bfd/
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
ebd1c875 3 2004, 2005, 2006
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
15 the Free Software Foundation; either version 2, or (at your option)
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
237arm_is_eabi(void)
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:
c19d1205 679 <insn>
b99bd4ef
NC
680*/
681
682symbolS * last_label_seen;
b34976b6 683static int label_is_thumb_function_name = FALSE;
a737bd4d 684\f
3d0c9500
NC
685/* Literal pool structure. Held on a per-section
686 and per-sub-section basis. */
a737bd4d 687
c19d1205 688#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 689typedef struct literal_pool
b99bd4ef 690{
c19d1205
ZW
691 expressionS literals [MAX_LITERAL_POOL_SIZE];
692 unsigned int next_free_entry;
693 unsigned int id;
694 symbolS * symbol;
695 segT section;
696 subsegT sub_section;
61b5f74b 697 struct literal_pool * next;
3d0c9500 698} literal_pool;
b99bd4ef 699
3d0c9500
NC
700/* Pointer to a linked list of literal pools. */
701literal_pool * list_of_pools = NULL;
e27ec89e
PB
702
703/* State variables for IT block handling. */
704static bfd_boolean current_it_mask = 0;
705static int current_cc;
706
c19d1205
ZW
707\f
708/* Pure syntax. */
b99bd4ef 709
c19d1205
ZW
710/* This array holds the chars that always start a comment. If the
711 pre-processor is disabled, these aren't very useful. */
712const char comment_chars[] = "@";
3d0c9500 713
c19d1205
ZW
714/* This array holds the chars that only start a comment at the beginning of
715 a line. If the line seems to have the form '# 123 filename'
716 .line and .file directives will appear in the pre-processed output. */
717/* Note that input_file.c hand checks for '#' at the beginning of the
718 first line of the input file. This is because the compiler outputs
719 #NO_APP at the beginning of its output. */
720/* Also note that comments like this one will always work. */
721const char line_comment_chars[] = "#";
3d0c9500 722
c19d1205 723const char line_separator_chars[] = ";";
b99bd4ef 724
c19d1205
ZW
725/* Chars that can be used to separate mant
726 from exp in floating point numbers. */
727const char EXP_CHARS[] = "eE";
3d0c9500 728
c19d1205
ZW
729/* Chars that mean this number is a floating point constant. */
730/* As in 0f12.456 */
731/* or 0d1.2345e12 */
b99bd4ef 732
c19d1205 733const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 734
c19d1205
ZW
735/* Prefix characters that indicate the start of an immediate
736 value. */
737#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 738
c19d1205
ZW
739/* Separator character handling. */
740
741#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
742
743static inline int
744skip_past_char (char ** str, char c)
745{
746 if (**str == c)
747 {
748 (*str)++;
749 return SUCCESS;
3d0c9500 750 }
c19d1205
ZW
751 else
752 return FAIL;
753}
754#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 755
c19d1205
ZW
756/* Arithmetic expressions (possibly involving symbols). */
757
758/* Return TRUE if anything in the expression is a bignum. */
759
760static int
761walk_no_bignums (symbolS * sp)
762{
763 if (symbol_get_value_expression (sp)->X_op == O_big)
764 return 1;
765
766 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 767 {
c19d1205
ZW
768 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
769 || (symbol_get_value_expression (sp)->X_op_symbol
770 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
771 }
772
c19d1205 773 return 0;
3d0c9500
NC
774}
775
c19d1205
ZW
776static int in_my_get_expression = 0;
777
778/* Third argument to my_get_expression. */
779#define GE_NO_PREFIX 0
780#define GE_IMM_PREFIX 1
781#define GE_OPT_PREFIX 2
5287ad62
JB
782/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
783 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
784#define GE_OPT_PREFIX_BIG 3
a737bd4d 785
b99bd4ef 786static int
c19d1205 787my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 788{
c19d1205
ZW
789 char * save_in;
790 segT seg;
b99bd4ef 791
c19d1205
ZW
792 /* In unified syntax, all prefixes are optional. */
793 if (unified_syntax)
5287ad62
JB
794 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
795 : GE_OPT_PREFIX;
b99bd4ef 796
c19d1205 797 switch (prefix_mode)
b99bd4ef 798 {
c19d1205
ZW
799 case GE_NO_PREFIX: break;
800 case GE_IMM_PREFIX:
801 if (!is_immediate_prefix (**str))
802 {
803 inst.error = _("immediate expression requires a # prefix");
804 return FAIL;
805 }
806 (*str)++;
807 break;
808 case GE_OPT_PREFIX:
5287ad62 809 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
810 if (is_immediate_prefix (**str))
811 (*str)++;
812 break;
813 default: abort ();
814 }
b99bd4ef 815
c19d1205 816 memset (ep, 0, sizeof (expressionS));
b99bd4ef 817
c19d1205
ZW
818 save_in = input_line_pointer;
819 input_line_pointer = *str;
820 in_my_get_expression = 1;
821 seg = expression (ep);
822 in_my_get_expression = 0;
823
824 if (ep->X_op == O_illegal)
b99bd4ef 825 {
c19d1205
ZW
826 /* We found a bad expression in md_operand(). */
827 *str = input_line_pointer;
828 input_line_pointer = save_in;
829 if (inst.error == NULL)
830 inst.error = _("bad expression");
831 return 1;
832 }
b99bd4ef 833
c19d1205
ZW
834#ifdef OBJ_AOUT
835 if (seg != absolute_section
836 && seg != text_section
837 && seg != data_section
838 && seg != bss_section
839 && seg != undefined_section)
840 {
841 inst.error = _("bad segment");
842 *str = input_line_pointer;
843 input_line_pointer = save_in;
844 return 1;
b99bd4ef 845 }
c19d1205 846#endif
b99bd4ef 847
c19d1205
ZW
848 /* Get rid of any bignums now, so that we don't generate an error for which
849 we can't establish a line number later on. Big numbers are never valid
850 in instructions, which is where this routine is always called. */
5287ad62
JB
851 if (prefix_mode != GE_OPT_PREFIX_BIG
852 && (ep->X_op == O_big
853 || (ep->X_add_symbol
854 && (walk_no_bignums (ep->X_add_symbol)
855 || (ep->X_op_symbol
856 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
857 {
858 inst.error = _("invalid constant");
859 *str = input_line_pointer;
860 input_line_pointer = save_in;
861 return 1;
862 }
b99bd4ef 863
c19d1205
ZW
864 *str = input_line_pointer;
865 input_line_pointer = save_in;
866 return 0;
b99bd4ef
NC
867}
868
c19d1205
ZW
869/* Turn a string in input_line_pointer into a floating point constant
870 of type TYPE, and store the appropriate bytes in *LITP. The number
871 of LITTLENUMS emitted is stored in *SIZEP. An error message is
872 returned, or NULL on OK.
b99bd4ef 873
c19d1205
ZW
874 Note that fp constants aren't represent in the normal way on the ARM.
875 In big endian mode, things are as expected. However, in little endian
876 mode fp constants are big-endian word-wise, and little-endian byte-wise
877 within the words. For example, (double) 1.1 in big endian mode is
878 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
879 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 880
c19d1205 881 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 882
c19d1205
ZW
883char *
884md_atof (int type, char * litP, int * sizeP)
885{
886 int prec;
887 LITTLENUM_TYPE words[MAX_LITTLENUMS];
888 char *t;
889 int i;
b99bd4ef 890
c19d1205
ZW
891 switch (type)
892 {
893 case 'f':
894 case 'F':
895 case 's':
896 case 'S':
897 prec = 2;
898 break;
b99bd4ef 899
c19d1205
ZW
900 case 'd':
901 case 'D':
902 case 'r':
903 case 'R':
904 prec = 4;
905 break;
b99bd4ef 906
c19d1205
ZW
907 case 'x':
908 case 'X':
909 prec = 6;
910 break;
b99bd4ef 911
c19d1205
ZW
912 case 'p':
913 case 'P':
914 prec = 6;
915 break;
a737bd4d 916
c19d1205
ZW
917 default:
918 *sizeP = 0;
919 return _("bad call to MD_ATOF()");
920 }
b99bd4ef 921
c19d1205
ZW
922 t = atof_ieee (input_line_pointer, type, words);
923 if (t)
924 input_line_pointer = t;
925 *sizeP = prec * 2;
b99bd4ef 926
c19d1205
ZW
927 if (target_big_endian)
928 {
929 for (i = 0; i < prec; i++)
930 {
931 md_number_to_chars (litP, (valueT) words[i], 2);
932 litP += 2;
933 }
934 }
935 else
936 {
e74cfd16 937 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
938 for (i = prec - 1; i >= 0; i--)
939 {
940 md_number_to_chars (litP, (valueT) words[i], 2);
941 litP += 2;
942 }
943 else
944 /* For a 4 byte float the order of elements in `words' is 1 0.
945 For an 8 byte float the order is 1 0 3 2. */
946 for (i = 0; i < prec; i += 2)
947 {
948 md_number_to_chars (litP, (valueT) words[i + 1], 2);
949 md_number_to_chars (litP + 2, (valueT) words[i], 2);
950 litP += 4;
951 }
952 }
b99bd4ef 953
c19d1205
ZW
954 return 0;
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;
1226
1227 *ccp = str;
1228
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;
1287
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 }
1298
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 }
1306
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 }
1335
1336 if (typeinfo)
1337 *typeinfo = atype;
1338
1339 if (rtype)
1340 *rtype = type;
1341
1342 *ccp = str;
1343
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).
1352 This function will fault on encountering a scalar.
1353*/
1354
1355static int
1356arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1357 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1358{
1359 struct neon_typed_alias atype;
1360 char *str = *ccp;
1361 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1362
1363 if (reg == FAIL)
1364 return FAIL;
1365
1366 /* Do not allow a scalar (reg+index) to parse as a register. */
1367 if ((atype.defined & NTA_HASINDEX) != 0)
1368 {
1369 first_error (_("register operand expected, but got scalar"));
1370 return FAIL;
1371 }
1372
1373 if (vectype)
1374 *vectype = atype.eltype;
1375
1376 *ccp = str;
1377
1378 return reg;
1379}
1380
1381#define NEON_SCALAR_REG(X) ((X) >> 4)
1382#define NEON_SCALAR_INDEX(X) ((X) & 15)
1383
5287ad62
JB
1384/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1385 have enough information to be able to do a good job bounds-checking. So, we
1386 just do easy checks here, and do further checks later. */
1387
1388static int
dcbf9037 1389parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1390{
dcbf9037 1391 int reg;
5287ad62 1392 char *str = *ccp;
dcbf9037 1393 struct neon_typed_alias atype;
5287ad62 1394
dcbf9037 1395 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5287ad62 1396
dcbf9037 1397 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62
JB
1398 return FAIL;
1399
dcbf9037 1400 if (atype.index == NEON_ALL_LANES)
5287ad62 1401 {
dcbf9037 1402 first_error (_("scalar must have an index"));
5287ad62
JB
1403 return FAIL;
1404 }
dcbf9037 1405 else if (atype.index >= 64 / elsize)
5287ad62 1406 {
dcbf9037 1407 first_error (_("scalar index out of range"));
5287ad62
JB
1408 return FAIL;
1409 }
1410
dcbf9037
JB
1411 if (type)
1412 *type = atype.eltype;
5287ad62 1413
5287ad62
JB
1414 *ccp = str;
1415
dcbf9037 1416 return reg * 16 + atype.index;
5287ad62
JB
1417}
1418
c19d1205
ZW
1419/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1420static long
1421parse_reg_list (char ** strp)
1422{
1423 char * str = * strp;
1424 long range = 0;
1425 int another_range;
a737bd4d 1426
c19d1205
ZW
1427 /* We come back here if we get ranges concatenated by '+' or '|'. */
1428 do
6057a28f 1429 {
c19d1205 1430 another_range = 0;
a737bd4d 1431
c19d1205
ZW
1432 if (*str == '{')
1433 {
1434 int in_range = 0;
1435 int cur_reg = -1;
a737bd4d 1436
c19d1205
ZW
1437 str++;
1438 do
1439 {
1440 int reg;
6057a28f 1441
dcbf9037 1442 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1443 {
dcbf9037 1444 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1445 return FAIL;
1446 }
a737bd4d 1447
c19d1205
ZW
1448 if (in_range)
1449 {
1450 int i;
a737bd4d 1451
c19d1205
ZW
1452 if (reg <= cur_reg)
1453 {
dcbf9037 1454 first_error (_("bad range in register list"));
c19d1205
ZW
1455 return FAIL;
1456 }
40a18ebd 1457
c19d1205
ZW
1458 for (i = cur_reg + 1; i < reg; i++)
1459 {
1460 if (range & (1 << i))
1461 as_tsktsk
1462 (_("Warning: duplicated register (r%d) in register list"),
1463 i);
1464 else
1465 range |= 1 << i;
1466 }
1467 in_range = 0;
1468 }
a737bd4d 1469
c19d1205
ZW
1470 if (range & (1 << reg))
1471 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1472 reg);
1473 else if (reg <= cur_reg)
1474 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1475
c19d1205
ZW
1476 range |= 1 << reg;
1477 cur_reg = reg;
1478 }
1479 while (skip_past_comma (&str) != FAIL
1480 || (in_range = 1, *str++ == '-'));
1481 str--;
a737bd4d 1482
c19d1205
ZW
1483 if (*str++ != '}')
1484 {
dcbf9037 1485 first_error (_("missing `}'"));
c19d1205
ZW
1486 return FAIL;
1487 }
1488 }
1489 else
1490 {
1491 expressionS expr;
40a18ebd 1492
c19d1205
ZW
1493 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1494 return FAIL;
40a18ebd 1495
c19d1205
ZW
1496 if (expr.X_op == O_constant)
1497 {
1498 if (expr.X_add_number
1499 != (expr.X_add_number & 0x0000ffff))
1500 {
1501 inst.error = _("invalid register mask");
1502 return FAIL;
1503 }
a737bd4d 1504
c19d1205
ZW
1505 if ((range & expr.X_add_number) != 0)
1506 {
1507 int regno = range & expr.X_add_number;
a737bd4d 1508
c19d1205
ZW
1509 regno &= -regno;
1510 regno = (1 << regno) - 1;
1511 as_tsktsk
1512 (_("Warning: duplicated register (r%d) in register list"),
1513 regno);
1514 }
a737bd4d 1515
c19d1205
ZW
1516 range |= expr.X_add_number;
1517 }
1518 else
1519 {
1520 if (inst.reloc.type != 0)
1521 {
1522 inst.error = _("expression too complex");
1523 return FAIL;
1524 }
a737bd4d 1525
c19d1205
ZW
1526 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1527 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1528 inst.reloc.pc_rel = 0;
1529 }
1530 }
a737bd4d 1531
c19d1205
ZW
1532 if (*str == '|' || *str == '+')
1533 {
1534 str++;
1535 another_range = 1;
1536 }
a737bd4d 1537 }
c19d1205 1538 while (another_range);
a737bd4d 1539
c19d1205
ZW
1540 *strp = str;
1541 return range;
a737bd4d
NC
1542}
1543
5287ad62
JB
1544/* Types of registers in a list. */
1545
1546enum reg_list_els
1547{
1548 REGLIST_VFP_S,
1549 REGLIST_VFP_D,
1550 REGLIST_NEON_D
1551};
1552
c19d1205
ZW
1553/* Parse a VFP register list. If the string is invalid return FAIL.
1554 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1555 register. Parses registers of type ETYPE.
1556 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1557 - Q registers can be used to specify pairs of D registers
1558 - { } can be omitted from around a singleton register list
1559 FIXME: This is not implemented, as it would require backtracking in
1560 some cases, e.g.:
1561 vtbl.8 d3,d4,d5
1562 This could be done (the meaning isn't really ambiguous), but doesn't
1563 fit in well with the current parsing framework.
dcbf9037
JB
1564 - 32 D registers may be used (also true for VFPv3).
1565 FIXME: Types are ignored in these register lists, which is probably a
1566 bug. */
6057a28f 1567
c19d1205 1568static int
037e8744 1569parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1570{
037e8744 1571 char *str = *ccp;
c19d1205
ZW
1572 int base_reg;
1573 int new_base;
5287ad62
JB
1574 enum arm_reg_type regtype = 0;
1575 int max_regs = 0;
c19d1205
ZW
1576 int count = 0;
1577 int warned = 0;
1578 unsigned long mask = 0;
a737bd4d 1579 int i;
6057a28f 1580
037e8744 1581 if (*str != '{')
5287ad62
JB
1582 {
1583 inst.error = _("expecting {");
1584 return FAIL;
1585 }
6057a28f 1586
037e8744 1587 str++;
6057a28f 1588
5287ad62 1589 switch (etype)
c19d1205 1590 {
5287ad62 1591 case REGLIST_VFP_S:
c19d1205
ZW
1592 regtype = REG_TYPE_VFS;
1593 max_regs = 32;
5287ad62
JB
1594 break;
1595
1596 case REGLIST_VFP_D:
1597 regtype = REG_TYPE_VFD;
b7fc2769
JB
1598 break;
1599
1600 case REGLIST_NEON_D:
1601 regtype = REG_TYPE_NDQ;
1602 break;
1603 }
1604
1605 if (etype != REGLIST_VFP_S)
1606 {
5287ad62
JB
1607 /* VFPv3 allows 32 D registers. */
1608 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1609 {
1610 max_regs = 32;
1611 if (thumb_mode)
1612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1613 fpu_vfp_ext_v3);
1614 else
1615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1616 fpu_vfp_ext_v3);
1617 }
1618 else
1619 max_regs = 16;
c19d1205 1620 }
6057a28f 1621
c19d1205 1622 base_reg = max_regs;
a737bd4d 1623
c19d1205
ZW
1624 do
1625 {
5287ad62 1626 int setmask = 1, addregs = 1;
dcbf9037 1627
037e8744 1628 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1629
c19d1205 1630 if (new_base == FAIL)
a737bd4d 1631 {
dcbf9037 1632 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1633 return FAIL;
1634 }
dcbf9037 1635
b7fc2769
JB
1636 if (new_base >= max_regs)
1637 {
1638 first_error (_("register out of range in list"));
1639 return FAIL;
1640 }
1641
5287ad62
JB
1642 /* Note: a value of 2 * n is returned for the register Q<n>. */
1643 if (regtype == REG_TYPE_NQ)
1644 {
1645 setmask = 3;
1646 addregs = 2;
1647 }
1648
c19d1205
ZW
1649 if (new_base < base_reg)
1650 base_reg = new_base;
a737bd4d 1651
5287ad62 1652 if (mask & (setmask << new_base))
c19d1205 1653 {
dcbf9037 1654 first_error (_("invalid register list"));
c19d1205 1655 return FAIL;
a737bd4d 1656 }
a737bd4d 1657
c19d1205
ZW
1658 if ((mask >> new_base) != 0 && ! warned)
1659 {
1660 as_tsktsk (_("register list not in ascending order"));
1661 warned = 1;
1662 }
0bbf2aa4 1663
5287ad62
JB
1664 mask |= setmask << new_base;
1665 count += addregs;
0bbf2aa4 1666
037e8744 1667 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1668 {
1669 int high_range;
0bbf2aa4 1670
037e8744 1671 str++;
0bbf2aa4 1672
037e8744 1673 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1674 == FAIL)
c19d1205
ZW
1675 {
1676 inst.error = gettext (reg_expected_msgs[regtype]);
1677 return FAIL;
1678 }
0bbf2aa4 1679
b7fc2769
JB
1680 if (high_range >= max_regs)
1681 {
1682 first_error (_("register out of range in list"));
1683 return FAIL;
1684 }
1685
5287ad62
JB
1686 if (regtype == REG_TYPE_NQ)
1687 high_range = high_range + 1;
1688
c19d1205
ZW
1689 if (high_range <= new_base)
1690 {
1691 inst.error = _("register range not in ascending order");
1692 return FAIL;
1693 }
0bbf2aa4 1694
5287ad62 1695 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1696 {
5287ad62 1697 if (mask & (setmask << new_base))
0bbf2aa4 1698 {
c19d1205
ZW
1699 inst.error = _("invalid register list");
1700 return FAIL;
0bbf2aa4 1701 }
c19d1205 1702
5287ad62
JB
1703 mask |= setmask << new_base;
1704 count += addregs;
0bbf2aa4 1705 }
0bbf2aa4 1706 }
0bbf2aa4 1707 }
037e8744 1708 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1709
037e8744 1710 str++;
0bbf2aa4 1711
c19d1205
ZW
1712 /* Sanity check -- should have raised a parse error above. */
1713 if (count == 0 || count > max_regs)
1714 abort ();
1715
1716 *pbase = base_reg;
1717
1718 /* Final test -- the registers must be consecutive. */
1719 mask >>= base_reg;
1720 for (i = 0; i < count; i++)
1721 {
1722 if ((mask & (1u << i)) == 0)
1723 {
1724 inst.error = _("non-contiguous register range");
1725 return FAIL;
1726 }
1727 }
1728
037e8744
JB
1729 *ccp = str;
1730
c19d1205 1731 return count;
b99bd4ef
NC
1732}
1733
dcbf9037
JB
1734/* True if two alias types are the same. */
1735
1736static int
1737neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1738{
1739 if (!a && !b)
1740 return 1;
1741
1742 if (!a || !b)
1743 return 0;
1744
1745 if (a->defined != b->defined)
1746 return 0;
1747
1748 if ((a->defined & NTA_HASTYPE) != 0
1749 && (a->eltype.type != b->eltype.type
1750 || a->eltype.size != b->eltype.size))
1751 return 0;
1752
1753 if ((a->defined & NTA_HASINDEX) != 0
1754 && (a->index != b->index))
1755 return 0;
1756
1757 return 1;
1758}
1759
5287ad62
JB
1760/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1761 The base register is put in *PBASE.
dcbf9037 1762 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1763 the return value.
1764 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1765 Bits [6:5] encode the list length (minus one).
1766 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1767
5287ad62 1768#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1769#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1770#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1771
1772static int
dcbf9037
JB
1773parse_neon_el_struct_list (char **str, unsigned *pbase,
1774 struct neon_type_el *eltype)
5287ad62
JB
1775{
1776 char *ptr = *str;
1777 int base_reg = -1;
1778 int reg_incr = -1;
1779 int count = 0;
1780 int lane = -1;
1781 int leading_brace = 0;
1782 enum arm_reg_type rtype = REG_TYPE_NDQ;
1783 int addregs = 1;
1784 const char *const incr_error = "register stride must be 1 or 2";
1785 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1786 struct neon_typed_alias firsttype;
5287ad62
JB
1787
1788 if (skip_past_char (&ptr, '{') == SUCCESS)
1789 leading_brace = 1;
1790
1791 do
1792 {
dcbf9037
JB
1793 struct neon_typed_alias atype;
1794 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1795
5287ad62
JB
1796 if (getreg == FAIL)
1797 {
dcbf9037 1798 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1799 return FAIL;
1800 }
1801
1802 if (base_reg == -1)
1803 {
1804 base_reg = getreg;
1805 if (rtype == REG_TYPE_NQ)
1806 {
1807 reg_incr = 1;
1808 addregs = 2;
1809 }
dcbf9037 1810 firsttype = atype;
5287ad62
JB
1811 }
1812 else if (reg_incr == -1)
1813 {
1814 reg_incr = getreg - base_reg;
1815 if (reg_incr < 1 || reg_incr > 2)
1816 {
dcbf9037 1817 first_error (_(incr_error));
5287ad62
JB
1818 return FAIL;
1819 }
1820 }
1821 else if (getreg != base_reg + reg_incr * count)
1822 {
dcbf9037
JB
1823 first_error (_(incr_error));
1824 return FAIL;
1825 }
1826
1827 if (!neon_alias_types_same (&atype, &firsttype))
1828 {
1829 first_error (_(type_error));
5287ad62
JB
1830 return FAIL;
1831 }
1832
1833 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1834 modes. */
1835 if (ptr[0] == '-')
1836 {
dcbf9037 1837 struct neon_typed_alias htype;
5287ad62
JB
1838 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1839 if (lane == -1)
1840 lane = NEON_INTERLEAVE_LANES;
1841 else if (lane != NEON_INTERLEAVE_LANES)
1842 {
dcbf9037 1843 first_error (_(type_error));
5287ad62
JB
1844 return FAIL;
1845 }
1846 if (reg_incr == -1)
1847 reg_incr = 1;
1848 else if (reg_incr != 1)
1849 {
dcbf9037 1850 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1851 return FAIL;
1852 }
1853 ptr++;
dcbf9037 1854 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1855 if (hireg == FAIL)
1856 {
dcbf9037
JB
1857 first_error (_(reg_expected_msgs[rtype]));
1858 return FAIL;
1859 }
1860 if (!neon_alias_types_same (&htype, &firsttype))
1861 {
1862 first_error (_(type_error));
5287ad62
JB
1863 return FAIL;
1864 }
1865 count += hireg + dregs - getreg;
1866 continue;
1867 }
1868
1869 /* If we're using Q registers, we can't use [] or [n] syntax. */
1870 if (rtype == REG_TYPE_NQ)
1871 {
1872 count += 2;
1873 continue;
1874 }
1875
dcbf9037 1876 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1877 {
dcbf9037
JB
1878 if (lane == -1)
1879 lane = atype.index;
1880 else if (lane != atype.index)
5287ad62 1881 {
dcbf9037
JB
1882 first_error (_(type_error));
1883 return FAIL;
5287ad62
JB
1884 }
1885 }
1886 else if (lane == -1)
1887 lane = NEON_INTERLEAVE_LANES;
1888 else if (lane != NEON_INTERLEAVE_LANES)
1889 {
dcbf9037 1890 first_error (_(type_error));
5287ad62
JB
1891 return FAIL;
1892 }
1893 count++;
1894 }
1895 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1896
1897 /* No lane set by [x]. We must be interleaving structures. */
1898 if (lane == -1)
1899 lane = NEON_INTERLEAVE_LANES;
1900
1901 /* Sanity check. */
1902 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1903 || (count > 1 && reg_incr == -1))
1904 {
dcbf9037 1905 first_error (_("error parsing element/structure list"));
5287ad62
JB
1906 return FAIL;
1907 }
1908
1909 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1910 {
dcbf9037 1911 first_error (_("expected }"));
5287ad62
JB
1912 return FAIL;
1913 }
1914
1915 if (reg_incr == -1)
1916 reg_incr = 1;
1917
dcbf9037
JB
1918 if (eltype)
1919 *eltype = firsttype.eltype;
1920
5287ad62
JB
1921 *pbase = base_reg;
1922 *str = ptr;
1923
1924 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1925}
1926
c19d1205
ZW
1927/* Parse an explicit relocation suffix on an expression. This is
1928 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1929 arm_reloc_hsh contains no entries, so this function can only
1930 succeed if there is no () after the word. Returns -1 on error,
1931 BFD_RELOC_UNUSED if there wasn't any suffix. */
1932static int
1933parse_reloc (char **str)
b99bd4ef 1934{
c19d1205
ZW
1935 struct reloc_entry *r;
1936 char *p, *q;
b99bd4ef 1937
c19d1205
ZW
1938 if (**str != '(')
1939 return BFD_RELOC_UNUSED;
b99bd4ef 1940
c19d1205
ZW
1941 p = *str + 1;
1942 q = p;
1943
1944 while (*q && *q != ')' && *q != ',')
1945 q++;
1946 if (*q != ')')
1947 return -1;
1948
1949 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1950 return -1;
1951
1952 *str = q + 1;
1953 return r->reloc;
b99bd4ef
NC
1954}
1955
c19d1205
ZW
1956/* Directives: register aliases. */
1957
dcbf9037 1958static struct reg_entry *
c19d1205 1959insert_reg_alias (char *str, int number, int type)
b99bd4ef 1960{
c19d1205
ZW
1961 struct reg_entry *new;
1962 const char *name;
b99bd4ef 1963
c19d1205
ZW
1964 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1965 {
1966 if (new->builtin)
1967 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1968
c19d1205
ZW
1969 /* Only warn about a redefinition if it's not defined as the
1970 same register. */
1971 else if (new->number != number || new->type != type)
1972 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1973
dcbf9037 1974 return 0;
c19d1205 1975 }
b99bd4ef 1976
c19d1205
ZW
1977 name = xstrdup (str);
1978 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1979
c19d1205
ZW
1980 new->name = name;
1981 new->number = number;
1982 new->type = type;
1983 new->builtin = FALSE;
dcbf9037 1984 new->neon = NULL;
b99bd4ef 1985
c19d1205
ZW
1986 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1987 abort ();
dcbf9037
JB
1988
1989 return new;
1990}
1991
1992static void
1993insert_neon_reg_alias (char *str, int number, int type,
1994 struct neon_typed_alias *atype)
1995{
1996 struct reg_entry *reg = insert_reg_alias (str, number, type);
1997
1998 if (!reg)
1999 {
2000 first_error (_("attempt to redefine typed alias"));
2001 return;
2002 }
2003
2004 if (atype)
2005 {
2006 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2007 *reg->neon = *atype;
2008 }
c19d1205 2009}
b99bd4ef 2010
c19d1205 2011/* Look for the .req directive. This is of the form:
b99bd4ef 2012
c19d1205 2013 new_register_name .req existing_register_name
b99bd4ef 2014
c19d1205
ZW
2015 If we find one, or if it looks sufficiently like one that we want to
2016 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 2017
c19d1205
ZW
2018static int
2019create_register_alias (char * newname, char *p)
2020{
2021 struct reg_entry *old;
2022 char *oldname, *nbuf;
2023 size_t nlen;
b99bd4ef 2024
c19d1205
ZW
2025 /* The input scrubber ensures that whitespace after the mnemonic is
2026 collapsed to single spaces. */
2027 oldname = p;
2028 if (strncmp (oldname, " .req ", 6) != 0)
2029 return 0;
b99bd4ef 2030
c19d1205
ZW
2031 oldname += 6;
2032 if (*oldname == '\0')
2033 return 0;
b99bd4ef 2034
c19d1205
ZW
2035 old = hash_find (arm_reg_hsh, oldname);
2036 if (!old)
b99bd4ef 2037 {
c19d1205
ZW
2038 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2039 return 1;
b99bd4ef
NC
2040 }
2041
c19d1205
ZW
2042 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2043 the desired alias name, and p points to its end. If not, then
2044 the desired alias name is in the global original_case_string. */
2045#ifdef TC_CASE_SENSITIVE
2046 nlen = p - newname;
2047#else
2048 newname = original_case_string;
2049 nlen = strlen (newname);
2050#endif
b99bd4ef 2051
c19d1205
ZW
2052 nbuf = alloca (nlen + 1);
2053 memcpy (nbuf, newname, nlen);
2054 nbuf[nlen] = '\0';
b99bd4ef 2055
c19d1205
ZW
2056 /* Create aliases under the new name as stated; an all-lowercase
2057 version of the new name; and an all-uppercase version of the new
2058 name. */
2059 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 2060
c19d1205
ZW
2061 for (p = nbuf; *p; p++)
2062 *p = TOUPPER (*p);
2063
2064 if (strncmp (nbuf, newname, nlen))
2065 insert_reg_alias (nbuf, old->number, old->type);
2066
2067 for (p = nbuf; *p; p++)
2068 *p = TOLOWER (*p);
2069
2070 if (strncmp (nbuf, newname, nlen))
2071 insert_reg_alias (nbuf, old->number, old->type);
2072
2073 return 1;
b99bd4ef
NC
2074}
2075
dcbf9037
JB
2076/* Create a Neon typed/indexed register alias using directives, e.g.:
2077 X .dn d5.s32[1]
2078 Y .qn 6.s16
2079 Z .dn d7
2080 T .dn Z[0]
2081 These typed registers can be used instead of the types specified after the
2082 Neon mnemonic, so long as all operands given have types. Types can also be
2083 specified directly, e.g.:
2084 vadd d0.s32, d1.s32, d2.s32
2085*/
2086
2087static int
2088create_neon_reg_alias (char *newname, char *p)
2089{
2090 enum arm_reg_type basetype;
2091 struct reg_entry *basereg;
2092 struct reg_entry mybasereg;
2093 struct neon_type ntype;
2094 struct neon_typed_alias typeinfo;
2095 char *namebuf, *nameend;
2096 int namelen;
2097
2098 typeinfo.defined = 0;
2099 typeinfo.eltype.type = NT_invtype;
2100 typeinfo.eltype.size = -1;
2101 typeinfo.index = -1;
2102
2103 nameend = p;
2104
2105 if (strncmp (p, " .dn ", 5) == 0)
2106 basetype = REG_TYPE_VFD;
2107 else if (strncmp (p, " .qn ", 5) == 0)
2108 basetype = REG_TYPE_NQ;
2109 else
2110 return 0;
2111
2112 p += 5;
2113
2114 if (*p == '\0')
2115 return 0;
2116
2117 basereg = arm_reg_parse_multi (&p);
2118
2119 if (basereg && basereg->type != basetype)
2120 {
2121 as_bad (_("bad type for register"));
2122 return 0;
2123 }
2124
2125 if (basereg == NULL)
2126 {
2127 expressionS exp;
2128 /* Try parsing as an integer. */
2129 my_get_expression (&exp, &p, GE_NO_PREFIX);
2130 if (exp.X_op != O_constant)
2131 {
2132 as_bad (_("expression must be constant"));
2133 return 0;
2134 }
2135 basereg = &mybasereg;
2136 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2137 : exp.X_add_number;
2138 basereg->neon = 0;
2139 }
2140
2141 if (basereg->neon)
2142 typeinfo = *basereg->neon;
2143
2144 if (parse_neon_type (&ntype, &p) == SUCCESS)
2145 {
2146 /* We got a type. */
2147 if (typeinfo.defined & NTA_HASTYPE)
2148 {
2149 as_bad (_("can't redefine the type of a register alias"));
2150 return 0;
2151 }
2152
2153 typeinfo.defined |= NTA_HASTYPE;
2154 if (ntype.elems != 1)
2155 {
2156 as_bad (_("you must specify a single type only"));
2157 return 0;
2158 }
2159 typeinfo.eltype = ntype.el[0];
2160 }
2161
2162 if (skip_past_char (&p, '[') == SUCCESS)
2163 {
2164 expressionS exp;
2165 /* We got a scalar index. */
2166
2167 if (typeinfo.defined & NTA_HASINDEX)
2168 {
2169 as_bad (_("can't redefine the index of a scalar alias"));
2170 return 0;
2171 }
2172
2173 my_get_expression (&exp, &p, GE_NO_PREFIX);
2174
2175 if (exp.X_op != O_constant)
2176 {
2177 as_bad (_("scalar index must be constant"));
2178 return 0;
2179 }
2180
2181 typeinfo.defined |= NTA_HASINDEX;
2182 typeinfo.index = exp.X_add_number;
2183
2184 if (skip_past_char (&p, ']') == FAIL)
2185 {
2186 as_bad (_("expecting ]"));
2187 return 0;
2188 }
2189 }
2190
2191 namelen = nameend - newname;
2192 namebuf = alloca (namelen + 1);
2193 strncpy (namebuf, newname, namelen);
2194 namebuf[namelen] = '\0';
2195
2196 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2197 typeinfo.defined != 0 ? &typeinfo : NULL);
2198
2199 /* Insert name in all uppercase. */
2200 for (p = namebuf; *p; p++)
2201 *p = TOUPPER (*p);
2202
2203 if (strncmp (namebuf, newname, namelen))
2204 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2205 typeinfo.defined != 0 ? &typeinfo : NULL);
2206
2207 /* Insert name in all lowercase. */
2208 for (p = namebuf; *p; p++)
2209 *p = TOLOWER (*p);
2210
2211 if (strncmp (namebuf, newname, namelen))
2212 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2213 typeinfo.defined != 0 ? &typeinfo : NULL);
2214
2215 return 1;
2216}
2217
c19d1205
ZW
2218/* Should never be called, as .req goes between the alias and the
2219 register name, not at the beginning of the line. */
b99bd4ef 2220static void
c19d1205 2221s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2222{
c19d1205
ZW
2223 as_bad (_("invalid syntax for .req directive"));
2224}
b99bd4ef 2225
dcbf9037
JB
2226static void
2227s_dn (int a ATTRIBUTE_UNUSED)
2228{
2229 as_bad (_("invalid syntax for .dn directive"));
2230}
2231
2232static void
2233s_qn (int a ATTRIBUTE_UNUSED)
2234{
2235 as_bad (_("invalid syntax for .qn directive"));
2236}
2237
c19d1205
ZW
2238/* The .unreq directive deletes an alias which was previously defined
2239 by .req. For example:
b99bd4ef 2240
c19d1205
ZW
2241 my_alias .req r11
2242 .unreq my_alias */
b99bd4ef
NC
2243
2244static void
c19d1205 2245s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2246{
c19d1205
ZW
2247 char * name;
2248 char saved_char;
b99bd4ef 2249
c19d1205
ZW
2250 name = input_line_pointer;
2251
2252 while (*input_line_pointer != 0
2253 && *input_line_pointer != ' '
2254 && *input_line_pointer != '\n')
2255 ++input_line_pointer;
2256
2257 saved_char = *input_line_pointer;
2258 *input_line_pointer = 0;
2259
2260 if (!*name)
2261 as_bad (_("invalid syntax for .unreq directive"));
2262 else
2263 {
2264 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2265
2266 if (!reg)
2267 as_bad (_("unknown register alias '%s'"), name);
2268 else if (reg->builtin)
2269 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2270 name);
2271 else
2272 {
2273 hash_delete (arm_reg_hsh, name);
2274 free ((char *) reg->name);
dcbf9037
JB
2275 if (reg->neon)
2276 free (reg->neon);
c19d1205
ZW
2277 free (reg);
2278 }
2279 }
b99bd4ef 2280
c19d1205 2281 *input_line_pointer = saved_char;
b99bd4ef
NC
2282 demand_empty_rest_of_line ();
2283}
2284
c19d1205
ZW
2285/* Directives: Instruction set selection. */
2286
2287#ifdef OBJ_ELF
2288/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2289 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2290 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2291 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2292
2293static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2294
e821645d 2295void
c19d1205 2296mapping_state (enum mstate state)
b99bd4ef 2297{
a737bd4d 2298 symbolS * symbolP;
c19d1205
ZW
2299 const char * symname;
2300 int type;
b99bd4ef 2301
c19d1205
ZW
2302 if (mapstate == state)
2303 /* The mapping symbol has already been emitted.
2304 There is nothing else to do. */
2305 return;
b99bd4ef 2306
c19d1205 2307 mapstate = state;
b99bd4ef 2308
c19d1205 2309 switch (state)
b99bd4ef 2310 {
c19d1205
ZW
2311 case MAP_DATA:
2312 symname = "$d";
2313 type = BSF_NO_FLAGS;
2314 break;
2315 case MAP_ARM:
2316 symname = "$a";
2317 type = BSF_NO_FLAGS;
2318 break;
2319 case MAP_THUMB:
2320 symname = "$t";
2321 type = BSF_NO_FLAGS;
2322 break;
2323 case MAP_UNDEFINED:
2324 return;
2325 default:
2326 abort ();
2327 }
2328
2329 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2330
2331 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2332 symbol_table_insert (symbolP);
2333 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2334
2335 switch (state)
2336 {
2337 case MAP_ARM:
2338 THUMB_SET_FUNC (symbolP, 0);
2339 ARM_SET_THUMB (symbolP, 0);
2340 ARM_SET_INTERWORK (symbolP, support_interwork);
2341 break;
2342
2343 case MAP_THUMB:
2344 THUMB_SET_FUNC (symbolP, 1);
2345 ARM_SET_THUMB (symbolP, 1);
2346 ARM_SET_INTERWORK (symbolP, support_interwork);
2347 break;
2348
2349 case MAP_DATA:
2350 default:
2351 return;
2352 }
2353}
2354#else
2355#define mapping_state(x) /* nothing */
2356#endif
2357
2358/* Find the real, Thumb encoded start of a Thumb function. */
2359
2360static symbolS *
2361find_real_start (symbolS * symbolP)
2362{
2363 char * real_start;
2364 const char * name = S_GET_NAME (symbolP);
2365 symbolS * new_target;
2366
2367 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2368#define STUB_NAME ".real_start_of"
2369
2370 if (name == NULL)
2371 abort ();
2372
37f6032b
ZW
2373 /* The compiler may generate BL instructions to local labels because
2374 it needs to perform a branch to a far away location. These labels
2375 do not have a corresponding ".real_start_of" label. We check
2376 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2377 the ".real_start_of" convention for nonlocal branches. */
2378 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2379 return symbolP;
2380
37f6032b 2381 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2382 new_target = symbol_find (real_start);
2383
2384 if (new_target == NULL)
2385 {
2386 as_warn ("Failed to find real start of function: %s\n", name);
2387 new_target = symbolP;
2388 }
2389
c19d1205
ZW
2390 return new_target;
2391}
2392
2393static void
2394opcode_select (int width)
2395{
2396 switch (width)
2397 {
2398 case 16:
2399 if (! thumb_mode)
2400 {
e74cfd16 2401 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2402 as_bad (_("selected processor does not support THUMB opcodes"));
2403
2404 thumb_mode = 1;
2405 /* No need to force the alignment, since we will have been
2406 coming from ARM mode, which is word-aligned. */
2407 record_alignment (now_seg, 1);
2408 }
2409 mapping_state (MAP_THUMB);
2410 break;
2411
2412 case 32:
2413 if (thumb_mode)
2414 {
e74cfd16 2415 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2416 as_bad (_("selected processor does not support ARM opcodes"));
2417
2418 thumb_mode = 0;
2419
2420 if (!need_pass_2)
2421 frag_align (2, 0, 0);
2422
2423 record_alignment (now_seg, 1);
2424 }
2425 mapping_state (MAP_ARM);
2426 break;
2427
2428 default:
2429 as_bad (_("invalid instruction size selected (%d)"), width);
2430 }
2431}
2432
2433static void
2434s_arm (int ignore ATTRIBUTE_UNUSED)
2435{
2436 opcode_select (32);
2437 demand_empty_rest_of_line ();
2438}
2439
2440static void
2441s_thumb (int ignore ATTRIBUTE_UNUSED)
2442{
2443 opcode_select (16);
2444 demand_empty_rest_of_line ();
2445}
2446
2447static void
2448s_code (int unused ATTRIBUTE_UNUSED)
2449{
2450 int temp;
2451
2452 temp = get_absolute_expression ();
2453 switch (temp)
2454 {
2455 case 16:
2456 case 32:
2457 opcode_select (temp);
2458 break;
2459
2460 default:
2461 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2462 }
2463}
2464
2465static void
2466s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2467{
2468 /* If we are not already in thumb mode go into it, EVEN if
2469 the target processor does not support thumb instructions.
2470 This is used by gcc/config/arm/lib1funcs.asm for example
2471 to compile interworking support functions even if the
2472 target processor should not support interworking. */
2473 if (! thumb_mode)
2474 {
2475 thumb_mode = 2;
2476 record_alignment (now_seg, 1);
2477 }
2478
2479 demand_empty_rest_of_line ();
2480}
2481
2482static void
2483s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2484{
2485 s_thumb (0);
2486
2487 /* The following label is the name/address of the start of a Thumb function.
2488 We need to know this for the interworking support. */
2489 label_is_thumb_function_name = TRUE;
2490}
2491
2492/* Perform a .set directive, but also mark the alias as
2493 being a thumb function. */
2494
2495static void
2496s_thumb_set (int equiv)
2497{
2498 /* XXX the following is a duplicate of the code for s_set() in read.c
2499 We cannot just call that code as we need to get at the symbol that
2500 is created. */
2501 char * name;
2502 char delim;
2503 char * end_name;
2504 symbolS * symbolP;
2505
2506 /* Especial apologies for the random logic:
2507 This just grew, and could be parsed much more simply!
2508 Dean - in haste. */
2509 name = input_line_pointer;
2510 delim = get_symbol_end ();
2511 end_name = input_line_pointer;
2512 *end_name = delim;
2513
2514 if (*input_line_pointer != ',')
2515 {
2516 *end_name = 0;
2517 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2518 *end_name = delim;
2519 ignore_rest_of_line ();
2520 return;
2521 }
2522
2523 input_line_pointer++;
2524 *end_name = 0;
2525
2526 if (name[0] == '.' && name[1] == '\0')
2527 {
2528 /* XXX - this should not happen to .thumb_set. */
2529 abort ();
2530 }
2531
2532 if ((symbolP = symbol_find (name)) == NULL
2533 && (symbolP = md_undefined_symbol (name)) == NULL)
2534 {
2535#ifndef NO_LISTING
2536 /* When doing symbol listings, play games with dummy fragments living
2537 outside the normal fragment chain to record the file and line info
c19d1205 2538 for this symbol. */
b99bd4ef
NC
2539 if (listing & LISTING_SYMBOLS)
2540 {
2541 extern struct list_info_struct * listing_tail;
a737bd4d 2542 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2543
2544 memset (dummy_frag, 0, sizeof (fragS));
2545 dummy_frag->fr_type = rs_fill;
2546 dummy_frag->line = listing_tail;
2547 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2548 dummy_frag->fr_symbol = symbolP;
2549 }
2550 else
2551#endif
2552 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2553
2554#ifdef OBJ_COFF
2555 /* "set" symbols are local unless otherwise specified. */
2556 SF_SET_LOCAL (symbolP);
2557#endif /* OBJ_COFF */
2558 } /* Make a new symbol. */
2559
2560 symbol_table_insert (symbolP);
2561
2562 * end_name = delim;
2563
2564 if (equiv
2565 && S_IS_DEFINED (symbolP)
2566 && S_GET_SEGMENT (symbolP) != reg_section)
2567 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2568
2569 pseudo_set (symbolP);
2570
2571 demand_empty_rest_of_line ();
2572
c19d1205 2573 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2574
2575 THUMB_SET_FUNC (symbolP, 1);
2576 ARM_SET_THUMB (symbolP, 1);
2577#if defined OBJ_ELF || defined OBJ_COFF
2578 ARM_SET_INTERWORK (symbolP, support_interwork);
2579#endif
2580}
2581
c19d1205 2582/* Directives: Mode selection. */
b99bd4ef 2583
c19d1205
ZW
2584/* .syntax [unified|divided] - choose the new unified syntax
2585 (same for Arm and Thumb encoding, modulo slight differences in what
2586 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2587static void
c19d1205 2588s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2589{
c19d1205
ZW
2590 char *name, delim;
2591
2592 name = input_line_pointer;
2593 delim = get_symbol_end ();
2594
2595 if (!strcasecmp (name, "unified"))
2596 unified_syntax = TRUE;
2597 else if (!strcasecmp (name, "divided"))
2598 unified_syntax = FALSE;
2599 else
2600 {
2601 as_bad (_("unrecognized syntax mode \"%s\""), name);
2602 return;
2603 }
2604 *input_line_pointer = delim;
b99bd4ef
NC
2605 demand_empty_rest_of_line ();
2606}
2607
c19d1205
ZW
2608/* Directives: sectioning and alignment. */
2609
2610/* Same as s_align_ptwo but align 0 => align 2. */
2611
b99bd4ef 2612static void
c19d1205 2613s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2614{
a737bd4d 2615 int temp;
dce323d1 2616 bfd_boolean fill_p;
c19d1205
ZW
2617 long temp_fill;
2618 long max_alignment = 15;
b99bd4ef
NC
2619
2620 temp = get_absolute_expression ();
c19d1205
ZW
2621 if (temp > max_alignment)
2622 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2623 else if (temp < 0)
b99bd4ef 2624 {
c19d1205
ZW
2625 as_bad (_("alignment negative. 0 assumed."));
2626 temp = 0;
2627 }
b99bd4ef 2628
c19d1205
ZW
2629 if (*input_line_pointer == ',')
2630 {
2631 input_line_pointer++;
2632 temp_fill = get_absolute_expression ();
dce323d1 2633 fill_p = TRUE;
b99bd4ef 2634 }
c19d1205 2635 else
dce323d1
PB
2636 {
2637 fill_p = FALSE;
2638 temp_fill = 0;
2639 }
b99bd4ef 2640
c19d1205
ZW
2641 if (!temp)
2642 temp = 2;
b99bd4ef 2643
c19d1205
ZW
2644 /* Only make a frag if we HAVE to. */
2645 if (temp && !need_pass_2)
dce323d1
PB
2646 {
2647 if (!fill_p && subseg_text_p (now_seg))
2648 frag_align_code (temp, 0);
2649 else
2650 frag_align (temp, (int) temp_fill, 0);
2651 }
c19d1205
ZW
2652 demand_empty_rest_of_line ();
2653
2654 record_alignment (now_seg, temp);
b99bd4ef
NC
2655}
2656
c19d1205
ZW
2657static void
2658s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2659{
c19d1205
ZW
2660 /* We don't support putting frags in the BSS segment, we fake it by
2661 marking in_bss, then looking at s_skip for clues. */
2662 subseg_set (bss_section, 0);
2663 demand_empty_rest_of_line ();
2664 mapping_state (MAP_DATA);
2665}
b99bd4ef 2666
c19d1205
ZW
2667static void
2668s_even (int ignore ATTRIBUTE_UNUSED)
2669{
2670 /* Never make frag if expect extra pass. */
2671 if (!need_pass_2)
2672 frag_align (1, 0, 0);
b99bd4ef 2673
c19d1205 2674 record_alignment (now_seg, 1);
b99bd4ef 2675
c19d1205 2676 demand_empty_rest_of_line ();
b99bd4ef
NC
2677}
2678
c19d1205 2679/* Directives: Literal pools. */
a737bd4d 2680
c19d1205
ZW
2681static literal_pool *
2682find_literal_pool (void)
a737bd4d 2683{
c19d1205 2684 literal_pool * pool;
a737bd4d 2685
c19d1205 2686 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2687 {
c19d1205
ZW
2688 if (pool->section == now_seg
2689 && pool->sub_section == now_subseg)
2690 break;
a737bd4d
NC
2691 }
2692
c19d1205 2693 return pool;
a737bd4d
NC
2694}
2695
c19d1205
ZW
2696static literal_pool *
2697find_or_make_literal_pool (void)
a737bd4d 2698{
c19d1205
ZW
2699 /* Next literal pool ID number. */
2700 static unsigned int latest_pool_num = 1;
2701 literal_pool * pool;
a737bd4d 2702
c19d1205 2703 pool = find_literal_pool ();
a737bd4d 2704
c19d1205 2705 if (pool == NULL)
a737bd4d 2706 {
c19d1205
ZW
2707 /* Create a new pool. */
2708 pool = xmalloc (sizeof (* pool));
2709 if (! pool)
2710 return NULL;
a737bd4d 2711
c19d1205
ZW
2712 pool->next_free_entry = 0;
2713 pool->section = now_seg;
2714 pool->sub_section = now_subseg;
2715 pool->next = list_of_pools;
2716 pool->symbol = NULL;
2717
2718 /* Add it to the list. */
2719 list_of_pools = pool;
a737bd4d 2720 }
a737bd4d 2721
c19d1205
ZW
2722 /* New pools, and emptied pools, will have a NULL symbol. */
2723 if (pool->symbol == NULL)
a737bd4d 2724 {
c19d1205
ZW
2725 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2726 (valueT) 0, &zero_address_frag);
2727 pool->id = latest_pool_num ++;
a737bd4d
NC
2728 }
2729
c19d1205
ZW
2730 /* Done. */
2731 return pool;
a737bd4d
NC
2732}
2733
c19d1205
ZW
2734/* Add the literal in the global 'inst'
2735 structure to the relevent literal pool. */
b99bd4ef
NC
2736
2737static int
c19d1205 2738add_to_lit_pool (void)
b99bd4ef 2739{
c19d1205
ZW
2740 literal_pool * pool;
2741 unsigned int entry;
b99bd4ef 2742
c19d1205
ZW
2743 pool = find_or_make_literal_pool ();
2744
2745 /* Check if this literal value is already in the pool. */
2746 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2747 {
c19d1205
ZW
2748 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2749 && (inst.reloc.exp.X_op == O_constant)
2750 && (pool->literals[entry].X_add_number
2751 == inst.reloc.exp.X_add_number)
2752 && (pool->literals[entry].X_unsigned
2753 == inst.reloc.exp.X_unsigned))
2754 break;
2755
2756 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2757 && (inst.reloc.exp.X_op == O_symbol)
2758 && (pool->literals[entry].X_add_number
2759 == inst.reloc.exp.X_add_number)
2760 && (pool->literals[entry].X_add_symbol
2761 == inst.reloc.exp.X_add_symbol)
2762 && (pool->literals[entry].X_op_symbol
2763 == inst.reloc.exp.X_op_symbol))
2764 break;
b99bd4ef
NC
2765 }
2766
c19d1205
ZW
2767 /* Do we need to create a new entry? */
2768 if (entry == pool->next_free_entry)
2769 {
2770 if (entry >= MAX_LITERAL_POOL_SIZE)
2771 {
2772 inst.error = _("literal pool overflow");
2773 return FAIL;
2774 }
2775
2776 pool->literals[entry] = inst.reloc.exp;
2777 pool->next_free_entry += 1;
2778 }
b99bd4ef 2779
c19d1205
ZW
2780 inst.reloc.exp.X_op = O_symbol;
2781 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2782 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2783
c19d1205 2784 return SUCCESS;
b99bd4ef
NC
2785}
2786
c19d1205
ZW
2787/* Can't use symbol_new here, so have to create a symbol and then at
2788 a later date assign it a value. Thats what these functions do. */
e16bb312 2789
c19d1205
ZW
2790static void
2791symbol_locate (symbolS * symbolP,
2792 const char * name, /* It is copied, the caller can modify. */
2793 segT segment, /* Segment identifier (SEG_<something>). */
2794 valueT valu, /* Symbol value. */
2795 fragS * frag) /* Associated fragment. */
2796{
2797 unsigned int name_length;
2798 char * preserved_copy_of_name;
e16bb312 2799
c19d1205
ZW
2800 name_length = strlen (name) + 1; /* +1 for \0. */
2801 obstack_grow (&notes, name, name_length);
2802 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2803
c19d1205
ZW
2804#ifdef tc_canonicalize_symbol_name
2805 preserved_copy_of_name =
2806 tc_canonicalize_symbol_name (preserved_copy_of_name);
2807#endif
b99bd4ef 2808
c19d1205 2809 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2810
c19d1205
ZW
2811 S_SET_SEGMENT (symbolP, segment);
2812 S_SET_VALUE (symbolP, valu);
2813 symbol_clear_list_pointers (symbolP);
b99bd4ef 2814
c19d1205 2815 symbol_set_frag (symbolP, frag);
b99bd4ef 2816
c19d1205
ZW
2817 /* Link to end of symbol chain. */
2818 {
2819 extern int symbol_table_frozen;
b99bd4ef 2820
c19d1205
ZW
2821 if (symbol_table_frozen)
2822 abort ();
2823 }
b99bd4ef 2824
c19d1205 2825 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2826
c19d1205 2827 obj_symbol_new_hook (symbolP);
b99bd4ef 2828
c19d1205
ZW
2829#ifdef tc_symbol_new_hook
2830 tc_symbol_new_hook (symbolP);
2831#endif
2832
2833#ifdef DEBUG_SYMS
2834 verify_symbol_chain (symbol_rootP, symbol_lastP);
2835#endif /* DEBUG_SYMS */
b99bd4ef
NC
2836}
2837
b99bd4ef 2838
c19d1205
ZW
2839static void
2840s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2841{
c19d1205
ZW
2842 unsigned int entry;
2843 literal_pool * pool;
2844 char sym_name[20];
b99bd4ef 2845
c19d1205
ZW
2846 pool = find_literal_pool ();
2847 if (pool == NULL
2848 || pool->symbol == NULL
2849 || pool->next_free_entry == 0)
2850 return;
b99bd4ef 2851
c19d1205 2852 mapping_state (MAP_DATA);
b99bd4ef 2853
c19d1205
ZW
2854 /* Align pool as you have word accesses.
2855 Only make a frag if we have to. */
2856 if (!need_pass_2)
2857 frag_align (2, 0, 0);
b99bd4ef 2858
c19d1205 2859 record_alignment (now_seg, 2);
b99bd4ef 2860
c19d1205 2861 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2862
c19d1205
ZW
2863 symbol_locate (pool->symbol, sym_name, now_seg,
2864 (valueT) frag_now_fix (), frag_now);
2865 symbol_table_insert (pool->symbol);
b99bd4ef 2866
c19d1205 2867 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2868
c19d1205
ZW
2869#if defined OBJ_COFF || defined OBJ_ELF
2870 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2871#endif
6c43fab6 2872
c19d1205
ZW
2873 for (entry = 0; entry < pool->next_free_entry; entry ++)
2874 /* First output the expression in the instruction to the pool. */
2875 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2876
c19d1205
ZW
2877 /* Mark the pool as empty. */
2878 pool->next_free_entry = 0;
2879 pool->symbol = NULL;
b99bd4ef
NC
2880}
2881
c19d1205
ZW
2882#ifdef OBJ_ELF
2883/* Forward declarations for functions below, in the MD interface
2884 section. */
2885static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2886static valueT create_unwind_entry (int);
2887static void start_unwind_section (const segT, int);
2888static void add_unwind_opcode (valueT, int);
2889static void flush_pending_unwind (void);
b99bd4ef 2890
c19d1205 2891/* Directives: Data. */
b99bd4ef 2892
c19d1205
ZW
2893static void
2894s_arm_elf_cons (int nbytes)
2895{
2896 expressionS exp;
b99bd4ef 2897
c19d1205
ZW
2898#ifdef md_flush_pending_output
2899 md_flush_pending_output ();
2900#endif
b99bd4ef 2901
c19d1205 2902 if (is_it_end_of_statement ())
b99bd4ef 2903 {
c19d1205
ZW
2904 demand_empty_rest_of_line ();
2905 return;
b99bd4ef
NC
2906 }
2907
c19d1205
ZW
2908#ifdef md_cons_align
2909 md_cons_align (nbytes);
2910#endif
b99bd4ef 2911
c19d1205
ZW
2912 mapping_state (MAP_DATA);
2913 do
b99bd4ef 2914 {
c19d1205
ZW
2915 int reloc;
2916 char *base = input_line_pointer;
b99bd4ef 2917
c19d1205 2918 expression (& exp);
b99bd4ef 2919
c19d1205
ZW
2920 if (exp.X_op != O_symbol)
2921 emit_expr (&exp, (unsigned int) nbytes);
2922 else
2923 {
2924 char *before_reloc = input_line_pointer;
2925 reloc = parse_reloc (&input_line_pointer);
2926 if (reloc == -1)
2927 {
2928 as_bad (_("unrecognized relocation suffix"));
2929 ignore_rest_of_line ();
2930 return;
2931 }
2932 else if (reloc == BFD_RELOC_UNUSED)
2933 emit_expr (&exp, (unsigned int) nbytes);
2934 else
2935 {
2936 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2937 int size = bfd_get_reloc_size (howto);
b99bd4ef 2938
2fc8bdac
ZW
2939 if (reloc == BFD_RELOC_ARM_PLT32)
2940 {
2941 as_bad (_("(plt) is only valid on branch targets"));
2942 reloc = BFD_RELOC_UNUSED;
2943 size = 0;
2944 }
2945
c19d1205 2946 if (size > nbytes)
2fc8bdac 2947 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2948 howto->name, nbytes);
2949 else
2950 {
2951 /* We've parsed an expression stopping at O_symbol.
2952 But there may be more expression left now that we
2953 have parsed the relocation marker. Parse it again.
2954 XXX Surely there is a cleaner way to do this. */
2955 char *p = input_line_pointer;
2956 int offset;
2957 char *save_buf = alloca (input_line_pointer - base);
2958 memcpy (save_buf, base, input_line_pointer - base);
2959 memmove (base + (input_line_pointer - before_reloc),
2960 base, before_reloc - base);
2961
2962 input_line_pointer = base + (input_line_pointer-before_reloc);
2963 expression (&exp);
2964 memcpy (base, save_buf, p - base);
2965
2966 offset = nbytes - size;
2967 p = frag_more ((int) nbytes);
2968 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2969 size, &exp, 0, reloc);
2970 }
2971 }
2972 }
b99bd4ef 2973 }
c19d1205 2974 while (*input_line_pointer++ == ',');
b99bd4ef 2975
c19d1205
ZW
2976 /* Put terminator back into stream. */
2977 input_line_pointer --;
2978 demand_empty_rest_of_line ();
b99bd4ef
NC
2979}
2980
b99bd4ef 2981
c19d1205 2982/* Parse a .rel31 directive. */
b99bd4ef 2983
c19d1205
ZW
2984static void
2985s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2986{
2987 expressionS exp;
2988 char *p;
2989 valueT highbit;
b99bd4ef 2990
c19d1205
ZW
2991 highbit = 0;
2992 if (*input_line_pointer == '1')
2993 highbit = 0x80000000;
2994 else if (*input_line_pointer != '0')
2995 as_bad (_("expected 0 or 1"));
b99bd4ef 2996
c19d1205
ZW
2997 input_line_pointer++;
2998 if (*input_line_pointer != ',')
2999 as_bad (_("missing comma"));
3000 input_line_pointer++;
b99bd4ef 3001
c19d1205
ZW
3002#ifdef md_flush_pending_output
3003 md_flush_pending_output ();
3004#endif
b99bd4ef 3005
c19d1205
ZW
3006#ifdef md_cons_align
3007 md_cons_align (4);
3008#endif
b99bd4ef 3009
c19d1205 3010 mapping_state (MAP_DATA);
b99bd4ef 3011
c19d1205 3012 expression (&exp);
b99bd4ef 3013
c19d1205
ZW
3014 p = frag_more (4);
3015 md_number_to_chars (p, highbit, 4);
3016 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3017 BFD_RELOC_ARM_PREL31);
b99bd4ef 3018
c19d1205 3019 demand_empty_rest_of_line ();
b99bd4ef
NC
3020}
3021
c19d1205 3022/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3023
c19d1205 3024/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3025
c19d1205
ZW
3026static void
3027s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3028{
3029 demand_empty_rest_of_line ();
3030 /* Mark the start of the function. */
3031 unwind.proc_start = expr_build_dot ();
b99bd4ef 3032
c19d1205
ZW
3033 /* Reset the rest of the unwind info. */
3034 unwind.opcode_count = 0;
3035 unwind.table_entry = NULL;
3036 unwind.personality_routine = NULL;
3037 unwind.personality_index = -1;
3038 unwind.frame_size = 0;
3039 unwind.fp_offset = 0;
3040 unwind.fp_reg = 13;
3041 unwind.fp_used = 0;
3042 unwind.sp_restored = 0;
3043}
b99bd4ef 3044
b99bd4ef 3045
c19d1205
ZW
3046/* Parse a handlerdata directive. Creates the exception handling table entry
3047 for the function. */
b99bd4ef 3048
c19d1205
ZW
3049static void
3050s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3051{
3052 demand_empty_rest_of_line ();
3053 if (unwind.table_entry)
3054 as_bad (_("dupicate .handlerdata directive"));
f02232aa 3055
c19d1205
ZW
3056 create_unwind_entry (1);
3057}
a737bd4d 3058
c19d1205 3059/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3060
c19d1205
ZW
3061static void
3062s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3063{
3064 long where;
3065 char *ptr;
3066 valueT val;
f02232aa 3067
c19d1205 3068 demand_empty_rest_of_line ();
f02232aa 3069
c19d1205
ZW
3070 /* Add eh table entry. */
3071 if (unwind.table_entry == NULL)
3072 val = create_unwind_entry (0);
3073 else
3074 val = 0;
f02232aa 3075
c19d1205
ZW
3076 /* Add index table entry. This is two words. */
3077 start_unwind_section (unwind.saved_seg, 1);
3078 frag_align (2, 0, 0);
3079 record_alignment (now_seg, 2);
b99bd4ef 3080
c19d1205
ZW
3081 ptr = frag_more (8);
3082 where = frag_now_fix () - 8;
f02232aa 3083
c19d1205
ZW
3084 /* Self relative offset of the function start. */
3085 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3086 BFD_RELOC_ARM_PREL31);
f02232aa 3087
c19d1205
ZW
3088 /* Indicate dependency on EHABI-defined personality routines to the
3089 linker, if it hasn't been done already. */
3090 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3091 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3092 {
3093 static const char *const name[] = {
3094 "__aeabi_unwind_cpp_pr0",
3095 "__aeabi_unwind_cpp_pr1",
3096 "__aeabi_unwind_cpp_pr2"
3097 };
3098 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3099 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3100 marked_pr_dependency |= 1 << unwind.personality_index;
3101 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3102 = marked_pr_dependency;
3103 }
f02232aa 3104
c19d1205
ZW
3105 if (val)
3106 /* Inline exception table entry. */
3107 md_number_to_chars (ptr + 4, val, 4);
3108 else
3109 /* Self relative offset of the table entry. */
3110 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3111 BFD_RELOC_ARM_PREL31);
f02232aa 3112
c19d1205
ZW
3113 /* Restore the original section. */
3114 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3115}
f02232aa 3116
f02232aa 3117
c19d1205 3118/* Parse an unwind_cantunwind directive. */
b99bd4ef 3119
c19d1205
ZW
3120static void
3121s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3122{
3123 demand_empty_rest_of_line ();
3124 if (unwind.personality_routine || unwind.personality_index != -1)
3125 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3126
c19d1205
ZW
3127 unwind.personality_index = -2;
3128}
b99bd4ef 3129
b99bd4ef 3130
c19d1205 3131/* Parse a personalityindex directive. */
b99bd4ef 3132
c19d1205
ZW
3133static void
3134s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3135{
3136 expressionS exp;
b99bd4ef 3137
c19d1205
ZW
3138 if (unwind.personality_routine || unwind.personality_index != -1)
3139 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3140
c19d1205 3141 expression (&exp);
b99bd4ef 3142
c19d1205
ZW
3143 if (exp.X_op != O_constant
3144 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3145 {
c19d1205
ZW
3146 as_bad (_("bad personality routine number"));
3147 ignore_rest_of_line ();
3148 return;
b99bd4ef
NC
3149 }
3150
c19d1205 3151 unwind.personality_index = exp.X_add_number;
b99bd4ef 3152
c19d1205
ZW
3153 demand_empty_rest_of_line ();
3154}
e16bb312 3155
e16bb312 3156
c19d1205 3157/* Parse a personality directive. */
e16bb312 3158
c19d1205
ZW
3159static void
3160s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3161{
3162 char *name, *p, c;
a737bd4d 3163
c19d1205
ZW
3164 if (unwind.personality_routine || unwind.personality_index != -1)
3165 as_bad (_("duplicate .personality directive"));
a737bd4d 3166
c19d1205
ZW
3167 name = input_line_pointer;
3168 c = get_symbol_end ();
3169 p = input_line_pointer;
3170 unwind.personality_routine = symbol_find_or_make (name);
3171 *p = c;
3172 demand_empty_rest_of_line ();
3173}
e16bb312 3174
e16bb312 3175
c19d1205 3176/* Parse a directive saving core registers. */
e16bb312 3177
c19d1205
ZW
3178static void
3179s_arm_unwind_save_core (void)
e16bb312 3180{
c19d1205
ZW
3181 valueT op;
3182 long range;
3183 int n;
e16bb312 3184
c19d1205
ZW
3185 range = parse_reg_list (&input_line_pointer);
3186 if (range == FAIL)
e16bb312 3187 {
c19d1205
ZW
3188 as_bad (_("expected register list"));
3189 ignore_rest_of_line ();
3190 return;
3191 }
e16bb312 3192
c19d1205 3193 demand_empty_rest_of_line ();
e16bb312 3194
c19d1205
ZW
3195 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3196 into .unwind_save {..., sp...}. We aren't bothered about the value of
3197 ip because it is clobbered by calls. */
3198 if (unwind.sp_restored && unwind.fp_reg == 12
3199 && (range & 0x3000) == 0x1000)
3200 {
3201 unwind.opcode_count--;
3202 unwind.sp_restored = 0;
3203 range = (range | 0x2000) & ~0x1000;
3204 unwind.pending_offset = 0;
3205 }
e16bb312 3206
01ae4198
DJ
3207 /* Pop r4-r15. */
3208 if (range & 0xfff0)
c19d1205 3209 {
01ae4198
DJ
3210 /* See if we can use the short opcodes. These pop a block of up to 8
3211 registers starting with r4, plus maybe r14. */
3212 for (n = 0; n < 8; n++)
3213 {
3214 /* Break at the first non-saved register. */
3215 if ((range & (1 << (n + 4))) == 0)
3216 break;
3217 }
3218 /* See if there are any other bits set. */
3219 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3220 {
3221 /* Use the long form. */
3222 op = 0x8000 | ((range >> 4) & 0xfff);
3223 add_unwind_opcode (op, 2);
3224 }
0dd132b6 3225 else
01ae4198
DJ
3226 {
3227 /* Use the short form. */
3228 if (range & 0x4000)
3229 op = 0xa8; /* Pop r14. */
3230 else
3231 op = 0xa0; /* Do not pop r14. */
3232 op |= (n - 1);
3233 add_unwind_opcode (op, 1);
3234 }
c19d1205 3235 }
0dd132b6 3236
c19d1205
ZW
3237 /* Pop r0-r3. */
3238 if (range & 0xf)
3239 {
3240 op = 0xb100 | (range & 0xf);
3241 add_unwind_opcode (op, 2);
0dd132b6
NC
3242 }
3243
c19d1205
ZW
3244 /* Record the number of bytes pushed. */
3245 for (n = 0; n < 16; n++)
3246 {
3247 if (range & (1 << n))
3248 unwind.frame_size += 4;
3249 }
0dd132b6
NC
3250}
3251
c19d1205
ZW
3252
3253/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3254
3255static void
c19d1205 3256s_arm_unwind_save_fpa (int reg)
b99bd4ef 3257{
c19d1205
ZW
3258 expressionS exp;
3259 int num_regs;
3260 valueT op;
b99bd4ef 3261
c19d1205
ZW
3262 /* Get Number of registers to transfer. */
3263 if (skip_past_comma (&input_line_pointer) != FAIL)
3264 expression (&exp);
3265 else
3266 exp.X_op = O_illegal;
b99bd4ef 3267
c19d1205 3268 if (exp.X_op != O_constant)
b99bd4ef 3269 {
c19d1205
ZW
3270 as_bad (_("expected , <constant>"));
3271 ignore_rest_of_line ();
b99bd4ef
NC
3272 return;
3273 }
3274
c19d1205
ZW
3275 num_regs = exp.X_add_number;
3276
3277 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3278 {
c19d1205
ZW
3279 as_bad (_("number of registers must be in the range [1:4]"));
3280 ignore_rest_of_line ();
b99bd4ef
NC
3281 return;
3282 }
3283
c19d1205 3284 demand_empty_rest_of_line ();
b99bd4ef 3285
c19d1205
ZW
3286 if (reg == 4)
3287 {
3288 /* Short form. */
3289 op = 0xb4 | (num_regs - 1);
3290 add_unwind_opcode (op, 1);
3291 }
b99bd4ef
NC
3292 else
3293 {
c19d1205
ZW
3294 /* Long form. */
3295 op = 0xc800 | (reg << 4) | (num_regs - 1);
3296 add_unwind_opcode (op, 2);
b99bd4ef 3297 }
c19d1205 3298 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3299}
3300
c19d1205 3301
fa073d69
MS
3302/* Parse a directive saving VFP registers for ARMv6 and above. */
3303
3304static void
3305s_arm_unwind_save_vfp_armv6 (void)
3306{
3307 int count;
3308 unsigned int start;
3309 valueT op;
3310 int num_vfpv3_regs = 0;
3311 int num_regs_below_16;
3312
3313 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3314 if (count == FAIL)
3315 {
3316 as_bad (_("expected register list"));
3317 ignore_rest_of_line ();
3318 return;
3319 }
3320
3321 demand_empty_rest_of_line ();
3322
3323 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3324 than FSTMX/FLDMX-style ones). */
3325
3326 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3327 if (start >= 16)
3328 num_vfpv3_regs = count;
3329 else if (start + count > 16)
3330 num_vfpv3_regs = start + count - 16;
3331
3332 if (num_vfpv3_regs > 0)
3333 {
3334 int start_offset = start > 16 ? start - 16 : 0;
3335 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3336 add_unwind_opcode (op, 2);
3337 }
3338
3339 /* Generate opcode for registers numbered in the range 0 .. 15. */
3340 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3341 assert (num_regs_below_16 + num_vfpv3_regs == count);
3342 if (num_regs_below_16 > 0)
3343 {
3344 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3345 add_unwind_opcode (op, 2);
3346 }
3347
3348 unwind.frame_size += count * 8;
3349}
3350
3351
3352/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3353
3354static void
c19d1205 3355s_arm_unwind_save_vfp (void)
b99bd4ef 3356{
c19d1205 3357 int count;
ca3f61f7 3358 unsigned int reg;
c19d1205 3359 valueT op;
b99bd4ef 3360
5287ad62 3361 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3362 if (count == FAIL)
b99bd4ef 3363 {
c19d1205
ZW
3364 as_bad (_("expected register list"));
3365 ignore_rest_of_line ();
b99bd4ef
NC
3366 return;
3367 }
3368
c19d1205 3369 demand_empty_rest_of_line ();
b99bd4ef 3370
c19d1205 3371 if (reg == 8)
b99bd4ef 3372 {
c19d1205
ZW
3373 /* Short form. */
3374 op = 0xb8 | (count - 1);
3375 add_unwind_opcode (op, 1);
b99bd4ef 3376 }
c19d1205 3377 else
b99bd4ef 3378 {
c19d1205
ZW
3379 /* Long form. */
3380 op = 0xb300 | (reg << 4) | (count - 1);
3381 add_unwind_opcode (op, 2);
b99bd4ef 3382 }
c19d1205
ZW
3383 unwind.frame_size += count * 8 + 4;
3384}
b99bd4ef 3385
b99bd4ef 3386
c19d1205
ZW
3387/* Parse a directive saving iWMMXt data registers. */
3388
3389static void
3390s_arm_unwind_save_mmxwr (void)
3391{
3392 int reg;
3393 int hi_reg;
3394 int i;
3395 unsigned mask = 0;
3396 valueT op;
b99bd4ef 3397
c19d1205
ZW
3398 if (*input_line_pointer == '{')
3399 input_line_pointer++;
b99bd4ef 3400
c19d1205 3401 do
b99bd4ef 3402 {
dcbf9037 3403 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3404
c19d1205 3405 if (reg == FAIL)
b99bd4ef 3406 {
c19d1205
ZW
3407 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3408 goto error;
b99bd4ef
NC
3409 }
3410
c19d1205
ZW
3411 if (mask >> reg)
3412 as_tsktsk (_("register list not in ascending order"));
3413 mask |= 1 << reg;
b99bd4ef 3414
c19d1205
ZW
3415 if (*input_line_pointer == '-')
3416 {
3417 input_line_pointer++;
dcbf9037 3418 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3419 if (hi_reg == FAIL)
3420 {
3421 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3422 goto error;
3423 }
3424 else if (reg >= hi_reg)
3425 {
3426 as_bad (_("bad register range"));
3427 goto error;
3428 }
3429 for (; reg < hi_reg; reg++)
3430 mask |= 1 << reg;
3431 }
3432 }
3433 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3434
c19d1205
ZW
3435 if (*input_line_pointer == '}')
3436 input_line_pointer++;
b99bd4ef 3437
c19d1205 3438 demand_empty_rest_of_line ();
b99bd4ef 3439
708587a4 3440 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3441 the list. */
3442 flush_pending_unwind ();
b99bd4ef 3443
c19d1205 3444 for (i = 0; i < 16; i++)
b99bd4ef 3445 {
c19d1205
ZW
3446 if (mask & (1 << i))
3447 unwind.frame_size += 8;
b99bd4ef
NC
3448 }
3449
c19d1205
ZW
3450 /* Attempt to combine with a previous opcode. We do this because gcc
3451 likes to output separate unwind directives for a single block of
3452 registers. */
3453 if (unwind.opcode_count > 0)
b99bd4ef 3454 {
c19d1205
ZW
3455 i = unwind.opcodes[unwind.opcode_count - 1];
3456 if ((i & 0xf8) == 0xc0)
3457 {
3458 i &= 7;
3459 /* Only merge if the blocks are contiguous. */
3460 if (i < 6)
3461 {
3462 if ((mask & 0xfe00) == (1 << 9))
3463 {
3464 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3465 unwind.opcode_count--;
3466 }
3467 }
3468 else if (i == 6 && unwind.opcode_count >= 2)
3469 {
3470 i = unwind.opcodes[unwind.opcode_count - 2];
3471 reg = i >> 4;
3472 i &= 0xf;
b99bd4ef 3473
c19d1205
ZW
3474 op = 0xffff << (reg - 1);
3475 if (reg > 0
87a1fd79 3476 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3477 {
3478 op = (1 << (reg + i + 1)) - 1;
3479 op &= ~((1 << reg) - 1);
3480 mask |= op;
3481 unwind.opcode_count -= 2;
3482 }
3483 }
3484 }
b99bd4ef
NC
3485 }
3486
c19d1205
ZW
3487 hi_reg = 15;
3488 /* We want to generate opcodes in the order the registers have been
3489 saved, ie. descending order. */
3490 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3491 {
c19d1205
ZW
3492 /* Save registers in blocks. */
3493 if (reg < 0
3494 || !(mask & (1 << reg)))
3495 {
3496 /* We found an unsaved reg. Generate opcodes to save the
3497 preceeding block. */
3498 if (reg != hi_reg)
3499 {
3500 if (reg == 9)
3501 {
3502 /* Short form. */
3503 op = 0xc0 | (hi_reg - 10);
3504 add_unwind_opcode (op, 1);
3505 }
3506 else
3507 {
3508 /* Long form. */
3509 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3510 add_unwind_opcode (op, 2);
3511 }
3512 }
3513 hi_reg = reg - 1;
3514 }
b99bd4ef
NC
3515 }
3516
c19d1205
ZW
3517 return;
3518error:
3519 ignore_rest_of_line ();
b99bd4ef
NC
3520}
3521
3522static void
c19d1205 3523s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3524{
c19d1205
ZW
3525 int reg;
3526 int hi_reg;
3527 unsigned mask = 0;
3528 valueT op;
b99bd4ef 3529
c19d1205
ZW
3530 if (*input_line_pointer == '{')
3531 input_line_pointer++;
b99bd4ef 3532
c19d1205 3533 do
b99bd4ef 3534 {
dcbf9037 3535 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3536
c19d1205
ZW
3537 if (reg == FAIL)
3538 {
3539 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3540 goto error;
3541 }
b99bd4ef 3542
c19d1205
ZW
3543 reg -= 8;
3544 if (mask >> reg)
3545 as_tsktsk (_("register list not in ascending order"));
3546 mask |= 1 << reg;
b99bd4ef 3547
c19d1205
ZW
3548 if (*input_line_pointer == '-')
3549 {
3550 input_line_pointer++;
dcbf9037 3551 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3552 if (hi_reg == FAIL)
3553 {
3554 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3555 goto error;
3556 }
3557 else if (reg >= hi_reg)
3558 {
3559 as_bad (_("bad register range"));
3560 goto error;
3561 }
3562 for (; reg < hi_reg; reg++)
3563 mask |= 1 << reg;
3564 }
b99bd4ef 3565 }
c19d1205 3566 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3567
c19d1205
ZW
3568 if (*input_line_pointer == '}')
3569 input_line_pointer++;
b99bd4ef 3570
c19d1205
ZW
3571 demand_empty_rest_of_line ();
3572
708587a4 3573 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3574 the list. */
3575 flush_pending_unwind ();
b99bd4ef 3576
c19d1205 3577 for (reg = 0; reg < 16; reg++)
b99bd4ef 3578 {
c19d1205
ZW
3579 if (mask & (1 << reg))
3580 unwind.frame_size += 4;
b99bd4ef 3581 }
c19d1205
ZW
3582 op = 0xc700 | mask;
3583 add_unwind_opcode (op, 2);
3584 return;
3585error:
3586 ignore_rest_of_line ();
b99bd4ef
NC
3587}
3588
c19d1205 3589
fa073d69
MS
3590/* Parse an unwind_save directive.
3591 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3592
b99bd4ef 3593static void
fa073d69 3594s_arm_unwind_save (int arch_v6)
b99bd4ef 3595{
c19d1205
ZW
3596 char *peek;
3597 struct reg_entry *reg;
3598 bfd_boolean had_brace = FALSE;
b99bd4ef 3599
c19d1205
ZW
3600 /* Figure out what sort of save we have. */
3601 peek = input_line_pointer;
b99bd4ef 3602
c19d1205 3603 if (*peek == '{')
b99bd4ef 3604 {
c19d1205
ZW
3605 had_brace = TRUE;
3606 peek++;
b99bd4ef
NC
3607 }
3608
c19d1205 3609 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3610
c19d1205 3611 if (!reg)
b99bd4ef 3612 {
c19d1205
ZW
3613 as_bad (_("register expected"));
3614 ignore_rest_of_line ();
b99bd4ef
NC
3615 return;
3616 }
3617
c19d1205 3618 switch (reg->type)
b99bd4ef 3619 {
c19d1205
ZW
3620 case REG_TYPE_FN:
3621 if (had_brace)
3622 {
3623 as_bad (_("FPA .unwind_save does not take a register list"));
3624 ignore_rest_of_line ();
3625 return;
3626 }
3627 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3628 return;
c19d1205
ZW
3629
3630 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3631 case REG_TYPE_VFD:
3632 if (arch_v6)
3633 s_arm_unwind_save_vfp_armv6 ();
3634 else
3635 s_arm_unwind_save_vfp ();
3636 return;
c19d1205
ZW
3637 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3638 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3639
3640 default:
3641 as_bad (_(".unwind_save does not support this kind of register"));
3642 ignore_rest_of_line ();
b99bd4ef 3643 }
c19d1205 3644}
b99bd4ef 3645
b99bd4ef 3646
c19d1205
ZW
3647/* Parse an unwind_movsp directive. */
3648
3649static void
3650s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3651{
3652 int reg;
3653 valueT op;
4fa3602b 3654 int offset;
c19d1205 3655
dcbf9037 3656 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3657 if (reg == FAIL)
b99bd4ef 3658 {
c19d1205
ZW
3659 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3660 ignore_rest_of_line ();
b99bd4ef
NC
3661 return;
3662 }
4fa3602b
PB
3663
3664 /* Optional constant. */
3665 if (skip_past_comma (&input_line_pointer) != FAIL)
3666 {
3667 if (immediate_for_directive (&offset) == FAIL)
3668 return;
3669 }
3670 else
3671 offset = 0;
3672
c19d1205 3673 demand_empty_rest_of_line ();
b99bd4ef 3674
c19d1205 3675 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3676 {
c19d1205 3677 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3678 return;
3679 }
3680
c19d1205
ZW
3681 if (unwind.fp_reg != REG_SP)
3682 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3683
c19d1205
ZW
3684 /* Generate opcode to restore the value. */
3685 op = 0x90 | reg;
3686 add_unwind_opcode (op, 1);
3687
3688 /* Record the information for later. */
3689 unwind.fp_reg = reg;
4fa3602b 3690 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3691 unwind.sp_restored = 1;
b05fe5cf
ZW
3692}
3693
c19d1205
ZW
3694/* Parse an unwind_pad directive. */
3695
b05fe5cf 3696static void
c19d1205 3697s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3698{
c19d1205 3699 int offset;
b05fe5cf 3700
c19d1205
ZW
3701 if (immediate_for_directive (&offset) == FAIL)
3702 return;
b99bd4ef 3703
c19d1205
ZW
3704 if (offset & 3)
3705 {
3706 as_bad (_("stack increment must be multiple of 4"));
3707 ignore_rest_of_line ();
3708 return;
3709 }
b99bd4ef 3710
c19d1205
ZW
3711 /* Don't generate any opcodes, just record the details for later. */
3712 unwind.frame_size += offset;
3713 unwind.pending_offset += offset;
3714
3715 demand_empty_rest_of_line ();
3716}
3717
3718/* Parse an unwind_setfp directive. */
3719
3720static void
3721s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3722{
c19d1205
ZW
3723 int sp_reg;
3724 int fp_reg;
3725 int offset;
3726
dcbf9037 3727 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3728 if (skip_past_comma (&input_line_pointer) == FAIL)
3729 sp_reg = FAIL;
3730 else
dcbf9037 3731 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3732
c19d1205
ZW
3733 if (fp_reg == FAIL || sp_reg == FAIL)
3734 {
3735 as_bad (_("expected <reg>, <reg>"));
3736 ignore_rest_of_line ();
3737 return;
3738 }
b99bd4ef 3739
c19d1205
ZW
3740 /* Optional constant. */
3741 if (skip_past_comma (&input_line_pointer) != FAIL)
3742 {
3743 if (immediate_for_directive (&offset) == FAIL)
3744 return;
3745 }
3746 else
3747 offset = 0;
a737bd4d 3748
c19d1205 3749 demand_empty_rest_of_line ();
a737bd4d 3750
c19d1205 3751 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3752 {
c19d1205
ZW
3753 as_bad (_("register must be either sp or set by a previous"
3754 "unwind_movsp directive"));
3755 return;
a737bd4d
NC
3756 }
3757
c19d1205
ZW
3758 /* Don't generate any opcodes, just record the information for later. */
3759 unwind.fp_reg = fp_reg;
3760 unwind.fp_used = 1;
3761 if (sp_reg == 13)
3762 unwind.fp_offset = unwind.frame_size - offset;
3763 else
3764 unwind.fp_offset -= offset;
a737bd4d
NC
3765}
3766
c19d1205
ZW
3767/* Parse an unwind_raw directive. */
3768
3769static void
3770s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3771{
c19d1205 3772 expressionS exp;
708587a4 3773 /* This is an arbitrary limit. */
c19d1205
ZW
3774 unsigned char op[16];
3775 int count;
a737bd4d 3776
c19d1205
ZW
3777 expression (&exp);
3778 if (exp.X_op == O_constant
3779 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3780 {
c19d1205
ZW
3781 unwind.frame_size += exp.X_add_number;
3782 expression (&exp);
3783 }
3784 else
3785 exp.X_op = O_illegal;
a737bd4d 3786
c19d1205
ZW
3787 if (exp.X_op != O_constant)
3788 {
3789 as_bad (_("expected <offset>, <opcode>"));
3790 ignore_rest_of_line ();
3791 return;
3792 }
a737bd4d 3793
c19d1205 3794 count = 0;
a737bd4d 3795
c19d1205
ZW
3796 /* Parse the opcode. */
3797 for (;;)
3798 {
3799 if (count >= 16)
3800 {
3801 as_bad (_("unwind opcode too long"));
3802 ignore_rest_of_line ();
a737bd4d 3803 }
c19d1205 3804 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3805 {
c19d1205
ZW
3806 as_bad (_("invalid unwind opcode"));
3807 ignore_rest_of_line ();
3808 return;
a737bd4d 3809 }
c19d1205 3810 op[count++] = exp.X_add_number;
a737bd4d 3811
c19d1205
ZW
3812 /* Parse the next byte. */
3813 if (skip_past_comma (&input_line_pointer) == FAIL)
3814 break;
a737bd4d 3815
c19d1205
ZW
3816 expression (&exp);
3817 }
b99bd4ef 3818
c19d1205
ZW
3819 /* Add the opcode bytes in reverse order. */
3820 while (count--)
3821 add_unwind_opcode (op[count], 1);
b99bd4ef 3822
c19d1205 3823 demand_empty_rest_of_line ();
b99bd4ef 3824}
ee065d83
PB
3825
3826
3827/* Parse a .eabi_attribute directive. */
3828
3829static void
3830s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3831{
3832 expressionS exp;
3833 bfd_boolean is_string;
3834 int tag;
3835 unsigned int i = 0;
3836 char *s = NULL;
3837 char saved_char;
3838
3839 expression (& exp);
3840 if (exp.X_op != O_constant)
3841 goto bad;
3842
3843 tag = exp.X_add_number;
3844 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3845 is_string = 1;
3846 else
3847 is_string = 0;
3848
3849 if (skip_past_comma (&input_line_pointer) == FAIL)
3850 goto bad;
3851 if (tag == 32 || !is_string)
3852 {
3853 expression (& exp);
3854 if (exp.X_op != O_constant)
3855 {
3856 as_bad (_("expected numeric constant"));
3857 ignore_rest_of_line ();
3858 return;
3859 }
3860 i = exp.X_add_number;
3861 }
3862 if (tag == Tag_compatibility
3863 && skip_past_comma (&input_line_pointer) == FAIL)
3864 {
3865 as_bad (_("expected comma"));
3866 ignore_rest_of_line ();
3867 return;
3868 }
3869 if (is_string)
3870 {
3871 skip_whitespace(input_line_pointer);
3872 if (*input_line_pointer != '"')
3873 goto bad_string;
3874 input_line_pointer++;
3875 s = input_line_pointer;
3876 while (*input_line_pointer && *input_line_pointer != '"')
3877 input_line_pointer++;
3878 if (*input_line_pointer != '"')
3879 goto bad_string;
3880 saved_char = *input_line_pointer;
3881 *input_line_pointer = 0;
3882 }
3883 else
3884 {
3885 s = NULL;
3886 saved_char = 0;
3887 }
3888
3889 if (tag == Tag_compatibility)
3890 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3891 else if (is_string)
3892 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3893 else
3894 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3895
3896 if (s)
3897 {
3898 *input_line_pointer = saved_char;
3899 input_line_pointer++;
3900 }
3901 demand_empty_rest_of_line ();
3902 return;
3903bad_string:
3904 as_bad (_("bad string constant"));
3905 ignore_rest_of_line ();
3906 return;
3907bad:
3908 as_bad (_("expected <tag> , <value>"));
3909 ignore_rest_of_line ();
3910}
8463be01 3911#endif /* OBJ_ELF */
ee065d83
PB
3912
3913static void s_arm_arch (int);
7a1d4c38 3914static void s_arm_object_arch (int);
ee065d83
PB
3915static void s_arm_cpu (int);
3916static void s_arm_fpu (int);
b99bd4ef 3917
f0927246
NC
3918#ifdef TE_PE
3919
3920static void
3921pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3922{
3923 expressionS exp;
3924
3925 do
3926 {
3927 expression (&exp);
3928 if (exp.X_op == O_symbol)
3929 exp.X_op = O_secrel;
3930
3931 emit_expr (&exp, 4);
3932 }
3933 while (*input_line_pointer++ == ',');
3934
3935 input_line_pointer--;
3936 demand_empty_rest_of_line ();
3937}
3938#endif /* TE_PE */
3939
c19d1205
ZW
3940/* This table describes all the machine specific pseudo-ops the assembler
3941 has to support. The fields are:
3942 pseudo-op name without dot
3943 function to call to execute this pseudo-op
3944 Integer arg to pass to the function. */
b99bd4ef 3945
c19d1205 3946const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3947{
c19d1205
ZW
3948 /* Never called because '.req' does not start a line. */
3949 { "req", s_req, 0 },
dcbf9037
JB
3950 /* Following two are likewise never called. */
3951 { "dn", s_dn, 0 },
3952 { "qn", s_qn, 0 },
c19d1205
ZW
3953 { "unreq", s_unreq, 0 },
3954 { "bss", s_bss, 0 },
3955 { "align", s_align, 0 },
3956 { "arm", s_arm, 0 },
3957 { "thumb", s_thumb, 0 },
3958 { "code", s_code, 0 },
3959 { "force_thumb", s_force_thumb, 0 },
3960 { "thumb_func", s_thumb_func, 0 },
3961 { "thumb_set", s_thumb_set, 0 },
3962 { "even", s_even, 0 },
3963 { "ltorg", s_ltorg, 0 },
3964 { "pool", s_ltorg, 0 },
3965 { "syntax", s_syntax, 0 },
8463be01
PB
3966 { "cpu", s_arm_cpu, 0 },
3967 { "arch", s_arm_arch, 0 },
7a1d4c38 3968 { "object_arch", s_arm_object_arch, 0 },
8463be01 3969 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3970#ifdef OBJ_ELF
3971 { "word", s_arm_elf_cons, 4 },
3972 { "long", s_arm_elf_cons, 4 },
3973 { "rel31", s_arm_rel31, 0 },
3974 { "fnstart", s_arm_unwind_fnstart, 0 },
3975 { "fnend", s_arm_unwind_fnend, 0 },
3976 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3977 { "personality", s_arm_unwind_personality, 0 },
3978 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3979 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3980 { "save", s_arm_unwind_save, 0 },
fa073d69 3981 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3982 { "movsp", s_arm_unwind_movsp, 0 },
3983 { "pad", s_arm_unwind_pad, 0 },
3984 { "setfp", s_arm_unwind_setfp, 0 },
3985 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3986 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3987#else
3988 { "word", cons, 4},
f0927246
NC
3989
3990 /* These are used for dwarf. */
3991 {"2byte", cons, 2},
3992 {"4byte", cons, 4},
3993 {"8byte", cons, 8},
3994 /* These are used for dwarf2. */
3995 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3996 { "loc", dwarf2_directive_loc, 0 },
3997 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3998#endif
3999 { "extend", float_cons, 'x' },
4000 { "ldouble", float_cons, 'x' },
4001 { "packed", float_cons, 'p' },
f0927246
NC
4002#ifdef TE_PE
4003 {"secrel32", pe_directive_secrel, 0},
4004#endif
c19d1205
ZW
4005 { 0, 0, 0 }
4006};
4007\f
4008/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4009
c19d1205
ZW
4010/* Generic immediate-value read function for use in insn parsing.
4011 STR points to the beginning of the immediate (the leading #);
4012 VAL receives the value; if the value is outside [MIN, MAX]
4013 issue an error. PREFIX_OPT is true if the immediate prefix is
4014 optional. */
b99bd4ef 4015
c19d1205
ZW
4016static int
4017parse_immediate (char **str, int *val, int min, int max,
4018 bfd_boolean prefix_opt)
4019{
4020 expressionS exp;
4021 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4022 if (exp.X_op != O_constant)
b99bd4ef 4023 {
c19d1205
ZW
4024 inst.error = _("constant expression required");
4025 return FAIL;
4026 }
b99bd4ef 4027
c19d1205
ZW
4028 if (exp.X_add_number < min || exp.X_add_number > max)
4029 {
4030 inst.error = _("immediate value out of range");
4031 return FAIL;
4032 }
b99bd4ef 4033
c19d1205
ZW
4034 *val = exp.X_add_number;
4035 return SUCCESS;
4036}
b99bd4ef 4037
5287ad62 4038/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4039 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4040 instructions. Puts the result directly in inst.operands[i]. */
4041
4042static int
4043parse_big_immediate (char **str, int i)
4044{
4045 expressionS exp;
4046 char *ptr = *str;
4047
4048 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4049
4050 if (exp.X_op == O_constant)
036dc3f7
PB
4051 {
4052 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4053 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4054 O_constant. We have to be careful not to break compilation for
4055 32-bit X_add_number, though. */
4056 if ((exp.X_add_number & ~0xffffffffl) != 0)
4057 {
4058 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4059 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4060 inst.operands[i].regisimm = 1;
4061 }
4062 }
5287ad62
JB
4063 else if (exp.X_op == O_big
4064 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4065 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4066 {
4067 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4068 /* Bignums have their least significant bits in
4069 generic_bignum[0]. Make sure we put 32 bits in imm and
4070 32 bits in reg, in a (hopefully) portable way. */
4071 assert (parts != 0);
4072 inst.operands[i].imm = 0;
4073 for (j = 0; j < parts; j++, idx++)
4074 inst.operands[i].imm |= generic_bignum[idx]
4075 << (LITTLENUM_NUMBER_OF_BITS * j);
4076 inst.operands[i].reg = 0;
4077 for (j = 0; j < parts; j++, idx++)
4078 inst.operands[i].reg |= generic_bignum[idx]
4079 << (LITTLENUM_NUMBER_OF_BITS * j);
4080 inst.operands[i].regisimm = 1;
4081 }
4082 else
4083 return FAIL;
4084
4085 *str = ptr;
4086
4087 return SUCCESS;
4088}
4089
c19d1205
ZW
4090/* Returns the pseudo-register number of an FPA immediate constant,
4091 or FAIL if there isn't a valid constant here. */
b99bd4ef 4092
c19d1205
ZW
4093static int
4094parse_fpa_immediate (char ** str)
4095{
4096 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4097 char * save_in;
4098 expressionS exp;
4099 int i;
4100 int j;
b99bd4ef 4101
c19d1205
ZW
4102 /* First try and match exact strings, this is to guarantee
4103 that some formats will work even for cross assembly. */
b99bd4ef 4104
c19d1205
ZW
4105 for (i = 0; fp_const[i]; i++)
4106 {
4107 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4108 {
c19d1205 4109 char *start = *str;
b99bd4ef 4110
c19d1205
ZW
4111 *str += strlen (fp_const[i]);
4112 if (is_end_of_line[(unsigned char) **str])
4113 return i + 8;
4114 *str = start;
4115 }
4116 }
b99bd4ef 4117
c19d1205
ZW
4118 /* Just because we didn't get a match doesn't mean that the constant
4119 isn't valid, just that it is in a format that we don't
4120 automatically recognize. Try parsing it with the standard
4121 expression routines. */
b99bd4ef 4122
c19d1205 4123 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4124
c19d1205
ZW
4125 /* Look for a raw floating point number. */
4126 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4127 && is_end_of_line[(unsigned char) *save_in])
4128 {
4129 for (i = 0; i < NUM_FLOAT_VALS; i++)
4130 {
4131 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4132 {
c19d1205
ZW
4133 if (words[j] != fp_values[i][j])
4134 break;
b99bd4ef
NC
4135 }
4136
c19d1205 4137 if (j == MAX_LITTLENUMS)
b99bd4ef 4138 {
c19d1205
ZW
4139 *str = save_in;
4140 return i + 8;
b99bd4ef
NC
4141 }
4142 }
4143 }
b99bd4ef 4144
c19d1205
ZW
4145 /* Try and parse a more complex expression, this will probably fail
4146 unless the code uses a floating point prefix (eg "0f"). */
4147 save_in = input_line_pointer;
4148 input_line_pointer = *str;
4149 if (expression (&exp) == absolute_section
4150 && exp.X_op == O_big
4151 && exp.X_add_number < 0)
4152 {
4153 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4154 Ditto for 15. */
4155 if (gen_to_words (words, 5, (long) 15) == 0)
4156 {
4157 for (i = 0; i < NUM_FLOAT_VALS; i++)
4158 {
4159 for (j = 0; j < MAX_LITTLENUMS; j++)
4160 {
4161 if (words[j] != fp_values[i][j])
4162 break;
4163 }
b99bd4ef 4164
c19d1205
ZW
4165 if (j == MAX_LITTLENUMS)
4166 {
4167 *str = input_line_pointer;
4168 input_line_pointer = save_in;
4169 return i + 8;
4170 }
4171 }
4172 }
b99bd4ef
NC
4173 }
4174
c19d1205
ZW
4175 *str = input_line_pointer;
4176 input_line_pointer = save_in;
4177 inst.error = _("invalid FPA immediate expression");
4178 return FAIL;
b99bd4ef
NC
4179}
4180
136da414
JB
4181/* Returns 1 if a number has "quarter-precision" float format
4182 0baBbbbbbc defgh000 00000000 00000000. */
4183
4184static int
4185is_quarter_float (unsigned imm)
4186{
4187 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4188 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4189}
4190
4191/* Parse an 8-bit "quarter-precision" floating point number of the form:
4192 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4193 The zero and minus-zero cases need special handling, since they can't be
4194 encoded in the "quarter-precision" float format, but can nonetheless be
4195 loaded as integer constants. */
136da414
JB
4196
4197static unsigned
4198parse_qfloat_immediate (char **ccp, int *immed)
4199{
4200 char *str = *ccp;
c96612cc 4201 char *fpnum;
136da414 4202 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4203 int found_fpchar = 0;
136da414
JB
4204
4205 skip_past_char (&str, '#');
4206
c96612cc
JB
4207 /* We must not accidentally parse an integer as a floating-point number. Make
4208 sure that the value we parse is not an integer by checking for special
4209 characters '.' or 'e'.
4210 FIXME: This is a horrible hack, but doing better is tricky because type
4211 information isn't in a very usable state at parse time. */
4212 fpnum = str;
4213 skip_whitespace (fpnum);
4214
4215 if (strncmp (fpnum, "0x", 2) == 0)
4216 return FAIL;
4217 else
4218 {
4219 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4220 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4221 {
4222 found_fpchar = 1;
4223 break;
4224 }
4225
4226 if (!found_fpchar)
4227 return FAIL;
4228 }
4229
136da414
JB
4230 if ((str = atof_ieee (str, 's', words)) != NULL)
4231 {
4232 unsigned fpword = 0;
4233 int i;
4234
4235 /* Our FP word must be 32 bits (single-precision FP). */
4236 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4237 {
4238 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4239 fpword |= words[i];
4240 }
4241
c96612cc 4242 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4243 *immed = fpword;
4244 else
4245 return FAIL;
4246
4247 *ccp = str;
4248
4249 return SUCCESS;
4250 }
4251
4252 return FAIL;
4253}
4254
c19d1205
ZW
4255/* Shift operands. */
4256enum shift_kind
b99bd4ef 4257{
c19d1205
ZW
4258 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4259};
b99bd4ef 4260
c19d1205
ZW
4261struct asm_shift_name
4262{
4263 const char *name;
4264 enum shift_kind kind;
4265};
b99bd4ef 4266
c19d1205
ZW
4267/* Third argument to parse_shift. */
4268enum parse_shift_mode
4269{
4270 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4271 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4272 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4273 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4274 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4275};
b99bd4ef 4276
c19d1205
ZW
4277/* Parse a <shift> specifier on an ARM data processing instruction.
4278 This has three forms:
b99bd4ef 4279
c19d1205
ZW
4280 (LSL|LSR|ASL|ASR|ROR) Rs
4281 (LSL|LSR|ASL|ASR|ROR) #imm
4282 RRX
b99bd4ef 4283
c19d1205
ZW
4284 Note that ASL is assimilated to LSL in the instruction encoding, and
4285 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4286
c19d1205
ZW
4287static int
4288parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4289{
c19d1205
ZW
4290 const struct asm_shift_name *shift_name;
4291 enum shift_kind shift;
4292 char *s = *str;
4293 char *p = s;
4294 int reg;
b99bd4ef 4295
c19d1205
ZW
4296 for (p = *str; ISALPHA (*p); p++)
4297 ;
b99bd4ef 4298
c19d1205 4299 if (p == *str)
b99bd4ef 4300 {
c19d1205
ZW
4301 inst.error = _("shift expression expected");
4302 return FAIL;
b99bd4ef
NC
4303 }
4304
c19d1205
ZW
4305 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4306
4307 if (shift_name == NULL)
b99bd4ef 4308 {
c19d1205
ZW
4309 inst.error = _("shift expression expected");
4310 return FAIL;
b99bd4ef
NC
4311 }
4312
c19d1205 4313 shift = shift_name->kind;
b99bd4ef 4314
c19d1205
ZW
4315 switch (mode)
4316 {
4317 case NO_SHIFT_RESTRICT:
4318 case SHIFT_IMMEDIATE: break;
b99bd4ef 4319
c19d1205
ZW
4320 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4321 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4322 {
4323 inst.error = _("'LSL' or 'ASR' required");
4324 return FAIL;
4325 }
4326 break;
b99bd4ef 4327
c19d1205
ZW
4328 case SHIFT_LSL_IMMEDIATE:
4329 if (shift != SHIFT_LSL)
4330 {
4331 inst.error = _("'LSL' required");
4332 return FAIL;
4333 }
4334 break;
b99bd4ef 4335
c19d1205
ZW
4336 case SHIFT_ASR_IMMEDIATE:
4337 if (shift != SHIFT_ASR)
4338 {
4339 inst.error = _("'ASR' required");
4340 return FAIL;
4341 }
4342 break;
b99bd4ef 4343
c19d1205
ZW
4344 default: abort ();
4345 }
b99bd4ef 4346
c19d1205
ZW
4347 if (shift != SHIFT_RRX)
4348 {
4349 /* Whitespace can appear here if the next thing is a bare digit. */
4350 skip_whitespace (p);
b99bd4ef 4351
c19d1205 4352 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4353 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4354 {
4355 inst.operands[i].imm = reg;
4356 inst.operands[i].immisreg = 1;
4357 }
4358 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4359 return FAIL;
4360 }
4361 inst.operands[i].shift_kind = shift;
4362 inst.operands[i].shifted = 1;
4363 *str = p;
4364 return SUCCESS;
b99bd4ef
NC
4365}
4366
c19d1205 4367/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4368
c19d1205
ZW
4369 #<immediate>
4370 #<immediate>, <rotate>
4371 <Rm>
4372 <Rm>, <shift>
b99bd4ef 4373
c19d1205
ZW
4374 where <shift> is defined by parse_shift above, and <rotate> is a
4375 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4376 is deferred to md_apply_fix. */
b99bd4ef 4377
c19d1205
ZW
4378static int
4379parse_shifter_operand (char **str, int i)
4380{
4381 int value;
4382 expressionS expr;
b99bd4ef 4383
dcbf9037 4384 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4385 {
4386 inst.operands[i].reg = value;
4387 inst.operands[i].isreg = 1;
b99bd4ef 4388
c19d1205
ZW
4389 /* parse_shift will override this if appropriate */
4390 inst.reloc.exp.X_op = O_constant;
4391 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4392
c19d1205
ZW
4393 if (skip_past_comma (str) == FAIL)
4394 return SUCCESS;
b99bd4ef 4395
c19d1205
ZW
4396 /* Shift operation on register. */
4397 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4398 }
4399
c19d1205
ZW
4400 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4401 return FAIL;
b99bd4ef 4402
c19d1205 4403 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4404 {
c19d1205
ZW
4405 /* #x, y -- ie explicit rotation by Y. */
4406 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4407 return FAIL;
b99bd4ef 4408
c19d1205
ZW
4409 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4410 {
4411 inst.error = _("constant expression expected");
4412 return FAIL;
4413 }
b99bd4ef 4414
c19d1205
ZW
4415 value = expr.X_add_number;
4416 if (value < 0 || value > 30 || value % 2 != 0)
4417 {
4418 inst.error = _("invalid rotation");
4419 return FAIL;
4420 }
4421 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4422 {
4423 inst.error = _("invalid constant");
4424 return FAIL;
4425 }
09d92015 4426
55cf6793 4427 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4428 inst.reloc.exp.X_add_number
4429 = (((inst.reloc.exp.X_add_number << (32 - value))
4430 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4431 }
4432
c19d1205
ZW
4433 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4434 inst.reloc.pc_rel = 0;
4435 return SUCCESS;
09d92015
MM
4436}
4437
4962c51a
MS
4438/* Group relocation information. Each entry in the table contains the
4439 textual name of the relocation as may appear in assembler source
4440 and must end with a colon.
4441 Along with this textual name are the relocation codes to be used if
4442 the corresponding instruction is an ALU instruction (ADD or SUB only),
4443 an LDR, an LDRS, or an LDC. */
4444
4445struct group_reloc_table_entry
4446{
4447 const char *name;
4448 int alu_code;
4449 int ldr_code;
4450 int ldrs_code;
4451 int ldc_code;
4452};
4453
4454typedef enum
4455{
4456 /* Varieties of non-ALU group relocation. */
4457
4458 GROUP_LDR,
4459 GROUP_LDRS,
4460 GROUP_LDC
4461} group_reloc_type;
4462
4463static struct group_reloc_table_entry group_reloc_table[] =
4464 { /* Program counter relative: */
4465 { "pc_g0_nc",
4466 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "pc_g0",
4471 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4472 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4473 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4474 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4475 { "pc_g1_nc",
4476 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4477 0, /* LDR */
4478 0, /* LDRS */
4479 0 }, /* LDC */
4480 { "pc_g1",
4481 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4482 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4483 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4484 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4485 { "pc_g2",
4486 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4487 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4488 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4489 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4490 /* Section base relative */
4491 { "sb_g0_nc",
4492 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4493 0, /* LDR */
4494 0, /* LDRS */
4495 0 }, /* LDC */
4496 { "sb_g0",
4497 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4498 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4499 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4500 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4501 { "sb_g1_nc",
4502 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4503 0, /* LDR */
4504 0, /* LDRS */
4505 0 }, /* LDC */
4506 { "sb_g1",
4507 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4508 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4509 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4510 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4511 { "sb_g2",
4512 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4513 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4514 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4515 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4516
4517/* Given the address of a pointer pointing to the textual name of a group
4518 relocation as may appear in assembler source, attempt to find its details
4519 in group_reloc_table. The pointer will be updated to the character after
4520 the trailing colon. On failure, FAIL will be returned; SUCCESS
4521 otherwise. On success, *entry will be updated to point at the relevant
4522 group_reloc_table entry. */
4523
4524static int
4525find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4526{
4527 unsigned int i;
4528 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4529 {
4530 int length = strlen (group_reloc_table[i].name);
4531
4532 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4533 (*str)[length] == ':')
4534 {
4535 *out = &group_reloc_table[i];
4536 *str += (length + 1);
4537 return SUCCESS;
4538 }
4539 }
4540
4541 return FAIL;
4542}
4543
4544/* Parse a <shifter_operand> for an ARM data processing instruction
4545 (as for parse_shifter_operand) where group relocations are allowed:
4546
4547 #<immediate>
4548 #<immediate>, <rotate>
4549 #:<group_reloc>:<expression>
4550 <Rm>
4551 <Rm>, <shift>
4552
4553 where <group_reloc> is one of the strings defined in group_reloc_table.
4554 The hashes are optional.
4555
4556 Everything else is as for parse_shifter_operand. */
4557
4558static parse_operand_result
4559parse_shifter_operand_group_reloc (char **str, int i)
4560{
4561 /* Determine if we have the sequence of characters #: or just :
4562 coming next. If we do, then we check for a group relocation.
4563 If we don't, punt the whole lot to parse_shifter_operand. */
4564
4565 if (((*str)[0] == '#' && (*str)[1] == ':')
4566 || (*str)[0] == ':')
4567 {
4568 struct group_reloc_table_entry *entry;
4569
4570 if ((*str)[0] == '#')
4571 (*str) += 2;
4572 else
4573 (*str)++;
4574
4575 /* Try to parse a group relocation. Anything else is an error. */
4576 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4577 {
4578 inst.error = _("unknown group relocation");
4579 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4580 }
4581
4582 /* We now have the group relocation table entry corresponding to
4583 the name in the assembler source. Next, we parse the expression. */
4584 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4585 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4586
4587 /* Record the relocation type (always the ALU variant here). */
4588 inst.reloc.type = entry->alu_code;
4589 assert (inst.reloc.type != 0);
4590
4591 return PARSE_OPERAND_SUCCESS;
4592 }
4593 else
4594 return parse_shifter_operand (str, i) == SUCCESS
4595 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4596
4597 /* Never reached. */
4598}
4599
c19d1205
ZW
4600/* Parse all forms of an ARM address expression. Information is written
4601 to inst.operands[i] and/or inst.reloc.
09d92015 4602
c19d1205 4603 Preindexed addressing (.preind=1):
09d92015 4604
c19d1205
ZW
4605 [Rn, #offset] .reg=Rn .reloc.exp=offset
4606 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4607 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4608 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4609
c19d1205 4610 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4611
c19d1205 4612 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4613
c19d1205
ZW
4614 [Rn], #offset .reg=Rn .reloc.exp=offset
4615 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4616 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4617 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4618
c19d1205 4619 Unindexed addressing (.preind=0, .postind=0):
09d92015 4620
c19d1205 4621 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4622
c19d1205 4623 Other:
09d92015 4624
c19d1205
ZW
4625 [Rn]{!} shorthand for [Rn,#0]{!}
4626 =immediate .isreg=0 .reloc.exp=immediate
4627 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4628
c19d1205
ZW
4629 It is the caller's responsibility to check for addressing modes not
4630 supported by the instruction, and to set inst.reloc.type. */
4631
4962c51a
MS
4632static parse_operand_result
4633parse_address_main (char **str, int i, int group_relocations,
4634 group_reloc_type group_type)
09d92015 4635{
c19d1205
ZW
4636 char *p = *str;
4637 int reg;
09d92015 4638
c19d1205 4639 if (skip_past_char (&p, '[') == FAIL)
09d92015 4640 {
c19d1205
ZW
4641 if (skip_past_char (&p, '=') == FAIL)
4642 {
4643 /* bare address - translate to PC-relative offset */
4644 inst.reloc.pc_rel = 1;
4645 inst.operands[i].reg = REG_PC;
4646 inst.operands[i].isreg = 1;
4647 inst.operands[i].preind = 1;
4648 }
4649 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4650
c19d1205 4651 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4652 return PARSE_OPERAND_FAIL;
09d92015 4653
c19d1205 4654 *str = p;
4962c51a 4655 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4656 }
4657
dcbf9037 4658 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4659 {
c19d1205 4660 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4661 return PARSE_OPERAND_FAIL;
09d92015 4662 }
c19d1205
ZW
4663 inst.operands[i].reg = reg;
4664 inst.operands[i].isreg = 1;
09d92015 4665
c19d1205 4666 if (skip_past_comma (&p) == SUCCESS)
09d92015 4667 {
c19d1205 4668 inst.operands[i].preind = 1;
09d92015 4669
c19d1205
ZW
4670 if (*p == '+') p++;
4671 else if (*p == '-') p++, inst.operands[i].negative = 1;
4672
dcbf9037 4673 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4674 {
c19d1205
ZW
4675 inst.operands[i].imm = reg;
4676 inst.operands[i].immisreg = 1;
4677
4678 if (skip_past_comma (&p) == SUCCESS)
4679 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4680 return PARSE_OPERAND_FAIL;
c19d1205 4681 }
5287ad62
JB
4682 else if (skip_past_char (&p, ':') == SUCCESS)
4683 {
4684 /* FIXME: '@' should be used here, but it's filtered out by generic
4685 code before we get to see it here. This may be subject to
4686 change. */
4687 expressionS exp;
4688 my_get_expression (&exp, &p, GE_NO_PREFIX);
4689 if (exp.X_op != O_constant)
4690 {
4691 inst.error = _("alignment must be constant");
4962c51a 4692 return PARSE_OPERAND_FAIL;
5287ad62
JB
4693 }
4694 inst.operands[i].imm = exp.X_add_number << 8;
4695 inst.operands[i].immisalign = 1;
4696 /* Alignments are not pre-indexes. */
4697 inst.operands[i].preind = 0;
4698 }
c19d1205
ZW
4699 else
4700 {
4701 if (inst.operands[i].negative)
4702 {
4703 inst.operands[i].negative = 0;
4704 p--;
4705 }
4962c51a
MS
4706
4707 if (group_relocations &&
4708 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4709
4710 {
4711 struct group_reloc_table_entry *entry;
4712
4713 /* Skip over the #: or : sequence. */
4714 if (*p == '#')
4715 p += 2;
4716 else
4717 p++;
4718
4719 /* Try to parse a group relocation. Anything else is an
4720 error. */
4721 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4722 {
4723 inst.error = _("unknown group relocation");
4724 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4725 }
4726
4727 /* We now have the group relocation table entry corresponding to
4728 the name in the assembler source. Next, we parse the
4729 expression. */
4730 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4731 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4732
4733 /* Record the relocation type. */
4734 switch (group_type)
4735 {
4736 case GROUP_LDR:
4737 inst.reloc.type = entry->ldr_code;
4738 break;
4739
4740 case GROUP_LDRS:
4741 inst.reloc.type = entry->ldrs_code;
4742 break;
4743
4744 case GROUP_LDC:
4745 inst.reloc.type = entry->ldc_code;
4746 break;
4747
4748 default:
4749 assert (0);
4750 }
4751
4752 if (inst.reloc.type == 0)
4753 {
4754 inst.error = _("this group relocation is not allowed on this instruction");
4755 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4756 }
4757 }
4758 else
4759 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4760 return PARSE_OPERAND_FAIL;
09d92015
MM
4761 }
4762 }
4763
c19d1205 4764 if (skip_past_char (&p, ']') == FAIL)
09d92015 4765 {
c19d1205 4766 inst.error = _("']' expected");
4962c51a 4767 return PARSE_OPERAND_FAIL;
09d92015
MM
4768 }
4769
c19d1205
ZW
4770 if (skip_past_char (&p, '!') == SUCCESS)
4771 inst.operands[i].writeback = 1;
09d92015 4772
c19d1205 4773 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4774 {
c19d1205
ZW
4775 if (skip_past_char (&p, '{') == SUCCESS)
4776 {
4777 /* [Rn], {expr} - unindexed, with option */
4778 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4779 0, 255, TRUE) == FAIL)
4962c51a 4780 return PARSE_OPERAND_FAIL;
09d92015 4781
c19d1205
ZW
4782 if (skip_past_char (&p, '}') == FAIL)
4783 {
4784 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4785 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4786 }
4787 if (inst.operands[i].preind)
4788 {
4789 inst.error = _("cannot combine index with option");
4962c51a 4790 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4791 }
4792 *str = p;
4962c51a 4793 return PARSE_OPERAND_SUCCESS;
09d92015 4794 }
c19d1205
ZW
4795 else
4796 {
4797 inst.operands[i].postind = 1;
4798 inst.operands[i].writeback = 1;
09d92015 4799
c19d1205
ZW
4800 if (inst.operands[i].preind)
4801 {
4802 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4803 return PARSE_OPERAND_FAIL;
c19d1205 4804 }
09d92015 4805
c19d1205
ZW
4806 if (*p == '+') p++;
4807 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4808
dcbf9037 4809 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4810 {
5287ad62
JB
4811 /* We might be using the immediate for alignment already. If we
4812 are, OR the register number into the low-order bits. */
4813 if (inst.operands[i].immisalign)
4814 inst.operands[i].imm |= reg;
4815 else
4816 inst.operands[i].imm = reg;
c19d1205 4817 inst.operands[i].immisreg = 1;
a737bd4d 4818
c19d1205
ZW
4819 if (skip_past_comma (&p) == SUCCESS)
4820 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4821 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4822 }
4823 else
4824 {
4825 if (inst.operands[i].negative)
4826 {
4827 inst.operands[i].negative = 0;
4828 p--;
4829 }
4830 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4831 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4832 }
4833 }
a737bd4d
NC
4834 }
4835
c19d1205
ZW
4836 /* If at this point neither .preind nor .postind is set, we have a
4837 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4838 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4839 {
4840 inst.operands[i].preind = 1;
4841 inst.reloc.exp.X_op = O_constant;
4842 inst.reloc.exp.X_add_number = 0;
4843 }
4844 *str = p;
4962c51a
MS
4845 return PARSE_OPERAND_SUCCESS;
4846}
4847
4848static int
4849parse_address (char **str, int i)
4850{
4851 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4852 ? SUCCESS : FAIL;
4853}
4854
4855static parse_operand_result
4856parse_address_group_reloc (char **str, int i, group_reloc_type type)
4857{
4858 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4859}
4860
b6895b4f
PB
4861/* Parse an operand for a MOVW or MOVT instruction. */
4862static int
4863parse_half (char **str)
4864{
4865 char * p;
4866
4867 p = *str;
4868 skip_past_char (&p, '#');
4869 if (strncasecmp (p, ":lower16:", 9) == 0)
4870 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4871 else if (strncasecmp (p, ":upper16:", 9) == 0)
4872 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4873
4874 if (inst.reloc.type != BFD_RELOC_UNUSED)
4875 {
4876 p += 9;
4877 skip_whitespace(p);
4878 }
4879
4880 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4881 return FAIL;
4882
4883 if (inst.reloc.type == BFD_RELOC_UNUSED)
4884 {
4885 if (inst.reloc.exp.X_op != O_constant)
4886 {
4887 inst.error = _("constant expression expected");
4888 return FAIL;
4889 }
4890 if (inst.reloc.exp.X_add_number < 0
4891 || inst.reloc.exp.X_add_number > 0xffff)
4892 {
4893 inst.error = _("immediate value out of range");
4894 return FAIL;
4895 }
4896 }
4897 *str = p;
4898 return SUCCESS;
4899}
4900
c19d1205 4901/* Miscellaneous. */
a737bd4d 4902
c19d1205
ZW
4903/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4904 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4905static int
4906parse_psr (char **str)
09d92015 4907{
c19d1205
ZW
4908 char *p;
4909 unsigned long psr_field;
62b3e311
PB
4910 const struct asm_psr *psr;
4911 char *start;
09d92015 4912
c19d1205
ZW
4913 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4914 feature for ease of use and backwards compatibility. */
4915 p = *str;
62b3e311 4916 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4917 psr_field = SPSR_BIT;
62b3e311 4918 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4919 psr_field = 0;
4920 else
62b3e311
PB
4921 {
4922 start = p;
4923 do
4924 p++;
4925 while (ISALNUM (*p) || *p == '_');
4926
4927 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4928 if (!psr)
4929 return FAIL;
09d92015 4930
62b3e311
PB
4931 *str = p;
4932 return psr->field;
4933 }
09d92015 4934
62b3e311 4935 p += 4;
c19d1205
ZW
4936 if (*p == '_')
4937 {
4938 /* A suffix follows. */
c19d1205
ZW
4939 p++;
4940 start = p;
a737bd4d 4941
c19d1205
ZW
4942 do
4943 p++;
4944 while (ISALNUM (*p) || *p == '_');
a737bd4d 4945
c19d1205
ZW
4946 psr = hash_find_n (arm_psr_hsh, start, p - start);
4947 if (!psr)
4948 goto error;
a737bd4d 4949
c19d1205 4950 psr_field |= psr->field;
a737bd4d 4951 }
c19d1205 4952 else
a737bd4d 4953 {
c19d1205
ZW
4954 if (ISALNUM (*p))
4955 goto error; /* Garbage after "[CS]PSR". */
4956
4957 psr_field |= (PSR_c | PSR_f);
a737bd4d 4958 }
c19d1205
ZW
4959 *str = p;
4960 return psr_field;
a737bd4d 4961
c19d1205
ZW
4962 error:
4963 inst.error = _("flag for {c}psr instruction expected");
4964 return FAIL;
a737bd4d
NC
4965}
4966
c19d1205
ZW
4967/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4968 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4969
c19d1205
ZW
4970static int
4971parse_cps_flags (char **str)
a737bd4d 4972{
c19d1205
ZW
4973 int val = 0;
4974 int saw_a_flag = 0;
4975 char *s = *str;
a737bd4d 4976
c19d1205
ZW
4977 for (;;)
4978 switch (*s++)
4979 {
4980 case '\0': case ',':
4981 goto done;
a737bd4d 4982
c19d1205
ZW
4983 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4984 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4985 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4986
c19d1205
ZW
4987 default:
4988 inst.error = _("unrecognized CPS flag");
4989 return FAIL;
4990 }
a737bd4d 4991
c19d1205
ZW
4992 done:
4993 if (saw_a_flag == 0)
a737bd4d 4994 {
c19d1205
ZW
4995 inst.error = _("missing CPS flags");
4996 return FAIL;
a737bd4d 4997 }
a737bd4d 4998
c19d1205
ZW
4999 *str = s - 1;
5000 return val;
a737bd4d
NC
5001}
5002
c19d1205
ZW
5003/* Parse an endian specifier ("BE" or "LE", case insensitive);
5004 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5005
5006static int
c19d1205 5007parse_endian_specifier (char **str)
a737bd4d 5008{
c19d1205
ZW
5009 int little_endian;
5010 char *s = *str;
a737bd4d 5011
c19d1205
ZW
5012 if (strncasecmp (s, "BE", 2))
5013 little_endian = 0;
5014 else if (strncasecmp (s, "LE", 2))
5015 little_endian = 1;
5016 else
a737bd4d 5017 {
c19d1205 5018 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5019 return FAIL;
5020 }
5021
c19d1205 5022 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5023 {
c19d1205 5024 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5025 return FAIL;
5026 }
5027
c19d1205
ZW
5028 *str = s + 2;
5029 return little_endian;
5030}
a737bd4d 5031
c19d1205
ZW
5032/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5033 value suitable for poking into the rotate field of an sxt or sxta
5034 instruction, or FAIL on error. */
5035
5036static int
5037parse_ror (char **str)
5038{
5039 int rot;
5040 char *s = *str;
5041
5042 if (strncasecmp (s, "ROR", 3) == 0)
5043 s += 3;
5044 else
a737bd4d 5045 {
c19d1205 5046 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5047 return FAIL;
5048 }
c19d1205
ZW
5049
5050 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5051 return FAIL;
5052
5053 switch (rot)
a737bd4d 5054 {
c19d1205
ZW
5055 case 0: *str = s; return 0x0;
5056 case 8: *str = s; return 0x1;
5057 case 16: *str = s; return 0x2;
5058 case 24: *str = s; return 0x3;
5059
5060 default:
5061 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5062 return FAIL;
5063 }
c19d1205 5064}
a737bd4d 5065
c19d1205
ZW
5066/* Parse a conditional code (from conds[] below). The value returned is in the
5067 range 0 .. 14, or FAIL. */
5068static int
5069parse_cond (char **str)
5070{
5071 char *p, *q;
5072 const struct asm_cond *c;
a737bd4d 5073
c19d1205
ZW
5074 p = q = *str;
5075 while (ISALPHA (*q))
5076 q++;
a737bd4d 5077
c19d1205
ZW
5078 c = hash_find_n (arm_cond_hsh, p, q - p);
5079 if (!c)
a737bd4d 5080 {
c19d1205 5081 inst.error = _("condition required");
a737bd4d
NC
5082 return FAIL;
5083 }
5084
c19d1205
ZW
5085 *str = q;
5086 return c->value;
5087}
5088
62b3e311
PB
5089/* Parse an option for a barrier instruction. Returns the encoding for the
5090 option, or FAIL. */
5091static int
5092parse_barrier (char **str)
5093{
5094 char *p, *q;
5095 const struct asm_barrier_opt *o;
5096
5097 p = q = *str;
5098 while (ISALPHA (*q))
5099 q++;
5100
5101 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5102 if (!o)
5103 return FAIL;
5104
5105 *str = q;
5106 return o->value;
5107}
5108
92e90b6e
PB
5109/* Parse the operands of a table branch instruction. Similar to a memory
5110 operand. */
5111static int
5112parse_tb (char **str)
5113{
5114 char * p = *str;
5115 int reg;
5116
5117 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5118 {
5119 inst.error = _("'[' expected");
5120 return FAIL;
5121 }
92e90b6e 5122
dcbf9037 5123 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5124 {
5125 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5126 return FAIL;
5127 }
5128 inst.operands[0].reg = reg;
5129
5130 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5131 {
5132 inst.error = _("',' expected");
5133 return FAIL;
5134 }
92e90b6e 5135
dcbf9037 5136 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5137 {
5138 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5139 return FAIL;
5140 }
5141 inst.operands[0].imm = reg;
5142
5143 if (skip_past_comma (&p) == SUCCESS)
5144 {
5145 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5146 return FAIL;
5147 if (inst.reloc.exp.X_add_number != 1)
5148 {
5149 inst.error = _("invalid shift");
5150 return FAIL;
5151 }
5152 inst.operands[0].shifted = 1;
5153 }
5154
5155 if (skip_past_char (&p, ']') == FAIL)
5156 {
5157 inst.error = _("']' expected");
5158 return FAIL;
5159 }
5160 *str = p;
5161 return SUCCESS;
5162}
5163
5287ad62
JB
5164/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5165 information on the types the operands can take and how they are encoded.
037e8744
JB
5166 Up to four operands may be read; this function handles setting the
5167 ".present" field for each read operand itself.
5287ad62
JB
5168 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5169 else returns FAIL. */
5170
5171static int
5172parse_neon_mov (char **str, int *which_operand)
5173{
5174 int i = *which_operand, val;
5175 enum arm_reg_type rtype;
5176 char *ptr = *str;
dcbf9037 5177 struct neon_type_el optype;
5287ad62 5178
dcbf9037 5179 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5180 {
5181 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5182 inst.operands[i].reg = val;
5183 inst.operands[i].isscalar = 1;
dcbf9037 5184 inst.operands[i].vectype = optype;
5287ad62
JB
5185 inst.operands[i++].present = 1;
5186
5187 if (skip_past_comma (&ptr) == FAIL)
5188 goto wanted_comma;
5189
dcbf9037 5190 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62
JB
5191 goto wanted_arm;
5192
5193 inst.operands[i].reg = val;
5194 inst.operands[i].isreg = 1;
5195 inst.operands[i].present = 1;
5196 }
037e8744 5197 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5198 != FAIL)
5287ad62
JB
5199 {
5200 /* Cases 0, 1, 2, 3, 5 (D only). */
5201 if (skip_past_comma (&ptr) == FAIL)
5202 goto wanted_comma;
5203
5204 inst.operands[i].reg = val;
5205 inst.operands[i].isreg = 1;
5206 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5207 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5208 inst.operands[i].isvec = 1;
dcbf9037 5209 inst.operands[i].vectype = optype;
5287ad62
JB
5210 inst.operands[i++].present = 1;
5211
dcbf9037 5212 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5213 {
037e8744
JB
5214 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5215 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5216 inst.operands[i].reg = val;
5217 inst.operands[i].isreg = 1;
037e8744 5218 inst.operands[i].present = 1;
5287ad62
JB
5219
5220 if (rtype == REG_TYPE_NQ)
5221 {
dcbf9037 5222 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5223 return FAIL;
5224 }
037e8744
JB
5225 else if (rtype != REG_TYPE_VFS)
5226 {
5227 i++;
5228 if (skip_past_comma (&ptr) == FAIL)
5229 goto wanted_comma;
5230 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5231 goto wanted_arm;
5232 inst.operands[i].reg = val;
5233 inst.operands[i].isreg = 1;
5234 inst.operands[i].present = 1;
5235 }
5287ad62 5236 }
136da414 5237 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5238 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5239 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5240 Case 10: VMOV.F32 <Sd>, #<imm>
5241 Case 11: VMOV.F64 <Dd>, #<imm> */
c96612cc 5242 inst.operands[i].immisfloat = 1;
5287ad62 5243 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5244 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5245 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5246 ;
5247 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5248 &optype)) != FAIL)
5287ad62
JB
5249 {
5250 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5251 Case 1: VMOV<c><q> <Dd>, <Dm>
5252 Case 8: VMOV.F32 <Sd>, <Sm>
5253 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5254
5255 inst.operands[i].reg = val;
5256 inst.operands[i].isreg = 1;
5257 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5258 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5259 inst.operands[i].isvec = 1;
dcbf9037 5260 inst.operands[i].vectype = optype;
5287ad62 5261 inst.operands[i].present = 1;
037e8744
JB
5262
5263 if (skip_past_comma (&ptr) == SUCCESS)
5264 {
5265 /* Case 15. */
5266 i++;
5267
5268 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5269 goto wanted_arm;
5270
5271 inst.operands[i].reg = val;
5272 inst.operands[i].isreg = 1;
5273 inst.operands[i++].present = 1;
5274
5275 if (skip_past_comma (&ptr) == FAIL)
5276 goto wanted_comma;
5277
5278 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5279 goto wanted_arm;
5280
5281 inst.operands[i].reg = val;
5282 inst.operands[i].isreg = 1;
5283 inst.operands[i++].present = 1;
5284 }
5287ad62
JB
5285 }
5286 else
5287 {
dcbf9037 5288 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5289 return FAIL;
5290 }
5291 }
dcbf9037 5292 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5293 {
5294 /* Cases 6, 7. */
5295 inst.operands[i].reg = val;
5296 inst.operands[i].isreg = 1;
5297 inst.operands[i++].present = 1;
5298
5299 if (skip_past_comma (&ptr) == FAIL)
5300 goto wanted_comma;
5301
dcbf9037 5302 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5303 {
5304 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5305 inst.operands[i].reg = val;
5306 inst.operands[i].isscalar = 1;
5307 inst.operands[i].present = 1;
dcbf9037 5308 inst.operands[i].vectype = optype;
5287ad62 5309 }
dcbf9037 5310 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5311 {
5312 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5313 inst.operands[i].reg = val;
5314 inst.operands[i].isreg = 1;
5315 inst.operands[i++].present = 1;
5316
5317 if (skip_past_comma (&ptr) == FAIL)
5318 goto wanted_comma;
5319
037e8744 5320 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5321 == FAIL)
5287ad62 5322 {
037e8744 5323 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5324 return FAIL;
5325 }
5326
5327 inst.operands[i].reg = val;
5328 inst.operands[i].isreg = 1;
037e8744
JB
5329 inst.operands[i].isvec = 1;
5330 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5331 inst.operands[i].vectype = optype;
5287ad62 5332 inst.operands[i].present = 1;
037e8744
JB
5333
5334 if (rtype == REG_TYPE_VFS)
5335 {
5336 /* Case 14. */
5337 i++;
5338 if (skip_past_comma (&ptr) == FAIL)
5339 goto wanted_comma;
5340 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5341 &optype)) == FAIL)
5342 {
5343 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5344 return FAIL;
5345 }
5346 inst.operands[i].reg = val;
5347 inst.operands[i].isreg = 1;
5348 inst.operands[i].isvec = 1;
5349 inst.operands[i].issingle = 1;
5350 inst.operands[i].vectype = optype;
5351 inst.operands[i].present = 1;
5352 }
5353 }
5354 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5355 != FAIL)
5356 {
5357 /* Case 13. */
5358 inst.operands[i].reg = val;
5359 inst.operands[i].isreg = 1;
5360 inst.operands[i].isvec = 1;
5361 inst.operands[i].issingle = 1;
5362 inst.operands[i].vectype = optype;
5363 inst.operands[i++].present = 1;
5287ad62
JB
5364 }
5365 }
5366 else
5367 {
dcbf9037 5368 first_error (_("parse error"));
5287ad62
JB
5369 return FAIL;
5370 }
5371
5372 /* Successfully parsed the operands. Update args. */
5373 *which_operand = i;
5374 *str = ptr;
5375 return SUCCESS;
5376
5377 wanted_comma:
dcbf9037 5378 first_error (_("expected comma"));
5287ad62
JB
5379 return FAIL;
5380
5381 wanted_arm:
dcbf9037 5382 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5383 return FAIL;
5287ad62
JB
5384}
5385
c19d1205
ZW
5386/* Matcher codes for parse_operands. */
5387enum operand_parse_code
5388{
5389 OP_stop, /* end of line */
5390
5391 OP_RR, /* ARM register */
5392 OP_RRnpc, /* ARM register, not r15 */
5393 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5394 OP_RRw, /* ARM register, not r15, optional trailing ! */
5395 OP_RCP, /* Coprocessor number */
5396 OP_RCN, /* Coprocessor register */
5397 OP_RF, /* FPA register */
5398 OP_RVS, /* VFP single precision register */
5287ad62
JB
5399 OP_RVD, /* VFP double precision register (0..15) */
5400 OP_RND, /* Neon double precision register (0..31) */
5401 OP_RNQ, /* Neon quad precision register */
037e8744 5402 OP_RVSD, /* VFP single or double precision register */
5287ad62 5403 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5404 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5405 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5406 OP_RVC, /* VFP control register */
5407 OP_RMF, /* Maverick F register */
5408 OP_RMD, /* Maverick D register */
5409 OP_RMFX, /* Maverick FX register */
5410 OP_RMDX, /* Maverick DX register */
5411 OP_RMAX, /* Maverick AX register */
5412 OP_RMDS, /* Maverick DSPSC register */
5413 OP_RIWR, /* iWMMXt wR register */
5414 OP_RIWC, /* iWMMXt wC register */
5415 OP_RIWG, /* iWMMXt wCG register */
5416 OP_RXA, /* XScale accumulator register */
5417
5418 OP_REGLST, /* ARM register list */
5419 OP_VRSLST, /* VFP single-precision register list */
5420 OP_VRDLST, /* VFP double-precision register list */
037e8744 5421 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5422 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5423 OP_NSTRLST, /* Neon element/structure list */
5424
5425 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5426 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5427 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5428 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5429 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5430 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5431 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5432 OP_VMOV, /* Neon VMOV operands. */
5433 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5434 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5435 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5436
5437 OP_I0, /* immediate zero */
c19d1205
ZW
5438 OP_I7, /* immediate value 0 .. 7 */
5439 OP_I15, /* 0 .. 15 */
5440 OP_I16, /* 1 .. 16 */
5287ad62 5441 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5442 OP_I31, /* 0 .. 31 */
5443 OP_I31w, /* 0 .. 31, optional trailing ! */
5444 OP_I32, /* 1 .. 32 */
5287ad62
JB
5445 OP_I32z, /* 0 .. 32 */
5446 OP_I63, /* 0 .. 63 */
c19d1205 5447 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5448 OP_I64, /* 1 .. 64 */
5449 OP_I64z, /* 0 .. 64 */
c19d1205 5450 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5451
5452 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5453 OP_I7b, /* 0 .. 7 */
5454 OP_I15b, /* 0 .. 15 */
5455 OP_I31b, /* 0 .. 31 */
5456
5457 OP_SH, /* shifter operand */
4962c51a 5458 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5459 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5460 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5461 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5462 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5463 OP_EXP, /* arbitrary expression */
5464 OP_EXPi, /* same, with optional immediate prefix */
5465 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5466 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5467
5468 OP_CPSF, /* CPS flags */
5469 OP_ENDI, /* Endianness specifier */
5470 OP_PSR, /* CPSR/SPSR mask for msr */
5471 OP_COND, /* conditional code */
92e90b6e 5472 OP_TB, /* Table branch. */
c19d1205 5473
037e8744
JB
5474 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5475 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5476
c19d1205
ZW
5477 OP_RRnpc_I0, /* ARM register or literal 0 */
5478 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5479 OP_RR_EXi, /* ARM register or expression with imm prefix */
5480 OP_RF_IF, /* FPA register or immediate */
5481 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5482 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5483
5484 /* Optional operands. */
5485 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5486 OP_oI31b, /* 0 .. 31 */
5287ad62 5487 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5488 OP_oIffffb, /* 0 .. 65535 */
5489 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5490
5491 OP_oRR, /* ARM register */
5492 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5493 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5494 OP_oRND, /* Optional Neon double precision register */
5495 OP_oRNQ, /* Optional Neon quad precision register */
5496 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5497 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5498 OP_oSHll, /* LSL immediate */
5499 OP_oSHar, /* ASR immediate */
5500 OP_oSHllar, /* LSL or ASR immediate */
5501 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5502 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5503
5504 OP_FIRST_OPTIONAL = OP_oI7b
5505};
a737bd4d 5506
c19d1205
ZW
5507/* Generic instruction operand parser. This does no encoding and no
5508 semantic validation; it merely squirrels values away in the inst
5509 structure. Returns SUCCESS or FAIL depending on whether the
5510 specified grammar matched. */
5511static int
ca3f61f7 5512parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5513{
5514 unsigned const char *upat = pattern;
5515 char *backtrack_pos = 0;
5516 const char *backtrack_error = 0;
5517 int i, val, backtrack_index = 0;
5287ad62 5518 enum arm_reg_type rtype;
4962c51a 5519 parse_operand_result result;
c19d1205
ZW
5520
5521#define po_char_or_fail(chr) do { \
5522 if (skip_past_char (&str, chr) == FAIL) \
5523 goto bad_args; \
5524} while (0)
5525
dcbf9037
JB
5526#define po_reg_or_fail(regtype) do { \
5527 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5528 &inst.operands[i].vectype); \
5529 if (val == FAIL) \
5530 { \
5531 first_error (_(reg_expected_msgs[regtype])); \
5532 goto failure; \
5533 } \
5534 inst.operands[i].reg = val; \
5535 inst.operands[i].isreg = 1; \
5536 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5537 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5538 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5539 || rtype == REG_TYPE_VFD \
5540 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5541} while (0)
5542
dcbf9037
JB
5543#define po_reg_or_goto(regtype, label) do { \
5544 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5545 &inst.operands[i].vectype); \
5546 if (val == FAIL) \
5547 goto label; \
5548 \
5549 inst.operands[i].reg = val; \
5550 inst.operands[i].isreg = 1; \
5551 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5552 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5553 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5554 || rtype == REG_TYPE_VFD \
5555 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5556} while (0)
5557
5558#define po_imm_or_fail(min, max, popt) do { \
5559 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5560 goto failure; \
5561 inst.operands[i].imm = val; \
5562} while (0)
5563
dcbf9037
JB
5564#define po_scalar_or_goto(elsz, label) do { \
5565 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5566 if (val == FAIL) \
5567 goto label; \
5568 inst.operands[i].reg = val; \
5569 inst.operands[i].isscalar = 1; \
5287ad62
JB
5570} while (0)
5571
c19d1205
ZW
5572#define po_misc_or_fail(expr) do { \
5573 if (expr) \
5574 goto failure; \
5575} while (0)
5576
4962c51a
MS
5577#define po_misc_or_fail_no_backtrack(expr) do { \
5578 result = expr; \
5579 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5580 backtrack_pos = 0; \
5581 if (result != PARSE_OPERAND_SUCCESS) \
5582 goto failure; \
5583} while (0)
5584
c19d1205
ZW
5585 skip_whitespace (str);
5586
5587 for (i = 0; upat[i] != OP_stop; i++)
5588 {
5589 if (upat[i] >= OP_FIRST_OPTIONAL)
5590 {
5591 /* Remember where we are in case we need to backtrack. */
5592 assert (!backtrack_pos);
5593 backtrack_pos = str;
5594 backtrack_error = inst.error;
5595 backtrack_index = i;
5596 }
5597
b6702015 5598 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5599 po_char_or_fail (',');
5600
5601 switch (upat[i])
5602 {
5603 /* Registers */
5604 case OP_oRRnpc:
5605 case OP_RRnpc:
5606 case OP_oRR:
5607 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5608 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5609 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5610 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5611 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5612 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5613 case OP_oRND:
5614 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
c19d1205
ZW
5615 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
5616 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5617 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5618 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5619 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5620 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5621 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5622 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5623 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5624 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5625 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5626 case OP_oRNQ:
5627 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5628 case OP_oRNDQ:
5629 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5630 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5631 case OP_oRNSDQ:
5632 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5633
5634 /* Neon scalar. Using an element size of 8 means that some invalid
5635 scalars are accepted here, so deal with those in later code. */
5636 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5637
5638 /* WARNING: We can expand to two operands here. This has the potential
5639 to totally confuse the backtracking mechanism! It will be OK at
5640 least as long as we don't try to use optional args as well,
5641 though. */
5642 case OP_NILO:
5643 {
5644 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5645 inst.operands[i].present = 1;
5287ad62
JB
5646 i++;
5647 skip_past_comma (&str);
5648 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5649 break;
5650 one_reg_only:
5651 /* Optional register operand was omitted. Unfortunately, it's in
5652 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5653 here (this is a bit grotty). */
5654 inst.operands[i] = inst.operands[i-1];
5655 inst.operands[i-1].present = 0;
5656 break;
5657 try_imm:
036dc3f7
PB
5658 /* There's a possibility of getting a 64-bit immediate here, so
5659 we need special handling. */
5660 if (parse_big_immediate (&str, i) == FAIL)
5661 {
5662 inst.error = _("immediate value is out of range");
5663 goto failure;
5664 }
5287ad62
JB
5665 }
5666 break;
5667
5668 case OP_RNDQ_I0:
5669 {
5670 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5671 break;
5672 try_imm0:
5673 po_imm_or_fail (0, 0, TRUE);
5674 }
5675 break;
5676
037e8744
JB
5677 case OP_RVSD_I0:
5678 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5679 break;
5680
5287ad62
JB
5681 case OP_RR_RNSC:
5682 {
5683 po_scalar_or_goto (8, try_rr);
5684 break;
5685 try_rr:
5686 po_reg_or_fail (REG_TYPE_RN);
5687 }
5688 break;
5689
037e8744
JB
5690 case OP_RNSDQ_RNSC:
5691 {
5692 po_scalar_or_goto (8, try_nsdq);
5693 break;
5694 try_nsdq:
5695 po_reg_or_fail (REG_TYPE_NSDQ);
5696 }
5697 break;
5698
5287ad62
JB
5699 case OP_RNDQ_RNSC:
5700 {
5701 po_scalar_or_goto (8, try_ndq);
5702 break;
5703 try_ndq:
5704 po_reg_or_fail (REG_TYPE_NDQ);
5705 }
5706 break;
5707
5708 case OP_RND_RNSC:
5709 {
5710 po_scalar_or_goto (8, try_vfd);
5711 break;
5712 try_vfd:
5713 po_reg_or_fail (REG_TYPE_VFD);
5714 }
5715 break;
5716
5717 case OP_VMOV:
5718 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5719 not careful then bad things might happen. */
5720 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5721 break;
5722
5723 case OP_RNDQ_IMVNb:
5724 {
5725 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5726 break;
5727 try_mvnimm:
5728 /* There's a possibility of getting a 64-bit immediate here, so
5729 we need special handling. */
5730 if (parse_big_immediate (&str, i) == FAIL)
5731 {
5732 inst.error = _("immediate value is out of range");
5733 goto failure;
5734 }
5735 }
5736 break;
5737
5738 case OP_RNDQ_I63b:
5739 {
5740 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5741 break;
5742 try_shimm:
5743 po_imm_or_fail (0, 63, TRUE);
5744 }
5745 break;
c19d1205
ZW
5746
5747 case OP_RRnpcb:
5748 po_char_or_fail ('[');
5749 po_reg_or_fail (REG_TYPE_RN);
5750 po_char_or_fail (']');
5751 break;
a737bd4d 5752
c19d1205 5753 case OP_RRw:
b6702015 5754 case OP_oRRw:
c19d1205
ZW
5755 po_reg_or_fail (REG_TYPE_RN);
5756 if (skip_past_char (&str, '!') == SUCCESS)
5757 inst.operands[i].writeback = 1;
5758 break;
5759
5760 /* Immediates */
5761 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5762 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5763 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5764 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5765 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5766 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5767 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5768 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5769 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5770 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5771 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5772 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5773
5774 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5775 case OP_oI7b:
5776 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5777 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5778 case OP_oI31b:
5779 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5780 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5781 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5782
5783 /* Immediate variants */
5784 case OP_oI255c:
5785 po_char_or_fail ('{');
5786 po_imm_or_fail (0, 255, TRUE);
5787 po_char_or_fail ('}');
5788 break;
5789
5790 case OP_I31w:
5791 /* The expression parser chokes on a trailing !, so we have
5792 to find it first and zap it. */
5793 {
5794 char *s = str;
5795 while (*s && *s != ',')
5796 s++;
5797 if (s[-1] == '!')
5798 {
5799 s[-1] = '\0';
5800 inst.operands[i].writeback = 1;
5801 }
5802 po_imm_or_fail (0, 31, TRUE);
5803 if (str == s - 1)
5804 str = s;
5805 }
5806 break;
5807
5808 /* Expressions */
5809 case OP_EXPi: EXPi:
5810 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5811 GE_OPT_PREFIX));
5812 break;
5813
5814 case OP_EXP:
5815 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5816 GE_NO_PREFIX));
5817 break;
5818
5819 case OP_EXPr: EXPr:
5820 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5821 GE_NO_PREFIX));
5822 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5823 {
c19d1205
ZW
5824 val = parse_reloc (&str);
5825 if (val == -1)
5826 {
5827 inst.error = _("unrecognized relocation suffix");
5828 goto failure;
5829 }
5830 else if (val != BFD_RELOC_UNUSED)
5831 {
5832 inst.operands[i].imm = val;
5833 inst.operands[i].hasreloc = 1;
5834 }
a737bd4d 5835 }
c19d1205 5836 break;
a737bd4d 5837
b6895b4f
PB
5838 /* Operand for MOVW or MOVT. */
5839 case OP_HALF:
5840 po_misc_or_fail (parse_half (&str));
5841 break;
5842
c19d1205
ZW
5843 /* Register or expression */
5844 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5845 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5846
c19d1205
ZW
5847 /* Register or immediate */
5848 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5849 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5850
c19d1205
ZW
5851 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5852 IF:
5853 if (!is_immediate_prefix (*str))
5854 goto bad_args;
5855 str++;
5856 val = parse_fpa_immediate (&str);
5857 if (val == FAIL)
5858 goto failure;
5859 /* FPA immediates are encoded as registers 8-15.
5860 parse_fpa_immediate has already applied the offset. */
5861 inst.operands[i].reg = val;
5862 inst.operands[i].isreg = 1;
5863 break;
09d92015 5864
2d447fca
JM
5865 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5866 I32z: po_imm_or_fail (0, 32, FALSE); break;
5867
c19d1205
ZW
5868 /* Two kinds of register */
5869 case OP_RIWR_RIWC:
5870 {
5871 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5872 if (!rege
5873 || (rege->type != REG_TYPE_MMXWR
5874 && rege->type != REG_TYPE_MMXWC
5875 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5876 {
5877 inst.error = _("iWMMXt data or control register expected");
5878 goto failure;
5879 }
5880 inst.operands[i].reg = rege->number;
5881 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5882 }
5883 break;
09d92015 5884
41adaa5c
JM
5885 case OP_RIWC_RIWG:
5886 {
5887 struct reg_entry *rege = arm_reg_parse_multi (&str);
5888 if (!rege
5889 || (rege->type != REG_TYPE_MMXWC
5890 && rege->type != REG_TYPE_MMXWCG))
5891 {
5892 inst.error = _("iWMMXt control register expected");
5893 goto failure;
5894 }
5895 inst.operands[i].reg = rege->number;
5896 inst.operands[i].isreg = 1;
5897 }
5898 break;
5899
c19d1205
ZW
5900 /* Misc */
5901 case OP_CPSF: val = parse_cps_flags (&str); break;
5902 case OP_ENDI: val = parse_endian_specifier (&str); break;
5903 case OP_oROR: val = parse_ror (&str); break;
5904 case OP_PSR: val = parse_psr (&str); break;
5905 case OP_COND: val = parse_cond (&str); break;
62b3e311 5906 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5907
037e8744
JB
5908 case OP_RVC_PSR:
5909 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5910 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5911 break;
5912 try_psr:
5913 val = parse_psr (&str);
5914 break;
5915
5916 case OP_APSR_RR:
5917 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5918 break;
5919 try_apsr:
5920 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5921 instruction). */
5922 if (strncasecmp (str, "APSR_", 5) == 0)
5923 {
5924 unsigned found = 0;
5925 str += 5;
5926 while (found < 15)
5927 switch (*str++)
5928 {
5929 case 'c': found = (found & 1) ? 16 : found | 1; break;
5930 case 'n': found = (found & 2) ? 16 : found | 2; break;
5931 case 'z': found = (found & 4) ? 16 : found | 4; break;
5932 case 'v': found = (found & 8) ? 16 : found | 8; break;
5933 default: found = 16;
5934 }
5935 if (found != 15)
5936 goto failure;
5937 inst.operands[i].isvec = 1;
5938 }
5939 else
5940 goto failure;
5941 break;
5942
92e90b6e
PB
5943 case OP_TB:
5944 po_misc_or_fail (parse_tb (&str));
5945 break;
5946
c19d1205
ZW
5947 /* Register lists */
5948 case OP_REGLST:
5949 val = parse_reg_list (&str);
5950 if (*str == '^')
5951 {
5952 inst.operands[1].writeback = 1;
5953 str++;
5954 }
5955 break;
09d92015 5956
c19d1205 5957 case OP_VRSLST:
5287ad62 5958 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5959 break;
09d92015 5960
c19d1205 5961 case OP_VRDLST:
5287ad62 5962 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5963 break;
a737bd4d 5964
037e8744
JB
5965 case OP_VRSDLST:
5966 /* Allow Q registers too. */
5967 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5968 REGLIST_NEON_D);
5969 if (val == FAIL)
5970 {
5971 inst.error = NULL;
5972 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5973 REGLIST_VFP_S);
5974 inst.operands[i].issingle = 1;
5975 }
5976 break;
5977
5287ad62
JB
5978 case OP_NRDLST:
5979 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5980 REGLIST_NEON_D);
5981 break;
5982
5983 case OP_NSTRLST:
dcbf9037
JB
5984 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5985 &inst.operands[i].vectype);
5287ad62
JB
5986 break;
5987
c19d1205
ZW
5988 /* Addressing modes */
5989 case OP_ADDR:
5990 po_misc_or_fail (parse_address (&str, i));
5991 break;
09d92015 5992
4962c51a
MS
5993 case OP_ADDRGLDR:
5994 po_misc_or_fail_no_backtrack (
5995 parse_address_group_reloc (&str, i, GROUP_LDR));
5996 break;
5997
5998 case OP_ADDRGLDRS:
5999 po_misc_or_fail_no_backtrack (
6000 parse_address_group_reloc (&str, i, GROUP_LDRS));
6001 break;
6002
6003 case OP_ADDRGLDC:
6004 po_misc_or_fail_no_backtrack (
6005 parse_address_group_reloc (&str, i, GROUP_LDC));
6006 break;
6007
c19d1205
ZW
6008 case OP_SH:
6009 po_misc_or_fail (parse_shifter_operand (&str, i));
6010 break;
09d92015 6011
4962c51a
MS
6012 case OP_SHG:
6013 po_misc_or_fail_no_backtrack (
6014 parse_shifter_operand_group_reloc (&str, i));
6015 break;
6016
c19d1205
ZW
6017 case OP_oSHll:
6018 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6019 break;
09d92015 6020
c19d1205
ZW
6021 case OP_oSHar:
6022 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6023 break;
09d92015 6024
c19d1205
ZW
6025 case OP_oSHllar:
6026 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6027 break;
09d92015 6028
c19d1205
ZW
6029 default:
6030 as_fatal ("unhandled operand code %d", upat[i]);
6031 }
09d92015 6032
c19d1205
ZW
6033 /* Various value-based sanity checks and shared operations. We
6034 do not signal immediate failures for the register constraints;
6035 this allows a syntax error to take precedence. */
6036 switch (upat[i])
6037 {
6038 case OP_oRRnpc:
6039 case OP_RRnpc:
6040 case OP_RRnpcb:
6041 case OP_RRw:
b6702015 6042 case OP_oRRw:
c19d1205
ZW
6043 case OP_RRnpc_I0:
6044 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6045 inst.error = BAD_PC;
6046 break;
09d92015 6047
c19d1205
ZW
6048 case OP_CPSF:
6049 case OP_ENDI:
6050 case OP_oROR:
6051 case OP_PSR:
037e8744 6052 case OP_RVC_PSR:
c19d1205 6053 case OP_COND:
62b3e311 6054 case OP_oBARRIER:
c19d1205
ZW
6055 case OP_REGLST:
6056 case OP_VRSLST:
6057 case OP_VRDLST:
037e8744 6058 case OP_VRSDLST:
5287ad62
JB
6059 case OP_NRDLST:
6060 case OP_NSTRLST:
c19d1205
ZW
6061 if (val == FAIL)
6062 goto failure;
6063 inst.operands[i].imm = val;
6064 break;
a737bd4d 6065
c19d1205
ZW
6066 default:
6067 break;
6068 }
09d92015 6069
c19d1205
ZW
6070 /* If we get here, this operand was successfully parsed. */
6071 inst.operands[i].present = 1;
6072 continue;
09d92015 6073
c19d1205 6074 bad_args:
09d92015 6075 inst.error = BAD_ARGS;
c19d1205
ZW
6076
6077 failure:
6078 if (!backtrack_pos)
d252fdde
PB
6079 {
6080 /* The parse routine should already have set inst.error, but set a
6081 defaut here just in case. */
6082 if (!inst.error)
6083 inst.error = _("syntax error");
6084 return FAIL;
6085 }
c19d1205
ZW
6086
6087 /* Do not backtrack over a trailing optional argument that
6088 absorbed some text. We will only fail again, with the
6089 'garbage following instruction' error message, which is
6090 probably less helpful than the current one. */
6091 if (backtrack_index == i && backtrack_pos != str
6092 && upat[i+1] == OP_stop)
d252fdde
PB
6093 {
6094 if (!inst.error)
6095 inst.error = _("syntax error");
6096 return FAIL;
6097 }
c19d1205
ZW
6098
6099 /* Try again, skipping the optional argument at backtrack_pos. */
6100 str = backtrack_pos;
6101 inst.error = backtrack_error;
6102 inst.operands[backtrack_index].present = 0;
6103 i = backtrack_index;
6104 backtrack_pos = 0;
09d92015 6105 }
09d92015 6106
c19d1205
ZW
6107 /* Check that we have parsed all the arguments. */
6108 if (*str != '\0' && !inst.error)
6109 inst.error = _("garbage following instruction");
09d92015 6110
c19d1205 6111 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6112}
6113
c19d1205
ZW
6114#undef po_char_or_fail
6115#undef po_reg_or_fail
6116#undef po_reg_or_goto
6117#undef po_imm_or_fail
5287ad62 6118#undef po_scalar_or_fail
c19d1205
ZW
6119\f
6120/* Shorthand macro for instruction encoding functions issuing errors. */
6121#define constraint(expr, err) do { \
6122 if (expr) \
6123 { \
6124 inst.error = err; \
6125 return; \
6126 } \
6127} while (0)
6128
6129/* Functions for operand encoding. ARM, then Thumb. */
6130
6131#define rotate_left(v, n) (v << n | v >> (32 - n))
6132
6133/* If VAL can be encoded in the immediate field of an ARM instruction,
6134 return the encoded form. Otherwise, return FAIL. */
6135
6136static unsigned int
6137encode_arm_immediate (unsigned int val)
09d92015 6138{
c19d1205
ZW
6139 unsigned int a, i;
6140
6141 for (i = 0; i < 32; i += 2)
6142 if ((a = rotate_left (val, i)) <= 0xff)
6143 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6144
6145 return FAIL;
09d92015
MM
6146}
6147
c19d1205
ZW
6148/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6149 return the encoded form. Otherwise, return FAIL. */
6150static unsigned int
6151encode_thumb32_immediate (unsigned int val)
09d92015 6152{
c19d1205 6153 unsigned int a, i;
09d92015 6154
9c3c69f2 6155 if (val <= 0xff)
c19d1205 6156 return val;
a737bd4d 6157
9c3c69f2 6158 for (i = 1; i <= 24; i++)
09d92015 6159 {
9c3c69f2
PB
6160 a = val >> i;
6161 if ((val & ~(0xff << i)) == 0)
6162 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6163 }
a737bd4d 6164
c19d1205
ZW
6165 a = val & 0xff;
6166 if (val == ((a << 16) | a))
6167 return 0x100 | a;
6168 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6169 return 0x300 | a;
09d92015 6170
c19d1205
ZW
6171 a = val & 0xff00;
6172 if (val == ((a << 16) | a))
6173 return 0x200 | (a >> 8);
a737bd4d 6174
c19d1205 6175 return FAIL;
09d92015 6176}
5287ad62 6177/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6178
6179static void
5287ad62
JB
6180encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6181{
6182 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6183 && reg > 15)
6184 {
6185 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6186 {
6187 if (thumb_mode)
6188 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6189 fpu_vfp_ext_v3);
6190 else
6191 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6192 fpu_vfp_ext_v3);
6193 }
6194 else
6195 {
dcbf9037 6196 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6197 return;
6198 }
6199 }
6200
c19d1205 6201 switch (pos)
09d92015 6202 {
c19d1205
ZW
6203 case VFP_REG_Sd:
6204 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6205 break;
6206
6207 case VFP_REG_Sn:
6208 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6209 break;
6210
6211 case VFP_REG_Sm:
6212 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6213 break;
6214
5287ad62
JB
6215 case VFP_REG_Dd:
6216 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6217 break;
6218
6219 case VFP_REG_Dn:
6220 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6221 break;
6222
6223 case VFP_REG_Dm:
6224 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6225 break;
6226
c19d1205
ZW
6227 default:
6228 abort ();
09d92015 6229 }
09d92015
MM
6230}
6231
c19d1205 6232/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6233 if any, is handled by md_apply_fix. */
09d92015 6234static void
c19d1205 6235encode_arm_shift (int i)
09d92015 6236{
c19d1205
ZW
6237 if (inst.operands[i].shift_kind == SHIFT_RRX)
6238 inst.instruction |= SHIFT_ROR << 5;
6239 else
09d92015 6240 {
c19d1205
ZW
6241 inst.instruction |= inst.operands[i].shift_kind << 5;
6242 if (inst.operands[i].immisreg)
6243 {
6244 inst.instruction |= SHIFT_BY_REG;
6245 inst.instruction |= inst.operands[i].imm << 8;
6246 }
6247 else
6248 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6249 }
c19d1205 6250}
09d92015 6251
c19d1205
ZW
6252static void
6253encode_arm_shifter_operand (int i)
6254{
6255 if (inst.operands[i].isreg)
09d92015 6256 {
c19d1205
ZW
6257 inst.instruction |= inst.operands[i].reg;
6258 encode_arm_shift (i);
09d92015 6259 }
c19d1205
ZW
6260 else
6261 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6262}
6263
c19d1205 6264/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6265static void
c19d1205 6266encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6267{
c19d1205
ZW
6268 assert (inst.operands[i].isreg);
6269 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6270
c19d1205 6271 if (inst.operands[i].preind)
09d92015 6272 {
c19d1205
ZW
6273 if (is_t)
6274 {
6275 inst.error = _("instruction does not accept preindexed addressing");
6276 return;
6277 }
6278 inst.instruction |= PRE_INDEX;
6279 if (inst.operands[i].writeback)
6280 inst.instruction |= WRITE_BACK;
09d92015 6281
c19d1205
ZW
6282 }
6283 else if (inst.operands[i].postind)
6284 {
6285 assert (inst.operands[i].writeback);
6286 if (is_t)
6287 inst.instruction |= WRITE_BACK;
6288 }
6289 else /* unindexed - only for coprocessor */
09d92015 6290 {
c19d1205 6291 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6292 return;
6293 }
6294
c19d1205
ZW
6295 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6296 && (((inst.instruction & 0x000f0000) >> 16)
6297 == ((inst.instruction & 0x0000f000) >> 12)))
6298 as_warn ((inst.instruction & LOAD_BIT)
6299 ? _("destination register same as write-back base")
6300 : _("source register same as write-back base"));
09d92015
MM
6301}
6302
c19d1205
ZW
6303/* inst.operands[i] was set up by parse_address. Encode it into an
6304 ARM-format mode 2 load or store instruction. If is_t is true,
6305 reject forms that cannot be used with a T instruction (i.e. not
6306 post-indexed). */
a737bd4d 6307static void
c19d1205 6308encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6309{
c19d1205 6310 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6311
c19d1205 6312 if (inst.operands[i].immisreg)
09d92015 6313 {
c19d1205
ZW
6314 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6315 inst.instruction |= inst.operands[i].imm;
6316 if (!inst.operands[i].negative)
6317 inst.instruction |= INDEX_UP;
6318 if (inst.operands[i].shifted)
6319 {
6320 if (inst.operands[i].shift_kind == SHIFT_RRX)
6321 inst.instruction |= SHIFT_ROR << 5;
6322 else
6323 {
6324 inst.instruction |= inst.operands[i].shift_kind << 5;
6325 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6326 }
6327 }
09d92015 6328 }
c19d1205 6329 else /* immediate offset in inst.reloc */
09d92015 6330 {
c19d1205
ZW
6331 if (inst.reloc.type == BFD_RELOC_UNUSED)
6332 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6333 }
09d92015
MM
6334}
6335
c19d1205
ZW
6336/* inst.operands[i] was set up by parse_address. Encode it into an
6337 ARM-format mode 3 load or store instruction. Reject forms that
6338 cannot be used with such instructions. If is_t is true, reject
6339 forms that cannot be used with a T instruction (i.e. not
6340 post-indexed). */
6341static void
6342encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6343{
c19d1205 6344 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6345 {
c19d1205
ZW
6346 inst.error = _("instruction does not accept scaled register index");
6347 return;
09d92015 6348 }
a737bd4d 6349
c19d1205 6350 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6351
c19d1205
ZW
6352 if (inst.operands[i].immisreg)
6353 {
6354 inst.instruction |= inst.operands[i].imm;
6355 if (!inst.operands[i].negative)
6356 inst.instruction |= INDEX_UP;
6357 }
6358 else /* immediate offset in inst.reloc */
6359 {
6360 inst.instruction |= HWOFFSET_IMM;
6361 if (inst.reloc.type == BFD_RELOC_UNUSED)
6362 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6363 }
a737bd4d
NC
6364}
6365
c19d1205
ZW
6366/* inst.operands[i] was set up by parse_address. Encode it into an
6367 ARM-format instruction. Reject all forms which cannot be encoded
6368 into a coprocessor load/store instruction. If wb_ok is false,
6369 reject use of writeback; if unind_ok is false, reject use of
6370 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6371 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6372 (in which case it is preserved). */
09d92015 6373
c19d1205
ZW
6374static int
6375encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6376{
c19d1205 6377 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6378
c19d1205 6379 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6380
c19d1205 6381 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6382 {
c19d1205
ZW
6383 assert (!inst.operands[i].writeback);
6384 if (!unind_ok)
6385 {
6386 inst.error = _("instruction does not support unindexed addressing");
6387 return FAIL;
6388 }
6389 inst.instruction |= inst.operands[i].imm;
6390 inst.instruction |= INDEX_UP;
6391 return SUCCESS;
09d92015 6392 }
a737bd4d 6393
c19d1205
ZW
6394 if (inst.operands[i].preind)
6395 inst.instruction |= PRE_INDEX;
a737bd4d 6396
c19d1205 6397 if (inst.operands[i].writeback)
09d92015 6398 {
c19d1205
ZW
6399 if (inst.operands[i].reg == REG_PC)
6400 {
6401 inst.error = _("pc may not be used with write-back");
6402 return FAIL;
6403 }
6404 if (!wb_ok)
6405 {
6406 inst.error = _("instruction does not support writeback");
6407 return FAIL;
6408 }
6409 inst.instruction |= WRITE_BACK;
09d92015 6410 }
a737bd4d 6411
c19d1205
ZW
6412 if (reloc_override)
6413 inst.reloc.type = reloc_override;
4962c51a
MS
6414 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6415 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6416 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6417 {
6418 if (thumb_mode)
6419 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6420 else
6421 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6422 }
6423
c19d1205
ZW
6424 return SUCCESS;
6425}
a737bd4d 6426
c19d1205
ZW
6427/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6428 Determine whether it can be performed with a move instruction; if
6429 it can, convert inst.instruction to that move instruction and
6430 return 1; if it can't, convert inst.instruction to a literal-pool
6431 load and return 0. If this is not a valid thing to do in the
6432 current context, set inst.error and return 1.
a737bd4d 6433
c19d1205
ZW
6434 inst.operands[i] describes the destination register. */
6435
6436static int
6437move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6438{
53365c0d
PB
6439 unsigned long tbit;
6440
6441 if (thumb_p)
6442 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6443 else
6444 tbit = LOAD_BIT;
6445
6446 if ((inst.instruction & tbit) == 0)
09d92015 6447 {
c19d1205
ZW
6448 inst.error = _("invalid pseudo operation");
6449 return 1;
09d92015 6450 }
c19d1205 6451 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6452 {
6453 inst.error = _("constant expression expected");
c19d1205 6454 return 1;
09d92015 6455 }
c19d1205 6456 if (inst.reloc.exp.X_op == O_constant)
09d92015 6457 {
c19d1205
ZW
6458 if (thumb_p)
6459 {
53365c0d 6460 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6461 {
6462 /* This can be done with a mov(1) instruction. */
6463 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6464 inst.instruction |= inst.reloc.exp.X_add_number;
6465 return 1;
6466 }
6467 }
6468 else
6469 {
6470 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6471 if (value != FAIL)
6472 {
6473 /* This can be done with a mov instruction. */
6474 inst.instruction &= LITERAL_MASK;
6475 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6476 inst.instruction |= value & 0xfff;
6477 return 1;
6478 }
09d92015 6479
c19d1205
ZW
6480 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6481 if (value != FAIL)
6482 {
6483 /* This can be done with a mvn instruction. */
6484 inst.instruction &= LITERAL_MASK;
6485 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6486 inst.instruction |= value & 0xfff;
6487 return 1;
6488 }
6489 }
09d92015
MM
6490 }
6491
c19d1205
ZW
6492 if (add_to_lit_pool () == FAIL)
6493 {
6494 inst.error = _("literal pool insertion failed");
6495 return 1;
6496 }
6497 inst.operands[1].reg = REG_PC;
6498 inst.operands[1].isreg = 1;
6499 inst.operands[1].preind = 1;
6500 inst.reloc.pc_rel = 1;
6501 inst.reloc.type = (thumb_p
6502 ? BFD_RELOC_ARM_THUMB_OFFSET
6503 : (mode_3
6504 ? BFD_RELOC_ARM_HWLITERAL
6505 : BFD_RELOC_ARM_LITERAL));
6506 return 0;
09d92015
MM
6507}
6508
c19d1205
ZW
6509/* Functions for instruction encoding, sorted by subarchitecture.
6510 First some generics; their names are taken from the conventional
6511 bit positions for register arguments in ARM format instructions. */
09d92015 6512
a737bd4d 6513static void
c19d1205 6514do_noargs (void)
09d92015 6515{
c19d1205 6516}
a737bd4d 6517
c19d1205
ZW
6518static void
6519do_rd (void)
6520{
6521 inst.instruction |= inst.operands[0].reg << 12;
6522}
a737bd4d 6523
c19d1205
ZW
6524static void
6525do_rd_rm (void)
6526{
6527 inst.instruction |= inst.operands[0].reg << 12;
6528 inst.instruction |= inst.operands[1].reg;
6529}
09d92015 6530
c19d1205
ZW
6531static void
6532do_rd_rn (void)
6533{
6534 inst.instruction |= inst.operands[0].reg << 12;
6535 inst.instruction |= inst.operands[1].reg << 16;
6536}
a737bd4d 6537
c19d1205
ZW
6538static void
6539do_rn_rd (void)
6540{
6541 inst.instruction |= inst.operands[0].reg << 16;
6542 inst.instruction |= inst.operands[1].reg << 12;
6543}
09d92015 6544
c19d1205
ZW
6545static void
6546do_rd_rm_rn (void)
6547{
9a64e435 6548 unsigned Rn = inst.operands[2].reg;
708587a4 6549 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6550 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6551 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6552 _("Rn must not overlap other operands"));
c19d1205
ZW
6553 inst.instruction |= inst.operands[0].reg << 12;
6554 inst.instruction |= inst.operands[1].reg;
9a64e435 6555 inst.instruction |= Rn << 16;
c19d1205 6556}
09d92015 6557
c19d1205
ZW
6558static void
6559do_rd_rn_rm (void)
6560{
6561 inst.instruction |= inst.operands[0].reg << 12;
6562 inst.instruction |= inst.operands[1].reg << 16;
6563 inst.instruction |= inst.operands[2].reg;
6564}
a737bd4d 6565
c19d1205
ZW
6566static void
6567do_rm_rd_rn (void)
6568{
6569 inst.instruction |= inst.operands[0].reg;
6570 inst.instruction |= inst.operands[1].reg << 12;
6571 inst.instruction |= inst.operands[2].reg << 16;
6572}
09d92015 6573
c19d1205
ZW
6574static void
6575do_imm0 (void)
6576{
6577 inst.instruction |= inst.operands[0].imm;
6578}
09d92015 6579
c19d1205
ZW
6580static void
6581do_rd_cpaddr (void)
6582{
6583 inst.instruction |= inst.operands[0].reg << 12;
6584 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6585}
a737bd4d 6586
c19d1205
ZW
6587/* ARM instructions, in alphabetical order by function name (except
6588 that wrapper functions appear immediately after the function they
6589 wrap). */
09d92015 6590
c19d1205
ZW
6591/* This is a pseudo-op of the form "adr rd, label" to be converted
6592 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6593
6594static void
c19d1205 6595do_adr (void)
09d92015 6596{
c19d1205 6597 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6598
c19d1205
ZW
6599 /* Frag hacking will turn this into a sub instruction if the offset turns
6600 out to be negative. */
6601 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6602 inst.reloc.pc_rel = 1;
2fc8bdac 6603 inst.reloc.exp.X_add_number -= 8;
c19d1205 6604}
b99bd4ef 6605
c19d1205
ZW
6606/* This is a pseudo-op of the form "adrl rd, label" to be converted
6607 into a relative address of the form:
6608 add rd, pc, #low(label-.-8)"
6609 add rd, rd, #high(label-.-8)" */
b99bd4ef 6610
c19d1205
ZW
6611static void
6612do_adrl (void)
6613{
6614 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6615
c19d1205
ZW
6616 /* Frag hacking will turn this into a sub instruction if the offset turns
6617 out to be negative. */
6618 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6619 inst.reloc.pc_rel = 1;
6620 inst.size = INSN_SIZE * 2;
2fc8bdac 6621 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6622}
6623
b99bd4ef 6624static void
c19d1205 6625do_arit (void)
b99bd4ef 6626{
c19d1205
ZW
6627 if (!inst.operands[1].present)
6628 inst.operands[1].reg = inst.operands[0].reg;
6629 inst.instruction |= inst.operands[0].reg << 12;
6630 inst.instruction |= inst.operands[1].reg << 16;
6631 encode_arm_shifter_operand (2);
6632}
b99bd4ef 6633
62b3e311
PB
6634static void
6635do_barrier (void)
6636{
6637 if (inst.operands[0].present)
6638 {
6639 constraint ((inst.instruction & 0xf0) != 0x40
6640 && inst.operands[0].imm != 0xf,
6641 "bad barrier type");
6642 inst.instruction |= inst.operands[0].imm;
6643 }
6644 else
6645 inst.instruction |= 0xf;
6646}
6647
c19d1205
ZW
6648static void
6649do_bfc (void)
6650{
6651 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6652 constraint (msb > 32, _("bit-field extends past end of register"));
6653 /* The instruction encoding stores the LSB and MSB,
6654 not the LSB and width. */
6655 inst.instruction |= inst.operands[0].reg << 12;
6656 inst.instruction |= inst.operands[1].imm << 7;
6657 inst.instruction |= (msb - 1) << 16;
6658}
b99bd4ef 6659
c19d1205
ZW
6660static void
6661do_bfi (void)
6662{
6663 unsigned int msb;
b99bd4ef 6664
c19d1205
ZW
6665 /* #0 in second position is alternative syntax for bfc, which is
6666 the same instruction but with REG_PC in the Rm field. */
6667 if (!inst.operands[1].isreg)
6668 inst.operands[1].reg = REG_PC;
b99bd4ef 6669
c19d1205
ZW
6670 msb = inst.operands[2].imm + inst.operands[3].imm;
6671 constraint (msb > 32, _("bit-field extends past end of register"));
6672 /* The instruction encoding stores the LSB and MSB,
6673 not the LSB and width. */
6674 inst.instruction |= inst.operands[0].reg << 12;
6675 inst.instruction |= inst.operands[1].reg;
6676 inst.instruction |= inst.operands[2].imm << 7;
6677 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6678}
6679
b99bd4ef 6680static void
c19d1205 6681do_bfx (void)
b99bd4ef 6682{
c19d1205
ZW
6683 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6684 _("bit-field extends past end of register"));
6685 inst.instruction |= inst.operands[0].reg << 12;
6686 inst.instruction |= inst.operands[1].reg;
6687 inst.instruction |= inst.operands[2].imm << 7;
6688 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6689}
09d92015 6690
c19d1205
ZW
6691/* ARM V5 breakpoint instruction (argument parse)
6692 BKPT <16 bit unsigned immediate>
6693 Instruction is not conditional.
6694 The bit pattern given in insns[] has the COND_ALWAYS condition,
6695 and it is an error if the caller tried to override that. */
b99bd4ef 6696
c19d1205
ZW
6697static void
6698do_bkpt (void)
6699{
6700 /* Top 12 of 16 bits to bits 19:8. */
6701 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6702
c19d1205
ZW
6703 /* Bottom 4 of 16 bits to bits 3:0. */
6704 inst.instruction |= inst.operands[0].imm & 0xf;
6705}
09d92015 6706
c19d1205
ZW
6707static void
6708encode_branch (int default_reloc)
6709{
6710 if (inst.operands[0].hasreloc)
6711 {
6712 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6713 _("the only suffix valid here is '(plt)'"));
6714 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6715 }
b99bd4ef 6716 else
c19d1205
ZW
6717 {
6718 inst.reloc.type = default_reloc;
c19d1205 6719 }
2fc8bdac 6720 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6721}
6722
b99bd4ef 6723static void
c19d1205 6724do_branch (void)
b99bd4ef 6725{
39b41c9c
PB
6726#ifdef OBJ_ELF
6727 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6728 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6729 else
6730#endif
6731 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6732}
6733
6734static void
6735do_bl (void)
6736{
6737#ifdef OBJ_ELF
6738 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6739 {
6740 if (inst.cond == COND_ALWAYS)
6741 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6742 else
6743 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6744 }
6745 else
6746#endif
6747 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6748}
b99bd4ef 6749
c19d1205
ZW
6750/* ARM V5 branch-link-exchange instruction (argument parse)
6751 BLX <target_addr> ie BLX(1)
6752 BLX{<condition>} <Rm> ie BLX(2)
6753 Unfortunately, there are two different opcodes for this mnemonic.
6754 So, the insns[].value is not used, and the code here zaps values
6755 into inst.instruction.
6756 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6757
c19d1205
ZW
6758static void
6759do_blx (void)
6760{
6761 if (inst.operands[0].isreg)
b99bd4ef 6762 {
c19d1205
ZW
6763 /* Arg is a register; the opcode provided by insns[] is correct.
6764 It is not illegal to do "blx pc", just useless. */
6765 if (inst.operands[0].reg == REG_PC)
6766 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6767
c19d1205
ZW
6768 inst.instruction |= inst.operands[0].reg;
6769 }
6770 else
b99bd4ef 6771 {
c19d1205
ZW
6772 /* Arg is an address; this instruction cannot be executed
6773 conditionally, and the opcode must be adjusted. */
6774 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6775 inst.instruction = 0xfa000000;
39b41c9c
PB
6776#ifdef OBJ_ELF
6777 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6778 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6779 else
6780#endif
6781 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6782 }
c19d1205
ZW
6783}
6784
6785static void
6786do_bx (void)
6787{
6788 if (inst.operands[0].reg == REG_PC)
6789 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6790
c19d1205 6791 inst.instruction |= inst.operands[0].reg;
09d92015
MM
6792}
6793
c19d1205
ZW
6794
6795/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6796
6797static void
c19d1205 6798do_bxj (void)
a737bd4d 6799{
c19d1205
ZW
6800 if (inst.operands[0].reg == REG_PC)
6801 as_tsktsk (_("use of r15 in bxj is not really useful"));
6802
6803 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6804}
6805
c19d1205
ZW
6806/* Co-processor data operation:
6807 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6808 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6809static void
6810do_cdp (void)
6811{
6812 inst.instruction |= inst.operands[0].reg << 8;
6813 inst.instruction |= inst.operands[1].imm << 20;
6814 inst.instruction |= inst.operands[2].reg << 12;
6815 inst.instruction |= inst.operands[3].reg << 16;
6816 inst.instruction |= inst.operands[4].reg;
6817 inst.instruction |= inst.operands[5].imm << 5;
6818}
a737bd4d
NC
6819
6820static void
c19d1205 6821do_cmp (void)
a737bd4d 6822{
c19d1205
ZW
6823 inst.instruction |= inst.operands[0].reg << 16;
6824 encode_arm_shifter_operand (1);
a737bd4d
NC
6825}
6826
c19d1205
ZW
6827/* Transfer between coprocessor and ARM registers.
6828 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6829 MRC2
6830 MCR{cond}
6831 MCR2
6832
6833 No special properties. */
09d92015
MM
6834
6835static void
c19d1205 6836do_co_reg (void)
09d92015 6837{
c19d1205
ZW
6838 inst.instruction |= inst.operands[0].reg << 8;
6839 inst.instruction |= inst.operands[1].imm << 21;
6840 inst.instruction |= inst.operands[2].reg << 12;
6841 inst.instruction |= inst.operands[3].reg << 16;
6842 inst.instruction |= inst.operands[4].reg;
6843 inst.instruction |= inst.operands[5].imm << 5;
6844}
09d92015 6845
c19d1205
ZW
6846/* Transfer between coprocessor register and pair of ARM registers.
6847 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6848 MCRR2
6849 MRRC{cond}
6850 MRRC2
b99bd4ef 6851
c19d1205 6852 Two XScale instructions are special cases of these:
09d92015 6853
c19d1205
ZW
6854 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6855 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6856
c19d1205 6857 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 6858
c19d1205
ZW
6859static void
6860do_co_reg2c (void)
6861{
6862 inst.instruction |= inst.operands[0].reg << 8;
6863 inst.instruction |= inst.operands[1].imm << 4;
6864 inst.instruction |= inst.operands[2].reg << 12;
6865 inst.instruction |= inst.operands[3].reg << 16;
6866 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6867}
6868
c19d1205
ZW
6869static void
6870do_cpsi (void)
6871{
6872 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6873 if (inst.operands[1].present)
6874 {
6875 inst.instruction |= CPSI_MMOD;
6876 inst.instruction |= inst.operands[1].imm;
6877 }
c19d1205 6878}
b99bd4ef 6879
62b3e311
PB
6880static void
6881do_dbg (void)
6882{
6883 inst.instruction |= inst.operands[0].imm;
6884}
6885
b99bd4ef 6886static void
c19d1205 6887do_it (void)
b99bd4ef 6888{
c19d1205
ZW
6889 /* There is no IT instruction in ARM mode. We
6890 process it but do not generate code for it. */
6891 inst.size = 0;
09d92015 6892}
b99bd4ef 6893
09d92015 6894static void
c19d1205 6895do_ldmstm (void)
ea6ef066 6896{
c19d1205
ZW
6897 int base_reg = inst.operands[0].reg;
6898 int range = inst.operands[1].imm;
ea6ef066 6899
c19d1205
ZW
6900 inst.instruction |= base_reg << 16;
6901 inst.instruction |= range;
ea6ef066 6902
c19d1205
ZW
6903 if (inst.operands[1].writeback)
6904 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6905
c19d1205 6906 if (inst.operands[0].writeback)
ea6ef066 6907 {
c19d1205
ZW
6908 inst.instruction |= WRITE_BACK;
6909 /* Check for unpredictable uses of writeback. */
6910 if (inst.instruction & LOAD_BIT)
09d92015 6911 {
c19d1205
ZW
6912 /* Not allowed in LDM type 2. */
6913 if ((inst.instruction & LDM_TYPE_2_OR_3)
6914 && ((range & (1 << REG_PC)) == 0))
6915 as_warn (_("writeback of base register is UNPREDICTABLE"));
6916 /* Only allowed if base reg not in list for other types. */
6917 else if (range & (1 << base_reg))
6918 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6919 }
6920 else /* STM. */
6921 {
6922 /* Not allowed for type 2. */
6923 if (inst.instruction & LDM_TYPE_2_OR_3)
6924 as_warn (_("writeback of base register is UNPREDICTABLE"));
6925 /* Only allowed if base reg not in list, or first in list. */
6926 else if ((range & (1 << base_reg))
6927 && (range & ((1 << base_reg) - 1)))
6928 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6929 }
ea6ef066 6930 }
a737bd4d
NC
6931}
6932
c19d1205
ZW
6933/* ARMv5TE load-consecutive (argument parse)
6934 Mode is like LDRH.
6935
6936 LDRccD R, mode
6937 STRccD R, mode. */
6938
a737bd4d 6939static void
c19d1205 6940do_ldrd (void)
a737bd4d 6941{
c19d1205
ZW
6942 constraint (inst.operands[0].reg % 2 != 0,
6943 _("first destination register must be even"));
6944 constraint (inst.operands[1].present
6945 && inst.operands[1].reg != inst.operands[0].reg + 1,
6946 _("can only load two consecutive registers"));
6947 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6948 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6949
c19d1205
ZW
6950 if (!inst.operands[1].present)
6951 inst.operands[1].reg = inst.operands[0].reg + 1;
6952
6953 if (inst.instruction & LOAD_BIT)
a737bd4d 6954 {
c19d1205
ZW
6955 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6956 register and the first register written; we have to diagnose
6957 overlap between the base and the second register written here. */
ea6ef066 6958
c19d1205
ZW
6959 if (inst.operands[2].reg == inst.operands[1].reg
6960 && (inst.operands[2].writeback || inst.operands[2].postind))
6961 as_warn (_("base register written back, and overlaps "
6962 "second destination register"));
b05fe5cf 6963
c19d1205
ZW
6964 /* For an index-register load, the index register must not overlap the
6965 destination (even if not write-back). */
6966 else if (inst.operands[2].immisreg
ca3f61f7
NC
6967 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6968 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6969 as_warn (_("index register overlaps destination register"));
b05fe5cf 6970 }
c19d1205
ZW
6971
6972 inst.instruction |= inst.operands[0].reg << 12;
6973 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6974}
6975
6976static void
c19d1205 6977do_ldrex (void)
b05fe5cf 6978{
c19d1205
ZW
6979 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6980 || inst.operands[1].postind || inst.operands[1].writeback
6981 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6982 || inst.operands[1].negative
6983 /* This can arise if the programmer has written
6984 strex rN, rM, foo
6985 or if they have mistakenly used a register name as the last
6986 operand, eg:
6987 strex rN, rM, rX
6988 It is very difficult to distinguish between these two cases
6989 because "rX" might actually be a label. ie the register
6990 name has been occluded by a symbol of the same name. So we
6991 just generate a general 'bad addressing mode' type error
6992 message and leave it up to the programmer to discover the
6993 true cause and fix their mistake. */
6994 || (inst.operands[1].reg == REG_PC),
6995 BAD_ADDR_MODE);
b05fe5cf 6996
c19d1205
ZW
6997 constraint (inst.reloc.exp.X_op != O_constant
6998 || inst.reloc.exp.X_add_number != 0,
6999 _("offset must be zero in ARM encoding"));
b05fe5cf 7000
c19d1205
ZW
7001 inst.instruction |= inst.operands[0].reg << 12;
7002 inst.instruction |= inst.operands[1].reg << 16;
7003 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7004}
7005
7006static void
c19d1205 7007do_ldrexd (void)
b05fe5cf 7008{
c19d1205
ZW
7009 constraint (inst.operands[0].reg % 2 != 0,
7010 _("even register required"));
7011 constraint (inst.operands[1].present
7012 && inst.operands[1].reg != inst.operands[0].reg + 1,
7013 _("can only load two consecutive registers"));
7014 /* If op 1 were present and equal to PC, this function wouldn't
7015 have been called in the first place. */
7016 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7017
c19d1205
ZW
7018 inst.instruction |= inst.operands[0].reg << 12;
7019 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7020}
7021
7022static void
c19d1205 7023do_ldst (void)
b05fe5cf 7024{
c19d1205
ZW
7025 inst.instruction |= inst.operands[0].reg << 12;
7026 if (!inst.operands[1].isreg)
7027 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7028 return;
c19d1205 7029 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7030}
7031
7032static void
c19d1205 7033do_ldstt (void)
b05fe5cf 7034{
c19d1205
ZW
7035 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7036 reject [Rn,...]. */
7037 if (inst.operands[1].preind)
b05fe5cf 7038 {
c19d1205
ZW
7039 constraint (inst.reloc.exp.X_op != O_constant ||
7040 inst.reloc.exp.X_add_number != 0,
7041 _("this instruction requires a post-indexed address"));
b05fe5cf 7042
c19d1205
ZW
7043 inst.operands[1].preind = 0;
7044 inst.operands[1].postind = 1;
7045 inst.operands[1].writeback = 1;
b05fe5cf 7046 }
c19d1205
ZW
7047 inst.instruction |= inst.operands[0].reg << 12;
7048 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7049}
b05fe5cf 7050
c19d1205 7051/* Halfword and signed-byte load/store operations. */
b05fe5cf 7052
c19d1205
ZW
7053static void
7054do_ldstv4 (void)
7055{
7056 inst.instruction |= inst.operands[0].reg << 12;
7057 if (!inst.operands[1].isreg)
7058 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7059 return;
c19d1205 7060 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7061}
7062
7063static void
c19d1205 7064do_ldsttv4 (void)
b05fe5cf 7065{
c19d1205
ZW
7066 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7067 reject [Rn,...]. */
7068 if (inst.operands[1].preind)
b05fe5cf 7069 {
c19d1205
ZW
7070 constraint (inst.reloc.exp.X_op != O_constant ||
7071 inst.reloc.exp.X_add_number != 0,
7072 _("this instruction requires a post-indexed address"));
b05fe5cf 7073
c19d1205
ZW
7074 inst.operands[1].preind = 0;
7075 inst.operands[1].postind = 1;
7076 inst.operands[1].writeback = 1;
b05fe5cf 7077 }
c19d1205
ZW
7078 inst.instruction |= inst.operands[0].reg << 12;
7079 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7080}
b05fe5cf 7081
c19d1205
ZW
7082/* Co-processor register load/store.
7083 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7084static void
7085do_lstc (void)
7086{
7087 inst.instruction |= inst.operands[0].reg << 8;
7088 inst.instruction |= inst.operands[1].reg << 12;
7089 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7090}
7091
b05fe5cf 7092static void
c19d1205 7093do_mlas (void)
b05fe5cf 7094{
8fb9d7b9 7095 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7096 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7097 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7098 && !(inst.instruction & 0x00400000))
8fb9d7b9 7099 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7100
c19d1205
ZW
7101 inst.instruction |= inst.operands[0].reg << 16;
7102 inst.instruction |= inst.operands[1].reg;
7103 inst.instruction |= inst.operands[2].reg << 8;
7104 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7105}
b05fe5cf 7106
c19d1205
ZW
7107static void
7108do_mov (void)
7109{
7110 inst.instruction |= inst.operands[0].reg << 12;
7111 encode_arm_shifter_operand (1);
7112}
b05fe5cf 7113
c19d1205
ZW
7114/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7115static void
7116do_mov16 (void)
7117{
b6895b4f
PB
7118 bfd_vma imm;
7119 bfd_boolean top;
7120
7121 top = (inst.instruction & 0x00400000) != 0;
7122 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7123 _(":lower16: not allowed this instruction"));
7124 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7125 _(":upper16: not allowed instruction"));
c19d1205 7126 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7127 if (inst.reloc.type == BFD_RELOC_UNUSED)
7128 {
7129 imm = inst.reloc.exp.X_add_number;
7130 /* The value is in two pieces: 0:11, 16:19. */
7131 inst.instruction |= (imm & 0x00000fff);
7132 inst.instruction |= (imm & 0x0000f000) << 4;
7133 }
b05fe5cf 7134}
b99bd4ef 7135
037e8744
JB
7136static void do_vfp_nsyn_opcode (const char *);
7137
7138static int
7139do_vfp_nsyn_mrs (void)
7140{
7141 if (inst.operands[0].isvec)
7142 {
7143 if (inst.operands[1].reg != 1)
7144 first_error (_("operand 1 must be FPSCR"));
7145 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7146 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7147 do_vfp_nsyn_opcode ("fmstat");
7148 }
7149 else if (inst.operands[1].isvec)
7150 do_vfp_nsyn_opcode ("fmrx");
7151 else
7152 return FAIL;
7153
7154 return SUCCESS;
7155}
7156
7157static int
7158do_vfp_nsyn_msr (void)
7159{
7160 if (inst.operands[0].isvec)
7161 do_vfp_nsyn_opcode ("fmxr");
7162 else
7163 return FAIL;
7164
7165 return SUCCESS;
7166}
7167
b99bd4ef 7168static void
c19d1205 7169do_mrs (void)
b99bd4ef 7170{
037e8744
JB
7171 if (do_vfp_nsyn_mrs () == SUCCESS)
7172 return;
7173
c19d1205
ZW
7174 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7175 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7176 != (PSR_c|PSR_f),
7177 _("'CPSR' or 'SPSR' expected"));
7178 inst.instruction |= inst.operands[0].reg << 12;
7179 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7180}
b99bd4ef 7181
c19d1205
ZW
7182/* Two possible forms:
7183 "{C|S}PSR_<field>, Rm",
7184 "{C|S}PSR_f, #expression". */
b99bd4ef 7185
c19d1205
ZW
7186static void
7187do_msr (void)
7188{
037e8744
JB
7189 if (do_vfp_nsyn_msr () == SUCCESS)
7190 return;
7191
c19d1205
ZW
7192 inst.instruction |= inst.operands[0].imm;
7193 if (inst.operands[1].isreg)
7194 inst.instruction |= inst.operands[1].reg;
7195 else
b99bd4ef 7196 {
c19d1205
ZW
7197 inst.instruction |= INST_IMMEDIATE;
7198 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7199 inst.reloc.pc_rel = 0;
b99bd4ef 7200 }
b99bd4ef
NC
7201}
7202
c19d1205
ZW
7203static void
7204do_mul (void)
a737bd4d 7205{
c19d1205
ZW
7206 if (!inst.operands[2].present)
7207 inst.operands[2].reg = inst.operands[0].reg;
7208 inst.instruction |= inst.operands[0].reg << 16;
7209 inst.instruction |= inst.operands[1].reg;
7210 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7211
8fb9d7b9
MS
7212 if (inst.operands[0].reg == inst.operands[1].reg
7213 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7214 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7215}
7216
c19d1205
ZW
7217/* Long Multiply Parser
7218 UMULL RdLo, RdHi, Rm, Rs
7219 SMULL RdLo, RdHi, Rm, Rs
7220 UMLAL RdLo, RdHi, Rm, Rs
7221 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7222
7223static void
c19d1205 7224do_mull (void)
b99bd4ef 7225{
c19d1205
ZW
7226 inst.instruction |= inst.operands[0].reg << 12;
7227 inst.instruction |= inst.operands[1].reg << 16;
7228 inst.instruction |= inst.operands[2].reg;
7229 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7230
c19d1205
ZW
7231 /* rdhi, rdlo and rm must all be different. */
7232 if (inst.operands[0].reg == inst.operands[1].reg
7233 || inst.operands[0].reg == inst.operands[2].reg
7234 || inst.operands[1].reg == inst.operands[2].reg)
7235 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7236}
b99bd4ef 7237
c19d1205
ZW
7238static void
7239do_nop (void)
7240{
7241 if (inst.operands[0].present)
7242 {
7243 /* Architectural NOP hints are CPSR sets with no bits selected. */
7244 inst.instruction &= 0xf0000000;
7245 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7246 }
b99bd4ef
NC
7247}
7248
c19d1205
ZW
7249/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7250 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7251 Condition defaults to COND_ALWAYS.
7252 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7253
7254static void
c19d1205 7255do_pkhbt (void)
b99bd4ef 7256{
c19d1205
ZW
7257 inst.instruction |= inst.operands[0].reg << 12;
7258 inst.instruction |= inst.operands[1].reg << 16;
7259 inst.instruction |= inst.operands[2].reg;
7260 if (inst.operands[3].present)
7261 encode_arm_shift (3);
7262}
b99bd4ef 7263
c19d1205 7264/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7265
c19d1205
ZW
7266static void
7267do_pkhtb (void)
7268{
7269 if (!inst.operands[3].present)
b99bd4ef 7270 {
c19d1205
ZW
7271 /* If the shift specifier is omitted, turn the instruction
7272 into pkhbt rd, rm, rn. */
7273 inst.instruction &= 0xfff00010;
7274 inst.instruction |= inst.operands[0].reg << 12;
7275 inst.instruction |= inst.operands[1].reg;
7276 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7277 }
7278 else
7279 {
c19d1205
ZW
7280 inst.instruction |= inst.operands[0].reg << 12;
7281 inst.instruction |= inst.operands[1].reg << 16;
7282 inst.instruction |= inst.operands[2].reg;
7283 encode_arm_shift (3);
b99bd4ef
NC
7284 }
7285}
7286
c19d1205
ZW
7287/* ARMv5TE: Preload-Cache
7288
7289 PLD <addr_mode>
7290
7291 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7292
7293static void
c19d1205 7294do_pld (void)
b99bd4ef 7295{
c19d1205
ZW
7296 constraint (!inst.operands[0].isreg,
7297 _("'[' expected after PLD mnemonic"));
7298 constraint (inst.operands[0].postind,
7299 _("post-indexed expression used in preload instruction"));
7300 constraint (inst.operands[0].writeback,
7301 _("writeback used in preload instruction"));
7302 constraint (!inst.operands[0].preind,
7303 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7304 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7305}
b99bd4ef 7306
62b3e311
PB
7307/* ARMv7: PLI <addr_mode> */
7308static void
7309do_pli (void)
7310{
7311 constraint (!inst.operands[0].isreg,
7312 _("'[' expected after PLI mnemonic"));
7313 constraint (inst.operands[0].postind,
7314 _("post-indexed expression used in preload instruction"));
7315 constraint (inst.operands[0].writeback,
7316 _("writeback used in preload instruction"));
7317 constraint (!inst.operands[0].preind,
7318 _("unindexed addressing used in preload instruction"));
7319 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7320 inst.instruction &= ~PRE_INDEX;
7321}
7322
c19d1205
ZW
7323static void
7324do_push_pop (void)
7325{
7326 inst.operands[1] = inst.operands[0];
7327 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7328 inst.operands[0].isreg = 1;
7329 inst.operands[0].writeback = 1;
7330 inst.operands[0].reg = REG_SP;
7331 do_ldmstm ();
7332}
b99bd4ef 7333
c19d1205
ZW
7334/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7335 word at the specified address and the following word
7336 respectively.
7337 Unconditionally executed.
7338 Error if Rn is R15. */
b99bd4ef 7339
c19d1205
ZW
7340static void
7341do_rfe (void)
7342{
7343 inst.instruction |= inst.operands[0].reg << 16;
7344 if (inst.operands[0].writeback)
7345 inst.instruction |= WRITE_BACK;
7346}
b99bd4ef 7347
c19d1205 7348/* ARM V6 ssat (argument parse). */
b99bd4ef 7349
c19d1205
ZW
7350static void
7351do_ssat (void)
7352{
7353 inst.instruction |= inst.operands[0].reg << 12;
7354 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7355 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7356
c19d1205
ZW
7357 if (inst.operands[3].present)
7358 encode_arm_shift (3);
b99bd4ef
NC
7359}
7360
c19d1205 7361/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7362
7363static void
c19d1205 7364do_usat (void)
b99bd4ef 7365{
c19d1205
ZW
7366 inst.instruction |= inst.operands[0].reg << 12;
7367 inst.instruction |= inst.operands[1].imm << 16;
7368 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7369
c19d1205
ZW
7370 if (inst.operands[3].present)
7371 encode_arm_shift (3);
b99bd4ef
NC
7372}
7373
c19d1205 7374/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7375
7376static void
c19d1205 7377do_ssat16 (void)
09d92015 7378{
c19d1205
ZW
7379 inst.instruction |= inst.operands[0].reg << 12;
7380 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7381 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7382}
7383
c19d1205
ZW
7384static void
7385do_usat16 (void)
a737bd4d 7386{
c19d1205
ZW
7387 inst.instruction |= inst.operands[0].reg << 12;
7388 inst.instruction |= inst.operands[1].imm << 16;
7389 inst.instruction |= inst.operands[2].reg;
7390}
a737bd4d 7391
c19d1205
ZW
7392/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7393 preserving the other bits.
a737bd4d 7394
c19d1205
ZW
7395 setend <endian_specifier>, where <endian_specifier> is either
7396 BE or LE. */
a737bd4d 7397
c19d1205
ZW
7398static void
7399do_setend (void)
7400{
7401 if (inst.operands[0].imm)
7402 inst.instruction |= 0x200;
a737bd4d
NC
7403}
7404
7405static void
c19d1205 7406do_shift (void)
a737bd4d 7407{
c19d1205
ZW
7408 unsigned int Rm = (inst.operands[1].present
7409 ? inst.operands[1].reg
7410 : inst.operands[0].reg);
a737bd4d 7411
c19d1205
ZW
7412 inst.instruction |= inst.operands[0].reg << 12;
7413 inst.instruction |= Rm;
7414 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7415 {
c19d1205
ZW
7416 inst.instruction |= inst.operands[2].reg << 8;
7417 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7418 }
7419 else
c19d1205 7420 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7421}
7422
09d92015 7423static void
3eb17e6b 7424do_smc (void)
09d92015 7425{
3eb17e6b 7426 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7427 inst.reloc.pc_rel = 0;
09d92015
MM
7428}
7429
09d92015 7430static void
c19d1205 7431do_swi (void)
09d92015 7432{
c19d1205
ZW
7433 inst.reloc.type = BFD_RELOC_ARM_SWI;
7434 inst.reloc.pc_rel = 0;
09d92015
MM
7435}
7436
c19d1205
ZW
7437/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7438 SMLAxy{cond} Rd,Rm,Rs,Rn
7439 SMLAWy{cond} Rd,Rm,Rs,Rn
7440 Error if any register is R15. */
e16bb312 7441
c19d1205
ZW
7442static void
7443do_smla (void)
e16bb312 7444{
c19d1205
ZW
7445 inst.instruction |= inst.operands[0].reg << 16;
7446 inst.instruction |= inst.operands[1].reg;
7447 inst.instruction |= inst.operands[2].reg << 8;
7448 inst.instruction |= inst.operands[3].reg << 12;
7449}
a737bd4d 7450
c19d1205
ZW
7451/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7452 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7453 Error if any register is R15.
7454 Warning if Rdlo == Rdhi. */
a737bd4d 7455
c19d1205
ZW
7456static void
7457do_smlal (void)
7458{
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= inst.operands[1].reg << 16;
7461 inst.instruction |= inst.operands[2].reg;
7462 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7463
c19d1205
ZW
7464 if (inst.operands[0].reg == inst.operands[1].reg)
7465 as_tsktsk (_("rdhi and rdlo must be different"));
7466}
a737bd4d 7467
c19d1205
ZW
7468/* ARM V5E (El Segundo) signed-multiply (argument parse)
7469 SMULxy{cond} Rd,Rm,Rs
7470 Error if any register is R15. */
a737bd4d 7471
c19d1205
ZW
7472static void
7473do_smul (void)
7474{
7475 inst.instruction |= inst.operands[0].reg << 16;
7476 inst.instruction |= inst.operands[1].reg;
7477 inst.instruction |= inst.operands[2].reg << 8;
7478}
a737bd4d 7479
b6702015
PB
7480/* ARM V6 srs (argument parse). The variable fields in the encoding are
7481 the same for both ARM and Thumb-2. */
a737bd4d 7482
c19d1205
ZW
7483static void
7484do_srs (void)
7485{
b6702015
PB
7486 int reg;
7487
7488 if (inst.operands[0].present)
7489 {
7490 reg = inst.operands[0].reg;
7491 constraint (reg != 13, _("SRS base register must be r13"));
7492 }
7493 else
7494 reg = 13;
7495
7496 inst.instruction |= reg << 16;
7497 inst.instruction |= inst.operands[1].imm;
7498 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7499 inst.instruction |= WRITE_BACK;
7500}
a737bd4d 7501
c19d1205 7502/* ARM V6 strex (argument parse). */
a737bd4d 7503
c19d1205
ZW
7504static void
7505do_strex (void)
7506{
7507 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7508 || inst.operands[2].postind || inst.operands[2].writeback
7509 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7510 || inst.operands[2].negative
7511 /* See comment in do_ldrex(). */
7512 || (inst.operands[2].reg == REG_PC),
7513 BAD_ADDR_MODE);
a737bd4d 7514
c19d1205
ZW
7515 constraint (inst.operands[0].reg == inst.operands[1].reg
7516 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7517
c19d1205
ZW
7518 constraint (inst.reloc.exp.X_op != O_constant
7519 || inst.reloc.exp.X_add_number != 0,
7520 _("offset must be zero in ARM encoding"));
a737bd4d 7521
c19d1205
ZW
7522 inst.instruction |= inst.operands[0].reg << 12;
7523 inst.instruction |= inst.operands[1].reg;
7524 inst.instruction |= inst.operands[2].reg << 16;
7525 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7526}
7527
7528static void
c19d1205 7529do_strexd (void)
e16bb312 7530{
c19d1205
ZW
7531 constraint (inst.operands[1].reg % 2 != 0,
7532 _("even register required"));
7533 constraint (inst.operands[2].present
7534 && inst.operands[2].reg != inst.operands[1].reg + 1,
7535 _("can only store two consecutive registers"));
7536 /* If op 2 were present and equal to PC, this function wouldn't
7537 have been called in the first place. */
7538 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7539
c19d1205
ZW
7540 constraint (inst.operands[0].reg == inst.operands[1].reg
7541 || inst.operands[0].reg == inst.operands[1].reg + 1
7542 || inst.operands[0].reg == inst.operands[3].reg,
7543 BAD_OVERLAP);
e16bb312 7544
c19d1205
ZW
7545 inst.instruction |= inst.operands[0].reg << 12;
7546 inst.instruction |= inst.operands[1].reg;
7547 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7548}
7549
c19d1205
ZW
7550/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7551 extends it to 32-bits, and adds the result to a value in another
7552 register. You can specify a rotation by 0, 8, 16, or 24 bits
7553 before extracting the 16-bit value.
7554 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7555 Condition defaults to COND_ALWAYS.
7556 Error if any register uses R15. */
7557
e16bb312 7558static void
c19d1205 7559do_sxtah (void)
e16bb312 7560{
c19d1205
ZW
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].reg << 16;
7563 inst.instruction |= inst.operands[2].reg;
7564 inst.instruction |= inst.operands[3].imm << 10;
7565}
e16bb312 7566
c19d1205 7567/* ARM V6 SXTH.
e16bb312 7568
c19d1205
ZW
7569 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7570 Condition defaults to COND_ALWAYS.
7571 Error if any register uses R15. */
e16bb312
NC
7572
7573static void
c19d1205 7574do_sxth (void)
e16bb312 7575{
c19d1205
ZW
7576 inst.instruction |= inst.operands[0].reg << 12;
7577 inst.instruction |= inst.operands[1].reg;
7578 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7579}
c19d1205
ZW
7580\f
7581/* VFP instructions. In a logical order: SP variant first, monad
7582 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7583
7584static void
c19d1205 7585do_vfp_sp_monadic (void)
e16bb312 7586{
5287ad62
JB
7587 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7588 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7589}
7590
7591static void
c19d1205 7592do_vfp_sp_dyadic (void)
e16bb312 7593{
5287ad62
JB
7594 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7595 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7596 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7597}
7598
7599static void
c19d1205 7600do_vfp_sp_compare_z (void)
e16bb312 7601{
5287ad62 7602 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7603}
7604
7605static void
c19d1205 7606do_vfp_dp_sp_cvt (void)
e16bb312 7607{
5287ad62
JB
7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7609 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7610}
7611
7612static void
c19d1205 7613do_vfp_sp_dp_cvt (void)
e16bb312 7614{
5287ad62
JB
7615 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7616 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7617}
7618
7619static void
c19d1205 7620do_vfp_reg_from_sp (void)
e16bb312 7621{
c19d1205 7622 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7623 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7624}
7625
7626static void
c19d1205 7627do_vfp_reg2_from_sp2 (void)
e16bb312 7628{
c19d1205
ZW
7629 constraint (inst.operands[2].imm != 2,
7630 _("only two consecutive VFP SP registers allowed here"));
7631 inst.instruction |= inst.operands[0].reg << 12;
7632 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7633 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7634}
7635
7636static void
c19d1205 7637do_vfp_sp_from_reg (void)
e16bb312 7638{
5287ad62 7639 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7640 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7641}
7642
7643static void
c19d1205 7644do_vfp_sp2_from_reg2 (void)
e16bb312 7645{
c19d1205
ZW
7646 constraint (inst.operands[0].imm != 2,
7647 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7648 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7649 inst.instruction |= inst.operands[1].reg << 12;
7650 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7651}
7652
7653static void
c19d1205 7654do_vfp_sp_ldst (void)
e16bb312 7655{
5287ad62 7656 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7657 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7658}
7659
7660static void
c19d1205 7661do_vfp_dp_ldst (void)
e16bb312 7662{
5287ad62 7663 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7664 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7665}
7666
c19d1205 7667
e16bb312 7668static void
c19d1205 7669vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7670{
c19d1205
ZW
7671 if (inst.operands[0].writeback)
7672 inst.instruction |= WRITE_BACK;
7673 else
7674 constraint (ldstm_type != VFP_LDSTMIA,
7675 _("this addressing mode requires base-register writeback"));
7676 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7677 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7678 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7679}
7680
7681static void
c19d1205 7682vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7683{
c19d1205 7684 int count;
e16bb312 7685
c19d1205
ZW
7686 if (inst.operands[0].writeback)
7687 inst.instruction |= WRITE_BACK;
7688 else
7689 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7690 _("this addressing mode requires base-register writeback"));
e16bb312 7691
c19d1205 7692 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7694
c19d1205
ZW
7695 count = inst.operands[1].imm << 1;
7696 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7697 count += 1;
e16bb312 7698
c19d1205 7699 inst.instruction |= count;
e16bb312
NC
7700}
7701
7702static void
c19d1205 7703do_vfp_sp_ldstmia (void)
e16bb312 7704{
c19d1205 7705 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7706}
7707
7708static void
c19d1205 7709do_vfp_sp_ldstmdb (void)
e16bb312 7710{
c19d1205 7711 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7712}
7713
7714static void
c19d1205 7715do_vfp_dp_ldstmia (void)
e16bb312 7716{
c19d1205 7717 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7718}
7719
7720static void
c19d1205 7721do_vfp_dp_ldstmdb (void)
e16bb312 7722{
c19d1205 7723 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7724}
7725
7726static void
c19d1205 7727do_vfp_xp_ldstmia (void)
e16bb312 7728{
c19d1205
ZW
7729 vfp_dp_ldstm (VFP_LDSTMIAX);
7730}
e16bb312 7731
c19d1205
ZW
7732static void
7733do_vfp_xp_ldstmdb (void)
7734{
7735 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7736}
5287ad62
JB
7737
7738static void
7739do_vfp_dp_rd_rm (void)
7740{
7741 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7742 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7743}
7744
7745static void
7746do_vfp_dp_rn_rd (void)
7747{
7748 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7749 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7750}
7751
7752static void
7753do_vfp_dp_rd_rn (void)
7754{
7755 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7756 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7757}
7758
7759static void
7760do_vfp_dp_rd_rn_rm (void)
7761{
7762 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7763 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7764 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7765}
7766
7767static void
7768do_vfp_dp_rd (void)
7769{
7770 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7771}
7772
7773static void
7774do_vfp_dp_rm_rd_rn (void)
7775{
7776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7777 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7778 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7779}
7780
7781/* VFPv3 instructions. */
7782static void
7783do_vfp_sp_const (void)
7784{
7785 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7786 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7787 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7788}
7789
7790static void
7791do_vfp_dp_const (void)
7792{
7793 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7794 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7795 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7796}
7797
7798static void
7799vfp_conv (int srcsize)
7800{
7801 unsigned immbits = srcsize - inst.operands[1].imm;
7802 inst.instruction |= (immbits & 1) << 5;
7803 inst.instruction |= (immbits >> 1);
7804}
7805
7806static void
7807do_vfp_sp_conv_16 (void)
7808{
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 vfp_conv (16);
7811}
7812
7813static void
7814do_vfp_dp_conv_16 (void)
7815{
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7817 vfp_conv (16);
7818}
7819
7820static void
7821do_vfp_sp_conv_32 (void)
7822{
7823 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7824 vfp_conv (32);
7825}
7826
7827static void
7828do_vfp_dp_conv_32 (void)
7829{
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 vfp_conv (32);
7832}
7833
c19d1205
ZW
7834\f
7835/* FPA instructions. Also in a logical order. */
e16bb312 7836
c19d1205
ZW
7837static void
7838do_fpa_cmp (void)
7839{
7840 inst.instruction |= inst.operands[0].reg << 16;
7841 inst.instruction |= inst.operands[1].reg;
7842}
b99bd4ef
NC
7843
7844static void
c19d1205 7845do_fpa_ldmstm (void)
b99bd4ef 7846{
c19d1205
ZW
7847 inst.instruction |= inst.operands[0].reg << 12;
7848 switch (inst.operands[1].imm)
7849 {
7850 case 1: inst.instruction |= CP_T_X; break;
7851 case 2: inst.instruction |= CP_T_Y; break;
7852 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7853 case 4: break;
7854 default: abort ();
7855 }
b99bd4ef 7856
c19d1205
ZW
7857 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7858 {
7859 /* The instruction specified "ea" or "fd", so we can only accept
7860 [Rn]{!}. The instruction does not really support stacking or
7861 unstacking, so we have to emulate these by setting appropriate
7862 bits and offsets. */
7863 constraint (inst.reloc.exp.X_op != O_constant
7864 || inst.reloc.exp.X_add_number != 0,
7865 _("this instruction does not support indexing"));
b99bd4ef 7866
c19d1205
ZW
7867 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7868 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7869
c19d1205
ZW
7870 if (!(inst.instruction & INDEX_UP))
7871 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7872
c19d1205
ZW
7873 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7874 {
7875 inst.operands[2].preind = 0;
7876 inst.operands[2].postind = 1;
7877 }
7878 }
b99bd4ef 7879
c19d1205 7880 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7881}
037e8744 7882
c19d1205
ZW
7883\f
7884/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7885
c19d1205
ZW
7886static void
7887do_iwmmxt_tandorc (void)
7888{
7889 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7890}
b99bd4ef 7891
c19d1205
ZW
7892static void
7893do_iwmmxt_textrc (void)
7894{
7895 inst.instruction |= inst.operands[0].reg << 12;
7896 inst.instruction |= inst.operands[1].imm;
7897}
b99bd4ef
NC
7898
7899static void
c19d1205 7900do_iwmmxt_textrm (void)
b99bd4ef 7901{
c19d1205
ZW
7902 inst.instruction |= inst.operands[0].reg << 12;
7903 inst.instruction |= inst.operands[1].reg << 16;
7904 inst.instruction |= inst.operands[2].imm;
7905}
b99bd4ef 7906
c19d1205
ZW
7907static void
7908do_iwmmxt_tinsr (void)
7909{
7910 inst.instruction |= inst.operands[0].reg << 16;
7911 inst.instruction |= inst.operands[1].reg << 12;
7912 inst.instruction |= inst.operands[2].imm;
7913}
b99bd4ef 7914
c19d1205
ZW
7915static void
7916do_iwmmxt_tmia (void)
7917{
7918 inst.instruction |= inst.operands[0].reg << 5;
7919 inst.instruction |= inst.operands[1].reg;
7920 inst.instruction |= inst.operands[2].reg << 12;
7921}
b99bd4ef 7922
c19d1205
ZW
7923static void
7924do_iwmmxt_waligni (void)
7925{
7926 inst.instruction |= inst.operands[0].reg << 12;
7927 inst.instruction |= inst.operands[1].reg << 16;
7928 inst.instruction |= inst.operands[2].reg;
7929 inst.instruction |= inst.operands[3].imm << 20;
7930}
b99bd4ef 7931
2d447fca
JM
7932static void
7933do_iwmmxt_wmerge (void)
7934{
7935 inst.instruction |= inst.operands[0].reg << 12;
7936 inst.instruction |= inst.operands[1].reg << 16;
7937 inst.instruction |= inst.operands[2].reg;
7938 inst.instruction |= inst.operands[3].imm << 21;
7939}
7940
c19d1205
ZW
7941static void
7942do_iwmmxt_wmov (void)
7943{
7944 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7945 inst.instruction |= inst.operands[0].reg << 12;
7946 inst.instruction |= inst.operands[1].reg << 16;
7947 inst.instruction |= inst.operands[1].reg;
7948}
b99bd4ef 7949
c19d1205
ZW
7950static void
7951do_iwmmxt_wldstbh (void)
7952{
8f06b2d8 7953 int reloc;
c19d1205 7954 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7955 if (thumb_mode)
7956 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7957 else
7958 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7959 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7960}
7961
c19d1205
ZW
7962static void
7963do_iwmmxt_wldstw (void)
7964{
7965 /* RIWR_RIWC clears .isreg for a control register. */
7966 if (!inst.operands[0].isreg)
7967 {
7968 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7969 inst.instruction |= 0xf0000000;
7970 }
b99bd4ef 7971
c19d1205
ZW
7972 inst.instruction |= inst.operands[0].reg << 12;
7973 encode_arm_cp_address (1, TRUE, TRUE, 0);
7974}
b99bd4ef
NC
7975
7976static void
c19d1205 7977do_iwmmxt_wldstd (void)
b99bd4ef 7978{
c19d1205 7979 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7980 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7981 && inst.operands[1].immisreg)
7982 {
7983 inst.instruction &= ~0x1a000ff;
7984 inst.instruction |= (0xf << 28);
7985 if (inst.operands[1].preind)
7986 inst.instruction |= PRE_INDEX;
7987 if (!inst.operands[1].negative)
7988 inst.instruction |= INDEX_UP;
7989 if (inst.operands[1].writeback)
7990 inst.instruction |= WRITE_BACK;
7991 inst.instruction |= inst.operands[1].reg << 16;
7992 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7993 inst.instruction |= inst.operands[1].imm;
7994 }
7995 else
7996 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 7997}
b99bd4ef 7998
c19d1205
ZW
7999static void
8000do_iwmmxt_wshufh (void)
8001{
8002 inst.instruction |= inst.operands[0].reg << 12;
8003 inst.instruction |= inst.operands[1].reg << 16;
8004 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8005 inst.instruction |= (inst.operands[2].imm & 0x0f);
8006}
b99bd4ef 8007
c19d1205
ZW
8008static void
8009do_iwmmxt_wzero (void)
8010{
8011 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8012 inst.instruction |= inst.operands[0].reg;
8013 inst.instruction |= inst.operands[0].reg << 12;
8014 inst.instruction |= inst.operands[0].reg << 16;
8015}
2d447fca
JM
8016
8017static void
8018do_iwmmxt_wrwrwr_or_imm5 (void)
8019{
8020 if (inst.operands[2].isreg)
8021 do_rd_rn_rm ();
8022 else {
8023 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8024 _("immediate operand requires iWMMXt2"));
8025 do_rd_rn ();
8026 if (inst.operands[2].imm == 0)
8027 {
8028 switch ((inst.instruction >> 20) & 0xf)
8029 {
8030 case 4:
8031 case 5:
8032 case 6:
8033 case 7:
8034 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8035 inst.operands[2].imm = 16;
8036 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8037 break;
8038 case 8:
8039 case 9:
8040 case 10:
8041 case 11:
8042 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8043 inst.operands[2].imm = 32;
8044 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8045 break;
8046 case 12:
8047 case 13:
8048 case 14:
8049 case 15:
8050 {
8051 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8052 unsigned long wrn;
8053 wrn = (inst.instruction >> 16) & 0xf;
8054 inst.instruction &= 0xff0fff0f;
8055 inst.instruction |= wrn;
8056 /* Bail out here; the instruction is now assembled. */
8057 return;
8058 }
8059 }
8060 }
8061 /* Map 32 -> 0, etc. */
8062 inst.operands[2].imm &= 0x1f;
8063 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8064 }
8065}
c19d1205
ZW
8066\f
8067/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8068 operations first, then control, shift, and load/store. */
b99bd4ef 8069
c19d1205 8070/* Insns like "foo X,Y,Z". */
b99bd4ef 8071
c19d1205
ZW
8072static void
8073do_mav_triple (void)
8074{
8075 inst.instruction |= inst.operands[0].reg << 16;
8076 inst.instruction |= inst.operands[1].reg;
8077 inst.instruction |= inst.operands[2].reg << 12;
8078}
b99bd4ef 8079
c19d1205
ZW
8080/* Insns like "foo W,X,Y,Z".
8081 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8082
c19d1205
ZW
8083static void
8084do_mav_quad (void)
8085{
8086 inst.instruction |= inst.operands[0].reg << 5;
8087 inst.instruction |= inst.operands[1].reg << 12;
8088 inst.instruction |= inst.operands[2].reg << 16;
8089 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8090}
8091
c19d1205
ZW
8092/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8093static void
8094do_mav_dspsc (void)
a737bd4d 8095{
c19d1205
ZW
8096 inst.instruction |= inst.operands[1].reg << 12;
8097}
a737bd4d 8098
c19d1205
ZW
8099/* Maverick shift immediate instructions.
8100 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8101 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8102
c19d1205
ZW
8103static void
8104do_mav_shift (void)
8105{
8106 int imm = inst.operands[2].imm;
a737bd4d 8107
c19d1205
ZW
8108 inst.instruction |= inst.operands[0].reg << 12;
8109 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8110
c19d1205
ZW
8111 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8112 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8113 Bit 4 should be 0. */
8114 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8115
c19d1205
ZW
8116 inst.instruction |= imm;
8117}
8118\f
8119/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8120
c19d1205
ZW
8121/* Xscale multiply-accumulate (argument parse)
8122 MIAcc acc0,Rm,Rs
8123 MIAPHcc acc0,Rm,Rs
8124 MIAxycc acc0,Rm,Rs. */
a737bd4d 8125
c19d1205
ZW
8126static void
8127do_xsc_mia (void)
8128{
8129 inst.instruction |= inst.operands[1].reg;
8130 inst.instruction |= inst.operands[2].reg << 12;
8131}
a737bd4d 8132
c19d1205 8133/* Xscale move-accumulator-register (argument parse)
a737bd4d 8134
c19d1205 8135 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8136
c19d1205
ZW
8137static void
8138do_xsc_mar (void)
8139{
8140 inst.instruction |= inst.operands[1].reg << 12;
8141 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8142}
8143
c19d1205 8144/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8145
c19d1205 8146 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8147
8148static void
c19d1205 8149do_xsc_mra (void)
b99bd4ef 8150{
c19d1205
ZW
8151 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8152 inst.instruction |= inst.operands[0].reg << 12;
8153 inst.instruction |= inst.operands[1].reg << 16;
8154}
8155\f
8156/* Encoding functions relevant only to Thumb. */
b99bd4ef 8157
c19d1205
ZW
8158/* inst.operands[i] is a shifted-register operand; encode
8159 it into inst.instruction in the format used by Thumb32. */
8160
8161static void
8162encode_thumb32_shifted_operand (int i)
8163{
8164 unsigned int value = inst.reloc.exp.X_add_number;
8165 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8166
9c3c69f2
PB
8167 constraint (inst.operands[i].immisreg,
8168 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8169 inst.instruction |= inst.operands[i].reg;
8170 if (shift == SHIFT_RRX)
8171 inst.instruction |= SHIFT_ROR << 4;
8172 else
b99bd4ef 8173 {
c19d1205
ZW
8174 constraint (inst.reloc.exp.X_op != O_constant,
8175 _("expression too complex"));
8176
8177 constraint (value > 32
8178 || (value == 32 && (shift == SHIFT_LSL
8179 || shift == SHIFT_ROR)),
8180 _("shift expression is too large"));
8181
8182 if (value == 0)
8183 shift = SHIFT_LSL;
8184 else if (value == 32)
8185 value = 0;
8186
8187 inst.instruction |= shift << 4;
8188 inst.instruction |= (value & 0x1c) << 10;
8189 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8190 }
c19d1205 8191}
b99bd4ef 8192
b99bd4ef 8193
c19d1205
ZW
8194/* inst.operands[i] was set up by parse_address. Encode it into a
8195 Thumb32 format load or store instruction. Reject forms that cannot
8196 be used with such instructions. If is_t is true, reject forms that
8197 cannot be used with a T instruction; if is_d is true, reject forms
8198 that cannot be used with a D instruction. */
b99bd4ef 8199
c19d1205
ZW
8200static void
8201encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8202{
8203 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8204
8205 constraint (!inst.operands[i].isreg,
53365c0d 8206 _("Instruction does not support =N addresses"));
b99bd4ef 8207
c19d1205
ZW
8208 inst.instruction |= inst.operands[i].reg << 16;
8209 if (inst.operands[i].immisreg)
b99bd4ef 8210 {
c19d1205
ZW
8211 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8212 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8213 constraint (inst.operands[i].negative,
8214 _("Thumb does not support negative register indexing"));
8215 constraint (inst.operands[i].postind,
8216 _("Thumb does not support register post-indexing"));
8217 constraint (inst.operands[i].writeback,
8218 _("Thumb does not support register indexing with writeback"));
8219 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8220 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8221
f40d1643 8222 inst.instruction |= inst.operands[i].imm;
c19d1205 8223 if (inst.operands[i].shifted)
b99bd4ef 8224 {
c19d1205
ZW
8225 constraint (inst.reloc.exp.X_op != O_constant,
8226 _("expression too complex"));
9c3c69f2
PB
8227 constraint (inst.reloc.exp.X_add_number < 0
8228 || inst.reloc.exp.X_add_number > 3,
c19d1205 8229 _("shift out of range"));
9c3c69f2 8230 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8231 }
8232 inst.reloc.type = BFD_RELOC_UNUSED;
8233 }
8234 else if (inst.operands[i].preind)
8235 {
8236 constraint (is_pc && inst.operands[i].writeback,
8237 _("cannot use writeback with PC-relative addressing"));
f40d1643 8238 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8239 _("cannot use writeback with this instruction"));
8240
8241 if (is_d)
8242 {
8243 inst.instruction |= 0x01000000;
8244 if (inst.operands[i].writeback)
8245 inst.instruction |= 0x00200000;
b99bd4ef 8246 }
c19d1205 8247 else
b99bd4ef 8248 {
c19d1205
ZW
8249 inst.instruction |= 0x00000c00;
8250 if (inst.operands[i].writeback)
8251 inst.instruction |= 0x00000100;
b99bd4ef 8252 }
c19d1205 8253 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8254 }
c19d1205 8255 else if (inst.operands[i].postind)
b99bd4ef 8256 {
c19d1205
ZW
8257 assert (inst.operands[i].writeback);
8258 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8259 constraint (is_t, _("cannot use post-indexing with this instruction"));
8260
8261 if (is_d)
8262 inst.instruction |= 0x00200000;
8263 else
8264 inst.instruction |= 0x00000900;
8265 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8266 }
8267 else /* unindexed - only for coprocessor */
8268 inst.error = _("instruction does not accept unindexed addressing");
8269}
8270
8271/* Table of Thumb instructions which exist in both 16- and 32-bit
8272 encodings (the latter only in post-V6T2 cores). The index is the
8273 value used in the insns table below. When there is more than one
8274 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8275 holds variant (1).
8276 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8277#define T16_32_TAB \
8278 X(adc, 4140, eb400000), \
8279 X(adcs, 4140, eb500000), \
8280 X(add, 1c00, eb000000), \
8281 X(adds, 1c00, eb100000), \
0110f2b8
PB
8282 X(addi, 0000, f1000000), \
8283 X(addis, 0000, f1100000), \
8284 X(add_pc,000f, f20f0000), \
8285 X(add_sp,000d, f10d0000), \
e9f89963 8286 X(adr, 000f, f20f0000), \
c19d1205
ZW
8287 X(and, 4000, ea000000), \
8288 X(ands, 4000, ea100000), \
8289 X(asr, 1000, fa40f000), \
8290 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8291 X(b, e000, f000b000), \
8292 X(bcond, d000, f0008000), \
c19d1205
ZW
8293 X(bic, 4380, ea200000), \
8294 X(bics, 4380, ea300000), \
8295 X(cmn, 42c0, eb100f00), \
8296 X(cmp, 2800, ebb00f00), \
8297 X(cpsie, b660, f3af8400), \
8298 X(cpsid, b670, f3af8600), \
8299 X(cpy, 4600, ea4f0000), \
155257ea 8300 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8301 X(eor, 4040, ea800000), \
8302 X(eors, 4040, ea900000), \
0110f2b8 8303 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8304 X(ldmia, c800, e8900000), \
8305 X(ldr, 6800, f8500000), \
8306 X(ldrb, 7800, f8100000), \
8307 X(ldrh, 8800, f8300000), \
8308 X(ldrsb, 5600, f9100000), \
8309 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8310 X(ldr_pc,4800, f85f0000), \
8311 X(ldr_pc2,4800, f85f0000), \
8312 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8313 X(lsl, 0000, fa00f000), \
8314 X(lsls, 0000, fa10f000), \
8315 X(lsr, 0800, fa20f000), \
8316 X(lsrs, 0800, fa30f000), \
8317 X(mov, 2000, ea4f0000), \
8318 X(movs, 2000, ea5f0000), \
8319 X(mul, 4340, fb00f000), \
8320 X(muls, 4340, ffffffff), /* no 32b muls */ \
8321 X(mvn, 43c0, ea6f0000), \
8322 X(mvns, 43c0, ea7f0000), \
8323 X(neg, 4240, f1c00000), /* rsb #0 */ \
8324 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8325 X(orr, 4300, ea400000), \
8326 X(orrs, 4300, ea500000), \
e9f89963
PB
8327 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8328 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8329 X(rev, ba00, fa90f080), \
8330 X(rev16, ba40, fa90f090), \
8331 X(revsh, bac0, fa90f0b0), \
8332 X(ror, 41c0, fa60f000), \
8333 X(rors, 41c0, fa70f000), \
8334 X(sbc, 4180, eb600000), \
8335 X(sbcs, 4180, eb700000), \
8336 X(stmia, c000, e8800000), \
8337 X(str, 6000, f8400000), \
8338 X(strb, 7000, f8000000), \
8339 X(strh, 8000, f8200000), \
0110f2b8 8340 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8341 X(sub, 1e00, eba00000), \
8342 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8343 X(subi, 8000, f1a00000), \
8344 X(subis, 8000, f1b00000), \
c19d1205
ZW
8345 X(sxtb, b240, fa4ff080), \
8346 X(sxth, b200, fa0ff080), \
8347 X(tst, 4200, ea100f00), \
8348 X(uxtb, b2c0, fa5ff080), \
8349 X(uxth, b280, fa1ff080), \
8350 X(nop, bf00, f3af8000), \
8351 X(yield, bf10, f3af8001), \
8352 X(wfe, bf20, f3af8002), \
8353 X(wfi, bf30, f3af8003), \
8354 X(sev, bf40, f3af9004), /* typo, 8004? */
8355
8356/* To catch errors in encoding functions, the codes are all offset by
8357 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8358 as 16-bit instructions. */
8359#define X(a,b,c) T_MNEM_##a
8360enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8361#undef X
8362
8363#define X(a,b,c) 0x##b
8364static const unsigned short thumb_op16[] = { T16_32_TAB };
8365#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8366#undef X
8367
8368#define X(a,b,c) 0x##c
8369static const unsigned int thumb_op32[] = { T16_32_TAB };
8370#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8371#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8372#undef X
8373#undef T16_32_TAB
8374
8375/* Thumb instruction encoders, in alphabetical order. */
8376
92e90b6e
PB
8377/* ADDW or SUBW. */
8378static void
8379do_t_add_sub_w (void)
8380{
8381 int Rd, Rn;
8382
8383 Rd = inst.operands[0].reg;
8384 Rn = inst.operands[1].reg;
8385
8386 constraint (Rd == 15, _("PC not allowed as destination"));
8387 inst.instruction |= (Rn << 16) | (Rd << 8);
8388 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8389}
8390
c19d1205
ZW
8391/* Parse an add or subtract instruction. We get here with inst.instruction
8392 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8393
8394static void
8395do_t_add_sub (void)
8396{
8397 int Rd, Rs, Rn;
8398
8399 Rd = inst.operands[0].reg;
8400 Rs = (inst.operands[1].present
8401 ? inst.operands[1].reg /* Rd, Rs, foo */
8402 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8403
8404 if (unified_syntax)
8405 {
0110f2b8
PB
8406 bfd_boolean flags;
8407 bfd_boolean narrow;
8408 int opcode;
8409
8410 flags = (inst.instruction == T_MNEM_adds
8411 || inst.instruction == T_MNEM_subs);
8412 if (flags)
8413 narrow = (current_it_mask == 0);
8414 else
8415 narrow = (current_it_mask != 0);
c19d1205 8416 if (!inst.operands[2].isreg)
b99bd4ef 8417 {
16805f35
PB
8418 int add;
8419
8420 add = (inst.instruction == T_MNEM_add
8421 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8422 opcode = 0;
8423 if (inst.size_req != 4)
8424 {
0110f2b8
PB
8425 /* Attempt to use a narrow opcode, with relaxation if
8426 appropriate. */
8427 if (Rd == REG_SP && Rs == REG_SP && !flags)
8428 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8429 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8430 opcode = T_MNEM_add_sp;
8431 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8432 opcode = T_MNEM_add_pc;
8433 else if (Rd <= 7 && Rs <= 7 && narrow)
8434 {
8435 if (flags)
8436 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8437 else
8438 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8439 }
8440 if (opcode)
8441 {
8442 inst.instruction = THUMB_OP16(opcode);
8443 inst.instruction |= (Rd << 4) | Rs;
8444 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8445 if (inst.size_req != 2)
8446 inst.relax = opcode;
8447 }
8448 else
8449 constraint (inst.size_req == 2, BAD_HIREG);
8450 }
8451 if (inst.size_req == 4
8452 || (inst.size_req != 2 && !opcode))
8453 {
efd81785
PB
8454 if (Rd == REG_PC)
8455 {
8456 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8457 _("only SUBS PC, LR, #const allowed"));
8458 constraint (inst.reloc.exp.X_op != O_constant,
8459 _("expression too complex"));
8460 constraint (inst.reloc.exp.X_add_number < 0
8461 || inst.reloc.exp.X_add_number > 0xff,
8462 _("immediate value out of range"));
8463 inst.instruction = T2_SUBS_PC_LR
8464 | inst.reloc.exp.X_add_number;
8465 inst.reloc.type = BFD_RELOC_UNUSED;
8466 return;
8467 }
8468 else if (Rs == REG_PC)
16805f35
PB
8469 {
8470 /* Always use addw/subw. */
8471 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8472 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8473 }
8474 else
8475 {
8476 inst.instruction = THUMB_OP32 (inst.instruction);
8477 inst.instruction = (inst.instruction & 0xe1ffffff)
8478 | 0x10000000;
8479 if (flags)
8480 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8481 else
8482 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8483 }
dc4503c6
PB
8484 inst.instruction |= Rd << 8;
8485 inst.instruction |= Rs << 16;
0110f2b8 8486 }
b99bd4ef 8487 }
c19d1205
ZW
8488 else
8489 {
8490 Rn = inst.operands[2].reg;
8491 /* See if we can do this with a 16-bit instruction. */
8492 if (!inst.operands[2].shifted && inst.size_req != 4)
8493 {
e27ec89e
PB
8494 if (Rd > 7 || Rs > 7 || Rn > 7)
8495 narrow = FALSE;
8496
8497 if (narrow)
c19d1205 8498 {
e27ec89e
PB
8499 inst.instruction = ((inst.instruction == T_MNEM_adds
8500 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8501 ? T_OPCODE_ADD_R3
8502 : T_OPCODE_SUB_R3);
8503 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8504 return;
8505 }
b99bd4ef 8506
c19d1205
ZW
8507 if (inst.instruction == T_MNEM_add)
8508 {
8509 if (Rd == Rs)
8510 {
8511 inst.instruction = T_OPCODE_ADD_HI;
8512 inst.instruction |= (Rd & 8) << 4;
8513 inst.instruction |= (Rd & 7);
8514 inst.instruction |= Rn << 3;
8515 return;
8516 }
8517 /* ... because addition is commutative! */
8518 else if (Rd == Rn)
8519 {
8520 inst.instruction = T_OPCODE_ADD_HI;
8521 inst.instruction |= (Rd & 8) << 4;
8522 inst.instruction |= (Rd & 7);
8523 inst.instruction |= Rs << 3;
8524 return;
8525 }
8526 }
8527 }
8528 /* If we get here, it can't be done in 16 bits. */
8529 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8530 _("shift must be constant"));
8531 inst.instruction = THUMB_OP32 (inst.instruction);
8532 inst.instruction |= Rd << 8;
8533 inst.instruction |= Rs << 16;
8534 encode_thumb32_shifted_operand (2);
8535 }
8536 }
8537 else
8538 {
8539 constraint (inst.instruction == T_MNEM_adds
8540 || inst.instruction == T_MNEM_subs,
8541 BAD_THUMB32);
b99bd4ef 8542
c19d1205 8543 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8544 {
c19d1205
ZW
8545 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8546 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8547 BAD_HIREG);
8548
8549 inst.instruction = (inst.instruction == T_MNEM_add
8550 ? 0x0000 : 0x8000);
8551 inst.instruction |= (Rd << 4) | Rs;
8552 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8553 return;
8554 }
8555
c19d1205
ZW
8556 Rn = inst.operands[2].reg;
8557 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8558
c19d1205
ZW
8559 /* We now have Rd, Rs, and Rn set to registers. */
8560 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8561 {
c19d1205
ZW
8562 /* Can't do this for SUB. */
8563 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8564 inst.instruction = T_OPCODE_ADD_HI;
8565 inst.instruction |= (Rd & 8) << 4;
8566 inst.instruction |= (Rd & 7);
8567 if (Rs == Rd)
8568 inst.instruction |= Rn << 3;
8569 else if (Rn == Rd)
8570 inst.instruction |= Rs << 3;
8571 else
8572 constraint (1, _("dest must overlap one source register"));
8573 }
8574 else
8575 {
8576 inst.instruction = (inst.instruction == T_MNEM_add
8577 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8578 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8579 }
b99bd4ef 8580 }
b99bd4ef
NC
8581}
8582
c19d1205
ZW
8583static void
8584do_t_adr (void)
8585{
0110f2b8
PB
8586 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8587 {
8588 /* Defer to section relaxation. */
8589 inst.relax = inst.instruction;
8590 inst.instruction = THUMB_OP16 (inst.instruction);
8591 inst.instruction |= inst.operands[0].reg << 4;
8592 }
8593 else if (unified_syntax && inst.size_req != 2)
e9f89963 8594 {
0110f2b8 8595 /* Generate a 32-bit opcode. */
e9f89963
PB
8596 inst.instruction = THUMB_OP32 (inst.instruction);
8597 inst.instruction |= inst.operands[0].reg << 8;
8598 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8599 inst.reloc.pc_rel = 1;
8600 }
8601 else
8602 {
0110f2b8 8603 /* Generate a 16-bit opcode. */
e9f89963
PB
8604 inst.instruction = THUMB_OP16 (inst.instruction);
8605 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8606 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8607 inst.reloc.pc_rel = 1;
b99bd4ef 8608
e9f89963
PB
8609 inst.instruction |= inst.operands[0].reg << 4;
8610 }
c19d1205 8611}
b99bd4ef 8612
c19d1205
ZW
8613/* Arithmetic instructions for which there is just one 16-bit
8614 instruction encoding, and it allows only two low registers.
8615 For maximal compatibility with ARM syntax, we allow three register
8616 operands even when Thumb-32 instructions are not available, as long
8617 as the first two are identical. For instance, both "sbc r0,r1" and
8618 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8619static void
c19d1205 8620do_t_arit3 (void)
b99bd4ef 8621{
c19d1205 8622 int Rd, Rs, Rn;
b99bd4ef 8623
c19d1205
ZW
8624 Rd = inst.operands[0].reg;
8625 Rs = (inst.operands[1].present
8626 ? inst.operands[1].reg /* Rd, Rs, foo */
8627 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8628 Rn = inst.operands[2].reg;
b99bd4ef 8629
c19d1205 8630 if (unified_syntax)
b99bd4ef 8631 {
c19d1205
ZW
8632 if (!inst.operands[2].isreg)
8633 {
8634 /* For an immediate, we always generate a 32-bit opcode;
8635 section relaxation will shrink it later if possible. */
8636 inst.instruction = THUMB_OP32 (inst.instruction);
8637 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8638 inst.instruction |= Rd << 8;
8639 inst.instruction |= Rs << 16;
8640 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8641 }
8642 else
8643 {
e27ec89e
PB
8644 bfd_boolean narrow;
8645
c19d1205 8646 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8647 if (THUMB_SETS_FLAGS (inst.instruction))
8648 narrow = current_it_mask == 0;
8649 else
8650 narrow = current_it_mask != 0;
8651
8652 if (Rd > 7 || Rn > 7 || Rs > 7)
8653 narrow = FALSE;
8654 if (inst.operands[2].shifted)
8655 narrow = FALSE;
8656 if (inst.size_req == 4)
8657 narrow = FALSE;
8658
8659 if (narrow
c19d1205
ZW
8660 && Rd == Rs)
8661 {
8662 inst.instruction = THUMB_OP16 (inst.instruction);
8663 inst.instruction |= Rd;
8664 inst.instruction |= Rn << 3;
8665 return;
8666 }
b99bd4ef 8667
c19d1205
ZW
8668 /* If we get here, it can't be done in 16 bits. */
8669 constraint (inst.operands[2].shifted
8670 && inst.operands[2].immisreg,
8671 _("shift must be constant"));
8672 inst.instruction = THUMB_OP32 (inst.instruction);
8673 inst.instruction |= Rd << 8;
8674 inst.instruction |= Rs << 16;
8675 encode_thumb32_shifted_operand (2);
8676 }
a737bd4d 8677 }
c19d1205 8678 else
b99bd4ef 8679 {
c19d1205
ZW
8680 /* On its face this is a lie - the instruction does set the
8681 flags. However, the only supported mnemonic in this mode
8682 says it doesn't. */
8683 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8684
c19d1205
ZW
8685 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8686 _("unshifted register required"));
8687 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8688 constraint (Rd != Rs,
8689 _("dest and source1 must be the same register"));
a737bd4d 8690
c19d1205
ZW
8691 inst.instruction = THUMB_OP16 (inst.instruction);
8692 inst.instruction |= Rd;
8693 inst.instruction |= Rn << 3;
b99bd4ef 8694 }
a737bd4d 8695}
b99bd4ef 8696
c19d1205
ZW
8697/* Similarly, but for instructions where the arithmetic operation is
8698 commutative, so we can allow either of them to be different from
8699 the destination operand in a 16-bit instruction. For instance, all
8700 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8701 accepted. */
8702static void
8703do_t_arit3c (void)
a737bd4d 8704{
c19d1205 8705 int Rd, Rs, Rn;
b99bd4ef 8706
c19d1205
ZW
8707 Rd = inst.operands[0].reg;
8708 Rs = (inst.operands[1].present
8709 ? inst.operands[1].reg /* Rd, Rs, foo */
8710 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8711 Rn = inst.operands[2].reg;
a737bd4d 8712
c19d1205 8713 if (unified_syntax)
a737bd4d 8714 {
c19d1205 8715 if (!inst.operands[2].isreg)
b99bd4ef 8716 {
c19d1205
ZW
8717 /* For an immediate, we always generate a 32-bit opcode;
8718 section relaxation will shrink it later if possible. */
8719 inst.instruction = THUMB_OP32 (inst.instruction);
8720 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8721 inst.instruction |= Rd << 8;
8722 inst.instruction |= Rs << 16;
8723 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8724 }
c19d1205 8725 else
a737bd4d 8726 {
e27ec89e
PB
8727 bfd_boolean narrow;
8728
c19d1205 8729 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8730 if (THUMB_SETS_FLAGS (inst.instruction))
8731 narrow = current_it_mask == 0;
8732 else
8733 narrow = current_it_mask != 0;
8734
8735 if (Rd > 7 || Rn > 7 || Rs > 7)
8736 narrow = FALSE;
8737 if (inst.operands[2].shifted)
8738 narrow = FALSE;
8739 if (inst.size_req == 4)
8740 narrow = FALSE;
8741
8742 if (narrow)
a737bd4d 8743 {
c19d1205 8744 if (Rd == Rs)
a737bd4d 8745 {
c19d1205
ZW
8746 inst.instruction = THUMB_OP16 (inst.instruction);
8747 inst.instruction |= Rd;
8748 inst.instruction |= Rn << 3;
8749 return;
a737bd4d 8750 }
c19d1205 8751 if (Rd == Rn)
a737bd4d 8752 {
c19d1205
ZW
8753 inst.instruction = THUMB_OP16 (inst.instruction);
8754 inst.instruction |= Rd;
8755 inst.instruction |= Rs << 3;
8756 return;
a737bd4d
NC
8757 }
8758 }
c19d1205
ZW
8759
8760 /* If we get here, it can't be done in 16 bits. */
8761 constraint (inst.operands[2].shifted
8762 && inst.operands[2].immisreg,
8763 _("shift must be constant"));
8764 inst.instruction = THUMB_OP32 (inst.instruction);
8765 inst.instruction |= Rd << 8;
8766 inst.instruction |= Rs << 16;
8767 encode_thumb32_shifted_operand (2);
a737bd4d 8768 }
b99bd4ef 8769 }
c19d1205
ZW
8770 else
8771 {
8772 /* On its face this is a lie - the instruction does set the
8773 flags. However, the only supported mnemonic in this mode
8774 says it doesn't. */
8775 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8776
c19d1205
ZW
8777 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8778 _("unshifted register required"));
8779 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8780
8781 inst.instruction = THUMB_OP16 (inst.instruction);
8782 inst.instruction |= Rd;
8783
8784 if (Rd == Rs)
8785 inst.instruction |= Rn << 3;
8786 else if (Rd == Rn)
8787 inst.instruction |= Rs << 3;
8788 else
8789 constraint (1, _("dest must overlap one source register"));
8790 }
a737bd4d
NC
8791}
8792
62b3e311
PB
8793static void
8794do_t_barrier (void)
8795{
8796 if (inst.operands[0].present)
8797 {
8798 constraint ((inst.instruction & 0xf0) != 0x40
8799 && inst.operands[0].imm != 0xf,
8800 "bad barrier type");
8801 inst.instruction |= inst.operands[0].imm;
8802 }
8803 else
8804 inst.instruction |= 0xf;
8805}
8806
c19d1205
ZW
8807static void
8808do_t_bfc (void)
a737bd4d 8809{
c19d1205
ZW
8810 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8811 constraint (msb > 32, _("bit-field extends past end of register"));
8812 /* The instruction encoding stores the LSB and MSB,
8813 not the LSB and width. */
8814 inst.instruction |= inst.operands[0].reg << 8;
8815 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8816 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8817 inst.instruction |= msb - 1;
b99bd4ef
NC
8818}
8819
c19d1205
ZW
8820static void
8821do_t_bfi (void)
b99bd4ef 8822{
c19d1205 8823 unsigned int msb;
b99bd4ef 8824
c19d1205
ZW
8825 /* #0 in second position is alternative syntax for bfc, which is
8826 the same instruction but with REG_PC in the Rm field. */
8827 if (!inst.operands[1].isreg)
8828 inst.operands[1].reg = REG_PC;
b99bd4ef 8829
c19d1205
ZW
8830 msb = inst.operands[2].imm + inst.operands[3].imm;
8831 constraint (msb > 32, _("bit-field extends past end of register"));
8832 /* The instruction encoding stores the LSB and MSB,
8833 not the LSB and width. */
8834 inst.instruction |= inst.operands[0].reg << 8;
8835 inst.instruction |= inst.operands[1].reg << 16;
8836 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8837 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8838 inst.instruction |= msb - 1;
b99bd4ef
NC
8839}
8840
c19d1205
ZW
8841static void
8842do_t_bfx (void)
b99bd4ef 8843{
c19d1205
ZW
8844 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8845 _("bit-field extends past end of register"));
8846 inst.instruction |= inst.operands[0].reg << 8;
8847 inst.instruction |= inst.operands[1].reg << 16;
8848 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8849 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8850 inst.instruction |= inst.operands[3].imm - 1;
8851}
b99bd4ef 8852
c19d1205
ZW
8853/* ARM V5 Thumb BLX (argument parse)
8854 BLX <target_addr> which is BLX(1)
8855 BLX <Rm> which is BLX(2)
8856 Unfortunately, there are two different opcodes for this mnemonic.
8857 So, the insns[].value is not used, and the code here zaps values
8858 into inst.instruction.
b99bd4ef 8859
c19d1205
ZW
8860 ??? How to take advantage of the additional two bits of displacement
8861 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8862
c19d1205
ZW
8863static void
8864do_t_blx (void)
8865{
dfa9f0d5 8866 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8867 if (inst.operands[0].isreg)
8868 /* We have a register, so this is BLX(2). */
8869 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8870 else
8871 {
c19d1205 8872 /* No register. This must be BLX(1). */
2fc8bdac 8873 inst.instruction = 0xf000e800;
39b41c9c
PB
8874#ifdef OBJ_ELF
8875 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8876 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8877 else
8878#endif
8879 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8880 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8881 }
8882}
8883
c19d1205
ZW
8884static void
8885do_t_branch (void)
b99bd4ef 8886{
0110f2b8 8887 int opcode;
dfa9f0d5
PB
8888 int cond;
8889
8890 if (current_it_mask)
8891 {
8892 /* Conditional branches inside IT blocks are encoded as unconditional
8893 branches. */
8894 cond = COND_ALWAYS;
8895 /* A branch must be the last instruction in an IT block. */
8896 constraint (current_it_mask != 0x10, BAD_BRANCH);
8897 }
8898 else
8899 cond = inst.cond;
8900
8901 if (cond != COND_ALWAYS)
0110f2b8
PB
8902 opcode = T_MNEM_bcond;
8903 else
8904 opcode = inst.instruction;
8905
8906 if (unified_syntax && inst.size_req == 4)
c19d1205 8907 {
0110f2b8 8908 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8909 if (cond == COND_ALWAYS)
0110f2b8 8910 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8911 else
8912 {
dfa9f0d5
PB
8913 assert (cond != 0xF);
8914 inst.instruction |= cond << 22;
c19d1205
ZW
8915 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8916 }
8917 }
b99bd4ef
NC
8918 else
8919 {
0110f2b8 8920 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8921 if (cond == COND_ALWAYS)
c19d1205
ZW
8922 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8923 else
b99bd4ef 8924 {
dfa9f0d5 8925 inst.instruction |= cond << 8;
c19d1205 8926 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8927 }
0110f2b8
PB
8928 /* Allow section relaxation. */
8929 if (unified_syntax && inst.size_req != 2)
8930 inst.relax = opcode;
b99bd4ef 8931 }
c19d1205
ZW
8932
8933 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8934}
8935
8936static void
c19d1205 8937do_t_bkpt (void)
b99bd4ef 8938{
dfa9f0d5
PB
8939 constraint (inst.cond != COND_ALWAYS,
8940 _("instruction is always unconditional"));
c19d1205 8941 if (inst.operands[0].present)
b99bd4ef 8942 {
c19d1205
ZW
8943 constraint (inst.operands[0].imm > 255,
8944 _("immediate value out of range"));
8945 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8946 }
b99bd4ef
NC
8947}
8948
8949static void
c19d1205 8950do_t_branch23 (void)
b99bd4ef 8951{
dfa9f0d5 8952 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8953 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8954 inst.reloc.pc_rel = 1;
8955
c19d1205
ZW
8956 /* If the destination of the branch is a defined symbol which does not have
8957 the THUMB_FUNC attribute, then we must be calling a function which has
8958 the (interfacearm) attribute. We look for the Thumb entry point to that
8959 function and change the branch to refer to that function instead. */
8960 if ( inst.reloc.exp.X_op == O_symbol
8961 && inst.reloc.exp.X_add_symbol != NULL
8962 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8963 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8964 inst.reloc.exp.X_add_symbol =
8965 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8966}
8967
8968static void
c19d1205 8969do_t_bx (void)
90e4755a 8970{
dfa9f0d5 8971 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8972 inst.instruction |= inst.operands[0].reg << 3;
8973 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8974 should cause the alignment to be checked once it is known. This is
8975 because BX PC only works if the instruction is word aligned. */
8976}
90e4755a 8977
c19d1205
ZW
8978static void
8979do_t_bxj (void)
8980{
dfa9f0d5 8981 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8982 if (inst.operands[0].reg == REG_PC)
8983 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8984
c19d1205 8985 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8986}
8987
8988static void
c19d1205 8989do_t_clz (void)
90e4755a 8990{
c19d1205
ZW
8991 inst.instruction |= inst.operands[0].reg << 8;
8992 inst.instruction |= inst.operands[1].reg << 16;
8993 inst.instruction |= inst.operands[1].reg;
8994}
90e4755a 8995
dfa9f0d5
PB
8996static void
8997do_t_cps (void)
8998{
8999 constraint (current_it_mask, BAD_NOT_IT);
9000 inst.instruction |= inst.operands[0].imm;
9001}
9002
c19d1205
ZW
9003static void
9004do_t_cpsi (void)
9005{
dfa9f0d5 9006 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9007 if (unified_syntax
62b3e311
PB
9008 && (inst.operands[1].present || inst.size_req == 4)
9009 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9010 {
c19d1205
ZW
9011 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9012 inst.instruction = 0xf3af8000;
9013 inst.instruction |= imod << 9;
9014 inst.instruction |= inst.operands[0].imm << 5;
9015 if (inst.operands[1].present)
9016 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9017 }
c19d1205 9018 else
90e4755a 9019 {
62b3e311
PB
9020 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9021 && (inst.operands[0].imm & 4),
9022 _("selected processor does not support 'A' form "
9023 "of this instruction"));
9024 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9025 _("Thumb does not support the 2-argument "
9026 "form of this instruction"));
9027 inst.instruction |= inst.operands[0].imm;
90e4755a 9028 }
90e4755a
RE
9029}
9030
c19d1205
ZW
9031/* THUMB CPY instruction (argument parse). */
9032
90e4755a 9033static void
c19d1205 9034do_t_cpy (void)
90e4755a 9035{
c19d1205 9036 if (inst.size_req == 4)
90e4755a 9037 {
c19d1205
ZW
9038 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9039 inst.instruction |= inst.operands[0].reg << 8;
9040 inst.instruction |= inst.operands[1].reg;
90e4755a 9041 }
c19d1205 9042 else
90e4755a 9043 {
c19d1205
ZW
9044 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9045 inst.instruction |= (inst.operands[0].reg & 0x7);
9046 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9047 }
90e4755a
RE
9048}
9049
90e4755a 9050static void
25fe350b 9051do_t_cbz (void)
90e4755a 9052{
dfa9f0d5 9053 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9054 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9055 inst.instruction |= inst.operands[0].reg;
9056 inst.reloc.pc_rel = 1;
9057 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9058}
90e4755a 9059
62b3e311
PB
9060static void
9061do_t_dbg (void)
9062{
9063 inst.instruction |= inst.operands[0].imm;
9064}
9065
9066static void
9067do_t_div (void)
9068{
9069 if (!inst.operands[1].present)
9070 inst.operands[1].reg = inst.operands[0].reg;
9071 inst.instruction |= inst.operands[0].reg << 8;
9072 inst.instruction |= inst.operands[1].reg << 16;
9073 inst.instruction |= inst.operands[2].reg;
9074}
9075
c19d1205
ZW
9076static void
9077do_t_hint (void)
9078{
9079 if (unified_syntax && inst.size_req == 4)
9080 inst.instruction = THUMB_OP32 (inst.instruction);
9081 else
9082 inst.instruction = THUMB_OP16 (inst.instruction);
9083}
90e4755a 9084
c19d1205
ZW
9085static void
9086do_t_it (void)
9087{
9088 unsigned int cond = inst.operands[0].imm;
e27ec89e 9089
dfa9f0d5 9090 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9091 current_it_mask = (inst.instruction & 0xf) | 0x10;
9092 current_cc = cond;
9093
9094 /* If the condition is a negative condition, invert the mask. */
c19d1205 9095 if ((cond & 0x1) == 0x0)
90e4755a 9096 {
c19d1205 9097 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9098
c19d1205
ZW
9099 if ((mask & 0x7) == 0)
9100 /* no conversion needed */;
9101 else if ((mask & 0x3) == 0)
e27ec89e
PB
9102 mask ^= 0x8;
9103 else if ((mask & 0x1) == 0)
9104 mask ^= 0xC;
c19d1205 9105 else
e27ec89e 9106 mask ^= 0xE;
90e4755a 9107
e27ec89e
PB
9108 inst.instruction &= 0xfff0;
9109 inst.instruction |= mask;
c19d1205 9110 }
90e4755a 9111
c19d1205
ZW
9112 inst.instruction |= cond << 4;
9113}
90e4755a 9114
3c707909
PB
9115/* Helper function used for both push/pop and ldm/stm. */
9116static void
9117encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9118{
9119 bfd_boolean load;
9120
9121 load = (inst.instruction & (1 << 20)) != 0;
9122
9123 if (mask & (1 << 13))
9124 inst.error = _("SP not allowed in register list");
9125 if (load)
9126 {
9127 if (mask & (1 << 14)
9128 && mask & (1 << 15))
9129 inst.error = _("LR and PC should not both be in register list");
9130
9131 if ((mask & (1 << base)) != 0
9132 && writeback)
9133 as_warn (_("base register should not be in register list "
9134 "when written back"));
9135 }
9136 else
9137 {
9138 if (mask & (1 << 15))
9139 inst.error = _("PC not allowed in register list");
9140
9141 if (mask & (1 << base))
9142 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9143 }
9144
9145 if ((mask & (mask - 1)) == 0)
9146 {
9147 /* Single register transfers implemented as str/ldr. */
9148 if (writeback)
9149 {
9150 if (inst.instruction & (1 << 23))
9151 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9152 else
9153 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9154 }
9155 else
9156 {
9157 if (inst.instruction & (1 << 23))
9158 inst.instruction = 0x00800000; /* ia -> [base] */
9159 else
9160 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9161 }
9162
9163 inst.instruction |= 0xf8400000;
9164 if (load)
9165 inst.instruction |= 0x00100000;
9166
9167 mask = ffs(mask) - 1;
9168 mask <<= 12;
9169 }
9170 else if (writeback)
9171 inst.instruction |= WRITE_BACK;
9172
9173 inst.instruction |= mask;
9174 inst.instruction |= base << 16;
9175}
9176
c19d1205
ZW
9177static void
9178do_t_ldmstm (void)
9179{
9180 /* This really doesn't seem worth it. */
9181 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9182 _("expression too complex"));
9183 constraint (inst.operands[1].writeback,
9184 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9185
c19d1205
ZW
9186 if (unified_syntax)
9187 {
3c707909
PB
9188 bfd_boolean narrow;
9189 unsigned mask;
9190
9191 narrow = FALSE;
c19d1205
ZW
9192 /* See if we can use a 16-bit instruction. */
9193 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9194 && inst.size_req != 4
3c707909 9195 && !(inst.operands[1].imm & ~0xff))
90e4755a 9196 {
3c707909 9197 mask = 1 << inst.operands[0].reg;
90e4755a 9198
3c707909
PB
9199 if (inst.operands[0].reg <= 7
9200 && (inst.instruction == T_MNEM_stmia
9201 ? inst.operands[0].writeback
9202 : (inst.operands[0].writeback
9203 == !(inst.operands[1].imm & mask))))
90e4755a 9204 {
3c707909
PB
9205 if (inst.instruction == T_MNEM_stmia
9206 && (inst.operands[1].imm & mask)
9207 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9208 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9209 inst.operands[0].reg);
3c707909
PB
9210
9211 inst.instruction = THUMB_OP16 (inst.instruction);
9212 inst.instruction |= inst.operands[0].reg << 8;
9213 inst.instruction |= inst.operands[1].imm;
9214 narrow = TRUE;
90e4755a 9215 }
3c707909
PB
9216 else if (inst.operands[0] .reg == REG_SP
9217 && inst.operands[0].writeback)
90e4755a 9218 {
3c707909
PB
9219 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9220 ? T_MNEM_push : T_MNEM_pop);
9221 inst.instruction |= inst.operands[1].imm;
9222 narrow = TRUE;
90e4755a 9223 }
3c707909
PB
9224 }
9225
9226 if (!narrow)
9227 {
c19d1205
ZW
9228 if (inst.instruction < 0xffff)
9229 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909
PB
9230
9231 encode_thumb2_ldmstm(inst.operands[0].reg, inst.operands[1].imm,
9232 inst.operands[0].writeback);
90e4755a
RE
9233 }
9234 }
c19d1205 9235 else
90e4755a 9236 {
c19d1205
ZW
9237 constraint (inst.operands[0].reg > 7
9238 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9239 constraint (inst.instruction != T_MNEM_ldmia
9240 && inst.instruction != T_MNEM_stmia,
9241 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9242 if (inst.instruction == T_MNEM_stmia)
f03698e6 9243 {
c19d1205
ZW
9244 if (!inst.operands[0].writeback)
9245 as_warn (_("this instruction will write back the base register"));
9246 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9247 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9248 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9249 inst.operands[0].reg);
f03698e6 9250 }
c19d1205 9251 else
90e4755a 9252 {
c19d1205
ZW
9253 if (!inst.operands[0].writeback
9254 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9255 as_warn (_("this instruction will write back the base register"));
9256 else if (inst.operands[0].writeback
9257 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9258 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9259 }
9260
c19d1205
ZW
9261 inst.instruction = THUMB_OP16 (inst.instruction);
9262 inst.instruction |= inst.operands[0].reg << 8;
9263 inst.instruction |= inst.operands[1].imm;
9264 }
9265}
e28cd48c 9266
c19d1205
ZW
9267static void
9268do_t_ldrex (void)
9269{
9270 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9271 || inst.operands[1].postind || inst.operands[1].writeback
9272 || inst.operands[1].immisreg || inst.operands[1].shifted
9273 || inst.operands[1].negative,
01cfc07f 9274 BAD_ADDR_MODE);
e28cd48c 9275
c19d1205
ZW
9276 inst.instruction |= inst.operands[0].reg << 12;
9277 inst.instruction |= inst.operands[1].reg << 16;
9278 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9279}
e28cd48c 9280
c19d1205
ZW
9281static void
9282do_t_ldrexd (void)
9283{
9284 if (!inst.operands[1].present)
1cac9012 9285 {
c19d1205
ZW
9286 constraint (inst.operands[0].reg == REG_LR,
9287 _("r14 not allowed as first register "
9288 "when second register is omitted"));
9289 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9290 }
c19d1205
ZW
9291 constraint (inst.operands[0].reg == inst.operands[1].reg,
9292 BAD_OVERLAP);
b99bd4ef 9293
c19d1205
ZW
9294 inst.instruction |= inst.operands[0].reg << 12;
9295 inst.instruction |= inst.operands[1].reg << 8;
9296 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9297}
9298
9299static void
c19d1205 9300do_t_ldst (void)
b99bd4ef 9301{
0110f2b8
PB
9302 unsigned long opcode;
9303 int Rn;
9304
9305 opcode = inst.instruction;
c19d1205 9306 if (unified_syntax)
b99bd4ef 9307 {
53365c0d
PB
9308 if (!inst.operands[1].isreg)
9309 {
9310 if (opcode <= 0xffff)
9311 inst.instruction = THUMB_OP32 (opcode);
9312 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9313 return;
9314 }
0110f2b8
PB
9315 if (inst.operands[1].isreg
9316 && !inst.operands[1].writeback
c19d1205
ZW
9317 && !inst.operands[1].shifted && !inst.operands[1].postind
9318 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9319 && opcode <= 0xffff
9320 && inst.size_req != 4)
c19d1205 9321 {
0110f2b8
PB
9322 /* Insn may have a 16-bit form. */
9323 Rn = inst.operands[1].reg;
9324 if (inst.operands[1].immisreg)
9325 {
9326 inst.instruction = THUMB_OP16 (opcode);
9327 /* [Rn, Ri] */
9328 if (Rn <= 7 && inst.operands[1].imm <= 7)
9329 goto op16;
9330 }
9331 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9332 && opcode != T_MNEM_ldrsb)
9333 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9334 || (Rn == REG_SP && opcode == T_MNEM_str))
9335 {
9336 /* [Rn, #const] */
9337 if (Rn > 7)
9338 {
9339 if (Rn == REG_PC)
9340 {
9341 if (inst.reloc.pc_rel)
9342 opcode = T_MNEM_ldr_pc2;
9343 else
9344 opcode = T_MNEM_ldr_pc;
9345 }
9346 else
9347 {
9348 if (opcode == T_MNEM_ldr)
9349 opcode = T_MNEM_ldr_sp;
9350 else
9351 opcode = T_MNEM_str_sp;
9352 }
9353 inst.instruction = inst.operands[0].reg << 8;
9354 }
9355 else
9356 {
9357 inst.instruction = inst.operands[0].reg;
9358 inst.instruction |= inst.operands[1].reg << 3;
9359 }
9360 inst.instruction |= THUMB_OP16 (opcode);
9361 if (inst.size_req == 2)
9362 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9363 else
9364 inst.relax = opcode;
9365 return;
9366 }
c19d1205 9367 }
0110f2b8
PB
9368 /* Definitely a 32-bit variant. */
9369 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9370 inst.instruction |= inst.operands[0].reg << 12;
9371 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9372 return;
9373 }
9374
c19d1205
ZW
9375 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9376
9377 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9378 {
c19d1205
ZW
9379 /* Only [Rn,Rm] is acceptable. */
9380 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9381 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9382 || inst.operands[1].postind || inst.operands[1].shifted
9383 || inst.operands[1].negative,
9384 _("Thumb does not support this addressing mode"));
9385 inst.instruction = THUMB_OP16 (inst.instruction);
9386 goto op16;
b99bd4ef 9387 }
c19d1205
ZW
9388
9389 inst.instruction = THUMB_OP16 (inst.instruction);
9390 if (!inst.operands[1].isreg)
9391 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9392 return;
b99bd4ef 9393
c19d1205
ZW
9394 constraint (!inst.operands[1].preind
9395 || inst.operands[1].shifted
9396 || inst.operands[1].writeback,
9397 _("Thumb does not support this addressing mode"));
9398 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9399 {
c19d1205
ZW
9400 constraint (inst.instruction & 0x0600,
9401 _("byte or halfword not valid for base register"));
9402 constraint (inst.operands[1].reg == REG_PC
9403 && !(inst.instruction & THUMB_LOAD_BIT),
9404 _("r15 based store not allowed"));
9405 constraint (inst.operands[1].immisreg,
9406 _("invalid base register for register offset"));
b99bd4ef 9407
c19d1205
ZW
9408 if (inst.operands[1].reg == REG_PC)
9409 inst.instruction = T_OPCODE_LDR_PC;
9410 else if (inst.instruction & THUMB_LOAD_BIT)
9411 inst.instruction = T_OPCODE_LDR_SP;
9412 else
9413 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9414
c19d1205
ZW
9415 inst.instruction |= inst.operands[0].reg << 8;
9416 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9417 return;
9418 }
90e4755a 9419
c19d1205
ZW
9420 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9421 if (!inst.operands[1].immisreg)
9422 {
9423 /* Immediate offset. */
9424 inst.instruction |= inst.operands[0].reg;
9425 inst.instruction |= inst.operands[1].reg << 3;
9426 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9427 return;
9428 }
90e4755a 9429
c19d1205
ZW
9430 /* Register offset. */
9431 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9432 constraint (inst.operands[1].negative,
9433 _("Thumb does not support this addressing mode"));
90e4755a 9434
c19d1205
ZW
9435 op16:
9436 switch (inst.instruction)
9437 {
9438 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9439 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9440 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9441 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9442 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9443 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9444 case 0x5600 /* ldrsb */:
9445 case 0x5e00 /* ldrsh */: break;
9446 default: abort ();
9447 }
90e4755a 9448
c19d1205
ZW
9449 inst.instruction |= inst.operands[0].reg;
9450 inst.instruction |= inst.operands[1].reg << 3;
9451 inst.instruction |= inst.operands[1].imm << 6;
9452}
90e4755a 9453
c19d1205
ZW
9454static void
9455do_t_ldstd (void)
9456{
9457 if (!inst.operands[1].present)
b99bd4ef 9458 {
c19d1205
ZW
9459 inst.operands[1].reg = inst.operands[0].reg + 1;
9460 constraint (inst.operands[0].reg == REG_LR,
9461 _("r14 not allowed here"));
b99bd4ef 9462 }
c19d1205
ZW
9463 inst.instruction |= inst.operands[0].reg << 12;
9464 inst.instruction |= inst.operands[1].reg << 8;
9465 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9466
b99bd4ef
NC
9467}
9468
c19d1205
ZW
9469static void
9470do_t_ldstt (void)
9471{
9472 inst.instruction |= inst.operands[0].reg << 12;
9473 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9474}
a737bd4d 9475
b99bd4ef 9476static void
c19d1205 9477do_t_mla (void)
b99bd4ef 9478{
c19d1205
ZW
9479 inst.instruction |= inst.operands[0].reg << 8;
9480 inst.instruction |= inst.operands[1].reg << 16;
9481 inst.instruction |= inst.operands[2].reg;
9482 inst.instruction |= inst.operands[3].reg << 12;
9483}
b99bd4ef 9484
c19d1205
ZW
9485static void
9486do_t_mlal (void)
9487{
9488 inst.instruction |= inst.operands[0].reg << 12;
9489 inst.instruction |= inst.operands[1].reg << 8;
9490 inst.instruction |= inst.operands[2].reg << 16;
9491 inst.instruction |= inst.operands[3].reg;
9492}
b99bd4ef 9493
c19d1205
ZW
9494static void
9495do_t_mov_cmp (void)
9496{
9497 if (unified_syntax)
b99bd4ef 9498 {
c19d1205
ZW
9499 int r0off = (inst.instruction == T_MNEM_mov
9500 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9501 unsigned long opcode;
3d388997
PB
9502 bfd_boolean narrow;
9503 bfd_boolean low_regs;
9504
9505 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9506 opcode = inst.instruction;
3d388997 9507 if (current_it_mask)
0110f2b8 9508 narrow = opcode != T_MNEM_movs;
3d388997 9509 else
0110f2b8 9510 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9511 if (inst.size_req == 4
9512 || inst.operands[1].shifted)
9513 narrow = FALSE;
9514
efd81785
PB
9515 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9516 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9517 && !inst.operands[1].shifted
9518 && inst.operands[0].reg == REG_PC
9519 && inst.operands[1].reg == REG_LR)
9520 {
9521 inst.instruction = T2_SUBS_PC_LR;
9522 return;
9523 }
9524
c19d1205
ZW
9525 if (!inst.operands[1].isreg)
9526 {
0110f2b8
PB
9527 /* Immediate operand. */
9528 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9529 narrow = 0;
9530 if (low_regs && narrow)
9531 {
9532 inst.instruction = THUMB_OP16 (opcode);
9533 inst.instruction |= inst.operands[0].reg << 8;
9534 if (inst.size_req == 2)
9535 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9536 else
9537 inst.relax = opcode;
9538 }
9539 else
9540 {
9541 inst.instruction = THUMB_OP32 (inst.instruction);
9542 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9543 inst.instruction |= inst.operands[0].reg << r0off;
9544 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9545 }
c19d1205 9546 }
3d388997 9547 else if (!narrow)
c19d1205
ZW
9548 {
9549 inst.instruction = THUMB_OP32 (inst.instruction);
9550 inst.instruction |= inst.operands[0].reg << r0off;
9551 encode_thumb32_shifted_operand (1);
9552 }
9553 else
9554 switch (inst.instruction)
9555 {
9556 case T_MNEM_mov:
9557 inst.instruction = T_OPCODE_MOV_HR;
9558 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9559 inst.instruction |= (inst.operands[0].reg & 0x7);
9560 inst.instruction |= inst.operands[1].reg << 3;
9561 break;
b99bd4ef 9562
c19d1205
ZW
9563 case T_MNEM_movs:
9564 /* We know we have low registers at this point.
9565 Generate ADD Rd, Rs, #0. */
9566 inst.instruction = T_OPCODE_ADD_I3;
9567 inst.instruction |= inst.operands[0].reg;
9568 inst.instruction |= inst.operands[1].reg << 3;
9569 break;
9570
9571 case T_MNEM_cmp:
3d388997 9572 if (low_regs)
c19d1205
ZW
9573 {
9574 inst.instruction = T_OPCODE_CMP_LR;
9575 inst.instruction |= inst.operands[0].reg;
9576 inst.instruction |= inst.operands[1].reg << 3;
9577 }
9578 else
9579 {
9580 inst.instruction = T_OPCODE_CMP_HR;
9581 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9582 inst.instruction |= (inst.operands[0].reg & 0x7);
9583 inst.instruction |= inst.operands[1].reg << 3;
9584 }
9585 break;
9586 }
b99bd4ef
NC
9587 return;
9588 }
9589
c19d1205
ZW
9590 inst.instruction = THUMB_OP16 (inst.instruction);
9591 if (inst.operands[1].isreg)
b99bd4ef 9592 {
c19d1205 9593 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9594 {
c19d1205
ZW
9595 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9596 since a MOV instruction produces unpredictable results. */
9597 if (inst.instruction == T_OPCODE_MOV_I8)
9598 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9599 else
c19d1205 9600 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9601
c19d1205
ZW
9602 inst.instruction |= inst.operands[0].reg;
9603 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9604 }
9605 else
9606 {
c19d1205
ZW
9607 if (inst.instruction == T_OPCODE_MOV_I8)
9608 inst.instruction = T_OPCODE_MOV_HR;
9609 else
9610 inst.instruction = T_OPCODE_CMP_HR;
9611 do_t_cpy ();
b99bd4ef
NC
9612 }
9613 }
c19d1205 9614 else
b99bd4ef 9615 {
c19d1205
ZW
9616 constraint (inst.operands[0].reg > 7,
9617 _("only lo regs allowed with immediate"));
9618 inst.instruction |= inst.operands[0].reg << 8;
9619 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9620 }
9621}
b99bd4ef 9622
c19d1205
ZW
9623static void
9624do_t_mov16 (void)
9625{
b6895b4f
PB
9626 bfd_vma imm;
9627 bfd_boolean top;
9628
9629 top = (inst.instruction & 0x00800000) != 0;
9630 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9631 {
9632 constraint (top, _(":lower16: not allowed this instruction"));
9633 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9634 }
9635 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9636 {
9637 constraint (!top, _(":upper16: not allowed this instruction"));
9638 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9639 }
9640
c19d1205 9641 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9642 if (inst.reloc.type == BFD_RELOC_UNUSED)
9643 {
9644 imm = inst.reloc.exp.X_add_number;
9645 inst.instruction |= (imm & 0xf000) << 4;
9646 inst.instruction |= (imm & 0x0800) << 15;
9647 inst.instruction |= (imm & 0x0700) << 4;
9648 inst.instruction |= (imm & 0x00ff);
9649 }
c19d1205 9650}
b99bd4ef 9651
c19d1205
ZW
9652static void
9653do_t_mvn_tst (void)
9654{
9655 if (unified_syntax)
9656 {
9657 int r0off = (inst.instruction == T_MNEM_mvn
9658 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9659 bfd_boolean narrow;
9660
9661 if (inst.size_req == 4
9662 || inst.instruction > 0xffff
9663 || inst.operands[1].shifted
9664 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9665 narrow = FALSE;
9666 else if (inst.instruction == T_MNEM_cmn)
9667 narrow = TRUE;
9668 else if (THUMB_SETS_FLAGS (inst.instruction))
9669 narrow = (current_it_mask == 0);
9670 else
9671 narrow = (current_it_mask != 0);
9672
c19d1205 9673 if (!inst.operands[1].isreg)
b99bd4ef 9674 {
c19d1205
ZW
9675 /* For an immediate, we always generate a 32-bit opcode;
9676 section relaxation will shrink it later if possible. */
9677 if (inst.instruction < 0xffff)
9678 inst.instruction = THUMB_OP32 (inst.instruction);
9679 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9680 inst.instruction |= inst.operands[0].reg << r0off;
9681 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9682 }
c19d1205 9683 else
b99bd4ef 9684 {
c19d1205 9685 /* See if we can do this with a 16-bit instruction. */
3d388997 9686 if (narrow)
b99bd4ef 9687 {
c19d1205
ZW
9688 inst.instruction = THUMB_OP16 (inst.instruction);
9689 inst.instruction |= inst.operands[0].reg;
9690 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9691 }
c19d1205 9692 else
b99bd4ef 9693 {
c19d1205
ZW
9694 constraint (inst.operands[1].shifted
9695 && inst.operands[1].immisreg,
9696 _("shift must be constant"));
9697 if (inst.instruction < 0xffff)
9698 inst.instruction = THUMB_OP32 (inst.instruction);
9699 inst.instruction |= inst.operands[0].reg << r0off;
9700 encode_thumb32_shifted_operand (1);
b99bd4ef 9701 }
b99bd4ef
NC
9702 }
9703 }
9704 else
9705 {
c19d1205
ZW
9706 constraint (inst.instruction > 0xffff
9707 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9708 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9709 _("unshifted register required"));
9710 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9711 BAD_HIREG);
b99bd4ef 9712
c19d1205
ZW
9713 inst.instruction = THUMB_OP16 (inst.instruction);
9714 inst.instruction |= inst.operands[0].reg;
9715 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9716 }
b99bd4ef
NC
9717}
9718
b05fe5cf 9719static void
c19d1205 9720do_t_mrs (void)
b05fe5cf 9721{
62b3e311 9722 int flags;
037e8744
JB
9723
9724 if (do_vfp_nsyn_mrs () == SUCCESS)
9725 return;
9726
62b3e311
PB
9727 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9728 if (flags == 0)
9729 {
9730 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9731 _("selected processor does not support "
9732 "requested special purpose register"));
9733 }
9734 else
9735 {
9736 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9737 _("selected processor does not support "
9738 "requested special purpose register %x"));
9739 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9740 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9741 _("'CPSR' or 'SPSR' expected"));
9742 }
9743
c19d1205 9744 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9745 inst.instruction |= (flags & SPSR_BIT) >> 2;
9746 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9747}
b05fe5cf 9748
c19d1205
ZW
9749static void
9750do_t_msr (void)
9751{
62b3e311
PB
9752 int flags;
9753
037e8744
JB
9754 if (do_vfp_nsyn_msr () == SUCCESS)
9755 return;
9756
c19d1205
ZW
9757 constraint (!inst.operands[1].isreg,
9758 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9759 flags = inst.operands[0].imm;
9760 if (flags & ~0xff)
9761 {
9762 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9763 _("selected processor does not support "
9764 "requested special purpose register"));
9765 }
9766 else
9767 {
9768 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9769 _("selected processor does not support "
9770 "requested special purpose register"));
9771 flags |= PSR_f;
9772 }
9773 inst.instruction |= (flags & SPSR_BIT) >> 2;
9774 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9775 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9776 inst.instruction |= inst.operands[1].reg << 16;
9777}
b05fe5cf 9778
c19d1205
ZW
9779static void
9780do_t_mul (void)
9781{
9782 if (!inst.operands[2].present)
9783 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9784
c19d1205
ZW
9785 /* There is no 32-bit MULS and no 16-bit MUL. */
9786 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9787 {
c19d1205
ZW
9788 inst.instruction = THUMB_OP32 (inst.instruction);
9789 inst.instruction |= inst.operands[0].reg << 8;
9790 inst.instruction |= inst.operands[1].reg << 16;
9791 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9792 }
c19d1205 9793 else
b05fe5cf 9794 {
c19d1205
ZW
9795 constraint (!unified_syntax
9796 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9797 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9798 BAD_HIREG);
b05fe5cf 9799
c19d1205
ZW
9800 inst.instruction = THUMB_OP16 (inst.instruction);
9801 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9802
c19d1205
ZW
9803 if (inst.operands[0].reg == inst.operands[1].reg)
9804 inst.instruction |= inst.operands[2].reg << 3;
9805 else if (inst.operands[0].reg == inst.operands[2].reg)
9806 inst.instruction |= inst.operands[1].reg << 3;
9807 else
9808 constraint (1, _("dest must overlap one source register"));
9809 }
9810}
b05fe5cf 9811
c19d1205
ZW
9812static void
9813do_t_mull (void)
9814{
9815 inst.instruction |= inst.operands[0].reg << 12;
9816 inst.instruction |= inst.operands[1].reg << 8;
9817 inst.instruction |= inst.operands[2].reg << 16;
9818 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9819
c19d1205
ZW
9820 if (inst.operands[0].reg == inst.operands[1].reg)
9821 as_tsktsk (_("rdhi and rdlo must be different"));
9822}
b05fe5cf 9823
c19d1205
ZW
9824static void
9825do_t_nop (void)
9826{
9827 if (unified_syntax)
9828 {
9829 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9830 {
c19d1205
ZW
9831 inst.instruction = THUMB_OP32 (inst.instruction);
9832 inst.instruction |= inst.operands[0].imm;
9833 }
9834 else
9835 {
9836 inst.instruction = THUMB_OP16 (inst.instruction);
9837 inst.instruction |= inst.operands[0].imm << 4;
9838 }
9839 }
9840 else
9841 {
9842 constraint (inst.operands[0].present,
9843 _("Thumb does not support NOP with hints"));
9844 inst.instruction = 0x46c0;
9845 }
9846}
b05fe5cf 9847
c19d1205
ZW
9848static void
9849do_t_neg (void)
9850{
9851 if (unified_syntax)
9852 {
3d388997
PB
9853 bfd_boolean narrow;
9854
9855 if (THUMB_SETS_FLAGS (inst.instruction))
9856 narrow = (current_it_mask == 0);
9857 else
9858 narrow = (current_it_mask != 0);
9859 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9860 narrow = FALSE;
9861 if (inst.size_req == 4)
9862 narrow = FALSE;
9863
9864 if (!narrow)
c19d1205
ZW
9865 {
9866 inst.instruction = THUMB_OP32 (inst.instruction);
9867 inst.instruction |= inst.operands[0].reg << 8;
9868 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9869 }
9870 else
9871 {
c19d1205
ZW
9872 inst.instruction = THUMB_OP16 (inst.instruction);
9873 inst.instruction |= inst.operands[0].reg;
9874 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9875 }
9876 }
9877 else
9878 {
c19d1205
ZW
9879 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9880 BAD_HIREG);
9881 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9882
9883 inst.instruction = THUMB_OP16 (inst.instruction);
9884 inst.instruction |= inst.operands[0].reg;
9885 inst.instruction |= inst.operands[1].reg << 3;
9886 }
9887}
9888
9889static void
9890do_t_pkhbt (void)
9891{
9892 inst.instruction |= inst.operands[0].reg << 8;
9893 inst.instruction |= inst.operands[1].reg << 16;
9894 inst.instruction |= inst.operands[2].reg;
9895 if (inst.operands[3].present)
9896 {
9897 unsigned int val = inst.reloc.exp.X_add_number;
9898 constraint (inst.reloc.exp.X_op != O_constant,
9899 _("expression too complex"));
9900 inst.instruction |= (val & 0x1c) << 10;
9901 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9902 }
c19d1205 9903}
b05fe5cf 9904
c19d1205
ZW
9905static void
9906do_t_pkhtb (void)
9907{
9908 if (!inst.operands[3].present)
9909 inst.instruction &= ~0x00000020;
9910 do_t_pkhbt ();
b05fe5cf
ZW
9911}
9912
c19d1205
ZW
9913static void
9914do_t_pld (void)
9915{
9916 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9917}
b05fe5cf 9918
c19d1205
ZW
9919static void
9920do_t_push_pop (void)
b99bd4ef 9921{
e9f89963
PB
9922 unsigned mask;
9923
c19d1205
ZW
9924 constraint (inst.operands[0].writeback,
9925 _("push/pop do not support {reglist}^"));
9926 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9927 _("expression too complex"));
b99bd4ef 9928
e9f89963
PB
9929 mask = inst.operands[0].imm;
9930 if ((mask & ~0xff) == 0)
3c707909 9931 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 9932 else if ((inst.instruction == T_MNEM_push
e9f89963 9933 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 9934 || (inst.instruction == T_MNEM_pop
e9f89963 9935 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 9936 {
c19d1205
ZW
9937 inst.instruction = THUMB_OP16 (inst.instruction);
9938 inst.instruction |= THUMB_PP_PC_LR;
3c707909 9939 inst.instruction |= mask & 0xff;
c19d1205
ZW
9940 }
9941 else if (unified_syntax)
9942 {
3c707909
PB
9943 inst.instruction = THUMB_OP32 (inst.instruction);
9944 encode_thumb2_ldmstm(13, mask, TRUE);
c19d1205
ZW
9945 }
9946 else
9947 {
9948 inst.error = _("invalid register list to push/pop instruction");
9949 return;
9950 }
c19d1205 9951}
b99bd4ef 9952
c19d1205
ZW
9953static void
9954do_t_rbit (void)
9955{
9956 inst.instruction |= inst.operands[0].reg << 8;
9957 inst.instruction |= inst.operands[1].reg << 16;
9958}
b99bd4ef 9959
c19d1205
ZW
9960static void
9961do_t_rev (void)
9962{
9963 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9964 && inst.size_req != 4)
9965 {
9966 inst.instruction = THUMB_OP16 (inst.instruction);
9967 inst.instruction |= inst.operands[0].reg;
9968 inst.instruction |= inst.operands[1].reg << 3;
9969 }
9970 else if (unified_syntax)
9971 {
9972 inst.instruction = THUMB_OP32 (inst.instruction);
9973 inst.instruction |= inst.operands[0].reg << 8;
9974 inst.instruction |= inst.operands[1].reg << 16;
9975 inst.instruction |= inst.operands[1].reg;
9976 }
9977 else
9978 inst.error = BAD_HIREG;
9979}
b99bd4ef 9980
c19d1205
ZW
9981static void
9982do_t_rsb (void)
9983{
9984 int Rd, Rs;
b99bd4ef 9985
c19d1205
ZW
9986 Rd = inst.operands[0].reg;
9987 Rs = (inst.operands[1].present
9988 ? inst.operands[1].reg /* Rd, Rs, foo */
9989 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 9990
c19d1205
ZW
9991 inst.instruction |= Rd << 8;
9992 inst.instruction |= Rs << 16;
9993 if (!inst.operands[2].isreg)
9994 {
026d3abb
PB
9995 bfd_boolean narrow;
9996
9997 if ((inst.instruction & 0x00100000) != 0)
9998 narrow = (current_it_mask == 0);
9999 else
10000 narrow = (current_it_mask != 0);
10001
10002 if (Rd > 7 || Rs > 7)
10003 narrow = FALSE;
10004
10005 if (inst.size_req == 4 || !unified_syntax)
10006 narrow = FALSE;
10007
10008 if (inst.reloc.exp.X_op != O_constant
10009 || inst.reloc.exp.X_add_number != 0)
10010 narrow = FALSE;
10011
10012 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10013 relaxation, but it doesn't seem worth the hassle. */
10014 if (narrow)
10015 {
10016 inst.reloc.type = BFD_RELOC_UNUSED;
10017 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10018 inst.instruction |= Rs << 3;
10019 inst.instruction |= Rd;
10020 }
10021 else
10022 {
10023 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10024 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10025 }
c19d1205
ZW
10026 }
10027 else
10028 encode_thumb32_shifted_operand (2);
10029}
b99bd4ef 10030
c19d1205
ZW
10031static void
10032do_t_setend (void)
10033{
dfa9f0d5 10034 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10035 if (inst.operands[0].imm)
10036 inst.instruction |= 0x8;
10037}
b99bd4ef 10038
c19d1205
ZW
10039static void
10040do_t_shift (void)
10041{
10042 if (!inst.operands[1].present)
10043 inst.operands[1].reg = inst.operands[0].reg;
10044
10045 if (unified_syntax)
10046 {
3d388997
PB
10047 bfd_boolean narrow;
10048 int shift_kind;
10049
10050 switch (inst.instruction)
10051 {
10052 case T_MNEM_asr:
10053 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10054 case T_MNEM_lsl:
10055 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10056 case T_MNEM_lsr:
10057 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10058 case T_MNEM_ror:
10059 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10060 default: abort ();
10061 }
10062
10063 if (THUMB_SETS_FLAGS (inst.instruction))
10064 narrow = (current_it_mask == 0);
10065 else
10066 narrow = (current_it_mask != 0);
10067 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10068 narrow = FALSE;
10069 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10070 narrow = FALSE;
10071 if (inst.operands[2].isreg
10072 && (inst.operands[1].reg != inst.operands[0].reg
10073 || inst.operands[2].reg > 7))
10074 narrow = FALSE;
10075 if (inst.size_req == 4)
10076 narrow = FALSE;
10077
10078 if (!narrow)
c19d1205
ZW
10079 {
10080 if (inst.operands[2].isreg)
b99bd4ef 10081 {
c19d1205
ZW
10082 inst.instruction = THUMB_OP32 (inst.instruction);
10083 inst.instruction |= inst.operands[0].reg << 8;
10084 inst.instruction |= inst.operands[1].reg << 16;
10085 inst.instruction |= inst.operands[2].reg;
10086 }
10087 else
10088 {
10089 inst.operands[1].shifted = 1;
3d388997 10090 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10091 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10092 ? T_MNEM_movs : T_MNEM_mov);
10093 inst.instruction |= inst.operands[0].reg << 8;
10094 encode_thumb32_shifted_operand (1);
10095 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10096 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10097 }
10098 }
10099 else
10100 {
c19d1205 10101 if (inst.operands[2].isreg)
b99bd4ef 10102 {
3d388997 10103 switch (shift_kind)
b99bd4ef 10104 {
3d388997
PB
10105 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10106 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10107 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10108 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10109 default: abort ();
b99bd4ef 10110 }
c19d1205
ZW
10111
10112 inst.instruction |= inst.operands[0].reg;
10113 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10114 }
10115 else
10116 {
3d388997 10117 switch (shift_kind)
b99bd4ef 10118 {
3d388997
PB
10119 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10120 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10121 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10122 default: abort ();
b99bd4ef 10123 }
c19d1205
ZW
10124 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10125 inst.instruction |= inst.operands[0].reg;
10126 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10127 }
10128 }
c19d1205
ZW
10129 }
10130 else
10131 {
10132 constraint (inst.operands[0].reg > 7
10133 || inst.operands[1].reg > 7, BAD_HIREG);
10134 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10135
c19d1205
ZW
10136 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10137 {
10138 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10139 constraint (inst.operands[0].reg != inst.operands[1].reg,
10140 _("source1 and dest must be same register"));
b99bd4ef 10141
c19d1205
ZW
10142 switch (inst.instruction)
10143 {
10144 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10145 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10146 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10147 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10148 default: abort ();
10149 }
10150
10151 inst.instruction |= inst.operands[0].reg;
10152 inst.instruction |= inst.operands[2].reg << 3;
10153 }
10154 else
b99bd4ef 10155 {
c19d1205
ZW
10156 switch (inst.instruction)
10157 {
10158 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10159 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10160 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10161 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10162 default: abort ();
10163 }
10164 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10165 inst.instruction |= inst.operands[0].reg;
10166 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10167 }
10168 }
b99bd4ef
NC
10169}
10170
10171static void
c19d1205 10172do_t_simd (void)
b99bd4ef 10173{
c19d1205
ZW
10174 inst.instruction |= inst.operands[0].reg << 8;
10175 inst.instruction |= inst.operands[1].reg << 16;
10176 inst.instruction |= inst.operands[2].reg;
10177}
b99bd4ef 10178
c19d1205 10179static void
3eb17e6b 10180do_t_smc (void)
c19d1205
ZW
10181{
10182 unsigned int value = inst.reloc.exp.X_add_number;
10183 constraint (inst.reloc.exp.X_op != O_constant,
10184 _("expression too complex"));
10185 inst.reloc.type = BFD_RELOC_UNUSED;
10186 inst.instruction |= (value & 0xf000) >> 12;
10187 inst.instruction |= (value & 0x0ff0);
10188 inst.instruction |= (value & 0x000f) << 16;
10189}
b99bd4ef 10190
c19d1205
ZW
10191static void
10192do_t_ssat (void)
10193{
10194 inst.instruction |= inst.operands[0].reg << 8;
10195 inst.instruction |= inst.operands[1].imm - 1;
10196 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10197
c19d1205 10198 if (inst.operands[3].present)
b99bd4ef 10199 {
c19d1205
ZW
10200 constraint (inst.reloc.exp.X_op != O_constant,
10201 _("expression too complex"));
b99bd4ef 10202
c19d1205 10203 if (inst.reloc.exp.X_add_number != 0)
6189168b 10204 {
c19d1205
ZW
10205 if (inst.operands[3].shift_kind == SHIFT_ASR)
10206 inst.instruction |= 0x00200000; /* sh bit */
10207 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10208 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10209 }
c19d1205 10210 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10211 }
b99bd4ef
NC
10212}
10213
0dd132b6 10214static void
c19d1205 10215do_t_ssat16 (void)
0dd132b6 10216{
c19d1205
ZW
10217 inst.instruction |= inst.operands[0].reg << 8;
10218 inst.instruction |= inst.operands[1].imm - 1;
10219 inst.instruction |= inst.operands[2].reg << 16;
10220}
0dd132b6 10221
c19d1205
ZW
10222static void
10223do_t_strex (void)
10224{
10225 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10226 || inst.operands[2].postind || inst.operands[2].writeback
10227 || inst.operands[2].immisreg || inst.operands[2].shifted
10228 || inst.operands[2].negative,
01cfc07f 10229 BAD_ADDR_MODE);
0dd132b6 10230
c19d1205
ZW
10231 inst.instruction |= inst.operands[0].reg << 8;
10232 inst.instruction |= inst.operands[1].reg << 12;
10233 inst.instruction |= inst.operands[2].reg << 16;
10234 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10235}
10236
b99bd4ef 10237static void
c19d1205 10238do_t_strexd (void)
b99bd4ef 10239{
c19d1205
ZW
10240 if (!inst.operands[2].present)
10241 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10242
c19d1205
ZW
10243 constraint (inst.operands[0].reg == inst.operands[1].reg
10244 || inst.operands[0].reg == inst.operands[2].reg
10245 || inst.operands[0].reg == inst.operands[3].reg
10246 || inst.operands[1].reg == inst.operands[2].reg,
10247 BAD_OVERLAP);
b99bd4ef 10248
c19d1205
ZW
10249 inst.instruction |= inst.operands[0].reg;
10250 inst.instruction |= inst.operands[1].reg << 12;
10251 inst.instruction |= inst.operands[2].reg << 8;
10252 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10253}
10254
10255static void
c19d1205 10256do_t_sxtah (void)
b99bd4ef 10257{
c19d1205
ZW
10258 inst.instruction |= inst.operands[0].reg << 8;
10259 inst.instruction |= inst.operands[1].reg << 16;
10260 inst.instruction |= inst.operands[2].reg;
10261 inst.instruction |= inst.operands[3].imm << 4;
10262}
b99bd4ef 10263
c19d1205
ZW
10264static void
10265do_t_sxth (void)
10266{
10267 if (inst.instruction <= 0xffff && inst.size_req != 4
10268 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10269 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10270 {
c19d1205
ZW
10271 inst.instruction = THUMB_OP16 (inst.instruction);
10272 inst.instruction |= inst.operands[0].reg;
10273 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10274 }
c19d1205 10275 else if (unified_syntax)
b99bd4ef 10276 {
c19d1205
ZW
10277 if (inst.instruction <= 0xffff)
10278 inst.instruction = THUMB_OP32 (inst.instruction);
10279 inst.instruction |= inst.operands[0].reg << 8;
10280 inst.instruction |= inst.operands[1].reg;
10281 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10282 }
c19d1205 10283 else
b99bd4ef 10284 {
c19d1205
ZW
10285 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10286 _("Thumb encoding does not support rotation"));
10287 constraint (1, BAD_HIREG);
b99bd4ef 10288 }
c19d1205 10289}
b99bd4ef 10290
c19d1205
ZW
10291static void
10292do_t_swi (void)
10293{
10294 inst.reloc.type = BFD_RELOC_ARM_SWI;
10295}
b99bd4ef 10296
92e90b6e
PB
10297static void
10298do_t_tb (void)
10299{
10300 int half;
10301
10302 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10303 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10304 constraint (inst.operands[0].immisreg,
10305 _("instruction requires register index"));
92e90b6e
PB
10306 constraint (inst.operands[0].imm == 15,
10307 _("PC is not a valid index register"));
10308 constraint (!half && inst.operands[0].shifted,
10309 _("instruction does not allow shifted index"));
92e90b6e
PB
10310 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10311}
10312
c19d1205
ZW
10313static void
10314do_t_usat (void)
10315{
10316 inst.instruction |= inst.operands[0].reg << 8;
10317 inst.instruction |= inst.operands[1].imm;
10318 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10319
c19d1205 10320 if (inst.operands[3].present)
b99bd4ef 10321 {
c19d1205
ZW
10322 constraint (inst.reloc.exp.X_op != O_constant,
10323 _("expression too complex"));
10324 if (inst.reloc.exp.X_add_number != 0)
10325 {
10326 if (inst.operands[3].shift_kind == SHIFT_ASR)
10327 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10328
c19d1205
ZW
10329 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10330 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10331 }
10332 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10333 }
b99bd4ef
NC
10334}
10335
10336static void
c19d1205 10337do_t_usat16 (void)
b99bd4ef 10338{
c19d1205
ZW
10339 inst.instruction |= inst.operands[0].reg << 8;
10340 inst.instruction |= inst.operands[1].imm;
10341 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10342}
c19d1205 10343
5287ad62
JB
10344/* Neon instruction encoder helpers. */
10345
10346/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10347
5287ad62
JB
10348/* An "invalid" code for the following tables. */
10349#define N_INV -1u
10350
10351struct neon_tab_entry
b99bd4ef 10352{
5287ad62
JB
10353 unsigned integer;
10354 unsigned float_or_poly;
10355 unsigned scalar_or_imm;
10356};
10357
10358/* Map overloaded Neon opcodes to their respective encodings. */
10359#define NEON_ENC_TAB \
10360 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10361 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10362 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10363 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10364 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10365 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10366 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10367 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10368 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10369 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10370 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10371 /* Register variants of the following two instructions are encoded as
10372 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10373 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10374 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10375 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10376 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10377 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10378 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10379 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10380 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10381 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10382 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10383 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10384 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10385 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10386 X(vshl, 0x0000400, N_INV, 0x0800510), \
10387 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10388 X(vand, 0x0000110, N_INV, 0x0800030), \
10389 X(vbic, 0x0100110, N_INV, 0x0800030), \
10390 X(veor, 0x1000110, N_INV, N_INV), \
10391 X(vorn, 0x0300110, N_INV, 0x0800010), \
10392 X(vorr, 0x0200110, N_INV, 0x0800010), \
10393 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10394 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10395 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10396 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10397 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10398 X(vst1, 0x0000000, 0x0800000, N_INV), \
10399 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10400 X(vst2, 0x0000100, 0x0800100, N_INV), \
10401 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10402 X(vst3, 0x0000200, 0x0800200, N_INV), \
10403 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10404 X(vst4, 0x0000300, 0x0800300, N_INV), \
10405 X(vmovn, 0x1b20200, N_INV, N_INV), \
10406 X(vtrn, 0x1b20080, N_INV, N_INV), \
10407 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10408 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10409 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10410 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10411 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10412 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10413 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10414 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10415 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10416
10417enum neon_opc
10418{
10419#define X(OPC,I,F,S) N_MNEM_##OPC
10420NEON_ENC_TAB
10421#undef X
10422};
b99bd4ef 10423
5287ad62
JB
10424static const struct neon_tab_entry neon_enc_tab[] =
10425{
10426#define X(OPC,I,F,S) { (I), (F), (S) }
10427NEON_ENC_TAB
10428#undef X
10429};
b99bd4ef 10430
5287ad62
JB
10431#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10432#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10433#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10434#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10435#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10436#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10437#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10438#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10439#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10440#define NEON_ENC_SINGLE(X) \
10441 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10442#define NEON_ENC_DOUBLE(X) \
10443 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10444
037e8744
JB
10445/* Define shapes for instruction operands. The following mnemonic characters
10446 are used in this table:
5287ad62 10447
037e8744 10448 F - VFP S<n> register
5287ad62
JB
10449 D - Neon D<n> register
10450 Q - Neon Q<n> register
10451 I - Immediate
10452 S - Scalar
10453 R - ARM register
10454 L - D<n> register list
037e8744
JB
10455
10456 This table is used to generate various data:
10457 - enumerations of the form NS_DDR to be used as arguments to
10458 neon_select_shape.
10459 - a table classifying shapes into single, double, quad, mixed.
10460 - a table used to drive neon_select_shape.
5287ad62 10461*/
b99bd4ef 10462
037e8744
JB
10463#define NEON_SHAPE_DEF \
10464 X(3, (D, D, D), DOUBLE), \
10465 X(3, (Q, Q, Q), QUAD), \
10466 X(3, (D, D, I), DOUBLE), \
10467 X(3, (Q, Q, I), QUAD), \
10468 X(3, (D, D, S), DOUBLE), \
10469 X(3, (Q, Q, S), QUAD), \
10470 X(2, (D, D), DOUBLE), \
10471 X(2, (Q, Q), QUAD), \
10472 X(2, (D, S), DOUBLE), \
10473 X(2, (Q, S), QUAD), \
10474 X(2, (D, R), DOUBLE), \
10475 X(2, (Q, R), QUAD), \
10476 X(2, (D, I), DOUBLE), \
10477 X(2, (Q, I), QUAD), \
10478 X(3, (D, L, D), DOUBLE), \
10479 X(2, (D, Q), MIXED), \
10480 X(2, (Q, D), MIXED), \
10481 X(3, (D, Q, I), MIXED), \
10482 X(3, (Q, D, I), MIXED), \
10483 X(3, (Q, D, D), MIXED), \
10484 X(3, (D, Q, Q), MIXED), \
10485 X(3, (Q, Q, D), MIXED), \
10486 X(3, (Q, D, S), MIXED), \
10487 X(3, (D, Q, S), MIXED), \
10488 X(4, (D, D, D, I), DOUBLE), \
10489 X(4, (Q, Q, Q, I), QUAD), \
10490 X(2, (F, F), SINGLE), \
10491 X(3, (F, F, F), SINGLE), \
10492 X(2, (F, I), SINGLE), \
10493 X(2, (F, D), MIXED), \
10494 X(2, (D, F), MIXED), \
10495 X(3, (F, F, I), MIXED), \
10496 X(4, (R, R, F, F), SINGLE), \
10497 X(4, (F, F, R, R), SINGLE), \
10498 X(3, (D, R, R), DOUBLE), \
10499 X(3, (R, R, D), DOUBLE), \
10500 X(2, (S, R), SINGLE), \
10501 X(2, (R, S), SINGLE), \
10502 X(2, (F, R), SINGLE), \
10503 X(2, (R, F), SINGLE)
10504
10505#define S2(A,B) NS_##A##B
10506#define S3(A,B,C) NS_##A##B##C
10507#define S4(A,B,C,D) NS_##A##B##C##D
10508
10509#define X(N, L, C) S##N L
10510
5287ad62
JB
10511enum neon_shape
10512{
037e8744
JB
10513 NEON_SHAPE_DEF,
10514 NS_NULL
5287ad62 10515};
b99bd4ef 10516
037e8744
JB
10517#undef X
10518#undef S2
10519#undef S3
10520#undef S4
10521
10522enum neon_shape_class
10523{
10524 SC_SINGLE,
10525 SC_DOUBLE,
10526 SC_QUAD,
10527 SC_MIXED
10528};
10529
10530#define X(N, L, C) SC_##C
10531
10532static enum neon_shape_class neon_shape_class[] =
10533{
10534 NEON_SHAPE_DEF
10535};
10536
10537#undef X
10538
10539enum neon_shape_el
10540{
10541 SE_F,
10542 SE_D,
10543 SE_Q,
10544 SE_I,
10545 SE_S,
10546 SE_R,
10547 SE_L
10548};
10549
10550/* Register widths of above. */
10551static unsigned neon_shape_el_size[] =
10552{
10553 32,
10554 64,
10555 128,
10556 0,
10557 32,
10558 32,
10559 0
10560};
10561
10562struct neon_shape_info
10563{
10564 unsigned els;
10565 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10566};
10567
10568#define S2(A,B) { SE_##A, SE_##B }
10569#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10570#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10571
10572#define X(N, L, C) { N, S##N L }
10573
10574static struct neon_shape_info neon_shape_tab[] =
10575{
10576 NEON_SHAPE_DEF
10577};
10578
10579#undef X
10580#undef S2
10581#undef S3
10582#undef S4
10583
5287ad62
JB
10584/* Bit masks used in type checking given instructions.
10585 'N_EQK' means the type must be the same as (or based on in some way) the key
10586 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10587 set, various other bits can be set as well in order to modify the meaning of
10588 the type constraint. */
10589
10590enum neon_type_mask
10591{
10592 N_S8 = 0x000001,
10593 N_S16 = 0x000002,
10594 N_S32 = 0x000004,
10595 N_S64 = 0x000008,
10596 N_U8 = 0x000010,
10597 N_U16 = 0x000020,
10598 N_U32 = 0x000040,
10599 N_U64 = 0x000080,
10600 N_I8 = 0x000100,
10601 N_I16 = 0x000200,
10602 N_I32 = 0x000400,
10603 N_I64 = 0x000800,
10604 N_8 = 0x001000,
10605 N_16 = 0x002000,
10606 N_32 = 0x004000,
10607 N_64 = 0x008000,
10608 N_P8 = 0x010000,
10609 N_P16 = 0x020000,
10610 N_F32 = 0x040000,
037e8744
JB
10611 N_F64 = 0x080000,
10612 N_KEY = 0x100000, /* key element (main type specifier). */
10613 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10614 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10615 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10616 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10617 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10618 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10619 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10620 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10621 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10622 N_UTYP = 0,
037e8744 10623 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10624};
10625
dcbf9037
JB
10626#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10627
5287ad62
JB
10628#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10629#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10630#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10631#define N_SUF_32 (N_SU_32 | N_F32)
10632#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10633#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10634
10635/* Pass this as the first type argument to neon_check_type to ignore types
10636 altogether. */
10637#define N_IGNORE_TYPE (N_KEY | N_EQK)
10638
037e8744
JB
10639/* Select a "shape" for the current instruction (describing register types or
10640 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10641 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10642 function of operand parsing, so this function doesn't need to be called.
10643 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10644
10645static enum neon_shape
037e8744 10646neon_select_shape (enum neon_shape shape, ...)
5287ad62 10647{
037e8744
JB
10648 va_list ap;
10649 enum neon_shape first_shape = shape;
5287ad62
JB
10650
10651 /* Fix missing optional operands. FIXME: we don't know at this point how
10652 many arguments we should have, so this makes the assumption that we have
10653 > 1. This is true of all current Neon opcodes, I think, but may not be
10654 true in the future. */
10655 if (!inst.operands[1].present)
10656 inst.operands[1] = inst.operands[0];
10657
037e8744 10658 va_start (ap, shape);
5287ad62 10659
037e8744
JB
10660 for (; shape != NS_NULL; shape = va_arg (ap, int))
10661 {
10662 unsigned j;
10663 int matches = 1;
10664
10665 for (j = 0; j < neon_shape_tab[shape].els; j++)
10666 {
10667 if (!inst.operands[j].present)
10668 {
10669 matches = 0;
10670 break;
10671 }
10672
10673 switch (neon_shape_tab[shape].el[j])
10674 {
10675 case SE_F:
10676 if (!(inst.operands[j].isreg
10677 && inst.operands[j].isvec
10678 && inst.operands[j].issingle
10679 && !inst.operands[j].isquad))
10680 matches = 0;
10681 break;
10682
10683 case SE_D:
10684 if (!(inst.operands[j].isreg
10685 && inst.operands[j].isvec
10686 && !inst.operands[j].isquad
10687 && !inst.operands[j].issingle))
10688 matches = 0;
10689 break;
10690
10691 case SE_R:
10692 if (!(inst.operands[j].isreg
10693 && !inst.operands[j].isvec))
10694 matches = 0;
10695 break;
10696
10697 case SE_Q:
10698 if (!(inst.operands[j].isreg
10699 && inst.operands[j].isvec
10700 && inst.operands[j].isquad
10701 && !inst.operands[j].issingle))
10702 matches = 0;
10703 break;
10704
10705 case SE_I:
10706 if (!(!inst.operands[j].isreg
10707 && !inst.operands[j].isscalar))
10708 matches = 0;
10709 break;
10710
10711 case SE_S:
10712 if (!(!inst.operands[j].isreg
10713 && inst.operands[j].isscalar))
10714 matches = 0;
10715 break;
10716
10717 case SE_L:
10718 break;
10719 }
10720 }
10721 if (matches)
5287ad62 10722 break;
037e8744 10723 }
5287ad62 10724
037e8744 10725 va_end (ap);
5287ad62 10726
037e8744
JB
10727 if (shape == NS_NULL && first_shape != NS_NULL)
10728 first_error (_("invalid instruction shape"));
5287ad62 10729
037e8744
JB
10730 return shape;
10731}
5287ad62 10732
037e8744
JB
10733/* True if SHAPE is predominantly a quadword operation (most of the time, this
10734 means the Q bit should be set). */
10735
10736static int
10737neon_quad (enum neon_shape shape)
10738{
10739 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10740}
037e8744 10741
5287ad62
JB
10742static void
10743neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10744 unsigned *g_size)
10745{
10746 /* Allow modification to be made to types which are constrained to be
10747 based on the key element, based on bits set alongside N_EQK. */
10748 if ((typebits & N_EQK) != 0)
10749 {
10750 if ((typebits & N_HLF) != 0)
10751 *g_size /= 2;
10752 else if ((typebits & N_DBL) != 0)
10753 *g_size *= 2;
10754 if ((typebits & N_SGN) != 0)
10755 *g_type = NT_signed;
10756 else if ((typebits & N_UNS) != 0)
10757 *g_type = NT_unsigned;
10758 else if ((typebits & N_INT) != 0)
10759 *g_type = NT_integer;
10760 else if ((typebits & N_FLT) != 0)
10761 *g_type = NT_float;
dcbf9037
JB
10762 else if ((typebits & N_SIZ) != 0)
10763 *g_type = NT_untyped;
5287ad62
JB
10764 }
10765}
10766
10767/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10768 operand type, i.e. the single type specified in a Neon instruction when it
10769 is the only one given. */
10770
10771static struct neon_type_el
10772neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10773{
10774 struct neon_type_el dest = *key;
10775
10776 assert ((thisarg & N_EQK) != 0);
10777
10778 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10779
10780 return dest;
10781}
10782
10783/* Convert Neon type and size into compact bitmask representation. */
10784
10785static enum neon_type_mask
10786type_chk_of_el_type (enum neon_el_type type, unsigned size)
10787{
10788 switch (type)
10789 {
10790 case NT_untyped:
10791 switch (size)
10792 {
10793 case 8: return N_8;
10794 case 16: return N_16;
10795 case 32: return N_32;
10796 case 64: return N_64;
10797 default: ;
10798 }
10799 break;
10800
10801 case NT_integer:
10802 switch (size)
10803 {
10804 case 8: return N_I8;
10805 case 16: return N_I16;
10806 case 32: return N_I32;
10807 case 64: return N_I64;
10808 default: ;
10809 }
10810 break;
10811
10812 case NT_float:
037e8744
JB
10813 switch (size)
10814 {
10815 case 32: return N_F32;
10816 case 64: return N_F64;
10817 default: ;
10818 }
5287ad62
JB
10819 break;
10820
10821 case NT_poly:
10822 switch (size)
10823 {
10824 case 8: return N_P8;
10825 case 16: return N_P16;
10826 default: ;
10827 }
10828 break;
10829
10830 case NT_signed:
10831 switch (size)
10832 {
10833 case 8: return N_S8;
10834 case 16: return N_S16;
10835 case 32: return N_S32;
10836 case 64: return N_S64;
10837 default: ;
10838 }
10839 break;
10840
10841 case NT_unsigned:
10842 switch (size)
10843 {
10844 case 8: return N_U8;
10845 case 16: return N_U16;
10846 case 32: return N_U32;
10847 case 64: return N_U64;
10848 default: ;
10849 }
10850 break;
10851
10852 default: ;
10853 }
10854
10855 return N_UTYP;
10856}
10857
10858/* Convert compact Neon bitmask type representation to a type and size. Only
10859 handles the case where a single bit is set in the mask. */
10860
dcbf9037 10861static int
5287ad62
JB
10862el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10863 enum neon_type_mask mask)
10864{
dcbf9037
JB
10865 if ((mask & N_EQK) != 0)
10866 return FAIL;
10867
5287ad62
JB
10868 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10869 *size = 8;
dcbf9037 10870 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10871 *size = 16;
dcbf9037 10872 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10873 *size = 32;
037e8744 10874 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10875 *size = 64;
dcbf9037
JB
10876 else
10877 return FAIL;
10878
5287ad62
JB
10879 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10880 *type = NT_signed;
dcbf9037 10881 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10882 *type = NT_unsigned;
dcbf9037 10883 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10884 *type = NT_integer;
dcbf9037 10885 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10886 *type = NT_untyped;
dcbf9037 10887 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10888 *type = NT_poly;
037e8744 10889 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10890 *type = NT_float;
dcbf9037
JB
10891 else
10892 return FAIL;
10893
10894 return SUCCESS;
5287ad62
JB
10895}
10896
10897/* Modify a bitmask of allowed types. This is only needed for type
10898 relaxation. */
10899
10900static unsigned
10901modify_types_allowed (unsigned allowed, unsigned mods)
10902{
10903 unsigned size;
10904 enum neon_el_type type;
10905 unsigned destmask;
10906 int i;
10907
10908 destmask = 0;
10909
10910 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10911 {
dcbf9037
JB
10912 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10913 {
10914 neon_modify_type_size (mods, &type, &size);
10915 destmask |= type_chk_of_el_type (type, size);
10916 }
5287ad62
JB
10917 }
10918
10919 return destmask;
10920}
10921
10922/* Check type and return type classification.
10923 The manual states (paraphrase): If one datatype is given, it indicates the
10924 type given in:
10925 - the second operand, if there is one
10926 - the operand, if there is no second operand
10927 - the result, if there are no operands.
10928 This isn't quite good enough though, so we use a concept of a "key" datatype
10929 which is set on a per-instruction basis, which is the one which matters when
10930 only one data type is written.
10931 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 10932 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
10933
10934static struct neon_type_el
10935neon_check_type (unsigned els, enum neon_shape ns, ...)
10936{
10937 va_list ap;
10938 unsigned i, pass, key_el = 0;
10939 unsigned types[NEON_MAX_TYPE_ELS];
10940 enum neon_el_type k_type = NT_invtype;
10941 unsigned k_size = -1u;
10942 struct neon_type_el badtype = {NT_invtype, -1};
10943 unsigned key_allowed = 0;
10944
10945 /* Optional registers in Neon instructions are always (not) in operand 1.
10946 Fill in the missing operand here, if it was omitted. */
10947 if (els > 1 && !inst.operands[1].present)
10948 inst.operands[1] = inst.operands[0];
10949
10950 /* Suck up all the varargs. */
10951 va_start (ap, ns);
10952 for (i = 0; i < els; i++)
10953 {
10954 unsigned thisarg = va_arg (ap, unsigned);
10955 if (thisarg == N_IGNORE_TYPE)
10956 {
10957 va_end (ap);
10958 return badtype;
10959 }
10960 types[i] = thisarg;
10961 if ((thisarg & N_KEY) != 0)
10962 key_el = i;
10963 }
10964 va_end (ap);
10965
dcbf9037
JB
10966 if (inst.vectype.elems > 0)
10967 for (i = 0; i < els; i++)
10968 if (inst.operands[i].vectype.type != NT_invtype)
10969 {
10970 first_error (_("types specified in both the mnemonic and operands"));
10971 return badtype;
10972 }
10973
5287ad62
JB
10974 /* Duplicate inst.vectype elements here as necessary.
10975 FIXME: No idea if this is exactly the same as the ARM assembler,
10976 particularly when an insn takes one register and one non-register
10977 operand. */
10978 if (inst.vectype.elems == 1 && els > 1)
10979 {
10980 unsigned j;
10981 inst.vectype.elems = els;
10982 inst.vectype.el[key_el] = inst.vectype.el[0];
10983 for (j = 0; j < els; j++)
dcbf9037
JB
10984 if (j != key_el)
10985 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10986 types[j]);
10987 }
10988 else if (inst.vectype.elems == 0 && els > 0)
10989 {
10990 unsigned j;
10991 /* No types were given after the mnemonic, so look for types specified
10992 after each operand. We allow some flexibility here; as long as the
10993 "key" operand has a type, we can infer the others. */
10994 for (j = 0; j < els; j++)
10995 if (inst.operands[j].vectype.type != NT_invtype)
10996 inst.vectype.el[j] = inst.operands[j].vectype;
10997
10998 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 10999 {
dcbf9037
JB
11000 for (j = 0; j < els; j++)
11001 if (inst.operands[j].vectype.type == NT_invtype)
11002 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11003 types[j]);
11004 }
11005 else
11006 {
11007 first_error (_("operand types can't be inferred"));
11008 return badtype;
5287ad62
JB
11009 }
11010 }
11011 else if (inst.vectype.elems != els)
11012 {
dcbf9037 11013 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11014 return badtype;
11015 }
11016
11017 for (pass = 0; pass < 2; pass++)
11018 {
11019 for (i = 0; i < els; i++)
11020 {
11021 unsigned thisarg = types[i];
11022 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11023 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11024 enum neon_el_type g_type = inst.vectype.el[i].type;
11025 unsigned g_size = inst.vectype.el[i].size;
11026
11027 /* Decay more-specific signed & unsigned types to sign-insensitive
11028 integer types if sign-specific variants are unavailable. */
11029 if ((g_type == NT_signed || g_type == NT_unsigned)
11030 && (types_allowed & N_SU_ALL) == 0)
11031 g_type = NT_integer;
11032
11033 /* If only untyped args are allowed, decay any more specific types to
11034 them. Some instructions only care about signs for some element
11035 sizes, so handle that properly. */
11036 if ((g_size == 8 && (types_allowed & N_8) != 0)
11037 || (g_size == 16 && (types_allowed & N_16) != 0)
11038 || (g_size == 32 && (types_allowed & N_32) != 0)
11039 || (g_size == 64 && (types_allowed & N_64) != 0))
11040 g_type = NT_untyped;
11041
11042 if (pass == 0)
11043 {
11044 if ((thisarg & N_KEY) != 0)
11045 {
11046 k_type = g_type;
11047 k_size = g_size;
11048 key_allowed = thisarg & ~N_KEY;
11049 }
11050 }
11051 else
11052 {
037e8744
JB
11053 if ((thisarg & N_VFP) != 0)
11054 {
11055 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11056 unsigned regwidth = neon_shape_el_size[regshape], match;
11057
11058 /* In VFP mode, operands must match register widths. If we
11059 have a key operand, use its width, else use the width of
11060 the current operand. */
11061 if (k_size != -1u)
11062 match = k_size;
11063 else
11064 match = g_size;
11065
11066 if (regwidth != match)
11067 {
11068 first_error (_("operand size must match register width"));
11069 return badtype;
11070 }
11071 }
11072
5287ad62
JB
11073 if ((thisarg & N_EQK) == 0)
11074 {
11075 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11076
11077 if ((given_type & types_allowed) == 0)
11078 {
dcbf9037 11079 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11080 return badtype;
11081 }
11082 }
11083 else
11084 {
11085 enum neon_el_type mod_k_type = k_type;
11086 unsigned mod_k_size = k_size;
11087 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11088 if (g_type != mod_k_type || g_size != mod_k_size)
11089 {
dcbf9037 11090 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11091 return badtype;
11092 }
11093 }
11094 }
11095 }
11096 }
11097
11098 return inst.vectype.el[key_el];
11099}
11100
037e8744 11101/* Neon-style VFP instruction forwarding. */
5287ad62 11102
037e8744
JB
11103/* Thumb VFP instructions have 0xE in the condition field. */
11104
11105static void
11106do_vfp_cond_or_thumb (void)
5287ad62
JB
11107{
11108 if (thumb_mode)
037e8744 11109 inst.instruction |= 0xe0000000;
5287ad62 11110 else
037e8744 11111 inst.instruction |= inst.cond << 28;
5287ad62
JB
11112}
11113
037e8744
JB
11114/* Look up and encode a simple mnemonic, for use as a helper function for the
11115 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11116 etc. It is assumed that operand parsing has already been done, and that the
11117 operands are in the form expected by the given opcode (this isn't necessarily
11118 the same as the form in which they were parsed, hence some massaging must
11119 take place before this function is called).
11120 Checks current arch version against that in the looked-up opcode. */
5287ad62 11121
037e8744
JB
11122static void
11123do_vfp_nsyn_opcode (const char *opname)
5287ad62 11124{
037e8744
JB
11125 const struct asm_opcode *opcode;
11126
11127 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11128
037e8744
JB
11129 if (!opcode)
11130 abort ();
5287ad62 11131
037e8744
JB
11132 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11133 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11134 _(BAD_FPU));
5287ad62 11135
037e8744
JB
11136 if (thumb_mode)
11137 {
11138 inst.instruction = opcode->tvalue;
11139 opcode->tencode ();
11140 }
11141 else
11142 {
11143 inst.instruction = (inst.cond << 28) | opcode->avalue;
11144 opcode->aencode ();
11145 }
11146}
5287ad62
JB
11147
11148static void
037e8744 11149do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11150{
037e8744
JB
11151 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11152
11153 if (rs == NS_FFF)
11154 {
11155 if (is_add)
11156 do_vfp_nsyn_opcode ("fadds");
11157 else
11158 do_vfp_nsyn_opcode ("fsubs");
11159 }
11160 else
11161 {
11162 if (is_add)
11163 do_vfp_nsyn_opcode ("faddd");
11164 else
11165 do_vfp_nsyn_opcode ("fsubd");
11166 }
11167}
11168
11169/* Check operand types to see if this is a VFP instruction, and if so call
11170 PFN (). */
11171
11172static int
11173try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11174{
11175 enum neon_shape rs;
11176 struct neon_type_el et;
11177
11178 switch (args)
11179 {
11180 case 2:
11181 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11182 et = neon_check_type (2, rs,
11183 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11184 break;
11185
11186 case 3:
11187 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11188 et = neon_check_type (3, rs,
11189 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11190 break;
11191
11192 default:
11193 abort ();
11194 }
11195
11196 if (et.type != NT_invtype)
11197 {
11198 pfn (rs);
11199 return SUCCESS;
11200 }
11201 else
11202 inst.error = NULL;
11203
11204 return FAIL;
11205}
11206
11207static void
11208do_vfp_nsyn_mla_mls (enum neon_shape rs)
11209{
11210 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11211
11212 if (rs == NS_FFF)
11213 {
11214 if (is_mla)
11215 do_vfp_nsyn_opcode ("fmacs");
11216 else
11217 do_vfp_nsyn_opcode ("fmscs");
11218 }
11219 else
11220 {
11221 if (is_mla)
11222 do_vfp_nsyn_opcode ("fmacd");
11223 else
11224 do_vfp_nsyn_opcode ("fmscd");
11225 }
11226}
11227
11228static void
11229do_vfp_nsyn_mul (enum neon_shape rs)
11230{
11231 if (rs == NS_FFF)
11232 do_vfp_nsyn_opcode ("fmuls");
11233 else
11234 do_vfp_nsyn_opcode ("fmuld");
11235}
11236
11237static void
11238do_vfp_nsyn_abs_neg (enum neon_shape rs)
11239{
11240 int is_neg = (inst.instruction & 0x80) != 0;
11241 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11242
11243 if (rs == NS_FF)
11244 {
11245 if (is_neg)
11246 do_vfp_nsyn_opcode ("fnegs");
11247 else
11248 do_vfp_nsyn_opcode ("fabss");
11249 }
11250 else
11251 {
11252 if (is_neg)
11253 do_vfp_nsyn_opcode ("fnegd");
11254 else
11255 do_vfp_nsyn_opcode ("fabsd");
11256 }
11257}
11258
11259/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11260 insns belong to Neon, and are handled elsewhere. */
11261
11262static void
11263do_vfp_nsyn_ldm_stm (int is_dbmode)
11264{
11265 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11266 if (is_ldm)
11267 {
11268 if (is_dbmode)
11269 do_vfp_nsyn_opcode ("fldmdbs");
11270 else
11271 do_vfp_nsyn_opcode ("fldmias");
11272 }
11273 else
11274 {
11275 if (is_dbmode)
11276 do_vfp_nsyn_opcode ("fstmdbs");
11277 else
11278 do_vfp_nsyn_opcode ("fstmias");
11279 }
11280}
11281
037e8744
JB
11282static void
11283do_vfp_nsyn_sqrt (void)
11284{
11285 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11286 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11287
11288 if (rs == NS_FF)
11289 do_vfp_nsyn_opcode ("fsqrts");
11290 else
11291 do_vfp_nsyn_opcode ("fsqrtd");
11292}
11293
11294static void
11295do_vfp_nsyn_div (void)
11296{
11297 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11298 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11299 N_F32 | N_F64 | N_KEY | N_VFP);
11300
11301 if (rs == NS_FFF)
11302 do_vfp_nsyn_opcode ("fdivs");
11303 else
11304 do_vfp_nsyn_opcode ("fdivd");
11305}
11306
11307static void
11308do_vfp_nsyn_nmul (void)
11309{
11310 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11311 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11312 N_F32 | N_F64 | N_KEY | N_VFP);
11313
11314 if (rs == NS_FFF)
11315 {
11316 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11317 do_vfp_sp_dyadic ();
11318 }
11319 else
11320 {
11321 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11322 do_vfp_dp_rd_rn_rm ();
11323 }
11324 do_vfp_cond_or_thumb ();
11325}
11326
11327static void
11328do_vfp_nsyn_cmp (void)
11329{
11330 if (inst.operands[1].isreg)
11331 {
11332 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11333 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11334
11335 if (rs == NS_FF)
11336 {
11337 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11338 do_vfp_sp_monadic ();
11339 }
11340 else
11341 {
11342 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11343 do_vfp_dp_rd_rm ();
11344 }
11345 }
11346 else
11347 {
11348 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11349 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11350
11351 switch (inst.instruction & 0x0fffffff)
11352 {
11353 case N_MNEM_vcmp:
11354 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11355 break;
11356 case N_MNEM_vcmpe:
11357 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11358 break;
11359 default:
11360 abort ();
11361 }
11362
11363 if (rs == NS_FI)
11364 {
11365 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11366 do_vfp_sp_compare_z ();
11367 }
11368 else
11369 {
11370 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11371 do_vfp_dp_rd ();
11372 }
11373 }
11374 do_vfp_cond_or_thumb ();
11375}
11376
11377static void
11378nsyn_insert_sp (void)
11379{
11380 inst.operands[1] = inst.operands[0];
11381 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11382 inst.operands[0].reg = 13;
11383 inst.operands[0].isreg = 1;
11384 inst.operands[0].writeback = 1;
11385 inst.operands[0].present = 1;
11386}
11387
11388static void
11389do_vfp_nsyn_push (void)
11390{
11391 nsyn_insert_sp ();
11392 if (inst.operands[1].issingle)
11393 do_vfp_nsyn_opcode ("fstmdbs");
11394 else
11395 do_vfp_nsyn_opcode ("fstmdbd");
11396}
11397
11398static void
11399do_vfp_nsyn_pop (void)
11400{
11401 nsyn_insert_sp ();
11402 if (inst.operands[1].issingle)
22b5b651 11403 do_vfp_nsyn_opcode ("fldmias");
037e8744 11404 else
22b5b651 11405 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11406}
11407
11408/* Fix up Neon data-processing instructions, ORing in the correct bits for
11409 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11410
11411static unsigned
11412neon_dp_fixup (unsigned i)
11413{
11414 if (thumb_mode)
11415 {
11416 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11417 if (i & (1 << 24))
11418 i |= 1 << 28;
11419
11420 i &= ~(1 << 24);
11421
11422 i |= 0xef000000;
11423 }
11424 else
11425 i |= 0xf2000000;
11426
11427 return i;
11428}
11429
11430/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11431 (0, 1, 2, 3). */
11432
11433static unsigned
11434neon_logbits (unsigned x)
11435{
11436 return ffs (x) - 4;
11437}
11438
11439#define LOW4(R) ((R) & 0xf)
11440#define HI1(R) (((R) >> 4) & 1)
11441
11442/* Encode insns with bit pattern:
11443
11444 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11445 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11446
11447 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11448 different meaning for some instruction. */
11449
11450static void
11451neon_three_same (int isquad, int ubit, int size)
11452{
11453 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11454 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11455 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11456 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11457 inst.instruction |= LOW4 (inst.operands[2].reg);
11458 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11459 inst.instruction |= (isquad != 0) << 6;
11460 inst.instruction |= (ubit != 0) << 24;
11461 if (size != -1)
11462 inst.instruction |= neon_logbits (size) << 20;
11463
11464 inst.instruction = neon_dp_fixup (inst.instruction);
11465}
11466
11467/* Encode instructions of the form:
11468
11469 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11470 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11471
11472 Don't write size if SIZE == -1. */
11473
11474static void
11475neon_two_same (int qbit, int ubit, int size)
11476{
11477 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11478 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11479 inst.instruction |= LOW4 (inst.operands[1].reg);
11480 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11481 inst.instruction |= (qbit != 0) << 6;
11482 inst.instruction |= (ubit != 0) << 24;
11483
11484 if (size != -1)
11485 inst.instruction |= neon_logbits (size) << 18;
11486
11487 inst.instruction = neon_dp_fixup (inst.instruction);
11488}
11489
11490/* Neon instruction encoders, in approximate order of appearance. */
11491
11492static void
11493do_neon_dyadic_i_su (void)
11494{
037e8744 11495 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11496 struct neon_type_el et = neon_check_type (3, rs,
11497 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11498 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11499}
11500
11501static void
11502do_neon_dyadic_i64_su (void)
11503{
037e8744 11504 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11505 struct neon_type_el et = neon_check_type (3, rs,
11506 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11507 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11508}
11509
11510static void
11511neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11512 unsigned immbits)
11513{
11514 unsigned size = et.size >> 3;
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);
11518 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11519 inst.instruction |= (isquad != 0) << 6;
11520 inst.instruction |= immbits << 16;
11521 inst.instruction |= (size >> 3) << 7;
11522 inst.instruction |= (size & 0x7) << 19;
11523 if (write_ubit)
11524 inst.instruction |= (uval != 0) << 24;
11525
11526 inst.instruction = neon_dp_fixup (inst.instruction);
11527}
11528
11529static void
11530do_neon_shl_imm (void)
11531{
11532 if (!inst.operands[2].isreg)
11533 {
037e8744 11534 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11535 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11536 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11537 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11538 }
11539 else
11540 {
037e8744 11541 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11542 struct neon_type_el et = neon_check_type (3, rs,
11543 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11544 unsigned int tmp;
11545
11546 /* VSHL/VQSHL 3-register variants have syntax such as:
11547 vshl.xx Dd, Dm, Dn
11548 whereas other 3-register operations encoded by neon_three_same have
11549 syntax like:
11550 vadd.xx Dd, Dn, Dm
11551 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11552 here. */
11553 tmp = inst.operands[2].reg;
11554 inst.operands[2].reg = inst.operands[1].reg;
11555 inst.operands[1].reg = tmp;
5287ad62 11556 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11557 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11558 }
11559}
11560
11561static void
11562do_neon_qshl_imm (void)
11563{
11564 if (!inst.operands[2].isreg)
11565 {
037e8744 11566 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11567 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11568
5287ad62 11569 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11570 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11571 inst.operands[2].imm);
11572 }
11573 else
11574 {
037e8744 11575 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11576 struct neon_type_el et = neon_check_type (3, rs,
11577 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11578 unsigned int tmp;
11579
11580 /* See note in do_neon_shl_imm. */
11581 tmp = inst.operands[2].reg;
11582 inst.operands[2].reg = inst.operands[1].reg;
11583 inst.operands[1].reg = tmp;
5287ad62 11584 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11585 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11586 }
11587}
11588
627907b7
JB
11589static void
11590do_neon_rshl (void)
11591{
11592 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11593 struct neon_type_el et = neon_check_type (3, rs,
11594 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11595 unsigned int tmp;
11596
11597 tmp = inst.operands[2].reg;
11598 inst.operands[2].reg = inst.operands[1].reg;
11599 inst.operands[1].reg = tmp;
11600 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11601}
11602
5287ad62
JB
11603static int
11604neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11605{
036dc3f7
PB
11606 /* Handle .I8 pseudo-instructions. */
11607 if (size == 8)
5287ad62 11608 {
5287ad62
JB
11609 /* Unfortunately, this will make everything apart from zero out-of-range.
11610 FIXME is this the intended semantics? There doesn't seem much point in
11611 accepting .I8 if so. */
11612 immediate |= immediate << 8;
11613 size = 16;
036dc3f7
PB
11614 }
11615
11616 if (size >= 32)
11617 {
11618 if (immediate == (immediate & 0x000000ff))
11619 {
11620 *immbits = immediate;
11621 return 0x1;
11622 }
11623 else if (immediate == (immediate & 0x0000ff00))
11624 {
11625 *immbits = immediate >> 8;
11626 return 0x3;
11627 }
11628 else if (immediate == (immediate & 0x00ff0000))
11629 {
11630 *immbits = immediate >> 16;
11631 return 0x5;
11632 }
11633 else if (immediate == (immediate & 0xff000000))
11634 {
11635 *immbits = immediate >> 24;
11636 return 0x7;
11637 }
11638 if ((immediate & 0xffff) != (immediate >> 16))
11639 goto bad_immediate;
11640 immediate &= 0xffff;
5287ad62
JB
11641 }
11642
11643 if (immediate == (immediate & 0x000000ff))
11644 {
11645 *immbits = immediate;
036dc3f7 11646 return 0x9;
5287ad62
JB
11647 }
11648 else if (immediate == (immediate & 0x0000ff00))
11649 {
11650 *immbits = immediate >> 8;
036dc3f7 11651 return 0xb;
5287ad62
JB
11652 }
11653
11654 bad_immediate:
dcbf9037 11655 first_error (_("immediate value out of range"));
5287ad62
JB
11656 return FAIL;
11657}
11658
11659/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11660 A, B, C, D. */
11661
11662static int
11663neon_bits_same_in_bytes (unsigned imm)
11664{
11665 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11666 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11667 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11668 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11669}
11670
11671/* For immediate of above form, return 0bABCD. */
11672
11673static unsigned
11674neon_squash_bits (unsigned imm)
11675{
11676 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11677 | ((imm & 0x01000000) >> 21);
11678}
11679
136da414 11680/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11681
11682static unsigned
11683neon_qfloat_bits (unsigned imm)
11684{
136da414 11685 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11686}
11687
11688/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11689 the instruction. *OP is passed as the initial value of the op field, and
11690 may be set to a different value depending on the constant (i.e.
11691 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
036dc3f7
PB
11692 MVN). If the immediate looks like a repeated parttern then also
11693 try smaller element sizes. */
5287ad62
JB
11694
11695static int
c96612cc
JB
11696neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11697 unsigned *immbits, int *op, int size,
11698 enum neon_el_type type)
5287ad62 11699{
c96612cc
JB
11700 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11701 float. */
11702 if (type == NT_float && !float_p)
11703 return FAIL;
11704
136da414
JB
11705 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11706 {
11707 if (size != 32 || *op == 1)
11708 return FAIL;
11709 *immbits = neon_qfloat_bits (immlo);
11710 return 0xf;
11711 }
036dc3f7
PB
11712
11713 if (size == 64)
5287ad62 11714 {
036dc3f7
PB
11715 if (neon_bits_same_in_bytes (immhi)
11716 && neon_bits_same_in_bytes (immlo))
11717 {
11718 if (*op == 1)
11719 return FAIL;
11720 *immbits = (neon_squash_bits (immhi) << 4)
11721 | neon_squash_bits (immlo);
11722 *op = 1;
11723 return 0xe;
11724 }
11725
11726 if (immhi != immlo)
11727 return FAIL;
5287ad62 11728 }
036dc3f7
PB
11729
11730 if (size >= 32)
5287ad62 11731 {
036dc3f7
PB
11732 if (immlo == (immlo & 0x000000ff))
11733 {
11734 *immbits = immlo;
11735 return 0x0;
11736 }
11737 else if (immlo == (immlo & 0x0000ff00))
11738 {
11739 *immbits = immlo >> 8;
11740 return 0x2;
11741 }
11742 else if (immlo == (immlo & 0x00ff0000))
11743 {
11744 *immbits = immlo >> 16;
11745 return 0x4;
11746 }
11747 else if (immlo == (immlo & 0xff000000))
11748 {
11749 *immbits = immlo >> 24;
11750 return 0x6;
11751 }
11752 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11753 {
11754 *immbits = (immlo >> 8) & 0xff;
11755 return 0xc;
11756 }
11757 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11758 {
11759 *immbits = (immlo >> 16) & 0xff;
11760 return 0xd;
11761 }
11762
11763 if ((immlo & 0xffff) != (immlo >> 16))
11764 return FAIL;
11765 immlo &= 0xffff;
5287ad62 11766 }
036dc3f7
PB
11767
11768 if (size >= 16)
5287ad62 11769 {
036dc3f7
PB
11770 if (immlo == (immlo & 0x000000ff))
11771 {
11772 *immbits = immlo;
11773 return 0x8;
11774 }
11775 else if (immlo == (immlo & 0x0000ff00))
11776 {
11777 *immbits = immlo >> 8;
11778 return 0xa;
11779 }
11780
11781 if ((immlo & 0xff) != (immlo >> 8))
11782 return FAIL;
11783 immlo &= 0xff;
5287ad62 11784 }
036dc3f7
PB
11785
11786 if (immlo == (immlo & 0x000000ff))
5287ad62 11787 {
036dc3f7
PB
11788 /* Don't allow MVN with 8-bit immediate. */
11789 if (*op == 1)
11790 return FAIL;
11791 *immbits = immlo;
11792 return 0xe;
5287ad62 11793 }
5287ad62
JB
11794
11795 return FAIL;
11796}
11797
11798/* Write immediate bits [7:0] to the following locations:
11799
11800 |28/24|23 19|18 16|15 4|3 0|
11801 | 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|
11802
11803 This function is used by VMOV/VMVN/VORR/VBIC. */
11804
11805static void
11806neon_write_immbits (unsigned immbits)
11807{
11808 inst.instruction |= immbits & 0xf;
11809 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11810 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11811}
11812
11813/* Invert low-order SIZE bits of XHI:XLO. */
11814
11815static void
11816neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11817{
11818 unsigned immlo = xlo ? *xlo : 0;
11819 unsigned immhi = xhi ? *xhi : 0;
11820
11821 switch (size)
11822 {
11823 case 8:
11824 immlo = (~immlo) & 0xff;
11825 break;
11826
11827 case 16:
11828 immlo = (~immlo) & 0xffff;
11829 break;
11830
11831 case 64:
11832 immhi = (~immhi) & 0xffffffff;
11833 /* fall through. */
11834
11835 case 32:
11836 immlo = (~immlo) & 0xffffffff;
11837 break;
11838
11839 default:
11840 abort ();
11841 }
11842
11843 if (xlo)
11844 *xlo = immlo;
11845
11846 if (xhi)
11847 *xhi = immhi;
11848}
11849
11850static void
11851do_neon_logic (void)
11852{
11853 if (inst.operands[2].present && inst.operands[2].isreg)
11854 {
037e8744 11855 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11856 neon_check_type (3, rs, N_IGNORE_TYPE);
11857 /* U bit and size field were set as part of the bitmask. */
11858 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11859 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11860 }
11861 else
11862 {
037e8744
JB
11863 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11864 struct neon_type_el et = neon_check_type (2, rs,
11865 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11866 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11867 unsigned immbits;
11868 int cmode;
11869
11870 if (et.type == NT_invtype)
11871 return;
11872
11873 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11874
036dc3f7
PB
11875 immbits = inst.operands[1].imm;
11876 if (et.size == 64)
11877 {
11878 /* .i64 is a pseudo-op, so the immediate must be a repeating
11879 pattern. */
11880 if (immbits != (inst.operands[1].regisimm ?
11881 inst.operands[1].reg : 0))
11882 {
11883 /* Set immbits to an invalid constant. */
11884 immbits = 0xdeadbeef;
11885 }
11886 }
11887
5287ad62
JB
11888 switch (opcode)
11889 {
11890 case N_MNEM_vbic:
036dc3f7 11891 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62
JB
11892 break;
11893
11894 case N_MNEM_vorr:
036dc3f7 11895 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62
JB
11896 break;
11897
11898 case N_MNEM_vand:
11899 /* Pseudo-instruction for VBIC. */
5287ad62
JB
11900 neon_invert_size (&immbits, 0, et.size);
11901 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11902 break;
11903
11904 case N_MNEM_vorn:
11905 /* Pseudo-instruction for VORR. */
5287ad62
JB
11906 neon_invert_size (&immbits, 0, et.size);
11907 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11908 break;
11909
11910 default:
11911 abort ();
11912 }
11913
11914 if (cmode == FAIL)
11915 return;
11916
037e8744 11917 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11918 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11919 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11920 inst.instruction |= cmode << 8;
11921 neon_write_immbits (immbits);
11922
11923 inst.instruction = neon_dp_fixup (inst.instruction);
11924 }
11925}
11926
11927static void
11928do_neon_bitfield (void)
11929{
037e8744 11930 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 11931 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 11932 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11933}
11934
11935static void
dcbf9037
JB
11936neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11937 unsigned destbits)
5287ad62 11938{
037e8744 11939 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
11940 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
11941 types | N_KEY);
5287ad62
JB
11942 if (et.type == NT_float)
11943 {
11944 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 11945 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11946 }
11947 else
11948 {
11949 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11950 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
11951 }
11952}
11953
11954static void
11955do_neon_dyadic_if_su (void)
11956{
dcbf9037 11957 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
11958}
11959
11960static void
11961do_neon_dyadic_if_su_d (void)
11962{
11963 /* This version only allow D registers, but that constraint is enforced during
11964 operand parsing so we don't need to do anything extra here. */
dcbf9037 11965 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
11966}
11967
5287ad62
JB
11968static void
11969do_neon_dyadic_if_i_d (void)
11970{
428e3f1f
PB
11971 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11972 affected if we specify unsigned args. */
11973 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
11974}
11975
037e8744
JB
11976enum vfp_or_neon_is_neon_bits
11977{
11978 NEON_CHECK_CC = 1,
11979 NEON_CHECK_ARCH = 2
11980};
11981
11982/* Call this function if an instruction which may have belonged to the VFP or
11983 Neon instruction sets, but turned out to be a Neon instruction (due to the
11984 operand types involved, etc.). We have to check and/or fix-up a couple of
11985 things:
11986
11987 - Make sure the user hasn't attempted to make a Neon instruction
11988 conditional.
11989 - Alter the value in the condition code field if necessary.
11990 - Make sure that the arch supports Neon instructions.
11991
11992 Which of these operations take place depends on bits from enum
11993 vfp_or_neon_is_neon_bits.
11994
11995 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
11996 current instruction's condition is COND_ALWAYS, the condition field is
11997 changed to inst.uncond_value. This is necessary because instructions shared
11998 between VFP and Neon may be conditional for the VFP variants only, and the
11999 unconditional Neon version must have, e.g., 0xF in the condition field. */
12000
12001static int
12002vfp_or_neon_is_neon (unsigned check)
12003{
12004 /* Conditions are always legal in Thumb mode (IT blocks). */
12005 if (!thumb_mode && (check & NEON_CHECK_CC))
12006 {
12007 if (inst.cond != COND_ALWAYS)
12008 {
12009 first_error (_(BAD_COND));
12010 return FAIL;
12011 }
12012 if (inst.uncond_value != -1)
12013 inst.instruction |= inst.uncond_value << 28;
12014 }
12015
12016 if ((check & NEON_CHECK_ARCH)
12017 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12018 {
12019 first_error (_(BAD_FPU));
12020 return FAIL;
12021 }
12022
12023 return SUCCESS;
12024}
12025
5287ad62
JB
12026static void
12027do_neon_addsub_if_i (void)
12028{
037e8744
JB
12029 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12030 return;
12031
12032 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12033 return;
12034
5287ad62
JB
12035 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12036 affected if we specify unsigned args. */
dcbf9037 12037 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12038}
12039
12040/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12041 result to be:
12042 V<op> A,B (A is operand 0, B is operand 2)
12043 to mean:
12044 V<op> A,B,A
12045 not:
12046 V<op> A,B,B
12047 so handle that case specially. */
12048
12049static void
12050neon_exchange_operands (void)
12051{
12052 void *scratch = alloca (sizeof (inst.operands[0]));
12053 if (inst.operands[1].present)
12054 {
12055 /* Swap operands[1] and operands[2]. */
12056 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12057 inst.operands[1] = inst.operands[2];
12058 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12059 }
12060 else
12061 {
12062 inst.operands[1] = inst.operands[2];
12063 inst.operands[2] = inst.operands[0];
12064 }
12065}
12066
12067static void
12068neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12069{
12070 if (inst.operands[2].isreg)
12071 {
12072 if (invert)
12073 neon_exchange_operands ();
dcbf9037 12074 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12075 }
12076 else
12077 {
037e8744 12078 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12079 struct neon_type_el et = neon_check_type (2, rs,
12080 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12081
12082 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12083 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12084 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12085 inst.instruction |= LOW4 (inst.operands[1].reg);
12086 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12087 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12088 inst.instruction |= (et.type == NT_float) << 10;
12089 inst.instruction |= neon_logbits (et.size) << 18;
12090
12091 inst.instruction = neon_dp_fixup (inst.instruction);
12092 }
12093}
12094
12095static void
12096do_neon_cmp (void)
12097{
12098 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12099}
12100
12101static void
12102do_neon_cmp_inv (void)
12103{
12104 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12105}
12106
12107static void
12108do_neon_ceq (void)
12109{
12110 neon_compare (N_IF_32, N_IF_32, FALSE);
12111}
12112
12113/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12114 scalars, which are encoded in 5 bits, M : Rm.
12115 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12116 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12117 index in M. */
12118
12119static unsigned
12120neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12121{
dcbf9037
JB
12122 unsigned regno = NEON_SCALAR_REG (scalar);
12123 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12124
12125 switch (elsize)
12126 {
12127 case 16:
12128 if (regno > 7 || elno > 3)
12129 goto bad_scalar;
12130 return regno | (elno << 3);
12131
12132 case 32:
12133 if (regno > 15 || elno > 1)
12134 goto bad_scalar;
12135 return regno | (elno << 4);
12136
12137 default:
12138 bad_scalar:
dcbf9037 12139 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12140 }
12141
12142 return 0;
12143}
12144
12145/* Encode multiply / multiply-accumulate scalar instructions. */
12146
12147static void
12148neon_mul_mac (struct neon_type_el et, int ubit)
12149{
dcbf9037
JB
12150 unsigned scalar;
12151
12152 /* Give a more helpful error message if we have an invalid type. */
12153 if (et.type == NT_invtype)
12154 return;
12155
12156 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12157 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12158 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12159 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12160 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12161 inst.instruction |= LOW4 (scalar);
12162 inst.instruction |= HI1 (scalar) << 5;
12163 inst.instruction |= (et.type == NT_float) << 8;
12164 inst.instruction |= neon_logbits (et.size) << 20;
12165 inst.instruction |= (ubit != 0) << 24;
12166
12167 inst.instruction = neon_dp_fixup (inst.instruction);
12168}
12169
12170static void
12171do_neon_mac_maybe_scalar (void)
12172{
037e8744
JB
12173 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12174 return;
12175
12176 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12177 return;
12178
5287ad62
JB
12179 if (inst.operands[2].isscalar)
12180 {
037e8744 12181 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12182 struct neon_type_el et = neon_check_type (3, rs,
12183 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12184 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12185 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12186 }
12187 else
428e3f1f
PB
12188 {
12189 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12190 affected if we specify unsigned args. */
12191 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12192 }
5287ad62
JB
12193}
12194
12195static void
12196do_neon_tst (void)
12197{
037e8744 12198 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12199 struct neon_type_el et = neon_check_type (3, rs,
12200 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12201 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12202}
12203
12204/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12205 same types as the MAC equivalents. The polynomial type for this instruction
12206 is encoded the same as the integer type. */
12207
12208static void
12209do_neon_mul (void)
12210{
037e8744
JB
12211 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12212 return;
12213
12214 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12215 return;
12216
5287ad62
JB
12217 if (inst.operands[2].isscalar)
12218 do_neon_mac_maybe_scalar ();
12219 else
dcbf9037 12220 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12221}
12222
12223static void
12224do_neon_qdmulh (void)
12225{
12226 if (inst.operands[2].isscalar)
12227 {
037e8744 12228 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12229 struct neon_type_el et = neon_check_type (3, rs,
12230 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12231 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12232 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12233 }
12234 else
12235 {
037e8744 12236 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12237 struct neon_type_el et = neon_check_type (3, rs,
12238 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12239 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12240 /* The U bit (rounding) comes from bit mask. */
037e8744 12241 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12242 }
12243}
12244
12245static void
12246do_neon_fcmp_absolute (void)
12247{
037e8744 12248 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12249 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12250 /* Size field comes from bit mask. */
037e8744 12251 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12252}
12253
12254static void
12255do_neon_fcmp_absolute_inv (void)
12256{
12257 neon_exchange_operands ();
12258 do_neon_fcmp_absolute ();
12259}
12260
12261static void
12262do_neon_step (void)
12263{
037e8744 12264 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12265 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12266 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12267}
12268
12269static void
12270do_neon_abs_neg (void)
12271{
037e8744
JB
12272 enum neon_shape rs;
12273 struct neon_type_el et;
12274
12275 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12276 return;
12277
12278 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12279 return;
12280
12281 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12282 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12283
5287ad62
JB
12284 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12285 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12286 inst.instruction |= LOW4 (inst.operands[1].reg);
12287 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12288 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12289 inst.instruction |= (et.type == NT_float) << 10;
12290 inst.instruction |= neon_logbits (et.size) << 18;
12291
12292 inst.instruction = neon_dp_fixup (inst.instruction);
12293}
12294
12295static void
12296do_neon_sli (void)
12297{
037e8744 12298 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12299 struct neon_type_el et = neon_check_type (2, rs,
12300 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12301 int imm = inst.operands[2].imm;
12302 constraint (imm < 0 || (unsigned)imm >= et.size,
12303 _("immediate out of range for insert"));
037e8744 12304 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12305}
12306
12307static void
12308do_neon_sri (void)
12309{
037e8744 12310 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12311 struct neon_type_el et = neon_check_type (2, rs,
12312 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12313 int imm = inst.operands[2].imm;
12314 constraint (imm < 1 || (unsigned)imm > et.size,
12315 _("immediate out of range for insert"));
037e8744 12316 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12317}
12318
12319static void
12320do_neon_qshlu_imm (void)
12321{
037e8744 12322 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12323 struct neon_type_el et = neon_check_type (2, rs,
12324 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12325 int imm = inst.operands[2].imm;
12326 constraint (imm < 0 || (unsigned)imm >= et.size,
12327 _("immediate out of range for shift"));
12328 /* Only encodes the 'U present' variant of the instruction.
12329 In this case, signed types have OP (bit 8) set to 0.
12330 Unsigned types have OP set to 1. */
12331 inst.instruction |= (et.type == NT_unsigned) << 8;
12332 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12333 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12334}
12335
12336static void
12337do_neon_qmovn (void)
12338{
12339 struct neon_type_el et = neon_check_type (2, NS_DQ,
12340 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12341 /* Saturating move where operands can be signed or unsigned, and the
12342 destination has the same signedness. */
12343 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12344 if (et.type == NT_unsigned)
12345 inst.instruction |= 0xc0;
12346 else
12347 inst.instruction |= 0x80;
12348 neon_two_same (0, 1, et.size / 2);
12349}
12350
12351static void
12352do_neon_qmovun (void)
12353{
12354 struct neon_type_el et = neon_check_type (2, NS_DQ,
12355 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12356 /* Saturating move with unsigned results. Operands must be signed. */
12357 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12358 neon_two_same (0, 1, et.size / 2);
12359}
12360
12361static void
12362do_neon_rshift_sat_narrow (void)
12363{
12364 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12365 or unsigned. If operands are unsigned, results must also be unsigned. */
12366 struct neon_type_el et = neon_check_type (2, NS_DQI,
12367 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12368 int imm = inst.operands[2].imm;
12369 /* This gets the bounds check, size encoding and immediate bits calculation
12370 right. */
12371 et.size /= 2;
12372
12373 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12374 VQMOVN.I<size> <Dd>, <Qm>. */
12375 if (imm == 0)
12376 {
12377 inst.operands[2].present = 0;
12378 inst.instruction = N_MNEM_vqmovn;
12379 do_neon_qmovn ();
12380 return;
12381 }
12382
12383 constraint (imm < 1 || (unsigned)imm > et.size,
12384 _("immediate out of range"));
12385 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12386}
12387
12388static void
12389do_neon_rshift_sat_narrow_u (void)
12390{
12391 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12392 or unsigned. If operands are unsigned, results must also be unsigned. */
12393 struct neon_type_el et = neon_check_type (2, NS_DQI,
12394 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12395 int imm = inst.operands[2].imm;
12396 /* This gets the bounds check, size encoding and immediate bits calculation
12397 right. */
12398 et.size /= 2;
12399
12400 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12401 VQMOVUN.I<size> <Dd>, <Qm>. */
12402 if (imm == 0)
12403 {
12404 inst.operands[2].present = 0;
12405 inst.instruction = N_MNEM_vqmovun;
12406 do_neon_qmovun ();
12407 return;
12408 }
12409
12410 constraint (imm < 1 || (unsigned)imm > et.size,
12411 _("immediate out of range"));
12412 /* FIXME: The manual is kind of unclear about what value U should have in
12413 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12414 must be 1. */
12415 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12416}
12417
12418static void
12419do_neon_movn (void)
12420{
12421 struct neon_type_el et = neon_check_type (2, NS_DQ,
12422 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12423 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12424 neon_two_same (0, 1, et.size / 2);
12425}
12426
12427static void
12428do_neon_rshift_narrow (void)
12429{
12430 struct neon_type_el et = neon_check_type (2, NS_DQI,
12431 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12432 int imm = inst.operands[2].imm;
12433 /* This gets the bounds check, size encoding and immediate bits calculation
12434 right. */
12435 et.size /= 2;
12436
12437 /* If immediate is zero then we are a pseudo-instruction for
12438 VMOVN.I<size> <Dd>, <Qm> */
12439 if (imm == 0)
12440 {
12441 inst.operands[2].present = 0;
12442 inst.instruction = N_MNEM_vmovn;
12443 do_neon_movn ();
12444 return;
12445 }
12446
12447 constraint (imm < 1 || (unsigned)imm > et.size,
12448 _("immediate out of range for narrowing operation"));
12449 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12450}
12451
12452static void
12453do_neon_shll (void)
12454{
12455 /* FIXME: Type checking when lengthening. */
12456 struct neon_type_el et = neon_check_type (2, NS_QDI,
12457 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12458 unsigned imm = inst.operands[2].imm;
12459
12460 if (imm == et.size)
12461 {
12462 /* Maximum shift variant. */
12463 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12464 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12465 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12466 inst.instruction |= LOW4 (inst.operands[1].reg);
12467 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12468 inst.instruction |= neon_logbits (et.size) << 18;
12469
12470 inst.instruction = neon_dp_fixup (inst.instruction);
12471 }
12472 else
12473 {
12474 /* A more-specific type check for non-max versions. */
12475 et = neon_check_type (2, NS_QDI,
12476 N_EQK | N_DBL, N_SU_32 | N_KEY);
12477 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12478 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12479 }
12480}
12481
037e8744 12482/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12483 the current instruction is. */
12484
12485static int
12486neon_cvt_flavour (enum neon_shape rs)
12487{
037e8744
JB
12488#define CVT_VAR(C,X,Y) \
12489 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12490 if (et.type != NT_invtype) \
12491 { \
12492 inst.error = NULL; \
12493 return (C); \
5287ad62
JB
12494 }
12495 struct neon_type_el et;
037e8744
JB
12496 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12497 || rs == NS_FF) ? N_VFP : 0;
12498 /* The instruction versions which take an immediate take one register
12499 argument, which is extended to the width of the full register. Thus the
12500 "source" and "destination" registers must have the same width. Hack that
12501 here by making the size equal to the key (wider, in this case) operand. */
12502 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5287ad62
JB
12503
12504 CVT_VAR (0, N_S32, N_F32);
12505 CVT_VAR (1, N_U32, N_F32);
12506 CVT_VAR (2, N_F32, N_S32);
12507 CVT_VAR (3, N_F32, N_U32);
12508
037e8744
JB
12509 whole_reg = N_VFP;
12510
12511 /* VFP instructions. */
12512 CVT_VAR (4, N_F32, N_F64);
12513 CVT_VAR (5, N_F64, N_F32);
12514 CVT_VAR (6, N_S32, N_F64 | key);
12515 CVT_VAR (7, N_U32, N_F64 | key);
12516 CVT_VAR (8, N_F64 | key, N_S32);
12517 CVT_VAR (9, N_F64 | key, N_U32);
12518 /* VFP instructions with bitshift. */
12519 CVT_VAR (10, N_F32 | key, N_S16);
12520 CVT_VAR (11, N_F32 | key, N_U16);
12521 CVT_VAR (12, N_F64 | key, N_S16);
12522 CVT_VAR (13, N_F64 | key, N_U16);
12523 CVT_VAR (14, N_S16, N_F32 | key);
12524 CVT_VAR (15, N_U16, N_F32 | key);
12525 CVT_VAR (16, N_S16, N_F64 | key);
12526 CVT_VAR (17, N_U16, N_F64 | key);
12527
5287ad62
JB
12528 return -1;
12529#undef CVT_VAR
12530}
12531
037e8744
JB
12532/* Neon-syntax VFP conversions. */
12533
5287ad62 12534static void
037e8744 12535do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12536{
037e8744
JB
12537 const char *opname = 0;
12538
12539 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12540 {
037e8744
JB
12541 /* Conversions with immediate bitshift. */
12542 const char *enc[] =
12543 {
12544 "ftosls",
12545 "ftouls",
12546 "fsltos",
12547 "fultos",
12548 NULL,
12549 NULL,
12550 "ftosld",
12551 "ftould",
12552 "fsltod",
12553 "fultod",
12554 "fshtos",
12555 "fuhtos",
12556 "fshtod",
12557 "fuhtod",
12558 "ftoshs",
12559 "ftouhs",
12560 "ftoshd",
12561 "ftouhd"
12562 };
12563
12564 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12565 {
12566 opname = enc[flavour];
12567 constraint (inst.operands[0].reg != inst.operands[1].reg,
12568 _("operands 0 and 1 must be the same register"));
12569 inst.operands[1] = inst.operands[2];
12570 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12571 }
5287ad62
JB
12572 }
12573 else
12574 {
037e8744
JB
12575 /* Conversions without bitshift. */
12576 const char *enc[] =
12577 {
12578 "ftosis",
12579 "ftouis",
12580 "fsitos",
12581 "fuitos",
12582 "fcvtsd",
12583 "fcvtds",
12584 "ftosid",
12585 "ftouid",
12586 "fsitod",
12587 "fuitod"
12588 };
12589
12590 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12591 opname = enc[flavour];
12592 }
12593
12594 if (opname)
12595 do_vfp_nsyn_opcode (opname);
12596}
12597
12598static void
12599do_vfp_nsyn_cvtz (void)
12600{
12601 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12602 int flavour = neon_cvt_flavour (rs);
12603 const char *enc[] =
12604 {
12605 "ftosizs",
12606 "ftouizs",
12607 NULL,
12608 NULL,
12609 NULL,
12610 NULL,
12611 "ftosizd",
12612 "ftouizd"
12613 };
12614
12615 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12616 do_vfp_nsyn_opcode (enc[flavour]);
12617}
12618
12619static void
12620do_neon_cvt (void)
12621{
12622 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12623 NS_FD, NS_DF, NS_FF, NS_NULL);
12624 int flavour = neon_cvt_flavour (rs);
12625
12626 /* VFP rather than Neon conversions. */
12627 if (flavour >= 4)
12628 {
12629 do_vfp_nsyn_cvt (rs, flavour);
12630 return;
12631 }
12632
12633 switch (rs)
12634 {
12635 case NS_DDI:
12636 case NS_QQI:
12637 {
12638 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12639 return;
12640
12641 /* Fixed-point conversion with #0 immediate is encoded as an
12642 integer conversion. */
12643 if (inst.operands[2].present && inst.operands[2].imm == 0)
12644 goto int_encode;
12645 unsigned immbits = 32 - inst.operands[2].imm;
12646 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12647 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12648 if (flavour != -1)
12649 inst.instruction |= enctab[flavour];
12650 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12651 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12652 inst.instruction |= LOW4 (inst.operands[1].reg);
12653 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12654 inst.instruction |= neon_quad (rs) << 6;
12655 inst.instruction |= 1 << 21;
12656 inst.instruction |= immbits << 16;
12657
12658 inst.instruction = neon_dp_fixup (inst.instruction);
12659 }
12660 break;
12661
12662 case NS_DD:
12663 case NS_QQ:
12664 int_encode:
12665 {
12666 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12667
12668 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12669
12670 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12671 return;
12672
12673 if (flavour != -1)
12674 inst.instruction |= enctab[flavour];
12675
12676 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12677 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12678 inst.instruction |= LOW4 (inst.operands[1].reg);
12679 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12680 inst.instruction |= neon_quad (rs) << 6;
12681 inst.instruction |= 2 << 18;
12682
12683 inst.instruction = neon_dp_fixup (inst.instruction);
12684 }
12685 break;
12686
12687 default:
12688 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12689 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12690 }
5287ad62
JB
12691}
12692
12693static void
12694neon_move_immediate (void)
12695{
037e8744
JB
12696 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12697 struct neon_type_el et = neon_check_type (2, rs,
12698 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12699 unsigned immlo, immhi = 0, immbits;
c96612cc 12700 int op, cmode, float_p;
5287ad62 12701
037e8744
JB
12702 constraint (et.type == NT_invtype,
12703 _("operand size must be specified for immediate VMOV"));
12704
5287ad62
JB
12705 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12706 op = (inst.instruction & (1 << 5)) != 0;
12707
12708 immlo = inst.operands[1].imm;
12709 if (inst.operands[1].regisimm)
12710 immhi = inst.operands[1].reg;
12711
12712 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12713 _("immediate has bits set outside the operand size"));
12714
c96612cc
JB
12715 float_p = inst.operands[1].immisfloat;
12716
12717 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12718 et.size, et.type)) == FAIL)
5287ad62
JB
12719 {
12720 /* Invert relevant bits only. */
12721 neon_invert_size (&immlo, &immhi, et.size);
12722 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12723 with one or the other; those cases are caught by
12724 neon_cmode_for_move_imm. */
12725 op = !op;
c96612cc
JB
12726 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12727 &op, et.size, et.type)) == FAIL)
5287ad62 12728 {
dcbf9037 12729 first_error (_("immediate out of range"));
5287ad62
JB
12730 return;
12731 }
12732 }
12733
12734 inst.instruction &= ~(1 << 5);
12735 inst.instruction |= op << 5;
12736
12737 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12738 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12739 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12740 inst.instruction |= cmode << 8;
12741
12742 neon_write_immbits (immbits);
12743}
12744
12745static void
12746do_neon_mvn (void)
12747{
12748 if (inst.operands[1].isreg)
12749 {
037e8744 12750 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12751
12752 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12753 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12754 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12755 inst.instruction |= LOW4 (inst.operands[1].reg);
12756 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12757 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12758 }
12759 else
12760 {
12761 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12762 neon_move_immediate ();
12763 }
12764
12765 inst.instruction = neon_dp_fixup (inst.instruction);
12766}
12767
12768/* Encode instructions of form:
12769
12770 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12771 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12772
12773*/
12774
12775static void
12776neon_mixed_length (struct neon_type_el et, unsigned size)
12777{
12778 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12779 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12780 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12781 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12782 inst.instruction |= LOW4 (inst.operands[2].reg);
12783 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12784 inst.instruction |= (et.type == NT_unsigned) << 24;
12785 inst.instruction |= neon_logbits (size) << 20;
12786
12787 inst.instruction = neon_dp_fixup (inst.instruction);
12788}
12789
12790static void
12791do_neon_dyadic_long (void)
12792{
12793 /* FIXME: Type checking for lengthening op. */
12794 struct neon_type_el et = neon_check_type (3, NS_QDD,
12795 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12796 neon_mixed_length (et, et.size);
12797}
12798
12799static void
12800do_neon_abal (void)
12801{
12802 struct neon_type_el et = neon_check_type (3, NS_QDD,
12803 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12804 neon_mixed_length (et, et.size);
12805}
12806
12807static void
12808neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12809{
12810 if (inst.operands[2].isscalar)
12811 {
dcbf9037
JB
12812 struct neon_type_el et = neon_check_type (3, NS_QDS,
12813 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12814 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12815 neon_mul_mac (et, et.type == NT_unsigned);
12816 }
12817 else
12818 {
12819 struct neon_type_el et = neon_check_type (3, NS_QDD,
12820 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12821 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12822 neon_mixed_length (et, et.size);
12823 }
12824}
12825
12826static void
12827do_neon_mac_maybe_scalar_long (void)
12828{
12829 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12830}
12831
12832static void
12833do_neon_dyadic_wide (void)
12834{
12835 struct neon_type_el et = neon_check_type (3, NS_QQD,
12836 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12837 neon_mixed_length (et, et.size);
12838}
12839
12840static void
12841do_neon_dyadic_narrow (void)
12842{
12843 struct neon_type_el et = neon_check_type (3, NS_QDD,
12844 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12845 /* Operand sign is unimportant, and the U bit is part of the opcode,
12846 so force the operand type to integer. */
12847 et.type = NT_integer;
5287ad62
JB
12848 neon_mixed_length (et, et.size / 2);
12849}
12850
12851static void
12852do_neon_mul_sat_scalar_long (void)
12853{
12854 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12855}
12856
12857static void
12858do_neon_vmull (void)
12859{
12860 if (inst.operands[2].isscalar)
12861 do_neon_mac_maybe_scalar_long ();
12862 else
12863 {
12864 struct neon_type_el et = neon_check_type (3, NS_QDD,
12865 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12866 if (et.type == NT_poly)
12867 inst.instruction = NEON_ENC_POLY (inst.instruction);
12868 else
12869 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12870 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12871 zero. Should be OK as-is. */
12872 neon_mixed_length (et, et.size);
12873 }
12874}
12875
12876static void
12877do_neon_ext (void)
12878{
037e8744 12879 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12880 struct neon_type_el et = neon_check_type (3, rs,
12881 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12882 unsigned imm = (inst.operands[3].imm * et.size) / 8;
3b8d421e 12883 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
5287ad62
JB
12884 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12885 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12886 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12887 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12888 inst.instruction |= LOW4 (inst.operands[2].reg);
12889 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12890 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12891 inst.instruction |= imm << 8;
12892
12893 inst.instruction = neon_dp_fixup (inst.instruction);
12894}
12895
12896static void
12897do_neon_rev (void)
12898{
037e8744 12899 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12900 struct neon_type_el et = neon_check_type (2, rs,
12901 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12902 unsigned op = (inst.instruction >> 7) & 3;
12903 /* N (width of reversed regions) is encoded as part of the bitmask. We
12904 extract it here to check the elements to be reversed are smaller.
12905 Otherwise we'd get a reserved instruction. */
12906 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12907 assert (elsize != 0);
12908 constraint (et.size >= elsize,
12909 _("elements must be smaller than reversal region"));
037e8744 12910 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12911}
12912
12913static void
12914do_neon_dup (void)
12915{
12916 if (inst.operands[1].isscalar)
12917 {
037e8744 12918 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
12919 struct neon_type_el et = neon_check_type (2, rs,
12920 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 12921 unsigned sizebits = et.size >> 3;
dcbf9037 12922 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 12923 int logsize = neon_logbits (et.size);
dcbf9037 12924 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
12925
12926 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12927 return;
12928
5287ad62
JB
12929 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12930 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12931 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12932 inst.instruction |= LOW4 (dm);
12933 inst.instruction |= HI1 (dm) << 5;
037e8744 12934 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12935 inst.instruction |= x << 17;
12936 inst.instruction |= sizebits << 16;
12937
12938 inst.instruction = neon_dp_fixup (inst.instruction);
12939 }
12940 else
12941 {
037e8744
JB
12942 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
12943 struct neon_type_el et = neon_check_type (2, rs,
12944 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
12945 /* Duplicate ARM register to lanes of vector. */
12946 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
12947 switch (et.size)
12948 {
12949 case 8: inst.instruction |= 0x400000; break;
12950 case 16: inst.instruction |= 0x000020; break;
12951 case 32: inst.instruction |= 0x000000; break;
12952 default: break;
12953 }
12954 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12955 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
12956 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 12957 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
12958 /* The encoding for this instruction is identical for the ARM and Thumb
12959 variants, except for the condition field. */
037e8744 12960 do_vfp_cond_or_thumb ();
5287ad62
JB
12961 }
12962}
12963
12964/* VMOV has particularly many variations. It can be one of:
12965 0. VMOV<c><q> <Qd>, <Qm>
12966 1. VMOV<c><q> <Dd>, <Dm>
12967 (Register operations, which are VORR with Rm = Rn.)
12968 2. VMOV<c><q>.<dt> <Qd>, #<imm>
12969 3. VMOV<c><q>.<dt> <Dd>, #<imm>
12970 (Immediate loads.)
12971 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
12972 (ARM register to scalar.)
12973 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
12974 (Two ARM registers to vector.)
12975 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
12976 (Scalar to ARM register.)
12977 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
12978 (Vector to two ARM registers.)
037e8744
JB
12979 8. VMOV.F32 <Sd>, <Sm>
12980 9. VMOV.F64 <Dd>, <Dm>
12981 (VFP register moves.)
12982 10. VMOV.F32 <Sd>, #imm
12983 11. VMOV.F64 <Dd>, #imm
12984 (VFP float immediate load.)
12985 12. VMOV <Rd>, <Sm>
12986 (VFP single to ARM reg.)
12987 13. VMOV <Sd>, <Rm>
12988 (ARM reg to VFP single.)
12989 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
12990 (Two ARM regs to two VFP singles.)
12991 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
12992 (Two VFP singles to two ARM regs.)
5287ad62 12993
037e8744
JB
12994 These cases can be disambiguated using neon_select_shape, except cases 1/9
12995 and 3/11 which depend on the operand type too.
5287ad62
JB
12996
12997 All the encoded bits are hardcoded by this function.
12998
b7fc2769
JB
12999 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13000 Cases 5, 7 may be used with VFPv2 and above.
13001
5287ad62
JB
13002 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13003 can specify a type where it doesn't make sense to, and is ignored).
13004*/
13005
13006static void
13007do_neon_mov (void)
13008{
037e8744
JB
13009 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13010 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13011 NS_NULL);
13012 struct neon_type_el et;
13013 const char *ldconst = 0;
5287ad62 13014
037e8744 13015 switch (rs)
5287ad62 13016 {
037e8744
JB
13017 case NS_DD: /* case 1/9. */
13018 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13019 /* It is not an error here if no type is given. */
13020 inst.error = NULL;
13021 if (et.type == NT_float && et.size == 64)
5287ad62 13022 {
037e8744
JB
13023 do_vfp_nsyn_opcode ("fcpyd");
13024 break;
5287ad62 13025 }
037e8744 13026 /* fall through. */
5287ad62 13027
037e8744
JB
13028 case NS_QQ: /* case 0/1. */
13029 {
13030 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13031 return;
13032 /* The architecture manual I have doesn't explicitly state which
13033 value the U bit should have for register->register moves, but
13034 the equivalent VORR instruction has U = 0, so do that. */
13035 inst.instruction = 0x0200110;
13036 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13037 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13038 inst.instruction |= LOW4 (inst.operands[1].reg);
13039 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13040 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13041 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13042 inst.instruction |= neon_quad (rs) << 6;
13043
13044 inst.instruction = neon_dp_fixup (inst.instruction);
13045 }
13046 break;
13047
13048 case NS_DI: /* case 3/11. */
13049 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13050 inst.error = NULL;
13051 if (et.type == NT_float && et.size == 64)
5287ad62 13052 {
037e8744
JB
13053 /* case 11 (fconstd). */
13054 ldconst = "fconstd";
13055 goto encode_fconstd;
5287ad62 13056 }
037e8744
JB
13057 /* fall through. */
13058
13059 case NS_QI: /* case 2/3. */
13060 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13061 return;
13062 inst.instruction = 0x0800010;
13063 neon_move_immediate ();
13064 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62
JB
13065 break;
13066
037e8744
JB
13067 case NS_SR: /* case 4. */
13068 {
13069 unsigned bcdebits = 0;
13070 struct neon_type_el et = neon_check_type (2, NS_NULL,
13071 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13072 int logsize = neon_logbits (et.size);
13073 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13074 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13075
13076 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13077 _(BAD_FPU));
13078 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13079 && et.size != 32, _(BAD_FPU));
13080 constraint (et.type == NT_invtype, _("bad type for scalar"));
13081 constraint (x >= 64 / et.size, _("scalar index out of range"));
13082
13083 switch (et.size)
13084 {
13085 case 8: bcdebits = 0x8; break;
13086 case 16: bcdebits = 0x1; break;
13087 case 32: bcdebits = 0x0; break;
13088 default: ;
13089 }
13090
13091 bcdebits |= x << logsize;
13092
13093 inst.instruction = 0xe000b10;
13094 do_vfp_cond_or_thumb ();
13095 inst.instruction |= LOW4 (dn) << 16;
13096 inst.instruction |= HI1 (dn) << 7;
13097 inst.instruction |= inst.operands[1].reg << 12;
13098 inst.instruction |= (bcdebits & 3) << 5;
13099 inst.instruction |= (bcdebits >> 2) << 21;
13100 }
13101 break;
13102
13103 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13104 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13105 _(BAD_FPU));
b7fc2769 13106
037e8744
JB
13107 inst.instruction = 0xc400b10;
13108 do_vfp_cond_or_thumb ();
13109 inst.instruction |= LOW4 (inst.operands[0].reg);
13110 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13111 inst.instruction |= inst.operands[1].reg << 12;
13112 inst.instruction |= inst.operands[2].reg << 16;
13113 break;
13114
13115 case NS_RS: /* case 6. */
13116 {
13117 struct neon_type_el et = neon_check_type (2, NS_NULL,
13118 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13119 unsigned logsize = neon_logbits (et.size);
13120 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13121 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13122 unsigned abcdebits = 0;
13123
13124 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13125 _(BAD_FPU));
13126 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13127 && et.size != 32, _(BAD_FPU));
13128 constraint (et.type == NT_invtype, _("bad type for scalar"));
13129 constraint (x >= 64 / et.size, _("scalar index out of range"));
13130
13131 switch (et.size)
13132 {
13133 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13134 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13135 case 32: abcdebits = 0x00; break;
13136 default: ;
13137 }
13138
13139 abcdebits |= x << logsize;
13140 inst.instruction = 0xe100b10;
13141 do_vfp_cond_or_thumb ();
13142 inst.instruction |= LOW4 (dn) << 16;
13143 inst.instruction |= HI1 (dn) << 7;
13144 inst.instruction |= inst.operands[0].reg << 12;
13145 inst.instruction |= (abcdebits & 3) << 5;
13146 inst.instruction |= (abcdebits >> 2) << 21;
13147 }
13148 break;
13149
13150 case NS_RRD: /* case 7 (fmrrd). */
13151 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13152 _(BAD_FPU));
13153
13154 inst.instruction = 0xc500b10;
13155 do_vfp_cond_or_thumb ();
13156 inst.instruction |= inst.operands[0].reg << 12;
13157 inst.instruction |= inst.operands[1].reg << 16;
13158 inst.instruction |= LOW4 (inst.operands[2].reg);
13159 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13160 break;
13161
13162 case NS_FF: /* case 8 (fcpys). */
13163 do_vfp_nsyn_opcode ("fcpys");
13164 break;
13165
13166 case NS_FI: /* case 10 (fconsts). */
13167 ldconst = "fconsts";
13168 encode_fconstd:
13169 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13170 {
037e8744
JB
13171 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13172 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13173 }
13174 else
037e8744
JB
13175 first_error (_("immediate out of range"));
13176 break;
13177
13178 case NS_RF: /* case 12 (fmrs). */
13179 do_vfp_nsyn_opcode ("fmrs");
13180 break;
13181
13182 case NS_FR: /* case 13 (fmsr). */
13183 do_vfp_nsyn_opcode ("fmsr");
13184 break;
13185
13186 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13187 (one of which is a list), but we have parsed four. Do some fiddling to
13188 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13189 expect. */
13190 case NS_RRFF: /* case 14 (fmrrs). */
13191 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13192 _("VFP registers must be adjacent"));
13193 inst.operands[2].imm = 2;
13194 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13195 do_vfp_nsyn_opcode ("fmrrs");
13196 break;
13197
13198 case NS_FFRR: /* case 15 (fmsrr). */
13199 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13200 _("VFP registers must be adjacent"));
13201 inst.operands[1] = inst.operands[2];
13202 inst.operands[2] = inst.operands[3];
13203 inst.operands[0].imm = 2;
13204 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13205 do_vfp_nsyn_opcode ("fmsrr");
5287ad62
JB
13206 break;
13207
13208 default:
13209 abort ();
13210 }
13211}
13212
13213static void
13214do_neon_rshift_round_imm (void)
13215{
037e8744 13216 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13217 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13218 int imm = inst.operands[2].imm;
13219
13220 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13221 if (imm == 0)
13222 {
13223 inst.operands[2].present = 0;
13224 do_neon_mov ();
13225 return;
13226 }
13227
13228 constraint (imm < 1 || (unsigned)imm > et.size,
13229 _("immediate out of range for shift"));
037e8744 13230 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13231 et.size - imm);
13232}
13233
13234static void
13235do_neon_movl (void)
13236{
13237 struct neon_type_el et = neon_check_type (2, NS_QD,
13238 N_EQK | N_DBL, N_SU_32 | N_KEY);
13239 unsigned sizebits = et.size >> 3;
13240 inst.instruction |= sizebits << 19;
13241 neon_two_same (0, et.type == NT_unsigned, -1);
13242}
13243
13244static void
13245do_neon_trn (void)
13246{
037e8744 13247 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13248 struct neon_type_el et = neon_check_type (2, rs,
13249 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13250 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13251 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13252}
13253
13254static void
13255do_neon_zip_uzp (void)
13256{
037e8744 13257 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13258 struct neon_type_el et = neon_check_type (2, rs,
13259 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13260 if (rs == NS_DD && et.size == 32)
13261 {
13262 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13263 inst.instruction = N_MNEM_vtrn;
13264 do_neon_trn ();
13265 return;
13266 }
037e8744 13267 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13268}
13269
13270static void
13271do_neon_sat_abs_neg (void)
13272{
037e8744 13273 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13274 struct neon_type_el et = neon_check_type (2, rs,
13275 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13276 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13277}
13278
13279static void
13280do_neon_pair_long (void)
13281{
037e8744 13282 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13283 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13284 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13285 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13286 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13287}
13288
13289static void
13290do_neon_recip_est (void)
13291{
037e8744 13292 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13293 struct neon_type_el et = neon_check_type (2, rs,
13294 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13295 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13296 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13297}
13298
13299static void
13300do_neon_cls (void)
13301{
037e8744 13302 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13303 struct neon_type_el et = neon_check_type (2, rs,
13304 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13305 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13306}
13307
13308static void
13309do_neon_clz (void)
13310{
037e8744 13311 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13312 struct neon_type_el et = neon_check_type (2, rs,
13313 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13314 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13315}
13316
13317static void
13318do_neon_cnt (void)
13319{
037e8744 13320 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13321 struct neon_type_el et = neon_check_type (2, rs,
13322 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13323 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13324}
13325
13326static void
13327do_neon_swp (void)
13328{
037e8744
JB
13329 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13330 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13331}
13332
13333static void
13334do_neon_tbl_tbx (void)
13335{
13336 unsigned listlenbits;
dcbf9037 13337 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5287ad62
JB
13338
13339 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13340 {
dcbf9037 13341 first_error (_("bad list length for table lookup"));
5287ad62
JB
13342 return;
13343 }
13344
13345 listlenbits = inst.operands[1].imm - 1;
13346 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13347 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13348 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13349 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13350 inst.instruction |= LOW4 (inst.operands[2].reg);
13351 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13352 inst.instruction |= listlenbits << 8;
13353
13354 inst.instruction = neon_dp_fixup (inst.instruction);
13355}
13356
13357static void
13358do_neon_ldm_stm (void)
13359{
13360 /* P, U and L bits are part of bitmask. */
13361 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13362 unsigned offsetbits = inst.operands[1].imm * 2;
13363
037e8744
JB
13364 if (inst.operands[1].issingle)
13365 {
13366 do_vfp_nsyn_ldm_stm (is_dbmode);
13367 return;
13368 }
13369
5287ad62
JB
13370 constraint (is_dbmode && !inst.operands[0].writeback,
13371 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13372
13373 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13374 _("register list must contain at least 1 and at most 16 "
13375 "registers"));
13376
13377 inst.instruction |= inst.operands[0].reg << 16;
13378 inst.instruction |= inst.operands[0].writeback << 21;
13379 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13380 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13381
13382 inst.instruction |= offsetbits;
13383
037e8744 13384 do_vfp_cond_or_thumb ();
5287ad62
JB
13385}
13386
13387static void
13388do_neon_ldr_str (void)
13389{
5287ad62
JB
13390 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13391
037e8744
JB
13392 if (inst.operands[0].issingle)
13393 {
cd2f129f
JB
13394 if (is_ldr)
13395 do_vfp_nsyn_opcode ("flds");
13396 else
13397 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13398 }
13399 else
5287ad62 13400 {
cd2f129f
JB
13401 if (is_ldr)
13402 do_vfp_nsyn_opcode ("fldd");
5287ad62 13403 else
cd2f129f 13404 do_vfp_nsyn_opcode ("fstd");
5287ad62 13405 }
5287ad62
JB
13406}
13407
13408/* "interleave" version also handles non-interleaving register VLD1/VST1
13409 instructions. */
13410
13411static void
13412do_neon_ld_st_interleave (void)
13413{
037e8744 13414 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13415 N_8 | N_16 | N_32 | N_64);
13416 unsigned alignbits = 0;
13417 unsigned idx;
13418 /* The bits in this table go:
13419 0: register stride of one (0) or two (1)
13420 1,2: register list length, minus one (1, 2, 3, 4).
13421 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13422 We use -1 for invalid entries. */
13423 const int typetable[] =
13424 {
13425 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13426 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13427 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13428 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13429 };
13430 int typebits;
13431
dcbf9037
JB
13432 if (et.type == NT_invtype)
13433 return;
13434
5287ad62
JB
13435 if (inst.operands[1].immisalign)
13436 switch (inst.operands[1].imm >> 8)
13437 {
13438 case 64: alignbits = 1; break;
13439 case 128:
13440 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13441 goto bad_alignment;
13442 alignbits = 2;
13443 break;
13444 case 256:
13445 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13446 goto bad_alignment;
13447 alignbits = 3;
13448 break;
13449 default:
13450 bad_alignment:
dcbf9037 13451 first_error (_("bad alignment"));
5287ad62
JB
13452 return;
13453 }
13454
13455 inst.instruction |= alignbits << 4;
13456 inst.instruction |= neon_logbits (et.size) << 6;
13457
13458 /* Bits [4:6] of the immediate in a list specifier encode register stride
13459 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13460 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13461 up the right value for "type" in a table based on this value and the given
13462 list style, then stick it back. */
13463 idx = ((inst.operands[0].imm >> 4) & 7)
13464 | (((inst.instruction >> 8) & 3) << 3);
13465
13466 typebits = typetable[idx];
13467
13468 constraint (typebits == -1, _("bad list type for instruction"));
13469
13470 inst.instruction &= ~0xf00;
13471 inst.instruction |= typebits << 8;
13472}
13473
13474/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13475 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13476 otherwise. The variable arguments are a list of pairs of legal (size, align)
13477 values, terminated with -1. */
13478
13479static int
13480neon_alignment_bit (int size, int align, int *do_align, ...)
13481{
13482 va_list ap;
13483 int result = FAIL, thissize, thisalign;
13484
13485 if (!inst.operands[1].immisalign)
13486 {
13487 *do_align = 0;
13488 return SUCCESS;
13489 }
13490
13491 va_start (ap, do_align);
13492
13493 do
13494 {
13495 thissize = va_arg (ap, int);
13496 if (thissize == -1)
13497 break;
13498 thisalign = va_arg (ap, int);
13499
13500 if (size == thissize && align == thisalign)
13501 result = SUCCESS;
13502 }
13503 while (result != SUCCESS);
13504
13505 va_end (ap);
13506
13507 if (result == SUCCESS)
13508 *do_align = 1;
13509 else
dcbf9037 13510 first_error (_("unsupported alignment for instruction"));
5287ad62
JB
13511
13512 return result;
13513}
13514
13515static void
13516do_neon_ld_st_lane (void)
13517{
037e8744 13518 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13519 int align_good, do_align = 0;
13520 int logsize = neon_logbits (et.size);
13521 int align = inst.operands[1].imm >> 8;
13522 int n = (inst.instruction >> 8) & 3;
13523 int max_el = 64 / et.size;
13524
dcbf9037
JB
13525 if (et.type == NT_invtype)
13526 return;
13527
5287ad62
JB
13528 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13529 _("bad list length"));
13530 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13531 _("scalar index out of range"));
13532 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13533 && et.size == 8,
13534 _("stride of 2 unavailable when element size is 8"));
13535
13536 switch (n)
13537 {
13538 case 0: /* VLD1 / VST1. */
13539 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13540 32, 32, -1);
13541 if (align_good == FAIL)
13542 return;
13543 if (do_align)
13544 {
13545 unsigned alignbits = 0;
13546 switch (et.size)
13547 {
13548 case 16: alignbits = 0x1; break;
13549 case 32: alignbits = 0x3; break;
13550 default: ;
13551 }
13552 inst.instruction |= alignbits << 4;
13553 }
13554 break;
13555
13556 case 1: /* VLD2 / VST2. */
13557 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13558 32, 64, -1);
13559 if (align_good == FAIL)
13560 return;
13561 if (do_align)
13562 inst.instruction |= 1 << 4;
13563 break;
13564
13565 case 2: /* VLD3 / VST3. */
13566 constraint (inst.operands[1].immisalign,
13567 _("can't use alignment with this instruction"));
13568 break;
13569
13570 case 3: /* VLD4 / VST4. */
13571 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13572 16, 64, 32, 64, 32, 128, -1);
13573 if (align_good == FAIL)
13574 return;
13575 if (do_align)
13576 {
13577 unsigned alignbits = 0;
13578 switch (et.size)
13579 {
13580 case 8: alignbits = 0x1; break;
13581 case 16: alignbits = 0x1; break;
13582 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13583 default: ;
13584 }
13585 inst.instruction |= alignbits << 4;
13586 }
13587 break;
13588
13589 default: ;
13590 }
13591
13592 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13593 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13594 inst.instruction |= 1 << (4 + logsize);
13595
13596 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13597 inst.instruction |= logsize << 10;
13598}
13599
13600/* Encode single n-element structure to all lanes VLD<n> instructions. */
13601
13602static void
13603do_neon_ld_dup (void)
13604{
037e8744 13605 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13606 int align_good, do_align = 0;
13607
dcbf9037
JB
13608 if (et.type == NT_invtype)
13609 return;
13610
5287ad62
JB
13611 switch ((inst.instruction >> 8) & 3)
13612 {
13613 case 0: /* VLD1. */
13614 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13615 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13616 &do_align, 16, 16, 32, 32, -1);
13617 if (align_good == FAIL)
13618 return;
13619 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13620 {
13621 case 1: break;
13622 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13623 default: first_error (_("bad list length")); return;
5287ad62
JB
13624 }
13625 inst.instruction |= neon_logbits (et.size) << 6;
13626 break;
13627
13628 case 1: /* VLD2. */
13629 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13630 &do_align, 8, 16, 16, 32, 32, 64, -1);
13631 if (align_good == FAIL)
13632 return;
13633 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13634 _("bad list length"));
13635 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13636 inst.instruction |= 1 << 5;
13637 inst.instruction |= neon_logbits (et.size) << 6;
13638 break;
13639
13640 case 2: /* VLD3. */
13641 constraint (inst.operands[1].immisalign,
13642 _("can't use alignment with this instruction"));
13643 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13644 _("bad list length"));
13645 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13646 inst.instruction |= 1 << 5;
13647 inst.instruction |= neon_logbits (et.size) << 6;
13648 break;
13649
13650 case 3: /* VLD4. */
13651 {
13652 int align = inst.operands[1].imm >> 8;
13653 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13654 16, 64, 32, 64, 32, 128, -1);
13655 if (align_good == FAIL)
13656 return;
13657 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13658 _("bad list length"));
13659 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13660 inst.instruction |= 1 << 5;
13661 if (et.size == 32 && align == 128)
13662 inst.instruction |= 0x3 << 6;
13663 else
13664 inst.instruction |= neon_logbits (et.size) << 6;
13665 }
13666 break;
13667
13668 default: ;
13669 }
13670
13671 inst.instruction |= do_align << 4;
13672}
13673
13674/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13675 apart from bits [11:4]. */
13676
13677static void
13678do_neon_ldx_stx (void)
13679{
13680 switch (NEON_LANE (inst.operands[0].imm))
13681 {
13682 case NEON_INTERLEAVE_LANES:
13683 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13684 do_neon_ld_st_interleave ();
13685 break;
13686
13687 case NEON_ALL_LANES:
13688 inst.instruction = NEON_ENC_DUP (inst.instruction);
13689 do_neon_ld_dup ();
13690 break;
13691
13692 default:
13693 inst.instruction = NEON_ENC_LANE (inst.instruction);
13694 do_neon_ld_st_lane ();
13695 }
13696
13697 /* L bit comes from bit mask. */
13698 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13699 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13700 inst.instruction |= inst.operands[1].reg << 16;
13701
13702 if (inst.operands[1].postind)
13703 {
13704 int postreg = inst.operands[1].imm & 0xf;
13705 constraint (!inst.operands[1].immisreg,
13706 _("post-index must be a register"));
13707 constraint (postreg == 0xd || postreg == 0xf,
13708 _("bad register for post-index"));
13709 inst.instruction |= postreg;
13710 }
13711 else if (inst.operands[1].writeback)
13712 {
13713 inst.instruction |= 0xd;
13714 }
13715 else
13716 inst.instruction |= 0xf;
13717
13718 if (thumb_mode)
13719 inst.instruction |= 0xf9000000;
13720 else
13721 inst.instruction |= 0xf4000000;
13722}
13723
13724\f
13725/* Overall per-instruction processing. */
13726
13727/* We need to be able to fix up arbitrary expressions in some statements.
13728 This is so that we can handle symbols that are an arbitrary distance from
13729 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13730 which returns part of an address in a form which will be valid for
13731 a data instruction. We do this by pushing the expression into a symbol
13732 in the expr_section, and creating a fix for that. */
13733
13734static void
13735fix_new_arm (fragS * frag,
13736 int where,
13737 short int size,
13738 expressionS * exp,
13739 int pc_rel,
13740 int reloc)
13741{
13742 fixS * new_fix;
13743
13744 switch (exp->X_op)
13745 {
13746 case O_constant:
13747 case O_symbol:
13748 case O_add:
13749 case O_subtract:
13750 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13751 break;
13752
13753 default:
13754 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13755 pc_rel, reloc);
13756 break;
13757 }
13758
13759 /* Mark whether the fix is to a THUMB instruction, or an ARM
13760 instruction. */
13761 new_fix->tc_fix_data = thumb_mode;
13762}
13763
13764/* Create a frg for an instruction requiring relaxation. */
13765static void
13766output_relax_insn (void)
13767{
13768 char * to;
13769 symbolS *sym;
0110f2b8
PB
13770 int offset;
13771
6e1cb1a6
PB
13772 /* The size of the instruction is unknown, so tie the debug info to the
13773 start of the instruction. */
13774 dwarf2_emit_insn (0);
6e1cb1a6 13775
0110f2b8
PB
13776 switch (inst.reloc.exp.X_op)
13777 {
13778 case O_symbol:
13779 sym = inst.reloc.exp.X_add_symbol;
13780 offset = inst.reloc.exp.X_add_number;
13781 break;
13782 case O_constant:
13783 sym = NULL;
13784 offset = inst.reloc.exp.X_add_number;
13785 break;
13786 default:
13787 sym = make_expr_symbol (&inst.reloc.exp);
13788 offset = 0;
13789 break;
13790 }
13791 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13792 inst.relax, sym, offset, NULL/*offset, opcode*/);
13793 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13794}
13795
13796/* Write a 32-bit thumb instruction to buf. */
13797static void
13798put_thumb32_insn (char * buf, unsigned long insn)
13799{
13800 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13801 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13802}
13803
b99bd4ef 13804static void
c19d1205 13805output_inst (const char * str)
b99bd4ef 13806{
c19d1205 13807 char * to = NULL;
b99bd4ef 13808
c19d1205 13809 if (inst.error)
b99bd4ef 13810 {
c19d1205 13811 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13812 return;
13813 }
0110f2b8
PB
13814 if (inst.relax) {
13815 output_relax_insn();
13816 return;
13817 }
c19d1205
ZW
13818 if (inst.size == 0)
13819 return;
b99bd4ef 13820
c19d1205
ZW
13821 to = frag_more (inst.size);
13822
13823 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13824 {
c19d1205 13825 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13826 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13827 }
c19d1205 13828 else if (inst.size > INSN_SIZE)
b99bd4ef 13829 {
c19d1205
ZW
13830 assert (inst.size == (2 * INSN_SIZE));
13831 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13832 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13833 }
c19d1205
ZW
13834 else
13835 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13836
c19d1205
ZW
13837 if (inst.reloc.type != BFD_RELOC_UNUSED)
13838 fix_new_arm (frag_now, to - frag_now->fr_literal,
13839 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13840 inst.reloc.type);
b99bd4ef 13841
c19d1205 13842 dwarf2_emit_insn (inst.size);
c19d1205 13843}
b99bd4ef 13844
c19d1205
ZW
13845/* Tag values used in struct asm_opcode's tag field. */
13846enum opcode_tag
13847{
13848 OT_unconditional, /* Instruction cannot be conditionalized.
13849 The ARM condition field is still 0xE. */
13850 OT_unconditionalF, /* Instruction cannot be conditionalized
13851 and carries 0xF in its ARM condition field. */
13852 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13853 OT_csuffixF, /* Some forms of the instruction take a conditional
13854 suffix, others place 0xF where the condition field
13855 would be. */
c19d1205
ZW
13856 OT_cinfix3, /* Instruction takes a conditional infix,
13857 beginning at character index 3. (In
13858 unified mode, it becomes a suffix.) */
088fa78e
KH
13859 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13860 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13861 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13862 character index 3, even in unified mode. Used for
13863 legacy instructions where suffix and infix forms
13864 may be ambiguous. */
c19d1205 13865 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13866 suffix or an infix at character index 3. */
c19d1205
ZW
13867 OT_odd_infix_unc, /* This is the unconditional variant of an
13868 instruction that takes a conditional infix
13869 at an unusual position. In unified mode,
13870 this variant will accept a suffix. */
13871 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13872 are the conditional variants of instructions that
13873 take conditional infixes in unusual positions.
13874 The infix appears at character index
13875 (tag - OT_odd_infix_0). These are not accepted
13876 in unified mode. */
13877};
b99bd4ef 13878
c19d1205
ZW
13879/* Subroutine of md_assemble, responsible for looking up the primary
13880 opcode from the mnemonic the user wrote. STR points to the
13881 beginning of the mnemonic.
13882
13883 This is not simply a hash table lookup, because of conditional
13884 variants. Most instructions have conditional variants, which are
13885 expressed with a _conditional affix_ to the mnemonic. If we were
13886 to encode each conditional variant as a literal string in the opcode
13887 table, it would have approximately 20,000 entries.
13888
13889 Most mnemonics take this affix as a suffix, and in unified syntax,
13890 'most' is upgraded to 'all'. However, in the divided syntax, some
13891 instructions take the affix as an infix, notably the s-variants of
13892 the arithmetic instructions. Of those instructions, all but six
13893 have the infix appear after the third character of the mnemonic.
13894
13895 Accordingly, the algorithm for looking up primary opcodes given
13896 an identifier is:
13897
13898 1. Look up the identifier in the opcode table.
13899 If we find a match, go to step U.
13900
13901 2. Look up the last two characters of the identifier in the
13902 conditions table. If we find a match, look up the first N-2
13903 characters of the identifier in the opcode table. If we
13904 find a match, go to step CE.
13905
13906 3. Look up the fourth and fifth characters of the identifier in
13907 the conditions table. If we find a match, extract those
13908 characters from the identifier, and look up the remaining
13909 characters in the opcode table. If we find a match, go
13910 to step CM.
13911
13912 4. Fail.
13913
13914 U. Examine the tag field of the opcode structure, in case this is
13915 one of the six instructions with its conditional infix in an
13916 unusual place. If it is, the tag tells us where to find the
13917 infix; look it up in the conditions table and set inst.cond
13918 accordingly. Otherwise, this is an unconditional instruction.
13919 Again set inst.cond accordingly. Return the opcode structure.
13920
13921 CE. Examine the tag field to make sure this is an instruction that
13922 should receive a conditional suffix. If it is not, fail.
13923 Otherwise, set inst.cond from the suffix we already looked up,
13924 and return the opcode structure.
13925
13926 CM. Examine the tag field to make sure this is an instruction that
13927 should receive a conditional infix after the third character.
13928 If it is not, fail. Otherwise, undo the edits to the current
13929 line of input and proceed as for case CE. */
13930
13931static const struct asm_opcode *
13932opcode_lookup (char **str)
13933{
13934 char *end, *base;
13935 char *affix;
13936 const struct asm_opcode *opcode;
13937 const struct asm_cond *cond;
e3cb604e 13938 char save[2];
267d2029
JB
13939 bfd_boolean neon_supported;
13940
13941 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
13942
13943 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 13944 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 13945 for (base = end = *str; *end != '\0'; end++)
267d2029 13946 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 13947 break;
b99bd4ef 13948
c19d1205
ZW
13949 if (end == base)
13950 return 0;
b99bd4ef 13951
5287ad62 13952 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 13953 if (end[0] == '.')
b99bd4ef 13954 {
5287ad62
JB
13955 int offset = 2;
13956
267d2029
JB
13957 /* The .w and .n suffixes are only valid if the unified syntax is in
13958 use. */
13959 if (unified_syntax && end[1] == 'w')
c19d1205 13960 inst.size_req = 4;
267d2029 13961 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
13962 inst.size_req = 2;
13963 else
5287ad62
JB
13964 offset = 0;
13965
13966 inst.vectype.elems = 0;
13967
13968 *str = end + offset;
b99bd4ef 13969
5287ad62
JB
13970 if (end[offset] == '.')
13971 {
267d2029
JB
13972 /* See if we have a Neon type suffix (possible in either unified or
13973 non-unified ARM syntax mode). */
dcbf9037 13974 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
13975 return 0;
13976 }
13977 else if (end[offset] != '\0' && end[offset] != ' ')
13978 return 0;
b99bd4ef 13979 }
c19d1205
ZW
13980 else
13981 *str = end;
b99bd4ef 13982
c19d1205
ZW
13983 /* Look for unaffixed or special-case affixed mnemonic. */
13984 opcode = hash_find_n (arm_ops_hsh, base, end - base);
13985 if (opcode)
b99bd4ef 13986 {
c19d1205
ZW
13987 /* step U */
13988 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 13989 {
c19d1205
ZW
13990 inst.cond = COND_ALWAYS;
13991 return opcode;
b99bd4ef 13992 }
b99bd4ef 13993
c19d1205
ZW
13994 if (unified_syntax)
13995 as_warn (_("conditional infixes are deprecated in unified syntax"));
13996 affix = base + (opcode->tag - OT_odd_infix_0);
13997 cond = hash_find_n (arm_cond_hsh, affix, 2);
13998 assert (cond);
b99bd4ef 13999
c19d1205
ZW
14000 inst.cond = cond->value;
14001 return opcode;
14002 }
b99bd4ef 14003
c19d1205
ZW
14004 /* Cannot have a conditional suffix on a mnemonic of less than two
14005 characters. */
14006 if (end - base < 3)
14007 return 0;
b99bd4ef 14008
c19d1205
ZW
14009 /* Look for suffixed mnemonic. */
14010 affix = end - 2;
14011 cond = hash_find_n (arm_cond_hsh, affix, 2);
14012 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14013 if (opcode && cond)
14014 {
14015 /* step CE */
14016 switch (opcode->tag)
14017 {
e3cb604e
PB
14018 case OT_cinfix3_legacy:
14019 /* Ignore conditional suffixes matched on infix only mnemonics. */
14020 break;
14021
c19d1205 14022 case OT_cinfix3:
088fa78e 14023 case OT_cinfix3_deprecated:
c19d1205
ZW
14024 case OT_odd_infix_unc:
14025 if (!unified_syntax)
e3cb604e 14026 return 0;
c19d1205
ZW
14027 /* else fall through */
14028
14029 case OT_csuffix:
037e8744 14030 case OT_csuffixF:
c19d1205
ZW
14031 case OT_csuf_or_in3:
14032 inst.cond = cond->value;
14033 return opcode;
14034
14035 case OT_unconditional:
14036 case OT_unconditionalF:
dfa9f0d5
PB
14037 if (thumb_mode)
14038 {
14039 inst.cond = cond->value;
14040 }
14041 else
14042 {
14043 /* delayed diagnostic */
14044 inst.error = BAD_COND;
14045 inst.cond = COND_ALWAYS;
14046 }
c19d1205 14047 return opcode;
b99bd4ef 14048
c19d1205
ZW
14049 default:
14050 return 0;
14051 }
14052 }
b99bd4ef 14053
c19d1205
ZW
14054 /* Cannot have a usual-position infix on a mnemonic of less than
14055 six characters (five would be a suffix). */
14056 if (end - base < 6)
14057 return 0;
b99bd4ef 14058
c19d1205
ZW
14059 /* Look for infixed mnemonic in the usual position. */
14060 affix = base + 3;
14061 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14062 if (!cond)
14063 return 0;
14064
14065 memcpy (save, affix, 2);
14066 memmove (affix, affix + 2, (end - affix) - 2);
14067 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14068 memmove (affix + 2, affix, (end - affix) - 2);
14069 memcpy (affix, save, 2);
14070
088fa78e
KH
14071 if (opcode
14072 && (opcode->tag == OT_cinfix3
14073 || opcode->tag == OT_cinfix3_deprecated
14074 || opcode->tag == OT_csuf_or_in3
14075 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14076 {
c19d1205 14077 /* step CM */
088fa78e
KH
14078 if (unified_syntax
14079 && (opcode->tag == OT_cinfix3
14080 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14081 as_warn (_("conditional infixes are deprecated in unified syntax"));
14082
14083 inst.cond = cond->value;
14084 return opcode;
b99bd4ef
NC
14085 }
14086
c19d1205 14087 return 0;
b99bd4ef
NC
14088}
14089
c19d1205
ZW
14090void
14091md_assemble (char *str)
b99bd4ef 14092{
c19d1205
ZW
14093 char *p = str;
14094 const struct asm_opcode * opcode;
b99bd4ef 14095
c19d1205
ZW
14096 /* Align the previous label if needed. */
14097 if (last_label_seen != NULL)
b99bd4ef 14098 {
c19d1205
ZW
14099 symbol_set_frag (last_label_seen, frag_now);
14100 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14101 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14102 }
14103
c19d1205
ZW
14104 memset (&inst, '\0', sizeof (inst));
14105 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14106
c19d1205
ZW
14107 opcode = opcode_lookup (&p);
14108 if (!opcode)
b99bd4ef 14109 {
c19d1205 14110 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14111 the form alias .req reg, or a Neon .dn/.qn directive. */
14112 if (!create_register_alias (str, p)
14113 && !create_neon_reg_alias (str, p))
c19d1205 14114 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14115
b99bd4ef
NC
14116 return;
14117 }
14118
088fa78e
KH
14119 if (opcode->tag == OT_cinfix3_deprecated)
14120 as_warn (_("s suffix on comparison instruction is deprecated"));
14121
037e8744
JB
14122 /* The value which unconditional instructions should have in place of the
14123 condition field. */
14124 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14125
c19d1205 14126 if (thumb_mode)
b99bd4ef 14127 {
e74cfd16 14128 arm_feature_set variant;
8f06b2d8
PB
14129
14130 variant = cpu_variant;
14131 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14132 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14133 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14134 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14135 if (!opcode->tvariant
14136 || (thumb_mode == 1
14137 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14138 {
c19d1205 14139 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14140 return;
14141 }
c19d1205
ZW
14142 if (inst.cond != COND_ALWAYS && !unified_syntax
14143 && opcode->tencode != do_t_branch)
b99bd4ef 14144 {
c19d1205 14145 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14146 return;
14147 }
14148
076d447c
PB
14149 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14150 {
14151 /* Implicit require narrow instructions on Thumb-1. This avoids
14152 relaxation accidentally introducing Thumb-2 instructions. */
14153 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23)
14154 inst.size_req = 2;
14155 }
14156
e27ec89e
PB
14157 /* Check conditional suffixes. */
14158 if (current_it_mask)
14159 {
14160 int cond;
14161 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14162 current_it_mask <<= 1;
14163 current_it_mask &= 0x1f;
14164 /* The BKPT instruction is unconditional even in an IT block. */
14165 if (!inst.error
14166 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14167 {
14168 as_bad (_("incorrect condition in IT block"));
14169 return;
14170 }
e27ec89e
PB
14171 }
14172 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14173 {
14174 as_bad (_("thumb conditional instrunction not in IT block"));
14175 return;
14176 }
14177
c19d1205
ZW
14178 mapping_state (MAP_THUMB);
14179 inst.instruction = opcode->tvalue;
14180
14181 if (!parse_operands (p, opcode->operands))
14182 opcode->tencode ();
14183
e27ec89e
PB
14184 /* Clear current_it_mask at the end of an IT block. */
14185 if (current_it_mask == 0x10)
14186 current_it_mask = 0;
14187
0110f2b8 14188 if (!(inst.error || inst.relax))
b99bd4ef 14189 {
c19d1205
ZW
14190 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14191 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14192 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14193 {
c19d1205 14194 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14195 return;
14196 }
14197 }
076d447c
PB
14198
14199 /* Something has gone badly wrong if we try to relax a fixed size
14200 instruction. */
14201 assert (inst.size_req == 0 || !inst.relax);
14202
e74cfd16
PB
14203 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14204 *opcode->tvariant);
ee065d83 14205 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14206 set those bits when Thumb-2 32-bit instructions are seen. ie.
ee065d83
PB
14207 anything other than bl/blx.
14208 This is overly pessimistic for relaxable instructions. */
14209 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14210 || inst.relax)
e74cfd16
PB
14211 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14212 arm_ext_v6t2);
c19d1205 14213 }
3e9e4fcf 14214 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
14215 {
14216 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14217 if (!opcode->avariant ||
14218 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 14219 {
c19d1205
ZW
14220 as_bad (_("selected processor does not support `%s'"), str);
14221 return;
b99bd4ef 14222 }
c19d1205 14223 if (inst.size_req)
b99bd4ef 14224 {
c19d1205
ZW
14225 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14226 return;
b99bd4ef
NC
14227 }
14228
c19d1205
ZW
14229 mapping_state (MAP_ARM);
14230 inst.instruction = opcode->avalue;
14231 if (opcode->tag == OT_unconditionalF)
14232 inst.instruction |= 0xF << 28;
14233 else
14234 inst.instruction |= inst.cond << 28;
14235 inst.size = INSN_SIZE;
14236 if (!parse_operands (p, opcode->operands))
14237 opcode->aencode ();
ee065d83
PB
14238 /* Arm mode bx is marked as both v4T and v5 because it's still required
14239 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
14240 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
14241 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
14242 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14243 else
e74cfd16
PB
14244 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14245 *opcode->avariant);
b99bd4ef 14246 }
3e9e4fcf
JB
14247 else
14248 {
14249 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14250 "-- `%s'"), str);
14251 return;
14252 }
c19d1205
ZW
14253 output_inst (str);
14254}
b99bd4ef 14255
c19d1205
ZW
14256/* Various frobbings of labels and their addresses. */
14257
14258void
14259arm_start_line_hook (void)
14260{
14261 last_label_seen = NULL;
b99bd4ef
NC
14262}
14263
c19d1205
ZW
14264void
14265arm_frob_label (symbolS * sym)
b99bd4ef 14266{
c19d1205 14267 last_label_seen = sym;
b99bd4ef 14268
c19d1205 14269 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14270
c19d1205
ZW
14271#if defined OBJ_COFF || defined OBJ_ELF
14272 ARM_SET_INTERWORK (sym, support_interwork);
14273#endif
b99bd4ef 14274
c19d1205
ZW
14275 /* Note - do not allow local symbols (.Lxxx) to be labeled
14276 as Thumb functions. This is because these labels, whilst
14277 they exist inside Thumb code, are not the entry points for
14278 possible ARM->Thumb calls. Also, these labels can be used
14279 as part of a computed goto or switch statement. eg gcc
14280 can generate code that looks like this:
b99bd4ef 14281
c19d1205
ZW
14282 ldr r2, [pc, .Laaa]
14283 lsl r3, r3, #2
14284 ldr r2, [r3, r2]
14285 mov pc, r2
b99bd4ef 14286
c19d1205
ZW
14287 .Lbbb: .word .Lxxx
14288 .Lccc: .word .Lyyy
14289 ..etc...
14290 .Laaa: .word Lbbb
b99bd4ef 14291
c19d1205
ZW
14292 The first instruction loads the address of the jump table.
14293 The second instruction converts a table index into a byte offset.
14294 The third instruction gets the jump address out of the table.
14295 The fourth instruction performs the jump.
b99bd4ef 14296
c19d1205
ZW
14297 If the address stored at .Laaa is that of a symbol which has the
14298 Thumb_Func bit set, then the linker will arrange for this address
14299 to have the bottom bit set, which in turn would mean that the
14300 address computation performed by the third instruction would end
14301 up with the bottom bit set. Since the ARM is capable of unaligned
14302 word loads, the instruction would then load the incorrect address
14303 out of the jump table, and chaos would ensue. */
14304 if (label_is_thumb_function_name
14305 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14306 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14307 {
c19d1205
ZW
14308 /* When the address of a Thumb function is taken the bottom
14309 bit of that address should be set. This will allow
14310 interworking between Arm and Thumb functions to work
14311 correctly. */
b99bd4ef 14312
c19d1205 14313 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14314
c19d1205 14315 label_is_thumb_function_name = FALSE;
b99bd4ef 14316 }
07a53e5c 14317
07a53e5c 14318 dwarf2_emit_label (sym);
b99bd4ef
NC
14319}
14320
c19d1205
ZW
14321int
14322arm_data_in_code (void)
b99bd4ef 14323{
c19d1205 14324 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14325 {
c19d1205
ZW
14326 *input_line_pointer = '/';
14327 input_line_pointer += 5;
14328 *input_line_pointer = 0;
14329 return 1;
b99bd4ef
NC
14330 }
14331
c19d1205 14332 return 0;
b99bd4ef
NC
14333}
14334
c19d1205
ZW
14335char *
14336arm_canonicalize_symbol_name (char * name)
b99bd4ef 14337{
c19d1205 14338 int len;
b99bd4ef 14339
c19d1205
ZW
14340 if (thumb_mode && (len = strlen (name)) > 5
14341 && streq (name + len - 5, "/data"))
14342 *(name + len - 5) = 0;
b99bd4ef 14343
c19d1205 14344 return name;
b99bd4ef 14345}
c19d1205
ZW
14346\f
14347/* Table of all register names defined by default. The user can
14348 define additional names with .req. Note that all register names
14349 should appear in both upper and lowercase variants. Some registers
14350 also have mixed-case names. */
b99bd4ef 14351
dcbf9037 14352#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14353#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14354#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14355#define REGSET(p,t) \
14356 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14357 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14358 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14359 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14360#define REGSETH(p,t) \
14361 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14362 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14363 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14364 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14365#define REGSET2(p,t) \
14366 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14367 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14368 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14369 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14370
c19d1205 14371static const struct reg_entry reg_names[] =
7ed4c4c5 14372{
c19d1205
ZW
14373 /* ARM integer registers. */
14374 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14375
c19d1205
ZW
14376 /* ATPCS synonyms. */
14377 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14378 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14379 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14380
c19d1205
ZW
14381 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14382 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14383 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14384
c19d1205
ZW
14385 /* Well-known aliases. */
14386 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14387 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14388
14389 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14390 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14391
14392 /* Coprocessor numbers. */
14393 REGSET(p, CP), REGSET(P, CP),
14394
14395 /* Coprocessor register numbers. The "cr" variants are for backward
14396 compatibility. */
14397 REGSET(c, CN), REGSET(C, CN),
14398 REGSET(cr, CN), REGSET(CR, CN),
14399
14400 /* FPA registers. */
14401 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14402 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14403
14404 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14405 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14406
14407 /* VFP SP registers. */
5287ad62
JB
14408 REGSET(s,VFS), REGSET(S,VFS),
14409 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14410
14411 /* VFP DP Registers. */
5287ad62
JB
14412 REGSET(d,VFD), REGSET(D,VFD),
14413 /* Extra Neon DP registers. */
14414 REGSETH(d,VFD), REGSETH(D,VFD),
14415
14416 /* Neon QP registers. */
14417 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14418
14419 /* VFP control registers. */
14420 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14421 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14422
14423 /* Maverick DSP coprocessor registers. */
14424 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14425 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14426
14427 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14428 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14429 REGDEF(dspsc,0,DSPSC),
14430
14431 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14432 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14433 REGDEF(DSPSC,0,DSPSC),
14434
14435 /* iWMMXt data registers - p0, c0-15. */
14436 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14437
14438 /* iWMMXt control registers - p1, c0-3. */
14439 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14440 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14441 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14442 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14443
14444 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14445 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14446 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14447 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14448 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14449
14450 /* XScale accumulator registers. */
14451 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14452};
14453#undef REGDEF
14454#undef REGNUM
14455#undef REGSET
7ed4c4c5 14456
c19d1205
ZW
14457/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14458 within psr_required_here. */
14459static const struct asm_psr psrs[] =
14460{
14461 /* Backward compatibility notation. Note that "all" is no longer
14462 truly all possible PSR bits. */
14463 {"all", PSR_c | PSR_f},
14464 {"flg", PSR_f},
14465 {"ctl", PSR_c},
14466
14467 /* Individual flags. */
14468 {"f", PSR_f},
14469 {"c", PSR_c},
14470 {"x", PSR_x},
14471 {"s", PSR_s},
14472 /* Combinations of flags. */
14473 {"fs", PSR_f | PSR_s},
14474 {"fx", PSR_f | PSR_x},
14475 {"fc", PSR_f | PSR_c},
14476 {"sf", PSR_s | PSR_f},
14477 {"sx", PSR_s | PSR_x},
14478 {"sc", PSR_s | PSR_c},
14479 {"xf", PSR_x | PSR_f},
14480 {"xs", PSR_x | PSR_s},
14481 {"xc", PSR_x | PSR_c},
14482 {"cf", PSR_c | PSR_f},
14483 {"cs", PSR_c | PSR_s},
14484 {"cx", PSR_c | PSR_x},
14485 {"fsx", PSR_f | PSR_s | PSR_x},
14486 {"fsc", PSR_f | PSR_s | PSR_c},
14487 {"fxs", PSR_f | PSR_x | PSR_s},
14488 {"fxc", PSR_f | PSR_x | PSR_c},
14489 {"fcs", PSR_f | PSR_c | PSR_s},
14490 {"fcx", PSR_f | PSR_c | PSR_x},
14491 {"sfx", PSR_s | PSR_f | PSR_x},
14492 {"sfc", PSR_s | PSR_f | PSR_c},
14493 {"sxf", PSR_s | PSR_x | PSR_f},
14494 {"sxc", PSR_s | PSR_x | PSR_c},
14495 {"scf", PSR_s | PSR_c | PSR_f},
14496 {"scx", PSR_s | PSR_c | PSR_x},
14497 {"xfs", PSR_x | PSR_f | PSR_s},
14498 {"xfc", PSR_x | PSR_f | PSR_c},
14499 {"xsf", PSR_x | PSR_s | PSR_f},
14500 {"xsc", PSR_x | PSR_s | PSR_c},
14501 {"xcf", PSR_x | PSR_c | PSR_f},
14502 {"xcs", PSR_x | PSR_c | PSR_s},
14503 {"cfs", PSR_c | PSR_f | PSR_s},
14504 {"cfx", PSR_c | PSR_f | PSR_x},
14505 {"csf", PSR_c | PSR_s | PSR_f},
14506 {"csx", PSR_c | PSR_s | PSR_x},
14507 {"cxf", PSR_c | PSR_x | PSR_f},
14508 {"cxs", PSR_c | PSR_x | PSR_s},
14509 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14510 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14511 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14512 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14513 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14514 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14515 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14516 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14517 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14518 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14519 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14520 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14521 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14522 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14523 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14524 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14525 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14526 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14527 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14528 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14529 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14530 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14531 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14532 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14533};
14534
62b3e311
PB
14535/* Table of V7M psr names. */
14536static const struct asm_psr v7m_psrs[] =
14537{
2b744c99
PB
14538 {"apsr", 0 }, {"APSR", 0 },
14539 {"iapsr", 1 }, {"IAPSR", 1 },
14540 {"eapsr", 2 }, {"EAPSR", 2 },
14541 {"psr", 3 }, {"PSR", 3 },
14542 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14543 {"ipsr", 5 }, {"IPSR", 5 },
14544 {"epsr", 6 }, {"EPSR", 6 },
14545 {"iepsr", 7 }, {"IEPSR", 7 },
14546 {"msp", 8 }, {"MSP", 8 },
14547 {"psp", 9 }, {"PSP", 9 },
14548 {"primask", 16}, {"PRIMASK", 16},
14549 {"basepri", 17}, {"BASEPRI", 17},
14550 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14551 {"faultmask", 19}, {"FAULTMASK", 19},
14552 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14553};
14554
c19d1205
ZW
14555/* Table of all shift-in-operand names. */
14556static const struct asm_shift_name shift_names [] =
b99bd4ef 14557{
c19d1205
ZW
14558 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14559 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14560 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14561 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14562 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14563 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14564};
b99bd4ef 14565
c19d1205
ZW
14566/* Table of all explicit relocation names. */
14567#ifdef OBJ_ELF
14568static struct reloc_entry reloc_names[] =
14569{
14570 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14571 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14572 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14573 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14574 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14575 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14576 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14577 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14578 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14579 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14580 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14581};
14582#endif
b99bd4ef 14583
c19d1205
ZW
14584/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14585static const struct asm_cond conds[] =
14586{
14587 {"eq", 0x0},
14588 {"ne", 0x1},
14589 {"cs", 0x2}, {"hs", 0x2},
14590 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14591 {"mi", 0x4},
14592 {"pl", 0x5},
14593 {"vs", 0x6},
14594 {"vc", 0x7},
14595 {"hi", 0x8},
14596 {"ls", 0x9},
14597 {"ge", 0xa},
14598 {"lt", 0xb},
14599 {"gt", 0xc},
14600 {"le", 0xd},
14601 {"al", 0xe}
14602};
bfae80f2 14603
62b3e311
PB
14604static struct asm_barrier_opt barrier_opt_names[] =
14605{
14606 { "sy", 0xf },
14607 { "un", 0x7 },
14608 { "st", 0xe },
14609 { "unst", 0x6 }
14610};
14611
c19d1205
ZW
14612/* Table of ARM-format instructions. */
14613
14614/* Macros for gluing together operand strings. N.B. In all cases
14615 other than OPS0, the trailing OP_stop comes from default
14616 zero-initialization of the unspecified elements of the array. */
14617#define OPS0() { OP_stop, }
14618#define OPS1(a) { OP_##a, }
14619#define OPS2(a,b) { OP_##a,OP_##b, }
14620#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14621#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14622#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14623#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14624
14625/* These macros abstract out the exact format of the mnemonic table and
14626 save some repeated characters. */
14627
14628/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14629#define TxCE(mnem, op, top, nops, ops, ae, te) \
14630 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14631 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14632
14633/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14634 a T_MNEM_xyz enumerator. */
14635#define TCE(mnem, aop, top, nops, ops, ae, te) \
14636 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14637#define tCE(mnem, aop, top, nops, ops, ae, te) \
14638 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14639
14640/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14641 infix after the third character. */
14642#define TxC3(mnem, op, top, nops, ops, ae, te) \
14643 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14644 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14645#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14646 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14647 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14648#define TC3(mnem, aop, top, nops, ops, ae, te) \
14649 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14650#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14651 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14652#define tC3(mnem, aop, top, nops, ops, ae, te) \
14653 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14654#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14655 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14656
14657/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14658 appear in the condition table. */
14659#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14660 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14661 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14662
14663#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14664 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14665 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14666 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14667 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14668 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14669 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14670 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14671 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14672 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14673 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14674 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14675 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14676 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14677 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14678 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14679 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14680 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14681 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14682 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14683
14684#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14685 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14686#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14687 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14688
14689/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14690 field is still 0xE. Many of the Thumb variants can be executed
14691 conditionally, so this is checked separately. */
c19d1205
ZW
14692#define TUE(mnem, op, top, nops, ops, ae, te) \
14693 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14694 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14695
14696/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14697 condition code field. */
14698#define TUF(mnem, op, top, nops, ops, ae, te) \
14699 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14700 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14701
14702/* ARM-only variants of all the above. */
6a86118a
NC
14703#define CE(mnem, op, nops, ops, ae) \
14704 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14705
14706#define C3(mnem, op, nops, ops, ae) \
14707 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14708
e3cb604e
PB
14709/* Legacy mnemonics that always have conditional infix after the third
14710 character. */
14711#define CL(mnem, op, nops, ops, ae) \
14712 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14713 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14714
8f06b2d8
PB
14715/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14716#define cCE(mnem, op, nops, ops, ae) \
14717 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14718
e3cb604e
PB
14719/* Legacy coprocessor instructions where conditional infix and conditional
14720 suffix are ambiguous. For consistency this includes all FPA instructions,
14721 not just the potentially ambiguous ones. */
14722#define cCL(mnem, op, nops, ops, ae) \
14723 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14724 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14725
14726/* Coprocessor, takes either a suffix or a position-3 infix
14727 (for an FPA corner case). */
14728#define C3E(mnem, op, nops, ops, ae) \
14729 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14730 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14731
6a86118a
NC
14732#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14733 { #m1 #m2 #m3, OPS##nops ops, \
14734 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14735 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14736
14737#define CM(m1, m2, op, nops, ops, ae) \
14738 xCM_(m1, , m2, op, nops, ops, ae), \
14739 xCM_(m1, eq, m2, op, nops, ops, ae), \
14740 xCM_(m1, ne, m2, op, nops, ops, ae), \
14741 xCM_(m1, cs, m2, op, nops, ops, ae), \
14742 xCM_(m1, hs, m2, op, nops, ops, ae), \
14743 xCM_(m1, cc, m2, op, nops, ops, ae), \
14744 xCM_(m1, ul, m2, op, nops, ops, ae), \
14745 xCM_(m1, lo, m2, op, nops, ops, ae), \
14746 xCM_(m1, mi, m2, op, nops, ops, ae), \
14747 xCM_(m1, pl, m2, op, nops, ops, ae), \
14748 xCM_(m1, vs, m2, op, nops, ops, ae), \
14749 xCM_(m1, vc, m2, op, nops, ops, ae), \
14750 xCM_(m1, hi, m2, op, nops, ops, ae), \
14751 xCM_(m1, ls, m2, op, nops, ops, ae), \
14752 xCM_(m1, ge, m2, op, nops, ops, ae), \
14753 xCM_(m1, lt, m2, op, nops, ops, ae), \
14754 xCM_(m1, gt, m2, op, nops, ops, ae), \
14755 xCM_(m1, le, m2, op, nops, ops, ae), \
14756 xCM_(m1, al, m2, op, nops, ops, ae)
14757
14758#define UE(mnem, op, nops, ops, ae) \
14759 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14760
14761#define UF(mnem, op, nops, ops, ae) \
14762 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14763
5287ad62
JB
14764/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14765 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14766 use the same encoding function for each. */
14767#define NUF(mnem, op, nops, ops, enc) \
14768 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14769 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14770
14771/* Neon data processing, version which indirects through neon_enc_tab for
14772 the various overloaded versions of opcodes. */
14773#define nUF(mnem, op, nops, ops, enc) \
14774 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14775 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14776
14777/* Neon insn with conditional suffix for the ARM version, non-overloaded
14778 version. */
037e8744
JB
14779#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14780 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14781 THUMB_VARIANT, do_##enc, do_##enc }
14782
037e8744
JB
14783#define NCE(mnem, op, nops, ops, enc) \
14784 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14785
14786#define NCEF(mnem, op, nops, ops, enc) \
14787 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14788
5287ad62 14789/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14790#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14791 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14792 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14793
037e8744
JB
14794#define nCE(mnem, op, nops, ops, enc) \
14795 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14796
14797#define nCEF(mnem, op, nops, ops, enc) \
14798 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14799
c19d1205
ZW
14800#define do_0 0
14801
14802/* Thumb-only, unconditional. */
14803#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14804
c19d1205 14805static const struct asm_opcode insns[] =
bfae80f2 14806{
e74cfd16
PB
14807#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14808#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14809 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14810 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14811 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14812 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14813 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14814 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14815 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14816 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14817 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14818 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14819 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14820 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14821 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14822 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14823 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14824 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14825
14826 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14827 for setting PSR flag bits. They are obsolete in V6 and do not
14828 have Thumb equivalents. */
14829 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14830 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14831 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14832 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14833 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14834 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14835 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14836 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14837 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14838
14839 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14840 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14841 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14842 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14843
4962c51a
MS
14844 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14845 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14846 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14847 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14848
f5208ef2 14849 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14850 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14851 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14852 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14853 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14854 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14855
14856 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14857 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14858 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14859 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14860
c19d1205 14861 /* Pseudo ops. */
e9f89963 14862 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14863 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14864 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14865
14866 /* Thumb-compatibility pseudo ops. */
14867 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14868 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14869 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14870 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14871 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14872 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14873 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14874 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14875 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14876 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14877 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14878 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14879
16a4cf17
PB
14880 /* These may simplify to neg. */
14881 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14882 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14883
c19d1205 14884#undef THUMB_VARIANT
e74cfd16 14885#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14886 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14887
14888 /* V1 instructions with no Thumb analogue prior to V6T2. */
14889#undef THUMB_VARIANT
e74cfd16 14890#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14891 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14892 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14893 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14894
14895 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14896 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14897 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14898 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14899
9c3c69f2
PB
14900 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14901 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14902
9c3c69f2
PB
14903 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14904 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14905
14906 /* V1 instructions with no Thumb analogue at all. */
14907 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14908 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14909
14910 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14911 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14912 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14913 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14914 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14915 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14916 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14917 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14918
14919#undef ARM_VARIANT
e74cfd16 14920#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 14921#undef THUMB_VARIANT
e74cfd16 14922#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14923 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14924 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14925
14926#undef THUMB_VARIANT
e74cfd16 14927#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14928 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14929 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14930
14931 /* Generic coprocessor instructions. */
14932 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
14933 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14934 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14935 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14936 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
14937 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14938 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14939
14940#undef ARM_VARIANT
e74cfd16 14941#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
14942 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14943 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14944
14945#undef ARM_VARIANT
e74cfd16 14946#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
037e8744
JB
14947 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
14948 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
14949
14950#undef ARM_VARIANT
e74cfd16 14951#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
14952 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14953 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14954 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14955 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14956 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14957 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14958 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14959 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14960
14961#undef ARM_VARIANT
e74cfd16 14962#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 14963#undef THUMB_VARIANT
e74cfd16 14964#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
14965 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14966 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14967 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14968 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14969 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14970 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
14971
14972#undef ARM_VARIANT
e74cfd16 14973#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
14974 /* ARM Architecture 4T. */
14975 /* Note: bx (and blx) are required on V5, even if the processor does
14976 not support Thumb. */
14977 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
14978
14979#undef ARM_VARIANT
e74cfd16 14980#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 14981#undef THUMB_VARIANT
e74cfd16 14982#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
14983 /* Note: blx has 2 variants; the .value coded here is for
14984 BLX(2). Only this variant has conditional execution. */
14985 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
14986 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
14987
14988#undef THUMB_VARIANT
e74cfd16 14989#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14990 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
14991 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14992 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14993 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14994 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
14995 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14996 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14997 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14998
14999#undef ARM_VARIANT
e74cfd16 15000#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15001 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15002 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15003 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15004 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15005
15006 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15007 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15008
15009 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15010 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15011 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15012 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15013
15014 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15015 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15016 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15017 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15018
15019 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15020 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15021
15022 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15023 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15024 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15025 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15026
15027#undef ARM_VARIANT
e74cfd16 15028#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15029 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15030 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15031 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15032
15033 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15034 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15035
15036#undef ARM_VARIANT
e74cfd16 15037#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15038 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15039
15040#undef ARM_VARIANT
e74cfd16 15041#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15042#undef THUMB_VARIANT
e74cfd16 15043#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15044 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15045 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15046 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15047 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15048 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15049 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15050 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15051 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15052 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15053 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15054
15055#undef THUMB_VARIANT
e74cfd16 15056#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15057 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15058 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15059 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15060 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15061
15062 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15063 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15064
15065/* ARM V6 not included in V7M (eg. integer SIMD). */
15066#undef THUMB_VARIANT
15067#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15068 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15069 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15070 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15071 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15072 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15073 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15074 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15075 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15076 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15077 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15078 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15079 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15080 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15081 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15082 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15083 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15084 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15085 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15086 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15087 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15088 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15089 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15090 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15091 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15092 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15093 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15094 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15095 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15096 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15097 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15098 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15099 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15100 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15101 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15102 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15103 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15104 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15105 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15106 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15107 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15108 UF(rfeib, 9900a00, 1, (RRw), rfe),
15109 UF(rfeda, 8100a00, 1, (RRw), rfe),
15110 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15111 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15112 UF(rfefa, 9900a00, 1, (RRw), rfe),
15113 UF(rfeea, 8100a00, 1, (RRw), rfe),
15114 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15115 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15116 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15117 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15118 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15119 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15120 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15121 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15122 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15123 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15124 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15125 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15126 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15127 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15128 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15129 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15130 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15131 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15132 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15133 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15134 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15135 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15136 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15137 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15138 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15139 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15140 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15141 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15142 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15143 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15144 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15145 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15146 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15147 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15148 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15149 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15150 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15151
15152#undef ARM_VARIANT
e74cfd16 15153#define ARM_VARIANT &arm_ext_v6k
c19d1205 15154#undef THUMB_VARIANT
e74cfd16 15155#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15156 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15157 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15158 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15159 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15160
ebdca51a
PB
15161#undef THUMB_VARIANT
15162#define THUMB_VARIANT &arm_ext_v6_notm
15163 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15164 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15165
c19d1205 15166#undef THUMB_VARIANT
e74cfd16 15167#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15168 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15169 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15170 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15171 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15172 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15173
15174#undef ARM_VARIANT
e74cfd16 15175#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15176 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15177
15178#undef ARM_VARIANT
e74cfd16 15179#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15180 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15181 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15182 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15183 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15184
15185 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15186 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15187 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15188 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15189
15190 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15191 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15192 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15193 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15194
25fe350b
MS
15195 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15196 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15197 /* ARM does not really have an IT instruction, so always allow it. */
15198#undef ARM_VARIANT
15199#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15200 TUE(it, 0, bf08, 1, (COND), it, t_it),
15201 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15202 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15203 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15204 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15205 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15206 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15207 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15208 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15209 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15210 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15211 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15212 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15213 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15214 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15215
92e90b6e
PB
15216 /* Thumb2 only instructions. */
15217#undef ARM_VARIANT
e74cfd16 15218#define ARM_VARIANT NULL
92e90b6e
PB
15219
15220 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15221 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15222 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15223 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15224
62b3e311
PB
15225 /* Thumb-2 hardware division instructions (R and M profiles only). */
15226#undef THUMB_VARIANT
15227#define THUMB_VARIANT &arm_ext_div
15228 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15229 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15230
15231 /* ARM V7 instructions. */
15232#undef ARM_VARIANT
15233#define ARM_VARIANT &arm_ext_v7
15234#undef THUMB_VARIANT
15235#define THUMB_VARIANT &arm_ext_v7
15236 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15237 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15238 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15239 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15240 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15241
c19d1205 15242#undef ARM_VARIANT
e74cfd16 15243#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15244 cCE(wfs, e200110, 1, (RR), rd),
15245 cCE(rfs, e300110, 1, (RR), rd),
15246 cCE(wfc, e400110, 1, (RR), rd),
15247 cCE(rfc, e500110, 1, (RR), rd),
15248
4962c51a
MS
15249 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15250 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15251 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15252 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15253
4962c51a
MS
15254 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15255 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15256 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15257 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15258
15259 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15260 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15261 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15262 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15263 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15264 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15265 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15266 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15267 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15268 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15269 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15270 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15271
15272 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15273 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15274 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15275 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15276 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15277 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15278 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15279 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15280 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15281 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15282 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15283 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15284
15285 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15286 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15287 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15288 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15289 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15290 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15291 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15292 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15293 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15294 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15295 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15296 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15297
15298 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15299 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15300 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15301 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15302 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15303 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15304 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15305 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15306 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15307 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15308 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15309 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15310
15311 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15312 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15313 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15314 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15315 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15316 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15317 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15318 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15319 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15320 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15321 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15322 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15323
15324 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15325 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15326 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15327 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15328 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15329 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15330 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15331 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15332 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15333 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15334 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15335 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15336
15337 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15338 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15339 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15340 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15341 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15342 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15343 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15344 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15345 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15346 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15347 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15348 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15349
15350 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15351 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15352 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15353 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15354 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15355 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15356 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15357 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15358 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15359 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15360 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15361 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15362
15363 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15364 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15365 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15366 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15367 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15368 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15369 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15370 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15371 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15372 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15373 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15374 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15375
15376 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15377 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15378 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15379 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15380 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15381 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15382 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15383 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15384 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15385 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15386 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15387 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15388
15389 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15390 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15391 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15392 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15393 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15394 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15395 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15396 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15397 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15398 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15399 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15400 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15401
15402 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15403 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15404 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15405 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15406 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15407 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15408 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15409 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15410 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15411 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15412 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15413 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15414
15415 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15416 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15417 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15418 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15419 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15420 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15421 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15422 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15423 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15424 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15425 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15426 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15427
15428 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15429 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15430 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15431 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15432 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15433 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15434 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15435 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15436 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15437 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15438 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15439 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15440
15441 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15442 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15443 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15444 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15445 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15446 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15447 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15448 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15449 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15450 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15451 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15452 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15453
15454 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15455 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15456 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15457 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15458 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15459 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15460 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15461 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15462 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15463 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15464 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15465 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15466
15467 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15468 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15469 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15470 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15471 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15472 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15473 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15474 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15475 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15476 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15477 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15478 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15479
15480 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15481 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15482 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15483 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15484 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15485 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15486 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15487 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15488 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15489 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15490 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15491 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15492
15493 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15494 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15495 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15496 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15497 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15498 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15499 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15500 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15501 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15502 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15503 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15504 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15505
15506 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15507 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15508 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15509 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15510 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15511 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15512 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15513 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15514 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15515 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15516 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15517 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15518
15519 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15520 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15521 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15522 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15523 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15524 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15525 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15526 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15527 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15528 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15529 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15530 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15531
15532 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15533 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15534 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15535 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15536 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15537 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15538 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15539 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15540 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15541 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15542 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15543 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15544
15545 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15546 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15547 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15548 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15549 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15550 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15551 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15552 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15553 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15554 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15555 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15556 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15557
15558 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15559 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15560 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15561 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15562 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15563 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15564 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15565 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15566 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15570
15571 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15583
15584 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15596
15597 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15609
15610 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15622
15623 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15635
15636 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15637 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15638 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15639 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15640
e3cb604e
PB
15641 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15642 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15643 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15644 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15645 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15646 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15647 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15648 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15649 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15650 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15651 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15652 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15653
c19d1205
ZW
15654 /* The implementation of the FIX instruction is broken on some
15655 assemblers, in that it accepts a precision specifier as well as a
15656 rounding specifier, despite the fact that this is meaningless.
15657 To be more compatible, we accept it as well, though of course it
15658 does not set any bits. */
8f06b2d8 15659 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15660 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15661 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15662 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15663 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15664 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15665 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15666 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15667 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15668 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15669 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15670 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15671 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15672
c19d1205
ZW
15673 /* Instructions that were new with the real FPA, call them V2. */
15674#undef ARM_VARIANT
e74cfd16 15675#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15676 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15677 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15678 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15679 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15680 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15681 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15682
15683#undef ARM_VARIANT
e74cfd16 15684#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15685 /* Moves and type conversions. */
8f06b2d8
PB
15686 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15687 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15688 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15689 cCE(fmstat, ef1fa10, 0, (), noargs),
15690 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15691 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15692 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15693 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15694 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15695 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15696 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15697 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15698
15699 /* Memory operations. */
4962c51a
MS
15700 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15701 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15702 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15703 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15704 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15705 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15706 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15707 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15708 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15709 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15710 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15711 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15712 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15713 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15714 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15715 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15716 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15717 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15718
c19d1205 15719 /* Monadic operations. */
8f06b2d8
PB
15720 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15721 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15722 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15723
15724 /* Dyadic operations. */
8f06b2d8
PB
15725 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15726 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15727 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15728 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15729 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15730 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15731 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15732 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15733 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15734
c19d1205 15735 /* Comparisons. */
8f06b2d8
PB
15736 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15737 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15738 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15739 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15740
c19d1205 15741#undef ARM_VARIANT
e74cfd16 15742#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15743 /* Moves and type conversions. */
5287ad62 15744 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15745 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15746 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15747 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15748 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15749 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15750 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15751 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15752 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15753 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15754 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15755 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15756 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15757
15758 /* Memory operations. */
4962c51a
MS
15759 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15760 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15761 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15762 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15763 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15764 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15765 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15766 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15767 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15768 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15769
c19d1205 15770 /* Monadic operations. */
5287ad62
JB
15771 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15772 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15773 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15774
15775 /* Dyadic operations. */
5287ad62
JB
15776 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15777 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15778 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15779 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15780 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15781 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15782 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15783 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15784 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15785
c19d1205 15786 /* Comparisons. */
5287ad62
JB
15787 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15788 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15789 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15790 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15791
15792#undef ARM_VARIANT
e74cfd16 15793#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15794 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15795 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15796 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15797 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15798
037e8744
JB
15799/* Instructions which may belong to either the Neon or VFP instruction sets.
15800 Individual encoder functions perform additional architecture checks. */
15801#undef ARM_VARIANT
15802#define ARM_VARIANT &fpu_vfp_ext_v1xd
15803#undef THUMB_VARIANT
15804#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15805 /* These mnemonics are unique to VFP. */
15806 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15807 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15808 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15809 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15810 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15811 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15812 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15813 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15814 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15815 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15816
15817 /* Mnemonics shared by Neon and VFP. */
15818 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15819 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15820 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15821
15822 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15823 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15824
15825 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15826 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15827
15828 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15829 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15830 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15831 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15832 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15833 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15834 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15835 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15836
15837 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15838
15839 /* NOTE: All VMOV encoding is special-cased! */
15840 NCE(vmov, 0, 1, (VMOV), neon_mov),
15841 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15842
5287ad62
JB
15843#undef THUMB_VARIANT
15844#define THUMB_VARIANT &fpu_neon_ext_v1
15845#undef ARM_VARIANT
15846#define ARM_VARIANT &fpu_neon_ext_v1
15847 /* Data processing with three registers of the same length. */
15848 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15849 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15850 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15851 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15852 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15853 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15854 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15855 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15856 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15857 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15858 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15859 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15860 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15861 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15862 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15863 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15864 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15865 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15866 /* If not immediate, fall back to neon_dyadic_i64_su.
15867 shl_imm should accept I8 I16 I32 I64,
15868 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15869 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15870 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15871 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15872 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15873 /* Logic ops, types optional & ignored. */
15874 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15875 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15876 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15877 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15878 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15879 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15880 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15881 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15882 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15883 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15884 /* Bitfield ops, untyped. */
15885 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15886 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15887 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15888 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15889 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15890 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15891 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15892 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15893 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15894 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15895 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15896 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15897 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15898 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15899 back to neon_dyadic_if_su. */
15900 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15901 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15902 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15903 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15904 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15905 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15906 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15907 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 15908 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
15909 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15910 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15911 /* As above, D registers only. */
15912 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15913 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15914 /* Int and float variants, signedness unimportant. */
5287ad62 15915 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
15916 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15917 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15918 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 15919 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
15920 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15921 /* vtst takes sizes 8, 16, 32. */
15922 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15923 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15924 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 15925 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
15926 /* VQD{R}MULH takes S16 S32. */
15927 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15928 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15929 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15930 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15931 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15932 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15933 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15934 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
15935 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15936 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15937 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15938 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
15939 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15940 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15941 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15942 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15943
15944 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 15945 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
15946 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
15947
15948 /* Data processing with two registers and a shift amount. */
15949 /* Right shifts, and variants with rounding.
15950 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
15951 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15952 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15953 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15954 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15955 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15956 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15957 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15958 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15959 /* Shift and insert. Sizes accepted 8 16 32 64. */
15960 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
15961 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
15962 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
15963 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
15964 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
15965 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
15966 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
15967 /* Right shift immediate, saturating & narrowing, with rounding variants.
15968 Types accepted S16 S32 S64 U16 U32 U64. */
15969 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15970 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15971 /* As above, unsigned. Types accepted S16 S32 S64. */
15972 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15973 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15974 /* Right shift narrowing. Types accepted I16 I32 I64. */
15975 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15976 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15977 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
15978 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
15979 /* CVT with optional immediate for fixed-point variant. */
037e8744 15980 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 15981
5287ad62
JB
15982 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
15983 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
15984
15985 /* Data processing, three registers of different lengths. */
15986 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
15987 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
15988 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
15989 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
15990 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
15991 /* If not scalar, fall back to neon_dyadic_long.
15992 Vector types as above, scalar types S16 S32 U16 U32. */
15993 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15994 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15995 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
15996 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15997 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15998 /* Dyadic, narrowing insns. Types I16 I32 I64. */
15999 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16000 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16001 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16002 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16003 /* Saturating doubling multiplies. Types S16 S32. */
16004 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16005 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16006 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16007 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16008 S16 S32 U16 U32. */
16009 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16010
16011 /* Extract. Size 8. */
3b8d421e
PB
16012 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16013 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16014
16015 /* Two registers, miscellaneous. */
16016 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16017 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16018 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16019 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16020 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16021 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16022 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16023 /* Vector replicate. Sizes 8 16 32. */
16024 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16025 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16026 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16027 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16028 /* VMOVN. Types I16 I32 I64. */
16029 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16030 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16031 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16032 /* VQMOVUN. Types S16 S32 S64. */
16033 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16034 /* VZIP / VUZP. Sizes 8 16 32. */
16035 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16036 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16037 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16038 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16039 /* VQABS / VQNEG. Types S8 S16 S32. */
16040 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16041 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16042 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16043 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16044 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16045 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16046 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16047 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16048 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16049 /* Reciprocal estimates. Types U32 F32. */
16050 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16051 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16052 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16053 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16054 /* VCLS. Types S8 S16 S32. */
16055 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16056 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16057 /* VCLZ. Types I8 I16 I32. */
16058 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16059 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16060 /* VCNT. Size 8. */
16061 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16062 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16063 /* Two address, untyped. */
16064 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16065 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16066 /* VTRN. Sizes 8 16 32. */
16067 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16068 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16069
16070 /* Table lookup. Size 8. */
16071 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16072 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16073
b7fc2769
JB
16074#undef THUMB_VARIANT
16075#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16076#undef ARM_VARIANT
16077#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16078 /* Neon element/structure load/store. */
16079 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16080 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16081 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16082 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16083 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16084 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16085 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16086 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16087
16088#undef THUMB_VARIANT
16089#define THUMB_VARIANT &fpu_vfp_ext_v3
16090#undef ARM_VARIANT
16091#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16092 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16093 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16094 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16095 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16096 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16097 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16098 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16099 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16100 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16101 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16102 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16103 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16104 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16105 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16106 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16107 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16108 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16109 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16110
5287ad62 16111#undef THUMB_VARIANT
c19d1205 16112#undef ARM_VARIANT
e74cfd16 16113#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16114 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16115 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16116 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16117 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16118 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16119 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16120 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16121 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16122
16123#undef ARM_VARIANT
e74cfd16 16124#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16125 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16126 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16127 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16128 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16129 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16130 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16131 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16132 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16133 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16134 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16135 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16136 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16137 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16138 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16139 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16140 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16141 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16142 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16143 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16144 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16145 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16146 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16147 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16148 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16149 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16150 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16151 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16152 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16153 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16154 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16155 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16156 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16157 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16158 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16159 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16160 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16161 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16162 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16163 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16164 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16165 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16166 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16167 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16168 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16169 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16170 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16171 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16172 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16173 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16174 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16175 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16176 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16177 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16178 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16179 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16180 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16181 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16182 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16183 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16184 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16185 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16186 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16187 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16188 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16189 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16190 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16191 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16192 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16193 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16194 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16195 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16196 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16197 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16198 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16199 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16200 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16201 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16202 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16203 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16204 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16205 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16206 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16207 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16208 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16209 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16210 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16211 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16212 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16213 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16214 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16215 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16216 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16217 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16218 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16219 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16220 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16221 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16222 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16223 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16224 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16225 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16226 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16227 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16228 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16229 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16230 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16231 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16232 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16233 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16234 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16235 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16236 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16237 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16238 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16239 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16240 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16241 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16242 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16243 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16244 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16245 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16246 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16247 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16248 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16249 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16250 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16251 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16252 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16253 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16254 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16255 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16256 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16257 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16258 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16259 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16260 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16261 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16268 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16269 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16270 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16271 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16272 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16273 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16277 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16278 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16279 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16280 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16281 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16282 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16287
2d447fca
JM
16288#undef ARM_VARIANT
16289#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16290 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16291 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16292 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16293 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16294 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16295 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16296 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16311 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16324 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16325 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16326 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16327 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16328 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16335 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16336 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16337 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16338 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16339 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16340 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16341 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16342 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16343 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16344 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16345 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16346 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16347
c19d1205 16348#undef ARM_VARIANT
e74cfd16 16349#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16350 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16351 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16352 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16353 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16354 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16355 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16356 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16357 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16358 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16359 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16360 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16361 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16362 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16363 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16364 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16365 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16366 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16367 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16368 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16369 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16370 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16371 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16372 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16373 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16374 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16375 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16376 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16377 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16378 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16379 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16380 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16381 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16382 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16383 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16384 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16385 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16386 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16387 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16388 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16389 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16390 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16391 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16392 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16393 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16394 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16395 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16396 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16397 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16398 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16399 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16400 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16401 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16402 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16403 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16404 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16405 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16406 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16407 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16408 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16409 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16410 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16411 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16412 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16413 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16414 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16415 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16416 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16417 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16418 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16419 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16420 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16421 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16422 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16423 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16424 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16425 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16426};
16427#undef ARM_VARIANT
16428#undef THUMB_VARIANT
16429#undef TCE
16430#undef TCM
16431#undef TUE
16432#undef TUF
16433#undef TCC
8f06b2d8 16434#undef cCE
e3cb604e
PB
16435#undef cCL
16436#undef C3E
c19d1205
ZW
16437#undef CE
16438#undef CM
16439#undef UE
16440#undef UF
16441#undef UT
5287ad62
JB
16442#undef NUF
16443#undef nUF
16444#undef NCE
16445#undef nCE
c19d1205
ZW
16446#undef OPS0
16447#undef OPS1
16448#undef OPS2
16449#undef OPS3
16450#undef OPS4
16451#undef OPS5
16452#undef OPS6
16453#undef do_0
16454\f
16455/* MD interface: bits in the object file. */
bfae80f2 16456
c19d1205
ZW
16457/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16458 for use in the a.out file, and stores them in the array pointed to by buf.
16459 This knows about the endian-ness of the target machine and does
16460 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16461 2 (short) and 4 (long) Floating numbers are put out as a series of
16462 LITTLENUMS (shorts, here at least). */
b99bd4ef 16463
c19d1205
ZW
16464void
16465md_number_to_chars (char * buf, valueT val, int n)
16466{
16467 if (target_big_endian)
16468 number_to_chars_bigendian (buf, val, n);
16469 else
16470 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16471}
16472
c19d1205
ZW
16473static valueT
16474md_chars_to_number (char * buf, int n)
bfae80f2 16475{
c19d1205
ZW
16476 valueT result = 0;
16477 unsigned char * where = (unsigned char *) buf;
bfae80f2 16478
c19d1205 16479 if (target_big_endian)
b99bd4ef 16480 {
c19d1205
ZW
16481 while (n--)
16482 {
16483 result <<= 8;
16484 result |= (*where++ & 255);
16485 }
b99bd4ef 16486 }
c19d1205 16487 else
b99bd4ef 16488 {
c19d1205
ZW
16489 while (n--)
16490 {
16491 result <<= 8;
16492 result |= (where[n] & 255);
16493 }
bfae80f2 16494 }
b99bd4ef 16495
c19d1205 16496 return result;
bfae80f2 16497}
b99bd4ef 16498
c19d1205 16499/* MD interface: Sections. */
b99bd4ef 16500
0110f2b8
PB
16501/* Estimate the size of a frag before relaxing. Assume everything fits in
16502 2 bytes. */
16503
c19d1205 16504int
0110f2b8 16505md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16506 segT segtype ATTRIBUTE_UNUSED)
16507{
0110f2b8
PB
16508 fragp->fr_var = 2;
16509 return 2;
16510}
16511
16512/* Convert a machine dependent frag. */
16513
16514void
16515md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16516{
16517 unsigned long insn;
16518 unsigned long old_op;
16519 char *buf;
16520 expressionS exp;
16521 fixS *fixp;
16522 int reloc_type;
16523 int pc_rel;
16524 int opcode;
16525
16526 buf = fragp->fr_literal + fragp->fr_fix;
16527
16528 old_op = bfd_get_16(abfd, buf);
16529 if (fragp->fr_symbol) {
16530 exp.X_op = O_symbol;
16531 exp.X_add_symbol = fragp->fr_symbol;
16532 } else {
16533 exp.X_op = O_constant;
16534 }
16535 exp.X_add_number = fragp->fr_offset;
16536 opcode = fragp->fr_subtype;
16537 switch (opcode)
16538 {
16539 case T_MNEM_ldr_pc:
16540 case T_MNEM_ldr_pc2:
16541 case T_MNEM_ldr_sp:
16542 case T_MNEM_str_sp:
16543 case T_MNEM_ldr:
16544 case T_MNEM_ldrb:
16545 case T_MNEM_ldrh:
16546 case T_MNEM_str:
16547 case T_MNEM_strb:
16548 case T_MNEM_strh:
16549 if (fragp->fr_var == 4)
16550 {
16551 insn = THUMB_OP32(opcode);
16552 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16553 {
16554 insn |= (old_op & 0x700) << 4;
16555 }
16556 else
16557 {
16558 insn |= (old_op & 7) << 12;
16559 insn |= (old_op & 0x38) << 13;
16560 }
16561 insn |= 0x00000c00;
16562 put_thumb32_insn (buf, insn);
16563 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16564 }
16565 else
16566 {
16567 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16568 }
16569 pc_rel = (opcode == T_MNEM_ldr_pc2);
16570 break;
16571 case T_MNEM_adr:
16572 if (fragp->fr_var == 4)
16573 {
16574 insn = THUMB_OP32 (opcode);
16575 insn |= (old_op & 0xf0) << 4;
16576 put_thumb32_insn (buf, insn);
16577 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16578 }
16579 else
16580 {
16581 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16582 exp.X_add_number -= 4;
16583 }
16584 pc_rel = 1;
16585 break;
16586 case T_MNEM_mov:
16587 case T_MNEM_movs:
16588 case T_MNEM_cmp:
16589 case T_MNEM_cmn:
16590 if (fragp->fr_var == 4)
16591 {
16592 int r0off = (opcode == T_MNEM_mov
16593 || opcode == T_MNEM_movs) ? 0 : 8;
16594 insn = THUMB_OP32 (opcode);
16595 insn = (insn & 0xe1ffffff) | 0x10000000;
16596 insn |= (old_op & 0x700) << r0off;
16597 put_thumb32_insn (buf, insn);
16598 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16599 }
16600 else
16601 {
16602 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16603 }
16604 pc_rel = 0;
16605 break;
16606 case T_MNEM_b:
16607 if (fragp->fr_var == 4)
16608 {
16609 insn = THUMB_OP32(opcode);
16610 put_thumb32_insn (buf, insn);
16611 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16612 }
16613 else
16614 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16615 pc_rel = 1;
16616 break;
16617 case T_MNEM_bcond:
16618 if (fragp->fr_var == 4)
16619 {
16620 insn = THUMB_OP32(opcode);
16621 insn |= (old_op & 0xf00) << 14;
16622 put_thumb32_insn (buf, insn);
16623 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16624 }
16625 else
16626 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16627 pc_rel = 1;
16628 break;
16629 case T_MNEM_add_sp:
16630 case T_MNEM_add_pc:
16631 case T_MNEM_inc_sp:
16632 case T_MNEM_dec_sp:
16633 if (fragp->fr_var == 4)
16634 {
16635 /* ??? Choose between add and addw. */
16636 insn = THUMB_OP32 (opcode);
16637 insn |= (old_op & 0xf0) << 4;
16638 put_thumb32_insn (buf, insn);
16805f35
PB
16639 if (opcode == T_MNEM_add_pc)
16640 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16641 else
16642 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16643 }
16644 else
16645 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16646 pc_rel = 0;
16647 break;
16648
16649 case T_MNEM_addi:
16650 case T_MNEM_addis:
16651 case T_MNEM_subi:
16652 case T_MNEM_subis:
16653 if (fragp->fr_var == 4)
16654 {
16655 insn = THUMB_OP32 (opcode);
16656 insn |= (old_op & 0xf0) << 4;
16657 insn |= (old_op & 0xf) << 16;
16658 put_thumb32_insn (buf, insn);
16805f35
PB
16659 if (insn & (1 << 20))
16660 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16661 else
16662 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16663 }
16664 else
16665 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16666 pc_rel = 0;
16667 break;
16668 default:
16669 abort();
16670 }
16671 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16672 reloc_type);
16673 fixp->fx_file = fragp->fr_file;
16674 fixp->fx_line = fragp->fr_line;
16675 fragp->fr_fix += fragp->fr_var;
16676}
16677
16678/* Return the size of a relaxable immediate operand instruction.
16679 SHIFT and SIZE specify the form of the allowable immediate. */
16680static int
16681relax_immediate (fragS *fragp, int size, int shift)
16682{
16683 offsetT offset;
16684 offsetT mask;
16685 offsetT low;
16686
16687 /* ??? Should be able to do better than this. */
16688 if (fragp->fr_symbol)
16689 return 4;
16690
16691 low = (1 << shift) - 1;
16692 mask = (1 << (shift + size)) - (1 << shift);
16693 offset = fragp->fr_offset;
16694 /* Force misaligned offsets to 32-bit variant. */
16695 if (offset & low)
5e77afaa 16696 return 4;
0110f2b8
PB
16697 if (offset & ~mask)
16698 return 4;
16699 return 2;
16700}
16701
5e77afaa
PB
16702/* Get the address of a symbol during relaxation. */
16703static addressT
16704relaxed_symbol_addr(fragS *fragp, long stretch)
16705{
16706 fragS *sym_frag;
16707 addressT addr;
16708 symbolS *sym;
16709
16710 sym = fragp->fr_symbol;
16711 sym_frag = symbol_get_frag (sym);
16712 know (S_GET_SEGMENT (sym) != absolute_section
16713 || sym_frag == &zero_address_frag);
16714 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16715
16716 /* If frag has yet to be reached on this pass, assume it will
16717 move by STRETCH just as we did. If this is not so, it will
16718 be because some frag between grows, and that will force
16719 another pass. */
16720
16721 if (stretch != 0
16722 && sym_frag->relax_marker != fragp->relax_marker)
16723 addr += stretch;
16724
16725 return addr;
16726}
16727
0110f2b8
PB
16728/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16729 load. */
16730static int
5e77afaa 16731relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16732{
16733 addressT addr;
16734 offsetT val;
16735
16736 /* Assume worst case for symbols not known to be in the same section. */
16737 if (!S_IS_DEFINED(fragp->fr_symbol)
16738 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16739 return 4;
16740
5e77afaa 16741 val = relaxed_symbol_addr(fragp, stretch);
0110f2b8
PB
16742 addr = fragp->fr_address + fragp->fr_fix;
16743 addr = (addr + 4) & ~3;
5e77afaa 16744 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16745 if (val & 3)
5e77afaa 16746 return 4;
0110f2b8
PB
16747 val -= addr;
16748 if (val < 0 || val > 1020)
16749 return 4;
16750 return 2;
16751}
16752
16753/* Return the size of a relaxable add/sub immediate instruction. */
16754static int
16755relax_addsub (fragS *fragp, asection *sec)
16756{
16757 char *buf;
16758 int op;
16759
16760 buf = fragp->fr_literal + fragp->fr_fix;
16761 op = bfd_get_16(sec->owner, buf);
16762 if ((op & 0xf) == ((op >> 4) & 0xf))
16763 return relax_immediate (fragp, 8, 0);
16764 else
16765 return relax_immediate (fragp, 3, 0);
16766}
16767
16768
16769/* Return the size of a relaxable branch instruction. BITS is the
16770 size of the offset field in the narrow instruction. */
16771
16772static int
5e77afaa 16773relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16774{
16775 addressT addr;
16776 offsetT val;
16777 offsetT limit;
16778
16779 /* Assume worst case for symbols not known to be in the same section. */
16780 if (!S_IS_DEFINED(fragp->fr_symbol)
16781 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16782 return 4;
16783
5e77afaa 16784 val = relaxed_symbol_addr(fragp, stretch);
0110f2b8
PB
16785 addr = fragp->fr_address + fragp->fr_fix + 4;
16786 val -= addr;
16787
16788 /* Offset is a signed value *2 */
16789 limit = 1 << bits;
16790 if (val >= limit || val < -limit)
16791 return 4;
16792 return 2;
16793}
16794
16795
16796/* Relax a machine dependent frag. This returns the amount by which
16797 the current size of the frag should change. */
16798
16799int
5e77afaa 16800arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16801{
16802 int oldsize;
16803 int newsize;
16804
16805 oldsize = fragp->fr_var;
16806 switch (fragp->fr_subtype)
16807 {
16808 case T_MNEM_ldr_pc2:
5e77afaa 16809 newsize = relax_adr(fragp, sec, stretch);
0110f2b8
PB
16810 break;
16811 case T_MNEM_ldr_pc:
16812 case T_MNEM_ldr_sp:
16813 case T_MNEM_str_sp:
16814 newsize = relax_immediate(fragp, 8, 2);
16815 break;
16816 case T_MNEM_ldr:
16817 case T_MNEM_str:
16818 newsize = relax_immediate(fragp, 5, 2);
16819 break;
16820 case T_MNEM_ldrh:
16821 case T_MNEM_strh:
16822 newsize = relax_immediate(fragp, 5, 1);
16823 break;
16824 case T_MNEM_ldrb:
16825 case T_MNEM_strb:
16826 newsize = relax_immediate(fragp, 5, 0);
16827 break;
16828 case T_MNEM_adr:
5e77afaa 16829 newsize = relax_adr(fragp, sec, stretch);
0110f2b8
PB
16830 break;
16831 case T_MNEM_mov:
16832 case T_MNEM_movs:
16833 case T_MNEM_cmp:
16834 case T_MNEM_cmn:
16835 newsize = relax_immediate(fragp, 8, 0);
16836 break;
16837 case T_MNEM_b:
5e77afaa 16838 newsize = relax_branch(fragp, sec, 11, stretch);
0110f2b8
PB
16839 break;
16840 case T_MNEM_bcond:
5e77afaa 16841 newsize = relax_branch(fragp, sec, 8, stretch);
0110f2b8
PB
16842 break;
16843 case T_MNEM_add_sp:
16844 case T_MNEM_add_pc:
16845 newsize = relax_immediate (fragp, 8, 2);
16846 break;
16847 case T_MNEM_inc_sp:
16848 case T_MNEM_dec_sp:
16849 newsize = relax_immediate (fragp, 7, 2);
16850 break;
16851 case T_MNEM_addi:
16852 case T_MNEM_addis:
16853 case T_MNEM_subi:
16854 case T_MNEM_subis:
16855 newsize = relax_addsub (fragp, sec);
16856 break;
16857 default:
16858 abort();
16859 }
5e77afaa
PB
16860
16861 fragp->fr_var = newsize;
16862 /* Freeze wide instructions that are at or before the same location as
16863 in the previous pass. This avoids infinite loops.
16864 Don't freeze them unconditionally because targets may be artificialy
16865 misaligned by the expansion of preceeding frags. */
16866 if (stretch <= 0 && newsize > 2)
0110f2b8 16867 {
0110f2b8
PB
16868 md_convert_frag (sec->owner, sec, fragp);
16869 frag_wane(fragp);
0110f2b8 16870 }
5e77afaa 16871
0110f2b8 16872 return newsize - oldsize;
c19d1205 16873}
b99bd4ef 16874
c19d1205 16875/* Round up a section size to the appropriate boundary. */
b99bd4ef 16876
c19d1205
ZW
16877valueT
16878md_section_align (segT segment ATTRIBUTE_UNUSED,
16879 valueT size)
16880{
f0927246
NC
16881#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16882 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16883 {
16884 /* For a.out, force the section size to be aligned. If we don't do
16885 this, BFD will align it for us, but it will not write out the
16886 final bytes of the section. This may be a bug in BFD, but it is
16887 easier to fix it here since that is how the other a.out targets
16888 work. */
16889 int align;
16890
16891 align = bfd_get_section_alignment (stdoutput, segment);
16892 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16893 }
c19d1205 16894#endif
f0927246
NC
16895
16896 return size;
bfae80f2 16897}
b99bd4ef 16898
c19d1205
ZW
16899/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16900 of an rs_align_code fragment. */
16901
16902void
16903arm_handle_align (fragS * fragP)
bfae80f2 16904{
c19d1205
ZW
16905 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16906 static char const thumb_noop[2] = { 0xc0, 0x46 };
16907 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16908 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16909
16910 int bytes, fix, noop_size;
16911 char * p;
16912 const char * noop;
bfae80f2 16913
c19d1205 16914 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
16915 return;
16916
c19d1205
ZW
16917 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16918 p = fragP->fr_literal + fragP->fr_fix;
16919 fix = 0;
bfae80f2 16920
c19d1205
ZW
16921 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16922 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 16923
c19d1205 16924 if (fragP->tc_frag_data)
a737bd4d 16925 {
c19d1205
ZW
16926 if (target_big_endian)
16927 noop = thumb_bigend_noop;
16928 else
16929 noop = thumb_noop;
16930 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
16931 }
16932 else
16933 {
c19d1205
ZW
16934 if (target_big_endian)
16935 noop = arm_bigend_noop;
16936 else
16937 noop = arm_noop;
16938 noop_size = sizeof (arm_noop);
7ed4c4c5 16939 }
a737bd4d 16940
c19d1205 16941 if (bytes & (noop_size - 1))
7ed4c4c5 16942 {
c19d1205
ZW
16943 fix = bytes & (noop_size - 1);
16944 memset (p, 0, fix);
16945 p += fix;
16946 bytes -= fix;
a737bd4d 16947 }
a737bd4d 16948
c19d1205 16949 while (bytes >= noop_size)
a737bd4d 16950 {
c19d1205
ZW
16951 memcpy (p, noop, noop_size);
16952 p += noop_size;
16953 bytes -= noop_size;
16954 fix += noop_size;
a737bd4d
NC
16955 }
16956
c19d1205
ZW
16957 fragP->fr_fix += fix;
16958 fragP->fr_var = noop_size;
a737bd4d
NC
16959}
16960
c19d1205
ZW
16961/* Called from md_do_align. Used to create an alignment
16962 frag in a code section. */
16963
16964void
16965arm_frag_align_code (int n, int max)
bfae80f2 16966{
c19d1205 16967 char * p;
7ed4c4c5 16968
c19d1205
ZW
16969 /* We assume that there will never be a requirement
16970 to support alignments greater than 32 bytes. */
16971 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
16972 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 16973
c19d1205
ZW
16974 p = frag_var (rs_align_code,
16975 MAX_MEM_FOR_RS_ALIGN_CODE,
16976 1,
16977 (relax_substateT) max,
16978 (symbolS *) NULL,
16979 (offsetT) n,
16980 (char *) NULL);
16981 *p = 0;
16982}
bfae80f2 16983
c19d1205 16984/* Perform target specific initialisation of a frag. */
bfae80f2 16985
c19d1205
ZW
16986void
16987arm_init_frag (fragS * fragP)
16988{
16989 /* Record whether this frag is in an ARM or a THUMB area. */
16990 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
16991}
16992
c19d1205
ZW
16993#ifdef OBJ_ELF
16994/* When we change sections we need to issue a new mapping symbol. */
16995
16996void
16997arm_elf_change_section (void)
bfae80f2 16998{
c19d1205
ZW
16999 flagword flags;
17000 segment_info_type *seginfo;
bfae80f2 17001
c19d1205
ZW
17002 /* Link an unlinked unwind index table section to the .text section. */
17003 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17004 && elf_linked_to_section (now_seg) == NULL)
17005 elf_linked_to_section (now_seg) = text_section;
17006
17007 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17008 return;
17009
c19d1205
ZW
17010 flags = bfd_get_section_flags (stdoutput, now_seg);
17011
17012 /* We can ignore sections that only contain debug info. */
17013 if ((flags & SEC_ALLOC) == 0)
17014 return;
bfae80f2 17015
c19d1205
ZW
17016 seginfo = seg_info (now_seg);
17017 mapstate = seginfo->tc_segment_info_data.mapstate;
17018 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17019}
17020
c19d1205
ZW
17021int
17022arm_elf_section_type (const char * str, size_t len)
e45d0630 17023{
c19d1205
ZW
17024 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17025 return SHT_ARM_EXIDX;
e45d0630 17026
c19d1205
ZW
17027 return -1;
17028}
17029\f
17030/* Code to deal with unwinding tables. */
e45d0630 17031
c19d1205 17032static void add_unwind_adjustsp (offsetT);
e45d0630 17033
c19d1205 17034/* Cenerate and deferred unwind frame offset. */
e45d0630 17035
bfae80f2 17036static void
c19d1205 17037flush_pending_unwind (void)
bfae80f2 17038{
c19d1205 17039 offsetT offset;
bfae80f2 17040
c19d1205
ZW
17041 offset = unwind.pending_offset;
17042 unwind.pending_offset = 0;
17043 if (offset != 0)
17044 add_unwind_adjustsp (offset);
bfae80f2
RE
17045}
17046
c19d1205
ZW
17047/* Add an opcode to this list for this function. Two-byte opcodes should
17048 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17049 order. */
17050
bfae80f2 17051static void
c19d1205 17052add_unwind_opcode (valueT op, int length)
bfae80f2 17053{
c19d1205
ZW
17054 /* Add any deferred stack adjustment. */
17055 if (unwind.pending_offset)
17056 flush_pending_unwind ();
bfae80f2 17057
c19d1205 17058 unwind.sp_restored = 0;
bfae80f2 17059
c19d1205 17060 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17061 {
c19d1205
ZW
17062 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17063 if (unwind.opcodes)
17064 unwind.opcodes = xrealloc (unwind.opcodes,
17065 unwind.opcode_alloc);
17066 else
17067 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17068 }
c19d1205 17069 while (length > 0)
bfae80f2 17070 {
c19d1205
ZW
17071 length--;
17072 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17073 op >>= 8;
17074 unwind.opcode_count++;
bfae80f2 17075 }
bfae80f2
RE
17076}
17077
c19d1205
ZW
17078/* Add unwind opcodes to adjust the stack pointer. */
17079
bfae80f2 17080static void
c19d1205 17081add_unwind_adjustsp (offsetT offset)
bfae80f2 17082{
c19d1205 17083 valueT op;
bfae80f2 17084
c19d1205 17085 if (offset > 0x200)
bfae80f2 17086 {
c19d1205
ZW
17087 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17088 char bytes[5];
17089 int n;
17090 valueT o;
bfae80f2 17091
c19d1205
ZW
17092 /* Long form: 0xb2, uleb128. */
17093 /* This might not fit in a word so add the individual bytes,
17094 remembering the list is built in reverse order. */
17095 o = (valueT) ((offset - 0x204) >> 2);
17096 if (o == 0)
17097 add_unwind_opcode (0, 1);
bfae80f2 17098
c19d1205
ZW
17099 /* Calculate the uleb128 encoding of the offset. */
17100 n = 0;
17101 while (o)
17102 {
17103 bytes[n] = o & 0x7f;
17104 o >>= 7;
17105 if (o)
17106 bytes[n] |= 0x80;
17107 n++;
17108 }
17109 /* Add the insn. */
17110 for (; n; n--)
17111 add_unwind_opcode (bytes[n - 1], 1);
17112 add_unwind_opcode (0xb2, 1);
17113 }
17114 else if (offset > 0x100)
bfae80f2 17115 {
c19d1205
ZW
17116 /* Two short opcodes. */
17117 add_unwind_opcode (0x3f, 1);
17118 op = (offset - 0x104) >> 2;
17119 add_unwind_opcode (op, 1);
bfae80f2 17120 }
c19d1205
ZW
17121 else if (offset > 0)
17122 {
17123 /* Short opcode. */
17124 op = (offset - 4) >> 2;
17125 add_unwind_opcode (op, 1);
17126 }
17127 else if (offset < 0)
bfae80f2 17128 {
c19d1205
ZW
17129 offset = -offset;
17130 while (offset > 0x100)
bfae80f2 17131 {
c19d1205
ZW
17132 add_unwind_opcode (0x7f, 1);
17133 offset -= 0x100;
bfae80f2 17134 }
c19d1205
ZW
17135 op = ((offset - 4) >> 2) | 0x40;
17136 add_unwind_opcode (op, 1);
bfae80f2 17137 }
bfae80f2
RE
17138}
17139
c19d1205
ZW
17140/* Finish the list of unwind opcodes for this function. */
17141static void
17142finish_unwind_opcodes (void)
bfae80f2 17143{
c19d1205 17144 valueT op;
bfae80f2 17145
c19d1205 17146 if (unwind.fp_used)
bfae80f2 17147 {
708587a4 17148 /* Adjust sp as necessary. */
c19d1205
ZW
17149 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17150 flush_pending_unwind ();
bfae80f2 17151
c19d1205
ZW
17152 /* After restoring sp from the frame pointer. */
17153 op = 0x90 | unwind.fp_reg;
17154 add_unwind_opcode (op, 1);
17155 }
17156 else
17157 flush_pending_unwind ();
bfae80f2
RE
17158}
17159
bfae80f2 17160
c19d1205
ZW
17161/* Start an exception table entry. If idx is nonzero this is an index table
17162 entry. */
bfae80f2
RE
17163
17164static void
c19d1205 17165start_unwind_section (const segT text_seg, int idx)
bfae80f2 17166{
c19d1205
ZW
17167 const char * text_name;
17168 const char * prefix;
17169 const char * prefix_once;
17170 const char * group_name;
17171 size_t prefix_len;
17172 size_t text_len;
17173 char * sec_name;
17174 size_t sec_name_len;
17175 int type;
17176 int flags;
17177 int linkonce;
bfae80f2 17178
c19d1205 17179 if (idx)
bfae80f2 17180 {
c19d1205
ZW
17181 prefix = ELF_STRING_ARM_unwind;
17182 prefix_once = ELF_STRING_ARM_unwind_once;
17183 type = SHT_ARM_EXIDX;
bfae80f2 17184 }
c19d1205 17185 else
bfae80f2 17186 {
c19d1205
ZW
17187 prefix = ELF_STRING_ARM_unwind_info;
17188 prefix_once = ELF_STRING_ARM_unwind_info_once;
17189 type = SHT_PROGBITS;
bfae80f2
RE
17190 }
17191
c19d1205
ZW
17192 text_name = segment_name (text_seg);
17193 if (streq (text_name, ".text"))
17194 text_name = "";
17195
17196 if (strncmp (text_name, ".gnu.linkonce.t.",
17197 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17198 {
c19d1205
ZW
17199 prefix = prefix_once;
17200 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17201 }
17202
c19d1205
ZW
17203 prefix_len = strlen (prefix);
17204 text_len = strlen (text_name);
17205 sec_name_len = prefix_len + text_len;
17206 sec_name = xmalloc (sec_name_len + 1);
17207 memcpy (sec_name, prefix, prefix_len);
17208 memcpy (sec_name + prefix_len, text_name, text_len);
17209 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17210
c19d1205
ZW
17211 flags = SHF_ALLOC;
17212 linkonce = 0;
17213 group_name = 0;
bfae80f2 17214
c19d1205
ZW
17215 /* Handle COMDAT group. */
17216 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17217 {
c19d1205
ZW
17218 group_name = elf_group_name (text_seg);
17219 if (group_name == NULL)
17220 {
17221 as_bad ("Group section `%s' has no group signature",
17222 segment_name (text_seg));
17223 ignore_rest_of_line ();
17224 return;
17225 }
17226 flags |= SHF_GROUP;
17227 linkonce = 1;
bfae80f2
RE
17228 }
17229
c19d1205 17230 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17231
c19d1205
ZW
17232 /* Set the setion link for index tables. */
17233 if (idx)
17234 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17235}
17236
bfae80f2 17237
c19d1205
ZW
17238/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17239 personality routine data. Returns zero, or the index table value for
17240 and inline entry. */
17241
17242static valueT
17243create_unwind_entry (int have_data)
bfae80f2 17244{
c19d1205
ZW
17245 int size;
17246 addressT where;
17247 char *ptr;
17248 /* The current word of data. */
17249 valueT data;
17250 /* The number of bytes left in this word. */
17251 int n;
bfae80f2 17252
c19d1205 17253 finish_unwind_opcodes ();
bfae80f2 17254
c19d1205
ZW
17255 /* Remember the current text section. */
17256 unwind.saved_seg = now_seg;
17257 unwind.saved_subseg = now_subseg;
bfae80f2 17258
c19d1205 17259 start_unwind_section (now_seg, 0);
bfae80f2 17260
c19d1205 17261 if (unwind.personality_routine == NULL)
bfae80f2 17262 {
c19d1205
ZW
17263 if (unwind.personality_index == -2)
17264 {
17265 if (have_data)
17266 as_bad (_("handerdata in cantunwind frame"));
17267 return 1; /* EXIDX_CANTUNWIND. */
17268 }
bfae80f2 17269
c19d1205
ZW
17270 /* Use a default personality routine if none is specified. */
17271 if (unwind.personality_index == -1)
17272 {
17273 if (unwind.opcode_count > 3)
17274 unwind.personality_index = 1;
17275 else
17276 unwind.personality_index = 0;
17277 }
bfae80f2 17278
c19d1205
ZW
17279 /* Space for the personality routine entry. */
17280 if (unwind.personality_index == 0)
17281 {
17282 if (unwind.opcode_count > 3)
17283 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17284
c19d1205
ZW
17285 if (!have_data)
17286 {
17287 /* All the data is inline in the index table. */
17288 data = 0x80;
17289 n = 3;
17290 while (unwind.opcode_count > 0)
17291 {
17292 unwind.opcode_count--;
17293 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17294 n--;
17295 }
bfae80f2 17296
c19d1205
ZW
17297 /* Pad with "finish" opcodes. */
17298 while (n--)
17299 data = (data << 8) | 0xb0;
bfae80f2 17300
c19d1205
ZW
17301 return data;
17302 }
17303 size = 0;
17304 }
17305 else
17306 /* We get two opcodes "free" in the first word. */
17307 size = unwind.opcode_count - 2;
17308 }
17309 else
17310 /* An extra byte is required for the opcode count. */
17311 size = unwind.opcode_count + 1;
bfae80f2 17312
c19d1205
ZW
17313 size = (size + 3) >> 2;
17314 if (size > 0xff)
17315 as_bad (_("too many unwind opcodes"));
bfae80f2 17316
c19d1205
ZW
17317 frag_align (2, 0, 0);
17318 record_alignment (now_seg, 2);
17319 unwind.table_entry = expr_build_dot ();
17320
17321 /* Allocate the table entry. */
17322 ptr = frag_more ((size << 2) + 4);
17323 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17324
c19d1205 17325 switch (unwind.personality_index)
bfae80f2 17326 {
c19d1205
ZW
17327 case -1:
17328 /* ??? Should this be a PLT generating relocation? */
17329 /* Custom personality routine. */
17330 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17331 BFD_RELOC_ARM_PREL31);
bfae80f2 17332
c19d1205
ZW
17333 where += 4;
17334 ptr += 4;
bfae80f2 17335
c19d1205
ZW
17336 /* Set the first byte to the number of additional words. */
17337 data = size - 1;
17338 n = 3;
17339 break;
bfae80f2 17340
c19d1205
ZW
17341 /* ABI defined personality routines. */
17342 case 0:
17343 /* Three opcodes bytes are packed into the first word. */
17344 data = 0x80;
17345 n = 3;
17346 break;
bfae80f2 17347
c19d1205
ZW
17348 case 1:
17349 case 2:
17350 /* The size and first two opcode bytes go in the first word. */
17351 data = ((0x80 + unwind.personality_index) << 8) | size;
17352 n = 2;
17353 break;
bfae80f2 17354
c19d1205
ZW
17355 default:
17356 /* Should never happen. */
17357 abort ();
17358 }
bfae80f2 17359
c19d1205
ZW
17360 /* Pack the opcodes into words (MSB first), reversing the list at the same
17361 time. */
17362 while (unwind.opcode_count > 0)
17363 {
17364 if (n == 0)
17365 {
17366 md_number_to_chars (ptr, data, 4);
17367 ptr += 4;
17368 n = 4;
17369 data = 0;
17370 }
17371 unwind.opcode_count--;
17372 n--;
17373 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17374 }
17375
17376 /* Finish off the last word. */
17377 if (n < 4)
17378 {
17379 /* Pad with "finish" opcodes. */
17380 while (n--)
17381 data = (data << 8) | 0xb0;
17382
17383 md_number_to_chars (ptr, data, 4);
17384 }
17385
17386 if (!have_data)
17387 {
17388 /* Add an empty descriptor if there is no user-specified data. */
17389 ptr = frag_more (4);
17390 md_number_to_chars (ptr, 0, 4);
17391 }
17392
17393 return 0;
bfae80f2
RE
17394}
17395
f0927246
NC
17396
17397/* Initialize the DWARF-2 unwind information for this procedure. */
17398
17399void
17400tc_arm_frame_initial_instructions (void)
17401{
17402 cfi_add_CFA_def_cfa (REG_SP, 0);
17403}
17404#endif /* OBJ_ELF */
17405
c19d1205
ZW
17406/* Convert REGNAME to a DWARF-2 register number. */
17407
17408int
1df69f4f 17409tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17410{
1df69f4f 17411 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17412
17413 if (reg == FAIL)
17414 return -1;
17415
17416 return reg;
bfae80f2
RE
17417}
17418
f0927246 17419#ifdef TE_PE
c19d1205 17420void
f0927246 17421tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17422{
f0927246 17423 expressionS expr;
bfae80f2 17424
f0927246
NC
17425 expr.X_op = O_secrel;
17426 expr.X_add_symbol = symbol;
17427 expr.X_add_number = 0;
17428 emit_expr (&expr, size);
17429}
17430#endif
bfae80f2 17431
c19d1205 17432/* MD interface: Symbol and relocation handling. */
bfae80f2 17433
2fc8bdac
ZW
17434/* Return the address within the segment that a PC-relative fixup is
17435 relative to. For ARM, PC-relative fixups applied to instructions
17436 are generally relative to the location of the fixup plus 8 bytes.
17437 Thumb branches are offset by 4, and Thumb loads relative to PC
17438 require special handling. */
bfae80f2 17439
c19d1205 17440long
2fc8bdac 17441md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17442{
2fc8bdac
ZW
17443 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17444
17445 /* If this is pc-relative and we are going to emit a relocation
17446 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17447 will need. Otherwise we want to use the calculated base.
17448 For WinCE we skip the bias for externals as well, since this
17449 is how the MS ARM-CE assembler behaves and we want to be compatible. */
2fc8bdac
ZW
17450 if (fixP->fx_pcrel
17451 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17452 || (arm_force_relocation (fixP)
17453#ifdef TE_WINCE
17454 && !S_IS_EXTERNAL (fixP->fx_addsy)
17455#endif
17456 )))
2fc8bdac 17457 base = 0;
bfae80f2 17458
c19d1205 17459 switch (fixP->fx_r_type)
bfae80f2 17460 {
2fc8bdac
ZW
17461 /* PC relative addressing on the Thumb is slightly odd as the
17462 bottom two bits of the PC are forced to zero for the
17463 calculation. This happens *after* application of the
17464 pipeline offset. However, Thumb adrl already adjusts for
17465 this, so we need not do it again. */
c19d1205 17466 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17467 return base & ~3;
c19d1205
ZW
17468
17469 case BFD_RELOC_ARM_THUMB_OFFSET:
17470 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17471 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17472 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17473 return (base + 4) & ~3;
c19d1205 17474
2fc8bdac
ZW
17475 /* Thumb branches are simply offset by +4. */
17476 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17477 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17478 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17479 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17480 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17481 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17482 case BFD_RELOC_THUMB_PCREL_BLX:
17483 return base + 4;
bfae80f2 17484
2fc8bdac
ZW
17485 /* ARM mode branches are offset by +8. However, the Windows CE
17486 loader expects the relocation not to take this into account. */
17487 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17488 case BFD_RELOC_ARM_PCREL_CALL:
17489 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17490 case BFD_RELOC_ARM_PCREL_BLX:
17491 case BFD_RELOC_ARM_PLT32:
c19d1205 17492#ifdef TE_WINCE
53baae48
NC
17493 /* When handling fixups immediately, because we have already
17494 discovered the value of a symbol, or the address of the frag involved
17495 we must account for the offset by +8, as the OS loader will never see the reloc.
17496 see fixup_segment() in write.c
17497 The S_IS_EXTERNAL test handles the case of global symbols.
17498 Those need the calculated base, not just the pipe compensation the linker will need. */
17499 if (fixP->fx_pcrel
17500 && fixP->fx_addsy != NULL
17501 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17502 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17503 return base + 8;
2fc8bdac 17504 return base;
c19d1205 17505#else
2fc8bdac 17506 return base + 8;
c19d1205 17507#endif
2fc8bdac
ZW
17508
17509 /* ARM mode loads relative to PC are also offset by +8. Unlike
17510 branches, the Windows CE loader *does* expect the relocation
17511 to take this into account. */
17512 case BFD_RELOC_ARM_OFFSET_IMM:
17513 case BFD_RELOC_ARM_OFFSET_IMM8:
17514 case BFD_RELOC_ARM_HWLITERAL:
17515 case BFD_RELOC_ARM_LITERAL:
17516 case BFD_RELOC_ARM_CP_OFF_IMM:
17517 return base + 8;
17518
17519
17520 /* Other PC-relative relocations are un-offset. */
17521 default:
17522 return base;
17523 }
bfae80f2
RE
17524}
17525
c19d1205
ZW
17526/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17527 Otherwise we have no need to default values of symbols. */
17528
17529symbolS *
17530md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17531{
c19d1205
ZW
17532#ifdef OBJ_ELF
17533 if (name[0] == '_' && name[1] == 'G'
17534 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17535 {
17536 if (!GOT_symbol)
17537 {
17538 if (symbol_find (name))
17539 as_bad ("GOT already in the symbol table");
bfae80f2 17540
c19d1205
ZW
17541 GOT_symbol = symbol_new (name, undefined_section,
17542 (valueT) 0, & zero_address_frag);
17543 }
bfae80f2 17544
c19d1205 17545 return GOT_symbol;
bfae80f2 17546 }
c19d1205 17547#endif
bfae80f2 17548
c19d1205 17549 return 0;
bfae80f2
RE
17550}
17551
55cf6793 17552/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17553 computed as two separate immediate values, added together. We
17554 already know that this value cannot be computed by just one ARM
17555 instruction. */
17556
17557static unsigned int
17558validate_immediate_twopart (unsigned int val,
17559 unsigned int * highpart)
bfae80f2 17560{
c19d1205
ZW
17561 unsigned int a;
17562 unsigned int i;
bfae80f2 17563
c19d1205
ZW
17564 for (i = 0; i < 32; i += 2)
17565 if (((a = rotate_left (val, i)) & 0xff) != 0)
17566 {
17567 if (a & 0xff00)
17568 {
17569 if (a & ~ 0xffff)
17570 continue;
17571 * highpart = (a >> 8) | ((i + 24) << 7);
17572 }
17573 else if (a & 0xff0000)
17574 {
17575 if (a & 0xff000000)
17576 continue;
17577 * highpart = (a >> 16) | ((i + 16) << 7);
17578 }
17579 else
17580 {
17581 assert (a & 0xff000000);
17582 * highpart = (a >> 24) | ((i + 8) << 7);
17583 }
bfae80f2 17584
c19d1205
ZW
17585 return (a & 0xff) | (i << 7);
17586 }
bfae80f2 17587
c19d1205 17588 return FAIL;
bfae80f2
RE
17589}
17590
c19d1205
ZW
17591static int
17592validate_offset_imm (unsigned int val, int hwse)
17593{
17594 if ((hwse && val > 255) || val > 4095)
17595 return FAIL;
17596 return val;
17597}
bfae80f2 17598
55cf6793 17599/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17600 negative immediate constant by altering the instruction. A bit of
17601 a hack really.
17602 MOV <-> MVN
17603 AND <-> BIC
17604 ADC <-> SBC
17605 by inverting the second operand, and
17606 ADD <-> SUB
17607 CMP <-> CMN
17608 by negating the second operand. */
bfae80f2 17609
c19d1205
ZW
17610static int
17611negate_data_op (unsigned long * instruction,
17612 unsigned long value)
bfae80f2 17613{
c19d1205
ZW
17614 int op, new_inst;
17615 unsigned long negated, inverted;
bfae80f2 17616
c19d1205
ZW
17617 negated = encode_arm_immediate (-value);
17618 inverted = encode_arm_immediate (~value);
bfae80f2 17619
c19d1205
ZW
17620 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17621 switch (op)
bfae80f2 17622 {
c19d1205
ZW
17623 /* First negates. */
17624 case OPCODE_SUB: /* ADD <-> SUB */
17625 new_inst = OPCODE_ADD;
17626 value = negated;
17627 break;
bfae80f2 17628
c19d1205
ZW
17629 case OPCODE_ADD:
17630 new_inst = OPCODE_SUB;
17631 value = negated;
17632 break;
bfae80f2 17633
c19d1205
ZW
17634 case OPCODE_CMP: /* CMP <-> CMN */
17635 new_inst = OPCODE_CMN;
17636 value = negated;
17637 break;
bfae80f2 17638
c19d1205
ZW
17639 case OPCODE_CMN:
17640 new_inst = OPCODE_CMP;
17641 value = negated;
17642 break;
bfae80f2 17643
c19d1205
ZW
17644 /* Now Inverted ops. */
17645 case OPCODE_MOV: /* MOV <-> MVN */
17646 new_inst = OPCODE_MVN;
17647 value = inverted;
17648 break;
bfae80f2 17649
c19d1205
ZW
17650 case OPCODE_MVN:
17651 new_inst = OPCODE_MOV;
17652 value = inverted;
17653 break;
bfae80f2 17654
c19d1205
ZW
17655 case OPCODE_AND: /* AND <-> BIC */
17656 new_inst = OPCODE_BIC;
17657 value = inverted;
17658 break;
bfae80f2 17659
c19d1205
ZW
17660 case OPCODE_BIC:
17661 new_inst = OPCODE_AND;
17662 value = inverted;
17663 break;
bfae80f2 17664
c19d1205
ZW
17665 case OPCODE_ADC: /* ADC <-> SBC */
17666 new_inst = OPCODE_SBC;
17667 value = inverted;
17668 break;
bfae80f2 17669
c19d1205
ZW
17670 case OPCODE_SBC:
17671 new_inst = OPCODE_ADC;
17672 value = inverted;
17673 break;
bfae80f2 17674
c19d1205
ZW
17675 /* We cannot do anything. */
17676 default:
17677 return FAIL;
b99bd4ef
NC
17678 }
17679
c19d1205
ZW
17680 if (value == (unsigned) FAIL)
17681 return FAIL;
17682
17683 *instruction &= OPCODE_MASK;
17684 *instruction |= new_inst << DATA_OP_SHIFT;
17685 return value;
b99bd4ef
NC
17686}
17687
ef8d22e6
PB
17688/* Like negate_data_op, but for Thumb-2. */
17689
17690static unsigned int
16dd5e42 17691thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17692{
17693 int op, new_inst;
17694 int rd;
16dd5e42 17695 unsigned int negated, inverted;
ef8d22e6
PB
17696
17697 negated = encode_thumb32_immediate (-value);
17698 inverted = encode_thumb32_immediate (~value);
17699
17700 rd = (*instruction >> 8) & 0xf;
17701 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17702 switch (op)
17703 {
17704 /* ADD <-> SUB. Includes CMP <-> CMN. */
17705 case T2_OPCODE_SUB:
17706 new_inst = T2_OPCODE_ADD;
17707 value = negated;
17708 break;
17709
17710 case T2_OPCODE_ADD:
17711 new_inst = T2_OPCODE_SUB;
17712 value = negated;
17713 break;
17714
17715 /* ORR <-> ORN. Includes MOV <-> MVN. */
17716 case T2_OPCODE_ORR:
17717 new_inst = T2_OPCODE_ORN;
17718 value = inverted;
17719 break;
17720
17721 case T2_OPCODE_ORN:
17722 new_inst = T2_OPCODE_ORR;
17723 value = inverted;
17724 break;
17725
17726 /* AND <-> BIC. TST has no inverted equivalent. */
17727 case T2_OPCODE_AND:
17728 new_inst = T2_OPCODE_BIC;
17729 if (rd == 15)
17730 value = FAIL;
17731 else
17732 value = inverted;
17733 break;
17734
17735 case T2_OPCODE_BIC:
17736 new_inst = T2_OPCODE_AND;
17737 value = inverted;
17738 break;
17739
17740 /* ADC <-> SBC */
17741 case T2_OPCODE_ADC:
17742 new_inst = T2_OPCODE_SBC;
17743 value = inverted;
17744 break;
17745
17746 case T2_OPCODE_SBC:
17747 new_inst = T2_OPCODE_ADC;
17748 value = inverted;
17749 break;
17750
17751 /* We cannot do anything. */
17752 default:
17753 return FAIL;
17754 }
17755
16dd5e42 17756 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17757 return FAIL;
17758
17759 *instruction &= T2_OPCODE_MASK;
17760 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17761 return value;
17762}
17763
8f06b2d8
PB
17764/* Read a 32-bit thumb instruction from buf. */
17765static unsigned long
17766get_thumb32_insn (char * buf)
17767{
17768 unsigned long insn;
17769 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17770 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17771
17772 return insn;
17773}
17774
a8bc6c78
PB
17775
17776/* We usually want to set the low bit on the address of thumb function
17777 symbols. In particular .word foo - . should have the low bit set.
17778 Generic code tries to fold the difference of two symbols to
17779 a constant. Prevent this and force a relocation when the first symbols
17780 is a thumb function. */
17781int
17782arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17783{
17784 if (op == O_subtract
17785 && l->X_op == O_symbol
17786 && r->X_op == O_symbol
17787 && THUMB_IS_FUNC (l->X_add_symbol))
17788 {
17789 l->X_op = O_subtract;
17790 l->X_op_symbol = r->X_add_symbol;
17791 l->X_add_number -= r->X_add_number;
17792 return 1;
17793 }
17794 /* Process as normal. */
17795 return 0;
17796}
17797
c19d1205 17798void
55cf6793 17799md_apply_fix (fixS * fixP,
c19d1205
ZW
17800 valueT * valP,
17801 segT seg)
17802{
17803 offsetT value = * valP;
17804 offsetT newval;
17805 unsigned int newimm;
17806 unsigned long temp;
17807 int sign;
17808 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17809
c19d1205 17810 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17811
c19d1205 17812 /* Note whether this will delete the relocation. */
4962c51a 17813
c19d1205
ZW
17814 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17815 fixP->fx_done = 1;
b99bd4ef 17816
adbaf948
ZW
17817 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17818 consistency with the behavior on 32-bit hosts. Remember value
17819 for emit_reloc. */
17820 value &= 0xffffffff;
17821 value ^= 0x80000000;
17822 value -= 0x80000000;
17823
17824 *valP = value;
c19d1205 17825 fixP->fx_addnumber = value;
b99bd4ef 17826
adbaf948
ZW
17827 /* Same treatment for fixP->fx_offset. */
17828 fixP->fx_offset &= 0xffffffff;
17829 fixP->fx_offset ^= 0x80000000;
17830 fixP->fx_offset -= 0x80000000;
17831
c19d1205 17832 switch (fixP->fx_r_type)
b99bd4ef 17833 {
c19d1205
ZW
17834 case BFD_RELOC_NONE:
17835 /* This will need to go in the object file. */
17836 fixP->fx_done = 0;
17837 break;
b99bd4ef 17838
c19d1205
ZW
17839 case BFD_RELOC_ARM_IMMEDIATE:
17840 /* We claim that this fixup has been processed here,
17841 even if in fact we generate an error because we do
17842 not have a reloc for it, so tc_gen_reloc will reject it. */
17843 fixP->fx_done = 1;
b99bd4ef 17844
c19d1205
ZW
17845 if (fixP->fx_addsy
17846 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17847 {
c19d1205
ZW
17848 as_bad_where (fixP->fx_file, fixP->fx_line,
17849 _("undefined symbol %s used as an immediate value"),
17850 S_GET_NAME (fixP->fx_addsy));
17851 break;
b99bd4ef
NC
17852 }
17853
c19d1205
ZW
17854 newimm = encode_arm_immediate (value);
17855 temp = md_chars_to_number (buf, INSN_SIZE);
17856
17857 /* If the instruction will fail, see if we can fix things up by
17858 changing the opcode. */
17859 if (newimm == (unsigned int) FAIL
17860 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17861 {
c19d1205
ZW
17862 as_bad_where (fixP->fx_file, fixP->fx_line,
17863 _("invalid constant (%lx) after fixup"),
17864 (unsigned long) value);
17865 break;
b99bd4ef 17866 }
b99bd4ef 17867
c19d1205
ZW
17868 newimm |= (temp & 0xfffff000);
17869 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17870 break;
b99bd4ef 17871
c19d1205
ZW
17872 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17873 {
17874 unsigned int highpart = 0;
17875 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 17876
c19d1205
ZW
17877 newimm = encode_arm_immediate (value);
17878 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 17879
c19d1205
ZW
17880 /* If the instruction will fail, see if we can fix things up by
17881 changing the opcode. */
17882 if (newimm == (unsigned int) FAIL
17883 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17884 {
17885 /* No ? OK - try using two ADD instructions to generate
17886 the value. */
17887 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 17888
c19d1205
ZW
17889 /* Yes - then make sure that the second instruction is
17890 also an add. */
17891 if (newimm != (unsigned int) FAIL)
17892 newinsn = temp;
17893 /* Still No ? Try using a negated value. */
17894 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17895 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17896 /* Otherwise - give up. */
17897 else
17898 {
17899 as_bad_where (fixP->fx_file, fixP->fx_line,
17900 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17901 (long) value);
17902 break;
17903 }
b99bd4ef 17904
c19d1205
ZW
17905 /* Replace the first operand in the 2nd instruction (which
17906 is the PC) with the destination register. We have
17907 already added in the PC in the first instruction and we
17908 do not want to do it again. */
17909 newinsn &= ~ 0xf0000;
17910 newinsn |= ((newinsn & 0x0f000) << 4);
17911 }
b99bd4ef 17912
c19d1205
ZW
17913 newimm |= (temp & 0xfffff000);
17914 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 17915
c19d1205
ZW
17916 highpart |= (newinsn & 0xfffff000);
17917 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17918 }
17919 break;
b99bd4ef 17920
c19d1205 17921 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
17922 if (!fixP->fx_done && seg->use_rela_p)
17923 value = 0;
17924
c19d1205
ZW
17925 case BFD_RELOC_ARM_LITERAL:
17926 sign = value >= 0;
b99bd4ef 17927
c19d1205
ZW
17928 if (value < 0)
17929 value = - value;
b99bd4ef 17930
c19d1205 17931 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 17932 {
c19d1205
ZW
17933 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
17934 as_bad_where (fixP->fx_file, fixP->fx_line,
17935 _("invalid literal constant: pool needs to be closer"));
17936 else
17937 as_bad_where (fixP->fx_file, fixP->fx_line,
17938 _("bad immediate value for offset (%ld)"),
17939 (long) value);
17940 break;
f03698e6
RE
17941 }
17942
c19d1205
ZW
17943 newval = md_chars_to_number (buf, INSN_SIZE);
17944 newval &= 0xff7ff000;
17945 newval |= value | (sign ? INDEX_UP : 0);
17946 md_number_to_chars (buf, newval, INSN_SIZE);
17947 break;
b99bd4ef 17948
c19d1205
ZW
17949 case BFD_RELOC_ARM_OFFSET_IMM8:
17950 case BFD_RELOC_ARM_HWLITERAL:
17951 sign = value >= 0;
b99bd4ef 17952
c19d1205
ZW
17953 if (value < 0)
17954 value = - value;
b99bd4ef 17955
c19d1205 17956 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 17957 {
c19d1205
ZW
17958 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
17959 as_bad_where (fixP->fx_file, fixP->fx_line,
17960 _("invalid literal constant: pool needs to be closer"));
17961 else
f9d4405b 17962 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
17963 (long) value);
17964 break;
b99bd4ef
NC
17965 }
17966
c19d1205
ZW
17967 newval = md_chars_to_number (buf, INSN_SIZE);
17968 newval &= 0xff7ff0f0;
17969 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
17970 md_number_to_chars (buf, newval, INSN_SIZE);
17971 break;
b99bd4ef 17972
c19d1205
ZW
17973 case BFD_RELOC_ARM_T32_OFFSET_U8:
17974 if (value < 0 || value > 1020 || value % 4 != 0)
17975 as_bad_where (fixP->fx_file, fixP->fx_line,
17976 _("bad immediate value for offset (%ld)"), (long) value);
17977 value /= 4;
b99bd4ef 17978
c19d1205 17979 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
17980 newval |= value;
17981 md_number_to_chars (buf+2, newval, THUMB_SIZE);
17982 break;
b99bd4ef 17983
c19d1205
ZW
17984 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17985 /* This is a complicated relocation used for all varieties of Thumb32
17986 load/store instruction with immediate offset:
17987
17988 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
17989 *4, optional writeback(W)
17990 (doubleword load/store)
17991
17992 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
17993 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
17994 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
17995 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
17996 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
17997
17998 Uppercase letters indicate bits that are already encoded at
17999 this point. Lowercase letters are our problem. For the
18000 second block of instructions, the secondary opcode nybble
18001 (bits 8..11) is present, and bit 23 is zero, even if this is
18002 a PC-relative operation. */
18003 newval = md_chars_to_number (buf, THUMB_SIZE);
18004 newval <<= 16;
18005 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18006
c19d1205 18007 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18008 {
c19d1205
ZW
18009 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18010 if (value >= 0)
18011 newval |= (1 << 23);
18012 else
18013 value = -value;
18014 if (value % 4 != 0)
18015 {
18016 as_bad_where (fixP->fx_file, fixP->fx_line,
18017 _("offset not a multiple of 4"));
18018 break;
18019 }
18020 value /= 4;
216d22bc 18021 if (value > 0xff)
c19d1205
ZW
18022 {
18023 as_bad_where (fixP->fx_file, fixP->fx_line,
18024 _("offset out of range"));
18025 break;
18026 }
18027 newval &= ~0xff;
b99bd4ef 18028 }
c19d1205 18029 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18030 {
c19d1205
ZW
18031 /* PC-relative, 12-bit offset. */
18032 if (value >= 0)
18033 newval |= (1 << 23);
18034 else
18035 value = -value;
216d22bc 18036 if (value > 0xfff)
c19d1205
ZW
18037 {
18038 as_bad_where (fixP->fx_file, fixP->fx_line,
18039 _("offset out of range"));
18040 break;
18041 }
18042 newval &= ~0xfff;
b99bd4ef 18043 }
c19d1205 18044 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18045 {
c19d1205
ZW
18046 /* Writeback: 8-bit, +/- offset. */
18047 if (value >= 0)
18048 newval |= (1 << 9);
18049 else
18050 value = -value;
216d22bc 18051 if (value > 0xff)
c19d1205
ZW
18052 {
18053 as_bad_where (fixP->fx_file, fixP->fx_line,
18054 _("offset out of range"));
18055 break;
18056 }
18057 newval &= ~0xff;
b99bd4ef 18058 }
c19d1205 18059 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18060 {
c19d1205 18061 /* T-instruction: positive 8-bit offset. */
216d22bc 18062 if (value < 0 || value > 0xff)
b99bd4ef 18063 {
c19d1205
ZW
18064 as_bad_where (fixP->fx_file, fixP->fx_line,
18065 _("offset out of range"));
18066 break;
b99bd4ef 18067 }
c19d1205
ZW
18068 newval &= ~0xff;
18069 newval |= value;
b99bd4ef
NC
18070 }
18071 else
b99bd4ef 18072 {
c19d1205
ZW
18073 /* Positive 12-bit or negative 8-bit offset. */
18074 int limit;
18075 if (value >= 0)
b99bd4ef 18076 {
c19d1205
ZW
18077 newval |= (1 << 23);
18078 limit = 0xfff;
18079 }
18080 else
18081 {
18082 value = -value;
18083 limit = 0xff;
18084 }
18085 if (value > limit)
18086 {
18087 as_bad_where (fixP->fx_file, fixP->fx_line,
18088 _("offset out of range"));
18089 break;
b99bd4ef 18090 }
c19d1205 18091 newval &= ~limit;
b99bd4ef 18092 }
b99bd4ef 18093
c19d1205
ZW
18094 newval |= value;
18095 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18096 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18097 break;
404ff6b5 18098
c19d1205
ZW
18099 case BFD_RELOC_ARM_SHIFT_IMM:
18100 newval = md_chars_to_number (buf, INSN_SIZE);
18101 if (((unsigned long) value) > 32
18102 || (value == 32
18103 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18104 {
18105 as_bad_where (fixP->fx_file, fixP->fx_line,
18106 _("shift expression is too large"));
18107 break;
18108 }
404ff6b5 18109
c19d1205
ZW
18110 if (value == 0)
18111 /* Shifts of zero must be done as lsl. */
18112 newval &= ~0x60;
18113 else if (value == 32)
18114 value = 0;
18115 newval &= 0xfffff07f;
18116 newval |= (value & 0x1f) << 7;
18117 md_number_to_chars (buf, newval, INSN_SIZE);
18118 break;
404ff6b5 18119
c19d1205 18120 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18121 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18122 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18123 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18124 /* We claim that this fixup has been processed here,
18125 even if in fact we generate an error because we do
18126 not have a reloc for it, so tc_gen_reloc will reject it. */
18127 fixP->fx_done = 1;
404ff6b5 18128
c19d1205
ZW
18129 if (fixP->fx_addsy
18130 && ! S_IS_DEFINED (fixP->fx_addsy))
18131 {
18132 as_bad_where (fixP->fx_file, fixP->fx_line,
18133 _("undefined symbol %s used as an immediate value"),
18134 S_GET_NAME (fixP->fx_addsy));
18135 break;
18136 }
404ff6b5 18137
c19d1205
ZW
18138 newval = md_chars_to_number (buf, THUMB_SIZE);
18139 newval <<= 16;
18140 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18141
16805f35
PB
18142 newimm = FAIL;
18143 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18144 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18145 {
18146 newimm = encode_thumb32_immediate (value);
18147 if (newimm == (unsigned int) FAIL)
18148 newimm = thumb32_negate_data_op (&newval, value);
18149 }
16805f35
PB
18150 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18151 && newimm == (unsigned int) FAIL)
92e90b6e 18152 {
16805f35
PB
18153 /* Turn add/sum into addw/subw. */
18154 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18155 newval = (newval & 0xfeffffff) | 0x02000000;
18156
e9f89963
PB
18157 /* 12 bit immediate for addw/subw. */
18158 if (value < 0)
18159 {
18160 value = -value;
18161 newval ^= 0x00a00000;
18162 }
92e90b6e
PB
18163 if (value > 0xfff)
18164 newimm = (unsigned int) FAIL;
18165 else
18166 newimm = value;
18167 }
cc8a6dd0 18168
c19d1205 18169 if (newimm == (unsigned int)FAIL)
3631a3c8 18170 {
c19d1205
ZW
18171 as_bad_where (fixP->fx_file, fixP->fx_line,
18172 _("invalid constant (%lx) after fixup"),
18173 (unsigned long) value);
18174 break;
3631a3c8
NC
18175 }
18176
c19d1205
ZW
18177 newval |= (newimm & 0x800) << 15;
18178 newval |= (newimm & 0x700) << 4;
18179 newval |= (newimm & 0x0ff);
cc8a6dd0 18180
c19d1205
ZW
18181 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18182 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18183 break;
a737bd4d 18184
3eb17e6b 18185 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18186 if (((unsigned long) value) > 0xffff)
18187 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18188 _("invalid smc expression"));
2fc8bdac 18189 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18190 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18191 md_number_to_chars (buf, newval, INSN_SIZE);
18192 break;
a737bd4d 18193
c19d1205 18194 case BFD_RELOC_ARM_SWI:
adbaf948 18195 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18196 {
18197 if (((unsigned long) value) > 0xff)
18198 as_bad_where (fixP->fx_file, fixP->fx_line,
18199 _("invalid swi expression"));
2fc8bdac 18200 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18201 newval |= value;
18202 md_number_to_chars (buf, newval, THUMB_SIZE);
18203 }
18204 else
18205 {
18206 if (((unsigned long) value) > 0x00ffffff)
18207 as_bad_where (fixP->fx_file, fixP->fx_line,
18208 _("invalid swi expression"));
2fc8bdac 18209 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18210 newval |= value;
18211 md_number_to_chars (buf, newval, INSN_SIZE);
18212 }
18213 break;
a737bd4d 18214
c19d1205
ZW
18215 case BFD_RELOC_ARM_MULTI:
18216 if (((unsigned long) value) > 0xffff)
18217 as_bad_where (fixP->fx_file, fixP->fx_line,
18218 _("invalid expression in load/store multiple"));
18219 newval = value | md_chars_to_number (buf, INSN_SIZE);
18220 md_number_to_chars (buf, newval, INSN_SIZE);
18221 break;
a737bd4d 18222
c19d1205 18223#ifdef OBJ_ELF
39b41c9c
PB
18224 case BFD_RELOC_ARM_PCREL_CALL:
18225 newval = md_chars_to_number (buf, INSN_SIZE);
18226 if ((newval & 0xf0000000) == 0xf0000000)
18227 temp = 1;
18228 else
18229 temp = 3;
18230 goto arm_branch_common;
18231
18232 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18233 case BFD_RELOC_ARM_PLT32:
c19d1205 18234#endif
39b41c9c
PB
18235 case BFD_RELOC_ARM_PCREL_BRANCH:
18236 temp = 3;
18237 goto arm_branch_common;
a737bd4d 18238
39b41c9c
PB
18239 case BFD_RELOC_ARM_PCREL_BLX:
18240 temp = 1;
18241 arm_branch_common:
c19d1205 18242 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18243 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18244 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18245 also be be clear. */
18246 if (value & temp)
c19d1205 18247 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18248 _("misaligned branch destination"));
18249 if ((value & (offsetT)0xfe000000) != (offsetT)0
18250 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18251 as_bad_where (fixP->fx_file, fixP->fx_line,
18252 _("branch out of range"));
a737bd4d 18253
2fc8bdac 18254 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18255 {
2fc8bdac
ZW
18256 newval = md_chars_to_number (buf, INSN_SIZE);
18257 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18258 /* Set the H bit on BLX instructions. */
18259 if (temp == 1)
18260 {
18261 if (value & 2)
18262 newval |= 0x01000000;
18263 else
18264 newval &= ~0x01000000;
18265 }
2fc8bdac 18266 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18267 }
c19d1205 18268 break;
a737bd4d 18269
25fe350b
MS
18270 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18271 /* CBZ can only branch forward. */
a737bd4d 18272
738755b0
MS
18273 /* Attempts to use CBZ to branch to the next instruction
18274 (which, strictly speaking, are prohibited) will be turned into
18275 no-ops.
18276
18277 FIXME: It may be better to remove the instruction completely and
18278 perform relaxation. */
18279 if (value == -2)
2fc8bdac
ZW
18280 {
18281 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18282 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18283 md_number_to_chars (buf, newval, THUMB_SIZE);
18284 }
738755b0
MS
18285 else
18286 {
18287 if (value & ~0x7e)
18288 as_bad_where (fixP->fx_file, fixP->fx_line,
18289 _("branch out of range"));
18290
18291 if (fixP->fx_done || !seg->use_rela_p)
18292 {
18293 newval = md_chars_to_number (buf, THUMB_SIZE);
18294 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18295 md_number_to_chars (buf, newval, THUMB_SIZE);
18296 }
18297 }
c19d1205 18298 break;
a737bd4d 18299
c19d1205 18300 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18301 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18302 as_bad_where (fixP->fx_file, fixP->fx_line,
18303 _("branch out of range"));
a737bd4d 18304
2fc8bdac
ZW
18305 if (fixP->fx_done || !seg->use_rela_p)
18306 {
18307 newval = md_chars_to_number (buf, THUMB_SIZE);
18308 newval |= (value & 0x1ff) >> 1;
18309 md_number_to_chars (buf, newval, THUMB_SIZE);
18310 }
c19d1205 18311 break;
a737bd4d 18312
c19d1205 18313 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18314 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18315 as_bad_where (fixP->fx_file, fixP->fx_line,
18316 _("branch out of range"));
a737bd4d 18317
2fc8bdac
ZW
18318 if (fixP->fx_done || !seg->use_rela_p)
18319 {
18320 newval = md_chars_to_number (buf, THUMB_SIZE);
18321 newval |= (value & 0xfff) >> 1;
18322 md_number_to_chars (buf, newval, THUMB_SIZE);
18323 }
c19d1205 18324 break;
a737bd4d 18325
c19d1205 18326 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18327 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18328 as_bad_where (fixP->fx_file, fixP->fx_line,
18329 _("conditional branch out of range"));
404ff6b5 18330
2fc8bdac
ZW
18331 if (fixP->fx_done || !seg->use_rela_p)
18332 {
18333 offsetT newval2;
18334 addressT S, J1, J2, lo, hi;
404ff6b5 18335
2fc8bdac
ZW
18336 S = (value & 0x00100000) >> 20;
18337 J2 = (value & 0x00080000) >> 19;
18338 J1 = (value & 0x00040000) >> 18;
18339 hi = (value & 0x0003f000) >> 12;
18340 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18341
2fc8bdac
ZW
18342 newval = md_chars_to_number (buf, THUMB_SIZE);
18343 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18344 newval |= (S << 10) | hi;
18345 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18346 md_number_to_chars (buf, newval, THUMB_SIZE);
18347 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18348 }
c19d1205 18349 break;
6c43fab6 18350
c19d1205
ZW
18351 case BFD_RELOC_THUMB_PCREL_BLX:
18352 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18353 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18354 as_bad_where (fixP->fx_file, fixP->fx_line,
18355 _("branch out of range"));
404ff6b5 18356
2fc8bdac
ZW
18357 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18358 /* For a BLX instruction, make sure that the relocation is rounded up
18359 to a word boundary. This follows the semantics of the instruction
18360 which specifies that bit 1 of the target address will come from bit
18361 1 of the base address. */
18362 value = (value + 1) & ~ 1;
404ff6b5 18363
2fc8bdac 18364 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18365 {
2fc8bdac
ZW
18366 offsetT newval2;
18367
18368 newval = md_chars_to_number (buf, THUMB_SIZE);
18369 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18370 newval |= (value & 0x7fffff) >> 12;
18371 newval2 |= (value & 0xfff) >> 1;
18372 md_number_to_chars (buf, newval, THUMB_SIZE);
18373 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18374 }
c19d1205 18375 break;
404ff6b5 18376
c19d1205 18377 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18378 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18379 as_bad_where (fixP->fx_file, fixP->fx_line,
18380 _("branch out of range"));
6c43fab6 18381
2fc8bdac
ZW
18382 if (fixP->fx_done || !seg->use_rela_p)
18383 {
18384 offsetT newval2;
18385 addressT S, I1, I2, lo, hi;
6c43fab6 18386
2fc8bdac
ZW
18387 S = (value & 0x01000000) >> 24;
18388 I1 = (value & 0x00800000) >> 23;
18389 I2 = (value & 0x00400000) >> 22;
18390 hi = (value & 0x003ff000) >> 12;
18391 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18392
2fc8bdac
ZW
18393 I1 = !(I1 ^ S);
18394 I2 = !(I2 ^ S);
a737bd4d 18395
2fc8bdac
ZW
18396 newval = md_chars_to_number (buf, THUMB_SIZE);
18397 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18398 newval |= (S << 10) | hi;
18399 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18400 md_number_to_chars (buf, newval, THUMB_SIZE);
18401 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18402 }
18403 break;
a737bd4d 18404
2fc8bdac
ZW
18405 case BFD_RELOC_8:
18406 if (fixP->fx_done || !seg->use_rela_p)
18407 md_number_to_chars (buf, value, 1);
c19d1205 18408 break;
a737bd4d 18409
c19d1205 18410 case BFD_RELOC_16:
2fc8bdac 18411 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18412 md_number_to_chars (buf, value, 2);
c19d1205 18413 break;
a737bd4d 18414
c19d1205
ZW
18415#ifdef OBJ_ELF
18416 case BFD_RELOC_ARM_TLS_GD32:
18417 case BFD_RELOC_ARM_TLS_LE32:
18418 case BFD_RELOC_ARM_TLS_IE32:
18419 case BFD_RELOC_ARM_TLS_LDM32:
18420 case BFD_RELOC_ARM_TLS_LDO32:
18421 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18422 /* fall through */
6c43fab6 18423
c19d1205
ZW
18424 case BFD_RELOC_ARM_GOT32:
18425 case BFD_RELOC_ARM_GOTOFF:
18426 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18427 if (fixP->fx_done || !seg->use_rela_p)
18428 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18429 break;
18430#endif
6c43fab6 18431
c19d1205
ZW
18432 case BFD_RELOC_RVA:
18433 case BFD_RELOC_32:
18434 case BFD_RELOC_ARM_TARGET1:
18435 case BFD_RELOC_ARM_ROSEGREL32:
18436 case BFD_RELOC_ARM_SBREL32:
18437 case BFD_RELOC_32_PCREL:
f0927246
NC
18438#ifdef TE_PE
18439 case BFD_RELOC_32_SECREL:
18440#endif
2fc8bdac 18441 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18442#ifdef TE_WINCE
18443 /* For WinCE we only do this for pcrel fixups. */
18444 if (fixP->fx_done || fixP->fx_pcrel)
18445#endif
18446 md_number_to_chars (buf, value, 4);
c19d1205 18447 break;
6c43fab6 18448
c19d1205
ZW
18449#ifdef OBJ_ELF
18450 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18451 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18452 {
18453 newval = md_chars_to_number (buf, 4) & 0x80000000;
18454 if ((value ^ (value >> 1)) & 0x40000000)
18455 {
18456 as_bad_where (fixP->fx_file, fixP->fx_line,
18457 _("rel31 relocation overflow"));
18458 }
18459 newval |= value & 0x7fffffff;
18460 md_number_to_chars (buf, newval, 4);
18461 }
18462 break;
c19d1205 18463#endif
a737bd4d 18464
c19d1205 18465 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18466 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18467 if (value < -1023 || value > 1023 || (value & 3))
18468 as_bad_where (fixP->fx_file, fixP->fx_line,
18469 _("co-processor offset out of range"));
18470 cp_off_common:
18471 sign = value >= 0;
18472 if (value < 0)
18473 value = -value;
8f06b2d8
PB
18474 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18475 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18476 newval = md_chars_to_number (buf, INSN_SIZE);
18477 else
18478 newval = get_thumb32_insn (buf);
18479 newval &= 0xff7fff00;
c19d1205 18480 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18481 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18482 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18483 md_number_to_chars (buf, newval, INSN_SIZE);
18484 else
18485 put_thumb32_insn (buf, newval);
c19d1205 18486 break;
a737bd4d 18487
c19d1205 18488 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18489 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18490 if (value < -255 || value > 255)
18491 as_bad_where (fixP->fx_file, fixP->fx_line,
18492 _("co-processor offset out of range"));
df7849c5 18493 value *= 4;
c19d1205 18494 goto cp_off_common;
6c43fab6 18495
c19d1205
ZW
18496 case BFD_RELOC_ARM_THUMB_OFFSET:
18497 newval = md_chars_to_number (buf, THUMB_SIZE);
18498 /* Exactly what ranges, and where the offset is inserted depends
18499 on the type of instruction, we can establish this from the
18500 top 4 bits. */
18501 switch (newval >> 12)
18502 {
18503 case 4: /* PC load. */
18504 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18505 forced to zero for these loads; md_pcrel_from has already
18506 compensated for this. */
18507 if (value & 3)
18508 as_bad_where (fixP->fx_file, fixP->fx_line,
18509 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18510 (((unsigned long) fixP->fx_frag->fr_address
18511 + (unsigned long) fixP->fx_where) & ~3)
18512 + (unsigned long) value);
a737bd4d 18513
c19d1205
ZW
18514 if (value & ~0x3fc)
18515 as_bad_where (fixP->fx_file, fixP->fx_line,
18516 _("invalid offset, value too big (0x%08lX)"),
18517 (long) value);
a737bd4d 18518
c19d1205
ZW
18519 newval |= value >> 2;
18520 break;
a737bd4d 18521
c19d1205
ZW
18522 case 9: /* SP load/store. */
18523 if (value & ~0x3fc)
18524 as_bad_where (fixP->fx_file, fixP->fx_line,
18525 _("invalid offset, value too big (0x%08lX)"),
18526 (long) value);
18527 newval |= value >> 2;
18528 break;
6c43fab6 18529
c19d1205
ZW
18530 case 6: /* Word load/store. */
18531 if (value & ~0x7c)
18532 as_bad_where (fixP->fx_file, fixP->fx_line,
18533 _("invalid offset, value too big (0x%08lX)"),
18534 (long) value);
18535 newval |= value << 4; /* 6 - 2. */
18536 break;
a737bd4d 18537
c19d1205
ZW
18538 case 7: /* Byte load/store. */
18539 if (value & ~0x1f)
18540 as_bad_where (fixP->fx_file, fixP->fx_line,
18541 _("invalid offset, value too big (0x%08lX)"),
18542 (long) value);
18543 newval |= value << 6;
18544 break;
a737bd4d 18545
c19d1205
ZW
18546 case 8: /* Halfword load/store. */
18547 if (value & ~0x3e)
18548 as_bad_where (fixP->fx_file, fixP->fx_line,
18549 _("invalid offset, value too big (0x%08lX)"),
18550 (long) value);
18551 newval |= value << 5; /* 6 - 1. */
18552 break;
a737bd4d 18553
c19d1205
ZW
18554 default:
18555 as_bad_where (fixP->fx_file, fixP->fx_line,
18556 "Unable to process relocation for thumb opcode: %lx",
18557 (unsigned long) newval);
18558 break;
18559 }
18560 md_number_to_chars (buf, newval, THUMB_SIZE);
18561 break;
a737bd4d 18562
c19d1205
ZW
18563 case BFD_RELOC_ARM_THUMB_ADD:
18564 /* This is a complicated relocation, since we use it for all of
18565 the following immediate relocations:
a737bd4d 18566
c19d1205
ZW
18567 3bit ADD/SUB
18568 8bit ADD/SUB
18569 9bit ADD/SUB SP word-aligned
18570 10bit ADD PC/SP word-aligned
a737bd4d 18571
c19d1205
ZW
18572 The type of instruction being processed is encoded in the
18573 instruction field:
a737bd4d 18574
c19d1205
ZW
18575 0x8000 SUB
18576 0x00F0 Rd
18577 0x000F Rs
18578 */
18579 newval = md_chars_to_number (buf, THUMB_SIZE);
18580 {
18581 int rd = (newval >> 4) & 0xf;
18582 int rs = newval & 0xf;
18583 int subtract = !!(newval & 0x8000);
a737bd4d 18584
c19d1205
ZW
18585 /* Check for HI regs, only very restricted cases allowed:
18586 Adjusting SP, and using PC or SP to get an address. */
18587 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18588 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18589 as_bad_where (fixP->fx_file, fixP->fx_line,
18590 _("invalid Hi register with immediate"));
a737bd4d 18591
c19d1205
ZW
18592 /* If value is negative, choose the opposite instruction. */
18593 if (value < 0)
18594 {
18595 value = -value;
18596 subtract = !subtract;
18597 if (value < 0)
18598 as_bad_where (fixP->fx_file, fixP->fx_line,
18599 _("immediate value out of range"));
18600 }
a737bd4d 18601
c19d1205
ZW
18602 if (rd == REG_SP)
18603 {
18604 if (value & ~0x1fc)
18605 as_bad_where (fixP->fx_file, fixP->fx_line,
18606 _("invalid immediate for stack address calculation"));
18607 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18608 newval |= value >> 2;
18609 }
18610 else if (rs == REG_PC || rs == REG_SP)
18611 {
18612 if (subtract || value & ~0x3fc)
18613 as_bad_where (fixP->fx_file, fixP->fx_line,
18614 _("invalid immediate for address calculation (value = 0x%08lX)"),
18615 (unsigned long) value);
18616 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18617 newval |= rd << 8;
18618 newval |= value >> 2;
18619 }
18620 else if (rs == rd)
18621 {
18622 if (value & ~0xff)
18623 as_bad_where (fixP->fx_file, fixP->fx_line,
18624 _("immediate value out of range"));
18625 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18626 newval |= (rd << 8) | value;
18627 }
18628 else
18629 {
18630 if (value & ~0x7)
18631 as_bad_where (fixP->fx_file, fixP->fx_line,
18632 _("immediate value out of range"));
18633 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18634 newval |= rd | (rs << 3) | (value << 6);
18635 }
18636 }
18637 md_number_to_chars (buf, newval, THUMB_SIZE);
18638 break;
a737bd4d 18639
c19d1205
ZW
18640 case BFD_RELOC_ARM_THUMB_IMM:
18641 newval = md_chars_to_number (buf, THUMB_SIZE);
18642 if (value < 0 || value > 255)
18643 as_bad_where (fixP->fx_file, fixP->fx_line,
18644 _("invalid immediate: %ld is too large"),
18645 (long) value);
18646 newval |= value;
18647 md_number_to_chars (buf, newval, THUMB_SIZE);
18648 break;
a737bd4d 18649
c19d1205
ZW
18650 case BFD_RELOC_ARM_THUMB_SHIFT:
18651 /* 5bit shift value (0..32). LSL cannot take 32. */
18652 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18653 temp = newval & 0xf800;
18654 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18655 as_bad_where (fixP->fx_file, fixP->fx_line,
18656 _("invalid shift value: %ld"), (long) value);
18657 /* Shifts of zero must be encoded as LSL. */
18658 if (value == 0)
18659 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18660 /* Shifts of 32 are encoded as zero. */
18661 else if (value == 32)
18662 value = 0;
18663 newval |= value << 6;
18664 md_number_to_chars (buf, newval, THUMB_SIZE);
18665 break;
a737bd4d 18666
c19d1205
ZW
18667 case BFD_RELOC_VTABLE_INHERIT:
18668 case BFD_RELOC_VTABLE_ENTRY:
18669 fixP->fx_done = 0;
18670 return;
6c43fab6 18671
b6895b4f
PB
18672 case BFD_RELOC_ARM_MOVW:
18673 case BFD_RELOC_ARM_MOVT:
18674 case BFD_RELOC_ARM_THUMB_MOVW:
18675 case BFD_RELOC_ARM_THUMB_MOVT:
18676 if (fixP->fx_done || !seg->use_rela_p)
18677 {
18678 /* REL format relocations are limited to a 16-bit addend. */
18679 if (!fixP->fx_done)
18680 {
18681 if (value < -0x1000 || value > 0xffff)
18682 as_bad_where (fixP->fx_file, fixP->fx_line,
18683 _("offset too big"));
18684 }
18685 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18686 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18687 {
18688 value >>= 16;
18689 }
18690
18691 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18692 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18693 {
18694 newval = get_thumb32_insn (buf);
18695 newval &= 0xfbf08f00;
18696 newval |= (value & 0xf000) << 4;
18697 newval |= (value & 0x0800) << 15;
18698 newval |= (value & 0x0700) << 4;
18699 newval |= (value & 0x00ff);
18700 put_thumb32_insn (buf, newval);
18701 }
18702 else
18703 {
18704 newval = md_chars_to_number (buf, 4);
18705 newval &= 0xfff0f000;
18706 newval |= value & 0x0fff;
18707 newval |= (value & 0xf000) << 4;
18708 md_number_to_chars (buf, newval, 4);
18709 }
18710 }
18711 return;
18712
4962c51a
MS
18713 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18714 case BFD_RELOC_ARM_ALU_PC_G0:
18715 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18716 case BFD_RELOC_ARM_ALU_PC_G1:
18717 case BFD_RELOC_ARM_ALU_PC_G2:
18718 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18719 case BFD_RELOC_ARM_ALU_SB_G0:
18720 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18721 case BFD_RELOC_ARM_ALU_SB_G1:
18722 case BFD_RELOC_ARM_ALU_SB_G2:
18723 assert (!fixP->fx_done);
18724 if (!seg->use_rela_p)
18725 {
18726 bfd_vma insn;
18727 bfd_vma encoded_addend;
18728 bfd_vma addend_abs = abs (value);
18729
18730 /* Check that the absolute value of the addend can be
18731 expressed as an 8-bit constant plus a rotation. */
18732 encoded_addend = encode_arm_immediate (addend_abs);
18733 if (encoded_addend == (unsigned int) FAIL)
18734 as_bad_where (fixP->fx_file, fixP->fx_line,
18735 _("the offset 0x%08lX is not representable"),
18736 addend_abs);
18737
18738 /* Extract the instruction. */
18739 insn = md_chars_to_number (buf, INSN_SIZE);
18740
18741 /* If the addend is positive, use an ADD instruction.
18742 Otherwise use a SUB. Take care not to destroy the S bit. */
18743 insn &= 0xff1fffff;
18744 if (value < 0)
18745 insn |= 1 << 22;
18746 else
18747 insn |= 1 << 23;
18748
18749 /* Place the encoded addend into the first 12 bits of the
18750 instruction. */
18751 insn &= 0xfffff000;
18752 insn |= encoded_addend;
18753
18754 /* Update the instruction. */
18755 md_number_to_chars (buf, insn, INSN_SIZE);
18756 }
18757 break;
18758
18759 case BFD_RELOC_ARM_LDR_PC_G0:
18760 case BFD_RELOC_ARM_LDR_PC_G1:
18761 case BFD_RELOC_ARM_LDR_PC_G2:
18762 case BFD_RELOC_ARM_LDR_SB_G0:
18763 case BFD_RELOC_ARM_LDR_SB_G1:
18764 case BFD_RELOC_ARM_LDR_SB_G2:
18765 assert (!fixP->fx_done);
18766 if (!seg->use_rela_p)
18767 {
18768 bfd_vma insn;
18769 bfd_vma addend_abs = abs (value);
18770
18771 /* Check that the absolute value of the addend can be
18772 encoded in 12 bits. */
18773 if (addend_abs >= 0x1000)
18774 as_bad_where (fixP->fx_file, fixP->fx_line,
18775 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18776 addend_abs);
18777
18778 /* Extract the instruction. */
18779 insn = md_chars_to_number (buf, INSN_SIZE);
18780
18781 /* If the addend is negative, clear bit 23 of the instruction.
18782 Otherwise set it. */
18783 if (value < 0)
18784 insn &= ~(1 << 23);
18785 else
18786 insn |= 1 << 23;
18787
18788 /* Place the absolute value of the addend into the first 12 bits
18789 of the instruction. */
18790 insn &= 0xfffff000;
18791 insn |= addend_abs;
18792
18793 /* Update the instruction. */
18794 md_number_to_chars (buf, insn, INSN_SIZE);
18795 }
18796 break;
18797
18798 case BFD_RELOC_ARM_LDRS_PC_G0:
18799 case BFD_RELOC_ARM_LDRS_PC_G1:
18800 case BFD_RELOC_ARM_LDRS_PC_G2:
18801 case BFD_RELOC_ARM_LDRS_SB_G0:
18802 case BFD_RELOC_ARM_LDRS_SB_G1:
18803 case BFD_RELOC_ARM_LDRS_SB_G2:
18804 assert (!fixP->fx_done);
18805 if (!seg->use_rela_p)
18806 {
18807 bfd_vma insn;
18808 bfd_vma addend_abs = abs (value);
18809
18810 /* Check that the absolute value of the addend can be
18811 encoded in 8 bits. */
18812 if (addend_abs >= 0x100)
18813 as_bad_where (fixP->fx_file, fixP->fx_line,
18814 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18815 addend_abs);
18816
18817 /* Extract the instruction. */
18818 insn = md_chars_to_number (buf, INSN_SIZE);
18819
18820 /* If the addend is negative, clear bit 23 of the instruction.
18821 Otherwise set it. */
18822 if (value < 0)
18823 insn &= ~(1 << 23);
18824 else
18825 insn |= 1 << 23;
18826
18827 /* Place the first four bits of the absolute value of the addend
18828 into the first 4 bits of the instruction, and the remaining
18829 four into bits 8 .. 11. */
18830 insn &= 0xfffff0f0;
18831 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18832
18833 /* Update the instruction. */
18834 md_number_to_chars (buf, insn, INSN_SIZE);
18835 }
18836 break;
18837
18838 case BFD_RELOC_ARM_LDC_PC_G0:
18839 case BFD_RELOC_ARM_LDC_PC_G1:
18840 case BFD_RELOC_ARM_LDC_PC_G2:
18841 case BFD_RELOC_ARM_LDC_SB_G0:
18842 case BFD_RELOC_ARM_LDC_SB_G1:
18843 case BFD_RELOC_ARM_LDC_SB_G2:
18844 assert (!fixP->fx_done);
18845 if (!seg->use_rela_p)
18846 {
18847 bfd_vma insn;
18848 bfd_vma addend_abs = abs (value);
18849
18850 /* Check that the absolute value of the addend is a multiple of
18851 four and, when divided by four, fits in 8 bits. */
18852 if (addend_abs & 0x3)
18853 as_bad_where (fixP->fx_file, fixP->fx_line,
18854 _("bad offset 0x%08lX (must be word-aligned)"),
18855 addend_abs);
18856
18857 if ((addend_abs >> 2) > 0xff)
18858 as_bad_where (fixP->fx_file, fixP->fx_line,
18859 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18860 addend_abs);
18861
18862 /* Extract the instruction. */
18863 insn = md_chars_to_number (buf, INSN_SIZE);
18864
18865 /* If the addend is negative, clear bit 23 of the instruction.
18866 Otherwise set it. */
18867 if (value < 0)
18868 insn &= ~(1 << 23);
18869 else
18870 insn |= 1 << 23;
18871
18872 /* Place the addend (divided by four) into the first eight
18873 bits of the instruction. */
18874 insn &= 0xfffffff0;
18875 insn |= addend_abs >> 2;
18876
18877 /* Update the instruction. */
18878 md_number_to_chars (buf, insn, INSN_SIZE);
18879 }
18880 break;
18881
c19d1205
ZW
18882 case BFD_RELOC_UNUSED:
18883 default:
18884 as_bad_where (fixP->fx_file, fixP->fx_line,
18885 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18886 }
6c43fab6
RE
18887}
18888
c19d1205
ZW
18889/* Translate internal representation of relocation info to BFD target
18890 format. */
a737bd4d 18891
c19d1205 18892arelent *
00a97672 18893tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 18894{
c19d1205
ZW
18895 arelent * reloc;
18896 bfd_reloc_code_real_type code;
a737bd4d 18897
c19d1205 18898 reloc = xmalloc (sizeof (arelent));
a737bd4d 18899
c19d1205
ZW
18900 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18901 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18902 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 18903
2fc8bdac 18904 if (fixp->fx_pcrel)
00a97672
RS
18905 {
18906 if (section->use_rela_p)
18907 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18908 else
18909 fixp->fx_offset = reloc->address;
18910 }
c19d1205 18911 reloc->addend = fixp->fx_offset;
a737bd4d 18912
c19d1205 18913 switch (fixp->fx_r_type)
a737bd4d 18914 {
c19d1205
ZW
18915 case BFD_RELOC_8:
18916 if (fixp->fx_pcrel)
18917 {
18918 code = BFD_RELOC_8_PCREL;
18919 break;
18920 }
a737bd4d 18921
c19d1205
ZW
18922 case BFD_RELOC_16:
18923 if (fixp->fx_pcrel)
18924 {
18925 code = BFD_RELOC_16_PCREL;
18926 break;
18927 }
6c43fab6 18928
c19d1205
ZW
18929 case BFD_RELOC_32:
18930 if (fixp->fx_pcrel)
18931 {
18932 code = BFD_RELOC_32_PCREL;
18933 break;
18934 }
a737bd4d 18935
b6895b4f
PB
18936 case BFD_RELOC_ARM_MOVW:
18937 if (fixp->fx_pcrel)
18938 {
18939 code = BFD_RELOC_ARM_MOVW_PCREL;
18940 break;
18941 }
18942
18943 case BFD_RELOC_ARM_MOVT:
18944 if (fixp->fx_pcrel)
18945 {
18946 code = BFD_RELOC_ARM_MOVT_PCREL;
18947 break;
18948 }
18949
18950 case BFD_RELOC_ARM_THUMB_MOVW:
18951 if (fixp->fx_pcrel)
18952 {
18953 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
18954 break;
18955 }
18956
18957 case BFD_RELOC_ARM_THUMB_MOVT:
18958 if (fixp->fx_pcrel)
18959 {
18960 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
18961 break;
18962 }
18963
c19d1205
ZW
18964 case BFD_RELOC_NONE:
18965 case BFD_RELOC_ARM_PCREL_BRANCH:
18966 case BFD_RELOC_ARM_PCREL_BLX:
18967 case BFD_RELOC_RVA:
18968 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18969 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18970 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18971 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18972 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18973 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18974 case BFD_RELOC_THUMB_PCREL_BLX:
18975 case BFD_RELOC_VTABLE_ENTRY:
18976 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
18977#ifdef TE_PE
18978 case BFD_RELOC_32_SECREL:
18979#endif
c19d1205
ZW
18980 code = fixp->fx_r_type;
18981 break;
a737bd4d 18982
c19d1205
ZW
18983 case BFD_RELOC_ARM_LITERAL:
18984 case BFD_RELOC_ARM_HWLITERAL:
18985 /* If this is called then the a literal has
18986 been referenced across a section boundary. */
18987 as_bad_where (fixp->fx_file, fixp->fx_line,
18988 _("literal referenced across section boundary"));
18989 return NULL;
a737bd4d 18990
c19d1205
ZW
18991#ifdef OBJ_ELF
18992 case BFD_RELOC_ARM_GOT32:
18993 case BFD_RELOC_ARM_GOTOFF:
18994 case BFD_RELOC_ARM_PLT32:
18995 case BFD_RELOC_ARM_TARGET1:
18996 case BFD_RELOC_ARM_ROSEGREL32:
18997 case BFD_RELOC_ARM_SBREL32:
18998 case BFD_RELOC_ARM_PREL31:
18999 case BFD_RELOC_ARM_TARGET2:
19000 case BFD_RELOC_ARM_TLS_LE32:
19001 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19002 case BFD_RELOC_ARM_PCREL_CALL:
19003 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19004 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19005 case BFD_RELOC_ARM_ALU_PC_G0:
19006 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19007 case BFD_RELOC_ARM_ALU_PC_G1:
19008 case BFD_RELOC_ARM_ALU_PC_G2:
19009 case BFD_RELOC_ARM_LDR_PC_G0:
19010 case BFD_RELOC_ARM_LDR_PC_G1:
19011 case BFD_RELOC_ARM_LDR_PC_G2:
19012 case BFD_RELOC_ARM_LDRS_PC_G0:
19013 case BFD_RELOC_ARM_LDRS_PC_G1:
19014 case BFD_RELOC_ARM_LDRS_PC_G2:
19015 case BFD_RELOC_ARM_LDC_PC_G0:
19016 case BFD_RELOC_ARM_LDC_PC_G1:
19017 case BFD_RELOC_ARM_LDC_PC_G2:
19018 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19019 case BFD_RELOC_ARM_ALU_SB_G0:
19020 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19021 case BFD_RELOC_ARM_ALU_SB_G1:
19022 case BFD_RELOC_ARM_ALU_SB_G2:
19023 case BFD_RELOC_ARM_LDR_SB_G0:
19024 case BFD_RELOC_ARM_LDR_SB_G1:
19025 case BFD_RELOC_ARM_LDR_SB_G2:
19026 case BFD_RELOC_ARM_LDRS_SB_G0:
19027 case BFD_RELOC_ARM_LDRS_SB_G1:
19028 case BFD_RELOC_ARM_LDRS_SB_G2:
19029 case BFD_RELOC_ARM_LDC_SB_G0:
19030 case BFD_RELOC_ARM_LDC_SB_G1:
19031 case BFD_RELOC_ARM_LDC_SB_G2:
c19d1205
ZW
19032 code = fixp->fx_r_type;
19033 break;
a737bd4d 19034
c19d1205
ZW
19035 case BFD_RELOC_ARM_TLS_GD32:
19036 case BFD_RELOC_ARM_TLS_IE32:
19037 case BFD_RELOC_ARM_TLS_LDM32:
19038 /* BFD will include the symbol's address in the addend.
19039 But we don't want that, so subtract it out again here. */
19040 if (!S_IS_COMMON (fixp->fx_addsy))
19041 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19042 code = fixp->fx_r_type;
19043 break;
19044#endif
a737bd4d 19045
c19d1205
ZW
19046 case BFD_RELOC_ARM_IMMEDIATE:
19047 as_bad_where (fixp->fx_file, fixp->fx_line,
19048 _("internal relocation (type: IMMEDIATE) not fixed up"));
19049 return NULL;
a737bd4d 19050
c19d1205
ZW
19051 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19052 as_bad_where (fixp->fx_file, fixp->fx_line,
19053 _("ADRL used for a symbol not defined in the same file"));
19054 return NULL;
a737bd4d 19055
c19d1205 19056 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19057 if (section->use_rela_p)
19058 {
19059 code = fixp->fx_r_type;
19060 break;
19061 }
19062
c19d1205
ZW
19063 if (fixp->fx_addsy != NULL
19064 && !S_IS_DEFINED (fixp->fx_addsy)
19065 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19066 {
c19d1205
ZW
19067 as_bad_where (fixp->fx_file, fixp->fx_line,
19068 _("undefined local label `%s'"),
19069 S_GET_NAME (fixp->fx_addsy));
19070 return NULL;
a737bd4d
NC
19071 }
19072
c19d1205
ZW
19073 as_bad_where (fixp->fx_file, fixp->fx_line,
19074 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19075 return NULL;
a737bd4d 19076
c19d1205
ZW
19077 default:
19078 {
19079 char * type;
6c43fab6 19080
c19d1205
ZW
19081 switch (fixp->fx_r_type)
19082 {
19083 case BFD_RELOC_NONE: type = "NONE"; break;
19084 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19085 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19086 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19087 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19088 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19089 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19090 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19091 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19092 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19093 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19094 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19095 default: type = _("<unknown>"); break;
19096 }
19097 as_bad_where (fixp->fx_file, fixp->fx_line,
19098 _("cannot represent %s relocation in this object file format"),
19099 type);
19100 return NULL;
19101 }
a737bd4d 19102 }
6c43fab6 19103
c19d1205
ZW
19104#ifdef OBJ_ELF
19105 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19106 && GOT_symbol
19107 && fixp->fx_addsy == GOT_symbol)
19108 {
19109 code = BFD_RELOC_ARM_GOTPC;
19110 reloc->addend = fixp->fx_offset = reloc->address;
19111 }
19112#endif
6c43fab6 19113
c19d1205 19114 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19115
c19d1205
ZW
19116 if (reloc->howto == NULL)
19117 {
19118 as_bad_where (fixp->fx_file, fixp->fx_line,
19119 _("cannot represent %s relocation in this object file format"),
19120 bfd_get_reloc_code_name (code));
19121 return NULL;
19122 }
6c43fab6 19123
c19d1205
ZW
19124 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19125 vtable entry to be used in the relocation's section offset. */
19126 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19127 reloc->address = fixp->fx_offset;
6c43fab6 19128
c19d1205 19129 return reloc;
6c43fab6
RE
19130}
19131
c19d1205 19132/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19133
c19d1205
ZW
19134void
19135cons_fix_new_arm (fragS * frag,
19136 int where,
19137 int size,
19138 expressionS * exp)
6c43fab6 19139{
c19d1205
ZW
19140 bfd_reloc_code_real_type type;
19141 int pcrel = 0;
6c43fab6 19142
c19d1205
ZW
19143 /* Pick a reloc.
19144 FIXME: @@ Should look at CPU word size. */
19145 switch (size)
19146 {
19147 case 1:
19148 type = BFD_RELOC_8;
19149 break;
19150 case 2:
19151 type = BFD_RELOC_16;
19152 break;
19153 case 4:
19154 default:
19155 type = BFD_RELOC_32;
19156 break;
19157 case 8:
19158 type = BFD_RELOC_64;
19159 break;
19160 }
6c43fab6 19161
f0927246
NC
19162#ifdef TE_PE
19163 if (exp->X_op == O_secrel)
19164 {
19165 exp->X_op = O_symbol;
19166 type = BFD_RELOC_32_SECREL;
19167 }
19168#endif
19169
c19d1205
ZW
19170 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19171}
6c43fab6 19172
c19d1205
ZW
19173#if defined OBJ_COFF || defined OBJ_ELF
19174void
19175arm_validate_fix (fixS * fixP)
6c43fab6 19176{
c19d1205
ZW
19177 /* If the destination of the branch is a defined symbol which does not have
19178 the THUMB_FUNC attribute, then we must be calling a function which has
19179 the (interfacearm) attribute. We look for the Thumb entry point to that
19180 function and change the branch to refer to that function instead. */
19181 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19182 && fixP->fx_addsy != NULL
19183 && S_IS_DEFINED (fixP->fx_addsy)
19184 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19185 {
c19d1205 19186 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19187 }
c19d1205
ZW
19188}
19189#endif
6c43fab6 19190
c19d1205
ZW
19191int
19192arm_force_relocation (struct fix * fixp)
19193{
19194#if defined (OBJ_COFF) && defined (TE_PE)
19195 if (fixp->fx_r_type == BFD_RELOC_RVA)
19196 return 1;
19197#endif
6c43fab6 19198
c19d1205
ZW
19199 /* Resolve these relocations even if the symbol is extern or weak. */
19200 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19201 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19202 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19203 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19204 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19205 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19206 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19207 return 0;
a737bd4d 19208
4962c51a
MS
19209 /* Always leave these relocations for the linker. */
19210 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19211 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19212 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19213 return 1;
19214
f0291e4c
PB
19215 /* Always generate relocations against function symbols. */
19216 if (fixp->fx_r_type == BFD_RELOC_32
19217 && fixp->fx_addsy
19218 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19219 return 1;
19220
c19d1205 19221 return generic_force_reloc (fixp);
404ff6b5
AH
19222}
19223
0ffdc86c 19224#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19225/* Relocations against function names must be left unadjusted,
19226 so that the linker can use this information to generate interworking
19227 stubs. The MIPS version of this function
c19d1205
ZW
19228 also prevents relocations that are mips-16 specific, but I do not
19229 know why it does this.
404ff6b5 19230
c19d1205
ZW
19231 FIXME:
19232 There is one other problem that ought to be addressed here, but
19233 which currently is not: Taking the address of a label (rather
19234 than a function) and then later jumping to that address. Such
19235 addresses also ought to have their bottom bit set (assuming that
19236 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19237
c19d1205
ZW
19238bfd_boolean
19239arm_fix_adjustable (fixS * fixP)
404ff6b5 19240{
c19d1205
ZW
19241 if (fixP->fx_addsy == NULL)
19242 return 1;
404ff6b5 19243
e28387c3
PB
19244 /* Preserve relocations against symbols with function type. */
19245 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19246 return 0;
19247
c19d1205
ZW
19248 if (THUMB_IS_FUNC (fixP->fx_addsy)
19249 && fixP->fx_subsy == NULL)
19250 return 0;
a737bd4d 19251
c19d1205
ZW
19252 /* We need the symbol name for the VTABLE entries. */
19253 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19254 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19255 return 0;
404ff6b5 19256
c19d1205
ZW
19257 /* Don't allow symbols to be discarded on GOT related relocs. */
19258 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19259 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19260 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19261 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19262 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19263 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19264 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19265 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19266 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19267 return 0;
a737bd4d 19268
4962c51a
MS
19269 /* Similarly for group relocations. */
19270 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19271 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19272 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19273 return 0;
19274
c19d1205 19275 return 1;
a737bd4d 19276}
0ffdc86c
NC
19277#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19278
19279#ifdef OBJ_ELF
404ff6b5 19280
c19d1205
ZW
19281const char *
19282elf32_arm_target_format (void)
404ff6b5 19283{
c19d1205
ZW
19284#ifdef TE_SYMBIAN
19285 return (target_big_endian
19286 ? "elf32-bigarm-symbian"
19287 : "elf32-littlearm-symbian");
19288#elif defined (TE_VXWORKS)
19289 return (target_big_endian
19290 ? "elf32-bigarm-vxworks"
19291 : "elf32-littlearm-vxworks");
19292#else
19293 if (target_big_endian)
19294 return "elf32-bigarm";
19295 else
19296 return "elf32-littlearm";
19297#endif
404ff6b5
AH
19298}
19299
c19d1205
ZW
19300void
19301armelf_frob_symbol (symbolS * symp,
19302 int * puntp)
404ff6b5 19303{
c19d1205
ZW
19304 elf_frob_symbol (symp, puntp);
19305}
19306#endif
404ff6b5 19307
c19d1205 19308/* MD interface: Finalization. */
a737bd4d 19309
c19d1205
ZW
19310/* A good place to do this, although this was probably not intended
19311 for this kind of use. We need to dump the literal pool before
19312 references are made to a null symbol pointer. */
a737bd4d 19313
c19d1205
ZW
19314void
19315arm_cleanup (void)
19316{
19317 literal_pool * pool;
a737bd4d 19318
c19d1205
ZW
19319 for (pool = list_of_pools; pool; pool = pool->next)
19320 {
19321 /* Put it at the end of the relevent section. */
19322 subseg_set (pool->section, pool->sub_section);
19323#ifdef OBJ_ELF
19324 arm_elf_change_section ();
19325#endif
19326 s_ltorg (0);
19327 }
404ff6b5
AH
19328}
19329
c19d1205
ZW
19330/* Adjust the symbol table. This marks Thumb symbols as distinct from
19331 ARM ones. */
404ff6b5 19332
c19d1205
ZW
19333void
19334arm_adjust_symtab (void)
404ff6b5 19335{
c19d1205
ZW
19336#ifdef OBJ_COFF
19337 symbolS * sym;
404ff6b5 19338
c19d1205
ZW
19339 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19340 {
19341 if (ARM_IS_THUMB (sym))
19342 {
19343 if (THUMB_IS_FUNC (sym))
19344 {
19345 /* Mark the symbol as a Thumb function. */
19346 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19347 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19348 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19349
c19d1205
ZW
19350 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19351 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19352 else
19353 as_bad (_("%s: unexpected function type: %d"),
19354 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19355 }
19356 else switch (S_GET_STORAGE_CLASS (sym))
19357 {
19358 case C_EXT:
19359 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19360 break;
19361 case C_STAT:
19362 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19363 break;
19364 case C_LABEL:
19365 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19366 break;
19367 default:
19368 /* Do nothing. */
19369 break;
19370 }
19371 }
a737bd4d 19372
c19d1205
ZW
19373 if (ARM_IS_INTERWORK (sym))
19374 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19375 }
c19d1205
ZW
19376#endif
19377#ifdef OBJ_ELF
19378 symbolS * sym;
19379 char bind;
404ff6b5 19380
c19d1205 19381 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19382 {
c19d1205
ZW
19383 if (ARM_IS_THUMB (sym))
19384 {
19385 elf_symbol_type * elf_sym;
404ff6b5 19386
c19d1205
ZW
19387 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19388 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19389
b0796911
PB
19390 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19391 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19392 {
19393 /* If it's a .thumb_func, declare it as so,
19394 otherwise tag label as .code 16. */
19395 if (THUMB_IS_FUNC (sym))
19396 elf_sym->internal_elf_sym.st_info =
19397 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19398 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19399 elf_sym->internal_elf_sym.st_info =
19400 ELF_ST_INFO (bind, STT_ARM_16BIT);
19401 }
19402 }
19403 }
19404#endif
404ff6b5
AH
19405}
19406
c19d1205 19407/* MD interface: Initialization. */
404ff6b5 19408
a737bd4d 19409static void
c19d1205 19410set_constant_flonums (void)
a737bd4d 19411{
c19d1205 19412 int i;
404ff6b5 19413
c19d1205
ZW
19414 for (i = 0; i < NUM_FLOAT_VALS; i++)
19415 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19416 abort ();
a737bd4d 19417}
404ff6b5 19418
3e9e4fcf
JB
19419/* Auto-select Thumb mode if it's the only available instruction set for the
19420 given architecture. */
19421
19422static void
19423autoselect_thumb_from_cpu_variant (void)
19424{
19425 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19426 opcode_select (16);
19427}
19428
c19d1205
ZW
19429void
19430md_begin (void)
a737bd4d 19431{
c19d1205
ZW
19432 unsigned mach;
19433 unsigned int i;
404ff6b5 19434
c19d1205
ZW
19435 if ( (arm_ops_hsh = hash_new ()) == NULL
19436 || (arm_cond_hsh = hash_new ()) == NULL
19437 || (arm_shift_hsh = hash_new ()) == NULL
19438 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19439 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19440 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19441 || (arm_reloc_hsh = hash_new ()) == NULL
19442 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19443 as_fatal (_("virtual memory exhausted"));
19444
19445 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19446 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19447 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19448 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19449 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19450 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19451 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19452 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19453 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19454 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19455 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19456 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19457 for (i = 0;
19458 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19459 i++)
19460 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19461 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19462#ifdef OBJ_ELF
19463 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19464 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19465#endif
19466
19467 set_constant_flonums ();
404ff6b5 19468
c19d1205
ZW
19469 /* Set the cpu variant based on the command-line options. We prefer
19470 -mcpu= over -march= if both are set (as for GCC); and we prefer
19471 -mfpu= over any other way of setting the floating point unit.
19472 Use of legacy options with new options are faulted. */
e74cfd16 19473 if (legacy_cpu)
404ff6b5 19474 {
e74cfd16 19475 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19476 as_bad (_("use of old and new-style options to set CPU type"));
19477
19478 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19479 }
e74cfd16 19480 else if (!mcpu_cpu_opt)
c19d1205 19481 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19482
e74cfd16 19483 if (legacy_fpu)
c19d1205 19484 {
e74cfd16 19485 if (mfpu_opt)
c19d1205 19486 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19487
19488 mfpu_opt = legacy_fpu;
19489 }
e74cfd16 19490 else if (!mfpu_opt)
03b1477f 19491 {
c19d1205 19492#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19493 /* Some environments specify a default FPU. If they don't, infer it
19494 from the processor. */
e74cfd16 19495 if (mcpu_fpu_opt)
03b1477f
RE
19496 mfpu_opt = mcpu_fpu_opt;
19497 else
19498 mfpu_opt = march_fpu_opt;
39c2da32 19499#else
e74cfd16 19500 mfpu_opt = &fpu_default;
39c2da32 19501#endif
03b1477f
RE
19502 }
19503
e74cfd16 19504 if (!mfpu_opt)
03b1477f 19505 {
493cb6ef 19506 if (mcpu_cpu_opt != NULL)
e74cfd16 19507 mfpu_opt = &fpu_default;
493cb6ef 19508 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19509 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19510 else
e74cfd16 19511 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19512 }
19513
ee065d83 19514#ifdef CPU_DEFAULT
e74cfd16 19515 if (!mcpu_cpu_opt)
ee065d83 19516 {
e74cfd16
PB
19517 mcpu_cpu_opt = &cpu_default;
19518 selected_cpu = cpu_default;
ee065d83 19519 }
e74cfd16
PB
19520#else
19521 if (mcpu_cpu_opt)
19522 selected_cpu = *mcpu_cpu_opt;
ee065d83 19523 else
e74cfd16 19524 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19525#endif
03b1477f 19526
e74cfd16 19527 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19528
3e9e4fcf
JB
19529 autoselect_thumb_from_cpu_variant ();
19530
e74cfd16 19531 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19532
f17c130b 19533#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19534 {
7cc69913
NC
19535 unsigned int flags = 0;
19536
19537#if defined OBJ_ELF
19538 flags = meabi_flags;
d507cf36
PB
19539
19540 switch (meabi_flags)
33a392fb 19541 {
d507cf36 19542 case EF_ARM_EABI_UNKNOWN:
7cc69913 19543#endif
d507cf36
PB
19544 /* Set the flags in the private structure. */
19545 if (uses_apcs_26) flags |= F_APCS26;
19546 if (support_interwork) flags |= F_INTERWORK;
19547 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19548 if (pic_code) flags |= F_PIC;
e74cfd16 19549 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19550 flags |= F_SOFT_FLOAT;
19551
d507cf36
PB
19552 switch (mfloat_abi_opt)
19553 {
19554 case ARM_FLOAT_ABI_SOFT:
19555 case ARM_FLOAT_ABI_SOFTFP:
19556 flags |= F_SOFT_FLOAT;
19557 break;
33a392fb 19558
d507cf36
PB
19559 case ARM_FLOAT_ABI_HARD:
19560 if (flags & F_SOFT_FLOAT)
19561 as_bad (_("hard-float conflicts with specified fpu"));
19562 break;
19563 }
03b1477f 19564
e74cfd16
PB
19565 /* Using pure-endian doubles (even if soft-float). */
19566 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19567 flags |= F_VFP_FLOAT;
f17c130b 19568
fde78edd 19569#if defined OBJ_ELF
e74cfd16 19570 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19571 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19572 break;
19573
8cb51566 19574 case EF_ARM_EABI_VER4:
3a4a14e9 19575 case EF_ARM_EABI_VER5:
c19d1205 19576 /* No additional flags to set. */
d507cf36
PB
19577 break;
19578
19579 default:
19580 abort ();
19581 }
7cc69913 19582#endif
b99bd4ef
NC
19583 bfd_set_private_flags (stdoutput, flags);
19584
19585 /* We have run out flags in the COFF header to encode the
19586 status of ATPCS support, so instead we create a dummy,
c19d1205 19587 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19588 if (atpcs)
19589 {
19590 asection * sec;
19591
19592 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19593
19594 if (sec != NULL)
19595 {
19596 bfd_set_section_flags
19597 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19598 bfd_set_section_size (stdoutput, sec, 0);
19599 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19600 }
19601 }
7cc69913 19602 }
f17c130b 19603#endif
b99bd4ef
NC
19604
19605 /* Record the CPU type as well. */
2d447fca
JM
19606 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19607 mach = bfd_mach_arm_iWMMXt2;
19608 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19609 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19610 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19611 mach = bfd_mach_arm_XScale;
e74cfd16 19612 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19613 mach = bfd_mach_arm_ep9312;
e74cfd16 19614 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19615 mach = bfd_mach_arm_5TE;
e74cfd16 19616 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19617 {
e74cfd16 19618 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19619 mach = bfd_mach_arm_5T;
19620 else
19621 mach = bfd_mach_arm_5;
19622 }
e74cfd16 19623 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19624 {
e74cfd16 19625 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19626 mach = bfd_mach_arm_4T;
19627 else
19628 mach = bfd_mach_arm_4;
19629 }
e74cfd16 19630 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19631 mach = bfd_mach_arm_3M;
e74cfd16
PB
19632 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19633 mach = bfd_mach_arm_3;
19634 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19635 mach = bfd_mach_arm_2a;
19636 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19637 mach = bfd_mach_arm_2;
19638 else
19639 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19640
19641 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19642}
19643
c19d1205 19644/* Command line processing. */
b99bd4ef 19645
c19d1205
ZW
19646/* md_parse_option
19647 Invocation line includes a switch not recognized by the base assembler.
19648 See if it's a processor-specific option.
b99bd4ef 19649
c19d1205
ZW
19650 This routine is somewhat complicated by the need for backwards
19651 compatibility (since older releases of gcc can't be changed).
19652 The new options try to make the interface as compatible as
19653 possible with GCC.
b99bd4ef 19654
c19d1205 19655 New options (supported) are:
b99bd4ef 19656
c19d1205
ZW
19657 -mcpu=<cpu name> Assemble for selected processor
19658 -march=<architecture name> Assemble for selected architecture
19659 -mfpu=<fpu architecture> Assemble for selected FPU.
19660 -EB/-mbig-endian Big-endian
19661 -EL/-mlittle-endian Little-endian
19662 -k Generate PIC code
19663 -mthumb Start in Thumb mode
19664 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19665
c19d1205 19666 For now we will also provide support for:
b99bd4ef 19667
c19d1205
ZW
19668 -mapcs-32 32-bit Program counter
19669 -mapcs-26 26-bit Program counter
19670 -macps-float Floats passed in FP registers
19671 -mapcs-reentrant Reentrant code
19672 -matpcs
19673 (sometime these will probably be replaced with -mapcs=<list of options>
19674 and -matpcs=<list of options>)
b99bd4ef 19675
c19d1205
ZW
19676 The remaining options are only supported for back-wards compatibility.
19677 Cpu variants, the arm part is optional:
19678 -m[arm]1 Currently not supported.
19679 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19680 -m[arm]3 Arm 3 processor
19681 -m[arm]6[xx], Arm 6 processors
19682 -m[arm]7[xx][t][[d]m] Arm 7 processors
19683 -m[arm]8[10] Arm 8 processors
19684 -m[arm]9[20][tdmi] Arm 9 processors
19685 -mstrongarm[110[0]] StrongARM processors
19686 -mxscale XScale processors
19687 -m[arm]v[2345[t[e]]] Arm architectures
19688 -mall All (except the ARM1)
19689 FP variants:
19690 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19691 -mfpe-old (No float load/store multiples)
19692 -mvfpxd VFP Single precision
19693 -mvfp All VFP
19694 -mno-fpu Disable all floating point instructions
b99bd4ef 19695
c19d1205
ZW
19696 The following CPU names are recognized:
19697 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19698 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19699 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19700 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19701 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19702 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19703 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19704
c19d1205 19705 */
b99bd4ef 19706
c19d1205 19707const char * md_shortopts = "m:k";
b99bd4ef 19708
c19d1205
ZW
19709#ifdef ARM_BI_ENDIAN
19710#define OPTION_EB (OPTION_MD_BASE + 0)
19711#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19712#else
c19d1205
ZW
19713#if TARGET_BYTES_BIG_ENDIAN
19714#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19715#else
c19d1205
ZW
19716#define OPTION_EL (OPTION_MD_BASE + 1)
19717#endif
b99bd4ef 19718#endif
b99bd4ef 19719
c19d1205 19720struct option md_longopts[] =
b99bd4ef 19721{
c19d1205
ZW
19722#ifdef OPTION_EB
19723 {"EB", no_argument, NULL, OPTION_EB},
19724#endif
19725#ifdef OPTION_EL
19726 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19727#endif
c19d1205
ZW
19728 {NULL, no_argument, NULL, 0}
19729};
b99bd4ef 19730
c19d1205 19731size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19732
c19d1205 19733struct arm_option_table
b99bd4ef 19734{
c19d1205
ZW
19735 char *option; /* Option name to match. */
19736 char *help; /* Help information. */
19737 int *var; /* Variable to change. */
19738 int value; /* What to change it to. */
19739 char *deprecated; /* If non-null, print this message. */
19740};
b99bd4ef 19741
c19d1205
ZW
19742struct arm_option_table arm_opts[] =
19743{
19744 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19745 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19746 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19747 &support_interwork, 1, NULL},
19748 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19749 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19750 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19751 1, NULL},
19752 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19753 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19754 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19755 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19756 NULL},
b99bd4ef 19757
c19d1205
ZW
19758 /* These are recognized by the assembler, but have no affect on code. */
19759 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19760 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19761 {NULL, NULL, NULL, 0, NULL}
19762};
19763
19764struct arm_legacy_option_table
19765{
19766 char *option; /* Option name to match. */
19767 const arm_feature_set **var; /* Variable to change. */
19768 const arm_feature_set value; /* What to change it to. */
19769 char *deprecated; /* If non-null, print this message. */
19770};
b99bd4ef 19771
e74cfd16
PB
19772const struct arm_legacy_option_table arm_legacy_opts[] =
19773{
c19d1205
ZW
19774 /* DON'T add any new processors to this list -- we want the whole list
19775 to go away... Add them to the processors table instead. */
e74cfd16
PB
19776 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19777 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19778 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19779 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19780 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19781 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19782 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19783 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19784 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19785 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19786 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19787 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19788 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19789 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19790 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19791 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19792 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19793 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19794 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19795 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19796 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19797 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19798 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19799 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19800 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19801 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19802 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19803 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19804 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19805 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19806 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19807 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19808 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19809 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19810 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19811 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19812 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19813 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19814 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19815 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19816 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19817 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19818 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19819 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19820 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19821 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19822 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19823 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19824 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19825 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19826 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19827 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19828 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19829 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19830 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19831 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19832 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19833 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19834 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19835 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19836 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19837 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19838 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19839 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19840 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19841 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19842 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19843 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19844 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19845 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19846 N_("use -mcpu=strongarm110")},
e74cfd16 19847 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19848 N_("use -mcpu=strongarm1100")},
e74cfd16 19849 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19850 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19851 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19852 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19853 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19854
c19d1205 19855 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19856 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19857 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19858 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19859 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19860 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19861 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19862 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19863 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19864 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19865 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19866 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19867 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19868 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19869 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19870 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19871 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19872 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19873 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 19874
c19d1205 19875 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
19876 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19877 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19878 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19879 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 19880 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 19881
e74cfd16 19882 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 19883};
7ed4c4c5 19884
c19d1205 19885struct arm_cpu_option_table
7ed4c4c5 19886{
c19d1205 19887 char *name;
e74cfd16 19888 const arm_feature_set value;
c19d1205
ZW
19889 /* For some CPUs we assume an FPU unless the user explicitly sets
19890 -mfpu=... */
e74cfd16 19891 const arm_feature_set default_fpu;
ee065d83
PB
19892 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19893 case. */
19894 const char *canonical_name;
c19d1205 19895};
7ed4c4c5 19896
c19d1205
ZW
19897/* This list should, at a minimum, contain all the cpu names
19898 recognized by GCC. */
e74cfd16 19899static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 19900{
ee065d83
PB
19901 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19902 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19903 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19904 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19905 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19906 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19907 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19908 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19909 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19910 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19911 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19912 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19913 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19914 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19915 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19916 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19917 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19918 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19919 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19920 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19921 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19922 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19923 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19924 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19925 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19926 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19927 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19928 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19929 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19930 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19931 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19932 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19933 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19934 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19935 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19936 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19937 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19938 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19939 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19940 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
19941 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19942 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19943 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19944 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
19945 /* For V5 or later processors we default to using VFP; but the user
19946 should really set the FPU type explicitly. */
ee065d83
PB
19947 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19948 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19949 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19950 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19951 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19952 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19953 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
19954 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19955 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19956 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
19957 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19958 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19959 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19960 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19961 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19962 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
19963 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19964 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19965 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19966 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
19967 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19968 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
19969 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
19970 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
19971 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
19972 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
19973 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
19974 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
19975 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
19976 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
19977 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
19978 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
19979 | FPU_NEON_EXT_V1),
19980 NULL},
62b3e311
PB
19981 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
19982 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 19983 /* ??? XSCALE is really an architecture. */
ee065d83 19984 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 19985 /* ??? iwmmxt is not a processor. */
ee065d83 19986 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 19987 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 19988 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 19989 /* Maverick */
e74cfd16
PB
19990 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
19991 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 19992};
7ed4c4c5 19993
c19d1205 19994struct arm_arch_option_table
7ed4c4c5 19995{
c19d1205 19996 char *name;
e74cfd16
PB
19997 const arm_feature_set value;
19998 const arm_feature_set default_fpu;
c19d1205 19999};
7ed4c4c5 20000
c19d1205
ZW
20001/* This list should, at a minimum, contain all the architecture names
20002 recognized by GCC. */
e74cfd16 20003static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20004{
20005 {"all", ARM_ANY, FPU_ARCH_FPA},
20006 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20007 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20008 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20009 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20010 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20011 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20012 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20013 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20014 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20015 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20016 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20017 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20018 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20019 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20020 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20021 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20022 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20023 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20024 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20025 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20026 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20027 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20028 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20029 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20030 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311 20031 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20032 /* The official spelling of the ARMv7 profile variants is the dashed form.
20033 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20034 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20035 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20036 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20037 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20038 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20039 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20040 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20041 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20042 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20043 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20044};
7ed4c4c5 20045
c19d1205 20046/* ISA extensions in the co-processor space. */
e74cfd16 20047struct arm_option_cpu_value_table
c19d1205
ZW
20048{
20049 char *name;
e74cfd16 20050 const arm_feature_set value;
c19d1205 20051};
7ed4c4c5 20052
e74cfd16 20053static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20054{
e74cfd16
PB
20055 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20056 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20057 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20058 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20059 {NULL, ARM_ARCH_NONE}
c19d1205 20060};
7ed4c4c5 20061
c19d1205
ZW
20062/* This list should, at a minimum, contain all the fpu names
20063 recognized by GCC. */
e74cfd16 20064static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20065{
20066 {"softfpa", FPU_NONE},
20067 {"fpe", FPU_ARCH_FPE},
20068 {"fpe2", FPU_ARCH_FPE},
20069 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20070 {"fpa", FPU_ARCH_FPA},
20071 {"fpa10", FPU_ARCH_FPA},
20072 {"fpa11", FPU_ARCH_FPA},
20073 {"arm7500fe", FPU_ARCH_FPA},
20074 {"softvfp", FPU_ARCH_VFP},
20075 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20076 {"vfp", FPU_ARCH_VFP_V2},
20077 {"vfp9", FPU_ARCH_VFP_V2},
5287ad62 20078 {"vfp3", FPU_ARCH_VFP_V3},
c19d1205
ZW
20079 {"vfp10", FPU_ARCH_VFP_V2},
20080 {"vfp10-r0", FPU_ARCH_VFP_V1},
20081 {"vfpxd", FPU_ARCH_VFP_V1xD},
20082 {"arm1020t", FPU_ARCH_VFP_V1},
20083 {"arm1020e", FPU_ARCH_VFP_V2},
20084 {"arm1136jfs", FPU_ARCH_VFP_V2},
20085 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20086 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20087 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20088 {NULL, ARM_ARCH_NONE}
20089};
20090
20091struct arm_option_value_table
20092{
20093 char *name;
20094 long value;
c19d1205 20095};
7ed4c4c5 20096
e74cfd16 20097static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20098{
20099 {"hard", ARM_FLOAT_ABI_HARD},
20100 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20101 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20102 {NULL, 0}
c19d1205 20103};
7ed4c4c5 20104
c19d1205 20105#ifdef OBJ_ELF
3a4a14e9 20106/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20107static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20108{
20109 {"gnu", EF_ARM_EABI_UNKNOWN},
20110 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20111 {"5", EF_ARM_EABI_VER5},
e74cfd16 20112 {NULL, 0}
c19d1205
ZW
20113};
20114#endif
7ed4c4c5 20115
c19d1205
ZW
20116struct arm_long_option_table
20117{
20118 char * option; /* Substring to match. */
20119 char * help; /* Help information. */
20120 int (* func) (char * subopt); /* Function to decode sub-option. */
20121 char * deprecated; /* If non-null, print this message. */
20122};
7ed4c4c5
NC
20123
20124static int
e74cfd16 20125arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20126{
e74cfd16
PB
20127 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20128
20129 /* Copy the feature set, so that we can modify it. */
20130 *ext_set = **opt_p;
20131 *opt_p = ext_set;
20132
c19d1205 20133 while (str != NULL && *str != 0)
7ed4c4c5 20134 {
e74cfd16 20135 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20136 char * ext;
20137 int optlen;
7ed4c4c5 20138
c19d1205
ZW
20139 if (*str != '+')
20140 {
20141 as_bad (_("invalid architectural extension"));
20142 return 0;
20143 }
7ed4c4c5 20144
c19d1205
ZW
20145 str++;
20146 ext = strchr (str, '+');
7ed4c4c5 20147
c19d1205
ZW
20148 if (ext != NULL)
20149 optlen = ext - str;
20150 else
20151 optlen = strlen (str);
7ed4c4c5 20152
c19d1205
ZW
20153 if (optlen == 0)
20154 {
20155 as_bad (_("missing architectural extension"));
20156 return 0;
20157 }
7ed4c4c5 20158
c19d1205
ZW
20159 for (opt = arm_extensions; opt->name != NULL; opt++)
20160 if (strncmp (opt->name, str, optlen) == 0)
20161 {
e74cfd16 20162 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20163 break;
20164 }
7ed4c4c5 20165
c19d1205
ZW
20166 if (opt->name == NULL)
20167 {
20168 as_bad (_("unknown architectural extnsion `%s'"), str);
20169 return 0;
20170 }
7ed4c4c5 20171
c19d1205
ZW
20172 str = ext;
20173 };
7ed4c4c5 20174
c19d1205
ZW
20175 return 1;
20176}
7ed4c4c5 20177
c19d1205
ZW
20178static int
20179arm_parse_cpu (char * str)
7ed4c4c5 20180{
e74cfd16 20181 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20182 char * ext = strchr (str, '+');
20183 int optlen;
7ed4c4c5 20184
c19d1205
ZW
20185 if (ext != NULL)
20186 optlen = ext - str;
7ed4c4c5 20187 else
c19d1205 20188 optlen = strlen (str);
7ed4c4c5 20189
c19d1205 20190 if (optlen == 0)
7ed4c4c5 20191 {
c19d1205
ZW
20192 as_bad (_("missing cpu name `%s'"), str);
20193 return 0;
7ed4c4c5
NC
20194 }
20195
c19d1205
ZW
20196 for (opt = arm_cpus; opt->name != NULL; opt++)
20197 if (strncmp (opt->name, str, optlen) == 0)
20198 {
e74cfd16
PB
20199 mcpu_cpu_opt = &opt->value;
20200 mcpu_fpu_opt = &opt->default_fpu;
ee065d83
PB
20201 if (opt->canonical_name)
20202 strcpy(selected_cpu_name, opt->canonical_name);
20203 else
20204 {
20205 int i;
20206 for (i = 0; i < optlen; i++)
20207 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20208 selected_cpu_name[i] = 0;
20209 }
7ed4c4c5 20210
c19d1205
ZW
20211 if (ext != NULL)
20212 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20213
c19d1205
ZW
20214 return 1;
20215 }
7ed4c4c5 20216
c19d1205
ZW
20217 as_bad (_("unknown cpu `%s'"), str);
20218 return 0;
7ed4c4c5
NC
20219}
20220
c19d1205
ZW
20221static int
20222arm_parse_arch (char * str)
7ed4c4c5 20223{
e74cfd16 20224 const struct arm_arch_option_table *opt;
c19d1205
ZW
20225 char *ext = strchr (str, '+');
20226 int optlen;
7ed4c4c5 20227
c19d1205
ZW
20228 if (ext != NULL)
20229 optlen = ext - str;
7ed4c4c5 20230 else
c19d1205 20231 optlen = strlen (str);
7ed4c4c5 20232
c19d1205 20233 if (optlen == 0)
7ed4c4c5 20234 {
c19d1205
ZW
20235 as_bad (_("missing architecture name `%s'"), str);
20236 return 0;
7ed4c4c5
NC
20237 }
20238
c19d1205
ZW
20239 for (opt = arm_archs; opt->name != NULL; opt++)
20240 if (streq (opt->name, str))
20241 {
e74cfd16
PB
20242 march_cpu_opt = &opt->value;
20243 march_fpu_opt = &opt->default_fpu;
ee065d83 20244 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 20245
c19d1205
ZW
20246 if (ext != NULL)
20247 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20248
c19d1205
ZW
20249 return 1;
20250 }
20251
20252 as_bad (_("unknown architecture `%s'\n"), str);
20253 return 0;
7ed4c4c5 20254}
eb043451 20255
c19d1205
ZW
20256static int
20257arm_parse_fpu (char * str)
20258{
e74cfd16 20259 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20260
c19d1205
ZW
20261 for (opt = arm_fpus; opt->name != NULL; opt++)
20262 if (streq (opt->name, str))
20263 {
e74cfd16 20264 mfpu_opt = &opt->value;
c19d1205
ZW
20265 return 1;
20266 }
b99bd4ef 20267
c19d1205
ZW
20268 as_bad (_("unknown floating point format `%s'\n"), str);
20269 return 0;
20270}
20271
20272static int
20273arm_parse_float_abi (char * str)
b99bd4ef 20274{
e74cfd16 20275 const struct arm_option_value_table * opt;
b99bd4ef 20276
c19d1205
ZW
20277 for (opt = arm_float_abis; opt->name != NULL; opt++)
20278 if (streq (opt->name, str))
20279 {
20280 mfloat_abi_opt = opt->value;
20281 return 1;
20282 }
cc8a6dd0 20283
c19d1205
ZW
20284 as_bad (_("unknown floating point abi `%s'\n"), str);
20285 return 0;
20286}
b99bd4ef 20287
c19d1205
ZW
20288#ifdef OBJ_ELF
20289static int
20290arm_parse_eabi (char * str)
20291{
e74cfd16 20292 const struct arm_option_value_table *opt;
cc8a6dd0 20293
c19d1205
ZW
20294 for (opt = arm_eabis; opt->name != NULL; opt++)
20295 if (streq (opt->name, str))
20296 {
20297 meabi_flags = opt->value;
20298 return 1;
20299 }
20300 as_bad (_("unknown EABI `%s'\n"), str);
20301 return 0;
20302}
20303#endif
cc8a6dd0 20304
c19d1205
ZW
20305struct arm_long_option_table arm_long_opts[] =
20306{
20307 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20308 arm_parse_cpu, NULL},
20309 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20310 arm_parse_arch, NULL},
20311 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20312 arm_parse_fpu, NULL},
20313 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20314 arm_parse_float_abi, NULL},
20315#ifdef OBJ_ELF
20316 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20317 arm_parse_eabi, NULL},
20318#endif
20319 {NULL, NULL, 0, NULL}
20320};
cc8a6dd0 20321
c19d1205
ZW
20322int
20323md_parse_option (int c, char * arg)
20324{
20325 struct arm_option_table *opt;
e74cfd16 20326 const struct arm_legacy_option_table *fopt;
c19d1205 20327 struct arm_long_option_table *lopt;
b99bd4ef 20328
c19d1205 20329 switch (c)
b99bd4ef 20330 {
c19d1205
ZW
20331#ifdef OPTION_EB
20332 case OPTION_EB:
20333 target_big_endian = 1;
20334 break;
20335#endif
cc8a6dd0 20336
c19d1205
ZW
20337#ifdef OPTION_EL
20338 case OPTION_EL:
20339 target_big_endian = 0;
20340 break;
20341#endif
b99bd4ef 20342
c19d1205
ZW
20343 case 'a':
20344 /* Listing option. Just ignore these, we don't support additional
20345 ones. */
20346 return 0;
b99bd4ef 20347
c19d1205
ZW
20348 default:
20349 for (opt = arm_opts; opt->option != NULL; opt++)
20350 {
20351 if (c == opt->option[0]
20352 && ((arg == NULL && opt->option[1] == 0)
20353 || streq (arg, opt->option + 1)))
20354 {
20355#if WARN_DEPRECATED
20356 /* If the option is deprecated, tell the user. */
20357 if (opt->deprecated != NULL)
20358 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20359 arg ? arg : "", _(opt->deprecated));
20360#endif
b99bd4ef 20361
c19d1205
ZW
20362 if (opt->var != NULL)
20363 *opt->var = opt->value;
cc8a6dd0 20364
c19d1205
ZW
20365 return 1;
20366 }
20367 }
b99bd4ef 20368
e74cfd16
PB
20369 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20370 {
20371 if (c == fopt->option[0]
20372 && ((arg == NULL && fopt->option[1] == 0)
20373 || streq (arg, fopt->option + 1)))
20374 {
20375#if WARN_DEPRECATED
20376 /* If the option is deprecated, tell the user. */
20377 if (fopt->deprecated != NULL)
20378 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20379 arg ? arg : "", _(fopt->deprecated));
20380#endif
20381
20382 if (fopt->var != NULL)
20383 *fopt->var = &fopt->value;
20384
20385 return 1;
20386 }
20387 }
20388
c19d1205
ZW
20389 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20390 {
20391 /* These options are expected to have an argument. */
20392 if (c == lopt->option[0]
20393 && arg != NULL
20394 && strncmp (arg, lopt->option + 1,
20395 strlen (lopt->option + 1)) == 0)
20396 {
20397#if WARN_DEPRECATED
20398 /* If the option is deprecated, tell the user. */
20399 if (lopt->deprecated != NULL)
20400 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20401 _(lopt->deprecated));
20402#endif
b99bd4ef 20403
c19d1205
ZW
20404 /* Call the sup-option parser. */
20405 return lopt->func (arg + strlen (lopt->option) - 1);
20406 }
20407 }
a737bd4d 20408
c19d1205
ZW
20409 return 0;
20410 }
a394c00f 20411
c19d1205
ZW
20412 return 1;
20413}
a394c00f 20414
c19d1205
ZW
20415void
20416md_show_usage (FILE * fp)
a394c00f 20417{
c19d1205
ZW
20418 struct arm_option_table *opt;
20419 struct arm_long_option_table *lopt;
a394c00f 20420
c19d1205 20421 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20422
c19d1205
ZW
20423 for (opt = arm_opts; opt->option != NULL; opt++)
20424 if (opt->help != NULL)
20425 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20426
c19d1205
ZW
20427 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20428 if (lopt->help != NULL)
20429 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20430
c19d1205
ZW
20431#ifdef OPTION_EB
20432 fprintf (fp, _("\
20433 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20434#endif
20435
c19d1205
ZW
20436#ifdef OPTION_EL
20437 fprintf (fp, _("\
20438 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20439#endif
c19d1205 20440}
ee065d83
PB
20441
20442
20443#ifdef OBJ_ELF
62b3e311
PB
20444typedef struct
20445{
20446 int val;
20447 arm_feature_set flags;
20448} cpu_arch_ver_table;
20449
20450/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20451 least features first. */
20452static const cpu_arch_ver_table cpu_arch_ver[] =
20453{
20454 {1, ARM_ARCH_V4},
20455 {2, ARM_ARCH_V4T},
20456 {3, ARM_ARCH_V5},
20457 {4, ARM_ARCH_V5TE},
20458 {5, ARM_ARCH_V5TEJ},
20459 {6, ARM_ARCH_V6},
20460 {7, ARM_ARCH_V6Z},
20461 {8, ARM_ARCH_V6K},
20462 {9, ARM_ARCH_V6T2},
20463 {10, ARM_ARCH_V7A},
20464 {10, ARM_ARCH_V7R},
20465 {10, ARM_ARCH_V7M},
20466 {0, ARM_ARCH_NONE}
20467};
20468
ee065d83
PB
20469/* Set the public EABI object attributes. */
20470static void
20471aeabi_set_public_attributes (void)
20472{
20473 int arch;
e74cfd16 20474 arm_feature_set flags;
62b3e311
PB
20475 arm_feature_set tmp;
20476 const cpu_arch_ver_table *p;
ee065d83
PB
20477
20478 /* Choose the architecture based on the capabilities of the requested cpu
20479 (if any) and/or the instructions actually used. */
e74cfd16
PB
20480 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20481 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20482 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20483 /*Allow the user to override the reported architecture. */
20484 if (object_arch)
20485 {
20486 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20487 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20488 }
20489
62b3e311
PB
20490 tmp = flags;
20491 arch = 0;
20492 for (p = cpu_arch_ver; p->val; p++)
20493 {
20494 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20495 {
20496 arch = p->val;
20497 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20498 }
20499 }
ee065d83
PB
20500
20501 /* Tag_CPU_name. */
20502 if (selected_cpu_name[0])
20503 {
20504 char *p;
20505
20506 p = selected_cpu_name;
20507 if (strncmp(p, "armv", 4) == 0)
20508 {
20509 int i;
20510
20511 p += 4;
20512 for (i = 0; p[i]; i++)
20513 p[i] = TOUPPER (p[i]);
20514 }
20515 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
20516 }
20517 /* Tag_CPU_arch. */
20518 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
62b3e311
PB
20519 /* Tag_CPU_arch_profile. */
20520 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20521 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
20522 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20523 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
20524 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20525 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
ee065d83 20526 /* Tag_ARM_ISA_use. */
e74cfd16 20527 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
ee065d83
PB
20528 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
20529 /* Tag_THUMB_ISA_use. */
e74cfd16 20530 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
ee065d83 20531 elf32_arm_add_eabi_attr_int (stdoutput, 9,
e74cfd16 20532 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20533 /* Tag_VFP_arch. */
5287ad62
JB
20534 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20535 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20536 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
20537 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20538 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
ee065d83 20539 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
5287ad62
JB
20540 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20541 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20542 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20543 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
ee065d83
PB
20544 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
20545 /* Tag_WMMX_arch. */
e74cfd16
PB
20546 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20547 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
ee065d83 20548 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
5287ad62
JB
20549 /* Tag_NEON_arch. */
20550 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20551 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20552 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
ee065d83
PB
20553}
20554
20555/* Add the .ARM.attributes section. */
20556void
20557arm_md_end (void)
20558{
20559 segT s;
20560 char *p;
20561 addressT addr;
20562 offsetT size;
20563
20564 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20565 return;
20566
20567 aeabi_set_public_attributes ();
20568 size = elf32_arm_eabi_attr_size (stdoutput);
20569 s = subseg_new (".ARM.attributes", 0);
20570 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
20571 addr = frag_now_fix ();
20572 p = frag_more (size);
20573 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
20574}
8463be01 20575#endif /* OBJ_ELF */
ee065d83
PB
20576
20577
20578/* Parse a .cpu directive. */
20579
20580static void
20581s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20582{
e74cfd16 20583 const struct arm_cpu_option_table *opt;
ee065d83
PB
20584 char *name;
20585 char saved_char;
20586
20587 name = input_line_pointer;
20588 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20589 input_line_pointer++;
20590 saved_char = *input_line_pointer;
20591 *input_line_pointer = 0;
20592
20593 /* Skip the first "all" entry. */
20594 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20595 if (streq (opt->name, name))
20596 {
e74cfd16
PB
20597 mcpu_cpu_opt = &opt->value;
20598 selected_cpu = opt->value;
ee065d83
PB
20599 if (opt->canonical_name)
20600 strcpy(selected_cpu_name, opt->canonical_name);
20601 else
20602 {
20603 int i;
20604 for (i = 0; opt->name[i]; i++)
20605 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20606 selected_cpu_name[i] = 0;
20607 }
e74cfd16 20608 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20609 *input_line_pointer = saved_char;
20610 demand_empty_rest_of_line ();
20611 return;
20612 }
20613 as_bad (_("unknown cpu `%s'"), name);
20614 *input_line_pointer = saved_char;
20615 ignore_rest_of_line ();
20616}
20617
20618
20619/* Parse a .arch directive. */
20620
20621static void
20622s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20623{
e74cfd16 20624 const struct arm_arch_option_table *opt;
ee065d83
PB
20625 char saved_char;
20626 char *name;
20627
20628 name = input_line_pointer;
20629 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20630 input_line_pointer++;
20631 saved_char = *input_line_pointer;
20632 *input_line_pointer = 0;
20633
20634 /* Skip the first "all" entry. */
20635 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20636 if (streq (opt->name, name))
20637 {
e74cfd16
PB
20638 mcpu_cpu_opt = &opt->value;
20639 selected_cpu = opt->value;
ee065d83 20640 strcpy(selected_cpu_name, opt->name);
e74cfd16 20641 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20642 *input_line_pointer = saved_char;
20643 demand_empty_rest_of_line ();
20644 return;
20645 }
20646
20647 as_bad (_("unknown architecture `%s'\n"), name);
20648 *input_line_pointer = saved_char;
20649 ignore_rest_of_line ();
20650}
20651
20652
7a1d4c38
PB
20653/* Parse a .object_arch directive. */
20654
20655static void
20656s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20657{
20658 const struct arm_arch_option_table *opt;
20659 char saved_char;
20660 char *name;
20661
20662 name = input_line_pointer;
20663 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20664 input_line_pointer++;
20665 saved_char = *input_line_pointer;
20666 *input_line_pointer = 0;
20667
20668 /* Skip the first "all" entry. */
20669 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20670 if (streq (opt->name, name))
20671 {
20672 object_arch = &opt->value;
20673 *input_line_pointer = saved_char;
20674 demand_empty_rest_of_line ();
20675 return;
20676 }
20677
20678 as_bad (_("unknown architecture `%s'\n"), name);
20679 *input_line_pointer = saved_char;
20680 ignore_rest_of_line ();
20681}
20682
20683
ee065d83
PB
20684/* Parse a .fpu directive. */
20685
20686static void
20687s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20688{
e74cfd16 20689 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20690 char saved_char;
20691 char *name;
20692
20693 name = input_line_pointer;
20694 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20695 input_line_pointer++;
20696 saved_char = *input_line_pointer;
20697 *input_line_pointer = 0;
20698
20699 for (opt = arm_fpus; opt->name != NULL; opt++)
20700 if (streq (opt->name, name))
20701 {
e74cfd16
PB
20702 mfpu_opt = &opt->value;
20703 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20704 *input_line_pointer = saved_char;
20705 demand_empty_rest_of_line ();
20706 return;
20707 }
20708
20709 as_bad (_("unknown floating point format `%s'\n"), name);
20710 *input_line_pointer = saved_char;
20711 ignore_rest_of_line ();
20712}
ee065d83 20713
794ba86a
DJ
20714/* Copy symbol information. */
20715void
20716arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20717{
20718 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20719}
This page took 1.738642 seconds and 4 git commands to generate.