2008-03-09 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
ec2655a6 3 2004, 2005, 2006, 2007
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
5287ad62 28#include <limits.h>
037e8744 29#include <stdarg.h>
c19d1205 30#define NO_RELOC 0
b99bd4ef 31#include "as.h"
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
720abc60 45#define WARN_DEPRECATED 1
03b1477f 46
7ed4c4c5
NC
47#ifdef OBJ_ELF
48/* Must be at least the size of the largest unwind opcode (currently two). */
49#define ARM_OPCODE_CHUNK_SIZE 8
50
51/* This structure holds the unwinding state. */
52
53static struct
54{
c19d1205
ZW
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
7ed4c4c5 59 /* The segment containing the function. */
c19d1205
ZW
60 segT saved_seg;
61 subsegT saved_subseg;
7ed4c4c5
NC
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
c19d1205
ZW
64 int opcode_count;
65 int opcode_alloc;
7ed4c4c5 66 /* The number of bytes pushed to the stack. */
c19d1205 67 offsetT frame_size;
7ed4c4c5
NC
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
c19d1205 71 offsetT pending_offset;
7ed4c4c5 72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
7ed4c4c5 76 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 77 unsigned fp_used:1;
7ed4c4c5 78 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 79 unsigned sp_restored:1;
7ed4c4c5
NC
80} unwind;
81
8b1ad454
NC
82/* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85static unsigned int marked_pr_dependency = 0;
86
87#endif /* OBJ_ELF */
88
4962c51a
MS
89/* Results from operand parsing worker functions. */
90
91typedef enum
92{
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96} parse_operand_result;
97
33a392fb
PB
98enum arm_float_abi
99{
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103};
104
c19d1205 105/* Types of processor to assemble for. */
b99bd4ef
NC
106#ifndef CPU_DEFAULT
107#if defined __XSCALE__
e74cfd16 108#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
109#else
110#if defined __thumb__
e74cfd16 111#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
112#endif
113#endif
114#endif
115
116#ifndef FPU_DEFAULT
c820d418
MM
117# ifdef TE_LINUX
118# define FPU_DEFAULT FPU_ARCH_FPA
119# elif defined (TE_NetBSD)
120# ifdef OBJ_ELF
121# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122# else
123 /* Legacy a.out format. */
124# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125# endif
4e7fd91e
PB
126# elif defined (TE_VXWORKS)
127# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
128# else
129 /* For backwards compatibility, default to FPA. */
130# define FPU_DEFAULT FPU_ARCH_FPA
131# endif
132#endif /* ifndef FPU_DEFAULT */
b99bd4ef 133
c19d1205 134#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 135
e74cfd16
PB
136static arm_feature_set cpu_variant;
137static arm_feature_set arm_arch_used;
138static arm_feature_set thumb_arch_used;
b99bd4ef 139
b99bd4ef 140/* Flags stored in private area of BFD structure. */
c19d1205
ZW
141static int uses_apcs_26 = FALSE;
142static int atpcs = FALSE;
b34976b6
AM
143static int support_interwork = FALSE;
144static int uses_apcs_float = FALSE;
c19d1205 145static int pic_code = FALSE;
845b51d6 146static int fix_v4bx = FALSE;
03b1477f
RE
147
148/* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
e74cfd16
PB
151static const arm_feature_set *legacy_cpu = NULL;
152static const arm_feature_set *legacy_fpu = NULL;
153
154static const arm_feature_set *mcpu_cpu_opt = NULL;
155static const arm_feature_set *mcpu_fpu_opt = NULL;
156static const arm_feature_set *march_cpu_opt = NULL;
157static const arm_feature_set *march_fpu_opt = NULL;
158static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 159static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
160
161/* Constants for known architecture features. */
162static const arm_feature_set fpu_default = FPU_DEFAULT;
163static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
164static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
165static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
166static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
167static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
168static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
169static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
170static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
171
172#ifdef CPU_DEFAULT
173static const arm_feature_set cpu_default = CPU_DEFAULT;
174#endif
175
176static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
177static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
178static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
179static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
180static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
181static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
182static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
183static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
184static const arm_feature_set arm_ext_v4t_5 =
185 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
186static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
187static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
188static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
189static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
190static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
191static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
192static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
193static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 194static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
7e806470
PB
195static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
196static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
197static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
7e806470
PB
201static const arm_feature_set arm_ext_m =
202 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
203
204static const arm_feature_set arm_arch_any = ARM_ANY;
205static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
208
2d447fca
JM
209static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
211static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62 223static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
224static const arm_feature_set fpu_vfp_ext_d32 =
225 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
226static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
227static const arm_feature_set fpu_vfp_v3_or_neon_ext =
228 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
e74cfd16 229
33a392fb 230static int mfloat_abi_opt = -1;
e74cfd16
PB
231/* Record user cpu selection for object attributes. */
232static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
233/* Must be long enough to hold any of the names in arm_cpus. */
234static char selected_cpu_name[16];
7cc69913 235#ifdef OBJ_ELF
deeaaff8
DJ
236# ifdef EABI_DEFAULT
237static int meabi_flags = EABI_DEFAULT;
238# else
d507cf36 239static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 240# endif
e1da3f5b
PB
241
242bfd_boolean
5f4273c7 243arm_is_eabi (void)
e1da3f5b
PB
244{
245 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
246}
7cc69913 247#endif
b99bd4ef 248
b99bd4ef 249#ifdef OBJ_ELF
c19d1205 250/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
251symbolS * GOT_symbol;
252#endif
253
b99bd4ef
NC
254/* 0: assemble for ARM,
255 1: assemble for Thumb,
256 2: assemble for Thumb even though target CPU does not support thumb
257 instructions. */
258static int thumb_mode = 0;
259
c19d1205
ZW
260/* If unified_syntax is true, we are processing the new unified
261 ARM/Thumb syntax. Important differences from the old ARM mode:
262
263 - Immediate operands do not require a # prefix.
264 - Conditional affixes always appear at the end of the
265 instruction. (For backward compatibility, those instructions
266 that formerly had them in the middle, continue to accept them
267 there.)
268 - The IT instruction may appear, and if it does is validated
269 against subsequent conditional affixes. It does not generate
270 machine code.
271
272 Important differences from the old Thumb mode:
273
274 - Immediate operands do not require a # prefix.
275 - Most of the V6T2 instructions are only available in unified mode.
276 - The .N and .W suffixes are recognized and honored (it is an error
277 if they cannot be honored).
278 - All instructions set the flags if and only if they have an 's' affix.
279 - Conditional affixes may be used. They are validated against
280 preceding IT instructions. Unlike ARM mode, you cannot use a
281 conditional affix except in the scope of an IT instruction. */
282
283static bfd_boolean unified_syntax = FALSE;
b99bd4ef 284
5287ad62
JB
285enum neon_el_type
286{
dcbf9037 287 NT_invtype,
5287ad62
JB
288 NT_untyped,
289 NT_integer,
290 NT_float,
291 NT_poly,
292 NT_signed,
dcbf9037 293 NT_unsigned
5287ad62
JB
294};
295
296struct neon_type_el
297{
298 enum neon_el_type type;
299 unsigned size;
300};
301
302#define NEON_MAX_TYPE_ELS 4
303
304struct neon_type
305{
306 struct neon_type_el el[NEON_MAX_TYPE_ELS];
307 unsigned elems;
308};
309
b99bd4ef
NC
310struct arm_it
311{
c19d1205 312 const char * error;
b99bd4ef 313 unsigned long instruction;
c19d1205
ZW
314 int size;
315 int size_req;
316 int cond;
037e8744
JB
317 /* "uncond_value" is set to the value in place of the conditional field in
318 unconditional versions of the instruction, or -1 if nothing is
319 appropriate. */
320 int uncond_value;
5287ad62 321 struct neon_type vectype;
0110f2b8
PB
322 /* Set to the opcode if the instruction needs relaxation.
323 Zero if the instruction is not relaxed. */
324 unsigned long relax;
b99bd4ef
NC
325 struct
326 {
327 bfd_reloc_code_real_type type;
c19d1205
ZW
328 expressionS exp;
329 int pc_rel;
b99bd4ef 330 } reloc;
b99bd4ef 331
c19d1205
ZW
332 struct
333 {
334 unsigned reg;
ca3f61f7 335 signed int imm;
dcbf9037 336 struct neon_type_el vectype;
ca3f61f7
NC
337 unsigned present : 1; /* Operand present. */
338 unsigned isreg : 1; /* Operand was a register. */
339 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
340 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
341 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 342 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
343 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
344 instructions. This allows us to disambiguate ARM <-> vector insns. */
345 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 346 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 347 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 348 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
349 unsigned hasreloc : 1; /* Operand has relocation suffix. */
350 unsigned writeback : 1; /* Operand has trailing ! */
351 unsigned preind : 1; /* Preindexed address. */
352 unsigned postind : 1; /* Postindexed address. */
353 unsigned negative : 1; /* Index register was negated. */
354 unsigned shifted : 1; /* Shift applied to operation. */
355 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 356 } operands[6];
b99bd4ef
NC
357};
358
c19d1205 359static struct arm_it inst;
b99bd4ef
NC
360
361#define NUM_FLOAT_VALS 8
362
05d2d07e 363const char * fp_const[] =
b99bd4ef
NC
364{
365 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
366};
367
c19d1205 368/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
369#define MAX_LITTLENUMS 6
370
371LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
372
373#define FAIL (-1)
374#define SUCCESS (0)
375
376#define SUFF_S 1
377#define SUFF_D 2
378#define SUFF_E 3
379#define SUFF_P 4
380
c19d1205
ZW
381#define CP_T_X 0x00008000
382#define CP_T_Y 0x00400000
b99bd4ef 383
c19d1205
ZW
384#define CONDS_BIT 0x00100000
385#define LOAD_BIT 0x00100000
b99bd4ef
NC
386
387#define DOUBLE_LOAD_FLAG 0x00000001
388
389struct asm_cond
390{
c19d1205 391 const char * template;
b99bd4ef
NC
392 unsigned long value;
393};
394
c19d1205 395#define COND_ALWAYS 0xE
b99bd4ef 396
b99bd4ef
NC
397struct asm_psr
398{
b34976b6 399 const char *template;
b99bd4ef
NC
400 unsigned long field;
401};
402
62b3e311
PB
403struct asm_barrier_opt
404{
405 const char *template;
406 unsigned long value;
407};
408
2d2255b5 409/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
410#define SPSR_BIT (1 << 22)
411
c19d1205
ZW
412/* The individual PSR flag bits. */
413#define PSR_c (1 << 16)
414#define PSR_x (1 << 17)
415#define PSR_s (1 << 18)
416#define PSR_f (1 << 19)
b99bd4ef 417
c19d1205 418struct reloc_entry
bfae80f2 419{
c19d1205
ZW
420 char *name;
421 bfd_reloc_code_real_type reloc;
bfae80f2
RE
422};
423
5287ad62 424enum vfp_reg_pos
bfae80f2 425{
5287ad62
JB
426 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
427 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
428};
429
430enum vfp_ldstm_type
431{
432 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
433};
434
dcbf9037
JB
435/* Bits for DEFINED field in neon_typed_alias. */
436#define NTA_HASTYPE 1
437#define NTA_HASINDEX 2
438
439struct neon_typed_alias
440{
441 unsigned char defined;
442 unsigned char index;
443 struct neon_type_el eltype;
444};
445
c19d1205
ZW
446/* ARM register categories. This includes coprocessor numbers and various
447 architecture extensions' registers. */
448enum arm_reg_type
bfae80f2 449{
c19d1205
ZW
450 REG_TYPE_RN,
451 REG_TYPE_CP,
452 REG_TYPE_CN,
453 REG_TYPE_FN,
454 REG_TYPE_VFS,
455 REG_TYPE_VFD,
5287ad62 456 REG_TYPE_NQ,
037e8744 457 REG_TYPE_VFSD,
5287ad62 458 REG_TYPE_NDQ,
037e8744 459 REG_TYPE_NSDQ,
c19d1205
ZW
460 REG_TYPE_VFC,
461 REG_TYPE_MVF,
462 REG_TYPE_MVD,
463 REG_TYPE_MVFX,
464 REG_TYPE_MVDX,
465 REG_TYPE_MVAX,
466 REG_TYPE_DSPSC,
467 REG_TYPE_MMXWR,
468 REG_TYPE_MMXWC,
469 REG_TYPE_MMXWCG,
470 REG_TYPE_XSCALE,
bfae80f2
RE
471};
472
dcbf9037
JB
473/* Structure for a hash table entry for a register.
474 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
475 information which states whether a vector type or index is specified (for a
476 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
477struct reg_entry
478{
dcbf9037
JB
479 const char *name;
480 unsigned char number;
481 unsigned char type;
482 unsigned char builtin;
483 struct neon_typed_alias *neon;
6c43fab6
RE
484};
485
c19d1205
ZW
486/* Diagnostics used when we don't get a register of the expected type. */
487const char *const reg_expected_msgs[] =
488{
489 N_("ARM register expected"),
490 N_("bad or missing co-processor number"),
491 N_("co-processor register expected"),
492 N_("FPA register expected"),
493 N_("VFP single precision register expected"),
5287ad62
JB
494 N_("VFP/Neon double precision register expected"),
495 N_("Neon quad precision register expected"),
037e8744 496 N_("VFP single or double precision register expected"),
5287ad62 497 N_("Neon double or quad precision register expected"),
037e8744 498 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
499 N_("VFP system register expected"),
500 N_("Maverick MVF register expected"),
501 N_("Maverick MVD register expected"),
502 N_("Maverick MVFX register expected"),
503 N_("Maverick MVDX register expected"),
504 N_("Maverick MVAX register expected"),
505 N_("Maverick DSPSC register expected"),
506 N_("iWMMXt data register expected"),
507 N_("iWMMXt control register expected"),
508 N_("iWMMXt scalar register expected"),
509 N_("XScale accumulator register expected"),
6c43fab6
RE
510};
511
c19d1205
ZW
512/* Some well known registers that we refer to directly elsewhere. */
513#define REG_SP 13
514#define REG_LR 14
515#define REG_PC 15
404ff6b5 516
b99bd4ef
NC
517/* ARM instructions take 4bytes in the object file, Thumb instructions
518 take 2: */
c19d1205 519#define INSN_SIZE 4
b99bd4ef
NC
520
521struct asm_opcode
522{
523 /* Basic string to match. */
c19d1205
ZW
524 const char *template;
525
526 /* Parameters to instruction. */
527 unsigned char operands[8];
528
529 /* Conditional tag - see opcode_lookup. */
530 unsigned int tag : 4;
b99bd4ef
NC
531
532 /* Basic instruction code. */
c19d1205 533 unsigned int avalue : 28;
b99bd4ef 534
c19d1205
ZW
535 /* Thumb-format instruction code. */
536 unsigned int tvalue;
b99bd4ef 537
90e4755a 538 /* Which architecture variant provides this instruction. */
e74cfd16
PB
539 const arm_feature_set *avariant;
540 const arm_feature_set *tvariant;
c19d1205
ZW
541
542 /* Function to call to encode instruction in ARM format. */
543 void (* aencode) (void);
b99bd4ef 544
c19d1205
ZW
545 /* Function to call to encode instruction in Thumb format. */
546 void (* tencode) (void);
b99bd4ef
NC
547};
548
a737bd4d
NC
549/* Defines for various bits that we will want to toggle. */
550#define INST_IMMEDIATE 0x02000000
551#define OFFSET_REG 0x02000000
c19d1205 552#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
553#define SHIFT_BY_REG 0x00000010
554#define PRE_INDEX 0x01000000
555#define INDEX_UP 0x00800000
556#define WRITE_BACK 0x00200000
557#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 558#define CPSI_MMOD 0x00020000
90e4755a 559
a737bd4d
NC
560#define LITERAL_MASK 0xf000f000
561#define OPCODE_MASK 0xfe1fffff
562#define V4_STR_BIT 0x00000020
90e4755a 563
efd81785
PB
564#define T2_SUBS_PC_LR 0xf3de8f00
565
a737bd4d 566#define DATA_OP_SHIFT 21
90e4755a 567
ef8d22e6
PB
568#define T2_OPCODE_MASK 0xfe1fffff
569#define T2_DATA_OP_SHIFT 21
570
a737bd4d
NC
571/* Codes to distinguish the arithmetic instructions. */
572#define OPCODE_AND 0
573#define OPCODE_EOR 1
574#define OPCODE_SUB 2
575#define OPCODE_RSB 3
576#define OPCODE_ADD 4
577#define OPCODE_ADC 5
578#define OPCODE_SBC 6
579#define OPCODE_RSC 7
580#define OPCODE_TST 8
581#define OPCODE_TEQ 9
582#define OPCODE_CMP 10
583#define OPCODE_CMN 11
584#define OPCODE_ORR 12
585#define OPCODE_MOV 13
586#define OPCODE_BIC 14
587#define OPCODE_MVN 15
90e4755a 588
ef8d22e6
PB
589#define T2_OPCODE_AND 0
590#define T2_OPCODE_BIC 1
591#define T2_OPCODE_ORR 2
592#define T2_OPCODE_ORN 3
593#define T2_OPCODE_EOR 4
594#define T2_OPCODE_ADD 8
595#define T2_OPCODE_ADC 10
596#define T2_OPCODE_SBC 11
597#define T2_OPCODE_SUB 13
598#define T2_OPCODE_RSB 14
599
a737bd4d
NC
600#define T_OPCODE_MUL 0x4340
601#define T_OPCODE_TST 0x4200
602#define T_OPCODE_CMN 0x42c0
603#define T_OPCODE_NEG 0x4240
604#define T_OPCODE_MVN 0x43c0
90e4755a 605
a737bd4d
NC
606#define T_OPCODE_ADD_R3 0x1800
607#define T_OPCODE_SUB_R3 0x1a00
608#define T_OPCODE_ADD_HI 0x4400
609#define T_OPCODE_ADD_ST 0xb000
610#define T_OPCODE_SUB_ST 0xb080
611#define T_OPCODE_ADD_SP 0xa800
612#define T_OPCODE_ADD_PC 0xa000
613#define T_OPCODE_ADD_I8 0x3000
614#define T_OPCODE_SUB_I8 0x3800
615#define T_OPCODE_ADD_I3 0x1c00
616#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 617
a737bd4d
NC
618#define T_OPCODE_ASR_R 0x4100
619#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
620#define T_OPCODE_LSR_R 0x40c0
621#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
622#define T_OPCODE_ASR_I 0x1000
623#define T_OPCODE_LSL_I 0x0000
624#define T_OPCODE_LSR_I 0x0800
b99bd4ef 625
a737bd4d
NC
626#define T_OPCODE_MOV_I8 0x2000
627#define T_OPCODE_CMP_I8 0x2800
628#define T_OPCODE_CMP_LR 0x4280
629#define T_OPCODE_MOV_HR 0x4600
630#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 631
a737bd4d
NC
632#define T_OPCODE_LDR_PC 0x4800
633#define T_OPCODE_LDR_SP 0x9800
634#define T_OPCODE_STR_SP 0x9000
635#define T_OPCODE_LDR_IW 0x6800
636#define T_OPCODE_STR_IW 0x6000
637#define T_OPCODE_LDR_IH 0x8800
638#define T_OPCODE_STR_IH 0x8000
639#define T_OPCODE_LDR_IB 0x7800
640#define T_OPCODE_STR_IB 0x7000
641#define T_OPCODE_LDR_RW 0x5800
642#define T_OPCODE_STR_RW 0x5000
643#define T_OPCODE_LDR_RH 0x5a00
644#define T_OPCODE_STR_RH 0x5200
645#define T_OPCODE_LDR_RB 0x5c00
646#define T_OPCODE_STR_RB 0x5400
c9b604bd 647
a737bd4d
NC
648#define T_OPCODE_PUSH 0xb400
649#define T_OPCODE_POP 0xbc00
b99bd4ef 650
2fc8bdac 651#define T_OPCODE_BRANCH 0xe000
b99bd4ef 652
a737bd4d 653#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 654#define THUMB_PP_PC_LR 0x0100
c19d1205 655#define THUMB_LOAD_BIT 0x0800
53365c0d 656#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
657
658#define BAD_ARGS _("bad arguments to instruction")
659#define BAD_PC _("r15 not allowed here")
660#define BAD_COND _("instruction cannot be conditional")
661#define BAD_OVERLAP _("registers may not be the same")
662#define BAD_HIREG _("lo register required")
663#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 664#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
665#define BAD_BRANCH _("branch must be last instruction in IT block")
666#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 667#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
668
669static struct hash_control *arm_ops_hsh;
670static struct hash_control *arm_cond_hsh;
671static struct hash_control *arm_shift_hsh;
672static struct hash_control *arm_psr_hsh;
62b3e311 673static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
674static struct hash_control *arm_reg_hsh;
675static struct hash_control *arm_reloc_hsh;
62b3e311 676static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 677
b99bd4ef
NC
678/* Stuff needed to resolve the label ambiguity
679 As:
680 ...
681 label: <insn>
682 may differ from:
683 ...
684 label:
5f4273c7 685 <insn> */
b99bd4ef
NC
686
687symbolS * last_label_seen;
b34976b6 688static int label_is_thumb_function_name = FALSE;
a737bd4d 689\f
3d0c9500
NC
690/* Literal pool structure. Held on a per-section
691 and per-sub-section basis. */
a737bd4d 692
c19d1205 693#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 694typedef struct literal_pool
b99bd4ef 695{
c19d1205
ZW
696 expressionS literals [MAX_LITERAL_POOL_SIZE];
697 unsigned int next_free_entry;
698 unsigned int id;
699 symbolS * symbol;
700 segT section;
701 subsegT sub_section;
61b5f74b 702 struct literal_pool * next;
3d0c9500 703} literal_pool;
b99bd4ef 704
3d0c9500
NC
705/* Pointer to a linked list of literal pools. */
706literal_pool * list_of_pools = NULL;
e27ec89e
PB
707
708/* State variables for IT block handling. */
709static bfd_boolean current_it_mask = 0;
710static int current_cc;
c19d1205
ZW
711\f
712/* Pure syntax. */
b99bd4ef 713
c19d1205
ZW
714/* This array holds the chars that always start a comment. If the
715 pre-processor is disabled, these aren't very useful. */
716const char comment_chars[] = "@";
3d0c9500 717
c19d1205
ZW
718/* This array holds the chars that only start a comment at the beginning of
719 a line. If the line seems to have the form '# 123 filename'
720 .line and .file directives will appear in the pre-processed output. */
721/* Note that input_file.c hand checks for '#' at the beginning of the
722 first line of the input file. This is because the compiler outputs
723 #NO_APP at the beginning of its output. */
724/* Also note that comments like this one will always work. */
725const char line_comment_chars[] = "#";
3d0c9500 726
c19d1205 727const char line_separator_chars[] = ";";
b99bd4ef 728
c19d1205
ZW
729/* Chars that can be used to separate mant
730 from exp in floating point numbers. */
731const char EXP_CHARS[] = "eE";
3d0c9500 732
c19d1205
ZW
733/* Chars that mean this number is a floating point constant. */
734/* As in 0f12.456 */
735/* or 0d1.2345e12 */
b99bd4ef 736
c19d1205 737const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 738
c19d1205
ZW
739/* Prefix characters that indicate the start of an immediate
740 value. */
741#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 742
c19d1205
ZW
743/* Separator character handling. */
744
745#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
746
747static inline int
748skip_past_char (char ** str, char c)
749{
750 if (**str == c)
751 {
752 (*str)++;
753 return SUCCESS;
3d0c9500 754 }
c19d1205
ZW
755 else
756 return FAIL;
757}
758#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 759
c19d1205
ZW
760/* Arithmetic expressions (possibly involving symbols). */
761
762/* Return TRUE if anything in the expression is a bignum. */
763
764static int
765walk_no_bignums (symbolS * sp)
766{
767 if (symbol_get_value_expression (sp)->X_op == O_big)
768 return 1;
769
770 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 771 {
c19d1205
ZW
772 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
773 || (symbol_get_value_expression (sp)->X_op_symbol
774 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
775 }
776
c19d1205 777 return 0;
3d0c9500
NC
778}
779
c19d1205
ZW
780static int in_my_get_expression = 0;
781
782/* Third argument to my_get_expression. */
783#define GE_NO_PREFIX 0
784#define GE_IMM_PREFIX 1
785#define GE_OPT_PREFIX 2
5287ad62
JB
786/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
787 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
788#define GE_OPT_PREFIX_BIG 3
a737bd4d 789
b99bd4ef 790static int
c19d1205 791my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 792{
c19d1205
ZW
793 char * save_in;
794 segT seg;
b99bd4ef 795
c19d1205
ZW
796 /* In unified syntax, all prefixes are optional. */
797 if (unified_syntax)
5287ad62
JB
798 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
799 : GE_OPT_PREFIX;
b99bd4ef 800
c19d1205 801 switch (prefix_mode)
b99bd4ef 802 {
c19d1205
ZW
803 case GE_NO_PREFIX: break;
804 case GE_IMM_PREFIX:
805 if (!is_immediate_prefix (**str))
806 {
807 inst.error = _("immediate expression requires a # prefix");
808 return FAIL;
809 }
810 (*str)++;
811 break;
812 case GE_OPT_PREFIX:
5287ad62 813 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
814 if (is_immediate_prefix (**str))
815 (*str)++;
816 break;
817 default: abort ();
818 }
b99bd4ef 819
c19d1205 820 memset (ep, 0, sizeof (expressionS));
b99bd4ef 821
c19d1205
ZW
822 save_in = input_line_pointer;
823 input_line_pointer = *str;
824 in_my_get_expression = 1;
825 seg = expression (ep);
826 in_my_get_expression = 0;
827
828 if (ep->X_op == O_illegal)
b99bd4ef 829 {
c19d1205
ZW
830 /* We found a bad expression in md_operand(). */
831 *str = input_line_pointer;
832 input_line_pointer = save_in;
833 if (inst.error == NULL)
834 inst.error = _("bad expression");
835 return 1;
836 }
b99bd4ef 837
c19d1205
ZW
838#ifdef OBJ_AOUT
839 if (seg != absolute_section
840 && seg != text_section
841 && seg != data_section
842 && seg != bss_section
843 && seg != undefined_section)
844 {
845 inst.error = _("bad segment");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
b99bd4ef 849 }
c19d1205 850#endif
b99bd4ef 851
c19d1205
ZW
852 /* Get rid of any bignums now, so that we don't generate an error for which
853 we can't establish a line number later on. Big numbers are never valid
854 in instructions, which is where this routine is always called. */
5287ad62
JB
855 if (prefix_mode != GE_OPT_PREFIX_BIG
856 && (ep->X_op == O_big
857 || (ep->X_add_symbol
858 && (walk_no_bignums (ep->X_add_symbol)
859 || (ep->X_op_symbol
860 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
861 {
862 inst.error = _("invalid constant");
863 *str = input_line_pointer;
864 input_line_pointer = save_in;
865 return 1;
866 }
b99bd4ef 867
c19d1205
ZW
868 *str = input_line_pointer;
869 input_line_pointer = save_in;
870 return 0;
b99bd4ef
NC
871}
872
c19d1205
ZW
873/* Turn a string in input_line_pointer into a floating point constant
874 of type TYPE, and store the appropriate bytes in *LITP. The number
875 of LITTLENUMS emitted is stored in *SIZEP. An error message is
876 returned, or NULL on OK.
b99bd4ef 877
c19d1205
ZW
878 Note that fp constants aren't represent in the normal way on the ARM.
879 In big endian mode, things are as expected. However, in little endian
880 mode fp constants are big-endian word-wise, and little-endian byte-wise
881 within the words. For example, (double) 1.1 in big endian mode is
882 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
883 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 884
c19d1205 885 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 886
c19d1205
ZW
887char *
888md_atof (int type, char * litP, int * sizeP)
889{
890 int prec;
891 LITTLENUM_TYPE words[MAX_LITTLENUMS];
892 char *t;
893 int i;
b99bd4ef 894
c19d1205
ZW
895 switch (type)
896 {
897 case 'f':
898 case 'F':
899 case 's':
900 case 'S':
901 prec = 2;
902 break;
b99bd4ef 903
c19d1205
ZW
904 case 'd':
905 case 'D':
906 case 'r':
907 case 'R':
908 prec = 4;
909 break;
b99bd4ef 910
c19d1205
ZW
911 case 'x':
912 case 'X':
499ac353 913 prec = 5;
c19d1205 914 break;
b99bd4ef 915
c19d1205
ZW
916 case 'p':
917 case 'P':
499ac353 918 prec = 5;
c19d1205 919 break;
a737bd4d 920
c19d1205
ZW
921 default:
922 *sizeP = 0;
499ac353 923 return _("Unrecognized or unsupported floating point constant");
c19d1205 924 }
b99bd4ef 925
c19d1205
ZW
926 t = atof_ieee (input_line_pointer, type, words);
927 if (t)
928 input_line_pointer = t;
499ac353 929 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 930
c19d1205
ZW
931 if (target_big_endian)
932 {
933 for (i = 0; i < prec; i++)
934 {
499ac353
NC
935 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
936 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
937 }
938 }
939 else
940 {
e74cfd16 941 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
942 for (i = prec - 1; i >= 0; i--)
943 {
499ac353
NC
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
946 }
947 else
948 /* For a 4 byte float the order of elements in `words' is 1 0.
949 For an 8 byte float the order is 1 0 3 2. */
950 for (i = 0; i < prec; i += 2)
951 {
499ac353
NC
952 md_number_to_chars (litP, (valueT) words[i + 1],
953 sizeof (LITTLENUM_TYPE));
954 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
955 (valueT) words[i], sizeof (LITTLENUM_TYPE));
956 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
957 }
958 }
b99bd4ef 959
499ac353 960 return NULL;
c19d1205 961}
b99bd4ef 962
c19d1205
ZW
963/* We handle all bad expressions here, so that we can report the faulty
964 instruction in the error message. */
965void
966md_operand (expressionS * expr)
967{
968 if (in_my_get_expression)
969 expr->X_op = O_illegal;
b99bd4ef
NC
970}
971
c19d1205 972/* Immediate values. */
b99bd4ef 973
c19d1205
ZW
974/* Generic immediate-value read function for use in directives.
975 Accepts anything that 'expression' can fold to a constant.
976 *val receives the number. */
977#ifdef OBJ_ELF
978static int
979immediate_for_directive (int *val)
b99bd4ef 980{
c19d1205
ZW
981 expressionS exp;
982 exp.X_op = O_illegal;
b99bd4ef 983
c19d1205
ZW
984 if (is_immediate_prefix (*input_line_pointer))
985 {
986 input_line_pointer++;
987 expression (&exp);
988 }
b99bd4ef 989
c19d1205
ZW
990 if (exp.X_op != O_constant)
991 {
992 as_bad (_("expected #constant"));
993 ignore_rest_of_line ();
994 return FAIL;
995 }
996 *val = exp.X_add_number;
997 return SUCCESS;
b99bd4ef 998}
c19d1205 999#endif
b99bd4ef 1000
c19d1205 1001/* Register parsing. */
b99bd4ef 1002
c19d1205
ZW
1003/* Generic register parser. CCP points to what should be the
1004 beginning of a register name. If it is indeed a valid register
1005 name, advance CCP over it and return the reg_entry structure;
1006 otherwise return NULL. Does not issue diagnostics. */
1007
1008static struct reg_entry *
1009arm_reg_parse_multi (char **ccp)
b99bd4ef 1010{
c19d1205
ZW
1011 char *start = *ccp;
1012 char *p;
1013 struct reg_entry *reg;
b99bd4ef 1014
c19d1205
ZW
1015#ifdef REGISTER_PREFIX
1016 if (*start != REGISTER_PREFIX)
01cfc07f 1017 return NULL;
c19d1205
ZW
1018 start++;
1019#endif
1020#ifdef OPTIONAL_REGISTER_PREFIX
1021 if (*start == OPTIONAL_REGISTER_PREFIX)
1022 start++;
1023#endif
b99bd4ef 1024
c19d1205
ZW
1025 p = start;
1026 if (!ISALPHA (*p) || !is_name_beginner (*p))
1027 return NULL;
b99bd4ef 1028
c19d1205
ZW
1029 do
1030 p++;
1031 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1032
1033 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1034
1035 if (!reg)
1036 return NULL;
1037
1038 *ccp = p;
1039 return reg;
b99bd4ef
NC
1040}
1041
1042static int
dcbf9037
JB
1043arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1044 enum arm_reg_type type)
b99bd4ef 1045{
c19d1205
ZW
1046 /* Alternative syntaxes are accepted for a few register classes. */
1047 switch (type)
1048 {
1049 case REG_TYPE_MVF:
1050 case REG_TYPE_MVD:
1051 case REG_TYPE_MVFX:
1052 case REG_TYPE_MVDX:
1053 /* Generic coprocessor register names are allowed for these. */
79134647 1054 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1055 return reg->number;
1056 break;
69b97547 1057
c19d1205
ZW
1058 case REG_TYPE_CP:
1059 /* For backward compatibility, a bare number is valid here. */
1060 {
1061 unsigned long processor = strtoul (start, ccp, 10);
1062 if (*ccp != start && processor <= 15)
1063 return processor;
1064 }
6057a28f 1065
c19d1205
ZW
1066 case REG_TYPE_MMXWC:
1067 /* WC includes WCG. ??? I'm not sure this is true for all
1068 instructions that take WC registers. */
79134647 1069 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1070 return reg->number;
6057a28f 1071 break;
c19d1205 1072
6057a28f 1073 default:
c19d1205 1074 break;
6057a28f
NC
1075 }
1076
dcbf9037
JB
1077 return FAIL;
1078}
1079
1080/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1081 return value is the register number or FAIL. */
1082
1083static int
1084arm_reg_parse (char **ccp, enum arm_reg_type type)
1085{
1086 char *start = *ccp;
1087 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1088 int ret;
1089
1090 /* Do not allow a scalar (reg+index) to parse as a register. */
1091 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1092 return FAIL;
1093
1094 if (reg && reg->type == type)
1095 return reg->number;
1096
1097 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1098 return ret;
1099
c19d1205
ZW
1100 *ccp = start;
1101 return FAIL;
1102}
69b97547 1103
dcbf9037
JB
1104/* Parse a Neon type specifier. *STR should point at the leading '.'
1105 character. Does no verification at this stage that the type fits the opcode
1106 properly. E.g.,
1107
1108 .i32.i32.s16
1109 .s32.f32
1110 .u16
1111
1112 Can all be legally parsed by this function.
1113
1114 Fills in neon_type struct pointer with parsed information, and updates STR
1115 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1116 type, FAIL if not. */
1117
1118static int
1119parse_neon_type (struct neon_type *type, char **str)
1120{
1121 char *ptr = *str;
1122
1123 if (type)
1124 type->elems = 0;
1125
1126 while (type->elems < NEON_MAX_TYPE_ELS)
1127 {
1128 enum neon_el_type thistype = NT_untyped;
1129 unsigned thissize = -1u;
1130
1131 if (*ptr != '.')
1132 break;
1133
1134 ptr++;
1135
1136 /* Just a size without an explicit type. */
1137 if (ISDIGIT (*ptr))
1138 goto parsesize;
1139
1140 switch (TOLOWER (*ptr))
1141 {
1142 case 'i': thistype = NT_integer; break;
1143 case 'f': thistype = NT_float; break;
1144 case 'p': thistype = NT_poly; break;
1145 case 's': thistype = NT_signed; break;
1146 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1147 case 'd':
1148 thistype = NT_float;
1149 thissize = 64;
1150 ptr++;
1151 goto done;
dcbf9037
JB
1152 default:
1153 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1154 return FAIL;
1155 }
1156
1157 ptr++;
1158
1159 /* .f is an abbreviation for .f32. */
1160 if (thistype == NT_float && !ISDIGIT (*ptr))
1161 thissize = 32;
1162 else
1163 {
1164 parsesize:
1165 thissize = strtoul (ptr, &ptr, 10);
1166
1167 if (thissize != 8 && thissize != 16 && thissize != 32
1168 && thissize != 64)
1169 {
1170 as_bad (_("bad size %d in type specifier"), thissize);
1171 return FAIL;
1172 }
1173 }
1174
037e8744 1175 done:
dcbf9037
JB
1176 if (type)
1177 {
1178 type->el[type->elems].type = thistype;
1179 type->el[type->elems].size = thissize;
1180 type->elems++;
1181 }
1182 }
1183
1184 /* Empty/missing type is not a successful parse. */
1185 if (type->elems == 0)
1186 return FAIL;
1187
1188 *str = ptr;
1189
1190 return SUCCESS;
1191}
1192
1193/* Errors may be set multiple times during parsing or bit encoding
1194 (particularly in the Neon bits), but usually the earliest error which is set
1195 will be the most meaningful. Avoid overwriting it with later (cascading)
1196 errors by calling this function. */
1197
1198static void
1199first_error (const char *err)
1200{
1201 if (!inst.error)
1202 inst.error = err;
1203}
1204
1205/* Parse a single type, e.g. ".s32", leading period included. */
1206static int
1207parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1208{
1209 char *str = *ccp;
1210 struct neon_type optype;
1211
1212 if (*str == '.')
1213 {
1214 if (parse_neon_type (&optype, &str) == SUCCESS)
1215 {
1216 if (optype.elems == 1)
1217 *vectype = optype.el[0];
1218 else
1219 {
1220 first_error (_("only one type should be specified for operand"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 {
1226 first_error (_("vector type expected"));
1227 return FAIL;
1228 }
1229 }
1230 else
1231 return FAIL;
5f4273c7 1232
dcbf9037 1233 *ccp = str;
5f4273c7 1234
dcbf9037
JB
1235 return SUCCESS;
1236}
1237
1238/* Special meanings for indices (which have a range of 0-7), which will fit into
1239 a 4-bit integer. */
1240
1241#define NEON_ALL_LANES 15
1242#define NEON_INTERLEAVE_LANES 14
1243
1244/* Parse either a register or a scalar, with an optional type. Return the
1245 register number, and optionally fill in the actual type of the register
1246 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1247 type/index information in *TYPEINFO. */
1248
1249static int
1250parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1251 enum arm_reg_type *rtype,
1252 struct neon_typed_alias *typeinfo)
1253{
1254 char *str = *ccp;
1255 struct reg_entry *reg = arm_reg_parse_multi (&str);
1256 struct neon_typed_alias atype;
1257 struct neon_type_el parsetype;
1258
1259 atype.defined = 0;
1260 atype.index = -1;
1261 atype.eltype.type = NT_invtype;
1262 atype.eltype.size = -1;
1263
1264 /* Try alternate syntax for some types of register. Note these are mutually
1265 exclusive with the Neon syntax extensions. */
1266 if (reg == NULL)
1267 {
1268 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1269 if (altreg != FAIL)
1270 *ccp = str;
1271 if (typeinfo)
1272 *typeinfo = atype;
1273 return altreg;
1274 }
1275
037e8744
JB
1276 /* Undo polymorphism when a set of register types may be accepted. */
1277 if ((type == REG_TYPE_NDQ
1278 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_VFSD
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1281 || (type == REG_TYPE_NSDQ
1282 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1283 || reg->type == REG_TYPE_NQ))
1284 || (type == REG_TYPE_MMXWC
1285 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1286 type = reg->type;
1287
1288 if (type != reg->type)
1289 return FAIL;
1290
1291 if (reg->neon)
1292 atype = *reg->neon;
5f4273c7 1293
dcbf9037
JB
1294 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1295 {
1296 if ((atype.defined & NTA_HASTYPE) != 0)
1297 {
1298 first_error (_("can't redefine type for operand"));
1299 return FAIL;
1300 }
1301 atype.defined |= NTA_HASTYPE;
1302 atype.eltype = parsetype;
1303 }
5f4273c7 1304
dcbf9037
JB
1305 if (skip_past_char (&str, '[') == SUCCESS)
1306 {
1307 if (type != REG_TYPE_VFD)
1308 {
1309 first_error (_("only D registers may be indexed"));
1310 return FAIL;
1311 }
5f4273c7 1312
dcbf9037
JB
1313 if ((atype.defined & NTA_HASINDEX) != 0)
1314 {
1315 first_error (_("can't change index for operand"));
1316 return FAIL;
1317 }
1318
1319 atype.defined |= NTA_HASINDEX;
1320
1321 if (skip_past_char (&str, ']') == SUCCESS)
1322 atype.index = NEON_ALL_LANES;
1323 else
1324 {
1325 expressionS exp;
1326
1327 my_get_expression (&exp, &str, GE_NO_PREFIX);
1328
1329 if (exp.X_op != O_constant)
1330 {
1331 first_error (_("constant expression required"));
1332 return FAIL;
1333 }
1334
1335 if (skip_past_char (&str, ']') == FAIL)
1336 return FAIL;
1337
1338 atype.index = exp.X_add_number;
1339 }
1340 }
5f4273c7 1341
dcbf9037
JB
1342 if (typeinfo)
1343 *typeinfo = atype;
5f4273c7 1344
dcbf9037
JB
1345 if (rtype)
1346 *rtype = type;
5f4273c7 1347
dcbf9037 1348 *ccp = str;
5f4273c7 1349
dcbf9037
JB
1350 return reg->number;
1351}
1352
1353/* Like arm_reg_parse, but allow allow the following extra features:
1354 - If RTYPE is non-zero, return the (possibly restricted) type of the
1355 register (e.g. Neon double or quad reg when either has been requested).
1356 - If this is a Neon vector type with additional type information, fill
1357 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1358 This function will fault on encountering a scalar. */
dcbf9037
JB
1359
1360static int
1361arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1362 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1363{
1364 struct neon_typed_alias atype;
1365 char *str = *ccp;
1366 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1367
1368 if (reg == FAIL)
1369 return FAIL;
1370
1371 /* Do not allow a scalar (reg+index) to parse as a register. */
1372 if ((atype.defined & NTA_HASINDEX) != 0)
1373 {
1374 first_error (_("register operand expected, but got scalar"));
1375 return FAIL;
1376 }
1377
1378 if (vectype)
1379 *vectype = atype.eltype;
1380
1381 *ccp = str;
1382
1383 return reg;
1384}
1385
1386#define NEON_SCALAR_REG(X) ((X) >> 4)
1387#define NEON_SCALAR_INDEX(X) ((X) & 15)
1388
5287ad62
JB
1389/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1390 have enough information to be able to do a good job bounds-checking. So, we
1391 just do easy checks here, and do further checks later. */
1392
1393static int
dcbf9037 1394parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1395{
dcbf9037 1396 int reg;
5287ad62 1397 char *str = *ccp;
dcbf9037 1398 struct neon_typed_alias atype;
5f4273c7 1399
dcbf9037 1400 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1401
dcbf9037 1402 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1403 return FAIL;
5f4273c7 1404
dcbf9037 1405 if (atype.index == NEON_ALL_LANES)
5287ad62 1406 {
dcbf9037 1407 first_error (_("scalar must have an index"));
5287ad62
JB
1408 return FAIL;
1409 }
dcbf9037 1410 else if (atype.index >= 64 / elsize)
5287ad62 1411 {
dcbf9037 1412 first_error (_("scalar index out of range"));
5287ad62
JB
1413 return FAIL;
1414 }
5f4273c7 1415
dcbf9037
JB
1416 if (type)
1417 *type = atype.eltype;
5f4273c7 1418
5287ad62 1419 *ccp = str;
5f4273c7 1420
dcbf9037 1421 return reg * 16 + atype.index;
5287ad62
JB
1422}
1423
c19d1205
ZW
1424/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1425static long
1426parse_reg_list (char ** strp)
1427{
1428 char * str = * strp;
1429 long range = 0;
1430 int another_range;
a737bd4d 1431
c19d1205
ZW
1432 /* We come back here if we get ranges concatenated by '+' or '|'. */
1433 do
6057a28f 1434 {
c19d1205 1435 another_range = 0;
a737bd4d 1436
c19d1205
ZW
1437 if (*str == '{')
1438 {
1439 int in_range = 0;
1440 int cur_reg = -1;
a737bd4d 1441
c19d1205
ZW
1442 str++;
1443 do
1444 {
1445 int reg;
6057a28f 1446
dcbf9037 1447 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1448 {
dcbf9037 1449 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1450 return FAIL;
1451 }
a737bd4d 1452
c19d1205
ZW
1453 if (in_range)
1454 {
1455 int i;
a737bd4d 1456
c19d1205
ZW
1457 if (reg <= cur_reg)
1458 {
dcbf9037 1459 first_error (_("bad range in register list"));
c19d1205
ZW
1460 return FAIL;
1461 }
40a18ebd 1462
c19d1205
ZW
1463 for (i = cur_reg + 1; i < reg; i++)
1464 {
1465 if (range & (1 << i))
1466 as_tsktsk
1467 (_("Warning: duplicated register (r%d) in register list"),
1468 i);
1469 else
1470 range |= 1 << i;
1471 }
1472 in_range = 0;
1473 }
a737bd4d 1474
c19d1205
ZW
1475 if (range & (1 << reg))
1476 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1477 reg);
1478 else if (reg <= cur_reg)
1479 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1480
c19d1205
ZW
1481 range |= 1 << reg;
1482 cur_reg = reg;
1483 }
1484 while (skip_past_comma (&str) != FAIL
1485 || (in_range = 1, *str++ == '-'));
1486 str--;
a737bd4d 1487
c19d1205
ZW
1488 if (*str++ != '}')
1489 {
dcbf9037 1490 first_error (_("missing `}'"));
c19d1205
ZW
1491 return FAIL;
1492 }
1493 }
1494 else
1495 {
1496 expressionS expr;
40a18ebd 1497
c19d1205
ZW
1498 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1499 return FAIL;
40a18ebd 1500
c19d1205
ZW
1501 if (expr.X_op == O_constant)
1502 {
1503 if (expr.X_add_number
1504 != (expr.X_add_number & 0x0000ffff))
1505 {
1506 inst.error = _("invalid register mask");
1507 return FAIL;
1508 }
a737bd4d 1509
c19d1205
ZW
1510 if ((range & expr.X_add_number) != 0)
1511 {
1512 int regno = range & expr.X_add_number;
a737bd4d 1513
c19d1205
ZW
1514 regno &= -regno;
1515 regno = (1 << regno) - 1;
1516 as_tsktsk
1517 (_("Warning: duplicated register (r%d) in register list"),
1518 regno);
1519 }
a737bd4d 1520
c19d1205
ZW
1521 range |= expr.X_add_number;
1522 }
1523 else
1524 {
1525 if (inst.reloc.type != 0)
1526 {
1527 inst.error = _("expression too complex");
1528 return FAIL;
1529 }
a737bd4d 1530
c19d1205
ZW
1531 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1532 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1533 inst.reloc.pc_rel = 0;
1534 }
1535 }
a737bd4d 1536
c19d1205
ZW
1537 if (*str == '|' || *str == '+')
1538 {
1539 str++;
1540 another_range = 1;
1541 }
a737bd4d 1542 }
c19d1205 1543 while (another_range);
a737bd4d 1544
c19d1205
ZW
1545 *strp = str;
1546 return range;
a737bd4d
NC
1547}
1548
5287ad62
JB
1549/* Types of registers in a list. */
1550
1551enum reg_list_els
1552{
1553 REGLIST_VFP_S,
1554 REGLIST_VFP_D,
1555 REGLIST_NEON_D
1556};
1557
c19d1205
ZW
1558/* Parse a VFP register list. If the string is invalid return FAIL.
1559 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1560 register. Parses registers of type ETYPE.
1561 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1562 - Q registers can be used to specify pairs of D registers
1563 - { } can be omitted from around a singleton register list
1564 FIXME: This is not implemented, as it would require backtracking in
1565 some cases, e.g.:
1566 vtbl.8 d3,d4,d5
1567 This could be done (the meaning isn't really ambiguous), but doesn't
1568 fit in well with the current parsing framework.
dcbf9037
JB
1569 - 32 D registers may be used (also true for VFPv3).
1570 FIXME: Types are ignored in these register lists, which is probably a
1571 bug. */
6057a28f 1572
c19d1205 1573static int
037e8744 1574parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1575{
037e8744 1576 char *str = *ccp;
c19d1205
ZW
1577 int base_reg;
1578 int new_base;
5287ad62
JB
1579 enum arm_reg_type regtype = 0;
1580 int max_regs = 0;
c19d1205
ZW
1581 int count = 0;
1582 int warned = 0;
1583 unsigned long mask = 0;
a737bd4d 1584 int i;
6057a28f 1585
037e8744 1586 if (*str != '{')
5287ad62
JB
1587 {
1588 inst.error = _("expecting {");
1589 return FAIL;
1590 }
6057a28f 1591
037e8744 1592 str++;
6057a28f 1593
5287ad62 1594 switch (etype)
c19d1205 1595 {
5287ad62 1596 case REGLIST_VFP_S:
c19d1205
ZW
1597 regtype = REG_TYPE_VFS;
1598 max_regs = 32;
5287ad62 1599 break;
5f4273c7 1600
5287ad62
JB
1601 case REGLIST_VFP_D:
1602 regtype = REG_TYPE_VFD;
b7fc2769 1603 break;
5f4273c7 1604
b7fc2769
JB
1605 case REGLIST_NEON_D:
1606 regtype = REG_TYPE_NDQ;
1607 break;
1608 }
1609
1610 if (etype != REGLIST_VFP_S)
1611 {
b1cc4aeb
PB
1612 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1613 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1614 {
1615 max_regs = 32;
1616 if (thumb_mode)
1617 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1618 fpu_vfp_ext_d32);
5287ad62
JB
1619 else
1620 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1621 fpu_vfp_ext_d32);
5287ad62
JB
1622 }
1623 else
1624 max_regs = 16;
c19d1205 1625 }
6057a28f 1626
c19d1205 1627 base_reg = max_regs;
a737bd4d 1628
c19d1205
ZW
1629 do
1630 {
5287ad62 1631 int setmask = 1, addregs = 1;
dcbf9037 1632
037e8744 1633 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1634
c19d1205 1635 if (new_base == FAIL)
a737bd4d 1636 {
dcbf9037 1637 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1638 return FAIL;
1639 }
5f4273c7 1640
b7fc2769
JB
1641 if (new_base >= max_regs)
1642 {
1643 first_error (_("register out of range in list"));
1644 return FAIL;
1645 }
5f4273c7 1646
5287ad62
JB
1647 /* Note: a value of 2 * n is returned for the register Q<n>. */
1648 if (regtype == REG_TYPE_NQ)
1649 {
1650 setmask = 3;
1651 addregs = 2;
1652 }
1653
c19d1205
ZW
1654 if (new_base < base_reg)
1655 base_reg = new_base;
a737bd4d 1656
5287ad62 1657 if (mask & (setmask << new_base))
c19d1205 1658 {
dcbf9037 1659 first_error (_("invalid register list"));
c19d1205 1660 return FAIL;
a737bd4d 1661 }
a737bd4d 1662
c19d1205
ZW
1663 if ((mask >> new_base) != 0 && ! warned)
1664 {
1665 as_tsktsk (_("register list not in ascending order"));
1666 warned = 1;
1667 }
0bbf2aa4 1668
5287ad62
JB
1669 mask |= setmask << new_base;
1670 count += addregs;
0bbf2aa4 1671
037e8744 1672 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1673 {
1674 int high_range;
0bbf2aa4 1675
037e8744 1676 str++;
0bbf2aa4 1677
037e8744 1678 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1679 == FAIL)
c19d1205
ZW
1680 {
1681 inst.error = gettext (reg_expected_msgs[regtype]);
1682 return FAIL;
1683 }
0bbf2aa4 1684
b7fc2769
JB
1685 if (high_range >= max_regs)
1686 {
1687 first_error (_("register out of range in list"));
1688 return FAIL;
1689 }
1690
5287ad62
JB
1691 if (regtype == REG_TYPE_NQ)
1692 high_range = high_range + 1;
1693
c19d1205
ZW
1694 if (high_range <= new_base)
1695 {
1696 inst.error = _("register range not in ascending order");
1697 return FAIL;
1698 }
0bbf2aa4 1699
5287ad62 1700 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1701 {
5287ad62 1702 if (mask & (setmask << new_base))
0bbf2aa4 1703 {
c19d1205
ZW
1704 inst.error = _("invalid register list");
1705 return FAIL;
0bbf2aa4 1706 }
c19d1205 1707
5287ad62
JB
1708 mask |= setmask << new_base;
1709 count += addregs;
0bbf2aa4 1710 }
0bbf2aa4 1711 }
0bbf2aa4 1712 }
037e8744 1713 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1714
037e8744 1715 str++;
0bbf2aa4 1716
c19d1205
ZW
1717 /* Sanity check -- should have raised a parse error above. */
1718 if (count == 0 || count > max_regs)
1719 abort ();
1720
1721 *pbase = base_reg;
1722
1723 /* Final test -- the registers must be consecutive. */
1724 mask >>= base_reg;
1725 for (i = 0; i < count; i++)
1726 {
1727 if ((mask & (1u << i)) == 0)
1728 {
1729 inst.error = _("non-contiguous register range");
1730 return FAIL;
1731 }
1732 }
1733
037e8744
JB
1734 *ccp = str;
1735
c19d1205 1736 return count;
b99bd4ef
NC
1737}
1738
dcbf9037
JB
1739/* True if two alias types are the same. */
1740
1741static int
1742neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1743{
1744 if (!a && !b)
1745 return 1;
5f4273c7 1746
dcbf9037
JB
1747 if (!a || !b)
1748 return 0;
1749
1750 if (a->defined != b->defined)
1751 return 0;
5f4273c7 1752
dcbf9037
JB
1753 if ((a->defined & NTA_HASTYPE) != 0
1754 && (a->eltype.type != b->eltype.type
1755 || a->eltype.size != b->eltype.size))
1756 return 0;
1757
1758 if ((a->defined & NTA_HASINDEX) != 0
1759 && (a->index != b->index))
1760 return 0;
5f4273c7 1761
dcbf9037
JB
1762 return 1;
1763}
1764
5287ad62
JB
1765/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1766 The base register is put in *PBASE.
dcbf9037 1767 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1768 the return value.
1769 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1770 Bits [6:5] encode the list length (minus one).
1771 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1772
5287ad62 1773#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1774#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1775#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1776
1777static int
dcbf9037
JB
1778parse_neon_el_struct_list (char **str, unsigned *pbase,
1779 struct neon_type_el *eltype)
5287ad62
JB
1780{
1781 char *ptr = *str;
1782 int base_reg = -1;
1783 int reg_incr = -1;
1784 int count = 0;
1785 int lane = -1;
1786 int leading_brace = 0;
1787 enum arm_reg_type rtype = REG_TYPE_NDQ;
1788 int addregs = 1;
1789 const char *const incr_error = "register stride must be 1 or 2";
1790 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1791 struct neon_typed_alias firsttype;
5f4273c7 1792
5287ad62
JB
1793 if (skip_past_char (&ptr, '{') == SUCCESS)
1794 leading_brace = 1;
5f4273c7 1795
5287ad62
JB
1796 do
1797 {
dcbf9037
JB
1798 struct neon_typed_alias atype;
1799 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1800
5287ad62
JB
1801 if (getreg == FAIL)
1802 {
dcbf9037 1803 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1804 return FAIL;
1805 }
5f4273c7 1806
5287ad62
JB
1807 if (base_reg == -1)
1808 {
1809 base_reg = getreg;
1810 if (rtype == REG_TYPE_NQ)
1811 {
1812 reg_incr = 1;
1813 addregs = 2;
1814 }
dcbf9037 1815 firsttype = atype;
5287ad62
JB
1816 }
1817 else if (reg_incr == -1)
1818 {
1819 reg_incr = getreg - base_reg;
1820 if (reg_incr < 1 || reg_incr > 2)
1821 {
dcbf9037 1822 first_error (_(incr_error));
5287ad62
JB
1823 return FAIL;
1824 }
1825 }
1826 else if (getreg != base_reg + reg_incr * count)
1827 {
dcbf9037
JB
1828 first_error (_(incr_error));
1829 return FAIL;
1830 }
1831
1832 if (!neon_alias_types_same (&atype, &firsttype))
1833 {
1834 first_error (_(type_error));
5287ad62
JB
1835 return FAIL;
1836 }
5f4273c7 1837
5287ad62
JB
1838 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1839 modes. */
1840 if (ptr[0] == '-')
1841 {
dcbf9037 1842 struct neon_typed_alias htype;
5287ad62
JB
1843 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1844 if (lane == -1)
1845 lane = NEON_INTERLEAVE_LANES;
1846 else if (lane != NEON_INTERLEAVE_LANES)
1847 {
dcbf9037 1848 first_error (_(type_error));
5287ad62
JB
1849 return FAIL;
1850 }
1851 if (reg_incr == -1)
1852 reg_incr = 1;
1853 else if (reg_incr != 1)
1854 {
dcbf9037 1855 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1856 return FAIL;
1857 }
1858 ptr++;
dcbf9037 1859 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1860 if (hireg == FAIL)
1861 {
dcbf9037
JB
1862 first_error (_(reg_expected_msgs[rtype]));
1863 return FAIL;
1864 }
1865 if (!neon_alias_types_same (&htype, &firsttype))
1866 {
1867 first_error (_(type_error));
5287ad62
JB
1868 return FAIL;
1869 }
1870 count += hireg + dregs - getreg;
1871 continue;
1872 }
5f4273c7 1873
5287ad62
JB
1874 /* If we're using Q registers, we can't use [] or [n] syntax. */
1875 if (rtype == REG_TYPE_NQ)
1876 {
1877 count += 2;
1878 continue;
1879 }
5f4273c7 1880
dcbf9037 1881 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1882 {
dcbf9037
JB
1883 if (lane == -1)
1884 lane = atype.index;
1885 else if (lane != atype.index)
5287ad62 1886 {
dcbf9037
JB
1887 first_error (_(type_error));
1888 return FAIL;
5287ad62
JB
1889 }
1890 }
1891 else if (lane == -1)
1892 lane = NEON_INTERLEAVE_LANES;
1893 else if (lane != NEON_INTERLEAVE_LANES)
1894 {
dcbf9037 1895 first_error (_(type_error));
5287ad62
JB
1896 return FAIL;
1897 }
1898 count++;
1899 }
1900 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1901
5287ad62
JB
1902 /* No lane set by [x]. We must be interleaving structures. */
1903 if (lane == -1)
1904 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1905
5287ad62
JB
1906 /* Sanity check. */
1907 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1908 || (count > 1 && reg_incr == -1))
1909 {
dcbf9037 1910 first_error (_("error parsing element/structure list"));
5287ad62
JB
1911 return FAIL;
1912 }
1913
1914 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1915 {
dcbf9037 1916 first_error (_("expected }"));
5287ad62
JB
1917 return FAIL;
1918 }
5f4273c7 1919
5287ad62
JB
1920 if (reg_incr == -1)
1921 reg_incr = 1;
1922
dcbf9037
JB
1923 if (eltype)
1924 *eltype = firsttype.eltype;
1925
5287ad62
JB
1926 *pbase = base_reg;
1927 *str = ptr;
5f4273c7 1928
5287ad62
JB
1929 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1930}
1931
c19d1205
ZW
1932/* Parse an explicit relocation suffix on an expression. This is
1933 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1934 arm_reloc_hsh contains no entries, so this function can only
1935 succeed if there is no () after the word. Returns -1 on error,
1936 BFD_RELOC_UNUSED if there wasn't any suffix. */
1937static int
1938parse_reloc (char **str)
b99bd4ef 1939{
c19d1205
ZW
1940 struct reloc_entry *r;
1941 char *p, *q;
b99bd4ef 1942
c19d1205
ZW
1943 if (**str != '(')
1944 return BFD_RELOC_UNUSED;
b99bd4ef 1945
c19d1205
ZW
1946 p = *str + 1;
1947 q = p;
1948
1949 while (*q && *q != ')' && *q != ',')
1950 q++;
1951 if (*q != ')')
1952 return -1;
1953
1954 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1955 return -1;
1956
1957 *str = q + 1;
1958 return r->reloc;
b99bd4ef
NC
1959}
1960
c19d1205
ZW
1961/* Directives: register aliases. */
1962
dcbf9037 1963static struct reg_entry *
c19d1205 1964insert_reg_alias (char *str, int number, int type)
b99bd4ef 1965{
c19d1205
ZW
1966 struct reg_entry *new;
1967 const char *name;
b99bd4ef 1968
c19d1205
ZW
1969 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1970 {
1971 if (new->builtin)
1972 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1973
c19d1205
ZW
1974 /* Only warn about a redefinition if it's not defined as the
1975 same register. */
1976 else if (new->number != number || new->type != type)
1977 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1978
d929913e 1979 return NULL;
c19d1205 1980 }
b99bd4ef 1981
c19d1205
ZW
1982 name = xstrdup (str);
1983 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1984
c19d1205
ZW
1985 new->name = name;
1986 new->number = number;
1987 new->type = type;
1988 new->builtin = FALSE;
dcbf9037 1989 new->neon = NULL;
b99bd4ef 1990
c19d1205
ZW
1991 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1992 abort ();
5f4273c7 1993
dcbf9037
JB
1994 return new;
1995}
1996
1997static void
1998insert_neon_reg_alias (char *str, int number, int type,
1999 struct neon_typed_alias *atype)
2000{
2001 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2002
dcbf9037
JB
2003 if (!reg)
2004 {
2005 first_error (_("attempt to redefine typed alias"));
2006 return;
2007 }
5f4273c7 2008
dcbf9037
JB
2009 if (atype)
2010 {
2011 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2012 *reg->neon = *atype;
2013 }
c19d1205 2014}
b99bd4ef 2015
c19d1205 2016/* Look for the .req directive. This is of the form:
b99bd4ef 2017
c19d1205 2018 new_register_name .req existing_register_name
b99bd4ef 2019
c19d1205 2020 If we find one, or if it looks sufficiently like one that we want to
d929913e 2021 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2022
d929913e 2023static bfd_boolean
c19d1205
ZW
2024create_register_alias (char * newname, char *p)
2025{
2026 struct reg_entry *old;
2027 char *oldname, *nbuf;
2028 size_t nlen;
b99bd4ef 2029
c19d1205
ZW
2030 /* The input scrubber ensures that whitespace after the mnemonic is
2031 collapsed to single spaces. */
2032 oldname = p;
2033 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2034 return FALSE;
b99bd4ef 2035
c19d1205
ZW
2036 oldname += 6;
2037 if (*oldname == '\0')
d929913e 2038 return FALSE;
b99bd4ef 2039
c19d1205
ZW
2040 old = hash_find (arm_reg_hsh, oldname);
2041 if (!old)
b99bd4ef 2042 {
c19d1205 2043 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2044 return TRUE;
b99bd4ef
NC
2045 }
2046
c19d1205
ZW
2047 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2048 the desired alias name, and p points to its end. If not, then
2049 the desired alias name is in the global original_case_string. */
2050#ifdef TC_CASE_SENSITIVE
2051 nlen = p - newname;
2052#else
2053 newname = original_case_string;
2054 nlen = strlen (newname);
2055#endif
b99bd4ef 2056
c19d1205
ZW
2057 nbuf = alloca (nlen + 1);
2058 memcpy (nbuf, newname, nlen);
2059 nbuf[nlen] = '\0';
b99bd4ef 2060
c19d1205
ZW
2061 /* Create aliases under the new name as stated; an all-lowercase
2062 version of the new name; and an all-uppercase version of the new
2063 name. */
d929913e
NC
2064 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2065 {
2066 for (p = nbuf; *p; p++)
2067 *p = TOUPPER (*p);
c19d1205 2068
d929913e
NC
2069 if (strncmp (nbuf, newname, nlen))
2070 {
2071 /* If this attempt to create an additional alias fails, do not bother
2072 trying to create the all-lower case alias. We will fail and issue
2073 a second, duplicate error message. This situation arises when the
2074 programmer does something like:
2075 foo .req r0
2076 Foo .req r1
2077 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2078 the artificial FOO alias because it has already been created by the
d929913e
NC
2079 first .req. */
2080 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2081 return TRUE;
2082 }
c19d1205 2083
d929913e
NC
2084 for (p = nbuf; *p; p++)
2085 *p = TOLOWER (*p);
c19d1205 2086
d929913e
NC
2087 if (strncmp (nbuf, newname, nlen))
2088 insert_reg_alias (nbuf, old->number, old->type);
2089 }
c19d1205 2090
d929913e 2091 return TRUE;
b99bd4ef
NC
2092}
2093
dcbf9037
JB
2094/* Create a Neon typed/indexed register alias using directives, e.g.:
2095 X .dn d5.s32[1]
2096 Y .qn 6.s16
2097 Z .dn d7
2098 T .dn Z[0]
2099 These typed registers can be used instead of the types specified after the
2100 Neon mnemonic, so long as all operands given have types. Types can also be
2101 specified directly, e.g.:
5f4273c7 2102 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2103
2104static int
2105create_neon_reg_alias (char *newname, char *p)
2106{
2107 enum arm_reg_type basetype;
2108 struct reg_entry *basereg;
2109 struct reg_entry mybasereg;
2110 struct neon_type ntype;
2111 struct neon_typed_alias typeinfo;
2112 char *namebuf, *nameend;
2113 int namelen;
5f4273c7 2114
dcbf9037
JB
2115 typeinfo.defined = 0;
2116 typeinfo.eltype.type = NT_invtype;
2117 typeinfo.eltype.size = -1;
2118 typeinfo.index = -1;
5f4273c7 2119
dcbf9037 2120 nameend = p;
5f4273c7 2121
dcbf9037
JB
2122 if (strncmp (p, " .dn ", 5) == 0)
2123 basetype = REG_TYPE_VFD;
2124 else if (strncmp (p, " .qn ", 5) == 0)
2125 basetype = REG_TYPE_NQ;
2126 else
2127 return 0;
5f4273c7 2128
dcbf9037 2129 p += 5;
5f4273c7 2130
dcbf9037
JB
2131 if (*p == '\0')
2132 return 0;
5f4273c7 2133
dcbf9037
JB
2134 basereg = arm_reg_parse_multi (&p);
2135
2136 if (basereg && basereg->type != basetype)
2137 {
2138 as_bad (_("bad type for register"));
2139 return 0;
2140 }
2141
2142 if (basereg == NULL)
2143 {
2144 expressionS exp;
2145 /* Try parsing as an integer. */
2146 my_get_expression (&exp, &p, GE_NO_PREFIX);
2147 if (exp.X_op != O_constant)
2148 {
2149 as_bad (_("expression must be constant"));
2150 return 0;
2151 }
2152 basereg = &mybasereg;
2153 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2154 : exp.X_add_number;
2155 basereg->neon = 0;
2156 }
2157
2158 if (basereg->neon)
2159 typeinfo = *basereg->neon;
2160
2161 if (parse_neon_type (&ntype, &p) == SUCCESS)
2162 {
2163 /* We got a type. */
2164 if (typeinfo.defined & NTA_HASTYPE)
2165 {
2166 as_bad (_("can't redefine the type of a register alias"));
2167 return 0;
2168 }
5f4273c7 2169
dcbf9037
JB
2170 typeinfo.defined |= NTA_HASTYPE;
2171 if (ntype.elems != 1)
2172 {
2173 as_bad (_("you must specify a single type only"));
2174 return 0;
2175 }
2176 typeinfo.eltype = ntype.el[0];
2177 }
5f4273c7 2178
dcbf9037
JB
2179 if (skip_past_char (&p, '[') == SUCCESS)
2180 {
2181 expressionS exp;
2182 /* We got a scalar index. */
5f4273c7 2183
dcbf9037
JB
2184 if (typeinfo.defined & NTA_HASINDEX)
2185 {
2186 as_bad (_("can't redefine the index of a scalar alias"));
2187 return 0;
2188 }
5f4273c7 2189
dcbf9037 2190 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2191
dcbf9037
JB
2192 if (exp.X_op != O_constant)
2193 {
2194 as_bad (_("scalar index must be constant"));
2195 return 0;
2196 }
5f4273c7 2197
dcbf9037
JB
2198 typeinfo.defined |= NTA_HASINDEX;
2199 typeinfo.index = exp.X_add_number;
5f4273c7 2200
dcbf9037
JB
2201 if (skip_past_char (&p, ']') == FAIL)
2202 {
2203 as_bad (_("expecting ]"));
2204 return 0;
2205 }
2206 }
2207
2208 namelen = nameend - newname;
2209 namebuf = alloca (namelen + 1);
2210 strncpy (namebuf, newname, namelen);
2211 namebuf[namelen] = '\0';
5f4273c7 2212
dcbf9037
JB
2213 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2214 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2215
dcbf9037
JB
2216 /* Insert name in all uppercase. */
2217 for (p = namebuf; *p; p++)
2218 *p = TOUPPER (*p);
5f4273c7 2219
dcbf9037
JB
2220 if (strncmp (namebuf, newname, namelen))
2221 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2222 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2223
dcbf9037
JB
2224 /* Insert name in all lowercase. */
2225 for (p = namebuf; *p; p++)
2226 *p = TOLOWER (*p);
5f4273c7 2227
dcbf9037
JB
2228 if (strncmp (namebuf, newname, namelen))
2229 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2230 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2231
dcbf9037
JB
2232 return 1;
2233}
2234
c19d1205
ZW
2235/* Should never be called, as .req goes between the alias and the
2236 register name, not at the beginning of the line. */
b99bd4ef 2237static void
c19d1205 2238s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2239{
c19d1205
ZW
2240 as_bad (_("invalid syntax for .req directive"));
2241}
b99bd4ef 2242
dcbf9037
JB
2243static void
2244s_dn (int a ATTRIBUTE_UNUSED)
2245{
2246 as_bad (_("invalid syntax for .dn directive"));
2247}
2248
2249static void
2250s_qn (int a ATTRIBUTE_UNUSED)
2251{
2252 as_bad (_("invalid syntax for .qn directive"));
2253}
2254
c19d1205
ZW
2255/* The .unreq directive deletes an alias which was previously defined
2256 by .req. For example:
b99bd4ef 2257
c19d1205
ZW
2258 my_alias .req r11
2259 .unreq my_alias */
b99bd4ef
NC
2260
2261static void
c19d1205 2262s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2263{
c19d1205
ZW
2264 char * name;
2265 char saved_char;
b99bd4ef 2266
c19d1205
ZW
2267 name = input_line_pointer;
2268
2269 while (*input_line_pointer != 0
2270 && *input_line_pointer != ' '
2271 && *input_line_pointer != '\n')
2272 ++input_line_pointer;
2273
2274 saved_char = *input_line_pointer;
2275 *input_line_pointer = 0;
2276
2277 if (!*name)
2278 as_bad (_("invalid syntax for .unreq directive"));
2279 else
2280 {
2281 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2282
2283 if (!reg)
2284 as_bad (_("unknown register alias '%s'"), name);
2285 else if (reg->builtin)
2286 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2287 name);
2288 else
2289 {
d929913e
NC
2290 char * p;
2291 char * nbuf;
2292
c19d1205
ZW
2293 hash_delete (arm_reg_hsh, name);
2294 free ((char *) reg->name);
dcbf9037
JB
2295 if (reg->neon)
2296 free (reg->neon);
c19d1205 2297 free (reg);
d929913e
NC
2298
2299 /* Also locate the all upper case and all lower case versions.
2300 Do not complain if we cannot find one or the other as it
2301 was probably deleted above. */
5f4273c7 2302
d929913e
NC
2303 nbuf = strdup (name);
2304 for (p = nbuf; *p; p++)
2305 *p = TOUPPER (*p);
2306 reg = hash_find (arm_reg_hsh, nbuf);
2307 if (reg)
2308 {
2309 hash_delete (arm_reg_hsh, nbuf);
2310 free ((char *) reg->name);
2311 if (reg->neon)
2312 free (reg->neon);
2313 free (reg);
2314 }
2315
2316 for (p = nbuf; *p; p++)
2317 *p = TOLOWER (*p);
2318 reg = hash_find (arm_reg_hsh, nbuf);
2319 if (reg)
2320 {
2321 hash_delete (arm_reg_hsh, nbuf);
2322 free ((char *) reg->name);
2323 if (reg->neon)
2324 free (reg->neon);
2325 free (reg);
2326 }
2327
2328 free (nbuf);
c19d1205
ZW
2329 }
2330 }
b99bd4ef 2331
c19d1205 2332 *input_line_pointer = saved_char;
b99bd4ef
NC
2333 demand_empty_rest_of_line ();
2334}
2335
c19d1205
ZW
2336/* Directives: Instruction set selection. */
2337
2338#ifdef OBJ_ELF
2339/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2340 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2341 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2342 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2343
2344static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2345
e821645d 2346void
c19d1205 2347mapping_state (enum mstate state)
b99bd4ef 2348{
a737bd4d 2349 symbolS * symbolP;
c19d1205
ZW
2350 const char * symname;
2351 int type;
b99bd4ef 2352
c19d1205
ZW
2353 if (mapstate == state)
2354 /* The mapping symbol has already been emitted.
2355 There is nothing else to do. */
2356 return;
b99bd4ef 2357
c19d1205 2358 mapstate = state;
b99bd4ef 2359
c19d1205 2360 switch (state)
b99bd4ef 2361 {
c19d1205
ZW
2362 case MAP_DATA:
2363 symname = "$d";
2364 type = BSF_NO_FLAGS;
2365 break;
2366 case MAP_ARM:
2367 symname = "$a";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_THUMB:
2371 symname = "$t";
2372 type = BSF_NO_FLAGS;
2373 break;
2374 case MAP_UNDEFINED:
2375 return;
2376 default:
2377 abort ();
2378 }
2379
2380 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2381
2382 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2383 symbol_table_insert (symbolP);
2384 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2385
2386 switch (state)
2387 {
2388 case MAP_ARM:
2389 THUMB_SET_FUNC (symbolP, 0);
2390 ARM_SET_THUMB (symbolP, 0);
2391 ARM_SET_INTERWORK (symbolP, support_interwork);
2392 break;
2393
2394 case MAP_THUMB:
2395 THUMB_SET_FUNC (symbolP, 1);
2396 ARM_SET_THUMB (symbolP, 1);
2397 ARM_SET_INTERWORK (symbolP, support_interwork);
2398 break;
2399
2400 case MAP_DATA:
2401 default:
2402 return;
2403 }
2404}
2405#else
2406#define mapping_state(x) /* nothing */
2407#endif
2408
2409/* Find the real, Thumb encoded start of a Thumb function. */
2410
2411static symbolS *
2412find_real_start (symbolS * symbolP)
2413{
2414 char * real_start;
2415 const char * name = S_GET_NAME (symbolP);
2416 symbolS * new_target;
2417
2418 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2419#define STUB_NAME ".real_start_of"
2420
2421 if (name == NULL)
2422 abort ();
2423
37f6032b
ZW
2424 /* The compiler may generate BL instructions to local labels because
2425 it needs to perform a branch to a far away location. These labels
2426 do not have a corresponding ".real_start_of" label. We check
2427 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2428 the ".real_start_of" convention for nonlocal branches. */
2429 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2430 return symbolP;
2431
37f6032b 2432 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2433 new_target = symbol_find (real_start);
2434
2435 if (new_target == NULL)
2436 {
bd3ba5d1 2437 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2438 new_target = symbolP;
2439 }
2440
c19d1205
ZW
2441 return new_target;
2442}
2443
2444static void
2445opcode_select (int width)
2446{
2447 switch (width)
2448 {
2449 case 16:
2450 if (! thumb_mode)
2451 {
e74cfd16 2452 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2453 as_bad (_("selected processor does not support THUMB opcodes"));
2454
2455 thumb_mode = 1;
2456 /* No need to force the alignment, since we will have been
2457 coming from ARM mode, which is word-aligned. */
2458 record_alignment (now_seg, 1);
2459 }
2460 mapping_state (MAP_THUMB);
2461 break;
2462
2463 case 32:
2464 if (thumb_mode)
2465 {
e74cfd16 2466 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2467 as_bad (_("selected processor does not support ARM opcodes"));
2468
2469 thumb_mode = 0;
2470
2471 if (!need_pass_2)
2472 frag_align (2, 0, 0);
2473
2474 record_alignment (now_seg, 1);
2475 }
2476 mapping_state (MAP_ARM);
2477 break;
2478
2479 default:
2480 as_bad (_("invalid instruction size selected (%d)"), width);
2481 }
2482}
2483
2484static void
2485s_arm (int ignore ATTRIBUTE_UNUSED)
2486{
2487 opcode_select (32);
2488 demand_empty_rest_of_line ();
2489}
2490
2491static void
2492s_thumb (int ignore ATTRIBUTE_UNUSED)
2493{
2494 opcode_select (16);
2495 demand_empty_rest_of_line ();
2496}
2497
2498static void
2499s_code (int unused ATTRIBUTE_UNUSED)
2500{
2501 int temp;
2502
2503 temp = get_absolute_expression ();
2504 switch (temp)
2505 {
2506 case 16:
2507 case 32:
2508 opcode_select (temp);
2509 break;
2510
2511 default:
2512 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2513 }
2514}
2515
2516static void
2517s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2518{
2519 /* If we are not already in thumb mode go into it, EVEN if
2520 the target processor does not support thumb instructions.
2521 This is used by gcc/config/arm/lib1funcs.asm for example
2522 to compile interworking support functions even if the
2523 target processor should not support interworking. */
2524 if (! thumb_mode)
2525 {
2526 thumb_mode = 2;
2527 record_alignment (now_seg, 1);
2528 }
2529
2530 demand_empty_rest_of_line ();
2531}
2532
2533static void
2534s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2535{
2536 s_thumb (0);
2537
2538 /* The following label is the name/address of the start of a Thumb function.
2539 We need to know this for the interworking support. */
2540 label_is_thumb_function_name = TRUE;
2541}
2542
2543/* Perform a .set directive, but also mark the alias as
2544 being a thumb function. */
2545
2546static void
2547s_thumb_set (int equiv)
2548{
2549 /* XXX the following is a duplicate of the code for s_set() in read.c
2550 We cannot just call that code as we need to get at the symbol that
2551 is created. */
2552 char * name;
2553 char delim;
2554 char * end_name;
2555 symbolS * symbolP;
2556
2557 /* Especial apologies for the random logic:
2558 This just grew, and could be parsed much more simply!
2559 Dean - in haste. */
2560 name = input_line_pointer;
2561 delim = get_symbol_end ();
2562 end_name = input_line_pointer;
2563 *end_name = delim;
2564
2565 if (*input_line_pointer != ',')
2566 {
2567 *end_name = 0;
2568 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2569 *end_name = delim;
2570 ignore_rest_of_line ();
2571 return;
2572 }
2573
2574 input_line_pointer++;
2575 *end_name = 0;
2576
2577 if (name[0] == '.' && name[1] == '\0')
2578 {
2579 /* XXX - this should not happen to .thumb_set. */
2580 abort ();
2581 }
2582
2583 if ((symbolP = symbol_find (name)) == NULL
2584 && (symbolP = md_undefined_symbol (name)) == NULL)
2585 {
2586#ifndef NO_LISTING
2587 /* When doing symbol listings, play games with dummy fragments living
2588 outside the normal fragment chain to record the file and line info
c19d1205 2589 for this symbol. */
b99bd4ef
NC
2590 if (listing & LISTING_SYMBOLS)
2591 {
2592 extern struct list_info_struct * listing_tail;
a737bd4d 2593 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2594
2595 memset (dummy_frag, 0, sizeof (fragS));
2596 dummy_frag->fr_type = rs_fill;
2597 dummy_frag->line = listing_tail;
2598 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2599 dummy_frag->fr_symbol = symbolP;
2600 }
2601 else
2602#endif
2603 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2604
2605#ifdef OBJ_COFF
2606 /* "set" symbols are local unless otherwise specified. */
2607 SF_SET_LOCAL (symbolP);
2608#endif /* OBJ_COFF */
2609 } /* Make a new symbol. */
2610
2611 symbol_table_insert (symbolP);
2612
2613 * end_name = delim;
2614
2615 if (equiv
2616 && S_IS_DEFINED (symbolP)
2617 && S_GET_SEGMENT (symbolP) != reg_section)
2618 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2619
2620 pseudo_set (symbolP);
2621
2622 demand_empty_rest_of_line ();
2623
c19d1205 2624 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2625
2626 THUMB_SET_FUNC (symbolP, 1);
2627 ARM_SET_THUMB (symbolP, 1);
2628#if defined OBJ_ELF || defined OBJ_COFF
2629 ARM_SET_INTERWORK (symbolP, support_interwork);
2630#endif
2631}
2632
c19d1205 2633/* Directives: Mode selection. */
b99bd4ef 2634
c19d1205
ZW
2635/* .syntax [unified|divided] - choose the new unified syntax
2636 (same for Arm and Thumb encoding, modulo slight differences in what
2637 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2638static void
c19d1205 2639s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2640{
c19d1205
ZW
2641 char *name, delim;
2642
2643 name = input_line_pointer;
2644 delim = get_symbol_end ();
2645
2646 if (!strcasecmp (name, "unified"))
2647 unified_syntax = TRUE;
2648 else if (!strcasecmp (name, "divided"))
2649 unified_syntax = FALSE;
2650 else
2651 {
2652 as_bad (_("unrecognized syntax mode \"%s\""), name);
2653 return;
2654 }
2655 *input_line_pointer = delim;
b99bd4ef
NC
2656 demand_empty_rest_of_line ();
2657}
2658
c19d1205
ZW
2659/* Directives: sectioning and alignment. */
2660
2661/* Same as s_align_ptwo but align 0 => align 2. */
2662
b99bd4ef 2663static void
c19d1205 2664s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2665{
a737bd4d 2666 int temp;
dce323d1 2667 bfd_boolean fill_p;
c19d1205
ZW
2668 long temp_fill;
2669 long max_alignment = 15;
b99bd4ef
NC
2670
2671 temp = get_absolute_expression ();
c19d1205
ZW
2672 if (temp > max_alignment)
2673 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2674 else if (temp < 0)
b99bd4ef 2675 {
c19d1205
ZW
2676 as_bad (_("alignment negative. 0 assumed."));
2677 temp = 0;
2678 }
b99bd4ef 2679
c19d1205
ZW
2680 if (*input_line_pointer == ',')
2681 {
2682 input_line_pointer++;
2683 temp_fill = get_absolute_expression ();
dce323d1 2684 fill_p = TRUE;
b99bd4ef 2685 }
c19d1205 2686 else
dce323d1
PB
2687 {
2688 fill_p = FALSE;
2689 temp_fill = 0;
2690 }
b99bd4ef 2691
c19d1205
ZW
2692 if (!temp)
2693 temp = 2;
b99bd4ef 2694
c19d1205
ZW
2695 /* Only make a frag if we HAVE to. */
2696 if (temp && !need_pass_2)
dce323d1
PB
2697 {
2698 if (!fill_p && subseg_text_p (now_seg))
2699 frag_align_code (temp, 0);
2700 else
2701 frag_align (temp, (int) temp_fill, 0);
2702 }
c19d1205
ZW
2703 demand_empty_rest_of_line ();
2704
2705 record_alignment (now_seg, temp);
b99bd4ef
NC
2706}
2707
c19d1205
ZW
2708static void
2709s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2710{
c19d1205
ZW
2711 /* We don't support putting frags in the BSS segment, we fake it by
2712 marking in_bss, then looking at s_skip for clues. */
2713 subseg_set (bss_section, 0);
2714 demand_empty_rest_of_line ();
2715 mapping_state (MAP_DATA);
2716}
b99bd4ef 2717
c19d1205
ZW
2718static void
2719s_even (int ignore ATTRIBUTE_UNUSED)
2720{
2721 /* Never make frag if expect extra pass. */
2722 if (!need_pass_2)
2723 frag_align (1, 0, 0);
b99bd4ef 2724
c19d1205 2725 record_alignment (now_seg, 1);
b99bd4ef 2726
c19d1205 2727 demand_empty_rest_of_line ();
b99bd4ef
NC
2728}
2729
c19d1205 2730/* Directives: Literal pools. */
a737bd4d 2731
c19d1205
ZW
2732static literal_pool *
2733find_literal_pool (void)
a737bd4d 2734{
c19d1205 2735 literal_pool * pool;
a737bd4d 2736
c19d1205 2737 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2738 {
c19d1205
ZW
2739 if (pool->section == now_seg
2740 && pool->sub_section == now_subseg)
2741 break;
a737bd4d
NC
2742 }
2743
c19d1205 2744 return pool;
a737bd4d
NC
2745}
2746
c19d1205
ZW
2747static literal_pool *
2748find_or_make_literal_pool (void)
a737bd4d 2749{
c19d1205
ZW
2750 /* Next literal pool ID number. */
2751 static unsigned int latest_pool_num = 1;
2752 literal_pool * pool;
a737bd4d 2753
c19d1205 2754 pool = find_literal_pool ();
a737bd4d 2755
c19d1205 2756 if (pool == NULL)
a737bd4d 2757 {
c19d1205
ZW
2758 /* Create a new pool. */
2759 pool = xmalloc (sizeof (* pool));
2760 if (! pool)
2761 return NULL;
a737bd4d 2762
c19d1205
ZW
2763 pool->next_free_entry = 0;
2764 pool->section = now_seg;
2765 pool->sub_section = now_subseg;
2766 pool->next = list_of_pools;
2767 pool->symbol = NULL;
2768
2769 /* Add it to the list. */
2770 list_of_pools = pool;
a737bd4d 2771 }
a737bd4d 2772
c19d1205
ZW
2773 /* New pools, and emptied pools, will have a NULL symbol. */
2774 if (pool->symbol == NULL)
a737bd4d 2775 {
c19d1205
ZW
2776 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2777 (valueT) 0, &zero_address_frag);
2778 pool->id = latest_pool_num ++;
a737bd4d
NC
2779 }
2780
c19d1205
ZW
2781 /* Done. */
2782 return pool;
a737bd4d
NC
2783}
2784
c19d1205 2785/* Add the literal in the global 'inst'
5f4273c7 2786 structure to the relevant literal pool. */
b99bd4ef
NC
2787
2788static int
c19d1205 2789add_to_lit_pool (void)
b99bd4ef 2790{
c19d1205
ZW
2791 literal_pool * pool;
2792 unsigned int entry;
b99bd4ef 2793
c19d1205
ZW
2794 pool = find_or_make_literal_pool ();
2795
2796 /* Check if this literal value is already in the pool. */
2797 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2798 {
c19d1205
ZW
2799 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2800 && (inst.reloc.exp.X_op == O_constant)
2801 && (pool->literals[entry].X_add_number
2802 == inst.reloc.exp.X_add_number)
2803 && (pool->literals[entry].X_unsigned
2804 == inst.reloc.exp.X_unsigned))
2805 break;
2806
2807 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2808 && (inst.reloc.exp.X_op == O_symbol)
2809 && (pool->literals[entry].X_add_number
2810 == inst.reloc.exp.X_add_number)
2811 && (pool->literals[entry].X_add_symbol
2812 == inst.reloc.exp.X_add_symbol)
2813 && (pool->literals[entry].X_op_symbol
2814 == inst.reloc.exp.X_op_symbol))
2815 break;
b99bd4ef
NC
2816 }
2817
c19d1205
ZW
2818 /* Do we need to create a new entry? */
2819 if (entry == pool->next_free_entry)
2820 {
2821 if (entry >= MAX_LITERAL_POOL_SIZE)
2822 {
2823 inst.error = _("literal pool overflow");
2824 return FAIL;
2825 }
2826
2827 pool->literals[entry] = inst.reloc.exp;
2828 pool->next_free_entry += 1;
2829 }
b99bd4ef 2830
c19d1205
ZW
2831 inst.reloc.exp.X_op = O_symbol;
2832 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2833 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2834
c19d1205 2835 return SUCCESS;
b99bd4ef
NC
2836}
2837
c19d1205
ZW
2838/* Can't use symbol_new here, so have to create a symbol and then at
2839 a later date assign it a value. Thats what these functions do. */
e16bb312 2840
c19d1205
ZW
2841static void
2842symbol_locate (symbolS * symbolP,
2843 const char * name, /* It is copied, the caller can modify. */
2844 segT segment, /* Segment identifier (SEG_<something>). */
2845 valueT valu, /* Symbol value. */
2846 fragS * frag) /* Associated fragment. */
2847{
2848 unsigned int name_length;
2849 char * preserved_copy_of_name;
e16bb312 2850
c19d1205
ZW
2851 name_length = strlen (name) + 1; /* +1 for \0. */
2852 obstack_grow (&notes, name, name_length);
2853 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2854
c19d1205
ZW
2855#ifdef tc_canonicalize_symbol_name
2856 preserved_copy_of_name =
2857 tc_canonicalize_symbol_name (preserved_copy_of_name);
2858#endif
b99bd4ef 2859
c19d1205 2860 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2861
c19d1205
ZW
2862 S_SET_SEGMENT (symbolP, segment);
2863 S_SET_VALUE (symbolP, valu);
2864 symbol_clear_list_pointers (symbolP);
b99bd4ef 2865
c19d1205 2866 symbol_set_frag (symbolP, frag);
b99bd4ef 2867
c19d1205
ZW
2868 /* Link to end of symbol chain. */
2869 {
2870 extern int symbol_table_frozen;
b99bd4ef 2871
c19d1205
ZW
2872 if (symbol_table_frozen)
2873 abort ();
2874 }
b99bd4ef 2875
c19d1205 2876 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2877
c19d1205 2878 obj_symbol_new_hook (symbolP);
b99bd4ef 2879
c19d1205
ZW
2880#ifdef tc_symbol_new_hook
2881 tc_symbol_new_hook (symbolP);
2882#endif
2883
2884#ifdef DEBUG_SYMS
2885 verify_symbol_chain (symbol_rootP, symbol_lastP);
2886#endif /* DEBUG_SYMS */
b99bd4ef
NC
2887}
2888
b99bd4ef 2889
c19d1205
ZW
2890static void
2891s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2892{
c19d1205
ZW
2893 unsigned int entry;
2894 literal_pool * pool;
2895 char sym_name[20];
b99bd4ef 2896
c19d1205
ZW
2897 pool = find_literal_pool ();
2898 if (pool == NULL
2899 || pool->symbol == NULL
2900 || pool->next_free_entry == 0)
2901 return;
b99bd4ef 2902
c19d1205 2903 mapping_state (MAP_DATA);
b99bd4ef 2904
c19d1205
ZW
2905 /* Align pool as you have word accesses.
2906 Only make a frag if we have to. */
2907 if (!need_pass_2)
2908 frag_align (2, 0, 0);
b99bd4ef 2909
c19d1205 2910 record_alignment (now_seg, 2);
b99bd4ef 2911
c19d1205 2912 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2913
c19d1205
ZW
2914 symbol_locate (pool->symbol, sym_name, now_seg,
2915 (valueT) frag_now_fix (), frag_now);
2916 symbol_table_insert (pool->symbol);
b99bd4ef 2917
c19d1205 2918 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2919
c19d1205
ZW
2920#if defined OBJ_COFF || defined OBJ_ELF
2921 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2922#endif
6c43fab6 2923
c19d1205
ZW
2924 for (entry = 0; entry < pool->next_free_entry; entry ++)
2925 /* First output the expression in the instruction to the pool. */
2926 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2927
c19d1205
ZW
2928 /* Mark the pool as empty. */
2929 pool->next_free_entry = 0;
2930 pool->symbol = NULL;
b99bd4ef
NC
2931}
2932
c19d1205
ZW
2933#ifdef OBJ_ELF
2934/* Forward declarations for functions below, in the MD interface
2935 section. */
2936static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2937static valueT create_unwind_entry (int);
2938static void start_unwind_section (const segT, int);
2939static void add_unwind_opcode (valueT, int);
2940static void flush_pending_unwind (void);
b99bd4ef 2941
c19d1205 2942/* Directives: Data. */
b99bd4ef 2943
c19d1205
ZW
2944static void
2945s_arm_elf_cons (int nbytes)
2946{
2947 expressionS exp;
b99bd4ef 2948
c19d1205
ZW
2949#ifdef md_flush_pending_output
2950 md_flush_pending_output ();
2951#endif
b99bd4ef 2952
c19d1205 2953 if (is_it_end_of_statement ())
b99bd4ef 2954 {
c19d1205
ZW
2955 demand_empty_rest_of_line ();
2956 return;
b99bd4ef
NC
2957 }
2958
c19d1205
ZW
2959#ifdef md_cons_align
2960 md_cons_align (nbytes);
2961#endif
b99bd4ef 2962
c19d1205
ZW
2963 mapping_state (MAP_DATA);
2964 do
b99bd4ef 2965 {
c19d1205
ZW
2966 int reloc;
2967 char *base = input_line_pointer;
b99bd4ef 2968
c19d1205 2969 expression (& exp);
b99bd4ef 2970
c19d1205
ZW
2971 if (exp.X_op != O_symbol)
2972 emit_expr (&exp, (unsigned int) nbytes);
2973 else
2974 {
2975 char *before_reloc = input_line_pointer;
2976 reloc = parse_reloc (&input_line_pointer);
2977 if (reloc == -1)
2978 {
2979 as_bad (_("unrecognized relocation suffix"));
2980 ignore_rest_of_line ();
2981 return;
2982 }
2983 else if (reloc == BFD_RELOC_UNUSED)
2984 emit_expr (&exp, (unsigned int) nbytes);
2985 else
2986 {
2987 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2988 int size = bfd_get_reloc_size (howto);
b99bd4ef 2989
2fc8bdac
ZW
2990 if (reloc == BFD_RELOC_ARM_PLT32)
2991 {
2992 as_bad (_("(plt) is only valid on branch targets"));
2993 reloc = BFD_RELOC_UNUSED;
2994 size = 0;
2995 }
2996
c19d1205 2997 if (size > nbytes)
2fc8bdac 2998 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2999 howto->name, nbytes);
3000 else
3001 {
3002 /* We've parsed an expression stopping at O_symbol.
3003 But there may be more expression left now that we
3004 have parsed the relocation marker. Parse it again.
3005 XXX Surely there is a cleaner way to do this. */
3006 char *p = input_line_pointer;
3007 int offset;
3008 char *save_buf = alloca (input_line_pointer - base);
3009 memcpy (save_buf, base, input_line_pointer - base);
3010 memmove (base + (input_line_pointer - before_reloc),
3011 base, before_reloc - base);
3012
3013 input_line_pointer = base + (input_line_pointer-before_reloc);
3014 expression (&exp);
3015 memcpy (base, save_buf, p - base);
3016
3017 offset = nbytes - size;
3018 p = frag_more ((int) nbytes);
3019 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3020 size, &exp, 0, reloc);
3021 }
3022 }
3023 }
b99bd4ef 3024 }
c19d1205 3025 while (*input_line_pointer++ == ',');
b99bd4ef 3026
c19d1205
ZW
3027 /* Put terminator back into stream. */
3028 input_line_pointer --;
3029 demand_empty_rest_of_line ();
b99bd4ef
NC
3030}
3031
b99bd4ef 3032
c19d1205 3033/* Parse a .rel31 directive. */
b99bd4ef 3034
c19d1205
ZW
3035static void
3036s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3037{
3038 expressionS exp;
3039 char *p;
3040 valueT highbit;
b99bd4ef 3041
c19d1205
ZW
3042 highbit = 0;
3043 if (*input_line_pointer == '1')
3044 highbit = 0x80000000;
3045 else if (*input_line_pointer != '0')
3046 as_bad (_("expected 0 or 1"));
b99bd4ef 3047
c19d1205
ZW
3048 input_line_pointer++;
3049 if (*input_line_pointer != ',')
3050 as_bad (_("missing comma"));
3051 input_line_pointer++;
b99bd4ef 3052
c19d1205
ZW
3053#ifdef md_flush_pending_output
3054 md_flush_pending_output ();
3055#endif
b99bd4ef 3056
c19d1205
ZW
3057#ifdef md_cons_align
3058 md_cons_align (4);
3059#endif
b99bd4ef 3060
c19d1205 3061 mapping_state (MAP_DATA);
b99bd4ef 3062
c19d1205 3063 expression (&exp);
b99bd4ef 3064
c19d1205
ZW
3065 p = frag_more (4);
3066 md_number_to_chars (p, highbit, 4);
3067 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3068 BFD_RELOC_ARM_PREL31);
b99bd4ef 3069
c19d1205 3070 demand_empty_rest_of_line ();
b99bd4ef
NC
3071}
3072
c19d1205 3073/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3074
c19d1205 3075/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3076
c19d1205
ZW
3077static void
3078s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3079{
3080 demand_empty_rest_of_line ();
3081 /* Mark the start of the function. */
3082 unwind.proc_start = expr_build_dot ();
b99bd4ef 3083
c19d1205
ZW
3084 /* Reset the rest of the unwind info. */
3085 unwind.opcode_count = 0;
3086 unwind.table_entry = NULL;
3087 unwind.personality_routine = NULL;
3088 unwind.personality_index = -1;
3089 unwind.frame_size = 0;
3090 unwind.fp_offset = 0;
3091 unwind.fp_reg = 13;
3092 unwind.fp_used = 0;
3093 unwind.sp_restored = 0;
3094}
b99bd4ef 3095
b99bd4ef 3096
c19d1205
ZW
3097/* Parse a handlerdata directive. Creates the exception handling table entry
3098 for the function. */
b99bd4ef 3099
c19d1205
ZW
3100static void
3101s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3102{
3103 demand_empty_rest_of_line ();
3104 if (unwind.table_entry)
6decc662 3105 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3106
c19d1205
ZW
3107 create_unwind_entry (1);
3108}
a737bd4d 3109
c19d1205 3110/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3111
c19d1205
ZW
3112static void
3113s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3114{
3115 long where;
3116 char *ptr;
3117 valueT val;
f02232aa 3118
c19d1205 3119 demand_empty_rest_of_line ();
f02232aa 3120
c19d1205
ZW
3121 /* Add eh table entry. */
3122 if (unwind.table_entry == NULL)
3123 val = create_unwind_entry (0);
3124 else
3125 val = 0;
f02232aa 3126
c19d1205
ZW
3127 /* Add index table entry. This is two words. */
3128 start_unwind_section (unwind.saved_seg, 1);
3129 frag_align (2, 0, 0);
3130 record_alignment (now_seg, 2);
b99bd4ef 3131
c19d1205
ZW
3132 ptr = frag_more (8);
3133 where = frag_now_fix () - 8;
f02232aa 3134
c19d1205
ZW
3135 /* Self relative offset of the function start. */
3136 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3137 BFD_RELOC_ARM_PREL31);
f02232aa 3138
c19d1205
ZW
3139 /* Indicate dependency on EHABI-defined personality routines to the
3140 linker, if it hasn't been done already. */
3141 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3142 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3143 {
5f4273c7
NC
3144 static const char *const name[] =
3145 {
3146 "__aeabi_unwind_cpp_pr0",
3147 "__aeabi_unwind_cpp_pr1",
3148 "__aeabi_unwind_cpp_pr2"
3149 };
c19d1205
ZW
3150 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3151 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3152 marked_pr_dependency |= 1 << unwind.personality_index;
3153 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3154 = marked_pr_dependency;
3155 }
f02232aa 3156
c19d1205
ZW
3157 if (val)
3158 /* Inline exception table entry. */
3159 md_number_to_chars (ptr + 4, val, 4);
3160 else
3161 /* Self relative offset of the table entry. */
3162 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3163 BFD_RELOC_ARM_PREL31);
f02232aa 3164
c19d1205
ZW
3165 /* Restore the original section. */
3166 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3167}
f02232aa 3168
f02232aa 3169
c19d1205 3170/* Parse an unwind_cantunwind directive. */
b99bd4ef 3171
c19d1205
ZW
3172static void
3173s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3174{
3175 demand_empty_rest_of_line ();
3176 if (unwind.personality_routine || unwind.personality_index != -1)
3177 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3178
c19d1205
ZW
3179 unwind.personality_index = -2;
3180}
b99bd4ef 3181
b99bd4ef 3182
c19d1205 3183/* Parse a personalityindex directive. */
b99bd4ef 3184
c19d1205
ZW
3185static void
3186s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3187{
3188 expressionS exp;
b99bd4ef 3189
c19d1205
ZW
3190 if (unwind.personality_routine || unwind.personality_index != -1)
3191 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3192
c19d1205 3193 expression (&exp);
b99bd4ef 3194
c19d1205
ZW
3195 if (exp.X_op != O_constant
3196 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3197 {
c19d1205
ZW
3198 as_bad (_("bad personality routine number"));
3199 ignore_rest_of_line ();
3200 return;
b99bd4ef
NC
3201 }
3202
c19d1205 3203 unwind.personality_index = exp.X_add_number;
b99bd4ef 3204
c19d1205
ZW
3205 demand_empty_rest_of_line ();
3206}
e16bb312 3207
e16bb312 3208
c19d1205 3209/* Parse a personality directive. */
e16bb312 3210
c19d1205
ZW
3211static void
3212s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3213{
3214 char *name, *p, c;
a737bd4d 3215
c19d1205
ZW
3216 if (unwind.personality_routine || unwind.personality_index != -1)
3217 as_bad (_("duplicate .personality directive"));
a737bd4d 3218
c19d1205
ZW
3219 name = input_line_pointer;
3220 c = get_symbol_end ();
3221 p = input_line_pointer;
3222 unwind.personality_routine = symbol_find_or_make (name);
3223 *p = c;
3224 demand_empty_rest_of_line ();
3225}
e16bb312 3226
e16bb312 3227
c19d1205 3228/* Parse a directive saving core registers. */
e16bb312 3229
c19d1205
ZW
3230static void
3231s_arm_unwind_save_core (void)
e16bb312 3232{
c19d1205
ZW
3233 valueT op;
3234 long range;
3235 int n;
e16bb312 3236
c19d1205
ZW
3237 range = parse_reg_list (&input_line_pointer);
3238 if (range == FAIL)
e16bb312 3239 {
c19d1205
ZW
3240 as_bad (_("expected register list"));
3241 ignore_rest_of_line ();
3242 return;
3243 }
e16bb312 3244
c19d1205 3245 demand_empty_rest_of_line ();
e16bb312 3246
c19d1205
ZW
3247 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3248 into .unwind_save {..., sp...}. We aren't bothered about the value of
3249 ip because it is clobbered by calls. */
3250 if (unwind.sp_restored && unwind.fp_reg == 12
3251 && (range & 0x3000) == 0x1000)
3252 {
3253 unwind.opcode_count--;
3254 unwind.sp_restored = 0;
3255 range = (range | 0x2000) & ~0x1000;
3256 unwind.pending_offset = 0;
3257 }
e16bb312 3258
01ae4198
DJ
3259 /* Pop r4-r15. */
3260 if (range & 0xfff0)
c19d1205 3261 {
01ae4198
DJ
3262 /* See if we can use the short opcodes. These pop a block of up to 8
3263 registers starting with r4, plus maybe r14. */
3264 for (n = 0; n < 8; n++)
3265 {
3266 /* Break at the first non-saved register. */
3267 if ((range & (1 << (n + 4))) == 0)
3268 break;
3269 }
3270 /* See if there are any other bits set. */
3271 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3272 {
3273 /* Use the long form. */
3274 op = 0x8000 | ((range >> 4) & 0xfff);
3275 add_unwind_opcode (op, 2);
3276 }
0dd132b6 3277 else
01ae4198
DJ
3278 {
3279 /* Use the short form. */
3280 if (range & 0x4000)
3281 op = 0xa8; /* Pop r14. */
3282 else
3283 op = 0xa0; /* Do not pop r14. */
3284 op |= (n - 1);
3285 add_unwind_opcode (op, 1);
3286 }
c19d1205 3287 }
0dd132b6 3288
c19d1205
ZW
3289 /* Pop r0-r3. */
3290 if (range & 0xf)
3291 {
3292 op = 0xb100 | (range & 0xf);
3293 add_unwind_opcode (op, 2);
0dd132b6
NC
3294 }
3295
c19d1205
ZW
3296 /* Record the number of bytes pushed. */
3297 for (n = 0; n < 16; n++)
3298 {
3299 if (range & (1 << n))
3300 unwind.frame_size += 4;
3301 }
0dd132b6
NC
3302}
3303
c19d1205
ZW
3304
3305/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3306
3307static void
c19d1205 3308s_arm_unwind_save_fpa (int reg)
b99bd4ef 3309{
c19d1205
ZW
3310 expressionS exp;
3311 int num_regs;
3312 valueT op;
b99bd4ef 3313
c19d1205
ZW
3314 /* Get Number of registers to transfer. */
3315 if (skip_past_comma (&input_line_pointer) != FAIL)
3316 expression (&exp);
3317 else
3318 exp.X_op = O_illegal;
b99bd4ef 3319
c19d1205 3320 if (exp.X_op != O_constant)
b99bd4ef 3321 {
c19d1205
ZW
3322 as_bad (_("expected , <constant>"));
3323 ignore_rest_of_line ();
b99bd4ef
NC
3324 return;
3325 }
3326
c19d1205
ZW
3327 num_regs = exp.X_add_number;
3328
3329 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3330 {
c19d1205
ZW
3331 as_bad (_("number of registers must be in the range [1:4]"));
3332 ignore_rest_of_line ();
b99bd4ef
NC
3333 return;
3334 }
3335
c19d1205 3336 demand_empty_rest_of_line ();
b99bd4ef 3337
c19d1205
ZW
3338 if (reg == 4)
3339 {
3340 /* Short form. */
3341 op = 0xb4 | (num_regs - 1);
3342 add_unwind_opcode (op, 1);
3343 }
b99bd4ef
NC
3344 else
3345 {
c19d1205
ZW
3346 /* Long form. */
3347 op = 0xc800 | (reg << 4) | (num_regs - 1);
3348 add_unwind_opcode (op, 2);
b99bd4ef 3349 }
c19d1205 3350 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3351}
3352
c19d1205 3353
fa073d69
MS
3354/* Parse a directive saving VFP registers for ARMv6 and above. */
3355
3356static void
3357s_arm_unwind_save_vfp_armv6 (void)
3358{
3359 int count;
3360 unsigned int start;
3361 valueT op;
3362 int num_vfpv3_regs = 0;
3363 int num_regs_below_16;
3364
3365 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3366 if (count == FAIL)
3367 {
3368 as_bad (_("expected register list"));
3369 ignore_rest_of_line ();
3370 return;
3371 }
3372
3373 demand_empty_rest_of_line ();
3374
3375 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3376 than FSTMX/FLDMX-style ones). */
3377
3378 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3379 if (start >= 16)
3380 num_vfpv3_regs = count;
3381 else if (start + count > 16)
3382 num_vfpv3_regs = start + count - 16;
3383
3384 if (num_vfpv3_regs > 0)
3385 {
3386 int start_offset = start > 16 ? start - 16 : 0;
3387 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3388 add_unwind_opcode (op, 2);
3389 }
3390
3391 /* Generate opcode for registers numbered in the range 0 .. 15. */
3392 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3393 assert (num_regs_below_16 + num_vfpv3_regs == count);
3394 if (num_regs_below_16 > 0)
3395 {
3396 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3397 add_unwind_opcode (op, 2);
3398 }
3399
3400 unwind.frame_size += count * 8;
3401}
3402
3403
3404/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3405
3406static void
c19d1205 3407s_arm_unwind_save_vfp (void)
b99bd4ef 3408{
c19d1205 3409 int count;
ca3f61f7 3410 unsigned int reg;
c19d1205 3411 valueT op;
b99bd4ef 3412
5287ad62 3413 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3414 if (count == FAIL)
b99bd4ef 3415 {
c19d1205
ZW
3416 as_bad (_("expected register list"));
3417 ignore_rest_of_line ();
b99bd4ef
NC
3418 return;
3419 }
3420
c19d1205 3421 demand_empty_rest_of_line ();
b99bd4ef 3422
c19d1205 3423 if (reg == 8)
b99bd4ef 3424 {
c19d1205
ZW
3425 /* Short form. */
3426 op = 0xb8 | (count - 1);
3427 add_unwind_opcode (op, 1);
b99bd4ef 3428 }
c19d1205 3429 else
b99bd4ef 3430 {
c19d1205
ZW
3431 /* Long form. */
3432 op = 0xb300 | (reg << 4) | (count - 1);
3433 add_unwind_opcode (op, 2);
b99bd4ef 3434 }
c19d1205
ZW
3435 unwind.frame_size += count * 8 + 4;
3436}
b99bd4ef 3437
b99bd4ef 3438
c19d1205
ZW
3439/* Parse a directive saving iWMMXt data registers. */
3440
3441static void
3442s_arm_unwind_save_mmxwr (void)
3443{
3444 int reg;
3445 int hi_reg;
3446 int i;
3447 unsigned mask = 0;
3448 valueT op;
b99bd4ef 3449
c19d1205
ZW
3450 if (*input_line_pointer == '{')
3451 input_line_pointer++;
b99bd4ef 3452
c19d1205 3453 do
b99bd4ef 3454 {
dcbf9037 3455 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3456
c19d1205 3457 if (reg == FAIL)
b99bd4ef 3458 {
c19d1205
ZW
3459 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3460 goto error;
b99bd4ef
NC
3461 }
3462
c19d1205
ZW
3463 if (mask >> reg)
3464 as_tsktsk (_("register list not in ascending order"));
3465 mask |= 1 << reg;
b99bd4ef 3466
c19d1205
ZW
3467 if (*input_line_pointer == '-')
3468 {
3469 input_line_pointer++;
dcbf9037 3470 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3471 if (hi_reg == FAIL)
3472 {
3473 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3474 goto error;
3475 }
3476 else if (reg >= hi_reg)
3477 {
3478 as_bad (_("bad register range"));
3479 goto error;
3480 }
3481 for (; reg < hi_reg; reg++)
3482 mask |= 1 << reg;
3483 }
3484 }
3485 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3486
c19d1205
ZW
3487 if (*input_line_pointer == '}')
3488 input_line_pointer++;
b99bd4ef 3489
c19d1205 3490 demand_empty_rest_of_line ();
b99bd4ef 3491
708587a4 3492 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3493 the list. */
3494 flush_pending_unwind ();
b99bd4ef 3495
c19d1205 3496 for (i = 0; i < 16; i++)
b99bd4ef 3497 {
c19d1205
ZW
3498 if (mask & (1 << i))
3499 unwind.frame_size += 8;
b99bd4ef
NC
3500 }
3501
c19d1205
ZW
3502 /* Attempt to combine with a previous opcode. We do this because gcc
3503 likes to output separate unwind directives for a single block of
3504 registers. */
3505 if (unwind.opcode_count > 0)
b99bd4ef 3506 {
c19d1205
ZW
3507 i = unwind.opcodes[unwind.opcode_count - 1];
3508 if ((i & 0xf8) == 0xc0)
3509 {
3510 i &= 7;
3511 /* Only merge if the blocks are contiguous. */
3512 if (i < 6)
3513 {
3514 if ((mask & 0xfe00) == (1 << 9))
3515 {
3516 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3517 unwind.opcode_count--;
3518 }
3519 }
3520 else if (i == 6 && unwind.opcode_count >= 2)
3521 {
3522 i = unwind.opcodes[unwind.opcode_count - 2];
3523 reg = i >> 4;
3524 i &= 0xf;
b99bd4ef 3525
c19d1205
ZW
3526 op = 0xffff << (reg - 1);
3527 if (reg > 0
87a1fd79 3528 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3529 {
3530 op = (1 << (reg + i + 1)) - 1;
3531 op &= ~((1 << reg) - 1);
3532 mask |= op;
3533 unwind.opcode_count -= 2;
3534 }
3535 }
3536 }
b99bd4ef
NC
3537 }
3538
c19d1205
ZW
3539 hi_reg = 15;
3540 /* We want to generate opcodes in the order the registers have been
3541 saved, ie. descending order. */
3542 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3543 {
c19d1205
ZW
3544 /* Save registers in blocks. */
3545 if (reg < 0
3546 || !(mask & (1 << reg)))
3547 {
3548 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3549 preceding block. */
c19d1205
ZW
3550 if (reg != hi_reg)
3551 {
3552 if (reg == 9)
3553 {
3554 /* Short form. */
3555 op = 0xc0 | (hi_reg - 10);
3556 add_unwind_opcode (op, 1);
3557 }
3558 else
3559 {
3560 /* Long form. */
3561 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3562 add_unwind_opcode (op, 2);
3563 }
3564 }
3565 hi_reg = reg - 1;
3566 }
b99bd4ef
NC
3567 }
3568
c19d1205
ZW
3569 return;
3570error:
3571 ignore_rest_of_line ();
b99bd4ef
NC
3572}
3573
3574static void
c19d1205 3575s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3576{
c19d1205
ZW
3577 int reg;
3578 int hi_reg;
3579 unsigned mask = 0;
3580 valueT op;
b99bd4ef 3581
c19d1205
ZW
3582 if (*input_line_pointer == '{')
3583 input_line_pointer++;
b99bd4ef 3584
c19d1205 3585 do
b99bd4ef 3586 {
dcbf9037 3587 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3588
c19d1205
ZW
3589 if (reg == FAIL)
3590 {
3591 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3592 goto error;
3593 }
b99bd4ef 3594
c19d1205
ZW
3595 reg -= 8;
3596 if (mask >> reg)
3597 as_tsktsk (_("register list not in ascending order"));
3598 mask |= 1 << reg;
b99bd4ef 3599
c19d1205
ZW
3600 if (*input_line_pointer == '-')
3601 {
3602 input_line_pointer++;
dcbf9037 3603 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3604 if (hi_reg == FAIL)
3605 {
3606 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3607 goto error;
3608 }
3609 else if (reg >= hi_reg)
3610 {
3611 as_bad (_("bad register range"));
3612 goto error;
3613 }
3614 for (; reg < hi_reg; reg++)
3615 mask |= 1 << reg;
3616 }
b99bd4ef 3617 }
c19d1205 3618 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3619
c19d1205
ZW
3620 if (*input_line_pointer == '}')
3621 input_line_pointer++;
b99bd4ef 3622
c19d1205
ZW
3623 demand_empty_rest_of_line ();
3624
708587a4 3625 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3626 the list. */
3627 flush_pending_unwind ();
b99bd4ef 3628
c19d1205 3629 for (reg = 0; reg < 16; reg++)
b99bd4ef 3630 {
c19d1205
ZW
3631 if (mask & (1 << reg))
3632 unwind.frame_size += 4;
b99bd4ef 3633 }
c19d1205
ZW
3634 op = 0xc700 | mask;
3635 add_unwind_opcode (op, 2);
3636 return;
3637error:
3638 ignore_rest_of_line ();
b99bd4ef
NC
3639}
3640
c19d1205 3641
fa073d69
MS
3642/* Parse an unwind_save directive.
3643 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3644
b99bd4ef 3645static void
fa073d69 3646s_arm_unwind_save (int arch_v6)
b99bd4ef 3647{
c19d1205
ZW
3648 char *peek;
3649 struct reg_entry *reg;
3650 bfd_boolean had_brace = FALSE;
b99bd4ef 3651
c19d1205
ZW
3652 /* Figure out what sort of save we have. */
3653 peek = input_line_pointer;
b99bd4ef 3654
c19d1205 3655 if (*peek == '{')
b99bd4ef 3656 {
c19d1205
ZW
3657 had_brace = TRUE;
3658 peek++;
b99bd4ef
NC
3659 }
3660
c19d1205 3661 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3662
c19d1205 3663 if (!reg)
b99bd4ef 3664 {
c19d1205
ZW
3665 as_bad (_("register expected"));
3666 ignore_rest_of_line ();
b99bd4ef
NC
3667 return;
3668 }
3669
c19d1205 3670 switch (reg->type)
b99bd4ef 3671 {
c19d1205
ZW
3672 case REG_TYPE_FN:
3673 if (had_brace)
3674 {
3675 as_bad (_("FPA .unwind_save does not take a register list"));
3676 ignore_rest_of_line ();
3677 return;
3678 }
93ac2687 3679 input_line_pointer = peek;
c19d1205 3680 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3681 return;
c19d1205
ZW
3682
3683 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3684 case REG_TYPE_VFD:
3685 if (arch_v6)
3686 s_arm_unwind_save_vfp_armv6 ();
3687 else
3688 s_arm_unwind_save_vfp ();
3689 return;
c19d1205
ZW
3690 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3691 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3692
3693 default:
3694 as_bad (_(".unwind_save does not support this kind of register"));
3695 ignore_rest_of_line ();
b99bd4ef 3696 }
c19d1205 3697}
b99bd4ef 3698
b99bd4ef 3699
c19d1205
ZW
3700/* Parse an unwind_movsp directive. */
3701
3702static void
3703s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3704{
3705 int reg;
3706 valueT op;
4fa3602b 3707 int offset;
c19d1205 3708
dcbf9037 3709 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3710 if (reg == FAIL)
b99bd4ef 3711 {
c19d1205
ZW
3712 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3713 ignore_rest_of_line ();
b99bd4ef
NC
3714 return;
3715 }
4fa3602b
PB
3716
3717 /* Optional constant. */
3718 if (skip_past_comma (&input_line_pointer) != FAIL)
3719 {
3720 if (immediate_for_directive (&offset) == FAIL)
3721 return;
3722 }
3723 else
3724 offset = 0;
3725
c19d1205 3726 demand_empty_rest_of_line ();
b99bd4ef 3727
c19d1205 3728 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3729 {
c19d1205 3730 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3731 return;
3732 }
3733
c19d1205
ZW
3734 if (unwind.fp_reg != REG_SP)
3735 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3736
c19d1205
ZW
3737 /* Generate opcode to restore the value. */
3738 op = 0x90 | reg;
3739 add_unwind_opcode (op, 1);
3740
3741 /* Record the information for later. */
3742 unwind.fp_reg = reg;
4fa3602b 3743 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3744 unwind.sp_restored = 1;
b05fe5cf
ZW
3745}
3746
c19d1205
ZW
3747/* Parse an unwind_pad directive. */
3748
b05fe5cf 3749static void
c19d1205 3750s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3751{
c19d1205 3752 int offset;
b05fe5cf 3753
c19d1205
ZW
3754 if (immediate_for_directive (&offset) == FAIL)
3755 return;
b99bd4ef 3756
c19d1205
ZW
3757 if (offset & 3)
3758 {
3759 as_bad (_("stack increment must be multiple of 4"));
3760 ignore_rest_of_line ();
3761 return;
3762 }
b99bd4ef 3763
c19d1205
ZW
3764 /* Don't generate any opcodes, just record the details for later. */
3765 unwind.frame_size += offset;
3766 unwind.pending_offset += offset;
3767
3768 demand_empty_rest_of_line ();
3769}
3770
3771/* Parse an unwind_setfp directive. */
3772
3773static void
3774s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3775{
c19d1205
ZW
3776 int sp_reg;
3777 int fp_reg;
3778 int offset;
3779
dcbf9037 3780 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3781 if (skip_past_comma (&input_line_pointer) == FAIL)
3782 sp_reg = FAIL;
3783 else
dcbf9037 3784 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3785
c19d1205
ZW
3786 if (fp_reg == FAIL || sp_reg == FAIL)
3787 {
3788 as_bad (_("expected <reg>, <reg>"));
3789 ignore_rest_of_line ();
3790 return;
3791 }
b99bd4ef 3792
c19d1205
ZW
3793 /* Optional constant. */
3794 if (skip_past_comma (&input_line_pointer) != FAIL)
3795 {
3796 if (immediate_for_directive (&offset) == FAIL)
3797 return;
3798 }
3799 else
3800 offset = 0;
a737bd4d 3801
c19d1205 3802 demand_empty_rest_of_line ();
a737bd4d 3803
c19d1205 3804 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3805 {
c19d1205
ZW
3806 as_bad (_("register must be either sp or set by a previous"
3807 "unwind_movsp directive"));
3808 return;
a737bd4d
NC
3809 }
3810
c19d1205
ZW
3811 /* Don't generate any opcodes, just record the information for later. */
3812 unwind.fp_reg = fp_reg;
3813 unwind.fp_used = 1;
3814 if (sp_reg == 13)
3815 unwind.fp_offset = unwind.frame_size - offset;
3816 else
3817 unwind.fp_offset -= offset;
a737bd4d
NC
3818}
3819
c19d1205
ZW
3820/* Parse an unwind_raw directive. */
3821
3822static void
3823s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3824{
c19d1205 3825 expressionS exp;
708587a4 3826 /* This is an arbitrary limit. */
c19d1205
ZW
3827 unsigned char op[16];
3828 int count;
a737bd4d 3829
c19d1205
ZW
3830 expression (&exp);
3831 if (exp.X_op == O_constant
3832 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3833 {
c19d1205
ZW
3834 unwind.frame_size += exp.X_add_number;
3835 expression (&exp);
3836 }
3837 else
3838 exp.X_op = O_illegal;
a737bd4d 3839
c19d1205
ZW
3840 if (exp.X_op != O_constant)
3841 {
3842 as_bad (_("expected <offset>, <opcode>"));
3843 ignore_rest_of_line ();
3844 return;
3845 }
a737bd4d 3846
c19d1205 3847 count = 0;
a737bd4d 3848
c19d1205
ZW
3849 /* Parse the opcode. */
3850 for (;;)
3851 {
3852 if (count >= 16)
3853 {
3854 as_bad (_("unwind opcode too long"));
3855 ignore_rest_of_line ();
a737bd4d 3856 }
c19d1205 3857 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3858 {
c19d1205
ZW
3859 as_bad (_("invalid unwind opcode"));
3860 ignore_rest_of_line ();
3861 return;
a737bd4d 3862 }
c19d1205 3863 op[count++] = exp.X_add_number;
a737bd4d 3864
c19d1205
ZW
3865 /* Parse the next byte. */
3866 if (skip_past_comma (&input_line_pointer) == FAIL)
3867 break;
a737bd4d 3868
c19d1205
ZW
3869 expression (&exp);
3870 }
b99bd4ef 3871
c19d1205
ZW
3872 /* Add the opcode bytes in reverse order. */
3873 while (count--)
3874 add_unwind_opcode (op[count], 1);
b99bd4ef 3875
c19d1205 3876 demand_empty_rest_of_line ();
b99bd4ef 3877}
ee065d83
PB
3878
3879
3880/* Parse a .eabi_attribute directive. */
3881
3882static void
3883s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3884{
104d59d1 3885 s_vendor_attribute (OBJ_ATTR_PROC);
ee065d83 3886}
8463be01 3887#endif /* OBJ_ELF */
ee065d83
PB
3888
3889static void s_arm_arch (int);
7a1d4c38 3890static void s_arm_object_arch (int);
ee065d83
PB
3891static void s_arm_cpu (int);
3892static void s_arm_fpu (int);
b99bd4ef 3893
f0927246
NC
3894#ifdef TE_PE
3895
3896static void
5f4273c7 3897pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
3898{
3899 expressionS exp;
3900
3901 do
3902 {
3903 expression (&exp);
3904 if (exp.X_op == O_symbol)
3905 exp.X_op = O_secrel;
3906
3907 emit_expr (&exp, 4);
3908 }
3909 while (*input_line_pointer++ == ',');
3910
3911 input_line_pointer--;
3912 demand_empty_rest_of_line ();
3913}
3914#endif /* TE_PE */
3915
c19d1205
ZW
3916/* This table describes all the machine specific pseudo-ops the assembler
3917 has to support. The fields are:
3918 pseudo-op name without dot
3919 function to call to execute this pseudo-op
3920 Integer arg to pass to the function. */
b99bd4ef 3921
c19d1205 3922const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3923{
c19d1205
ZW
3924 /* Never called because '.req' does not start a line. */
3925 { "req", s_req, 0 },
dcbf9037
JB
3926 /* Following two are likewise never called. */
3927 { "dn", s_dn, 0 },
3928 { "qn", s_qn, 0 },
c19d1205
ZW
3929 { "unreq", s_unreq, 0 },
3930 { "bss", s_bss, 0 },
3931 { "align", s_align, 0 },
3932 { "arm", s_arm, 0 },
3933 { "thumb", s_thumb, 0 },
3934 { "code", s_code, 0 },
3935 { "force_thumb", s_force_thumb, 0 },
3936 { "thumb_func", s_thumb_func, 0 },
3937 { "thumb_set", s_thumb_set, 0 },
3938 { "even", s_even, 0 },
3939 { "ltorg", s_ltorg, 0 },
3940 { "pool", s_ltorg, 0 },
3941 { "syntax", s_syntax, 0 },
8463be01
PB
3942 { "cpu", s_arm_cpu, 0 },
3943 { "arch", s_arm_arch, 0 },
7a1d4c38 3944 { "object_arch", s_arm_object_arch, 0 },
8463be01 3945 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3946#ifdef OBJ_ELF
3947 { "word", s_arm_elf_cons, 4 },
3948 { "long", s_arm_elf_cons, 4 },
3949 { "rel31", s_arm_rel31, 0 },
3950 { "fnstart", s_arm_unwind_fnstart, 0 },
3951 { "fnend", s_arm_unwind_fnend, 0 },
3952 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3953 { "personality", s_arm_unwind_personality, 0 },
3954 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3955 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3956 { "save", s_arm_unwind_save, 0 },
fa073d69 3957 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3958 { "movsp", s_arm_unwind_movsp, 0 },
3959 { "pad", s_arm_unwind_pad, 0 },
3960 { "setfp", s_arm_unwind_setfp, 0 },
3961 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3962 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3963#else
3964 { "word", cons, 4},
f0927246
NC
3965
3966 /* These are used for dwarf. */
3967 {"2byte", cons, 2},
3968 {"4byte", cons, 4},
3969 {"8byte", cons, 8},
3970 /* These are used for dwarf2. */
3971 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3972 { "loc", dwarf2_directive_loc, 0 },
3973 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3974#endif
3975 { "extend", float_cons, 'x' },
3976 { "ldouble", float_cons, 'x' },
3977 { "packed", float_cons, 'p' },
f0927246
NC
3978#ifdef TE_PE
3979 {"secrel32", pe_directive_secrel, 0},
3980#endif
c19d1205
ZW
3981 { 0, 0, 0 }
3982};
3983\f
3984/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3985
c19d1205
ZW
3986/* Generic immediate-value read function for use in insn parsing.
3987 STR points to the beginning of the immediate (the leading #);
3988 VAL receives the value; if the value is outside [MIN, MAX]
3989 issue an error. PREFIX_OPT is true if the immediate prefix is
3990 optional. */
b99bd4ef 3991
c19d1205
ZW
3992static int
3993parse_immediate (char **str, int *val, int min, int max,
3994 bfd_boolean prefix_opt)
3995{
3996 expressionS exp;
3997 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3998 if (exp.X_op != O_constant)
b99bd4ef 3999 {
c19d1205
ZW
4000 inst.error = _("constant expression required");
4001 return FAIL;
4002 }
b99bd4ef 4003
c19d1205
ZW
4004 if (exp.X_add_number < min || exp.X_add_number > max)
4005 {
4006 inst.error = _("immediate value out of range");
4007 return FAIL;
4008 }
b99bd4ef 4009
c19d1205
ZW
4010 *val = exp.X_add_number;
4011 return SUCCESS;
4012}
b99bd4ef 4013
5287ad62 4014/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4015 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4016 instructions. Puts the result directly in inst.operands[i]. */
4017
4018static int
4019parse_big_immediate (char **str, int i)
4020{
4021 expressionS exp;
4022 char *ptr = *str;
4023
4024 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4025
4026 if (exp.X_op == O_constant)
036dc3f7
PB
4027 {
4028 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4029 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4030 O_constant. We have to be careful not to break compilation for
4031 32-bit X_add_number, though. */
4032 if ((exp.X_add_number & ~0xffffffffl) != 0)
4033 {
4034 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4035 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4036 inst.operands[i].regisimm = 1;
4037 }
4038 }
5287ad62
JB
4039 else if (exp.X_op == O_big
4040 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4041 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4042 {
4043 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4044 /* Bignums have their least significant bits in
4045 generic_bignum[0]. Make sure we put 32 bits in imm and
4046 32 bits in reg, in a (hopefully) portable way. */
4047 assert (parts != 0);
4048 inst.operands[i].imm = 0;
4049 for (j = 0; j < parts; j++, idx++)
4050 inst.operands[i].imm |= generic_bignum[idx]
4051 << (LITTLENUM_NUMBER_OF_BITS * j);
4052 inst.operands[i].reg = 0;
4053 for (j = 0; j < parts; j++, idx++)
4054 inst.operands[i].reg |= generic_bignum[idx]
4055 << (LITTLENUM_NUMBER_OF_BITS * j);
4056 inst.operands[i].regisimm = 1;
4057 }
4058 else
4059 return FAIL;
5f4273c7 4060
5287ad62
JB
4061 *str = ptr;
4062
4063 return SUCCESS;
4064}
4065
c19d1205
ZW
4066/* Returns the pseudo-register number of an FPA immediate constant,
4067 or FAIL if there isn't a valid constant here. */
b99bd4ef 4068
c19d1205
ZW
4069static int
4070parse_fpa_immediate (char ** str)
4071{
4072 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4073 char * save_in;
4074 expressionS exp;
4075 int i;
4076 int j;
b99bd4ef 4077
c19d1205
ZW
4078 /* First try and match exact strings, this is to guarantee
4079 that some formats will work even for cross assembly. */
b99bd4ef 4080
c19d1205
ZW
4081 for (i = 0; fp_const[i]; i++)
4082 {
4083 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4084 {
c19d1205 4085 char *start = *str;
b99bd4ef 4086
c19d1205
ZW
4087 *str += strlen (fp_const[i]);
4088 if (is_end_of_line[(unsigned char) **str])
4089 return i + 8;
4090 *str = start;
4091 }
4092 }
b99bd4ef 4093
c19d1205
ZW
4094 /* Just because we didn't get a match doesn't mean that the constant
4095 isn't valid, just that it is in a format that we don't
4096 automatically recognize. Try parsing it with the standard
4097 expression routines. */
b99bd4ef 4098
c19d1205 4099 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4100
c19d1205
ZW
4101 /* Look for a raw floating point number. */
4102 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4103 && is_end_of_line[(unsigned char) *save_in])
4104 {
4105 for (i = 0; i < NUM_FLOAT_VALS; i++)
4106 {
4107 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4108 {
c19d1205
ZW
4109 if (words[j] != fp_values[i][j])
4110 break;
b99bd4ef
NC
4111 }
4112
c19d1205 4113 if (j == MAX_LITTLENUMS)
b99bd4ef 4114 {
c19d1205
ZW
4115 *str = save_in;
4116 return i + 8;
b99bd4ef
NC
4117 }
4118 }
4119 }
b99bd4ef 4120
c19d1205
ZW
4121 /* Try and parse a more complex expression, this will probably fail
4122 unless the code uses a floating point prefix (eg "0f"). */
4123 save_in = input_line_pointer;
4124 input_line_pointer = *str;
4125 if (expression (&exp) == absolute_section
4126 && exp.X_op == O_big
4127 && exp.X_add_number < 0)
4128 {
4129 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4130 Ditto for 15. */
4131 if (gen_to_words (words, 5, (long) 15) == 0)
4132 {
4133 for (i = 0; i < NUM_FLOAT_VALS; i++)
4134 {
4135 for (j = 0; j < MAX_LITTLENUMS; j++)
4136 {
4137 if (words[j] != fp_values[i][j])
4138 break;
4139 }
b99bd4ef 4140
c19d1205
ZW
4141 if (j == MAX_LITTLENUMS)
4142 {
4143 *str = input_line_pointer;
4144 input_line_pointer = save_in;
4145 return i + 8;
4146 }
4147 }
4148 }
b99bd4ef
NC
4149 }
4150
c19d1205
ZW
4151 *str = input_line_pointer;
4152 input_line_pointer = save_in;
4153 inst.error = _("invalid FPA immediate expression");
4154 return FAIL;
b99bd4ef
NC
4155}
4156
136da414
JB
4157/* Returns 1 if a number has "quarter-precision" float format
4158 0baBbbbbbc defgh000 00000000 00000000. */
4159
4160static int
4161is_quarter_float (unsigned imm)
4162{
4163 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4164 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4165}
4166
4167/* Parse an 8-bit "quarter-precision" floating point number of the form:
4168 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4169 The zero and minus-zero cases need special handling, since they can't be
4170 encoded in the "quarter-precision" float format, but can nonetheless be
4171 loaded as integer constants. */
136da414
JB
4172
4173static unsigned
4174parse_qfloat_immediate (char **ccp, int *immed)
4175{
4176 char *str = *ccp;
c96612cc 4177 char *fpnum;
136da414 4178 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4179 int found_fpchar = 0;
5f4273c7 4180
136da414 4181 skip_past_char (&str, '#');
5f4273c7 4182
c96612cc
JB
4183 /* We must not accidentally parse an integer as a floating-point number. Make
4184 sure that the value we parse is not an integer by checking for special
4185 characters '.' or 'e'.
4186 FIXME: This is a horrible hack, but doing better is tricky because type
4187 information isn't in a very usable state at parse time. */
4188 fpnum = str;
4189 skip_whitespace (fpnum);
4190
4191 if (strncmp (fpnum, "0x", 2) == 0)
4192 return FAIL;
4193 else
4194 {
4195 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4196 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4197 {
4198 found_fpchar = 1;
4199 break;
4200 }
4201
4202 if (!found_fpchar)
4203 return FAIL;
4204 }
5f4273c7 4205
136da414
JB
4206 if ((str = atof_ieee (str, 's', words)) != NULL)
4207 {
4208 unsigned fpword = 0;
4209 int i;
5f4273c7 4210
136da414
JB
4211 /* Our FP word must be 32 bits (single-precision FP). */
4212 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4213 {
4214 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4215 fpword |= words[i];
4216 }
5f4273c7 4217
c96612cc 4218 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4219 *immed = fpword;
4220 else
4221 return FAIL;
4222
4223 *ccp = str;
5f4273c7 4224
136da414
JB
4225 return SUCCESS;
4226 }
5f4273c7 4227
136da414
JB
4228 return FAIL;
4229}
4230
c19d1205
ZW
4231/* Shift operands. */
4232enum shift_kind
b99bd4ef 4233{
c19d1205
ZW
4234 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4235};
b99bd4ef 4236
c19d1205
ZW
4237struct asm_shift_name
4238{
4239 const char *name;
4240 enum shift_kind kind;
4241};
b99bd4ef 4242
c19d1205
ZW
4243/* Third argument to parse_shift. */
4244enum parse_shift_mode
4245{
4246 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4247 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4248 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4249 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4250 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4251};
b99bd4ef 4252
c19d1205
ZW
4253/* Parse a <shift> specifier on an ARM data processing instruction.
4254 This has three forms:
b99bd4ef 4255
c19d1205
ZW
4256 (LSL|LSR|ASL|ASR|ROR) Rs
4257 (LSL|LSR|ASL|ASR|ROR) #imm
4258 RRX
b99bd4ef 4259
c19d1205
ZW
4260 Note that ASL is assimilated to LSL in the instruction encoding, and
4261 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4262
c19d1205
ZW
4263static int
4264parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4265{
c19d1205
ZW
4266 const struct asm_shift_name *shift_name;
4267 enum shift_kind shift;
4268 char *s = *str;
4269 char *p = s;
4270 int reg;
b99bd4ef 4271
c19d1205
ZW
4272 for (p = *str; ISALPHA (*p); p++)
4273 ;
b99bd4ef 4274
c19d1205 4275 if (p == *str)
b99bd4ef 4276 {
c19d1205
ZW
4277 inst.error = _("shift expression expected");
4278 return FAIL;
b99bd4ef
NC
4279 }
4280
c19d1205
ZW
4281 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4282
4283 if (shift_name == NULL)
b99bd4ef 4284 {
c19d1205
ZW
4285 inst.error = _("shift expression expected");
4286 return FAIL;
b99bd4ef
NC
4287 }
4288
c19d1205 4289 shift = shift_name->kind;
b99bd4ef 4290
c19d1205
ZW
4291 switch (mode)
4292 {
4293 case NO_SHIFT_RESTRICT:
4294 case SHIFT_IMMEDIATE: break;
b99bd4ef 4295
c19d1205
ZW
4296 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4297 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4298 {
4299 inst.error = _("'LSL' or 'ASR' required");
4300 return FAIL;
4301 }
4302 break;
b99bd4ef 4303
c19d1205
ZW
4304 case SHIFT_LSL_IMMEDIATE:
4305 if (shift != SHIFT_LSL)
4306 {
4307 inst.error = _("'LSL' required");
4308 return FAIL;
4309 }
4310 break;
b99bd4ef 4311
c19d1205
ZW
4312 case SHIFT_ASR_IMMEDIATE:
4313 if (shift != SHIFT_ASR)
4314 {
4315 inst.error = _("'ASR' required");
4316 return FAIL;
4317 }
4318 break;
b99bd4ef 4319
c19d1205
ZW
4320 default: abort ();
4321 }
b99bd4ef 4322
c19d1205
ZW
4323 if (shift != SHIFT_RRX)
4324 {
4325 /* Whitespace can appear here if the next thing is a bare digit. */
4326 skip_whitespace (p);
b99bd4ef 4327
c19d1205 4328 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4329 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4330 {
4331 inst.operands[i].imm = reg;
4332 inst.operands[i].immisreg = 1;
4333 }
4334 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4335 return FAIL;
4336 }
4337 inst.operands[i].shift_kind = shift;
4338 inst.operands[i].shifted = 1;
4339 *str = p;
4340 return SUCCESS;
b99bd4ef
NC
4341}
4342
c19d1205 4343/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4344
c19d1205
ZW
4345 #<immediate>
4346 #<immediate>, <rotate>
4347 <Rm>
4348 <Rm>, <shift>
b99bd4ef 4349
c19d1205
ZW
4350 where <shift> is defined by parse_shift above, and <rotate> is a
4351 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4352 is deferred to md_apply_fix. */
b99bd4ef 4353
c19d1205
ZW
4354static int
4355parse_shifter_operand (char **str, int i)
4356{
4357 int value;
4358 expressionS expr;
b99bd4ef 4359
dcbf9037 4360 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4361 {
4362 inst.operands[i].reg = value;
4363 inst.operands[i].isreg = 1;
b99bd4ef 4364
c19d1205
ZW
4365 /* parse_shift will override this if appropriate */
4366 inst.reloc.exp.X_op = O_constant;
4367 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4368
c19d1205
ZW
4369 if (skip_past_comma (str) == FAIL)
4370 return SUCCESS;
b99bd4ef 4371
c19d1205
ZW
4372 /* Shift operation on register. */
4373 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4374 }
4375
c19d1205
ZW
4376 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4377 return FAIL;
b99bd4ef 4378
c19d1205 4379 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4380 {
c19d1205
ZW
4381 /* #x, y -- ie explicit rotation by Y. */
4382 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4383 return FAIL;
b99bd4ef 4384
c19d1205
ZW
4385 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4386 {
4387 inst.error = _("constant expression expected");
4388 return FAIL;
4389 }
b99bd4ef 4390
c19d1205
ZW
4391 value = expr.X_add_number;
4392 if (value < 0 || value > 30 || value % 2 != 0)
4393 {
4394 inst.error = _("invalid rotation");
4395 return FAIL;
4396 }
4397 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4398 {
4399 inst.error = _("invalid constant");
4400 return FAIL;
4401 }
09d92015 4402
55cf6793 4403 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4404 inst.reloc.exp.X_add_number
4405 = (((inst.reloc.exp.X_add_number << (32 - value))
4406 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4407 }
4408
c19d1205
ZW
4409 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4410 inst.reloc.pc_rel = 0;
4411 return SUCCESS;
09d92015
MM
4412}
4413
4962c51a
MS
4414/* Group relocation information. Each entry in the table contains the
4415 textual name of the relocation as may appear in assembler source
4416 and must end with a colon.
4417 Along with this textual name are the relocation codes to be used if
4418 the corresponding instruction is an ALU instruction (ADD or SUB only),
4419 an LDR, an LDRS, or an LDC. */
4420
4421struct group_reloc_table_entry
4422{
4423 const char *name;
4424 int alu_code;
4425 int ldr_code;
4426 int ldrs_code;
4427 int ldc_code;
4428};
4429
4430typedef enum
4431{
4432 /* Varieties of non-ALU group relocation. */
4433
4434 GROUP_LDR,
4435 GROUP_LDRS,
4436 GROUP_LDC
4437} group_reloc_type;
4438
4439static struct group_reloc_table_entry group_reloc_table[] =
4440 { /* Program counter relative: */
4441 { "pc_g0_nc",
4442 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4443 0, /* LDR */
4444 0, /* LDRS */
4445 0 }, /* LDC */
4446 { "pc_g0",
4447 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4448 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4449 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4450 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4451 { "pc_g1_nc",
4452 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4453 0, /* LDR */
4454 0, /* LDRS */
4455 0 }, /* LDC */
4456 { "pc_g1",
4457 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4458 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4459 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4460 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4461 { "pc_g2",
4462 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4463 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4464 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4465 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4466 /* Section base relative */
4467 { "sb_g0_nc",
4468 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4469 0, /* LDR */
4470 0, /* LDRS */
4471 0 }, /* LDC */
4472 { "sb_g0",
4473 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4474 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4475 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4476 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4477 { "sb_g1_nc",
4478 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4479 0, /* LDR */
4480 0, /* LDRS */
4481 0 }, /* LDC */
4482 { "sb_g1",
4483 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4484 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4485 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4486 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4487 { "sb_g2",
4488 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4489 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4490 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4491 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4492
4493/* Given the address of a pointer pointing to the textual name of a group
4494 relocation as may appear in assembler source, attempt to find its details
4495 in group_reloc_table. The pointer will be updated to the character after
4496 the trailing colon. On failure, FAIL will be returned; SUCCESS
4497 otherwise. On success, *entry will be updated to point at the relevant
4498 group_reloc_table entry. */
4499
4500static int
4501find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4502{
4503 unsigned int i;
4504 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4505 {
4506 int length = strlen (group_reloc_table[i].name);
4507
5f4273c7
NC
4508 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4509 && (*str)[length] == ':')
4962c51a
MS
4510 {
4511 *out = &group_reloc_table[i];
4512 *str += (length + 1);
4513 return SUCCESS;
4514 }
4515 }
4516
4517 return FAIL;
4518}
4519
4520/* Parse a <shifter_operand> for an ARM data processing instruction
4521 (as for parse_shifter_operand) where group relocations are allowed:
4522
4523 #<immediate>
4524 #<immediate>, <rotate>
4525 #:<group_reloc>:<expression>
4526 <Rm>
4527 <Rm>, <shift>
4528
4529 where <group_reloc> is one of the strings defined in group_reloc_table.
4530 The hashes are optional.
4531
4532 Everything else is as for parse_shifter_operand. */
4533
4534static parse_operand_result
4535parse_shifter_operand_group_reloc (char **str, int i)
4536{
4537 /* Determine if we have the sequence of characters #: or just :
4538 coming next. If we do, then we check for a group relocation.
4539 If we don't, punt the whole lot to parse_shifter_operand. */
4540
4541 if (((*str)[0] == '#' && (*str)[1] == ':')
4542 || (*str)[0] == ':')
4543 {
4544 struct group_reloc_table_entry *entry;
4545
4546 if ((*str)[0] == '#')
4547 (*str) += 2;
4548 else
4549 (*str)++;
4550
4551 /* Try to parse a group relocation. Anything else is an error. */
4552 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4553 {
4554 inst.error = _("unknown group relocation");
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4556 }
4557
4558 /* We now have the group relocation table entry corresponding to
4559 the name in the assembler source. Next, we parse the expression. */
4560 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4561 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4562
4563 /* Record the relocation type (always the ALU variant here). */
4564 inst.reloc.type = entry->alu_code;
4565 assert (inst.reloc.type != 0);
4566
4567 return PARSE_OPERAND_SUCCESS;
4568 }
4569 else
4570 return parse_shifter_operand (str, i) == SUCCESS
4571 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4572
4573 /* Never reached. */
4574}
4575
c19d1205
ZW
4576/* Parse all forms of an ARM address expression. Information is written
4577 to inst.operands[i] and/or inst.reloc.
09d92015 4578
c19d1205 4579 Preindexed addressing (.preind=1):
09d92015 4580
c19d1205
ZW
4581 [Rn, #offset] .reg=Rn .reloc.exp=offset
4582 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4583 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4584 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4585
c19d1205 4586 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4587
c19d1205 4588 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4589
c19d1205
ZW
4590 [Rn], #offset .reg=Rn .reloc.exp=offset
4591 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4592 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4593 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4594
c19d1205 4595 Unindexed addressing (.preind=0, .postind=0):
09d92015 4596
c19d1205 4597 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4598
c19d1205 4599 Other:
09d92015 4600
c19d1205
ZW
4601 [Rn]{!} shorthand for [Rn,#0]{!}
4602 =immediate .isreg=0 .reloc.exp=immediate
4603 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4604
c19d1205
ZW
4605 It is the caller's responsibility to check for addressing modes not
4606 supported by the instruction, and to set inst.reloc.type. */
4607
4962c51a
MS
4608static parse_operand_result
4609parse_address_main (char **str, int i, int group_relocations,
4610 group_reloc_type group_type)
09d92015 4611{
c19d1205
ZW
4612 char *p = *str;
4613 int reg;
09d92015 4614
c19d1205 4615 if (skip_past_char (&p, '[') == FAIL)
09d92015 4616 {
c19d1205
ZW
4617 if (skip_past_char (&p, '=') == FAIL)
4618 {
4619 /* bare address - translate to PC-relative offset */
4620 inst.reloc.pc_rel = 1;
4621 inst.operands[i].reg = REG_PC;
4622 inst.operands[i].isreg = 1;
4623 inst.operands[i].preind = 1;
4624 }
4625 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4626
c19d1205 4627 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4628 return PARSE_OPERAND_FAIL;
09d92015 4629
c19d1205 4630 *str = p;
4962c51a 4631 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4632 }
4633
dcbf9037 4634 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4635 {
c19d1205 4636 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4637 return PARSE_OPERAND_FAIL;
09d92015 4638 }
c19d1205
ZW
4639 inst.operands[i].reg = reg;
4640 inst.operands[i].isreg = 1;
09d92015 4641
c19d1205 4642 if (skip_past_comma (&p) == SUCCESS)
09d92015 4643 {
c19d1205 4644 inst.operands[i].preind = 1;
09d92015 4645
c19d1205
ZW
4646 if (*p == '+') p++;
4647 else if (*p == '-') p++, inst.operands[i].negative = 1;
4648
dcbf9037 4649 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4650 {
c19d1205
ZW
4651 inst.operands[i].imm = reg;
4652 inst.operands[i].immisreg = 1;
4653
4654 if (skip_past_comma (&p) == SUCCESS)
4655 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4656 return PARSE_OPERAND_FAIL;
c19d1205 4657 }
5287ad62
JB
4658 else if (skip_past_char (&p, ':') == SUCCESS)
4659 {
4660 /* FIXME: '@' should be used here, but it's filtered out by generic
4661 code before we get to see it here. This may be subject to
4662 change. */
4663 expressionS exp;
4664 my_get_expression (&exp, &p, GE_NO_PREFIX);
4665 if (exp.X_op != O_constant)
4666 {
4667 inst.error = _("alignment must be constant");
4962c51a 4668 return PARSE_OPERAND_FAIL;
5287ad62
JB
4669 }
4670 inst.operands[i].imm = exp.X_add_number << 8;
4671 inst.operands[i].immisalign = 1;
4672 /* Alignments are not pre-indexes. */
4673 inst.operands[i].preind = 0;
4674 }
c19d1205
ZW
4675 else
4676 {
4677 if (inst.operands[i].negative)
4678 {
4679 inst.operands[i].negative = 0;
4680 p--;
4681 }
4962c51a 4682
5f4273c7
NC
4683 if (group_relocations
4684 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4685 {
4686 struct group_reloc_table_entry *entry;
4687
4688 /* Skip over the #: or : sequence. */
4689 if (*p == '#')
4690 p += 2;
4691 else
4692 p++;
4693
4694 /* Try to parse a group relocation. Anything else is an
4695 error. */
4696 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4697 {
4698 inst.error = _("unknown group relocation");
4699 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4700 }
4701
4702 /* We now have the group relocation table entry corresponding to
4703 the name in the assembler source. Next, we parse the
4704 expression. */
4705 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4706 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4707
4708 /* Record the relocation type. */
4709 switch (group_type)
4710 {
4711 case GROUP_LDR:
4712 inst.reloc.type = entry->ldr_code;
4713 break;
4714
4715 case GROUP_LDRS:
4716 inst.reloc.type = entry->ldrs_code;
4717 break;
4718
4719 case GROUP_LDC:
4720 inst.reloc.type = entry->ldc_code;
4721 break;
4722
4723 default:
4724 assert (0);
4725 }
4726
4727 if (inst.reloc.type == 0)
4728 {
4729 inst.error = _("this group relocation is not allowed on this instruction");
4730 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4731 }
4732 }
4733 else
4734 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4735 return PARSE_OPERAND_FAIL;
09d92015
MM
4736 }
4737 }
4738
c19d1205 4739 if (skip_past_char (&p, ']') == FAIL)
09d92015 4740 {
c19d1205 4741 inst.error = _("']' expected");
4962c51a 4742 return PARSE_OPERAND_FAIL;
09d92015
MM
4743 }
4744
c19d1205
ZW
4745 if (skip_past_char (&p, '!') == SUCCESS)
4746 inst.operands[i].writeback = 1;
09d92015 4747
c19d1205 4748 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4749 {
c19d1205
ZW
4750 if (skip_past_char (&p, '{') == SUCCESS)
4751 {
4752 /* [Rn], {expr} - unindexed, with option */
4753 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4754 0, 255, TRUE) == FAIL)
4962c51a 4755 return PARSE_OPERAND_FAIL;
09d92015 4756
c19d1205
ZW
4757 if (skip_past_char (&p, '}') == FAIL)
4758 {
4759 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4760 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4761 }
4762 if (inst.operands[i].preind)
4763 {
4764 inst.error = _("cannot combine index with option");
4962c51a 4765 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4766 }
4767 *str = p;
4962c51a 4768 return PARSE_OPERAND_SUCCESS;
09d92015 4769 }
c19d1205
ZW
4770 else
4771 {
4772 inst.operands[i].postind = 1;
4773 inst.operands[i].writeback = 1;
09d92015 4774
c19d1205
ZW
4775 if (inst.operands[i].preind)
4776 {
4777 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4778 return PARSE_OPERAND_FAIL;
c19d1205 4779 }
09d92015 4780
c19d1205
ZW
4781 if (*p == '+') p++;
4782 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4783
dcbf9037 4784 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4785 {
5287ad62
JB
4786 /* We might be using the immediate for alignment already. If we
4787 are, OR the register number into the low-order bits. */
4788 if (inst.operands[i].immisalign)
4789 inst.operands[i].imm |= reg;
4790 else
4791 inst.operands[i].imm = reg;
c19d1205 4792 inst.operands[i].immisreg = 1;
a737bd4d 4793
c19d1205
ZW
4794 if (skip_past_comma (&p) == SUCCESS)
4795 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4796 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4797 }
4798 else
4799 {
4800 if (inst.operands[i].negative)
4801 {
4802 inst.operands[i].negative = 0;
4803 p--;
4804 }
4805 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4806 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4807 }
4808 }
a737bd4d
NC
4809 }
4810
c19d1205
ZW
4811 /* If at this point neither .preind nor .postind is set, we have a
4812 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4813 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4814 {
4815 inst.operands[i].preind = 1;
4816 inst.reloc.exp.X_op = O_constant;
4817 inst.reloc.exp.X_add_number = 0;
4818 }
4819 *str = p;
4962c51a
MS
4820 return PARSE_OPERAND_SUCCESS;
4821}
4822
4823static int
4824parse_address (char **str, int i)
4825{
4826 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4827 ? SUCCESS : FAIL;
4828}
4829
4830static parse_operand_result
4831parse_address_group_reloc (char **str, int i, group_reloc_type type)
4832{
4833 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4834}
4835
b6895b4f
PB
4836/* Parse an operand for a MOVW or MOVT instruction. */
4837static int
4838parse_half (char **str)
4839{
4840 char * p;
5f4273c7 4841
b6895b4f
PB
4842 p = *str;
4843 skip_past_char (&p, '#');
5f4273c7 4844 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4845 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4846 else if (strncasecmp (p, ":upper16:", 9) == 0)
4847 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4848
4849 if (inst.reloc.type != BFD_RELOC_UNUSED)
4850 {
4851 p += 9;
5f4273c7 4852 skip_whitespace (p);
b6895b4f
PB
4853 }
4854
4855 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4856 return FAIL;
4857
4858 if (inst.reloc.type == BFD_RELOC_UNUSED)
4859 {
4860 if (inst.reloc.exp.X_op != O_constant)
4861 {
4862 inst.error = _("constant expression expected");
4863 return FAIL;
4864 }
4865 if (inst.reloc.exp.X_add_number < 0
4866 || inst.reloc.exp.X_add_number > 0xffff)
4867 {
4868 inst.error = _("immediate value out of range");
4869 return FAIL;
4870 }
4871 }
4872 *str = p;
4873 return SUCCESS;
4874}
4875
c19d1205 4876/* Miscellaneous. */
a737bd4d 4877
c19d1205
ZW
4878/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4879 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4880static int
4881parse_psr (char **str)
09d92015 4882{
c19d1205
ZW
4883 char *p;
4884 unsigned long psr_field;
62b3e311
PB
4885 const struct asm_psr *psr;
4886 char *start;
09d92015 4887
c19d1205
ZW
4888 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4889 feature for ease of use and backwards compatibility. */
4890 p = *str;
62b3e311 4891 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4892 psr_field = SPSR_BIT;
62b3e311 4893 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4894 psr_field = 0;
4895 else
62b3e311
PB
4896 {
4897 start = p;
4898 do
4899 p++;
4900 while (ISALNUM (*p) || *p == '_');
4901
4902 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4903 if (!psr)
4904 return FAIL;
09d92015 4905
62b3e311
PB
4906 *str = p;
4907 return psr->field;
4908 }
09d92015 4909
62b3e311 4910 p += 4;
c19d1205
ZW
4911 if (*p == '_')
4912 {
4913 /* A suffix follows. */
c19d1205
ZW
4914 p++;
4915 start = p;
a737bd4d 4916
c19d1205
ZW
4917 do
4918 p++;
4919 while (ISALNUM (*p) || *p == '_');
a737bd4d 4920
c19d1205
ZW
4921 psr = hash_find_n (arm_psr_hsh, start, p - start);
4922 if (!psr)
4923 goto error;
a737bd4d 4924
c19d1205 4925 psr_field |= psr->field;
a737bd4d 4926 }
c19d1205 4927 else
a737bd4d 4928 {
c19d1205
ZW
4929 if (ISALNUM (*p))
4930 goto error; /* Garbage after "[CS]PSR". */
4931
4932 psr_field |= (PSR_c | PSR_f);
a737bd4d 4933 }
c19d1205
ZW
4934 *str = p;
4935 return psr_field;
a737bd4d 4936
c19d1205
ZW
4937 error:
4938 inst.error = _("flag for {c}psr instruction expected");
4939 return FAIL;
a737bd4d
NC
4940}
4941
c19d1205
ZW
4942/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4943 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4944
c19d1205
ZW
4945static int
4946parse_cps_flags (char **str)
a737bd4d 4947{
c19d1205
ZW
4948 int val = 0;
4949 int saw_a_flag = 0;
4950 char *s = *str;
a737bd4d 4951
c19d1205
ZW
4952 for (;;)
4953 switch (*s++)
4954 {
4955 case '\0': case ',':
4956 goto done;
a737bd4d 4957
c19d1205
ZW
4958 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4959 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4960 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4961
c19d1205
ZW
4962 default:
4963 inst.error = _("unrecognized CPS flag");
4964 return FAIL;
4965 }
a737bd4d 4966
c19d1205
ZW
4967 done:
4968 if (saw_a_flag == 0)
a737bd4d 4969 {
c19d1205
ZW
4970 inst.error = _("missing CPS flags");
4971 return FAIL;
a737bd4d 4972 }
a737bd4d 4973
c19d1205
ZW
4974 *str = s - 1;
4975 return val;
a737bd4d
NC
4976}
4977
c19d1205
ZW
4978/* Parse an endian specifier ("BE" or "LE", case insensitive);
4979 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4980
4981static int
c19d1205 4982parse_endian_specifier (char **str)
a737bd4d 4983{
c19d1205
ZW
4984 int little_endian;
4985 char *s = *str;
a737bd4d 4986
c19d1205
ZW
4987 if (strncasecmp (s, "BE", 2))
4988 little_endian = 0;
4989 else if (strncasecmp (s, "LE", 2))
4990 little_endian = 1;
4991 else
a737bd4d 4992 {
c19d1205 4993 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4994 return FAIL;
4995 }
4996
c19d1205 4997 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 4998 {
c19d1205 4999 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5000 return FAIL;
5001 }
5002
c19d1205
ZW
5003 *str = s + 2;
5004 return little_endian;
5005}
a737bd4d 5006
c19d1205
ZW
5007/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5008 value suitable for poking into the rotate field of an sxt or sxta
5009 instruction, or FAIL on error. */
5010
5011static int
5012parse_ror (char **str)
5013{
5014 int rot;
5015 char *s = *str;
5016
5017 if (strncasecmp (s, "ROR", 3) == 0)
5018 s += 3;
5019 else
a737bd4d 5020 {
c19d1205 5021 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5022 return FAIL;
5023 }
c19d1205
ZW
5024
5025 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5026 return FAIL;
5027
5028 switch (rot)
a737bd4d 5029 {
c19d1205
ZW
5030 case 0: *str = s; return 0x0;
5031 case 8: *str = s; return 0x1;
5032 case 16: *str = s; return 0x2;
5033 case 24: *str = s; return 0x3;
5034
5035 default:
5036 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5037 return FAIL;
5038 }
c19d1205 5039}
a737bd4d 5040
c19d1205
ZW
5041/* Parse a conditional code (from conds[] below). The value returned is in the
5042 range 0 .. 14, or FAIL. */
5043static int
5044parse_cond (char **str)
5045{
5046 char *p, *q;
5047 const struct asm_cond *c;
a737bd4d 5048
c19d1205
ZW
5049 p = q = *str;
5050 while (ISALPHA (*q))
5051 q++;
a737bd4d 5052
c19d1205
ZW
5053 c = hash_find_n (arm_cond_hsh, p, q - p);
5054 if (!c)
a737bd4d 5055 {
c19d1205 5056 inst.error = _("condition required");
a737bd4d
NC
5057 return FAIL;
5058 }
5059
c19d1205
ZW
5060 *str = q;
5061 return c->value;
5062}
5063
62b3e311
PB
5064/* Parse an option for a barrier instruction. Returns the encoding for the
5065 option, or FAIL. */
5066static int
5067parse_barrier (char **str)
5068{
5069 char *p, *q;
5070 const struct asm_barrier_opt *o;
5071
5072 p = q = *str;
5073 while (ISALPHA (*q))
5074 q++;
5075
5076 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5077 if (!o)
5078 return FAIL;
5079
5080 *str = q;
5081 return o->value;
5082}
5083
92e90b6e
PB
5084/* Parse the operands of a table branch instruction. Similar to a memory
5085 operand. */
5086static int
5087parse_tb (char **str)
5088{
5089 char * p = *str;
5090 int reg;
5091
5092 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5093 {
5094 inst.error = _("'[' expected");
5095 return FAIL;
5096 }
92e90b6e 5097
dcbf9037 5098 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5099 {
5100 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5101 return FAIL;
5102 }
5103 inst.operands[0].reg = reg;
5104
5105 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5106 {
5107 inst.error = _("',' expected");
5108 return FAIL;
5109 }
5f4273c7 5110
dcbf9037 5111 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5112 {
5113 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5114 return FAIL;
5115 }
5116 inst.operands[0].imm = reg;
5117
5118 if (skip_past_comma (&p) == SUCCESS)
5119 {
5120 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5121 return FAIL;
5122 if (inst.reloc.exp.X_add_number != 1)
5123 {
5124 inst.error = _("invalid shift");
5125 return FAIL;
5126 }
5127 inst.operands[0].shifted = 1;
5128 }
5129
5130 if (skip_past_char (&p, ']') == FAIL)
5131 {
5132 inst.error = _("']' expected");
5133 return FAIL;
5134 }
5135 *str = p;
5136 return SUCCESS;
5137}
5138
5287ad62
JB
5139/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5140 information on the types the operands can take and how they are encoded.
037e8744
JB
5141 Up to four operands may be read; this function handles setting the
5142 ".present" field for each read operand itself.
5287ad62
JB
5143 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5144 else returns FAIL. */
5145
5146static int
5147parse_neon_mov (char **str, int *which_operand)
5148{
5149 int i = *which_operand, val;
5150 enum arm_reg_type rtype;
5151 char *ptr = *str;
dcbf9037 5152 struct neon_type_el optype;
5f4273c7 5153
dcbf9037 5154 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5155 {
5156 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5157 inst.operands[i].reg = val;
5158 inst.operands[i].isscalar = 1;
dcbf9037 5159 inst.operands[i].vectype = optype;
5287ad62
JB
5160 inst.operands[i++].present = 1;
5161
5162 if (skip_past_comma (&ptr) == FAIL)
5163 goto wanted_comma;
5f4273c7 5164
dcbf9037 5165 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5166 goto wanted_arm;
5f4273c7 5167
5287ad62
JB
5168 inst.operands[i].reg = val;
5169 inst.operands[i].isreg = 1;
5170 inst.operands[i].present = 1;
5171 }
037e8744 5172 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5173 != FAIL)
5287ad62
JB
5174 {
5175 /* Cases 0, 1, 2, 3, 5 (D only). */
5176 if (skip_past_comma (&ptr) == FAIL)
5177 goto wanted_comma;
5f4273c7 5178
5287ad62
JB
5179 inst.operands[i].reg = val;
5180 inst.operands[i].isreg = 1;
5181 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5182 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5183 inst.operands[i].isvec = 1;
dcbf9037 5184 inst.operands[i].vectype = optype;
5287ad62
JB
5185 inst.operands[i++].present = 1;
5186
dcbf9037 5187 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5188 {
037e8744
JB
5189 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5190 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5191 inst.operands[i].reg = val;
5192 inst.operands[i].isreg = 1;
037e8744 5193 inst.operands[i].present = 1;
5287ad62
JB
5194
5195 if (rtype == REG_TYPE_NQ)
5196 {
dcbf9037 5197 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5198 return FAIL;
5199 }
037e8744
JB
5200 else if (rtype != REG_TYPE_VFS)
5201 {
5202 i++;
5203 if (skip_past_comma (&ptr) == FAIL)
5204 goto wanted_comma;
5205 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5206 goto wanted_arm;
5207 inst.operands[i].reg = val;
5208 inst.operands[i].isreg = 1;
5209 inst.operands[i].present = 1;
5210 }
5287ad62 5211 }
136da414 5212 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5213 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5214 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5215 Case 10: VMOV.F32 <Sd>, #<imm>
5216 Case 11: VMOV.F64 <Dd>, #<imm> */
c96612cc 5217 inst.operands[i].immisfloat = 1;
5287ad62 5218 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5219 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5220 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5221 ;
5222 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5223 &optype)) != FAIL)
5287ad62
JB
5224 {
5225 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5226 Case 1: VMOV<c><q> <Dd>, <Dm>
5227 Case 8: VMOV.F32 <Sd>, <Sm>
5228 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5229
5230 inst.operands[i].reg = val;
5231 inst.operands[i].isreg = 1;
5232 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5233 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5234 inst.operands[i].isvec = 1;
dcbf9037 5235 inst.operands[i].vectype = optype;
5287ad62 5236 inst.operands[i].present = 1;
5f4273c7 5237
037e8744
JB
5238 if (skip_past_comma (&ptr) == SUCCESS)
5239 {
5240 /* Case 15. */
5241 i++;
5242
5243 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5244 goto wanted_arm;
5245
5246 inst.operands[i].reg = val;
5247 inst.operands[i].isreg = 1;
5248 inst.operands[i++].present = 1;
5f4273c7 5249
037e8744
JB
5250 if (skip_past_comma (&ptr) == FAIL)
5251 goto wanted_comma;
5f4273c7 5252
037e8744
JB
5253 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5254 goto wanted_arm;
5f4273c7 5255
037e8744
JB
5256 inst.operands[i].reg = val;
5257 inst.operands[i].isreg = 1;
5258 inst.operands[i++].present = 1;
5259 }
5287ad62
JB
5260 }
5261 else
5262 {
dcbf9037 5263 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5264 return FAIL;
5265 }
5266 }
dcbf9037 5267 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5268 {
5269 /* Cases 6, 7. */
5270 inst.operands[i].reg = val;
5271 inst.operands[i].isreg = 1;
5272 inst.operands[i++].present = 1;
5f4273c7 5273
5287ad62
JB
5274 if (skip_past_comma (&ptr) == FAIL)
5275 goto wanted_comma;
5f4273c7 5276
dcbf9037 5277 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5278 {
5279 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5280 inst.operands[i].reg = val;
5281 inst.operands[i].isscalar = 1;
5282 inst.operands[i].present = 1;
dcbf9037 5283 inst.operands[i].vectype = optype;
5287ad62 5284 }
dcbf9037 5285 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5286 {
5287 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5288 inst.operands[i].reg = val;
5289 inst.operands[i].isreg = 1;
5290 inst.operands[i++].present = 1;
5f4273c7 5291
5287ad62
JB
5292 if (skip_past_comma (&ptr) == FAIL)
5293 goto wanted_comma;
5f4273c7 5294
037e8744 5295 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5296 == FAIL)
5287ad62 5297 {
037e8744 5298 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5299 return FAIL;
5300 }
5301
5302 inst.operands[i].reg = val;
5303 inst.operands[i].isreg = 1;
037e8744
JB
5304 inst.operands[i].isvec = 1;
5305 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5306 inst.operands[i].vectype = optype;
5287ad62 5307 inst.operands[i].present = 1;
5f4273c7 5308
037e8744
JB
5309 if (rtype == REG_TYPE_VFS)
5310 {
5311 /* Case 14. */
5312 i++;
5313 if (skip_past_comma (&ptr) == FAIL)
5314 goto wanted_comma;
5315 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5316 &optype)) == FAIL)
5317 {
5318 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5319 return FAIL;
5320 }
5321 inst.operands[i].reg = val;
5322 inst.operands[i].isreg = 1;
5323 inst.operands[i].isvec = 1;
5324 inst.operands[i].issingle = 1;
5325 inst.operands[i].vectype = optype;
5326 inst.operands[i].present = 1;
5327 }
5328 }
5329 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5330 != FAIL)
5331 {
5332 /* Case 13. */
5333 inst.operands[i].reg = val;
5334 inst.operands[i].isreg = 1;
5335 inst.operands[i].isvec = 1;
5336 inst.operands[i].issingle = 1;
5337 inst.operands[i].vectype = optype;
5338 inst.operands[i++].present = 1;
5287ad62
JB
5339 }
5340 }
5341 else
5342 {
dcbf9037 5343 first_error (_("parse error"));
5287ad62
JB
5344 return FAIL;
5345 }
5346
5347 /* Successfully parsed the operands. Update args. */
5348 *which_operand = i;
5349 *str = ptr;
5350 return SUCCESS;
5351
5f4273c7 5352 wanted_comma:
dcbf9037 5353 first_error (_("expected comma"));
5287ad62 5354 return FAIL;
5f4273c7
NC
5355
5356 wanted_arm:
dcbf9037 5357 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5358 return FAIL;
5287ad62
JB
5359}
5360
c19d1205
ZW
5361/* Matcher codes for parse_operands. */
5362enum operand_parse_code
5363{
5364 OP_stop, /* end of line */
5365
5366 OP_RR, /* ARM register */
5367 OP_RRnpc, /* ARM register, not r15 */
5368 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5369 OP_RRw, /* ARM register, not r15, optional trailing ! */
5370 OP_RCP, /* Coprocessor number */
5371 OP_RCN, /* Coprocessor register */
5372 OP_RF, /* FPA register */
5373 OP_RVS, /* VFP single precision register */
5287ad62
JB
5374 OP_RVD, /* VFP double precision register (0..15) */
5375 OP_RND, /* Neon double precision register (0..31) */
5376 OP_RNQ, /* Neon quad precision register */
037e8744 5377 OP_RVSD, /* VFP single or double precision register */
5287ad62 5378 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5379 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5380 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5381 OP_RVC, /* VFP control register */
5382 OP_RMF, /* Maverick F register */
5383 OP_RMD, /* Maverick D register */
5384 OP_RMFX, /* Maverick FX register */
5385 OP_RMDX, /* Maverick DX register */
5386 OP_RMAX, /* Maverick AX register */
5387 OP_RMDS, /* Maverick DSPSC register */
5388 OP_RIWR, /* iWMMXt wR register */
5389 OP_RIWC, /* iWMMXt wC register */
5390 OP_RIWG, /* iWMMXt wCG register */
5391 OP_RXA, /* XScale accumulator register */
5392
5393 OP_REGLST, /* ARM register list */
5394 OP_VRSLST, /* VFP single-precision register list */
5395 OP_VRDLST, /* VFP double-precision register list */
037e8744 5396 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5397 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5398 OP_NSTRLST, /* Neon element/structure list */
5399
5400 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5401 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5402 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5403 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5404 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5405 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5406 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5407 OP_VMOV, /* Neon VMOV operands. */
5408 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5409 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5410 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5411
5412 OP_I0, /* immediate zero */
c19d1205
ZW
5413 OP_I7, /* immediate value 0 .. 7 */
5414 OP_I15, /* 0 .. 15 */
5415 OP_I16, /* 1 .. 16 */
5287ad62 5416 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5417 OP_I31, /* 0 .. 31 */
5418 OP_I31w, /* 0 .. 31, optional trailing ! */
5419 OP_I32, /* 1 .. 32 */
5287ad62
JB
5420 OP_I32z, /* 0 .. 32 */
5421 OP_I63, /* 0 .. 63 */
c19d1205 5422 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5423 OP_I64, /* 1 .. 64 */
5424 OP_I64z, /* 0 .. 64 */
c19d1205 5425 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5426
5427 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5428 OP_I7b, /* 0 .. 7 */
5429 OP_I15b, /* 0 .. 15 */
5430 OP_I31b, /* 0 .. 31 */
5431
5432 OP_SH, /* shifter operand */
4962c51a 5433 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5434 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5435 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5436 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5437 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5438 OP_EXP, /* arbitrary expression */
5439 OP_EXPi, /* same, with optional immediate prefix */
5440 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5441 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5442
5443 OP_CPSF, /* CPS flags */
5444 OP_ENDI, /* Endianness specifier */
5445 OP_PSR, /* CPSR/SPSR mask for msr */
5446 OP_COND, /* conditional code */
92e90b6e 5447 OP_TB, /* Table branch. */
c19d1205 5448
037e8744
JB
5449 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5450 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5451
c19d1205
ZW
5452 OP_RRnpc_I0, /* ARM register or literal 0 */
5453 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5454 OP_RR_EXi, /* ARM register or expression with imm prefix */
5455 OP_RF_IF, /* FPA register or immediate */
5456 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5457 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5458
5459 /* Optional operands. */
5460 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5461 OP_oI31b, /* 0 .. 31 */
5287ad62 5462 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5463 OP_oIffffb, /* 0 .. 65535 */
5464 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5465
5466 OP_oRR, /* ARM register */
5467 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5468 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5469 OP_oRND, /* Optional Neon double precision register */
5470 OP_oRNQ, /* Optional Neon quad precision register */
5471 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5472 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5473 OP_oSHll, /* LSL immediate */
5474 OP_oSHar, /* ASR immediate */
5475 OP_oSHllar, /* LSL or ASR immediate */
5476 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5477 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5478
5479 OP_FIRST_OPTIONAL = OP_oI7b
5480};
a737bd4d 5481
c19d1205
ZW
5482/* Generic instruction operand parser. This does no encoding and no
5483 semantic validation; it merely squirrels values away in the inst
5484 structure. Returns SUCCESS or FAIL depending on whether the
5485 specified grammar matched. */
5486static int
ca3f61f7 5487parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5488{
5489 unsigned const char *upat = pattern;
5490 char *backtrack_pos = 0;
5491 const char *backtrack_error = 0;
5492 int i, val, backtrack_index = 0;
5287ad62 5493 enum arm_reg_type rtype;
4962c51a 5494 parse_operand_result result;
c19d1205
ZW
5495
5496#define po_char_or_fail(chr) do { \
5497 if (skip_past_char (&str, chr) == FAIL) \
5498 goto bad_args; \
5499} while (0)
5500
dcbf9037
JB
5501#define po_reg_or_fail(regtype) do { \
5502 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5503 &inst.operands[i].vectype); \
5504 if (val == FAIL) \
5505 { \
5506 first_error (_(reg_expected_msgs[regtype])); \
5507 goto failure; \
5508 } \
5509 inst.operands[i].reg = val; \
5510 inst.operands[i].isreg = 1; \
5511 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5512 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5513 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5514 || rtype == REG_TYPE_VFD \
5515 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5516} while (0)
5517
dcbf9037
JB
5518#define po_reg_or_goto(regtype, label) do { \
5519 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5520 &inst.operands[i].vectype); \
5521 if (val == FAIL) \
5522 goto label; \
5523 \
5524 inst.operands[i].reg = val; \
5525 inst.operands[i].isreg = 1; \
5526 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5527 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5528 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5529 || rtype == REG_TYPE_VFD \
5530 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5531} while (0)
5532
5533#define po_imm_or_fail(min, max, popt) do { \
5534 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5535 goto failure; \
5536 inst.operands[i].imm = val; \
5537} while (0)
5538
dcbf9037
JB
5539#define po_scalar_or_goto(elsz, label) do { \
5540 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5541 if (val == FAIL) \
5542 goto label; \
5543 inst.operands[i].reg = val; \
5544 inst.operands[i].isscalar = 1; \
5287ad62
JB
5545} while (0)
5546
c19d1205
ZW
5547#define po_misc_or_fail(expr) do { \
5548 if (expr) \
5549 goto failure; \
5550} while (0)
5551
4962c51a
MS
5552#define po_misc_or_fail_no_backtrack(expr) do { \
5553 result = expr; \
5554 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5555 backtrack_pos = 0; \
5556 if (result != PARSE_OPERAND_SUCCESS) \
5557 goto failure; \
5558} while (0)
5559
c19d1205
ZW
5560 skip_whitespace (str);
5561
5562 for (i = 0; upat[i] != OP_stop; i++)
5563 {
5564 if (upat[i] >= OP_FIRST_OPTIONAL)
5565 {
5566 /* Remember where we are in case we need to backtrack. */
5567 assert (!backtrack_pos);
5568 backtrack_pos = str;
5569 backtrack_error = inst.error;
5570 backtrack_index = i;
5571 }
5572
b6702015 5573 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5574 po_char_or_fail (',');
5575
5576 switch (upat[i])
5577 {
5578 /* Registers */
5579 case OP_oRRnpc:
5580 case OP_RRnpc:
5581 case OP_oRR:
5582 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5583 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5584 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5585 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5586 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5587 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5588 case OP_oRND:
5589 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5590 case OP_RVC:
5591 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5592 break;
5593 /* Also accept generic coprocessor regs for unknown registers. */
5594 coproc_reg:
5595 po_reg_or_fail (REG_TYPE_CN);
5596 break;
c19d1205
ZW
5597 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5598 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5599 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5600 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5601 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5602 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5603 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5604 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5605 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5606 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5607 case OP_oRNQ:
5608 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5609 case OP_oRNDQ:
5610 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5611 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5612 case OP_oRNSDQ:
5613 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5614
5615 /* Neon scalar. Using an element size of 8 means that some invalid
5616 scalars are accepted here, so deal with those in later code. */
5617 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5618
5619 /* WARNING: We can expand to two operands here. This has the potential
5620 to totally confuse the backtracking mechanism! It will be OK at
5621 least as long as we don't try to use optional args as well,
5622 though. */
5623 case OP_NILO:
5624 {
5625 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5626 inst.operands[i].present = 1;
5287ad62
JB
5627 i++;
5628 skip_past_comma (&str);
5629 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5630 break;
5631 one_reg_only:
5632 /* Optional register operand was omitted. Unfortunately, it's in
5633 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5634 here (this is a bit grotty). */
5635 inst.operands[i] = inst.operands[i-1];
5636 inst.operands[i-1].present = 0;
5637 break;
5638 try_imm:
036dc3f7
PB
5639 /* There's a possibility of getting a 64-bit immediate here, so
5640 we need special handling. */
5641 if (parse_big_immediate (&str, i) == FAIL)
5642 {
5643 inst.error = _("immediate value is out of range");
5644 goto failure;
5645 }
5287ad62
JB
5646 }
5647 break;
5648
5649 case OP_RNDQ_I0:
5650 {
5651 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5652 break;
5653 try_imm0:
5654 po_imm_or_fail (0, 0, TRUE);
5655 }
5656 break;
5657
037e8744
JB
5658 case OP_RVSD_I0:
5659 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5660 break;
5661
5287ad62
JB
5662 case OP_RR_RNSC:
5663 {
5664 po_scalar_or_goto (8, try_rr);
5665 break;
5666 try_rr:
5667 po_reg_or_fail (REG_TYPE_RN);
5668 }
5669 break;
5670
037e8744
JB
5671 case OP_RNSDQ_RNSC:
5672 {
5673 po_scalar_or_goto (8, try_nsdq);
5674 break;
5675 try_nsdq:
5676 po_reg_or_fail (REG_TYPE_NSDQ);
5677 }
5678 break;
5679
5287ad62
JB
5680 case OP_RNDQ_RNSC:
5681 {
5682 po_scalar_or_goto (8, try_ndq);
5683 break;
5684 try_ndq:
5685 po_reg_or_fail (REG_TYPE_NDQ);
5686 }
5687 break;
5688
5689 case OP_RND_RNSC:
5690 {
5691 po_scalar_or_goto (8, try_vfd);
5692 break;
5693 try_vfd:
5694 po_reg_or_fail (REG_TYPE_VFD);
5695 }
5696 break;
5697
5698 case OP_VMOV:
5699 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5700 not careful then bad things might happen. */
5701 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5702 break;
5703
5704 case OP_RNDQ_IMVNb:
5705 {
5706 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5707 break;
5708 try_mvnimm:
5709 /* There's a possibility of getting a 64-bit immediate here, so
5710 we need special handling. */
5711 if (parse_big_immediate (&str, i) == FAIL)
5712 {
5713 inst.error = _("immediate value is out of range");
5714 goto failure;
5715 }
5716 }
5717 break;
5718
5719 case OP_RNDQ_I63b:
5720 {
5721 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5722 break;
5723 try_shimm:
5724 po_imm_or_fail (0, 63, TRUE);
5725 }
5726 break;
c19d1205
ZW
5727
5728 case OP_RRnpcb:
5729 po_char_or_fail ('[');
5730 po_reg_or_fail (REG_TYPE_RN);
5731 po_char_or_fail (']');
5732 break;
a737bd4d 5733
c19d1205 5734 case OP_RRw:
b6702015 5735 case OP_oRRw:
c19d1205
ZW
5736 po_reg_or_fail (REG_TYPE_RN);
5737 if (skip_past_char (&str, '!') == SUCCESS)
5738 inst.operands[i].writeback = 1;
5739 break;
5740
5741 /* Immediates */
5742 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5743 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5744 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5745 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5746 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5747 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5748 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5749 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5750 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5751 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5752 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5753 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5754
5755 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5756 case OP_oI7b:
5757 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5758 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5759 case OP_oI31b:
5760 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5761 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5762 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5763
5764 /* Immediate variants */
5765 case OP_oI255c:
5766 po_char_or_fail ('{');
5767 po_imm_or_fail (0, 255, TRUE);
5768 po_char_or_fail ('}');
5769 break;
5770
5771 case OP_I31w:
5772 /* The expression parser chokes on a trailing !, so we have
5773 to find it first and zap it. */
5774 {
5775 char *s = str;
5776 while (*s && *s != ',')
5777 s++;
5778 if (s[-1] == '!')
5779 {
5780 s[-1] = '\0';
5781 inst.operands[i].writeback = 1;
5782 }
5783 po_imm_or_fail (0, 31, TRUE);
5784 if (str == s - 1)
5785 str = s;
5786 }
5787 break;
5788
5789 /* Expressions */
5790 case OP_EXPi: EXPi:
5791 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5792 GE_OPT_PREFIX));
5793 break;
5794
5795 case OP_EXP:
5796 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5797 GE_NO_PREFIX));
5798 break;
5799
5800 case OP_EXPr: EXPr:
5801 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5802 GE_NO_PREFIX));
5803 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5804 {
c19d1205
ZW
5805 val = parse_reloc (&str);
5806 if (val == -1)
5807 {
5808 inst.error = _("unrecognized relocation suffix");
5809 goto failure;
5810 }
5811 else if (val != BFD_RELOC_UNUSED)
5812 {
5813 inst.operands[i].imm = val;
5814 inst.operands[i].hasreloc = 1;
5815 }
a737bd4d 5816 }
c19d1205 5817 break;
a737bd4d 5818
b6895b4f
PB
5819 /* Operand for MOVW or MOVT. */
5820 case OP_HALF:
5821 po_misc_or_fail (parse_half (&str));
5822 break;
5823
c19d1205
ZW
5824 /* Register or expression */
5825 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5826 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5827
c19d1205
ZW
5828 /* Register or immediate */
5829 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5830 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5831
c19d1205
ZW
5832 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5833 IF:
5834 if (!is_immediate_prefix (*str))
5835 goto bad_args;
5836 str++;
5837 val = parse_fpa_immediate (&str);
5838 if (val == FAIL)
5839 goto failure;
5840 /* FPA immediates are encoded as registers 8-15.
5841 parse_fpa_immediate has already applied the offset. */
5842 inst.operands[i].reg = val;
5843 inst.operands[i].isreg = 1;
5844 break;
09d92015 5845
2d447fca
JM
5846 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5847 I32z: po_imm_or_fail (0, 32, FALSE); break;
5848
c19d1205
ZW
5849 /* Two kinds of register */
5850 case OP_RIWR_RIWC:
5851 {
5852 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5853 if (!rege
5854 || (rege->type != REG_TYPE_MMXWR
5855 && rege->type != REG_TYPE_MMXWC
5856 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5857 {
5858 inst.error = _("iWMMXt data or control register expected");
5859 goto failure;
5860 }
5861 inst.operands[i].reg = rege->number;
5862 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5863 }
5864 break;
09d92015 5865
41adaa5c
JM
5866 case OP_RIWC_RIWG:
5867 {
5868 struct reg_entry *rege = arm_reg_parse_multi (&str);
5869 if (!rege
5870 || (rege->type != REG_TYPE_MMXWC
5871 && rege->type != REG_TYPE_MMXWCG))
5872 {
5873 inst.error = _("iWMMXt control register expected");
5874 goto failure;
5875 }
5876 inst.operands[i].reg = rege->number;
5877 inst.operands[i].isreg = 1;
5878 }
5879 break;
5880
c19d1205
ZW
5881 /* Misc */
5882 case OP_CPSF: val = parse_cps_flags (&str); break;
5883 case OP_ENDI: val = parse_endian_specifier (&str); break;
5884 case OP_oROR: val = parse_ror (&str); break;
5885 case OP_PSR: val = parse_psr (&str); break;
5886 case OP_COND: val = parse_cond (&str); break;
62b3e311 5887 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5888
037e8744
JB
5889 case OP_RVC_PSR:
5890 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5891 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5892 break;
5893 try_psr:
5894 val = parse_psr (&str);
5895 break;
5896
5897 case OP_APSR_RR:
5898 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5899 break;
5900 try_apsr:
5901 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5902 instruction). */
5903 if (strncasecmp (str, "APSR_", 5) == 0)
5904 {
5905 unsigned found = 0;
5906 str += 5;
5907 while (found < 15)
5908 switch (*str++)
5909 {
5910 case 'c': found = (found & 1) ? 16 : found | 1; break;
5911 case 'n': found = (found & 2) ? 16 : found | 2; break;
5912 case 'z': found = (found & 4) ? 16 : found | 4; break;
5913 case 'v': found = (found & 8) ? 16 : found | 8; break;
5914 default: found = 16;
5915 }
5916 if (found != 15)
5917 goto failure;
5918 inst.operands[i].isvec = 1;
5919 }
5920 else
5921 goto failure;
5922 break;
5923
92e90b6e
PB
5924 case OP_TB:
5925 po_misc_or_fail (parse_tb (&str));
5926 break;
5927
c19d1205
ZW
5928 /* Register lists */
5929 case OP_REGLST:
5930 val = parse_reg_list (&str);
5931 if (*str == '^')
5932 {
5933 inst.operands[1].writeback = 1;
5934 str++;
5935 }
5936 break;
09d92015 5937
c19d1205 5938 case OP_VRSLST:
5287ad62 5939 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5940 break;
09d92015 5941
c19d1205 5942 case OP_VRDLST:
5287ad62 5943 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5944 break;
a737bd4d 5945
037e8744
JB
5946 case OP_VRSDLST:
5947 /* Allow Q registers too. */
5948 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5949 REGLIST_NEON_D);
5950 if (val == FAIL)
5951 {
5952 inst.error = NULL;
5953 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5954 REGLIST_VFP_S);
5955 inst.operands[i].issingle = 1;
5956 }
5957 break;
5958
5287ad62
JB
5959 case OP_NRDLST:
5960 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5961 REGLIST_NEON_D);
5962 break;
5963
5964 case OP_NSTRLST:
dcbf9037
JB
5965 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5966 &inst.operands[i].vectype);
5287ad62
JB
5967 break;
5968
c19d1205
ZW
5969 /* Addressing modes */
5970 case OP_ADDR:
5971 po_misc_or_fail (parse_address (&str, i));
5972 break;
09d92015 5973
4962c51a
MS
5974 case OP_ADDRGLDR:
5975 po_misc_or_fail_no_backtrack (
5976 parse_address_group_reloc (&str, i, GROUP_LDR));
5977 break;
5978
5979 case OP_ADDRGLDRS:
5980 po_misc_or_fail_no_backtrack (
5981 parse_address_group_reloc (&str, i, GROUP_LDRS));
5982 break;
5983
5984 case OP_ADDRGLDC:
5985 po_misc_or_fail_no_backtrack (
5986 parse_address_group_reloc (&str, i, GROUP_LDC));
5987 break;
5988
c19d1205
ZW
5989 case OP_SH:
5990 po_misc_or_fail (parse_shifter_operand (&str, i));
5991 break;
09d92015 5992
4962c51a
MS
5993 case OP_SHG:
5994 po_misc_or_fail_no_backtrack (
5995 parse_shifter_operand_group_reloc (&str, i));
5996 break;
5997
c19d1205
ZW
5998 case OP_oSHll:
5999 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6000 break;
09d92015 6001
c19d1205
ZW
6002 case OP_oSHar:
6003 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6004 break;
09d92015 6005
c19d1205
ZW
6006 case OP_oSHllar:
6007 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6008 break;
09d92015 6009
c19d1205 6010 default:
bd3ba5d1 6011 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6012 }
09d92015 6013
c19d1205
ZW
6014 /* Various value-based sanity checks and shared operations. We
6015 do not signal immediate failures for the register constraints;
6016 this allows a syntax error to take precedence. */
6017 switch (upat[i])
6018 {
6019 case OP_oRRnpc:
6020 case OP_RRnpc:
6021 case OP_RRnpcb:
6022 case OP_RRw:
b6702015 6023 case OP_oRRw:
c19d1205
ZW
6024 case OP_RRnpc_I0:
6025 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6026 inst.error = BAD_PC;
6027 break;
09d92015 6028
c19d1205
ZW
6029 case OP_CPSF:
6030 case OP_ENDI:
6031 case OP_oROR:
6032 case OP_PSR:
037e8744 6033 case OP_RVC_PSR:
c19d1205 6034 case OP_COND:
62b3e311 6035 case OP_oBARRIER:
c19d1205
ZW
6036 case OP_REGLST:
6037 case OP_VRSLST:
6038 case OP_VRDLST:
037e8744 6039 case OP_VRSDLST:
5287ad62
JB
6040 case OP_NRDLST:
6041 case OP_NSTRLST:
c19d1205
ZW
6042 if (val == FAIL)
6043 goto failure;
6044 inst.operands[i].imm = val;
6045 break;
a737bd4d 6046
c19d1205
ZW
6047 default:
6048 break;
6049 }
09d92015 6050
c19d1205
ZW
6051 /* If we get here, this operand was successfully parsed. */
6052 inst.operands[i].present = 1;
6053 continue;
09d92015 6054
c19d1205 6055 bad_args:
09d92015 6056 inst.error = BAD_ARGS;
c19d1205
ZW
6057
6058 failure:
6059 if (!backtrack_pos)
d252fdde
PB
6060 {
6061 /* The parse routine should already have set inst.error, but set a
5f4273c7 6062 default here just in case. */
d252fdde
PB
6063 if (!inst.error)
6064 inst.error = _("syntax error");
6065 return FAIL;
6066 }
c19d1205
ZW
6067
6068 /* Do not backtrack over a trailing optional argument that
6069 absorbed some text. We will only fail again, with the
6070 'garbage following instruction' error message, which is
6071 probably less helpful than the current one. */
6072 if (backtrack_index == i && backtrack_pos != str
6073 && upat[i+1] == OP_stop)
d252fdde
PB
6074 {
6075 if (!inst.error)
6076 inst.error = _("syntax error");
6077 return FAIL;
6078 }
c19d1205
ZW
6079
6080 /* Try again, skipping the optional argument at backtrack_pos. */
6081 str = backtrack_pos;
6082 inst.error = backtrack_error;
6083 inst.operands[backtrack_index].present = 0;
6084 i = backtrack_index;
6085 backtrack_pos = 0;
09d92015 6086 }
09d92015 6087
c19d1205
ZW
6088 /* Check that we have parsed all the arguments. */
6089 if (*str != '\0' && !inst.error)
6090 inst.error = _("garbage following instruction");
09d92015 6091
c19d1205 6092 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6093}
6094
c19d1205
ZW
6095#undef po_char_or_fail
6096#undef po_reg_or_fail
6097#undef po_reg_or_goto
6098#undef po_imm_or_fail
5287ad62 6099#undef po_scalar_or_fail
c19d1205
ZW
6100\f
6101/* Shorthand macro for instruction encoding functions issuing errors. */
6102#define constraint(expr, err) do { \
6103 if (expr) \
6104 { \
6105 inst.error = err; \
6106 return; \
6107 } \
6108} while (0)
6109
6110/* Functions for operand encoding. ARM, then Thumb. */
6111
6112#define rotate_left(v, n) (v << n | v >> (32 - n))
6113
6114/* If VAL can be encoded in the immediate field of an ARM instruction,
6115 return the encoded form. Otherwise, return FAIL. */
6116
6117static unsigned int
6118encode_arm_immediate (unsigned int val)
09d92015 6119{
c19d1205
ZW
6120 unsigned int a, i;
6121
6122 for (i = 0; i < 32; i += 2)
6123 if ((a = rotate_left (val, i)) <= 0xff)
6124 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6125
6126 return FAIL;
09d92015
MM
6127}
6128
c19d1205
ZW
6129/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6130 return the encoded form. Otherwise, return FAIL. */
6131static unsigned int
6132encode_thumb32_immediate (unsigned int val)
09d92015 6133{
c19d1205 6134 unsigned int a, i;
09d92015 6135
9c3c69f2 6136 if (val <= 0xff)
c19d1205 6137 return val;
a737bd4d 6138
9c3c69f2 6139 for (i = 1; i <= 24; i++)
09d92015 6140 {
9c3c69f2
PB
6141 a = val >> i;
6142 if ((val & ~(0xff << i)) == 0)
6143 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6144 }
a737bd4d 6145
c19d1205
ZW
6146 a = val & 0xff;
6147 if (val == ((a << 16) | a))
6148 return 0x100 | a;
6149 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6150 return 0x300 | a;
09d92015 6151
c19d1205
ZW
6152 a = val & 0xff00;
6153 if (val == ((a << 16) | a))
6154 return 0x200 | (a >> 8);
a737bd4d 6155
c19d1205 6156 return FAIL;
09d92015 6157}
5287ad62 6158/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6159
6160static void
5287ad62
JB
6161encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6162{
6163 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6164 && reg > 15)
6165 {
b1cc4aeb 6166 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6167 {
6168 if (thumb_mode)
6169 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6170 fpu_vfp_ext_d32);
5287ad62
JB
6171 else
6172 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6173 fpu_vfp_ext_d32);
5287ad62
JB
6174 }
6175 else
6176 {
dcbf9037 6177 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6178 return;
6179 }
6180 }
6181
c19d1205 6182 switch (pos)
09d92015 6183 {
c19d1205
ZW
6184 case VFP_REG_Sd:
6185 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6186 break;
6187
6188 case VFP_REG_Sn:
6189 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6190 break;
6191
6192 case VFP_REG_Sm:
6193 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6194 break;
6195
5287ad62
JB
6196 case VFP_REG_Dd:
6197 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6198 break;
5f4273c7 6199
5287ad62
JB
6200 case VFP_REG_Dn:
6201 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6202 break;
5f4273c7 6203
5287ad62
JB
6204 case VFP_REG_Dm:
6205 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6206 break;
6207
c19d1205
ZW
6208 default:
6209 abort ();
09d92015 6210 }
09d92015
MM
6211}
6212
c19d1205 6213/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6214 if any, is handled by md_apply_fix. */
09d92015 6215static void
c19d1205 6216encode_arm_shift (int i)
09d92015 6217{
c19d1205
ZW
6218 if (inst.operands[i].shift_kind == SHIFT_RRX)
6219 inst.instruction |= SHIFT_ROR << 5;
6220 else
09d92015 6221 {
c19d1205
ZW
6222 inst.instruction |= inst.operands[i].shift_kind << 5;
6223 if (inst.operands[i].immisreg)
6224 {
6225 inst.instruction |= SHIFT_BY_REG;
6226 inst.instruction |= inst.operands[i].imm << 8;
6227 }
6228 else
6229 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6230 }
c19d1205 6231}
09d92015 6232
c19d1205
ZW
6233static void
6234encode_arm_shifter_operand (int i)
6235{
6236 if (inst.operands[i].isreg)
09d92015 6237 {
c19d1205
ZW
6238 inst.instruction |= inst.operands[i].reg;
6239 encode_arm_shift (i);
09d92015 6240 }
c19d1205
ZW
6241 else
6242 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6243}
6244
c19d1205 6245/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6246static void
c19d1205 6247encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6248{
c19d1205
ZW
6249 assert (inst.operands[i].isreg);
6250 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6251
c19d1205 6252 if (inst.operands[i].preind)
09d92015 6253 {
c19d1205
ZW
6254 if (is_t)
6255 {
6256 inst.error = _("instruction does not accept preindexed addressing");
6257 return;
6258 }
6259 inst.instruction |= PRE_INDEX;
6260 if (inst.operands[i].writeback)
6261 inst.instruction |= WRITE_BACK;
09d92015 6262
c19d1205
ZW
6263 }
6264 else if (inst.operands[i].postind)
6265 {
6266 assert (inst.operands[i].writeback);
6267 if (is_t)
6268 inst.instruction |= WRITE_BACK;
6269 }
6270 else /* unindexed - only for coprocessor */
09d92015 6271 {
c19d1205 6272 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6273 return;
6274 }
6275
c19d1205
ZW
6276 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6277 && (((inst.instruction & 0x000f0000) >> 16)
6278 == ((inst.instruction & 0x0000f000) >> 12)))
6279 as_warn ((inst.instruction & LOAD_BIT)
6280 ? _("destination register same as write-back base")
6281 : _("source register same as write-back base"));
09d92015
MM
6282}
6283
c19d1205
ZW
6284/* inst.operands[i] was set up by parse_address. Encode it into an
6285 ARM-format mode 2 load or store instruction. If is_t is true,
6286 reject forms that cannot be used with a T instruction (i.e. not
6287 post-indexed). */
a737bd4d 6288static void
c19d1205 6289encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6290{
c19d1205 6291 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6292
c19d1205 6293 if (inst.operands[i].immisreg)
09d92015 6294 {
c19d1205
ZW
6295 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6296 inst.instruction |= inst.operands[i].imm;
6297 if (!inst.operands[i].negative)
6298 inst.instruction |= INDEX_UP;
6299 if (inst.operands[i].shifted)
6300 {
6301 if (inst.operands[i].shift_kind == SHIFT_RRX)
6302 inst.instruction |= SHIFT_ROR << 5;
6303 else
6304 {
6305 inst.instruction |= inst.operands[i].shift_kind << 5;
6306 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6307 }
6308 }
09d92015 6309 }
c19d1205 6310 else /* immediate offset in inst.reloc */
09d92015 6311 {
c19d1205
ZW
6312 if (inst.reloc.type == BFD_RELOC_UNUSED)
6313 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6314 }
09d92015
MM
6315}
6316
c19d1205
ZW
6317/* inst.operands[i] was set up by parse_address. Encode it into an
6318 ARM-format mode 3 load or store instruction. Reject forms that
6319 cannot be used with such instructions. If is_t is true, reject
6320 forms that cannot be used with a T instruction (i.e. not
6321 post-indexed). */
6322static void
6323encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6324{
c19d1205 6325 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6326 {
c19d1205
ZW
6327 inst.error = _("instruction does not accept scaled register index");
6328 return;
09d92015 6329 }
a737bd4d 6330
c19d1205 6331 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6332
c19d1205
ZW
6333 if (inst.operands[i].immisreg)
6334 {
6335 inst.instruction |= inst.operands[i].imm;
6336 if (!inst.operands[i].negative)
6337 inst.instruction |= INDEX_UP;
6338 }
6339 else /* immediate offset in inst.reloc */
6340 {
6341 inst.instruction |= HWOFFSET_IMM;
6342 if (inst.reloc.type == BFD_RELOC_UNUSED)
6343 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6344 }
a737bd4d
NC
6345}
6346
c19d1205
ZW
6347/* inst.operands[i] was set up by parse_address. Encode it into an
6348 ARM-format instruction. Reject all forms which cannot be encoded
6349 into a coprocessor load/store instruction. If wb_ok is false,
6350 reject use of writeback; if unind_ok is false, reject use of
6351 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6352 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6353 (in which case it is preserved). */
09d92015 6354
c19d1205
ZW
6355static int
6356encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6357{
c19d1205 6358 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6359
c19d1205 6360 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6361
c19d1205 6362 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6363 {
c19d1205
ZW
6364 assert (!inst.operands[i].writeback);
6365 if (!unind_ok)
6366 {
6367 inst.error = _("instruction does not support unindexed addressing");
6368 return FAIL;
6369 }
6370 inst.instruction |= inst.operands[i].imm;
6371 inst.instruction |= INDEX_UP;
6372 return SUCCESS;
09d92015 6373 }
a737bd4d 6374
c19d1205
ZW
6375 if (inst.operands[i].preind)
6376 inst.instruction |= PRE_INDEX;
a737bd4d 6377
c19d1205 6378 if (inst.operands[i].writeback)
09d92015 6379 {
c19d1205
ZW
6380 if (inst.operands[i].reg == REG_PC)
6381 {
6382 inst.error = _("pc may not be used with write-back");
6383 return FAIL;
6384 }
6385 if (!wb_ok)
6386 {
6387 inst.error = _("instruction does not support writeback");
6388 return FAIL;
6389 }
6390 inst.instruction |= WRITE_BACK;
09d92015 6391 }
a737bd4d 6392
c19d1205
ZW
6393 if (reloc_override)
6394 inst.reloc.type = reloc_override;
4962c51a
MS
6395 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6396 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6397 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6398 {
6399 if (thumb_mode)
6400 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6401 else
6402 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6403 }
6404
c19d1205
ZW
6405 return SUCCESS;
6406}
a737bd4d 6407
c19d1205
ZW
6408/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6409 Determine whether it can be performed with a move instruction; if
6410 it can, convert inst.instruction to that move instruction and
6411 return 1; if it can't, convert inst.instruction to a literal-pool
6412 load and return 0. If this is not a valid thing to do in the
6413 current context, set inst.error and return 1.
a737bd4d 6414
c19d1205
ZW
6415 inst.operands[i] describes the destination register. */
6416
6417static int
6418move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6419{
53365c0d
PB
6420 unsigned long tbit;
6421
6422 if (thumb_p)
6423 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6424 else
6425 tbit = LOAD_BIT;
6426
6427 if ((inst.instruction & tbit) == 0)
09d92015 6428 {
c19d1205
ZW
6429 inst.error = _("invalid pseudo operation");
6430 return 1;
09d92015 6431 }
c19d1205 6432 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6433 {
6434 inst.error = _("constant expression expected");
c19d1205 6435 return 1;
09d92015 6436 }
c19d1205 6437 if (inst.reloc.exp.X_op == O_constant)
09d92015 6438 {
c19d1205
ZW
6439 if (thumb_p)
6440 {
53365c0d 6441 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6442 {
6443 /* This can be done with a mov(1) instruction. */
6444 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6445 inst.instruction |= inst.reloc.exp.X_add_number;
6446 return 1;
6447 }
6448 }
6449 else
6450 {
6451 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6452 if (value != FAIL)
6453 {
6454 /* This can be done with a mov instruction. */
6455 inst.instruction &= LITERAL_MASK;
6456 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6457 inst.instruction |= value & 0xfff;
6458 return 1;
6459 }
09d92015 6460
c19d1205
ZW
6461 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6462 if (value != FAIL)
6463 {
6464 /* This can be done with a mvn instruction. */
6465 inst.instruction &= LITERAL_MASK;
6466 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6467 inst.instruction |= value & 0xfff;
6468 return 1;
6469 }
6470 }
09d92015
MM
6471 }
6472
c19d1205
ZW
6473 if (add_to_lit_pool () == FAIL)
6474 {
6475 inst.error = _("literal pool insertion failed");
6476 return 1;
6477 }
6478 inst.operands[1].reg = REG_PC;
6479 inst.operands[1].isreg = 1;
6480 inst.operands[1].preind = 1;
6481 inst.reloc.pc_rel = 1;
6482 inst.reloc.type = (thumb_p
6483 ? BFD_RELOC_ARM_THUMB_OFFSET
6484 : (mode_3
6485 ? BFD_RELOC_ARM_HWLITERAL
6486 : BFD_RELOC_ARM_LITERAL));
6487 return 0;
09d92015
MM
6488}
6489
5f4273c7 6490/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6491 First some generics; their names are taken from the conventional
6492 bit positions for register arguments in ARM format instructions. */
09d92015 6493
a737bd4d 6494static void
c19d1205 6495do_noargs (void)
09d92015 6496{
c19d1205 6497}
a737bd4d 6498
c19d1205
ZW
6499static void
6500do_rd (void)
6501{
6502 inst.instruction |= inst.operands[0].reg << 12;
6503}
a737bd4d 6504
c19d1205
ZW
6505static void
6506do_rd_rm (void)
6507{
6508 inst.instruction |= inst.operands[0].reg << 12;
6509 inst.instruction |= inst.operands[1].reg;
6510}
09d92015 6511
c19d1205
ZW
6512static void
6513do_rd_rn (void)
6514{
6515 inst.instruction |= inst.operands[0].reg << 12;
6516 inst.instruction |= inst.operands[1].reg << 16;
6517}
a737bd4d 6518
c19d1205
ZW
6519static void
6520do_rn_rd (void)
6521{
6522 inst.instruction |= inst.operands[0].reg << 16;
6523 inst.instruction |= inst.operands[1].reg << 12;
6524}
09d92015 6525
c19d1205
ZW
6526static void
6527do_rd_rm_rn (void)
6528{
9a64e435 6529 unsigned Rn = inst.operands[2].reg;
708587a4 6530 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6531 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6532 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6533 _("Rn must not overlap other operands"));
c19d1205
ZW
6534 inst.instruction |= inst.operands[0].reg << 12;
6535 inst.instruction |= inst.operands[1].reg;
9a64e435 6536 inst.instruction |= Rn << 16;
c19d1205 6537}
09d92015 6538
c19d1205
ZW
6539static void
6540do_rd_rn_rm (void)
6541{
6542 inst.instruction |= inst.operands[0].reg << 12;
6543 inst.instruction |= inst.operands[1].reg << 16;
6544 inst.instruction |= inst.operands[2].reg;
6545}
a737bd4d 6546
c19d1205
ZW
6547static void
6548do_rm_rd_rn (void)
6549{
6550 inst.instruction |= inst.operands[0].reg;
6551 inst.instruction |= inst.operands[1].reg << 12;
6552 inst.instruction |= inst.operands[2].reg << 16;
6553}
09d92015 6554
c19d1205
ZW
6555static void
6556do_imm0 (void)
6557{
6558 inst.instruction |= inst.operands[0].imm;
6559}
09d92015 6560
c19d1205
ZW
6561static void
6562do_rd_cpaddr (void)
6563{
6564 inst.instruction |= inst.operands[0].reg << 12;
6565 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6566}
a737bd4d 6567
c19d1205
ZW
6568/* ARM instructions, in alphabetical order by function name (except
6569 that wrapper functions appear immediately after the function they
6570 wrap). */
09d92015 6571
c19d1205
ZW
6572/* This is a pseudo-op of the form "adr rd, label" to be converted
6573 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6574
6575static void
c19d1205 6576do_adr (void)
09d92015 6577{
c19d1205 6578 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6579
c19d1205
ZW
6580 /* Frag hacking will turn this into a sub instruction if the offset turns
6581 out to be negative. */
6582 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6583 inst.reloc.pc_rel = 1;
2fc8bdac 6584 inst.reloc.exp.X_add_number -= 8;
c19d1205 6585}
b99bd4ef 6586
c19d1205
ZW
6587/* This is a pseudo-op of the form "adrl rd, label" to be converted
6588 into a relative address of the form:
6589 add rd, pc, #low(label-.-8)"
6590 add rd, rd, #high(label-.-8)" */
b99bd4ef 6591
c19d1205
ZW
6592static void
6593do_adrl (void)
6594{
6595 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6596
c19d1205
ZW
6597 /* Frag hacking will turn this into a sub instruction if the offset turns
6598 out to be negative. */
6599 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6600 inst.reloc.pc_rel = 1;
6601 inst.size = INSN_SIZE * 2;
2fc8bdac 6602 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6603}
6604
b99bd4ef 6605static void
c19d1205 6606do_arit (void)
b99bd4ef 6607{
c19d1205
ZW
6608 if (!inst.operands[1].present)
6609 inst.operands[1].reg = inst.operands[0].reg;
6610 inst.instruction |= inst.operands[0].reg << 12;
6611 inst.instruction |= inst.operands[1].reg << 16;
6612 encode_arm_shifter_operand (2);
6613}
b99bd4ef 6614
62b3e311
PB
6615static void
6616do_barrier (void)
6617{
6618 if (inst.operands[0].present)
6619 {
6620 constraint ((inst.instruction & 0xf0) != 0x40
6621 && inst.operands[0].imm != 0xf,
bd3ba5d1 6622 _("bad barrier type"));
62b3e311
PB
6623 inst.instruction |= inst.operands[0].imm;
6624 }
6625 else
6626 inst.instruction |= 0xf;
6627}
6628
c19d1205
ZW
6629static void
6630do_bfc (void)
6631{
6632 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6633 constraint (msb > 32, _("bit-field extends past end of register"));
6634 /* The instruction encoding stores the LSB and MSB,
6635 not the LSB and width. */
6636 inst.instruction |= inst.operands[0].reg << 12;
6637 inst.instruction |= inst.operands[1].imm << 7;
6638 inst.instruction |= (msb - 1) << 16;
6639}
b99bd4ef 6640
c19d1205
ZW
6641static void
6642do_bfi (void)
6643{
6644 unsigned int msb;
b99bd4ef 6645
c19d1205
ZW
6646 /* #0 in second position is alternative syntax for bfc, which is
6647 the same instruction but with REG_PC in the Rm field. */
6648 if (!inst.operands[1].isreg)
6649 inst.operands[1].reg = REG_PC;
b99bd4ef 6650
c19d1205
ZW
6651 msb = inst.operands[2].imm + inst.operands[3].imm;
6652 constraint (msb > 32, _("bit-field extends past end of register"));
6653 /* The instruction encoding stores the LSB and MSB,
6654 not the LSB and width. */
6655 inst.instruction |= inst.operands[0].reg << 12;
6656 inst.instruction |= inst.operands[1].reg;
6657 inst.instruction |= inst.operands[2].imm << 7;
6658 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6659}
6660
b99bd4ef 6661static void
c19d1205 6662do_bfx (void)
b99bd4ef 6663{
c19d1205
ZW
6664 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6665 _("bit-field extends past end of register"));
6666 inst.instruction |= inst.operands[0].reg << 12;
6667 inst.instruction |= inst.operands[1].reg;
6668 inst.instruction |= inst.operands[2].imm << 7;
6669 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6670}
09d92015 6671
c19d1205
ZW
6672/* ARM V5 breakpoint instruction (argument parse)
6673 BKPT <16 bit unsigned immediate>
6674 Instruction is not conditional.
6675 The bit pattern given in insns[] has the COND_ALWAYS condition,
6676 and it is an error if the caller tried to override that. */
b99bd4ef 6677
c19d1205
ZW
6678static void
6679do_bkpt (void)
6680{
6681 /* Top 12 of 16 bits to bits 19:8. */
6682 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6683
c19d1205
ZW
6684 /* Bottom 4 of 16 bits to bits 3:0. */
6685 inst.instruction |= inst.operands[0].imm & 0xf;
6686}
09d92015 6687
c19d1205
ZW
6688static void
6689encode_branch (int default_reloc)
6690{
6691 if (inst.operands[0].hasreloc)
6692 {
6693 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6694 _("the only suffix valid here is '(plt)'"));
6695 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6696 }
b99bd4ef 6697 else
c19d1205
ZW
6698 {
6699 inst.reloc.type = default_reloc;
c19d1205 6700 }
2fc8bdac 6701 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6702}
6703
b99bd4ef 6704static void
c19d1205 6705do_branch (void)
b99bd4ef 6706{
39b41c9c
PB
6707#ifdef OBJ_ELF
6708 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6709 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6710 else
6711#endif
6712 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6713}
6714
6715static void
6716do_bl (void)
6717{
6718#ifdef OBJ_ELF
6719 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6720 {
6721 if (inst.cond == COND_ALWAYS)
6722 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6723 else
6724 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6725 }
6726 else
6727#endif
6728 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6729}
b99bd4ef 6730
c19d1205
ZW
6731/* ARM V5 branch-link-exchange instruction (argument parse)
6732 BLX <target_addr> ie BLX(1)
6733 BLX{<condition>} <Rm> ie BLX(2)
6734 Unfortunately, there are two different opcodes for this mnemonic.
6735 So, the insns[].value is not used, and the code here zaps values
6736 into inst.instruction.
6737 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6738
c19d1205
ZW
6739static void
6740do_blx (void)
6741{
6742 if (inst.operands[0].isreg)
b99bd4ef 6743 {
c19d1205
ZW
6744 /* Arg is a register; the opcode provided by insns[] is correct.
6745 It is not illegal to do "blx pc", just useless. */
6746 if (inst.operands[0].reg == REG_PC)
6747 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6748
c19d1205
ZW
6749 inst.instruction |= inst.operands[0].reg;
6750 }
6751 else
b99bd4ef 6752 {
c19d1205
ZW
6753 /* Arg is an address; this instruction cannot be executed
6754 conditionally, and the opcode must be adjusted. */
6755 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6756 inst.instruction = 0xfa000000;
39b41c9c
PB
6757#ifdef OBJ_ELF
6758 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6759 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6760 else
6761#endif
6762 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6763 }
c19d1205
ZW
6764}
6765
6766static void
6767do_bx (void)
6768{
845b51d6
PB
6769 bfd_boolean want_reloc;
6770
c19d1205
ZW
6771 if (inst.operands[0].reg == REG_PC)
6772 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6773
c19d1205 6774 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6775 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6776 it is for ARMv4t or earlier. */
6777 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6778 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6779 want_reloc = TRUE;
6780
5ad34203 6781#ifdef OBJ_ELF
845b51d6 6782 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6783#endif
584206db 6784 want_reloc = FALSE;
845b51d6
PB
6785
6786 if (want_reloc)
6787 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6788}
6789
c19d1205
ZW
6790
6791/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6792
6793static void
c19d1205 6794do_bxj (void)
a737bd4d 6795{
c19d1205
ZW
6796 if (inst.operands[0].reg == REG_PC)
6797 as_tsktsk (_("use of r15 in bxj is not really useful"));
6798
6799 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6800}
6801
c19d1205
ZW
6802/* Co-processor data operation:
6803 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6804 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6805static void
6806do_cdp (void)
6807{
6808 inst.instruction |= inst.operands[0].reg << 8;
6809 inst.instruction |= inst.operands[1].imm << 20;
6810 inst.instruction |= inst.operands[2].reg << 12;
6811 inst.instruction |= inst.operands[3].reg << 16;
6812 inst.instruction |= inst.operands[4].reg;
6813 inst.instruction |= inst.operands[5].imm << 5;
6814}
a737bd4d
NC
6815
6816static void
c19d1205 6817do_cmp (void)
a737bd4d 6818{
c19d1205
ZW
6819 inst.instruction |= inst.operands[0].reg << 16;
6820 encode_arm_shifter_operand (1);
a737bd4d
NC
6821}
6822
c19d1205
ZW
6823/* Transfer between coprocessor and ARM registers.
6824 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6825 MRC2
6826 MCR{cond}
6827 MCR2
6828
6829 No special properties. */
09d92015
MM
6830
6831static void
c19d1205 6832do_co_reg (void)
09d92015 6833{
c19d1205
ZW
6834 inst.instruction |= inst.operands[0].reg << 8;
6835 inst.instruction |= inst.operands[1].imm << 21;
6836 inst.instruction |= inst.operands[2].reg << 12;
6837 inst.instruction |= inst.operands[3].reg << 16;
6838 inst.instruction |= inst.operands[4].reg;
6839 inst.instruction |= inst.operands[5].imm << 5;
6840}
09d92015 6841
c19d1205
ZW
6842/* Transfer between coprocessor register and pair of ARM registers.
6843 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6844 MCRR2
6845 MRRC{cond}
6846 MRRC2
b99bd4ef 6847
c19d1205 6848 Two XScale instructions are special cases of these:
09d92015 6849
c19d1205
ZW
6850 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6851 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6852
5f4273c7 6853 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6854
c19d1205
ZW
6855static void
6856do_co_reg2c (void)
6857{
6858 inst.instruction |= inst.operands[0].reg << 8;
6859 inst.instruction |= inst.operands[1].imm << 4;
6860 inst.instruction |= inst.operands[2].reg << 12;
6861 inst.instruction |= inst.operands[3].reg << 16;
6862 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6863}
6864
c19d1205
ZW
6865static void
6866do_cpsi (void)
6867{
6868 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6869 if (inst.operands[1].present)
6870 {
6871 inst.instruction |= CPSI_MMOD;
6872 inst.instruction |= inst.operands[1].imm;
6873 }
c19d1205 6874}
b99bd4ef 6875
62b3e311
PB
6876static void
6877do_dbg (void)
6878{
6879 inst.instruction |= inst.operands[0].imm;
6880}
6881
b99bd4ef 6882static void
c19d1205 6883do_it (void)
b99bd4ef 6884{
c19d1205
ZW
6885 /* There is no IT instruction in ARM mode. We
6886 process it but do not generate code for it. */
6887 inst.size = 0;
09d92015 6888}
b99bd4ef 6889
09d92015 6890static void
c19d1205 6891do_ldmstm (void)
ea6ef066 6892{
c19d1205
ZW
6893 int base_reg = inst.operands[0].reg;
6894 int range = inst.operands[1].imm;
ea6ef066 6895
c19d1205
ZW
6896 inst.instruction |= base_reg << 16;
6897 inst.instruction |= range;
ea6ef066 6898
c19d1205
ZW
6899 if (inst.operands[1].writeback)
6900 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6901
c19d1205 6902 if (inst.operands[0].writeback)
ea6ef066 6903 {
c19d1205
ZW
6904 inst.instruction |= WRITE_BACK;
6905 /* Check for unpredictable uses of writeback. */
6906 if (inst.instruction & LOAD_BIT)
09d92015 6907 {
c19d1205
ZW
6908 /* Not allowed in LDM type 2. */
6909 if ((inst.instruction & LDM_TYPE_2_OR_3)
6910 && ((range & (1 << REG_PC)) == 0))
6911 as_warn (_("writeback of base register is UNPREDICTABLE"));
6912 /* Only allowed if base reg not in list for other types. */
6913 else if (range & (1 << base_reg))
6914 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6915 }
6916 else /* STM. */
6917 {
6918 /* Not allowed for type 2. */
6919 if (inst.instruction & LDM_TYPE_2_OR_3)
6920 as_warn (_("writeback of base register is UNPREDICTABLE"));
6921 /* Only allowed if base reg not in list, or first in list. */
6922 else if ((range & (1 << base_reg))
6923 && (range & ((1 << base_reg) - 1)))
6924 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6925 }
ea6ef066 6926 }
a737bd4d
NC
6927}
6928
c19d1205
ZW
6929/* ARMv5TE load-consecutive (argument parse)
6930 Mode is like LDRH.
6931
6932 LDRccD R, mode
6933 STRccD R, mode. */
6934
a737bd4d 6935static void
c19d1205 6936do_ldrd (void)
a737bd4d 6937{
c19d1205
ZW
6938 constraint (inst.operands[0].reg % 2 != 0,
6939 _("first destination register must be even"));
6940 constraint (inst.operands[1].present
6941 && inst.operands[1].reg != inst.operands[0].reg + 1,
6942 _("can only load two consecutive registers"));
6943 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6944 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6945
c19d1205
ZW
6946 if (!inst.operands[1].present)
6947 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 6948
c19d1205 6949 if (inst.instruction & LOAD_BIT)
a737bd4d 6950 {
c19d1205
ZW
6951 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6952 register and the first register written; we have to diagnose
6953 overlap between the base and the second register written here. */
ea6ef066 6954
c19d1205
ZW
6955 if (inst.operands[2].reg == inst.operands[1].reg
6956 && (inst.operands[2].writeback || inst.operands[2].postind))
6957 as_warn (_("base register written back, and overlaps "
6958 "second destination register"));
b05fe5cf 6959
c19d1205
ZW
6960 /* For an index-register load, the index register must not overlap the
6961 destination (even if not write-back). */
6962 else if (inst.operands[2].immisreg
ca3f61f7
NC
6963 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6964 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6965 as_warn (_("index register overlaps destination register"));
b05fe5cf 6966 }
c19d1205
ZW
6967
6968 inst.instruction |= inst.operands[0].reg << 12;
6969 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6970}
6971
6972static void
c19d1205 6973do_ldrex (void)
b05fe5cf 6974{
c19d1205
ZW
6975 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6976 || inst.operands[1].postind || inst.operands[1].writeback
6977 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6978 || inst.operands[1].negative
6979 /* This can arise if the programmer has written
6980 strex rN, rM, foo
6981 or if they have mistakenly used a register name as the last
6982 operand, eg:
6983 strex rN, rM, rX
6984 It is very difficult to distinguish between these two cases
6985 because "rX" might actually be a label. ie the register
6986 name has been occluded by a symbol of the same name. So we
6987 just generate a general 'bad addressing mode' type error
6988 message and leave it up to the programmer to discover the
6989 true cause and fix their mistake. */
6990 || (inst.operands[1].reg == REG_PC),
6991 BAD_ADDR_MODE);
b05fe5cf 6992
c19d1205
ZW
6993 constraint (inst.reloc.exp.X_op != O_constant
6994 || inst.reloc.exp.X_add_number != 0,
6995 _("offset must be zero in ARM encoding"));
b05fe5cf 6996
c19d1205
ZW
6997 inst.instruction |= inst.operands[0].reg << 12;
6998 inst.instruction |= inst.operands[1].reg << 16;
6999 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7000}
7001
7002static void
c19d1205 7003do_ldrexd (void)
b05fe5cf 7004{
c19d1205
ZW
7005 constraint (inst.operands[0].reg % 2 != 0,
7006 _("even register required"));
7007 constraint (inst.operands[1].present
7008 && inst.operands[1].reg != inst.operands[0].reg + 1,
7009 _("can only load two consecutive registers"));
7010 /* If op 1 were present and equal to PC, this function wouldn't
7011 have been called in the first place. */
7012 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7013
c19d1205
ZW
7014 inst.instruction |= inst.operands[0].reg << 12;
7015 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7016}
7017
7018static void
c19d1205 7019do_ldst (void)
b05fe5cf 7020{
c19d1205
ZW
7021 inst.instruction |= inst.operands[0].reg << 12;
7022 if (!inst.operands[1].isreg)
7023 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7024 return;
c19d1205 7025 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7026}
7027
7028static void
c19d1205 7029do_ldstt (void)
b05fe5cf 7030{
c19d1205
ZW
7031 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7032 reject [Rn,...]. */
7033 if (inst.operands[1].preind)
b05fe5cf 7034 {
bd3ba5d1
NC
7035 constraint (inst.reloc.exp.X_op != O_constant
7036 || inst.reloc.exp.X_add_number != 0,
c19d1205 7037 _("this instruction requires a post-indexed address"));
b05fe5cf 7038
c19d1205
ZW
7039 inst.operands[1].preind = 0;
7040 inst.operands[1].postind = 1;
7041 inst.operands[1].writeback = 1;
b05fe5cf 7042 }
c19d1205
ZW
7043 inst.instruction |= inst.operands[0].reg << 12;
7044 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7045}
b05fe5cf 7046
c19d1205 7047/* Halfword and signed-byte load/store operations. */
b05fe5cf 7048
c19d1205
ZW
7049static void
7050do_ldstv4 (void)
7051{
7052 inst.instruction |= inst.operands[0].reg << 12;
7053 if (!inst.operands[1].isreg)
7054 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7055 return;
c19d1205 7056 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7057}
7058
7059static void
c19d1205 7060do_ldsttv4 (void)
b05fe5cf 7061{
c19d1205
ZW
7062 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7063 reject [Rn,...]. */
7064 if (inst.operands[1].preind)
b05fe5cf 7065 {
bd3ba5d1
NC
7066 constraint (inst.reloc.exp.X_op != O_constant
7067 || inst.reloc.exp.X_add_number != 0,
c19d1205 7068 _("this instruction requires a post-indexed address"));
b05fe5cf 7069
c19d1205
ZW
7070 inst.operands[1].preind = 0;
7071 inst.operands[1].postind = 1;
7072 inst.operands[1].writeback = 1;
b05fe5cf 7073 }
c19d1205
ZW
7074 inst.instruction |= inst.operands[0].reg << 12;
7075 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7076}
b05fe5cf 7077
c19d1205
ZW
7078/* Co-processor register load/store.
7079 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7080static void
7081do_lstc (void)
7082{
7083 inst.instruction |= inst.operands[0].reg << 8;
7084 inst.instruction |= inst.operands[1].reg << 12;
7085 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7086}
7087
b05fe5cf 7088static void
c19d1205 7089do_mlas (void)
b05fe5cf 7090{
8fb9d7b9 7091 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7092 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7093 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7094 && !(inst.instruction & 0x00400000))
8fb9d7b9 7095 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7096
c19d1205
ZW
7097 inst.instruction |= inst.operands[0].reg << 16;
7098 inst.instruction |= inst.operands[1].reg;
7099 inst.instruction |= inst.operands[2].reg << 8;
7100 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7101}
b05fe5cf 7102
c19d1205
ZW
7103static void
7104do_mov (void)
7105{
7106 inst.instruction |= inst.operands[0].reg << 12;
7107 encode_arm_shifter_operand (1);
7108}
b05fe5cf 7109
c19d1205
ZW
7110/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7111static void
7112do_mov16 (void)
7113{
b6895b4f
PB
7114 bfd_vma imm;
7115 bfd_boolean top;
7116
7117 top = (inst.instruction & 0x00400000) != 0;
7118 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7119 _(":lower16: not allowed this instruction"));
7120 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7121 _(":upper16: not allowed instruction"));
c19d1205 7122 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7123 if (inst.reloc.type == BFD_RELOC_UNUSED)
7124 {
7125 imm = inst.reloc.exp.X_add_number;
7126 /* The value is in two pieces: 0:11, 16:19. */
7127 inst.instruction |= (imm & 0x00000fff);
7128 inst.instruction |= (imm & 0x0000f000) << 4;
7129 }
b05fe5cf 7130}
b99bd4ef 7131
037e8744
JB
7132static void do_vfp_nsyn_opcode (const char *);
7133
7134static int
7135do_vfp_nsyn_mrs (void)
7136{
7137 if (inst.operands[0].isvec)
7138 {
7139 if (inst.operands[1].reg != 1)
7140 first_error (_("operand 1 must be FPSCR"));
7141 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7142 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7143 do_vfp_nsyn_opcode ("fmstat");
7144 }
7145 else if (inst.operands[1].isvec)
7146 do_vfp_nsyn_opcode ("fmrx");
7147 else
7148 return FAIL;
5f4273c7 7149
037e8744
JB
7150 return SUCCESS;
7151}
7152
7153static int
7154do_vfp_nsyn_msr (void)
7155{
7156 if (inst.operands[0].isvec)
7157 do_vfp_nsyn_opcode ("fmxr");
7158 else
7159 return FAIL;
7160
7161 return SUCCESS;
7162}
7163
b99bd4ef 7164static void
c19d1205 7165do_mrs (void)
b99bd4ef 7166{
037e8744
JB
7167 if (do_vfp_nsyn_mrs () == SUCCESS)
7168 return;
7169
c19d1205
ZW
7170 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7171 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7172 != (PSR_c|PSR_f),
7173 _("'CPSR' or 'SPSR' expected"));
7174 inst.instruction |= inst.operands[0].reg << 12;
7175 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7176}
b99bd4ef 7177
c19d1205
ZW
7178/* Two possible forms:
7179 "{C|S}PSR_<field>, Rm",
7180 "{C|S}PSR_f, #expression". */
b99bd4ef 7181
c19d1205
ZW
7182static void
7183do_msr (void)
7184{
037e8744
JB
7185 if (do_vfp_nsyn_msr () == SUCCESS)
7186 return;
7187
c19d1205
ZW
7188 inst.instruction |= inst.operands[0].imm;
7189 if (inst.operands[1].isreg)
7190 inst.instruction |= inst.operands[1].reg;
7191 else
b99bd4ef 7192 {
c19d1205
ZW
7193 inst.instruction |= INST_IMMEDIATE;
7194 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7195 inst.reloc.pc_rel = 0;
b99bd4ef 7196 }
b99bd4ef
NC
7197}
7198
c19d1205
ZW
7199static void
7200do_mul (void)
a737bd4d 7201{
c19d1205
ZW
7202 if (!inst.operands[2].present)
7203 inst.operands[2].reg = inst.operands[0].reg;
7204 inst.instruction |= inst.operands[0].reg << 16;
7205 inst.instruction |= inst.operands[1].reg;
7206 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7207
8fb9d7b9
MS
7208 if (inst.operands[0].reg == inst.operands[1].reg
7209 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7210 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7211}
7212
c19d1205
ZW
7213/* Long Multiply Parser
7214 UMULL RdLo, RdHi, Rm, Rs
7215 SMULL RdLo, RdHi, Rm, Rs
7216 UMLAL RdLo, RdHi, Rm, Rs
7217 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7218
7219static void
c19d1205 7220do_mull (void)
b99bd4ef 7221{
c19d1205
ZW
7222 inst.instruction |= inst.operands[0].reg << 12;
7223 inst.instruction |= inst.operands[1].reg << 16;
7224 inst.instruction |= inst.operands[2].reg;
7225 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7226
682b27ad
PB
7227 /* rdhi and rdlo must be different. */
7228 if (inst.operands[0].reg == inst.operands[1].reg)
7229 as_tsktsk (_("rdhi and rdlo must be different"));
7230
7231 /* rdhi, rdlo and rm must all be different before armv6. */
7232 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7233 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7234 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7235 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7236}
b99bd4ef 7237
c19d1205
ZW
7238static void
7239do_nop (void)
7240{
7241 if (inst.operands[0].present)
7242 {
7243 /* Architectural NOP hints are CPSR sets with no bits selected. */
7244 inst.instruction &= 0xf0000000;
7245 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7246 }
b99bd4ef
NC
7247}
7248
c19d1205
ZW
7249/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7250 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7251 Condition defaults to COND_ALWAYS.
7252 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7253
7254static void
c19d1205 7255do_pkhbt (void)
b99bd4ef 7256{
c19d1205
ZW
7257 inst.instruction |= inst.operands[0].reg << 12;
7258 inst.instruction |= inst.operands[1].reg << 16;
7259 inst.instruction |= inst.operands[2].reg;
7260 if (inst.operands[3].present)
7261 encode_arm_shift (3);
7262}
b99bd4ef 7263
c19d1205 7264/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7265
c19d1205
ZW
7266static void
7267do_pkhtb (void)
7268{
7269 if (!inst.operands[3].present)
b99bd4ef 7270 {
c19d1205
ZW
7271 /* If the shift specifier is omitted, turn the instruction
7272 into pkhbt rd, rm, rn. */
7273 inst.instruction &= 0xfff00010;
7274 inst.instruction |= inst.operands[0].reg << 12;
7275 inst.instruction |= inst.operands[1].reg;
7276 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7277 }
7278 else
7279 {
c19d1205
ZW
7280 inst.instruction |= inst.operands[0].reg << 12;
7281 inst.instruction |= inst.operands[1].reg << 16;
7282 inst.instruction |= inst.operands[2].reg;
7283 encode_arm_shift (3);
b99bd4ef
NC
7284 }
7285}
7286
c19d1205
ZW
7287/* ARMv5TE: Preload-Cache
7288
7289 PLD <addr_mode>
7290
7291 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7292
7293static void
c19d1205 7294do_pld (void)
b99bd4ef 7295{
c19d1205
ZW
7296 constraint (!inst.operands[0].isreg,
7297 _("'[' expected after PLD mnemonic"));
7298 constraint (inst.operands[0].postind,
7299 _("post-indexed expression used in preload instruction"));
7300 constraint (inst.operands[0].writeback,
7301 _("writeback used in preload instruction"));
7302 constraint (!inst.operands[0].preind,
7303 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7304 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7305}
b99bd4ef 7306
62b3e311
PB
7307/* ARMv7: PLI <addr_mode> */
7308static void
7309do_pli (void)
7310{
7311 constraint (!inst.operands[0].isreg,
7312 _("'[' expected after PLI mnemonic"));
7313 constraint (inst.operands[0].postind,
7314 _("post-indexed expression used in preload instruction"));
7315 constraint (inst.operands[0].writeback,
7316 _("writeback used in preload instruction"));
7317 constraint (!inst.operands[0].preind,
7318 _("unindexed addressing used in preload instruction"));
7319 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7320 inst.instruction &= ~PRE_INDEX;
7321}
7322
c19d1205
ZW
7323static void
7324do_push_pop (void)
7325{
7326 inst.operands[1] = inst.operands[0];
7327 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7328 inst.operands[0].isreg = 1;
7329 inst.operands[0].writeback = 1;
7330 inst.operands[0].reg = REG_SP;
7331 do_ldmstm ();
7332}
b99bd4ef 7333
c19d1205
ZW
7334/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7335 word at the specified address and the following word
7336 respectively.
7337 Unconditionally executed.
7338 Error if Rn is R15. */
b99bd4ef 7339
c19d1205
ZW
7340static void
7341do_rfe (void)
7342{
7343 inst.instruction |= inst.operands[0].reg << 16;
7344 if (inst.operands[0].writeback)
7345 inst.instruction |= WRITE_BACK;
7346}
b99bd4ef 7347
c19d1205 7348/* ARM V6 ssat (argument parse). */
b99bd4ef 7349
c19d1205
ZW
7350static void
7351do_ssat (void)
7352{
7353 inst.instruction |= inst.operands[0].reg << 12;
7354 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7355 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7356
c19d1205
ZW
7357 if (inst.operands[3].present)
7358 encode_arm_shift (3);
b99bd4ef
NC
7359}
7360
c19d1205 7361/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7362
7363static void
c19d1205 7364do_usat (void)
b99bd4ef 7365{
c19d1205
ZW
7366 inst.instruction |= inst.operands[0].reg << 12;
7367 inst.instruction |= inst.operands[1].imm << 16;
7368 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7369
c19d1205
ZW
7370 if (inst.operands[3].present)
7371 encode_arm_shift (3);
b99bd4ef
NC
7372}
7373
c19d1205 7374/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7375
7376static void
c19d1205 7377do_ssat16 (void)
09d92015 7378{
c19d1205
ZW
7379 inst.instruction |= inst.operands[0].reg << 12;
7380 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7381 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7382}
7383
c19d1205
ZW
7384static void
7385do_usat16 (void)
a737bd4d 7386{
c19d1205
ZW
7387 inst.instruction |= inst.operands[0].reg << 12;
7388 inst.instruction |= inst.operands[1].imm << 16;
7389 inst.instruction |= inst.operands[2].reg;
7390}
a737bd4d 7391
c19d1205
ZW
7392/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7393 preserving the other bits.
a737bd4d 7394
c19d1205
ZW
7395 setend <endian_specifier>, where <endian_specifier> is either
7396 BE or LE. */
a737bd4d 7397
c19d1205
ZW
7398static void
7399do_setend (void)
7400{
7401 if (inst.operands[0].imm)
7402 inst.instruction |= 0x200;
a737bd4d
NC
7403}
7404
7405static void
c19d1205 7406do_shift (void)
a737bd4d 7407{
c19d1205
ZW
7408 unsigned int Rm = (inst.operands[1].present
7409 ? inst.operands[1].reg
7410 : inst.operands[0].reg);
a737bd4d 7411
c19d1205
ZW
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= Rm;
7414 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7415 {
c19d1205
ZW
7416 inst.instruction |= inst.operands[2].reg << 8;
7417 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7418 }
7419 else
c19d1205 7420 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7421}
7422
09d92015 7423static void
3eb17e6b 7424do_smc (void)
09d92015 7425{
3eb17e6b 7426 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7427 inst.reloc.pc_rel = 0;
09d92015
MM
7428}
7429
09d92015 7430static void
c19d1205 7431do_swi (void)
09d92015 7432{
c19d1205
ZW
7433 inst.reloc.type = BFD_RELOC_ARM_SWI;
7434 inst.reloc.pc_rel = 0;
09d92015
MM
7435}
7436
c19d1205
ZW
7437/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7438 SMLAxy{cond} Rd,Rm,Rs,Rn
7439 SMLAWy{cond} Rd,Rm,Rs,Rn
7440 Error if any register is R15. */
e16bb312 7441
c19d1205
ZW
7442static void
7443do_smla (void)
e16bb312 7444{
c19d1205
ZW
7445 inst.instruction |= inst.operands[0].reg << 16;
7446 inst.instruction |= inst.operands[1].reg;
7447 inst.instruction |= inst.operands[2].reg << 8;
7448 inst.instruction |= inst.operands[3].reg << 12;
7449}
a737bd4d 7450
c19d1205
ZW
7451/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7452 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7453 Error if any register is R15.
7454 Warning if Rdlo == Rdhi. */
a737bd4d 7455
c19d1205
ZW
7456static void
7457do_smlal (void)
7458{
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7462 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7463
c19d1205
ZW
7464 if (inst.operands[0].reg == inst.operands[1].reg)
7465 as_tsktsk (_("rdhi and rdlo must be different"));
7466}
a737bd4d 7467
c19d1205
ZW
7468/* ARM V5E (El Segundo) signed-multiply (argument parse)
7469 SMULxy{cond} Rd,Rm,Rs
7470 Error if any register is R15. */
a737bd4d 7471
c19d1205
ZW
7472static void
7473do_smul (void)
7474{
7475 inst.instruction |= inst.operands[0].reg << 16;
7476 inst.instruction |= inst.operands[1].reg;
7477 inst.instruction |= inst.operands[2].reg << 8;
7478}
a737bd4d 7479
b6702015
PB
7480/* ARM V6 srs (argument parse). The variable fields in the encoding are
7481 the same for both ARM and Thumb-2. */
a737bd4d 7482
c19d1205
ZW
7483static void
7484do_srs (void)
7485{
b6702015
PB
7486 int reg;
7487
7488 if (inst.operands[0].present)
7489 {
7490 reg = inst.operands[0].reg;
7491 constraint (reg != 13, _("SRS base register must be r13"));
7492 }
7493 else
7494 reg = 13;
7495
7496 inst.instruction |= reg << 16;
7497 inst.instruction |= inst.operands[1].imm;
7498 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7499 inst.instruction |= WRITE_BACK;
7500}
a737bd4d 7501
c19d1205 7502/* ARM V6 strex (argument parse). */
a737bd4d 7503
c19d1205
ZW
7504static void
7505do_strex (void)
7506{
7507 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7508 || inst.operands[2].postind || inst.operands[2].writeback
7509 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7510 || inst.operands[2].negative
7511 /* See comment in do_ldrex(). */
7512 || (inst.operands[2].reg == REG_PC),
7513 BAD_ADDR_MODE);
a737bd4d 7514
c19d1205
ZW
7515 constraint (inst.operands[0].reg == inst.operands[1].reg
7516 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7517
c19d1205
ZW
7518 constraint (inst.reloc.exp.X_op != O_constant
7519 || inst.reloc.exp.X_add_number != 0,
7520 _("offset must be zero in ARM encoding"));
a737bd4d 7521
c19d1205
ZW
7522 inst.instruction |= inst.operands[0].reg << 12;
7523 inst.instruction |= inst.operands[1].reg;
7524 inst.instruction |= inst.operands[2].reg << 16;
7525 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7526}
7527
7528static void
c19d1205 7529do_strexd (void)
e16bb312 7530{
c19d1205
ZW
7531 constraint (inst.operands[1].reg % 2 != 0,
7532 _("even register required"));
7533 constraint (inst.operands[2].present
7534 && inst.operands[2].reg != inst.operands[1].reg + 1,
7535 _("can only store two consecutive registers"));
7536 /* If op 2 were present and equal to PC, this function wouldn't
7537 have been called in the first place. */
7538 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7539
c19d1205
ZW
7540 constraint (inst.operands[0].reg == inst.operands[1].reg
7541 || inst.operands[0].reg == inst.operands[1].reg + 1
7542 || inst.operands[0].reg == inst.operands[3].reg,
7543 BAD_OVERLAP);
e16bb312 7544
c19d1205
ZW
7545 inst.instruction |= inst.operands[0].reg << 12;
7546 inst.instruction |= inst.operands[1].reg;
7547 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7548}
7549
c19d1205
ZW
7550/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7551 extends it to 32-bits, and adds the result to a value in another
7552 register. You can specify a rotation by 0, 8, 16, or 24 bits
7553 before extracting the 16-bit value.
7554 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7555 Condition defaults to COND_ALWAYS.
7556 Error if any register uses R15. */
7557
e16bb312 7558static void
c19d1205 7559do_sxtah (void)
e16bb312 7560{
c19d1205
ZW
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].reg << 16;
7563 inst.instruction |= inst.operands[2].reg;
7564 inst.instruction |= inst.operands[3].imm << 10;
7565}
e16bb312 7566
c19d1205 7567/* ARM V6 SXTH.
e16bb312 7568
c19d1205
ZW
7569 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7570 Condition defaults to COND_ALWAYS.
7571 Error if any register uses R15. */
e16bb312
NC
7572
7573static void
c19d1205 7574do_sxth (void)
e16bb312 7575{
c19d1205
ZW
7576 inst.instruction |= inst.operands[0].reg << 12;
7577 inst.instruction |= inst.operands[1].reg;
7578 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7579}
c19d1205
ZW
7580\f
7581/* VFP instructions. In a logical order: SP variant first, monad
7582 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7583
7584static void
c19d1205 7585do_vfp_sp_monadic (void)
e16bb312 7586{
5287ad62
JB
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7589}
7590
7591static void
c19d1205 7592do_vfp_sp_dyadic (void)
e16bb312 7593{
5287ad62
JB
7594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7595 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7596 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7597}
7598
7599static void
c19d1205 7600do_vfp_sp_compare_z (void)
e16bb312 7601{
5287ad62 7602 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7603}
7604
7605static void
c19d1205 7606do_vfp_dp_sp_cvt (void)
e16bb312 7607{
5287ad62
JB
7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7610}
7611
7612static void
c19d1205 7613do_vfp_sp_dp_cvt (void)
e16bb312 7614{
5287ad62
JB
7615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7616 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7617}
7618
7619static void
c19d1205 7620do_vfp_reg_from_sp (void)
e16bb312 7621{
c19d1205 7622 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7624}
7625
7626static void
c19d1205 7627do_vfp_reg2_from_sp2 (void)
e16bb312 7628{
c19d1205
ZW
7629 constraint (inst.operands[2].imm != 2,
7630 _("only two consecutive VFP SP registers allowed here"));
7631 inst.instruction |= inst.operands[0].reg << 12;
7632 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7633 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7634}
7635
7636static void
c19d1205 7637do_vfp_sp_from_reg (void)
e16bb312 7638{
5287ad62 7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7640 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7641}
7642
7643static void
c19d1205 7644do_vfp_sp2_from_reg2 (void)
e16bb312 7645{
c19d1205
ZW
7646 constraint (inst.operands[0].imm != 2,
7647 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7649 inst.instruction |= inst.operands[1].reg << 12;
7650 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7651}
7652
7653static void
c19d1205 7654do_vfp_sp_ldst (void)
e16bb312 7655{
5287ad62 7656 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7657 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7658}
7659
7660static void
c19d1205 7661do_vfp_dp_ldst (void)
e16bb312 7662{
5287ad62 7663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7664 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7665}
7666
c19d1205 7667
e16bb312 7668static void
c19d1205 7669vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7670{
c19d1205
ZW
7671 if (inst.operands[0].writeback)
7672 inst.instruction |= WRITE_BACK;
7673 else
7674 constraint (ldstm_type != VFP_LDSTMIA,
7675 _("this addressing mode requires base-register writeback"));
7676 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7677 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7678 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7679}
7680
7681static void
c19d1205 7682vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7683{
c19d1205 7684 int count;
e16bb312 7685
c19d1205
ZW
7686 if (inst.operands[0].writeback)
7687 inst.instruction |= WRITE_BACK;
7688 else
7689 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7690 _("this addressing mode requires base-register writeback"));
e16bb312 7691
c19d1205 7692 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7694
c19d1205
ZW
7695 count = inst.operands[1].imm << 1;
7696 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7697 count += 1;
e16bb312 7698
c19d1205 7699 inst.instruction |= count;
e16bb312
NC
7700}
7701
7702static void
c19d1205 7703do_vfp_sp_ldstmia (void)
e16bb312 7704{
c19d1205 7705 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7706}
7707
7708static void
c19d1205 7709do_vfp_sp_ldstmdb (void)
e16bb312 7710{
c19d1205 7711 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7712}
7713
7714static void
c19d1205 7715do_vfp_dp_ldstmia (void)
e16bb312 7716{
c19d1205 7717 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7718}
7719
7720static void
c19d1205 7721do_vfp_dp_ldstmdb (void)
e16bb312 7722{
c19d1205 7723 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7724}
7725
7726static void
c19d1205 7727do_vfp_xp_ldstmia (void)
e16bb312 7728{
c19d1205
ZW
7729 vfp_dp_ldstm (VFP_LDSTMIAX);
7730}
e16bb312 7731
c19d1205
ZW
7732static void
7733do_vfp_xp_ldstmdb (void)
7734{
7735 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7736}
5287ad62
JB
7737
7738static void
7739do_vfp_dp_rd_rm (void)
7740{
7741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7742 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7743}
7744
7745static void
7746do_vfp_dp_rn_rd (void)
7747{
7748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7749 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7750}
7751
7752static void
7753do_vfp_dp_rd_rn (void)
7754{
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7757}
7758
7759static void
7760do_vfp_dp_rd_rn_rm (void)
7761{
7762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7763 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7764 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7765}
7766
7767static void
7768do_vfp_dp_rd (void)
7769{
7770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7771}
7772
7773static void
7774do_vfp_dp_rm_rd_rn (void)
7775{
7776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7777 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7778 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7779}
7780
7781/* VFPv3 instructions. */
7782static void
7783do_vfp_sp_const (void)
7784{
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7786 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7787 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7788}
7789
7790static void
7791do_vfp_dp_const (void)
7792{
7793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7794 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7795 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7796}
7797
7798static void
7799vfp_conv (int srcsize)
7800{
7801 unsigned immbits = srcsize - inst.operands[1].imm;
7802 inst.instruction |= (immbits & 1) << 5;
7803 inst.instruction |= (immbits >> 1);
7804}
7805
7806static void
7807do_vfp_sp_conv_16 (void)
7808{
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 vfp_conv (16);
7811}
7812
7813static void
7814do_vfp_dp_conv_16 (void)
7815{
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7817 vfp_conv (16);
7818}
7819
7820static void
7821do_vfp_sp_conv_32 (void)
7822{
7823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7824 vfp_conv (32);
7825}
7826
7827static void
7828do_vfp_dp_conv_32 (void)
7829{
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 vfp_conv (32);
7832}
c19d1205
ZW
7833\f
7834/* FPA instructions. Also in a logical order. */
e16bb312 7835
c19d1205
ZW
7836static void
7837do_fpa_cmp (void)
7838{
7839 inst.instruction |= inst.operands[0].reg << 16;
7840 inst.instruction |= inst.operands[1].reg;
7841}
b99bd4ef
NC
7842
7843static void
c19d1205 7844do_fpa_ldmstm (void)
b99bd4ef 7845{
c19d1205
ZW
7846 inst.instruction |= inst.operands[0].reg << 12;
7847 switch (inst.operands[1].imm)
7848 {
7849 case 1: inst.instruction |= CP_T_X; break;
7850 case 2: inst.instruction |= CP_T_Y; break;
7851 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7852 case 4: break;
7853 default: abort ();
7854 }
b99bd4ef 7855
c19d1205
ZW
7856 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7857 {
7858 /* The instruction specified "ea" or "fd", so we can only accept
7859 [Rn]{!}. The instruction does not really support stacking or
7860 unstacking, so we have to emulate these by setting appropriate
7861 bits and offsets. */
7862 constraint (inst.reloc.exp.X_op != O_constant
7863 || inst.reloc.exp.X_add_number != 0,
7864 _("this instruction does not support indexing"));
b99bd4ef 7865
c19d1205
ZW
7866 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7867 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7868
c19d1205
ZW
7869 if (!(inst.instruction & INDEX_UP))
7870 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7871
c19d1205
ZW
7872 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7873 {
7874 inst.operands[2].preind = 0;
7875 inst.operands[2].postind = 1;
7876 }
7877 }
b99bd4ef 7878
c19d1205 7879 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7880}
c19d1205
ZW
7881\f
7882/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7883
c19d1205
ZW
7884static void
7885do_iwmmxt_tandorc (void)
7886{
7887 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7888}
b99bd4ef 7889
c19d1205
ZW
7890static void
7891do_iwmmxt_textrc (void)
7892{
7893 inst.instruction |= inst.operands[0].reg << 12;
7894 inst.instruction |= inst.operands[1].imm;
7895}
b99bd4ef
NC
7896
7897static void
c19d1205 7898do_iwmmxt_textrm (void)
b99bd4ef 7899{
c19d1205
ZW
7900 inst.instruction |= inst.operands[0].reg << 12;
7901 inst.instruction |= inst.operands[1].reg << 16;
7902 inst.instruction |= inst.operands[2].imm;
7903}
b99bd4ef 7904
c19d1205
ZW
7905static void
7906do_iwmmxt_tinsr (void)
7907{
7908 inst.instruction |= inst.operands[0].reg << 16;
7909 inst.instruction |= inst.operands[1].reg << 12;
7910 inst.instruction |= inst.operands[2].imm;
7911}
b99bd4ef 7912
c19d1205
ZW
7913static void
7914do_iwmmxt_tmia (void)
7915{
7916 inst.instruction |= inst.operands[0].reg << 5;
7917 inst.instruction |= inst.operands[1].reg;
7918 inst.instruction |= inst.operands[2].reg << 12;
7919}
b99bd4ef 7920
c19d1205
ZW
7921static void
7922do_iwmmxt_waligni (void)
7923{
7924 inst.instruction |= inst.operands[0].reg << 12;
7925 inst.instruction |= inst.operands[1].reg << 16;
7926 inst.instruction |= inst.operands[2].reg;
7927 inst.instruction |= inst.operands[3].imm << 20;
7928}
b99bd4ef 7929
2d447fca
JM
7930static void
7931do_iwmmxt_wmerge (void)
7932{
7933 inst.instruction |= inst.operands[0].reg << 12;
7934 inst.instruction |= inst.operands[1].reg << 16;
7935 inst.instruction |= inst.operands[2].reg;
7936 inst.instruction |= inst.operands[3].imm << 21;
7937}
7938
c19d1205
ZW
7939static void
7940do_iwmmxt_wmov (void)
7941{
7942 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7943 inst.instruction |= inst.operands[0].reg << 12;
7944 inst.instruction |= inst.operands[1].reg << 16;
7945 inst.instruction |= inst.operands[1].reg;
7946}
b99bd4ef 7947
c19d1205
ZW
7948static void
7949do_iwmmxt_wldstbh (void)
7950{
8f06b2d8 7951 int reloc;
c19d1205 7952 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7953 if (thumb_mode)
7954 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7955 else
7956 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7957 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7958}
7959
c19d1205
ZW
7960static void
7961do_iwmmxt_wldstw (void)
7962{
7963 /* RIWR_RIWC clears .isreg for a control register. */
7964 if (!inst.operands[0].isreg)
7965 {
7966 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7967 inst.instruction |= 0xf0000000;
7968 }
b99bd4ef 7969
c19d1205
ZW
7970 inst.instruction |= inst.operands[0].reg << 12;
7971 encode_arm_cp_address (1, TRUE, TRUE, 0);
7972}
b99bd4ef
NC
7973
7974static void
c19d1205 7975do_iwmmxt_wldstd (void)
b99bd4ef 7976{
c19d1205 7977 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7978 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7979 && inst.operands[1].immisreg)
7980 {
7981 inst.instruction &= ~0x1a000ff;
7982 inst.instruction |= (0xf << 28);
7983 if (inst.operands[1].preind)
7984 inst.instruction |= PRE_INDEX;
7985 if (!inst.operands[1].negative)
7986 inst.instruction |= INDEX_UP;
7987 if (inst.operands[1].writeback)
7988 inst.instruction |= WRITE_BACK;
7989 inst.instruction |= inst.operands[1].reg << 16;
7990 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7991 inst.instruction |= inst.operands[1].imm;
7992 }
7993 else
7994 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 7995}
b99bd4ef 7996
c19d1205
ZW
7997static void
7998do_iwmmxt_wshufh (void)
7999{
8000 inst.instruction |= inst.operands[0].reg << 12;
8001 inst.instruction |= inst.operands[1].reg << 16;
8002 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8003 inst.instruction |= (inst.operands[2].imm & 0x0f);
8004}
b99bd4ef 8005
c19d1205
ZW
8006static void
8007do_iwmmxt_wzero (void)
8008{
8009 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8010 inst.instruction |= inst.operands[0].reg;
8011 inst.instruction |= inst.operands[0].reg << 12;
8012 inst.instruction |= inst.operands[0].reg << 16;
8013}
2d447fca
JM
8014
8015static void
8016do_iwmmxt_wrwrwr_or_imm5 (void)
8017{
8018 if (inst.operands[2].isreg)
8019 do_rd_rn_rm ();
8020 else {
8021 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8022 _("immediate operand requires iWMMXt2"));
8023 do_rd_rn ();
8024 if (inst.operands[2].imm == 0)
8025 {
8026 switch ((inst.instruction >> 20) & 0xf)
8027 {
8028 case 4:
8029 case 5:
8030 case 6:
5f4273c7 8031 case 7:
2d447fca
JM
8032 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8033 inst.operands[2].imm = 16;
8034 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8035 break;
8036 case 8:
8037 case 9:
8038 case 10:
8039 case 11:
8040 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8041 inst.operands[2].imm = 32;
8042 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8043 break;
8044 case 12:
8045 case 13:
8046 case 14:
8047 case 15:
8048 {
8049 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8050 unsigned long wrn;
8051 wrn = (inst.instruction >> 16) & 0xf;
8052 inst.instruction &= 0xff0fff0f;
8053 inst.instruction |= wrn;
8054 /* Bail out here; the instruction is now assembled. */
8055 return;
8056 }
8057 }
8058 }
8059 /* Map 32 -> 0, etc. */
8060 inst.operands[2].imm &= 0x1f;
8061 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8062 }
8063}
c19d1205
ZW
8064\f
8065/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8066 operations first, then control, shift, and load/store. */
b99bd4ef 8067
c19d1205 8068/* Insns like "foo X,Y,Z". */
b99bd4ef 8069
c19d1205
ZW
8070static void
8071do_mav_triple (void)
8072{
8073 inst.instruction |= inst.operands[0].reg << 16;
8074 inst.instruction |= inst.operands[1].reg;
8075 inst.instruction |= inst.operands[2].reg << 12;
8076}
b99bd4ef 8077
c19d1205
ZW
8078/* Insns like "foo W,X,Y,Z".
8079 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8080
c19d1205
ZW
8081static void
8082do_mav_quad (void)
8083{
8084 inst.instruction |= inst.operands[0].reg << 5;
8085 inst.instruction |= inst.operands[1].reg << 12;
8086 inst.instruction |= inst.operands[2].reg << 16;
8087 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8088}
8089
c19d1205
ZW
8090/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8091static void
8092do_mav_dspsc (void)
a737bd4d 8093{
c19d1205
ZW
8094 inst.instruction |= inst.operands[1].reg << 12;
8095}
a737bd4d 8096
c19d1205
ZW
8097/* Maverick shift immediate instructions.
8098 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8099 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8100
c19d1205
ZW
8101static void
8102do_mav_shift (void)
8103{
8104 int imm = inst.operands[2].imm;
a737bd4d 8105
c19d1205
ZW
8106 inst.instruction |= inst.operands[0].reg << 12;
8107 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8108
c19d1205
ZW
8109 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8110 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8111 Bit 4 should be 0. */
8112 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8113
c19d1205
ZW
8114 inst.instruction |= imm;
8115}
8116\f
8117/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8118
c19d1205
ZW
8119/* Xscale multiply-accumulate (argument parse)
8120 MIAcc acc0,Rm,Rs
8121 MIAPHcc acc0,Rm,Rs
8122 MIAxycc acc0,Rm,Rs. */
a737bd4d 8123
c19d1205
ZW
8124static void
8125do_xsc_mia (void)
8126{
8127 inst.instruction |= inst.operands[1].reg;
8128 inst.instruction |= inst.operands[2].reg << 12;
8129}
a737bd4d 8130
c19d1205 8131/* Xscale move-accumulator-register (argument parse)
a737bd4d 8132
c19d1205 8133 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8134
c19d1205
ZW
8135static void
8136do_xsc_mar (void)
8137{
8138 inst.instruction |= inst.operands[1].reg << 12;
8139 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8140}
8141
c19d1205 8142/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8143
c19d1205 8144 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8145
8146static void
c19d1205 8147do_xsc_mra (void)
b99bd4ef 8148{
c19d1205
ZW
8149 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8150 inst.instruction |= inst.operands[0].reg << 12;
8151 inst.instruction |= inst.operands[1].reg << 16;
8152}
8153\f
8154/* Encoding functions relevant only to Thumb. */
b99bd4ef 8155
c19d1205
ZW
8156/* inst.operands[i] is a shifted-register operand; encode
8157 it into inst.instruction in the format used by Thumb32. */
8158
8159static void
8160encode_thumb32_shifted_operand (int i)
8161{
8162 unsigned int value = inst.reloc.exp.X_add_number;
8163 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8164
9c3c69f2
PB
8165 constraint (inst.operands[i].immisreg,
8166 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8167 inst.instruction |= inst.operands[i].reg;
8168 if (shift == SHIFT_RRX)
8169 inst.instruction |= SHIFT_ROR << 4;
8170 else
b99bd4ef 8171 {
c19d1205
ZW
8172 constraint (inst.reloc.exp.X_op != O_constant,
8173 _("expression too complex"));
8174
8175 constraint (value > 32
8176 || (value == 32 && (shift == SHIFT_LSL
8177 || shift == SHIFT_ROR)),
8178 _("shift expression is too large"));
8179
8180 if (value == 0)
8181 shift = SHIFT_LSL;
8182 else if (value == 32)
8183 value = 0;
8184
8185 inst.instruction |= shift << 4;
8186 inst.instruction |= (value & 0x1c) << 10;
8187 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8188 }
c19d1205 8189}
b99bd4ef 8190
b99bd4ef 8191
c19d1205
ZW
8192/* inst.operands[i] was set up by parse_address. Encode it into a
8193 Thumb32 format load or store instruction. Reject forms that cannot
8194 be used with such instructions. If is_t is true, reject forms that
8195 cannot be used with a T instruction; if is_d is true, reject forms
8196 that cannot be used with a D instruction. */
b99bd4ef 8197
c19d1205
ZW
8198static void
8199encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8200{
8201 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8202
8203 constraint (!inst.operands[i].isreg,
53365c0d 8204 _("Instruction does not support =N addresses"));
b99bd4ef 8205
c19d1205
ZW
8206 inst.instruction |= inst.operands[i].reg << 16;
8207 if (inst.operands[i].immisreg)
b99bd4ef 8208 {
c19d1205
ZW
8209 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8210 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8211 constraint (inst.operands[i].negative,
8212 _("Thumb does not support negative register indexing"));
8213 constraint (inst.operands[i].postind,
8214 _("Thumb does not support register post-indexing"));
8215 constraint (inst.operands[i].writeback,
8216 _("Thumb does not support register indexing with writeback"));
8217 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8218 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8219
f40d1643 8220 inst.instruction |= inst.operands[i].imm;
c19d1205 8221 if (inst.operands[i].shifted)
b99bd4ef 8222 {
c19d1205
ZW
8223 constraint (inst.reloc.exp.X_op != O_constant,
8224 _("expression too complex"));
9c3c69f2
PB
8225 constraint (inst.reloc.exp.X_add_number < 0
8226 || inst.reloc.exp.X_add_number > 3,
c19d1205 8227 _("shift out of range"));
9c3c69f2 8228 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8229 }
8230 inst.reloc.type = BFD_RELOC_UNUSED;
8231 }
8232 else if (inst.operands[i].preind)
8233 {
8234 constraint (is_pc && inst.operands[i].writeback,
8235 _("cannot use writeback with PC-relative addressing"));
f40d1643 8236 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8237 _("cannot use writeback with this instruction"));
8238
8239 if (is_d)
8240 {
8241 inst.instruction |= 0x01000000;
8242 if (inst.operands[i].writeback)
8243 inst.instruction |= 0x00200000;
b99bd4ef 8244 }
c19d1205 8245 else
b99bd4ef 8246 {
c19d1205
ZW
8247 inst.instruction |= 0x00000c00;
8248 if (inst.operands[i].writeback)
8249 inst.instruction |= 0x00000100;
b99bd4ef 8250 }
c19d1205 8251 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8252 }
c19d1205 8253 else if (inst.operands[i].postind)
b99bd4ef 8254 {
c19d1205
ZW
8255 assert (inst.operands[i].writeback);
8256 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8257 constraint (is_t, _("cannot use post-indexing with this instruction"));
8258
8259 if (is_d)
8260 inst.instruction |= 0x00200000;
8261 else
8262 inst.instruction |= 0x00000900;
8263 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8264 }
8265 else /* unindexed - only for coprocessor */
8266 inst.error = _("instruction does not accept unindexed addressing");
8267}
8268
8269/* Table of Thumb instructions which exist in both 16- and 32-bit
8270 encodings (the latter only in post-V6T2 cores). The index is the
8271 value used in the insns table below. When there is more than one
8272 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8273 holds variant (1).
8274 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8275#define T16_32_TAB \
8276 X(adc, 4140, eb400000), \
8277 X(adcs, 4140, eb500000), \
8278 X(add, 1c00, eb000000), \
8279 X(adds, 1c00, eb100000), \
0110f2b8
PB
8280 X(addi, 0000, f1000000), \
8281 X(addis, 0000, f1100000), \
8282 X(add_pc,000f, f20f0000), \
8283 X(add_sp,000d, f10d0000), \
e9f89963 8284 X(adr, 000f, f20f0000), \
c19d1205
ZW
8285 X(and, 4000, ea000000), \
8286 X(ands, 4000, ea100000), \
8287 X(asr, 1000, fa40f000), \
8288 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8289 X(b, e000, f000b000), \
8290 X(bcond, d000, f0008000), \
c19d1205
ZW
8291 X(bic, 4380, ea200000), \
8292 X(bics, 4380, ea300000), \
8293 X(cmn, 42c0, eb100f00), \
8294 X(cmp, 2800, ebb00f00), \
8295 X(cpsie, b660, f3af8400), \
8296 X(cpsid, b670, f3af8600), \
8297 X(cpy, 4600, ea4f0000), \
155257ea 8298 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8299 X(eor, 4040, ea800000), \
8300 X(eors, 4040, ea900000), \
0110f2b8 8301 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8302 X(ldmia, c800, e8900000), \
8303 X(ldr, 6800, f8500000), \
8304 X(ldrb, 7800, f8100000), \
8305 X(ldrh, 8800, f8300000), \
8306 X(ldrsb, 5600, f9100000), \
8307 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8308 X(ldr_pc,4800, f85f0000), \
8309 X(ldr_pc2,4800, f85f0000), \
8310 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8311 X(lsl, 0000, fa00f000), \
8312 X(lsls, 0000, fa10f000), \
8313 X(lsr, 0800, fa20f000), \
8314 X(lsrs, 0800, fa30f000), \
8315 X(mov, 2000, ea4f0000), \
8316 X(movs, 2000, ea5f0000), \
8317 X(mul, 4340, fb00f000), \
8318 X(muls, 4340, ffffffff), /* no 32b muls */ \
8319 X(mvn, 43c0, ea6f0000), \
8320 X(mvns, 43c0, ea7f0000), \
8321 X(neg, 4240, f1c00000), /* rsb #0 */ \
8322 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8323 X(orr, 4300, ea400000), \
8324 X(orrs, 4300, ea500000), \
e9f89963
PB
8325 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8326 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8327 X(rev, ba00, fa90f080), \
8328 X(rev16, ba40, fa90f090), \
8329 X(revsh, bac0, fa90f0b0), \
8330 X(ror, 41c0, fa60f000), \
8331 X(rors, 41c0, fa70f000), \
8332 X(sbc, 4180, eb600000), \
8333 X(sbcs, 4180, eb700000), \
8334 X(stmia, c000, e8800000), \
8335 X(str, 6000, f8400000), \
8336 X(strb, 7000, f8000000), \
8337 X(strh, 8000, f8200000), \
0110f2b8 8338 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8339 X(sub, 1e00, eba00000), \
8340 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8341 X(subi, 8000, f1a00000), \
8342 X(subis, 8000, f1b00000), \
c19d1205
ZW
8343 X(sxtb, b240, fa4ff080), \
8344 X(sxth, b200, fa0ff080), \
8345 X(tst, 4200, ea100f00), \
8346 X(uxtb, b2c0, fa5ff080), \
8347 X(uxth, b280, fa1ff080), \
8348 X(nop, bf00, f3af8000), \
8349 X(yield, bf10, f3af8001), \
8350 X(wfe, bf20, f3af8002), \
8351 X(wfi, bf30, f3af8003), \
8352 X(sev, bf40, f3af9004), /* typo, 8004? */
8353
8354/* To catch errors in encoding functions, the codes are all offset by
8355 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8356 as 16-bit instructions. */
8357#define X(a,b,c) T_MNEM_##a
8358enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8359#undef X
8360
8361#define X(a,b,c) 0x##b
8362static const unsigned short thumb_op16[] = { T16_32_TAB };
8363#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8364#undef X
8365
8366#define X(a,b,c) 0x##c
8367static const unsigned int thumb_op32[] = { T16_32_TAB };
8368#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8369#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8370#undef X
8371#undef T16_32_TAB
8372
8373/* Thumb instruction encoders, in alphabetical order. */
8374
92e90b6e
PB
8375/* ADDW or SUBW. */
8376static void
8377do_t_add_sub_w (void)
8378{
8379 int Rd, Rn;
8380
8381 Rd = inst.operands[0].reg;
8382 Rn = inst.operands[1].reg;
8383
8384 constraint (Rd == 15, _("PC not allowed as destination"));
8385 inst.instruction |= (Rn << 16) | (Rd << 8);
8386 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8387}
8388
c19d1205
ZW
8389/* Parse an add or subtract instruction. We get here with inst.instruction
8390 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8391
8392static void
8393do_t_add_sub (void)
8394{
8395 int Rd, Rs, Rn;
8396
8397 Rd = inst.operands[0].reg;
8398 Rs = (inst.operands[1].present
8399 ? inst.operands[1].reg /* Rd, Rs, foo */
8400 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8401
8402 if (unified_syntax)
8403 {
0110f2b8
PB
8404 bfd_boolean flags;
8405 bfd_boolean narrow;
8406 int opcode;
8407
8408 flags = (inst.instruction == T_MNEM_adds
8409 || inst.instruction == T_MNEM_subs);
8410 if (flags)
8411 narrow = (current_it_mask == 0);
8412 else
8413 narrow = (current_it_mask != 0);
c19d1205 8414 if (!inst.operands[2].isreg)
b99bd4ef 8415 {
16805f35
PB
8416 int add;
8417
8418 add = (inst.instruction == T_MNEM_add
8419 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8420 opcode = 0;
8421 if (inst.size_req != 4)
8422 {
0110f2b8
PB
8423 /* Attempt to use a narrow opcode, with relaxation if
8424 appropriate. */
8425 if (Rd == REG_SP && Rs == REG_SP && !flags)
8426 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8427 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8428 opcode = T_MNEM_add_sp;
8429 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8430 opcode = T_MNEM_add_pc;
8431 else if (Rd <= 7 && Rs <= 7 && narrow)
8432 {
8433 if (flags)
8434 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8435 else
8436 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8437 }
8438 if (opcode)
8439 {
8440 inst.instruction = THUMB_OP16(opcode);
8441 inst.instruction |= (Rd << 4) | Rs;
8442 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8443 if (inst.size_req != 2)
8444 inst.relax = opcode;
8445 }
8446 else
8447 constraint (inst.size_req == 2, BAD_HIREG);
8448 }
8449 if (inst.size_req == 4
8450 || (inst.size_req != 2 && !opcode))
8451 {
efd81785
PB
8452 if (Rd == REG_PC)
8453 {
8454 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8455 _("only SUBS PC, LR, #const allowed"));
8456 constraint (inst.reloc.exp.X_op != O_constant,
8457 _("expression too complex"));
8458 constraint (inst.reloc.exp.X_add_number < 0
8459 || inst.reloc.exp.X_add_number > 0xff,
8460 _("immediate value out of range"));
8461 inst.instruction = T2_SUBS_PC_LR
8462 | inst.reloc.exp.X_add_number;
8463 inst.reloc.type = BFD_RELOC_UNUSED;
8464 return;
8465 }
8466 else if (Rs == REG_PC)
16805f35
PB
8467 {
8468 /* Always use addw/subw. */
8469 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8470 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8471 }
8472 else
8473 {
8474 inst.instruction = THUMB_OP32 (inst.instruction);
8475 inst.instruction = (inst.instruction & 0xe1ffffff)
8476 | 0x10000000;
8477 if (flags)
8478 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8479 else
8480 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8481 }
dc4503c6
PB
8482 inst.instruction |= Rd << 8;
8483 inst.instruction |= Rs << 16;
0110f2b8 8484 }
b99bd4ef 8485 }
c19d1205
ZW
8486 else
8487 {
8488 Rn = inst.operands[2].reg;
8489 /* See if we can do this with a 16-bit instruction. */
8490 if (!inst.operands[2].shifted && inst.size_req != 4)
8491 {
e27ec89e
PB
8492 if (Rd > 7 || Rs > 7 || Rn > 7)
8493 narrow = FALSE;
8494
8495 if (narrow)
c19d1205 8496 {
e27ec89e
PB
8497 inst.instruction = ((inst.instruction == T_MNEM_adds
8498 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8499 ? T_OPCODE_ADD_R3
8500 : T_OPCODE_SUB_R3);
8501 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8502 return;
8503 }
b99bd4ef 8504
7e806470 8505 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8506 {
7e806470
PB
8507 /* Thumb-1 cores (except v6-M) require at least one high
8508 register in a narrow non flag setting add. */
8509 if (Rd > 7 || Rn > 7
8510 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8511 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8512 {
7e806470
PB
8513 if (Rd == Rn)
8514 {
8515 Rn = Rs;
8516 Rs = Rd;
8517 }
c19d1205
ZW
8518 inst.instruction = T_OPCODE_ADD_HI;
8519 inst.instruction |= (Rd & 8) << 4;
8520 inst.instruction |= (Rd & 7);
8521 inst.instruction |= Rn << 3;
8522 return;
8523 }
c19d1205
ZW
8524 }
8525 }
8526 /* If we get here, it can't be done in 16 bits. */
8527 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8528 _("shift must be constant"));
8529 inst.instruction = THUMB_OP32 (inst.instruction);
8530 inst.instruction |= Rd << 8;
8531 inst.instruction |= Rs << 16;
8532 encode_thumb32_shifted_operand (2);
8533 }
8534 }
8535 else
8536 {
8537 constraint (inst.instruction == T_MNEM_adds
8538 || inst.instruction == T_MNEM_subs,
8539 BAD_THUMB32);
b99bd4ef 8540
c19d1205 8541 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8542 {
c19d1205
ZW
8543 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8544 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8545 BAD_HIREG);
8546
8547 inst.instruction = (inst.instruction == T_MNEM_add
8548 ? 0x0000 : 0x8000);
8549 inst.instruction |= (Rd << 4) | Rs;
8550 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8551 return;
8552 }
8553
c19d1205
ZW
8554 Rn = inst.operands[2].reg;
8555 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8556
c19d1205
ZW
8557 /* We now have Rd, Rs, and Rn set to registers. */
8558 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8559 {
c19d1205
ZW
8560 /* Can't do this for SUB. */
8561 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8562 inst.instruction = T_OPCODE_ADD_HI;
8563 inst.instruction |= (Rd & 8) << 4;
8564 inst.instruction |= (Rd & 7);
8565 if (Rs == Rd)
8566 inst.instruction |= Rn << 3;
8567 else if (Rn == Rd)
8568 inst.instruction |= Rs << 3;
8569 else
8570 constraint (1, _("dest must overlap one source register"));
8571 }
8572 else
8573 {
8574 inst.instruction = (inst.instruction == T_MNEM_add
8575 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8576 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8577 }
b99bd4ef 8578 }
b99bd4ef
NC
8579}
8580
c19d1205
ZW
8581static void
8582do_t_adr (void)
8583{
0110f2b8
PB
8584 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8585 {
8586 /* Defer to section relaxation. */
8587 inst.relax = inst.instruction;
8588 inst.instruction = THUMB_OP16 (inst.instruction);
8589 inst.instruction |= inst.operands[0].reg << 4;
8590 }
8591 else if (unified_syntax && inst.size_req != 2)
e9f89963 8592 {
0110f2b8 8593 /* Generate a 32-bit opcode. */
e9f89963
PB
8594 inst.instruction = THUMB_OP32 (inst.instruction);
8595 inst.instruction |= inst.operands[0].reg << 8;
8596 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8597 inst.reloc.pc_rel = 1;
8598 }
8599 else
8600 {
0110f2b8 8601 /* Generate a 16-bit opcode. */
e9f89963
PB
8602 inst.instruction = THUMB_OP16 (inst.instruction);
8603 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8604 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8605 inst.reloc.pc_rel = 1;
b99bd4ef 8606
e9f89963
PB
8607 inst.instruction |= inst.operands[0].reg << 4;
8608 }
c19d1205 8609}
b99bd4ef 8610
c19d1205
ZW
8611/* Arithmetic instructions for which there is just one 16-bit
8612 instruction encoding, and it allows only two low registers.
8613 For maximal compatibility with ARM syntax, we allow three register
8614 operands even when Thumb-32 instructions are not available, as long
8615 as the first two are identical. For instance, both "sbc r0,r1" and
8616 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8617static void
c19d1205 8618do_t_arit3 (void)
b99bd4ef 8619{
c19d1205 8620 int Rd, Rs, Rn;
b99bd4ef 8621
c19d1205
ZW
8622 Rd = inst.operands[0].reg;
8623 Rs = (inst.operands[1].present
8624 ? inst.operands[1].reg /* Rd, Rs, foo */
8625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8626 Rn = inst.operands[2].reg;
b99bd4ef 8627
c19d1205 8628 if (unified_syntax)
b99bd4ef 8629 {
c19d1205
ZW
8630 if (!inst.operands[2].isreg)
8631 {
8632 /* For an immediate, we always generate a 32-bit opcode;
8633 section relaxation will shrink it later if possible. */
8634 inst.instruction = THUMB_OP32 (inst.instruction);
8635 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8636 inst.instruction |= Rd << 8;
8637 inst.instruction |= Rs << 16;
8638 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8639 }
8640 else
8641 {
e27ec89e
PB
8642 bfd_boolean narrow;
8643
c19d1205 8644 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8645 if (THUMB_SETS_FLAGS (inst.instruction))
8646 narrow = current_it_mask == 0;
8647 else
8648 narrow = current_it_mask != 0;
8649
8650 if (Rd > 7 || Rn > 7 || Rs > 7)
8651 narrow = FALSE;
8652 if (inst.operands[2].shifted)
8653 narrow = FALSE;
8654 if (inst.size_req == 4)
8655 narrow = FALSE;
8656
8657 if (narrow
c19d1205
ZW
8658 && Rd == Rs)
8659 {
8660 inst.instruction = THUMB_OP16 (inst.instruction);
8661 inst.instruction |= Rd;
8662 inst.instruction |= Rn << 3;
8663 return;
8664 }
b99bd4ef 8665
c19d1205
ZW
8666 /* If we get here, it can't be done in 16 bits. */
8667 constraint (inst.operands[2].shifted
8668 && inst.operands[2].immisreg,
8669 _("shift must be constant"));
8670 inst.instruction = THUMB_OP32 (inst.instruction);
8671 inst.instruction |= Rd << 8;
8672 inst.instruction |= Rs << 16;
8673 encode_thumb32_shifted_operand (2);
8674 }
a737bd4d 8675 }
c19d1205 8676 else
b99bd4ef 8677 {
c19d1205
ZW
8678 /* On its face this is a lie - the instruction does set the
8679 flags. However, the only supported mnemonic in this mode
8680 says it doesn't. */
8681 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8682
c19d1205
ZW
8683 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8684 _("unshifted register required"));
8685 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8686 constraint (Rd != Rs,
8687 _("dest and source1 must be the same register"));
a737bd4d 8688
c19d1205
ZW
8689 inst.instruction = THUMB_OP16 (inst.instruction);
8690 inst.instruction |= Rd;
8691 inst.instruction |= Rn << 3;
b99bd4ef 8692 }
a737bd4d 8693}
b99bd4ef 8694
c19d1205
ZW
8695/* Similarly, but for instructions where the arithmetic operation is
8696 commutative, so we can allow either of them to be different from
8697 the destination operand in a 16-bit instruction. For instance, all
8698 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8699 accepted. */
8700static void
8701do_t_arit3c (void)
a737bd4d 8702{
c19d1205 8703 int Rd, Rs, Rn;
b99bd4ef 8704
c19d1205
ZW
8705 Rd = inst.operands[0].reg;
8706 Rs = (inst.operands[1].present
8707 ? inst.operands[1].reg /* Rd, Rs, foo */
8708 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8709 Rn = inst.operands[2].reg;
a737bd4d 8710
c19d1205 8711 if (unified_syntax)
a737bd4d 8712 {
c19d1205 8713 if (!inst.operands[2].isreg)
b99bd4ef 8714 {
c19d1205
ZW
8715 /* For an immediate, we always generate a 32-bit opcode;
8716 section relaxation will shrink it later if possible. */
8717 inst.instruction = THUMB_OP32 (inst.instruction);
8718 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8719 inst.instruction |= Rd << 8;
8720 inst.instruction |= Rs << 16;
8721 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8722 }
c19d1205 8723 else
a737bd4d 8724 {
e27ec89e
PB
8725 bfd_boolean narrow;
8726
c19d1205 8727 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8728 if (THUMB_SETS_FLAGS (inst.instruction))
8729 narrow = current_it_mask == 0;
8730 else
8731 narrow = current_it_mask != 0;
8732
8733 if (Rd > 7 || Rn > 7 || Rs > 7)
8734 narrow = FALSE;
8735 if (inst.operands[2].shifted)
8736 narrow = FALSE;
8737 if (inst.size_req == 4)
8738 narrow = FALSE;
8739
8740 if (narrow)
a737bd4d 8741 {
c19d1205 8742 if (Rd == Rs)
a737bd4d 8743 {
c19d1205
ZW
8744 inst.instruction = THUMB_OP16 (inst.instruction);
8745 inst.instruction |= Rd;
8746 inst.instruction |= Rn << 3;
8747 return;
a737bd4d 8748 }
c19d1205 8749 if (Rd == Rn)
a737bd4d 8750 {
c19d1205
ZW
8751 inst.instruction = THUMB_OP16 (inst.instruction);
8752 inst.instruction |= Rd;
8753 inst.instruction |= Rs << 3;
8754 return;
a737bd4d
NC
8755 }
8756 }
c19d1205
ZW
8757
8758 /* If we get here, it can't be done in 16 bits. */
8759 constraint (inst.operands[2].shifted
8760 && inst.operands[2].immisreg,
8761 _("shift must be constant"));
8762 inst.instruction = THUMB_OP32 (inst.instruction);
8763 inst.instruction |= Rd << 8;
8764 inst.instruction |= Rs << 16;
8765 encode_thumb32_shifted_operand (2);
a737bd4d 8766 }
b99bd4ef 8767 }
c19d1205
ZW
8768 else
8769 {
8770 /* On its face this is a lie - the instruction does set the
8771 flags. However, the only supported mnemonic in this mode
8772 says it doesn't. */
8773 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8774
c19d1205
ZW
8775 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8776 _("unshifted register required"));
8777 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8778
8779 inst.instruction = THUMB_OP16 (inst.instruction);
8780 inst.instruction |= Rd;
8781
8782 if (Rd == Rs)
8783 inst.instruction |= Rn << 3;
8784 else if (Rd == Rn)
8785 inst.instruction |= Rs << 3;
8786 else
8787 constraint (1, _("dest must overlap one source register"));
8788 }
a737bd4d
NC
8789}
8790
62b3e311
PB
8791static void
8792do_t_barrier (void)
8793{
8794 if (inst.operands[0].present)
8795 {
8796 constraint ((inst.instruction & 0xf0) != 0x40
8797 && inst.operands[0].imm != 0xf,
bd3ba5d1 8798 _("bad barrier type"));
62b3e311
PB
8799 inst.instruction |= inst.operands[0].imm;
8800 }
8801 else
8802 inst.instruction |= 0xf;
8803}
8804
c19d1205
ZW
8805static void
8806do_t_bfc (void)
a737bd4d 8807{
c19d1205
ZW
8808 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8809 constraint (msb > 32, _("bit-field extends past end of register"));
8810 /* The instruction encoding stores the LSB and MSB,
8811 not the LSB and width. */
8812 inst.instruction |= inst.operands[0].reg << 8;
8813 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8814 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8815 inst.instruction |= msb - 1;
b99bd4ef
NC
8816}
8817
c19d1205
ZW
8818static void
8819do_t_bfi (void)
b99bd4ef 8820{
c19d1205 8821 unsigned int msb;
b99bd4ef 8822
c19d1205
ZW
8823 /* #0 in second position is alternative syntax for bfc, which is
8824 the same instruction but with REG_PC in the Rm field. */
8825 if (!inst.operands[1].isreg)
8826 inst.operands[1].reg = REG_PC;
b99bd4ef 8827
c19d1205
ZW
8828 msb = inst.operands[2].imm + inst.operands[3].imm;
8829 constraint (msb > 32, _("bit-field extends past end of register"));
8830 /* The instruction encoding stores the LSB and MSB,
8831 not the LSB and width. */
8832 inst.instruction |= inst.operands[0].reg << 8;
8833 inst.instruction |= inst.operands[1].reg << 16;
8834 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8835 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8836 inst.instruction |= msb - 1;
b99bd4ef
NC
8837}
8838
c19d1205
ZW
8839static void
8840do_t_bfx (void)
b99bd4ef 8841{
c19d1205
ZW
8842 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8843 _("bit-field extends past end of register"));
8844 inst.instruction |= inst.operands[0].reg << 8;
8845 inst.instruction |= inst.operands[1].reg << 16;
8846 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8847 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8848 inst.instruction |= inst.operands[3].imm - 1;
8849}
b99bd4ef 8850
c19d1205
ZW
8851/* ARM V5 Thumb BLX (argument parse)
8852 BLX <target_addr> which is BLX(1)
8853 BLX <Rm> which is BLX(2)
8854 Unfortunately, there are two different opcodes for this mnemonic.
8855 So, the insns[].value is not used, and the code here zaps values
8856 into inst.instruction.
b99bd4ef 8857
c19d1205
ZW
8858 ??? How to take advantage of the additional two bits of displacement
8859 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8860
c19d1205
ZW
8861static void
8862do_t_blx (void)
8863{
dfa9f0d5 8864 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8865 if (inst.operands[0].isreg)
8866 /* We have a register, so this is BLX(2). */
8867 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8868 else
8869 {
c19d1205 8870 /* No register. This must be BLX(1). */
2fc8bdac 8871 inst.instruction = 0xf000e800;
39b41c9c
PB
8872#ifdef OBJ_ELF
8873 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8874 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8875 else
8876#endif
8877 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8878 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8879 }
8880}
8881
c19d1205
ZW
8882static void
8883do_t_branch (void)
b99bd4ef 8884{
0110f2b8 8885 int opcode;
dfa9f0d5
PB
8886 int cond;
8887
8888 if (current_it_mask)
8889 {
8890 /* Conditional branches inside IT blocks are encoded as unconditional
8891 branches. */
8892 cond = COND_ALWAYS;
8893 /* A branch must be the last instruction in an IT block. */
8894 constraint (current_it_mask != 0x10, BAD_BRANCH);
8895 }
8896 else
8897 cond = inst.cond;
8898
8899 if (cond != COND_ALWAYS)
0110f2b8
PB
8900 opcode = T_MNEM_bcond;
8901 else
8902 opcode = inst.instruction;
8903
8904 if (unified_syntax && inst.size_req == 4)
c19d1205 8905 {
0110f2b8 8906 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8907 if (cond == COND_ALWAYS)
0110f2b8 8908 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8909 else
8910 {
dfa9f0d5
PB
8911 assert (cond != 0xF);
8912 inst.instruction |= cond << 22;
c19d1205
ZW
8913 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8914 }
8915 }
b99bd4ef
NC
8916 else
8917 {
0110f2b8 8918 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8919 if (cond == COND_ALWAYS)
c19d1205
ZW
8920 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8921 else
b99bd4ef 8922 {
dfa9f0d5 8923 inst.instruction |= cond << 8;
c19d1205 8924 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8925 }
0110f2b8
PB
8926 /* Allow section relaxation. */
8927 if (unified_syntax && inst.size_req != 2)
8928 inst.relax = opcode;
b99bd4ef 8929 }
c19d1205
ZW
8930
8931 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8932}
8933
8934static void
c19d1205 8935do_t_bkpt (void)
b99bd4ef 8936{
dfa9f0d5
PB
8937 constraint (inst.cond != COND_ALWAYS,
8938 _("instruction is always unconditional"));
c19d1205 8939 if (inst.operands[0].present)
b99bd4ef 8940 {
c19d1205
ZW
8941 constraint (inst.operands[0].imm > 255,
8942 _("immediate value out of range"));
8943 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8944 }
b99bd4ef
NC
8945}
8946
8947static void
c19d1205 8948do_t_branch23 (void)
b99bd4ef 8949{
dfa9f0d5 8950 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8951 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8952 inst.reloc.pc_rel = 1;
8953
c19d1205
ZW
8954 /* If the destination of the branch is a defined symbol which does not have
8955 the THUMB_FUNC attribute, then we must be calling a function which has
8956 the (interfacearm) attribute. We look for the Thumb entry point to that
8957 function and change the branch to refer to that function instead. */
8958 if ( inst.reloc.exp.X_op == O_symbol
8959 && inst.reloc.exp.X_add_symbol != NULL
8960 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8961 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8962 inst.reloc.exp.X_add_symbol =
8963 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8964}
8965
8966static void
c19d1205 8967do_t_bx (void)
90e4755a 8968{
dfa9f0d5 8969 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8970 inst.instruction |= inst.operands[0].reg << 3;
8971 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8972 should cause the alignment to be checked once it is known. This is
8973 because BX PC only works if the instruction is word aligned. */
8974}
90e4755a 8975
c19d1205
ZW
8976static void
8977do_t_bxj (void)
8978{
dfa9f0d5 8979 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8980 if (inst.operands[0].reg == REG_PC)
8981 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8982
c19d1205 8983 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8984}
8985
8986static void
c19d1205 8987do_t_clz (void)
90e4755a 8988{
c19d1205
ZW
8989 inst.instruction |= inst.operands[0].reg << 8;
8990 inst.instruction |= inst.operands[1].reg << 16;
8991 inst.instruction |= inst.operands[1].reg;
8992}
90e4755a 8993
dfa9f0d5
PB
8994static void
8995do_t_cps (void)
8996{
8997 constraint (current_it_mask, BAD_NOT_IT);
8998 inst.instruction |= inst.operands[0].imm;
8999}
9000
c19d1205
ZW
9001static void
9002do_t_cpsi (void)
9003{
dfa9f0d5 9004 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9005 if (unified_syntax
62b3e311
PB
9006 && (inst.operands[1].present || inst.size_req == 4)
9007 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9008 {
c19d1205
ZW
9009 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9010 inst.instruction = 0xf3af8000;
9011 inst.instruction |= imod << 9;
9012 inst.instruction |= inst.operands[0].imm << 5;
9013 if (inst.operands[1].present)
9014 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9015 }
c19d1205 9016 else
90e4755a 9017 {
62b3e311
PB
9018 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9019 && (inst.operands[0].imm & 4),
9020 _("selected processor does not support 'A' form "
9021 "of this instruction"));
9022 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9023 _("Thumb does not support the 2-argument "
9024 "form of this instruction"));
9025 inst.instruction |= inst.operands[0].imm;
90e4755a 9026 }
90e4755a
RE
9027}
9028
c19d1205
ZW
9029/* THUMB CPY instruction (argument parse). */
9030
90e4755a 9031static void
c19d1205 9032do_t_cpy (void)
90e4755a 9033{
c19d1205 9034 if (inst.size_req == 4)
90e4755a 9035 {
c19d1205
ZW
9036 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9037 inst.instruction |= inst.operands[0].reg << 8;
9038 inst.instruction |= inst.operands[1].reg;
90e4755a 9039 }
c19d1205 9040 else
90e4755a 9041 {
c19d1205
ZW
9042 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9043 inst.instruction |= (inst.operands[0].reg & 0x7);
9044 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9045 }
90e4755a
RE
9046}
9047
90e4755a 9048static void
25fe350b 9049do_t_cbz (void)
90e4755a 9050{
dfa9f0d5 9051 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9052 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9053 inst.instruction |= inst.operands[0].reg;
9054 inst.reloc.pc_rel = 1;
9055 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9056}
90e4755a 9057
62b3e311
PB
9058static void
9059do_t_dbg (void)
9060{
9061 inst.instruction |= inst.operands[0].imm;
9062}
9063
9064static void
9065do_t_div (void)
9066{
9067 if (!inst.operands[1].present)
9068 inst.operands[1].reg = inst.operands[0].reg;
9069 inst.instruction |= inst.operands[0].reg << 8;
9070 inst.instruction |= inst.operands[1].reg << 16;
9071 inst.instruction |= inst.operands[2].reg;
9072}
9073
c19d1205
ZW
9074static void
9075do_t_hint (void)
9076{
9077 if (unified_syntax && inst.size_req == 4)
9078 inst.instruction = THUMB_OP32 (inst.instruction);
9079 else
9080 inst.instruction = THUMB_OP16 (inst.instruction);
9081}
90e4755a 9082
c19d1205
ZW
9083static void
9084do_t_it (void)
9085{
9086 unsigned int cond = inst.operands[0].imm;
e27ec89e 9087
dfa9f0d5 9088 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9089 current_it_mask = (inst.instruction & 0xf) | 0x10;
9090 current_cc = cond;
9091
9092 /* If the condition is a negative condition, invert the mask. */
c19d1205 9093 if ((cond & 0x1) == 0x0)
90e4755a 9094 {
c19d1205 9095 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9096
c19d1205
ZW
9097 if ((mask & 0x7) == 0)
9098 /* no conversion needed */;
9099 else if ((mask & 0x3) == 0)
e27ec89e
PB
9100 mask ^= 0x8;
9101 else if ((mask & 0x1) == 0)
9102 mask ^= 0xC;
c19d1205 9103 else
e27ec89e 9104 mask ^= 0xE;
90e4755a 9105
e27ec89e
PB
9106 inst.instruction &= 0xfff0;
9107 inst.instruction |= mask;
c19d1205 9108 }
90e4755a 9109
c19d1205
ZW
9110 inst.instruction |= cond << 4;
9111}
90e4755a 9112
3c707909
PB
9113/* Helper function used for both push/pop and ldm/stm. */
9114static void
9115encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9116{
9117 bfd_boolean load;
9118
9119 load = (inst.instruction & (1 << 20)) != 0;
9120
9121 if (mask & (1 << 13))
9122 inst.error = _("SP not allowed in register list");
9123 if (load)
9124 {
9125 if (mask & (1 << 14)
9126 && mask & (1 << 15))
9127 inst.error = _("LR and PC should not both be in register list");
9128
9129 if ((mask & (1 << base)) != 0
9130 && writeback)
9131 as_warn (_("base register should not be in register list "
9132 "when written back"));
9133 }
9134 else
9135 {
9136 if (mask & (1 << 15))
9137 inst.error = _("PC not allowed in register list");
9138
9139 if (mask & (1 << base))
9140 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9141 }
9142
9143 if ((mask & (mask - 1)) == 0)
9144 {
9145 /* Single register transfers implemented as str/ldr. */
9146 if (writeback)
9147 {
9148 if (inst.instruction & (1 << 23))
9149 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9150 else
9151 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9152 }
9153 else
9154 {
9155 if (inst.instruction & (1 << 23))
9156 inst.instruction = 0x00800000; /* ia -> [base] */
9157 else
9158 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9159 }
9160
9161 inst.instruction |= 0xf8400000;
9162 if (load)
9163 inst.instruction |= 0x00100000;
9164
5f4273c7 9165 mask = ffs (mask) - 1;
3c707909
PB
9166 mask <<= 12;
9167 }
9168 else if (writeback)
9169 inst.instruction |= WRITE_BACK;
9170
9171 inst.instruction |= mask;
9172 inst.instruction |= base << 16;
9173}
9174
c19d1205
ZW
9175static void
9176do_t_ldmstm (void)
9177{
9178 /* This really doesn't seem worth it. */
9179 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9180 _("expression too complex"));
9181 constraint (inst.operands[1].writeback,
9182 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9183
c19d1205
ZW
9184 if (unified_syntax)
9185 {
3c707909
PB
9186 bfd_boolean narrow;
9187 unsigned mask;
9188
9189 narrow = FALSE;
c19d1205
ZW
9190 /* See if we can use a 16-bit instruction. */
9191 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9192 && inst.size_req != 4
3c707909 9193 && !(inst.operands[1].imm & ~0xff))
90e4755a 9194 {
3c707909 9195 mask = 1 << inst.operands[0].reg;
90e4755a 9196
3c707909
PB
9197 if (inst.operands[0].reg <= 7
9198 && (inst.instruction == T_MNEM_stmia
9199 ? inst.operands[0].writeback
9200 : (inst.operands[0].writeback
9201 == !(inst.operands[1].imm & mask))))
90e4755a 9202 {
3c707909
PB
9203 if (inst.instruction == T_MNEM_stmia
9204 && (inst.operands[1].imm & mask)
9205 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9206 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9207 inst.operands[0].reg);
3c707909
PB
9208
9209 inst.instruction = THUMB_OP16 (inst.instruction);
9210 inst.instruction |= inst.operands[0].reg << 8;
9211 inst.instruction |= inst.operands[1].imm;
9212 narrow = TRUE;
90e4755a 9213 }
3c707909
PB
9214 else if (inst.operands[0] .reg == REG_SP
9215 && inst.operands[0].writeback)
90e4755a 9216 {
3c707909
PB
9217 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9218 ? T_MNEM_push : T_MNEM_pop);
9219 inst.instruction |= inst.operands[1].imm;
9220 narrow = TRUE;
90e4755a 9221 }
3c707909
PB
9222 }
9223
9224 if (!narrow)
9225 {
c19d1205
ZW
9226 if (inst.instruction < 0xffff)
9227 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9228
5f4273c7
NC
9229 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9230 inst.operands[0].writeback);
90e4755a
RE
9231 }
9232 }
c19d1205 9233 else
90e4755a 9234 {
c19d1205
ZW
9235 constraint (inst.operands[0].reg > 7
9236 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9237 constraint (inst.instruction != T_MNEM_ldmia
9238 && inst.instruction != T_MNEM_stmia,
9239 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9240 if (inst.instruction == T_MNEM_stmia)
f03698e6 9241 {
c19d1205
ZW
9242 if (!inst.operands[0].writeback)
9243 as_warn (_("this instruction will write back the base register"));
9244 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9245 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9246 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9247 inst.operands[0].reg);
f03698e6 9248 }
c19d1205 9249 else
90e4755a 9250 {
c19d1205
ZW
9251 if (!inst.operands[0].writeback
9252 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9253 as_warn (_("this instruction will write back the base register"));
9254 else if (inst.operands[0].writeback
9255 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9256 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9257 }
9258
c19d1205
ZW
9259 inst.instruction = THUMB_OP16 (inst.instruction);
9260 inst.instruction |= inst.operands[0].reg << 8;
9261 inst.instruction |= inst.operands[1].imm;
9262 }
9263}
e28cd48c 9264
c19d1205
ZW
9265static void
9266do_t_ldrex (void)
9267{
9268 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9269 || inst.operands[1].postind || inst.operands[1].writeback
9270 || inst.operands[1].immisreg || inst.operands[1].shifted
9271 || inst.operands[1].negative,
01cfc07f 9272 BAD_ADDR_MODE);
e28cd48c 9273
c19d1205
ZW
9274 inst.instruction |= inst.operands[0].reg << 12;
9275 inst.instruction |= inst.operands[1].reg << 16;
9276 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9277}
e28cd48c 9278
c19d1205
ZW
9279static void
9280do_t_ldrexd (void)
9281{
9282 if (!inst.operands[1].present)
1cac9012 9283 {
c19d1205
ZW
9284 constraint (inst.operands[0].reg == REG_LR,
9285 _("r14 not allowed as first register "
9286 "when second register is omitted"));
9287 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9288 }
c19d1205
ZW
9289 constraint (inst.operands[0].reg == inst.operands[1].reg,
9290 BAD_OVERLAP);
b99bd4ef 9291
c19d1205
ZW
9292 inst.instruction |= inst.operands[0].reg << 12;
9293 inst.instruction |= inst.operands[1].reg << 8;
9294 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9295}
9296
9297static void
c19d1205 9298do_t_ldst (void)
b99bd4ef 9299{
0110f2b8
PB
9300 unsigned long opcode;
9301 int Rn;
9302
9303 opcode = inst.instruction;
c19d1205 9304 if (unified_syntax)
b99bd4ef 9305 {
53365c0d
PB
9306 if (!inst.operands[1].isreg)
9307 {
9308 if (opcode <= 0xffff)
9309 inst.instruction = THUMB_OP32 (opcode);
9310 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9311 return;
9312 }
0110f2b8
PB
9313 if (inst.operands[1].isreg
9314 && !inst.operands[1].writeback
c19d1205
ZW
9315 && !inst.operands[1].shifted && !inst.operands[1].postind
9316 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9317 && opcode <= 0xffff
9318 && inst.size_req != 4)
c19d1205 9319 {
0110f2b8
PB
9320 /* Insn may have a 16-bit form. */
9321 Rn = inst.operands[1].reg;
9322 if (inst.operands[1].immisreg)
9323 {
9324 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9325 /* [Rn, Rik] */
0110f2b8
PB
9326 if (Rn <= 7 && inst.operands[1].imm <= 7)
9327 goto op16;
9328 }
9329 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9330 && opcode != T_MNEM_ldrsb)
9331 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9332 || (Rn == REG_SP && opcode == T_MNEM_str))
9333 {
9334 /* [Rn, #const] */
9335 if (Rn > 7)
9336 {
9337 if (Rn == REG_PC)
9338 {
9339 if (inst.reloc.pc_rel)
9340 opcode = T_MNEM_ldr_pc2;
9341 else
9342 opcode = T_MNEM_ldr_pc;
9343 }
9344 else
9345 {
9346 if (opcode == T_MNEM_ldr)
9347 opcode = T_MNEM_ldr_sp;
9348 else
9349 opcode = T_MNEM_str_sp;
9350 }
9351 inst.instruction = inst.operands[0].reg << 8;
9352 }
9353 else
9354 {
9355 inst.instruction = inst.operands[0].reg;
9356 inst.instruction |= inst.operands[1].reg << 3;
9357 }
9358 inst.instruction |= THUMB_OP16 (opcode);
9359 if (inst.size_req == 2)
9360 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9361 else
9362 inst.relax = opcode;
9363 return;
9364 }
c19d1205 9365 }
0110f2b8
PB
9366 /* Definitely a 32-bit variant. */
9367 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9368 inst.instruction |= inst.operands[0].reg << 12;
9369 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9370 return;
9371 }
9372
c19d1205
ZW
9373 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9374
9375 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9376 {
c19d1205
ZW
9377 /* Only [Rn,Rm] is acceptable. */
9378 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9379 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9380 || inst.operands[1].postind || inst.operands[1].shifted
9381 || inst.operands[1].negative,
9382 _("Thumb does not support this addressing mode"));
9383 inst.instruction = THUMB_OP16 (inst.instruction);
9384 goto op16;
b99bd4ef 9385 }
5f4273c7 9386
c19d1205
ZW
9387 inst.instruction = THUMB_OP16 (inst.instruction);
9388 if (!inst.operands[1].isreg)
9389 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9390 return;
b99bd4ef 9391
c19d1205
ZW
9392 constraint (!inst.operands[1].preind
9393 || inst.operands[1].shifted
9394 || inst.operands[1].writeback,
9395 _("Thumb does not support this addressing mode"));
9396 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9397 {
c19d1205
ZW
9398 constraint (inst.instruction & 0x0600,
9399 _("byte or halfword not valid for base register"));
9400 constraint (inst.operands[1].reg == REG_PC
9401 && !(inst.instruction & THUMB_LOAD_BIT),
9402 _("r15 based store not allowed"));
9403 constraint (inst.operands[1].immisreg,
9404 _("invalid base register for register offset"));
b99bd4ef 9405
c19d1205
ZW
9406 if (inst.operands[1].reg == REG_PC)
9407 inst.instruction = T_OPCODE_LDR_PC;
9408 else if (inst.instruction & THUMB_LOAD_BIT)
9409 inst.instruction = T_OPCODE_LDR_SP;
9410 else
9411 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9412
c19d1205
ZW
9413 inst.instruction |= inst.operands[0].reg << 8;
9414 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9415 return;
9416 }
90e4755a 9417
c19d1205
ZW
9418 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9419 if (!inst.operands[1].immisreg)
9420 {
9421 /* Immediate offset. */
9422 inst.instruction |= inst.operands[0].reg;
9423 inst.instruction |= inst.operands[1].reg << 3;
9424 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9425 return;
9426 }
90e4755a 9427
c19d1205
ZW
9428 /* Register offset. */
9429 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9430 constraint (inst.operands[1].negative,
9431 _("Thumb does not support this addressing mode"));
90e4755a 9432
c19d1205
ZW
9433 op16:
9434 switch (inst.instruction)
9435 {
9436 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9437 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9438 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9439 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9440 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9441 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9442 case 0x5600 /* ldrsb */:
9443 case 0x5e00 /* ldrsh */: break;
9444 default: abort ();
9445 }
90e4755a 9446
c19d1205
ZW
9447 inst.instruction |= inst.operands[0].reg;
9448 inst.instruction |= inst.operands[1].reg << 3;
9449 inst.instruction |= inst.operands[1].imm << 6;
9450}
90e4755a 9451
c19d1205
ZW
9452static void
9453do_t_ldstd (void)
9454{
9455 if (!inst.operands[1].present)
b99bd4ef 9456 {
c19d1205
ZW
9457 inst.operands[1].reg = inst.operands[0].reg + 1;
9458 constraint (inst.operands[0].reg == REG_LR,
9459 _("r14 not allowed here"));
b99bd4ef 9460 }
c19d1205
ZW
9461 inst.instruction |= inst.operands[0].reg << 12;
9462 inst.instruction |= inst.operands[1].reg << 8;
9463 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9464}
9465
c19d1205
ZW
9466static void
9467do_t_ldstt (void)
9468{
9469 inst.instruction |= inst.operands[0].reg << 12;
9470 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9471}
a737bd4d 9472
b99bd4ef 9473static void
c19d1205 9474do_t_mla (void)
b99bd4ef 9475{
c19d1205
ZW
9476 inst.instruction |= inst.operands[0].reg << 8;
9477 inst.instruction |= inst.operands[1].reg << 16;
9478 inst.instruction |= inst.operands[2].reg;
9479 inst.instruction |= inst.operands[3].reg << 12;
9480}
b99bd4ef 9481
c19d1205
ZW
9482static void
9483do_t_mlal (void)
9484{
9485 inst.instruction |= inst.operands[0].reg << 12;
9486 inst.instruction |= inst.operands[1].reg << 8;
9487 inst.instruction |= inst.operands[2].reg << 16;
9488 inst.instruction |= inst.operands[3].reg;
9489}
b99bd4ef 9490
c19d1205
ZW
9491static void
9492do_t_mov_cmp (void)
9493{
9494 if (unified_syntax)
b99bd4ef 9495 {
c19d1205
ZW
9496 int r0off = (inst.instruction == T_MNEM_mov
9497 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9498 unsigned long opcode;
3d388997
PB
9499 bfd_boolean narrow;
9500 bfd_boolean low_regs;
9501
9502 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9503 opcode = inst.instruction;
3d388997 9504 if (current_it_mask)
0110f2b8 9505 narrow = opcode != T_MNEM_movs;
3d388997 9506 else
0110f2b8 9507 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9508 if (inst.size_req == 4
9509 || inst.operands[1].shifted)
9510 narrow = FALSE;
9511
efd81785
PB
9512 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9513 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9514 && !inst.operands[1].shifted
9515 && inst.operands[0].reg == REG_PC
9516 && inst.operands[1].reg == REG_LR)
9517 {
9518 inst.instruction = T2_SUBS_PC_LR;
9519 return;
9520 }
9521
c19d1205
ZW
9522 if (!inst.operands[1].isreg)
9523 {
0110f2b8
PB
9524 /* Immediate operand. */
9525 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9526 narrow = 0;
9527 if (low_regs && narrow)
9528 {
9529 inst.instruction = THUMB_OP16 (opcode);
9530 inst.instruction |= inst.operands[0].reg << 8;
9531 if (inst.size_req == 2)
9532 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9533 else
9534 inst.relax = opcode;
9535 }
9536 else
9537 {
9538 inst.instruction = THUMB_OP32 (inst.instruction);
9539 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9540 inst.instruction |= inst.operands[0].reg << r0off;
9541 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9542 }
c19d1205 9543 }
728ca7c9
PB
9544 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9545 && (inst.instruction == T_MNEM_mov
9546 || inst.instruction == T_MNEM_movs))
9547 {
9548 /* Register shifts are encoded as separate shift instructions. */
9549 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9550
9551 if (current_it_mask)
9552 narrow = !flags;
9553 else
9554 narrow = flags;
9555
9556 if (inst.size_req == 4)
9557 narrow = FALSE;
9558
9559 if (!low_regs || inst.operands[1].imm > 7)
9560 narrow = FALSE;
9561
9562 if (inst.operands[0].reg != inst.operands[1].reg)
9563 narrow = FALSE;
9564
9565 switch (inst.operands[1].shift_kind)
9566 {
9567 case SHIFT_LSL:
9568 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9569 break;
9570 case SHIFT_ASR:
9571 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9572 break;
9573 case SHIFT_LSR:
9574 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9575 break;
9576 case SHIFT_ROR:
9577 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9578 break;
9579 default:
5f4273c7 9580 abort ();
728ca7c9
PB
9581 }
9582
9583 inst.instruction = opcode;
9584 if (narrow)
9585 {
9586 inst.instruction |= inst.operands[0].reg;
9587 inst.instruction |= inst.operands[1].imm << 3;
9588 }
9589 else
9590 {
9591 if (flags)
9592 inst.instruction |= CONDS_BIT;
9593
9594 inst.instruction |= inst.operands[0].reg << 8;
9595 inst.instruction |= inst.operands[1].reg << 16;
9596 inst.instruction |= inst.operands[1].imm;
9597 }
9598 }
3d388997 9599 else if (!narrow)
c19d1205 9600 {
728ca7c9
PB
9601 /* Some mov with immediate shift have narrow variants.
9602 Register shifts are handled above. */
9603 if (low_regs && inst.operands[1].shifted
9604 && (inst.instruction == T_MNEM_mov
9605 || inst.instruction == T_MNEM_movs))
9606 {
9607 if (current_it_mask)
9608 narrow = (inst.instruction == T_MNEM_mov);
9609 else
9610 narrow = (inst.instruction == T_MNEM_movs);
9611 }
9612
9613 if (narrow)
9614 {
9615 switch (inst.operands[1].shift_kind)
9616 {
9617 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9618 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9619 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9620 default: narrow = FALSE; break;
9621 }
9622 }
9623
9624 if (narrow)
9625 {
9626 inst.instruction |= inst.operands[0].reg;
9627 inst.instruction |= inst.operands[1].reg << 3;
9628 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9629 }
9630 else
9631 {
9632 inst.instruction = THUMB_OP32 (inst.instruction);
9633 inst.instruction |= inst.operands[0].reg << r0off;
9634 encode_thumb32_shifted_operand (1);
9635 }
c19d1205
ZW
9636 }
9637 else
9638 switch (inst.instruction)
9639 {
9640 case T_MNEM_mov:
9641 inst.instruction = T_OPCODE_MOV_HR;
9642 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9643 inst.instruction |= (inst.operands[0].reg & 0x7);
9644 inst.instruction |= inst.operands[1].reg << 3;
9645 break;
b99bd4ef 9646
c19d1205
ZW
9647 case T_MNEM_movs:
9648 /* We know we have low registers at this point.
9649 Generate ADD Rd, Rs, #0. */
9650 inst.instruction = T_OPCODE_ADD_I3;
9651 inst.instruction |= inst.operands[0].reg;
9652 inst.instruction |= inst.operands[1].reg << 3;
9653 break;
9654
9655 case T_MNEM_cmp:
3d388997 9656 if (low_regs)
c19d1205
ZW
9657 {
9658 inst.instruction = T_OPCODE_CMP_LR;
9659 inst.instruction |= inst.operands[0].reg;
9660 inst.instruction |= inst.operands[1].reg << 3;
9661 }
9662 else
9663 {
9664 inst.instruction = T_OPCODE_CMP_HR;
9665 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9666 inst.instruction |= (inst.operands[0].reg & 0x7);
9667 inst.instruction |= inst.operands[1].reg << 3;
9668 }
9669 break;
9670 }
b99bd4ef
NC
9671 return;
9672 }
9673
c19d1205
ZW
9674 inst.instruction = THUMB_OP16 (inst.instruction);
9675 if (inst.operands[1].isreg)
b99bd4ef 9676 {
c19d1205 9677 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9678 {
c19d1205
ZW
9679 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9680 since a MOV instruction produces unpredictable results. */
9681 if (inst.instruction == T_OPCODE_MOV_I8)
9682 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9683 else
c19d1205 9684 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9685
c19d1205
ZW
9686 inst.instruction |= inst.operands[0].reg;
9687 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9688 }
9689 else
9690 {
c19d1205
ZW
9691 if (inst.instruction == T_OPCODE_MOV_I8)
9692 inst.instruction = T_OPCODE_MOV_HR;
9693 else
9694 inst.instruction = T_OPCODE_CMP_HR;
9695 do_t_cpy ();
b99bd4ef
NC
9696 }
9697 }
c19d1205 9698 else
b99bd4ef 9699 {
c19d1205
ZW
9700 constraint (inst.operands[0].reg > 7,
9701 _("only lo regs allowed with immediate"));
9702 inst.instruction |= inst.operands[0].reg << 8;
9703 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9704 }
9705}
b99bd4ef 9706
c19d1205
ZW
9707static void
9708do_t_mov16 (void)
9709{
b6895b4f
PB
9710 bfd_vma imm;
9711 bfd_boolean top;
9712
9713 top = (inst.instruction & 0x00800000) != 0;
9714 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9715 {
9716 constraint (top, _(":lower16: not allowed this instruction"));
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9718 }
9719 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9720 {
9721 constraint (!top, _(":upper16: not allowed this instruction"));
9722 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9723 }
9724
c19d1205 9725 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9726 if (inst.reloc.type == BFD_RELOC_UNUSED)
9727 {
9728 imm = inst.reloc.exp.X_add_number;
9729 inst.instruction |= (imm & 0xf000) << 4;
9730 inst.instruction |= (imm & 0x0800) << 15;
9731 inst.instruction |= (imm & 0x0700) << 4;
9732 inst.instruction |= (imm & 0x00ff);
9733 }
c19d1205 9734}
b99bd4ef 9735
c19d1205
ZW
9736static void
9737do_t_mvn_tst (void)
9738{
9739 if (unified_syntax)
9740 {
9741 int r0off = (inst.instruction == T_MNEM_mvn
9742 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9743 bfd_boolean narrow;
9744
9745 if (inst.size_req == 4
9746 || inst.instruction > 0xffff
9747 || inst.operands[1].shifted
9748 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9749 narrow = FALSE;
9750 else if (inst.instruction == T_MNEM_cmn)
9751 narrow = TRUE;
9752 else if (THUMB_SETS_FLAGS (inst.instruction))
9753 narrow = (current_it_mask == 0);
9754 else
9755 narrow = (current_it_mask != 0);
9756
c19d1205 9757 if (!inst.operands[1].isreg)
b99bd4ef 9758 {
c19d1205
ZW
9759 /* For an immediate, we always generate a 32-bit opcode;
9760 section relaxation will shrink it later if possible. */
9761 if (inst.instruction < 0xffff)
9762 inst.instruction = THUMB_OP32 (inst.instruction);
9763 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9764 inst.instruction |= inst.operands[0].reg << r0off;
9765 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9766 }
c19d1205 9767 else
b99bd4ef 9768 {
c19d1205 9769 /* See if we can do this with a 16-bit instruction. */
3d388997 9770 if (narrow)
b99bd4ef 9771 {
c19d1205
ZW
9772 inst.instruction = THUMB_OP16 (inst.instruction);
9773 inst.instruction |= inst.operands[0].reg;
9774 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9775 }
c19d1205 9776 else
b99bd4ef 9777 {
c19d1205
ZW
9778 constraint (inst.operands[1].shifted
9779 && inst.operands[1].immisreg,
9780 _("shift must be constant"));
9781 if (inst.instruction < 0xffff)
9782 inst.instruction = THUMB_OP32 (inst.instruction);
9783 inst.instruction |= inst.operands[0].reg << r0off;
9784 encode_thumb32_shifted_operand (1);
b99bd4ef 9785 }
b99bd4ef
NC
9786 }
9787 }
9788 else
9789 {
c19d1205
ZW
9790 constraint (inst.instruction > 0xffff
9791 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9792 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9793 _("unshifted register required"));
9794 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9795 BAD_HIREG);
b99bd4ef 9796
c19d1205
ZW
9797 inst.instruction = THUMB_OP16 (inst.instruction);
9798 inst.instruction |= inst.operands[0].reg;
9799 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9800 }
b99bd4ef
NC
9801}
9802
b05fe5cf 9803static void
c19d1205 9804do_t_mrs (void)
b05fe5cf 9805{
62b3e311 9806 int flags;
037e8744
JB
9807
9808 if (do_vfp_nsyn_mrs () == SUCCESS)
9809 return;
9810
62b3e311
PB
9811 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9812 if (flags == 0)
9813 {
7e806470 9814 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9815 _("selected processor does not support "
9816 "requested special purpose register"));
9817 }
9818 else
9819 {
9820 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9821 _("selected processor does not support "
9822 "requested special purpose register %x"));
9823 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9824 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9825 _("'CPSR' or 'SPSR' expected"));
9826 }
5f4273c7 9827
c19d1205 9828 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9829 inst.instruction |= (flags & SPSR_BIT) >> 2;
9830 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9831}
b05fe5cf 9832
c19d1205
ZW
9833static void
9834do_t_msr (void)
9835{
62b3e311
PB
9836 int flags;
9837
037e8744
JB
9838 if (do_vfp_nsyn_msr () == SUCCESS)
9839 return;
9840
c19d1205
ZW
9841 constraint (!inst.operands[1].isreg,
9842 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9843 flags = inst.operands[0].imm;
9844 if (flags & ~0xff)
9845 {
9846 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9847 _("selected processor does not support "
9848 "requested special purpose register"));
9849 }
9850 else
9851 {
7e806470 9852 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9853 _("selected processor does not support "
9854 "requested special purpose register"));
9855 flags |= PSR_f;
9856 }
9857 inst.instruction |= (flags & SPSR_BIT) >> 2;
9858 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9859 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9860 inst.instruction |= inst.operands[1].reg << 16;
9861}
b05fe5cf 9862
c19d1205
ZW
9863static void
9864do_t_mul (void)
9865{
9866 if (!inst.operands[2].present)
9867 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9868
c19d1205
ZW
9869 /* There is no 32-bit MULS and no 16-bit MUL. */
9870 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9871 {
c19d1205
ZW
9872 inst.instruction = THUMB_OP32 (inst.instruction);
9873 inst.instruction |= inst.operands[0].reg << 8;
9874 inst.instruction |= inst.operands[1].reg << 16;
9875 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9876 }
c19d1205 9877 else
b05fe5cf 9878 {
c19d1205
ZW
9879 constraint (!unified_syntax
9880 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9881 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9882 BAD_HIREG);
b05fe5cf 9883
c19d1205
ZW
9884 inst.instruction = THUMB_OP16 (inst.instruction);
9885 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9886
c19d1205
ZW
9887 if (inst.operands[0].reg == inst.operands[1].reg)
9888 inst.instruction |= inst.operands[2].reg << 3;
9889 else if (inst.operands[0].reg == inst.operands[2].reg)
9890 inst.instruction |= inst.operands[1].reg << 3;
9891 else
9892 constraint (1, _("dest must overlap one source register"));
9893 }
9894}
b05fe5cf 9895
c19d1205
ZW
9896static void
9897do_t_mull (void)
9898{
9899 inst.instruction |= inst.operands[0].reg << 12;
9900 inst.instruction |= inst.operands[1].reg << 8;
9901 inst.instruction |= inst.operands[2].reg << 16;
9902 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9903
c19d1205
ZW
9904 if (inst.operands[0].reg == inst.operands[1].reg)
9905 as_tsktsk (_("rdhi and rdlo must be different"));
9906}
b05fe5cf 9907
c19d1205
ZW
9908static void
9909do_t_nop (void)
9910{
9911 if (unified_syntax)
9912 {
9913 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9914 {
c19d1205
ZW
9915 inst.instruction = THUMB_OP32 (inst.instruction);
9916 inst.instruction |= inst.operands[0].imm;
9917 }
9918 else
9919 {
9920 inst.instruction = THUMB_OP16 (inst.instruction);
9921 inst.instruction |= inst.operands[0].imm << 4;
9922 }
9923 }
9924 else
9925 {
9926 constraint (inst.operands[0].present,
9927 _("Thumb does not support NOP with hints"));
9928 inst.instruction = 0x46c0;
9929 }
9930}
b05fe5cf 9931
c19d1205
ZW
9932static void
9933do_t_neg (void)
9934{
9935 if (unified_syntax)
9936 {
3d388997
PB
9937 bfd_boolean narrow;
9938
9939 if (THUMB_SETS_FLAGS (inst.instruction))
9940 narrow = (current_it_mask == 0);
9941 else
9942 narrow = (current_it_mask != 0);
9943 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9944 narrow = FALSE;
9945 if (inst.size_req == 4)
9946 narrow = FALSE;
9947
9948 if (!narrow)
c19d1205
ZW
9949 {
9950 inst.instruction = THUMB_OP32 (inst.instruction);
9951 inst.instruction |= inst.operands[0].reg << 8;
9952 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9953 }
9954 else
9955 {
c19d1205
ZW
9956 inst.instruction = THUMB_OP16 (inst.instruction);
9957 inst.instruction |= inst.operands[0].reg;
9958 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9959 }
9960 }
9961 else
9962 {
c19d1205
ZW
9963 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9964 BAD_HIREG);
9965 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9966
9967 inst.instruction = THUMB_OP16 (inst.instruction);
9968 inst.instruction |= inst.operands[0].reg;
9969 inst.instruction |= inst.operands[1].reg << 3;
9970 }
9971}
9972
9973static void
9974do_t_pkhbt (void)
9975{
9976 inst.instruction |= inst.operands[0].reg << 8;
9977 inst.instruction |= inst.operands[1].reg << 16;
9978 inst.instruction |= inst.operands[2].reg;
9979 if (inst.operands[3].present)
9980 {
9981 unsigned int val = inst.reloc.exp.X_add_number;
9982 constraint (inst.reloc.exp.X_op != O_constant,
9983 _("expression too complex"));
9984 inst.instruction |= (val & 0x1c) << 10;
9985 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9986 }
c19d1205 9987}
b05fe5cf 9988
c19d1205
ZW
9989static void
9990do_t_pkhtb (void)
9991{
9992 if (!inst.operands[3].present)
9993 inst.instruction &= ~0x00000020;
9994 do_t_pkhbt ();
b05fe5cf
ZW
9995}
9996
c19d1205
ZW
9997static void
9998do_t_pld (void)
9999{
10000 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10001}
b05fe5cf 10002
c19d1205
ZW
10003static void
10004do_t_push_pop (void)
b99bd4ef 10005{
e9f89963 10006 unsigned mask;
5f4273c7 10007
c19d1205
ZW
10008 constraint (inst.operands[0].writeback,
10009 _("push/pop do not support {reglist}^"));
10010 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10011 _("expression too complex"));
b99bd4ef 10012
e9f89963
PB
10013 mask = inst.operands[0].imm;
10014 if ((mask & ~0xff) == 0)
3c707909 10015 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10016 else if ((inst.instruction == T_MNEM_push
e9f89963 10017 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10018 || (inst.instruction == T_MNEM_pop
e9f89963 10019 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10020 {
c19d1205
ZW
10021 inst.instruction = THUMB_OP16 (inst.instruction);
10022 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10023 inst.instruction |= mask & 0xff;
c19d1205
ZW
10024 }
10025 else if (unified_syntax)
10026 {
3c707909 10027 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10028 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10029 }
10030 else
10031 {
10032 inst.error = _("invalid register list to push/pop instruction");
10033 return;
10034 }
c19d1205 10035}
b99bd4ef 10036
c19d1205
ZW
10037static void
10038do_t_rbit (void)
10039{
10040 inst.instruction |= inst.operands[0].reg << 8;
10041 inst.instruction |= inst.operands[1].reg << 16;
10042}
b99bd4ef 10043
c19d1205
ZW
10044static void
10045do_t_rev (void)
10046{
10047 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10048 && inst.size_req != 4)
10049 {
10050 inst.instruction = THUMB_OP16 (inst.instruction);
10051 inst.instruction |= inst.operands[0].reg;
10052 inst.instruction |= inst.operands[1].reg << 3;
10053 }
10054 else if (unified_syntax)
10055 {
10056 inst.instruction = THUMB_OP32 (inst.instruction);
10057 inst.instruction |= inst.operands[0].reg << 8;
10058 inst.instruction |= inst.operands[1].reg << 16;
10059 inst.instruction |= inst.operands[1].reg;
10060 }
10061 else
10062 inst.error = BAD_HIREG;
10063}
b99bd4ef 10064
c19d1205
ZW
10065static void
10066do_t_rsb (void)
10067{
10068 int Rd, Rs;
b99bd4ef 10069
c19d1205
ZW
10070 Rd = inst.operands[0].reg;
10071 Rs = (inst.operands[1].present
10072 ? inst.operands[1].reg /* Rd, Rs, foo */
10073 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10074
c19d1205
ZW
10075 inst.instruction |= Rd << 8;
10076 inst.instruction |= Rs << 16;
10077 if (!inst.operands[2].isreg)
10078 {
026d3abb
PB
10079 bfd_boolean narrow;
10080
10081 if ((inst.instruction & 0x00100000) != 0)
10082 narrow = (current_it_mask == 0);
10083 else
10084 narrow = (current_it_mask != 0);
10085
10086 if (Rd > 7 || Rs > 7)
10087 narrow = FALSE;
10088
10089 if (inst.size_req == 4 || !unified_syntax)
10090 narrow = FALSE;
10091
10092 if (inst.reloc.exp.X_op != O_constant
10093 || inst.reloc.exp.X_add_number != 0)
10094 narrow = FALSE;
10095
10096 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10097 relaxation, but it doesn't seem worth the hassle. */
10098 if (narrow)
10099 {
10100 inst.reloc.type = BFD_RELOC_UNUSED;
10101 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10102 inst.instruction |= Rs << 3;
10103 inst.instruction |= Rd;
10104 }
10105 else
10106 {
10107 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10108 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10109 }
c19d1205
ZW
10110 }
10111 else
10112 encode_thumb32_shifted_operand (2);
10113}
b99bd4ef 10114
c19d1205
ZW
10115static void
10116do_t_setend (void)
10117{
dfa9f0d5 10118 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10119 if (inst.operands[0].imm)
10120 inst.instruction |= 0x8;
10121}
b99bd4ef 10122
c19d1205
ZW
10123static void
10124do_t_shift (void)
10125{
10126 if (!inst.operands[1].present)
10127 inst.operands[1].reg = inst.operands[0].reg;
10128
10129 if (unified_syntax)
10130 {
3d388997
PB
10131 bfd_boolean narrow;
10132 int shift_kind;
10133
10134 switch (inst.instruction)
10135 {
10136 case T_MNEM_asr:
10137 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10138 case T_MNEM_lsl:
10139 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10140 case T_MNEM_lsr:
10141 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10142 case T_MNEM_ror:
10143 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10144 default: abort ();
10145 }
10146
10147 if (THUMB_SETS_FLAGS (inst.instruction))
10148 narrow = (current_it_mask == 0);
10149 else
10150 narrow = (current_it_mask != 0);
10151 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10152 narrow = FALSE;
10153 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10154 narrow = FALSE;
10155 if (inst.operands[2].isreg
10156 && (inst.operands[1].reg != inst.operands[0].reg
10157 || inst.operands[2].reg > 7))
10158 narrow = FALSE;
10159 if (inst.size_req == 4)
10160 narrow = FALSE;
10161
10162 if (!narrow)
c19d1205
ZW
10163 {
10164 if (inst.operands[2].isreg)
b99bd4ef 10165 {
c19d1205
ZW
10166 inst.instruction = THUMB_OP32 (inst.instruction);
10167 inst.instruction |= inst.operands[0].reg << 8;
10168 inst.instruction |= inst.operands[1].reg << 16;
10169 inst.instruction |= inst.operands[2].reg;
10170 }
10171 else
10172 {
10173 inst.operands[1].shifted = 1;
3d388997 10174 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10175 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10176 ? T_MNEM_movs : T_MNEM_mov);
10177 inst.instruction |= inst.operands[0].reg << 8;
10178 encode_thumb32_shifted_operand (1);
10179 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10180 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10181 }
10182 }
10183 else
10184 {
c19d1205 10185 if (inst.operands[2].isreg)
b99bd4ef 10186 {
3d388997 10187 switch (shift_kind)
b99bd4ef 10188 {
3d388997
PB
10189 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10190 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10191 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10192 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10193 default: abort ();
b99bd4ef 10194 }
5f4273c7 10195
c19d1205
ZW
10196 inst.instruction |= inst.operands[0].reg;
10197 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10198 }
10199 else
10200 {
3d388997 10201 switch (shift_kind)
b99bd4ef 10202 {
3d388997
PB
10203 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10204 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10205 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10206 default: abort ();
b99bd4ef 10207 }
c19d1205
ZW
10208 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10209 inst.instruction |= inst.operands[0].reg;
10210 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10211 }
10212 }
c19d1205
ZW
10213 }
10214 else
10215 {
10216 constraint (inst.operands[0].reg > 7
10217 || inst.operands[1].reg > 7, BAD_HIREG);
10218 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10219
c19d1205
ZW
10220 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10221 {
10222 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10223 constraint (inst.operands[0].reg != inst.operands[1].reg,
10224 _("source1 and dest must be same register"));
b99bd4ef 10225
c19d1205
ZW
10226 switch (inst.instruction)
10227 {
10228 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10229 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10230 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10231 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10232 default: abort ();
10233 }
5f4273c7 10234
c19d1205
ZW
10235 inst.instruction |= inst.operands[0].reg;
10236 inst.instruction |= inst.operands[2].reg << 3;
10237 }
10238 else
b99bd4ef 10239 {
c19d1205
ZW
10240 switch (inst.instruction)
10241 {
10242 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10243 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10244 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10245 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10246 default: abort ();
10247 }
10248 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10249 inst.instruction |= inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10251 }
10252 }
b99bd4ef
NC
10253}
10254
10255static void
c19d1205 10256do_t_simd (void)
b99bd4ef 10257{
c19d1205
ZW
10258 inst.instruction |= inst.operands[0].reg << 8;
10259 inst.instruction |= inst.operands[1].reg << 16;
10260 inst.instruction |= inst.operands[2].reg;
10261}
b99bd4ef 10262
c19d1205 10263static void
3eb17e6b 10264do_t_smc (void)
c19d1205
ZW
10265{
10266 unsigned int value = inst.reloc.exp.X_add_number;
10267 constraint (inst.reloc.exp.X_op != O_constant,
10268 _("expression too complex"));
10269 inst.reloc.type = BFD_RELOC_UNUSED;
10270 inst.instruction |= (value & 0xf000) >> 12;
10271 inst.instruction |= (value & 0x0ff0);
10272 inst.instruction |= (value & 0x000f) << 16;
10273}
b99bd4ef 10274
c19d1205
ZW
10275static void
10276do_t_ssat (void)
10277{
10278 inst.instruction |= inst.operands[0].reg << 8;
10279 inst.instruction |= inst.operands[1].imm - 1;
10280 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10281
c19d1205 10282 if (inst.operands[3].present)
b99bd4ef 10283 {
c19d1205
ZW
10284 constraint (inst.reloc.exp.X_op != O_constant,
10285 _("expression too complex"));
b99bd4ef 10286
c19d1205 10287 if (inst.reloc.exp.X_add_number != 0)
6189168b 10288 {
c19d1205
ZW
10289 if (inst.operands[3].shift_kind == SHIFT_ASR)
10290 inst.instruction |= 0x00200000; /* sh bit */
10291 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10292 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10293 }
c19d1205 10294 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10295 }
b99bd4ef
NC
10296}
10297
0dd132b6 10298static void
c19d1205 10299do_t_ssat16 (void)
0dd132b6 10300{
c19d1205
ZW
10301 inst.instruction |= inst.operands[0].reg << 8;
10302 inst.instruction |= inst.operands[1].imm - 1;
10303 inst.instruction |= inst.operands[2].reg << 16;
10304}
0dd132b6 10305
c19d1205
ZW
10306static void
10307do_t_strex (void)
10308{
10309 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10310 || inst.operands[2].postind || inst.operands[2].writeback
10311 || inst.operands[2].immisreg || inst.operands[2].shifted
10312 || inst.operands[2].negative,
01cfc07f 10313 BAD_ADDR_MODE);
0dd132b6 10314
c19d1205
ZW
10315 inst.instruction |= inst.operands[0].reg << 8;
10316 inst.instruction |= inst.operands[1].reg << 12;
10317 inst.instruction |= inst.operands[2].reg << 16;
10318 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10319}
10320
b99bd4ef 10321static void
c19d1205 10322do_t_strexd (void)
b99bd4ef 10323{
c19d1205
ZW
10324 if (!inst.operands[2].present)
10325 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10326
c19d1205
ZW
10327 constraint (inst.operands[0].reg == inst.operands[1].reg
10328 || inst.operands[0].reg == inst.operands[2].reg
10329 || inst.operands[0].reg == inst.operands[3].reg
10330 || inst.operands[1].reg == inst.operands[2].reg,
10331 BAD_OVERLAP);
b99bd4ef 10332
c19d1205
ZW
10333 inst.instruction |= inst.operands[0].reg;
10334 inst.instruction |= inst.operands[1].reg << 12;
10335 inst.instruction |= inst.operands[2].reg << 8;
10336 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10337}
10338
10339static void
c19d1205 10340do_t_sxtah (void)
b99bd4ef 10341{
c19d1205
ZW
10342 inst.instruction |= inst.operands[0].reg << 8;
10343 inst.instruction |= inst.operands[1].reg << 16;
10344 inst.instruction |= inst.operands[2].reg;
10345 inst.instruction |= inst.operands[3].imm << 4;
10346}
b99bd4ef 10347
c19d1205
ZW
10348static void
10349do_t_sxth (void)
10350{
10351 if (inst.instruction <= 0xffff && inst.size_req != 4
10352 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10353 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10354 {
c19d1205
ZW
10355 inst.instruction = THUMB_OP16 (inst.instruction);
10356 inst.instruction |= inst.operands[0].reg;
10357 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10358 }
c19d1205 10359 else if (unified_syntax)
b99bd4ef 10360 {
c19d1205
ZW
10361 if (inst.instruction <= 0xffff)
10362 inst.instruction = THUMB_OP32 (inst.instruction);
10363 inst.instruction |= inst.operands[0].reg << 8;
10364 inst.instruction |= inst.operands[1].reg;
10365 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10366 }
c19d1205 10367 else
b99bd4ef 10368 {
c19d1205
ZW
10369 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10370 _("Thumb encoding does not support rotation"));
10371 constraint (1, BAD_HIREG);
b99bd4ef 10372 }
c19d1205 10373}
b99bd4ef 10374
c19d1205
ZW
10375static void
10376do_t_swi (void)
10377{
10378 inst.reloc.type = BFD_RELOC_ARM_SWI;
10379}
b99bd4ef 10380
92e90b6e
PB
10381static void
10382do_t_tb (void)
10383{
10384 int half;
10385
10386 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10387 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10388 constraint (inst.operands[0].immisreg,
10389 _("instruction requires register index"));
92e90b6e
PB
10390 constraint (inst.operands[0].imm == 15,
10391 _("PC is not a valid index register"));
10392 constraint (!half && inst.operands[0].shifted,
10393 _("instruction does not allow shifted index"));
92e90b6e
PB
10394 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10395}
10396
c19d1205
ZW
10397static void
10398do_t_usat (void)
10399{
10400 inst.instruction |= inst.operands[0].reg << 8;
10401 inst.instruction |= inst.operands[1].imm;
10402 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10403
c19d1205 10404 if (inst.operands[3].present)
b99bd4ef 10405 {
c19d1205
ZW
10406 constraint (inst.reloc.exp.X_op != O_constant,
10407 _("expression too complex"));
10408 if (inst.reloc.exp.X_add_number != 0)
10409 {
10410 if (inst.operands[3].shift_kind == SHIFT_ASR)
10411 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10412
c19d1205
ZW
10413 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10414 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10415 }
10416 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10417 }
b99bd4ef
NC
10418}
10419
10420static void
c19d1205 10421do_t_usat16 (void)
b99bd4ef 10422{
c19d1205
ZW
10423 inst.instruction |= inst.operands[0].reg << 8;
10424 inst.instruction |= inst.operands[1].imm;
10425 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10426}
c19d1205 10427
5287ad62 10428/* Neon instruction encoder helpers. */
5f4273c7 10429
5287ad62 10430/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10431
5287ad62
JB
10432/* An "invalid" code for the following tables. */
10433#define N_INV -1u
10434
10435struct neon_tab_entry
b99bd4ef 10436{
5287ad62
JB
10437 unsigned integer;
10438 unsigned float_or_poly;
10439 unsigned scalar_or_imm;
10440};
5f4273c7 10441
5287ad62
JB
10442/* Map overloaded Neon opcodes to their respective encodings. */
10443#define NEON_ENC_TAB \
10444 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10445 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10446 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10447 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10448 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10449 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10450 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10451 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10452 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10453 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10454 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10455 /* Register variants of the following two instructions are encoded as
10456 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10457 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10458 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10459 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10460 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10461 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10462 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10463 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10464 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10465 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10466 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10467 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10468 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10469 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10470 X(vshl, 0x0000400, N_INV, 0x0800510), \
10471 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10472 X(vand, 0x0000110, N_INV, 0x0800030), \
10473 X(vbic, 0x0100110, N_INV, 0x0800030), \
10474 X(veor, 0x1000110, N_INV, N_INV), \
10475 X(vorn, 0x0300110, N_INV, 0x0800010), \
10476 X(vorr, 0x0200110, N_INV, 0x0800010), \
10477 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10478 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10479 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10480 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10481 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10482 X(vst1, 0x0000000, 0x0800000, N_INV), \
10483 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10484 X(vst2, 0x0000100, 0x0800100, N_INV), \
10485 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10486 X(vst3, 0x0000200, 0x0800200, N_INV), \
10487 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10488 X(vst4, 0x0000300, 0x0800300, N_INV), \
10489 X(vmovn, 0x1b20200, N_INV, N_INV), \
10490 X(vtrn, 0x1b20080, N_INV, N_INV), \
10491 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10492 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10493 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10494 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10495 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10496 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10497 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10498 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10499 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10500
10501enum neon_opc
10502{
10503#define X(OPC,I,F,S) N_MNEM_##OPC
10504NEON_ENC_TAB
10505#undef X
10506};
b99bd4ef 10507
5287ad62
JB
10508static const struct neon_tab_entry neon_enc_tab[] =
10509{
10510#define X(OPC,I,F,S) { (I), (F), (S) }
10511NEON_ENC_TAB
10512#undef X
10513};
b99bd4ef 10514
5287ad62
JB
10515#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10516#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10517#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10518#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10519#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10520#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10521#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10522#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10523#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10524#define NEON_ENC_SINGLE(X) \
10525 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10526#define NEON_ENC_DOUBLE(X) \
10527 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10528
037e8744
JB
10529/* Define shapes for instruction operands. The following mnemonic characters
10530 are used in this table:
5287ad62 10531
037e8744 10532 F - VFP S<n> register
5287ad62
JB
10533 D - Neon D<n> register
10534 Q - Neon Q<n> register
10535 I - Immediate
10536 S - Scalar
10537 R - ARM register
10538 L - D<n> register list
5f4273c7 10539
037e8744
JB
10540 This table is used to generate various data:
10541 - enumerations of the form NS_DDR to be used as arguments to
10542 neon_select_shape.
10543 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10544 - a table used to drive neon_select_shape. */
b99bd4ef 10545
037e8744
JB
10546#define NEON_SHAPE_DEF \
10547 X(3, (D, D, D), DOUBLE), \
10548 X(3, (Q, Q, Q), QUAD), \
10549 X(3, (D, D, I), DOUBLE), \
10550 X(3, (Q, Q, I), QUAD), \
10551 X(3, (D, D, S), DOUBLE), \
10552 X(3, (Q, Q, S), QUAD), \
10553 X(2, (D, D), DOUBLE), \
10554 X(2, (Q, Q), QUAD), \
10555 X(2, (D, S), DOUBLE), \
10556 X(2, (Q, S), QUAD), \
10557 X(2, (D, R), DOUBLE), \
10558 X(2, (Q, R), QUAD), \
10559 X(2, (D, I), DOUBLE), \
10560 X(2, (Q, I), QUAD), \
10561 X(3, (D, L, D), DOUBLE), \
10562 X(2, (D, Q), MIXED), \
10563 X(2, (Q, D), MIXED), \
10564 X(3, (D, Q, I), MIXED), \
10565 X(3, (Q, D, I), MIXED), \
10566 X(3, (Q, D, D), MIXED), \
10567 X(3, (D, Q, Q), MIXED), \
10568 X(3, (Q, Q, D), MIXED), \
10569 X(3, (Q, D, S), MIXED), \
10570 X(3, (D, Q, S), MIXED), \
10571 X(4, (D, D, D, I), DOUBLE), \
10572 X(4, (Q, Q, Q, I), QUAD), \
10573 X(2, (F, F), SINGLE), \
10574 X(3, (F, F, F), SINGLE), \
10575 X(2, (F, I), SINGLE), \
10576 X(2, (F, D), MIXED), \
10577 X(2, (D, F), MIXED), \
10578 X(3, (F, F, I), MIXED), \
10579 X(4, (R, R, F, F), SINGLE), \
10580 X(4, (F, F, R, R), SINGLE), \
10581 X(3, (D, R, R), DOUBLE), \
10582 X(3, (R, R, D), DOUBLE), \
10583 X(2, (S, R), SINGLE), \
10584 X(2, (R, S), SINGLE), \
10585 X(2, (F, R), SINGLE), \
10586 X(2, (R, F), SINGLE)
10587
10588#define S2(A,B) NS_##A##B
10589#define S3(A,B,C) NS_##A##B##C
10590#define S4(A,B,C,D) NS_##A##B##C##D
10591
10592#define X(N, L, C) S##N L
10593
5287ad62
JB
10594enum neon_shape
10595{
037e8744
JB
10596 NEON_SHAPE_DEF,
10597 NS_NULL
5287ad62 10598};
b99bd4ef 10599
037e8744
JB
10600#undef X
10601#undef S2
10602#undef S3
10603#undef S4
10604
10605enum neon_shape_class
10606{
10607 SC_SINGLE,
10608 SC_DOUBLE,
10609 SC_QUAD,
10610 SC_MIXED
10611};
10612
10613#define X(N, L, C) SC_##C
10614
10615static enum neon_shape_class neon_shape_class[] =
10616{
10617 NEON_SHAPE_DEF
10618};
10619
10620#undef X
10621
10622enum neon_shape_el
10623{
10624 SE_F,
10625 SE_D,
10626 SE_Q,
10627 SE_I,
10628 SE_S,
10629 SE_R,
10630 SE_L
10631};
10632
10633/* Register widths of above. */
10634static unsigned neon_shape_el_size[] =
10635{
10636 32,
10637 64,
10638 128,
10639 0,
10640 32,
10641 32,
10642 0
10643};
10644
10645struct neon_shape_info
10646{
10647 unsigned els;
10648 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10649};
10650
10651#define S2(A,B) { SE_##A, SE_##B }
10652#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10653#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10654
10655#define X(N, L, C) { N, S##N L }
10656
10657static struct neon_shape_info neon_shape_tab[] =
10658{
10659 NEON_SHAPE_DEF
10660};
10661
10662#undef X
10663#undef S2
10664#undef S3
10665#undef S4
10666
5287ad62
JB
10667/* Bit masks used in type checking given instructions.
10668 'N_EQK' means the type must be the same as (or based on in some way) the key
10669 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10670 set, various other bits can be set as well in order to modify the meaning of
10671 the type constraint. */
10672
10673enum neon_type_mask
10674{
10675 N_S8 = 0x000001,
10676 N_S16 = 0x000002,
10677 N_S32 = 0x000004,
10678 N_S64 = 0x000008,
10679 N_U8 = 0x000010,
10680 N_U16 = 0x000020,
10681 N_U32 = 0x000040,
10682 N_U64 = 0x000080,
10683 N_I8 = 0x000100,
10684 N_I16 = 0x000200,
10685 N_I32 = 0x000400,
10686 N_I64 = 0x000800,
10687 N_8 = 0x001000,
10688 N_16 = 0x002000,
10689 N_32 = 0x004000,
10690 N_64 = 0x008000,
10691 N_P8 = 0x010000,
10692 N_P16 = 0x020000,
10693 N_F32 = 0x040000,
037e8744
JB
10694 N_F64 = 0x080000,
10695 N_KEY = 0x100000, /* key element (main type specifier). */
10696 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10697 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10698 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10699 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10700 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10701 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10702 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10703 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10704 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10705 N_UTYP = 0,
037e8744 10706 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10707};
10708
dcbf9037
JB
10709#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10710
5287ad62
JB
10711#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10712#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10713#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10714#define N_SUF_32 (N_SU_32 | N_F32)
10715#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10716#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10717
10718/* Pass this as the first type argument to neon_check_type to ignore types
10719 altogether. */
10720#define N_IGNORE_TYPE (N_KEY | N_EQK)
10721
037e8744
JB
10722/* Select a "shape" for the current instruction (describing register types or
10723 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10724 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10725 function of operand parsing, so this function doesn't need to be called.
10726 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10727
10728static enum neon_shape
037e8744 10729neon_select_shape (enum neon_shape shape, ...)
5287ad62 10730{
037e8744
JB
10731 va_list ap;
10732 enum neon_shape first_shape = shape;
5287ad62
JB
10733
10734 /* Fix missing optional operands. FIXME: we don't know at this point how
10735 many arguments we should have, so this makes the assumption that we have
10736 > 1. This is true of all current Neon opcodes, I think, but may not be
10737 true in the future. */
10738 if (!inst.operands[1].present)
10739 inst.operands[1] = inst.operands[0];
10740
037e8744 10741 va_start (ap, shape);
5f4273c7 10742
037e8744
JB
10743 for (; shape != NS_NULL; shape = va_arg (ap, int))
10744 {
10745 unsigned j;
10746 int matches = 1;
10747
10748 for (j = 0; j < neon_shape_tab[shape].els; j++)
10749 {
10750 if (!inst.operands[j].present)
10751 {
10752 matches = 0;
10753 break;
10754 }
10755
10756 switch (neon_shape_tab[shape].el[j])
10757 {
10758 case SE_F:
10759 if (!(inst.operands[j].isreg
10760 && inst.operands[j].isvec
10761 && inst.operands[j].issingle
10762 && !inst.operands[j].isquad))
10763 matches = 0;
10764 break;
10765
10766 case SE_D:
10767 if (!(inst.operands[j].isreg
10768 && inst.operands[j].isvec
10769 && !inst.operands[j].isquad
10770 && !inst.operands[j].issingle))
10771 matches = 0;
10772 break;
10773
10774 case SE_R:
10775 if (!(inst.operands[j].isreg
10776 && !inst.operands[j].isvec))
10777 matches = 0;
10778 break;
10779
10780 case SE_Q:
10781 if (!(inst.operands[j].isreg
10782 && inst.operands[j].isvec
10783 && inst.operands[j].isquad
10784 && !inst.operands[j].issingle))
10785 matches = 0;
10786 break;
10787
10788 case SE_I:
10789 if (!(!inst.operands[j].isreg
10790 && !inst.operands[j].isscalar))
10791 matches = 0;
10792 break;
10793
10794 case SE_S:
10795 if (!(!inst.operands[j].isreg
10796 && inst.operands[j].isscalar))
10797 matches = 0;
10798 break;
10799
10800 case SE_L:
10801 break;
10802 }
10803 }
10804 if (matches)
5287ad62 10805 break;
037e8744 10806 }
5f4273c7 10807
037e8744 10808 va_end (ap);
5287ad62 10809
037e8744
JB
10810 if (shape == NS_NULL && first_shape != NS_NULL)
10811 first_error (_("invalid instruction shape"));
5287ad62 10812
037e8744
JB
10813 return shape;
10814}
5287ad62 10815
037e8744
JB
10816/* True if SHAPE is predominantly a quadword operation (most of the time, this
10817 means the Q bit should be set). */
10818
10819static int
10820neon_quad (enum neon_shape shape)
10821{
10822 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10823}
037e8744 10824
5287ad62
JB
10825static void
10826neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10827 unsigned *g_size)
10828{
10829 /* Allow modification to be made to types which are constrained to be
10830 based on the key element, based on bits set alongside N_EQK. */
10831 if ((typebits & N_EQK) != 0)
10832 {
10833 if ((typebits & N_HLF) != 0)
10834 *g_size /= 2;
10835 else if ((typebits & N_DBL) != 0)
10836 *g_size *= 2;
10837 if ((typebits & N_SGN) != 0)
10838 *g_type = NT_signed;
10839 else if ((typebits & N_UNS) != 0)
10840 *g_type = NT_unsigned;
10841 else if ((typebits & N_INT) != 0)
10842 *g_type = NT_integer;
10843 else if ((typebits & N_FLT) != 0)
10844 *g_type = NT_float;
dcbf9037
JB
10845 else if ((typebits & N_SIZ) != 0)
10846 *g_type = NT_untyped;
5287ad62
JB
10847 }
10848}
5f4273c7 10849
5287ad62
JB
10850/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10851 operand type, i.e. the single type specified in a Neon instruction when it
10852 is the only one given. */
10853
10854static struct neon_type_el
10855neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10856{
10857 struct neon_type_el dest = *key;
5f4273c7 10858
5287ad62 10859 assert ((thisarg & N_EQK) != 0);
5f4273c7 10860
5287ad62
JB
10861 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10862
10863 return dest;
10864}
10865
10866/* Convert Neon type and size into compact bitmask representation. */
10867
10868static enum neon_type_mask
10869type_chk_of_el_type (enum neon_el_type type, unsigned size)
10870{
10871 switch (type)
10872 {
10873 case NT_untyped:
10874 switch (size)
10875 {
10876 case 8: return N_8;
10877 case 16: return N_16;
10878 case 32: return N_32;
10879 case 64: return N_64;
10880 default: ;
10881 }
10882 break;
10883
10884 case NT_integer:
10885 switch (size)
10886 {
10887 case 8: return N_I8;
10888 case 16: return N_I16;
10889 case 32: return N_I32;
10890 case 64: return N_I64;
10891 default: ;
10892 }
10893 break;
10894
10895 case NT_float:
037e8744
JB
10896 switch (size)
10897 {
10898 case 32: return N_F32;
10899 case 64: return N_F64;
10900 default: ;
10901 }
5287ad62
JB
10902 break;
10903
10904 case NT_poly:
10905 switch (size)
10906 {
10907 case 8: return N_P8;
10908 case 16: return N_P16;
10909 default: ;
10910 }
10911 break;
10912
10913 case NT_signed:
10914 switch (size)
10915 {
10916 case 8: return N_S8;
10917 case 16: return N_S16;
10918 case 32: return N_S32;
10919 case 64: return N_S64;
10920 default: ;
10921 }
10922 break;
10923
10924 case NT_unsigned:
10925 switch (size)
10926 {
10927 case 8: return N_U8;
10928 case 16: return N_U16;
10929 case 32: return N_U32;
10930 case 64: return N_U64;
10931 default: ;
10932 }
10933 break;
10934
10935 default: ;
10936 }
5f4273c7 10937
5287ad62
JB
10938 return N_UTYP;
10939}
10940
10941/* Convert compact Neon bitmask type representation to a type and size. Only
10942 handles the case where a single bit is set in the mask. */
10943
dcbf9037 10944static int
5287ad62
JB
10945el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10946 enum neon_type_mask mask)
10947{
dcbf9037
JB
10948 if ((mask & N_EQK) != 0)
10949 return FAIL;
10950
5287ad62
JB
10951 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10952 *size = 8;
dcbf9037 10953 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10954 *size = 16;
dcbf9037 10955 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10956 *size = 32;
037e8744 10957 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10958 *size = 64;
dcbf9037
JB
10959 else
10960 return FAIL;
10961
5287ad62
JB
10962 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10963 *type = NT_signed;
dcbf9037 10964 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10965 *type = NT_unsigned;
dcbf9037 10966 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10967 *type = NT_integer;
dcbf9037 10968 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10969 *type = NT_untyped;
dcbf9037 10970 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10971 *type = NT_poly;
037e8744 10972 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10973 *type = NT_float;
dcbf9037
JB
10974 else
10975 return FAIL;
5f4273c7 10976
dcbf9037 10977 return SUCCESS;
5287ad62
JB
10978}
10979
10980/* Modify a bitmask of allowed types. This is only needed for type
10981 relaxation. */
10982
10983static unsigned
10984modify_types_allowed (unsigned allowed, unsigned mods)
10985{
10986 unsigned size;
10987 enum neon_el_type type;
10988 unsigned destmask;
10989 int i;
5f4273c7 10990
5287ad62 10991 destmask = 0;
5f4273c7 10992
5287ad62
JB
10993 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10994 {
dcbf9037
JB
10995 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10996 {
10997 neon_modify_type_size (mods, &type, &size);
10998 destmask |= type_chk_of_el_type (type, size);
10999 }
5287ad62 11000 }
5f4273c7 11001
5287ad62
JB
11002 return destmask;
11003}
11004
11005/* Check type and return type classification.
11006 The manual states (paraphrase): If one datatype is given, it indicates the
11007 type given in:
11008 - the second operand, if there is one
11009 - the operand, if there is no second operand
11010 - the result, if there are no operands.
11011 This isn't quite good enough though, so we use a concept of a "key" datatype
11012 which is set on a per-instruction basis, which is the one which matters when
11013 only one data type is written.
11014 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11015 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11016
11017static struct neon_type_el
11018neon_check_type (unsigned els, enum neon_shape ns, ...)
11019{
11020 va_list ap;
11021 unsigned i, pass, key_el = 0;
11022 unsigned types[NEON_MAX_TYPE_ELS];
11023 enum neon_el_type k_type = NT_invtype;
11024 unsigned k_size = -1u;
11025 struct neon_type_el badtype = {NT_invtype, -1};
11026 unsigned key_allowed = 0;
11027
11028 /* Optional registers in Neon instructions are always (not) in operand 1.
11029 Fill in the missing operand here, if it was omitted. */
11030 if (els > 1 && !inst.operands[1].present)
11031 inst.operands[1] = inst.operands[0];
11032
11033 /* Suck up all the varargs. */
11034 va_start (ap, ns);
11035 for (i = 0; i < els; i++)
11036 {
11037 unsigned thisarg = va_arg (ap, unsigned);
11038 if (thisarg == N_IGNORE_TYPE)
11039 {
11040 va_end (ap);
11041 return badtype;
11042 }
11043 types[i] = thisarg;
11044 if ((thisarg & N_KEY) != 0)
11045 key_el = i;
11046 }
11047 va_end (ap);
11048
dcbf9037
JB
11049 if (inst.vectype.elems > 0)
11050 for (i = 0; i < els; i++)
11051 if (inst.operands[i].vectype.type != NT_invtype)
11052 {
11053 first_error (_("types specified in both the mnemonic and operands"));
11054 return badtype;
11055 }
11056
5287ad62
JB
11057 /* Duplicate inst.vectype elements here as necessary.
11058 FIXME: No idea if this is exactly the same as the ARM assembler,
11059 particularly when an insn takes one register and one non-register
11060 operand. */
11061 if (inst.vectype.elems == 1 && els > 1)
11062 {
11063 unsigned j;
11064 inst.vectype.elems = els;
11065 inst.vectype.el[key_el] = inst.vectype.el[0];
11066 for (j = 0; j < els; j++)
dcbf9037
JB
11067 if (j != key_el)
11068 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11069 types[j]);
11070 }
11071 else if (inst.vectype.elems == 0 && els > 0)
11072 {
11073 unsigned j;
11074 /* No types were given after the mnemonic, so look for types specified
11075 after each operand. We allow some flexibility here; as long as the
11076 "key" operand has a type, we can infer the others. */
11077 for (j = 0; j < els; j++)
11078 if (inst.operands[j].vectype.type != NT_invtype)
11079 inst.vectype.el[j] = inst.operands[j].vectype;
11080
11081 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11082 {
dcbf9037
JB
11083 for (j = 0; j < els; j++)
11084 if (inst.operands[j].vectype.type == NT_invtype)
11085 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11086 types[j]);
11087 }
11088 else
11089 {
11090 first_error (_("operand types can't be inferred"));
11091 return badtype;
5287ad62
JB
11092 }
11093 }
11094 else if (inst.vectype.elems != els)
11095 {
dcbf9037 11096 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11097 return badtype;
11098 }
11099
11100 for (pass = 0; pass < 2; pass++)
11101 {
11102 for (i = 0; i < els; i++)
11103 {
11104 unsigned thisarg = types[i];
11105 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11106 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11107 enum neon_el_type g_type = inst.vectype.el[i].type;
11108 unsigned g_size = inst.vectype.el[i].size;
11109
11110 /* Decay more-specific signed & unsigned types to sign-insensitive
11111 integer types if sign-specific variants are unavailable. */
11112 if ((g_type == NT_signed || g_type == NT_unsigned)
11113 && (types_allowed & N_SU_ALL) == 0)
11114 g_type = NT_integer;
11115
11116 /* If only untyped args are allowed, decay any more specific types to
11117 them. Some instructions only care about signs for some element
11118 sizes, so handle that properly. */
11119 if ((g_size == 8 && (types_allowed & N_8) != 0)
11120 || (g_size == 16 && (types_allowed & N_16) != 0)
11121 || (g_size == 32 && (types_allowed & N_32) != 0)
11122 || (g_size == 64 && (types_allowed & N_64) != 0))
11123 g_type = NT_untyped;
11124
11125 if (pass == 0)
11126 {
11127 if ((thisarg & N_KEY) != 0)
11128 {
11129 k_type = g_type;
11130 k_size = g_size;
11131 key_allowed = thisarg & ~N_KEY;
11132 }
11133 }
11134 else
11135 {
037e8744
JB
11136 if ((thisarg & N_VFP) != 0)
11137 {
11138 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11139 unsigned regwidth = neon_shape_el_size[regshape], match;
11140
11141 /* In VFP mode, operands must match register widths. If we
11142 have a key operand, use its width, else use the width of
11143 the current operand. */
11144 if (k_size != -1u)
11145 match = k_size;
11146 else
11147 match = g_size;
11148
11149 if (regwidth != match)
11150 {
11151 first_error (_("operand size must match register width"));
11152 return badtype;
11153 }
11154 }
5f4273c7 11155
5287ad62
JB
11156 if ((thisarg & N_EQK) == 0)
11157 {
11158 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11159
11160 if ((given_type & types_allowed) == 0)
11161 {
dcbf9037 11162 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11163 return badtype;
11164 }
11165 }
11166 else
11167 {
11168 enum neon_el_type mod_k_type = k_type;
11169 unsigned mod_k_size = k_size;
11170 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11171 if (g_type != mod_k_type || g_size != mod_k_size)
11172 {
dcbf9037 11173 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11174 return badtype;
11175 }
11176 }
11177 }
11178 }
11179 }
11180
11181 return inst.vectype.el[key_el];
11182}
11183
037e8744 11184/* Neon-style VFP instruction forwarding. */
5287ad62 11185
037e8744
JB
11186/* Thumb VFP instructions have 0xE in the condition field. */
11187
11188static void
11189do_vfp_cond_or_thumb (void)
5287ad62
JB
11190{
11191 if (thumb_mode)
037e8744 11192 inst.instruction |= 0xe0000000;
5287ad62 11193 else
037e8744 11194 inst.instruction |= inst.cond << 28;
5287ad62
JB
11195}
11196
037e8744
JB
11197/* Look up and encode a simple mnemonic, for use as a helper function for the
11198 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11199 etc. It is assumed that operand parsing has already been done, and that the
11200 operands are in the form expected by the given opcode (this isn't necessarily
11201 the same as the form in which they were parsed, hence some massaging must
11202 take place before this function is called).
11203 Checks current arch version against that in the looked-up opcode. */
5287ad62 11204
037e8744
JB
11205static void
11206do_vfp_nsyn_opcode (const char *opname)
5287ad62 11207{
037e8744 11208 const struct asm_opcode *opcode;
5f4273c7 11209
037e8744 11210 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11211
037e8744
JB
11212 if (!opcode)
11213 abort ();
5287ad62 11214
037e8744
JB
11215 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11216 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11217 _(BAD_FPU));
5287ad62 11218
037e8744
JB
11219 if (thumb_mode)
11220 {
11221 inst.instruction = opcode->tvalue;
11222 opcode->tencode ();
11223 }
11224 else
11225 {
11226 inst.instruction = (inst.cond << 28) | opcode->avalue;
11227 opcode->aencode ();
11228 }
11229}
5287ad62
JB
11230
11231static void
037e8744 11232do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11233{
037e8744
JB
11234 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11235
11236 if (rs == NS_FFF)
11237 {
11238 if (is_add)
11239 do_vfp_nsyn_opcode ("fadds");
11240 else
11241 do_vfp_nsyn_opcode ("fsubs");
11242 }
11243 else
11244 {
11245 if (is_add)
11246 do_vfp_nsyn_opcode ("faddd");
11247 else
11248 do_vfp_nsyn_opcode ("fsubd");
11249 }
11250}
11251
11252/* Check operand types to see if this is a VFP instruction, and if so call
11253 PFN (). */
11254
11255static int
11256try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11257{
11258 enum neon_shape rs;
11259 struct neon_type_el et;
11260
11261 switch (args)
11262 {
11263 case 2:
11264 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11265 et = neon_check_type (2, rs,
11266 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11267 break;
5f4273c7 11268
037e8744
JB
11269 case 3:
11270 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11271 et = neon_check_type (3, rs,
11272 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11273 break;
11274
11275 default:
11276 abort ();
11277 }
11278
11279 if (et.type != NT_invtype)
11280 {
11281 pfn (rs);
11282 return SUCCESS;
11283 }
11284 else
11285 inst.error = NULL;
11286
11287 return FAIL;
11288}
11289
11290static void
11291do_vfp_nsyn_mla_mls (enum neon_shape rs)
11292{
11293 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11294
037e8744
JB
11295 if (rs == NS_FFF)
11296 {
11297 if (is_mla)
11298 do_vfp_nsyn_opcode ("fmacs");
11299 else
11300 do_vfp_nsyn_opcode ("fmscs");
11301 }
11302 else
11303 {
11304 if (is_mla)
11305 do_vfp_nsyn_opcode ("fmacd");
11306 else
11307 do_vfp_nsyn_opcode ("fmscd");
11308 }
11309}
11310
11311static void
11312do_vfp_nsyn_mul (enum neon_shape rs)
11313{
11314 if (rs == NS_FFF)
11315 do_vfp_nsyn_opcode ("fmuls");
11316 else
11317 do_vfp_nsyn_opcode ("fmuld");
11318}
11319
11320static void
11321do_vfp_nsyn_abs_neg (enum neon_shape rs)
11322{
11323 int is_neg = (inst.instruction & 0x80) != 0;
11324 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11325
11326 if (rs == NS_FF)
11327 {
11328 if (is_neg)
11329 do_vfp_nsyn_opcode ("fnegs");
11330 else
11331 do_vfp_nsyn_opcode ("fabss");
11332 }
11333 else
11334 {
11335 if (is_neg)
11336 do_vfp_nsyn_opcode ("fnegd");
11337 else
11338 do_vfp_nsyn_opcode ("fabsd");
11339 }
11340}
11341
11342/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11343 insns belong to Neon, and are handled elsewhere. */
11344
11345static void
11346do_vfp_nsyn_ldm_stm (int is_dbmode)
11347{
11348 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11349 if (is_ldm)
11350 {
11351 if (is_dbmode)
11352 do_vfp_nsyn_opcode ("fldmdbs");
11353 else
11354 do_vfp_nsyn_opcode ("fldmias");
11355 }
11356 else
11357 {
11358 if (is_dbmode)
11359 do_vfp_nsyn_opcode ("fstmdbs");
11360 else
11361 do_vfp_nsyn_opcode ("fstmias");
11362 }
11363}
11364
037e8744
JB
11365static void
11366do_vfp_nsyn_sqrt (void)
11367{
11368 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11369 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11370
037e8744
JB
11371 if (rs == NS_FF)
11372 do_vfp_nsyn_opcode ("fsqrts");
11373 else
11374 do_vfp_nsyn_opcode ("fsqrtd");
11375}
11376
11377static void
11378do_vfp_nsyn_div (void)
11379{
11380 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11381 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11382 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11383
037e8744
JB
11384 if (rs == NS_FFF)
11385 do_vfp_nsyn_opcode ("fdivs");
11386 else
11387 do_vfp_nsyn_opcode ("fdivd");
11388}
11389
11390static void
11391do_vfp_nsyn_nmul (void)
11392{
11393 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11394 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11395 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11396
037e8744
JB
11397 if (rs == NS_FFF)
11398 {
11399 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11400 do_vfp_sp_dyadic ();
11401 }
11402 else
11403 {
11404 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11405 do_vfp_dp_rd_rn_rm ();
11406 }
11407 do_vfp_cond_or_thumb ();
11408}
11409
11410static void
11411do_vfp_nsyn_cmp (void)
11412{
11413 if (inst.operands[1].isreg)
11414 {
11415 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11416 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11417
037e8744
JB
11418 if (rs == NS_FF)
11419 {
11420 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11421 do_vfp_sp_monadic ();
11422 }
11423 else
11424 {
11425 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11426 do_vfp_dp_rd_rm ();
11427 }
11428 }
11429 else
11430 {
11431 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11432 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11433
11434 switch (inst.instruction & 0x0fffffff)
11435 {
11436 case N_MNEM_vcmp:
11437 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11438 break;
11439 case N_MNEM_vcmpe:
11440 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11441 break;
11442 default:
11443 abort ();
11444 }
5f4273c7 11445
037e8744
JB
11446 if (rs == NS_FI)
11447 {
11448 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11449 do_vfp_sp_compare_z ();
11450 }
11451 else
11452 {
11453 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11454 do_vfp_dp_rd ();
11455 }
11456 }
11457 do_vfp_cond_or_thumb ();
11458}
11459
11460static void
11461nsyn_insert_sp (void)
11462{
11463 inst.operands[1] = inst.operands[0];
11464 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11465 inst.operands[0].reg = 13;
11466 inst.operands[0].isreg = 1;
11467 inst.operands[0].writeback = 1;
11468 inst.operands[0].present = 1;
11469}
11470
11471static void
11472do_vfp_nsyn_push (void)
11473{
11474 nsyn_insert_sp ();
11475 if (inst.operands[1].issingle)
11476 do_vfp_nsyn_opcode ("fstmdbs");
11477 else
11478 do_vfp_nsyn_opcode ("fstmdbd");
11479}
11480
11481static void
11482do_vfp_nsyn_pop (void)
11483{
11484 nsyn_insert_sp ();
11485 if (inst.operands[1].issingle)
22b5b651 11486 do_vfp_nsyn_opcode ("fldmias");
037e8744 11487 else
22b5b651 11488 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11489}
11490
11491/* Fix up Neon data-processing instructions, ORing in the correct bits for
11492 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11493
11494static unsigned
11495neon_dp_fixup (unsigned i)
11496{
11497 if (thumb_mode)
11498 {
11499 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11500 if (i & (1 << 24))
11501 i |= 1 << 28;
5f4273c7 11502
037e8744 11503 i &= ~(1 << 24);
5f4273c7 11504
037e8744
JB
11505 i |= 0xef000000;
11506 }
11507 else
11508 i |= 0xf2000000;
5f4273c7 11509
037e8744
JB
11510 return i;
11511}
11512
11513/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11514 (0, 1, 2, 3). */
11515
11516static unsigned
11517neon_logbits (unsigned x)
11518{
11519 return ffs (x) - 4;
11520}
11521
11522#define LOW4(R) ((R) & 0xf)
11523#define HI1(R) (((R) >> 4) & 1)
11524
11525/* Encode insns with bit pattern:
11526
11527 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11528 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11529
037e8744
JB
11530 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11531 different meaning for some instruction. */
11532
11533static void
11534neon_three_same (int isquad, int ubit, int size)
11535{
11536 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11537 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11538 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11539 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11540 inst.instruction |= LOW4 (inst.operands[2].reg);
11541 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11542 inst.instruction |= (isquad != 0) << 6;
11543 inst.instruction |= (ubit != 0) << 24;
11544 if (size != -1)
11545 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11546
037e8744
JB
11547 inst.instruction = neon_dp_fixup (inst.instruction);
11548}
11549
11550/* Encode instructions of the form:
11551
11552 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11553 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11554
11555 Don't write size if SIZE == -1. */
11556
11557static void
11558neon_two_same (int qbit, int ubit, int size)
11559{
11560 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11561 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11562 inst.instruction |= LOW4 (inst.operands[1].reg);
11563 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11564 inst.instruction |= (qbit != 0) << 6;
11565 inst.instruction |= (ubit != 0) << 24;
11566
11567 if (size != -1)
11568 inst.instruction |= neon_logbits (size) << 18;
11569
11570 inst.instruction = neon_dp_fixup (inst.instruction);
11571}
11572
11573/* Neon instruction encoders, in approximate order of appearance. */
11574
11575static void
11576do_neon_dyadic_i_su (void)
11577{
037e8744 11578 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11579 struct neon_type_el et = neon_check_type (3, rs,
11580 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11581 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11582}
11583
11584static void
11585do_neon_dyadic_i64_su (void)
11586{
037e8744 11587 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11588 struct neon_type_el et = neon_check_type (3, rs,
11589 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11590 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11591}
11592
11593static void
11594neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11595 unsigned immbits)
11596{
11597 unsigned size = et.size >> 3;
11598 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11599 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11600 inst.instruction |= LOW4 (inst.operands[1].reg);
11601 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11602 inst.instruction |= (isquad != 0) << 6;
11603 inst.instruction |= immbits << 16;
11604 inst.instruction |= (size >> 3) << 7;
11605 inst.instruction |= (size & 0x7) << 19;
11606 if (write_ubit)
11607 inst.instruction |= (uval != 0) << 24;
11608
11609 inst.instruction = neon_dp_fixup (inst.instruction);
11610}
11611
11612static void
11613do_neon_shl_imm (void)
11614{
11615 if (!inst.operands[2].isreg)
11616 {
037e8744 11617 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11618 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11619 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11620 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11621 }
11622 else
11623 {
037e8744 11624 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11625 struct neon_type_el et = neon_check_type (3, rs,
11626 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11627 unsigned int tmp;
11628
11629 /* VSHL/VQSHL 3-register variants have syntax such as:
11630 vshl.xx Dd, Dm, Dn
11631 whereas other 3-register operations encoded by neon_three_same have
11632 syntax like:
11633 vadd.xx Dd, Dn, Dm
11634 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11635 here. */
11636 tmp = inst.operands[2].reg;
11637 inst.operands[2].reg = inst.operands[1].reg;
11638 inst.operands[1].reg = tmp;
5287ad62 11639 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11640 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11641 }
11642}
11643
11644static void
11645do_neon_qshl_imm (void)
11646{
11647 if (!inst.operands[2].isreg)
11648 {
037e8744 11649 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11650 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11651
5287ad62 11652 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11653 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11654 inst.operands[2].imm);
11655 }
11656 else
11657 {
037e8744 11658 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11659 struct neon_type_el et = neon_check_type (3, rs,
11660 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11661 unsigned int tmp;
11662
11663 /* See note in do_neon_shl_imm. */
11664 tmp = inst.operands[2].reg;
11665 inst.operands[2].reg = inst.operands[1].reg;
11666 inst.operands[1].reg = tmp;
5287ad62 11667 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11668 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11669 }
11670}
11671
627907b7
JB
11672static void
11673do_neon_rshl (void)
11674{
11675 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11676 struct neon_type_el et = neon_check_type (3, rs,
11677 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11678 unsigned int tmp;
11679
11680 tmp = inst.operands[2].reg;
11681 inst.operands[2].reg = inst.operands[1].reg;
11682 inst.operands[1].reg = tmp;
11683 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11684}
11685
5287ad62
JB
11686static int
11687neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11688{
036dc3f7
PB
11689 /* Handle .I8 pseudo-instructions. */
11690 if (size == 8)
5287ad62 11691 {
5287ad62
JB
11692 /* Unfortunately, this will make everything apart from zero out-of-range.
11693 FIXME is this the intended semantics? There doesn't seem much point in
11694 accepting .I8 if so. */
11695 immediate |= immediate << 8;
11696 size = 16;
036dc3f7
PB
11697 }
11698
11699 if (size >= 32)
11700 {
11701 if (immediate == (immediate & 0x000000ff))
11702 {
11703 *immbits = immediate;
11704 return 0x1;
11705 }
11706 else if (immediate == (immediate & 0x0000ff00))
11707 {
11708 *immbits = immediate >> 8;
11709 return 0x3;
11710 }
11711 else if (immediate == (immediate & 0x00ff0000))
11712 {
11713 *immbits = immediate >> 16;
11714 return 0x5;
11715 }
11716 else if (immediate == (immediate & 0xff000000))
11717 {
11718 *immbits = immediate >> 24;
11719 return 0x7;
11720 }
11721 if ((immediate & 0xffff) != (immediate >> 16))
11722 goto bad_immediate;
11723 immediate &= 0xffff;
5287ad62
JB
11724 }
11725
11726 if (immediate == (immediate & 0x000000ff))
11727 {
11728 *immbits = immediate;
036dc3f7 11729 return 0x9;
5287ad62
JB
11730 }
11731 else if (immediate == (immediate & 0x0000ff00))
11732 {
11733 *immbits = immediate >> 8;
036dc3f7 11734 return 0xb;
5287ad62
JB
11735 }
11736
11737 bad_immediate:
dcbf9037 11738 first_error (_("immediate value out of range"));
5287ad62
JB
11739 return FAIL;
11740}
11741
11742/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11743 A, B, C, D. */
11744
11745static int
11746neon_bits_same_in_bytes (unsigned imm)
11747{
11748 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11749 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11750 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11751 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11752}
11753
11754/* For immediate of above form, return 0bABCD. */
11755
11756static unsigned
11757neon_squash_bits (unsigned imm)
11758{
11759 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11760 | ((imm & 0x01000000) >> 21);
11761}
11762
136da414 11763/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11764
11765static unsigned
11766neon_qfloat_bits (unsigned imm)
11767{
136da414 11768 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11769}
11770
11771/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11772 the instruction. *OP is passed as the initial value of the op field, and
11773 may be set to a different value depending on the constant (i.e.
11774 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 11775 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 11776 try smaller element sizes. */
5287ad62
JB
11777
11778static int
c96612cc
JB
11779neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11780 unsigned *immbits, int *op, int size,
11781 enum neon_el_type type)
5287ad62 11782{
c96612cc
JB
11783 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11784 float. */
11785 if (type == NT_float && !float_p)
11786 return FAIL;
11787
136da414
JB
11788 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11789 {
11790 if (size != 32 || *op == 1)
11791 return FAIL;
11792 *immbits = neon_qfloat_bits (immlo);
11793 return 0xf;
11794 }
036dc3f7
PB
11795
11796 if (size == 64)
5287ad62 11797 {
036dc3f7
PB
11798 if (neon_bits_same_in_bytes (immhi)
11799 && neon_bits_same_in_bytes (immlo))
11800 {
11801 if (*op == 1)
11802 return FAIL;
11803 *immbits = (neon_squash_bits (immhi) << 4)
11804 | neon_squash_bits (immlo);
11805 *op = 1;
11806 return 0xe;
11807 }
11808
11809 if (immhi != immlo)
11810 return FAIL;
5287ad62 11811 }
036dc3f7
PB
11812
11813 if (size >= 32)
5287ad62 11814 {
036dc3f7
PB
11815 if (immlo == (immlo & 0x000000ff))
11816 {
11817 *immbits = immlo;
11818 return 0x0;
11819 }
11820 else if (immlo == (immlo & 0x0000ff00))
11821 {
11822 *immbits = immlo >> 8;
11823 return 0x2;
11824 }
11825 else if (immlo == (immlo & 0x00ff0000))
11826 {
11827 *immbits = immlo >> 16;
11828 return 0x4;
11829 }
11830 else if (immlo == (immlo & 0xff000000))
11831 {
11832 *immbits = immlo >> 24;
11833 return 0x6;
11834 }
11835 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11836 {
11837 *immbits = (immlo >> 8) & 0xff;
11838 return 0xc;
11839 }
11840 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11841 {
11842 *immbits = (immlo >> 16) & 0xff;
11843 return 0xd;
11844 }
11845
11846 if ((immlo & 0xffff) != (immlo >> 16))
11847 return FAIL;
11848 immlo &= 0xffff;
5287ad62 11849 }
036dc3f7
PB
11850
11851 if (size >= 16)
5287ad62 11852 {
036dc3f7
PB
11853 if (immlo == (immlo & 0x000000ff))
11854 {
11855 *immbits = immlo;
11856 return 0x8;
11857 }
11858 else if (immlo == (immlo & 0x0000ff00))
11859 {
11860 *immbits = immlo >> 8;
11861 return 0xa;
11862 }
11863
11864 if ((immlo & 0xff) != (immlo >> 8))
11865 return FAIL;
11866 immlo &= 0xff;
5287ad62 11867 }
036dc3f7
PB
11868
11869 if (immlo == (immlo & 0x000000ff))
5287ad62 11870 {
036dc3f7
PB
11871 /* Don't allow MVN with 8-bit immediate. */
11872 if (*op == 1)
11873 return FAIL;
11874 *immbits = immlo;
11875 return 0xe;
5287ad62 11876 }
5287ad62
JB
11877
11878 return FAIL;
11879}
11880
11881/* Write immediate bits [7:0] to the following locations:
11882
11883 |28/24|23 19|18 16|15 4|3 0|
11884 | 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|
11885
11886 This function is used by VMOV/VMVN/VORR/VBIC. */
11887
11888static void
11889neon_write_immbits (unsigned immbits)
11890{
11891 inst.instruction |= immbits & 0xf;
11892 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11893 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11894}
11895
11896/* Invert low-order SIZE bits of XHI:XLO. */
11897
11898static void
11899neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11900{
11901 unsigned immlo = xlo ? *xlo : 0;
11902 unsigned immhi = xhi ? *xhi : 0;
11903
11904 switch (size)
11905 {
11906 case 8:
11907 immlo = (~immlo) & 0xff;
11908 break;
11909
11910 case 16:
11911 immlo = (~immlo) & 0xffff;
11912 break;
11913
11914 case 64:
11915 immhi = (~immhi) & 0xffffffff;
11916 /* fall through. */
11917
11918 case 32:
11919 immlo = (~immlo) & 0xffffffff;
11920 break;
11921
11922 default:
11923 abort ();
11924 }
11925
11926 if (xlo)
11927 *xlo = immlo;
11928
11929 if (xhi)
11930 *xhi = immhi;
11931}
11932
11933static void
11934do_neon_logic (void)
11935{
11936 if (inst.operands[2].present && inst.operands[2].isreg)
11937 {
037e8744 11938 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11939 neon_check_type (3, rs, N_IGNORE_TYPE);
11940 /* U bit and size field were set as part of the bitmask. */
11941 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11942 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11943 }
11944 else
11945 {
037e8744
JB
11946 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11947 struct neon_type_el et = neon_check_type (2, rs,
11948 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11949 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11950 unsigned immbits;
11951 int cmode;
5f4273c7 11952
5287ad62
JB
11953 if (et.type == NT_invtype)
11954 return;
5f4273c7 11955
5287ad62
JB
11956 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11957
036dc3f7
PB
11958 immbits = inst.operands[1].imm;
11959 if (et.size == 64)
11960 {
11961 /* .i64 is a pseudo-op, so the immediate must be a repeating
11962 pattern. */
11963 if (immbits != (inst.operands[1].regisimm ?
11964 inst.operands[1].reg : 0))
11965 {
11966 /* Set immbits to an invalid constant. */
11967 immbits = 0xdeadbeef;
11968 }
11969 }
11970
5287ad62
JB
11971 switch (opcode)
11972 {
11973 case N_MNEM_vbic:
036dc3f7 11974 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11975 break;
5f4273c7 11976
5287ad62 11977 case N_MNEM_vorr:
036dc3f7 11978 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11979 break;
5f4273c7 11980
5287ad62
JB
11981 case N_MNEM_vand:
11982 /* Pseudo-instruction for VBIC. */
5287ad62
JB
11983 neon_invert_size (&immbits, 0, et.size);
11984 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11985 break;
5f4273c7 11986
5287ad62
JB
11987 case N_MNEM_vorn:
11988 /* Pseudo-instruction for VORR. */
5287ad62
JB
11989 neon_invert_size (&immbits, 0, et.size);
11990 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11991 break;
5f4273c7 11992
5287ad62
JB
11993 default:
11994 abort ();
11995 }
11996
11997 if (cmode == FAIL)
11998 return;
11999
037e8744 12000 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12001 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12002 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12003 inst.instruction |= cmode << 8;
12004 neon_write_immbits (immbits);
5f4273c7 12005
5287ad62
JB
12006 inst.instruction = neon_dp_fixup (inst.instruction);
12007 }
12008}
12009
12010static void
12011do_neon_bitfield (void)
12012{
037e8744 12013 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12014 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12015 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12016}
12017
12018static void
dcbf9037
JB
12019neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12020 unsigned destbits)
5287ad62 12021{
037e8744 12022 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12023 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12024 types | N_KEY);
5287ad62
JB
12025 if (et.type == NT_float)
12026 {
12027 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12028 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12029 }
12030 else
12031 {
12032 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12033 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12034 }
12035}
12036
12037static void
12038do_neon_dyadic_if_su (void)
12039{
dcbf9037 12040 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12041}
12042
12043static void
12044do_neon_dyadic_if_su_d (void)
12045{
12046 /* This version only allow D registers, but that constraint is enforced during
12047 operand parsing so we don't need to do anything extra here. */
dcbf9037 12048 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12049}
12050
5287ad62
JB
12051static void
12052do_neon_dyadic_if_i_d (void)
12053{
428e3f1f
PB
12054 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12055 affected if we specify unsigned args. */
12056 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12057}
12058
037e8744
JB
12059enum vfp_or_neon_is_neon_bits
12060{
12061 NEON_CHECK_CC = 1,
12062 NEON_CHECK_ARCH = 2
12063};
12064
12065/* Call this function if an instruction which may have belonged to the VFP or
12066 Neon instruction sets, but turned out to be a Neon instruction (due to the
12067 operand types involved, etc.). We have to check and/or fix-up a couple of
12068 things:
12069
12070 - Make sure the user hasn't attempted to make a Neon instruction
12071 conditional.
12072 - Alter the value in the condition code field if necessary.
12073 - Make sure that the arch supports Neon instructions.
12074
12075 Which of these operations take place depends on bits from enum
12076 vfp_or_neon_is_neon_bits.
12077
12078 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12079 current instruction's condition is COND_ALWAYS, the condition field is
12080 changed to inst.uncond_value. This is necessary because instructions shared
12081 between VFP and Neon may be conditional for the VFP variants only, and the
12082 unconditional Neon version must have, e.g., 0xF in the condition field. */
12083
12084static int
12085vfp_or_neon_is_neon (unsigned check)
12086{
12087 /* Conditions are always legal in Thumb mode (IT blocks). */
12088 if (!thumb_mode && (check & NEON_CHECK_CC))
12089 {
12090 if (inst.cond != COND_ALWAYS)
12091 {
12092 first_error (_(BAD_COND));
12093 return FAIL;
12094 }
12095 if (inst.uncond_value != -1)
12096 inst.instruction |= inst.uncond_value << 28;
12097 }
5f4273c7 12098
037e8744
JB
12099 if ((check & NEON_CHECK_ARCH)
12100 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12101 {
12102 first_error (_(BAD_FPU));
12103 return FAIL;
12104 }
5f4273c7 12105
037e8744
JB
12106 return SUCCESS;
12107}
12108
5287ad62
JB
12109static void
12110do_neon_addsub_if_i (void)
12111{
037e8744
JB
12112 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12113 return;
12114
12115 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12116 return;
12117
5287ad62
JB
12118 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12119 affected if we specify unsigned args. */
dcbf9037 12120 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12121}
12122
12123/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12124 result to be:
12125 V<op> A,B (A is operand 0, B is operand 2)
12126 to mean:
12127 V<op> A,B,A
12128 not:
12129 V<op> A,B,B
12130 so handle that case specially. */
12131
12132static void
12133neon_exchange_operands (void)
12134{
12135 void *scratch = alloca (sizeof (inst.operands[0]));
12136 if (inst.operands[1].present)
12137 {
12138 /* Swap operands[1] and operands[2]. */
12139 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12140 inst.operands[1] = inst.operands[2];
12141 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12142 }
12143 else
12144 {
12145 inst.operands[1] = inst.operands[2];
12146 inst.operands[2] = inst.operands[0];
12147 }
12148}
12149
12150static void
12151neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12152{
12153 if (inst.operands[2].isreg)
12154 {
12155 if (invert)
12156 neon_exchange_operands ();
dcbf9037 12157 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12158 }
12159 else
12160 {
037e8744 12161 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12162 struct neon_type_el et = neon_check_type (2, rs,
12163 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12164
12165 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12166 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12167 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12168 inst.instruction |= LOW4 (inst.operands[1].reg);
12169 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12170 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12171 inst.instruction |= (et.type == NT_float) << 10;
12172 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12173
5287ad62
JB
12174 inst.instruction = neon_dp_fixup (inst.instruction);
12175 }
12176}
12177
12178static void
12179do_neon_cmp (void)
12180{
12181 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12182}
12183
12184static void
12185do_neon_cmp_inv (void)
12186{
12187 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12188}
12189
12190static void
12191do_neon_ceq (void)
12192{
12193 neon_compare (N_IF_32, N_IF_32, FALSE);
12194}
12195
12196/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12197 scalars, which are encoded in 5 bits, M : Rm.
12198 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12199 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12200 index in M. */
12201
12202static unsigned
12203neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12204{
dcbf9037
JB
12205 unsigned regno = NEON_SCALAR_REG (scalar);
12206 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12207
12208 switch (elsize)
12209 {
12210 case 16:
12211 if (regno > 7 || elno > 3)
12212 goto bad_scalar;
12213 return regno | (elno << 3);
5f4273c7 12214
5287ad62
JB
12215 case 32:
12216 if (regno > 15 || elno > 1)
12217 goto bad_scalar;
12218 return regno | (elno << 4);
12219
12220 default:
12221 bad_scalar:
dcbf9037 12222 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12223 }
12224
12225 return 0;
12226}
12227
12228/* Encode multiply / multiply-accumulate scalar instructions. */
12229
12230static void
12231neon_mul_mac (struct neon_type_el et, int ubit)
12232{
dcbf9037
JB
12233 unsigned scalar;
12234
12235 /* Give a more helpful error message if we have an invalid type. */
12236 if (et.type == NT_invtype)
12237 return;
5f4273c7 12238
dcbf9037 12239 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12240 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12241 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12242 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12243 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12244 inst.instruction |= LOW4 (scalar);
12245 inst.instruction |= HI1 (scalar) << 5;
12246 inst.instruction |= (et.type == NT_float) << 8;
12247 inst.instruction |= neon_logbits (et.size) << 20;
12248 inst.instruction |= (ubit != 0) << 24;
12249
12250 inst.instruction = neon_dp_fixup (inst.instruction);
12251}
12252
12253static void
12254do_neon_mac_maybe_scalar (void)
12255{
037e8744
JB
12256 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12257 return;
12258
12259 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12260 return;
12261
5287ad62
JB
12262 if (inst.operands[2].isscalar)
12263 {
037e8744 12264 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12265 struct neon_type_el et = neon_check_type (3, rs,
12266 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12267 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12268 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12269 }
12270 else
428e3f1f
PB
12271 {
12272 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12273 affected if we specify unsigned args. */
12274 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12275 }
5287ad62
JB
12276}
12277
12278static void
12279do_neon_tst (void)
12280{
037e8744 12281 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12282 struct neon_type_el et = neon_check_type (3, rs,
12283 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12284 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12285}
12286
12287/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12288 same types as the MAC equivalents. The polynomial type for this instruction
12289 is encoded the same as the integer type. */
12290
12291static void
12292do_neon_mul (void)
12293{
037e8744
JB
12294 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12295 return;
12296
12297 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12298 return;
12299
5287ad62
JB
12300 if (inst.operands[2].isscalar)
12301 do_neon_mac_maybe_scalar ();
12302 else
dcbf9037 12303 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12304}
12305
12306static void
12307do_neon_qdmulh (void)
12308{
12309 if (inst.operands[2].isscalar)
12310 {
037e8744 12311 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12312 struct neon_type_el et = neon_check_type (3, rs,
12313 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12314 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12315 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12316 }
12317 else
12318 {
037e8744 12319 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12320 struct neon_type_el et = neon_check_type (3, rs,
12321 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12322 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12323 /* The U bit (rounding) comes from bit mask. */
037e8744 12324 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12325 }
12326}
12327
12328static void
12329do_neon_fcmp_absolute (void)
12330{
037e8744 12331 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12332 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12333 /* Size field comes from bit mask. */
037e8744 12334 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12335}
12336
12337static void
12338do_neon_fcmp_absolute_inv (void)
12339{
12340 neon_exchange_operands ();
12341 do_neon_fcmp_absolute ();
12342}
12343
12344static void
12345do_neon_step (void)
12346{
037e8744 12347 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12348 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12349 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12350}
12351
12352static void
12353do_neon_abs_neg (void)
12354{
037e8744
JB
12355 enum neon_shape rs;
12356 struct neon_type_el et;
5f4273c7 12357
037e8744
JB
12358 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12359 return;
12360
12361 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12362 return;
12363
12364 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12365 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12366
5287ad62
JB
12367 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12368 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12369 inst.instruction |= LOW4 (inst.operands[1].reg);
12370 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12371 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12372 inst.instruction |= (et.type == NT_float) << 10;
12373 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12374
5287ad62
JB
12375 inst.instruction = neon_dp_fixup (inst.instruction);
12376}
12377
12378static void
12379do_neon_sli (void)
12380{
037e8744 12381 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12382 struct neon_type_el et = neon_check_type (2, rs,
12383 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12384 int imm = inst.operands[2].imm;
12385 constraint (imm < 0 || (unsigned)imm >= et.size,
12386 _("immediate out of range for insert"));
037e8744 12387 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12388}
12389
12390static void
12391do_neon_sri (void)
12392{
037e8744 12393 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12394 struct neon_type_el et = neon_check_type (2, rs,
12395 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12396 int imm = inst.operands[2].imm;
12397 constraint (imm < 1 || (unsigned)imm > et.size,
12398 _("immediate out of range for insert"));
037e8744 12399 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12400}
12401
12402static void
12403do_neon_qshlu_imm (void)
12404{
037e8744 12405 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12406 struct neon_type_el et = neon_check_type (2, rs,
12407 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12408 int imm = inst.operands[2].imm;
12409 constraint (imm < 0 || (unsigned)imm >= et.size,
12410 _("immediate out of range for shift"));
12411 /* Only encodes the 'U present' variant of the instruction.
12412 In this case, signed types have OP (bit 8) set to 0.
12413 Unsigned types have OP set to 1. */
12414 inst.instruction |= (et.type == NT_unsigned) << 8;
12415 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12416 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12417}
12418
12419static void
12420do_neon_qmovn (void)
12421{
12422 struct neon_type_el et = neon_check_type (2, NS_DQ,
12423 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12424 /* Saturating move where operands can be signed or unsigned, and the
12425 destination has the same signedness. */
12426 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12427 if (et.type == NT_unsigned)
12428 inst.instruction |= 0xc0;
12429 else
12430 inst.instruction |= 0x80;
12431 neon_two_same (0, 1, et.size / 2);
12432}
12433
12434static void
12435do_neon_qmovun (void)
12436{
12437 struct neon_type_el et = neon_check_type (2, NS_DQ,
12438 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12439 /* Saturating move with unsigned results. Operands must be signed. */
12440 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12441 neon_two_same (0, 1, et.size / 2);
12442}
12443
12444static void
12445do_neon_rshift_sat_narrow (void)
12446{
12447 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12448 or unsigned. If operands are unsigned, results must also be unsigned. */
12449 struct neon_type_el et = neon_check_type (2, NS_DQI,
12450 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12451 int imm = inst.operands[2].imm;
12452 /* This gets the bounds check, size encoding and immediate bits calculation
12453 right. */
12454 et.size /= 2;
5f4273c7 12455
5287ad62
JB
12456 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12457 VQMOVN.I<size> <Dd>, <Qm>. */
12458 if (imm == 0)
12459 {
12460 inst.operands[2].present = 0;
12461 inst.instruction = N_MNEM_vqmovn;
12462 do_neon_qmovn ();
12463 return;
12464 }
5f4273c7 12465
5287ad62
JB
12466 constraint (imm < 1 || (unsigned)imm > et.size,
12467 _("immediate out of range"));
12468 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12469}
12470
12471static void
12472do_neon_rshift_sat_narrow_u (void)
12473{
12474 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12475 or unsigned. If operands are unsigned, results must also be unsigned. */
12476 struct neon_type_el et = neon_check_type (2, NS_DQI,
12477 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12478 int imm = inst.operands[2].imm;
12479 /* This gets the bounds check, size encoding and immediate bits calculation
12480 right. */
12481 et.size /= 2;
12482
12483 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12484 VQMOVUN.I<size> <Dd>, <Qm>. */
12485 if (imm == 0)
12486 {
12487 inst.operands[2].present = 0;
12488 inst.instruction = N_MNEM_vqmovun;
12489 do_neon_qmovun ();
12490 return;
12491 }
12492
12493 constraint (imm < 1 || (unsigned)imm > et.size,
12494 _("immediate out of range"));
12495 /* FIXME: The manual is kind of unclear about what value U should have in
12496 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12497 must be 1. */
12498 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12499}
12500
12501static void
12502do_neon_movn (void)
12503{
12504 struct neon_type_el et = neon_check_type (2, NS_DQ,
12505 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12506 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12507 neon_two_same (0, 1, et.size / 2);
12508}
12509
12510static void
12511do_neon_rshift_narrow (void)
12512{
12513 struct neon_type_el et = neon_check_type (2, NS_DQI,
12514 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12515 int imm = inst.operands[2].imm;
12516 /* This gets the bounds check, size encoding and immediate bits calculation
12517 right. */
12518 et.size /= 2;
5f4273c7 12519
5287ad62
JB
12520 /* If immediate is zero then we are a pseudo-instruction for
12521 VMOVN.I<size> <Dd>, <Qm> */
12522 if (imm == 0)
12523 {
12524 inst.operands[2].present = 0;
12525 inst.instruction = N_MNEM_vmovn;
12526 do_neon_movn ();
12527 return;
12528 }
5f4273c7 12529
5287ad62
JB
12530 constraint (imm < 1 || (unsigned)imm > et.size,
12531 _("immediate out of range for narrowing operation"));
12532 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12533}
12534
12535static void
12536do_neon_shll (void)
12537{
12538 /* FIXME: Type checking when lengthening. */
12539 struct neon_type_el et = neon_check_type (2, NS_QDI,
12540 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12541 unsigned imm = inst.operands[2].imm;
12542
12543 if (imm == et.size)
12544 {
12545 /* Maximum shift variant. */
12546 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12547 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12548 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12549 inst.instruction |= LOW4 (inst.operands[1].reg);
12550 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12551 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12552
5287ad62
JB
12553 inst.instruction = neon_dp_fixup (inst.instruction);
12554 }
12555 else
12556 {
12557 /* A more-specific type check for non-max versions. */
12558 et = neon_check_type (2, NS_QDI,
12559 N_EQK | N_DBL, N_SU_32 | N_KEY);
12560 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12561 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12562 }
12563}
12564
037e8744 12565/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12566 the current instruction is. */
12567
12568static int
12569neon_cvt_flavour (enum neon_shape rs)
12570{
037e8744
JB
12571#define CVT_VAR(C,X,Y) \
12572 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12573 if (et.type != NT_invtype) \
12574 { \
12575 inst.error = NULL; \
12576 return (C); \
5287ad62
JB
12577 }
12578 struct neon_type_el et;
037e8744
JB
12579 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12580 || rs == NS_FF) ? N_VFP : 0;
12581 /* The instruction versions which take an immediate take one register
12582 argument, which is extended to the width of the full register. Thus the
12583 "source" and "destination" registers must have the same width. Hack that
12584 here by making the size equal to the key (wider, in this case) operand. */
12585 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 12586
5287ad62
JB
12587 CVT_VAR (0, N_S32, N_F32);
12588 CVT_VAR (1, N_U32, N_F32);
12589 CVT_VAR (2, N_F32, N_S32);
12590 CVT_VAR (3, N_F32, N_U32);
5f4273c7 12591
037e8744 12592 whole_reg = N_VFP;
5f4273c7 12593
037e8744
JB
12594 /* VFP instructions. */
12595 CVT_VAR (4, N_F32, N_F64);
12596 CVT_VAR (5, N_F64, N_F32);
12597 CVT_VAR (6, N_S32, N_F64 | key);
12598 CVT_VAR (7, N_U32, N_F64 | key);
12599 CVT_VAR (8, N_F64 | key, N_S32);
12600 CVT_VAR (9, N_F64 | key, N_U32);
12601 /* VFP instructions with bitshift. */
12602 CVT_VAR (10, N_F32 | key, N_S16);
12603 CVT_VAR (11, N_F32 | key, N_U16);
12604 CVT_VAR (12, N_F64 | key, N_S16);
12605 CVT_VAR (13, N_F64 | key, N_U16);
12606 CVT_VAR (14, N_S16, N_F32 | key);
12607 CVT_VAR (15, N_U16, N_F32 | key);
12608 CVT_VAR (16, N_S16, N_F64 | key);
12609 CVT_VAR (17, N_U16, N_F64 | key);
5f4273c7 12610
5287ad62
JB
12611 return -1;
12612#undef CVT_VAR
12613}
12614
037e8744
JB
12615/* Neon-syntax VFP conversions. */
12616
5287ad62 12617static void
037e8744 12618do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12619{
037e8744 12620 const char *opname = 0;
5f4273c7 12621
037e8744 12622 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12623 {
037e8744
JB
12624 /* Conversions with immediate bitshift. */
12625 const char *enc[] =
12626 {
12627 "ftosls",
12628 "ftouls",
12629 "fsltos",
12630 "fultos",
12631 NULL,
12632 NULL,
12633 "ftosld",
12634 "ftould",
12635 "fsltod",
12636 "fultod",
12637 "fshtos",
12638 "fuhtos",
12639 "fshtod",
12640 "fuhtod",
12641 "ftoshs",
12642 "ftouhs",
12643 "ftoshd",
12644 "ftouhd"
12645 };
12646
12647 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12648 {
12649 opname = enc[flavour];
12650 constraint (inst.operands[0].reg != inst.operands[1].reg,
12651 _("operands 0 and 1 must be the same register"));
12652 inst.operands[1] = inst.operands[2];
12653 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12654 }
5287ad62
JB
12655 }
12656 else
12657 {
037e8744
JB
12658 /* Conversions without bitshift. */
12659 const char *enc[] =
12660 {
12661 "ftosis",
12662 "ftouis",
12663 "fsitos",
12664 "fuitos",
12665 "fcvtsd",
12666 "fcvtds",
12667 "ftosid",
12668 "ftouid",
12669 "fsitod",
12670 "fuitod"
12671 };
12672
12673 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12674 opname = enc[flavour];
12675 }
12676
12677 if (opname)
12678 do_vfp_nsyn_opcode (opname);
12679}
12680
12681static void
12682do_vfp_nsyn_cvtz (void)
12683{
12684 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12685 int flavour = neon_cvt_flavour (rs);
12686 const char *enc[] =
12687 {
12688 "ftosizs",
12689 "ftouizs",
12690 NULL,
12691 NULL,
12692 NULL,
12693 NULL,
12694 "ftosizd",
12695 "ftouizd"
12696 };
12697
12698 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12699 do_vfp_nsyn_opcode (enc[flavour]);
12700}
12701
12702static void
12703do_neon_cvt (void)
12704{
12705 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12706 NS_FD, NS_DF, NS_FF, NS_NULL);
12707 int flavour = neon_cvt_flavour (rs);
12708
12709 /* VFP rather than Neon conversions. */
12710 if (flavour >= 4)
12711 {
12712 do_vfp_nsyn_cvt (rs, flavour);
12713 return;
12714 }
12715
12716 switch (rs)
12717 {
12718 case NS_DDI:
12719 case NS_QQI:
12720 {
12721 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12722 return;
12723
12724 /* Fixed-point conversion with #0 immediate is encoded as an
12725 integer conversion. */
12726 if (inst.operands[2].present && inst.operands[2].imm == 0)
12727 goto int_encode;
12728 unsigned immbits = 32 - inst.operands[2].imm;
12729 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12730 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12731 if (flavour != -1)
12732 inst.instruction |= enctab[flavour];
12733 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12734 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12735 inst.instruction |= LOW4 (inst.operands[1].reg);
12736 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12737 inst.instruction |= neon_quad (rs) << 6;
12738 inst.instruction |= 1 << 21;
12739 inst.instruction |= immbits << 16;
12740
12741 inst.instruction = neon_dp_fixup (inst.instruction);
12742 }
12743 break;
12744
12745 case NS_DD:
12746 case NS_QQ:
12747 int_encode:
12748 {
12749 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12750
12751 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12752
12753 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12754 return;
12755
12756 if (flavour != -1)
12757 inst.instruction |= enctab[flavour];
12758
12759 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12760 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12761 inst.instruction |= LOW4 (inst.operands[1].reg);
12762 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12763 inst.instruction |= neon_quad (rs) << 6;
12764 inst.instruction |= 2 << 18;
12765
12766 inst.instruction = neon_dp_fixup (inst.instruction);
12767 }
12768 break;
12769
12770 default:
12771 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12772 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12773 }
5287ad62
JB
12774}
12775
12776static void
12777neon_move_immediate (void)
12778{
037e8744
JB
12779 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12780 struct neon_type_el et = neon_check_type (2, rs,
12781 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12782 unsigned immlo, immhi = 0, immbits;
c96612cc 12783 int op, cmode, float_p;
5287ad62 12784
037e8744
JB
12785 constraint (et.type == NT_invtype,
12786 _("operand size must be specified for immediate VMOV"));
12787
5287ad62
JB
12788 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12789 op = (inst.instruction & (1 << 5)) != 0;
12790
12791 immlo = inst.operands[1].imm;
12792 if (inst.operands[1].regisimm)
12793 immhi = inst.operands[1].reg;
12794
12795 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12796 _("immediate has bits set outside the operand size"));
12797
c96612cc
JB
12798 float_p = inst.operands[1].immisfloat;
12799
12800 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12801 et.size, et.type)) == FAIL)
5287ad62
JB
12802 {
12803 /* Invert relevant bits only. */
12804 neon_invert_size (&immlo, &immhi, et.size);
12805 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12806 with one or the other; those cases are caught by
12807 neon_cmode_for_move_imm. */
12808 op = !op;
c96612cc
JB
12809 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12810 &op, et.size, et.type)) == FAIL)
5287ad62 12811 {
dcbf9037 12812 first_error (_("immediate out of range"));
5287ad62
JB
12813 return;
12814 }
12815 }
12816
12817 inst.instruction &= ~(1 << 5);
12818 inst.instruction |= op << 5;
12819
12820 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12821 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12822 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12823 inst.instruction |= cmode << 8;
12824
12825 neon_write_immbits (immbits);
12826}
12827
12828static void
12829do_neon_mvn (void)
12830{
12831 if (inst.operands[1].isreg)
12832 {
037e8744 12833 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 12834
5287ad62
JB
12835 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12836 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12837 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12838 inst.instruction |= LOW4 (inst.operands[1].reg);
12839 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12840 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12841 }
12842 else
12843 {
12844 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12845 neon_move_immediate ();
12846 }
12847
12848 inst.instruction = neon_dp_fixup (inst.instruction);
12849}
12850
12851/* Encode instructions of form:
12852
12853 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 12854 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
12855
12856static void
12857neon_mixed_length (struct neon_type_el et, unsigned size)
12858{
12859 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12860 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12861 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12862 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12863 inst.instruction |= LOW4 (inst.operands[2].reg);
12864 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12865 inst.instruction |= (et.type == NT_unsigned) << 24;
12866 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12867
5287ad62
JB
12868 inst.instruction = neon_dp_fixup (inst.instruction);
12869}
12870
12871static void
12872do_neon_dyadic_long (void)
12873{
12874 /* FIXME: Type checking for lengthening op. */
12875 struct neon_type_el et = neon_check_type (3, NS_QDD,
12876 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12877 neon_mixed_length (et, et.size);
12878}
12879
12880static void
12881do_neon_abal (void)
12882{
12883 struct neon_type_el et = neon_check_type (3, NS_QDD,
12884 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12885 neon_mixed_length (et, et.size);
12886}
12887
12888static void
12889neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12890{
12891 if (inst.operands[2].isscalar)
12892 {
dcbf9037
JB
12893 struct neon_type_el et = neon_check_type (3, NS_QDS,
12894 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12895 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12896 neon_mul_mac (et, et.type == NT_unsigned);
12897 }
12898 else
12899 {
12900 struct neon_type_el et = neon_check_type (3, NS_QDD,
12901 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12902 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12903 neon_mixed_length (et, et.size);
12904 }
12905}
12906
12907static void
12908do_neon_mac_maybe_scalar_long (void)
12909{
12910 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12911}
12912
12913static void
12914do_neon_dyadic_wide (void)
12915{
12916 struct neon_type_el et = neon_check_type (3, NS_QQD,
12917 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12918 neon_mixed_length (et, et.size);
12919}
12920
12921static void
12922do_neon_dyadic_narrow (void)
12923{
12924 struct neon_type_el et = neon_check_type (3, NS_QDD,
12925 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12926 /* Operand sign is unimportant, and the U bit is part of the opcode,
12927 so force the operand type to integer. */
12928 et.type = NT_integer;
5287ad62
JB
12929 neon_mixed_length (et, et.size / 2);
12930}
12931
12932static void
12933do_neon_mul_sat_scalar_long (void)
12934{
12935 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12936}
12937
12938static void
12939do_neon_vmull (void)
12940{
12941 if (inst.operands[2].isscalar)
12942 do_neon_mac_maybe_scalar_long ();
12943 else
12944 {
12945 struct neon_type_el et = neon_check_type (3, NS_QDD,
12946 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12947 if (et.type == NT_poly)
12948 inst.instruction = NEON_ENC_POLY (inst.instruction);
12949 else
12950 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12951 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12952 zero. Should be OK as-is. */
12953 neon_mixed_length (et, et.size);
12954 }
12955}
12956
12957static void
12958do_neon_ext (void)
12959{
037e8744 12960 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12961 struct neon_type_el et = neon_check_type (3, rs,
12962 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12963 unsigned imm = (inst.operands[3].imm * et.size) / 8;
3b8d421e 12964 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
5287ad62
JB
12965 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12966 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12967 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12968 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12969 inst.instruction |= LOW4 (inst.operands[2].reg);
12970 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12971 inst.instruction |= neon_quad (rs) << 6;
5287ad62 12972 inst.instruction |= imm << 8;
5f4273c7 12973
5287ad62
JB
12974 inst.instruction = neon_dp_fixup (inst.instruction);
12975}
12976
12977static void
12978do_neon_rev (void)
12979{
037e8744 12980 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12981 struct neon_type_el et = neon_check_type (2, rs,
12982 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12983 unsigned op = (inst.instruction >> 7) & 3;
12984 /* N (width of reversed regions) is encoded as part of the bitmask. We
12985 extract it here to check the elements to be reversed are smaller.
12986 Otherwise we'd get a reserved instruction. */
12987 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12988 assert (elsize != 0);
12989 constraint (et.size >= elsize,
12990 _("elements must be smaller than reversal region"));
037e8744 12991 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12992}
12993
12994static void
12995do_neon_dup (void)
12996{
12997 if (inst.operands[1].isscalar)
12998 {
037e8744 12999 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13000 struct neon_type_el et = neon_check_type (2, rs,
13001 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13002 unsigned sizebits = et.size >> 3;
dcbf9037 13003 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13004 int logsize = neon_logbits (et.size);
dcbf9037 13005 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13006
13007 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13008 return;
13009
5287ad62
JB
13010 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13013 inst.instruction |= LOW4 (dm);
13014 inst.instruction |= HI1 (dm) << 5;
037e8744 13015 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13016 inst.instruction |= x << 17;
13017 inst.instruction |= sizebits << 16;
5f4273c7 13018
5287ad62
JB
13019 inst.instruction = neon_dp_fixup (inst.instruction);
13020 }
13021 else
13022 {
037e8744
JB
13023 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13024 struct neon_type_el et = neon_check_type (2, rs,
13025 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13026 /* Duplicate ARM register to lanes of vector. */
13027 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13028 switch (et.size)
13029 {
13030 case 8: inst.instruction |= 0x400000; break;
13031 case 16: inst.instruction |= 0x000020; break;
13032 case 32: inst.instruction |= 0x000000; break;
13033 default: break;
13034 }
13035 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13036 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13037 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13038 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13039 /* The encoding for this instruction is identical for the ARM and Thumb
13040 variants, except for the condition field. */
037e8744 13041 do_vfp_cond_or_thumb ();
5287ad62
JB
13042 }
13043}
13044
13045/* VMOV has particularly many variations. It can be one of:
13046 0. VMOV<c><q> <Qd>, <Qm>
13047 1. VMOV<c><q> <Dd>, <Dm>
13048 (Register operations, which are VORR with Rm = Rn.)
13049 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13050 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13051 (Immediate loads.)
13052 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13053 (ARM register to scalar.)
13054 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13055 (Two ARM registers to vector.)
13056 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13057 (Scalar to ARM register.)
13058 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13059 (Vector to two ARM registers.)
037e8744
JB
13060 8. VMOV.F32 <Sd>, <Sm>
13061 9. VMOV.F64 <Dd>, <Dm>
13062 (VFP register moves.)
13063 10. VMOV.F32 <Sd>, #imm
13064 11. VMOV.F64 <Dd>, #imm
13065 (VFP float immediate load.)
13066 12. VMOV <Rd>, <Sm>
13067 (VFP single to ARM reg.)
13068 13. VMOV <Sd>, <Rm>
13069 (ARM reg to VFP single.)
13070 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13071 (Two ARM regs to two VFP singles.)
13072 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13073 (Two VFP singles to two ARM regs.)
5f4273c7 13074
037e8744
JB
13075 These cases can be disambiguated using neon_select_shape, except cases 1/9
13076 and 3/11 which depend on the operand type too.
5f4273c7 13077
5287ad62 13078 All the encoded bits are hardcoded by this function.
5f4273c7 13079
b7fc2769
JB
13080 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13081 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13082
5287ad62 13083 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13084 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13085
13086static void
13087do_neon_mov (void)
13088{
037e8744
JB
13089 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13090 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13091 NS_NULL);
13092 struct neon_type_el et;
13093 const char *ldconst = 0;
5287ad62 13094
037e8744 13095 switch (rs)
5287ad62 13096 {
037e8744
JB
13097 case NS_DD: /* case 1/9. */
13098 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13099 /* It is not an error here if no type is given. */
13100 inst.error = NULL;
13101 if (et.type == NT_float && et.size == 64)
5287ad62 13102 {
037e8744
JB
13103 do_vfp_nsyn_opcode ("fcpyd");
13104 break;
5287ad62 13105 }
037e8744 13106 /* fall through. */
5287ad62 13107
037e8744
JB
13108 case NS_QQ: /* case 0/1. */
13109 {
13110 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13111 return;
13112 /* The architecture manual I have doesn't explicitly state which
13113 value the U bit should have for register->register moves, but
13114 the equivalent VORR instruction has U = 0, so do that. */
13115 inst.instruction = 0x0200110;
13116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13118 inst.instruction |= LOW4 (inst.operands[1].reg);
13119 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13120 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13121 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13122 inst.instruction |= neon_quad (rs) << 6;
13123
13124 inst.instruction = neon_dp_fixup (inst.instruction);
13125 }
13126 break;
5f4273c7 13127
037e8744
JB
13128 case NS_DI: /* case 3/11. */
13129 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13130 inst.error = NULL;
13131 if (et.type == NT_float && et.size == 64)
5287ad62 13132 {
037e8744
JB
13133 /* case 11 (fconstd). */
13134 ldconst = "fconstd";
13135 goto encode_fconstd;
5287ad62 13136 }
037e8744
JB
13137 /* fall through. */
13138
13139 case NS_QI: /* case 2/3. */
13140 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13141 return;
13142 inst.instruction = 0x0800010;
13143 neon_move_immediate ();
13144 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13145 break;
5f4273c7 13146
037e8744
JB
13147 case NS_SR: /* case 4. */
13148 {
13149 unsigned bcdebits = 0;
13150 struct neon_type_el et = neon_check_type (2, NS_NULL,
13151 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13152 int logsize = neon_logbits (et.size);
13153 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13154 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13155
13156 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13157 _(BAD_FPU));
13158 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13159 && et.size != 32, _(BAD_FPU));
13160 constraint (et.type == NT_invtype, _("bad type for scalar"));
13161 constraint (x >= 64 / et.size, _("scalar index out of range"));
13162
13163 switch (et.size)
13164 {
13165 case 8: bcdebits = 0x8; break;
13166 case 16: bcdebits = 0x1; break;
13167 case 32: bcdebits = 0x0; break;
13168 default: ;
13169 }
13170
13171 bcdebits |= x << logsize;
13172
13173 inst.instruction = 0xe000b10;
13174 do_vfp_cond_or_thumb ();
13175 inst.instruction |= LOW4 (dn) << 16;
13176 inst.instruction |= HI1 (dn) << 7;
13177 inst.instruction |= inst.operands[1].reg << 12;
13178 inst.instruction |= (bcdebits & 3) << 5;
13179 inst.instruction |= (bcdebits >> 2) << 21;
13180 }
13181 break;
5f4273c7 13182
037e8744 13183 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13184 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13185 _(BAD_FPU));
b7fc2769 13186
037e8744
JB
13187 inst.instruction = 0xc400b10;
13188 do_vfp_cond_or_thumb ();
13189 inst.instruction |= LOW4 (inst.operands[0].reg);
13190 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13191 inst.instruction |= inst.operands[1].reg << 12;
13192 inst.instruction |= inst.operands[2].reg << 16;
13193 break;
5f4273c7 13194
037e8744
JB
13195 case NS_RS: /* case 6. */
13196 {
13197 struct neon_type_el et = neon_check_type (2, NS_NULL,
13198 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13199 unsigned logsize = neon_logbits (et.size);
13200 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13201 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13202 unsigned abcdebits = 0;
13203
13204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13205 _(BAD_FPU));
13206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13207 && et.size != 32, _(BAD_FPU));
13208 constraint (et.type == NT_invtype, _("bad type for scalar"));
13209 constraint (x >= 64 / et.size, _("scalar index out of range"));
13210
13211 switch (et.size)
13212 {
13213 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13214 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13215 case 32: abcdebits = 0x00; break;
13216 default: ;
13217 }
13218
13219 abcdebits |= x << logsize;
13220 inst.instruction = 0xe100b10;
13221 do_vfp_cond_or_thumb ();
13222 inst.instruction |= LOW4 (dn) << 16;
13223 inst.instruction |= HI1 (dn) << 7;
13224 inst.instruction |= inst.operands[0].reg << 12;
13225 inst.instruction |= (abcdebits & 3) << 5;
13226 inst.instruction |= (abcdebits >> 2) << 21;
13227 }
13228 break;
5f4273c7 13229
037e8744
JB
13230 case NS_RRD: /* case 7 (fmrrd). */
13231 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13232 _(BAD_FPU));
13233
13234 inst.instruction = 0xc500b10;
13235 do_vfp_cond_or_thumb ();
13236 inst.instruction |= inst.operands[0].reg << 12;
13237 inst.instruction |= inst.operands[1].reg << 16;
13238 inst.instruction |= LOW4 (inst.operands[2].reg);
13239 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13240 break;
5f4273c7 13241
037e8744
JB
13242 case NS_FF: /* case 8 (fcpys). */
13243 do_vfp_nsyn_opcode ("fcpys");
13244 break;
5f4273c7 13245
037e8744
JB
13246 case NS_FI: /* case 10 (fconsts). */
13247 ldconst = "fconsts";
13248 encode_fconstd:
13249 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13250 {
037e8744
JB
13251 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13252 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13253 }
13254 else
037e8744
JB
13255 first_error (_("immediate out of range"));
13256 break;
5f4273c7 13257
037e8744
JB
13258 case NS_RF: /* case 12 (fmrs). */
13259 do_vfp_nsyn_opcode ("fmrs");
13260 break;
5f4273c7 13261
037e8744
JB
13262 case NS_FR: /* case 13 (fmsr). */
13263 do_vfp_nsyn_opcode ("fmsr");
13264 break;
5f4273c7 13265
037e8744
JB
13266 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13267 (one of which is a list), but we have parsed four. Do some fiddling to
13268 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13269 expect. */
13270 case NS_RRFF: /* case 14 (fmrrs). */
13271 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13272 _("VFP registers must be adjacent"));
13273 inst.operands[2].imm = 2;
13274 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13275 do_vfp_nsyn_opcode ("fmrrs");
13276 break;
5f4273c7 13277
037e8744
JB
13278 case NS_FFRR: /* case 15 (fmsrr). */
13279 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13280 _("VFP registers must be adjacent"));
13281 inst.operands[1] = inst.operands[2];
13282 inst.operands[2] = inst.operands[3];
13283 inst.operands[0].imm = 2;
13284 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13285 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13286 break;
5f4273c7 13287
5287ad62
JB
13288 default:
13289 abort ();
13290 }
13291}
13292
13293static void
13294do_neon_rshift_round_imm (void)
13295{
037e8744 13296 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13297 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13298 int imm = inst.operands[2].imm;
13299
13300 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13301 if (imm == 0)
13302 {
13303 inst.operands[2].present = 0;
13304 do_neon_mov ();
13305 return;
13306 }
13307
13308 constraint (imm < 1 || (unsigned)imm > et.size,
13309 _("immediate out of range for shift"));
037e8744 13310 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13311 et.size - imm);
13312}
13313
13314static void
13315do_neon_movl (void)
13316{
13317 struct neon_type_el et = neon_check_type (2, NS_QD,
13318 N_EQK | N_DBL, N_SU_32 | N_KEY);
13319 unsigned sizebits = et.size >> 3;
13320 inst.instruction |= sizebits << 19;
13321 neon_two_same (0, et.type == NT_unsigned, -1);
13322}
13323
13324static void
13325do_neon_trn (void)
13326{
037e8744 13327 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13328 struct neon_type_el et = neon_check_type (2, rs,
13329 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13330 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13331 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13332}
13333
13334static void
13335do_neon_zip_uzp (void)
13336{
037e8744 13337 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13338 struct neon_type_el et = neon_check_type (2, rs,
13339 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13340 if (rs == NS_DD && et.size == 32)
13341 {
13342 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13343 inst.instruction = N_MNEM_vtrn;
13344 do_neon_trn ();
13345 return;
13346 }
037e8744 13347 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13348}
13349
13350static void
13351do_neon_sat_abs_neg (void)
13352{
037e8744 13353 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13354 struct neon_type_el et = neon_check_type (2, rs,
13355 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13356 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13357}
13358
13359static void
13360do_neon_pair_long (void)
13361{
037e8744 13362 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13363 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13364 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13365 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13366 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13367}
13368
13369static void
13370do_neon_recip_est (void)
13371{
037e8744 13372 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13373 struct neon_type_el et = neon_check_type (2, rs,
13374 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13375 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13376 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13377}
13378
13379static void
13380do_neon_cls (void)
13381{
037e8744 13382 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13383 struct neon_type_el et = neon_check_type (2, rs,
13384 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13385 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13386}
13387
13388static void
13389do_neon_clz (void)
13390{
037e8744 13391 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13392 struct neon_type_el et = neon_check_type (2, rs,
13393 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13394 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13395}
13396
13397static void
13398do_neon_cnt (void)
13399{
037e8744 13400 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13401 struct neon_type_el et = neon_check_type (2, rs,
13402 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13403 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13404}
13405
13406static void
13407do_neon_swp (void)
13408{
037e8744
JB
13409 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13410 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13411}
13412
13413static void
13414do_neon_tbl_tbx (void)
13415{
13416 unsigned listlenbits;
dcbf9037 13417 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13418
5287ad62
JB
13419 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13420 {
dcbf9037 13421 first_error (_("bad list length for table lookup"));
5287ad62
JB
13422 return;
13423 }
5f4273c7 13424
5287ad62
JB
13425 listlenbits = inst.operands[1].imm - 1;
13426 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13427 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13428 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13429 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13430 inst.instruction |= LOW4 (inst.operands[2].reg);
13431 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13432 inst.instruction |= listlenbits << 8;
5f4273c7 13433
5287ad62
JB
13434 inst.instruction = neon_dp_fixup (inst.instruction);
13435}
13436
13437static void
13438do_neon_ldm_stm (void)
13439{
13440 /* P, U and L bits are part of bitmask. */
13441 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13442 unsigned offsetbits = inst.operands[1].imm * 2;
13443
037e8744
JB
13444 if (inst.operands[1].issingle)
13445 {
13446 do_vfp_nsyn_ldm_stm (is_dbmode);
13447 return;
13448 }
13449
5287ad62
JB
13450 constraint (is_dbmode && !inst.operands[0].writeback,
13451 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13452
13453 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13454 _("register list must contain at least 1 and at most 16 "
13455 "registers"));
13456
13457 inst.instruction |= inst.operands[0].reg << 16;
13458 inst.instruction |= inst.operands[0].writeback << 21;
13459 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13460 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13461
13462 inst.instruction |= offsetbits;
5f4273c7 13463
037e8744 13464 do_vfp_cond_or_thumb ();
5287ad62
JB
13465}
13466
13467static void
13468do_neon_ldr_str (void)
13469{
5287ad62 13470 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13471
037e8744
JB
13472 if (inst.operands[0].issingle)
13473 {
cd2f129f
JB
13474 if (is_ldr)
13475 do_vfp_nsyn_opcode ("flds");
13476 else
13477 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13478 }
13479 else
5287ad62 13480 {
cd2f129f
JB
13481 if (is_ldr)
13482 do_vfp_nsyn_opcode ("fldd");
5287ad62 13483 else
cd2f129f 13484 do_vfp_nsyn_opcode ("fstd");
5287ad62 13485 }
5287ad62
JB
13486}
13487
13488/* "interleave" version also handles non-interleaving register VLD1/VST1
13489 instructions. */
13490
13491static void
13492do_neon_ld_st_interleave (void)
13493{
037e8744 13494 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13495 N_8 | N_16 | N_32 | N_64);
13496 unsigned alignbits = 0;
13497 unsigned idx;
13498 /* The bits in this table go:
13499 0: register stride of one (0) or two (1)
13500 1,2: register list length, minus one (1, 2, 3, 4).
13501 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13502 We use -1 for invalid entries. */
13503 const int typetable[] =
13504 {
13505 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13506 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13507 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13508 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13509 };
13510 int typebits;
13511
dcbf9037
JB
13512 if (et.type == NT_invtype)
13513 return;
13514
5287ad62
JB
13515 if (inst.operands[1].immisalign)
13516 switch (inst.operands[1].imm >> 8)
13517 {
13518 case 64: alignbits = 1; break;
13519 case 128:
13520 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13521 goto bad_alignment;
13522 alignbits = 2;
13523 break;
13524 case 256:
13525 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13526 goto bad_alignment;
13527 alignbits = 3;
13528 break;
13529 default:
13530 bad_alignment:
dcbf9037 13531 first_error (_("bad alignment"));
5287ad62
JB
13532 return;
13533 }
13534
13535 inst.instruction |= alignbits << 4;
13536 inst.instruction |= neon_logbits (et.size) << 6;
13537
13538 /* Bits [4:6] of the immediate in a list specifier encode register stride
13539 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13540 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13541 up the right value for "type" in a table based on this value and the given
13542 list style, then stick it back. */
13543 idx = ((inst.operands[0].imm >> 4) & 7)
13544 | (((inst.instruction >> 8) & 3) << 3);
13545
13546 typebits = typetable[idx];
5f4273c7 13547
5287ad62
JB
13548 constraint (typebits == -1, _("bad list type for instruction"));
13549
13550 inst.instruction &= ~0xf00;
13551 inst.instruction |= typebits << 8;
13552}
13553
13554/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13555 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13556 otherwise. The variable arguments are a list of pairs of legal (size, align)
13557 values, terminated with -1. */
13558
13559static int
13560neon_alignment_bit (int size, int align, int *do_align, ...)
13561{
13562 va_list ap;
13563 int result = FAIL, thissize, thisalign;
5f4273c7 13564
5287ad62
JB
13565 if (!inst.operands[1].immisalign)
13566 {
13567 *do_align = 0;
13568 return SUCCESS;
13569 }
5f4273c7 13570
5287ad62
JB
13571 va_start (ap, do_align);
13572
13573 do
13574 {
13575 thissize = va_arg (ap, int);
13576 if (thissize == -1)
13577 break;
13578 thisalign = va_arg (ap, int);
13579
13580 if (size == thissize && align == thisalign)
13581 result = SUCCESS;
13582 }
13583 while (result != SUCCESS);
13584
13585 va_end (ap);
13586
13587 if (result == SUCCESS)
13588 *do_align = 1;
13589 else
dcbf9037 13590 first_error (_("unsupported alignment for instruction"));
5f4273c7 13591
5287ad62
JB
13592 return result;
13593}
13594
13595static void
13596do_neon_ld_st_lane (void)
13597{
037e8744 13598 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13599 int align_good, do_align = 0;
13600 int logsize = neon_logbits (et.size);
13601 int align = inst.operands[1].imm >> 8;
13602 int n = (inst.instruction >> 8) & 3;
13603 int max_el = 64 / et.size;
5f4273c7 13604
dcbf9037
JB
13605 if (et.type == NT_invtype)
13606 return;
5f4273c7 13607
5287ad62
JB
13608 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13609 _("bad list length"));
13610 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13611 _("scalar index out of range"));
13612 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13613 && et.size == 8,
13614 _("stride of 2 unavailable when element size is 8"));
5f4273c7 13615
5287ad62
JB
13616 switch (n)
13617 {
13618 case 0: /* VLD1 / VST1. */
13619 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13620 32, 32, -1);
13621 if (align_good == FAIL)
13622 return;
13623 if (do_align)
13624 {
13625 unsigned alignbits = 0;
13626 switch (et.size)
13627 {
13628 case 16: alignbits = 0x1; break;
13629 case 32: alignbits = 0x3; break;
13630 default: ;
13631 }
13632 inst.instruction |= alignbits << 4;
13633 }
13634 break;
13635
13636 case 1: /* VLD2 / VST2. */
13637 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13638 32, 64, -1);
13639 if (align_good == FAIL)
13640 return;
13641 if (do_align)
13642 inst.instruction |= 1 << 4;
13643 break;
13644
13645 case 2: /* VLD3 / VST3. */
13646 constraint (inst.operands[1].immisalign,
13647 _("can't use alignment with this instruction"));
13648 break;
13649
13650 case 3: /* VLD4 / VST4. */
13651 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13652 16, 64, 32, 64, 32, 128, -1);
13653 if (align_good == FAIL)
13654 return;
13655 if (do_align)
13656 {
13657 unsigned alignbits = 0;
13658 switch (et.size)
13659 {
13660 case 8: alignbits = 0x1; break;
13661 case 16: alignbits = 0x1; break;
13662 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13663 default: ;
13664 }
13665 inst.instruction |= alignbits << 4;
13666 }
13667 break;
13668
13669 default: ;
13670 }
13671
13672 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13673 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13674 inst.instruction |= 1 << (4 + logsize);
5f4273c7 13675
5287ad62
JB
13676 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13677 inst.instruction |= logsize << 10;
13678}
13679
13680/* Encode single n-element structure to all lanes VLD<n> instructions. */
13681
13682static void
13683do_neon_ld_dup (void)
13684{
037e8744 13685 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13686 int align_good, do_align = 0;
13687
dcbf9037
JB
13688 if (et.type == NT_invtype)
13689 return;
13690
5287ad62
JB
13691 switch ((inst.instruction >> 8) & 3)
13692 {
13693 case 0: /* VLD1. */
13694 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13695 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13696 &do_align, 16, 16, 32, 32, -1);
13697 if (align_good == FAIL)
13698 return;
13699 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13700 {
13701 case 1: break;
13702 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13703 default: first_error (_("bad list length")); return;
5287ad62
JB
13704 }
13705 inst.instruction |= neon_logbits (et.size) << 6;
13706 break;
13707
13708 case 1: /* VLD2. */
13709 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13710 &do_align, 8, 16, 16, 32, 32, 64, -1);
13711 if (align_good == FAIL)
13712 return;
13713 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13714 _("bad list length"));
13715 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13716 inst.instruction |= 1 << 5;
13717 inst.instruction |= neon_logbits (et.size) << 6;
13718 break;
13719
13720 case 2: /* VLD3. */
13721 constraint (inst.operands[1].immisalign,
13722 _("can't use alignment with this instruction"));
13723 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13724 _("bad list length"));
13725 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13726 inst.instruction |= 1 << 5;
13727 inst.instruction |= neon_logbits (et.size) << 6;
13728 break;
13729
13730 case 3: /* VLD4. */
13731 {
13732 int align = inst.operands[1].imm >> 8;
13733 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13734 16, 64, 32, 64, 32, 128, -1);
13735 if (align_good == FAIL)
13736 return;
13737 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13738 _("bad list length"));
13739 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13740 inst.instruction |= 1 << 5;
13741 if (et.size == 32 && align == 128)
13742 inst.instruction |= 0x3 << 6;
13743 else
13744 inst.instruction |= neon_logbits (et.size) << 6;
13745 }
13746 break;
13747
13748 default: ;
13749 }
13750
13751 inst.instruction |= do_align << 4;
13752}
13753
13754/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13755 apart from bits [11:4]. */
13756
13757static void
13758do_neon_ldx_stx (void)
13759{
13760 switch (NEON_LANE (inst.operands[0].imm))
13761 {
13762 case NEON_INTERLEAVE_LANES:
13763 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13764 do_neon_ld_st_interleave ();
13765 break;
5f4273c7 13766
5287ad62
JB
13767 case NEON_ALL_LANES:
13768 inst.instruction = NEON_ENC_DUP (inst.instruction);
13769 do_neon_ld_dup ();
13770 break;
5f4273c7 13771
5287ad62
JB
13772 default:
13773 inst.instruction = NEON_ENC_LANE (inst.instruction);
13774 do_neon_ld_st_lane ();
13775 }
13776
13777 /* L bit comes from bit mask. */
13778 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13779 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13780 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 13781
5287ad62
JB
13782 if (inst.operands[1].postind)
13783 {
13784 int postreg = inst.operands[1].imm & 0xf;
13785 constraint (!inst.operands[1].immisreg,
13786 _("post-index must be a register"));
13787 constraint (postreg == 0xd || postreg == 0xf,
13788 _("bad register for post-index"));
13789 inst.instruction |= postreg;
13790 }
13791 else if (inst.operands[1].writeback)
13792 {
13793 inst.instruction |= 0xd;
13794 }
13795 else
5f4273c7
NC
13796 inst.instruction |= 0xf;
13797
5287ad62
JB
13798 if (thumb_mode)
13799 inst.instruction |= 0xf9000000;
13800 else
13801 inst.instruction |= 0xf4000000;
13802}
5287ad62
JB
13803\f
13804/* Overall per-instruction processing. */
13805
13806/* We need to be able to fix up arbitrary expressions in some statements.
13807 This is so that we can handle symbols that are an arbitrary distance from
13808 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13809 which returns part of an address in a form which will be valid for
13810 a data instruction. We do this by pushing the expression into a symbol
13811 in the expr_section, and creating a fix for that. */
13812
13813static void
13814fix_new_arm (fragS * frag,
13815 int where,
13816 short int size,
13817 expressionS * exp,
13818 int pc_rel,
13819 int reloc)
13820{
13821 fixS * new_fix;
13822
13823 switch (exp->X_op)
13824 {
13825 case O_constant:
13826 case O_symbol:
13827 case O_add:
13828 case O_subtract:
13829 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13830 break;
13831
13832 default:
13833 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13834 pc_rel, reloc);
13835 break;
13836 }
13837
13838 /* Mark whether the fix is to a THUMB instruction, or an ARM
13839 instruction. */
13840 new_fix->tc_fix_data = thumb_mode;
13841}
13842
13843/* Create a frg for an instruction requiring relaxation. */
13844static void
13845output_relax_insn (void)
13846{
13847 char * to;
13848 symbolS *sym;
0110f2b8
PB
13849 int offset;
13850
6e1cb1a6
PB
13851 /* The size of the instruction is unknown, so tie the debug info to the
13852 start of the instruction. */
13853 dwarf2_emit_insn (0);
6e1cb1a6 13854
0110f2b8
PB
13855 switch (inst.reloc.exp.X_op)
13856 {
13857 case O_symbol:
13858 sym = inst.reloc.exp.X_add_symbol;
13859 offset = inst.reloc.exp.X_add_number;
13860 break;
13861 case O_constant:
13862 sym = NULL;
13863 offset = inst.reloc.exp.X_add_number;
13864 break;
13865 default:
13866 sym = make_expr_symbol (&inst.reloc.exp);
13867 offset = 0;
13868 break;
13869 }
13870 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13871 inst.relax, sym, offset, NULL/*offset, opcode*/);
13872 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13873}
13874
13875/* Write a 32-bit thumb instruction to buf. */
13876static void
13877put_thumb32_insn (char * buf, unsigned long insn)
13878{
13879 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13880 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13881}
13882
b99bd4ef 13883static void
c19d1205 13884output_inst (const char * str)
b99bd4ef 13885{
c19d1205 13886 char * to = NULL;
b99bd4ef 13887
c19d1205 13888 if (inst.error)
b99bd4ef 13889 {
c19d1205 13890 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13891 return;
13892 }
5f4273c7
NC
13893 if (inst.relax)
13894 {
13895 output_relax_insn ();
0110f2b8 13896 return;
5f4273c7 13897 }
c19d1205
ZW
13898 if (inst.size == 0)
13899 return;
b99bd4ef 13900
c19d1205
ZW
13901 to = frag_more (inst.size);
13902
13903 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13904 {
c19d1205 13905 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13906 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13907 }
c19d1205 13908 else if (inst.size > INSN_SIZE)
b99bd4ef 13909 {
c19d1205
ZW
13910 assert (inst.size == (2 * INSN_SIZE));
13911 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13912 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13913 }
c19d1205
ZW
13914 else
13915 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13916
c19d1205
ZW
13917 if (inst.reloc.type != BFD_RELOC_UNUSED)
13918 fix_new_arm (frag_now, to - frag_now->fr_literal,
13919 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13920 inst.reloc.type);
b99bd4ef 13921
c19d1205 13922 dwarf2_emit_insn (inst.size);
c19d1205 13923}
b99bd4ef 13924
c19d1205
ZW
13925/* Tag values used in struct asm_opcode's tag field. */
13926enum opcode_tag
13927{
13928 OT_unconditional, /* Instruction cannot be conditionalized.
13929 The ARM condition field is still 0xE. */
13930 OT_unconditionalF, /* Instruction cannot be conditionalized
13931 and carries 0xF in its ARM condition field. */
13932 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13933 OT_csuffixF, /* Some forms of the instruction take a conditional
13934 suffix, others place 0xF where the condition field
13935 would be. */
c19d1205
ZW
13936 OT_cinfix3, /* Instruction takes a conditional infix,
13937 beginning at character index 3. (In
13938 unified mode, it becomes a suffix.) */
088fa78e
KH
13939 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13940 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13941 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13942 character index 3, even in unified mode. Used for
13943 legacy instructions where suffix and infix forms
13944 may be ambiguous. */
c19d1205 13945 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13946 suffix or an infix at character index 3. */
c19d1205
ZW
13947 OT_odd_infix_unc, /* This is the unconditional variant of an
13948 instruction that takes a conditional infix
13949 at an unusual position. In unified mode,
13950 this variant will accept a suffix. */
13951 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13952 are the conditional variants of instructions that
13953 take conditional infixes in unusual positions.
13954 The infix appears at character index
13955 (tag - OT_odd_infix_0). These are not accepted
13956 in unified mode. */
13957};
b99bd4ef 13958
c19d1205
ZW
13959/* Subroutine of md_assemble, responsible for looking up the primary
13960 opcode from the mnemonic the user wrote. STR points to the
13961 beginning of the mnemonic.
13962
13963 This is not simply a hash table lookup, because of conditional
13964 variants. Most instructions have conditional variants, which are
13965 expressed with a _conditional affix_ to the mnemonic. If we were
13966 to encode each conditional variant as a literal string in the opcode
13967 table, it would have approximately 20,000 entries.
13968
13969 Most mnemonics take this affix as a suffix, and in unified syntax,
13970 'most' is upgraded to 'all'. However, in the divided syntax, some
13971 instructions take the affix as an infix, notably the s-variants of
13972 the arithmetic instructions. Of those instructions, all but six
13973 have the infix appear after the third character of the mnemonic.
13974
13975 Accordingly, the algorithm for looking up primary opcodes given
13976 an identifier is:
13977
13978 1. Look up the identifier in the opcode table.
13979 If we find a match, go to step U.
13980
13981 2. Look up the last two characters of the identifier in the
13982 conditions table. If we find a match, look up the first N-2
13983 characters of the identifier in the opcode table. If we
13984 find a match, go to step CE.
13985
13986 3. Look up the fourth and fifth characters of the identifier in
13987 the conditions table. If we find a match, extract those
13988 characters from the identifier, and look up the remaining
13989 characters in the opcode table. If we find a match, go
13990 to step CM.
13991
13992 4. Fail.
13993
13994 U. Examine the tag field of the opcode structure, in case this is
13995 one of the six instructions with its conditional infix in an
13996 unusual place. If it is, the tag tells us where to find the
13997 infix; look it up in the conditions table and set inst.cond
13998 accordingly. Otherwise, this is an unconditional instruction.
13999 Again set inst.cond accordingly. Return the opcode structure.
14000
14001 CE. Examine the tag field to make sure this is an instruction that
14002 should receive a conditional suffix. If it is not, fail.
14003 Otherwise, set inst.cond from the suffix we already looked up,
14004 and return the opcode structure.
14005
14006 CM. Examine the tag field to make sure this is an instruction that
14007 should receive a conditional infix after the third character.
14008 If it is not, fail. Otherwise, undo the edits to the current
14009 line of input and proceed as for case CE. */
14010
14011static const struct asm_opcode *
14012opcode_lookup (char **str)
14013{
14014 char *end, *base;
14015 char *affix;
14016 const struct asm_opcode *opcode;
14017 const struct asm_cond *cond;
e3cb604e 14018 char save[2];
267d2029 14019 bfd_boolean neon_supported;
5f4273c7 14020
267d2029 14021 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14022
14023 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14024 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14025 for (base = end = *str; *end != '\0'; end++)
267d2029 14026 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14027 break;
b99bd4ef 14028
c19d1205
ZW
14029 if (end == base)
14030 return 0;
b99bd4ef 14031
5287ad62 14032 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14033 if (end[0] == '.')
b99bd4ef 14034 {
5287ad62 14035 int offset = 2;
5f4273c7 14036
267d2029
JB
14037 /* The .w and .n suffixes are only valid if the unified syntax is in
14038 use. */
14039 if (unified_syntax && end[1] == 'w')
c19d1205 14040 inst.size_req = 4;
267d2029 14041 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14042 inst.size_req = 2;
14043 else
5287ad62
JB
14044 offset = 0;
14045
14046 inst.vectype.elems = 0;
14047
14048 *str = end + offset;
b99bd4ef 14049
5f4273c7 14050 if (end[offset] == '.')
5287ad62 14051 {
267d2029
JB
14052 /* See if we have a Neon type suffix (possible in either unified or
14053 non-unified ARM syntax mode). */
dcbf9037 14054 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14055 return 0;
14056 }
14057 else if (end[offset] != '\0' && end[offset] != ' ')
14058 return 0;
b99bd4ef 14059 }
c19d1205
ZW
14060 else
14061 *str = end;
b99bd4ef 14062
c19d1205
ZW
14063 /* Look for unaffixed or special-case affixed mnemonic. */
14064 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14065 if (opcode)
b99bd4ef 14066 {
c19d1205
ZW
14067 /* step U */
14068 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14069 {
c19d1205
ZW
14070 inst.cond = COND_ALWAYS;
14071 return opcode;
b99bd4ef 14072 }
b99bd4ef 14073
c19d1205
ZW
14074 if (unified_syntax)
14075 as_warn (_("conditional infixes are deprecated in unified syntax"));
14076 affix = base + (opcode->tag - OT_odd_infix_0);
14077 cond = hash_find_n (arm_cond_hsh, affix, 2);
14078 assert (cond);
b99bd4ef 14079
c19d1205
ZW
14080 inst.cond = cond->value;
14081 return opcode;
14082 }
b99bd4ef 14083
c19d1205
ZW
14084 /* Cannot have a conditional suffix on a mnemonic of less than two
14085 characters. */
14086 if (end - base < 3)
14087 return 0;
b99bd4ef 14088
c19d1205
ZW
14089 /* Look for suffixed mnemonic. */
14090 affix = end - 2;
14091 cond = hash_find_n (arm_cond_hsh, affix, 2);
14092 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14093 if (opcode && cond)
14094 {
14095 /* step CE */
14096 switch (opcode->tag)
14097 {
e3cb604e
PB
14098 case OT_cinfix3_legacy:
14099 /* Ignore conditional suffixes matched on infix only mnemonics. */
14100 break;
14101
c19d1205 14102 case OT_cinfix3:
088fa78e 14103 case OT_cinfix3_deprecated:
c19d1205
ZW
14104 case OT_odd_infix_unc:
14105 if (!unified_syntax)
e3cb604e 14106 return 0;
c19d1205
ZW
14107 /* else fall through */
14108
14109 case OT_csuffix:
037e8744 14110 case OT_csuffixF:
c19d1205
ZW
14111 case OT_csuf_or_in3:
14112 inst.cond = cond->value;
14113 return opcode;
14114
14115 case OT_unconditional:
14116 case OT_unconditionalF:
dfa9f0d5
PB
14117 if (thumb_mode)
14118 {
14119 inst.cond = cond->value;
14120 }
14121 else
14122 {
14123 /* delayed diagnostic */
14124 inst.error = BAD_COND;
14125 inst.cond = COND_ALWAYS;
14126 }
c19d1205 14127 return opcode;
b99bd4ef 14128
c19d1205
ZW
14129 default:
14130 return 0;
14131 }
14132 }
b99bd4ef 14133
c19d1205
ZW
14134 /* Cannot have a usual-position infix on a mnemonic of less than
14135 six characters (five would be a suffix). */
14136 if (end - base < 6)
14137 return 0;
b99bd4ef 14138
c19d1205
ZW
14139 /* Look for infixed mnemonic in the usual position. */
14140 affix = base + 3;
14141 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14142 if (!cond)
14143 return 0;
14144
14145 memcpy (save, affix, 2);
14146 memmove (affix, affix + 2, (end - affix) - 2);
14147 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14148 memmove (affix + 2, affix, (end - affix) - 2);
14149 memcpy (affix, save, 2);
14150
088fa78e
KH
14151 if (opcode
14152 && (opcode->tag == OT_cinfix3
14153 || opcode->tag == OT_cinfix3_deprecated
14154 || opcode->tag == OT_csuf_or_in3
14155 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14156 {
c19d1205 14157 /* step CM */
088fa78e
KH
14158 if (unified_syntax
14159 && (opcode->tag == OT_cinfix3
14160 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14161 as_warn (_("conditional infixes are deprecated in unified syntax"));
14162
14163 inst.cond = cond->value;
14164 return opcode;
b99bd4ef
NC
14165 }
14166
c19d1205 14167 return 0;
b99bd4ef
NC
14168}
14169
c19d1205
ZW
14170void
14171md_assemble (char *str)
b99bd4ef 14172{
c19d1205
ZW
14173 char *p = str;
14174 const struct asm_opcode * opcode;
b99bd4ef 14175
c19d1205
ZW
14176 /* Align the previous label if needed. */
14177 if (last_label_seen != NULL)
b99bd4ef 14178 {
c19d1205
ZW
14179 symbol_set_frag (last_label_seen, frag_now);
14180 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14181 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14182 }
14183
c19d1205
ZW
14184 memset (&inst, '\0', sizeof (inst));
14185 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14186
c19d1205
ZW
14187 opcode = opcode_lookup (&p);
14188 if (!opcode)
b99bd4ef 14189 {
c19d1205 14190 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14191 the form alias .req reg, or a Neon .dn/.qn directive. */
14192 if (!create_register_alias (str, p)
14193 && !create_neon_reg_alias (str, p))
c19d1205 14194 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14195
b99bd4ef
NC
14196 return;
14197 }
14198
088fa78e
KH
14199 if (opcode->tag == OT_cinfix3_deprecated)
14200 as_warn (_("s suffix on comparison instruction is deprecated"));
14201
037e8744
JB
14202 /* The value which unconditional instructions should have in place of the
14203 condition field. */
14204 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14205
c19d1205 14206 if (thumb_mode)
b99bd4ef 14207 {
e74cfd16 14208 arm_feature_set variant;
8f06b2d8
PB
14209
14210 variant = cpu_variant;
14211 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14212 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14213 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14214 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14215 if (!opcode->tvariant
14216 || (thumb_mode == 1
14217 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14218 {
c19d1205 14219 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14220 return;
14221 }
c19d1205
ZW
14222 if (inst.cond != COND_ALWAYS && !unified_syntax
14223 && opcode->tencode != do_t_branch)
b99bd4ef 14224 {
c19d1205 14225 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14226 return;
14227 }
14228
076d447c
PB
14229 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14230 {
14231 /* Implicit require narrow instructions on Thumb-1. This avoids
14232 relaxation accidentally introducing Thumb-2 instructions. */
7e806470
PB
14233 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14234 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
076d447c
PB
14235 inst.size_req = 2;
14236 }
14237
e27ec89e
PB
14238 /* Check conditional suffixes. */
14239 if (current_it_mask)
14240 {
14241 int cond;
14242 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14243 current_it_mask <<= 1;
14244 current_it_mask &= 0x1f;
14245 /* The BKPT instruction is unconditional even in an IT block. */
14246 if (!inst.error
14247 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14248 {
14249 as_bad (_("incorrect condition in IT block"));
14250 return;
14251 }
e27ec89e
PB
14252 }
14253 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14254 {
6decc662 14255 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14256 return;
14257 }
14258
c19d1205
ZW
14259 mapping_state (MAP_THUMB);
14260 inst.instruction = opcode->tvalue;
14261
14262 if (!parse_operands (p, opcode->operands))
14263 opcode->tencode ();
14264
e27ec89e
PB
14265 /* Clear current_it_mask at the end of an IT block. */
14266 if (current_it_mask == 0x10)
14267 current_it_mask = 0;
14268
0110f2b8 14269 if (!(inst.error || inst.relax))
b99bd4ef 14270 {
c19d1205
ZW
14271 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14272 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14273 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14274 {
c19d1205 14275 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14276 return;
14277 }
14278 }
076d447c
PB
14279
14280 /* Something has gone badly wrong if we try to relax a fixed size
14281 instruction. */
14282 assert (inst.size_req == 0 || !inst.relax);
14283
e74cfd16
PB
14284 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14285 *opcode->tvariant);
ee065d83 14286 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14287 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14288 anything other than bl/blx and v6-M instructions.
ee065d83 14289 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14290 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14291 || inst.relax)
14292 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
e74cfd16
PB
14293 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14294 arm_ext_v6t2);
c19d1205 14295 }
3e9e4fcf 14296 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14297 {
845b51d6
PB
14298 bfd_boolean is_bx;
14299
14300 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14301 is_bx = (opcode->aencode == do_bx);
14302
c19d1205 14303 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14304 if (!(is_bx && fix_v4bx)
14305 && !(opcode->avariant &&
14306 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14307 {
c19d1205
ZW
14308 as_bad (_("selected processor does not support `%s'"), str);
14309 return;
b99bd4ef 14310 }
c19d1205 14311 if (inst.size_req)
b99bd4ef 14312 {
c19d1205
ZW
14313 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14314 return;
b99bd4ef
NC
14315 }
14316
c19d1205
ZW
14317 mapping_state (MAP_ARM);
14318 inst.instruction = opcode->avalue;
14319 if (opcode->tag == OT_unconditionalF)
14320 inst.instruction |= 0xF << 28;
14321 else
14322 inst.instruction |= inst.cond << 28;
14323 inst.size = INSN_SIZE;
14324 if (!parse_operands (p, opcode->operands))
14325 opcode->aencode ();
ee065d83
PB
14326 /* Arm mode bx is marked as both v4T and v5 because it's still required
14327 on a hypothetical non-thumb v5 core. */
845b51d6 14328 if (is_bx)
e74cfd16 14329 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14330 else
e74cfd16
PB
14331 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14332 *opcode->avariant);
b99bd4ef 14333 }
3e9e4fcf
JB
14334 else
14335 {
14336 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14337 "-- `%s'"), str);
14338 return;
14339 }
c19d1205
ZW
14340 output_inst (str);
14341}
b99bd4ef 14342
c19d1205
ZW
14343/* Various frobbings of labels and their addresses. */
14344
14345void
14346arm_start_line_hook (void)
14347{
14348 last_label_seen = NULL;
b99bd4ef
NC
14349}
14350
c19d1205
ZW
14351void
14352arm_frob_label (symbolS * sym)
b99bd4ef 14353{
c19d1205 14354 last_label_seen = sym;
b99bd4ef 14355
c19d1205 14356 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14357
c19d1205
ZW
14358#if defined OBJ_COFF || defined OBJ_ELF
14359 ARM_SET_INTERWORK (sym, support_interwork);
14360#endif
b99bd4ef 14361
5f4273c7 14362 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14363 as Thumb functions. This is because these labels, whilst
14364 they exist inside Thumb code, are not the entry points for
14365 possible ARM->Thumb calls. Also, these labels can be used
14366 as part of a computed goto or switch statement. eg gcc
14367 can generate code that looks like this:
b99bd4ef 14368
c19d1205
ZW
14369 ldr r2, [pc, .Laaa]
14370 lsl r3, r3, #2
14371 ldr r2, [r3, r2]
14372 mov pc, r2
b99bd4ef 14373
c19d1205
ZW
14374 .Lbbb: .word .Lxxx
14375 .Lccc: .word .Lyyy
14376 ..etc...
14377 .Laaa: .word Lbbb
b99bd4ef 14378
c19d1205
ZW
14379 The first instruction loads the address of the jump table.
14380 The second instruction converts a table index into a byte offset.
14381 The third instruction gets the jump address out of the table.
14382 The fourth instruction performs the jump.
b99bd4ef 14383
c19d1205
ZW
14384 If the address stored at .Laaa is that of a symbol which has the
14385 Thumb_Func bit set, then the linker will arrange for this address
14386 to have the bottom bit set, which in turn would mean that the
14387 address computation performed by the third instruction would end
14388 up with the bottom bit set. Since the ARM is capable of unaligned
14389 word loads, the instruction would then load the incorrect address
14390 out of the jump table, and chaos would ensue. */
14391 if (label_is_thumb_function_name
14392 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14393 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14394 {
c19d1205
ZW
14395 /* When the address of a Thumb function is taken the bottom
14396 bit of that address should be set. This will allow
14397 interworking between Arm and Thumb functions to work
14398 correctly. */
b99bd4ef 14399
c19d1205 14400 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14401
c19d1205 14402 label_is_thumb_function_name = FALSE;
b99bd4ef 14403 }
07a53e5c 14404
07a53e5c 14405 dwarf2_emit_label (sym);
b99bd4ef
NC
14406}
14407
c19d1205
ZW
14408int
14409arm_data_in_code (void)
b99bd4ef 14410{
c19d1205 14411 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14412 {
c19d1205
ZW
14413 *input_line_pointer = '/';
14414 input_line_pointer += 5;
14415 *input_line_pointer = 0;
14416 return 1;
b99bd4ef
NC
14417 }
14418
c19d1205 14419 return 0;
b99bd4ef
NC
14420}
14421
c19d1205
ZW
14422char *
14423arm_canonicalize_symbol_name (char * name)
b99bd4ef 14424{
c19d1205 14425 int len;
b99bd4ef 14426
c19d1205
ZW
14427 if (thumb_mode && (len = strlen (name)) > 5
14428 && streq (name + len - 5, "/data"))
14429 *(name + len - 5) = 0;
b99bd4ef 14430
c19d1205 14431 return name;
b99bd4ef 14432}
c19d1205
ZW
14433\f
14434/* Table of all register names defined by default. The user can
14435 define additional names with .req. Note that all register names
14436 should appear in both upper and lowercase variants. Some registers
14437 also have mixed-case names. */
b99bd4ef 14438
dcbf9037 14439#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14440#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14441#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14442#define REGSET(p,t) \
14443 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14444 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14445 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14446 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14447#define REGSETH(p,t) \
14448 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14449 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14450 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14451 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14452#define REGSET2(p,t) \
14453 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14454 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14455 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14456 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14457
c19d1205 14458static const struct reg_entry reg_names[] =
7ed4c4c5 14459{
c19d1205
ZW
14460 /* ARM integer registers. */
14461 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14462
c19d1205
ZW
14463 /* ATPCS synonyms. */
14464 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14465 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14466 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14467
c19d1205
ZW
14468 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14469 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14470 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14471
c19d1205
ZW
14472 /* Well-known aliases. */
14473 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14474 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14475
14476 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14477 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14478
14479 /* Coprocessor numbers. */
14480 REGSET(p, CP), REGSET(P, CP),
14481
14482 /* Coprocessor register numbers. The "cr" variants are for backward
14483 compatibility. */
14484 REGSET(c, CN), REGSET(C, CN),
14485 REGSET(cr, CN), REGSET(CR, CN),
14486
14487 /* FPA registers. */
14488 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14489 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14490
14491 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14492 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14493
14494 /* VFP SP registers. */
5287ad62
JB
14495 REGSET(s,VFS), REGSET(S,VFS),
14496 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14497
14498 /* VFP DP Registers. */
5287ad62
JB
14499 REGSET(d,VFD), REGSET(D,VFD),
14500 /* Extra Neon DP registers. */
14501 REGSETH(d,VFD), REGSETH(D,VFD),
14502
14503 /* Neon QP registers. */
14504 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14505
14506 /* VFP control registers. */
14507 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14508 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14509 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14510 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14511 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14512 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14513
14514 /* Maverick DSP coprocessor registers. */
14515 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14516 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14517
14518 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14519 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14520 REGDEF(dspsc,0,DSPSC),
14521
14522 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14523 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14524 REGDEF(DSPSC,0,DSPSC),
14525
14526 /* iWMMXt data registers - p0, c0-15. */
14527 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14528
14529 /* iWMMXt control registers - p1, c0-3. */
14530 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14531 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14532 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14533 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14534
14535 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14536 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14537 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14538 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14539 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14540
14541 /* XScale accumulator registers. */
14542 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14543};
14544#undef REGDEF
14545#undef REGNUM
14546#undef REGSET
7ed4c4c5 14547
c19d1205
ZW
14548/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14549 within psr_required_here. */
14550static const struct asm_psr psrs[] =
14551{
14552 /* Backward compatibility notation. Note that "all" is no longer
14553 truly all possible PSR bits. */
14554 {"all", PSR_c | PSR_f},
14555 {"flg", PSR_f},
14556 {"ctl", PSR_c},
14557
14558 /* Individual flags. */
14559 {"f", PSR_f},
14560 {"c", PSR_c},
14561 {"x", PSR_x},
14562 {"s", PSR_s},
14563 /* Combinations of flags. */
14564 {"fs", PSR_f | PSR_s},
14565 {"fx", PSR_f | PSR_x},
14566 {"fc", PSR_f | PSR_c},
14567 {"sf", PSR_s | PSR_f},
14568 {"sx", PSR_s | PSR_x},
14569 {"sc", PSR_s | PSR_c},
14570 {"xf", PSR_x | PSR_f},
14571 {"xs", PSR_x | PSR_s},
14572 {"xc", PSR_x | PSR_c},
14573 {"cf", PSR_c | PSR_f},
14574 {"cs", PSR_c | PSR_s},
14575 {"cx", PSR_c | PSR_x},
14576 {"fsx", PSR_f | PSR_s | PSR_x},
14577 {"fsc", PSR_f | PSR_s | PSR_c},
14578 {"fxs", PSR_f | PSR_x | PSR_s},
14579 {"fxc", PSR_f | PSR_x | PSR_c},
14580 {"fcs", PSR_f | PSR_c | PSR_s},
14581 {"fcx", PSR_f | PSR_c | PSR_x},
14582 {"sfx", PSR_s | PSR_f | PSR_x},
14583 {"sfc", PSR_s | PSR_f | PSR_c},
14584 {"sxf", PSR_s | PSR_x | PSR_f},
14585 {"sxc", PSR_s | PSR_x | PSR_c},
14586 {"scf", PSR_s | PSR_c | PSR_f},
14587 {"scx", PSR_s | PSR_c | PSR_x},
14588 {"xfs", PSR_x | PSR_f | PSR_s},
14589 {"xfc", PSR_x | PSR_f | PSR_c},
14590 {"xsf", PSR_x | PSR_s | PSR_f},
14591 {"xsc", PSR_x | PSR_s | PSR_c},
14592 {"xcf", PSR_x | PSR_c | PSR_f},
14593 {"xcs", PSR_x | PSR_c | PSR_s},
14594 {"cfs", PSR_c | PSR_f | PSR_s},
14595 {"cfx", PSR_c | PSR_f | PSR_x},
14596 {"csf", PSR_c | PSR_s | PSR_f},
14597 {"csx", PSR_c | PSR_s | PSR_x},
14598 {"cxf", PSR_c | PSR_x | PSR_f},
14599 {"cxs", PSR_c | PSR_x | PSR_s},
14600 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14601 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14602 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14603 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14604 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14605 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14606 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14607 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14608 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14609 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14610 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14611 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14612 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14613 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14614 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14615 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14616 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14617 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14618 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14619 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14620 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14621 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14622 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14623 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14624};
14625
62b3e311
PB
14626/* Table of V7M psr names. */
14627static const struct asm_psr v7m_psrs[] =
14628{
2b744c99
PB
14629 {"apsr", 0 }, {"APSR", 0 },
14630 {"iapsr", 1 }, {"IAPSR", 1 },
14631 {"eapsr", 2 }, {"EAPSR", 2 },
14632 {"psr", 3 }, {"PSR", 3 },
14633 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14634 {"ipsr", 5 }, {"IPSR", 5 },
14635 {"epsr", 6 }, {"EPSR", 6 },
14636 {"iepsr", 7 }, {"IEPSR", 7 },
14637 {"msp", 8 }, {"MSP", 8 },
14638 {"psp", 9 }, {"PSP", 9 },
14639 {"primask", 16}, {"PRIMASK", 16},
14640 {"basepri", 17}, {"BASEPRI", 17},
14641 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14642 {"faultmask", 19}, {"FAULTMASK", 19},
14643 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14644};
14645
c19d1205
ZW
14646/* Table of all shift-in-operand names. */
14647static const struct asm_shift_name shift_names [] =
b99bd4ef 14648{
c19d1205
ZW
14649 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14650 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14651 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14652 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14653 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14654 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14655};
b99bd4ef 14656
c19d1205
ZW
14657/* Table of all explicit relocation names. */
14658#ifdef OBJ_ELF
14659static struct reloc_entry reloc_names[] =
14660{
14661 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14662 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14663 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14664 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14665 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14666 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14667 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14668 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14669 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14670 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14671 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14672};
14673#endif
b99bd4ef 14674
c19d1205
ZW
14675/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14676static const struct asm_cond conds[] =
14677{
14678 {"eq", 0x0},
14679 {"ne", 0x1},
14680 {"cs", 0x2}, {"hs", 0x2},
14681 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14682 {"mi", 0x4},
14683 {"pl", 0x5},
14684 {"vs", 0x6},
14685 {"vc", 0x7},
14686 {"hi", 0x8},
14687 {"ls", 0x9},
14688 {"ge", 0xa},
14689 {"lt", 0xb},
14690 {"gt", 0xc},
14691 {"le", 0xd},
14692 {"al", 0xe}
14693};
bfae80f2 14694
62b3e311
PB
14695static struct asm_barrier_opt barrier_opt_names[] =
14696{
14697 { "sy", 0xf },
14698 { "un", 0x7 },
14699 { "st", 0xe },
14700 { "unst", 0x6 }
14701};
14702
c19d1205
ZW
14703/* Table of ARM-format instructions. */
14704
14705/* Macros for gluing together operand strings. N.B. In all cases
14706 other than OPS0, the trailing OP_stop comes from default
14707 zero-initialization of the unspecified elements of the array. */
14708#define OPS0() { OP_stop, }
14709#define OPS1(a) { OP_##a, }
14710#define OPS2(a,b) { OP_##a,OP_##b, }
14711#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14712#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14713#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14714#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14715
14716/* These macros abstract out the exact format of the mnemonic table and
14717 save some repeated characters. */
14718
14719/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14720#define TxCE(mnem, op, top, nops, ops, ae, te) \
14721 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14722 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14723
14724/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14725 a T_MNEM_xyz enumerator. */
14726#define TCE(mnem, aop, top, nops, ops, ae, te) \
14727 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14728#define tCE(mnem, aop, top, nops, ops, ae, te) \
14729 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14730
14731/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14732 infix after the third character. */
14733#define TxC3(mnem, op, top, nops, ops, ae, te) \
14734 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14735 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14736#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14737 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14738 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14739#define TC3(mnem, aop, top, nops, ops, ae, te) \
14740 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14741#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14742 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14743#define tC3(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14745#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14746 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14747
14748/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14749 appear in the condition table. */
14750#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14751 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14752 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14753
14754#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14755 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14756 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14757 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14758 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14759 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14774
14775#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14776 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14777#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14778 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14779
14780/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14781 field is still 0xE. Many of the Thumb variants can be executed
14782 conditionally, so this is checked separately. */
c19d1205
ZW
14783#define TUE(mnem, op, top, nops, ops, ae, te) \
14784 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14785 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14786
14787/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14788 condition code field. */
14789#define TUF(mnem, op, top, nops, ops, ae, te) \
14790 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14791 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14792
14793/* ARM-only variants of all the above. */
6a86118a
NC
14794#define CE(mnem, op, nops, ops, ae) \
14795 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14796
14797#define C3(mnem, op, nops, ops, ae) \
14798 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14799
e3cb604e
PB
14800/* Legacy mnemonics that always have conditional infix after the third
14801 character. */
14802#define CL(mnem, op, nops, ops, ae) \
14803 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14804 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14805
8f06b2d8
PB
14806/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14807#define cCE(mnem, op, nops, ops, ae) \
14808 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14809
e3cb604e
PB
14810/* Legacy coprocessor instructions where conditional infix and conditional
14811 suffix are ambiguous. For consistency this includes all FPA instructions,
14812 not just the potentially ambiguous ones. */
14813#define cCL(mnem, op, nops, ops, ae) \
14814 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14815 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14816
14817/* Coprocessor, takes either a suffix or a position-3 infix
14818 (for an FPA corner case). */
14819#define C3E(mnem, op, nops, ops, ae) \
14820 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14821 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14822
6a86118a
NC
14823#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14824 { #m1 #m2 #m3, OPS##nops ops, \
14825 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14826 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14827
14828#define CM(m1, m2, op, nops, ops, ae) \
14829 xCM_(m1, , m2, op, nops, ops, ae), \
14830 xCM_(m1, eq, m2, op, nops, ops, ae), \
14831 xCM_(m1, ne, m2, op, nops, ops, ae), \
14832 xCM_(m1, cs, m2, op, nops, ops, ae), \
14833 xCM_(m1, hs, m2, op, nops, ops, ae), \
14834 xCM_(m1, cc, m2, op, nops, ops, ae), \
14835 xCM_(m1, ul, m2, op, nops, ops, ae), \
14836 xCM_(m1, lo, m2, op, nops, ops, ae), \
14837 xCM_(m1, mi, m2, op, nops, ops, ae), \
14838 xCM_(m1, pl, m2, op, nops, ops, ae), \
14839 xCM_(m1, vs, m2, op, nops, ops, ae), \
14840 xCM_(m1, vc, m2, op, nops, ops, ae), \
14841 xCM_(m1, hi, m2, op, nops, ops, ae), \
14842 xCM_(m1, ls, m2, op, nops, ops, ae), \
14843 xCM_(m1, ge, m2, op, nops, ops, ae), \
14844 xCM_(m1, lt, m2, op, nops, ops, ae), \
14845 xCM_(m1, gt, m2, op, nops, ops, ae), \
14846 xCM_(m1, le, m2, op, nops, ops, ae), \
14847 xCM_(m1, al, m2, op, nops, ops, ae)
14848
14849#define UE(mnem, op, nops, ops, ae) \
14850 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14851
14852#define UF(mnem, op, nops, ops, ae) \
14853 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14854
5287ad62
JB
14855/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14856 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14857 use the same encoding function for each. */
14858#define NUF(mnem, op, nops, ops, enc) \
14859 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14860 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14861
14862/* Neon data processing, version which indirects through neon_enc_tab for
14863 the various overloaded versions of opcodes. */
14864#define nUF(mnem, op, nops, ops, enc) \
14865 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14866 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14867
14868/* Neon insn with conditional suffix for the ARM version, non-overloaded
14869 version. */
037e8744
JB
14870#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14871 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14872 THUMB_VARIANT, do_##enc, do_##enc }
14873
037e8744
JB
14874#define NCE(mnem, op, nops, ops, enc) \
14875 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14876
14877#define NCEF(mnem, op, nops, ops, enc) \
14878 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14879
5287ad62 14880/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14881#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14882 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14883 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14884
037e8744
JB
14885#define nCE(mnem, op, nops, ops, enc) \
14886 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14887
14888#define nCEF(mnem, op, nops, ops, enc) \
14889 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14890
c19d1205
ZW
14891#define do_0 0
14892
14893/* Thumb-only, unconditional. */
14894#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14895
c19d1205 14896static const struct asm_opcode insns[] =
bfae80f2 14897{
e74cfd16
PB
14898#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14899#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14900 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14901 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14902 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14903 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14904 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14905 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14906 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14907 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14908 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14909 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14910 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14911 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14912 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14913 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14914 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14915 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14916
14917 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14918 for setting PSR flag bits. They are obsolete in V6 and do not
14919 have Thumb equivalents. */
14920 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14921 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14922 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14923 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14924 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14925 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14926 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14927 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14928 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14929
14930 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14931 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14932 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14933 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14934
4962c51a
MS
14935 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14936 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14937 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14938 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14939
f5208ef2 14940 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14941 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14942 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14943 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14944 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14945 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14946
14947 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14948 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14949 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14950 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14951
c19d1205 14952 /* Pseudo ops. */
e9f89963 14953 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14954 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14955 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14956
14957 /* Thumb-compatibility pseudo ops. */
14958 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14959 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14960 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14961 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14962 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14963 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14964 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14965 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14966 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14967 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14968 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14969 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14970
16a4cf17
PB
14971 /* These may simplify to neg. */
14972 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14973 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14974
c19d1205 14975#undef THUMB_VARIANT
e74cfd16 14976#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14977 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14978
14979 /* V1 instructions with no Thumb analogue prior to V6T2. */
14980#undef THUMB_VARIANT
e74cfd16 14981#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14982 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14983 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14984 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14985
14986 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14987 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14988 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14989 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14990
9c3c69f2
PB
14991 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14992 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14993
9c3c69f2
PB
14994 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14995 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14996
14997 /* V1 instructions with no Thumb analogue at all. */
14998 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14999 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15000
15001 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15002 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15003 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15004 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15005 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15006 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15007 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15008 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15009
15010#undef ARM_VARIANT
e74cfd16 15011#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15012#undef THUMB_VARIANT
e74cfd16 15013#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15014 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15015 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15016
15017#undef THUMB_VARIANT
e74cfd16 15018#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15019 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15020 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15021
15022 /* Generic coprocessor instructions. */
15023 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15024 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15025 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15026 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15027 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15028 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15029 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15030
15031#undef ARM_VARIANT
e74cfd16 15032#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15033 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15034 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15035
15036#undef ARM_VARIANT
e74cfd16 15037#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15038#undef THUMB_VARIANT
15039#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15040 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15041 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15042
15043#undef ARM_VARIANT
e74cfd16 15044#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15045#undef THUMB_VARIANT
15046#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15047 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15048 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15049 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15050 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15051 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15054 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15055
15056#undef ARM_VARIANT
e74cfd16 15057#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15058#undef THUMB_VARIANT
e74cfd16 15059#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15060 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15061 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15062 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15063 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15064 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15065 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15066
15067#undef ARM_VARIANT
e74cfd16 15068#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15069 /* ARM Architecture 4T. */
15070 /* Note: bx (and blx) are required on V5, even if the processor does
15071 not support Thumb. */
15072 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15073
15074#undef ARM_VARIANT
e74cfd16 15075#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15076#undef THUMB_VARIANT
e74cfd16 15077#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15078 /* Note: blx has 2 variants; the .value coded here is for
15079 BLX(2). Only this variant has conditional execution. */
15080 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15081 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15082
15083#undef THUMB_VARIANT
e74cfd16 15084#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15085 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15086 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15087 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15088 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15089 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15090 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15091 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15092 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15093
15094#undef ARM_VARIANT
e74cfd16 15095#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15096 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15097 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15098 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15099 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15100
15101 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15102 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15103
15104 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15105 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15106 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15107 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15108
15109 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15110 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15111 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15112 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15113
15114 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15115 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15116
15117 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15118 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15119 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15120 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15121
15122#undef ARM_VARIANT
e74cfd16 15123#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15124 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15125 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15126 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15127
15128 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15129 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15130
15131#undef ARM_VARIANT
e74cfd16 15132#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15133 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15134
15135#undef ARM_VARIANT
e74cfd16 15136#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15137#undef THUMB_VARIANT
e74cfd16 15138#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15139 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15140 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15141 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15142 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15143 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15144 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15145 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15146 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15147 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15148 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15149
15150#undef THUMB_VARIANT
e74cfd16 15151#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15152 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15153 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15154 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15155 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15156
15157 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15158 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15159
15160/* ARM V6 not included in V7M (eg. integer SIMD). */
15161#undef THUMB_VARIANT
15162#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15163 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15164 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15165 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15166 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15203 UF(rfeib, 9900a00, 1, (RRw), rfe),
15204 UF(rfeda, 8100a00, 1, (RRw), rfe),
15205 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15206 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15207 UF(rfefa, 9900a00, 1, (RRw), rfe),
15208 UF(rfeea, 8100a00, 1, (RRw), rfe),
15209 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15210 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15211 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15212 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15213 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15214 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15216 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15217 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15218 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15219 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15220 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15221 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15222 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15223 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15224 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15225 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15226 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15227 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15230 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15231 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15232 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15235 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15236 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15237 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15238 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15239 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15240 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15241 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15242 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15243 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15244 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15245 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15246
15247#undef ARM_VARIANT
e74cfd16 15248#define ARM_VARIANT &arm_ext_v6k
c19d1205 15249#undef THUMB_VARIANT
e74cfd16 15250#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15251 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15252 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15253 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15254 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15255
ebdca51a
PB
15256#undef THUMB_VARIANT
15257#define THUMB_VARIANT &arm_ext_v6_notm
15258 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15259 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15260
c19d1205 15261#undef THUMB_VARIANT
e74cfd16 15262#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15263 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15264 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15265 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15266 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15267 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15268
15269#undef ARM_VARIANT
e74cfd16 15270#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15271 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15272
15273#undef ARM_VARIANT
e74cfd16 15274#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15275 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15276 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15277 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15278 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15279
15280 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15281 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15282 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15283 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15284
15285 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15286 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15287 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15288 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15289
25fe350b
MS
15290 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15291 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15292 /* ARM does not really have an IT instruction, so always allow it. */
15293#undef ARM_VARIANT
15294#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15295 TUE(it, 0, bf08, 1, (COND), it, t_it),
15296 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15297 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15298 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15299 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15300 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15301 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15302 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15303 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15304 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15305 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15306 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15307 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15308 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15309 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15310
92e90b6e
PB
15311 /* Thumb2 only instructions. */
15312#undef ARM_VARIANT
e74cfd16 15313#define ARM_VARIANT NULL
92e90b6e
PB
15314
15315 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15316 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15317 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15318 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15319
62b3e311
PB
15320 /* Thumb-2 hardware division instructions (R and M profiles only). */
15321#undef THUMB_VARIANT
15322#define THUMB_VARIANT &arm_ext_div
15323 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15324 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15325
7e806470
PB
15326 /* ARM V6M/V7 instructions. */
15327#undef ARM_VARIANT
15328#define ARM_VARIANT &arm_ext_barrier
15329#undef THUMB_VARIANT
15330#define THUMB_VARIANT &arm_ext_barrier
15331 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15332 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15333 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15334
62b3e311
PB
15335 /* ARM V7 instructions. */
15336#undef ARM_VARIANT
15337#define ARM_VARIANT &arm_ext_v7
15338#undef THUMB_VARIANT
15339#define THUMB_VARIANT &arm_ext_v7
15340 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15341 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15342
c19d1205 15343#undef ARM_VARIANT
e74cfd16 15344#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15345 cCE(wfs, e200110, 1, (RR), rd),
15346 cCE(rfs, e300110, 1, (RR), rd),
15347 cCE(wfc, e400110, 1, (RR), rd),
15348 cCE(rfc, e500110, 1, (RR), rd),
15349
4962c51a
MS
15350 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15351 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15352 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15353 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15354
4962c51a
MS
15355 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15357 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15358 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15359
15360 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15361 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15362 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15363 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15364 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15370 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15371 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15372
15373 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15374 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15375 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15376 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15377 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15383 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15384 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15385
15386 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15387 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15388 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15389 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15390 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15391 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15392 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15393 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15394 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15395 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15396 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15397 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15398
15399 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15400 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15401 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15402 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15403 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15404 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15405 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15406 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15407 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15408 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15409 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15410 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15411
15412 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15413 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15414 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15415 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15416 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15422 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15423 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15424
15425 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15426 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15427 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15428 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15429 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15430 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15431 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15432 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15433 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15434 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15435 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15436 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15437
15438 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15439 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15440 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15441 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15442 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15448 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15449 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15450
15451 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15452 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15453 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15454 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15455 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15456 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15457 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15458 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15459 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15460 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15461 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15462 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15463
15464 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15465 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15466 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15467 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15468 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15469 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15470 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15471 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15472 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15473 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15474 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15475 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15476
15477 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15478 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15479 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15480 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15481 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15482 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15483 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15484 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15485 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15487 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15488 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15489
15490 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15491 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15492 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15493 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15494 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15495 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15496 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15497 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15498 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15499 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15500 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15501 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15502
15503 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15504 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15505 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15506 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15507 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15508 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15509 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15510 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15511 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15512 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15513 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15514 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15515
15516 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15517 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15518 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15519 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15520 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15521 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15522 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15523 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15524 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15526 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15527 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15528
15529 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15530 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15531 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15532 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15533 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15534 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15535 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15536 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15537 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15538 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15539 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15540 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15541
15542 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15543 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15544 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15545 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15546 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15547 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15548 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15549 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15550 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15551 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15552 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15553 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15554
15555 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15556 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15557 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15558 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15559 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15565 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15566 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15567
15568 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15580
15581 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15593
15594 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15606
15607 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15619
15620 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15632
15633 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15645
15646 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15658
15659 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15671
15672 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15684
15685 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15697
15698 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15710
15711 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15723
15724 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15735 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15736
15737 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15738 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15739 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15740 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15741
e3cb604e
PB
15742 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15743 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15744 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15745 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15746 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15747 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15748 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15749 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15750 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15751 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15752 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15753 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15754
c19d1205
ZW
15755 /* The implementation of the FIX instruction is broken on some
15756 assemblers, in that it accepts a precision specifier as well as a
15757 rounding specifier, despite the fact that this is meaningless.
15758 To be more compatible, we accept it as well, though of course it
15759 does not set any bits. */
8f06b2d8 15760 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15761 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15762 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15763 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15764 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15765 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15766 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15767 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15768 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15769 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15770 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15771 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15772 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15773
c19d1205
ZW
15774 /* Instructions that were new with the real FPA, call them V2. */
15775#undef ARM_VARIANT
e74cfd16 15776#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15777 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15778 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15779 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15780 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15781 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15782 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15783
15784#undef ARM_VARIANT
e74cfd16 15785#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15786 /* Moves and type conversions. */
8f06b2d8
PB
15787 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15788 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15789 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15790 cCE(fmstat, ef1fa10, 0, (), noargs),
15791 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15793 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15794 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15795 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15796 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15797 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15798 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15799
15800 /* Memory operations. */
4962c51a
MS
15801 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15802 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15803 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15804 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15805 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15806 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15807 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15808 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15809 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15810 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15811 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15812 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15813 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15814 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15815 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15816 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15817 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15818 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15819
c19d1205 15820 /* Monadic operations. */
8f06b2d8
PB
15821 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15822 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15823 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15824
15825 /* Dyadic operations. */
8f06b2d8
PB
15826 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15827 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15828 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15829 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15830 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15833 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15834 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15835
c19d1205 15836 /* Comparisons. */
8f06b2d8
PB
15837 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15838 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15839 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15840 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15841
c19d1205 15842#undef ARM_VARIANT
e74cfd16 15843#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15844 /* Moves and type conversions. */
5287ad62 15845 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15846 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15847 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15848 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15849 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15850 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15851 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15852 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15853 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15854 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15855 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15856 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15857 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15858
15859 /* Memory operations. */
4962c51a
MS
15860 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15861 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15862 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15863 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15864 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15865 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15866 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15867 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15868 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15869 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15870
c19d1205 15871 /* Monadic operations. */
5287ad62
JB
15872 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15873 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15874 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15875
15876 /* Dyadic operations. */
5287ad62
JB
15877 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15878 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15879 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15880 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15881 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15884 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15885 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15886
c19d1205 15887 /* Comparisons. */
5287ad62
JB
15888 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15889 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15890 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15891 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15892
15893#undef ARM_VARIANT
e74cfd16 15894#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15895 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15896 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15897 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15898 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15899
037e8744
JB
15900/* Instructions which may belong to either the Neon or VFP instruction sets.
15901 Individual encoder functions perform additional architecture checks. */
15902#undef ARM_VARIANT
15903#define ARM_VARIANT &fpu_vfp_ext_v1xd
15904#undef THUMB_VARIANT
15905#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15906 /* These mnemonics are unique to VFP. */
15907 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15908 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15909 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15910 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15911 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15912 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15913 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15914 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15915 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15916 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15917
15918 /* Mnemonics shared by Neon and VFP. */
15919 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15920 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15921 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15922
15923 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15924 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15925
15926 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15927 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15928
15929 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15930 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15931 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15932 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15933 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15934 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15935 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15936 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15937
15938 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15939
15940 /* NOTE: All VMOV encoding is special-cased! */
15941 NCE(vmov, 0, 1, (VMOV), neon_mov),
15942 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15943
5287ad62
JB
15944#undef THUMB_VARIANT
15945#define THUMB_VARIANT &fpu_neon_ext_v1
15946#undef ARM_VARIANT
15947#define ARM_VARIANT &fpu_neon_ext_v1
15948 /* Data processing with three registers of the same length. */
15949 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15950 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15951 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15952 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15953 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15954 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15956 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15957 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15958 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15959 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15960 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15961 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15962 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15963 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15964 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15965 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15966 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15967 /* If not immediate, fall back to neon_dyadic_i64_su.
15968 shl_imm should accept I8 I16 I32 I64,
15969 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15970 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15971 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15972 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15973 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15974 /* Logic ops, types optional & ignored. */
15975 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15976 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15977 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15978 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15979 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15981 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15982 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15983 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15984 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15985 /* Bitfield ops, untyped. */
15986 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15987 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15988 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15989 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15990 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15991 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15992 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15993 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15994 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15995 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15996 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15997 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15998 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15999 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16000 back to neon_dyadic_if_su. */
16001 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16002 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16003 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16004 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16005 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16006 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16007 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16008 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16009 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16010 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16011 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16012 /* As above, D registers only. */
16013 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16014 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16015 /* Int and float variants, signedness unimportant. */
5287ad62 16016 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16017 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16018 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16019 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16020 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16021 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16022 /* vtst takes sizes 8, 16, 32. */
16023 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16024 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16025 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16026 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16027 /* VQD{R}MULH takes S16 S32. */
16028 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16029 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16030 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16031 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16032 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16033 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16034 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16035 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16036 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16037 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16038 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16039 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16040 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16041 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16042 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16043 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16044
16045 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16046 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16047 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16048
16049 /* Data processing with two registers and a shift amount. */
16050 /* Right shifts, and variants with rounding.
16051 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16052 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16053 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16054 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16055 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16056 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16057 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16058 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16059 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16060 /* Shift and insert. Sizes accepted 8 16 32 64. */
16061 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16062 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16063 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16064 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16065 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16066 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16067 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16068 /* Right shift immediate, saturating & narrowing, with rounding variants.
16069 Types accepted S16 S32 S64 U16 U32 U64. */
16070 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16071 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16072 /* As above, unsigned. Types accepted S16 S32 S64. */
16073 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16074 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16075 /* Right shift narrowing. Types accepted I16 I32 I64. */
16076 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16077 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16078 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16079 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16080 /* CVT with optional immediate for fixed-point variant. */
037e8744 16081 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16082
5287ad62
JB
16083 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16084 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16085
16086 /* Data processing, three registers of different lengths. */
16087 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16088 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16089 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16090 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16091 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16092 /* If not scalar, fall back to neon_dyadic_long.
16093 Vector types as above, scalar types S16 S32 U16 U32. */
16094 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16095 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16096 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16097 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16098 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16099 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16100 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16101 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16102 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16103 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16104 /* Saturating doubling multiplies. Types S16 S32. */
16105 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16106 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16107 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16108 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16109 S16 S32 U16 U32. */
16110 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16111
16112 /* Extract. Size 8. */
3b8d421e
PB
16113 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16114 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16115
16116 /* Two registers, miscellaneous. */
16117 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16118 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16119 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16120 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16121 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16122 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16123 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16124 /* Vector replicate. Sizes 8 16 32. */
16125 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16126 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16127 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16128 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16129 /* VMOVN. Types I16 I32 I64. */
16130 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16131 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16132 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16133 /* VQMOVUN. Types S16 S32 S64. */
16134 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16135 /* VZIP / VUZP. Sizes 8 16 32. */
16136 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16137 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16138 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16139 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16140 /* VQABS / VQNEG. Types S8 S16 S32. */
16141 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16142 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16143 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16144 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16145 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16146 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16147 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16148 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16149 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16150 /* Reciprocal estimates. Types U32 F32. */
16151 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16152 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16153 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16154 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16155 /* VCLS. Types S8 S16 S32. */
16156 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16157 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16158 /* VCLZ. Types I8 I16 I32. */
16159 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16160 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16161 /* VCNT. Size 8. */
16162 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16163 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16164 /* Two address, untyped. */
16165 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16166 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16167 /* VTRN. Sizes 8 16 32. */
16168 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16169 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16170
16171 /* Table lookup. Size 8. */
16172 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16173 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16174
b7fc2769
JB
16175#undef THUMB_VARIANT
16176#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16177#undef ARM_VARIANT
16178#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16179 /* Neon element/structure load/store. */
16180 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16181 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16182 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16183 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16184 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16187 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16188
16189#undef THUMB_VARIANT
16190#define THUMB_VARIANT &fpu_vfp_ext_v3
16191#undef ARM_VARIANT
16192#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16193 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16194 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16195 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16196 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16197 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16198 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16199 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16200 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16201 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16202 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16203 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16204 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16205 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16206 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16207 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16208 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16209 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16210 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16211
5287ad62 16212#undef THUMB_VARIANT
c19d1205 16213#undef ARM_VARIANT
e74cfd16 16214#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16215 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16216 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16217 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16218 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16219 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16220 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16221 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16222 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16223
16224#undef ARM_VARIANT
e74cfd16 16225#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16226 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16227 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16228 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16229 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16230 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16231 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16232 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16233 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16234 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16235 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16236 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16237 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16238 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16239 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16240 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16241 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16242 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16243 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16244 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16245 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16246 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16247 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16248 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16249 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16250 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16251 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16252 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16253 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16254 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16255 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16256 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16257 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16258 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16259 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16260 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16261 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16262 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16263 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16273 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16293 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16294 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16295 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16296 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16315 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16326 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16327 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16328 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16329 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16330 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16331 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16332 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16335 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16336 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16337 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16338 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16339 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16340 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16341 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16342 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16343 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16344 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16345 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16346 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16347 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16348 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16349 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16350 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16351 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16352 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16353 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16354 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16355 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16356 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16357 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16358 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16359 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16369 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16370 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16371 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16372 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16373 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16374 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16376 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16377 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16380 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16381 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16382 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16383 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16386 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16387 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16388
2d447fca
JM
16389#undef ARM_VARIANT
16390#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16391 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16392 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16393 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16394 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16395 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16396 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16397 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16412 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16448
c19d1205 16449#undef ARM_VARIANT
e74cfd16 16450#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16451 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16452 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16453 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16454 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16455 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16456 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16457 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16458 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16459 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16460 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16461 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16462 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16463 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16464 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16465 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16466 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16467 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16468 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16469 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16470 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16471 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16472 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16473 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16476 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16477 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16478 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16479 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16480 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16481 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16482 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16483 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16484 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16485 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16486 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16487 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16488 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16489 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16490 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16491 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16492 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16493 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16494 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16495 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16496 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16497 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16498 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16499 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16500 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16501 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16502 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16503 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16504 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16505 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16506 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16507 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16508 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16509 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16510 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16511 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16512 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16513 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16514 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16515 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16516 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16517 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16518 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16519 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16521 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16522 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16523 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16524 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16525 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16526 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16527};
16528#undef ARM_VARIANT
16529#undef THUMB_VARIANT
16530#undef TCE
16531#undef TCM
16532#undef TUE
16533#undef TUF
16534#undef TCC
8f06b2d8 16535#undef cCE
e3cb604e
PB
16536#undef cCL
16537#undef C3E
c19d1205
ZW
16538#undef CE
16539#undef CM
16540#undef UE
16541#undef UF
16542#undef UT
5287ad62
JB
16543#undef NUF
16544#undef nUF
16545#undef NCE
16546#undef nCE
c19d1205
ZW
16547#undef OPS0
16548#undef OPS1
16549#undef OPS2
16550#undef OPS3
16551#undef OPS4
16552#undef OPS5
16553#undef OPS6
16554#undef do_0
16555\f
16556/* MD interface: bits in the object file. */
bfae80f2 16557
c19d1205
ZW
16558/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16559 for use in the a.out file, and stores them in the array pointed to by buf.
16560 This knows about the endian-ness of the target machine and does
16561 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16562 2 (short) and 4 (long) Floating numbers are put out as a series of
16563 LITTLENUMS (shorts, here at least). */
b99bd4ef 16564
c19d1205
ZW
16565void
16566md_number_to_chars (char * buf, valueT val, int n)
16567{
16568 if (target_big_endian)
16569 number_to_chars_bigendian (buf, val, n);
16570 else
16571 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16572}
16573
c19d1205
ZW
16574static valueT
16575md_chars_to_number (char * buf, int n)
bfae80f2 16576{
c19d1205
ZW
16577 valueT result = 0;
16578 unsigned char * where = (unsigned char *) buf;
bfae80f2 16579
c19d1205 16580 if (target_big_endian)
b99bd4ef 16581 {
c19d1205
ZW
16582 while (n--)
16583 {
16584 result <<= 8;
16585 result |= (*where++ & 255);
16586 }
b99bd4ef 16587 }
c19d1205 16588 else
b99bd4ef 16589 {
c19d1205
ZW
16590 while (n--)
16591 {
16592 result <<= 8;
16593 result |= (where[n] & 255);
16594 }
bfae80f2 16595 }
b99bd4ef 16596
c19d1205 16597 return result;
bfae80f2 16598}
b99bd4ef 16599
c19d1205 16600/* MD interface: Sections. */
b99bd4ef 16601
0110f2b8
PB
16602/* Estimate the size of a frag before relaxing. Assume everything fits in
16603 2 bytes. */
16604
c19d1205 16605int
0110f2b8 16606md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16607 segT segtype ATTRIBUTE_UNUSED)
16608{
0110f2b8
PB
16609 fragp->fr_var = 2;
16610 return 2;
16611}
16612
16613/* Convert a machine dependent frag. */
16614
16615void
16616md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16617{
16618 unsigned long insn;
16619 unsigned long old_op;
16620 char *buf;
16621 expressionS exp;
16622 fixS *fixp;
16623 int reloc_type;
16624 int pc_rel;
16625 int opcode;
16626
16627 buf = fragp->fr_literal + fragp->fr_fix;
16628
16629 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
16630 if (fragp->fr_symbol)
16631 {
0110f2b8
PB
16632 exp.X_op = O_symbol;
16633 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
16634 }
16635 else
16636 {
0110f2b8 16637 exp.X_op = O_constant;
5f4273c7 16638 }
0110f2b8
PB
16639 exp.X_add_number = fragp->fr_offset;
16640 opcode = fragp->fr_subtype;
16641 switch (opcode)
16642 {
16643 case T_MNEM_ldr_pc:
16644 case T_MNEM_ldr_pc2:
16645 case T_MNEM_ldr_sp:
16646 case T_MNEM_str_sp:
16647 case T_MNEM_ldr:
16648 case T_MNEM_ldrb:
16649 case T_MNEM_ldrh:
16650 case T_MNEM_str:
16651 case T_MNEM_strb:
16652 case T_MNEM_strh:
16653 if (fragp->fr_var == 4)
16654 {
5f4273c7 16655 insn = THUMB_OP32 (opcode);
0110f2b8
PB
16656 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16657 {
16658 insn |= (old_op & 0x700) << 4;
16659 }
16660 else
16661 {
16662 insn |= (old_op & 7) << 12;
16663 insn |= (old_op & 0x38) << 13;
16664 }
16665 insn |= 0x00000c00;
16666 put_thumb32_insn (buf, insn);
16667 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16668 }
16669 else
16670 {
16671 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16672 }
16673 pc_rel = (opcode == T_MNEM_ldr_pc2);
16674 break;
16675 case T_MNEM_adr:
16676 if (fragp->fr_var == 4)
16677 {
16678 insn = THUMB_OP32 (opcode);
16679 insn |= (old_op & 0xf0) << 4;
16680 put_thumb32_insn (buf, insn);
16681 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16682 }
16683 else
16684 {
16685 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16686 exp.X_add_number -= 4;
16687 }
16688 pc_rel = 1;
16689 break;
16690 case T_MNEM_mov:
16691 case T_MNEM_movs:
16692 case T_MNEM_cmp:
16693 case T_MNEM_cmn:
16694 if (fragp->fr_var == 4)
16695 {
16696 int r0off = (opcode == T_MNEM_mov
16697 || opcode == T_MNEM_movs) ? 0 : 8;
16698 insn = THUMB_OP32 (opcode);
16699 insn = (insn & 0xe1ffffff) | 0x10000000;
16700 insn |= (old_op & 0x700) << r0off;
16701 put_thumb32_insn (buf, insn);
16702 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16703 }
16704 else
16705 {
16706 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16707 }
16708 pc_rel = 0;
16709 break;
16710 case T_MNEM_b:
16711 if (fragp->fr_var == 4)
16712 {
16713 insn = THUMB_OP32(opcode);
16714 put_thumb32_insn (buf, insn);
16715 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16716 }
16717 else
16718 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16719 pc_rel = 1;
16720 break;
16721 case T_MNEM_bcond:
16722 if (fragp->fr_var == 4)
16723 {
16724 insn = THUMB_OP32(opcode);
16725 insn |= (old_op & 0xf00) << 14;
16726 put_thumb32_insn (buf, insn);
16727 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16728 }
16729 else
16730 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16731 pc_rel = 1;
16732 break;
16733 case T_MNEM_add_sp:
16734 case T_MNEM_add_pc:
16735 case T_MNEM_inc_sp:
16736 case T_MNEM_dec_sp:
16737 if (fragp->fr_var == 4)
16738 {
16739 /* ??? Choose between add and addw. */
16740 insn = THUMB_OP32 (opcode);
16741 insn |= (old_op & 0xf0) << 4;
16742 put_thumb32_insn (buf, insn);
16805f35
PB
16743 if (opcode == T_MNEM_add_pc)
16744 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16745 else
16746 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16747 }
16748 else
16749 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16750 pc_rel = 0;
16751 break;
16752
16753 case T_MNEM_addi:
16754 case T_MNEM_addis:
16755 case T_MNEM_subi:
16756 case T_MNEM_subis:
16757 if (fragp->fr_var == 4)
16758 {
16759 insn = THUMB_OP32 (opcode);
16760 insn |= (old_op & 0xf0) << 4;
16761 insn |= (old_op & 0xf) << 16;
16762 put_thumb32_insn (buf, insn);
16805f35
PB
16763 if (insn & (1 << 20))
16764 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16765 else
16766 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16767 }
16768 else
16769 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16770 pc_rel = 0;
16771 break;
16772 default:
5f4273c7 16773 abort ();
0110f2b8
PB
16774 }
16775 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16776 reloc_type);
16777 fixp->fx_file = fragp->fr_file;
16778 fixp->fx_line = fragp->fr_line;
16779 fragp->fr_fix += fragp->fr_var;
16780}
16781
16782/* Return the size of a relaxable immediate operand instruction.
16783 SHIFT and SIZE specify the form of the allowable immediate. */
16784static int
16785relax_immediate (fragS *fragp, int size, int shift)
16786{
16787 offsetT offset;
16788 offsetT mask;
16789 offsetT low;
16790
16791 /* ??? Should be able to do better than this. */
16792 if (fragp->fr_symbol)
16793 return 4;
16794
16795 low = (1 << shift) - 1;
16796 mask = (1 << (shift + size)) - (1 << shift);
16797 offset = fragp->fr_offset;
16798 /* Force misaligned offsets to 32-bit variant. */
16799 if (offset & low)
5e77afaa 16800 return 4;
0110f2b8
PB
16801 if (offset & ~mask)
16802 return 4;
16803 return 2;
16804}
16805
5e77afaa
PB
16806/* Get the address of a symbol during relaxation. */
16807static addressT
5f4273c7 16808relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
16809{
16810 fragS *sym_frag;
16811 addressT addr;
16812 symbolS *sym;
16813
16814 sym = fragp->fr_symbol;
16815 sym_frag = symbol_get_frag (sym);
16816 know (S_GET_SEGMENT (sym) != absolute_section
16817 || sym_frag == &zero_address_frag);
16818 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16819
16820 /* If frag has yet to be reached on this pass, assume it will
16821 move by STRETCH just as we did. If this is not so, it will
16822 be because some frag between grows, and that will force
16823 another pass. */
16824
16825 if (stretch != 0
16826 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
16827 {
16828 fragS *f;
16829
16830 /* Adjust stretch for any alignment frag. Note that if have
16831 been expanding the earlier code, the symbol may be
16832 defined in what appears to be an earlier frag. FIXME:
16833 This doesn't handle the fr_subtype field, which specifies
16834 a maximum number of bytes to skip when doing an
16835 alignment. */
16836 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16837 {
16838 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16839 {
16840 if (stretch < 0)
16841 stretch = - ((- stretch)
16842 & ~ ((1 << (int) f->fr_offset) - 1));
16843 else
16844 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16845 if (stretch == 0)
16846 break;
16847 }
16848 }
16849 if (f != NULL)
16850 addr += stretch;
16851 }
5e77afaa
PB
16852
16853 return addr;
16854}
16855
0110f2b8
PB
16856/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16857 load. */
16858static int
5e77afaa 16859relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16860{
16861 addressT addr;
16862 offsetT val;
16863
16864 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16865 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16866 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16867 return 4;
16868
5f4273c7 16869 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16870 addr = fragp->fr_address + fragp->fr_fix;
16871 addr = (addr + 4) & ~3;
5e77afaa 16872 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16873 if (val & 3)
5e77afaa 16874 return 4;
0110f2b8
PB
16875 val -= addr;
16876 if (val < 0 || val > 1020)
16877 return 4;
16878 return 2;
16879}
16880
16881/* Return the size of a relaxable add/sub immediate instruction. */
16882static int
16883relax_addsub (fragS *fragp, asection *sec)
16884{
16885 char *buf;
16886 int op;
16887
16888 buf = fragp->fr_literal + fragp->fr_fix;
16889 op = bfd_get_16(sec->owner, buf);
16890 if ((op & 0xf) == ((op >> 4) & 0xf))
16891 return relax_immediate (fragp, 8, 0);
16892 else
16893 return relax_immediate (fragp, 3, 0);
16894}
16895
16896
16897/* Return the size of a relaxable branch instruction. BITS is the
16898 size of the offset field in the narrow instruction. */
16899
16900static int
5e77afaa 16901relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16902{
16903 addressT addr;
16904 offsetT val;
16905 offsetT limit;
16906
16907 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16908 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16909 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16910 return 4;
16911
5f4273c7 16912 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16913 addr = fragp->fr_address + fragp->fr_fix + 4;
16914 val -= addr;
16915
16916 /* Offset is a signed value *2 */
16917 limit = 1 << bits;
16918 if (val >= limit || val < -limit)
16919 return 4;
16920 return 2;
16921}
16922
16923
16924/* Relax a machine dependent frag. This returns the amount by which
16925 the current size of the frag should change. */
16926
16927int
5e77afaa 16928arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16929{
16930 int oldsize;
16931 int newsize;
16932
16933 oldsize = fragp->fr_var;
16934 switch (fragp->fr_subtype)
16935 {
16936 case T_MNEM_ldr_pc2:
5f4273c7 16937 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16938 break;
16939 case T_MNEM_ldr_pc:
16940 case T_MNEM_ldr_sp:
16941 case T_MNEM_str_sp:
5f4273c7 16942 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
16943 break;
16944 case T_MNEM_ldr:
16945 case T_MNEM_str:
5f4273c7 16946 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
16947 break;
16948 case T_MNEM_ldrh:
16949 case T_MNEM_strh:
5f4273c7 16950 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
16951 break;
16952 case T_MNEM_ldrb:
16953 case T_MNEM_strb:
5f4273c7 16954 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
16955 break;
16956 case T_MNEM_adr:
5f4273c7 16957 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16958 break;
16959 case T_MNEM_mov:
16960 case T_MNEM_movs:
16961 case T_MNEM_cmp:
16962 case T_MNEM_cmn:
5f4273c7 16963 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
16964 break;
16965 case T_MNEM_b:
5f4273c7 16966 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
16967 break;
16968 case T_MNEM_bcond:
5f4273c7 16969 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
16970 break;
16971 case T_MNEM_add_sp:
16972 case T_MNEM_add_pc:
16973 newsize = relax_immediate (fragp, 8, 2);
16974 break;
16975 case T_MNEM_inc_sp:
16976 case T_MNEM_dec_sp:
16977 newsize = relax_immediate (fragp, 7, 2);
16978 break;
16979 case T_MNEM_addi:
16980 case T_MNEM_addis:
16981 case T_MNEM_subi:
16982 case T_MNEM_subis:
16983 newsize = relax_addsub (fragp, sec);
16984 break;
16985 default:
5f4273c7 16986 abort ();
0110f2b8 16987 }
5e77afaa
PB
16988
16989 fragp->fr_var = newsize;
16990 /* Freeze wide instructions that are at or before the same location as
16991 in the previous pass. This avoids infinite loops.
5f4273c7
NC
16992 Don't freeze them unconditionally because targets may be artificially
16993 misaligned by the expansion of preceding frags. */
5e77afaa 16994 if (stretch <= 0 && newsize > 2)
0110f2b8 16995 {
0110f2b8 16996 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 16997 frag_wane (fragp);
0110f2b8 16998 }
5e77afaa 16999
0110f2b8 17000 return newsize - oldsize;
c19d1205 17001}
b99bd4ef 17002
c19d1205 17003/* Round up a section size to the appropriate boundary. */
b99bd4ef 17004
c19d1205
ZW
17005valueT
17006md_section_align (segT segment ATTRIBUTE_UNUSED,
17007 valueT size)
17008{
f0927246
NC
17009#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17010 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17011 {
17012 /* For a.out, force the section size to be aligned. If we don't do
17013 this, BFD will align it for us, but it will not write out the
17014 final bytes of the section. This may be a bug in BFD, but it is
17015 easier to fix it here since that is how the other a.out targets
17016 work. */
17017 int align;
17018
17019 align = bfd_get_section_alignment (stdoutput, segment);
17020 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17021 }
c19d1205 17022#endif
f0927246
NC
17023
17024 return size;
bfae80f2 17025}
b99bd4ef 17026
c19d1205
ZW
17027/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17028 of an rs_align_code fragment. */
17029
17030void
17031arm_handle_align (fragS * fragP)
bfae80f2 17032{
c19d1205
ZW
17033 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17034 static char const thumb_noop[2] = { 0xc0, 0x46 };
17035 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17036 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17037
17038 int bytes, fix, noop_size;
17039 char * p;
17040 const char * noop;
bfae80f2 17041
c19d1205 17042 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17043 return;
17044
c19d1205
ZW
17045 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17046 p = fragP->fr_literal + fragP->fr_fix;
17047 fix = 0;
bfae80f2 17048
c19d1205
ZW
17049 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17050 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17051
c19d1205 17052 if (fragP->tc_frag_data)
a737bd4d 17053 {
c19d1205
ZW
17054 if (target_big_endian)
17055 noop = thumb_bigend_noop;
17056 else
17057 noop = thumb_noop;
17058 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17059 }
17060 else
17061 {
c19d1205
ZW
17062 if (target_big_endian)
17063 noop = arm_bigend_noop;
17064 else
17065 noop = arm_noop;
17066 noop_size = sizeof (arm_noop);
7ed4c4c5 17067 }
a737bd4d 17068
c19d1205 17069 if (bytes & (noop_size - 1))
7ed4c4c5 17070 {
c19d1205
ZW
17071 fix = bytes & (noop_size - 1);
17072 memset (p, 0, fix);
17073 p += fix;
17074 bytes -= fix;
a737bd4d 17075 }
a737bd4d 17076
c19d1205 17077 while (bytes >= noop_size)
a737bd4d 17078 {
c19d1205
ZW
17079 memcpy (p, noop, noop_size);
17080 p += noop_size;
17081 bytes -= noop_size;
17082 fix += noop_size;
a737bd4d
NC
17083 }
17084
c19d1205
ZW
17085 fragP->fr_fix += fix;
17086 fragP->fr_var = noop_size;
a737bd4d
NC
17087}
17088
c19d1205
ZW
17089/* Called from md_do_align. Used to create an alignment
17090 frag in a code section. */
17091
17092void
17093arm_frag_align_code (int n, int max)
bfae80f2 17094{
c19d1205 17095 char * p;
7ed4c4c5 17096
c19d1205
ZW
17097 /* We assume that there will never be a requirement
17098 to support alignments greater than 32 bytes. */
17099 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17100 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17101
c19d1205
ZW
17102 p = frag_var (rs_align_code,
17103 MAX_MEM_FOR_RS_ALIGN_CODE,
17104 1,
17105 (relax_substateT) max,
17106 (symbolS *) NULL,
17107 (offsetT) n,
17108 (char *) NULL);
17109 *p = 0;
17110}
bfae80f2 17111
c19d1205 17112/* Perform target specific initialisation of a frag. */
bfae80f2 17113
c19d1205
ZW
17114void
17115arm_init_frag (fragS * fragP)
17116{
17117 /* Record whether this frag is in an ARM or a THUMB area. */
17118 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17119}
17120
c19d1205
ZW
17121#ifdef OBJ_ELF
17122/* When we change sections we need to issue a new mapping symbol. */
17123
17124void
17125arm_elf_change_section (void)
bfae80f2 17126{
c19d1205
ZW
17127 flagword flags;
17128 segment_info_type *seginfo;
bfae80f2 17129
c19d1205
ZW
17130 /* Link an unlinked unwind index table section to the .text section. */
17131 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17132 && elf_linked_to_section (now_seg) == NULL)
17133 elf_linked_to_section (now_seg) = text_section;
17134
17135 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17136 return;
17137
c19d1205
ZW
17138 flags = bfd_get_section_flags (stdoutput, now_seg);
17139
17140 /* We can ignore sections that only contain debug info. */
17141 if ((flags & SEC_ALLOC) == 0)
17142 return;
bfae80f2 17143
c19d1205
ZW
17144 seginfo = seg_info (now_seg);
17145 mapstate = seginfo->tc_segment_info_data.mapstate;
17146 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17147}
17148
c19d1205
ZW
17149int
17150arm_elf_section_type (const char * str, size_t len)
e45d0630 17151{
c19d1205
ZW
17152 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17153 return SHT_ARM_EXIDX;
e45d0630 17154
c19d1205
ZW
17155 return -1;
17156}
17157\f
17158/* Code to deal with unwinding tables. */
e45d0630 17159
c19d1205 17160static void add_unwind_adjustsp (offsetT);
e45d0630 17161
5f4273c7 17162/* Generate any deferred unwind frame offset. */
e45d0630 17163
bfae80f2 17164static void
c19d1205 17165flush_pending_unwind (void)
bfae80f2 17166{
c19d1205 17167 offsetT offset;
bfae80f2 17168
c19d1205
ZW
17169 offset = unwind.pending_offset;
17170 unwind.pending_offset = 0;
17171 if (offset != 0)
17172 add_unwind_adjustsp (offset);
bfae80f2
RE
17173}
17174
c19d1205
ZW
17175/* Add an opcode to this list for this function. Two-byte opcodes should
17176 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17177 order. */
17178
bfae80f2 17179static void
c19d1205 17180add_unwind_opcode (valueT op, int length)
bfae80f2 17181{
c19d1205
ZW
17182 /* Add any deferred stack adjustment. */
17183 if (unwind.pending_offset)
17184 flush_pending_unwind ();
bfae80f2 17185
c19d1205 17186 unwind.sp_restored = 0;
bfae80f2 17187
c19d1205 17188 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17189 {
c19d1205
ZW
17190 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17191 if (unwind.opcodes)
17192 unwind.opcodes = xrealloc (unwind.opcodes,
17193 unwind.opcode_alloc);
17194 else
17195 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17196 }
c19d1205 17197 while (length > 0)
bfae80f2 17198 {
c19d1205
ZW
17199 length--;
17200 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17201 op >>= 8;
17202 unwind.opcode_count++;
bfae80f2 17203 }
bfae80f2
RE
17204}
17205
c19d1205
ZW
17206/* Add unwind opcodes to adjust the stack pointer. */
17207
bfae80f2 17208static void
c19d1205 17209add_unwind_adjustsp (offsetT offset)
bfae80f2 17210{
c19d1205 17211 valueT op;
bfae80f2 17212
c19d1205 17213 if (offset > 0x200)
bfae80f2 17214 {
c19d1205
ZW
17215 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17216 char bytes[5];
17217 int n;
17218 valueT o;
bfae80f2 17219
c19d1205
ZW
17220 /* Long form: 0xb2, uleb128. */
17221 /* This might not fit in a word so add the individual bytes,
17222 remembering the list is built in reverse order. */
17223 o = (valueT) ((offset - 0x204) >> 2);
17224 if (o == 0)
17225 add_unwind_opcode (0, 1);
bfae80f2 17226
c19d1205
ZW
17227 /* Calculate the uleb128 encoding of the offset. */
17228 n = 0;
17229 while (o)
17230 {
17231 bytes[n] = o & 0x7f;
17232 o >>= 7;
17233 if (o)
17234 bytes[n] |= 0x80;
17235 n++;
17236 }
17237 /* Add the insn. */
17238 for (; n; n--)
17239 add_unwind_opcode (bytes[n - 1], 1);
17240 add_unwind_opcode (0xb2, 1);
17241 }
17242 else if (offset > 0x100)
bfae80f2 17243 {
c19d1205
ZW
17244 /* Two short opcodes. */
17245 add_unwind_opcode (0x3f, 1);
17246 op = (offset - 0x104) >> 2;
17247 add_unwind_opcode (op, 1);
bfae80f2 17248 }
c19d1205
ZW
17249 else if (offset > 0)
17250 {
17251 /* Short opcode. */
17252 op = (offset - 4) >> 2;
17253 add_unwind_opcode (op, 1);
17254 }
17255 else if (offset < 0)
bfae80f2 17256 {
c19d1205
ZW
17257 offset = -offset;
17258 while (offset > 0x100)
bfae80f2 17259 {
c19d1205
ZW
17260 add_unwind_opcode (0x7f, 1);
17261 offset -= 0x100;
bfae80f2 17262 }
c19d1205
ZW
17263 op = ((offset - 4) >> 2) | 0x40;
17264 add_unwind_opcode (op, 1);
bfae80f2 17265 }
bfae80f2
RE
17266}
17267
c19d1205
ZW
17268/* Finish the list of unwind opcodes for this function. */
17269static void
17270finish_unwind_opcodes (void)
bfae80f2 17271{
c19d1205 17272 valueT op;
bfae80f2 17273
c19d1205 17274 if (unwind.fp_used)
bfae80f2 17275 {
708587a4 17276 /* Adjust sp as necessary. */
c19d1205
ZW
17277 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17278 flush_pending_unwind ();
bfae80f2 17279
c19d1205
ZW
17280 /* After restoring sp from the frame pointer. */
17281 op = 0x90 | unwind.fp_reg;
17282 add_unwind_opcode (op, 1);
17283 }
17284 else
17285 flush_pending_unwind ();
bfae80f2
RE
17286}
17287
bfae80f2 17288
c19d1205
ZW
17289/* Start an exception table entry. If idx is nonzero this is an index table
17290 entry. */
bfae80f2
RE
17291
17292static void
c19d1205 17293start_unwind_section (const segT text_seg, int idx)
bfae80f2 17294{
c19d1205
ZW
17295 const char * text_name;
17296 const char * prefix;
17297 const char * prefix_once;
17298 const char * group_name;
17299 size_t prefix_len;
17300 size_t text_len;
17301 char * sec_name;
17302 size_t sec_name_len;
17303 int type;
17304 int flags;
17305 int linkonce;
bfae80f2 17306
c19d1205 17307 if (idx)
bfae80f2 17308 {
c19d1205
ZW
17309 prefix = ELF_STRING_ARM_unwind;
17310 prefix_once = ELF_STRING_ARM_unwind_once;
17311 type = SHT_ARM_EXIDX;
bfae80f2 17312 }
c19d1205 17313 else
bfae80f2 17314 {
c19d1205
ZW
17315 prefix = ELF_STRING_ARM_unwind_info;
17316 prefix_once = ELF_STRING_ARM_unwind_info_once;
17317 type = SHT_PROGBITS;
bfae80f2
RE
17318 }
17319
c19d1205
ZW
17320 text_name = segment_name (text_seg);
17321 if (streq (text_name, ".text"))
17322 text_name = "";
17323
17324 if (strncmp (text_name, ".gnu.linkonce.t.",
17325 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17326 {
c19d1205
ZW
17327 prefix = prefix_once;
17328 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17329 }
17330
c19d1205
ZW
17331 prefix_len = strlen (prefix);
17332 text_len = strlen (text_name);
17333 sec_name_len = prefix_len + text_len;
17334 sec_name = xmalloc (sec_name_len + 1);
17335 memcpy (sec_name, prefix, prefix_len);
17336 memcpy (sec_name + prefix_len, text_name, text_len);
17337 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17338
c19d1205
ZW
17339 flags = SHF_ALLOC;
17340 linkonce = 0;
17341 group_name = 0;
bfae80f2 17342
c19d1205
ZW
17343 /* Handle COMDAT group. */
17344 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17345 {
c19d1205
ZW
17346 group_name = elf_group_name (text_seg);
17347 if (group_name == NULL)
17348 {
bd3ba5d1 17349 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17350 segment_name (text_seg));
17351 ignore_rest_of_line ();
17352 return;
17353 }
17354 flags |= SHF_GROUP;
17355 linkonce = 1;
bfae80f2
RE
17356 }
17357
c19d1205 17358 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17359
5f4273c7 17360 /* Set the section link for index tables. */
c19d1205
ZW
17361 if (idx)
17362 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17363}
17364
bfae80f2 17365
c19d1205
ZW
17366/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17367 personality routine data. Returns zero, or the index table value for
17368 and inline entry. */
17369
17370static valueT
17371create_unwind_entry (int have_data)
bfae80f2 17372{
c19d1205
ZW
17373 int size;
17374 addressT where;
17375 char *ptr;
17376 /* The current word of data. */
17377 valueT data;
17378 /* The number of bytes left in this word. */
17379 int n;
bfae80f2 17380
c19d1205 17381 finish_unwind_opcodes ();
bfae80f2 17382
c19d1205
ZW
17383 /* Remember the current text section. */
17384 unwind.saved_seg = now_seg;
17385 unwind.saved_subseg = now_subseg;
bfae80f2 17386
c19d1205 17387 start_unwind_section (now_seg, 0);
bfae80f2 17388
c19d1205 17389 if (unwind.personality_routine == NULL)
bfae80f2 17390 {
c19d1205
ZW
17391 if (unwind.personality_index == -2)
17392 {
17393 if (have_data)
5f4273c7 17394 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17395 return 1; /* EXIDX_CANTUNWIND. */
17396 }
bfae80f2 17397
c19d1205
ZW
17398 /* Use a default personality routine if none is specified. */
17399 if (unwind.personality_index == -1)
17400 {
17401 if (unwind.opcode_count > 3)
17402 unwind.personality_index = 1;
17403 else
17404 unwind.personality_index = 0;
17405 }
bfae80f2 17406
c19d1205
ZW
17407 /* Space for the personality routine entry. */
17408 if (unwind.personality_index == 0)
17409 {
17410 if (unwind.opcode_count > 3)
17411 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17412
c19d1205
ZW
17413 if (!have_data)
17414 {
17415 /* All the data is inline in the index table. */
17416 data = 0x80;
17417 n = 3;
17418 while (unwind.opcode_count > 0)
17419 {
17420 unwind.opcode_count--;
17421 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17422 n--;
17423 }
bfae80f2 17424
c19d1205
ZW
17425 /* Pad with "finish" opcodes. */
17426 while (n--)
17427 data = (data << 8) | 0xb0;
bfae80f2 17428
c19d1205
ZW
17429 return data;
17430 }
17431 size = 0;
17432 }
17433 else
17434 /* We get two opcodes "free" in the first word. */
17435 size = unwind.opcode_count - 2;
17436 }
17437 else
17438 /* An extra byte is required for the opcode count. */
17439 size = unwind.opcode_count + 1;
bfae80f2 17440
c19d1205
ZW
17441 size = (size + 3) >> 2;
17442 if (size > 0xff)
17443 as_bad (_("too many unwind opcodes"));
bfae80f2 17444
c19d1205
ZW
17445 frag_align (2, 0, 0);
17446 record_alignment (now_seg, 2);
17447 unwind.table_entry = expr_build_dot ();
17448
17449 /* Allocate the table entry. */
17450 ptr = frag_more ((size << 2) + 4);
17451 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17452
c19d1205 17453 switch (unwind.personality_index)
bfae80f2 17454 {
c19d1205
ZW
17455 case -1:
17456 /* ??? Should this be a PLT generating relocation? */
17457 /* Custom personality routine. */
17458 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17459 BFD_RELOC_ARM_PREL31);
bfae80f2 17460
c19d1205
ZW
17461 where += 4;
17462 ptr += 4;
bfae80f2 17463
c19d1205
ZW
17464 /* Set the first byte to the number of additional words. */
17465 data = size - 1;
17466 n = 3;
17467 break;
bfae80f2 17468
c19d1205
ZW
17469 /* ABI defined personality routines. */
17470 case 0:
17471 /* Three opcodes bytes are packed into the first word. */
17472 data = 0x80;
17473 n = 3;
17474 break;
bfae80f2 17475
c19d1205
ZW
17476 case 1:
17477 case 2:
17478 /* The size and first two opcode bytes go in the first word. */
17479 data = ((0x80 + unwind.personality_index) << 8) | size;
17480 n = 2;
17481 break;
bfae80f2 17482
c19d1205
ZW
17483 default:
17484 /* Should never happen. */
17485 abort ();
17486 }
bfae80f2 17487
c19d1205
ZW
17488 /* Pack the opcodes into words (MSB first), reversing the list at the same
17489 time. */
17490 while (unwind.opcode_count > 0)
17491 {
17492 if (n == 0)
17493 {
17494 md_number_to_chars (ptr, data, 4);
17495 ptr += 4;
17496 n = 4;
17497 data = 0;
17498 }
17499 unwind.opcode_count--;
17500 n--;
17501 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17502 }
17503
17504 /* Finish off the last word. */
17505 if (n < 4)
17506 {
17507 /* Pad with "finish" opcodes. */
17508 while (n--)
17509 data = (data << 8) | 0xb0;
17510
17511 md_number_to_chars (ptr, data, 4);
17512 }
17513
17514 if (!have_data)
17515 {
17516 /* Add an empty descriptor if there is no user-specified data. */
17517 ptr = frag_more (4);
17518 md_number_to_chars (ptr, 0, 4);
17519 }
17520
17521 return 0;
bfae80f2
RE
17522}
17523
f0927246
NC
17524
17525/* Initialize the DWARF-2 unwind information for this procedure. */
17526
17527void
17528tc_arm_frame_initial_instructions (void)
17529{
17530 cfi_add_CFA_def_cfa (REG_SP, 0);
17531}
17532#endif /* OBJ_ELF */
17533
c19d1205
ZW
17534/* Convert REGNAME to a DWARF-2 register number. */
17535
17536int
1df69f4f 17537tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17538{
1df69f4f 17539 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17540
17541 if (reg == FAIL)
17542 return -1;
17543
17544 return reg;
bfae80f2
RE
17545}
17546
f0927246 17547#ifdef TE_PE
c19d1205 17548void
f0927246 17549tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17550{
f0927246 17551 expressionS expr;
bfae80f2 17552
f0927246
NC
17553 expr.X_op = O_secrel;
17554 expr.X_add_symbol = symbol;
17555 expr.X_add_number = 0;
17556 emit_expr (&expr, size);
17557}
17558#endif
bfae80f2 17559
c19d1205 17560/* MD interface: Symbol and relocation handling. */
bfae80f2 17561
2fc8bdac
ZW
17562/* Return the address within the segment that a PC-relative fixup is
17563 relative to. For ARM, PC-relative fixups applied to instructions
17564 are generally relative to the location of the fixup plus 8 bytes.
17565 Thumb branches are offset by 4, and Thumb loads relative to PC
17566 require special handling. */
bfae80f2 17567
c19d1205 17568long
2fc8bdac 17569md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17570{
2fc8bdac
ZW
17571 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17572
17573 /* If this is pc-relative and we are going to emit a relocation
17574 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17575 will need. Otherwise we want to use the calculated base.
17576 For WinCE we skip the bias for externals as well, since this
17577 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 17578 if (fixP->fx_pcrel
2fc8bdac 17579 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17580 || (arm_force_relocation (fixP)
17581#ifdef TE_WINCE
17582 && !S_IS_EXTERNAL (fixP->fx_addsy)
17583#endif
17584 )))
2fc8bdac 17585 base = 0;
bfae80f2 17586
c19d1205 17587 switch (fixP->fx_r_type)
bfae80f2 17588 {
2fc8bdac
ZW
17589 /* PC relative addressing on the Thumb is slightly odd as the
17590 bottom two bits of the PC are forced to zero for the
17591 calculation. This happens *after* application of the
17592 pipeline offset. However, Thumb adrl already adjusts for
17593 this, so we need not do it again. */
c19d1205 17594 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17595 return base & ~3;
c19d1205
ZW
17596
17597 case BFD_RELOC_ARM_THUMB_OFFSET:
17598 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17599 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17600 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17601 return (base + 4) & ~3;
c19d1205 17602
2fc8bdac
ZW
17603 /* Thumb branches are simply offset by +4. */
17604 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17605 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17606 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17607 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17608 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17609 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17610 case BFD_RELOC_THUMB_PCREL_BLX:
17611 return base + 4;
bfae80f2 17612
2fc8bdac
ZW
17613 /* ARM mode branches are offset by +8. However, the Windows CE
17614 loader expects the relocation not to take this into account. */
17615 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17616 case BFD_RELOC_ARM_PCREL_CALL:
17617 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17618 case BFD_RELOC_ARM_PCREL_BLX:
17619 case BFD_RELOC_ARM_PLT32:
c19d1205 17620#ifdef TE_WINCE
5f4273c7 17621 /* When handling fixups immediately, because we have already
53baae48
NC
17622 discovered the value of a symbol, or the address of the frag involved
17623 we must account for the offset by +8, as the OS loader will never see the reloc.
17624 see fixup_segment() in write.c
17625 The S_IS_EXTERNAL test handles the case of global symbols.
17626 Those need the calculated base, not just the pipe compensation the linker will need. */
17627 if (fixP->fx_pcrel
17628 && fixP->fx_addsy != NULL
17629 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17630 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17631 return base + 8;
2fc8bdac 17632 return base;
c19d1205 17633#else
2fc8bdac 17634 return base + 8;
c19d1205 17635#endif
2fc8bdac
ZW
17636
17637 /* ARM mode loads relative to PC are also offset by +8. Unlike
17638 branches, the Windows CE loader *does* expect the relocation
17639 to take this into account. */
17640 case BFD_RELOC_ARM_OFFSET_IMM:
17641 case BFD_RELOC_ARM_OFFSET_IMM8:
17642 case BFD_RELOC_ARM_HWLITERAL:
17643 case BFD_RELOC_ARM_LITERAL:
17644 case BFD_RELOC_ARM_CP_OFF_IMM:
17645 return base + 8;
17646
17647
17648 /* Other PC-relative relocations are un-offset. */
17649 default:
17650 return base;
17651 }
bfae80f2
RE
17652}
17653
c19d1205
ZW
17654/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17655 Otherwise we have no need to default values of symbols. */
17656
17657symbolS *
17658md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17659{
c19d1205
ZW
17660#ifdef OBJ_ELF
17661 if (name[0] == '_' && name[1] == 'G'
17662 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17663 {
17664 if (!GOT_symbol)
17665 {
17666 if (symbol_find (name))
bd3ba5d1 17667 as_bad (_("GOT already in the symbol table"));
bfae80f2 17668
c19d1205
ZW
17669 GOT_symbol = symbol_new (name, undefined_section,
17670 (valueT) 0, & zero_address_frag);
17671 }
bfae80f2 17672
c19d1205 17673 return GOT_symbol;
bfae80f2 17674 }
c19d1205 17675#endif
bfae80f2 17676
c19d1205 17677 return 0;
bfae80f2
RE
17678}
17679
55cf6793 17680/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17681 computed as two separate immediate values, added together. We
17682 already know that this value cannot be computed by just one ARM
17683 instruction. */
17684
17685static unsigned int
17686validate_immediate_twopart (unsigned int val,
17687 unsigned int * highpart)
bfae80f2 17688{
c19d1205
ZW
17689 unsigned int a;
17690 unsigned int i;
bfae80f2 17691
c19d1205
ZW
17692 for (i = 0; i < 32; i += 2)
17693 if (((a = rotate_left (val, i)) & 0xff) != 0)
17694 {
17695 if (a & 0xff00)
17696 {
17697 if (a & ~ 0xffff)
17698 continue;
17699 * highpart = (a >> 8) | ((i + 24) << 7);
17700 }
17701 else if (a & 0xff0000)
17702 {
17703 if (a & 0xff000000)
17704 continue;
17705 * highpart = (a >> 16) | ((i + 16) << 7);
17706 }
17707 else
17708 {
17709 assert (a & 0xff000000);
17710 * highpart = (a >> 24) | ((i + 8) << 7);
17711 }
bfae80f2 17712
c19d1205
ZW
17713 return (a & 0xff) | (i << 7);
17714 }
bfae80f2 17715
c19d1205 17716 return FAIL;
bfae80f2
RE
17717}
17718
c19d1205
ZW
17719static int
17720validate_offset_imm (unsigned int val, int hwse)
17721{
17722 if ((hwse && val > 255) || val > 4095)
17723 return FAIL;
17724 return val;
17725}
bfae80f2 17726
55cf6793 17727/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17728 negative immediate constant by altering the instruction. A bit of
17729 a hack really.
17730 MOV <-> MVN
17731 AND <-> BIC
17732 ADC <-> SBC
17733 by inverting the second operand, and
17734 ADD <-> SUB
17735 CMP <-> CMN
17736 by negating the second operand. */
bfae80f2 17737
c19d1205
ZW
17738static int
17739negate_data_op (unsigned long * instruction,
17740 unsigned long value)
bfae80f2 17741{
c19d1205
ZW
17742 int op, new_inst;
17743 unsigned long negated, inverted;
bfae80f2 17744
c19d1205
ZW
17745 negated = encode_arm_immediate (-value);
17746 inverted = encode_arm_immediate (~value);
bfae80f2 17747
c19d1205
ZW
17748 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17749 switch (op)
bfae80f2 17750 {
c19d1205
ZW
17751 /* First negates. */
17752 case OPCODE_SUB: /* ADD <-> SUB */
17753 new_inst = OPCODE_ADD;
17754 value = negated;
17755 break;
bfae80f2 17756
c19d1205
ZW
17757 case OPCODE_ADD:
17758 new_inst = OPCODE_SUB;
17759 value = negated;
17760 break;
bfae80f2 17761
c19d1205
ZW
17762 case OPCODE_CMP: /* CMP <-> CMN */
17763 new_inst = OPCODE_CMN;
17764 value = negated;
17765 break;
bfae80f2 17766
c19d1205
ZW
17767 case OPCODE_CMN:
17768 new_inst = OPCODE_CMP;
17769 value = negated;
17770 break;
bfae80f2 17771
c19d1205
ZW
17772 /* Now Inverted ops. */
17773 case OPCODE_MOV: /* MOV <-> MVN */
17774 new_inst = OPCODE_MVN;
17775 value = inverted;
17776 break;
bfae80f2 17777
c19d1205
ZW
17778 case OPCODE_MVN:
17779 new_inst = OPCODE_MOV;
17780 value = inverted;
17781 break;
bfae80f2 17782
c19d1205
ZW
17783 case OPCODE_AND: /* AND <-> BIC */
17784 new_inst = OPCODE_BIC;
17785 value = inverted;
17786 break;
bfae80f2 17787
c19d1205
ZW
17788 case OPCODE_BIC:
17789 new_inst = OPCODE_AND;
17790 value = inverted;
17791 break;
bfae80f2 17792
c19d1205
ZW
17793 case OPCODE_ADC: /* ADC <-> SBC */
17794 new_inst = OPCODE_SBC;
17795 value = inverted;
17796 break;
bfae80f2 17797
c19d1205
ZW
17798 case OPCODE_SBC:
17799 new_inst = OPCODE_ADC;
17800 value = inverted;
17801 break;
bfae80f2 17802
c19d1205
ZW
17803 /* We cannot do anything. */
17804 default:
17805 return FAIL;
b99bd4ef
NC
17806 }
17807
c19d1205
ZW
17808 if (value == (unsigned) FAIL)
17809 return FAIL;
17810
17811 *instruction &= OPCODE_MASK;
17812 *instruction |= new_inst << DATA_OP_SHIFT;
17813 return value;
b99bd4ef
NC
17814}
17815
ef8d22e6
PB
17816/* Like negate_data_op, but for Thumb-2. */
17817
17818static unsigned int
16dd5e42 17819thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17820{
17821 int op, new_inst;
17822 int rd;
16dd5e42 17823 unsigned int negated, inverted;
ef8d22e6
PB
17824
17825 negated = encode_thumb32_immediate (-value);
17826 inverted = encode_thumb32_immediate (~value);
17827
17828 rd = (*instruction >> 8) & 0xf;
17829 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17830 switch (op)
17831 {
17832 /* ADD <-> SUB. Includes CMP <-> CMN. */
17833 case T2_OPCODE_SUB:
17834 new_inst = T2_OPCODE_ADD;
17835 value = negated;
17836 break;
17837
17838 case T2_OPCODE_ADD:
17839 new_inst = T2_OPCODE_SUB;
17840 value = negated;
17841 break;
17842
17843 /* ORR <-> ORN. Includes MOV <-> MVN. */
17844 case T2_OPCODE_ORR:
17845 new_inst = T2_OPCODE_ORN;
17846 value = inverted;
17847 break;
17848
17849 case T2_OPCODE_ORN:
17850 new_inst = T2_OPCODE_ORR;
17851 value = inverted;
17852 break;
17853
17854 /* AND <-> BIC. TST has no inverted equivalent. */
17855 case T2_OPCODE_AND:
17856 new_inst = T2_OPCODE_BIC;
17857 if (rd == 15)
17858 value = FAIL;
17859 else
17860 value = inverted;
17861 break;
17862
17863 case T2_OPCODE_BIC:
17864 new_inst = T2_OPCODE_AND;
17865 value = inverted;
17866 break;
17867
17868 /* ADC <-> SBC */
17869 case T2_OPCODE_ADC:
17870 new_inst = T2_OPCODE_SBC;
17871 value = inverted;
17872 break;
17873
17874 case T2_OPCODE_SBC:
17875 new_inst = T2_OPCODE_ADC;
17876 value = inverted;
17877 break;
17878
17879 /* We cannot do anything. */
17880 default:
17881 return FAIL;
17882 }
17883
16dd5e42 17884 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17885 return FAIL;
17886
17887 *instruction &= T2_OPCODE_MASK;
17888 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17889 return value;
17890}
17891
8f06b2d8
PB
17892/* Read a 32-bit thumb instruction from buf. */
17893static unsigned long
17894get_thumb32_insn (char * buf)
17895{
17896 unsigned long insn;
17897 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17898 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17899
17900 return insn;
17901}
17902
a8bc6c78
PB
17903
17904/* We usually want to set the low bit on the address of thumb function
17905 symbols. In particular .word foo - . should have the low bit set.
17906 Generic code tries to fold the difference of two symbols to
17907 a constant. Prevent this and force a relocation when the first symbols
17908 is a thumb function. */
17909int
17910arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17911{
17912 if (op == O_subtract
17913 && l->X_op == O_symbol
17914 && r->X_op == O_symbol
17915 && THUMB_IS_FUNC (l->X_add_symbol))
17916 {
17917 l->X_op = O_subtract;
17918 l->X_op_symbol = r->X_add_symbol;
17919 l->X_add_number -= r->X_add_number;
17920 return 1;
17921 }
17922 /* Process as normal. */
17923 return 0;
17924}
17925
c19d1205 17926void
55cf6793 17927md_apply_fix (fixS * fixP,
c19d1205
ZW
17928 valueT * valP,
17929 segT seg)
17930{
17931 offsetT value = * valP;
17932 offsetT newval;
17933 unsigned int newimm;
17934 unsigned long temp;
17935 int sign;
17936 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17937
c19d1205 17938 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17939
c19d1205 17940 /* Note whether this will delete the relocation. */
4962c51a 17941
c19d1205
ZW
17942 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17943 fixP->fx_done = 1;
b99bd4ef 17944
adbaf948 17945 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 17946 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
17947 for emit_reloc. */
17948 value &= 0xffffffff;
17949 value ^= 0x80000000;
5f4273c7 17950 value -= 0x80000000;
adbaf948
ZW
17951
17952 *valP = value;
c19d1205 17953 fixP->fx_addnumber = value;
b99bd4ef 17954
adbaf948
ZW
17955 /* Same treatment for fixP->fx_offset. */
17956 fixP->fx_offset &= 0xffffffff;
17957 fixP->fx_offset ^= 0x80000000;
17958 fixP->fx_offset -= 0x80000000;
17959
c19d1205 17960 switch (fixP->fx_r_type)
b99bd4ef 17961 {
c19d1205
ZW
17962 case BFD_RELOC_NONE:
17963 /* This will need to go in the object file. */
17964 fixP->fx_done = 0;
17965 break;
b99bd4ef 17966
c19d1205
ZW
17967 case BFD_RELOC_ARM_IMMEDIATE:
17968 /* We claim that this fixup has been processed here,
17969 even if in fact we generate an error because we do
17970 not have a reloc for it, so tc_gen_reloc will reject it. */
17971 fixP->fx_done = 1;
b99bd4ef 17972
c19d1205
ZW
17973 if (fixP->fx_addsy
17974 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17975 {
c19d1205
ZW
17976 as_bad_where (fixP->fx_file, fixP->fx_line,
17977 _("undefined symbol %s used as an immediate value"),
17978 S_GET_NAME (fixP->fx_addsy));
17979 break;
b99bd4ef
NC
17980 }
17981
c19d1205
ZW
17982 newimm = encode_arm_immediate (value);
17983 temp = md_chars_to_number (buf, INSN_SIZE);
17984
17985 /* If the instruction will fail, see if we can fix things up by
17986 changing the opcode. */
17987 if (newimm == (unsigned int) FAIL
17988 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17989 {
c19d1205
ZW
17990 as_bad_where (fixP->fx_file, fixP->fx_line,
17991 _("invalid constant (%lx) after fixup"),
17992 (unsigned long) value);
17993 break;
b99bd4ef 17994 }
b99bd4ef 17995
c19d1205
ZW
17996 newimm |= (temp & 0xfffff000);
17997 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17998 break;
b99bd4ef 17999
c19d1205
ZW
18000 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18001 {
18002 unsigned int highpart = 0;
18003 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18004
c19d1205
ZW
18005 newimm = encode_arm_immediate (value);
18006 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18007
c19d1205
ZW
18008 /* If the instruction will fail, see if we can fix things up by
18009 changing the opcode. */
18010 if (newimm == (unsigned int) FAIL
18011 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18012 {
18013 /* No ? OK - try using two ADD instructions to generate
18014 the value. */
18015 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18016
c19d1205
ZW
18017 /* Yes - then make sure that the second instruction is
18018 also an add. */
18019 if (newimm != (unsigned int) FAIL)
18020 newinsn = temp;
18021 /* Still No ? Try using a negated value. */
18022 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18023 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18024 /* Otherwise - give up. */
18025 else
18026 {
18027 as_bad_where (fixP->fx_file, fixP->fx_line,
18028 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18029 (long) value);
18030 break;
18031 }
b99bd4ef 18032
c19d1205
ZW
18033 /* Replace the first operand in the 2nd instruction (which
18034 is the PC) with the destination register. We have
18035 already added in the PC in the first instruction and we
18036 do not want to do it again. */
18037 newinsn &= ~ 0xf0000;
18038 newinsn |= ((newinsn & 0x0f000) << 4);
18039 }
b99bd4ef 18040
c19d1205
ZW
18041 newimm |= (temp & 0xfffff000);
18042 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18043
c19d1205
ZW
18044 highpart |= (newinsn & 0xfffff000);
18045 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18046 }
18047 break;
b99bd4ef 18048
c19d1205 18049 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18050 if (!fixP->fx_done && seg->use_rela_p)
18051 value = 0;
18052
c19d1205
ZW
18053 case BFD_RELOC_ARM_LITERAL:
18054 sign = value >= 0;
b99bd4ef 18055
c19d1205
ZW
18056 if (value < 0)
18057 value = - value;
b99bd4ef 18058
c19d1205 18059 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18060 {
c19d1205
ZW
18061 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18062 as_bad_where (fixP->fx_file, fixP->fx_line,
18063 _("invalid literal constant: pool needs to be closer"));
18064 else
18065 as_bad_where (fixP->fx_file, fixP->fx_line,
18066 _("bad immediate value for offset (%ld)"),
18067 (long) value);
18068 break;
f03698e6
RE
18069 }
18070
c19d1205
ZW
18071 newval = md_chars_to_number (buf, INSN_SIZE);
18072 newval &= 0xff7ff000;
18073 newval |= value | (sign ? INDEX_UP : 0);
18074 md_number_to_chars (buf, newval, INSN_SIZE);
18075 break;
b99bd4ef 18076
c19d1205
ZW
18077 case BFD_RELOC_ARM_OFFSET_IMM8:
18078 case BFD_RELOC_ARM_HWLITERAL:
18079 sign = value >= 0;
b99bd4ef 18080
c19d1205
ZW
18081 if (value < 0)
18082 value = - value;
b99bd4ef 18083
c19d1205 18084 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18085 {
c19d1205
ZW
18086 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18087 as_bad_where (fixP->fx_file, fixP->fx_line,
18088 _("invalid literal constant: pool needs to be closer"));
18089 else
f9d4405b 18090 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18091 (long) value);
18092 break;
b99bd4ef
NC
18093 }
18094
c19d1205
ZW
18095 newval = md_chars_to_number (buf, INSN_SIZE);
18096 newval &= 0xff7ff0f0;
18097 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18098 md_number_to_chars (buf, newval, INSN_SIZE);
18099 break;
b99bd4ef 18100
c19d1205
ZW
18101 case BFD_RELOC_ARM_T32_OFFSET_U8:
18102 if (value < 0 || value > 1020 || value % 4 != 0)
18103 as_bad_where (fixP->fx_file, fixP->fx_line,
18104 _("bad immediate value for offset (%ld)"), (long) value);
18105 value /= 4;
b99bd4ef 18106
c19d1205 18107 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18108 newval |= value;
18109 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18110 break;
b99bd4ef 18111
c19d1205
ZW
18112 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18113 /* This is a complicated relocation used for all varieties of Thumb32
18114 load/store instruction with immediate offset:
18115
18116 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18117 *4, optional writeback(W)
18118 (doubleword load/store)
18119
18120 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18121 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18122 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18123 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18124 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18125
18126 Uppercase letters indicate bits that are already encoded at
18127 this point. Lowercase letters are our problem. For the
18128 second block of instructions, the secondary opcode nybble
18129 (bits 8..11) is present, and bit 23 is zero, even if this is
18130 a PC-relative operation. */
18131 newval = md_chars_to_number (buf, THUMB_SIZE);
18132 newval <<= 16;
18133 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18134
c19d1205 18135 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18136 {
c19d1205
ZW
18137 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18138 if (value >= 0)
18139 newval |= (1 << 23);
18140 else
18141 value = -value;
18142 if (value % 4 != 0)
18143 {
18144 as_bad_where (fixP->fx_file, fixP->fx_line,
18145 _("offset not a multiple of 4"));
18146 break;
18147 }
18148 value /= 4;
216d22bc 18149 if (value > 0xff)
c19d1205
ZW
18150 {
18151 as_bad_where (fixP->fx_file, fixP->fx_line,
18152 _("offset out of range"));
18153 break;
18154 }
18155 newval &= ~0xff;
b99bd4ef 18156 }
c19d1205 18157 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18158 {
c19d1205
ZW
18159 /* PC-relative, 12-bit offset. */
18160 if (value >= 0)
18161 newval |= (1 << 23);
18162 else
18163 value = -value;
216d22bc 18164 if (value > 0xfff)
c19d1205
ZW
18165 {
18166 as_bad_where (fixP->fx_file, fixP->fx_line,
18167 _("offset out of range"));
18168 break;
18169 }
18170 newval &= ~0xfff;
b99bd4ef 18171 }
c19d1205 18172 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18173 {
c19d1205
ZW
18174 /* Writeback: 8-bit, +/- offset. */
18175 if (value >= 0)
18176 newval |= (1 << 9);
18177 else
18178 value = -value;
216d22bc 18179 if (value > 0xff)
c19d1205
ZW
18180 {
18181 as_bad_where (fixP->fx_file, fixP->fx_line,
18182 _("offset out of range"));
18183 break;
18184 }
18185 newval &= ~0xff;
b99bd4ef 18186 }
c19d1205 18187 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18188 {
c19d1205 18189 /* T-instruction: positive 8-bit offset. */
216d22bc 18190 if (value < 0 || value > 0xff)
b99bd4ef 18191 {
c19d1205
ZW
18192 as_bad_where (fixP->fx_file, fixP->fx_line,
18193 _("offset out of range"));
18194 break;
b99bd4ef 18195 }
c19d1205
ZW
18196 newval &= ~0xff;
18197 newval |= value;
b99bd4ef
NC
18198 }
18199 else
b99bd4ef 18200 {
c19d1205
ZW
18201 /* Positive 12-bit or negative 8-bit offset. */
18202 int limit;
18203 if (value >= 0)
b99bd4ef 18204 {
c19d1205
ZW
18205 newval |= (1 << 23);
18206 limit = 0xfff;
18207 }
18208 else
18209 {
18210 value = -value;
18211 limit = 0xff;
18212 }
18213 if (value > limit)
18214 {
18215 as_bad_where (fixP->fx_file, fixP->fx_line,
18216 _("offset out of range"));
18217 break;
b99bd4ef 18218 }
c19d1205 18219 newval &= ~limit;
b99bd4ef 18220 }
b99bd4ef 18221
c19d1205
ZW
18222 newval |= value;
18223 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18224 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18225 break;
404ff6b5 18226
c19d1205
ZW
18227 case BFD_RELOC_ARM_SHIFT_IMM:
18228 newval = md_chars_to_number (buf, INSN_SIZE);
18229 if (((unsigned long) value) > 32
18230 || (value == 32
18231 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18232 {
18233 as_bad_where (fixP->fx_file, fixP->fx_line,
18234 _("shift expression is too large"));
18235 break;
18236 }
404ff6b5 18237
c19d1205
ZW
18238 if (value == 0)
18239 /* Shifts of zero must be done as lsl. */
18240 newval &= ~0x60;
18241 else if (value == 32)
18242 value = 0;
18243 newval &= 0xfffff07f;
18244 newval |= (value & 0x1f) << 7;
18245 md_number_to_chars (buf, newval, INSN_SIZE);
18246 break;
404ff6b5 18247
c19d1205 18248 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18249 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18250 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18251 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18252 /* We claim that this fixup has been processed here,
18253 even if in fact we generate an error because we do
18254 not have a reloc for it, so tc_gen_reloc will reject it. */
18255 fixP->fx_done = 1;
404ff6b5 18256
c19d1205
ZW
18257 if (fixP->fx_addsy
18258 && ! S_IS_DEFINED (fixP->fx_addsy))
18259 {
18260 as_bad_where (fixP->fx_file, fixP->fx_line,
18261 _("undefined symbol %s used as an immediate value"),
18262 S_GET_NAME (fixP->fx_addsy));
18263 break;
18264 }
404ff6b5 18265
c19d1205
ZW
18266 newval = md_chars_to_number (buf, THUMB_SIZE);
18267 newval <<= 16;
18268 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18269
16805f35
PB
18270 newimm = FAIL;
18271 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18272 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18273 {
18274 newimm = encode_thumb32_immediate (value);
18275 if (newimm == (unsigned int) FAIL)
18276 newimm = thumb32_negate_data_op (&newval, value);
18277 }
16805f35
PB
18278 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18279 && newimm == (unsigned int) FAIL)
92e90b6e 18280 {
16805f35
PB
18281 /* Turn add/sum into addw/subw. */
18282 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18283 newval = (newval & 0xfeffffff) | 0x02000000;
18284
e9f89963
PB
18285 /* 12 bit immediate for addw/subw. */
18286 if (value < 0)
18287 {
18288 value = -value;
18289 newval ^= 0x00a00000;
18290 }
92e90b6e
PB
18291 if (value > 0xfff)
18292 newimm = (unsigned int) FAIL;
18293 else
18294 newimm = value;
18295 }
cc8a6dd0 18296
c19d1205 18297 if (newimm == (unsigned int)FAIL)
3631a3c8 18298 {
c19d1205
ZW
18299 as_bad_where (fixP->fx_file, fixP->fx_line,
18300 _("invalid constant (%lx) after fixup"),
18301 (unsigned long) value);
18302 break;
3631a3c8
NC
18303 }
18304
c19d1205
ZW
18305 newval |= (newimm & 0x800) << 15;
18306 newval |= (newimm & 0x700) << 4;
18307 newval |= (newimm & 0x0ff);
cc8a6dd0 18308
c19d1205
ZW
18309 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18310 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18311 break;
a737bd4d 18312
3eb17e6b 18313 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18314 if (((unsigned long) value) > 0xffff)
18315 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18316 _("invalid smc expression"));
2fc8bdac 18317 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18318 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18319 md_number_to_chars (buf, newval, INSN_SIZE);
18320 break;
a737bd4d 18321
c19d1205 18322 case BFD_RELOC_ARM_SWI:
adbaf948 18323 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18324 {
18325 if (((unsigned long) value) > 0xff)
18326 as_bad_where (fixP->fx_file, fixP->fx_line,
18327 _("invalid swi expression"));
2fc8bdac 18328 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18329 newval |= value;
18330 md_number_to_chars (buf, newval, THUMB_SIZE);
18331 }
18332 else
18333 {
18334 if (((unsigned long) value) > 0x00ffffff)
18335 as_bad_where (fixP->fx_file, fixP->fx_line,
18336 _("invalid swi expression"));
2fc8bdac 18337 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18338 newval |= value;
18339 md_number_to_chars (buf, newval, INSN_SIZE);
18340 }
18341 break;
a737bd4d 18342
c19d1205
ZW
18343 case BFD_RELOC_ARM_MULTI:
18344 if (((unsigned long) value) > 0xffff)
18345 as_bad_where (fixP->fx_file, fixP->fx_line,
18346 _("invalid expression in load/store multiple"));
18347 newval = value | md_chars_to_number (buf, INSN_SIZE);
18348 md_number_to_chars (buf, newval, INSN_SIZE);
18349 break;
a737bd4d 18350
c19d1205 18351#ifdef OBJ_ELF
39b41c9c
PB
18352 case BFD_RELOC_ARM_PCREL_CALL:
18353 newval = md_chars_to_number (buf, INSN_SIZE);
18354 if ((newval & 0xf0000000) == 0xf0000000)
18355 temp = 1;
18356 else
18357 temp = 3;
18358 goto arm_branch_common;
18359
18360 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18361 case BFD_RELOC_ARM_PLT32:
c19d1205 18362#endif
39b41c9c
PB
18363 case BFD_RELOC_ARM_PCREL_BRANCH:
18364 temp = 3;
18365 goto arm_branch_common;
a737bd4d 18366
39b41c9c
PB
18367 case BFD_RELOC_ARM_PCREL_BLX:
18368 temp = 1;
18369 arm_branch_common:
c19d1205 18370 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18371 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18372 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18373 also be be clear. */
18374 if (value & temp)
c19d1205 18375 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18376 _("misaligned branch destination"));
18377 if ((value & (offsetT)0xfe000000) != (offsetT)0
18378 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18379 as_bad_where (fixP->fx_file, fixP->fx_line,
18380 _("branch out of range"));
a737bd4d 18381
2fc8bdac 18382 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18383 {
2fc8bdac
ZW
18384 newval = md_chars_to_number (buf, INSN_SIZE);
18385 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18386 /* Set the H bit on BLX instructions. */
18387 if (temp == 1)
18388 {
18389 if (value & 2)
18390 newval |= 0x01000000;
18391 else
18392 newval &= ~0x01000000;
18393 }
2fc8bdac 18394 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18395 }
c19d1205 18396 break;
a737bd4d 18397
25fe350b
MS
18398 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18399 /* CBZ can only branch forward. */
a737bd4d 18400
738755b0
MS
18401 /* Attempts to use CBZ to branch to the next instruction
18402 (which, strictly speaking, are prohibited) will be turned into
18403 no-ops.
18404
18405 FIXME: It may be better to remove the instruction completely and
18406 perform relaxation. */
18407 if (value == -2)
2fc8bdac
ZW
18408 {
18409 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18410 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18411 md_number_to_chars (buf, newval, THUMB_SIZE);
18412 }
738755b0
MS
18413 else
18414 {
18415 if (value & ~0x7e)
18416 as_bad_where (fixP->fx_file, fixP->fx_line,
18417 _("branch out of range"));
18418
18419 if (fixP->fx_done || !seg->use_rela_p)
18420 {
18421 newval = md_chars_to_number (buf, THUMB_SIZE);
18422 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18423 md_number_to_chars (buf, newval, THUMB_SIZE);
18424 }
18425 }
c19d1205 18426 break;
a737bd4d 18427
c19d1205 18428 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18429 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18430 as_bad_where (fixP->fx_file, fixP->fx_line,
18431 _("branch out of range"));
a737bd4d 18432
2fc8bdac
ZW
18433 if (fixP->fx_done || !seg->use_rela_p)
18434 {
18435 newval = md_chars_to_number (buf, THUMB_SIZE);
18436 newval |= (value & 0x1ff) >> 1;
18437 md_number_to_chars (buf, newval, THUMB_SIZE);
18438 }
c19d1205 18439 break;
a737bd4d 18440
c19d1205 18441 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18442 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18443 as_bad_where (fixP->fx_file, fixP->fx_line,
18444 _("branch out of range"));
a737bd4d 18445
2fc8bdac
ZW
18446 if (fixP->fx_done || !seg->use_rela_p)
18447 {
18448 newval = md_chars_to_number (buf, THUMB_SIZE);
18449 newval |= (value & 0xfff) >> 1;
18450 md_number_to_chars (buf, newval, THUMB_SIZE);
18451 }
c19d1205 18452 break;
a737bd4d 18453
c19d1205 18454 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18455 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18456 as_bad_where (fixP->fx_file, fixP->fx_line,
18457 _("conditional branch out of range"));
404ff6b5 18458
2fc8bdac
ZW
18459 if (fixP->fx_done || !seg->use_rela_p)
18460 {
18461 offsetT newval2;
18462 addressT S, J1, J2, lo, hi;
404ff6b5 18463
2fc8bdac
ZW
18464 S = (value & 0x00100000) >> 20;
18465 J2 = (value & 0x00080000) >> 19;
18466 J1 = (value & 0x00040000) >> 18;
18467 hi = (value & 0x0003f000) >> 12;
18468 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18469
2fc8bdac
ZW
18470 newval = md_chars_to_number (buf, THUMB_SIZE);
18471 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18472 newval |= (S << 10) | hi;
18473 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18474 md_number_to_chars (buf, newval, THUMB_SIZE);
18475 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18476 }
c19d1205 18477 break;
6c43fab6 18478
c19d1205
ZW
18479 case BFD_RELOC_THUMB_PCREL_BLX:
18480 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18481 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18482 as_bad_where (fixP->fx_file, fixP->fx_line,
18483 _("branch out of range"));
404ff6b5 18484
2fc8bdac
ZW
18485 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18486 /* For a BLX instruction, make sure that the relocation is rounded up
18487 to a word boundary. This follows the semantics of the instruction
18488 which specifies that bit 1 of the target address will come from bit
18489 1 of the base address. */
18490 value = (value + 1) & ~ 1;
404ff6b5 18491
2fc8bdac 18492 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18493 {
2fc8bdac
ZW
18494 offsetT newval2;
18495
18496 newval = md_chars_to_number (buf, THUMB_SIZE);
18497 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18498 newval |= (value & 0x7fffff) >> 12;
18499 newval2 |= (value & 0xfff) >> 1;
18500 md_number_to_chars (buf, newval, THUMB_SIZE);
18501 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18502 }
c19d1205 18503 break;
404ff6b5 18504
c19d1205 18505 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18506 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18507 as_bad_where (fixP->fx_file, fixP->fx_line,
18508 _("branch out of range"));
6c43fab6 18509
2fc8bdac
ZW
18510 if (fixP->fx_done || !seg->use_rela_p)
18511 {
18512 offsetT newval2;
18513 addressT S, I1, I2, lo, hi;
6c43fab6 18514
2fc8bdac
ZW
18515 S = (value & 0x01000000) >> 24;
18516 I1 = (value & 0x00800000) >> 23;
18517 I2 = (value & 0x00400000) >> 22;
18518 hi = (value & 0x003ff000) >> 12;
18519 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18520
2fc8bdac
ZW
18521 I1 = !(I1 ^ S);
18522 I2 = !(I2 ^ S);
a737bd4d 18523
2fc8bdac
ZW
18524 newval = md_chars_to_number (buf, THUMB_SIZE);
18525 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18526 newval |= (S << 10) | hi;
18527 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18528 md_number_to_chars (buf, newval, THUMB_SIZE);
18529 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18530 }
18531 break;
a737bd4d 18532
2fc8bdac
ZW
18533 case BFD_RELOC_8:
18534 if (fixP->fx_done || !seg->use_rela_p)
18535 md_number_to_chars (buf, value, 1);
c19d1205 18536 break;
a737bd4d 18537
c19d1205 18538 case BFD_RELOC_16:
2fc8bdac 18539 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18540 md_number_to_chars (buf, value, 2);
c19d1205 18541 break;
a737bd4d 18542
c19d1205
ZW
18543#ifdef OBJ_ELF
18544 case BFD_RELOC_ARM_TLS_GD32:
18545 case BFD_RELOC_ARM_TLS_LE32:
18546 case BFD_RELOC_ARM_TLS_IE32:
18547 case BFD_RELOC_ARM_TLS_LDM32:
18548 case BFD_RELOC_ARM_TLS_LDO32:
18549 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18550 /* fall through */
6c43fab6 18551
c19d1205
ZW
18552 case BFD_RELOC_ARM_GOT32:
18553 case BFD_RELOC_ARM_GOTOFF:
18554 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18555 if (fixP->fx_done || !seg->use_rela_p)
18556 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18557 break;
18558#endif
6c43fab6 18559
c19d1205
ZW
18560 case BFD_RELOC_RVA:
18561 case BFD_RELOC_32:
18562 case BFD_RELOC_ARM_TARGET1:
18563 case BFD_RELOC_ARM_ROSEGREL32:
18564 case BFD_RELOC_ARM_SBREL32:
18565 case BFD_RELOC_32_PCREL:
f0927246
NC
18566#ifdef TE_PE
18567 case BFD_RELOC_32_SECREL:
18568#endif
2fc8bdac 18569 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18570#ifdef TE_WINCE
18571 /* For WinCE we only do this for pcrel fixups. */
18572 if (fixP->fx_done || fixP->fx_pcrel)
18573#endif
18574 md_number_to_chars (buf, value, 4);
c19d1205 18575 break;
6c43fab6 18576
c19d1205
ZW
18577#ifdef OBJ_ELF
18578 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18579 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18580 {
18581 newval = md_chars_to_number (buf, 4) & 0x80000000;
18582 if ((value ^ (value >> 1)) & 0x40000000)
18583 {
18584 as_bad_where (fixP->fx_file, fixP->fx_line,
18585 _("rel31 relocation overflow"));
18586 }
18587 newval |= value & 0x7fffffff;
18588 md_number_to_chars (buf, newval, 4);
18589 }
18590 break;
c19d1205 18591#endif
a737bd4d 18592
c19d1205 18593 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18594 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18595 if (value < -1023 || value > 1023 || (value & 3))
18596 as_bad_where (fixP->fx_file, fixP->fx_line,
18597 _("co-processor offset out of range"));
18598 cp_off_common:
18599 sign = value >= 0;
18600 if (value < 0)
18601 value = -value;
8f06b2d8
PB
18602 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18603 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18604 newval = md_chars_to_number (buf, INSN_SIZE);
18605 else
18606 newval = get_thumb32_insn (buf);
18607 newval &= 0xff7fff00;
c19d1205 18608 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18609 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18610 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18611 md_number_to_chars (buf, newval, INSN_SIZE);
18612 else
18613 put_thumb32_insn (buf, newval);
c19d1205 18614 break;
a737bd4d 18615
c19d1205 18616 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18617 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18618 if (value < -255 || value > 255)
18619 as_bad_where (fixP->fx_file, fixP->fx_line,
18620 _("co-processor offset out of range"));
df7849c5 18621 value *= 4;
c19d1205 18622 goto cp_off_common;
6c43fab6 18623
c19d1205
ZW
18624 case BFD_RELOC_ARM_THUMB_OFFSET:
18625 newval = md_chars_to_number (buf, THUMB_SIZE);
18626 /* Exactly what ranges, and where the offset is inserted depends
18627 on the type of instruction, we can establish this from the
18628 top 4 bits. */
18629 switch (newval >> 12)
18630 {
18631 case 4: /* PC load. */
18632 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18633 forced to zero for these loads; md_pcrel_from has already
18634 compensated for this. */
18635 if (value & 3)
18636 as_bad_where (fixP->fx_file, fixP->fx_line,
18637 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18638 (((unsigned long) fixP->fx_frag->fr_address
18639 + (unsigned long) fixP->fx_where) & ~3)
18640 + (unsigned long) value);
a737bd4d 18641
c19d1205
ZW
18642 if (value & ~0x3fc)
18643 as_bad_where (fixP->fx_file, fixP->fx_line,
18644 _("invalid offset, value too big (0x%08lX)"),
18645 (long) value);
a737bd4d 18646
c19d1205
ZW
18647 newval |= value >> 2;
18648 break;
a737bd4d 18649
c19d1205
ZW
18650 case 9: /* SP load/store. */
18651 if (value & ~0x3fc)
18652 as_bad_where (fixP->fx_file, fixP->fx_line,
18653 _("invalid offset, value too big (0x%08lX)"),
18654 (long) value);
18655 newval |= value >> 2;
18656 break;
6c43fab6 18657
c19d1205
ZW
18658 case 6: /* Word load/store. */
18659 if (value & ~0x7c)
18660 as_bad_where (fixP->fx_file, fixP->fx_line,
18661 _("invalid offset, value too big (0x%08lX)"),
18662 (long) value);
18663 newval |= value << 4; /* 6 - 2. */
18664 break;
a737bd4d 18665
c19d1205
ZW
18666 case 7: /* Byte load/store. */
18667 if (value & ~0x1f)
18668 as_bad_where (fixP->fx_file, fixP->fx_line,
18669 _("invalid offset, value too big (0x%08lX)"),
18670 (long) value);
18671 newval |= value << 6;
18672 break;
a737bd4d 18673
c19d1205
ZW
18674 case 8: /* Halfword load/store. */
18675 if (value & ~0x3e)
18676 as_bad_where (fixP->fx_file, fixP->fx_line,
18677 _("invalid offset, value too big (0x%08lX)"),
18678 (long) value);
18679 newval |= value << 5; /* 6 - 1. */
18680 break;
a737bd4d 18681
c19d1205
ZW
18682 default:
18683 as_bad_where (fixP->fx_file, fixP->fx_line,
18684 "Unable to process relocation for thumb opcode: %lx",
18685 (unsigned long) newval);
18686 break;
18687 }
18688 md_number_to_chars (buf, newval, THUMB_SIZE);
18689 break;
a737bd4d 18690
c19d1205
ZW
18691 case BFD_RELOC_ARM_THUMB_ADD:
18692 /* This is a complicated relocation, since we use it for all of
18693 the following immediate relocations:
a737bd4d 18694
c19d1205
ZW
18695 3bit ADD/SUB
18696 8bit ADD/SUB
18697 9bit ADD/SUB SP word-aligned
18698 10bit ADD PC/SP word-aligned
a737bd4d 18699
c19d1205
ZW
18700 The type of instruction being processed is encoded in the
18701 instruction field:
a737bd4d 18702
c19d1205
ZW
18703 0x8000 SUB
18704 0x00F0 Rd
18705 0x000F Rs
18706 */
18707 newval = md_chars_to_number (buf, THUMB_SIZE);
18708 {
18709 int rd = (newval >> 4) & 0xf;
18710 int rs = newval & 0xf;
18711 int subtract = !!(newval & 0x8000);
a737bd4d 18712
c19d1205
ZW
18713 /* Check for HI regs, only very restricted cases allowed:
18714 Adjusting SP, and using PC or SP to get an address. */
18715 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18716 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18717 as_bad_where (fixP->fx_file, fixP->fx_line,
18718 _("invalid Hi register with immediate"));
a737bd4d 18719
c19d1205
ZW
18720 /* If value is negative, choose the opposite instruction. */
18721 if (value < 0)
18722 {
18723 value = -value;
18724 subtract = !subtract;
18725 if (value < 0)
18726 as_bad_where (fixP->fx_file, fixP->fx_line,
18727 _("immediate value out of range"));
18728 }
a737bd4d 18729
c19d1205
ZW
18730 if (rd == REG_SP)
18731 {
18732 if (value & ~0x1fc)
18733 as_bad_where (fixP->fx_file, fixP->fx_line,
18734 _("invalid immediate for stack address calculation"));
18735 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18736 newval |= value >> 2;
18737 }
18738 else if (rs == REG_PC || rs == REG_SP)
18739 {
18740 if (subtract || value & ~0x3fc)
18741 as_bad_where (fixP->fx_file, fixP->fx_line,
18742 _("invalid immediate for address calculation (value = 0x%08lX)"),
18743 (unsigned long) value);
18744 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18745 newval |= rd << 8;
18746 newval |= value >> 2;
18747 }
18748 else if (rs == rd)
18749 {
18750 if (value & ~0xff)
18751 as_bad_where (fixP->fx_file, fixP->fx_line,
18752 _("immediate value out of range"));
18753 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18754 newval |= (rd << 8) | value;
18755 }
18756 else
18757 {
18758 if (value & ~0x7)
18759 as_bad_where (fixP->fx_file, fixP->fx_line,
18760 _("immediate value out of range"));
18761 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18762 newval |= rd | (rs << 3) | (value << 6);
18763 }
18764 }
18765 md_number_to_chars (buf, newval, THUMB_SIZE);
18766 break;
a737bd4d 18767
c19d1205
ZW
18768 case BFD_RELOC_ARM_THUMB_IMM:
18769 newval = md_chars_to_number (buf, THUMB_SIZE);
18770 if (value < 0 || value > 255)
18771 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 18772 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
18773 (long) value);
18774 newval |= value;
18775 md_number_to_chars (buf, newval, THUMB_SIZE);
18776 break;
a737bd4d 18777
c19d1205
ZW
18778 case BFD_RELOC_ARM_THUMB_SHIFT:
18779 /* 5bit shift value (0..32). LSL cannot take 32. */
18780 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18781 temp = newval & 0xf800;
18782 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18783 as_bad_where (fixP->fx_file, fixP->fx_line,
18784 _("invalid shift value: %ld"), (long) value);
18785 /* Shifts of zero must be encoded as LSL. */
18786 if (value == 0)
18787 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18788 /* Shifts of 32 are encoded as zero. */
18789 else if (value == 32)
18790 value = 0;
18791 newval |= value << 6;
18792 md_number_to_chars (buf, newval, THUMB_SIZE);
18793 break;
a737bd4d 18794
c19d1205
ZW
18795 case BFD_RELOC_VTABLE_INHERIT:
18796 case BFD_RELOC_VTABLE_ENTRY:
18797 fixP->fx_done = 0;
18798 return;
6c43fab6 18799
b6895b4f
PB
18800 case BFD_RELOC_ARM_MOVW:
18801 case BFD_RELOC_ARM_MOVT:
18802 case BFD_RELOC_ARM_THUMB_MOVW:
18803 case BFD_RELOC_ARM_THUMB_MOVT:
18804 if (fixP->fx_done || !seg->use_rela_p)
18805 {
18806 /* REL format relocations are limited to a 16-bit addend. */
18807 if (!fixP->fx_done)
18808 {
39623e12 18809 if (value < -0x8000 || value > 0x7fff)
b6895b4f 18810 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 18811 _("offset out of range"));
b6895b4f
PB
18812 }
18813 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18814 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18815 {
18816 value >>= 16;
18817 }
18818
18819 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18820 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18821 {
18822 newval = get_thumb32_insn (buf);
18823 newval &= 0xfbf08f00;
18824 newval |= (value & 0xf000) << 4;
18825 newval |= (value & 0x0800) << 15;
18826 newval |= (value & 0x0700) << 4;
18827 newval |= (value & 0x00ff);
18828 put_thumb32_insn (buf, newval);
18829 }
18830 else
18831 {
18832 newval = md_chars_to_number (buf, 4);
18833 newval &= 0xfff0f000;
18834 newval |= value & 0x0fff;
18835 newval |= (value & 0xf000) << 4;
18836 md_number_to_chars (buf, newval, 4);
18837 }
18838 }
18839 return;
18840
4962c51a
MS
18841 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18842 case BFD_RELOC_ARM_ALU_PC_G0:
18843 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18844 case BFD_RELOC_ARM_ALU_PC_G1:
18845 case BFD_RELOC_ARM_ALU_PC_G2:
18846 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18847 case BFD_RELOC_ARM_ALU_SB_G0:
18848 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18849 case BFD_RELOC_ARM_ALU_SB_G1:
18850 case BFD_RELOC_ARM_ALU_SB_G2:
18851 assert (!fixP->fx_done);
18852 if (!seg->use_rela_p)
18853 {
18854 bfd_vma insn;
18855 bfd_vma encoded_addend;
18856 bfd_vma addend_abs = abs (value);
18857
18858 /* Check that the absolute value of the addend can be
18859 expressed as an 8-bit constant plus a rotation. */
18860 encoded_addend = encode_arm_immediate (addend_abs);
18861 if (encoded_addend == (unsigned int) FAIL)
18862 as_bad_where (fixP->fx_file, fixP->fx_line,
18863 _("the offset 0x%08lX is not representable"),
495bde8e 18864 (unsigned long) addend_abs);
4962c51a
MS
18865
18866 /* Extract the instruction. */
18867 insn = md_chars_to_number (buf, INSN_SIZE);
18868
18869 /* If the addend is positive, use an ADD instruction.
18870 Otherwise use a SUB. Take care not to destroy the S bit. */
18871 insn &= 0xff1fffff;
18872 if (value < 0)
18873 insn |= 1 << 22;
18874 else
18875 insn |= 1 << 23;
18876
18877 /* Place the encoded addend into the first 12 bits of the
18878 instruction. */
18879 insn &= 0xfffff000;
18880 insn |= encoded_addend;
5f4273c7
NC
18881
18882 /* Update the instruction. */
4962c51a
MS
18883 md_number_to_chars (buf, insn, INSN_SIZE);
18884 }
18885 break;
18886
18887 case BFD_RELOC_ARM_LDR_PC_G0:
18888 case BFD_RELOC_ARM_LDR_PC_G1:
18889 case BFD_RELOC_ARM_LDR_PC_G2:
18890 case BFD_RELOC_ARM_LDR_SB_G0:
18891 case BFD_RELOC_ARM_LDR_SB_G1:
18892 case BFD_RELOC_ARM_LDR_SB_G2:
18893 assert (!fixP->fx_done);
18894 if (!seg->use_rela_p)
18895 {
18896 bfd_vma insn;
18897 bfd_vma addend_abs = abs (value);
18898
18899 /* Check that the absolute value of the addend can be
18900 encoded in 12 bits. */
18901 if (addend_abs >= 0x1000)
18902 as_bad_where (fixP->fx_file, fixP->fx_line,
18903 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 18904 (unsigned long) addend_abs);
4962c51a
MS
18905
18906 /* Extract the instruction. */
18907 insn = md_chars_to_number (buf, INSN_SIZE);
18908
18909 /* If the addend is negative, clear bit 23 of the instruction.
18910 Otherwise set it. */
18911 if (value < 0)
18912 insn &= ~(1 << 23);
18913 else
18914 insn |= 1 << 23;
18915
18916 /* Place the absolute value of the addend into the first 12 bits
18917 of the instruction. */
18918 insn &= 0xfffff000;
18919 insn |= addend_abs;
5f4273c7
NC
18920
18921 /* Update the instruction. */
4962c51a
MS
18922 md_number_to_chars (buf, insn, INSN_SIZE);
18923 }
18924 break;
18925
18926 case BFD_RELOC_ARM_LDRS_PC_G0:
18927 case BFD_RELOC_ARM_LDRS_PC_G1:
18928 case BFD_RELOC_ARM_LDRS_PC_G2:
18929 case BFD_RELOC_ARM_LDRS_SB_G0:
18930 case BFD_RELOC_ARM_LDRS_SB_G1:
18931 case BFD_RELOC_ARM_LDRS_SB_G2:
18932 assert (!fixP->fx_done);
18933 if (!seg->use_rela_p)
18934 {
18935 bfd_vma insn;
18936 bfd_vma addend_abs = abs (value);
18937
18938 /* Check that the absolute value of the addend can be
18939 encoded in 8 bits. */
18940 if (addend_abs >= 0x100)
18941 as_bad_where (fixP->fx_file, fixP->fx_line,
18942 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 18943 (unsigned long) addend_abs);
4962c51a
MS
18944
18945 /* Extract the instruction. */
18946 insn = md_chars_to_number (buf, INSN_SIZE);
18947
18948 /* If the addend is negative, clear bit 23 of the instruction.
18949 Otherwise set it. */
18950 if (value < 0)
18951 insn &= ~(1 << 23);
18952 else
18953 insn |= 1 << 23;
18954
18955 /* Place the first four bits of the absolute value of the addend
18956 into the first 4 bits of the instruction, and the remaining
18957 four into bits 8 .. 11. */
18958 insn &= 0xfffff0f0;
18959 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
18960
18961 /* Update the instruction. */
4962c51a
MS
18962 md_number_to_chars (buf, insn, INSN_SIZE);
18963 }
18964 break;
18965
18966 case BFD_RELOC_ARM_LDC_PC_G0:
18967 case BFD_RELOC_ARM_LDC_PC_G1:
18968 case BFD_RELOC_ARM_LDC_PC_G2:
18969 case BFD_RELOC_ARM_LDC_SB_G0:
18970 case BFD_RELOC_ARM_LDC_SB_G1:
18971 case BFD_RELOC_ARM_LDC_SB_G2:
18972 assert (!fixP->fx_done);
18973 if (!seg->use_rela_p)
18974 {
18975 bfd_vma insn;
18976 bfd_vma addend_abs = abs (value);
18977
18978 /* Check that the absolute value of the addend is a multiple of
18979 four and, when divided by four, fits in 8 bits. */
18980 if (addend_abs & 0x3)
18981 as_bad_where (fixP->fx_file, fixP->fx_line,
18982 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 18983 (unsigned long) addend_abs);
4962c51a
MS
18984
18985 if ((addend_abs >> 2) > 0xff)
18986 as_bad_where (fixP->fx_file, fixP->fx_line,
18987 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 18988 (unsigned long) addend_abs);
4962c51a
MS
18989
18990 /* Extract the instruction. */
18991 insn = md_chars_to_number (buf, INSN_SIZE);
18992
18993 /* If the addend is negative, clear bit 23 of the instruction.
18994 Otherwise set it. */
18995 if (value < 0)
18996 insn &= ~(1 << 23);
18997 else
18998 insn |= 1 << 23;
18999
19000 /* Place the addend (divided by four) into the first eight
19001 bits of the instruction. */
19002 insn &= 0xfffffff0;
19003 insn |= addend_abs >> 2;
5f4273c7
NC
19004
19005 /* Update the instruction. */
4962c51a
MS
19006 md_number_to_chars (buf, insn, INSN_SIZE);
19007 }
19008 break;
19009
845b51d6
PB
19010 case BFD_RELOC_ARM_V4BX:
19011 /* This will need to go in the object file. */
19012 fixP->fx_done = 0;
19013 break;
19014
c19d1205
ZW
19015 case BFD_RELOC_UNUSED:
19016 default:
19017 as_bad_where (fixP->fx_file, fixP->fx_line,
19018 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19019 }
6c43fab6
RE
19020}
19021
c19d1205
ZW
19022/* Translate internal representation of relocation info to BFD target
19023 format. */
a737bd4d 19024
c19d1205 19025arelent *
00a97672 19026tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19027{
c19d1205
ZW
19028 arelent * reloc;
19029 bfd_reloc_code_real_type code;
a737bd4d 19030
c19d1205 19031 reloc = xmalloc (sizeof (arelent));
a737bd4d 19032
c19d1205
ZW
19033 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19034 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19035 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19036
2fc8bdac 19037 if (fixp->fx_pcrel)
00a97672
RS
19038 {
19039 if (section->use_rela_p)
19040 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19041 else
19042 fixp->fx_offset = reloc->address;
19043 }
c19d1205 19044 reloc->addend = fixp->fx_offset;
a737bd4d 19045
c19d1205 19046 switch (fixp->fx_r_type)
a737bd4d 19047 {
c19d1205
ZW
19048 case BFD_RELOC_8:
19049 if (fixp->fx_pcrel)
19050 {
19051 code = BFD_RELOC_8_PCREL;
19052 break;
19053 }
a737bd4d 19054
c19d1205
ZW
19055 case BFD_RELOC_16:
19056 if (fixp->fx_pcrel)
19057 {
19058 code = BFD_RELOC_16_PCREL;
19059 break;
19060 }
6c43fab6 19061
c19d1205
ZW
19062 case BFD_RELOC_32:
19063 if (fixp->fx_pcrel)
19064 {
19065 code = BFD_RELOC_32_PCREL;
19066 break;
19067 }
a737bd4d 19068
b6895b4f
PB
19069 case BFD_RELOC_ARM_MOVW:
19070 if (fixp->fx_pcrel)
19071 {
19072 code = BFD_RELOC_ARM_MOVW_PCREL;
19073 break;
19074 }
19075
19076 case BFD_RELOC_ARM_MOVT:
19077 if (fixp->fx_pcrel)
19078 {
19079 code = BFD_RELOC_ARM_MOVT_PCREL;
19080 break;
19081 }
19082
19083 case BFD_RELOC_ARM_THUMB_MOVW:
19084 if (fixp->fx_pcrel)
19085 {
19086 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19087 break;
19088 }
19089
19090 case BFD_RELOC_ARM_THUMB_MOVT:
19091 if (fixp->fx_pcrel)
19092 {
19093 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19094 break;
19095 }
19096
c19d1205
ZW
19097 case BFD_RELOC_NONE:
19098 case BFD_RELOC_ARM_PCREL_BRANCH:
19099 case BFD_RELOC_ARM_PCREL_BLX:
19100 case BFD_RELOC_RVA:
19101 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19102 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19103 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19104 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19105 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19106 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19107 case BFD_RELOC_THUMB_PCREL_BLX:
19108 case BFD_RELOC_VTABLE_ENTRY:
19109 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19110#ifdef TE_PE
19111 case BFD_RELOC_32_SECREL:
19112#endif
c19d1205
ZW
19113 code = fixp->fx_r_type;
19114 break;
a737bd4d 19115
c19d1205
ZW
19116 case BFD_RELOC_ARM_LITERAL:
19117 case BFD_RELOC_ARM_HWLITERAL:
19118 /* If this is called then the a literal has
19119 been referenced across a section boundary. */
19120 as_bad_where (fixp->fx_file, fixp->fx_line,
19121 _("literal referenced across section boundary"));
19122 return NULL;
a737bd4d 19123
c19d1205
ZW
19124#ifdef OBJ_ELF
19125 case BFD_RELOC_ARM_GOT32:
19126 case BFD_RELOC_ARM_GOTOFF:
19127 case BFD_RELOC_ARM_PLT32:
19128 case BFD_RELOC_ARM_TARGET1:
19129 case BFD_RELOC_ARM_ROSEGREL32:
19130 case BFD_RELOC_ARM_SBREL32:
19131 case BFD_RELOC_ARM_PREL31:
19132 case BFD_RELOC_ARM_TARGET2:
19133 case BFD_RELOC_ARM_TLS_LE32:
19134 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19135 case BFD_RELOC_ARM_PCREL_CALL:
19136 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19137 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19138 case BFD_RELOC_ARM_ALU_PC_G0:
19139 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19140 case BFD_RELOC_ARM_ALU_PC_G1:
19141 case BFD_RELOC_ARM_ALU_PC_G2:
19142 case BFD_RELOC_ARM_LDR_PC_G0:
19143 case BFD_RELOC_ARM_LDR_PC_G1:
19144 case BFD_RELOC_ARM_LDR_PC_G2:
19145 case BFD_RELOC_ARM_LDRS_PC_G0:
19146 case BFD_RELOC_ARM_LDRS_PC_G1:
19147 case BFD_RELOC_ARM_LDRS_PC_G2:
19148 case BFD_RELOC_ARM_LDC_PC_G0:
19149 case BFD_RELOC_ARM_LDC_PC_G1:
19150 case BFD_RELOC_ARM_LDC_PC_G2:
19151 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19152 case BFD_RELOC_ARM_ALU_SB_G0:
19153 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19154 case BFD_RELOC_ARM_ALU_SB_G1:
19155 case BFD_RELOC_ARM_ALU_SB_G2:
19156 case BFD_RELOC_ARM_LDR_SB_G0:
19157 case BFD_RELOC_ARM_LDR_SB_G1:
19158 case BFD_RELOC_ARM_LDR_SB_G2:
19159 case BFD_RELOC_ARM_LDRS_SB_G0:
19160 case BFD_RELOC_ARM_LDRS_SB_G1:
19161 case BFD_RELOC_ARM_LDRS_SB_G2:
19162 case BFD_RELOC_ARM_LDC_SB_G0:
19163 case BFD_RELOC_ARM_LDC_SB_G1:
19164 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19165 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19166 code = fixp->fx_r_type;
19167 break;
a737bd4d 19168
c19d1205
ZW
19169 case BFD_RELOC_ARM_TLS_GD32:
19170 case BFD_RELOC_ARM_TLS_IE32:
19171 case BFD_RELOC_ARM_TLS_LDM32:
19172 /* BFD will include the symbol's address in the addend.
19173 But we don't want that, so subtract it out again here. */
19174 if (!S_IS_COMMON (fixp->fx_addsy))
19175 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19176 code = fixp->fx_r_type;
19177 break;
19178#endif
a737bd4d 19179
c19d1205
ZW
19180 case BFD_RELOC_ARM_IMMEDIATE:
19181 as_bad_where (fixp->fx_file, fixp->fx_line,
19182 _("internal relocation (type: IMMEDIATE) not fixed up"));
19183 return NULL;
a737bd4d 19184
c19d1205
ZW
19185 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19186 as_bad_where (fixp->fx_file, fixp->fx_line,
19187 _("ADRL used for a symbol not defined in the same file"));
19188 return NULL;
a737bd4d 19189
c19d1205 19190 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19191 if (section->use_rela_p)
19192 {
19193 code = fixp->fx_r_type;
19194 break;
19195 }
19196
c19d1205
ZW
19197 if (fixp->fx_addsy != NULL
19198 && !S_IS_DEFINED (fixp->fx_addsy)
19199 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19200 {
c19d1205
ZW
19201 as_bad_where (fixp->fx_file, fixp->fx_line,
19202 _("undefined local label `%s'"),
19203 S_GET_NAME (fixp->fx_addsy));
19204 return NULL;
a737bd4d
NC
19205 }
19206
c19d1205
ZW
19207 as_bad_where (fixp->fx_file, fixp->fx_line,
19208 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19209 return NULL;
a737bd4d 19210
c19d1205
ZW
19211 default:
19212 {
19213 char * type;
6c43fab6 19214
c19d1205
ZW
19215 switch (fixp->fx_r_type)
19216 {
19217 case BFD_RELOC_NONE: type = "NONE"; break;
19218 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19219 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19220 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19221 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19222 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19223 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19224 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19225 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19226 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19227 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19228 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19229 default: type = _("<unknown>"); break;
19230 }
19231 as_bad_where (fixp->fx_file, fixp->fx_line,
19232 _("cannot represent %s relocation in this object file format"),
19233 type);
19234 return NULL;
19235 }
a737bd4d 19236 }
6c43fab6 19237
c19d1205
ZW
19238#ifdef OBJ_ELF
19239 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19240 && GOT_symbol
19241 && fixp->fx_addsy == GOT_symbol)
19242 {
19243 code = BFD_RELOC_ARM_GOTPC;
19244 reloc->addend = fixp->fx_offset = reloc->address;
19245 }
19246#endif
6c43fab6 19247
c19d1205 19248 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19249
c19d1205
ZW
19250 if (reloc->howto == NULL)
19251 {
19252 as_bad_where (fixp->fx_file, fixp->fx_line,
19253 _("cannot represent %s relocation in this object file format"),
19254 bfd_get_reloc_code_name (code));
19255 return NULL;
19256 }
6c43fab6 19257
c19d1205
ZW
19258 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19259 vtable entry to be used in the relocation's section offset. */
19260 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19261 reloc->address = fixp->fx_offset;
6c43fab6 19262
c19d1205 19263 return reloc;
6c43fab6
RE
19264}
19265
c19d1205 19266/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19267
c19d1205
ZW
19268void
19269cons_fix_new_arm (fragS * frag,
19270 int where,
19271 int size,
19272 expressionS * exp)
6c43fab6 19273{
c19d1205
ZW
19274 bfd_reloc_code_real_type type;
19275 int pcrel = 0;
6c43fab6 19276
c19d1205
ZW
19277 /* Pick a reloc.
19278 FIXME: @@ Should look at CPU word size. */
19279 switch (size)
19280 {
19281 case 1:
19282 type = BFD_RELOC_8;
19283 break;
19284 case 2:
19285 type = BFD_RELOC_16;
19286 break;
19287 case 4:
19288 default:
19289 type = BFD_RELOC_32;
19290 break;
19291 case 8:
19292 type = BFD_RELOC_64;
19293 break;
19294 }
6c43fab6 19295
f0927246
NC
19296#ifdef TE_PE
19297 if (exp->X_op == O_secrel)
19298 {
19299 exp->X_op = O_symbol;
19300 type = BFD_RELOC_32_SECREL;
19301 }
19302#endif
19303
c19d1205
ZW
19304 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19305}
6c43fab6 19306
c19d1205
ZW
19307#if defined OBJ_COFF || defined OBJ_ELF
19308void
19309arm_validate_fix (fixS * fixP)
6c43fab6 19310{
c19d1205
ZW
19311 /* If the destination of the branch is a defined symbol which does not have
19312 the THUMB_FUNC attribute, then we must be calling a function which has
19313 the (interfacearm) attribute. We look for the Thumb entry point to that
19314 function and change the branch to refer to that function instead. */
19315 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19316 && fixP->fx_addsy != NULL
19317 && S_IS_DEFINED (fixP->fx_addsy)
19318 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19319 {
c19d1205 19320 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19321 }
c19d1205
ZW
19322}
19323#endif
6c43fab6 19324
c19d1205
ZW
19325int
19326arm_force_relocation (struct fix * fixp)
19327{
19328#if defined (OBJ_COFF) && defined (TE_PE)
19329 if (fixp->fx_r_type == BFD_RELOC_RVA)
19330 return 1;
19331#endif
6c43fab6 19332
c19d1205
ZW
19333 /* Resolve these relocations even if the symbol is extern or weak. */
19334 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19335 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19336 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19337 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19338 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19339 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19340 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19341 return 0;
a737bd4d 19342
4962c51a
MS
19343 /* Always leave these relocations for the linker. */
19344 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19345 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19346 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19347 return 1;
19348
f0291e4c
PB
19349 /* Always generate relocations against function symbols. */
19350 if (fixp->fx_r_type == BFD_RELOC_32
19351 && fixp->fx_addsy
19352 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19353 return 1;
19354
c19d1205 19355 return generic_force_reloc (fixp);
404ff6b5
AH
19356}
19357
0ffdc86c 19358#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19359/* Relocations against function names must be left unadjusted,
19360 so that the linker can use this information to generate interworking
19361 stubs. The MIPS version of this function
c19d1205
ZW
19362 also prevents relocations that are mips-16 specific, but I do not
19363 know why it does this.
404ff6b5 19364
c19d1205
ZW
19365 FIXME:
19366 There is one other problem that ought to be addressed here, but
19367 which currently is not: Taking the address of a label (rather
19368 than a function) and then later jumping to that address. Such
19369 addresses also ought to have their bottom bit set (assuming that
19370 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19371
c19d1205
ZW
19372bfd_boolean
19373arm_fix_adjustable (fixS * fixP)
404ff6b5 19374{
c19d1205
ZW
19375 if (fixP->fx_addsy == NULL)
19376 return 1;
404ff6b5 19377
e28387c3
PB
19378 /* Preserve relocations against symbols with function type. */
19379 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19380 return 0;
19381
c19d1205
ZW
19382 if (THUMB_IS_FUNC (fixP->fx_addsy)
19383 && fixP->fx_subsy == NULL)
19384 return 0;
a737bd4d 19385
c19d1205
ZW
19386 /* We need the symbol name for the VTABLE entries. */
19387 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19388 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19389 return 0;
404ff6b5 19390
c19d1205
ZW
19391 /* Don't allow symbols to be discarded on GOT related relocs. */
19392 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19393 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19394 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19395 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19396 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19399 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19400 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19401 return 0;
a737bd4d 19402
4962c51a
MS
19403 /* Similarly for group relocations. */
19404 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19405 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19406 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19407 return 0;
19408
c19d1205 19409 return 1;
a737bd4d 19410}
0ffdc86c
NC
19411#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19412
19413#ifdef OBJ_ELF
404ff6b5 19414
c19d1205
ZW
19415const char *
19416elf32_arm_target_format (void)
404ff6b5 19417{
c19d1205
ZW
19418#ifdef TE_SYMBIAN
19419 return (target_big_endian
19420 ? "elf32-bigarm-symbian"
19421 : "elf32-littlearm-symbian");
19422#elif defined (TE_VXWORKS)
19423 return (target_big_endian
19424 ? "elf32-bigarm-vxworks"
19425 : "elf32-littlearm-vxworks");
19426#else
19427 if (target_big_endian)
19428 return "elf32-bigarm";
19429 else
19430 return "elf32-littlearm";
19431#endif
404ff6b5
AH
19432}
19433
c19d1205
ZW
19434void
19435armelf_frob_symbol (symbolS * symp,
19436 int * puntp)
404ff6b5 19437{
c19d1205
ZW
19438 elf_frob_symbol (symp, puntp);
19439}
19440#endif
404ff6b5 19441
c19d1205 19442/* MD interface: Finalization. */
a737bd4d 19443
c19d1205
ZW
19444/* A good place to do this, although this was probably not intended
19445 for this kind of use. We need to dump the literal pool before
19446 references are made to a null symbol pointer. */
a737bd4d 19447
c19d1205
ZW
19448void
19449arm_cleanup (void)
19450{
19451 literal_pool * pool;
a737bd4d 19452
c19d1205
ZW
19453 for (pool = list_of_pools; pool; pool = pool->next)
19454 {
5f4273c7 19455 /* Put it at the end of the relevant section. */
c19d1205
ZW
19456 subseg_set (pool->section, pool->sub_section);
19457#ifdef OBJ_ELF
19458 arm_elf_change_section ();
19459#endif
19460 s_ltorg (0);
19461 }
404ff6b5
AH
19462}
19463
c19d1205
ZW
19464/* Adjust the symbol table. This marks Thumb symbols as distinct from
19465 ARM ones. */
404ff6b5 19466
c19d1205
ZW
19467void
19468arm_adjust_symtab (void)
404ff6b5 19469{
c19d1205
ZW
19470#ifdef OBJ_COFF
19471 symbolS * sym;
404ff6b5 19472
c19d1205
ZW
19473 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19474 {
19475 if (ARM_IS_THUMB (sym))
19476 {
19477 if (THUMB_IS_FUNC (sym))
19478 {
19479 /* Mark the symbol as a Thumb function. */
19480 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19481 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19482 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19483
c19d1205
ZW
19484 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19485 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19486 else
19487 as_bad (_("%s: unexpected function type: %d"),
19488 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19489 }
19490 else switch (S_GET_STORAGE_CLASS (sym))
19491 {
19492 case C_EXT:
19493 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19494 break;
19495 case C_STAT:
19496 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19497 break;
19498 case C_LABEL:
19499 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19500 break;
19501 default:
19502 /* Do nothing. */
19503 break;
19504 }
19505 }
a737bd4d 19506
c19d1205
ZW
19507 if (ARM_IS_INTERWORK (sym))
19508 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19509 }
c19d1205
ZW
19510#endif
19511#ifdef OBJ_ELF
19512 symbolS * sym;
19513 char bind;
404ff6b5 19514
c19d1205 19515 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19516 {
c19d1205
ZW
19517 if (ARM_IS_THUMB (sym))
19518 {
19519 elf_symbol_type * elf_sym;
404ff6b5 19520
c19d1205
ZW
19521 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19522 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19523
b0796911
PB
19524 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19525 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19526 {
19527 /* If it's a .thumb_func, declare it as so,
19528 otherwise tag label as .code 16. */
19529 if (THUMB_IS_FUNC (sym))
19530 elf_sym->internal_elf_sym.st_info =
19531 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19532 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19533 elf_sym->internal_elf_sym.st_info =
19534 ELF_ST_INFO (bind, STT_ARM_16BIT);
19535 }
19536 }
19537 }
19538#endif
404ff6b5
AH
19539}
19540
c19d1205 19541/* MD interface: Initialization. */
404ff6b5 19542
a737bd4d 19543static void
c19d1205 19544set_constant_flonums (void)
a737bd4d 19545{
c19d1205 19546 int i;
404ff6b5 19547
c19d1205
ZW
19548 for (i = 0; i < NUM_FLOAT_VALS; i++)
19549 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19550 abort ();
a737bd4d 19551}
404ff6b5 19552
3e9e4fcf
JB
19553/* Auto-select Thumb mode if it's the only available instruction set for the
19554 given architecture. */
19555
19556static void
19557autoselect_thumb_from_cpu_variant (void)
19558{
19559 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19560 opcode_select (16);
19561}
19562
c19d1205
ZW
19563void
19564md_begin (void)
a737bd4d 19565{
c19d1205
ZW
19566 unsigned mach;
19567 unsigned int i;
404ff6b5 19568
c19d1205
ZW
19569 if ( (arm_ops_hsh = hash_new ()) == NULL
19570 || (arm_cond_hsh = hash_new ()) == NULL
19571 || (arm_shift_hsh = hash_new ()) == NULL
19572 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19573 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19574 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19575 || (arm_reloc_hsh = hash_new ()) == NULL
19576 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19577 as_fatal (_("virtual memory exhausted"));
19578
19579 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19580 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19581 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19582 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19583 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19584 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19585 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19586 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19587 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19588 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19589 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19590 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19591 for (i = 0;
19592 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19593 i++)
19594 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19595 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19596#ifdef OBJ_ELF
19597 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19598 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19599#endif
19600
19601 set_constant_flonums ();
404ff6b5 19602
c19d1205
ZW
19603 /* Set the cpu variant based on the command-line options. We prefer
19604 -mcpu= over -march= if both are set (as for GCC); and we prefer
19605 -mfpu= over any other way of setting the floating point unit.
19606 Use of legacy options with new options are faulted. */
e74cfd16 19607 if (legacy_cpu)
404ff6b5 19608 {
e74cfd16 19609 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19610 as_bad (_("use of old and new-style options to set CPU type"));
19611
19612 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19613 }
e74cfd16 19614 else if (!mcpu_cpu_opt)
c19d1205 19615 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19616
e74cfd16 19617 if (legacy_fpu)
c19d1205 19618 {
e74cfd16 19619 if (mfpu_opt)
c19d1205 19620 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19621
19622 mfpu_opt = legacy_fpu;
19623 }
e74cfd16 19624 else if (!mfpu_opt)
03b1477f 19625 {
c19d1205 19626#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19627 /* Some environments specify a default FPU. If they don't, infer it
19628 from the processor. */
e74cfd16 19629 if (mcpu_fpu_opt)
03b1477f
RE
19630 mfpu_opt = mcpu_fpu_opt;
19631 else
19632 mfpu_opt = march_fpu_opt;
39c2da32 19633#else
e74cfd16 19634 mfpu_opt = &fpu_default;
39c2da32 19635#endif
03b1477f
RE
19636 }
19637
e74cfd16 19638 if (!mfpu_opt)
03b1477f 19639 {
493cb6ef 19640 if (mcpu_cpu_opt != NULL)
e74cfd16 19641 mfpu_opt = &fpu_default;
493cb6ef 19642 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19643 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19644 else
e74cfd16 19645 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19646 }
19647
ee065d83 19648#ifdef CPU_DEFAULT
e74cfd16 19649 if (!mcpu_cpu_opt)
ee065d83 19650 {
e74cfd16
PB
19651 mcpu_cpu_opt = &cpu_default;
19652 selected_cpu = cpu_default;
ee065d83 19653 }
e74cfd16
PB
19654#else
19655 if (mcpu_cpu_opt)
19656 selected_cpu = *mcpu_cpu_opt;
ee065d83 19657 else
e74cfd16 19658 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19659#endif
03b1477f 19660
e74cfd16 19661 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19662
3e9e4fcf
JB
19663 autoselect_thumb_from_cpu_variant ();
19664
e74cfd16 19665 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19666
f17c130b 19667#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19668 {
7cc69913
NC
19669 unsigned int flags = 0;
19670
19671#if defined OBJ_ELF
19672 flags = meabi_flags;
d507cf36
PB
19673
19674 switch (meabi_flags)
33a392fb 19675 {
d507cf36 19676 case EF_ARM_EABI_UNKNOWN:
7cc69913 19677#endif
d507cf36
PB
19678 /* Set the flags in the private structure. */
19679 if (uses_apcs_26) flags |= F_APCS26;
19680 if (support_interwork) flags |= F_INTERWORK;
19681 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19682 if (pic_code) flags |= F_PIC;
e74cfd16 19683 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19684 flags |= F_SOFT_FLOAT;
19685
d507cf36
PB
19686 switch (mfloat_abi_opt)
19687 {
19688 case ARM_FLOAT_ABI_SOFT:
19689 case ARM_FLOAT_ABI_SOFTFP:
19690 flags |= F_SOFT_FLOAT;
19691 break;
33a392fb 19692
d507cf36
PB
19693 case ARM_FLOAT_ABI_HARD:
19694 if (flags & F_SOFT_FLOAT)
19695 as_bad (_("hard-float conflicts with specified fpu"));
19696 break;
19697 }
03b1477f 19698
e74cfd16
PB
19699 /* Using pure-endian doubles (even if soft-float). */
19700 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19701 flags |= F_VFP_FLOAT;
f17c130b 19702
fde78edd 19703#if defined OBJ_ELF
e74cfd16 19704 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19705 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19706 break;
19707
8cb51566 19708 case EF_ARM_EABI_VER4:
3a4a14e9 19709 case EF_ARM_EABI_VER5:
c19d1205 19710 /* No additional flags to set. */
d507cf36
PB
19711 break;
19712
19713 default:
19714 abort ();
19715 }
7cc69913 19716#endif
b99bd4ef
NC
19717 bfd_set_private_flags (stdoutput, flags);
19718
19719 /* We have run out flags in the COFF header to encode the
19720 status of ATPCS support, so instead we create a dummy,
c19d1205 19721 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19722 if (atpcs)
19723 {
19724 asection * sec;
19725
19726 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19727
19728 if (sec != NULL)
19729 {
19730 bfd_set_section_flags
19731 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19732 bfd_set_section_size (stdoutput, sec, 0);
19733 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19734 }
19735 }
7cc69913 19736 }
f17c130b 19737#endif
b99bd4ef
NC
19738
19739 /* Record the CPU type as well. */
2d447fca
JM
19740 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19741 mach = bfd_mach_arm_iWMMXt2;
19742 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19743 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19745 mach = bfd_mach_arm_XScale;
e74cfd16 19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19747 mach = bfd_mach_arm_ep9312;
e74cfd16 19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19749 mach = bfd_mach_arm_5TE;
e74cfd16 19750 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19751 {
e74cfd16 19752 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19753 mach = bfd_mach_arm_5T;
19754 else
19755 mach = bfd_mach_arm_5;
19756 }
e74cfd16 19757 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19758 {
e74cfd16 19759 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19760 mach = bfd_mach_arm_4T;
19761 else
19762 mach = bfd_mach_arm_4;
19763 }
e74cfd16 19764 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19765 mach = bfd_mach_arm_3M;
e74cfd16
PB
19766 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19767 mach = bfd_mach_arm_3;
19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19769 mach = bfd_mach_arm_2a;
19770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19771 mach = bfd_mach_arm_2;
19772 else
19773 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19774
19775 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19776}
19777
c19d1205 19778/* Command line processing. */
b99bd4ef 19779
c19d1205
ZW
19780/* md_parse_option
19781 Invocation line includes a switch not recognized by the base assembler.
19782 See if it's a processor-specific option.
b99bd4ef 19783
c19d1205
ZW
19784 This routine is somewhat complicated by the need for backwards
19785 compatibility (since older releases of gcc can't be changed).
19786 The new options try to make the interface as compatible as
19787 possible with GCC.
b99bd4ef 19788
c19d1205 19789 New options (supported) are:
b99bd4ef 19790
c19d1205
ZW
19791 -mcpu=<cpu name> Assemble for selected processor
19792 -march=<architecture name> Assemble for selected architecture
19793 -mfpu=<fpu architecture> Assemble for selected FPU.
19794 -EB/-mbig-endian Big-endian
19795 -EL/-mlittle-endian Little-endian
19796 -k Generate PIC code
19797 -mthumb Start in Thumb mode
19798 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19799
c19d1205 19800 For now we will also provide support for:
b99bd4ef 19801
c19d1205
ZW
19802 -mapcs-32 32-bit Program counter
19803 -mapcs-26 26-bit Program counter
19804 -macps-float Floats passed in FP registers
19805 -mapcs-reentrant Reentrant code
19806 -matpcs
19807 (sometime these will probably be replaced with -mapcs=<list of options>
19808 and -matpcs=<list of options>)
b99bd4ef 19809
c19d1205
ZW
19810 The remaining options are only supported for back-wards compatibility.
19811 Cpu variants, the arm part is optional:
19812 -m[arm]1 Currently not supported.
19813 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19814 -m[arm]3 Arm 3 processor
19815 -m[arm]6[xx], Arm 6 processors
19816 -m[arm]7[xx][t][[d]m] Arm 7 processors
19817 -m[arm]8[10] Arm 8 processors
19818 -m[arm]9[20][tdmi] Arm 9 processors
19819 -mstrongarm[110[0]] StrongARM processors
19820 -mxscale XScale processors
19821 -m[arm]v[2345[t[e]]] Arm architectures
19822 -mall All (except the ARM1)
19823 FP variants:
19824 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19825 -mfpe-old (No float load/store multiples)
19826 -mvfpxd VFP Single precision
19827 -mvfp All VFP
19828 -mno-fpu Disable all floating point instructions
b99bd4ef 19829
c19d1205
ZW
19830 The following CPU names are recognized:
19831 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19832 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19833 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19834 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19835 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19836 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19837 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19838
c19d1205 19839 */
b99bd4ef 19840
c19d1205 19841const char * md_shortopts = "m:k";
b99bd4ef 19842
c19d1205
ZW
19843#ifdef ARM_BI_ENDIAN
19844#define OPTION_EB (OPTION_MD_BASE + 0)
19845#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19846#else
c19d1205
ZW
19847#if TARGET_BYTES_BIG_ENDIAN
19848#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19849#else
c19d1205
ZW
19850#define OPTION_EL (OPTION_MD_BASE + 1)
19851#endif
b99bd4ef 19852#endif
845b51d6 19853#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 19854
c19d1205 19855struct option md_longopts[] =
b99bd4ef 19856{
c19d1205
ZW
19857#ifdef OPTION_EB
19858 {"EB", no_argument, NULL, OPTION_EB},
19859#endif
19860#ifdef OPTION_EL
19861 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19862#endif
845b51d6 19863 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
19864 {NULL, no_argument, NULL, 0}
19865};
b99bd4ef 19866
c19d1205 19867size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19868
c19d1205 19869struct arm_option_table
b99bd4ef 19870{
c19d1205
ZW
19871 char *option; /* Option name to match. */
19872 char *help; /* Help information. */
19873 int *var; /* Variable to change. */
19874 int value; /* What to change it to. */
19875 char *deprecated; /* If non-null, print this message. */
19876};
b99bd4ef 19877
c19d1205
ZW
19878struct arm_option_table arm_opts[] =
19879{
19880 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19881 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19882 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19883 &support_interwork, 1, NULL},
19884 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19885 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19886 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19887 1, NULL},
19888 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19889 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19890 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19891 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19892 NULL},
b99bd4ef 19893
c19d1205
ZW
19894 /* These are recognized by the assembler, but have no affect on code. */
19895 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19896 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19897 {NULL, NULL, NULL, 0, NULL}
19898};
19899
19900struct arm_legacy_option_table
19901{
19902 char *option; /* Option name to match. */
19903 const arm_feature_set **var; /* Variable to change. */
19904 const arm_feature_set value; /* What to change it to. */
19905 char *deprecated; /* If non-null, print this message. */
19906};
b99bd4ef 19907
e74cfd16
PB
19908const struct arm_legacy_option_table arm_legacy_opts[] =
19909{
c19d1205
ZW
19910 /* DON'T add any new processors to this list -- we want the whole list
19911 to go away... Add them to the processors table instead. */
e74cfd16
PB
19912 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19913 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19914 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19915 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19916 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19917 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19918 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19919 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19920 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19921 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19922 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19923 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19924 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19925 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19926 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19927 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19928 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19929 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19930 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19931 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19932 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19933 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19934 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19935 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19936 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19937 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19938 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19939 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19940 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19941 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19942 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19943 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19944 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19945 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19946 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19947 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19948 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19949 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19950 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19951 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19952 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19953 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19954 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19955 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19956 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19957 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19958 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19959 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19960 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19961 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19962 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19963 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19964 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19965 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19966 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19967 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19968 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19969 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19970 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19971 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19972 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19973 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19974 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19975 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19976 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19977 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19978 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19979 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19980 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19981 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19982 N_("use -mcpu=strongarm110")},
e74cfd16 19983 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19984 N_("use -mcpu=strongarm1100")},
e74cfd16 19985 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19986 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19987 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19988 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19989 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19990
c19d1205 19991 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19992 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19993 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19994 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19995 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19996 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19997 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19998 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19999 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20000 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20001 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20002 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20003 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20004 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20005 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20006 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20007 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20008 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20009 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20010
c19d1205 20011 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20012 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20013 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20014 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20015 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20016 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20017
e74cfd16 20018 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20019};
7ed4c4c5 20020
c19d1205 20021struct arm_cpu_option_table
7ed4c4c5 20022{
c19d1205 20023 char *name;
e74cfd16 20024 const arm_feature_set value;
c19d1205
ZW
20025 /* For some CPUs we assume an FPU unless the user explicitly sets
20026 -mfpu=... */
e74cfd16 20027 const arm_feature_set default_fpu;
ee065d83
PB
20028 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20029 case. */
20030 const char *canonical_name;
c19d1205 20031};
7ed4c4c5 20032
c19d1205
ZW
20033/* This list should, at a minimum, contain all the cpu names
20034 recognized by GCC. */
e74cfd16 20035static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20036{
ee065d83
PB
20037 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20038 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20039 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20040 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20041 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20042 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20043 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20044 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20045 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20046 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20047 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20049 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20051 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20053 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20055 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20056 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20057 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20058 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20059 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20060 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20061 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20062 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20064 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20065 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20066 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20067 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20068 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20069 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20070 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20071 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20072 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20074 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20075 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20076 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20077 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20078 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20079 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20080 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20081 /* For V5 or later processors we default to using VFP; but the user
20082 should really set the FPU type explicitly. */
ee065d83
PB
20083 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20084 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20085 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20086 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20087 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20088 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20089 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20090 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20091 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20092 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20093 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20094 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20095 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20096 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20097 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20098 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20099 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20100 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20101 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20103 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20104 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20105 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20106 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20107 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20108 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20109 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20110 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20111 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20112 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20113 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20114 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20115 | FPU_NEON_EXT_V1),
20116 NULL},
62b3e311
PB
20117 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20118 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20119 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20120 /* ??? XSCALE is really an architecture. */
ee065d83 20121 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20122 /* ??? iwmmxt is not a processor. */
ee065d83 20123 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20124 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20125 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20126 /* Maverick */
e74cfd16
PB
20127 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20128 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20129};
7ed4c4c5 20130
c19d1205 20131struct arm_arch_option_table
7ed4c4c5 20132{
c19d1205 20133 char *name;
e74cfd16
PB
20134 const arm_feature_set value;
20135 const arm_feature_set default_fpu;
c19d1205 20136};
7ed4c4c5 20137
c19d1205
ZW
20138/* This list should, at a minimum, contain all the architecture names
20139 recognized by GCC. */
e74cfd16 20140static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20141{
20142 {"all", ARM_ANY, FPU_ARCH_FPA},
20143 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20144 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20145 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20146 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20147 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20148 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20149 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20150 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20151 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20152 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20153 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20154 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20155 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20156 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20157 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20158 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20159 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20160 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20161 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20162 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20163 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20164 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20165 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20166 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20167 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20168 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20169 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20170 /* The official spelling of the ARMv7 profile variants is the dashed form.
20171 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20172 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20173 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20174 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20175 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20176 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20177 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20178 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20179 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20180 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20181 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20182};
7ed4c4c5 20183
c19d1205 20184/* ISA extensions in the co-processor space. */
e74cfd16 20185struct arm_option_cpu_value_table
c19d1205
ZW
20186{
20187 char *name;
e74cfd16 20188 const arm_feature_set value;
c19d1205 20189};
7ed4c4c5 20190
e74cfd16 20191static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20192{
e74cfd16
PB
20193 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20194 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20195 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20196 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20197 {NULL, ARM_ARCH_NONE}
c19d1205 20198};
7ed4c4c5 20199
c19d1205
ZW
20200/* This list should, at a minimum, contain all the fpu names
20201 recognized by GCC. */
e74cfd16 20202static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20203{
20204 {"softfpa", FPU_NONE},
20205 {"fpe", FPU_ARCH_FPE},
20206 {"fpe2", FPU_ARCH_FPE},
20207 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20208 {"fpa", FPU_ARCH_FPA},
20209 {"fpa10", FPU_ARCH_FPA},
20210 {"fpa11", FPU_ARCH_FPA},
20211 {"arm7500fe", FPU_ARCH_FPA},
20212 {"softvfp", FPU_ARCH_VFP},
20213 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20214 {"vfp", FPU_ARCH_VFP_V2},
20215 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 20216 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
20217 {"vfp10", FPU_ARCH_VFP_V2},
20218 {"vfp10-r0", FPU_ARCH_VFP_V1},
20219 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
20220 {"vfpv2", FPU_ARCH_VFP_V2},
20221 {"vfpv3", FPU_ARCH_VFP_V3},
20222 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
20223 {"arm1020t", FPU_ARCH_VFP_V1},
20224 {"arm1020e", FPU_ARCH_VFP_V2},
20225 {"arm1136jfs", FPU_ARCH_VFP_V2},
20226 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20227 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20228 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20229 {NULL, ARM_ARCH_NONE}
20230};
20231
20232struct arm_option_value_table
20233{
20234 char *name;
20235 long value;
c19d1205 20236};
7ed4c4c5 20237
e74cfd16 20238static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20239{
20240 {"hard", ARM_FLOAT_ABI_HARD},
20241 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20242 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20243 {NULL, 0}
c19d1205 20244};
7ed4c4c5 20245
c19d1205 20246#ifdef OBJ_ELF
3a4a14e9 20247/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20248static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20249{
20250 {"gnu", EF_ARM_EABI_UNKNOWN},
20251 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20252 {"5", EF_ARM_EABI_VER5},
e74cfd16 20253 {NULL, 0}
c19d1205
ZW
20254};
20255#endif
7ed4c4c5 20256
c19d1205
ZW
20257struct arm_long_option_table
20258{
20259 char * option; /* Substring to match. */
20260 char * help; /* Help information. */
20261 int (* func) (char * subopt); /* Function to decode sub-option. */
20262 char * deprecated; /* If non-null, print this message. */
20263};
7ed4c4c5
NC
20264
20265static int
e74cfd16 20266arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20267{
e74cfd16
PB
20268 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20269
20270 /* Copy the feature set, so that we can modify it. */
20271 *ext_set = **opt_p;
20272 *opt_p = ext_set;
20273
c19d1205 20274 while (str != NULL && *str != 0)
7ed4c4c5 20275 {
e74cfd16 20276 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20277 char * ext;
20278 int optlen;
7ed4c4c5 20279
c19d1205
ZW
20280 if (*str != '+')
20281 {
20282 as_bad (_("invalid architectural extension"));
20283 return 0;
20284 }
7ed4c4c5 20285
c19d1205
ZW
20286 str++;
20287 ext = strchr (str, '+');
7ed4c4c5 20288
c19d1205
ZW
20289 if (ext != NULL)
20290 optlen = ext - str;
20291 else
20292 optlen = strlen (str);
7ed4c4c5 20293
c19d1205
ZW
20294 if (optlen == 0)
20295 {
20296 as_bad (_("missing architectural extension"));
20297 return 0;
20298 }
7ed4c4c5 20299
c19d1205
ZW
20300 for (opt = arm_extensions; opt->name != NULL; opt++)
20301 if (strncmp (opt->name, str, optlen) == 0)
20302 {
e74cfd16 20303 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20304 break;
20305 }
7ed4c4c5 20306
c19d1205
ZW
20307 if (opt->name == NULL)
20308 {
5f4273c7 20309 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20310 return 0;
20311 }
7ed4c4c5 20312
c19d1205
ZW
20313 str = ext;
20314 };
7ed4c4c5 20315
c19d1205
ZW
20316 return 1;
20317}
7ed4c4c5 20318
c19d1205
ZW
20319static int
20320arm_parse_cpu (char * str)
7ed4c4c5 20321{
e74cfd16 20322 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20323 char * ext = strchr (str, '+');
20324 int optlen;
7ed4c4c5 20325
c19d1205
ZW
20326 if (ext != NULL)
20327 optlen = ext - str;
7ed4c4c5 20328 else
c19d1205 20329 optlen = strlen (str);
7ed4c4c5 20330
c19d1205 20331 if (optlen == 0)
7ed4c4c5 20332 {
c19d1205
ZW
20333 as_bad (_("missing cpu name `%s'"), str);
20334 return 0;
7ed4c4c5
NC
20335 }
20336
c19d1205
ZW
20337 for (opt = arm_cpus; opt->name != NULL; opt++)
20338 if (strncmp (opt->name, str, optlen) == 0)
20339 {
e74cfd16
PB
20340 mcpu_cpu_opt = &opt->value;
20341 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 20342 if (opt->canonical_name)
5f4273c7 20343 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20344 else
20345 {
20346 int i;
20347 for (i = 0; i < optlen; i++)
20348 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20349 selected_cpu_name[i] = 0;
20350 }
7ed4c4c5 20351
c19d1205
ZW
20352 if (ext != NULL)
20353 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20354
c19d1205
ZW
20355 return 1;
20356 }
7ed4c4c5 20357
c19d1205
ZW
20358 as_bad (_("unknown cpu `%s'"), str);
20359 return 0;
7ed4c4c5
NC
20360}
20361
c19d1205
ZW
20362static int
20363arm_parse_arch (char * str)
7ed4c4c5 20364{
e74cfd16 20365 const struct arm_arch_option_table *opt;
c19d1205
ZW
20366 char *ext = strchr (str, '+');
20367 int optlen;
7ed4c4c5 20368
c19d1205
ZW
20369 if (ext != NULL)
20370 optlen = ext - str;
7ed4c4c5 20371 else
c19d1205 20372 optlen = strlen (str);
7ed4c4c5 20373
c19d1205 20374 if (optlen == 0)
7ed4c4c5 20375 {
c19d1205
ZW
20376 as_bad (_("missing architecture name `%s'"), str);
20377 return 0;
7ed4c4c5
NC
20378 }
20379
c19d1205
ZW
20380 for (opt = arm_archs; opt->name != NULL; opt++)
20381 if (streq (opt->name, str))
20382 {
e74cfd16
PB
20383 march_cpu_opt = &opt->value;
20384 march_fpu_opt = &opt->default_fpu;
5f4273c7 20385 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 20386
c19d1205
ZW
20387 if (ext != NULL)
20388 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20389
c19d1205
ZW
20390 return 1;
20391 }
20392
20393 as_bad (_("unknown architecture `%s'\n"), str);
20394 return 0;
7ed4c4c5 20395}
eb043451 20396
c19d1205
ZW
20397static int
20398arm_parse_fpu (char * str)
20399{
e74cfd16 20400 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20401
c19d1205
ZW
20402 for (opt = arm_fpus; opt->name != NULL; opt++)
20403 if (streq (opt->name, str))
20404 {
e74cfd16 20405 mfpu_opt = &opt->value;
c19d1205
ZW
20406 return 1;
20407 }
b99bd4ef 20408
c19d1205
ZW
20409 as_bad (_("unknown floating point format `%s'\n"), str);
20410 return 0;
20411}
20412
20413static int
20414arm_parse_float_abi (char * str)
b99bd4ef 20415{
e74cfd16 20416 const struct arm_option_value_table * opt;
b99bd4ef 20417
c19d1205
ZW
20418 for (opt = arm_float_abis; opt->name != NULL; opt++)
20419 if (streq (opt->name, str))
20420 {
20421 mfloat_abi_opt = opt->value;
20422 return 1;
20423 }
cc8a6dd0 20424
c19d1205
ZW
20425 as_bad (_("unknown floating point abi `%s'\n"), str);
20426 return 0;
20427}
b99bd4ef 20428
c19d1205
ZW
20429#ifdef OBJ_ELF
20430static int
20431arm_parse_eabi (char * str)
20432{
e74cfd16 20433 const struct arm_option_value_table *opt;
cc8a6dd0 20434
c19d1205
ZW
20435 for (opt = arm_eabis; opt->name != NULL; opt++)
20436 if (streq (opt->name, str))
20437 {
20438 meabi_flags = opt->value;
20439 return 1;
20440 }
20441 as_bad (_("unknown EABI `%s'\n"), str);
20442 return 0;
20443}
20444#endif
cc8a6dd0 20445
c19d1205
ZW
20446struct arm_long_option_table arm_long_opts[] =
20447{
20448 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20449 arm_parse_cpu, NULL},
20450 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20451 arm_parse_arch, NULL},
20452 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20453 arm_parse_fpu, NULL},
20454 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20455 arm_parse_float_abi, NULL},
20456#ifdef OBJ_ELF
20457 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20458 arm_parse_eabi, NULL},
20459#endif
20460 {NULL, NULL, 0, NULL}
20461};
cc8a6dd0 20462
c19d1205
ZW
20463int
20464md_parse_option (int c, char * arg)
20465{
20466 struct arm_option_table *opt;
e74cfd16 20467 const struct arm_legacy_option_table *fopt;
c19d1205 20468 struct arm_long_option_table *lopt;
b99bd4ef 20469
c19d1205 20470 switch (c)
b99bd4ef 20471 {
c19d1205
ZW
20472#ifdef OPTION_EB
20473 case OPTION_EB:
20474 target_big_endian = 1;
20475 break;
20476#endif
cc8a6dd0 20477
c19d1205
ZW
20478#ifdef OPTION_EL
20479 case OPTION_EL:
20480 target_big_endian = 0;
20481 break;
20482#endif
b99bd4ef 20483
845b51d6
PB
20484 case OPTION_FIX_V4BX:
20485 fix_v4bx = TRUE;
20486 break;
20487
c19d1205
ZW
20488 case 'a':
20489 /* Listing option. Just ignore these, we don't support additional
20490 ones. */
20491 return 0;
b99bd4ef 20492
c19d1205
ZW
20493 default:
20494 for (opt = arm_opts; opt->option != NULL; opt++)
20495 {
20496 if (c == opt->option[0]
20497 && ((arg == NULL && opt->option[1] == 0)
20498 || streq (arg, opt->option + 1)))
20499 {
20500#if WARN_DEPRECATED
20501 /* If the option is deprecated, tell the user. */
20502 if (opt->deprecated != NULL)
20503 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20504 arg ? arg : "", _(opt->deprecated));
20505#endif
b99bd4ef 20506
c19d1205
ZW
20507 if (opt->var != NULL)
20508 *opt->var = opt->value;
cc8a6dd0 20509
c19d1205
ZW
20510 return 1;
20511 }
20512 }
b99bd4ef 20513
e74cfd16
PB
20514 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20515 {
20516 if (c == fopt->option[0]
20517 && ((arg == NULL && fopt->option[1] == 0)
20518 || streq (arg, fopt->option + 1)))
20519 {
20520#if WARN_DEPRECATED
20521 /* If the option is deprecated, tell the user. */
20522 if (fopt->deprecated != NULL)
20523 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20524 arg ? arg : "", _(fopt->deprecated));
20525#endif
20526
20527 if (fopt->var != NULL)
20528 *fopt->var = &fopt->value;
20529
20530 return 1;
20531 }
20532 }
20533
c19d1205
ZW
20534 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20535 {
20536 /* These options are expected to have an argument. */
20537 if (c == lopt->option[0]
20538 && arg != NULL
20539 && strncmp (arg, lopt->option + 1,
20540 strlen (lopt->option + 1)) == 0)
20541 {
20542#if WARN_DEPRECATED
20543 /* If the option is deprecated, tell the user. */
20544 if (lopt->deprecated != NULL)
20545 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20546 _(lopt->deprecated));
20547#endif
b99bd4ef 20548
c19d1205
ZW
20549 /* Call the sup-option parser. */
20550 return lopt->func (arg + strlen (lopt->option) - 1);
20551 }
20552 }
a737bd4d 20553
c19d1205
ZW
20554 return 0;
20555 }
a394c00f 20556
c19d1205
ZW
20557 return 1;
20558}
a394c00f 20559
c19d1205
ZW
20560void
20561md_show_usage (FILE * fp)
a394c00f 20562{
c19d1205
ZW
20563 struct arm_option_table *opt;
20564 struct arm_long_option_table *lopt;
a394c00f 20565
c19d1205 20566 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20567
c19d1205
ZW
20568 for (opt = arm_opts; opt->option != NULL; opt++)
20569 if (opt->help != NULL)
20570 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20571
c19d1205
ZW
20572 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20573 if (lopt->help != NULL)
20574 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20575
c19d1205
ZW
20576#ifdef OPTION_EB
20577 fprintf (fp, _("\
20578 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20579#endif
20580
c19d1205
ZW
20581#ifdef OPTION_EL
20582 fprintf (fp, _("\
20583 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20584#endif
845b51d6
PB
20585
20586 fprintf (fp, _("\
20587 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 20588}
ee065d83
PB
20589
20590
20591#ifdef OBJ_ELF
62b3e311
PB
20592typedef struct
20593{
20594 int val;
20595 arm_feature_set flags;
20596} cpu_arch_ver_table;
20597
20598/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20599 least features first. */
20600static const cpu_arch_ver_table cpu_arch_ver[] =
20601{
20602 {1, ARM_ARCH_V4},
20603 {2, ARM_ARCH_V4T},
20604 {3, ARM_ARCH_V5},
20605 {4, ARM_ARCH_V5TE},
20606 {5, ARM_ARCH_V5TEJ},
20607 {6, ARM_ARCH_V6},
20608 {7, ARM_ARCH_V6Z},
7e806470
PB
20609 {9, ARM_ARCH_V6K},
20610 {9, ARM_ARCH_V6M},
20611 {8, ARM_ARCH_V6T2},
62b3e311
PB
20612 {10, ARM_ARCH_V7A},
20613 {10, ARM_ARCH_V7R},
20614 {10, ARM_ARCH_V7M},
20615 {0, ARM_ARCH_NONE}
20616};
20617
ee065d83
PB
20618/* Set the public EABI object attributes. */
20619static void
20620aeabi_set_public_attributes (void)
20621{
20622 int arch;
e74cfd16 20623 arm_feature_set flags;
62b3e311
PB
20624 arm_feature_set tmp;
20625 const cpu_arch_ver_table *p;
ee065d83
PB
20626
20627 /* Choose the architecture based on the capabilities of the requested cpu
20628 (if any) and/or the instructions actually used. */
e74cfd16
PB
20629 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20630 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20631 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20632 /*Allow the user to override the reported architecture. */
20633 if (object_arch)
20634 {
20635 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20636 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20637 }
20638
62b3e311
PB
20639 tmp = flags;
20640 arch = 0;
20641 for (p = cpu_arch_ver; p->val; p++)
20642 {
20643 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20644 {
20645 arch = p->val;
20646 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20647 }
20648 }
ee065d83
PB
20649
20650 /* Tag_CPU_name. */
20651 if (selected_cpu_name[0])
20652 {
20653 char *p;
20654
20655 p = selected_cpu_name;
5f4273c7 20656 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
20657 {
20658 int i;
5f4273c7 20659
ee065d83
PB
20660 p += 4;
20661 for (i = 0; p[i]; i++)
20662 p[i] = TOUPPER (p[i]);
20663 }
104d59d1 20664 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
ee065d83
PB
20665 }
20666 /* Tag_CPU_arch. */
104d59d1 20667 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
62b3e311
PB
20668 /* Tag_CPU_arch_profile. */
20669 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
104d59d1 20670 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
62b3e311 20671 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
104d59d1 20672 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
7e806470 20673 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
104d59d1 20674 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
ee065d83 20675 /* Tag_ARM_ISA_use. */
e74cfd16 20676 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
104d59d1 20677 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
ee065d83 20678 /* Tag_THUMB_ISA_use. */
e74cfd16 20679 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
104d59d1 20680 bfd_elf_add_proc_attr_int (stdoutput, 9,
e74cfd16 20681 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20682 /* Tag_VFP_arch. */
b1cc4aeb
PB
20683 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_d32)
20684 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_d32))
20685 bfd_elf_add_proc_attr_int (stdoutput, 10, 4);
20686 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
5287ad62 20687 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
104d59d1 20688 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
5287ad62
JB
20689 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20690 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
104d59d1 20691 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
5287ad62
JB
20692 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20693 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20694 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20695 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
104d59d1 20696 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
ee065d83 20697 /* Tag_WMMX_arch. */
e74cfd16
PB
20698 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20699 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
104d59d1 20700 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
5287ad62
JB
20701 /* Tag_NEON_arch. */
20702 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20703 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
104d59d1 20704 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
ee065d83
PB
20705}
20706
104d59d1 20707/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
20708void
20709arm_md_end (void)
20710{
ee065d83
PB
20711 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20712 return;
20713
20714 aeabi_set_public_attributes ();
ee065d83 20715}
8463be01 20716#endif /* OBJ_ELF */
ee065d83
PB
20717
20718
20719/* Parse a .cpu directive. */
20720
20721static void
20722s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20723{
e74cfd16 20724 const struct arm_cpu_option_table *opt;
ee065d83
PB
20725 char *name;
20726 char saved_char;
20727
20728 name = input_line_pointer;
5f4273c7 20729 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20730 input_line_pointer++;
20731 saved_char = *input_line_pointer;
20732 *input_line_pointer = 0;
20733
20734 /* Skip the first "all" entry. */
20735 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20736 if (streq (opt->name, name))
20737 {
e74cfd16
PB
20738 mcpu_cpu_opt = &opt->value;
20739 selected_cpu = opt->value;
ee065d83 20740 if (opt->canonical_name)
5f4273c7 20741 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20742 else
20743 {
20744 int i;
20745 for (i = 0; opt->name[i]; i++)
20746 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20747 selected_cpu_name[i] = 0;
20748 }
e74cfd16 20749 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20750 *input_line_pointer = saved_char;
20751 demand_empty_rest_of_line ();
20752 return;
20753 }
20754 as_bad (_("unknown cpu `%s'"), name);
20755 *input_line_pointer = saved_char;
20756 ignore_rest_of_line ();
20757}
20758
20759
20760/* Parse a .arch directive. */
20761
20762static void
20763s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20764{
e74cfd16 20765 const struct arm_arch_option_table *opt;
ee065d83
PB
20766 char saved_char;
20767 char *name;
20768
20769 name = input_line_pointer;
5f4273c7 20770 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20771 input_line_pointer++;
20772 saved_char = *input_line_pointer;
20773 *input_line_pointer = 0;
20774
20775 /* Skip the first "all" entry. */
20776 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20777 if (streq (opt->name, name))
20778 {
e74cfd16
PB
20779 mcpu_cpu_opt = &opt->value;
20780 selected_cpu = opt->value;
5f4273c7 20781 strcpy (selected_cpu_name, opt->name);
e74cfd16 20782 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20783 *input_line_pointer = saved_char;
20784 demand_empty_rest_of_line ();
20785 return;
20786 }
20787
20788 as_bad (_("unknown architecture `%s'\n"), name);
20789 *input_line_pointer = saved_char;
20790 ignore_rest_of_line ();
20791}
20792
20793
7a1d4c38
PB
20794/* Parse a .object_arch directive. */
20795
20796static void
20797s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20798{
20799 const struct arm_arch_option_table *opt;
20800 char saved_char;
20801 char *name;
20802
20803 name = input_line_pointer;
5f4273c7 20804 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
20805 input_line_pointer++;
20806 saved_char = *input_line_pointer;
20807 *input_line_pointer = 0;
20808
20809 /* Skip the first "all" entry. */
20810 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20811 if (streq (opt->name, name))
20812 {
20813 object_arch = &opt->value;
20814 *input_line_pointer = saved_char;
20815 demand_empty_rest_of_line ();
20816 return;
20817 }
20818
20819 as_bad (_("unknown architecture `%s'\n"), name);
20820 *input_line_pointer = saved_char;
20821 ignore_rest_of_line ();
20822}
20823
20824
ee065d83
PB
20825/* Parse a .fpu directive. */
20826
20827static void
20828s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20829{
e74cfd16 20830 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20831 char saved_char;
20832 char *name;
20833
20834 name = input_line_pointer;
5f4273c7 20835 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20836 input_line_pointer++;
20837 saved_char = *input_line_pointer;
20838 *input_line_pointer = 0;
5f4273c7 20839
ee065d83
PB
20840 for (opt = arm_fpus; opt->name != NULL; opt++)
20841 if (streq (opt->name, name))
20842 {
e74cfd16
PB
20843 mfpu_opt = &opt->value;
20844 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20845 *input_line_pointer = saved_char;
20846 demand_empty_rest_of_line ();
20847 return;
20848 }
20849
20850 as_bad (_("unknown floating point format `%s'\n"), name);
20851 *input_line_pointer = saved_char;
20852 ignore_rest_of_line ();
20853}
ee065d83 20854
794ba86a
DJ
20855/* Copy symbol information. */
20856void
20857arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20858{
20859 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20860}
This page took 1.816109 seconds and 4 git commands to generate.