gdb/
[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,
35997600 3 2004, 2005, 2006, 2007, 2008
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 {
35997600
NC
12721 unsigned immbits;
12722 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12723
037e8744
JB
12724 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12725 return;
12726
12727 /* Fixed-point conversion with #0 immediate is encoded as an
12728 integer conversion. */
12729 if (inst.operands[2].present && inst.operands[2].imm == 0)
12730 goto int_encode;
35997600 12731 immbits = 32 - inst.operands[2].imm;
037e8744
JB
12732 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12733 if (flavour != -1)
12734 inst.instruction |= enctab[flavour];
12735 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12736 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12737 inst.instruction |= LOW4 (inst.operands[1].reg);
12738 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12739 inst.instruction |= neon_quad (rs) << 6;
12740 inst.instruction |= 1 << 21;
12741 inst.instruction |= immbits << 16;
12742
12743 inst.instruction = neon_dp_fixup (inst.instruction);
12744 }
12745 break;
12746
12747 case NS_DD:
12748 case NS_QQ:
12749 int_encode:
12750 {
12751 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12752
12753 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12754
12755 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12756 return;
12757
12758 if (flavour != -1)
12759 inst.instruction |= enctab[flavour];
12760
12761 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12762 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12763 inst.instruction |= LOW4 (inst.operands[1].reg);
12764 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12765 inst.instruction |= neon_quad (rs) << 6;
12766 inst.instruction |= 2 << 18;
12767
12768 inst.instruction = neon_dp_fixup (inst.instruction);
12769 }
12770 break;
12771
12772 default:
12773 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12774 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12775 }
5287ad62
JB
12776}
12777
12778static void
12779neon_move_immediate (void)
12780{
037e8744
JB
12781 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12782 struct neon_type_el et = neon_check_type (2, rs,
12783 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12784 unsigned immlo, immhi = 0, immbits;
c96612cc 12785 int op, cmode, float_p;
5287ad62 12786
037e8744
JB
12787 constraint (et.type == NT_invtype,
12788 _("operand size must be specified for immediate VMOV"));
12789
5287ad62
JB
12790 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12791 op = (inst.instruction & (1 << 5)) != 0;
12792
12793 immlo = inst.operands[1].imm;
12794 if (inst.operands[1].regisimm)
12795 immhi = inst.operands[1].reg;
12796
12797 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12798 _("immediate has bits set outside the operand size"));
12799
c96612cc
JB
12800 float_p = inst.operands[1].immisfloat;
12801
12802 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12803 et.size, et.type)) == FAIL)
5287ad62
JB
12804 {
12805 /* Invert relevant bits only. */
12806 neon_invert_size (&immlo, &immhi, et.size);
12807 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12808 with one or the other; those cases are caught by
12809 neon_cmode_for_move_imm. */
12810 op = !op;
c96612cc
JB
12811 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12812 &op, et.size, et.type)) == FAIL)
5287ad62 12813 {
dcbf9037 12814 first_error (_("immediate out of range"));
5287ad62
JB
12815 return;
12816 }
12817 }
12818
12819 inst.instruction &= ~(1 << 5);
12820 inst.instruction |= op << 5;
12821
12822 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12823 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12824 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12825 inst.instruction |= cmode << 8;
12826
12827 neon_write_immbits (immbits);
12828}
12829
12830static void
12831do_neon_mvn (void)
12832{
12833 if (inst.operands[1].isreg)
12834 {
037e8744 12835 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 12836
5287ad62
JB
12837 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12838 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12839 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12840 inst.instruction |= LOW4 (inst.operands[1].reg);
12841 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12842 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12843 }
12844 else
12845 {
12846 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12847 neon_move_immediate ();
12848 }
12849
12850 inst.instruction = neon_dp_fixup (inst.instruction);
12851}
12852
12853/* Encode instructions of form:
12854
12855 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 12856 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
12857
12858static void
12859neon_mixed_length (struct neon_type_el et, unsigned size)
12860{
12861 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12862 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12863 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12864 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12865 inst.instruction |= LOW4 (inst.operands[2].reg);
12866 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12867 inst.instruction |= (et.type == NT_unsigned) << 24;
12868 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12869
5287ad62
JB
12870 inst.instruction = neon_dp_fixup (inst.instruction);
12871}
12872
12873static void
12874do_neon_dyadic_long (void)
12875{
12876 /* FIXME: Type checking for lengthening op. */
12877 struct neon_type_el et = neon_check_type (3, NS_QDD,
12878 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12879 neon_mixed_length (et, et.size);
12880}
12881
12882static void
12883do_neon_abal (void)
12884{
12885 struct neon_type_el et = neon_check_type (3, NS_QDD,
12886 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12887 neon_mixed_length (et, et.size);
12888}
12889
12890static void
12891neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12892{
12893 if (inst.operands[2].isscalar)
12894 {
dcbf9037
JB
12895 struct neon_type_el et = neon_check_type (3, NS_QDS,
12896 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12897 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12898 neon_mul_mac (et, et.type == NT_unsigned);
12899 }
12900 else
12901 {
12902 struct neon_type_el et = neon_check_type (3, NS_QDD,
12903 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12904 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12905 neon_mixed_length (et, et.size);
12906 }
12907}
12908
12909static void
12910do_neon_mac_maybe_scalar_long (void)
12911{
12912 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12913}
12914
12915static void
12916do_neon_dyadic_wide (void)
12917{
12918 struct neon_type_el et = neon_check_type (3, NS_QQD,
12919 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12920 neon_mixed_length (et, et.size);
12921}
12922
12923static void
12924do_neon_dyadic_narrow (void)
12925{
12926 struct neon_type_el et = neon_check_type (3, NS_QDD,
12927 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12928 /* Operand sign is unimportant, and the U bit is part of the opcode,
12929 so force the operand type to integer. */
12930 et.type = NT_integer;
5287ad62
JB
12931 neon_mixed_length (et, et.size / 2);
12932}
12933
12934static void
12935do_neon_mul_sat_scalar_long (void)
12936{
12937 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12938}
12939
12940static void
12941do_neon_vmull (void)
12942{
12943 if (inst.operands[2].isscalar)
12944 do_neon_mac_maybe_scalar_long ();
12945 else
12946 {
12947 struct neon_type_el et = neon_check_type (3, NS_QDD,
12948 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12949 if (et.type == NT_poly)
12950 inst.instruction = NEON_ENC_POLY (inst.instruction);
12951 else
12952 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12953 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12954 zero. Should be OK as-is. */
12955 neon_mixed_length (et, et.size);
12956 }
12957}
12958
12959static void
12960do_neon_ext (void)
12961{
037e8744 12962 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12963 struct neon_type_el et = neon_check_type (3, rs,
12964 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12965 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
12966
12967 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
12968 _("shift out of range"));
5287ad62
JB
12969 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12970 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12971 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12972 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12973 inst.instruction |= LOW4 (inst.operands[2].reg);
12974 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12975 inst.instruction |= neon_quad (rs) << 6;
5287ad62 12976 inst.instruction |= imm << 8;
5f4273c7 12977
5287ad62
JB
12978 inst.instruction = neon_dp_fixup (inst.instruction);
12979}
12980
12981static void
12982do_neon_rev (void)
12983{
037e8744 12984 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12985 struct neon_type_el et = neon_check_type (2, rs,
12986 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12987 unsigned op = (inst.instruction >> 7) & 3;
12988 /* N (width of reversed regions) is encoded as part of the bitmask. We
12989 extract it here to check the elements to be reversed are smaller.
12990 Otherwise we'd get a reserved instruction. */
12991 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12992 assert (elsize != 0);
12993 constraint (et.size >= elsize,
12994 _("elements must be smaller than reversal region"));
037e8744 12995 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12996}
12997
12998static void
12999do_neon_dup (void)
13000{
13001 if (inst.operands[1].isscalar)
13002 {
037e8744 13003 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13004 struct neon_type_el et = neon_check_type (2, rs,
13005 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13006 unsigned sizebits = et.size >> 3;
dcbf9037 13007 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13008 int logsize = neon_logbits (et.size);
dcbf9037 13009 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13010
13011 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13012 return;
13013
5287ad62
JB
13014 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13015 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13016 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13017 inst.instruction |= LOW4 (dm);
13018 inst.instruction |= HI1 (dm) << 5;
037e8744 13019 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13020 inst.instruction |= x << 17;
13021 inst.instruction |= sizebits << 16;
5f4273c7 13022
5287ad62
JB
13023 inst.instruction = neon_dp_fixup (inst.instruction);
13024 }
13025 else
13026 {
037e8744
JB
13027 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13028 struct neon_type_el et = neon_check_type (2, rs,
13029 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13030 /* Duplicate ARM register to lanes of vector. */
13031 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13032 switch (et.size)
13033 {
13034 case 8: inst.instruction |= 0x400000; break;
13035 case 16: inst.instruction |= 0x000020; break;
13036 case 32: inst.instruction |= 0x000000; break;
13037 default: break;
13038 }
13039 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13040 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13041 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13042 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13043 /* The encoding for this instruction is identical for the ARM and Thumb
13044 variants, except for the condition field. */
037e8744 13045 do_vfp_cond_or_thumb ();
5287ad62
JB
13046 }
13047}
13048
13049/* VMOV has particularly many variations. It can be one of:
13050 0. VMOV<c><q> <Qd>, <Qm>
13051 1. VMOV<c><q> <Dd>, <Dm>
13052 (Register operations, which are VORR with Rm = Rn.)
13053 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13054 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13055 (Immediate loads.)
13056 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13057 (ARM register to scalar.)
13058 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13059 (Two ARM registers to vector.)
13060 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13061 (Scalar to ARM register.)
13062 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13063 (Vector to two ARM registers.)
037e8744
JB
13064 8. VMOV.F32 <Sd>, <Sm>
13065 9. VMOV.F64 <Dd>, <Dm>
13066 (VFP register moves.)
13067 10. VMOV.F32 <Sd>, #imm
13068 11. VMOV.F64 <Dd>, #imm
13069 (VFP float immediate load.)
13070 12. VMOV <Rd>, <Sm>
13071 (VFP single to ARM reg.)
13072 13. VMOV <Sd>, <Rm>
13073 (ARM reg to VFP single.)
13074 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13075 (Two ARM regs to two VFP singles.)
13076 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13077 (Two VFP singles to two ARM regs.)
5f4273c7 13078
037e8744
JB
13079 These cases can be disambiguated using neon_select_shape, except cases 1/9
13080 and 3/11 which depend on the operand type too.
5f4273c7 13081
5287ad62 13082 All the encoded bits are hardcoded by this function.
5f4273c7 13083
b7fc2769
JB
13084 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13085 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13086
5287ad62 13087 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13088 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13089
13090static void
13091do_neon_mov (void)
13092{
037e8744
JB
13093 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13094 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13095 NS_NULL);
13096 struct neon_type_el et;
13097 const char *ldconst = 0;
5287ad62 13098
037e8744 13099 switch (rs)
5287ad62 13100 {
037e8744
JB
13101 case NS_DD: /* case 1/9. */
13102 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13103 /* It is not an error here if no type is given. */
13104 inst.error = NULL;
13105 if (et.type == NT_float && et.size == 64)
5287ad62 13106 {
037e8744
JB
13107 do_vfp_nsyn_opcode ("fcpyd");
13108 break;
5287ad62 13109 }
037e8744 13110 /* fall through. */
5287ad62 13111
037e8744
JB
13112 case NS_QQ: /* case 0/1. */
13113 {
13114 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13115 return;
13116 /* The architecture manual I have doesn't explicitly state which
13117 value the U bit should have for register->register moves, but
13118 the equivalent VORR instruction has U = 0, so do that. */
13119 inst.instruction = 0x0200110;
13120 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13121 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13122 inst.instruction |= LOW4 (inst.operands[1].reg);
13123 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13124 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13125 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13126 inst.instruction |= neon_quad (rs) << 6;
13127
13128 inst.instruction = neon_dp_fixup (inst.instruction);
13129 }
13130 break;
5f4273c7 13131
037e8744
JB
13132 case NS_DI: /* case 3/11. */
13133 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13134 inst.error = NULL;
13135 if (et.type == NT_float && et.size == 64)
5287ad62 13136 {
037e8744
JB
13137 /* case 11 (fconstd). */
13138 ldconst = "fconstd";
13139 goto encode_fconstd;
5287ad62 13140 }
037e8744
JB
13141 /* fall through. */
13142
13143 case NS_QI: /* case 2/3. */
13144 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13145 return;
13146 inst.instruction = 0x0800010;
13147 neon_move_immediate ();
13148 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13149 break;
5f4273c7 13150
037e8744
JB
13151 case NS_SR: /* case 4. */
13152 {
13153 unsigned bcdebits = 0;
13154 struct neon_type_el et = neon_check_type (2, NS_NULL,
13155 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13156 int logsize = neon_logbits (et.size);
13157 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13158 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13159
13160 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13161 _(BAD_FPU));
13162 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13163 && et.size != 32, _(BAD_FPU));
13164 constraint (et.type == NT_invtype, _("bad type for scalar"));
13165 constraint (x >= 64 / et.size, _("scalar index out of range"));
13166
13167 switch (et.size)
13168 {
13169 case 8: bcdebits = 0x8; break;
13170 case 16: bcdebits = 0x1; break;
13171 case 32: bcdebits = 0x0; break;
13172 default: ;
13173 }
13174
13175 bcdebits |= x << logsize;
13176
13177 inst.instruction = 0xe000b10;
13178 do_vfp_cond_or_thumb ();
13179 inst.instruction |= LOW4 (dn) << 16;
13180 inst.instruction |= HI1 (dn) << 7;
13181 inst.instruction |= inst.operands[1].reg << 12;
13182 inst.instruction |= (bcdebits & 3) << 5;
13183 inst.instruction |= (bcdebits >> 2) << 21;
13184 }
13185 break;
5f4273c7 13186
037e8744 13187 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13188 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13189 _(BAD_FPU));
b7fc2769 13190
037e8744
JB
13191 inst.instruction = 0xc400b10;
13192 do_vfp_cond_or_thumb ();
13193 inst.instruction |= LOW4 (inst.operands[0].reg);
13194 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13195 inst.instruction |= inst.operands[1].reg << 12;
13196 inst.instruction |= inst.operands[2].reg << 16;
13197 break;
5f4273c7 13198
037e8744
JB
13199 case NS_RS: /* case 6. */
13200 {
13201 struct neon_type_el et = neon_check_type (2, NS_NULL,
13202 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13203 unsigned logsize = neon_logbits (et.size);
13204 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13205 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13206 unsigned abcdebits = 0;
13207
13208 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13209 _(BAD_FPU));
13210 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13211 && et.size != 32, _(BAD_FPU));
13212 constraint (et.type == NT_invtype, _("bad type for scalar"));
13213 constraint (x >= 64 / et.size, _("scalar index out of range"));
13214
13215 switch (et.size)
13216 {
13217 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13218 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13219 case 32: abcdebits = 0x00; break;
13220 default: ;
13221 }
13222
13223 abcdebits |= x << logsize;
13224 inst.instruction = 0xe100b10;
13225 do_vfp_cond_or_thumb ();
13226 inst.instruction |= LOW4 (dn) << 16;
13227 inst.instruction |= HI1 (dn) << 7;
13228 inst.instruction |= inst.operands[0].reg << 12;
13229 inst.instruction |= (abcdebits & 3) << 5;
13230 inst.instruction |= (abcdebits >> 2) << 21;
13231 }
13232 break;
5f4273c7 13233
037e8744
JB
13234 case NS_RRD: /* case 7 (fmrrd). */
13235 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13236 _(BAD_FPU));
13237
13238 inst.instruction = 0xc500b10;
13239 do_vfp_cond_or_thumb ();
13240 inst.instruction |= inst.operands[0].reg << 12;
13241 inst.instruction |= inst.operands[1].reg << 16;
13242 inst.instruction |= LOW4 (inst.operands[2].reg);
13243 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13244 break;
5f4273c7 13245
037e8744
JB
13246 case NS_FF: /* case 8 (fcpys). */
13247 do_vfp_nsyn_opcode ("fcpys");
13248 break;
5f4273c7 13249
037e8744
JB
13250 case NS_FI: /* case 10 (fconsts). */
13251 ldconst = "fconsts";
13252 encode_fconstd:
13253 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13254 {
037e8744
JB
13255 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13256 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13257 }
13258 else
037e8744
JB
13259 first_error (_("immediate out of range"));
13260 break;
5f4273c7 13261
037e8744
JB
13262 case NS_RF: /* case 12 (fmrs). */
13263 do_vfp_nsyn_opcode ("fmrs");
13264 break;
5f4273c7 13265
037e8744
JB
13266 case NS_FR: /* case 13 (fmsr). */
13267 do_vfp_nsyn_opcode ("fmsr");
13268 break;
5f4273c7 13269
037e8744
JB
13270 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13271 (one of which is a list), but we have parsed four. Do some fiddling to
13272 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13273 expect. */
13274 case NS_RRFF: /* case 14 (fmrrs). */
13275 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13276 _("VFP registers must be adjacent"));
13277 inst.operands[2].imm = 2;
13278 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13279 do_vfp_nsyn_opcode ("fmrrs");
13280 break;
5f4273c7 13281
037e8744
JB
13282 case NS_FFRR: /* case 15 (fmsrr). */
13283 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13284 _("VFP registers must be adjacent"));
13285 inst.operands[1] = inst.operands[2];
13286 inst.operands[2] = inst.operands[3];
13287 inst.operands[0].imm = 2;
13288 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13289 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13290 break;
5f4273c7 13291
5287ad62
JB
13292 default:
13293 abort ();
13294 }
13295}
13296
13297static void
13298do_neon_rshift_round_imm (void)
13299{
037e8744 13300 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13301 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13302 int imm = inst.operands[2].imm;
13303
13304 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13305 if (imm == 0)
13306 {
13307 inst.operands[2].present = 0;
13308 do_neon_mov ();
13309 return;
13310 }
13311
13312 constraint (imm < 1 || (unsigned)imm > et.size,
13313 _("immediate out of range for shift"));
037e8744 13314 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13315 et.size - imm);
13316}
13317
13318static void
13319do_neon_movl (void)
13320{
13321 struct neon_type_el et = neon_check_type (2, NS_QD,
13322 N_EQK | N_DBL, N_SU_32 | N_KEY);
13323 unsigned sizebits = et.size >> 3;
13324 inst.instruction |= sizebits << 19;
13325 neon_two_same (0, et.type == NT_unsigned, -1);
13326}
13327
13328static void
13329do_neon_trn (void)
13330{
037e8744 13331 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13332 struct neon_type_el et = neon_check_type (2, rs,
13333 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13334 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13335 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13336}
13337
13338static void
13339do_neon_zip_uzp (void)
13340{
037e8744 13341 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13342 struct neon_type_el et = neon_check_type (2, rs,
13343 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13344 if (rs == NS_DD && et.size == 32)
13345 {
13346 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13347 inst.instruction = N_MNEM_vtrn;
13348 do_neon_trn ();
13349 return;
13350 }
037e8744 13351 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13352}
13353
13354static void
13355do_neon_sat_abs_neg (void)
13356{
037e8744 13357 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13358 struct neon_type_el et = neon_check_type (2, rs,
13359 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13360 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13361}
13362
13363static void
13364do_neon_pair_long (void)
13365{
037e8744 13366 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13367 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13368 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13369 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13370 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13371}
13372
13373static void
13374do_neon_recip_est (void)
13375{
037e8744 13376 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13377 struct neon_type_el et = neon_check_type (2, rs,
13378 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13379 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13380 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13381}
13382
13383static void
13384do_neon_cls (void)
13385{
037e8744 13386 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13387 struct neon_type_el et = neon_check_type (2, rs,
13388 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13389 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13390}
13391
13392static void
13393do_neon_clz (void)
13394{
037e8744 13395 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13396 struct neon_type_el et = neon_check_type (2, rs,
13397 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13398 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13399}
13400
13401static void
13402do_neon_cnt (void)
13403{
037e8744 13404 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13405 struct neon_type_el et = neon_check_type (2, rs,
13406 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13407 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13408}
13409
13410static void
13411do_neon_swp (void)
13412{
037e8744
JB
13413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13414 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13415}
13416
13417static void
13418do_neon_tbl_tbx (void)
13419{
13420 unsigned listlenbits;
dcbf9037 13421 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13422
5287ad62
JB
13423 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13424 {
dcbf9037 13425 first_error (_("bad list length for table lookup"));
5287ad62
JB
13426 return;
13427 }
5f4273c7 13428
5287ad62
JB
13429 listlenbits = inst.operands[1].imm - 1;
13430 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13431 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13432 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13433 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13434 inst.instruction |= LOW4 (inst.operands[2].reg);
13435 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13436 inst.instruction |= listlenbits << 8;
5f4273c7 13437
5287ad62
JB
13438 inst.instruction = neon_dp_fixup (inst.instruction);
13439}
13440
13441static void
13442do_neon_ldm_stm (void)
13443{
13444 /* P, U and L bits are part of bitmask. */
13445 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13446 unsigned offsetbits = inst.operands[1].imm * 2;
13447
037e8744
JB
13448 if (inst.operands[1].issingle)
13449 {
13450 do_vfp_nsyn_ldm_stm (is_dbmode);
13451 return;
13452 }
13453
5287ad62
JB
13454 constraint (is_dbmode && !inst.operands[0].writeback,
13455 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13456
13457 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13458 _("register list must contain at least 1 and at most 16 "
13459 "registers"));
13460
13461 inst.instruction |= inst.operands[0].reg << 16;
13462 inst.instruction |= inst.operands[0].writeback << 21;
13463 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13464 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13465
13466 inst.instruction |= offsetbits;
5f4273c7 13467
037e8744 13468 do_vfp_cond_or_thumb ();
5287ad62
JB
13469}
13470
13471static void
13472do_neon_ldr_str (void)
13473{
5287ad62 13474 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13475
037e8744
JB
13476 if (inst.operands[0].issingle)
13477 {
cd2f129f
JB
13478 if (is_ldr)
13479 do_vfp_nsyn_opcode ("flds");
13480 else
13481 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13482 }
13483 else
5287ad62 13484 {
cd2f129f
JB
13485 if (is_ldr)
13486 do_vfp_nsyn_opcode ("fldd");
5287ad62 13487 else
cd2f129f 13488 do_vfp_nsyn_opcode ("fstd");
5287ad62 13489 }
5287ad62
JB
13490}
13491
13492/* "interleave" version also handles non-interleaving register VLD1/VST1
13493 instructions. */
13494
13495static void
13496do_neon_ld_st_interleave (void)
13497{
037e8744 13498 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13499 N_8 | N_16 | N_32 | N_64);
13500 unsigned alignbits = 0;
13501 unsigned idx;
13502 /* The bits in this table go:
13503 0: register stride of one (0) or two (1)
13504 1,2: register list length, minus one (1, 2, 3, 4).
13505 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13506 We use -1 for invalid entries. */
13507 const int typetable[] =
13508 {
13509 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13510 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13511 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13512 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13513 };
13514 int typebits;
13515
dcbf9037
JB
13516 if (et.type == NT_invtype)
13517 return;
13518
5287ad62
JB
13519 if (inst.operands[1].immisalign)
13520 switch (inst.operands[1].imm >> 8)
13521 {
13522 case 64: alignbits = 1; break;
13523 case 128:
13524 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13525 goto bad_alignment;
13526 alignbits = 2;
13527 break;
13528 case 256:
13529 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13530 goto bad_alignment;
13531 alignbits = 3;
13532 break;
13533 default:
13534 bad_alignment:
dcbf9037 13535 first_error (_("bad alignment"));
5287ad62
JB
13536 return;
13537 }
13538
13539 inst.instruction |= alignbits << 4;
13540 inst.instruction |= neon_logbits (et.size) << 6;
13541
13542 /* Bits [4:6] of the immediate in a list specifier encode register stride
13543 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13544 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13545 up the right value for "type" in a table based on this value and the given
13546 list style, then stick it back. */
13547 idx = ((inst.operands[0].imm >> 4) & 7)
13548 | (((inst.instruction >> 8) & 3) << 3);
13549
13550 typebits = typetable[idx];
5f4273c7 13551
5287ad62
JB
13552 constraint (typebits == -1, _("bad list type for instruction"));
13553
13554 inst.instruction &= ~0xf00;
13555 inst.instruction |= typebits << 8;
13556}
13557
13558/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13559 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13560 otherwise. The variable arguments are a list of pairs of legal (size, align)
13561 values, terminated with -1. */
13562
13563static int
13564neon_alignment_bit (int size, int align, int *do_align, ...)
13565{
13566 va_list ap;
13567 int result = FAIL, thissize, thisalign;
5f4273c7 13568
5287ad62
JB
13569 if (!inst.operands[1].immisalign)
13570 {
13571 *do_align = 0;
13572 return SUCCESS;
13573 }
5f4273c7 13574
5287ad62
JB
13575 va_start (ap, do_align);
13576
13577 do
13578 {
13579 thissize = va_arg (ap, int);
13580 if (thissize == -1)
13581 break;
13582 thisalign = va_arg (ap, int);
13583
13584 if (size == thissize && align == thisalign)
13585 result = SUCCESS;
13586 }
13587 while (result != SUCCESS);
13588
13589 va_end (ap);
13590
13591 if (result == SUCCESS)
13592 *do_align = 1;
13593 else
dcbf9037 13594 first_error (_("unsupported alignment for instruction"));
5f4273c7 13595
5287ad62
JB
13596 return result;
13597}
13598
13599static void
13600do_neon_ld_st_lane (void)
13601{
037e8744 13602 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13603 int align_good, do_align = 0;
13604 int logsize = neon_logbits (et.size);
13605 int align = inst.operands[1].imm >> 8;
13606 int n = (inst.instruction >> 8) & 3;
13607 int max_el = 64 / et.size;
5f4273c7 13608
dcbf9037
JB
13609 if (et.type == NT_invtype)
13610 return;
5f4273c7 13611
5287ad62
JB
13612 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13613 _("bad list length"));
13614 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13615 _("scalar index out of range"));
13616 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13617 && et.size == 8,
13618 _("stride of 2 unavailable when element size is 8"));
5f4273c7 13619
5287ad62
JB
13620 switch (n)
13621 {
13622 case 0: /* VLD1 / VST1. */
13623 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13624 32, 32, -1);
13625 if (align_good == FAIL)
13626 return;
13627 if (do_align)
13628 {
13629 unsigned alignbits = 0;
13630 switch (et.size)
13631 {
13632 case 16: alignbits = 0x1; break;
13633 case 32: alignbits = 0x3; break;
13634 default: ;
13635 }
13636 inst.instruction |= alignbits << 4;
13637 }
13638 break;
13639
13640 case 1: /* VLD2 / VST2. */
13641 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13642 32, 64, -1);
13643 if (align_good == FAIL)
13644 return;
13645 if (do_align)
13646 inst.instruction |= 1 << 4;
13647 break;
13648
13649 case 2: /* VLD3 / VST3. */
13650 constraint (inst.operands[1].immisalign,
13651 _("can't use alignment with this instruction"));
13652 break;
13653
13654 case 3: /* VLD4 / VST4. */
13655 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13656 16, 64, 32, 64, 32, 128, -1);
13657 if (align_good == FAIL)
13658 return;
13659 if (do_align)
13660 {
13661 unsigned alignbits = 0;
13662 switch (et.size)
13663 {
13664 case 8: alignbits = 0x1; break;
13665 case 16: alignbits = 0x1; break;
13666 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13667 default: ;
13668 }
13669 inst.instruction |= alignbits << 4;
13670 }
13671 break;
13672
13673 default: ;
13674 }
13675
13676 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13677 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13678 inst.instruction |= 1 << (4 + logsize);
5f4273c7 13679
5287ad62
JB
13680 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13681 inst.instruction |= logsize << 10;
13682}
13683
13684/* Encode single n-element structure to all lanes VLD<n> instructions. */
13685
13686static void
13687do_neon_ld_dup (void)
13688{
037e8744 13689 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13690 int align_good, do_align = 0;
13691
dcbf9037
JB
13692 if (et.type == NT_invtype)
13693 return;
13694
5287ad62
JB
13695 switch ((inst.instruction >> 8) & 3)
13696 {
13697 case 0: /* VLD1. */
13698 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13699 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13700 &do_align, 16, 16, 32, 32, -1);
13701 if (align_good == FAIL)
13702 return;
13703 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13704 {
13705 case 1: break;
13706 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13707 default: first_error (_("bad list length")); return;
5287ad62
JB
13708 }
13709 inst.instruction |= neon_logbits (et.size) << 6;
13710 break;
13711
13712 case 1: /* VLD2. */
13713 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13714 &do_align, 8, 16, 16, 32, 32, 64, -1);
13715 if (align_good == FAIL)
13716 return;
13717 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13718 _("bad list length"));
13719 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13720 inst.instruction |= 1 << 5;
13721 inst.instruction |= neon_logbits (et.size) << 6;
13722 break;
13723
13724 case 2: /* VLD3. */
13725 constraint (inst.operands[1].immisalign,
13726 _("can't use alignment with this instruction"));
13727 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13728 _("bad list length"));
13729 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13730 inst.instruction |= 1 << 5;
13731 inst.instruction |= neon_logbits (et.size) << 6;
13732 break;
13733
13734 case 3: /* VLD4. */
13735 {
13736 int align = inst.operands[1].imm >> 8;
13737 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13738 16, 64, 32, 64, 32, 128, -1);
13739 if (align_good == FAIL)
13740 return;
13741 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13742 _("bad list length"));
13743 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13744 inst.instruction |= 1 << 5;
13745 if (et.size == 32 && align == 128)
13746 inst.instruction |= 0x3 << 6;
13747 else
13748 inst.instruction |= neon_logbits (et.size) << 6;
13749 }
13750 break;
13751
13752 default: ;
13753 }
13754
13755 inst.instruction |= do_align << 4;
13756}
13757
13758/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13759 apart from bits [11:4]. */
13760
13761static void
13762do_neon_ldx_stx (void)
13763{
13764 switch (NEON_LANE (inst.operands[0].imm))
13765 {
13766 case NEON_INTERLEAVE_LANES:
13767 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13768 do_neon_ld_st_interleave ();
13769 break;
5f4273c7 13770
5287ad62
JB
13771 case NEON_ALL_LANES:
13772 inst.instruction = NEON_ENC_DUP (inst.instruction);
13773 do_neon_ld_dup ();
13774 break;
5f4273c7 13775
5287ad62
JB
13776 default:
13777 inst.instruction = NEON_ENC_LANE (inst.instruction);
13778 do_neon_ld_st_lane ();
13779 }
13780
13781 /* L bit comes from bit mask. */
13782 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13783 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13784 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 13785
5287ad62
JB
13786 if (inst.operands[1].postind)
13787 {
13788 int postreg = inst.operands[1].imm & 0xf;
13789 constraint (!inst.operands[1].immisreg,
13790 _("post-index must be a register"));
13791 constraint (postreg == 0xd || postreg == 0xf,
13792 _("bad register for post-index"));
13793 inst.instruction |= postreg;
13794 }
13795 else if (inst.operands[1].writeback)
13796 {
13797 inst.instruction |= 0xd;
13798 }
13799 else
5f4273c7
NC
13800 inst.instruction |= 0xf;
13801
5287ad62
JB
13802 if (thumb_mode)
13803 inst.instruction |= 0xf9000000;
13804 else
13805 inst.instruction |= 0xf4000000;
13806}
5287ad62
JB
13807\f
13808/* Overall per-instruction processing. */
13809
13810/* We need to be able to fix up arbitrary expressions in some statements.
13811 This is so that we can handle symbols that are an arbitrary distance from
13812 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13813 which returns part of an address in a form which will be valid for
13814 a data instruction. We do this by pushing the expression into a symbol
13815 in the expr_section, and creating a fix for that. */
13816
13817static void
13818fix_new_arm (fragS * frag,
13819 int where,
13820 short int size,
13821 expressionS * exp,
13822 int pc_rel,
13823 int reloc)
13824{
13825 fixS * new_fix;
13826
13827 switch (exp->X_op)
13828 {
13829 case O_constant:
13830 case O_symbol:
13831 case O_add:
13832 case O_subtract:
13833 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13834 break;
13835
13836 default:
13837 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13838 pc_rel, reloc);
13839 break;
13840 }
13841
13842 /* Mark whether the fix is to a THUMB instruction, or an ARM
13843 instruction. */
13844 new_fix->tc_fix_data = thumb_mode;
13845}
13846
13847/* Create a frg for an instruction requiring relaxation. */
13848static void
13849output_relax_insn (void)
13850{
13851 char * to;
13852 symbolS *sym;
0110f2b8
PB
13853 int offset;
13854
6e1cb1a6
PB
13855 /* The size of the instruction is unknown, so tie the debug info to the
13856 start of the instruction. */
13857 dwarf2_emit_insn (0);
6e1cb1a6 13858
0110f2b8
PB
13859 switch (inst.reloc.exp.X_op)
13860 {
13861 case O_symbol:
13862 sym = inst.reloc.exp.X_add_symbol;
13863 offset = inst.reloc.exp.X_add_number;
13864 break;
13865 case O_constant:
13866 sym = NULL;
13867 offset = inst.reloc.exp.X_add_number;
13868 break;
13869 default:
13870 sym = make_expr_symbol (&inst.reloc.exp);
13871 offset = 0;
13872 break;
13873 }
13874 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13875 inst.relax, sym, offset, NULL/*offset, opcode*/);
13876 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13877}
13878
13879/* Write a 32-bit thumb instruction to buf. */
13880static void
13881put_thumb32_insn (char * buf, unsigned long insn)
13882{
13883 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13884 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13885}
13886
b99bd4ef 13887static void
c19d1205 13888output_inst (const char * str)
b99bd4ef 13889{
c19d1205 13890 char * to = NULL;
b99bd4ef 13891
c19d1205 13892 if (inst.error)
b99bd4ef 13893 {
c19d1205 13894 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13895 return;
13896 }
5f4273c7
NC
13897 if (inst.relax)
13898 {
13899 output_relax_insn ();
0110f2b8 13900 return;
5f4273c7 13901 }
c19d1205
ZW
13902 if (inst.size == 0)
13903 return;
b99bd4ef 13904
c19d1205
ZW
13905 to = frag_more (inst.size);
13906
13907 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13908 {
c19d1205 13909 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13910 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13911 }
c19d1205 13912 else if (inst.size > INSN_SIZE)
b99bd4ef 13913 {
c19d1205
ZW
13914 assert (inst.size == (2 * INSN_SIZE));
13915 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13916 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13917 }
c19d1205
ZW
13918 else
13919 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13920
c19d1205
ZW
13921 if (inst.reloc.type != BFD_RELOC_UNUSED)
13922 fix_new_arm (frag_now, to - frag_now->fr_literal,
13923 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13924 inst.reloc.type);
b99bd4ef 13925
c19d1205 13926 dwarf2_emit_insn (inst.size);
c19d1205 13927}
b99bd4ef 13928
c19d1205
ZW
13929/* Tag values used in struct asm_opcode's tag field. */
13930enum opcode_tag
13931{
13932 OT_unconditional, /* Instruction cannot be conditionalized.
13933 The ARM condition field is still 0xE. */
13934 OT_unconditionalF, /* Instruction cannot be conditionalized
13935 and carries 0xF in its ARM condition field. */
13936 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13937 OT_csuffixF, /* Some forms of the instruction take a conditional
13938 suffix, others place 0xF where the condition field
13939 would be. */
c19d1205
ZW
13940 OT_cinfix3, /* Instruction takes a conditional infix,
13941 beginning at character index 3. (In
13942 unified mode, it becomes a suffix.) */
088fa78e
KH
13943 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13944 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13945 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13946 character index 3, even in unified mode. Used for
13947 legacy instructions where suffix and infix forms
13948 may be ambiguous. */
c19d1205 13949 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13950 suffix or an infix at character index 3. */
c19d1205
ZW
13951 OT_odd_infix_unc, /* This is the unconditional variant of an
13952 instruction that takes a conditional infix
13953 at an unusual position. In unified mode,
13954 this variant will accept a suffix. */
13955 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13956 are the conditional variants of instructions that
13957 take conditional infixes in unusual positions.
13958 The infix appears at character index
13959 (tag - OT_odd_infix_0). These are not accepted
13960 in unified mode. */
13961};
b99bd4ef 13962
c19d1205
ZW
13963/* Subroutine of md_assemble, responsible for looking up the primary
13964 opcode from the mnemonic the user wrote. STR points to the
13965 beginning of the mnemonic.
13966
13967 This is not simply a hash table lookup, because of conditional
13968 variants. Most instructions have conditional variants, which are
13969 expressed with a _conditional affix_ to the mnemonic. If we were
13970 to encode each conditional variant as a literal string in the opcode
13971 table, it would have approximately 20,000 entries.
13972
13973 Most mnemonics take this affix as a suffix, and in unified syntax,
13974 'most' is upgraded to 'all'. However, in the divided syntax, some
13975 instructions take the affix as an infix, notably the s-variants of
13976 the arithmetic instructions. Of those instructions, all but six
13977 have the infix appear after the third character of the mnemonic.
13978
13979 Accordingly, the algorithm for looking up primary opcodes given
13980 an identifier is:
13981
13982 1. Look up the identifier in the opcode table.
13983 If we find a match, go to step U.
13984
13985 2. Look up the last two characters of the identifier in the
13986 conditions table. If we find a match, look up the first N-2
13987 characters of the identifier in the opcode table. If we
13988 find a match, go to step CE.
13989
13990 3. Look up the fourth and fifth characters of the identifier in
13991 the conditions table. If we find a match, extract those
13992 characters from the identifier, and look up the remaining
13993 characters in the opcode table. If we find a match, go
13994 to step CM.
13995
13996 4. Fail.
13997
13998 U. Examine the tag field of the opcode structure, in case this is
13999 one of the six instructions with its conditional infix in an
14000 unusual place. If it is, the tag tells us where to find the
14001 infix; look it up in the conditions table and set inst.cond
14002 accordingly. Otherwise, this is an unconditional instruction.
14003 Again set inst.cond accordingly. Return the opcode structure.
14004
14005 CE. Examine the tag field to make sure this is an instruction that
14006 should receive a conditional suffix. If it is not, fail.
14007 Otherwise, set inst.cond from the suffix we already looked up,
14008 and return the opcode structure.
14009
14010 CM. Examine the tag field to make sure this is an instruction that
14011 should receive a conditional infix after the third character.
14012 If it is not, fail. Otherwise, undo the edits to the current
14013 line of input and proceed as for case CE. */
14014
14015static const struct asm_opcode *
14016opcode_lookup (char **str)
14017{
14018 char *end, *base;
14019 char *affix;
14020 const struct asm_opcode *opcode;
14021 const struct asm_cond *cond;
e3cb604e 14022 char save[2];
267d2029 14023 bfd_boolean neon_supported;
5f4273c7 14024
267d2029 14025 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14026
14027 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14028 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14029 for (base = end = *str; *end != '\0'; end++)
267d2029 14030 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14031 break;
b99bd4ef 14032
c19d1205
ZW
14033 if (end == base)
14034 return 0;
b99bd4ef 14035
5287ad62 14036 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14037 if (end[0] == '.')
b99bd4ef 14038 {
5287ad62 14039 int offset = 2;
5f4273c7 14040
267d2029
JB
14041 /* The .w and .n suffixes are only valid if the unified syntax is in
14042 use. */
14043 if (unified_syntax && end[1] == 'w')
c19d1205 14044 inst.size_req = 4;
267d2029 14045 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14046 inst.size_req = 2;
14047 else
5287ad62
JB
14048 offset = 0;
14049
14050 inst.vectype.elems = 0;
14051
14052 *str = end + offset;
b99bd4ef 14053
5f4273c7 14054 if (end[offset] == '.')
5287ad62 14055 {
267d2029
JB
14056 /* See if we have a Neon type suffix (possible in either unified or
14057 non-unified ARM syntax mode). */
dcbf9037 14058 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14059 return 0;
14060 }
14061 else if (end[offset] != '\0' && end[offset] != ' ')
14062 return 0;
b99bd4ef 14063 }
c19d1205
ZW
14064 else
14065 *str = end;
b99bd4ef 14066
c19d1205
ZW
14067 /* Look for unaffixed or special-case affixed mnemonic. */
14068 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14069 if (opcode)
b99bd4ef 14070 {
c19d1205
ZW
14071 /* step U */
14072 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14073 {
c19d1205
ZW
14074 inst.cond = COND_ALWAYS;
14075 return opcode;
b99bd4ef 14076 }
b99bd4ef 14077
c19d1205
ZW
14078 if (unified_syntax)
14079 as_warn (_("conditional infixes are deprecated in unified syntax"));
14080 affix = base + (opcode->tag - OT_odd_infix_0);
14081 cond = hash_find_n (arm_cond_hsh, affix, 2);
14082 assert (cond);
b99bd4ef 14083
c19d1205
ZW
14084 inst.cond = cond->value;
14085 return opcode;
14086 }
b99bd4ef 14087
c19d1205
ZW
14088 /* Cannot have a conditional suffix on a mnemonic of less than two
14089 characters. */
14090 if (end - base < 3)
14091 return 0;
b99bd4ef 14092
c19d1205
ZW
14093 /* Look for suffixed mnemonic. */
14094 affix = end - 2;
14095 cond = hash_find_n (arm_cond_hsh, affix, 2);
14096 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14097 if (opcode && cond)
14098 {
14099 /* step CE */
14100 switch (opcode->tag)
14101 {
e3cb604e
PB
14102 case OT_cinfix3_legacy:
14103 /* Ignore conditional suffixes matched on infix only mnemonics. */
14104 break;
14105
c19d1205 14106 case OT_cinfix3:
088fa78e 14107 case OT_cinfix3_deprecated:
c19d1205
ZW
14108 case OT_odd_infix_unc:
14109 if (!unified_syntax)
e3cb604e 14110 return 0;
c19d1205
ZW
14111 /* else fall through */
14112
14113 case OT_csuffix:
037e8744 14114 case OT_csuffixF:
c19d1205
ZW
14115 case OT_csuf_or_in3:
14116 inst.cond = cond->value;
14117 return opcode;
14118
14119 case OT_unconditional:
14120 case OT_unconditionalF:
dfa9f0d5
PB
14121 if (thumb_mode)
14122 {
14123 inst.cond = cond->value;
14124 }
14125 else
14126 {
14127 /* delayed diagnostic */
14128 inst.error = BAD_COND;
14129 inst.cond = COND_ALWAYS;
14130 }
c19d1205 14131 return opcode;
b99bd4ef 14132
c19d1205
ZW
14133 default:
14134 return 0;
14135 }
14136 }
b99bd4ef 14137
c19d1205
ZW
14138 /* Cannot have a usual-position infix on a mnemonic of less than
14139 six characters (five would be a suffix). */
14140 if (end - base < 6)
14141 return 0;
b99bd4ef 14142
c19d1205
ZW
14143 /* Look for infixed mnemonic in the usual position. */
14144 affix = base + 3;
14145 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14146 if (!cond)
14147 return 0;
14148
14149 memcpy (save, affix, 2);
14150 memmove (affix, affix + 2, (end - affix) - 2);
14151 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14152 memmove (affix + 2, affix, (end - affix) - 2);
14153 memcpy (affix, save, 2);
14154
088fa78e
KH
14155 if (opcode
14156 && (opcode->tag == OT_cinfix3
14157 || opcode->tag == OT_cinfix3_deprecated
14158 || opcode->tag == OT_csuf_or_in3
14159 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14160 {
c19d1205 14161 /* step CM */
088fa78e
KH
14162 if (unified_syntax
14163 && (opcode->tag == OT_cinfix3
14164 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14165 as_warn (_("conditional infixes are deprecated in unified syntax"));
14166
14167 inst.cond = cond->value;
14168 return opcode;
b99bd4ef
NC
14169 }
14170
c19d1205 14171 return 0;
b99bd4ef
NC
14172}
14173
c19d1205
ZW
14174void
14175md_assemble (char *str)
b99bd4ef 14176{
c19d1205
ZW
14177 char *p = str;
14178 const struct asm_opcode * opcode;
b99bd4ef 14179
c19d1205
ZW
14180 /* Align the previous label if needed. */
14181 if (last_label_seen != NULL)
b99bd4ef 14182 {
c19d1205
ZW
14183 symbol_set_frag (last_label_seen, frag_now);
14184 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14185 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14186 }
14187
c19d1205
ZW
14188 memset (&inst, '\0', sizeof (inst));
14189 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14190
c19d1205
ZW
14191 opcode = opcode_lookup (&p);
14192 if (!opcode)
b99bd4ef 14193 {
c19d1205 14194 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14195 the form alias .req reg, or a Neon .dn/.qn directive. */
14196 if (!create_register_alias (str, p)
14197 && !create_neon_reg_alias (str, p))
c19d1205 14198 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14199
b99bd4ef
NC
14200 return;
14201 }
14202
088fa78e
KH
14203 if (opcode->tag == OT_cinfix3_deprecated)
14204 as_warn (_("s suffix on comparison instruction is deprecated"));
14205
037e8744
JB
14206 /* The value which unconditional instructions should have in place of the
14207 condition field. */
14208 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14209
c19d1205 14210 if (thumb_mode)
b99bd4ef 14211 {
e74cfd16 14212 arm_feature_set variant;
8f06b2d8
PB
14213
14214 variant = cpu_variant;
14215 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14216 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14217 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14218 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14219 if (!opcode->tvariant
14220 || (thumb_mode == 1
14221 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14222 {
c19d1205 14223 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14224 return;
14225 }
c19d1205
ZW
14226 if (inst.cond != COND_ALWAYS && !unified_syntax
14227 && opcode->tencode != do_t_branch)
b99bd4ef 14228 {
c19d1205 14229 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14230 return;
14231 }
14232
076d447c
PB
14233 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14234 {
14235 /* Implicit require narrow instructions on Thumb-1. This avoids
14236 relaxation accidentally introducing Thumb-2 instructions. */
7e806470
PB
14237 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14238 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
076d447c
PB
14239 inst.size_req = 2;
14240 }
14241
e27ec89e
PB
14242 /* Check conditional suffixes. */
14243 if (current_it_mask)
14244 {
14245 int cond;
14246 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14247 current_it_mask <<= 1;
14248 current_it_mask &= 0x1f;
14249 /* The BKPT instruction is unconditional even in an IT block. */
14250 if (!inst.error
14251 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14252 {
14253 as_bad (_("incorrect condition in IT block"));
14254 return;
14255 }
e27ec89e
PB
14256 }
14257 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14258 {
6decc662 14259 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14260 return;
14261 }
14262
c19d1205
ZW
14263 mapping_state (MAP_THUMB);
14264 inst.instruction = opcode->tvalue;
14265
14266 if (!parse_operands (p, opcode->operands))
14267 opcode->tencode ();
14268
e27ec89e
PB
14269 /* Clear current_it_mask at the end of an IT block. */
14270 if (current_it_mask == 0x10)
14271 current_it_mask = 0;
14272
0110f2b8 14273 if (!(inst.error || inst.relax))
b99bd4ef 14274 {
c19d1205
ZW
14275 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14276 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14277 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14278 {
c19d1205 14279 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14280 return;
14281 }
14282 }
076d447c
PB
14283
14284 /* Something has gone badly wrong if we try to relax a fixed size
14285 instruction. */
14286 assert (inst.size_req == 0 || !inst.relax);
14287
e74cfd16
PB
14288 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14289 *opcode->tvariant);
ee065d83 14290 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14291 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14292 anything other than bl/blx and v6-M instructions.
ee065d83 14293 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14294 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14295 || inst.relax)
14296 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
e74cfd16
PB
14297 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14298 arm_ext_v6t2);
c19d1205 14299 }
3e9e4fcf 14300 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14301 {
845b51d6
PB
14302 bfd_boolean is_bx;
14303
14304 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14305 is_bx = (opcode->aencode == do_bx);
14306
c19d1205 14307 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14308 if (!(is_bx && fix_v4bx)
14309 && !(opcode->avariant &&
14310 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14311 {
c19d1205
ZW
14312 as_bad (_("selected processor does not support `%s'"), str);
14313 return;
b99bd4ef 14314 }
c19d1205 14315 if (inst.size_req)
b99bd4ef 14316 {
c19d1205
ZW
14317 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14318 return;
b99bd4ef
NC
14319 }
14320
c19d1205
ZW
14321 mapping_state (MAP_ARM);
14322 inst.instruction = opcode->avalue;
14323 if (opcode->tag == OT_unconditionalF)
14324 inst.instruction |= 0xF << 28;
14325 else
14326 inst.instruction |= inst.cond << 28;
14327 inst.size = INSN_SIZE;
14328 if (!parse_operands (p, opcode->operands))
14329 opcode->aencode ();
ee065d83
PB
14330 /* Arm mode bx is marked as both v4T and v5 because it's still required
14331 on a hypothetical non-thumb v5 core. */
845b51d6 14332 if (is_bx)
e74cfd16 14333 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14334 else
e74cfd16
PB
14335 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14336 *opcode->avariant);
b99bd4ef 14337 }
3e9e4fcf
JB
14338 else
14339 {
14340 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14341 "-- `%s'"), str);
14342 return;
14343 }
c19d1205
ZW
14344 output_inst (str);
14345}
b99bd4ef 14346
c19d1205
ZW
14347/* Various frobbings of labels and their addresses. */
14348
14349void
14350arm_start_line_hook (void)
14351{
14352 last_label_seen = NULL;
b99bd4ef
NC
14353}
14354
c19d1205
ZW
14355void
14356arm_frob_label (symbolS * sym)
b99bd4ef 14357{
c19d1205 14358 last_label_seen = sym;
b99bd4ef 14359
c19d1205 14360 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14361
c19d1205
ZW
14362#if defined OBJ_COFF || defined OBJ_ELF
14363 ARM_SET_INTERWORK (sym, support_interwork);
14364#endif
b99bd4ef 14365
5f4273c7 14366 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14367 as Thumb functions. This is because these labels, whilst
14368 they exist inside Thumb code, are not the entry points for
14369 possible ARM->Thumb calls. Also, these labels can be used
14370 as part of a computed goto or switch statement. eg gcc
14371 can generate code that looks like this:
b99bd4ef 14372
c19d1205
ZW
14373 ldr r2, [pc, .Laaa]
14374 lsl r3, r3, #2
14375 ldr r2, [r3, r2]
14376 mov pc, r2
b99bd4ef 14377
c19d1205
ZW
14378 .Lbbb: .word .Lxxx
14379 .Lccc: .word .Lyyy
14380 ..etc...
14381 .Laaa: .word Lbbb
b99bd4ef 14382
c19d1205
ZW
14383 The first instruction loads the address of the jump table.
14384 The second instruction converts a table index into a byte offset.
14385 The third instruction gets the jump address out of the table.
14386 The fourth instruction performs the jump.
b99bd4ef 14387
c19d1205
ZW
14388 If the address stored at .Laaa is that of a symbol which has the
14389 Thumb_Func bit set, then the linker will arrange for this address
14390 to have the bottom bit set, which in turn would mean that the
14391 address computation performed by the third instruction would end
14392 up with the bottom bit set. Since the ARM is capable of unaligned
14393 word loads, the instruction would then load the incorrect address
14394 out of the jump table, and chaos would ensue. */
14395 if (label_is_thumb_function_name
14396 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14397 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14398 {
c19d1205
ZW
14399 /* When the address of a Thumb function is taken the bottom
14400 bit of that address should be set. This will allow
14401 interworking between Arm and Thumb functions to work
14402 correctly. */
b99bd4ef 14403
c19d1205 14404 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14405
c19d1205 14406 label_is_thumb_function_name = FALSE;
b99bd4ef 14407 }
07a53e5c 14408
07a53e5c 14409 dwarf2_emit_label (sym);
b99bd4ef
NC
14410}
14411
c19d1205
ZW
14412int
14413arm_data_in_code (void)
b99bd4ef 14414{
c19d1205 14415 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14416 {
c19d1205
ZW
14417 *input_line_pointer = '/';
14418 input_line_pointer += 5;
14419 *input_line_pointer = 0;
14420 return 1;
b99bd4ef
NC
14421 }
14422
c19d1205 14423 return 0;
b99bd4ef
NC
14424}
14425
c19d1205
ZW
14426char *
14427arm_canonicalize_symbol_name (char * name)
b99bd4ef 14428{
c19d1205 14429 int len;
b99bd4ef 14430
c19d1205
ZW
14431 if (thumb_mode && (len = strlen (name)) > 5
14432 && streq (name + len - 5, "/data"))
14433 *(name + len - 5) = 0;
b99bd4ef 14434
c19d1205 14435 return name;
b99bd4ef 14436}
c19d1205
ZW
14437\f
14438/* Table of all register names defined by default. The user can
14439 define additional names with .req. Note that all register names
14440 should appear in both upper and lowercase variants. Some registers
14441 also have mixed-case names. */
b99bd4ef 14442
dcbf9037 14443#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14444#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14445#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14446#define REGSET(p,t) \
14447 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14448 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14449 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14450 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14451#define REGSETH(p,t) \
14452 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14453 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14454 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14455 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14456#define REGSET2(p,t) \
14457 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14458 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14459 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14460 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14461
c19d1205 14462static const struct reg_entry reg_names[] =
7ed4c4c5 14463{
c19d1205
ZW
14464 /* ARM integer registers. */
14465 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14466
c19d1205
ZW
14467 /* ATPCS synonyms. */
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 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14473 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14474 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14475
c19d1205
ZW
14476 /* Well-known aliases. */
14477 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14478 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14479
14480 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14481 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14482
14483 /* Coprocessor numbers. */
14484 REGSET(p, CP), REGSET(P, CP),
14485
14486 /* Coprocessor register numbers. The "cr" variants are for backward
14487 compatibility. */
14488 REGSET(c, CN), REGSET(C, CN),
14489 REGSET(cr, CN), REGSET(CR, CN),
14490
14491 /* FPA registers. */
14492 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14493 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14494
14495 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14496 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14497
14498 /* VFP SP registers. */
5287ad62
JB
14499 REGSET(s,VFS), REGSET(S,VFS),
14500 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14501
14502 /* VFP DP Registers. */
5287ad62
JB
14503 REGSET(d,VFD), REGSET(D,VFD),
14504 /* Extra Neon DP registers. */
14505 REGSETH(d,VFD), REGSETH(D,VFD),
14506
14507 /* Neon QP registers. */
14508 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14509
14510 /* VFP control registers. */
14511 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14512 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14513 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14514 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14515 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14516 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14517
14518 /* Maverick DSP coprocessor registers. */
14519 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14520 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
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 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14527 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14528 REGDEF(DSPSC,0,DSPSC),
14529
14530 /* iWMMXt data registers - p0, c0-15. */
14531 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14532
14533 /* iWMMXt control registers - p1, c0-3. */
14534 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14535 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14536 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14537 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14538
14539 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14540 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14541 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14542 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14543 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14544
14545 /* XScale accumulator registers. */
14546 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14547};
14548#undef REGDEF
14549#undef REGNUM
14550#undef REGSET
7ed4c4c5 14551
c19d1205
ZW
14552/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14553 within psr_required_here. */
14554static const struct asm_psr psrs[] =
14555{
14556 /* Backward compatibility notation. Note that "all" is no longer
14557 truly all possible PSR bits. */
14558 {"all", PSR_c | PSR_f},
14559 {"flg", PSR_f},
14560 {"ctl", PSR_c},
14561
14562 /* Individual flags. */
14563 {"f", PSR_f},
14564 {"c", PSR_c},
14565 {"x", PSR_x},
14566 {"s", PSR_s},
14567 /* Combinations of flags. */
14568 {"fs", PSR_f | PSR_s},
14569 {"fx", PSR_f | PSR_x},
14570 {"fc", PSR_f | PSR_c},
14571 {"sf", PSR_s | PSR_f},
14572 {"sx", PSR_s | PSR_x},
14573 {"sc", PSR_s | PSR_c},
14574 {"xf", PSR_x | PSR_f},
14575 {"xs", PSR_x | PSR_s},
14576 {"xc", PSR_x | PSR_c},
14577 {"cf", PSR_c | PSR_f},
14578 {"cs", PSR_c | PSR_s},
14579 {"cx", PSR_c | PSR_x},
14580 {"fsx", PSR_f | PSR_s | PSR_x},
14581 {"fsc", PSR_f | PSR_s | PSR_c},
14582 {"fxs", PSR_f | PSR_x | PSR_s},
14583 {"fxc", PSR_f | PSR_x | PSR_c},
14584 {"fcs", PSR_f | PSR_c | PSR_s},
14585 {"fcx", PSR_f | PSR_c | PSR_x},
14586 {"sfx", PSR_s | PSR_f | PSR_x},
14587 {"sfc", PSR_s | PSR_f | PSR_c},
14588 {"sxf", PSR_s | PSR_x | PSR_f},
14589 {"sxc", PSR_s | PSR_x | PSR_c},
14590 {"scf", PSR_s | PSR_c | PSR_f},
14591 {"scx", PSR_s | PSR_c | PSR_x},
14592 {"xfs", PSR_x | PSR_f | PSR_s},
14593 {"xfc", PSR_x | PSR_f | PSR_c},
14594 {"xsf", PSR_x | PSR_s | PSR_f},
14595 {"xsc", PSR_x | PSR_s | PSR_c},
14596 {"xcf", PSR_x | PSR_c | PSR_f},
14597 {"xcs", PSR_x | PSR_c | PSR_s},
14598 {"cfs", PSR_c | PSR_f | PSR_s},
14599 {"cfx", PSR_c | PSR_f | PSR_x},
14600 {"csf", PSR_c | PSR_s | PSR_f},
14601 {"csx", PSR_c | PSR_s | PSR_x},
14602 {"cxf", PSR_c | PSR_x | PSR_f},
14603 {"cxs", PSR_c | PSR_x | PSR_s},
14604 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14605 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14606 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14607 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14608 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14609 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14610 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14611 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14612 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14613 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14614 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14615 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14616 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14617 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14618 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14619 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14620 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14621 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14622 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14623 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14624 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14625 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14626 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14627 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14628};
14629
62b3e311
PB
14630/* Table of V7M psr names. */
14631static const struct asm_psr v7m_psrs[] =
14632{
2b744c99
PB
14633 {"apsr", 0 }, {"APSR", 0 },
14634 {"iapsr", 1 }, {"IAPSR", 1 },
14635 {"eapsr", 2 }, {"EAPSR", 2 },
14636 {"psr", 3 }, {"PSR", 3 },
14637 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14638 {"ipsr", 5 }, {"IPSR", 5 },
14639 {"epsr", 6 }, {"EPSR", 6 },
14640 {"iepsr", 7 }, {"IEPSR", 7 },
14641 {"msp", 8 }, {"MSP", 8 },
14642 {"psp", 9 }, {"PSP", 9 },
14643 {"primask", 16}, {"PRIMASK", 16},
14644 {"basepri", 17}, {"BASEPRI", 17},
14645 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14646 {"faultmask", 19}, {"FAULTMASK", 19},
14647 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14648};
14649
c19d1205
ZW
14650/* Table of all shift-in-operand names. */
14651static const struct asm_shift_name shift_names [] =
b99bd4ef 14652{
c19d1205
ZW
14653 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14654 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14655 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14656 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14657 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14658 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14659};
b99bd4ef 14660
c19d1205
ZW
14661/* Table of all explicit relocation names. */
14662#ifdef OBJ_ELF
14663static struct reloc_entry reloc_names[] =
14664{
14665 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14666 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14667 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14668 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14669 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14670 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14671 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14672 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14673 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14674 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14675 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14676};
14677#endif
b99bd4ef 14678
c19d1205
ZW
14679/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14680static const struct asm_cond conds[] =
14681{
14682 {"eq", 0x0},
14683 {"ne", 0x1},
14684 {"cs", 0x2}, {"hs", 0x2},
14685 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14686 {"mi", 0x4},
14687 {"pl", 0x5},
14688 {"vs", 0x6},
14689 {"vc", 0x7},
14690 {"hi", 0x8},
14691 {"ls", 0x9},
14692 {"ge", 0xa},
14693 {"lt", 0xb},
14694 {"gt", 0xc},
14695 {"le", 0xd},
14696 {"al", 0xe}
14697};
bfae80f2 14698
62b3e311
PB
14699static struct asm_barrier_opt barrier_opt_names[] =
14700{
14701 { "sy", 0xf },
14702 { "un", 0x7 },
14703 { "st", 0xe },
14704 { "unst", 0x6 }
14705};
14706
c19d1205
ZW
14707/* Table of ARM-format instructions. */
14708
14709/* Macros for gluing together operand strings. N.B. In all cases
14710 other than OPS0, the trailing OP_stop comes from default
14711 zero-initialization of the unspecified elements of the array. */
14712#define OPS0() { OP_stop, }
14713#define OPS1(a) { OP_##a, }
14714#define OPS2(a,b) { OP_##a,OP_##b, }
14715#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14716#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14717#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14718#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14719
14720/* These macros abstract out the exact format of the mnemonic table and
14721 save some repeated characters. */
14722
14723/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14724#define TxCE(mnem, op, top, nops, ops, ae, te) \
14725 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14726 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14727
14728/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14729 a T_MNEM_xyz enumerator. */
14730#define TCE(mnem, aop, top, nops, ops, ae, te) \
14731 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14732#define tCE(mnem, aop, top, nops, ops, ae, te) \
14733 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14734
14735/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14736 infix after the third character. */
14737#define TxC3(mnem, op, top, nops, ops, ae, te) \
14738 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14739 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14740#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14741 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14742 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14743#define TC3(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14745#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14746 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14747#define tC3(mnem, aop, top, nops, ops, ae, te) \
14748 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14749#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14750 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14751
14752/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14753 appear in the condition table. */
14754#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14755 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14756 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14757
14758#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14759 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14774 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14775 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14776 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14777 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14778
14779#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14780 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14781#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14782 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14783
14784/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14785 field is still 0xE. Many of the Thumb variants can be executed
14786 conditionally, so this is checked separately. */
c19d1205
ZW
14787#define TUE(mnem, op, top, nops, ops, ae, te) \
14788 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14789 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14790
14791/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14792 condition code field. */
14793#define TUF(mnem, op, top, nops, ops, ae, te) \
14794 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14795 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14796
14797/* ARM-only variants of all the above. */
6a86118a
NC
14798#define CE(mnem, op, nops, ops, ae) \
14799 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14800
14801#define C3(mnem, op, nops, ops, ae) \
14802 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14803
e3cb604e
PB
14804/* Legacy mnemonics that always have conditional infix after the third
14805 character. */
14806#define CL(mnem, op, nops, ops, ae) \
14807 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14808 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14809
8f06b2d8
PB
14810/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14811#define cCE(mnem, op, nops, ops, ae) \
14812 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14813
e3cb604e
PB
14814/* Legacy coprocessor instructions where conditional infix and conditional
14815 suffix are ambiguous. For consistency this includes all FPA instructions,
14816 not just the potentially ambiguous ones. */
14817#define cCL(mnem, op, nops, ops, ae) \
14818 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14819 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14820
14821/* Coprocessor, takes either a suffix or a position-3 infix
14822 (for an FPA corner case). */
14823#define C3E(mnem, op, nops, ops, ae) \
14824 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14825 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14826
6a86118a
NC
14827#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14828 { #m1 #m2 #m3, OPS##nops ops, \
14829 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14830 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14831
14832#define CM(m1, m2, op, nops, ops, ae) \
14833 xCM_(m1, , m2, op, nops, ops, ae), \
14834 xCM_(m1, eq, m2, op, nops, ops, ae), \
14835 xCM_(m1, ne, m2, op, nops, ops, ae), \
14836 xCM_(m1, cs, m2, op, nops, ops, ae), \
14837 xCM_(m1, hs, m2, op, nops, ops, ae), \
14838 xCM_(m1, cc, m2, op, nops, ops, ae), \
14839 xCM_(m1, ul, m2, op, nops, ops, ae), \
14840 xCM_(m1, lo, m2, op, nops, ops, ae), \
14841 xCM_(m1, mi, m2, op, nops, ops, ae), \
14842 xCM_(m1, pl, m2, op, nops, ops, ae), \
14843 xCM_(m1, vs, m2, op, nops, ops, ae), \
14844 xCM_(m1, vc, m2, op, nops, ops, ae), \
14845 xCM_(m1, hi, m2, op, nops, ops, ae), \
14846 xCM_(m1, ls, m2, op, nops, ops, ae), \
14847 xCM_(m1, ge, m2, op, nops, ops, ae), \
14848 xCM_(m1, lt, m2, op, nops, ops, ae), \
14849 xCM_(m1, gt, m2, op, nops, ops, ae), \
14850 xCM_(m1, le, m2, op, nops, ops, ae), \
14851 xCM_(m1, al, m2, op, nops, ops, ae)
14852
14853#define UE(mnem, op, nops, ops, ae) \
14854 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14855
14856#define UF(mnem, op, nops, ops, ae) \
14857 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14858
5287ad62
JB
14859/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14860 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14861 use the same encoding function for each. */
14862#define NUF(mnem, op, nops, ops, enc) \
14863 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14864 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14865
14866/* Neon data processing, version which indirects through neon_enc_tab for
14867 the various overloaded versions of opcodes. */
14868#define nUF(mnem, op, nops, ops, enc) \
14869 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14870 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14871
14872/* Neon insn with conditional suffix for the ARM version, non-overloaded
14873 version. */
037e8744
JB
14874#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14875 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14876 THUMB_VARIANT, do_##enc, do_##enc }
14877
037e8744
JB
14878#define NCE(mnem, op, nops, ops, enc) \
14879 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14880
14881#define NCEF(mnem, op, nops, ops, enc) \
14882 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14883
5287ad62 14884/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14885#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14886 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14887 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14888
037e8744
JB
14889#define nCE(mnem, op, nops, ops, enc) \
14890 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14891
14892#define nCEF(mnem, op, nops, ops, enc) \
14893 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14894
c19d1205
ZW
14895#define do_0 0
14896
14897/* Thumb-only, unconditional. */
14898#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14899
c19d1205 14900static const struct asm_opcode insns[] =
bfae80f2 14901{
e74cfd16
PB
14902#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14903#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14904 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14905 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14906 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14908 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14909 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14910 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14911 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14912 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14913 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14914 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14915 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14916 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14917 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14918 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14919 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14920
14921 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14922 for setting PSR flag bits. They are obsolete in V6 and do not
14923 have Thumb equivalents. */
14924 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14925 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14926 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14927 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14928 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14929 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14930 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14931 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14932 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14933
14934 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14935 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14936 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14937 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14938
4962c51a
MS
14939 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14940 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14941 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14942 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14943
f5208ef2 14944 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14945 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14946 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14947 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14948 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14949 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14950
14951 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14952 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14953 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14954 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14955
c19d1205 14956 /* Pseudo ops. */
e9f89963 14957 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14958 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14959 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14960
14961 /* Thumb-compatibility pseudo ops. */
14962 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14963 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14964 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14965 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14966 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14967 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14968 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14969 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14970 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14971 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14972 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14973 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14974
16a4cf17
PB
14975 /* These may simplify to neg. */
14976 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14977 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14978
c19d1205 14979#undef THUMB_VARIANT
e74cfd16 14980#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14981 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14982
14983 /* V1 instructions with no Thumb analogue prior to V6T2. */
14984#undef THUMB_VARIANT
e74cfd16 14985#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14986 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14987 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14988 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14989
14990 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14991 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14992 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14993 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14994
9c3c69f2
PB
14995 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14996 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14997
9c3c69f2
PB
14998 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14999 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15000
15001 /* V1 instructions with no Thumb analogue at all. */
15002 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15003 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15004
15005 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15006 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15007 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15008 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15009 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15010 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15011 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15012 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15013
15014#undef ARM_VARIANT
e74cfd16 15015#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15016#undef THUMB_VARIANT
e74cfd16 15017#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15018 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15019 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15020
15021#undef THUMB_VARIANT
e74cfd16 15022#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15023 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15024 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15025
15026 /* Generic coprocessor instructions. */
15027 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15028 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15029 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15030 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15031 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15032 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15033 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15034
15035#undef ARM_VARIANT
e74cfd16 15036#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15037 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15038 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15039
15040#undef ARM_VARIANT
e74cfd16 15041#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15042#undef THUMB_VARIANT
15043#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15044 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15045 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15046
15047#undef ARM_VARIANT
e74cfd16 15048#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15049#undef THUMB_VARIANT
15050#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15051 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15054 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15055 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15056 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15057 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15058 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15059
15060#undef ARM_VARIANT
e74cfd16 15061#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15062#undef THUMB_VARIANT
e74cfd16 15063#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15064 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15065 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15066 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15067 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15068 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15069 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15070
15071#undef ARM_VARIANT
e74cfd16 15072#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15073 /* ARM Architecture 4T. */
15074 /* Note: bx (and blx) are required on V5, even if the processor does
15075 not support Thumb. */
15076 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15077
15078#undef ARM_VARIANT
e74cfd16 15079#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15080#undef THUMB_VARIANT
e74cfd16 15081#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15082 /* Note: blx has 2 variants; the .value coded here is for
15083 BLX(2). Only this variant has conditional execution. */
15084 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15085 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15086
15087#undef THUMB_VARIANT
e74cfd16 15088#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15089 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15090 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15091 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15092 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15093 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15094 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15095 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15096 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15097
15098#undef ARM_VARIANT
e74cfd16 15099#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15100 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15102 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15103 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15104
15105 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15106 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15107
15108 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15109 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15110 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15111 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15112
15113 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15115 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15116 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15117
15118 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15119 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15120
15121 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15122 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15123 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15124 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15125
15126#undef ARM_VARIANT
e74cfd16 15127#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15128 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15129 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15130 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15131
15132 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15133 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15134
15135#undef ARM_VARIANT
e74cfd16 15136#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15137 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15138
15139#undef ARM_VARIANT
e74cfd16 15140#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15141#undef THUMB_VARIANT
e74cfd16 15142#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15143 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15144 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15145 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15146 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15147 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15148 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15149 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15150 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15151 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15152 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15153
15154#undef THUMB_VARIANT
e74cfd16 15155#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15156 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15157 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15158 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15159 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15160
15161 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15162 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15163
15164/* ARM V6 not included in V7M (eg. integer SIMD). */
15165#undef THUMB_VARIANT
15166#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15167 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15168 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15169 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15170 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15203 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15204 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15205 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15206 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15207 UF(rfeib, 9900a00, 1, (RRw), rfe),
15208 UF(rfeda, 8100a00, 1, (RRw), rfe),
15209 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15210 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15211 UF(rfefa, 9900a00, 1, (RRw), rfe),
15212 UF(rfeea, 8100a00, 1, (RRw), rfe),
15213 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15214 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15216 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15217 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15218 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15219 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15220 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15221 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15222 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15223 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15224 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15225 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15226 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15227 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15230 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15231 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15232 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15233 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15234 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15235 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15236 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15237 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15238 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15239 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15240 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15241 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15242 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15243 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15244 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15245 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15246 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15247 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15248 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15249 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15250
15251#undef ARM_VARIANT
e74cfd16 15252#define ARM_VARIANT &arm_ext_v6k
c19d1205 15253#undef THUMB_VARIANT
e74cfd16 15254#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15255 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15256 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15257 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15258 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15259
ebdca51a
PB
15260#undef THUMB_VARIANT
15261#define THUMB_VARIANT &arm_ext_v6_notm
15262 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15263 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15264
c19d1205 15265#undef THUMB_VARIANT
e74cfd16 15266#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15267 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15268 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15269 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15270 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15271 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15272
15273#undef ARM_VARIANT
e74cfd16 15274#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15275 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15276
15277#undef ARM_VARIANT
e74cfd16 15278#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15279 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15280 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15281 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15282 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15283
15284 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15285 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15286 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15287 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15288
15289 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15290 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15291 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15292 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15293
25fe350b
MS
15294 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15295 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15296 /* ARM does not really have an IT instruction, so always allow it. */
15297#undef ARM_VARIANT
15298#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15299 TUE(it, 0, bf08, 1, (COND), it, t_it),
15300 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15301 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15302 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15303 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15304 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15305 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15306 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15307 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15308 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15309 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15310 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15311 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15312 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15313 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15314
92e90b6e
PB
15315 /* Thumb2 only instructions. */
15316#undef ARM_VARIANT
e74cfd16 15317#define ARM_VARIANT NULL
92e90b6e
PB
15318
15319 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15320 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15321 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15322 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15323
62b3e311
PB
15324 /* Thumb-2 hardware division instructions (R and M profiles only). */
15325#undef THUMB_VARIANT
15326#define THUMB_VARIANT &arm_ext_div
15327 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15328 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15329
7e806470
PB
15330 /* ARM V6M/V7 instructions. */
15331#undef ARM_VARIANT
15332#define ARM_VARIANT &arm_ext_barrier
15333#undef THUMB_VARIANT
15334#define THUMB_VARIANT &arm_ext_barrier
15335 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15336 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15337 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15338
62b3e311
PB
15339 /* ARM V7 instructions. */
15340#undef ARM_VARIANT
15341#define ARM_VARIANT &arm_ext_v7
15342#undef THUMB_VARIANT
15343#define THUMB_VARIANT &arm_ext_v7
15344 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15345 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15346
c19d1205 15347#undef ARM_VARIANT
e74cfd16 15348#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15349 cCE(wfs, e200110, 1, (RR), rd),
15350 cCE(rfs, e300110, 1, (RR), rd),
15351 cCE(wfc, e400110, 1, (RR), rd),
15352 cCE(rfc, e500110, 1, (RR), rd),
15353
4962c51a
MS
15354 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15355 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15357 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15358
4962c51a
MS
15359 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15360 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15361 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15362 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15363
15364 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15370 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15371 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15372 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15373 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15374 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15375 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15376
15377 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15383 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15384 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15385 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15386 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15387 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15388 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15389
15390 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15391 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15392 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15393 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15394 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15395 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15396 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15397 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15398 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15399 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15400 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15401 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15402
15403 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15404 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15405 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15406 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15407 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15408 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15409 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15410 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15411 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15412 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15413 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15414 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15415
15416 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15422 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15423 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15424 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15425 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15426 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15427 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15428
15429 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15430 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15431 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15432 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15433 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15434 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15435 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15436 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15437 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15438 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15439 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15440 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15441
15442 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15448 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15449 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15450 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15451 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15452 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15453 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15454
15455 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15456 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15457 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15458 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15459 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15460 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15461 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15462 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15463 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15464 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15465 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15466 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15467
15468 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15469 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15470 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15471 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15472 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15473 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15474 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15475 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15476 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15477 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15478 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15479 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15480
15481 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15482 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15483 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15484 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15485 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15487 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15488 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15489 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15490 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15491 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15492 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15493
15494 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15495 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15496 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15497 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15498 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15499 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15500 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15501 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15502 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15503 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15504 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15505 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15506
15507 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15508 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15509 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15510 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15511 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15512 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15513 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15514 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15515 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15516 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15517 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15518 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15519
15520 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15521 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15522 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15523 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15524 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15526 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15527 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15528 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15529 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15530 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15531 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15532
15533 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15534 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15535 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15536 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15537 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15538 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15539 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15540 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15541 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15542 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15543 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15544 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15545
15546 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15547 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15548 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15549 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15550 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15551 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15552 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15553 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15554 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15555 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15556 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15557 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15558
15559 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15565 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15566 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15567 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15568 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15569 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15570 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15571
15572 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15584
15585 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15597
15598 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15610
15611 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15623
15624 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15636
15637 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15649
15650 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15662
15663 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15675
15676 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15688
15689 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15701
15702 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15714
15715 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15723 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15727
15728 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15735 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15736 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15737 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15738 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15739 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15740
15741 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15742 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15743 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15744 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15745
e3cb604e
PB
15746 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15747 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15748 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15749 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15750 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15751 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15752 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15753 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15754 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15755 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15756 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15757 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15758
c19d1205
ZW
15759 /* The implementation of the FIX instruction is broken on some
15760 assemblers, in that it accepts a precision specifier as well as a
15761 rounding specifier, despite the fact that this is meaningless.
15762 To be more compatible, we accept it as well, though of course it
15763 does not set any bits. */
8f06b2d8 15764 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15765 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15766 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15767 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15768 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15769 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15770 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15771 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15772 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15773 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15774 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15775 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15776 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15777
c19d1205
ZW
15778 /* Instructions that were new with the real FPA, call them V2. */
15779#undef ARM_VARIANT
e74cfd16 15780#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15781 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15782 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15783 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15784 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15785 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15786 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15787
15788#undef ARM_VARIANT
e74cfd16 15789#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15790 /* Moves and type conversions. */
8f06b2d8
PB
15791 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15793 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15794 cCE(fmstat, ef1fa10, 0, (), noargs),
15795 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15796 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15797 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15798 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15799 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15800 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15801 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15802 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15803
15804 /* Memory operations. */
4962c51a
MS
15805 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15806 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15807 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15808 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15809 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15810 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15811 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15812 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15813 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15814 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15815 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15816 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15817 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15818 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15819 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15820 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15821 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15822 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15823
c19d1205 15824 /* Monadic operations. */
8f06b2d8
PB
15825 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15826 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15827 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15828
15829 /* Dyadic operations. */
8f06b2d8
PB
15830 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15833 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15834 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15835 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15836 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15837 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15838 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15839
c19d1205 15840 /* Comparisons. */
8f06b2d8
PB
15841 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15842 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15843 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15844 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15845
c19d1205 15846#undef ARM_VARIANT
e74cfd16 15847#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15848 /* Moves and type conversions. */
5287ad62 15849 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15850 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15851 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15852 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15853 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15854 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15855 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15856 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15857 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15858 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15859 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15860 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15861 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15862
15863 /* Memory operations. */
4962c51a
MS
15864 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15865 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15866 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15867 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15868 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15869 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15870 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15871 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15872 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15873 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15874
c19d1205 15875 /* Monadic operations. */
5287ad62
JB
15876 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15877 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15878 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15879
15880 /* Dyadic operations. */
5287ad62
JB
15881 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15884 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15885 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15886 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15887 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15888 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15889 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15890
c19d1205 15891 /* Comparisons. */
5287ad62
JB
15892 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15893 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15894 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15895 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15896
15897#undef ARM_VARIANT
e74cfd16 15898#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15899 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15900 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15901 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15902 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15903
037e8744
JB
15904/* Instructions which may belong to either the Neon or VFP instruction sets.
15905 Individual encoder functions perform additional architecture checks. */
15906#undef ARM_VARIANT
15907#define ARM_VARIANT &fpu_vfp_ext_v1xd
15908#undef THUMB_VARIANT
15909#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15910 /* These mnemonics are unique to VFP. */
15911 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15912 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15913 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15914 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15915 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15916 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15917 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15918 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15919 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15920 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15921
15922 /* Mnemonics shared by Neon and VFP. */
15923 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15924 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15925 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15926
15927 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15928 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15929
15930 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15931 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15932
15933 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15934 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15935 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15936 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15937 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15938 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15939 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15940 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15941
15942 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15943
15944 /* NOTE: All VMOV encoding is special-cased! */
15945 NCE(vmov, 0, 1, (VMOV), neon_mov),
15946 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15947
5287ad62
JB
15948#undef THUMB_VARIANT
15949#define THUMB_VARIANT &fpu_neon_ext_v1
15950#undef ARM_VARIANT
15951#define ARM_VARIANT &fpu_neon_ext_v1
15952 /* Data processing with three registers of the same length. */
15953 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15954 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15956 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15957 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15958 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15959 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15960 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15961 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15962 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15963 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15964 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15965 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15966 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15967 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15968 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15969 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15970 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15971 /* If not immediate, fall back to neon_dyadic_i64_su.
15972 shl_imm should accept I8 I16 I32 I64,
15973 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15974 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15975 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15976 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15977 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15978 /* Logic ops, types optional & ignored. */
15979 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15981 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15982 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15983 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15984 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15985 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15986 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15987 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15988 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15989 /* Bitfield ops, untyped. */
15990 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15991 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15992 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15993 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15994 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15995 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15996 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15997 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15998 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15999 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16000 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16001 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16002 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16003 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16004 back to neon_dyadic_if_su. */
16005 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16006 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16007 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16008 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16009 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16010 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16011 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16012 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16013 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16014 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16015 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16016 /* As above, D registers only. */
16017 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16018 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16019 /* Int and float variants, signedness unimportant. */
5287ad62 16020 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16021 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16022 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16023 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16024 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16025 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16026 /* vtst takes sizes 8, 16, 32. */
16027 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16028 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16029 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16030 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16031 /* VQD{R}MULH takes S16 S32. */
16032 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16033 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16034 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16035 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16036 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16037 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16038 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16039 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16040 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16041 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16042 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16043 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16044 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16045 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16046 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16047 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16048
16049 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16050 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16051 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16052
16053 /* Data processing with two registers and a shift amount. */
16054 /* Right shifts, and variants with rounding.
16055 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16056 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16057 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16058 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16059 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16060 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16061 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16062 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16063 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16064 /* Shift and insert. Sizes accepted 8 16 32 64. */
16065 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16066 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16067 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16068 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16069 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16070 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16071 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16072 /* Right shift immediate, saturating & narrowing, with rounding variants.
16073 Types accepted S16 S32 S64 U16 U32 U64. */
16074 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16075 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16076 /* As above, unsigned. Types accepted S16 S32 S64. */
16077 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16078 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16079 /* Right shift narrowing. Types accepted I16 I32 I64. */
16080 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16081 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16082 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16083 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16084 /* CVT with optional immediate for fixed-point variant. */
037e8744 16085 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16086
5287ad62
JB
16087 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16088 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16089
16090 /* Data processing, three registers of different lengths. */
16091 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16092 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16093 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16094 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16095 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16096 /* If not scalar, fall back to neon_dyadic_long.
16097 Vector types as above, scalar types S16 S32 U16 U32. */
16098 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16099 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16100 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16101 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16102 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16103 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16104 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16105 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16106 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16107 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16108 /* Saturating doubling multiplies. Types S16 S32. */
16109 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16110 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16111 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16112 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16113 S16 S32 U16 U32. */
16114 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16115
16116 /* Extract. Size 8. */
3b8d421e
PB
16117 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16118 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16119
16120 /* Two registers, miscellaneous. */
16121 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16122 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16123 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16124 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16125 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16126 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16127 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16128 /* Vector replicate. Sizes 8 16 32. */
16129 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16130 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16131 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16132 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16133 /* VMOVN. Types I16 I32 I64. */
16134 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16135 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16136 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16137 /* VQMOVUN. Types S16 S32 S64. */
16138 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16139 /* VZIP / VUZP. Sizes 8 16 32. */
16140 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16141 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16142 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16143 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16144 /* VQABS / VQNEG. Types S8 S16 S32. */
16145 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16146 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16147 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16148 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16149 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16150 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16151 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16152 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16153 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16154 /* Reciprocal estimates. Types U32 F32. */
16155 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16156 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16157 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16158 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16159 /* VCLS. Types S8 S16 S32. */
16160 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16161 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16162 /* VCLZ. Types I8 I16 I32. */
16163 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16164 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16165 /* VCNT. Size 8. */
16166 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16167 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16168 /* Two address, untyped. */
16169 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16170 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16171 /* VTRN. Sizes 8 16 32. */
16172 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16173 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16174
16175 /* Table lookup. Size 8. */
16176 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16177 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16178
b7fc2769
JB
16179#undef THUMB_VARIANT
16180#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16181#undef ARM_VARIANT
16182#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16183 /* Neon element/structure load/store. */
16184 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16187 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16188 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16189 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16190 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16191 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16192
16193#undef THUMB_VARIANT
16194#define THUMB_VARIANT &fpu_vfp_ext_v3
16195#undef ARM_VARIANT
16196#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16197 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16198 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16199 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16200 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16201 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16202 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16203 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16204 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16205 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16206 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16207 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16208 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16209 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16210 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16211 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16212 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16213 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16214 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16215
5287ad62 16216#undef THUMB_VARIANT
c19d1205 16217#undef ARM_VARIANT
e74cfd16 16218#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16219 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16220 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16221 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16222 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16223 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16224 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16225 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16226 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16227
16228#undef ARM_VARIANT
e74cfd16 16229#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16230 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16231 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16232 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16233 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16234 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16235 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16236 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16237 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16238 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16239 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16240 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16241 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16242 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16243 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16244 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16245 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16246 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16247 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16248 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16249 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16250 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16251 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16252 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16253 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16254 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16255 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16256 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16257 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16258 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16259 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16260 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16261 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16262 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16263 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16264 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16265 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16266 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16267 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16277 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16291 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16292 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16293 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16294 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16297 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16298 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16299 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16300 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16319 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16328 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16330 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16331 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16332 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16333 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16334 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16335 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16336 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16337 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16338 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16339 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16340 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16341 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16342 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16343 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16344 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16345 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16346 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16347 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16348 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16349 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16350 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16351 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16352 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16353 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16354 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16355 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16356 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16357 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16358 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16359 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16360 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16361 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16362 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16363 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16369 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16370 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16371 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16372 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16373 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16374 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16375 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16376 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16377 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16379 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16382 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16383 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16384 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16385 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16386 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16387 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16391 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16392
2d447fca
JM
16393#undef ARM_VARIANT
16394#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16395 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16396 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16397 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16398 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16399 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16400 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16401 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16416 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16448 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16449 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16450 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16451 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16452
c19d1205 16453#undef ARM_VARIANT
e74cfd16 16454#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16455 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16456 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16457 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16458 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16459 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16460 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16461 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16462 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16463 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16464 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16465 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16466 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16467 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16468 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16469 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16470 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16471 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16472 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16473 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16476 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16477 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16478 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16479 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16480 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16481 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16482 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16483 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16484 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16485 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16486 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16487 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16488 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16489 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16490 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16491 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16492 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16493 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16494 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16495 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16496 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16497 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16498 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16499 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16500 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16501 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16502 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16503 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16504 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16505 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16506 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16507 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16508 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16509 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16510 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16511 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16512 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16513 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16514 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16515 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16516 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16517 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16518 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16519 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16521 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16522 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16523 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16524 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16525 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16526 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16527 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16528 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16529 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16530 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16531};
16532#undef ARM_VARIANT
16533#undef THUMB_VARIANT
16534#undef TCE
16535#undef TCM
16536#undef TUE
16537#undef TUF
16538#undef TCC
8f06b2d8 16539#undef cCE
e3cb604e
PB
16540#undef cCL
16541#undef C3E
c19d1205
ZW
16542#undef CE
16543#undef CM
16544#undef UE
16545#undef UF
16546#undef UT
5287ad62
JB
16547#undef NUF
16548#undef nUF
16549#undef NCE
16550#undef nCE
c19d1205
ZW
16551#undef OPS0
16552#undef OPS1
16553#undef OPS2
16554#undef OPS3
16555#undef OPS4
16556#undef OPS5
16557#undef OPS6
16558#undef do_0
16559\f
16560/* MD interface: bits in the object file. */
bfae80f2 16561
c19d1205
ZW
16562/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16563 for use in the a.out file, and stores them in the array pointed to by buf.
16564 This knows about the endian-ness of the target machine and does
16565 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16566 2 (short) and 4 (long) Floating numbers are put out as a series of
16567 LITTLENUMS (shorts, here at least). */
b99bd4ef 16568
c19d1205
ZW
16569void
16570md_number_to_chars (char * buf, valueT val, int n)
16571{
16572 if (target_big_endian)
16573 number_to_chars_bigendian (buf, val, n);
16574 else
16575 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16576}
16577
c19d1205
ZW
16578static valueT
16579md_chars_to_number (char * buf, int n)
bfae80f2 16580{
c19d1205
ZW
16581 valueT result = 0;
16582 unsigned char * where = (unsigned char *) buf;
bfae80f2 16583
c19d1205 16584 if (target_big_endian)
b99bd4ef 16585 {
c19d1205
ZW
16586 while (n--)
16587 {
16588 result <<= 8;
16589 result |= (*where++ & 255);
16590 }
b99bd4ef 16591 }
c19d1205 16592 else
b99bd4ef 16593 {
c19d1205
ZW
16594 while (n--)
16595 {
16596 result <<= 8;
16597 result |= (where[n] & 255);
16598 }
bfae80f2 16599 }
b99bd4ef 16600
c19d1205 16601 return result;
bfae80f2 16602}
b99bd4ef 16603
c19d1205 16604/* MD interface: Sections. */
b99bd4ef 16605
0110f2b8
PB
16606/* Estimate the size of a frag before relaxing. Assume everything fits in
16607 2 bytes. */
16608
c19d1205 16609int
0110f2b8 16610md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16611 segT segtype ATTRIBUTE_UNUSED)
16612{
0110f2b8
PB
16613 fragp->fr_var = 2;
16614 return 2;
16615}
16616
16617/* Convert a machine dependent frag. */
16618
16619void
16620md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16621{
16622 unsigned long insn;
16623 unsigned long old_op;
16624 char *buf;
16625 expressionS exp;
16626 fixS *fixp;
16627 int reloc_type;
16628 int pc_rel;
16629 int opcode;
16630
16631 buf = fragp->fr_literal + fragp->fr_fix;
16632
16633 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
16634 if (fragp->fr_symbol)
16635 {
0110f2b8
PB
16636 exp.X_op = O_symbol;
16637 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
16638 }
16639 else
16640 {
0110f2b8 16641 exp.X_op = O_constant;
5f4273c7 16642 }
0110f2b8
PB
16643 exp.X_add_number = fragp->fr_offset;
16644 opcode = fragp->fr_subtype;
16645 switch (opcode)
16646 {
16647 case T_MNEM_ldr_pc:
16648 case T_MNEM_ldr_pc2:
16649 case T_MNEM_ldr_sp:
16650 case T_MNEM_str_sp:
16651 case T_MNEM_ldr:
16652 case T_MNEM_ldrb:
16653 case T_MNEM_ldrh:
16654 case T_MNEM_str:
16655 case T_MNEM_strb:
16656 case T_MNEM_strh:
16657 if (fragp->fr_var == 4)
16658 {
5f4273c7 16659 insn = THUMB_OP32 (opcode);
0110f2b8
PB
16660 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16661 {
16662 insn |= (old_op & 0x700) << 4;
16663 }
16664 else
16665 {
16666 insn |= (old_op & 7) << 12;
16667 insn |= (old_op & 0x38) << 13;
16668 }
16669 insn |= 0x00000c00;
16670 put_thumb32_insn (buf, insn);
16671 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16672 }
16673 else
16674 {
16675 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16676 }
16677 pc_rel = (opcode == T_MNEM_ldr_pc2);
16678 break;
16679 case T_MNEM_adr:
16680 if (fragp->fr_var == 4)
16681 {
16682 insn = THUMB_OP32 (opcode);
16683 insn |= (old_op & 0xf0) << 4;
16684 put_thumb32_insn (buf, insn);
16685 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16686 }
16687 else
16688 {
16689 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16690 exp.X_add_number -= 4;
16691 }
16692 pc_rel = 1;
16693 break;
16694 case T_MNEM_mov:
16695 case T_MNEM_movs:
16696 case T_MNEM_cmp:
16697 case T_MNEM_cmn:
16698 if (fragp->fr_var == 4)
16699 {
16700 int r0off = (opcode == T_MNEM_mov
16701 || opcode == T_MNEM_movs) ? 0 : 8;
16702 insn = THUMB_OP32 (opcode);
16703 insn = (insn & 0xe1ffffff) | 0x10000000;
16704 insn |= (old_op & 0x700) << r0off;
16705 put_thumb32_insn (buf, insn);
16706 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16707 }
16708 else
16709 {
16710 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16711 }
16712 pc_rel = 0;
16713 break;
16714 case T_MNEM_b:
16715 if (fragp->fr_var == 4)
16716 {
16717 insn = THUMB_OP32(opcode);
16718 put_thumb32_insn (buf, insn);
16719 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16720 }
16721 else
16722 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16723 pc_rel = 1;
16724 break;
16725 case T_MNEM_bcond:
16726 if (fragp->fr_var == 4)
16727 {
16728 insn = THUMB_OP32(opcode);
16729 insn |= (old_op & 0xf00) << 14;
16730 put_thumb32_insn (buf, insn);
16731 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16732 }
16733 else
16734 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16735 pc_rel = 1;
16736 break;
16737 case T_MNEM_add_sp:
16738 case T_MNEM_add_pc:
16739 case T_MNEM_inc_sp:
16740 case T_MNEM_dec_sp:
16741 if (fragp->fr_var == 4)
16742 {
16743 /* ??? Choose between add and addw. */
16744 insn = THUMB_OP32 (opcode);
16745 insn |= (old_op & 0xf0) << 4;
16746 put_thumb32_insn (buf, insn);
16805f35
PB
16747 if (opcode == T_MNEM_add_pc)
16748 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16749 else
16750 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16751 }
16752 else
16753 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16754 pc_rel = 0;
16755 break;
16756
16757 case T_MNEM_addi:
16758 case T_MNEM_addis:
16759 case T_MNEM_subi:
16760 case T_MNEM_subis:
16761 if (fragp->fr_var == 4)
16762 {
16763 insn = THUMB_OP32 (opcode);
16764 insn |= (old_op & 0xf0) << 4;
16765 insn |= (old_op & 0xf) << 16;
16766 put_thumb32_insn (buf, insn);
16805f35
PB
16767 if (insn & (1 << 20))
16768 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16769 else
16770 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16771 }
16772 else
16773 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16774 pc_rel = 0;
16775 break;
16776 default:
5f4273c7 16777 abort ();
0110f2b8
PB
16778 }
16779 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16780 reloc_type);
16781 fixp->fx_file = fragp->fr_file;
16782 fixp->fx_line = fragp->fr_line;
16783 fragp->fr_fix += fragp->fr_var;
16784}
16785
16786/* Return the size of a relaxable immediate operand instruction.
16787 SHIFT and SIZE specify the form of the allowable immediate. */
16788static int
16789relax_immediate (fragS *fragp, int size, int shift)
16790{
16791 offsetT offset;
16792 offsetT mask;
16793 offsetT low;
16794
16795 /* ??? Should be able to do better than this. */
16796 if (fragp->fr_symbol)
16797 return 4;
16798
16799 low = (1 << shift) - 1;
16800 mask = (1 << (shift + size)) - (1 << shift);
16801 offset = fragp->fr_offset;
16802 /* Force misaligned offsets to 32-bit variant. */
16803 if (offset & low)
5e77afaa 16804 return 4;
0110f2b8
PB
16805 if (offset & ~mask)
16806 return 4;
16807 return 2;
16808}
16809
5e77afaa
PB
16810/* Get the address of a symbol during relaxation. */
16811static addressT
5f4273c7 16812relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
16813{
16814 fragS *sym_frag;
16815 addressT addr;
16816 symbolS *sym;
16817
16818 sym = fragp->fr_symbol;
16819 sym_frag = symbol_get_frag (sym);
16820 know (S_GET_SEGMENT (sym) != absolute_section
16821 || sym_frag == &zero_address_frag);
16822 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16823
16824 /* If frag has yet to be reached on this pass, assume it will
16825 move by STRETCH just as we did. If this is not so, it will
16826 be because some frag between grows, and that will force
16827 another pass. */
16828
16829 if (stretch != 0
16830 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
16831 {
16832 fragS *f;
16833
16834 /* Adjust stretch for any alignment frag. Note that if have
16835 been expanding the earlier code, the symbol may be
16836 defined in what appears to be an earlier frag. FIXME:
16837 This doesn't handle the fr_subtype field, which specifies
16838 a maximum number of bytes to skip when doing an
16839 alignment. */
16840 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16841 {
16842 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16843 {
16844 if (stretch < 0)
16845 stretch = - ((- stretch)
16846 & ~ ((1 << (int) f->fr_offset) - 1));
16847 else
16848 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16849 if (stretch == 0)
16850 break;
16851 }
16852 }
16853 if (f != NULL)
16854 addr += stretch;
16855 }
5e77afaa
PB
16856
16857 return addr;
16858}
16859
0110f2b8
PB
16860/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16861 load. */
16862static int
5e77afaa 16863relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16864{
16865 addressT addr;
16866 offsetT val;
16867
16868 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16869 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16870 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16871 return 4;
16872
5f4273c7 16873 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16874 addr = fragp->fr_address + fragp->fr_fix;
16875 addr = (addr + 4) & ~3;
5e77afaa 16876 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16877 if (val & 3)
5e77afaa 16878 return 4;
0110f2b8
PB
16879 val -= addr;
16880 if (val < 0 || val > 1020)
16881 return 4;
16882 return 2;
16883}
16884
16885/* Return the size of a relaxable add/sub immediate instruction. */
16886static int
16887relax_addsub (fragS *fragp, asection *sec)
16888{
16889 char *buf;
16890 int op;
16891
16892 buf = fragp->fr_literal + fragp->fr_fix;
16893 op = bfd_get_16(sec->owner, buf);
16894 if ((op & 0xf) == ((op >> 4) & 0xf))
16895 return relax_immediate (fragp, 8, 0);
16896 else
16897 return relax_immediate (fragp, 3, 0);
16898}
16899
16900
16901/* Return the size of a relaxable branch instruction. BITS is the
16902 size of the offset field in the narrow instruction. */
16903
16904static int
5e77afaa 16905relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16906{
16907 addressT addr;
16908 offsetT val;
16909 offsetT limit;
16910
16911 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16912 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16913 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16914 return 4;
16915
5f4273c7 16916 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16917 addr = fragp->fr_address + fragp->fr_fix + 4;
16918 val -= addr;
16919
16920 /* Offset is a signed value *2 */
16921 limit = 1 << bits;
16922 if (val >= limit || val < -limit)
16923 return 4;
16924 return 2;
16925}
16926
16927
16928/* Relax a machine dependent frag. This returns the amount by which
16929 the current size of the frag should change. */
16930
16931int
5e77afaa 16932arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16933{
16934 int oldsize;
16935 int newsize;
16936
16937 oldsize = fragp->fr_var;
16938 switch (fragp->fr_subtype)
16939 {
16940 case T_MNEM_ldr_pc2:
5f4273c7 16941 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16942 break;
16943 case T_MNEM_ldr_pc:
16944 case T_MNEM_ldr_sp:
16945 case T_MNEM_str_sp:
5f4273c7 16946 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
16947 break;
16948 case T_MNEM_ldr:
16949 case T_MNEM_str:
5f4273c7 16950 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
16951 break;
16952 case T_MNEM_ldrh:
16953 case T_MNEM_strh:
5f4273c7 16954 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
16955 break;
16956 case T_MNEM_ldrb:
16957 case T_MNEM_strb:
5f4273c7 16958 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
16959 break;
16960 case T_MNEM_adr:
5f4273c7 16961 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16962 break;
16963 case T_MNEM_mov:
16964 case T_MNEM_movs:
16965 case T_MNEM_cmp:
16966 case T_MNEM_cmn:
5f4273c7 16967 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
16968 break;
16969 case T_MNEM_b:
5f4273c7 16970 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
16971 break;
16972 case T_MNEM_bcond:
5f4273c7 16973 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
16974 break;
16975 case T_MNEM_add_sp:
16976 case T_MNEM_add_pc:
16977 newsize = relax_immediate (fragp, 8, 2);
16978 break;
16979 case T_MNEM_inc_sp:
16980 case T_MNEM_dec_sp:
16981 newsize = relax_immediate (fragp, 7, 2);
16982 break;
16983 case T_MNEM_addi:
16984 case T_MNEM_addis:
16985 case T_MNEM_subi:
16986 case T_MNEM_subis:
16987 newsize = relax_addsub (fragp, sec);
16988 break;
16989 default:
5f4273c7 16990 abort ();
0110f2b8 16991 }
5e77afaa
PB
16992
16993 fragp->fr_var = newsize;
16994 /* Freeze wide instructions that are at or before the same location as
16995 in the previous pass. This avoids infinite loops.
5f4273c7
NC
16996 Don't freeze them unconditionally because targets may be artificially
16997 misaligned by the expansion of preceding frags. */
5e77afaa 16998 if (stretch <= 0 && newsize > 2)
0110f2b8 16999 {
0110f2b8 17000 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 17001 frag_wane (fragp);
0110f2b8 17002 }
5e77afaa 17003
0110f2b8 17004 return newsize - oldsize;
c19d1205 17005}
b99bd4ef 17006
c19d1205 17007/* Round up a section size to the appropriate boundary. */
b99bd4ef 17008
c19d1205
ZW
17009valueT
17010md_section_align (segT segment ATTRIBUTE_UNUSED,
17011 valueT size)
17012{
f0927246
NC
17013#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17014 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17015 {
17016 /* For a.out, force the section size to be aligned. If we don't do
17017 this, BFD will align it for us, but it will not write out the
17018 final bytes of the section. This may be a bug in BFD, but it is
17019 easier to fix it here since that is how the other a.out targets
17020 work. */
17021 int align;
17022
17023 align = bfd_get_section_alignment (stdoutput, segment);
17024 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17025 }
c19d1205 17026#endif
f0927246
NC
17027
17028 return size;
bfae80f2 17029}
b99bd4ef 17030
c19d1205
ZW
17031/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17032 of an rs_align_code fragment. */
17033
17034void
17035arm_handle_align (fragS * fragP)
bfae80f2 17036{
c19d1205
ZW
17037 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17038 static char const thumb_noop[2] = { 0xc0, 0x46 };
17039 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17040 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17041
17042 int bytes, fix, noop_size;
17043 char * p;
17044 const char * noop;
bfae80f2 17045
c19d1205 17046 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17047 return;
17048
c19d1205
ZW
17049 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17050 p = fragP->fr_literal + fragP->fr_fix;
17051 fix = 0;
bfae80f2 17052
c19d1205
ZW
17053 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17054 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17055
c19d1205 17056 if (fragP->tc_frag_data)
a737bd4d 17057 {
c19d1205
ZW
17058 if (target_big_endian)
17059 noop = thumb_bigend_noop;
17060 else
17061 noop = thumb_noop;
17062 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17063 }
17064 else
17065 {
c19d1205
ZW
17066 if (target_big_endian)
17067 noop = arm_bigend_noop;
17068 else
17069 noop = arm_noop;
17070 noop_size = sizeof (arm_noop);
7ed4c4c5 17071 }
a737bd4d 17072
c19d1205 17073 if (bytes & (noop_size - 1))
7ed4c4c5 17074 {
c19d1205
ZW
17075 fix = bytes & (noop_size - 1);
17076 memset (p, 0, fix);
17077 p += fix;
17078 bytes -= fix;
a737bd4d 17079 }
a737bd4d 17080
c19d1205 17081 while (bytes >= noop_size)
a737bd4d 17082 {
c19d1205
ZW
17083 memcpy (p, noop, noop_size);
17084 p += noop_size;
17085 bytes -= noop_size;
17086 fix += noop_size;
a737bd4d
NC
17087 }
17088
c19d1205
ZW
17089 fragP->fr_fix += fix;
17090 fragP->fr_var = noop_size;
a737bd4d
NC
17091}
17092
c19d1205
ZW
17093/* Called from md_do_align. Used to create an alignment
17094 frag in a code section. */
17095
17096void
17097arm_frag_align_code (int n, int max)
bfae80f2 17098{
c19d1205 17099 char * p;
7ed4c4c5 17100
c19d1205
ZW
17101 /* We assume that there will never be a requirement
17102 to support alignments greater than 32 bytes. */
17103 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17104 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17105
c19d1205
ZW
17106 p = frag_var (rs_align_code,
17107 MAX_MEM_FOR_RS_ALIGN_CODE,
17108 1,
17109 (relax_substateT) max,
17110 (symbolS *) NULL,
17111 (offsetT) n,
17112 (char *) NULL);
17113 *p = 0;
17114}
bfae80f2 17115
c19d1205 17116/* Perform target specific initialisation of a frag. */
bfae80f2 17117
c19d1205
ZW
17118void
17119arm_init_frag (fragS * fragP)
17120{
17121 /* Record whether this frag is in an ARM or a THUMB area. */
17122 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17123}
17124
c19d1205
ZW
17125#ifdef OBJ_ELF
17126/* When we change sections we need to issue a new mapping symbol. */
17127
17128void
17129arm_elf_change_section (void)
bfae80f2 17130{
c19d1205
ZW
17131 flagword flags;
17132 segment_info_type *seginfo;
bfae80f2 17133
c19d1205
ZW
17134 /* Link an unlinked unwind index table section to the .text section. */
17135 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17136 && elf_linked_to_section (now_seg) == NULL)
17137 elf_linked_to_section (now_seg) = text_section;
17138
17139 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17140 return;
17141
c19d1205
ZW
17142 flags = bfd_get_section_flags (stdoutput, now_seg);
17143
17144 /* We can ignore sections that only contain debug info. */
17145 if ((flags & SEC_ALLOC) == 0)
17146 return;
bfae80f2 17147
c19d1205
ZW
17148 seginfo = seg_info (now_seg);
17149 mapstate = seginfo->tc_segment_info_data.mapstate;
17150 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17151}
17152
c19d1205
ZW
17153int
17154arm_elf_section_type (const char * str, size_t len)
e45d0630 17155{
c19d1205
ZW
17156 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17157 return SHT_ARM_EXIDX;
e45d0630 17158
c19d1205
ZW
17159 return -1;
17160}
17161\f
17162/* Code to deal with unwinding tables. */
e45d0630 17163
c19d1205 17164static void add_unwind_adjustsp (offsetT);
e45d0630 17165
5f4273c7 17166/* Generate any deferred unwind frame offset. */
e45d0630 17167
bfae80f2 17168static void
c19d1205 17169flush_pending_unwind (void)
bfae80f2 17170{
c19d1205 17171 offsetT offset;
bfae80f2 17172
c19d1205
ZW
17173 offset = unwind.pending_offset;
17174 unwind.pending_offset = 0;
17175 if (offset != 0)
17176 add_unwind_adjustsp (offset);
bfae80f2
RE
17177}
17178
c19d1205
ZW
17179/* Add an opcode to this list for this function. Two-byte opcodes should
17180 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17181 order. */
17182
bfae80f2 17183static void
c19d1205 17184add_unwind_opcode (valueT op, int length)
bfae80f2 17185{
c19d1205
ZW
17186 /* Add any deferred stack adjustment. */
17187 if (unwind.pending_offset)
17188 flush_pending_unwind ();
bfae80f2 17189
c19d1205 17190 unwind.sp_restored = 0;
bfae80f2 17191
c19d1205 17192 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17193 {
c19d1205
ZW
17194 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17195 if (unwind.opcodes)
17196 unwind.opcodes = xrealloc (unwind.opcodes,
17197 unwind.opcode_alloc);
17198 else
17199 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17200 }
c19d1205 17201 while (length > 0)
bfae80f2 17202 {
c19d1205
ZW
17203 length--;
17204 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17205 op >>= 8;
17206 unwind.opcode_count++;
bfae80f2 17207 }
bfae80f2
RE
17208}
17209
c19d1205
ZW
17210/* Add unwind opcodes to adjust the stack pointer. */
17211
bfae80f2 17212static void
c19d1205 17213add_unwind_adjustsp (offsetT offset)
bfae80f2 17214{
c19d1205 17215 valueT op;
bfae80f2 17216
c19d1205 17217 if (offset > 0x200)
bfae80f2 17218 {
c19d1205
ZW
17219 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17220 char bytes[5];
17221 int n;
17222 valueT o;
bfae80f2 17223
c19d1205
ZW
17224 /* Long form: 0xb2, uleb128. */
17225 /* This might not fit in a word so add the individual bytes,
17226 remembering the list is built in reverse order. */
17227 o = (valueT) ((offset - 0x204) >> 2);
17228 if (o == 0)
17229 add_unwind_opcode (0, 1);
bfae80f2 17230
c19d1205
ZW
17231 /* Calculate the uleb128 encoding of the offset. */
17232 n = 0;
17233 while (o)
17234 {
17235 bytes[n] = o & 0x7f;
17236 o >>= 7;
17237 if (o)
17238 bytes[n] |= 0x80;
17239 n++;
17240 }
17241 /* Add the insn. */
17242 for (; n; n--)
17243 add_unwind_opcode (bytes[n - 1], 1);
17244 add_unwind_opcode (0xb2, 1);
17245 }
17246 else if (offset > 0x100)
bfae80f2 17247 {
c19d1205
ZW
17248 /* Two short opcodes. */
17249 add_unwind_opcode (0x3f, 1);
17250 op = (offset - 0x104) >> 2;
17251 add_unwind_opcode (op, 1);
bfae80f2 17252 }
c19d1205
ZW
17253 else if (offset > 0)
17254 {
17255 /* Short opcode. */
17256 op = (offset - 4) >> 2;
17257 add_unwind_opcode (op, 1);
17258 }
17259 else if (offset < 0)
bfae80f2 17260 {
c19d1205
ZW
17261 offset = -offset;
17262 while (offset > 0x100)
bfae80f2 17263 {
c19d1205
ZW
17264 add_unwind_opcode (0x7f, 1);
17265 offset -= 0x100;
bfae80f2 17266 }
c19d1205
ZW
17267 op = ((offset - 4) >> 2) | 0x40;
17268 add_unwind_opcode (op, 1);
bfae80f2 17269 }
bfae80f2
RE
17270}
17271
c19d1205
ZW
17272/* Finish the list of unwind opcodes for this function. */
17273static void
17274finish_unwind_opcodes (void)
bfae80f2 17275{
c19d1205 17276 valueT op;
bfae80f2 17277
c19d1205 17278 if (unwind.fp_used)
bfae80f2 17279 {
708587a4 17280 /* Adjust sp as necessary. */
c19d1205
ZW
17281 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17282 flush_pending_unwind ();
bfae80f2 17283
c19d1205
ZW
17284 /* After restoring sp from the frame pointer. */
17285 op = 0x90 | unwind.fp_reg;
17286 add_unwind_opcode (op, 1);
17287 }
17288 else
17289 flush_pending_unwind ();
bfae80f2
RE
17290}
17291
bfae80f2 17292
c19d1205
ZW
17293/* Start an exception table entry. If idx is nonzero this is an index table
17294 entry. */
bfae80f2
RE
17295
17296static void
c19d1205 17297start_unwind_section (const segT text_seg, int idx)
bfae80f2 17298{
c19d1205
ZW
17299 const char * text_name;
17300 const char * prefix;
17301 const char * prefix_once;
17302 const char * group_name;
17303 size_t prefix_len;
17304 size_t text_len;
17305 char * sec_name;
17306 size_t sec_name_len;
17307 int type;
17308 int flags;
17309 int linkonce;
bfae80f2 17310
c19d1205 17311 if (idx)
bfae80f2 17312 {
c19d1205
ZW
17313 prefix = ELF_STRING_ARM_unwind;
17314 prefix_once = ELF_STRING_ARM_unwind_once;
17315 type = SHT_ARM_EXIDX;
bfae80f2 17316 }
c19d1205 17317 else
bfae80f2 17318 {
c19d1205
ZW
17319 prefix = ELF_STRING_ARM_unwind_info;
17320 prefix_once = ELF_STRING_ARM_unwind_info_once;
17321 type = SHT_PROGBITS;
bfae80f2
RE
17322 }
17323
c19d1205
ZW
17324 text_name = segment_name (text_seg);
17325 if (streq (text_name, ".text"))
17326 text_name = "";
17327
17328 if (strncmp (text_name, ".gnu.linkonce.t.",
17329 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17330 {
c19d1205
ZW
17331 prefix = prefix_once;
17332 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17333 }
17334
c19d1205
ZW
17335 prefix_len = strlen (prefix);
17336 text_len = strlen (text_name);
17337 sec_name_len = prefix_len + text_len;
17338 sec_name = xmalloc (sec_name_len + 1);
17339 memcpy (sec_name, prefix, prefix_len);
17340 memcpy (sec_name + prefix_len, text_name, text_len);
17341 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17342
c19d1205
ZW
17343 flags = SHF_ALLOC;
17344 linkonce = 0;
17345 group_name = 0;
bfae80f2 17346
c19d1205
ZW
17347 /* Handle COMDAT group. */
17348 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17349 {
c19d1205
ZW
17350 group_name = elf_group_name (text_seg);
17351 if (group_name == NULL)
17352 {
bd3ba5d1 17353 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17354 segment_name (text_seg));
17355 ignore_rest_of_line ();
17356 return;
17357 }
17358 flags |= SHF_GROUP;
17359 linkonce = 1;
bfae80f2
RE
17360 }
17361
c19d1205 17362 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17363
5f4273c7 17364 /* Set the section link for index tables. */
c19d1205
ZW
17365 if (idx)
17366 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17367}
17368
bfae80f2 17369
c19d1205
ZW
17370/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17371 personality routine data. Returns zero, or the index table value for
17372 and inline entry. */
17373
17374static valueT
17375create_unwind_entry (int have_data)
bfae80f2 17376{
c19d1205
ZW
17377 int size;
17378 addressT where;
17379 char *ptr;
17380 /* The current word of data. */
17381 valueT data;
17382 /* The number of bytes left in this word. */
17383 int n;
bfae80f2 17384
c19d1205 17385 finish_unwind_opcodes ();
bfae80f2 17386
c19d1205
ZW
17387 /* Remember the current text section. */
17388 unwind.saved_seg = now_seg;
17389 unwind.saved_subseg = now_subseg;
bfae80f2 17390
c19d1205 17391 start_unwind_section (now_seg, 0);
bfae80f2 17392
c19d1205 17393 if (unwind.personality_routine == NULL)
bfae80f2 17394 {
c19d1205
ZW
17395 if (unwind.personality_index == -2)
17396 {
17397 if (have_data)
5f4273c7 17398 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17399 return 1; /* EXIDX_CANTUNWIND. */
17400 }
bfae80f2 17401
c19d1205
ZW
17402 /* Use a default personality routine if none is specified. */
17403 if (unwind.personality_index == -1)
17404 {
17405 if (unwind.opcode_count > 3)
17406 unwind.personality_index = 1;
17407 else
17408 unwind.personality_index = 0;
17409 }
bfae80f2 17410
c19d1205
ZW
17411 /* Space for the personality routine entry. */
17412 if (unwind.personality_index == 0)
17413 {
17414 if (unwind.opcode_count > 3)
17415 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17416
c19d1205
ZW
17417 if (!have_data)
17418 {
17419 /* All the data is inline in the index table. */
17420 data = 0x80;
17421 n = 3;
17422 while (unwind.opcode_count > 0)
17423 {
17424 unwind.opcode_count--;
17425 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17426 n--;
17427 }
bfae80f2 17428
c19d1205
ZW
17429 /* Pad with "finish" opcodes. */
17430 while (n--)
17431 data = (data << 8) | 0xb0;
bfae80f2 17432
c19d1205
ZW
17433 return data;
17434 }
17435 size = 0;
17436 }
17437 else
17438 /* We get two opcodes "free" in the first word. */
17439 size = unwind.opcode_count - 2;
17440 }
17441 else
17442 /* An extra byte is required for the opcode count. */
17443 size = unwind.opcode_count + 1;
bfae80f2 17444
c19d1205
ZW
17445 size = (size + 3) >> 2;
17446 if (size > 0xff)
17447 as_bad (_("too many unwind opcodes"));
bfae80f2 17448
c19d1205
ZW
17449 frag_align (2, 0, 0);
17450 record_alignment (now_seg, 2);
17451 unwind.table_entry = expr_build_dot ();
17452
17453 /* Allocate the table entry. */
17454 ptr = frag_more ((size << 2) + 4);
17455 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17456
c19d1205 17457 switch (unwind.personality_index)
bfae80f2 17458 {
c19d1205
ZW
17459 case -1:
17460 /* ??? Should this be a PLT generating relocation? */
17461 /* Custom personality routine. */
17462 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17463 BFD_RELOC_ARM_PREL31);
bfae80f2 17464
c19d1205
ZW
17465 where += 4;
17466 ptr += 4;
bfae80f2 17467
c19d1205
ZW
17468 /* Set the first byte to the number of additional words. */
17469 data = size - 1;
17470 n = 3;
17471 break;
bfae80f2 17472
c19d1205
ZW
17473 /* ABI defined personality routines. */
17474 case 0:
17475 /* Three opcodes bytes are packed into the first word. */
17476 data = 0x80;
17477 n = 3;
17478 break;
bfae80f2 17479
c19d1205
ZW
17480 case 1:
17481 case 2:
17482 /* The size and first two opcode bytes go in the first word. */
17483 data = ((0x80 + unwind.personality_index) << 8) | size;
17484 n = 2;
17485 break;
bfae80f2 17486
c19d1205
ZW
17487 default:
17488 /* Should never happen. */
17489 abort ();
17490 }
bfae80f2 17491
c19d1205
ZW
17492 /* Pack the opcodes into words (MSB first), reversing the list at the same
17493 time. */
17494 while (unwind.opcode_count > 0)
17495 {
17496 if (n == 0)
17497 {
17498 md_number_to_chars (ptr, data, 4);
17499 ptr += 4;
17500 n = 4;
17501 data = 0;
17502 }
17503 unwind.opcode_count--;
17504 n--;
17505 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17506 }
17507
17508 /* Finish off the last word. */
17509 if (n < 4)
17510 {
17511 /* Pad with "finish" opcodes. */
17512 while (n--)
17513 data = (data << 8) | 0xb0;
17514
17515 md_number_to_chars (ptr, data, 4);
17516 }
17517
17518 if (!have_data)
17519 {
17520 /* Add an empty descriptor if there is no user-specified data. */
17521 ptr = frag_more (4);
17522 md_number_to_chars (ptr, 0, 4);
17523 }
17524
17525 return 0;
bfae80f2
RE
17526}
17527
f0927246
NC
17528
17529/* Initialize the DWARF-2 unwind information for this procedure. */
17530
17531void
17532tc_arm_frame_initial_instructions (void)
17533{
17534 cfi_add_CFA_def_cfa (REG_SP, 0);
17535}
17536#endif /* OBJ_ELF */
17537
c19d1205
ZW
17538/* Convert REGNAME to a DWARF-2 register number. */
17539
17540int
1df69f4f 17541tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17542{
1df69f4f 17543 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17544
17545 if (reg == FAIL)
17546 return -1;
17547
17548 return reg;
bfae80f2
RE
17549}
17550
f0927246 17551#ifdef TE_PE
c19d1205 17552void
f0927246 17553tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17554{
f0927246 17555 expressionS expr;
bfae80f2 17556
f0927246
NC
17557 expr.X_op = O_secrel;
17558 expr.X_add_symbol = symbol;
17559 expr.X_add_number = 0;
17560 emit_expr (&expr, size);
17561}
17562#endif
bfae80f2 17563
c19d1205 17564/* MD interface: Symbol and relocation handling. */
bfae80f2 17565
2fc8bdac
ZW
17566/* Return the address within the segment that a PC-relative fixup is
17567 relative to. For ARM, PC-relative fixups applied to instructions
17568 are generally relative to the location of the fixup plus 8 bytes.
17569 Thumb branches are offset by 4, and Thumb loads relative to PC
17570 require special handling. */
bfae80f2 17571
c19d1205 17572long
2fc8bdac 17573md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17574{
2fc8bdac
ZW
17575 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17576
17577 /* If this is pc-relative and we are going to emit a relocation
17578 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17579 will need. Otherwise we want to use the calculated base.
17580 For WinCE we skip the bias for externals as well, since this
17581 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 17582 if (fixP->fx_pcrel
2fc8bdac 17583 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17584 || (arm_force_relocation (fixP)
17585#ifdef TE_WINCE
17586 && !S_IS_EXTERNAL (fixP->fx_addsy)
17587#endif
17588 )))
2fc8bdac 17589 base = 0;
bfae80f2 17590
c19d1205 17591 switch (fixP->fx_r_type)
bfae80f2 17592 {
2fc8bdac
ZW
17593 /* PC relative addressing on the Thumb is slightly odd as the
17594 bottom two bits of the PC are forced to zero for the
17595 calculation. This happens *after* application of the
17596 pipeline offset. However, Thumb adrl already adjusts for
17597 this, so we need not do it again. */
c19d1205 17598 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17599 return base & ~3;
c19d1205
ZW
17600
17601 case BFD_RELOC_ARM_THUMB_OFFSET:
17602 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17603 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17604 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17605 return (base + 4) & ~3;
c19d1205 17606
2fc8bdac
ZW
17607 /* Thumb branches are simply offset by +4. */
17608 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17609 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17610 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17611 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17612 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17613 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17614 case BFD_RELOC_THUMB_PCREL_BLX:
17615 return base + 4;
bfae80f2 17616
2fc8bdac
ZW
17617 /* ARM mode branches are offset by +8. However, the Windows CE
17618 loader expects the relocation not to take this into account. */
17619 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17620 case BFD_RELOC_ARM_PCREL_CALL:
17621 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17622 case BFD_RELOC_ARM_PCREL_BLX:
17623 case BFD_RELOC_ARM_PLT32:
c19d1205 17624#ifdef TE_WINCE
5f4273c7 17625 /* When handling fixups immediately, because we have already
53baae48
NC
17626 discovered the value of a symbol, or the address of the frag involved
17627 we must account for the offset by +8, as the OS loader will never see the reloc.
17628 see fixup_segment() in write.c
17629 The S_IS_EXTERNAL test handles the case of global symbols.
17630 Those need the calculated base, not just the pipe compensation the linker will need. */
17631 if (fixP->fx_pcrel
17632 && fixP->fx_addsy != NULL
17633 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17634 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17635 return base + 8;
2fc8bdac 17636 return base;
c19d1205 17637#else
2fc8bdac 17638 return base + 8;
c19d1205 17639#endif
2fc8bdac
ZW
17640
17641 /* ARM mode loads relative to PC are also offset by +8. Unlike
17642 branches, the Windows CE loader *does* expect the relocation
17643 to take this into account. */
17644 case BFD_RELOC_ARM_OFFSET_IMM:
17645 case BFD_RELOC_ARM_OFFSET_IMM8:
17646 case BFD_RELOC_ARM_HWLITERAL:
17647 case BFD_RELOC_ARM_LITERAL:
17648 case BFD_RELOC_ARM_CP_OFF_IMM:
17649 return base + 8;
17650
17651
17652 /* Other PC-relative relocations are un-offset. */
17653 default:
17654 return base;
17655 }
bfae80f2
RE
17656}
17657
c19d1205
ZW
17658/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17659 Otherwise we have no need to default values of symbols. */
17660
17661symbolS *
17662md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17663{
c19d1205
ZW
17664#ifdef OBJ_ELF
17665 if (name[0] == '_' && name[1] == 'G'
17666 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17667 {
17668 if (!GOT_symbol)
17669 {
17670 if (symbol_find (name))
bd3ba5d1 17671 as_bad (_("GOT already in the symbol table"));
bfae80f2 17672
c19d1205
ZW
17673 GOT_symbol = symbol_new (name, undefined_section,
17674 (valueT) 0, & zero_address_frag);
17675 }
bfae80f2 17676
c19d1205 17677 return GOT_symbol;
bfae80f2 17678 }
c19d1205 17679#endif
bfae80f2 17680
c19d1205 17681 return 0;
bfae80f2
RE
17682}
17683
55cf6793 17684/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17685 computed as two separate immediate values, added together. We
17686 already know that this value cannot be computed by just one ARM
17687 instruction. */
17688
17689static unsigned int
17690validate_immediate_twopart (unsigned int val,
17691 unsigned int * highpart)
bfae80f2 17692{
c19d1205
ZW
17693 unsigned int a;
17694 unsigned int i;
bfae80f2 17695
c19d1205
ZW
17696 for (i = 0; i < 32; i += 2)
17697 if (((a = rotate_left (val, i)) & 0xff) != 0)
17698 {
17699 if (a & 0xff00)
17700 {
17701 if (a & ~ 0xffff)
17702 continue;
17703 * highpart = (a >> 8) | ((i + 24) << 7);
17704 }
17705 else if (a & 0xff0000)
17706 {
17707 if (a & 0xff000000)
17708 continue;
17709 * highpart = (a >> 16) | ((i + 16) << 7);
17710 }
17711 else
17712 {
17713 assert (a & 0xff000000);
17714 * highpart = (a >> 24) | ((i + 8) << 7);
17715 }
bfae80f2 17716
c19d1205
ZW
17717 return (a & 0xff) | (i << 7);
17718 }
bfae80f2 17719
c19d1205 17720 return FAIL;
bfae80f2
RE
17721}
17722
c19d1205
ZW
17723static int
17724validate_offset_imm (unsigned int val, int hwse)
17725{
17726 if ((hwse && val > 255) || val > 4095)
17727 return FAIL;
17728 return val;
17729}
bfae80f2 17730
55cf6793 17731/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17732 negative immediate constant by altering the instruction. A bit of
17733 a hack really.
17734 MOV <-> MVN
17735 AND <-> BIC
17736 ADC <-> SBC
17737 by inverting the second operand, and
17738 ADD <-> SUB
17739 CMP <-> CMN
17740 by negating the second operand. */
bfae80f2 17741
c19d1205
ZW
17742static int
17743negate_data_op (unsigned long * instruction,
17744 unsigned long value)
bfae80f2 17745{
c19d1205
ZW
17746 int op, new_inst;
17747 unsigned long negated, inverted;
bfae80f2 17748
c19d1205
ZW
17749 negated = encode_arm_immediate (-value);
17750 inverted = encode_arm_immediate (~value);
bfae80f2 17751
c19d1205
ZW
17752 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17753 switch (op)
bfae80f2 17754 {
c19d1205
ZW
17755 /* First negates. */
17756 case OPCODE_SUB: /* ADD <-> SUB */
17757 new_inst = OPCODE_ADD;
17758 value = negated;
17759 break;
bfae80f2 17760
c19d1205
ZW
17761 case OPCODE_ADD:
17762 new_inst = OPCODE_SUB;
17763 value = negated;
17764 break;
bfae80f2 17765
c19d1205
ZW
17766 case OPCODE_CMP: /* CMP <-> CMN */
17767 new_inst = OPCODE_CMN;
17768 value = negated;
17769 break;
bfae80f2 17770
c19d1205
ZW
17771 case OPCODE_CMN:
17772 new_inst = OPCODE_CMP;
17773 value = negated;
17774 break;
bfae80f2 17775
c19d1205
ZW
17776 /* Now Inverted ops. */
17777 case OPCODE_MOV: /* MOV <-> MVN */
17778 new_inst = OPCODE_MVN;
17779 value = inverted;
17780 break;
bfae80f2 17781
c19d1205
ZW
17782 case OPCODE_MVN:
17783 new_inst = OPCODE_MOV;
17784 value = inverted;
17785 break;
bfae80f2 17786
c19d1205
ZW
17787 case OPCODE_AND: /* AND <-> BIC */
17788 new_inst = OPCODE_BIC;
17789 value = inverted;
17790 break;
bfae80f2 17791
c19d1205
ZW
17792 case OPCODE_BIC:
17793 new_inst = OPCODE_AND;
17794 value = inverted;
17795 break;
bfae80f2 17796
c19d1205
ZW
17797 case OPCODE_ADC: /* ADC <-> SBC */
17798 new_inst = OPCODE_SBC;
17799 value = inverted;
17800 break;
bfae80f2 17801
c19d1205
ZW
17802 case OPCODE_SBC:
17803 new_inst = OPCODE_ADC;
17804 value = inverted;
17805 break;
bfae80f2 17806
c19d1205
ZW
17807 /* We cannot do anything. */
17808 default:
17809 return FAIL;
b99bd4ef
NC
17810 }
17811
c19d1205
ZW
17812 if (value == (unsigned) FAIL)
17813 return FAIL;
17814
17815 *instruction &= OPCODE_MASK;
17816 *instruction |= new_inst << DATA_OP_SHIFT;
17817 return value;
b99bd4ef
NC
17818}
17819
ef8d22e6
PB
17820/* Like negate_data_op, but for Thumb-2. */
17821
17822static unsigned int
16dd5e42 17823thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17824{
17825 int op, new_inst;
17826 int rd;
16dd5e42 17827 unsigned int negated, inverted;
ef8d22e6
PB
17828
17829 negated = encode_thumb32_immediate (-value);
17830 inverted = encode_thumb32_immediate (~value);
17831
17832 rd = (*instruction >> 8) & 0xf;
17833 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17834 switch (op)
17835 {
17836 /* ADD <-> SUB. Includes CMP <-> CMN. */
17837 case T2_OPCODE_SUB:
17838 new_inst = T2_OPCODE_ADD;
17839 value = negated;
17840 break;
17841
17842 case T2_OPCODE_ADD:
17843 new_inst = T2_OPCODE_SUB;
17844 value = negated;
17845 break;
17846
17847 /* ORR <-> ORN. Includes MOV <-> MVN. */
17848 case T2_OPCODE_ORR:
17849 new_inst = T2_OPCODE_ORN;
17850 value = inverted;
17851 break;
17852
17853 case T2_OPCODE_ORN:
17854 new_inst = T2_OPCODE_ORR;
17855 value = inverted;
17856 break;
17857
17858 /* AND <-> BIC. TST has no inverted equivalent. */
17859 case T2_OPCODE_AND:
17860 new_inst = T2_OPCODE_BIC;
17861 if (rd == 15)
17862 value = FAIL;
17863 else
17864 value = inverted;
17865 break;
17866
17867 case T2_OPCODE_BIC:
17868 new_inst = T2_OPCODE_AND;
17869 value = inverted;
17870 break;
17871
17872 /* ADC <-> SBC */
17873 case T2_OPCODE_ADC:
17874 new_inst = T2_OPCODE_SBC;
17875 value = inverted;
17876 break;
17877
17878 case T2_OPCODE_SBC:
17879 new_inst = T2_OPCODE_ADC;
17880 value = inverted;
17881 break;
17882
17883 /* We cannot do anything. */
17884 default:
17885 return FAIL;
17886 }
17887
16dd5e42 17888 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17889 return FAIL;
17890
17891 *instruction &= T2_OPCODE_MASK;
17892 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17893 return value;
17894}
17895
8f06b2d8
PB
17896/* Read a 32-bit thumb instruction from buf. */
17897static unsigned long
17898get_thumb32_insn (char * buf)
17899{
17900 unsigned long insn;
17901 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17902 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17903
17904 return insn;
17905}
17906
a8bc6c78
PB
17907
17908/* We usually want to set the low bit on the address of thumb function
17909 symbols. In particular .word foo - . should have the low bit set.
17910 Generic code tries to fold the difference of two symbols to
17911 a constant. Prevent this and force a relocation when the first symbols
17912 is a thumb function. */
17913int
17914arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17915{
17916 if (op == O_subtract
17917 && l->X_op == O_symbol
17918 && r->X_op == O_symbol
17919 && THUMB_IS_FUNC (l->X_add_symbol))
17920 {
17921 l->X_op = O_subtract;
17922 l->X_op_symbol = r->X_add_symbol;
17923 l->X_add_number -= r->X_add_number;
17924 return 1;
17925 }
17926 /* Process as normal. */
17927 return 0;
17928}
17929
c19d1205 17930void
55cf6793 17931md_apply_fix (fixS * fixP,
c19d1205
ZW
17932 valueT * valP,
17933 segT seg)
17934{
17935 offsetT value = * valP;
17936 offsetT newval;
17937 unsigned int newimm;
17938 unsigned long temp;
17939 int sign;
17940 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17941
c19d1205 17942 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17943
c19d1205 17944 /* Note whether this will delete the relocation. */
4962c51a 17945
c19d1205
ZW
17946 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17947 fixP->fx_done = 1;
b99bd4ef 17948
adbaf948 17949 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 17950 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
17951 for emit_reloc. */
17952 value &= 0xffffffff;
17953 value ^= 0x80000000;
5f4273c7 17954 value -= 0x80000000;
adbaf948
ZW
17955
17956 *valP = value;
c19d1205 17957 fixP->fx_addnumber = value;
b99bd4ef 17958
adbaf948
ZW
17959 /* Same treatment for fixP->fx_offset. */
17960 fixP->fx_offset &= 0xffffffff;
17961 fixP->fx_offset ^= 0x80000000;
17962 fixP->fx_offset -= 0x80000000;
17963
c19d1205 17964 switch (fixP->fx_r_type)
b99bd4ef 17965 {
c19d1205
ZW
17966 case BFD_RELOC_NONE:
17967 /* This will need to go in the object file. */
17968 fixP->fx_done = 0;
17969 break;
b99bd4ef 17970
c19d1205
ZW
17971 case BFD_RELOC_ARM_IMMEDIATE:
17972 /* We claim that this fixup has been processed here,
17973 even if in fact we generate an error because we do
17974 not have a reloc for it, so tc_gen_reloc will reject it. */
17975 fixP->fx_done = 1;
b99bd4ef 17976
c19d1205
ZW
17977 if (fixP->fx_addsy
17978 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17979 {
c19d1205
ZW
17980 as_bad_where (fixP->fx_file, fixP->fx_line,
17981 _("undefined symbol %s used as an immediate value"),
17982 S_GET_NAME (fixP->fx_addsy));
17983 break;
b99bd4ef
NC
17984 }
17985
c19d1205
ZW
17986 newimm = encode_arm_immediate (value);
17987 temp = md_chars_to_number (buf, INSN_SIZE);
17988
17989 /* If the instruction will fail, see if we can fix things up by
17990 changing the opcode. */
17991 if (newimm == (unsigned int) FAIL
17992 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17993 {
c19d1205
ZW
17994 as_bad_where (fixP->fx_file, fixP->fx_line,
17995 _("invalid constant (%lx) after fixup"),
17996 (unsigned long) value);
17997 break;
b99bd4ef 17998 }
b99bd4ef 17999
c19d1205
ZW
18000 newimm |= (temp & 0xfffff000);
18001 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18002 break;
b99bd4ef 18003
c19d1205
ZW
18004 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18005 {
18006 unsigned int highpart = 0;
18007 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18008
c19d1205
ZW
18009 newimm = encode_arm_immediate (value);
18010 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18011
c19d1205
ZW
18012 /* If the instruction will fail, see if we can fix things up by
18013 changing the opcode. */
18014 if (newimm == (unsigned int) FAIL
18015 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18016 {
18017 /* No ? OK - try using two ADD instructions to generate
18018 the value. */
18019 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18020
c19d1205
ZW
18021 /* Yes - then make sure that the second instruction is
18022 also an add. */
18023 if (newimm != (unsigned int) FAIL)
18024 newinsn = temp;
18025 /* Still No ? Try using a negated value. */
18026 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18027 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18028 /* Otherwise - give up. */
18029 else
18030 {
18031 as_bad_where (fixP->fx_file, fixP->fx_line,
18032 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18033 (long) value);
18034 break;
18035 }
b99bd4ef 18036
c19d1205
ZW
18037 /* Replace the first operand in the 2nd instruction (which
18038 is the PC) with the destination register. We have
18039 already added in the PC in the first instruction and we
18040 do not want to do it again. */
18041 newinsn &= ~ 0xf0000;
18042 newinsn |= ((newinsn & 0x0f000) << 4);
18043 }
b99bd4ef 18044
c19d1205
ZW
18045 newimm |= (temp & 0xfffff000);
18046 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18047
c19d1205
ZW
18048 highpart |= (newinsn & 0xfffff000);
18049 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18050 }
18051 break;
b99bd4ef 18052
c19d1205 18053 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18054 if (!fixP->fx_done && seg->use_rela_p)
18055 value = 0;
18056
c19d1205
ZW
18057 case BFD_RELOC_ARM_LITERAL:
18058 sign = value >= 0;
b99bd4ef 18059
c19d1205
ZW
18060 if (value < 0)
18061 value = - value;
b99bd4ef 18062
c19d1205 18063 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18064 {
c19d1205
ZW
18065 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18066 as_bad_where (fixP->fx_file, fixP->fx_line,
18067 _("invalid literal constant: pool needs to be closer"));
18068 else
18069 as_bad_where (fixP->fx_file, fixP->fx_line,
18070 _("bad immediate value for offset (%ld)"),
18071 (long) value);
18072 break;
f03698e6
RE
18073 }
18074
c19d1205
ZW
18075 newval = md_chars_to_number (buf, INSN_SIZE);
18076 newval &= 0xff7ff000;
18077 newval |= value | (sign ? INDEX_UP : 0);
18078 md_number_to_chars (buf, newval, INSN_SIZE);
18079 break;
b99bd4ef 18080
c19d1205
ZW
18081 case BFD_RELOC_ARM_OFFSET_IMM8:
18082 case BFD_RELOC_ARM_HWLITERAL:
18083 sign = value >= 0;
b99bd4ef 18084
c19d1205
ZW
18085 if (value < 0)
18086 value = - value;
b99bd4ef 18087
c19d1205 18088 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18089 {
c19d1205
ZW
18090 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18091 as_bad_where (fixP->fx_file, fixP->fx_line,
18092 _("invalid literal constant: pool needs to be closer"));
18093 else
f9d4405b 18094 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18095 (long) value);
18096 break;
b99bd4ef
NC
18097 }
18098
c19d1205
ZW
18099 newval = md_chars_to_number (buf, INSN_SIZE);
18100 newval &= 0xff7ff0f0;
18101 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18102 md_number_to_chars (buf, newval, INSN_SIZE);
18103 break;
b99bd4ef 18104
c19d1205
ZW
18105 case BFD_RELOC_ARM_T32_OFFSET_U8:
18106 if (value < 0 || value > 1020 || value % 4 != 0)
18107 as_bad_where (fixP->fx_file, fixP->fx_line,
18108 _("bad immediate value for offset (%ld)"), (long) value);
18109 value /= 4;
b99bd4ef 18110
c19d1205 18111 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18112 newval |= value;
18113 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18114 break;
b99bd4ef 18115
c19d1205
ZW
18116 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18117 /* This is a complicated relocation used for all varieties of Thumb32
18118 load/store instruction with immediate offset:
18119
18120 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18121 *4, optional writeback(W)
18122 (doubleword load/store)
18123
18124 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18125 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18126 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18127 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18128 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18129
18130 Uppercase letters indicate bits that are already encoded at
18131 this point. Lowercase letters are our problem. For the
18132 second block of instructions, the secondary opcode nybble
18133 (bits 8..11) is present, and bit 23 is zero, even if this is
18134 a PC-relative operation. */
18135 newval = md_chars_to_number (buf, THUMB_SIZE);
18136 newval <<= 16;
18137 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18138
c19d1205 18139 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18140 {
c19d1205
ZW
18141 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18142 if (value >= 0)
18143 newval |= (1 << 23);
18144 else
18145 value = -value;
18146 if (value % 4 != 0)
18147 {
18148 as_bad_where (fixP->fx_file, fixP->fx_line,
18149 _("offset not a multiple of 4"));
18150 break;
18151 }
18152 value /= 4;
216d22bc 18153 if (value > 0xff)
c19d1205
ZW
18154 {
18155 as_bad_where (fixP->fx_file, fixP->fx_line,
18156 _("offset out of range"));
18157 break;
18158 }
18159 newval &= ~0xff;
b99bd4ef 18160 }
c19d1205 18161 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18162 {
c19d1205
ZW
18163 /* PC-relative, 12-bit offset. */
18164 if (value >= 0)
18165 newval |= (1 << 23);
18166 else
18167 value = -value;
216d22bc 18168 if (value > 0xfff)
c19d1205
ZW
18169 {
18170 as_bad_where (fixP->fx_file, fixP->fx_line,
18171 _("offset out of range"));
18172 break;
18173 }
18174 newval &= ~0xfff;
b99bd4ef 18175 }
c19d1205 18176 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18177 {
c19d1205
ZW
18178 /* Writeback: 8-bit, +/- offset. */
18179 if (value >= 0)
18180 newval |= (1 << 9);
18181 else
18182 value = -value;
216d22bc 18183 if (value > 0xff)
c19d1205
ZW
18184 {
18185 as_bad_where (fixP->fx_file, fixP->fx_line,
18186 _("offset out of range"));
18187 break;
18188 }
18189 newval &= ~0xff;
b99bd4ef 18190 }
c19d1205 18191 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18192 {
c19d1205 18193 /* T-instruction: positive 8-bit offset. */
216d22bc 18194 if (value < 0 || value > 0xff)
b99bd4ef 18195 {
c19d1205
ZW
18196 as_bad_where (fixP->fx_file, fixP->fx_line,
18197 _("offset out of range"));
18198 break;
b99bd4ef 18199 }
c19d1205
ZW
18200 newval &= ~0xff;
18201 newval |= value;
b99bd4ef
NC
18202 }
18203 else
b99bd4ef 18204 {
c19d1205
ZW
18205 /* Positive 12-bit or negative 8-bit offset. */
18206 int limit;
18207 if (value >= 0)
b99bd4ef 18208 {
c19d1205
ZW
18209 newval |= (1 << 23);
18210 limit = 0xfff;
18211 }
18212 else
18213 {
18214 value = -value;
18215 limit = 0xff;
18216 }
18217 if (value > limit)
18218 {
18219 as_bad_where (fixP->fx_file, fixP->fx_line,
18220 _("offset out of range"));
18221 break;
b99bd4ef 18222 }
c19d1205 18223 newval &= ~limit;
b99bd4ef 18224 }
b99bd4ef 18225
c19d1205
ZW
18226 newval |= value;
18227 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18228 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18229 break;
404ff6b5 18230
c19d1205
ZW
18231 case BFD_RELOC_ARM_SHIFT_IMM:
18232 newval = md_chars_to_number (buf, INSN_SIZE);
18233 if (((unsigned long) value) > 32
18234 || (value == 32
18235 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18236 {
18237 as_bad_where (fixP->fx_file, fixP->fx_line,
18238 _("shift expression is too large"));
18239 break;
18240 }
404ff6b5 18241
c19d1205
ZW
18242 if (value == 0)
18243 /* Shifts of zero must be done as lsl. */
18244 newval &= ~0x60;
18245 else if (value == 32)
18246 value = 0;
18247 newval &= 0xfffff07f;
18248 newval |= (value & 0x1f) << 7;
18249 md_number_to_chars (buf, newval, INSN_SIZE);
18250 break;
404ff6b5 18251
c19d1205 18252 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18253 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18254 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18255 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18256 /* We claim that this fixup has been processed here,
18257 even if in fact we generate an error because we do
18258 not have a reloc for it, so tc_gen_reloc will reject it. */
18259 fixP->fx_done = 1;
404ff6b5 18260
c19d1205
ZW
18261 if (fixP->fx_addsy
18262 && ! S_IS_DEFINED (fixP->fx_addsy))
18263 {
18264 as_bad_where (fixP->fx_file, fixP->fx_line,
18265 _("undefined symbol %s used as an immediate value"),
18266 S_GET_NAME (fixP->fx_addsy));
18267 break;
18268 }
404ff6b5 18269
c19d1205
ZW
18270 newval = md_chars_to_number (buf, THUMB_SIZE);
18271 newval <<= 16;
18272 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18273
16805f35
PB
18274 newimm = FAIL;
18275 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18276 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18277 {
18278 newimm = encode_thumb32_immediate (value);
18279 if (newimm == (unsigned int) FAIL)
18280 newimm = thumb32_negate_data_op (&newval, value);
18281 }
16805f35
PB
18282 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18283 && newimm == (unsigned int) FAIL)
92e90b6e 18284 {
16805f35
PB
18285 /* Turn add/sum into addw/subw. */
18286 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18287 newval = (newval & 0xfeffffff) | 0x02000000;
18288
e9f89963
PB
18289 /* 12 bit immediate for addw/subw. */
18290 if (value < 0)
18291 {
18292 value = -value;
18293 newval ^= 0x00a00000;
18294 }
92e90b6e
PB
18295 if (value > 0xfff)
18296 newimm = (unsigned int) FAIL;
18297 else
18298 newimm = value;
18299 }
cc8a6dd0 18300
c19d1205 18301 if (newimm == (unsigned int)FAIL)
3631a3c8 18302 {
c19d1205
ZW
18303 as_bad_where (fixP->fx_file, fixP->fx_line,
18304 _("invalid constant (%lx) after fixup"),
18305 (unsigned long) value);
18306 break;
3631a3c8
NC
18307 }
18308
c19d1205
ZW
18309 newval |= (newimm & 0x800) << 15;
18310 newval |= (newimm & 0x700) << 4;
18311 newval |= (newimm & 0x0ff);
cc8a6dd0 18312
c19d1205
ZW
18313 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18314 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18315 break;
a737bd4d 18316
3eb17e6b 18317 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18318 if (((unsigned long) value) > 0xffff)
18319 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18320 _("invalid smc expression"));
2fc8bdac 18321 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18322 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18323 md_number_to_chars (buf, newval, INSN_SIZE);
18324 break;
a737bd4d 18325
c19d1205 18326 case BFD_RELOC_ARM_SWI:
adbaf948 18327 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18328 {
18329 if (((unsigned long) value) > 0xff)
18330 as_bad_where (fixP->fx_file, fixP->fx_line,
18331 _("invalid swi expression"));
2fc8bdac 18332 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18333 newval |= value;
18334 md_number_to_chars (buf, newval, THUMB_SIZE);
18335 }
18336 else
18337 {
18338 if (((unsigned long) value) > 0x00ffffff)
18339 as_bad_where (fixP->fx_file, fixP->fx_line,
18340 _("invalid swi expression"));
2fc8bdac 18341 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18342 newval |= value;
18343 md_number_to_chars (buf, newval, INSN_SIZE);
18344 }
18345 break;
a737bd4d 18346
c19d1205
ZW
18347 case BFD_RELOC_ARM_MULTI:
18348 if (((unsigned long) value) > 0xffff)
18349 as_bad_where (fixP->fx_file, fixP->fx_line,
18350 _("invalid expression in load/store multiple"));
18351 newval = value | md_chars_to_number (buf, INSN_SIZE);
18352 md_number_to_chars (buf, newval, INSN_SIZE);
18353 break;
a737bd4d 18354
c19d1205 18355#ifdef OBJ_ELF
39b41c9c
PB
18356 case BFD_RELOC_ARM_PCREL_CALL:
18357 newval = md_chars_to_number (buf, INSN_SIZE);
18358 if ((newval & 0xf0000000) == 0xf0000000)
18359 temp = 1;
18360 else
18361 temp = 3;
18362 goto arm_branch_common;
18363
18364 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18365 case BFD_RELOC_ARM_PLT32:
c19d1205 18366#endif
39b41c9c
PB
18367 case BFD_RELOC_ARM_PCREL_BRANCH:
18368 temp = 3;
18369 goto arm_branch_common;
a737bd4d 18370
39b41c9c
PB
18371 case BFD_RELOC_ARM_PCREL_BLX:
18372 temp = 1;
18373 arm_branch_common:
c19d1205 18374 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18375 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18376 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18377 also be be clear. */
18378 if (value & temp)
c19d1205 18379 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18380 _("misaligned branch destination"));
18381 if ((value & (offsetT)0xfe000000) != (offsetT)0
18382 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18383 as_bad_where (fixP->fx_file, fixP->fx_line,
18384 _("branch out of range"));
a737bd4d 18385
2fc8bdac 18386 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18387 {
2fc8bdac
ZW
18388 newval = md_chars_to_number (buf, INSN_SIZE);
18389 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18390 /* Set the H bit on BLX instructions. */
18391 if (temp == 1)
18392 {
18393 if (value & 2)
18394 newval |= 0x01000000;
18395 else
18396 newval &= ~0x01000000;
18397 }
2fc8bdac 18398 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18399 }
c19d1205 18400 break;
a737bd4d 18401
25fe350b
MS
18402 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18403 /* CBZ can only branch forward. */
a737bd4d 18404
738755b0
MS
18405 /* Attempts to use CBZ to branch to the next instruction
18406 (which, strictly speaking, are prohibited) will be turned into
18407 no-ops.
18408
18409 FIXME: It may be better to remove the instruction completely and
18410 perform relaxation. */
18411 if (value == -2)
2fc8bdac
ZW
18412 {
18413 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18414 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18415 md_number_to_chars (buf, newval, THUMB_SIZE);
18416 }
738755b0
MS
18417 else
18418 {
18419 if (value & ~0x7e)
18420 as_bad_where (fixP->fx_file, fixP->fx_line,
18421 _("branch out of range"));
18422
18423 if (fixP->fx_done || !seg->use_rela_p)
18424 {
18425 newval = md_chars_to_number (buf, THUMB_SIZE);
18426 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18427 md_number_to_chars (buf, newval, THUMB_SIZE);
18428 }
18429 }
c19d1205 18430 break;
a737bd4d 18431
c19d1205 18432 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18433 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18434 as_bad_where (fixP->fx_file, fixP->fx_line,
18435 _("branch out of range"));
a737bd4d 18436
2fc8bdac
ZW
18437 if (fixP->fx_done || !seg->use_rela_p)
18438 {
18439 newval = md_chars_to_number (buf, THUMB_SIZE);
18440 newval |= (value & 0x1ff) >> 1;
18441 md_number_to_chars (buf, newval, THUMB_SIZE);
18442 }
c19d1205 18443 break;
a737bd4d 18444
c19d1205 18445 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18446 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18447 as_bad_where (fixP->fx_file, fixP->fx_line,
18448 _("branch out of range"));
a737bd4d 18449
2fc8bdac
ZW
18450 if (fixP->fx_done || !seg->use_rela_p)
18451 {
18452 newval = md_chars_to_number (buf, THUMB_SIZE);
18453 newval |= (value & 0xfff) >> 1;
18454 md_number_to_chars (buf, newval, THUMB_SIZE);
18455 }
c19d1205 18456 break;
a737bd4d 18457
c19d1205 18458 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18459 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18460 as_bad_where (fixP->fx_file, fixP->fx_line,
18461 _("conditional branch out of range"));
404ff6b5 18462
2fc8bdac
ZW
18463 if (fixP->fx_done || !seg->use_rela_p)
18464 {
18465 offsetT newval2;
18466 addressT S, J1, J2, lo, hi;
404ff6b5 18467
2fc8bdac
ZW
18468 S = (value & 0x00100000) >> 20;
18469 J2 = (value & 0x00080000) >> 19;
18470 J1 = (value & 0x00040000) >> 18;
18471 hi = (value & 0x0003f000) >> 12;
18472 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18473
2fc8bdac
ZW
18474 newval = md_chars_to_number (buf, THUMB_SIZE);
18475 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18476 newval |= (S << 10) | hi;
18477 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18478 md_number_to_chars (buf, newval, THUMB_SIZE);
18479 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18480 }
c19d1205 18481 break;
6c43fab6 18482
c19d1205
ZW
18483 case BFD_RELOC_THUMB_PCREL_BLX:
18484 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18485 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18486 as_bad_where (fixP->fx_file, fixP->fx_line,
18487 _("branch out of range"));
404ff6b5 18488
2fc8bdac
ZW
18489 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18490 /* For a BLX instruction, make sure that the relocation is rounded up
18491 to a word boundary. This follows the semantics of the instruction
18492 which specifies that bit 1 of the target address will come from bit
18493 1 of the base address. */
18494 value = (value + 1) & ~ 1;
404ff6b5 18495
2fc8bdac 18496 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18497 {
2fc8bdac
ZW
18498 offsetT newval2;
18499
18500 newval = md_chars_to_number (buf, THUMB_SIZE);
18501 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18502 newval |= (value & 0x7fffff) >> 12;
18503 newval2 |= (value & 0xfff) >> 1;
18504 md_number_to_chars (buf, newval, THUMB_SIZE);
18505 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18506 }
c19d1205 18507 break;
404ff6b5 18508
c19d1205 18509 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18510 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18511 as_bad_where (fixP->fx_file, fixP->fx_line,
18512 _("branch out of range"));
6c43fab6 18513
2fc8bdac
ZW
18514 if (fixP->fx_done || !seg->use_rela_p)
18515 {
18516 offsetT newval2;
18517 addressT S, I1, I2, lo, hi;
6c43fab6 18518
2fc8bdac
ZW
18519 S = (value & 0x01000000) >> 24;
18520 I1 = (value & 0x00800000) >> 23;
18521 I2 = (value & 0x00400000) >> 22;
18522 hi = (value & 0x003ff000) >> 12;
18523 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18524
2fc8bdac
ZW
18525 I1 = !(I1 ^ S);
18526 I2 = !(I2 ^ S);
a737bd4d 18527
2fc8bdac
ZW
18528 newval = md_chars_to_number (buf, THUMB_SIZE);
18529 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18530 newval |= (S << 10) | hi;
18531 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18532 md_number_to_chars (buf, newval, THUMB_SIZE);
18533 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18534 }
18535 break;
a737bd4d 18536
2fc8bdac
ZW
18537 case BFD_RELOC_8:
18538 if (fixP->fx_done || !seg->use_rela_p)
18539 md_number_to_chars (buf, value, 1);
c19d1205 18540 break;
a737bd4d 18541
c19d1205 18542 case BFD_RELOC_16:
2fc8bdac 18543 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18544 md_number_to_chars (buf, value, 2);
c19d1205 18545 break;
a737bd4d 18546
c19d1205
ZW
18547#ifdef OBJ_ELF
18548 case BFD_RELOC_ARM_TLS_GD32:
18549 case BFD_RELOC_ARM_TLS_LE32:
18550 case BFD_RELOC_ARM_TLS_IE32:
18551 case BFD_RELOC_ARM_TLS_LDM32:
18552 case BFD_RELOC_ARM_TLS_LDO32:
18553 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18554 /* fall through */
6c43fab6 18555
c19d1205
ZW
18556 case BFD_RELOC_ARM_GOT32:
18557 case BFD_RELOC_ARM_GOTOFF:
18558 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18559 if (fixP->fx_done || !seg->use_rela_p)
18560 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18561 break;
18562#endif
6c43fab6 18563
c19d1205
ZW
18564 case BFD_RELOC_RVA:
18565 case BFD_RELOC_32:
18566 case BFD_RELOC_ARM_TARGET1:
18567 case BFD_RELOC_ARM_ROSEGREL32:
18568 case BFD_RELOC_ARM_SBREL32:
18569 case BFD_RELOC_32_PCREL:
f0927246
NC
18570#ifdef TE_PE
18571 case BFD_RELOC_32_SECREL:
18572#endif
2fc8bdac 18573 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18574#ifdef TE_WINCE
18575 /* For WinCE we only do this for pcrel fixups. */
18576 if (fixP->fx_done || fixP->fx_pcrel)
18577#endif
18578 md_number_to_chars (buf, value, 4);
c19d1205 18579 break;
6c43fab6 18580
c19d1205
ZW
18581#ifdef OBJ_ELF
18582 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18583 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18584 {
18585 newval = md_chars_to_number (buf, 4) & 0x80000000;
18586 if ((value ^ (value >> 1)) & 0x40000000)
18587 {
18588 as_bad_where (fixP->fx_file, fixP->fx_line,
18589 _("rel31 relocation overflow"));
18590 }
18591 newval |= value & 0x7fffffff;
18592 md_number_to_chars (buf, newval, 4);
18593 }
18594 break;
c19d1205 18595#endif
a737bd4d 18596
c19d1205 18597 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18598 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18599 if (value < -1023 || value > 1023 || (value & 3))
18600 as_bad_where (fixP->fx_file, fixP->fx_line,
18601 _("co-processor offset out of range"));
18602 cp_off_common:
18603 sign = value >= 0;
18604 if (value < 0)
18605 value = -value;
8f06b2d8
PB
18606 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18607 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18608 newval = md_chars_to_number (buf, INSN_SIZE);
18609 else
18610 newval = get_thumb32_insn (buf);
18611 newval &= 0xff7fff00;
c19d1205 18612 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18613 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18614 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18615 md_number_to_chars (buf, newval, INSN_SIZE);
18616 else
18617 put_thumb32_insn (buf, newval);
c19d1205 18618 break;
a737bd4d 18619
c19d1205 18620 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18621 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18622 if (value < -255 || value > 255)
18623 as_bad_where (fixP->fx_file, fixP->fx_line,
18624 _("co-processor offset out of range"));
df7849c5 18625 value *= 4;
c19d1205 18626 goto cp_off_common;
6c43fab6 18627
c19d1205
ZW
18628 case BFD_RELOC_ARM_THUMB_OFFSET:
18629 newval = md_chars_to_number (buf, THUMB_SIZE);
18630 /* Exactly what ranges, and where the offset is inserted depends
18631 on the type of instruction, we can establish this from the
18632 top 4 bits. */
18633 switch (newval >> 12)
18634 {
18635 case 4: /* PC load. */
18636 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18637 forced to zero for these loads; md_pcrel_from has already
18638 compensated for this. */
18639 if (value & 3)
18640 as_bad_where (fixP->fx_file, fixP->fx_line,
18641 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18642 (((unsigned long) fixP->fx_frag->fr_address
18643 + (unsigned long) fixP->fx_where) & ~3)
18644 + (unsigned long) value);
a737bd4d 18645
c19d1205
ZW
18646 if (value & ~0x3fc)
18647 as_bad_where (fixP->fx_file, fixP->fx_line,
18648 _("invalid offset, value too big (0x%08lX)"),
18649 (long) value);
a737bd4d 18650
c19d1205
ZW
18651 newval |= value >> 2;
18652 break;
a737bd4d 18653
c19d1205
ZW
18654 case 9: /* SP load/store. */
18655 if (value & ~0x3fc)
18656 as_bad_where (fixP->fx_file, fixP->fx_line,
18657 _("invalid offset, value too big (0x%08lX)"),
18658 (long) value);
18659 newval |= value >> 2;
18660 break;
6c43fab6 18661
c19d1205
ZW
18662 case 6: /* Word load/store. */
18663 if (value & ~0x7c)
18664 as_bad_where (fixP->fx_file, fixP->fx_line,
18665 _("invalid offset, value too big (0x%08lX)"),
18666 (long) value);
18667 newval |= value << 4; /* 6 - 2. */
18668 break;
a737bd4d 18669
c19d1205
ZW
18670 case 7: /* Byte load/store. */
18671 if (value & ~0x1f)
18672 as_bad_where (fixP->fx_file, fixP->fx_line,
18673 _("invalid offset, value too big (0x%08lX)"),
18674 (long) value);
18675 newval |= value << 6;
18676 break;
a737bd4d 18677
c19d1205
ZW
18678 case 8: /* Halfword load/store. */
18679 if (value & ~0x3e)
18680 as_bad_where (fixP->fx_file, fixP->fx_line,
18681 _("invalid offset, value too big (0x%08lX)"),
18682 (long) value);
18683 newval |= value << 5; /* 6 - 1. */
18684 break;
a737bd4d 18685
c19d1205
ZW
18686 default:
18687 as_bad_where (fixP->fx_file, fixP->fx_line,
18688 "Unable to process relocation for thumb opcode: %lx",
18689 (unsigned long) newval);
18690 break;
18691 }
18692 md_number_to_chars (buf, newval, THUMB_SIZE);
18693 break;
a737bd4d 18694
c19d1205
ZW
18695 case BFD_RELOC_ARM_THUMB_ADD:
18696 /* This is a complicated relocation, since we use it for all of
18697 the following immediate relocations:
a737bd4d 18698
c19d1205
ZW
18699 3bit ADD/SUB
18700 8bit ADD/SUB
18701 9bit ADD/SUB SP word-aligned
18702 10bit ADD PC/SP word-aligned
a737bd4d 18703
c19d1205
ZW
18704 The type of instruction being processed is encoded in the
18705 instruction field:
a737bd4d 18706
c19d1205
ZW
18707 0x8000 SUB
18708 0x00F0 Rd
18709 0x000F Rs
18710 */
18711 newval = md_chars_to_number (buf, THUMB_SIZE);
18712 {
18713 int rd = (newval >> 4) & 0xf;
18714 int rs = newval & 0xf;
18715 int subtract = !!(newval & 0x8000);
a737bd4d 18716
c19d1205
ZW
18717 /* Check for HI regs, only very restricted cases allowed:
18718 Adjusting SP, and using PC or SP to get an address. */
18719 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18720 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18721 as_bad_where (fixP->fx_file, fixP->fx_line,
18722 _("invalid Hi register with immediate"));
a737bd4d 18723
c19d1205
ZW
18724 /* If value is negative, choose the opposite instruction. */
18725 if (value < 0)
18726 {
18727 value = -value;
18728 subtract = !subtract;
18729 if (value < 0)
18730 as_bad_where (fixP->fx_file, fixP->fx_line,
18731 _("immediate value out of range"));
18732 }
a737bd4d 18733
c19d1205
ZW
18734 if (rd == REG_SP)
18735 {
18736 if (value & ~0x1fc)
18737 as_bad_where (fixP->fx_file, fixP->fx_line,
18738 _("invalid immediate for stack address calculation"));
18739 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18740 newval |= value >> 2;
18741 }
18742 else if (rs == REG_PC || rs == REG_SP)
18743 {
18744 if (subtract || value & ~0x3fc)
18745 as_bad_where (fixP->fx_file, fixP->fx_line,
18746 _("invalid immediate for address calculation (value = 0x%08lX)"),
18747 (unsigned long) value);
18748 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18749 newval |= rd << 8;
18750 newval |= value >> 2;
18751 }
18752 else if (rs == rd)
18753 {
18754 if (value & ~0xff)
18755 as_bad_where (fixP->fx_file, fixP->fx_line,
18756 _("immediate value out of range"));
18757 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18758 newval |= (rd << 8) | value;
18759 }
18760 else
18761 {
18762 if (value & ~0x7)
18763 as_bad_where (fixP->fx_file, fixP->fx_line,
18764 _("immediate value out of range"));
18765 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18766 newval |= rd | (rs << 3) | (value << 6);
18767 }
18768 }
18769 md_number_to_chars (buf, newval, THUMB_SIZE);
18770 break;
a737bd4d 18771
c19d1205
ZW
18772 case BFD_RELOC_ARM_THUMB_IMM:
18773 newval = md_chars_to_number (buf, THUMB_SIZE);
18774 if (value < 0 || value > 255)
18775 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 18776 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
18777 (long) value);
18778 newval |= value;
18779 md_number_to_chars (buf, newval, THUMB_SIZE);
18780 break;
a737bd4d 18781
c19d1205
ZW
18782 case BFD_RELOC_ARM_THUMB_SHIFT:
18783 /* 5bit shift value (0..32). LSL cannot take 32. */
18784 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18785 temp = newval & 0xf800;
18786 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18787 as_bad_where (fixP->fx_file, fixP->fx_line,
18788 _("invalid shift value: %ld"), (long) value);
18789 /* Shifts of zero must be encoded as LSL. */
18790 if (value == 0)
18791 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18792 /* Shifts of 32 are encoded as zero. */
18793 else if (value == 32)
18794 value = 0;
18795 newval |= value << 6;
18796 md_number_to_chars (buf, newval, THUMB_SIZE);
18797 break;
a737bd4d 18798
c19d1205
ZW
18799 case BFD_RELOC_VTABLE_INHERIT:
18800 case BFD_RELOC_VTABLE_ENTRY:
18801 fixP->fx_done = 0;
18802 return;
6c43fab6 18803
b6895b4f
PB
18804 case BFD_RELOC_ARM_MOVW:
18805 case BFD_RELOC_ARM_MOVT:
18806 case BFD_RELOC_ARM_THUMB_MOVW:
18807 case BFD_RELOC_ARM_THUMB_MOVT:
18808 if (fixP->fx_done || !seg->use_rela_p)
18809 {
18810 /* REL format relocations are limited to a 16-bit addend. */
18811 if (!fixP->fx_done)
18812 {
39623e12 18813 if (value < -0x8000 || value > 0x7fff)
b6895b4f 18814 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 18815 _("offset out of range"));
b6895b4f
PB
18816 }
18817 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18818 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18819 {
18820 value >>= 16;
18821 }
18822
18823 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18824 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18825 {
18826 newval = get_thumb32_insn (buf);
18827 newval &= 0xfbf08f00;
18828 newval |= (value & 0xf000) << 4;
18829 newval |= (value & 0x0800) << 15;
18830 newval |= (value & 0x0700) << 4;
18831 newval |= (value & 0x00ff);
18832 put_thumb32_insn (buf, newval);
18833 }
18834 else
18835 {
18836 newval = md_chars_to_number (buf, 4);
18837 newval &= 0xfff0f000;
18838 newval |= value & 0x0fff;
18839 newval |= (value & 0xf000) << 4;
18840 md_number_to_chars (buf, newval, 4);
18841 }
18842 }
18843 return;
18844
4962c51a
MS
18845 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18846 case BFD_RELOC_ARM_ALU_PC_G0:
18847 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18848 case BFD_RELOC_ARM_ALU_PC_G1:
18849 case BFD_RELOC_ARM_ALU_PC_G2:
18850 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18851 case BFD_RELOC_ARM_ALU_SB_G0:
18852 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18853 case BFD_RELOC_ARM_ALU_SB_G1:
18854 case BFD_RELOC_ARM_ALU_SB_G2:
18855 assert (!fixP->fx_done);
18856 if (!seg->use_rela_p)
18857 {
18858 bfd_vma insn;
18859 bfd_vma encoded_addend;
18860 bfd_vma addend_abs = abs (value);
18861
18862 /* Check that the absolute value of the addend can be
18863 expressed as an 8-bit constant plus a rotation. */
18864 encoded_addend = encode_arm_immediate (addend_abs);
18865 if (encoded_addend == (unsigned int) FAIL)
18866 as_bad_where (fixP->fx_file, fixP->fx_line,
18867 _("the offset 0x%08lX is not representable"),
495bde8e 18868 (unsigned long) addend_abs);
4962c51a
MS
18869
18870 /* Extract the instruction. */
18871 insn = md_chars_to_number (buf, INSN_SIZE);
18872
18873 /* If the addend is positive, use an ADD instruction.
18874 Otherwise use a SUB. Take care not to destroy the S bit. */
18875 insn &= 0xff1fffff;
18876 if (value < 0)
18877 insn |= 1 << 22;
18878 else
18879 insn |= 1 << 23;
18880
18881 /* Place the encoded addend into the first 12 bits of the
18882 instruction. */
18883 insn &= 0xfffff000;
18884 insn |= encoded_addend;
5f4273c7
NC
18885
18886 /* Update the instruction. */
4962c51a
MS
18887 md_number_to_chars (buf, insn, INSN_SIZE);
18888 }
18889 break;
18890
18891 case BFD_RELOC_ARM_LDR_PC_G0:
18892 case BFD_RELOC_ARM_LDR_PC_G1:
18893 case BFD_RELOC_ARM_LDR_PC_G2:
18894 case BFD_RELOC_ARM_LDR_SB_G0:
18895 case BFD_RELOC_ARM_LDR_SB_G1:
18896 case BFD_RELOC_ARM_LDR_SB_G2:
18897 assert (!fixP->fx_done);
18898 if (!seg->use_rela_p)
18899 {
18900 bfd_vma insn;
18901 bfd_vma addend_abs = abs (value);
18902
18903 /* Check that the absolute value of the addend can be
18904 encoded in 12 bits. */
18905 if (addend_abs >= 0x1000)
18906 as_bad_where (fixP->fx_file, fixP->fx_line,
18907 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 18908 (unsigned long) addend_abs);
4962c51a
MS
18909
18910 /* Extract the instruction. */
18911 insn = md_chars_to_number (buf, INSN_SIZE);
18912
18913 /* If the addend is negative, clear bit 23 of the instruction.
18914 Otherwise set it. */
18915 if (value < 0)
18916 insn &= ~(1 << 23);
18917 else
18918 insn |= 1 << 23;
18919
18920 /* Place the absolute value of the addend into the first 12 bits
18921 of the instruction. */
18922 insn &= 0xfffff000;
18923 insn |= addend_abs;
5f4273c7
NC
18924
18925 /* Update the instruction. */
4962c51a
MS
18926 md_number_to_chars (buf, insn, INSN_SIZE);
18927 }
18928 break;
18929
18930 case BFD_RELOC_ARM_LDRS_PC_G0:
18931 case BFD_RELOC_ARM_LDRS_PC_G1:
18932 case BFD_RELOC_ARM_LDRS_PC_G2:
18933 case BFD_RELOC_ARM_LDRS_SB_G0:
18934 case BFD_RELOC_ARM_LDRS_SB_G1:
18935 case BFD_RELOC_ARM_LDRS_SB_G2:
18936 assert (!fixP->fx_done);
18937 if (!seg->use_rela_p)
18938 {
18939 bfd_vma insn;
18940 bfd_vma addend_abs = abs (value);
18941
18942 /* Check that the absolute value of the addend can be
18943 encoded in 8 bits. */
18944 if (addend_abs >= 0x100)
18945 as_bad_where (fixP->fx_file, fixP->fx_line,
18946 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 18947 (unsigned long) addend_abs);
4962c51a
MS
18948
18949 /* Extract the instruction. */
18950 insn = md_chars_to_number (buf, INSN_SIZE);
18951
18952 /* If the addend is negative, clear bit 23 of the instruction.
18953 Otherwise set it. */
18954 if (value < 0)
18955 insn &= ~(1 << 23);
18956 else
18957 insn |= 1 << 23;
18958
18959 /* Place the first four bits of the absolute value of the addend
18960 into the first 4 bits of the instruction, and the remaining
18961 four into bits 8 .. 11. */
18962 insn &= 0xfffff0f0;
18963 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
18964
18965 /* Update the instruction. */
4962c51a
MS
18966 md_number_to_chars (buf, insn, INSN_SIZE);
18967 }
18968 break;
18969
18970 case BFD_RELOC_ARM_LDC_PC_G0:
18971 case BFD_RELOC_ARM_LDC_PC_G1:
18972 case BFD_RELOC_ARM_LDC_PC_G2:
18973 case BFD_RELOC_ARM_LDC_SB_G0:
18974 case BFD_RELOC_ARM_LDC_SB_G1:
18975 case BFD_RELOC_ARM_LDC_SB_G2:
18976 assert (!fixP->fx_done);
18977 if (!seg->use_rela_p)
18978 {
18979 bfd_vma insn;
18980 bfd_vma addend_abs = abs (value);
18981
18982 /* Check that the absolute value of the addend is a multiple of
18983 four and, when divided by four, fits in 8 bits. */
18984 if (addend_abs & 0x3)
18985 as_bad_where (fixP->fx_file, fixP->fx_line,
18986 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 18987 (unsigned long) addend_abs);
4962c51a
MS
18988
18989 if ((addend_abs >> 2) > 0xff)
18990 as_bad_where (fixP->fx_file, fixP->fx_line,
18991 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 18992 (unsigned long) addend_abs);
4962c51a
MS
18993
18994 /* Extract the instruction. */
18995 insn = md_chars_to_number (buf, INSN_SIZE);
18996
18997 /* If the addend is negative, clear bit 23 of the instruction.
18998 Otherwise set it. */
18999 if (value < 0)
19000 insn &= ~(1 << 23);
19001 else
19002 insn |= 1 << 23;
19003
19004 /* Place the addend (divided by four) into the first eight
19005 bits of the instruction. */
19006 insn &= 0xfffffff0;
19007 insn |= addend_abs >> 2;
5f4273c7
NC
19008
19009 /* Update the instruction. */
4962c51a
MS
19010 md_number_to_chars (buf, insn, INSN_SIZE);
19011 }
19012 break;
19013
845b51d6
PB
19014 case BFD_RELOC_ARM_V4BX:
19015 /* This will need to go in the object file. */
19016 fixP->fx_done = 0;
19017 break;
19018
c19d1205
ZW
19019 case BFD_RELOC_UNUSED:
19020 default:
19021 as_bad_where (fixP->fx_file, fixP->fx_line,
19022 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19023 }
6c43fab6
RE
19024}
19025
c19d1205
ZW
19026/* Translate internal representation of relocation info to BFD target
19027 format. */
a737bd4d 19028
c19d1205 19029arelent *
00a97672 19030tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19031{
c19d1205
ZW
19032 arelent * reloc;
19033 bfd_reloc_code_real_type code;
a737bd4d 19034
c19d1205 19035 reloc = xmalloc (sizeof (arelent));
a737bd4d 19036
c19d1205
ZW
19037 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19038 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19039 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19040
2fc8bdac 19041 if (fixp->fx_pcrel)
00a97672
RS
19042 {
19043 if (section->use_rela_p)
19044 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19045 else
19046 fixp->fx_offset = reloc->address;
19047 }
c19d1205 19048 reloc->addend = fixp->fx_offset;
a737bd4d 19049
c19d1205 19050 switch (fixp->fx_r_type)
a737bd4d 19051 {
c19d1205
ZW
19052 case BFD_RELOC_8:
19053 if (fixp->fx_pcrel)
19054 {
19055 code = BFD_RELOC_8_PCREL;
19056 break;
19057 }
a737bd4d 19058
c19d1205
ZW
19059 case BFD_RELOC_16:
19060 if (fixp->fx_pcrel)
19061 {
19062 code = BFD_RELOC_16_PCREL;
19063 break;
19064 }
6c43fab6 19065
c19d1205
ZW
19066 case BFD_RELOC_32:
19067 if (fixp->fx_pcrel)
19068 {
19069 code = BFD_RELOC_32_PCREL;
19070 break;
19071 }
a737bd4d 19072
b6895b4f
PB
19073 case BFD_RELOC_ARM_MOVW:
19074 if (fixp->fx_pcrel)
19075 {
19076 code = BFD_RELOC_ARM_MOVW_PCREL;
19077 break;
19078 }
19079
19080 case BFD_RELOC_ARM_MOVT:
19081 if (fixp->fx_pcrel)
19082 {
19083 code = BFD_RELOC_ARM_MOVT_PCREL;
19084 break;
19085 }
19086
19087 case BFD_RELOC_ARM_THUMB_MOVW:
19088 if (fixp->fx_pcrel)
19089 {
19090 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19091 break;
19092 }
19093
19094 case BFD_RELOC_ARM_THUMB_MOVT:
19095 if (fixp->fx_pcrel)
19096 {
19097 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19098 break;
19099 }
19100
c19d1205
ZW
19101 case BFD_RELOC_NONE:
19102 case BFD_RELOC_ARM_PCREL_BRANCH:
19103 case BFD_RELOC_ARM_PCREL_BLX:
19104 case BFD_RELOC_RVA:
19105 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19106 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19107 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19108 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19109 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19110 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19111 case BFD_RELOC_THUMB_PCREL_BLX:
19112 case BFD_RELOC_VTABLE_ENTRY:
19113 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19114#ifdef TE_PE
19115 case BFD_RELOC_32_SECREL:
19116#endif
c19d1205
ZW
19117 code = fixp->fx_r_type;
19118 break;
a737bd4d 19119
c19d1205
ZW
19120 case BFD_RELOC_ARM_LITERAL:
19121 case BFD_RELOC_ARM_HWLITERAL:
19122 /* If this is called then the a literal has
19123 been referenced across a section boundary. */
19124 as_bad_where (fixp->fx_file, fixp->fx_line,
19125 _("literal referenced across section boundary"));
19126 return NULL;
a737bd4d 19127
c19d1205
ZW
19128#ifdef OBJ_ELF
19129 case BFD_RELOC_ARM_GOT32:
19130 case BFD_RELOC_ARM_GOTOFF:
19131 case BFD_RELOC_ARM_PLT32:
19132 case BFD_RELOC_ARM_TARGET1:
19133 case BFD_RELOC_ARM_ROSEGREL32:
19134 case BFD_RELOC_ARM_SBREL32:
19135 case BFD_RELOC_ARM_PREL31:
19136 case BFD_RELOC_ARM_TARGET2:
19137 case BFD_RELOC_ARM_TLS_LE32:
19138 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19139 case BFD_RELOC_ARM_PCREL_CALL:
19140 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19141 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19142 case BFD_RELOC_ARM_ALU_PC_G0:
19143 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19144 case BFD_RELOC_ARM_ALU_PC_G1:
19145 case BFD_RELOC_ARM_ALU_PC_G2:
19146 case BFD_RELOC_ARM_LDR_PC_G0:
19147 case BFD_RELOC_ARM_LDR_PC_G1:
19148 case BFD_RELOC_ARM_LDR_PC_G2:
19149 case BFD_RELOC_ARM_LDRS_PC_G0:
19150 case BFD_RELOC_ARM_LDRS_PC_G1:
19151 case BFD_RELOC_ARM_LDRS_PC_G2:
19152 case BFD_RELOC_ARM_LDC_PC_G0:
19153 case BFD_RELOC_ARM_LDC_PC_G1:
19154 case BFD_RELOC_ARM_LDC_PC_G2:
19155 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19156 case BFD_RELOC_ARM_ALU_SB_G0:
19157 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19158 case BFD_RELOC_ARM_ALU_SB_G1:
19159 case BFD_RELOC_ARM_ALU_SB_G2:
19160 case BFD_RELOC_ARM_LDR_SB_G0:
19161 case BFD_RELOC_ARM_LDR_SB_G1:
19162 case BFD_RELOC_ARM_LDR_SB_G2:
19163 case BFD_RELOC_ARM_LDRS_SB_G0:
19164 case BFD_RELOC_ARM_LDRS_SB_G1:
19165 case BFD_RELOC_ARM_LDRS_SB_G2:
19166 case BFD_RELOC_ARM_LDC_SB_G0:
19167 case BFD_RELOC_ARM_LDC_SB_G1:
19168 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19169 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19170 code = fixp->fx_r_type;
19171 break;
a737bd4d 19172
c19d1205
ZW
19173 case BFD_RELOC_ARM_TLS_GD32:
19174 case BFD_RELOC_ARM_TLS_IE32:
19175 case BFD_RELOC_ARM_TLS_LDM32:
19176 /* BFD will include the symbol's address in the addend.
19177 But we don't want that, so subtract it out again here. */
19178 if (!S_IS_COMMON (fixp->fx_addsy))
19179 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19180 code = fixp->fx_r_type;
19181 break;
19182#endif
a737bd4d 19183
c19d1205
ZW
19184 case BFD_RELOC_ARM_IMMEDIATE:
19185 as_bad_where (fixp->fx_file, fixp->fx_line,
19186 _("internal relocation (type: IMMEDIATE) not fixed up"));
19187 return NULL;
a737bd4d 19188
c19d1205
ZW
19189 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19190 as_bad_where (fixp->fx_file, fixp->fx_line,
19191 _("ADRL used for a symbol not defined in the same file"));
19192 return NULL;
a737bd4d 19193
c19d1205 19194 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19195 if (section->use_rela_p)
19196 {
19197 code = fixp->fx_r_type;
19198 break;
19199 }
19200
c19d1205
ZW
19201 if (fixp->fx_addsy != NULL
19202 && !S_IS_DEFINED (fixp->fx_addsy)
19203 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19204 {
c19d1205
ZW
19205 as_bad_where (fixp->fx_file, fixp->fx_line,
19206 _("undefined local label `%s'"),
19207 S_GET_NAME (fixp->fx_addsy));
19208 return NULL;
a737bd4d
NC
19209 }
19210
c19d1205
ZW
19211 as_bad_where (fixp->fx_file, fixp->fx_line,
19212 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19213 return NULL;
a737bd4d 19214
c19d1205
ZW
19215 default:
19216 {
19217 char * type;
6c43fab6 19218
c19d1205
ZW
19219 switch (fixp->fx_r_type)
19220 {
19221 case BFD_RELOC_NONE: type = "NONE"; break;
19222 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19223 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19224 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19225 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19226 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19227 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19228 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19229 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19230 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19231 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19232 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19233 default: type = _("<unknown>"); break;
19234 }
19235 as_bad_where (fixp->fx_file, fixp->fx_line,
19236 _("cannot represent %s relocation in this object file format"),
19237 type);
19238 return NULL;
19239 }
a737bd4d 19240 }
6c43fab6 19241
c19d1205
ZW
19242#ifdef OBJ_ELF
19243 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19244 && GOT_symbol
19245 && fixp->fx_addsy == GOT_symbol)
19246 {
19247 code = BFD_RELOC_ARM_GOTPC;
19248 reloc->addend = fixp->fx_offset = reloc->address;
19249 }
19250#endif
6c43fab6 19251
c19d1205 19252 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19253
c19d1205
ZW
19254 if (reloc->howto == NULL)
19255 {
19256 as_bad_where (fixp->fx_file, fixp->fx_line,
19257 _("cannot represent %s relocation in this object file format"),
19258 bfd_get_reloc_code_name (code));
19259 return NULL;
19260 }
6c43fab6 19261
c19d1205
ZW
19262 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19263 vtable entry to be used in the relocation's section offset. */
19264 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19265 reloc->address = fixp->fx_offset;
6c43fab6 19266
c19d1205 19267 return reloc;
6c43fab6
RE
19268}
19269
c19d1205 19270/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19271
c19d1205
ZW
19272void
19273cons_fix_new_arm (fragS * frag,
19274 int where,
19275 int size,
19276 expressionS * exp)
6c43fab6 19277{
c19d1205
ZW
19278 bfd_reloc_code_real_type type;
19279 int pcrel = 0;
6c43fab6 19280
c19d1205
ZW
19281 /* Pick a reloc.
19282 FIXME: @@ Should look at CPU word size. */
19283 switch (size)
19284 {
19285 case 1:
19286 type = BFD_RELOC_8;
19287 break;
19288 case 2:
19289 type = BFD_RELOC_16;
19290 break;
19291 case 4:
19292 default:
19293 type = BFD_RELOC_32;
19294 break;
19295 case 8:
19296 type = BFD_RELOC_64;
19297 break;
19298 }
6c43fab6 19299
f0927246
NC
19300#ifdef TE_PE
19301 if (exp->X_op == O_secrel)
19302 {
19303 exp->X_op = O_symbol;
19304 type = BFD_RELOC_32_SECREL;
19305 }
19306#endif
19307
c19d1205
ZW
19308 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19309}
6c43fab6 19310
c19d1205
ZW
19311#if defined OBJ_COFF || defined OBJ_ELF
19312void
19313arm_validate_fix (fixS * fixP)
6c43fab6 19314{
c19d1205
ZW
19315 /* If the destination of the branch is a defined symbol which does not have
19316 the THUMB_FUNC attribute, then we must be calling a function which has
19317 the (interfacearm) attribute. We look for the Thumb entry point to that
19318 function and change the branch to refer to that function instead. */
19319 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19320 && fixP->fx_addsy != NULL
19321 && S_IS_DEFINED (fixP->fx_addsy)
19322 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19323 {
c19d1205 19324 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19325 }
c19d1205
ZW
19326}
19327#endif
6c43fab6 19328
c19d1205
ZW
19329int
19330arm_force_relocation (struct fix * fixp)
19331{
19332#if defined (OBJ_COFF) && defined (TE_PE)
19333 if (fixp->fx_r_type == BFD_RELOC_RVA)
19334 return 1;
19335#endif
6c43fab6 19336
c19d1205
ZW
19337 /* Resolve these relocations even if the symbol is extern or weak. */
19338 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19339 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19340 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19341 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19342 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19343 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19344 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19345 return 0;
a737bd4d 19346
4962c51a
MS
19347 /* Always leave these relocations for the linker. */
19348 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19349 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19350 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19351 return 1;
19352
f0291e4c
PB
19353 /* Always generate relocations against function symbols. */
19354 if (fixp->fx_r_type == BFD_RELOC_32
19355 && fixp->fx_addsy
19356 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19357 return 1;
19358
c19d1205 19359 return generic_force_reloc (fixp);
404ff6b5
AH
19360}
19361
0ffdc86c 19362#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19363/* Relocations against function names must be left unadjusted,
19364 so that the linker can use this information to generate interworking
19365 stubs. The MIPS version of this function
c19d1205
ZW
19366 also prevents relocations that are mips-16 specific, but I do not
19367 know why it does this.
404ff6b5 19368
c19d1205
ZW
19369 FIXME:
19370 There is one other problem that ought to be addressed here, but
19371 which currently is not: Taking the address of a label (rather
19372 than a function) and then later jumping to that address. Such
19373 addresses also ought to have their bottom bit set (assuming that
19374 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19375
c19d1205
ZW
19376bfd_boolean
19377arm_fix_adjustable (fixS * fixP)
404ff6b5 19378{
c19d1205
ZW
19379 if (fixP->fx_addsy == NULL)
19380 return 1;
404ff6b5 19381
e28387c3
PB
19382 /* Preserve relocations against symbols with function type. */
19383 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19384 return 0;
19385
c19d1205
ZW
19386 if (THUMB_IS_FUNC (fixP->fx_addsy)
19387 && fixP->fx_subsy == NULL)
19388 return 0;
a737bd4d 19389
c19d1205
ZW
19390 /* We need the symbol name for the VTABLE entries. */
19391 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19392 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19393 return 0;
404ff6b5 19394
c19d1205
ZW
19395 /* Don't allow symbols to be discarded on GOT related relocs. */
19396 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19399 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19400 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19401 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19402 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19403 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19404 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19405 return 0;
a737bd4d 19406
4962c51a
MS
19407 /* Similarly for group relocations. */
19408 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19409 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19410 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19411 return 0;
19412
c19d1205 19413 return 1;
a737bd4d 19414}
0ffdc86c
NC
19415#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19416
19417#ifdef OBJ_ELF
404ff6b5 19418
c19d1205
ZW
19419const char *
19420elf32_arm_target_format (void)
404ff6b5 19421{
c19d1205
ZW
19422#ifdef TE_SYMBIAN
19423 return (target_big_endian
19424 ? "elf32-bigarm-symbian"
19425 : "elf32-littlearm-symbian");
19426#elif defined (TE_VXWORKS)
19427 return (target_big_endian
19428 ? "elf32-bigarm-vxworks"
19429 : "elf32-littlearm-vxworks");
19430#else
19431 if (target_big_endian)
19432 return "elf32-bigarm";
19433 else
19434 return "elf32-littlearm";
19435#endif
404ff6b5
AH
19436}
19437
c19d1205
ZW
19438void
19439armelf_frob_symbol (symbolS * symp,
19440 int * puntp)
404ff6b5 19441{
c19d1205
ZW
19442 elf_frob_symbol (symp, puntp);
19443}
19444#endif
404ff6b5 19445
c19d1205 19446/* MD interface: Finalization. */
a737bd4d 19447
c19d1205
ZW
19448/* A good place to do this, although this was probably not intended
19449 for this kind of use. We need to dump the literal pool before
19450 references are made to a null symbol pointer. */
a737bd4d 19451
c19d1205
ZW
19452void
19453arm_cleanup (void)
19454{
19455 literal_pool * pool;
a737bd4d 19456
c19d1205
ZW
19457 for (pool = list_of_pools; pool; pool = pool->next)
19458 {
5f4273c7 19459 /* Put it at the end of the relevant section. */
c19d1205
ZW
19460 subseg_set (pool->section, pool->sub_section);
19461#ifdef OBJ_ELF
19462 arm_elf_change_section ();
19463#endif
19464 s_ltorg (0);
19465 }
404ff6b5
AH
19466}
19467
c19d1205
ZW
19468/* Adjust the symbol table. This marks Thumb symbols as distinct from
19469 ARM ones. */
404ff6b5 19470
c19d1205
ZW
19471void
19472arm_adjust_symtab (void)
404ff6b5 19473{
c19d1205
ZW
19474#ifdef OBJ_COFF
19475 symbolS * sym;
404ff6b5 19476
c19d1205
ZW
19477 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19478 {
19479 if (ARM_IS_THUMB (sym))
19480 {
19481 if (THUMB_IS_FUNC (sym))
19482 {
19483 /* Mark the symbol as a Thumb function. */
19484 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19485 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19486 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19487
c19d1205
ZW
19488 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19489 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19490 else
19491 as_bad (_("%s: unexpected function type: %d"),
19492 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19493 }
19494 else switch (S_GET_STORAGE_CLASS (sym))
19495 {
19496 case C_EXT:
19497 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19498 break;
19499 case C_STAT:
19500 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19501 break;
19502 case C_LABEL:
19503 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19504 break;
19505 default:
19506 /* Do nothing. */
19507 break;
19508 }
19509 }
a737bd4d 19510
c19d1205
ZW
19511 if (ARM_IS_INTERWORK (sym))
19512 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19513 }
c19d1205
ZW
19514#endif
19515#ifdef OBJ_ELF
19516 symbolS * sym;
19517 char bind;
404ff6b5 19518
c19d1205 19519 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19520 {
c19d1205
ZW
19521 if (ARM_IS_THUMB (sym))
19522 {
19523 elf_symbol_type * elf_sym;
404ff6b5 19524
c19d1205
ZW
19525 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19526 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19527
b0796911
PB
19528 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19529 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19530 {
19531 /* If it's a .thumb_func, declare it as so,
19532 otherwise tag label as .code 16. */
19533 if (THUMB_IS_FUNC (sym))
19534 elf_sym->internal_elf_sym.st_info =
19535 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19536 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19537 elf_sym->internal_elf_sym.st_info =
19538 ELF_ST_INFO (bind, STT_ARM_16BIT);
19539 }
19540 }
19541 }
19542#endif
404ff6b5
AH
19543}
19544
c19d1205 19545/* MD interface: Initialization. */
404ff6b5 19546
a737bd4d 19547static void
c19d1205 19548set_constant_flonums (void)
a737bd4d 19549{
c19d1205 19550 int i;
404ff6b5 19551
c19d1205
ZW
19552 for (i = 0; i < NUM_FLOAT_VALS; i++)
19553 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19554 abort ();
a737bd4d 19555}
404ff6b5 19556
3e9e4fcf
JB
19557/* Auto-select Thumb mode if it's the only available instruction set for the
19558 given architecture. */
19559
19560static void
19561autoselect_thumb_from_cpu_variant (void)
19562{
19563 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19564 opcode_select (16);
19565}
19566
c19d1205
ZW
19567void
19568md_begin (void)
a737bd4d 19569{
c19d1205
ZW
19570 unsigned mach;
19571 unsigned int i;
404ff6b5 19572
c19d1205
ZW
19573 if ( (arm_ops_hsh = hash_new ()) == NULL
19574 || (arm_cond_hsh = hash_new ()) == NULL
19575 || (arm_shift_hsh = hash_new ()) == NULL
19576 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19577 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19578 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19579 || (arm_reloc_hsh = hash_new ()) == NULL
19580 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19581 as_fatal (_("virtual memory exhausted"));
19582
19583 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19584 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19585 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19586 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19587 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19588 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19589 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19590 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19591 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19592 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19593 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19594 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19595 for (i = 0;
19596 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19597 i++)
19598 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19599 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19600#ifdef OBJ_ELF
19601 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19602 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19603#endif
19604
19605 set_constant_flonums ();
404ff6b5 19606
c19d1205
ZW
19607 /* Set the cpu variant based on the command-line options. We prefer
19608 -mcpu= over -march= if both are set (as for GCC); and we prefer
19609 -mfpu= over any other way of setting the floating point unit.
19610 Use of legacy options with new options are faulted. */
e74cfd16 19611 if (legacy_cpu)
404ff6b5 19612 {
e74cfd16 19613 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19614 as_bad (_("use of old and new-style options to set CPU type"));
19615
19616 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19617 }
e74cfd16 19618 else if (!mcpu_cpu_opt)
c19d1205 19619 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19620
e74cfd16 19621 if (legacy_fpu)
c19d1205 19622 {
e74cfd16 19623 if (mfpu_opt)
c19d1205 19624 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19625
19626 mfpu_opt = legacy_fpu;
19627 }
e74cfd16 19628 else if (!mfpu_opt)
03b1477f 19629 {
c19d1205 19630#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19631 /* Some environments specify a default FPU. If they don't, infer it
19632 from the processor. */
e74cfd16 19633 if (mcpu_fpu_opt)
03b1477f
RE
19634 mfpu_opt = mcpu_fpu_opt;
19635 else
19636 mfpu_opt = march_fpu_opt;
39c2da32 19637#else
e74cfd16 19638 mfpu_opt = &fpu_default;
39c2da32 19639#endif
03b1477f
RE
19640 }
19641
e74cfd16 19642 if (!mfpu_opt)
03b1477f 19643 {
493cb6ef 19644 if (mcpu_cpu_opt != NULL)
e74cfd16 19645 mfpu_opt = &fpu_default;
493cb6ef 19646 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19647 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19648 else
e74cfd16 19649 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19650 }
19651
ee065d83 19652#ifdef CPU_DEFAULT
e74cfd16 19653 if (!mcpu_cpu_opt)
ee065d83 19654 {
e74cfd16
PB
19655 mcpu_cpu_opt = &cpu_default;
19656 selected_cpu = cpu_default;
ee065d83 19657 }
e74cfd16
PB
19658#else
19659 if (mcpu_cpu_opt)
19660 selected_cpu = *mcpu_cpu_opt;
ee065d83 19661 else
e74cfd16 19662 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19663#endif
03b1477f 19664
e74cfd16 19665 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19666
3e9e4fcf
JB
19667 autoselect_thumb_from_cpu_variant ();
19668
e74cfd16 19669 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19670
f17c130b 19671#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19672 {
7cc69913
NC
19673 unsigned int flags = 0;
19674
19675#if defined OBJ_ELF
19676 flags = meabi_flags;
d507cf36
PB
19677
19678 switch (meabi_flags)
33a392fb 19679 {
d507cf36 19680 case EF_ARM_EABI_UNKNOWN:
7cc69913 19681#endif
d507cf36
PB
19682 /* Set the flags in the private structure. */
19683 if (uses_apcs_26) flags |= F_APCS26;
19684 if (support_interwork) flags |= F_INTERWORK;
19685 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19686 if (pic_code) flags |= F_PIC;
e74cfd16 19687 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19688 flags |= F_SOFT_FLOAT;
19689
d507cf36
PB
19690 switch (mfloat_abi_opt)
19691 {
19692 case ARM_FLOAT_ABI_SOFT:
19693 case ARM_FLOAT_ABI_SOFTFP:
19694 flags |= F_SOFT_FLOAT;
19695 break;
33a392fb 19696
d507cf36
PB
19697 case ARM_FLOAT_ABI_HARD:
19698 if (flags & F_SOFT_FLOAT)
19699 as_bad (_("hard-float conflicts with specified fpu"));
19700 break;
19701 }
03b1477f 19702
e74cfd16
PB
19703 /* Using pure-endian doubles (even if soft-float). */
19704 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19705 flags |= F_VFP_FLOAT;
f17c130b 19706
fde78edd 19707#if defined OBJ_ELF
e74cfd16 19708 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19709 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19710 break;
19711
8cb51566 19712 case EF_ARM_EABI_VER4:
3a4a14e9 19713 case EF_ARM_EABI_VER5:
c19d1205 19714 /* No additional flags to set. */
d507cf36
PB
19715 break;
19716
19717 default:
19718 abort ();
19719 }
7cc69913 19720#endif
b99bd4ef
NC
19721 bfd_set_private_flags (stdoutput, flags);
19722
19723 /* We have run out flags in the COFF header to encode the
19724 status of ATPCS support, so instead we create a dummy,
c19d1205 19725 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19726 if (atpcs)
19727 {
19728 asection * sec;
19729
19730 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19731
19732 if (sec != NULL)
19733 {
19734 bfd_set_section_flags
19735 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19736 bfd_set_section_size (stdoutput, sec, 0);
19737 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19738 }
19739 }
7cc69913 19740 }
f17c130b 19741#endif
b99bd4ef
NC
19742
19743 /* Record the CPU type as well. */
2d447fca
JM
19744 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19745 mach = bfd_mach_arm_iWMMXt2;
19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19747 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19749 mach = bfd_mach_arm_XScale;
e74cfd16 19750 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19751 mach = bfd_mach_arm_ep9312;
e74cfd16 19752 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19753 mach = bfd_mach_arm_5TE;
e74cfd16 19754 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19755 {
e74cfd16 19756 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19757 mach = bfd_mach_arm_5T;
19758 else
19759 mach = bfd_mach_arm_5;
19760 }
e74cfd16 19761 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19762 {
e74cfd16 19763 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19764 mach = bfd_mach_arm_4T;
19765 else
19766 mach = bfd_mach_arm_4;
19767 }
e74cfd16 19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19769 mach = bfd_mach_arm_3M;
e74cfd16
PB
19770 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19771 mach = bfd_mach_arm_3;
19772 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19773 mach = bfd_mach_arm_2a;
19774 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19775 mach = bfd_mach_arm_2;
19776 else
19777 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19778
19779 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19780}
19781
c19d1205 19782/* Command line processing. */
b99bd4ef 19783
c19d1205
ZW
19784/* md_parse_option
19785 Invocation line includes a switch not recognized by the base assembler.
19786 See if it's a processor-specific option.
b99bd4ef 19787
c19d1205
ZW
19788 This routine is somewhat complicated by the need for backwards
19789 compatibility (since older releases of gcc can't be changed).
19790 The new options try to make the interface as compatible as
19791 possible with GCC.
b99bd4ef 19792
c19d1205 19793 New options (supported) are:
b99bd4ef 19794
c19d1205
ZW
19795 -mcpu=<cpu name> Assemble for selected processor
19796 -march=<architecture name> Assemble for selected architecture
19797 -mfpu=<fpu architecture> Assemble for selected FPU.
19798 -EB/-mbig-endian Big-endian
19799 -EL/-mlittle-endian Little-endian
19800 -k Generate PIC code
19801 -mthumb Start in Thumb mode
19802 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19803
c19d1205 19804 For now we will also provide support for:
b99bd4ef 19805
c19d1205
ZW
19806 -mapcs-32 32-bit Program counter
19807 -mapcs-26 26-bit Program counter
19808 -macps-float Floats passed in FP registers
19809 -mapcs-reentrant Reentrant code
19810 -matpcs
19811 (sometime these will probably be replaced with -mapcs=<list of options>
19812 and -matpcs=<list of options>)
b99bd4ef 19813
c19d1205
ZW
19814 The remaining options are only supported for back-wards compatibility.
19815 Cpu variants, the arm part is optional:
19816 -m[arm]1 Currently not supported.
19817 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19818 -m[arm]3 Arm 3 processor
19819 -m[arm]6[xx], Arm 6 processors
19820 -m[arm]7[xx][t][[d]m] Arm 7 processors
19821 -m[arm]8[10] Arm 8 processors
19822 -m[arm]9[20][tdmi] Arm 9 processors
19823 -mstrongarm[110[0]] StrongARM processors
19824 -mxscale XScale processors
19825 -m[arm]v[2345[t[e]]] Arm architectures
19826 -mall All (except the ARM1)
19827 FP variants:
19828 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19829 -mfpe-old (No float load/store multiples)
19830 -mvfpxd VFP Single precision
19831 -mvfp All VFP
19832 -mno-fpu Disable all floating point instructions
b99bd4ef 19833
c19d1205
ZW
19834 The following CPU names are recognized:
19835 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19836 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19837 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19838 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19839 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19840 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19841 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19842
c19d1205 19843 */
b99bd4ef 19844
c19d1205 19845const char * md_shortopts = "m:k";
b99bd4ef 19846
c19d1205
ZW
19847#ifdef ARM_BI_ENDIAN
19848#define OPTION_EB (OPTION_MD_BASE + 0)
19849#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19850#else
c19d1205
ZW
19851#if TARGET_BYTES_BIG_ENDIAN
19852#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19853#else
c19d1205
ZW
19854#define OPTION_EL (OPTION_MD_BASE + 1)
19855#endif
b99bd4ef 19856#endif
845b51d6 19857#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 19858
c19d1205 19859struct option md_longopts[] =
b99bd4ef 19860{
c19d1205
ZW
19861#ifdef OPTION_EB
19862 {"EB", no_argument, NULL, OPTION_EB},
19863#endif
19864#ifdef OPTION_EL
19865 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19866#endif
845b51d6 19867 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
19868 {NULL, no_argument, NULL, 0}
19869};
b99bd4ef 19870
c19d1205 19871size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19872
c19d1205 19873struct arm_option_table
b99bd4ef 19874{
c19d1205
ZW
19875 char *option; /* Option name to match. */
19876 char *help; /* Help information. */
19877 int *var; /* Variable to change. */
19878 int value; /* What to change it to. */
19879 char *deprecated; /* If non-null, print this message. */
19880};
b99bd4ef 19881
c19d1205
ZW
19882struct arm_option_table arm_opts[] =
19883{
19884 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19885 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19886 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19887 &support_interwork, 1, NULL},
19888 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19889 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19890 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19891 1, NULL},
19892 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19893 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19894 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19895 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19896 NULL},
b99bd4ef 19897
c19d1205
ZW
19898 /* These are recognized by the assembler, but have no affect on code. */
19899 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19900 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19901 {NULL, NULL, NULL, 0, NULL}
19902};
19903
19904struct arm_legacy_option_table
19905{
19906 char *option; /* Option name to match. */
19907 const arm_feature_set **var; /* Variable to change. */
19908 const arm_feature_set value; /* What to change it to. */
19909 char *deprecated; /* If non-null, print this message. */
19910};
b99bd4ef 19911
e74cfd16
PB
19912const struct arm_legacy_option_table arm_legacy_opts[] =
19913{
c19d1205
ZW
19914 /* DON'T add any new processors to this list -- we want the whole list
19915 to go away... Add them to the processors table instead. */
e74cfd16
PB
19916 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19917 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19918 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19919 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19920 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19921 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19922 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19923 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19924 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19925 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19926 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19927 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19928 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19929 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19930 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19931 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19932 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19933 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19934 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19935 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19936 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19937 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19938 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19939 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19940 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19941 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19942 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19943 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19944 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19945 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19946 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19947 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19948 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19949 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19950 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19951 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19952 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19953 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19954 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19955 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19956 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19957 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19958 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19959 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19960 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19961 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19962 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19963 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19964 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19965 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19966 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19967 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19968 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19969 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19970 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19971 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19972 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19973 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19974 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19975 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19976 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19977 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19978 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19979 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19980 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19981 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19982 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19983 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19984 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19985 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19986 N_("use -mcpu=strongarm110")},
e74cfd16 19987 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19988 N_("use -mcpu=strongarm1100")},
e74cfd16 19989 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19990 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19991 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19992 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19993 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19994
c19d1205 19995 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19996 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19997 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19998 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19999 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20000 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20001 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20002 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20003 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20004 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20005 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20006 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20007 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20008 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20009 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20010 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20011 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20012 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20013 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20014
c19d1205 20015 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20016 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20017 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20018 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20019 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20020 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20021
e74cfd16 20022 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20023};
7ed4c4c5 20024
c19d1205 20025struct arm_cpu_option_table
7ed4c4c5 20026{
c19d1205 20027 char *name;
e74cfd16 20028 const arm_feature_set value;
c19d1205
ZW
20029 /* For some CPUs we assume an FPU unless the user explicitly sets
20030 -mfpu=... */
e74cfd16 20031 const arm_feature_set default_fpu;
ee065d83
PB
20032 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20033 case. */
20034 const char *canonical_name;
c19d1205 20035};
7ed4c4c5 20036
c19d1205
ZW
20037/* This list should, at a minimum, contain all the cpu names
20038 recognized by GCC. */
e74cfd16 20039static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20040{
ee065d83
PB
20041 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20042 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20043 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20044 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20045 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20046 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20047 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20049 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20051 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20053 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20055 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20056 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20057 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20058 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20059 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20060 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20061 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20062 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20064 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20065 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20066 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20067 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20068 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20069 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20070 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20071 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20072 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20074 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20075 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20076 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20077 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20078 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20079 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20080 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20081 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20082 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20083 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20084 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20085 /* For V5 or later processors we default to using VFP; but the user
20086 should really set the FPU type explicitly. */
ee065d83
PB
20087 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20088 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20089 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20090 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20091 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20092 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20093 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20094 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20095 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20096 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20097 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20098 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20099 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20100 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20101 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20103 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20104 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20105 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20106 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20107 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20108 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20109 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20110 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20111 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20112 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20113 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20114 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20115 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20116 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20117 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20118 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20119 | FPU_NEON_EXT_V1),
15290f0a
PB
20120 NULL},
20121 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20122 | FPU_NEON_EXT_V1),
5287ad62 20123 NULL},
62b3e311
PB
20124 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20125 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20126 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20127 /* ??? XSCALE is really an architecture. */
ee065d83 20128 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20129 /* ??? iwmmxt is not a processor. */
ee065d83 20130 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20131 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20132 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20133 /* Maverick */
e74cfd16
PB
20134 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20135 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20136};
7ed4c4c5 20137
c19d1205 20138struct arm_arch_option_table
7ed4c4c5 20139{
c19d1205 20140 char *name;
e74cfd16
PB
20141 const arm_feature_set value;
20142 const arm_feature_set default_fpu;
c19d1205 20143};
7ed4c4c5 20144
c19d1205
ZW
20145/* This list should, at a minimum, contain all the architecture names
20146 recognized by GCC. */
e74cfd16 20147static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20148{
20149 {"all", ARM_ANY, FPU_ARCH_FPA},
20150 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20151 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20152 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20153 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20154 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20155 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20156 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20157 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20158 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20159 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20160 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20161 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20162 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20163 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20164 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20165 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20166 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20167 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20168 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20169 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20170 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20171 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20172 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20173 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20174 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20175 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20176 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20177 /* The official spelling of the ARMv7 profile variants is the dashed form.
20178 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20179 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20180 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20181 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20182 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20183 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20184 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20185 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20186 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20187 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20188 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20189};
7ed4c4c5 20190
c19d1205 20191/* ISA extensions in the co-processor space. */
e74cfd16 20192struct arm_option_cpu_value_table
c19d1205
ZW
20193{
20194 char *name;
e74cfd16 20195 const arm_feature_set value;
c19d1205 20196};
7ed4c4c5 20197
e74cfd16 20198static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20199{
e74cfd16
PB
20200 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20201 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20202 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20203 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20204 {NULL, ARM_ARCH_NONE}
c19d1205 20205};
7ed4c4c5 20206
c19d1205
ZW
20207/* This list should, at a minimum, contain all the fpu names
20208 recognized by GCC. */
e74cfd16 20209static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20210{
20211 {"softfpa", FPU_NONE},
20212 {"fpe", FPU_ARCH_FPE},
20213 {"fpe2", FPU_ARCH_FPE},
20214 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20215 {"fpa", FPU_ARCH_FPA},
20216 {"fpa10", FPU_ARCH_FPA},
20217 {"fpa11", FPU_ARCH_FPA},
20218 {"arm7500fe", FPU_ARCH_FPA},
20219 {"softvfp", FPU_ARCH_VFP},
20220 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20221 {"vfp", FPU_ARCH_VFP_V2},
20222 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 20223 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
20224 {"vfp10", FPU_ARCH_VFP_V2},
20225 {"vfp10-r0", FPU_ARCH_VFP_V1},
20226 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
20227 {"vfpv2", FPU_ARCH_VFP_V2},
20228 {"vfpv3", FPU_ARCH_VFP_V3},
20229 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
20230 {"arm1020t", FPU_ARCH_VFP_V1},
20231 {"arm1020e", FPU_ARCH_VFP_V2},
20232 {"arm1136jfs", FPU_ARCH_VFP_V2},
20233 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20234 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20235 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20236 {NULL, ARM_ARCH_NONE}
20237};
20238
20239struct arm_option_value_table
20240{
20241 char *name;
20242 long value;
c19d1205 20243};
7ed4c4c5 20244
e74cfd16 20245static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20246{
20247 {"hard", ARM_FLOAT_ABI_HARD},
20248 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20249 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20250 {NULL, 0}
c19d1205 20251};
7ed4c4c5 20252
c19d1205 20253#ifdef OBJ_ELF
3a4a14e9 20254/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20255static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20256{
20257 {"gnu", EF_ARM_EABI_UNKNOWN},
20258 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20259 {"5", EF_ARM_EABI_VER5},
e74cfd16 20260 {NULL, 0}
c19d1205
ZW
20261};
20262#endif
7ed4c4c5 20263
c19d1205
ZW
20264struct arm_long_option_table
20265{
20266 char * option; /* Substring to match. */
20267 char * help; /* Help information. */
20268 int (* func) (char * subopt); /* Function to decode sub-option. */
20269 char * deprecated; /* If non-null, print this message. */
20270};
7ed4c4c5
NC
20271
20272static int
e74cfd16 20273arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20274{
e74cfd16
PB
20275 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20276
20277 /* Copy the feature set, so that we can modify it. */
20278 *ext_set = **opt_p;
20279 *opt_p = ext_set;
20280
c19d1205 20281 while (str != NULL && *str != 0)
7ed4c4c5 20282 {
e74cfd16 20283 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20284 char * ext;
20285 int optlen;
7ed4c4c5 20286
c19d1205
ZW
20287 if (*str != '+')
20288 {
20289 as_bad (_("invalid architectural extension"));
20290 return 0;
20291 }
7ed4c4c5 20292
c19d1205
ZW
20293 str++;
20294 ext = strchr (str, '+');
7ed4c4c5 20295
c19d1205
ZW
20296 if (ext != NULL)
20297 optlen = ext - str;
20298 else
20299 optlen = strlen (str);
7ed4c4c5 20300
c19d1205
ZW
20301 if (optlen == 0)
20302 {
20303 as_bad (_("missing architectural extension"));
20304 return 0;
20305 }
7ed4c4c5 20306
c19d1205
ZW
20307 for (opt = arm_extensions; opt->name != NULL; opt++)
20308 if (strncmp (opt->name, str, optlen) == 0)
20309 {
e74cfd16 20310 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20311 break;
20312 }
7ed4c4c5 20313
c19d1205
ZW
20314 if (opt->name == NULL)
20315 {
5f4273c7 20316 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20317 return 0;
20318 }
7ed4c4c5 20319
c19d1205
ZW
20320 str = ext;
20321 };
7ed4c4c5 20322
c19d1205
ZW
20323 return 1;
20324}
7ed4c4c5 20325
c19d1205
ZW
20326static int
20327arm_parse_cpu (char * str)
7ed4c4c5 20328{
e74cfd16 20329 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20330 char * ext = strchr (str, '+');
20331 int optlen;
7ed4c4c5 20332
c19d1205
ZW
20333 if (ext != NULL)
20334 optlen = ext - str;
7ed4c4c5 20335 else
c19d1205 20336 optlen = strlen (str);
7ed4c4c5 20337
c19d1205 20338 if (optlen == 0)
7ed4c4c5 20339 {
c19d1205
ZW
20340 as_bad (_("missing cpu name `%s'"), str);
20341 return 0;
7ed4c4c5
NC
20342 }
20343
c19d1205
ZW
20344 for (opt = arm_cpus; opt->name != NULL; opt++)
20345 if (strncmp (opt->name, str, optlen) == 0)
20346 {
e74cfd16
PB
20347 mcpu_cpu_opt = &opt->value;
20348 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 20349 if (opt->canonical_name)
5f4273c7 20350 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20351 else
20352 {
20353 int i;
20354 for (i = 0; i < optlen; i++)
20355 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20356 selected_cpu_name[i] = 0;
20357 }
7ed4c4c5 20358
c19d1205
ZW
20359 if (ext != NULL)
20360 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20361
c19d1205
ZW
20362 return 1;
20363 }
7ed4c4c5 20364
c19d1205
ZW
20365 as_bad (_("unknown cpu `%s'"), str);
20366 return 0;
7ed4c4c5
NC
20367}
20368
c19d1205
ZW
20369static int
20370arm_parse_arch (char * str)
7ed4c4c5 20371{
e74cfd16 20372 const struct arm_arch_option_table *opt;
c19d1205
ZW
20373 char *ext = strchr (str, '+');
20374 int optlen;
7ed4c4c5 20375
c19d1205
ZW
20376 if (ext != NULL)
20377 optlen = ext - str;
7ed4c4c5 20378 else
c19d1205 20379 optlen = strlen (str);
7ed4c4c5 20380
c19d1205 20381 if (optlen == 0)
7ed4c4c5 20382 {
c19d1205
ZW
20383 as_bad (_("missing architecture name `%s'"), str);
20384 return 0;
7ed4c4c5
NC
20385 }
20386
c19d1205
ZW
20387 for (opt = arm_archs; opt->name != NULL; opt++)
20388 if (streq (opt->name, str))
20389 {
e74cfd16
PB
20390 march_cpu_opt = &opt->value;
20391 march_fpu_opt = &opt->default_fpu;
5f4273c7 20392 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 20393
c19d1205
ZW
20394 if (ext != NULL)
20395 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20396
c19d1205
ZW
20397 return 1;
20398 }
20399
20400 as_bad (_("unknown architecture `%s'\n"), str);
20401 return 0;
7ed4c4c5 20402}
eb043451 20403
c19d1205
ZW
20404static int
20405arm_parse_fpu (char * str)
20406{
e74cfd16 20407 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20408
c19d1205
ZW
20409 for (opt = arm_fpus; opt->name != NULL; opt++)
20410 if (streq (opt->name, str))
20411 {
e74cfd16 20412 mfpu_opt = &opt->value;
c19d1205
ZW
20413 return 1;
20414 }
b99bd4ef 20415
c19d1205
ZW
20416 as_bad (_("unknown floating point format `%s'\n"), str);
20417 return 0;
20418}
20419
20420static int
20421arm_parse_float_abi (char * str)
b99bd4ef 20422{
e74cfd16 20423 const struct arm_option_value_table * opt;
b99bd4ef 20424
c19d1205
ZW
20425 for (opt = arm_float_abis; opt->name != NULL; opt++)
20426 if (streq (opt->name, str))
20427 {
20428 mfloat_abi_opt = opt->value;
20429 return 1;
20430 }
cc8a6dd0 20431
c19d1205
ZW
20432 as_bad (_("unknown floating point abi `%s'\n"), str);
20433 return 0;
20434}
b99bd4ef 20435
c19d1205
ZW
20436#ifdef OBJ_ELF
20437static int
20438arm_parse_eabi (char * str)
20439{
e74cfd16 20440 const struct arm_option_value_table *opt;
cc8a6dd0 20441
c19d1205
ZW
20442 for (opt = arm_eabis; opt->name != NULL; opt++)
20443 if (streq (opt->name, str))
20444 {
20445 meabi_flags = opt->value;
20446 return 1;
20447 }
20448 as_bad (_("unknown EABI `%s'\n"), str);
20449 return 0;
20450}
20451#endif
cc8a6dd0 20452
c19d1205
ZW
20453struct arm_long_option_table arm_long_opts[] =
20454{
20455 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20456 arm_parse_cpu, NULL},
20457 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20458 arm_parse_arch, NULL},
20459 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20460 arm_parse_fpu, NULL},
20461 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20462 arm_parse_float_abi, NULL},
20463#ifdef OBJ_ELF
20464 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20465 arm_parse_eabi, NULL},
20466#endif
20467 {NULL, NULL, 0, NULL}
20468};
cc8a6dd0 20469
c19d1205
ZW
20470int
20471md_parse_option (int c, char * arg)
20472{
20473 struct arm_option_table *opt;
e74cfd16 20474 const struct arm_legacy_option_table *fopt;
c19d1205 20475 struct arm_long_option_table *lopt;
b99bd4ef 20476
c19d1205 20477 switch (c)
b99bd4ef 20478 {
c19d1205
ZW
20479#ifdef OPTION_EB
20480 case OPTION_EB:
20481 target_big_endian = 1;
20482 break;
20483#endif
cc8a6dd0 20484
c19d1205
ZW
20485#ifdef OPTION_EL
20486 case OPTION_EL:
20487 target_big_endian = 0;
20488 break;
20489#endif
b99bd4ef 20490
845b51d6
PB
20491 case OPTION_FIX_V4BX:
20492 fix_v4bx = TRUE;
20493 break;
20494
c19d1205
ZW
20495 case 'a':
20496 /* Listing option. Just ignore these, we don't support additional
20497 ones. */
20498 return 0;
b99bd4ef 20499
c19d1205
ZW
20500 default:
20501 for (opt = arm_opts; opt->option != NULL; opt++)
20502 {
20503 if (c == opt->option[0]
20504 && ((arg == NULL && opt->option[1] == 0)
20505 || streq (arg, opt->option + 1)))
20506 {
20507#if WARN_DEPRECATED
20508 /* If the option is deprecated, tell the user. */
20509 if (opt->deprecated != NULL)
20510 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20511 arg ? arg : "", _(opt->deprecated));
20512#endif
b99bd4ef 20513
c19d1205
ZW
20514 if (opt->var != NULL)
20515 *opt->var = opt->value;
cc8a6dd0 20516
c19d1205
ZW
20517 return 1;
20518 }
20519 }
b99bd4ef 20520
e74cfd16
PB
20521 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20522 {
20523 if (c == fopt->option[0]
20524 && ((arg == NULL && fopt->option[1] == 0)
20525 || streq (arg, fopt->option + 1)))
20526 {
20527#if WARN_DEPRECATED
20528 /* If the option is deprecated, tell the user. */
20529 if (fopt->deprecated != NULL)
20530 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20531 arg ? arg : "", _(fopt->deprecated));
20532#endif
20533
20534 if (fopt->var != NULL)
20535 *fopt->var = &fopt->value;
20536
20537 return 1;
20538 }
20539 }
20540
c19d1205
ZW
20541 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20542 {
20543 /* These options are expected to have an argument. */
20544 if (c == lopt->option[0]
20545 && arg != NULL
20546 && strncmp (arg, lopt->option + 1,
20547 strlen (lopt->option + 1)) == 0)
20548 {
20549#if WARN_DEPRECATED
20550 /* If the option is deprecated, tell the user. */
20551 if (lopt->deprecated != NULL)
20552 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20553 _(lopt->deprecated));
20554#endif
b99bd4ef 20555
c19d1205
ZW
20556 /* Call the sup-option parser. */
20557 return lopt->func (arg + strlen (lopt->option) - 1);
20558 }
20559 }
a737bd4d 20560
c19d1205
ZW
20561 return 0;
20562 }
a394c00f 20563
c19d1205
ZW
20564 return 1;
20565}
a394c00f 20566
c19d1205
ZW
20567void
20568md_show_usage (FILE * fp)
a394c00f 20569{
c19d1205
ZW
20570 struct arm_option_table *opt;
20571 struct arm_long_option_table *lopt;
a394c00f 20572
c19d1205 20573 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20574
c19d1205
ZW
20575 for (opt = arm_opts; opt->option != NULL; opt++)
20576 if (opt->help != NULL)
20577 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20578
c19d1205
ZW
20579 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20580 if (lopt->help != NULL)
20581 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20582
c19d1205
ZW
20583#ifdef OPTION_EB
20584 fprintf (fp, _("\
20585 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20586#endif
20587
c19d1205
ZW
20588#ifdef OPTION_EL
20589 fprintf (fp, _("\
20590 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20591#endif
845b51d6
PB
20592
20593 fprintf (fp, _("\
20594 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 20595}
ee065d83
PB
20596
20597
20598#ifdef OBJ_ELF
62b3e311
PB
20599typedef struct
20600{
20601 int val;
20602 arm_feature_set flags;
20603} cpu_arch_ver_table;
20604
20605/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20606 least features first. */
20607static const cpu_arch_ver_table cpu_arch_ver[] =
20608{
20609 {1, ARM_ARCH_V4},
20610 {2, ARM_ARCH_V4T},
20611 {3, ARM_ARCH_V5},
20612 {4, ARM_ARCH_V5TE},
20613 {5, ARM_ARCH_V5TEJ},
20614 {6, ARM_ARCH_V6},
20615 {7, ARM_ARCH_V6Z},
7e806470
PB
20616 {9, ARM_ARCH_V6K},
20617 {9, ARM_ARCH_V6M},
20618 {8, ARM_ARCH_V6T2},
62b3e311
PB
20619 {10, ARM_ARCH_V7A},
20620 {10, ARM_ARCH_V7R},
20621 {10, ARM_ARCH_V7M},
20622 {0, ARM_ARCH_NONE}
20623};
20624
ee065d83
PB
20625/* Set the public EABI object attributes. */
20626static void
20627aeabi_set_public_attributes (void)
20628{
20629 int arch;
e74cfd16 20630 arm_feature_set flags;
62b3e311
PB
20631 arm_feature_set tmp;
20632 const cpu_arch_ver_table *p;
ee065d83
PB
20633
20634 /* Choose the architecture based on the capabilities of the requested cpu
20635 (if any) and/or the instructions actually used. */
e74cfd16
PB
20636 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20637 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20638 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20639 /*Allow the user to override the reported architecture. */
20640 if (object_arch)
20641 {
20642 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20643 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20644 }
20645
62b3e311
PB
20646 tmp = flags;
20647 arch = 0;
20648 for (p = cpu_arch_ver; p->val; p++)
20649 {
20650 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20651 {
20652 arch = p->val;
20653 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20654 }
20655 }
ee065d83
PB
20656
20657 /* Tag_CPU_name. */
20658 if (selected_cpu_name[0])
20659 {
20660 char *p;
20661
20662 p = selected_cpu_name;
5f4273c7 20663 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
20664 {
20665 int i;
5f4273c7 20666
ee065d83
PB
20667 p += 4;
20668 for (i = 0; p[i]; i++)
20669 p[i] = TOUPPER (p[i]);
20670 }
104d59d1 20671 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
ee065d83
PB
20672 }
20673 /* Tag_CPU_arch. */
104d59d1 20674 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
62b3e311
PB
20675 /* Tag_CPU_arch_profile. */
20676 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
104d59d1 20677 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
62b3e311 20678 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
104d59d1 20679 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
7e806470 20680 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
104d59d1 20681 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
ee065d83 20682 /* Tag_ARM_ISA_use. */
e74cfd16 20683 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
104d59d1 20684 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
ee065d83 20685 /* Tag_THUMB_ISA_use. */
e74cfd16 20686 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
104d59d1 20687 bfd_elf_add_proc_attr_int (stdoutput, 9,
e74cfd16 20688 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20689 /* Tag_VFP_arch. */
b1cc4aeb
PB
20690 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_d32)
20691 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_d32))
20692 bfd_elf_add_proc_attr_int (stdoutput, 10, 4);
20693 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
5287ad62 20694 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
104d59d1 20695 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
5287ad62
JB
20696 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20697 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
104d59d1 20698 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
5287ad62
JB
20699 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20700 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20701 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20702 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
104d59d1 20703 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
ee065d83 20704 /* Tag_WMMX_arch. */
e74cfd16
PB
20705 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20706 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
104d59d1 20707 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
5287ad62
JB
20708 /* Tag_NEON_arch. */
20709 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20710 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
104d59d1 20711 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
ee065d83
PB
20712}
20713
104d59d1 20714/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
20715void
20716arm_md_end (void)
20717{
ee065d83
PB
20718 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20719 return;
20720
20721 aeabi_set_public_attributes ();
ee065d83 20722}
8463be01 20723#endif /* OBJ_ELF */
ee065d83
PB
20724
20725
20726/* Parse a .cpu directive. */
20727
20728static void
20729s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20730{
e74cfd16 20731 const struct arm_cpu_option_table *opt;
ee065d83
PB
20732 char *name;
20733 char saved_char;
20734
20735 name = input_line_pointer;
5f4273c7 20736 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20737 input_line_pointer++;
20738 saved_char = *input_line_pointer;
20739 *input_line_pointer = 0;
20740
20741 /* Skip the first "all" entry. */
20742 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20743 if (streq (opt->name, name))
20744 {
e74cfd16
PB
20745 mcpu_cpu_opt = &opt->value;
20746 selected_cpu = opt->value;
ee065d83 20747 if (opt->canonical_name)
5f4273c7 20748 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20749 else
20750 {
20751 int i;
20752 for (i = 0; opt->name[i]; i++)
20753 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20754 selected_cpu_name[i] = 0;
20755 }
e74cfd16 20756 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20757 *input_line_pointer = saved_char;
20758 demand_empty_rest_of_line ();
20759 return;
20760 }
20761 as_bad (_("unknown cpu `%s'"), name);
20762 *input_line_pointer = saved_char;
20763 ignore_rest_of_line ();
20764}
20765
20766
20767/* Parse a .arch directive. */
20768
20769static void
20770s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20771{
e74cfd16 20772 const struct arm_arch_option_table *opt;
ee065d83
PB
20773 char saved_char;
20774 char *name;
20775
20776 name = input_line_pointer;
5f4273c7 20777 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20778 input_line_pointer++;
20779 saved_char = *input_line_pointer;
20780 *input_line_pointer = 0;
20781
20782 /* Skip the first "all" entry. */
20783 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20784 if (streq (opt->name, name))
20785 {
e74cfd16
PB
20786 mcpu_cpu_opt = &opt->value;
20787 selected_cpu = opt->value;
5f4273c7 20788 strcpy (selected_cpu_name, opt->name);
e74cfd16 20789 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20790 *input_line_pointer = saved_char;
20791 demand_empty_rest_of_line ();
20792 return;
20793 }
20794
20795 as_bad (_("unknown architecture `%s'\n"), name);
20796 *input_line_pointer = saved_char;
20797 ignore_rest_of_line ();
20798}
20799
20800
7a1d4c38
PB
20801/* Parse a .object_arch directive. */
20802
20803static void
20804s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20805{
20806 const struct arm_arch_option_table *opt;
20807 char saved_char;
20808 char *name;
20809
20810 name = input_line_pointer;
5f4273c7 20811 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
20812 input_line_pointer++;
20813 saved_char = *input_line_pointer;
20814 *input_line_pointer = 0;
20815
20816 /* Skip the first "all" entry. */
20817 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20818 if (streq (opt->name, name))
20819 {
20820 object_arch = &opt->value;
20821 *input_line_pointer = saved_char;
20822 demand_empty_rest_of_line ();
20823 return;
20824 }
20825
20826 as_bad (_("unknown architecture `%s'\n"), name);
20827 *input_line_pointer = saved_char;
20828 ignore_rest_of_line ();
20829}
20830
20831
ee065d83
PB
20832/* Parse a .fpu directive. */
20833
20834static void
20835s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20836{
e74cfd16 20837 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20838 char saved_char;
20839 char *name;
20840
20841 name = input_line_pointer;
5f4273c7 20842 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20843 input_line_pointer++;
20844 saved_char = *input_line_pointer;
20845 *input_line_pointer = 0;
5f4273c7 20846
ee065d83
PB
20847 for (opt = arm_fpus; opt->name != NULL; opt++)
20848 if (streq (opt->name, name))
20849 {
e74cfd16
PB
20850 mfpu_opt = &opt->value;
20851 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20852 *input_line_pointer = saved_char;
20853 demand_empty_rest_of_line ();
20854 return;
20855 }
20856
20857 as_bad (_("unknown floating point format `%s'\n"), name);
20858 *input_line_pointer = saved_char;
20859 ignore_rest_of_line ();
20860}
ee065d83 20861
794ba86a
DJ
20862/* Copy symbol information. */
20863void
20864arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20865{
20866 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20867}
This page took 2.416838 seconds and 4 git commands to generate.