]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* rs6000-tdep.c (gdb_print_insn_powerpc): Get the current endianess
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
ec2655a6 3 2004, 2005, 2006, 2007
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
5287ad62 28#include <limits.h>
037e8744 29#include <stdarg.h>
c19d1205 30#define NO_RELOC 0
b99bd4ef 31#include "as.h"
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
720abc60 45#define WARN_DEPRECATED 1
03b1477f 46
7ed4c4c5
NC
47#ifdef OBJ_ELF
48/* Must be at least the size of the largest unwind opcode (currently two). */
49#define ARM_OPCODE_CHUNK_SIZE 8
50
51/* This structure holds the unwinding state. */
52
53static struct
54{
c19d1205
ZW
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
7ed4c4c5 59 /* The segment containing the function. */
c19d1205
ZW
60 segT saved_seg;
61 subsegT saved_subseg;
7ed4c4c5
NC
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
c19d1205
ZW
64 int opcode_count;
65 int opcode_alloc;
7ed4c4c5 66 /* The number of bytes pushed to the stack. */
c19d1205 67 offsetT frame_size;
7ed4c4c5
NC
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
c19d1205 71 offsetT pending_offset;
7ed4c4c5 72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
7ed4c4c5 76 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 77 unsigned fp_used:1;
7ed4c4c5 78 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 79 unsigned sp_restored:1;
7ed4c4c5
NC
80} unwind;
81
8b1ad454
NC
82/* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85static unsigned int marked_pr_dependency = 0;
86
87#endif /* OBJ_ELF */
88
4962c51a
MS
89/* Results from operand parsing worker functions. */
90
91typedef enum
92{
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96} parse_operand_result;
97
33a392fb
PB
98enum arm_float_abi
99{
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103};
104
c19d1205 105/* Types of processor to assemble for. */
b99bd4ef
NC
106#ifndef CPU_DEFAULT
107#if defined __XSCALE__
e74cfd16 108#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
109#else
110#if defined __thumb__
e74cfd16 111#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
112#endif
113#endif
114#endif
115
116#ifndef FPU_DEFAULT
c820d418
MM
117# ifdef TE_LINUX
118# define FPU_DEFAULT FPU_ARCH_FPA
119# elif defined (TE_NetBSD)
120# ifdef OBJ_ELF
121# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122# else
123 /* Legacy a.out format. */
124# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125# endif
4e7fd91e
PB
126# elif defined (TE_VXWORKS)
127# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
128# else
129 /* For backwards compatibility, default to FPA. */
130# define FPU_DEFAULT FPU_ARCH_FPA
131# endif
132#endif /* ifndef FPU_DEFAULT */
b99bd4ef 133
c19d1205 134#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 135
e74cfd16
PB
136static arm_feature_set cpu_variant;
137static arm_feature_set arm_arch_used;
138static arm_feature_set thumb_arch_used;
b99bd4ef 139
b99bd4ef 140/* Flags stored in private area of BFD structure. */
c19d1205
ZW
141static int uses_apcs_26 = FALSE;
142static int atpcs = FALSE;
b34976b6
AM
143static int support_interwork = FALSE;
144static int uses_apcs_float = FALSE;
c19d1205 145static int pic_code = FALSE;
03b1477f
RE
146
147/* Variables that we set while parsing command-line options. Once all
148 options have been read we re-process these values to set the real
149 assembly flags. */
e74cfd16
PB
150static const arm_feature_set *legacy_cpu = NULL;
151static const arm_feature_set *legacy_fpu = NULL;
152
153static const arm_feature_set *mcpu_cpu_opt = NULL;
154static const arm_feature_set *mcpu_fpu_opt = NULL;
155static const arm_feature_set *march_cpu_opt = NULL;
156static const arm_feature_set *march_fpu_opt = NULL;
157static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 158static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
159
160/* Constants for known architecture features. */
161static const arm_feature_set fpu_default = FPU_DEFAULT;
162static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
163static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
164static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
165static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
166static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
167static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
168static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
169static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171#ifdef CPU_DEFAULT
172static const arm_feature_set cpu_default = CPU_DEFAULT;
173#endif
174
175static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
176static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
177static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
178static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
179static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
180static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
181static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
182static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
183static const arm_feature_set arm_ext_v4t_5 =
184 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
185static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
186static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
187static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
188static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
189static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
190static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
191static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
192static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
194static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
198static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
e74cfd16
PB
199
200static const arm_feature_set arm_arch_any = ARM_ANY;
201static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
202static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
203static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
204
2d447fca
JM
205static const arm_feature_set arm_cext_iwmmxt2 =
206 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
207static const arm_feature_set arm_cext_iwmmxt =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
209static const arm_feature_set arm_cext_xscale =
210 ARM_FEATURE (0, ARM_CEXT_XSCALE);
211static const arm_feature_set arm_cext_maverick =
212 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
213static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
214static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
215static const arm_feature_set fpu_vfp_ext_v1xd =
216 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
217static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
218static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62
JB
219static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
220static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
221static const arm_feature_set fpu_vfp_v3_or_neon_ext =
222 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
e74cfd16 223
33a392fb 224static int mfloat_abi_opt = -1;
e74cfd16
PB
225/* Record user cpu selection for object attributes. */
226static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
227/* Must be long enough to hold any of the names in arm_cpus. */
228static char selected_cpu_name[16];
7cc69913 229#ifdef OBJ_ELF
deeaaff8
DJ
230# ifdef EABI_DEFAULT
231static int meabi_flags = EABI_DEFAULT;
232# else
d507cf36 233static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 234# endif
e1da3f5b
PB
235
236bfd_boolean
5f4273c7 237arm_is_eabi (void)
e1da3f5b
PB
238{
239 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
240}
7cc69913 241#endif
b99bd4ef 242
b99bd4ef 243#ifdef OBJ_ELF
c19d1205 244/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
245symbolS * GOT_symbol;
246#endif
247
b99bd4ef
NC
248/* 0: assemble for ARM,
249 1: assemble for Thumb,
250 2: assemble for Thumb even though target CPU does not support thumb
251 instructions. */
252static int thumb_mode = 0;
253
c19d1205
ZW
254/* If unified_syntax is true, we are processing the new unified
255 ARM/Thumb syntax. Important differences from the old ARM mode:
256
257 - Immediate operands do not require a # prefix.
258 - Conditional affixes always appear at the end of the
259 instruction. (For backward compatibility, those instructions
260 that formerly had them in the middle, continue to accept them
261 there.)
262 - The IT instruction may appear, and if it does is validated
263 against subsequent conditional affixes. It does not generate
264 machine code.
265
266 Important differences from the old Thumb mode:
267
268 - Immediate operands do not require a # prefix.
269 - Most of the V6T2 instructions are only available in unified mode.
270 - The .N and .W suffixes are recognized and honored (it is an error
271 if they cannot be honored).
272 - All instructions set the flags if and only if they have an 's' affix.
273 - Conditional affixes may be used. They are validated against
274 preceding IT instructions. Unlike ARM mode, you cannot use a
275 conditional affix except in the scope of an IT instruction. */
276
277static bfd_boolean unified_syntax = FALSE;
b99bd4ef 278
5287ad62
JB
279enum neon_el_type
280{
dcbf9037 281 NT_invtype,
5287ad62
JB
282 NT_untyped,
283 NT_integer,
284 NT_float,
285 NT_poly,
286 NT_signed,
dcbf9037 287 NT_unsigned
5287ad62
JB
288};
289
290struct neon_type_el
291{
292 enum neon_el_type type;
293 unsigned size;
294};
295
296#define NEON_MAX_TYPE_ELS 4
297
298struct neon_type
299{
300 struct neon_type_el el[NEON_MAX_TYPE_ELS];
301 unsigned elems;
302};
303
b99bd4ef
NC
304struct arm_it
305{
c19d1205 306 const char * error;
b99bd4ef 307 unsigned long instruction;
c19d1205
ZW
308 int size;
309 int size_req;
310 int cond;
037e8744
JB
311 /* "uncond_value" is set to the value in place of the conditional field in
312 unconditional versions of the instruction, or -1 if nothing is
313 appropriate. */
314 int uncond_value;
5287ad62 315 struct neon_type vectype;
0110f2b8
PB
316 /* Set to the opcode if the instruction needs relaxation.
317 Zero if the instruction is not relaxed. */
318 unsigned long relax;
b99bd4ef
NC
319 struct
320 {
321 bfd_reloc_code_real_type type;
c19d1205
ZW
322 expressionS exp;
323 int pc_rel;
b99bd4ef 324 } reloc;
b99bd4ef 325
c19d1205
ZW
326 struct
327 {
328 unsigned reg;
ca3f61f7 329 signed int imm;
dcbf9037 330 struct neon_type_el vectype;
ca3f61f7
NC
331 unsigned present : 1; /* Operand present. */
332 unsigned isreg : 1; /* Operand was a register. */
333 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
334 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
335 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 336 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
337 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
338 instructions. This allows us to disambiguate ARM <-> vector insns. */
339 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 340 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 341 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 342 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
343 unsigned hasreloc : 1; /* Operand has relocation suffix. */
344 unsigned writeback : 1; /* Operand has trailing ! */
345 unsigned preind : 1; /* Preindexed address. */
346 unsigned postind : 1; /* Postindexed address. */
347 unsigned negative : 1; /* Index register was negated. */
348 unsigned shifted : 1; /* Shift applied to operation. */
349 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 350 } operands[6];
b99bd4ef
NC
351};
352
c19d1205 353static struct arm_it inst;
b99bd4ef
NC
354
355#define NUM_FLOAT_VALS 8
356
05d2d07e 357const char * fp_const[] =
b99bd4ef
NC
358{
359 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
360};
361
c19d1205 362/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
363#define MAX_LITTLENUMS 6
364
365LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
366
367#define FAIL (-1)
368#define SUCCESS (0)
369
370#define SUFF_S 1
371#define SUFF_D 2
372#define SUFF_E 3
373#define SUFF_P 4
374
c19d1205
ZW
375#define CP_T_X 0x00008000
376#define CP_T_Y 0x00400000
b99bd4ef 377
c19d1205
ZW
378#define CONDS_BIT 0x00100000
379#define LOAD_BIT 0x00100000
b99bd4ef
NC
380
381#define DOUBLE_LOAD_FLAG 0x00000001
382
383struct asm_cond
384{
c19d1205 385 const char * template;
b99bd4ef
NC
386 unsigned long value;
387};
388
c19d1205 389#define COND_ALWAYS 0xE
b99bd4ef 390
b99bd4ef
NC
391struct asm_psr
392{
b34976b6 393 const char *template;
b99bd4ef
NC
394 unsigned long field;
395};
396
62b3e311
PB
397struct asm_barrier_opt
398{
399 const char *template;
400 unsigned long value;
401};
402
2d2255b5 403/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
404#define SPSR_BIT (1 << 22)
405
c19d1205
ZW
406/* The individual PSR flag bits. */
407#define PSR_c (1 << 16)
408#define PSR_x (1 << 17)
409#define PSR_s (1 << 18)
410#define PSR_f (1 << 19)
b99bd4ef 411
c19d1205 412struct reloc_entry
bfae80f2 413{
c19d1205
ZW
414 char *name;
415 bfd_reloc_code_real_type reloc;
bfae80f2
RE
416};
417
5287ad62 418enum vfp_reg_pos
bfae80f2 419{
5287ad62
JB
420 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
421 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
422};
423
424enum vfp_ldstm_type
425{
426 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
427};
428
dcbf9037
JB
429/* Bits for DEFINED field in neon_typed_alias. */
430#define NTA_HASTYPE 1
431#define NTA_HASINDEX 2
432
433struct neon_typed_alias
434{
435 unsigned char defined;
436 unsigned char index;
437 struct neon_type_el eltype;
438};
439
c19d1205
ZW
440/* ARM register categories. This includes coprocessor numbers and various
441 architecture extensions' registers. */
442enum arm_reg_type
bfae80f2 443{
c19d1205
ZW
444 REG_TYPE_RN,
445 REG_TYPE_CP,
446 REG_TYPE_CN,
447 REG_TYPE_FN,
448 REG_TYPE_VFS,
449 REG_TYPE_VFD,
5287ad62 450 REG_TYPE_NQ,
037e8744 451 REG_TYPE_VFSD,
5287ad62 452 REG_TYPE_NDQ,
037e8744 453 REG_TYPE_NSDQ,
c19d1205
ZW
454 REG_TYPE_VFC,
455 REG_TYPE_MVF,
456 REG_TYPE_MVD,
457 REG_TYPE_MVFX,
458 REG_TYPE_MVDX,
459 REG_TYPE_MVAX,
460 REG_TYPE_DSPSC,
461 REG_TYPE_MMXWR,
462 REG_TYPE_MMXWC,
463 REG_TYPE_MMXWCG,
464 REG_TYPE_XSCALE,
bfae80f2
RE
465};
466
dcbf9037
JB
467/* Structure for a hash table entry for a register.
468 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
469 information which states whether a vector type or index is specified (for a
470 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
471struct reg_entry
472{
dcbf9037
JB
473 const char *name;
474 unsigned char number;
475 unsigned char type;
476 unsigned char builtin;
477 struct neon_typed_alias *neon;
6c43fab6
RE
478};
479
c19d1205
ZW
480/* Diagnostics used when we don't get a register of the expected type. */
481const char *const reg_expected_msgs[] =
482{
483 N_("ARM register expected"),
484 N_("bad or missing co-processor number"),
485 N_("co-processor register expected"),
486 N_("FPA register expected"),
487 N_("VFP single precision register expected"),
5287ad62
JB
488 N_("VFP/Neon double precision register expected"),
489 N_("Neon quad precision register expected"),
037e8744 490 N_("VFP single or double precision register expected"),
5287ad62 491 N_("Neon double or quad precision register expected"),
037e8744 492 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
493 N_("VFP system register expected"),
494 N_("Maverick MVF register expected"),
495 N_("Maverick MVD register expected"),
496 N_("Maverick MVFX register expected"),
497 N_("Maverick MVDX register expected"),
498 N_("Maverick MVAX register expected"),
499 N_("Maverick DSPSC register expected"),
500 N_("iWMMXt data register expected"),
501 N_("iWMMXt control register expected"),
502 N_("iWMMXt scalar register expected"),
503 N_("XScale accumulator register expected"),
6c43fab6
RE
504};
505
c19d1205
ZW
506/* Some well known registers that we refer to directly elsewhere. */
507#define REG_SP 13
508#define REG_LR 14
509#define REG_PC 15
404ff6b5 510
b99bd4ef
NC
511/* ARM instructions take 4bytes in the object file, Thumb instructions
512 take 2: */
c19d1205 513#define INSN_SIZE 4
b99bd4ef
NC
514
515struct asm_opcode
516{
517 /* Basic string to match. */
c19d1205
ZW
518 const char *template;
519
520 /* Parameters to instruction. */
521 unsigned char operands[8];
522
523 /* Conditional tag - see opcode_lookup. */
524 unsigned int tag : 4;
b99bd4ef
NC
525
526 /* Basic instruction code. */
c19d1205 527 unsigned int avalue : 28;
b99bd4ef 528
c19d1205
ZW
529 /* Thumb-format instruction code. */
530 unsigned int tvalue;
b99bd4ef 531
90e4755a 532 /* Which architecture variant provides this instruction. */
e74cfd16
PB
533 const arm_feature_set *avariant;
534 const arm_feature_set *tvariant;
c19d1205
ZW
535
536 /* Function to call to encode instruction in ARM format. */
537 void (* aencode) (void);
b99bd4ef 538
c19d1205
ZW
539 /* Function to call to encode instruction in Thumb format. */
540 void (* tencode) (void);
b99bd4ef
NC
541};
542
a737bd4d
NC
543/* Defines for various bits that we will want to toggle. */
544#define INST_IMMEDIATE 0x02000000
545#define OFFSET_REG 0x02000000
c19d1205 546#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
547#define SHIFT_BY_REG 0x00000010
548#define PRE_INDEX 0x01000000
549#define INDEX_UP 0x00800000
550#define WRITE_BACK 0x00200000
551#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 552#define CPSI_MMOD 0x00020000
90e4755a 553
a737bd4d
NC
554#define LITERAL_MASK 0xf000f000
555#define OPCODE_MASK 0xfe1fffff
556#define V4_STR_BIT 0x00000020
90e4755a 557
efd81785
PB
558#define T2_SUBS_PC_LR 0xf3de8f00
559
a737bd4d 560#define DATA_OP_SHIFT 21
90e4755a 561
ef8d22e6
PB
562#define T2_OPCODE_MASK 0xfe1fffff
563#define T2_DATA_OP_SHIFT 21
564
a737bd4d
NC
565/* Codes to distinguish the arithmetic instructions. */
566#define OPCODE_AND 0
567#define OPCODE_EOR 1
568#define OPCODE_SUB 2
569#define OPCODE_RSB 3
570#define OPCODE_ADD 4
571#define OPCODE_ADC 5
572#define OPCODE_SBC 6
573#define OPCODE_RSC 7
574#define OPCODE_TST 8
575#define OPCODE_TEQ 9
576#define OPCODE_CMP 10
577#define OPCODE_CMN 11
578#define OPCODE_ORR 12
579#define OPCODE_MOV 13
580#define OPCODE_BIC 14
581#define OPCODE_MVN 15
90e4755a 582
ef8d22e6
PB
583#define T2_OPCODE_AND 0
584#define T2_OPCODE_BIC 1
585#define T2_OPCODE_ORR 2
586#define T2_OPCODE_ORN 3
587#define T2_OPCODE_EOR 4
588#define T2_OPCODE_ADD 8
589#define T2_OPCODE_ADC 10
590#define T2_OPCODE_SBC 11
591#define T2_OPCODE_SUB 13
592#define T2_OPCODE_RSB 14
593
a737bd4d
NC
594#define T_OPCODE_MUL 0x4340
595#define T_OPCODE_TST 0x4200
596#define T_OPCODE_CMN 0x42c0
597#define T_OPCODE_NEG 0x4240
598#define T_OPCODE_MVN 0x43c0
90e4755a 599
a737bd4d
NC
600#define T_OPCODE_ADD_R3 0x1800
601#define T_OPCODE_SUB_R3 0x1a00
602#define T_OPCODE_ADD_HI 0x4400
603#define T_OPCODE_ADD_ST 0xb000
604#define T_OPCODE_SUB_ST 0xb080
605#define T_OPCODE_ADD_SP 0xa800
606#define T_OPCODE_ADD_PC 0xa000
607#define T_OPCODE_ADD_I8 0x3000
608#define T_OPCODE_SUB_I8 0x3800
609#define T_OPCODE_ADD_I3 0x1c00
610#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 611
a737bd4d
NC
612#define T_OPCODE_ASR_R 0x4100
613#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
614#define T_OPCODE_LSR_R 0x40c0
615#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
616#define T_OPCODE_ASR_I 0x1000
617#define T_OPCODE_LSL_I 0x0000
618#define T_OPCODE_LSR_I 0x0800
b99bd4ef 619
a737bd4d
NC
620#define T_OPCODE_MOV_I8 0x2000
621#define T_OPCODE_CMP_I8 0x2800
622#define T_OPCODE_CMP_LR 0x4280
623#define T_OPCODE_MOV_HR 0x4600
624#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 625
a737bd4d
NC
626#define T_OPCODE_LDR_PC 0x4800
627#define T_OPCODE_LDR_SP 0x9800
628#define T_OPCODE_STR_SP 0x9000
629#define T_OPCODE_LDR_IW 0x6800
630#define T_OPCODE_STR_IW 0x6000
631#define T_OPCODE_LDR_IH 0x8800
632#define T_OPCODE_STR_IH 0x8000
633#define T_OPCODE_LDR_IB 0x7800
634#define T_OPCODE_STR_IB 0x7000
635#define T_OPCODE_LDR_RW 0x5800
636#define T_OPCODE_STR_RW 0x5000
637#define T_OPCODE_LDR_RH 0x5a00
638#define T_OPCODE_STR_RH 0x5200
639#define T_OPCODE_LDR_RB 0x5c00
640#define T_OPCODE_STR_RB 0x5400
c9b604bd 641
a737bd4d
NC
642#define T_OPCODE_PUSH 0xb400
643#define T_OPCODE_POP 0xbc00
b99bd4ef 644
2fc8bdac 645#define T_OPCODE_BRANCH 0xe000
b99bd4ef 646
a737bd4d 647#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 648#define THUMB_PP_PC_LR 0x0100
c19d1205 649#define THUMB_LOAD_BIT 0x0800
53365c0d 650#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
651
652#define BAD_ARGS _("bad arguments to instruction")
653#define BAD_PC _("r15 not allowed here")
654#define BAD_COND _("instruction cannot be conditional")
655#define BAD_OVERLAP _("registers may not be the same")
656#define BAD_HIREG _("lo register required")
657#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 658#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
659#define BAD_BRANCH _("branch must be last instruction in IT block")
660#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 661#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
662
663static struct hash_control *arm_ops_hsh;
664static struct hash_control *arm_cond_hsh;
665static struct hash_control *arm_shift_hsh;
666static struct hash_control *arm_psr_hsh;
62b3e311 667static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
668static struct hash_control *arm_reg_hsh;
669static struct hash_control *arm_reloc_hsh;
62b3e311 670static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 671
b99bd4ef
NC
672/* Stuff needed to resolve the label ambiguity
673 As:
674 ...
675 label: <insn>
676 may differ from:
677 ...
678 label:
5f4273c7 679 <insn> */
b99bd4ef
NC
680
681symbolS * last_label_seen;
b34976b6 682static int label_is_thumb_function_name = FALSE;
a737bd4d 683\f
3d0c9500
NC
684/* Literal pool structure. Held on a per-section
685 and per-sub-section basis. */
a737bd4d 686
c19d1205 687#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 688typedef struct literal_pool
b99bd4ef 689{
c19d1205
ZW
690 expressionS literals [MAX_LITERAL_POOL_SIZE];
691 unsigned int next_free_entry;
692 unsigned int id;
693 symbolS * symbol;
694 segT section;
695 subsegT sub_section;
61b5f74b 696 struct literal_pool * next;
3d0c9500 697} literal_pool;
b99bd4ef 698
3d0c9500
NC
699/* Pointer to a linked list of literal pools. */
700literal_pool * list_of_pools = NULL;
e27ec89e
PB
701
702/* State variables for IT block handling. */
703static bfd_boolean current_it_mask = 0;
704static int current_cc;
c19d1205
ZW
705\f
706/* Pure syntax. */
b99bd4ef 707
c19d1205
ZW
708/* This array holds the chars that always start a comment. If the
709 pre-processor is disabled, these aren't very useful. */
710const char comment_chars[] = "@";
3d0c9500 711
c19d1205
ZW
712/* This array holds the chars that only start a comment at the beginning of
713 a line. If the line seems to have the form '# 123 filename'
714 .line and .file directives will appear in the pre-processed output. */
715/* Note that input_file.c hand checks for '#' at the beginning of the
716 first line of the input file. This is because the compiler outputs
717 #NO_APP at the beginning of its output. */
718/* Also note that comments like this one will always work. */
719const char line_comment_chars[] = "#";
3d0c9500 720
c19d1205 721const char line_separator_chars[] = ";";
b99bd4ef 722
c19d1205
ZW
723/* Chars that can be used to separate mant
724 from exp in floating point numbers. */
725const char EXP_CHARS[] = "eE";
3d0c9500 726
c19d1205
ZW
727/* Chars that mean this number is a floating point constant. */
728/* As in 0f12.456 */
729/* or 0d1.2345e12 */
b99bd4ef 730
c19d1205 731const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 732
c19d1205
ZW
733/* Prefix characters that indicate the start of an immediate
734 value. */
735#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 736
c19d1205
ZW
737/* Separator character handling. */
738
739#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
740
741static inline int
742skip_past_char (char ** str, char c)
743{
744 if (**str == c)
745 {
746 (*str)++;
747 return SUCCESS;
3d0c9500 748 }
c19d1205
ZW
749 else
750 return FAIL;
751}
752#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 753
c19d1205
ZW
754/* Arithmetic expressions (possibly involving symbols). */
755
756/* Return TRUE if anything in the expression is a bignum. */
757
758static int
759walk_no_bignums (symbolS * sp)
760{
761 if (symbol_get_value_expression (sp)->X_op == O_big)
762 return 1;
763
764 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 765 {
c19d1205
ZW
766 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
767 || (symbol_get_value_expression (sp)->X_op_symbol
768 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
769 }
770
c19d1205 771 return 0;
3d0c9500
NC
772}
773
c19d1205
ZW
774static int in_my_get_expression = 0;
775
776/* Third argument to my_get_expression. */
777#define GE_NO_PREFIX 0
778#define GE_IMM_PREFIX 1
779#define GE_OPT_PREFIX 2
5287ad62
JB
780/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
781 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
782#define GE_OPT_PREFIX_BIG 3
a737bd4d 783
b99bd4ef 784static int
c19d1205 785my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 786{
c19d1205
ZW
787 char * save_in;
788 segT seg;
b99bd4ef 789
c19d1205
ZW
790 /* In unified syntax, all prefixes are optional. */
791 if (unified_syntax)
5287ad62
JB
792 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
793 : GE_OPT_PREFIX;
b99bd4ef 794
c19d1205 795 switch (prefix_mode)
b99bd4ef 796 {
c19d1205
ZW
797 case GE_NO_PREFIX: break;
798 case GE_IMM_PREFIX:
799 if (!is_immediate_prefix (**str))
800 {
801 inst.error = _("immediate expression requires a # prefix");
802 return FAIL;
803 }
804 (*str)++;
805 break;
806 case GE_OPT_PREFIX:
5287ad62 807 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
808 if (is_immediate_prefix (**str))
809 (*str)++;
810 break;
811 default: abort ();
812 }
b99bd4ef 813
c19d1205 814 memset (ep, 0, sizeof (expressionS));
b99bd4ef 815
c19d1205
ZW
816 save_in = input_line_pointer;
817 input_line_pointer = *str;
818 in_my_get_expression = 1;
819 seg = expression (ep);
820 in_my_get_expression = 0;
821
822 if (ep->X_op == O_illegal)
b99bd4ef 823 {
c19d1205
ZW
824 /* We found a bad expression in md_operand(). */
825 *str = input_line_pointer;
826 input_line_pointer = save_in;
827 if (inst.error == NULL)
828 inst.error = _("bad expression");
829 return 1;
830 }
b99bd4ef 831
c19d1205
ZW
832#ifdef OBJ_AOUT
833 if (seg != absolute_section
834 && seg != text_section
835 && seg != data_section
836 && seg != bss_section
837 && seg != undefined_section)
838 {
839 inst.error = _("bad segment");
840 *str = input_line_pointer;
841 input_line_pointer = save_in;
842 return 1;
b99bd4ef 843 }
c19d1205 844#endif
b99bd4ef 845
c19d1205
ZW
846 /* Get rid of any bignums now, so that we don't generate an error for which
847 we can't establish a line number later on. Big numbers are never valid
848 in instructions, which is where this routine is always called. */
5287ad62
JB
849 if (prefix_mode != GE_OPT_PREFIX_BIG
850 && (ep->X_op == O_big
851 || (ep->X_add_symbol
852 && (walk_no_bignums (ep->X_add_symbol)
853 || (ep->X_op_symbol
854 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
855 {
856 inst.error = _("invalid constant");
857 *str = input_line_pointer;
858 input_line_pointer = save_in;
859 return 1;
860 }
b99bd4ef 861
c19d1205
ZW
862 *str = input_line_pointer;
863 input_line_pointer = save_in;
864 return 0;
b99bd4ef
NC
865}
866
c19d1205
ZW
867/* Turn a string in input_line_pointer into a floating point constant
868 of type TYPE, and store the appropriate bytes in *LITP. The number
869 of LITTLENUMS emitted is stored in *SIZEP. An error message is
870 returned, or NULL on OK.
b99bd4ef 871
c19d1205
ZW
872 Note that fp constants aren't represent in the normal way on the ARM.
873 In big endian mode, things are as expected. However, in little endian
874 mode fp constants are big-endian word-wise, and little-endian byte-wise
875 within the words. For example, (double) 1.1 in big endian mode is
876 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
877 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 878
c19d1205 879 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 880
c19d1205
ZW
881char *
882md_atof (int type, char * litP, int * sizeP)
883{
884 int prec;
885 LITTLENUM_TYPE words[MAX_LITTLENUMS];
886 char *t;
887 int i;
b99bd4ef 888
c19d1205
ZW
889 switch (type)
890 {
891 case 'f':
892 case 'F':
893 case 's':
894 case 'S':
895 prec = 2;
896 break;
b99bd4ef 897
c19d1205
ZW
898 case 'd':
899 case 'D':
900 case 'r':
901 case 'R':
902 prec = 4;
903 break;
b99bd4ef 904
c19d1205
ZW
905 case 'x':
906 case 'X':
499ac353 907 prec = 5;
c19d1205 908 break;
b99bd4ef 909
c19d1205
ZW
910 case 'p':
911 case 'P':
499ac353 912 prec = 5;
c19d1205 913 break;
a737bd4d 914
c19d1205
ZW
915 default:
916 *sizeP = 0;
499ac353 917 return _("Unrecognized or unsupported floating point constant");
c19d1205 918 }
b99bd4ef 919
c19d1205
ZW
920 t = atof_ieee (input_line_pointer, type, words);
921 if (t)
922 input_line_pointer = t;
499ac353 923 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 924
c19d1205
ZW
925 if (target_big_endian)
926 {
927 for (i = 0; i < prec; i++)
928 {
499ac353
NC
929 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
930 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
931 }
932 }
933 else
934 {
e74cfd16 935 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
936 for (i = prec - 1; i >= 0; i--)
937 {
499ac353
NC
938 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
939 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
940 }
941 else
942 /* For a 4 byte float the order of elements in `words' is 1 0.
943 For an 8 byte float the order is 1 0 3 2. */
944 for (i = 0; i < prec; i += 2)
945 {
499ac353
NC
946 md_number_to_chars (litP, (valueT) words[i + 1],
947 sizeof (LITTLENUM_TYPE));
948 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
949 (valueT) words[i], sizeof (LITTLENUM_TYPE));
950 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
951 }
952 }
b99bd4ef 953
499ac353 954 return NULL;
c19d1205 955}
b99bd4ef 956
c19d1205
ZW
957/* We handle all bad expressions here, so that we can report the faulty
958 instruction in the error message. */
959void
960md_operand (expressionS * expr)
961{
962 if (in_my_get_expression)
963 expr->X_op = O_illegal;
b99bd4ef
NC
964}
965
c19d1205 966/* Immediate values. */
b99bd4ef 967
c19d1205
ZW
968/* Generic immediate-value read function for use in directives.
969 Accepts anything that 'expression' can fold to a constant.
970 *val receives the number. */
971#ifdef OBJ_ELF
972static int
973immediate_for_directive (int *val)
b99bd4ef 974{
c19d1205
ZW
975 expressionS exp;
976 exp.X_op = O_illegal;
b99bd4ef 977
c19d1205
ZW
978 if (is_immediate_prefix (*input_line_pointer))
979 {
980 input_line_pointer++;
981 expression (&exp);
982 }
b99bd4ef 983
c19d1205
ZW
984 if (exp.X_op != O_constant)
985 {
986 as_bad (_("expected #constant"));
987 ignore_rest_of_line ();
988 return FAIL;
989 }
990 *val = exp.X_add_number;
991 return SUCCESS;
b99bd4ef 992}
c19d1205 993#endif
b99bd4ef 994
c19d1205 995/* Register parsing. */
b99bd4ef 996
c19d1205
ZW
997/* Generic register parser. CCP points to what should be the
998 beginning of a register name. If it is indeed a valid register
999 name, advance CCP over it and return the reg_entry structure;
1000 otherwise return NULL. Does not issue diagnostics. */
1001
1002static struct reg_entry *
1003arm_reg_parse_multi (char **ccp)
b99bd4ef 1004{
c19d1205
ZW
1005 char *start = *ccp;
1006 char *p;
1007 struct reg_entry *reg;
b99bd4ef 1008
c19d1205
ZW
1009#ifdef REGISTER_PREFIX
1010 if (*start != REGISTER_PREFIX)
01cfc07f 1011 return NULL;
c19d1205
ZW
1012 start++;
1013#endif
1014#ifdef OPTIONAL_REGISTER_PREFIX
1015 if (*start == OPTIONAL_REGISTER_PREFIX)
1016 start++;
1017#endif
b99bd4ef 1018
c19d1205
ZW
1019 p = start;
1020 if (!ISALPHA (*p) || !is_name_beginner (*p))
1021 return NULL;
b99bd4ef 1022
c19d1205
ZW
1023 do
1024 p++;
1025 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1026
1027 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1028
1029 if (!reg)
1030 return NULL;
1031
1032 *ccp = p;
1033 return reg;
b99bd4ef
NC
1034}
1035
1036static int
dcbf9037
JB
1037arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1038 enum arm_reg_type type)
b99bd4ef 1039{
c19d1205
ZW
1040 /* Alternative syntaxes are accepted for a few register classes. */
1041 switch (type)
1042 {
1043 case REG_TYPE_MVF:
1044 case REG_TYPE_MVD:
1045 case REG_TYPE_MVFX:
1046 case REG_TYPE_MVDX:
1047 /* Generic coprocessor register names are allowed for these. */
79134647 1048 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1049 return reg->number;
1050 break;
69b97547 1051
c19d1205
ZW
1052 case REG_TYPE_CP:
1053 /* For backward compatibility, a bare number is valid here. */
1054 {
1055 unsigned long processor = strtoul (start, ccp, 10);
1056 if (*ccp != start && processor <= 15)
1057 return processor;
1058 }
6057a28f 1059
c19d1205
ZW
1060 case REG_TYPE_MMXWC:
1061 /* WC includes WCG. ??? I'm not sure this is true for all
1062 instructions that take WC registers. */
79134647 1063 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1064 return reg->number;
6057a28f 1065 break;
c19d1205 1066
6057a28f 1067 default:
c19d1205 1068 break;
6057a28f
NC
1069 }
1070
dcbf9037
JB
1071 return FAIL;
1072}
1073
1074/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1075 return value is the register number or FAIL. */
1076
1077static int
1078arm_reg_parse (char **ccp, enum arm_reg_type type)
1079{
1080 char *start = *ccp;
1081 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1082 int ret;
1083
1084 /* Do not allow a scalar (reg+index) to parse as a register. */
1085 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1086 return FAIL;
1087
1088 if (reg && reg->type == type)
1089 return reg->number;
1090
1091 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1092 return ret;
1093
c19d1205
ZW
1094 *ccp = start;
1095 return FAIL;
1096}
69b97547 1097
dcbf9037
JB
1098/* Parse a Neon type specifier. *STR should point at the leading '.'
1099 character. Does no verification at this stage that the type fits the opcode
1100 properly. E.g.,
1101
1102 .i32.i32.s16
1103 .s32.f32
1104 .u16
1105
1106 Can all be legally parsed by this function.
1107
1108 Fills in neon_type struct pointer with parsed information, and updates STR
1109 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1110 type, FAIL if not. */
1111
1112static int
1113parse_neon_type (struct neon_type *type, char **str)
1114{
1115 char *ptr = *str;
1116
1117 if (type)
1118 type->elems = 0;
1119
1120 while (type->elems < NEON_MAX_TYPE_ELS)
1121 {
1122 enum neon_el_type thistype = NT_untyped;
1123 unsigned thissize = -1u;
1124
1125 if (*ptr != '.')
1126 break;
1127
1128 ptr++;
1129
1130 /* Just a size without an explicit type. */
1131 if (ISDIGIT (*ptr))
1132 goto parsesize;
1133
1134 switch (TOLOWER (*ptr))
1135 {
1136 case 'i': thistype = NT_integer; break;
1137 case 'f': thistype = NT_float; break;
1138 case 'p': thistype = NT_poly; break;
1139 case 's': thistype = NT_signed; break;
1140 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1141 case 'd':
1142 thistype = NT_float;
1143 thissize = 64;
1144 ptr++;
1145 goto done;
dcbf9037
JB
1146 default:
1147 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1148 return FAIL;
1149 }
1150
1151 ptr++;
1152
1153 /* .f is an abbreviation for .f32. */
1154 if (thistype == NT_float && !ISDIGIT (*ptr))
1155 thissize = 32;
1156 else
1157 {
1158 parsesize:
1159 thissize = strtoul (ptr, &ptr, 10);
1160
1161 if (thissize != 8 && thissize != 16 && thissize != 32
1162 && thissize != 64)
1163 {
1164 as_bad (_("bad size %d in type specifier"), thissize);
1165 return FAIL;
1166 }
1167 }
1168
037e8744 1169 done:
dcbf9037
JB
1170 if (type)
1171 {
1172 type->el[type->elems].type = thistype;
1173 type->el[type->elems].size = thissize;
1174 type->elems++;
1175 }
1176 }
1177
1178 /* Empty/missing type is not a successful parse. */
1179 if (type->elems == 0)
1180 return FAIL;
1181
1182 *str = ptr;
1183
1184 return SUCCESS;
1185}
1186
1187/* Errors may be set multiple times during parsing or bit encoding
1188 (particularly in the Neon bits), but usually the earliest error which is set
1189 will be the most meaningful. Avoid overwriting it with later (cascading)
1190 errors by calling this function. */
1191
1192static void
1193first_error (const char *err)
1194{
1195 if (!inst.error)
1196 inst.error = err;
1197}
1198
1199/* Parse a single type, e.g. ".s32", leading period included. */
1200static int
1201parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1202{
1203 char *str = *ccp;
1204 struct neon_type optype;
1205
1206 if (*str == '.')
1207 {
1208 if (parse_neon_type (&optype, &str) == SUCCESS)
1209 {
1210 if (optype.elems == 1)
1211 *vectype = optype.el[0];
1212 else
1213 {
1214 first_error (_("only one type should be specified for operand"));
1215 return FAIL;
1216 }
1217 }
1218 else
1219 {
1220 first_error (_("vector type expected"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 return FAIL;
5f4273c7 1226
dcbf9037 1227 *ccp = str;
5f4273c7 1228
dcbf9037
JB
1229 return SUCCESS;
1230}
1231
1232/* Special meanings for indices (which have a range of 0-7), which will fit into
1233 a 4-bit integer. */
1234
1235#define NEON_ALL_LANES 15
1236#define NEON_INTERLEAVE_LANES 14
1237
1238/* Parse either a register or a scalar, with an optional type. Return the
1239 register number, and optionally fill in the actual type of the register
1240 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1241 type/index information in *TYPEINFO. */
1242
1243static int
1244parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1245 enum arm_reg_type *rtype,
1246 struct neon_typed_alias *typeinfo)
1247{
1248 char *str = *ccp;
1249 struct reg_entry *reg = arm_reg_parse_multi (&str);
1250 struct neon_typed_alias atype;
1251 struct neon_type_el parsetype;
1252
1253 atype.defined = 0;
1254 atype.index = -1;
1255 atype.eltype.type = NT_invtype;
1256 atype.eltype.size = -1;
1257
1258 /* Try alternate syntax for some types of register. Note these are mutually
1259 exclusive with the Neon syntax extensions. */
1260 if (reg == NULL)
1261 {
1262 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1263 if (altreg != FAIL)
1264 *ccp = str;
1265 if (typeinfo)
1266 *typeinfo = atype;
1267 return altreg;
1268 }
1269
037e8744
JB
1270 /* Undo polymorphism when a set of register types may be accepted. */
1271 if ((type == REG_TYPE_NDQ
1272 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1273 || (type == REG_TYPE_VFSD
1274 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1275 || (type == REG_TYPE_NSDQ
1276 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1277 || reg->type == REG_TYPE_NQ))
1278 || (type == REG_TYPE_MMXWC
1279 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1280 type = reg->type;
1281
1282 if (type != reg->type)
1283 return FAIL;
1284
1285 if (reg->neon)
1286 atype = *reg->neon;
5f4273c7 1287
dcbf9037
JB
1288 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1289 {
1290 if ((atype.defined & NTA_HASTYPE) != 0)
1291 {
1292 first_error (_("can't redefine type for operand"));
1293 return FAIL;
1294 }
1295 atype.defined |= NTA_HASTYPE;
1296 atype.eltype = parsetype;
1297 }
5f4273c7 1298
dcbf9037
JB
1299 if (skip_past_char (&str, '[') == SUCCESS)
1300 {
1301 if (type != REG_TYPE_VFD)
1302 {
1303 first_error (_("only D registers may be indexed"));
1304 return FAIL;
1305 }
5f4273c7 1306
dcbf9037
JB
1307 if ((atype.defined & NTA_HASINDEX) != 0)
1308 {
1309 first_error (_("can't change index for operand"));
1310 return FAIL;
1311 }
1312
1313 atype.defined |= NTA_HASINDEX;
1314
1315 if (skip_past_char (&str, ']') == SUCCESS)
1316 atype.index = NEON_ALL_LANES;
1317 else
1318 {
1319 expressionS exp;
1320
1321 my_get_expression (&exp, &str, GE_NO_PREFIX);
1322
1323 if (exp.X_op != O_constant)
1324 {
1325 first_error (_("constant expression required"));
1326 return FAIL;
1327 }
1328
1329 if (skip_past_char (&str, ']') == FAIL)
1330 return FAIL;
1331
1332 atype.index = exp.X_add_number;
1333 }
1334 }
5f4273c7 1335
dcbf9037
JB
1336 if (typeinfo)
1337 *typeinfo = atype;
5f4273c7 1338
dcbf9037
JB
1339 if (rtype)
1340 *rtype = type;
5f4273c7 1341
dcbf9037 1342 *ccp = str;
5f4273c7 1343
dcbf9037
JB
1344 return reg->number;
1345}
1346
1347/* Like arm_reg_parse, but allow allow the following extra features:
1348 - If RTYPE is non-zero, return the (possibly restricted) type of the
1349 register (e.g. Neon double or quad reg when either has been requested).
1350 - If this is a Neon vector type with additional type information, fill
1351 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1352 This function will fault on encountering a scalar. */
dcbf9037
JB
1353
1354static int
1355arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1356 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1357{
1358 struct neon_typed_alias atype;
1359 char *str = *ccp;
1360 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1361
1362 if (reg == FAIL)
1363 return FAIL;
1364
1365 /* Do not allow a scalar (reg+index) to parse as a register. */
1366 if ((atype.defined & NTA_HASINDEX) != 0)
1367 {
1368 first_error (_("register operand expected, but got scalar"));
1369 return FAIL;
1370 }
1371
1372 if (vectype)
1373 *vectype = atype.eltype;
1374
1375 *ccp = str;
1376
1377 return reg;
1378}
1379
1380#define NEON_SCALAR_REG(X) ((X) >> 4)
1381#define NEON_SCALAR_INDEX(X) ((X) & 15)
1382
5287ad62
JB
1383/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1384 have enough information to be able to do a good job bounds-checking. So, we
1385 just do easy checks here, and do further checks later. */
1386
1387static int
dcbf9037 1388parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1389{
dcbf9037 1390 int reg;
5287ad62 1391 char *str = *ccp;
dcbf9037 1392 struct neon_typed_alias atype;
5f4273c7 1393
dcbf9037 1394 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1395
dcbf9037 1396 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1397 return FAIL;
5f4273c7 1398
dcbf9037 1399 if (atype.index == NEON_ALL_LANES)
5287ad62 1400 {
dcbf9037 1401 first_error (_("scalar must have an index"));
5287ad62
JB
1402 return FAIL;
1403 }
dcbf9037 1404 else if (atype.index >= 64 / elsize)
5287ad62 1405 {
dcbf9037 1406 first_error (_("scalar index out of range"));
5287ad62
JB
1407 return FAIL;
1408 }
5f4273c7 1409
dcbf9037
JB
1410 if (type)
1411 *type = atype.eltype;
5f4273c7 1412
5287ad62 1413 *ccp = str;
5f4273c7 1414
dcbf9037 1415 return reg * 16 + atype.index;
5287ad62
JB
1416}
1417
c19d1205
ZW
1418/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1419static long
1420parse_reg_list (char ** strp)
1421{
1422 char * str = * strp;
1423 long range = 0;
1424 int another_range;
a737bd4d 1425
c19d1205
ZW
1426 /* We come back here if we get ranges concatenated by '+' or '|'. */
1427 do
6057a28f 1428 {
c19d1205 1429 another_range = 0;
a737bd4d 1430
c19d1205
ZW
1431 if (*str == '{')
1432 {
1433 int in_range = 0;
1434 int cur_reg = -1;
a737bd4d 1435
c19d1205
ZW
1436 str++;
1437 do
1438 {
1439 int reg;
6057a28f 1440
dcbf9037 1441 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1442 {
dcbf9037 1443 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1444 return FAIL;
1445 }
a737bd4d 1446
c19d1205
ZW
1447 if (in_range)
1448 {
1449 int i;
a737bd4d 1450
c19d1205
ZW
1451 if (reg <= cur_reg)
1452 {
dcbf9037 1453 first_error (_("bad range in register list"));
c19d1205
ZW
1454 return FAIL;
1455 }
40a18ebd 1456
c19d1205
ZW
1457 for (i = cur_reg + 1; i < reg; i++)
1458 {
1459 if (range & (1 << i))
1460 as_tsktsk
1461 (_("Warning: duplicated register (r%d) in register list"),
1462 i);
1463 else
1464 range |= 1 << i;
1465 }
1466 in_range = 0;
1467 }
a737bd4d 1468
c19d1205
ZW
1469 if (range & (1 << reg))
1470 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1471 reg);
1472 else if (reg <= cur_reg)
1473 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1474
c19d1205
ZW
1475 range |= 1 << reg;
1476 cur_reg = reg;
1477 }
1478 while (skip_past_comma (&str) != FAIL
1479 || (in_range = 1, *str++ == '-'));
1480 str--;
a737bd4d 1481
c19d1205
ZW
1482 if (*str++ != '}')
1483 {
dcbf9037 1484 first_error (_("missing `}'"));
c19d1205
ZW
1485 return FAIL;
1486 }
1487 }
1488 else
1489 {
1490 expressionS expr;
40a18ebd 1491
c19d1205
ZW
1492 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1493 return FAIL;
40a18ebd 1494
c19d1205
ZW
1495 if (expr.X_op == O_constant)
1496 {
1497 if (expr.X_add_number
1498 != (expr.X_add_number & 0x0000ffff))
1499 {
1500 inst.error = _("invalid register mask");
1501 return FAIL;
1502 }
a737bd4d 1503
c19d1205
ZW
1504 if ((range & expr.X_add_number) != 0)
1505 {
1506 int regno = range & expr.X_add_number;
a737bd4d 1507
c19d1205
ZW
1508 regno &= -regno;
1509 regno = (1 << regno) - 1;
1510 as_tsktsk
1511 (_("Warning: duplicated register (r%d) in register list"),
1512 regno);
1513 }
a737bd4d 1514
c19d1205
ZW
1515 range |= expr.X_add_number;
1516 }
1517 else
1518 {
1519 if (inst.reloc.type != 0)
1520 {
1521 inst.error = _("expression too complex");
1522 return FAIL;
1523 }
a737bd4d 1524
c19d1205
ZW
1525 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1526 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1527 inst.reloc.pc_rel = 0;
1528 }
1529 }
a737bd4d 1530
c19d1205
ZW
1531 if (*str == '|' || *str == '+')
1532 {
1533 str++;
1534 another_range = 1;
1535 }
a737bd4d 1536 }
c19d1205 1537 while (another_range);
a737bd4d 1538
c19d1205
ZW
1539 *strp = str;
1540 return range;
a737bd4d
NC
1541}
1542
5287ad62
JB
1543/* Types of registers in a list. */
1544
1545enum reg_list_els
1546{
1547 REGLIST_VFP_S,
1548 REGLIST_VFP_D,
1549 REGLIST_NEON_D
1550};
1551
c19d1205
ZW
1552/* Parse a VFP register list. If the string is invalid return FAIL.
1553 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1554 register. Parses registers of type ETYPE.
1555 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1556 - Q registers can be used to specify pairs of D registers
1557 - { } can be omitted from around a singleton register list
1558 FIXME: This is not implemented, as it would require backtracking in
1559 some cases, e.g.:
1560 vtbl.8 d3,d4,d5
1561 This could be done (the meaning isn't really ambiguous), but doesn't
1562 fit in well with the current parsing framework.
dcbf9037
JB
1563 - 32 D registers may be used (also true for VFPv3).
1564 FIXME: Types are ignored in these register lists, which is probably a
1565 bug. */
6057a28f 1566
c19d1205 1567static int
037e8744 1568parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1569{
037e8744 1570 char *str = *ccp;
c19d1205
ZW
1571 int base_reg;
1572 int new_base;
5287ad62
JB
1573 enum arm_reg_type regtype = 0;
1574 int max_regs = 0;
c19d1205
ZW
1575 int count = 0;
1576 int warned = 0;
1577 unsigned long mask = 0;
a737bd4d 1578 int i;
6057a28f 1579
037e8744 1580 if (*str != '{')
5287ad62
JB
1581 {
1582 inst.error = _("expecting {");
1583 return FAIL;
1584 }
6057a28f 1585
037e8744 1586 str++;
6057a28f 1587
5287ad62 1588 switch (etype)
c19d1205 1589 {
5287ad62 1590 case REGLIST_VFP_S:
c19d1205
ZW
1591 regtype = REG_TYPE_VFS;
1592 max_regs = 32;
5287ad62 1593 break;
5f4273c7 1594
5287ad62
JB
1595 case REGLIST_VFP_D:
1596 regtype = REG_TYPE_VFD;
b7fc2769 1597 break;
5f4273c7 1598
b7fc2769
JB
1599 case REGLIST_NEON_D:
1600 regtype = REG_TYPE_NDQ;
1601 break;
1602 }
1603
1604 if (etype != REGLIST_VFP_S)
1605 {
5287ad62
JB
1606 /* VFPv3 allows 32 D registers. */
1607 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1608 {
1609 max_regs = 32;
1610 if (thumb_mode)
1611 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1612 fpu_vfp_ext_v3);
1613 else
1614 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1615 fpu_vfp_ext_v3);
1616 }
1617 else
1618 max_regs = 16;
c19d1205 1619 }
6057a28f 1620
c19d1205 1621 base_reg = max_regs;
a737bd4d 1622
c19d1205
ZW
1623 do
1624 {
5287ad62 1625 int setmask = 1, addregs = 1;
dcbf9037 1626
037e8744 1627 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1628
c19d1205 1629 if (new_base == FAIL)
a737bd4d 1630 {
dcbf9037 1631 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1632 return FAIL;
1633 }
5f4273c7 1634
b7fc2769
JB
1635 if (new_base >= max_regs)
1636 {
1637 first_error (_("register out of range in list"));
1638 return FAIL;
1639 }
5f4273c7 1640
5287ad62
JB
1641 /* Note: a value of 2 * n is returned for the register Q<n>. */
1642 if (regtype == REG_TYPE_NQ)
1643 {
1644 setmask = 3;
1645 addregs = 2;
1646 }
1647
c19d1205
ZW
1648 if (new_base < base_reg)
1649 base_reg = new_base;
a737bd4d 1650
5287ad62 1651 if (mask & (setmask << new_base))
c19d1205 1652 {
dcbf9037 1653 first_error (_("invalid register list"));
c19d1205 1654 return FAIL;
a737bd4d 1655 }
a737bd4d 1656
c19d1205
ZW
1657 if ((mask >> new_base) != 0 && ! warned)
1658 {
1659 as_tsktsk (_("register list not in ascending order"));
1660 warned = 1;
1661 }
0bbf2aa4 1662
5287ad62
JB
1663 mask |= setmask << new_base;
1664 count += addregs;
0bbf2aa4 1665
037e8744 1666 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1667 {
1668 int high_range;
0bbf2aa4 1669
037e8744 1670 str++;
0bbf2aa4 1671
037e8744 1672 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1673 == FAIL)
c19d1205
ZW
1674 {
1675 inst.error = gettext (reg_expected_msgs[regtype]);
1676 return FAIL;
1677 }
0bbf2aa4 1678
b7fc2769
JB
1679 if (high_range >= max_regs)
1680 {
1681 first_error (_("register out of range in list"));
1682 return FAIL;
1683 }
1684
5287ad62
JB
1685 if (regtype == REG_TYPE_NQ)
1686 high_range = high_range + 1;
1687
c19d1205
ZW
1688 if (high_range <= new_base)
1689 {
1690 inst.error = _("register range not in ascending order");
1691 return FAIL;
1692 }
0bbf2aa4 1693
5287ad62 1694 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1695 {
5287ad62 1696 if (mask & (setmask << new_base))
0bbf2aa4 1697 {
c19d1205
ZW
1698 inst.error = _("invalid register list");
1699 return FAIL;
0bbf2aa4 1700 }
c19d1205 1701
5287ad62
JB
1702 mask |= setmask << new_base;
1703 count += addregs;
0bbf2aa4 1704 }
0bbf2aa4 1705 }
0bbf2aa4 1706 }
037e8744 1707 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1708
037e8744 1709 str++;
0bbf2aa4 1710
c19d1205
ZW
1711 /* Sanity check -- should have raised a parse error above. */
1712 if (count == 0 || count > max_regs)
1713 abort ();
1714
1715 *pbase = base_reg;
1716
1717 /* Final test -- the registers must be consecutive. */
1718 mask >>= base_reg;
1719 for (i = 0; i < count; i++)
1720 {
1721 if ((mask & (1u << i)) == 0)
1722 {
1723 inst.error = _("non-contiguous register range");
1724 return FAIL;
1725 }
1726 }
1727
037e8744
JB
1728 *ccp = str;
1729
c19d1205 1730 return count;
b99bd4ef
NC
1731}
1732
dcbf9037
JB
1733/* True if two alias types are the same. */
1734
1735static int
1736neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1737{
1738 if (!a && !b)
1739 return 1;
5f4273c7 1740
dcbf9037
JB
1741 if (!a || !b)
1742 return 0;
1743
1744 if (a->defined != b->defined)
1745 return 0;
5f4273c7 1746
dcbf9037
JB
1747 if ((a->defined & NTA_HASTYPE) != 0
1748 && (a->eltype.type != b->eltype.type
1749 || a->eltype.size != b->eltype.size))
1750 return 0;
1751
1752 if ((a->defined & NTA_HASINDEX) != 0
1753 && (a->index != b->index))
1754 return 0;
5f4273c7 1755
dcbf9037
JB
1756 return 1;
1757}
1758
5287ad62
JB
1759/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1760 The base register is put in *PBASE.
dcbf9037 1761 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1762 the return value.
1763 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1764 Bits [6:5] encode the list length (minus one).
1765 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1766
5287ad62 1767#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1768#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1769#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1770
1771static int
dcbf9037
JB
1772parse_neon_el_struct_list (char **str, unsigned *pbase,
1773 struct neon_type_el *eltype)
5287ad62
JB
1774{
1775 char *ptr = *str;
1776 int base_reg = -1;
1777 int reg_incr = -1;
1778 int count = 0;
1779 int lane = -1;
1780 int leading_brace = 0;
1781 enum arm_reg_type rtype = REG_TYPE_NDQ;
1782 int addregs = 1;
1783 const char *const incr_error = "register stride must be 1 or 2";
1784 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1785 struct neon_typed_alias firsttype;
5f4273c7 1786
5287ad62
JB
1787 if (skip_past_char (&ptr, '{') == SUCCESS)
1788 leading_brace = 1;
5f4273c7 1789
5287ad62
JB
1790 do
1791 {
dcbf9037
JB
1792 struct neon_typed_alias atype;
1793 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1794
5287ad62
JB
1795 if (getreg == FAIL)
1796 {
dcbf9037 1797 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1798 return FAIL;
1799 }
5f4273c7 1800
5287ad62
JB
1801 if (base_reg == -1)
1802 {
1803 base_reg = getreg;
1804 if (rtype == REG_TYPE_NQ)
1805 {
1806 reg_incr = 1;
1807 addregs = 2;
1808 }
dcbf9037 1809 firsttype = atype;
5287ad62
JB
1810 }
1811 else if (reg_incr == -1)
1812 {
1813 reg_incr = getreg - base_reg;
1814 if (reg_incr < 1 || reg_incr > 2)
1815 {
dcbf9037 1816 first_error (_(incr_error));
5287ad62
JB
1817 return FAIL;
1818 }
1819 }
1820 else if (getreg != base_reg + reg_incr * count)
1821 {
dcbf9037
JB
1822 first_error (_(incr_error));
1823 return FAIL;
1824 }
1825
1826 if (!neon_alias_types_same (&atype, &firsttype))
1827 {
1828 first_error (_(type_error));
5287ad62
JB
1829 return FAIL;
1830 }
5f4273c7 1831
5287ad62
JB
1832 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1833 modes. */
1834 if (ptr[0] == '-')
1835 {
dcbf9037 1836 struct neon_typed_alias htype;
5287ad62
JB
1837 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1838 if (lane == -1)
1839 lane = NEON_INTERLEAVE_LANES;
1840 else if (lane != NEON_INTERLEAVE_LANES)
1841 {
dcbf9037 1842 first_error (_(type_error));
5287ad62
JB
1843 return FAIL;
1844 }
1845 if (reg_incr == -1)
1846 reg_incr = 1;
1847 else if (reg_incr != 1)
1848 {
dcbf9037 1849 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1850 return FAIL;
1851 }
1852 ptr++;
dcbf9037 1853 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1854 if (hireg == FAIL)
1855 {
dcbf9037
JB
1856 first_error (_(reg_expected_msgs[rtype]));
1857 return FAIL;
1858 }
1859 if (!neon_alias_types_same (&htype, &firsttype))
1860 {
1861 first_error (_(type_error));
5287ad62
JB
1862 return FAIL;
1863 }
1864 count += hireg + dregs - getreg;
1865 continue;
1866 }
5f4273c7 1867
5287ad62
JB
1868 /* If we're using Q registers, we can't use [] or [n] syntax. */
1869 if (rtype == REG_TYPE_NQ)
1870 {
1871 count += 2;
1872 continue;
1873 }
5f4273c7 1874
dcbf9037 1875 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1876 {
dcbf9037
JB
1877 if (lane == -1)
1878 lane = atype.index;
1879 else if (lane != atype.index)
5287ad62 1880 {
dcbf9037
JB
1881 first_error (_(type_error));
1882 return FAIL;
5287ad62
JB
1883 }
1884 }
1885 else if (lane == -1)
1886 lane = NEON_INTERLEAVE_LANES;
1887 else if (lane != NEON_INTERLEAVE_LANES)
1888 {
dcbf9037 1889 first_error (_(type_error));
5287ad62
JB
1890 return FAIL;
1891 }
1892 count++;
1893 }
1894 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1895
5287ad62
JB
1896 /* No lane set by [x]. We must be interleaving structures. */
1897 if (lane == -1)
1898 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1899
5287ad62
JB
1900 /* Sanity check. */
1901 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1902 || (count > 1 && reg_incr == -1))
1903 {
dcbf9037 1904 first_error (_("error parsing element/structure list"));
5287ad62
JB
1905 return FAIL;
1906 }
1907
1908 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1909 {
dcbf9037 1910 first_error (_("expected }"));
5287ad62
JB
1911 return FAIL;
1912 }
5f4273c7 1913
5287ad62
JB
1914 if (reg_incr == -1)
1915 reg_incr = 1;
1916
dcbf9037
JB
1917 if (eltype)
1918 *eltype = firsttype.eltype;
1919
5287ad62
JB
1920 *pbase = base_reg;
1921 *str = ptr;
5f4273c7 1922
5287ad62
JB
1923 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1924}
1925
c19d1205
ZW
1926/* Parse an explicit relocation suffix on an expression. This is
1927 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1928 arm_reloc_hsh contains no entries, so this function can only
1929 succeed if there is no () after the word. Returns -1 on error,
1930 BFD_RELOC_UNUSED if there wasn't any suffix. */
1931static int
1932parse_reloc (char **str)
b99bd4ef 1933{
c19d1205
ZW
1934 struct reloc_entry *r;
1935 char *p, *q;
b99bd4ef 1936
c19d1205
ZW
1937 if (**str != '(')
1938 return BFD_RELOC_UNUSED;
b99bd4ef 1939
c19d1205
ZW
1940 p = *str + 1;
1941 q = p;
1942
1943 while (*q && *q != ')' && *q != ',')
1944 q++;
1945 if (*q != ')')
1946 return -1;
1947
1948 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1949 return -1;
1950
1951 *str = q + 1;
1952 return r->reloc;
b99bd4ef
NC
1953}
1954
c19d1205
ZW
1955/* Directives: register aliases. */
1956
dcbf9037 1957static struct reg_entry *
c19d1205 1958insert_reg_alias (char *str, int number, int type)
b99bd4ef 1959{
c19d1205
ZW
1960 struct reg_entry *new;
1961 const char *name;
b99bd4ef 1962
c19d1205
ZW
1963 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1964 {
1965 if (new->builtin)
1966 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1967
c19d1205
ZW
1968 /* Only warn about a redefinition if it's not defined as the
1969 same register. */
1970 else if (new->number != number || new->type != type)
1971 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1972
d929913e 1973 return NULL;
c19d1205 1974 }
b99bd4ef 1975
c19d1205
ZW
1976 name = xstrdup (str);
1977 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1978
c19d1205
ZW
1979 new->name = name;
1980 new->number = number;
1981 new->type = type;
1982 new->builtin = FALSE;
dcbf9037 1983 new->neon = NULL;
b99bd4ef 1984
c19d1205
ZW
1985 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1986 abort ();
5f4273c7 1987
dcbf9037
JB
1988 return new;
1989}
1990
1991static void
1992insert_neon_reg_alias (char *str, int number, int type,
1993 struct neon_typed_alias *atype)
1994{
1995 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 1996
dcbf9037
JB
1997 if (!reg)
1998 {
1999 first_error (_("attempt to redefine typed alias"));
2000 return;
2001 }
5f4273c7 2002
dcbf9037
JB
2003 if (atype)
2004 {
2005 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2006 *reg->neon = *atype;
2007 }
c19d1205 2008}
b99bd4ef 2009
c19d1205 2010/* Look for the .req directive. This is of the form:
b99bd4ef 2011
c19d1205 2012 new_register_name .req existing_register_name
b99bd4ef 2013
c19d1205 2014 If we find one, or if it looks sufficiently like one that we want to
d929913e 2015 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2016
d929913e 2017static bfd_boolean
c19d1205
ZW
2018create_register_alias (char * newname, char *p)
2019{
2020 struct reg_entry *old;
2021 char *oldname, *nbuf;
2022 size_t nlen;
b99bd4ef 2023
c19d1205
ZW
2024 /* The input scrubber ensures that whitespace after the mnemonic is
2025 collapsed to single spaces. */
2026 oldname = p;
2027 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2028 return FALSE;
b99bd4ef 2029
c19d1205
ZW
2030 oldname += 6;
2031 if (*oldname == '\0')
d929913e 2032 return FALSE;
b99bd4ef 2033
c19d1205
ZW
2034 old = hash_find (arm_reg_hsh, oldname);
2035 if (!old)
b99bd4ef 2036 {
c19d1205 2037 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2038 return TRUE;
b99bd4ef
NC
2039 }
2040
c19d1205
ZW
2041 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2042 the desired alias name, and p points to its end. If not, then
2043 the desired alias name is in the global original_case_string. */
2044#ifdef TC_CASE_SENSITIVE
2045 nlen = p - newname;
2046#else
2047 newname = original_case_string;
2048 nlen = strlen (newname);
2049#endif
b99bd4ef 2050
c19d1205
ZW
2051 nbuf = alloca (nlen + 1);
2052 memcpy (nbuf, newname, nlen);
2053 nbuf[nlen] = '\0';
b99bd4ef 2054
c19d1205
ZW
2055 /* Create aliases under the new name as stated; an all-lowercase
2056 version of the new name; and an all-uppercase version of the new
2057 name. */
d929913e
NC
2058 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2059 {
2060 for (p = nbuf; *p; p++)
2061 *p = TOUPPER (*p);
c19d1205 2062
d929913e
NC
2063 if (strncmp (nbuf, newname, nlen))
2064 {
2065 /* If this attempt to create an additional alias fails, do not bother
2066 trying to create the all-lower case alias. We will fail and issue
2067 a second, duplicate error message. This situation arises when the
2068 programmer does something like:
2069 foo .req r0
2070 Foo .req r1
2071 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2072 the artificial FOO alias because it has already been created by the
d929913e
NC
2073 first .req. */
2074 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2075 return TRUE;
2076 }
c19d1205 2077
d929913e
NC
2078 for (p = nbuf; *p; p++)
2079 *p = TOLOWER (*p);
c19d1205 2080
d929913e
NC
2081 if (strncmp (nbuf, newname, nlen))
2082 insert_reg_alias (nbuf, old->number, old->type);
2083 }
c19d1205 2084
d929913e 2085 return TRUE;
b99bd4ef
NC
2086}
2087
dcbf9037
JB
2088/* Create a Neon typed/indexed register alias using directives, e.g.:
2089 X .dn d5.s32[1]
2090 Y .qn 6.s16
2091 Z .dn d7
2092 T .dn Z[0]
2093 These typed registers can be used instead of the types specified after the
2094 Neon mnemonic, so long as all operands given have types. Types can also be
2095 specified directly, e.g.:
5f4273c7 2096 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2097
2098static int
2099create_neon_reg_alias (char *newname, char *p)
2100{
2101 enum arm_reg_type basetype;
2102 struct reg_entry *basereg;
2103 struct reg_entry mybasereg;
2104 struct neon_type ntype;
2105 struct neon_typed_alias typeinfo;
2106 char *namebuf, *nameend;
2107 int namelen;
5f4273c7 2108
dcbf9037
JB
2109 typeinfo.defined = 0;
2110 typeinfo.eltype.type = NT_invtype;
2111 typeinfo.eltype.size = -1;
2112 typeinfo.index = -1;
5f4273c7 2113
dcbf9037 2114 nameend = p;
5f4273c7 2115
dcbf9037
JB
2116 if (strncmp (p, " .dn ", 5) == 0)
2117 basetype = REG_TYPE_VFD;
2118 else if (strncmp (p, " .qn ", 5) == 0)
2119 basetype = REG_TYPE_NQ;
2120 else
2121 return 0;
5f4273c7 2122
dcbf9037 2123 p += 5;
5f4273c7 2124
dcbf9037
JB
2125 if (*p == '\0')
2126 return 0;
5f4273c7 2127
dcbf9037
JB
2128 basereg = arm_reg_parse_multi (&p);
2129
2130 if (basereg && basereg->type != basetype)
2131 {
2132 as_bad (_("bad type for register"));
2133 return 0;
2134 }
2135
2136 if (basereg == NULL)
2137 {
2138 expressionS exp;
2139 /* Try parsing as an integer. */
2140 my_get_expression (&exp, &p, GE_NO_PREFIX);
2141 if (exp.X_op != O_constant)
2142 {
2143 as_bad (_("expression must be constant"));
2144 return 0;
2145 }
2146 basereg = &mybasereg;
2147 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2148 : exp.X_add_number;
2149 basereg->neon = 0;
2150 }
2151
2152 if (basereg->neon)
2153 typeinfo = *basereg->neon;
2154
2155 if (parse_neon_type (&ntype, &p) == SUCCESS)
2156 {
2157 /* We got a type. */
2158 if (typeinfo.defined & NTA_HASTYPE)
2159 {
2160 as_bad (_("can't redefine the type of a register alias"));
2161 return 0;
2162 }
5f4273c7 2163
dcbf9037
JB
2164 typeinfo.defined |= NTA_HASTYPE;
2165 if (ntype.elems != 1)
2166 {
2167 as_bad (_("you must specify a single type only"));
2168 return 0;
2169 }
2170 typeinfo.eltype = ntype.el[0];
2171 }
5f4273c7 2172
dcbf9037
JB
2173 if (skip_past_char (&p, '[') == SUCCESS)
2174 {
2175 expressionS exp;
2176 /* We got a scalar index. */
5f4273c7 2177
dcbf9037
JB
2178 if (typeinfo.defined & NTA_HASINDEX)
2179 {
2180 as_bad (_("can't redefine the index of a scalar alias"));
2181 return 0;
2182 }
5f4273c7 2183
dcbf9037 2184 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2185
dcbf9037
JB
2186 if (exp.X_op != O_constant)
2187 {
2188 as_bad (_("scalar index must be constant"));
2189 return 0;
2190 }
5f4273c7 2191
dcbf9037
JB
2192 typeinfo.defined |= NTA_HASINDEX;
2193 typeinfo.index = exp.X_add_number;
5f4273c7 2194
dcbf9037
JB
2195 if (skip_past_char (&p, ']') == FAIL)
2196 {
2197 as_bad (_("expecting ]"));
2198 return 0;
2199 }
2200 }
2201
2202 namelen = nameend - newname;
2203 namebuf = alloca (namelen + 1);
2204 strncpy (namebuf, newname, namelen);
2205 namebuf[namelen] = '\0';
5f4273c7 2206
dcbf9037
JB
2207 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2208 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2209
dcbf9037
JB
2210 /* Insert name in all uppercase. */
2211 for (p = namebuf; *p; p++)
2212 *p = TOUPPER (*p);
5f4273c7 2213
dcbf9037
JB
2214 if (strncmp (namebuf, newname, namelen))
2215 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2216 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2217
dcbf9037
JB
2218 /* Insert name in all lowercase. */
2219 for (p = namebuf; *p; p++)
2220 *p = TOLOWER (*p);
5f4273c7 2221
dcbf9037
JB
2222 if (strncmp (namebuf, newname, namelen))
2223 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2224 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2225
dcbf9037
JB
2226 return 1;
2227}
2228
c19d1205
ZW
2229/* Should never be called, as .req goes between the alias and the
2230 register name, not at the beginning of the line. */
b99bd4ef 2231static void
c19d1205 2232s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2233{
c19d1205
ZW
2234 as_bad (_("invalid syntax for .req directive"));
2235}
b99bd4ef 2236
dcbf9037
JB
2237static void
2238s_dn (int a ATTRIBUTE_UNUSED)
2239{
2240 as_bad (_("invalid syntax for .dn directive"));
2241}
2242
2243static void
2244s_qn (int a ATTRIBUTE_UNUSED)
2245{
2246 as_bad (_("invalid syntax for .qn directive"));
2247}
2248
c19d1205
ZW
2249/* The .unreq directive deletes an alias which was previously defined
2250 by .req. For example:
b99bd4ef 2251
c19d1205
ZW
2252 my_alias .req r11
2253 .unreq my_alias */
b99bd4ef
NC
2254
2255static void
c19d1205 2256s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2257{
c19d1205
ZW
2258 char * name;
2259 char saved_char;
b99bd4ef 2260
c19d1205
ZW
2261 name = input_line_pointer;
2262
2263 while (*input_line_pointer != 0
2264 && *input_line_pointer != ' '
2265 && *input_line_pointer != '\n')
2266 ++input_line_pointer;
2267
2268 saved_char = *input_line_pointer;
2269 *input_line_pointer = 0;
2270
2271 if (!*name)
2272 as_bad (_("invalid syntax for .unreq directive"));
2273 else
2274 {
2275 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2276
2277 if (!reg)
2278 as_bad (_("unknown register alias '%s'"), name);
2279 else if (reg->builtin)
2280 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2281 name);
2282 else
2283 {
d929913e
NC
2284 char * p;
2285 char * nbuf;
2286
c19d1205
ZW
2287 hash_delete (arm_reg_hsh, name);
2288 free ((char *) reg->name);
dcbf9037
JB
2289 if (reg->neon)
2290 free (reg->neon);
c19d1205 2291 free (reg);
d929913e
NC
2292
2293 /* Also locate the all upper case and all lower case versions.
2294 Do not complain if we cannot find one or the other as it
2295 was probably deleted above. */
5f4273c7 2296
d929913e
NC
2297 nbuf = strdup (name);
2298 for (p = nbuf; *p; p++)
2299 *p = TOUPPER (*p);
2300 reg = hash_find (arm_reg_hsh, nbuf);
2301 if (reg)
2302 {
2303 hash_delete (arm_reg_hsh, nbuf);
2304 free ((char *) reg->name);
2305 if (reg->neon)
2306 free (reg->neon);
2307 free (reg);
2308 }
2309
2310 for (p = nbuf; *p; p++)
2311 *p = TOLOWER (*p);
2312 reg = hash_find (arm_reg_hsh, nbuf);
2313 if (reg)
2314 {
2315 hash_delete (arm_reg_hsh, nbuf);
2316 free ((char *) reg->name);
2317 if (reg->neon)
2318 free (reg->neon);
2319 free (reg);
2320 }
2321
2322 free (nbuf);
c19d1205
ZW
2323 }
2324 }
b99bd4ef 2325
c19d1205 2326 *input_line_pointer = saved_char;
b99bd4ef
NC
2327 demand_empty_rest_of_line ();
2328}
2329
c19d1205
ZW
2330/* Directives: Instruction set selection. */
2331
2332#ifdef OBJ_ELF
2333/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2334 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2335 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2336 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2337
2338static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2339
e821645d 2340void
c19d1205 2341mapping_state (enum mstate state)
b99bd4ef 2342{
a737bd4d 2343 symbolS * symbolP;
c19d1205
ZW
2344 const char * symname;
2345 int type;
b99bd4ef 2346
c19d1205
ZW
2347 if (mapstate == state)
2348 /* The mapping symbol has already been emitted.
2349 There is nothing else to do. */
2350 return;
b99bd4ef 2351
c19d1205 2352 mapstate = state;
b99bd4ef 2353
c19d1205 2354 switch (state)
b99bd4ef 2355 {
c19d1205
ZW
2356 case MAP_DATA:
2357 symname = "$d";
2358 type = BSF_NO_FLAGS;
2359 break;
2360 case MAP_ARM:
2361 symname = "$a";
2362 type = BSF_NO_FLAGS;
2363 break;
2364 case MAP_THUMB:
2365 symname = "$t";
2366 type = BSF_NO_FLAGS;
2367 break;
2368 case MAP_UNDEFINED:
2369 return;
2370 default:
2371 abort ();
2372 }
2373
2374 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2375
2376 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2377 symbol_table_insert (symbolP);
2378 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2379
2380 switch (state)
2381 {
2382 case MAP_ARM:
2383 THUMB_SET_FUNC (symbolP, 0);
2384 ARM_SET_THUMB (symbolP, 0);
2385 ARM_SET_INTERWORK (symbolP, support_interwork);
2386 break;
2387
2388 case MAP_THUMB:
2389 THUMB_SET_FUNC (symbolP, 1);
2390 ARM_SET_THUMB (symbolP, 1);
2391 ARM_SET_INTERWORK (symbolP, support_interwork);
2392 break;
2393
2394 case MAP_DATA:
2395 default:
2396 return;
2397 }
2398}
2399#else
2400#define mapping_state(x) /* nothing */
2401#endif
2402
2403/* Find the real, Thumb encoded start of a Thumb function. */
2404
2405static symbolS *
2406find_real_start (symbolS * symbolP)
2407{
2408 char * real_start;
2409 const char * name = S_GET_NAME (symbolP);
2410 symbolS * new_target;
2411
2412 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2413#define STUB_NAME ".real_start_of"
2414
2415 if (name == NULL)
2416 abort ();
2417
37f6032b
ZW
2418 /* The compiler may generate BL instructions to local labels because
2419 it needs to perform a branch to a far away location. These labels
2420 do not have a corresponding ".real_start_of" label. We check
2421 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2422 the ".real_start_of" convention for nonlocal branches. */
2423 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2424 return symbolP;
2425
37f6032b 2426 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2427 new_target = symbol_find (real_start);
2428
2429 if (new_target == NULL)
2430 {
bd3ba5d1 2431 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2432 new_target = symbolP;
2433 }
2434
c19d1205
ZW
2435 return new_target;
2436}
2437
2438static void
2439opcode_select (int width)
2440{
2441 switch (width)
2442 {
2443 case 16:
2444 if (! thumb_mode)
2445 {
e74cfd16 2446 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2447 as_bad (_("selected processor does not support THUMB opcodes"));
2448
2449 thumb_mode = 1;
2450 /* No need to force the alignment, since we will have been
2451 coming from ARM mode, which is word-aligned. */
2452 record_alignment (now_seg, 1);
2453 }
2454 mapping_state (MAP_THUMB);
2455 break;
2456
2457 case 32:
2458 if (thumb_mode)
2459 {
e74cfd16 2460 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2461 as_bad (_("selected processor does not support ARM opcodes"));
2462
2463 thumb_mode = 0;
2464
2465 if (!need_pass_2)
2466 frag_align (2, 0, 0);
2467
2468 record_alignment (now_seg, 1);
2469 }
2470 mapping_state (MAP_ARM);
2471 break;
2472
2473 default:
2474 as_bad (_("invalid instruction size selected (%d)"), width);
2475 }
2476}
2477
2478static void
2479s_arm (int ignore ATTRIBUTE_UNUSED)
2480{
2481 opcode_select (32);
2482 demand_empty_rest_of_line ();
2483}
2484
2485static void
2486s_thumb (int ignore ATTRIBUTE_UNUSED)
2487{
2488 opcode_select (16);
2489 demand_empty_rest_of_line ();
2490}
2491
2492static void
2493s_code (int unused ATTRIBUTE_UNUSED)
2494{
2495 int temp;
2496
2497 temp = get_absolute_expression ();
2498 switch (temp)
2499 {
2500 case 16:
2501 case 32:
2502 opcode_select (temp);
2503 break;
2504
2505 default:
2506 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2507 }
2508}
2509
2510static void
2511s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2512{
2513 /* If we are not already in thumb mode go into it, EVEN if
2514 the target processor does not support thumb instructions.
2515 This is used by gcc/config/arm/lib1funcs.asm for example
2516 to compile interworking support functions even if the
2517 target processor should not support interworking. */
2518 if (! thumb_mode)
2519 {
2520 thumb_mode = 2;
2521 record_alignment (now_seg, 1);
2522 }
2523
2524 demand_empty_rest_of_line ();
2525}
2526
2527static void
2528s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2529{
2530 s_thumb (0);
2531
2532 /* The following label is the name/address of the start of a Thumb function.
2533 We need to know this for the interworking support. */
2534 label_is_thumb_function_name = TRUE;
2535}
2536
2537/* Perform a .set directive, but also mark the alias as
2538 being a thumb function. */
2539
2540static void
2541s_thumb_set (int equiv)
2542{
2543 /* XXX the following is a duplicate of the code for s_set() in read.c
2544 We cannot just call that code as we need to get at the symbol that
2545 is created. */
2546 char * name;
2547 char delim;
2548 char * end_name;
2549 symbolS * symbolP;
2550
2551 /* Especial apologies for the random logic:
2552 This just grew, and could be parsed much more simply!
2553 Dean - in haste. */
2554 name = input_line_pointer;
2555 delim = get_symbol_end ();
2556 end_name = input_line_pointer;
2557 *end_name = delim;
2558
2559 if (*input_line_pointer != ',')
2560 {
2561 *end_name = 0;
2562 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2563 *end_name = delim;
2564 ignore_rest_of_line ();
2565 return;
2566 }
2567
2568 input_line_pointer++;
2569 *end_name = 0;
2570
2571 if (name[0] == '.' && name[1] == '\0')
2572 {
2573 /* XXX - this should not happen to .thumb_set. */
2574 abort ();
2575 }
2576
2577 if ((symbolP = symbol_find (name)) == NULL
2578 && (symbolP = md_undefined_symbol (name)) == NULL)
2579 {
2580#ifndef NO_LISTING
2581 /* When doing symbol listings, play games with dummy fragments living
2582 outside the normal fragment chain to record the file and line info
c19d1205 2583 for this symbol. */
b99bd4ef
NC
2584 if (listing & LISTING_SYMBOLS)
2585 {
2586 extern struct list_info_struct * listing_tail;
a737bd4d 2587 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2588
2589 memset (dummy_frag, 0, sizeof (fragS));
2590 dummy_frag->fr_type = rs_fill;
2591 dummy_frag->line = listing_tail;
2592 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2593 dummy_frag->fr_symbol = symbolP;
2594 }
2595 else
2596#endif
2597 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2598
2599#ifdef OBJ_COFF
2600 /* "set" symbols are local unless otherwise specified. */
2601 SF_SET_LOCAL (symbolP);
2602#endif /* OBJ_COFF */
2603 } /* Make a new symbol. */
2604
2605 symbol_table_insert (symbolP);
2606
2607 * end_name = delim;
2608
2609 if (equiv
2610 && S_IS_DEFINED (symbolP)
2611 && S_GET_SEGMENT (symbolP) != reg_section)
2612 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2613
2614 pseudo_set (symbolP);
2615
2616 demand_empty_rest_of_line ();
2617
c19d1205 2618 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2619
2620 THUMB_SET_FUNC (symbolP, 1);
2621 ARM_SET_THUMB (symbolP, 1);
2622#if defined OBJ_ELF || defined OBJ_COFF
2623 ARM_SET_INTERWORK (symbolP, support_interwork);
2624#endif
2625}
2626
c19d1205 2627/* Directives: Mode selection. */
b99bd4ef 2628
c19d1205
ZW
2629/* .syntax [unified|divided] - choose the new unified syntax
2630 (same for Arm and Thumb encoding, modulo slight differences in what
2631 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2632static void
c19d1205 2633s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2634{
c19d1205
ZW
2635 char *name, delim;
2636
2637 name = input_line_pointer;
2638 delim = get_symbol_end ();
2639
2640 if (!strcasecmp (name, "unified"))
2641 unified_syntax = TRUE;
2642 else if (!strcasecmp (name, "divided"))
2643 unified_syntax = FALSE;
2644 else
2645 {
2646 as_bad (_("unrecognized syntax mode \"%s\""), name);
2647 return;
2648 }
2649 *input_line_pointer = delim;
b99bd4ef
NC
2650 demand_empty_rest_of_line ();
2651}
2652
c19d1205
ZW
2653/* Directives: sectioning and alignment. */
2654
2655/* Same as s_align_ptwo but align 0 => align 2. */
2656
b99bd4ef 2657static void
c19d1205 2658s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2659{
a737bd4d 2660 int temp;
dce323d1 2661 bfd_boolean fill_p;
c19d1205
ZW
2662 long temp_fill;
2663 long max_alignment = 15;
b99bd4ef
NC
2664
2665 temp = get_absolute_expression ();
c19d1205
ZW
2666 if (temp > max_alignment)
2667 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2668 else if (temp < 0)
b99bd4ef 2669 {
c19d1205
ZW
2670 as_bad (_("alignment negative. 0 assumed."));
2671 temp = 0;
2672 }
b99bd4ef 2673
c19d1205
ZW
2674 if (*input_line_pointer == ',')
2675 {
2676 input_line_pointer++;
2677 temp_fill = get_absolute_expression ();
dce323d1 2678 fill_p = TRUE;
b99bd4ef 2679 }
c19d1205 2680 else
dce323d1
PB
2681 {
2682 fill_p = FALSE;
2683 temp_fill = 0;
2684 }
b99bd4ef 2685
c19d1205
ZW
2686 if (!temp)
2687 temp = 2;
b99bd4ef 2688
c19d1205
ZW
2689 /* Only make a frag if we HAVE to. */
2690 if (temp && !need_pass_2)
dce323d1
PB
2691 {
2692 if (!fill_p && subseg_text_p (now_seg))
2693 frag_align_code (temp, 0);
2694 else
2695 frag_align (temp, (int) temp_fill, 0);
2696 }
c19d1205
ZW
2697 demand_empty_rest_of_line ();
2698
2699 record_alignment (now_seg, temp);
b99bd4ef
NC
2700}
2701
c19d1205
ZW
2702static void
2703s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2704{
c19d1205
ZW
2705 /* We don't support putting frags in the BSS segment, we fake it by
2706 marking in_bss, then looking at s_skip for clues. */
2707 subseg_set (bss_section, 0);
2708 demand_empty_rest_of_line ();
2709 mapping_state (MAP_DATA);
2710}
b99bd4ef 2711
c19d1205
ZW
2712static void
2713s_even (int ignore ATTRIBUTE_UNUSED)
2714{
2715 /* Never make frag if expect extra pass. */
2716 if (!need_pass_2)
2717 frag_align (1, 0, 0);
b99bd4ef 2718
c19d1205 2719 record_alignment (now_seg, 1);
b99bd4ef 2720
c19d1205 2721 demand_empty_rest_of_line ();
b99bd4ef
NC
2722}
2723
c19d1205 2724/* Directives: Literal pools. */
a737bd4d 2725
c19d1205
ZW
2726static literal_pool *
2727find_literal_pool (void)
a737bd4d 2728{
c19d1205 2729 literal_pool * pool;
a737bd4d 2730
c19d1205 2731 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2732 {
c19d1205
ZW
2733 if (pool->section == now_seg
2734 && pool->sub_section == now_subseg)
2735 break;
a737bd4d
NC
2736 }
2737
c19d1205 2738 return pool;
a737bd4d
NC
2739}
2740
c19d1205
ZW
2741static literal_pool *
2742find_or_make_literal_pool (void)
a737bd4d 2743{
c19d1205
ZW
2744 /* Next literal pool ID number. */
2745 static unsigned int latest_pool_num = 1;
2746 literal_pool * pool;
a737bd4d 2747
c19d1205 2748 pool = find_literal_pool ();
a737bd4d 2749
c19d1205 2750 if (pool == NULL)
a737bd4d 2751 {
c19d1205
ZW
2752 /* Create a new pool. */
2753 pool = xmalloc (sizeof (* pool));
2754 if (! pool)
2755 return NULL;
a737bd4d 2756
c19d1205
ZW
2757 pool->next_free_entry = 0;
2758 pool->section = now_seg;
2759 pool->sub_section = now_subseg;
2760 pool->next = list_of_pools;
2761 pool->symbol = NULL;
2762
2763 /* Add it to the list. */
2764 list_of_pools = pool;
a737bd4d 2765 }
a737bd4d 2766
c19d1205
ZW
2767 /* New pools, and emptied pools, will have a NULL symbol. */
2768 if (pool->symbol == NULL)
a737bd4d 2769 {
c19d1205
ZW
2770 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2771 (valueT) 0, &zero_address_frag);
2772 pool->id = latest_pool_num ++;
a737bd4d
NC
2773 }
2774
c19d1205
ZW
2775 /* Done. */
2776 return pool;
a737bd4d
NC
2777}
2778
c19d1205 2779/* Add the literal in the global 'inst'
5f4273c7 2780 structure to the relevant literal pool. */
b99bd4ef
NC
2781
2782static int
c19d1205 2783add_to_lit_pool (void)
b99bd4ef 2784{
c19d1205
ZW
2785 literal_pool * pool;
2786 unsigned int entry;
b99bd4ef 2787
c19d1205
ZW
2788 pool = find_or_make_literal_pool ();
2789
2790 /* Check if this literal value is already in the pool. */
2791 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2792 {
c19d1205
ZW
2793 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2794 && (inst.reloc.exp.X_op == O_constant)
2795 && (pool->literals[entry].X_add_number
2796 == inst.reloc.exp.X_add_number)
2797 && (pool->literals[entry].X_unsigned
2798 == inst.reloc.exp.X_unsigned))
2799 break;
2800
2801 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2802 && (inst.reloc.exp.X_op == O_symbol)
2803 && (pool->literals[entry].X_add_number
2804 == inst.reloc.exp.X_add_number)
2805 && (pool->literals[entry].X_add_symbol
2806 == inst.reloc.exp.X_add_symbol)
2807 && (pool->literals[entry].X_op_symbol
2808 == inst.reloc.exp.X_op_symbol))
2809 break;
b99bd4ef
NC
2810 }
2811
c19d1205
ZW
2812 /* Do we need to create a new entry? */
2813 if (entry == pool->next_free_entry)
2814 {
2815 if (entry >= MAX_LITERAL_POOL_SIZE)
2816 {
2817 inst.error = _("literal pool overflow");
2818 return FAIL;
2819 }
2820
2821 pool->literals[entry] = inst.reloc.exp;
2822 pool->next_free_entry += 1;
2823 }
b99bd4ef 2824
c19d1205
ZW
2825 inst.reloc.exp.X_op = O_symbol;
2826 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2827 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2828
c19d1205 2829 return SUCCESS;
b99bd4ef
NC
2830}
2831
c19d1205
ZW
2832/* Can't use symbol_new here, so have to create a symbol and then at
2833 a later date assign it a value. Thats what these functions do. */
e16bb312 2834
c19d1205
ZW
2835static void
2836symbol_locate (symbolS * symbolP,
2837 const char * name, /* It is copied, the caller can modify. */
2838 segT segment, /* Segment identifier (SEG_<something>). */
2839 valueT valu, /* Symbol value. */
2840 fragS * frag) /* Associated fragment. */
2841{
2842 unsigned int name_length;
2843 char * preserved_copy_of_name;
e16bb312 2844
c19d1205
ZW
2845 name_length = strlen (name) + 1; /* +1 for \0. */
2846 obstack_grow (&notes, name, name_length);
2847 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2848
c19d1205
ZW
2849#ifdef tc_canonicalize_symbol_name
2850 preserved_copy_of_name =
2851 tc_canonicalize_symbol_name (preserved_copy_of_name);
2852#endif
b99bd4ef 2853
c19d1205 2854 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2855
c19d1205
ZW
2856 S_SET_SEGMENT (symbolP, segment);
2857 S_SET_VALUE (symbolP, valu);
2858 symbol_clear_list_pointers (symbolP);
b99bd4ef 2859
c19d1205 2860 symbol_set_frag (symbolP, frag);
b99bd4ef 2861
c19d1205
ZW
2862 /* Link to end of symbol chain. */
2863 {
2864 extern int symbol_table_frozen;
b99bd4ef 2865
c19d1205
ZW
2866 if (symbol_table_frozen)
2867 abort ();
2868 }
b99bd4ef 2869
c19d1205 2870 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2871
c19d1205 2872 obj_symbol_new_hook (symbolP);
b99bd4ef 2873
c19d1205
ZW
2874#ifdef tc_symbol_new_hook
2875 tc_symbol_new_hook (symbolP);
2876#endif
2877
2878#ifdef DEBUG_SYMS
2879 verify_symbol_chain (symbol_rootP, symbol_lastP);
2880#endif /* DEBUG_SYMS */
b99bd4ef
NC
2881}
2882
b99bd4ef 2883
c19d1205
ZW
2884static void
2885s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2886{
c19d1205
ZW
2887 unsigned int entry;
2888 literal_pool * pool;
2889 char sym_name[20];
b99bd4ef 2890
c19d1205
ZW
2891 pool = find_literal_pool ();
2892 if (pool == NULL
2893 || pool->symbol == NULL
2894 || pool->next_free_entry == 0)
2895 return;
b99bd4ef 2896
c19d1205 2897 mapping_state (MAP_DATA);
b99bd4ef 2898
c19d1205
ZW
2899 /* Align pool as you have word accesses.
2900 Only make a frag if we have to. */
2901 if (!need_pass_2)
2902 frag_align (2, 0, 0);
b99bd4ef 2903
c19d1205 2904 record_alignment (now_seg, 2);
b99bd4ef 2905
c19d1205 2906 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2907
c19d1205
ZW
2908 symbol_locate (pool->symbol, sym_name, now_seg,
2909 (valueT) frag_now_fix (), frag_now);
2910 symbol_table_insert (pool->symbol);
b99bd4ef 2911
c19d1205 2912 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2913
c19d1205
ZW
2914#if defined OBJ_COFF || defined OBJ_ELF
2915 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2916#endif
6c43fab6 2917
c19d1205
ZW
2918 for (entry = 0; entry < pool->next_free_entry; entry ++)
2919 /* First output the expression in the instruction to the pool. */
2920 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2921
c19d1205
ZW
2922 /* Mark the pool as empty. */
2923 pool->next_free_entry = 0;
2924 pool->symbol = NULL;
b99bd4ef
NC
2925}
2926
c19d1205
ZW
2927#ifdef OBJ_ELF
2928/* Forward declarations for functions below, in the MD interface
2929 section. */
2930static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2931static valueT create_unwind_entry (int);
2932static void start_unwind_section (const segT, int);
2933static void add_unwind_opcode (valueT, int);
2934static void flush_pending_unwind (void);
b99bd4ef 2935
c19d1205 2936/* Directives: Data. */
b99bd4ef 2937
c19d1205
ZW
2938static void
2939s_arm_elf_cons (int nbytes)
2940{
2941 expressionS exp;
b99bd4ef 2942
c19d1205
ZW
2943#ifdef md_flush_pending_output
2944 md_flush_pending_output ();
2945#endif
b99bd4ef 2946
c19d1205 2947 if (is_it_end_of_statement ())
b99bd4ef 2948 {
c19d1205
ZW
2949 demand_empty_rest_of_line ();
2950 return;
b99bd4ef
NC
2951 }
2952
c19d1205
ZW
2953#ifdef md_cons_align
2954 md_cons_align (nbytes);
2955#endif
b99bd4ef 2956
c19d1205
ZW
2957 mapping_state (MAP_DATA);
2958 do
b99bd4ef 2959 {
c19d1205
ZW
2960 int reloc;
2961 char *base = input_line_pointer;
b99bd4ef 2962
c19d1205 2963 expression (& exp);
b99bd4ef 2964
c19d1205
ZW
2965 if (exp.X_op != O_symbol)
2966 emit_expr (&exp, (unsigned int) nbytes);
2967 else
2968 {
2969 char *before_reloc = input_line_pointer;
2970 reloc = parse_reloc (&input_line_pointer);
2971 if (reloc == -1)
2972 {
2973 as_bad (_("unrecognized relocation suffix"));
2974 ignore_rest_of_line ();
2975 return;
2976 }
2977 else if (reloc == BFD_RELOC_UNUSED)
2978 emit_expr (&exp, (unsigned int) nbytes);
2979 else
2980 {
2981 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2982 int size = bfd_get_reloc_size (howto);
b99bd4ef 2983
2fc8bdac
ZW
2984 if (reloc == BFD_RELOC_ARM_PLT32)
2985 {
2986 as_bad (_("(plt) is only valid on branch targets"));
2987 reloc = BFD_RELOC_UNUSED;
2988 size = 0;
2989 }
2990
c19d1205 2991 if (size > nbytes)
2fc8bdac 2992 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2993 howto->name, nbytes);
2994 else
2995 {
2996 /* We've parsed an expression stopping at O_symbol.
2997 But there may be more expression left now that we
2998 have parsed the relocation marker. Parse it again.
2999 XXX Surely there is a cleaner way to do this. */
3000 char *p = input_line_pointer;
3001 int offset;
3002 char *save_buf = alloca (input_line_pointer - base);
3003 memcpy (save_buf, base, input_line_pointer - base);
3004 memmove (base + (input_line_pointer - before_reloc),
3005 base, before_reloc - base);
3006
3007 input_line_pointer = base + (input_line_pointer-before_reloc);
3008 expression (&exp);
3009 memcpy (base, save_buf, p - base);
3010
3011 offset = nbytes - size;
3012 p = frag_more ((int) nbytes);
3013 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3014 size, &exp, 0, reloc);
3015 }
3016 }
3017 }
b99bd4ef 3018 }
c19d1205 3019 while (*input_line_pointer++ == ',');
b99bd4ef 3020
c19d1205
ZW
3021 /* Put terminator back into stream. */
3022 input_line_pointer --;
3023 demand_empty_rest_of_line ();
b99bd4ef
NC
3024}
3025
b99bd4ef 3026
c19d1205 3027/* Parse a .rel31 directive. */
b99bd4ef 3028
c19d1205
ZW
3029static void
3030s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3031{
3032 expressionS exp;
3033 char *p;
3034 valueT highbit;
b99bd4ef 3035
c19d1205
ZW
3036 highbit = 0;
3037 if (*input_line_pointer == '1')
3038 highbit = 0x80000000;
3039 else if (*input_line_pointer != '0')
3040 as_bad (_("expected 0 or 1"));
b99bd4ef 3041
c19d1205
ZW
3042 input_line_pointer++;
3043 if (*input_line_pointer != ',')
3044 as_bad (_("missing comma"));
3045 input_line_pointer++;
b99bd4ef 3046
c19d1205
ZW
3047#ifdef md_flush_pending_output
3048 md_flush_pending_output ();
3049#endif
b99bd4ef 3050
c19d1205
ZW
3051#ifdef md_cons_align
3052 md_cons_align (4);
3053#endif
b99bd4ef 3054
c19d1205 3055 mapping_state (MAP_DATA);
b99bd4ef 3056
c19d1205 3057 expression (&exp);
b99bd4ef 3058
c19d1205
ZW
3059 p = frag_more (4);
3060 md_number_to_chars (p, highbit, 4);
3061 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3062 BFD_RELOC_ARM_PREL31);
b99bd4ef 3063
c19d1205 3064 demand_empty_rest_of_line ();
b99bd4ef
NC
3065}
3066
c19d1205 3067/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3068
c19d1205 3069/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3070
c19d1205
ZW
3071static void
3072s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3073{
3074 demand_empty_rest_of_line ();
3075 /* Mark the start of the function. */
3076 unwind.proc_start = expr_build_dot ();
b99bd4ef 3077
c19d1205
ZW
3078 /* Reset the rest of the unwind info. */
3079 unwind.opcode_count = 0;
3080 unwind.table_entry = NULL;
3081 unwind.personality_routine = NULL;
3082 unwind.personality_index = -1;
3083 unwind.frame_size = 0;
3084 unwind.fp_offset = 0;
3085 unwind.fp_reg = 13;
3086 unwind.fp_used = 0;
3087 unwind.sp_restored = 0;
3088}
b99bd4ef 3089
b99bd4ef 3090
c19d1205
ZW
3091/* Parse a handlerdata directive. Creates the exception handling table entry
3092 for the function. */
b99bd4ef 3093
c19d1205
ZW
3094static void
3095s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3096{
3097 demand_empty_rest_of_line ();
3098 if (unwind.table_entry)
6decc662 3099 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3100
c19d1205
ZW
3101 create_unwind_entry (1);
3102}
a737bd4d 3103
c19d1205 3104/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3105
c19d1205
ZW
3106static void
3107s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3108{
3109 long where;
3110 char *ptr;
3111 valueT val;
f02232aa 3112
c19d1205 3113 demand_empty_rest_of_line ();
f02232aa 3114
c19d1205
ZW
3115 /* Add eh table entry. */
3116 if (unwind.table_entry == NULL)
3117 val = create_unwind_entry (0);
3118 else
3119 val = 0;
f02232aa 3120
c19d1205
ZW
3121 /* Add index table entry. This is two words. */
3122 start_unwind_section (unwind.saved_seg, 1);
3123 frag_align (2, 0, 0);
3124 record_alignment (now_seg, 2);
b99bd4ef 3125
c19d1205
ZW
3126 ptr = frag_more (8);
3127 where = frag_now_fix () - 8;
f02232aa 3128
c19d1205
ZW
3129 /* Self relative offset of the function start. */
3130 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3131 BFD_RELOC_ARM_PREL31);
f02232aa 3132
c19d1205
ZW
3133 /* Indicate dependency on EHABI-defined personality routines to the
3134 linker, if it hasn't been done already. */
3135 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3136 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3137 {
5f4273c7
NC
3138 static const char *const name[] =
3139 {
3140 "__aeabi_unwind_cpp_pr0",
3141 "__aeabi_unwind_cpp_pr1",
3142 "__aeabi_unwind_cpp_pr2"
3143 };
c19d1205
ZW
3144 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3145 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3146 marked_pr_dependency |= 1 << unwind.personality_index;
3147 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3148 = marked_pr_dependency;
3149 }
f02232aa 3150
c19d1205
ZW
3151 if (val)
3152 /* Inline exception table entry. */
3153 md_number_to_chars (ptr + 4, val, 4);
3154 else
3155 /* Self relative offset of the table entry. */
3156 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3157 BFD_RELOC_ARM_PREL31);
f02232aa 3158
c19d1205
ZW
3159 /* Restore the original section. */
3160 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3161}
f02232aa 3162
f02232aa 3163
c19d1205 3164/* Parse an unwind_cantunwind directive. */
b99bd4ef 3165
c19d1205
ZW
3166static void
3167s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3168{
3169 demand_empty_rest_of_line ();
3170 if (unwind.personality_routine || unwind.personality_index != -1)
3171 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3172
c19d1205
ZW
3173 unwind.personality_index = -2;
3174}
b99bd4ef 3175
b99bd4ef 3176
c19d1205 3177/* Parse a personalityindex directive. */
b99bd4ef 3178
c19d1205
ZW
3179static void
3180s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3181{
3182 expressionS exp;
b99bd4ef 3183
c19d1205
ZW
3184 if (unwind.personality_routine || unwind.personality_index != -1)
3185 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3186
c19d1205 3187 expression (&exp);
b99bd4ef 3188
c19d1205
ZW
3189 if (exp.X_op != O_constant
3190 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3191 {
c19d1205
ZW
3192 as_bad (_("bad personality routine number"));
3193 ignore_rest_of_line ();
3194 return;
b99bd4ef
NC
3195 }
3196
c19d1205 3197 unwind.personality_index = exp.X_add_number;
b99bd4ef 3198
c19d1205
ZW
3199 demand_empty_rest_of_line ();
3200}
e16bb312 3201
e16bb312 3202
c19d1205 3203/* Parse a personality directive. */
e16bb312 3204
c19d1205
ZW
3205static void
3206s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3207{
3208 char *name, *p, c;
a737bd4d 3209
c19d1205
ZW
3210 if (unwind.personality_routine || unwind.personality_index != -1)
3211 as_bad (_("duplicate .personality directive"));
a737bd4d 3212
c19d1205
ZW
3213 name = input_line_pointer;
3214 c = get_symbol_end ();
3215 p = input_line_pointer;
3216 unwind.personality_routine = symbol_find_or_make (name);
3217 *p = c;
3218 demand_empty_rest_of_line ();
3219}
e16bb312 3220
e16bb312 3221
c19d1205 3222/* Parse a directive saving core registers. */
e16bb312 3223
c19d1205
ZW
3224static void
3225s_arm_unwind_save_core (void)
e16bb312 3226{
c19d1205
ZW
3227 valueT op;
3228 long range;
3229 int n;
e16bb312 3230
c19d1205
ZW
3231 range = parse_reg_list (&input_line_pointer);
3232 if (range == FAIL)
e16bb312 3233 {
c19d1205
ZW
3234 as_bad (_("expected register list"));
3235 ignore_rest_of_line ();
3236 return;
3237 }
e16bb312 3238
c19d1205 3239 demand_empty_rest_of_line ();
e16bb312 3240
c19d1205
ZW
3241 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3242 into .unwind_save {..., sp...}. We aren't bothered about the value of
3243 ip because it is clobbered by calls. */
3244 if (unwind.sp_restored && unwind.fp_reg == 12
3245 && (range & 0x3000) == 0x1000)
3246 {
3247 unwind.opcode_count--;
3248 unwind.sp_restored = 0;
3249 range = (range | 0x2000) & ~0x1000;
3250 unwind.pending_offset = 0;
3251 }
e16bb312 3252
01ae4198
DJ
3253 /* Pop r4-r15. */
3254 if (range & 0xfff0)
c19d1205 3255 {
01ae4198
DJ
3256 /* See if we can use the short opcodes. These pop a block of up to 8
3257 registers starting with r4, plus maybe r14. */
3258 for (n = 0; n < 8; n++)
3259 {
3260 /* Break at the first non-saved register. */
3261 if ((range & (1 << (n + 4))) == 0)
3262 break;
3263 }
3264 /* See if there are any other bits set. */
3265 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3266 {
3267 /* Use the long form. */
3268 op = 0x8000 | ((range >> 4) & 0xfff);
3269 add_unwind_opcode (op, 2);
3270 }
0dd132b6 3271 else
01ae4198
DJ
3272 {
3273 /* Use the short form. */
3274 if (range & 0x4000)
3275 op = 0xa8; /* Pop r14. */
3276 else
3277 op = 0xa0; /* Do not pop r14. */
3278 op |= (n - 1);
3279 add_unwind_opcode (op, 1);
3280 }
c19d1205 3281 }
0dd132b6 3282
c19d1205
ZW
3283 /* Pop r0-r3. */
3284 if (range & 0xf)
3285 {
3286 op = 0xb100 | (range & 0xf);
3287 add_unwind_opcode (op, 2);
0dd132b6
NC
3288 }
3289
c19d1205
ZW
3290 /* Record the number of bytes pushed. */
3291 for (n = 0; n < 16; n++)
3292 {
3293 if (range & (1 << n))
3294 unwind.frame_size += 4;
3295 }
0dd132b6
NC
3296}
3297
c19d1205
ZW
3298
3299/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3300
3301static void
c19d1205 3302s_arm_unwind_save_fpa (int reg)
b99bd4ef 3303{
c19d1205
ZW
3304 expressionS exp;
3305 int num_regs;
3306 valueT op;
b99bd4ef 3307
c19d1205
ZW
3308 /* Get Number of registers to transfer. */
3309 if (skip_past_comma (&input_line_pointer) != FAIL)
3310 expression (&exp);
3311 else
3312 exp.X_op = O_illegal;
b99bd4ef 3313
c19d1205 3314 if (exp.X_op != O_constant)
b99bd4ef 3315 {
c19d1205
ZW
3316 as_bad (_("expected , <constant>"));
3317 ignore_rest_of_line ();
b99bd4ef
NC
3318 return;
3319 }
3320
c19d1205
ZW
3321 num_regs = exp.X_add_number;
3322
3323 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3324 {
c19d1205
ZW
3325 as_bad (_("number of registers must be in the range [1:4]"));
3326 ignore_rest_of_line ();
b99bd4ef
NC
3327 return;
3328 }
3329
c19d1205 3330 demand_empty_rest_of_line ();
b99bd4ef 3331
c19d1205
ZW
3332 if (reg == 4)
3333 {
3334 /* Short form. */
3335 op = 0xb4 | (num_regs - 1);
3336 add_unwind_opcode (op, 1);
3337 }
b99bd4ef
NC
3338 else
3339 {
c19d1205
ZW
3340 /* Long form. */
3341 op = 0xc800 | (reg << 4) | (num_regs - 1);
3342 add_unwind_opcode (op, 2);
b99bd4ef 3343 }
c19d1205 3344 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3345}
3346
c19d1205 3347
fa073d69
MS
3348/* Parse a directive saving VFP registers for ARMv6 and above. */
3349
3350static void
3351s_arm_unwind_save_vfp_armv6 (void)
3352{
3353 int count;
3354 unsigned int start;
3355 valueT op;
3356 int num_vfpv3_regs = 0;
3357 int num_regs_below_16;
3358
3359 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3360 if (count == FAIL)
3361 {
3362 as_bad (_("expected register list"));
3363 ignore_rest_of_line ();
3364 return;
3365 }
3366
3367 demand_empty_rest_of_line ();
3368
3369 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3370 than FSTMX/FLDMX-style ones). */
3371
3372 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3373 if (start >= 16)
3374 num_vfpv3_regs = count;
3375 else if (start + count > 16)
3376 num_vfpv3_regs = start + count - 16;
3377
3378 if (num_vfpv3_regs > 0)
3379 {
3380 int start_offset = start > 16 ? start - 16 : 0;
3381 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3382 add_unwind_opcode (op, 2);
3383 }
3384
3385 /* Generate opcode for registers numbered in the range 0 .. 15. */
3386 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3387 assert (num_regs_below_16 + num_vfpv3_regs == count);
3388 if (num_regs_below_16 > 0)
3389 {
3390 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3391 add_unwind_opcode (op, 2);
3392 }
3393
3394 unwind.frame_size += count * 8;
3395}
3396
3397
3398/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3399
3400static void
c19d1205 3401s_arm_unwind_save_vfp (void)
b99bd4ef 3402{
c19d1205 3403 int count;
ca3f61f7 3404 unsigned int reg;
c19d1205 3405 valueT op;
b99bd4ef 3406
5287ad62 3407 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3408 if (count == FAIL)
b99bd4ef 3409 {
c19d1205
ZW
3410 as_bad (_("expected register list"));
3411 ignore_rest_of_line ();
b99bd4ef
NC
3412 return;
3413 }
3414
c19d1205 3415 demand_empty_rest_of_line ();
b99bd4ef 3416
c19d1205 3417 if (reg == 8)
b99bd4ef 3418 {
c19d1205
ZW
3419 /* Short form. */
3420 op = 0xb8 | (count - 1);
3421 add_unwind_opcode (op, 1);
b99bd4ef 3422 }
c19d1205 3423 else
b99bd4ef 3424 {
c19d1205
ZW
3425 /* Long form. */
3426 op = 0xb300 | (reg << 4) | (count - 1);
3427 add_unwind_opcode (op, 2);
b99bd4ef 3428 }
c19d1205
ZW
3429 unwind.frame_size += count * 8 + 4;
3430}
b99bd4ef 3431
b99bd4ef 3432
c19d1205
ZW
3433/* Parse a directive saving iWMMXt data registers. */
3434
3435static void
3436s_arm_unwind_save_mmxwr (void)
3437{
3438 int reg;
3439 int hi_reg;
3440 int i;
3441 unsigned mask = 0;
3442 valueT op;
b99bd4ef 3443
c19d1205
ZW
3444 if (*input_line_pointer == '{')
3445 input_line_pointer++;
b99bd4ef 3446
c19d1205 3447 do
b99bd4ef 3448 {
dcbf9037 3449 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3450
c19d1205 3451 if (reg == FAIL)
b99bd4ef 3452 {
c19d1205
ZW
3453 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3454 goto error;
b99bd4ef
NC
3455 }
3456
c19d1205
ZW
3457 if (mask >> reg)
3458 as_tsktsk (_("register list not in ascending order"));
3459 mask |= 1 << reg;
b99bd4ef 3460
c19d1205
ZW
3461 if (*input_line_pointer == '-')
3462 {
3463 input_line_pointer++;
dcbf9037 3464 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3465 if (hi_reg == FAIL)
3466 {
3467 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3468 goto error;
3469 }
3470 else if (reg >= hi_reg)
3471 {
3472 as_bad (_("bad register range"));
3473 goto error;
3474 }
3475 for (; reg < hi_reg; reg++)
3476 mask |= 1 << reg;
3477 }
3478 }
3479 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3480
c19d1205
ZW
3481 if (*input_line_pointer == '}')
3482 input_line_pointer++;
b99bd4ef 3483
c19d1205 3484 demand_empty_rest_of_line ();
b99bd4ef 3485
708587a4 3486 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3487 the list. */
3488 flush_pending_unwind ();
b99bd4ef 3489
c19d1205 3490 for (i = 0; i < 16; i++)
b99bd4ef 3491 {
c19d1205
ZW
3492 if (mask & (1 << i))
3493 unwind.frame_size += 8;
b99bd4ef
NC
3494 }
3495
c19d1205
ZW
3496 /* Attempt to combine with a previous opcode. We do this because gcc
3497 likes to output separate unwind directives for a single block of
3498 registers. */
3499 if (unwind.opcode_count > 0)
b99bd4ef 3500 {
c19d1205
ZW
3501 i = unwind.opcodes[unwind.opcode_count - 1];
3502 if ((i & 0xf8) == 0xc0)
3503 {
3504 i &= 7;
3505 /* Only merge if the blocks are contiguous. */
3506 if (i < 6)
3507 {
3508 if ((mask & 0xfe00) == (1 << 9))
3509 {
3510 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3511 unwind.opcode_count--;
3512 }
3513 }
3514 else if (i == 6 && unwind.opcode_count >= 2)
3515 {
3516 i = unwind.opcodes[unwind.opcode_count - 2];
3517 reg = i >> 4;
3518 i &= 0xf;
b99bd4ef 3519
c19d1205
ZW
3520 op = 0xffff << (reg - 1);
3521 if (reg > 0
87a1fd79 3522 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3523 {
3524 op = (1 << (reg + i + 1)) - 1;
3525 op &= ~((1 << reg) - 1);
3526 mask |= op;
3527 unwind.opcode_count -= 2;
3528 }
3529 }
3530 }
b99bd4ef
NC
3531 }
3532
c19d1205
ZW
3533 hi_reg = 15;
3534 /* We want to generate opcodes in the order the registers have been
3535 saved, ie. descending order. */
3536 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3537 {
c19d1205
ZW
3538 /* Save registers in blocks. */
3539 if (reg < 0
3540 || !(mask & (1 << reg)))
3541 {
3542 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3543 preceding block. */
c19d1205
ZW
3544 if (reg != hi_reg)
3545 {
3546 if (reg == 9)
3547 {
3548 /* Short form. */
3549 op = 0xc0 | (hi_reg - 10);
3550 add_unwind_opcode (op, 1);
3551 }
3552 else
3553 {
3554 /* Long form. */
3555 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3556 add_unwind_opcode (op, 2);
3557 }
3558 }
3559 hi_reg = reg - 1;
3560 }
b99bd4ef
NC
3561 }
3562
c19d1205
ZW
3563 return;
3564error:
3565 ignore_rest_of_line ();
b99bd4ef
NC
3566}
3567
3568static void
c19d1205 3569s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3570{
c19d1205
ZW
3571 int reg;
3572 int hi_reg;
3573 unsigned mask = 0;
3574 valueT op;
b99bd4ef 3575
c19d1205
ZW
3576 if (*input_line_pointer == '{')
3577 input_line_pointer++;
b99bd4ef 3578
c19d1205 3579 do
b99bd4ef 3580 {
dcbf9037 3581 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3582
c19d1205
ZW
3583 if (reg == FAIL)
3584 {
3585 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3586 goto error;
3587 }
b99bd4ef 3588
c19d1205
ZW
3589 reg -= 8;
3590 if (mask >> reg)
3591 as_tsktsk (_("register list not in ascending order"));
3592 mask |= 1 << reg;
b99bd4ef 3593
c19d1205
ZW
3594 if (*input_line_pointer == '-')
3595 {
3596 input_line_pointer++;
dcbf9037 3597 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3598 if (hi_reg == FAIL)
3599 {
3600 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3601 goto error;
3602 }
3603 else if (reg >= hi_reg)
3604 {
3605 as_bad (_("bad register range"));
3606 goto error;
3607 }
3608 for (; reg < hi_reg; reg++)
3609 mask |= 1 << reg;
3610 }
b99bd4ef 3611 }
c19d1205 3612 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3613
c19d1205
ZW
3614 if (*input_line_pointer == '}')
3615 input_line_pointer++;
b99bd4ef 3616
c19d1205
ZW
3617 demand_empty_rest_of_line ();
3618
708587a4 3619 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3620 the list. */
3621 flush_pending_unwind ();
b99bd4ef 3622
c19d1205 3623 for (reg = 0; reg < 16; reg++)
b99bd4ef 3624 {
c19d1205
ZW
3625 if (mask & (1 << reg))
3626 unwind.frame_size += 4;
b99bd4ef 3627 }
c19d1205
ZW
3628 op = 0xc700 | mask;
3629 add_unwind_opcode (op, 2);
3630 return;
3631error:
3632 ignore_rest_of_line ();
b99bd4ef
NC
3633}
3634
c19d1205 3635
fa073d69
MS
3636/* Parse an unwind_save directive.
3637 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3638
b99bd4ef 3639static void
fa073d69 3640s_arm_unwind_save (int arch_v6)
b99bd4ef 3641{
c19d1205
ZW
3642 char *peek;
3643 struct reg_entry *reg;
3644 bfd_boolean had_brace = FALSE;
b99bd4ef 3645
c19d1205
ZW
3646 /* Figure out what sort of save we have. */
3647 peek = input_line_pointer;
b99bd4ef 3648
c19d1205 3649 if (*peek == '{')
b99bd4ef 3650 {
c19d1205
ZW
3651 had_brace = TRUE;
3652 peek++;
b99bd4ef
NC
3653 }
3654
c19d1205 3655 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3656
c19d1205 3657 if (!reg)
b99bd4ef 3658 {
c19d1205
ZW
3659 as_bad (_("register expected"));
3660 ignore_rest_of_line ();
b99bd4ef
NC
3661 return;
3662 }
3663
c19d1205 3664 switch (reg->type)
b99bd4ef 3665 {
c19d1205
ZW
3666 case REG_TYPE_FN:
3667 if (had_brace)
3668 {
3669 as_bad (_("FPA .unwind_save does not take a register list"));
3670 ignore_rest_of_line ();
3671 return;
3672 }
93ac2687 3673 input_line_pointer = peek;
c19d1205 3674 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3675 return;
c19d1205
ZW
3676
3677 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3678 case REG_TYPE_VFD:
3679 if (arch_v6)
3680 s_arm_unwind_save_vfp_armv6 ();
3681 else
3682 s_arm_unwind_save_vfp ();
3683 return;
c19d1205
ZW
3684 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3685 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3686
3687 default:
3688 as_bad (_(".unwind_save does not support this kind of register"));
3689 ignore_rest_of_line ();
b99bd4ef 3690 }
c19d1205 3691}
b99bd4ef 3692
b99bd4ef 3693
c19d1205
ZW
3694/* Parse an unwind_movsp directive. */
3695
3696static void
3697s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3698{
3699 int reg;
3700 valueT op;
4fa3602b 3701 int offset;
c19d1205 3702
dcbf9037 3703 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3704 if (reg == FAIL)
b99bd4ef 3705 {
c19d1205
ZW
3706 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3707 ignore_rest_of_line ();
b99bd4ef
NC
3708 return;
3709 }
4fa3602b
PB
3710
3711 /* Optional constant. */
3712 if (skip_past_comma (&input_line_pointer) != FAIL)
3713 {
3714 if (immediate_for_directive (&offset) == FAIL)
3715 return;
3716 }
3717 else
3718 offset = 0;
3719
c19d1205 3720 demand_empty_rest_of_line ();
b99bd4ef 3721
c19d1205 3722 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3723 {
c19d1205 3724 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3725 return;
3726 }
3727
c19d1205
ZW
3728 if (unwind.fp_reg != REG_SP)
3729 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3730
c19d1205
ZW
3731 /* Generate opcode to restore the value. */
3732 op = 0x90 | reg;
3733 add_unwind_opcode (op, 1);
3734
3735 /* Record the information for later. */
3736 unwind.fp_reg = reg;
4fa3602b 3737 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3738 unwind.sp_restored = 1;
b05fe5cf
ZW
3739}
3740
c19d1205
ZW
3741/* Parse an unwind_pad directive. */
3742
b05fe5cf 3743static void
c19d1205 3744s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3745{
c19d1205 3746 int offset;
b05fe5cf 3747
c19d1205
ZW
3748 if (immediate_for_directive (&offset) == FAIL)
3749 return;
b99bd4ef 3750
c19d1205
ZW
3751 if (offset & 3)
3752 {
3753 as_bad (_("stack increment must be multiple of 4"));
3754 ignore_rest_of_line ();
3755 return;
3756 }
b99bd4ef 3757
c19d1205
ZW
3758 /* Don't generate any opcodes, just record the details for later. */
3759 unwind.frame_size += offset;
3760 unwind.pending_offset += offset;
3761
3762 demand_empty_rest_of_line ();
3763}
3764
3765/* Parse an unwind_setfp directive. */
3766
3767static void
3768s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3769{
c19d1205
ZW
3770 int sp_reg;
3771 int fp_reg;
3772 int offset;
3773
dcbf9037 3774 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3775 if (skip_past_comma (&input_line_pointer) == FAIL)
3776 sp_reg = FAIL;
3777 else
dcbf9037 3778 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3779
c19d1205
ZW
3780 if (fp_reg == FAIL || sp_reg == FAIL)
3781 {
3782 as_bad (_("expected <reg>, <reg>"));
3783 ignore_rest_of_line ();
3784 return;
3785 }
b99bd4ef 3786
c19d1205
ZW
3787 /* Optional constant. */
3788 if (skip_past_comma (&input_line_pointer) != FAIL)
3789 {
3790 if (immediate_for_directive (&offset) == FAIL)
3791 return;
3792 }
3793 else
3794 offset = 0;
a737bd4d 3795
c19d1205 3796 demand_empty_rest_of_line ();
a737bd4d 3797
c19d1205 3798 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3799 {
c19d1205
ZW
3800 as_bad (_("register must be either sp or set by a previous"
3801 "unwind_movsp directive"));
3802 return;
a737bd4d
NC
3803 }
3804
c19d1205
ZW
3805 /* Don't generate any opcodes, just record the information for later. */
3806 unwind.fp_reg = fp_reg;
3807 unwind.fp_used = 1;
3808 if (sp_reg == 13)
3809 unwind.fp_offset = unwind.frame_size - offset;
3810 else
3811 unwind.fp_offset -= offset;
a737bd4d
NC
3812}
3813
c19d1205
ZW
3814/* Parse an unwind_raw directive. */
3815
3816static void
3817s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3818{
c19d1205 3819 expressionS exp;
708587a4 3820 /* This is an arbitrary limit. */
c19d1205
ZW
3821 unsigned char op[16];
3822 int count;
a737bd4d 3823
c19d1205
ZW
3824 expression (&exp);
3825 if (exp.X_op == O_constant
3826 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3827 {
c19d1205
ZW
3828 unwind.frame_size += exp.X_add_number;
3829 expression (&exp);
3830 }
3831 else
3832 exp.X_op = O_illegal;
a737bd4d 3833
c19d1205
ZW
3834 if (exp.X_op != O_constant)
3835 {
3836 as_bad (_("expected <offset>, <opcode>"));
3837 ignore_rest_of_line ();
3838 return;
3839 }
a737bd4d 3840
c19d1205 3841 count = 0;
a737bd4d 3842
c19d1205
ZW
3843 /* Parse the opcode. */
3844 for (;;)
3845 {
3846 if (count >= 16)
3847 {
3848 as_bad (_("unwind opcode too long"));
3849 ignore_rest_of_line ();
a737bd4d 3850 }
c19d1205 3851 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3852 {
c19d1205
ZW
3853 as_bad (_("invalid unwind opcode"));
3854 ignore_rest_of_line ();
3855 return;
a737bd4d 3856 }
c19d1205 3857 op[count++] = exp.X_add_number;
a737bd4d 3858
c19d1205
ZW
3859 /* Parse the next byte. */
3860 if (skip_past_comma (&input_line_pointer) == FAIL)
3861 break;
a737bd4d 3862
c19d1205
ZW
3863 expression (&exp);
3864 }
b99bd4ef 3865
c19d1205
ZW
3866 /* Add the opcode bytes in reverse order. */
3867 while (count--)
3868 add_unwind_opcode (op[count], 1);
b99bd4ef 3869
c19d1205 3870 demand_empty_rest_of_line ();
b99bd4ef 3871}
ee065d83
PB
3872
3873
3874/* Parse a .eabi_attribute directive. */
3875
3876static void
3877s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3878{
104d59d1 3879 s_vendor_attribute (OBJ_ATTR_PROC);
ee065d83 3880}
8463be01 3881#endif /* OBJ_ELF */
ee065d83
PB
3882
3883static void s_arm_arch (int);
7a1d4c38 3884static void s_arm_object_arch (int);
ee065d83
PB
3885static void s_arm_cpu (int);
3886static void s_arm_fpu (int);
b99bd4ef 3887
f0927246
NC
3888#ifdef TE_PE
3889
3890static void
5f4273c7 3891pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
3892{
3893 expressionS exp;
3894
3895 do
3896 {
3897 expression (&exp);
3898 if (exp.X_op == O_symbol)
3899 exp.X_op = O_secrel;
3900
3901 emit_expr (&exp, 4);
3902 }
3903 while (*input_line_pointer++ == ',');
3904
3905 input_line_pointer--;
3906 demand_empty_rest_of_line ();
3907}
3908#endif /* TE_PE */
3909
c19d1205
ZW
3910/* This table describes all the machine specific pseudo-ops the assembler
3911 has to support. The fields are:
3912 pseudo-op name without dot
3913 function to call to execute this pseudo-op
3914 Integer arg to pass to the function. */
b99bd4ef 3915
c19d1205 3916const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3917{
c19d1205
ZW
3918 /* Never called because '.req' does not start a line. */
3919 { "req", s_req, 0 },
dcbf9037
JB
3920 /* Following two are likewise never called. */
3921 { "dn", s_dn, 0 },
3922 { "qn", s_qn, 0 },
c19d1205
ZW
3923 { "unreq", s_unreq, 0 },
3924 { "bss", s_bss, 0 },
3925 { "align", s_align, 0 },
3926 { "arm", s_arm, 0 },
3927 { "thumb", s_thumb, 0 },
3928 { "code", s_code, 0 },
3929 { "force_thumb", s_force_thumb, 0 },
3930 { "thumb_func", s_thumb_func, 0 },
3931 { "thumb_set", s_thumb_set, 0 },
3932 { "even", s_even, 0 },
3933 { "ltorg", s_ltorg, 0 },
3934 { "pool", s_ltorg, 0 },
3935 { "syntax", s_syntax, 0 },
8463be01
PB
3936 { "cpu", s_arm_cpu, 0 },
3937 { "arch", s_arm_arch, 0 },
7a1d4c38 3938 { "object_arch", s_arm_object_arch, 0 },
8463be01 3939 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3940#ifdef OBJ_ELF
3941 { "word", s_arm_elf_cons, 4 },
3942 { "long", s_arm_elf_cons, 4 },
3943 { "rel31", s_arm_rel31, 0 },
3944 { "fnstart", s_arm_unwind_fnstart, 0 },
3945 { "fnend", s_arm_unwind_fnend, 0 },
3946 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3947 { "personality", s_arm_unwind_personality, 0 },
3948 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3949 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3950 { "save", s_arm_unwind_save, 0 },
fa073d69 3951 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3952 { "movsp", s_arm_unwind_movsp, 0 },
3953 { "pad", s_arm_unwind_pad, 0 },
3954 { "setfp", s_arm_unwind_setfp, 0 },
3955 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3956 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3957#else
3958 { "word", cons, 4},
f0927246
NC
3959
3960 /* These are used for dwarf. */
3961 {"2byte", cons, 2},
3962 {"4byte", cons, 4},
3963 {"8byte", cons, 8},
3964 /* These are used for dwarf2. */
3965 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3966 { "loc", dwarf2_directive_loc, 0 },
3967 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3968#endif
3969 { "extend", float_cons, 'x' },
3970 { "ldouble", float_cons, 'x' },
3971 { "packed", float_cons, 'p' },
f0927246
NC
3972#ifdef TE_PE
3973 {"secrel32", pe_directive_secrel, 0},
3974#endif
c19d1205
ZW
3975 { 0, 0, 0 }
3976};
3977\f
3978/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3979
c19d1205
ZW
3980/* Generic immediate-value read function for use in insn parsing.
3981 STR points to the beginning of the immediate (the leading #);
3982 VAL receives the value; if the value is outside [MIN, MAX]
3983 issue an error. PREFIX_OPT is true if the immediate prefix is
3984 optional. */
b99bd4ef 3985
c19d1205
ZW
3986static int
3987parse_immediate (char **str, int *val, int min, int max,
3988 bfd_boolean prefix_opt)
3989{
3990 expressionS exp;
3991 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3992 if (exp.X_op != O_constant)
b99bd4ef 3993 {
c19d1205
ZW
3994 inst.error = _("constant expression required");
3995 return FAIL;
3996 }
b99bd4ef 3997
c19d1205
ZW
3998 if (exp.X_add_number < min || exp.X_add_number > max)
3999 {
4000 inst.error = _("immediate value out of range");
4001 return FAIL;
4002 }
b99bd4ef 4003
c19d1205
ZW
4004 *val = exp.X_add_number;
4005 return SUCCESS;
4006}
b99bd4ef 4007
5287ad62 4008/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4009 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4010 instructions. Puts the result directly in inst.operands[i]. */
4011
4012static int
4013parse_big_immediate (char **str, int i)
4014{
4015 expressionS exp;
4016 char *ptr = *str;
4017
4018 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4019
4020 if (exp.X_op == O_constant)
036dc3f7
PB
4021 {
4022 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4023 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4024 O_constant. We have to be careful not to break compilation for
4025 32-bit X_add_number, though. */
4026 if ((exp.X_add_number & ~0xffffffffl) != 0)
4027 {
4028 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4029 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4030 inst.operands[i].regisimm = 1;
4031 }
4032 }
5287ad62
JB
4033 else if (exp.X_op == O_big
4034 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4035 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4036 {
4037 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4038 /* Bignums have their least significant bits in
4039 generic_bignum[0]. Make sure we put 32 bits in imm and
4040 32 bits in reg, in a (hopefully) portable way. */
4041 assert (parts != 0);
4042 inst.operands[i].imm = 0;
4043 for (j = 0; j < parts; j++, idx++)
4044 inst.operands[i].imm |= generic_bignum[idx]
4045 << (LITTLENUM_NUMBER_OF_BITS * j);
4046 inst.operands[i].reg = 0;
4047 for (j = 0; j < parts; j++, idx++)
4048 inst.operands[i].reg |= generic_bignum[idx]
4049 << (LITTLENUM_NUMBER_OF_BITS * j);
4050 inst.operands[i].regisimm = 1;
4051 }
4052 else
4053 return FAIL;
5f4273c7 4054
5287ad62
JB
4055 *str = ptr;
4056
4057 return SUCCESS;
4058}
4059
c19d1205
ZW
4060/* Returns the pseudo-register number of an FPA immediate constant,
4061 or FAIL if there isn't a valid constant here. */
b99bd4ef 4062
c19d1205
ZW
4063static int
4064parse_fpa_immediate (char ** str)
4065{
4066 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4067 char * save_in;
4068 expressionS exp;
4069 int i;
4070 int j;
b99bd4ef 4071
c19d1205
ZW
4072 /* First try and match exact strings, this is to guarantee
4073 that some formats will work even for cross assembly. */
b99bd4ef 4074
c19d1205
ZW
4075 for (i = 0; fp_const[i]; i++)
4076 {
4077 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4078 {
c19d1205 4079 char *start = *str;
b99bd4ef 4080
c19d1205
ZW
4081 *str += strlen (fp_const[i]);
4082 if (is_end_of_line[(unsigned char) **str])
4083 return i + 8;
4084 *str = start;
4085 }
4086 }
b99bd4ef 4087
c19d1205
ZW
4088 /* Just because we didn't get a match doesn't mean that the constant
4089 isn't valid, just that it is in a format that we don't
4090 automatically recognize. Try parsing it with the standard
4091 expression routines. */
b99bd4ef 4092
c19d1205 4093 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4094
c19d1205
ZW
4095 /* Look for a raw floating point number. */
4096 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4097 && is_end_of_line[(unsigned char) *save_in])
4098 {
4099 for (i = 0; i < NUM_FLOAT_VALS; i++)
4100 {
4101 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4102 {
c19d1205
ZW
4103 if (words[j] != fp_values[i][j])
4104 break;
b99bd4ef
NC
4105 }
4106
c19d1205 4107 if (j == MAX_LITTLENUMS)
b99bd4ef 4108 {
c19d1205
ZW
4109 *str = save_in;
4110 return i + 8;
b99bd4ef
NC
4111 }
4112 }
4113 }
b99bd4ef 4114
c19d1205
ZW
4115 /* Try and parse a more complex expression, this will probably fail
4116 unless the code uses a floating point prefix (eg "0f"). */
4117 save_in = input_line_pointer;
4118 input_line_pointer = *str;
4119 if (expression (&exp) == absolute_section
4120 && exp.X_op == O_big
4121 && exp.X_add_number < 0)
4122 {
4123 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4124 Ditto for 15. */
4125 if (gen_to_words (words, 5, (long) 15) == 0)
4126 {
4127 for (i = 0; i < NUM_FLOAT_VALS; i++)
4128 {
4129 for (j = 0; j < MAX_LITTLENUMS; j++)
4130 {
4131 if (words[j] != fp_values[i][j])
4132 break;
4133 }
b99bd4ef 4134
c19d1205
ZW
4135 if (j == MAX_LITTLENUMS)
4136 {
4137 *str = input_line_pointer;
4138 input_line_pointer = save_in;
4139 return i + 8;
4140 }
4141 }
4142 }
b99bd4ef
NC
4143 }
4144
c19d1205
ZW
4145 *str = input_line_pointer;
4146 input_line_pointer = save_in;
4147 inst.error = _("invalid FPA immediate expression");
4148 return FAIL;
b99bd4ef
NC
4149}
4150
136da414
JB
4151/* Returns 1 if a number has "quarter-precision" float format
4152 0baBbbbbbc defgh000 00000000 00000000. */
4153
4154static int
4155is_quarter_float (unsigned imm)
4156{
4157 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4158 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4159}
4160
4161/* Parse an 8-bit "quarter-precision" floating point number of the form:
4162 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4163 The zero and minus-zero cases need special handling, since they can't be
4164 encoded in the "quarter-precision" float format, but can nonetheless be
4165 loaded as integer constants. */
136da414
JB
4166
4167static unsigned
4168parse_qfloat_immediate (char **ccp, int *immed)
4169{
4170 char *str = *ccp;
c96612cc 4171 char *fpnum;
136da414 4172 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4173 int found_fpchar = 0;
5f4273c7 4174
136da414 4175 skip_past_char (&str, '#');
5f4273c7 4176
c96612cc
JB
4177 /* We must not accidentally parse an integer as a floating-point number. Make
4178 sure that the value we parse is not an integer by checking for special
4179 characters '.' or 'e'.
4180 FIXME: This is a horrible hack, but doing better is tricky because type
4181 information isn't in a very usable state at parse time. */
4182 fpnum = str;
4183 skip_whitespace (fpnum);
4184
4185 if (strncmp (fpnum, "0x", 2) == 0)
4186 return FAIL;
4187 else
4188 {
4189 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4190 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4191 {
4192 found_fpchar = 1;
4193 break;
4194 }
4195
4196 if (!found_fpchar)
4197 return FAIL;
4198 }
5f4273c7 4199
136da414
JB
4200 if ((str = atof_ieee (str, 's', words)) != NULL)
4201 {
4202 unsigned fpword = 0;
4203 int i;
5f4273c7 4204
136da414
JB
4205 /* Our FP word must be 32 bits (single-precision FP). */
4206 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4207 {
4208 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4209 fpword |= words[i];
4210 }
5f4273c7 4211
c96612cc 4212 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4213 *immed = fpword;
4214 else
4215 return FAIL;
4216
4217 *ccp = str;
5f4273c7 4218
136da414
JB
4219 return SUCCESS;
4220 }
5f4273c7 4221
136da414
JB
4222 return FAIL;
4223}
4224
c19d1205
ZW
4225/* Shift operands. */
4226enum shift_kind
b99bd4ef 4227{
c19d1205
ZW
4228 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4229};
b99bd4ef 4230
c19d1205
ZW
4231struct asm_shift_name
4232{
4233 const char *name;
4234 enum shift_kind kind;
4235};
b99bd4ef 4236
c19d1205
ZW
4237/* Third argument to parse_shift. */
4238enum parse_shift_mode
4239{
4240 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4241 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4242 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4243 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4244 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4245};
b99bd4ef 4246
c19d1205
ZW
4247/* Parse a <shift> specifier on an ARM data processing instruction.
4248 This has three forms:
b99bd4ef 4249
c19d1205
ZW
4250 (LSL|LSR|ASL|ASR|ROR) Rs
4251 (LSL|LSR|ASL|ASR|ROR) #imm
4252 RRX
b99bd4ef 4253
c19d1205
ZW
4254 Note that ASL is assimilated to LSL in the instruction encoding, and
4255 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4256
c19d1205
ZW
4257static int
4258parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4259{
c19d1205
ZW
4260 const struct asm_shift_name *shift_name;
4261 enum shift_kind shift;
4262 char *s = *str;
4263 char *p = s;
4264 int reg;
b99bd4ef 4265
c19d1205
ZW
4266 for (p = *str; ISALPHA (*p); p++)
4267 ;
b99bd4ef 4268
c19d1205 4269 if (p == *str)
b99bd4ef 4270 {
c19d1205
ZW
4271 inst.error = _("shift expression expected");
4272 return FAIL;
b99bd4ef
NC
4273 }
4274
c19d1205
ZW
4275 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4276
4277 if (shift_name == NULL)
b99bd4ef 4278 {
c19d1205
ZW
4279 inst.error = _("shift expression expected");
4280 return FAIL;
b99bd4ef
NC
4281 }
4282
c19d1205 4283 shift = shift_name->kind;
b99bd4ef 4284
c19d1205
ZW
4285 switch (mode)
4286 {
4287 case NO_SHIFT_RESTRICT:
4288 case SHIFT_IMMEDIATE: break;
b99bd4ef 4289
c19d1205
ZW
4290 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4291 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4292 {
4293 inst.error = _("'LSL' or 'ASR' required");
4294 return FAIL;
4295 }
4296 break;
b99bd4ef 4297
c19d1205
ZW
4298 case SHIFT_LSL_IMMEDIATE:
4299 if (shift != SHIFT_LSL)
4300 {
4301 inst.error = _("'LSL' required");
4302 return FAIL;
4303 }
4304 break;
b99bd4ef 4305
c19d1205
ZW
4306 case SHIFT_ASR_IMMEDIATE:
4307 if (shift != SHIFT_ASR)
4308 {
4309 inst.error = _("'ASR' required");
4310 return FAIL;
4311 }
4312 break;
b99bd4ef 4313
c19d1205
ZW
4314 default: abort ();
4315 }
b99bd4ef 4316
c19d1205
ZW
4317 if (shift != SHIFT_RRX)
4318 {
4319 /* Whitespace can appear here if the next thing is a bare digit. */
4320 skip_whitespace (p);
b99bd4ef 4321
c19d1205 4322 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4323 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4324 {
4325 inst.operands[i].imm = reg;
4326 inst.operands[i].immisreg = 1;
4327 }
4328 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4329 return FAIL;
4330 }
4331 inst.operands[i].shift_kind = shift;
4332 inst.operands[i].shifted = 1;
4333 *str = p;
4334 return SUCCESS;
b99bd4ef
NC
4335}
4336
c19d1205 4337/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4338
c19d1205
ZW
4339 #<immediate>
4340 #<immediate>, <rotate>
4341 <Rm>
4342 <Rm>, <shift>
b99bd4ef 4343
c19d1205
ZW
4344 where <shift> is defined by parse_shift above, and <rotate> is a
4345 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4346 is deferred to md_apply_fix. */
b99bd4ef 4347
c19d1205
ZW
4348static int
4349parse_shifter_operand (char **str, int i)
4350{
4351 int value;
4352 expressionS expr;
b99bd4ef 4353
dcbf9037 4354 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4355 {
4356 inst.operands[i].reg = value;
4357 inst.operands[i].isreg = 1;
b99bd4ef 4358
c19d1205
ZW
4359 /* parse_shift will override this if appropriate */
4360 inst.reloc.exp.X_op = O_constant;
4361 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4362
c19d1205
ZW
4363 if (skip_past_comma (str) == FAIL)
4364 return SUCCESS;
b99bd4ef 4365
c19d1205
ZW
4366 /* Shift operation on register. */
4367 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4368 }
4369
c19d1205
ZW
4370 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4371 return FAIL;
b99bd4ef 4372
c19d1205 4373 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4374 {
c19d1205
ZW
4375 /* #x, y -- ie explicit rotation by Y. */
4376 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4377 return FAIL;
b99bd4ef 4378
c19d1205
ZW
4379 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4380 {
4381 inst.error = _("constant expression expected");
4382 return FAIL;
4383 }
b99bd4ef 4384
c19d1205
ZW
4385 value = expr.X_add_number;
4386 if (value < 0 || value > 30 || value % 2 != 0)
4387 {
4388 inst.error = _("invalid rotation");
4389 return FAIL;
4390 }
4391 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4392 {
4393 inst.error = _("invalid constant");
4394 return FAIL;
4395 }
09d92015 4396
55cf6793 4397 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4398 inst.reloc.exp.X_add_number
4399 = (((inst.reloc.exp.X_add_number << (32 - value))
4400 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4401 }
4402
c19d1205
ZW
4403 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4404 inst.reloc.pc_rel = 0;
4405 return SUCCESS;
09d92015
MM
4406}
4407
4962c51a
MS
4408/* Group relocation information. Each entry in the table contains the
4409 textual name of the relocation as may appear in assembler source
4410 and must end with a colon.
4411 Along with this textual name are the relocation codes to be used if
4412 the corresponding instruction is an ALU instruction (ADD or SUB only),
4413 an LDR, an LDRS, or an LDC. */
4414
4415struct group_reloc_table_entry
4416{
4417 const char *name;
4418 int alu_code;
4419 int ldr_code;
4420 int ldrs_code;
4421 int ldc_code;
4422};
4423
4424typedef enum
4425{
4426 /* Varieties of non-ALU group relocation. */
4427
4428 GROUP_LDR,
4429 GROUP_LDRS,
4430 GROUP_LDC
4431} group_reloc_type;
4432
4433static struct group_reloc_table_entry group_reloc_table[] =
4434 { /* Program counter relative: */
4435 { "pc_g0_nc",
4436 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4437 0, /* LDR */
4438 0, /* LDRS */
4439 0 }, /* LDC */
4440 { "pc_g0",
4441 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4442 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4443 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4444 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4445 { "pc_g1_nc",
4446 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4447 0, /* LDR */
4448 0, /* LDRS */
4449 0 }, /* LDC */
4450 { "pc_g1",
4451 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4452 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4453 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4454 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4455 { "pc_g2",
4456 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4457 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4458 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4459 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4460 /* Section base relative */
4461 { "sb_g0_nc",
4462 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4463 0, /* LDR */
4464 0, /* LDRS */
4465 0 }, /* LDC */
4466 { "sb_g0",
4467 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4468 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4469 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4470 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4471 { "sb_g1_nc",
4472 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4473 0, /* LDR */
4474 0, /* LDRS */
4475 0 }, /* LDC */
4476 { "sb_g1",
4477 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4478 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4479 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4480 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4481 { "sb_g2",
4482 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4483 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4484 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4485 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4486
4487/* Given the address of a pointer pointing to the textual name of a group
4488 relocation as may appear in assembler source, attempt to find its details
4489 in group_reloc_table. The pointer will be updated to the character after
4490 the trailing colon. On failure, FAIL will be returned; SUCCESS
4491 otherwise. On success, *entry will be updated to point at the relevant
4492 group_reloc_table entry. */
4493
4494static int
4495find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4496{
4497 unsigned int i;
4498 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4499 {
4500 int length = strlen (group_reloc_table[i].name);
4501
5f4273c7
NC
4502 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4503 && (*str)[length] == ':')
4962c51a
MS
4504 {
4505 *out = &group_reloc_table[i];
4506 *str += (length + 1);
4507 return SUCCESS;
4508 }
4509 }
4510
4511 return FAIL;
4512}
4513
4514/* Parse a <shifter_operand> for an ARM data processing instruction
4515 (as for parse_shifter_operand) where group relocations are allowed:
4516
4517 #<immediate>
4518 #<immediate>, <rotate>
4519 #:<group_reloc>:<expression>
4520 <Rm>
4521 <Rm>, <shift>
4522
4523 where <group_reloc> is one of the strings defined in group_reloc_table.
4524 The hashes are optional.
4525
4526 Everything else is as for parse_shifter_operand. */
4527
4528static parse_operand_result
4529parse_shifter_operand_group_reloc (char **str, int i)
4530{
4531 /* Determine if we have the sequence of characters #: or just :
4532 coming next. If we do, then we check for a group relocation.
4533 If we don't, punt the whole lot to parse_shifter_operand. */
4534
4535 if (((*str)[0] == '#' && (*str)[1] == ':')
4536 || (*str)[0] == ':')
4537 {
4538 struct group_reloc_table_entry *entry;
4539
4540 if ((*str)[0] == '#')
4541 (*str) += 2;
4542 else
4543 (*str)++;
4544
4545 /* Try to parse a group relocation. Anything else is an error. */
4546 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4547 {
4548 inst.error = _("unknown group relocation");
4549 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4550 }
4551
4552 /* We now have the group relocation table entry corresponding to
4553 the name in the assembler source. Next, we parse the expression. */
4554 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4555 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4556
4557 /* Record the relocation type (always the ALU variant here). */
4558 inst.reloc.type = entry->alu_code;
4559 assert (inst.reloc.type != 0);
4560
4561 return PARSE_OPERAND_SUCCESS;
4562 }
4563 else
4564 return parse_shifter_operand (str, i) == SUCCESS
4565 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4566
4567 /* Never reached. */
4568}
4569
c19d1205
ZW
4570/* Parse all forms of an ARM address expression. Information is written
4571 to inst.operands[i] and/or inst.reloc.
09d92015 4572
c19d1205 4573 Preindexed addressing (.preind=1):
09d92015 4574
c19d1205
ZW
4575 [Rn, #offset] .reg=Rn .reloc.exp=offset
4576 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4577 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4578 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4579
c19d1205 4580 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4581
c19d1205 4582 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4583
c19d1205
ZW
4584 [Rn], #offset .reg=Rn .reloc.exp=offset
4585 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4586 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4587 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4588
c19d1205 4589 Unindexed addressing (.preind=0, .postind=0):
09d92015 4590
c19d1205 4591 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4592
c19d1205 4593 Other:
09d92015 4594
c19d1205
ZW
4595 [Rn]{!} shorthand for [Rn,#0]{!}
4596 =immediate .isreg=0 .reloc.exp=immediate
4597 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4598
c19d1205
ZW
4599 It is the caller's responsibility to check for addressing modes not
4600 supported by the instruction, and to set inst.reloc.type. */
4601
4962c51a
MS
4602static parse_operand_result
4603parse_address_main (char **str, int i, int group_relocations,
4604 group_reloc_type group_type)
09d92015 4605{
c19d1205
ZW
4606 char *p = *str;
4607 int reg;
09d92015 4608
c19d1205 4609 if (skip_past_char (&p, '[') == FAIL)
09d92015 4610 {
c19d1205
ZW
4611 if (skip_past_char (&p, '=') == FAIL)
4612 {
4613 /* bare address - translate to PC-relative offset */
4614 inst.reloc.pc_rel = 1;
4615 inst.operands[i].reg = REG_PC;
4616 inst.operands[i].isreg = 1;
4617 inst.operands[i].preind = 1;
4618 }
4619 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4620
c19d1205 4621 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4622 return PARSE_OPERAND_FAIL;
09d92015 4623
c19d1205 4624 *str = p;
4962c51a 4625 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4626 }
4627
dcbf9037 4628 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4629 {
c19d1205 4630 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4631 return PARSE_OPERAND_FAIL;
09d92015 4632 }
c19d1205
ZW
4633 inst.operands[i].reg = reg;
4634 inst.operands[i].isreg = 1;
09d92015 4635
c19d1205 4636 if (skip_past_comma (&p) == SUCCESS)
09d92015 4637 {
c19d1205 4638 inst.operands[i].preind = 1;
09d92015 4639
c19d1205
ZW
4640 if (*p == '+') p++;
4641 else if (*p == '-') p++, inst.operands[i].negative = 1;
4642
dcbf9037 4643 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4644 {
c19d1205
ZW
4645 inst.operands[i].imm = reg;
4646 inst.operands[i].immisreg = 1;
4647
4648 if (skip_past_comma (&p) == SUCCESS)
4649 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4650 return PARSE_OPERAND_FAIL;
c19d1205 4651 }
5287ad62
JB
4652 else if (skip_past_char (&p, ':') == SUCCESS)
4653 {
4654 /* FIXME: '@' should be used here, but it's filtered out by generic
4655 code before we get to see it here. This may be subject to
4656 change. */
4657 expressionS exp;
4658 my_get_expression (&exp, &p, GE_NO_PREFIX);
4659 if (exp.X_op != O_constant)
4660 {
4661 inst.error = _("alignment must be constant");
4962c51a 4662 return PARSE_OPERAND_FAIL;
5287ad62
JB
4663 }
4664 inst.operands[i].imm = exp.X_add_number << 8;
4665 inst.operands[i].immisalign = 1;
4666 /* Alignments are not pre-indexes. */
4667 inst.operands[i].preind = 0;
4668 }
c19d1205
ZW
4669 else
4670 {
4671 if (inst.operands[i].negative)
4672 {
4673 inst.operands[i].negative = 0;
4674 p--;
4675 }
4962c51a 4676
5f4273c7
NC
4677 if (group_relocations
4678 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4679 {
4680 struct group_reloc_table_entry *entry;
4681
4682 /* Skip over the #: or : sequence. */
4683 if (*p == '#')
4684 p += 2;
4685 else
4686 p++;
4687
4688 /* Try to parse a group relocation. Anything else is an
4689 error. */
4690 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4691 {
4692 inst.error = _("unknown group relocation");
4693 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4694 }
4695
4696 /* We now have the group relocation table entry corresponding to
4697 the name in the assembler source. Next, we parse the
4698 expression. */
4699 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4700 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4701
4702 /* Record the relocation type. */
4703 switch (group_type)
4704 {
4705 case GROUP_LDR:
4706 inst.reloc.type = entry->ldr_code;
4707 break;
4708
4709 case GROUP_LDRS:
4710 inst.reloc.type = entry->ldrs_code;
4711 break;
4712
4713 case GROUP_LDC:
4714 inst.reloc.type = entry->ldc_code;
4715 break;
4716
4717 default:
4718 assert (0);
4719 }
4720
4721 if (inst.reloc.type == 0)
4722 {
4723 inst.error = _("this group relocation is not allowed on this instruction");
4724 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4725 }
4726 }
4727 else
4728 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4729 return PARSE_OPERAND_FAIL;
09d92015
MM
4730 }
4731 }
4732
c19d1205 4733 if (skip_past_char (&p, ']') == FAIL)
09d92015 4734 {
c19d1205 4735 inst.error = _("']' expected");
4962c51a 4736 return PARSE_OPERAND_FAIL;
09d92015
MM
4737 }
4738
c19d1205
ZW
4739 if (skip_past_char (&p, '!') == SUCCESS)
4740 inst.operands[i].writeback = 1;
09d92015 4741
c19d1205 4742 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4743 {
c19d1205
ZW
4744 if (skip_past_char (&p, '{') == SUCCESS)
4745 {
4746 /* [Rn], {expr} - unindexed, with option */
4747 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4748 0, 255, TRUE) == FAIL)
4962c51a 4749 return PARSE_OPERAND_FAIL;
09d92015 4750
c19d1205
ZW
4751 if (skip_past_char (&p, '}') == FAIL)
4752 {
4753 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4754 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4755 }
4756 if (inst.operands[i].preind)
4757 {
4758 inst.error = _("cannot combine index with option");
4962c51a 4759 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4760 }
4761 *str = p;
4962c51a 4762 return PARSE_OPERAND_SUCCESS;
09d92015 4763 }
c19d1205
ZW
4764 else
4765 {
4766 inst.operands[i].postind = 1;
4767 inst.operands[i].writeback = 1;
09d92015 4768
c19d1205
ZW
4769 if (inst.operands[i].preind)
4770 {
4771 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4772 return PARSE_OPERAND_FAIL;
c19d1205 4773 }
09d92015 4774
c19d1205
ZW
4775 if (*p == '+') p++;
4776 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4777
dcbf9037 4778 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4779 {
5287ad62
JB
4780 /* We might be using the immediate for alignment already. If we
4781 are, OR the register number into the low-order bits. */
4782 if (inst.operands[i].immisalign)
4783 inst.operands[i].imm |= reg;
4784 else
4785 inst.operands[i].imm = reg;
c19d1205 4786 inst.operands[i].immisreg = 1;
a737bd4d 4787
c19d1205
ZW
4788 if (skip_past_comma (&p) == SUCCESS)
4789 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4790 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4791 }
4792 else
4793 {
4794 if (inst.operands[i].negative)
4795 {
4796 inst.operands[i].negative = 0;
4797 p--;
4798 }
4799 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4800 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4801 }
4802 }
a737bd4d
NC
4803 }
4804
c19d1205
ZW
4805 /* If at this point neither .preind nor .postind is set, we have a
4806 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4807 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4808 {
4809 inst.operands[i].preind = 1;
4810 inst.reloc.exp.X_op = O_constant;
4811 inst.reloc.exp.X_add_number = 0;
4812 }
4813 *str = p;
4962c51a
MS
4814 return PARSE_OPERAND_SUCCESS;
4815}
4816
4817static int
4818parse_address (char **str, int i)
4819{
4820 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4821 ? SUCCESS : FAIL;
4822}
4823
4824static parse_operand_result
4825parse_address_group_reloc (char **str, int i, group_reloc_type type)
4826{
4827 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4828}
4829
b6895b4f
PB
4830/* Parse an operand for a MOVW or MOVT instruction. */
4831static int
4832parse_half (char **str)
4833{
4834 char * p;
5f4273c7 4835
b6895b4f
PB
4836 p = *str;
4837 skip_past_char (&p, '#');
5f4273c7 4838 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4839 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4840 else if (strncasecmp (p, ":upper16:", 9) == 0)
4841 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4842
4843 if (inst.reloc.type != BFD_RELOC_UNUSED)
4844 {
4845 p += 9;
5f4273c7 4846 skip_whitespace (p);
b6895b4f
PB
4847 }
4848
4849 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4850 return FAIL;
4851
4852 if (inst.reloc.type == BFD_RELOC_UNUSED)
4853 {
4854 if (inst.reloc.exp.X_op != O_constant)
4855 {
4856 inst.error = _("constant expression expected");
4857 return FAIL;
4858 }
4859 if (inst.reloc.exp.X_add_number < 0
4860 || inst.reloc.exp.X_add_number > 0xffff)
4861 {
4862 inst.error = _("immediate value out of range");
4863 return FAIL;
4864 }
4865 }
4866 *str = p;
4867 return SUCCESS;
4868}
4869
c19d1205 4870/* Miscellaneous. */
a737bd4d 4871
c19d1205
ZW
4872/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4873 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4874static int
4875parse_psr (char **str)
09d92015 4876{
c19d1205
ZW
4877 char *p;
4878 unsigned long psr_field;
62b3e311
PB
4879 const struct asm_psr *psr;
4880 char *start;
09d92015 4881
c19d1205
ZW
4882 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4883 feature for ease of use and backwards compatibility. */
4884 p = *str;
62b3e311 4885 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4886 psr_field = SPSR_BIT;
62b3e311 4887 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4888 psr_field = 0;
4889 else
62b3e311
PB
4890 {
4891 start = p;
4892 do
4893 p++;
4894 while (ISALNUM (*p) || *p == '_');
4895
4896 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4897 if (!psr)
4898 return FAIL;
09d92015 4899
62b3e311
PB
4900 *str = p;
4901 return psr->field;
4902 }
09d92015 4903
62b3e311 4904 p += 4;
c19d1205
ZW
4905 if (*p == '_')
4906 {
4907 /* A suffix follows. */
c19d1205
ZW
4908 p++;
4909 start = p;
a737bd4d 4910
c19d1205
ZW
4911 do
4912 p++;
4913 while (ISALNUM (*p) || *p == '_');
a737bd4d 4914
c19d1205
ZW
4915 psr = hash_find_n (arm_psr_hsh, start, p - start);
4916 if (!psr)
4917 goto error;
a737bd4d 4918
c19d1205 4919 psr_field |= psr->field;
a737bd4d 4920 }
c19d1205 4921 else
a737bd4d 4922 {
c19d1205
ZW
4923 if (ISALNUM (*p))
4924 goto error; /* Garbage after "[CS]PSR". */
4925
4926 psr_field |= (PSR_c | PSR_f);
a737bd4d 4927 }
c19d1205
ZW
4928 *str = p;
4929 return psr_field;
a737bd4d 4930
c19d1205
ZW
4931 error:
4932 inst.error = _("flag for {c}psr instruction expected");
4933 return FAIL;
a737bd4d
NC
4934}
4935
c19d1205
ZW
4936/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4937 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4938
c19d1205
ZW
4939static int
4940parse_cps_flags (char **str)
a737bd4d 4941{
c19d1205
ZW
4942 int val = 0;
4943 int saw_a_flag = 0;
4944 char *s = *str;
a737bd4d 4945
c19d1205
ZW
4946 for (;;)
4947 switch (*s++)
4948 {
4949 case '\0': case ',':
4950 goto done;
a737bd4d 4951
c19d1205
ZW
4952 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4953 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4954 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4955
c19d1205
ZW
4956 default:
4957 inst.error = _("unrecognized CPS flag");
4958 return FAIL;
4959 }
a737bd4d 4960
c19d1205
ZW
4961 done:
4962 if (saw_a_flag == 0)
a737bd4d 4963 {
c19d1205
ZW
4964 inst.error = _("missing CPS flags");
4965 return FAIL;
a737bd4d 4966 }
a737bd4d 4967
c19d1205
ZW
4968 *str = s - 1;
4969 return val;
a737bd4d
NC
4970}
4971
c19d1205
ZW
4972/* Parse an endian specifier ("BE" or "LE", case insensitive);
4973 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4974
4975static int
c19d1205 4976parse_endian_specifier (char **str)
a737bd4d 4977{
c19d1205
ZW
4978 int little_endian;
4979 char *s = *str;
a737bd4d 4980
c19d1205
ZW
4981 if (strncasecmp (s, "BE", 2))
4982 little_endian = 0;
4983 else if (strncasecmp (s, "LE", 2))
4984 little_endian = 1;
4985 else
a737bd4d 4986 {
c19d1205 4987 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4988 return FAIL;
4989 }
4990
c19d1205 4991 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 4992 {
c19d1205 4993 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4994 return FAIL;
4995 }
4996
c19d1205
ZW
4997 *str = s + 2;
4998 return little_endian;
4999}
a737bd4d 5000
c19d1205
ZW
5001/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5002 value suitable for poking into the rotate field of an sxt or sxta
5003 instruction, or FAIL on error. */
5004
5005static int
5006parse_ror (char **str)
5007{
5008 int rot;
5009 char *s = *str;
5010
5011 if (strncasecmp (s, "ROR", 3) == 0)
5012 s += 3;
5013 else
a737bd4d 5014 {
c19d1205 5015 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5016 return FAIL;
5017 }
c19d1205
ZW
5018
5019 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5020 return FAIL;
5021
5022 switch (rot)
a737bd4d 5023 {
c19d1205
ZW
5024 case 0: *str = s; return 0x0;
5025 case 8: *str = s; return 0x1;
5026 case 16: *str = s; return 0x2;
5027 case 24: *str = s; return 0x3;
5028
5029 default:
5030 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5031 return FAIL;
5032 }
c19d1205 5033}
a737bd4d 5034
c19d1205
ZW
5035/* Parse a conditional code (from conds[] below). The value returned is in the
5036 range 0 .. 14, or FAIL. */
5037static int
5038parse_cond (char **str)
5039{
5040 char *p, *q;
5041 const struct asm_cond *c;
a737bd4d 5042
c19d1205
ZW
5043 p = q = *str;
5044 while (ISALPHA (*q))
5045 q++;
a737bd4d 5046
c19d1205
ZW
5047 c = hash_find_n (arm_cond_hsh, p, q - p);
5048 if (!c)
a737bd4d 5049 {
c19d1205 5050 inst.error = _("condition required");
a737bd4d
NC
5051 return FAIL;
5052 }
5053
c19d1205
ZW
5054 *str = q;
5055 return c->value;
5056}
5057
62b3e311
PB
5058/* Parse an option for a barrier instruction. Returns the encoding for the
5059 option, or FAIL. */
5060static int
5061parse_barrier (char **str)
5062{
5063 char *p, *q;
5064 const struct asm_barrier_opt *o;
5065
5066 p = q = *str;
5067 while (ISALPHA (*q))
5068 q++;
5069
5070 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5071 if (!o)
5072 return FAIL;
5073
5074 *str = q;
5075 return o->value;
5076}
5077
92e90b6e
PB
5078/* Parse the operands of a table branch instruction. Similar to a memory
5079 operand. */
5080static int
5081parse_tb (char **str)
5082{
5083 char * p = *str;
5084 int reg;
5085
5086 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5087 {
5088 inst.error = _("'[' expected");
5089 return FAIL;
5090 }
92e90b6e 5091
dcbf9037 5092 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5093 {
5094 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5095 return FAIL;
5096 }
5097 inst.operands[0].reg = reg;
5098
5099 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5100 {
5101 inst.error = _("',' expected");
5102 return FAIL;
5103 }
5f4273c7 5104
dcbf9037 5105 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5106 {
5107 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5108 return FAIL;
5109 }
5110 inst.operands[0].imm = reg;
5111
5112 if (skip_past_comma (&p) == SUCCESS)
5113 {
5114 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5115 return FAIL;
5116 if (inst.reloc.exp.X_add_number != 1)
5117 {
5118 inst.error = _("invalid shift");
5119 return FAIL;
5120 }
5121 inst.operands[0].shifted = 1;
5122 }
5123
5124 if (skip_past_char (&p, ']') == FAIL)
5125 {
5126 inst.error = _("']' expected");
5127 return FAIL;
5128 }
5129 *str = p;
5130 return SUCCESS;
5131}
5132
5287ad62
JB
5133/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5134 information on the types the operands can take and how they are encoded.
037e8744
JB
5135 Up to four operands may be read; this function handles setting the
5136 ".present" field for each read operand itself.
5287ad62
JB
5137 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5138 else returns FAIL. */
5139
5140static int
5141parse_neon_mov (char **str, int *which_operand)
5142{
5143 int i = *which_operand, val;
5144 enum arm_reg_type rtype;
5145 char *ptr = *str;
dcbf9037 5146 struct neon_type_el optype;
5f4273c7 5147
dcbf9037 5148 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5149 {
5150 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5151 inst.operands[i].reg = val;
5152 inst.operands[i].isscalar = 1;
dcbf9037 5153 inst.operands[i].vectype = optype;
5287ad62
JB
5154 inst.operands[i++].present = 1;
5155
5156 if (skip_past_comma (&ptr) == FAIL)
5157 goto wanted_comma;
5f4273c7 5158
dcbf9037 5159 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5160 goto wanted_arm;
5f4273c7 5161
5287ad62
JB
5162 inst.operands[i].reg = val;
5163 inst.operands[i].isreg = 1;
5164 inst.operands[i].present = 1;
5165 }
037e8744 5166 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5167 != FAIL)
5287ad62
JB
5168 {
5169 /* Cases 0, 1, 2, 3, 5 (D only). */
5170 if (skip_past_comma (&ptr) == FAIL)
5171 goto wanted_comma;
5f4273c7 5172
5287ad62
JB
5173 inst.operands[i].reg = val;
5174 inst.operands[i].isreg = 1;
5175 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5176 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5177 inst.operands[i].isvec = 1;
dcbf9037 5178 inst.operands[i].vectype = optype;
5287ad62
JB
5179 inst.operands[i++].present = 1;
5180
dcbf9037 5181 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5182 {
037e8744
JB
5183 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5184 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5185 inst.operands[i].reg = val;
5186 inst.operands[i].isreg = 1;
037e8744 5187 inst.operands[i].present = 1;
5287ad62
JB
5188
5189 if (rtype == REG_TYPE_NQ)
5190 {
dcbf9037 5191 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5192 return FAIL;
5193 }
037e8744
JB
5194 else if (rtype != REG_TYPE_VFS)
5195 {
5196 i++;
5197 if (skip_past_comma (&ptr) == FAIL)
5198 goto wanted_comma;
5199 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5200 goto wanted_arm;
5201 inst.operands[i].reg = val;
5202 inst.operands[i].isreg = 1;
5203 inst.operands[i].present = 1;
5204 }
5287ad62 5205 }
136da414 5206 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5207 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5208 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5209 Case 10: VMOV.F32 <Sd>, #<imm>
5210 Case 11: VMOV.F64 <Dd>, #<imm> */
c96612cc 5211 inst.operands[i].immisfloat = 1;
5287ad62 5212 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5213 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5214 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5215 ;
5216 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5217 &optype)) != FAIL)
5287ad62
JB
5218 {
5219 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5220 Case 1: VMOV<c><q> <Dd>, <Dm>
5221 Case 8: VMOV.F32 <Sd>, <Sm>
5222 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5223
5224 inst.operands[i].reg = val;
5225 inst.operands[i].isreg = 1;
5226 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5227 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5228 inst.operands[i].isvec = 1;
dcbf9037 5229 inst.operands[i].vectype = optype;
5287ad62 5230 inst.operands[i].present = 1;
5f4273c7 5231
037e8744
JB
5232 if (skip_past_comma (&ptr) == SUCCESS)
5233 {
5234 /* Case 15. */
5235 i++;
5236
5237 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5238 goto wanted_arm;
5239
5240 inst.operands[i].reg = val;
5241 inst.operands[i].isreg = 1;
5242 inst.operands[i++].present = 1;
5f4273c7 5243
037e8744
JB
5244 if (skip_past_comma (&ptr) == FAIL)
5245 goto wanted_comma;
5f4273c7 5246
037e8744
JB
5247 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5248 goto wanted_arm;
5f4273c7 5249
037e8744
JB
5250 inst.operands[i].reg = val;
5251 inst.operands[i].isreg = 1;
5252 inst.operands[i++].present = 1;
5253 }
5287ad62
JB
5254 }
5255 else
5256 {
dcbf9037 5257 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5258 return FAIL;
5259 }
5260 }
dcbf9037 5261 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5262 {
5263 /* Cases 6, 7. */
5264 inst.operands[i].reg = val;
5265 inst.operands[i].isreg = 1;
5266 inst.operands[i++].present = 1;
5f4273c7 5267
5287ad62
JB
5268 if (skip_past_comma (&ptr) == FAIL)
5269 goto wanted_comma;
5f4273c7 5270
dcbf9037 5271 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5272 {
5273 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5274 inst.operands[i].reg = val;
5275 inst.operands[i].isscalar = 1;
5276 inst.operands[i].present = 1;
dcbf9037 5277 inst.operands[i].vectype = optype;
5287ad62 5278 }
dcbf9037 5279 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5280 {
5281 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5282 inst.operands[i].reg = val;
5283 inst.operands[i].isreg = 1;
5284 inst.operands[i++].present = 1;
5f4273c7 5285
5287ad62
JB
5286 if (skip_past_comma (&ptr) == FAIL)
5287 goto wanted_comma;
5f4273c7 5288
037e8744 5289 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5290 == FAIL)
5287ad62 5291 {
037e8744 5292 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5293 return FAIL;
5294 }
5295
5296 inst.operands[i].reg = val;
5297 inst.operands[i].isreg = 1;
037e8744
JB
5298 inst.operands[i].isvec = 1;
5299 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5300 inst.operands[i].vectype = optype;
5287ad62 5301 inst.operands[i].present = 1;
5f4273c7 5302
037e8744
JB
5303 if (rtype == REG_TYPE_VFS)
5304 {
5305 /* Case 14. */
5306 i++;
5307 if (skip_past_comma (&ptr) == FAIL)
5308 goto wanted_comma;
5309 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5310 &optype)) == FAIL)
5311 {
5312 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5313 return FAIL;
5314 }
5315 inst.operands[i].reg = val;
5316 inst.operands[i].isreg = 1;
5317 inst.operands[i].isvec = 1;
5318 inst.operands[i].issingle = 1;
5319 inst.operands[i].vectype = optype;
5320 inst.operands[i].present = 1;
5321 }
5322 }
5323 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5324 != FAIL)
5325 {
5326 /* Case 13. */
5327 inst.operands[i].reg = val;
5328 inst.operands[i].isreg = 1;
5329 inst.operands[i].isvec = 1;
5330 inst.operands[i].issingle = 1;
5331 inst.operands[i].vectype = optype;
5332 inst.operands[i++].present = 1;
5287ad62
JB
5333 }
5334 }
5335 else
5336 {
dcbf9037 5337 first_error (_("parse error"));
5287ad62
JB
5338 return FAIL;
5339 }
5340
5341 /* Successfully parsed the operands. Update args. */
5342 *which_operand = i;
5343 *str = ptr;
5344 return SUCCESS;
5345
5f4273c7 5346 wanted_comma:
dcbf9037 5347 first_error (_("expected comma"));
5287ad62 5348 return FAIL;
5f4273c7
NC
5349
5350 wanted_arm:
dcbf9037 5351 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5352 return FAIL;
5287ad62
JB
5353}
5354
c19d1205
ZW
5355/* Matcher codes for parse_operands. */
5356enum operand_parse_code
5357{
5358 OP_stop, /* end of line */
5359
5360 OP_RR, /* ARM register */
5361 OP_RRnpc, /* ARM register, not r15 */
5362 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5363 OP_RRw, /* ARM register, not r15, optional trailing ! */
5364 OP_RCP, /* Coprocessor number */
5365 OP_RCN, /* Coprocessor register */
5366 OP_RF, /* FPA register */
5367 OP_RVS, /* VFP single precision register */
5287ad62
JB
5368 OP_RVD, /* VFP double precision register (0..15) */
5369 OP_RND, /* Neon double precision register (0..31) */
5370 OP_RNQ, /* Neon quad precision register */
037e8744 5371 OP_RVSD, /* VFP single or double precision register */
5287ad62 5372 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5373 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5374 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5375 OP_RVC, /* VFP control register */
5376 OP_RMF, /* Maverick F register */
5377 OP_RMD, /* Maverick D register */
5378 OP_RMFX, /* Maverick FX register */
5379 OP_RMDX, /* Maverick DX register */
5380 OP_RMAX, /* Maverick AX register */
5381 OP_RMDS, /* Maverick DSPSC register */
5382 OP_RIWR, /* iWMMXt wR register */
5383 OP_RIWC, /* iWMMXt wC register */
5384 OP_RIWG, /* iWMMXt wCG register */
5385 OP_RXA, /* XScale accumulator register */
5386
5387 OP_REGLST, /* ARM register list */
5388 OP_VRSLST, /* VFP single-precision register list */
5389 OP_VRDLST, /* VFP double-precision register list */
037e8744 5390 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5391 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5392 OP_NSTRLST, /* Neon element/structure list */
5393
5394 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5395 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5396 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5397 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5398 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5399 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5400 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5401 OP_VMOV, /* Neon VMOV operands. */
5402 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5403 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5404 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5405
5406 OP_I0, /* immediate zero */
c19d1205
ZW
5407 OP_I7, /* immediate value 0 .. 7 */
5408 OP_I15, /* 0 .. 15 */
5409 OP_I16, /* 1 .. 16 */
5287ad62 5410 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5411 OP_I31, /* 0 .. 31 */
5412 OP_I31w, /* 0 .. 31, optional trailing ! */
5413 OP_I32, /* 1 .. 32 */
5287ad62
JB
5414 OP_I32z, /* 0 .. 32 */
5415 OP_I63, /* 0 .. 63 */
c19d1205 5416 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5417 OP_I64, /* 1 .. 64 */
5418 OP_I64z, /* 0 .. 64 */
c19d1205 5419 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5420
5421 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5422 OP_I7b, /* 0 .. 7 */
5423 OP_I15b, /* 0 .. 15 */
5424 OP_I31b, /* 0 .. 31 */
5425
5426 OP_SH, /* shifter operand */
4962c51a 5427 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5428 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5429 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5430 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5431 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5432 OP_EXP, /* arbitrary expression */
5433 OP_EXPi, /* same, with optional immediate prefix */
5434 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5435 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5436
5437 OP_CPSF, /* CPS flags */
5438 OP_ENDI, /* Endianness specifier */
5439 OP_PSR, /* CPSR/SPSR mask for msr */
5440 OP_COND, /* conditional code */
92e90b6e 5441 OP_TB, /* Table branch. */
c19d1205 5442
037e8744
JB
5443 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5444 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5445
c19d1205
ZW
5446 OP_RRnpc_I0, /* ARM register or literal 0 */
5447 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5448 OP_RR_EXi, /* ARM register or expression with imm prefix */
5449 OP_RF_IF, /* FPA register or immediate */
5450 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5451 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5452
5453 /* Optional operands. */
5454 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5455 OP_oI31b, /* 0 .. 31 */
5287ad62 5456 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5457 OP_oIffffb, /* 0 .. 65535 */
5458 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5459
5460 OP_oRR, /* ARM register */
5461 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5462 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5463 OP_oRND, /* Optional Neon double precision register */
5464 OP_oRNQ, /* Optional Neon quad precision register */
5465 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5466 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5467 OP_oSHll, /* LSL immediate */
5468 OP_oSHar, /* ASR immediate */
5469 OP_oSHllar, /* LSL or ASR immediate */
5470 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5471 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5472
5473 OP_FIRST_OPTIONAL = OP_oI7b
5474};
a737bd4d 5475
c19d1205
ZW
5476/* Generic instruction operand parser. This does no encoding and no
5477 semantic validation; it merely squirrels values away in the inst
5478 structure. Returns SUCCESS or FAIL depending on whether the
5479 specified grammar matched. */
5480static int
ca3f61f7 5481parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5482{
5483 unsigned const char *upat = pattern;
5484 char *backtrack_pos = 0;
5485 const char *backtrack_error = 0;
5486 int i, val, backtrack_index = 0;
5287ad62 5487 enum arm_reg_type rtype;
4962c51a 5488 parse_operand_result result;
c19d1205
ZW
5489
5490#define po_char_or_fail(chr) do { \
5491 if (skip_past_char (&str, chr) == FAIL) \
5492 goto bad_args; \
5493} while (0)
5494
dcbf9037
JB
5495#define po_reg_or_fail(regtype) do { \
5496 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5497 &inst.operands[i].vectype); \
5498 if (val == FAIL) \
5499 { \
5500 first_error (_(reg_expected_msgs[regtype])); \
5501 goto failure; \
5502 } \
5503 inst.operands[i].reg = val; \
5504 inst.operands[i].isreg = 1; \
5505 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5506 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5507 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5508 || rtype == REG_TYPE_VFD \
5509 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5510} while (0)
5511
dcbf9037
JB
5512#define po_reg_or_goto(regtype, label) do { \
5513 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5514 &inst.operands[i].vectype); \
5515 if (val == FAIL) \
5516 goto label; \
5517 \
5518 inst.operands[i].reg = val; \
5519 inst.operands[i].isreg = 1; \
5520 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5521 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5522 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5523 || rtype == REG_TYPE_VFD \
5524 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5525} while (0)
5526
5527#define po_imm_or_fail(min, max, popt) do { \
5528 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5529 goto failure; \
5530 inst.operands[i].imm = val; \
5531} while (0)
5532
dcbf9037
JB
5533#define po_scalar_or_goto(elsz, label) do { \
5534 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5535 if (val == FAIL) \
5536 goto label; \
5537 inst.operands[i].reg = val; \
5538 inst.operands[i].isscalar = 1; \
5287ad62
JB
5539} while (0)
5540
c19d1205
ZW
5541#define po_misc_or_fail(expr) do { \
5542 if (expr) \
5543 goto failure; \
5544} while (0)
5545
4962c51a
MS
5546#define po_misc_or_fail_no_backtrack(expr) do { \
5547 result = expr; \
5548 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5549 backtrack_pos = 0; \
5550 if (result != PARSE_OPERAND_SUCCESS) \
5551 goto failure; \
5552} while (0)
5553
c19d1205
ZW
5554 skip_whitespace (str);
5555
5556 for (i = 0; upat[i] != OP_stop; i++)
5557 {
5558 if (upat[i] >= OP_FIRST_OPTIONAL)
5559 {
5560 /* Remember where we are in case we need to backtrack. */
5561 assert (!backtrack_pos);
5562 backtrack_pos = str;
5563 backtrack_error = inst.error;
5564 backtrack_index = i;
5565 }
5566
b6702015 5567 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5568 po_char_or_fail (',');
5569
5570 switch (upat[i])
5571 {
5572 /* Registers */
5573 case OP_oRRnpc:
5574 case OP_RRnpc:
5575 case OP_oRR:
5576 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5577 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5578 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5579 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5580 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5581 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5582 case OP_oRND:
5583 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5584 case OP_RVC:
5585 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5586 break;
5587 /* Also accept generic coprocessor regs for unknown registers. */
5588 coproc_reg:
5589 po_reg_or_fail (REG_TYPE_CN);
5590 break;
c19d1205
ZW
5591 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5592 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5593 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5594 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5595 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5596 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5597 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5598 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5599 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5600 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5601 case OP_oRNQ:
5602 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5603 case OP_oRNDQ:
5604 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5605 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5606 case OP_oRNSDQ:
5607 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5608
5609 /* Neon scalar. Using an element size of 8 means that some invalid
5610 scalars are accepted here, so deal with those in later code. */
5611 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5612
5613 /* WARNING: We can expand to two operands here. This has the potential
5614 to totally confuse the backtracking mechanism! It will be OK at
5615 least as long as we don't try to use optional args as well,
5616 though. */
5617 case OP_NILO:
5618 {
5619 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5620 inst.operands[i].present = 1;
5287ad62
JB
5621 i++;
5622 skip_past_comma (&str);
5623 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5624 break;
5625 one_reg_only:
5626 /* Optional register operand was omitted. Unfortunately, it's in
5627 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5628 here (this is a bit grotty). */
5629 inst.operands[i] = inst.operands[i-1];
5630 inst.operands[i-1].present = 0;
5631 break;
5632 try_imm:
036dc3f7
PB
5633 /* There's a possibility of getting a 64-bit immediate here, so
5634 we need special handling. */
5635 if (parse_big_immediate (&str, i) == FAIL)
5636 {
5637 inst.error = _("immediate value is out of range");
5638 goto failure;
5639 }
5287ad62
JB
5640 }
5641 break;
5642
5643 case OP_RNDQ_I0:
5644 {
5645 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5646 break;
5647 try_imm0:
5648 po_imm_or_fail (0, 0, TRUE);
5649 }
5650 break;
5651
037e8744
JB
5652 case OP_RVSD_I0:
5653 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5654 break;
5655
5287ad62
JB
5656 case OP_RR_RNSC:
5657 {
5658 po_scalar_or_goto (8, try_rr);
5659 break;
5660 try_rr:
5661 po_reg_or_fail (REG_TYPE_RN);
5662 }
5663 break;
5664
037e8744
JB
5665 case OP_RNSDQ_RNSC:
5666 {
5667 po_scalar_or_goto (8, try_nsdq);
5668 break;
5669 try_nsdq:
5670 po_reg_or_fail (REG_TYPE_NSDQ);
5671 }
5672 break;
5673
5287ad62
JB
5674 case OP_RNDQ_RNSC:
5675 {
5676 po_scalar_or_goto (8, try_ndq);
5677 break;
5678 try_ndq:
5679 po_reg_or_fail (REG_TYPE_NDQ);
5680 }
5681 break;
5682
5683 case OP_RND_RNSC:
5684 {
5685 po_scalar_or_goto (8, try_vfd);
5686 break;
5687 try_vfd:
5688 po_reg_or_fail (REG_TYPE_VFD);
5689 }
5690 break;
5691
5692 case OP_VMOV:
5693 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5694 not careful then bad things might happen. */
5695 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5696 break;
5697
5698 case OP_RNDQ_IMVNb:
5699 {
5700 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5701 break;
5702 try_mvnimm:
5703 /* There's a possibility of getting a 64-bit immediate here, so
5704 we need special handling. */
5705 if (parse_big_immediate (&str, i) == FAIL)
5706 {
5707 inst.error = _("immediate value is out of range");
5708 goto failure;
5709 }
5710 }
5711 break;
5712
5713 case OP_RNDQ_I63b:
5714 {
5715 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5716 break;
5717 try_shimm:
5718 po_imm_or_fail (0, 63, TRUE);
5719 }
5720 break;
c19d1205
ZW
5721
5722 case OP_RRnpcb:
5723 po_char_or_fail ('[');
5724 po_reg_or_fail (REG_TYPE_RN);
5725 po_char_or_fail (']');
5726 break;
a737bd4d 5727
c19d1205 5728 case OP_RRw:
b6702015 5729 case OP_oRRw:
c19d1205
ZW
5730 po_reg_or_fail (REG_TYPE_RN);
5731 if (skip_past_char (&str, '!') == SUCCESS)
5732 inst.operands[i].writeback = 1;
5733 break;
5734
5735 /* Immediates */
5736 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5737 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5738 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5739 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5740 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5741 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5742 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5743 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5744 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5745 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5746 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5747 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5748
5749 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5750 case OP_oI7b:
5751 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5752 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5753 case OP_oI31b:
5754 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5755 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5756 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5757
5758 /* Immediate variants */
5759 case OP_oI255c:
5760 po_char_or_fail ('{');
5761 po_imm_or_fail (0, 255, TRUE);
5762 po_char_or_fail ('}');
5763 break;
5764
5765 case OP_I31w:
5766 /* The expression parser chokes on a trailing !, so we have
5767 to find it first and zap it. */
5768 {
5769 char *s = str;
5770 while (*s && *s != ',')
5771 s++;
5772 if (s[-1] == '!')
5773 {
5774 s[-1] = '\0';
5775 inst.operands[i].writeback = 1;
5776 }
5777 po_imm_or_fail (0, 31, TRUE);
5778 if (str == s - 1)
5779 str = s;
5780 }
5781 break;
5782
5783 /* Expressions */
5784 case OP_EXPi: EXPi:
5785 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5786 GE_OPT_PREFIX));
5787 break;
5788
5789 case OP_EXP:
5790 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5791 GE_NO_PREFIX));
5792 break;
5793
5794 case OP_EXPr: EXPr:
5795 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5796 GE_NO_PREFIX));
5797 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5798 {
c19d1205
ZW
5799 val = parse_reloc (&str);
5800 if (val == -1)
5801 {
5802 inst.error = _("unrecognized relocation suffix");
5803 goto failure;
5804 }
5805 else if (val != BFD_RELOC_UNUSED)
5806 {
5807 inst.operands[i].imm = val;
5808 inst.operands[i].hasreloc = 1;
5809 }
a737bd4d 5810 }
c19d1205 5811 break;
a737bd4d 5812
b6895b4f
PB
5813 /* Operand for MOVW or MOVT. */
5814 case OP_HALF:
5815 po_misc_or_fail (parse_half (&str));
5816 break;
5817
c19d1205
ZW
5818 /* Register or expression */
5819 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5820 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5821
c19d1205
ZW
5822 /* Register or immediate */
5823 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5824 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5825
c19d1205
ZW
5826 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5827 IF:
5828 if (!is_immediate_prefix (*str))
5829 goto bad_args;
5830 str++;
5831 val = parse_fpa_immediate (&str);
5832 if (val == FAIL)
5833 goto failure;
5834 /* FPA immediates are encoded as registers 8-15.
5835 parse_fpa_immediate has already applied the offset. */
5836 inst.operands[i].reg = val;
5837 inst.operands[i].isreg = 1;
5838 break;
09d92015 5839
2d447fca
JM
5840 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5841 I32z: po_imm_or_fail (0, 32, FALSE); break;
5842
c19d1205
ZW
5843 /* Two kinds of register */
5844 case OP_RIWR_RIWC:
5845 {
5846 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5847 if (!rege
5848 || (rege->type != REG_TYPE_MMXWR
5849 && rege->type != REG_TYPE_MMXWC
5850 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5851 {
5852 inst.error = _("iWMMXt data or control register expected");
5853 goto failure;
5854 }
5855 inst.operands[i].reg = rege->number;
5856 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5857 }
5858 break;
09d92015 5859
41adaa5c
JM
5860 case OP_RIWC_RIWG:
5861 {
5862 struct reg_entry *rege = arm_reg_parse_multi (&str);
5863 if (!rege
5864 || (rege->type != REG_TYPE_MMXWC
5865 && rege->type != REG_TYPE_MMXWCG))
5866 {
5867 inst.error = _("iWMMXt control register expected");
5868 goto failure;
5869 }
5870 inst.operands[i].reg = rege->number;
5871 inst.operands[i].isreg = 1;
5872 }
5873 break;
5874
c19d1205
ZW
5875 /* Misc */
5876 case OP_CPSF: val = parse_cps_flags (&str); break;
5877 case OP_ENDI: val = parse_endian_specifier (&str); break;
5878 case OP_oROR: val = parse_ror (&str); break;
5879 case OP_PSR: val = parse_psr (&str); break;
5880 case OP_COND: val = parse_cond (&str); break;
62b3e311 5881 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5882
037e8744
JB
5883 case OP_RVC_PSR:
5884 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5885 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5886 break;
5887 try_psr:
5888 val = parse_psr (&str);
5889 break;
5890
5891 case OP_APSR_RR:
5892 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5893 break;
5894 try_apsr:
5895 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5896 instruction). */
5897 if (strncasecmp (str, "APSR_", 5) == 0)
5898 {
5899 unsigned found = 0;
5900 str += 5;
5901 while (found < 15)
5902 switch (*str++)
5903 {
5904 case 'c': found = (found & 1) ? 16 : found | 1; break;
5905 case 'n': found = (found & 2) ? 16 : found | 2; break;
5906 case 'z': found = (found & 4) ? 16 : found | 4; break;
5907 case 'v': found = (found & 8) ? 16 : found | 8; break;
5908 default: found = 16;
5909 }
5910 if (found != 15)
5911 goto failure;
5912 inst.operands[i].isvec = 1;
5913 }
5914 else
5915 goto failure;
5916 break;
5917
92e90b6e
PB
5918 case OP_TB:
5919 po_misc_or_fail (parse_tb (&str));
5920 break;
5921
c19d1205
ZW
5922 /* Register lists */
5923 case OP_REGLST:
5924 val = parse_reg_list (&str);
5925 if (*str == '^')
5926 {
5927 inst.operands[1].writeback = 1;
5928 str++;
5929 }
5930 break;
09d92015 5931
c19d1205 5932 case OP_VRSLST:
5287ad62 5933 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5934 break;
09d92015 5935
c19d1205 5936 case OP_VRDLST:
5287ad62 5937 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5938 break;
a737bd4d 5939
037e8744
JB
5940 case OP_VRSDLST:
5941 /* Allow Q registers too. */
5942 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5943 REGLIST_NEON_D);
5944 if (val == FAIL)
5945 {
5946 inst.error = NULL;
5947 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5948 REGLIST_VFP_S);
5949 inst.operands[i].issingle = 1;
5950 }
5951 break;
5952
5287ad62
JB
5953 case OP_NRDLST:
5954 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5955 REGLIST_NEON_D);
5956 break;
5957
5958 case OP_NSTRLST:
dcbf9037
JB
5959 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5960 &inst.operands[i].vectype);
5287ad62
JB
5961 break;
5962
c19d1205
ZW
5963 /* Addressing modes */
5964 case OP_ADDR:
5965 po_misc_or_fail (parse_address (&str, i));
5966 break;
09d92015 5967
4962c51a
MS
5968 case OP_ADDRGLDR:
5969 po_misc_or_fail_no_backtrack (
5970 parse_address_group_reloc (&str, i, GROUP_LDR));
5971 break;
5972
5973 case OP_ADDRGLDRS:
5974 po_misc_or_fail_no_backtrack (
5975 parse_address_group_reloc (&str, i, GROUP_LDRS));
5976 break;
5977
5978 case OP_ADDRGLDC:
5979 po_misc_or_fail_no_backtrack (
5980 parse_address_group_reloc (&str, i, GROUP_LDC));
5981 break;
5982
c19d1205
ZW
5983 case OP_SH:
5984 po_misc_or_fail (parse_shifter_operand (&str, i));
5985 break;
09d92015 5986
4962c51a
MS
5987 case OP_SHG:
5988 po_misc_or_fail_no_backtrack (
5989 parse_shifter_operand_group_reloc (&str, i));
5990 break;
5991
c19d1205
ZW
5992 case OP_oSHll:
5993 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5994 break;
09d92015 5995
c19d1205
ZW
5996 case OP_oSHar:
5997 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5998 break;
09d92015 5999
c19d1205
ZW
6000 case OP_oSHllar:
6001 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6002 break;
09d92015 6003
c19d1205 6004 default:
bd3ba5d1 6005 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6006 }
09d92015 6007
c19d1205
ZW
6008 /* Various value-based sanity checks and shared operations. We
6009 do not signal immediate failures for the register constraints;
6010 this allows a syntax error to take precedence. */
6011 switch (upat[i])
6012 {
6013 case OP_oRRnpc:
6014 case OP_RRnpc:
6015 case OP_RRnpcb:
6016 case OP_RRw:
b6702015 6017 case OP_oRRw:
c19d1205
ZW
6018 case OP_RRnpc_I0:
6019 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6020 inst.error = BAD_PC;
6021 break;
09d92015 6022
c19d1205
ZW
6023 case OP_CPSF:
6024 case OP_ENDI:
6025 case OP_oROR:
6026 case OP_PSR:
037e8744 6027 case OP_RVC_PSR:
c19d1205 6028 case OP_COND:
62b3e311 6029 case OP_oBARRIER:
c19d1205
ZW
6030 case OP_REGLST:
6031 case OP_VRSLST:
6032 case OP_VRDLST:
037e8744 6033 case OP_VRSDLST:
5287ad62
JB
6034 case OP_NRDLST:
6035 case OP_NSTRLST:
c19d1205
ZW
6036 if (val == FAIL)
6037 goto failure;
6038 inst.operands[i].imm = val;
6039 break;
a737bd4d 6040
c19d1205
ZW
6041 default:
6042 break;
6043 }
09d92015 6044
c19d1205
ZW
6045 /* If we get here, this operand was successfully parsed. */
6046 inst.operands[i].present = 1;
6047 continue;
09d92015 6048
c19d1205 6049 bad_args:
09d92015 6050 inst.error = BAD_ARGS;
c19d1205
ZW
6051
6052 failure:
6053 if (!backtrack_pos)
d252fdde
PB
6054 {
6055 /* The parse routine should already have set inst.error, but set a
5f4273c7 6056 default here just in case. */
d252fdde
PB
6057 if (!inst.error)
6058 inst.error = _("syntax error");
6059 return FAIL;
6060 }
c19d1205
ZW
6061
6062 /* Do not backtrack over a trailing optional argument that
6063 absorbed some text. We will only fail again, with the
6064 'garbage following instruction' error message, which is
6065 probably less helpful than the current one. */
6066 if (backtrack_index == i && backtrack_pos != str
6067 && upat[i+1] == OP_stop)
d252fdde
PB
6068 {
6069 if (!inst.error)
6070 inst.error = _("syntax error");
6071 return FAIL;
6072 }
c19d1205
ZW
6073
6074 /* Try again, skipping the optional argument at backtrack_pos. */
6075 str = backtrack_pos;
6076 inst.error = backtrack_error;
6077 inst.operands[backtrack_index].present = 0;
6078 i = backtrack_index;
6079 backtrack_pos = 0;
09d92015 6080 }
09d92015 6081
c19d1205
ZW
6082 /* Check that we have parsed all the arguments. */
6083 if (*str != '\0' && !inst.error)
6084 inst.error = _("garbage following instruction");
09d92015 6085
c19d1205 6086 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6087}
6088
c19d1205
ZW
6089#undef po_char_or_fail
6090#undef po_reg_or_fail
6091#undef po_reg_or_goto
6092#undef po_imm_or_fail
5287ad62 6093#undef po_scalar_or_fail
c19d1205
ZW
6094\f
6095/* Shorthand macro for instruction encoding functions issuing errors. */
6096#define constraint(expr, err) do { \
6097 if (expr) \
6098 { \
6099 inst.error = err; \
6100 return; \
6101 } \
6102} while (0)
6103
6104/* Functions for operand encoding. ARM, then Thumb. */
6105
6106#define rotate_left(v, n) (v << n | v >> (32 - n))
6107
6108/* If VAL can be encoded in the immediate field of an ARM instruction,
6109 return the encoded form. Otherwise, return FAIL. */
6110
6111static unsigned int
6112encode_arm_immediate (unsigned int val)
09d92015 6113{
c19d1205
ZW
6114 unsigned int a, i;
6115
6116 for (i = 0; i < 32; i += 2)
6117 if ((a = rotate_left (val, i)) <= 0xff)
6118 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6119
6120 return FAIL;
09d92015
MM
6121}
6122
c19d1205
ZW
6123/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6124 return the encoded form. Otherwise, return FAIL. */
6125static unsigned int
6126encode_thumb32_immediate (unsigned int val)
09d92015 6127{
c19d1205 6128 unsigned int a, i;
09d92015 6129
9c3c69f2 6130 if (val <= 0xff)
c19d1205 6131 return val;
a737bd4d 6132
9c3c69f2 6133 for (i = 1; i <= 24; i++)
09d92015 6134 {
9c3c69f2
PB
6135 a = val >> i;
6136 if ((val & ~(0xff << i)) == 0)
6137 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6138 }
a737bd4d 6139
c19d1205
ZW
6140 a = val & 0xff;
6141 if (val == ((a << 16) | a))
6142 return 0x100 | a;
6143 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6144 return 0x300 | a;
09d92015 6145
c19d1205
ZW
6146 a = val & 0xff00;
6147 if (val == ((a << 16) | a))
6148 return 0x200 | (a >> 8);
a737bd4d 6149
c19d1205 6150 return FAIL;
09d92015 6151}
5287ad62 6152/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6153
6154static void
5287ad62
JB
6155encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6156{
6157 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6158 && reg > 15)
6159 {
6160 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6161 {
6162 if (thumb_mode)
6163 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6164 fpu_vfp_ext_v3);
6165 else
6166 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6167 fpu_vfp_ext_v3);
6168 }
6169 else
6170 {
dcbf9037 6171 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6172 return;
6173 }
6174 }
6175
c19d1205 6176 switch (pos)
09d92015 6177 {
c19d1205
ZW
6178 case VFP_REG_Sd:
6179 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6180 break;
6181
6182 case VFP_REG_Sn:
6183 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6184 break;
6185
6186 case VFP_REG_Sm:
6187 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6188 break;
6189
5287ad62
JB
6190 case VFP_REG_Dd:
6191 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6192 break;
5f4273c7 6193
5287ad62
JB
6194 case VFP_REG_Dn:
6195 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6196 break;
5f4273c7 6197
5287ad62
JB
6198 case VFP_REG_Dm:
6199 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6200 break;
6201
c19d1205
ZW
6202 default:
6203 abort ();
09d92015 6204 }
09d92015
MM
6205}
6206
c19d1205 6207/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6208 if any, is handled by md_apply_fix. */
09d92015 6209static void
c19d1205 6210encode_arm_shift (int i)
09d92015 6211{
c19d1205
ZW
6212 if (inst.operands[i].shift_kind == SHIFT_RRX)
6213 inst.instruction |= SHIFT_ROR << 5;
6214 else
09d92015 6215 {
c19d1205
ZW
6216 inst.instruction |= inst.operands[i].shift_kind << 5;
6217 if (inst.operands[i].immisreg)
6218 {
6219 inst.instruction |= SHIFT_BY_REG;
6220 inst.instruction |= inst.operands[i].imm << 8;
6221 }
6222 else
6223 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6224 }
c19d1205 6225}
09d92015 6226
c19d1205
ZW
6227static void
6228encode_arm_shifter_operand (int i)
6229{
6230 if (inst.operands[i].isreg)
09d92015 6231 {
c19d1205
ZW
6232 inst.instruction |= inst.operands[i].reg;
6233 encode_arm_shift (i);
09d92015 6234 }
c19d1205
ZW
6235 else
6236 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6237}
6238
c19d1205 6239/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6240static void
c19d1205 6241encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6242{
c19d1205
ZW
6243 assert (inst.operands[i].isreg);
6244 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6245
c19d1205 6246 if (inst.operands[i].preind)
09d92015 6247 {
c19d1205
ZW
6248 if (is_t)
6249 {
6250 inst.error = _("instruction does not accept preindexed addressing");
6251 return;
6252 }
6253 inst.instruction |= PRE_INDEX;
6254 if (inst.operands[i].writeback)
6255 inst.instruction |= WRITE_BACK;
09d92015 6256
c19d1205
ZW
6257 }
6258 else if (inst.operands[i].postind)
6259 {
6260 assert (inst.operands[i].writeback);
6261 if (is_t)
6262 inst.instruction |= WRITE_BACK;
6263 }
6264 else /* unindexed - only for coprocessor */
09d92015 6265 {
c19d1205 6266 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6267 return;
6268 }
6269
c19d1205
ZW
6270 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6271 && (((inst.instruction & 0x000f0000) >> 16)
6272 == ((inst.instruction & 0x0000f000) >> 12)))
6273 as_warn ((inst.instruction & LOAD_BIT)
6274 ? _("destination register same as write-back base")
6275 : _("source register same as write-back base"));
09d92015
MM
6276}
6277
c19d1205
ZW
6278/* inst.operands[i] was set up by parse_address. Encode it into an
6279 ARM-format mode 2 load or store instruction. If is_t is true,
6280 reject forms that cannot be used with a T instruction (i.e. not
6281 post-indexed). */
a737bd4d 6282static void
c19d1205 6283encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6284{
c19d1205 6285 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6286
c19d1205 6287 if (inst.operands[i].immisreg)
09d92015 6288 {
c19d1205
ZW
6289 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6290 inst.instruction |= inst.operands[i].imm;
6291 if (!inst.operands[i].negative)
6292 inst.instruction |= INDEX_UP;
6293 if (inst.operands[i].shifted)
6294 {
6295 if (inst.operands[i].shift_kind == SHIFT_RRX)
6296 inst.instruction |= SHIFT_ROR << 5;
6297 else
6298 {
6299 inst.instruction |= inst.operands[i].shift_kind << 5;
6300 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6301 }
6302 }
09d92015 6303 }
c19d1205 6304 else /* immediate offset in inst.reloc */
09d92015 6305 {
c19d1205
ZW
6306 if (inst.reloc.type == BFD_RELOC_UNUSED)
6307 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6308 }
09d92015
MM
6309}
6310
c19d1205
ZW
6311/* inst.operands[i] was set up by parse_address. Encode it into an
6312 ARM-format mode 3 load or store instruction. Reject forms that
6313 cannot be used with such instructions. If is_t is true, reject
6314 forms that cannot be used with a T instruction (i.e. not
6315 post-indexed). */
6316static void
6317encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6318{
c19d1205 6319 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6320 {
c19d1205
ZW
6321 inst.error = _("instruction does not accept scaled register index");
6322 return;
09d92015 6323 }
a737bd4d 6324
c19d1205 6325 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6326
c19d1205
ZW
6327 if (inst.operands[i].immisreg)
6328 {
6329 inst.instruction |= inst.operands[i].imm;
6330 if (!inst.operands[i].negative)
6331 inst.instruction |= INDEX_UP;
6332 }
6333 else /* immediate offset in inst.reloc */
6334 {
6335 inst.instruction |= HWOFFSET_IMM;
6336 if (inst.reloc.type == BFD_RELOC_UNUSED)
6337 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6338 }
a737bd4d
NC
6339}
6340
c19d1205
ZW
6341/* inst.operands[i] was set up by parse_address. Encode it into an
6342 ARM-format instruction. Reject all forms which cannot be encoded
6343 into a coprocessor load/store instruction. If wb_ok is false,
6344 reject use of writeback; if unind_ok is false, reject use of
6345 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6346 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6347 (in which case it is preserved). */
09d92015 6348
c19d1205
ZW
6349static int
6350encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6351{
c19d1205 6352 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6353
c19d1205 6354 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6355
c19d1205 6356 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6357 {
c19d1205
ZW
6358 assert (!inst.operands[i].writeback);
6359 if (!unind_ok)
6360 {
6361 inst.error = _("instruction does not support unindexed addressing");
6362 return FAIL;
6363 }
6364 inst.instruction |= inst.operands[i].imm;
6365 inst.instruction |= INDEX_UP;
6366 return SUCCESS;
09d92015 6367 }
a737bd4d 6368
c19d1205
ZW
6369 if (inst.operands[i].preind)
6370 inst.instruction |= PRE_INDEX;
a737bd4d 6371
c19d1205 6372 if (inst.operands[i].writeback)
09d92015 6373 {
c19d1205
ZW
6374 if (inst.operands[i].reg == REG_PC)
6375 {
6376 inst.error = _("pc may not be used with write-back");
6377 return FAIL;
6378 }
6379 if (!wb_ok)
6380 {
6381 inst.error = _("instruction does not support writeback");
6382 return FAIL;
6383 }
6384 inst.instruction |= WRITE_BACK;
09d92015 6385 }
a737bd4d 6386
c19d1205
ZW
6387 if (reloc_override)
6388 inst.reloc.type = reloc_override;
4962c51a
MS
6389 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6390 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6391 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6392 {
6393 if (thumb_mode)
6394 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6395 else
6396 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6397 }
6398
c19d1205
ZW
6399 return SUCCESS;
6400}
a737bd4d 6401
c19d1205
ZW
6402/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6403 Determine whether it can be performed with a move instruction; if
6404 it can, convert inst.instruction to that move instruction and
6405 return 1; if it can't, convert inst.instruction to a literal-pool
6406 load and return 0. If this is not a valid thing to do in the
6407 current context, set inst.error and return 1.
a737bd4d 6408
c19d1205
ZW
6409 inst.operands[i] describes the destination register. */
6410
6411static int
6412move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6413{
53365c0d
PB
6414 unsigned long tbit;
6415
6416 if (thumb_p)
6417 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6418 else
6419 tbit = LOAD_BIT;
6420
6421 if ((inst.instruction & tbit) == 0)
09d92015 6422 {
c19d1205
ZW
6423 inst.error = _("invalid pseudo operation");
6424 return 1;
09d92015 6425 }
c19d1205 6426 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6427 {
6428 inst.error = _("constant expression expected");
c19d1205 6429 return 1;
09d92015 6430 }
c19d1205 6431 if (inst.reloc.exp.X_op == O_constant)
09d92015 6432 {
c19d1205
ZW
6433 if (thumb_p)
6434 {
53365c0d 6435 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6436 {
6437 /* This can be done with a mov(1) instruction. */
6438 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6439 inst.instruction |= inst.reloc.exp.X_add_number;
6440 return 1;
6441 }
6442 }
6443 else
6444 {
6445 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6446 if (value != FAIL)
6447 {
6448 /* This can be done with a mov instruction. */
6449 inst.instruction &= LITERAL_MASK;
6450 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6451 inst.instruction |= value & 0xfff;
6452 return 1;
6453 }
09d92015 6454
c19d1205
ZW
6455 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6456 if (value != FAIL)
6457 {
6458 /* This can be done with a mvn instruction. */
6459 inst.instruction &= LITERAL_MASK;
6460 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6461 inst.instruction |= value & 0xfff;
6462 return 1;
6463 }
6464 }
09d92015
MM
6465 }
6466
c19d1205
ZW
6467 if (add_to_lit_pool () == FAIL)
6468 {
6469 inst.error = _("literal pool insertion failed");
6470 return 1;
6471 }
6472 inst.operands[1].reg = REG_PC;
6473 inst.operands[1].isreg = 1;
6474 inst.operands[1].preind = 1;
6475 inst.reloc.pc_rel = 1;
6476 inst.reloc.type = (thumb_p
6477 ? BFD_RELOC_ARM_THUMB_OFFSET
6478 : (mode_3
6479 ? BFD_RELOC_ARM_HWLITERAL
6480 : BFD_RELOC_ARM_LITERAL));
6481 return 0;
09d92015
MM
6482}
6483
5f4273c7 6484/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6485 First some generics; their names are taken from the conventional
6486 bit positions for register arguments in ARM format instructions. */
09d92015 6487
a737bd4d 6488static void
c19d1205 6489do_noargs (void)
09d92015 6490{
c19d1205 6491}
a737bd4d 6492
c19d1205
ZW
6493static void
6494do_rd (void)
6495{
6496 inst.instruction |= inst.operands[0].reg << 12;
6497}
a737bd4d 6498
c19d1205
ZW
6499static void
6500do_rd_rm (void)
6501{
6502 inst.instruction |= inst.operands[0].reg << 12;
6503 inst.instruction |= inst.operands[1].reg;
6504}
09d92015 6505
c19d1205
ZW
6506static void
6507do_rd_rn (void)
6508{
6509 inst.instruction |= inst.operands[0].reg << 12;
6510 inst.instruction |= inst.operands[1].reg << 16;
6511}
a737bd4d 6512
c19d1205
ZW
6513static void
6514do_rn_rd (void)
6515{
6516 inst.instruction |= inst.operands[0].reg << 16;
6517 inst.instruction |= inst.operands[1].reg << 12;
6518}
09d92015 6519
c19d1205
ZW
6520static void
6521do_rd_rm_rn (void)
6522{
9a64e435 6523 unsigned Rn = inst.operands[2].reg;
708587a4 6524 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6525 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6526 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6527 _("Rn must not overlap other operands"));
c19d1205
ZW
6528 inst.instruction |= inst.operands[0].reg << 12;
6529 inst.instruction |= inst.operands[1].reg;
9a64e435 6530 inst.instruction |= Rn << 16;
c19d1205 6531}
09d92015 6532
c19d1205
ZW
6533static void
6534do_rd_rn_rm (void)
6535{
6536 inst.instruction |= inst.operands[0].reg << 12;
6537 inst.instruction |= inst.operands[1].reg << 16;
6538 inst.instruction |= inst.operands[2].reg;
6539}
a737bd4d 6540
c19d1205
ZW
6541static void
6542do_rm_rd_rn (void)
6543{
6544 inst.instruction |= inst.operands[0].reg;
6545 inst.instruction |= inst.operands[1].reg << 12;
6546 inst.instruction |= inst.operands[2].reg << 16;
6547}
09d92015 6548
c19d1205
ZW
6549static void
6550do_imm0 (void)
6551{
6552 inst.instruction |= inst.operands[0].imm;
6553}
09d92015 6554
c19d1205
ZW
6555static void
6556do_rd_cpaddr (void)
6557{
6558 inst.instruction |= inst.operands[0].reg << 12;
6559 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6560}
a737bd4d 6561
c19d1205
ZW
6562/* ARM instructions, in alphabetical order by function name (except
6563 that wrapper functions appear immediately after the function they
6564 wrap). */
09d92015 6565
c19d1205
ZW
6566/* This is a pseudo-op of the form "adr rd, label" to be converted
6567 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6568
6569static void
c19d1205 6570do_adr (void)
09d92015 6571{
c19d1205 6572 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6573
c19d1205
ZW
6574 /* Frag hacking will turn this into a sub instruction if the offset turns
6575 out to be negative. */
6576 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6577 inst.reloc.pc_rel = 1;
2fc8bdac 6578 inst.reloc.exp.X_add_number -= 8;
c19d1205 6579}
b99bd4ef 6580
c19d1205
ZW
6581/* This is a pseudo-op of the form "adrl rd, label" to be converted
6582 into a relative address of the form:
6583 add rd, pc, #low(label-.-8)"
6584 add rd, rd, #high(label-.-8)" */
b99bd4ef 6585
c19d1205
ZW
6586static void
6587do_adrl (void)
6588{
6589 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6590
c19d1205
ZW
6591 /* Frag hacking will turn this into a sub instruction if the offset turns
6592 out to be negative. */
6593 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6594 inst.reloc.pc_rel = 1;
6595 inst.size = INSN_SIZE * 2;
2fc8bdac 6596 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6597}
6598
b99bd4ef 6599static void
c19d1205 6600do_arit (void)
b99bd4ef 6601{
c19d1205
ZW
6602 if (!inst.operands[1].present)
6603 inst.operands[1].reg = inst.operands[0].reg;
6604 inst.instruction |= inst.operands[0].reg << 12;
6605 inst.instruction |= inst.operands[1].reg << 16;
6606 encode_arm_shifter_operand (2);
6607}
b99bd4ef 6608
62b3e311
PB
6609static void
6610do_barrier (void)
6611{
6612 if (inst.operands[0].present)
6613 {
6614 constraint ((inst.instruction & 0xf0) != 0x40
6615 && inst.operands[0].imm != 0xf,
bd3ba5d1 6616 _("bad barrier type"));
62b3e311
PB
6617 inst.instruction |= inst.operands[0].imm;
6618 }
6619 else
6620 inst.instruction |= 0xf;
6621}
6622
c19d1205
ZW
6623static void
6624do_bfc (void)
6625{
6626 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6627 constraint (msb > 32, _("bit-field extends past end of register"));
6628 /* The instruction encoding stores the LSB and MSB,
6629 not the LSB and width. */
6630 inst.instruction |= inst.operands[0].reg << 12;
6631 inst.instruction |= inst.operands[1].imm << 7;
6632 inst.instruction |= (msb - 1) << 16;
6633}
b99bd4ef 6634
c19d1205
ZW
6635static void
6636do_bfi (void)
6637{
6638 unsigned int msb;
b99bd4ef 6639
c19d1205
ZW
6640 /* #0 in second position is alternative syntax for bfc, which is
6641 the same instruction but with REG_PC in the Rm field. */
6642 if (!inst.operands[1].isreg)
6643 inst.operands[1].reg = REG_PC;
b99bd4ef 6644
c19d1205
ZW
6645 msb = inst.operands[2].imm + inst.operands[3].imm;
6646 constraint (msb > 32, _("bit-field extends past end of register"));
6647 /* The instruction encoding stores the LSB and MSB,
6648 not the LSB and width. */
6649 inst.instruction |= inst.operands[0].reg << 12;
6650 inst.instruction |= inst.operands[1].reg;
6651 inst.instruction |= inst.operands[2].imm << 7;
6652 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6653}
6654
b99bd4ef 6655static void
c19d1205 6656do_bfx (void)
b99bd4ef 6657{
c19d1205
ZW
6658 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6659 _("bit-field extends past end of register"));
6660 inst.instruction |= inst.operands[0].reg << 12;
6661 inst.instruction |= inst.operands[1].reg;
6662 inst.instruction |= inst.operands[2].imm << 7;
6663 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6664}
09d92015 6665
c19d1205
ZW
6666/* ARM V5 breakpoint instruction (argument parse)
6667 BKPT <16 bit unsigned immediate>
6668 Instruction is not conditional.
6669 The bit pattern given in insns[] has the COND_ALWAYS condition,
6670 and it is an error if the caller tried to override that. */
b99bd4ef 6671
c19d1205
ZW
6672static void
6673do_bkpt (void)
6674{
6675 /* Top 12 of 16 bits to bits 19:8. */
6676 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6677
c19d1205
ZW
6678 /* Bottom 4 of 16 bits to bits 3:0. */
6679 inst.instruction |= inst.operands[0].imm & 0xf;
6680}
09d92015 6681
c19d1205
ZW
6682static void
6683encode_branch (int default_reloc)
6684{
6685 if (inst.operands[0].hasreloc)
6686 {
6687 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6688 _("the only suffix valid here is '(plt)'"));
6689 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6690 }
b99bd4ef 6691 else
c19d1205
ZW
6692 {
6693 inst.reloc.type = default_reloc;
c19d1205 6694 }
2fc8bdac 6695 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6696}
6697
b99bd4ef 6698static void
c19d1205 6699do_branch (void)
b99bd4ef 6700{
39b41c9c
PB
6701#ifdef OBJ_ELF
6702 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6703 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6704 else
6705#endif
6706 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6707}
6708
6709static void
6710do_bl (void)
6711{
6712#ifdef OBJ_ELF
6713 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6714 {
6715 if (inst.cond == COND_ALWAYS)
6716 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6717 else
6718 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6719 }
6720 else
6721#endif
6722 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6723}
b99bd4ef 6724
c19d1205
ZW
6725/* ARM V5 branch-link-exchange instruction (argument parse)
6726 BLX <target_addr> ie BLX(1)
6727 BLX{<condition>} <Rm> ie BLX(2)
6728 Unfortunately, there are two different opcodes for this mnemonic.
6729 So, the insns[].value is not used, and the code here zaps values
6730 into inst.instruction.
6731 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6732
c19d1205
ZW
6733static void
6734do_blx (void)
6735{
6736 if (inst.operands[0].isreg)
b99bd4ef 6737 {
c19d1205
ZW
6738 /* Arg is a register; the opcode provided by insns[] is correct.
6739 It is not illegal to do "blx pc", just useless. */
6740 if (inst.operands[0].reg == REG_PC)
6741 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6742
c19d1205
ZW
6743 inst.instruction |= inst.operands[0].reg;
6744 }
6745 else
b99bd4ef 6746 {
c19d1205
ZW
6747 /* Arg is an address; this instruction cannot be executed
6748 conditionally, and the opcode must be adjusted. */
6749 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6750 inst.instruction = 0xfa000000;
39b41c9c
PB
6751#ifdef OBJ_ELF
6752 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6753 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6754 else
6755#endif
6756 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6757 }
c19d1205
ZW
6758}
6759
6760static void
6761do_bx (void)
6762{
6763 if (inst.operands[0].reg == REG_PC)
6764 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6765
c19d1205 6766 inst.instruction |= inst.operands[0].reg;
09d92015
MM
6767}
6768
c19d1205
ZW
6769
6770/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6771
6772static void
c19d1205 6773do_bxj (void)
a737bd4d 6774{
c19d1205
ZW
6775 if (inst.operands[0].reg == REG_PC)
6776 as_tsktsk (_("use of r15 in bxj is not really useful"));
6777
6778 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6779}
6780
c19d1205
ZW
6781/* Co-processor data operation:
6782 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6783 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6784static void
6785do_cdp (void)
6786{
6787 inst.instruction |= inst.operands[0].reg << 8;
6788 inst.instruction |= inst.operands[1].imm << 20;
6789 inst.instruction |= inst.operands[2].reg << 12;
6790 inst.instruction |= inst.operands[3].reg << 16;
6791 inst.instruction |= inst.operands[4].reg;
6792 inst.instruction |= inst.operands[5].imm << 5;
6793}
a737bd4d
NC
6794
6795static void
c19d1205 6796do_cmp (void)
a737bd4d 6797{
c19d1205
ZW
6798 inst.instruction |= inst.operands[0].reg << 16;
6799 encode_arm_shifter_operand (1);
a737bd4d
NC
6800}
6801
c19d1205
ZW
6802/* Transfer between coprocessor and ARM registers.
6803 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6804 MRC2
6805 MCR{cond}
6806 MCR2
6807
6808 No special properties. */
09d92015
MM
6809
6810static void
c19d1205 6811do_co_reg (void)
09d92015 6812{
c19d1205
ZW
6813 inst.instruction |= inst.operands[0].reg << 8;
6814 inst.instruction |= inst.operands[1].imm << 21;
6815 inst.instruction |= inst.operands[2].reg << 12;
6816 inst.instruction |= inst.operands[3].reg << 16;
6817 inst.instruction |= inst.operands[4].reg;
6818 inst.instruction |= inst.operands[5].imm << 5;
6819}
09d92015 6820
c19d1205
ZW
6821/* Transfer between coprocessor register and pair of ARM registers.
6822 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6823 MCRR2
6824 MRRC{cond}
6825 MRRC2
b99bd4ef 6826
c19d1205 6827 Two XScale instructions are special cases of these:
09d92015 6828
c19d1205
ZW
6829 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6830 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6831
5f4273c7 6832 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6833
c19d1205
ZW
6834static void
6835do_co_reg2c (void)
6836{
6837 inst.instruction |= inst.operands[0].reg << 8;
6838 inst.instruction |= inst.operands[1].imm << 4;
6839 inst.instruction |= inst.operands[2].reg << 12;
6840 inst.instruction |= inst.operands[3].reg << 16;
6841 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6842}
6843
c19d1205
ZW
6844static void
6845do_cpsi (void)
6846{
6847 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6848 if (inst.operands[1].present)
6849 {
6850 inst.instruction |= CPSI_MMOD;
6851 inst.instruction |= inst.operands[1].imm;
6852 }
c19d1205 6853}
b99bd4ef 6854
62b3e311
PB
6855static void
6856do_dbg (void)
6857{
6858 inst.instruction |= inst.operands[0].imm;
6859}
6860
b99bd4ef 6861static void
c19d1205 6862do_it (void)
b99bd4ef 6863{
c19d1205
ZW
6864 /* There is no IT instruction in ARM mode. We
6865 process it but do not generate code for it. */
6866 inst.size = 0;
09d92015 6867}
b99bd4ef 6868
09d92015 6869static void
c19d1205 6870do_ldmstm (void)
ea6ef066 6871{
c19d1205
ZW
6872 int base_reg = inst.operands[0].reg;
6873 int range = inst.operands[1].imm;
ea6ef066 6874
c19d1205
ZW
6875 inst.instruction |= base_reg << 16;
6876 inst.instruction |= range;
ea6ef066 6877
c19d1205
ZW
6878 if (inst.operands[1].writeback)
6879 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6880
c19d1205 6881 if (inst.operands[0].writeback)
ea6ef066 6882 {
c19d1205
ZW
6883 inst.instruction |= WRITE_BACK;
6884 /* Check for unpredictable uses of writeback. */
6885 if (inst.instruction & LOAD_BIT)
09d92015 6886 {
c19d1205
ZW
6887 /* Not allowed in LDM type 2. */
6888 if ((inst.instruction & LDM_TYPE_2_OR_3)
6889 && ((range & (1 << REG_PC)) == 0))
6890 as_warn (_("writeback of base register is UNPREDICTABLE"));
6891 /* Only allowed if base reg not in list for other types. */
6892 else if (range & (1 << base_reg))
6893 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6894 }
6895 else /* STM. */
6896 {
6897 /* Not allowed for type 2. */
6898 if (inst.instruction & LDM_TYPE_2_OR_3)
6899 as_warn (_("writeback of base register is UNPREDICTABLE"));
6900 /* Only allowed if base reg not in list, or first in list. */
6901 else if ((range & (1 << base_reg))
6902 && (range & ((1 << base_reg) - 1)))
6903 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6904 }
ea6ef066 6905 }
a737bd4d
NC
6906}
6907
c19d1205
ZW
6908/* ARMv5TE load-consecutive (argument parse)
6909 Mode is like LDRH.
6910
6911 LDRccD R, mode
6912 STRccD R, mode. */
6913
a737bd4d 6914static void
c19d1205 6915do_ldrd (void)
a737bd4d 6916{
c19d1205
ZW
6917 constraint (inst.operands[0].reg % 2 != 0,
6918 _("first destination register must be even"));
6919 constraint (inst.operands[1].present
6920 && inst.operands[1].reg != inst.operands[0].reg + 1,
6921 _("can only load two consecutive registers"));
6922 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6923 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6924
c19d1205
ZW
6925 if (!inst.operands[1].present)
6926 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 6927
c19d1205 6928 if (inst.instruction & LOAD_BIT)
a737bd4d 6929 {
c19d1205
ZW
6930 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6931 register and the first register written; we have to diagnose
6932 overlap between the base and the second register written here. */
ea6ef066 6933
c19d1205
ZW
6934 if (inst.operands[2].reg == inst.operands[1].reg
6935 && (inst.operands[2].writeback || inst.operands[2].postind))
6936 as_warn (_("base register written back, and overlaps "
6937 "second destination register"));
b05fe5cf 6938
c19d1205
ZW
6939 /* For an index-register load, the index register must not overlap the
6940 destination (even if not write-back). */
6941 else if (inst.operands[2].immisreg
ca3f61f7
NC
6942 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6943 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6944 as_warn (_("index register overlaps destination register"));
b05fe5cf 6945 }
c19d1205
ZW
6946
6947 inst.instruction |= inst.operands[0].reg << 12;
6948 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6949}
6950
6951static void
c19d1205 6952do_ldrex (void)
b05fe5cf 6953{
c19d1205
ZW
6954 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6955 || inst.operands[1].postind || inst.operands[1].writeback
6956 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6957 || inst.operands[1].negative
6958 /* This can arise if the programmer has written
6959 strex rN, rM, foo
6960 or if they have mistakenly used a register name as the last
6961 operand, eg:
6962 strex rN, rM, rX
6963 It is very difficult to distinguish between these two cases
6964 because "rX" might actually be a label. ie the register
6965 name has been occluded by a symbol of the same name. So we
6966 just generate a general 'bad addressing mode' type error
6967 message and leave it up to the programmer to discover the
6968 true cause and fix their mistake. */
6969 || (inst.operands[1].reg == REG_PC),
6970 BAD_ADDR_MODE);
b05fe5cf 6971
c19d1205
ZW
6972 constraint (inst.reloc.exp.X_op != O_constant
6973 || inst.reloc.exp.X_add_number != 0,
6974 _("offset must be zero in ARM encoding"));
b05fe5cf 6975
c19d1205
ZW
6976 inst.instruction |= inst.operands[0].reg << 12;
6977 inst.instruction |= inst.operands[1].reg << 16;
6978 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
6979}
6980
6981static void
c19d1205 6982do_ldrexd (void)
b05fe5cf 6983{
c19d1205
ZW
6984 constraint (inst.operands[0].reg % 2 != 0,
6985 _("even register required"));
6986 constraint (inst.operands[1].present
6987 && inst.operands[1].reg != inst.operands[0].reg + 1,
6988 _("can only load two consecutive registers"));
6989 /* If op 1 were present and equal to PC, this function wouldn't
6990 have been called in the first place. */
6991 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 6992
c19d1205
ZW
6993 inst.instruction |= inst.operands[0].reg << 12;
6994 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
6995}
6996
6997static void
c19d1205 6998do_ldst (void)
b05fe5cf 6999{
c19d1205
ZW
7000 inst.instruction |= inst.operands[0].reg << 12;
7001 if (!inst.operands[1].isreg)
7002 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7003 return;
c19d1205 7004 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7005}
7006
7007static void
c19d1205 7008do_ldstt (void)
b05fe5cf 7009{
c19d1205
ZW
7010 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7011 reject [Rn,...]. */
7012 if (inst.operands[1].preind)
b05fe5cf 7013 {
bd3ba5d1
NC
7014 constraint (inst.reloc.exp.X_op != O_constant
7015 || inst.reloc.exp.X_add_number != 0,
c19d1205 7016 _("this instruction requires a post-indexed address"));
b05fe5cf 7017
c19d1205
ZW
7018 inst.operands[1].preind = 0;
7019 inst.operands[1].postind = 1;
7020 inst.operands[1].writeback = 1;
b05fe5cf 7021 }
c19d1205
ZW
7022 inst.instruction |= inst.operands[0].reg << 12;
7023 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7024}
b05fe5cf 7025
c19d1205 7026/* Halfword and signed-byte load/store operations. */
b05fe5cf 7027
c19d1205
ZW
7028static void
7029do_ldstv4 (void)
7030{
7031 inst.instruction |= inst.operands[0].reg << 12;
7032 if (!inst.operands[1].isreg)
7033 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7034 return;
c19d1205 7035 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7036}
7037
7038static void
c19d1205 7039do_ldsttv4 (void)
b05fe5cf 7040{
c19d1205
ZW
7041 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7042 reject [Rn,...]. */
7043 if (inst.operands[1].preind)
b05fe5cf 7044 {
bd3ba5d1
NC
7045 constraint (inst.reloc.exp.X_op != O_constant
7046 || inst.reloc.exp.X_add_number != 0,
c19d1205 7047 _("this instruction requires a post-indexed address"));
b05fe5cf 7048
c19d1205
ZW
7049 inst.operands[1].preind = 0;
7050 inst.operands[1].postind = 1;
7051 inst.operands[1].writeback = 1;
b05fe5cf 7052 }
c19d1205
ZW
7053 inst.instruction |= inst.operands[0].reg << 12;
7054 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7055}
b05fe5cf 7056
c19d1205
ZW
7057/* Co-processor register load/store.
7058 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7059static void
7060do_lstc (void)
7061{
7062 inst.instruction |= inst.operands[0].reg << 8;
7063 inst.instruction |= inst.operands[1].reg << 12;
7064 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7065}
7066
b05fe5cf 7067static void
c19d1205 7068do_mlas (void)
b05fe5cf 7069{
8fb9d7b9 7070 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7071 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7072 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7073 && !(inst.instruction & 0x00400000))
8fb9d7b9 7074 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7075
c19d1205
ZW
7076 inst.instruction |= inst.operands[0].reg << 16;
7077 inst.instruction |= inst.operands[1].reg;
7078 inst.instruction |= inst.operands[2].reg << 8;
7079 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7080}
b05fe5cf 7081
c19d1205
ZW
7082static void
7083do_mov (void)
7084{
7085 inst.instruction |= inst.operands[0].reg << 12;
7086 encode_arm_shifter_operand (1);
7087}
b05fe5cf 7088
c19d1205
ZW
7089/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7090static void
7091do_mov16 (void)
7092{
b6895b4f
PB
7093 bfd_vma imm;
7094 bfd_boolean top;
7095
7096 top = (inst.instruction & 0x00400000) != 0;
7097 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7098 _(":lower16: not allowed this instruction"));
7099 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7100 _(":upper16: not allowed instruction"));
c19d1205 7101 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7102 if (inst.reloc.type == BFD_RELOC_UNUSED)
7103 {
7104 imm = inst.reloc.exp.X_add_number;
7105 /* The value is in two pieces: 0:11, 16:19. */
7106 inst.instruction |= (imm & 0x00000fff);
7107 inst.instruction |= (imm & 0x0000f000) << 4;
7108 }
b05fe5cf 7109}
b99bd4ef 7110
037e8744
JB
7111static void do_vfp_nsyn_opcode (const char *);
7112
7113static int
7114do_vfp_nsyn_mrs (void)
7115{
7116 if (inst.operands[0].isvec)
7117 {
7118 if (inst.operands[1].reg != 1)
7119 first_error (_("operand 1 must be FPSCR"));
7120 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7121 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7122 do_vfp_nsyn_opcode ("fmstat");
7123 }
7124 else if (inst.operands[1].isvec)
7125 do_vfp_nsyn_opcode ("fmrx");
7126 else
7127 return FAIL;
5f4273c7 7128
037e8744
JB
7129 return SUCCESS;
7130}
7131
7132static int
7133do_vfp_nsyn_msr (void)
7134{
7135 if (inst.operands[0].isvec)
7136 do_vfp_nsyn_opcode ("fmxr");
7137 else
7138 return FAIL;
7139
7140 return SUCCESS;
7141}
7142
b99bd4ef 7143static void
c19d1205 7144do_mrs (void)
b99bd4ef 7145{
037e8744
JB
7146 if (do_vfp_nsyn_mrs () == SUCCESS)
7147 return;
7148
c19d1205
ZW
7149 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7150 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7151 != (PSR_c|PSR_f),
7152 _("'CPSR' or 'SPSR' expected"));
7153 inst.instruction |= inst.operands[0].reg << 12;
7154 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7155}
b99bd4ef 7156
c19d1205
ZW
7157/* Two possible forms:
7158 "{C|S}PSR_<field>, Rm",
7159 "{C|S}PSR_f, #expression". */
b99bd4ef 7160
c19d1205
ZW
7161static void
7162do_msr (void)
7163{
037e8744
JB
7164 if (do_vfp_nsyn_msr () == SUCCESS)
7165 return;
7166
c19d1205
ZW
7167 inst.instruction |= inst.operands[0].imm;
7168 if (inst.operands[1].isreg)
7169 inst.instruction |= inst.operands[1].reg;
7170 else
b99bd4ef 7171 {
c19d1205
ZW
7172 inst.instruction |= INST_IMMEDIATE;
7173 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7174 inst.reloc.pc_rel = 0;
b99bd4ef 7175 }
b99bd4ef
NC
7176}
7177
c19d1205
ZW
7178static void
7179do_mul (void)
a737bd4d 7180{
c19d1205
ZW
7181 if (!inst.operands[2].present)
7182 inst.operands[2].reg = inst.operands[0].reg;
7183 inst.instruction |= inst.operands[0].reg << 16;
7184 inst.instruction |= inst.operands[1].reg;
7185 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7186
8fb9d7b9
MS
7187 if (inst.operands[0].reg == inst.operands[1].reg
7188 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7189 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7190}
7191
c19d1205
ZW
7192/* Long Multiply Parser
7193 UMULL RdLo, RdHi, Rm, Rs
7194 SMULL RdLo, RdHi, Rm, Rs
7195 UMLAL RdLo, RdHi, Rm, Rs
7196 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7197
7198static void
c19d1205 7199do_mull (void)
b99bd4ef 7200{
c19d1205
ZW
7201 inst.instruction |= inst.operands[0].reg << 12;
7202 inst.instruction |= inst.operands[1].reg << 16;
7203 inst.instruction |= inst.operands[2].reg;
7204 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7205
682b27ad
PB
7206 /* rdhi and rdlo must be different. */
7207 if (inst.operands[0].reg == inst.operands[1].reg)
7208 as_tsktsk (_("rdhi and rdlo must be different"));
7209
7210 /* rdhi, rdlo and rm must all be different before armv6. */
7211 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7212 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7213 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7214 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7215}
b99bd4ef 7216
c19d1205
ZW
7217static void
7218do_nop (void)
7219{
7220 if (inst.operands[0].present)
7221 {
7222 /* Architectural NOP hints are CPSR sets with no bits selected. */
7223 inst.instruction &= 0xf0000000;
7224 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7225 }
b99bd4ef
NC
7226}
7227
c19d1205
ZW
7228/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7229 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7230 Condition defaults to COND_ALWAYS.
7231 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7232
7233static void
c19d1205 7234do_pkhbt (void)
b99bd4ef 7235{
c19d1205
ZW
7236 inst.instruction |= inst.operands[0].reg << 12;
7237 inst.instruction |= inst.operands[1].reg << 16;
7238 inst.instruction |= inst.operands[2].reg;
7239 if (inst.operands[3].present)
7240 encode_arm_shift (3);
7241}
b99bd4ef 7242
c19d1205 7243/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7244
c19d1205
ZW
7245static void
7246do_pkhtb (void)
7247{
7248 if (!inst.operands[3].present)
b99bd4ef 7249 {
c19d1205
ZW
7250 /* If the shift specifier is omitted, turn the instruction
7251 into pkhbt rd, rm, rn. */
7252 inst.instruction &= 0xfff00010;
7253 inst.instruction |= inst.operands[0].reg << 12;
7254 inst.instruction |= inst.operands[1].reg;
7255 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7256 }
7257 else
7258 {
c19d1205
ZW
7259 inst.instruction |= inst.operands[0].reg << 12;
7260 inst.instruction |= inst.operands[1].reg << 16;
7261 inst.instruction |= inst.operands[2].reg;
7262 encode_arm_shift (3);
b99bd4ef
NC
7263 }
7264}
7265
c19d1205
ZW
7266/* ARMv5TE: Preload-Cache
7267
7268 PLD <addr_mode>
7269
7270 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7271
7272static void
c19d1205 7273do_pld (void)
b99bd4ef 7274{
c19d1205
ZW
7275 constraint (!inst.operands[0].isreg,
7276 _("'[' expected after PLD mnemonic"));
7277 constraint (inst.operands[0].postind,
7278 _("post-indexed expression used in preload instruction"));
7279 constraint (inst.operands[0].writeback,
7280 _("writeback used in preload instruction"));
7281 constraint (!inst.operands[0].preind,
7282 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7283 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7284}
b99bd4ef 7285
62b3e311
PB
7286/* ARMv7: PLI <addr_mode> */
7287static void
7288do_pli (void)
7289{
7290 constraint (!inst.operands[0].isreg,
7291 _("'[' expected after PLI mnemonic"));
7292 constraint (inst.operands[0].postind,
7293 _("post-indexed expression used in preload instruction"));
7294 constraint (inst.operands[0].writeback,
7295 _("writeback used in preload instruction"));
7296 constraint (!inst.operands[0].preind,
7297 _("unindexed addressing used in preload instruction"));
7298 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7299 inst.instruction &= ~PRE_INDEX;
7300}
7301
c19d1205
ZW
7302static void
7303do_push_pop (void)
7304{
7305 inst.operands[1] = inst.operands[0];
7306 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7307 inst.operands[0].isreg = 1;
7308 inst.operands[0].writeback = 1;
7309 inst.operands[0].reg = REG_SP;
7310 do_ldmstm ();
7311}
b99bd4ef 7312
c19d1205
ZW
7313/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7314 word at the specified address and the following word
7315 respectively.
7316 Unconditionally executed.
7317 Error if Rn is R15. */
b99bd4ef 7318
c19d1205
ZW
7319static void
7320do_rfe (void)
7321{
7322 inst.instruction |= inst.operands[0].reg << 16;
7323 if (inst.operands[0].writeback)
7324 inst.instruction |= WRITE_BACK;
7325}
b99bd4ef 7326
c19d1205 7327/* ARM V6 ssat (argument parse). */
b99bd4ef 7328
c19d1205
ZW
7329static void
7330do_ssat (void)
7331{
7332 inst.instruction |= inst.operands[0].reg << 12;
7333 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7334 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7335
c19d1205
ZW
7336 if (inst.operands[3].present)
7337 encode_arm_shift (3);
b99bd4ef
NC
7338}
7339
c19d1205 7340/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7341
7342static void
c19d1205 7343do_usat (void)
b99bd4ef 7344{
c19d1205
ZW
7345 inst.instruction |= inst.operands[0].reg << 12;
7346 inst.instruction |= inst.operands[1].imm << 16;
7347 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7348
c19d1205
ZW
7349 if (inst.operands[3].present)
7350 encode_arm_shift (3);
b99bd4ef
NC
7351}
7352
c19d1205 7353/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7354
7355static void
c19d1205 7356do_ssat16 (void)
09d92015 7357{
c19d1205
ZW
7358 inst.instruction |= inst.operands[0].reg << 12;
7359 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7360 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7361}
7362
c19d1205
ZW
7363static void
7364do_usat16 (void)
a737bd4d 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;
7369}
a737bd4d 7370
c19d1205
ZW
7371/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7372 preserving the other bits.
a737bd4d 7373
c19d1205
ZW
7374 setend <endian_specifier>, where <endian_specifier> is either
7375 BE or LE. */
a737bd4d 7376
c19d1205
ZW
7377static void
7378do_setend (void)
7379{
7380 if (inst.operands[0].imm)
7381 inst.instruction |= 0x200;
a737bd4d
NC
7382}
7383
7384static void
c19d1205 7385do_shift (void)
a737bd4d 7386{
c19d1205
ZW
7387 unsigned int Rm = (inst.operands[1].present
7388 ? inst.operands[1].reg
7389 : inst.operands[0].reg);
a737bd4d 7390
c19d1205
ZW
7391 inst.instruction |= inst.operands[0].reg << 12;
7392 inst.instruction |= Rm;
7393 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7394 {
c19d1205
ZW
7395 inst.instruction |= inst.operands[2].reg << 8;
7396 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7397 }
7398 else
c19d1205 7399 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7400}
7401
09d92015 7402static void
3eb17e6b 7403do_smc (void)
09d92015 7404{
3eb17e6b 7405 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7406 inst.reloc.pc_rel = 0;
09d92015
MM
7407}
7408
09d92015 7409static void
c19d1205 7410do_swi (void)
09d92015 7411{
c19d1205
ZW
7412 inst.reloc.type = BFD_RELOC_ARM_SWI;
7413 inst.reloc.pc_rel = 0;
09d92015
MM
7414}
7415
c19d1205
ZW
7416/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7417 SMLAxy{cond} Rd,Rm,Rs,Rn
7418 SMLAWy{cond} Rd,Rm,Rs,Rn
7419 Error if any register is R15. */
e16bb312 7420
c19d1205
ZW
7421static void
7422do_smla (void)
e16bb312 7423{
c19d1205
ZW
7424 inst.instruction |= inst.operands[0].reg << 16;
7425 inst.instruction |= inst.operands[1].reg;
7426 inst.instruction |= inst.operands[2].reg << 8;
7427 inst.instruction |= inst.operands[3].reg << 12;
7428}
a737bd4d 7429
c19d1205
ZW
7430/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7431 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7432 Error if any register is R15.
7433 Warning if Rdlo == Rdhi. */
a737bd4d 7434
c19d1205
ZW
7435static void
7436do_smlal (void)
7437{
7438 inst.instruction |= inst.operands[0].reg << 12;
7439 inst.instruction |= inst.operands[1].reg << 16;
7440 inst.instruction |= inst.operands[2].reg;
7441 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7442
c19d1205
ZW
7443 if (inst.operands[0].reg == inst.operands[1].reg)
7444 as_tsktsk (_("rdhi and rdlo must be different"));
7445}
a737bd4d 7446
c19d1205
ZW
7447/* ARM V5E (El Segundo) signed-multiply (argument parse)
7448 SMULxy{cond} Rd,Rm,Rs
7449 Error if any register is R15. */
a737bd4d 7450
c19d1205
ZW
7451static void
7452do_smul (void)
7453{
7454 inst.instruction |= inst.operands[0].reg << 16;
7455 inst.instruction |= inst.operands[1].reg;
7456 inst.instruction |= inst.operands[2].reg << 8;
7457}
a737bd4d 7458
b6702015
PB
7459/* ARM V6 srs (argument parse). The variable fields in the encoding are
7460 the same for both ARM and Thumb-2. */
a737bd4d 7461
c19d1205
ZW
7462static void
7463do_srs (void)
7464{
b6702015
PB
7465 int reg;
7466
7467 if (inst.operands[0].present)
7468 {
7469 reg = inst.operands[0].reg;
7470 constraint (reg != 13, _("SRS base register must be r13"));
7471 }
7472 else
7473 reg = 13;
7474
7475 inst.instruction |= reg << 16;
7476 inst.instruction |= inst.operands[1].imm;
7477 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7478 inst.instruction |= WRITE_BACK;
7479}
a737bd4d 7480
c19d1205 7481/* ARM V6 strex (argument parse). */
a737bd4d 7482
c19d1205
ZW
7483static void
7484do_strex (void)
7485{
7486 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7487 || inst.operands[2].postind || inst.operands[2].writeback
7488 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7489 || inst.operands[2].negative
7490 /* See comment in do_ldrex(). */
7491 || (inst.operands[2].reg == REG_PC),
7492 BAD_ADDR_MODE);
a737bd4d 7493
c19d1205
ZW
7494 constraint (inst.operands[0].reg == inst.operands[1].reg
7495 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7496
c19d1205
ZW
7497 constraint (inst.reloc.exp.X_op != O_constant
7498 || inst.reloc.exp.X_add_number != 0,
7499 _("offset must be zero in ARM encoding"));
a737bd4d 7500
c19d1205
ZW
7501 inst.instruction |= inst.operands[0].reg << 12;
7502 inst.instruction |= inst.operands[1].reg;
7503 inst.instruction |= inst.operands[2].reg << 16;
7504 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7505}
7506
7507static void
c19d1205 7508do_strexd (void)
e16bb312 7509{
c19d1205
ZW
7510 constraint (inst.operands[1].reg % 2 != 0,
7511 _("even register required"));
7512 constraint (inst.operands[2].present
7513 && inst.operands[2].reg != inst.operands[1].reg + 1,
7514 _("can only store two consecutive registers"));
7515 /* If op 2 were present and equal to PC, this function wouldn't
7516 have been called in the first place. */
7517 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7518
c19d1205
ZW
7519 constraint (inst.operands[0].reg == inst.operands[1].reg
7520 || inst.operands[0].reg == inst.operands[1].reg + 1
7521 || inst.operands[0].reg == inst.operands[3].reg,
7522 BAD_OVERLAP);
e16bb312 7523
c19d1205
ZW
7524 inst.instruction |= inst.operands[0].reg << 12;
7525 inst.instruction |= inst.operands[1].reg;
7526 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7527}
7528
c19d1205
ZW
7529/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7530 extends it to 32-bits, and adds the result to a value in another
7531 register. You can specify a rotation by 0, 8, 16, or 24 bits
7532 before extracting the 16-bit value.
7533 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7534 Condition defaults to COND_ALWAYS.
7535 Error if any register uses R15. */
7536
e16bb312 7537static void
c19d1205 7538do_sxtah (void)
e16bb312 7539{
c19d1205
ZW
7540 inst.instruction |= inst.operands[0].reg << 12;
7541 inst.instruction |= inst.operands[1].reg << 16;
7542 inst.instruction |= inst.operands[2].reg;
7543 inst.instruction |= inst.operands[3].imm << 10;
7544}
e16bb312 7545
c19d1205 7546/* ARM V6 SXTH.
e16bb312 7547
c19d1205
ZW
7548 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7549 Condition defaults to COND_ALWAYS.
7550 Error if any register uses R15. */
e16bb312
NC
7551
7552static void
c19d1205 7553do_sxth (void)
e16bb312 7554{
c19d1205
ZW
7555 inst.instruction |= inst.operands[0].reg << 12;
7556 inst.instruction |= inst.operands[1].reg;
7557 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7558}
c19d1205
ZW
7559\f
7560/* VFP instructions. In a logical order: SP variant first, monad
7561 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7562
7563static void
c19d1205 7564do_vfp_sp_monadic (void)
e16bb312 7565{
5287ad62
JB
7566 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7567 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7568}
7569
7570static void
c19d1205 7571do_vfp_sp_dyadic (void)
e16bb312 7572{
5287ad62
JB
7573 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7575 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7576}
7577
7578static void
c19d1205 7579do_vfp_sp_compare_z (void)
e16bb312 7580{
5287ad62 7581 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7582}
7583
7584static void
c19d1205 7585do_vfp_dp_sp_cvt (void)
e16bb312 7586{
5287ad62
JB
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7589}
7590
7591static void
c19d1205 7592do_vfp_sp_dp_cvt (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_Dm);
e16bb312
NC
7596}
7597
7598static void
c19d1205 7599do_vfp_reg_from_sp (void)
e16bb312 7600{
c19d1205 7601 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7602 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7603}
7604
7605static void
c19d1205 7606do_vfp_reg2_from_sp2 (void)
e16bb312 7607{
c19d1205
ZW
7608 constraint (inst.operands[2].imm != 2,
7609 _("only two consecutive VFP SP registers allowed here"));
7610 inst.instruction |= inst.operands[0].reg << 12;
7611 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7612 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7613}
7614
7615static void
c19d1205 7616do_vfp_sp_from_reg (void)
e16bb312 7617{
5287ad62 7618 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7619 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7620}
7621
7622static void
c19d1205 7623do_vfp_sp2_from_reg2 (void)
e16bb312 7624{
c19d1205
ZW
7625 constraint (inst.operands[0].imm != 2,
7626 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7627 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7628 inst.instruction |= inst.operands[1].reg << 12;
7629 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7630}
7631
7632static void
c19d1205 7633do_vfp_sp_ldst (void)
e16bb312 7634{
5287ad62 7635 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7636 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7637}
7638
7639static void
c19d1205 7640do_vfp_dp_ldst (void)
e16bb312 7641{
5287ad62 7642 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7643 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7644}
7645
c19d1205 7646
e16bb312 7647static void
c19d1205 7648vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7649{
c19d1205
ZW
7650 if (inst.operands[0].writeback)
7651 inst.instruction |= WRITE_BACK;
7652 else
7653 constraint (ldstm_type != VFP_LDSTMIA,
7654 _("this addressing mode requires base-register writeback"));
7655 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7656 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7657 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7658}
7659
7660static void
c19d1205 7661vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7662{
c19d1205 7663 int count;
e16bb312 7664
c19d1205
ZW
7665 if (inst.operands[0].writeback)
7666 inst.instruction |= WRITE_BACK;
7667 else
7668 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7669 _("this addressing mode requires base-register writeback"));
e16bb312 7670
c19d1205 7671 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7672 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7673
c19d1205
ZW
7674 count = inst.operands[1].imm << 1;
7675 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7676 count += 1;
e16bb312 7677
c19d1205 7678 inst.instruction |= count;
e16bb312
NC
7679}
7680
7681static void
c19d1205 7682do_vfp_sp_ldstmia (void)
e16bb312 7683{
c19d1205 7684 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7685}
7686
7687static void
c19d1205 7688do_vfp_sp_ldstmdb (void)
e16bb312 7689{
c19d1205 7690 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7691}
7692
7693static void
c19d1205 7694do_vfp_dp_ldstmia (void)
e16bb312 7695{
c19d1205 7696 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7697}
7698
7699static void
c19d1205 7700do_vfp_dp_ldstmdb (void)
e16bb312 7701{
c19d1205 7702 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7703}
7704
7705static void
c19d1205 7706do_vfp_xp_ldstmia (void)
e16bb312 7707{
c19d1205
ZW
7708 vfp_dp_ldstm (VFP_LDSTMIAX);
7709}
e16bb312 7710
c19d1205
ZW
7711static void
7712do_vfp_xp_ldstmdb (void)
7713{
7714 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7715}
5287ad62
JB
7716
7717static void
7718do_vfp_dp_rd_rm (void)
7719{
7720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7721 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7722}
7723
7724static void
7725do_vfp_dp_rn_rd (void)
7726{
7727 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7728 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7729}
7730
7731static void
7732do_vfp_dp_rd_rn (void)
7733{
7734 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7735 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7736}
7737
7738static void
7739do_vfp_dp_rd_rn_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_Dn);
7743 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7744}
7745
7746static void
7747do_vfp_dp_rd (void)
7748{
7749 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7750}
7751
7752static void
7753do_vfp_dp_rm_rd_rn (void)
7754{
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7757 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7758}
7759
7760/* VFPv3 instructions. */
7761static void
7762do_vfp_sp_const (void)
7763{
7764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7765 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7766 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7767}
7768
7769static void
7770do_vfp_dp_const (void)
7771{
7772 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7773 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7774 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7775}
7776
7777static void
7778vfp_conv (int srcsize)
7779{
7780 unsigned immbits = srcsize - inst.operands[1].imm;
7781 inst.instruction |= (immbits & 1) << 5;
7782 inst.instruction |= (immbits >> 1);
7783}
7784
7785static void
7786do_vfp_sp_conv_16 (void)
7787{
7788 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7789 vfp_conv (16);
7790}
7791
7792static void
7793do_vfp_dp_conv_16 (void)
7794{
7795 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7796 vfp_conv (16);
7797}
7798
7799static void
7800do_vfp_sp_conv_32 (void)
7801{
7802 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7803 vfp_conv (32);
7804}
7805
7806static void
7807do_vfp_dp_conv_32 (void)
7808{
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7810 vfp_conv (32);
7811}
c19d1205
ZW
7812\f
7813/* FPA instructions. Also in a logical order. */
e16bb312 7814
c19d1205
ZW
7815static void
7816do_fpa_cmp (void)
7817{
7818 inst.instruction |= inst.operands[0].reg << 16;
7819 inst.instruction |= inst.operands[1].reg;
7820}
b99bd4ef
NC
7821
7822static void
c19d1205 7823do_fpa_ldmstm (void)
b99bd4ef 7824{
c19d1205
ZW
7825 inst.instruction |= inst.operands[0].reg << 12;
7826 switch (inst.operands[1].imm)
7827 {
7828 case 1: inst.instruction |= CP_T_X; break;
7829 case 2: inst.instruction |= CP_T_Y; break;
7830 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7831 case 4: break;
7832 default: abort ();
7833 }
b99bd4ef 7834
c19d1205
ZW
7835 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7836 {
7837 /* The instruction specified "ea" or "fd", so we can only accept
7838 [Rn]{!}. The instruction does not really support stacking or
7839 unstacking, so we have to emulate these by setting appropriate
7840 bits and offsets. */
7841 constraint (inst.reloc.exp.X_op != O_constant
7842 || inst.reloc.exp.X_add_number != 0,
7843 _("this instruction does not support indexing"));
b99bd4ef 7844
c19d1205
ZW
7845 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7846 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7847
c19d1205
ZW
7848 if (!(inst.instruction & INDEX_UP))
7849 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7850
c19d1205
ZW
7851 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7852 {
7853 inst.operands[2].preind = 0;
7854 inst.operands[2].postind = 1;
7855 }
7856 }
b99bd4ef 7857
c19d1205 7858 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7859}
c19d1205
ZW
7860\f
7861/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7862
c19d1205
ZW
7863static void
7864do_iwmmxt_tandorc (void)
7865{
7866 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7867}
b99bd4ef 7868
c19d1205
ZW
7869static void
7870do_iwmmxt_textrc (void)
7871{
7872 inst.instruction |= inst.operands[0].reg << 12;
7873 inst.instruction |= inst.operands[1].imm;
7874}
b99bd4ef
NC
7875
7876static void
c19d1205 7877do_iwmmxt_textrm (void)
b99bd4ef 7878{
c19d1205
ZW
7879 inst.instruction |= inst.operands[0].reg << 12;
7880 inst.instruction |= inst.operands[1].reg << 16;
7881 inst.instruction |= inst.operands[2].imm;
7882}
b99bd4ef 7883
c19d1205
ZW
7884static void
7885do_iwmmxt_tinsr (void)
7886{
7887 inst.instruction |= inst.operands[0].reg << 16;
7888 inst.instruction |= inst.operands[1].reg << 12;
7889 inst.instruction |= inst.operands[2].imm;
7890}
b99bd4ef 7891
c19d1205
ZW
7892static void
7893do_iwmmxt_tmia (void)
7894{
7895 inst.instruction |= inst.operands[0].reg << 5;
7896 inst.instruction |= inst.operands[1].reg;
7897 inst.instruction |= inst.operands[2].reg << 12;
7898}
b99bd4ef 7899
c19d1205
ZW
7900static void
7901do_iwmmxt_waligni (void)
7902{
7903 inst.instruction |= inst.operands[0].reg << 12;
7904 inst.instruction |= inst.operands[1].reg << 16;
7905 inst.instruction |= inst.operands[2].reg;
7906 inst.instruction |= inst.operands[3].imm << 20;
7907}
b99bd4ef 7908
2d447fca
JM
7909static void
7910do_iwmmxt_wmerge (void)
7911{
7912 inst.instruction |= inst.operands[0].reg << 12;
7913 inst.instruction |= inst.operands[1].reg << 16;
7914 inst.instruction |= inst.operands[2].reg;
7915 inst.instruction |= inst.operands[3].imm << 21;
7916}
7917
c19d1205
ZW
7918static void
7919do_iwmmxt_wmov (void)
7920{
7921 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7922 inst.instruction |= inst.operands[0].reg << 12;
7923 inst.instruction |= inst.operands[1].reg << 16;
7924 inst.instruction |= inst.operands[1].reg;
7925}
b99bd4ef 7926
c19d1205
ZW
7927static void
7928do_iwmmxt_wldstbh (void)
7929{
8f06b2d8 7930 int reloc;
c19d1205 7931 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7932 if (thumb_mode)
7933 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7934 else
7935 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7936 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7937}
7938
c19d1205
ZW
7939static void
7940do_iwmmxt_wldstw (void)
7941{
7942 /* RIWR_RIWC clears .isreg for a control register. */
7943 if (!inst.operands[0].isreg)
7944 {
7945 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7946 inst.instruction |= 0xf0000000;
7947 }
b99bd4ef 7948
c19d1205
ZW
7949 inst.instruction |= inst.operands[0].reg << 12;
7950 encode_arm_cp_address (1, TRUE, TRUE, 0);
7951}
b99bd4ef
NC
7952
7953static void
c19d1205 7954do_iwmmxt_wldstd (void)
b99bd4ef 7955{
c19d1205 7956 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7957 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7958 && inst.operands[1].immisreg)
7959 {
7960 inst.instruction &= ~0x1a000ff;
7961 inst.instruction |= (0xf << 28);
7962 if (inst.operands[1].preind)
7963 inst.instruction |= PRE_INDEX;
7964 if (!inst.operands[1].negative)
7965 inst.instruction |= INDEX_UP;
7966 if (inst.operands[1].writeback)
7967 inst.instruction |= WRITE_BACK;
7968 inst.instruction |= inst.operands[1].reg << 16;
7969 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7970 inst.instruction |= inst.operands[1].imm;
7971 }
7972 else
7973 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 7974}
b99bd4ef 7975
c19d1205
ZW
7976static void
7977do_iwmmxt_wshufh (void)
7978{
7979 inst.instruction |= inst.operands[0].reg << 12;
7980 inst.instruction |= inst.operands[1].reg << 16;
7981 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7982 inst.instruction |= (inst.operands[2].imm & 0x0f);
7983}
b99bd4ef 7984
c19d1205
ZW
7985static void
7986do_iwmmxt_wzero (void)
7987{
7988 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7989 inst.instruction |= inst.operands[0].reg;
7990 inst.instruction |= inst.operands[0].reg << 12;
7991 inst.instruction |= inst.operands[0].reg << 16;
7992}
2d447fca
JM
7993
7994static void
7995do_iwmmxt_wrwrwr_or_imm5 (void)
7996{
7997 if (inst.operands[2].isreg)
7998 do_rd_rn_rm ();
7999 else {
8000 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8001 _("immediate operand requires iWMMXt2"));
8002 do_rd_rn ();
8003 if (inst.operands[2].imm == 0)
8004 {
8005 switch ((inst.instruction >> 20) & 0xf)
8006 {
8007 case 4:
8008 case 5:
8009 case 6:
5f4273c7 8010 case 7:
2d447fca
JM
8011 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8012 inst.operands[2].imm = 16;
8013 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8014 break;
8015 case 8:
8016 case 9:
8017 case 10:
8018 case 11:
8019 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8020 inst.operands[2].imm = 32;
8021 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8022 break;
8023 case 12:
8024 case 13:
8025 case 14:
8026 case 15:
8027 {
8028 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8029 unsigned long wrn;
8030 wrn = (inst.instruction >> 16) & 0xf;
8031 inst.instruction &= 0xff0fff0f;
8032 inst.instruction |= wrn;
8033 /* Bail out here; the instruction is now assembled. */
8034 return;
8035 }
8036 }
8037 }
8038 /* Map 32 -> 0, etc. */
8039 inst.operands[2].imm &= 0x1f;
8040 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8041 }
8042}
c19d1205
ZW
8043\f
8044/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8045 operations first, then control, shift, and load/store. */
b99bd4ef 8046
c19d1205 8047/* Insns like "foo X,Y,Z". */
b99bd4ef 8048
c19d1205
ZW
8049static void
8050do_mav_triple (void)
8051{
8052 inst.instruction |= inst.operands[0].reg << 16;
8053 inst.instruction |= inst.operands[1].reg;
8054 inst.instruction |= inst.operands[2].reg << 12;
8055}
b99bd4ef 8056
c19d1205
ZW
8057/* Insns like "foo W,X,Y,Z".
8058 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8059
c19d1205
ZW
8060static void
8061do_mav_quad (void)
8062{
8063 inst.instruction |= inst.operands[0].reg << 5;
8064 inst.instruction |= inst.operands[1].reg << 12;
8065 inst.instruction |= inst.operands[2].reg << 16;
8066 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8067}
8068
c19d1205
ZW
8069/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8070static void
8071do_mav_dspsc (void)
a737bd4d 8072{
c19d1205
ZW
8073 inst.instruction |= inst.operands[1].reg << 12;
8074}
a737bd4d 8075
c19d1205
ZW
8076/* Maverick shift immediate instructions.
8077 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8078 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8079
c19d1205
ZW
8080static void
8081do_mav_shift (void)
8082{
8083 int imm = inst.operands[2].imm;
a737bd4d 8084
c19d1205
ZW
8085 inst.instruction |= inst.operands[0].reg << 12;
8086 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8087
c19d1205
ZW
8088 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8089 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8090 Bit 4 should be 0. */
8091 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8092
c19d1205
ZW
8093 inst.instruction |= imm;
8094}
8095\f
8096/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8097
c19d1205
ZW
8098/* Xscale multiply-accumulate (argument parse)
8099 MIAcc acc0,Rm,Rs
8100 MIAPHcc acc0,Rm,Rs
8101 MIAxycc acc0,Rm,Rs. */
a737bd4d 8102
c19d1205
ZW
8103static void
8104do_xsc_mia (void)
8105{
8106 inst.instruction |= inst.operands[1].reg;
8107 inst.instruction |= inst.operands[2].reg << 12;
8108}
a737bd4d 8109
c19d1205 8110/* Xscale move-accumulator-register (argument parse)
a737bd4d 8111
c19d1205 8112 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8113
c19d1205
ZW
8114static void
8115do_xsc_mar (void)
8116{
8117 inst.instruction |= inst.operands[1].reg << 12;
8118 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8119}
8120
c19d1205 8121/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8122
c19d1205 8123 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8124
8125static void
c19d1205 8126do_xsc_mra (void)
b99bd4ef 8127{
c19d1205
ZW
8128 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8129 inst.instruction |= inst.operands[0].reg << 12;
8130 inst.instruction |= inst.operands[1].reg << 16;
8131}
8132\f
8133/* Encoding functions relevant only to Thumb. */
b99bd4ef 8134
c19d1205
ZW
8135/* inst.operands[i] is a shifted-register operand; encode
8136 it into inst.instruction in the format used by Thumb32. */
8137
8138static void
8139encode_thumb32_shifted_operand (int i)
8140{
8141 unsigned int value = inst.reloc.exp.X_add_number;
8142 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8143
9c3c69f2
PB
8144 constraint (inst.operands[i].immisreg,
8145 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8146 inst.instruction |= inst.operands[i].reg;
8147 if (shift == SHIFT_RRX)
8148 inst.instruction |= SHIFT_ROR << 4;
8149 else
b99bd4ef 8150 {
c19d1205
ZW
8151 constraint (inst.reloc.exp.X_op != O_constant,
8152 _("expression too complex"));
8153
8154 constraint (value > 32
8155 || (value == 32 && (shift == SHIFT_LSL
8156 || shift == SHIFT_ROR)),
8157 _("shift expression is too large"));
8158
8159 if (value == 0)
8160 shift = SHIFT_LSL;
8161 else if (value == 32)
8162 value = 0;
8163
8164 inst.instruction |= shift << 4;
8165 inst.instruction |= (value & 0x1c) << 10;
8166 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8167 }
c19d1205 8168}
b99bd4ef 8169
b99bd4ef 8170
c19d1205
ZW
8171/* inst.operands[i] was set up by parse_address. Encode it into a
8172 Thumb32 format load or store instruction. Reject forms that cannot
8173 be used with such instructions. If is_t is true, reject forms that
8174 cannot be used with a T instruction; if is_d is true, reject forms
8175 that cannot be used with a D instruction. */
b99bd4ef 8176
c19d1205
ZW
8177static void
8178encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8179{
8180 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8181
8182 constraint (!inst.operands[i].isreg,
53365c0d 8183 _("Instruction does not support =N addresses"));
b99bd4ef 8184
c19d1205
ZW
8185 inst.instruction |= inst.operands[i].reg << 16;
8186 if (inst.operands[i].immisreg)
b99bd4ef 8187 {
c19d1205
ZW
8188 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8189 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8190 constraint (inst.operands[i].negative,
8191 _("Thumb does not support negative register indexing"));
8192 constraint (inst.operands[i].postind,
8193 _("Thumb does not support register post-indexing"));
8194 constraint (inst.operands[i].writeback,
8195 _("Thumb does not support register indexing with writeback"));
8196 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8197 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8198
f40d1643 8199 inst.instruction |= inst.operands[i].imm;
c19d1205 8200 if (inst.operands[i].shifted)
b99bd4ef 8201 {
c19d1205
ZW
8202 constraint (inst.reloc.exp.X_op != O_constant,
8203 _("expression too complex"));
9c3c69f2
PB
8204 constraint (inst.reloc.exp.X_add_number < 0
8205 || inst.reloc.exp.X_add_number > 3,
c19d1205 8206 _("shift out of range"));
9c3c69f2 8207 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8208 }
8209 inst.reloc.type = BFD_RELOC_UNUSED;
8210 }
8211 else if (inst.operands[i].preind)
8212 {
8213 constraint (is_pc && inst.operands[i].writeback,
8214 _("cannot use writeback with PC-relative addressing"));
f40d1643 8215 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8216 _("cannot use writeback with this instruction"));
8217
8218 if (is_d)
8219 {
8220 inst.instruction |= 0x01000000;
8221 if (inst.operands[i].writeback)
8222 inst.instruction |= 0x00200000;
b99bd4ef 8223 }
c19d1205 8224 else
b99bd4ef 8225 {
c19d1205
ZW
8226 inst.instruction |= 0x00000c00;
8227 if (inst.operands[i].writeback)
8228 inst.instruction |= 0x00000100;
b99bd4ef 8229 }
c19d1205 8230 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8231 }
c19d1205 8232 else if (inst.operands[i].postind)
b99bd4ef 8233 {
c19d1205
ZW
8234 assert (inst.operands[i].writeback);
8235 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8236 constraint (is_t, _("cannot use post-indexing with this instruction"));
8237
8238 if (is_d)
8239 inst.instruction |= 0x00200000;
8240 else
8241 inst.instruction |= 0x00000900;
8242 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8243 }
8244 else /* unindexed - only for coprocessor */
8245 inst.error = _("instruction does not accept unindexed addressing");
8246}
8247
8248/* Table of Thumb instructions which exist in both 16- and 32-bit
8249 encodings (the latter only in post-V6T2 cores). The index is the
8250 value used in the insns table below. When there is more than one
8251 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8252 holds variant (1).
8253 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8254#define T16_32_TAB \
8255 X(adc, 4140, eb400000), \
8256 X(adcs, 4140, eb500000), \
8257 X(add, 1c00, eb000000), \
8258 X(adds, 1c00, eb100000), \
0110f2b8
PB
8259 X(addi, 0000, f1000000), \
8260 X(addis, 0000, f1100000), \
8261 X(add_pc,000f, f20f0000), \
8262 X(add_sp,000d, f10d0000), \
e9f89963 8263 X(adr, 000f, f20f0000), \
c19d1205
ZW
8264 X(and, 4000, ea000000), \
8265 X(ands, 4000, ea100000), \
8266 X(asr, 1000, fa40f000), \
8267 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8268 X(b, e000, f000b000), \
8269 X(bcond, d000, f0008000), \
c19d1205
ZW
8270 X(bic, 4380, ea200000), \
8271 X(bics, 4380, ea300000), \
8272 X(cmn, 42c0, eb100f00), \
8273 X(cmp, 2800, ebb00f00), \
8274 X(cpsie, b660, f3af8400), \
8275 X(cpsid, b670, f3af8600), \
8276 X(cpy, 4600, ea4f0000), \
155257ea 8277 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8278 X(eor, 4040, ea800000), \
8279 X(eors, 4040, ea900000), \
0110f2b8 8280 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8281 X(ldmia, c800, e8900000), \
8282 X(ldr, 6800, f8500000), \
8283 X(ldrb, 7800, f8100000), \
8284 X(ldrh, 8800, f8300000), \
8285 X(ldrsb, 5600, f9100000), \
8286 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8287 X(ldr_pc,4800, f85f0000), \
8288 X(ldr_pc2,4800, f85f0000), \
8289 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8290 X(lsl, 0000, fa00f000), \
8291 X(lsls, 0000, fa10f000), \
8292 X(lsr, 0800, fa20f000), \
8293 X(lsrs, 0800, fa30f000), \
8294 X(mov, 2000, ea4f0000), \
8295 X(movs, 2000, ea5f0000), \
8296 X(mul, 4340, fb00f000), \
8297 X(muls, 4340, ffffffff), /* no 32b muls */ \
8298 X(mvn, 43c0, ea6f0000), \
8299 X(mvns, 43c0, ea7f0000), \
8300 X(neg, 4240, f1c00000), /* rsb #0 */ \
8301 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8302 X(orr, 4300, ea400000), \
8303 X(orrs, 4300, ea500000), \
e9f89963
PB
8304 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8305 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8306 X(rev, ba00, fa90f080), \
8307 X(rev16, ba40, fa90f090), \
8308 X(revsh, bac0, fa90f0b0), \
8309 X(ror, 41c0, fa60f000), \
8310 X(rors, 41c0, fa70f000), \
8311 X(sbc, 4180, eb600000), \
8312 X(sbcs, 4180, eb700000), \
8313 X(stmia, c000, e8800000), \
8314 X(str, 6000, f8400000), \
8315 X(strb, 7000, f8000000), \
8316 X(strh, 8000, f8200000), \
0110f2b8 8317 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8318 X(sub, 1e00, eba00000), \
8319 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8320 X(subi, 8000, f1a00000), \
8321 X(subis, 8000, f1b00000), \
c19d1205
ZW
8322 X(sxtb, b240, fa4ff080), \
8323 X(sxth, b200, fa0ff080), \
8324 X(tst, 4200, ea100f00), \
8325 X(uxtb, b2c0, fa5ff080), \
8326 X(uxth, b280, fa1ff080), \
8327 X(nop, bf00, f3af8000), \
8328 X(yield, bf10, f3af8001), \
8329 X(wfe, bf20, f3af8002), \
8330 X(wfi, bf30, f3af8003), \
8331 X(sev, bf40, f3af9004), /* typo, 8004? */
8332
8333/* To catch errors in encoding functions, the codes are all offset by
8334 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8335 as 16-bit instructions. */
8336#define X(a,b,c) T_MNEM_##a
8337enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8338#undef X
8339
8340#define X(a,b,c) 0x##b
8341static const unsigned short thumb_op16[] = { T16_32_TAB };
8342#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8343#undef X
8344
8345#define X(a,b,c) 0x##c
8346static const unsigned int thumb_op32[] = { T16_32_TAB };
8347#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8348#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8349#undef X
8350#undef T16_32_TAB
8351
8352/* Thumb instruction encoders, in alphabetical order. */
8353
92e90b6e
PB
8354/* ADDW or SUBW. */
8355static void
8356do_t_add_sub_w (void)
8357{
8358 int Rd, Rn;
8359
8360 Rd = inst.operands[0].reg;
8361 Rn = inst.operands[1].reg;
8362
8363 constraint (Rd == 15, _("PC not allowed as destination"));
8364 inst.instruction |= (Rn << 16) | (Rd << 8);
8365 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8366}
8367
c19d1205
ZW
8368/* Parse an add or subtract instruction. We get here with inst.instruction
8369 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8370
8371static void
8372do_t_add_sub (void)
8373{
8374 int Rd, Rs, Rn;
8375
8376 Rd = inst.operands[0].reg;
8377 Rs = (inst.operands[1].present
8378 ? inst.operands[1].reg /* Rd, Rs, foo */
8379 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8380
8381 if (unified_syntax)
8382 {
0110f2b8
PB
8383 bfd_boolean flags;
8384 bfd_boolean narrow;
8385 int opcode;
8386
8387 flags = (inst.instruction == T_MNEM_adds
8388 || inst.instruction == T_MNEM_subs);
8389 if (flags)
8390 narrow = (current_it_mask == 0);
8391 else
8392 narrow = (current_it_mask != 0);
c19d1205 8393 if (!inst.operands[2].isreg)
b99bd4ef 8394 {
16805f35
PB
8395 int add;
8396
8397 add = (inst.instruction == T_MNEM_add
8398 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8399 opcode = 0;
8400 if (inst.size_req != 4)
8401 {
0110f2b8
PB
8402 /* Attempt to use a narrow opcode, with relaxation if
8403 appropriate. */
8404 if (Rd == REG_SP && Rs == REG_SP && !flags)
8405 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8406 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8407 opcode = T_MNEM_add_sp;
8408 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8409 opcode = T_MNEM_add_pc;
8410 else if (Rd <= 7 && Rs <= 7 && narrow)
8411 {
8412 if (flags)
8413 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8414 else
8415 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8416 }
8417 if (opcode)
8418 {
8419 inst.instruction = THUMB_OP16(opcode);
8420 inst.instruction |= (Rd << 4) | Rs;
8421 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8422 if (inst.size_req != 2)
8423 inst.relax = opcode;
8424 }
8425 else
8426 constraint (inst.size_req == 2, BAD_HIREG);
8427 }
8428 if (inst.size_req == 4
8429 || (inst.size_req != 2 && !opcode))
8430 {
efd81785
PB
8431 if (Rd == REG_PC)
8432 {
8433 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8434 _("only SUBS PC, LR, #const allowed"));
8435 constraint (inst.reloc.exp.X_op != O_constant,
8436 _("expression too complex"));
8437 constraint (inst.reloc.exp.X_add_number < 0
8438 || inst.reloc.exp.X_add_number > 0xff,
8439 _("immediate value out of range"));
8440 inst.instruction = T2_SUBS_PC_LR
8441 | inst.reloc.exp.X_add_number;
8442 inst.reloc.type = BFD_RELOC_UNUSED;
8443 return;
8444 }
8445 else if (Rs == REG_PC)
16805f35
PB
8446 {
8447 /* Always use addw/subw. */
8448 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8449 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8450 }
8451 else
8452 {
8453 inst.instruction = THUMB_OP32 (inst.instruction);
8454 inst.instruction = (inst.instruction & 0xe1ffffff)
8455 | 0x10000000;
8456 if (flags)
8457 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8458 else
8459 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8460 }
dc4503c6
PB
8461 inst.instruction |= Rd << 8;
8462 inst.instruction |= Rs << 16;
0110f2b8 8463 }
b99bd4ef 8464 }
c19d1205
ZW
8465 else
8466 {
8467 Rn = inst.operands[2].reg;
8468 /* See if we can do this with a 16-bit instruction. */
8469 if (!inst.operands[2].shifted && inst.size_req != 4)
8470 {
e27ec89e
PB
8471 if (Rd > 7 || Rs > 7 || Rn > 7)
8472 narrow = FALSE;
8473
8474 if (narrow)
c19d1205 8475 {
e27ec89e
PB
8476 inst.instruction = ((inst.instruction == T_MNEM_adds
8477 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8478 ? T_OPCODE_ADD_R3
8479 : T_OPCODE_SUB_R3);
8480 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8481 return;
8482 }
b99bd4ef 8483
c19d1205
ZW
8484 if (inst.instruction == T_MNEM_add)
8485 {
8486 if (Rd == Rs)
8487 {
8488 inst.instruction = T_OPCODE_ADD_HI;
8489 inst.instruction |= (Rd & 8) << 4;
8490 inst.instruction |= (Rd & 7);
8491 inst.instruction |= Rn << 3;
8492 return;
8493 }
8494 /* ... because addition is commutative! */
8495 else if (Rd == Rn)
8496 {
8497 inst.instruction = T_OPCODE_ADD_HI;
8498 inst.instruction |= (Rd & 8) << 4;
8499 inst.instruction |= (Rd & 7);
8500 inst.instruction |= Rs << 3;
8501 return;
8502 }
8503 }
8504 }
8505 /* If we get here, it can't be done in 16 bits. */
8506 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8507 _("shift must be constant"));
8508 inst.instruction = THUMB_OP32 (inst.instruction);
8509 inst.instruction |= Rd << 8;
8510 inst.instruction |= Rs << 16;
8511 encode_thumb32_shifted_operand (2);
8512 }
8513 }
8514 else
8515 {
8516 constraint (inst.instruction == T_MNEM_adds
8517 || inst.instruction == T_MNEM_subs,
8518 BAD_THUMB32);
b99bd4ef 8519
c19d1205 8520 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8521 {
c19d1205
ZW
8522 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8523 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8524 BAD_HIREG);
8525
8526 inst.instruction = (inst.instruction == T_MNEM_add
8527 ? 0x0000 : 0x8000);
8528 inst.instruction |= (Rd << 4) | Rs;
8529 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8530 return;
8531 }
8532
c19d1205
ZW
8533 Rn = inst.operands[2].reg;
8534 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8535
c19d1205
ZW
8536 /* We now have Rd, Rs, and Rn set to registers. */
8537 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8538 {
c19d1205
ZW
8539 /* Can't do this for SUB. */
8540 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8541 inst.instruction = T_OPCODE_ADD_HI;
8542 inst.instruction |= (Rd & 8) << 4;
8543 inst.instruction |= (Rd & 7);
8544 if (Rs == Rd)
8545 inst.instruction |= Rn << 3;
8546 else if (Rn == Rd)
8547 inst.instruction |= Rs << 3;
8548 else
8549 constraint (1, _("dest must overlap one source register"));
8550 }
8551 else
8552 {
8553 inst.instruction = (inst.instruction == T_MNEM_add
8554 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8555 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8556 }
b99bd4ef 8557 }
b99bd4ef
NC
8558}
8559
c19d1205
ZW
8560static void
8561do_t_adr (void)
8562{
0110f2b8
PB
8563 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8564 {
8565 /* Defer to section relaxation. */
8566 inst.relax = inst.instruction;
8567 inst.instruction = THUMB_OP16 (inst.instruction);
8568 inst.instruction |= inst.operands[0].reg << 4;
8569 }
8570 else if (unified_syntax && inst.size_req != 2)
e9f89963 8571 {
0110f2b8 8572 /* Generate a 32-bit opcode. */
e9f89963
PB
8573 inst.instruction = THUMB_OP32 (inst.instruction);
8574 inst.instruction |= inst.operands[0].reg << 8;
8575 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8576 inst.reloc.pc_rel = 1;
8577 }
8578 else
8579 {
0110f2b8 8580 /* Generate a 16-bit opcode. */
e9f89963
PB
8581 inst.instruction = THUMB_OP16 (inst.instruction);
8582 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8583 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8584 inst.reloc.pc_rel = 1;
b99bd4ef 8585
e9f89963
PB
8586 inst.instruction |= inst.operands[0].reg << 4;
8587 }
c19d1205 8588}
b99bd4ef 8589
c19d1205
ZW
8590/* Arithmetic instructions for which there is just one 16-bit
8591 instruction encoding, and it allows only two low registers.
8592 For maximal compatibility with ARM syntax, we allow three register
8593 operands even when Thumb-32 instructions are not available, as long
8594 as the first two are identical. For instance, both "sbc r0,r1" and
8595 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8596static void
c19d1205 8597do_t_arit3 (void)
b99bd4ef 8598{
c19d1205 8599 int Rd, Rs, Rn;
b99bd4ef 8600
c19d1205
ZW
8601 Rd = inst.operands[0].reg;
8602 Rs = (inst.operands[1].present
8603 ? inst.operands[1].reg /* Rd, Rs, foo */
8604 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8605 Rn = inst.operands[2].reg;
b99bd4ef 8606
c19d1205 8607 if (unified_syntax)
b99bd4ef 8608 {
c19d1205
ZW
8609 if (!inst.operands[2].isreg)
8610 {
8611 /* For an immediate, we always generate a 32-bit opcode;
8612 section relaxation will shrink it later if possible. */
8613 inst.instruction = THUMB_OP32 (inst.instruction);
8614 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8615 inst.instruction |= Rd << 8;
8616 inst.instruction |= Rs << 16;
8617 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8618 }
8619 else
8620 {
e27ec89e
PB
8621 bfd_boolean narrow;
8622
c19d1205 8623 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8624 if (THUMB_SETS_FLAGS (inst.instruction))
8625 narrow = current_it_mask == 0;
8626 else
8627 narrow = current_it_mask != 0;
8628
8629 if (Rd > 7 || Rn > 7 || Rs > 7)
8630 narrow = FALSE;
8631 if (inst.operands[2].shifted)
8632 narrow = FALSE;
8633 if (inst.size_req == 4)
8634 narrow = FALSE;
8635
8636 if (narrow
c19d1205
ZW
8637 && Rd == Rs)
8638 {
8639 inst.instruction = THUMB_OP16 (inst.instruction);
8640 inst.instruction |= Rd;
8641 inst.instruction |= Rn << 3;
8642 return;
8643 }
b99bd4ef 8644
c19d1205
ZW
8645 /* If we get here, it can't be done in 16 bits. */
8646 constraint (inst.operands[2].shifted
8647 && inst.operands[2].immisreg,
8648 _("shift must be constant"));
8649 inst.instruction = THUMB_OP32 (inst.instruction);
8650 inst.instruction |= Rd << 8;
8651 inst.instruction |= Rs << 16;
8652 encode_thumb32_shifted_operand (2);
8653 }
a737bd4d 8654 }
c19d1205 8655 else
b99bd4ef 8656 {
c19d1205
ZW
8657 /* On its face this is a lie - the instruction does set the
8658 flags. However, the only supported mnemonic in this mode
8659 says it doesn't. */
8660 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8661
c19d1205
ZW
8662 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8663 _("unshifted register required"));
8664 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8665 constraint (Rd != Rs,
8666 _("dest and source1 must be the same register"));
a737bd4d 8667
c19d1205
ZW
8668 inst.instruction = THUMB_OP16 (inst.instruction);
8669 inst.instruction |= Rd;
8670 inst.instruction |= Rn << 3;
b99bd4ef 8671 }
a737bd4d 8672}
b99bd4ef 8673
c19d1205
ZW
8674/* Similarly, but for instructions where the arithmetic operation is
8675 commutative, so we can allow either of them to be different from
8676 the destination operand in a 16-bit instruction. For instance, all
8677 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8678 accepted. */
8679static void
8680do_t_arit3c (void)
a737bd4d 8681{
c19d1205 8682 int Rd, Rs, Rn;
b99bd4ef 8683
c19d1205
ZW
8684 Rd = inst.operands[0].reg;
8685 Rs = (inst.operands[1].present
8686 ? inst.operands[1].reg /* Rd, Rs, foo */
8687 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8688 Rn = inst.operands[2].reg;
a737bd4d 8689
c19d1205 8690 if (unified_syntax)
a737bd4d 8691 {
c19d1205 8692 if (!inst.operands[2].isreg)
b99bd4ef 8693 {
c19d1205
ZW
8694 /* For an immediate, we always generate a 32-bit opcode;
8695 section relaxation will shrink it later if possible. */
8696 inst.instruction = THUMB_OP32 (inst.instruction);
8697 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8698 inst.instruction |= Rd << 8;
8699 inst.instruction |= Rs << 16;
8700 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8701 }
c19d1205 8702 else
a737bd4d 8703 {
e27ec89e
PB
8704 bfd_boolean narrow;
8705
c19d1205 8706 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8707 if (THUMB_SETS_FLAGS (inst.instruction))
8708 narrow = current_it_mask == 0;
8709 else
8710 narrow = current_it_mask != 0;
8711
8712 if (Rd > 7 || Rn > 7 || Rs > 7)
8713 narrow = FALSE;
8714 if (inst.operands[2].shifted)
8715 narrow = FALSE;
8716 if (inst.size_req == 4)
8717 narrow = FALSE;
8718
8719 if (narrow)
a737bd4d 8720 {
c19d1205 8721 if (Rd == Rs)
a737bd4d 8722 {
c19d1205
ZW
8723 inst.instruction = THUMB_OP16 (inst.instruction);
8724 inst.instruction |= Rd;
8725 inst.instruction |= Rn << 3;
8726 return;
a737bd4d 8727 }
c19d1205 8728 if (Rd == Rn)
a737bd4d 8729 {
c19d1205
ZW
8730 inst.instruction = THUMB_OP16 (inst.instruction);
8731 inst.instruction |= Rd;
8732 inst.instruction |= Rs << 3;
8733 return;
a737bd4d
NC
8734 }
8735 }
c19d1205
ZW
8736
8737 /* If we get here, it can't be done in 16 bits. */
8738 constraint (inst.operands[2].shifted
8739 && inst.operands[2].immisreg,
8740 _("shift must be constant"));
8741 inst.instruction = THUMB_OP32 (inst.instruction);
8742 inst.instruction |= Rd << 8;
8743 inst.instruction |= Rs << 16;
8744 encode_thumb32_shifted_operand (2);
a737bd4d 8745 }
b99bd4ef 8746 }
c19d1205
ZW
8747 else
8748 {
8749 /* On its face this is a lie - the instruction does set the
8750 flags. However, the only supported mnemonic in this mode
8751 says it doesn't. */
8752 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8753
c19d1205
ZW
8754 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8755 _("unshifted register required"));
8756 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8757
8758 inst.instruction = THUMB_OP16 (inst.instruction);
8759 inst.instruction |= Rd;
8760
8761 if (Rd == Rs)
8762 inst.instruction |= Rn << 3;
8763 else if (Rd == Rn)
8764 inst.instruction |= Rs << 3;
8765 else
8766 constraint (1, _("dest must overlap one source register"));
8767 }
a737bd4d
NC
8768}
8769
62b3e311
PB
8770static void
8771do_t_barrier (void)
8772{
8773 if (inst.operands[0].present)
8774 {
8775 constraint ((inst.instruction & 0xf0) != 0x40
8776 && inst.operands[0].imm != 0xf,
bd3ba5d1 8777 _("bad barrier type"));
62b3e311
PB
8778 inst.instruction |= inst.operands[0].imm;
8779 }
8780 else
8781 inst.instruction |= 0xf;
8782}
8783
c19d1205
ZW
8784static void
8785do_t_bfc (void)
a737bd4d 8786{
c19d1205
ZW
8787 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8788 constraint (msb > 32, _("bit-field extends past end of register"));
8789 /* The instruction encoding stores the LSB and MSB,
8790 not the LSB and width. */
8791 inst.instruction |= inst.operands[0].reg << 8;
8792 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8793 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8794 inst.instruction |= msb - 1;
b99bd4ef
NC
8795}
8796
c19d1205
ZW
8797static void
8798do_t_bfi (void)
b99bd4ef 8799{
c19d1205 8800 unsigned int msb;
b99bd4ef 8801
c19d1205
ZW
8802 /* #0 in second position is alternative syntax for bfc, which is
8803 the same instruction but with REG_PC in the Rm field. */
8804 if (!inst.operands[1].isreg)
8805 inst.operands[1].reg = REG_PC;
b99bd4ef 8806
c19d1205
ZW
8807 msb = inst.operands[2].imm + inst.operands[3].imm;
8808 constraint (msb > 32, _("bit-field extends past end of register"));
8809 /* The instruction encoding stores the LSB and MSB,
8810 not the LSB and width. */
8811 inst.instruction |= inst.operands[0].reg << 8;
8812 inst.instruction |= inst.operands[1].reg << 16;
8813 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8814 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8815 inst.instruction |= msb - 1;
b99bd4ef
NC
8816}
8817
c19d1205
ZW
8818static void
8819do_t_bfx (void)
b99bd4ef 8820{
c19d1205
ZW
8821 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8822 _("bit-field extends past end of register"));
8823 inst.instruction |= inst.operands[0].reg << 8;
8824 inst.instruction |= inst.operands[1].reg << 16;
8825 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8826 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8827 inst.instruction |= inst.operands[3].imm - 1;
8828}
b99bd4ef 8829
c19d1205
ZW
8830/* ARM V5 Thumb BLX (argument parse)
8831 BLX <target_addr> which is BLX(1)
8832 BLX <Rm> which is BLX(2)
8833 Unfortunately, there are two different opcodes for this mnemonic.
8834 So, the insns[].value is not used, and the code here zaps values
8835 into inst.instruction.
b99bd4ef 8836
c19d1205
ZW
8837 ??? How to take advantage of the additional two bits of displacement
8838 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8839
c19d1205
ZW
8840static void
8841do_t_blx (void)
8842{
dfa9f0d5 8843 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8844 if (inst.operands[0].isreg)
8845 /* We have a register, so this is BLX(2). */
8846 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8847 else
8848 {
c19d1205 8849 /* No register. This must be BLX(1). */
2fc8bdac 8850 inst.instruction = 0xf000e800;
39b41c9c
PB
8851#ifdef OBJ_ELF
8852 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8853 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8854 else
8855#endif
8856 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8857 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8858 }
8859}
8860
c19d1205
ZW
8861static void
8862do_t_branch (void)
b99bd4ef 8863{
0110f2b8 8864 int opcode;
dfa9f0d5
PB
8865 int cond;
8866
8867 if (current_it_mask)
8868 {
8869 /* Conditional branches inside IT blocks are encoded as unconditional
8870 branches. */
8871 cond = COND_ALWAYS;
8872 /* A branch must be the last instruction in an IT block. */
8873 constraint (current_it_mask != 0x10, BAD_BRANCH);
8874 }
8875 else
8876 cond = inst.cond;
8877
8878 if (cond != COND_ALWAYS)
0110f2b8
PB
8879 opcode = T_MNEM_bcond;
8880 else
8881 opcode = inst.instruction;
8882
8883 if (unified_syntax && inst.size_req == 4)
c19d1205 8884 {
0110f2b8 8885 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8886 if (cond == COND_ALWAYS)
0110f2b8 8887 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8888 else
8889 {
dfa9f0d5
PB
8890 assert (cond != 0xF);
8891 inst.instruction |= cond << 22;
c19d1205
ZW
8892 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8893 }
8894 }
b99bd4ef
NC
8895 else
8896 {
0110f2b8 8897 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8898 if (cond == COND_ALWAYS)
c19d1205
ZW
8899 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8900 else
b99bd4ef 8901 {
dfa9f0d5 8902 inst.instruction |= cond << 8;
c19d1205 8903 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8904 }
0110f2b8
PB
8905 /* Allow section relaxation. */
8906 if (unified_syntax && inst.size_req != 2)
8907 inst.relax = opcode;
b99bd4ef 8908 }
c19d1205
ZW
8909
8910 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8911}
8912
8913static void
c19d1205 8914do_t_bkpt (void)
b99bd4ef 8915{
dfa9f0d5
PB
8916 constraint (inst.cond != COND_ALWAYS,
8917 _("instruction is always unconditional"));
c19d1205 8918 if (inst.operands[0].present)
b99bd4ef 8919 {
c19d1205
ZW
8920 constraint (inst.operands[0].imm > 255,
8921 _("immediate value out of range"));
8922 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8923 }
b99bd4ef
NC
8924}
8925
8926static void
c19d1205 8927do_t_branch23 (void)
b99bd4ef 8928{
dfa9f0d5 8929 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8930 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8931 inst.reloc.pc_rel = 1;
8932
c19d1205
ZW
8933 /* If the destination of the branch is a defined symbol which does not have
8934 the THUMB_FUNC attribute, then we must be calling a function which has
8935 the (interfacearm) attribute. We look for the Thumb entry point to that
8936 function and change the branch to refer to that function instead. */
8937 if ( inst.reloc.exp.X_op == O_symbol
8938 && inst.reloc.exp.X_add_symbol != NULL
8939 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8940 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8941 inst.reloc.exp.X_add_symbol =
8942 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8943}
8944
8945static void
c19d1205 8946do_t_bx (void)
90e4755a 8947{
dfa9f0d5 8948 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8949 inst.instruction |= inst.operands[0].reg << 3;
8950 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8951 should cause the alignment to be checked once it is known. This is
8952 because BX PC only works if the instruction is word aligned. */
8953}
90e4755a 8954
c19d1205
ZW
8955static void
8956do_t_bxj (void)
8957{
dfa9f0d5 8958 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8959 if (inst.operands[0].reg == REG_PC)
8960 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8961
c19d1205 8962 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8963}
8964
8965static void
c19d1205 8966do_t_clz (void)
90e4755a 8967{
c19d1205
ZW
8968 inst.instruction |= inst.operands[0].reg << 8;
8969 inst.instruction |= inst.operands[1].reg << 16;
8970 inst.instruction |= inst.operands[1].reg;
8971}
90e4755a 8972
dfa9f0d5
PB
8973static void
8974do_t_cps (void)
8975{
8976 constraint (current_it_mask, BAD_NOT_IT);
8977 inst.instruction |= inst.operands[0].imm;
8978}
8979
c19d1205
ZW
8980static void
8981do_t_cpsi (void)
8982{
dfa9f0d5 8983 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 8984 if (unified_syntax
62b3e311
PB
8985 && (inst.operands[1].present || inst.size_req == 4)
8986 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 8987 {
c19d1205
ZW
8988 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8989 inst.instruction = 0xf3af8000;
8990 inst.instruction |= imod << 9;
8991 inst.instruction |= inst.operands[0].imm << 5;
8992 if (inst.operands[1].present)
8993 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 8994 }
c19d1205 8995 else
90e4755a 8996 {
62b3e311
PB
8997 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8998 && (inst.operands[0].imm & 4),
8999 _("selected processor does not support 'A' form "
9000 "of this instruction"));
9001 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9002 _("Thumb does not support the 2-argument "
9003 "form of this instruction"));
9004 inst.instruction |= inst.operands[0].imm;
90e4755a 9005 }
90e4755a
RE
9006}
9007
c19d1205
ZW
9008/* THUMB CPY instruction (argument parse). */
9009
90e4755a 9010static void
c19d1205 9011do_t_cpy (void)
90e4755a 9012{
c19d1205 9013 if (inst.size_req == 4)
90e4755a 9014 {
c19d1205
ZW
9015 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9016 inst.instruction |= inst.operands[0].reg << 8;
9017 inst.instruction |= inst.operands[1].reg;
90e4755a 9018 }
c19d1205 9019 else
90e4755a 9020 {
c19d1205
ZW
9021 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9022 inst.instruction |= (inst.operands[0].reg & 0x7);
9023 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9024 }
90e4755a
RE
9025}
9026
90e4755a 9027static void
25fe350b 9028do_t_cbz (void)
90e4755a 9029{
dfa9f0d5 9030 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9031 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9032 inst.instruction |= inst.operands[0].reg;
9033 inst.reloc.pc_rel = 1;
9034 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9035}
90e4755a 9036
62b3e311
PB
9037static void
9038do_t_dbg (void)
9039{
9040 inst.instruction |= inst.operands[0].imm;
9041}
9042
9043static void
9044do_t_div (void)
9045{
9046 if (!inst.operands[1].present)
9047 inst.operands[1].reg = inst.operands[0].reg;
9048 inst.instruction |= inst.operands[0].reg << 8;
9049 inst.instruction |= inst.operands[1].reg << 16;
9050 inst.instruction |= inst.operands[2].reg;
9051}
9052
c19d1205
ZW
9053static void
9054do_t_hint (void)
9055{
9056 if (unified_syntax && inst.size_req == 4)
9057 inst.instruction = THUMB_OP32 (inst.instruction);
9058 else
9059 inst.instruction = THUMB_OP16 (inst.instruction);
9060}
90e4755a 9061
c19d1205
ZW
9062static void
9063do_t_it (void)
9064{
9065 unsigned int cond = inst.operands[0].imm;
e27ec89e 9066
dfa9f0d5 9067 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9068 current_it_mask = (inst.instruction & 0xf) | 0x10;
9069 current_cc = cond;
9070
9071 /* If the condition is a negative condition, invert the mask. */
c19d1205 9072 if ((cond & 0x1) == 0x0)
90e4755a 9073 {
c19d1205 9074 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9075
c19d1205
ZW
9076 if ((mask & 0x7) == 0)
9077 /* no conversion needed */;
9078 else if ((mask & 0x3) == 0)
e27ec89e
PB
9079 mask ^= 0x8;
9080 else if ((mask & 0x1) == 0)
9081 mask ^= 0xC;
c19d1205 9082 else
e27ec89e 9083 mask ^= 0xE;
90e4755a 9084
e27ec89e
PB
9085 inst.instruction &= 0xfff0;
9086 inst.instruction |= mask;
c19d1205 9087 }
90e4755a 9088
c19d1205
ZW
9089 inst.instruction |= cond << 4;
9090}
90e4755a 9091
3c707909
PB
9092/* Helper function used for both push/pop and ldm/stm. */
9093static void
9094encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9095{
9096 bfd_boolean load;
9097
9098 load = (inst.instruction & (1 << 20)) != 0;
9099
9100 if (mask & (1 << 13))
9101 inst.error = _("SP not allowed in register list");
9102 if (load)
9103 {
9104 if (mask & (1 << 14)
9105 && mask & (1 << 15))
9106 inst.error = _("LR and PC should not both be in register list");
9107
9108 if ((mask & (1 << base)) != 0
9109 && writeback)
9110 as_warn (_("base register should not be in register list "
9111 "when written back"));
9112 }
9113 else
9114 {
9115 if (mask & (1 << 15))
9116 inst.error = _("PC not allowed in register list");
9117
9118 if (mask & (1 << base))
9119 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9120 }
9121
9122 if ((mask & (mask - 1)) == 0)
9123 {
9124 /* Single register transfers implemented as str/ldr. */
9125 if (writeback)
9126 {
9127 if (inst.instruction & (1 << 23))
9128 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9129 else
9130 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9131 }
9132 else
9133 {
9134 if (inst.instruction & (1 << 23))
9135 inst.instruction = 0x00800000; /* ia -> [base] */
9136 else
9137 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9138 }
9139
9140 inst.instruction |= 0xf8400000;
9141 if (load)
9142 inst.instruction |= 0x00100000;
9143
5f4273c7 9144 mask = ffs (mask) - 1;
3c707909
PB
9145 mask <<= 12;
9146 }
9147 else if (writeback)
9148 inst.instruction |= WRITE_BACK;
9149
9150 inst.instruction |= mask;
9151 inst.instruction |= base << 16;
9152}
9153
c19d1205
ZW
9154static void
9155do_t_ldmstm (void)
9156{
9157 /* This really doesn't seem worth it. */
9158 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9159 _("expression too complex"));
9160 constraint (inst.operands[1].writeback,
9161 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9162
c19d1205
ZW
9163 if (unified_syntax)
9164 {
3c707909
PB
9165 bfd_boolean narrow;
9166 unsigned mask;
9167
9168 narrow = FALSE;
c19d1205
ZW
9169 /* See if we can use a 16-bit instruction. */
9170 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9171 && inst.size_req != 4
3c707909 9172 && !(inst.operands[1].imm & ~0xff))
90e4755a 9173 {
3c707909 9174 mask = 1 << inst.operands[0].reg;
90e4755a 9175
3c707909
PB
9176 if (inst.operands[0].reg <= 7
9177 && (inst.instruction == T_MNEM_stmia
9178 ? inst.operands[0].writeback
9179 : (inst.operands[0].writeback
9180 == !(inst.operands[1].imm & mask))))
90e4755a 9181 {
3c707909
PB
9182 if (inst.instruction == T_MNEM_stmia
9183 && (inst.operands[1].imm & mask)
9184 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9185 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9186 inst.operands[0].reg);
3c707909
PB
9187
9188 inst.instruction = THUMB_OP16 (inst.instruction);
9189 inst.instruction |= inst.operands[0].reg << 8;
9190 inst.instruction |= inst.operands[1].imm;
9191 narrow = TRUE;
90e4755a 9192 }
3c707909
PB
9193 else if (inst.operands[0] .reg == REG_SP
9194 && inst.operands[0].writeback)
90e4755a 9195 {
3c707909
PB
9196 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9197 ? T_MNEM_push : T_MNEM_pop);
9198 inst.instruction |= inst.operands[1].imm;
9199 narrow = TRUE;
90e4755a 9200 }
3c707909
PB
9201 }
9202
9203 if (!narrow)
9204 {
c19d1205
ZW
9205 if (inst.instruction < 0xffff)
9206 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9207
5f4273c7
NC
9208 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9209 inst.operands[0].writeback);
90e4755a
RE
9210 }
9211 }
c19d1205 9212 else
90e4755a 9213 {
c19d1205
ZW
9214 constraint (inst.operands[0].reg > 7
9215 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9216 constraint (inst.instruction != T_MNEM_ldmia
9217 && inst.instruction != T_MNEM_stmia,
9218 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9219 if (inst.instruction == T_MNEM_stmia)
f03698e6 9220 {
c19d1205
ZW
9221 if (!inst.operands[0].writeback)
9222 as_warn (_("this instruction will write back the base register"));
9223 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9224 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9225 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9226 inst.operands[0].reg);
f03698e6 9227 }
c19d1205 9228 else
90e4755a 9229 {
c19d1205
ZW
9230 if (!inst.operands[0].writeback
9231 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9232 as_warn (_("this instruction will write back the base register"));
9233 else if (inst.operands[0].writeback
9234 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9235 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9236 }
9237
c19d1205
ZW
9238 inst.instruction = THUMB_OP16 (inst.instruction);
9239 inst.instruction |= inst.operands[0].reg << 8;
9240 inst.instruction |= inst.operands[1].imm;
9241 }
9242}
e28cd48c 9243
c19d1205
ZW
9244static void
9245do_t_ldrex (void)
9246{
9247 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9248 || inst.operands[1].postind || inst.operands[1].writeback
9249 || inst.operands[1].immisreg || inst.operands[1].shifted
9250 || inst.operands[1].negative,
01cfc07f 9251 BAD_ADDR_MODE);
e28cd48c 9252
c19d1205
ZW
9253 inst.instruction |= inst.operands[0].reg << 12;
9254 inst.instruction |= inst.operands[1].reg << 16;
9255 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9256}
e28cd48c 9257
c19d1205
ZW
9258static void
9259do_t_ldrexd (void)
9260{
9261 if (!inst.operands[1].present)
1cac9012 9262 {
c19d1205
ZW
9263 constraint (inst.operands[0].reg == REG_LR,
9264 _("r14 not allowed as first register "
9265 "when second register is omitted"));
9266 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9267 }
c19d1205
ZW
9268 constraint (inst.operands[0].reg == inst.operands[1].reg,
9269 BAD_OVERLAP);
b99bd4ef 9270
c19d1205
ZW
9271 inst.instruction |= inst.operands[0].reg << 12;
9272 inst.instruction |= inst.operands[1].reg << 8;
9273 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9274}
9275
9276static void
c19d1205 9277do_t_ldst (void)
b99bd4ef 9278{
0110f2b8
PB
9279 unsigned long opcode;
9280 int Rn;
9281
9282 opcode = inst.instruction;
c19d1205 9283 if (unified_syntax)
b99bd4ef 9284 {
53365c0d
PB
9285 if (!inst.operands[1].isreg)
9286 {
9287 if (opcode <= 0xffff)
9288 inst.instruction = THUMB_OP32 (opcode);
9289 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9290 return;
9291 }
0110f2b8
PB
9292 if (inst.operands[1].isreg
9293 && !inst.operands[1].writeback
c19d1205
ZW
9294 && !inst.operands[1].shifted && !inst.operands[1].postind
9295 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9296 && opcode <= 0xffff
9297 && inst.size_req != 4)
c19d1205 9298 {
0110f2b8
PB
9299 /* Insn may have a 16-bit form. */
9300 Rn = inst.operands[1].reg;
9301 if (inst.operands[1].immisreg)
9302 {
9303 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9304 /* [Rn, Rik] */
0110f2b8
PB
9305 if (Rn <= 7 && inst.operands[1].imm <= 7)
9306 goto op16;
9307 }
9308 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9309 && opcode != T_MNEM_ldrsb)
9310 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9311 || (Rn == REG_SP && opcode == T_MNEM_str))
9312 {
9313 /* [Rn, #const] */
9314 if (Rn > 7)
9315 {
9316 if (Rn == REG_PC)
9317 {
9318 if (inst.reloc.pc_rel)
9319 opcode = T_MNEM_ldr_pc2;
9320 else
9321 opcode = T_MNEM_ldr_pc;
9322 }
9323 else
9324 {
9325 if (opcode == T_MNEM_ldr)
9326 opcode = T_MNEM_ldr_sp;
9327 else
9328 opcode = T_MNEM_str_sp;
9329 }
9330 inst.instruction = inst.operands[0].reg << 8;
9331 }
9332 else
9333 {
9334 inst.instruction = inst.operands[0].reg;
9335 inst.instruction |= inst.operands[1].reg << 3;
9336 }
9337 inst.instruction |= THUMB_OP16 (opcode);
9338 if (inst.size_req == 2)
9339 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9340 else
9341 inst.relax = opcode;
9342 return;
9343 }
c19d1205 9344 }
0110f2b8
PB
9345 /* Definitely a 32-bit variant. */
9346 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9347 inst.instruction |= inst.operands[0].reg << 12;
9348 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9349 return;
9350 }
9351
c19d1205
ZW
9352 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9353
9354 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9355 {
c19d1205
ZW
9356 /* Only [Rn,Rm] is acceptable. */
9357 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9358 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9359 || inst.operands[1].postind || inst.operands[1].shifted
9360 || inst.operands[1].negative,
9361 _("Thumb does not support this addressing mode"));
9362 inst.instruction = THUMB_OP16 (inst.instruction);
9363 goto op16;
b99bd4ef 9364 }
5f4273c7 9365
c19d1205
ZW
9366 inst.instruction = THUMB_OP16 (inst.instruction);
9367 if (!inst.operands[1].isreg)
9368 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9369 return;
b99bd4ef 9370
c19d1205
ZW
9371 constraint (!inst.operands[1].preind
9372 || inst.operands[1].shifted
9373 || inst.operands[1].writeback,
9374 _("Thumb does not support this addressing mode"));
9375 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9376 {
c19d1205
ZW
9377 constraint (inst.instruction & 0x0600,
9378 _("byte or halfword not valid for base register"));
9379 constraint (inst.operands[1].reg == REG_PC
9380 && !(inst.instruction & THUMB_LOAD_BIT),
9381 _("r15 based store not allowed"));
9382 constraint (inst.operands[1].immisreg,
9383 _("invalid base register for register offset"));
b99bd4ef 9384
c19d1205
ZW
9385 if (inst.operands[1].reg == REG_PC)
9386 inst.instruction = T_OPCODE_LDR_PC;
9387 else if (inst.instruction & THUMB_LOAD_BIT)
9388 inst.instruction = T_OPCODE_LDR_SP;
9389 else
9390 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9391
c19d1205
ZW
9392 inst.instruction |= inst.operands[0].reg << 8;
9393 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9394 return;
9395 }
90e4755a 9396
c19d1205
ZW
9397 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9398 if (!inst.operands[1].immisreg)
9399 {
9400 /* Immediate offset. */
9401 inst.instruction |= inst.operands[0].reg;
9402 inst.instruction |= inst.operands[1].reg << 3;
9403 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9404 return;
9405 }
90e4755a 9406
c19d1205
ZW
9407 /* Register offset. */
9408 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9409 constraint (inst.operands[1].negative,
9410 _("Thumb does not support this addressing mode"));
90e4755a 9411
c19d1205
ZW
9412 op16:
9413 switch (inst.instruction)
9414 {
9415 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9416 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9417 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9418 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9419 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9420 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9421 case 0x5600 /* ldrsb */:
9422 case 0x5e00 /* ldrsh */: break;
9423 default: abort ();
9424 }
90e4755a 9425
c19d1205
ZW
9426 inst.instruction |= inst.operands[0].reg;
9427 inst.instruction |= inst.operands[1].reg << 3;
9428 inst.instruction |= inst.operands[1].imm << 6;
9429}
90e4755a 9430
c19d1205
ZW
9431static void
9432do_t_ldstd (void)
9433{
9434 if (!inst.operands[1].present)
b99bd4ef 9435 {
c19d1205
ZW
9436 inst.operands[1].reg = inst.operands[0].reg + 1;
9437 constraint (inst.operands[0].reg == REG_LR,
9438 _("r14 not allowed here"));
b99bd4ef 9439 }
c19d1205
ZW
9440 inst.instruction |= inst.operands[0].reg << 12;
9441 inst.instruction |= inst.operands[1].reg << 8;
9442 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9443}
9444
c19d1205
ZW
9445static void
9446do_t_ldstt (void)
9447{
9448 inst.instruction |= inst.operands[0].reg << 12;
9449 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9450}
a737bd4d 9451
b99bd4ef 9452static void
c19d1205 9453do_t_mla (void)
b99bd4ef 9454{
c19d1205
ZW
9455 inst.instruction |= inst.operands[0].reg << 8;
9456 inst.instruction |= inst.operands[1].reg << 16;
9457 inst.instruction |= inst.operands[2].reg;
9458 inst.instruction |= inst.operands[3].reg << 12;
9459}
b99bd4ef 9460
c19d1205
ZW
9461static void
9462do_t_mlal (void)
9463{
9464 inst.instruction |= inst.operands[0].reg << 12;
9465 inst.instruction |= inst.operands[1].reg << 8;
9466 inst.instruction |= inst.operands[2].reg << 16;
9467 inst.instruction |= inst.operands[3].reg;
9468}
b99bd4ef 9469
c19d1205
ZW
9470static void
9471do_t_mov_cmp (void)
9472{
9473 if (unified_syntax)
b99bd4ef 9474 {
c19d1205
ZW
9475 int r0off = (inst.instruction == T_MNEM_mov
9476 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9477 unsigned long opcode;
3d388997
PB
9478 bfd_boolean narrow;
9479 bfd_boolean low_regs;
9480
9481 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9482 opcode = inst.instruction;
3d388997 9483 if (current_it_mask)
0110f2b8 9484 narrow = opcode != T_MNEM_movs;
3d388997 9485 else
0110f2b8 9486 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9487 if (inst.size_req == 4
9488 || inst.operands[1].shifted)
9489 narrow = FALSE;
9490
efd81785
PB
9491 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9492 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9493 && !inst.operands[1].shifted
9494 && inst.operands[0].reg == REG_PC
9495 && inst.operands[1].reg == REG_LR)
9496 {
9497 inst.instruction = T2_SUBS_PC_LR;
9498 return;
9499 }
9500
c19d1205
ZW
9501 if (!inst.operands[1].isreg)
9502 {
0110f2b8
PB
9503 /* Immediate operand. */
9504 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9505 narrow = 0;
9506 if (low_regs && narrow)
9507 {
9508 inst.instruction = THUMB_OP16 (opcode);
9509 inst.instruction |= inst.operands[0].reg << 8;
9510 if (inst.size_req == 2)
9511 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9512 else
9513 inst.relax = opcode;
9514 }
9515 else
9516 {
9517 inst.instruction = THUMB_OP32 (inst.instruction);
9518 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9519 inst.instruction |= inst.operands[0].reg << r0off;
9520 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9521 }
c19d1205 9522 }
728ca7c9
PB
9523 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9524 && (inst.instruction == T_MNEM_mov
9525 || inst.instruction == T_MNEM_movs))
9526 {
9527 /* Register shifts are encoded as separate shift instructions. */
9528 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9529
9530 if (current_it_mask)
9531 narrow = !flags;
9532 else
9533 narrow = flags;
9534
9535 if (inst.size_req == 4)
9536 narrow = FALSE;
9537
9538 if (!low_regs || inst.operands[1].imm > 7)
9539 narrow = FALSE;
9540
9541 if (inst.operands[0].reg != inst.operands[1].reg)
9542 narrow = FALSE;
9543
9544 switch (inst.operands[1].shift_kind)
9545 {
9546 case SHIFT_LSL:
9547 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9548 break;
9549 case SHIFT_ASR:
9550 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9551 break;
9552 case SHIFT_LSR:
9553 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9554 break;
9555 case SHIFT_ROR:
9556 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9557 break;
9558 default:
5f4273c7 9559 abort ();
728ca7c9
PB
9560 }
9561
9562 inst.instruction = opcode;
9563 if (narrow)
9564 {
9565 inst.instruction |= inst.operands[0].reg;
9566 inst.instruction |= inst.operands[1].imm << 3;
9567 }
9568 else
9569 {
9570 if (flags)
9571 inst.instruction |= CONDS_BIT;
9572
9573 inst.instruction |= inst.operands[0].reg << 8;
9574 inst.instruction |= inst.operands[1].reg << 16;
9575 inst.instruction |= inst.operands[1].imm;
9576 }
9577 }
3d388997 9578 else if (!narrow)
c19d1205 9579 {
728ca7c9
PB
9580 /* Some mov with immediate shift have narrow variants.
9581 Register shifts are handled above. */
9582 if (low_regs && inst.operands[1].shifted
9583 && (inst.instruction == T_MNEM_mov
9584 || inst.instruction == T_MNEM_movs))
9585 {
9586 if (current_it_mask)
9587 narrow = (inst.instruction == T_MNEM_mov);
9588 else
9589 narrow = (inst.instruction == T_MNEM_movs);
9590 }
9591
9592 if (narrow)
9593 {
9594 switch (inst.operands[1].shift_kind)
9595 {
9596 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9597 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9598 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9599 default: narrow = FALSE; break;
9600 }
9601 }
9602
9603 if (narrow)
9604 {
9605 inst.instruction |= inst.operands[0].reg;
9606 inst.instruction |= inst.operands[1].reg << 3;
9607 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9608 }
9609 else
9610 {
9611 inst.instruction = THUMB_OP32 (inst.instruction);
9612 inst.instruction |= inst.operands[0].reg << r0off;
9613 encode_thumb32_shifted_operand (1);
9614 }
c19d1205
ZW
9615 }
9616 else
9617 switch (inst.instruction)
9618 {
9619 case T_MNEM_mov:
9620 inst.instruction = T_OPCODE_MOV_HR;
9621 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9622 inst.instruction |= (inst.operands[0].reg & 0x7);
9623 inst.instruction |= inst.operands[1].reg << 3;
9624 break;
b99bd4ef 9625
c19d1205
ZW
9626 case T_MNEM_movs:
9627 /* We know we have low registers at this point.
9628 Generate ADD Rd, Rs, #0. */
9629 inst.instruction = T_OPCODE_ADD_I3;
9630 inst.instruction |= inst.operands[0].reg;
9631 inst.instruction |= inst.operands[1].reg << 3;
9632 break;
9633
9634 case T_MNEM_cmp:
3d388997 9635 if (low_regs)
c19d1205
ZW
9636 {
9637 inst.instruction = T_OPCODE_CMP_LR;
9638 inst.instruction |= inst.operands[0].reg;
9639 inst.instruction |= inst.operands[1].reg << 3;
9640 }
9641 else
9642 {
9643 inst.instruction = T_OPCODE_CMP_HR;
9644 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9645 inst.instruction |= (inst.operands[0].reg & 0x7);
9646 inst.instruction |= inst.operands[1].reg << 3;
9647 }
9648 break;
9649 }
b99bd4ef
NC
9650 return;
9651 }
9652
c19d1205
ZW
9653 inst.instruction = THUMB_OP16 (inst.instruction);
9654 if (inst.operands[1].isreg)
b99bd4ef 9655 {
c19d1205 9656 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9657 {
c19d1205
ZW
9658 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9659 since a MOV instruction produces unpredictable results. */
9660 if (inst.instruction == T_OPCODE_MOV_I8)
9661 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9662 else
c19d1205 9663 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9664
c19d1205
ZW
9665 inst.instruction |= inst.operands[0].reg;
9666 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9667 }
9668 else
9669 {
c19d1205
ZW
9670 if (inst.instruction == T_OPCODE_MOV_I8)
9671 inst.instruction = T_OPCODE_MOV_HR;
9672 else
9673 inst.instruction = T_OPCODE_CMP_HR;
9674 do_t_cpy ();
b99bd4ef
NC
9675 }
9676 }
c19d1205 9677 else
b99bd4ef 9678 {
c19d1205
ZW
9679 constraint (inst.operands[0].reg > 7,
9680 _("only lo regs allowed with immediate"));
9681 inst.instruction |= inst.operands[0].reg << 8;
9682 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9683 }
9684}
b99bd4ef 9685
c19d1205
ZW
9686static void
9687do_t_mov16 (void)
9688{
b6895b4f
PB
9689 bfd_vma imm;
9690 bfd_boolean top;
9691
9692 top = (inst.instruction & 0x00800000) != 0;
9693 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9694 {
9695 constraint (top, _(":lower16: not allowed this instruction"));
9696 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9697 }
9698 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9699 {
9700 constraint (!top, _(":upper16: not allowed this instruction"));
9701 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9702 }
9703
c19d1205 9704 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9705 if (inst.reloc.type == BFD_RELOC_UNUSED)
9706 {
9707 imm = inst.reloc.exp.X_add_number;
9708 inst.instruction |= (imm & 0xf000) << 4;
9709 inst.instruction |= (imm & 0x0800) << 15;
9710 inst.instruction |= (imm & 0x0700) << 4;
9711 inst.instruction |= (imm & 0x00ff);
9712 }
c19d1205 9713}
b99bd4ef 9714
c19d1205
ZW
9715static void
9716do_t_mvn_tst (void)
9717{
9718 if (unified_syntax)
9719 {
9720 int r0off = (inst.instruction == T_MNEM_mvn
9721 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9722 bfd_boolean narrow;
9723
9724 if (inst.size_req == 4
9725 || inst.instruction > 0xffff
9726 || inst.operands[1].shifted
9727 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9728 narrow = FALSE;
9729 else if (inst.instruction == T_MNEM_cmn)
9730 narrow = TRUE;
9731 else if (THUMB_SETS_FLAGS (inst.instruction))
9732 narrow = (current_it_mask == 0);
9733 else
9734 narrow = (current_it_mask != 0);
9735
c19d1205 9736 if (!inst.operands[1].isreg)
b99bd4ef 9737 {
c19d1205
ZW
9738 /* For an immediate, we always generate a 32-bit opcode;
9739 section relaxation will shrink it later if possible. */
9740 if (inst.instruction < 0xffff)
9741 inst.instruction = THUMB_OP32 (inst.instruction);
9742 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9743 inst.instruction |= inst.operands[0].reg << r0off;
9744 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9745 }
c19d1205 9746 else
b99bd4ef 9747 {
c19d1205 9748 /* See if we can do this with a 16-bit instruction. */
3d388997 9749 if (narrow)
b99bd4ef 9750 {
c19d1205
ZW
9751 inst.instruction = THUMB_OP16 (inst.instruction);
9752 inst.instruction |= inst.operands[0].reg;
9753 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9754 }
c19d1205 9755 else
b99bd4ef 9756 {
c19d1205
ZW
9757 constraint (inst.operands[1].shifted
9758 && inst.operands[1].immisreg,
9759 _("shift must be constant"));
9760 if (inst.instruction < 0xffff)
9761 inst.instruction = THUMB_OP32 (inst.instruction);
9762 inst.instruction |= inst.operands[0].reg << r0off;
9763 encode_thumb32_shifted_operand (1);
b99bd4ef 9764 }
b99bd4ef
NC
9765 }
9766 }
9767 else
9768 {
c19d1205
ZW
9769 constraint (inst.instruction > 0xffff
9770 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9771 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9772 _("unshifted register required"));
9773 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9774 BAD_HIREG);
b99bd4ef 9775
c19d1205
ZW
9776 inst.instruction = THUMB_OP16 (inst.instruction);
9777 inst.instruction |= inst.operands[0].reg;
9778 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9779 }
b99bd4ef
NC
9780}
9781
b05fe5cf 9782static void
c19d1205 9783do_t_mrs (void)
b05fe5cf 9784{
62b3e311 9785 int flags;
037e8744
JB
9786
9787 if (do_vfp_nsyn_mrs () == SUCCESS)
9788 return;
9789
62b3e311
PB
9790 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9791 if (flags == 0)
9792 {
9793 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9794 _("selected processor does not support "
9795 "requested special purpose register"));
9796 }
9797 else
9798 {
9799 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9800 _("selected processor does not support "
9801 "requested special purpose register %x"));
9802 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9803 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9804 _("'CPSR' or 'SPSR' expected"));
9805 }
5f4273c7 9806
c19d1205 9807 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9808 inst.instruction |= (flags & SPSR_BIT) >> 2;
9809 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9810}
b05fe5cf 9811
c19d1205
ZW
9812static void
9813do_t_msr (void)
9814{
62b3e311
PB
9815 int flags;
9816
037e8744
JB
9817 if (do_vfp_nsyn_msr () == SUCCESS)
9818 return;
9819
c19d1205
ZW
9820 constraint (!inst.operands[1].isreg,
9821 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9822 flags = inst.operands[0].imm;
9823 if (flags & ~0xff)
9824 {
9825 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9826 _("selected processor does not support "
9827 "requested special purpose register"));
9828 }
9829 else
9830 {
9831 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9832 _("selected processor does not support "
9833 "requested special purpose register"));
9834 flags |= PSR_f;
9835 }
9836 inst.instruction |= (flags & SPSR_BIT) >> 2;
9837 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9838 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9839 inst.instruction |= inst.operands[1].reg << 16;
9840}
b05fe5cf 9841
c19d1205
ZW
9842static void
9843do_t_mul (void)
9844{
9845 if (!inst.operands[2].present)
9846 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9847
c19d1205
ZW
9848 /* There is no 32-bit MULS and no 16-bit MUL. */
9849 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9850 {
c19d1205
ZW
9851 inst.instruction = THUMB_OP32 (inst.instruction);
9852 inst.instruction |= inst.operands[0].reg << 8;
9853 inst.instruction |= inst.operands[1].reg << 16;
9854 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9855 }
c19d1205 9856 else
b05fe5cf 9857 {
c19d1205
ZW
9858 constraint (!unified_syntax
9859 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9860 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9861 BAD_HIREG);
b05fe5cf 9862
c19d1205
ZW
9863 inst.instruction = THUMB_OP16 (inst.instruction);
9864 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9865
c19d1205
ZW
9866 if (inst.operands[0].reg == inst.operands[1].reg)
9867 inst.instruction |= inst.operands[2].reg << 3;
9868 else if (inst.operands[0].reg == inst.operands[2].reg)
9869 inst.instruction |= inst.operands[1].reg << 3;
9870 else
9871 constraint (1, _("dest must overlap one source register"));
9872 }
9873}
b05fe5cf 9874
c19d1205
ZW
9875static void
9876do_t_mull (void)
9877{
9878 inst.instruction |= inst.operands[0].reg << 12;
9879 inst.instruction |= inst.operands[1].reg << 8;
9880 inst.instruction |= inst.operands[2].reg << 16;
9881 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9882
c19d1205
ZW
9883 if (inst.operands[0].reg == inst.operands[1].reg)
9884 as_tsktsk (_("rdhi and rdlo must be different"));
9885}
b05fe5cf 9886
c19d1205
ZW
9887static void
9888do_t_nop (void)
9889{
9890 if (unified_syntax)
9891 {
9892 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9893 {
c19d1205
ZW
9894 inst.instruction = THUMB_OP32 (inst.instruction);
9895 inst.instruction |= inst.operands[0].imm;
9896 }
9897 else
9898 {
9899 inst.instruction = THUMB_OP16 (inst.instruction);
9900 inst.instruction |= inst.operands[0].imm << 4;
9901 }
9902 }
9903 else
9904 {
9905 constraint (inst.operands[0].present,
9906 _("Thumb does not support NOP with hints"));
9907 inst.instruction = 0x46c0;
9908 }
9909}
b05fe5cf 9910
c19d1205
ZW
9911static void
9912do_t_neg (void)
9913{
9914 if (unified_syntax)
9915 {
3d388997
PB
9916 bfd_boolean narrow;
9917
9918 if (THUMB_SETS_FLAGS (inst.instruction))
9919 narrow = (current_it_mask == 0);
9920 else
9921 narrow = (current_it_mask != 0);
9922 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9923 narrow = FALSE;
9924 if (inst.size_req == 4)
9925 narrow = FALSE;
9926
9927 if (!narrow)
c19d1205
ZW
9928 {
9929 inst.instruction = THUMB_OP32 (inst.instruction);
9930 inst.instruction |= inst.operands[0].reg << 8;
9931 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9932 }
9933 else
9934 {
c19d1205
ZW
9935 inst.instruction = THUMB_OP16 (inst.instruction);
9936 inst.instruction |= inst.operands[0].reg;
9937 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9938 }
9939 }
9940 else
9941 {
c19d1205
ZW
9942 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9943 BAD_HIREG);
9944 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9945
9946 inst.instruction = THUMB_OP16 (inst.instruction);
9947 inst.instruction |= inst.operands[0].reg;
9948 inst.instruction |= inst.operands[1].reg << 3;
9949 }
9950}
9951
9952static void
9953do_t_pkhbt (void)
9954{
9955 inst.instruction |= inst.operands[0].reg << 8;
9956 inst.instruction |= inst.operands[1].reg << 16;
9957 inst.instruction |= inst.operands[2].reg;
9958 if (inst.operands[3].present)
9959 {
9960 unsigned int val = inst.reloc.exp.X_add_number;
9961 constraint (inst.reloc.exp.X_op != O_constant,
9962 _("expression too complex"));
9963 inst.instruction |= (val & 0x1c) << 10;
9964 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9965 }
c19d1205 9966}
b05fe5cf 9967
c19d1205
ZW
9968static void
9969do_t_pkhtb (void)
9970{
9971 if (!inst.operands[3].present)
9972 inst.instruction &= ~0x00000020;
9973 do_t_pkhbt ();
b05fe5cf
ZW
9974}
9975
c19d1205
ZW
9976static void
9977do_t_pld (void)
9978{
9979 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9980}
b05fe5cf 9981
c19d1205
ZW
9982static void
9983do_t_push_pop (void)
b99bd4ef 9984{
e9f89963 9985 unsigned mask;
5f4273c7 9986
c19d1205
ZW
9987 constraint (inst.operands[0].writeback,
9988 _("push/pop do not support {reglist}^"));
9989 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9990 _("expression too complex"));
b99bd4ef 9991
e9f89963
PB
9992 mask = inst.operands[0].imm;
9993 if ((mask & ~0xff) == 0)
3c707909 9994 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 9995 else if ((inst.instruction == T_MNEM_push
e9f89963 9996 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 9997 || (inst.instruction == T_MNEM_pop
e9f89963 9998 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 9999 {
c19d1205
ZW
10000 inst.instruction = THUMB_OP16 (inst.instruction);
10001 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10002 inst.instruction |= mask & 0xff;
c19d1205
ZW
10003 }
10004 else if (unified_syntax)
10005 {
3c707909 10006 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10007 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10008 }
10009 else
10010 {
10011 inst.error = _("invalid register list to push/pop instruction");
10012 return;
10013 }
c19d1205 10014}
b99bd4ef 10015
c19d1205
ZW
10016static void
10017do_t_rbit (void)
10018{
10019 inst.instruction |= inst.operands[0].reg << 8;
10020 inst.instruction |= inst.operands[1].reg << 16;
10021}
b99bd4ef 10022
c19d1205
ZW
10023static void
10024do_t_rev (void)
10025{
10026 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10027 && inst.size_req != 4)
10028 {
10029 inst.instruction = THUMB_OP16 (inst.instruction);
10030 inst.instruction |= inst.operands[0].reg;
10031 inst.instruction |= inst.operands[1].reg << 3;
10032 }
10033 else if (unified_syntax)
10034 {
10035 inst.instruction = THUMB_OP32 (inst.instruction);
10036 inst.instruction |= inst.operands[0].reg << 8;
10037 inst.instruction |= inst.operands[1].reg << 16;
10038 inst.instruction |= inst.operands[1].reg;
10039 }
10040 else
10041 inst.error = BAD_HIREG;
10042}
b99bd4ef 10043
c19d1205
ZW
10044static void
10045do_t_rsb (void)
10046{
10047 int Rd, Rs;
b99bd4ef 10048
c19d1205
ZW
10049 Rd = inst.operands[0].reg;
10050 Rs = (inst.operands[1].present
10051 ? inst.operands[1].reg /* Rd, Rs, foo */
10052 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10053
c19d1205
ZW
10054 inst.instruction |= Rd << 8;
10055 inst.instruction |= Rs << 16;
10056 if (!inst.operands[2].isreg)
10057 {
026d3abb
PB
10058 bfd_boolean narrow;
10059
10060 if ((inst.instruction & 0x00100000) != 0)
10061 narrow = (current_it_mask == 0);
10062 else
10063 narrow = (current_it_mask != 0);
10064
10065 if (Rd > 7 || Rs > 7)
10066 narrow = FALSE;
10067
10068 if (inst.size_req == 4 || !unified_syntax)
10069 narrow = FALSE;
10070
10071 if (inst.reloc.exp.X_op != O_constant
10072 || inst.reloc.exp.X_add_number != 0)
10073 narrow = FALSE;
10074
10075 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10076 relaxation, but it doesn't seem worth the hassle. */
10077 if (narrow)
10078 {
10079 inst.reloc.type = BFD_RELOC_UNUSED;
10080 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10081 inst.instruction |= Rs << 3;
10082 inst.instruction |= Rd;
10083 }
10084 else
10085 {
10086 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10087 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10088 }
c19d1205
ZW
10089 }
10090 else
10091 encode_thumb32_shifted_operand (2);
10092}
b99bd4ef 10093
c19d1205
ZW
10094static void
10095do_t_setend (void)
10096{
dfa9f0d5 10097 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10098 if (inst.operands[0].imm)
10099 inst.instruction |= 0x8;
10100}
b99bd4ef 10101
c19d1205
ZW
10102static void
10103do_t_shift (void)
10104{
10105 if (!inst.operands[1].present)
10106 inst.operands[1].reg = inst.operands[0].reg;
10107
10108 if (unified_syntax)
10109 {
3d388997
PB
10110 bfd_boolean narrow;
10111 int shift_kind;
10112
10113 switch (inst.instruction)
10114 {
10115 case T_MNEM_asr:
10116 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10117 case T_MNEM_lsl:
10118 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10119 case T_MNEM_lsr:
10120 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10121 case T_MNEM_ror:
10122 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10123 default: abort ();
10124 }
10125
10126 if (THUMB_SETS_FLAGS (inst.instruction))
10127 narrow = (current_it_mask == 0);
10128 else
10129 narrow = (current_it_mask != 0);
10130 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10131 narrow = FALSE;
10132 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10133 narrow = FALSE;
10134 if (inst.operands[2].isreg
10135 && (inst.operands[1].reg != inst.operands[0].reg
10136 || inst.operands[2].reg > 7))
10137 narrow = FALSE;
10138 if (inst.size_req == 4)
10139 narrow = FALSE;
10140
10141 if (!narrow)
c19d1205
ZW
10142 {
10143 if (inst.operands[2].isreg)
b99bd4ef 10144 {
c19d1205
ZW
10145 inst.instruction = THUMB_OP32 (inst.instruction);
10146 inst.instruction |= inst.operands[0].reg << 8;
10147 inst.instruction |= inst.operands[1].reg << 16;
10148 inst.instruction |= inst.operands[2].reg;
10149 }
10150 else
10151 {
10152 inst.operands[1].shifted = 1;
3d388997 10153 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10154 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10155 ? T_MNEM_movs : T_MNEM_mov);
10156 inst.instruction |= inst.operands[0].reg << 8;
10157 encode_thumb32_shifted_operand (1);
10158 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10159 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10160 }
10161 }
10162 else
10163 {
c19d1205 10164 if (inst.operands[2].isreg)
b99bd4ef 10165 {
3d388997 10166 switch (shift_kind)
b99bd4ef 10167 {
3d388997
PB
10168 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10169 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10170 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10171 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10172 default: abort ();
b99bd4ef 10173 }
5f4273c7 10174
c19d1205
ZW
10175 inst.instruction |= inst.operands[0].reg;
10176 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10177 }
10178 else
10179 {
3d388997 10180 switch (shift_kind)
b99bd4ef 10181 {
3d388997
PB
10182 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10183 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10184 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10185 default: abort ();
b99bd4ef 10186 }
c19d1205
ZW
10187 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10188 inst.instruction |= inst.operands[0].reg;
10189 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10190 }
10191 }
c19d1205
ZW
10192 }
10193 else
10194 {
10195 constraint (inst.operands[0].reg > 7
10196 || inst.operands[1].reg > 7, BAD_HIREG);
10197 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10198
c19d1205
ZW
10199 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10200 {
10201 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10202 constraint (inst.operands[0].reg != inst.operands[1].reg,
10203 _("source1 and dest must be same register"));
b99bd4ef 10204
c19d1205
ZW
10205 switch (inst.instruction)
10206 {
10207 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10208 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10209 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10210 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10211 default: abort ();
10212 }
5f4273c7 10213
c19d1205
ZW
10214 inst.instruction |= inst.operands[0].reg;
10215 inst.instruction |= inst.operands[2].reg << 3;
10216 }
10217 else
b99bd4ef 10218 {
c19d1205
ZW
10219 switch (inst.instruction)
10220 {
10221 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10222 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10223 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10224 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10225 default: abort ();
10226 }
10227 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10228 inst.instruction |= inst.operands[0].reg;
10229 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10230 }
10231 }
b99bd4ef
NC
10232}
10233
10234static void
c19d1205 10235do_t_simd (void)
b99bd4ef 10236{
c19d1205
ZW
10237 inst.instruction |= inst.operands[0].reg << 8;
10238 inst.instruction |= inst.operands[1].reg << 16;
10239 inst.instruction |= inst.operands[2].reg;
10240}
b99bd4ef 10241
c19d1205 10242static void
3eb17e6b 10243do_t_smc (void)
c19d1205
ZW
10244{
10245 unsigned int value = inst.reloc.exp.X_add_number;
10246 constraint (inst.reloc.exp.X_op != O_constant,
10247 _("expression too complex"));
10248 inst.reloc.type = BFD_RELOC_UNUSED;
10249 inst.instruction |= (value & 0xf000) >> 12;
10250 inst.instruction |= (value & 0x0ff0);
10251 inst.instruction |= (value & 0x000f) << 16;
10252}
b99bd4ef 10253
c19d1205
ZW
10254static void
10255do_t_ssat (void)
10256{
10257 inst.instruction |= inst.operands[0].reg << 8;
10258 inst.instruction |= inst.operands[1].imm - 1;
10259 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10260
c19d1205 10261 if (inst.operands[3].present)
b99bd4ef 10262 {
c19d1205
ZW
10263 constraint (inst.reloc.exp.X_op != O_constant,
10264 _("expression too complex"));
b99bd4ef 10265
c19d1205 10266 if (inst.reloc.exp.X_add_number != 0)
6189168b 10267 {
c19d1205
ZW
10268 if (inst.operands[3].shift_kind == SHIFT_ASR)
10269 inst.instruction |= 0x00200000; /* sh bit */
10270 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10271 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10272 }
c19d1205 10273 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10274 }
b99bd4ef
NC
10275}
10276
0dd132b6 10277static void
c19d1205 10278do_t_ssat16 (void)
0dd132b6 10279{
c19d1205
ZW
10280 inst.instruction |= inst.operands[0].reg << 8;
10281 inst.instruction |= inst.operands[1].imm - 1;
10282 inst.instruction |= inst.operands[2].reg << 16;
10283}
0dd132b6 10284
c19d1205
ZW
10285static void
10286do_t_strex (void)
10287{
10288 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10289 || inst.operands[2].postind || inst.operands[2].writeback
10290 || inst.operands[2].immisreg || inst.operands[2].shifted
10291 || inst.operands[2].negative,
01cfc07f 10292 BAD_ADDR_MODE);
0dd132b6 10293
c19d1205
ZW
10294 inst.instruction |= inst.operands[0].reg << 8;
10295 inst.instruction |= inst.operands[1].reg << 12;
10296 inst.instruction |= inst.operands[2].reg << 16;
10297 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10298}
10299
b99bd4ef 10300static void
c19d1205 10301do_t_strexd (void)
b99bd4ef 10302{
c19d1205
ZW
10303 if (!inst.operands[2].present)
10304 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10305
c19d1205
ZW
10306 constraint (inst.operands[0].reg == inst.operands[1].reg
10307 || inst.operands[0].reg == inst.operands[2].reg
10308 || inst.operands[0].reg == inst.operands[3].reg
10309 || inst.operands[1].reg == inst.operands[2].reg,
10310 BAD_OVERLAP);
b99bd4ef 10311
c19d1205
ZW
10312 inst.instruction |= inst.operands[0].reg;
10313 inst.instruction |= inst.operands[1].reg << 12;
10314 inst.instruction |= inst.operands[2].reg << 8;
10315 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10316}
10317
10318static void
c19d1205 10319do_t_sxtah (void)
b99bd4ef 10320{
c19d1205
ZW
10321 inst.instruction |= inst.operands[0].reg << 8;
10322 inst.instruction |= inst.operands[1].reg << 16;
10323 inst.instruction |= inst.operands[2].reg;
10324 inst.instruction |= inst.operands[3].imm << 4;
10325}
b99bd4ef 10326
c19d1205
ZW
10327static void
10328do_t_sxth (void)
10329{
10330 if (inst.instruction <= 0xffff && inst.size_req != 4
10331 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10332 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10333 {
c19d1205
ZW
10334 inst.instruction = THUMB_OP16 (inst.instruction);
10335 inst.instruction |= inst.operands[0].reg;
10336 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10337 }
c19d1205 10338 else if (unified_syntax)
b99bd4ef 10339 {
c19d1205
ZW
10340 if (inst.instruction <= 0xffff)
10341 inst.instruction = THUMB_OP32 (inst.instruction);
10342 inst.instruction |= inst.operands[0].reg << 8;
10343 inst.instruction |= inst.operands[1].reg;
10344 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10345 }
c19d1205 10346 else
b99bd4ef 10347 {
c19d1205
ZW
10348 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10349 _("Thumb encoding does not support rotation"));
10350 constraint (1, BAD_HIREG);
b99bd4ef 10351 }
c19d1205 10352}
b99bd4ef 10353
c19d1205
ZW
10354static void
10355do_t_swi (void)
10356{
10357 inst.reloc.type = BFD_RELOC_ARM_SWI;
10358}
b99bd4ef 10359
92e90b6e
PB
10360static void
10361do_t_tb (void)
10362{
10363 int half;
10364
10365 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10366 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10367 constraint (inst.operands[0].immisreg,
10368 _("instruction requires register index"));
92e90b6e
PB
10369 constraint (inst.operands[0].imm == 15,
10370 _("PC is not a valid index register"));
10371 constraint (!half && inst.operands[0].shifted,
10372 _("instruction does not allow shifted index"));
92e90b6e
PB
10373 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10374}
10375
c19d1205
ZW
10376static void
10377do_t_usat (void)
10378{
10379 inst.instruction |= inst.operands[0].reg << 8;
10380 inst.instruction |= inst.operands[1].imm;
10381 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10382
c19d1205 10383 if (inst.operands[3].present)
b99bd4ef 10384 {
c19d1205
ZW
10385 constraint (inst.reloc.exp.X_op != O_constant,
10386 _("expression too complex"));
10387 if (inst.reloc.exp.X_add_number != 0)
10388 {
10389 if (inst.operands[3].shift_kind == SHIFT_ASR)
10390 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10391
c19d1205
ZW
10392 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10393 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10394 }
10395 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10396 }
b99bd4ef
NC
10397}
10398
10399static void
c19d1205 10400do_t_usat16 (void)
b99bd4ef 10401{
c19d1205
ZW
10402 inst.instruction |= inst.operands[0].reg << 8;
10403 inst.instruction |= inst.operands[1].imm;
10404 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10405}
c19d1205 10406
5287ad62 10407/* Neon instruction encoder helpers. */
5f4273c7 10408
5287ad62 10409/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10410
5287ad62
JB
10411/* An "invalid" code for the following tables. */
10412#define N_INV -1u
10413
10414struct neon_tab_entry
b99bd4ef 10415{
5287ad62
JB
10416 unsigned integer;
10417 unsigned float_or_poly;
10418 unsigned scalar_or_imm;
10419};
5f4273c7 10420
5287ad62
JB
10421/* Map overloaded Neon opcodes to their respective encodings. */
10422#define NEON_ENC_TAB \
10423 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10424 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10425 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10426 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10427 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10428 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10429 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10430 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10431 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10432 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10433 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10434 /* Register variants of the following two instructions are encoded as
10435 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10436 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10437 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10438 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10439 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10440 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10441 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10442 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10443 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10444 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10445 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10446 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10447 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10448 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10449 X(vshl, 0x0000400, N_INV, 0x0800510), \
10450 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10451 X(vand, 0x0000110, N_INV, 0x0800030), \
10452 X(vbic, 0x0100110, N_INV, 0x0800030), \
10453 X(veor, 0x1000110, N_INV, N_INV), \
10454 X(vorn, 0x0300110, N_INV, 0x0800010), \
10455 X(vorr, 0x0200110, N_INV, 0x0800010), \
10456 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10457 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10458 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10459 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10460 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10461 X(vst1, 0x0000000, 0x0800000, N_INV), \
10462 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10463 X(vst2, 0x0000100, 0x0800100, N_INV), \
10464 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10465 X(vst3, 0x0000200, 0x0800200, N_INV), \
10466 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10467 X(vst4, 0x0000300, 0x0800300, N_INV), \
10468 X(vmovn, 0x1b20200, N_INV, N_INV), \
10469 X(vtrn, 0x1b20080, N_INV, N_INV), \
10470 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10471 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10472 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10473 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10474 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10475 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10476 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10477 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10478 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10479
10480enum neon_opc
10481{
10482#define X(OPC,I,F,S) N_MNEM_##OPC
10483NEON_ENC_TAB
10484#undef X
10485};
b99bd4ef 10486
5287ad62
JB
10487static const struct neon_tab_entry neon_enc_tab[] =
10488{
10489#define X(OPC,I,F,S) { (I), (F), (S) }
10490NEON_ENC_TAB
10491#undef X
10492};
b99bd4ef 10493
5287ad62
JB
10494#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10495#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10496#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10497#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10498#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10499#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10500#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10501#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10502#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10503#define NEON_ENC_SINGLE(X) \
10504 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10505#define NEON_ENC_DOUBLE(X) \
10506 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10507
037e8744
JB
10508/* Define shapes for instruction operands. The following mnemonic characters
10509 are used in this table:
5287ad62 10510
037e8744 10511 F - VFP S<n> register
5287ad62
JB
10512 D - Neon D<n> register
10513 Q - Neon Q<n> register
10514 I - Immediate
10515 S - Scalar
10516 R - ARM register
10517 L - D<n> register list
5f4273c7 10518
037e8744
JB
10519 This table is used to generate various data:
10520 - enumerations of the form NS_DDR to be used as arguments to
10521 neon_select_shape.
10522 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10523 - a table used to drive neon_select_shape. */
b99bd4ef 10524
037e8744
JB
10525#define NEON_SHAPE_DEF \
10526 X(3, (D, D, D), DOUBLE), \
10527 X(3, (Q, Q, Q), QUAD), \
10528 X(3, (D, D, I), DOUBLE), \
10529 X(3, (Q, Q, I), QUAD), \
10530 X(3, (D, D, S), DOUBLE), \
10531 X(3, (Q, Q, S), QUAD), \
10532 X(2, (D, D), DOUBLE), \
10533 X(2, (Q, Q), QUAD), \
10534 X(2, (D, S), DOUBLE), \
10535 X(2, (Q, S), QUAD), \
10536 X(2, (D, R), DOUBLE), \
10537 X(2, (Q, R), QUAD), \
10538 X(2, (D, I), DOUBLE), \
10539 X(2, (Q, I), QUAD), \
10540 X(3, (D, L, D), DOUBLE), \
10541 X(2, (D, Q), MIXED), \
10542 X(2, (Q, D), MIXED), \
10543 X(3, (D, Q, I), MIXED), \
10544 X(3, (Q, D, I), MIXED), \
10545 X(3, (Q, D, D), MIXED), \
10546 X(3, (D, Q, Q), MIXED), \
10547 X(3, (Q, Q, D), MIXED), \
10548 X(3, (Q, D, S), MIXED), \
10549 X(3, (D, Q, S), MIXED), \
10550 X(4, (D, D, D, I), DOUBLE), \
10551 X(4, (Q, Q, Q, I), QUAD), \
10552 X(2, (F, F), SINGLE), \
10553 X(3, (F, F, F), SINGLE), \
10554 X(2, (F, I), SINGLE), \
10555 X(2, (F, D), MIXED), \
10556 X(2, (D, F), MIXED), \
10557 X(3, (F, F, I), MIXED), \
10558 X(4, (R, R, F, F), SINGLE), \
10559 X(4, (F, F, R, R), SINGLE), \
10560 X(3, (D, R, R), DOUBLE), \
10561 X(3, (R, R, D), DOUBLE), \
10562 X(2, (S, R), SINGLE), \
10563 X(2, (R, S), SINGLE), \
10564 X(2, (F, R), SINGLE), \
10565 X(2, (R, F), SINGLE)
10566
10567#define S2(A,B) NS_##A##B
10568#define S3(A,B,C) NS_##A##B##C
10569#define S4(A,B,C,D) NS_##A##B##C##D
10570
10571#define X(N, L, C) S##N L
10572
5287ad62
JB
10573enum neon_shape
10574{
037e8744
JB
10575 NEON_SHAPE_DEF,
10576 NS_NULL
5287ad62 10577};
b99bd4ef 10578
037e8744
JB
10579#undef X
10580#undef S2
10581#undef S3
10582#undef S4
10583
10584enum neon_shape_class
10585{
10586 SC_SINGLE,
10587 SC_DOUBLE,
10588 SC_QUAD,
10589 SC_MIXED
10590};
10591
10592#define X(N, L, C) SC_##C
10593
10594static enum neon_shape_class neon_shape_class[] =
10595{
10596 NEON_SHAPE_DEF
10597};
10598
10599#undef X
10600
10601enum neon_shape_el
10602{
10603 SE_F,
10604 SE_D,
10605 SE_Q,
10606 SE_I,
10607 SE_S,
10608 SE_R,
10609 SE_L
10610};
10611
10612/* Register widths of above. */
10613static unsigned neon_shape_el_size[] =
10614{
10615 32,
10616 64,
10617 128,
10618 0,
10619 32,
10620 32,
10621 0
10622};
10623
10624struct neon_shape_info
10625{
10626 unsigned els;
10627 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10628};
10629
10630#define S2(A,B) { SE_##A, SE_##B }
10631#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10632#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10633
10634#define X(N, L, C) { N, S##N L }
10635
10636static struct neon_shape_info neon_shape_tab[] =
10637{
10638 NEON_SHAPE_DEF
10639};
10640
10641#undef X
10642#undef S2
10643#undef S3
10644#undef S4
10645
5287ad62
JB
10646/* Bit masks used in type checking given instructions.
10647 'N_EQK' means the type must be the same as (or based on in some way) the key
10648 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10649 set, various other bits can be set as well in order to modify the meaning of
10650 the type constraint. */
10651
10652enum neon_type_mask
10653{
10654 N_S8 = 0x000001,
10655 N_S16 = 0x000002,
10656 N_S32 = 0x000004,
10657 N_S64 = 0x000008,
10658 N_U8 = 0x000010,
10659 N_U16 = 0x000020,
10660 N_U32 = 0x000040,
10661 N_U64 = 0x000080,
10662 N_I8 = 0x000100,
10663 N_I16 = 0x000200,
10664 N_I32 = 0x000400,
10665 N_I64 = 0x000800,
10666 N_8 = 0x001000,
10667 N_16 = 0x002000,
10668 N_32 = 0x004000,
10669 N_64 = 0x008000,
10670 N_P8 = 0x010000,
10671 N_P16 = 0x020000,
10672 N_F32 = 0x040000,
037e8744
JB
10673 N_F64 = 0x080000,
10674 N_KEY = 0x100000, /* key element (main type specifier). */
10675 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10676 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10677 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10678 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10679 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10680 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10681 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10682 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10683 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10684 N_UTYP = 0,
037e8744 10685 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10686};
10687
dcbf9037
JB
10688#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10689
5287ad62
JB
10690#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10691#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10692#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10693#define N_SUF_32 (N_SU_32 | N_F32)
10694#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10695#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10696
10697/* Pass this as the first type argument to neon_check_type to ignore types
10698 altogether. */
10699#define N_IGNORE_TYPE (N_KEY | N_EQK)
10700
037e8744
JB
10701/* Select a "shape" for the current instruction (describing register types or
10702 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10703 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10704 function of operand parsing, so this function doesn't need to be called.
10705 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10706
10707static enum neon_shape
037e8744 10708neon_select_shape (enum neon_shape shape, ...)
5287ad62 10709{
037e8744
JB
10710 va_list ap;
10711 enum neon_shape first_shape = shape;
5287ad62
JB
10712
10713 /* Fix missing optional operands. FIXME: we don't know at this point how
10714 many arguments we should have, so this makes the assumption that we have
10715 > 1. This is true of all current Neon opcodes, I think, but may not be
10716 true in the future. */
10717 if (!inst.operands[1].present)
10718 inst.operands[1] = inst.operands[0];
10719
037e8744 10720 va_start (ap, shape);
5f4273c7 10721
037e8744
JB
10722 for (; shape != NS_NULL; shape = va_arg (ap, int))
10723 {
10724 unsigned j;
10725 int matches = 1;
10726
10727 for (j = 0; j < neon_shape_tab[shape].els; j++)
10728 {
10729 if (!inst.operands[j].present)
10730 {
10731 matches = 0;
10732 break;
10733 }
10734
10735 switch (neon_shape_tab[shape].el[j])
10736 {
10737 case SE_F:
10738 if (!(inst.operands[j].isreg
10739 && inst.operands[j].isvec
10740 && inst.operands[j].issingle
10741 && !inst.operands[j].isquad))
10742 matches = 0;
10743 break;
10744
10745 case SE_D:
10746 if (!(inst.operands[j].isreg
10747 && inst.operands[j].isvec
10748 && !inst.operands[j].isquad
10749 && !inst.operands[j].issingle))
10750 matches = 0;
10751 break;
10752
10753 case SE_R:
10754 if (!(inst.operands[j].isreg
10755 && !inst.operands[j].isvec))
10756 matches = 0;
10757 break;
10758
10759 case SE_Q:
10760 if (!(inst.operands[j].isreg
10761 && inst.operands[j].isvec
10762 && inst.operands[j].isquad
10763 && !inst.operands[j].issingle))
10764 matches = 0;
10765 break;
10766
10767 case SE_I:
10768 if (!(!inst.operands[j].isreg
10769 && !inst.operands[j].isscalar))
10770 matches = 0;
10771 break;
10772
10773 case SE_S:
10774 if (!(!inst.operands[j].isreg
10775 && inst.operands[j].isscalar))
10776 matches = 0;
10777 break;
10778
10779 case SE_L:
10780 break;
10781 }
10782 }
10783 if (matches)
5287ad62 10784 break;
037e8744 10785 }
5f4273c7 10786
037e8744 10787 va_end (ap);
5287ad62 10788
037e8744
JB
10789 if (shape == NS_NULL && first_shape != NS_NULL)
10790 first_error (_("invalid instruction shape"));
5287ad62 10791
037e8744
JB
10792 return shape;
10793}
5287ad62 10794
037e8744
JB
10795/* True if SHAPE is predominantly a quadword operation (most of the time, this
10796 means the Q bit should be set). */
10797
10798static int
10799neon_quad (enum neon_shape shape)
10800{
10801 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10802}
037e8744 10803
5287ad62
JB
10804static void
10805neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10806 unsigned *g_size)
10807{
10808 /* Allow modification to be made to types which are constrained to be
10809 based on the key element, based on bits set alongside N_EQK. */
10810 if ((typebits & N_EQK) != 0)
10811 {
10812 if ((typebits & N_HLF) != 0)
10813 *g_size /= 2;
10814 else if ((typebits & N_DBL) != 0)
10815 *g_size *= 2;
10816 if ((typebits & N_SGN) != 0)
10817 *g_type = NT_signed;
10818 else if ((typebits & N_UNS) != 0)
10819 *g_type = NT_unsigned;
10820 else if ((typebits & N_INT) != 0)
10821 *g_type = NT_integer;
10822 else if ((typebits & N_FLT) != 0)
10823 *g_type = NT_float;
dcbf9037
JB
10824 else if ((typebits & N_SIZ) != 0)
10825 *g_type = NT_untyped;
5287ad62
JB
10826 }
10827}
5f4273c7 10828
5287ad62
JB
10829/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10830 operand type, i.e. the single type specified in a Neon instruction when it
10831 is the only one given. */
10832
10833static struct neon_type_el
10834neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10835{
10836 struct neon_type_el dest = *key;
5f4273c7 10837
5287ad62 10838 assert ((thisarg & N_EQK) != 0);
5f4273c7 10839
5287ad62
JB
10840 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10841
10842 return dest;
10843}
10844
10845/* Convert Neon type and size into compact bitmask representation. */
10846
10847static enum neon_type_mask
10848type_chk_of_el_type (enum neon_el_type type, unsigned size)
10849{
10850 switch (type)
10851 {
10852 case NT_untyped:
10853 switch (size)
10854 {
10855 case 8: return N_8;
10856 case 16: return N_16;
10857 case 32: return N_32;
10858 case 64: return N_64;
10859 default: ;
10860 }
10861 break;
10862
10863 case NT_integer:
10864 switch (size)
10865 {
10866 case 8: return N_I8;
10867 case 16: return N_I16;
10868 case 32: return N_I32;
10869 case 64: return N_I64;
10870 default: ;
10871 }
10872 break;
10873
10874 case NT_float:
037e8744
JB
10875 switch (size)
10876 {
10877 case 32: return N_F32;
10878 case 64: return N_F64;
10879 default: ;
10880 }
5287ad62
JB
10881 break;
10882
10883 case NT_poly:
10884 switch (size)
10885 {
10886 case 8: return N_P8;
10887 case 16: return N_P16;
10888 default: ;
10889 }
10890 break;
10891
10892 case NT_signed:
10893 switch (size)
10894 {
10895 case 8: return N_S8;
10896 case 16: return N_S16;
10897 case 32: return N_S32;
10898 case 64: return N_S64;
10899 default: ;
10900 }
10901 break;
10902
10903 case NT_unsigned:
10904 switch (size)
10905 {
10906 case 8: return N_U8;
10907 case 16: return N_U16;
10908 case 32: return N_U32;
10909 case 64: return N_U64;
10910 default: ;
10911 }
10912 break;
10913
10914 default: ;
10915 }
5f4273c7 10916
5287ad62
JB
10917 return N_UTYP;
10918}
10919
10920/* Convert compact Neon bitmask type representation to a type and size. Only
10921 handles the case where a single bit is set in the mask. */
10922
dcbf9037 10923static int
5287ad62
JB
10924el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10925 enum neon_type_mask mask)
10926{
dcbf9037
JB
10927 if ((mask & N_EQK) != 0)
10928 return FAIL;
10929
5287ad62
JB
10930 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10931 *size = 8;
dcbf9037 10932 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10933 *size = 16;
dcbf9037 10934 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10935 *size = 32;
037e8744 10936 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10937 *size = 64;
dcbf9037
JB
10938 else
10939 return FAIL;
10940
5287ad62
JB
10941 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10942 *type = NT_signed;
dcbf9037 10943 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10944 *type = NT_unsigned;
dcbf9037 10945 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10946 *type = NT_integer;
dcbf9037 10947 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10948 *type = NT_untyped;
dcbf9037 10949 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10950 *type = NT_poly;
037e8744 10951 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10952 *type = NT_float;
dcbf9037
JB
10953 else
10954 return FAIL;
5f4273c7 10955
dcbf9037 10956 return SUCCESS;
5287ad62
JB
10957}
10958
10959/* Modify a bitmask of allowed types. This is only needed for type
10960 relaxation. */
10961
10962static unsigned
10963modify_types_allowed (unsigned allowed, unsigned mods)
10964{
10965 unsigned size;
10966 enum neon_el_type type;
10967 unsigned destmask;
10968 int i;
5f4273c7 10969
5287ad62 10970 destmask = 0;
5f4273c7 10971
5287ad62
JB
10972 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10973 {
dcbf9037
JB
10974 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10975 {
10976 neon_modify_type_size (mods, &type, &size);
10977 destmask |= type_chk_of_el_type (type, size);
10978 }
5287ad62 10979 }
5f4273c7 10980
5287ad62
JB
10981 return destmask;
10982}
10983
10984/* Check type and return type classification.
10985 The manual states (paraphrase): If one datatype is given, it indicates the
10986 type given in:
10987 - the second operand, if there is one
10988 - the operand, if there is no second operand
10989 - the result, if there are no operands.
10990 This isn't quite good enough though, so we use a concept of a "key" datatype
10991 which is set on a per-instruction basis, which is the one which matters when
10992 only one data type is written.
10993 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 10994 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
10995
10996static struct neon_type_el
10997neon_check_type (unsigned els, enum neon_shape ns, ...)
10998{
10999 va_list ap;
11000 unsigned i, pass, key_el = 0;
11001 unsigned types[NEON_MAX_TYPE_ELS];
11002 enum neon_el_type k_type = NT_invtype;
11003 unsigned k_size = -1u;
11004 struct neon_type_el badtype = {NT_invtype, -1};
11005 unsigned key_allowed = 0;
11006
11007 /* Optional registers in Neon instructions are always (not) in operand 1.
11008 Fill in the missing operand here, if it was omitted. */
11009 if (els > 1 && !inst.operands[1].present)
11010 inst.operands[1] = inst.operands[0];
11011
11012 /* Suck up all the varargs. */
11013 va_start (ap, ns);
11014 for (i = 0; i < els; i++)
11015 {
11016 unsigned thisarg = va_arg (ap, unsigned);
11017 if (thisarg == N_IGNORE_TYPE)
11018 {
11019 va_end (ap);
11020 return badtype;
11021 }
11022 types[i] = thisarg;
11023 if ((thisarg & N_KEY) != 0)
11024 key_el = i;
11025 }
11026 va_end (ap);
11027
dcbf9037
JB
11028 if (inst.vectype.elems > 0)
11029 for (i = 0; i < els; i++)
11030 if (inst.operands[i].vectype.type != NT_invtype)
11031 {
11032 first_error (_("types specified in both the mnemonic and operands"));
11033 return badtype;
11034 }
11035
5287ad62
JB
11036 /* Duplicate inst.vectype elements here as necessary.
11037 FIXME: No idea if this is exactly the same as the ARM assembler,
11038 particularly when an insn takes one register and one non-register
11039 operand. */
11040 if (inst.vectype.elems == 1 && els > 1)
11041 {
11042 unsigned j;
11043 inst.vectype.elems = els;
11044 inst.vectype.el[key_el] = inst.vectype.el[0];
11045 for (j = 0; j < els; j++)
dcbf9037
JB
11046 if (j != key_el)
11047 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11048 types[j]);
11049 }
11050 else if (inst.vectype.elems == 0 && els > 0)
11051 {
11052 unsigned j;
11053 /* No types were given after the mnemonic, so look for types specified
11054 after each operand. We allow some flexibility here; as long as the
11055 "key" operand has a type, we can infer the others. */
11056 for (j = 0; j < els; j++)
11057 if (inst.operands[j].vectype.type != NT_invtype)
11058 inst.vectype.el[j] = inst.operands[j].vectype;
11059
11060 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11061 {
dcbf9037
JB
11062 for (j = 0; j < els; j++)
11063 if (inst.operands[j].vectype.type == NT_invtype)
11064 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11065 types[j]);
11066 }
11067 else
11068 {
11069 first_error (_("operand types can't be inferred"));
11070 return badtype;
5287ad62
JB
11071 }
11072 }
11073 else if (inst.vectype.elems != els)
11074 {
dcbf9037 11075 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11076 return badtype;
11077 }
11078
11079 for (pass = 0; pass < 2; pass++)
11080 {
11081 for (i = 0; i < els; i++)
11082 {
11083 unsigned thisarg = types[i];
11084 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11085 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11086 enum neon_el_type g_type = inst.vectype.el[i].type;
11087 unsigned g_size = inst.vectype.el[i].size;
11088
11089 /* Decay more-specific signed & unsigned types to sign-insensitive
11090 integer types if sign-specific variants are unavailable. */
11091 if ((g_type == NT_signed || g_type == NT_unsigned)
11092 && (types_allowed & N_SU_ALL) == 0)
11093 g_type = NT_integer;
11094
11095 /* If only untyped args are allowed, decay any more specific types to
11096 them. Some instructions only care about signs for some element
11097 sizes, so handle that properly. */
11098 if ((g_size == 8 && (types_allowed & N_8) != 0)
11099 || (g_size == 16 && (types_allowed & N_16) != 0)
11100 || (g_size == 32 && (types_allowed & N_32) != 0)
11101 || (g_size == 64 && (types_allowed & N_64) != 0))
11102 g_type = NT_untyped;
11103
11104 if (pass == 0)
11105 {
11106 if ((thisarg & N_KEY) != 0)
11107 {
11108 k_type = g_type;
11109 k_size = g_size;
11110 key_allowed = thisarg & ~N_KEY;
11111 }
11112 }
11113 else
11114 {
037e8744
JB
11115 if ((thisarg & N_VFP) != 0)
11116 {
11117 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11118 unsigned regwidth = neon_shape_el_size[regshape], match;
11119
11120 /* In VFP mode, operands must match register widths. If we
11121 have a key operand, use its width, else use the width of
11122 the current operand. */
11123 if (k_size != -1u)
11124 match = k_size;
11125 else
11126 match = g_size;
11127
11128 if (regwidth != match)
11129 {
11130 first_error (_("operand size must match register width"));
11131 return badtype;
11132 }
11133 }
5f4273c7 11134
5287ad62
JB
11135 if ((thisarg & N_EQK) == 0)
11136 {
11137 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11138
11139 if ((given_type & types_allowed) == 0)
11140 {
dcbf9037 11141 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11142 return badtype;
11143 }
11144 }
11145 else
11146 {
11147 enum neon_el_type mod_k_type = k_type;
11148 unsigned mod_k_size = k_size;
11149 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11150 if (g_type != mod_k_type || g_size != mod_k_size)
11151 {
dcbf9037 11152 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11153 return badtype;
11154 }
11155 }
11156 }
11157 }
11158 }
11159
11160 return inst.vectype.el[key_el];
11161}
11162
037e8744 11163/* Neon-style VFP instruction forwarding. */
5287ad62 11164
037e8744
JB
11165/* Thumb VFP instructions have 0xE in the condition field. */
11166
11167static void
11168do_vfp_cond_or_thumb (void)
5287ad62
JB
11169{
11170 if (thumb_mode)
037e8744 11171 inst.instruction |= 0xe0000000;
5287ad62 11172 else
037e8744 11173 inst.instruction |= inst.cond << 28;
5287ad62
JB
11174}
11175
037e8744
JB
11176/* Look up and encode a simple mnemonic, for use as a helper function for the
11177 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11178 etc. It is assumed that operand parsing has already been done, and that the
11179 operands are in the form expected by the given opcode (this isn't necessarily
11180 the same as the form in which they were parsed, hence some massaging must
11181 take place before this function is called).
11182 Checks current arch version against that in the looked-up opcode. */
5287ad62 11183
037e8744
JB
11184static void
11185do_vfp_nsyn_opcode (const char *opname)
5287ad62 11186{
037e8744 11187 const struct asm_opcode *opcode;
5f4273c7 11188
037e8744 11189 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11190
037e8744
JB
11191 if (!opcode)
11192 abort ();
5287ad62 11193
037e8744
JB
11194 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11195 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11196 _(BAD_FPU));
5287ad62 11197
037e8744
JB
11198 if (thumb_mode)
11199 {
11200 inst.instruction = opcode->tvalue;
11201 opcode->tencode ();
11202 }
11203 else
11204 {
11205 inst.instruction = (inst.cond << 28) | opcode->avalue;
11206 opcode->aencode ();
11207 }
11208}
5287ad62
JB
11209
11210static void
037e8744 11211do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11212{
037e8744
JB
11213 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11214
11215 if (rs == NS_FFF)
11216 {
11217 if (is_add)
11218 do_vfp_nsyn_opcode ("fadds");
11219 else
11220 do_vfp_nsyn_opcode ("fsubs");
11221 }
11222 else
11223 {
11224 if (is_add)
11225 do_vfp_nsyn_opcode ("faddd");
11226 else
11227 do_vfp_nsyn_opcode ("fsubd");
11228 }
11229}
11230
11231/* Check operand types to see if this is a VFP instruction, and if so call
11232 PFN (). */
11233
11234static int
11235try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11236{
11237 enum neon_shape rs;
11238 struct neon_type_el et;
11239
11240 switch (args)
11241 {
11242 case 2:
11243 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11244 et = neon_check_type (2, rs,
11245 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11246 break;
5f4273c7 11247
037e8744
JB
11248 case 3:
11249 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11250 et = neon_check_type (3, rs,
11251 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11252 break;
11253
11254 default:
11255 abort ();
11256 }
11257
11258 if (et.type != NT_invtype)
11259 {
11260 pfn (rs);
11261 return SUCCESS;
11262 }
11263 else
11264 inst.error = NULL;
11265
11266 return FAIL;
11267}
11268
11269static void
11270do_vfp_nsyn_mla_mls (enum neon_shape rs)
11271{
11272 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11273
037e8744
JB
11274 if (rs == NS_FFF)
11275 {
11276 if (is_mla)
11277 do_vfp_nsyn_opcode ("fmacs");
11278 else
11279 do_vfp_nsyn_opcode ("fmscs");
11280 }
11281 else
11282 {
11283 if (is_mla)
11284 do_vfp_nsyn_opcode ("fmacd");
11285 else
11286 do_vfp_nsyn_opcode ("fmscd");
11287 }
11288}
11289
11290static void
11291do_vfp_nsyn_mul (enum neon_shape rs)
11292{
11293 if (rs == NS_FFF)
11294 do_vfp_nsyn_opcode ("fmuls");
11295 else
11296 do_vfp_nsyn_opcode ("fmuld");
11297}
11298
11299static void
11300do_vfp_nsyn_abs_neg (enum neon_shape rs)
11301{
11302 int is_neg = (inst.instruction & 0x80) != 0;
11303 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11304
11305 if (rs == NS_FF)
11306 {
11307 if (is_neg)
11308 do_vfp_nsyn_opcode ("fnegs");
11309 else
11310 do_vfp_nsyn_opcode ("fabss");
11311 }
11312 else
11313 {
11314 if (is_neg)
11315 do_vfp_nsyn_opcode ("fnegd");
11316 else
11317 do_vfp_nsyn_opcode ("fabsd");
11318 }
11319}
11320
11321/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11322 insns belong to Neon, and are handled elsewhere. */
11323
11324static void
11325do_vfp_nsyn_ldm_stm (int is_dbmode)
11326{
11327 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11328 if (is_ldm)
11329 {
11330 if (is_dbmode)
11331 do_vfp_nsyn_opcode ("fldmdbs");
11332 else
11333 do_vfp_nsyn_opcode ("fldmias");
11334 }
11335 else
11336 {
11337 if (is_dbmode)
11338 do_vfp_nsyn_opcode ("fstmdbs");
11339 else
11340 do_vfp_nsyn_opcode ("fstmias");
11341 }
11342}
11343
037e8744
JB
11344static void
11345do_vfp_nsyn_sqrt (void)
11346{
11347 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11348 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11349
037e8744
JB
11350 if (rs == NS_FF)
11351 do_vfp_nsyn_opcode ("fsqrts");
11352 else
11353 do_vfp_nsyn_opcode ("fsqrtd");
11354}
11355
11356static void
11357do_vfp_nsyn_div (void)
11358{
11359 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11360 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11361 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11362
037e8744
JB
11363 if (rs == NS_FFF)
11364 do_vfp_nsyn_opcode ("fdivs");
11365 else
11366 do_vfp_nsyn_opcode ("fdivd");
11367}
11368
11369static void
11370do_vfp_nsyn_nmul (void)
11371{
11372 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11373 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11374 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11375
037e8744
JB
11376 if (rs == NS_FFF)
11377 {
11378 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11379 do_vfp_sp_dyadic ();
11380 }
11381 else
11382 {
11383 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11384 do_vfp_dp_rd_rn_rm ();
11385 }
11386 do_vfp_cond_or_thumb ();
11387}
11388
11389static void
11390do_vfp_nsyn_cmp (void)
11391{
11392 if (inst.operands[1].isreg)
11393 {
11394 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11395 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11396
037e8744
JB
11397 if (rs == NS_FF)
11398 {
11399 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11400 do_vfp_sp_monadic ();
11401 }
11402 else
11403 {
11404 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11405 do_vfp_dp_rd_rm ();
11406 }
11407 }
11408 else
11409 {
11410 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11411 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11412
11413 switch (inst.instruction & 0x0fffffff)
11414 {
11415 case N_MNEM_vcmp:
11416 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11417 break;
11418 case N_MNEM_vcmpe:
11419 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11420 break;
11421 default:
11422 abort ();
11423 }
5f4273c7 11424
037e8744
JB
11425 if (rs == NS_FI)
11426 {
11427 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11428 do_vfp_sp_compare_z ();
11429 }
11430 else
11431 {
11432 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11433 do_vfp_dp_rd ();
11434 }
11435 }
11436 do_vfp_cond_or_thumb ();
11437}
11438
11439static void
11440nsyn_insert_sp (void)
11441{
11442 inst.operands[1] = inst.operands[0];
11443 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11444 inst.operands[0].reg = 13;
11445 inst.operands[0].isreg = 1;
11446 inst.operands[0].writeback = 1;
11447 inst.operands[0].present = 1;
11448}
11449
11450static void
11451do_vfp_nsyn_push (void)
11452{
11453 nsyn_insert_sp ();
11454 if (inst.operands[1].issingle)
11455 do_vfp_nsyn_opcode ("fstmdbs");
11456 else
11457 do_vfp_nsyn_opcode ("fstmdbd");
11458}
11459
11460static void
11461do_vfp_nsyn_pop (void)
11462{
11463 nsyn_insert_sp ();
11464 if (inst.operands[1].issingle)
22b5b651 11465 do_vfp_nsyn_opcode ("fldmias");
037e8744 11466 else
22b5b651 11467 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11468}
11469
11470/* Fix up Neon data-processing instructions, ORing in the correct bits for
11471 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11472
11473static unsigned
11474neon_dp_fixup (unsigned i)
11475{
11476 if (thumb_mode)
11477 {
11478 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11479 if (i & (1 << 24))
11480 i |= 1 << 28;
5f4273c7 11481
037e8744 11482 i &= ~(1 << 24);
5f4273c7 11483
037e8744
JB
11484 i |= 0xef000000;
11485 }
11486 else
11487 i |= 0xf2000000;
5f4273c7 11488
037e8744
JB
11489 return i;
11490}
11491
11492/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11493 (0, 1, 2, 3). */
11494
11495static unsigned
11496neon_logbits (unsigned x)
11497{
11498 return ffs (x) - 4;
11499}
11500
11501#define LOW4(R) ((R) & 0xf)
11502#define HI1(R) (((R) >> 4) & 1)
11503
11504/* Encode insns with bit pattern:
11505
11506 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11507 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11508
037e8744
JB
11509 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11510 different meaning for some instruction. */
11511
11512static void
11513neon_three_same (int isquad, int ubit, int size)
11514{
11515 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11516 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11517 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11518 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11519 inst.instruction |= LOW4 (inst.operands[2].reg);
11520 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11521 inst.instruction |= (isquad != 0) << 6;
11522 inst.instruction |= (ubit != 0) << 24;
11523 if (size != -1)
11524 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11525
037e8744
JB
11526 inst.instruction = neon_dp_fixup (inst.instruction);
11527}
11528
11529/* Encode instructions of the form:
11530
11531 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11532 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11533
11534 Don't write size if SIZE == -1. */
11535
11536static void
11537neon_two_same (int qbit, int ubit, int size)
11538{
11539 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11540 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11541 inst.instruction |= LOW4 (inst.operands[1].reg);
11542 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11543 inst.instruction |= (qbit != 0) << 6;
11544 inst.instruction |= (ubit != 0) << 24;
11545
11546 if (size != -1)
11547 inst.instruction |= neon_logbits (size) << 18;
11548
11549 inst.instruction = neon_dp_fixup (inst.instruction);
11550}
11551
11552/* Neon instruction encoders, in approximate order of appearance. */
11553
11554static void
11555do_neon_dyadic_i_su (void)
11556{
037e8744 11557 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11558 struct neon_type_el et = neon_check_type (3, rs,
11559 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11560 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11561}
11562
11563static void
11564do_neon_dyadic_i64_su (void)
11565{
037e8744 11566 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11567 struct neon_type_el et = neon_check_type (3, rs,
11568 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11569 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11570}
11571
11572static void
11573neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11574 unsigned immbits)
11575{
11576 unsigned size = et.size >> 3;
11577 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11578 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11579 inst.instruction |= LOW4 (inst.operands[1].reg);
11580 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11581 inst.instruction |= (isquad != 0) << 6;
11582 inst.instruction |= immbits << 16;
11583 inst.instruction |= (size >> 3) << 7;
11584 inst.instruction |= (size & 0x7) << 19;
11585 if (write_ubit)
11586 inst.instruction |= (uval != 0) << 24;
11587
11588 inst.instruction = neon_dp_fixup (inst.instruction);
11589}
11590
11591static void
11592do_neon_shl_imm (void)
11593{
11594 if (!inst.operands[2].isreg)
11595 {
037e8744 11596 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11597 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11598 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11599 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11600 }
11601 else
11602 {
037e8744 11603 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11604 struct neon_type_el et = neon_check_type (3, rs,
11605 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11606 unsigned int tmp;
11607
11608 /* VSHL/VQSHL 3-register variants have syntax such as:
11609 vshl.xx Dd, Dm, Dn
11610 whereas other 3-register operations encoded by neon_three_same have
11611 syntax like:
11612 vadd.xx Dd, Dn, Dm
11613 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11614 here. */
11615 tmp = inst.operands[2].reg;
11616 inst.operands[2].reg = inst.operands[1].reg;
11617 inst.operands[1].reg = tmp;
5287ad62 11618 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11619 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11620 }
11621}
11622
11623static void
11624do_neon_qshl_imm (void)
11625{
11626 if (!inst.operands[2].isreg)
11627 {
037e8744 11628 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11629 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11630
5287ad62 11631 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11632 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11633 inst.operands[2].imm);
11634 }
11635 else
11636 {
037e8744 11637 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11638 struct neon_type_el et = neon_check_type (3, rs,
11639 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11640 unsigned int tmp;
11641
11642 /* See note in do_neon_shl_imm. */
11643 tmp = inst.operands[2].reg;
11644 inst.operands[2].reg = inst.operands[1].reg;
11645 inst.operands[1].reg = tmp;
5287ad62 11646 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11647 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11648 }
11649}
11650
627907b7
JB
11651static void
11652do_neon_rshl (void)
11653{
11654 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11655 struct neon_type_el et = neon_check_type (3, rs,
11656 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11657 unsigned int tmp;
11658
11659 tmp = inst.operands[2].reg;
11660 inst.operands[2].reg = inst.operands[1].reg;
11661 inst.operands[1].reg = tmp;
11662 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11663}
11664
5287ad62
JB
11665static int
11666neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11667{
036dc3f7
PB
11668 /* Handle .I8 pseudo-instructions. */
11669 if (size == 8)
5287ad62 11670 {
5287ad62
JB
11671 /* Unfortunately, this will make everything apart from zero out-of-range.
11672 FIXME is this the intended semantics? There doesn't seem much point in
11673 accepting .I8 if so. */
11674 immediate |= immediate << 8;
11675 size = 16;
036dc3f7
PB
11676 }
11677
11678 if (size >= 32)
11679 {
11680 if (immediate == (immediate & 0x000000ff))
11681 {
11682 *immbits = immediate;
11683 return 0x1;
11684 }
11685 else if (immediate == (immediate & 0x0000ff00))
11686 {
11687 *immbits = immediate >> 8;
11688 return 0x3;
11689 }
11690 else if (immediate == (immediate & 0x00ff0000))
11691 {
11692 *immbits = immediate >> 16;
11693 return 0x5;
11694 }
11695 else if (immediate == (immediate & 0xff000000))
11696 {
11697 *immbits = immediate >> 24;
11698 return 0x7;
11699 }
11700 if ((immediate & 0xffff) != (immediate >> 16))
11701 goto bad_immediate;
11702 immediate &= 0xffff;
5287ad62
JB
11703 }
11704
11705 if (immediate == (immediate & 0x000000ff))
11706 {
11707 *immbits = immediate;
036dc3f7 11708 return 0x9;
5287ad62
JB
11709 }
11710 else if (immediate == (immediate & 0x0000ff00))
11711 {
11712 *immbits = immediate >> 8;
036dc3f7 11713 return 0xb;
5287ad62
JB
11714 }
11715
11716 bad_immediate:
dcbf9037 11717 first_error (_("immediate value out of range"));
5287ad62
JB
11718 return FAIL;
11719}
11720
11721/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11722 A, B, C, D. */
11723
11724static int
11725neon_bits_same_in_bytes (unsigned imm)
11726{
11727 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11728 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11729 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11730 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11731}
11732
11733/* For immediate of above form, return 0bABCD. */
11734
11735static unsigned
11736neon_squash_bits (unsigned imm)
11737{
11738 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11739 | ((imm & 0x01000000) >> 21);
11740}
11741
136da414 11742/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11743
11744static unsigned
11745neon_qfloat_bits (unsigned imm)
11746{
136da414 11747 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11748}
11749
11750/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11751 the instruction. *OP is passed as the initial value of the op field, and
11752 may be set to a different value depending on the constant (i.e.
11753 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 11754 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 11755 try smaller element sizes. */
5287ad62
JB
11756
11757static int
c96612cc
JB
11758neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11759 unsigned *immbits, int *op, int size,
11760 enum neon_el_type type)
5287ad62 11761{
c96612cc
JB
11762 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11763 float. */
11764 if (type == NT_float && !float_p)
11765 return FAIL;
11766
136da414
JB
11767 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11768 {
11769 if (size != 32 || *op == 1)
11770 return FAIL;
11771 *immbits = neon_qfloat_bits (immlo);
11772 return 0xf;
11773 }
036dc3f7
PB
11774
11775 if (size == 64)
5287ad62 11776 {
036dc3f7
PB
11777 if (neon_bits_same_in_bytes (immhi)
11778 && neon_bits_same_in_bytes (immlo))
11779 {
11780 if (*op == 1)
11781 return FAIL;
11782 *immbits = (neon_squash_bits (immhi) << 4)
11783 | neon_squash_bits (immlo);
11784 *op = 1;
11785 return 0xe;
11786 }
11787
11788 if (immhi != immlo)
11789 return FAIL;
5287ad62 11790 }
036dc3f7
PB
11791
11792 if (size >= 32)
5287ad62 11793 {
036dc3f7
PB
11794 if (immlo == (immlo & 0x000000ff))
11795 {
11796 *immbits = immlo;
11797 return 0x0;
11798 }
11799 else if (immlo == (immlo & 0x0000ff00))
11800 {
11801 *immbits = immlo >> 8;
11802 return 0x2;
11803 }
11804 else if (immlo == (immlo & 0x00ff0000))
11805 {
11806 *immbits = immlo >> 16;
11807 return 0x4;
11808 }
11809 else if (immlo == (immlo & 0xff000000))
11810 {
11811 *immbits = immlo >> 24;
11812 return 0x6;
11813 }
11814 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11815 {
11816 *immbits = (immlo >> 8) & 0xff;
11817 return 0xc;
11818 }
11819 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11820 {
11821 *immbits = (immlo >> 16) & 0xff;
11822 return 0xd;
11823 }
11824
11825 if ((immlo & 0xffff) != (immlo >> 16))
11826 return FAIL;
11827 immlo &= 0xffff;
5287ad62 11828 }
036dc3f7
PB
11829
11830 if (size >= 16)
5287ad62 11831 {
036dc3f7
PB
11832 if (immlo == (immlo & 0x000000ff))
11833 {
11834 *immbits = immlo;
11835 return 0x8;
11836 }
11837 else if (immlo == (immlo & 0x0000ff00))
11838 {
11839 *immbits = immlo >> 8;
11840 return 0xa;
11841 }
11842
11843 if ((immlo & 0xff) != (immlo >> 8))
11844 return FAIL;
11845 immlo &= 0xff;
5287ad62 11846 }
036dc3f7
PB
11847
11848 if (immlo == (immlo & 0x000000ff))
5287ad62 11849 {
036dc3f7
PB
11850 /* Don't allow MVN with 8-bit immediate. */
11851 if (*op == 1)
11852 return FAIL;
11853 *immbits = immlo;
11854 return 0xe;
5287ad62 11855 }
5287ad62
JB
11856
11857 return FAIL;
11858}
11859
11860/* Write immediate bits [7:0] to the following locations:
11861
11862 |28/24|23 19|18 16|15 4|3 0|
11863 | 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|
11864
11865 This function is used by VMOV/VMVN/VORR/VBIC. */
11866
11867static void
11868neon_write_immbits (unsigned immbits)
11869{
11870 inst.instruction |= immbits & 0xf;
11871 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11872 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11873}
11874
11875/* Invert low-order SIZE bits of XHI:XLO. */
11876
11877static void
11878neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11879{
11880 unsigned immlo = xlo ? *xlo : 0;
11881 unsigned immhi = xhi ? *xhi : 0;
11882
11883 switch (size)
11884 {
11885 case 8:
11886 immlo = (~immlo) & 0xff;
11887 break;
11888
11889 case 16:
11890 immlo = (~immlo) & 0xffff;
11891 break;
11892
11893 case 64:
11894 immhi = (~immhi) & 0xffffffff;
11895 /* fall through. */
11896
11897 case 32:
11898 immlo = (~immlo) & 0xffffffff;
11899 break;
11900
11901 default:
11902 abort ();
11903 }
11904
11905 if (xlo)
11906 *xlo = immlo;
11907
11908 if (xhi)
11909 *xhi = immhi;
11910}
11911
11912static void
11913do_neon_logic (void)
11914{
11915 if (inst.operands[2].present && inst.operands[2].isreg)
11916 {
037e8744 11917 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11918 neon_check_type (3, rs, N_IGNORE_TYPE);
11919 /* U bit and size field were set as part of the bitmask. */
11920 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11921 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11922 }
11923 else
11924 {
037e8744
JB
11925 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11926 struct neon_type_el et = neon_check_type (2, rs,
11927 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11928 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11929 unsigned immbits;
11930 int cmode;
5f4273c7 11931
5287ad62
JB
11932 if (et.type == NT_invtype)
11933 return;
5f4273c7 11934
5287ad62
JB
11935 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11936
036dc3f7
PB
11937 immbits = inst.operands[1].imm;
11938 if (et.size == 64)
11939 {
11940 /* .i64 is a pseudo-op, so the immediate must be a repeating
11941 pattern. */
11942 if (immbits != (inst.operands[1].regisimm ?
11943 inst.operands[1].reg : 0))
11944 {
11945 /* Set immbits to an invalid constant. */
11946 immbits = 0xdeadbeef;
11947 }
11948 }
11949
5287ad62
JB
11950 switch (opcode)
11951 {
11952 case N_MNEM_vbic:
036dc3f7 11953 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11954 break;
5f4273c7 11955
5287ad62 11956 case N_MNEM_vorr:
036dc3f7 11957 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11958 break;
5f4273c7 11959
5287ad62
JB
11960 case N_MNEM_vand:
11961 /* Pseudo-instruction for VBIC. */
5287ad62
JB
11962 neon_invert_size (&immbits, 0, et.size);
11963 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11964 break;
5f4273c7 11965
5287ad62
JB
11966 case N_MNEM_vorn:
11967 /* Pseudo-instruction for VORR. */
5287ad62
JB
11968 neon_invert_size (&immbits, 0, et.size);
11969 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11970 break;
5f4273c7 11971
5287ad62
JB
11972 default:
11973 abort ();
11974 }
11975
11976 if (cmode == FAIL)
11977 return;
11978
037e8744 11979 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11980 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11981 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11982 inst.instruction |= cmode << 8;
11983 neon_write_immbits (immbits);
5f4273c7 11984
5287ad62
JB
11985 inst.instruction = neon_dp_fixup (inst.instruction);
11986 }
11987}
11988
11989static void
11990do_neon_bitfield (void)
11991{
037e8744 11992 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 11993 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 11994 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11995}
11996
11997static void
dcbf9037
JB
11998neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11999 unsigned destbits)
5287ad62 12000{
037e8744 12001 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12002 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12003 types | N_KEY);
5287ad62
JB
12004 if (et.type == NT_float)
12005 {
12006 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12007 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12008 }
12009 else
12010 {
12011 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12012 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12013 }
12014}
12015
12016static void
12017do_neon_dyadic_if_su (void)
12018{
dcbf9037 12019 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12020}
12021
12022static void
12023do_neon_dyadic_if_su_d (void)
12024{
12025 /* This version only allow D registers, but that constraint is enforced during
12026 operand parsing so we don't need to do anything extra here. */
dcbf9037 12027 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12028}
12029
5287ad62
JB
12030static void
12031do_neon_dyadic_if_i_d (void)
12032{
428e3f1f
PB
12033 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12034 affected if we specify unsigned args. */
12035 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12036}
12037
037e8744
JB
12038enum vfp_or_neon_is_neon_bits
12039{
12040 NEON_CHECK_CC = 1,
12041 NEON_CHECK_ARCH = 2
12042};
12043
12044/* Call this function if an instruction which may have belonged to the VFP or
12045 Neon instruction sets, but turned out to be a Neon instruction (due to the
12046 operand types involved, etc.). We have to check and/or fix-up a couple of
12047 things:
12048
12049 - Make sure the user hasn't attempted to make a Neon instruction
12050 conditional.
12051 - Alter the value in the condition code field if necessary.
12052 - Make sure that the arch supports Neon instructions.
12053
12054 Which of these operations take place depends on bits from enum
12055 vfp_or_neon_is_neon_bits.
12056
12057 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12058 current instruction's condition is COND_ALWAYS, the condition field is
12059 changed to inst.uncond_value. This is necessary because instructions shared
12060 between VFP and Neon may be conditional for the VFP variants only, and the
12061 unconditional Neon version must have, e.g., 0xF in the condition field. */
12062
12063static int
12064vfp_or_neon_is_neon (unsigned check)
12065{
12066 /* Conditions are always legal in Thumb mode (IT blocks). */
12067 if (!thumb_mode && (check & NEON_CHECK_CC))
12068 {
12069 if (inst.cond != COND_ALWAYS)
12070 {
12071 first_error (_(BAD_COND));
12072 return FAIL;
12073 }
12074 if (inst.uncond_value != -1)
12075 inst.instruction |= inst.uncond_value << 28;
12076 }
5f4273c7 12077
037e8744
JB
12078 if ((check & NEON_CHECK_ARCH)
12079 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12080 {
12081 first_error (_(BAD_FPU));
12082 return FAIL;
12083 }
5f4273c7 12084
037e8744
JB
12085 return SUCCESS;
12086}
12087
5287ad62
JB
12088static void
12089do_neon_addsub_if_i (void)
12090{
037e8744
JB
12091 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12092 return;
12093
12094 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12095 return;
12096
5287ad62
JB
12097 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12098 affected if we specify unsigned args. */
dcbf9037 12099 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12100}
12101
12102/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12103 result to be:
12104 V<op> A,B (A is operand 0, B is operand 2)
12105 to mean:
12106 V<op> A,B,A
12107 not:
12108 V<op> A,B,B
12109 so handle that case specially. */
12110
12111static void
12112neon_exchange_operands (void)
12113{
12114 void *scratch = alloca (sizeof (inst.operands[0]));
12115 if (inst.operands[1].present)
12116 {
12117 /* Swap operands[1] and operands[2]. */
12118 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12119 inst.operands[1] = inst.operands[2];
12120 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12121 }
12122 else
12123 {
12124 inst.operands[1] = inst.operands[2];
12125 inst.operands[2] = inst.operands[0];
12126 }
12127}
12128
12129static void
12130neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12131{
12132 if (inst.operands[2].isreg)
12133 {
12134 if (invert)
12135 neon_exchange_operands ();
dcbf9037 12136 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12137 }
12138 else
12139 {
037e8744 12140 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12141 struct neon_type_el et = neon_check_type (2, rs,
12142 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12143
12144 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12145 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12146 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12147 inst.instruction |= LOW4 (inst.operands[1].reg);
12148 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12149 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12150 inst.instruction |= (et.type == NT_float) << 10;
12151 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12152
5287ad62
JB
12153 inst.instruction = neon_dp_fixup (inst.instruction);
12154 }
12155}
12156
12157static void
12158do_neon_cmp (void)
12159{
12160 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12161}
12162
12163static void
12164do_neon_cmp_inv (void)
12165{
12166 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12167}
12168
12169static void
12170do_neon_ceq (void)
12171{
12172 neon_compare (N_IF_32, N_IF_32, FALSE);
12173}
12174
12175/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12176 scalars, which are encoded in 5 bits, M : Rm.
12177 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12178 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12179 index in M. */
12180
12181static unsigned
12182neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12183{
dcbf9037
JB
12184 unsigned regno = NEON_SCALAR_REG (scalar);
12185 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12186
12187 switch (elsize)
12188 {
12189 case 16:
12190 if (regno > 7 || elno > 3)
12191 goto bad_scalar;
12192 return regno | (elno << 3);
5f4273c7 12193
5287ad62
JB
12194 case 32:
12195 if (regno > 15 || elno > 1)
12196 goto bad_scalar;
12197 return regno | (elno << 4);
12198
12199 default:
12200 bad_scalar:
dcbf9037 12201 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12202 }
12203
12204 return 0;
12205}
12206
12207/* Encode multiply / multiply-accumulate scalar instructions. */
12208
12209static void
12210neon_mul_mac (struct neon_type_el et, int ubit)
12211{
dcbf9037
JB
12212 unsigned scalar;
12213
12214 /* Give a more helpful error message if we have an invalid type. */
12215 if (et.type == NT_invtype)
12216 return;
5f4273c7 12217
dcbf9037 12218 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12219 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12220 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12221 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12222 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12223 inst.instruction |= LOW4 (scalar);
12224 inst.instruction |= HI1 (scalar) << 5;
12225 inst.instruction |= (et.type == NT_float) << 8;
12226 inst.instruction |= neon_logbits (et.size) << 20;
12227 inst.instruction |= (ubit != 0) << 24;
12228
12229 inst.instruction = neon_dp_fixup (inst.instruction);
12230}
12231
12232static void
12233do_neon_mac_maybe_scalar (void)
12234{
037e8744
JB
12235 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12236 return;
12237
12238 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12239 return;
12240
5287ad62
JB
12241 if (inst.operands[2].isscalar)
12242 {
037e8744 12243 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12244 struct neon_type_el et = neon_check_type (3, rs,
12245 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12246 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12247 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12248 }
12249 else
428e3f1f
PB
12250 {
12251 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12252 affected if we specify unsigned args. */
12253 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12254 }
5287ad62
JB
12255}
12256
12257static void
12258do_neon_tst (void)
12259{
037e8744 12260 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12261 struct neon_type_el et = neon_check_type (3, rs,
12262 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12263 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12264}
12265
12266/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12267 same types as the MAC equivalents. The polynomial type for this instruction
12268 is encoded the same as the integer type. */
12269
12270static void
12271do_neon_mul (void)
12272{
037e8744
JB
12273 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12274 return;
12275
12276 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12277 return;
12278
5287ad62
JB
12279 if (inst.operands[2].isscalar)
12280 do_neon_mac_maybe_scalar ();
12281 else
dcbf9037 12282 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12283}
12284
12285static void
12286do_neon_qdmulh (void)
12287{
12288 if (inst.operands[2].isscalar)
12289 {
037e8744 12290 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12291 struct neon_type_el et = neon_check_type (3, rs,
12292 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12293 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12294 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12295 }
12296 else
12297 {
037e8744 12298 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12299 struct neon_type_el et = neon_check_type (3, rs,
12300 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12301 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12302 /* The U bit (rounding) comes from bit mask. */
037e8744 12303 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12304 }
12305}
12306
12307static void
12308do_neon_fcmp_absolute (void)
12309{
037e8744 12310 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12311 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12312 /* Size field comes from bit mask. */
037e8744 12313 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12314}
12315
12316static void
12317do_neon_fcmp_absolute_inv (void)
12318{
12319 neon_exchange_operands ();
12320 do_neon_fcmp_absolute ();
12321}
12322
12323static void
12324do_neon_step (void)
12325{
037e8744 12326 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12327 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12328 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12329}
12330
12331static void
12332do_neon_abs_neg (void)
12333{
037e8744
JB
12334 enum neon_shape rs;
12335 struct neon_type_el et;
5f4273c7 12336
037e8744
JB
12337 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12338 return;
12339
12340 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12341 return;
12342
12343 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12344 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12345
5287ad62
JB
12346 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12347 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12348 inst.instruction |= LOW4 (inst.operands[1].reg);
12349 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12350 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12351 inst.instruction |= (et.type == NT_float) << 10;
12352 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12353
5287ad62
JB
12354 inst.instruction = neon_dp_fixup (inst.instruction);
12355}
12356
12357static void
12358do_neon_sli (void)
12359{
037e8744 12360 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12361 struct neon_type_el et = neon_check_type (2, rs,
12362 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12363 int imm = inst.operands[2].imm;
12364 constraint (imm < 0 || (unsigned)imm >= et.size,
12365 _("immediate out of range for insert"));
037e8744 12366 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12367}
12368
12369static void
12370do_neon_sri (void)
12371{
037e8744 12372 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12373 struct neon_type_el et = neon_check_type (2, rs,
12374 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12375 int imm = inst.operands[2].imm;
12376 constraint (imm < 1 || (unsigned)imm > et.size,
12377 _("immediate out of range for insert"));
037e8744 12378 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12379}
12380
12381static void
12382do_neon_qshlu_imm (void)
12383{
037e8744 12384 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12385 struct neon_type_el et = neon_check_type (2, rs,
12386 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12387 int imm = inst.operands[2].imm;
12388 constraint (imm < 0 || (unsigned)imm >= et.size,
12389 _("immediate out of range for shift"));
12390 /* Only encodes the 'U present' variant of the instruction.
12391 In this case, signed types have OP (bit 8) set to 0.
12392 Unsigned types have OP set to 1. */
12393 inst.instruction |= (et.type == NT_unsigned) << 8;
12394 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12395 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12396}
12397
12398static void
12399do_neon_qmovn (void)
12400{
12401 struct neon_type_el et = neon_check_type (2, NS_DQ,
12402 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12403 /* Saturating move where operands can be signed or unsigned, and the
12404 destination has the same signedness. */
12405 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12406 if (et.type == NT_unsigned)
12407 inst.instruction |= 0xc0;
12408 else
12409 inst.instruction |= 0x80;
12410 neon_two_same (0, 1, et.size / 2);
12411}
12412
12413static void
12414do_neon_qmovun (void)
12415{
12416 struct neon_type_el et = neon_check_type (2, NS_DQ,
12417 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12418 /* Saturating move with unsigned results. Operands must be signed. */
12419 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12420 neon_two_same (0, 1, et.size / 2);
12421}
12422
12423static void
12424do_neon_rshift_sat_narrow (void)
12425{
12426 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12427 or unsigned. If operands are unsigned, results must also be unsigned. */
12428 struct neon_type_el et = neon_check_type (2, NS_DQI,
12429 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12430 int imm = inst.operands[2].imm;
12431 /* This gets the bounds check, size encoding and immediate bits calculation
12432 right. */
12433 et.size /= 2;
5f4273c7 12434
5287ad62
JB
12435 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12436 VQMOVN.I<size> <Dd>, <Qm>. */
12437 if (imm == 0)
12438 {
12439 inst.operands[2].present = 0;
12440 inst.instruction = N_MNEM_vqmovn;
12441 do_neon_qmovn ();
12442 return;
12443 }
5f4273c7 12444
5287ad62
JB
12445 constraint (imm < 1 || (unsigned)imm > et.size,
12446 _("immediate out of range"));
12447 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12448}
12449
12450static void
12451do_neon_rshift_sat_narrow_u (void)
12452{
12453 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12454 or unsigned. If operands are unsigned, results must also be unsigned. */
12455 struct neon_type_el et = neon_check_type (2, NS_DQI,
12456 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12457 int imm = inst.operands[2].imm;
12458 /* This gets the bounds check, size encoding and immediate bits calculation
12459 right. */
12460 et.size /= 2;
12461
12462 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12463 VQMOVUN.I<size> <Dd>, <Qm>. */
12464 if (imm == 0)
12465 {
12466 inst.operands[2].present = 0;
12467 inst.instruction = N_MNEM_vqmovun;
12468 do_neon_qmovun ();
12469 return;
12470 }
12471
12472 constraint (imm < 1 || (unsigned)imm > et.size,
12473 _("immediate out of range"));
12474 /* FIXME: The manual is kind of unclear about what value U should have in
12475 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12476 must be 1. */
12477 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12478}
12479
12480static void
12481do_neon_movn (void)
12482{
12483 struct neon_type_el et = neon_check_type (2, NS_DQ,
12484 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12485 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12486 neon_two_same (0, 1, et.size / 2);
12487}
12488
12489static void
12490do_neon_rshift_narrow (void)
12491{
12492 struct neon_type_el et = neon_check_type (2, NS_DQI,
12493 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12494 int imm = inst.operands[2].imm;
12495 /* This gets the bounds check, size encoding and immediate bits calculation
12496 right. */
12497 et.size /= 2;
5f4273c7 12498
5287ad62
JB
12499 /* If immediate is zero then we are a pseudo-instruction for
12500 VMOVN.I<size> <Dd>, <Qm> */
12501 if (imm == 0)
12502 {
12503 inst.operands[2].present = 0;
12504 inst.instruction = N_MNEM_vmovn;
12505 do_neon_movn ();
12506 return;
12507 }
5f4273c7 12508
5287ad62
JB
12509 constraint (imm < 1 || (unsigned)imm > et.size,
12510 _("immediate out of range for narrowing operation"));
12511 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12512}
12513
12514static void
12515do_neon_shll (void)
12516{
12517 /* FIXME: Type checking when lengthening. */
12518 struct neon_type_el et = neon_check_type (2, NS_QDI,
12519 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12520 unsigned imm = inst.operands[2].imm;
12521
12522 if (imm == et.size)
12523 {
12524 /* Maximum shift variant. */
12525 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12526 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12527 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12528 inst.instruction |= LOW4 (inst.operands[1].reg);
12529 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12530 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12531
5287ad62
JB
12532 inst.instruction = neon_dp_fixup (inst.instruction);
12533 }
12534 else
12535 {
12536 /* A more-specific type check for non-max versions. */
12537 et = neon_check_type (2, NS_QDI,
12538 N_EQK | N_DBL, N_SU_32 | N_KEY);
12539 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12540 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12541 }
12542}
12543
037e8744 12544/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12545 the current instruction is. */
12546
12547static int
12548neon_cvt_flavour (enum neon_shape rs)
12549{
037e8744
JB
12550#define CVT_VAR(C,X,Y) \
12551 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12552 if (et.type != NT_invtype) \
12553 { \
12554 inst.error = NULL; \
12555 return (C); \
5287ad62
JB
12556 }
12557 struct neon_type_el et;
037e8744
JB
12558 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12559 || rs == NS_FF) ? N_VFP : 0;
12560 /* The instruction versions which take an immediate take one register
12561 argument, which is extended to the width of the full register. Thus the
12562 "source" and "destination" registers must have the same width. Hack that
12563 here by making the size equal to the key (wider, in this case) operand. */
12564 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 12565
5287ad62
JB
12566 CVT_VAR (0, N_S32, N_F32);
12567 CVT_VAR (1, N_U32, N_F32);
12568 CVT_VAR (2, N_F32, N_S32);
12569 CVT_VAR (3, N_F32, N_U32);
5f4273c7 12570
037e8744 12571 whole_reg = N_VFP;
5f4273c7 12572
037e8744
JB
12573 /* VFP instructions. */
12574 CVT_VAR (4, N_F32, N_F64);
12575 CVT_VAR (5, N_F64, N_F32);
12576 CVT_VAR (6, N_S32, N_F64 | key);
12577 CVT_VAR (7, N_U32, N_F64 | key);
12578 CVT_VAR (8, N_F64 | key, N_S32);
12579 CVT_VAR (9, N_F64 | key, N_U32);
12580 /* VFP instructions with bitshift. */
12581 CVT_VAR (10, N_F32 | key, N_S16);
12582 CVT_VAR (11, N_F32 | key, N_U16);
12583 CVT_VAR (12, N_F64 | key, N_S16);
12584 CVT_VAR (13, N_F64 | key, N_U16);
12585 CVT_VAR (14, N_S16, N_F32 | key);
12586 CVT_VAR (15, N_U16, N_F32 | key);
12587 CVT_VAR (16, N_S16, N_F64 | key);
12588 CVT_VAR (17, N_U16, N_F64 | key);
5f4273c7 12589
5287ad62
JB
12590 return -1;
12591#undef CVT_VAR
12592}
12593
037e8744
JB
12594/* Neon-syntax VFP conversions. */
12595
5287ad62 12596static void
037e8744 12597do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12598{
037e8744 12599 const char *opname = 0;
5f4273c7 12600
037e8744 12601 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12602 {
037e8744
JB
12603 /* Conversions with immediate bitshift. */
12604 const char *enc[] =
12605 {
12606 "ftosls",
12607 "ftouls",
12608 "fsltos",
12609 "fultos",
12610 NULL,
12611 NULL,
12612 "ftosld",
12613 "ftould",
12614 "fsltod",
12615 "fultod",
12616 "fshtos",
12617 "fuhtos",
12618 "fshtod",
12619 "fuhtod",
12620 "ftoshs",
12621 "ftouhs",
12622 "ftoshd",
12623 "ftouhd"
12624 };
12625
12626 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12627 {
12628 opname = enc[flavour];
12629 constraint (inst.operands[0].reg != inst.operands[1].reg,
12630 _("operands 0 and 1 must be the same register"));
12631 inst.operands[1] = inst.operands[2];
12632 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12633 }
5287ad62
JB
12634 }
12635 else
12636 {
037e8744
JB
12637 /* Conversions without bitshift. */
12638 const char *enc[] =
12639 {
12640 "ftosis",
12641 "ftouis",
12642 "fsitos",
12643 "fuitos",
12644 "fcvtsd",
12645 "fcvtds",
12646 "ftosid",
12647 "ftouid",
12648 "fsitod",
12649 "fuitod"
12650 };
12651
12652 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12653 opname = enc[flavour];
12654 }
12655
12656 if (opname)
12657 do_vfp_nsyn_opcode (opname);
12658}
12659
12660static void
12661do_vfp_nsyn_cvtz (void)
12662{
12663 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12664 int flavour = neon_cvt_flavour (rs);
12665 const char *enc[] =
12666 {
12667 "ftosizs",
12668 "ftouizs",
12669 NULL,
12670 NULL,
12671 NULL,
12672 NULL,
12673 "ftosizd",
12674 "ftouizd"
12675 };
12676
12677 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12678 do_vfp_nsyn_opcode (enc[flavour]);
12679}
12680
12681static void
12682do_neon_cvt (void)
12683{
12684 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12685 NS_FD, NS_DF, NS_FF, NS_NULL);
12686 int flavour = neon_cvt_flavour (rs);
12687
12688 /* VFP rather than Neon conversions. */
12689 if (flavour >= 4)
12690 {
12691 do_vfp_nsyn_cvt (rs, flavour);
12692 return;
12693 }
12694
12695 switch (rs)
12696 {
12697 case NS_DDI:
12698 case NS_QQI:
12699 {
12700 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12701 return;
12702
12703 /* Fixed-point conversion with #0 immediate is encoded as an
12704 integer conversion. */
12705 if (inst.operands[2].present && inst.operands[2].imm == 0)
12706 goto int_encode;
12707 unsigned immbits = 32 - inst.operands[2].imm;
12708 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12709 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12710 if (flavour != -1)
12711 inst.instruction |= enctab[flavour];
12712 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12713 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12714 inst.instruction |= LOW4 (inst.operands[1].reg);
12715 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12716 inst.instruction |= neon_quad (rs) << 6;
12717 inst.instruction |= 1 << 21;
12718 inst.instruction |= immbits << 16;
12719
12720 inst.instruction = neon_dp_fixup (inst.instruction);
12721 }
12722 break;
12723
12724 case NS_DD:
12725 case NS_QQ:
12726 int_encode:
12727 {
12728 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12729
12730 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12731
12732 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12733 return;
12734
12735 if (flavour != -1)
12736 inst.instruction |= enctab[flavour];
12737
12738 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12739 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12740 inst.instruction |= LOW4 (inst.operands[1].reg);
12741 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12742 inst.instruction |= neon_quad (rs) << 6;
12743 inst.instruction |= 2 << 18;
12744
12745 inst.instruction = neon_dp_fixup (inst.instruction);
12746 }
12747 break;
12748
12749 default:
12750 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12751 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12752 }
5287ad62
JB
12753}
12754
12755static void
12756neon_move_immediate (void)
12757{
037e8744
JB
12758 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12759 struct neon_type_el et = neon_check_type (2, rs,
12760 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12761 unsigned immlo, immhi = 0, immbits;
c96612cc 12762 int op, cmode, float_p;
5287ad62 12763
037e8744
JB
12764 constraint (et.type == NT_invtype,
12765 _("operand size must be specified for immediate VMOV"));
12766
5287ad62
JB
12767 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12768 op = (inst.instruction & (1 << 5)) != 0;
12769
12770 immlo = inst.operands[1].imm;
12771 if (inst.operands[1].regisimm)
12772 immhi = inst.operands[1].reg;
12773
12774 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12775 _("immediate has bits set outside the operand size"));
12776
c96612cc
JB
12777 float_p = inst.operands[1].immisfloat;
12778
12779 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12780 et.size, et.type)) == FAIL)
5287ad62
JB
12781 {
12782 /* Invert relevant bits only. */
12783 neon_invert_size (&immlo, &immhi, et.size);
12784 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12785 with one or the other; those cases are caught by
12786 neon_cmode_for_move_imm. */
12787 op = !op;
c96612cc
JB
12788 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12789 &op, et.size, et.type)) == FAIL)
5287ad62 12790 {
dcbf9037 12791 first_error (_("immediate out of range"));
5287ad62
JB
12792 return;
12793 }
12794 }
12795
12796 inst.instruction &= ~(1 << 5);
12797 inst.instruction |= op << 5;
12798
12799 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12800 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12801 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12802 inst.instruction |= cmode << 8;
12803
12804 neon_write_immbits (immbits);
12805}
12806
12807static void
12808do_neon_mvn (void)
12809{
12810 if (inst.operands[1].isreg)
12811 {
037e8744 12812 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 12813
5287ad62
JB
12814 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12815 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12816 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12817 inst.instruction |= LOW4 (inst.operands[1].reg);
12818 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12819 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12820 }
12821 else
12822 {
12823 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12824 neon_move_immediate ();
12825 }
12826
12827 inst.instruction = neon_dp_fixup (inst.instruction);
12828}
12829
12830/* Encode instructions of form:
12831
12832 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 12833 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
12834
12835static void
12836neon_mixed_length (struct neon_type_el et, unsigned size)
12837{
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) << 16;
12841 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12842 inst.instruction |= LOW4 (inst.operands[2].reg);
12843 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12844 inst.instruction |= (et.type == NT_unsigned) << 24;
12845 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12846
5287ad62
JB
12847 inst.instruction = neon_dp_fixup (inst.instruction);
12848}
12849
12850static void
12851do_neon_dyadic_long (void)
12852{
12853 /* FIXME: Type checking for lengthening op. */
12854 struct neon_type_el et = neon_check_type (3, NS_QDD,
12855 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12856 neon_mixed_length (et, et.size);
12857}
12858
12859static void
12860do_neon_abal (void)
12861{
12862 struct neon_type_el et = neon_check_type (3, NS_QDD,
12863 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12864 neon_mixed_length (et, et.size);
12865}
12866
12867static void
12868neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12869{
12870 if (inst.operands[2].isscalar)
12871 {
dcbf9037
JB
12872 struct neon_type_el et = neon_check_type (3, NS_QDS,
12873 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12874 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12875 neon_mul_mac (et, et.type == NT_unsigned);
12876 }
12877 else
12878 {
12879 struct neon_type_el et = neon_check_type (3, NS_QDD,
12880 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12881 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12882 neon_mixed_length (et, et.size);
12883 }
12884}
12885
12886static void
12887do_neon_mac_maybe_scalar_long (void)
12888{
12889 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12890}
12891
12892static void
12893do_neon_dyadic_wide (void)
12894{
12895 struct neon_type_el et = neon_check_type (3, NS_QQD,
12896 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12897 neon_mixed_length (et, et.size);
12898}
12899
12900static void
12901do_neon_dyadic_narrow (void)
12902{
12903 struct neon_type_el et = neon_check_type (3, NS_QDD,
12904 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12905 /* Operand sign is unimportant, and the U bit is part of the opcode,
12906 so force the operand type to integer. */
12907 et.type = NT_integer;
5287ad62
JB
12908 neon_mixed_length (et, et.size / 2);
12909}
12910
12911static void
12912do_neon_mul_sat_scalar_long (void)
12913{
12914 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12915}
12916
12917static void
12918do_neon_vmull (void)
12919{
12920 if (inst.operands[2].isscalar)
12921 do_neon_mac_maybe_scalar_long ();
12922 else
12923 {
12924 struct neon_type_el et = neon_check_type (3, NS_QDD,
12925 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12926 if (et.type == NT_poly)
12927 inst.instruction = NEON_ENC_POLY (inst.instruction);
12928 else
12929 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12930 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12931 zero. Should be OK as-is. */
12932 neon_mixed_length (et, et.size);
12933 }
12934}
12935
12936static void
12937do_neon_ext (void)
12938{
037e8744 12939 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12940 struct neon_type_el et = neon_check_type (3, rs,
12941 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12942 unsigned imm = (inst.operands[3].imm * et.size) / 8;
3b8d421e 12943 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
5287ad62
JB
12944 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12945 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12946 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12947 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12948 inst.instruction |= LOW4 (inst.operands[2].reg);
12949 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12950 inst.instruction |= neon_quad (rs) << 6;
5287ad62 12951 inst.instruction |= imm << 8;
5f4273c7 12952
5287ad62
JB
12953 inst.instruction = neon_dp_fixup (inst.instruction);
12954}
12955
12956static void
12957do_neon_rev (void)
12958{
037e8744 12959 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12960 struct neon_type_el et = neon_check_type (2, rs,
12961 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12962 unsigned op = (inst.instruction >> 7) & 3;
12963 /* N (width of reversed regions) is encoded as part of the bitmask. We
12964 extract it here to check the elements to be reversed are smaller.
12965 Otherwise we'd get a reserved instruction. */
12966 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12967 assert (elsize != 0);
12968 constraint (et.size >= elsize,
12969 _("elements must be smaller than reversal region"));
037e8744 12970 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12971}
12972
12973static void
12974do_neon_dup (void)
12975{
12976 if (inst.operands[1].isscalar)
12977 {
037e8744 12978 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
12979 struct neon_type_el et = neon_check_type (2, rs,
12980 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 12981 unsigned sizebits = et.size >> 3;
dcbf9037 12982 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 12983 int logsize = neon_logbits (et.size);
dcbf9037 12984 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
12985
12986 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12987 return;
12988
5287ad62
JB
12989 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12990 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12991 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12992 inst.instruction |= LOW4 (dm);
12993 inst.instruction |= HI1 (dm) << 5;
037e8744 12994 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12995 inst.instruction |= x << 17;
12996 inst.instruction |= sizebits << 16;
5f4273c7 12997
5287ad62
JB
12998 inst.instruction = neon_dp_fixup (inst.instruction);
12999 }
13000 else
13001 {
037e8744
JB
13002 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13003 struct neon_type_el et = neon_check_type (2, rs,
13004 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13005 /* Duplicate ARM register to lanes of vector. */
13006 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13007 switch (et.size)
13008 {
13009 case 8: inst.instruction |= 0x400000; break;
13010 case 16: inst.instruction |= 0x000020; break;
13011 case 32: inst.instruction |= 0x000000; break;
13012 default: break;
13013 }
13014 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13015 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13016 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13017 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13018 /* The encoding for this instruction is identical for the ARM and Thumb
13019 variants, except for the condition field. */
037e8744 13020 do_vfp_cond_or_thumb ();
5287ad62
JB
13021 }
13022}
13023
13024/* VMOV has particularly many variations. It can be one of:
13025 0. VMOV<c><q> <Qd>, <Qm>
13026 1. VMOV<c><q> <Dd>, <Dm>
13027 (Register operations, which are VORR with Rm = Rn.)
13028 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13029 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13030 (Immediate loads.)
13031 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13032 (ARM register to scalar.)
13033 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13034 (Two ARM registers to vector.)
13035 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13036 (Scalar to ARM register.)
13037 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13038 (Vector to two ARM registers.)
037e8744
JB
13039 8. VMOV.F32 <Sd>, <Sm>
13040 9. VMOV.F64 <Dd>, <Dm>
13041 (VFP register moves.)
13042 10. VMOV.F32 <Sd>, #imm
13043 11. VMOV.F64 <Dd>, #imm
13044 (VFP float immediate load.)
13045 12. VMOV <Rd>, <Sm>
13046 (VFP single to ARM reg.)
13047 13. VMOV <Sd>, <Rm>
13048 (ARM reg to VFP single.)
13049 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13050 (Two ARM regs to two VFP singles.)
13051 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13052 (Two VFP singles to two ARM regs.)
5f4273c7 13053
037e8744
JB
13054 These cases can be disambiguated using neon_select_shape, except cases 1/9
13055 and 3/11 which depend on the operand type too.
5f4273c7 13056
5287ad62 13057 All the encoded bits are hardcoded by this function.
5f4273c7 13058
b7fc2769
JB
13059 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13060 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13061
5287ad62 13062 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13063 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13064
13065static void
13066do_neon_mov (void)
13067{
037e8744
JB
13068 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13069 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13070 NS_NULL);
13071 struct neon_type_el et;
13072 const char *ldconst = 0;
5287ad62 13073
037e8744 13074 switch (rs)
5287ad62 13075 {
037e8744
JB
13076 case NS_DD: /* case 1/9. */
13077 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13078 /* It is not an error here if no type is given. */
13079 inst.error = NULL;
13080 if (et.type == NT_float && et.size == 64)
5287ad62 13081 {
037e8744
JB
13082 do_vfp_nsyn_opcode ("fcpyd");
13083 break;
5287ad62 13084 }
037e8744 13085 /* fall through. */
5287ad62 13086
037e8744
JB
13087 case NS_QQ: /* case 0/1. */
13088 {
13089 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13090 return;
13091 /* The architecture manual I have doesn't explicitly state which
13092 value the U bit should have for register->register moves, but
13093 the equivalent VORR instruction has U = 0, so do that. */
13094 inst.instruction = 0x0200110;
13095 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13096 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13097 inst.instruction |= LOW4 (inst.operands[1].reg);
13098 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13099 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13100 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13101 inst.instruction |= neon_quad (rs) << 6;
13102
13103 inst.instruction = neon_dp_fixup (inst.instruction);
13104 }
13105 break;
5f4273c7 13106
037e8744
JB
13107 case NS_DI: /* case 3/11. */
13108 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13109 inst.error = NULL;
13110 if (et.type == NT_float && et.size == 64)
5287ad62 13111 {
037e8744
JB
13112 /* case 11 (fconstd). */
13113 ldconst = "fconstd";
13114 goto encode_fconstd;
5287ad62 13115 }
037e8744
JB
13116 /* fall through. */
13117
13118 case NS_QI: /* case 2/3. */
13119 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13120 return;
13121 inst.instruction = 0x0800010;
13122 neon_move_immediate ();
13123 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13124 break;
5f4273c7 13125
037e8744
JB
13126 case NS_SR: /* case 4. */
13127 {
13128 unsigned bcdebits = 0;
13129 struct neon_type_el et = neon_check_type (2, NS_NULL,
13130 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13131 int logsize = neon_logbits (et.size);
13132 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13133 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13134
13135 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13136 _(BAD_FPU));
13137 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13138 && et.size != 32, _(BAD_FPU));
13139 constraint (et.type == NT_invtype, _("bad type for scalar"));
13140 constraint (x >= 64 / et.size, _("scalar index out of range"));
13141
13142 switch (et.size)
13143 {
13144 case 8: bcdebits = 0x8; break;
13145 case 16: bcdebits = 0x1; break;
13146 case 32: bcdebits = 0x0; break;
13147 default: ;
13148 }
13149
13150 bcdebits |= x << logsize;
13151
13152 inst.instruction = 0xe000b10;
13153 do_vfp_cond_or_thumb ();
13154 inst.instruction |= LOW4 (dn) << 16;
13155 inst.instruction |= HI1 (dn) << 7;
13156 inst.instruction |= inst.operands[1].reg << 12;
13157 inst.instruction |= (bcdebits & 3) << 5;
13158 inst.instruction |= (bcdebits >> 2) << 21;
13159 }
13160 break;
5f4273c7 13161
037e8744 13162 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13163 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13164 _(BAD_FPU));
b7fc2769 13165
037e8744
JB
13166 inst.instruction = 0xc400b10;
13167 do_vfp_cond_or_thumb ();
13168 inst.instruction |= LOW4 (inst.operands[0].reg);
13169 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13170 inst.instruction |= inst.operands[1].reg << 12;
13171 inst.instruction |= inst.operands[2].reg << 16;
13172 break;
5f4273c7 13173
037e8744
JB
13174 case NS_RS: /* case 6. */
13175 {
13176 struct neon_type_el et = neon_check_type (2, NS_NULL,
13177 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13178 unsigned logsize = neon_logbits (et.size);
13179 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13180 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13181 unsigned abcdebits = 0;
13182
13183 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13184 _(BAD_FPU));
13185 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13186 && et.size != 32, _(BAD_FPU));
13187 constraint (et.type == NT_invtype, _("bad type for scalar"));
13188 constraint (x >= 64 / et.size, _("scalar index out of range"));
13189
13190 switch (et.size)
13191 {
13192 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13193 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13194 case 32: abcdebits = 0x00; break;
13195 default: ;
13196 }
13197
13198 abcdebits |= x << logsize;
13199 inst.instruction = 0xe100b10;
13200 do_vfp_cond_or_thumb ();
13201 inst.instruction |= LOW4 (dn) << 16;
13202 inst.instruction |= HI1 (dn) << 7;
13203 inst.instruction |= inst.operands[0].reg << 12;
13204 inst.instruction |= (abcdebits & 3) << 5;
13205 inst.instruction |= (abcdebits >> 2) << 21;
13206 }
13207 break;
5f4273c7 13208
037e8744
JB
13209 case NS_RRD: /* case 7 (fmrrd). */
13210 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13211 _(BAD_FPU));
13212
13213 inst.instruction = 0xc500b10;
13214 do_vfp_cond_or_thumb ();
13215 inst.instruction |= inst.operands[0].reg << 12;
13216 inst.instruction |= inst.operands[1].reg << 16;
13217 inst.instruction |= LOW4 (inst.operands[2].reg);
13218 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13219 break;
5f4273c7 13220
037e8744
JB
13221 case NS_FF: /* case 8 (fcpys). */
13222 do_vfp_nsyn_opcode ("fcpys");
13223 break;
5f4273c7 13224
037e8744
JB
13225 case NS_FI: /* case 10 (fconsts). */
13226 ldconst = "fconsts";
13227 encode_fconstd:
13228 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13229 {
037e8744
JB
13230 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13231 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13232 }
13233 else
037e8744
JB
13234 first_error (_("immediate out of range"));
13235 break;
5f4273c7 13236
037e8744
JB
13237 case NS_RF: /* case 12 (fmrs). */
13238 do_vfp_nsyn_opcode ("fmrs");
13239 break;
5f4273c7 13240
037e8744
JB
13241 case NS_FR: /* case 13 (fmsr). */
13242 do_vfp_nsyn_opcode ("fmsr");
13243 break;
5f4273c7 13244
037e8744
JB
13245 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13246 (one of which is a list), but we have parsed four. Do some fiddling to
13247 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13248 expect. */
13249 case NS_RRFF: /* case 14 (fmrrs). */
13250 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13251 _("VFP registers must be adjacent"));
13252 inst.operands[2].imm = 2;
13253 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13254 do_vfp_nsyn_opcode ("fmrrs");
13255 break;
5f4273c7 13256
037e8744
JB
13257 case NS_FFRR: /* case 15 (fmsrr). */
13258 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13259 _("VFP registers must be adjacent"));
13260 inst.operands[1] = inst.operands[2];
13261 inst.operands[2] = inst.operands[3];
13262 inst.operands[0].imm = 2;
13263 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13264 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13265 break;
5f4273c7 13266
5287ad62
JB
13267 default:
13268 abort ();
13269 }
13270}
13271
13272static void
13273do_neon_rshift_round_imm (void)
13274{
037e8744 13275 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13276 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13277 int imm = inst.operands[2].imm;
13278
13279 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13280 if (imm == 0)
13281 {
13282 inst.operands[2].present = 0;
13283 do_neon_mov ();
13284 return;
13285 }
13286
13287 constraint (imm < 1 || (unsigned)imm > et.size,
13288 _("immediate out of range for shift"));
037e8744 13289 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13290 et.size - imm);
13291}
13292
13293static void
13294do_neon_movl (void)
13295{
13296 struct neon_type_el et = neon_check_type (2, NS_QD,
13297 N_EQK | N_DBL, N_SU_32 | N_KEY);
13298 unsigned sizebits = et.size >> 3;
13299 inst.instruction |= sizebits << 19;
13300 neon_two_same (0, et.type == NT_unsigned, -1);
13301}
13302
13303static void
13304do_neon_trn (void)
13305{
037e8744 13306 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13307 struct neon_type_el et = neon_check_type (2, rs,
13308 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13309 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13310 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13311}
13312
13313static void
13314do_neon_zip_uzp (void)
13315{
037e8744 13316 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13317 struct neon_type_el et = neon_check_type (2, rs,
13318 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13319 if (rs == NS_DD && et.size == 32)
13320 {
13321 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13322 inst.instruction = N_MNEM_vtrn;
13323 do_neon_trn ();
13324 return;
13325 }
037e8744 13326 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13327}
13328
13329static void
13330do_neon_sat_abs_neg (void)
13331{
037e8744 13332 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13333 struct neon_type_el et = neon_check_type (2, rs,
13334 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13335 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13336}
13337
13338static void
13339do_neon_pair_long (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, N_EQK, N_SU_32 | N_KEY);
13343 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13344 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13345 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13346}
13347
13348static void
13349do_neon_recip_est (void)
13350{
037e8744 13351 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13352 struct neon_type_el et = neon_check_type (2, rs,
13353 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13354 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13355 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13356}
13357
13358static void
13359do_neon_cls (void)
13360{
037e8744 13361 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13362 struct neon_type_el et = neon_check_type (2, rs,
13363 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13364 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13365}
13366
13367static void
13368do_neon_clz (void)
13369{
037e8744 13370 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13371 struct neon_type_el et = neon_check_type (2, rs,
13372 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13373 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13374}
13375
13376static void
13377do_neon_cnt (void)
13378{
037e8744 13379 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13380 struct neon_type_el et = neon_check_type (2, rs,
13381 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13382 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13383}
13384
13385static void
13386do_neon_swp (void)
13387{
037e8744
JB
13388 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13389 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13390}
13391
13392static void
13393do_neon_tbl_tbx (void)
13394{
13395 unsigned listlenbits;
dcbf9037 13396 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13397
5287ad62
JB
13398 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13399 {
dcbf9037 13400 first_error (_("bad list length for table lookup"));
5287ad62
JB
13401 return;
13402 }
5f4273c7 13403
5287ad62
JB
13404 listlenbits = inst.operands[1].imm - 1;
13405 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13406 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13407 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13408 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13409 inst.instruction |= LOW4 (inst.operands[2].reg);
13410 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13411 inst.instruction |= listlenbits << 8;
5f4273c7 13412
5287ad62
JB
13413 inst.instruction = neon_dp_fixup (inst.instruction);
13414}
13415
13416static void
13417do_neon_ldm_stm (void)
13418{
13419 /* P, U and L bits are part of bitmask. */
13420 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13421 unsigned offsetbits = inst.operands[1].imm * 2;
13422
037e8744
JB
13423 if (inst.operands[1].issingle)
13424 {
13425 do_vfp_nsyn_ldm_stm (is_dbmode);
13426 return;
13427 }
13428
5287ad62
JB
13429 constraint (is_dbmode && !inst.operands[0].writeback,
13430 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13431
13432 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13433 _("register list must contain at least 1 and at most 16 "
13434 "registers"));
13435
13436 inst.instruction |= inst.operands[0].reg << 16;
13437 inst.instruction |= inst.operands[0].writeback << 21;
13438 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13439 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13440
13441 inst.instruction |= offsetbits;
5f4273c7 13442
037e8744 13443 do_vfp_cond_or_thumb ();
5287ad62
JB
13444}
13445
13446static void
13447do_neon_ldr_str (void)
13448{
5287ad62 13449 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13450
037e8744
JB
13451 if (inst.operands[0].issingle)
13452 {
cd2f129f
JB
13453 if (is_ldr)
13454 do_vfp_nsyn_opcode ("flds");
13455 else
13456 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13457 }
13458 else
5287ad62 13459 {
cd2f129f
JB
13460 if (is_ldr)
13461 do_vfp_nsyn_opcode ("fldd");
5287ad62 13462 else
cd2f129f 13463 do_vfp_nsyn_opcode ("fstd");
5287ad62 13464 }
5287ad62
JB
13465}
13466
13467/* "interleave" version also handles non-interleaving register VLD1/VST1
13468 instructions. */
13469
13470static void
13471do_neon_ld_st_interleave (void)
13472{
037e8744 13473 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13474 N_8 | N_16 | N_32 | N_64);
13475 unsigned alignbits = 0;
13476 unsigned idx;
13477 /* The bits in this table go:
13478 0: register stride of one (0) or two (1)
13479 1,2: register list length, minus one (1, 2, 3, 4).
13480 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13481 We use -1 for invalid entries. */
13482 const int typetable[] =
13483 {
13484 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13485 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13486 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13487 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13488 };
13489 int typebits;
13490
dcbf9037
JB
13491 if (et.type == NT_invtype)
13492 return;
13493
5287ad62
JB
13494 if (inst.operands[1].immisalign)
13495 switch (inst.operands[1].imm >> 8)
13496 {
13497 case 64: alignbits = 1; break;
13498 case 128:
13499 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13500 goto bad_alignment;
13501 alignbits = 2;
13502 break;
13503 case 256:
13504 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13505 goto bad_alignment;
13506 alignbits = 3;
13507 break;
13508 default:
13509 bad_alignment:
dcbf9037 13510 first_error (_("bad alignment"));
5287ad62
JB
13511 return;
13512 }
13513
13514 inst.instruction |= alignbits << 4;
13515 inst.instruction |= neon_logbits (et.size) << 6;
13516
13517 /* Bits [4:6] of the immediate in a list specifier encode register stride
13518 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13519 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13520 up the right value for "type" in a table based on this value and the given
13521 list style, then stick it back. */
13522 idx = ((inst.operands[0].imm >> 4) & 7)
13523 | (((inst.instruction >> 8) & 3) << 3);
13524
13525 typebits = typetable[idx];
5f4273c7 13526
5287ad62
JB
13527 constraint (typebits == -1, _("bad list type for instruction"));
13528
13529 inst.instruction &= ~0xf00;
13530 inst.instruction |= typebits << 8;
13531}
13532
13533/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13534 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13535 otherwise. The variable arguments are a list of pairs of legal (size, align)
13536 values, terminated with -1. */
13537
13538static int
13539neon_alignment_bit (int size, int align, int *do_align, ...)
13540{
13541 va_list ap;
13542 int result = FAIL, thissize, thisalign;
5f4273c7 13543
5287ad62
JB
13544 if (!inst.operands[1].immisalign)
13545 {
13546 *do_align = 0;
13547 return SUCCESS;
13548 }
5f4273c7 13549
5287ad62
JB
13550 va_start (ap, do_align);
13551
13552 do
13553 {
13554 thissize = va_arg (ap, int);
13555 if (thissize == -1)
13556 break;
13557 thisalign = va_arg (ap, int);
13558
13559 if (size == thissize && align == thisalign)
13560 result = SUCCESS;
13561 }
13562 while (result != SUCCESS);
13563
13564 va_end (ap);
13565
13566 if (result == SUCCESS)
13567 *do_align = 1;
13568 else
dcbf9037 13569 first_error (_("unsupported alignment for instruction"));
5f4273c7 13570
5287ad62
JB
13571 return result;
13572}
13573
13574static void
13575do_neon_ld_st_lane (void)
13576{
037e8744 13577 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13578 int align_good, do_align = 0;
13579 int logsize = neon_logbits (et.size);
13580 int align = inst.operands[1].imm >> 8;
13581 int n = (inst.instruction >> 8) & 3;
13582 int max_el = 64 / et.size;
5f4273c7 13583
dcbf9037
JB
13584 if (et.type == NT_invtype)
13585 return;
5f4273c7 13586
5287ad62
JB
13587 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13588 _("bad list length"));
13589 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13590 _("scalar index out of range"));
13591 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13592 && et.size == 8,
13593 _("stride of 2 unavailable when element size is 8"));
5f4273c7 13594
5287ad62
JB
13595 switch (n)
13596 {
13597 case 0: /* VLD1 / VST1. */
13598 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13599 32, 32, -1);
13600 if (align_good == FAIL)
13601 return;
13602 if (do_align)
13603 {
13604 unsigned alignbits = 0;
13605 switch (et.size)
13606 {
13607 case 16: alignbits = 0x1; break;
13608 case 32: alignbits = 0x3; break;
13609 default: ;
13610 }
13611 inst.instruction |= alignbits << 4;
13612 }
13613 break;
13614
13615 case 1: /* VLD2 / VST2. */
13616 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13617 32, 64, -1);
13618 if (align_good == FAIL)
13619 return;
13620 if (do_align)
13621 inst.instruction |= 1 << 4;
13622 break;
13623
13624 case 2: /* VLD3 / VST3. */
13625 constraint (inst.operands[1].immisalign,
13626 _("can't use alignment with this instruction"));
13627 break;
13628
13629 case 3: /* VLD4 / VST4. */
13630 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13631 16, 64, 32, 64, 32, 128, -1);
13632 if (align_good == FAIL)
13633 return;
13634 if (do_align)
13635 {
13636 unsigned alignbits = 0;
13637 switch (et.size)
13638 {
13639 case 8: alignbits = 0x1; break;
13640 case 16: alignbits = 0x1; break;
13641 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13642 default: ;
13643 }
13644 inst.instruction |= alignbits << 4;
13645 }
13646 break;
13647
13648 default: ;
13649 }
13650
13651 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13652 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13653 inst.instruction |= 1 << (4 + logsize);
5f4273c7 13654
5287ad62
JB
13655 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13656 inst.instruction |= logsize << 10;
13657}
13658
13659/* Encode single n-element structure to all lanes VLD<n> instructions. */
13660
13661static void
13662do_neon_ld_dup (void)
13663{
037e8744 13664 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13665 int align_good, do_align = 0;
13666
dcbf9037
JB
13667 if (et.type == NT_invtype)
13668 return;
13669
5287ad62
JB
13670 switch ((inst.instruction >> 8) & 3)
13671 {
13672 case 0: /* VLD1. */
13673 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13674 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13675 &do_align, 16, 16, 32, 32, -1);
13676 if (align_good == FAIL)
13677 return;
13678 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13679 {
13680 case 1: break;
13681 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13682 default: first_error (_("bad list length")); return;
5287ad62
JB
13683 }
13684 inst.instruction |= neon_logbits (et.size) << 6;
13685 break;
13686
13687 case 1: /* VLD2. */
13688 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13689 &do_align, 8, 16, 16, 32, 32, 64, -1);
13690 if (align_good == FAIL)
13691 return;
13692 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13693 _("bad list length"));
13694 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13695 inst.instruction |= 1 << 5;
13696 inst.instruction |= neon_logbits (et.size) << 6;
13697 break;
13698
13699 case 2: /* VLD3. */
13700 constraint (inst.operands[1].immisalign,
13701 _("can't use alignment with this instruction"));
13702 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13703 _("bad list length"));
13704 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13705 inst.instruction |= 1 << 5;
13706 inst.instruction |= neon_logbits (et.size) << 6;
13707 break;
13708
13709 case 3: /* VLD4. */
13710 {
13711 int align = inst.operands[1].imm >> 8;
13712 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13713 16, 64, 32, 64, 32, 128, -1);
13714 if (align_good == FAIL)
13715 return;
13716 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13717 _("bad list length"));
13718 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13719 inst.instruction |= 1 << 5;
13720 if (et.size == 32 && align == 128)
13721 inst.instruction |= 0x3 << 6;
13722 else
13723 inst.instruction |= neon_logbits (et.size) << 6;
13724 }
13725 break;
13726
13727 default: ;
13728 }
13729
13730 inst.instruction |= do_align << 4;
13731}
13732
13733/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13734 apart from bits [11:4]. */
13735
13736static void
13737do_neon_ldx_stx (void)
13738{
13739 switch (NEON_LANE (inst.operands[0].imm))
13740 {
13741 case NEON_INTERLEAVE_LANES:
13742 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13743 do_neon_ld_st_interleave ();
13744 break;
5f4273c7 13745
5287ad62
JB
13746 case NEON_ALL_LANES:
13747 inst.instruction = NEON_ENC_DUP (inst.instruction);
13748 do_neon_ld_dup ();
13749 break;
5f4273c7 13750
5287ad62
JB
13751 default:
13752 inst.instruction = NEON_ENC_LANE (inst.instruction);
13753 do_neon_ld_st_lane ();
13754 }
13755
13756 /* L bit comes from bit mask. */
13757 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13758 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13759 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 13760
5287ad62
JB
13761 if (inst.operands[1].postind)
13762 {
13763 int postreg = inst.operands[1].imm & 0xf;
13764 constraint (!inst.operands[1].immisreg,
13765 _("post-index must be a register"));
13766 constraint (postreg == 0xd || postreg == 0xf,
13767 _("bad register for post-index"));
13768 inst.instruction |= postreg;
13769 }
13770 else if (inst.operands[1].writeback)
13771 {
13772 inst.instruction |= 0xd;
13773 }
13774 else
5f4273c7
NC
13775 inst.instruction |= 0xf;
13776
5287ad62
JB
13777 if (thumb_mode)
13778 inst.instruction |= 0xf9000000;
13779 else
13780 inst.instruction |= 0xf4000000;
13781}
5287ad62
JB
13782\f
13783/* Overall per-instruction processing. */
13784
13785/* We need to be able to fix up arbitrary expressions in some statements.
13786 This is so that we can handle symbols that are an arbitrary distance from
13787 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13788 which returns part of an address in a form which will be valid for
13789 a data instruction. We do this by pushing the expression into a symbol
13790 in the expr_section, and creating a fix for that. */
13791
13792static void
13793fix_new_arm (fragS * frag,
13794 int where,
13795 short int size,
13796 expressionS * exp,
13797 int pc_rel,
13798 int reloc)
13799{
13800 fixS * new_fix;
13801
13802 switch (exp->X_op)
13803 {
13804 case O_constant:
13805 case O_symbol:
13806 case O_add:
13807 case O_subtract:
13808 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13809 break;
13810
13811 default:
13812 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13813 pc_rel, reloc);
13814 break;
13815 }
13816
13817 /* Mark whether the fix is to a THUMB instruction, or an ARM
13818 instruction. */
13819 new_fix->tc_fix_data = thumb_mode;
13820}
13821
13822/* Create a frg for an instruction requiring relaxation. */
13823static void
13824output_relax_insn (void)
13825{
13826 char * to;
13827 symbolS *sym;
0110f2b8
PB
13828 int offset;
13829
6e1cb1a6
PB
13830 /* The size of the instruction is unknown, so tie the debug info to the
13831 start of the instruction. */
13832 dwarf2_emit_insn (0);
6e1cb1a6 13833
0110f2b8
PB
13834 switch (inst.reloc.exp.X_op)
13835 {
13836 case O_symbol:
13837 sym = inst.reloc.exp.X_add_symbol;
13838 offset = inst.reloc.exp.X_add_number;
13839 break;
13840 case O_constant:
13841 sym = NULL;
13842 offset = inst.reloc.exp.X_add_number;
13843 break;
13844 default:
13845 sym = make_expr_symbol (&inst.reloc.exp);
13846 offset = 0;
13847 break;
13848 }
13849 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13850 inst.relax, sym, offset, NULL/*offset, opcode*/);
13851 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13852}
13853
13854/* Write a 32-bit thumb instruction to buf. */
13855static void
13856put_thumb32_insn (char * buf, unsigned long insn)
13857{
13858 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13859 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13860}
13861
b99bd4ef 13862static void
c19d1205 13863output_inst (const char * str)
b99bd4ef 13864{
c19d1205 13865 char * to = NULL;
b99bd4ef 13866
c19d1205 13867 if (inst.error)
b99bd4ef 13868 {
c19d1205 13869 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13870 return;
13871 }
5f4273c7
NC
13872 if (inst.relax)
13873 {
13874 output_relax_insn ();
0110f2b8 13875 return;
5f4273c7 13876 }
c19d1205
ZW
13877 if (inst.size == 0)
13878 return;
b99bd4ef 13879
c19d1205
ZW
13880 to = frag_more (inst.size);
13881
13882 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13883 {
c19d1205 13884 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13885 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13886 }
c19d1205 13887 else if (inst.size > INSN_SIZE)
b99bd4ef 13888 {
c19d1205
ZW
13889 assert (inst.size == (2 * INSN_SIZE));
13890 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13891 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13892 }
c19d1205
ZW
13893 else
13894 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13895
c19d1205
ZW
13896 if (inst.reloc.type != BFD_RELOC_UNUSED)
13897 fix_new_arm (frag_now, to - frag_now->fr_literal,
13898 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13899 inst.reloc.type);
b99bd4ef 13900
c19d1205 13901 dwarf2_emit_insn (inst.size);
c19d1205 13902}
b99bd4ef 13903
c19d1205
ZW
13904/* Tag values used in struct asm_opcode's tag field. */
13905enum opcode_tag
13906{
13907 OT_unconditional, /* Instruction cannot be conditionalized.
13908 The ARM condition field is still 0xE. */
13909 OT_unconditionalF, /* Instruction cannot be conditionalized
13910 and carries 0xF in its ARM condition field. */
13911 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13912 OT_csuffixF, /* Some forms of the instruction take a conditional
13913 suffix, others place 0xF where the condition field
13914 would be. */
c19d1205
ZW
13915 OT_cinfix3, /* Instruction takes a conditional infix,
13916 beginning at character index 3. (In
13917 unified mode, it becomes a suffix.) */
088fa78e
KH
13918 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13919 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13920 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13921 character index 3, even in unified mode. Used for
13922 legacy instructions where suffix and infix forms
13923 may be ambiguous. */
c19d1205 13924 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13925 suffix or an infix at character index 3. */
c19d1205
ZW
13926 OT_odd_infix_unc, /* This is the unconditional variant of an
13927 instruction that takes a conditional infix
13928 at an unusual position. In unified mode,
13929 this variant will accept a suffix. */
13930 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13931 are the conditional variants of instructions that
13932 take conditional infixes in unusual positions.
13933 The infix appears at character index
13934 (tag - OT_odd_infix_0). These are not accepted
13935 in unified mode. */
13936};
b99bd4ef 13937
c19d1205
ZW
13938/* Subroutine of md_assemble, responsible for looking up the primary
13939 opcode from the mnemonic the user wrote. STR points to the
13940 beginning of the mnemonic.
13941
13942 This is not simply a hash table lookup, because of conditional
13943 variants. Most instructions have conditional variants, which are
13944 expressed with a _conditional affix_ to the mnemonic. If we were
13945 to encode each conditional variant as a literal string in the opcode
13946 table, it would have approximately 20,000 entries.
13947
13948 Most mnemonics take this affix as a suffix, and in unified syntax,
13949 'most' is upgraded to 'all'. However, in the divided syntax, some
13950 instructions take the affix as an infix, notably the s-variants of
13951 the arithmetic instructions. Of those instructions, all but six
13952 have the infix appear after the third character of the mnemonic.
13953
13954 Accordingly, the algorithm for looking up primary opcodes given
13955 an identifier is:
13956
13957 1. Look up the identifier in the opcode table.
13958 If we find a match, go to step U.
13959
13960 2. Look up the last two characters of the identifier in the
13961 conditions table. If we find a match, look up the first N-2
13962 characters of the identifier in the opcode table. If we
13963 find a match, go to step CE.
13964
13965 3. Look up the fourth and fifth characters of the identifier in
13966 the conditions table. If we find a match, extract those
13967 characters from the identifier, and look up the remaining
13968 characters in the opcode table. If we find a match, go
13969 to step CM.
13970
13971 4. Fail.
13972
13973 U. Examine the tag field of the opcode structure, in case this is
13974 one of the six instructions with its conditional infix in an
13975 unusual place. If it is, the tag tells us where to find the
13976 infix; look it up in the conditions table and set inst.cond
13977 accordingly. Otherwise, this is an unconditional instruction.
13978 Again set inst.cond accordingly. Return the opcode structure.
13979
13980 CE. Examine the tag field to make sure this is an instruction that
13981 should receive a conditional suffix. If it is not, fail.
13982 Otherwise, set inst.cond from the suffix we already looked up,
13983 and return the opcode structure.
13984
13985 CM. Examine the tag field to make sure this is an instruction that
13986 should receive a conditional infix after the third character.
13987 If it is not, fail. Otherwise, undo the edits to the current
13988 line of input and proceed as for case CE. */
13989
13990static const struct asm_opcode *
13991opcode_lookup (char **str)
13992{
13993 char *end, *base;
13994 char *affix;
13995 const struct asm_opcode *opcode;
13996 const struct asm_cond *cond;
e3cb604e 13997 char save[2];
267d2029 13998 bfd_boolean neon_supported;
5f4273c7 13999
267d2029 14000 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14001
14002 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14003 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14004 for (base = end = *str; *end != '\0'; end++)
267d2029 14005 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14006 break;
b99bd4ef 14007
c19d1205
ZW
14008 if (end == base)
14009 return 0;
b99bd4ef 14010
5287ad62 14011 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14012 if (end[0] == '.')
b99bd4ef 14013 {
5287ad62 14014 int offset = 2;
5f4273c7 14015
267d2029
JB
14016 /* The .w and .n suffixes are only valid if the unified syntax is in
14017 use. */
14018 if (unified_syntax && end[1] == 'w')
c19d1205 14019 inst.size_req = 4;
267d2029 14020 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14021 inst.size_req = 2;
14022 else
5287ad62
JB
14023 offset = 0;
14024
14025 inst.vectype.elems = 0;
14026
14027 *str = end + offset;
b99bd4ef 14028
5f4273c7 14029 if (end[offset] == '.')
5287ad62 14030 {
267d2029
JB
14031 /* See if we have a Neon type suffix (possible in either unified or
14032 non-unified ARM syntax mode). */
dcbf9037 14033 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14034 return 0;
14035 }
14036 else if (end[offset] != '\0' && end[offset] != ' ')
14037 return 0;
b99bd4ef 14038 }
c19d1205
ZW
14039 else
14040 *str = end;
b99bd4ef 14041
c19d1205
ZW
14042 /* Look for unaffixed or special-case affixed mnemonic. */
14043 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14044 if (opcode)
b99bd4ef 14045 {
c19d1205
ZW
14046 /* step U */
14047 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14048 {
c19d1205
ZW
14049 inst.cond = COND_ALWAYS;
14050 return opcode;
b99bd4ef 14051 }
b99bd4ef 14052
c19d1205
ZW
14053 if (unified_syntax)
14054 as_warn (_("conditional infixes are deprecated in unified syntax"));
14055 affix = base + (opcode->tag - OT_odd_infix_0);
14056 cond = hash_find_n (arm_cond_hsh, affix, 2);
14057 assert (cond);
b99bd4ef 14058
c19d1205
ZW
14059 inst.cond = cond->value;
14060 return opcode;
14061 }
b99bd4ef 14062
c19d1205
ZW
14063 /* Cannot have a conditional suffix on a mnemonic of less than two
14064 characters. */
14065 if (end - base < 3)
14066 return 0;
b99bd4ef 14067
c19d1205
ZW
14068 /* Look for suffixed mnemonic. */
14069 affix = end - 2;
14070 cond = hash_find_n (arm_cond_hsh, affix, 2);
14071 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14072 if (opcode && cond)
14073 {
14074 /* step CE */
14075 switch (opcode->tag)
14076 {
e3cb604e
PB
14077 case OT_cinfix3_legacy:
14078 /* Ignore conditional suffixes matched on infix only mnemonics. */
14079 break;
14080
c19d1205 14081 case OT_cinfix3:
088fa78e 14082 case OT_cinfix3_deprecated:
c19d1205
ZW
14083 case OT_odd_infix_unc:
14084 if (!unified_syntax)
e3cb604e 14085 return 0;
c19d1205
ZW
14086 /* else fall through */
14087
14088 case OT_csuffix:
037e8744 14089 case OT_csuffixF:
c19d1205
ZW
14090 case OT_csuf_or_in3:
14091 inst.cond = cond->value;
14092 return opcode;
14093
14094 case OT_unconditional:
14095 case OT_unconditionalF:
dfa9f0d5
PB
14096 if (thumb_mode)
14097 {
14098 inst.cond = cond->value;
14099 }
14100 else
14101 {
14102 /* delayed diagnostic */
14103 inst.error = BAD_COND;
14104 inst.cond = COND_ALWAYS;
14105 }
c19d1205 14106 return opcode;
b99bd4ef 14107
c19d1205
ZW
14108 default:
14109 return 0;
14110 }
14111 }
b99bd4ef 14112
c19d1205
ZW
14113 /* Cannot have a usual-position infix on a mnemonic of less than
14114 six characters (five would be a suffix). */
14115 if (end - base < 6)
14116 return 0;
b99bd4ef 14117
c19d1205
ZW
14118 /* Look for infixed mnemonic in the usual position. */
14119 affix = base + 3;
14120 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14121 if (!cond)
14122 return 0;
14123
14124 memcpy (save, affix, 2);
14125 memmove (affix, affix + 2, (end - affix) - 2);
14126 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14127 memmove (affix + 2, affix, (end - affix) - 2);
14128 memcpy (affix, save, 2);
14129
088fa78e
KH
14130 if (opcode
14131 && (opcode->tag == OT_cinfix3
14132 || opcode->tag == OT_cinfix3_deprecated
14133 || opcode->tag == OT_csuf_or_in3
14134 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14135 {
c19d1205 14136 /* step CM */
088fa78e
KH
14137 if (unified_syntax
14138 && (opcode->tag == OT_cinfix3
14139 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14140 as_warn (_("conditional infixes are deprecated in unified syntax"));
14141
14142 inst.cond = cond->value;
14143 return opcode;
b99bd4ef
NC
14144 }
14145
c19d1205 14146 return 0;
b99bd4ef
NC
14147}
14148
c19d1205
ZW
14149void
14150md_assemble (char *str)
b99bd4ef 14151{
c19d1205
ZW
14152 char *p = str;
14153 const struct asm_opcode * opcode;
b99bd4ef 14154
c19d1205
ZW
14155 /* Align the previous label if needed. */
14156 if (last_label_seen != NULL)
b99bd4ef 14157 {
c19d1205
ZW
14158 symbol_set_frag (last_label_seen, frag_now);
14159 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14160 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14161 }
14162
c19d1205
ZW
14163 memset (&inst, '\0', sizeof (inst));
14164 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14165
c19d1205
ZW
14166 opcode = opcode_lookup (&p);
14167 if (!opcode)
b99bd4ef 14168 {
c19d1205 14169 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14170 the form alias .req reg, or a Neon .dn/.qn directive. */
14171 if (!create_register_alias (str, p)
14172 && !create_neon_reg_alias (str, p))
c19d1205 14173 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14174
b99bd4ef
NC
14175 return;
14176 }
14177
088fa78e
KH
14178 if (opcode->tag == OT_cinfix3_deprecated)
14179 as_warn (_("s suffix on comparison instruction is deprecated"));
14180
037e8744
JB
14181 /* The value which unconditional instructions should have in place of the
14182 condition field. */
14183 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14184
c19d1205 14185 if (thumb_mode)
b99bd4ef 14186 {
e74cfd16 14187 arm_feature_set variant;
8f06b2d8
PB
14188
14189 variant = cpu_variant;
14190 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14191 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14192 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14193 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14194 if (!opcode->tvariant
14195 || (thumb_mode == 1
14196 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14197 {
c19d1205 14198 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14199 return;
14200 }
c19d1205
ZW
14201 if (inst.cond != COND_ALWAYS && !unified_syntax
14202 && opcode->tencode != do_t_branch)
b99bd4ef 14203 {
c19d1205 14204 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14205 return;
14206 }
14207
076d447c
PB
14208 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14209 {
14210 /* Implicit require narrow instructions on Thumb-1. This avoids
14211 relaxation accidentally introducing Thumb-2 instructions. */
14212 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23)
14213 inst.size_req = 2;
14214 }
14215
e27ec89e
PB
14216 /* Check conditional suffixes. */
14217 if (current_it_mask)
14218 {
14219 int cond;
14220 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14221 current_it_mask <<= 1;
14222 current_it_mask &= 0x1f;
14223 /* The BKPT instruction is unconditional even in an IT block. */
14224 if (!inst.error
14225 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14226 {
14227 as_bad (_("incorrect condition in IT block"));
14228 return;
14229 }
e27ec89e
PB
14230 }
14231 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14232 {
6decc662 14233 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14234 return;
14235 }
14236
c19d1205
ZW
14237 mapping_state (MAP_THUMB);
14238 inst.instruction = opcode->tvalue;
14239
14240 if (!parse_operands (p, opcode->operands))
14241 opcode->tencode ();
14242
e27ec89e
PB
14243 /* Clear current_it_mask at the end of an IT block. */
14244 if (current_it_mask == 0x10)
14245 current_it_mask = 0;
14246
0110f2b8 14247 if (!(inst.error || inst.relax))
b99bd4ef 14248 {
c19d1205
ZW
14249 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14250 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14251 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14252 {
c19d1205 14253 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14254 return;
14255 }
14256 }
076d447c
PB
14257
14258 /* Something has gone badly wrong if we try to relax a fixed size
14259 instruction. */
14260 assert (inst.size_req == 0 || !inst.relax);
14261
e74cfd16
PB
14262 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14263 *opcode->tvariant);
ee065d83 14264 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14265 set those bits when Thumb-2 32-bit instructions are seen. ie.
ee065d83
PB
14266 anything other than bl/blx.
14267 This is overly pessimistic for relaxable instructions. */
14268 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14269 || inst.relax)
e74cfd16
PB
14270 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14271 arm_ext_v6t2);
c19d1205 14272 }
3e9e4fcf 14273 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
14274 {
14275 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14276 if (!opcode->avariant ||
14277 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 14278 {
c19d1205
ZW
14279 as_bad (_("selected processor does not support `%s'"), str);
14280 return;
b99bd4ef 14281 }
c19d1205 14282 if (inst.size_req)
b99bd4ef 14283 {
c19d1205
ZW
14284 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14285 return;
b99bd4ef
NC
14286 }
14287
c19d1205
ZW
14288 mapping_state (MAP_ARM);
14289 inst.instruction = opcode->avalue;
14290 if (opcode->tag == OT_unconditionalF)
14291 inst.instruction |= 0xF << 28;
14292 else
14293 inst.instruction |= inst.cond << 28;
14294 inst.size = INSN_SIZE;
14295 if (!parse_operands (p, opcode->operands))
14296 opcode->aencode ();
ee065d83
PB
14297 /* Arm mode bx is marked as both v4T and v5 because it's still required
14298 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
14299 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
14300 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
14301 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14302 else
e74cfd16
PB
14303 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14304 *opcode->avariant);
b99bd4ef 14305 }
3e9e4fcf
JB
14306 else
14307 {
14308 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14309 "-- `%s'"), str);
14310 return;
14311 }
c19d1205
ZW
14312 output_inst (str);
14313}
b99bd4ef 14314
c19d1205
ZW
14315/* Various frobbings of labels and their addresses. */
14316
14317void
14318arm_start_line_hook (void)
14319{
14320 last_label_seen = NULL;
b99bd4ef
NC
14321}
14322
c19d1205
ZW
14323void
14324arm_frob_label (symbolS * sym)
b99bd4ef 14325{
c19d1205 14326 last_label_seen = sym;
b99bd4ef 14327
c19d1205 14328 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14329
c19d1205
ZW
14330#if defined OBJ_COFF || defined OBJ_ELF
14331 ARM_SET_INTERWORK (sym, support_interwork);
14332#endif
b99bd4ef 14333
5f4273c7 14334 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14335 as Thumb functions. This is because these labels, whilst
14336 they exist inside Thumb code, are not the entry points for
14337 possible ARM->Thumb calls. Also, these labels can be used
14338 as part of a computed goto or switch statement. eg gcc
14339 can generate code that looks like this:
b99bd4ef 14340
c19d1205
ZW
14341 ldr r2, [pc, .Laaa]
14342 lsl r3, r3, #2
14343 ldr r2, [r3, r2]
14344 mov pc, r2
b99bd4ef 14345
c19d1205
ZW
14346 .Lbbb: .word .Lxxx
14347 .Lccc: .word .Lyyy
14348 ..etc...
14349 .Laaa: .word Lbbb
b99bd4ef 14350
c19d1205
ZW
14351 The first instruction loads the address of the jump table.
14352 The second instruction converts a table index into a byte offset.
14353 The third instruction gets the jump address out of the table.
14354 The fourth instruction performs the jump.
b99bd4ef 14355
c19d1205
ZW
14356 If the address stored at .Laaa is that of a symbol which has the
14357 Thumb_Func bit set, then the linker will arrange for this address
14358 to have the bottom bit set, which in turn would mean that the
14359 address computation performed by the third instruction would end
14360 up with the bottom bit set. Since the ARM is capable of unaligned
14361 word loads, the instruction would then load the incorrect address
14362 out of the jump table, and chaos would ensue. */
14363 if (label_is_thumb_function_name
14364 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14365 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14366 {
c19d1205
ZW
14367 /* When the address of a Thumb function is taken the bottom
14368 bit of that address should be set. This will allow
14369 interworking between Arm and Thumb functions to work
14370 correctly. */
b99bd4ef 14371
c19d1205 14372 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14373
c19d1205 14374 label_is_thumb_function_name = FALSE;
b99bd4ef 14375 }
07a53e5c 14376
07a53e5c 14377 dwarf2_emit_label (sym);
b99bd4ef
NC
14378}
14379
c19d1205
ZW
14380int
14381arm_data_in_code (void)
b99bd4ef 14382{
c19d1205 14383 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14384 {
c19d1205
ZW
14385 *input_line_pointer = '/';
14386 input_line_pointer += 5;
14387 *input_line_pointer = 0;
14388 return 1;
b99bd4ef
NC
14389 }
14390
c19d1205 14391 return 0;
b99bd4ef
NC
14392}
14393
c19d1205
ZW
14394char *
14395arm_canonicalize_symbol_name (char * name)
b99bd4ef 14396{
c19d1205 14397 int len;
b99bd4ef 14398
c19d1205
ZW
14399 if (thumb_mode && (len = strlen (name)) > 5
14400 && streq (name + len - 5, "/data"))
14401 *(name + len - 5) = 0;
b99bd4ef 14402
c19d1205 14403 return name;
b99bd4ef 14404}
c19d1205
ZW
14405\f
14406/* Table of all register names defined by default. The user can
14407 define additional names with .req. Note that all register names
14408 should appear in both upper and lowercase variants. Some registers
14409 also have mixed-case names. */
b99bd4ef 14410
dcbf9037 14411#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14412#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14413#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14414#define REGSET(p,t) \
14415 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14416 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14417 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14418 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14419#define REGSETH(p,t) \
14420 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14421 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14422 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14423 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14424#define REGSET2(p,t) \
14425 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14426 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14427 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14428 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14429
c19d1205 14430static const struct reg_entry reg_names[] =
7ed4c4c5 14431{
c19d1205
ZW
14432 /* ARM integer registers. */
14433 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14434
c19d1205
ZW
14435 /* ATPCS synonyms. */
14436 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14437 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14438 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14439
c19d1205
ZW
14440 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14441 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14442 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14443
c19d1205
ZW
14444 /* Well-known aliases. */
14445 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14446 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14447
14448 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14449 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14450
14451 /* Coprocessor numbers. */
14452 REGSET(p, CP), REGSET(P, CP),
14453
14454 /* Coprocessor register numbers. The "cr" variants are for backward
14455 compatibility. */
14456 REGSET(c, CN), REGSET(C, CN),
14457 REGSET(cr, CN), REGSET(CR, CN),
14458
14459 /* FPA registers. */
14460 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14461 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14462
14463 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14464 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14465
14466 /* VFP SP registers. */
5287ad62
JB
14467 REGSET(s,VFS), REGSET(S,VFS),
14468 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14469
14470 /* VFP DP Registers. */
5287ad62
JB
14471 REGSET(d,VFD), REGSET(D,VFD),
14472 /* Extra Neon DP registers. */
14473 REGSETH(d,VFD), REGSETH(D,VFD),
14474
14475 /* Neon QP registers. */
14476 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14477
14478 /* VFP control registers. */
14479 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14480 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14481 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14482 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14483 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14484 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14485
14486 /* Maverick DSP coprocessor registers. */
14487 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14488 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14489
14490 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14491 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14492 REGDEF(dspsc,0,DSPSC),
14493
14494 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14495 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14496 REGDEF(DSPSC,0,DSPSC),
14497
14498 /* iWMMXt data registers - p0, c0-15. */
14499 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14500
14501 /* iWMMXt control registers - p1, c0-3. */
14502 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14503 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14504 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14505 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14506
14507 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14508 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14509 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14510 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14511 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14512
14513 /* XScale accumulator registers. */
14514 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14515};
14516#undef REGDEF
14517#undef REGNUM
14518#undef REGSET
7ed4c4c5 14519
c19d1205
ZW
14520/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14521 within psr_required_here. */
14522static const struct asm_psr psrs[] =
14523{
14524 /* Backward compatibility notation. Note that "all" is no longer
14525 truly all possible PSR bits. */
14526 {"all", PSR_c | PSR_f},
14527 {"flg", PSR_f},
14528 {"ctl", PSR_c},
14529
14530 /* Individual flags. */
14531 {"f", PSR_f},
14532 {"c", PSR_c},
14533 {"x", PSR_x},
14534 {"s", PSR_s},
14535 /* Combinations of flags. */
14536 {"fs", PSR_f | PSR_s},
14537 {"fx", PSR_f | PSR_x},
14538 {"fc", PSR_f | PSR_c},
14539 {"sf", PSR_s | PSR_f},
14540 {"sx", PSR_s | PSR_x},
14541 {"sc", PSR_s | PSR_c},
14542 {"xf", PSR_x | PSR_f},
14543 {"xs", PSR_x | PSR_s},
14544 {"xc", PSR_x | PSR_c},
14545 {"cf", PSR_c | PSR_f},
14546 {"cs", PSR_c | PSR_s},
14547 {"cx", PSR_c | PSR_x},
14548 {"fsx", PSR_f | PSR_s | PSR_x},
14549 {"fsc", PSR_f | PSR_s | PSR_c},
14550 {"fxs", PSR_f | PSR_x | PSR_s},
14551 {"fxc", PSR_f | PSR_x | PSR_c},
14552 {"fcs", PSR_f | PSR_c | PSR_s},
14553 {"fcx", PSR_f | PSR_c | PSR_x},
14554 {"sfx", PSR_s | PSR_f | PSR_x},
14555 {"sfc", PSR_s | PSR_f | PSR_c},
14556 {"sxf", PSR_s | PSR_x | PSR_f},
14557 {"sxc", PSR_s | PSR_x | PSR_c},
14558 {"scf", PSR_s | PSR_c | PSR_f},
14559 {"scx", PSR_s | PSR_c | PSR_x},
14560 {"xfs", PSR_x | PSR_f | PSR_s},
14561 {"xfc", PSR_x | PSR_f | PSR_c},
14562 {"xsf", PSR_x | PSR_s | PSR_f},
14563 {"xsc", PSR_x | PSR_s | PSR_c},
14564 {"xcf", PSR_x | PSR_c | PSR_f},
14565 {"xcs", PSR_x | PSR_c | PSR_s},
14566 {"cfs", PSR_c | PSR_f | PSR_s},
14567 {"cfx", PSR_c | PSR_f | PSR_x},
14568 {"csf", PSR_c | PSR_s | PSR_f},
14569 {"csx", PSR_c | PSR_s | PSR_x},
14570 {"cxf", PSR_c | PSR_x | PSR_f},
14571 {"cxs", PSR_c | PSR_x | PSR_s},
14572 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14573 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14574 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14575 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14576 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14577 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14578 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14579 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14580 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14581 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14582 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14583 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14584 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14585 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14586 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14587 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14588 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14589 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14590 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14591 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14592 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14593 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14594 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14595 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14596};
14597
62b3e311
PB
14598/* Table of V7M psr names. */
14599static const struct asm_psr v7m_psrs[] =
14600{
2b744c99
PB
14601 {"apsr", 0 }, {"APSR", 0 },
14602 {"iapsr", 1 }, {"IAPSR", 1 },
14603 {"eapsr", 2 }, {"EAPSR", 2 },
14604 {"psr", 3 }, {"PSR", 3 },
14605 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14606 {"ipsr", 5 }, {"IPSR", 5 },
14607 {"epsr", 6 }, {"EPSR", 6 },
14608 {"iepsr", 7 }, {"IEPSR", 7 },
14609 {"msp", 8 }, {"MSP", 8 },
14610 {"psp", 9 }, {"PSP", 9 },
14611 {"primask", 16}, {"PRIMASK", 16},
14612 {"basepri", 17}, {"BASEPRI", 17},
14613 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14614 {"faultmask", 19}, {"FAULTMASK", 19},
14615 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14616};
14617
c19d1205
ZW
14618/* Table of all shift-in-operand names. */
14619static const struct asm_shift_name shift_names [] =
b99bd4ef 14620{
c19d1205
ZW
14621 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14622 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14623 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14624 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14625 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14626 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14627};
b99bd4ef 14628
c19d1205
ZW
14629/* Table of all explicit relocation names. */
14630#ifdef OBJ_ELF
14631static struct reloc_entry reloc_names[] =
14632{
14633 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14634 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14635 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14636 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14637 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14638 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14639 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14640 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14641 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14642 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14643 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14644};
14645#endif
b99bd4ef 14646
c19d1205
ZW
14647/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14648static const struct asm_cond conds[] =
14649{
14650 {"eq", 0x0},
14651 {"ne", 0x1},
14652 {"cs", 0x2}, {"hs", 0x2},
14653 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14654 {"mi", 0x4},
14655 {"pl", 0x5},
14656 {"vs", 0x6},
14657 {"vc", 0x7},
14658 {"hi", 0x8},
14659 {"ls", 0x9},
14660 {"ge", 0xa},
14661 {"lt", 0xb},
14662 {"gt", 0xc},
14663 {"le", 0xd},
14664 {"al", 0xe}
14665};
bfae80f2 14666
62b3e311
PB
14667static struct asm_barrier_opt barrier_opt_names[] =
14668{
14669 { "sy", 0xf },
14670 { "un", 0x7 },
14671 { "st", 0xe },
14672 { "unst", 0x6 }
14673};
14674
c19d1205
ZW
14675/* Table of ARM-format instructions. */
14676
14677/* Macros for gluing together operand strings. N.B. In all cases
14678 other than OPS0, the trailing OP_stop comes from default
14679 zero-initialization of the unspecified elements of the array. */
14680#define OPS0() { OP_stop, }
14681#define OPS1(a) { OP_##a, }
14682#define OPS2(a,b) { OP_##a,OP_##b, }
14683#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14684#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14685#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14686#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14687
14688/* These macros abstract out the exact format of the mnemonic table and
14689 save some repeated characters. */
14690
14691/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14692#define TxCE(mnem, op, top, nops, ops, ae, te) \
14693 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14694 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14695
14696/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14697 a T_MNEM_xyz enumerator. */
14698#define TCE(mnem, aop, top, nops, ops, ae, te) \
14699 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14700#define tCE(mnem, aop, top, nops, ops, ae, te) \
14701 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14702
14703/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14704 infix after the third character. */
14705#define TxC3(mnem, op, top, nops, ops, ae, te) \
14706 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14707 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14708#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14709 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14710 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14711#define TC3(mnem, aop, top, nops, ops, ae, te) \
14712 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14713#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14714 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14715#define tC3(mnem, aop, top, nops, ops, ae, te) \
14716 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14717#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14718 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14719
14720/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14721 appear in the condition table. */
14722#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14723 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14724 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14725
14726#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14727 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14728 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14729 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14730 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14731 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14732 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14733 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14734 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14735 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14736 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14737 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14738 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14739 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14740 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14741 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14742 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14743 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14744 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14745 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14746
14747#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14748 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14749#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14750 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14751
14752/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14753 field is still 0xE. Many of the Thumb variants can be executed
14754 conditionally, so this is checked separately. */
c19d1205
ZW
14755#define TUE(mnem, op, top, nops, ops, ae, te) \
14756 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14757 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14758
14759/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14760 condition code field. */
14761#define TUF(mnem, op, top, nops, ops, ae, te) \
14762 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14763 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14764
14765/* ARM-only variants of all the above. */
6a86118a
NC
14766#define CE(mnem, op, nops, ops, ae) \
14767 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14768
14769#define C3(mnem, op, nops, ops, ae) \
14770 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14771
e3cb604e
PB
14772/* Legacy mnemonics that always have conditional infix after the third
14773 character. */
14774#define CL(mnem, op, nops, ops, ae) \
14775 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14776 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14777
8f06b2d8
PB
14778/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14779#define cCE(mnem, op, nops, ops, ae) \
14780 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14781
e3cb604e
PB
14782/* Legacy coprocessor instructions where conditional infix and conditional
14783 suffix are ambiguous. For consistency this includes all FPA instructions,
14784 not just the potentially ambiguous ones. */
14785#define cCL(mnem, op, nops, ops, ae) \
14786 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14787 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14788
14789/* Coprocessor, takes either a suffix or a position-3 infix
14790 (for an FPA corner case). */
14791#define C3E(mnem, op, nops, ops, ae) \
14792 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14793 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14794
6a86118a
NC
14795#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14796 { #m1 #m2 #m3, OPS##nops ops, \
14797 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14798 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14799
14800#define CM(m1, m2, op, nops, ops, ae) \
14801 xCM_(m1, , m2, op, nops, ops, ae), \
14802 xCM_(m1, eq, m2, op, nops, ops, ae), \
14803 xCM_(m1, ne, m2, op, nops, ops, ae), \
14804 xCM_(m1, cs, m2, op, nops, ops, ae), \
14805 xCM_(m1, hs, m2, op, nops, ops, ae), \
14806 xCM_(m1, cc, m2, op, nops, ops, ae), \
14807 xCM_(m1, ul, m2, op, nops, ops, ae), \
14808 xCM_(m1, lo, m2, op, nops, ops, ae), \
14809 xCM_(m1, mi, m2, op, nops, ops, ae), \
14810 xCM_(m1, pl, m2, op, nops, ops, ae), \
14811 xCM_(m1, vs, m2, op, nops, ops, ae), \
14812 xCM_(m1, vc, m2, op, nops, ops, ae), \
14813 xCM_(m1, hi, m2, op, nops, ops, ae), \
14814 xCM_(m1, ls, m2, op, nops, ops, ae), \
14815 xCM_(m1, ge, m2, op, nops, ops, ae), \
14816 xCM_(m1, lt, m2, op, nops, ops, ae), \
14817 xCM_(m1, gt, m2, op, nops, ops, ae), \
14818 xCM_(m1, le, m2, op, nops, ops, ae), \
14819 xCM_(m1, al, m2, op, nops, ops, ae)
14820
14821#define UE(mnem, op, nops, ops, ae) \
14822 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14823
14824#define UF(mnem, op, nops, ops, ae) \
14825 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14826
5287ad62
JB
14827/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14828 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14829 use the same encoding function for each. */
14830#define NUF(mnem, op, nops, ops, enc) \
14831 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14832 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14833
14834/* Neon data processing, version which indirects through neon_enc_tab for
14835 the various overloaded versions of opcodes. */
14836#define nUF(mnem, op, nops, ops, enc) \
14837 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14838 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14839
14840/* Neon insn with conditional suffix for the ARM version, non-overloaded
14841 version. */
037e8744
JB
14842#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14843 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14844 THUMB_VARIANT, do_##enc, do_##enc }
14845
037e8744
JB
14846#define NCE(mnem, op, nops, ops, enc) \
14847 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14848
14849#define NCEF(mnem, op, nops, ops, enc) \
14850 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14851
5287ad62 14852/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14853#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14854 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14855 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14856
037e8744
JB
14857#define nCE(mnem, op, nops, ops, enc) \
14858 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14859
14860#define nCEF(mnem, op, nops, ops, enc) \
14861 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14862
c19d1205
ZW
14863#define do_0 0
14864
14865/* Thumb-only, unconditional. */
14866#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14867
c19d1205 14868static const struct asm_opcode insns[] =
bfae80f2 14869{
e74cfd16
PB
14870#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14871#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14872 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14873 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14874 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14875 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14876 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14877 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14878 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14879 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14880 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14881 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14882 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14883 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14884 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14885 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14886 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14887 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14888
14889 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14890 for setting PSR flag bits. They are obsolete in V6 and do not
14891 have Thumb equivalents. */
14892 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14893 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14894 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14895 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14896 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14897 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14898 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14899 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14900 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14901
14902 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14903 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14904 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14905 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14906
4962c51a
MS
14907 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14908 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14909 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14910 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14911
f5208ef2 14912 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14913 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14914 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14915 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14916 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14917 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14918
14919 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14920 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14921 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14922 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14923
c19d1205 14924 /* Pseudo ops. */
e9f89963 14925 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14926 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14927 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14928
14929 /* Thumb-compatibility pseudo ops. */
14930 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14931 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14932 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14933 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14934 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14935 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14936 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14937 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14938 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14939 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14940 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14941 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14942
16a4cf17
PB
14943 /* These may simplify to neg. */
14944 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14945 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14946
c19d1205 14947#undef THUMB_VARIANT
e74cfd16 14948#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14949 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14950
14951 /* V1 instructions with no Thumb analogue prior to V6T2. */
14952#undef THUMB_VARIANT
e74cfd16 14953#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14954 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14955 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14956 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14957
14958 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14959 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14960 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14961 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14962
9c3c69f2
PB
14963 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14964 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14965
9c3c69f2
PB
14966 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14967 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14968
14969 /* V1 instructions with no Thumb analogue at all. */
14970 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14971 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14972
14973 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14974 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14975 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14976 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14977 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14978 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14979 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14980 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14981
14982#undef ARM_VARIANT
e74cfd16 14983#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 14984#undef THUMB_VARIANT
e74cfd16 14985#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14986 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14987 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14988
14989#undef THUMB_VARIANT
e74cfd16 14990#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14991 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14992 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14993
14994 /* Generic coprocessor instructions. */
14995 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
14996 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14997 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14998 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14999 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15000 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15001 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15002
15003#undef ARM_VARIANT
e74cfd16 15004#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15005 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15006 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15007
15008#undef ARM_VARIANT
e74cfd16 15009#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
037e8744
JB
15010 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15011 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15012
15013#undef ARM_VARIANT
e74cfd16 15014#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
15015 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15016 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15017 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15018 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15019 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15020 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15021 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15022 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15023
15024#undef ARM_VARIANT
e74cfd16 15025#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15026#undef THUMB_VARIANT
e74cfd16 15027#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15028 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15029 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15030 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15031 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15032 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15033 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15034
15035#undef ARM_VARIANT
e74cfd16 15036#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15037 /* ARM Architecture 4T. */
15038 /* Note: bx (and blx) are required on V5, even if the processor does
15039 not support Thumb. */
15040 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15041
15042#undef ARM_VARIANT
e74cfd16 15043#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15044#undef THUMB_VARIANT
e74cfd16 15045#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15046 /* Note: blx has 2 variants; the .value coded here is for
15047 BLX(2). Only this variant has conditional execution. */
15048 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15049 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15050
15051#undef THUMB_VARIANT
e74cfd16 15052#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15053 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15054 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15055 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15056 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15057 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15058 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15059 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15060 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15061
15062#undef ARM_VARIANT
e74cfd16 15063#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15064 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15065 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15066 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15067 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15068
15069 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15070 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15071
15072 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15073 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15074 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15075 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15076
15077 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15078 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15079 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15080 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15081
15082 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15083 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15084
15085 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15086 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15087 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15088 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15089
15090#undef ARM_VARIANT
e74cfd16 15091#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15092 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15093 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15094 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15095
15096 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15097 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15098
15099#undef ARM_VARIANT
e74cfd16 15100#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15101 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15102
15103#undef ARM_VARIANT
e74cfd16 15104#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15105#undef THUMB_VARIANT
e74cfd16 15106#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15107 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15108 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15109 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15110 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15111 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15112 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15113 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15114 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15115 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15116 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15117
15118#undef THUMB_VARIANT
e74cfd16 15119#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15120 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15121 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15122 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15123 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15124
15125 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15126 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15127
15128/* ARM V6 not included in V7M (eg. integer SIMD). */
15129#undef THUMB_VARIANT
15130#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15131 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15132 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15133 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15134 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15135 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15136 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15137 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15138 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15139 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15140 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15141 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15142 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15143 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15144 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15145 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15146 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15147 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15148 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15149 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15150 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15151 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15152 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15153 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15154 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15155 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15156 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15157 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15158 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15159 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15160 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15161 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15162 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15163 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15164 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15165 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15166 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15171 UF(rfeib, 9900a00, 1, (RRw), rfe),
15172 UF(rfeda, 8100a00, 1, (RRw), rfe),
15173 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15174 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15175 UF(rfefa, 9900a00, 1, (RRw), rfe),
15176 UF(rfeea, 8100a00, 1, (RRw), rfe),
15177 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15178 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15179 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15180 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15181 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15182 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15183 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15184 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15185 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15186 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15187 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15188 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15189 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15190 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15191 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15192 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15193 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15194 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15195 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15196 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15197 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15198 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15199 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15200 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15201 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15202 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15203 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15204 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15205 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15206 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15207 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15208 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15209 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15210 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15211 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15212 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15213 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15214
15215#undef ARM_VARIANT
e74cfd16 15216#define ARM_VARIANT &arm_ext_v6k
c19d1205 15217#undef THUMB_VARIANT
e74cfd16 15218#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15219 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15220 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15221 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15222 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15223
ebdca51a
PB
15224#undef THUMB_VARIANT
15225#define THUMB_VARIANT &arm_ext_v6_notm
15226 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15227 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15228
c19d1205 15229#undef THUMB_VARIANT
e74cfd16 15230#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15231 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15232 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15233 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15234 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15235 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15236
15237#undef ARM_VARIANT
e74cfd16 15238#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15239 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15240
15241#undef ARM_VARIANT
e74cfd16 15242#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15243 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15244 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15245 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15246 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15247
15248 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15249 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15250 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15251 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15252
15253 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15254 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15255 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15256 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15257
25fe350b
MS
15258 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15259 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15260 /* ARM does not really have an IT instruction, so always allow it. */
15261#undef ARM_VARIANT
15262#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15263 TUE(it, 0, bf08, 1, (COND), it, t_it),
15264 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15265 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15266 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15267 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15268 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15269 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15270 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15271 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15272 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15273 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15274 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15275 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15276 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15277 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15278
92e90b6e
PB
15279 /* Thumb2 only instructions. */
15280#undef ARM_VARIANT
e74cfd16 15281#define ARM_VARIANT NULL
92e90b6e
PB
15282
15283 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15284 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15285 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15286 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15287
62b3e311
PB
15288 /* Thumb-2 hardware division instructions (R and M profiles only). */
15289#undef THUMB_VARIANT
15290#define THUMB_VARIANT &arm_ext_div
15291 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15292 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15293
15294 /* ARM V7 instructions. */
15295#undef ARM_VARIANT
15296#define ARM_VARIANT &arm_ext_v7
15297#undef THUMB_VARIANT
15298#define THUMB_VARIANT &arm_ext_v7
15299 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15300 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15301 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15302 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15303 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15304
c19d1205 15305#undef ARM_VARIANT
e74cfd16 15306#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15307 cCE(wfs, e200110, 1, (RR), rd),
15308 cCE(rfs, e300110, 1, (RR), rd),
15309 cCE(wfc, e400110, 1, (RR), rd),
15310 cCE(rfc, e500110, 1, (RR), rd),
15311
4962c51a
MS
15312 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15313 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15314 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15315 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15316
4962c51a
MS
15317 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15318 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15319 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15320 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15321
15322 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15323 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15324 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15325 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15326 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15327 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15328 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15329 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15330 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15331 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15332 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15333 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15334
15335 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15336 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15337 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15338 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15339 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15340 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15341 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15342 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15343 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15344 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15345 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15346 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15347
15348 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15349 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15350 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15351 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15352 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15353 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15354 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15355 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15356 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15357 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15358 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15359 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15360
15361 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15362 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15363 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15364 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15365 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15366 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15367 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15368 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15369 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15370 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15371 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15372 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15373
15374 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15375 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15376 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15377 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15378 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15379 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15380 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15381 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15382 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15383 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15384 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15385 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15386
15387 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15388 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15389 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15390 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15391 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15392 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15393 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15394 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15395 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15396 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15397 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15398 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15399
15400 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15401 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15402 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15403 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15404 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15405 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15406 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15407 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15408 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15409 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15410 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15411 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15412
15413 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15414 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15415 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15416 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15417 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15418 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15419 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15420 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15421 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15422 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15423 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15424 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15425
15426 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15427 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15428 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15429 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15430 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15431 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15432 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15433 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15434 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15435 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15436 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15437 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15438
15439 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15440 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15441 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15442 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15443 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15444 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15445 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15446 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15447 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15448 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15449 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15450 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15451
15452 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15453 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15454 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15455 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15456 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15457 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15458 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15459 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15460 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15461 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15462 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15463 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15464
15465 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15466 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15467 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15468 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15469 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15470 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15471 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15472 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15473 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15474 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15475 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15476 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15477
15478 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15479 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15480 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15481 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15482 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15483 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15484 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15485 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15486 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15487 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15488 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15489 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15490
15491 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15492 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15493 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15494 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15495 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15496 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15497 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15498 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15499 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15500 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15501 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15502 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15503
15504 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15505 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15506 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15507 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15508 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15509 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15510 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15511 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15512 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15513 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15514 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15515 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15516
15517 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15518 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15519 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15520 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15521 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15522 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15523 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15524 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15525 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15526 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15527 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15528 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15529
15530 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15531 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15532 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15533 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15534 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15535 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15536 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15537 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15538 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15539 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15540 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15541 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15542
15543 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15544 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15545 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15546 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15547 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15548 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15549 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15550 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15551 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15552 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15553 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15554 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15555
15556 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15557 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15558 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15559 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15560 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15561 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15562 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15563 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15564 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15565 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15566 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15568
15569 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15581
15582 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15594
15595 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15607
15608 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15620
15621 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15633
15634 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15646
15647 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15659
15660 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15672
15673 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15685
15686 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15698
15699 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15700 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15701 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15702 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15703
e3cb604e
PB
15704 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15705 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15706 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15707 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15708 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15709 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15710 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15711 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15712 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15713 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15714 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15715 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15716
c19d1205
ZW
15717 /* The implementation of the FIX instruction is broken on some
15718 assemblers, in that it accepts a precision specifier as well as a
15719 rounding specifier, despite the fact that this is meaningless.
15720 To be more compatible, we accept it as well, though of course it
15721 does not set any bits. */
8f06b2d8 15722 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15723 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15724 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15725 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15726 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15727 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15728 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15729 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15730 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15731 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15732 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15733 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15734 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15735
c19d1205
ZW
15736 /* Instructions that were new with the real FPA, call them V2. */
15737#undef ARM_VARIANT
e74cfd16 15738#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15739 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15740 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15741 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15742 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15743 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15744 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15745
15746#undef ARM_VARIANT
e74cfd16 15747#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15748 /* Moves and type conversions. */
8f06b2d8
PB
15749 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15750 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15751 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15752 cCE(fmstat, ef1fa10, 0, (), noargs),
15753 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15754 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15755 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15756 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15757 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15758 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15759 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15760 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15761
15762 /* Memory operations. */
4962c51a
MS
15763 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15764 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15765 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15766 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15767 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15768 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15769 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15770 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15771 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15772 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15773 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15774 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15775 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15776 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15777 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15778 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15779 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15780 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15781
c19d1205 15782 /* Monadic operations. */
8f06b2d8
PB
15783 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15784 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15785 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15786
15787 /* Dyadic operations. */
8f06b2d8
PB
15788 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15789 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15790 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15791 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15792 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15793 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15794 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15795 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15796 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15797
c19d1205 15798 /* Comparisons. */
8f06b2d8
PB
15799 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15800 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15801 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15802 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15803
c19d1205 15804#undef ARM_VARIANT
e74cfd16 15805#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15806 /* Moves and type conversions. */
5287ad62 15807 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15808 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15809 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15810 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15811 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15812 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15813 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15814 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15815 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15816 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15817 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15818 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15819 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15820
15821 /* Memory operations. */
4962c51a
MS
15822 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15823 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15824 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15825 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15826 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15827 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15828 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15829 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15830 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15831 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15832
c19d1205 15833 /* Monadic operations. */
5287ad62
JB
15834 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15835 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15836 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15837
15838 /* Dyadic operations. */
5287ad62
JB
15839 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15840 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15841 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15842 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15843 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15844 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15845 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15846 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15847 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15848
c19d1205 15849 /* Comparisons. */
5287ad62
JB
15850 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15851 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15852 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15853 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15854
15855#undef ARM_VARIANT
e74cfd16 15856#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15857 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15858 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15859 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15860 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15861
037e8744
JB
15862/* Instructions which may belong to either the Neon or VFP instruction sets.
15863 Individual encoder functions perform additional architecture checks. */
15864#undef ARM_VARIANT
15865#define ARM_VARIANT &fpu_vfp_ext_v1xd
15866#undef THUMB_VARIANT
15867#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15868 /* These mnemonics are unique to VFP. */
15869 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15870 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15871 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15872 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15873 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15874 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15875 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15876 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15877 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15878 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15879
15880 /* Mnemonics shared by Neon and VFP. */
15881 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15882 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15883 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15884
15885 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15886 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15887
15888 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15889 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15890
15891 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15892 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15893 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15894 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15895 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15896 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15897 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15898 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15899
15900 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15901
15902 /* NOTE: All VMOV encoding is special-cased! */
15903 NCE(vmov, 0, 1, (VMOV), neon_mov),
15904 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15905
5287ad62
JB
15906#undef THUMB_VARIANT
15907#define THUMB_VARIANT &fpu_neon_ext_v1
15908#undef ARM_VARIANT
15909#define ARM_VARIANT &fpu_neon_ext_v1
15910 /* Data processing with three registers of the same length. */
15911 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15912 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15913 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15914 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15915 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15916 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15917 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15918 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15919 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15920 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15921 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15922 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15923 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15924 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15925 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15926 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15927 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15928 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15929 /* If not immediate, fall back to neon_dyadic_i64_su.
15930 shl_imm should accept I8 I16 I32 I64,
15931 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15932 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15933 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15934 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15935 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15936 /* Logic ops, types optional & ignored. */
15937 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15938 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15939 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15940 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15941 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15942 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15943 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15944 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15945 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15946 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15947 /* Bitfield ops, untyped. */
15948 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15949 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15950 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15951 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15952 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15953 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15954 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15955 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15956 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15957 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15958 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15959 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15960 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15961 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15962 back to neon_dyadic_if_su. */
15963 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15964 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15965 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15966 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15967 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15968 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15969 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15970 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 15971 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
15972 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15973 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15974 /* As above, D registers only. */
15975 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15976 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15977 /* Int and float variants, signedness unimportant. */
5287ad62 15978 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
15979 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15980 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15981 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 15982 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
15983 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15984 /* vtst takes sizes 8, 16, 32. */
15985 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15986 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15987 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 15988 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
15989 /* VQD{R}MULH takes S16 S32. */
15990 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15991 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15992 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15993 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15994 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15995 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15996 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15997 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
15998 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15999 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16000 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16001 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16002 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16003 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16004 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16005 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16006
16007 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16008 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16009 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16010
16011 /* Data processing with two registers and a shift amount. */
16012 /* Right shifts, and variants with rounding.
16013 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16014 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16015 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16016 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16017 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16018 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16019 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16020 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16021 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16022 /* Shift and insert. Sizes accepted 8 16 32 64. */
16023 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16024 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16025 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16026 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16027 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16028 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16029 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16030 /* Right shift immediate, saturating & narrowing, with rounding variants.
16031 Types accepted S16 S32 S64 U16 U32 U64. */
16032 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16033 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16034 /* As above, unsigned. Types accepted S16 S32 S64. */
16035 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16036 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16037 /* Right shift narrowing. Types accepted I16 I32 I64. */
16038 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16039 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16040 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16041 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16042 /* CVT with optional immediate for fixed-point variant. */
037e8744 16043 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16044
5287ad62
JB
16045 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16046 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16047
16048 /* Data processing, three registers of different lengths. */
16049 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16050 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16051 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16052 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16053 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16054 /* If not scalar, fall back to neon_dyadic_long.
16055 Vector types as above, scalar types S16 S32 U16 U32. */
16056 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16057 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16058 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16059 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16060 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16061 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16062 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16063 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16064 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16065 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16066 /* Saturating doubling multiplies. Types S16 S32. */
16067 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16068 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16069 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16070 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16071 S16 S32 U16 U32. */
16072 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16073
16074 /* Extract. Size 8. */
3b8d421e
PB
16075 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16076 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16077
16078 /* Two registers, miscellaneous. */
16079 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16080 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16081 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16082 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16083 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16084 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16085 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16086 /* Vector replicate. Sizes 8 16 32. */
16087 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16088 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16089 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16090 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16091 /* VMOVN. Types I16 I32 I64. */
16092 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16093 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16094 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16095 /* VQMOVUN. Types S16 S32 S64. */
16096 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16097 /* VZIP / VUZP. Sizes 8 16 32. */
16098 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16099 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16100 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16101 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16102 /* VQABS / VQNEG. Types S8 S16 S32. */
16103 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16104 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16105 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16106 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16107 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16108 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16109 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16110 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16111 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16112 /* Reciprocal estimates. Types U32 F32. */
16113 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16114 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16115 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16116 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16117 /* VCLS. Types S8 S16 S32. */
16118 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16119 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16120 /* VCLZ. Types I8 I16 I32. */
16121 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16122 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16123 /* VCNT. Size 8. */
16124 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16125 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16126 /* Two address, untyped. */
16127 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16128 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16129 /* VTRN. Sizes 8 16 32. */
16130 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16131 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16132
16133 /* Table lookup. Size 8. */
16134 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16135 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16136
b7fc2769
JB
16137#undef THUMB_VARIANT
16138#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16139#undef ARM_VARIANT
16140#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16141 /* Neon element/structure load/store. */
16142 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16143 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16144 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16145 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16146 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16147 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16148 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16149 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16150
16151#undef THUMB_VARIANT
16152#define THUMB_VARIANT &fpu_vfp_ext_v3
16153#undef ARM_VARIANT
16154#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16155 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16156 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16157 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16158 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16159 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16160 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16161 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16162 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16163 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16164 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16165 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16166 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16167 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16168 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16169 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16170 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16171 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16172 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16173
5287ad62 16174#undef THUMB_VARIANT
c19d1205 16175#undef ARM_VARIANT
e74cfd16 16176#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16177 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16178 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16179 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16180 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16181 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16182 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16183 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16184 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16185
16186#undef ARM_VARIANT
e74cfd16 16187#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16188 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16189 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16190 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16191 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16192 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16193 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16194 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16195 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16196 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16197 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16198 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16199 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16200 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16201 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16202 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16203 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16204 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16205 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16206 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16207 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16208 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16209 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16210 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16211 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16212 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16213 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16214 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16215 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16216 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16217 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16218 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16219 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16220 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16221 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16222 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16223 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16224 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16225 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16226 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16227 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16228 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16229 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16230 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16231 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16232 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16233 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16234 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16235 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16236 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16237 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16238 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16239 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16240 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16241 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16242 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16243 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16244 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16245 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16246 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16247 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16248 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16249 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16250 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16251 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16252 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16253 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16254 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16255 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16256 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16257 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16258 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16259 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16260 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16261 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16277 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16288 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16289 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16290 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16291 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16292 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16293 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16294 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16299 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16300 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16301 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16302 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16303 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16304 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16305 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16306 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16307 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16308 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16309 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16310 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16311 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16312 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16313 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16314 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16315 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16316 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16317 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16318 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16319 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16320 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16321 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16328 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16331 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16332 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16333 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16334 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16335 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16336 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16337 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16338 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16339 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16340 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16341 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16342 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16343 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16344 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16345 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16346 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16347 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16348 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16349 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16350
2d447fca
JM
16351#undef ARM_VARIANT
16352#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16353 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16354 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16355 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16356 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16357 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16358 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16359 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16367 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16368 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16369 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16370 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16371 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16372 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16374 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16376 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16377 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16378 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16379 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16386 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16387 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16388 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16389 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16390 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16391 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16392 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16393 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16394 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16395 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410
c19d1205 16411#undef ARM_VARIANT
e74cfd16 16412#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16413 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16414 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16415 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16416 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16417 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16418 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16419 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16420 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16421 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16422 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16423 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16424 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16425 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16426 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16427 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16428 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16429 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16430 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16431 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16432 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16433 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16434 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16435 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16436 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16437 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16438 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16439 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16440 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16441 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16442 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16443 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16444 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16445 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16446 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16447 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16448 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16449 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16450 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16451 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16452 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16453 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16454 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16455 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16456 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16457 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16458 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16459 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16460 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16461 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16462 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16463 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16464 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16465 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16466 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16467 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16468 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16469 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16470 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16471 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16472 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16473 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16474 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16475 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16476 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16477 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16478 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16479 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16480 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16481 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16482 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16483 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16484 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16485 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16486 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16487 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16488 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16489};
16490#undef ARM_VARIANT
16491#undef THUMB_VARIANT
16492#undef TCE
16493#undef TCM
16494#undef TUE
16495#undef TUF
16496#undef TCC
8f06b2d8 16497#undef cCE
e3cb604e
PB
16498#undef cCL
16499#undef C3E
c19d1205
ZW
16500#undef CE
16501#undef CM
16502#undef UE
16503#undef UF
16504#undef UT
5287ad62
JB
16505#undef NUF
16506#undef nUF
16507#undef NCE
16508#undef nCE
c19d1205
ZW
16509#undef OPS0
16510#undef OPS1
16511#undef OPS2
16512#undef OPS3
16513#undef OPS4
16514#undef OPS5
16515#undef OPS6
16516#undef do_0
16517\f
16518/* MD interface: bits in the object file. */
bfae80f2 16519
c19d1205
ZW
16520/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16521 for use in the a.out file, and stores them in the array pointed to by buf.
16522 This knows about the endian-ness of the target machine and does
16523 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16524 2 (short) and 4 (long) Floating numbers are put out as a series of
16525 LITTLENUMS (shorts, here at least). */
b99bd4ef 16526
c19d1205
ZW
16527void
16528md_number_to_chars (char * buf, valueT val, int n)
16529{
16530 if (target_big_endian)
16531 number_to_chars_bigendian (buf, val, n);
16532 else
16533 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16534}
16535
c19d1205
ZW
16536static valueT
16537md_chars_to_number (char * buf, int n)
bfae80f2 16538{
c19d1205
ZW
16539 valueT result = 0;
16540 unsigned char * where = (unsigned char *) buf;
bfae80f2 16541
c19d1205 16542 if (target_big_endian)
b99bd4ef 16543 {
c19d1205
ZW
16544 while (n--)
16545 {
16546 result <<= 8;
16547 result |= (*where++ & 255);
16548 }
b99bd4ef 16549 }
c19d1205 16550 else
b99bd4ef 16551 {
c19d1205
ZW
16552 while (n--)
16553 {
16554 result <<= 8;
16555 result |= (where[n] & 255);
16556 }
bfae80f2 16557 }
b99bd4ef 16558
c19d1205 16559 return result;
bfae80f2 16560}
b99bd4ef 16561
c19d1205 16562/* MD interface: Sections. */
b99bd4ef 16563
0110f2b8
PB
16564/* Estimate the size of a frag before relaxing. Assume everything fits in
16565 2 bytes. */
16566
c19d1205 16567int
0110f2b8 16568md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16569 segT segtype ATTRIBUTE_UNUSED)
16570{
0110f2b8
PB
16571 fragp->fr_var = 2;
16572 return 2;
16573}
16574
16575/* Convert a machine dependent frag. */
16576
16577void
16578md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16579{
16580 unsigned long insn;
16581 unsigned long old_op;
16582 char *buf;
16583 expressionS exp;
16584 fixS *fixp;
16585 int reloc_type;
16586 int pc_rel;
16587 int opcode;
16588
16589 buf = fragp->fr_literal + fragp->fr_fix;
16590
16591 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
16592 if (fragp->fr_symbol)
16593 {
0110f2b8
PB
16594 exp.X_op = O_symbol;
16595 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
16596 }
16597 else
16598 {
0110f2b8 16599 exp.X_op = O_constant;
5f4273c7 16600 }
0110f2b8
PB
16601 exp.X_add_number = fragp->fr_offset;
16602 opcode = fragp->fr_subtype;
16603 switch (opcode)
16604 {
16605 case T_MNEM_ldr_pc:
16606 case T_MNEM_ldr_pc2:
16607 case T_MNEM_ldr_sp:
16608 case T_MNEM_str_sp:
16609 case T_MNEM_ldr:
16610 case T_MNEM_ldrb:
16611 case T_MNEM_ldrh:
16612 case T_MNEM_str:
16613 case T_MNEM_strb:
16614 case T_MNEM_strh:
16615 if (fragp->fr_var == 4)
16616 {
5f4273c7 16617 insn = THUMB_OP32 (opcode);
0110f2b8
PB
16618 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16619 {
16620 insn |= (old_op & 0x700) << 4;
16621 }
16622 else
16623 {
16624 insn |= (old_op & 7) << 12;
16625 insn |= (old_op & 0x38) << 13;
16626 }
16627 insn |= 0x00000c00;
16628 put_thumb32_insn (buf, insn);
16629 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16630 }
16631 else
16632 {
16633 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16634 }
16635 pc_rel = (opcode == T_MNEM_ldr_pc2);
16636 break;
16637 case T_MNEM_adr:
16638 if (fragp->fr_var == 4)
16639 {
16640 insn = THUMB_OP32 (opcode);
16641 insn |= (old_op & 0xf0) << 4;
16642 put_thumb32_insn (buf, insn);
16643 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16644 }
16645 else
16646 {
16647 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16648 exp.X_add_number -= 4;
16649 }
16650 pc_rel = 1;
16651 break;
16652 case T_MNEM_mov:
16653 case T_MNEM_movs:
16654 case T_MNEM_cmp:
16655 case T_MNEM_cmn:
16656 if (fragp->fr_var == 4)
16657 {
16658 int r0off = (opcode == T_MNEM_mov
16659 || opcode == T_MNEM_movs) ? 0 : 8;
16660 insn = THUMB_OP32 (opcode);
16661 insn = (insn & 0xe1ffffff) | 0x10000000;
16662 insn |= (old_op & 0x700) << r0off;
16663 put_thumb32_insn (buf, insn);
16664 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16665 }
16666 else
16667 {
16668 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16669 }
16670 pc_rel = 0;
16671 break;
16672 case T_MNEM_b:
16673 if (fragp->fr_var == 4)
16674 {
16675 insn = THUMB_OP32(opcode);
16676 put_thumb32_insn (buf, insn);
16677 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16678 }
16679 else
16680 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16681 pc_rel = 1;
16682 break;
16683 case T_MNEM_bcond:
16684 if (fragp->fr_var == 4)
16685 {
16686 insn = THUMB_OP32(opcode);
16687 insn |= (old_op & 0xf00) << 14;
16688 put_thumb32_insn (buf, insn);
16689 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16690 }
16691 else
16692 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16693 pc_rel = 1;
16694 break;
16695 case T_MNEM_add_sp:
16696 case T_MNEM_add_pc:
16697 case T_MNEM_inc_sp:
16698 case T_MNEM_dec_sp:
16699 if (fragp->fr_var == 4)
16700 {
16701 /* ??? Choose between add and addw. */
16702 insn = THUMB_OP32 (opcode);
16703 insn |= (old_op & 0xf0) << 4;
16704 put_thumb32_insn (buf, insn);
16805f35
PB
16705 if (opcode == T_MNEM_add_pc)
16706 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16707 else
16708 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16709 }
16710 else
16711 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16712 pc_rel = 0;
16713 break;
16714
16715 case T_MNEM_addi:
16716 case T_MNEM_addis:
16717 case T_MNEM_subi:
16718 case T_MNEM_subis:
16719 if (fragp->fr_var == 4)
16720 {
16721 insn = THUMB_OP32 (opcode);
16722 insn |= (old_op & 0xf0) << 4;
16723 insn |= (old_op & 0xf) << 16;
16724 put_thumb32_insn (buf, insn);
16805f35
PB
16725 if (insn & (1 << 20))
16726 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16727 else
16728 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16729 }
16730 else
16731 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16732 pc_rel = 0;
16733 break;
16734 default:
5f4273c7 16735 abort ();
0110f2b8
PB
16736 }
16737 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16738 reloc_type);
16739 fixp->fx_file = fragp->fr_file;
16740 fixp->fx_line = fragp->fr_line;
16741 fragp->fr_fix += fragp->fr_var;
16742}
16743
16744/* Return the size of a relaxable immediate operand instruction.
16745 SHIFT and SIZE specify the form of the allowable immediate. */
16746static int
16747relax_immediate (fragS *fragp, int size, int shift)
16748{
16749 offsetT offset;
16750 offsetT mask;
16751 offsetT low;
16752
16753 /* ??? Should be able to do better than this. */
16754 if (fragp->fr_symbol)
16755 return 4;
16756
16757 low = (1 << shift) - 1;
16758 mask = (1 << (shift + size)) - (1 << shift);
16759 offset = fragp->fr_offset;
16760 /* Force misaligned offsets to 32-bit variant. */
16761 if (offset & low)
5e77afaa 16762 return 4;
0110f2b8
PB
16763 if (offset & ~mask)
16764 return 4;
16765 return 2;
16766}
16767
5e77afaa
PB
16768/* Get the address of a symbol during relaxation. */
16769static addressT
5f4273c7 16770relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
16771{
16772 fragS *sym_frag;
16773 addressT addr;
16774 symbolS *sym;
16775
16776 sym = fragp->fr_symbol;
16777 sym_frag = symbol_get_frag (sym);
16778 know (S_GET_SEGMENT (sym) != absolute_section
16779 || sym_frag == &zero_address_frag);
16780 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16781
16782 /* If frag has yet to be reached on this pass, assume it will
16783 move by STRETCH just as we did. If this is not so, it will
16784 be because some frag between grows, and that will force
16785 another pass. */
16786
16787 if (stretch != 0
16788 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
16789 {
16790 fragS *f;
16791
16792 /* Adjust stretch for any alignment frag. Note that if have
16793 been expanding the earlier code, the symbol may be
16794 defined in what appears to be an earlier frag. FIXME:
16795 This doesn't handle the fr_subtype field, which specifies
16796 a maximum number of bytes to skip when doing an
16797 alignment. */
16798 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16799 {
16800 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16801 {
16802 if (stretch < 0)
16803 stretch = - ((- stretch)
16804 & ~ ((1 << (int) f->fr_offset) - 1));
16805 else
16806 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16807 if (stretch == 0)
16808 break;
16809 }
16810 }
16811 if (f != NULL)
16812 addr += stretch;
16813 }
5e77afaa
PB
16814
16815 return addr;
16816}
16817
0110f2b8
PB
16818/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16819 load. */
16820static int
5e77afaa 16821relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16822{
16823 addressT addr;
16824 offsetT val;
16825
16826 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16827 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16828 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16829 return 4;
16830
5f4273c7 16831 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16832 addr = fragp->fr_address + fragp->fr_fix;
16833 addr = (addr + 4) & ~3;
5e77afaa 16834 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16835 if (val & 3)
5e77afaa 16836 return 4;
0110f2b8
PB
16837 val -= addr;
16838 if (val < 0 || val > 1020)
16839 return 4;
16840 return 2;
16841}
16842
16843/* Return the size of a relaxable add/sub immediate instruction. */
16844static int
16845relax_addsub (fragS *fragp, asection *sec)
16846{
16847 char *buf;
16848 int op;
16849
16850 buf = fragp->fr_literal + fragp->fr_fix;
16851 op = bfd_get_16(sec->owner, buf);
16852 if ((op & 0xf) == ((op >> 4) & 0xf))
16853 return relax_immediate (fragp, 8, 0);
16854 else
16855 return relax_immediate (fragp, 3, 0);
16856}
16857
16858
16859/* Return the size of a relaxable branch instruction. BITS is the
16860 size of the offset field in the narrow instruction. */
16861
16862static int
5e77afaa 16863relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16864{
16865 addressT addr;
16866 offsetT val;
16867 offsetT limit;
16868
16869 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16870 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16871 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16872 return 4;
16873
5f4273c7 16874 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16875 addr = fragp->fr_address + fragp->fr_fix + 4;
16876 val -= addr;
16877
16878 /* Offset is a signed value *2 */
16879 limit = 1 << bits;
16880 if (val >= limit || val < -limit)
16881 return 4;
16882 return 2;
16883}
16884
16885
16886/* Relax a machine dependent frag. This returns the amount by which
16887 the current size of the frag should change. */
16888
16889int
5e77afaa 16890arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16891{
16892 int oldsize;
16893 int newsize;
16894
16895 oldsize = fragp->fr_var;
16896 switch (fragp->fr_subtype)
16897 {
16898 case T_MNEM_ldr_pc2:
5f4273c7 16899 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16900 break;
16901 case T_MNEM_ldr_pc:
16902 case T_MNEM_ldr_sp:
16903 case T_MNEM_str_sp:
5f4273c7 16904 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
16905 break;
16906 case T_MNEM_ldr:
16907 case T_MNEM_str:
5f4273c7 16908 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
16909 break;
16910 case T_MNEM_ldrh:
16911 case T_MNEM_strh:
5f4273c7 16912 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
16913 break;
16914 case T_MNEM_ldrb:
16915 case T_MNEM_strb:
5f4273c7 16916 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
16917 break;
16918 case T_MNEM_adr:
5f4273c7 16919 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16920 break;
16921 case T_MNEM_mov:
16922 case T_MNEM_movs:
16923 case T_MNEM_cmp:
16924 case T_MNEM_cmn:
5f4273c7 16925 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
16926 break;
16927 case T_MNEM_b:
5f4273c7 16928 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
16929 break;
16930 case T_MNEM_bcond:
5f4273c7 16931 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
16932 break;
16933 case T_MNEM_add_sp:
16934 case T_MNEM_add_pc:
16935 newsize = relax_immediate (fragp, 8, 2);
16936 break;
16937 case T_MNEM_inc_sp:
16938 case T_MNEM_dec_sp:
16939 newsize = relax_immediate (fragp, 7, 2);
16940 break;
16941 case T_MNEM_addi:
16942 case T_MNEM_addis:
16943 case T_MNEM_subi:
16944 case T_MNEM_subis:
16945 newsize = relax_addsub (fragp, sec);
16946 break;
16947 default:
5f4273c7 16948 abort ();
0110f2b8 16949 }
5e77afaa
PB
16950
16951 fragp->fr_var = newsize;
16952 /* Freeze wide instructions that are at or before the same location as
16953 in the previous pass. This avoids infinite loops.
5f4273c7
NC
16954 Don't freeze them unconditionally because targets may be artificially
16955 misaligned by the expansion of preceding frags. */
5e77afaa 16956 if (stretch <= 0 && newsize > 2)
0110f2b8 16957 {
0110f2b8 16958 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 16959 frag_wane (fragp);
0110f2b8 16960 }
5e77afaa 16961
0110f2b8 16962 return newsize - oldsize;
c19d1205 16963}
b99bd4ef 16964
c19d1205 16965/* Round up a section size to the appropriate boundary. */
b99bd4ef 16966
c19d1205
ZW
16967valueT
16968md_section_align (segT segment ATTRIBUTE_UNUSED,
16969 valueT size)
16970{
f0927246
NC
16971#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16972 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16973 {
16974 /* For a.out, force the section size to be aligned. If we don't do
16975 this, BFD will align it for us, but it will not write out the
16976 final bytes of the section. This may be a bug in BFD, but it is
16977 easier to fix it here since that is how the other a.out targets
16978 work. */
16979 int align;
16980
16981 align = bfd_get_section_alignment (stdoutput, segment);
16982 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16983 }
c19d1205 16984#endif
f0927246
NC
16985
16986 return size;
bfae80f2 16987}
b99bd4ef 16988
c19d1205
ZW
16989/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16990 of an rs_align_code fragment. */
16991
16992void
16993arm_handle_align (fragS * fragP)
bfae80f2 16994{
c19d1205
ZW
16995 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16996 static char const thumb_noop[2] = { 0xc0, 0x46 };
16997 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16998 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16999
17000 int bytes, fix, noop_size;
17001 char * p;
17002 const char * noop;
bfae80f2 17003
c19d1205 17004 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17005 return;
17006
c19d1205
ZW
17007 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17008 p = fragP->fr_literal + fragP->fr_fix;
17009 fix = 0;
bfae80f2 17010
c19d1205
ZW
17011 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17012 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17013
c19d1205 17014 if (fragP->tc_frag_data)
a737bd4d 17015 {
c19d1205
ZW
17016 if (target_big_endian)
17017 noop = thumb_bigend_noop;
17018 else
17019 noop = thumb_noop;
17020 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17021 }
17022 else
17023 {
c19d1205
ZW
17024 if (target_big_endian)
17025 noop = arm_bigend_noop;
17026 else
17027 noop = arm_noop;
17028 noop_size = sizeof (arm_noop);
7ed4c4c5 17029 }
a737bd4d 17030
c19d1205 17031 if (bytes & (noop_size - 1))
7ed4c4c5 17032 {
c19d1205
ZW
17033 fix = bytes & (noop_size - 1);
17034 memset (p, 0, fix);
17035 p += fix;
17036 bytes -= fix;
a737bd4d 17037 }
a737bd4d 17038
c19d1205 17039 while (bytes >= noop_size)
a737bd4d 17040 {
c19d1205
ZW
17041 memcpy (p, noop, noop_size);
17042 p += noop_size;
17043 bytes -= noop_size;
17044 fix += noop_size;
a737bd4d
NC
17045 }
17046
c19d1205
ZW
17047 fragP->fr_fix += fix;
17048 fragP->fr_var = noop_size;
a737bd4d
NC
17049}
17050
c19d1205
ZW
17051/* Called from md_do_align. Used to create an alignment
17052 frag in a code section. */
17053
17054void
17055arm_frag_align_code (int n, int max)
bfae80f2 17056{
c19d1205 17057 char * p;
7ed4c4c5 17058
c19d1205
ZW
17059 /* We assume that there will never be a requirement
17060 to support alignments greater than 32 bytes. */
17061 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17062 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17063
c19d1205
ZW
17064 p = frag_var (rs_align_code,
17065 MAX_MEM_FOR_RS_ALIGN_CODE,
17066 1,
17067 (relax_substateT) max,
17068 (symbolS *) NULL,
17069 (offsetT) n,
17070 (char *) NULL);
17071 *p = 0;
17072}
bfae80f2 17073
c19d1205 17074/* Perform target specific initialisation of a frag. */
bfae80f2 17075
c19d1205
ZW
17076void
17077arm_init_frag (fragS * fragP)
17078{
17079 /* Record whether this frag is in an ARM or a THUMB area. */
17080 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17081}
17082
c19d1205
ZW
17083#ifdef OBJ_ELF
17084/* When we change sections we need to issue a new mapping symbol. */
17085
17086void
17087arm_elf_change_section (void)
bfae80f2 17088{
c19d1205
ZW
17089 flagword flags;
17090 segment_info_type *seginfo;
bfae80f2 17091
c19d1205
ZW
17092 /* Link an unlinked unwind index table section to the .text section. */
17093 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17094 && elf_linked_to_section (now_seg) == NULL)
17095 elf_linked_to_section (now_seg) = text_section;
17096
17097 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17098 return;
17099
c19d1205
ZW
17100 flags = bfd_get_section_flags (stdoutput, now_seg);
17101
17102 /* We can ignore sections that only contain debug info. */
17103 if ((flags & SEC_ALLOC) == 0)
17104 return;
bfae80f2 17105
c19d1205
ZW
17106 seginfo = seg_info (now_seg);
17107 mapstate = seginfo->tc_segment_info_data.mapstate;
17108 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17109}
17110
c19d1205
ZW
17111int
17112arm_elf_section_type (const char * str, size_t len)
e45d0630 17113{
c19d1205
ZW
17114 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17115 return SHT_ARM_EXIDX;
e45d0630 17116
c19d1205
ZW
17117 return -1;
17118}
17119\f
17120/* Code to deal with unwinding tables. */
e45d0630 17121
c19d1205 17122static void add_unwind_adjustsp (offsetT);
e45d0630 17123
5f4273c7 17124/* Generate any deferred unwind frame offset. */
e45d0630 17125
bfae80f2 17126static void
c19d1205 17127flush_pending_unwind (void)
bfae80f2 17128{
c19d1205 17129 offsetT offset;
bfae80f2 17130
c19d1205
ZW
17131 offset = unwind.pending_offset;
17132 unwind.pending_offset = 0;
17133 if (offset != 0)
17134 add_unwind_adjustsp (offset);
bfae80f2
RE
17135}
17136
c19d1205
ZW
17137/* Add an opcode to this list for this function. Two-byte opcodes should
17138 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17139 order. */
17140
bfae80f2 17141static void
c19d1205 17142add_unwind_opcode (valueT op, int length)
bfae80f2 17143{
c19d1205
ZW
17144 /* Add any deferred stack adjustment. */
17145 if (unwind.pending_offset)
17146 flush_pending_unwind ();
bfae80f2 17147
c19d1205 17148 unwind.sp_restored = 0;
bfae80f2 17149
c19d1205 17150 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17151 {
c19d1205
ZW
17152 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17153 if (unwind.opcodes)
17154 unwind.opcodes = xrealloc (unwind.opcodes,
17155 unwind.opcode_alloc);
17156 else
17157 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17158 }
c19d1205 17159 while (length > 0)
bfae80f2 17160 {
c19d1205
ZW
17161 length--;
17162 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17163 op >>= 8;
17164 unwind.opcode_count++;
bfae80f2 17165 }
bfae80f2
RE
17166}
17167
c19d1205
ZW
17168/* Add unwind opcodes to adjust the stack pointer. */
17169
bfae80f2 17170static void
c19d1205 17171add_unwind_adjustsp (offsetT offset)
bfae80f2 17172{
c19d1205 17173 valueT op;
bfae80f2 17174
c19d1205 17175 if (offset > 0x200)
bfae80f2 17176 {
c19d1205
ZW
17177 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17178 char bytes[5];
17179 int n;
17180 valueT o;
bfae80f2 17181
c19d1205
ZW
17182 /* Long form: 0xb2, uleb128. */
17183 /* This might not fit in a word so add the individual bytes,
17184 remembering the list is built in reverse order. */
17185 o = (valueT) ((offset - 0x204) >> 2);
17186 if (o == 0)
17187 add_unwind_opcode (0, 1);
bfae80f2 17188
c19d1205
ZW
17189 /* Calculate the uleb128 encoding of the offset. */
17190 n = 0;
17191 while (o)
17192 {
17193 bytes[n] = o & 0x7f;
17194 o >>= 7;
17195 if (o)
17196 bytes[n] |= 0x80;
17197 n++;
17198 }
17199 /* Add the insn. */
17200 for (; n; n--)
17201 add_unwind_opcode (bytes[n - 1], 1);
17202 add_unwind_opcode (0xb2, 1);
17203 }
17204 else if (offset > 0x100)
bfae80f2 17205 {
c19d1205
ZW
17206 /* Two short opcodes. */
17207 add_unwind_opcode (0x3f, 1);
17208 op = (offset - 0x104) >> 2;
17209 add_unwind_opcode (op, 1);
bfae80f2 17210 }
c19d1205
ZW
17211 else if (offset > 0)
17212 {
17213 /* Short opcode. */
17214 op = (offset - 4) >> 2;
17215 add_unwind_opcode (op, 1);
17216 }
17217 else if (offset < 0)
bfae80f2 17218 {
c19d1205
ZW
17219 offset = -offset;
17220 while (offset > 0x100)
bfae80f2 17221 {
c19d1205
ZW
17222 add_unwind_opcode (0x7f, 1);
17223 offset -= 0x100;
bfae80f2 17224 }
c19d1205
ZW
17225 op = ((offset - 4) >> 2) | 0x40;
17226 add_unwind_opcode (op, 1);
bfae80f2 17227 }
bfae80f2
RE
17228}
17229
c19d1205
ZW
17230/* Finish the list of unwind opcodes for this function. */
17231static void
17232finish_unwind_opcodes (void)
bfae80f2 17233{
c19d1205 17234 valueT op;
bfae80f2 17235
c19d1205 17236 if (unwind.fp_used)
bfae80f2 17237 {
708587a4 17238 /* Adjust sp as necessary. */
c19d1205
ZW
17239 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17240 flush_pending_unwind ();
bfae80f2 17241
c19d1205
ZW
17242 /* After restoring sp from the frame pointer. */
17243 op = 0x90 | unwind.fp_reg;
17244 add_unwind_opcode (op, 1);
17245 }
17246 else
17247 flush_pending_unwind ();
bfae80f2
RE
17248}
17249
bfae80f2 17250
c19d1205
ZW
17251/* Start an exception table entry. If idx is nonzero this is an index table
17252 entry. */
bfae80f2
RE
17253
17254static void
c19d1205 17255start_unwind_section (const segT text_seg, int idx)
bfae80f2 17256{
c19d1205
ZW
17257 const char * text_name;
17258 const char * prefix;
17259 const char * prefix_once;
17260 const char * group_name;
17261 size_t prefix_len;
17262 size_t text_len;
17263 char * sec_name;
17264 size_t sec_name_len;
17265 int type;
17266 int flags;
17267 int linkonce;
bfae80f2 17268
c19d1205 17269 if (idx)
bfae80f2 17270 {
c19d1205
ZW
17271 prefix = ELF_STRING_ARM_unwind;
17272 prefix_once = ELF_STRING_ARM_unwind_once;
17273 type = SHT_ARM_EXIDX;
bfae80f2 17274 }
c19d1205 17275 else
bfae80f2 17276 {
c19d1205
ZW
17277 prefix = ELF_STRING_ARM_unwind_info;
17278 prefix_once = ELF_STRING_ARM_unwind_info_once;
17279 type = SHT_PROGBITS;
bfae80f2
RE
17280 }
17281
c19d1205
ZW
17282 text_name = segment_name (text_seg);
17283 if (streq (text_name, ".text"))
17284 text_name = "";
17285
17286 if (strncmp (text_name, ".gnu.linkonce.t.",
17287 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17288 {
c19d1205
ZW
17289 prefix = prefix_once;
17290 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17291 }
17292
c19d1205
ZW
17293 prefix_len = strlen (prefix);
17294 text_len = strlen (text_name);
17295 sec_name_len = prefix_len + text_len;
17296 sec_name = xmalloc (sec_name_len + 1);
17297 memcpy (sec_name, prefix, prefix_len);
17298 memcpy (sec_name + prefix_len, text_name, text_len);
17299 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17300
c19d1205
ZW
17301 flags = SHF_ALLOC;
17302 linkonce = 0;
17303 group_name = 0;
bfae80f2 17304
c19d1205
ZW
17305 /* Handle COMDAT group. */
17306 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17307 {
c19d1205
ZW
17308 group_name = elf_group_name (text_seg);
17309 if (group_name == NULL)
17310 {
bd3ba5d1 17311 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17312 segment_name (text_seg));
17313 ignore_rest_of_line ();
17314 return;
17315 }
17316 flags |= SHF_GROUP;
17317 linkonce = 1;
bfae80f2
RE
17318 }
17319
c19d1205 17320 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17321
5f4273c7 17322 /* Set the section link for index tables. */
c19d1205
ZW
17323 if (idx)
17324 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17325}
17326
bfae80f2 17327
c19d1205
ZW
17328/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17329 personality routine data. Returns zero, or the index table value for
17330 and inline entry. */
17331
17332static valueT
17333create_unwind_entry (int have_data)
bfae80f2 17334{
c19d1205
ZW
17335 int size;
17336 addressT where;
17337 char *ptr;
17338 /* The current word of data. */
17339 valueT data;
17340 /* The number of bytes left in this word. */
17341 int n;
bfae80f2 17342
c19d1205 17343 finish_unwind_opcodes ();
bfae80f2 17344
c19d1205
ZW
17345 /* Remember the current text section. */
17346 unwind.saved_seg = now_seg;
17347 unwind.saved_subseg = now_subseg;
bfae80f2 17348
c19d1205 17349 start_unwind_section (now_seg, 0);
bfae80f2 17350
c19d1205 17351 if (unwind.personality_routine == NULL)
bfae80f2 17352 {
c19d1205
ZW
17353 if (unwind.personality_index == -2)
17354 {
17355 if (have_data)
5f4273c7 17356 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17357 return 1; /* EXIDX_CANTUNWIND. */
17358 }
bfae80f2 17359
c19d1205
ZW
17360 /* Use a default personality routine if none is specified. */
17361 if (unwind.personality_index == -1)
17362 {
17363 if (unwind.opcode_count > 3)
17364 unwind.personality_index = 1;
17365 else
17366 unwind.personality_index = 0;
17367 }
bfae80f2 17368
c19d1205
ZW
17369 /* Space for the personality routine entry. */
17370 if (unwind.personality_index == 0)
17371 {
17372 if (unwind.opcode_count > 3)
17373 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17374
c19d1205
ZW
17375 if (!have_data)
17376 {
17377 /* All the data is inline in the index table. */
17378 data = 0x80;
17379 n = 3;
17380 while (unwind.opcode_count > 0)
17381 {
17382 unwind.opcode_count--;
17383 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17384 n--;
17385 }
bfae80f2 17386
c19d1205
ZW
17387 /* Pad with "finish" opcodes. */
17388 while (n--)
17389 data = (data << 8) | 0xb0;
bfae80f2 17390
c19d1205
ZW
17391 return data;
17392 }
17393 size = 0;
17394 }
17395 else
17396 /* We get two opcodes "free" in the first word. */
17397 size = unwind.opcode_count - 2;
17398 }
17399 else
17400 /* An extra byte is required for the opcode count. */
17401 size = unwind.opcode_count + 1;
bfae80f2 17402
c19d1205
ZW
17403 size = (size + 3) >> 2;
17404 if (size > 0xff)
17405 as_bad (_("too many unwind opcodes"));
bfae80f2 17406
c19d1205
ZW
17407 frag_align (2, 0, 0);
17408 record_alignment (now_seg, 2);
17409 unwind.table_entry = expr_build_dot ();
17410
17411 /* Allocate the table entry. */
17412 ptr = frag_more ((size << 2) + 4);
17413 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17414
c19d1205 17415 switch (unwind.personality_index)
bfae80f2 17416 {
c19d1205
ZW
17417 case -1:
17418 /* ??? Should this be a PLT generating relocation? */
17419 /* Custom personality routine. */
17420 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17421 BFD_RELOC_ARM_PREL31);
bfae80f2 17422
c19d1205
ZW
17423 where += 4;
17424 ptr += 4;
bfae80f2 17425
c19d1205
ZW
17426 /* Set the first byte to the number of additional words. */
17427 data = size - 1;
17428 n = 3;
17429 break;
bfae80f2 17430
c19d1205
ZW
17431 /* ABI defined personality routines. */
17432 case 0:
17433 /* Three opcodes bytes are packed into the first word. */
17434 data = 0x80;
17435 n = 3;
17436 break;
bfae80f2 17437
c19d1205
ZW
17438 case 1:
17439 case 2:
17440 /* The size and first two opcode bytes go in the first word. */
17441 data = ((0x80 + unwind.personality_index) << 8) | size;
17442 n = 2;
17443 break;
bfae80f2 17444
c19d1205
ZW
17445 default:
17446 /* Should never happen. */
17447 abort ();
17448 }
bfae80f2 17449
c19d1205
ZW
17450 /* Pack the opcodes into words (MSB first), reversing the list at the same
17451 time. */
17452 while (unwind.opcode_count > 0)
17453 {
17454 if (n == 0)
17455 {
17456 md_number_to_chars (ptr, data, 4);
17457 ptr += 4;
17458 n = 4;
17459 data = 0;
17460 }
17461 unwind.opcode_count--;
17462 n--;
17463 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17464 }
17465
17466 /* Finish off the last word. */
17467 if (n < 4)
17468 {
17469 /* Pad with "finish" opcodes. */
17470 while (n--)
17471 data = (data << 8) | 0xb0;
17472
17473 md_number_to_chars (ptr, data, 4);
17474 }
17475
17476 if (!have_data)
17477 {
17478 /* Add an empty descriptor if there is no user-specified data. */
17479 ptr = frag_more (4);
17480 md_number_to_chars (ptr, 0, 4);
17481 }
17482
17483 return 0;
bfae80f2
RE
17484}
17485
f0927246
NC
17486
17487/* Initialize the DWARF-2 unwind information for this procedure. */
17488
17489void
17490tc_arm_frame_initial_instructions (void)
17491{
17492 cfi_add_CFA_def_cfa (REG_SP, 0);
17493}
17494#endif /* OBJ_ELF */
17495
c19d1205
ZW
17496/* Convert REGNAME to a DWARF-2 register number. */
17497
17498int
1df69f4f 17499tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17500{
1df69f4f 17501 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17502
17503 if (reg == FAIL)
17504 return -1;
17505
17506 return reg;
bfae80f2
RE
17507}
17508
f0927246 17509#ifdef TE_PE
c19d1205 17510void
f0927246 17511tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17512{
f0927246 17513 expressionS expr;
bfae80f2 17514
f0927246
NC
17515 expr.X_op = O_secrel;
17516 expr.X_add_symbol = symbol;
17517 expr.X_add_number = 0;
17518 emit_expr (&expr, size);
17519}
17520#endif
bfae80f2 17521
c19d1205 17522/* MD interface: Symbol and relocation handling. */
bfae80f2 17523
2fc8bdac
ZW
17524/* Return the address within the segment that a PC-relative fixup is
17525 relative to. For ARM, PC-relative fixups applied to instructions
17526 are generally relative to the location of the fixup plus 8 bytes.
17527 Thumb branches are offset by 4, and Thumb loads relative to PC
17528 require special handling. */
bfae80f2 17529
c19d1205 17530long
2fc8bdac 17531md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17532{
2fc8bdac
ZW
17533 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17534
17535 /* If this is pc-relative and we are going to emit a relocation
17536 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17537 will need. Otherwise we want to use the calculated base.
17538 For WinCE we skip the bias for externals as well, since this
17539 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 17540 if (fixP->fx_pcrel
2fc8bdac 17541 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17542 || (arm_force_relocation (fixP)
17543#ifdef TE_WINCE
17544 && !S_IS_EXTERNAL (fixP->fx_addsy)
17545#endif
17546 )))
2fc8bdac 17547 base = 0;
bfae80f2 17548
c19d1205 17549 switch (fixP->fx_r_type)
bfae80f2 17550 {
2fc8bdac
ZW
17551 /* PC relative addressing on the Thumb is slightly odd as the
17552 bottom two bits of the PC are forced to zero for the
17553 calculation. This happens *after* application of the
17554 pipeline offset. However, Thumb adrl already adjusts for
17555 this, so we need not do it again. */
c19d1205 17556 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17557 return base & ~3;
c19d1205
ZW
17558
17559 case BFD_RELOC_ARM_THUMB_OFFSET:
17560 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17561 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17562 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17563 return (base + 4) & ~3;
c19d1205 17564
2fc8bdac
ZW
17565 /* Thumb branches are simply offset by +4. */
17566 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17567 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17568 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17569 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17570 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17571 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17572 case BFD_RELOC_THUMB_PCREL_BLX:
17573 return base + 4;
bfae80f2 17574
2fc8bdac
ZW
17575 /* ARM mode branches are offset by +8. However, the Windows CE
17576 loader expects the relocation not to take this into account. */
17577 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17578 case BFD_RELOC_ARM_PCREL_CALL:
17579 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17580 case BFD_RELOC_ARM_PCREL_BLX:
17581 case BFD_RELOC_ARM_PLT32:
c19d1205 17582#ifdef TE_WINCE
5f4273c7 17583 /* When handling fixups immediately, because we have already
53baae48
NC
17584 discovered the value of a symbol, or the address of the frag involved
17585 we must account for the offset by +8, as the OS loader will never see the reloc.
17586 see fixup_segment() in write.c
17587 The S_IS_EXTERNAL test handles the case of global symbols.
17588 Those need the calculated base, not just the pipe compensation the linker will need. */
17589 if (fixP->fx_pcrel
17590 && fixP->fx_addsy != NULL
17591 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17592 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17593 return base + 8;
2fc8bdac 17594 return base;
c19d1205 17595#else
2fc8bdac 17596 return base + 8;
c19d1205 17597#endif
2fc8bdac
ZW
17598
17599 /* ARM mode loads relative to PC are also offset by +8. Unlike
17600 branches, the Windows CE loader *does* expect the relocation
17601 to take this into account. */
17602 case BFD_RELOC_ARM_OFFSET_IMM:
17603 case BFD_RELOC_ARM_OFFSET_IMM8:
17604 case BFD_RELOC_ARM_HWLITERAL:
17605 case BFD_RELOC_ARM_LITERAL:
17606 case BFD_RELOC_ARM_CP_OFF_IMM:
17607 return base + 8;
17608
17609
17610 /* Other PC-relative relocations are un-offset. */
17611 default:
17612 return base;
17613 }
bfae80f2
RE
17614}
17615
c19d1205
ZW
17616/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17617 Otherwise we have no need to default values of symbols. */
17618
17619symbolS *
17620md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17621{
c19d1205
ZW
17622#ifdef OBJ_ELF
17623 if (name[0] == '_' && name[1] == 'G'
17624 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17625 {
17626 if (!GOT_symbol)
17627 {
17628 if (symbol_find (name))
bd3ba5d1 17629 as_bad (_("GOT already in the symbol table"));
bfae80f2 17630
c19d1205
ZW
17631 GOT_symbol = symbol_new (name, undefined_section,
17632 (valueT) 0, & zero_address_frag);
17633 }
bfae80f2 17634
c19d1205 17635 return GOT_symbol;
bfae80f2 17636 }
c19d1205 17637#endif
bfae80f2 17638
c19d1205 17639 return 0;
bfae80f2
RE
17640}
17641
55cf6793 17642/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17643 computed as two separate immediate values, added together. We
17644 already know that this value cannot be computed by just one ARM
17645 instruction. */
17646
17647static unsigned int
17648validate_immediate_twopart (unsigned int val,
17649 unsigned int * highpart)
bfae80f2 17650{
c19d1205
ZW
17651 unsigned int a;
17652 unsigned int i;
bfae80f2 17653
c19d1205
ZW
17654 for (i = 0; i < 32; i += 2)
17655 if (((a = rotate_left (val, i)) & 0xff) != 0)
17656 {
17657 if (a & 0xff00)
17658 {
17659 if (a & ~ 0xffff)
17660 continue;
17661 * highpart = (a >> 8) | ((i + 24) << 7);
17662 }
17663 else if (a & 0xff0000)
17664 {
17665 if (a & 0xff000000)
17666 continue;
17667 * highpart = (a >> 16) | ((i + 16) << 7);
17668 }
17669 else
17670 {
17671 assert (a & 0xff000000);
17672 * highpart = (a >> 24) | ((i + 8) << 7);
17673 }
bfae80f2 17674
c19d1205
ZW
17675 return (a & 0xff) | (i << 7);
17676 }
bfae80f2 17677
c19d1205 17678 return FAIL;
bfae80f2
RE
17679}
17680
c19d1205
ZW
17681static int
17682validate_offset_imm (unsigned int val, int hwse)
17683{
17684 if ((hwse && val > 255) || val > 4095)
17685 return FAIL;
17686 return val;
17687}
bfae80f2 17688
55cf6793 17689/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17690 negative immediate constant by altering the instruction. A bit of
17691 a hack really.
17692 MOV <-> MVN
17693 AND <-> BIC
17694 ADC <-> SBC
17695 by inverting the second operand, and
17696 ADD <-> SUB
17697 CMP <-> CMN
17698 by negating the second operand. */
bfae80f2 17699
c19d1205
ZW
17700static int
17701negate_data_op (unsigned long * instruction,
17702 unsigned long value)
bfae80f2 17703{
c19d1205
ZW
17704 int op, new_inst;
17705 unsigned long negated, inverted;
bfae80f2 17706
c19d1205
ZW
17707 negated = encode_arm_immediate (-value);
17708 inverted = encode_arm_immediate (~value);
bfae80f2 17709
c19d1205
ZW
17710 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17711 switch (op)
bfae80f2 17712 {
c19d1205
ZW
17713 /* First negates. */
17714 case OPCODE_SUB: /* ADD <-> SUB */
17715 new_inst = OPCODE_ADD;
17716 value = negated;
17717 break;
bfae80f2 17718
c19d1205
ZW
17719 case OPCODE_ADD:
17720 new_inst = OPCODE_SUB;
17721 value = negated;
17722 break;
bfae80f2 17723
c19d1205
ZW
17724 case OPCODE_CMP: /* CMP <-> CMN */
17725 new_inst = OPCODE_CMN;
17726 value = negated;
17727 break;
bfae80f2 17728
c19d1205
ZW
17729 case OPCODE_CMN:
17730 new_inst = OPCODE_CMP;
17731 value = negated;
17732 break;
bfae80f2 17733
c19d1205
ZW
17734 /* Now Inverted ops. */
17735 case OPCODE_MOV: /* MOV <-> MVN */
17736 new_inst = OPCODE_MVN;
17737 value = inverted;
17738 break;
bfae80f2 17739
c19d1205
ZW
17740 case OPCODE_MVN:
17741 new_inst = OPCODE_MOV;
17742 value = inverted;
17743 break;
bfae80f2 17744
c19d1205
ZW
17745 case OPCODE_AND: /* AND <-> BIC */
17746 new_inst = OPCODE_BIC;
17747 value = inverted;
17748 break;
bfae80f2 17749
c19d1205
ZW
17750 case OPCODE_BIC:
17751 new_inst = OPCODE_AND;
17752 value = inverted;
17753 break;
bfae80f2 17754
c19d1205
ZW
17755 case OPCODE_ADC: /* ADC <-> SBC */
17756 new_inst = OPCODE_SBC;
17757 value = inverted;
17758 break;
bfae80f2 17759
c19d1205
ZW
17760 case OPCODE_SBC:
17761 new_inst = OPCODE_ADC;
17762 value = inverted;
17763 break;
bfae80f2 17764
c19d1205
ZW
17765 /* We cannot do anything. */
17766 default:
17767 return FAIL;
b99bd4ef
NC
17768 }
17769
c19d1205
ZW
17770 if (value == (unsigned) FAIL)
17771 return FAIL;
17772
17773 *instruction &= OPCODE_MASK;
17774 *instruction |= new_inst << DATA_OP_SHIFT;
17775 return value;
b99bd4ef
NC
17776}
17777
ef8d22e6
PB
17778/* Like negate_data_op, but for Thumb-2. */
17779
17780static unsigned int
16dd5e42 17781thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17782{
17783 int op, new_inst;
17784 int rd;
16dd5e42 17785 unsigned int negated, inverted;
ef8d22e6
PB
17786
17787 negated = encode_thumb32_immediate (-value);
17788 inverted = encode_thumb32_immediate (~value);
17789
17790 rd = (*instruction >> 8) & 0xf;
17791 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17792 switch (op)
17793 {
17794 /* ADD <-> SUB. Includes CMP <-> CMN. */
17795 case T2_OPCODE_SUB:
17796 new_inst = T2_OPCODE_ADD;
17797 value = negated;
17798 break;
17799
17800 case T2_OPCODE_ADD:
17801 new_inst = T2_OPCODE_SUB;
17802 value = negated;
17803 break;
17804
17805 /* ORR <-> ORN. Includes MOV <-> MVN. */
17806 case T2_OPCODE_ORR:
17807 new_inst = T2_OPCODE_ORN;
17808 value = inverted;
17809 break;
17810
17811 case T2_OPCODE_ORN:
17812 new_inst = T2_OPCODE_ORR;
17813 value = inverted;
17814 break;
17815
17816 /* AND <-> BIC. TST has no inverted equivalent. */
17817 case T2_OPCODE_AND:
17818 new_inst = T2_OPCODE_BIC;
17819 if (rd == 15)
17820 value = FAIL;
17821 else
17822 value = inverted;
17823 break;
17824
17825 case T2_OPCODE_BIC:
17826 new_inst = T2_OPCODE_AND;
17827 value = inverted;
17828 break;
17829
17830 /* ADC <-> SBC */
17831 case T2_OPCODE_ADC:
17832 new_inst = T2_OPCODE_SBC;
17833 value = inverted;
17834 break;
17835
17836 case T2_OPCODE_SBC:
17837 new_inst = T2_OPCODE_ADC;
17838 value = inverted;
17839 break;
17840
17841 /* We cannot do anything. */
17842 default:
17843 return FAIL;
17844 }
17845
16dd5e42 17846 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17847 return FAIL;
17848
17849 *instruction &= T2_OPCODE_MASK;
17850 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17851 return value;
17852}
17853
8f06b2d8
PB
17854/* Read a 32-bit thumb instruction from buf. */
17855static unsigned long
17856get_thumb32_insn (char * buf)
17857{
17858 unsigned long insn;
17859 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17860 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17861
17862 return insn;
17863}
17864
a8bc6c78
PB
17865
17866/* We usually want to set the low bit on the address of thumb function
17867 symbols. In particular .word foo - . should have the low bit set.
17868 Generic code tries to fold the difference of two symbols to
17869 a constant. Prevent this and force a relocation when the first symbols
17870 is a thumb function. */
17871int
17872arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17873{
17874 if (op == O_subtract
17875 && l->X_op == O_symbol
17876 && r->X_op == O_symbol
17877 && THUMB_IS_FUNC (l->X_add_symbol))
17878 {
17879 l->X_op = O_subtract;
17880 l->X_op_symbol = r->X_add_symbol;
17881 l->X_add_number -= r->X_add_number;
17882 return 1;
17883 }
17884 /* Process as normal. */
17885 return 0;
17886}
17887
c19d1205 17888void
55cf6793 17889md_apply_fix (fixS * fixP,
c19d1205
ZW
17890 valueT * valP,
17891 segT seg)
17892{
17893 offsetT value = * valP;
17894 offsetT newval;
17895 unsigned int newimm;
17896 unsigned long temp;
17897 int sign;
17898 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17899
c19d1205 17900 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17901
c19d1205 17902 /* Note whether this will delete the relocation. */
4962c51a 17903
c19d1205
ZW
17904 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17905 fixP->fx_done = 1;
b99bd4ef 17906
adbaf948 17907 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 17908 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
17909 for emit_reloc. */
17910 value &= 0xffffffff;
17911 value ^= 0x80000000;
5f4273c7 17912 value -= 0x80000000;
adbaf948
ZW
17913
17914 *valP = value;
c19d1205 17915 fixP->fx_addnumber = value;
b99bd4ef 17916
adbaf948
ZW
17917 /* Same treatment for fixP->fx_offset. */
17918 fixP->fx_offset &= 0xffffffff;
17919 fixP->fx_offset ^= 0x80000000;
17920 fixP->fx_offset -= 0x80000000;
17921
c19d1205 17922 switch (fixP->fx_r_type)
b99bd4ef 17923 {
c19d1205
ZW
17924 case BFD_RELOC_NONE:
17925 /* This will need to go in the object file. */
17926 fixP->fx_done = 0;
17927 break;
b99bd4ef 17928
c19d1205
ZW
17929 case BFD_RELOC_ARM_IMMEDIATE:
17930 /* We claim that this fixup has been processed here,
17931 even if in fact we generate an error because we do
17932 not have a reloc for it, so tc_gen_reloc will reject it. */
17933 fixP->fx_done = 1;
b99bd4ef 17934
c19d1205
ZW
17935 if (fixP->fx_addsy
17936 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17937 {
c19d1205
ZW
17938 as_bad_where (fixP->fx_file, fixP->fx_line,
17939 _("undefined symbol %s used as an immediate value"),
17940 S_GET_NAME (fixP->fx_addsy));
17941 break;
b99bd4ef
NC
17942 }
17943
c19d1205
ZW
17944 newimm = encode_arm_immediate (value);
17945 temp = md_chars_to_number (buf, INSN_SIZE);
17946
17947 /* If the instruction will fail, see if we can fix things up by
17948 changing the opcode. */
17949 if (newimm == (unsigned int) FAIL
17950 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17951 {
c19d1205
ZW
17952 as_bad_where (fixP->fx_file, fixP->fx_line,
17953 _("invalid constant (%lx) after fixup"),
17954 (unsigned long) value);
17955 break;
b99bd4ef 17956 }
b99bd4ef 17957
c19d1205
ZW
17958 newimm |= (temp & 0xfffff000);
17959 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17960 break;
b99bd4ef 17961
c19d1205
ZW
17962 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17963 {
17964 unsigned int highpart = 0;
17965 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 17966
c19d1205
ZW
17967 newimm = encode_arm_immediate (value);
17968 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 17969
c19d1205
ZW
17970 /* If the instruction will fail, see if we can fix things up by
17971 changing the opcode. */
17972 if (newimm == (unsigned int) FAIL
17973 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17974 {
17975 /* No ? OK - try using two ADD instructions to generate
17976 the value. */
17977 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 17978
c19d1205
ZW
17979 /* Yes - then make sure that the second instruction is
17980 also an add. */
17981 if (newimm != (unsigned int) FAIL)
17982 newinsn = temp;
17983 /* Still No ? Try using a negated value. */
17984 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17985 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17986 /* Otherwise - give up. */
17987 else
17988 {
17989 as_bad_where (fixP->fx_file, fixP->fx_line,
17990 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17991 (long) value);
17992 break;
17993 }
b99bd4ef 17994
c19d1205
ZW
17995 /* Replace the first operand in the 2nd instruction (which
17996 is the PC) with the destination register. We have
17997 already added in the PC in the first instruction and we
17998 do not want to do it again. */
17999 newinsn &= ~ 0xf0000;
18000 newinsn |= ((newinsn & 0x0f000) << 4);
18001 }
b99bd4ef 18002
c19d1205
ZW
18003 newimm |= (temp & 0xfffff000);
18004 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18005
c19d1205
ZW
18006 highpart |= (newinsn & 0xfffff000);
18007 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18008 }
18009 break;
b99bd4ef 18010
c19d1205 18011 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18012 if (!fixP->fx_done && seg->use_rela_p)
18013 value = 0;
18014
c19d1205
ZW
18015 case BFD_RELOC_ARM_LITERAL:
18016 sign = value >= 0;
b99bd4ef 18017
c19d1205
ZW
18018 if (value < 0)
18019 value = - value;
b99bd4ef 18020
c19d1205 18021 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18022 {
c19d1205
ZW
18023 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18024 as_bad_where (fixP->fx_file, fixP->fx_line,
18025 _("invalid literal constant: pool needs to be closer"));
18026 else
18027 as_bad_where (fixP->fx_file, fixP->fx_line,
18028 _("bad immediate value for offset (%ld)"),
18029 (long) value);
18030 break;
f03698e6
RE
18031 }
18032
c19d1205
ZW
18033 newval = md_chars_to_number (buf, INSN_SIZE);
18034 newval &= 0xff7ff000;
18035 newval |= value | (sign ? INDEX_UP : 0);
18036 md_number_to_chars (buf, newval, INSN_SIZE);
18037 break;
b99bd4ef 18038
c19d1205
ZW
18039 case BFD_RELOC_ARM_OFFSET_IMM8:
18040 case BFD_RELOC_ARM_HWLITERAL:
18041 sign = value >= 0;
b99bd4ef 18042
c19d1205
ZW
18043 if (value < 0)
18044 value = - value;
b99bd4ef 18045
c19d1205 18046 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18047 {
c19d1205
ZW
18048 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18049 as_bad_where (fixP->fx_file, fixP->fx_line,
18050 _("invalid literal constant: pool needs to be closer"));
18051 else
f9d4405b 18052 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18053 (long) value);
18054 break;
b99bd4ef
NC
18055 }
18056
c19d1205
ZW
18057 newval = md_chars_to_number (buf, INSN_SIZE);
18058 newval &= 0xff7ff0f0;
18059 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18060 md_number_to_chars (buf, newval, INSN_SIZE);
18061 break;
b99bd4ef 18062
c19d1205
ZW
18063 case BFD_RELOC_ARM_T32_OFFSET_U8:
18064 if (value < 0 || value > 1020 || value % 4 != 0)
18065 as_bad_where (fixP->fx_file, fixP->fx_line,
18066 _("bad immediate value for offset (%ld)"), (long) value);
18067 value /= 4;
b99bd4ef 18068
c19d1205 18069 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18070 newval |= value;
18071 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18072 break;
b99bd4ef 18073
c19d1205
ZW
18074 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18075 /* This is a complicated relocation used for all varieties of Thumb32
18076 load/store instruction with immediate offset:
18077
18078 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18079 *4, optional writeback(W)
18080 (doubleword load/store)
18081
18082 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18083 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18084 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18085 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18086 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18087
18088 Uppercase letters indicate bits that are already encoded at
18089 this point. Lowercase letters are our problem. For the
18090 second block of instructions, the secondary opcode nybble
18091 (bits 8..11) is present, and bit 23 is zero, even if this is
18092 a PC-relative operation. */
18093 newval = md_chars_to_number (buf, THUMB_SIZE);
18094 newval <<= 16;
18095 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18096
c19d1205 18097 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18098 {
c19d1205
ZW
18099 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18100 if (value >= 0)
18101 newval |= (1 << 23);
18102 else
18103 value = -value;
18104 if (value % 4 != 0)
18105 {
18106 as_bad_where (fixP->fx_file, fixP->fx_line,
18107 _("offset not a multiple of 4"));
18108 break;
18109 }
18110 value /= 4;
216d22bc 18111 if (value > 0xff)
c19d1205
ZW
18112 {
18113 as_bad_where (fixP->fx_file, fixP->fx_line,
18114 _("offset out of range"));
18115 break;
18116 }
18117 newval &= ~0xff;
b99bd4ef 18118 }
c19d1205 18119 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18120 {
c19d1205
ZW
18121 /* PC-relative, 12-bit offset. */
18122 if (value >= 0)
18123 newval |= (1 << 23);
18124 else
18125 value = -value;
216d22bc 18126 if (value > 0xfff)
c19d1205
ZW
18127 {
18128 as_bad_where (fixP->fx_file, fixP->fx_line,
18129 _("offset out of range"));
18130 break;
18131 }
18132 newval &= ~0xfff;
b99bd4ef 18133 }
c19d1205 18134 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18135 {
c19d1205
ZW
18136 /* Writeback: 8-bit, +/- offset. */
18137 if (value >= 0)
18138 newval |= (1 << 9);
18139 else
18140 value = -value;
216d22bc 18141 if (value > 0xff)
c19d1205
ZW
18142 {
18143 as_bad_where (fixP->fx_file, fixP->fx_line,
18144 _("offset out of range"));
18145 break;
18146 }
18147 newval &= ~0xff;
b99bd4ef 18148 }
c19d1205 18149 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18150 {
c19d1205 18151 /* T-instruction: positive 8-bit offset. */
216d22bc 18152 if (value < 0 || value > 0xff)
b99bd4ef 18153 {
c19d1205
ZW
18154 as_bad_where (fixP->fx_file, fixP->fx_line,
18155 _("offset out of range"));
18156 break;
b99bd4ef 18157 }
c19d1205
ZW
18158 newval &= ~0xff;
18159 newval |= value;
b99bd4ef
NC
18160 }
18161 else
b99bd4ef 18162 {
c19d1205
ZW
18163 /* Positive 12-bit or negative 8-bit offset. */
18164 int limit;
18165 if (value >= 0)
b99bd4ef 18166 {
c19d1205
ZW
18167 newval |= (1 << 23);
18168 limit = 0xfff;
18169 }
18170 else
18171 {
18172 value = -value;
18173 limit = 0xff;
18174 }
18175 if (value > limit)
18176 {
18177 as_bad_where (fixP->fx_file, fixP->fx_line,
18178 _("offset out of range"));
18179 break;
b99bd4ef 18180 }
c19d1205 18181 newval &= ~limit;
b99bd4ef 18182 }
b99bd4ef 18183
c19d1205
ZW
18184 newval |= value;
18185 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18186 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18187 break;
404ff6b5 18188
c19d1205
ZW
18189 case BFD_RELOC_ARM_SHIFT_IMM:
18190 newval = md_chars_to_number (buf, INSN_SIZE);
18191 if (((unsigned long) value) > 32
18192 || (value == 32
18193 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18194 {
18195 as_bad_where (fixP->fx_file, fixP->fx_line,
18196 _("shift expression is too large"));
18197 break;
18198 }
404ff6b5 18199
c19d1205
ZW
18200 if (value == 0)
18201 /* Shifts of zero must be done as lsl. */
18202 newval &= ~0x60;
18203 else if (value == 32)
18204 value = 0;
18205 newval &= 0xfffff07f;
18206 newval |= (value & 0x1f) << 7;
18207 md_number_to_chars (buf, newval, INSN_SIZE);
18208 break;
404ff6b5 18209
c19d1205 18210 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18211 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18212 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18213 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18214 /* We claim that this fixup has been processed here,
18215 even if in fact we generate an error because we do
18216 not have a reloc for it, so tc_gen_reloc will reject it. */
18217 fixP->fx_done = 1;
404ff6b5 18218
c19d1205
ZW
18219 if (fixP->fx_addsy
18220 && ! S_IS_DEFINED (fixP->fx_addsy))
18221 {
18222 as_bad_where (fixP->fx_file, fixP->fx_line,
18223 _("undefined symbol %s used as an immediate value"),
18224 S_GET_NAME (fixP->fx_addsy));
18225 break;
18226 }
404ff6b5 18227
c19d1205
ZW
18228 newval = md_chars_to_number (buf, THUMB_SIZE);
18229 newval <<= 16;
18230 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18231
16805f35
PB
18232 newimm = FAIL;
18233 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18234 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18235 {
18236 newimm = encode_thumb32_immediate (value);
18237 if (newimm == (unsigned int) FAIL)
18238 newimm = thumb32_negate_data_op (&newval, value);
18239 }
16805f35
PB
18240 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18241 && newimm == (unsigned int) FAIL)
92e90b6e 18242 {
16805f35
PB
18243 /* Turn add/sum into addw/subw. */
18244 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18245 newval = (newval & 0xfeffffff) | 0x02000000;
18246
e9f89963
PB
18247 /* 12 bit immediate for addw/subw. */
18248 if (value < 0)
18249 {
18250 value = -value;
18251 newval ^= 0x00a00000;
18252 }
92e90b6e
PB
18253 if (value > 0xfff)
18254 newimm = (unsigned int) FAIL;
18255 else
18256 newimm = value;
18257 }
cc8a6dd0 18258
c19d1205 18259 if (newimm == (unsigned int)FAIL)
3631a3c8 18260 {
c19d1205
ZW
18261 as_bad_where (fixP->fx_file, fixP->fx_line,
18262 _("invalid constant (%lx) after fixup"),
18263 (unsigned long) value);
18264 break;
3631a3c8
NC
18265 }
18266
c19d1205
ZW
18267 newval |= (newimm & 0x800) << 15;
18268 newval |= (newimm & 0x700) << 4;
18269 newval |= (newimm & 0x0ff);
cc8a6dd0 18270
c19d1205
ZW
18271 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18272 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18273 break;
a737bd4d 18274
3eb17e6b 18275 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18276 if (((unsigned long) value) > 0xffff)
18277 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18278 _("invalid smc expression"));
2fc8bdac 18279 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18280 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18281 md_number_to_chars (buf, newval, INSN_SIZE);
18282 break;
a737bd4d 18283
c19d1205 18284 case BFD_RELOC_ARM_SWI:
adbaf948 18285 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18286 {
18287 if (((unsigned long) value) > 0xff)
18288 as_bad_where (fixP->fx_file, fixP->fx_line,
18289 _("invalid swi expression"));
2fc8bdac 18290 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18291 newval |= value;
18292 md_number_to_chars (buf, newval, THUMB_SIZE);
18293 }
18294 else
18295 {
18296 if (((unsigned long) value) > 0x00ffffff)
18297 as_bad_where (fixP->fx_file, fixP->fx_line,
18298 _("invalid swi expression"));
2fc8bdac 18299 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18300 newval |= value;
18301 md_number_to_chars (buf, newval, INSN_SIZE);
18302 }
18303 break;
a737bd4d 18304
c19d1205
ZW
18305 case BFD_RELOC_ARM_MULTI:
18306 if (((unsigned long) value) > 0xffff)
18307 as_bad_where (fixP->fx_file, fixP->fx_line,
18308 _("invalid expression in load/store multiple"));
18309 newval = value | md_chars_to_number (buf, INSN_SIZE);
18310 md_number_to_chars (buf, newval, INSN_SIZE);
18311 break;
a737bd4d 18312
c19d1205 18313#ifdef OBJ_ELF
39b41c9c
PB
18314 case BFD_RELOC_ARM_PCREL_CALL:
18315 newval = md_chars_to_number (buf, INSN_SIZE);
18316 if ((newval & 0xf0000000) == 0xf0000000)
18317 temp = 1;
18318 else
18319 temp = 3;
18320 goto arm_branch_common;
18321
18322 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18323 case BFD_RELOC_ARM_PLT32:
c19d1205 18324#endif
39b41c9c
PB
18325 case BFD_RELOC_ARM_PCREL_BRANCH:
18326 temp = 3;
18327 goto arm_branch_common;
a737bd4d 18328
39b41c9c
PB
18329 case BFD_RELOC_ARM_PCREL_BLX:
18330 temp = 1;
18331 arm_branch_common:
c19d1205 18332 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18333 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18334 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18335 also be be clear. */
18336 if (value & temp)
c19d1205 18337 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18338 _("misaligned branch destination"));
18339 if ((value & (offsetT)0xfe000000) != (offsetT)0
18340 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18341 as_bad_where (fixP->fx_file, fixP->fx_line,
18342 _("branch out of range"));
a737bd4d 18343
2fc8bdac 18344 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18345 {
2fc8bdac
ZW
18346 newval = md_chars_to_number (buf, INSN_SIZE);
18347 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18348 /* Set the H bit on BLX instructions. */
18349 if (temp == 1)
18350 {
18351 if (value & 2)
18352 newval |= 0x01000000;
18353 else
18354 newval &= ~0x01000000;
18355 }
2fc8bdac 18356 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18357 }
c19d1205 18358 break;
a737bd4d 18359
25fe350b
MS
18360 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18361 /* CBZ can only branch forward. */
a737bd4d 18362
738755b0
MS
18363 /* Attempts to use CBZ to branch to the next instruction
18364 (which, strictly speaking, are prohibited) will be turned into
18365 no-ops.
18366
18367 FIXME: It may be better to remove the instruction completely and
18368 perform relaxation. */
18369 if (value == -2)
2fc8bdac
ZW
18370 {
18371 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18372 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18373 md_number_to_chars (buf, newval, THUMB_SIZE);
18374 }
738755b0
MS
18375 else
18376 {
18377 if (value & ~0x7e)
18378 as_bad_where (fixP->fx_file, fixP->fx_line,
18379 _("branch out of range"));
18380
18381 if (fixP->fx_done || !seg->use_rela_p)
18382 {
18383 newval = md_chars_to_number (buf, THUMB_SIZE);
18384 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18385 md_number_to_chars (buf, newval, THUMB_SIZE);
18386 }
18387 }
c19d1205 18388 break;
a737bd4d 18389
c19d1205 18390 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18391 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18392 as_bad_where (fixP->fx_file, fixP->fx_line,
18393 _("branch out of range"));
a737bd4d 18394
2fc8bdac
ZW
18395 if (fixP->fx_done || !seg->use_rela_p)
18396 {
18397 newval = md_chars_to_number (buf, THUMB_SIZE);
18398 newval |= (value & 0x1ff) >> 1;
18399 md_number_to_chars (buf, newval, THUMB_SIZE);
18400 }
c19d1205 18401 break;
a737bd4d 18402
c19d1205 18403 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18404 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18405 as_bad_where (fixP->fx_file, fixP->fx_line,
18406 _("branch out of range"));
a737bd4d 18407
2fc8bdac
ZW
18408 if (fixP->fx_done || !seg->use_rela_p)
18409 {
18410 newval = md_chars_to_number (buf, THUMB_SIZE);
18411 newval |= (value & 0xfff) >> 1;
18412 md_number_to_chars (buf, newval, THUMB_SIZE);
18413 }
c19d1205 18414 break;
a737bd4d 18415
c19d1205 18416 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18417 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18418 as_bad_where (fixP->fx_file, fixP->fx_line,
18419 _("conditional branch out of range"));
404ff6b5 18420
2fc8bdac
ZW
18421 if (fixP->fx_done || !seg->use_rela_p)
18422 {
18423 offsetT newval2;
18424 addressT S, J1, J2, lo, hi;
404ff6b5 18425
2fc8bdac
ZW
18426 S = (value & 0x00100000) >> 20;
18427 J2 = (value & 0x00080000) >> 19;
18428 J1 = (value & 0x00040000) >> 18;
18429 hi = (value & 0x0003f000) >> 12;
18430 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18431
2fc8bdac
ZW
18432 newval = md_chars_to_number (buf, THUMB_SIZE);
18433 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18434 newval |= (S << 10) | hi;
18435 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18436 md_number_to_chars (buf, newval, THUMB_SIZE);
18437 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18438 }
c19d1205 18439 break;
6c43fab6 18440
c19d1205
ZW
18441 case BFD_RELOC_THUMB_PCREL_BLX:
18442 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18443 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18444 as_bad_where (fixP->fx_file, fixP->fx_line,
18445 _("branch out of range"));
404ff6b5 18446
2fc8bdac
ZW
18447 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18448 /* For a BLX instruction, make sure that the relocation is rounded up
18449 to a word boundary. This follows the semantics of the instruction
18450 which specifies that bit 1 of the target address will come from bit
18451 1 of the base address. */
18452 value = (value + 1) & ~ 1;
404ff6b5 18453
2fc8bdac 18454 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18455 {
2fc8bdac
ZW
18456 offsetT newval2;
18457
18458 newval = md_chars_to_number (buf, THUMB_SIZE);
18459 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18460 newval |= (value & 0x7fffff) >> 12;
18461 newval2 |= (value & 0xfff) >> 1;
18462 md_number_to_chars (buf, newval, THUMB_SIZE);
18463 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18464 }
c19d1205 18465 break;
404ff6b5 18466
c19d1205 18467 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18468 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18469 as_bad_where (fixP->fx_file, fixP->fx_line,
18470 _("branch out of range"));
6c43fab6 18471
2fc8bdac
ZW
18472 if (fixP->fx_done || !seg->use_rela_p)
18473 {
18474 offsetT newval2;
18475 addressT S, I1, I2, lo, hi;
6c43fab6 18476
2fc8bdac
ZW
18477 S = (value & 0x01000000) >> 24;
18478 I1 = (value & 0x00800000) >> 23;
18479 I2 = (value & 0x00400000) >> 22;
18480 hi = (value & 0x003ff000) >> 12;
18481 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18482
2fc8bdac
ZW
18483 I1 = !(I1 ^ S);
18484 I2 = !(I2 ^ S);
a737bd4d 18485
2fc8bdac
ZW
18486 newval = md_chars_to_number (buf, THUMB_SIZE);
18487 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18488 newval |= (S << 10) | hi;
18489 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18490 md_number_to_chars (buf, newval, THUMB_SIZE);
18491 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18492 }
18493 break;
a737bd4d 18494
2fc8bdac
ZW
18495 case BFD_RELOC_8:
18496 if (fixP->fx_done || !seg->use_rela_p)
18497 md_number_to_chars (buf, value, 1);
c19d1205 18498 break;
a737bd4d 18499
c19d1205 18500 case BFD_RELOC_16:
2fc8bdac 18501 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18502 md_number_to_chars (buf, value, 2);
c19d1205 18503 break;
a737bd4d 18504
c19d1205
ZW
18505#ifdef OBJ_ELF
18506 case BFD_RELOC_ARM_TLS_GD32:
18507 case BFD_RELOC_ARM_TLS_LE32:
18508 case BFD_RELOC_ARM_TLS_IE32:
18509 case BFD_RELOC_ARM_TLS_LDM32:
18510 case BFD_RELOC_ARM_TLS_LDO32:
18511 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18512 /* fall through */
6c43fab6 18513
c19d1205
ZW
18514 case BFD_RELOC_ARM_GOT32:
18515 case BFD_RELOC_ARM_GOTOFF:
18516 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18517 if (fixP->fx_done || !seg->use_rela_p)
18518 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18519 break;
18520#endif
6c43fab6 18521
c19d1205
ZW
18522 case BFD_RELOC_RVA:
18523 case BFD_RELOC_32:
18524 case BFD_RELOC_ARM_TARGET1:
18525 case BFD_RELOC_ARM_ROSEGREL32:
18526 case BFD_RELOC_ARM_SBREL32:
18527 case BFD_RELOC_32_PCREL:
f0927246
NC
18528#ifdef TE_PE
18529 case BFD_RELOC_32_SECREL:
18530#endif
2fc8bdac 18531 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18532#ifdef TE_WINCE
18533 /* For WinCE we only do this for pcrel fixups. */
18534 if (fixP->fx_done || fixP->fx_pcrel)
18535#endif
18536 md_number_to_chars (buf, value, 4);
c19d1205 18537 break;
6c43fab6 18538
c19d1205
ZW
18539#ifdef OBJ_ELF
18540 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18541 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18542 {
18543 newval = md_chars_to_number (buf, 4) & 0x80000000;
18544 if ((value ^ (value >> 1)) & 0x40000000)
18545 {
18546 as_bad_where (fixP->fx_file, fixP->fx_line,
18547 _("rel31 relocation overflow"));
18548 }
18549 newval |= value & 0x7fffffff;
18550 md_number_to_chars (buf, newval, 4);
18551 }
18552 break;
c19d1205 18553#endif
a737bd4d 18554
c19d1205 18555 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18556 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18557 if (value < -1023 || value > 1023 || (value & 3))
18558 as_bad_where (fixP->fx_file, fixP->fx_line,
18559 _("co-processor offset out of range"));
18560 cp_off_common:
18561 sign = value >= 0;
18562 if (value < 0)
18563 value = -value;
8f06b2d8
PB
18564 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18565 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18566 newval = md_chars_to_number (buf, INSN_SIZE);
18567 else
18568 newval = get_thumb32_insn (buf);
18569 newval &= 0xff7fff00;
c19d1205 18570 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18571 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18572 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18573 md_number_to_chars (buf, newval, INSN_SIZE);
18574 else
18575 put_thumb32_insn (buf, newval);
c19d1205 18576 break;
a737bd4d 18577
c19d1205 18578 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18579 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18580 if (value < -255 || value > 255)
18581 as_bad_where (fixP->fx_file, fixP->fx_line,
18582 _("co-processor offset out of range"));
df7849c5 18583 value *= 4;
c19d1205 18584 goto cp_off_common;
6c43fab6 18585
c19d1205
ZW
18586 case BFD_RELOC_ARM_THUMB_OFFSET:
18587 newval = md_chars_to_number (buf, THUMB_SIZE);
18588 /* Exactly what ranges, and where the offset is inserted depends
18589 on the type of instruction, we can establish this from the
18590 top 4 bits. */
18591 switch (newval >> 12)
18592 {
18593 case 4: /* PC load. */
18594 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18595 forced to zero for these loads; md_pcrel_from has already
18596 compensated for this. */
18597 if (value & 3)
18598 as_bad_where (fixP->fx_file, fixP->fx_line,
18599 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18600 (((unsigned long) fixP->fx_frag->fr_address
18601 + (unsigned long) fixP->fx_where) & ~3)
18602 + (unsigned long) value);
a737bd4d 18603
c19d1205
ZW
18604 if (value & ~0x3fc)
18605 as_bad_where (fixP->fx_file, fixP->fx_line,
18606 _("invalid offset, value too big (0x%08lX)"),
18607 (long) value);
a737bd4d 18608
c19d1205
ZW
18609 newval |= value >> 2;
18610 break;
a737bd4d 18611
c19d1205
ZW
18612 case 9: /* SP load/store. */
18613 if (value & ~0x3fc)
18614 as_bad_where (fixP->fx_file, fixP->fx_line,
18615 _("invalid offset, value too big (0x%08lX)"),
18616 (long) value);
18617 newval |= value >> 2;
18618 break;
6c43fab6 18619
c19d1205
ZW
18620 case 6: /* Word load/store. */
18621 if (value & ~0x7c)
18622 as_bad_where (fixP->fx_file, fixP->fx_line,
18623 _("invalid offset, value too big (0x%08lX)"),
18624 (long) value);
18625 newval |= value << 4; /* 6 - 2. */
18626 break;
a737bd4d 18627
c19d1205
ZW
18628 case 7: /* Byte load/store. */
18629 if (value & ~0x1f)
18630 as_bad_where (fixP->fx_file, fixP->fx_line,
18631 _("invalid offset, value too big (0x%08lX)"),
18632 (long) value);
18633 newval |= value << 6;
18634 break;
a737bd4d 18635
c19d1205
ZW
18636 case 8: /* Halfword load/store. */
18637 if (value & ~0x3e)
18638 as_bad_where (fixP->fx_file, fixP->fx_line,
18639 _("invalid offset, value too big (0x%08lX)"),
18640 (long) value);
18641 newval |= value << 5; /* 6 - 1. */
18642 break;
a737bd4d 18643
c19d1205
ZW
18644 default:
18645 as_bad_where (fixP->fx_file, fixP->fx_line,
18646 "Unable to process relocation for thumb opcode: %lx",
18647 (unsigned long) newval);
18648 break;
18649 }
18650 md_number_to_chars (buf, newval, THUMB_SIZE);
18651 break;
a737bd4d 18652
c19d1205
ZW
18653 case BFD_RELOC_ARM_THUMB_ADD:
18654 /* This is a complicated relocation, since we use it for all of
18655 the following immediate relocations:
a737bd4d 18656
c19d1205
ZW
18657 3bit ADD/SUB
18658 8bit ADD/SUB
18659 9bit ADD/SUB SP word-aligned
18660 10bit ADD PC/SP word-aligned
a737bd4d 18661
c19d1205
ZW
18662 The type of instruction being processed is encoded in the
18663 instruction field:
a737bd4d 18664
c19d1205
ZW
18665 0x8000 SUB
18666 0x00F0 Rd
18667 0x000F Rs
18668 */
18669 newval = md_chars_to_number (buf, THUMB_SIZE);
18670 {
18671 int rd = (newval >> 4) & 0xf;
18672 int rs = newval & 0xf;
18673 int subtract = !!(newval & 0x8000);
a737bd4d 18674
c19d1205
ZW
18675 /* Check for HI regs, only very restricted cases allowed:
18676 Adjusting SP, and using PC or SP to get an address. */
18677 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18678 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18679 as_bad_where (fixP->fx_file, fixP->fx_line,
18680 _("invalid Hi register with immediate"));
a737bd4d 18681
c19d1205
ZW
18682 /* If value is negative, choose the opposite instruction. */
18683 if (value < 0)
18684 {
18685 value = -value;
18686 subtract = !subtract;
18687 if (value < 0)
18688 as_bad_where (fixP->fx_file, fixP->fx_line,
18689 _("immediate value out of range"));
18690 }
a737bd4d 18691
c19d1205
ZW
18692 if (rd == REG_SP)
18693 {
18694 if (value & ~0x1fc)
18695 as_bad_where (fixP->fx_file, fixP->fx_line,
18696 _("invalid immediate for stack address calculation"));
18697 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18698 newval |= value >> 2;
18699 }
18700 else if (rs == REG_PC || rs == REG_SP)
18701 {
18702 if (subtract || value & ~0x3fc)
18703 as_bad_where (fixP->fx_file, fixP->fx_line,
18704 _("invalid immediate for address calculation (value = 0x%08lX)"),
18705 (unsigned long) value);
18706 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18707 newval |= rd << 8;
18708 newval |= value >> 2;
18709 }
18710 else if (rs == rd)
18711 {
18712 if (value & ~0xff)
18713 as_bad_where (fixP->fx_file, fixP->fx_line,
18714 _("immediate value out of range"));
18715 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18716 newval |= (rd << 8) | value;
18717 }
18718 else
18719 {
18720 if (value & ~0x7)
18721 as_bad_where (fixP->fx_file, fixP->fx_line,
18722 _("immediate value out of range"));
18723 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18724 newval |= rd | (rs << 3) | (value << 6);
18725 }
18726 }
18727 md_number_to_chars (buf, newval, THUMB_SIZE);
18728 break;
a737bd4d 18729
c19d1205
ZW
18730 case BFD_RELOC_ARM_THUMB_IMM:
18731 newval = md_chars_to_number (buf, THUMB_SIZE);
18732 if (value < 0 || value > 255)
18733 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 18734 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
18735 (long) value);
18736 newval |= value;
18737 md_number_to_chars (buf, newval, THUMB_SIZE);
18738 break;
a737bd4d 18739
c19d1205
ZW
18740 case BFD_RELOC_ARM_THUMB_SHIFT:
18741 /* 5bit shift value (0..32). LSL cannot take 32. */
18742 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18743 temp = newval & 0xf800;
18744 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18745 as_bad_where (fixP->fx_file, fixP->fx_line,
18746 _("invalid shift value: %ld"), (long) value);
18747 /* Shifts of zero must be encoded as LSL. */
18748 if (value == 0)
18749 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18750 /* Shifts of 32 are encoded as zero. */
18751 else if (value == 32)
18752 value = 0;
18753 newval |= value << 6;
18754 md_number_to_chars (buf, newval, THUMB_SIZE);
18755 break;
a737bd4d 18756
c19d1205
ZW
18757 case BFD_RELOC_VTABLE_INHERIT:
18758 case BFD_RELOC_VTABLE_ENTRY:
18759 fixP->fx_done = 0;
18760 return;
6c43fab6 18761
b6895b4f
PB
18762 case BFD_RELOC_ARM_MOVW:
18763 case BFD_RELOC_ARM_MOVT:
18764 case BFD_RELOC_ARM_THUMB_MOVW:
18765 case BFD_RELOC_ARM_THUMB_MOVT:
18766 if (fixP->fx_done || !seg->use_rela_p)
18767 {
18768 /* REL format relocations are limited to a 16-bit addend. */
18769 if (!fixP->fx_done)
18770 {
18771 if (value < -0x1000 || value > 0xffff)
18772 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 18773 _("offset out of range"));
b6895b4f
PB
18774 }
18775 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18776 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18777 {
18778 value >>= 16;
18779 }
18780
18781 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18782 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18783 {
18784 newval = get_thumb32_insn (buf);
18785 newval &= 0xfbf08f00;
18786 newval |= (value & 0xf000) << 4;
18787 newval |= (value & 0x0800) << 15;
18788 newval |= (value & 0x0700) << 4;
18789 newval |= (value & 0x00ff);
18790 put_thumb32_insn (buf, newval);
18791 }
18792 else
18793 {
18794 newval = md_chars_to_number (buf, 4);
18795 newval &= 0xfff0f000;
18796 newval |= value & 0x0fff;
18797 newval |= (value & 0xf000) << 4;
18798 md_number_to_chars (buf, newval, 4);
18799 }
18800 }
18801 return;
18802
4962c51a
MS
18803 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18804 case BFD_RELOC_ARM_ALU_PC_G0:
18805 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18806 case BFD_RELOC_ARM_ALU_PC_G1:
18807 case BFD_RELOC_ARM_ALU_PC_G2:
18808 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18809 case BFD_RELOC_ARM_ALU_SB_G0:
18810 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18811 case BFD_RELOC_ARM_ALU_SB_G1:
18812 case BFD_RELOC_ARM_ALU_SB_G2:
18813 assert (!fixP->fx_done);
18814 if (!seg->use_rela_p)
18815 {
18816 bfd_vma insn;
18817 bfd_vma encoded_addend;
18818 bfd_vma addend_abs = abs (value);
18819
18820 /* Check that the absolute value of the addend can be
18821 expressed as an 8-bit constant plus a rotation. */
18822 encoded_addend = encode_arm_immediate (addend_abs);
18823 if (encoded_addend == (unsigned int) FAIL)
18824 as_bad_where (fixP->fx_file, fixP->fx_line,
18825 _("the offset 0x%08lX is not representable"),
495bde8e 18826 (unsigned long) addend_abs);
4962c51a
MS
18827
18828 /* Extract the instruction. */
18829 insn = md_chars_to_number (buf, INSN_SIZE);
18830
18831 /* If the addend is positive, use an ADD instruction.
18832 Otherwise use a SUB. Take care not to destroy the S bit. */
18833 insn &= 0xff1fffff;
18834 if (value < 0)
18835 insn |= 1 << 22;
18836 else
18837 insn |= 1 << 23;
18838
18839 /* Place the encoded addend into the first 12 bits of the
18840 instruction. */
18841 insn &= 0xfffff000;
18842 insn |= encoded_addend;
5f4273c7
NC
18843
18844 /* Update the instruction. */
4962c51a
MS
18845 md_number_to_chars (buf, insn, INSN_SIZE);
18846 }
18847 break;
18848
18849 case BFD_RELOC_ARM_LDR_PC_G0:
18850 case BFD_RELOC_ARM_LDR_PC_G1:
18851 case BFD_RELOC_ARM_LDR_PC_G2:
18852 case BFD_RELOC_ARM_LDR_SB_G0:
18853 case BFD_RELOC_ARM_LDR_SB_G1:
18854 case BFD_RELOC_ARM_LDR_SB_G2:
18855 assert (!fixP->fx_done);
18856 if (!seg->use_rela_p)
18857 {
18858 bfd_vma insn;
18859 bfd_vma addend_abs = abs (value);
18860
18861 /* Check that the absolute value of the addend can be
18862 encoded in 12 bits. */
18863 if (addend_abs >= 0x1000)
18864 as_bad_where (fixP->fx_file, fixP->fx_line,
18865 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 18866 (unsigned long) addend_abs);
4962c51a
MS
18867
18868 /* Extract the instruction. */
18869 insn = md_chars_to_number (buf, INSN_SIZE);
18870
18871 /* If the addend is negative, clear bit 23 of the instruction.
18872 Otherwise set it. */
18873 if (value < 0)
18874 insn &= ~(1 << 23);
18875 else
18876 insn |= 1 << 23;
18877
18878 /* Place the absolute value of the addend into the first 12 bits
18879 of the instruction. */
18880 insn &= 0xfffff000;
18881 insn |= addend_abs;
5f4273c7
NC
18882
18883 /* Update the instruction. */
4962c51a
MS
18884 md_number_to_chars (buf, insn, INSN_SIZE);
18885 }
18886 break;
18887
18888 case BFD_RELOC_ARM_LDRS_PC_G0:
18889 case BFD_RELOC_ARM_LDRS_PC_G1:
18890 case BFD_RELOC_ARM_LDRS_PC_G2:
18891 case BFD_RELOC_ARM_LDRS_SB_G0:
18892 case BFD_RELOC_ARM_LDRS_SB_G1:
18893 case BFD_RELOC_ARM_LDRS_SB_G2:
18894 assert (!fixP->fx_done);
18895 if (!seg->use_rela_p)
18896 {
18897 bfd_vma insn;
18898 bfd_vma addend_abs = abs (value);
18899
18900 /* Check that the absolute value of the addend can be
18901 encoded in 8 bits. */
18902 if (addend_abs >= 0x100)
18903 as_bad_where (fixP->fx_file, fixP->fx_line,
18904 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 18905 (unsigned long) addend_abs);
4962c51a
MS
18906
18907 /* Extract the instruction. */
18908 insn = md_chars_to_number (buf, INSN_SIZE);
18909
18910 /* If the addend is negative, clear bit 23 of the instruction.
18911 Otherwise set it. */
18912 if (value < 0)
18913 insn &= ~(1 << 23);
18914 else
18915 insn |= 1 << 23;
18916
18917 /* Place the first four bits of the absolute value of the addend
18918 into the first 4 bits of the instruction, and the remaining
18919 four into bits 8 .. 11. */
18920 insn &= 0xfffff0f0;
18921 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
18922
18923 /* Update the instruction. */
4962c51a
MS
18924 md_number_to_chars (buf, insn, INSN_SIZE);
18925 }
18926 break;
18927
18928 case BFD_RELOC_ARM_LDC_PC_G0:
18929 case BFD_RELOC_ARM_LDC_PC_G1:
18930 case BFD_RELOC_ARM_LDC_PC_G2:
18931 case BFD_RELOC_ARM_LDC_SB_G0:
18932 case BFD_RELOC_ARM_LDC_SB_G1:
18933 case BFD_RELOC_ARM_LDC_SB_G2:
18934 assert (!fixP->fx_done);
18935 if (!seg->use_rela_p)
18936 {
18937 bfd_vma insn;
18938 bfd_vma addend_abs = abs (value);
18939
18940 /* Check that the absolute value of the addend is a multiple of
18941 four and, when divided by four, fits in 8 bits. */
18942 if (addend_abs & 0x3)
18943 as_bad_where (fixP->fx_file, fixP->fx_line,
18944 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 18945 (unsigned long) addend_abs);
4962c51a
MS
18946
18947 if ((addend_abs >> 2) > 0xff)
18948 as_bad_where (fixP->fx_file, fixP->fx_line,
18949 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 18950 (unsigned long) addend_abs);
4962c51a
MS
18951
18952 /* Extract the instruction. */
18953 insn = md_chars_to_number (buf, INSN_SIZE);
18954
18955 /* If the addend is negative, clear bit 23 of the instruction.
18956 Otherwise set it. */
18957 if (value < 0)
18958 insn &= ~(1 << 23);
18959 else
18960 insn |= 1 << 23;
18961
18962 /* Place the addend (divided by four) into the first eight
18963 bits of the instruction. */
18964 insn &= 0xfffffff0;
18965 insn |= addend_abs >> 2;
5f4273c7
NC
18966
18967 /* Update the instruction. */
4962c51a
MS
18968 md_number_to_chars (buf, insn, INSN_SIZE);
18969 }
18970 break;
18971
c19d1205
ZW
18972 case BFD_RELOC_UNUSED:
18973 default:
18974 as_bad_where (fixP->fx_file, fixP->fx_line,
18975 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18976 }
6c43fab6
RE
18977}
18978
c19d1205
ZW
18979/* Translate internal representation of relocation info to BFD target
18980 format. */
a737bd4d 18981
c19d1205 18982arelent *
00a97672 18983tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 18984{
c19d1205
ZW
18985 arelent * reloc;
18986 bfd_reloc_code_real_type code;
a737bd4d 18987
c19d1205 18988 reloc = xmalloc (sizeof (arelent));
a737bd4d 18989
c19d1205
ZW
18990 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18991 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18992 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 18993
2fc8bdac 18994 if (fixp->fx_pcrel)
00a97672
RS
18995 {
18996 if (section->use_rela_p)
18997 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18998 else
18999 fixp->fx_offset = reloc->address;
19000 }
c19d1205 19001 reloc->addend = fixp->fx_offset;
a737bd4d 19002
c19d1205 19003 switch (fixp->fx_r_type)
a737bd4d 19004 {
c19d1205
ZW
19005 case BFD_RELOC_8:
19006 if (fixp->fx_pcrel)
19007 {
19008 code = BFD_RELOC_8_PCREL;
19009 break;
19010 }
a737bd4d 19011
c19d1205
ZW
19012 case BFD_RELOC_16:
19013 if (fixp->fx_pcrel)
19014 {
19015 code = BFD_RELOC_16_PCREL;
19016 break;
19017 }
6c43fab6 19018
c19d1205
ZW
19019 case BFD_RELOC_32:
19020 if (fixp->fx_pcrel)
19021 {
19022 code = BFD_RELOC_32_PCREL;
19023 break;
19024 }
a737bd4d 19025
b6895b4f
PB
19026 case BFD_RELOC_ARM_MOVW:
19027 if (fixp->fx_pcrel)
19028 {
19029 code = BFD_RELOC_ARM_MOVW_PCREL;
19030 break;
19031 }
19032
19033 case BFD_RELOC_ARM_MOVT:
19034 if (fixp->fx_pcrel)
19035 {
19036 code = BFD_RELOC_ARM_MOVT_PCREL;
19037 break;
19038 }
19039
19040 case BFD_RELOC_ARM_THUMB_MOVW:
19041 if (fixp->fx_pcrel)
19042 {
19043 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19044 break;
19045 }
19046
19047 case BFD_RELOC_ARM_THUMB_MOVT:
19048 if (fixp->fx_pcrel)
19049 {
19050 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19051 break;
19052 }
19053
c19d1205
ZW
19054 case BFD_RELOC_NONE:
19055 case BFD_RELOC_ARM_PCREL_BRANCH:
19056 case BFD_RELOC_ARM_PCREL_BLX:
19057 case BFD_RELOC_RVA:
19058 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19059 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19060 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19061 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19062 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19063 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19064 case BFD_RELOC_THUMB_PCREL_BLX:
19065 case BFD_RELOC_VTABLE_ENTRY:
19066 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19067#ifdef TE_PE
19068 case BFD_RELOC_32_SECREL:
19069#endif
c19d1205
ZW
19070 code = fixp->fx_r_type;
19071 break;
a737bd4d 19072
c19d1205
ZW
19073 case BFD_RELOC_ARM_LITERAL:
19074 case BFD_RELOC_ARM_HWLITERAL:
19075 /* If this is called then the a literal has
19076 been referenced across a section boundary. */
19077 as_bad_where (fixp->fx_file, fixp->fx_line,
19078 _("literal referenced across section boundary"));
19079 return NULL;
a737bd4d 19080
c19d1205
ZW
19081#ifdef OBJ_ELF
19082 case BFD_RELOC_ARM_GOT32:
19083 case BFD_RELOC_ARM_GOTOFF:
19084 case BFD_RELOC_ARM_PLT32:
19085 case BFD_RELOC_ARM_TARGET1:
19086 case BFD_RELOC_ARM_ROSEGREL32:
19087 case BFD_RELOC_ARM_SBREL32:
19088 case BFD_RELOC_ARM_PREL31:
19089 case BFD_RELOC_ARM_TARGET2:
19090 case BFD_RELOC_ARM_TLS_LE32:
19091 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19092 case BFD_RELOC_ARM_PCREL_CALL:
19093 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19094 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19095 case BFD_RELOC_ARM_ALU_PC_G0:
19096 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19097 case BFD_RELOC_ARM_ALU_PC_G1:
19098 case BFD_RELOC_ARM_ALU_PC_G2:
19099 case BFD_RELOC_ARM_LDR_PC_G0:
19100 case BFD_RELOC_ARM_LDR_PC_G1:
19101 case BFD_RELOC_ARM_LDR_PC_G2:
19102 case BFD_RELOC_ARM_LDRS_PC_G0:
19103 case BFD_RELOC_ARM_LDRS_PC_G1:
19104 case BFD_RELOC_ARM_LDRS_PC_G2:
19105 case BFD_RELOC_ARM_LDC_PC_G0:
19106 case BFD_RELOC_ARM_LDC_PC_G1:
19107 case BFD_RELOC_ARM_LDC_PC_G2:
19108 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19109 case BFD_RELOC_ARM_ALU_SB_G0:
19110 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19111 case BFD_RELOC_ARM_ALU_SB_G1:
19112 case BFD_RELOC_ARM_ALU_SB_G2:
19113 case BFD_RELOC_ARM_LDR_SB_G0:
19114 case BFD_RELOC_ARM_LDR_SB_G1:
19115 case BFD_RELOC_ARM_LDR_SB_G2:
19116 case BFD_RELOC_ARM_LDRS_SB_G0:
19117 case BFD_RELOC_ARM_LDRS_SB_G1:
19118 case BFD_RELOC_ARM_LDRS_SB_G2:
19119 case BFD_RELOC_ARM_LDC_SB_G0:
19120 case BFD_RELOC_ARM_LDC_SB_G1:
19121 case BFD_RELOC_ARM_LDC_SB_G2:
c19d1205
ZW
19122 code = fixp->fx_r_type;
19123 break;
a737bd4d 19124
c19d1205
ZW
19125 case BFD_RELOC_ARM_TLS_GD32:
19126 case BFD_RELOC_ARM_TLS_IE32:
19127 case BFD_RELOC_ARM_TLS_LDM32:
19128 /* BFD will include the symbol's address in the addend.
19129 But we don't want that, so subtract it out again here. */
19130 if (!S_IS_COMMON (fixp->fx_addsy))
19131 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19132 code = fixp->fx_r_type;
19133 break;
19134#endif
a737bd4d 19135
c19d1205
ZW
19136 case BFD_RELOC_ARM_IMMEDIATE:
19137 as_bad_where (fixp->fx_file, fixp->fx_line,
19138 _("internal relocation (type: IMMEDIATE) not fixed up"));
19139 return NULL;
a737bd4d 19140
c19d1205
ZW
19141 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19142 as_bad_where (fixp->fx_file, fixp->fx_line,
19143 _("ADRL used for a symbol not defined in the same file"));
19144 return NULL;
a737bd4d 19145
c19d1205 19146 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19147 if (section->use_rela_p)
19148 {
19149 code = fixp->fx_r_type;
19150 break;
19151 }
19152
c19d1205
ZW
19153 if (fixp->fx_addsy != NULL
19154 && !S_IS_DEFINED (fixp->fx_addsy)
19155 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19156 {
c19d1205
ZW
19157 as_bad_where (fixp->fx_file, fixp->fx_line,
19158 _("undefined local label `%s'"),
19159 S_GET_NAME (fixp->fx_addsy));
19160 return NULL;
a737bd4d
NC
19161 }
19162
c19d1205
ZW
19163 as_bad_where (fixp->fx_file, fixp->fx_line,
19164 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19165 return NULL;
a737bd4d 19166
c19d1205
ZW
19167 default:
19168 {
19169 char * type;
6c43fab6 19170
c19d1205
ZW
19171 switch (fixp->fx_r_type)
19172 {
19173 case BFD_RELOC_NONE: type = "NONE"; break;
19174 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19175 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19176 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19177 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19178 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19179 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19180 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19181 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19182 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19183 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19184 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19185 default: type = _("<unknown>"); break;
19186 }
19187 as_bad_where (fixp->fx_file, fixp->fx_line,
19188 _("cannot represent %s relocation in this object file format"),
19189 type);
19190 return NULL;
19191 }
a737bd4d 19192 }
6c43fab6 19193
c19d1205
ZW
19194#ifdef OBJ_ELF
19195 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19196 && GOT_symbol
19197 && fixp->fx_addsy == GOT_symbol)
19198 {
19199 code = BFD_RELOC_ARM_GOTPC;
19200 reloc->addend = fixp->fx_offset = reloc->address;
19201 }
19202#endif
6c43fab6 19203
c19d1205 19204 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19205
c19d1205
ZW
19206 if (reloc->howto == NULL)
19207 {
19208 as_bad_where (fixp->fx_file, fixp->fx_line,
19209 _("cannot represent %s relocation in this object file format"),
19210 bfd_get_reloc_code_name (code));
19211 return NULL;
19212 }
6c43fab6 19213
c19d1205
ZW
19214 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19215 vtable entry to be used in the relocation's section offset. */
19216 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19217 reloc->address = fixp->fx_offset;
6c43fab6 19218
c19d1205 19219 return reloc;
6c43fab6
RE
19220}
19221
c19d1205 19222/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19223
c19d1205
ZW
19224void
19225cons_fix_new_arm (fragS * frag,
19226 int where,
19227 int size,
19228 expressionS * exp)
6c43fab6 19229{
c19d1205
ZW
19230 bfd_reloc_code_real_type type;
19231 int pcrel = 0;
6c43fab6 19232
c19d1205
ZW
19233 /* Pick a reloc.
19234 FIXME: @@ Should look at CPU word size. */
19235 switch (size)
19236 {
19237 case 1:
19238 type = BFD_RELOC_8;
19239 break;
19240 case 2:
19241 type = BFD_RELOC_16;
19242 break;
19243 case 4:
19244 default:
19245 type = BFD_RELOC_32;
19246 break;
19247 case 8:
19248 type = BFD_RELOC_64;
19249 break;
19250 }
6c43fab6 19251
f0927246
NC
19252#ifdef TE_PE
19253 if (exp->X_op == O_secrel)
19254 {
19255 exp->X_op = O_symbol;
19256 type = BFD_RELOC_32_SECREL;
19257 }
19258#endif
19259
c19d1205
ZW
19260 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19261}
6c43fab6 19262
c19d1205
ZW
19263#if defined OBJ_COFF || defined OBJ_ELF
19264void
19265arm_validate_fix (fixS * fixP)
6c43fab6 19266{
c19d1205
ZW
19267 /* If the destination of the branch is a defined symbol which does not have
19268 the THUMB_FUNC attribute, then we must be calling a function which has
19269 the (interfacearm) attribute. We look for the Thumb entry point to that
19270 function and change the branch to refer to that function instead. */
19271 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19272 && fixP->fx_addsy != NULL
19273 && S_IS_DEFINED (fixP->fx_addsy)
19274 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19275 {
c19d1205 19276 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19277 }
c19d1205
ZW
19278}
19279#endif
6c43fab6 19280
c19d1205
ZW
19281int
19282arm_force_relocation (struct fix * fixp)
19283{
19284#if defined (OBJ_COFF) && defined (TE_PE)
19285 if (fixp->fx_r_type == BFD_RELOC_RVA)
19286 return 1;
19287#endif
6c43fab6 19288
c19d1205
ZW
19289 /* Resolve these relocations even if the symbol is extern or weak. */
19290 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19291 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19292 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19293 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19294 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19295 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19296 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19297 return 0;
a737bd4d 19298
4962c51a
MS
19299 /* Always leave these relocations for the linker. */
19300 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19301 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19302 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19303 return 1;
19304
f0291e4c
PB
19305 /* Always generate relocations against function symbols. */
19306 if (fixp->fx_r_type == BFD_RELOC_32
19307 && fixp->fx_addsy
19308 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19309 return 1;
19310
c19d1205 19311 return generic_force_reloc (fixp);
404ff6b5
AH
19312}
19313
0ffdc86c 19314#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19315/* Relocations against function names must be left unadjusted,
19316 so that the linker can use this information to generate interworking
19317 stubs. The MIPS version of this function
c19d1205
ZW
19318 also prevents relocations that are mips-16 specific, but I do not
19319 know why it does this.
404ff6b5 19320
c19d1205
ZW
19321 FIXME:
19322 There is one other problem that ought to be addressed here, but
19323 which currently is not: Taking the address of a label (rather
19324 than a function) and then later jumping to that address. Such
19325 addresses also ought to have their bottom bit set (assuming that
19326 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19327
c19d1205
ZW
19328bfd_boolean
19329arm_fix_adjustable (fixS * fixP)
404ff6b5 19330{
c19d1205
ZW
19331 if (fixP->fx_addsy == NULL)
19332 return 1;
404ff6b5 19333
e28387c3
PB
19334 /* Preserve relocations against symbols with function type. */
19335 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19336 return 0;
19337
c19d1205
ZW
19338 if (THUMB_IS_FUNC (fixP->fx_addsy)
19339 && fixP->fx_subsy == NULL)
19340 return 0;
a737bd4d 19341
c19d1205
ZW
19342 /* We need the symbol name for the VTABLE entries. */
19343 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19344 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19345 return 0;
404ff6b5 19346
c19d1205
ZW
19347 /* Don't allow symbols to be discarded on GOT related relocs. */
19348 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19349 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19350 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19351 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19352 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19353 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19354 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19355 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19356 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19357 return 0;
a737bd4d 19358
4962c51a
MS
19359 /* Similarly for group relocations. */
19360 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19361 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19362 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19363 return 0;
19364
c19d1205 19365 return 1;
a737bd4d 19366}
0ffdc86c
NC
19367#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19368
19369#ifdef OBJ_ELF
404ff6b5 19370
c19d1205
ZW
19371const char *
19372elf32_arm_target_format (void)
404ff6b5 19373{
c19d1205
ZW
19374#ifdef TE_SYMBIAN
19375 return (target_big_endian
19376 ? "elf32-bigarm-symbian"
19377 : "elf32-littlearm-symbian");
19378#elif defined (TE_VXWORKS)
19379 return (target_big_endian
19380 ? "elf32-bigarm-vxworks"
19381 : "elf32-littlearm-vxworks");
19382#else
19383 if (target_big_endian)
19384 return "elf32-bigarm";
19385 else
19386 return "elf32-littlearm";
19387#endif
404ff6b5
AH
19388}
19389
c19d1205
ZW
19390void
19391armelf_frob_symbol (symbolS * symp,
19392 int * puntp)
404ff6b5 19393{
c19d1205
ZW
19394 elf_frob_symbol (symp, puntp);
19395}
19396#endif
404ff6b5 19397
c19d1205 19398/* MD interface: Finalization. */
a737bd4d 19399
c19d1205
ZW
19400/* A good place to do this, although this was probably not intended
19401 for this kind of use. We need to dump the literal pool before
19402 references are made to a null symbol pointer. */
a737bd4d 19403
c19d1205
ZW
19404void
19405arm_cleanup (void)
19406{
19407 literal_pool * pool;
a737bd4d 19408
c19d1205
ZW
19409 for (pool = list_of_pools; pool; pool = pool->next)
19410 {
5f4273c7 19411 /* Put it at the end of the relevant section. */
c19d1205
ZW
19412 subseg_set (pool->section, pool->sub_section);
19413#ifdef OBJ_ELF
19414 arm_elf_change_section ();
19415#endif
19416 s_ltorg (0);
19417 }
404ff6b5
AH
19418}
19419
c19d1205
ZW
19420/* Adjust the symbol table. This marks Thumb symbols as distinct from
19421 ARM ones. */
404ff6b5 19422
c19d1205
ZW
19423void
19424arm_adjust_symtab (void)
404ff6b5 19425{
c19d1205
ZW
19426#ifdef OBJ_COFF
19427 symbolS * sym;
404ff6b5 19428
c19d1205
ZW
19429 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19430 {
19431 if (ARM_IS_THUMB (sym))
19432 {
19433 if (THUMB_IS_FUNC (sym))
19434 {
19435 /* Mark the symbol as a Thumb function. */
19436 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19437 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19438 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19439
c19d1205
ZW
19440 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19441 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19442 else
19443 as_bad (_("%s: unexpected function type: %d"),
19444 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19445 }
19446 else switch (S_GET_STORAGE_CLASS (sym))
19447 {
19448 case C_EXT:
19449 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19450 break;
19451 case C_STAT:
19452 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19453 break;
19454 case C_LABEL:
19455 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19456 break;
19457 default:
19458 /* Do nothing. */
19459 break;
19460 }
19461 }
a737bd4d 19462
c19d1205
ZW
19463 if (ARM_IS_INTERWORK (sym))
19464 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19465 }
c19d1205
ZW
19466#endif
19467#ifdef OBJ_ELF
19468 symbolS * sym;
19469 char bind;
404ff6b5 19470
c19d1205 19471 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19472 {
c19d1205
ZW
19473 if (ARM_IS_THUMB (sym))
19474 {
19475 elf_symbol_type * elf_sym;
404ff6b5 19476
c19d1205
ZW
19477 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19478 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19479
b0796911
PB
19480 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19481 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19482 {
19483 /* If it's a .thumb_func, declare it as so,
19484 otherwise tag label as .code 16. */
19485 if (THUMB_IS_FUNC (sym))
19486 elf_sym->internal_elf_sym.st_info =
19487 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19488 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19489 elf_sym->internal_elf_sym.st_info =
19490 ELF_ST_INFO (bind, STT_ARM_16BIT);
19491 }
19492 }
19493 }
19494#endif
404ff6b5
AH
19495}
19496
c19d1205 19497/* MD interface: Initialization. */
404ff6b5 19498
a737bd4d 19499static void
c19d1205 19500set_constant_flonums (void)
a737bd4d 19501{
c19d1205 19502 int i;
404ff6b5 19503
c19d1205
ZW
19504 for (i = 0; i < NUM_FLOAT_VALS; i++)
19505 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19506 abort ();
a737bd4d 19507}
404ff6b5 19508
3e9e4fcf
JB
19509/* Auto-select Thumb mode if it's the only available instruction set for the
19510 given architecture. */
19511
19512static void
19513autoselect_thumb_from_cpu_variant (void)
19514{
19515 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19516 opcode_select (16);
19517}
19518
c19d1205
ZW
19519void
19520md_begin (void)
a737bd4d 19521{
c19d1205
ZW
19522 unsigned mach;
19523 unsigned int i;
404ff6b5 19524
c19d1205
ZW
19525 if ( (arm_ops_hsh = hash_new ()) == NULL
19526 || (arm_cond_hsh = hash_new ()) == NULL
19527 || (arm_shift_hsh = hash_new ()) == NULL
19528 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19529 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19530 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19531 || (arm_reloc_hsh = hash_new ()) == NULL
19532 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19533 as_fatal (_("virtual memory exhausted"));
19534
19535 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19536 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19537 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19538 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19539 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19540 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19541 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19542 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19543 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19544 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19545 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19546 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19547 for (i = 0;
19548 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19549 i++)
19550 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19551 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19552#ifdef OBJ_ELF
19553 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19554 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19555#endif
19556
19557 set_constant_flonums ();
404ff6b5 19558
c19d1205
ZW
19559 /* Set the cpu variant based on the command-line options. We prefer
19560 -mcpu= over -march= if both are set (as for GCC); and we prefer
19561 -mfpu= over any other way of setting the floating point unit.
19562 Use of legacy options with new options are faulted. */
e74cfd16 19563 if (legacy_cpu)
404ff6b5 19564 {
e74cfd16 19565 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19566 as_bad (_("use of old and new-style options to set CPU type"));
19567
19568 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19569 }
e74cfd16 19570 else if (!mcpu_cpu_opt)
c19d1205 19571 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19572
e74cfd16 19573 if (legacy_fpu)
c19d1205 19574 {
e74cfd16 19575 if (mfpu_opt)
c19d1205 19576 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19577
19578 mfpu_opt = legacy_fpu;
19579 }
e74cfd16 19580 else if (!mfpu_opt)
03b1477f 19581 {
c19d1205 19582#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19583 /* Some environments specify a default FPU. If they don't, infer it
19584 from the processor. */
e74cfd16 19585 if (mcpu_fpu_opt)
03b1477f
RE
19586 mfpu_opt = mcpu_fpu_opt;
19587 else
19588 mfpu_opt = march_fpu_opt;
39c2da32 19589#else
e74cfd16 19590 mfpu_opt = &fpu_default;
39c2da32 19591#endif
03b1477f
RE
19592 }
19593
e74cfd16 19594 if (!mfpu_opt)
03b1477f 19595 {
493cb6ef 19596 if (mcpu_cpu_opt != NULL)
e74cfd16 19597 mfpu_opt = &fpu_default;
493cb6ef 19598 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19599 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19600 else
e74cfd16 19601 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19602 }
19603
ee065d83 19604#ifdef CPU_DEFAULT
e74cfd16 19605 if (!mcpu_cpu_opt)
ee065d83 19606 {
e74cfd16
PB
19607 mcpu_cpu_opt = &cpu_default;
19608 selected_cpu = cpu_default;
ee065d83 19609 }
e74cfd16
PB
19610#else
19611 if (mcpu_cpu_opt)
19612 selected_cpu = *mcpu_cpu_opt;
ee065d83 19613 else
e74cfd16 19614 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19615#endif
03b1477f 19616
e74cfd16 19617 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19618
3e9e4fcf
JB
19619 autoselect_thumb_from_cpu_variant ();
19620
e74cfd16 19621 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19622
f17c130b 19623#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19624 {
7cc69913
NC
19625 unsigned int flags = 0;
19626
19627#if defined OBJ_ELF
19628 flags = meabi_flags;
d507cf36
PB
19629
19630 switch (meabi_flags)
33a392fb 19631 {
d507cf36 19632 case EF_ARM_EABI_UNKNOWN:
7cc69913 19633#endif
d507cf36
PB
19634 /* Set the flags in the private structure. */
19635 if (uses_apcs_26) flags |= F_APCS26;
19636 if (support_interwork) flags |= F_INTERWORK;
19637 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19638 if (pic_code) flags |= F_PIC;
e74cfd16 19639 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19640 flags |= F_SOFT_FLOAT;
19641
d507cf36
PB
19642 switch (mfloat_abi_opt)
19643 {
19644 case ARM_FLOAT_ABI_SOFT:
19645 case ARM_FLOAT_ABI_SOFTFP:
19646 flags |= F_SOFT_FLOAT;
19647 break;
33a392fb 19648
d507cf36
PB
19649 case ARM_FLOAT_ABI_HARD:
19650 if (flags & F_SOFT_FLOAT)
19651 as_bad (_("hard-float conflicts with specified fpu"));
19652 break;
19653 }
03b1477f 19654
e74cfd16
PB
19655 /* Using pure-endian doubles (even if soft-float). */
19656 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19657 flags |= F_VFP_FLOAT;
f17c130b 19658
fde78edd 19659#if defined OBJ_ELF
e74cfd16 19660 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19661 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19662 break;
19663
8cb51566 19664 case EF_ARM_EABI_VER4:
3a4a14e9 19665 case EF_ARM_EABI_VER5:
c19d1205 19666 /* No additional flags to set. */
d507cf36
PB
19667 break;
19668
19669 default:
19670 abort ();
19671 }
7cc69913 19672#endif
b99bd4ef
NC
19673 bfd_set_private_flags (stdoutput, flags);
19674
19675 /* We have run out flags in the COFF header to encode the
19676 status of ATPCS support, so instead we create a dummy,
c19d1205 19677 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19678 if (atpcs)
19679 {
19680 asection * sec;
19681
19682 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19683
19684 if (sec != NULL)
19685 {
19686 bfd_set_section_flags
19687 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19688 bfd_set_section_size (stdoutput, sec, 0);
19689 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19690 }
19691 }
7cc69913 19692 }
f17c130b 19693#endif
b99bd4ef
NC
19694
19695 /* Record the CPU type as well. */
2d447fca
JM
19696 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19697 mach = bfd_mach_arm_iWMMXt2;
19698 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19699 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19700 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19701 mach = bfd_mach_arm_XScale;
e74cfd16 19702 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19703 mach = bfd_mach_arm_ep9312;
e74cfd16 19704 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19705 mach = bfd_mach_arm_5TE;
e74cfd16 19706 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19707 {
e74cfd16 19708 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19709 mach = bfd_mach_arm_5T;
19710 else
19711 mach = bfd_mach_arm_5;
19712 }
e74cfd16 19713 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19714 {
e74cfd16 19715 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19716 mach = bfd_mach_arm_4T;
19717 else
19718 mach = bfd_mach_arm_4;
19719 }
e74cfd16 19720 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19721 mach = bfd_mach_arm_3M;
e74cfd16
PB
19722 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19723 mach = bfd_mach_arm_3;
19724 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19725 mach = bfd_mach_arm_2a;
19726 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19727 mach = bfd_mach_arm_2;
19728 else
19729 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19730
19731 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19732}
19733
c19d1205 19734/* Command line processing. */
b99bd4ef 19735
c19d1205
ZW
19736/* md_parse_option
19737 Invocation line includes a switch not recognized by the base assembler.
19738 See if it's a processor-specific option.
b99bd4ef 19739
c19d1205
ZW
19740 This routine is somewhat complicated by the need for backwards
19741 compatibility (since older releases of gcc can't be changed).
19742 The new options try to make the interface as compatible as
19743 possible with GCC.
b99bd4ef 19744
c19d1205 19745 New options (supported) are:
b99bd4ef 19746
c19d1205
ZW
19747 -mcpu=<cpu name> Assemble for selected processor
19748 -march=<architecture name> Assemble for selected architecture
19749 -mfpu=<fpu architecture> Assemble for selected FPU.
19750 -EB/-mbig-endian Big-endian
19751 -EL/-mlittle-endian Little-endian
19752 -k Generate PIC code
19753 -mthumb Start in Thumb mode
19754 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19755
c19d1205 19756 For now we will also provide support for:
b99bd4ef 19757
c19d1205
ZW
19758 -mapcs-32 32-bit Program counter
19759 -mapcs-26 26-bit Program counter
19760 -macps-float Floats passed in FP registers
19761 -mapcs-reentrant Reentrant code
19762 -matpcs
19763 (sometime these will probably be replaced with -mapcs=<list of options>
19764 and -matpcs=<list of options>)
b99bd4ef 19765
c19d1205
ZW
19766 The remaining options are only supported for back-wards compatibility.
19767 Cpu variants, the arm part is optional:
19768 -m[arm]1 Currently not supported.
19769 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19770 -m[arm]3 Arm 3 processor
19771 -m[arm]6[xx], Arm 6 processors
19772 -m[arm]7[xx][t][[d]m] Arm 7 processors
19773 -m[arm]8[10] Arm 8 processors
19774 -m[arm]9[20][tdmi] Arm 9 processors
19775 -mstrongarm[110[0]] StrongARM processors
19776 -mxscale XScale processors
19777 -m[arm]v[2345[t[e]]] Arm architectures
19778 -mall All (except the ARM1)
19779 FP variants:
19780 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19781 -mfpe-old (No float load/store multiples)
19782 -mvfpxd VFP Single precision
19783 -mvfp All VFP
19784 -mno-fpu Disable all floating point instructions
b99bd4ef 19785
c19d1205
ZW
19786 The following CPU names are recognized:
19787 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19788 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19789 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19790 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19791 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19792 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19793 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19794
c19d1205 19795 */
b99bd4ef 19796
c19d1205 19797const char * md_shortopts = "m:k";
b99bd4ef 19798
c19d1205
ZW
19799#ifdef ARM_BI_ENDIAN
19800#define OPTION_EB (OPTION_MD_BASE + 0)
19801#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19802#else
c19d1205
ZW
19803#if TARGET_BYTES_BIG_ENDIAN
19804#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19805#else
c19d1205
ZW
19806#define OPTION_EL (OPTION_MD_BASE + 1)
19807#endif
b99bd4ef 19808#endif
b99bd4ef 19809
c19d1205 19810struct option md_longopts[] =
b99bd4ef 19811{
c19d1205
ZW
19812#ifdef OPTION_EB
19813 {"EB", no_argument, NULL, OPTION_EB},
19814#endif
19815#ifdef OPTION_EL
19816 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19817#endif
c19d1205
ZW
19818 {NULL, no_argument, NULL, 0}
19819};
b99bd4ef 19820
c19d1205 19821size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19822
c19d1205 19823struct arm_option_table
b99bd4ef 19824{
c19d1205
ZW
19825 char *option; /* Option name to match. */
19826 char *help; /* Help information. */
19827 int *var; /* Variable to change. */
19828 int value; /* What to change it to. */
19829 char *deprecated; /* If non-null, print this message. */
19830};
b99bd4ef 19831
c19d1205
ZW
19832struct arm_option_table arm_opts[] =
19833{
19834 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19835 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19836 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19837 &support_interwork, 1, NULL},
19838 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19839 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19840 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19841 1, NULL},
19842 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19843 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19844 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19845 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19846 NULL},
b99bd4ef 19847
c19d1205
ZW
19848 /* These are recognized by the assembler, but have no affect on code. */
19849 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19850 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19851 {NULL, NULL, NULL, 0, NULL}
19852};
19853
19854struct arm_legacy_option_table
19855{
19856 char *option; /* Option name to match. */
19857 const arm_feature_set **var; /* Variable to change. */
19858 const arm_feature_set value; /* What to change it to. */
19859 char *deprecated; /* If non-null, print this message. */
19860};
b99bd4ef 19861
e74cfd16
PB
19862const struct arm_legacy_option_table arm_legacy_opts[] =
19863{
c19d1205
ZW
19864 /* DON'T add any new processors to this list -- we want the whole list
19865 to go away... Add them to the processors table instead. */
e74cfd16
PB
19866 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19867 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19868 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19869 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19870 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19871 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19872 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19873 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19874 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19875 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19876 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19877 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19878 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19879 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19880 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19881 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19882 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19883 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19884 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19885 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19886 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19887 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19888 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19889 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19890 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19891 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19892 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19893 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19894 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19895 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19896 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19897 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19898 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19899 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19900 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19901 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19902 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19903 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19904 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19905 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19906 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19907 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19908 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19909 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19910 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19911 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19912 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19913 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19914 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19915 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19916 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19917 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19918 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19919 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19920 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19921 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19922 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19923 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19924 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19925 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19926 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19927 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19928 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19929 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19930 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19931 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19932 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19933 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19934 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19935 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19936 N_("use -mcpu=strongarm110")},
e74cfd16 19937 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19938 N_("use -mcpu=strongarm1100")},
e74cfd16 19939 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19940 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19941 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19942 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19943 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19944
c19d1205 19945 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19946 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19947 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19948 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19949 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19950 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19951 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19952 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19953 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19954 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19955 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19956 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19957 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19958 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19959 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19960 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19961 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19962 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19963 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 19964
c19d1205 19965 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
19966 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19967 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19968 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19969 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 19970 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 19971
e74cfd16 19972 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 19973};
7ed4c4c5 19974
c19d1205 19975struct arm_cpu_option_table
7ed4c4c5 19976{
c19d1205 19977 char *name;
e74cfd16 19978 const arm_feature_set value;
c19d1205
ZW
19979 /* For some CPUs we assume an FPU unless the user explicitly sets
19980 -mfpu=... */
e74cfd16 19981 const arm_feature_set default_fpu;
ee065d83
PB
19982 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19983 case. */
19984 const char *canonical_name;
c19d1205 19985};
7ed4c4c5 19986
c19d1205
ZW
19987/* This list should, at a minimum, contain all the cpu names
19988 recognized by GCC. */
e74cfd16 19989static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 19990{
ee065d83
PB
19991 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19992 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19993 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19994 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19995 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19996 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19997 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19998 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19999 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20000 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20001 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20002 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20003 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20004 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20005 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20006 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20007 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20008 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20009 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20010 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20011 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20012 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20013 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20014 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20015 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20016 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20017 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20018 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20019 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20020 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20021 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20022 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20023 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20024 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20025 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20026 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20027 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20028 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20029 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20030 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20031 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20032 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20033 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20034 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20035 /* For V5 or later processors we default to using VFP; but the user
20036 should really set the FPU type explicitly. */
ee065d83
PB
20037 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20038 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20039 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20040 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20041 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20042 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20043 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20044 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20045 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20046 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20047 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20048 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20049 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20050 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20051 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20052 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20053 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20054 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20055 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20056 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20057 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20058 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20059 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20060 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20061 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20062 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20063 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20064 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20065 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20066 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20067 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20068 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20069 | FPU_NEON_EXT_V1),
20070 NULL},
62b3e311
PB
20071 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20072 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 20073 /* ??? XSCALE is really an architecture. */
ee065d83 20074 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20075 /* ??? iwmmxt is not a processor. */
ee065d83 20076 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20077 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20078 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20079 /* Maverick */
e74cfd16
PB
20080 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20081 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20082};
7ed4c4c5 20083
c19d1205 20084struct arm_arch_option_table
7ed4c4c5 20085{
c19d1205 20086 char *name;
e74cfd16
PB
20087 const arm_feature_set value;
20088 const arm_feature_set default_fpu;
c19d1205 20089};
7ed4c4c5 20090
c19d1205
ZW
20091/* This list should, at a minimum, contain all the architecture names
20092 recognized by GCC. */
e74cfd16 20093static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20094{
20095 {"all", ARM_ANY, FPU_ARCH_FPA},
20096 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20097 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20098 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20099 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20100 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20101 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20102 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20103 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20104 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20105 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20106 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20107 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20108 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20109 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20110 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20111 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20112 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20113 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20114 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20115 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20116 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20117 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20118 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20119 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20120 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311 20121 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20122 /* The official spelling of the ARMv7 profile variants is the dashed form.
20123 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20124 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20125 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20126 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20127 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20128 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20129 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20130 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20131 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20132 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20133 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20134};
7ed4c4c5 20135
c19d1205 20136/* ISA extensions in the co-processor space. */
e74cfd16 20137struct arm_option_cpu_value_table
c19d1205
ZW
20138{
20139 char *name;
e74cfd16 20140 const arm_feature_set value;
c19d1205 20141};
7ed4c4c5 20142
e74cfd16 20143static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20144{
e74cfd16
PB
20145 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20146 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20147 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20148 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20149 {NULL, ARM_ARCH_NONE}
c19d1205 20150};
7ed4c4c5 20151
c19d1205
ZW
20152/* This list should, at a minimum, contain all the fpu names
20153 recognized by GCC. */
e74cfd16 20154static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20155{
20156 {"softfpa", FPU_NONE},
20157 {"fpe", FPU_ARCH_FPE},
20158 {"fpe2", FPU_ARCH_FPE},
20159 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20160 {"fpa", FPU_ARCH_FPA},
20161 {"fpa10", FPU_ARCH_FPA},
20162 {"fpa11", FPU_ARCH_FPA},
20163 {"arm7500fe", FPU_ARCH_FPA},
20164 {"softvfp", FPU_ARCH_VFP},
20165 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20166 {"vfp", FPU_ARCH_VFP_V2},
20167 {"vfp9", FPU_ARCH_VFP_V2},
5287ad62 20168 {"vfp3", FPU_ARCH_VFP_V3},
c19d1205
ZW
20169 {"vfp10", FPU_ARCH_VFP_V2},
20170 {"vfp10-r0", FPU_ARCH_VFP_V1},
20171 {"vfpxd", FPU_ARCH_VFP_V1xD},
20172 {"arm1020t", FPU_ARCH_VFP_V1},
20173 {"arm1020e", FPU_ARCH_VFP_V2},
20174 {"arm1136jfs", FPU_ARCH_VFP_V2},
20175 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20176 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20177 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20178 {NULL, ARM_ARCH_NONE}
20179};
20180
20181struct arm_option_value_table
20182{
20183 char *name;
20184 long value;
c19d1205 20185};
7ed4c4c5 20186
e74cfd16 20187static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20188{
20189 {"hard", ARM_FLOAT_ABI_HARD},
20190 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20191 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20192 {NULL, 0}
c19d1205 20193};
7ed4c4c5 20194
c19d1205 20195#ifdef OBJ_ELF
3a4a14e9 20196/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20197static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20198{
20199 {"gnu", EF_ARM_EABI_UNKNOWN},
20200 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20201 {"5", EF_ARM_EABI_VER5},
e74cfd16 20202 {NULL, 0}
c19d1205
ZW
20203};
20204#endif
7ed4c4c5 20205
c19d1205
ZW
20206struct arm_long_option_table
20207{
20208 char * option; /* Substring to match. */
20209 char * help; /* Help information. */
20210 int (* func) (char * subopt); /* Function to decode sub-option. */
20211 char * deprecated; /* If non-null, print this message. */
20212};
7ed4c4c5
NC
20213
20214static int
e74cfd16 20215arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20216{
e74cfd16
PB
20217 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20218
20219 /* Copy the feature set, so that we can modify it. */
20220 *ext_set = **opt_p;
20221 *opt_p = ext_set;
20222
c19d1205 20223 while (str != NULL && *str != 0)
7ed4c4c5 20224 {
e74cfd16 20225 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20226 char * ext;
20227 int optlen;
7ed4c4c5 20228
c19d1205
ZW
20229 if (*str != '+')
20230 {
20231 as_bad (_("invalid architectural extension"));
20232 return 0;
20233 }
7ed4c4c5 20234
c19d1205
ZW
20235 str++;
20236 ext = strchr (str, '+');
7ed4c4c5 20237
c19d1205
ZW
20238 if (ext != NULL)
20239 optlen = ext - str;
20240 else
20241 optlen = strlen (str);
7ed4c4c5 20242
c19d1205
ZW
20243 if (optlen == 0)
20244 {
20245 as_bad (_("missing architectural extension"));
20246 return 0;
20247 }
7ed4c4c5 20248
c19d1205
ZW
20249 for (opt = arm_extensions; opt->name != NULL; opt++)
20250 if (strncmp (opt->name, str, optlen) == 0)
20251 {
e74cfd16 20252 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20253 break;
20254 }
7ed4c4c5 20255
c19d1205
ZW
20256 if (opt->name == NULL)
20257 {
5f4273c7 20258 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20259 return 0;
20260 }
7ed4c4c5 20261
c19d1205
ZW
20262 str = ext;
20263 };
7ed4c4c5 20264
c19d1205
ZW
20265 return 1;
20266}
7ed4c4c5 20267
c19d1205
ZW
20268static int
20269arm_parse_cpu (char * str)
7ed4c4c5 20270{
e74cfd16 20271 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20272 char * ext = strchr (str, '+');
20273 int optlen;
7ed4c4c5 20274
c19d1205
ZW
20275 if (ext != NULL)
20276 optlen = ext - str;
7ed4c4c5 20277 else
c19d1205 20278 optlen = strlen (str);
7ed4c4c5 20279
c19d1205 20280 if (optlen == 0)
7ed4c4c5 20281 {
c19d1205
ZW
20282 as_bad (_("missing cpu name `%s'"), str);
20283 return 0;
7ed4c4c5
NC
20284 }
20285
c19d1205
ZW
20286 for (opt = arm_cpus; opt->name != NULL; opt++)
20287 if (strncmp (opt->name, str, optlen) == 0)
20288 {
e74cfd16
PB
20289 mcpu_cpu_opt = &opt->value;
20290 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 20291 if (opt->canonical_name)
5f4273c7 20292 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20293 else
20294 {
20295 int i;
20296 for (i = 0; i < optlen; i++)
20297 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20298 selected_cpu_name[i] = 0;
20299 }
7ed4c4c5 20300
c19d1205
ZW
20301 if (ext != NULL)
20302 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20303
c19d1205
ZW
20304 return 1;
20305 }
7ed4c4c5 20306
c19d1205
ZW
20307 as_bad (_("unknown cpu `%s'"), str);
20308 return 0;
7ed4c4c5
NC
20309}
20310
c19d1205
ZW
20311static int
20312arm_parse_arch (char * str)
7ed4c4c5 20313{
e74cfd16 20314 const struct arm_arch_option_table *opt;
c19d1205
ZW
20315 char *ext = strchr (str, '+');
20316 int optlen;
7ed4c4c5 20317
c19d1205
ZW
20318 if (ext != NULL)
20319 optlen = ext - str;
7ed4c4c5 20320 else
c19d1205 20321 optlen = strlen (str);
7ed4c4c5 20322
c19d1205 20323 if (optlen == 0)
7ed4c4c5 20324 {
c19d1205
ZW
20325 as_bad (_("missing architecture name `%s'"), str);
20326 return 0;
7ed4c4c5
NC
20327 }
20328
c19d1205
ZW
20329 for (opt = arm_archs; opt->name != NULL; opt++)
20330 if (streq (opt->name, str))
20331 {
e74cfd16
PB
20332 march_cpu_opt = &opt->value;
20333 march_fpu_opt = &opt->default_fpu;
5f4273c7 20334 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 20335
c19d1205
ZW
20336 if (ext != NULL)
20337 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20338
c19d1205
ZW
20339 return 1;
20340 }
20341
20342 as_bad (_("unknown architecture `%s'\n"), str);
20343 return 0;
7ed4c4c5 20344}
eb043451 20345
c19d1205
ZW
20346static int
20347arm_parse_fpu (char * str)
20348{
e74cfd16 20349 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20350
c19d1205
ZW
20351 for (opt = arm_fpus; opt->name != NULL; opt++)
20352 if (streq (opt->name, str))
20353 {
e74cfd16 20354 mfpu_opt = &opt->value;
c19d1205
ZW
20355 return 1;
20356 }
b99bd4ef 20357
c19d1205
ZW
20358 as_bad (_("unknown floating point format `%s'\n"), str);
20359 return 0;
20360}
20361
20362static int
20363arm_parse_float_abi (char * str)
b99bd4ef 20364{
e74cfd16 20365 const struct arm_option_value_table * opt;
b99bd4ef 20366
c19d1205
ZW
20367 for (opt = arm_float_abis; opt->name != NULL; opt++)
20368 if (streq (opt->name, str))
20369 {
20370 mfloat_abi_opt = opt->value;
20371 return 1;
20372 }
cc8a6dd0 20373
c19d1205
ZW
20374 as_bad (_("unknown floating point abi `%s'\n"), str);
20375 return 0;
20376}
b99bd4ef 20377
c19d1205
ZW
20378#ifdef OBJ_ELF
20379static int
20380arm_parse_eabi (char * str)
20381{
e74cfd16 20382 const struct arm_option_value_table *opt;
cc8a6dd0 20383
c19d1205
ZW
20384 for (opt = arm_eabis; opt->name != NULL; opt++)
20385 if (streq (opt->name, str))
20386 {
20387 meabi_flags = opt->value;
20388 return 1;
20389 }
20390 as_bad (_("unknown EABI `%s'\n"), str);
20391 return 0;
20392}
20393#endif
cc8a6dd0 20394
c19d1205
ZW
20395struct arm_long_option_table arm_long_opts[] =
20396{
20397 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20398 arm_parse_cpu, NULL},
20399 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20400 arm_parse_arch, NULL},
20401 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20402 arm_parse_fpu, NULL},
20403 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20404 arm_parse_float_abi, NULL},
20405#ifdef OBJ_ELF
20406 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20407 arm_parse_eabi, NULL},
20408#endif
20409 {NULL, NULL, 0, NULL}
20410};
cc8a6dd0 20411
c19d1205
ZW
20412int
20413md_parse_option (int c, char * arg)
20414{
20415 struct arm_option_table *opt;
e74cfd16 20416 const struct arm_legacy_option_table *fopt;
c19d1205 20417 struct arm_long_option_table *lopt;
b99bd4ef 20418
c19d1205 20419 switch (c)
b99bd4ef 20420 {
c19d1205
ZW
20421#ifdef OPTION_EB
20422 case OPTION_EB:
20423 target_big_endian = 1;
20424 break;
20425#endif
cc8a6dd0 20426
c19d1205
ZW
20427#ifdef OPTION_EL
20428 case OPTION_EL:
20429 target_big_endian = 0;
20430 break;
20431#endif
b99bd4ef 20432
c19d1205
ZW
20433 case 'a':
20434 /* Listing option. Just ignore these, we don't support additional
20435 ones. */
20436 return 0;
b99bd4ef 20437
c19d1205
ZW
20438 default:
20439 for (opt = arm_opts; opt->option != NULL; opt++)
20440 {
20441 if (c == opt->option[0]
20442 && ((arg == NULL && opt->option[1] == 0)
20443 || streq (arg, opt->option + 1)))
20444 {
20445#if WARN_DEPRECATED
20446 /* If the option is deprecated, tell the user. */
20447 if (opt->deprecated != NULL)
20448 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20449 arg ? arg : "", _(opt->deprecated));
20450#endif
b99bd4ef 20451
c19d1205
ZW
20452 if (opt->var != NULL)
20453 *opt->var = opt->value;
cc8a6dd0 20454
c19d1205
ZW
20455 return 1;
20456 }
20457 }
b99bd4ef 20458
e74cfd16
PB
20459 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20460 {
20461 if (c == fopt->option[0]
20462 && ((arg == NULL && fopt->option[1] == 0)
20463 || streq (arg, fopt->option + 1)))
20464 {
20465#if WARN_DEPRECATED
20466 /* If the option is deprecated, tell the user. */
20467 if (fopt->deprecated != NULL)
20468 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20469 arg ? arg : "", _(fopt->deprecated));
20470#endif
20471
20472 if (fopt->var != NULL)
20473 *fopt->var = &fopt->value;
20474
20475 return 1;
20476 }
20477 }
20478
c19d1205
ZW
20479 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20480 {
20481 /* These options are expected to have an argument. */
20482 if (c == lopt->option[0]
20483 && arg != NULL
20484 && strncmp (arg, lopt->option + 1,
20485 strlen (lopt->option + 1)) == 0)
20486 {
20487#if WARN_DEPRECATED
20488 /* If the option is deprecated, tell the user. */
20489 if (lopt->deprecated != NULL)
20490 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20491 _(lopt->deprecated));
20492#endif
b99bd4ef 20493
c19d1205
ZW
20494 /* Call the sup-option parser. */
20495 return lopt->func (arg + strlen (lopt->option) - 1);
20496 }
20497 }
a737bd4d 20498
c19d1205
ZW
20499 return 0;
20500 }
a394c00f 20501
c19d1205
ZW
20502 return 1;
20503}
a394c00f 20504
c19d1205
ZW
20505void
20506md_show_usage (FILE * fp)
a394c00f 20507{
c19d1205
ZW
20508 struct arm_option_table *opt;
20509 struct arm_long_option_table *lopt;
a394c00f 20510
c19d1205 20511 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20512
c19d1205
ZW
20513 for (opt = arm_opts; opt->option != NULL; opt++)
20514 if (opt->help != NULL)
20515 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20516
c19d1205
ZW
20517 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20518 if (lopt->help != NULL)
20519 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20520
c19d1205
ZW
20521#ifdef OPTION_EB
20522 fprintf (fp, _("\
20523 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20524#endif
20525
c19d1205
ZW
20526#ifdef OPTION_EL
20527 fprintf (fp, _("\
20528 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20529#endif
c19d1205 20530}
ee065d83
PB
20531
20532
20533#ifdef OBJ_ELF
62b3e311
PB
20534typedef struct
20535{
20536 int val;
20537 arm_feature_set flags;
20538} cpu_arch_ver_table;
20539
20540/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20541 least features first. */
20542static const cpu_arch_ver_table cpu_arch_ver[] =
20543{
20544 {1, ARM_ARCH_V4},
20545 {2, ARM_ARCH_V4T},
20546 {3, ARM_ARCH_V5},
20547 {4, ARM_ARCH_V5TE},
20548 {5, ARM_ARCH_V5TEJ},
20549 {6, ARM_ARCH_V6},
20550 {7, ARM_ARCH_V6Z},
20551 {8, ARM_ARCH_V6K},
20552 {9, ARM_ARCH_V6T2},
20553 {10, ARM_ARCH_V7A},
20554 {10, ARM_ARCH_V7R},
20555 {10, ARM_ARCH_V7M},
20556 {0, ARM_ARCH_NONE}
20557};
20558
ee065d83
PB
20559/* Set the public EABI object attributes. */
20560static void
20561aeabi_set_public_attributes (void)
20562{
20563 int arch;
e74cfd16 20564 arm_feature_set flags;
62b3e311
PB
20565 arm_feature_set tmp;
20566 const cpu_arch_ver_table *p;
ee065d83
PB
20567
20568 /* Choose the architecture based on the capabilities of the requested cpu
20569 (if any) and/or the instructions actually used. */
e74cfd16
PB
20570 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20571 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20572 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20573 /*Allow the user to override the reported architecture. */
20574 if (object_arch)
20575 {
20576 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20577 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20578 }
20579
62b3e311
PB
20580 tmp = flags;
20581 arch = 0;
20582 for (p = cpu_arch_ver; p->val; p++)
20583 {
20584 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20585 {
20586 arch = p->val;
20587 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20588 }
20589 }
ee065d83
PB
20590
20591 /* Tag_CPU_name. */
20592 if (selected_cpu_name[0])
20593 {
20594 char *p;
20595
20596 p = selected_cpu_name;
5f4273c7 20597 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
20598 {
20599 int i;
5f4273c7 20600
ee065d83
PB
20601 p += 4;
20602 for (i = 0; p[i]; i++)
20603 p[i] = TOUPPER (p[i]);
20604 }
104d59d1 20605 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
ee065d83
PB
20606 }
20607 /* Tag_CPU_arch. */
104d59d1 20608 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
62b3e311
PB
20609 /* Tag_CPU_arch_profile. */
20610 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
104d59d1 20611 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
62b3e311 20612 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
104d59d1 20613 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
62b3e311 20614 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
104d59d1 20615 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
ee065d83 20616 /* Tag_ARM_ISA_use. */
e74cfd16 20617 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
104d59d1 20618 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
ee065d83 20619 /* Tag_THUMB_ISA_use. */
e74cfd16 20620 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
104d59d1 20621 bfd_elf_add_proc_attr_int (stdoutput, 9,
e74cfd16 20622 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20623 /* Tag_VFP_arch. */
5287ad62
JB
20624 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20625 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
104d59d1 20626 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
5287ad62
JB
20627 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20628 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
104d59d1 20629 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
5287ad62
JB
20630 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20631 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20632 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20633 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
104d59d1 20634 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
ee065d83 20635 /* Tag_WMMX_arch. */
e74cfd16
PB
20636 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20637 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
104d59d1 20638 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
5287ad62
JB
20639 /* Tag_NEON_arch. */
20640 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20641 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
104d59d1 20642 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
ee065d83
PB
20643}
20644
104d59d1 20645/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
20646void
20647arm_md_end (void)
20648{
ee065d83
PB
20649 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20650 return;
20651
20652 aeabi_set_public_attributes ();
ee065d83 20653}
8463be01 20654#endif /* OBJ_ELF */
ee065d83
PB
20655
20656
20657/* Parse a .cpu directive. */
20658
20659static void
20660s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20661{
e74cfd16 20662 const struct arm_cpu_option_table *opt;
ee065d83
PB
20663 char *name;
20664 char saved_char;
20665
20666 name = input_line_pointer;
5f4273c7 20667 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20668 input_line_pointer++;
20669 saved_char = *input_line_pointer;
20670 *input_line_pointer = 0;
20671
20672 /* Skip the first "all" entry. */
20673 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20674 if (streq (opt->name, name))
20675 {
e74cfd16
PB
20676 mcpu_cpu_opt = &opt->value;
20677 selected_cpu = opt->value;
ee065d83 20678 if (opt->canonical_name)
5f4273c7 20679 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20680 else
20681 {
20682 int i;
20683 for (i = 0; opt->name[i]; i++)
20684 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20685 selected_cpu_name[i] = 0;
20686 }
e74cfd16 20687 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20688 *input_line_pointer = saved_char;
20689 demand_empty_rest_of_line ();
20690 return;
20691 }
20692 as_bad (_("unknown cpu `%s'"), name);
20693 *input_line_pointer = saved_char;
20694 ignore_rest_of_line ();
20695}
20696
20697
20698/* Parse a .arch directive. */
20699
20700static void
20701s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20702{
e74cfd16 20703 const struct arm_arch_option_table *opt;
ee065d83
PB
20704 char saved_char;
20705 char *name;
20706
20707 name = input_line_pointer;
5f4273c7 20708 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20709 input_line_pointer++;
20710 saved_char = *input_line_pointer;
20711 *input_line_pointer = 0;
20712
20713 /* Skip the first "all" entry. */
20714 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20715 if (streq (opt->name, name))
20716 {
e74cfd16
PB
20717 mcpu_cpu_opt = &opt->value;
20718 selected_cpu = opt->value;
5f4273c7 20719 strcpy (selected_cpu_name, opt->name);
e74cfd16 20720 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20721 *input_line_pointer = saved_char;
20722 demand_empty_rest_of_line ();
20723 return;
20724 }
20725
20726 as_bad (_("unknown architecture `%s'\n"), name);
20727 *input_line_pointer = saved_char;
20728 ignore_rest_of_line ();
20729}
20730
20731
7a1d4c38
PB
20732/* Parse a .object_arch directive. */
20733
20734static void
20735s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20736{
20737 const struct arm_arch_option_table *opt;
20738 char saved_char;
20739 char *name;
20740
20741 name = input_line_pointer;
5f4273c7 20742 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
20743 input_line_pointer++;
20744 saved_char = *input_line_pointer;
20745 *input_line_pointer = 0;
20746
20747 /* Skip the first "all" entry. */
20748 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20749 if (streq (opt->name, name))
20750 {
20751 object_arch = &opt->value;
20752 *input_line_pointer = saved_char;
20753 demand_empty_rest_of_line ();
20754 return;
20755 }
20756
20757 as_bad (_("unknown architecture `%s'\n"), name);
20758 *input_line_pointer = saved_char;
20759 ignore_rest_of_line ();
20760}
20761
20762
ee065d83
PB
20763/* Parse a .fpu directive. */
20764
20765static void
20766s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20767{
e74cfd16 20768 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20769 char saved_char;
20770 char *name;
20771
20772 name = input_line_pointer;
5f4273c7 20773 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20774 input_line_pointer++;
20775 saved_char = *input_line_pointer;
20776 *input_line_pointer = 0;
5f4273c7 20777
ee065d83
PB
20778 for (opt = arm_fpus; opt->name != NULL; opt++)
20779 if (streq (opt->name, name))
20780 {
e74cfd16
PB
20781 mfpu_opt = &opt->value;
20782 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20783 *input_line_pointer = saved_char;
20784 demand_empty_rest_of_line ();
20785 return;
20786 }
20787
20788 as_bad (_("unknown floating point format `%s'\n"), name);
20789 *input_line_pointer = saved_char;
20790 ignore_rest_of_line ();
20791}
ee065d83 20792
794ba86a
DJ
20793/* Copy symbol information. */
20794void
20795arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20796{
20797 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20798}