*** empty log message ***
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
ec2655a6 3 2004, 2005, 2006, 2007
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
5287ad62 28#include <limits.h>
037e8744 29#include <stdarg.h>
c19d1205 30#define NO_RELOC 0
b99bd4ef 31#include "as.h"
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
720abc60 45#define WARN_DEPRECATED 1
03b1477f 46
7ed4c4c5
NC
47#ifdef OBJ_ELF
48/* Must be at least the size of the largest unwind opcode (currently two). */
49#define ARM_OPCODE_CHUNK_SIZE 8
50
51/* This structure holds the unwinding state. */
52
53static struct
54{
c19d1205
ZW
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
7ed4c4c5 59 /* The segment containing the function. */
c19d1205
ZW
60 segT saved_seg;
61 subsegT saved_subseg;
7ed4c4c5
NC
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
c19d1205
ZW
64 int opcode_count;
65 int opcode_alloc;
7ed4c4c5 66 /* The number of bytes pushed to the stack. */
c19d1205 67 offsetT frame_size;
7ed4c4c5
NC
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
c19d1205 71 offsetT pending_offset;
7ed4c4c5 72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
7ed4c4c5 76 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 77 unsigned fp_used:1;
7ed4c4c5 78 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 79 unsigned sp_restored:1;
7ed4c4c5
NC
80} unwind;
81
8b1ad454
NC
82/* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85static unsigned int marked_pr_dependency = 0;
86
87#endif /* OBJ_ELF */
88
4962c51a
MS
89/* Results from operand parsing worker functions. */
90
91typedef enum
92{
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96} parse_operand_result;
97
33a392fb
PB
98enum arm_float_abi
99{
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103};
104
c19d1205 105/* Types of processor to assemble for. */
b99bd4ef
NC
106#ifndef CPU_DEFAULT
107#if defined __XSCALE__
e74cfd16 108#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
109#else
110#if defined __thumb__
e74cfd16 111#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
112#endif
113#endif
114#endif
115
116#ifndef FPU_DEFAULT
c820d418
MM
117# ifdef TE_LINUX
118# define FPU_DEFAULT FPU_ARCH_FPA
119# elif defined (TE_NetBSD)
120# ifdef OBJ_ELF
121# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122# else
123 /* Legacy a.out format. */
124# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125# endif
4e7fd91e
PB
126# elif defined (TE_VXWORKS)
127# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
128# else
129 /* For backwards compatibility, default to FPA. */
130# define FPU_DEFAULT FPU_ARCH_FPA
131# endif
132#endif /* ifndef FPU_DEFAULT */
b99bd4ef 133
c19d1205 134#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 135
e74cfd16
PB
136static arm_feature_set cpu_variant;
137static arm_feature_set arm_arch_used;
138static arm_feature_set thumb_arch_used;
b99bd4ef 139
b99bd4ef 140/* Flags stored in private area of BFD structure. */
c19d1205
ZW
141static int uses_apcs_26 = FALSE;
142static int atpcs = FALSE;
b34976b6
AM
143static int support_interwork = FALSE;
144static int uses_apcs_float = FALSE;
c19d1205 145static int pic_code = FALSE;
845b51d6 146static int fix_v4bx = FALSE;
03b1477f
RE
147
148/* Variables that we set while parsing command-line options. Once all
149 options have been read we re-process these values to set the real
150 assembly flags. */
e74cfd16
PB
151static const arm_feature_set *legacy_cpu = NULL;
152static const arm_feature_set *legacy_fpu = NULL;
153
154static const arm_feature_set *mcpu_cpu_opt = NULL;
155static const arm_feature_set *mcpu_fpu_opt = NULL;
156static const arm_feature_set *march_cpu_opt = NULL;
157static const arm_feature_set *march_fpu_opt = NULL;
158static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 159static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
160
161/* Constants for known architecture features. */
162static const arm_feature_set fpu_default = FPU_DEFAULT;
163static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
164static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
165static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
166static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
167static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
168static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
169static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
170static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
171
172#ifdef CPU_DEFAULT
173static const arm_feature_set cpu_default = CPU_DEFAULT;
174#endif
175
176static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
177static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
178static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
179static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
180static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
181static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
182static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
183static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
184static const arm_feature_set arm_ext_v4t_5 =
185 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
186static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
187static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
188static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
189static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
190static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
191static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
192static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
193static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 194static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
7e806470
PB
195static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
196static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
197static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
198static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
199static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
200static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
7e806470
PB
201static const arm_feature_set arm_ext_m =
202 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
203
204static const arm_feature_set arm_arch_any = ARM_ANY;
205static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
206static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
207static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
208
2d447fca
JM
209static const arm_feature_set arm_cext_iwmmxt2 =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
211static const arm_feature_set arm_cext_iwmmxt =
212 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
213static const arm_feature_set arm_cext_xscale =
214 ARM_FEATURE (0, ARM_CEXT_XSCALE);
215static const arm_feature_set arm_cext_maverick =
216 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
217static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
218static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
219static const arm_feature_set fpu_vfp_ext_v1xd =
220 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
221static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
222static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62
JB
223static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
224static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
225static const arm_feature_set fpu_vfp_v3_or_neon_ext =
226 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
e74cfd16 227
33a392fb 228static int mfloat_abi_opt = -1;
e74cfd16
PB
229/* Record user cpu selection for object attributes. */
230static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
231/* Must be long enough to hold any of the names in arm_cpus. */
232static char selected_cpu_name[16];
7cc69913 233#ifdef OBJ_ELF
deeaaff8
DJ
234# ifdef EABI_DEFAULT
235static int meabi_flags = EABI_DEFAULT;
236# else
d507cf36 237static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 238# endif
e1da3f5b
PB
239
240bfd_boolean
5f4273c7 241arm_is_eabi (void)
e1da3f5b
PB
242{
243 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
244}
7cc69913 245#endif
b99bd4ef 246
b99bd4ef 247#ifdef OBJ_ELF
c19d1205 248/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
249symbolS * GOT_symbol;
250#endif
251
b99bd4ef
NC
252/* 0: assemble for ARM,
253 1: assemble for Thumb,
254 2: assemble for Thumb even though target CPU does not support thumb
255 instructions. */
256static int thumb_mode = 0;
257
c19d1205
ZW
258/* If unified_syntax is true, we are processing the new unified
259 ARM/Thumb syntax. Important differences from the old ARM mode:
260
261 - Immediate operands do not require a # prefix.
262 - Conditional affixes always appear at the end of the
263 instruction. (For backward compatibility, those instructions
264 that formerly had them in the middle, continue to accept them
265 there.)
266 - The IT instruction may appear, and if it does is validated
267 against subsequent conditional affixes. It does not generate
268 machine code.
269
270 Important differences from the old Thumb mode:
271
272 - Immediate operands do not require a # prefix.
273 - Most of the V6T2 instructions are only available in unified mode.
274 - The .N and .W suffixes are recognized and honored (it is an error
275 if they cannot be honored).
276 - All instructions set the flags if and only if they have an 's' affix.
277 - Conditional affixes may be used. They are validated against
278 preceding IT instructions. Unlike ARM mode, you cannot use a
279 conditional affix except in the scope of an IT instruction. */
280
281static bfd_boolean unified_syntax = FALSE;
b99bd4ef 282
5287ad62
JB
283enum neon_el_type
284{
dcbf9037 285 NT_invtype,
5287ad62
JB
286 NT_untyped,
287 NT_integer,
288 NT_float,
289 NT_poly,
290 NT_signed,
dcbf9037 291 NT_unsigned
5287ad62
JB
292};
293
294struct neon_type_el
295{
296 enum neon_el_type type;
297 unsigned size;
298};
299
300#define NEON_MAX_TYPE_ELS 4
301
302struct neon_type
303{
304 struct neon_type_el el[NEON_MAX_TYPE_ELS];
305 unsigned elems;
306};
307
b99bd4ef
NC
308struct arm_it
309{
c19d1205 310 const char * error;
b99bd4ef 311 unsigned long instruction;
c19d1205
ZW
312 int size;
313 int size_req;
314 int cond;
037e8744
JB
315 /* "uncond_value" is set to the value in place of the conditional field in
316 unconditional versions of the instruction, or -1 if nothing is
317 appropriate. */
318 int uncond_value;
5287ad62 319 struct neon_type vectype;
0110f2b8
PB
320 /* Set to the opcode if the instruction needs relaxation.
321 Zero if the instruction is not relaxed. */
322 unsigned long relax;
b99bd4ef
NC
323 struct
324 {
325 bfd_reloc_code_real_type type;
c19d1205
ZW
326 expressionS exp;
327 int pc_rel;
b99bd4ef 328 } reloc;
b99bd4ef 329
c19d1205
ZW
330 struct
331 {
332 unsigned reg;
ca3f61f7 333 signed int imm;
dcbf9037 334 struct neon_type_el vectype;
ca3f61f7
NC
335 unsigned present : 1; /* Operand present. */
336 unsigned isreg : 1; /* Operand was a register. */
337 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
338 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
339 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 340 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
341 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
342 instructions. This allows us to disambiguate ARM <-> vector insns. */
343 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 344 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 345 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 346 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
347 unsigned hasreloc : 1; /* Operand has relocation suffix. */
348 unsigned writeback : 1; /* Operand has trailing ! */
349 unsigned preind : 1; /* Preindexed address. */
350 unsigned postind : 1; /* Postindexed address. */
351 unsigned negative : 1; /* Index register was negated. */
352 unsigned shifted : 1; /* Shift applied to operation. */
353 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 354 } operands[6];
b99bd4ef
NC
355};
356
c19d1205 357static struct arm_it inst;
b99bd4ef
NC
358
359#define NUM_FLOAT_VALS 8
360
05d2d07e 361const char * fp_const[] =
b99bd4ef
NC
362{
363 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
364};
365
c19d1205 366/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
367#define MAX_LITTLENUMS 6
368
369LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
370
371#define FAIL (-1)
372#define SUCCESS (0)
373
374#define SUFF_S 1
375#define SUFF_D 2
376#define SUFF_E 3
377#define SUFF_P 4
378
c19d1205
ZW
379#define CP_T_X 0x00008000
380#define CP_T_Y 0x00400000
b99bd4ef 381
c19d1205
ZW
382#define CONDS_BIT 0x00100000
383#define LOAD_BIT 0x00100000
b99bd4ef
NC
384
385#define DOUBLE_LOAD_FLAG 0x00000001
386
387struct asm_cond
388{
c19d1205 389 const char * template;
b99bd4ef
NC
390 unsigned long value;
391};
392
c19d1205 393#define COND_ALWAYS 0xE
b99bd4ef 394
b99bd4ef
NC
395struct asm_psr
396{
b34976b6 397 const char *template;
b99bd4ef
NC
398 unsigned long field;
399};
400
62b3e311
PB
401struct asm_barrier_opt
402{
403 const char *template;
404 unsigned long value;
405};
406
2d2255b5 407/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
408#define SPSR_BIT (1 << 22)
409
c19d1205
ZW
410/* The individual PSR flag bits. */
411#define PSR_c (1 << 16)
412#define PSR_x (1 << 17)
413#define PSR_s (1 << 18)
414#define PSR_f (1 << 19)
b99bd4ef 415
c19d1205 416struct reloc_entry
bfae80f2 417{
c19d1205
ZW
418 char *name;
419 bfd_reloc_code_real_type reloc;
bfae80f2
RE
420};
421
5287ad62 422enum vfp_reg_pos
bfae80f2 423{
5287ad62
JB
424 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
425 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
426};
427
428enum vfp_ldstm_type
429{
430 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
431};
432
dcbf9037
JB
433/* Bits for DEFINED field in neon_typed_alias. */
434#define NTA_HASTYPE 1
435#define NTA_HASINDEX 2
436
437struct neon_typed_alias
438{
439 unsigned char defined;
440 unsigned char index;
441 struct neon_type_el eltype;
442};
443
c19d1205
ZW
444/* ARM register categories. This includes coprocessor numbers and various
445 architecture extensions' registers. */
446enum arm_reg_type
bfae80f2 447{
c19d1205
ZW
448 REG_TYPE_RN,
449 REG_TYPE_CP,
450 REG_TYPE_CN,
451 REG_TYPE_FN,
452 REG_TYPE_VFS,
453 REG_TYPE_VFD,
5287ad62 454 REG_TYPE_NQ,
037e8744 455 REG_TYPE_VFSD,
5287ad62 456 REG_TYPE_NDQ,
037e8744 457 REG_TYPE_NSDQ,
c19d1205
ZW
458 REG_TYPE_VFC,
459 REG_TYPE_MVF,
460 REG_TYPE_MVD,
461 REG_TYPE_MVFX,
462 REG_TYPE_MVDX,
463 REG_TYPE_MVAX,
464 REG_TYPE_DSPSC,
465 REG_TYPE_MMXWR,
466 REG_TYPE_MMXWC,
467 REG_TYPE_MMXWCG,
468 REG_TYPE_XSCALE,
bfae80f2
RE
469};
470
dcbf9037
JB
471/* Structure for a hash table entry for a register.
472 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
473 information which states whether a vector type or index is specified (for a
474 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
475struct reg_entry
476{
dcbf9037
JB
477 const char *name;
478 unsigned char number;
479 unsigned char type;
480 unsigned char builtin;
481 struct neon_typed_alias *neon;
6c43fab6
RE
482};
483
c19d1205
ZW
484/* Diagnostics used when we don't get a register of the expected type. */
485const char *const reg_expected_msgs[] =
486{
487 N_("ARM register expected"),
488 N_("bad or missing co-processor number"),
489 N_("co-processor register expected"),
490 N_("FPA register expected"),
491 N_("VFP single precision register expected"),
5287ad62
JB
492 N_("VFP/Neon double precision register expected"),
493 N_("Neon quad precision register expected"),
037e8744 494 N_("VFP single or double precision register expected"),
5287ad62 495 N_("Neon double or quad precision register expected"),
037e8744 496 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
497 N_("VFP system register expected"),
498 N_("Maverick MVF register expected"),
499 N_("Maverick MVD register expected"),
500 N_("Maverick MVFX register expected"),
501 N_("Maverick MVDX register expected"),
502 N_("Maverick MVAX register expected"),
503 N_("Maverick DSPSC register expected"),
504 N_("iWMMXt data register expected"),
505 N_("iWMMXt control register expected"),
506 N_("iWMMXt scalar register expected"),
507 N_("XScale accumulator register expected"),
6c43fab6
RE
508};
509
c19d1205
ZW
510/* Some well known registers that we refer to directly elsewhere. */
511#define REG_SP 13
512#define REG_LR 14
513#define REG_PC 15
404ff6b5 514
b99bd4ef
NC
515/* ARM instructions take 4bytes in the object file, Thumb instructions
516 take 2: */
c19d1205 517#define INSN_SIZE 4
b99bd4ef
NC
518
519struct asm_opcode
520{
521 /* Basic string to match. */
c19d1205
ZW
522 const char *template;
523
524 /* Parameters to instruction. */
525 unsigned char operands[8];
526
527 /* Conditional tag - see opcode_lookup. */
528 unsigned int tag : 4;
b99bd4ef
NC
529
530 /* Basic instruction code. */
c19d1205 531 unsigned int avalue : 28;
b99bd4ef 532
c19d1205
ZW
533 /* Thumb-format instruction code. */
534 unsigned int tvalue;
b99bd4ef 535
90e4755a 536 /* Which architecture variant provides this instruction. */
e74cfd16
PB
537 const arm_feature_set *avariant;
538 const arm_feature_set *tvariant;
c19d1205
ZW
539
540 /* Function to call to encode instruction in ARM format. */
541 void (* aencode) (void);
b99bd4ef 542
c19d1205
ZW
543 /* Function to call to encode instruction in Thumb format. */
544 void (* tencode) (void);
b99bd4ef
NC
545};
546
a737bd4d
NC
547/* Defines for various bits that we will want to toggle. */
548#define INST_IMMEDIATE 0x02000000
549#define OFFSET_REG 0x02000000
c19d1205 550#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
551#define SHIFT_BY_REG 0x00000010
552#define PRE_INDEX 0x01000000
553#define INDEX_UP 0x00800000
554#define WRITE_BACK 0x00200000
555#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 556#define CPSI_MMOD 0x00020000
90e4755a 557
a737bd4d
NC
558#define LITERAL_MASK 0xf000f000
559#define OPCODE_MASK 0xfe1fffff
560#define V4_STR_BIT 0x00000020
90e4755a 561
efd81785
PB
562#define T2_SUBS_PC_LR 0xf3de8f00
563
a737bd4d 564#define DATA_OP_SHIFT 21
90e4755a 565
ef8d22e6
PB
566#define T2_OPCODE_MASK 0xfe1fffff
567#define T2_DATA_OP_SHIFT 21
568
a737bd4d
NC
569/* Codes to distinguish the arithmetic instructions. */
570#define OPCODE_AND 0
571#define OPCODE_EOR 1
572#define OPCODE_SUB 2
573#define OPCODE_RSB 3
574#define OPCODE_ADD 4
575#define OPCODE_ADC 5
576#define OPCODE_SBC 6
577#define OPCODE_RSC 7
578#define OPCODE_TST 8
579#define OPCODE_TEQ 9
580#define OPCODE_CMP 10
581#define OPCODE_CMN 11
582#define OPCODE_ORR 12
583#define OPCODE_MOV 13
584#define OPCODE_BIC 14
585#define OPCODE_MVN 15
90e4755a 586
ef8d22e6
PB
587#define T2_OPCODE_AND 0
588#define T2_OPCODE_BIC 1
589#define T2_OPCODE_ORR 2
590#define T2_OPCODE_ORN 3
591#define T2_OPCODE_EOR 4
592#define T2_OPCODE_ADD 8
593#define T2_OPCODE_ADC 10
594#define T2_OPCODE_SBC 11
595#define T2_OPCODE_SUB 13
596#define T2_OPCODE_RSB 14
597
a737bd4d
NC
598#define T_OPCODE_MUL 0x4340
599#define T_OPCODE_TST 0x4200
600#define T_OPCODE_CMN 0x42c0
601#define T_OPCODE_NEG 0x4240
602#define T_OPCODE_MVN 0x43c0
90e4755a 603
a737bd4d
NC
604#define T_OPCODE_ADD_R3 0x1800
605#define T_OPCODE_SUB_R3 0x1a00
606#define T_OPCODE_ADD_HI 0x4400
607#define T_OPCODE_ADD_ST 0xb000
608#define T_OPCODE_SUB_ST 0xb080
609#define T_OPCODE_ADD_SP 0xa800
610#define T_OPCODE_ADD_PC 0xa000
611#define T_OPCODE_ADD_I8 0x3000
612#define T_OPCODE_SUB_I8 0x3800
613#define T_OPCODE_ADD_I3 0x1c00
614#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 615
a737bd4d
NC
616#define T_OPCODE_ASR_R 0x4100
617#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
618#define T_OPCODE_LSR_R 0x40c0
619#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
620#define T_OPCODE_ASR_I 0x1000
621#define T_OPCODE_LSL_I 0x0000
622#define T_OPCODE_LSR_I 0x0800
b99bd4ef 623
a737bd4d
NC
624#define T_OPCODE_MOV_I8 0x2000
625#define T_OPCODE_CMP_I8 0x2800
626#define T_OPCODE_CMP_LR 0x4280
627#define T_OPCODE_MOV_HR 0x4600
628#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 629
a737bd4d
NC
630#define T_OPCODE_LDR_PC 0x4800
631#define T_OPCODE_LDR_SP 0x9800
632#define T_OPCODE_STR_SP 0x9000
633#define T_OPCODE_LDR_IW 0x6800
634#define T_OPCODE_STR_IW 0x6000
635#define T_OPCODE_LDR_IH 0x8800
636#define T_OPCODE_STR_IH 0x8000
637#define T_OPCODE_LDR_IB 0x7800
638#define T_OPCODE_STR_IB 0x7000
639#define T_OPCODE_LDR_RW 0x5800
640#define T_OPCODE_STR_RW 0x5000
641#define T_OPCODE_LDR_RH 0x5a00
642#define T_OPCODE_STR_RH 0x5200
643#define T_OPCODE_LDR_RB 0x5c00
644#define T_OPCODE_STR_RB 0x5400
c9b604bd 645
a737bd4d
NC
646#define T_OPCODE_PUSH 0xb400
647#define T_OPCODE_POP 0xbc00
b99bd4ef 648
2fc8bdac 649#define T_OPCODE_BRANCH 0xe000
b99bd4ef 650
a737bd4d 651#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 652#define THUMB_PP_PC_LR 0x0100
c19d1205 653#define THUMB_LOAD_BIT 0x0800
53365c0d 654#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
655
656#define BAD_ARGS _("bad arguments to instruction")
657#define BAD_PC _("r15 not allowed here")
658#define BAD_COND _("instruction cannot be conditional")
659#define BAD_OVERLAP _("registers may not be the same")
660#define BAD_HIREG _("lo register required")
661#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 662#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
663#define BAD_BRANCH _("branch must be last instruction in IT block")
664#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 665#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
666
667static struct hash_control *arm_ops_hsh;
668static struct hash_control *arm_cond_hsh;
669static struct hash_control *arm_shift_hsh;
670static struct hash_control *arm_psr_hsh;
62b3e311 671static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
672static struct hash_control *arm_reg_hsh;
673static struct hash_control *arm_reloc_hsh;
62b3e311 674static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 675
b99bd4ef
NC
676/* Stuff needed to resolve the label ambiguity
677 As:
678 ...
679 label: <insn>
680 may differ from:
681 ...
682 label:
5f4273c7 683 <insn> */
b99bd4ef
NC
684
685symbolS * last_label_seen;
b34976b6 686static int label_is_thumb_function_name = FALSE;
a737bd4d 687\f
3d0c9500
NC
688/* Literal pool structure. Held on a per-section
689 and per-sub-section basis. */
a737bd4d 690
c19d1205 691#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 692typedef struct literal_pool
b99bd4ef 693{
c19d1205
ZW
694 expressionS literals [MAX_LITERAL_POOL_SIZE];
695 unsigned int next_free_entry;
696 unsigned int id;
697 symbolS * symbol;
698 segT section;
699 subsegT sub_section;
61b5f74b 700 struct literal_pool * next;
3d0c9500 701} literal_pool;
b99bd4ef 702
3d0c9500
NC
703/* Pointer to a linked list of literal pools. */
704literal_pool * list_of_pools = NULL;
e27ec89e
PB
705
706/* State variables for IT block handling. */
707static bfd_boolean current_it_mask = 0;
708static int current_cc;
c19d1205
ZW
709\f
710/* Pure syntax. */
b99bd4ef 711
c19d1205
ZW
712/* This array holds the chars that always start a comment. If the
713 pre-processor is disabled, these aren't very useful. */
714const char comment_chars[] = "@";
3d0c9500 715
c19d1205
ZW
716/* This array holds the chars that only start a comment at the beginning of
717 a line. If the line seems to have the form '# 123 filename'
718 .line and .file directives will appear in the pre-processed output. */
719/* Note that input_file.c hand checks for '#' at the beginning of the
720 first line of the input file. This is because the compiler outputs
721 #NO_APP at the beginning of its output. */
722/* Also note that comments like this one will always work. */
723const char line_comment_chars[] = "#";
3d0c9500 724
c19d1205 725const char line_separator_chars[] = ";";
b99bd4ef 726
c19d1205
ZW
727/* Chars that can be used to separate mant
728 from exp in floating point numbers. */
729const char EXP_CHARS[] = "eE";
3d0c9500 730
c19d1205
ZW
731/* Chars that mean this number is a floating point constant. */
732/* As in 0f12.456 */
733/* or 0d1.2345e12 */
b99bd4ef 734
c19d1205 735const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 736
c19d1205
ZW
737/* Prefix characters that indicate the start of an immediate
738 value. */
739#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 740
c19d1205
ZW
741/* Separator character handling. */
742
743#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
744
745static inline int
746skip_past_char (char ** str, char c)
747{
748 if (**str == c)
749 {
750 (*str)++;
751 return SUCCESS;
3d0c9500 752 }
c19d1205
ZW
753 else
754 return FAIL;
755}
756#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 757
c19d1205
ZW
758/* Arithmetic expressions (possibly involving symbols). */
759
760/* Return TRUE if anything in the expression is a bignum. */
761
762static int
763walk_no_bignums (symbolS * sp)
764{
765 if (symbol_get_value_expression (sp)->X_op == O_big)
766 return 1;
767
768 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 769 {
c19d1205
ZW
770 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
771 || (symbol_get_value_expression (sp)->X_op_symbol
772 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
773 }
774
c19d1205 775 return 0;
3d0c9500
NC
776}
777
c19d1205
ZW
778static int in_my_get_expression = 0;
779
780/* Third argument to my_get_expression. */
781#define GE_NO_PREFIX 0
782#define GE_IMM_PREFIX 1
783#define GE_OPT_PREFIX 2
5287ad62
JB
784/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
785 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
786#define GE_OPT_PREFIX_BIG 3
a737bd4d 787
b99bd4ef 788static int
c19d1205 789my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 790{
c19d1205
ZW
791 char * save_in;
792 segT seg;
b99bd4ef 793
c19d1205
ZW
794 /* In unified syntax, all prefixes are optional. */
795 if (unified_syntax)
5287ad62
JB
796 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
797 : GE_OPT_PREFIX;
b99bd4ef 798
c19d1205 799 switch (prefix_mode)
b99bd4ef 800 {
c19d1205
ZW
801 case GE_NO_PREFIX: break;
802 case GE_IMM_PREFIX:
803 if (!is_immediate_prefix (**str))
804 {
805 inst.error = _("immediate expression requires a # prefix");
806 return FAIL;
807 }
808 (*str)++;
809 break;
810 case GE_OPT_PREFIX:
5287ad62 811 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
812 if (is_immediate_prefix (**str))
813 (*str)++;
814 break;
815 default: abort ();
816 }
b99bd4ef 817
c19d1205 818 memset (ep, 0, sizeof (expressionS));
b99bd4ef 819
c19d1205
ZW
820 save_in = input_line_pointer;
821 input_line_pointer = *str;
822 in_my_get_expression = 1;
823 seg = expression (ep);
824 in_my_get_expression = 0;
825
826 if (ep->X_op == O_illegal)
b99bd4ef 827 {
c19d1205
ZW
828 /* We found a bad expression in md_operand(). */
829 *str = input_line_pointer;
830 input_line_pointer = save_in;
831 if (inst.error == NULL)
832 inst.error = _("bad expression");
833 return 1;
834 }
b99bd4ef 835
c19d1205
ZW
836#ifdef OBJ_AOUT
837 if (seg != absolute_section
838 && seg != text_section
839 && seg != data_section
840 && seg != bss_section
841 && seg != undefined_section)
842 {
843 inst.error = _("bad segment");
844 *str = input_line_pointer;
845 input_line_pointer = save_in;
846 return 1;
b99bd4ef 847 }
c19d1205 848#endif
b99bd4ef 849
c19d1205
ZW
850 /* Get rid of any bignums now, so that we don't generate an error for which
851 we can't establish a line number later on. Big numbers are never valid
852 in instructions, which is where this routine is always called. */
5287ad62
JB
853 if (prefix_mode != GE_OPT_PREFIX_BIG
854 && (ep->X_op == O_big
855 || (ep->X_add_symbol
856 && (walk_no_bignums (ep->X_add_symbol)
857 || (ep->X_op_symbol
858 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
859 {
860 inst.error = _("invalid constant");
861 *str = input_line_pointer;
862 input_line_pointer = save_in;
863 return 1;
864 }
b99bd4ef 865
c19d1205
ZW
866 *str = input_line_pointer;
867 input_line_pointer = save_in;
868 return 0;
b99bd4ef
NC
869}
870
c19d1205
ZW
871/* Turn a string in input_line_pointer into a floating point constant
872 of type TYPE, and store the appropriate bytes in *LITP. The number
873 of LITTLENUMS emitted is stored in *SIZEP. An error message is
874 returned, or NULL on OK.
b99bd4ef 875
c19d1205
ZW
876 Note that fp constants aren't represent in the normal way on the ARM.
877 In big endian mode, things are as expected. However, in little endian
878 mode fp constants are big-endian word-wise, and little-endian byte-wise
879 within the words. For example, (double) 1.1 in big endian mode is
880 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
881 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 882
c19d1205 883 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 884
c19d1205
ZW
885char *
886md_atof (int type, char * litP, int * sizeP)
887{
888 int prec;
889 LITTLENUM_TYPE words[MAX_LITTLENUMS];
890 char *t;
891 int i;
b99bd4ef 892
c19d1205
ZW
893 switch (type)
894 {
895 case 'f':
896 case 'F':
897 case 's':
898 case 'S':
899 prec = 2;
900 break;
b99bd4ef 901
c19d1205
ZW
902 case 'd':
903 case 'D':
904 case 'r':
905 case 'R':
906 prec = 4;
907 break;
b99bd4ef 908
c19d1205
ZW
909 case 'x':
910 case 'X':
499ac353 911 prec = 5;
c19d1205 912 break;
b99bd4ef 913
c19d1205
ZW
914 case 'p':
915 case 'P':
499ac353 916 prec = 5;
c19d1205 917 break;
a737bd4d 918
c19d1205
ZW
919 default:
920 *sizeP = 0;
499ac353 921 return _("Unrecognized or unsupported floating point constant");
c19d1205 922 }
b99bd4ef 923
c19d1205
ZW
924 t = atof_ieee (input_line_pointer, type, words);
925 if (t)
926 input_line_pointer = t;
499ac353 927 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 928
c19d1205
ZW
929 if (target_big_endian)
930 {
931 for (i = 0; i < prec; i++)
932 {
499ac353
NC
933 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
934 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
935 }
936 }
937 else
938 {
e74cfd16 939 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
940 for (i = prec - 1; i >= 0; i--)
941 {
499ac353
NC
942 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
943 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
944 }
945 else
946 /* For a 4 byte float the order of elements in `words' is 1 0.
947 For an 8 byte float the order is 1 0 3 2. */
948 for (i = 0; i < prec; i += 2)
949 {
499ac353
NC
950 md_number_to_chars (litP, (valueT) words[i + 1],
951 sizeof (LITTLENUM_TYPE));
952 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
953 (valueT) words[i], sizeof (LITTLENUM_TYPE));
954 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
955 }
956 }
b99bd4ef 957
499ac353 958 return NULL;
c19d1205 959}
b99bd4ef 960
c19d1205
ZW
961/* We handle all bad expressions here, so that we can report the faulty
962 instruction in the error message. */
963void
964md_operand (expressionS * expr)
965{
966 if (in_my_get_expression)
967 expr->X_op = O_illegal;
b99bd4ef
NC
968}
969
c19d1205 970/* Immediate values. */
b99bd4ef 971
c19d1205
ZW
972/* Generic immediate-value read function for use in directives.
973 Accepts anything that 'expression' can fold to a constant.
974 *val receives the number. */
975#ifdef OBJ_ELF
976static int
977immediate_for_directive (int *val)
b99bd4ef 978{
c19d1205
ZW
979 expressionS exp;
980 exp.X_op = O_illegal;
b99bd4ef 981
c19d1205
ZW
982 if (is_immediate_prefix (*input_line_pointer))
983 {
984 input_line_pointer++;
985 expression (&exp);
986 }
b99bd4ef 987
c19d1205
ZW
988 if (exp.X_op != O_constant)
989 {
990 as_bad (_("expected #constant"));
991 ignore_rest_of_line ();
992 return FAIL;
993 }
994 *val = exp.X_add_number;
995 return SUCCESS;
b99bd4ef 996}
c19d1205 997#endif
b99bd4ef 998
c19d1205 999/* Register parsing. */
b99bd4ef 1000
c19d1205
ZW
1001/* Generic register parser. CCP points to what should be the
1002 beginning of a register name. If it is indeed a valid register
1003 name, advance CCP over it and return the reg_entry structure;
1004 otherwise return NULL. Does not issue diagnostics. */
1005
1006static struct reg_entry *
1007arm_reg_parse_multi (char **ccp)
b99bd4ef 1008{
c19d1205
ZW
1009 char *start = *ccp;
1010 char *p;
1011 struct reg_entry *reg;
b99bd4ef 1012
c19d1205
ZW
1013#ifdef REGISTER_PREFIX
1014 if (*start != REGISTER_PREFIX)
01cfc07f 1015 return NULL;
c19d1205
ZW
1016 start++;
1017#endif
1018#ifdef OPTIONAL_REGISTER_PREFIX
1019 if (*start == OPTIONAL_REGISTER_PREFIX)
1020 start++;
1021#endif
b99bd4ef 1022
c19d1205
ZW
1023 p = start;
1024 if (!ISALPHA (*p) || !is_name_beginner (*p))
1025 return NULL;
b99bd4ef 1026
c19d1205
ZW
1027 do
1028 p++;
1029 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1030
1031 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1032
1033 if (!reg)
1034 return NULL;
1035
1036 *ccp = p;
1037 return reg;
b99bd4ef
NC
1038}
1039
1040static int
dcbf9037
JB
1041arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1042 enum arm_reg_type type)
b99bd4ef 1043{
c19d1205
ZW
1044 /* Alternative syntaxes are accepted for a few register classes. */
1045 switch (type)
1046 {
1047 case REG_TYPE_MVF:
1048 case REG_TYPE_MVD:
1049 case REG_TYPE_MVFX:
1050 case REG_TYPE_MVDX:
1051 /* Generic coprocessor register names are allowed for these. */
79134647 1052 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1053 return reg->number;
1054 break;
69b97547 1055
c19d1205
ZW
1056 case REG_TYPE_CP:
1057 /* For backward compatibility, a bare number is valid here. */
1058 {
1059 unsigned long processor = strtoul (start, ccp, 10);
1060 if (*ccp != start && processor <= 15)
1061 return processor;
1062 }
6057a28f 1063
c19d1205
ZW
1064 case REG_TYPE_MMXWC:
1065 /* WC includes WCG. ??? I'm not sure this is true for all
1066 instructions that take WC registers. */
79134647 1067 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1068 return reg->number;
6057a28f 1069 break;
c19d1205 1070
6057a28f 1071 default:
c19d1205 1072 break;
6057a28f
NC
1073 }
1074
dcbf9037
JB
1075 return FAIL;
1076}
1077
1078/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1079 return value is the register number or FAIL. */
1080
1081static int
1082arm_reg_parse (char **ccp, enum arm_reg_type type)
1083{
1084 char *start = *ccp;
1085 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1086 int ret;
1087
1088 /* Do not allow a scalar (reg+index) to parse as a register. */
1089 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1090 return FAIL;
1091
1092 if (reg && reg->type == type)
1093 return reg->number;
1094
1095 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1096 return ret;
1097
c19d1205
ZW
1098 *ccp = start;
1099 return FAIL;
1100}
69b97547 1101
dcbf9037
JB
1102/* Parse a Neon type specifier. *STR should point at the leading '.'
1103 character. Does no verification at this stage that the type fits the opcode
1104 properly. E.g.,
1105
1106 .i32.i32.s16
1107 .s32.f32
1108 .u16
1109
1110 Can all be legally parsed by this function.
1111
1112 Fills in neon_type struct pointer with parsed information, and updates STR
1113 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1114 type, FAIL if not. */
1115
1116static int
1117parse_neon_type (struct neon_type *type, char **str)
1118{
1119 char *ptr = *str;
1120
1121 if (type)
1122 type->elems = 0;
1123
1124 while (type->elems < NEON_MAX_TYPE_ELS)
1125 {
1126 enum neon_el_type thistype = NT_untyped;
1127 unsigned thissize = -1u;
1128
1129 if (*ptr != '.')
1130 break;
1131
1132 ptr++;
1133
1134 /* Just a size without an explicit type. */
1135 if (ISDIGIT (*ptr))
1136 goto parsesize;
1137
1138 switch (TOLOWER (*ptr))
1139 {
1140 case 'i': thistype = NT_integer; break;
1141 case 'f': thistype = NT_float; break;
1142 case 'p': thistype = NT_poly; break;
1143 case 's': thistype = NT_signed; break;
1144 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1145 case 'd':
1146 thistype = NT_float;
1147 thissize = 64;
1148 ptr++;
1149 goto done;
dcbf9037
JB
1150 default:
1151 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1152 return FAIL;
1153 }
1154
1155 ptr++;
1156
1157 /* .f is an abbreviation for .f32. */
1158 if (thistype == NT_float && !ISDIGIT (*ptr))
1159 thissize = 32;
1160 else
1161 {
1162 parsesize:
1163 thissize = strtoul (ptr, &ptr, 10);
1164
1165 if (thissize != 8 && thissize != 16 && thissize != 32
1166 && thissize != 64)
1167 {
1168 as_bad (_("bad size %d in type specifier"), thissize);
1169 return FAIL;
1170 }
1171 }
1172
037e8744 1173 done:
dcbf9037
JB
1174 if (type)
1175 {
1176 type->el[type->elems].type = thistype;
1177 type->el[type->elems].size = thissize;
1178 type->elems++;
1179 }
1180 }
1181
1182 /* Empty/missing type is not a successful parse. */
1183 if (type->elems == 0)
1184 return FAIL;
1185
1186 *str = ptr;
1187
1188 return SUCCESS;
1189}
1190
1191/* Errors may be set multiple times during parsing or bit encoding
1192 (particularly in the Neon bits), but usually the earliest error which is set
1193 will be the most meaningful. Avoid overwriting it with later (cascading)
1194 errors by calling this function. */
1195
1196static void
1197first_error (const char *err)
1198{
1199 if (!inst.error)
1200 inst.error = err;
1201}
1202
1203/* Parse a single type, e.g. ".s32", leading period included. */
1204static int
1205parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1206{
1207 char *str = *ccp;
1208 struct neon_type optype;
1209
1210 if (*str == '.')
1211 {
1212 if (parse_neon_type (&optype, &str) == SUCCESS)
1213 {
1214 if (optype.elems == 1)
1215 *vectype = optype.el[0];
1216 else
1217 {
1218 first_error (_("only one type should be specified for operand"));
1219 return FAIL;
1220 }
1221 }
1222 else
1223 {
1224 first_error (_("vector type expected"));
1225 return FAIL;
1226 }
1227 }
1228 else
1229 return FAIL;
5f4273c7 1230
dcbf9037 1231 *ccp = str;
5f4273c7 1232
dcbf9037
JB
1233 return SUCCESS;
1234}
1235
1236/* Special meanings for indices (which have a range of 0-7), which will fit into
1237 a 4-bit integer. */
1238
1239#define NEON_ALL_LANES 15
1240#define NEON_INTERLEAVE_LANES 14
1241
1242/* Parse either a register or a scalar, with an optional type. Return the
1243 register number, and optionally fill in the actual type of the register
1244 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1245 type/index information in *TYPEINFO. */
1246
1247static int
1248parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1249 enum arm_reg_type *rtype,
1250 struct neon_typed_alias *typeinfo)
1251{
1252 char *str = *ccp;
1253 struct reg_entry *reg = arm_reg_parse_multi (&str);
1254 struct neon_typed_alias atype;
1255 struct neon_type_el parsetype;
1256
1257 atype.defined = 0;
1258 atype.index = -1;
1259 atype.eltype.type = NT_invtype;
1260 atype.eltype.size = -1;
1261
1262 /* Try alternate syntax for some types of register. Note these are mutually
1263 exclusive with the Neon syntax extensions. */
1264 if (reg == NULL)
1265 {
1266 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1267 if (altreg != FAIL)
1268 *ccp = str;
1269 if (typeinfo)
1270 *typeinfo = atype;
1271 return altreg;
1272 }
1273
037e8744
JB
1274 /* Undo polymorphism when a set of register types may be accepted. */
1275 if ((type == REG_TYPE_NDQ
1276 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1277 || (type == REG_TYPE_VFSD
1278 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1279 || (type == REG_TYPE_NSDQ
1280 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1281 || reg->type == REG_TYPE_NQ))
1282 || (type == REG_TYPE_MMXWC
1283 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1284 type = reg->type;
1285
1286 if (type != reg->type)
1287 return FAIL;
1288
1289 if (reg->neon)
1290 atype = *reg->neon;
5f4273c7 1291
dcbf9037
JB
1292 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1293 {
1294 if ((atype.defined & NTA_HASTYPE) != 0)
1295 {
1296 first_error (_("can't redefine type for operand"));
1297 return FAIL;
1298 }
1299 atype.defined |= NTA_HASTYPE;
1300 atype.eltype = parsetype;
1301 }
5f4273c7 1302
dcbf9037
JB
1303 if (skip_past_char (&str, '[') == SUCCESS)
1304 {
1305 if (type != REG_TYPE_VFD)
1306 {
1307 first_error (_("only D registers may be indexed"));
1308 return FAIL;
1309 }
5f4273c7 1310
dcbf9037
JB
1311 if ((atype.defined & NTA_HASINDEX) != 0)
1312 {
1313 first_error (_("can't change index for operand"));
1314 return FAIL;
1315 }
1316
1317 atype.defined |= NTA_HASINDEX;
1318
1319 if (skip_past_char (&str, ']') == SUCCESS)
1320 atype.index = NEON_ALL_LANES;
1321 else
1322 {
1323 expressionS exp;
1324
1325 my_get_expression (&exp, &str, GE_NO_PREFIX);
1326
1327 if (exp.X_op != O_constant)
1328 {
1329 first_error (_("constant expression required"));
1330 return FAIL;
1331 }
1332
1333 if (skip_past_char (&str, ']') == FAIL)
1334 return FAIL;
1335
1336 atype.index = exp.X_add_number;
1337 }
1338 }
5f4273c7 1339
dcbf9037
JB
1340 if (typeinfo)
1341 *typeinfo = atype;
5f4273c7 1342
dcbf9037
JB
1343 if (rtype)
1344 *rtype = type;
5f4273c7 1345
dcbf9037 1346 *ccp = str;
5f4273c7 1347
dcbf9037
JB
1348 return reg->number;
1349}
1350
1351/* Like arm_reg_parse, but allow allow the following extra features:
1352 - If RTYPE is non-zero, return the (possibly restricted) type of the
1353 register (e.g. Neon double or quad reg when either has been requested).
1354 - If this is a Neon vector type with additional type information, fill
1355 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1356 This function will fault on encountering a scalar. */
dcbf9037
JB
1357
1358static int
1359arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1360 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1361{
1362 struct neon_typed_alias atype;
1363 char *str = *ccp;
1364 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1365
1366 if (reg == FAIL)
1367 return FAIL;
1368
1369 /* Do not allow a scalar (reg+index) to parse as a register. */
1370 if ((atype.defined & NTA_HASINDEX) != 0)
1371 {
1372 first_error (_("register operand expected, but got scalar"));
1373 return FAIL;
1374 }
1375
1376 if (vectype)
1377 *vectype = atype.eltype;
1378
1379 *ccp = str;
1380
1381 return reg;
1382}
1383
1384#define NEON_SCALAR_REG(X) ((X) >> 4)
1385#define NEON_SCALAR_INDEX(X) ((X) & 15)
1386
5287ad62
JB
1387/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1388 have enough information to be able to do a good job bounds-checking. So, we
1389 just do easy checks here, and do further checks later. */
1390
1391static int
dcbf9037 1392parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1393{
dcbf9037 1394 int reg;
5287ad62 1395 char *str = *ccp;
dcbf9037 1396 struct neon_typed_alias atype;
5f4273c7 1397
dcbf9037 1398 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1399
dcbf9037 1400 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1401 return FAIL;
5f4273c7 1402
dcbf9037 1403 if (atype.index == NEON_ALL_LANES)
5287ad62 1404 {
dcbf9037 1405 first_error (_("scalar must have an index"));
5287ad62
JB
1406 return FAIL;
1407 }
dcbf9037 1408 else if (atype.index >= 64 / elsize)
5287ad62 1409 {
dcbf9037 1410 first_error (_("scalar index out of range"));
5287ad62
JB
1411 return FAIL;
1412 }
5f4273c7 1413
dcbf9037
JB
1414 if (type)
1415 *type = atype.eltype;
5f4273c7 1416
5287ad62 1417 *ccp = str;
5f4273c7 1418
dcbf9037 1419 return reg * 16 + atype.index;
5287ad62
JB
1420}
1421
c19d1205
ZW
1422/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1423static long
1424parse_reg_list (char ** strp)
1425{
1426 char * str = * strp;
1427 long range = 0;
1428 int another_range;
a737bd4d 1429
c19d1205
ZW
1430 /* We come back here if we get ranges concatenated by '+' or '|'. */
1431 do
6057a28f 1432 {
c19d1205 1433 another_range = 0;
a737bd4d 1434
c19d1205
ZW
1435 if (*str == '{')
1436 {
1437 int in_range = 0;
1438 int cur_reg = -1;
a737bd4d 1439
c19d1205
ZW
1440 str++;
1441 do
1442 {
1443 int reg;
6057a28f 1444
dcbf9037 1445 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1446 {
dcbf9037 1447 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1448 return FAIL;
1449 }
a737bd4d 1450
c19d1205
ZW
1451 if (in_range)
1452 {
1453 int i;
a737bd4d 1454
c19d1205
ZW
1455 if (reg <= cur_reg)
1456 {
dcbf9037 1457 first_error (_("bad range in register list"));
c19d1205
ZW
1458 return FAIL;
1459 }
40a18ebd 1460
c19d1205
ZW
1461 for (i = cur_reg + 1; i < reg; i++)
1462 {
1463 if (range & (1 << i))
1464 as_tsktsk
1465 (_("Warning: duplicated register (r%d) in register list"),
1466 i);
1467 else
1468 range |= 1 << i;
1469 }
1470 in_range = 0;
1471 }
a737bd4d 1472
c19d1205
ZW
1473 if (range & (1 << reg))
1474 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1475 reg);
1476 else if (reg <= cur_reg)
1477 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1478
c19d1205
ZW
1479 range |= 1 << reg;
1480 cur_reg = reg;
1481 }
1482 while (skip_past_comma (&str) != FAIL
1483 || (in_range = 1, *str++ == '-'));
1484 str--;
a737bd4d 1485
c19d1205
ZW
1486 if (*str++ != '}')
1487 {
dcbf9037 1488 first_error (_("missing `}'"));
c19d1205
ZW
1489 return FAIL;
1490 }
1491 }
1492 else
1493 {
1494 expressionS expr;
40a18ebd 1495
c19d1205
ZW
1496 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1497 return FAIL;
40a18ebd 1498
c19d1205
ZW
1499 if (expr.X_op == O_constant)
1500 {
1501 if (expr.X_add_number
1502 != (expr.X_add_number & 0x0000ffff))
1503 {
1504 inst.error = _("invalid register mask");
1505 return FAIL;
1506 }
a737bd4d 1507
c19d1205
ZW
1508 if ((range & expr.X_add_number) != 0)
1509 {
1510 int regno = range & expr.X_add_number;
a737bd4d 1511
c19d1205
ZW
1512 regno &= -regno;
1513 regno = (1 << regno) - 1;
1514 as_tsktsk
1515 (_("Warning: duplicated register (r%d) in register list"),
1516 regno);
1517 }
a737bd4d 1518
c19d1205
ZW
1519 range |= expr.X_add_number;
1520 }
1521 else
1522 {
1523 if (inst.reloc.type != 0)
1524 {
1525 inst.error = _("expression too complex");
1526 return FAIL;
1527 }
a737bd4d 1528
c19d1205
ZW
1529 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1530 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1531 inst.reloc.pc_rel = 0;
1532 }
1533 }
a737bd4d 1534
c19d1205
ZW
1535 if (*str == '|' || *str == '+')
1536 {
1537 str++;
1538 another_range = 1;
1539 }
a737bd4d 1540 }
c19d1205 1541 while (another_range);
a737bd4d 1542
c19d1205
ZW
1543 *strp = str;
1544 return range;
a737bd4d
NC
1545}
1546
5287ad62
JB
1547/* Types of registers in a list. */
1548
1549enum reg_list_els
1550{
1551 REGLIST_VFP_S,
1552 REGLIST_VFP_D,
1553 REGLIST_NEON_D
1554};
1555
c19d1205
ZW
1556/* Parse a VFP register list. If the string is invalid return FAIL.
1557 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1558 register. Parses registers of type ETYPE.
1559 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1560 - Q registers can be used to specify pairs of D registers
1561 - { } can be omitted from around a singleton register list
1562 FIXME: This is not implemented, as it would require backtracking in
1563 some cases, e.g.:
1564 vtbl.8 d3,d4,d5
1565 This could be done (the meaning isn't really ambiguous), but doesn't
1566 fit in well with the current parsing framework.
dcbf9037
JB
1567 - 32 D registers may be used (also true for VFPv3).
1568 FIXME: Types are ignored in these register lists, which is probably a
1569 bug. */
6057a28f 1570
c19d1205 1571static int
037e8744 1572parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1573{
037e8744 1574 char *str = *ccp;
c19d1205
ZW
1575 int base_reg;
1576 int new_base;
5287ad62
JB
1577 enum arm_reg_type regtype = 0;
1578 int max_regs = 0;
c19d1205
ZW
1579 int count = 0;
1580 int warned = 0;
1581 unsigned long mask = 0;
a737bd4d 1582 int i;
6057a28f 1583
037e8744 1584 if (*str != '{')
5287ad62
JB
1585 {
1586 inst.error = _("expecting {");
1587 return FAIL;
1588 }
6057a28f 1589
037e8744 1590 str++;
6057a28f 1591
5287ad62 1592 switch (etype)
c19d1205 1593 {
5287ad62 1594 case REGLIST_VFP_S:
c19d1205
ZW
1595 regtype = REG_TYPE_VFS;
1596 max_regs = 32;
5287ad62 1597 break;
5f4273c7 1598
5287ad62
JB
1599 case REGLIST_VFP_D:
1600 regtype = REG_TYPE_VFD;
b7fc2769 1601 break;
5f4273c7 1602
b7fc2769
JB
1603 case REGLIST_NEON_D:
1604 regtype = REG_TYPE_NDQ;
1605 break;
1606 }
1607
1608 if (etype != REGLIST_VFP_S)
1609 {
5287ad62
JB
1610 /* VFPv3 allows 32 D registers. */
1611 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1612 {
1613 max_regs = 32;
1614 if (thumb_mode)
1615 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1616 fpu_vfp_ext_v3);
1617 else
1618 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1619 fpu_vfp_ext_v3);
1620 }
1621 else
1622 max_regs = 16;
c19d1205 1623 }
6057a28f 1624
c19d1205 1625 base_reg = max_regs;
a737bd4d 1626
c19d1205
ZW
1627 do
1628 {
5287ad62 1629 int setmask = 1, addregs = 1;
dcbf9037 1630
037e8744 1631 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1632
c19d1205 1633 if (new_base == FAIL)
a737bd4d 1634 {
dcbf9037 1635 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1636 return FAIL;
1637 }
5f4273c7 1638
b7fc2769
JB
1639 if (new_base >= max_regs)
1640 {
1641 first_error (_("register out of range in list"));
1642 return FAIL;
1643 }
5f4273c7 1644
5287ad62
JB
1645 /* Note: a value of 2 * n is returned for the register Q<n>. */
1646 if (regtype == REG_TYPE_NQ)
1647 {
1648 setmask = 3;
1649 addregs = 2;
1650 }
1651
c19d1205
ZW
1652 if (new_base < base_reg)
1653 base_reg = new_base;
a737bd4d 1654
5287ad62 1655 if (mask & (setmask << new_base))
c19d1205 1656 {
dcbf9037 1657 first_error (_("invalid register list"));
c19d1205 1658 return FAIL;
a737bd4d 1659 }
a737bd4d 1660
c19d1205
ZW
1661 if ((mask >> new_base) != 0 && ! warned)
1662 {
1663 as_tsktsk (_("register list not in ascending order"));
1664 warned = 1;
1665 }
0bbf2aa4 1666
5287ad62
JB
1667 mask |= setmask << new_base;
1668 count += addregs;
0bbf2aa4 1669
037e8744 1670 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1671 {
1672 int high_range;
0bbf2aa4 1673
037e8744 1674 str++;
0bbf2aa4 1675
037e8744 1676 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1677 == FAIL)
c19d1205
ZW
1678 {
1679 inst.error = gettext (reg_expected_msgs[regtype]);
1680 return FAIL;
1681 }
0bbf2aa4 1682
b7fc2769
JB
1683 if (high_range >= max_regs)
1684 {
1685 first_error (_("register out of range in list"));
1686 return FAIL;
1687 }
1688
5287ad62
JB
1689 if (regtype == REG_TYPE_NQ)
1690 high_range = high_range + 1;
1691
c19d1205
ZW
1692 if (high_range <= new_base)
1693 {
1694 inst.error = _("register range not in ascending order");
1695 return FAIL;
1696 }
0bbf2aa4 1697
5287ad62 1698 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1699 {
5287ad62 1700 if (mask & (setmask << new_base))
0bbf2aa4 1701 {
c19d1205
ZW
1702 inst.error = _("invalid register list");
1703 return FAIL;
0bbf2aa4 1704 }
c19d1205 1705
5287ad62
JB
1706 mask |= setmask << new_base;
1707 count += addregs;
0bbf2aa4 1708 }
0bbf2aa4 1709 }
0bbf2aa4 1710 }
037e8744 1711 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1712
037e8744 1713 str++;
0bbf2aa4 1714
c19d1205
ZW
1715 /* Sanity check -- should have raised a parse error above. */
1716 if (count == 0 || count > max_regs)
1717 abort ();
1718
1719 *pbase = base_reg;
1720
1721 /* Final test -- the registers must be consecutive. */
1722 mask >>= base_reg;
1723 for (i = 0; i < count; i++)
1724 {
1725 if ((mask & (1u << i)) == 0)
1726 {
1727 inst.error = _("non-contiguous register range");
1728 return FAIL;
1729 }
1730 }
1731
037e8744
JB
1732 *ccp = str;
1733
c19d1205 1734 return count;
b99bd4ef
NC
1735}
1736
dcbf9037
JB
1737/* True if two alias types are the same. */
1738
1739static int
1740neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1741{
1742 if (!a && !b)
1743 return 1;
5f4273c7 1744
dcbf9037
JB
1745 if (!a || !b)
1746 return 0;
1747
1748 if (a->defined != b->defined)
1749 return 0;
5f4273c7 1750
dcbf9037
JB
1751 if ((a->defined & NTA_HASTYPE) != 0
1752 && (a->eltype.type != b->eltype.type
1753 || a->eltype.size != b->eltype.size))
1754 return 0;
1755
1756 if ((a->defined & NTA_HASINDEX) != 0
1757 && (a->index != b->index))
1758 return 0;
5f4273c7 1759
dcbf9037
JB
1760 return 1;
1761}
1762
5287ad62
JB
1763/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1764 The base register is put in *PBASE.
dcbf9037 1765 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1766 the return value.
1767 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1768 Bits [6:5] encode the list length (minus one).
1769 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1770
5287ad62 1771#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1772#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1773#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1774
1775static int
dcbf9037
JB
1776parse_neon_el_struct_list (char **str, unsigned *pbase,
1777 struct neon_type_el *eltype)
5287ad62
JB
1778{
1779 char *ptr = *str;
1780 int base_reg = -1;
1781 int reg_incr = -1;
1782 int count = 0;
1783 int lane = -1;
1784 int leading_brace = 0;
1785 enum arm_reg_type rtype = REG_TYPE_NDQ;
1786 int addregs = 1;
1787 const char *const incr_error = "register stride must be 1 or 2";
1788 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1789 struct neon_typed_alias firsttype;
5f4273c7 1790
5287ad62
JB
1791 if (skip_past_char (&ptr, '{') == SUCCESS)
1792 leading_brace = 1;
5f4273c7 1793
5287ad62
JB
1794 do
1795 {
dcbf9037
JB
1796 struct neon_typed_alias atype;
1797 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1798
5287ad62
JB
1799 if (getreg == FAIL)
1800 {
dcbf9037 1801 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1802 return FAIL;
1803 }
5f4273c7 1804
5287ad62
JB
1805 if (base_reg == -1)
1806 {
1807 base_reg = getreg;
1808 if (rtype == REG_TYPE_NQ)
1809 {
1810 reg_incr = 1;
1811 addregs = 2;
1812 }
dcbf9037 1813 firsttype = atype;
5287ad62
JB
1814 }
1815 else if (reg_incr == -1)
1816 {
1817 reg_incr = getreg - base_reg;
1818 if (reg_incr < 1 || reg_incr > 2)
1819 {
dcbf9037 1820 first_error (_(incr_error));
5287ad62
JB
1821 return FAIL;
1822 }
1823 }
1824 else if (getreg != base_reg + reg_incr * count)
1825 {
dcbf9037
JB
1826 first_error (_(incr_error));
1827 return FAIL;
1828 }
1829
1830 if (!neon_alias_types_same (&atype, &firsttype))
1831 {
1832 first_error (_(type_error));
5287ad62
JB
1833 return FAIL;
1834 }
5f4273c7 1835
5287ad62
JB
1836 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1837 modes. */
1838 if (ptr[0] == '-')
1839 {
dcbf9037 1840 struct neon_typed_alias htype;
5287ad62
JB
1841 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1842 if (lane == -1)
1843 lane = NEON_INTERLEAVE_LANES;
1844 else if (lane != NEON_INTERLEAVE_LANES)
1845 {
dcbf9037 1846 first_error (_(type_error));
5287ad62
JB
1847 return FAIL;
1848 }
1849 if (reg_incr == -1)
1850 reg_incr = 1;
1851 else if (reg_incr != 1)
1852 {
dcbf9037 1853 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1854 return FAIL;
1855 }
1856 ptr++;
dcbf9037 1857 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1858 if (hireg == FAIL)
1859 {
dcbf9037
JB
1860 first_error (_(reg_expected_msgs[rtype]));
1861 return FAIL;
1862 }
1863 if (!neon_alias_types_same (&htype, &firsttype))
1864 {
1865 first_error (_(type_error));
5287ad62
JB
1866 return FAIL;
1867 }
1868 count += hireg + dregs - getreg;
1869 continue;
1870 }
5f4273c7 1871
5287ad62
JB
1872 /* If we're using Q registers, we can't use [] or [n] syntax. */
1873 if (rtype == REG_TYPE_NQ)
1874 {
1875 count += 2;
1876 continue;
1877 }
5f4273c7 1878
dcbf9037 1879 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1880 {
dcbf9037
JB
1881 if (lane == -1)
1882 lane = atype.index;
1883 else if (lane != atype.index)
5287ad62 1884 {
dcbf9037
JB
1885 first_error (_(type_error));
1886 return FAIL;
5287ad62
JB
1887 }
1888 }
1889 else if (lane == -1)
1890 lane = NEON_INTERLEAVE_LANES;
1891 else if (lane != NEON_INTERLEAVE_LANES)
1892 {
dcbf9037 1893 first_error (_(type_error));
5287ad62
JB
1894 return FAIL;
1895 }
1896 count++;
1897 }
1898 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1899
5287ad62
JB
1900 /* No lane set by [x]. We must be interleaving structures. */
1901 if (lane == -1)
1902 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1903
5287ad62
JB
1904 /* Sanity check. */
1905 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1906 || (count > 1 && reg_incr == -1))
1907 {
dcbf9037 1908 first_error (_("error parsing element/structure list"));
5287ad62
JB
1909 return FAIL;
1910 }
1911
1912 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1913 {
dcbf9037 1914 first_error (_("expected }"));
5287ad62
JB
1915 return FAIL;
1916 }
5f4273c7 1917
5287ad62
JB
1918 if (reg_incr == -1)
1919 reg_incr = 1;
1920
dcbf9037
JB
1921 if (eltype)
1922 *eltype = firsttype.eltype;
1923
5287ad62
JB
1924 *pbase = base_reg;
1925 *str = ptr;
5f4273c7 1926
5287ad62
JB
1927 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1928}
1929
c19d1205
ZW
1930/* Parse an explicit relocation suffix on an expression. This is
1931 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1932 arm_reloc_hsh contains no entries, so this function can only
1933 succeed if there is no () after the word. Returns -1 on error,
1934 BFD_RELOC_UNUSED if there wasn't any suffix. */
1935static int
1936parse_reloc (char **str)
b99bd4ef 1937{
c19d1205
ZW
1938 struct reloc_entry *r;
1939 char *p, *q;
b99bd4ef 1940
c19d1205
ZW
1941 if (**str != '(')
1942 return BFD_RELOC_UNUSED;
b99bd4ef 1943
c19d1205
ZW
1944 p = *str + 1;
1945 q = p;
1946
1947 while (*q && *q != ')' && *q != ',')
1948 q++;
1949 if (*q != ')')
1950 return -1;
1951
1952 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1953 return -1;
1954
1955 *str = q + 1;
1956 return r->reloc;
b99bd4ef
NC
1957}
1958
c19d1205
ZW
1959/* Directives: register aliases. */
1960
dcbf9037 1961static struct reg_entry *
c19d1205 1962insert_reg_alias (char *str, int number, int type)
b99bd4ef 1963{
c19d1205
ZW
1964 struct reg_entry *new;
1965 const char *name;
b99bd4ef 1966
c19d1205
ZW
1967 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1968 {
1969 if (new->builtin)
1970 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1971
c19d1205
ZW
1972 /* Only warn about a redefinition if it's not defined as the
1973 same register. */
1974 else if (new->number != number || new->type != type)
1975 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1976
d929913e 1977 return NULL;
c19d1205 1978 }
b99bd4ef 1979
c19d1205
ZW
1980 name = xstrdup (str);
1981 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1982
c19d1205
ZW
1983 new->name = name;
1984 new->number = number;
1985 new->type = type;
1986 new->builtin = FALSE;
dcbf9037 1987 new->neon = NULL;
b99bd4ef 1988
c19d1205
ZW
1989 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1990 abort ();
5f4273c7 1991
dcbf9037
JB
1992 return new;
1993}
1994
1995static void
1996insert_neon_reg_alias (char *str, int number, int type,
1997 struct neon_typed_alias *atype)
1998{
1999 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2000
dcbf9037
JB
2001 if (!reg)
2002 {
2003 first_error (_("attempt to redefine typed alias"));
2004 return;
2005 }
5f4273c7 2006
dcbf9037
JB
2007 if (atype)
2008 {
2009 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2010 *reg->neon = *atype;
2011 }
c19d1205 2012}
b99bd4ef 2013
c19d1205 2014/* Look for the .req directive. This is of the form:
b99bd4ef 2015
c19d1205 2016 new_register_name .req existing_register_name
b99bd4ef 2017
c19d1205 2018 If we find one, or if it looks sufficiently like one that we want to
d929913e 2019 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2020
d929913e 2021static bfd_boolean
c19d1205
ZW
2022create_register_alias (char * newname, char *p)
2023{
2024 struct reg_entry *old;
2025 char *oldname, *nbuf;
2026 size_t nlen;
b99bd4ef 2027
c19d1205
ZW
2028 /* The input scrubber ensures that whitespace after the mnemonic is
2029 collapsed to single spaces. */
2030 oldname = p;
2031 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2032 return FALSE;
b99bd4ef 2033
c19d1205
ZW
2034 oldname += 6;
2035 if (*oldname == '\0')
d929913e 2036 return FALSE;
b99bd4ef 2037
c19d1205
ZW
2038 old = hash_find (arm_reg_hsh, oldname);
2039 if (!old)
b99bd4ef 2040 {
c19d1205 2041 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2042 return TRUE;
b99bd4ef
NC
2043 }
2044
c19d1205
ZW
2045 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2046 the desired alias name, and p points to its end. If not, then
2047 the desired alias name is in the global original_case_string. */
2048#ifdef TC_CASE_SENSITIVE
2049 nlen = p - newname;
2050#else
2051 newname = original_case_string;
2052 nlen = strlen (newname);
2053#endif
b99bd4ef 2054
c19d1205
ZW
2055 nbuf = alloca (nlen + 1);
2056 memcpy (nbuf, newname, nlen);
2057 nbuf[nlen] = '\0';
b99bd4ef 2058
c19d1205
ZW
2059 /* Create aliases under the new name as stated; an all-lowercase
2060 version of the new name; and an all-uppercase version of the new
2061 name. */
d929913e
NC
2062 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2063 {
2064 for (p = nbuf; *p; p++)
2065 *p = TOUPPER (*p);
c19d1205 2066
d929913e
NC
2067 if (strncmp (nbuf, newname, nlen))
2068 {
2069 /* If this attempt to create an additional alias fails, do not bother
2070 trying to create the all-lower case alias. We will fail and issue
2071 a second, duplicate error message. This situation arises when the
2072 programmer does something like:
2073 foo .req r0
2074 Foo .req r1
2075 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2076 the artificial FOO alias because it has already been created by the
d929913e
NC
2077 first .req. */
2078 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2079 return TRUE;
2080 }
c19d1205 2081
d929913e
NC
2082 for (p = nbuf; *p; p++)
2083 *p = TOLOWER (*p);
c19d1205 2084
d929913e
NC
2085 if (strncmp (nbuf, newname, nlen))
2086 insert_reg_alias (nbuf, old->number, old->type);
2087 }
c19d1205 2088
d929913e 2089 return TRUE;
b99bd4ef
NC
2090}
2091
dcbf9037
JB
2092/* Create a Neon typed/indexed register alias using directives, e.g.:
2093 X .dn d5.s32[1]
2094 Y .qn 6.s16
2095 Z .dn d7
2096 T .dn Z[0]
2097 These typed registers can be used instead of the types specified after the
2098 Neon mnemonic, so long as all operands given have types. Types can also be
2099 specified directly, e.g.:
5f4273c7 2100 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2101
2102static int
2103create_neon_reg_alias (char *newname, char *p)
2104{
2105 enum arm_reg_type basetype;
2106 struct reg_entry *basereg;
2107 struct reg_entry mybasereg;
2108 struct neon_type ntype;
2109 struct neon_typed_alias typeinfo;
2110 char *namebuf, *nameend;
2111 int namelen;
5f4273c7 2112
dcbf9037
JB
2113 typeinfo.defined = 0;
2114 typeinfo.eltype.type = NT_invtype;
2115 typeinfo.eltype.size = -1;
2116 typeinfo.index = -1;
5f4273c7 2117
dcbf9037 2118 nameend = p;
5f4273c7 2119
dcbf9037
JB
2120 if (strncmp (p, " .dn ", 5) == 0)
2121 basetype = REG_TYPE_VFD;
2122 else if (strncmp (p, " .qn ", 5) == 0)
2123 basetype = REG_TYPE_NQ;
2124 else
2125 return 0;
5f4273c7 2126
dcbf9037 2127 p += 5;
5f4273c7 2128
dcbf9037
JB
2129 if (*p == '\0')
2130 return 0;
5f4273c7 2131
dcbf9037
JB
2132 basereg = arm_reg_parse_multi (&p);
2133
2134 if (basereg && basereg->type != basetype)
2135 {
2136 as_bad (_("bad type for register"));
2137 return 0;
2138 }
2139
2140 if (basereg == NULL)
2141 {
2142 expressionS exp;
2143 /* Try parsing as an integer. */
2144 my_get_expression (&exp, &p, GE_NO_PREFIX);
2145 if (exp.X_op != O_constant)
2146 {
2147 as_bad (_("expression must be constant"));
2148 return 0;
2149 }
2150 basereg = &mybasereg;
2151 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2152 : exp.X_add_number;
2153 basereg->neon = 0;
2154 }
2155
2156 if (basereg->neon)
2157 typeinfo = *basereg->neon;
2158
2159 if (parse_neon_type (&ntype, &p) == SUCCESS)
2160 {
2161 /* We got a type. */
2162 if (typeinfo.defined & NTA_HASTYPE)
2163 {
2164 as_bad (_("can't redefine the type of a register alias"));
2165 return 0;
2166 }
5f4273c7 2167
dcbf9037
JB
2168 typeinfo.defined |= NTA_HASTYPE;
2169 if (ntype.elems != 1)
2170 {
2171 as_bad (_("you must specify a single type only"));
2172 return 0;
2173 }
2174 typeinfo.eltype = ntype.el[0];
2175 }
5f4273c7 2176
dcbf9037
JB
2177 if (skip_past_char (&p, '[') == SUCCESS)
2178 {
2179 expressionS exp;
2180 /* We got a scalar index. */
5f4273c7 2181
dcbf9037
JB
2182 if (typeinfo.defined & NTA_HASINDEX)
2183 {
2184 as_bad (_("can't redefine the index of a scalar alias"));
2185 return 0;
2186 }
5f4273c7 2187
dcbf9037 2188 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2189
dcbf9037
JB
2190 if (exp.X_op != O_constant)
2191 {
2192 as_bad (_("scalar index must be constant"));
2193 return 0;
2194 }
5f4273c7 2195
dcbf9037
JB
2196 typeinfo.defined |= NTA_HASINDEX;
2197 typeinfo.index = exp.X_add_number;
5f4273c7 2198
dcbf9037
JB
2199 if (skip_past_char (&p, ']') == FAIL)
2200 {
2201 as_bad (_("expecting ]"));
2202 return 0;
2203 }
2204 }
2205
2206 namelen = nameend - newname;
2207 namebuf = alloca (namelen + 1);
2208 strncpy (namebuf, newname, namelen);
2209 namebuf[namelen] = '\0';
5f4273c7 2210
dcbf9037
JB
2211 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2212 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2213
dcbf9037
JB
2214 /* Insert name in all uppercase. */
2215 for (p = namebuf; *p; p++)
2216 *p = TOUPPER (*p);
5f4273c7 2217
dcbf9037
JB
2218 if (strncmp (namebuf, newname, namelen))
2219 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2220 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2221
dcbf9037
JB
2222 /* Insert name in all lowercase. */
2223 for (p = namebuf; *p; p++)
2224 *p = TOLOWER (*p);
5f4273c7 2225
dcbf9037
JB
2226 if (strncmp (namebuf, newname, namelen))
2227 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2228 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2229
dcbf9037
JB
2230 return 1;
2231}
2232
c19d1205
ZW
2233/* Should never be called, as .req goes between the alias and the
2234 register name, not at the beginning of the line. */
b99bd4ef 2235static void
c19d1205 2236s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2237{
c19d1205
ZW
2238 as_bad (_("invalid syntax for .req directive"));
2239}
b99bd4ef 2240
dcbf9037
JB
2241static void
2242s_dn (int a ATTRIBUTE_UNUSED)
2243{
2244 as_bad (_("invalid syntax for .dn directive"));
2245}
2246
2247static void
2248s_qn (int a ATTRIBUTE_UNUSED)
2249{
2250 as_bad (_("invalid syntax for .qn directive"));
2251}
2252
c19d1205
ZW
2253/* The .unreq directive deletes an alias which was previously defined
2254 by .req. For example:
b99bd4ef 2255
c19d1205
ZW
2256 my_alias .req r11
2257 .unreq my_alias */
b99bd4ef
NC
2258
2259static void
c19d1205 2260s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2261{
c19d1205
ZW
2262 char * name;
2263 char saved_char;
b99bd4ef 2264
c19d1205
ZW
2265 name = input_line_pointer;
2266
2267 while (*input_line_pointer != 0
2268 && *input_line_pointer != ' '
2269 && *input_line_pointer != '\n')
2270 ++input_line_pointer;
2271
2272 saved_char = *input_line_pointer;
2273 *input_line_pointer = 0;
2274
2275 if (!*name)
2276 as_bad (_("invalid syntax for .unreq directive"));
2277 else
2278 {
2279 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2280
2281 if (!reg)
2282 as_bad (_("unknown register alias '%s'"), name);
2283 else if (reg->builtin)
2284 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2285 name);
2286 else
2287 {
d929913e
NC
2288 char * p;
2289 char * nbuf;
2290
c19d1205
ZW
2291 hash_delete (arm_reg_hsh, name);
2292 free ((char *) reg->name);
dcbf9037
JB
2293 if (reg->neon)
2294 free (reg->neon);
c19d1205 2295 free (reg);
d929913e
NC
2296
2297 /* Also locate the all upper case and all lower case versions.
2298 Do not complain if we cannot find one or the other as it
2299 was probably deleted above. */
5f4273c7 2300
d929913e
NC
2301 nbuf = strdup (name);
2302 for (p = nbuf; *p; p++)
2303 *p = TOUPPER (*p);
2304 reg = hash_find (arm_reg_hsh, nbuf);
2305 if (reg)
2306 {
2307 hash_delete (arm_reg_hsh, nbuf);
2308 free ((char *) reg->name);
2309 if (reg->neon)
2310 free (reg->neon);
2311 free (reg);
2312 }
2313
2314 for (p = nbuf; *p; p++)
2315 *p = TOLOWER (*p);
2316 reg = hash_find (arm_reg_hsh, nbuf);
2317 if (reg)
2318 {
2319 hash_delete (arm_reg_hsh, nbuf);
2320 free ((char *) reg->name);
2321 if (reg->neon)
2322 free (reg->neon);
2323 free (reg);
2324 }
2325
2326 free (nbuf);
c19d1205
ZW
2327 }
2328 }
b99bd4ef 2329
c19d1205 2330 *input_line_pointer = saved_char;
b99bd4ef
NC
2331 demand_empty_rest_of_line ();
2332}
2333
c19d1205
ZW
2334/* Directives: Instruction set selection. */
2335
2336#ifdef OBJ_ELF
2337/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2338 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2339 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2340 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2341
2342static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2343
e821645d 2344void
c19d1205 2345mapping_state (enum mstate state)
b99bd4ef 2346{
a737bd4d 2347 symbolS * symbolP;
c19d1205
ZW
2348 const char * symname;
2349 int type;
b99bd4ef 2350
c19d1205
ZW
2351 if (mapstate == state)
2352 /* The mapping symbol has already been emitted.
2353 There is nothing else to do. */
2354 return;
b99bd4ef 2355
c19d1205 2356 mapstate = state;
b99bd4ef 2357
c19d1205 2358 switch (state)
b99bd4ef 2359 {
c19d1205
ZW
2360 case MAP_DATA:
2361 symname = "$d";
2362 type = BSF_NO_FLAGS;
2363 break;
2364 case MAP_ARM:
2365 symname = "$a";
2366 type = BSF_NO_FLAGS;
2367 break;
2368 case MAP_THUMB:
2369 symname = "$t";
2370 type = BSF_NO_FLAGS;
2371 break;
2372 case MAP_UNDEFINED:
2373 return;
2374 default:
2375 abort ();
2376 }
2377
2378 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2379
2380 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2381 symbol_table_insert (symbolP);
2382 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2383
2384 switch (state)
2385 {
2386 case MAP_ARM:
2387 THUMB_SET_FUNC (symbolP, 0);
2388 ARM_SET_THUMB (symbolP, 0);
2389 ARM_SET_INTERWORK (symbolP, support_interwork);
2390 break;
2391
2392 case MAP_THUMB:
2393 THUMB_SET_FUNC (symbolP, 1);
2394 ARM_SET_THUMB (symbolP, 1);
2395 ARM_SET_INTERWORK (symbolP, support_interwork);
2396 break;
2397
2398 case MAP_DATA:
2399 default:
2400 return;
2401 }
2402}
2403#else
2404#define mapping_state(x) /* nothing */
2405#endif
2406
2407/* Find the real, Thumb encoded start of a Thumb function. */
2408
2409static symbolS *
2410find_real_start (symbolS * symbolP)
2411{
2412 char * real_start;
2413 const char * name = S_GET_NAME (symbolP);
2414 symbolS * new_target;
2415
2416 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2417#define STUB_NAME ".real_start_of"
2418
2419 if (name == NULL)
2420 abort ();
2421
37f6032b
ZW
2422 /* The compiler may generate BL instructions to local labels because
2423 it needs to perform a branch to a far away location. These labels
2424 do not have a corresponding ".real_start_of" label. We check
2425 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2426 the ".real_start_of" convention for nonlocal branches. */
2427 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2428 return symbolP;
2429
37f6032b 2430 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2431 new_target = symbol_find (real_start);
2432
2433 if (new_target == NULL)
2434 {
bd3ba5d1 2435 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2436 new_target = symbolP;
2437 }
2438
c19d1205
ZW
2439 return new_target;
2440}
2441
2442static void
2443opcode_select (int width)
2444{
2445 switch (width)
2446 {
2447 case 16:
2448 if (! thumb_mode)
2449 {
e74cfd16 2450 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2451 as_bad (_("selected processor does not support THUMB opcodes"));
2452
2453 thumb_mode = 1;
2454 /* No need to force the alignment, since we will have been
2455 coming from ARM mode, which is word-aligned. */
2456 record_alignment (now_seg, 1);
2457 }
2458 mapping_state (MAP_THUMB);
2459 break;
2460
2461 case 32:
2462 if (thumb_mode)
2463 {
e74cfd16 2464 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2465 as_bad (_("selected processor does not support ARM opcodes"));
2466
2467 thumb_mode = 0;
2468
2469 if (!need_pass_2)
2470 frag_align (2, 0, 0);
2471
2472 record_alignment (now_seg, 1);
2473 }
2474 mapping_state (MAP_ARM);
2475 break;
2476
2477 default:
2478 as_bad (_("invalid instruction size selected (%d)"), width);
2479 }
2480}
2481
2482static void
2483s_arm (int ignore ATTRIBUTE_UNUSED)
2484{
2485 opcode_select (32);
2486 demand_empty_rest_of_line ();
2487}
2488
2489static void
2490s_thumb (int ignore ATTRIBUTE_UNUSED)
2491{
2492 opcode_select (16);
2493 demand_empty_rest_of_line ();
2494}
2495
2496static void
2497s_code (int unused ATTRIBUTE_UNUSED)
2498{
2499 int temp;
2500
2501 temp = get_absolute_expression ();
2502 switch (temp)
2503 {
2504 case 16:
2505 case 32:
2506 opcode_select (temp);
2507 break;
2508
2509 default:
2510 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2511 }
2512}
2513
2514static void
2515s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2516{
2517 /* If we are not already in thumb mode go into it, EVEN if
2518 the target processor does not support thumb instructions.
2519 This is used by gcc/config/arm/lib1funcs.asm for example
2520 to compile interworking support functions even if the
2521 target processor should not support interworking. */
2522 if (! thumb_mode)
2523 {
2524 thumb_mode = 2;
2525 record_alignment (now_seg, 1);
2526 }
2527
2528 demand_empty_rest_of_line ();
2529}
2530
2531static void
2532s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2533{
2534 s_thumb (0);
2535
2536 /* The following label is the name/address of the start of a Thumb function.
2537 We need to know this for the interworking support. */
2538 label_is_thumb_function_name = TRUE;
2539}
2540
2541/* Perform a .set directive, but also mark the alias as
2542 being a thumb function. */
2543
2544static void
2545s_thumb_set (int equiv)
2546{
2547 /* XXX the following is a duplicate of the code for s_set() in read.c
2548 We cannot just call that code as we need to get at the symbol that
2549 is created. */
2550 char * name;
2551 char delim;
2552 char * end_name;
2553 symbolS * symbolP;
2554
2555 /* Especial apologies for the random logic:
2556 This just grew, and could be parsed much more simply!
2557 Dean - in haste. */
2558 name = input_line_pointer;
2559 delim = get_symbol_end ();
2560 end_name = input_line_pointer;
2561 *end_name = delim;
2562
2563 if (*input_line_pointer != ',')
2564 {
2565 *end_name = 0;
2566 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2567 *end_name = delim;
2568 ignore_rest_of_line ();
2569 return;
2570 }
2571
2572 input_line_pointer++;
2573 *end_name = 0;
2574
2575 if (name[0] == '.' && name[1] == '\0')
2576 {
2577 /* XXX - this should not happen to .thumb_set. */
2578 abort ();
2579 }
2580
2581 if ((symbolP = symbol_find (name)) == NULL
2582 && (symbolP = md_undefined_symbol (name)) == NULL)
2583 {
2584#ifndef NO_LISTING
2585 /* When doing symbol listings, play games with dummy fragments living
2586 outside the normal fragment chain to record the file and line info
c19d1205 2587 for this symbol. */
b99bd4ef
NC
2588 if (listing & LISTING_SYMBOLS)
2589 {
2590 extern struct list_info_struct * listing_tail;
a737bd4d 2591 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2592
2593 memset (dummy_frag, 0, sizeof (fragS));
2594 dummy_frag->fr_type = rs_fill;
2595 dummy_frag->line = listing_tail;
2596 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2597 dummy_frag->fr_symbol = symbolP;
2598 }
2599 else
2600#endif
2601 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2602
2603#ifdef OBJ_COFF
2604 /* "set" symbols are local unless otherwise specified. */
2605 SF_SET_LOCAL (symbolP);
2606#endif /* OBJ_COFF */
2607 } /* Make a new symbol. */
2608
2609 symbol_table_insert (symbolP);
2610
2611 * end_name = delim;
2612
2613 if (equiv
2614 && S_IS_DEFINED (symbolP)
2615 && S_GET_SEGMENT (symbolP) != reg_section)
2616 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2617
2618 pseudo_set (symbolP);
2619
2620 demand_empty_rest_of_line ();
2621
c19d1205 2622 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2623
2624 THUMB_SET_FUNC (symbolP, 1);
2625 ARM_SET_THUMB (symbolP, 1);
2626#if defined OBJ_ELF || defined OBJ_COFF
2627 ARM_SET_INTERWORK (symbolP, support_interwork);
2628#endif
2629}
2630
c19d1205 2631/* Directives: Mode selection. */
b99bd4ef 2632
c19d1205
ZW
2633/* .syntax [unified|divided] - choose the new unified syntax
2634 (same for Arm and Thumb encoding, modulo slight differences in what
2635 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2636static void
c19d1205 2637s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2638{
c19d1205
ZW
2639 char *name, delim;
2640
2641 name = input_line_pointer;
2642 delim = get_symbol_end ();
2643
2644 if (!strcasecmp (name, "unified"))
2645 unified_syntax = TRUE;
2646 else if (!strcasecmp (name, "divided"))
2647 unified_syntax = FALSE;
2648 else
2649 {
2650 as_bad (_("unrecognized syntax mode \"%s\""), name);
2651 return;
2652 }
2653 *input_line_pointer = delim;
b99bd4ef
NC
2654 demand_empty_rest_of_line ();
2655}
2656
c19d1205
ZW
2657/* Directives: sectioning and alignment. */
2658
2659/* Same as s_align_ptwo but align 0 => align 2. */
2660
b99bd4ef 2661static void
c19d1205 2662s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2663{
a737bd4d 2664 int temp;
dce323d1 2665 bfd_boolean fill_p;
c19d1205
ZW
2666 long temp_fill;
2667 long max_alignment = 15;
b99bd4ef
NC
2668
2669 temp = get_absolute_expression ();
c19d1205
ZW
2670 if (temp > max_alignment)
2671 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2672 else if (temp < 0)
b99bd4ef 2673 {
c19d1205
ZW
2674 as_bad (_("alignment negative. 0 assumed."));
2675 temp = 0;
2676 }
b99bd4ef 2677
c19d1205
ZW
2678 if (*input_line_pointer == ',')
2679 {
2680 input_line_pointer++;
2681 temp_fill = get_absolute_expression ();
dce323d1 2682 fill_p = TRUE;
b99bd4ef 2683 }
c19d1205 2684 else
dce323d1
PB
2685 {
2686 fill_p = FALSE;
2687 temp_fill = 0;
2688 }
b99bd4ef 2689
c19d1205
ZW
2690 if (!temp)
2691 temp = 2;
b99bd4ef 2692
c19d1205
ZW
2693 /* Only make a frag if we HAVE to. */
2694 if (temp && !need_pass_2)
dce323d1
PB
2695 {
2696 if (!fill_p && subseg_text_p (now_seg))
2697 frag_align_code (temp, 0);
2698 else
2699 frag_align (temp, (int) temp_fill, 0);
2700 }
c19d1205
ZW
2701 demand_empty_rest_of_line ();
2702
2703 record_alignment (now_seg, temp);
b99bd4ef
NC
2704}
2705
c19d1205
ZW
2706static void
2707s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2708{
c19d1205
ZW
2709 /* We don't support putting frags in the BSS segment, we fake it by
2710 marking in_bss, then looking at s_skip for clues. */
2711 subseg_set (bss_section, 0);
2712 demand_empty_rest_of_line ();
2713 mapping_state (MAP_DATA);
2714}
b99bd4ef 2715
c19d1205
ZW
2716static void
2717s_even (int ignore ATTRIBUTE_UNUSED)
2718{
2719 /* Never make frag if expect extra pass. */
2720 if (!need_pass_2)
2721 frag_align (1, 0, 0);
b99bd4ef 2722
c19d1205 2723 record_alignment (now_seg, 1);
b99bd4ef 2724
c19d1205 2725 demand_empty_rest_of_line ();
b99bd4ef
NC
2726}
2727
c19d1205 2728/* Directives: Literal pools. */
a737bd4d 2729
c19d1205
ZW
2730static literal_pool *
2731find_literal_pool (void)
a737bd4d 2732{
c19d1205 2733 literal_pool * pool;
a737bd4d 2734
c19d1205 2735 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2736 {
c19d1205
ZW
2737 if (pool->section == now_seg
2738 && pool->sub_section == now_subseg)
2739 break;
a737bd4d
NC
2740 }
2741
c19d1205 2742 return pool;
a737bd4d
NC
2743}
2744
c19d1205
ZW
2745static literal_pool *
2746find_or_make_literal_pool (void)
a737bd4d 2747{
c19d1205
ZW
2748 /* Next literal pool ID number. */
2749 static unsigned int latest_pool_num = 1;
2750 literal_pool * pool;
a737bd4d 2751
c19d1205 2752 pool = find_literal_pool ();
a737bd4d 2753
c19d1205 2754 if (pool == NULL)
a737bd4d 2755 {
c19d1205
ZW
2756 /* Create a new pool. */
2757 pool = xmalloc (sizeof (* pool));
2758 if (! pool)
2759 return NULL;
a737bd4d 2760
c19d1205
ZW
2761 pool->next_free_entry = 0;
2762 pool->section = now_seg;
2763 pool->sub_section = now_subseg;
2764 pool->next = list_of_pools;
2765 pool->symbol = NULL;
2766
2767 /* Add it to the list. */
2768 list_of_pools = pool;
a737bd4d 2769 }
a737bd4d 2770
c19d1205
ZW
2771 /* New pools, and emptied pools, will have a NULL symbol. */
2772 if (pool->symbol == NULL)
a737bd4d 2773 {
c19d1205
ZW
2774 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2775 (valueT) 0, &zero_address_frag);
2776 pool->id = latest_pool_num ++;
a737bd4d
NC
2777 }
2778
c19d1205
ZW
2779 /* Done. */
2780 return pool;
a737bd4d
NC
2781}
2782
c19d1205 2783/* Add the literal in the global 'inst'
5f4273c7 2784 structure to the relevant literal pool. */
b99bd4ef
NC
2785
2786static int
c19d1205 2787add_to_lit_pool (void)
b99bd4ef 2788{
c19d1205
ZW
2789 literal_pool * pool;
2790 unsigned int entry;
b99bd4ef 2791
c19d1205
ZW
2792 pool = find_or_make_literal_pool ();
2793
2794 /* Check if this literal value is already in the pool. */
2795 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2796 {
c19d1205
ZW
2797 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2798 && (inst.reloc.exp.X_op == O_constant)
2799 && (pool->literals[entry].X_add_number
2800 == inst.reloc.exp.X_add_number)
2801 && (pool->literals[entry].X_unsigned
2802 == inst.reloc.exp.X_unsigned))
2803 break;
2804
2805 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2806 && (inst.reloc.exp.X_op == O_symbol)
2807 && (pool->literals[entry].X_add_number
2808 == inst.reloc.exp.X_add_number)
2809 && (pool->literals[entry].X_add_symbol
2810 == inst.reloc.exp.X_add_symbol)
2811 && (pool->literals[entry].X_op_symbol
2812 == inst.reloc.exp.X_op_symbol))
2813 break;
b99bd4ef
NC
2814 }
2815
c19d1205
ZW
2816 /* Do we need to create a new entry? */
2817 if (entry == pool->next_free_entry)
2818 {
2819 if (entry >= MAX_LITERAL_POOL_SIZE)
2820 {
2821 inst.error = _("literal pool overflow");
2822 return FAIL;
2823 }
2824
2825 pool->literals[entry] = inst.reloc.exp;
2826 pool->next_free_entry += 1;
2827 }
b99bd4ef 2828
c19d1205
ZW
2829 inst.reloc.exp.X_op = O_symbol;
2830 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2831 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2832
c19d1205 2833 return SUCCESS;
b99bd4ef
NC
2834}
2835
c19d1205
ZW
2836/* Can't use symbol_new here, so have to create a symbol and then at
2837 a later date assign it a value. Thats what these functions do. */
e16bb312 2838
c19d1205
ZW
2839static void
2840symbol_locate (symbolS * symbolP,
2841 const char * name, /* It is copied, the caller can modify. */
2842 segT segment, /* Segment identifier (SEG_<something>). */
2843 valueT valu, /* Symbol value. */
2844 fragS * frag) /* Associated fragment. */
2845{
2846 unsigned int name_length;
2847 char * preserved_copy_of_name;
e16bb312 2848
c19d1205
ZW
2849 name_length = strlen (name) + 1; /* +1 for \0. */
2850 obstack_grow (&notes, name, name_length);
2851 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2852
c19d1205
ZW
2853#ifdef tc_canonicalize_symbol_name
2854 preserved_copy_of_name =
2855 tc_canonicalize_symbol_name (preserved_copy_of_name);
2856#endif
b99bd4ef 2857
c19d1205 2858 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2859
c19d1205
ZW
2860 S_SET_SEGMENT (symbolP, segment);
2861 S_SET_VALUE (symbolP, valu);
2862 symbol_clear_list_pointers (symbolP);
b99bd4ef 2863
c19d1205 2864 symbol_set_frag (symbolP, frag);
b99bd4ef 2865
c19d1205
ZW
2866 /* Link to end of symbol chain. */
2867 {
2868 extern int symbol_table_frozen;
b99bd4ef 2869
c19d1205
ZW
2870 if (symbol_table_frozen)
2871 abort ();
2872 }
b99bd4ef 2873
c19d1205 2874 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2875
c19d1205 2876 obj_symbol_new_hook (symbolP);
b99bd4ef 2877
c19d1205
ZW
2878#ifdef tc_symbol_new_hook
2879 tc_symbol_new_hook (symbolP);
2880#endif
2881
2882#ifdef DEBUG_SYMS
2883 verify_symbol_chain (symbol_rootP, symbol_lastP);
2884#endif /* DEBUG_SYMS */
b99bd4ef
NC
2885}
2886
b99bd4ef 2887
c19d1205
ZW
2888static void
2889s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2890{
c19d1205
ZW
2891 unsigned int entry;
2892 literal_pool * pool;
2893 char sym_name[20];
b99bd4ef 2894
c19d1205
ZW
2895 pool = find_literal_pool ();
2896 if (pool == NULL
2897 || pool->symbol == NULL
2898 || pool->next_free_entry == 0)
2899 return;
b99bd4ef 2900
c19d1205 2901 mapping_state (MAP_DATA);
b99bd4ef 2902
c19d1205
ZW
2903 /* Align pool as you have word accesses.
2904 Only make a frag if we have to. */
2905 if (!need_pass_2)
2906 frag_align (2, 0, 0);
b99bd4ef 2907
c19d1205 2908 record_alignment (now_seg, 2);
b99bd4ef 2909
c19d1205 2910 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2911
c19d1205
ZW
2912 symbol_locate (pool->symbol, sym_name, now_seg,
2913 (valueT) frag_now_fix (), frag_now);
2914 symbol_table_insert (pool->symbol);
b99bd4ef 2915
c19d1205 2916 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2917
c19d1205
ZW
2918#if defined OBJ_COFF || defined OBJ_ELF
2919 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2920#endif
6c43fab6 2921
c19d1205
ZW
2922 for (entry = 0; entry < pool->next_free_entry; entry ++)
2923 /* First output the expression in the instruction to the pool. */
2924 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2925
c19d1205
ZW
2926 /* Mark the pool as empty. */
2927 pool->next_free_entry = 0;
2928 pool->symbol = NULL;
b99bd4ef
NC
2929}
2930
c19d1205
ZW
2931#ifdef OBJ_ELF
2932/* Forward declarations for functions below, in the MD interface
2933 section. */
2934static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2935static valueT create_unwind_entry (int);
2936static void start_unwind_section (const segT, int);
2937static void add_unwind_opcode (valueT, int);
2938static void flush_pending_unwind (void);
b99bd4ef 2939
c19d1205 2940/* Directives: Data. */
b99bd4ef 2941
c19d1205
ZW
2942static void
2943s_arm_elf_cons (int nbytes)
2944{
2945 expressionS exp;
b99bd4ef 2946
c19d1205
ZW
2947#ifdef md_flush_pending_output
2948 md_flush_pending_output ();
2949#endif
b99bd4ef 2950
c19d1205 2951 if (is_it_end_of_statement ())
b99bd4ef 2952 {
c19d1205
ZW
2953 demand_empty_rest_of_line ();
2954 return;
b99bd4ef
NC
2955 }
2956
c19d1205
ZW
2957#ifdef md_cons_align
2958 md_cons_align (nbytes);
2959#endif
b99bd4ef 2960
c19d1205
ZW
2961 mapping_state (MAP_DATA);
2962 do
b99bd4ef 2963 {
c19d1205
ZW
2964 int reloc;
2965 char *base = input_line_pointer;
b99bd4ef 2966
c19d1205 2967 expression (& exp);
b99bd4ef 2968
c19d1205
ZW
2969 if (exp.X_op != O_symbol)
2970 emit_expr (&exp, (unsigned int) nbytes);
2971 else
2972 {
2973 char *before_reloc = input_line_pointer;
2974 reloc = parse_reloc (&input_line_pointer);
2975 if (reloc == -1)
2976 {
2977 as_bad (_("unrecognized relocation suffix"));
2978 ignore_rest_of_line ();
2979 return;
2980 }
2981 else if (reloc == BFD_RELOC_UNUSED)
2982 emit_expr (&exp, (unsigned int) nbytes);
2983 else
2984 {
2985 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2986 int size = bfd_get_reloc_size (howto);
b99bd4ef 2987
2fc8bdac
ZW
2988 if (reloc == BFD_RELOC_ARM_PLT32)
2989 {
2990 as_bad (_("(plt) is only valid on branch targets"));
2991 reloc = BFD_RELOC_UNUSED;
2992 size = 0;
2993 }
2994
c19d1205 2995 if (size > nbytes)
2fc8bdac 2996 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2997 howto->name, nbytes);
2998 else
2999 {
3000 /* We've parsed an expression stopping at O_symbol.
3001 But there may be more expression left now that we
3002 have parsed the relocation marker. Parse it again.
3003 XXX Surely there is a cleaner way to do this. */
3004 char *p = input_line_pointer;
3005 int offset;
3006 char *save_buf = alloca (input_line_pointer - base);
3007 memcpy (save_buf, base, input_line_pointer - base);
3008 memmove (base + (input_line_pointer - before_reloc),
3009 base, before_reloc - base);
3010
3011 input_line_pointer = base + (input_line_pointer-before_reloc);
3012 expression (&exp);
3013 memcpy (base, save_buf, p - base);
3014
3015 offset = nbytes - size;
3016 p = frag_more ((int) nbytes);
3017 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3018 size, &exp, 0, reloc);
3019 }
3020 }
3021 }
b99bd4ef 3022 }
c19d1205 3023 while (*input_line_pointer++ == ',');
b99bd4ef 3024
c19d1205
ZW
3025 /* Put terminator back into stream. */
3026 input_line_pointer --;
3027 demand_empty_rest_of_line ();
b99bd4ef
NC
3028}
3029
b99bd4ef 3030
c19d1205 3031/* Parse a .rel31 directive. */
b99bd4ef 3032
c19d1205
ZW
3033static void
3034s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3035{
3036 expressionS exp;
3037 char *p;
3038 valueT highbit;
b99bd4ef 3039
c19d1205
ZW
3040 highbit = 0;
3041 if (*input_line_pointer == '1')
3042 highbit = 0x80000000;
3043 else if (*input_line_pointer != '0')
3044 as_bad (_("expected 0 or 1"));
b99bd4ef 3045
c19d1205
ZW
3046 input_line_pointer++;
3047 if (*input_line_pointer != ',')
3048 as_bad (_("missing comma"));
3049 input_line_pointer++;
b99bd4ef 3050
c19d1205
ZW
3051#ifdef md_flush_pending_output
3052 md_flush_pending_output ();
3053#endif
b99bd4ef 3054
c19d1205
ZW
3055#ifdef md_cons_align
3056 md_cons_align (4);
3057#endif
b99bd4ef 3058
c19d1205 3059 mapping_state (MAP_DATA);
b99bd4ef 3060
c19d1205 3061 expression (&exp);
b99bd4ef 3062
c19d1205
ZW
3063 p = frag_more (4);
3064 md_number_to_chars (p, highbit, 4);
3065 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3066 BFD_RELOC_ARM_PREL31);
b99bd4ef 3067
c19d1205 3068 demand_empty_rest_of_line ();
b99bd4ef
NC
3069}
3070
c19d1205 3071/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3072
c19d1205 3073/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3074
c19d1205
ZW
3075static void
3076s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3077{
3078 demand_empty_rest_of_line ();
3079 /* Mark the start of the function. */
3080 unwind.proc_start = expr_build_dot ();
b99bd4ef 3081
c19d1205
ZW
3082 /* Reset the rest of the unwind info. */
3083 unwind.opcode_count = 0;
3084 unwind.table_entry = NULL;
3085 unwind.personality_routine = NULL;
3086 unwind.personality_index = -1;
3087 unwind.frame_size = 0;
3088 unwind.fp_offset = 0;
3089 unwind.fp_reg = 13;
3090 unwind.fp_used = 0;
3091 unwind.sp_restored = 0;
3092}
b99bd4ef 3093
b99bd4ef 3094
c19d1205
ZW
3095/* Parse a handlerdata directive. Creates the exception handling table entry
3096 for the function. */
b99bd4ef 3097
c19d1205
ZW
3098static void
3099s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3100{
3101 demand_empty_rest_of_line ();
3102 if (unwind.table_entry)
6decc662 3103 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3104
c19d1205
ZW
3105 create_unwind_entry (1);
3106}
a737bd4d 3107
c19d1205 3108/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3109
c19d1205
ZW
3110static void
3111s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3112{
3113 long where;
3114 char *ptr;
3115 valueT val;
f02232aa 3116
c19d1205 3117 demand_empty_rest_of_line ();
f02232aa 3118
c19d1205
ZW
3119 /* Add eh table entry. */
3120 if (unwind.table_entry == NULL)
3121 val = create_unwind_entry (0);
3122 else
3123 val = 0;
f02232aa 3124
c19d1205
ZW
3125 /* Add index table entry. This is two words. */
3126 start_unwind_section (unwind.saved_seg, 1);
3127 frag_align (2, 0, 0);
3128 record_alignment (now_seg, 2);
b99bd4ef 3129
c19d1205
ZW
3130 ptr = frag_more (8);
3131 where = frag_now_fix () - 8;
f02232aa 3132
c19d1205
ZW
3133 /* Self relative offset of the function start. */
3134 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3135 BFD_RELOC_ARM_PREL31);
f02232aa 3136
c19d1205
ZW
3137 /* Indicate dependency on EHABI-defined personality routines to the
3138 linker, if it hasn't been done already. */
3139 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3140 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3141 {
5f4273c7
NC
3142 static const char *const name[] =
3143 {
3144 "__aeabi_unwind_cpp_pr0",
3145 "__aeabi_unwind_cpp_pr1",
3146 "__aeabi_unwind_cpp_pr2"
3147 };
c19d1205
ZW
3148 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3149 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3150 marked_pr_dependency |= 1 << unwind.personality_index;
3151 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3152 = marked_pr_dependency;
3153 }
f02232aa 3154
c19d1205
ZW
3155 if (val)
3156 /* Inline exception table entry. */
3157 md_number_to_chars (ptr + 4, val, 4);
3158 else
3159 /* Self relative offset of the table entry. */
3160 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3161 BFD_RELOC_ARM_PREL31);
f02232aa 3162
c19d1205
ZW
3163 /* Restore the original section. */
3164 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3165}
f02232aa 3166
f02232aa 3167
c19d1205 3168/* Parse an unwind_cantunwind directive. */
b99bd4ef 3169
c19d1205
ZW
3170static void
3171s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3172{
3173 demand_empty_rest_of_line ();
3174 if (unwind.personality_routine || unwind.personality_index != -1)
3175 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3176
c19d1205
ZW
3177 unwind.personality_index = -2;
3178}
b99bd4ef 3179
b99bd4ef 3180
c19d1205 3181/* Parse a personalityindex directive. */
b99bd4ef 3182
c19d1205
ZW
3183static void
3184s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3185{
3186 expressionS exp;
b99bd4ef 3187
c19d1205
ZW
3188 if (unwind.personality_routine || unwind.personality_index != -1)
3189 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3190
c19d1205 3191 expression (&exp);
b99bd4ef 3192
c19d1205
ZW
3193 if (exp.X_op != O_constant
3194 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3195 {
c19d1205
ZW
3196 as_bad (_("bad personality routine number"));
3197 ignore_rest_of_line ();
3198 return;
b99bd4ef
NC
3199 }
3200
c19d1205 3201 unwind.personality_index = exp.X_add_number;
b99bd4ef 3202
c19d1205
ZW
3203 demand_empty_rest_of_line ();
3204}
e16bb312 3205
e16bb312 3206
c19d1205 3207/* Parse a personality directive. */
e16bb312 3208
c19d1205
ZW
3209static void
3210s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3211{
3212 char *name, *p, c;
a737bd4d 3213
c19d1205
ZW
3214 if (unwind.personality_routine || unwind.personality_index != -1)
3215 as_bad (_("duplicate .personality directive"));
a737bd4d 3216
c19d1205
ZW
3217 name = input_line_pointer;
3218 c = get_symbol_end ();
3219 p = input_line_pointer;
3220 unwind.personality_routine = symbol_find_or_make (name);
3221 *p = c;
3222 demand_empty_rest_of_line ();
3223}
e16bb312 3224
e16bb312 3225
c19d1205 3226/* Parse a directive saving core registers. */
e16bb312 3227
c19d1205
ZW
3228static void
3229s_arm_unwind_save_core (void)
e16bb312 3230{
c19d1205
ZW
3231 valueT op;
3232 long range;
3233 int n;
e16bb312 3234
c19d1205
ZW
3235 range = parse_reg_list (&input_line_pointer);
3236 if (range == FAIL)
e16bb312 3237 {
c19d1205
ZW
3238 as_bad (_("expected register list"));
3239 ignore_rest_of_line ();
3240 return;
3241 }
e16bb312 3242
c19d1205 3243 demand_empty_rest_of_line ();
e16bb312 3244
c19d1205
ZW
3245 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3246 into .unwind_save {..., sp...}. We aren't bothered about the value of
3247 ip because it is clobbered by calls. */
3248 if (unwind.sp_restored && unwind.fp_reg == 12
3249 && (range & 0x3000) == 0x1000)
3250 {
3251 unwind.opcode_count--;
3252 unwind.sp_restored = 0;
3253 range = (range | 0x2000) & ~0x1000;
3254 unwind.pending_offset = 0;
3255 }
e16bb312 3256
01ae4198
DJ
3257 /* Pop r4-r15. */
3258 if (range & 0xfff0)
c19d1205 3259 {
01ae4198
DJ
3260 /* See if we can use the short opcodes. These pop a block of up to 8
3261 registers starting with r4, plus maybe r14. */
3262 for (n = 0; n < 8; n++)
3263 {
3264 /* Break at the first non-saved register. */
3265 if ((range & (1 << (n + 4))) == 0)
3266 break;
3267 }
3268 /* See if there are any other bits set. */
3269 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3270 {
3271 /* Use the long form. */
3272 op = 0x8000 | ((range >> 4) & 0xfff);
3273 add_unwind_opcode (op, 2);
3274 }
0dd132b6 3275 else
01ae4198
DJ
3276 {
3277 /* Use the short form. */
3278 if (range & 0x4000)
3279 op = 0xa8; /* Pop r14. */
3280 else
3281 op = 0xa0; /* Do not pop r14. */
3282 op |= (n - 1);
3283 add_unwind_opcode (op, 1);
3284 }
c19d1205 3285 }
0dd132b6 3286
c19d1205
ZW
3287 /* Pop r0-r3. */
3288 if (range & 0xf)
3289 {
3290 op = 0xb100 | (range & 0xf);
3291 add_unwind_opcode (op, 2);
0dd132b6
NC
3292 }
3293
c19d1205
ZW
3294 /* Record the number of bytes pushed. */
3295 for (n = 0; n < 16; n++)
3296 {
3297 if (range & (1 << n))
3298 unwind.frame_size += 4;
3299 }
0dd132b6
NC
3300}
3301
c19d1205
ZW
3302
3303/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3304
3305static void
c19d1205 3306s_arm_unwind_save_fpa (int reg)
b99bd4ef 3307{
c19d1205
ZW
3308 expressionS exp;
3309 int num_regs;
3310 valueT op;
b99bd4ef 3311
c19d1205
ZW
3312 /* Get Number of registers to transfer. */
3313 if (skip_past_comma (&input_line_pointer) != FAIL)
3314 expression (&exp);
3315 else
3316 exp.X_op = O_illegal;
b99bd4ef 3317
c19d1205 3318 if (exp.X_op != O_constant)
b99bd4ef 3319 {
c19d1205
ZW
3320 as_bad (_("expected , <constant>"));
3321 ignore_rest_of_line ();
b99bd4ef
NC
3322 return;
3323 }
3324
c19d1205
ZW
3325 num_regs = exp.X_add_number;
3326
3327 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3328 {
c19d1205
ZW
3329 as_bad (_("number of registers must be in the range [1:4]"));
3330 ignore_rest_of_line ();
b99bd4ef
NC
3331 return;
3332 }
3333
c19d1205 3334 demand_empty_rest_of_line ();
b99bd4ef 3335
c19d1205
ZW
3336 if (reg == 4)
3337 {
3338 /* Short form. */
3339 op = 0xb4 | (num_regs - 1);
3340 add_unwind_opcode (op, 1);
3341 }
b99bd4ef
NC
3342 else
3343 {
c19d1205
ZW
3344 /* Long form. */
3345 op = 0xc800 | (reg << 4) | (num_regs - 1);
3346 add_unwind_opcode (op, 2);
b99bd4ef 3347 }
c19d1205 3348 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3349}
3350
c19d1205 3351
fa073d69
MS
3352/* Parse a directive saving VFP registers for ARMv6 and above. */
3353
3354static void
3355s_arm_unwind_save_vfp_armv6 (void)
3356{
3357 int count;
3358 unsigned int start;
3359 valueT op;
3360 int num_vfpv3_regs = 0;
3361 int num_regs_below_16;
3362
3363 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3364 if (count == FAIL)
3365 {
3366 as_bad (_("expected register list"));
3367 ignore_rest_of_line ();
3368 return;
3369 }
3370
3371 demand_empty_rest_of_line ();
3372
3373 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3374 than FSTMX/FLDMX-style ones). */
3375
3376 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3377 if (start >= 16)
3378 num_vfpv3_regs = count;
3379 else if (start + count > 16)
3380 num_vfpv3_regs = start + count - 16;
3381
3382 if (num_vfpv3_regs > 0)
3383 {
3384 int start_offset = start > 16 ? start - 16 : 0;
3385 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3386 add_unwind_opcode (op, 2);
3387 }
3388
3389 /* Generate opcode for registers numbered in the range 0 .. 15. */
3390 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3391 assert (num_regs_below_16 + num_vfpv3_regs == count);
3392 if (num_regs_below_16 > 0)
3393 {
3394 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3395 add_unwind_opcode (op, 2);
3396 }
3397
3398 unwind.frame_size += count * 8;
3399}
3400
3401
3402/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3403
3404static void
c19d1205 3405s_arm_unwind_save_vfp (void)
b99bd4ef 3406{
c19d1205 3407 int count;
ca3f61f7 3408 unsigned int reg;
c19d1205 3409 valueT op;
b99bd4ef 3410
5287ad62 3411 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3412 if (count == FAIL)
b99bd4ef 3413 {
c19d1205
ZW
3414 as_bad (_("expected register list"));
3415 ignore_rest_of_line ();
b99bd4ef
NC
3416 return;
3417 }
3418
c19d1205 3419 demand_empty_rest_of_line ();
b99bd4ef 3420
c19d1205 3421 if (reg == 8)
b99bd4ef 3422 {
c19d1205
ZW
3423 /* Short form. */
3424 op = 0xb8 | (count - 1);
3425 add_unwind_opcode (op, 1);
b99bd4ef 3426 }
c19d1205 3427 else
b99bd4ef 3428 {
c19d1205
ZW
3429 /* Long form. */
3430 op = 0xb300 | (reg << 4) | (count - 1);
3431 add_unwind_opcode (op, 2);
b99bd4ef 3432 }
c19d1205
ZW
3433 unwind.frame_size += count * 8 + 4;
3434}
b99bd4ef 3435
b99bd4ef 3436
c19d1205
ZW
3437/* Parse a directive saving iWMMXt data registers. */
3438
3439static void
3440s_arm_unwind_save_mmxwr (void)
3441{
3442 int reg;
3443 int hi_reg;
3444 int i;
3445 unsigned mask = 0;
3446 valueT op;
b99bd4ef 3447
c19d1205
ZW
3448 if (*input_line_pointer == '{')
3449 input_line_pointer++;
b99bd4ef 3450
c19d1205 3451 do
b99bd4ef 3452 {
dcbf9037 3453 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3454
c19d1205 3455 if (reg == FAIL)
b99bd4ef 3456 {
c19d1205
ZW
3457 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3458 goto error;
b99bd4ef
NC
3459 }
3460
c19d1205
ZW
3461 if (mask >> reg)
3462 as_tsktsk (_("register list not in ascending order"));
3463 mask |= 1 << reg;
b99bd4ef 3464
c19d1205
ZW
3465 if (*input_line_pointer == '-')
3466 {
3467 input_line_pointer++;
dcbf9037 3468 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3469 if (hi_reg == FAIL)
3470 {
3471 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3472 goto error;
3473 }
3474 else if (reg >= hi_reg)
3475 {
3476 as_bad (_("bad register range"));
3477 goto error;
3478 }
3479 for (; reg < hi_reg; reg++)
3480 mask |= 1 << reg;
3481 }
3482 }
3483 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3484
c19d1205
ZW
3485 if (*input_line_pointer == '}')
3486 input_line_pointer++;
b99bd4ef 3487
c19d1205 3488 demand_empty_rest_of_line ();
b99bd4ef 3489
708587a4 3490 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3491 the list. */
3492 flush_pending_unwind ();
b99bd4ef 3493
c19d1205 3494 for (i = 0; i < 16; i++)
b99bd4ef 3495 {
c19d1205
ZW
3496 if (mask & (1 << i))
3497 unwind.frame_size += 8;
b99bd4ef
NC
3498 }
3499
c19d1205
ZW
3500 /* Attempt to combine with a previous opcode. We do this because gcc
3501 likes to output separate unwind directives for a single block of
3502 registers. */
3503 if (unwind.opcode_count > 0)
b99bd4ef 3504 {
c19d1205
ZW
3505 i = unwind.opcodes[unwind.opcode_count - 1];
3506 if ((i & 0xf8) == 0xc0)
3507 {
3508 i &= 7;
3509 /* Only merge if the blocks are contiguous. */
3510 if (i < 6)
3511 {
3512 if ((mask & 0xfe00) == (1 << 9))
3513 {
3514 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3515 unwind.opcode_count--;
3516 }
3517 }
3518 else if (i == 6 && unwind.opcode_count >= 2)
3519 {
3520 i = unwind.opcodes[unwind.opcode_count - 2];
3521 reg = i >> 4;
3522 i &= 0xf;
b99bd4ef 3523
c19d1205
ZW
3524 op = 0xffff << (reg - 1);
3525 if (reg > 0
87a1fd79 3526 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3527 {
3528 op = (1 << (reg + i + 1)) - 1;
3529 op &= ~((1 << reg) - 1);
3530 mask |= op;
3531 unwind.opcode_count -= 2;
3532 }
3533 }
3534 }
b99bd4ef
NC
3535 }
3536
c19d1205
ZW
3537 hi_reg = 15;
3538 /* We want to generate opcodes in the order the registers have been
3539 saved, ie. descending order. */
3540 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3541 {
c19d1205
ZW
3542 /* Save registers in blocks. */
3543 if (reg < 0
3544 || !(mask & (1 << reg)))
3545 {
3546 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3547 preceding block. */
c19d1205
ZW
3548 if (reg != hi_reg)
3549 {
3550 if (reg == 9)
3551 {
3552 /* Short form. */
3553 op = 0xc0 | (hi_reg - 10);
3554 add_unwind_opcode (op, 1);
3555 }
3556 else
3557 {
3558 /* Long form. */
3559 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3560 add_unwind_opcode (op, 2);
3561 }
3562 }
3563 hi_reg = reg - 1;
3564 }
b99bd4ef
NC
3565 }
3566
c19d1205
ZW
3567 return;
3568error:
3569 ignore_rest_of_line ();
b99bd4ef
NC
3570}
3571
3572static void
c19d1205 3573s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3574{
c19d1205
ZW
3575 int reg;
3576 int hi_reg;
3577 unsigned mask = 0;
3578 valueT op;
b99bd4ef 3579
c19d1205
ZW
3580 if (*input_line_pointer == '{')
3581 input_line_pointer++;
b99bd4ef 3582
c19d1205 3583 do
b99bd4ef 3584 {
dcbf9037 3585 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3586
c19d1205
ZW
3587 if (reg == FAIL)
3588 {
3589 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3590 goto error;
3591 }
b99bd4ef 3592
c19d1205
ZW
3593 reg -= 8;
3594 if (mask >> reg)
3595 as_tsktsk (_("register list not in ascending order"));
3596 mask |= 1 << reg;
b99bd4ef 3597
c19d1205
ZW
3598 if (*input_line_pointer == '-')
3599 {
3600 input_line_pointer++;
dcbf9037 3601 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3602 if (hi_reg == FAIL)
3603 {
3604 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3605 goto error;
3606 }
3607 else if (reg >= hi_reg)
3608 {
3609 as_bad (_("bad register range"));
3610 goto error;
3611 }
3612 for (; reg < hi_reg; reg++)
3613 mask |= 1 << reg;
3614 }
b99bd4ef 3615 }
c19d1205 3616 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3617
c19d1205
ZW
3618 if (*input_line_pointer == '}')
3619 input_line_pointer++;
b99bd4ef 3620
c19d1205
ZW
3621 demand_empty_rest_of_line ();
3622
708587a4 3623 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3624 the list. */
3625 flush_pending_unwind ();
b99bd4ef 3626
c19d1205 3627 for (reg = 0; reg < 16; reg++)
b99bd4ef 3628 {
c19d1205
ZW
3629 if (mask & (1 << reg))
3630 unwind.frame_size += 4;
b99bd4ef 3631 }
c19d1205
ZW
3632 op = 0xc700 | mask;
3633 add_unwind_opcode (op, 2);
3634 return;
3635error:
3636 ignore_rest_of_line ();
b99bd4ef
NC
3637}
3638
c19d1205 3639
fa073d69
MS
3640/* Parse an unwind_save directive.
3641 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3642
b99bd4ef 3643static void
fa073d69 3644s_arm_unwind_save (int arch_v6)
b99bd4ef 3645{
c19d1205
ZW
3646 char *peek;
3647 struct reg_entry *reg;
3648 bfd_boolean had_brace = FALSE;
b99bd4ef 3649
c19d1205
ZW
3650 /* Figure out what sort of save we have. */
3651 peek = input_line_pointer;
b99bd4ef 3652
c19d1205 3653 if (*peek == '{')
b99bd4ef 3654 {
c19d1205
ZW
3655 had_brace = TRUE;
3656 peek++;
b99bd4ef
NC
3657 }
3658
c19d1205 3659 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3660
c19d1205 3661 if (!reg)
b99bd4ef 3662 {
c19d1205
ZW
3663 as_bad (_("register expected"));
3664 ignore_rest_of_line ();
b99bd4ef
NC
3665 return;
3666 }
3667
c19d1205 3668 switch (reg->type)
b99bd4ef 3669 {
c19d1205
ZW
3670 case REG_TYPE_FN:
3671 if (had_brace)
3672 {
3673 as_bad (_("FPA .unwind_save does not take a register list"));
3674 ignore_rest_of_line ();
3675 return;
3676 }
93ac2687 3677 input_line_pointer = peek;
c19d1205 3678 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3679 return;
c19d1205
ZW
3680
3681 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3682 case REG_TYPE_VFD:
3683 if (arch_v6)
3684 s_arm_unwind_save_vfp_armv6 ();
3685 else
3686 s_arm_unwind_save_vfp ();
3687 return;
c19d1205
ZW
3688 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3689 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3690
3691 default:
3692 as_bad (_(".unwind_save does not support this kind of register"));
3693 ignore_rest_of_line ();
b99bd4ef 3694 }
c19d1205 3695}
b99bd4ef 3696
b99bd4ef 3697
c19d1205
ZW
3698/* Parse an unwind_movsp directive. */
3699
3700static void
3701s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3702{
3703 int reg;
3704 valueT op;
4fa3602b 3705 int offset;
c19d1205 3706
dcbf9037 3707 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3708 if (reg == FAIL)
b99bd4ef 3709 {
c19d1205
ZW
3710 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3711 ignore_rest_of_line ();
b99bd4ef
NC
3712 return;
3713 }
4fa3602b
PB
3714
3715 /* Optional constant. */
3716 if (skip_past_comma (&input_line_pointer) != FAIL)
3717 {
3718 if (immediate_for_directive (&offset) == FAIL)
3719 return;
3720 }
3721 else
3722 offset = 0;
3723
c19d1205 3724 demand_empty_rest_of_line ();
b99bd4ef 3725
c19d1205 3726 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3727 {
c19d1205 3728 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3729 return;
3730 }
3731
c19d1205
ZW
3732 if (unwind.fp_reg != REG_SP)
3733 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3734
c19d1205
ZW
3735 /* Generate opcode to restore the value. */
3736 op = 0x90 | reg;
3737 add_unwind_opcode (op, 1);
3738
3739 /* Record the information for later. */
3740 unwind.fp_reg = reg;
4fa3602b 3741 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3742 unwind.sp_restored = 1;
b05fe5cf
ZW
3743}
3744
c19d1205
ZW
3745/* Parse an unwind_pad directive. */
3746
b05fe5cf 3747static void
c19d1205 3748s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3749{
c19d1205 3750 int offset;
b05fe5cf 3751
c19d1205
ZW
3752 if (immediate_for_directive (&offset) == FAIL)
3753 return;
b99bd4ef 3754
c19d1205
ZW
3755 if (offset & 3)
3756 {
3757 as_bad (_("stack increment must be multiple of 4"));
3758 ignore_rest_of_line ();
3759 return;
3760 }
b99bd4ef 3761
c19d1205
ZW
3762 /* Don't generate any opcodes, just record the details for later. */
3763 unwind.frame_size += offset;
3764 unwind.pending_offset += offset;
3765
3766 demand_empty_rest_of_line ();
3767}
3768
3769/* Parse an unwind_setfp directive. */
3770
3771static void
3772s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3773{
c19d1205
ZW
3774 int sp_reg;
3775 int fp_reg;
3776 int offset;
3777
dcbf9037 3778 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3779 if (skip_past_comma (&input_line_pointer) == FAIL)
3780 sp_reg = FAIL;
3781 else
dcbf9037 3782 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3783
c19d1205
ZW
3784 if (fp_reg == FAIL || sp_reg == FAIL)
3785 {
3786 as_bad (_("expected <reg>, <reg>"));
3787 ignore_rest_of_line ();
3788 return;
3789 }
b99bd4ef 3790
c19d1205
ZW
3791 /* Optional constant. */
3792 if (skip_past_comma (&input_line_pointer) != FAIL)
3793 {
3794 if (immediate_for_directive (&offset) == FAIL)
3795 return;
3796 }
3797 else
3798 offset = 0;
a737bd4d 3799
c19d1205 3800 demand_empty_rest_of_line ();
a737bd4d 3801
c19d1205 3802 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3803 {
c19d1205
ZW
3804 as_bad (_("register must be either sp or set by a previous"
3805 "unwind_movsp directive"));
3806 return;
a737bd4d
NC
3807 }
3808
c19d1205
ZW
3809 /* Don't generate any opcodes, just record the information for later. */
3810 unwind.fp_reg = fp_reg;
3811 unwind.fp_used = 1;
3812 if (sp_reg == 13)
3813 unwind.fp_offset = unwind.frame_size - offset;
3814 else
3815 unwind.fp_offset -= offset;
a737bd4d
NC
3816}
3817
c19d1205
ZW
3818/* Parse an unwind_raw directive. */
3819
3820static void
3821s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3822{
c19d1205 3823 expressionS exp;
708587a4 3824 /* This is an arbitrary limit. */
c19d1205
ZW
3825 unsigned char op[16];
3826 int count;
a737bd4d 3827
c19d1205
ZW
3828 expression (&exp);
3829 if (exp.X_op == O_constant
3830 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3831 {
c19d1205
ZW
3832 unwind.frame_size += exp.X_add_number;
3833 expression (&exp);
3834 }
3835 else
3836 exp.X_op = O_illegal;
a737bd4d 3837
c19d1205
ZW
3838 if (exp.X_op != O_constant)
3839 {
3840 as_bad (_("expected <offset>, <opcode>"));
3841 ignore_rest_of_line ();
3842 return;
3843 }
a737bd4d 3844
c19d1205 3845 count = 0;
a737bd4d 3846
c19d1205
ZW
3847 /* Parse the opcode. */
3848 for (;;)
3849 {
3850 if (count >= 16)
3851 {
3852 as_bad (_("unwind opcode too long"));
3853 ignore_rest_of_line ();
a737bd4d 3854 }
c19d1205 3855 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3856 {
c19d1205
ZW
3857 as_bad (_("invalid unwind opcode"));
3858 ignore_rest_of_line ();
3859 return;
a737bd4d 3860 }
c19d1205 3861 op[count++] = exp.X_add_number;
a737bd4d 3862
c19d1205
ZW
3863 /* Parse the next byte. */
3864 if (skip_past_comma (&input_line_pointer) == FAIL)
3865 break;
a737bd4d 3866
c19d1205
ZW
3867 expression (&exp);
3868 }
b99bd4ef 3869
c19d1205
ZW
3870 /* Add the opcode bytes in reverse order. */
3871 while (count--)
3872 add_unwind_opcode (op[count], 1);
b99bd4ef 3873
c19d1205 3874 demand_empty_rest_of_line ();
b99bd4ef 3875}
ee065d83
PB
3876
3877
3878/* Parse a .eabi_attribute directive. */
3879
3880static void
3881s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3882{
104d59d1 3883 s_vendor_attribute (OBJ_ATTR_PROC);
ee065d83 3884}
8463be01 3885#endif /* OBJ_ELF */
ee065d83
PB
3886
3887static void s_arm_arch (int);
7a1d4c38 3888static void s_arm_object_arch (int);
ee065d83
PB
3889static void s_arm_cpu (int);
3890static void s_arm_fpu (int);
b99bd4ef 3891
f0927246
NC
3892#ifdef TE_PE
3893
3894static void
5f4273c7 3895pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
3896{
3897 expressionS exp;
3898
3899 do
3900 {
3901 expression (&exp);
3902 if (exp.X_op == O_symbol)
3903 exp.X_op = O_secrel;
3904
3905 emit_expr (&exp, 4);
3906 }
3907 while (*input_line_pointer++ == ',');
3908
3909 input_line_pointer--;
3910 demand_empty_rest_of_line ();
3911}
3912#endif /* TE_PE */
3913
c19d1205
ZW
3914/* This table describes all the machine specific pseudo-ops the assembler
3915 has to support. The fields are:
3916 pseudo-op name without dot
3917 function to call to execute this pseudo-op
3918 Integer arg to pass to the function. */
b99bd4ef 3919
c19d1205 3920const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3921{
c19d1205
ZW
3922 /* Never called because '.req' does not start a line. */
3923 { "req", s_req, 0 },
dcbf9037
JB
3924 /* Following two are likewise never called. */
3925 { "dn", s_dn, 0 },
3926 { "qn", s_qn, 0 },
c19d1205
ZW
3927 { "unreq", s_unreq, 0 },
3928 { "bss", s_bss, 0 },
3929 { "align", s_align, 0 },
3930 { "arm", s_arm, 0 },
3931 { "thumb", s_thumb, 0 },
3932 { "code", s_code, 0 },
3933 { "force_thumb", s_force_thumb, 0 },
3934 { "thumb_func", s_thumb_func, 0 },
3935 { "thumb_set", s_thumb_set, 0 },
3936 { "even", s_even, 0 },
3937 { "ltorg", s_ltorg, 0 },
3938 { "pool", s_ltorg, 0 },
3939 { "syntax", s_syntax, 0 },
8463be01
PB
3940 { "cpu", s_arm_cpu, 0 },
3941 { "arch", s_arm_arch, 0 },
7a1d4c38 3942 { "object_arch", s_arm_object_arch, 0 },
8463be01 3943 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3944#ifdef OBJ_ELF
3945 { "word", s_arm_elf_cons, 4 },
3946 { "long", s_arm_elf_cons, 4 },
3947 { "rel31", s_arm_rel31, 0 },
3948 { "fnstart", s_arm_unwind_fnstart, 0 },
3949 { "fnend", s_arm_unwind_fnend, 0 },
3950 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3951 { "personality", s_arm_unwind_personality, 0 },
3952 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3953 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3954 { "save", s_arm_unwind_save, 0 },
fa073d69 3955 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3956 { "movsp", s_arm_unwind_movsp, 0 },
3957 { "pad", s_arm_unwind_pad, 0 },
3958 { "setfp", s_arm_unwind_setfp, 0 },
3959 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3960 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3961#else
3962 { "word", cons, 4},
f0927246
NC
3963
3964 /* These are used for dwarf. */
3965 {"2byte", cons, 2},
3966 {"4byte", cons, 4},
3967 {"8byte", cons, 8},
3968 /* These are used for dwarf2. */
3969 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3970 { "loc", dwarf2_directive_loc, 0 },
3971 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3972#endif
3973 { "extend", float_cons, 'x' },
3974 { "ldouble", float_cons, 'x' },
3975 { "packed", float_cons, 'p' },
f0927246
NC
3976#ifdef TE_PE
3977 {"secrel32", pe_directive_secrel, 0},
3978#endif
c19d1205
ZW
3979 { 0, 0, 0 }
3980};
3981\f
3982/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3983
c19d1205
ZW
3984/* Generic immediate-value read function for use in insn parsing.
3985 STR points to the beginning of the immediate (the leading #);
3986 VAL receives the value; if the value is outside [MIN, MAX]
3987 issue an error. PREFIX_OPT is true if the immediate prefix is
3988 optional. */
b99bd4ef 3989
c19d1205
ZW
3990static int
3991parse_immediate (char **str, int *val, int min, int max,
3992 bfd_boolean prefix_opt)
3993{
3994 expressionS exp;
3995 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3996 if (exp.X_op != O_constant)
b99bd4ef 3997 {
c19d1205
ZW
3998 inst.error = _("constant expression required");
3999 return FAIL;
4000 }
b99bd4ef 4001
c19d1205
ZW
4002 if (exp.X_add_number < min || exp.X_add_number > max)
4003 {
4004 inst.error = _("immediate value out of range");
4005 return FAIL;
4006 }
b99bd4ef 4007
c19d1205
ZW
4008 *val = exp.X_add_number;
4009 return SUCCESS;
4010}
b99bd4ef 4011
5287ad62 4012/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4013 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4014 instructions. Puts the result directly in inst.operands[i]. */
4015
4016static int
4017parse_big_immediate (char **str, int i)
4018{
4019 expressionS exp;
4020 char *ptr = *str;
4021
4022 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4023
4024 if (exp.X_op == O_constant)
036dc3f7
PB
4025 {
4026 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4027 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4028 O_constant. We have to be careful not to break compilation for
4029 32-bit X_add_number, though. */
4030 if ((exp.X_add_number & ~0xffffffffl) != 0)
4031 {
4032 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4033 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4034 inst.operands[i].regisimm = 1;
4035 }
4036 }
5287ad62
JB
4037 else if (exp.X_op == O_big
4038 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4039 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4040 {
4041 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4042 /* Bignums have their least significant bits in
4043 generic_bignum[0]. Make sure we put 32 bits in imm and
4044 32 bits in reg, in a (hopefully) portable way. */
4045 assert (parts != 0);
4046 inst.operands[i].imm = 0;
4047 for (j = 0; j < parts; j++, idx++)
4048 inst.operands[i].imm |= generic_bignum[idx]
4049 << (LITTLENUM_NUMBER_OF_BITS * j);
4050 inst.operands[i].reg = 0;
4051 for (j = 0; j < parts; j++, idx++)
4052 inst.operands[i].reg |= generic_bignum[idx]
4053 << (LITTLENUM_NUMBER_OF_BITS * j);
4054 inst.operands[i].regisimm = 1;
4055 }
4056 else
4057 return FAIL;
5f4273c7 4058
5287ad62
JB
4059 *str = ptr;
4060
4061 return SUCCESS;
4062}
4063
c19d1205
ZW
4064/* Returns the pseudo-register number of an FPA immediate constant,
4065 or FAIL if there isn't a valid constant here. */
b99bd4ef 4066
c19d1205
ZW
4067static int
4068parse_fpa_immediate (char ** str)
4069{
4070 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4071 char * save_in;
4072 expressionS exp;
4073 int i;
4074 int j;
b99bd4ef 4075
c19d1205
ZW
4076 /* First try and match exact strings, this is to guarantee
4077 that some formats will work even for cross assembly. */
b99bd4ef 4078
c19d1205
ZW
4079 for (i = 0; fp_const[i]; i++)
4080 {
4081 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4082 {
c19d1205 4083 char *start = *str;
b99bd4ef 4084
c19d1205
ZW
4085 *str += strlen (fp_const[i]);
4086 if (is_end_of_line[(unsigned char) **str])
4087 return i + 8;
4088 *str = start;
4089 }
4090 }
b99bd4ef 4091
c19d1205
ZW
4092 /* Just because we didn't get a match doesn't mean that the constant
4093 isn't valid, just that it is in a format that we don't
4094 automatically recognize. Try parsing it with the standard
4095 expression routines. */
b99bd4ef 4096
c19d1205 4097 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4098
c19d1205
ZW
4099 /* Look for a raw floating point number. */
4100 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4101 && is_end_of_line[(unsigned char) *save_in])
4102 {
4103 for (i = 0; i < NUM_FLOAT_VALS; i++)
4104 {
4105 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4106 {
c19d1205
ZW
4107 if (words[j] != fp_values[i][j])
4108 break;
b99bd4ef
NC
4109 }
4110
c19d1205 4111 if (j == MAX_LITTLENUMS)
b99bd4ef 4112 {
c19d1205
ZW
4113 *str = save_in;
4114 return i + 8;
b99bd4ef
NC
4115 }
4116 }
4117 }
b99bd4ef 4118
c19d1205
ZW
4119 /* Try and parse a more complex expression, this will probably fail
4120 unless the code uses a floating point prefix (eg "0f"). */
4121 save_in = input_line_pointer;
4122 input_line_pointer = *str;
4123 if (expression (&exp) == absolute_section
4124 && exp.X_op == O_big
4125 && exp.X_add_number < 0)
4126 {
4127 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4128 Ditto for 15. */
4129 if (gen_to_words (words, 5, (long) 15) == 0)
4130 {
4131 for (i = 0; i < NUM_FLOAT_VALS; i++)
4132 {
4133 for (j = 0; j < MAX_LITTLENUMS; j++)
4134 {
4135 if (words[j] != fp_values[i][j])
4136 break;
4137 }
b99bd4ef 4138
c19d1205
ZW
4139 if (j == MAX_LITTLENUMS)
4140 {
4141 *str = input_line_pointer;
4142 input_line_pointer = save_in;
4143 return i + 8;
4144 }
4145 }
4146 }
b99bd4ef
NC
4147 }
4148
c19d1205
ZW
4149 *str = input_line_pointer;
4150 input_line_pointer = save_in;
4151 inst.error = _("invalid FPA immediate expression");
4152 return FAIL;
b99bd4ef
NC
4153}
4154
136da414
JB
4155/* Returns 1 if a number has "quarter-precision" float format
4156 0baBbbbbbc defgh000 00000000 00000000. */
4157
4158static int
4159is_quarter_float (unsigned imm)
4160{
4161 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4162 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4163}
4164
4165/* Parse an 8-bit "quarter-precision" floating point number of the form:
4166 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4167 The zero and minus-zero cases need special handling, since they can't be
4168 encoded in the "quarter-precision" float format, but can nonetheless be
4169 loaded as integer constants. */
136da414
JB
4170
4171static unsigned
4172parse_qfloat_immediate (char **ccp, int *immed)
4173{
4174 char *str = *ccp;
c96612cc 4175 char *fpnum;
136da414 4176 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4177 int found_fpchar = 0;
5f4273c7 4178
136da414 4179 skip_past_char (&str, '#');
5f4273c7 4180
c96612cc
JB
4181 /* We must not accidentally parse an integer as a floating-point number. Make
4182 sure that the value we parse is not an integer by checking for special
4183 characters '.' or 'e'.
4184 FIXME: This is a horrible hack, but doing better is tricky because type
4185 information isn't in a very usable state at parse time. */
4186 fpnum = str;
4187 skip_whitespace (fpnum);
4188
4189 if (strncmp (fpnum, "0x", 2) == 0)
4190 return FAIL;
4191 else
4192 {
4193 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4194 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4195 {
4196 found_fpchar = 1;
4197 break;
4198 }
4199
4200 if (!found_fpchar)
4201 return FAIL;
4202 }
5f4273c7 4203
136da414
JB
4204 if ((str = atof_ieee (str, 's', words)) != NULL)
4205 {
4206 unsigned fpword = 0;
4207 int i;
5f4273c7 4208
136da414
JB
4209 /* Our FP word must be 32 bits (single-precision FP). */
4210 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4211 {
4212 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4213 fpword |= words[i];
4214 }
5f4273c7 4215
c96612cc 4216 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4217 *immed = fpword;
4218 else
4219 return FAIL;
4220
4221 *ccp = str;
5f4273c7 4222
136da414
JB
4223 return SUCCESS;
4224 }
5f4273c7 4225
136da414
JB
4226 return FAIL;
4227}
4228
c19d1205
ZW
4229/* Shift operands. */
4230enum shift_kind
b99bd4ef 4231{
c19d1205
ZW
4232 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4233};
b99bd4ef 4234
c19d1205
ZW
4235struct asm_shift_name
4236{
4237 const char *name;
4238 enum shift_kind kind;
4239};
b99bd4ef 4240
c19d1205
ZW
4241/* Third argument to parse_shift. */
4242enum parse_shift_mode
4243{
4244 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4245 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4246 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4247 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4248 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4249};
b99bd4ef 4250
c19d1205
ZW
4251/* Parse a <shift> specifier on an ARM data processing instruction.
4252 This has three forms:
b99bd4ef 4253
c19d1205
ZW
4254 (LSL|LSR|ASL|ASR|ROR) Rs
4255 (LSL|LSR|ASL|ASR|ROR) #imm
4256 RRX
b99bd4ef 4257
c19d1205
ZW
4258 Note that ASL is assimilated to LSL in the instruction encoding, and
4259 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4260
c19d1205
ZW
4261static int
4262parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4263{
c19d1205
ZW
4264 const struct asm_shift_name *shift_name;
4265 enum shift_kind shift;
4266 char *s = *str;
4267 char *p = s;
4268 int reg;
b99bd4ef 4269
c19d1205
ZW
4270 for (p = *str; ISALPHA (*p); p++)
4271 ;
b99bd4ef 4272
c19d1205 4273 if (p == *str)
b99bd4ef 4274 {
c19d1205
ZW
4275 inst.error = _("shift expression expected");
4276 return FAIL;
b99bd4ef
NC
4277 }
4278
c19d1205
ZW
4279 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4280
4281 if (shift_name == NULL)
b99bd4ef 4282 {
c19d1205
ZW
4283 inst.error = _("shift expression expected");
4284 return FAIL;
b99bd4ef
NC
4285 }
4286
c19d1205 4287 shift = shift_name->kind;
b99bd4ef 4288
c19d1205
ZW
4289 switch (mode)
4290 {
4291 case NO_SHIFT_RESTRICT:
4292 case SHIFT_IMMEDIATE: break;
b99bd4ef 4293
c19d1205
ZW
4294 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4295 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4296 {
4297 inst.error = _("'LSL' or 'ASR' required");
4298 return FAIL;
4299 }
4300 break;
b99bd4ef 4301
c19d1205
ZW
4302 case SHIFT_LSL_IMMEDIATE:
4303 if (shift != SHIFT_LSL)
4304 {
4305 inst.error = _("'LSL' required");
4306 return FAIL;
4307 }
4308 break;
b99bd4ef 4309
c19d1205
ZW
4310 case SHIFT_ASR_IMMEDIATE:
4311 if (shift != SHIFT_ASR)
4312 {
4313 inst.error = _("'ASR' required");
4314 return FAIL;
4315 }
4316 break;
b99bd4ef 4317
c19d1205
ZW
4318 default: abort ();
4319 }
b99bd4ef 4320
c19d1205
ZW
4321 if (shift != SHIFT_RRX)
4322 {
4323 /* Whitespace can appear here if the next thing is a bare digit. */
4324 skip_whitespace (p);
b99bd4ef 4325
c19d1205 4326 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4327 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4328 {
4329 inst.operands[i].imm = reg;
4330 inst.operands[i].immisreg = 1;
4331 }
4332 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4333 return FAIL;
4334 }
4335 inst.operands[i].shift_kind = shift;
4336 inst.operands[i].shifted = 1;
4337 *str = p;
4338 return SUCCESS;
b99bd4ef
NC
4339}
4340
c19d1205 4341/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4342
c19d1205
ZW
4343 #<immediate>
4344 #<immediate>, <rotate>
4345 <Rm>
4346 <Rm>, <shift>
b99bd4ef 4347
c19d1205
ZW
4348 where <shift> is defined by parse_shift above, and <rotate> is a
4349 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4350 is deferred to md_apply_fix. */
b99bd4ef 4351
c19d1205
ZW
4352static int
4353parse_shifter_operand (char **str, int i)
4354{
4355 int value;
4356 expressionS expr;
b99bd4ef 4357
dcbf9037 4358 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4359 {
4360 inst.operands[i].reg = value;
4361 inst.operands[i].isreg = 1;
b99bd4ef 4362
c19d1205
ZW
4363 /* parse_shift will override this if appropriate */
4364 inst.reloc.exp.X_op = O_constant;
4365 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4366
c19d1205
ZW
4367 if (skip_past_comma (str) == FAIL)
4368 return SUCCESS;
b99bd4ef 4369
c19d1205
ZW
4370 /* Shift operation on register. */
4371 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4372 }
4373
c19d1205
ZW
4374 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4375 return FAIL;
b99bd4ef 4376
c19d1205 4377 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4378 {
c19d1205
ZW
4379 /* #x, y -- ie explicit rotation by Y. */
4380 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4381 return FAIL;
b99bd4ef 4382
c19d1205
ZW
4383 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4384 {
4385 inst.error = _("constant expression expected");
4386 return FAIL;
4387 }
b99bd4ef 4388
c19d1205
ZW
4389 value = expr.X_add_number;
4390 if (value < 0 || value > 30 || value % 2 != 0)
4391 {
4392 inst.error = _("invalid rotation");
4393 return FAIL;
4394 }
4395 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4396 {
4397 inst.error = _("invalid constant");
4398 return FAIL;
4399 }
09d92015 4400
55cf6793 4401 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4402 inst.reloc.exp.X_add_number
4403 = (((inst.reloc.exp.X_add_number << (32 - value))
4404 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4405 }
4406
c19d1205
ZW
4407 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4408 inst.reloc.pc_rel = 0;
4409 return SUCCESS;
09d92015
MM
4410}
4411
4962c51a
MS
4412/* Group relocation information. Each entry in the table contains the
4413 textual name of the relocation as may appear in assembler source
4414 and must end with a colon.
4415 Along with this textual name are the relocation codes to be used if
4416 the corresponding instruction is an ALU instruction (ADD or SUB only),
4417 an LDR, an LDRS, or an LDC. */
4418
4419struct group_reloc_table_entry
4420{
4421 const char *name;
4422 int alu_code;
4423 int ldr_code;
4424 int ldrs_code;
4425 int ldc_code;
4426};
4427
4428typedef enum
4429{
4430 /* Varieties of non-ALU group relocation. */
4431
4432 GROUP_LDR,
4433 GROUP_LDRS,
4434 GROUP_LDC
4435} group_reloc_type;
4436
4437static struct group_reloc_table_entry group_reloc_table[] =
4438 { /* Program counter relative: */
4439 { "pc_g0_nc",
4440 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4441 0, /* LDR */
4442 0, /* LDRS */
4443 0 }, /* LDC */
4444 { "pc_g0",
4445 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4446 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4447 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4448 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4449 { "pc_g1_nc",
4450 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4451 0, /* LDR */
4452 0, /* LDRS */
4453 0 }, /* LDC */
4454 { "pc_g1",
4455 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4456 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4457 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4458 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4459 { "pc_g2",
4460 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4461 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4462 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4463 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4464 /* Section base relative */
4465 { "sb_g0_nc",
4466 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "sb_g0",
4471 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4472 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4473 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4474 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4475 { "sb_g1_nc",
4476 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4477 0, /* LDR */
4478 0, /* LDRS */
4479 0 }, /* LDC */
4480 { "sb_g1",
4481 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4482 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4483 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4484 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4485 { "sb_g2",
4486 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4487 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4488 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4489 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4490
4491/* Given the address of a pointer pointing to the textual name of a group
4492 relocation as may appear in assembler source, attempt to find its details
4493 in group_reloc_table. The pointer will be updated to the character after
4494 the trailing colon. On failure, FAIL will be returned; SUCCESS
4495 otherwise. On success, *entry will be updated to point at the relevant
4496 group_reloc_table entry. */
4497
4498static int
4499find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4500{
4501 unsigned int i;
4502 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4503 {
4504 int length = strlen (group_reloc_table[i].name);
4505
5f4273c7
NC
4506 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4507 && (*str)[length] == ':')
4962c51a
MS
4508 {
4509 *out = &group_reloc_table[i];
4510 *str += (length + 1);
4511 return SUCCESS;
4512 }
4513 }
4514
4515 return FAIL;
4516}
4517
4518/* Parse a <shifter_operand> for an ARM data processing instruction
4519 (as for parse_shifter_operand) where group relocations are allowed:
4520
4521 #<immediate>
4522 #<immediate>, <rotate>
4523 #:<group_reloc>:<expression>
4524 <Rm>
4525 <Rm>, <shift>
4526
4527 where <group_reloc> is one of the strings defined in group_reloc_table.
4528 The hashes are optional.
4529
4530 Everything else is as for parse_shifter_operand. */
4531
4532static parse_operand_result
4533parse_shifter_operand_group_reloc (char **str, int i)
4534{
4535 /* Determine if we have the sequence of characters #: or just :
4536 coming next. If we do, then we check for a group relocation.
4537 If we don't, punt the whole lot to parse_shifter_operand. */
4538
4539 if (((*str)[0] == '#' && (*str)[1] == ':')
4540 || (*str)[0] == ':')
4541 {
4542 struct group_reloc_table_entry *entry;
4543
4544 if ((*str)[0] == '#')
4545 (*str) += 2;
4546 else
4547 (*str)++;
4548
4549 /* Try to parse a group relocation. Anything else is an error. */
4550 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4551 {
4552 inst.error = _("unknown group relocation");
4553 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4554 }
4555
4556 /* We now have the group relocation table entry corresponding to
4557 the name in the assembler source. Next, we parse the expression. */
4558 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4559 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4560
4561 /* Record the relocation type (always the ALU variant here). */
4562 inst.reloc.type = entry->alu_code;
4563 assert (inst.reloc.type != 0);
4564
4565 return PARSE_OPERAND_SUCCESS;
4566 }
4567 else
4568 return parse_shifter_operand (str, i) == SUCCESS
4569 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4570
4571 /* Never reached. */
4572}
4573
c19d1205
ZW
4574/* Parse all forms of an ARM address expression. Information is written
4575 to inst.operands[i] and/or inst.reloc.
09d92015 4576
c19d1205 4577 Preindexed addressing (.preind=1):
09d92015 4578
c19d1205
ZW
4579 [Rn, #offset] .reg=Rn .reloc.exp=offset
4580 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4581 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4582 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4583
c19d1205 4584 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4585
c19d1205 4586 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4587
c19d1205
ZW
4588 [Rn], #offset .reg=Rn .reloc.exp=offset
4589 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4590 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4591 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4592
c19d1205 4593 Unindexed addressing (.preind=0, .postind=0):
09d92015 4594
c19d1205 4595 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4596
c19d1205 4597 Other:
09d92015 4598
c19d1205
ZW
4599 [Rn]{!} shorthand for [Rn,#0]{!}
4600 =immediate .isreg=0 .reloc.exp=immediate
4601 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4602
c19d1205
ZW
4603 It is the caller's responsibility to check for addressing modes not
4604 supported by the instruction, and to set inst.reloc.type. */
4605
4962c51a
MS
4606static parse_operand_result
4607parse_address_main (char **str, int i, int group_relocations,
4608 group_reloc_type group_type)
09d92015 4609{
c19d1205
ZW
4610 char *p = *str;
4611 int reg;
09d92015 4612
c19d1205 4613 if (skip_past_char (&p, '[') == FAIL)
09d92015 4614 {
c19d1205
ZW
4615 if (skip_past_char (&p, '=') == FAIL)
4616 {
4617 /* bare address - translate to PC-relative offset */
4618 inst.reloc.pc_rel = 1;
4619 inst.operands[i].reg = REG_PC;
4620 inst.operands[i].isreg = 1;
4621 inst.operands[i].preind = 1;
4622 }
4623 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4624
c19d1205 4625 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4626 return PARSE_OPERAND_FAIL;
09d92015 4627
c19d1205 4628 *str = p;
4962c51a 4629 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4630 }
4631
dcbf9037 4632 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4633 {
c19d1205 4634 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4635 return PARSE_OPERAND_FAIL;
09d92015 4636 }
c19d1205
ZW
4637 inst.operands[i].reg = reg;
4638 inst.operands[i].isreg = 1;
09d92015 4639
c19d1205 4640 if (skip_past_comma (&p) == SUCCESS)
09d92015 4641 {
c19d1205 4642 inst.operands[i].preind = 1;
09d92015 4643
c19d1205
ZW
4644 if (*p == '+') p++;
4645 else if (*p == '-') p++, inst.operands[i].negative = 1;
4646
dcbf9037 4647 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4648 {
c19d1205
ZW
4649 inst.operands[i].imm = reg;
4650 inst.operands[i].immisreg = 1;
4651
4652 if (skip_past_comma (&p) == SUCCESS)
4653 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4654 return PARSE_OPERAND_FAIL;
c19d1205 4655 }
5287ad62
JB
4656 else if (skip_past_char (&p, ':') == SUCCESS)
4657 {
4658 /* FIXME: '@' should be used here, but it's filtered out by generic
4659 code before we get to see it here. This may be subject to
4660 change. */
4661 expressionS exp;
4662 my_get_expression (&exp, &p, GE_NO_PREFIX);
4663 if (exp.X_op != O_constant)
4664 {
4665 inst.error = _("alignment must be constant");
4962c51a 4666 return PARSE_OPERAND_FAIL;
5287ad62
JB
4667 }
4668 inst.operands[i].imm = exp.X_add_number << 8;
4669 inst.operands[i].immisalign = 1;
4670 /* Alignments are not pre-indexes. */
4671 inst.operands[i].preind = 0;
4672 }
c19d1205
ZW
4673 else
4674 {
4675 if (inst.operands[i].negative)
4676 {
4677 inst.operands[i].negative = 0;
4678 p--;
4679 }
4962c51a 4680
5f4273c7
NC
4681 if (group_relocations
4682 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4683 {
4684 struct group_reloc_table_entry *entry;
4685
4686 /* Skip over the #: or : sequence. */
4687 if (*p == '#')
4688 p += 2;
4689 else
4690 p++;
4691
4692 /* Try to parse a group relocation. Anything else is an
4693 error. */
4694 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4695 {
4696 inst.error = _("unknown group relocation");
4697 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4698 }
4699
4700 /* We now have the group relocation table entry corresponding to
4701 the name in the assembler source. Next, we parse the
4702 expression. */
4703 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4704 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4705
4706 /* Record the relocation type. */
4707 switch (group_type)
4708 {
4709 case GROUP_LDR:
4710 inst.reloc.type = entry->ldr_code;
4711 break;
4712
4713 case GROUP_LDRS:
4714 inst.reloc.type = entry->ldrs_code;
4715 break;
4716
4717 case GROUP_LDC:
4718 inst.reloc.type = entry->ldc_code;
4719 break;
4720
4721 default:
4722 assert (0);
4723 }
4724
4725 if (inst.reloc.type == 0)
4726 {
4727 inst.error = _("this group relocation is not allowed on this instruction");
4728 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4729 }
4730 }
4731 else
4732 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4733 return PARSE_OPERAND_FAIL;
09d92015
MM
4734 }
4735 }
4736
c19d1205 4737 if (skip_past_char (&p, ']') == FAIL)
09d92015 4738 {
c19d1205 4739 inst.error = _("']' expected");
4962c51a 4740 return PARSE_OPERAND_FAIL;
09d92015
MM
4741 }
4742
c19d1205
ZW
4743 if (skip_past_char (&p, '!') == SUCCESS)
4744 inst.operands[i].writeback = 1;
09d92015 4745
c19d1205 4746 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4747 {
c19d1205
ZW
4748 if (skip_past_char (&p, '{') == SUCCESS)
4749 {
4750 /* [Rn], {expr} - unindexed, with option */
4751 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4752 0, 255, TRUE) == FAIL)
4962c51a 4753 return PARSE_OPERAND_FAIL;
09d92015 4754
c19d1205
ZW
4755 if (skip_past_char (&p, '}') == FAIL)
4756 {
4757 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4758 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4759 }
4760 if (inst.operands[i].preind)
4761 {
4762 inst.error = _("cannot combine index with option");
4962c51a 4763 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4764 }
4765 *str = p;
4962c51a 4766 return PARSE_OPERAND_SUCCESS;
09d92015 4767 }
c19d1205
ZW
4768 else
4769 {
4770 inst.operands[i].postind = 1;
4771 inst.operands[i].writeback = 1;
09d92015 4772
c19d1205
ZW
4773 if (inst.operands[i].preind)
4774 {
4775 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4776 return PARSE_OPERAND_FAIL;
c19d1205 4777 }
09d92015 4778
c19d1205
ZW
4779 if (*p == '+') p++;
4780 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4781
dcbf9037 4782 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4783 {
5287ad62
JB
4784 /* We might be using the immediate for alignment already. If we
4785 are, OR the register number into the low-order bits. */
4786 if (inst.operands[i].immisalign)
4787 inst.operands[i].imm |= reg;
4788 else
4789 inst.operands[i].imm = reg;
c19d1205 4790 inst.operands[i].immisreg = 1;
a737bd4d 4791
c19d1205
ZW
4792 if (skip_past_comma (&p) == SUCCESS)
4793 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4794 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4795 }
4796 else
4797 {
4798 if (inst.operands[i].negative)
4799 {
4800 inst.operands[i].negative = 0;
4801 p--;
4802 }
4803 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4804 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4805 }
4806 }
a737bd4d
NC
4807 }
4808
c19d1205
ZW
4809 /* If at this point neither .preind nor .postind is set, we have a
4810 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4811 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4812 {
4813 inst.operands[i].preind = 1;
4814 inst.reloc.exp.X_op = O_constant;
4815 inst.reloc.exp.X_add_number = 0;
4816 }
4817 *str = p;
4962c51a
MS
4818 return PARSE_OPERAND_SUCCESS;
4819}
4820
4821static int
4822parse_address (char **str, int i)
4823{
4824 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4825 ? SUCCESS : FAIL;
4826}
4827
4828static parse_operand_result
4829parse_address_group_reloc (char **str, int i, group_reloc_type type)
4830{
4831 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4832}
4833
b6895b4f
PB
4834/* Parse an operand for a MOVW or MOVT instruction. */
4835static int
4836parse_half (char **str)
4837{
4838 char * p;
5f4273c7 4839
b6895b4f
PB
4840 p = *str;
4841 skip_past_char (&p, '#');
5f4273c7 4842 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4843 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4844 else if (strncasecmp (p, ":upper16:", 9) == 0)
4845 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4846
4847 if (inst.reloc.type != BFD_RELOC_UNUSED)
4848 {
4849 p += 9;
5f4273c7 4850 skip_whitespace (p);
b6895b4f
PB
4851 }
4852
4853 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4854 return FAIL;
4855
4856 if (inst.reloc.type == BFD_RELOC_UNUSED)
4857 {
4858 if (inst.reloc.exp.X_op != O_constant)
4859 {
4860 inst.error = _("constant expression expected");
4861 return FAIL;
4862 }
4863 if (inst.reloc.exp.X_add_number < 0
4864 || inst.reloc.exp.X_add_number > 0xffff)
4865 {
4866 inst.error = _("immediate value out of range");
4867 return FAIL;
4868 }
4869 }
4870 *str = p;
4871 return SUCCESS;
4872}
4873
c19d1205 4874/* Miscellaneous. */
a737bd4d 4875
c19d1205
ZW
4876/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4877 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4878static int
4879parse_psr (char **str)
09d92015 4880{
c19d1205
ZW
4881 char *p;
4882 unsigned long psr_field;
62b3e311
PB
4883 const struct asm_psr *psr;
4884 char *start;
09d92015 4885
c19d1205
ZW
4886 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4887 feature for ease of use and backwards compatibility. */
4888 p = *str;
62b3e311 4889 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4890 psr_field = SPSR_BIT;
62b3e311 4891 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4892 psr_field = 0;
4893 else
62b3e311
PB
4894 {
4895 start = p;
4896 do
4897 p++;
4898 while (ISALNUM (*p) || *p == '_');
4899
4900 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4901 if (!psr)
4902 return FAIL;
09d92015 4903
62b3e311
PB
4904 *str = p;
4905 return psr->field;
4906 }
09d92015 4907
62b3e311 4908 p += 4;
c19d1205
ZW
4909 if (*p == '_')
4910 {
4911 /* A suffix follows. */
c19d1205
ZW
4912 p++;
4913 start = p;
a737bd4d 4914
c19d1205
ZW
4915 do
4916 p++;
4917 while (ISALNUM (*p) || *p == '_');
a737bd4d 4918
c19d1205
ZW
4919 psr = hash_find_n (arm_psr_hsh, start, p - start);
4920 if (!psr)
4921 goto error;
a737bd4d 4922
c19d1205 4923 psr_field |= psr->field;
a737bd4d 4924 }
c19d1205 4925 else
a737bd4d 4926 {
c19d1205
ZW
4927 if (ISALNUM (*p))
4928 goto error; /* Garbage after "[CS]PSR". */
4929
4930 psr_field |= (PSR_c | PSR_f);
a737bd4d 4931 }
c19d1205
ZW
4932 *str = p;
4933 return psr_field;
a737bd4d 4934
c19d1205
ZW
4935 error:
4936 inst.error = _("flag for {c}psr instruction expected");
4937 return FAIL;
a737bd4d
NC
4938}
4939
c19d1205
ZW
4940/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4941 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4942
c19d1205
ZW
4943static int
4944parse_cps_flags (char **str)
a737bd4d 4945{
c19d1205
ZW
4946 int val = 0;
4947 int saw_a_flag = 0;
4948 char *s = *str;
a737bd4d 4949
c19d1205
ZW
4950 for (;;)
4951 switch (*s++)
4952 {
4953 case '\0': case ',':
4954 goto done;
a737bd4d 4955
c19d1205
ZW
4956 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4957 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4958 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4959
c19d1205
ZW
4960 default:
4961 inst.error = _("unrecognized CPS flag");
4962 return FAIL;
4963 }
a737bd4d 4964
c19d1205
ZW
4965 done:
4966 if (saw_a_flag == 0)
a737bd4d 4967 {
c19d1205
ZW
4968 inst.error = _("missing CPS flags");
4969 return FAIL;
a737bd4d 4970 }
a737bd4d 4971
c19d1205
ZW
4972 *str = s - 1;
4973 return val;
a737bd4d
NC
4974}
4975
c19d1205
ZW
4976/* Parse an endian specifier ("BE" or "LE", case insensitive);
4977 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4978
4979static int
c19d1205 4980parse_endian_specifier (char **str)
a737bd4d 4981{
c19d1205
ZW
4982 int little_endian;
4983 char *s = *str;
a737bd4d 4984
c19d1205
ZW
4985 if (strncasecmp (s, "BE", 2))
4986 little_endian = 0;
4987 else if (strncasecmp (s, "LE", 2))
4988 little_endian = 1;
4989 else
a737bd4d 4990 {
c19d1205 4991 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4992 return FAIL;
4993 }
4994
c19d1205 4995 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 4996 {
c19d1205 4997 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4998 return FAIL;
4999 }
5000
c19d1205
ZW
5001 *str = s + 2;
5002 return little_endian;
5003}
a737bd4d 5004
c19d1205
ZW
5005/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5006 value suitable for poking into the rotate field of an sxt or sxta
5007 instruction, or FAIL on error. */
5008
5009static int
5010parse_ror (char **str)
5011{
5012 int rot;
5013 char *s = *str;
5014
5015 if (strncasecmp (s, "ROR", 3) == 0)
5016 s += 3;
5017 else
a737bd4d 5018 {
c19d1205 5019 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5020 return FAIL;
5021 }
c19d1205
ZW
5022
5023 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5024 return FAIL;
5025
5026 switch (rot)
a737bd4d 5027 {
c19d1205
ZW
5028 case 0: *str = s; return 0x0;
5029 case 8: *str = s; return 0x1;
5030 case 16: *str = s; return 0x2;
5031 case 24: *str = s; return 0x3;
5032
5033 default:
5034 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5035 return FAIL;
5036 }
c19d1205 5037}
a737bd4d 5038
c19d1205
ZW
5039/* Parse a conditional code (from conds[] below). The value returned is in the
5040 range 0 .. 14, or FAIL. */
5041static int
5042parse_cond (char **str)
5043{
5044 char *p, *q;
5045 const struct asm_cond *c;
a737bd4d 5046
c19d1205
ZW
5047 p = q = *str;
5048 while (ISALPHA (*q))
5049 q++;
a737bd4d 5050
c19d1205
ZW
5051 c = hash_find_n (arm_cond_hsh, p, q - p);
5052 if (!c)
a737bd4d 5053 {
c19d1205 5054 inst.error = _("condition required");
a737bd4d
NC
5055 return FAIL;
5056 }
5057
c19d1205
ZW
5058 *str = q;
5059 return c->value;
5060}
5061
62b3e311
PB
5062/* Parse an option for a barrier instruction. Returns the encoding for the
5063 option, or FAIL. */
5064static int
5065parse_barrier (char **str)
5066{
5067 char *p, *q;
5068 const struct asm_barrier_opt *o;
5069
5070 p = q = *str;
5071 while (ISALPHA (*q))
5072 q++;
5073
5074 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5075 if (!o)
5076 return FAIL;
5077
5078 *str = q;
5079 return o->value;
5080}
5081
92e90b6e
PB
5082/* Parse the operands of a table branch instruction. Similar to a memory
5083 operand. */
5084static int
5085parse_tb (char **str)
5086{
5087 char * p = *str;
5088 int reg;
5089
5090 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5091 {
5092 inst.error = _("'[' expected");
5093 return FAIL;
5094 }
92e90b6e 5095
dcbf9037 5096 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5097 {
5098 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5099 return FAIL;
5100 }
5101 inst.operands[0].reg = reg;
5102
5103 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5104 {
5105 inst.error = _("',' expected");
5106 return FAIL;
5107 }
5f4273c7 5108
dcbf9037 5109 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5110 {
5111 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5112 return FAIL;
5113 }
5114 inst.operands[0].imm = reg;
5115
5116 if (skip_past_comma (&p) == SUCCESS)
5117 {
5118 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5119 return FAIL;
5120 if (inst.reloc.exp.X_add_number != 1)
5121 {
5122 inst.error = _("invalid shift");
5123 return FAIL;
5124 }
5125 inst.operands[0].shifted = 1;
5126 }
5127
5128 if (skip_past_char (&p, ']') == FAIL)
5129 {
5130 inst.error = _("']' expected");
5131 return FAIL;
5132 }
5133 *str = p;
5134 return SUCCESS;
5135}
5136
5287ad62
JB
5137/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5138 information on the types the operands can take and how they are encoded.
037e8744
JB
5139 Up to four operands may be read; this function handles setting the
5140 ".present" field for each read operand itself.
5287ad62
JB
5141 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5142 else returns FAIL. */
5143
5144static int
5145parse_neon_mov (char **str, int *which_operand)
5146{
5147 int i = *which_operand, val;
5148 enum arm_reg_type rtype;
5149 char *ptr = *str;
dcbf9037 5150 struct neon_type_el optype;
5f4273c7 5151
dcbf9037 5152 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5153 {
5154 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5155 inst.operands[i].reg = val;
5156 inst.operands[i].isscalar = 1;
dcbf9037 5157 inst.operands[i].vectype = optype;
5287ad62
JB
5158 inst.operands[i++].present = 1;
5159
5160 if (skip_past_comma (&ptr) == FAIL)
5161 goto wanted_comma;
5f4273c7 5162
dcbf9037 5163 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5164 goto wanted_arm;
5f4273c7 5165
5287ad62
JB
5166 inst.operands[i].reg = val;
5167 inst.operands[i].isreg = 1;
5168 inst.operands[i].present = 1;
5169 }
037e8744 5170 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5171 != FAIL)
5287ad62
JB
5172 {
5173 /* Cases 0, 1, 2, 3, 5 (D only). */
5174 if (skip_past_comma (&ptr) == FAIL)
5175 goto wanted_comma;
5f4273c7 5176
5287ad62
JB
5177 inst.operands[i].reg = val;
5178 inst.operands[i].isreg = 1;
5179 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5180 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5181 inst.operands[i].isvec = 1;
dcbf9037 5182 inst.operands[i].vectype = optype;
5287ad62
JB
5183 inst.operands[i++].present = 1;
5184
dcbf9037 5185 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5186 {
037e8744
JB
5187 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5188 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5189 inst.operands[i].reg = val;
5190 inst.operands[i].isreg = 1;
037e8744 5191 inst.operands[i].present = 1;
5287ad62
JB
5192
5193 if (rtype == REG_TYPE_NQ)
5194 {
dcbf9037 5195 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5196 return FAIL;
5197 }
037e8744
JB
5198 else if (rtype != REG_TYPE_VFS)
5199 {
5200 i++;
5201 if (skip_past_comma (&ptr) == FAIL)
5202 goto wanted_comma;
5203 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5204 goto wanted_arm;
5205 inst.operands[i].reg = val;
5206 inst.operands[i].isreg = 1;
5207 inst.operands[i].present = 1;
5208 }
5287ad62 5209 }
136da414 5210 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5211 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5212 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5213 Case 10: VMOV.F32 <Sd>, #<imm>
5214 Case 11: VMOV.F64 <Dd>, #<imm> */
c96612cc 5215 inst.operands[i].immisfloat = 1;
5287ad62 5216 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5217 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5218 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5219 ;
5220 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5221 &optype)) != FAIL)
5287ad62
JB
5222 {
5223 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5224 Case 1: VMOV<c><q> <Dd>, <Dm>
5225 Case 8: VMOV.F32 <Sd>, <Sm>
5226 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5227
5228 inst.operands[i].reg = val;
5229 inst.operands[i].isreg = 1;
5230 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5231 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5232 inst.operands[i].isvec = 1;
dcbf9037 5233 inst.operands[i].vectype = optype;
5287ad62 5234 inst.operands[i].present = 1;
5f4273c7 5235
037e8744
JB
5236 if (skip_past_comma (&ptr) == SUCCESS)
5237 {
5238 /* Case 15. */
5239 i++;
5240
5241 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5242 goto wanted_arm;
5243
5244 inst.operands[i].reg = val;
5245 inst.operands[i].isreg = 1;
5246 inst.operands[i++].present = 1;
5f4273c7 5247
037e8744
JB
5248 if (skip_past_comma (&ptr) == FAIL)
5249 goto wanted_comma;
5f4273c7 5250
037e8744
JB
5251 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5252 goto wanted_arm;
5f4273c7 5253
037e8744
JB
5254 inst.operands[i].reg = val;
5255 inst.operands[i].isreg = 1;
5256 inst.operands[i++].present = 1;
5257 }
5287ad62
JB
5258 }
5259 else
5260 {
dcbf9037 5261 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5262 return FAIL;
5263 }
5264 }
dcbf9037 5265 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5266 {
5267 /* Cases 6, 7. */
5268 inst.operands[i].reg = val;
5269 inst.operands[i].isreg = 1;
5270 inst.operands[i++].present = 1;
5f4273c7 5271
5287ad62
JB
5272 if (skip_past_comma (&ptr) == FAIL)
5273 goto wanted_comma;
5f4273c7 5274
dcbf9037 5275 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5276 {
5277 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5278 inst.operands[i].reg = val;
5279 inst.operands[i].isscalar = 1;
5280 inst.operands[i].present = 1;
dcbf9037 5281 inst.operands[i].vectype = optype;
5287ad62 5282 }
dcbf9037 5283 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5284 {
5285 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5286 inst.operands[i].reg = val;
5287 inst.operands[i].isreg = 1;
5288 inst.operands[i++].present = 1;
5f4273c7 5289
5287ad62
JB
5290 if (skip_past_comma (&ptr) == FAIL)
5291 goto wanted_comma;
5f4273c7 5292
037e8744 5293 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5294 == FAIL)
5287ad62 5295 {
037e8744 5296 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5297 return FAIL;
5298 }
5299
5300 inst.operands[i].reg = val;
5301 inst.operands[i].isreg = 1;
037e8744
JB
5302 inst.operands[i].isvec = 1;
5303 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5304 inst.operands[i].vectype = optype;
5287ad62 5305 inst.operands[i].present = 1;
5f4273c7 5306
037e8744
JB
5307 if (rtype == REG_TYPE_VFS)
5308 {
5309 /* Case 14. */
5310 i++;
5311 if (skip_past_comma (&ptr) == FAIL)
5312 goto wanted_comma;
5313 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5314 &optype)) == FAIL)
5315 {
5316 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5317 return FAIL;
5318 }
5319 inst.operands[i].reg = val;
5320 inst.operands[i].isreg = 1;
5321 inst.operands[i].isvec = 1;
5322 inst.operands[i].issingle = 1;
5323 inst.operands[i].vectype = optype;
5324 inst.operands[i].present = 1;
5325 }
5326 }
5327 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5328 != FAIL)
5329 {
5330 /* Case 13. */
5331 inst.operands[i].reg = val;
5332 inst.operands[i].isreg = 1;
5333 inst.operands[i].isvec = 1;
5334 inst.operands[i].issingle = 1;
5335 inst.operands[i].vectype = optype;
5336 inst.operands[i++].present = 1;
5287ad62
JB
5337 }
5338 }
5339 else
5340 {
dcbf9037 5341 first_error (_("parse error"));
5287ad62
JB
5342 return FAIL;
5343 }
5344
5345 /* Successfully parsed the operands. Update args. */
5346 *which_operand = i;
5347 *str = ptr;
5348 return SUCCESS;
5349
5f4273c7 5350 wanted_comma:
dcbf9037 5351 first_error (_("expected comma"));
5287ad62 5352 return FAIL;
5f4273c7
NC
5353
5354 wanted_arm:
dcbf9037 5355 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5356 return FAIL;
5287ad62
JB
5357}
5358
c19d1205
ZW
5359/* Matcher codes for parse_operands. */
5360enum operand_parse_code
5361{
5362 OP_stop, /* end of line */
5363
5364 OP_RR, /* ARM register */
5365 OP_RRnpc, /* ARM register, not r15 */
5366 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5367 OP_RRw, /* ARM register, not r15, optional trailing ! */
5368 OP_RCP, /* Coprocessor number */
5369 OP_RCN, /* Coprocessor register */
5370 OP_RF, /* FPA register */
5371 OP_RVS, /* VFP single precision register */
5287ad62
JB
5372 OP_RVD, /* VFP double precision register (0..15) */
5373 OP_RND, /* Neon double precision register (0..31) */
5374 OP_RNQ, /* Neon quad precision register */
037e8744 5375 OP_RVSD, /* VFP single or double precision register */
5287ad62 5376 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5377 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5378 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5379 OP_RVC, /* VFP control register */
5380 OP_RMF, /* Maverick F register */
5381 OP_RMD, /* Maverick D register */
5382 OP_RMFX, /* Maverick FX register */
5383 OP_RMDX, /* Maverick DX register */
5384 OP_RMAX, /* Maverick AX register */
5385 OP_RMDS, /* Maverick DSPSC register */
5386 OP_RIWR, /* iWMMXt wR register */
5387 OP_RIWC, /* iWMMXt wC register */
5388 OP_RIWG, /* iWMMXt wCG register */
5389 OP_RXA, /* XScale accumulator register */
5390
5391 OP_REGLST, /* ARM register list */
5392 OP_VRSLST, /* VFP single-precision register list */
5393 OP_VRDLST, /* VFP double-precision register list */
037e8744 5394 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5395 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5396 OP_NSTRLST, /* Neon element/structure list */
5397
5398 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5399 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5400 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5401 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5402 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5403 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5404 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5405 OP_VMOV, /* Neon VMOV operands. */
5406 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5407 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5408 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5409
5410 OP_I0, /* immediate zero */
c19d1205
ZW
5411 OP_I7, /* immediate value 0 .. 7 */
5412 OP_I15, /* 0 .. 15 */
5413 OP_I16, /* 1 .. 16 */
5287ad62 5414 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5415 OP_I31, /* 0 .. 31 */
5416 OP_I31w, /* 0 .. 31, optional trailing ! */
5417 OP_I32, /* 1 .. 32 */
5287ad62
JB
5418 OP_I32z, /* 0 .. 32 */
5419 OP_I63, /* 0 .. 63 */
c19d1205 5420 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5421 OP_I64, /* 1 .. 64 */
5422 OP_I64z, /* 0 .. 64 */
c19d1205 5423 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5424
5425 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5426 OP_I7b, /* 0 .. 7 */
5427 OP_I15b, /* 0 .. 15 */
5428 OP_I31b, /* 0 .. 31 */
5429
5430 OP_SH, /* shifter operand */
4962c51a 5431 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5432 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5433 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5434 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5435 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5436 OP_EXP, /* arbitrary expression */
5437 OP_EXPi, /* same, with optional immediate prefix */
5438 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5439 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5440
5441 OP_CPSF, /* CPS flags */
5442 OP_ENDI, /* Endianness specifier */
5443 OP_PSR, /* CPSR/SPSR mask for msr */
5444 OP_COND, /* conditional code */
92e90b6e 5445 OP_TB, /* Table branch. */
c19d1205 5446
037e8744
JB
5447 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5448 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5449
c19d1205
ZW
5450 OP_RRnpc_I0, /* ARM register or literal 0 */
5451 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5452 OP_RR_EXi, /* ARM register or expression with imm prefix */
5453 OP_RF_IF, /* FPA register or immediate */
5454 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5455 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5456
5457 /* Optional operands. */
5458 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5459 OP_oI31b, /* 0 .. 31 */
5287ad62 5460 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5461 OP_oIffffb, /* 0 .. 65535 */
5462 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5463
5464 OP_oRR, /* ARM register */
5465 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5466 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5467 OP_oRND, /* Optional Neon double precision register */
5468 OP_oRNQ, /* Optional Neon quad precision register */
5469 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5470 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5471 OP_oSHll, /* LSL immediate */
5472 OP_oSHar, /* ASR immediate */
5473 OP_oSHllar, /* LSL or ASR immediate */
5474 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5475 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5476
5477 OP_FIRST_OPTIONAL = OP_oI7b
5478};
a737bd4d 5479
c19d1205
ZW
5480/* Generic instruction operand parser. This does no encoding and no
5481 semantic validation; it merely squirrels values away in the inst
5482 structure. Returns SUCCESS or FAIL depending on whether the
5483 specified grammar matched. */
5484static int
ca3f61f7 5485parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5486{
5487 unsigned const char *upat = pattern;
5488 char *backtrack_pos = 0;
5489 const char *backtrack_error = 0;
5490 int i, val, backtrack_index = 0;
5287ad62 5491 enum arm_reg_type rtype;
4962c51a 5492 parse_operand_result result;
c19d1205
ZW
5493
5494#define po_char_or_fail(chr) do { \
5495 if (skip_past_char (&str, chr) == FAIL) \
5496 goto bad_args; \
5497} while (0)
5498
dcbf9037
JB
5499#define po_reg_or_fail(regtype) do { \
5500 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5501 &inst.operands[i].vectype); \
5502 if (val == FAIL) \
5503 { \
5504 first_error (_(reg_expected_msgs[regtype])); \
5505 goto failure; \
5506 } \
5507 inst.operands[i].reg = val; \
5508 inst.operands[i].isreg = 1; \
5509 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5510 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5511 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5512 || rtype == REG_TYPE_VFD \
5513 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5514} while (0)
5515
dcbf9037
JB
5516#define po_reg_or_goto(regtype, label) do { \
5517 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5518 &inst.operands[i].vectype); \
5519 if (val == FAIL) \
5520 goto label; \
5521 \
5522 inst.operands[i].reg = val; \
5523 inst.operands[i].isreg = 1; \
5524 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5525 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5526 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5527 || rtype == REG_TYPE_VFD \
5528 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5529} while (0)
5530
5531#define po_imm_or_fail(min, max, popt) do { \
5532 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5533 goto failure; \
5534 inst.operands[i].imm = val; \
5535} while (0)
5536
dcbf9037
JB
5537#define po_scalar_or_goto(elsz, label) do { \
5538 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5539 if (val == FAIL) \
5540 goto label; \
5541 inst.operands[i].reg = val; \
5542 inst.operands[i].isscalar = 1; \
5287ad62
JB
5543} while (0)
5544
c19d1205
ZW
5545#define po_misc_or_fail(expr) do { \
5546 if (expr) \
5547 goto failure; \
5548} while (0)
5549
4962c51a
MS
5550#define po_misc_or_fail_no_backtrack(expr) do { \
5551 result = expr; \
5552 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5553 backtrack_pos = 0; \
5554 if (result != PARSE_OPERAND_SUCCESS) \
5555 goto failure; \
5556} while (0)
5557
c19d1205
ZW
5558 skip_whitespace (str);
5559
5560 for (i = 0; upat[i] != OP_stop; i++)
5561 {
5562 if (upat[i] >= OP_FIRST_OPTIONAL)
5563 {
5564 /* Remember where we are in case we need to backtrack. */
5565 assert (!backtrack_pos);
5566 backtrack_pos = str;
5567 backtrack_error = inst.error;
5568 backtrack_index = i;
5569 }
5570
b6702015 5571 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5572 po_char_or_fail (',');
5573
5574 switch (upat[i])
5575 {
5576 /* Registers */
5577 case OP_oRRnpc:
5578 case OP_RRnpc:
5579 case OP_oRR:
5580 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5581 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5582 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5583 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5584 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5585 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5586 case OP_oRND:
5587 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5588 case OP_RVC:
5589 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5590 break;
5591 /* Also accept generic coprocessor regs for unknown registers. */
5592 coproc_reg:
5593 po_reg_or_fail (REG_TYPE_CN);
5594 break;
c19d1205
ZW
5595 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5596 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5597 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5598 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5599 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5600 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5601 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5602 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5603 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5604 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5605 case OP_oRNQ:
5606 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5607 case OP_oRNDQ:
5608 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5609 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5610 case OP_oRNSDQ:
5611 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5612
5613 /* Neon scalar. Using an element size of 8 means that some invalid
5614 scalars are accepted here, so deal with those in later code. */
5615 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5616
5617 /* WARNING: We can expand to two operands here. This has the potential
5618 to totally confuse the backtracking mechanism! It will be OK at
5619 least as long as we don't try to use optional args as well,
5620 though. */
5621 case OP_NILO:
5622 {
5623 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5624 inst.operands[i].present = 1;
5287ad62
JB
5625 i++;
5626 skip_past_comma (&str);
5627 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5628 break;
5629 one_reg_only:
5630 /* Optional register operand was omitted. Unfortunately, it's in
5631 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5632 here (this is a bit grotty). */
5633 inst.operands[i] = inst.operands[i-1];
5634 inst.operands[i-1].present = 0;
5635 break;
5636 try_imm:
036dc3f7
PB
5637 /* There's a possibility of getting a 64-bit immediate here, so
5638 we need special handling. */
5639 if (parse_big_immediate (&str, i) == FAIL)
5640 {
5641 inst.error = _("immediate value is out of range");
5642 goto failure;
5643 }
5287ad62
JB
5644 }
5645 break;
5646
5647 case OP_RNDQ_I0:
5648 {
5649 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5650 break;
5651 try_imm0:
5652 po_imm_or_fail (0, 0, TRUE);
5653 }
5654 break;
5655
037e8744
JB
5656 case OP_RVSD_I0:
5657 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5658 break;
5659
5287ad62
JB
5660 case OP_RR_RNSC:
5661 {
5662 po_scalar_or_goto (8, try_rr);
5663 break;
5664 try_rr:
5665 po_reg_or_fail (REG_TYPE_RN);
5666 }
5667 break;
5668
037e8744
JB
5669 case OP_RNSDQ_RNSC:
5670 {
5671 po_scalar_or_goto (8, try_nsdq);
5672 break;
5673 try_nsdq:
5674 po_reg_or_fail (REG_TYPE_NSDQ);
5675 }
5676 break;
5677
5287ad62
JB
5678 case OP_RNDQ_RNSC:
5679 {
5680 po_scalar_or_goto (8, try_ndq);
5681 break;
5682 try_ndq:
5683 po_reg_or_fail (REG_TYPE_NDQ);
5684 }
5685 break;
5686
5687 case OP_RND_RNSC:
5688 {
5689 po_scalar_or_goto (8, try_vfd);
5690 break;
5691 try_vfd:
5692 po_reg_or_fail (REG_TYPE_VFD);
5693 }
5694 break;
5695
5696 case OP_VMOV:
5697 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5698 not careful then bad things might happen. */
5699 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5700 break;
5701
5702 case OP_RNDQ_IMVNb:
5703 {
5704 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5705 break;
5706 try_mvnimm:
5707 /* There's a possibility of getting a 64-bit immediate here, so
5708 we need special handling. */
5709 if (parse_big_immediate (&str, i) == FAIL)
5710 {
5711 inst.error = _("immediate value is out of range");
5712 goto failure;
5713 }
5714 }
5715 break;
5716
5717 case OP_RNDQ_I63b:
5718 {
5719 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5720 break;
5721 try_shimm:
5722 po_imm_or_fail (0, 63, TRUE);
5723 }
5724 break;
c19d1205
ZW
5725
5726 case OP_RRnpcb:
5727 po_char_or_fail ('[');
5728 po_reg_or_fail (REG_TYPE_RN);
5729 po_char_or_fail (']');
5730 break;
a737bd4d 5731
c19d1205 5732 case OP_RRw:
b6702015 5733 case OP_oRRw:
c19d1205
ZW
5734 po_reg_or_fail (REG_TYPE_RN);
5735 if (skip_past_char (&str, '!') == SUCCESS)
5736 inst.operands[i].writeback = 1;
5737 break;
5738
5739 /* Immediates */
5740 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5741 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5742 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5743 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5744 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5745 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5746 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5747 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5748 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5749 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5750 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5751 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5752
5753 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5754 case OP_oI7b:
5755 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5756 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5757 case OP_oI31b:
5758 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5759 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5760 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5761
5762 /* Immediate variants */
5763 case OP_oI255c:
5764 po_char_or_fail ('{');
5765 po_imm_or_fail (0, 255, TRUE);
5766 po_char_or_fail ('}');
5767 break;
5768
5769 case OP_I31w:
5770 /* The expression parser chokes on a trailing !, so we have
5771 to find it first and zap it. */
5772 {
5773 char *s = str;
5774 while (*s && *s != ',')
5775 s++;
5776 if (s[-1] == '!')
5777 {
5778 s[-1] = '\0';
5779 inst.operands[i].writeback = 1;
5780 }
5781 po_imm_or_fail (0, 31, TRUE);
5782 if (str == s - 1)
5783 str = s;
5784 }
5785 break;
5786
5787 /* Expressions */
5788 case OP_EXPi: EXPi:
5789 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5790 GE_OPT_PREFIX));
5791 break;
5792
5793 case OP_EXP:
5794 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5795 GE_NO_PREFIX));
5796 break;
5797
5798 case OP_EXPr: EXPr:
5799 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5800 GE_NO_PREFIX));
5801 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5802 {
c19d1205
ZW
5803 val = parse_reloc (&str);
5804 if (val == -1)
5805 {
5806 inst.error = _("unrecognized relocation suffix");
5807 goto failure;
5808 }
5809 else if (val != BFD_RELOC_UNUSED)
5810 {
5811 inst.operands[i].imm = val;
5812 inst.operands[i].hasreloc = 1;
5813 }
a737bd4d 5814 }
c19d1205 5815 break;
a737bd4d 5816
b6895b4f
PB
5817 /* Operand for MOVW or MOVT. */
5818 case OP_HALF:
5819 po_misc_or_fail (parse_half (&str));
5820 break;
5821
c19d1205
ZW
5822 /* Register or expression */
5823 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5824 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5825
c19d1205
ZW
5826 /* Register or immediate */
5827 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5828 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5829
c19d1205
ZW
5830 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5831 IF:
5832 if (!is_immediate_prefix (*str))
5833 goto bad_args;
5834 str++;
5835 val = parse_fpa_immediate (&str);
5836 if (val == FAIL)
5837 goto failure;
5838 /* FPA immediates are encoded as registers 8-15.
5839 parse_fpa_immediate has already applied the offset. */
5840 inst.operands[i].reg = val;
5841 inst.operands[i].isreg = 1;
5842 break;
09d92015 5843
2d447fca
JM
5844 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5845 I32z: po_imm_or_fail (0, 32, FALSE); break;
5846
c19d1205
ZW
5847 /* Two kinds of register */
5848 case OP_RIWR_RIWC:
5849 {
5850 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5851 if (!rege
5852 || (rege->type != REG_TYPE_MMXWR
5853 && rege->type != REG_TYPE_MMXWC
5854 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5855 {
5856 inst.error = _("iWMMXt data or control register expected");
5857 goto failure;
5858 }
5859 inst.operands[i].reg = rege->number;
5860 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5861 }
5862 break;
09d92015 5863
41adaa5c
JM
5864 case OP_RIWC_RIWG:
5865 {
5866 struct reg_entry *rege = arm_reg_parse_multi (&str);
5867 if (!rege
5868 || (rege->type != REG_TYPE_MMXWC
5869 && rege->type != REG_TYPE_MMXWCG))
5870 {
5871 inst.error = _("iWMMXt control register expected");
5872 goto failure;
5873 }
5874 inst.operands[i].reg = rege->number;
5875 inst.operands[i].isreg = 1;
5876 }
5877 break;
5878
c19d1205
ZW
5879 /* Misc */
5880 case OP_CPSF: val = parse_cps_flags (&str); break;
5881 case OP_ENDI: val = parse_endian_specifier (&str); break;
5882 case OP_oROR: val = parse_ror (&str); break;
5883 case OP_PSR: val = parse_psr (&str); break;
5884 case OP_COND: val = parse_cond (&str); break;
62b3e311 5885 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5886
037e8744
JB
5887 case OP_RVC_PSR:
5888 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5889 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5890 break;
5891 try_psr:
5892 val = parse_psr (&str);
5893 break;
5894
5895 case OP_APSR_RR:
5896 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5897 break;
5898 try_apsr:
5899 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5900 instruction). */
5901 if (strncasecmp (str, "APSR_", 5) == 0)
5902 {
5903 unsigned found = 0;
5904 str += 5;
5905 while (found < 15)
5906 switch (*str++)
5907 {
5908 case 'c': found = (found & 1) ? 16 : found | 1; break;
5909 case 'n': found = (found & 2) ? 16 : found | 2; break;
5910 case 'z': found = (found & 4) ? 16 : found | 4; break;
5911 case 'v': found = (found & 8) ? 16 : found | 8; break;
5912 default: found = 16;
5913 }
5914 if (found != 15)
5915 goto failure;
5916 inst.operands[i].isvec = 1;
5917 }
5918 else
5919 goto failure;
5920 break;
5921
92e90b6e
PB
5922 case OP_TB:
5923 po_misc_or_fail (parse_tb (&str));
5924 break;
5925
c19d1205
ZW
5926 /* Register lists */
5927 case OP_REGLST:
5928 val = parse_reg_list (&str);
5929 if (*str == '^')
5930 {
5931 inst.operands[1].writeback = 1;
5932 str++;
5933 }
5934 break;
09d92015 5935
c19d1205 5936 case OP_VRSLST:
5287ad62 5937 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5938 break;
09d92015 5939
c19d1205 5940 case OP_VRDLST:
5287ad62 5941 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5942 break;
a737bd4d 5943
037e8744
JB
5944 case OP_VRSDLST:
5945 /* Allow Q registers too. */
5946 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5947 REGLIST_NEON_D);
5948 if (val == FAIL)
5949 {
5950 inst.error = NULL;
5951 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5952 REGLIST_VFP_S);
5953 inst.operands[i].issingle = 1;
5954 }
5955 break;
5956
5287ad62
JB
5957 case OP_NRDLST:
5958 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5959 REGLIST_NEON_D);
5960 break;
5961
5962 case OP_NSTRLST:
dcbf9037
JB
5963 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5964 &inst.operands[i].vectype);
5287ad62
JB
5965 break;
5966
c19d1205
ZW
5967 /* Addressing modes */
5968 case OP_ADDR:
5969 po_misc_or_fail (parse_address (&str, i));
5970 break;
09d92015 5971
4962c51a
MS
5972 case OP_ADDRGLDR:
5973 po_misc_or_fail_no_backtrack (
5974 parse_address_group_reloc (&str, i, GROUP_LDR));
5975 break;
5976
5977 case OP_ADDRGLDRS:
5978 po_misc_or_fail_no_backtrack (
5979 parse_address_group_reloc (&str, i, GROUP_LDRS));
5980 break;
5981
5982 case OP_ADDRGLDC:
5983 po_misc_or_fail_no_backtrack (
5984 parse_address_group_reloc (&str, i, GROUP_LDC));
5985 break;
5986
c19d1205
ZW
5987 case OP_SH:
5988 po_misc_or_fail (parse_shifter_operand (&str, i));
5989 break;
09d92015 5990
4962c51a
MS
5991 case OP_SHG:
5992 po_misc_or_fail_no_backtrack (
5993 parse_shifter_operand_group_reloc (&str, i));
5994 break;
5995
c19d1205
ZW
5996 case OP_oSHll:
5997 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5998 break;
09d92015 5999
c19d1205
ZW
6000 case OP_oSHar:
6001 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6002 break;
09d92015 6003
c19d1205
ZW
6004 case OP_oSHllar:
6005 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6006 break;
09d92015 6007
c19d1205 6008 default:
bd3ba5d1 6009 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6010 }
09d92015 6011
c19d1205
ZW
6012 /* Various value-based sanity checks and shared operations. We
6013 do not signal immediate failures for the register constraints;
6014 this allows a syntax error to take precedence. */
6015 switch (upat[i])
6016 {
6017 case OP_oRRnpc:
6018 case OP_RRnpc:
6019 case OP_RRnpcb:
6020 case OP_RRw:
b6702015 6021 case OP_oRRw:
c19d1205
ZW
6022 case OP_RRnpc_I0:
6023 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6024 inst.error = BAD_PC;
6025 break;
09d92015 6026
c19d1205
ZW
6027 case OP_CPSF:
6028 case OP_ENDI:
6029 case OP_oROR:
6030 case OP_PSR:
037e8744 6031 case OP_RVC_PSR:
c19d1205 6032 case OP_COND:
62b3e311 6033 case OP_oBARRIER:
c19d1205
ZW
6034 case OP_REGLST:
6035 case OP_VRSLST:
6036 case OP_VRDLST:
037e8744 6037 case OP_VRSDLST:
5287ad62
JB
6038 case OP_NRDLST:
6039 case OP_NSTRLST:
c19d1205
ZW
6040 if (val == FAIL)
6041 goto failure;
6042 inst.operands[i].imm = val;
6043 break;
a737bd4d 6044
c19d1205
ZW
6045 default:
6046 break;
6047 }
09d92015 6048
c19d1205
ZW
6049 /* If we get here, this operand was successfully parsed. */
6050 inst.operands[i].present = 1;
6051 continue;
09d92015 6052
c19d1205 6053 bad_args:
09d92015 6054 inst.error = BAD_ARGS;
c19d1205
ZW
6055
6056 failure:
6057 if (!backtrack_pos)
d252fdde
PB
6058 {
6059 /* The parse routine should already have set inst.error, but set a
5f4273c7 6060 default here just in case. */
d252fdde
PB
6061 if (!inst.error)
6062 inst.error = _("syntax error");
6063 return FAIL;
6064 }
c19d1205
ZW
6065
6066 /* Do not backtrack over a trailing optional argument that
6067 absorbed some text. We will only fail again, with the
6068 'garbage following instruction' error message, which is
6069 probably less helpful than the current one. */
6070 if (backtrack_index == i && backtrack_pos != str
6071 && upat[i+1] == OP_stop)
d252fdde
PB
6072 {
6073 if (!inst.error)
6074 inst.error = _("syntax error");
6075 return FAIL;
6076 }
c19d1205
ZW
6077
6078 /* Try again, skipping the optional argument at backtrack_pos. */
6079 str = backtrack_pos;
6080 inst.error = backtrack_error;
6081 inst.operands[backtrack_index].present = 0;
6082 i = backtrack_index;
6083 backtrack_pos = 0;
09d92015 6084 }
09d92015 6085
c19d1205
ZW
6086 /* Check that we have parsed all the arguments. */
6087 if (*str != '\0' && !inst.error)
6088 inst.error = _("garbage following instruction");
09d92015 6089
c19d1205 6090 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6091}
6092
c19d1205
ZW
6093#undef po_char_or_fail
6094#undef po_reg_or_fail
6095#undef po_reg_or_goto
6096#undef po_imm_or_fail
5287ad62 6097#undef po_scalar_or_fail
c19d1205
ZW
6098\f
6099/* Shorthand macro for instruction encoding functions issuing errors. */
6100#define constraint(expr, err) do { \
6101 if (expr) \
6102 { \
6103 inst.error = err; \
6104 return; \
6105 } \
6106} while (0)
6107
6108/* Functions for operand encoding. ARM, then Thumb. */
6109
6110#define rotate_left(v, n) (v << n | v >> (32 - n))
6111
6112/* If VAL can be encoded in the immediate field of an ARM instruction,
6113 return the encoded form. Otherwise, return FAIL. */
6114
6115static unsigned int
6116encode_arm_immediate (unsigned int val)
09d92015 6117{
c19d1205
ZW
6118 unsigned int a, i;
6119
6120 for (i = 0; i < 32; i += 2)
6121 if ((a = rotate_left (val, i)) <= 0xff)
6122 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6123
6124 return FAIL;
09d92015
MM
6125}
6126
c19d1205
ZW
6127/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6128 return the encoded form. Otherwise, return FAIL. */
6129static unsigned int
6130encode_thumb32_immediate (unsigned int val)
09d92015 6131{
c19d1205 6132 unsigned int a, i;
09d92015 6133
9c3c69f2 6134 if (val <= 0xff)
c19d1205 6135 return val;
a737bd4d 6136
9c3c69f2 6137 for (i = 1; i <= 24; i++)
09d92015 6138 {
9c3c69f2
PB
6139 a = val >> i;
6140 if ((val & ~(0xff << i)) == 0)
6141 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6142 }
a737bd4d 6143
c19d1205
ZW
6144 a = val & 0xff;
6145 if (val == ((a << 16) | a))
6146 return 0x100 | a;
6147 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6148 return 0x300 | a;
09d92015 6149
c19d1205
ZW
6150 a = val & 0xff00;
6151 if (val == ((a << 16) | a))
6152 return 0x200 | (a >> 8);
a737bd4d 6153
c19d1205 6154 return FAIL;
09d92015 6155}
5287ad62 6156/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6157
6158static void
5287ad62
JB
6159encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6160{
6161 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6162 && reg > 15)
6163 {
6164 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6165 {
6166 if (thumb_mode)
6167 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6168 fpu_vfp_ext_v3);
6169 else
6170 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6171 fpu_vfp_ext_v3);
6172 }
6173 else
6174 {
dcbf9037 6175 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6176 return;
6177 }
6178 }
6179
c19d1205 6180 switch (pos)
09d92015 6181 {
c19d1205
ZW
6182 case VFP_REG_Sd:
6183 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6184 break;
6185
6186 case VFP_REG_Sn:
6187 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6188 break;
6189
6190 case VFP_REG_Sm:
6191 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6192 break;
6193
5287ad62
JB
6194 case VFP_REG_Dd:
6195 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6196 break;
5f4273c7 6197
5287ad62
JB
6198 case VFP_REG_Dn:
6199 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6200 break;
5f4273c7 6201
5287ad62
JB
6202 case VFP_REG_Dm:
6203 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6204 break;
6205
c19d1205
ZW
6206 default:
6207 abort ();
09d92015 6208 }
09d92015
MM
6209}
6210
c19d1205 6211/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6212 if any, is handled by md_apply_fix. */
09d92015 6213static void
c19d1205 6214encode_arm_shift (int i)
09d92015 6215{
c19d1205
ZW
6216 if (inst.operands[i].shift_kind == SHIFT_RRX)
6217 inst.instruction |= SHIFT_ROR << 5;
6218 else
09d92015 6219 {
c19d1205
ZW
6220 inst.instruction |= inst.operands[i].shift_kind << 5;
6221 if (inst.operands[i].immisreg)
6222 {
6223 inst.instruction |= SHIFT_BY_REG;
6224 inst.instruction |= inst.operands[i].imm << 8;
6225 }
6226 else
6227 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6228 }
c19d1205 6229}
09d92015 6230
c19d1205
ZW
6231static void
6232encode_arm_shifter_operand (int i)
6233{
6234 if (inst.operands[i].isreg)
09d92015 6235 {
c19d1205
ZW
6236 inst.instruction |= inst.operands[i].reg;
6237 encode_arm_shift (i);
09d92015 6238 }
c19d1205
ZW
6239 else
6240 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6241}
6242
c19d1205 6243/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6244static void
c19d1205 6245encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6246{
c19d1205
ZW
6247 assert (inst.operands[i].isreg);
6248 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6249
c19d1205 6250 if (inst.operands[i].preind)
09d92015 6251 {
c19d1205
ZW
6252 if (is_t)
6253 {
6254 inst.error = _("instruction does not accept preindexed addressing");
6255 return;
6256 }
6257 inst.instruction |= PRE_INDEX;
6258 if (inst.operands[i].writeback)
6259 inst.instruction |= WRITE_BACK;
09d92015 6260
c19d1205
ZW
6261 }
6262 else if (inst.operands[i].postind)
6263 {
6264 assert (inst.operands[i].writeback);
6265 if (is_t)
6266 inst.instruction |= WRITE_BACK;
6267 }
6268 else /* unindexed - only for coprocessor */
09d92015 6269 {
c19d1205 6270 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6271 return;
6272 }
6273
c19d1205
ZW
6274 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6275 && (((inst.instruction & 0x000f0000) >> 16)
6276 == ((inst.instruction & 0x0000f000) >> 12)))
6277 as_warn ((inst.instruction & LOAD_BIT)
6278 ? _("destination register same as write-back base")
6279 : _("source register same as write-back base"));
09d92015
MM
6280}
6281
c19d1205
ZW
6282/* inst.operands[i] was set up by parse_address. Encode it into an
6283 ARM-format mode 2 load or store instruction. If is_t is true,
6284 reject forms that cannot be used with a T instruction (i.e. not
6285 post-indexed). */
a737bd4d 6286static void
c19d1205 6287encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6288{
c19d1205 6289 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6290
c19d1205 6291 if (inst.operands[i].immisreg)
09d92015 6292 {
c19d1205
ZW
6293 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6294 inst.instruction |= inst.operands[i].imm;
6295 if (!inst.operands[i].negative)
6296 inst.instruction |= INDEX_UP;
6297 if (inst.operands[i].shifted)
6298 {
6299 if (inst.operands[i].shift_kind == SHIFT_RRX)
6300 inst.instruction |= SHIFT_ROR << 5;
6301 else
6302 {
6303 inst.instruction |= inst.operands[i].shift_kind << 5;
6304 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6305 }
6306 }
09d92015 6307 }
c19d1205 6308 else /* immediate offset in inst.reloc */
09d92015 6309 {
c19d1205
ZW
6310 if (inst.reloc.type == BFD_RELOC_UNUSED)
6311 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6312 }
09d92015
MM
6313}
6314
c19d1205
ZW
6315/* inst.operands[i] was set up by parse_address. Encode it into an
6316 ARM-format mode 3 load or store instruction. Reject forms that
6317 cannot be used with such instructions. If is_t is true, reject
6318 forms that cannot be used with a T instruction (i.e. not
6319 post-indexed). */
6320static void
6321encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6322{
c19d1205 6323 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6324 {
c19d1205
ZW
6325 inst.error = _("instruction does not accept scaled register index");
6326 return;
09d92015 6327 }
a737bd4d 6328
c19d1205 6329 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6330
c19d1205
ZW
6331 if (inst.operands[i].immisreg)
6332 {
6333 inst.instruction |= inst.operands[i].imm;
6334 if (!inst.operands[i].negative)
6335 inst.instruction |= INDEX_UP;
6336 }
6337 else /* immediate offset in inst.reloc */
6338 {
6339 inst.instruction |= HWOFFSET_IMM;
6340 if (inst.reloc.type == BFD_RELOC_UNUSED)
6341 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6342 }
a737bd4d
NC
6343}
6344
c19d1205
ZW
6345/* inst.operands[i] was set up by parse_address. Encode it into an
6346 ARM-format instruction. Reject all forms which cannot be encoded
6347 into a coprocessor load/store instruction. If wb_ok is false,
6348 reject use of writeback; if unind_ok is false, reject use of
6349 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6350 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6351 (in which case it is preserved). */
09d92015 6352
c19d1205
ZW
6353static int
6354encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6355{
c19d1205 6356 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6357
c19d1205 6358 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6359
c19d1205 6360 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6361 {
c19d1205
ZW
6362 assert (!inst.operands[i].writeback);
6363 if (!unind_ok)
6364 {
6365 inst.error = _("instruction does not support unindexed addressing");
6366 return FAIL;
6367 }
6368 inst.instruction |= inst.operands[i].imm;
6369 inst.instruction |= INDEX_UP;
6370 return SUCCESS;
09d92015 6371 }
a737bd4d 6372
c19d1205
ZW
6373 if (inst.operands[i].preind)
6374 inst.instruction |= PRE_INDEX;
a737bd4d 6375
c19d1205 6376 if (inst.operands[i].writeback)
09d92015 6377 {
c19d1205
ZW
6378 if (inst.operands[i].reg == REG_PC)
6379 {
6380 inst.error = _("pc may not be used with write-back");
6381 return FAIL;
6382 }
6383 if (!wb_ok)
6384 {
6385 inst.error = _("instruction does not support writeback");
6386 return FAIL;
6387 }
6388 inst.instruction |= WRITE_BACK;
09d92015 6389 }
a737bd4d 6390
c19d1205
ZW
6391 if (reloc_override)
6392 inst.reloc.type = reloc_override;
4962c51a
MS
6393 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6394 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6395 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6396 {
6397 if (thumb_mode)
6398 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6399 else
6400 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6401 }
6402
c19d1205
ZW
6403 return SUCCESS;
6404}
a737bd4d 6405
c19d1205
ZW
6406/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6407 Determine whether it can be performed with a move instruction; if
6408 it can, convert inst.instruction to that move instruction and
6409 return 1; if it can't, convert inst.instruction to a literal-pool
6410 load and return 0. If this is not a valid thing to do in the
6411 current context, set inst.error and return 1.
a737bd4d 6412
c19d1205
ZW
6413 inst.operands[i] describes the destination register. */
6414
6415static int
6416move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6417{
53365c0d
PB
6418 unsigned long tbit;
6419
6420 if (thumb_p)
6421 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6422 else
6423 tbit = LOAD_BIT;
6424
6425 if ((inst.instruction & tbit) == 0)
09d92015 6426 {
c19d1205
ZW
6427 inst.error = _("invalid pseudo operation");
6428 return 1;
09d92015 6429 }
c19d1205 6430 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6431 {
6432 inst.error = _("constant expression expected");
c19d1205 6433 return 1;
09d92015 6434 }
c19d1205 6435 if (inst.reloc.exp.X_op == O_constant)
09d92015 6436 {
c19d1205
ZW
6437 if (thumb_p)
6438 {
53365c0d 6439 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6440 {
6441 /* This can be done with a mov(1) instruction. */
6442 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6443 inst.instruction |= inst.reloc.exp.X_add_number;
6444 return 1;
6445 }
6446 }
6447 else
6448 {
6449 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6450 if (value != FAIL)
6451 {
6452 /* This can be done with a mov instruction. */
6453 inst.instruction &= LITERAL_MASK;
6454 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6455 inst.instruction |= value & 0xfff;
6456 return 1;
6457 }
09d92015 6458
c19d1205
ZW
6459 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6460 if (value != FAIL)
6461 {
6462 /* This can be done with a mvn instruction. */
6463 inst.instruction &= LITERAL_MASK;
6464 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6465 inst.instruction |= value & 0xfff;
6466 return 1;
6467 }
6468 }
09d92015
MM
6469 }
6470
c19d1205
ZW
6471 if (add_to_lit_pool () == FAIL)
6472 {
6473 inst.error = _("literal pool insertion failed");
6474 return 1;
6475 }
6476 inst.operands[1].reg = REG_PC;
6477 inst.operands[1].isreg = 1;
6478 inst.operands[1].preind = 1;
6479 inst.reloc.pc_rel = 1;
6480 inst.reloc.type = (thumb_p
6481 ? BFD_RELOC_ARM_THUMB_OFFSET
6482 : (mode_3
6483 ? BFD_RELOC_ARM_HWLITERAL
6484 : BFD_RELOC_ARM_LITERAL));
6485 return 0;
09d92015
MM
6486}
6487
5f4273c7 6488/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6489 First some generics; their names are taken from the conventional
6490 bit positions for register arguments in ARM format instructions. */
09d92015 6491
a737bd4d 6492static void
c19d1205 6493do_noargs (void)
09d92015 6494{
c19d1205 6495}
a737bd4d 6496
c19d1205
ZW
6497static void
6498do_rd (void)
6499{
6500 inst.instruction |= inst.operands[0].reg << 12;
6501}
a737bd4d 6502
c19d1205
ZW
6503static void
6504do_rd_rm (void)
6505{
6506 inst.instruction |= inst.operands[0].reg << 12;
6507 inst.instruction |= inst.operands[1].reg;
6508}
09d92015 6509
c19d1205
ZW
6510static void
6511do_rd_rn (void)
6512{
6513 inst.instruction |= inst.operands[0].reg << 12;
6514 inst.instruction |= inst.operands[1].reg << 16;
6515}
a737bd4d 6516
c19d1205
ZW
6517static void
6518do_rn_rd (void)
6519{
6520 inst.instruction |= inst.operands[0].reg << 16;
6521 inst.instruction |= inst.operands[1].reg << 12;
6522}
09d92015 6523
c19d1205
ZW
6524static void
6525do_rd_rm_rn (void)
6526{
9a64e435 6527 unsigned Rn = inst.operands[2].reg;
708587a4 6528 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6529 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6530 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6531 _("Rn must not overlap other operands"));
c19d1205
ZW
6532 inst.instruction |= inst.operands[0].reg << 12;
6533 inst.instruction |= inst.operands[1].reg;
9a64e435 6534 inst.instruction |= Rn << 16;
c19d1205 6535}
09d92015 6536
c19d1205
ZW
6537static void
6538do_rd_rn_rm (void)
6539{
6540 inst.instruction |= inst.operands[0].reg << 12;
6541 inst.instruction |= inst.operands[1].reg << 16;
6542 inst.instruction |= inst.operands[2].reg;
6543}
a737bd4d 6544
c19d1205
ZW
6545static void
6546do_rm_rd_rn (void)
6547{
6548 inst.instruction |= inst.operands[0].reg;
6549 inst.instruction |= inst.operands[1].reg << 12;
6550 inst.instruction |= inst.operands[2].reg << 16;
6551}
09d92015 6552
c19d1205
ZW
6553static void
6554do_imm0 (void)
6555{
6556 inst.instruction |= inst.operands[0].imm;
6557}
09d92015 6558
c19d1205
ZW
6559static void
6560do_rd_cpaddr (void)
6561{
6562 inst.instruction |= inst.operands[0].reg << 12;
6563 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6564}
a737bd4d 6565
c19d1205
ZW
6566/* ARM instructions, in alphabetical order by function name (except
6567 that wrapper functions appear immediately after the function they
6568 wrap). */
09d92015 6569
c19d1205
ZW
6570/* This is a pseudo-op of the form "adr rd, label" to be converted
6571 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6572
6573static void
c19d1205 6574do_adr (void)
09d92015 6575{
c19d1205 6576 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6577
c19d1205
ZW
6578 /* Frag hacking will turn this into a sub instruction if the offset turns
6579 out to be negative. */
6580 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6581 inst.reloc.pc_rel = 1;
2fc8bdac 6582 inst.reloc.exp.X_add_number -= 8;
c19d1205 6583}
b99bd4ef 6584
c19d1205
ZW
6585/* This is a pseudo-op of the form "adrl rd, label" to be converted
6586 into a relative address of the form:
6587 add rd, pc, #low(label-.-8)"
6588 add rd, rd, #high(label-.-8)" */
b99bd4ef 6589
c19d1205
ZW
6590static void
6591do_adrl (void)
6592{
6593 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6594
c19d1205
ZW
6595 /* Frag hacking will turn this into a sub instruction if the offset turns
6596 out to be negative. */
6597 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6598 inst.reloc.pc_rel = 1;
6599 inst.size = INSN_SIZE * 2;
2fc8bdac 6600 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6601}
6602
b99bd4ef 6603static void
c19d1205 6604do_arit (void)
b99bd4ef 6605{
c19d1205
ZW
6606 if (!inst.operands[1].present)
6607 inst.operands[1].reg = inst.operands[0].reg;
6608 inst.instruction |= inst.operands[0].reg << 12;
6609 inst.instruction |= inst.operands[1].reg << 16;
6610 encode_arm_shifter_operand (2);
6611}
b99bd4ef 6612
62b3e311
PB
6613static void
6614do_barrier (void)
6615{
6616 if (inst.operands[0].present)
6617 {
6618 constraint ((inst.instruction & 0xf0) != 0x40
6619 && inst.operands[0].imm != 0xf,
bd3ba5d1 6620 _("bad barrier type"));
62b3e311
PB
6621 inst.instruction |= inst.operands[0].imm;
6622 }
6623 else
6624 inst.instruction |= 0xf;
6625}
6626
c19d1205
ZW
6627static void
6628do_bfc (void)
6629{
6630 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6631 constraint (msb > 32, _("bit-field extends past end of register"));
6632 /* The instruction encoding stores the LSB and MSB,
6633 not the LSB and width. */
6634 inst.instruction |= inst.operands[0].reg << 12;
6635 inst.instruction |= inst.operands[1].imm << 7;
6636 inst.instruction |= (msb - 1) << 16;
6637}
b99bd4ef 6638
c19d1205
ZW
6639static void
6640do_bfi (void)
6641{
6642 unsigned int msb;
b99bd4ef 6643
c19d1205
ZW
6644 /* #0 in second position is alternative syntax for bfc, which is
6645 the same instruction but with REG_PC in the Rm field. */
6646 if (!inst.operands[1].isreg)
6647 inst.operands[1].reg = REG_PC;
b99bd4ef 6648
c19d1205
ZW
6649 msb = inst.operands[2].imm + inst.operands[3].imm;
6650 constraint (msb > 32, _("bit-field extends past end of register"));
6651 /* The instruction encoding stores the LSB and MSB,
6652 not the LSB and width. */
6653 inst.instruction |= inst.operands[0].reg << 12;
6654 inst.instruction |= inst.operands[1].reg;
6655 inst.instruction |= inst.operands[2].imm << 7;
6656 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6657}
6658
b99bd4ef 6659static void
c19d1205 6660do_bfx (void)
b99bd4ef 6661{
c19d1205
ZW
6662 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6663 _("bit-field extends past end of register"));
6664 inst.instruction |= inst.operands[0].reg << 12;
6665 inst.instruction |= inst.operands[1].reg;
6666 inst.instruction |= inst.operands[2].imm << 7;
6667 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6668}
09d92015 6669
c19d1205
ZW
6670/* ARM V5 breakpoint instruction (argument parse)
6671 BKPT <16 bit unsigned immediate>
6672 Instruction is not conditional.
6673 The bit pattern given in insns[] has the COND_ALWAYS condition,
6674 and it is an error if the caller tried to override that. */
b99bd4ef 6675
c19d1205
ZW
6676static void
6677do_bkpt (void)
6678{
6679 /* Top 12 of 16 bits to bits 19:8. */
6680 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6681
c19d1205
ZW
6682 /* Bottom 4 of 16 bits to bits 3:0. */
6683 inst.instruction |= inst.operands[0].imm & 0xf;
6684}
09d92015 6685
c19d1205
ZW
6686static void
6687encode_branch (int default_reloc)
6688{
6689 if (inst.operands[0].hasreloc)
6690 {
6691 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6692 _("the only suffix valid here is '(plt)'"));
6693 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6694 }
b99bd4ef 6695 else
c19d1205
ZW
6696 {
6697 inst.reloc.type = default_reloc;
c19d1205 6698 }
2fc8bdac 6699 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6700}
6701
b99bd4ef 6702static void
c19d1205 6703do_branch (void)
b99bd4ef 6704{
39b41c9c
PB
6705#ifdef OBJ_ELF
6706 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6707 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6708 else
6709#endif
6710 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6711}
6712
6713static void
6714do_bl (void)
6715{
6716#ifdef OBJ_ELF
6717 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6718 {
6719 if (inst.cond == COND_ALWAYS)
6720 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6721 else
6722 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6723 }
6724 else
6725#endif
6726 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6727}
b99bd4ef 6728
c19d1205
ZW
6729/* ARM V5 branch-link-exchange instruction (argument parse)
6730 BLX <target_addr> ie BLX(1)
6731 BLX{<condition>} <Rm> ie BLX(2)
6732 Unfortunately, there are two different opcodes for this mnemonic.
6733 So, the insns[].value is not used, and the code here zaps values
6734 into inst.instruction.
6735 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6736
c19d1205
ZW
6737static void
6738do_blx (void)
6739{
6740 if (inst.operands[0].isreg)
b99bd4ef 6741 {
c19d1205
ZW
6742 /* Arg is a register; the opcode provided by insns[] is correct.
6743 It is not illegal to do "blx pc", just useless. */
6744 if (inst.operands[0].reg == REG_PC)
6745 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6746
c19d1205
ZW
6747 inst.instruction |= inst.operands[0].reg;
6748 }
6749 else
b99bd4ef 6750 {
c19d1205
ZW
6751 /* Arg is an address; this instruction cannot be executed
6752 conditionally, and the opcode must be adjusted. */
6753 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6754 inst.instruction = 0xfa000000;
39b41c9c
PB
6755#ifdef OBJ_ELF
6756 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6757 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6758 else
6759#endif
6760 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6761 }
c19d1205
ZW
6762}
6763
6764static void
6765do_bx (void)
6766{
845b51d6
PB
6767 bfd_boolean want_reloc;
6768
c19d1205
ZW
6769 if (inst.operands[0].reg == REG_PC)
6770 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6771
c19d1205 6772 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6773 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6774 it is for ARMv4t or earlier. */
6775 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6776 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6777 want_reloc = TRUE;
6778
5ad34203 6779#ifdef OBJ_ELF
845b51d6 6780 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6781#endif
584206db 6782 want_reloc = FALSE;
845b51d6
PB
6783
6784 if (want_reloc)
6785 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6786}
6787
c19d1205
ZW
6788
6789/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6790
6791static void
c19d1205 6792do_bxj (void)
a737bd4d 6793{
c19d1205
ZW
6794 if (inst.operands[0].reg == REG_PC)
6795 as_tsktsk (_("use of r15 in bxj is not really useful"));
6796
6797 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6798}
6799
c19d1205
ZW
6800/* Co-processor data operation:
6801 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6802 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6803static void
6804do_cdp (void)
6805{
6806 inst.instruction |= inst.operands[0].reg << 8;
6807 inst.instruction |= inst.operands[1].imm << 20;
6808 inst.instruction |= inst.operands[2].reg << 12;
6809 inst.instruction |= inst.operands[3].reg << 16;
6810 inst.instruction |= inst.operands[4].reg;
6811 inst.instruction |= inst.operands[5].imm << 5;
6812}
a737bd4d
NC
6813
6814static void
c19d1205 6815do_cmp (void)
a737bd4d 6816{
c19d1205
ZW
6817 inst.instruction |= inst.operands[0].reg << 16;
6818 encode_arm_shifter_operand (1);
a737bd4d
NC
6819}
6820
c19d1205
ZW
6821/* Transfer between coprocessor and ARM registers.
6822 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6823 MRC2
6824 MCR{cond}
6825 MCR2
6826
6827 No special properties. */
09d92015
MM
6828
6829static void
c19d1205 6830do_co_reg (void)
09d92015 6831{
c19d1205
ZW
6832 inst.instruction |= inst.operands[0].reg << 8;
6833 inst.instruction |= inst.operands[1].imm << 21;
6834 inst.instruction |= inst.operands[2].reg << 12;
6835 inst.instruction |= inst.operands[3].reg << 16;
6836 inst.instruction |= inst.operands[4].reg;
6837 inst.instruction |= inst.operands[5].imm << 5;
6838}
09d92015 6839
c19d1205
ZW
6840/* Transfer between coprocessor register and pair of ARM registers.
6841 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6842 MCRR2
6843 MRRC{cond}
6844 MRRC2
b99bd4ef 6845
c19d1205 6846 Two XScale instructions are special cases of these:
09d92015 6847
c19d1205
ZW
6848 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6849 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6850
5f4273c7 6851 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6852
c19d1205
ZW
6853static void
6854do_co_reg2c (void)
6855{
6856 inst.instruction |= inst.operands[0].reg << 8;
6857 inst.instruction |= inst.operands[1].imm << 4;
6858 inst.instruction |= inst.operands[2].reg << 12;
6859 inst.instruction |= inst.operands[3].reg << 16;
6860 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6861}
6862
c19d1205
ZW
6863static void
6864do_cpsi (void)
6865{
6866 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6867 if (inst.operands[1].present)
6868 {
6869 inst.instruction |= CPSI_MMOD;
6870 inst.instruction |= inst.operands[1].imm;
6871 }
c19d1205 6872}
b99bd4ef 6873
62b3e311
PB
6874static void
6875do_dbg (void)
6876{
6877 inst.instruction |= inst.operands[0].imm;
6878}
6879
b99bd4ef 6880static void
c19d1205 6881do_it (void)
b99bd4ef 6882{
c19d1205
ZW
6883 /* There is no IT instruction in ARM mode. We
6884 process it but do not generate code for it. */
6885 inst.size = 0;
09d92015 6886}
b99bd4ef 6887
09d92015 6888static void
c19d1205 6889do_ldmstm (void)
ea6ef066 6890{
c19d1205
ZW
6891 int base_reg = inst.operands[0].reg;
6892 int range = inst.operands[1].imm;
ea6ef066 6893
c19d1205
ZW
6894 inst.instruction |= base_reg << 16;
6895 inst.instruction |= range;
ea6ef066 6896
c19d1205
ZW
6897 if (inst.operands[1].writeback)
6898 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6899
c19d1205 6900 if (inst.operands[0].writeback)
ea6ef066 6901 {
c19d1205
ZW
6902 inst.instruction |= WRITE_BACK;
6903 /* Check for unpredictable uses of writeback. */
6904 if (inst.instruction & LOAD_BIT)
09d92015 6905 {
c19d1205
ZW
6906 /* Not allowed in LDM type 2. */
6907 if ((inst.instruction & LDM_TYPE_2_OR_3)
6908 && ((range & (1 << REG_PC)) == 0))
6909 as_warn (_("writeback of base register is UNPREDICTABLE"));
6910 /* Only allowed if base reg not in list for other types. */
6911 else if (range & (1 << base_reg))
6912 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6913 }
6914 else /* STM. */
6915 {
6916 /* Not allowed for type 2. */
6917 if (inst.instruction & LDM_TYPE_2_OR_3)
6918 as_warn (_("writeback of base register is UNPREDICTABLE"));
6919 /* Only allowed if base reg not in list, or first in list. */
6920 else if ((range & (1 << base_reg))
6921 && (range & ((1 << base_reg) - 1)))
6922 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6923 }
ea6ef066 6924 }
a737bd4d
NC
6925}
6926
c19d1205
ZW
6927/* ARMv5TE load-consecutive (argument parse)
6928 Mode is like LDRH.
6929
6930 LDRccD R, mode
6931 STRccD R, mode. */
6932
a737bd4d 6933static void
c19d1205 6934do_ldrd (void)
a737bd4d 6935{
c19d1205
ZW
6936 constraint (inst.operands[0].reg % 2 != 0,
6937 _("first destination register must be even"));
6938 constraint (inst.operands[1].present
6939 && inst.operands[1].reg != inst.operands[0].reg + 1,
6940 _("can only load two consecutive registers"));
6941 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6942 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6943
c19d1205
ZW
6944 if (!inst.operands[1].present)
6945 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 6946
c19d1205 6947 if (inst.instruction & LOAD_BIT)
a737bd4d 6948 {
c19d1205
ZW
6949 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6950 register and the first register written; we have to diagnose
6951 overlap between the base and the second register written here. */
ea6ef066 6952
c19d1205
ZW
6953 if (inst.operands[2].reg == inst.operands[1].reg
6954 && (inst.operands[2].writeback || inst.operands[2].postind))
6955 as_warn (_("base register written back, and overlaps "
6956 "second destination register"));
b05fe5cf 6957
c19d1205
ZW
6958 /* For an index-register load, the index register must not overlap the
6959 destination (even if not write-back). */
6960 else if (inst.operands[2].immisreg
ca3f61f7
NC
6961 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6962 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6963 as_warn (_("index register overlaps destination register"));
b05fe5cf 6964 }
c19d1205
ZW
6965
6966 inst.instruction |= inst.operands[0].reg << 12;
6967 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6968}
6969
6970static void
c19d1205 6971do_ldrex (void)
b05fe5cf 6972{
c19d1205
ZW
6973 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6974 || inst.operands[1].postind || inst.operands[1].writeback
6975 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6976 || inst.operands[1].negative
6977 /* This can arise if the programmer has written
6978 strex rN, rM, foo
6979 or if they have mistakenly used a register name as the last
6980 operand, eg:
6981 strex rN, rM, rX
6982 It is very difficult to distinguish between these two cases
6983 because "rX" might actually be a label. ie the register
6984 name has been occluded by a symbol of the same name. So we
6985 just generate a general 'bad addressing mode' type error
6986 message and leave it up to the programmer to discover the
6987 true cause and fix their mistake. */
6988 || (inst.operands[1].reg == REG_PC),
6989 BAD_ADDR_MODE);
b05fe5cf 6990
c19d1205
ZW
6991 constraint (inst.reloc.exp.X_op != O_constant
6992 || inst.reloc.exp.X_add_number != 0,
6993 _("offset must be zero in ARM encoding"));
b05fe5cf 6994
c19d1205
ZW
6995 inst.instruction |= inst.operands[0].reg << 12;
6996 inst.instruction |= inst.operands[1].reg << 16;
6997 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
6998}
6999
7000static void
c19d1205 7001do_ldrexd (void)
b05fe5cf 7002{
c19d1205
ZW
7003 constraint (inst.operands[0].reg % 2 != 0,
7004 _("even register required"));
7005 constraint (inst.operands[1].present
7006 && inst.operands[1].reg != inst.operands[0].reg + 1,
7007 _("can only load two consecutive registers"));
7008 /* If op 1 were present and equal to PC, this function wouldn't
7009 have been called in the first place. */
7010 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7011
c19d1205
ZW
7012 inst.instruction |= inst.operands[0].reg << 12;
7013 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7014}
7015
7016static void
c19d1205 7017do_ldst (void)
b05fe5cf 7018{
c19d1205
ZW
7019 inst.instruction |= inst.operands[0].reg << 12;
7020 if (!inst.operands[1].isreg)
7021 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7022 return;
c19d1205 7023 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7024}
7025
7026static void
c19d1205 7027do_ldstt (void)
b05fe5cf 7028{
c19d1205
ZW
7029 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7030 reject [Rn,...]. */
7031 if (inst.operands[1].preind)
b05fe5cf 7032 {
bd3ba5d1
NC
7033 constraint (inst.reloc.exp.X_op != O_constant
7034 || inst.reloc.exp.X_add_number != 0,
c19d1205 7035 _("this instruction requires a post-indexed address"));
b05fe5cf 7036
c19d1205
ZW
7037 inst.operands[1].preind = 0;
7038 inst.operands[1].postind = 1;
7039 inst.operands[1].writeback = 1;
b05fe5cf 7040 }
c19d1205
ZW
7041 inst.instruction |= inst.operands[0].reg << 12;
7042 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7043}
b05fe5cf 7044
c19d1205 7045/* Halfword and signed-byte load/store operations. */
b05fe5cf 7046
c19d1205
ZW
7047static void
7048do_ldstv4 (void)
7049{
7050 inst.instruction |= inst.operands[0].reg << 12;
7051 if (!inst.operands[1].isreg)
7052 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7053 return;
c19d1205 7054 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7055}
7056
7057static void
c19d1205 7058do_ldsttv4 (void)
b05fe5cf 7059{
c19d1205
ZW
7060 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7061 reject [Rn,...]. */
7062 if (inst.operands[1].preind)
b05fe5cf 7063 {
bd3ba5d1
NC
7064 constraint (inst.reloc.exp.X_op != O_constant
7065 || inst.reloc.exp.X_add_number != 0,
c19d1205 7066 _("this instruction requires a post-indexed address"));
b05fe5cf 7067
c19d1205
ZW
7068 inst.operands[1].preind = 0;
7069 inst.operands[1].postind = 1;
7070 inst.operands[1].writeback = 1;
b05fe5cf 7071 }
c19d1205
ZW
7072 inst.instruction |= inst.operands[0].reg << 12;
7073 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7074}
b05fe5cf 7075
c19d1205
ZW
7076/* Co-processor register load/store.
7077 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7078static void
7079do_lstc (void)
7080{
7081 inst.instruction |= inst.operands[0].reg << 8;
7082 inst.instruction |= inst.operands[1].reg << 12;
7083 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7084}
7085
b05fe5cf 7086static void
c19d1205 7087do_mlas (void)
b05fe5cf 7088{
8fb9d7b9 7089 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7090 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7091 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7092 && !(inst.instruction & 0x00400000))
8fb9d7b9 7093 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7094
c19d1205
ZW
7095 inst.instruction |= inst.operands[0].reg << 16;
7096 inst.instruction |= inst.operands[1].reg;
7097 inst.instruction |= inst.operands[2].reg << 8;
7098 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7099}
b05fe5cf 7100
c19d1205
ZW
7101static void
7102do_mov (void)
7103{
7104 inst.instruction |= inst.operands[0].reg << 12;
7105 encode_arm_shifter_operand (1);
7106}
b05fe5cf 7107
c19d1205
ZW
7108/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7109static void
7110do_mov16 (void)
7111{
b6895b4f
PB
7112 bfd_vma imm;
7113 bfd_boolean top;
7114
7115 top = (inst.instruction & 0x00400000) != 0;
7116 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7117 _(":lower16: not allowed this instruction"));
7118 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7119 _(":upper16: not allowed instruction"));
c19d1205 7120 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7121 if (inst.reloc.type == BFD_RELOC_UNUSED)
7122 {
7123 imm = inst.reloc.exp.X_add_number;
7124 /* The value is in two pieces: 0:11, 16:19. */
7125 inst.instruction |= (imm & 0x00000fff);
7126 inst.instruction |= (imm & 0x0000f000) << 4;
7127 }
b05fe5cf 7128}
b99bd4ef 7129
037e8744
JB
7130static void do_vfp_nsyn_opcode (const char *);
7131
7132static int
7133do_vfp_nsyn_mrs (void)
7134{
7135 if (inst.operands[0].isvec)
7136 {
7137 if (inst.operands[1].reg != 1)
7138 first_error (_("operand 1 must be FPSCR"));
7139 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7140 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7141 do_vfp_nsyn_opcode ("fmstat");
7142 }
7143 else if (inst.operands[1].isvec)
7144 do_vfp_nsyn_opcode ("fmrx");
7145 else
7146 return FAIL;
5f4273c7 7147
037e8744
JB
7148 return SUCCESS;
7149}
7150
7151static int
7152do_vfp_nsyn_msr (void)
7153{
7154 if (inst.operands[0].isvec)
7155 do_vfp_nsyn_opcode ("fmxr");
7156 else
7157 return FAIL;
7158
7159 return SUCCESS;
7160}
7161
b99bd4ef 7162static void
c19d1205 7163do_mrs (void)
b99bd4ef 7164{
037e8744
JB
7165 if (do_vfp_nsyn_mrs () == SUCCESS)
7166 return;
7167
c19d1205
ZW
7168 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7169 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7170 != (PSR_c|PSR_f),
7171 _("'CPSR' or 'SPSR' expected"));
7172 inst.instruction |= inst.operands[0].reg << 12;
7173 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7174}
b99bd4ef 7175
c19d1205
ZW
7176/* Two possible forms:
7177 "{C|S}PSR_<field>, Rm",
7178 "{C|S}PSR_f, #expression". */
b99bd4ef 7179
c19d1205
ZW
7180static void
7181do_msr (void)
7182{
037e8744
JB
7183 if (do_vfp_nsyn_msr () == SUCCESS)
7184 return;
7185
c19d1205
ZW
7186 inst.instruction |= inst.operands[0].imm;
7187 if (inst.operands[1].isreg)
7188 inst.instruction |= inst.operands[1].reg;
7189 else
b99bd4ef 7190 {
c19d1205
ZW
7191 inst.instruction |= INST_IMMEDIATE;
7192 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7193 inst.reloc.pc_rel = 0;
b99bd4ef 7194 }
b99bd4ef
NC
7195}
7196
c19d1205
ZW
7197static void
7198do_mul (void)
a737bd4d 7199{
c19d1205
ZW
7200 if (!inst.operands[2].present)
7201 inst.operands[2].reg = inst.operands[0].reg;
7202 inst.instruction |= inst.operands[0].reg << 16;
7203 inst.instruction |= inst.operands[1].reg;
7204 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7205
8fb9d7b9
MS
7206 if (inst.operands[0].reg == inst.operands[1].reg
7207 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7208 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7209}
7210
c19d1205
ZW
7211/* Long Multiply Parser
7212 UMULL RdLo, RdHi, Rm, Rs
7213 SMULL RdLo, RdHi, Rm, Rs
7214 UMLAL RdLo, RdHi, Rm, Rs
7215 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7216
7217static void
c19d1205 7218do_mull (void)
b99bd4ef 7219{
c19d1205
ZW
7220 inst.instruction |= inst.operands[0].reg << 12;
7221 inst.instruction |= inst.operands[1].reg << 16;
7222 inst.instruction |= inst.operands[2].reg;
7223 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7224
682b27ad
PB
7225 /* rdhi and rdlo must be different. */
7226 if (inst.operands[0].reg == inst.operands[1].reg)
7227 as_tsktsk (_("rdhi and rdlo must be different"));
7228
7229 /* rdhi, rdlo and rm must all be different before armv6. */
7230 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7231 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7232 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7233 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7234}
b99bd4ef 7235
c19d1205
ZW
7236static void
7237do_nop (void)
7238{
7239 if (inst.operands[0].present)
7240 {
7241 /* Architectural NOP hints are CPSR sets with no bits selected. */
7242 inst.instruction &= 0xf0000000;
7243 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7244 }
b99bd4ef
NC
7245}
7246
c19d1205
ZW
7247/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7248 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7249 Condition defaults to COND_ALWAYS.
7250 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7251
7252static void
c19d1205 7253do_pkhbt (void)
b99bd4ef 7254{
c19d1205
ZW
7255 inst.instruction |= inst.operands[0].reg << 12;
7256 inst.instruction |= inst.operands[1].reg << 16;
7257 inst.instruction |= inst.operands[2].reg;
7258 if (inst.operands[3].present)
7259 encode_arm_shift (3);
7260}
b99bd4ef 7261
c19d1205 7262/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7263
c19d1205
ZW
7264static void
7265do_pkhtb (void)
7266{
7267 if (!inst.operands[3].present)
b99bd4ef 7268 {
c19d1205
ZW
7269 /* If the shift specifier is omitted, turn the instruction
7270 into pkhbt rd, rm, rn. */
7271 inst.instruction &= 0xfff00010;
7272 inst.instruction |= inst.operands[0].reg << 12;
7273 inst.instruction |= inst.operands[1].reg;
7274 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7275 }
7276 else
7277 {
c19d1205
ZW
7278 inst.instruction |= inst.operands[0].reg << 12;
7279 inst.instruction |= inst.operands[1].reg << 16;
7280 inst.instruction |= inst.operands[2].reg;
7281 encode_arm_shift (3);
b99bd4ef
NC
7282 }
7283}
7284
c19d1205
ZW
7285/* ARMv5TE: Preload-Cache
7286
7287 PLD <addr_mode>
7288
7289 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7290
7291static void
c19d1205 7292do_pld (void)
b99bd4ef 7293{
c19d1205
ZW
7294 constraint (!inst.operands[0].isreg,
7295 _("'[' expected after PLD mnemonic"));
7296 constraint (inst.operands[0].postind,
7297 _("post-indexed expression used in preload instruction"));
7298 constraint (inst.operands[0].writeback,
7299 _("writeback used in preload instruction"));
7300 constraint (!inst.operands[0].preind,
7301 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7302 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7303}
b99bd4ef 7304
62b3e311
PB
7305/* ARMv7: PLI <addr_mode> */
7306static void
7307do_pli (void)
7308{
7309 constraint (!inst.operands[0].isreg,
7310 _("'[' expected after PLI mnemonic"));
7311 constraint (inst.operands[0].postind,
7312 _("post-indexed expression used in preload instruction"));
7313 constraint (inst.operands[0].writeback,
7314 _("writeback used in preload instruction"));
7315 constraint (!inst.operands[0].preind,
7316 _("unindexed addressing used in preload instruction"));
7317 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7318 inst.instruction &= ~PRE_INDEX;
7319}
7320
c19d1205
ZW
7321static void
7322do_push_pop (void)
7323{
7324 inst.operands[1] = inst.operands[0];
7325 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7326 inst.operands[0].isreg = 1;
7327 inst.operands[0].writeback = 1;
7328 inst.operands[0].reg = REG_SP;
7329 do_ldmstm ();
7330}
b99bd4ef 7331
c19d1205
ZW
7332/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7333 word at the specified address and the following word
7334 respectively.
7335 Unconditionally executed.
7336 Error if Rn is R15. */
b99bd4ef 7337
c19d1205
ZW
7338static void
7339do_rfe (void)
7340{
7341 inst.instruction |= inst.operands[0].reg << 16;
7342 if (inst.operands[0].writeback)
7343 inst.instruction |= WRITE_BACK;
7344}
b99bd4ef 7345
c19d1205 7346/* ARM V6 ssat (argument parse). */
b99bd4ef 7347
c19d1205
ZW
7348static void
7349do_ssat (void)
7350{
7351 inst.instruction |= inst.operands[0].reg << 12;
7352 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7353 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7354
c19d1205
ZW
7355 if (inst.operands[3].present)
7356 encode_arm_shift (3);
b99bd4ef
NC
7357}
7358
c19d1205 7359/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7360
7361static void
c19d1205 7362do_usat (void)
b99bd4ef 7363{
c19d1205
ZW
7364 inst.instruction |= inst.operands[0].reg << 12;
7365 inst.instruction |= inst.operands[1].imm << 16;
7366 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7367
c19d1205
ZW
7368 if (inst.operands[3].present)
7369 encode_arm_shift (3);
b99bd4ef
NC
7370}
7371
c19d1205 7372/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7373
7374static void
c19d1205 7375do_ssat16 (void)
09d92015 7376{
c19d1205
ZW
7377 inst.instruction |= inst.operands[0].reg << 12;
7378 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7379 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7380}
7381
c19d1205
ZW
7382static void
7383do_usat16 (void)
a737bd4d 7384{
c19d1205
ZW
7385 inst.instruction |= inst.operands[0].reg << 12;
7386 inst.instruction |= inst.operands[1].imm << 16;
7387 inst.instruction |= inst.operands[2].reg;
7388}
a737bd4d 7389
c19d1205
ZW
7390/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7391 preserving the other bits.
a737bd4d 7392
c19d1205
ZW
7393 setend <endian_specifier>, where <endian_specifier> is either
7394 BE or LE. */
a737bd4d 7395
c19d1205
ZW
7396static void
7397do_setend (void)
7398{
7399 if (inst.operands[0].imm)
7400 inst.instruction |= 0x200;
a737bd4d
NC
7401}
7402
7403static void
c19d1205 7404do_shift (void)
a737bd4d 7405{
c19d1205
ZW
7406 unsigned int Rm = (inst.operands[1].present
7407 ? inst.operands[1].reg
7408 : inst.operands[0].reg);
a737bd4d 7409
c19d1205
ZW
7410 inst.instruction |= inst.operands[0].reg << 12;
7411 inst.instruction |= Rm;
7412 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7413 {
c19d1205
ZW
7414 inst.instruction |= inst.operands[2].reg << 8;
7415 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7416 }
7417 else
c19d1205 7418 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7419}
7420
09d92015 7421static void
3eb17e6b 7422do_smc (void)
09d92015 7423{
3eb17e6b 7424 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7425 inst.reloc.pc_rel = 0;
09d92015
MM
7426}
7427
09d92015 7428static void
c19d1205 7429do_swi (void)
09d92015 7430{
c19d1205
ZW
7431 inst.reloc.type = BFD_RELOC_ARM_SWI;
7432 inst.reloc.pc_rel = 0;
09d92015
MM
7433}
7434
c19d1205
ZW
7435/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7436 SMLAxy{cond} Rd,Rm,Rs,Rn
7437 SMLAWy{cond} Rd,Rm,Rs,Rn
7438 Error if any register is R15. */
e16bb312 7439
c19d1205
ZW
7440static void
7441do_smla (void)
e16bb312 7442{
c19d1205
ZW
7443 inst.instruction |= inst.operands[0].reg << 16;
7444 inst.instruction |= inst.operands[1].reg;
7445 inst.instruction |= inst.operands[2].reg << 8;
7446 inst.instruction |= inst.operands[3].reg << 12;
7447}
a737bd4d 7448
c19d1205
ZW
7449/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7450 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7451 Error if any register is R15.
7452 Warning if Rdlo == Rdhi. */
a737bd4d 7453
c19d1205
ZW
7454static void
7455do_smlal (void)
7456{
7457 inst.instruction |= inst.operands[0].reg << 12;
7458 inst.instruction |= inst.operands[1].reg << 16;
7459 inst.instruction |= inst.operands[2].reg;
7460 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7461
c19d1205
ZW
7462 if (inst.operands[0].reg == inst.operands[1].reg)
7463 as_tsktsk (_("rdhi and rdlo must be different"));
7464}
a737bd4d 7465
c19d1205
ZW
7466/* ARM V5E (El Segundo) signed-multiply (argument parse)
7467 SMULxy{cond} Rd,Rm,Rs
7468 Error if any register is R15. */
a737bd4d 7469
c19d1205
ZW
7470static void
7471do_smul (void)
7472{
7473 inst.instruction |= inst.operands[0].reg << 16;
7474 inst.instruction |= inst.operands[1].reg;
7475 inst.instruction |= inst.operands[2].reg << 8;
7476}
a737bd4d 7477
b6702015
PB
7478/* ARM V6 srs (argument parse). The variable fields in the encoding are
7479 the same for both ARM and Thumb-2. */
a737bd4d 7480
c19d1205
ZW
7481static void
7482do_srs (void)
7483{
b6702015
PB
7484 int reg;
7485
7486 if (inst.operands[0].present)
7487 {
7488 reg = inst.operands[0].reg;
7489 constraint (reg != 13, _("SRS base register must be r13"));
7490 }
7491 else
7492 reg = 13;
7493
7494 inst.instruction |= reg << 16;
7495 inst.instruction |= inst.operands[1].imm;
7496 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7497 inst.instruction |= WRITE_BACK;
7498}
a737bd4d 7499
c19d1205 7500/* ARM V6 strex (argument parse). */
a737bd4d 7501
c19d1205
ZW
7502static void
7503do_strex (void)
7504{
7505 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7506 || inst.operands[2].postind || inst.operands[2].writeback
7507 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7508 || inst.operands[2].negative
7509 /* See comment in do_ldrex(). */
7510 || (inst.operands[2].reg == REG_PC),
7511 BAD_ADDR_MODE);
a737bd4d 7512
c19d1205
ZW
7513 constraint (inst.operands[0].reg == inst.operands[1].reg
7514 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7515
c19d1205
ZW
7516 constraint (inst.reloc.exp.X_op != O_constant
7517 || inst.reloc.exp.X_add_number != 0,
7518 _("offset must be zero in ARM encoding"));
a737bd4d 7519
c19d1205
ZW
7520 inst.instruction |= inst.operands[0].reg << 12;
7521 inst.instruction |= inst.operands[1].reg;
7522 inst.instruction |= inst.operands[2].reg << 16;
7523 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7524}
7525
7526static void
c19d1205 7527do_strexd (void)
e16bb312 7528{
c19d1205
ZW
7529 constraint (inst.operands[1].reg % 2 != 0,
7530 _("even register required"));
7531 constraint (inst.operands[2].present
7532 && inst.operands[2].reg != inst.operands[1].reg + 1,
7533 _("can only store two consecutive registers"));
7534 /* If op 2 were present and equal to PC, this function wouldn't
7535 have been called in the first place. */
7536 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7537
c19d1205
ZW
7538 constraint (inst.operands[0].reg == inst.operands[1].reg
7539 || inst.operands[0].reg == inst.operands[1].reg + 1
7540 || inst.operands[0].reg == inst.operands[3].reg,
7541 BAD_OVERLAP);
e16bb312 7542
c19d1205
ZW
7543 inst.instruction |= inst.operands[0].reg << 12;
7544 inst.instruction |= inst.operands[1].reg;
7545 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7546}
7547
c19d1205
ZW
7548/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7549 extends it to 32-bits, and adds the result to a value in another
7550 register. You can specify a rotation by 0, 8, 16, or 24 bits
7551 before extracting the 16-bit value.
7552 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7553 Condition defaults to COND_ALWAYS.
7554 Error if any register uses R15. */
7555
e16bb312 7556static void
c19d1205 7557do_sxtah (void)
e16bb312 7558{
c19d1205
ZW
7559 inst.instruction |= inst.operands[0].reg << 12;
7560 inst.instruction |= inst.operands[1].reg << 16;
7561 inst.instruction |= inst.operands[2].reg;
7562 inst.instruction |= inst.operands[3].imm << 10;
7563}
e16bb312 7564
c19d1205 7565/* ARM V6 SXTH.
e16bb312 7566
c19d1205
ZW
7567 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7568 Condition defaults to COND_ALWAYS.
7569 Error if any register uses R15. */
e16bb312
NC
7570
7571static void
c19d1205 7572do_sxth (void)
e16bb312 7573{
c19d1205
ZW
7574 inst.instruction |= inst.operands[0].reg << 12;
7575 inst.instruction |= inst.operands[1].reg;
7576 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7577}
c19d1205
ZW
7578\f
7579/* VFP instructions. In a logical order: SP variant first, monad
7580 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7581
7582static void
c19d1205 7583do_vfp_sp_monadic (void)
e16bb312 7584{
5287ad62
JB
7585 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7586 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7587}
7588
7589static void
c19d1205 7590do_vfp_sp_dyadic (void)
e16bb312 7591{
5287ad62
JB
7592 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7593 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7594 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7595}
7596
7597static void
c19d1205 7598do_vfp_sp_compare_z (void)
e16bb312 7599{
5287ad62 7600 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7601}
7602
7603static void
c19d1205 7604do_vfp_dp_sp_cvt (void)
e16bb312 7605{
5287ad62
JB
7606 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7607 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7608}
7609
7610static void
c19d1205 7611do_vfp_sp_dp_cvt (void)
e16bb312 7612{
5287ad62
JB
7613 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7614 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7615}
7616
7617static void
c19d1205 7618do_vfp_reg_from_sp (void)
e16bb312 7619{
c19d1205 7620 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7621 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7622}
7623
7624static void
c19d1205 7625do_vfp_reg2_from_sp2 (void)
e16bb312 7626{
c19d1205
ZW
7627 constraint (inst.operands[2].imm != 2,
7628 _("only two consecutive VFP SP registers allowed here"));
7629 inst.instruction |= inst.operands[0].reg << 12;
7630 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7631 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7632}
7633
7634static void
c19d1205 7635do_vfp_sp_from_reg (void)
e16bb312 7636{
5287ad62 7637 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7638 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7639}
7640
7641static void
c19d1205 7642do_vfp_sp2_from_reg2 (void)
e16bb312 7643{
c19d1205
ZW
7644 constraint (inst.operands[0].imm != 2,
7645 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7646 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7647 inst.instruction |= inst.operands[1].reg << 12;
7648 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7649}
7650
7651static void
c19d1205 7652do_vfp_sp_ldst (void)
e16bb312 7653{
5287ad62 7654 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7655 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7656}
7657
7658static void
c19d1205 7659do_vfp_dp_ldst (void)
e16bb312 7660{
5287ad62 7661 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7662 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7663}
7664
c19d1205 7665
e16bb312 7666static void
c19d1205 7667vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7668{
c19d1205
ZW
7669 if (inst.operands[0].writeback)
7670 inst.instruction |= WRITE_BACK;
7671 else
7672 constraint (ldstm_type != VFP_LDSTMIA,
7673 _("this addressing mode requires base-register writeback"));
7674 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7675 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7676 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7677}
7678
7679static void
c19d1205 7680vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7681{
c19d1205 7682 int count;
e16bb312 7683
c19d1205
ZW
7684 if (inst.operands[0].writeback)
7685 inst.instruction |= WRITE_BACK;
7686 else
7687 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7688 _("this addressing mode requires base-register writeback"));
e16bb312 7689
c19d1205 7690 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7691 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7692
c19d1205
ZW
7693 count = inst.operands[1].imm << 1;
7694 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7695 count += 1;
e16bb312 7696
c19d1205 7697 inst.instruction |= count;
e16bb312
NC
7698}
7699
7700static void
c19d1205 7701do_vfp_sp_ldstmia (void)
e16bb312 7702{
c19d1205 7703 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7704}
7705
7706static void
c19d1205 7707do_vfp_sp_ldstmdb (void)
e16bb312 7708{
c19d1205 7709 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7710}
7711
7712static void
c19d1205 7713do_vfp_dp_ldstmia (void)
e16bb312 7714{
c19d1205 7715 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7716}
7717
7718static void
c19d1205 7719do_vfp_dp_ldstmdb (void)
e16bb312 7720{
c19d1205 7721 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7722}
7723
7724static void
c19d1205 7725do_vfp_xp_ldstmia (void)
e16bb312 7726{
c19d1205
ZW
7727 vfp_dp_ldstm (VFP_LDSTMIAX);
7728}
e16bb312 7729
c19d1205
ZW
7730static void
7731do_vfp_xp_ldstmdb (void)
7732{
7733 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7734}
5287ad62
JB
7735
7736static void
7737do_vfp_dp_rd_rm (void)
7738{
7739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7740 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7741}
7742
7743static void
7744do_vfp_dp_rn_rd (void)
7745{
7746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7747 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7748}
7749
7750static void
7751do_vfp_dp_rd_rn (void)
7752{
7753 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7754 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7755}
7756
7757static void
7758do_vfp_dp_rd_rn_rm (void)
7759{
7760 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7761 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7762 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7763}
7764
7765static void
7766do_vfp_dp_rd (void)
7767{
7768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7769}
7770
7771static void
7772do_vfp_dp_rm_rd_rn (void)
7773{
7774 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7775 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7776 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7777}
7778
7779/* VFPv3 instructions. */
7780static void
7781do_vfp_sp_const (void)
7782{
7783 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7784 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7785 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7786}
7787
7788static void
7789do_vfp_dp_const (void)
7790{
7791 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7792 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7793 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7794}
7795
7796static void
7797vfp_conv (int srcsize)
7798{
7799 unsigned immbits = srcsize - inst.operands[1].imm;
7800 inst.instruction |= (immbits & 1) << 5;
7801 inst.instruction |= (immbits >> 1);
7802}
7803
7804static void
7805do_vfp_sp_conv_16 (void)
7806{
7807 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7808 vfp_conv (16);
7809}
7810
7811static void
7812do_vfp_dp_conv_16 (void)
7813{
7814 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7815 vfp_conv (16);
7816}
7817
7818static void
7819do_vfp_sp_conv_32 (void)
7820{
7821 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7822 vfp_conv (32);
7823}
7824
7825static void
7826do_vfp_dp_conv_32 (void)
7827{
7828 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7829 vfp_conv (32);
7830}
c19d1205
ZW
7831\f
7832/* FPA instructions. Also in a logical order. */
e16bb312 7833
c19d1205
ZW
7834static void
7835do_fpa_cmp (void)
7836{
7837 inst.instruction |= inst.operands[0].reg << 16;
7838 inst.instruction |= inst.operands[1].reg;
7839}
b99bd4ef
NC
7840
7841static void
c19d1205 7842do_fpa_ldmstm (void)
b99bd4ef 7843{
c19d1205
ZW
7844 inst.instruction |= inst.operands[0].reg << 12;
7845 switch (inst.operands[1].imm)
7846 {
7847 case 1: inst.instruction |= CP_T_X; break;
7848 case 2: inst.instruction |= CP_T_Y; break;
7849 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7850 case 4: break;
7851 default: abort ();
7852 }
b99bd4ef 7853
c19d1205
ZW
7854 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7855 {
7856 /* The instruction specified "ea" or "fd", so we can only accept
7857 [Rn]{!}. The instruction does not really support stacking or
7858 unstacking, so we have to emulate these by setting appropriate
7859 bits and offsets. */
7860 constraint (inst.reloc.exp.X_op != O_constant
7861 || inst.reloc.exp.X_add_number != 0,
7862 _("this instruction does not support indexing"));
b99bd4ef 7863
c19d1205
ZW
7864 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7865 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7866
c19d1205
ZW
7867 if (!(inst.instruction & INDEX_UP))
7868 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7869
c19d1205
ZW
7870 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7871 {
7872 inst.operands[2].preind = 0;
7873 inst.operands[2].postind = 1;
7874 }
7875 }
b99bd4ef 7876
c19d1205 7877 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7878}
c19d1205
ZW
7879\f
7880/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7881
c19d1205
ZW
7882static void
7883do_iwmmxt_tandorc (void)
7884{
7885 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7886}
b99bd4ef 7887
c19d1205
ZW
7888static void
7889do_iwmmxt_textrc (void)
7890{
7891 inst.instruction |= inst.operands[0].reg << 12;
7892 inst.instruction |= inst.operands[1].imm;
7893}
b99bd4ef
NC
7894
7895static void
c19d1205 7896do_iwmmxt_textrm (void)
b99bd4ef 7897{
c19d1205
ZW
7898 inst.instruction |= inst.operands[0].reg << 12;
7899 inst.instruction |= inst.operands[1].reg << 16;
7900 inst.instruction |= inst.operands[2].imm;
7901}
b99bd4ef 7902
c19d1205
ZW
7903static void
7904do_iwmmxt_tinsr (void)
7905{
7906 inst.instruction |= inst.operands[0].reg << 16;
7907 inst.instruction |= inst.operands[1].reg << 12;
7908 inst.instruction |= inst.operands[2].imm;
7909}
b99bd4ef 7910
c19d1205
ZW
7911static void
7912do_iwmmxt_tmia (void)
7913{
7914 inst.instruction |= inst.operands[0].reg << 5;
7915 inst.instruction |= inst.operands[1].reg;
7916 inst.instruction |= inst.operands[2].reg << 12;
7917}
b99bd4ef 7918
c19d1205
ZW
7919static void
7920do_iwmmxt_waligni (void)
7921{
7922 inst.instruction |= inst.operands[0].reg << 12;
7923 inst.instruction |= inst.operands[1].reg << 16;
7924 inst.instruction |= inst.operands[2].reg;
7925 inst.instruction |= inst.operands[3].imm << 20;
7926}
b99bd4ef 7927
2d447fca
JM
7928static void
7929do_iwmmxt_wmerge (void)
7930{
7931 inst.instruction |= inst.operands[0].reg << 12;
7932 inst.instruction |= inst.operands[1].reg << 16;
7933 inst.instruction |= inst.operands[2].reg;
7934 inst.instruction |= inst.operands[3].imm << 21;
7935}
7936
c19d1205
ZW
7937static void
7938do_iwmmxt_wmov (void)
7939{
7940 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 inst.instruction |= inst.operands[1].reg << 16;
7943 inst.instruction |= inst.operands[1].reg;
7944}
b99bd4ef 7945
c19d1205
ZW
7946static void
7947do_iwmmxt_wldstbh (void)
7948{
8f06b2d8 7949 int reloc;
c19d1205 7950 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7951 if (thumb_mode)
7952 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7953 else
7954 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7955 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7956}
7957
c19d1205
ZW
7958static void
7959do_iwmmxt_wldstw (void)
7960{
7961 /* RIWR_RIWC clears .isreg for a control register. */
7962 if (!inst.operands[0].isreg)
7963 {
7964 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7965 inst.instruction |= 0xf0000000;
7966 }
b99bd4ef 7967
c19d1205
ZW
7968 inst.instruction |= inst.operands[0].reg << 12;
7969 encode_arm_cp_address (1, TRUE, TRUE, 0);
7970}
b99bd4ef
NC
7971
7972static void
c19d1205 7973do_iwmmxt_wldstd (void)
b99bd4ef 7974{
c19d1205 7975 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7976 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7977 && inst.operands[1].immisreg)
7978 {
7979 inst.instruction &= ~0x1a000ff;
7980 inst.instruction |= (0xf << 28);
7981 if (inst.operands[1].preind)
7982 inst.instruction |= PRE_INDEX;
7983 if (!inst.operands[1].negative)
7984 inst.instruction |= INDEX_UP;
7985 if (inst.operands[1].writeback)
7986 inst.instruction |= WRITE_BACK;
7987 inst.instruction |= inst.operands[1].reg << 16;
7988 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7989 inst.instruction |= inst.operands[1].imm;
7990 }
7991 else
7992 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 7993}
b99bd4ef 7994
c19d1205
ZW
7995static void
7996do_iwmmxt_wshufh (void)
7997{
7998 inst.instruction |= inst.operands[0].reg << 12;
7999 inst.instruction |= inst.operands[1].reg << 16;
8000 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8001 inst.instruction |= (inst.operands[2].imm & 0x0f);
8002}
b99bd4ef 8003
c19d1205
ZW
8004static void
8005do_iwmmxt_wzero (void)
8006{
8007 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8008 inst.instruction |= inst.operands[0].reg;
8009 inst.instruction |= inst.operands[0].reg << 12;
8010 inst.instruction |= inst.operands[0].reg << 16;
8011}
2d447fca
JM
8012
8013static void
8014do_iwmmxt_wrwrwr_or_imm5 (void)
8015{
8016 if (inst.operands[2].isreg)
8017 do_rd_rn_rm ();
8018 else {
8019 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8020 _("immediate operand requires iWMMXt2"));
8021 do_rd_rn ();
8022 if (inst.operands[2].imm == 0)
8023 {
8024 switch ((inst.instruction >> 20) & 0xf)
8025 {
8026 case 4:
8027 case 5:
8028 case 6:
5f4273c7 8029 case 7:
2d447fca
JM
8030 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8031 inst.operands[2].imm = 16;
8032 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8033 break;
8034 case 8:
8035 case 9:
8036 case 10:
8037 case 11:
8038 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8039 inst.operands[2].imm = 32;
8040 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8041 break;
8042 case 12:
8043 case 13:
8044 case 14:
8045 case 15:
8046 {
8047 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8048 unsigned long wrn;
8049 wrn = (inst.instruction >> 16) & 0xf;
8050 inst.instruction &= 0xff0fff0f;
8051 inst.instruction |= wrn;
8052 /* Bail out here; the instruction is now assembled. */
8053 return;
8054 }
8055 }
8056 }
8057 /* Map 32 -> 0, etc. */
8058 inst.operands[2].imm &= 0x1f;
8059 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8060 }
8061}
c19d1205
ZW
8062\f
8063/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8064 operations first, then control, shift, and load/store. */
b99bd4ef 8065
c19d1205 8066/* Insns like "foo X,Y,Z". */
b99bd4ef 8067
c19d1205
ZW
8068static void
8069do_mav_triple (void)
8070{
8071 inst.instruction |= inst.operands[0].reg << 16;
8072 inst.instruction |= inst.operands[1].reg;
8073 inst.instruction |= inst.operands[2].reg << 12;
8074}
b99bd4ef 8075
c19d1205
ZW
8076/* Insns like "foo W,X,Y,Z".
8077 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8078
c19d1205
ZW
8079static void
8080do_mav_quad (void)
8081{
8082 inst.instruction |= inst.operands[0].reg << 5;
8083 inst.instruction |= inst.operands[1].reg << 12;
8084 inst.instruction |= inst.operands[2].reg << 16;
8085 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8086}
8087
c19d1205
ZW
8088/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8089static void
8090do_mav_dspsc (void)
a737bd4d 8091{
c19d1205
ZW
8092 inst.instruction |= inst.operands[1].reg << 12;
8093}
a737bd4d 8094
c19d1205
ZW
8095/* Maverick shift immediate instructions.
8096 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8097 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8098
c19d1205
ZW
8099static void
8100do_mav_shift (void)
8101{
8102 int imm = inst.operands[2].imm;
a737bd4d 8103
c19d1205
ZW
8104 inst.instruction |= inst.operands[0].reg << 12;
8105 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8106
c19d1205
ZW
8107 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8108 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8109 Bit 4 should be 0. */
8110 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8111
c19d1205
ZW
8112 inst.instruction |= imm;
8113}
8114\f
8115/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8116
c19d1205
ZW
8117/* Xscale multiply-accumulate (argument parse)
8118 MIAcc acc0,Rm,Rs
8119 MIAPHcc acc0,Rm,Rs
8120 MIAxycc acc0,Rm,Rs. */
a737bd4d 8121
c19d1205
ZW
8122static void
8123do_xsc_mia (void)
8124{
8125 inst.instruction |= inst.operands[1].reg;
8126 inst.instruction |= inst.operands[2].reg << 12;
8127}
a737bd4d 8128
c19d1205 8129/* Xscale move-accumulator-register (argument parse)
a737bd4d 8130
c19d1205 8131 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8132
c19d1205
ZW
8133static void
8134do_xsc_mar (void)
8135{
8136 inst.instruction |= inst.operands[1].reg << 12;
8137 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8138}
8139
c19d1205 8140/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8141
c19d1205 8142 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8143
8144static void
c19d1205 8145do_xsc_mra (void)
b99bd4ef 8146{
c19d1205
ZW
8147 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8148 inst.instruction |= inst.operands[0].reg << 12;
8149 inst.instruction |= inst.operands[1].reg << 16;
8150}
8151\f
8152/* Encoding functions relevant only to Thumb. */
b99bd4ef 8153
c19d1205
ZW
8154/* inst.operands[i] is a shifted-register operand; encode
8155 it into inst.instruction in the format used by Thumb32. */
8156
8157static void
8158encode_thumb32_shifted_operand (int i)
8159{
8160 unsigned int value = inst.reloc.exp.X_add_number;
8161 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8162
9c3c69f2
PB
8163 constraint (inst.operands[i].immisreg,
8164 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8165 inst.instruction |= inst.operands[i].reg;
8166 if (shift == SHIFT_RRX)
8167 inst.instruction |= SHIFT_ROR << 4;
8168 else
b99bd4ef 8169 {
c19d1205
ZW
8170 constraint (inst.reloc.exp.X_op != O_constant,
8171 _("expression too complex"));
8172
8173 constraint (value > 32
8174 || (value == 32 && (shift == SHIFT_LSL
8175 || shift == SHIFT_ROR)),
8176 _("shift expression is too large"));
8177
8178 if (value == 0)
8179 shift = SHIFT_LSL;
8180 else if (value == 32)
8181 value = 0;
8182
8183 inst.instruction |= shift << 4;
8184 inst.instruction |= (value & 0x1c) << 10;
8185 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8186 }
c19d1205 8187}
b99bd4ef 8188
b99bd4ef 8189
c19d1205
ZW
8190/* inst.operands[i] was set up by parse_address. Encode it into a
8191 Thumb32 format load or store instruction. Reject forms that cannot
8192 be used with such instructions. If is_t is true, reject forms that
8193 cannot be used with a T instruction; if is_d is true, reject forms
8194 that cannot be used with a D instruction. */
b99bd4ef 8195
c19d1205
ZW
8196static void
8197encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8198{
8199 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8200
8201 constraint (!inst.operands[i].isreg,
53365c0d 8202 _("Instruction does not support =N addresses"));
b99bd4ef 8203
c19d1205
ZW
8204 inst.instruction |= inst.operands[i].reg << 16;
8205 if (inst.operands[i].immisreg)
b99bd4ef 8206 {
c19d1205
ZW
8207 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8208 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8209 constraint (inst.operands[i].negative,
8210 _("Thumb does not support negative register indexing"));
8211 constraint (inst.operands[i].postind,
8212 _("Thumb does not support register post-indexing"));
8213 constraint (inst.operands[i].writeback,
8214 _("Thumb does not support register indexing with writeback"));
8215 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8216 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8217
f40d1643 8218 inst.instruction |= inst.operands[i].imm;
c19d1205 8219 if (inst.operands[i].shifted)
b99bd4ef 8220 {
c19d1205
ZW
8221 constraint (inst.reloc.exp.X_op != O_constant,
8222 _("expression too complex"));
9c3c69f2
PB
8223 constraint (inst.reloc.exp.X_add_number < 0
8224 || inst.reloc.exp.X_add_number > 3,
c19d1205 8225 _("shift out of range"));
9c3c69f2 8226 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8227 }
8228 inst.reloc.type = BFD_RELOC_UNUSED;
8229 }
8230 else if (inst.operands[i].preind)
8231 {
8232 constraint (is_pc && inst.operands[i].writeback,
8233 _("cannot use writeback with PC-relative addressing"));
f40d1643 8234 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8235 _("cannot use writeback with this instruction"));
8236
8237 if (is_d)
8238 {
8239 inst.instruction |= 0x01000000;
8240 if (inst.operands[i].writeback)
8241 inst.instruction |= 0x00200000;
b99bd4ef 8242 }
c19d1205 8243 else
b99bd4ef 8244 {
c19d1205
ZW
8245 inst.instruction |= 0x00000c00;
8246 if (inst.operands[i].writeback)
8247 inst.instruction |= 0x00000100;
b99bd4ef 8248 }
c19d1205 8249 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8250 }
c19d1205 8251 else if (inst.operands[i].postind)
b99bd4ef 8252 {
c19d1205
ZW
8253 assert (inst.operands[i].writeback);
8254 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8255 constraint (is_t, _("cannot use post-indexing with this instruction"));
8256
8257 if (is_d)
8258 inst.instruction |= 0x00200000;
8259 else
8260 inst.instruction |= 0x00000900;
8261 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8262 }
8263 else /* unindexed - only for coprocessor */
8264 inst.error = _("instruction does not accept unindexed addressing");
8265}
8266
8267/* Table of Thumb instructions which exist in both 16- and 32-bit
8268 encodings (the latter only in post-V6T2 cores). The index is the
8269 value used in the insns table below. When there is more than one
8270 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8271 holds variant (1).
8272 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8273#define T16_32_TAB \
8274 X(adc, 4140, eb400000), \
8275 X(adcs, 4140, eb500000), \
8276 X(add, 1c00, eb000000), \
8277 X(adds, 1c00, eb100000), \
0110f2b8
PB
8278 X(addi, 0000, f1000000), \
8279 X(addis, 0000, f1100000), \
8280 X(add_pc,000f, f20f0000), \
8281 X(add_sp,000d, f10d0000), \
e9f89963 8282 X(adr, 000f, f20f0000), \
c19d1205
ZW
8283 X(and, 4000, ea000000), \
8284 X(ands, 4000, ea100000), \
8285 X(asr, 1000, fa40f000), \
8286 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8287 X(b, e000, f000b000), \
8288 X(bcond, d000, f0008000), \
c19d1205
ZW
8289 X(bic, 4380, ea200000), \
8290 X(bics, 4380, ea300000), \
8291 X(cmn, 42c0, eb100f00), \
8292 X(cmp, 2800, ebb00f00), \
8293 X(cpsie, b660, f3af8400), \
8294 X(cpsid, b670, f3af8600), \
8295 X(cpy, 4600, ea4f0000), \
155257ea 8296 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8297 X(eor, 4040, ea800000), \
8298 X(eors, 4040, ea900000), \
0110f2b8 8299 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8300 X(ldmia, c800, e8900000), \
8301 X(ldr, 6800, f8500000), \
8302 X(ldrb, 7800, f8100000), \
8303 X(ldrh, 8800, f8300000), \
8304 X(ldrsb, 5600, f9100000), \
8305 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8306 X(ldr_pc,4800, f85f0000), \
8307 X(ldr_pc2,4800, f85f0000), \
8308 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8309 X(lsl, 0000, fa00f000), \
8310 X(lsls, 0000, fa10f000), \
8311 X(lsr, 0800, fa20f000), \
8312 X(lsrs, 0800, fa30f000), \
8313 X(mov, 2000, ea4f0000), \
8314 X(movs, 2000, ea5f0000), \
8315 X(mul, 4340, fb00f000), \
8316 X(muls, 4340, ffffffff), /* no 32b muls */ \
8317 X(mvn, 43c0, ea6f0000), \
8318 X(mvns, 43c0, ea7f0000), \
8319 X(neg, 4240, f1c00000), /* rsb #0 */ \
8320 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8321 X(orr, 4300, ea400000), \
8322 X(orrs, 4300, ea500000), \
e9f89963
PB
8323 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8324 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8325 X(rev, ba00, fa90f080), \
8326 X(rev16, ba40, fa90f090), \
8327 X(revsh, bac0, fa90f0b0), \
8328 X(ror, 41c0, fa60f000), \
8329 X(rors, 41c0, fa70f000), \
8330 X(sbc, 4180, eb600000), \
8331 X(sbcs, 4180, eb700000), \
8332 X(stmia, c000, e8800000), \
8333 X(str, 6000, f8400000), \
8334 X(strb, 7000, f8000000), \
8335 X(strh, 8000, f8200000), \
0110f2b8 8336 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8337 X(sub, 1e00, eba00000), \
8338 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8339 X(subi, 8000, f1a00000), \
8340 X(subis, 8000, f1b00000), \
c19d1205
ZW
8341 X(sxtb, b240, fa4ff080), \
8342 X(sxth, b200, fa0ff080), \
8343 X(tst, 4200, ea100f00), \
8344 X(uxtb, b2c0, fa5ff080), \
8345 X(uxth, b280, fa1ff080), \
8346 X(nop, bf00, f3af8000), \
8347 X(yield, bf10, f3af8001), \
8348 X(wfe, bf20, f3af8002), \
8349 X(wfi, bf30, f3af8003), \
8350 X(sev, bf40, f3af9004), /* typo, 8004? */
8351
8352/* To catch errors in encoding functions, the codes are all offset by
8353 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8354 as 16-bit instructions. */
8355#define X(a,b,c) T_MNEM_##a
8356enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8357#undef X
8358
8359#define X(a,b,c) 0x##b
8360static const unsigned short thumb_op16[] = { T16_32_TAB };
8361#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8362#undef X
8363
8364#define X(a,b,c) 0x##c
8365static const unsigned int thumb_op32[] = { T16_32_TAB };
8366#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8367#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8368#undef X
8369#undef T16_32_TAB
8370
8371/* Thumb instruction encoders, in alphabetical order. */
8372
92e90b6e
PB
8373/* ADDW or SUBW. */
8374static void
8375do_t_add_sub_w (void)
8376{
8377 int Rd, Rn;
8378
8379 Rd = inst.operands[0].reg;
8380 Rn = inst.operands[1].reg;
8381
8382 constraint (Rd == 15, _("PC not allowed as destination"));
8383 inst.instruction |= (Rn << 16) | (Rd << 8);
8384 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8385}
8386
c19d1205
ZW
8387/* Parse an add or subtract instruction. We get here with inst.instruction
8388 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8389
8390static void
8391do_t_add_sub (void)
8392{
8393 int Rd, Rs, Rn;
8394
8395 Rd = inst.operands[0].reg;
8396 Rs = (inst.operands[1].present
8397 ? inst.operands[1].reg /* Rd, Rs, foo */
8398 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8399
8400 if (unified_syntax)
8401 {
0110f2b8
PB
8402 bfd_boolean flags;
8403 bfd_boolean narrow;
8404 int opcode;
8405
8406 flags = (inst.instruction == T_MNEM_adds
8407 || inst.instruction == T_MNEM_subs);
8408 if (flags)
8409 narrow = (current_it_mask == 0);
8410 else
8411 narrow = (current_it_mask != 0);
c19d1205 8412 if (!inst.operands[2].isreg)
b99bd4ef 8413 {
16805f35
PB
8414 int add;
8415
8416 add = (inst.instruction == T_MNEM_add
8417 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8418 opcode = 0;
8419 if (inst.size_req != 4)
8420 {
0110f2b8
PB
8421 /* Attempt to use a narrow opcode, with relaxation if
8422 appropriate. */
8423 if (Rd == REG_SP && Rs == REG_SP && !flags)
8424 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8425 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8426 opcode = T_MNEM_add_sp;
8427 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8428 opcode = T_MNEM_add_pc;
8429 else if (Rd <= 7 && Rs <= 7 && narrow)
8430 {
8431 if (flags)
8432 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8433 else
8434 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8435 }
8436 if (opcode)
8437 {
8438 inst.instruction = THUMB_OP16(opcode);
8439 inst.instruction |= (Rd << 4) | Rs;
8440 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8441 if (inst.size_req != 2)
8442 inst.relax = opcode;
8443 }
8444 else
8445 constraint (inst.size_req == 2, BAD_HIREG);
8446 }
8447 if (inst.size_req == 4
8448 || (inst.size_req != 2 && !opcode))
8449 {
efd81785
PB
8450 if (Rd == REG_PC)
8451 {
8452 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8453 _("only SUBS PC, LR, #const allowed"));
8454 constraint (inst.reloc.exp.X_op != O_constant,
8455 _("expression too complex"));
8456 constraint (inst.reloc.exp.X_add_number < 0
8457 || inst.reloc.exp.X_add_number > 0xff,
8458 _("immediate value out of range"));
8459 inst.instruction = T2_SUBS_PC_LR
8460 | inst.reloc.exp.X_add_number;
8461 inst.reloc.type = BFD_RELOC_UNUSED;
8462 return;
8463 }
8464 else if (Rs == REG_PC)
16805f35
PB
8465 {
8466 /* Always use addw/subw. */
8467 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8468 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8469 }
8470 else
8471 {
8472 inst.instruction = THUMB_OP32 (inst.instruction);
8473 inst.instruction = (inst.instruction & 0xe1ffffff)
8474 | 0x10000000;
8475 if (flags)
8476 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8477 else
8478 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8479 }
dc4503c6
PB
8480 inst.instruction |= Rd << 8;
8481 inst.instruction |= Rs << 16;
0110f2b8 8482 }
b99bd4ef 8483 }
c19d1205
ZW
8484 else
8485 {
8486 Rn = inst.operands[2].reg;
8487 /* See if we can do this with a 16-bit instruction. */
8488 if (!inst.operands[2].shifted && inst.size_req != 4)
8489 {
e27ec89e
PB
8490 if (Rd > 7 || Rs > 7 || Rn > 7)
8491 narrow = FALSE;
8492
8493 if (narrow)
c19d1205 8494 {
e27ec89e
PB
8495 inst.instruction = ((inst.instruction == T_MNEM_adds
8496 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8497 ? T_OPCODE_ADD_R3
8498 : T_OPCODE_SUB_R3);
8499 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8500 return;
8501 }
b99bd4ef 8502
7e806470 8503 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8504 {
7e806470
PB
8505 /* Thumb-1 cores (except v6-M) require at least one high
8506 register in a narrow non flag setting add. */
8507 if (Rd > 7 || Rn > 7
8508 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8509 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8510 {
7e806470
PB
8511 if (Rd == Rn)
8512 {
8513 Rn = Rs;
8514 Rs = Rd;
8515 }
c19d1205
ZW
8516 inst.instruction = T_OPCODE_ADD_HI;
8517 inst.instruction |= (Rd & 8) << 4;
8518 inst.instruction |= (Rd & 7);
8519 inst.instruction |= Rn << 3;
8520 return;
8521 }
c19d1205
ZW
8522 }
8523 }
8524 /* If we get here, it can't be done in 16 bits. */
8525 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8526 _("shift must be constant"));
8527 inst.instruction = THUMB_OP32 (inst.instruction);
8528 inst.instruction |= Rd << 8;
8529 inst.instruction |= Rs << 16;
8530 encode_thumb32_shifted_operand (2);
8531 }
8532 }
8533 else
8534 {
8535 constraint (inst.instruction == T_MNEM_adds
8536 || inst.instruction == T_MNEM_subs,
8537 BAD_THUMB32);
b99bd4ef 8538
c19d1205 8539 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8540 {
c19d1205
ZW
8541 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8542 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8543 BAD_HIREG);
8544
8545 inst.instruction = (inst.instruction == T_MNEM_add
8546 ? 0x0000 : 0x8000);
8547 inst.instruction |= (Rd << 4) | Rs;
8548 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8549 return;
8550 }
8551
c19d1205
ZW
8552 Rn = inst.operands[2].reg;
8553 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8554
c19d1205
ZW
8555 /* We now have Rd, Rs, and Rn set to registers. */
8556 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8557 {
c19d1205
ZW
8558 /* Can't do this for SUB. */
8559 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8560 inst.instruction = T_OPCODE_ADD_HI;
8561 inst.instruction |= (Rd & 8) << 4;
8562 inst.instruction |= (Rd & 7);
8563 if (Rs == Rd)
8564 inst.instruction |= Rn << 3;
8565 else if (Rn == Rd)
8566 inst.instruction |= Rs << 3;
8567 else
8568 constraint (1, _("dest must overlap one source register"));
8569 }
8570 else
8571 {
8572 inst.instruction = (inst.instruction == T_MNEM_add
8573 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8574 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8575 }
b99bd4ef 8576 }
b99bd4ef
NC
8577}
8578
c19d1205
ZW
8579static void
8580do_t_adr (void)
8581{
0110f2b8
PB
8582 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8583 {
8584 /* Defer to section relaxation. */
8585 inst.relax = inst.instruction;
8586 inst.instruction = THUMB_OP16 (inst.instruction);
8587 inst.instruction |= inst.operands[0].reg << 4;
8588 }
8589 else if (unified_syntax && inst.size_req != 2)
e9f89963 8590 {
0110f2b8 8591 /* Generate a 32-bit opcode. */
e9f89963
PB
8592 inst.instruction = THUMB_OP32 (inst.instruction);
8593 inst.instruction |= inst.operands[0].reg << 8;
8594 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8595 inst.reloc.pc_rel = 1;
8596 }
8597 else
8598 {
0110f2b8 8599 /* Generate a 16-bit opcode. */
e9f89963
PB
8600 inst.instruction = THUMB_OP16 (inst.instruction);
8601 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8602 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8603 inst.reloc.pc_rel = 1;
b99bd4ef 8604
e9f89963
PB
8605 inst.instruction |= inst.operands[0].reg << 4;
8606 }
c19d1205 8607}
b99bd4ef 8608
c19d1205
ZW
8609/* Arithmetic instructions for which there is just one 16-bit
8610 instruction encoding, and it allows only two low registers.
8611 For maximal compatibility with ARM syntax, we allow three register
8612 operands even when Thumb-32 instructions are not available, as long
8613 as the first two are identical. For instance, both "sbc r0,r1" and
8614 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8615static void
c19d1205 8616do_t_arit3 (void)
b99bd4ef 8617{
c19d1205 8618 int Rd, Rs, Rn;
b99bd4ef 8619
c19d1205
ZW
8620 Rd = inst.operands[0].reg;
8621 Rs = (inst.operands[1].present
8622 ? inst.operands[1].reg /* Rd, Rs, foo */
8623 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8624 Rn = inst.operands[2].reg;
b99bd4ef 8625
c19d1205 8626 if (unified_syntax)
b99bd4ef 8627 {
c19d1205
ZW
8628 if (!inst.operands[2].isreg)
8629 {
8630 /* For an immediate, we always generate a 32-bit opcode;
8631 section relaxation will shrink it later if possible. */
8632 inst.instruction = THUMB_OP32 (inst.instruction);
8633 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8634 inst.instruction |= Rd << 8;
8635 inst.instruction |= Rs << 16;
8636 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8637 }
8638 else
8639 {
e27ec89e
PB
8640 bfd_boolean narrow;
8641
c19d1205 8642 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8643 if (THUMB_SETS_FLAGS (inst.instruction))
8644 narrow = current_it_mask == 0;
8645 else
8646 narrow = current_it_mask != 0;
8647
8648 if (Rd > 7 || Rn > 7 || Rs > 7)
8649 narrow = FALSE;
8650 if (inst.operands[2].shifted)
8651 narrow = FALSE;
8652 if (inst.size_req == 4)
8653 narrow = FALSE;
8654
8655 if (narrow
c19d1205
ZW
8656 && Rd == Rs)
8657 {
8658 inst.instruction = THUMB_OP16 (inst.instruction);
8659 inst.instruction |= Rd;
8660 inst.instruction |= Rn << 3;
8661 return;
8662 }
b99bd4ef 8663
c19d1205
ZW
8664 /* If we get here, it can't be done in 16 bits. */
8665 constraint (inst.operands[2].shifted
8666 && inst.operands[2].immisreg,
8667 _("shift must be constant"));
8668 inst.instruction = THUMB_OP32 (inst.instruction);
8669 inst.instruction |= Rd << 8;
8670 inst.instruction |= Rs << 16;
8671 encode_thumb32_shifted_operand (2);
8672 }
a737bd4d 8673 }
c19d1205 8674 else
b99bd4ef 8675 {
c19d1205
ZW
8676 /* On its face this is a lie - the instruction does set the
8677 flags. However, the only supported mnemonic in this mode
8678 says it doesn't. */
8679 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8680
c19d1205
ZW
8681 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8682 _("unshifted register required"));
8683 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8684 constraint (Rd != Rs,
8685 _("dest and source1 must be the same register"));
a737bd4d 8686
c19d1205
ZW
8687 inst.instruction = THUMB_OP16 (inst.instruction);
8688 inst.instruction |= Rd;
8689 inst.instruction |= Rn << 3;
b99bd4ef 8690 }
a737bd4d 8691}
b99bd4ef 8692
c19d1205
ZW
8693/* Similarly, but for instructions where the arithmetic operation is
8694 commutative, so we can allow either of them to be different from
8695 the destination operand in a 16-bit instruction. For instance, all
8696 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8697 accepted. */
8698static void
8699do_t_arit3c (void)
a737bd4d 8700{
c19d1205 8701 int Rd, Rs, Rn;
b99bd4ef 8702
c19d1205
ZW
8703 Rd = inst.operands[0].reg;
8704 Rs = (inst.operands[1].present
8705 ? inst.operands[1].reg /* Rd, Rs, foo */
8706 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8707 Rn = inst.operands[2].reg;
a737bd4d 8708
c19d1205 8709 if (unified_syntax)
a737bd4d 8710 {
c19d1205 8711 if (!inst.operands[2].isreg)
b99bd4ef 8712 {
c19d1205
ZW
8713 /* For an immediate, we always generate a 32-bit opcode;
8714 section relaxation will shrink it later if possible. */
8715 inst.instruction = THUMB_OP32 (inst.instruction);
8716 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8717 inst.instruction |= Rd << 8;
8718 inst.instruction |= Rs << 16;
8719 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8720 }
c19d1205 8721 else
a737bd4d 8722 {
e27ec89e
PB
8723 bfd_boolean narrow;
8724
c19d1205 8725 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8726 if (THUMB_SETS_FLAGS (inst.instruction))
8727 narrow = current_it_mask == 0;
8728 else
8729 narrow = current_it_mask != 0;
8730
8731 if (Rd > 7 || Rn > 7 || Rs > 7)
8732 narrow = FALSE;
8733 if (inst.operands[2].shifted)
8734 narrow = FALSE;
8735 if (inst.size_req == 4)
8736 narrow = FALSE;
8737
8738 if (narrow)
a737bd4d 8739 {
c19d1205 8740 if (Rd == Rs)
a737bd4d 8741 {
c19d1205
ZW
8742 inst.instruction = THUMB_OP16 (inst.instruction);
8743 inst.instruction |= Rd;
8744 inst.instruction |= Rn << 3;
8745 return;
a737bd4d 8746 }
c19d1205 8747 if (Rd == Rn)
a737bd4d 8748 {
c19d1205
ZW
8749 inst.instruction = THUMB_OP16 (inst.instruction);
8750 inst.instruction |= Rd;
8751 inst.instruction |= Rs << 3;
8752 return;
a737bd4d
NC
8753 }
8754 }
c19d1205
ZW
8755
8756 /* If we get here, it can't be done in 16 bits. */
8757 constraint (inst.operands[2].shifted
8758 && inst.operands[2].immisreg,
8759 _("shift must be constant"));
8760 inst.instruction = THUMB_OP32 (inst.instruction);
8761 inst.instruction |= Rd << 8;
8762 inst.instruction |= Rs << 16;
8763 encode_thumb32_shifted_operand (2);
a737bd4d 8764 }
b99bd4ef 8765 }
c19d1205
ZW
8766 else
8767 {
8768 /* On its face this is a lie - the instruction does set the
8769 flags. However, the only supported mnemonic in this mode
8770 says it doesn't. */
8771 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8772
c19d1205
ZW
8773 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8774 _("unshifted register required"));
8775 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8776
8777 inst.instruction = THUMB_OP16 (inst.instruction);
8778 inst.instruction |= Rd;
8779
8780 if (Rd == Rs)
8781 inst.instruction |= Rn << 3;
8782 else if (Rd == Rn)
8783 inst.instruction |= Rs << 3;
8784 else
8785 constraint (1, _("dest must overlap one source register"));
8786 }
a737bd4d
NC
8787}
8788
62b3e311
PB
8789static void
8790do_t_barrier (void)
8791{
8792 if (inst.operands[0].present)
8793 {
8794 constraint ((inst.instruction & 0xf0) != 0x40
8795 && inst.operands[0].imm != 0xf,
bd3ba5d1 8796 _("bad barrier type"));
62b3e311
PB
8797 inst.instruction |= inst.operands[0].imm;
8798 }
8799 else
8800 inst.instruction |= 0xf;
8801}
8802
c19d1205
ZW
8803static void
8804do_t_bfc (void)
a737bd4d 8805{
c19d1205
ZW
8806 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8807 constraint (msb > 32, _("bit-field extends past end of register"));
8808 /* The instruction encoding stores the LSB and MSB,
8809 not the LSB and width. */
8810 inst.instruction |= inst.operands[0].reg << 8;
8811 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8812 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8813 inst.instruction |= msb - 1;
b99bd4ef
NC
8814}
8815
c19d1205
ZW
8816static void
8817do_t_bfi (void)
b99bd4ef 8818{
c19d1205 8819 unsigned int msb;
b99bd4ef 8820
c19d1205
ZW
8821 /* #0 in second position is alternative syntax for bfc, which is
8822 the same instruction but with REG_PC in the Rm field. */
8823 if (!inst.operands[1].isreg)
8824 inst.operands[1].reg = REG_PC;
b99bd4ef 8825
c19d1205
ZW
8826 msb = inst.operands[2].imm + inst.operands[3].imm;
8827 constraint (msb > 32, _("bit-field extends past end of register"));
8828 /* The instruction encoding stores the LSB and MSB,
8829 not the LSB and width. */
8830 inst.instruction |= inst.operands[0].reg << 8;
8831 inst.instruction |= inst.operands[1].reg << 16;
8832 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8833 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8834 inst.instruction |= msb - 1;
b99bd4ef
NC
8835}
8836
c19d1205
ZW
8837static void
8838do_t_bfx (void)
b99bd4ef 8839{
c19d1205
ZW
8840 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8841 _("bit-field extends past end of register"));
8842 inst.instruction |= inst.operands[0].reg << 8;
8843 inst.instruction |= inst.operands[1].reg << 16;
8844 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8845 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8846 inst.instruction |= inst.operands[3].imm - 1;
8847}
b99bd4ef 8848
c19d1205
ZW
8849/* ARM V5 Thumb BLX (argument parse)
8850 BLX <target_addr> which is BLX(1)
8851 BLX <Rm> which is BLX(2)
8852 Unfortunately, there are two different opcodes for this mnemonic.
8853 So, the insns[].value is not used, and the code here zaps values
8854 into inst.instruction.
b99bd4ef 8855
c19d1205
ZW
8856 ??? How to take advantage of the additional two bits of displacement
8857 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8858
c19d1205
ZW
8859static void
8860do_t_blx (void)
8861{
dfa9f0d5 8862 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8863 if (inst.operands[0].isreg)
8864 /* We have a register, so this is BLX(2). */
8865 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8866 else
8867 {
c19d1205 8868 /* No register. This must be BLX(1). */
2fc8bdac 8869 inst.instruction = 0xf000e800;
39b41c9c
PB
8870#ifdef OBJ_ELF
8871 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8872 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8873 else
8874#endif
8875 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8876 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8877 }
8878}
8879
c19d1205
ZW
8880static void
8881do_t_branch (void)
b99bd4ef 8882{
0110f2b8 8883 int opcode;
dfa9f0d5
PB
8884 int cond;
8885
8886 if (current_it_mask)
8887 {
8888 /* Conditional branches inside IT blocks are encoded as unconditional
8889 branches. */
8890 cond = COND_ALWAYS;
8891 /* A branch must be the last instruction in an IT block. */
8892 constraint (current_it_mask != 0x10, BAD_BRANCH);
8893 }
8894 else
8895 cond = inst.cond;
8896
8897 if (cond != COND_ALWAYS)
0110f2b8
PB
8898 opcode = T_MNEM_bcond;
8899 else
8900 opcode = inst.instruction;
8901
8902 if (unified_syntax && inst.size_req == 4)
c19d1205 8903 {
0110f2b8 8904 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8905 if (cond == COND_ALWAYS)
0110f2b8 8906 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8907 else
8908 {
dfa9f0d5
PB
8909 assert (cond != 0xF);
8910 inst.instruction |= cond << 22;
c19d1205
ZW
8911 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8912 }
8913 }
b99bd4ef
NC
8914 else
8915 {
0110f2b8 8916 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8917 if (cond == COND_ALWAYS)
c19d1205
ZW
8918 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8919 else
b99bd4ef 8920 {
dfa9f0d5 8921 inst.instruction |= cond << 8;
c19d1205 8922 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8923 }
0110f2b8
PB
8924 /* Allow section relaxation. */
8925 if (unified_syntax && inst.size_req != 2)
8926 inst.relax = opcode;
b99bd4ef 8927 }
c19d1205
ZW
8928
8929 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8930}
8931
8932static void
c19d1205 8933do_t_bkpt (void)
b99bd4ef 8934{
dfa9f0d5
PB
8935 constraint (inst.cond != COND_ALWAYS,
8936 _("instruction is always unconditional"));
c19d1205 8937 if (inst.operands[0].present)
b99bd4ef 8938 {
c19d1205
ZW
8939 constraint (inst.operands[0].imm > 255,
8940 _("immediate value out of range"));
8941 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8942 }
b99bd4ef
NC
8943}
8944
8945static void
c19d1205 8946do_t_branch23 (void)
b99bd4ef 8947{
dfa9f0d5 8948 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8949 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8950 inst.reloc.pc_rel = 1;
8951
c19d1205
ZW
8952 /* If the destination of the branch is a defined symbol which does not have
8953 the THUMB_FUNC attribute, then we must be calling a function which has
8954 the (interfacearm) attribute. We look for the Thumb entry point to that
8955 function and change the branch to refer to that function instead. */
8956 if ( inst.reloc.exp.X_op == O_symbol
8957 && inst.reloc.exp.X_add_symbol != NULL
8958 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8959 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8960 inst.reloc.exp.X_add_symbol =
8961 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8962}
8963
8964static void
c19d1205 8965do_t_bx (void)
90e4755a 8966{
dfa9f0d5 8967 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8968 inst.instruction |= inst.operands[0].reg << 3;
8969 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8970 should cause the alignment to be checked once it is known. This is
8971 because BX PC only works if the instruction is word aligned. */
8972}
90e4755a 8973
c19d1205
ZW
8974static void
8975do_t_bxj (void)
8976{
dfa9f0d5 8977 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8978 if (inst.operands[0].reg == REG_PC)
8979 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8980
c19d1205 8981 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8982}
8983
8984static void
c19d1205 8985do_t_clz (void)
90e4755a 8986{
c19d1205
ZW
8987 inst.instruction |= inst.operands[0].reg << 8;
8988 inst.instruction |= inst.operands[1].reg << 16;
8989 inst.instruction |= inst.operands[1].reg;
8990}
90e4755a 8991
dfa9f0d5
PB
8992static void
8993do_t_cps (void)
8994{
8995 constraint (current_it_mask, BAD_NOT_IT);
8996 inst.instruction |= inst.operands[0].imm;
8997}
8998
c19d1205
ZW
8999static void
9000do_t_cpsi (void)
9001{
dfa9f0d5 9002 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9003 if (unified_syntax
62b3e311
PB
9004 && (inst.operands[1].present || inst.size_req == 4)
9005 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9006 {
c19d1205
ZW
9007 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9008 inst.instruction = 0xf3af8000;
9009 inst.instruction |= imod << 9;
9010 inst.instruction |= inst.operands[0].imm << 5;
9011 if (inst.operands[1].present)
9012 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9013 }
c19d1205 9014 else
90e4755a 9015 {
62b3e311
PB
9016 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9017 && (inst.operands[0].imm & 4),
9018 _("selected processor does not support 'A' form "
9019 "of this instruction"));
9020 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9021 _("Thumb does not support the 2-argument "
9022 "form of this instruction"));
9023 inst.instruction |= inst.operands[0].imm;
90e4755a 9024 }
90e4755a
RE
9025}
9026
c19d1205
ZW
9027/* THUMB CPY instruction (argument parse). */
9028
90e4755a 9029static void
c19d1205 9030do_t_cpy (void)
90e4755a 9031{
c19d1205 9032 if (inst.size_req == 4)
90e4755a 9033 {
c19d1205
ZW
9034 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9035 inst.instruction |= inst.operands[0].reg << 8;
9036 inst.instruction |= inst.operands[1].reg;
90e4755a 9037 }
c19d1205 9038 else
90e4755a 9039 {
c19d1205
ZW
9040 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9041 inst.instruction |= (inst.operands[0].reg & 0x7);
9042 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9043 }
90e4755a
RE
9044}
9045
90e4755a 9046static void
25fe350b 9047do_t_cbz (void)
90e4755a 9048{
dfa9f0d5 9049 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9050 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9051 inst.instruction |= inst.operands[0].reg;
9052 inst.reloc.pc_rel = 1;
9053 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9054}
90e4755a 9055
62b3e311
PB
9056static void
9057do_t_dbg (void)
9058{
9059 inst.instruction |= inst.operands[0].imm;
9060}
9061
9062static void
9063do_t_div (void)
9064{
9065 if (!inst.operands[1].present)
9066 inst.operands[1].reg = inst.operands[0].reg;
9067 inst.instruction |= inst.operands[0].reg << 8;
9068 inst.instruction |= inst.operands[1].reg << 16;
9069 inst.instruction |= inst.operands[2].reg;
9070}
9071
c19d1205
ZW
9072static void
9073do_t_hint (void)
9074{
9075 if (unified_syntax && inst.size_req == 4)
9076 inst.instruction = THUMB_OP32 (inst.instruction);
9077 else
9078 inst.instruction = THUMB_OP16 (inst.instruction);
9079}
90e4755a 9080
c19d1205
ZW
9081static void
9082do_t_it (void)
9083{
9084 unsigned int cond = inst.operands[0].imm;
e27ec89e 9085
dfa9f0d5 9086 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9087 current_it_mask = (inst.instruction & 0xf) | 0x10;
9088 current_cc = cond;
9089
9090 /* If the condition is a negative condition, invert the mask. */
c19d1205 9091 if ((cond & 0x1) == 0x0)
90e4755a 9092 {
c19d1205 9093 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9094
c19d1205
ZW
9095 if ((mask & 0x7) == 0)
9096 /* no conversion needed */;
9097 else if ((mask & 0x3) == 0)
e27ec89e
PB
9098 mask ^= 0x8;
9099 else if ((mask & 0x1) == 0)
9100 mask ^= 0xC;
c19d1205 9101 else
e27ec89e 9102 mask ^= 0xE;
90e4755a 9103
e27ec89e
PB
9104 inst.instruction &= 0xfff0;
9105 inst.instruction |= mask;
c19d1205 9106 }
90e4755a 9107
c19d1205
ZW
9108 inst.instruction |= cond << 4;
9109}
90e4755a 9110
3c707909
PB
9111/* Helper function used for both push/pop and ldm/stm. */
9112static void
9113encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9114{
9115 bfd_boolean load;
9116
9117 load = (inst.instruction & (1 << 20)) != 0;
9118
9119 if (mask & (1 << 13))
9120 inst.error = _("SP not allowed in register list");
9121 if (load)
9122 {
9123 if (mask & (1 << 14)
9124 && mask & (1 << 15))
9125 inst.error = _("LR and PC should not both be in register list");
9126
9127 if ((mask & (1 << base)) != 0
9128 && writeback)
9129 as_warn (_("base register should not be in register list "
9130 "when written back"));
9131 }
9132 else
9133 {
9134 if (mask & (1 << 15))
9135 inst.error = _("PC not allowed in register list");
9136
9137 if (mask & (1 << base))
9138 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9139 }
9140
9141 if ((mask & (mask - 1)) == 0)
9142 {
9143 /* Single register transfers implemented as str/ldr. */
9144 if (writeback)
9145 {
9146 if (inst.instruction & (1 << 23))
9147 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9148 else
9149 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9150 }
9151 else
9152 {
9153 if (inst.instruction & (1 << 23))
9154 inst.instruction = 0x00800000; /* ia -> [base] */
9155 else
9156 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9157 }
9158
9159 inst.instruction |= 0xf8400000;
9160 if (load)
9161 inst.instruction |= 0x00100000;
9162
5f4273c7 9163 mask = ffs (mask) - 1;
3c707909
PB
9164 mask <<= 12;
9165 }
9166 else if (writeback)
9167 inst.instruction |= WRITE_BACK;
9168
9169 inst.instruction |= mask;
9170 inst.instruction |= base << 16;
9171}
9172
c19d1205
ZW
9173static void
9174do_t_ldmstm (void)
9175{
9176 /* This really doesn't seem worth it. */
9177 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9178 _("expression too complex"));
9179 constraint (inst.operands[1].writeback,
9180 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9181
c19d1205
ZW
9182 if (unified_syntax)
9183 {
3c707909
PB
9184 bfd_boolean narrow;
9185 unsigned mask;
9186
9187 narrow = FALSE;
c19d1205
ZW
9188 /* See if we can use a 16-bit instruction. */
9189 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9190 && inst.size_req != 4
3c707909 9191 && !(inst.operands[1].imm & ~0xff))
90e4755a 9192 {
3c707909 9193 mask = 1 << inst.operands[0].reg;
90e4755a 9194
3c707909
PB
9195 if (inst.operands[0].reg <= 7
9196 && (inst.instruction == T_MNEM_stmia
9197 ? inst.operands[0].writeback
9198 : (inst.operands[0].writeback
9199 == !(inst.operands[1].imm & mask))))
90e4755a 9200 {
3c707909
PB
9201 if (inst.instruction == T_MNEM_stmia
9202 && (inst.operands[1].imm & mask)
9203 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9204 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9205 inst.operands[0].reg);
3c707909
PB
9206
9207 inst.instruction = THUMB_OP16 (inst.instruction);
9208 inst.instruction |= inst.operands[0].reg << 8;
9209 inst.instruction |= inst.operands[1].imm;
9210 narrow = TRUE;
90e4755a 9211 }
3c707909
PB
9212 else if (inst.operands[0] .reg == REG_SP
9213 && inst.operands[0].writeback)
90e4755a 9214 {
3c707909
PB
9215 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9216 ? T_MNEM_push : T_MNEM_pop);
9217 inst.instruction |= inst.operands[1].imm;
9218 narrow = TRUE;
90e4755a 9219 }
3c707909
PB
9220 }
9221
9222 if (!narrow)
9223 {
c19d1205
ZW
9224 if (inst.instruction < 0xffff)
9225 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9226
5f4273c7
NC
9227 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9228 inst.operands[0].writeback);
90e4755a
RE
9229 }
9230 }
c19d1205 9231 else
90e4755a 9232 {
c19d1205
ZW
9233 constraint (inst.operands[0].reg > 7
9234 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9235 constraint (inst.instruction != T_MNEM_ldmia
9236 && inst.instruction != T_MNEM_stmia,
9237 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9238 if (inst.instruction == T_MNEM_stmia)
f03698e6 9239 {
c19d1205
ZW
9240 if (!inst.operands[0].writeback)
9241 as_warn (_("this instruction will write back the base register"));
9242 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9243 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9244 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9245 inst.operands[0].reg);
f03698e6 9246 }
c19d1205 9247 else
90e4755a 9248 {
c19d1205
ZW
9249 if (!inst.operands[0].writeback
9250 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9251 as_warn (_("this instruction will write back the base register"));
9252 else if (inst.operands[0].writeback
9253 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9254 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9255 }
9256
c19d1205
ZW
9257 inst.instruction = THUMB_OP16 (inst.instruction);
9258 inst.instruction |= inst.operands[0].reg << 8;
9259 inst.instruction |= inst.operands[1].imm;
9260 }
9261}
e28cd48c 9262
c19d1205
ZW
9263static void
9264do_t_ldrex (void)
9265{
9266 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9267 || inst.operands[1].postind || inst.operands[1].writeback
9268 || inst.operands[1].immisreg || inst.operands[1].shifted
9269 || inst.operands[1].negative,
01cfc07f 9270 BAD_ADDR_MODE);
e28cd48c 9271
c19d1205
ZW
9272 inst.instruction |= inst.operands[0].reg << 12;
9273 inst.instruction |= inst.operands[1].reg << 16;
9274 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9275}
e28cd48c 9276
c19d1205
ZW
9277static void
9278do_t_ldrexd (void)
9279{
9280 if (!inst.operands[1].present)
1cac9012 9281 {
c19d1205
ZW
9282 constraint (inst.operands[0].reg == REG_LR,
9283 _("r14 not allowed as first register "
9284 "when second register is omitted"));
9285 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9286 }
c19d1205
ZW
9287 constraint (inst.operands[0].reg == inst.operands[1].reg,
9288 BAD_OVERLAP);
b99bd4ef 9289
c19d1205
ZW
9290 inst.instruction |= inst.operands[0].reg << 12;
9291 inst.instruction |= inst.operands[1].reg << 8;
9292 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9293}
9294
9295static void
c19d1205 9296do_t_ldst (void)
b99bd4ef 9297{
0110f2b8
PB
9298 unsigned long opcode;
9299 int Rn;
9300
9301 opcode = inst.instruction;
c19d1205 9302 if (unified_syntax)
b99bd4ef 9303 {
53365c0d
PB
9304 if (!inst.operands[1].isreg)
9305 {
9306 if (opcode <= 0xffff)
9307 inst.instruction = THUMB_OP32 (opcode);
9308 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9309 return;
9310 }
0110f2b8
PB
9311 if (inst.operands[1].isreg
9312 && !inst.operands[1].writeback
c19d1205
ZW
9313 && !inst.operands[1].shifted && !inst.operands[1].postind
9314 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9315 && opcode <= 0xffff
9316 && inst.size_req != 4)
c19d1205 9317 {
0110f2b8
PB
9318 /* Insn may have a 16-bit form. */
9319 Rn = inst.operands[1].reg;
9320 if (inst.operands[1].immisreg)
9321 {
9322 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9323 /* [Rn, Rik] */
0110f2b8
PB
9324 if (Rn <= 7 && inst.operands[1].imm <= 7)
9325 goto op16;
9326 }
9327 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9328 && opcode != T_MNEM_ldrsb)
9329 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9330 || (Rn == REG_SP && opcode == T_MNEM_str))
9331 {
9332 /* [Rn, #const] */
9333 if (Rn > 7)
9334 {
9335 if (Rn == REG_PC)
9336 {
9337 if (inst.reloc.pc_rel)
9338 opcode = T_MNEM_ldr_pc2;
9339 else
9340 opcode = T_MNEM_ldr_pc;
9341 }
9342 else
9343 {
9344 if (opcode == T_MNEM_ldr)
9345 opcode = T_MNEM_ldr_sp;
9346 else
9347 opcode = T_MNEM_str_sp;
9348 }
9349 inst.instruction = inst.operands[0].reg << 8;
9350 }
9351 else
9352 {
9353 inst.instruction = inst.operands[0].reg;
9354 inst.instruction |= inst.operands[1].reg << 3;
9355 }
9356 inst.instruction |= THUMB_OP16 (opcode);
9357 if (inst.size_req == 2)
9358 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9359 else
9360 inst.relax = opcode;
9361 return;
9362 }
c19d1205 9363 }
0110f2b8
PB
9364 /* Definitely a 32-bit variant. */
9365 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9366 inst.instruction |= inst.operands[0].reg << 12;
9367 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9368 return;
9369 }
9370
c19d1205
ZW
9371 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9372
9373 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9374 {
c19d1205
ZW
9375 /* Only [Rn,Rm] is acceptable. */
9376 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9377 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9378 || inst.operands[1].postind || inst.operands[1].shifted
9379 || inst.operands[1].negative,
9380 _("Thumb does not support this addressing mode"));
9381 inst.instruction = THUMB_OP16 (inst.instruction);
9382 goto op16;
b99bd4ef 9383 }
5f4273c7 9384
c19d1205
ZW
9385 inst.instruction = THUMB_OP16 (inst.instruction);
9386 if (!inst.operands[1].isreg)
9387 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9388 return;
b99bd4ef 9389
c19d1205
ZW
9390 constraint (!inst.operands[1].preind
9391 || inst.operands[1].shifted
9392 || inst.operands[1].writeback,
9393 _("Thumb does not support this addressing mode"));
9394 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9395 {
c19d1205
ZW
9396 constraint (inst.instruction & 0x0600,
9397 _("byte or halfword not valid for base register"));
9398 constraint (inst.operands[1].reg == REG_PC
9399 && !(inst.instruction & THUMB_LOAD_BIT),
9400 _("r15 based store not allowed"));
9401 constraint (inst.operands[1].immisreg,
9402 _("invalid base register for register offset"));
b99bd4ef 9403
c19d1205
ZW
9404 if (inst.operands[1].reg == REG_PC)
9405 inst.instruction = T_OPCODE_LDR_PC;
9406 else if (inst.instruction & THUMB_LOAD_BIT)
9407 inst.instruction = T_OPCODE_LDR_SP;
9408 else
9409 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9410
c19d1205
ZW
9411 inst.instruction |= inst.operands[0].reg << 8;
9412 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9413 return;
9414 }
90e4755a 9415
c19d1205
ZW
9416 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9417 if (!inst.operands[1].immisreg)
9418 {
9419 /* Immediate offset. */
9420 inst.instruction |= inst.operands[0].reg;
9421 inst.instruction |= inst.operands[1].reg << 3;
9422 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9423 return;
9424 }
90e4755a 9425
c19d1205
ZW
9426 /* Register offset. */
9427 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9428 constraint (inst.operands[1].negative,
9429 _("Thumb does not support this addressing mode"));
90e4755a 9430
c19d1205
ZW
9431 op16:
9432 switch (inst.instruction)
9433 {
9434 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9435 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9436 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9437 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9438 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9439 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9440 case 0x5600 /* ldrsb */:
9441 case 0x5e00 /* ldrsh */: break;
9442 default: abort ();
9443 }
90e4755a 9444
c19d1205
ZW
9445 inst.instruction |= inst.operands[0].reg;
9446 inst.instruction |= inst.operands[1].reg << 3;
9447 inst.instruction |= inst.operands[1].imm << 6;
9448}
90e4755a 9449
c19d1205
ZW
9450static void
9451do_t_ldstd (void)
9452{
9453 if (!inst.operands[1].present)
b99bd4ef 9454 {
c19d1205
ZW
9455 inst.operands[1].reg = inst.operands[0].reg + 1;
9456 constraint (inst.operands[0].reg == REG_LR,
9457 _("r14 not allowed here"));
b99bd4ef 9458 }
c19d1205
ZW
9459 inst.instruction |= inst.operands[0].reg << 12;
9460 inst.instruction |= inst.operands[1].reg << 8;
9461 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9462}
9463
c19d1205
ZW
9464static void
9465do_t_ldstt (void)
9466{
9467 inst.instruction |= inst.operands[0].reg << 12;
9468 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9469}
a737bd4d 9470
b99bd4ef 9471static void
c19d1205 9472do_t_mla (void)
b99bd4ef 9473{
c19d1205
ZW
9474 inst.instruction |= inst.operands[0].reg << 8;
9475 inst.instruction |= inst.operands[1].reg << 16;
9476 inst.instruction |= inst.operands[2].reg;
9477 inst.instruction |= inst.operands[3].reg << 12;
9478}
b99bd4ef 9479
c19d1205
ZW
9480static void
9481do_t_mlal (void)
9482{
9483 inst.instruction |= inst.operands[0].reg << 12;
9484 inst.instruction |= inst.operands[1].reg << 8;
9485 inst.instruction |= inst.operands[2].reg << 16;
9486 inst.instruction |= inst.operands[3].reg;
9487}
b99bd4ef 9488
c19d1205
ZW
9489static void
9490do_t_mov_cmp (void)
9491{
9492 if (unified_syntax)
b99bd4ef 9493 {
c19d1205
ZW
9494 int r0off = (inst.instruction == T_MNEM_mov
9495 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9496 unsigned long opcode;
3d388997
PB
9497 bfd_boolean narrow;
9498 bfd_boolean low_regs;
9499
9500 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9501 opcode = inst.instruction;
3d388997 9502 if (current_it_mask)
0110f2b8 9503 narrow = opcode != T_MNEM_movs;
3d388997 9504 else
0110f2b8 9505 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9506 if (inst.size_req == 4
9507 || inst.operands[1].shifted)
9508 narrow = FALSE;
9509
efd81785
PB
9510 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9511 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9512 && !inst.operands[1].shifted
9513 && inst.operands[0].reg == REG_PC
9514 && inst.operands[1].reg == REG_LR)
9515 {
9516 inst.instruction = T2_SUBS_PC_LR;
9517 return;
9518 }
9519
c19d1205
ZW
9520 if (!inst.operands[1].isreg)
9521 {
0110f2b8
PB
9522 /* Immediate operand. */
9523 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9524 narrow = 0;
9525 if (low_regs && narrow)
9526 {
9527 inst.instruction = THUMB_OP16 (opcode);
9528 inst.instruction |= inst.operands[0].reg << 8;
9529 if (inst.size_req == 2)
9530 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9531 else
9532 inst.relax = opcode;
9533 }
9534 else
9535 {
9536 inst.instruction = THUMB_OP32 (inst.instruction);
9537 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9538 inst.instruction |= inst.operands[0].reg << r0off;
9539 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9540 }
c19d1205 9541 }
728ca7c9
PB
9542 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9543 && (inst.instruction == T_MNEM_mov
9544 || inst.instruction == T_MNEM_movs))
9545 {
9546 /* Register shifts are encoded as separate shift instructions. */
9547 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9548
9549 if (current_it_mask)
9550 narrow = !flags;
9551 else
9552 narrow = flags;
9553
9554 if (inst.size_req == 4)
9555 narrow = FALSE;
9556
9557 if (!low_regs || inst.operands[1].imm > 7)
9558 narrow = FALSE;
9559
9560 if (inst.operands[0].reg != inst.operands[1].reg)
9561 narrow = FALSE;
9562
9563 switch (inst.operands[1].shift_kind)
9564 {
9565 case SHIFT_LSL:
9566 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9567 break;
9568 case SHIFT_ASR:
9569 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9570 break;
9571 case SHIFT_LSR:
9572 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9573 break;
9574 case SHIFT_ROR:
9575 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9576 break;
9577 default:
5f4273c7 9578 abort ();
728ca7c9
PB
9579 }
9580
9581 inst.instruction = opcode;
9582 if (narrow)
9583 {
9584 inst.instruction |= inst.operands[0].reg;
9585 inst.instruction |= inst.operands[1].imm << 3;
9586 }
9587 else
9588 {
9589 if (flags)
9590 inst.instruction |= CONDS_BIT;
9591
9592 inst.instruction |= inst.operands[0].reg << 8;
9593 inst.instruction |= inst.operands[1].reg << 16;
9594 inst.instruction |= inst.operands[1].imm;
9595 }
9596 }
3d388997 9597 else if (!narrow)
c19d1205 9598 {
728ca7c9
PB
9599 /* Some mov with immediate shift have narrow variants.
9600 Register shifts are handled above. */
9601 if (low_regs && inst.operands[1].shifted
9602 && (inst.instruction == T_MNEM_mov
9603 || inst.instruction == T_MNEM_movs))
9604 {
9605 if (current_it_mask)
9606 narrow = (inst.instruction == T_MNEM_mov);
9607 else
9608 narrow = (inst.instruction == T_MNEM_movs);
9609 }
9610
9611 if (narrow)
9612 {
9613 switch (inst.operands[1].shift_kind)
9614 {
9615 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9616 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9617 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9618 default: narrow = FALSE; break;
9619 }
9620 }
9621
9622 if (narrow)
9623 {
9624 inst.instruction |= inst.operands[0].reg;
9625 inst.instruction |= inst.operands[1].reg << 3;
9626 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9627 }
9628 else
9629 {
9630 inst.instruction = THUMB_OP32 (inst.instruction);
9631 inst.instruction |= inst.operands[0].reg << r0off;
9632 encode_thumb32_shifted_operand (1);
9633 }
c19d1205
ZW
9634 }
9635 else
9636 switch (inst.instruction)
9637 {
9638 case T_MNEM_mov:
9639 inst.instruction = T_OPCODE_MOV_HR;
9640 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9641 inst.instruction |= (inst.operands[0].reg & 0x7);
9642 inst.instruction |= inst.operands[1].reg << 3;
9643 break;
b99bd4ef 9644
c19d1205
ZW
9645 case T_MNEM_movs:
9646 /* We know we have low registers at this point.
9647 Generate ADD Rd, Rs, #0. */
9648 inst.instruction = T_OPCODE_ADD_I3;
9649 inst.instruction |= inst.operands[0].reg;
9650 inst.instruction |= inst.operands[1].reg << 3;
9651 break;
9652
9653 case T_MNEM_cmp:
3d388997 9654 if (low_regs)
c19d1205
ZW
9655 {
9656 inst.instruction = T_OPCODE_CMP_LR;
9657 inst.instruction |= inst.operands[0].reg;
9658 inst.instruction |= inst.operands[1].reg << 3;
9659 }
9660 else
9661 {
9662 inst.instruction = T_OPCODE_CMP_HR;
9663 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9664 inst.instruction |= (inst.operands[0].reg & 0x7);
9665 inst.instruction |= inst.operands[1].reg << 3;
9666 }
9667 break;
9668 }
b99bd4ef
NC
9669 return;
9670 }
9671
c19d1205
ZW
9672 inst.instruction = THUMB_OP16 (inst.instruction);
9673 if (inst.operands[1].isreg)
b99bd4ef 9674 {
c19d1205 9675 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9676 {
c19d1205
ZW
9677 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9678 since a MOV instruction produces unpredictable results. */
9679 if (inst.instruction == T_OPCODE_MOV_I8)
9680 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9681 else
c19d1205 9682 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9683
c19d1205
ZW
9684 inst.instruction |= inst.operands[0].reg;
9685 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9686 }
9687 else
9688 {
c19d1205
ZW
9689 if (inst.instruction == T_OPCODE_MOV_I8)
9690 inst.instruction = T_OPCODE_MOV_HR;
9691 else
9692 inst.instruction = T_OPCODE_CMP_HR;
9693 do_t_cpy ();
b99bd4ef
NC
9694 }
9695 }
c19d1205 9696 else
b99bd4ef 9697 {
c19d1205
ZW
9698 constraint (inst.operands[0].reg > 7,
9699 _("only lo regs allowed with immediate"));
9700 inst.instruction |= inst.operands[0].reg << 8;
9701 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9702 }
9703}
b99bd4ef 9704
c19d1205
ZW
9705static void
9706do_t_mov16 (void)
9707{
b6895b4f
PB
9708 bfd_vma imm;
9709 bfd_boolean top;
9710
9711 top = (inst.instruction & 0x00800000) != 0;
9712 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9713 {
9714 constraint (top, _(":lower16: not allowed this instruction"));
9715 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9716 }
9717 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9718 {
9719 constraint (!top, _(":upper16: not allowed this instruction"));
9720 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9721 }
9722
c19d1205 9723 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9724 if (inst.reloc.type == BFD_RELOC_UNUSED)
9725 {
9726 imm = inst.reloc.exp.X_add_number;
9727 inst.instruction |= (imm & 0xf000) << 4;
9728 inst.instruction |= (imm & 0x0800) << 15;
9729 inst.instruction |= (imm & 0x0700) << 4;
9730 inst.instruction |= (imm & 0x00ff);
9731 }
c19d1205 9732}
b99bd4ef 9733
c19d1205
ZW
9734static void
9735do_t_mvn_tst (void)
9736{
9737 if (unified_syntax)
9738 {
9739 int r0off = (inst.instruction == T_MNEM_mvn
9740 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9741 bfd_boolean narrow;
9742
9743 if (inst.size_req == 4
9744 || inst.instruction > 0xffff
9745 || inst.operands[1].shifted
9746 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9747 narrow = FALSE;
9748 else if (inst.instruction == T_MNEM_cmn)
9749 narrow = TRUE;
9750 else if (THUMB_SETS_FLAGS (inst.instruction))
9751 narrow = (current_it_mask == 0);
9752 else
9753 narrow = (current_it_mask != 0);
9754
c19d1205 9755 if (!inst.operands[1].isreg)
b99bd4ef 9756 {
c19d1205
ZW
9757 /* For an immediate, we always generate a 32-bit opcode;
9758 section relaxation will shrink it later if possible. */
9759 if (inst.instruction < 0xffff)
9760 inst.instruction = THUMB_OP32 (inst.instruction);
9761 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9762 inst.instruction |= inst.operands[0].reg << r0off;
9763 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9764 }
c19d1205 9765 else
b99bd4ef 9766 {
c19d1205 9767 /* See if we can do this with a 16-bit instruction. */
3d388997 9768 if (narrow)
b99bd4ef 9769 {
c19d1205
ZW
9770 inst.instruction = THUMB_OP16 (inst.instruction);
9771 inst.instruction |= inst.operands[0].reg;
9772 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9773 }
c19d1205 9774 else
b99bd4ef 9775 {
c19d1205
ZW
9776 constraint (inst.operands[1].shifted
9777 && inst.operands[1].immisreg,
9778 _("shift must be constant"));
9779 if (inst.instruction < 0xffff)
9780 inst.instruction = THUMB_OP32 (inst.instruction);
9781 inst.instruction |= inst.operands[0].reg << r0off;
9782 encode_thumb32_shifted_operand (1);
b99bd4ef 9783 }
b99bd4ef
NC
9784 }
9785 }
9786 else
9787 {
c19d1205
ZW
9788 constraint (inst.instruction > 0xffff
9789 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9790 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9791 _("unshifted register required"));
9792 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9793 BAD_HIREG);
b99bd4ef 9794
c19d1205
ZW
9795 inst.instruction = THUMB_OP16 (inst.instruction);
9796 inst.instruction |= inst.operands[0].reg;
9797 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9798 }
b99bd4ef
NC
9799}
9800
b05fe5cf 9801static void
c19d1205 9802do_t_mrs (void)
b05fe5cf 9803{
62b3e311 9804 int flags;
037e8744
JB
9805
9806 if (do_vfp_nsyn_mrs () == SUCCESS)
9807 return;
9808
62b3e311
PB
9809 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9810 if (flags == 0)
9811 {
7e806470 9812 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9813 _("selected processor does not support "
9814 "requested special purpose register"));
9815 }
9816 else
9817 {
9818 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9819 _("selected processor does not support "
9820 "requested special purpose register %x"));
9821 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9822 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9823 _("'CPSR' or 'SPSR' expected"));
9824 }
5f4273c7 9825
c19d1205 9826 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9827 inst.instruction |= (flags & SPSR_BIT) >> 2;
9828 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9829}
b05fe5cf 9830
c19d1205
ZW
9831static void
9832do_t_msr (void)
9833{
62b3e311
PB
9834 int flags;
9835
037e8744
JB
9836 if (do_vfp_nsyn_msr () == SUCCESS)
9837 return;
9838
c19d1205
ZW
9839 constraint (!inst.operands[1].isreg,
9840 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9841 flags = inst.operands[0].imm;
9842 if (flags & ~0xff)
9843 {
9844 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9845 _("selected processor does not support "
9846 "requested special purpose register"));
9847 }
9848 else
9849 {
7e806470 9850 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9851 _("selected processor does not support "
9852 "requested special purpose register"));
9853 flags |= PSR_f;
9854 }
9855 inst.instruction |= (flags & SPSR_BIT) >> 2;
9856 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9857 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9858 inst.instruction |= inst.operands[1].reg << 16;
9859}
b05fe5cf 9860
c19d1205
ZW
9861static void
9862do_t_mul (void)
9863{
9864 if (!inst.operands[2].present)
9865 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9866
c19d1205
ZW
9867 /* There is no 32-bit MULS and no 16-bit MUL. */
9868 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9869 {
c19d1205
ZW
9870 inst.instruction = THUMB_OP32 (inst.instruction);
9871 inst.instruction |= inst.operands[0].reg << 8;
9872 inst.instruction |= inst.operands[1].reg << 16;
9873 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9874 }
c19d1205 9875 else
b05fe5cf 9876 {
c19d1205
ZW
9877 constraint (!unified_syntax
9878 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9879 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9880 BAD_HIREG);
b05fe5cf 9881
c19d1205
ZW
9882 inst.instruction = THUMB_OP16 (inst.instruction);
9883 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9884
c19d1205
ZW
9885 if (inst.operands[0].reg == inst.operands[1].reg)
9886 inst.instruction |= inst.operands[2].reg << 3;
9887 else if (inst.operands[0].reg == inst.operands[2].reg)
9888 inst.instruction |= inst.operands[1].reg << 3;
9889 else
9890 constraint (1, _("dest must overlap one source register"));
9891 }
9892}
b05fe5cf 9893
c19d1205
ZW
9894static void
9895do_t_mull (void)
9896{
9897 inst.instruction |= inst.operands[0].reg << 12;
9898 inst.instruction |= inst.operands[1].reg << 8;
9899 inst.instruction |= inst.operands[2].reg << 16;
9900 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9901
c19d1205
ZW
9902 if (inst.operands[0].reg == inst.operands[1].reg)
9903 as_tsktsk (_("rdhi and rdlo must be different"));
9904}
b05fe5cf 9905
c19d1205
ZW
9906static void
9907do_t_nop (void)
9908{
9909 if (unified_syntax)
9910 {
9911 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9912 {
c19d1205
ZW
9913 inst.instruction = THUMB_OP32 (inst.instruction);
9914 inst.instruction |= inst.operands[0].imm;
9915 }
9916 else
9917 {
9918 inst.instruction = THUMB_OP16 (inst.instruction);
9919 inst.instruction |= inst.operands[0].imm << 4;
9920 }
9921 }
9922 else
9923 {
9924 constraint (inst.operands[0].present,
9925 _("Thumb does not support NOP with hints"));
9926 inst.instruction = 0x46c0;
9927 }
9928}
b05fe5cf 9929
c19d1205
ZW
9930static void
9931do_t_neg (void)
9932{
9933 if (unified_syntax)
9934 {
3d388997
PB
9935 bfd_boolean narrow;
9936
9937 if (THUMB_SETS_FLAGS (inst.instruction))
9938 narrow = (current_it_mask == 0);
9939 else
9940 narrow = (current_it_mask != 0);
9941 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9942 narrow = FALSE;
9943 if (inst.size_req == 4)
9944 narrow = FALSE;
9945
9946 if (!narrow)
c19d1205
ZW
9947 {
9948 inst.instruction = THUMB_OP32 (inst.instruction);
9949 inst.instruction |= inst.operands[0].reg << 8;
9950 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9951 }
9952 else
9953 {
c19d1205
ZW
9954 inst.instruction = THUMB_OP16 (inst.instruction);
9955 inst.instruction |= inst.operands[0].reg;
9956 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9957 }
9958 }
9959 else
9960 {
c19d1205
ZW
9961 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9962 BAD_HIREG);
9963 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9964
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= inst.operands[0].reg;
9967 inst.instruction |= inst.operands[1].reg << 3;
9968 }
9969}
9970
9971static void
9972do_t_pkhbt (void)
9973{
9974 inst.instruction |= inst.operands[0].reg << 8;
9975 inst.instruction |= inst.operands[1].reg << 16;
9976 inst.instruction |= inst.operands[2].reg;
9977 if (inst.operands[3].present)
9978 {
9979 unsigned int val = inst.reloc.exp.X_add_number;
9980 constraint (inst.reloc.exp.X_op != O_constant,
9981 _("expression too complex"));
9982 inst.instruction |= (val & 0x1c) << 10;
9983 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9984 }
c19d1205 9985}
b05fe5cf 9986
c19d1205
ZW
9987static void
9988do_t_pkhtb (void)
9989{
9990 if (!inst.operands[3].present)
9991 inst.instruction &= ~0x00000020;
9992 do_t_pkhbt ();
b05fe5cf
ZW
9993}
9994
c19d1205
ZW
9995static void
9996do_t_pld (void)
9997{
9998 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9999}
b05fe5cf 10000
c19d1205
ZW
10001static void
10002do_t_push_pop (void)
b99bd4ef 10003{
e9f89963 10004 unsigned mask;
5f4273c7 10005
c19d1205
ZW
10006 constraint (inst.operands[0].writeback,
10007 _("push/pop do not support {reglist}^"));
10008 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10009 _("expression too complex"));
b99bd4ef 10010
e9f89963
PB
10011 mask = inst.operands[0].imm;
10012 if ((mask & ~0xff) == 0)
3c707909 10013 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10014 else if ((inst.instruction == T_MNEM_push
e9f89963 10015 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10016 || (inst.instruction == T_MNEM_pop
e9f89963 10017 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10018 {
c19d1205
ZW
10019 inst.instruction = THUMB_OP16 (inst.instruction);
10020 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10021 inst.instruction |= mask & 0xff;
c19d1205
ZW
10022 }
10023 else if (unified_syntax)
10024 {
3c707909 10025 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10026 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10027 }
10028 else
10029 {
10030 inst.error = _("invalid register list to push/pop instruction");
10031 return;
10032 }
c19d1205 10033}
b99bd4ef 10034
c19d1205
ZW
10035static void
10036do_t_rbit (void)
10037{
10038 inst.instruction |= inst.operands[0].reg << 8;
10039 inst.instruction |= inst.operands[1].reg << 16;
10040}
b99bd4ef 10041
c19d1205
ZW
10042static void
10043do_t_rev (void)
10044{
10045 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10046 && inst.size_req != 4)
10047 {
10048 inst.instruction = THUMB_OP16 (inst.instruction);
10049 inst.instruction |= inst.operands[0].reg;
10050 inst.instruction |= inst.operands[1].reg << 3;
10051 }
10052 else if (unified_syntax)
10053 {
10054 inst.instruction = THUMB_OP32 (inst.instruction);
10055 inst.instruction |= inst.operands[0].reg << 8;
10056 inst.instruction |= inst.operands[1].reg << 16;
10057 inst.instruction |= inst.operands[1].reg;
10058 }
10059 else
10060 inst.error = BAD_HIREG;
10061}
b99bd4ef 10062
c19d1205
ZW
10063static void
10064do_t_rsb (void)
10065{
10066 int Rd, Rs;
b99bd4ef 10067
c19d1205
ZW
10068 Rd = inst.operands[0].reg;
10069 Rs = (inst.operands[1].present
10070 ? inst.operands[1].reg /* Rd, Rs, foo */
10071 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10072
c19d1205
ZW
10073 inst.instruction |= Rd << 8;
10074 inst.instruction |= Rs << 16;
10075 if (!inst.operands[2].isreg)
10076 {
026d3abb
PB
10077 bfd_boolean narrow;
10078
10079 if ((inst.instruction & 0x00100000) != 0)
10080 narrow = (current_it_mask == 0);
10081 else
10082 narrow = (current_it_mask != 0);
10083
10084 if (Rd > 7 || Rs > 7)
10085 narrow = FALSE;
10086
10087 if (inst.size_req == 4 || !unified_syntax)
10088 narrow = FALSE;
10089
10090 if (inst.reloc.exp.X_op != O_constant
10091 || inst.reloc.exp.X_add_number != 0)
10092 narrow = FALSE;
10093
10094 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10095 relaxation, but it doesn't seem worth the hassle. */
10096 if (narrow)
10097 {
10098 inst.reloc.type = BFD_RELOC_UNUSED;
10099 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10100 inst.instruction |= Rs << 3;
10101 inst.instruction |= Rd;
10102 }
10103 else
10104 {
10105 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10106 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10107 }
c19d1205
ZW
10108 }
10109 else
10110 encode_thumb32_shifted_operand (2);
10111}
b99bd4ef 10112
c19d1205
ZW
10113static void
10114do_t_setend (void)
10115{
dfa9f0d5 10116 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10117 if (inst.operands[0].imm)
10118 inst.instruction |= 0x8;
10119}
b99bd4ef 10120
c19d1205
ZW
10121static void
10122do_t_shift (void)
10123{
10124 if (!inst.operands[1].present)
10125 inst.operands[1].reg = inst.operands[0].reg;
10126
10127 if (unified_syntax)
10128 {
3d388997
PB
10129 bfd_boolean narrow;
10130 int shift_kind;
10131
10132 switch (inst.instruction)
10133 {
10134 case T_MNEM_asr:
10135 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10136 case T_MNEM_lsl:
10137 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10138 case T_MNEM_lsr:
10139 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10140 case T_MNEM_ror:
10141 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10142 default: abort ();
10143 }
10144
10145 if (THUMB_SETS_FLAGS (inst.instruction))
10146 narrow = (current_it_mask == 0);
10147 else
10148 narrow = (current_it_mask != 0);
10149 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10150 narrow = FALSE;
10151 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10152 narrow = FALSE;
10153 if (inst.operands[2].isreg
10154 && (inst.operands[1].reg != inst.operands[0].reg
10155 || inst.operands[2].reg > 7))
10156 narrow = FALSE;
10157 if (inst.size_req == 4)
10158 narrow = FALSE;
10159
10160 if (!narrow)
c19d1205
ZW
10161 {
10162 if (inst.operands[2].isreg)
b99bd4ef 10163 {
c19d1205
ZW
10164 inst.instruction = THUMB_OP32 (inst.instruction);
10165 inst.instruction |= inst.operands[0].reg << 8;
10166 inst.instruction |= inst.operands[1].reg << 16;
10167 inst.instruction |= inst.operands[2].reg;
10168 }
10169 else
10170 {
10171 inst.operands[1].shifted = 1;
3d388997 10172 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10173 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10174 ? T_MNEM_movs : T_MNEM_mov);
10175 inst.instruction |= inst.operands[0].reg << 8;
10176 encode_thumb32_shifted_operand (1);
10177 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10178 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10179 }
10180 }
10181 else
10182 {
c19d1205 10183 if (inst.operands[2].isreg)
b99bd4ef 10184 {
3d388997 10185 switch (shift_kind)
b99bd4ef 10186 {
3d388997
PB
10187 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10188 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10189 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10190 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10191 default: abort ();
b99bd4ef 10192 }
5f4273c7 10193
c19d1205
ZW
10194 inst.instruction |= inst.operands[0].reg;
10195 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10196 }
10197 else
10198 {
3d388997 10199 switch (shift_kind)
b99bd4ef 10200 {
3d388997
PB
10201 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10202 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10203 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10204 default: abort ();
b99bd4ef 10205 }
c19d1205
ZW
10206 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10207 inst.instruction |= inst.operands[0].reg;
10208 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10209 }
10210 }
c19d1205
ZW
10211 }
10212 else
10213 {
10214 constraint (inst.operands[0].reg > 7
10215 || inst.operands[1].reg > 7, BAD_HIREG);
10216 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10217
c19d1205
ZW
10218 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10219 {
10220 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10221 constraint (inst.operands[0].reg != inst.operands[1].reg,
10222 _("source1 and dest must be same register"));
b99bd4ef 10223
c19d1205
ZW
10224 switch (inst.instruction)
10225 {
10226 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10227 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10228 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10229 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10230 default: abort ();
10231 }
5f4273c7 10232
c19d1205
ZW
10233 inst.instruction |= inst.operands[0].reg;
10234 inst.instruction |= inst.operands[2].reg << 3;
10235 }
10236 else
b99bd4ef 10237 {
c19d1205
ZW
10238 switch (inst.instruction)
10239 {
10240 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10241 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10242 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10243 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10244 default: abort ();
10245 }
10246 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10247 inst.instruction |= inst.operands[0].reg;
10248 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10249 }
10250 }
b99bd4ef
NC
10251}
10252
10253static void
c19d1205 10254do_t_simd (void)
b99bd4ef 10255{
c19d1205
ZW
10256 inst.instruction |= inst.operands[0].reg << 8;
10257 inst.instruction |= inst.operands[1].reg << 16;
10258 inst.instruction |= inst.operands[2].reg;
10259}
b99bd4ef 10260
c19d1205 10261static void
3eb17e6b 10262do_t_smc (void)
c19d1205
ZW
10263{
10264 unsigned int value = inst.reloc.exp.X_add_number;
10265 constraint (inst.reloc.exp.X_op != O_constant,
10266 _("expression too complex"));
10267 inst.reloc.type = BFD_RELOC_UNUSED;
10268 inst.instruction |= (value & 0xf000) >> 12;
10269 inst.instruction |= (value & 0x0ff0);
10270 inst.instruction |= (value & 0x000f) << 16;
10271}
b99bd4ef 10272
c19d1205
ZW
10273static void
10274do_t_ssat (void)
10275{
10276 inst.instruction |= inst.operands[0].reg << 8;
10277 inst.instruction |= inst.operands[1].imm - 1;
10278 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10279
c19d1205 10280 if (inst.operands[3].present)
b99bd4ef 10281 {
c19d1205
ZW
10282 constraint (inst.reloc.exp.X_op != O_constant,
10283 _("expression too complex"));
b99bd4ef 10284
c19d1205 10285 if (inst.reloc.exp.X_add_number != 0)
6189168b 10286 {
c19d1205
ZW
10287 if (inst.operands[3].shift_kind == SHIFT_ASR)
10288 inst.instruction |= 0x00200000; /* sh bit */
10289 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10290 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10291 }
c19d1205 10292 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10293 }
b99bd4ef
NC
10294}
10295
0dd132b6 10296static void
c19d1205 10297do_t_ssat16 (void)
0dd132b6 10298{
c19d1205
ZW
10299 inst.instruction |= inst.operands[0].reg << 8;
10300 inst.instruction |= inst.operands[1].imm - 1;
10301 inst.instruction |= inst.operands[2].reg << 16;
10302}
0dd132b6 10303
c19d1205
ZW
10304static void
10305do_t_strex (void)
10306{
10307 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10308 || inst.operands[2].postind || inst.operands[2].writeback
10309 || inst.operands[2].immisreg || inst.operands[2].shifted
10310 || inst.operands[2].negative,
01cfc07f 10311 BAD_ADDR_MODE);
0dd132b6 10312
c19d1205
ZW
10313 inst.instruction |= inst.operands[0].reg << 8;
10314 inst.instruction |= inst.operands[1].reg << 12;
10315 inst.instruction |= inst.operands[2].reg << 16;
10316 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10317}
10318
b99bd4ef 10319static void
c19d1205 10320do_t_strexd (void)
b99bd4ef 10321{
c19d1205
ZW
10322 if (!inst.operands[2].present)
10323 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10324
c19d1205
ZW
10325 constraint (inst.operands[0].reg == inst.operands[1].reg
10326 || inst.operands[0].reg == inst.operands[2].reg
10327 || inst.operands[0].reg == inst.operands[3].reg
10328 || inst.operands[1].reg == inst.operands[2].reg,
10329 BAD_OVERLAP);
b99bd4ef 10330
c19d1205
ZW
10331 inst.instruction |= inst.operands[0].reg;
10332 inst.instruction |= inst.operands[1].reg << 12;
10333 inst.instruction |= inst.operands[2].reg << 8;
10334 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10335}
10336
10337static void
c19d1205 10338do_t_sxtah (void)
b99bd4ef 10339{
c19d1205
ZW
10340 inst.instruction |= inst.operands[0].reg << 8;
10341 inst.instruction |= inst.operands[1].reg << 16;
10342 inst.instruction |= inst.operands[2].reg;
10343 inst.instruction |= inst.operands[3].imm << 4;
10344}
b99bd4ef 10345
c19d1205
ZW
10346static void
10347do_t_sxth (void)
10348{
10349 if (inst.instruction <= 0xffff && inst.size_req != 4
10350 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10351 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10352 {
c19d1205
ZW
10353 inst.instruction = THUMB_OP16 (inst.instruction);
10354 inst.instruction |= inst.operands[0].reg;
10355 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10356 }
c19d1205 10357 else if (unified_syntax)
b99bd4ef 10358 {
c19d1205
ZW
10359 if (inst.instruction <= 0xffff)
10360 inst.instruction = THUMB_OP32 (inst.instruction);
10361 inst.instruction |= inst.operands[0].reg << 8;
10362 inst.instruction |= inst.operands[1].reg;
10363 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10364 }
c19d1205 10365 else
b99bd4ef 10366 {
c19d1205
ZW
10367 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10368 _("Thumb encoding does not support rotation"));
10369 constraint (1, BAD_HIREG);
b99bd4ef 10370 }
c19d1205 10371}
b99bd4ef 10372
c19d1205
ZW
10373static void
10374do_t_swi (void)
10375{
10376 inst.reloc.type = BFD_RELOC_ARM_SWI;
10377}
b99bd4ef 10378
92e90b6e
PB
10379static void
10380do_t_tb (void)
10381{
10382 int half;
10383
10384 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10385 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10386 constraint (inst.operands[0].immisreg,
10387 _("instruction requires register index"));
92e90b6e
PB
10388 constraint (inst.operands[0].imm == 15,
10389 _("PC is not a valid index register"));
10390 constraint (!half && inst.operands[0].shifted,
10391 _("instruction does not allow shifted index"));
92e90b6e
PB
10392 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10393}
10394
c19d1205
ZW
10395static void
10396do_t_usat (void)
10397{
10398 inst.instruction |= inst.operands[0].reg << 8;
10399 inst.instruction |= inst.operands[1].imm;
10400 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10401
c19d1205 10402 if (inst.operands[3].present)
b99bd4ef 10403 {
c19d1205
ZW
10404 constraint (inst.reloc.exp.X_op != O_constant,
10405 _("expression too complex"));
10406 if (inst.reloc.exp.X_add_number != 0)
10407 {
10408 if (inst.operands[3].shift_kind == SHIFT_ASR)
10409 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10410
c19d1205
ZW
10411 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10412 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10413 }
10414 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10415 }
b99bd4ef
NC
10416}
10417
10418static void
c19d1205 10419do_t_usat16 (void)
b99bd4ef 10420{
c19d1205
ZW
10421 inst.instruction |= inst.operands[0].reg << 8;
10422 inst.instruction |= inst.operands[1].imm;
10423 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10424}
c19d1205 10425
5287ad62 10426/* Neon instruction encoder helpers. */
5f4273c7 10427
5287ad62 10428/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10429
5287ad62
JB
10430/* An "invalid" code for the following tables. */
10431#define N_INV -1u
10432
10433struct neon_tab_entry
b99bd4ef 10434{
5287ad62
JB
10435 unsigned integer;
10436 unsigned float_or_poly;
10437 unsigned scalar_or_imm;
10438};
5f4273c7 10439
5287ad62
JB
10440/* Map overloaded Neon opcodes to their respective encodings. */
10441#define NEON_ENC_TAB \
10442 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10443 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10444 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10445 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10446 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10447 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10448 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10449 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10450 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10451 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10452 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10453 /* Register variants of the following two instructions are encoded as
10454 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10455 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10456 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10457 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10458 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10459 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10460 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10461 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10462 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10463 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10464 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10465 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10466 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10467 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10468 X(vshl, 0x0000400, N_INV, 0x0800510), \
10469 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10470 X(vand, 0x0000110, N_INV, 0x0800030), \
10471 X(vbic, 0x0100110, N_INV, 0x0800030), \
10472 X(veor, 0x1000110, N_INV, N_INV), \
10473 X(vorn, 0x0300110, N_INV, 0x0800010), \
10474 X(vorr, 0x0200110, N_INV, 0x0800010), \
10475 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10476 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10477 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10478 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10479 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10480 X(vst1, 0x0000000, 0x0800000, N_INV), \
10481 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10482 X(vst2, 0x0000100, 0x0800100, N_INV), \
10483 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10484 X(vst3, 0x0000200, 0x0800200, N_INV), \
10485 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10486 X(vst4, 0x0000300, 0x0800300, N_INV), \
10487 X(vmovn, 0x1b20200, N_INV, N_INV), \
10488 X(vtrn, 0x1b20080, N_INV, N_INV), \
10489 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10490 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10491 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10492 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10493 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10494 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10495 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10496 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10497 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10498
10499enum neon_opc
10500{
10501#define X(OPC,I,F,S) N_MNEM_##OPC
10502NEON_ENC_TAB
10503#undef X
10504};
b99bd4ef 10505
5287ad62
JB
10506static const struct neon_tab_entry neon_enc_tab[] =
10507{
10508#define X(OPC,I,F,S) { (I), (F), (S) }
10509NEON_ENC_TAB
10510#undef X
10511};
b99bd4ef 10512
5287ad62
JB
10513#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10514#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10515#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10516#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10517#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10518#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10519#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10520#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10521#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10522#define NEON_ENC_SINGLE(X) \
10523 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10524#define NEON_ENC_DOUBLE(X) \
10525 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10526
037e8744
JB
10527/* Define shapes for instruction operands. The following mnemonic characters
10528 are used in this table:
5287ad62 10529
037e8744 10530 F - VFP S<n> register
5287ad62
JB
10531 D - Neon D<n> register
10532 Q - Neon Q<n> register
10533 I - Immediate
10534 S - Scalar
10535 R - ARM register
10536 L - D<n> register list
5f4273c7 10537
037e8744
JB
10538 This table is used to generate various data:
10539 - enumerations of the form NS_DDR to be used as arguments to
10540 neon_select_shape.
10541 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10542 - a table used to drive neon_select_shape. */
b99bd4ef 10543
037e8744
JB
10544#define NEON_SHAPE_DEF \
10545 X(3, (D, D, D), DOUBLE), \
10546 X(3, (Q, Q, Q), QUAD), \
10547 X(3, (D, D, I), DOUBLE), \
10548 X(3, (Q, Q, I), QUAD), \
10549 X(3, (D, D, S), DOUBLE), \
10550 X(3, (Q, Q, S), QUAD), \
10551 X(2, (D, D), DOUBLE), \
10552 X(2, (Q, Q), QUAD), \
10553 X(2, (D, S), DOUBLE), \
10554 X(2, (Q, S), QUAD), \
10555 X(2, (D, R), DOUBLE), \
10556 X(2, (Q, R), QUAD), \
10557 X(2, (D, I), DOUBLE), \
10558 X(2, (Q, I), QUAD), \
10559 X(3, (D, L, D), DOUBLE), \
10560 X(2, (D, Q), MIXED), \
10561 X(2, (Q, D), MIXED), \
10562 X(3, (D, Q, I), MIXED), \
10563 X(3, (Q, D, I), MIXED), \
10564 X(3, (Q, D, D), MIXED), \
10565 X(3, (D, Q, Q), MIXED), \
10566 X(3, (Q, Q, D), MIXED), \
10567 X(3, (Q, D, S), MIXED), \
10568 X(3, (D, Q, S), MIXED), \
10569 X(4, (D, D, D, I), DOUBLE), \
10570 X(4, (Q, Q, Q, I), QUAD), \
10571 X(2, (F, F), SINGLE), \
10572 X(3, (F, F, F), SINGLE), \
10573 X(2, (F, I), SINGLE), \
10574 X(2, (F, D), MIXED), \
10575 X(2, (D, F), MIXED), \
10576 X(3, (F, F, I), MIXED), \
10577 X(4, (R, R, F, F), SINGLE), \
10578 X(4, (F, F, R, R), SINGLE), \
10579 X(3, (D, R, R), DOUBLE), \
10580 X(3, (R, R, D), DOUBLE), \
10581 X(2, (S, R), SINGLE), \
10582 X(2, (R, S), SINGLE), \
10583 X(2, (F, R), SINGLE), \
10584 X(2, (R, F), SINGLE)
10585
10586#define S2(A,B) NS_##A##B
10587#define S3(A,B,C) NS_##A##B##C
10588#define S4(A,B,C,D) NS_##A##B##C##D
10589
10590#define X(N, L, C) S##N L
10591
5287ad62
JB
10592enum neon_shape
10593{
037e8744
JB
10594 NEON_SHAPE_DEF,
10595 NS_NULL
5287ad62 10596};
b99bd4ef 10597
037e8744
JB
10598#undef X
10599#undef S2
10600#undef S3
10601#undef S4
10602
10603enum neon_shape_class
10604{
10605 SC_SINGLE,
10606 SC_DOUBLE,
10607 SC_QUAD,
10608 SC_MIXED
10609};
10610
10611#define X(N, L, C) SC_##C
10612
10613static enum neon_shape_class neon_shape_class[] =
10614{
10615 NEON_SHAPE_DEF
10616};
10617
10618#undef X
10619
10620enum neon_shape_el
10621{
10622 SE_F,
10623 SE_D,
10624 SE_Q,
10625 SE_I,
10626 SE_S,
10627 SE_R,
10628 SE_L
10629};
10630
10631/* Register widths of above. */
10632static unsigned neon_shape_el_size[] =
10633{
10634 32,
10635 64,
10636 128,
10637 0,
10638 32,
10639 32,
10640 0
10641};
10642
10643struct neon_shape_info
10644{
10645 unsigned els;
10646 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10647};
10648
10649#define S2(A,B) { SE_##A, SE_##B }
10650#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10651#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10652
10653#define X(N, L, C) { N, S##N L }
10654
10655static struct neon_shape_info neon_shape_tab[] =
10656{
10657 NEON_SHAPE_DEF
10658};
10659
10660#undef X
10661#undef S2
10662#undef S3
10663#undef S4
10664
5287ad62
JB
10665/* Bit masks used in type checking given instructions.
10666 'N_EQK' means the type must be the same as (or based on in some way) the key
10667 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10668 set, various other bits can be set as well in order to modify the meaning of
10669 the type constraint. */
10670
10671enum neon_type_mask
10672{
10673 N_S8 = 0x000001,
10674 N_S16 = 0x000002,
10675 N_S32 = 0x000004,
10676 N_S64 = 0x000008,
10677 N_U8 = 0x000010,
10678 N_U16 = 0x000020,
10679 N_U32 = 0x000040,
10680 N_U64 = 0x000080,
10681 N_I8 = 0x000100,
10682 N_I16 = 0x000200,
10683 N_I32 = 0x000400,
10684 N_I64 = 0x000800,
10685 N_8 = 0x001000,
10686 N_16 = 0x002000,
10687 N_32 = 0x004000,
10688 N_64 = 0x008000,
10689 N_P8 = 0x010000,
10690 N_P16 = 0x020000,
10691 N_F32 = 0x040000,
037e8744
JB
10692 N_F64 = 0x080000,
10693 N_KEY = 0x100000, /* key element (main type specifier). */
10694 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10695 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10696 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10697 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10698 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10699 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10700 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10701 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10702 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10703 N_UTYP = 0,
037e8744 10704 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10705};
10706
dcbf9037
JB
10707#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10708
5287ad62
JB
10709#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10710#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10711#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10712#define N_SUF_32 (N_SU_32 | N_F32)
10713#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10714#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10715
10716/* Pass this as the first type argument to neon_check_type to ignore types
10717 altogether. */
10718#define N_IGNORE_TYPE (N_KEY | N_EQK)
10719
037e8744
JB
10720/* Select a "shape" for the current instruction (describing register types or
10721 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10722 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10723 function of operand parsing, so this function doesn't need to be called.
10724 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10725
10726static enum neon_shape
037e8744 10727neon_select_shape (enum neon_shape shape, ...)
5287ad62 10728{
037e8744
JB
10729 va_list ap;
10730 enum neon_shape first_shape = shape;
5287ad62
JB
10731
10732 /* Fix missing optional operands. FIXME: we don't know at this point how
10733 many arguments we should have, so this makes the assumption that we have
10734 > 1. This is true of all current Neon opcodes, I think, but may not be
10735 true in the future. */
10736 if (!inst.operands[1].present)
10737 inst.operands[1] = inst.operands[0];
10738
037e8744 10739 va_start (ap, shape);
5f4273c7 10740
037e8744
JB
10741 for (; shape != NS_NULL; shape = va_arg (ap, int))
10742 {
10743 unsigned j;
10744 int matches = 1;
10745
10746 for (j = 0; j < neon_shape_tab[shape].els; j++)
10747 {
10748 if (!inst.operands[j].present)
10749 {
10750 matches = 0;
10751 break;
10752 }
10753
10754 switch (neon_shape_tab[shape].el[j])
10755 {
10756 case SE_F:
10757 if (!(inst.operands[j].isreg
10758 && inst.operands[j].isvec
10759 && inst.operands[j].issingle
10760 && !inst.operands[j].isquad))
10761 matches = 0;
10762 break;
10763
10764 case SE_D:
10765 if (!(inst.operands[j].isreg
10766 && inst.operands[j].isvec
10767 && !inst.operands[j].isquad
10768 && !inst.operands[j].issingle))
10769 matches = 0;
10770 break;
10771
10772 case SE_R:
10773 if (!(inst.operands[j].isreg
10774 && !inst.operands[j].isvec))
10775 matches = 0;
10776 break;
10777
10778 case SE_Q:
10779 if (!(inst.operands[j].isreg
10780 && inst.operands[j].isvec
10781 && inst.operands[j].isquad
10782 && !inst.operands[j].issingle))
10783 matches = 0;
10784 break;
10785
10786 case SE_I:
10787 if (!(!inst.operands[j].isreg
10788 && !inst.operands[j].isscalar))
10789 matches = 0;
10790 break;
10791
10792 case SE_S:
10793 if (!(!inst.operands[j].isreg
10794 && inst.operands[j].isscalar))
10795 matches = 0;
10796 break;
10797
10798 case SE_L:
10799 break;
10800 }
10801 }
10802 if (matches)
5287ad62 10803 break;
037e8744 10804 }
5f4273c7 10805
037e8744 10806 va_end (ap);
5287ad62 10807
037e8744
JB
10808 if (shape == NS_NULL && first_shape != NS_NULL)
10809 first_error (_("invalid instruction shape"));
5287ad62 10810
037e8744
JB
10811 return shape;
10812}
5287ad62 10813
037e8744
JB
10814/* True if SHAPE is predominantly a quadword operation (most of the time, this
10815 means the Q bit should be set). */
10816
10817static int
10818neon_quad (enum neon_shape shape)
10819{
10820 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10821}
037e8744 10822
5287ad62
JB
10823static void
10824neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10825 unsigned *g_size)
10826{
10827 /* Allow modification to be made to types which are constrained to be
10828 based on the key element, based on bits set alongside N_EQK. */
10829 if ((typebits & N_EQK) != 0)
10830 {
10831 if ((typebits & N_HLF) != 0)
10832 *g_size /= 2;
10833 else if ((typebits & N_DBL) != 0)
10834 *g_size *= 2;
10835 if ((typebits & N_SGN) != 0)
10836 *g_type = NT_signed;
10837 else if ((typebits & N_UNS) != 0)
10838 *g_type = NT_unsigned;
10839 else if ((typebits & N_INT) != 0)
10840 *g_type = NT_integer;
10841 else if ((typebits & N_FLT) != 0)
10842 *g_type = NT_float;
dcbf9037
JB
10843 else if ((typebits & N_SIZ) != 0)
10844 *g_type = NT_untyped;
5287ad62
JB
10845 }
10846}
5f4273c7 10847
5287ad62
JB
10848/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10849 operand type, i.e. the single type specified in a Neon instruction when it
10850 is the only one given. */
10851
10852static struct neon_type_el
10853neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10854{
10855 struct neon_type_el dest = *key;
5f4273c7 10856
5287ad62 10857 assert ((thisarg & N_EQK) != 0);
5f4273c7 10858
5287ad62
JB
10859 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10860
10861 return dest;
10862}
10863
10864/* Convert Neon type and size into compact bitmask representation. */
10865
10866static enum neon_type_mask
10867type_chk_of_el_type (enum neon_el_type type, unsigned size)
10868{
10869 switch (type)
10870 {
10871 case NT_untyped:
10872 switch (size)
10873 {
10874 case 8: return N_8;
10875 case 16: return N_16;
10876 case 32: return N_32;
10877 case 64: return N_64;
10878 default: ;
10879 }
10880 break;
10881
10882 case NT_integer:
10883 switch (size)
10884 {
10885 case 8: return N_I8;
10886 case 16: return N_I16;
10887 case 32: return N_I32;
10888 case 64: return N_I64;
10889 default: ;
10890 }
10891 break;
10892
10893 case NT_float:
037e8744
JB
10894 switch (size)
10895 {
10896 case 32: return N_F32;
10897 case 64: return N_F64;
10898 default: ;
10899 }
5287ad62
JB
10900 break;
10901
10902 case NT_poly:
10903 switch (size)
10904 {
10905 case 8: return N_P8;
10906 case 16: return N_P16;
10907 default: ;
10908 }
10909 break;
10910
10911 case NT_signed:
10912 switch (size)
10913 {
10914 case 8: return N_S8;
10915 case 16: return N_S16;
10916 case 32: return N_S32;
10917 case 64: return N_S64;
10918 default: ;
10919 }
10920 break;
10921
10922 case NT_unsigned:
10923 switch (size)
10924 {
10925 case 8: return N_U8;
10926 case 16: return N_U16;
10927 case 32: return N_U32;
10928 case 64: return N_U64;
10929 default: ;
10930 }
10931 break;
10932
10933 default: ;
10934 }
5f4273c7 10935
5287ad62
JB
10936 return N_UTYP;
10937}
10938
10939/* Convert compact Neon bitmask type representation to a type and size. Only
10940 handles the case where a single bit is set in the mask. */
10941
dcbf9037 10942static int
5287ad62
JB
10943el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10944 enum neon_type_mask mask)
10945{
dcbf9037
JB
10946 if ((mask & N_EQK) != 0)
10947 return FAIL;
10948
5287ad62
JB
10949 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10950 *size = 8;
dcbf9037 10951 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10952 *size = 16;
dcbf9037 10953 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10954 *size = 32;
037e8744 10955 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10956 *size = 64;
dcbf9037
JB
10957 else
10958 return FAIL;
10959
5287ad62
JB
10960 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10961 *type = NT_signed;
dcbf9037 10962 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10963 *type = NT_unsigned;
dcbf9037 10964 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10965 *type = NT_integer;
dcbf9037 10966 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10967 *type = NT_untyped;
dcbf9037 10968 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10969 *type = NT_poly;
037e8744 10970 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10971 *type = NT_float;
dcbf9037
JB
10972 else
10973 return FAIL;
5f4273c7 10974
dcbf9037 10975 return SUCCESS;
5287ad62
JB
10976}
10977
10978/* Modify a bitmask of allowed types. This is only needed for type
10979 relaxation. */
10980
10981static unsigned
10982modify_types_allowed (unsigned allowed, unsigned mods)
10983{
10984 unsigned size;
10985 enum neon_el_type type;
10986 unsigned destmask;
10987 int i;
5f4273c7 10988
5287ad62 10989 destmask = 0;
5f4273c7 10990
5287ad62
JB
10991 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10992 {
dcbf9037
JB
10993 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10994 {
10995 neon_modify_type_size (mods, &type, &size);
10996 destmask |= type_chk_of_el_type (type, size);
10997 }
5287ad62 10998 }
5f4273c7 10999
5287ad62
JB
11000 return destmask;
11001}
11002
11003/* Check type and return type classification.
11004 The manual states (paraphrase): If one datatype is given, it indicates the
11005 type given in:
11006 - the second operand, if there is one
11007 - the operand, if there is no second operand
11008 - the result, if there are no operands.
11009 This isn't quite good enough though, so we use a concept of a "key" datatype
11010 which is set on a per-instruction basis, which is the one which matters when
11011 only one data type is written.
11012 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11013 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11014
11015static struct neon_type_el
11016neon_check_type (unsigned els, enum neon_shape ns, ...)
11017{
11018 va_list ap;
11019 unsigned i, pass, key_el = 0;
11020 unsigned types[NEON_MAX_TYPE_ELS];
11021 enum neon_el_type k_type = NT_invtype;
11022 unsigned k_size = -1u;
11023 struct neon_type_el badtype = {NT_invtype, -1};
11024 unsigned key_allowed = 0;
11025
11026 /* Optional registers in Neon instructions are always (not) in operand 1.
11027 Fill in the missing operand here, if it was omitted. */
11028 if (els > 1 && !inst.operands[1].present)
11029 inst.operands[1] = inst.operands[0];
11030
11031 /* Suck up all the varargs. */
11032 va_start (ap, ns);
11033 for (i = 0; i < els; i++)
11034 {
11035 unsigned thisarg = va_arg (ap, unsigned);
11036 if (thisarg == N_IGNORE_TYPE)
11037 {
11038 va_end (ap);
11039 return badtype;
11040 }
11041 types[i] = thisarg;
11042 if ((thisarg & N_KEY) != 0)
11043 key_el = i;
11044 }
11045 va_end (ap);
11046
dcbf9037
JB
11047 if (inst.vectype.elems > 0)
11048 for (i = 0; i < els; i++)
11049 if (inst.operands[i].vectype.type != NT_invtype)
11050 {
11051 first_error (_("types specified in both the mnemonic and operands"));
11052 return badtype;
11053 }
11054
5287ad62
JB
11055 /* Duplicate inst.vectype elements here as necessary.
11056 FIXME: No idea if this is exactly the same as the ARM assembler,
11057 particularly when an insn takes one register and one non-register
11058 operand. */
11059 if (inst.vectype.elems == 1 && els > 1)
11060 {
11061 unsigned j;
11062 inst.vectype.elems = els;
11063 inst.vectype.el[key_el] = inst.vectype.el[0];
11064 for (j = 0; j < els; j++)
dcbf9037
JB
11065 if (j != key_el)
11066 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11067 types[j]);
11068 }
11069 else if (inst.vectype.elems == 0 && els > 0)
11070 {
11071 unsigned j;
11072 /* No types were given after the mnemonic, so look for types specified
11073 after each operand. We allow some flexibility here; as long as the
11074 "key" operand has a type, we can infer the others. */
11075 for (j = 0; j < els; j++)
11076 if (inst.operands[j].vectype.type != NT_invtype)
11077 inst.vectype.el[j] = inst.operands[j].vectype;
11078
11079 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11080 {
dcbf9037
JB
11081 for (j = 0; j < els; j++)
11082 if (inst.operands[j].vectype.type == NT_invtype)
11083 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11084 types[j]);
11085 }
11086 else
11087 {
11088 first_error (_("operand types can't be inferred"));
11089 return badtype;
5287ad62
JB
11090 }
11091 }
11092 else if (inst.vectype.elems != els)
11093 {
dcbf9037 11094 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11095 return badtype;
11096 }
11097
11098 for (pass = 0; pass < 2; pass++)
11099 {
11100 for (i = 0; i < els; i++)
11101 {
11102 unsigned thisarg = types[i];
11103 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11104 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11105 enum neon_el_type g_type = inst.vectype.el[i].type;
11106 unsigned g_size = inst.vectype.el[i].size;
11107
11108 /* Decay more-specific signed & unsigned types to sign-insensitive
11109 integer types if sign-specific variants are unavailable. */
11110 if ((g_type == NT_signed || g_type == NT_unsigned)
11111 && (types_allowed & N_SU_ALL) == 0)
11112 g_type = NT_integer;
11113
11114 /* If only untyped args are allowed, decay any more specific types to
11115 them. Some instructions only care about signs for some element
11116 sizes, so handle that properly. */
11117 if ((g_size == 8 && (types_allowed & N_8) != 0)
11118 || (g_size == 16 && (types_allowed & N_16) != 0)
11119 || (g_size == 32 && (types_allowed & N_32) != 0)
11120 || (g_size == 64 && (types_allowed & N_64) != 0))
11121 g_type = NT_untyped;
11122
11123 if (pass == 0)
11124 {
11125 if ((thisarg & N_KEY) != 0)
11126 {
11127 k_type = g_type;
11128 k_size = g_size;
11129 key_allowed = thisarg & ~N_KEY;
11130 }
11131 }
11132 else
11133 {
037e8744
JB
11134 if ((thisarg & N_VFP) != 0)
11135 {
11136 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11137 unsigned regwidth = neon_shape_el_size[regshape], match;
11138
11139 /* In VFP mode, operands must match register widths. If we
11140 have a key operand, use its width, else use the width of
11141 the current operand. */
11142 if (k_size != -1u)
11143 match = k_size;
11144 else
11145 match = g_size;
11146
11147 if (regwidth != match)
11148 {
11149 first_error (_("operand size must match register width"));
11150 return badtype;
11151 }
11152 }
5f4273c7 11153
5287ad62
JB
11154 if ((thisarg & N_EQK) == 0)
11155 {
11156 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11157
11158 if ((given_type & types_allowed) == 0)
11159 {
dcbf9037 11160 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11161 return badtype;
11162 }
11163 }
11164 else
11165 {
11166 enum neon_el_type mod_k_type = k_type;
11167 unsigned mod_k_size = k_size;
11168 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11169 if (g_type != mod_k_type || g_size != mod_k_size)
11170 {
dcbf9037 11171 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11172 return badtype;
11173 }
11174 }
11175 }
11176 }
11177 }
11178
11179 return inst.vectype.el[key_el];
11180}
11181
037e8744 11182/* Neon-style VFP instruction forwarding. */
5287ad62 11183
037e8744
JB
11184/* Thumb VFP instructions have 0xE in the condition field. */
11185
11186static void
11187do_vfp_cond_or_thumb (void)
5287ad62
JB
11188{
11189 if (thumb_mode)
037e8744 11190 inst.instruction |= 0xe0000000;
5287ad62 11191 else
037e8744 11192 inst.instruction |= inst.cond << 28;
5287ad62
JB
11193}
11194
037e8744
JB
11195/* Look up and encode a simple mnemonic, for use as a helper function for the
11196 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11197 etc. It is assumed that operand parsing has already been done, and that the
11198 operands are in the form expected by the given opcode (this isn't necessarily
11199 the same as the form in which they were parsed, hence some massaging must
11200 take place before this function is called).
11201 Checks current arch version against that in the looked-up opcode. */
5287ad62 11202
037e8744
JB
11203static void
11204do_vfp_nsyn_opcode (const char *opname)
5287ad62 11205{
037e8744 11206 const struct asm_opcode *opcode;
5f4273c7 11207
037e8744 11208 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11209
037e8744
JB
11210 if (!opcode)
11211 abort ();
5287ad62 11212
037e8744
JB
11213 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11214 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11215 _(BAD_FPU));
5287ad62 11216
037e8744
JB
11217 if (thumb_mode)
11218 {
11219 inst.instruction = opcode->tvalue;
11220 opcode->tencode ();
11221 }
11222 else
11223 {
11224 inst.instruction = (inst.cond << 28) | opcode->avalue;
11225 opcode->aencode ();
11226 }
11227}
5287ad62
JB
11228
11229static void
037e8744 11230do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11231{
037e8744
JB
11232 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11233
11234 if (rs == NS_FFF)
11235 {
11236 if (is_add)
11237 do_vfp_nsyn_opcode ("fadds");
11238 else
11239 do_vfp_nsyn_opcode ("fsubs");
11240 }
11241 else
11242 {
11243 if (is_add)
11244 do_vfp_nsyn_opcode ("faddd");
11245 else
11246 do_vfp_nsyn_opcode ("fsubd");
11247 }
11248}
11249
11250/* Check operand types to see if this is a VFP instruction, and if so call
11251 PFN (). */
11252
11253static int
11254try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11255{
11256 enum neon_shape rs;
11257 struct neon_type_el et;
11258
11259 switch (args)
11260 {
11261 case 2:
11262 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11263 et = neon_check_type (2, rs,
11264 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11265 break;
5f4273c7 11266
037e8744
JB
11267 case 3:
11268 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11269 et = neon_check_type (3, rs,
11270 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11271 break;
11272
11273 default:
11274 abort ();
11275 }
11276
11277 if (et.type != NT_invtype)
11278 {
11279 pfn (rs);
11280 return SUCCESS;
11281 }
11282 else
11283 inst.error = NULL;
11284
11285 return FAIL;
11286}
11287
11288static void
11289do_vfp_nsyn_mla_mls (enum neon_shape rs)
11290{
11291 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11292
037e8744
JB
11293 if (rs == NS_FFF)
11294 {
11295 if (is_mla)
11296 do_vfp_nsyn_opcode ("fmacs");
11297 else
11298 do_vfp_nsyn_opcode ("fmscs");
11299 }
11300 else
11301 {
11302 if (is_mla)
11303 do_vfp_nsyn_opcode ("fmacd");
11304 else
11305 do_vfp_nsyn_opcode ("fmscd");
11306 }
11307}
11308
11309static void
11310do_vfp_nsyn_mul (enum neon_shape rs)
11311{
11312 if (rs == NS_FFF)
11313 do_vfp_nsyn_opcode ("fmuls");
11314 else
11315 do_vfp_nsyn_opcode ("fmuld");
11316}
11317
11318static void
11319do_vfp_nsyn_abs_neg (enum neon_shape rs)
11320{
11321 int is_neg = (inst.instruction & 0x80) != 0;
11322 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11323
11324 if (rs == NS_FF)
11325 {
11326 if (is_neg)
11327 do_vfp_nsyn_opcode ("fnegs");
11328 else
11329 do_vfp_nsyn_opcode ("fabss");
11330 }
11331 else
11332 {
11333 if (is_neg)
11334 do_vfp_nsyn_opcode ("fnegd");
11335 else
11336 do_vfp_nsyn_opcode ("fabsd");
11337 }
11338}
11339
11340/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11341 insns belong to Neon, and are handled elsewhere. */
11342
11343static void
11344do_vfp_nsyn_ldm_stm (int is_dbmode)
11345{
11346 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11347 if (is_ldm)
11348 {
11349 if (is_dbmode)
11350 do_vfp_nsyn_opcode ("fldmdbs");
11351 else
11352 do_vfp_nsyn_opcode ("fldmias");
11353 }
11354 else
11355 {
11356 if (is_dbmode)
11357 do_vfp_nsyn_opcode ("fstmdbs");
11358 else
11359 do_vfp_nsyn_opcode ("fstmias");
11360 }
11361}
11362
037e8744
JB
11363static void
11364do_vfp_nsyn_sqrt (void)
11365{
11366 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11367 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11368
037e8744
JB
11369 if (rs == NS_FF)
11370 do_vfp_nsyn_opcode ("fsqrts");
11371 else
11372 do_vfp_nsyn_opcode ("fsqrtd");
11373}
11374
11375static void
11376do_vfp_nsyn_div (void)
11377{
11378 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11379 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11380 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11381
037e8744
JB
11382 if (rs == NS_FFF)
11383 do_vfp_nsyn_opcode ("fdivs");
11384 else
11385 do_vfp_nsyn_opcode ("fdivd");
11386}
11387
11388static void
11389do_vfp_nsyn_nmul (void)
11390{
11391 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11392 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11393 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11394
037e8744
JB
11395 if (rs == NS_FFF)
11396 {
11397 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11398 do_vfp_sp_dyadic ();
11399 }
11400 else
11401 {
11402 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11403 do_vfp_dp_rd_rn_rm ();
11404 }
11405 do_vfp_cond_or_thumb ();
11406}
11407
11408static void
11409do_vfp_nsyn_cmp (void)
11410{
11411 if (inst.operands[1].isreg)
11412 {
11413 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11414 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11415
037e8744
JB
11416 if (rs == NS_FF)
11417 {
11418 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11419 do_vfp_sp_monadic ();
11420 }
11421 else
11422 {
11423 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11424 do_vfp_dp_rd_rm ();
11425 }
11426 }
11427 else
11428 {
11429 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11430 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11431
11432 switch (inst.instruction & 0x0fffffff)
11433 {
11434 case N_MNEM_vcmp:
11435 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11436 break;
11437 case N_MNEM_vcmpe:
11438 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11439 break;
11440 default:
11441 abort ();
11442 }
5f4273c7 11443
037e8744
JB
11444 if (rs == NS_FI)
11445 {
11446 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11447 do_vfp_sp_compare_z ();
11448 }
11449 else
11450 {
11451 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11452 do_vfp_dp_rd ();
11453 }
11454 }
11455 do_vfp_cond_or_thumb ();
11456}
11457
11458static void
11459nsyn_insert_sp (void)
11460{
11461 inst.operands[1] = inst.operands[0];
11462 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11463 inst.operands[0].reg = 13;
11464 inst.operands[0].isreg = 1;
11465 inst.operands[0].writeback = 1;
11466 inst.operands[0].present = 1;
11467}
11468
11469static void
11470do_vfp_nsyn_push (void)
11471{
11472 nsyn_insert_sp ();
11473 if (inst.operands[1].issingle)
11474 do_vfp_nsyn_opcode ("fstmdbs");
11475 else
11476 do_vfp_nsyn_opcode ("fstmdbd");
11477}
11478
11479static void
11480do_vfp_nsyn_pop (void)
11481{
11482 nsyn_insert_sp ();
11483 if (inst.operands[1].issingle)
22b5b651 11484 do_vfp_nsyn_opcode ("fldmias");
037e8744 11485 else
22b5b651 11486 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11487}
11488
11489/* Fix up Neon data-processing instructions, ORing in the correct bits for
11490 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11491
11492static unsigned
11493neon_dp_fixup (unsigned i)
11494{
11495 if (thumb_mode)
11496 {
11497 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11498 if (i & (1 << 24))
11499 i |= 1 << 28;
5f4273c7 11500
037e8744 11501 i &= ~(1 << 24);
5f4273c7 11502
037e8744
JB
11503 i |= 0xef000000;
11504 }
11505 else
11506 i |= 0xf2000000;
5f4273c7 11507
037e8744
JB
11508 return i;
11509}
11510
11511/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11512 (0, 1, 2, 3). */
11513
11514static unsigned
11515neon_logbits (unsigned x)
11516{
11517 return ffs (x) - 4;
11518}
11519
11520#define LOW4(R) ((R) & 0xf)
11521#define HI1(R) (((R) >> 4) & 1)
11522
11523/* Encode insns with bit pattern:
11524
11525 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11526 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11527
037e8744
JB
11528 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11529 different meaning for some instruction. */
11530
11531static void
11532neon_three_same (int isquad, int ubit, int size)
11533{
11534 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11535 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11536 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11537 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11538 inst.instruction |= LOW4 (inst.operands[2].reg);
11539 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11540 inst.instruction |= (isquad != 0) << 6;
11541 inst.instruction |= (ubit != 0) << 24;
11542 if (size != -1)
11543 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11544
037e8744
JB
11545 inst.instruction = neon_dp_fixup (inst.instruction);
11546}
11547
11548/* Encode instructions of the form:
11549
11550 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11551 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11552
11553 Don't write size if SIZE == -1. */
11554
11555static void
11556neon_two_same (int qbit, int ubit, int size)
11557{
11558 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11559 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11560 inst.instruction |= LOW4 (inst.operands[1].reg);
11561 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11562 inst.instruction |= (qbit != 0) << 6;
11563 inst.instruction |= (ubit != 0) << 24;
11564
11565 if (size != -1)
11566 inst.instruction |= neon_logbits (size) << 18;
11567
11568 inst.instruction = neon_dp_fixup (inst.instruction);
11569}
11570
11571/* Neon instruction encoders, in approximate order of appearance. */
11572
11573static void
11574do_neon_dyadic_i_su (void)
11575{
037e8744 11576 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11577 struct neon_type_el et = neon_check_type (3, rs,
11578 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11579 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11580}
11581
11582static void
11583do_neon_dyadic_i64_su (void)
11584{
037e8744 11585 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11586 struct neon_type_el et = neon_check_type (3, rs,
11587 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11588 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11589}
11590
11591static void
11592neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11593 unsigned immbits)
11594{
11595 unsigned size = et.size >> 3;
11596 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11597 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11598 inst.instruction |= LOW4 (inst.operands[1].reg);
11599 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11600 inst.instruction |= (isquad != 0) << 6;
11601 inst.instruction |= immbits << 16;
11602 inst.instruction |= (size >> 3) << 7;
11603 inst.instruction |= (size & 0x7) << 19;
11604 if (write_ubit)
11605 inst.instruction |= (uval != 0) << 24;
11606
11607 inst.instruction = neon_dp_fixup (inst.instruction);
11608}
11609
11610static void
11611do_neon_shl_imm (void)
11612{
11613 if (!inst.operands[2].isreg)
11614 {
037e8744 11615 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11616 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11617 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11618 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11619 }
11620 else
11621 {
037e8744 11622 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11623 struct neon_type_el et = neon_check_type (3, rs,
11624 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11625 unsigned int tmp;
11626
11627 /* VSHL/VQSHL 3-register variants have syntax such as:
11628 vshl.xx Dd, Dm, Dn
11629 whereas other 3-register operations encoded by neon_three_same have
11630 syntax like:
11631 vadd.xx Dd, Dn, Dm
11632 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11633 here. */
11634 tmp = inst.operands[2].reg;
11635 inst.operands[2].reg = inst.operands[1].reg;
11636 inst.operands[1].reg = tmp;
5287ad62 11637 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11638 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11639 }
11640}
11641
11642static void
11643do_neon_qshl_imm (void)
11644{
11645 if (!inst.operands[2].isreg)
11646 {
037e8744 11647 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11648 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11649
5287ad62 11650 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11651 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11652 inst.operands[2].imm);
11653 }
11654 else
11655 {
037e8744 11656 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11657 struct neon_type_el et = neon_check_type (3, rs,
11658 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11659 unsigned int tmp;
11660
11661 /* See note in do_neon_shl_imm. */
11662 tmp = inst.operands[2].reg;
11663 inst.operands[2].reg = inst.operands[1].reg;
11664 inst.operands[1].reg = tmp;
5287ad62 11665 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11666 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11667 }
11668}
11669
627907b7
JB
11670static void
11671do_neon_rshl (void)
11672{
11673 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11674 struct neon_type_el et = neon_check_type (3, rs,
11675 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11676 unsigned int tmp;
11677
11678 tmp = inst.operands[2].reg;
11679 inst.operands[2].reg = inst.operands[1].reg;
11680 inst.operands[1].reg = tmp;
11681 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11682}
11683
5287ad62
JB
11684static int
11685neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11686{
036dc3f7
PB
11687 /* Handle .I8 pseudo-instructions. */
11688 if (size == 8)
5287ad62 11689 {
5287ad62
JB
11690 /* Unfortunately, this will make everything apart from zero out-of-range.
11691 FIXME is this the intended semantics? There doesn't seem much point in
11692 accepting .I8 if so. */
11693 immediate |= immediate << 8;
11694 size = 16;
036dc3f7
PB
11695 }
11696
11697 if (size >= 32)
11698 {
11699 if (immediate == (immediate & 0x000000ff))
11700 {
11701 *immbits = immediate;
11702 return 0x1;
11703 }
11704 else if (immediate == (immediate & 0x0000ff00))
11705 {
11706 *immbits = immediate >> 8;
11707 return 0x3;
11708 }
11709 else if (immediate == (immediate & 0x00ff0000))
11710 {
11711 *immbits = immediate >> 16;
11712 return 0x5;
11713 }
11714 else if (immediate == (immediate & 0xff000000))
11715 {
11716 *immbits = immediate >> 24;
11717 return 0x7;
11718 }
11719 if ((immediate & 0xffff) != (immediate >> 16))
11720 goto bad_immediate;
11721 immediate &= 0xffff;
5287ad62
JB
11722 }
11723
11724 if (immediate == (immediate & 0x000000ff))
11725 {
11726 *immbits = immediate;
036dc3f7 11727 return 0x9;
5287ad62
JB
11728 }
11729 else if (immediate == (immediate & 0x0000ff00))
11730 {
11731 *immbits = immediate >> 8;
036dc3f7 11732 return 0xb;
5287ad62
JB
11733 }
11734
11735 bad_immediate:
dcbf9037 11736 first_error (_("immediate value out of range"));
5287ad62
JB
11737 return FAIL;
11738}
11739
11740/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11741 A, B, C, D. */
11742
11743static int
11744neon_bits_same_in_bytes (unsigned imm)
11745{
11746 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11747 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11748 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11749 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11750}
11751
11752/* For immediate of above form, return 0bABCD. */
11753
11754static unsigned
11755neon_squash_bits (unsigned imm)
11756{
11757 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11758 | ((imm & 0x01000000) >> 21);
11759}
11760
136da414 11761/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11762
11763static unsigned
11764neon_qfloat_bits (unsigned imm)
11765{
136da414 11766 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11767}
11768
11769/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11770 the instruction. *OP is passed as the initial value of the op field, and
11771 may be set to a different value depending on the constant (i.e.
11772 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 11773 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 11774 try smaller element sizes. */
5287ad62
JB
11775
11776static int
c96612cc
JB
11777neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11778 unsigned *immbits, int *op, int size,
11779 enum neon_el_type type)
5287ad62 11780{
c96612cc
JB
11781 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11782 float. */
11783 if (type == NT_float && !float_p)
11784 return FAIL;
11785
136da414
JB
11786 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11787 {
11788 if (size != 32 || *op == 1)
11789 return FAIL;
11790 *immbits = neon_qfloat_bits (immlo);
11791 return 0xf;
11792 }
036dc3f7
PB
11793
11794 if (size == 64)
5287ad62 11795 {
036dc3f7
PB
11796 if (neon_bits_same_in_bytes (immhi)
11797 && neon_bits_same_in_bytes (immlo))
11798 {
11799 if (*op == 1)
11800 return FAIL;
11801 *immbits = (neon_squash_bits (immhi) << 4)
11802 | neon_squash_bits (immlo);
11803 *op = 1;
11804 return 0xe;
11805 }
11806
11807 if (immhi != immlo)
11808 return FAIL;
5287ad62 11809 }
036dc3f7
PB
11810
11811 if (size >= 32)
5287ad62 11812 {
036dc3f7
PB
11813 if (immlo == (immlo & 0x000000ff))
11814 {
11815 *immbits = immlo;
11816 return 0x0;
11817 }
11818 else if (immlo == (immlo & 0x0000ff00))
11819 {
11820 *immbits = immlo >> 8;
11821 return 0x2;
11822 }
11823 else if (immlo == (immlo & 0x00ff0000))
11824 {
11825 *immbits = immlo >> 16;
11826 return 0x4;
11827 }
11828 else if (immlo == (immlo & 0xff000000))
11829 {
11830 *immbits = immlo >> 24;
11831 return 0x6;
11832 }
11833 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11834 {
11835 *immbits = (immlo >> 8) & 0xff;
11836 return 0xc;
11837 }
11838 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11839 {
11840 *immbits = (immlo >> 16) & 0xff;
11841 return 0xd;
11842 }
11843
11844 if ((immlo & 0xffff) != (immlo >> 16))
11845 return FAIL;
11846 immlo &= 0xffff;
5287ad62 11847 }
036dc3f7
PB
11848
11849 if (size >= 16)
5287ad62 11850 {
036dc3f7
PB
11851 if (immlo == (immlo & 0x000000ff))
11852 {
11853 *immbits = immlo;
11854 return 0x8;
11855 }
11856 else if (immlo == (immlo & 0x0000ff00))
11857 {
11858 *immbits = immlo >> 8;
11859 return 0xa;
11860 }
11861
11862 if ((immlo & 0xff) != (immlo >> 8))
11863 return FAIL;
11864 immlo &= 0xff;
5287ad62 11865 }
036dc3f7
PB
11866
11867 if (immlo == (immlo & 0x000000ff))
5287ad62 11868 {
036dc3f7
PB
11869 /* Don't allow MVN with 8-bit immediate. */
11870 if (*op == 1)
11871 return FAIL;
11872 *immbits = immlo;
11873 return 0xe;
5287ad62 11874 }
5287ad62
JB
11875
11876 return FAIL;
11877}
11878
11879/* Write immediate bits [7:0] to the following locations:
11880
11881 |28/24|23 19|18 16|15 4|3 0|
11882 | 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|
11883
11884 This function is used by VMOV/VMVN/VORR/VBIC. */
11885
11886static void
11887neon_write_immbits (unsigned immbits)
11888{
11889 inst.instruction |= immbits & 0xf;
11890 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11891 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11892}
11893
11894/* Invert low-order SIZE bits of XHI:XLO. */
11895
11896static void
11897neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11898{
11899 unsigned immlo = xlo ? *xlo : 0;
11900 unsigned immhi = xhi ? *xhi : 0;
11901
11902 switch (size)
11903 {
11904 case 8:
11905 immlo = (~immlo) & 0xff;
11906 break;
11907
11908 case 16:
11909 immlo = (~immlo) & 0xffff;
11910 break;
11911
11912 case 64:
11913 immhi = (~immhi) & 0xffffffff;
11914 /* fall through. */
11915
11916 case 32:
11917 immlo = (~immlo) & 0xffffffff;
11918 break;
11919
11920 default:
11921 abort ();
11922 }
11923
11924 if (xlo)
11925 *xlo = immlo;
11926
11927 if (xhi)
11928 *xhi = immhi;
11929}
11930
11931static void
11932do_neon_logic (void)
11933{
11934 if (inst.operands[2].present && inst.operands[2].isreg)
11935 {
037e8744 11936 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11937 neon_check_type (3, rs, N_IGNORE_TYPE);
11938 /* U bit and size field were set as part of the bitmask. */
11939 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11940 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11941 }
11942 else
11943 {
037e8744
JB
11944 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11945 struct neon_type_el et = neon_check_type (2, rs,
11946 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11947 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11948 unsigned immbits;
11949 int cmode;
5f4273c7 11950
5287ad62
JB
11951 if (et.type == NT_invtype)
11952 return;
5f4273c7 11953
5287ad62
JB
11954 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11955
036dc3f7
PB
11956 immbits = inst.operands[1].imm;
11957 if (et.size == 64)
11958 {
11959 /* .i64 is a pseudo-op, so the immediate must be a repeating
11960 pattern. */
11961 if (immbits != (inst.operands[1].regisimm ?
11962 inst.operands[1].reg : 0))
11963 {
11964 /* Set immbits to an invalid constant. */
11965 immbits = 0xdeadbeef;
11966 }
11967 }
11968
5287ad62
JB
11969 switch (opcode)
11970 {
11971 case N_MNEM_vbic:
036dc3f7 11972 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11973 break;
5f4273c7 11974
5287ad62 11975 case N_MNEM_vorr:
036dc3f7 11976 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 11977 break;
5f4273c7 11978
5287ad62
JB
11979 case N_MNEM_vand:
11980 /* Pseudo-instruction for VBIC. */
5287ad62
JB
11981 neon_invert_size (&immbits, 0, et.size);
11982 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11983 break;
5f4273c7 11984
5287ad62
JB
11985 case N_MNEM_vorn:
11986 /* Pseudo-instruction for VORR. */
5287ad62
JB
11987 neon_invert_size (&immbits, 0, et.size);
11988 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11989 break;
5f4273c7 11990
5287ad62
JB
11991 default:
11992 abort ();
11993 }
11994
11995 if (cmode == FAIL)
11996 return;
11997
037e8744 11998 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11999 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12000 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12001 inst.instruction |= cmode << 8;
12002 neon_write_immbits (immbits);
5f4273c7 12003
5287ad62
JB
12004 inst.instruction = neon_dp_fixup (inst.instruction);
12005 }
12006}
12007
12008static void
12009do_neon_bitfield (void)
12010{
037e8744 12011 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12012 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12013 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12014}
12015
12016static void
dcbf9037
JB
12017neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12018 unsigned destbits)
5287ad62 12019{
037e8744 12020 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12021 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12022 types | N_KEY);
5287ad62
JB
12023 if (et.type == NT_float)
12024 {
12025 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12026 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12027 }
12028 else
12029 {
12030 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12031 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12032 }
12033}
12034
12035static void
12036do_neon_dyadic_if_su (void)
12037{
dcbf9037 12038 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12039}
12040
12041static void
12042do_neon_dyadic_if_su_d (void)
12043{
12044 /* This version only allow D registers, but that constraint is enforced during
12045 operand parsing so we don't need to do anything extra here. */
dcbf9037 12046 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12047}
12048
5287ad62
JB
12049static void
12050do_neon_dyadic_if_i_d (void)
12051{
428e3f1f
PB
12052 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12053 affected if we specify unsigned args. */
12054 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12055}
12056
037e8744
JB
12057enum vfp_or_neon_is_neon_bits
12058{
12059 NEON_CHECK_CC = 1,
12060 NEON_CHECK_ARCH = 2
12061};
12062
12063/* Call this function if an instruction which may have belonged to the VFP or
12064 Neon instruction sets, but turned out to be a Neon instruction (due to the
12065 operand types involved, etc.). We have to check and/or fix-up a couple of
12066 things:
12067
12068 - Make sure the user hasn't attempted to make a Neon instruction
12069 conditional.
12070 - Alter the value in the condition code field if necessary.
12071 - Make sure that the arch supports Neon instructions.
12072
12073 Which of these operations take place depends on bits from enum
12074 vfp_or_neon_is_neon_bits.
12075
12076 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12077 current instruction's condition is COND_ALWAYS, the condition field is
12078 changed to inst.uncond_value. This is necessary because instructions shared
12079 between VFP and Neon may be conditional for the VFP variants only, and the
12080 unconditional Neon version must have, e.g., 0xF in the condition field. */
12081
12082static int
12083vfp_or_neon_is_neon (unsigned check)
12084{
12085 /* Conditions are always legal in Thumb mode (IT blocks). */
12086 if (!thumb_mode && (check & NEON_CHECK_CC))
12087 {
12088 if (inst.cond != COND_ALWAYS)
12089 {
12090 first_error (_(BAD_COND));
12091 return FAIL;
12092 }
12093 if (inst.uncond_value != -1)
12094 inst.instruction |= inst.uncond_value << 28;
12095 }
5f4273c7 12096
037e8744
JB
12097 if ((check & NEON_CHECK_ARCH)
12098 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12099 {
12100 first_error (_(BAD_FPU));
12101 return FAIL;
12102 }
5f4273c7 12103
037e8744
JB
12104 return SUCCESS;
12105}
12106
5287ad62
JB
12107static void
12108do_neon_addsub_if_i (void)
12109{
037e8744
JB
12110 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12111 return;
12112
12113 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12114 return;
12115
5287ad62
JB
12116 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12117 affected if we specify unsigned args. */
dcbf9037 12118 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12119}
12120
12121/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12122 result to be:
12123 V<op> A,B (A is operand 0, B is operand 2)
12124 to mean:
12125 V<op> A,B,A
12126 not:
12127 V<op> A,B,B
12128 so handle that case specially. */
12129
12130static void
12131neon_exchange_operands (void)
12132{
12133 void *scratch = alloca (sizeof (inst.operands[0]));
12134 if (inst.operands[1].present)
12135 {
12136 /* Swap operands[1] and operands[2]. */
12137 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12138 inst.operands[1] = inst.operands[2];
12139 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12140 }
12141 else
12142 {
12143 inst.operands[1] = inst.operands[2];
12144 inst.operands[2] = inst.operands[0];
12145 }
12146}
12147
12148static void
12149neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12150{
12151 if (inst.operands[2].isreg)
12152 {
12153 if (invert)
12154 neon_exchange_operands ();
dcbf9037 12155 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12156 }
12157 else
12158 {
037e8744 12159 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12160 struct neon_type_el et = neon_check_type (2, rs,
12161 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12162
12163 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12164 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12165 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12166 inst.instruction |= LOW4 (inst.operands[1].reg);
12167 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12168 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12169 inst.instruction |= (et.type == NT_float) << 10;
12170 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12171
5287ad62
JB
12172 inst.instruction = neon_dp_fixup (inst.instruction);
12173 }
12174}
12175
12176static void
12177do_neon_cmp (void)
12178{
12179 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12180}
12181
12182static void
12183do_neon_cmp_inv (void)
12184{
12185 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12186}
12187
12188static void
12189do_neon_ceq (void)
12190{
12191 neon_compare (N_IF_32, N_IF_32, FALSE);
12192}
12193
12194/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12195 scalars, which are encoded in 5 bits, M : Rm.
12196 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12197 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12198 index in M. */
12199
12200static unsigned
12201neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12202{
dcbf9037
JB
12203 unsigned regno = NEON_SCALAR_REG (scalar);
12204 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12205
12206 switch (elsize)
12207 {
12208 case 16:
12209 if (regno > 7 || elno > 3)
12210 goto bad_scalar;
12211 return regno | (elno << 3);
5f4273c7 12212
5287ad62
JB
12213 case 32:
12214 if (regno > 15 || elno > 1)
12215 goto bad_scalar;
12216 return regno | (elno << 4);
12217
12218 default:
12219 bad_scalar:
dcbf9037 12220 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12221 }
12222
12223 return 0;
12224}
12225
12226/* Encode multiply / multiply-accumulate scalar instructions. */
12227
12228static void
12229neon_mul_mac (struct neon_type_el et, int ubit)
12230{
dcbf9037
JB
12231 unsigned scalar;
12232
12233 /* Give a more helpful error message if we have an invalid type. */
12234 if (et.type == NT_invtype)
12235 return;
5f4273c7 12236
dcbf9037 12237 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12238 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12239 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12240 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12241 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12242 inst.instruction |= LOW4 (scalar);
12243 inst.instruction |= HI1 (scalar) << 5;
12244 inst.instruction |= (et.type == NT_float) << 8;
12245 inst.instruction |= neon_logbits (et.size) << 20;
12246 inst.instruction |= (ubit != 0) << 24;
12247
12248 inst.instruction = neon_dp_fixup (inst.instruction);
12249}
12250
12251static void
12252do_neon_mac_maybe_scalar (void)
12253{
037e8744
JB
12254 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12255 return;
12256
12257 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12258 return;
12259
5287ad62
JB
12260 if (inst.operands[2].isscalar)
12261 {
037e8744 12262 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12263 struct neon_type_el et = neon_check_type (3, rs,
12264 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12265 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12266 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12267 }
12268 else
428e3f1f
PB
12269 {
12270 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12271 affected if we specify unsigned args. */
12272 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12273 }
5287ad62
JB
12274}
12275
12276static void
12277do_neon_tst (void)
12278{
037e8744 12279 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12280 struct neon_type_el et = neon_check_type (3, rs,
12281 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12282 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12283}
12284
12285/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12286 same types as the MAC equivalents. The polynomial type for this instruction
12287 is encoded the same as the integer type. */
12288
12289static void
12290do_neon_mul (void)
12291{
037e8744
JB
12292 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12293 return;
12294
12295 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12296 return;
12297
5287ad62
JB
12298 if (inst.operands[2].isscalar)
12299 do_neon_mac_maybe_scalar ();
12300 else
dcbf9037 12301 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12302}
12303
12304static void
12305do_neon_qdmulh (void)
12306{
12307 if (inst.operands[2].isscalar)
12308 {
037e8744 12309 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12310 struct neon_type_el et = neon_check_type (3, rs,
12311 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12312 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12313 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12314 }
12315 else
12316 {
037e8744 12317 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12318 struct neon_type_el et = neon_check_type (3, rs,
12319 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12320 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12321 /* The U bit (rounding) comes from bit mask. */
037e8744 12322 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12323 }
12324}
12325
12326static void
12327do_neon_fcmp_absolute (void)
12328{
037e8744 12329 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12330 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12331 /* Size field comes from bit mask. */
037e8744 12332 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12333}
12334
12335static void
12336do_neon_fcmp_absolute_inv (void)
12337{
12338 neon_exchange_operands ();
12339 do_neon_fcmp_absolute ();
12340}
12341
12342static void
12343do_neon_step (void)
12344{
037e8744 12345 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12346 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12347 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12348}
12349
12350static void
12351do_neon_abs_neg (void)
12352{
037e8744
JB
12353 enum neon_shape rs;
12354 struct neon_type_el et;
5f4273c7 12355
037e8744
JB
12356 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12357 return;
12358
12359 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12360 return;
12361
12362 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12363 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12364
5287ad62
JB
12365 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12366 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12367 inst.instruction |= LOW4 (inst.operands[1].reg);
12368 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12369 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12370 inst.instruction |= (et.type == NT_float) << 10;
12371 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12372
5287ad62
JB
12373 inst.instruction = neon_dp_fixup (inst.instruction);
12374}
12375
12376static void
12377do_neon_sli (void)
12378{
037e8744 12379 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12380 struct neon_type_el et = neon_check_type (2, rs,
12381 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12382 int imm = inst.operands[2].imm;
12383 constraint (imm < 0 || (unsigned)imm >= et.size,
12384 _("immediate out of range for insert"));
037e8744 12385 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12386}
12387
12388static void
12389do_neon_sri (void)
12390{
037e8744 12391 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12392 struct neon_type_el et = neon_check_type (2, rs,
12393 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12394 int imm = inst.operands[2].imm;
12395 constraint (imm < 1 || (unsigned)imm > et.size,
12396 _("immediate out of range for insert"));
037e8744 12397 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12398}
12399
12400static void
12401do_neon_qshlu_imm (void)
12402{
037e8744 12403 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12404 struct neon_type_el et = neon_check_type (2, rs,
12405 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12406 int imm = inst.operands[2].imm;
12407 constraint (imm < 0 || (unsigned)imm >= et.size,
12408 _("immediate out of range for shift"));
12409 /* Only encodes the 'U present' variant of the instruction.
12410 In this case, signed types have OP (bit 8) set to 0.
12411 Unsigned types have OP set to 1. */
12412 inst.instruction |= (et.type == NT_unsigned) << 8;
12413 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12414 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12415}
12416
12417static void
12418do_neon_qmovn (void)
12419{
12420 struct neon_type_el et = neon_check_type (2, NS_DQ,
12421 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12422 /* Saturating move where operands can be signed or unsigned, and the
12423 destination has the same signedness. */
12424 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12425 if (et.type == NT_unsigned)
12426 inst.instruction |= 0xc0;
12427 else
12428 inst.instruction |= 0x80;
12429 neon_two_same (0, 1, et.size / 2);
12430}
12431
12432static void
12433do_neon_qmovun (void)
12434{
12435 struct neon_type_el et = neon_check_type (2, NS_DQ,
12436 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12437 /* Saturating move with unsigned results. Operands must be signed. */
12438 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12439 neon_two_same (0, 1, et.size / 2);
12440}
12441
12442static void
12443do_neon_rshift_sat_narrow (void)
12444{
12445 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12446 or unsigned. If operands are unsigned, results must also be unsigned. */
12447 struct neon_type_el et = neon_check_type (2, NS_DQI,
12448 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12449 int imm = inst.operands[2].imm;
12450 /* This gets the bounds check, size encoding and immediate bits calculation
12451 right. */
12452 et.size /= 2;
5f4273c7 12453
5287ad62
JB
12454 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12455 VQMOVN.I<size> <Dd>, <Qm>. */
12456 if (imm == 0)
12457 {
12458 inst.operands[2].present = 0;
12459 inst.instruction = N_MNEM_vqmovn;
12460 do_neon_qmovn ();
12461 return;
12462 }
5f4273c7 12463
5287ad62
JB
12464 constraint (imm < 1 || (unsigned)imm > et.size,
12465 _("immediate out of range"));
12466 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12467}
12468
12469static void
12470do_neon_rshift_sat_narrow_u (void)
12471{
12472 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12473 or unsigned. If operands are unsigned, results must also be unsigned. */
12474 struct neon_type_el et = neon_check_type (2, NS_DQI,
12475 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12476 int imm = inst.operands[2].imm;
12477 /* This gets the bounds check, size encoding and immediate bits calculation
12478 right. */
12479 et.size /= 2;
12480
12481 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12482 VQMOVUN.I<size> <Dd>, <Qm>. */
12483 if (imm == 0)
12484 {
12485 inst.operands[2].present = 0;
12486 inst.instruction = N_MNEM_vqmovun;
12487 do_neon_qmovun ();
12488 return;
12489 }
12490
12491 constraint (imm < 1 || (unsigned)imm > et.size,
12492 _("immediate out of range"));
12493 /* FIXME: The manual is kind of unclear about what value U should have in
12494 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12495 must be 1. */
12496 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12497}
12498
12499static void
12500do_neon_movn (void)
12501{
12502 struct neon_type_el et = neon_check_type (2, NS_DQ,
12503 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12504 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12505 neon_two_same (0, 1, et.size / 2);
12506}
12507
12508static void
12509do_neon_rshift_narrow (void)
12510{
12511 struct neon_type_el et = neon_check_type (2, NS_DQI,
12512 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12513 int imm = inst.operands[2].imm;
12514 /* This gets the bounds check, size encoding and immediate bits calculation
12515 right. */
12516 et.size /= 2;
5f4273c7 12517
5287ad62
JB
12518 /* If immediate is zero then we are a pseudo-instruction for
12519 VMOVN.I<size> <Dd>, <Qm> */
12520 if (imm == 0)
12521 {
12522 inst.operands[2].present = 0;
12523 inst.instruction = N_MNEM_vmovn;
12524 do_neon_movn ();
12525 return;
12526 }
5f4273c7 12527
5287ad62
JB
12528 constraint (imm < 1 || (unsigned)imm > et.size,
12529 _("immediate out of range for narrowing operation"));
12530 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12531}
12532
12533static void
12534do_neon_shll (void)
12535{
12536 /* FIXME: Type checking when lengthening. */
12537 struct neon_type_el et = neon_check_type (2, NS_QDI,
12538 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12539 unsigned imm = inst.operands[2].imm;
12540
12541 if (imm == et.size)
12542 {
12543 /* Maximum shift variant. */
12544 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12545 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12546 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12547 inst.instruction |= LOW4 (inst.operands[1].reg);
12548 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12549 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12550
5287ad62
JB
12551 inst.instruction = neon_dp_fixup (inst.instruction);
12552 }
12553 else
12554 {
12555 /* A more-specific type check for non-max versions. */
12556 et = neon_check_type (2, NS_QDI,
12557 N_EQK | N_DBL, N_SU_32 | N_KEY);
12558 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12559 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12560 }
12561}
12562
037e8744 12563/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12564 the current instruction is. */
12565
12566static int
12567neon_cvt_flavour (enum neon_shape rs)
12568{
037e8744
JB
12569#define CVT_VAR(C,X,Y) \
12570 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12571 if (et.type != NT_invtype) \
12572 { \
12573 inst.error = NULL; \
12574 return (C); \
5287ad62
JB
12575 }
12576 struct neon_type_el et;
037e8744
JB
12577 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12578 || rs == NS_FF) ? N_VFP : 0;
12579 /* The instruction versions which take an immediate take one register
12580 argument, which is extended to the width of the full register. Thus the
12581 "source" and "destination" registers must have the same width. Hack that
12582 here by making the size equal to the key (wider, in this case) operand. */
12583 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 12584
5287ad62
JB
12585 CVT_VAR (0, N_S32, N_F32);
12586 CVT_VAR (1, N_U32, N_F32);
12587 CVT_VAR (2, N_F32, N_S32);
12588 CVT_VAR (3, N_F32, N_U32);
5f4273c7 12589
037e8744 12590 whole_reg = N_VFP;
5f4273c7 12591
037e8744
JB
12592 /* VFP instructions. */
12593 CVT_VAR (4, N_F32, N_F64);
12594 CVT_VAR (5, N_F64, N_F32);
12595 CVT_VAR (6, N_S32, N_F64 | key);
12596 CVT_VAR (7, N_U32, N_F64 | key);
12597 CVT_VAR (8, N_F64 | key, N_S32);
12598 CVT_VAR (9, N_F64 | key, N_U32);
12599 /* VFP instructions with bitshift. */
12600 CVT_VAR (10, N_F32 | key, N_S16);
12601 CVT_VAR (11, N_F32 | key, N_U16);
12602 CVT_VAR (12, N_F64 | key, N_S16);
12603 CVT_VAR (13, N_F64 | key, N_U16);
12604 CVT_VAR (14, N_S16, N_F32 | key);
12605 CVT_VAR (15, N_U16, N_F32 | key);
12606 CVT_VAR (16, N_S16, N_F64 | key);
12607 CVT_VAR (17, N_U16, N_F64 | key);
5f4273c7 12608
5287ad62
JB
12609 return -1;
12610#undef CVT_VAR
12611}
12612
037e8744
JB
12613/* Neon-syntax VFP conversions. */
12614
5287ad62 12615static void
037e8744 12616do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12617{
037e8744 12618 const char *opname = 0;
5f4273c7 12619
037e8744 12620 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12621 {
037e8744
JB
12622 /* Conversions with immediate bitshift. */
12623 const char *enc[] =
12624 {
12625 "ftosls",
12626 "ftouls",
12627 "fsltos",
12628 "fultos",
12629 NULL,
12630 NULL,
12631 "ftosld",
12632 "ftould",
12633 "fsltod",
12634 "fultod",
12635 "fshtos",
12636 "fuhtos",
12637 "fshtod",
12638 "fuhtod",
12639 "ftoshs",
12640 "ftouhs",
12641 "ftoshd",
12642 "ftouhd"
12643 };
12644
12645 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12646 {
12647 opname = enc[flavour];
12648 constraint (inst.operands[0].reg != inst.operands[1].reg,
12649 _("operands 0 and 1 must be the same register"));
12650 inst.operands[1] = inst.operands[2];
12651 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12652 }
5287ad62
JB
12653 }
12654 else
12655 {
037e8744
JB
12656 /* Conversions without bitshift. */
12657 const char *enc[] =
12658 {
12659 "ftosis",
12660 "ftouis",
12661 "fsitos",
12662 "fuitos",
12663 "fcvtsd",
12664 "fcvtds",
12665 "ftosid",
12666 "ftouid",
12667 "fsitod",
12668 "fuitod"
12669 };
12670
12671 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12672 opname = enc[flavour];
12673 }
12674
12675 if (opname)
12676 do_vfp_nsyn_opcode (opname);
12677}
12678
12679static void
12680do_vfp_nsyn_cvtz (void)
12681{
12682 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12683 int flavour = neon_cvt_flavour (rs);
12684 const char *enc[] =
12685 {
12686 "ftosizs",
12687 "ftouizs",
12688 NULL,
12689 NULL,
12690 NULL,
12691 NULL,
12692 "ftosizd",
12693 "ftouizd"
12694 };
12695
12696 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12697 do_vfp_nsyn_opcode (enc[flavour]);
12698}
12699
12700static void
12701do_neon_cvt (void)
12702{
12703 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12704 NS_FD, NS_DF, NS_FF, NS_NULL);
12705 int flavour = neon_cvt_flavour (rs);
12706
12707 /* VFP rather than Neon conversions. */
12708 if (flavour >= 4)
12709 {
12710 do_vfp_nsyn_cvt (rs, flavour);
12711 return;
12712 }
12713
12714 switch (rs)
12715 {
12716 case NS_DDI:
12717 case NS_QQI:
12718 {
12719 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12720 return;
12721
12722 /* Fixed-point conversion with #0 immediate is encoded as an
12723 integer conversion. */
12724 if (inst.operands[2].present && inst.operands[2].imm == 0)
12725 goto int_encode;
12726 unsigned immbits = 32 - inst.operands[2].imm;
12727 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12728 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12729 if (flavour != -1)
12730 inst.instruction |= enctab[flavour];
12731 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12732 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12733 inst.instruction |= LOW4 (inst.operands[1].reg);
12734 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12735 inst.instruction |= neon_quad (rs) << 6;
12736 inst.instruction |= 1 << 21;
12737 inst.instruction |= immbits << 16;
12738
12739 inst.instruction = neon_dp_fixup (inst.instruction);
12740 }
12741 break;
12742
12743 case NS_DD:
12744 case NS_QQ:
12745 int_encode:
12746 {
12747 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12748
12749 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12750
12751 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12752 return;
12753
12754 if (flavour != -1)
12755 inst.instruction |= enctab[flavour];
12756
12757 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12758 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12759 inst.instruction |= LOW4 (inst.operands[1].reg);
12760 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12761 inst.instruction |= neon_quad (rs) << 6;
12762 inst.instruction |= 2 << 18;
12763
12764 inst.instruction = neon_dp_fixup (inst.instruction);
12765 }
12766 break;
12767
12768 default:
12769 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12770 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12771 }
5287ad62
JB
12772}
12773
12774static void
12775neon_move_immediate (void)
12776{
037e8744
JB
12777 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12778 struct neon_type_el et = neon_check_type (2, rs,
12779 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12780 unsigned immlo, immhi = 0, immbits;
c96612cc 12781 int op, cmode, float_p;
5287ad62 12782
037e8744
JB
12783 constraint (et.type == NT_invtype,
12784 _("operand size must be specified for immediate VMOV"));
12785
5287ad62
JB
12786 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12787 op = (inst.instruction & (1 << 5)) != 0;
12788
12789 immlo = inst.operands[1].imm;
12790 if (inst.operands[1].regisimm)
12791 immhi = inst.operands[1].reg;
12792
12793 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12794 _("immediate has bits set outside the operand size"));
12795
c96612cc
JB
12796 float_p = inst.operands[1].immisfloat;
12797
12798 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12799 et.size, et.type)) == FAIL)
5287ad62
JB
12800 {
12801 /* Invert relevant bits only. */
12802 neon_invert_size (&immlo, &immhi, et.size);
12803 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12804 with one or the other; those cases are caught by
12805 neon_cmode_for_move_imm. */
12806 op = !op;
c96612cc
JB
12807 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12808 &op, et.size, et.type)) == FAIL)
5287ad62 12809 {
dcbf9037 12810 first_error (_("immediate out of range"));
5287ad62
JB
12811 return;
12812 }
12813 }
12814
12815 inst.instruction &= ~(1 << 5);
12816 inst.instruction |= op << 5;
12817
12818 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12819 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12820 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12821 inst.instruction |= cmode << 8;
12822
12823 neon_write_immbits (immbits);
12824}
12825
12826static void
12827do_neon_mvn (void)
12828{
12829 if (inst.operands[1].isreg)
12830 {
037e8744 12831 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 12832
5287ad62
JB
12833 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12834 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12835 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12836 inst.instruction |= LOW4 (inst.operands[1].reg);
12837 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12838 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12839 }
12840 else
12841 {
12842 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12843 neon_move_immediate ();
12844 }
12845
12846 inst.instruction = neon_dp_fixup (inst.instruction);
12847}
12848
12849/* Encode instructions of form:
12850
12851 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 12852 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
12853
12854static void
12855neon_mixed_length (struct neon_type_el et, unsigned size)
12856{
12857 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12858 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12859 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12860 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12861 inst.instruction |= LOW4 (inst.operands[2].reg);
12862 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12863 inst.instruction |= (et.type == NT_unsigned) << 24;
12864 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12865
5287ad62
JB
12866 inst.instruction = neon_dp_fixup (inst.instruction);
12867}
12868
12869static void
12870do_neon_dyadic_long (void)
12871{
12872 /* FIXME: Type checking for lengthening op. */
12873 struct neon_type_el et = neon_check_type (3, NS_QDD,
12874 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12875 neon_mixed_length (et, et.size);
12876}
12877
12878static void
12879do_neon_abal (void)
12880{
12881 struct neon_type_el et = neon_check_type (3, NS_QDD,
12882 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12883 neon_mixed_length (et, et.size);
12884}
12885
12886static void
12887neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12888{
12889 if (inst.operands[2].isscalar)
12890 {
dcbf9037
JB
12891 struct neon_type_el et = neon_check_type (3, NS_QDS,
12892 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12893 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12894 neon_mul_mac (et, et.type == NT_unsigned);
12895 }
12896 else
12897 {
12898 struct neon_type_el et = neon_check_type (3, NS_QDD,
12899 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12900 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12901 neon_mixed_length (et, et.size);
12902 }
12903}
12904
12905static void
12906do_neon_mac_maybe_scalar_long (void)
12907{
12908 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12909}
12910
12911static void
12912do_neon_dyadic_wide (void)
12913{
12914 struct neon_type_el et = neon_check_type (3, NS_QQD,
12915 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12916 neon_mixed_length (et, et.size);
12917}
12918
12919static void
12920do_neon_dyadic_narrow (void)
12921{
12922 struct neon_type_el et = neon_check_type (3, NS_QDD,
12923 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12924 /* Operand sign is unimportant, and the U bit is part of the opcode,
12925 so force the operand type to integer. */
12926 et.type = NT_integer;
5287ad62
JB
12927 neon_mixed_length (et, et.size / 2);
12928}
12929
12930static void
12931do_neon_mul_sat_scalar_long (void)
12932{
12933 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12934}
12935
12936static void
12937do_neon_vmull (void)
12938{
12939 if (inst.operands[2].isscalar)
12940 do_neon_mac_maybe_scalar_long ();
12941 else
12942 {
12943 struct neon_type_el et = neon_check_type (3, NS_QDD,
12944 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12945 if (et.type == NT_poly)
12946 inst.instruction = NEON_ENC_POLY (inst.instruction);
12947 else
12948 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12949 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12950 zero. Should be OK as-is. */
12951 neon_mixed_length (et, et.size);
12952 }
12953}
12954
12955static void
12956do_neon_ext (void)
12957{
037e8744 12958 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12959 struct neon_type_el et = neon_check_type (3, rs,
12960 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12961 unsigned imm = (inst.operands[3].imm * et.size) / 8;
3b8d421e 12962 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
5287ad62
JB
12963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12965 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12966 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12967 inst.instruction |= LOW4 (inst.operands[2].reg);
12968 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12969 inst.instruction |= neon_quad (rs) << 6;
5287ad62 12970 inst.instruction |= imm << 8;
5f4273c7 12971
5287ad62
JB
12972 inst.instruction = neon_dp_fixup (inst.instruction);
12973}
12974
12975static void
12976do_neon_rev (void)
12977{
037e8744 12978 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12979 struct neon_type_el et = neon_check_type (2, rs,
12980 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12981 unsigned op = (inst.instruction >> 7) & 3;
12982 /* N (width of reversed regions) is encoded as part of the bitmask. We
12983 extract it here to check the elements to be reversed are smaller.
12984 Otherwise we'd get a reserved instruction. */
12985 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12986 assert (elsize != 0);
12987 constraint (et.size >= elsize,
12988 _("elements must be smaller than reversal region"));
037e8744 12989 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12990}
12991
12992static void
12993do_neon_dup (void)
12994{
12995 if (inst.operands[1].isscalar)
12996 {
037e8744 12997 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
12998 struct neon_type_el et = neon_check_type (2, rs,
12999 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13000 unsigned sizebits = et.size >> 3;
dcbf9037 13001 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13002 int logsize = neon_logbits (et.size);
dcbf9037 13003 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13004
13005 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13006 return;
13007
5287ad62
JB
13008 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13009 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13010 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13011 inst.instruction |= LOW4 (dm);
13012 inst.instruction |= HI1 (dm) << 5;
037e8744 13013 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13014 inst.instruction |= x << 17;
13015 inst.instruction |= sizebits << 16;
5f4273c7 13016
5287ad62
JB
13017 inst.instruction = neon_dp_fixup (inst.instruction);
13018 }
13019 else
13020 {
037e8744
JB
13021 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13022 struct neon_type_el et = neon_check_type (2, rs,
13023 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13024 /* Duplicate ARM register to lanes of vector. */
13025 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13026 switch (et.size)
13027 {
13028 case 8: inst.instruction |= 0x400000; break;
13029 case 16: inst.instruction |= 0x000020; break;
13030 case 32: inst.instruction |= 0x000000; break;
13031 default: break;
13032 }
13033 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13034 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13035 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13036 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13037 /* The encoding for this instruction is identical for the ARM and Thumb
13038 variants, except for the condition field. */
037e8744 13039 do_vfp_cond_or_thumb ();
5287ad62
JB
13040 }
13041}
13042
13043/* VMOV has particularly many variations. It can be one of:
13044 0. VMOV<c><q> <Qd>, <Qm>
13045 1. VMOV<c><q> <Dd>, <Dm>
13046 (Register operations, which are VORR with Rm = Rn.)
13047 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13048 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13049 (Immediate loads.)
13050 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13051 (ARM register to scalar.)
13052 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13053 (Two ARM registers to vector.)
13054 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13055 (Scalar to ARM register.)
13056 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13057 (Vector to two ARM registers.)
037e8744
JB
13058 8. VMOV.F32 <Sd>, <Sm>
13059 9. VMOV.F64 <Dd>, <Dm>
13060 (VFP register moves.)
13061 10. VMOV.F32 <Sd>, #imm
13062 11. VMOV.F64 <Dd>, #imm
13063 (VFP float immediate load.)
13064 12. VMOV <Rd>, <Sm>
13065 (VFP single to ARM reg.)
13066 13. VMOV <Sd>, <Rm>
13067 (ARM reg to VFP single.)
13068 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13069 (Two ARM regs to two VFP singles.)
13070 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13071 (Two VFP singles to two ARM regs.)
5f4273c7 13072
037e8744
JB
13073 These cases can be disambiguated using neon_select_shape, except cases 1/9
13074 and 3/11 which depend on the operand type too.
5f4273c7 13075
5287ad62 13076 All the encoded bits are hardcoded by this function.
5f4273c7 13077
b7fc2769
JB
13078 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13079 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13080
5287ad62 13081 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13082 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13083
13084static void
13085do_neon_mov (void)
13086{
037e8744
JB
13087 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13088 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13089 NS_NULL);
13090 struct neon_type_el et;
13091 const char *ldconst = 0;
5287ad62 13092
037e8744 13093 switch (rs)
5287ad62 13094 {
037e8744
JB
13095 case NS_DD: /* case 1/9. */
13096 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13097 /* It is not an error here if no type is given. */
13098 inst.error = NULL;
13099 if (et.type == NT_float && et.size == 64)
5287ad62 13100 {
037e8744
JB
13101 do_vfp_nsyn_opcode ("fcpyd");
13102 break;
5287ad62 13103 }
037e8744 13104 /* fall through. */
5287ad62 13105
037e8744
JB
13106 case NS_QQ: /* case 0/1. */
13107 {
13108 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13109 return;
13110 /* The architecture manual I have doesn't explicitly state which
13111 value the U bit should have for register->register moves, but
13112 the equivalent VORR instruction has U = 0, so do that. */
13113 inst.instruction = 0x0200110;
13114 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13115 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13116 inst.instruction |= LOW4 (inst.operands[1].reg);
13117 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13118 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13119 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13120 inst.instruction |= neon_quad (rs) << 6;
13121
13122 inst.instruction = neon_dp_fixup (inst.instruction);
13123 }
13124 break;
5f4273c7 13125
037e8744
JB
13126 case NS_DI: /* case 3/11. */
13127 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13128 inst.error = NULL;
13129 if (et.type == NT_float && et.size == 64)
5287ad62 13130 {
037e8744
JB
13131 /* case 11 (fconstd). */
13132 ldconst = "fconstd";
13133 goto encode_fconstd;
5287ad62 13134 }
037e8744
JB
13135 /* fall through. */
13136
13137 case NS_QI: /* case 2/3. */
13138 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13139 return;
13140 inst.instruction = 0x0800010;
13141 neon_move_immediate ();
13142 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13143 break;
5f4273c7 13144
037e8744
JB
13145 case NS_SR: /* case 4. */
13146 {
13147 unsigned bcdebits = 0;
13148 struct neon_type_el et = neon_check_type (2, NS_NULL,
13149 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13150 int logsize = neon_logbits (et.size);
13151 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13152 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13153
13154 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13155 _(BAD_FPU));
13156 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13157 && et.size != 32, _(BAD_FPU));
13158 constraint (et.type == NT_invtype, _("bad type for scalar"));
13159 constraint (x >= 64 / et.size, _("scalar index out of range"));
13160
13161 switch (et.size)
13162 {
13163 case 8: bcdebits = 0x8; break;
13164 case 16: bcdebits = 0x1; break;
13165 case 32: bcdebits = 0x0; break;
13166 default: ;
13167 }
13168
13169 bcdebits |= x << logsize;
13170
13171 inst.instruction = 0xe000b10;
13172 do_vfp_cond_or_thumb ();
13173 inst.instruction |= LOW4 (dn) << 16;
13174 inst.instruction |= HI1 (dn) << 7;
13175 inst.instruction |= inst.operands[1].reg << 12;
13176 inst.instruction |= (bcdebits & 3) << 5;
13177 inst.instruction |= (bcdebits >> 2) << 21;
13178 }
13179 break;
5f4273c7 13180
037e8744 13181 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13183 _(BAD_FPU));
b7fc2769 13184
037e8744
JB
13185 inst.instruction = 0xc400b10;
13186 do_vfp_cond_or_thumb ();
13187 inst.instruction |= LOW4 (inst.operands[0].reg);
13188 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13189 inst.instruction |= inst.operands[1].reg << 12;
13190 inst.instruction |= inst.operands[2].reg << 16;
13191 break;
5f4273c7 13192
037e8744
JB
13193 case NS_RS: /* case 6. */
13194 {
13195 struct neon_type_el et = neon_check_type (2, NS_NULL,
13196 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13197 unsigned logsize = neon_logbits (et.size);
13198 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13199 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13200 unsigned abcdebits = 0;
13201
13202 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13203 _(BAD_FPU));
13204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13205 && et.size != 32, _(BAD_FPU));
13206 constraint (et.type == NT_invtype, _("bad type for scalar"));
13207 constraint (x >= 64 / et.size, _("scalar index out of range"));
13208
13209 switch (et.size)
13210 {
13211 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13212 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13213 case 32: abcdebits = 0x00; break;
13214 default: ;
13215 }
13216
13217 abcdebits |= x << logsize;
13218 inst.instruction = 0xe100b10;
13219 do_vfp_cond_or_thumb ();
13220 inst.instruction |= LOW4 (dn) << 16;
13221 inst.instruction |= HI1 (dn) << 7;
13222 inst.instruction |= inst.operands[0].reg << 12;
13223 inst.instruction |= (abcdebits & 3) << 5;
13224 inst.instruction |= (abcdebits >> 2) << 21;
13225 }
13226 break;
5f4273c7 13227
037e8744
JB
13228 case NS_RRD: /* case 7 (fmrrd). */
13229 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13230 _(BAD_FPU));
13231
13232 inst.instruction = 0xc500b10;
13233 do_vfp_cond_or_thumb ();
13234 inst.instruction |= inst.operands[0].reg << 12;
13235 inst.instruction |= inst.operands[1].reg << 16;
13236 inst.instruction |= LOW4 (inst.operands[2].reg);
13237 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13238 break;
5f4273c7 13239
037e8744
JB
13240 case NS_FF: /* case 8 (fcpys). */
13241 do_vfp_nsyn_opcode ("fcpys");
13242 break;
5f4273c7 13243
037e8744
JB
13244 case NS_FI: /* case 10 (fconsts). */
13245 ldconst = "fconsts";
13246 encode_fconstd:
13247 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13248 {
037e8744
JB
13249 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13250 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13251 }
13252 else
037e8744
JB
13253 first_error (_("immediate out of range"));
13254 break;
5f4273c7 13255
037e8744
JB
13256 case NS_RF: /* case 12 (fmrs). */
13257 do_vfp_nsyn_opcode ("fmrs");
13258 break;
5f4273c7 13259
037e8744
JB
13260 case NS_FR: /* case 13 (fmsr). */
13261 do_vfp_nsyn_opcode ("fmsr");
13262 break;
5f4273c7 13263
037e8744
JB
13264 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13265 (one of which is a list), but we have parsed four. Do some fiddling to
13266 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13267 expect. */
13268 case NS_RRFF: /* case 14 (fmrrs). */
13269 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13270 _("VFP registers must be adjacent"));
13271 inst.operands[2].imm = 2;
13272 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13273 do_vfp_nsyn_opcode ("fmrrs");
13274 break;
5f4273c7 13275
037e8744
JB
13276 case NS_FFRR: /* case 15 (fmsrr). */
13277 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13278 _("VFP registers must be adjacent"));
13279 inst.operands[1] = inst.operands[2];
13280 inst.operands[2] = inst.operands[3];
13281 inst.operands[0].imm = 2;
13282 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13283 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13284 break;
5f4273c7 13285
5287ad62
JB
13286 default:
13287 abort ();
13288 }
13289}
13290
13291static void
13292do_neon_rshift_round_imm (void)
13293{
037e8744 13294 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13295 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13296 int imm = inst.operands[2].imm;
13297
13298 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13299 if (imm == 0)
13300 {
13301 inst.operands[2].present = 0;
13302 do_neon_mov ();
13303 return;
13304 }
13305
13306 constraint (imm < 1 || (unsigned)imm > et.size,
13307 _("immediate out of range for shift"));
037e8744 13308 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13309 et.size - imm);
13310}
13311
13312static void
13313do_neon_movl (void)
13314{
13315 struct neon_type_el et = neon_check_type (2, NS_QD,
13316 N_EQK | N_DBL, N_SU_32 | N_KEY);
13317 unsigned sizebits = et.size >> 3;
13318 inst.instruction |= sizebits << 19;
13319 neon_two_same (0, et.type == NT_unsigned, -1);
13320}
13321
13322static void
13323do_neon_trn (void)
13324{
037e8744 13325 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13326 struct neon_type_el et = neon_check_type (2, rs,
13327 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13328 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13329 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13330}
13331
13332static void
13333do_neon_zip_uzp (void)
13334{
037e8744 13335 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13336 struct neon_type_el et = neon_check_type (2, rs,
13337 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13338 if (rs == NS_DD && et.size == 32)
13339 {
13340 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13341 inst.instruction = N_MNEM_vtrn;
13342 do_neon_trn ();
13343 return;
13344 }
037e8744 13345 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13346}
13347
13348static void
13349do_neon_sat_abs_neg (void)
13350{
037e8744 13351 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13352 struct neon_type_el et = neon_check_type (2, rs,
13353 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13354 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13355}
13356
13357static void
13358do_neon_pair_long (void)
13359{
037e8744 13360 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13361 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13362 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13363 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13364 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13365}
13366
13367static void
13368do_neon_recip_est (void)
13369{
037e8744 13370 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13371 struct neon_type_el et = neon_check_type (2, rs,
13372 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13373 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13374 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13375}
13376
13377static void
13378do_neon_cls (void)
13379{
037e8744 13380 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13381 struct neon_type_el et = neon_check_type (2, rs,
13382 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13383 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13384}
13385
13386static void
13387do_neon_clz (void)
13388{
037e8744 13389 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13390 struct neon_type_el et = neon_check_type (2, rs,
13391 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13392 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13393}
13394
13395static void
13396do_neon_cnt (void)
13397{
037e8744 13398 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13399 struct neon_type_el et = neon_check_type (2, rs,
13400 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13401 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13402}
13403
13404static void
13405do_neon_swp (void)
13406{
037e8744
JB
13407 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13408 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13409}
13410
13411static void
13412do_neon_tbl_tbx (void)
13413{
13414 unsigned listlenbits;
dcbf9037 13415 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13416
5287ad62
JB
13417 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13418 {
dcbf9037 13419 first_error (_("bad list length for table lookup"));
5287ad62
JB
13420 return;
13421 }
5f4273c7 13422
5287ad62
JB
13423 listlenbits = inst.operands[1].imm - 1;
13424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13426 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13427 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13428 inst.instruction |= LOW4 (inst.operands[2].reg);
13429 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13430 inst.instruction |= listlenbits << 8;
5f4273c7 13431
5287ad62
JB
13432 inst.instruction = neon_dp_fixup (inst.instruction);
13433}
13434
13435static void
13436do_neon_ldm_stm (void)
13437{
13438 /* P, U and L bits are part of bitmask. */
13439 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13440 unsigned offsetbits = inst.operands[1].imm * 2;
13441
037e8744
JB
13442 if (inst.operands[1].issingle)
13443 {
13444 do_vfp_nsyn_ldm_stm (is_dbmode);
13445 return;
13446 }
13447
5287ad62
JB
13448 constraint (is_dbmode && !inst.operands[0].writeback,
13449 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13450
13451 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13452 _("register list must contain at least 1 and at most 16 "
13453 "registers"));
13454
13455 inst.instruction |= inst.operands[0].reg << 16;
13456 inst.instruction |= inst.operands[0].writeback << 21;
13457 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13458 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13459
13460 inst.instruction |= offsetbits;
5f4273c7 13461
037e8744 13462 do_vfp_cond_or_thumb ();
5287ad62
JB
13463}
13464
13465static void
13466do_neon_ldr_str (void)
13467{
5287ad62 13468 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13469
037e8744
JB
13470 if (inst.operands[0].issingle)
13471 {
cd2f129f
JB
13472 if (is_ldr)
13473 do_vfp_nsyn_opcode ("flds");
13474 else
13475 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13476 }
13477 else
5287ad62 13478 {
cd2f129f
JB
13479 if (is_ldr)
13480 do_vfp_nsyn_opcode ("fldd");
5287ad62 13481 else
cd2f129f 13482 do_vfp_nsyn_opcode ("fstd");
5287ad62 13483 }
5287ad62
JB
13484}
13485
13486/* "interleave" version also handles non-interleaving register VLD1/VST1
13487 instructions. */
13488
13489static void
13490do_neon_ld_st_interleave (void)
13491{
037e8744 13492 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13493 N_8 | N_16 | N_32 | N_64);
13494 unsigned alignbits = 0;
13495 unsigned idx;
13496 /* The bits in this table go:
13497 0: register stride of one (0) or two (1)
13498 1,2: register list length, minus one (1, 2, 3, 4).
13499 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13500 We use -1 for invalid entries. */
13501 const int typetable[] =
13502 {
13503 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13504 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13505 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13506 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13507 };
13508 int typebits;
13509
dcbf9037
JB
13510 if (et.type == NT_invtype)
13511 return;
13512
5287ad62
JB
13513 if (inst.operands[1].immisalign)
13514 switch (inst.operands[1].imm >> 8)
13515 {
13516 case 64: alignbits = 1; break;
13517 case 128:
13518 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13519 goto bad_alignment;
13520 alignbits = 2;
13521 break;
13522 case 256:
13523 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13524 goto bad_alignment;
13525 alignbits = 3;
13526 break;
13527 default:
13528 bad_alignment:
dcbf9037 13529 first_error (_("bad alignment"));
5287ad62
JB
13530 return;
13531 }
13532
13533 inst.instruction |= alignbits << 4;
13534 inst.instruction |= neon_logbits (et.size) << 6;
13535
13536 /* Bits [4:6] of the immediate in a list specifier encode register stride
13537 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13538 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13539 up the right value for "type" in a table based on this value and the given
13540 list style, then stick it back. */
13541 idx = ((inst.operands[0].imm >> 4) & 7)
13542 | (((inst.instruction >> 8) & 3) << 3);
13543
13544 typebits = typetable[idx];
5f4273c7 13545
5287ad62
JB
13546 constraint (typebits == -1, _("bad list type for instruction"));
13547
13548 inst.instruction &= ~0xf00;
13549 inst.instruction |= typebits << 8;
13550}
13551
13552/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13553 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13554 otherwise. The variable arguments are a list of pairs of legal (size, align)
13555 values, terminated with -1. */
13556
13557static int
13558neon_alignment_bit (int size, int align, int *do_align, ...)
13559{
13560 va_list ap;
13561 int result = FAIL, thissize, thisalign;
5f4273c7 13562
5287ad62
JB
13563 if (!inst.operands[1].immisalign)
13564 {
13565 *do_align = 0;
13566 return SUCCESS;
13567 }
5f4273c7 13568
5287ad62
JB
13569 va_start (ap, do_align);
13570
13571 do
13572 {
13573 thissize = va_arg (ap, int);
13574 if (thissize == -1)
13575 break;
13576 thisalign = va_arg (ap, int);
13577
13578 if (size == thissize && align == thisalign)
13579 result = SUCCESS;
13580 }
13581 while (result != SUCCESS);
13582
13583 va_end (ap);
13584
13585 if (result == SUCCESS)
13586 *do_align = 1;
13587 else
dcbf9037 13588 first_error (_("unsupported alignment for instruction"));
5f4273c7 13589
5287ad62
JB
13590 return result;
13591}
13592
13593static void
13594do_neon_ld_st_lane (void)
13595{
037e8744 13596 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13597 int align_good, do_align = 0;
13598 int logsize = neon_logbits (et.size);
13599 int align = inst.operands[1].imm >> 8;
13600 int n = (inst.instruction >> 8) & 3;
13601 int max_el = 64 / et.size;
5f4273c7 13602
dcbf9037
JB
13603 if (et.type == NT_invtype)
13604 return;
5f4273c7 13605
5287ad62
JB
13606 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13607 _("bad list length"));
13608 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13609 _("scalar index out of range"));
13610 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13611 && et.size == 8,
13612 _("stride of 2 unavailable when element size is 8"));
5f4273c7 13613
5287ad62
JB
13614 switch (n)
13615 {
13616 case 0: /* VLD1 / VST1. */
13617 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13618 32, 32, -1);
13619 if (align_good == FAIL)
13620 return;
13621 if (do_align)
13622 {
13623 unsigned alignbits = 0;
13624 switch (et.size)
13625 {
13626 case 16: alignbits = 0x1; break;
13627 case 32: alignbits = 0x3; break;
13628 default: ;
13629 }
13630 inst.instruction |= alignbits << 4;
13631 }
13632 break;
13633
13634 case 1: /* VLD2 / VST2. */
13635 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13636 32, 64, -1);
13637 if (align_good == FAIL)
13638 return;
13639 if (do_align)
13640 inst.instruction |= 1 << 4;
13641 break;
13642
13643 case 2: /* VLD3 / VST3. */
13644 constraint (inst.operands[1].immisalign,
13645 _("can't use alignment with this instruction"));
13646 break;
13647
13648 case 3: /* VLD4 / VST4. */
13649 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13650 16, 64, 32, 64, 32, 128, -1);
13651 if (align_good == FAIL)
13652 return;
13653 if (do_align)
13654 {
13655 unsigned alignbits = 0;
13656 switch (et.size)
13657 {
13658 case 8: alignbits = 0x1; break;
13659 case 16: alignbits = 0x1; break;
13660 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13661 default: ;
13662 }
13663 inst.instruction |= alignbits << 4;
13664 }
13665 break;
13666
13667 default: ;
13668 }
13669
13670 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13671 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13672 inst.instruction |= 1 << (4 + logsize);
5f4273c7 13673
5287ad62
JB
13674 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13675 inst.instruction |= logsize << 10;
13676}
13677
13678/* Encode single n-element structure to all lanes VLD<n> instructions. */
13679
13680static void
13681do_neon_ld_dup (void)
13682{
037e8744 13683 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13684 int align_good, do_align = 0;
13685
dcbf9037
JB
13686 if (et.type == NT_invtype)
13687 return;
13688
5287ad62
JB
13689 switch ((inst.instruction >> 8) & 3)
13690 {
13691 case 0: /* VLD1. */
13692 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13693 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13694 &do_align, 16, 16, 32, 32, -1);
13695 if (align_good == FAIL)
13696 return;
13697 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13698 {
13699 case 1: break;
13700 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13701 default: first_error (_("bad list length")); return;
5287ad62
JB
13702 }
13703 inst.instruction |= neon_logbits (et.size) << 6;
13704 break;
13705
13706 case 1: /* VLD2. */
13707 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13708 &do_align, 8, 16, 16, 32, 32, 64, -1);
13709 if (align_good == FAIL)
13710 return;
13711 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13712 _("bad list length"));
13713 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13714 inst.instruction |= 1 << 5;
13715 inst.instruction |= neon_logbits (et.size) << 6;
13716 break;
13717
13718 case 2: /* VLD3. */
13719 constraint (inst.operands[1].immisalign,
13720 _("can't use alignment with this instruction"));
13721 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13722 _("bad list length"));
13723 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13724 inst.instruction |= 1 << 5;
13725 inst.instruction |= neon_logbits (et.size) << 6;
13726 break;
13727
13728 case 3: /* VLD4. */
13729 {
13730 int align = inst.operands[1].imm >> 8;
13731 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13732 16, 64, 32, 64, 32, 128, -1);
13733 if (align_good == FAIL)
13734 return;
13735 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13736 _("bad list length"));
13737 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13738 inst.instruction |= 1 << 5;
13739 if (et.size == 32 && align == 128)
13740 inst.instruction |= 0x3 << 6;
13741 else
13742 inst.instruction |= neon_logbits (et.size) << 6;
13743 }
13744 break;
13745
13746 default: ;
13747 }
13748
13749 inst.instruction |= do_align << 4;
13750}
13751
13752/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13753 apart from bits [11:4]. */
13754
13755static void
13756do_neon_ldx_stx (void)
13757{
13758 switch (NEON_LANE (inst.operands[0].imm))
13759 {
13760 case NEON_INTERLEAVE_LANES:
13761 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13762 do_neon_ld_st_interleave ();
13763 break;
5f4273c7 13764
5287ad62
JB
13765 case NEON_ALL_LANES:
13766 inst.instruction = NEON_ENC_DUP (inst.instruction);
13767 do_neon_ld_dup ();
13768 break;
5f4273c7 13769
5287ad62
JB
13770 default:
13771 inst.instruction = NEON_ENC_LANE (inst.instruction);
13772 do_neon_ld_st_lane ();
13773 }
13774
13775 /* L bit comes from bit mask. */
13776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13778 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 13779
5287ad62
JB
13780 if (inst.operands[1].postind)
13781 {
13782 int postreg = inst.operands[1].imm & 0xf;
13783 constraint (!inst.operands[1].immisreg,
13784 _("post-index must be a register"));
13785 constraint (postreg == 0xd || postreg == 0xf,
13786 _("bad register for post-index"));
13787 inst.instruction |= postreg;
13788 }
13789 else if (inst.operands[1].writeback)
13790 {
13791 inst.instruction |= 0xd;
13792 }
13793 else
5f4273c7
NC
13794 inst.instruction |= 0xf;
13795
5287ad62
JB
13796 if (thumb_mode)
13797 inst.instruction |= 0xf9000000;
13798 else
13799 inst.instruction |= 0xf4000000;
13800}
5287ad62
JB
13801\f
13802/* Overall per-instruction processing. */
13803
13804/* We need to be able to fix up arbitrary expressions in some statements.
13805 This is so that we can handle symbols that are an arbitrary distance from
13806 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13807 which returns part of an address in a form which will be valid for
13808 a data instruction. We do this by pushing the expression into a symbol
13809 in the expr_section, and creating a fix for that. */
13810
13811static void
13812fix_new_arm (fragS * frag,
13813 int where,
13814 short int size,
13815 expressionS * exp,
13816 int pc_rel,
13817 int reloc)
13818{
13819 fixS * new_fix;
13820
13821 switch (exp->X_op)
13822 {
13823 case O_constant:
13824 case O_symbol:
13825 case O_add:
13826 case O_subtract:
13827 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13828 break;
13829
13830 default:
13831 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13832 pc_rel, reloc);
13833 break;
13834 }
13835
13836 /* Mark whether the fix is to a THUMB instruction, or an ARM
13837 instruction. */
13838 new_fix->tc_fix_data = thumb_mode;
13839}
13840
13841/* Create a frg for an instruction requiring relaxation. */
13842static void
13843output_relax_insn (void)
13844{
13845 char * to;
13846 symbolS *sym;
0110f2b8
PB
13847 int offset;
13848
6e1cb1a6
PB
13849 /* The size of the instruction is unknown, so tie the debug info to the
13850 start of the instruction. */
13851 dwarf2_emit_insn (0);
6e1cb1a6 13852
0110f2b8
PB
13853 switch (inst.reloc.exp.X_op)
13854 {
13855 case O_symbol:
13856 sym = inst.reloc.exp.X_add_symbol;
13857 offset = inst.reloc.exp.X_add_number;
13858 break;
13859 case O_constant:
13860 sym = NULL;
13861 offset = inst.reloc.exp.X_add_number;
13862 break;
13863 default:
13864 sym = make_expr_symbol (&inst.reloc.exp);
13865 offset = 0;
13866 break;
13867 }
13868 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13869 inst.relax, sym, offset, NULL/*offset, opcode*/);
13870 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13871}
13872
13873/* Write a 32-bit thumb instruction to buf. */
13874static void
13875put_thumb32_insn (char * buf, unsigned long insn)
13876{
13877 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13878 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13879}
13880
b99bd4ef 13881static void
c19d1205 13882output_inst (const char * str)
b99bd4ef 13883{
c19d1205 13884 char * to = NULL;
b99bd4ef 13885
c19d1205 13886 if (inst.error)
b99bd4ef 13887 {
c19d1205 13888 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13889 return;
13890 }
5f4273c7
NC
13891 if (inst.relax)
13892 {
13893 output_relax_insn ();
0110f2b8 13894 return;
5f4273c7 13895 }
c19d1205
ZW
13896 if (inst.size == 0)
13897 return;
b99bd4ef 13898
c19d1205
ZW
13899 to = frag_more (inst.size);
13900
13901 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13902 {
c19d1205 13903 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13904 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13905 }
c19d1205 13906 else if (inst.size > INSN_SIZE)
b99bd4ef 13907 {
c19d1205
ZW
13908 assert (inst.size == (2 * INSN_SIZE));
13909 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13910 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13911 }
c19d1205
ZW
13912 else
13913 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13914
c19d1205
ZW
13915 if (inst.reloc.type != BFD_RELOC_UNUSED)
13916 fix_new_arm (frag_now, to - frag_now->fr_literal,
13917 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13918 inst.reloc.type);
b99bd4ef 13919
c19d1205 13920 dwarf2_emit_insn (inst.size);
c19d1205 13921}
b99bd4ef 13922
c19d1205
ZW
13923/* Tag values used in struct asm_opcode's tag field. */
13924enum opcode_tag
13925{
13926 OT_unconditional, /* Instruction cannot be conditionalized.
13927 The ARM condition field is still 0xE. */
13928 OT_unconditionalF, /* Instruction cannot be conditionalized
13929 and carries 0xF in its ARM condition field. */
13930 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13931 OT_csuffixF, /* Some forms of the instruction take a conditional
13932 suffix, others place 0xF where the condition field
13933 would be. */
c19d1205
ZW
13934 OT_cinfix3, /* Instruction takes a conditional infix,
13935 beginning at character index 3. (In
13936 unified mode, it becomes a suffix.) */
088fa78e
KH
13937 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13938 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13939 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13940 character index 3, even in unified mode. Used for
13941 legacy instructions where suffix and infix forms
13942 may be ambiguous. */
c19d1205 13943 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13944 suffix or an infix at character index 3. */
c19d1205
ZW
13945 OT_odd_infix_unc, /* This is the unconditional variant of an
13946 instruction that takes a conditional infix
13947 at an unusual position. In unified mode,
13948 this variant will accept a suffix. */
13949 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13950 are the conditional variants of instructions that
13951 take conditional infixes in unusual positions.
13952 The infix appears at character index
13953 (tag - OT_odd_infix_0). These are not accepted
13954 in unified mode. */
13955};
b99bd4ef 13956
c19d1205
ZW
13957/* Subroutine of md_assemble, responsible for looking up the primary
13958 opcode from the mnemonic the user wrote. STR points to the
13959 beginning of the mnemonic.
13960
13961 This is not simply a hash table lookup, because of conditional
13962 variants. Most instructions have conditional variants, which are
13963 expressed with a _conditional affix_ to the mnemonic. If we were
13964 to encode each conditional variant as a literal string in the opcode
13965 table, it would have approximately 20,000 entries.
13966
13967 Most mnemonics take this affix as a suffix, and in unified syntax,
13968 'most' is upgraded to 'all'. However, in the divided syntax, some
13969 instructions take the affix as an infix, notably the s-variants of
13970 the arithmetic instructions. Of those instructions, all but six
13971 have the infix appear after the third character of the mnemonic.
13972
13973 Accordingly, the algorithm for looking up primary opcodes given
13974 an identifier is:
13975
13976 1. Look up the identifier in the opcode table.
13977 If we find a match, go to step U.
13978
13979 2. Look up the last two characters of the identifier in the
13980 conditions table. If we find a match, look up the first N-2
13981 characters of the identifier in the opcode table. If we
13982 find a match, go to step CE.
13983
13984 3. Look up the fourth and fifth characters of the identifier in
13985 the conditions table. If we find a match, extract those
13986 characters from the identifier, and look up the remaining
13987 characters in the opcode table. If we find a match, go
13988 to step CM.
13989
13990 4. Fail.
13991
13992 U. Examine the tag field of the opcode structure, in case this is
13993 one of the six instructions with its conditional infix in an
13994 unusual place. If it is, the tag tells us where to find the
13995 infix; look it up in the conditions table and set inst.cond
13996 accordingly. Otherwise, this is an unconditional instruction.
13997 Again set inst.cond accordingly. Return the opcode structure.
13998
13999 CE. Examine the tag field to make sure this is an instruction that
14000 should receive a conditional suffix. If it is not, fail.
14001 Otherwise, set inst.cond from the suffix we already looked up,
14002 and return the opcode structure.
14003
14004 CM. Examine the tag field to make sure this is an instruction that
14005 should receive a conditional infix after the third character.
14006 If it is not, fail. Otherwise, undo the edits to the current
14007 line of input and proceed as for case CE. */
14008
14009static const struct asm_opcode *
14010opcode_lookup (char **str)
14011{
14012 char *end, *base;
14013 char *affix;
14014 const struct asm_opcode *opcode;
14015 const struct asm_cond *cond;
e3cb604e 14016 char save[2];
267d2029 14017 bfd_boolean neon_supported;
5f4273c7 14018
267d2029 14019 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14020
14021 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14022 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14023 for (base = end = *str; *end != '\0'; end++)
267d2029 14024 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14025 break;
b99bd4ef 14026
c19d1205
ZW
14027 if (end == base)
14028 return 0;
b99bd4ef 14029
5287ad62 14030 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14031 if (end[0] == '.')
b99bd4ef 14032 {
5287ad62 14033 int offset = 2;
5f4273c7 14034
267d2029
JB
14035 /* The .w and .n suffixes are only valid if the unified syntax is in
14036 use. */
14037 if (unified_syntax && end[1] == 'w')
c19d1205 14038 inst.size_req = 4;
267d2029 14039 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14040 inst.size_req = 2;
14041 else
5287ad62
JB
14042 offset = 0;
14043
14044 inst.vectype.elems = 0;
14045
14046 *str = end + offset;
b99bd4ef 14047
5f4273c7 14048 if (end[offset] == '.')
5287ad62 14049 {
267d2029
JB
14050 /* See if we have a Neon type suffix (possible in either unified or
14051 non-unified ARM syntax mode). */
dcbf9037 14052 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14053 return 0;
14054 }
14055 else if (end[offset] != '\0' && end[offset] != ' ')
14056 return 0;
b99bd4ef 14057 }
c19d1205
ZW
14058 else
14059 *str = end;
b99bd4ef 14060
c19d1205
ZW
14061 /* Look for unaffixed or special-case affixed mnemonic. */
14062 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14063 if (opcode)
b99bd4ef 14064 {
c19d1205
ZW
14065 /* step U */
14066 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14067 {
c19d1205
ZW
14068 inst.cond = COND_ALWAYS;
14069 return opcode;
b99bd4ef 14070 }
b99bd4ef 14071
c19d1205
ZW
14072 if (unified_syntax)
14073 as_warn (_("conditional infixes are deprecated in unified syntax"));
14074 affix = base + (opcode->tag - OT_odd_infix_0);
14075 cond = hash_find_n (arm_cond_hsh, affix, 2);
14076 assert (cond);
b99bd4ef 14077
c19d1205
ZW
14078 inst.cond = cond->value;
14079 return opcode;
14080 }
b99bd4ef 14081
c19d1205
ZW
14082 /* Cannot have a conditional suffix on a mnemonic of less than two
14083 characters. */
14084 if (end - base < 3)
14085 return 0;
b99bd4ef 14086
c19d1205
ZW
14087 /* Look for suffixed mnemonic. */
14088 affix = end - 2;
14089 cond = hash_find_n (arm_cond_hsh, affix, 2);
14090 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14091 if (opcode && cond)
14092 {
14093 /* step CE */
14094 switch (opcode->tag)
14095 {
e3cb604e
PB
14096 case OT_cinfix3_legacy:
14097 /* Ignore conditional suffixes matched on infix only mnemonics. */
14098 break;
14099
c19d1205 14100 case OT_cinfix3:
088fa78e 14101 case OT_cinfix3_deprecated:
c19d1205
ZW
14102 case OT_odd_infix_unc:
14103 if (!unified_syntax)
e3cb604e 14104 return 0;
c19d1205
ZW
14105 /* else fall through */
14106
14107 case OT_csuffix:
037e8744 14108 case OT_csuffixF:
c19d1205
ZW
14109 case OT_csuf_or_in3:
14110 inst.cond = cond->value;
14111 return opcode;
14112
14113 case OT_unconditional:
14114 case OT_unconditionalF:
dfa9f0d5
PB
14115 if (thumb_mode)
14116 {
14117 inst.cond = cond->value;
14118 }
14119 else
14120 {
14121 /* delayed diagnostic */
14122 inst.error = BAD_COND;
14123 inst.cond = COND_ALWAYS;
14124 }
c19d1205 14125 return opcode;
b99bd4ef 14126
c19d1205
ZW
14127 default:
14128 return 0;
14129 }
14130 }
b99bd4ef 14131
c19d1205
ZW
14132 /* Cannot have a usual-position infix on a mnemonic of less than
14133 six characters (five would be a suffix). */
14134 if (end - base < 6)
14135 return 0;
b99bd4ef 14136
c19d1205
ZW
14137 /* Look for infixed mnemonic in the usual position. */
14138 affix = base + 3;
14139 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14140 if (!cond)
14141 return 0;
14142
14143 memcpy (save, affix, 2);
14144 memmove (affix, affix + 2, (end - affix) - 2);
14145 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14146 memmove (affix + 2, affix, (end - affix) - 2);
14147 memcpy (affix, save, 2);
14148
088fa78e
KH
14149 if (opcode
14150 && (opcode->tag == OT_cinfix3
14151 || opcode->tag == OT_cinfix3_deprecated
14152 || opcode->tag == OT_csuf_or_in3
14153 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14154 {
c19d1205 14155 /* step CM */
088fa78e
KH
14156 if (unified_syntax
14157 && (opcode->tag == OT_cinfix3
14158 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14159 as_warn (_("conditional infixes are deprecated in unified syntax"));
14160
14161 inst.cond = cond->value;
14162 return opcode;
b99bd4ef
NC
14163 }
14164
c19d1205 14165 return 0;
b99bd4ef
NC
14166}
14167
c19d1205
ZW
14168void
14169md_assemble (char *str)
b99bd4ef 14170{
c19d1205
ZW
14171 char *p = str;
14172 const struct asm_opcode * opcode;
b99bd4ef 14173
c19d1205
ZW
14174 /* Align the previous label if needed. */
14175 if (last_label_seen != NULL)
b99bd4ef 14176 {
c19d1205
ZW
14177 symbol_set_frag (last_label_seen, frag_now);
14178 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14179 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14180 }
14181
c19d1205
ZW
14182 memset (&inst, '\0', sizeof (inst));
14183 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14184
c19d1205
ZW
14185 opcode = opcode_lookup (&p);
14186 if (!opcode)
b99bd4ef 14187 {
c19d1205 14188 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14189 the form alias .req reg, or a Neon .dn/.qn directive. */
14190 if (!create_register_alias (str, p)
14191 && !create_neon_reg_alias (str, p))
c19d1205 14192 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14193
b99bd4ef
NC
14194 return;
14195 }
14196
088fa78e
KH
14197 if (opcode->tag == OT_cinfix3_deprecated)
14198 as_warn (_("s suffix on comparison instruction is deprecated"));
14199
037e8744
JB
14200 /* The value which unconditional instructions should have in place of the
14201 condition field. */
14202 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14203
c19d1205 14204 if (thumb_mode)
b99bd4ef 14205 {
e74cfd16 14206 arm_feature_set variant;
8f06b2d8
PB
14207
14208 variant = cpu_variant;
14209 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14210 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14211 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14212 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14213 if (!opcode->tvariant
14214 || (thumb_mode == 1
14215 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14216 {
c19d1205 14217 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14218 return;
14219 }
c19d1205
ZW
14220 if (inst.cond != COND_ALWAYS && !unified_syntax
14221 && opcode->tencode != do_t_branch)
b99bd4ef 14222 {
c19d1205 14223 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14224 return;
14225 }
14226
076d447c
PB
14227 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14228 {
14229 /* Implicit require narrow instructions on Thumb-1. This avoids
14230 relaxation accidentally introducing Thumb-2 instructions. */
7e806470
PB
14231 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14232 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
076d447c
PB
14233 inst.size_req = 2;
14234 }
14235
e27ec89e
PB
14236 /* Check conditional suffixes. */
14237 if (current_it_mask)
14238 {
14239 int cond;
14240 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14241 current_it_mask <<= 1;
14242 current_it_mask &= 0x1f;
14243 /* The BKPT instruction is unconditional even in an IT block. */
14244 if (!inst.error
14245 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14246 {
14247 as_bad (_("incorrect condition in IT block"));
14248 return;
14249 }
e27ec89e
PB
14250 }
14251 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14252 {
6decc662 14253 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14254 return;
14255 }
14256
c19d1205
ZW
14257 mapping_state (MAP_THUMB);
14258 inst.instruction = opcode->tvalue;
14259
14260 if (!parse_operands (p, opcode->operands))
14261 opcode->tencode ();
14262
e27ec89e
PB
14263 /* Clear current_it_mask at the end of an IT block. */
14264 if (current_it_mask == 0x10)
14265 current_it_mask = 0;
14266
0110f2b8 14267 if (!(inst.error || inst.relax))
b99bd4ef 14268 {
c19d1205
ZW
14269 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14270 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14271 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14272 {
c19d1205 14273 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14274 return;
14275 }
14276 }
076d447c
PB
14277
14278 /* Something has gone badly wrong if we try to relax a fixed size
14279 instruction. */
14280 assert (inst.size_req == 0 || !inst.relax);
14281
e74cfd16
PB
14282 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14283 *opcode->tvariant);
ee065d83 14284 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14285 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14286 anything other than bl/blx and v6-M instructions.
ee065d83 14287 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14288 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14289 || inst.relax)
14290 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
e74cfd16
PB
14291 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14292 arm_ext_v6t2);
c19d1205 14293 }
3e9e4fcf 14294 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14295 {
845b51d6
PB
14296 bfd_boolean is_bx;
14297
14298 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14299 is_bx = (opcode->aencode == do_bx);
14300
c19d1205 14301 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14302 if (!(is_bx && fix_v4bx)
14303 && !(opcode->avariant &&
14304 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14305 {
c19d1205
ZW
14306 as_bad (_("selected processor does not support `%s'"), str);
14307 return;
b99bd4ef 14308 }
c19d1205 14309 if (inst.size_req)
b99bd4ef 14310 {
c19d1205
ZW
14311 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14312 return;
b99bd4ef
NC
14313 }
14314
c19d1205
ZW
14315 mapping_state (MAP_ARM);
14316 inst.instruction = opcode->avalue;
14317 if (opcode->tag == OT_unconditionalF)
14318 inst.instruction |= 0xF << 28;
14319 else
14320 inst.instruction |= inst.cond << 28;
14321 inst.size = INSN_SIZE;
14322 if (!parse_operands (p, opcode->operands))
14323 opcode->aencode ();
ee065d83
PB
14324 /* Arm mode bx is marked as both v4T and v5 because it's still required
14325 on a hypothetical non-thumb v5 core. */
845b51d6 14326 if (is_bx)
e74cfd16 14327 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14328 else
e74cfd16
PB
14329 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14330 *opcode->avariant);
b99bd4ef 14331 }
3e9e4fcf
JB
14332 else
14333 {
14334 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14335 "-- `%s'"), str);
14336 return;
14337 }
c19d1205
ZW
14338 output_inst (str);
14339}
b99bd4ef 14340
c19d1205
ZW
14341/* Various frobbings of labels and their addresses. */
14342
14343void
14344arm_start_line_hook (void)
14345{
14346 last_label_seen = NULL;
b99bd4ef
NC
14347}
14348
c19d1205
ZW
14349void
14350arm_frob_label (symbolS * sym)
b99bd4ef 14351{
c19d1205 14352 last_label_seen = sym;
b99bd4ef 14353
c19d1205 14354 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14355
c19d1205
ZW
14356#if defined OBJ_COFF || defined OBJ_ELF
14357 ARM_SET_INTERWORK (sym, support_interwork);
14358#endif
b99bd4ef 14359
5f4273c7 14360 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14361 as Thumb functions. This is because these labels, whilst
14362 they exist inside Thumb code, are not the entry points for
14363 possible ARM->Thumb calls. Also, these labels can be used
14364 as part of a computed goto or switch statement. eg gcc
14365 can generate code that looks like this:
b99bd4ef 14366
c19d1205
ZW
14367 ldr r2, [pc, .Laaa]
14368 lsl r3, r3, #2
14369 ldr r2, [r3, r2]
14370 mov pc, r2
b99bd4ef 14371
c19d1205
ZW
14372 .Lbbb: .word .Lxxx
14373 .Lccc: .word .Lyyy
14374 ..etc...
14375 .Laaa: .word Lbbb
b99bd4ef 14376
c19d1205
ZW
14377 The first instruction loads the address of the jump table.
14378 The second instruction converts a table index into a byte offset.
14379 The third instruction gets the jump address out of the table.
14380 The fourth instruction performs the jump.
b99bd4ef 14381
c19d1205
ZW
14382 If the address stored at .Laaa is that of a symbol which has the
14383 Thumb_Func bit set, then the linker will arrange for this address
14384 to have the bottom bit set, which in turn would mean that the
14385 address computation performed by the third instruction would end
14386 up with the bottom bit set. Since the ARM is capable of unaligned
14387 word loads, the instruction would then load the incorrect address
14388 out of the jump table, and chaos would ensue. */
14389 if (label_is_thumb_function_name
14390 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14391 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14392 {
c19d1205
ZW
14393 /* When the address of a Thumb function is taken the bottom
14394 bit of that address should be set. This will allow
14395 interworking between Arm and Thumb functions to work
14396 correctly. */
b99bd4ef 14397
c19d1205 14398 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14399
c19d1205 14400 label_is_thumb_function_name = FALSE;
b99bd4ef 14401 }
07a53e5c 14402
07a53e5c 14403 dwarf2_emit_label (sym);
b99bd4ef
NC
14404}
14405
c19d1205
ZW
14406int
14407arm_data_in_code (void)
b99bd4ef 14408{
c19d1205 14409 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14410 {
c19d1205
ZW
14411 *input_line_pointer = '/';
14412 input_line_pointer += 5;
14413 *input_line_pointer = 0;
14414 return 1;
b99bd4ef
NC
14415 }
14416
c19d1205 14417 return 0;
b99bd4ef
NC
14418}
14419
c19d1205
ZW
14420char *
14421arm_canonicalize_symbol_name (char * name)
b99bd4ef 14422{
c19d1205 14423 int len;
b99bd4ef 14424
c19d1205
ZW
14425 if (thumb_mode && (len = strlen (name)) > 5
14426 && streq (name + len - 5, "/data"))
14427 *(name + len - 5) = 0;
b99bd4ef 14428
c19d1205 14429 return name;
b99bd4ef 14430}
c19d1205
ZW
14431\f
14432/* Table of all register names defined by default. The user can
14433 define additional names with .req. Note that all register names
14434 should appear in both upper and lowercase variants. Some registers
14435 also have mixed-case names. */
b99bd4ef 14436
dcbf9037 14437#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14438#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14439#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14440#define REGSET(p,t) \
14441 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14442 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14443 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14444 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14445#define REGSETH(p,t) \
14446 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14447 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14448 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14449 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14450#define REGSET2(p,t) \
14451 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14452 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14453 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14454 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14455
c19d1205 14456static const struct reg_entry reg_names[] =
7ed4c4c5 14457{
c19d1205
ZW
14458 /* ARM integer registers. */
14459 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14460
c19d1205
ZW
14461 /* ATPCS synonyms. */
14462 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14463 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14464 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14465
c19d1205
ZW
14466 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14467 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14468 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14469
c19d1205
ZW
14470 /* Well-known aliases. */
14471 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14472 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14473
14474 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14475 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14476
14477 /* Coprocessor numbers. */
14478 REGSET(p, CP), REGSET(P, CP),
14479
14480 /* Coprocessor register numbers. The "cr" variants are for backward
14481 compatibility. */
14482 REGSET(c, CN), REGSET(C, CN),
14483 REGSET(cr, CN), REGSET(CR, CN),
14484
14485 /* FPA registers. */
14486 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14487 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14488
14489 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14490 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14491
14492 /* VFP SP registers. */
5287ad62
JB
14493 REGSET(s,VFS), REGSET(S,VFS),
14494 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14495
14496 /* VFP DP Registers. */
5287ad62
JB
14497 REGSET(d,VFD), REGSET(D,VFD),
14498 /* Extra Neon DP registers. */
14499 REGSETH(d,VFD), REGSETH(D,VFD),
14500
14501 /* Neon QP registers. */
14502 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14503
14504 /* VFP control registers. */
14505 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14506 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14507 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14508 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14509 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14510 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14511
14512 /* Maverick DSP coprocessor registers. */
14513 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14514 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14515
14516 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14517 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14518 REGDEF(dspsc,0,DSPSC),
14519
14520 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14521 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14522 REGDEF(DSPSC,0,DSPSC),
14523
14524 /* iWMMXt data registers - p0, c0-15. */
14525 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14526
14527 /* iWMMXt control registers - p1, c0-3. */
14528 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14529 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14530 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14531 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14532
14533 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14534 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14535 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14536 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14537 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14538
14539 /* XScale accumulator registers. */
14540 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14541};
14542#undef REGDEF
14543#undef REGNUM
14544#undef REGSET
7ed4c4c5 14545
c19d1205
ZW
14546/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14547 within psr_required_here. */
14548static const struct asm_psr psrs[] =
14549{
14550 /* Backward compatibility notation. Note that "all" is no longer
14551 truly all possible PSR bits. */
14552 {"all", PSR_c | PSR_f},
14553 {"flg", PSR_f},
14554 {"ctl", PSR_c},
14555
14556 /* Individual flags. */
14557 {"f", PSR_f},
14558 {"c", PSR_c},
14559 {"x", PSR_x},
14560 {"s", PSR_s},
14561 /* Combinations of flags. */
14562 {"fs", PSR_f | PSR_s},
14563 {"fx", PSR_f | PSR_x},
14564 {"fc", PSR_f | PSR_c},
14565 {"sf", PSR_s | PSR_f},
14566 {"sx", PSR_s | PSR_x},
14567 {"sc", PSR_s | PSR_c},
14568 {"xf", PSR_x | PSR_f},
14569 {"xs", PSR_x | PSR_s},
14570 {"xc", PSR_x | PSR_c},
14571 {"cf", PSR_c | PSR_f},
14572 {"cs", PSR_c | PSR_s},
14573 {"cx", PSR_c | PSR_x},
14574 {"fsx", PSR_f | PSR_s | PSR_x},
14575 {"fsc", PSR_f | PSR_s | PSR_c},
14576 {"fxs", PSR_f | PSR_x | PSR_s},
14577 {"fxc", PSR_f | PSR_x | PSR_c},
14578 {"fcs", PSR_f | PSR_c | PSR_s},
14579 {"fcx", PSR_f | PSR_c | PSR_x},
14580 {"sfx", PSR_s | PSR_f | PSR_x},
14581 {"sfc", PSR_s | PSR_f | PSR_c},
14582 {"sxf", PSR_s | PSR_x | PSR_f},
14583 {"sxc", PSR_s | PSR_x | PSR_c},
14584 {"scf", PSR_s | PSR_c | PSR_f},
14585 {"scx", PSR_s | PSR_c | PSR_x},
14586 {"xfs", PSR_x | PSR_f | PSR_s},
14587 {"xfc", PSR_x | PSR_f | PSR_c},
14588 {"xsf", PSR_x | PSR_s | PSR_f},
14589 {"xsc", PSR_x | PSR_s | PSR_c},
14590 {"xcf", PSR_x | PSR_c | PSR_f},
14591 {"xcs", PSR_x | PSR_c | PSR_s},
14592 {"cfs", PSR_c | PSR_f | PSR_s},
14593 {"cfx", PSR_c | PSR_f | PSR_x},
14594 {"csf", PSR_c | PSR_s | PSR_f},
14595 {"csx", PSR_c | PSR_s | PSR_x},
14596 {"cxf", PSR_c | PSR_x | PSR_f},
14597 {"cxs", PSR_c | PSR_x | PSR_s},
14598 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14599 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14600 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14601 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14602 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14603 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14604 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14605 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14606 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14607 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14608 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14609 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14610 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14611 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14612 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14613 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14614 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14615 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14616 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14617 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14618 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14619 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14620 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14621 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14622};
14623
62b3e311
PB
14624/* Table of V7M psr names. */
14625static const struct asm_psr v7m_psrs[] =
14626{
2b744c99
PB
14627 {"apsr", 0 }, {"APSR", 0 },
14628 {"iapsr", 1 }, {"IAPSR", 1 },
14629 {"eapsr", 2 }, {"EAPSR", 2 },
14630 {"psr", 3 }, {"PSR", 3 },
14631 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14632 {"ipsr", 5 }, {"IPSR", 5 },
14633 {"epsr", 6 }, {"EPSR", 6 },
14634 {"iepsr", 7 }, {"IEPSR", 7 },
14635 {"msp", 8 }, {"MSP", 8 },
14636 {"psp", 9 }, {"PSP", 9 },
14637 {"primask", 16}, {"PRIMASK", 16},
14638 {"basepri", 17}, {"BASEPRI", 17},
14639 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14640 {"faultmask", 19}, {"FAULTMASK", 19},
14641 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14642};
14643
c19d1205
ZW
14644/* Table of all shift-in-operand names. */
14645static const struct asm_shift_name shift_names [] =
b99bd4ef 14646{
c19d1205
ZW
14647 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14648 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14649 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14650 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14651 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14652 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14653};
b99bd4ef 14654
c19d1205
ZW
14655/* Table of all explicit relocation names. */
14656#ifdef OBJ_ELF
14657static struct reloc_entry reloc_names[] =
14658{
14659 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14660 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14661 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14662 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14663 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14664 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14665 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14666 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14667 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14668 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14669 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14670};
14671#endif
b99bd4ef 14672
c19d1205
ZW
14673/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14674static const struct asm_cond conds[] =
14675{
14676 {"eq", 0x0},
14677 {"ne", 0x1},
14678 {"cs", 0x2}, {"hs", 0x2},
14679 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14680 {"mi", 0x4},
14681 {"pl", 0x5},
14682 {"vs", 0x6},
14683 {"vc", 0x7},
14684 {"hi", 0x8},
14685 {"ls", 0x9},
14686 {"ge", 0xa},
14687 {"lt", 0xb},
14688 {"gt", 0xc},
14689 {"le", 0xd},
14690 {"al", 0xe}
14691};
bfae80f2 14692
62b3e311
PB
14693static struct asm_barrier_opt barrier_opt_names[] =
14694{
14695 { "sy", 0xf },
14696 { "un", 0x7 },
14697 { "st", 0xe },
14698 { "unst", 0x6 }
14699};
14700
c19d1205
ZW
14701/* Table of ARM-format instructions. */
14702
14703/* Macros for gluing together operand strings. N.B. In all cases
14704 other than OPS0, the trailing OP_stop comes from default
14705 zero-initialization of the unspecified elements of the array. */
14706#define OPS0() { OP_stop, }
14707#define OPS1(a) { OP_##a, }
14708#define OPS2(a,b) { OP_##a,OP_##b, }
14709#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14710#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14711#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14712#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14713
14714/* These macros abstract out the exact format of the mnemonic table and
14715 save some repeated characters. */
14716
14717/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14718#define TxCE(mnem, op, top, nops, ops, ae, te) \
14719 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14720 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14721
14722/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14723 a T_MNEM_xyz enumerator. */
14724#define TCE(mnem, aop, top, nops, ops, ae, te) \
14725 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14726#define tCE(mnem, aop, top, nops, ops, ae, te) \
14727 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14728
14729/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14730 infix after the third character. */
14731#define TxC3(mnem, op, top, nops, ops, ae, te) \
14732 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14733 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14734#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14735 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14736 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14737#define TC3(mnem, aop, top, nops, ops, ae, te) \
14738 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14739#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14740 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14741#define tC3(mnem, aop, top, nops, ops, ae, te) \
14742 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14743#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14744 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14745
14746/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14747 appear in the condition table. */
14748#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14749 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14750 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14751
14752#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14753 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14754 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14755 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14756 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14757 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14758 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14759 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14760 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14761 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14772
14773#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14774 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14775#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14776 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14777
14778/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14779 field is still 0xE. Many of the Thumb variants can be executed
14780 conditionally, so this is checked separately. */
c19d1205
ZW
14781#define TUE(mnem, op, top, nops, ops, ae, te) \
14782 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14783 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14784
14785/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14786 condition code field. */
14787#define TUF(mnem, op, top, nops, ops, ae, te) \
14788 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14789 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14790
14791/* ARM-only variants of all the above. */
6a86118a
NC
14792#define CE(mnem, op, nops, ops, ae) \
14793 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14794
14795#define C3(mnem, op, nops, ops, ae) \
14796 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14797
e3cb604e
PB
14798/* Legacy mnemonics that always have conditional infix after the third
14799 character. */
14800#define CL(mnem, op, nops, ops, ae) \
14801 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14802 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14803
8f06b2d8
PB
14804/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14805#define cCE(mnem, op, nops, ops, ae) \
14806 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14807
e3cb604e
PB
14808/* Legacy coprocessor instructions where conditional infix and conditional
14809 suffix are ambiguous. For consistency this includes all FPA instructions,
14810 not just the potentially ambiguous ones. */
14811#define cCL(mnem, op, nops, ops, ae) \
14812 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14813 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14814
14815/* Coprocessor, takes either a suffix or a position-3 infix
14816 (for an FPA corner case). */
14817#define C3E(mnem, op, nops, ops, ae) \
14818 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14819 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14820
6a86118a
NC
14821#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14822 { #m1 #m2 #m3, OPS##nops ops, \
14823 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14824 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14825
14826#define CM(m1, m2, op, nops, ops, ae) \
14827 xCM_(m1, , m2, op, nops, ops, ae), \
14828 xCM_(m1, eq, m2, op, nops, ops, ae), \
14829 xCM_(m1, ne, m2, op, nops, ops, ae), \
14830 xCM_(m1, cs, m2, op, nops, ops, ae), \
14831 xCM_(m1, hs, m2, op, nops, ops, ae), \
14832 xCM_(m1, cc, m2, op, nops, ops, ae), \
14833 xCM_(m1, ul, m2, op, nops, ops, ae), \
14834 xCM_(m1, lo, m2, op, nops, ops, ae), \
14835 xCM_(m1, mi, m2, op, nops, ops, ae), \
14836 xCM_(m1, pl, m2, op, nops, ops, ae), \
14837 xCM_(m1, vs, m2, op, nops, ops, ae), \
14838 xCM_(m1, vc, m2, op, nops, ops, ae), \
14839 xCM_(m1, hi, m2, op, nops, ops, ae), \
14840 xCM_(m1, ls, m2, op, nops, ops, ae), \
14841 xCM_(m1, ge, m2, op, nops, ops, ae), \
14842 xCM_(m1, lt, m2, op, nops, ops, ae), \
14843 xCM_(m1, gt, m2, op, nops, ops, ae), \
14844 xCM_(m1, le, m2, op, nops, ops, ae), \
14845 xCM_(m1, al, m2, op, nops, ops, ae)
14846
14847#define UE(mnem, op, nops, ops, ae) \
14848 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14849
14850#define UF(mnem, op, nops, ops, ae) \
14851 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14852
5287ad62
JB
14853/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14854 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14855 use the same encoding function for each. */
14856#define NUF(mnem, op, nops, ops, enc) \
14857 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14858 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14859
14860/* Neon data processing, version which indirects through neon_enc_tab for
14861 the various overloaded versions of opcodes. */
14862#define nUF(mnem, op, nops, ops, enc) \
14863 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14864 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14865
14866/* Neon insn with conditional suffix for the ARM version, non-overloaded
14867 version. */
037e8744
JB
14868#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14869 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14870 THUMB_VARIANT, do_##enc, do_##enc }
14871
037e8744
JB
14872#define NCE(mnem, op, nops, ops, enc) \
14873 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14874
14875#define NCEF(mnem, op, nops, ops, enc) \
14876 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14877
5287ad62 14878/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14879#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14880 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14881 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14882
037e8744
JB
14883#define nCE(mnem, op, nops, ops, enc) \
14884 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14885
14886#define nCEF(mnem, op, nops, ops, enc) \
14887 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14888
c19d1205
ZW
14889#define do_0 0
14890
14891/* Thumb-only, unconditional. */
14892#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14893
c19d1205 14894static const struct asm_opcode insns[] =
bfae80f2 14895{
e74cfd16
PB
14896#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14897#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14898 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14899 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14900 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14901 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14902 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14903 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14904 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14905 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14906 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14908 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14909 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14910 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14911 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14912 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14913 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14914
14915 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14916 for setting PSR flag bits. They are obsolete in V6 and do not
14917 have Thumb equivalents. */
14918 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14919 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14920 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14921 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14922 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14923 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14924 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14925 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14926 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14927
14928 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14929 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14930 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14931 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14932
4962c51a
MS
14933 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14934 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14935 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14936 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14937
f5208ef2 14938 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14939 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14940 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14941 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14942 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14943 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14944
14945 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14946 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14947 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14948 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14949
c19d1205 14950 /* Pseudo ops. */
e9f89963 14951 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14952 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14953 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14954
14955 /* Thumb-compatibility pseudo ops. */
14956 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14957 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14958 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14959 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14960 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14961 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14962 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14963 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14964 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14965 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14966 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14967 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14968
16a4cf17
PB
14969 /* These may simplify to neg. */
14970 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14971 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14972
c19d1205 14973#undef THUMB_VARIANT
e74cfd16 14974#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14975 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14976
14977 /* V1 instructions with no Thumb analogue prior to V6T2. */
14978#undef THUMB_VARIANT
e74cfd16 14979#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14980 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14981 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14982 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14983
14984 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14985 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14986 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14987 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14988
9c3c69f2
PB
14989 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14990 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14991
9c3c69f2
PB
14992 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14993 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14994
14995 /* V1 instructions with no Thumb analogue at all. */
14996 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14997 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14998
14999 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15000 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15001 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15002 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15003 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15004 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15005 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15006 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15007
15008#undef ARM_VARIANT
e74cfd16 15009#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15010#undef THUMB_VARIANT
e74cfd16 15011#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15012 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15013 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15014
15015#undef THUMB_VARIANT
e74cfd16 15016#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15017 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15018 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15019
15020 /* Generic coprocessor instructions. */
15021 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15022 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15023 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15024 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15025 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15026 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15027 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15028
15029#undef ARM_VARIANT
e74cfd16 15030#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15031 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15032 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15033
15034#undef ARM_VARIANT
e74cfd16 15035#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15036#undef THUMB_VARIANT
15037#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15038 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15039 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15040
15041#undef ARM_VARIANT
e74cfd16 15042#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15043#undef THUMB_VARIANT
15044#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15045 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15046 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15047 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15048 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15049 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15050 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15051 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053
15054#undef ARM_VARIANT
e74cfd16 15055#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15056#undef THUMB_VARIANT
e74cfd16 15057#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15058 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15059 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15060 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15061 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15062 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15063 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15064
15065#undef ARM_VARIANT
e74cfd16 15066#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15067 /* ARM Architecture 4T. */
15068 /* Note: bx (and blx) are required on V5, even if the processor does
15069 not support Thumb. */
15070 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15071
15072#undef ARM_VARIANT
e74cfd16 15073#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15074#undef THUMB_VARIANT
e74cfd16 15075#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15076 /* Note: blx has 2 variants; the .value coded here is for
15077 BLX(2). Only this variant has conditional execution. */
15078 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15079 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15080
15081#undef THUMB_VARIANT
e74cfd16 15082#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15083 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15084 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15085 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15086 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15087 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15088 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15089 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15090 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15091
15092#undef ARM_VARIANT
e74cfd16 15093#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15094 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15095 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15096 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15097 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15098
15099 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15100 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101
15102 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15103 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15104 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15105 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15106
15107 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15108 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15109 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15110 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15111
15112 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15113 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114
15115 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15116 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15117 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15118 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15119
15120#undef ARM_VARIANT
e74cfd16 15121#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15122 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15123 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15124 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15125
15126 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15127 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15128
15129#undef ARM_VARIANT
e74cfd16 15130#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15131 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15132
15133#undef ARM_VARIANT
e74cfd16 15134#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15135#undef THUMB_VARIANT
e74cfd16 15136#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15137 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15138 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15139 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15140 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15141 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15142 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15143 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15144 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15145 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15146 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15147
15148#undef THUMB_VARIANT
e74cfd16 15149#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15150 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15151 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15152 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15153 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15154
15155 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15156 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15157
15158/* ARM V6 not included in V7M (eg. integer SIMD). */
15159#undef THUMB_VARIANT
15160#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15161 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15162 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15163 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15164 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15165 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15166 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15167 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15168 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15201 UF(rfeib, 9900a00, 1, (RRw), rfe),
15202 UF(rfeda, 8100a00, 1, (RRw), rfe),
15203 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15204 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15205 UF(rfefa, 9900a00, 1, (RRw), rfe),
15206 UF(rfeea, 8100a00, 1, (RRw), rfe),
15207 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15208 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15209 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15210 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15211 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15212 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15213 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15214 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15216 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15217 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15218 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15219 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15220 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15221 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15222 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15223 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15224 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15225 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15226 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15227 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15228 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15229 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15230 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15231 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15232 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15235 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15236 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15237 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15238 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15239 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15240 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15241 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15242 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15243 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15244
15245#undef ARM_VARIANT
e74cfd16 15246#define ARM_VARIANT &arm_ext_v6k
c19d1205 15247#undef THUMB_VARIANT
e74cfd16 15248#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15249 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15250 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15251 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15252 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15253
ebdca51a
PB
15254#undef THUMB_VARIANT
15255#define THUMB_VARIANT &arm_ext_v6_notm
15256 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15257 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15258
c19d1205 15259#undef THUMB_VARIANT
e74cfd16 15260#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15261 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15262 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15263 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15264 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15265 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15266
15267#undef ARM_VARIANT
e74cfd16 15268#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15269 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15270
15271#undef ARM_VARIANT
e74cfd16 15272#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15273 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15274 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15275 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15276 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15277
15278 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15279 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15280 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15281 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15282
15283 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15284 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15285 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15286 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15287
25fe350b
MS
15288 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15289 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15290 /* ARM does not really have an IT instruction, so always allow it. */
15291#undef ARM_VARIANT
15292#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15293 TUE(it, 0, bf08, 1, (COND), it, t_it),
15294 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15295 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15296 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15297 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15298 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15299 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15300 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15301 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15302 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15303 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15304 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15305 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15306 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15307 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15308
92e90b6e
PB
15309 /* Thumb2 only instructions. */
15310#undef ARM_VARIANT
e74cfd16 15311#define ARM_VARIANT NULL
92e90b6e
PB
15312
15313 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15314 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15315 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15316 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15317
62b3e311
PB
15318 /* Thumb-2 hardware division instructions (R and M profiles only). */
15319#undef THUMB_VARIANT
15320#define THUMB_VARIANT &arm_ext_div
15321 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15322 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15323
7e806470
PB
15324 /* ARM V6M/V7 instructions. */
15325#undef ARM_VARIANT
15326#define ARM_VARIANT &arm_ext_barrier
15327#undef THUMB_VARIANT
15328#define THUMB_VARIANT &arm_ext_barrier
15329 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15330 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15331 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15332
62b3e311
PB
15333 /* ARM V7 instructions. */
15334#undef ARM_VARIANT
15335#define ARM_VARIANT &arm_ext_v7
15336#undef THUMB_VARIANT
15337#define THUMB_VARIANT &arm_ext_v7
15338 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15339 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15340
c19d1205 15341#undef ARM_VARIANT
e74cfd16 15342#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15343 cCE(wfs, e200110, 1, (RR), rd),
15344 cCE(rfs, e300110, 1, (RR), rd),
15345 cCE(wfc, e400110, 1, (RR), rd),
15346 cCE(rfc, e500110, 1, (RR), rd),
15347
4962c51a
MS
15348 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15349 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15350 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15351 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15352
4962c51a
MS
15353 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15354 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15355 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15356 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15357
15358 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15359 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15360 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15361 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15362 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15363 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15364 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15368 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15369 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15370
15371 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15372 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15373 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15374 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15375 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15376 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15377 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15381 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15382 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15383
15384 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15385 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15386 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15387 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15388 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15389 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15390 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15391 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15392 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15393 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15394 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15395 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15396
15397 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15398 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15399 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15400 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15401 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15402 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15403 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15404 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15405 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15406 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15407 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15408 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15409
15410 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15411 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15412 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15413 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15414 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15415 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15416 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15420 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15421 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15422
15423 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15424 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15425 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15426 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15427 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15428 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15429 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15430 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15431 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15432 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15433 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15434 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15435
15436 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15437 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15438 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15439 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15440 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15441 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15442 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15446 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15447 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15448
15449 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15450 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15451 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15452 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15453 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15454 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15455 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15456 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15457 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15458 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15459 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15460 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15461
15462 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15463 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15464 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15465 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15466 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15467 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15468 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15469 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15470 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15471 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15472 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15473 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15474
15475 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15476 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15477 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15478 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15479 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15480 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15481 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15482 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15483 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15484 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15485 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15486 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15487
15488 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15489 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15490 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15491 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15492 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15493 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15494 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15495 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15496 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15497 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15498 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15499 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15500
15501 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15502 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15503 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15504 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15505 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15506 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15507 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15508 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15509 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15510 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15511 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15512 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15513
15514 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15515 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15516 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15517 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15518 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15519 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15520 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15521 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15522 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15523 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15524 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15525 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15526
15527 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15528 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15529 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15530 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15531 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15532 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15533 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15534 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15535 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15536 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15537 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15538 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15539
15540 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15541 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15542 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15543 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15544 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15545 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15546 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15547 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15548 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15549 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15550 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15551 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15552
15553 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15554 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15555 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15556 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15557 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15558 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15559 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15563 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15564 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15565
15566 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15576 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15577 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15578
15579 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15589 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15590 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15591
15592 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15602 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15603 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15604
15605 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15615 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15616 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15617
15618 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15628 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15629 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15630
15631 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15641 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15642 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15643
15644 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15654 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15655 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15656
15657 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15667 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15668 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15669
15670 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15680 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15681 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15682
15683 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15693 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15694 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15695
15696 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15706 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15707 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15708
15709 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15721
15722 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15723 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15734
15735 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15736 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15737 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15738 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15739
e3cb604e
PB
15740 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15741 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15742 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15743 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15744 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15745 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15746 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15747 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15748 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15749 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15750 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15751 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15752
c19d1205
ZW
15753 /* The implementation of the FIX instruction is broken on some
15754 assemblers, in that it accepts a precision specifier as well as a
15755 rounding specifier, despite the fact that this is meaningless.
15756 To be more compatible, we accept it as well, though of course it
15757 does not set any bits. */
8f06b2d8 15758 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15759 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15760 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15761 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15762 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15763 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15764 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15765 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15766 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15767 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15768 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15769 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15770 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15771
c19d1205
ZW
15772 /* Instructions that were new with the real FPA, call them V2. */
15773#undef ARM_VARIANT
e74cfd16 15774#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15775 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15776 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15777 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15778 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15779 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15780 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15781
15782#undef ARM_VARIANT
e74cfd16 15783#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15784 /* Moves and type conversions. */
8f06b2d8
PB
15785 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15786 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15787 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15788 cCE(fmstat, ef1fa10, 0, (), noargs),
15789 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15790 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15791 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15793 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15794 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15795 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15796 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15797
15798 /* Memory operations. */
4962c51a
MS
15799 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15800 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15801 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15802 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15803 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15804 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15805 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15806 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15807 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15808 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15809 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15810 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15811 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15812 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15813 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15814 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15815 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15816 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15817
c19d1205 15818 /* Monadic operations. */
8f06b2d8
PB
15819 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15820 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15821 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15822
15823 /* Dyadic operations. */
8f06b2d8
PB
15824 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15825 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15826 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15827 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15828 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15829 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15830 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15831 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15832 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15833
c19d1205 15834 /* Comparisons. */
8f06b2d8
PB
15835 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15836 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15837 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15838 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15839
c19d1205 15840#undef ARM_VARIANT
e74cfd16 15841#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15842 /* Moves and type conversions. */
5287ad62 15843 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15844 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15845 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15846 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15847 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15848 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15849 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15850 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15851 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15852 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15853 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15854 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15855 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15856
15857 /* Memory operations. */
4962c51a
MS
15858 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15859 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15860 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15861 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15862 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15863 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15864 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15865 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15866 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15867 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15868
c19d1205 15869 /* Monadic operations. */
5287ad62
JB
15870 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15871 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15872 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15873
15874 /* Dyadic operations. */
5287ad62
JB
15875 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15876 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15877 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15878 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15879 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15880 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15881 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15882 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15883 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15884
c19d1205 15885 /* Comparisons. */
5287ad62
JB
15886 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15887 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15888 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15889 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15890
15891#undef ARM_VARIANT
e74cfd16 15892#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15893 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15894 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15895 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15896 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15897
037e8744
JB
15898/* Instructions which may belong to either the Neon or VFP instruction sets.
15899 Individual encoder functions perform additional architecture checks. */
15900#undef ARM_VARIANT
15901#define ARM_VARIANT &fpu_vfp_ext_v1xd
15902#undef THUMB_VARIANT
15903#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15904 /* These mnemonics are unique to VFP. */
15905 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15906 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15907 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15908 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15909 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15910 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15911 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15912 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15913 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15914 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15915
15916 /* Mnemonics shared by Neon and VFP. */
15917 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15918 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15919 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15920
15921 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15922 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15923
15924 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15925 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15926
15927 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15928 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15929 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15930 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15931 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15932 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15933 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15934 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15935
15936 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15937
15938 /* NOTE: All VMOV encoding is special-cased! */
15939 NCE(vmov, 0, 1, (VMOV), neon_mov),
15940 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15941
5287ad62
JB
15942#undef THUMB_VARIANT
15943#define THUMB_VARIANT &fpu_neon_ext_v1
15944#undef ARM_VARIANT
15945#define ARM_VARIANT &fpu_neon_ext_v1
15946 /* Data processing with three registers of the same length. */
15947 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15948 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15949 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15950 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15951 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15952 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15953 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15954 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15955 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15956 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15957 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15958 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15959 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15960 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15961 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15962 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15963 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15964 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15965 /* If not immediate, fall back to neon_dyadic_i64_su.
15966 shl_imm should accept I8 I16 I32 I64,
15967 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15968 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15969 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15970 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15971 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15972 /* Logic ops, types optional & ignored. */
15973 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15974 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15975 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15976 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15977 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15978 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15979 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15980 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15981 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15982 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15983 /* Bitfield ops, untyped. */
15984 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15985 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15986 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15987 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15988 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15989 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15990 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15991 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15992 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15993 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15994 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15995 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15996 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15997 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15998 back to neon_dyadic_if_su. */
15999 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16000 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16001 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16002 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16003 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16004 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16005 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16006 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16007 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16008 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16009 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16010 /* As above, D registers only. */
16011 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16012 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16013 /* Int and float variants, signedness unimportant. */
5287ad62 16014 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16015 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16016 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16017 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16018 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16019 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16020 /* vtst takes sizes 8, 16, 32. */
16021 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16022 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16023 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16024 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16025 /* VQD{R}MULH takes S16 S32. */
16026 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16027 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16028 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16029 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16030 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16031 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16032 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16033 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16034 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16035 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16036 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16037 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16038 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16039 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16040 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16041 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16042
16043 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16044 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16045 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16046
16047 /* Data processing with two registers and a shift amount. */
16048 /* Right shifts, and variants with rounding.
16049 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16050 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16051 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16052 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16053 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16054 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16055 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16056 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16057 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16058 /* Shift and insert. Sizes accepted 8 16 32 64. */
16059 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16060 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16061 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16062 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16063 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16064 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16065 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16066 /* Right shift immediate, saturating & narrowing, with rounding variants.
16067 Types accepted S16 S32 S64 U16 U32 U64. */
16068 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16069 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16070 /* As above, unsigned. Types accepted S16 S32 S64. */
16071 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16072 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16073 /* Right shift narrowing. Types accepted I16 I32 I64. */
16074 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16075 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16076 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16077 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16078 /* CVT with optional immediate for fixed-point variant. */
037e8744 16079 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16080
5287ad62
JB
16081 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16082 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16083
16084 /* Data processing, three registers of different lengths. */
16085 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16086 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16087 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16088 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16089 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16090 /* If not scalar, fall back to neon_dyadic_long.
16091 Vector types as above, scalar types S16 S32 U16 U32. */
16092 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16093 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16094 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16095 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16096 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16097 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16098 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16099 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16100 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16101 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16102 /* Saturating doubling multiplies. Types S16 S32. */
16103 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16104 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16105 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16106 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16107 S16 S32 U16 U32. */
16108 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16109
16110 /* Extract. Size 8. */
3b8d421e
PB
16111 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16112 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16113
16114 /* Two registers, miscellaneous. */
16115 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16116 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16117 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16118 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16119 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16120 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16121 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16122 /* Vector replicate. Sizes 8 16 32. */
16123 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16124 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16125 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16126 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16127 /* VMOVN. Types I16 I32 I64. */
16128 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16129 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16130 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16131 /* VQMOVUN. Types S16 S32 S64. */
16132 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16133 /* VZIP / VUZP. Sizes 8 16 32. */
16134 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16135 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16136 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16137 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16138 /* VQABS / VQNEG. Types S8 S16 S32. */
16139 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16140 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16141 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16142 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16143 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16144 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16145 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16146 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16147 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16148 /* Reciprocal estimates. Types U32 F32. */
16149 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16150 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16151 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16152 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16153 /* VCLS. Types S8 S16 S32. */
16154 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16155 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16156 /* VCLZ. Types I8 I16 I32. */
16157 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16158 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16159 /* VCNT. Size 8. */
16160 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16161 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16162 /* Two address, untyped. */
16163 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16164 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16165 /* VTRN. Sizes 8 16 32. */
16166 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16167 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16168
16169 /* Table lookup. Size 8. */
16170 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16171 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16172
b7fc2769
JB
16173#undef THUMB_VARIANT
16174#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16175#undef ARM_VARIANT
16176#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16177 /* Neon element/structure load/store. */
16178 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16179 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16180 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16181 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16182 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16183 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16184 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16185 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16186
16187#undef THUMB_VARIANT
16188#define THUMB_VARIANT &fpu_vfp_ext_v3
16189#undef ARM_VARIANT
16190#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16191 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16192 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16193 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16194 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16195 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16196 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16197 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16198 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16199 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16200 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16201 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16202 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16203 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16204 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16205 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16206 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16207 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16208 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16209
5287ad62 16210#undef THUMB_VARIANT
c19d1205 16211#undef ARM_VARIANT
e74cfd16 16212#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16213 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16214 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16215 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16216 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16217 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16218 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16219 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16220 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16221
16222#undef ARM_VARIANT
e74cfd16 16223#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16224 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16225 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16226 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16227 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16228 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16229 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16230 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16231 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16232 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16233 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16234 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16235 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16236 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16237 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16238 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16239 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16240 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16241 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16242 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16243 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16244 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16245 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16246 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16247 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16248 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16249 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16250 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16251 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16252 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16253 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16254 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16255 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16256 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16257 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16258 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16259 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16260 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16261 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16269 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16271 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16289 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16290 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16291 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16292 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16293 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16294 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16311 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16313 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16322 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16323 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16324 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16325 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16326 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16327 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16328 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16329 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16330 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16333 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16334 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16335 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16336 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16337 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16338 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16339 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16340 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16341 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16342 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16343 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16344 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16345 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16346 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16347 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16348 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16349 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16350 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16351 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16352 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16353 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16354 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16355 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16356 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16357 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16358 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16359 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16365 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16366 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16367 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16368 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16369 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16370 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16371 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16372 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16374 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16375 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16376 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16377 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16380 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16381 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16384 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16385 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16386
2d447fca
JM
16387#undef ARM_VARIANT
16388#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16389 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16390 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16391 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16392 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16393 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16394 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16395 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16408 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16410 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446
c19d1205 16447#undef ARM_VARIANT
e74cfd16 16448#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16449 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16450 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16451 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16452 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16453 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16454 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16455 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16456 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16457 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16458 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16459 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16460 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16461 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16462 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16463 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16464 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16465 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16466 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16467 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16468 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16469 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16470 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16471 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16472 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16473 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16474 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16475 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16476 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16477 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16478 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16479 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16480 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16481 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16482 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16483 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16484 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16485 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16486 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16487 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16488 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16489 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16490 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16491 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16492 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16493 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16494 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16495 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16496 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16497 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16498 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16499 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16500 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16501 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16502 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16503 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16504 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16505 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16506 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16507 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16508 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16509 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16510 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16511 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16512 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16513 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16514 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16515 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16516 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16517 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16518 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16519 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16520 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16521 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16522 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16523 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16524 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16525};
16526#undef ARM_VARIANT
16527#undef THUMB_VARIANT
16528#undef TCE
16529#undef TCM
16530#undef TUE
16531#undef TUF
16532#undef TCC
8f06b2d8 16533#undef cCE
e3cb604e
PB
16534#undef cCL
16535#undef C3E
c19d1205
ZW
16536#undef CE
16537#undef CM
16538#undef UE
16539#undef UF
16540#undef UT
5287ad62
JB
16541#undef NUF
16542#undef nUF
16543#undef NCE
16544#undef nCE
c19d1205
ZW
16545#undef OPS0
16546#undef OPS1
16547#undef OPS2
16548#undef OPS3
16549#undef OPS4
16550#undef OPS5
16551#undef OPS6
16552#undef do_0
16553\f
16554/* MD interface: bits in the object file. */
bfae80f2 16555
c19d1205
ZW
16556/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16557 for use in the a.out file, and stores them in the array pointed to by buf.
16558 This knows about the endian-ness of the target machine and does
16559 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16560 2 (short) and 4 (long) Floating numbers are put out as a series of
16561 LITTLENUMS (shorts, here at least). */
b99bd4ef 16562
c19d1205
ZW
16563void
16564md_number_to_chars (char * buf, valueT val, int n)
16565{
16566 if (target_big_endian)
16567 number_to_chars_bigendian (buf, val, n);
16568 else
16569 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16570}
16571
c19d1205
ZW
16572static valueT
16573md_chars_to_number (char * buf, int n)
bfae80f2 16574{
c19d1205
ZW
16575 valueT result = 0;
16576 unsigned char * where = (unsigned char *) buf;
bfae80f2 16577
c19d1205 16578 if (target_big_endian)
b99bd4ef 16579 {
c19d1205
ZW
16580 while (n--)
16581 {
16582 result <<= 8;
16583 result |= (*where++ & 255);
16584 }
b99bd4ef 16585 }
c19d1205 16586 else
b99bd4ef 16587 {
c19d1205
ZW
16588 while (n--)
16589 {
16590 result <<= 8;
16591 result |= (where[n] & 255);
16592 }
bfae80f2 16593 }
b99bd4ef 16594
c19d1205 16595 return result;
bfae80f2 16596}
b99bd4ef 16597
c19d1205 16598/* MD interface: Sections. */
b99bd4ef 16599
0110f2b8
PB
16600/* Estimate the size of a frag before relaxing. Assume everything fits in
16601 2 bytes. */
16602
c19d1205 16603int
0110f2b8 16604md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16605 segT segtype ATTRIBUTE_UNUSED)
16606{
0110f2b8
PB
16607 fragp->fr_var = 2;
16608 return 2;
16609}
16610
16611/* Convert a machine dependent frag. */
16612
16613void
16614md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16615{
16616 unsigned long insn;
16617 unsigned long old_op;
16618 char *buf;
16619 expressionS exp;
16620 fixS *fixp;
16621 int reloc_type;
16622 int pc_rel;
16623 int opcode;
16624
16625 buf = fragp->fr_literal + fragp->fr_fix;
16626
16627 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
16628 if (fragp->fr_symbol)
16629 {
0110f2b8
PB
16630 exp.X_op = O_symbol;
16631 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
16632 }
16633 else
16634 {
0110f2b8 16635 exp.X_op = O_constant;
5f4273c7 16636 }
0110f2b8
PB
16637 exp.X_add_number = fragp->fr_offset;
16638 opcode = fragp->fr_subtype;
16639 switch (opcode)
16640 {
16641 case T_MNEM_ldr_pc:
16642 case T_MNEM_ldr_pc2:
16643 case T_MNEM_ldr_sp:
16644 case T_MNEM_str_sp:
16645 case T_MNEM_ldr:
16646 case T_MNEM_ldrb:
16647 case T_MNEM_ldrh:
16648 case T_MNEM_str:
16649 case T_MNEM_strb:
16650 case T_MNEM_strh:
16651 if (fragp->fr_var == 4)
16652 {
5f4273c7 16653 insn = THUMB_OP32 (opcode);
0110f2b8
PB
16654 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16655 {
16656 insn |= (old_op & 0x700) << 4;
16657 }
16658 else
16659 {
16660 insn |= (old_op & 7) << 12;
16661 insn |= (old_op & 0x38) << 13;
16662 }
16663 insn |= 0x00000c00;
16664 put_thumb32_insn (buf, insn);
16665 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16666 }
16667 else
16668 {
16669 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16670 }
16671 pc_rel = (opcode == T_MNEM_ldr_pc2);
16672 break;
16673 case T_MNEM_adr:
16674 if (fragp->fr_var == 4)
16675 {
16676 insn = THUMB_OP32 (opcode);
16677 insn |= (old_op & 0xf0) << 4;
16678 put_thumb32_insn (buf, insn);
16679 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16680 }
16681 else
16682 {
16683 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16684 exp.X_add_number -= 4;
16685 }
16686 pc_rel = 1;
16687 break;
16688 case T_MNEM_mov:
16689 case T_MNEM_movs:
16690 case T_MNEM_cmp:
16691 case T_MNEM_cmn:
16692 if (fragp->fr_var == 4)
16693 {
16694 int r0off = (opcode == T_MNEM_mov
16695 || opcode == T_MNEM_movs) ? 0 : 8;
16696 insn = THUMB_OP32 (opcode);
16697 insn = (insn & 0xe1ffffff) | 0x10000000;
16698 insn |= (old_op & 0x700) << r0off;
16699 put_thumb32_insn (buf, insn);
16700 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16701 }
16702 else
16703 {
16704 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16705 }
16706 pc_rel = 0;
16707 break;
16708 case T_MNEM_b:
16709 if (fragp->fr_var == 4)
16710 {
16711 insn = THUMB_OP32(opcode);
16712 put_thumb32_insn (buf, insn);
16713 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16714 }
16715 else
16716 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16717 pc_rel = 1;
16718 break;
16719 case T_MNEM_bcond:
16720 if (fragp->fr_var == 4)
16721 {
16722 insn = THUMB_OP32(opcode);
16723 insn |= (old_op & 0xf00) << 14;
16724 put_thumb32_insn (buf, insn);
16725 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16726 }
16727 else
16728 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16729 pc_rel = 1;
16730 break;
16731 case T_MNEM_add_sp:
16732 case T_MNEM_add_pc:
16733 case T_MNEM_inc_sp:
16734 case T_MNEM_dec_sp:
16735 if (fragp->fr_var == 4)
16736 {
16737 /* ??? Choose between add and addw. */
16738 insn = THUMB_OP32 (opcode);
16739 insn |= (old_op & 0xf0) << 4;
16740 put_thumb32_insn (buf, insn);
16805f35
PB
16741 if (opcode == T_MNEM_add_pc)
16742 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16743 else
16744 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16745 }
16746 else
16747 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16748 pc_rel = 0;
16749 break;
16750
16751 case T_MNEM_addi:
16752 case T_MNEM_addis:
16753 case T_MNEM_subi:
16754 case T_MNEM_subis:
16755 if (fragp->fr_var == 4)
16756 {
16757 insn = THUMB_OP32 (opcode);
16758 insn |= (old_op & 0xf0) << 4;
16759 insn |= (old_op & 0xf) << 16;
16760 put_thumb32_insn (buf, insn);
16805f35
PB
16761 if (insn & (1 << 20))
16762 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16763 else
16764 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16765 }
16766 else
16767 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16768 pc_rel = 0;
16769 break;
16770 default:
5f4273c7 16771 abort ();
0110f2b8
PB
16772 }
16773 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16774 reloc_type);
16775 fixp->fx_file = fragp->fr_file;
16776 fixp->fx_line = fragp->fr_line;
16777 fragp->fr_fix += fragp->fr_var;
16778}
16779
16780/* Return the size of a relaxable immediate operand instruction.
16781 SHIFT and SIZE specify the form of the allowable immediate. */
16782static int
16783relax_immediate (fragS *fragp, int size, int shift)
16784{
16785 offsetT offset;
16786 offsetT mask;
16787 offsetT low;
16788
16789 /* ??? Should be able to do better than this. */
16790 if (fragp->fr_symbol)
16791 return 4;
16792
16793 low = (1 << shift) - 1;
16794 mask = (1 << (shift + size)) - (1 << shift);
16795 offset = fragp->fr_offset;
16796 /* Force misaligned offsets to 32-bit variant. */
16797 if (offset & low)
5e77afaa 16798 return 4;
0110f2b8
PB
16799 if (offset & ~mask)
16800 return 4;
16801 return 2;
16802}
16803
5e77afaa
PB
16804/* Get the address of a symbol during relaxation. */
16805static addressT
5f4273c7 16806relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
16807{
16808 fragS *sym_frag;
16809 addressT addr;
16810 symbolS *sym;
16811
16812 sym = fragp->fr_symbol;
16813 sym_frag = symbol_get_frag (sym);
16814 know (S_GET_SEGMENT (sym) != absolute_section
16815 || sym_frag == &zero_address_frag);
16816 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16817
16818 /* If frag has yet to be reached on this pass, assume it will
16819 move by STRETCH just as we did. If this is not so, it will
16820 be because some frag between grows, and that will force
16821 another pass. */
16822
16823 if (stretch != 0
16824 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
16825 {
16826 fragS *f;
16827
16828 /* Adjust stretch for any alignment frag. Note that if have
16829 been expanding the earlier code, the symbol may be
16830 defined in what appears to be an earlier frag. FIXME:
16831 This doesn't handle the fr_subtype field, which specifies
16832 a maximum number of bytes to skip when doing an
16833 alignment. */
16834 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16835 {
16836 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16837 {
16838 if (stretch < 0)
16839 stretch = - ((- stretch)
16840 & ~ ((1 << (int) f->fr_offset) - 1));
16841 else
16842 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16843 if (stretch == 0)
16844 break;
16845 }
16846 }
16847 if (f != NULL)
16848 addr += stretch;
16849 }
5e77afaa
PB
16850
16851 return addr;
16852}
16853
0110f2b8
PB
16854/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16855 load. */
16856static int
5e77afaa 16857relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16858{
16859 addressT addr;
16860 offsetT val;
16861
16862 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16863 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16864 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16865 return 4;
16866
5f4273c7 16867 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16868 addr = fragp->fr_address + fragp->fr_fix;
16869 addr = (addr + 4) & ~3;
5e77afaa 16870 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16871 if (val & 3)
5e77afaa 16872 return 4;
0110f2b8
PB
16873 val -= addr;
16874 if (val < 0 || val > 1020)
16875 return 4;
16876 return 2;
16877}
16878
16879/* Return the size of a relaxable add/sub immediate instruction. */
16880static int
16881relax_addsub (fragS *fragp, asection *sec)
16882{
16883 char *buf;
16884 int op;
16885
16886 buf = fragp->fr_literal + fragp->fr_fix;
16887 op = bfd_get_16(sec->owner, buf);
16888 if ((op & 0xf) == ((op >> 4) & 0xf))
16889 return relax_immediate (fragp, 8, 0);
16890 else
16891 return relax_immediate (fragp, 3, 0);
16892}
16893
16894
16895/* Return the size of a relaxable branch instruction. BITS is the
16896 size of the offset field in the narrow instruction. */
16897
16898static int
5e77afaa 16899relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16900{
16901 addressT addr;
16902 offsetT val;
16903 offsetT limit;
16904
16905 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 16906 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
16907 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16908 return 4;
16909
5f4273c7 16910 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
16911 addr = fragp->fr_address + fragp->fr_fix + 4;
16912 val -= addr;
16913
16914 /* Offset is a signed value *2 */
16915 limit = 1 << bits;
16916 if (val >= limit || val < -limit)
16917 return 4;
16918 return 2;
16919}
16920
16921
16922/* Relax a machine dependent frag. This returns the amount by which
16923 the current size of the frag should change. */
16924
16925int
5e77afaa 16926arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16927{
16928 int oldsize;
16929 int newsize;
16930
16931 oldsize = fragp->fr_var;
16932 switch (fragp->fr_subtype)
16933 {
16934 case T_MNEM_ldr_pc2:
5f4273c7 16935 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16936 break;
16937 case T_MNEM_ldr_pc:
16938 case T_MNEM_ldr_sp:
16939 case T_MNEM_str_sp:
5f4273c7 16940 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
16941 break;
16942 case T_MNEM_ldr:
16943 case T_MNEM_str:
5f4273c7 16944 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
16945 break;
16946 case T_MNEM_ldrh:
16947 case T_MNEM_strh:
5f4273c7 16948 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
16949 break;
16950 case T_MNEM_ldrb:
16951 case T_MNEM_strb:
5f4273c7 16952 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
16953 break;
16954 case T_MNEM_adr:
5f4273c7 16955 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
16956 break;
16957 case T_MNEM_mov:
16958 case T_MNEM_movs:
16959 case T_MNEM_cmp:
16960 case T_MNEM_cmn:
5f4273c7 16961 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
16962 break;
16963 case T_MNEM_b:
5f4273c7 16964 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
16965 break;
16966 case T_MNEM_bcond:
5f4273c7 16967 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
16968 break;
16969 case T_MNEM_add_sp:
16970 case T_MNEM_add_pc:
16971 newsize = relax_immediate (fragp, 8, 2);
16972 break;
16973 case T_MNEM_inc_sp:
16974 case T_MNEM_dec_sp:
16975 newsize = relax_immediate (fragp, 7, 2);
16976 break;
16977 case T_MNEM_addi:
16978 case T_MNEM_addis:
16979 case T_MNEM_subi:
16980 case T_MNEM_subis:
16981 newsize = relax_addsub (fragp, sec);
16982 break;
16983 default:
5f4273c7 16984 abort ();
0110f2b8 16985 }
5e77afaa
PB
16986
16987 fragp->fr_var = newsize;
16988 /* Freeze wide instructions that are at or before the same location as
16989 in the previous pass. This avoids infinite loops.
5f4273c7
NC
16990 Don't freeze them unconditionally because targets may be artificially
16991 misaligned by the expansion of preceding frags. */
5e77afaa 16992 if (stretch <= 0 && newsize > 2)
0110f2b8 16993 {
0110f2b8 16994 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 16995 frag_wane (fragp);
0110f2b8 16996 }
5e77afaa 16997
0110f2b8 16998 return newsize - oldsize;
c19d1205 16999}
b99bd4ef 17000
c19d1205 17001/* Round up a section size to the appropriate boundary. */
b99bd4ef 17002
c19d1205
ZW
17003valueT
17004md_section_align (segT segment ATTRIBUTE_UNUSED,
17005 valueT size)
17006{
f0927246
NC
17007#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17008 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17009 {
17010 /* For a.out, force the section size to be aligned. If we don't do
17011 this, BFD will align it for us, but it will not write out the
17012 final bytes of the section. This may be a bug in BFD, but it is
17013 easier to fix it here since that is how the other a.out targets
17014 work. */
17015 int align;
17016
17017 align = bfd_get_section_alignment (stdoutput, segment);
17018 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17019 }
c19d1205 17020#endif
f0927246
NC
17021
17022 return size;
bfae80f2 17023}
b99bd4ef 17024
c19d1205
ZW
17025/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17026 of an rs_align_code fragment. */
17027
17028void
17029arm_handle_align (fragS * fragP)
bfae80f2 17030{
c19d1205
ZW
17031 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17032 static char const thumb_noop[2] = { 0xc0, 0x46 };
17033 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17034 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17035
17036 int bytes, fix, noop_size;
17037 char * p;
17038 const char * noop;
bfae80f2 17039
c19d1205 17040 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17041 return;
17042
c19d1205
ZW
17043 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17044 p = fragP->fr_literal + fragP->fr_fix;
17045 fix = 0;
bfae80f2 17046
c19d1205
ZW
17047 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17048 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17049
c19d1205 17050 if (fragP->tc_frag_data)
a737bd4d 17051 {
c19d1205
ZW
17052 if (target_big_endian)
17053 noop = thumb_bigend_noop;
17054 else
17055 noop = thumb_noop;
17056 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17057 }
17058 else
17059 {
c19d1205
ZW
17060 if (target_big_endian)
17061 noop = arm_bigend_noop;
17062 else
17063 noop = arm_noop;
17064 noop_size = sizeof (arm_noop);
7ed4c4c5 17065 }
a737bd4d 17066
c19d1205 17067 if (bytes & (noop_size - 1))
7ed4c4c5 17068 {
c19d1205
ZW
17069 fix = bytes & (noop_size - 1);
17070 memset (p, 0, fix);
17071 p += fix;
17072 bytes -= fix;
a737bd4d 17073 }
a737bd4d 17074
c19d1205 17075 while (bytes >= noop_size)
a737bd4d 17076 {
c19d1205
ZW
17077 memcpy (p, noop, noop_size);
17078 p += noop_size;
17079 bytes -= noop_size;
17080 fix += noop_size;
a737bd4d
NC
17081 }
17082
c19d1205
ZW
17083 fragP->fr_fix += fix;
17084 fragP->fr_var = noop_size;
a737bd4d
NC
17085}
17086
c19d1205
ZW
17087/* Called from md_do_align. Used to create an alignment
17088 frag in a code section. */
17089
17090void
17091arm_frag_align_code (int n, int max)
bfae80f2 17092{
c19d1205 17093 char * p;
7ed4c4c5 17094
c19d1205
ZW
17095 /* We assume that there will never be a requirement
17096 to support alignments greater than 32 bytes. */
17097 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17098 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17099
c19d1205
ZW
17100 p = frag_var (rs_align_code,
17101 MAX_MEM_FOR_RS_ALIGN_CODE,
17102 1,
17103 (relax_substateT) max,
17104 (symbolS *) NULL,
17105 (offsetT) n,
17106 (char *) NULL);
17107 *p = 0;
17108}
bfae80f2 17109
c19d1205 17110/* Perform target specific initialisation of a frag. */
bfae80f2 17111
c19d1205
ZW
17112void
17113arm_init_frag (fragS * fragP)
17114{
17115 /* Record whether this frag is in an ARM or a THUMB area. */
17116 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17117}
17118
c19d1205
ZW
17119#ifdef OBJ_ELF
17120/* When we change sections we need to issue a new mapping symbol. */
17121
17122void
17123arm_elf_change_section (void)
bfae80f2 17124{
c19d1205
ZW
17125 flagword flags;
17126 segment_info_type *seginfo;
bfae80f2 17127
c19d1205
ZW
17128 /* Link an unlinked unwind index table section to the .text section. */
17129 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17130 && elf_linked_to_section (now_seg) == NULL)
17131 elf_linked_to_section (now_seg) = text_section;
17132
17133 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17134 return;
17135
c19d1205
ZW
17136 flags = bfd_get_section_flags (stdoutput, now_seg);
17137
17138 /* We can ignore sections that only contain debug info. */
17139 if ((flags & SEC_ALLOC) == 0)
17140 return;
bfae80f2 17141
c19d1205
ZW
17142 seginfo = seg_info (now_seg);
17143 mapstate = seginfo->tc_segment_info_data.mapstate;
17144 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17145}
17146
c19d1205
ZW
17147int
17148arm_elf_section_type (const char * str, size_t len)
e45d0630 17149{
c19d1205
ZW
17150 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17151 return SHT_ARM_EXIDX;
e45d0630 17152
c19d1205
ZW
17153 return -1;
17154}
17155\f
17156/* Code to deal with unwinding tables. */
e45d0630 17157
c19d1205 17158static void add_unwind_adjustsp (offsetT);
e45d0630 17159
5f4273c7 17160/* Generate any deferred unwind frame offset. */
e45d0630 17161
bfae80f2 17162static void
c19d1205 17163flush_pending_unwind (void)
bfae80f2 17164{
c19d1205 17165 offsetT offset;
bfae80f2 17166
c19d1205
ZW
17167 offset = unwind.pending_offset;
17168 unwind.pending_offset = 0;
17169 if (offset != 0)
17170 add_unwind_adjustsp (offset);
bfae80f2
RE
17171}
17172
c19d1205
ZW
17173/* Add an opcode to this list for this function. Two-byte opcodes should
17174 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17175 order. */
17176
bfae80f2 17177static void
c19d1205 17178add_unwind_opcode (valueT op, int length)
bfae80f2 17179{
c19d1205
ZW
17180 /* Add any deferred stack adjustment. */
17181 if (unwind.pending_offset)
17182 flush_pending_unwind ();
bfae80f2 17183
c19d1205 17184 unwind.sp_restored = 0;
bfae80f2 17185
c19d1205 17186 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17187 {
c19d1205
ZW
17188 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17189 if (unwind.opcodes)
17190 unwind.opcodes = xrealloc (unwind.opcodes,
17191 unwind.opcode_alloc);
17192 else
17193 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17194 }
c19d1205 17195 while (length > 0)
bfae80f2 17196 {
c19d1205
ZW
17197 length--;
17198 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17199 op >>= 8;
17200 unwind.opcode_count++;
bfae80f2 17201 }
bfae80f2
RE
17202}
17203
c19d1205
ZW
17204/* Add unwind opcodes to adjust the stack pointer. */
17205
bfae80f2 17206static void
c19d1205 17207add_unwind_adjustsp (offsetT offset)
bfae80f2 17208{
c19d1205 17209 valueT op;
bfae80f2 17210
c19d1205 17211 if (offset > 0x200)
bfae80f2 17212 {
c19d1205
ZW
17213 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17214 char bytes[5];
17215 int n;
17216 valueT o;
bfae80f2 17217
c19d1205
ZW
17218 /* Long form: 0xb2, uleb128. */
17219 /* This might not fit in a word so add the individual bytes,
17220 remembering the list is built in reverse order. */
17221 o = (valueT) ((offset - 0x204) >> 2);
17222 if (o == 0)
17223 add_unwind_opcode (0, 1);
bfae80f2 17224
c19d1205
ZW
17225 /* Calculate the uleb128 encoding of the offset. */
17226 n = 0;
17227 while (o)
17228 {
17229 bytes[n] = o & 0x7f;
17230 o >>= 7;
17231 if (o)
17232 bytes[n] |= 0x80;
17233 n++;
17234 }
17235 /* Add the insn. */
17236 for (; n; n--)
17237 add_unwind_opcode (bytes[n - 1], 1);
17238 add_unwind_opcode (0xb2, 1);
17239 }
17240 else if (offset > 0x100)
bfae80f2 17241 {
c19d1205
ZW
17242 /* Two short opcodes. */
17243 add_unwind_opcode (0x3f, 1);
17244 op = (offset - 0x104) >> 2;
17245 add_unwind_opcode (op, 1);
bfae80f2 17246 }
c19d1205
ZW
17247 else if (offset > 0)
17248 {
17249 /* Short opcode. */
17250 op = (offset - 4) >> 2;
17251 add_unwind_opcode (op, 1);
17252 }
17253 else if (offset < 0)
bfae80f2 17254 {
c19d1205
ZW
17255 offset = -offset;
17256 while (offset > 0x100)
bfae80f2 17257 {
c19d1205
ZW
17258 add_unwind_opcode (0x7f, 1);
17259 offset -= 0x100;
bfae80f2 17260 }
c19d1205
ZW
17261 op = ((offset - 4) >> 2) | 0x40;
17262 add_unwind_opcode (op, 1);
bfae80f2 17263 }
bfae80f2
RE
17264}
17265
c19d1205
ZW
17266/* Finish the list of unwind opcodes for this function. */
17267static void
17268finish_unwind_opcodes (void)
bfae80f2 17269{
c19d1205 17270 valueT op;
bfae80f2 17271
c19d1205 17272 if (unwind.fp_used)
bfae80f2 17273 {
708587a4 17274 /* Adjust sp as necessary. */
c19d1205
ZW
17275 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17276 flush_pending_unwind ();
bfae80f2 17277
c19d1205
ZW
17278 /* After restoring sp from the frame pointer. */
17279 op = 0x90 | unwind.fp_reg;
17280 add_unwind_opcode (op, 1);
17281 }
17282 else
17283 flush_pending_unwind ();
bfae80f2
RE
17284}
17285
bfae80f2 17286
c19d1205
ZW
17287/* Start an exception table entry. If idx is nonzero this is an index table
17288 entry. */
bfae80f2
RE
17289
17290static void
c19d1205 17291start_unwind_section (const segT text_seg, int idx)
bfae80f2 17292{
c19d1205
ZW
17293 const char * text_name;
17294 const char * prefix;
17295 const char * prefix_once;
17296 const char * group_name;
17297 size_t prefix_len;
17298 size_t text_len;
17299 char * sec_name;
17300 size_t sec_name_len;
17301 int type;
17302 int flags;
17303 int linkonce;
bfae80f2 17304
c19d1205 17305 if (idx)
bfae80f2 17306 {
c19d1205
ZW
17307 prefix = ELF_STRING_ARM_unwind;
17308 prefix_once = ELF_STRING_ARM_unwind_once;
17309 type = SHT_ARM_EXIDX;
bfae80f2 17310 }
c19d1205 17311 else
bfae80f2 17312 {
c19d1205
ZW
17313 prefix = ELF_STRING_ARM_unwind_info;
17314 prefix_once = ELF_STRING_ARM_unwind_info_once;
17315 type = SHT_PROGBITS;
bfae80f2
RE
17316 }
17317
c19d1205
ZW
17318 text_name = segment_name (text_seg);
17319 if (streq (text_name, ".text"))
17320 text_name = "";
17321
17322 if (strncmp (text_name, ".gnu.linkonce.t.",
17323 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17324 {
c19d1205
ZW
17325 prefix = prefix_once;
17326 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17327 }
17328
c19d1205
ZW
17329 prefix_len = strlen (prefix);
17330 text_len = strlen (text_name);
17331 sec_name_len = prefix_len + text_len;
17332 sec_name = xmalloc (sec_name_len + 1);
17333 memcpy (sec_name, prefix, prefix_len);
17334 memcpy (sec_name + prefix_len, text_name, text_len);
17335 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17336
c19d1205
ZW
17337 flags = SHF_ALLOC;
17338 linkonce = 0;
17339 group_name = 0;
bfae80f2 17340
c19d1205
ZW
17341 /* Handle COMDAT group. */
17342 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17343 {
c19d1205
ZW
17344 group_name = elf_group_name (text_seg);
17345 if (group_name == NULL)
17346 {
bd3ba5d1 17347 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17348 segment_name (text_seg));
17349 ignore_rest_of_line ();
17350 return;
17351 }
17352 flags |= SHF_GROUP;
17353 linkonce = 1;
bfae80f2
RE
17354 }
17355
c19d1205 17356 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17357
5f4273c7 17358 /* Set the section link for index tables. */
c19d1205
ZW
17359 if (idx)
17360 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17361}
17362
bfae80f2 17363
c19d1205
ZW
17364/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17365 personality routine data. Returns zero, or the index table value for
17366 and inline entry. */
17367
17368static valueT
17369create_unwind_entry (int have_data)
bfae80f2 17370{
c19d1205
ZW
17371 int size;
17372 addressT where;
17373 char *ptr;
17374 /* The current word of data. */
17375 valueT data;
17376 /* The number of bytes left in this word. */
17377 int n;
bfae80f2 17378
c19d1205 17379 finish_unwind_opcodes ();
bfae80f2 17380
c19d1205
ZW
17381 /* Remember the current text section. */
17382 unwind.saved_seg = now_seg;
17383 unwind.saved_subseg = now_subseg;
bfae80f2 17384
c19d1205 17385 start_unwind_section (now_seg, 0);
bfae80f2 17386
c19d1205 17387 if (unwind.personality_routine == NULL)
bfae80f2 17388 {
c19d1205
ZW
17389 if (unwind.personality_index == -2)
17390 {
17391 if (have_data)
5f4273c7 17392 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17393 return 1; /* EXIDX_CANTUNWIND. */
17394 }
bfae80f2 17395
c19d1205
ZW
17396 /* Use a default personality routine if none is specified. */
17397 if (unwind.personality_index == -1)
17398 {
17399 if (unwind.opcode_count > 3)
17400 unwind.personality_index = 1;
17401 else
17402 unwind.personality_index = 0;
17403 }
bfae80f2 17404
c19d1205
ZW
17405 /* Space for the personality routine entry. */
17406 if (unwind.personality_index == 0)
17407 {
17408 if (unwind.opcode_count > 3)
17409 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17410
c19d1205
ZW
17411 if (!have_data)
17412 {
17413 /* All the data is inline in the index table. */
17414 data = 0x80;
17415 n = 3;
17416 while (unwind.opcode_count > 0)
17417 {
17418 unwind.opcode_count--;
17419 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17420 n--;
17421 }
bfae80f2 17422
c19d1205
ZW
17423 /* Pad with "finish" opcodes. */
17424 while (n--)
17425 data = (data << 8) | 0xb0;
bfae80f2 17426
c19d1205
ZW
17427 return data;
17428 }
17429 size = 0;
17430 }
17431 else
17432 /* We get two opcodes "free" in the first word. */
17433 size = unwind.opcode_count - 2;
17434 }
17435 else
17436 /* An extra byte is required for the opcode count. */
17437 size = unwind.opcode_count + 1;
bfae80f2 17438
c19d1205
ZW
17439 size = (size + 3) >> 2;
17440 if (size > 0xff)
17441 as_bad (_("too many unwind opcodes"));
bfae80f2 17442
c19d1205
ZW
17443 frag_align (2, 0, 0);
17444 record_alignment (now_seg, 2);
17445 unwind.table_entry = expr_build_dot ();
17446
17447 /* Allocate the table entry. */
17448 ptr = frag_more ((size << 2) + 4);
17449 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17450
c19d1205 17451 switch (unwind.personality_index)
bfae80f2 17452 {
c19d1205
ZW
17453 case -1:
17454 /* ??? Should this be a PLT generating relocation? */
17455 /* Custom personality routine. */
17456 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17457 BFD_RELOC_ARM_PREL31);
bfae80f2 17458
c19d1205
ZW
17459 where += 4;
17460 ptr += 4;
bfae80f2 17461
c19d1205
ZW
17462 /* Set the first byte to the number of additional words. */
17463 data = size - 1;
17464 n = 3;
17465 break;
bfae80f2 17466
c19d1205
ZW
17467 /* ABI defined personality routines. */
17468 case 0:
17469 /* Three opcodes bytes are packed into the first word. */
17470 data = 0x80;
17471 n = 3;
17472 break;
bfae80f2 17473
c19d1205
ZW
17474 case 1:
17475 case 2:
17476 /* The size and first two opcode bytes go in the first word. */
17477 data = ((0x80 + unwind.personality_index) << 8) | size;
17478 n = 2;
17479 break;
bfae80f2 17480
c19d1205
ZW
17481 default:
17482 /* Should never happen. */
17483 abort ();
17484 }
bfae80f2 17485
c19d1205
ZW
17486 /* Pack the opcodes into words (MSB first), reversing the list at the same
17487 time. */
17488 while (unwind.opcode_count > 0)
17489 {
17490 if (n == 0)
17491 {
17492 md_number_to_chars (ptr, data, 4);
17493 ptr += 4;
17494 n = 4;
17495 data = 0;
17496 }
17497 unwind.opcode_count--;
17498 n--;
17499 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17500 }
17501
17502 /* Finish off the last word. */
17503 if (n < 4)
17504 {
17505 /* Pad with "finish" opcodes. */
17506 while (n--)
17507 data = (data << 8) | 0xb0;
17508
17509 md_number_to_chars (ptr, data, 4);
17510 }
17511
17512 if (!have_data)
17513 {
17514 /* Add an empty descriptor if there is no user-specified data. */
17515 ptr = frag_more (4);
17516 md_number_to_chars (ptr, 0, 4);
17517 }
17518
17519 return 0;
bfae80f2
RE
17520}
17521
f0927246
NC
17522
17523/* Initialize the DWARF-2 unwind information for this procedure. */
17524
17525void
17526tc_arm_frame_initial_instructions (void)
17527{
17528 cfi_add_CFA_def_cfa (REG_SP, 0);
17529}
17530#endif /* OBJ_ELF */
17531
c19d1205
ZW
17532/* Convert REGNAME to a DWARF-2 register number. */
17533
17534int
1df69f4f 17535tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17536{
1df69f4f 17537 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17538
17539 if (reg == FAIL)
17540 return -1;
17541
17542 return reg;
bfae80f2
RE
17543}
17544
f0927246 17545#ifdef TE_PE
c19d1205 17546void
f0927246 17547tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17548{
f0927246 17549 expressionS expr;
bfae80f2 17550
f0927246
NC
17551 expr.X_op = O_secrel;
17552 expr.X_add_symbol = symbol;
17553 expr.X_add_number = 0;
17554 emit_expr (&expr, size);
17555}
17556#endif
bfae80f2 17557
c19d1205 17558/* MD interface: Symbol and relocation handling. */
bfae80f2 17559
2fc8bdac
ZW
17560/* Return the address within the segment that a PC-relative fixup is
17561 relative to. For ARM, PC-relative fixups applied to instructions
17562 are generally relative to the location of the fixup plus 8 bytes.
17563 Thumb branches are offset by 4, and Thumb loads relative to PC
17564 require special handling. */
bfae80f2 17565
c19d1205 17566long
2fc8bdac 17567md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17568{
2fc8bdac
ZW
17569 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17570
17571 /* If this is pc-relative and we are going to emit a relocation
17572 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17573 will need. Otherwise we want to use the calculated base.
17574 For WinCE we skip the bias for externals as well, since this
17575 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 17576 if (fixP->fx_pcrel
2fc8bdac 17577 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17578 || (arm_force_relocation (fixP)
17579#ifdef TE_WINCE
17580 && !S_IS_EXTERNAL (fixP->fx_addsy)
17581#endif
17582 )))
2fc8bdac 17583 base = 0;
bfae80f2 17584
c19d1205 17585 switch (fixP->fx_r_type)
bfae80f2 17586 {
2fc8bdac
ZW
17587 /* PC relative addressing on the Thumb is slightly odd as the
17588 bottom two bits of the PC are forced to zero for the
17589 calculation. This happens *after* application of the
17590 pipeline offset. However, Thumb adrl already adjusts for
17591 this, so we need not do it again. */
c19d1205 17592 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17593 return base & ~3;
c19d1205
ZW
17594
17595 case BFD_RELOC_ARM_THUMB_OFFSET:
17596 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17597 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17598 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17599 return (base + 4) & ~3;
c19d1205 17600
2fc8bdac
ZW
17601 /* Thumb branches are simply offset by +4. */
17602 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17603 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17604 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17605 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17606 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17607 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17608 case BFD_RELOC_THUMB_PCREL_BLX:
17609 return base + 4;
bfae80f2 17610
2fc8bdac
ZW
17611 /* ARM mode branches are offset by +8. However, the Windows CE
17612 loader expects the relocation not to take this into account. */
17613 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17614 case BFD_RELOC_ARM_PCREL_CALL:
17615 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17616 case BFD_RELOC_ARM_PCREL_BLX:
17617 case BFD_RELOC_ARM_PLT32:
c19d1205 17618#ifdef TE_WINCE
5f4273c7 17619 /* When handling fixups immediately, because we have already
53baae48
NC
17620 discovered the value of a symbol, or the address of the frag involved
17621 we must account for the offset by +8, as the OS loader will never see the reloc.
17622 see fixup_segment() in write.c
17623 The S_IS_EXTERNAL test handles the case of global symbols.
17624 Those need the calculated base, not just the pipe compensation the linker will need. */
17625 if (fixP->fx_pcrel
17626 && fixP->fx_addsy != NULL
17627 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17628 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17629 return base + 8;
2fc8bdac 17630 return base;
c19d1205 17631#else
2fc8bdac 17632 return base + 8;
c19d1205 17633#endif
2fc8bdac
ZW
17634
17635 /* ARM mode loads relative to PC are also offset by +8. Unlike
17636 branches, the Windows CE loader *does* expect the relocation
17637 to take this into account. */
17638 case BFD_RELOC_ARM_OFFSET_IMM:
17639 case BFD_RELOC_ARM_OFFSET_IMM8:
17640 case BFD_RELOC_ARM_HWLITERAL:
17641 case BFD_RELOC_ARM_LITERAL:
17642 case BFD_RELOC_ARM_CP_OFF_IMM:
17643 return base + 8;
17644
17645
17646 /* Other PC-relative relocations are un-offset. */
17647 default:
17648 return base;
17649 }
bfae80f2
RE
17650}
17651
c19d1205
ZW
17652/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17653 Otherwise we have no need to default values of symbols. */
17654
17655symbolS *
17656md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17657{
c19d1205
ZW
17658#ifdef OBJ_ELF
17659 if (name[0] == '_' && name[1] == 'G'
17660 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17661 {
17662 if (!GOT_symbol)
17663 {
17664 if (symbol_find (name))
bd3ba5d1 17665 as_bad (_("GOT already in the symbol table"));
bfae80f2 17666
c19d1205
ZW
17667 GOT_symbol = symbol_new (name, undefined_section,
17668 (valueT) 0, & zero_address_frag);
17669 }
bfae80f2 17670
c19d1205 17671 return GOT_symbol;
bfae80f2 17672 }
c19d1205 17673#endif
bfae80f2 17674
c19d1205 17675 return 0;
bfae80f2
RE
17676}
17677
55cf6793 17678/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17679 computed as two separate immediate values, added together. We
17680 already know that this value cannot be computed by just one ARM
17681 instruction. */
17682
17683static unsigned int
17684validate_immediate_twopart (unsigned int val,
17685 unsigned int * highpart)
bfae80f2 17686{
c19d1205
ZW
17687 unsigned int a;
17688 unsigned int i;
bfae80f2 17689
c19d1205
ZW
17690 for (i = 0; i < 32; i += 2)
17691 if (((a = rotate_left (val, i)) & 0xff) != 0)
17692 {
17693 if (a & 0xff00)
17694 {
17695 if (a & ~ 0xffff)
17696 continue;
17697 * highpart = (a >> 8) | ((i + 24) << 7);
17698 }
17699 else if (a & 0xff0000)
17700 {
17701 if (a & 0xff000000)
17702 continue;
17703 * highpart = (a >> 16) | ((i + 16) << 7);
17704 }
17705 else
17706 {
17707 assert (a & 0xff000000);
17708 * highpart = (a >> 24) | ((i + 8) << 7);
17709 }
bfae80f2 17710
c19d1205
ZW
17711 return (a & 0xff) | (i << 7);
17712 }
bfae80f2 17713
c19d1205 17714 return FAIL;
bfae80f2
RE
17715}
17716
c19d1205
ZW
17717static int
17718validate_offset_imm (unsigned int val, int hwse)
17719{
17720 if ((hwse && val > 255) || val > 4095)
17721 return FAIL;
17722 return val;
17723}
bfae80f2 17724
55cf6793 17725/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17726 negative immediate constant by altering the instruction. A bit of
17727 a hack really.
17728 MOV <-> MVN
17729 AND <-> BIC
17730 ADC <-> SBC
17731 by inverting the second operand, and
17732 ADD <-> SUB
17733 CMP <-> CMN
17734 by negating the second operand. */
bfae80f2 17735
c19d1205
ZW
17736static int
17737negate_data_op (unsigned long * instruction,
17738 unsigned long value)
bfae80f2 17739{
c19d1205
ZW
17740 int op, new_inst;
17741 unsigned long negated, inverted;
bfae80f2 17742
c19d1205
ZW
17743 negated = encode_arm_immediate (-value);
17744 inverted = encode_arm_immediate (~value);
bfae80f2 17745
c19d1205
ZW
17746 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17747 switch (op)
bfae80f2 17748 {
c19d1205
ZW
17749 /* First negates. */
17750 case OPCODE_SUB: /* ADD <-> SUB */
17751 new_inst = OPCODE_ADD;
17752 value = negated;
17753 break;
bfae80f2 17754
c19d1205
ZW
17755 case OPCODE_ADD:
17756 new_inst = OPCODE_SUB;
17757 value = negated;
17758 break;
bfae80f2 17759
c19d1205
ZW
17760 case OPCODE_CMP: /* CMP <-> CMN */
17761 new_inst = OPCODE_CMN;
17762 value = negated;
17763 break;
bfae80f2 17764
c19d1205
ZW
17765 case OPCODE_CMN:
17766 new_inst = OPCODE_CMP;
17767 value = negated;
17768 break;
bfae80f2 17769
c19d1205
ZW
17770 /* Now Inverted ops. */
17771 case OPCODE_MOV: /* MOV <-> MVN */
17772 new_inst = OPCODE_MVN;
17773 value = inverted;
17774 break;
bfae80f2 17775
c19d1205
ZW
17776 case OPCODE_MVN:
17777 new_inst = OPCODE_MOV;
17778 value = inverted;
17779 break;
bfae80f2 17780
c19d1205
ZW
17781 case OPCODE_AND: /* AND <-> BIC */
17782 new_inst = OPCODE_BIC;
17783 value = inverted;
17784 break;
bfae80f2 17785
c19d1205
ZW
17786 case OPCODE_BIC:
17787 new_inst = OPCODE_AND;
17788 value = inverted;
17789 break;
bfae80f2 17790
c19d1205
ZW
17791 case OPCODE_ADC: /* ADC <-> SBC */
17792 new_inst = OPCODE_SBC;
17793 value = inverted;
17794 break;
bfae80f2 17795
c19d1205
ZW
17796 case OPCODE_SBC:
17797 new_inst = OPCODE_ADC;
17798 value = inverted;
17799 break;
bfae80f2 17800
c19d1205
ZW
17801 /* We cannot do anything. */
17802 default:
17803 return FAIL;
b99bd4ef
NC
17804 }
17805
c19d1205
ZW
17806 if (value == (unsigned) FAIL)
17807 return FAIL;
17808
17809 *instruction &= OPCODE_MASK;
17810 *instruction |= new_inst << DATA_OP_SHIFT;
17811 return value;
b99bd4ef
NC
17812}
17813
ef8d22e6
PB
17814/* Like negate_data_op, but for Thumb-2. */
17815
17816static unsigned int
16dd5e42 17817thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17818{
17819 int op, new_inst;
17820 int rd;
16dd5e42 17821 unsigned int negated, inverted;
ef8d22e6
PB
17822
17823 negated = encode_thumb32_immediate (-value);
17824 inverted = encode_thumb32_immediate (~value);
17825
17826 rd = (*instruction >> 8) & 0xf;
17827 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17828 switch (op)
17829 {
17830 /* ADD <-> SUB. Includes CMP <-> CMN. */
17831 case T2_OPCODE_SUB:
17832 new_inst = T2_OPCODE_ADD;
17833 value = negated;
17834 break;
17835
17836 case T2_OPCODE_ADD:
17837 new_inst = T2_OPCODE_SUB;
17838 value = negated;
17839 break;
17840
17841 /* ORR <-> ORN. Includes MOV <-> MVN. */
17842 case T2_OPCODE_ORR:
17843 new_inst = T2_OPCODE_ORN;
17844 value = inverted;
17845 break;
17846
17847 case T2_OPCODE_ORN:
17848 new_inst = T2_OPCODE_ORR;
17849 value = inverted;
17850 break;
17851
17852 /* AND <-> BIC. TST has no inverted equivalent. */
17853 case T2_OPCODE_AND:
17854 new_inst = T2_OPCODE_BIC;
17855 if (rd == 15)
17856 value = FAIL;
17857 else
17858 value = inverted;
17859 break;
17860
17861 case T2_OPCODE_BIC:
17862 new_inst = T2_OPCODE_AND;
17863 value = inverted;
17864 break;
17865
17866 /* ADC <-> SBC */
17867 case T2_OPCODE_ADC:
17868 new_inst = T2_OPCODE_SBC;
17869 value = inverted;
17870 break;
17871
17872 case T2_OPCODE_SBC:
17873 new_inst = T2_OPCODE_ADC;
17874 value = inverted;
17875 break;
17876
17877 /* We cannot do anything. */
17878 default:
17879 return FAIL;
17880 }
17881
16dd5e42 17882 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17883 return FAIL;
17884
17885 *instruction &= T2_OPCODE_MASK;
17886 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17887 return value;
17888}
17889
8f06b2d8
PB
17890/* Read a 32-bit thumb instruction from buf. */
17891static unsigned long
17892get_thumb32_insn (char * buf)
17893{
17894 unsigned long insn;
17895 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17896 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17897
17898 return insn;
17899}
17900
a8bc6c78
PB
17901
17902/* We usually want to set the low bit on the address of thumb function
17903 symbols. In particular .word foo - . should have the low bit set.
17904 Generic code tries to fold the difference of two symbols to
17905 a constant. Prevent this and force a relocation when the first symbols
17906 is a thumb function. */
17907int
17908arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17909{
17910 if (op == O_subtract
17911 && l->X_op == O_symbol
17912 && r->X_op == O_symbol
17913 && THUMB_IS_FUNC (l->X_add_symbol))
17914 {
17915 l->X_op = O_subtract;
17916 l->X_op_symbol = r->X_add_symbol;
17917 l->X_add_number -= r->X_add_number;
17918 return 1;
17919 }
17920 /* Process as normal. */
17921 return 0;
17922}
17923
c19d1205 17924void
55cf6793 17925md_apply_fix (fixS * fixP,
c19d1205
ZW
17926 valueT * valP,
17927 segT seg)
17928{
17929 offsetT value = * valP;
17930 offsetT newval;
17931 unsigned int newimm;
17932 unsigned long temp;
17933 int sign;
17934 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17935
c19d1205 17936 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17937
c19d1205 17938 /* Note whether this will delete the relocation. */
4962c51a 17939
c19d1205
ZW
17940 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17941 fixP->fx_done = 1;
b99bd4ef 17942
adbaf948 17943 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 17944 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
17945 for emit_reloc. */
17946 value &= 0xffffffff;
17947 value ^= 0x80000000;
5f4273c7 17948 value -= 0x80000000;
adbaf948
ZW
17949
17950 *valP = value;
c19d1205 17951 fixP->fx_addnumber = value;
b99bd4ef 17952
adbaf948
ZW
17953 /* Same treatment for fixP->fx_offset. */
17954 fixP->fx_offset &= 0xffffffff;
17955 fixP->fx_offset ^= 0x80000000;
17956 fixP->fx_offset -= 0x80000000;
17957
c19d1205 17958 switch (fixP->fx_r_type)
b99bd4ef 17959 {
c19d1205
ZW
17960 case BFD_RELOC_NONE:
17961 /* This will need to go in the object file. */
17962 fixP->fx_done = 0;
17963 break;
b99bd4ef 17964
c19d1205
ZW
17965 case BFD_RELOC_ARM_IMMEDIATE:
17966 /* We claim that this fixup has been processed here,
17967 even if in fact we generate an error because we do
17968 not have a reloc for it, so tc_gen_reloc will reject it. */
17969 fixP->fx_done = 1;
b99bd4ef 17970
c19d1205
ZW
17971 if (fixP->fx_addsy
17972 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17973 {
c19d1205
ZW
17974 as_bad_where (fixP->fx_file, fixP->fx_line,
17975 _("undefined symbol %s used as an immediate value"),
17976 S_GET_NAME (fixP->fx_addsy));
17977 break;
b99bd4ef
NC
17978 }
17979
c19d1205
ZW
17980 newimm = encode_arm_immediate (value);
17981 temp = md_chars_to_number (buf, INSN_SIZE);
17982
17983 /* If the instruction will fail, see if we can fix things up by
17984 changing the opcode. */
17985 if (newimm == (unsigned int) FAIL
17986 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17987 {
c19d1205
ZW
17988 as_bad_where (fixP->fx_file, fixP->fx_line,
17989 _("invalid constant (%lx) after fixup"),
17990 (unsigned long) value);
17991 break;
b99bd4ef 17992 }
b99bd4ef 17993
c19d1205
ZW
17994 newimm |= (temp & 0xfffff000);
17995 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17996 break;
b99bd4ef 17997
c19d1205
ZW
17998 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17999 {
18000 unsigned int highpart = 0;
18001 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18002
c19d1205
ZW
18003 newimm = encode_arm_immediate (value);
18004 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18005
c19d1205
ZW
18006 /* If the instruction will fail, see if we can fix things up by
18007 changing the opcode. */
18008 if (newimm == (unsigned int) FAIL
18009 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18010 {
18011 /* No ? OK - try using two ADD instructions to generate
18012 the value. */
18013 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18014
c19d1205
ZW
18015 /* Yes - then make sure that the second instruction is
18016 also an add. */
18017 if (newimm != (unsigned int) FAIL)
18018 newinsn = temp;
18019 /* Still No ? Try using a negated value. */
18020 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18021 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18022 /* Otherwise - give up. */
18023 else
18024 {
18025 as_bad_where (fixP->fx_file, fixP->fx_line,
18026 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18027 (long) value);
18028 break;
18029 }
b99bd4ef 18030
c19d1205
ZW
18031 /* Replace the first operand in the 2nd instruction (which
18032 is the PC) with the destination register. We have
18033 already added in the PC in the first instruction and we
18034 do not want to do it again. */
18035 newinsn &= ~ 0xf0000;
18036 newinsn |= ((newinsn & 0x0f000) << 4);
18037 }
b99bd4ef 18038
c19d1205
ZW
18039 newimm |= (temp & 0xfffff000);
18040 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18041
c19d1205
ZW
18042 highpart |= (newinsn & 0xfffff000);
18043 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18044 }
18045 break;
b99bd4ef 18046
c19d1205 18047 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18048 if (!fixP->fx_done && seg->use_rela_p)
18049 value = 0;
18050
c19d1205
ZW
18051 case BFD_RELOC_ARM_LITERAL:
18052 sign = value >= 0;
b99bd4ef 18053
c19d1205
ZW
18054 if (value < 0)
18055 value = - value;
b99bd4ef 18056
c19d1205 18057 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18058 {
c19d1205
ZW
18059 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18060 as_bad_where (fixP->fx_file, fixP->fx_line,
18061 _("invalid literal constant: pool needs to be closer"));
18062 else
18063 as_bad_where (fixP->fx_file, fixP->fx_line,
18064 _("bad immediate value for offset (%ld)"),
18065 (long) value);
18066 break;
f03698e6
RE
18067 }
18068
c19d1205
ZW
18069 newval = md_chars_to_number (buf, INSN_SIZE);
18070 newval &= 0xff7ff000;
18071 newval |= value | (sign ? INDEX_UP : 0);
18072 md_number_to_chars (buf, newval, INSN_SIZE);
18073 break;
b99bd4ef 18074
c19d1205
ZW
18075 case BFD_RELOC_ARM_OFFSET_IMM8:
18076 case BFD_RELOC_ARM_HWLITERAL:
18077 sign = value >= 0;
b99bd4ef 18078
c19d1205
ZW
18079 if (value < 0)
18080 value = - value;
b99bd4ef 18081
c19d1205 18082 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18083 {
c19d1205
ZW
18084 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18085 as_bad_where (fixP->fx_file, fixP->fx_line,
18086 _("invalid literal constant: pool needs to be closer"));
18087 else
f9d4405b 18088 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18089 (long) value);
18090 break;
b99bd4ef
NC
18091 }
18092
c19d1205
ZW
18093 newval = md_chars_to_number (buf, INSN_SIZE);
18094 newval &= 0xff7ff0f0;
18095 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18096 md_number_to_chars (buf, newval, INSN_SIZE);
18097 break;
b99bd4ef 18098
c19d1205
ZW
18099 case BFD_RELOC_ARM_T32_OFFSET_U8:
18100 if (value < 0 || value > 1020 || value % 4 != 0)
18101 as_bad_where (fixP->fx_file, fixP->fx_line,
18102 _("bad immediate value for offset (%ld)"), (long) value);
18103 value /= 4;
b99bd4ef 18104
c19d1205 18105 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18106 newval |= value;
18107 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18108 break;
b99bd4ef 18109
c19d1205
ZW
18110 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18111 /* This is a complicated relocation used for all varieties of Thumb32
18112 load/store instruction with immediate offset:
18113
18114 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18115 *4, optional writeback(W)
18116 (doubleword load/store)
18117
18118 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18119 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18120 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18121 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18122 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18123
18124 Uppercase letters indicate bits that are already encoded at
18125 this point. Lowercase letters are our problem. For the
18126 second block of instructions, the secondary opcode nybble
18127 (bits 8..11) is present, and bit 23 is zero, even if this is
18128 a PC-relative operation. */
18129 newval = md_chars_to_number (buf, THUMB_SIZE);
18130 newval <<= 16;
18131 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18132
c19d1205 18133 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18134 {
c19d1205
ZW
18135 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18136 if (value >= 0)
18137 newval |= (1 << 23);
18138 else
18139 value = -value;
18140 if (value % 4 != 0)
18141 {
18142 as_bad_where (fixP->fx_file, fixP->fx_line,
18143 _("offset not a multiple of 4"));
18144 break;
18145 }
18146 value /= 4;
216d22bc 18147 if (value > 0xff)
c19d1205
ZW
18148 {
18149 as_bad_where (fixP->fx_file, fixP->fx_line,
18150 _("offset out of range"));
18151 break;
18152 }
18153 newval &= ~0xff;
b99bd4ef 18154 }
c19d1205 18155 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18156 {
c19d1205
ZW
18157 /* PC-relative, 12-bit offset. */
18158 if (value >= 0)
18159 newval |= (1 << 23);
18160 else
18161 value = -value;
216d22bc 18162 if (value > 0xfff)
c19d1205
ZW
18163 {
18164 as_bad_where (fixP->fx_file, fixP->fx_line,
18165 _("offset out of range"));
18166 break;
18167 }
18168 newval &= ~0xfff;
b99bd4ef 18169 }
c19d1205 18170 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18171 {
c19d1205
ZW
18172 /* Writeback: 8-bit, +/- offset. */
18173 if (value >= 0)
18174 newval |= (1 << 9);
18175 else
18176 value = -value;
216d22bc 18177 if (value > 0xff)
c19d1205
ZW
18178 {
18179 as_bad_where (fixP->fx_file, fixP->fx_line,
18180 _("offset out of range"));
18181 break;
18182 }
18183 newval &= ~0xff;
b99bd4ef 18184 }
c19d1205 18185 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18186 {
c19d1205 18187 /* T-instruction: positive 8-bit offset. */
216d22bc 18188 if (value < 0 || value > 0xff)
b99bd4ef 18189 {
c19d1205
ZW
18190 as_bad_where (fixP->fx_file, fixP->fx_line,
18191 _("offset out of range"));
18192 break;
b99bd4ef 18193 }
c19d1205
ZW
18194 newval &= ~0xff;
18195 newval |= value;
b99bd4ef
NC
18196 }
18197 else
b99bd4ef 18198 {
c19d1205
ZW
18199 /* Positive 12-bit or negative 8-bit offset. */
18200 int limit;
18201 if (value >= 0)
b99bd4ef 18202 {
c19d1205
ZW
18203 newval |= (1 << 23);
18204 limit = 0xfff;
18205 }
18206 else
18207 {
18208 value = -value;
18209 limit = 0xff;
18210 }
18211 if (value > limit)
18212 {
18213 as_bad_where (fixP->fx_file, fixP->fx_line,
18214 _("offset out of range"));
18215 break;
b99bd4ef 18216 }
c19d1205 18217 newval &= ~limit;
b99bd4ef 18218 }
b99bd4ef 18219
c19d1205
ZW
18220 newval |= value;
18221 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18222 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18223 break;
404ff6b5 18224
c19d1205
ZW
18225 case BFD_RELOC_ARM_SHIFT_IMM:
18226 newval = md_chars_to_number (buf, INSN_SIZE);
18227 if (((unsigned long) value) > 32
18228 || (value == 32
18229 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18230 {
18231 as_bad_where (fixP->fx_file, fixP->fx_line,
18232 _("shift expression is too large"));
18233 break;
18234 }
404ff6b5 18235
c19d1205
ZW
18236 if (value == 0)
18237 /* Shifts of zero must be done as lsl. */
18238 newval &= ~0x60;
18239 else if (value == 32)
18240 value = 0;
18241 newval &= 0xfffff07f;
18242 newval |= (value & 0x1f) << 7;
18243 md_number_to_chars (buf, newval, INSN_SIZE);
18244 break;
404ff6b5 18245
c19d1205 18246 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18247 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18248 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18249 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18250 /* We claim that this fixup has been processed here,
18251 even if in fact we generate an error because we do
18252 not have a reloc for it, so tc_gen_reloc will reject it. */
18253 fixP->fx_done = 1;
404ff6b5 18254
c19d1205
ZW
18255 if (fixP->fx_addsy
18256 && ! S_IS_DEFINED (fixP->fx_addsy))
18257 {
18258 as_bad_where (fixP->fx_file, fixP->fx_line,
18259 _("undefined symbol %s used as an immediate value"),
18260 S_GET_NAME (fixP->fx_addsy));
18261 break;
18262 }
404ff6b5 18263
c19d1205
ZW
18264 newval = md_chars_to_number (buf, THUMB_SIZE);
18265 newval <<= 16;
18266 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18267
16805f35
PB
18268 newimm = FAIL;
18269 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18270 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18271 {
18272 newimm = encode_thumb32_immediate (value);
18273 if (newimm == (unsigned int) FAIL)
18274 newimm = thumb32_negate_data_op (&newval, value);
18275 }
16805f35
PB
18276 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18277 && newimm == (unsigned int) FAIL)
92e90b6e 18278 {
16805f35
PB
18279 /* Turn add/sum into addw/subw. */
18280 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18281 newval = (newval & 0xfeffffff) | 0x02000000;
18282
e9f89963
PB
18283 /* 12 bit immediate for addw/subw. */
18284 if (value < 0)
18285 {
18286 value = -value;
18287 newval ^= 0x00a00000;
18288 }
92e90b6e
PB
18289 if (value > 0xfff)
18290 newimm = (unsigned int) FAIL;
18291 else
18292 newimm = value;
18293 }
cc8a6dd0 18294
c19d1205 18295 if (newimm == (unsigned int)FAIL)
3631a3c8 18296 {
c19d1205
ZW
18297 as_bad_where (fixP->fx_file, fixP->fx_line,
18298 _("invalid constant (%lx) after fixup"),
18299 (unsigned long) value);
18300 break;
3631a3c8
NC
18301 }
18302
c19d1205
ZW
18303 newval |= (newimm & 0x800) << 15;
18304 newval |= (newimm & 0x700) << 4;
18305 newval |= (newimm & 0x0ff);
cc8a6dd0 18306
c19d1205
ZW
18307 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18308 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18309 break;
a737bd4d 18310
3eb17e6b 18311 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18312 if (((unsigned long) value) > 0xffff)
18313 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18314 _("invalid smc expression"));
2fc8bdac 18315 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18316 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18317 md_number_to_chars (buf, newval, INSN_SIZE);
18318 break;
a737bd4d 18319
c19d1205 18320 case BFD_RELOC_ARM_SWI:
adbaf948 18321 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18322 {
18323 if (((unsigned long) value) > 0xff)
18324 as_bad_where (fixP->fx_file, fixP->fx_line,
18325 _("invalid swi expression"));
2fc8bdac 18326 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18327 newval |= value;
18328 md_number_to_chars (buf, newval, THUMB_SIZE);
18329 }
18330 else
18331 {
18332 if (((unsigned long) value) > 0x00ffffff)
18333 as_bad_where (fixP->fx_file, fixP->fx_line,
18334 _("invalid swi expression"));
2fc8bdac 18335 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18336 newval |= value;
18337 md_number_to_chars (buf, newval, INSN_SIZE);
18338 }
18339 break;
a737bd4d 18340
c19d1205
ZW
18341 case BFD_RELOC_ARM_MULTI:
18342 if (((unsigned long) value) > 0xffff)
18343 as_bad_where (fixP->fx_file, fixP->fx_line,
18344 _("invalid expression in load/store multiple"));
18345 newval = value | md_chars_to_number (buf, INSN_SIZE);
18346 md_number_to_chars (buf, newval, INSN_SIZE);
18347 break;
a737bd4d 18348
c19d1205 18349#ifdef OBJ_ELF
39b41c9c
PB
18350 case BFD_RELOC_ARM_PCREL_CALL:
18351 newval = md_chars_to_number (buf, INSN_SIZE);
18352 if ((newval & 0xf0000000) == 0xf0000000)
18353 temp = 1;
18354 else
18355 temp = 3;
18356 goto arm_branch_common;
18357
18358 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18359 case BFD_RELOC_ARM_PLT32:
c19d1205 18360#endif
39b41c9c
PB
18361 case BFD_RELOC_ARM_PCREL_BRANCH:
18362 temp = 3;
18363 goto arm_branch_common;
a737bd4d 18364
39b41c9c
PB
18365 case BFD_RELOC_ARM_PCREL_BLX:
18366 temp = 1;
18367 arm_branch_common:
c19d1205 18368 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18369 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18370 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18371 also be be clear. */
18372 if (value & temp)
c19d1205 18373 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18374 _("misaligned branch destination"));
18375 if ((value & (offsetT)0xfe000000) != (offsetT)0
18376 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18377 as_bad_where (fixP->fx_file, fixP->fx_line,
18378 _("branch out of range"));
a737bd4d 18379
2fc8bdac 18380 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18381 {
2fc8bdac
ZW
18382 newval = md_chars_to_number (buf, INSN_SIZE);
18383 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18384 /* Set the H bit on BLX instructions. */
18385 if (temp == 1)
18386 {
18387 if (value & 2)
18388 newval |= 0x01000000;
18389 else
18390 newval &= ~0x01000000;
18391 }
2fc8bdac 18392 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18393 }
c19d1205 18394 break;
a737bd4d 18395
25fe350b
MS
18396 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18397 /* CBZ can only branch forward. */
a737bd4d 18398
738755b0
MS
18399 /* Attempts to use CBZ to branch to the next instruction
18400 (which, strictly speaking, are prohibited) will be turned into
18401 no-ops.
18402
18403 FIXME: It may be better to remove the instruction completely and
18404 perform relaxation. */
18405 if (value == -2)
2fc8bdac
ZW
18406 {
18407 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18408 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18409 md_number_to_chars (buf, newval, THUMB_SIZE);
18410 }
738755b0
MS
18411 else
18412 {
18413 if (value & ~0x7e)
18414 as_bad_where (fixP->fx_file, fixP->fx_line,
18415 _("branch out of range"));
18416
18417 if (fixP->fx_done || !seg->use_rela_p)
18418 {
18419 newval = md_chars_to_number (buf, THUMB_SIZE);
18420 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18421 md_number_to_chars (buf, newval, THUMB_SIZE);
18422 }
18423 }
c19d1205 18424 break;
a737bd4d 18425
c19d1205 18426 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18427 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18428 as_bad_where (fixP->fx_file, fixP->fx_line,
18429 _("branch out of range"));
a737bd4d 18430
2fc8bdac
ZW
18431 if (fixP->fx_done || !seg->use_rela_p)
18432 {
18433 newval = md_chars_to_number (buf, THUMB_SIZE);
18434 newval |= (value & 0x1ff) >> 1;
18435 md_number_to_chars (buf, newval, THUMB_SIZE);
18436 }
c19d1205 18437 break;
a737bd4d 18438
c19d1205 18439 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18440 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18441 as_bad_where (fixP->fx_file, fixP->fx_line,
18442 _("branch out of range"));
a737bd4d 18443
2fc8bdac
ZW
18444 if (fixP->fx_done || !seg->use_rela_p)
18445 {
18446 newval = md_chars_to_number (buf, THUMB_SIZE);
18447 newval |= (value & 0xfff) >> 1;
18448 md_number_to_chars (buf, newval, THUMB_SIZE);
18449 }
c19d1205 18450 break;
a737bd4d 18451
c19d1205 18452 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18453 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18454 as_bad_where (fixP->fx_file, fixP->fx_line,
18455 _("conditional branch out of range"));
404ff6b5 18456
2fc8bdac
ZW
18457 if (fixP->fx_done || !seg->use_rela_p)
18458 {
18459 offsetT newval2;
18460 addressT S, J1, J2, lo, hi;
404ff6b5 18461
2fc8bdac
ZW
18462 S = (value & 0x00100000) >> 20;
18463 J2 = (value & 0x00080000) >> 19;
18464 J1 = (value & 0x00040000) >> 18;
18465 hi = (value & 0x0003f000) >> 12;
18466 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18467
2fc8bdac
ZW
18468 newval = md_chars_to_number (buf, THUMB_SIZE);
18469 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18470 newval |= (S << 10) | hi;
18471 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18472 md_number_to_chars (buf, newval, THUMB_SIZE);
18473 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18474 }
c19d1205 18475 break;
6c43fab6 18476
c19d1205
ZW
18477 case BFD_RELOC_THUMB_PCREL_BLX:
18478 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18479 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18480 as_bad_where (fixP->fx_file, fixP->fx_line,
18481 _("branch out of range"));
404ff6b5 18482
2fc8bdac
ZW
18483 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18484 /* For a BLX instruction, make sure that the relocation is rounded up
18485 to a word boundary. This follows the semantics of the instruction
18486 which specifies that bit 1 of the target address will come from bit
18487 1 of the base address. */
18488 value = (value + 1) & ~ 1;
404ff6b5 18489
2fc8bdac 18490 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18491 {
2fc8bdac
ZW
18492 offsetT newval2;
18493
18494 newval = md_chars_to_number (buf, THUMB_SIZE);
18495 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18496 newval |= (value & 0x7fffff) >> 12;
18497 newval2 |= (value & 0xfff) >> 1;
18498 md_number_to_chars (buf, newval, THUMB_SIZE);
18499 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18500 }
c19d1205 18501 break;
404ff6b5 18502
c19d1205 18503 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18504 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18505 as_bad_where (fixP->fx_file, fixP->fx_line,
18506 _("branch out of range"));
6c43fab6 18507
2fc8bdac
ZW
18508 if (fixP->fx_done || !seg->use_rela_p)
18509 {
18510 offsetT newval2;
18511 addressT S, I1, I2, lo, hi;
6c43fab6 18512
2fc8bdac
ZW
18513 S = (value & 0x01000000) >> 24;
18514 I1 = (value & 0x00800000) >> 23;
18515 I2 = (value & 0x00400000) >> 22;
18516 hi = (value & 0x003ff000) >> 12;
18517 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18518
2fc8bdac
ZW
18519 I1 = !(I1 ^ S);
18520 I2 = !(I2 ^ S);
a737bd4d 18521
2fc8bdac
ZW
18522 newval = md_chars_to_number (buf, THUMB_SIZE);
18523 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18524 newval |= (S << 10) | hi;
18525 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18526 md_number_to_chars (buf, newval, THUMB_SIZE);
18527 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18528 }
18529 break;
a737bd4d 18530
2fc8bdac
ZW
18531 case BFD_RELOC_8:
18532 if (fixP->fx_done || !seg->use_rela_p)
18533 md_number_to_chars (buf, value, 1);
c19d1205 18534 break;
a737bd4d 18535
c19d1205 18536 case BFD_RELOC_16:
2fc8bdac 18537 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18538 md_number_to_chars (buf, value, 2);
c19d1205 18539 break;
a737bd4d 18540
c19d1205
ZW
18541#ifdef OBJ_ELF
18542 case BFD_RELOC_ARM_TLS_GD32:
18543 case BFD_RELOC_ARM_TLS_LE32:
18544 case BFD_RELOC_ARM_TLS_IE32:
18545 case BFD_RELOC_ARM_TLS_LDM32:
18546 case BFD_RELOC_ARM_TLS_LDO32:
18547 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18548 /* fall through */
6c43fab6 18549
c19d1205
ZW
18550 case BFD_RELOC_ARM_GOT32:
18551 case BFD_RELOC_ARM_GOTOFF:
18552 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18553 if (fixP->fx_done || !seg->use_rela_p)
18554 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18555 break;
18556#endif
6c43fab6 18557
c19d1205
ZW
18558 case BFD_RELOC_RVA:
18559 case BFD_RELOC_32:
18560 case BFD_RELOC_ARM_TARGET1:
18561 case BFD_RELOC_ARM_ROSEGREL32:
18562 case BFD_RELOC_ARM_SBREL32:
18563 case BFD_RELOC_32_PCREL:
f0927246
NC
18564#ifdef TE_PE
18565 case BFD_RELOC_32_SECREL:
18566#endif
2fc8bdac 18567 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18568#ifdef TE_WINCE
18569 /* For WinCE we only do this for pcrel fixups. */
18570 if (fixP->fx_done || fixP->fx_pcrel)
18571#endif
18572 md_number_to_chars (buf, value, 4);
c19d1205 18573 break;
6c43fab6 18574
c19d1205
ZW
18575#ifdef OBJ_ELF
18576 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18577 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18578 {
18579 newval = md_chars_to_number (buf, 4) & 0x80000000;
18580 if ((value ^ (value >> 1)) & 0x40000000)
18581 {
18582 as_bad_where (fixP->fx_file, fixP->fx_line,
18583 _("rel31 relocation overflow"));
18584 }
18585 newval |= value & 0x7fffffff;
18586 md_number_to_chars (buf, newval, 4);
18587 }
18588 break;
c19d1205 18589#endif
a737bd4d 18590
c19d1205 18591 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18592 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18593 if (value < -1023 || value > 1023 || (value & 3))
18594 as_bad_where (fixP->fx_file, fixP->fx_line,
18595 _("co-processor offset out of range"));
18596 cp_off_common:
18597 sign = value >= 0;
18598 if (value < 0)
18599 value = -value;
8f06b2d8
PB
18600 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18601 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18602 newval = md_chars_to_number (buf, INSN_SIZE);
18603 else
18604 newval = get_thumb32_insn (buf);
18605 newval &= 0xff7fff00;
c19d1205 18606 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18607 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18608 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18609 md_number_to_chars (buf, newval, INSN_SIZE);
18610 else
18611 put_thumb32_insn (buf, newval);
c19d1205 18612 break;
a737bd4d 18613
c19d1205 18614 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18615 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18616 if (value < -255 || value > 255)
18617 as_bad_where (fixP->fx_file, fixP->fx_line,
18618 _("co-processor offset out of range"));
df7849c5 18619 value *= 4;
c19d1205 18620 goto cp_off_common;
6c43fab6 18621
c19d1205
ZW
18622 case BFD_RELOC_ARM_THUMB_OFFSET:
18623 newval = md_chars_to_number (buf, THUMB_SIZE);
18624 /* Exactly what ranges, and where the offset is inserted depends
18625 on the type of instruction, we can establish this from the
18626 top 4 bits. */
18627 switch (newval >> 12)
18628 {
18629 case 4: /* PC load. */
18630 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18631 forced to zero for these loads; md_pcrel_from has already
18632 compensated for this. */
18633 if (value & 3)
18634 as_bad_where (fixP->fx_file, fixP->fx_line,
18635 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18636 (((unsigned long) fixP->fx_frag->fr_address
18637 + (unsigned long) fixP->fx_where) & ~3)
18638 + (unsigned long) value);
a737bd4d 18639
c19d1205
ZW
18640 if (value & ~0x3fc)
18641 as_bad_where (fixP->fx_file, fixP->fx_line,
18642 _("invalid offset, value too big (0x%08lX)"),
18643 (long) value);
a737bd4d 18644
c19d1205
ZW
18645 newval |= value >> 2;
18646 break;
a737bd4d 18647
c19d1205
ZW
18648 case 9: /* SP load/store. */
18649 if (value & ~0x3fc)
18650 as_bad_where (fixP->fx_file, fixP->fx_line,
18651 _("invalid offset, value too big (0x%08lX)"),
18652 (long) value);
18653 newval |= value >> 2;
18654 break;
6c43fab6 18655
c19d1205
ZW
18656 case 6: /* Word load/store. */
18657 if (value & ~0x7c)
18658 as_bad_where (fixP->fx_file, fixP->fx_line,
18659 _("invalid offset, value too big (0x%08lX)"),
18660 (long) value);
18661 newval |= value << 4; /* 6 - 2. */
18662 break;
a737bd4d 18663
c19d1205
ZW
18664 case 7: /* Byte load/store. */
18665 if (value & ~0x1f)
18666 as_bad_where (fixP->fx_file, fixP->fx_line,
18667 _("invalid offset, value too big (0x%08lX)"),
18668 (long) value);
18669 newval |= value << 6;
18670 break;
a737bd4d 18671
c19d1205
ZW
18672 case 8: /* Halfword load/store. */
18673 if (value & ~0x3e)
18674 as_bad_where (fixP->fx_file, fixP->fx_line,
18675 _("invalid offset, value too big (0x%08lX)"),
18676 (long) value);
18677 newval |= value << 5; /* 6 - 1. */
18678 break;
a737bd4d 18679
c19d1205
ZW
18680 default:
18681 as_bad_where (fixP->fx_file, fixP->fx_line,
18682 "Unable to process relocation for thumb opcode: %lx",
18683 (unsigned long) newval);
18684 break;
18685 }
18686 md_number_to_chars (buf, newval, THUMB_SIZE);
18687 break;
a737bd4d 18688
c19d1205
ZW
18689 case BFD_RELOC_ARM_THUMB_ADD:
18690 /* This is a complicated relocation, since we use it for all of
18691 the following immediate relocations:
a737bd4d 18692
c19d1205
ZW
18693 3bit ADD/SUB
18694 8bit ADD/SUB
18695 9bit ADD/SUB SP word-aligned
18696 10bit ADD PC/SP word-aligned
a737bd4d 18697
c19d1205
ZW
18698 The type of instruction being processed is encoded in the
18699 instruction field:
a737bd4d 18700
c19d1205
ZW
18701 0x8000 SUB
18702 0x00F0 Rd
18703 0x000F Rs
18704 */
18705 newval = md_chars_to_number (buf, THUMB_SIZE);
18706 {
18707 int rd = (newval >> 4) & 0xf;
18708 int rs = newval & 0xf;
18709 int subtract = !!(newval & 0x8000);
a737bd4d 18710
c19d1205
ZW
18711 /* Check for HI regs, only very restricted cases allowed:
18712 Adjusting SP, and using PC or SP to get an address. */
18713 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18714 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18715 as_bad_where (fixP->fx_file, fixP->fx_line,
18716 _("invalid Hi register with immediate"));
a737bd4d 18717
c19d1205
ZW
18718 /* If value is negative, choose the opposite instruction. */
18719 if (value < 0)
18720 {
18721 value = -value;
18722 subtract = !subtract;
18723 if (value < 0)
18724 as_bad_where (fixP->fx_file, fixP->fx_line,
18725 _("immediate value out of range"));
18726 }
a737bd4d 18727
c19d1205
ZW
18728 if (rd == REG_SP)
18729 {
18730 if (value & ~0x1fc)
18731 as_bad_where (fixP->fx_file, fixP->fx_line,
18732 _("invalid immediate for stack address calculation"));
18733 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18734 newval |= value >> 2;
18735 }
18736 else if (rs == REG_PC || rs == REG_SP)
18737 {
18738 if (subtract || value & ~0x3fc)
18739 as_bad_where (fixP->fx_file, fixP->fx_line,
18740 _("invalid immediate for address calculation (value = 0x%08lX)"),
18741 (unsigned long) value);
18742 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18743 newval |= rd << 8;
18744 newval |= value >> 2;
18745 }
18746 else if (rs == rd)
18747 {
18748 if (value & ~0xff)
18749 as_bad_where (fixP->fx_file, fixP->fx_line,
18750 _("immediate value out of range"));
18751 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18752 newval |= (rd << 8) | value;
18753 }
18754 else
18755 {
18756 if (value & ~0x7)
18757 as_bad_where (fixP->fx_file, fixP->fx_line,
18758 _("immediate value out of range"));
18759 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18760 newval |= rd | (rs << 3) | (value << 6);
18761 }
18762 }
18763 md_number_to_chars (buf, newval, THUMB_SIZE);
18764 break;
a737bd4d 18765
c19d1205
ZW
18766 case BFD_RELOC_ARM_THUMB_IMM:
18767 newval = md_chars_to_number (buf, THUMB_SIZE);
18768 if (value < 0 || value > 255)
18769 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 18770 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
18771 (long) value);
18772 newval |= value;
18773 md_number_to_chars (buf, newval, THUMB_SIZE);
18774 break;
a737bd4d 18775
c19d1205
ZW
18776 case BFD_RELOC_ARM_THUMB_SHIFT:
18777 /* 5bit shift value (0..32). LSL cannot take 32. */
18778 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18779 temp = newval & 0xf800;
18780 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18781 as_bad_where (fixP->fx_file, fixP->fx_line,
18782 _("invalid shift value: %ld"), (long) value);
18783 /* Shifts of zero must be encoded as LSL. */
18784 if (value == 0)
18785 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18786 /* Shifts of 32 are encoded as zero. */
18787 else if (value == 32)
18788 value = 0;
18789 newval |= value << 6;
18790 md_number_to_chars (buf, newval, THUMB_SIZE);
18791 break;
a737bd4d 18792
c19d1205
ZW
18793 case BFD_RELOC_VTABLE_INHERIT:
18794 case BFD_RELOC_VTABLE_ENTRY:
18795 fixP->fx_done = 0;
18796 return;
6c43fab6 18797
b6895b4f
PB
18798 case BFD_RELOC_ARM_MOVW:
18799 case BFD_RELOC_ARM_MOVT:
18800 case BFD_RELOC_ARM_THUMB_MOVW:
18801 case BFD_RELOC_ARM_THUMB_MOVT:
18802 if (fixP->fx_done || !seg->use_rela_p)
18803 {
18804 /* REL format relocations are limited to a 16-bit addend. */
18805 if (!fixP->fx_done)
18806 {
39623e12 18807 if (value < -0x8000 || value > 0x7fff)
b6895b4f 18808 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 18809 _("offset out of range"));
b6895b4f
PB
18810 }
18811 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18812 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18813 {
18814 value >>= 16;
18815 }
18816
18817 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18818 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18819 {
18820 newval = get_thumb32_insn (buf);
18821 newval &= 0xfbf08f00;
18822 newval |= (value & 0xf000) << 4;
18823 newval |= (value & 0x0800) << 15;
18824 newval |= (value & 0x0700) << 4;
18825 newval |= (value & 0x00ff);
18826 put_thumb32_insn (buf, newval);
18827 }
18828 else
18829 {
18830 newval = md_chars_to_number (buf, 4);
18831 newval &= 0xfff0f000;
18832 newval |= value & 0x0fff;
18833 newval |= (value & 0xf000) << 4;
18834 md_number_to_chars (buf, newval, 4);
18835 }
18836 }
18837 return;
18838
4962c51a
MS
18839 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18840 case BFD_RELOC_ARM_ALU_PC_G0:
18841 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18842 case BFD_RELOC_ARM_ALU_PC_G1:
18843 case BFD_RELOC_ARM_ALU_PC_G2:
18844 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18845 case BFD_RELOC_ARM_ALU_SB_G0:
18846 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18847 case BFD_RELOC_ARM_ALU_SB_G1:
18848 case BFD_RELOC_ARM_ALU_SB_G2:
18849 assert (!fixP->fx_done);
18850 if (!seg->use_rela_p)
18851 {
18852 bfd_vma insn;
18853 bfd_vma encoded_addend;
18854 bfd_vma addend_abs = abs (value);
18855
18856 /* Check that the absolute value of the addend can be
18857 expressed as an 8-bit constant plus a rotation. */
18858 encoded_addend = encode_arm_immediate (addend_abs);
18859 if (encoded_addend == (unsigned int) FAIL)
18860 as_bad_where (fixP->fx_file, fixP->fx_line,
18861 _("the offset 0x%08lX is not representable"),
495bde8e 18862 (unsigned long) addend_abs);
4962c51a
MS
18863
18864 /* Extract the instruction. */
18865 insn = md_chars_to_number (buf, INSN_SIZE);
18866
18867 /* If the addend is positive, use an ADD instruction.
18868 Otherwise use a SUB. Take care not to destroy the S bit. */
18869 insn &= 0xff1fffff;
18870 if (value < 0)
18871 insn |= 1 << 22;
18872 else
18873 insn |= 1 << 23;
18874
18875 /* Place the encoded addend into the first 12 bits of the
18876 instruction. */
18877 insn &= 0xfffff000;
18878 insn |= encoded_addend;
5f4273c7
NC
18879
18880 /* Update the instruction. */
4962c51a
MS
18881 md_number_to_chars (buf, insn, INSN_SIZE);
18882 }
18883 break;
18884
18885 case BFD_RELOC_ARM_LDR_PC_G0:
18886 case BFD_RELOC_ARM_LDR_PC_G1:
18887 case BFD_RELOC_ARM_LDR_PC_G2:
18888 case BFD_RELOC_ARM_LDR_SB_G0:
18889 case BFD_RELOC_ARM_LDR_SB_G1:
18890 case BFD_RELOC_ARM_LDR_SB_G2:
18891 assert (!fixP->fx_done);
18892 if (!seg->use_rela_p)
18893 {
18894 bfd_vma insn;
18895 bfd_vma addend_abs = abs (value);
18896
18897 /* Check that the absolute value of the addend can be
18898 encoded in 12 bits. */
18899 if (addend_abs >= 0x1000)
18900 as_bad_where (fixP->fx_file, fixP->fx_line,
18901 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 18902 (unsigned long) addend_abs);
4962c51a
MS
18903
18904 /* Extract the instruction. */
18905 insn = md_chars_to_number (buf, INSN_SIZE);
18906
18907 /* If the addend is negative, clear bit 23 of the instruction.
18908 Otherwise set it. */
18909 if (value < 0)
18910 insn &= ~(1 << 23);
18911 else
18912 insn |= 1 << 23;
18913
18914 /* Place the absolute value of the addend into the first 12 bits
18915 of the instruction. */
18916 insn &= 0xfffff000;
18917 insn |= addend_abs;
5f4273c7
NC
18918
18919 /* Update the instruction. */
4962c51a
MS
18920 md_number_to_chars (buf, insn, INSN_SIZE);
18921 }
18922 break;
18923
18924 case BFD_RELOC_ARM_LDRS_PC_G0:
18925 case BFD_RELOC_ARM_LDRS_PC_G1:
18926 case BFD_RELOC_ARM_LDRS_PC_G2:
18927 case BFD_RELOC_ARM_LDRS_SB_G0:
18928 case BFD_RELOC_ARM_LDRS_SB_G1:
18929 case BFD_RELOC_ARM_LDRS_SB_G2:
18930 assert (!fixP->fx_done);
18931 if (!seg->use_rela_p)
18932 {
18933 bfd_vma insn;
18934 bfd_vma addend_abs = abs (value);
18935
18936 /* Check that the absolute value of the addend can be
18937 encoded in 8 bits. */
18938 if (addend_abs >= 0x100)
18939 as_bad_where (fixP->fx_file, fixP->fx_line,
18940 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 18941 (unsigned long) addend_abs);
4962c51a
MS
18942
18943 /* Extract the instruction. */
18944 insn = md_chars_to_number (buf, INSN_SIZE);
18945
18946 /* If the addend is negative, clear bit 23 of the instruction.
18947 Otherwise set it. */
18948 if (value < 0)
18949 insn &= ~(1 << 23);
18950 else
18951 insn |= 1 << 23;
18952
18953 /* Place the first four bits of the absolute value of the addend
18954 into the first 4 bits of the instruction, and the remaining
18955 four into bits 8 .. 11. */
18956 insn &= 0xfffff0f0;
18957 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
18958
18959 /* Update the instruction. */
4962c51a
MS
18960 md_number_to_chars (buf, insn, INSN_SIZE);
18961 }
18962 break;
18963
18964 case BFD_RELOC_ARM_LDC_PC_G0:
18965 case BFD_RELOC_ARM_LDC_PC_G1:
18966 case BFD_RELOC_ARM_LDC_PC_G2:
18967 case BFD_RELOC_ARM_LDC_SB_G0:
18968 case BFD_RELOC_ARM_LDC_SB_G1:
18969 case BFD_RELOC_ARM_LDC_SB_G2:
18970 assert (!fixP->fx_done);
18971 if (!seg->use_rela_p)
18972 {
18973 bfd_vma insn;
18974 bfd_vma addend_abs = abs (value);
18975
18976 /* Check that the absolute value of the addend is a multiple of
18977 four and, when divided by four, fits in 8 bits. */
18978 if (addend_abs & 0x3)
18979 as_bad_where (fixP->fx_file, fixP->fx_line,
18980 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 18981 (unsigned long) addend_abs);
4962c51a
MS
18982
18983 if ((addend_abs >> 2) > 0xff)
18984 as_bad_where (fixP->fx_file, fixP->fx_line,
18985 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 18986 (unsigned long) addend_abs);
4962c51a
MS
18987
18988 /* Extract the instruction. */
18989 insn = md_chars_to_number (buf, INSN_SIZE);
18990
18991 /* If the addend is negative, clear bit 23 of the instruction.
18992 Otherwise set it. */
18993 if (value < 0)
18994 insn &= ~(1 << 23);
18995 else
18996 insn |= 1 << 23;
18997
18998 /* Place the addend (divided by four) into the first eight
18999 bits of the instruction. */
19000 insn &= 0xfffffff0;
19001 insn |= addend_abs >> 2;
5f4273c7
NC
19002
19003 /* Update the instruction. */
4962c51a
MS
19004 md_number_to_chars (buf, insn, INSN_SIZE);
19005 }
19006 break;
19007
845b51d6
PB
19008 case BFD_RELOC_ARM_V4BX:
19009 /* This will need to go in the object file. */
19010 fixP->fx_done = 0;
19011 break;
19012
c19d1205
ZW
19013 case BFD_RELOC_UNUSED:
19014 default:
19015 as_bad_where (fixP->fx_file, fixP->fx_line,
19016 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19017 }
6c43fab6
RE
19018}
19019
c19d1205
ZW
19020/* Translate internal representation of relocation info to BFD target
19021 format. */
a737bd4d 19022
c19d1205 19023arelent *
00a97672 19024tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19025{
c19d1205
ZW
19026 arelent * reloc;
19027 bfd_reloc_code_real_type code;
a737bd4d 19028
c19d1205 19029 reloc = xmalloc (sizeof (arelent));
a737bd4d 19030
c19d1205
ZW
19031 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19032 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19033 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19034
2fc8bdac 19035 if (fixp->fx_pcrel)
00a97672
RS
19036 {
19037 if (section->use_rela_p)
19038 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19039 else
19040 fixp->fx_offset = reloc->address;
19041 }
c19d1205 19042 reloc->addend = fixp->fx_offset;
a737bd4d 19043
c19d1205 19044 switch (fixp->fx_r_type)
a737bd4d 19045 {
c19d1205
ZW
19046 case BFD_RELOC_8:
19047 if (fixp->fx_pcrel)
19048 {
19049 code = BFD_RELOC_8_PCREL;
19050 break;
19051 }
a737bd4d 19052
c19d1205
ZW
19053 case BFD_RELOC_16:
19054 if (fixp->fx_pcrel)
19055 {
19056 code = BFD_RELOC_16_PCREL;
19057 break;
19058 }
6c43fab6 19059
c19d1205
ZW
19060 case BFD_RELOC_32:
19061 if (fixp->fx_pcrel)
19062 {
19063 code = BFD_RELOC_32_PCREL;
19064 break;
19065 }
a737bd4d 19066
b6895b4f
PB
19067 case BFD_RELOC_ARM_MOVW:
19068 if (fixp->fx_pcrel)
19069 {
19070 code = BFD_RELOC_ARM_MOVW_PCREL;
19071 break;
19072 }
19073
19074 case BFD_RELOC_ARM_MOVT:
19075 if (fixp->fx_pcrel)
19076 {
19077 code = BFD_RELOC_ARM_MOVT_PCREL;
19078 break;
19079 }
19080
19081 case BFD_RELOC_ARM_THUMB_MOVW:
19082 if (fixp->fx_pcrel)
19083 {
19084 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19085 break;
19086 }
19087
19088 case BFD_RELOC_ARM_THUMB_MOVT:
19089 if (fixp->fx_pcrel)
19090 {
19091 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19092 break;
19093 }
19094
c19d1205
ZW
19095 case BFD_RELOC_NONE:
19096 case BFD_RELOC_ARM_PCREL_BRANCH:
19097 case BFD_RELOC_ARM_PCREL_BLX:
19098 case BFD_RELOC_RVA:
19099 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19100 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19101 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19102 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19103 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19104 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19105 case BFD_RELOC_THUMB_PCREL_BLX:
19106 case BFD_RELOC_VTABLE_ENTRY:
19107 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19108#ifdef TE_PE
19109 case BFD_RELOC_32_SECREL:
19110#endif
c19d1205
ZW
19111 code = fixp->fx_r_type;
19112 break;
a737bd4d 19113
c19d1205
ZW
19114 case BFD_RELOC_ARM_LITERAL:
19115 case BFD_RELOC_ARM_HWLITERAL:
19116 /* If this is called then the a literal has
19117 been referenced across a section boundary. */
19118 as_bad_where (fixp->fx_file, fixp->fx_line,
19119 _("literal referenced across section boundary"));
19120 return NULL;
a737bd4d 19121
c19d1205
ZW
19122#ifdef OBJ_ELF
19123 case BFD_RELOC_ARM_GOT32:
19124 case BFD_RELOC_ARM_GOTOFF:
19125 case BFD_RELOC_ARM_PLT32:
19126 case BFD_RELOC_ARM_TARGET1:
19127 case BFD_RELOC_ARM_ROSEGREL32:
19128 case BFD_RELOC_ARM_SBREL32:
19129 case BFD_RELOC_ARM_PREL31:
19130 case BFD_RELOC_ARM_TARGET2:
19131 case BFD_RELOC_ARM_TLS_LE32:
19132 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19133 case BFD_RELOC_ARM_PCREL_CALL:
19134 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19135 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19136 case BFD_RELOC_ARM_ALU_PC_G0:
19137 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19138 case BFD_RELOC_ARM_ALU_PC_G1:
19139 case BFD_RELOC_ARM_ALU_PC_G2:
19140 case BFD_RELOC_ARM_LDR_PC_G0:
19141 case BFD_RELOC_ARM_LDR_PC_G1:
19142 case BFD_RELOC_ARM_LDR_PC_G2:
19143 case BFD_RELOC_ARM_LDRS_PC_G0:
19144 case BFD_RELOC_ARM_LDRS_PC_G1:
19145 case BFD_RELOC_ARM_LDRS_PC_G2:
19146 case BFD_RELOC_ARM_LDC_PC_G0:
19147 case BFD_RELOC_ARM_LDC_PC_G1:
19148 case BFD_RELOC_ARM_LDC_PC_G2:
19149 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19150 case BFD_RELOC_ARM_ALU_SB_G0:
19151 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19152 case BFD_RELOC_ARM_ALU_SB_G1:
19153 case BFD_RELOC_ARM_ALU_SB_G2:
19154 case BFD_RELOC_ARM_LDR_SB_G0:
19155 case BFD_RELOC_ARM_LDR_SB_G1:
19156 case BFD_RELOC_ARM_LDR_SB_G2:
19157 case BFD_RELOC_ARM_LDRS_SB_G0:
19158 case BFD_RELOC_ARM_LDRS_SB_G1:
19159 case BFD_RELOC_ARM_LDRS_SB_G2:
19160 case BFD_RELOC_ARM_LDC_SB_G0:
19161 case BFD_RELOC_ARM_LDC_SB_G1:
19162 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19163 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19164 code = fixp->fx_r_type;
19165 break;
a737bd4d 19166
c19d1205
ZW
19167 case BFD_RELOC_ARM_TLS_GD32:
19168 case BFD_RELOC_ARM_TLS_IE32:
19169 case BFD_RELOC_ARM_TLS_LDM32:
19170 /* BFD will include the symbol's address in the addend.
19171 But we don't want that, so subtract it out again here. */
19172 if (!S_IS_COMMON (fixp->fx_addsy))
19173 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19174 code = fixp->fx_r_type;
19175 break;
19176#endif
a737bd4d 19177
c19d1205
ZW
19178 case BFD_RELOC_ARM_IMMEDIATE:
19179 as_bad_where (fixp->fx_file, fixp->fx_line,
19180 _("internal relocation (type: IMMEDIATE) not fixed up"));
19181 return NULL;
a737bd4d 19182
c19d1205
ZW
19183 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19184 as_bad_where (fixp->fx_file, fixp->fx_line,
19185 _("ADRL used for a symbol not defined in the same file"));
19186 return NULL;
a737bd4d 19187
c19d1205 19188 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19189 if (section->use_rela_p)
19190 {
19191 code = fixp->fx_r_type;
19192 break;
19193 }
19194
c19d1205
ZW
19195 if (fixp->fx_addsy != NULL
19196 && !S_IS_DEFINED (fixp->fx_addsy)
19197 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19198 {
c19d1205
ZW
19199 as_bad_where (fixp->fx_file, fixp->fx_line,
19200 _("undefined local label `%s'"),
19201 S_GET_NAME (fixp->fx_addsy));
19202 return NULL;
a737bd4d
NC
19203 }
19204
c19d1205
ZW
19205 as_bad_where (fixp->fx_file, fixp->fx_line,
19206 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19207 return NULL;
a737bd4d 19208
c19d1205
ZW
19209 default:
19210 {
19211 char * type;
6c43fab6 19212
c19d1205
ZW
19213 switch (fixp->fx_r_type)
19214 {
19215 case BFD_RELOC_NONE: type = "NONE"; break;
19216 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19217 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19218 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19219 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19220 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19221 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19222 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19223 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19224 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19225 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19226 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19227 default: type = _("<unknown>"); break;
19228 }
19229 as_bad_where (fixp->fx_file, fixp->fx_line,
19230 _("cannot represent %s relocation in this object file format"),
19231 type);
19232 return NULL;
19233 }
a737bd4d 19234 }
6c43fab6 19235
c19d1205
ZW
19236#ifdef OBJ_ELF
19237 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19238 && GOT_symbol
19239 && fixp->fx_addsy == GOT_symbol)
19240 {
19241 code = BFD_RELOC_ARM_GOTPC;
19242 reloc->addend = fixp->fx_offset = reloc->address;
19243 }
19244#endif
6c43fab6 19245
c19d1205 19246 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19247
c19d1205
ZW
19248 if (reloc->howto == NULL)
19249 {
19250 as_bad_where (fixp->fx_file, fixp->fx_line,
19251 _("cannot represent %s relocation in this object file format"),
19252 bfd_get_reloc_code_name (code));
19253 return NULL;
19254 }
6c43fab6 19255
c19d1205
ZW
19256 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19257 vtable entry to be used in the relocation's section offset. */
19258 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19259 reloc->address = fixp->fx_offset;
6c43fab6 19260
c19d1205 19261 return reloc;
6c43fab6
RE
19262}
19263
c19d1205 19264/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19265
c19d1205
ZW
19266void
19267cons_fix_new_arm (fragS * frag,
19268 int where,
19269 int size,
19270 expressionS * exp)
6c43fab6 19271{
c19d1205
ZW
19272 bfd_reloc_code_real_type type;
19273 int pcrel = 0;
6c43fab6 19274
c19d1205
ZW
19275 /* Pick a reloc.
19276 FIXME: @@ Should look at CPU word size. */
19277 switch (size)
19278 {
19279 case 1:
19280 type = BFD_RELOC_8;
19281 break;
19282 case 2:
19283 type = BFD_RELOC_16;
19284 break;
19285 case 4:
19286 default:
19287 type = BFD_RELOC_32;
19288 break;
19289 case 8:
19290 type = BFD_RELOC_64;
19291 break;
19292 }
6c43fab6 19293
f0927246
NC
19294#ifdef TE_PE
19295 if (exp->X_op == O_secrel)
19296 {
19297 exp->X_op = O_symbol;
19298 type = BFD_RELOC_32_SECREL;
19299 }
19300#endif
19301
c19d1205
ZW
19302 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19303}
6c43fab6 19304
c19d1205
ZW
19305#if defined OBJ_COFF || defined OBJ_ELF
19306void
19307arm_validate_fix (fixS * fixP)
6c43fab6 19308{
c19d1205
ZW
19309 /* If the destination of the branch is a defined symbol which does not have
19310 the THUMB_FUNC attribute, then we must be calling a function which has
19311 the (interfacearm) attribute. We look for the Thumb entry point to that
19312 function and change the branch to refer to that function instead. */
19313 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19314 && fixP->fx_addsy != NULL
19315 && S_IS_DEFINED (fixP->fx_addsy)
19316 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19317 {
c19d1205 19318 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19319 }
c19d1205
ZW
19320}
19321#endif
6c43fab6 19322
c19d1205
ZW
19323int
19324arm_force_relocation (struct fix * fixp)
19325{
19326#if defined (OBJ_COFF) && defined (TE_PE)
19327 if (fixp->fx_r_type == BFD_RELOC_RVA)
19328 return 1;
19329#endif
6c43fab6 19330
c19d1205
ZW
19331 /* Resolve these relocations even if the symbol is extern or weak. */
19332 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19333 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19334 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19335 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19336 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19337 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19338 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19339 return 0;
a737bd4d 19340
4962c51a
MS
19341 /* Always leave these relocations for the linker. */
19342 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19343 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19344 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19345 return 1;
19346
f0291e4c
PB
19347 /* Always generate relocations against function symbols. */
19348 if (fixp->fx_r_type == BFD_RELOC_32
19349 && fixp->fx_addsy
19350 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19351 return 1;
19352
c19d1205 19353 return generic_force_reloc (fixp);
404ff6b5
AH
19354}
19355
0ffdc86c 19356#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19357/* Relocations against function names must be left unadjusted,
19358 so that the linker can use this information to generate interworking
19359 stubs. The MIPS version of this function
c19d1205
ZW
19360 also prevents relocations that are mips-16 specific, but I do not
19361 know why it does this.
404ff6b5 19362
c19d1205
ZW
19363 FIXME:
19364 There is one other problem that ought to be addressed here, but
19365 which currently is not: Taking the address of a label (rather
19366 than a function) and then later jumping to that address. Such
19367 addresses also ought to have their bottom bit set (assuming that
19368 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19369
c19d1205
ZW
19370bfd_boolean
19371arm_fix_adjustable (fixS * fixP)
404ff6b5 19372{
c19d1205
ZW
19373 if (fixP->fx_addsy == NULL)
19374 return 1;
404ff6b5 19375
e28387c3
PB
19376 /* Preserve relocations against symbols with function type. */
19377 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19378 return 0;
19379
c19d1205
ZW
19380 if (THUMB_IS_FUNC (fixP->fx_addsy)
19381 && fixP->fx_subsy == NULL)
19382 return 0;
a737bd4d 19383
c19d1205
ZW
19384 /* We need the symbol name for the VTABLE entries. */
19385 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19386 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19387 return 0;
404ff6b5 19388
c19d1205
ZW
19389 /* Don't allow symbols to be discarded on GOT related relocs. */
19390 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19391 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19392 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19393 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19394 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19395 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19396 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19397 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19398 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19399 return 0;
a737bd4d 19400
4962c51a
MS
19401 /* Similarly for group relocations. */
19402 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19403 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19404 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19405 return 0;
19406
c19d1205 19407 return 1;
a737bd4d 19408}
0ffdc86c
NC
19409#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19410
19411#ifdef OBJ_ELF
404ff6b5 19412
c19d1205
ZW
19413const char *
19414elf32_arm_target_format (void)
404ff6b5 19415{
c19d1205
ZW
19416#ifdef TE_SYMBIAN
19417 return (target_big_endian
19418 ? "elf32-bigarm-symbian"
19419 : "elf32-littlearm-symbian");
19420#elif defined (TE_VXWORKS)
19421 return (target_big_endian
19422 ? "elf32-bigarm-vxworks"
19423 : "elf32-littlearm-vxworks");
19424#else
19425 if (target_big_endian)
19426 return "elf32-bigarm";
19427 else
19428 return "elf32-littlearm";
19429#endif
404ff6b5
AH
19430}
19431
c19d1205
ZW
19432void
19433armelf_frob_symbol (symbolS * symp,
19434 int * puntp)
404ff6b5 19435{
c19d1205
ZW
19436 elf_frob_symbol (symp, puntp);
19437}
19438#endif
404ff6b5 19439
c19d1205 19440/* MD interface: Finalization. */
a737bd4d 19441
c19d1205
ZW
19442/* A good place to do this, although this was probably not intended
19443 for this kind of use. We need to dump the literal pool before
19444 references are made to a null symbol pointer. */
a737bd4d 19445
c19d1205
ZW
19446void
19447arm_cleanup (void)
19448{
19449 literal_pool * pool;
a737bd4d 19450
c19d1205
ZW
19451 for (pool = list_of_pools; pool; pool = pool->next)
19452 {
5f4273c7 19453 /* Put it at the end of the relevant section. */
c19d1205
ZW
19454 subseg_set (pool->section, pool->sub_section);
19455#ifdef OBJ_ELF
19456 arm_elf_change_section ();
19457#endif
19458 s_ltorg (0);
19459 }
404ff6b5
AH
19460}
19461
c19d1205
ZW
19462/* Adjust the symbol table. This marks Thumb symbols as distinct from
19463 ARM ones. */
404ff6b5 19464
c19d1205
ZW
19465void
19466arm_adjust_symtab (void)
404ff6b5 19467{
c19d1205
ZW
19468#ifdef OBJ_COFF
19469 symbolS * sym;
404ff6b5 19470
c19d1205
ZW
19471 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19472 {
19473 if (ARM_IS_THUMB (sym))
19474 {
19475 if (THUMB_IS_FUNC (sym))
19476 {
19477 /* Mark the symbol as a Thumb function. */
19478 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19479 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19480 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19481
c19d1205
ZW
19482 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19483 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19484 else
19485 as_bad (_("%s: unexpected function type: %d"),
19486 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19487 }
19488 else switch (S_GET_STORAGE_CLASS (sym))
19489 {
19490 case C_EXT:
19491 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19492 break;
19493 case C_STAT:
19494 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19495 break;
19496 case C_LABEL:
19497 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19498 break;
19499 default:
19500 /* Do nothing. */
19501 break;
19502 }
19503 }
a737bd4d 19504
c19d1205
ZW
19505 if (ARM_IS_INTERWORK (sym))
19506 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19507 }
c19d1205
ZW
19508#endif
19509#ifdef OBJ_ELF
19510 symbolS * sym;
19511 char bind;
404ff6b5 19512
c19d1205 19513 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19514 {
c19d1205
ZW
19515 if (ARM_IS_THUMB (sym))
19516 {
19517 elf_symbol_type * elf_sym;
404ff6b5 19518
c19d1205
ZW
19519 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19520 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19521
b0796911
PB
19522 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19523 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19524 {
19525 /* If it's a .thumb_func, declare it as so,
19526 otherwise tag label as .code 16. */
19527 if (THUMB_IS_FUNC (sym))
19528 elf_sym->internal_elf_sym.st_info =
19529 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19530 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19531 elf_sym->internal_elf_sym.st_info =
19532 ELF_ST_INFO (bind, STT_ARM_16BIT);
19533 }
19534 }
19535 }
19536#endif
404ff6b5
AH
19537}
19538
c19d1205 19539/* MD interface: Initialization. */
404ff6b5 19540
a737bd4d 19541static void
c19d1205 19542set_constant_flonums (void)
a737bd4d 19543{
c19d1205 19544 int i;
404ff6b5 19545
c19d1205
ZW
19546 for (i = 0; i < NUM_FLOAT_VALS; i++)
19547 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19548 abort ();
a737bd4d 19549}
404ff6b5 19550
3e9e4fcf
JB
19551/* Auto-select Thumb mode if it's the only available instruction set for the
19552 given architecture. */
19553
19554static void
19555autoselect_thumb_from_cpu_variant (void)
19556{
19557 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19558 opcode_select (16);
19559}
19560
c19d1205
ZW
19561void
19562md_begin (void)
a737bd4d 19563{
c19d1205
ZW
19564 unsigned mach;
19565 unsigned int i;
404ff6b5 19566
c19d1205
ZW
19567 if ( (arm_ops_hsh = hash_new ()) == NULL
19568 || (arm_cond_hsh = hash_new ()) == NULL
19569 || (arm_shift_hsh = hash_new ()) == NULL
19570 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19571 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19572 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19573 || (arm_reloc_hsh = hash_new ()) == NULL
19574 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19575 as_fatal (_("virtual memory exhausted"));
19576
19577 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19578 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19579 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19580 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19581 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19582 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19583 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19584 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19585 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19586 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19587 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19588 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19589 for (i = 0;
19590 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19591 i++)
19592 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19593 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19594#ifdef OBJ_ELF
19595 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19596 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19597#endif
19598
19599 set_constant_flonums ();
404ff6b5 19600
c19d1205
ZW
19601 /* Set the cpu variant based on the command-line options. We prefer
19602 -mcpu= over -march= if both are set (as for GCC); and we prefer
19603 -mfpu= over any other way of setting the floating point unit.
19604 Use of legacy options with new options are faulted. */
e74cfd16 19605 if (legacy_cpu)
404ff6b5 19606 {
e74cfd16 19607 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19608 as_bad (_("use of old and new-style options to set CPU type"));
19609
19610 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19611 }
e74cfd16 19612 else if (!mcpu_cpu_opt)
c19d1205 19613 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19614
e74cfd16 19615 if (legacy_fpu)
c19d1205 19616 {
e74cfd16 19617 if (mfpu_opt)
c19d1205 19618 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19619
19620 mfpu_opt = legacy_fpu;
19621 }
e74cfd16 19622 else if (!mfpu_opt)
03b1477f 19623 {
c19d1205 19624#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19625 /* Some environments specify a default FPU. If they don't, infer it
19626 from the processor. */
e74cfd16 19627 if (mcpu_fpu_opt)
03b1477f
RE
19628 mfpu_opt = mcpu_fpu_opt;
19629 else
19630 mfpu_opt = march_fpu_opt;
39c2da32 19631#else
e74cfd16 19632 mfpu_opt = &fpu_default;
39c2da32 19633#endif
03b1477f
RE
19634 }
19635
e74cfd16 19636 if (!mfpu_opt)
03b1477f 19637 {
493cb6ef 19638 if (mcpu_cpu_opt != NULL)
e74cfd16 19639 mfpu_opt = &fpu_default;
493cb6ef 19640 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19641 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19642 else
e74cfd16 19643 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19644 }
19645
ee065d83 19646#ifdef CPU_DEFAULT
e74cfd16 19647 if (!mcpu_cpu_opt)
ee065d83 19648 {
e74cfd16
PB
19649 mcpu_cpu_opt = &cpu_default;
19650 selected_cpu = cpu_default;
ee065d83 19651 }
e74cfd16
PB
19652#else
19653 if (mcpu_cpu_opt)
19654 selected_cpu = *mcpu_cpu_opt;
ee065d83 19655 else
e74cfd16 19656 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19657#endif
03b1477f 19658
e74cfd16 19659 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19660
3e9e4fcf
JB
19661 autoselect_thumb_from_cpu_variant ();
19662
e74cfd16 19663 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19664
f17c130b 19665#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19666 {
7cc69913
NC
19667 unsigned int flags = 0;
19668
19669#if defined OBJ_ELF
19670 flags = meabi_flags;
d507cf36
PB
19671
19672 switch (meabi_flags)
33a392fb 19673 {
d507cf36 19674 case EF_ARM_EABI_UNKNOWN:
7cc69913 19675#endif
d507cf36
PB
19676 /* Set the flags in the private structure. */
19677 if (uses_apcs_26) flags |= F_APCS26;
19678 if (support_interwork) flags |= F_INTERWORK;
19679 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19680 if (pic_code) flags |= F_PIC;
e74cfd16 19681 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19682 flags |= F_SOFT_FLOAT;
19683
d507cf36
PB
19684 switch (mfloat_abi_opt)
19685 {
19686 case ARM_FLOAT_ABI_SOFT:
19687 case ARM_FLOAT_ABI_SOFTFP:
19688 flags |= F_SOFT_FLOAT;
19689 break;
33a392fb 19690
d507cf36
PB
19691 case ARM_FLOAT_ABI_HARD:
19692 if (flags & F_SOFT_FLOAT)
19693 as_bad (_("hard-float conflicts with specified fpu"));
19694 break;
19695 }
03b1477f 19696
e74cfd16
PB
19697 /* Using pure-endian doubles (even if soft-float). */
19698 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19699 flags |= F_VFP_FLOAT;
f17c130b 19700
fde78edd 19701#if defined OBJ_ELF
e74cfd16 19702 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19703 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19704 break;
19705
8cb51566 19706 case EF_ARM_EABI_VER4:
3a4a14e9 19707 case EF_ARM_EABI_VER5:
c19d1205 19708 /* No additional flags to set. */
d507cf36
PB
19709 break;
19710
19711 default:
19712 abort ();
19713 }
7cc69913 19714#endif
b99bd4ef
NC
19715 bfd_set_private_flags (stdoutput, flags);
19716
19717 /* We have run out flags in the COFF header to encode the
19718 status of ATPCS support, so instead we create a dummy,
c19d1205 19719 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19720 if (atpcs)
19721 {
19722 asection * sec;
19723
19724 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19725
19726 if (sec != NULL)
19727 {
19728 bfd_set_section_flags
19729 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19730 bfd_set_section_size (stdoutput, sec, 0);
19731 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19732 }
19733 }
7cc69913 19734 }
f17c130b 19735#endif
b99bd4ef
NC
19736
19737 /* Record the CPU type as well. */
2d447fca
JM
19738 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19739 mach = bfd_mach_arm_iWMMXt2;
19740 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19741 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19742 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19743 mach = bfd_mach_arm_XScale;
e74cfd16 19744 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19745 mach = bfd_mach_arm_ep9312;
e74cfd16 19746 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19747 mach = bfd_mach_arm_5TE;
e74cfd16 19748 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19749 {
e74cfd16 19750 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19751 mach = bfd_mach_arm_5T;
19752 else
19753 mach = bfd_mach_arm_5;
19754 }
e74cfd16 19755 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19756 {
e74cfd16 19757 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19758 mach = bfd_mach_arm_4T;
19759 else
19760 mach = bfd_mach_arm_4;
19761 }
e74cfd16 19762 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19763 mach = bfd_mach_arm_3M;
e74cfd16
PB
19764 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19765 mach = bfd_mach_arm_3;
19766 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19767 mach = bfd_mach_arm_2a;
19768 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19769 mach = bfd_mach_arm_2;
19770 else
19771 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19772
19773 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19774}
19775
c19d1205 19776/* Command line processing. */
b99bd4ef 19777
c19d1205
ZW
19778/* md_parse_option
19779 Invocation line includes a switch not recognized by the base assembler.
19780 See if it's a processor-specific option.
b99bd4ef 19781
c19d1205
ZW
19782 This routine is somewhat complicated by the need for backwards
19783 compatibility (since older releases of gcc can't be changed).
19784 The new options try to make the interface as compatible as
19785 possible with GCC.
b99bd4ef 19786
c19d1205 19787 New options (supported) are:
b99bd4ef 19788
c19d1205
ZW
19789 -mcpu=<cpu name> Assemble for selected processor
19790 -march=<architecture name> Assemble for selected architecture
19791 -mfpu=<fpu architecture> Assemble for selected FPU.
19792 -EB/-mbig-endian Big-endian
19793 -EL/-mlittle-endian Little-endian
19794 -k Generate PIC code
19795 -mthumb Start in Thumb mode
19796 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19797
c19d1205 19798 For now we will also provide support for:
b99bd4ef 19799
c19d1205
ZW
19800 -mapcs-32 32-bit Program counter
19801 -mapcs-26 26-bit Program counter
19802 -macps-float Floats passed in FP registers
19803 -mapcs-reentrant Reentrant code
19804 -matpcs
19805 (sometime these will probably be replaced with -mapcs=<list of options>
19806 and -matpcs=<list of options>)
b99bd4ef 19807
c19d1205
ZW
19808 The remaining options are only supported for back-wards compatibility.
19809 Cpu variants, the arm part is optional:
19810 -m[arm]1 Currently not supported.
19811 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19812 -m[arm]3 Arm 3 processor
19813 -m[arm]6[xx], Arm 6 processors
19814 -m[arm]7[xx][t][[d]m] Arm 7 processors
19815 -m[arm]8[10] Arm 8 processors
19816 -m[arm]9[20][tdmi] Arm 9 processors
19817 -mstrongarm[110[0]] StrongARM processors
19818 -mxscale XScale processors
19819 -m[arm]v[2345[t[e]]] Arm architectures
19820 -mall All (except the ARM1)
19821 FP variants:
19822 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19823 -mfpe-old (No float load/store multiples)
19824 -mvfpxd VFP Single precision
19825 -mvfp All VFP
19826 -mno-fpu Disable all floating point instructions
b99bd4ef 19827
c19d1205
ZW
19828 The following CPU names are recognized:
19829 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19830 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19831 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19832 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19833 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19834 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19835 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19836
c19d1205 19837 */
b99bd4ef 19838
c19d1205 19839const char * md_shortopts = "m:k";
b99bd4ef 19840
c19d1205
ZW
19841#ifdef ARM_BI_ENDIAN
19842#define OPTION_EB (OPTION_MD_BASE + 0)
19843#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19844#else
c19d1205
ZW
19845#if TARGET_BYTES_BIG_ENDIAN
19846#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19847#else
c19d1205
ZW
19848#define OPTION_EL (OPTION_MD_BASE + 1)
19849#endif
b99bd4ef 19850#endif
845b51d6 19851#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 19852
c19d1205 19853struct option md_longopts[] =
b99bd4ef 19854{
c19d1205
ZW
19855#ifdef OPTION_EB
19856 {"EB", no_argument, NULL, OPTION_EB},
19857#endif
19858#ifdef OPTION_EL
19859 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19860#endif
845b51d6 19861 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
19862 {NULL, no_argument, NULL, 0}
19863};
b99bd4ef 19864
c19d1205 19865size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19866
c19d1205 19867struct arm_option_table
b99bd4ef 19868{
c19d1205
ZW
19869 char *option; /* Option name to match. */
19870 char *help; /* Help information. */
19871 int *var; /* Variable to change. */
19872 int value; /* What to change it to. */
19873 char *deprecated; /* If non-null, print this message. */
19874};
b99bd4ef 19875
c19d1205
ZW
19876struct arm_option_table arm_opts[] =
19877{
19878 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19879 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19880 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19881 &support_interwork, 1, NULL},
19882 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19883 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19884 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19885 1, NULL},
19886 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19887 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19888 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19889 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19890 NULL},
b99bd4ef 19891
c19d1205
ZW
19892 /* These are recognized by the assembler, but have no affect on code. */
19893 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19894 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19895 {NULL, NULL, NULL, 0, NULL}
19896};
19897
19898struct arm_legacy_option_table
19899{
19900 char *option; /* Option name to match. */
19901 const arm_feature_set **var; /* Variable to change. */
19902 const arm_feature_set value; /* What to change it to. */
19903 char *deprecated; /* If non-null, print this message. */
19904};
b99bd4ef 19905
e74cfd16
PB
19906const struct arm_legacy_option_table arm_legacy_opts[] =
19907{
c19d1205
ZW
19908 /* DON'T add any new processors to this list -- we want the whole list
19909 to go away... Add them to the processors table instead. */
e74cfd16
PB
19910 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19911 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19912 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19913 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19914 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19915 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19916 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19917 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19918 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19919 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19920 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19921 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19922 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19923 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19924 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19925 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19926 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19927 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19928 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19929 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19930 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19931 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19932 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19933 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19934 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19935 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19936 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19937 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19938 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19939 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19940 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19941 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19942 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19943 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19944 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19945 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19946 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19947 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19948 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19949 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19950 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19951 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19952 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19953 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19954 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19955 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19956 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19957 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19958 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19959 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19960 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19961 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19962 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19963 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19964 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19965 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19966 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19967 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19968 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19969 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19970 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19971 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19972 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19973 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19974 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19975 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19976 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19977 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19978 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19979 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19980 N_("use -mcpu=strongarm110")},
e74cfd16 19981 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19982 N_("use -mcpu=strongarm1100")},
e74cfd16 19983 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19984 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19985 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19986 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19987 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19988
c19d1205 19989 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19990 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19991 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19992 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19993 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19994 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19995 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19996 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19997 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19998 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19999 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20000 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20001 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20002 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20003 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20004 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20005 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20006 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20007 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20008
c19d1205 20009 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20010 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20011 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20012 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20013 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20014 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20015
e74cfd16 20016 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20017};
7ed4c4c5 20018
c19d1205 20019struct arm_cpu_option_table
7ed4c4c5 20020{
c19d1205 20021 char *name;
e74cfd16 20022 const arm_feature_set value;
c19d1205
ZW
20023 /* For some CPUs we assume an FPU unless the user explicitly sets
20024 -mfpu=... */
e74cfd16 20025 const arm_feature_set default_fpu;
ee065d83
PB
20026 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20027 case. */
20028 const char *canonical_name;
c19d1205 20029};
7ed4c4c5 20030
c19d1205
ZW
20031/* This list should, at a minimum, contain all the cpu names
20032 recognized by GCC. */
e74cfd16 20033static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20034{
ee065d83
PB
20035 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20036 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20037 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20038 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20039 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20040 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20041 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20042 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20043 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20044 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20045 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20046 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20047 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20048 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20049 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20050 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20051 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20052 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20053 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20054 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20055 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20056 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20057 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20058 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20059 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20060 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20061 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20062 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20063 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20064 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20065 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20066 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20067 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20068 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20069 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20070 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20071 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20072 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20073 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20074 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20075 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20076 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20077 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20078 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20079 /* For V5 or later processors we default to using VFP; but the user
20080 should really set the FPU type explicitly. */
ee065d83
PB
20081 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20082 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20083 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20084 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20085 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20086 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20087 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20088 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20089 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20090 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20091 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20092 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20093 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20094 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20095 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20096 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20097 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20098 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20099 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20100 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20101 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20102 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20103 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20104 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20105 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20106 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20107 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20108 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20109 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20110 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20111 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20112 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20113 | FPU_NEON_EXT_V1),
20114 NULL},
62b3e311
PB
20115 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20116 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20117 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20118 /* ??? XSCALE is really an architecture. */
ee065d83 20119 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20120 /* ??? iwmmxt is not a processor. */
ee065d83 20121 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20122 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20123 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20124 /* Maverick */
e74cfd16
PB
20125 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20126 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20127};
7ed4c4c5 20128
c19d1205 20129struct arm_arch_option_table
7ed4c4c5 20130{
c19d1205 20131 char *name;
e74cfd16
PB
20132 const arm_feature_set value;
20133 const arm_feature_set default_fpu;
c19d1205 20134};
7ed4c4c5 20135
c19d1205
ZW
20136/* This list should, at a minimum, contain all the architecture names
20137 recognized by GCC. */
e74cfd16 20138static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20139{
20140 {"all", ARM_ANY, FPU_ARCH_FPA},
20141 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20142 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20143 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20144 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20145 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20146 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20147 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20148 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20149 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20150 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20151 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20152 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20153 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20154 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20155 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20156 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20157 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20158 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20159 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20160 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20161 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20162 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20163 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20164 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20165 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20166 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20167 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20168 /* The official spelling of the ARMv7 profile variants is the dashed form.
20169 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20170 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20171 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20172 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20173 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20174 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20175 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20176 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20177 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20178 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20179 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20180};
7ed4c4c5 20181
c19d1205 20182/* ISA extensions in the co-processor space. */
e74cfd16 20183struct arm_option_cpu_value_table
c19d1205
ZW
20184{
20185 char *name;
e74cfd16 20186 const arm_feature_set value;
c19d1205 20187};
7ed4c4c5 20188
e74cfd16 20189static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20190{
e74cfd16
PB
20191 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20192 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20193 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20194 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20195 {NULL, ARM_ARCH_NONE}
c19d1205 20196};
7ed4c4c5 20197
c19d1205
ZW
20198/* This list should, at a minimum, contain all the fpu names
20199 recognized by GCC. */
e74cfd16 20200static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20201{
20202 {"softfpa", FPU_NONE},
20203 {"fpe", FPU_ARCH_FPE},
20204 {"fpe2", FPU_ARCH_FPE},
20205 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20206 {"fpa", FPU_ARCH_FPA},
20207 {"fpa10", FPU_ARCH_FPA},
20208 {"fpa11", FPU_ARCH_FPA},
20209 {"arm7500fe", FPU_ARCH_FPA},
20210 {"softvfp", FPU_ARCH_VFP},
20211 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20212 {"vfp", FPU_ARCH_VFP_V2},
20213 {"vfp9", FPU_ARCH_VFP_V2},
5287ad62 20214 {"vfp3", FPU_ARCH_VFP_V3},
c19d1205
ZW
20215 {"vfp10", FPU_ARCH_VFP_V2},
20216 {"vfp10-r0", FPU_ARCH_VFP_V1},
20217 {"vfpxd", FPU_ARCH_VFP_V1xD},
20218 {"arm1020t", FPU_ARCH_VFP_V1},
20219 {"arm1020e", FPU_ARCH_VFP_V2},
20220 {"arm1136jfs", FPU_ARCH_VFP_V2},
20221 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20222 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20223 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20224 {NULL, ARM_ARCH_NONE}
20225};
20226
20227struct arm_option_value_table
20228{
20229 char *name;
20230 long value;
c19d1205 20231};
7ed4c4c5 20232
e74cfd16 20233static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20234{
20235 {"hard", ARM_FLOAT_ABI_HARD},
20236 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20237 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20238 {NULL, 0}
c19d1205 20239};
7ed4c4c5 20240
c19d1205 20241#ifdef OBJ_ELF
3a4a14e9 20242/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20243static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20244{
20245 {"gnu", EF_ARM_EABI_UNKNOWN},
20246 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20247 {"5", EF_ARM_EABI_VER5},
e74cfd16 20248 {NULL, 0}
c19d1205
ZW
20249};
20250#endif
7ed4c4c5 20251
c19d1205
ZW
20252struct arm_long_option_table
20253{
20254 char * option; /* Substring to match. */
20255 char * help; /* Help information. */
20256 int (* func) (char * subopt); /* Function to decode sub-option. */
20257 char * deprecated; /* If non-null, print this message. */
20258};
7ed4c4c5
NC
20259
20260static int
e74cfd16 20261arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20262{
e74cfd16
PB
20263 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20264
20265 /* Copy the feature set, so that we can modify it. */
20266 *ext_set = **opt_p;
20267 *opt_p = ext_set;
20268
c19d1205 20269 while (str != NULL && *str != 0)
7ed4c4c5 20270 {
e74cfd16 20271 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20272 char * ext;
20273 int optlen;
7ed4c4c5 20274
c19d1205
ZW
20275 if (*str != '+')
20276 {
20277 as_bad (_("invalid architectural extension"));
20278 return 0;
20279 }
7ed4c4c5 20280
c19d1205
ZW
20281 str++;
20282 ext = strchr (str, '+');
7ed4c4c5 20283
c19d1205
ZW
20284 if (ext != NULL)
20285 optlen = ext - str;
20286 else
20287 optlen = strlen (str);
7ed4c4c5 20288
c19d1205
ZW
20289 if (optlen == 0)
20290 {
20291 as_bad (_("missing architectural extension"));
20292 return 0;
20293 }
7ed4c4c5 20294
c19d1205
ZW
20295 for (opt = arm_extensions; opt->name != NULL; opt++)
20296 if (strncmp (opt->name, str, optlen) == 0)
20297 {
e74cfd16 20298 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20299 break;
20300 }
7ed4c4c5 20301
c19d1205
ZW
20302 if (opt->name == NULL)
20303 {
5f4273c7 20304 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20305 return 0;
20306 }
7ed4c4c5 20307
c19d1205
ZW
20308 str = ext;
20309 };
7ed4c4c5 20310
c19d1205
ZW
20311 return 1;
20312}
7ed4c4c5 20313
c19d1205
ZW
20314static int
20315arm_parse_cpu (char * str)
7ed4c4c5 20316{
e74cfd16 20317 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20318 char * ext = strchr (str, '+');
20319 int optlen;
7ed4c4c5 20320
c19d1205
ZW
20321 if (ext != NULL)
20322 optlen = ext - str;
7ed4c4c5 20323 else
c19d1205 20324 optlen = strlen (str);
7ed4c4c5 20325
c19d1205 20326 if (optlen == 0)
7ed4c4c5 20327 {
c19d1205
ZW
20328 as_bad (_("missing cpu name `%s'"), str);
20329 return 0;
7ed4c4c5
NC
20330 }
20331
c19d1205
ZW
20332 for (opt = arm_cpus; opt->name != NULL; opt++)
20333 if (strncmp (opt->name, str, optlen) == 0)
20334 {
e74cfd16
PB
20335 mcpu_cpu_opt = &opt->value;
20336 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 20337 if (opt->canonical_name)
5f4273c7 20338 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20339 else
20340 {
20341 int i;
20342 for (i = 0; i < optlen; i++)
20343 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20344 selected_cpu_name[i] = 0;
20345 }
7ed4c4c5 20346
c19d1205
ZW
20347 if (ext != NULL)
20348 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20349
c19d1205
ZW
20350 return 1;
20351 }
7ed4c4c5 20352
c19d1205
ZW
20353 as_bad (_("unknown cpu `%s'"), str);
20354 return 0;
7ed4c4c5
NC
20355}
20356
c19d1205
ZW
20357static int
20358arm_parse_arch (char * str)
7ed4c4c5 20359{
e74cfd16 20360 const struct arm_arch_option_table *opt;
c19d1205
ZW
20361 char *ext = strchr (str, '+');
20362 int optlen;
7ed4c4c5 20363
c19d1205
ZW
20364 if (ext != NULL)
20365 optlen = ext - str;
7ed4c4c5 20366 else
c19d1205 20367 optlen = strlen (str);
7ed4c4c5 20368
c19d1205 20369 if (optlen == 0)
7ed4c4c5 20370 {
c19d1205
ZW
20371 as_bad (_("missing architecture name `%s'"), str);
20372 return 0;
7ed4c4c5
NC
20373 }
20374
c19d1205
ZW
20375 for (opt = arm_archs; opt->name != NULL; opt++)
20376 if (streq (opt->name, str))
20377 {
e74cfd16
PB
20378 march_cpu_opt = &opt->value;
20379 march_fpu_opt = &opt->default_fpu;
5f4273c7 20380 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 20381
c19d1205
ZW
20382 if (ext != NULL)
20383 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20384
c19d1205
ZW
20385 return 1;
20386 }
20387
20388 as_bad (_("unknown architecture `%s'\n"), str);
20389 return 0;
7ed4c4c5 20390}
eb043451 20391
c19d1205
ZW
20392static int
20393arm_parse_fpu (char * str)
20394{
e74cfd16 20395 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20396
c19d1205
ZW
20397 for (opt = arm_fpus; opt->name != NULL; opt++)
20398 if (streq (opt->name, str))
20399 {
e74cfd16 20400 mfpu_opt = &opt->value;
c19d1205
ZW
20401 return 1;
20402 }
b99bd4ef 20403
c19d1205
ZW
20404 as_bad (_("unknown floating point format `%s'\n"), str);
20405 return 0;
20406}
20407
20408static int
20409arm_parse_float_abi (char * str)
b99bd4ef 20410{
e74cfd16 20411 const struct arm_option_value_table * opt;
b99bd4ef 20412
c19d1205
ZW
20413 for (opt = arm_float_abis; opt->name != NULL; opt++)
20414 if (streq (opt->name, str))
20415 {
20416 mfloat_abi_opt = opt->value;
20417 return 1;
20418 }
cc8a6dd0 20419
c19d1205
ZW
20420 as_bad (_("unknown floating point abi `%s'\n"), str);
20421 return 0;
20422}
b99bd4ef 20423
c19d1205
ZW
20424#ifdef OBJ_ELF
20425static int
20426arm_parse_eabi (char * str)
20427{
e74cfd16 20428 const struct arm_option_value_table *opt;
cc8a6dd0 20429
c19d1205
ZW
20430 for (opt = arm_eabis; opt->name != NULL; opt++)
20431 if (streq (opt->name, str))
20432 {
20433 meabi_flags = opt->value;
20434 return 1;
20435 }
20436 as_bad (_("unknown EABI `%s'\n"), str);
20437 return 0;
20438}
20439#endif
cc8a6dd0 20440
c19d1205
ZW
20441struct arm_long_option_table arm_long_opts[] =
20442{
20443 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20444 arm_parse_cpu, NULL},
20445 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20446 arm_parse_arch, NULL},
20447 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20448 arm_parse_fpu, NULL},
20449 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20450 arm_parse_float_abi, NULL},
20451#ifdef OBJ_ELF
20452 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20453 arm_parse_eabi, NULL},
20454#endif
20455 {NULL, NULL, 0, NULL}
20456};
cc8a6dd0 20457
c19d1205
ZW
20458int
20459md_parse_option (int c, char * arg)
20460{
20461 struct arm_option_table *opt;
e74cfd16 20462 const struct arm_legacy_option_table *fopt;
c19d1205 20463 struct arm_long_option_table *lopt;
b99bd4ef 20464
c19d1205 20465 switch (c)
b99bd4ef 20466 {
c19d1205
ZW
20467#ifdef OPTION_EB
20468 case OPTION_EB:
20469 target_big_endian = 1;
20470 break;
20471#endif
cc8a6dd0 20472
c19d1205
ZW
20473#ifdef OPTION_EL
20474 case OPTION_EL:
20475 target_big_endian = 0;
20476 break;
20477#endif
b99bd4ef 20478
845b51d6
PB
20479 case OPTION_FIX_V4BX:
20480 fix_v4bx = TRUE;
20481 break;
20482
c19d1205
ZW
20483 case 'a':
20484 /* Listing option. Just ignore these, we don't support additional
20485 ones. */
20486 return 0;
b99bd4ef 20487
c19d1205
ZW
20488 default:
20489 for (opt = arm_opts; opt->option != NULL; opt++)
20490 {
20491 if (c == opt->option[0]
20492 && ((arg == NULL && opt->option[1] == 0)
20493 || streq (arg, opt->option + 1)))
20494 {
20495#if WARN_DEPRECATED
20496 /* If the option is deprecated, tell the user. */
20497 if (opt->deprecated != NULL)
20498 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20499 arg ? arg : "", _(opt->deprecated));
20500#endif
b99bd4ef 20501
c19d1205
ZW
20502 if (opt->var != NULL)
20503 *opt->var = opt->value;
cc8a6dd0 20504
c19d1205
ZW
20505 return 1;
20506 }
20507 }
b99bd4ef 20508
e74cfd16
PB
20509 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20510 {
20511 if (c == fopt->option[0]
20512 && ((arg == NULL && fopt->option[1] == 0)
20513 || streq (arg, fopt->option + 1)))
20514 {
20515#if WARN_DEPRECATED
20516 /* If the option is deprecated, tell the user. */
20517 if (fopt->deprecated != NULL)
20518 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20519 arg ? arg : "", _(fopt->deprecated));
20520#endif
20521
20522 if (fopt->var != NULL)
20523 *fopt->var = &fopt->value;
20524
20525 return 1;
20526 }
20527 }
20528
c19d1205
ZW
20529 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20530 {
20531 /* These options are expected to have an argument. */
20532 if (c == lopt->option[0]
20533 && arg != NULL
20534 && strncmp (arg, lopt->option + 1,
20535 strlen (lopt->option + 1)) == 0)
20536 {
20537#if WARN_DEPRECATED
20538 /* If the option is deprecated, tell the user. */
20539 if (lopt->deprecated != NULL)
20540 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20541 _(lopt->deprecated));
20542#endif
b99bd4ef 20543
c19d1205
ZW
20544 /* Call the sup-option parser. */
20545 return lopt->func (arg + strlen (lopt->option) - 1);
20546 }
20547 }
a737bd4d 20548
c19d1205
ZW
20549 return 0;
20550 }
a394c00f 20551
c19d1205
ZW
20552 return 1;
20553}
a394c00f 20554
c19d1205
ZW
20555void
20556md_show_usage (FILE * fp)
a394c00f 20557{
c19d1205
ZW
20558 struct arm_option_table *opt;
20559 struct arm_long_option_table *lopt;
a394c00f 20560
c19d1205 20561 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20562
c19d1205
ZW
20563 for (opt = arm_opts; opt->option != NULL; opt++)
20564 if (opt->help != NULL)
20565 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20566
c19d1205
ZW
20567 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20568 if (lopt->help != NULL)
20569 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20570
c19d1205
ZW
20571#ifdef OPTION_EB
20572 fprintf (fp, _("\
20573 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20574#endif
20575
c19d1205
ZW
20576#ifdef OPTION_EL
20577 fprintf (fp, _("\
20578 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20579#endif
845b51d6
PB
20580
20581 fprintf (fp, _("\
20582 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 20583}
ee065d83
PB
20584
20585
20586#ifdef OBJ_ELF
62b3e311
PB
20587typedef struct
20588{
20589 int val;
20590 arm_feature_set flags;
20591} cpu_arch_ver_table;
20592
20593/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20594 least features first. */
20595static const cpu_arch_ver_table cpu_arch_ver[] =
20596{
20597 {1, ARM_ARCH_V4},
20598 {2, ARM_ARCH_V4T},
20599 {3, ARM_ARCH_V5},
20600 {4, ARM_ARCH_V5TE},
20601 {5, ARM_ARCH_V5TEJ},
20602 {6, ARM_ARCH_V6},
20603 {7, ARM_ARCH_V6Z},
7e806470
PB
20604 {9, ARM_ARCH_V6K},
20605 {9, ARM_ARCH_V6M},
20606 {8, ARM_ARCH_V6T2},
62b3e311
PB
20607 {10, ARM_ARCH_V7A},
20608 {10, ARM_ARCH_V7R},
20609 {10, ARM_ARCH_V7M},
20610 {0, ARM_ARCH_NONE}
20611};
20612
ee065d83
PB
20613/* Set the public EABI object attributes. */
20614static void
20615aeabi_set_public_attributes (void)
20616{
20617 int arch;
e74cfd16 20618 arm_feature_set flags;
62b3e311
PB
20619 arm_feature_set tmp;
20620 const cpu_arch_ver_table *p;
ee065d83
PB
20621
20622 /* Choose the architecture based on the capabilities of the requested cpu
20623 (if any) and/or the instructions actually used. */
e74cfd16
PB
20624 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20625 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20626 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20627 /*Allow the user to override the reported architecture. */
20628 if (object_arch)
20629 {
20630 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20631 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20632 }
20633
62b3e311
PB
20634 tmp = flags;
20635 arch = 0;
20636 for (p = cpu_arch_ver; p->val; p++)
20637 {
20638 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20639 {
20640 arch = p->val;
20641 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20642 }
20643 }
ee065d83
PB
20644
20645 /* Tag_CPU_name. */
20646 if (selected_cpu_name[0])
20647 {
20648 char *p;
20649
20650 p = selected_cpu_name;
5f4273c7 20651 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
20652 {
20653 int i;
5f4273c7 20654
ee065d83
PB
20655 p += 4;
20656 for (i = 0; p[i]; i++)
20657 p[i] = TOUPPER (p[i]);
20658 }
104d59d1 20659 bfd_elf_add_proc_attr_string (stdoutput, 5, p);
ee065d83
PB
20660 }
20661 /* Tag_CPU_arch. */
104d59d1 20662 bfd_elf_add_proc_attr_int (stdoutput, 6, arch);
62b3e311
PB
20663 /* Tag_CPU_arch_profile. */
20664 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
104d59d1 20665 bfd_elf_add_proc_attr_int (stdoutput, 7, 'A');
62b3e311 20666 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
104d59d1 20667 bfd_elf_add_proc_attr_int (stdoutput, 7, 'R');
7e806470 20668 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
104d59d1 20669 bfd_elf_add_proc_attr_int (stdoutput, 7, 'M');
ee065d83 20670 /* Tag_ARM_ISA_use. */
e74cfd16 20671 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
104d59d1 20672 bfd_elf_add_proc_attr_int (stdoutput, 8, 1);
ee065d83 20673 /* Tag_THUMB_ISA_use. */
e74cfd16 20674 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
104d59d1 20675 bfd_elf_add_proc_attr_int (stdoutput, 9,
e74cfd16 20676 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20677 /* Tag_VFP_arch. */
5287ad62
JB
20678 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20679 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
104d59d1 20680 bfd_elf_add_proc_attr_int (stdoutput, 10, 3);
5287ad62
JB
20681 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20682 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
104d59d1 20683 bfd_elf_add_proc_attr_int (stdoutput, 10, 2);
5287ad62
JB
20684 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20685 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20686 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20687 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
104d59d1 20688 bfd_elf_add_proc_attr_int (stdoutput, 10, 1);
ee065d83 20689 /* Tag_WMMX_arch. */
e74cfd16
PB
20690 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20691 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
104d59d1 20692 bfd_elf_add_proc_attr_int (stdoutput, 11, 1);
5287ad62
JB
20693 /* Tag_NEON_arch. */
20694 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20695 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
104d59d1 20696 bfd_elf_add_proc_attr_int (stdoutput, 12, 1);
ee065d83
PB
20697}
20698
104d59d1 20699/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
20700void
20701arm_md_end (void)
20702{
ee065d83
PB
20703 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20704 return;
20705
20706 aeabi_set_public_attributes ();
ee065d83 20707}
8463be01 20708#endif /* OBJ_ELF */
ee065d83
PB
20709
20710
20711/* Parse a .cpu directive. */
20712
20713static void
20714s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20715{
e74cfd16 20716 const struct arm_cpu_option_table *opt;
ee065d83
PB
20717 char *name;
20718 char saved_char;
20719
20720 name = input_line_pointer;
5f4273c7 20721 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20722 input_line_pointer++;
20723 saved_char = *input_line_pointer;
20724 *input_line_pointer = 0;
20725
20726 /* Skip the first "all" entry. */
20727 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20728 if (streq (opt->name, name))
20729 {
e74cfd16
PB
20730 mcpu_cpu_opt = &opt->value;
20731 selected_cpu = opt->value;
ee065d83 20732 if (opt->canonical_name)
5f4273c7 20733 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20734 else
20735 {
20736 int i;
20737 for (i = 0; opt->name[i]; i++)
20738 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20739 selected_cpu_name[i] = 0;
20740 }
e74cfd16 20741 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20742 *input_line_pointer = saved_char;
20743 demand_empty_rest_of_line ();
20744 return;
20745 }
20746 as_bad (_("unknown cpu `%s'"), name);
20747 *input_line_pointer = saved_char;
20748 ignore_rest_of_line ();
20749}
20750
20751
20752/* Parse a .arch directive. */
20753
20754static void
20755s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20756{
e74cfd16 20757 const struct arm_arch_option_table *opt;
ee065d83
PB
20758 char saved_char;
20759 char *name;
20760
20761 name = input_line_pointer;
5f4273c7 20762 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20763 input_line_pointer++;
20764 saved_char = *input_line_pointer;
20765 *input_line_pointer = 0;
20766
20767 /* Skip the first "all" entry. */
20768 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20769 if (streq (opt->name, name))
20770 {
e74cfd16
PB
20771 mcpu_cpu_opt = &opt->value;
20772 selected_cpu = opt->value;
5f4273c7 20773 strcpy (selected_cpu_name, opt->name);
e74cfd16 20774 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20775 *input_line_pointer = saved_char;
20776 demand_empty_rest_of_line ();
20777 return;
20778 }
20779
20780 as_bad (_("unknown architecture `%s'\n"), name);
20781 *input_line_pointer = saved_char;
20782 ignore_rest_of_line ();
20783}
20784
20785
7a1d4c38
PB
20786/* Parse a .object_arch directive. */
20787
20788static void
20789s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20790{
20791 const struct arm_arch_option_table *opt;
20792 char saved_char;
20793 char *name;
20794
20795 name = input_line_pointer;
5f4273c7 20796 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
20797 input_line_pointer++;
20798 saved_char = *input_line_pointer;
20799 *input_line_pointer = 0;
20800
20801 /* Skip the first "all" entry. */
20802 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20803 if (streq (opt->name, name))
20804 {
20805 object_arch = &opt->value;
20806 *input_line_pointer = saved_char;
20807 demand_empty_rest_of_line ();
20808 return;
20809 }
20810
20811 as_bad (_("unknown architecture `%s'\n"), name);
20812 *input_line_pointer = saved_char;
20813 ignore_rest_of_line ();
20814}
20815
20816
ee065d83
PB
20817/* Parse a .fpu directive. */
20818
20819static void
20820s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20821{
e74cfd16 20822 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20823 char saved_char;
20824 char *name;
20825
20826 name = input_line_pointer;
5f4273c7 20827 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20828 input_line_pointer++;
20829 saved_char = *input_line_pointer;
20830 *input_line_pointer = 0;
5f4273c7 20831
ee065d83
PB
20832 for (opt = arm_fpus; opt->name != NULL; opt++)
20833 if (streq (opt->name, name))
20834 {
e74cfd16
PB
20835 mfpu_opt = &opt->value;
20836 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20837 *input_line_pointer = saved_char;
20838 demand_empty_rest_of_line ();
20839 return;
20840 }
20841
20842 as_bad (_("unknown floating point format `%s'\n"), name);
20843 *input_line_pointer = saved_char;
20844 ignore_rest_of_line ();
20845}
ee065d83 20846
794ba86a
DJ
20847/* Copy symbol information. */
20848void
20849arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20850{
20851 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20852}
This page took 1.889073 seconds and 4 git commands to generate.