]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
gas:
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
f31fef98 3 2004, 2005, 2006, 2007, 2008, 2009
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
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80/* Bit N indicates that an R_ARM_NONE relocation has been output for
81 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
82 emitted only once per section, to save unnecessary bloat. */
83static unsigned int marked_pr_dependency = 0;
84
85#endif /* OBJ_ELF */
86
4962c51a
MS
87/* Results from operand parsing worker functions. */
88
89typedef enum
90{
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94} parse_operand_result;
95
33a392fb
PB
96enum arm_float_abi
97{
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
101};
102
c19d1205 103/* Types of processor to assemble for. */
b99bd4ef
NC
104#ifndef CPU_DEFAULT
105#if defined __XSCALE__
e74cfd16 106#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
107#else
108#if defined __thumb__
e74cfd16 109#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
110#endif
111#endif
112#endif
113
114#ifndef FPU_DEFAULT
c820d418
MM
115# ifdef TE_LINUX
116# define FPU_DEFAULT FPU_ARCH_FPA
117# elif defined (TE_NetBSD)
118# ifdef OBJ_ELF
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
120# else
121 /* Legacy a.out format. */
122# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
123# endif
4e7fd91e
PB
124# elif defined (TE_VXWORKS)
125# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
126# else
127 /* For backwards compatibility, default to FPA. */
128# define FPU_DEFAULT FPU_ARCH_FPA
129# endif
130#endif /* ifndef FPU_DEFAULT */
b99bd4ef 131
c19d1205 132#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 133
e74cfd16
PB
134static arm_feature_set cpu_variant;
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
03b1477f
RE
148
149/* Variables that we set while parsing command-line options. Once all
150 options have been read we re-process these values to set the real
151 assembly flags. */
e74cfd16
PB
152static const arm_feature_set *legacy_cpu = NULL;
153static const arm_feature_set *legacy_fpu = NULL;
154
155static const arm_feature_set *mcpu_cpu_opt = NULL;
156static const arm_feature_set *mcpu_fpu_opt = NULL;
157static const arm_feature_set *march_cpu_opt = NULL;
158static const arm_feature_set *march_fpu_opt = NULL;
159static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 160static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
161
162/* Constants for known architecture features. */
163static const arm_feature_set fpu_default = FPU_DEFAULT;
164static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
166static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
168static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
172
173#ifdef CPU_DEFAULT
174static const arm_feature_set cpu_default = CPU_DEFAULT;
175#endif
176
177static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 195static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
7e806470
PB
196static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
198static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
7e806470
PB
202static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
204
205static const arm_feature_set arm_arch_any = ARM_ANY;
206static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209
2d447fca
JM
210static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
212static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62 224static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
225static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
227static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
8e79c3df 230static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
e74cfd16 231
33a392fb 232static int mfloat_abi_opt = -1;
e74cfd16
PB
233/* Record user cpu selection for object attributes. */
234static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
235/* Must be long enough to hold any of the names in arm_cpus. */
236static char selected_cpu_name[16];
7cc69913 237#ifdef OBJ_ELF
deeaaff8
DJ
238# ifdef EABI_DEFAULT
239static int meabi_flags = EABI_DEFAULT;
240# else
d507cf36 241static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 242# endif
e1da3f5b 243
ee3c0378
AS
244static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
e1da3f5b 246bfd_boolean
5f4273c7 247arm_is_eabi (void)
e1da3f5b
PB
248{
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250}
7cc69913 251#endif
b99bd4ef 252
b99bd4ef 253#ifdef OBJ_ELF
c19d1205 254/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
255symbolS * GOT_symbol;
256#endif
257
b99bd4ef
NC
258/* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262static int thumb_mode = 0;
263
c19d1205
ZW
264/* If unified_syntax is true, we are processing the new unified
265 ARM/Thumb syntax. Important differences from the old ARM mode:
266
267 - Immediate operands do not require a # prefix.
268 - Conditional affixes always appear at the end of the
269 instruction. (For backward compatibility, those instructions
270 that formerly had them in the middle, continue to accept them
271 there.)
272 - The IT instruction may appear, and if it does is validated
273 against subsequent conditional affixes. It does not generate
274 machine code.
275
276 Important differences from the old Thumb mode:
277
278 - Immediate operands do not require a # prefix.
279 - Most of the V6T2 instructions are only available in unified mode.
280 - The .N and .W suffixes are recognized and honored (it is an error
281 if they cannot be honored).
282 - All instructions set the flags if and only if they have an 's' affix.
283 - Conditional affixes may be used. They are validated against
284 preceding IT instructions. Unlike ARM mode, you cannot use a
285 conditional affix except in the scope of an IT instruction. */
286
287static bfd_boolean unified_syntax = FALSE;
b99bd4ef 288
5287ad62
JB
289enum neon_el_type
290{
dcbf9037 291 NT_invtype,
5287ad62
JB
292 NT_untyped,
293 NT_integer,
294 NT_float,
295 NT_poly,
296 NT_signed,
dcbf9037 297 NT_unsigned
5287ad62
JB
298};
299
300struct neon_type_el
301{
302 enum neon_el_type type;
303 unsigned size;
304};
305
306#define NEON_MAX_TYPE_ELS 4
307
308struct neon_type
309{
310 struct neon_type_el el[NEON_MAX_TYPE_ELS];
311 unsigned elems;
312};
313
b99bd4ef
NC
314struct arm_it
315{
c19d1205 316 const char * error;
b99bd4ef 317 unsigned long instruction;
c19d1205
ZW
318 int size;
319 int size_req;
320 int cond;
037e8744
JB
321 /* "uncond_value" is set to the value in place of the conditional field in
322 unconditional versions of the instruction, or -1 if nothing is
323 appropriate. */
324 int uncond_value;
5287ad62 325 struct neon_type vectype;
0110f2b8
PB
326 /* Set to the opcode if the instruction needs relaxation.
327 Zero if the instruction is not relaxed. */
328 unsigned long relax;
b99bd4ef
NC
329 struct
330 {
331 bfd_reloc_code_real_type type;
c19d1205
ZW
332 expressionS exp;
333 int pc_rel;
b99bd4ef 334 } reloc;
b99bd4ef 335
c19d1205
ZW
336 struct
337 {
338 unsigned reg;
ca3f61f7 339 signed int imm;
dcbf9037 340 struct neon_type_el vectype;
ca3f61f7
NC
341 unsigned present : 1; /* Operand present. */
342 unsigned isreg : 1; /* Operand was a register. */
343 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
344 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
345 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 346 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
347 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
348 instructions. This allows us to disambiguate ARM <-> vector insns. */
349 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 350 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 351 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 352 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
353 unsigned hasreloc : 1; /* Operand has relocation suffix. */
354 unsigned writeback : 1; /* Operand has trailing ! */
355 unsigned preind : 1; /* Preindexed address. */
356 unsigned postind : 1; /* Postindexed address. */
357 unsigned negative : 1; /* Index register was negated. */
358 unsigned shifted : 1; /* Shift applied to operation. */
359 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 360 } operands[6];
b99bd4ef
NC
361};
362
c19d1205 363static struct arm_it inst;
b99bd4ef
NC
364
365#define NUM_FLOAT_VALS 8
366
05d2d07e 367const char * fp_const[] =
b99bd4ef
NC
368{
369 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
370};
371
c19d1205 372/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
373#define MAX_LITTLENUMS 6
374
375LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
376
377#define FAIL (-1)
378#define SUCCESS (0)
379
380#define SUFF_S 1
381#define SUFF_D 2
382#define SUFF_E 3
383#define SUFF_P 4
384
c19d1205
ZW
385#define CP_T_X 0x00008000
386#define CP_T_Y 0x00400000
b99bd4ef 387
c19d1205
ZW
388#define CONDS_BIT 0x00100000
389#define LOAD_BIT 0x00100000
b99bd4ef
NC
390
391#define DOUBLE_LOAD_FLAG 0x00000001
392
393struct asm_cond
394{
c19d1205 395 const char * template;
b99bd4ef
NC
396 unsigned long value;
397};
398
c19d1205 399#define COND_ALWAYS 0xE
b99bd4ef 400
b99bd4ef
NC
401struct asm_psr
402{
b34976b6 403 const char *template;
b99bd4ef
NC
404 unsigned long field;
405};
406
62b3e311
PB
407struct asm_barrier_opt
408{
409 const char *template;
410 unsigned long value;
411};
412
2d2255b5 413/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
414#define SPSR_BIT (1 << 22)
415
c19d1205
ZW
416/* The individual PSR flag bits. */
417#define PSR_c (1 << 16)
418#define PSR_x (1 << 17)
419#define PSR_s (1 << 18)
420#define PSR_f (1 << 19)
b99bd4ef 421
c19d1205 422struct reloc_entry
bfae80f2 423{
c19d1205
ZW
424 char *name;
425 bfd_reloc_code_real_type reloc;
bfae80f2
RE
426};
427
5287ad62 428enum vfp_reg_pos
bfae80f2 429{
5287ad62
JB
430 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
431 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
432};
433
434enum vfp_ldstm_type
435{
436 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
437};
438
dcbf9037
JB
439/* Bits for DEFINED field in neon_typed_alias. */
440#define NTA_HASTYPE 1
441#define NTA_HASINDEX 2
442
443struct neon_typed_alias
444{
445 unsigned char defined;
446 unsigned char index;
447 struct neon_type_el eltype;
448};
449
c19d1205
ZW
450/* ARM register categories. This includes coprocessor numbers and various
451 architecture extensions' registers. */
452enum arm_reg_type
bfae80f2 453{
c19d1205
ZW
454 REG_TYPE_RN,
455 REG_TYPE_CP,
456 REG_TYPE_CN,
457 REG_TYPE_FN,
458 REG_TYPE_VFS,
459 REG_TYPE_VFD,
5287ad62 460 REG_TYPE_NQ,
037e8744 461 REG_TYPE_VFSD,
5287ad62 462 REG_TYPE_NDQ,
037e8744 463 REG_TYPE_NSDQ,
c19d1205
ZW
464 REG_TYPE_VFC,
465 REG_TYPE_MVF,
466 REG_TYPE_MVD,
467 REG_TYPE_MVFX,
468 REG_TYPE_MVDX,
469 REG_TYPE_MVAX,
470 REG_TYPE_DSPSC,
471 REG_TYPE_MMXWR,
472 REG_TYPE_MMXWC,
473 REG_TYPE_MMXWCG,
474 REG_TYPE_XSCALE,
bfae80f2
RE
475};
476
dcbf9037
JB
477/* Structure for a hash table entry for a register.
478 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
479 information which states whether a vector type or index is specified (for a
480 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
481struct reg_entry
482{
dcbf9037
JB
483 const char *name;
484 unsigned char number;
485 unsigned char type;
486 unsigned char builtin;
487 struct neon_typed_alias *neon;
6c43fab6
RE
488};
489
c19d1205
ZW
490/* Diagnostics used when we don't get a register of the expected type. */
491const char *const reg_expected_msgs[] =
492{
493 N_("ARM register expected"),
494 N_("bad or missing co-processor number"),
495 N_("co-processor register expected"),
496 N_("FPA register expected"),
497 N_("VFP single precision register expected"),
5287ad62
JB
498 N_("VFP/Neon double precision register expected"),
499 N_("Neon quad precision register expected"),
037e8744 500 N_("VFP single or double precision register expected"),
5287ad62 501 N_("Neon double or quad precision register expected"),
037e8744 502 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
503 N_("VFP system register expected"),
504 N_("Maverick MVF register expected"),
505 N_("Maverick MVD register expected"),
506 N_("Maverick MVFX register expected"),
507 N_("Maverick MVDX register expected"),
508 N_("Maverick MVAX register expected"),
509 N_("Maverick DSPSC register expected"),
510 N_("iWMMXt data register expected"),
511 N_("iWMMXt control register expected"),
512 N_("iWMMXt scalar register expected"),
513 N_("XScale accumulator register expected"),
6c43fab6
RE
514};
515
c19d1205
ZW
516/* Some well known registers that we refer to directly elsewhere. */
517#define REG_SP 13
518#define REG_LR 14
519#define REG_PC 15
404ff6b5 520
b99bd4ef
NC
521/* ARM instructions take 4bytes in the object file, Thumb instructions
522 take 2: */
c19d1205 523#define INSN_SIZE 4
b99bd4ef
NC
524
525struct asm_opcode
526{
527 /* Basic string to match. */
c19d1205
ZW
528 const char *template;
529
530 /* Parameters to instruction. */
531 unsigned char operands[8];
532
533 /* Conditional tag - see opcode_lookup. */
534 unsigned int tag : 4;
b99bd4ef
NC
535
536 /* Basic instruction code. */
c19d1205 537 unsigned int avalue : 28;
b99bd4ef 538
c19d1205
ZW
539 /* Thumb-format instruction code. */
540 unsigned int tvalue;
b99bd4ef 541
90e4755a 542 /* Which architecture variant provides this instruction. */
e74cfd16
PB
543 const arm_feature_set *avariant;
544 const arm_feature_set *tvariant;
c19d1205
ZW
545
546 /* Function to call to encode instruction in ARM format. */
547 void (* aencode) (void);
b99bd4ef 548
c19d1205
ZW
549 /* Function to call to encode instruction in Thumb format. */
550 void (* tencode) (void);
b99bd4ef
NC
551};
552
a737bd4d
NC
553/* Defines for various bits that we will want to toggle. */
554#define INST_IMMEDIATE 0x02000000
555#define OFFSET_REG 0x02000000
c19d1205 556#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
557#define SHIFT_BY_REG 0x00000010
558#define PRE_INDEX 0x01000000
559#define INDEX_UP 0x00800000
560#define WRITE_BACK 0x00200000
561#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 562#define CPSI_MMOD 0x00020000
90e4755a 563
a737bd4d
NC
564#define LITERAL_MASK 0xf000f000
565#define OPCODE_MASK 0xfe1fffff
566#define V4_STR_BIT 0x00000020
90e4755a 567
efd81785
PB
568#define T2_SUBS_PC_LR 0xf3de8f00
569
a737bd4d 570#define DATA_OP_SHIFT 21
90e4755a 571
ef8d22e6
PB
572#define T2_OPCODE_MASK 0xfe1fffff
573#define T2_DATA_OP_SHIFT 21
574
a737bd4d
NC
575/* Codes to distinguish the arithmetic instructions. */
576#define OPCODE_AND 0
577#define OPCODE_EOR 1
578#define OPCODE_SUB 2
579#define OPCODE_RSB 3
580#define OPCODE_ADD 4
581#define OPCODE_ADC 5
582#define OPCODE_SBC 6
583#define OPCODE_RSC 7
584#define OPCODE_TST 8
585#define OPCODE_TEQ 9
586#define OPCODE_CMP 10
587#define OPCODE_CMN 11
588#define OPCODE_ORR 12
589#define OPCODE_MOV 13
590#define OPCODE_BIC 14
591#define OPCODE_MVN 15
90e4755a 592
ef8d22e6
PB
593#define T2_OPCODE_AND 0
594#define T2_OPCODE_BIC 1
595#define T2_OPCODE_ORR 2
596#define T2_OPCODE_ORN 3
597#define T2_OPCODE_EOR 4
598#define T2_OPCODE_ADD 8
599#define T2_OPCODE_ADC 10
600#define T2_OPCODE_SBC 11
601#define T2_OPCODE_SUB 13
602#define T2_OPCODE_RSB 14
603
a737bd4d
NC
604#define T_OPCODE_MUL 0x4340
605#define T_OPCODE_TST 0x4200
606#define T_OPCODE_CMN 0x42c0
607#define T_OPCODE_NEG 0x4240
608#define T_OPCODE_MVN 0x43c0
90e4755a 609
a737bd4d
NC
610#define T_OPCODE_ADD_R3 0x1800
611#define T_OPCODE_SUB_R3 0x1a00
612#define T_OPCODE_ADD_HI 0x4400
613#define T_OPCODE_ADD_ST 0xb000
614#define T_OPCODE_SUB_ST 0xb080
615#define T_OPCODE_ADD_SP 0xa800
616#define T_OPCODE_ADD_PC 0xa000
617#define T_OPCODE_ADD_I8 0x3000
618#define T_OPCODE_SUB_I8 0x3800
619#define T_OPCODE_ADD_I3 0x1c00
620#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 621
a737bd4d
NC
622#define T_OPCODE_ASR_R 0x4100
623#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
624#define T_OPCODE_LSR_R 0x40c0
625#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
626#define T_OPCODE_ASR_I 0x1000
627#define T_OPCODE_LSL_I 0x0000
628#define T_OPCODE_LSR_I 0x0800
b99bd4ef 629
a737bd4d
NC
630#define T_OPCODE_MOV_I8 0x2000
631#define T_OPCODE_CMP_I8 0x2800
632#define T_OPCODE_CMP_LR 0x4280
633#define T_OPCODE_MOV_HR 0x4600
634#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 635
a737bd4d
NC
636#define T_OPCODE_LDR_PC 0x4800
637#define T_OPCODE_LDR_SP 0x9800
638#define T_OPCODE_STR_SP 0x9000
639#define T_OPCODE_LDR_IW 0x6800
640#define T_OPCODE_STR_IW 0x6000
641#define T_OPCODE_LDR_IH 0x8800
642#define T_OPCODE_STR_IH 0x8000
643#define T_OPCODE_LDR_IB 0x7800
644#define T_OPCODE_STR_IB 0x7000
645#define T_OPCODE_LDR_RW 0x5800
646#define T_OPCODE_STR_RW 0x5000
647#define T_OPCODE_LDR_RH 0x5a00
648#define T_OPCODE_STR_RH 0x5200
649#define T_OPCODE_LDR_RB 0x5c00
650#define T_OPCODE_STR_RB 0x5400
c9b604bd 651
a737bd4d
NC
652#define T_OPCODE_PUSH 0xb400
653#define T_OPCODE_POP 0xbc00
b99bd4ef 654
2fc8bdac 655#define T_OPCODE_BRANCH 0xe000
b99bd4ef 656
a737bd4d 657#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 658#define THUMB_PP_PC_LR 0x0100
c19d1205 659#define THUMB_LOAD_BIT 0x0800
53365c0d 660#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
661
662#define BAD_ARGS _("bad arguments to instruction")
663#define BAD_PC _("r15 not allowed here")
664#define BAD_COND _("instruction cannot be conditional")
665#define BAD_OVERLAP _("registers may not be the same")
666#define BAD_HIREG _("lo register required")
667#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 668#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
669#define BAD_BRANCH _("branch must be last instruction in IT block")
670#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 671#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
672
673static struct hash_control *arm_ops_hsh;
674static struct hash_control *arm_cond_hsh;
675static struct hash_control *arm_shift_hsh;
676static struct hash_control *arm_psr_hsh;
62b3e311 677static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
678static struct hash_control *arm_reg_hsh;
679static struct hash_control *arm_reloc_hsh;
62b3e311 680static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 681
b99bd4ef
NC
682/* Stuff needed to resolve the label ambiguity
683 As:
684 ...
685 label: <insn>
686 may differ from:
687 ...
688 label:
5f4273c7 689 <insn> */
b99bd4ef
NC
690
691symbolS * last_label_seen;
b34976b6 692static int label_is_thumb_function_name = FALSE;
a737bd4d 693\f
3d0c9500
NC
694/* Literal pool structure. Held on a per-section
695 and per-sub-section basis. */
a737bd4d 696
c19d1205 697#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 698typedef struct literal_pool
b99bd4ef 699{
c19d1205
ZW
700 expressionS literals [MAX_LITERAL_POOL_SIZE];
701 unsigned int next_free_entry;
702 unsigned int id;
703 symbolS * symbol;
704 segT section;
705 subsegT sub_section;
61b5f74b 706 struct literal_pool * next;
3d0c9500 707} literal_pool;
b99bd4ef 708
3d0c9500
NC
709/* Pointer to a linked list of literal pools. */
710literal_pool * list_of_pools = NULL;
e27ec89e
PB
711
712/* State variables for IT block handling. */
713static bfd_boolean current_it_mask = 0;
714static int current_cc;
c19d1205
ZW
715\f
716/* Pure syntax. */
b99bd4ef 717
c19d1205
ZW
718/* This array holds the chars that always start a comment. If the
719 pre-processor is disabled, these aren't very useful. */
720const char comment_chars[] = "@";
3d0c9500 721
c19d1205
ZW
722/* This array holds the chars that only start a comment at the beginning of
723 a line. If the line seems to have the form '# 123 filename'
724 .line and .file directives will appear in the pre-processed output. */
725/* Note that input_file.c hand checks for '#' at the beginning of the
726 first line of the input file. This is because the compiler outputs
727 #NO_APP at the beginning of its output. */
728/* Also note that comments like this one will always work. */
729const char line_comment_chars[] = "#";
3d0c9500 730
c19d1205 731const char line_separator_chars[] = ";";
b99bd4ef 732
c19d1205
ZW
733/* Chars that can be used to separate mant
734 from exp in floating point numbers. */
735const char EXP_CHARS[] = "eE";
3d0c9500 736
c19d1205
ZW
737/* Chars that mean this number is a floating point constant. */
738/* As in 0f12.456 */
739/* or 0d1.2345e12 */
b99bd4ef 740
c19d1205 741const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 742
c19d1205
ZW
743/* Prefix characters that indicate the start of an immediate
744 value. */
745#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 746
c19d1205
ZW
747/* Separator character handling. */
748
749#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
750
751static inline int
752skip_past_char (char ** str, char c)
753{
754 if (**str == c)
755 {
756 (*str)++;
757 return SUCCESS;
3d0c9500 758 }
c19d1205
ZW
759 else
760 return FAIL;
761}
762#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 763
c19d1205
ZW
764/* Arithmetic expressions (possibly involving symbols). */
765
766/* Return TRUE if anything in the expression is a bignum. */
767
768static int
769walk_no_bignums (symbolS * sp)
770{
771 if (symbol_get_value_expression (sp)->X_op == O_big)
772 return 1;
773
774 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 775 {
c19d1205
ZW
776 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
777 || (symbol_get_value_expression (sp)->X_op_symbol
778 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
779 }
780
c19d1205 781 return 0;
3d0c9500
NC
782}
783
c19d1205
ZW
784static int in_my_get_expression = 0;
785
786/* Third argument to my_get_expression. */
787#define GE_NO_PREFIX 0
788#define GE_IMM_PREFIX 1
789#define GE_OPT_PREFIX 2
5287ad62
JB
790/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
791 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
792#define GE_OPT_PREFIX_BIG 3
a737bd4d 793
b99bd4ef 794static int
c19d1205 795my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 796{
c19d1205
ZW
797 char * save_in;
798 segT seg;
b99bd4ef 799
c19d1205
ZW
800 /* In unified syntax, all prefixes are optional. */
801 if (unified_syntax)
5287ad62
JB
802 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
803 : GE_OPT_PREFIX;
b99bd4ef 804
c19d1205 805 switch (prefix_mode)
b99bd4ef 806 {
c19d1205
ZW
807 case GE_NO_PREFIX: break;
808 case GE_IMM_PREFIX:
809 if (!is_immediate_prefix (**str))
810 {
811 inst.error = _("immediate expression requires a # prefix");
812 return FAIL;
813 }
814 (*str)++;
815 break;
816 case GE_OPT_PREFIX:
5287ad62 817 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
818 if (is_immediate_prefix (**str))
819 (*str)++;
820 break;
821 default: abort ();
822 }
b99bd4ef 823
c19d1205 824 memset (ep, 0, sizeof (expressionS));
b99bd4ef 825
c19d1205
ZW
826 save_in = input_line_pointer;
827 input_line_pointer = *str;
828 in_my_get_expression = 1;
829 seg = expression (ep);
830 in_my_get_expression = 0;
831
832 if (ep->X_op == O_illegal)
b99bd4ef 833 {
c19d1205
ZW
834 /* We found a bad expression in md_operand(). */
835 *str = input_line_pointer;
836 input_line_pointer = save_in;
837 if (inst.error == NULL)
838 inst.error = _("bad expression");
839 return 1;
840 }
b99bd4ef 841
c19d1205
ZW
842#ifdef OBJ_AOUT
843 if (seg != absolute_section
844 && seg != text_section
845 && seg != data_section
846 && seg != bss_section
847 && seg != undefined_section)
848 {
849 inst.error = _("bad segment");
850 *str = input_line_pointer;
851 input_line_pointer = save_in;
852 return 1;
b99bd4ef 853 }
c19d1205 854#endif
b99bd4ef 855
c19d1205
ZW
856 /* Get rid of any bignums now, so that we don't generate an error for which
857 we can't establish a line number later on. Big numbers are never valid
858 in instructions, which is where this routine is always called. */
5287ad62
JB
859 if (prefix_mode != GE_OPT_PREFIX_BIG
860 && (ep->X_op == O_big
861 || (ep->X_add_symbol
862 && (walk_no_bignums (ep->X_add_symbol)
863 || (ep->X_op_symbol
864 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
865 {
866 inst.error = _("invalid constant");
867 *str = input_line_pointer;
868 input_line_pointer = save_in;
869 return 1;
870 }
b99bd4ef 871
c19d1205
ZW
872 *str = input_line_pointer;
873 input_line_pointer = save_in;
874 return 0;
b99bd4ef
NC
875}
876
c19d1205
ZW
877/* Turn a string in input_line_pointer into a floating point constant
878 of type TYPE, and store the appropriate bytes in *LITP. The number
879 of LITTLENUMS emitted is stored in *SIZEP. An error message is
880 returned, or NULL on OK.
b99bd4ef 881
c19d1205
ZW
882 Note that fp constants aren't represent in the normal way on the ARM.
883 In big endian mode, things are as expected. However, in little endian
884 mode fp constants are big-endian word-wise, and little-endian byte-wise
885 within the words. For example, (double) 1.1 in big endian mode is
886 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
887 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 888
c19d1205 889 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 890
c19d1205
ZW
891char *
892md_atof (int type, char * litP, int * sizeP)
893{
894 int prec;
895 LITTLENUM_TYPE words[MAX_LITTLENUMS];
896 char *t;
897 int i;
b99bd4ef 898
c19d1205
ZW
899 switch (type)
900 {
901 case 'f':
902 case 'F':
903 case 's':
904 case 'S':
905 prec = 2;
906 break;
b99bd4ef 907
c19d1205
ZW
908 case 'd':
909 case 'D':
910 case 'r':
911 case 'R':
912 prec = 4;
913 break;
b99bd4ef 914
c19d1205
ZW
915 case 'x':
916 case 'X':
499ac353 917 prec = 5;
c19d1205 918 break;
b99bd4ef 919
c19d1205
ZW
920 case 'p':
921 case 'P':
499ac353 922 prec = 5;
c19d1205 923 break;
a737bd4d 924
c19d1205
ZW
925 default:
926 *sizeP = 0;
499ac353 927 return _("Unrecognized or unsupported floating point constant");
c19d1205 928 }
b99bd4ef 929
c19d1205
ZW
930 t = atof_ieee (input_line_pointer, type, words);
931 if (t)
932 input_line_pointer = t;
499ac353 933 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 934
c19d1205
ZW
935 if (target_big_endian)
936 {
937 for (i = 0; i < prec; i++)
938 {
499ac353
NC
939 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
940 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
941 }
942 }
943 else
944 {
e74cfd16 945 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
946 for (i = prec - 1; i >= 0; i--)
947 {
499ac353
NC
948 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
949 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
950 }
951 else
952 /* For a 4 byte float the order of elements in `words' is 1 0.
953 For an 8 byte float the order is 1 0 3 2. */
954 for (i = 0; i < prec; i += 2)
955 {
499ac353
NC
956 md_number_to_chars (litP, (valueT) words[i + 1],
957 sizeof (LITTLENUM_TYPE));
958 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
959 (valueT) words[i], sizeof (LITTLENUM_TYPE));
960 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
961 }
962 }
b99bd4ef 963
499ac353 964 return NULL;
c19d1205 965}
b99bd4ef 966
c19d1205
ZW
967/* We handle all bad expressions here, so that we can report the faulty
968 instruction in the error message. */
969void
970md_operand (expressionS * expr)
971{
972 if (in_my_get_expression)
973 expr->X_op = O_illegal;
b99bd4ef
NC
974}
975
c19d1205 976/* Immediate values. */
b99bd4ef 977
c19d1205
ZW
978/* Generic immediate-value read function for use in directives.
979 Accepts anything that 'expression' can fold to a constant.
980 *val receives the number. */
981#ifdef OBJ_ELF
982static int
983immediate_for_directive (int *val)
b99bd4ef 984{
c19d1205
ZW
985 expressionS exp;
986 exp.X_op = O_illegal;
b99bd4ef 987
c19d1205
ZW
988 if (is_immediate_prefix (*input_line_pointer))
989 {
990 input_line_pointer++;
991 expression (&exp);
992 }
b99bd4ef 993
c19d1205
ZW
994 if (exp.X_op != O_constant)
995 {
996 as_bad (_("expected #constant"));
997 ignore_rest_of_line ();
998 return FAIL;
999 }
1000 *val = exp.X_add_number;
1001 return SUCCESS;
b99bd4ef 1002}
c19d1205 1003#endif
b99bd4ef 1004
c19d1205 1005/* Register parsing. */
b99bd4ef 1006
c19d1205
ZW
1007/* Generic register parser. CCP points to what should be the
1008 beginning of a register name. If it is indeed a valid register
1009 name, advance CCP over it and return the reg_entry structure;
1010 otherwise return NULL. Does not issue diagnostics. */
1011
1012static struct reg_entry *
1013arm_reg_parse_multi (char **ccp)
b99bd4ef 1014{
c19d1205
ZW
1015 char *start = *ccp;
1016 char *p;
1017 struct reg_entry *reg;
b99bd4ef 1018
c19d1205
ZW
1019#ifdef REGISTER_PREFIX
1020 if (*start != REGISTER_PREFIX)
01cfc07f 1021 return NULL;
c19d1205
ZW
1022 start++;
1023#endif
1024#ifdef OPTIONAL_REGISTER_PREFIX
1025 if (*start == OPTIONAL_REGISTER_PREFIX)
1026 start++;
1027#endif
b99bd4ef 1028
c19d1205
ZW
1029 p = start;
1030 if (!ISALPHA (*p) || !is_name_beginner (*p))
1031 return NULL;
b99bd4ef 1032
c19d1205
ZW
1033 do
1034 p++;
1035 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1036
1037 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1038
1039 if (!reg)
1040 return NULL;
1041
1042 *ccp = p;
1043 return reg;
b99bd4ef
NC
1044}
1045
1046static int
dcbf9037
JB
1047arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1048 enum arm_reg_type type)
b99bd4ef 1049{
c19d1205
ZW
1050 /* Alternative syntaxes are accepted for a few register classes. */
1051 switch (type)
1052 {
1053 case REG_TYPE_MVF:
1054 case REG_TYPE_MVD:
1055 case REG_TYPE_MVFX:
1056 case REG_TYPE_MVDX:
1057 /* Generic coprocessor register names are allowed for these. */
79134647 1058 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1059 return reg->number;
1060 break;
69b97547 1061
c19d1205
ZW
1062 case REG_TYPE_CP:
1063 /* For backward compatibility, a bare number is valid here. */
1064 {
1065 unsigned long processor = strtoul (start, ccp, 10);
1066 if (*ccp != start && processor <= 15)
1067 return processor;
1068 }
6057a28f 1069
c19d1205
ZW
1070 case REG_TYPE_MMXWC:
1071 /* WC includes WCG. ??? I'm not sure this is true for all
1072 instructions that take WC registers. */
79134647 1073 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1074 return reg->number;
6057a28f 1075 break;
c19d1205 1076
6057a28f 1077 default:
c19d1205 1078 break;
6057a28f
NC
1079 }
1080
dcbf9037
JB
1081 return FAIL;
1082}
1083
1084/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1085 return value is the register number or FAIL. */
1086
1087static int
1088arm_reg_parse (char **ccp, enum arm_reg_type type)
1089{
1090 char *start = *ccp;
1091 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1092 int ret;
1093
1094 /* Do not allow a scalar (reg+index) to parse as a register. */
1095 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1096 return FAIL;
1097
1098 if (reg && reg->type == type)
1099 return reg->number;
1100
1101 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1102 return ret;
1103
c19d1205
ZW
1104 *ccp = start;
1105 return FAIL;
1106}
69b97547 1107
dcbf9037
JB
1108/* Parse a Neon type specifier. *STR should point at the leading '.'
1109 character. Does no verification at this stage that the type fits the opcode
1110 properly. E.g.,
1111
1112 .i32.i32.s16
1113 .s32.f32
1114 .u16
1115
1116 Can all be legally parsed by this function.
1117
1118 Fills in neon_type struct pointer with parsed information, and updates STR
1119 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1120 type, FAIL if not. */
1121
1122static int
1123parse_neon_type (struct neon_type *type, char **str)
1124{
1125 char *ptr = *str;
1126
1127 if (type)
1128 type->elems = 0;
1129
1130 while (type->elems < NEON_MAX_TYPE_ELS)
1131 {
1132 enum neon_el_type thistype = NT_untyped;
1133 unsigned thissize = -1u;
1134
1135 if (*ptr != '.')
1136 break;
1137
1138 ptr++;
1139
1140 /* Just a size without an explicit type. */
1141 if (ISDIGIT (*ptr))
1142 goto parsesize;
1143
1144 switch (TOLOWER (*ptr))
1145 {
1146 case 'i': thistype = NT_integer; break;
1147 case 'f': thistype = NT_float; break;
1148 case 'p': thistype = NT_poly; break;
1149 case 's': thistype = NT_signed; break;
1150 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1151 case 'd':
1152 thistype = NT_float;
1153 thissize = 64;
1154 ptr++;
1155 goto done;
dcbf9037
JB
1156 default:
1157 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1158 return FAIL;
1159 }
1160
1161 ptr++;
1162
1163 /* .f is an abbreviation for .f32. */
1164 if (thistype == NT_float && !ISDIGIT (*ptr))
1165 thissize = 32;
1166 else
1167 {
1168 parsesize:
1169 thissize = strtoul (ptr, &ptr, 10);
1170
1171 if (thissize != 8 && thissize != 16 && thissize != 32
1172 && thissize != 64)
1173 {
1174 as_bad (_("bad size %d in type specifier"), thissize);
1175 return FAIL;
1176 }
1177 }
1178
037e8744 1179 done:
dcbf9037
JB
1180 if (type)
1181 {
1182 type->el[type->elems].type = thistype;
1183 type->el[type->elems].size = thissize;
1184 type->elems++;
1185 }
1186 }
1187
1188 /* Empty/missing type is not a successful parse. */
1189 if (type->elems == 0)
1190 return FAIL;
1191
1192 *str = ptr;
1193
1194 return SUCCESS;
1195}
1196
1197/* Errors may be set multiple times during parsing or bit encoding
1198 (particularly in the Neon bits), but usually the earliest error which is set
1199 will be the most meaningful. Avoid overwriting it with later (cascading)
1200 errors by calling this function. */
1201
1202static void
1203first_error (const char *err)
1204{
1205 if (!inst.error)
1206 inst.error = err;
1207}
1208
1209/* Parse a single type, e.g. ".s32", leading period included. */
1210static int
1211parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1212{
1213 char *str = *ccp;
1214 struct neon_type optype;
1215
1216 if (*str == '.')
1217 {
1218 if (parse_neon_type (&optype, &str) == SUCCESS)
1219 {
1220 if (optype.elems == 1)
1221 *vectype = optype.el[0];
1222 else
1223 {
1224 first_error (_("only one type should be specified for operand"));
1225 return FAIL;
1226 }
1227 }
1228 else
1229 {
1230 first_error (_("vector type expected"));
1231 return FAIL;
1232 }
1233 }
1234 else
1235 return FAIL;
5f4273c7 1236
dcbf9037 1237 *ccp = str;
5f4273c7 1238
dcbf9037
JB
1239 return SUCCESS;
1240}
1241
1242/* Special meanings for indices (which have a range of 0-7), which will fit into
1243 a 4-bit integer. */
1244
1245#define NEON_ALL_LANES 15
1246#define NEON_INTERLEAVE_LANES 14
1247
1248/* Parse either a register or a scalar, with an optional type. Return the
1249 register number, and optionally fill in the actual type of the register
1250 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1251 type/index information in *TYPEINFO. */
1252
1253static int
1254parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1255 enum arm_reg_type *rtype,
1256 struct neon_typed_alias *typeinfo)
1257{
1258 char *str = *ccp;
1259 struct reg_entry *reg = arm_reg_parse_multi (&str);
1260 struct neon_typed_alias atype;
1261 struct neon_type_el parsetype;
1262
1263 atype.defined = 0;
1264 atype.index = -1;
1265 atype.eltype.type = NT_invtype;
1266 atype.eltype.size = -1;
1267
1268 /* Try alternate syntax for some types of register. Note these are mutually
1269 exclusive with the Neon syntax extensions. */
1270 if (reg == NULL)
1271 {
1272 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1273 if (altreg != FAIL)
1274 *ccp = str;
1275 if (typeinfo)
1276 *typeinfo = atype;
1277 return altreg;
1278 }
1279
037e8744
JB
1280 /* Undo polymorphism when a set of register types may be accepted. */
1281 if ((type == REG_TYPE_NDQ
1282 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1283 || (type == REG_TYPE_VFSD
1284 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1285 || (type == REG_TYPE_NSDQ
1286 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1287 || reg->type == REG_TYPE_NQ))
1288 || (type == REG_TYPE_MMXWC
1289 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1290 type = reg->type;
1291
1292 if (type != reg->type)
1293 return FAIL;
1294
1295 if (reg->neon)
1296 atype = *reg->neon;
5f4273c7 1297
dcbf9037
JB
1298 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1299 {
1300 if ((atype.defined & NTA_HASTYPE) != 0)
1301 {
1302 first_error (_("can't redefine type for operand"));
1303 return FAIL;
1304 }
1305 atype.defined |= NTA_HASTYPE;
1306 atype.eltype = parsetype;
1307 }
5f4273c7 1308
dcbf9037
JB
1309 if (skip_past_char (&str, '[') == SUCCESS)
1310 {
1311 if (type != REG_TYPE_VFD)
1312 {
1313 first_error (_("only D registers may be indexed"));
1314 return FAIL;
1315 }
5f4273c7 1316
dcbf9037
JB
1317 if ((atype.defined & NTA_HASINDEX) != 0)
1318 {
1319 first_error (_("can't change index for operand"));
1320 return FAIL;
1321 }
1322
1323 atype.defined |= NTA_HASINDEX;
1324
1325 if (skip_past_char (&str, ']') == SUCCESS)
1326 atype.index = NEON_ALL_LANES;
1327 else
1328 {
1329 expressionS exp;
1330
1331 my_get_expression (&exp, &str, GE_NO_PREFIX);
1332
1333 if (exp.X_op != O_constant)
1334 {
1335 first_error (_("constant expression required"));
1336 return FAIL;
1337 }
1338
1339 if (skip_past_char (&str, ']') == FAIL)
1340 return FAIL;
1341
1342 atype.index = exp.X_add_number;
1343 }
1344 }
5f4273c7 1345
dcbf9037
JB
1346 if (typeinfo)
1347 *typeinfo = atype;
5f4273c7 1348
dcbf9037
JB
1349 if (rtype)
1350 *rtype = type;
5f4273c7 1351
dcbf9037 1352 *ccp = str;
5f4273c7 1353
dcbf9037
JB
1354 return reg->number;
1355}
1356
1357/* Like arm_reg_parse, but allow allow the following extra features:
1358 - If RTYPE is non-zero, return the (possibly restricted) type of the
1359 register (e.g. Neon double or quad reg when either has been requested).
1360 - If this is a Neon vector type with additional type information, fill
1361 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1362 This function will fault on encountering a scalar. */
dcbf9037
JB
1363
1364static int
1365arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1366 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1367{
1368 struct neon_typed_alias atype;
1369 char *str = *ccp;
1370 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1371
1372 if (reg == FAIL)
1373 return FAIL;
1374
1375 /* Do not allow a scalar (reg+index) to parse as a register. */
1376 if ((atype.defined & NTA_HASINDEX) != 0)
1377 {
1378 first_error (_("register operand expected, but got scalar"));
1379 return FAIL;
1380 }
1381
1382 if (vectype)
1383 *vectype = atype.eltype;
1384
1385 *ccp = str;
1386
1387 return reg;
1388}
1389
1390#define NEON_SCALAR_REG(X) ((X) >> 4)
1391#define NEON_SCALAR_INDEX(X) ((X) & 15)
1392
5287ad62
JB
1393/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1394 have enough information to be able to do a good job bounds-checking. So, we
1395 just do easy checks here, and do further checks later. */
1396
1397static int
dcbf9037 1398parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1399{
dcbf9037 1400 int reg;
5287ad62 1401 char *str = *ccp;
dcbf9037 1402 struct neon_typed_alias atype;
5f4273c7 1403
dcbf9037 1404 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1405
dcbf9037 1406 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1407 return FAIL;
5f4273c7 1408
dcbf9037 1409 if (atype.index == NEON_ALL_LANES)
5287ad62 1410 {
dcbf9037 1411 first_error (_("scalar must have an index"));
5287ad62
JB
1412 return FAIL;
1413 }
dcbf9037 1414 else if (atype.index >= 64 / elsize)
5287ad62 1415 {
dcbf9037 1416 first_error (_("scalar index out of range"));
5287ad62
JB
1417 return FAIL;
1418 }
5f4273c7 1419
dcbf9037
JB
1420 if (type)
1421 *type = atype.eltype;
5f4273c7 1422
5287ad62 1423 *ccp = str;
5f4273c7 1424
dcbf9037 1425 return reg * 16 + atype.index;
5287ad62
JB
1426}
1427
c19d1205
ZW
1428/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1429static long
1430parse_reg_list (char ** strp)
1431{
1432 char * str = * strp;
1433 long range = 0;
1434 int another_range;
a737bd4d 1435
c19d1205
ZW
1436 /* We come back here if we get ranges concatenated by '+' or '|'. */
1437 do
6057a28f 1438 {
c19d1205 1439 another_range = 0;
a737bd4d 1440
c19d1205
ZW
1441 if (*str == '{')
1442 {
1443 int in_range = 0;
1444 int cur_reg = -1;
a737bd4d 1445
c19d1205
ZW
1446 str++;
1447 do
1448 {
1449 int reg;
6057a28f 1450
dcbf9037 1451 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1452 {
dcbf9037 1453 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1454 return FAIL;
1455 }
a737bd4d 1456
c19d1205
ZW
1457 if (in_range)
1458 {
1459 int i;
a737bd4d 1460
c19d1205
ZW
1461 if (reg <= cur_reg)
1462 {
dcbf9037 1463 first_error (_("bad range in register list"));
c19d1205
ZW
1464 return FAIL;
1465 }
40a18ebd 1466
c19d1205
ZW
1467 for (i = cur_reg + 1; i < reg; i++)
1468 {
1469 if (range & (1 << i))
1470 as_tsktsk
1471 (_("Warning: duplicated register (r%d) in register list"),
1472 i);
1473 else
1474 range |= 1 << i;
1475 }
1476 in_range = 0;
1477 }
a737bd4d 1478
c19d1205
ZW
1479 if (range & (1 << reg))
1480 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1481 reg);
1482 else if (reg <= cur_reg)
1483 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1484
c19d1205
ZW
1485 range |= 1 << reg;
1486 cur_reg = reg;
1487 }
1488 while (skip_past_comma (&str) != FAIL
1489 || (in_range = 1, *str++ == '-'));
1490 str--;
a737bd4d 1491
c19d1205
ZW
1492 if (*str++ != '}')
1493 {
dcbf9037 1494 first_error (_("missing `}'"));
c19d1205
ZW
1495 return FAIL;
1496 }
1497 }
1498 else
1499 {
1500 expressionS expr;
40a18ebd 1501
c19d1205
ZW
1502 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1503 return FAIL;
40a18ebd 1504
c19d1205
ZW
1505 if (expr.X_op == O_constant)
1506 {
1507 if (expr.X_add_number
1508 != (expr.X_add_number & 0x0000ffff))
1509 {
1510 inst.error = _("invalid register mask");
1511 return FAIL;
1512 }
a737bd4d 1513
c19d1205
ZW
1514 if ((range & expr.X_add_number) != 0)
1515 {
1516 int regno = range & expr.X_add_number;
a737bd4d 1517
c19d1205
ZW
1518 regno &= -regno;
1519 regno = (1 << regno) - 1;
1520 as_tsktsk
1521 (_("Warning: duplicated register (r%d) in register list"),
1522 regno);
1523 }
a737bd4d 1524
c19d1205
ZW
1525 range |= expr.X_add_number;
1526 }
1527 else
1528 {
1529 if (inst.reloc.type != 0)
1530 {
1531 inst.error = _("expression too complex");
1532 return FAIL;
1533 }
a737bd4d 1534
c19d1205
ZW
1535 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1536 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1537 inst.reloc.pc_rel = 0;
1538 }
1539 }
a737bd4d 1540
c19d1205
ZW
1541 if (*str == '|' || *str == '+')
1542 {
1543 str++;
1544 another_range = 1;
1545 }
a737bd4d 1546 }
c19d1205 1547 while (another_range);
a737bd4d 1548
c19d1205
ZW
1549 *strp = str;
1550 return range;
a737bd4d
NC
1551}
1552
5287ad62
JB
1553/* Types of registers in a list. */
1554
1555enum reg_list_els
1556{
1557 REGLIST_VFP_S,
1558 REGLIST_VFP_D,
1559 REGLIST_NEON_D
1560};
1561
c19d1205
ZW
1562/* Parse a VFP register list. If the string is invalid return FAIL.
1563 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1564 register. Parses registers of type ETYPE.
1565 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1566 - Q registers can be used to specify pairs of D registers
1567 - { } can be omitted from around a singleton register list
1568 FIXME: This is not implemented, as it would require backtracking in
1569 some cases, e.g.:
1570 vtbl.8 d3,d4,d5
1571 This could be done (the meaning isn't really ambiguous), but doesn't
1572 fit in well with the current parsing framework.
dcbf9037
JB
1573 - 32 D registers may be used (also true for VFPv3).
1574 FIXME: Types are ignored in these register lists, which is probably a
1575 bug. */
6057a28f 1576
c19d1205 1577static int
037e8744 1578parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1579{
037e8744 1580 char *str = *ccp;
c19d1205
ZW
1581 int base_reg;
1582 int new_base;
5287ad62
JB
1583 enum arm_reg_type regtype = 0;
1584 int max_regs = 0;
c19d1205
ZW
1585 int count = 0;
1586 int warned = 0;
1587 unsigned long mask = 0;
a737bd4d 1588 int i;
6057a28f 1589
037e8744 1590 if (*str != '{')
5287ad62
JB
1591 {
1592 inst.error = _("expecting {");
1593 return FAIL;
1594 }
6057a28f 1595
037e8744 1596 str++;
6057a28f 1597
5287ad62 1598 switch (etype)
c19d1205 1599 {
5287ad62 1600 case REGLIST_VFP_S:
c19d1205
ZW
1601 regtype = REG_TYPE_VFS;
1602 max_regs = 32;
5287ad62 1603 break;
5f4273c7 1604
5287ad62
JB
1605 case REGLIST_VFP_D:
1606 regtype = REG_TYPE_VFD;
b7fc2769 1607 break;
5f4273c7 1608
b7fc2769
JB
1609 case REGLIST_NEON_D:
1610 regtype = REG_TYPE_NDQ;
1611 break;
1612 }
1613
1614 if (etype != REGLIST_VFP_S)
1615 {
b1cc4aeb
PB
1616 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1617 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1618 {
1619 max_regs = 32;
1620 if (thumb_mode)
1621 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1622 fpu_vfp_ext_d32);
5287ad62
JB
1623 else
1624 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1625 fpu_vfp_ext_d32);
5287ad62
JB
1626 }
1627 else
1628 max_regs = 16;
c19d1205 1629 }
6057a28f 1630
c19d1205 1631 base_reg = max_regs;
a737bd4d 1632
c19d1205
ZW
1633 do
1634 {
5287ad62 1635 int setmask = 1, addregs = 1;
dcbf9037 1636
037e8744 1637 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1638
c19d1205 1639 if (new_base == FAIL)
a737bd4d 1640 {
dcbf9037 1641 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1642 return FAIL;
1643 }
5f4273c7 1644
b7fc2769
JB
1645 if (new_base >= max_regs)
1646 {
1647 first_error (_("register out of range in list"));
1648 return FAIL;
1649 }
5f4273c7 1650
5287ad62
JB
1651 /* Note: a value of 2 * n is returned for the register Q<n>. */
1652 if (regtype == REG_TYPE_NQ)
1653 {
1654 setmask = 3;
1655 addregs = 2;
1656 }
1657
c19d1205
ZW
1658 if (new_base < base_reg)
1659 base_reg = new_base;
a737bd4d 1660
5287ad62 1661 if (mask & (setmask << new_base))
c19d1205 1662 {
dcbf9037 1663 first_error (_("invalid register list"));
c19d1205 1664 return FAIL;
a737bd4d 1665 }
a737bd4d 1666
c19d1205
ZW
1667 if ((mask >> new_base) != 0 && ! warned)
1668 {
1669 as_tsktsk (_("register list not in ascending order"));
1670 warned = 1;
1671 }
0bbf2aa4 1672
5287ad62
JB
1673 mask |= setmask << new_base;
1674 count += addregs;
0bbf2aa4 1675
037e8744 1676 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1677 {
1678 int high_range;
0bbf2aa4 1679
037e8744 1680 str++;
0bbf2aa4 1681
037e8744 1682 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1683 == FAIL)
c19d1205
ZW
1684 {
1685 inst.error = gettext (reg_expected_msgs[regtype]);
1686 return FAIL;
1687 }
0bbf2aa4 1688
b7fc2769
JB
1689 if (high_range >= max_regs)
1690 {
1691 first_error (_("register out of range in list"));
1692 return FAIL;
1693 }
1694
5287ad62
JB
1695 if (regtype == REG_TYPE_NQ)
1696 high_range = high_range + 1;
1697
c19d1205
ZW
1698 if (high_range <= new_base)
1699 {
1700 inst.error = _("register range not in ascending order");
1701 return FAIL;
1702 }
0bbf2aa4 1703
5287ad62 1704 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1705 {
5287ad62 1706 if (mask & (setmask << new_base))
0bbf2aa4 1707 {
c19d1205
ZW
1708 inst.error = _("invalid register list");
1709 return FAIL;
0bbf2aa4 1710 }
c19d1205 1711
5287ad62
JB
1712 mask |= setmask << new_base;
1713 count += addregs;
0bbf2aa4 1714 }
0bbf2aa4 1715 }
0bbf2aa4 1716 }
037e8744 1717 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1718
037e8744 1719 str++;
0bbf2aa4 1720
c19d1205
ZW
1721 /* Sanity check -- should have raised a parse error above. */
1722 if (count == 0 || count > max_regs)
1723 abort ();
1724
1725 *pbase = base_reg;
1726
1727 /* Final test -- the registers must be consecutive. */
1728 mask >>= base_reg;
1729 for (i = 0; i < count; i++)
1730 {
1731 if ((mask & (1u << i)) == 0)
1732 {
1733 inst.error = _("non-contiguous register range");
1734 return FAIL;
1735 }
1736 }
1737
037e8744
JB
1738 *ccp = str;
1739
c19d1205 1740 return count;
b99bd4ef
NC
1741}
1742
dcbf9037
JB
1743/* True if two alias types are the same. */
1744
1745static int
1746neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1747{
1748 if (!a && !b)
1749 return 1;
5f4273c7 1750
dcbf9037
JB
1751 if (!a || !b)
1752 return 0;
1753
1754 if (a->defined != b->defined)
1755 return 0;
5f4273c7 1756
dcbf9037
JB
1757 if ((a->defined & NTA_HASTYPE) != 0
1758 && (a->eltype.type != b->eltype.type
1759 || a->eltype.size != b->eltype.size))
1760 return 0;
1761
1762 if ((a->defined & NTA_HASINDEX) != 0
1763 && (a->index != b->index))
1764 return 0;
5f4273c7 1765
dcbf9037
JB
1766 return 1;
1767}
1768
5287ad62
JB
1769/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1770 The base register is put in *PBASE.
dcbf9037 1771 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1772 the return value.
1773 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1774 Bits [6:5] encode the list length (minus one).
1775 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1776
5287ad62 1777#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1778#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1779#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1780
1781static int
dcbf9037
JB
1782parse_neon_el_struct_list (char **str, unsigned *pbase,
1783 struct neon_type_el *eltype)
5287ad62
JB
1784{
1785 char *ptr = *str;
1786 int base_reg = -1;
1787 int reg_incr = -1;
1788 int count = 0;
1789 int lane = -1;
1790 int leading_brace = 0;
1791 enum arm_reg_type rtype = REG_TYPE_NDQ;
1792 int addregs = 1;
1793 const char *const incr_error = "register stride must be 1 or 2";
1794 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1795 struct neon_typed_alias firsttype;
5f4273c7 1796
5287ad62
JB
1797 if (skip_past_char (&ptr, '{') == SUCCESS)
1798 leading_brace = 1;
5f4273c7 1799
5287ad62
JB
1800 do
1801 {
dcbf9037
JB
1802 struct neon_typed_alias atype;
1803 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1804
5287ad62
JB
1805 if (getreg == FAIL)
1806 {
dcbf9037 1807 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1808 return FAIL;
1809 }
5f4273c7 1810
5287ad62
JB
1811 if (base_reg == -1)
1812 {
1813 base_reg = getreg;
1814 if (rtype == REG_TYPE_NQ)
1815 {
1816 reg_incr = 1;
1817 addregs = 2;
1818 }
dcbf9037 1819 firsttype = atype;
5287ad62
JB
1820 }
1821 else if (reg_incr == -1)
1822 {
1823 reg_incr = getreg - base_reg;
1824 if (reg_incr < 1 || reg_incr > 2)
1825 {
dcbf9037 1826 first_error (_(incr_error));
5287ad62
JB
1827 return FAIL;
1828 }
1829 }
1830 else if (getreg != base_reg + reg_incr * count)
1831 {
dcbf9037
JB
1832 first_error (_(incr_error));
1833 return FAIL;
1834 }
1835
1836 if (!neon_alias_types_same (&atype, &firsttype))
1837 {
1838 first_error (_(type_error));
5287ad62
JB
1839 return FAIL;
1840 }
5f4273c7 1841
5287ad62
JB
1842 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1843 modes. */
1844 if (ptr[0] == '-')
1845 {
dcbf9037 1846 struct neon_typed_alias htype;
5287ad62
JB
1847 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1848 if (lane == -1)
1849 lane = NEON_INTERLEAVE_LANES;
1850 else if (lane != NEON_INTERLEAVE_LANES)
1851 {
dcbf9037 1852 first_error (_(type_error));
5287ad62
JB
1853 return FAIL;
1854 }
1855 if (reg_incr == -1)
1856 reg_incr = 1;
1857 else if (reg_incr != 1)
1858 {
dcbf9037 1859 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1860 return FAIL;
1861 }
1862 ptr++;
dcbf9037 1863 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1864 if (hireg == FAIL)
1865 {
dcbf9037
JB
1866 first_error (_(reg_expected_msgs[rtype]));
1867 return FAIL;
1868 }
1869 if (!neon_alias_types_same (&htype, &firsttype))
1870 {
1871 first_error (_(type_error));
5287ad62
JB
1872 return FAIL;
1873 }
1874 count += hireg + dregs - getreg;
1875 continue;
1876 }
5f4273c7 1877
5287ad62
JB
1878 /* If we're using Q registers, we can't use [] or [n] syntax. */
1879 if (rtype == REG_TYPE_NQ)
1880 {
1881 count += 2;
1882 continue;
1883 }
5f4273c7 1884
dcbf9037 1885 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1886 {
dcbf9037
JB
1887 if (lane == -1)
1888 lane = atype.index;
1889 else if (lane != atype.index)
5287ad62 1890 {
dcbf9037
JB
1891 first_error (_(type_error));
1892 return FAIL;
5287ad62
JB
1893 }
1894 }
1895 else if (lane == -1)
1896 lane = NEON_INTERLEAVE_LANES;
1897 else if (lane != NEON_INTERLEAVE_LANES)
1898 {
dcbf9037 1899 first_error (_(type_error));
5287ad62
JB
1900 return FAIL;
1901 }
1902 count++;
1903 }
1904 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1905
5287ad62
JB
1906 /* No lane set by [x]. We must be interleaving structures. */
1907 if (lane == -1)
1908 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1909
5287ad62
JB
1910 /* Sanity check. */
1911 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1912 || (count > 1 && reg_incr == -1))
1913 {
dcbf9037 1914 first_error (_("error parsing element/structure list"));
5287ad62
JB
1915 return FAIL;
1916 }
1917
1918 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1919 {
dcbf9037 1920 first_error (_("expected }"));
5287ad62
JB
1921 return FAIL;
1922 }
5f4273c7 1923
5287ad62
JB
1924 if (reg_incr == -1)
1925 reg_incr = 1;
1926
dcbf9037
JB
1927 if (eltype)
1928 *eltype = firsttype.eltype;
1929
5287ad62
JB
1930 *pbase = base_reg;
1931 *str = ptr;
5f4273c7 1932
5287ad62
JB
1933 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1934}
1935
c19d1205
ZW
1936/* Parse an explicit relocation suffix on an expression. This is
1937 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1938 arm_reloc_hsh contains no entries, so this function can only
1939 succeed if there is no () after the word. Returns -1 on error,
1940 BFD_RELOC_UNUSED if there wasn't any suffix. */
1941static int
1942parse_reloc (char **str)
b99bd4ef 1943{
c19d1205
ZW
1944 struct reloc_entry *r;
1945 char *p, *q;
b99bd4ef 1946
c19d1205
ZW
1947 if (**str != '(')
1948 return BFD_RELOC_UNUSED;
b99bd4ef 1949
c19d1205
ZW
1950 p = *str + 1;
1951 q = p;
1952
1953 while (*q && *q != ')' && *q != ',')
1954 q++;
1955 if (*q != ')')
1956 return -1;
1957
1958 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1959 return -1;
1960
1961 *str = q + 1;
1962 return r->reloc;
b99bd4ef
NC
1963}
1964
c19d1205
ZW
1965/* Directives: register aliases. */
1966
dcbf9037 1967static struct reg_entry *
c19d1205 1968insert_reg_alias (char *str, int number, int type)
b99bd4ef 1969{
c19d1205
ZW
1970 struct reg_entry *new;
1971 const char *name;
b99bd4ef 1972
c19d1205
ZW
1973 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1974 {
1975 if (new->builtin)
1976 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1977
c19d1205
ZW
1978 /* Only warn about a redefinition if it's not defined as the
1979 same register. */
1980 else if (new->number != number || new->type != type)
1981 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1982
d929913e 1983 return NULL;
c19d1205 1984 }
b99bd4ef 1985
c19d1205
ZW
1986 name = xstrdup (str);
1987 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1988
c19d1205
ZW
1989 new->name = name;
1990 new->number = number;
1991 new->type = type;
1992 new->builtin = FALSE;
dcbf9037 1993 new->neon = NULL;
b99bd4ef 1994
5a49b8ac 1995 if (hash_insert (arm_reg_hsh, name, (void *) new))
c19d1205 1996 abort ();
5f4273c7 1997
dcbf9037
JB
1998 return new;
1999}
2000
2001static void
2002insert_neon_reg_alias (char *str, int number, int type,
2003 struct neon_typed_alias *atype)
2004{
2005 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2006
dcbf9037
JB
2007 if (!reg)
2008 {
2009 first_error (_("attempt to redefine typed alias"));
2010 return;
2011 }
5f4273c7 2012
dcbf9037
JB
2013 if (atype)
2014 {
2015 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2016 *reg->neon = *atype;
2017 }
c19d1205 2018}
b99bd4ef 2019
c19d1205 2020/* Look for the .req directive. This is of the form:
b99bd4ef 2021
c19d1205 2022 new_register_name .req existing_register_name
b99bd4ef 2023
c19d1205 2024 If we find one, or if it looks sufficiently like one that we want to
d929913e 2025 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2026
d929913e 2027static bfd_boolean
c19d1205
ZW
2028create_register_alias (char * newname, char *p)
2029{
2030 struct reg_entry *old;
2031 char *oldname, *nbuf;
2032 size_t nlen;
b99bd4ef 2033
c19d1205
ZW
2034 /* The input scrubber ensures that whitespace after the mnemonic is
2035 collapsed to single spaces. */
2036 oldname = p;
2037 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2038 return FALSE;
b99bd4ef 2039
c19d1205
ZW
2040 oldname += 6;
2041 if (*oldname == '\0')
d929913e 2042 return FALSE;
b99bd4ef 2043
c19d1205
ZW
2044 old = hash_find (arm_reg_hsh, oldname);
2045 if (!old)
b99bd4ef 2046 {
c19d1205 2047 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2048 return TRUE;
b99bd4ef
NC
2049 }
2050
c19d1205
ZW
2051 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2052 the desired alias name, and p points to its end. If not, then
2053 the desired alias name is in the global original_case_string. */
2054#ifdef TC_CASE_SENSITIVE
2055 nlen = p - newname;
2056#else
2057 newname = original_case_string;
2058 nlen = strlen (newname);
2059#endif
b99bd4ef 2060
c19d1205
ZW
2061 nbuf = alloca (nlen + 1);
2062 memcpy (nbuf, newname, nlen);
2063 nbuf[nlen] = '\0';
b99bd4ef 2064
c19d1205
ZW
2065 /* Create aliases under the new name as stated; an all-lowercase
2066 version of the new name; and an all-uppercase version of the new
2067 name. */
d929913e
NC
2068 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2069 {
2070 for (p = nbuf; *p; p++)
2071 *p = TOUPPER (*p);
c19d1205 2072
d929913e
NC
2073 if (strncmp (nbuf, newname, nlen))
2074 {
2075 /* If this attempt to create an additional alias fails, do not bother
2076 trying to create the all-lower case alias. We will fail and issue
2077 a second, duplicate error message. This situation arises when the
2078 programmer does something like:
2079 foo .req r0
2080 Foo .req r1
2081 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2082 the artificial FOO alias because it has already been created by the
d929913e
NC
2083 first .req. */
2084 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2085 return TRUE;
2086 }
c19d1205 2087
d929913e
NC
2088 for (p = nbuf; *p; p++)
2089 *p = TOLOWER (*p);
c19d1205 2090
d929913e
NC
2091 if (strncmp (nbuf, newname, nlen))
2092 insert_reg_alias (nbuf, old->number, old->type);
2093 }
c19d1205 2094
d929913e 2095 return TRUE;
b99bd4ef
NC
2096}
2097
dcbf9037
JB
2098/* Create a Neon typed/indexed register alias using directives, e.g.:
2099 X .dn d5.s32[1]
2100 Y .qn 6.s16
2101 Z .dn d7
2102 T .dn Z[0]
2103 These typed registers can be used instead of the types specified after the
2104 Neon mnemonic, so long as all operands given have types. Types can also be
2105 specified directly, e.g.:
5f4273c7 2106 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2107
2108static int
2109create_neon_reg_alias (char *newname, char *p)
2110{
2111 enum arm_reg_type basetype;
2112 struct reg_entry *basereg;
2113 struct reg_entry mybasereg;
2114 struct neon_type ntype;
2115 struct neon_typed_alias typeinfo;
2116 char *namebuf, *nameend;
2117 int namelen;
5f4273c7 2118
dcbf9037
JB
2119 typeinfo.defined = 0;
2120 typeinfo.eltype.type = NT_invtype;
2121 typeinfo.eltype.size = -1;
2122 typeinfo.index = -1;
5f4273c7 2123
dcbf9037 2124 nameend = p;
5f4273c7 2125
dcbf9037
JB
2126 if (strncmp (p, " .dn ", 5) == 0)
2127 basetype = REG_TYPE_VFD;
2128 else if (strncmp (p, " .qn ", 5) == 0)
2129 basetype = REG_TYPE_NQ;
2130 else
2131 return 0;
5f4273c7 2132
dcbf9037 2133 p += 5;
5f4273c7 2134
dcbf9037
JB
2135 if (*p == '\0')
2136 return 0;
5f4273c7 2137
dcbf9037
JB
2138 basereg = arm_reg_parse_multi (&p);
2139
2140 if (basereg && basereg->type != basetype)
2141 {
2142 as_bad (_("bad type for register"));
2143 return 0;
2144 }
2145
2146 if (basereg == NULL)
2147 {
2148 expressionS exp;
2149 /* Try parsing as an integer. */
2150 my_get_expression (&exp, &p, GE_NO_PREFIX);
2151 if (exp.X_op != O_constant)
2152 {
2153 as_bad (_("expression must be constant"));
2154 return 0;
2155 }
2156 basereg = &mybasereg;
2157 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2158 : exp.X_add_number;
2159 basereg->neon = 0;
2160 }
2161
2162 if (basereg->neon)
2163 typeinfo = *basereg->neon;
2164
2165 if (parse_neon_type (&ntype, &p) == SUCCESS)
2166 {
2167 /* We got a type. */
2168 if (typeinfo.defined & NTA_HASTYPE)
2169 {
2170 as_bad (_("can't redefine the type of a register alias"));
2171 return 0;
2172 }
5f4273c7 2173
dcbf9037
JB
2174 typeinfo.defined |= NTA_HASTYPE;
2175 if (ntype.elems != 1)
2176 {
2177 as_bad (_("you must specify a single type only"));
2178 return 0;
2179 }
2180 typeinfo.eltype = ntype.el[0];
2181 }
5f4273c7 2182
dcbf9037
JB
2183 if (skip_past_char (&p, '[') == SUCCESS)
2184 {
2185 expressionS exp;
2186 /* We got a scalar index. */
5f4273c7 2187
dcbf9037
JB
2188 if (typeinfo.defined & NTA_HASINDEX)
2189 {
2190 as_bad (_("can't redefine the index of a scalar alias"));
2191 return 0;
2192 }
5f4273c7 2193
dcbf9037 2194 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2195
dcbf9037
JB
2196 if (exp.X_op != O_constant)
2197 {
2198 as_bad (_("scalar index must be constant"));
2199 return 0;
2200 }
5f4273c7 2201
dcbf9037
JB
2202 typeinfo.defined |= NTA_HASINDEX;
2203 typeinfo.index = exp.X_add_number;
5f4273c7 2204
dcbf9037
JB
2205 if (skip_past_char (&p, ']') == FAIL)
2206 {
2207 as_bad (_("expecting ]"));
2208 return 0;
2209 }
2210 }
2211
2212 namelen = nameend - newname;
2213 namebuf = alloca (namelen + 1);
2214 strncpy (namebuf, newname, namelen);
2215 namebuf[namelen] = '\0';
5f4273c7 2216
dcbf9037
JB
2217 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2218 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2219
dcbf9037
JB
2220 /* Insert name in all uppercase. */
2221 for (p = namebuf; *p; p++)
2222 *p = TOUPPER (*p);
5f4273c7 2223
dcbf9037
JB
2224 if (strncmp (namebuf, newname, namelen))
2225 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2226 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2227
dcbf9037
JB
2228 /* Insert name in all lowercase. */
2229 for (p = namebuf; *p; p++)
2230 *p = TOLOWER (*p);
5f4273c7 2231
dcbf9037
JB
2232 if (strncmp (namebuf, newname, namelen))
2233 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2234 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2235
dcbf9037
JB
2236 return 1;
2237}
2238
c19d1205
ZW
2239/* Should never be called, as .req goes between the alias and the
2240 register name, not at the beginning of the line. */
b99bd4ef 2241static void
c19d1205 2242s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2243{
c19d1205
ZW
2244 as_bad (_("invalid syntax for .req directive"));
2245}
b99bd4ef 2246
dcbf9037
JB
2247static void
2248s_dn (int a ATTRIBUTE_UNUSED)
2249{
2250 as_bad (_("invalid syntax for .dn directive"));
2251}
2252
2253static void
2254s_qn (int a ATTRIBUTE_UNUSED)
2255{
2256 as_bad (_("invalid syntax for .qn directive"));
2257}
2258
c19d1205
ZW
2259/* The .unreq directive deletes an alias which was previously defined
2260 by .req. For example:
b99bd4ef 2261
c19d1205
ZW
2262 my_alias .req r11
2263 .unreq my_alias */
b99bd4ef
NC
2264
2265static void
c19d1205 2266s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2267{
c19d1205
ZW
2268 char * name;
2269 char saved_char;
b99bd4ef 2270
c19d1205
ZW
2271 name = input_line_pointer;
2272
2273 while (*input_line_pointer != 0
2274 && *input_line_pointer != ' '
2275 && *input_line_pointer != '\n')
2276 ++input_line_pointer;
2277
2278 saved_char = *input_line_pointer;
2279 *input_line_pointer = 0;
2280
2281 if (!*name)
2282 as_bad (_("invalid syntax for .unreq directive"));
2283 else
2284 {
2285 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2286
2287 if (!reg)
2288 as_bad (_("unknown register alias '%s'"), name);
2289 else if (reg->builtin)
2290 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2291 name);
2292 else
2293 {
d929913e
NC
2294 char * p;
2295 char * nbuf;
2296
db0bc284 2297 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2298 free ((char *) reg->name);
dcbf9037
JB
2299 if (reg->neon)
2300 free (reg->neon);
c19d1205 2301 free (reg);
d929913e
NC
2302
2303 /* Also locate the all upper case and all lower case versions.
2304 Do not complain if we cannot find one or the other as it
2305 was probably deleted above. */
5f4273c7 2306
d929913e
NC
2307 nbuf = strdup (name);
2308 for (p = nbuf; *p; p++)
2309 *p = TOUPPER (*p);
2310 reg = hash_find (arm_reg_hsh, nbuf);
2311 if (reg)
2312 {
db0bc284 2313 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2314 free ((char *) reg->name);
2315 if (reg->neon)
2316 free (reg->neon);
2317 free (reg);
2318 }
2319
2320 for (p = nbuf; *p; p++)
2321 *p = TOLOWER (*p);
2322 reg = hash_find (arm_reg_hsh, nbuf);
2323 if (reg)
2324 {
db0bc284 2325 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2326 free ((char *) reg->name);
2327 if (reg->neon)
2328 free (reg->neon);
2329 free (reg);
2330 }
2331
2332 free (nbuf);
c19d1205
ZW
2333 }
2334 }
b99bd4ef 2335
c19d1205 2336 *input_line_pointer = saved_char;
b99bd4ef
NC
2337 demand_empty_rest_of_line ();
2338}
2339
c19d1205
ZW
2340/* Directives: Instruction set selection. */
2341
2342#ifdef OBJ_ELF
2343/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2344 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2345 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2346 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2347
2348static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2349
e821645d 2350void
c19d1205 2351mapping_state (enum mstate state)
b99bd4ef 2352{
a737bd4d 2353 symbolS * symbolP;
c19d1205
ZW
2354 const char * symname;
2355 int type;
b99bd4ef 2356
c19d1205
ZW
2357 if (mapstate == state)
2358 /* The mapping symbol has already been emitted.
2359 There is nothing else to do. */
2360 return;
b99bd4ef 2361
c19d1205 2362 mapstate = state;
b99bd4ef 2363
c19d1205 2364 switch (state)
b99bd4ef 2365 {
c19d1205
ZW
2366 case MAP_DATA:
2367 symname = "$d";
2368 type = BSF_NO_FLAGS;
2369 break;
2370 case MAP_ARM:
2371 symname = "$a";
2372 type = BSF_NO_FLAGS;
2373 break;
2374 case MAP_THUMB:
2375 symname = "$t";
2376 type = BSF_NO_FLAGS;
2377 break;
2378 case MAP_UNDEFINED:
2379 return;
2380 default:
2381 abort ();
2382 }
2383
2384 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2385
2386 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2387 symbol_table_insert (symbolP);
2388 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2389
2390 switch (state)
2391 {
2392 case MAP_ARM:
2393 THUMB_SET_FUNC (symbolP, 0);
2394 ARM_SET_THUMB (symbolP, 0);
2395 ARM_SET_INTERWORK (symbolP, support_interwork);
2396 break;
2397
2398 case MAP_THUMB:
2399 THUMB_SET_FUNC (symbolP, 1);
2400 ARM_SET_THUMB (symbolP, 1);
2401 ARM_SET_INTERWORK (symbolP, support_interwork);
2402 break;
2403
2404 case MAP_DATA:
2405 default:
2406 return;
2407 }
2408}
2409#else
2410#define mapping_state(x) /* nothing */
2411#endif
2412
2413/* Find the real, Thumb encoded start of a Thumb function. */
2414
2415static symbolS *
2416find_real_start (symbolS * symbolP)
2417{
2418 char * real_start;
2419 const char * name = S_GET_NAME (symbolP);
2420 symbolS * new_target;
2421
2422 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2423#define STUB_NAME ".real_start_of"
2424
2425 if (name == NULL)
2426 abort ();
2427
37f6032b
ZW
2428 /* The compiler may generate BL instructions to local labels because
2429 it needs to perform a branch to a far away location. These labels
2430 do not have a corresponding ".real_start_of" label. We check
2431 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2432 the ".real_start_of" convention for nonlocal branches. */
2433 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2434 return symbolP;
2435
37f6032b 2436 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2437 new_target = symbol_find (real_start);
2438
2439 if (new_target == NULL)
2440 {
bd3ba5d1 2441 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2442 new_target = symbolP;
2443 }
2444
c19d1205
ZW
2445 return new_target;
2446}
2447
2448static void
2449opcode_select (int width)
2450{
2451 switch (width)
2452 {
2453 case 16:
2454 if (! thumb_mode)
2455 {
e74cfd16 2456 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2457 as_bad (_("selected processor does not support THUMB opcodes"));
2458
2459 thumb_mode = 1;
2460 /* No need to force the alignment, since we will have been
2461 coming from ARM mode, which is word-aligned. */
2462 record_alignment (now_seg, 1);
2463 }
2464 mapping_state (MAP_THUMB);
2465 break;
2466
2467 case 32:
2468 if (thumb_mode)
2469 {
e74cfd16 2470 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2471 as_bad (_("selected processor does not support ARM opcodes"));
2472
2473 thumb_mode = 0;
2474
2475 if (!need_pass_2)
2476 frag_align (2, 0, 0);
2477
2478 record_alignment (now_seg, 1);
2479 }
2480 mapping_state (MAP_ARM);
2481 break;
2482
2483 default:
2484 as_bad (_("invalid instruction size selected (%d)"), width);
2485 }
2486}
2487
2488static void
2489s_arm (int ignore ATTRIBUTE_UNUSED)
2490{
2491 opcode_select (32);
2492 demand_empty_rest_of_line ();
2493}
2494
2495static void
2496s_thumb (int ignore ATTRIBUTE_UNUSED)
2497{
2498 opcode_select (16);
2499 demand_empty_rest_of_line ();
2500}
2501
2502static void
2503s_code (int unused ATTRIBUTE_UNUSED)
2504{
2505 int temp;
2506
2507 temp = get_absolute_expression ();
2508 switch (temp)
2509 {
2510 case 16:
2511 case 32:
2512 opcode_select (temp);
2513 break;
2514
2515 default:
2516 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2517 }
2518}
2519
2520static void
2521s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2522{
2523 /* If we are not already in thumb mode go into it, EVEN if
2524 the target processor does not support thumb instructions.
2525 This is used by gcc/config/arm/lib1funcs.asm for example
2526 to compile interworking support functions even if the
2527 target processor should not support interworking. */
2528 if (! thumb_mode)
2529 {
2530 thumb_mode = 2;
2531 record_alignment (now_seg, 1);
2532 }
2533
2534 demand_empty_rest_of_line ();
2535}
2536
2537static void
2538s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2539{
2540 s_thumb (0);
2541
2542 /* The following label is the name/address of the start of a Thumb function.
2543 We need to know this for the interworking support. */
2544 label_is_thumb_function_name = TRUE;
2545}
2546
2547/* Perform a .set directive, but also mark the alias as
2548 being a thumb function. */
2549
2550static void
2551s_thumb_set (int equiv)
2552{
2553 /* XXX the following is a duplicate of the code for s_set() in read.c
2554 We cannot just call that code as we need to get at the symbol that
2555 is created. */
2556 char * name;
2557 char delim;
2558 char * end_name;
2559 symbolS * symbolP;
2560
2561 /* Especial apologies for the random logic:
2562 This just grew, and could be parsed much more simply!
2563 Dean - in haste. */
2564 name = input_line_pointer;
2565 delim = get_symbol_end ();
2566 end_name = input_line_pointer;
2567 *end_name = delim;
2568
2569 if (*input_line_pointer != ',')
2570 {
2571 *end_name = 0;
2572 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2573 *end_name = delim;
2574 ignore_rest_of_line ();
2575 return;
2576 }
2577
2578 input_line_pointer++;
2579 *end_name = 0;
2580
2581 if (name[0] == '.' && name[1] == '\0')
2582 {
2583 /* XXX - this should not happen to .thumb_set. */
2584 abort ();
2585 }
2586
2587 if ((symbolP = symbol_find (name)) == NULL
2588 && (symbolP = md_undefined_symbol (name)) == NULL)
2589 {
2590#ifndef NO_LISTING
2591 /* When doing symbol listings, play games with dummy fragments living
2592 outside the normal fragment chain to record the file and line info
c19d1205 2593 for this symbol. */
b99bd4ef
NC
2594 if (listing & LISTING_SYMBOLS)
2595 {
2596 extern struct list_info_struct * listing_tail;
a737bd4d 2597 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2598
2599 memset (dummy_frag, 0, sizeof (fragS));
2600 dummy_frag->fr_type = rs_fill;
2601 dummy_frag->line = listing_tail;
2602 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2603 dummy_frag->fr_symbol = symbolP;
2604 }
2605 else
2606#endif
2607 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2608
2609#ifdef OBJ_COFF
2610 /* "set" symbols are local unless otherwise specified. */
2611 SF_SET_LOCAL (symbolP);
2612#endif /* OBJ_COFF */
2613 } /* Make a new symbol. */
2614
2615 symbol_table_insert (symbolP);
2616
2617 * end_name = delim;
2618
2619 if (equiv
2620 && S_IS_DEFINED (symbolP)
2621 && S_GET_SEGMENT (symbolP) != reg_section)
2622 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2623
2624 pseudo_set (symbolP);
2625
2626 demand_empty_rest_of_line ();
2627
c19d1205 2628 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2629
2630 THUMB_SET_FUNC (symbolP, 1);
2631 ARM_SET_THUMB (symbolP, 1);
2632#if defined OBJ_ELF || defined OBJ_COFF
2633 ARM_SET_INTERWORK (symbolP, support_interwork);
2634#endif
2635}
2636
c19d1205 2637/* Directives: Mode selection. */
b99bd4ef 2638
c19d1205
ZW
2639/* .syntax [unified|divided] - choose the new unified syntax
2640 (same for Arm and Thumb encoding, modulo slight differences in what
2641 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2642static void
c19d1205 2643s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2644{
c19d1205
ZW
2645 char *name, delim;
2646
2647 name = input_line_pointer;
2648 delim = get_symbol_end ();
2649
2650 if (!strcasecmp (name, "unified"))
2651 unified_syntax = TRUE;
2652 else if (!strcasecmp (name, "divided"))
2653 unified_syntax = FALSE;
2654 else
2655 {
2656 as_bad (_("unrecognized syntax mode \"%s\""), name);
2657 return;
2658 }
2659 *input_line_pointer = delim;
b99bd4ef
NC
2660 demand_empty_rest_of_line ();
2661}
2662
c19d1205
ZW
2663/* Directives: sectioning and alignment. */
2664
2665/* Same as s_align_ptwo but align 0 => align 2. */
2666
b99bd4ef 2667static void
c19d1205 2668s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2669{
a737bd4d 2670 int temp;
dce323d1 2671 bfd_boolean fill_p;
c19d1205
ZW
2672 long temp_fill;
2673 long max_alignment = 15;
b99bd4ef
NC
2674
2675 temp = get_absolute_expression ();
c19d1205
ZW
2676 if (temp > max_alignment)
2677 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2678 else if (temp < 0)
b99bd4ef 2679 {
c19d1205
ZW
2680 as_bad (_("alignment negative. 0 assumed."));
2681 temp = 0;
2682 }
b99bd4ef 2683
c19d1205
ZW
2684 if (*input_line_pointer == ',')
2685 {
2686 input_line_pointer++;
2687 temp_fill = get_absolute_expression ();
dce323d1 2688 fill_p = TRUE;
b99bd4ef 2689 }
c19d1205 2690 else
dce323d1
PB
2691 {
2692 fill_p = FALSE;
2693 temp_fill = 0;
2694 }
b99bd4ef 2695
c19d1205
ZW
2696 if (!temp)
2697 temp = 2;
b99bd4ef 2698
c19d1205
ZW
2699 /* Only make a frag if we HAVE to. */
2700 if (temp && !need_pass_2)
dce323d1
PB
2701 {
2702 if (!fill_p && subseg_text_p (now_seg))
2703 frag_align_code (temp, 0);
2704 else
2705 frag_align (temp, (int) temp_fill, 0);
2706 }
c19d1205
ZW
2707 demand_empty_rest_of_line ();
2708
2709 record_alignment (now_seg, temp);
b99bd4ef
NC
2710}
2711
c19d1205
ZW
2712static void
2713s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2714{
c19d1205
ZW
2715 /* We don't support putting frags in the BSS segment, we fake it by
2716 marking in_bss, then looking at s_skip for clues. */
2717 subseg_set (bss_section, 0);
2718 demand_empty_rest_of_line ();
2719 mapping_state (MAP_DATA);
2720}
b99bd4ef 2721
c19d1205
ZW
2722static void
2723s_even (int ignore ATTRIBUTE_UNUSED)
2724{
2725 /* Never make frag if expect extra pass. */
2726 if (!need_pass_2)
2727 frag_align (1, 0, 0);
b99bd4ef 2728
c19d1205 2729 record_alignment (now_seg, 1);
b99bd4ef 2730
c19d1205 2731 demand_empty_rest_of_line ();
b99bd4ef
NC
2732}
2733
c19d1205 2734/* Directives: Literal pools. */
a737bd4d 2735
c19d1205
ZW
2736static literal_pool *
2737find_literal_pool (void)
a737bd4d 2738{
c19d1205 2739 literal_pool * pool;
a737bd4d 2740
c19d1205 2741 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2742 {
c19d1205
ZW
2743 if (pool->section == now_seg
2744 && pool->sub_section == now_subseg)
2745 break;
a737bd4d
NC
2746 }
2747
c19d1205 2748 return pool;
a737bd4d
NC
2749}
2750
c19d1205
ZW
2751static literal_pool *
2752find_or_make_literal_pool (void)
a737bd4d 2753{
c19d1205
ZW
2754 /* Next literal pool ID number. */
2755 static unsigned int latest_pool_num = 1;
2756 literal_pool * pool;
a737bd4d 2757
c19d1205 2758 pool = find_literal_pool ();
a737bd4d 2759
c19d1205 2760 if (pool == NULL)
a737bd4d 2761 {
c19d1205
ZW
2762 /* Create a new pool. */
2763 pool = xmalloc (sizeof (* pool));
2764 if (! pool)
2765 return NULL;
a737bd4d 2766
c19d1205
ZW
2767 pool->next_free_entry = 0;
2768 pool->section = now_seg;
2769 pool->sub_section = now_subseg;
2770 pool->next = list_of_pools;
2771 pool->symbol = NULL;
2772
2773 /* Add it to the list. */
2774 list_of_pools = pool;
a737bd4d 2775 }
a737bd4d 2776
c19d1205
ZW
2777 /* New pools, and emptied pools, will have a NULL symbol. */
2778 if (pool->symbol == NULL)
a737bd4d 2779 {
c19d1205
ZW
2780 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2781 (valueT) 0, &zero_address_frag);
2782 pool->id = latest_pool_num ++;
a737bd4d
NC
2783 }
2784
c19d1205
ZW
2785 /* Done. */
2786 return pool;
a737bd4d
NC
2787}
2788
c19d1205 2789/* Add the literal in the global 'inst'
5f4273c7 2790 structure to the relevant literal pool. */
b99bd4ef
NC
2791
2792static int
c19d1205 2793add_to_lit_pool (void)
b99bd4ef 2794{
c19d1205
ZW
2795 literal_pool * pool;
2796 unsigned int entry;
b99bd4ef 2797
c19d1205
ZW
2798 pool = find_or_make_literal_pool ();
2799
2800 /* Check if this literal value is already in the pool. */
2801 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2802 {
c19d1205
ZW
2803 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2804 && (inst.reloc.exp.X_op == O_constant)
2805 && (pool->literals[entry].X_add_number
2806 == inst.reloc.exp.X_add_number)
2807 && (pool->literals[entry].X_unsigned
2808 == inst.reloc.exp.X_unsigned))
2809 break;
2810
2811 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2812 && (inst.reloc.exp.X_op == O_symbol)
2813 && (pool->literals[entry].X_add_number
2814 == inst.reloc.exp.X_add_number)
2815 && (pool->literals[entry].X_add_symbol
2816 == inst.reloc.exp.X_add_symbol)
2817 && (pool->literals[entry].X_op_symbol
2818 == inst.reloc.exp.X_op_symbol))
2819 break;
b99bd4ef
NC
2820 }
2821
c19d1205
ZW
2822 /* Do we need to create a new entry? */
2823 if (entry == pool->next_free_entry)
2824 {
2825 if (entry >= MAX_LITERAL_POOL_SIZE)
2826 {
2827 inst.error = _("literal pool overflow");
2828 return FAIL;
2829 }
2830
2831 pool->literals[entry] = inst.reloc.exp;
2832 pool->next_free_entry += 1;
2833 }
b99bd4ef 2834
c19d1205
ZW
2835 inst.reloc.exp.X_op = O_symbol;
2836 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2837 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2838
c19d1205 2839 return SUCCESS;
b99bd4ef
NC
2840}
2841
c19d1205
ZW
2842/* Can't use symbol_new here, so have to create a symbol and then at
2843 a later date assign it a value. Thats what these functions do. */
e16bb312 2844
c19d1205
ZW
2845static void
2846symbol_locate (symbolS * symbolP,
2847 const char * name, /* It is copied, the caller can modify. */
2848 segT segment, /* Segment identifier (SEG_<something>). */
2849 valueT valu, /* Symbol value. */
2850 fragS * frag) /* Associated fragment. */
2851{
2852 unsigned int name_length;
2853 char * preserved_copy_of_name;
e16bb312 2854
c19d1205
ZW
2855 name_length = strlen (name) + 1; /* +1 for \0. */
2856 obstack_grow (&notes, name, name_length);
2857 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2858
c19d1205
ZW
2859#ifdef tc_canonicalize_symbol_name
2860 preserved_copy_of_name =
2861 tc_canonicalize_symbol_name (preserved_copy_of_name);
2862#endif
b99bd4ef 2863
c19d1205 2864 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2865
c19d1205
ZW
2866 S_SET_SEGMENT (symbolP, segment);
2867 S_SET_VALUE (symbolP, valu);
2868 symbol_clear_list_pointers (symbolP);
b99bd4ef 2869
c19d1205 2870 symbol_set_frag (symbolP, frag);
b99bd4ef 2871
c19d1205
ZW
2872 /* Link to end of symbol chain. */
2873 {
2874 extern int symbol_table_frozen;
b99bd4ef 2875
c19d1205
ZW
2876 if (symbol_table_frozen)
2877 abort ();
2878 }
b99bd4ef 2879
c19d1205 2880 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2881
c19d1205 2882 obj_symbol_new_hook (symbolP);
b99bd4ef 2883
c19d1205
ZW
2884#ifdef tc_symbol_new_hook
2885 tc_symbol_new_hook (symbolP);
2886#endif
2887
2888#ifdef DEBUG_SYMS
2889 verify_symbol_chain (symbol_rootP, symbol_lastP);
2890#endif /* DEBUG_SYMS */
b99bd4ef
NC
2891}
2892
b99bd4ef 2893
c19d1205
ZW
2894static void
2895s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2896{
c19d1205
ZW
2897 unsigned int entry;
2898 literal_pool * pool;
2899 char sym_name[20];
b99bd4ef 2900
c19d1205
ZW
2901 pool = find_literal_pool ();
2902 if (pool == NULL
2903 || pool->symbol == NULL
2904 || pool->next_free_entry == 0)
2905 return;
b99bd4ef 2906
c19d1205 2907 mapping_state (MAP_DATA);
b99bd4ef 2908
c19d1205
ZW
2909 /* Align pool as you have word accesses.
2910 Only make a frag if we have to. */
2911 if (!need_pass_2)
2912 frag_align (2, 0, 0);
b99bd4ef 2913
c19d1205 2914 record_alignment (now_seg, 2);
b99bd4ef 2915
c19d1205 2916 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2917
c19d1205
ZW
2918 symbol_locate (pool->symbol, sym_name, now_seg,
2919 (valueT) frag_now_fix (), frag_now);
2920 symbol_table_insert (pool->symbol);
b99bd4ef 2921
c19d1205 2922 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2923
c19d1205
ZW
2924#if defined OBJ_COFF || defined OBJ_ELF
2925 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2926#endif
6c43fab6 2927
c19d1205
ZW
2928 for (entry = 0; entry < pool->next_free_entry; entry ++)
2929 /* First output the expression in the instruction to the pool. */
2930 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2931
c19d1205
ZW
2932 /* Mark the pool as empty. */
2933 pool->next_free_entry = 0;
2934 pool->symbol = NULL;
b99bd4ef
NC
2935}
2936
c19d1205
ZW
2937#ifdef OBJ_ELF
2938/* Forward declarations for functions below, in the MD interface
2939 section. */
2940static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2941static valueT create_unwind_entry (int);
2942static void start_unwind_section (const segT, int);
2943static void add_unwind_opcode (valueT, int);
2944static void flush_pending_unwind (void);
b99bd4ef 2945
c19d1205 2946/* Directives: Data. */
b99bd4ef 2947
c19d1205
ZW
2948static void
2949s_arm_elf_cons (int nbytes)
2950{
2951 expressionS exp;
b99bd4ef 2952
c19d1205
ZW
2953#ifdef md_flush_pending_output
2954 md_flush_pending_output ();
2955#endif
b99bd4ef 2956
c19d1205 2957 if (is_it_end_of_statement ())
b99bd4ef 2958 {
c19d1205
ZW
2959 demand_empty_rest_of_line ();
2960 return;
b99bd4ef
NC
2961 }
2962
c19d1205
ZW
2963#ifdef md_cons_align
2964 md_cons_align (nbytes);
2965#endif
b99bd4ef 2966
c19d1205
ZW
2967 mapping_state (MAP_DATA);
2968 do
b99bd4ef 2969 {
c19d1205
ZW
2970 int reloc;
2971 char *base = input_line_pointer;
b99bd4ef 2972
c19d1205 2973 expression (& exp);
b99bd4ef 2974
c19d1205
ZW
2975 if (exp.X_op != O_symbol)
2976 emit_expr (&exp, (unsigned int) nbytes);
2977 else
2978 {
2979 char *before_reloc = input_line_pointer;
2980 reloc = parse_reloc (&input_line_pointer);
2981 if (reloc == -1)
2982 {
2983 as_bad (_("unrecognized relocation suffix"));
2984 ignore_rest_of_line ();
2985 return;
2986 }
2987 else if (reloc == BFD_RELOC_UNUSED)
2988 emit_expr (&exp, (unsigned int) nbytes);
2989 else
2990 {
2991 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2992 int size = bfd_get_reloc_size (howto);
b99bd4ef 2993
2fc8bdac
ZW
2994 if (reloc == BFD_RELOC_ARM_PLT32)
2995 {
2996 as_bad (_("(plt) is only valid on branch targets"));
2997 reloc = BFD_RELOC_UNUSED;
2998 size = 0;
2999 }
3000
c19d1205 3001 if (size > nbytes)
2fc8bdac 3002 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3003 howto->name, nbytes);
3004 else
3005 {
3006 /* We've parsed an expression stopping at O_symbol.
3007 But there may be more expression left now that we
3008 have parsed the relocation marker. Parse it again.
3009 XXX Surely there is a cleaner way to do this. */
3010 char *p = input_line_pointer;
3011 int offset;
3012 char *save_buf = alloca (input_line_pointer - base);
3013 memcpy (save_buf, base, input_line_pointer - base);
3014 memmove (base + (input_line_pointer - before_reloc),
3015 base, before_reloc - base);
3016
3017 input_line_pointer = base + (input_line_pointer-before_reloc);
3018 expression (&exp);
3019 memcpy (base, save_buf, p - base);
3020
3021 offset = nbytes - size;
3022 p = frag_more ((int) nbytes);
3023 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3024 size, &exp, 0, reloc);
3025 }
3026 }
3027 }
b99bd4ef 3028 }
c19d1205 3029 while (*input_line_pointer++ == ',');
b99bd4ef 3030
c19d1205
ZW
3031 /* Put terminator back into stream. */
3032 input_line_pointer --;
3033 demand_empty_rest_of_line ();
b99bd4ef
NC
3034}
3035
b99bd4ef 3036
c19d1205 3037/* Parse a .rel31 directive. */
b99bd4ef 3038
c19d1205
ZW
3039static void
3040s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3041{
3042 expressionS exp;
3043 char *p;
3044 valueT highbit;
b99bd4ef 3045
c19d1205
ZW
3046 highbit = 0;
3047 if (*input_line_pointer == '1')
3048 highbit = 0x80000000;
3049 else if (*input_line_pointer != '0')
3050 as_bad (_("expected 0 or 1"));
b99bd4ef 3051
c19d1205
ZW
3052 input_line_pointer++;
3053 if (*input_line_pointer != ',')
3054 as_bad (_("missing comma"));
3055 input_line_pointer++;
b99bd4ef 3056
c19d1205
ZW
3057#ifdef md_flush_pending_output
3058 md_flush_pending_output ();
3059#endif
b99bd4ef 3060
c19d1205
ZW
3061#ifdef md_cons_align
3062 md_cons_align (4);
3063#endif
b99bd4ef 3064
c19d1205 3065 mapping_state (MAP_DATA);
b99bd4ef 3066
c19d1205 3067 expression (&exp);
b99bd4ef 3068
c19d1205
ZW
3069 p = frag_more (4);
3070 md_number_to_chars (p, highbit, 4);
3071 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3072 BFD_RELOC_ARM_PREL31);
b99bd4ef 3073
c19d1205 3074 demand_empty_rest_of_line ();
b99bd4ef
NC
3075}
3076
c19d1205 3077/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3078
c19d1205 3079/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3080
c19d1205
ZW
3081static void
3082s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3083{
3084 demand_empty_rest_of_line ();
3085 /* Mark the start of the function. */
3086 unwind.proc_start = expr_build_dot ();
b99bd4ef 3087
c19d1205
ZW
3088 /* Reset the rest of the unwind info. */
3089 unwind.opcode_count = 0;
3090 unwind.table_entry = NULL;
3091 unwind.personality_routine = NULL;
3092 unwind.personality_index = -1;
3093 unwind.frame_size = 0;
3094 unwind.fp_offset = 0;
3095 unwind.fp_reg = 13;
3096 unwind.fp_used = 0;
3097 unwind.sp_restored = 0;
3098}
b99bd4ef 3099
b99bd4ef 3100
c19d1205
ZW
3101/* Parse a handlerdata directive. Creates the exception handling table entry
3102 for the function. */
b99bd4ef 3103
c19d1205
ZW
3104static void
3105s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3106{
3107 demand_empty_rest_of_line ();
3108 if (unwind.table_entry)
6decc662 3109 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3110
c19d1205
ZW
3111 create_unwind_entry (1);
3112}
a737bd4d 3113
c19d1205 3114/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3115
c19d1205
ZW
3116static void
3117s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3118{
3119 long where;
3120 char *ptr;
3121 valueT val;
f02232aa 3122
c19d1205 3123 demand_empty_rest_of_line ();
f02232aa 3124
c19d1205
ZW
3125 /* Add eh table entry. */
3126 if (unwind.table_entry == NULL)
3127 val = create_unwind_entry (0);
3128 else
3129 val = 0;
f02232aa 3130
c19d1205
ZW
3131 /* Add index table entry. This is two words. */
3132 start_unwind_section (unwind.saved_seg, 1);
3133 frag_align (2, 0, 0);
3134 record_alignment (now_seg, 2);
b99bd4ef 3135
c19d1205
ZW
3136 ptr = frag_more (8);
3137 where = frag_now_fix () - 8;
f02232aa 3138
c19d1205
ZW
3139 /* Self relative offset of the function start. */
3140 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3141 BFD_RELOC_ARM_PREL31);
f02232aa 3142
c19d1205
ZW
3143 /* Indicate dependency on EHABI-defined personality routines to the
3144 linker, if it hasn't been done already. */
3145 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3146 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3147 {
5f4273c7
NC
3148 static const char *const name[] =
3149 {
3150 "__aeabi_unwind_cpp_pr0",
3151 "__aeabi_unwind_cpp_pr1",
3152 "__aeabi_unwind_cpp_pr2"
3153 };
c19d1205
ZW
3154 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3155 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3156 marked_pr_dependency |= 1 << unwind.personality_index;
3157 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3158 = marked_pr_dependency;
3159 }
f02232aa 3160
c19d1205
ZW
3161 if (val)
3162 /* Inline exception table entry. */
3163 md_number_to_chars (ptr + 4, val, 4);
3164 else
3165 /* Self relative offset of the table entry. */
3166 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3167 BFD_RELOC_ARM_PREL31);
f02232aa 3168
c19d1205
ZW
3169 /* Restore the original section. */
3170 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3171}
f02232aa 3172
f02232aa 3173
c19d1205 3174/* Parse an unwind_cantunwind directive. */
b99bd4ef 3175
c19d1205
ZW
3176static void
3177s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3178{
3179 demand_empty_rest_of_line ();
3180 if (unwind.personality_routine || unwind.personality_index != -1)
3181 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3182
c19d1205
ZW
3183 unwind.personality_index = -2;
3184}
b99bd4ef 3185
b99bd4ef 3186
c19d1205 3187/* Parse a personalityindex directive. */
b99bd4ef 3188
c19d1205
ZW
3189static void
3190s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3191{
3192 expressionS exp;
b99bd4ef 3193
c19d1205
ZW
3194 if (unwind.personality_routine || unwind.personality_index != -1)
3195 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3196
c19d1205 3197 expression (&exp);
b99bd4ef 3198
c19d1205
ZW
3199 if (exp.X_op != O_constant
3200 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3201 {
c19d1205
ZW
3202 as_bad (_("bad personality routine number"));
3203 ignore_rest_of_line ();
3204 return;
b99bd4ef
NC
3205 }
3206
c19d1205 3207 unwind.personality_index = exp.X_add_number;
b99bd4ef 3208
c19d1205
ZW
3209 demand_empty_rest_of_line ();
3210}
e16bb312 3211
e16bb312 3212
c19d1205 3213/* Parse a personality directive. */
e16bb312 3214
c19d1205
ZW
3215static void
3216s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3217{
3218 char *name, *p, c;
a737bd4d 3219
c19d1205
ZW
3220 if (unwind.personality_routine || unwind.personality_index != -1)
3221 as_bad (_("duplicate .personality directive"));
a737bd4d 3222
c19d1205
ZW
3223 name = input_line_pointer;
3224 c = get_symbol_end ();
3225 p = input_line_pointer;
3226 unwind.personality_routine = symbol_find_or_make (name);
3227 *p = c;
3228 demand_empty_rest_of_line ();
3229}
e16bb312 3230
e16bb312 3231
c19d1205 3232/* Parse a directive saving core registers. */
e16bb312 3233
c19d1205
ZW
3234static void
3235s_arm_unwind_save_core (void)
e16bb312 3236{
c19d1205
ZW
3237 valueT op;
3238 long range;
3239 int n;
e16bb312 3240
c19d1205
ZW
3241 range = parse_reg_list (&input_line_pointer);
3242 if (range == FAIL)
e16bb312 3243 {
c19d1205
ZW
3244 as_bad (_("expected register list"));
3245 ignore_rest_of_line ();
3246 return;
3247 }
e16bb312 3248
c19d1205 3249 demand_empty_rest_of_line ();
e16bb312 3250
c19d1205
ZW
3251 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3252 into .unwind_save {..., sp...}. We aren't bothered about the value of
3253 ip because it is clobbered by calls. */
3254 if (unwind.sp_restored && unwind.fp_reg == 12
3255 && (range & 0x3000) == 0x1000)
3256 {
3257 unwind.opcode_count--;
3258 unwind.sp_restored = 0;
3259 range = (range | 0x2000) & ~0x1000;
3260 unwind.pending_offset = 0;
3261 }
e16bb312 3262
01ae4198
DJ
3263 /* Pop r4-r15. */
3264 if (range & 0xfff0)
c19d1205 3265 {
01ae4198
DJ
3266 /* See if we can use the short opcodes. These pop a block of up to 8
3267 registers starting with r4, plus maybe r14. */
3268 for (n = 0; n < 8; n++)
3269 {
3270 /* Break at the first non-saved register. */
3271 if ((range & (1 << (n + 4))) == 0)
3272 break;
3273 }
3274 /* See if there are any other bits set. */
3275 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3276 {
3277 /* Use the long form. */
3278 op = 0x8000 | ((range >> 4) & 0xfff);
3279 add_unwind_opcode (op, 2);
3280 }
0dd132b6 3281 else
01ae4198
DJ
3282 {
3283 /* Use the short form. */
3284 if (range & 0x4000)
3285 op = 0xa8; /* Pop r14. */
3286 else
3287 op = 0xa0; /* Do not pop r14. */
3288 op |= (n - 1);
3289 add_unwind_opcode (op, 1);
3290 }
c19d1205 3291 }
0dd132b6 3292
c19d1205
ZW
3293 /* Pop r0-r3. */
3294 if (range & 0xf)
3295 {
3296 op = 0xb100 | (range & 0xf);
3297 add_unwind_opcode (op, 2);
0dd132b6
NC
3298 }
3299
c19d1205
ZW
3300 /* Record the number of bytes pushed. */
3301 for (n = 0; n < 16; n++)
3302 {
3303 if (range & (1 << n))
3304 unwind.frame_size += 4;
3305 }
0dd132b6
NC
3306}
3307
c19d1205
ZW
3308
3309/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3310
3311static void
c19d1205 3312s_arm_unwind_save_fpa (int reg)
b99bd4ef 3313{
c19d1205
ZW
3314 expressionS exp;
3315 int num_regs;
3316 valueT op;
b99bd4ef 3317
c19d1205
ZW
3318 /* Get Number of registers to transfer. */
3319 if (skip_past_comma (&input_line_pointer) != FAIL)
3320 expression (&exp);
3321 else
3322 exp.X_op = O_illegal;
b99bd4ef 3323
c19d1205 3324 if (exp.X_op != O_constant)
b99bd4ef 3325 {
c19d1205
ZW
3326 as_bad (_("expected , <constant>"));
3327 ignore_rest_of_line ();
b99bd4ef
NC
3328 return;
3329 }
3330
c19d1205
ZW
3331 num_regs = exp.X_add_number;
3332
3333 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3334 {
c19d1205
ZW
3335 as_bad (_("number of registers must be in the range [1:4]"));
3336 ignore_rest_of_line ();
b99bd4ef
NC
3337 return;
3338 }
3339
c19d1205 3340 demand_empty_rest_of_line ();
b99bd4ef 3341
c19d1205
ZW
3342 if (reg == 4)
3343 {
3344 /* Short form. */
3345 op = 0xb4 | (num_regs - 1);
3346 add_unwind_opcode (op, 1);
3347 }
b99bd4ef
NC
3348 else
3349 {
c19d1205
ZW
3350 /* Long form. */
3351 op = 0xc800 | (reg << 4) | (num_regs - 1);
3352 add_unwind_opcode (op, 2);
b99bd4ef 3353 }
c19d1205 3354 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3355}
3356
c19d1205 3357
fa073d69
MS
3358/* Parse a directive saving VFP registers for ARMv6 and above. */
3359
3360static void
3361s_arm_unwind_save_vfp_armv6 (void)
3362{
3363 int count;
3364 unsigned int start;
3365 valueT op;
3366 int num_vfpv3_regs = 0;
3367 int num_regs_below_16;
3368
3369 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3370 if (count == FAIL)
3371 {
3372 as_bad (_("expected register list"));
3373 ignore_rest_of_line ();
3374 return;
3375 }
3376
3377 demand_empty_rest_of_line ();
3378
3379 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3380 than FSTMX/FLDMX-style ones). */
3381
3382 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3383 if (start >= 16)
3384 num_vfpv3_regs = count;
3385 else if (start + count > 16)
3386 num_vfpv3_regs = start + count - 16;
3387
3388 if (num_vfpv3_regs > 0)
3389 {
3390 int start_offset = start > 16 ? start - 16 : 0;
3391 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3392 add_unwind_opcode (op, 2);
3393 }
3394
3395 /* Generate opcode for registers numbered in the range 0 .. 15. */
3396 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3397 assert (num_regs_below_16 + num_vfpv3_regs == count);
3398 if (num_regs_below_16 > 0)
3399 {
3400 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3401 add_unwind_opcode (op, 2);
3402 }
3403
3404 unwind.frame_size += count * 8;
3405}
3406
3407
3408/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3409
3410static void
c19d1205 3411s_arm_unwind_save_vfp (void)
b99bd4ef 3412{
c19d1205 3413 int count;
ca3f61f7 3414 unsigned int reg;
c19d1205 3415 valueT op;
b99bd4ef 3416
5287ad62 3417 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3418 if (count == FAIL)
b99bd4ef 3419 {
c19d1205
ZW
3420 as_bad (_("expected register list"));
3421 ignore_rest_of_line ();
b99bd4ef
NC
3422 return;
3423 }
3424
c19d1205 3425 demand_empty_rest_of_line ();
b99bd4ef 3426
c19d1205 3427 if (reg == 8)
b99bd4ef 3428 {
c19d1205
ZW
3429 /* Short form. */
3430 op = 0xb8 | (count - 1);
3431 add_unwind_opcode (op, 1);
b99bd4ef 3432 }
c19d1205 3433 else
b99bd4ef 3434 {
c19d1205
ZW
3435 /* Long form. */
3436 op = 0xb300 | (reg << 4) | (count - 1);
3437 add_unwind_opcode (op, 2);
b99bd4ef 3438 }
c19d1205
ZW
3439 unwind.frame_size += count * 8 + 4;
3440}
b99bd4ef 3441
b99bd4ef 3442
c19d1205
ZW
3443/* Parse a directive saving iWMMXt data registers. */
3444
3445static void
3446s_arm_unwind_save_mmxwr (void)
3447{
3448 int reg;
3449 int hi_reg;
3450 int i;
3451 unsigned mask = 0;
3452 valueT op;
b99bd4ef 3453
c19d1205
ZW
3454 if (*input_line_pointer == '{')
3455 input_line_pointer++;
b99bd4ef 3456
c19d1205 3457 do
b99bd4ef 3458 {
dcbf9037 3459 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3460
c19d1205 3461 if (reg == FAIL)
b99bd4ef 3462 {
9b7132d3 3463 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3464 goto error;
b99bd4ef
NC
3465 }
3466
c19d1205
ZW
3467 if (mask >> reg)
3468 as_tsktsk (_("register list not in ascending order"));
3469 mask |= 1 << reg;
b99bd4ef 3470
c19d1205
ZW
3471 if (*input_line_pointer == '-')
3472 {
3473 input_line_pointer++;
dcbf9037 3474 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3475 if (hi_reg == FAIL)
3476 {
9b7132d3 3477 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3478 goto error;
3479 }
3480 else if (reg >= hi_reg)
3481 {
3482 as_bad (_("bad register range"));
3483 goto error;
3484 }
3485 for (; reg < hi_reg; reg++)
3486 mask |= 1 << reg;
3487 }
3488 }
3489 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3490
c19d1205
ZW
3491 if (*input_line_pointer == '}')
3492 input_line_pointer++;
b99bd4ef 3493
c19d1205 3494 demand_empty_rest_of_line ();
b99bd4ef 3495
708587a4 3496 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3497 the list. */
3498 flush_pending_unwind ();
b99bd4ef 3499
c19d1205 3500 for (i = 0; i < 16; i++)
b99bd4ef 3501 {
c19d1205
ZW
3502 if (mask & (1 << i))
3503 unwind.frame_size += 8;
b99bd4ef
NC
3504 }
3505
c19d1205
ZW
3506 /* Attempt to combine with a previous opcode. We do this because gcc
3507 likes to output separate unwind directives for a single block of
3508 registers. */
3509 if (unwind.opcode_count > 0)
b99bd4ef 3510 {
c19d1205
ZW
3511 i = unwind.opcodes[unwind.opcode_count - 1];
3512 if ((i & 0xf8) == 0xc0)
3513 {
3514 i &= 7;
3515 /* Only merge if the blocks are contiguous. */
3516 if (i < 6)
3517 {
3518 if ((mask & 0xfe00) == (1 << 9))
3519 {
3520 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3521 unwind.opcode_count--;
3522 }
3523 }
3524 else if (i == 6 && unwind.opcode_count >= 2)
3525 {
3526 i = unwind.opcodes[unwind.opcode_count - 2];
3527 reg = i >> 4;
3528 i &= 0xf;
b99bd4ef 3529
c19d1205
ZW
3530 op = 0xffff << (reg - 1);
3531 if (reg > 0
87a1fd79 3532 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3533 {
3534 op = (1 << (reg + i + 1)) - 1;
3535 op &= ~((1 << reg) - 1);
3536 mask |= op;
3537 unwind.opcode_count -= 2;
3538 }
3539 }
3540 }
b99bd4ef
NC
3541 }
3542
c19d1205
ZW
3543 hi_reg = 15;
3544 /* We want to generate opcodes in the order the registers have been
3545 saved, ie. descending order. */
3546 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3547 {
c19d1205
ZW
3548 /* Save registers in blocks. */
3549 if (reg < 0
3550 || !(mask & (1 << reg)))
3551 {
3552 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3553 preceding block. */
c19d1205
ZW
3554 if (reg != hi_reg)
3555 {
3556 if (reg == 9)
3557 {
3558 /* Short form. */
3559 op = 0xc0 | (hi_reg - 10);
3560 add_unwind_opcode (op, 1);
3561 }
3562 else
3563 {
3564 /* Long form. */
3565 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3566 add_unwind_opcode (op, 2);
3567 }
3568 }
3569 hi_reg = reg - 1;
3570 }
b99bd4ef
NC
3571 }
3572
c19d1205
ZW
3573 return;
3574error:
3575 ignore_rest_of_line ();
b99bd4ef
NC
3576}
3577
3578static void
c19d1205 3579s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3580{
c19d1205
ZW
3581 int reg;
3582 int hi_reg;
3583 unsigned mask = 0;
3584 valueT op;
b99bd4ef 3585
c19d1205
ZW
3586 if (*input_line_pointer == '{')
3587 input_line_pointer++;
b99bd4ef 3588
c19d1205 3589 do
b99bd4ef 3590 {
dcbf9037 3591 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3592
c19d1205
ZW
3593 if (reg == FAIL)
3594 {
9b7132d3 3595 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3596 goto error;
3597 }
b99bd4ef 3598
c19d1205
ZW
3599 reg -= 8;
3600 if (mask >> reg)
3601 as_tsktsk (_("register list not in ascending order"));
3602 mask |= 1 << reg;
b99bd4ef 3603
c19d1205
ZW
3604 if (*input_line_pointer == '-')
3605 {
3606 input_line_pointer++;
dcbf9037 3607 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3608 if (hi_reg == FAIL)
3609 {
9b7132d3 3610 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3611 goto error;
3612 }
3613 else if (reg >= hi_reg)
3614 {
3615 as_bad (_("bad register range"));
3616 goto error;
3617 }
3618 for (; reg < hi_reg; reg++)
3619 mask |= 1 << reg;
3620 }
b99bd4ef 3621 }
c19d1205 3622 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3623
c19d1205
ZW
3624 if (*input_line_pointer == '}')
3625 input_line_pointer++;
b99bd4ef 3626
c19d1205
ZW
3627 demand_empty_rest_of_line ();
3628
708587a4 3629 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3630 the list. */
3631 flush_pending_unwind ();
b99bd4ef 3632
c19d1205 3633 for (reg = 0; reg < 16; reg++)
b99bd4ef 3634 {
c19d1205
ZW
3635 if (mask & (1 << reg))
3636 unwind.frame_size += 4;
b99bd4ef 3637 }
c19d1205
ZW
3638 op = 0xc700 | mask;
3639 add_unwind_opcode (op, 2);
3640 return;
3641error:
3642 ignore_rest_of_line ();
b99bd4ef
NC
3643}
3644
c19d1205 3645
fa073d69
MS
3646/* Parse an unwind_save directive.
3647 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3648
b99bd4ef 3649static void
fa073d69 3650s_arm_unwind_save (int arch_v6)
b99bd4ef 3651{
c19d1205
ZW
3652 char *peek;
3653 struct reg_entry *reg;
3654 bfd_boolean had_brace = FALSE;
b99bd4ef 3655
c19d1205
ZW
3656 /* Figure out what sort of save we have. */
3657 peek = input_line_pointer;
b99bd4ef 3658
c19d1205 3659 if (*peek == '{')
b99bd4ef 3660 {
c19d1205
ZW
3661 had_brace = TRUE;
3662 peek++;
b99bd4ef
NC
3663 }
3664
c19d1205 3665 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3666
c19d1205 3667 if (!reg)
b99bd4ef 3668 {
c19d1205
ZW
3669 as_bad (_("register expected"));
3670 ignore_rest_of_line ();
b99bd4ef
NC
3671 return;
3672 }
3673
c19d1205 3674 switch (reg->type)
b99bd4ef 3675 {
c19d1205
ZW
3676 case REG_TYPE_FN:
3677 if (had_brace)
3678 {
3679 as_bad (_("FPA .unwind_save does not take a register list"));
3680 ignore_rest_of_line ();
3681 return;
3682 }
93ac2687 3683 input_line_pointer = peek;
c19d1205 3684 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3685 return;
c19d1205
ZW
3686
3687 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3688 case REG_TYPE_VFD:
3689 if (arch_v6)
3690 s_arm_unwind_save_vfp_armv6 ();
3691 else
3692 s_arm_unwind_save_vfp ();
3693 return;
c19d1205
ZW
3694 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3695 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3696
3697 default:
3698 as_bad (_(".unwind_save does not support this kind of register"));
3699 ignore_rest_of_line ();
b99bd4ef 3700 }
c19d1205 3701}
b99bd4ef 3702
b99bd4ef 3703
c19d1205
ZW
3704/* Parse an unwind_movsp directive. */
3705
3706static void
3707s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3708{
3709 int reg;
3710 valueT op;
4fa3602b 3711 int offset;
c19d1205 3712
dcbf9037 3713 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3714 if (reg == FAIL)
b99bd4ef 3715 {
9b7132d3 3716 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 3717 ignore_rest_of_line ();
b99bd4ef
NC
3718 return;
3719 }
4fa3602b
PB
3720
3721 /* Optional constant. */
3722 if (skip_past_comma (&input_line_pointer) != FAIL)
3723 {
3724 if (immediate_for_directive (&offset) == FAIL)
3725 return;
3726 }
3727 else
3728 offset = 0;
3729
c19d1205 3730 demand_empty_rest_of_line ();
b99bd4ef 3731
c19d1205 3732 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3733 {
c19d1205 3734 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3735 return;
3736 }
3737
c19d1205
ZW
3738 if (unwind.fp_reg != REG_SP)
3739 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3740
c19d1205
ZW
3741 /* Generate opcode to restore the value. */
3742 op = 0x90 | reg;
3743 add_unwind_opcode (op, 1);
3744
3745 /* Record the information for later. */
3746 unwind.fp_reg = reg;
4fa3602b 3747 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3748 unwind.sp_restored = 1;
b05fe5cf
ZW
3749}
3750
c19d1205
ZW
3751/* Parse an unwind_pad directive. */
3752
b05fe5cf 3753static void
c19d1205 3754s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3755{
c19d1205 3756 int offset;
b05fe5cf 3757
c19d1205
ZW
3758 if (immediate_for_directive (&offset) == FAIL)
3759 return;
b99bd4ef 3760
c19d1205
ZW
3761 if (offset & 3)
3762 {
3763 as_bad (_("stack increment must be multiple of 4"));
3764 ignore_rest_of_line ();
3765 return;
3766 }
b99bd4ef 3767
c19d1205
ZW
3768 /* Don't generate any opcodes, just record the details for later. */
3769 unwind.frame_size += offset;
3770 unwind.pending_offset += offset;
3771
3772 demand_empty_rest_of_line ();
3773}
3774
3775/* Parse an unwind_setfp directive. */
3776
3777static void
3778s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3779{
c19d1205
ZW
3780 int sp_reg;
3781 int fp_reg;
3782 int offset;
3783
dcbf9037 3784 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3785 if (skip_past_comma (&input_line_pointer) == FAIL)
3786 sp_reg = FAIL;
3787 else
dcbf9037 3788 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3789
c19d1205
ZW
3790 if (fp_reg == FAIL || sp_reg == FAIL)
3791 {
3792 as_bad (_("expected <reg>, <reg>"));
3793 ignore_rest_of_line ();
3794 return;
3795 }
b99bd4ef 3796
c19d1205
ZW
3797 /* Optional constant. */
3798 if (skip_past_comma (&input_line_pointer) != FAIL)
3799 {
3800 if (immediate_for_directive (&offset) == FAIL)
3801 return;
3802 }
3803 else
3804 offset = 0;
a737bd4d 3805
c19d1205 3806 demand_empty_rest_of_line ();
a737bd4d 3807
c19d1205 3808 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3809 {
c19d1205
ZW
3810 as_bad (_("register must be either sp or set by a previous"
3811 "unwind_movsp directive"));
3812 return;
a737bd4d
NC
3813 }
3814
c19d1205
ZW
3815 /* Don't generate any opcodes, just record the information for later. */
3816 unwind.fp_reg = fp_reg;
3817 unwind.fp_used = 1;
3818 if (sp_reg == 13)
3819 unwind.fp_offset = unwind.frame_size - offset;
3820 else
3821 unwind.fp_offset -= offset;
a737bd4d
NC
3822}
3823
c19d1205
ZW
3824/* Parse an unwind_raw directive. */
3825
3826static void
3827s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3828{
c19d1205 3829 expressionS exp;
708587a4 3830 /* This is an arbitrary limit. */
c19d1205
ZW
3831 unsigned char op[16];
3832 int count;
a737bd4d 3833
c19d1205
ZW
3834 expression (&exp);
3835 if (exp.X_op == O_constant
3836 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3837 {
c19d1205
ZW
3838 unwind.frame_size += exp.X_add_number;
3839 expression (&exp);
3840 }
3841 else
3842 exp.X_op = O_illegal;
a737bd4d 3843
c19d1205
ZW
3844 if (exp.X_op != O_constant)
3845 {
3846 as_bad (_("expected <offset>, <opcode>"));
3847 ignore_rest_of_line ();
3848 return;
3849 }
a737bd4d 3850
c19d1205 3851 count = 0;
a737bd4d 3852
c19d1205
ZW
3853 /* Parse the opcode. */
3854 for (;;)
3855 {
3856 if (count >= 16)
3857 {
3858 as_bad (_("unwind opcode too long"));
3859 ignore_rest_of_line ();
a737bd4d 3860 }
c19d1205 3861 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3862 {
c19d1205
ZW
3863 as_bad (_("invalid unwind opcode"));
3864 ignore_rest_of_line ();
3865 return;
a737bd4d 3866 }
c19d1205 3867 op[count++] = exp.X_add_number;
a737bd4d 3868
c19d1205
ZW
3869 /* Parse the next byte. */
3870 if (skip_past_comma (&input_line_pointer) == FAIL)
3871 break;
a737bd4d 3872
c19d1205
ZW
3873 expression (&exp);
3874 }
b99bd4ef 3875
c19d1205
ZW
3876 /* Add the opcode bytes in reverse order. */
3877 while (count--)
3878 add_unwind_opcode (op[count], 1);
b99bd4ef 3879
c19d1205 3880 demand_empty_rest_of_line ();
b99bd4ef 3881}
ee065d83
PB
3882
3883
3884/* Parse a .eabi_attribute directive. */
3885
3886static void
3887s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3888{
ee3c0378
AS
3889 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
3890
3891 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
3892 attributes_set_explicitly[tag] = 1;
ee065d83 3893}
8463be01 3894#endif /* OBJ_ELF */
ee065d83
PB
3895
3896static void s_arm_arch (int);
7a1d4c38 3897static void s_arm_object_arch (int);
ee065d83
PB
3898static void s_arm_cpu (int);
3899static void s_arm_fpu (int);
b99bd4ef 3900
f0927246
NC
3901#ifdef TE_PE
3902
3903static void
5f4273c7 3904pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
3905{
3906 expressionS exp;
3907
3908 do
3909 {
3910 expression (&exp);
3911 if (exp.X_op == O_symbol)
3912 exp.X_op = O_secrel;
3913
3914 emit_expr (&exp, 4);
3915 }
3916 while (*input_line_pointer++ == ',');
3917
3918 input_line_pointer--;
3919 demand_empty_rest_of_line ();
3920}
3921#endif /* TE_PE */
3922
c19d1205
ZW
3923/* This table describes all the machine specific pseudo-ops the assembler
3924 has to support. The fields are:
3925 pseudo-op name without dot
3926 function to call to execute this pseudo-op
3927 Integer arg to pass to the function. */
b99bd4ef 3928
c19d1205 3929const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3930{
c19d1205
ZW
3931 /* Never called because '.req' does not start a line. */
3932 { "req", s_req, 0 },
dcbf9037
JB
3933 /* Following two are likewise never called. */
3934 { "dn", s_dn, 0 },
3935 { "qn", s_qn, 0 },
c19d1205
ZW
3936 { "unreq", s_unreq, 0 },
3937 { "bss", s_bss, 0 },
3938 { "align", s_align, 0 },
3939 { "arm", s_arm, 0 },
3940 { "thumb", s_thumb, 0 },
3941 { "code", s_code, 0 },
3942 { "force_thumb", s_force_thumb, 0 },
3943 { "thumb_func", s_thumb_func, 0 },
3944 { "thumb_set", s_thumb_set, 0 },
3945 { "even", s_even, 0 },
3946 { "ltorg", s_ltorg, 0 },
3947 { "pool", s_ltorg, 0 },
3948 { "syntax", s_syntax, 0 },
8463be01
PB
3949 { "cpu", s_arm_cpu, 0 },
3950 { "arch", s_arm_arch, 0 },
7a1d4c38 3951 { "object_arch", s_arm_object_arch, 0 },
8463be01 3952 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3953#ifdef OBJ_ELF
3954 { "word", s_arm_elf_cons, 4 },
3955 { "long", s_arm_elf_cons, 4 },
3956 { "rel31", s_arm_rel31, 0 },
3957 { "fnstart", s_arm_unwind_fnstart, 0 },
3958 { "fnend", s_arm_unwind_fnend, 0 },
3959 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3960 { "personality", s_arm_unwind_personality, 0 },
3961 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3962 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3963 { "save", s_arm_unwind_save, 0 },
fa073d69 3964 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3965 { "movsp", s_arm_unwind_movsp, 0 },
3966 { "pad", s_arm_unwind_pad, 0 },
3967 { "setfp", s_arm_unwind_setfp, 0 },
3968 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3969 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3970#else
3971 { "word", cons, 4},
f0927246
NC
3972
3973 /* These are used for dwarf. */
3974 {"2byte", cons, 2},
3975 {"4byte", cons, 4},
3976 {"8byte", cons, 8},
3977 /* These are used for dwarf2. */
3978 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3979 { "loc", dwarf2_directive_loc, 0 },
3980 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3981#endif
3982 { "extend", float_cons, 'x' },
3983 { "ldouble", float_cons, 'x' },
3984 { "packed", float_cons, 'p' },
f0927246
NC
3985#ifdef TE_PE
3986 {"secrel32", pe_directive_secrel, 0},
3987#endif
c19d1205
ZW
3988 { 0, 0, 0 }
3989};
3990\f
3991/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3992
c19d1205
ZW
3993/* Generic immediate-value read function for use in insn parsing.
3994 STR points to the beginning of the immediate (the leading #);
3995 VAL receives the value; if the value is outside [MIN, MAX]
3996 issue an error. PREFIX_OPT is true if the immediate prefix is
3997 optional. */
b99bd4ef 3998
c19d1205
ZW
3999static int
4000parse_immediate (char **str, int *val, int min, int max,
4001 bfd_boolean prefix_opt)
4002{
4003 expressionS exp;
4004 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4005 if (exp.X_op != O_constant)
b99bd4ef 4006 {
c19d1205
ZW
4007 inst.error = _("constant expression required");
4008 return FAIL;
4009 }
b99bd4ef 4010
c19d1205
ZW
4011 if (exp.X_add_number < min || exp.X_add_number > max)
4012 {
4013 inst.error = _("immediate value out of range");
4014 return FAIL;
4015 }
b99bd4ef 4016
c19d1205
ZW
4017 *val = exp.X_add_number;
4018 return SUCCESS;
4019}
b99bd4ef 4020
5287ad62 4021/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4022 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4023 instructions. Puts the result directly in inst.operands[i]. */
4024
4025static int
4026parse_big_immediate (char **str, int i)
4027{
4028 expressionS exp;
4029 char *ptr = *str;
4030
4031 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4032
4033 if (exp.X_op == O_constant)
036dc3f7
PB
4034 {
4035 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4036 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4037 O_constant. We have to be careful not to break compilation for
4038 32-bit X_add_number, though. */
4039 if ((exp.X_add_number & ~0xffffffffl) != 0)
4040 {
4041 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4042 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4043 inst.operands[i].regisimm = 1;
4044 }
4045 }
5287ad62
JB
4046 else if (exp.X_op == O_big
4047 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4048 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4049 {
4050 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4051 /* Bignums have their least significant bits in
4052 generic_bignum[0]. Make sure we put 32 bits in imm and
4053 32 bits in reg, in a (hopefully) portable way. */
4054 assert (parts != 0);
4055 inst.operands[i].imm = 0;
4056 for (j = 0; j < parts; j++, idx++)
4057 inst.operands[i].imm |= generic_bignum[idx]
4058 << (LITTLENUM_NUMBER_OF_BITS * j);
4059 inst.operands[i].reg = 0;
4060 for (j = 0; j < parts; j++, idx++)
4061 inst.operands[i].reg |= generic_bignum[idx]
4062 << (LITTLENUM_NUMBER_OF_BITS * j);
4063 inst.operands[i].regisimm = 1;
4064 }
4065 else
4066 return FAIL;
5f4273c7 4067
5287ad62
JB
4068 *str = ptr;
4069
4070 return SUCCESS;
4071}
4072
c19d1205
ZW
4073/* Returns the pseudo-register number of an FPA immediate constant,
4074 or FAIL if there isn't a valid constant here. */
b99bd4ef 4075
c19d1205
ZW
4076static int
4077parse_fpa_immediate (char ** str)
4078{
4079 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4080 char * save_in;
4081 expressionS exp;
4082 int i;
4083 int j;
b99bd4ef 4084
c19d1205
ZW
4085 /* First try and match exact strings, this is to guarantee
4086 that some formats will work even for cross assembly. */
b99bd4ef 4087
c19d1205
ZW
4088 for (i = 0; fp_const[i]; i++)
4089 {
4090 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4091 {
c19d1205 4092 char *start = *str;
b99bd4ef 4093
c19d1205
ZW
4094 *str += strlen (fp_const[i]);
4095 if (is_end_of_line[(unsigned char) **str])
4096 return i + 8;
4097 *str = start;
4098 }
4099 }
b99bd4ef 4100
c19d1205
ZW
4101 /* Just because we didn't get a match doesn't mean that the constant
4102 isn't valid, just that it is in a format that we don't
4103 automatically recognize. Try parsing it with the standard
4104 expression routines. */
b99bd4ef 4105
c19d1205 4106 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4107
c19d1205
ZW
4108 /* Look for a raw floating point number. */
4109 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4110 && is_end_of_line[(unsigned char) *save_in])
4111 {
4112 for (i = 0; i < NUM_FLOAT_VALS; i++)
4113 {
4114 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4115 {
c19d1205
ZW
4116 if (words[j] != fp_values[i][j])
4117 break;
b99bd4ef
NC
4118 }
4119
c19d1205 4120 if (j == MAX_LITTLENUMS)
b99bd4ef 4121 {
c19d1205
ZW
4122 *str = save_in;
4123 return i + 8;
b99bd4ef
NC
4124 }
4125 }
4126 }
b99bd4ef 4127
c19d1205
ZW
4128 /* Try and parse a more complex expression, this will probably fail
4129 unless the code uses a floating point prefix (eg "0f"). */
4130 save_in = input_line_pointer;
4131 input_line_pointer = *str;
4132 if (expression (&exp) == absolute_section
4133 && exp.X_op == O_big
4134 && exp.X_add_number < 0)
4135 {
4136 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4137 Ditto for 15. */
4138 if (gen_to_words (words, 5, (long) 15) == 0)
4139 {
4140 for (i = 0; i < NUM_FLOAT_VALS; i++)
4141 {
4142 for (j = 0; j < MAX_LITTLENUMS; j++)
4143 {
4144 if (words[j] != fp_values[i][j])
4145 break;
4146 }
b99bd4ef 4147
c19d1205
ZW
4148 if (j == MAX_LITTLENUMS)
4149 {
4150 *str = input_line_pointer;
4151 input_line_pointer = save_in;
4152 return i + 8;
4153 }
4154 }
4155 }
b99bd4ef
NC
4156 }
4157
c19d1205
ZW
4158 *str = input_line_pointer;
4159 input_line_pointer = save_in;
4160 inst.error = _("invalid FPA immediate expression");
4161 return FAIL;
b99bd4ef
NC
4162}
4163
136da414
JB
4164/* Returns 1 if a number has "quarter-precision" float format
4165 0baBbbbbbc defgh000 00000000 00000000. */
4166
4167static int
4168is_quarter_float (unsigned imm)
4169{
4170 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4171 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4172}
4173
4174/* Parse an 8-bit "quarter-precision" floating point number of the form:
4175 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4176 The zero and minus-zero cases need special handling, since they can't be
4177 encoded in the "quarter-precision" float format, but can nonetheless be
4178 loaded as integer constants. */
136da414
JB
4179
4180static unsigned
4181parse_qfloat_immediate (char **ccp, int *immed)
4182{
4183 char *str = *ccp;
c96612cc 4184 char *fpnum;
136da414 4185 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4186 int found_fpchar = 0;
5f4273c7 4187
136da414 4188 skip_past_char (&str, '#');
5f4273c7 4189
c96612cc
JB
4190 /* We must not accidentally parse an integer as a floating-point number. Make
4191 sure that the value we parse is not an integer by checking for special
4192 characters '.' or 'e'.
4193 FIXME: This is a horrible hack, but doing better is tricky because type
4194 information isn't in a very usable state at parse time. */
4195 fpnum = str;
4196 skip_whitespace (fpnum);
4197
4198 if (strncmp (fpnum, "0x", 2) == 0)
4199 return FAIL;
4200 else
4201 {
4202 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4203 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4204 {
4205 found_fpchar = 1;
4206 break;
4207 }
4208
4209 if (!found_fpchar)
4210 return FAIL;
4211 }
5f4273c7 4212
136da414
JB
4213 if ((str = atof_ieee (str, 's', words)) != NULL)
4214 {
4215 unsigned fpword = 0;
4216 int i;
5f4273c7 4217
136da414
JB
4218 /* Our FP word must be 32 bits (single-precision FP). */
4219 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4220 {
4221 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4222 fpword |= words[i];
4223 }
5f4273c7 4224
c96612cc 4225 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4226 *immed = fpword;
4227 else
4228 return FAIL;
4229
4230 *ccp = str;
5f4273c7 4231
136da414
JB
4232 return SUCCESS;
4233 }
5f4273c7 4234
136da414
JB
4235 return FAIL;
4236}
4237
c19d1205
ZW
4238/* Shift operands. */
4239enum shift_kind
b99bd4ef 4240{
c19d1205
ZW
4241 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4242};
b99bd4ef 4243
c19d1205
ZW
4244struct asm_shift_name
4245{
4246 const char *name;
4247 enum shift_kind kind;
4248};
b99bd4ef 4249
c19d1205
ZW
4250/* Third argument to parse_shift. */
4251enum parse_shift_mode
4252{
4253 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4254 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4255 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4256 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4257 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4258};
b99bd4ef 4259
c19d1205
ZW
4260/* Parse a <shift> specifier on an ARM data processing instruction.
4261 This has three forms:
b99bd4ef 4262
c19d1205
ZW
4263 (LSL|LSR|ASL|ASR|ROR) Rs
4264 (LSL|LSR|ASL|ASR|ROR) #imm
4265 RRX
b99bd4ef 4266
c19d1205
ZW
4267 Note that ASL is assimilated to LSL in the instruction encoding, and
4268 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4269
c19d1205
ZW
4270static int
4271parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4272{
c19d1205
ZW
4273 const struct asm_shift_name *shift_name;
4274 enum shift_kind shift;
4275 char *s = *str;
4276 char *p = s;
4277 int reg;
b99bd4ef 4278
c19d1205
ZW
4279 for (p = *str; ISALPHA (*p); p++)
4280 ;
b99bd4ef 4281
c19d1205 4282 if (p == *str)
b99bd4ef 4283 {
c19d1205
ZW
4284 inst.error = _("shift expression expected");
4285 return FAIL;
b99bd4ef
NC
4286 }
4287
c19d1205
ZW
4288 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4289
4290 if (shift_name == NULL)
b99bd4ef 4291 {
c19d1205
ZW
4292 inst.error = _("shift expression expected");
4293 return FAIL;
b99bd4ef
NC
4294 }
4295
c19d1205 4296 shift = shift_name->kind;
b99bd4ef 4297
c19d1205
ZW
4298 switch (mode)
4299 {
4300 case NO_SHIFT_RESTRICT:
4301 case SHIFT_IMMEDIATE: break;
b99bd4ef 4302
c19d1205
ZW
4303 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4304 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4305 {
4306 inst.error = _("'LSL' or 'ASR' required");
4307 return FAIL;
4308 }
4309 break;
b99bd4ef 4310
c19d1205
ZW
4311 case SHIFT_LSL_IMMEDIATE:
4312 if (shift != SHIFT_LSL)
4313 {
4314 inst.error = _("'LSL' required");
4315 return FAIL;
4316 }
4317 break;
b99bd4ef 4318
c19d1205
ZW
4319 case SHIFT_ASR_IMMEDIATE:
4320 if (shift != SHIFT_ASR)
4321 {
4322 inst.error = _("'ASR' required");
4323 return FAIL;
4324 }
4325 break;
b99bd4ef 4326
c19d1205
ZW
4327 default: abort ();
4328 }
b99bd4ef 4329
c19d1205
ZW
4330 if (shift != SHIFT_RRX)
4331 {
4332 /* Whitespace can appear here if the next thing is a bare digit. */
4333 skip_whitespace (p);
b99bd4ef 4334
c19d1205 4335 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4336 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4337 {
4338 inst.operands[i].imm = reg;
4339 inst.operands[i].immisreg = 1;
4340 }
4341 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4342 return FAIL;
4343 }
4344 inst.operands[i].shift_kind = shift;
4345 inst.operands[i].shifted = 1;
4346 *str = p;
4347 return SUCCESS;
b99bd4ef
NC
4348}
4349
c19d1205 4350/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4351
c19d1205
ZW
4352 #<immediate>
4353 #<immediate>, <rotate>
4354 <Rm>
4355 <Rm>, <shift>
b99bd4ef 4356
c19d1205
ZW
4357 where <shift> is defined by parse_shift above, and <rotate> is a
4358 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4359 is deferred to md_apply_fix. */
b99bd4ef 4360
c19d1205
ZW
4361static int
4362parse_shifter_operand (char **str, int i)
4363{
4364 int value;
4365 expressionS expr;
b99bd4ef 4366
dcbf9037 4367 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4368 {
4369 inst.operands[i].reg = value;
4370 inst.operands[i].isreg = 1;
b99bd4ef 4371
c19d1205
ZW
4372 /* parse_shift will override this if appropriate */
4373 inst.reloc.exp.X_op = O_constant;
4374 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4375
c19d1205
ZW
4376 if (skip_past_comma (str) == FAIL)
4377 return SUCCESS;
b99bd4ef 4378
c19d1205
ZW
4379 /* Shift operation on register. */
4380 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4381 }
4382
c19d1205
ZW
4383 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4384 return FAIL;
b99bd4ef 4385
c19d1205 4386 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4387 {
c19d1205
ZW
4388 /* #x, y -- ie explicit rotation by Y. */
4389 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4390 return FAIL;
b99bd4ef 4391
c19d1205
ZW
4392 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4393 {
4394 inst.error = _("constant expression expected");
4395 return FAIL;
4396 }
b99bd4ef 4397
c19d1205
ZW
4398 value = expr.X_add_number;
4399 if (value < 0 || value > 30 || value % 2 != 0)
4400 {
4401 inst.error = _("invalid rotation");
4402 return FAIL;
4403 }
4404 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4405 {
4406 inst.error = _("invalid constant");
4407 return FAIL;
4408 }
09d92015 4409
55cf6793 4410 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4411 inst.reloc.exp.X_add_number
4412 = (((inst.reloc.exp.X_add_number << (32 - value))
4413 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4414 }
4415
c19d1205
ZW
4416 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4417 inst.reloc.pc_rel = 0;
4418 return SUCCESS;
09d92015
MM
4419}
4420
4962c51a
MS
4421/* Group relocation information. Each entry in the table contains the
4422 textual name of the relocation as may appear in assembler source
4423 and must end with a colon.
4424 Along with this textual name are the relocation codes to be used if
4425 the corresponding instruction is an ALU instruction (ADD or SUB only),
4426 an LDR, an LDRS, or an LDC. */
4427
4428struct group_reloc_table_entry
4429{
4430 const char *name;
4431 int alu_code;
4432 int ldr_code;
4433 int ldrs_code;
4434 int ldc_code;
4435};
4436
4437typedef enum
4438{
4439 /* Varieties of non-ALU group relocation. */
4440
4441 GROUP_LDR,
4442 GROUP_LDRS,
4443 GROUP_LDC
4444} group_reloc_type;
4445
4446static struct group_reloc_table_entry group_reloc_table[] =
4447 { /* Program counter relative: */
4448 { "pc_g0_nc",
4449 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4450 0, /* LDR */
4451 0, /* LDRS */
4452 0 }, /* LDC */
4453 { "pc_g0",
4454 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4455 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4456 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4457 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4458 { "pc_g1_nc",
4459 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4460 0, /* LDR */
4461 0, /* LDRS */
4462 0 }, /* LDC */
4463 { "pc_g1",
4464 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4465 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4466 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4467 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4468 { "pc_g2",
4469 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4470 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4471 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4472 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4473 /* Section base relative */
4474 { "sb_g0_nc",
4475 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4476 0, /* LDR */
4477 0, /* LDRS */
4478 0 }, /* LDC */
4479 { "sb_g0",
4480 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4481 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4482 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4483 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4484 { "sb_g1_nc",
4485 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4486 0, /* LDR */
4487 0, /* LDRS */
4488 0 }, /* LDC */
4489 { "sb_g1",
4490 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4491 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4492 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4493 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4494 { "sb_g2",
4495 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4496 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4497 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4498 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4499
4500/* Given the address of a pointer pointing to the textual name of a group
4501 relocation as may appear in assembler source, attempt to find its details
4502 in group_reloc_table. The pointer will be updated to the character after
4503 the trailing colon. On failure, FAIL will be returned; SUCCESS
4504 otherwise. On success, *entry will be updated to point at the relevant
4505 group_reloc_table entry. */
4506
4507static int
4508find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4509{
4510 unsigned int i;
4511 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4512 {
4513 int length = strlen (group_reloc_table[i].name);
4514
5f4273c7
NC
4515 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4516 && (*str)[length] == ':')
4962c51a
MS
4517 {
4518 *out = &group_reloc_table[i];
4519 *str += (length + 1);
4520 return SUCCESS;
4521 }
4522 }
4523
4524 return FAIL;
4525}
4526
4527/* Parse a <shifter_operand> for an ARM data processing instruction
4528 (as for parse_shifter_operand) where group relocations are allowed:
4529
4530 #<immediate>
4531 #<immediate>, <rotate>
4532 #:<group_reloc>:<expression>
4533 <Rm>
4534 <Rm>, <shift>
4535
4536 where <group_reloc> is one of the strings defined in group_reloc_table.
4537 The hashes are optional.
4538
4539 Everything else is as for parse_shifter_operand. */
4540
4541static parse_operand_result
4542parse_shifter_operand_group_reloc (char **str, int i)
4543{
4544 /* Determine if we have the sequence of characters #: or just :
4545 coming next. If we do, then we check for a group relocation.
4546 If we don't, punt the whole lot to parse_shifter_operand. */
4547
4548 if (((*str)[0] == '#' && (*str)[1] == ':')
4549 || (*str)[0] == ':')
4550 {
4551 struct group_reloc_table_entry *entry;
4552
4553 if ((*str)[0] == '#')
4554 (*str) += 2;
4555 else
4556 (*str)++;
4557
4558 /* Try to parse a group relocation. Anything else is an error. */
4559 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4560 {
4561 inst.error = _("unknown group relocation");
4562 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4563 }
4564
4565 /* We now have the group relocation table entry corresponding to
4566 the name in the assembler source. Next, we parse the expression. */
4567 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4568 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4569
4570 /* Record the relocation type (always the ALU variant here). */
4571 inst.reloc.type = entry->alu_code;
4572 assert (inst.reloc.type != 0);
4573
4574 return PARSE_OPERAND_SUCCESS;
4575 }
4576 else
4577 return parse_shifter_operand (str, i) == SUCCESS
4578 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4579
4580 /* Never reached. */
4581}
4582
c19d1205
ZW
4583/* Parse all forms of an ARM address expression. Information is written
4584 to inst.operands[i] and/or inst.reloc.
09d92015 4585
c19d1205 4586 Preindexed addressing (.preind=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 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4594
c19d1205 4595 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4596
c19d1205
ZW
4597 [Rn], #offset .reg=Rn .reloc.exp=offset
4598 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4599 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4600 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4601
c19d1205 4602 Unindexed addressing (.preind=0, .postind=0):
09d92015 4603
c19d1205 4604 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4605
c19d1205 4606 Other:
09d92015 4607
c19d1205
ZW
4608 [Rn]{!} shorthand for [Rn,#0]{!}
4609 =immediate .isreg=0 .reloc.exp=immediate
4610 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4611
c19d1205
ZW
4612 It is the caller's responsibility to check for addressing modes not
4613 supported by the instruction, and to set inst.reloc.type. */
4614
4962c51a
MS
4615static parse_operand_result
4616parse_address_main (char **str, int i, int group_relocations,
4617 group_reloc_type group_type)
09d92015 4618{
c19d1205
ZW
4619 char *p = *str;
4620 int reg;
09d92015 4621
c19d1205 4622 if (skip_past_char (&p, '[') == FAIL)
09d92015 4623 {
c19d1205
ZW
4624 if (skip_past_char (&p, '=') == FAIL)
4625 {
4626 /* bare address - translate to PC-relative offset */
4627 inst.reloc.pc_rel = 1;
4628 inst.operands[i].reg = REG_PC;
4629 inst.operands[i].isreg = 1;
4630 inst.operands[i].preind = 1;
4631 }
4632 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4633
c19d1205 4634 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4635 return PARSE_OPERAND_FAIL;
09d92015 4636
c19d1205 4637 *str = p;
4962c51a 4638 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4639 }
4640
dcbf9037 4641 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4642 {
c19d1205 4643 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4644 return PARSE_OPERAND_FAIL;
09d92015 4645 }
c19d1205
ZW
4646 inst.operands[i].reg = reg;
4647 inst.operands[i].isreg = 1;
09d92015 4648
c19d1205 4649 if (skip_past_comma (&p) == SUCCESS)
09d92015 4650 {
c19d1205 4651 inst.operands[i].preind = 1;
09d92015 4652
c19d1205
ZW
4653 if (*p == '+') p++;
4654 else if (*p == '-') p++, inst.operands[i].negative = 1;
4655
dcbf9037 4656 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4657 {
c19d1205
ZW
4658 inst.operands[i].imm = reg;
4659 inst.operands[i].immisreg = 1;
4660
4661 if (skip_past_comma (&p) == SUCCESS)
4662 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4663 return PARSE_OPERAND_FAIL;
c19d1205 4664 }
5287ad62
JB
4665 else if (skip_past_char (&p, ':') == SUCCESS)
4666 {
4667 /* FIXME: '@' should be used here, but it's filtered out by generic
4668 code before we get to see it here. This may be subject to
4669 change. */
4670 expressionS exp;
4671 my_get_expression (&exp, &p, GE_NO_PREFIX);
4672 if (exp.X_op != O_constant)
4673 {
4674 inst.error = _("alignment must be constant");
4962c51a 4675 return PARSE_OPERAND_FAIL;
5287ad62
JB
4676 }
4677 inst.operands[i].imm = exp.X_add_number << 8;
4678 inst.operands[i].immisalign = 1;
4679 /* Alignments are not pre-indexes. */
4680 inst.operands[i].preind = 0;
4681 }
c19d1205
ZW
4682 else
4683 {
4684 if (inst.operands[i].negative)
4685 {
4686 inst.operands[i].negative = 0;
4687 p--;
4688 }
4962c51a 4689
5f4273c7
NC
4690 if (group_relocations
4691 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4692 {
4693 struct group_reloc_table_entry *entry;
4694
4695 /* Skip over the #: or : sequence. */
4696 if (*p == '#')
4697 p += 2;
4698 else
4699 p++;
4700
4701 /* Try to parse a group relocation. Anything else is an
4702 error. */
4703 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4704 {
4705 inst.error = _("unknown group relocation");
4706 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4707 }
4708
4709 /* We now have the group relocation table entry corresponding to
4710 the name in the assembler source. Next, we parse the
4711 expression. */
4712 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4713 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4714
4715 /* Record the relocation type. */
4716 switch (group_type)
4717 {
4718 case GROUP_LDR:
4719 inst.reloc.type = entry->ldr_code;
4720 break;
4721
4722 case GROUP_LDRS:
4723 inst.reloc.type = entry->ldrs_code;
4724 break;
4725
4726 case GROUP_LDC:
4727 inst.reloc.type = entry->ldc_code;
4728 break;
4729
4730 default:
4731 assert (0);
4732 }
4733
4734 if (inst.reloc.type == 0)
4735 {
4736 inst.error = _("this group relocation is not allowed on this instruction");
4737 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4738 }
4739 }
4740 else
4741 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4742 return PARSE_OPERAND_FAIL;
09d92015
MM
4743 }
4744 }
4745
c19d1205 4746 if (skip_past_char (&p, ']') == FAIL)
09d92015 4747 {
c19d1205 4748 inst.error = _("']' expected");
4962c51a 4749 return PARSE_OPERAND_FAIL;
09d92015
MM
4750 }
4751
c19d1205
ZW
4752 if (skip_past_char (&p, '!') == SUCCESS)
4753 inst.operands[i].writeback = 1;
09d92015 4754
c19d1205 4755 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4756 {
c19d1205
ZW
4757 if (skip_past_char (&p, '{') == SUCCESS)
4758 {
4759 /* [Rn], {expr} - unindexed, with option */
4760 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4761 0, 255, TRUE) == FAIL)
4962c51a 4762 return PARSE_OPERAND_FAIL;
09d92015 4763
c19d1205
ZW
4764 if (skip_past_char (&p, '}') == FAIL)
4765 {
4766 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4767 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4768 }
4769 if (inst.operands[i].preind)
4770 {
4771 inst.error = _("cannot combine index with option");
4962c51a 4772 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4773 }
4774 *str = p;
4962c51a 4775 return PARSE_OPERAND_SUCCESS;
09d92015 4776 }
c19d1205
ZW
4777 else
4778 {
4779 inst.operands[i].postind = 1;
4780 inst.operands[i].writeback = 1;
09d92015 4781
c19d1205
ZW
4782 if (inst.operands[i].preind)
4783 {
4784 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4785 return PARSE_OPERAND_FAIL;
c19d1205 4786 }
09d92015 4787
c19d1205
ZW
4788 if (*p == '+') p++;
4789 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4790
dcbf9037 4791 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4792 {
5287ad62
JB
4793 /* We might be using the immediate for alignment already. If we
4794 are, OR the register number into the low-order bits. */
4795 if (inst.operands[i].immisalign)
4796 inst.operands[i].imm |= reg;
4797 else
4798 inst.operands[i].imm = reg;
c19d1205 4799 inst.operands[i].immisreg = 1;
a737bd4d 4800
c19d1205
ZW
4801 if (skip_past_comma (&p) == SUCCESS)
4802 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4803 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4804 }
4805 else
4806 {
4807 if (inst.operands[i].negative)
4808 {
4809 inst.operands[i].negative = 0;
4810 p--;
4811 }
4812 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4813 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4814 }
4815 }
a737bd4d
NC
4816 }
4817
c19d1205
ZW
4818 /* If at this point neither .preind nor .postind is set, we have a
4819 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4820 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4821 {
4822 inst.operands[i].preind = 1;
4823 inst.reloc.exp.X_op = O_constant;
4824 inst.reloc.exp.X_add_number = 0;
4825 }
4826 *str = p;
4962c51a
MS
4827 return PARSE_OPERAND_SUCCESS;
4828}
4829
4830static int
4831parse_address (char **str, int i)
4832{
4833 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4834 ? SUCCESS : FAIL;
4835}
4836
4837static parse_operand_result
4838parse_address_group_reloc (char **str, int i, group_reloc_type type)
4839{
4840 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4841}
4842
b6895b4f
PB
4843/* Parse an operand for a MOVW or MOVT instruction. */
4844static int
4845parse_half (char **str)
4846{
4847 char * p;
5f4273c7 4848
b6895b4f
PB
4849 p = *str;
4850 skip_past_char (&p, '#');
5f4273c7 4851 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4852 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4853 else if (strncasecmp (p, ":upper16:", 9) == 0)
4854 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4855
4856 if (inst.reloc.type != BFD_RELOC_UNUSED)
4857 {
4858 p += 9;
5f4273c7 4859 skip_whitespace (p);
b6895b4f
PB
4860 }
4861
4862 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4863 return FAIL;
4864
4865 if (inst.reloc.type == BFD_RELOC_UNUSED)
4866 {
4867 if (inst.reloc.exp.X_op != O_constant)
4868 {
4869 inst.error = _("constant expression expected");
4870 return FAIL;
4871 }
4872 if (inst.reloc.exp.X_add_number < 0
4873 || inst.reloc.exp.X_add_number > 0xffff)
4874 {
4875 inst.error = _("immediate value out of range");
4876 return FAIL;
4877 }
4878 }
4879 *str = p;
4880 return SUCCESS;
4881}
4882
c19d1205 4883/* Miscellaneous. */
a737bd4d 4884
c19d1205
ZW
4885/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4886 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4887static int
4888parse_psr (char **str)
09d92015 4889{
c19d1205
ZW
4890 char *p;
4891 unsigned long psr_field;
62b3e311
PB
4892 const struct asm_psr *psr;
4893 char *start;
09d92015 4894
c19d1205
ZW
4895 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4896 feature for ease of use and backwards compatibility. */
4897 p = *str;
62b3e311 4898 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4899 psr_field = SPSR_BIT;
62b3e311 4900 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4901 psr_field = 0;
4902 else
62b3e311
PB
4903 {
4904 start = p;
4905 do
4906 p++;
4907 while (ISALNUM (*p) || *p == '_');
4908
4909 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4910 if (!psr)
4911 return FAIL;
09d92015 4912
62b3e311
PB
4913 *str = p;
4914 return psr->field;
4915 }
09d92015 4916
62b3e311 4917 p += 4;
c19d1205
ZW
4918 if (*p == '_')
4919 {
4920 /* A suffix follows. */
c19d1205
ZW
4921 p++;
4922 start = p;
a737bd4d 4923
c19d1205
ZW
4924 do
4925 p++;
4926 while (ISALNUM (*p) || *p == '_');
a737bd4d 4927
c19d1205
ZW
4928 psr = hash_find_n (arm_psr_hsh, start, p - start);
4929 if (!psr)
4930 goto error;
a737bd4d 4931
c19d1205 4932 psr_field |= psr->field;
a737bd4d 4933 }
c19d1205 4934 else
a737bd4d 4935 {
c19d1205
ZW
4936 if (ISALNUM (*p))
4937 goto error; /* Garbage after "[CS]PSR". */
4938
4939 psr_field |= (PSR_c | PSR_f);
a737bd4d 4940 }
c19d1205
ZW
4941 *str = p;
4942 return psr_field;
a737bd4d 4943
c19d1205
ZW
4944 error:
4945 inst.error = _("flag for {c}psr instruction expected");
4946 return FAIL;
a737bd4d
NC
4947}
4948
c19d1205
ZW
4949/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4950 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4951
c19d1205
ZW
4952static int
4953parse_cps_flags (char **str)
a737bd4d 4954{
c19d1205
ZW
4955 int val = 0;
4956 int saw_a_flag = 0;
4957 char *s = *str;
a737bd4d 4958
c19d1205
ZW
4959 for (;;)
4960 switch (*s++)
4961 {
4962 case '\0': case ',':
4963 goto done;
a737bd4d 4964
c19d1205
ZW
4965 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4966 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4967 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4968
c19d1205
ZW
4969 default:
4970 inst.error = _("unrecognized CPS flag");
4971 return FAIL;
4972 }
a737bd4d 4973
c19d1205
ZW
4974 done:
4975 if (saw_a_flag == 0)
a737bd4d 4976 {
c19d1205
ZW
4977 inst.error = _("missing CPS flags");
4978 return FAIL;
a737bd4d 4979 }
a737bd4d 4980
c19d1205
ZW
4981 *str = s - 1;
4982 return val;
a737bd4d
NC
4983}
4984
c19d1205
ZW
4985/* Parse an endian specifier ("BE" or "LE", case insensitive);
4986 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4987
4988static int
c19d1205 4989parse_endian_specifier (char **str)
a737bd4d 4990{
c19d1205
ZW
4991 int little_endian;
4992 char *s = *str;
a737bd4d 4993
c19d1205
ZW
4994 if (strncasecmp (s, "BE", 2))
4995 little_endian = 0;
4996 else if (strncasecmp (s, "LE", 2))
4997 little_endian = 1;
4998 else
a737bd4d 4999 {
c19d1205 5000 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5001 return FAIL;
5002 }
5003
c19d1205 5004 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5005 {
c19d1205 5006 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5007 return FAIL;
5008 }
5009
c19d1205
ZW
5010 *str = s + 2;
5011 return little_endian;
5012}
a737bd4d 5013
c19d1205
ZW
5014/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5015 value suitable for poking into the rotate field of an sxt or sxta
5016 instruction, or FAIL on error. */
5017
5018static int
5019parse_ror (char **str)
5020{
5021 int rot;
5022 char *s = *str;
5023
5024 if (strncasecmp (s, "ROR", 3) == 0)
5025 s += 3;
5026 else
a737bd4d 5027 {
c19d1205 5028 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5029 return FAIL;
5030 }
c19d1205
ZW
5031
5032 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5033 return FAIL;
5034
5035 switch (rot)
a737bd4d 5036 {
c19d1205
ZW
5037 case 0: *str = s; return 0x0;
5038 case 8: *str = s; return 0x1;
5039 case 16: *str = s; return 0x2;
5040 case 24: *str = s; return 0x3;
5041
5042 default:
5043 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5044 return FAIL;
5045 }
c19d1205 5046}
a737bd4d 5047
c19d1205
ZW
5048/* Parse a conditional code (from conds[] below). The value returned is in the
5049 range 0 .. 14, or FAIL. */
5050static int
5051parse_cond (char **str)
5052{
c462b453 5053 char *q;
c19d1205 5054 const struct asm_cond *c;
c462b453
PB
5055 int n;
5056 /* Condition codes are always 2 characters, so matching up to
5057 3 characters is sufficient. */
5058 char cond[3];
a737bd4d 5059
c462b453
PB
5060 q = *str;
5061 n = 0;
5062 while (ISALPHA (*q) && n < 3)
5063 {
5064 cond[n] = TOLOWER(*q);
5065 q++;
5066 n++;
5067 }
a737bd4d 5068
c462b453 5069 c = hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5070 if (!c)
a737bd4d 5071 {
c19d1205 5072 inst.error = _("condition required");
a737bd4d
NC
5073 return FAIL;
5074 }
5075
c19d1205
ZW
5076 *str = q;
5077 return c->value;
5078}
5079
62b3e311
PB
5080/* Parse an option for a barrier instruction. Returns the encoding for the
5081 option, or FAIL. */
5082static int
5083parse_barrier (char **str)
5084{
5085 char *p, *q;
5086 const struct asm_barrier_opt *o;
5087
5088 p = q = *str;
5089 while (ISALPHA (*q))
5090 q++;
5091
5092 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5093 if (!o)
5094 return FAIL;
5095
5096 *str = q;
5097 return o->value;
5098}
5099
92e90b6e
PB
5100/* Parse the operands of a table branch instruction. Similar to a memory
5101 operand. */
5102static int
5103parse_tb (char **str)
5104{
5105 char * p = *str;
5106 int reg;
5107
5108 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5109 {
5110 inst.error = _("'[' expected");
5111 return FAIL;
5112 }
92e90b6e 5113
dcbf9037 5114 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5115 {
5116 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5117 return FAIL;
5118 }
5119 inst.operands[0].reg = reg;
5120
5121 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5122 {
5123 inst.error = _("',' expected");
5124 return FAIL;
5125 }
5f4273c7 5126
dcbf9037 5127 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5128 {
5129 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5130 return FAIL;
5131 }
5132 inst.operands[0].imm = reg;
5133
5134 if (skip_past_comma (&p) == SUCCESS)
5135 {
5136 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5137 return FAIL;
5138 if (inst.reloc.exp.X_add_number != 1)
5139 {
5140 inst.error = _("invalid shift");
5141 return FAIL;
5142 }
5143 inst.operands[0].shifted = 1;
5144 }
5145
5146 if (skip_past_char (&p, ']') == FAIL)
5147 {
5148 inst.error = _("']' expected");
5149 return FAIL;
5150 }
5151 *str = p;
5152 return SUCCESS;
5153}
5154
5287ad62
JB
5155/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5156 information on the types the operands can take and how they are encoded.
037e8744
JB
5157 Up to four operands may be read; this function handles setting the
5158 ".present" field for each read operand itself.
5287ad62
JB
5159 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5160 else returns FAIL. */
5161
5162static int
5163parse_neon_mov (char **str, int *which_operand)
5164{
5165 int i = *which_operand, val;
5166 enum arm_reg_type rtype;
5167 char *ptr = *str;
dcbf9037 5168 struct neon_type_el optype;
5f4273c7 5169
dcbf9037 5170 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5171 {
5172 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5173 inst.operands[i].reg = val;
5174 inst.operands[i].isscalar = 1;
dcbf9037 5175 inst.operands[i].vectype = optype;
5287ad62
JB
5176 inst.operands[i++].present = 1;
5177
5178 if (skip_past_comma (&ptr) == FAIL)
5179 goto wanted_comma;
5f4273c7 5180
dcbf9037 5181 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5182 goto wanted_arm;
5f4273c7 5183
5287ad62
JB
5184 inst.operands[i].reg = val;
5185 inst.operands[i].isreg = 1;
5186 inst.operands[i].present = 1;
5187 }
037e8744 5188 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5189 != FAIL)
5287ad62
JB
5190 {
5191 /* Cases 0, 1, 2, 3, 5 (D only). */
5192 if (skip_past_comma (&ptr) == FAIL)
5193 goto wanted_comma;
5f4273c7 5194
5287ad62
JB
5195 inst.operands[i].reg = val;
5196 inst.operands[i].isreg = 1;
5197 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5198 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5199 inst.operands[i].isvec = 1;
dcbf9037 5200 inst.operands[i].vectype = optype;
5287ad62
JB
5201 inst.operands[i++].present = 1;
5202
dcbf9037 5203 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5204 {
037e8744
JB
5205 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5206 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5207 inst.operands[i].reg = val;
5208 inst.operands[i].isreg = 1;
037e8744 5209 inst.operands[i].present = 1;
5287ad62
JB
5210
5211 if (rtype == REG_TYPE_NQ)
5212 {
dcbf9037 5213 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5214 return FAIL;
5215 }
037e8744
JB
5216 else if (rtype != REG_TYPE_VFS)
5217 {
5218 i++;
5219 if (skip_past_comma (&ptr) == FAIL)
5220 goto wanted_comma;
5221 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5222 goto wanted_arm;
5223 inst.operands[i].reg = val;
5224 inst.operands[i].isreg = 1;
5225 inst.operands[i].present = 1;
5226 }
5287ad62 5227 }
037e8744
JB
5228 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5229 &optype)) != FAIL)
5287ad62
JB
5230 {
5231 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5232 Case 1: VMOV<c><q> <Dd>, <Dm>
5233 Case 8: VMOV.F32 <Sd>, <Sm>
5234 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5235
5236 inst.operands[i].reg = val;
5237 inst.operands[i].isreg = 1;
5238 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5239 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5240 inst.operands[i].isvec = 1;
dcbf9037 5241 inst.operands[i].vectype = optype;
5287ad62 5242 inst.operands[i].present = 1;
5f4273c7 5243
037e8744
JB
5244 if (skip_past_comma (&ptr) == SUCCESS)
5245 {
5246 /* Case 15. */
5247 i++;
5248
5249 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5250 goto wanted_arm;
5251
5252 inst.operands[i].reg = val;
5253 inst.operands[i].isreg = 1;
5254 inst.operands[i++].present = 1;
5f4273c7 5255
037e8744
JB
5256 if (skip_past_comma (&ptr) == FAIL)
5257 goto wanted_comma;
5f4273c7 5258
037e8744
JB
5259 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5260 goto wanted_arm;
5f4273c7 5261
037e8744
JB
5262 inst.operands[i].reg = val;
5263 inst.operands[i].isreg = 1;
5264 inst.operands[i++].present = 1;
5265 }
5287ad62 5266 }
4641781c
PB
5267 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5268 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5269 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5270 Case 10: VMOV.F32 <Sd>, #<imm>
5271 Case 11: VMOV.F64 <Dd>, #<imm> */
5272 inst.operands[i].immisfloat = 1;
5273 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5274 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5275 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5276 ;
5287ad62
JB
5277 else
5278 {
dcbf9037 5279 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5280 return FAIL;
5281 }
5282 }
dcbf9037 5283 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5284 {
5285 /* Cases 6, 7. */
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
dcbf9037 5293 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5294 {
5295 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5296 inst.operands[i].reg = val;
5297 inst.operands[i].isscalar = 1;
5298 inst.operands[i].present = 1;
dcbf9037 5299 inst.operands[i].vectype = optype;
5287ad62 5300 }
dcbf9037 5301 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5302 {
5303 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5304 inst.operands[i].reg = val;
5305 inst.operands[i].isreg = 1;
5306 inst.operands[i++].present = 1;
5f4273c7 5307
5287ad62
JB
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5f4273c7 5310
037e8744 5311 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5312 == FAIL)
5287ad62 5313 {
037e8744 5314 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5315 return FAIL;
5316 }
5317
5318 inst.operands[i].reg = val;
5319 inst.operands[i].isreg = 1;
037e8744
JB
5320 inst.operands[i].isvec = 1;
5321 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5322 inst.operands[i].vectype = optype;
5287ad62 5323 inst.operands[i].present = 1;
5f4273c7 5324
037e8744
JB
5325 if (rtype == REG_TYPE_VFS)
5326 {
5327 /* Case 14. */
5328 i++;
5329 if (skip_past_comma (&ptr) == FAIL)
5330 goto wanted_comma;
5331 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5332 &optype)) == FAIL)
5333 {
5334 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5335 return FAIL;
5336 }
5337 inst.operands[i].reg = val;
5338 inst.operands[i].isreg = 1;
5339 inst.operands[i].isvec = 1;
5340 inst.operands[i].issingle = 1;
5341 inst.operands[i].vectype = optype;
5342 inst.operands[i].present = 1;
5343 }
5344 }
5345 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5346 != FAIL)
5347 {
5348 /* Case 13. */
5349 inst.operands[i].reg = val;
5350 inst.operands[i].isreg = 1;
5351 inst.operands[i].isvec = 1;
5352 inst.operands[i].issingle = 1;
5353 inst.operands[i].vectype = optype;
5354 inst.operands[i++].present = 1;
5287ad62
JB
5355 }
5356 }
5357 else
5358 {
dcbf9037 5359 first_error (_("parse error"));
5287ad62
JB
5360 return FAIL;
5361 }
5362
5363 /* Successfully parsed the operands. Update args. */
5364 *which_operand = i;
5365 *str = ptr;
5366 return SUCCESS;
5367
5f4273c7 5368 wanted_comma:
dcbf9037 5369 first_error (_("expected comma"));
5287ad62 5370 return FAIL;
5f4273c7
NC
5371
5372 wanted_arm:
dcbf9037 5373 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5374 return FAIL;
5287ad62
JB
5375}
5376
c19d1205
ZW
5377/* Matcher codes for parse_operands. */
5378enum operand_parse_code
5379{
5380 OP_stop, /* end of line */
5381
5382 OP_RR, /* ARM register */
5383 OP_RRnpc, /* ARM register, not r15 */
5384 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5385 OP_RRw, /* ARM register, not r15, optional trailing ! */
5386 OP_RCP, /* Coprocessor number */
5387 OP_RCN, /* Coprocessor register */
5388 OP_RF, /* FPA register */
5389 OP_RVS, /* VFP single precision register */
5287ad62
JB
5390 OP_RVD, /* VFP double precision register (0..15) */
5391 OP_RND, /* Neon double precision register (0..31) */
5392 OP_RNQ, /* Neon quad precision register */
037e8744 5393 OP_RVSD, /* VFP single or double precision register */
5287ad62 5394 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5395 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5396 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5397 OP_RVC, /* VFP control register */
5398 OP_RMF, /* Maverick F register */
5399 OP_RMD, /* Maverick D register */
5400 OP_RMFX, /* Maverick FX register */
5401 OP_RMDX, /* Maverick DX register */
5402 OP_RMAX, /* Maverick AX register */
5403 OP_RMDS, /* Maverick DSPSC register */
5404 OP_RIWR, /* iWMMXt wR register */
5405 OP_RIWC, /* iWMMXt wC register */
5406 OP_RIWG, /* iWMMXt wCG register */
5407 OP_RXA, /* XScale accumulator register */
5408
5409 OP_REGLST, /* ARM register list */
5410 OP_VRSLST, /* VFP single-precision register list */
5411 OP_VRDLST, /* VFP double-precision register list */
037e8744 5412 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5413 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5414 OP_NSTRLST, /* Neon element/structure list */
5415
5416 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5417 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5418 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5419 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5420 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5421 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5422 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5423 OP_VMOV, /* Neon VMOV operands. */
5424 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5425 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5426 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5427
5428 OP_I0, /* immediate zero */
c19d1205
ZW
5429 OP_I7, /* immediate value 0 .. 7 */
5430 OP_I15, /* 0 .. 15 */
5431 OP_I16, /* 1 .. 16 */
5287ad62 5432 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5433 OP_I31, /* 0 .. 31 */
5434 OP_I31w, /* 0 .. 31, optional trailing ! */
5435 OP_I32, /* 1 .. 32 */
5287ad62
JB
5436 OP_I32z, /* 0 .. 32 */
5437 OP_I63, /* 0 .. 63 */
c19d1205 5438 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5439 OP_I64, /* 1 .. 64 */
5440 OP_I64z, /* 0 .. 64 */
c19d1205 5441 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5442
5443 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5444 OP_I7b, /* 0 .. 7 */
5445 OP_I15b, /* 0 .. 15 */
5446 OP_I31b, /* 0 .. 31 */
5447
5448 OP_SH, /* shifter operand */
4962c51a 5449 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5450 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5451 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5452 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5453 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5454 OP_EXP, /* arbitrary expression */
5455 OP_EXPi, /* same, with optional immediate prefix */
5456 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5457 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5458
5459 OP_CPSF, /* CPS flags */
5460 OP_ENDI, /* Endianness specifier */
5461 OP_PSR, /* CPSR/SPSR mask for msr */
5462 OP_COND, /* conditional code */
92e90b6e 5463 OP_TB, /* Table branch. */
c19d1205 5464
037e8744
JB
5465 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5466 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5467
c19d1205
ZW
5468 OP_RRnpc_I0, /* ARM register or literal 0 */
5469 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5470 OP_RR_EXi, /* ARM register or expression with imm prefix */
5471 OP_RF_IF, /* FPA register or immediate */
5472 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5473 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5474
5475 /* Optional operands. */
5476 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5477 OP_oI31b, /* 0 .. 31 */
5287ad62 5478 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5479 OP_oIffffb, /* 0 .. 65535 */
5480 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5481
5482 OP_oRR, /* ARM register */
5483 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5484 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5485 OP_oRND, /* Optional Neon double precision register */
5486 OP_oRNQ, /* Optional Neon quad precision register */
5487 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5488 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5489 OP_oSHll, /* LSL immediate */
5490 OP_oSHar, /* ASR immediate */
5491 OP_oSHllar, /* LSL or ASR immediate */
5492 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5493 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5494
5495 OP_FIRST_OPTIONAL = OP_oI7b
5496};
a737bd4d 5497
c19d1205
ZW
5498/* Generic instruction operand parser. This does no encoding and no
5499 semantic validation; it merely squirrels values away in the inst
5500 structure. Returns SUCCESS or FAIL depending on whether the
5501 specified grammar matched. */
5502static int
ca3f61f7 5503parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5504{
5505 unsigned const char *upat = pattern;
5506 char *backtrack_pos = 0;
5507 const char *backtrack_error = 0;
5508 int i, val, backtrack_index = 0;
5287ad62 5509 enum arm_reg_type rtype;
4962c51a 5510 parse_operand_result result;
c19d1205
ZW
5511
5512#define po_char_or_fail(chr) do { \
5513 if (skip_past_char (&str, chr) == FAIL) \
5514 goto bad_args; \
5515} while (0)
5516
dcbf9037
JB
5517#define po_reg_or_fail(regtype) do { \
5518 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5519 &inst.operands[i].vectype); \
5520 if (val == FAIL) \
5521 { \
5522 first_error (_(reg_expected_msgs[regtype])); \
5523 goto failure; \
5524 } \
5525 inst.operands[i].reg = val; \
5526 inst.operands[i].isreg = 1; \
5527 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5528 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5529 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5530 || rtype == REG_TYPE_VFD \
5531 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5532} while (0)
5533
dcbf9037
JB
5534#define po_reg_or_goto(regtype, label) do { \
5535 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5536 &inst.operands[i].vectype); \
5537 if (val == FAIL) \
5538 goto label; \
5539 \
5540 inst.operands[i].reg = val; \
5541 inst.operands[i].isreg = 1; \
5542 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5543 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5544 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5545 || rtype == REG_TYPE_VFD \
5546 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5547} while (0)
5548
5549#define po_imm_or_fail(min, max, popt) do { \
5550 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5551 goto failure; \
5552 inst.operands[i].imm = val; \
5553} while (0)
5554
dcbf9037
JB
5555#define po_scalar_or_goto(elsz, label) do { \
5556 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5557 if (val == FAIL) \
5558 goto label; \
5559 inst.operands[i].reg = val; \
5560 inst.operands[i].isscalar = 1; \
5287ad62
JB
5561} while (0)
5562
c19d1205
ZW
5563#define po_misc_or_fail(expr) do { \
5564 if (expr) \
5565 goto failure; \
5566} while (0)
5567
4962c51a
MS
5568#define po_misc_or_fail_no_backtrack(expr) do { \
5569 result = expr; \
5570 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5571 backtrack_pos = 0; \
5572 if (result != PARSE_OPERAND_SUCCESS) \
5573 goto failure; \
5574} while (0)
5575
c19d1205
ZW
5576 skip_whitespace (str);
5577
5578 for (i = 0; upat[i] != OP_stop; i++)
5579 {
5580 if (upat[i] >= OP_FIRST_OPTIONAL)
5581 {
5582 /* Remember where we are in case we need to backtrack. */
5583 assert (!backtrack_pos);
5584 backtrack_pos = str;
5585 backtrack_error = inst.error;
5586 backtrack_index = i;
5587 }
5588
b6702015 5589 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5590 po_char_or_fail (',');
5591
5592 switch (upat[i])
5593 {
5594 /* Registers */
5595 case OP_oRRnpc:
5596 case OP_RRnpc:
5597 case OP_oRR:
5598 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5599 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5600 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5601 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5602 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5603 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5604 case OP_oRND:
5605 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5606 case OP_RVC:
5607 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5608 break;
5609 /* Also accept generic coprocessor regs for unknown registers. */
5610 coproc_reg:
5611 po_reg_or_fail (REG_TYPE_CN);
5612 break;
c19d1205
ZW
5613 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5614 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5615 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5616 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5617 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5618 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5619 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5620 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5621 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5622 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5623 case OP_oRNQ:
5624 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5625 case OP_oRNDQ:
5626 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5627 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5628 case OP_oRNSDQ:
5629 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5630
5631 /* Neon scalar. Using an element size of 8 means that some invalid
5632 scalars are accepted here, so deal with those in later code. */
5633 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5634
5635 /* WARNING: We can expand to two operands here. This has the potential
5636 to totally confuse the backtracking mechanism! It will be OK at
5637 least as long as we don't try to use optional args as well,
5638 though. */
5639 case OP_NILO:
5640 {
5641 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5642 inst.operands[i].present = 1;
5287ad62
JB
5643 i++;
5644 skip_past_comma (&str);
5645 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5646 break;
5647 one_reg_only:
5648 /* Optional register operand was omitted. Unfortunately, it's in
5649 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5650 here (this is a bit grotty). */
5651 inst.operands[i] = inst.operands[i-1];
5652 inst.operands[i-1].present = 0;
5653 break;
5654 try_imm:
036dc3f7
PB
5655 /* There's a possibility of getting a 64-bit immediate here, so
5656 we need special handling. */
5657 if (parse_big_immediate (&str, i) == FAIL)
5658 {
5659 inst.error = _("immediate value is out of range");
5660 goto failure;
5661 }
5287ad62
JB
5662 }
5663 break;
5664
5665 case OP_RNDQ_I0:
5666 {
5667 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5668 break;
5669 try_imm0:
5670 po_imm_or_fail (0, 0, TRUE);
5671 }
5672 break;
5673
037e8744
JB
5674 case OP_RVSD_I0:
5675 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5676 break;
5677
5287ad62
JB
5678 case OP_RR_RNSC:
5679 {
5680 po_scalar_or_goto (8, try_rr);
5681 break;
5682 try_rr:
5683 po_reg_or_fail (REG_TYPE_RN);
5684 }
5685 break;
5686
037e8744
JB
5687 case OP_RNSDQ_RNSC:
5688 {
5689 po_scalar_or_goto (8, try_nsdq);
5690 break;
5691 try_nsdq:
5692 po_reg_or_fail (REG_TYPE_NSDQ);
5693 }
5694 break;
5695
5287ad62
JB
5696 case OP_RNDQ_RNSC:
5697 {
5698 po_scalar_or_goto (8, try_ndq);
5699 break;
5700 try_ndq:
5701 po_reg_or_fail (REG_TYPE_NDQ);
5702 }
5703 break;
5704
5705 case OP_RND_RNSC:
5706 {
5707 po_scalar_or_goto (8, try_vfd);
5708 break;
5709 try_vfd:
5710 po_reg_or_fail (REG_TYPE_VFD);
5711 }
5712 break;
5713
5714 case OP_VMOV:
5715 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5716 not careful then bad things might happen. */
5717 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5718 break;
5719
5720 case OP_RNDQ_IMVNb:
5721 {
5722 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5723 break;
5724 try_mvnimm:
5725 /* There's a possibility of getting a 64-bit immediate here, so
5726 we need special handling. */
5727 if (parse_big_immediate (&str, i) == FAIL)
5728 {
5729 inst.error = _("immediate value is out of range");
5730 goto failure;
5731 }
5732 }
5733 break;
5734
5735 case OP_RNDQ_I63b:
5736 {
5737 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5738 break;
5739 try_shimm:
5740 po_imm_or_fail (0, 63, TRUE);
5741 }
5742 break;
c19d1205
ZW
5743
5744 case OP_RRnpcb:
5745 po_char_or_fail ('[');
5746 po_reg_or_fail (REG_TYPE_RN);
5747 po_char_or_fail (']');
5748 break;
a737bd4d 5749
c19d1205 5750 case OP_RRw:
b6702015 5751 case OP_oRRw:
c19d1205
ZW
5752 po_reg_or_fail (REG_TYPE_RN);
5753 if (skip_past_char (&str, '!') == SUCCESS)
5754 inst.operands[i].writeback = 1;
5755 break;
5756
5757 /* Immediates */
5758 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5759 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5760 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5761 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5762 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5763 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5764 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5765 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5766 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5767 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5768 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5769 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5770
5771 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5772 case OP_oI7b:
5773 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5774 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5775 case OP_oI31b:
5776 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5777 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5778 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5779
5780 /* Immediate variants */
5781 case OP_oI255c:
5782 po_char_or_fail ('{');
5783 po_imm_or_fail (0, 255, TRUE);
5784 po_char_or_fail ('}');
5785 break;
5786
5787 case OP_I31w:
5788 /* The expression parser chokes on a trailing !, so we have
5789 to find it first and zap it. */
5790 {
5791 char *s = str;
5792 while (*s && *s != ',')
5793 s++;
5794 if (s[-1] == '!')
5795 {
5796 s[-1] = '\0';
5797 inst.operands[i].writeback = 1;
5798 }
5799 po_imm_or_fail (0, 31, TRUE);
5800 if (str == s - 1)
5801 str = s;
5802 }
5803 break;
5804
5805 /* Expressions */
5806 case OP_EXPi: EXPi:
5807 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5808 GE_OPT_PREFIX));
5809 break;
5810
5811 case OP_EXP:
5812 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5813 GE_NO_PREFIX));
5814 break;
5815
5816 case OP_EXPr: EXPr:
5817 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5818 GE_NO_PREFIX));
5819 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5820 {
c19d1205
ZW
5821 val = parse_reloc (&str);
5822 if (val == -1)
5823 {
5824 inst.error = _("unrecognized relocation suffix");
5825 goto failure;
5826 }
5827 else if (val != BFD_RELOC_UNUSED)
5828 {
5829 inst.operands[i].imm = val;
5830 inst.operands[i].hasreloc = 1;
5831 }
a737bd4d 5832 }
c19d1205 5833 break;
a737bd4d 5834
b6895b4f
PB
5835 /* Operand for MOVW or MOVT. */
5836 case OP_HALF:
5837 po_misc_or_fail (parse_half (&str));
5838 break;
5839
c19d1205
ZW
5840 /* Register or expression */
5841 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5842 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5843
c19d1205
ZW
5844 /* Register or immediate */
5845 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5846 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5847
c19d1205
ZW
5848 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5849 IF:
5850 if (!is_immediate_prefix (*str))
5851 goto bad_args;
5852 str++;
5853 val = parse_fpa_immediate (&str);
5854 if (val == FAIL)
5855 goto failure;
5856 /* FPA immediates are encoded as registers 8-15.
5857 parse_fpa_immediate has already applied the offset. */
5858 inst.operands[i].reg = val;
5859 inst.operands[i].isreg = 1;
5860 break;
09d92015 5861
2d447fca
JM
5862 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5863 I32z: po_imm_or_fail (0, 32, FALSE); break;
5864
c19d1205
ZW
5865 /* Two kinds of register */
5866 case OP_RIWR_RIWC:
5867 {
5868 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5869 if (!rege
5870 || (rege->type != REG_TYPE_MMXWR
5871 && rege->type != REG_TYPE_MMXWC
5872 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5873 {
5874 inst.error = _("iWMMXt data or control register expected");
5875 goto failure;
5876 }
5877 inst.operands[i].reg = rege->number;
5878 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5879 }
5880 break;
09d92015 5881
41adaa5c
JM
5882 case OP_RIWC_RIWG:
5883 {
5884 struct reg_entry *rege = arm_reg_parse_multi (&str);
5885 if (!rege
5886 || (rege->type != REG_TYPE_MMXWC
5887 && rege->type != REG_TYPE_MMXWCG))
5888 {
5889 inst.error = _("iWMMXt control register expected");
5890 goto failure;
5891 }
5892 inst.operands[i].reg = rege->number;
5893 inst.operands[i].isreg = 1;
5894 }
5895 break;
5896
c19d1205
ZW
5897 /* Misc */
5898 case OP_CPSF: val = parse_cps_flags (&str); break;
5899 case OP_ENDI: val = parse_endian_specifier (&str); break;
5900 case OP_oROR: val = parse_ror (&str); break;
5901 case OP_PSR: val = parse_psr (&str); break;
5902 case OP_COND: val = parse_cond (&str); break;
62b3e311 5903 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5904
037e8744
JB
5905 case OP_RVC_PSR:
5906 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5907 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5908 break;
5909 try_psr:
5910 val = parse_psr (&str);
5911 break;
5912
5913 case OP_APSR_RR:
5914 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5915 break;
5916 try_apsr:
5917 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5918 instruction). */
5919 if (strncasecmp (str, "APSR_", 5) == 0)
5920 {
5921 unsigned found = 0;
5922 str += 5;
5923 while (found < 15)
5924 switch (*str++)
5925 {
5926 case 'c': found = (found & 1) ? 16 : found | 1; break;
5927 case 'n': found = (found & 2) ? 16 : found | 2; break;
5928 case 'z': found = (found & 4) ? 16 : found | 4; break;
5929 case 'v': found = (found & 8) ? 16 : found | 8; break;
5930 default: found = 16;
5931 }
5932 if (found != 15)
5933 goto failure;
5934 inst.operands[i].isvec = 1;
5935 }
5936 else
5937 goto failure;
5938 break;
5939
92e90b6e
PB
5940 case OP_TB:
5941 po_misc_or_fail (parse_tb (&str));
5942 break;
5943
c19d1205
ZW
5944 /* Register lists */
5945 case OP_REGLST:
5946 val = parse_reg_list (&str);
5947 if (*str == '^')
5948 {
5949 inst.operands[1].writeback = 1;
5950 str++;
5951 }
5952 break;
09d92015 5953
c19d1205 5954 case OP_VRSLST:
5287ad62 5955 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5956 break;
09d92015 5957
c19d1205 5958 case OP_VRDLST:
5287ad62 5959 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5960 break;
a737bd4d 5961
037e8744
JB
5962 case OP_VRSDLST:
5963 /* Allow Q registers too. */
5964 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5965 REGLIST_NEON_D);
5966 if (val == FAIL)
5967 {
5968 inst.error = NULL;
5969 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5970 REGLIST_VFP_S);
5971 inst.operands[i].issingle = 1;
5972 }
5973 break;
5974
5287ad62
JB
5975 case OP_NRDLST:
5976 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5977 REGLIST_NEON_D);
5978 break;
5979
5980 case OP_NSTRLST:
dcbf9037
JB
5981 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5982 &inst.operands[i].vectype);
5287ad62
JB
5983 break;
5984
c19d1205
ZW
5985 /* Addressing modes */
5986 case OP_ADDR:
5987 po_misc_or_fail (parse_address (&str, i));
5988 break;
09d92015 5989
4962c51a
MS
5990 case OP_ADDRGLDR:
5991 po_misc_or_fail_no_backtrack (
5992 parse_address_group_reloc (&str, i, GROUP_LDR));
5993 break;
5994
5995 case OP_ADDRGLDRS:
5996 po_misc_or_fail_no_backtrack (
5997 parse_address_group_reloc (&str, i, GROUP_LDRS));
5998 break;
5999
6000 case OP_ADDRGLDC:
6001 po_misc_or_fail_no_backtrack (
6002 parse_address_group_reloc (&str, i, GROUP_LDC));
6003 break;
6004
c19d1205
ZW
6005 case OP_SH:
6006 po_misc_or_fail (parse_shifter_operand (&str, i));
6007 break;
09d92015 6008
4962c51a
MS
6009 case OP_SHG:
6010 po_misc_or_fail_no_backtrack (
6011 parse_shifter_operand_group_reloc (&str, i));
6012 break;
6013
c19d1205
ZW
6014 case OP_oSHll:
6015 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6016 break;
09d92015 6017
c19d1205
ZW
6018 case OP_oSHar:
6019 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6020 break;
09d92015 6021
c19d1205
ZW
6022 case OP_oSHllar:
6023 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6024 break;
09d92015 6025
c19d1205 6026 default:
bd3ba5d1 6027 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6028 }
09d92015 6029
c19d1205
ZW
6030 /* Various value-based sanity checks and shared operations. We
6031 do not signal immediate failures for the register constraints;
6032 this allows a syntax error to take precedence. */
6033 switch (upat[i])
6034 {
6035 case OP_oRRnpc:
6036 case OP_RRnpc:
6037 case OP_RRnpcb:
6038 case OP_RRw:
b6702015 6039 case OP_oRRw:
c19d1205
ZW
6040 case OP_RRnpc_I0:
6041 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6042 inst.error = BAD_PC;
6043 break;
09d92015 6044
c19d1205
ZW
6045 case OP_CPSF:
6046 case OP_ENDI:
6047 case OP_oROR:
6048 case OP_PSR:
037e8744 6049 case OP_RVC_PSR:
c19d1205 6050 case OP_COND:
62b3e311 6051 case OP_oBARRIER:
c19d1205
ZW
6052 case OP_REGLST:
6053 case OP_VRSLST:
6054 case OP_VRDLST:
037e8744 6055 case OP_VRSDLST:
5287ad62
JB
6056 case OP_NRDLST:
6057 case OP_NSTRLST:
c19d1205
ZW
6058 if (val == FAIL)
6059 goto failure;
6060 inst.operands[i].imm = val;
6061 break;
a737bd4d 6062
c19d1205
ZW
6063 default:
6064 break;
6065 }
09d92015 6066
c19d1205
ZW
6067 /* If we get here, this operand was successfully parsed. */
6068 inst.operands[i].present = 1;
6069 continue;
09d92015 6070
c19d1205 6071 bad_args:
09d92015 6072 inst.error = BAD_ARGS;
c19d1205
ZW
6073
6074 failure:
6075 if (!backtrack_pos)
d252fdde
PB
6076 {
6077 /* The parse routine should already have set inst.error, but set a
5f4273c7 6078 default here just in case. */
d252fdde
PB
6079 if (!inst.error)
6080 inst.error = _("syntax error");
6081 return FAIL;
6082 }
c19d1205
ZW
6083
6084 /* Do not backtrack over a trailing optional argument that
6085 absorbed some text. We will only fail again, with the
6086 'garbage following instruction' error message, which is
6087 probably less helpful than the current one. */
6088 if (backtrack_index == i && backtrack_pos != str
6089 && upat[i+1] == OP_stop)
d252fdde
PB
6090 {
6091 if (!inst.error)
6092 inst.error = _("syntax error");
6093 return FAIL;
6094 }
c19d1205
ZW
6095
6096 /* Try again, skipping the optional argument at backtrack_pos. */
6097 str = backtrack_pos;
6098 inst.error = backtrack_error;
6099 inst.operands[backtrack_index].present = 0;
6100 i = backtrack_index;
6101 backtrack_pos = 0;
09d92015 6102 }
09d92015 6103
c19d1205
ZW
6104 /* Check that we have parsed all the arguments. */
6105 if (*str != '\0' && !inst.error)
6106 inst.error = _("garbage following instruction");
09d92015 6107
c19d1205 6108 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6109}
6110
c19d1205
ZW
6111#undef po_char_or_fail
6112#undef po_reg_or_fail
6113#undef po_reg_or_goto
6114#undef po_imm_or_fail
5287ad62 6115#undef po_scalar_or_fail
c19d1205
ZW
6116\f
6117/* Shorthand macro for instruction encoding functions issuing errors. */
6118#define constraint(expr, err) do { \
6119 if (expr) \
6120 { \
6121 inst.error = err; \
6122 return; \
6123 } \
6124} while (0)
6125
6126/* Functions for operand encoding. ARM, then Thumb. */
6127
6128#define rotate_left(v, n) (v << n | v >> (32 - n))
6129
6130/* If VAL can be encoded in the immediate field of an ARM instruction,
6131 return the encoded form. Otherwise, return FAIL. */
6132
6133static unsigned int
6134encode_arm_immediate (unsigned int val)
09d92015 6135{
c19d1205
ZW
6136 unsigned int a, i;
6137
6138 for (i = 0; i < 32; i += 2)
6139 if ((a = rotate_left (val, i)) <= 0xff)
6140 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6141
6142 return FAIL;
09d92015
MM
6143}
6144
c19d1205
ZW
6145/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6146 return the encoded form. Otherwise, return FAIL. */
6147static unsigned int
6148encode_thumb32_immediate (unsigned int val)
09d92015 6149{
c19d1205 6150 unsigned int a, i;
09d92015 6151
9c3c69f2 6152 if (val <= 0xff)
c19d1205 6153 return val;
a737bd4d 6154
9c3c69f2 6155 for (i = 1; i <= 24; i++)
09d92015 6156 {
9c3c69f2
PB
6157 a = val >> i;
6158 if ((val & ~(0xff << i)) == 0)
6159 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6160 }
a737bd4d 6161
c19d1205
ZW
6162 a = val & 0xff;
6163 if (val == ((a << 16) | a))
6164 return 0x100 | a;
6165 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6166 return 0x300 | a;
09d92015 6167
c19d1205
ZW
6168 a = val & 0xff00;
6169 if (val == ((a << 16) | a))
6170 return 0x200 | (a >> 8);
a737bd4d 6171
c19d1205 6172 return FAIL;
09d92015 6173}
5287ad62 6174/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6175
6176static void
5287ad62
JB
6177encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6178{
6179 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6180 && reg > 15)
6181 {
b1cc4aeb 6182 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6183 {
6184 if (thumb_mode)
6185 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6186 fpu_vfp_ext_d32);
5287ad62
JB
6187 else
6188 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6189 fpu_vfp_ext_d32);
5287ad62
JB
6190 }
6191 else
6192 {
dcbf9037 6193 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6194 return;
6195 }
6196 }
6197
c19d1205 6198 switch (pos)
09d92015 6199 {
c19d1205
ZW
6200 case VFP_REG_Sd:
6201 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6202 break;
6203
6204 case VFP_REG_Sn:
6205 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6206 break;
6207
6208 case VFP_REG_Sm:
6209 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6210 break;
6211
5287ad62
JB
6212 case VFP_REG_Dd:
6213 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6214 break;
5f4273c7 6215
5287ad62
JB
6216 case VFP_REG_Dn:
6217 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6218 break;
5f4273c7 6219
5287ad62
JB
6220 case VFP_REG_Dm:
6221 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6222 break;
6223
c19d1205
ZW
6224 default:
6225 abort ();
09d92015 6226 }
09d92015
MM
6227}
6228
c19d1205 6229/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6230 if any, is handled by md_apply_fix. */
09d92015 6231static void
c19d1205 6232encode_arm_shift (int i)
09d92015 6233{
c19d1205
ZW
6234 if (inst.operands[i].shift_kind == SHIFT_RRX)
6235 inst.instruction |= SHIFT_ROR << 5;
6236 else
09d92015 6237 {
c19d1205
ZW
6238 inst.instruction |= inst.operands[i].shift_kind << 5;
6239 if (inst.operands[i].immisreg)
6240 {
6241 inst.instruction |= SHIFT_BY_REG;
6242 inst.instruction |= inst.operands[i].imm << 8;
6243 }
6244 else
6245 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6246 }
c19d1205 6247}
09d92015 6248
c19d1205
ZW
6249static void
6250encode_arm_shifter_operand (int i)
6251{
6252 if (inst.operands[i].isreg)
09d92015 6253 {
c19d1205
ZW
6254 inst.instruction |= inst.operands[i].reg;
6255 encode_arm_shift (i);
09d92015 6256 }
c19d1205
ZW
6257 else
6258 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6259}
6260
c19d1205 6261/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6262static void
c19d1205 6263encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6264{
c19d1205
ZW
6265 assert (inst.operands[i].isreg);
6266 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6267
c19d1205 6268 if (inst.operands[i].preind)
09d92015 6269 {
c19d1205
ZW
6270 if (is_t)
6271 {
6272 inst.error = _("instruction does not accept preindexed addressing");
6273 return;
6274 }
6275 inst.instruction |= PRE_INDEX;
6276 if (inst.operands[i].writeback)
6277 inst.instruction |= WRITE_BACK;
09d92015 6278
c19d1205
ZW
6279 }
6280 else if (inst.operands[i].postind)
6281 {
6282 assert (inst.operands[i].writeback);
6283 if (is_t)
6284 inst.instruction |= WRITE_BACK;
6285 }
6286 else /* unindexed - only for coprocessor */
09d92015 6287 {
c19d1205 6288 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6289 return;
6290 }
6291
c19d1205
ZW
6292 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6293 && (((inst.instruction & 0x000f0000) >> 16)
6294 == ((inst.instruction & 0x0000f000) >> 12)))
6295 as_warn ((inst.instruction & LOAD_BIT)
6296 ? _("destination register same as write-back base")
6297 : _("source register same as write-back base"));
09d92015
MM
6298}
6299
c19d1205
ZW
6300/* inst.operands[i] was set up by parse_address. Encode it into an
6301 ARM-format mode 2 load or store instruction. If is_t is true,
6302 reject forms that cannot be used with a T instruction (i.e. not
6303 post-indexed). */
a737bd4d 6304static void
c19d1205 6305encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6306{
c19d1205 6307 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6308
c19d1205 6309 if (inst.operands[i].immisreg)
09d92015 6310 {
c19d1205
ZW
6311 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6312 inst.instruction |= inst.operands[i].imm;
6313 if (!inst.operands[i].negative)
6314 inst.instruction |= INDEX_UP;
6315 if (inst.operands[i].shifted)
6316 {
6317 if (inst.operands[i].shift_kind == SHIFT_RRX)
6318 inst.instruction |= SHIFT_ROR << 5;
6319 else
6320 {
6321 inst.instruction |= inst.operands[i].shift_kind << 5;
6322 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6323 }
6324 }
09d92015 6325 }
c19d1205 6326 else /* immediate offset in inst.reloc */
09d92015 6327 {
c19d1205
ZW
6328 if (inst.reloc.type == BFD_RELOC_UNUSED)
6329 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6330 }
09d92015
MM
6331}
6332
c19d1205
ZW
6333/* inst.operands[i] was set up by parse_address. Encode it into an
6334 ARM-format mode 3 load or store instruction. Reject forms that
6335 cannot be used with such instructions. If is_t is true, reject
6336 forms that cannot be used with a T instruction (i.e. not
6337 post-indexed). */
6338static void
6339encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6340{
c19d1205 6341 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6342 {
c19d1205
ZW
6343 inst.error = _("instruction does not accept scaled register index");
6344 return;
09d92015 6345 }
a737bd4d 6346
c19d1205 6347 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6348
c19d1205
ZW
6349 if (inst.operands[i].immisreg)
6350 {
6351 inst.instruction |= inst.operands[i].imm;
6352 if (!inst.operands[i].negative)
6353 inst.instruction |= INDEX_UP;
6354 }
6355 else /* immediate offset in inst.reloc */
6356 {
6357 inst.instruction |= HWOFFSET_IMM;
6358 if (inst.reloc.type == BFD_RELOC_UNUSED)
6359 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6360 }
a737bd4d
NC
6361}
6362
c19d1205
ZW
6363/* inst.operands[i] was set up by parse_address. Encode it into an
6364 ARM-format instruction. Reject all forms which cannot be encoded
6365 into a coprocessor load/store instruction. If wb_ok is false,
6366 reject use of writeback; if unind_ok is false, reject use of
6367 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6368 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6369 (in which case it is preserved). */
09d92015 6370
c19d1205
ZW
6371static int
6372encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6373{
c19d1205 6374 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6375
c19d1205 6376 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6377
c19d1205 6378 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6379 {
c19d1205
ZW
6380 assert (!inst.operands[i].writeback);
6381 if (!unind_ok)
6382 {
6383 inst.error = _("instruction does not support unindexed addressing");
6384 return FAIL;
6385 }
6386 inst.instruction |= inst.operands[i].imm;
6387 inst.instruction |= INDEX_UP;
6388 return SUCCESS;
09d92015 6389 }
a737bd4d 6390
c19d1205
ZW
6391 if (inst.operands[i].preind)
6392 inst.instruction |= PRE_INDEX;
a737bd4d 6393
c19d1205 6394 if (inst.operands[i].writeback)
09d92015 6395 {
c19d1205
ZW
6396 if (inst.operands[i].reg == REG_PC)
6397 {
6398 inst.error = _("pc may not be used with write-back");
6399 return FAIL;
6400 }
6401 if (!wb_ok)
6402 {
6403 inst.error = _("instruction does not support writeback");
6404 return FAIL;
6405 }
6406 inst.instruction |= WRITE_BACK;
09d92015 6407 }
a737bd4d 6408
c19d1205
ZW
6409 if (reloc_override)
6410 inst.reloc.type = reloc_override;
4962c51a
MS
6411 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6412 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6413 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6414 {
6415 if (thumb_mode)
6416 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6417 else
6418 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6419 }
6420
c19d1205
ZW
6421 return SUCCESS;
6422}
a737bd4d 6423
c19d1205
ZW
6424/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6425 Determine whether it can be performed with a move instruction; if
6426 it can, convert inst.instruction to that move instruction and
6427 return 1; if it can't, convert inst.instruction to a literal-pool
6428 load and return 0. If this is not a valid thing to do in the
6429 current context, set inst.error and return 1.
a737bd4d 6430
c19d1205
ZW
6431 inst.operands[i] describes the destination register. */
6432
6433static int
6434move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6435{
53365c0d
PB
6436 unsigned long tbit;
6437
6438 if (thumb_p)
6439 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6440 else
6441 tbit = LOAD_BIT;
6442
6443 if ((inst.instruction & tbit) == 0)
09d92015 6444 {
c19d1205
ZW
6445 inst.error = _("invalid pseudo operation");
6446 return 1;
09d92015 6447 }
c19d1205 6448 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6449 {
6450 inst.error = _("constant expression expected");
c19d1205 6451 return 1;
09d92015 6452 }
c19d1205 6453 if (inst.reloc.exp.X_op == O_constant)
09d92015 6454 {
c19d1205
ZW
6455 if (thumb_p)
6456 {
53365c0d 6457 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6458 {
6459 /* This can be done with a mov(1) instruction. */
6460 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6461 inst.instruction |= inst.reloc.exp.X_add_number;
6462 return 1;
6463 }
6464 }
6465 else
6466 {
6467 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6468 if (value != FAIL)
6469 {
6470 /* This can be done with a mov instruction. */
6471 inst.instruction &= LITERAL_MASK;
6472 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6473 inst.instruction |= value & 0xfff;
6474 return 1;
6475 }
09d92015 6476
c19d1205
ZW
6477 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6478 if (value != FAIL)
6479 {
6480 /* This can be done with a mvn instruction. */
6481 inst.instruction &= LITERAL_MASK;
6482 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6483 inst.instruction |= value & 0xfff;
6484 return 1;
6485 }
6486 }
09d92015
MM
6487 }
6488
c19d1205
ZW
6489 if (add_to_lit_pool () == FAIL)
6490 {
6491 inst.error = _("literal pool insertion failed");
6492 return 1;
6493 }
6494 inst.operands[1].reg = REG_PC;
6495 inst.operands[1].isreg = 1;
6496 inst.operands[1].preind = 1;
6497 inst.reloc.pc_rel = 1;
6498 inst.reloc.type = (thumb_p
6499 ? BFD_RELOC_ARM_THUMB_OFFSET
6500 : (mode_3
6501 ? BFD_RELOC_ARM_HWLITERAL
6502 : BFD_RELOC_ARM_LITERAL));
6503 return 0;
09d92015
MM
6504}
6505
5f4273c7 6506/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6507 First some generics; their names are taken from the conventional
6508 bit positions for register arguments in ARM format instructions. */
09d92015 6509
a737bd4d 6510static void
c19d1205 6511do_noargs (void)
09d92015 6512{
c19d1205 6513}
a737bd4d 6514
c19d1205
ZW
6515static void
6516do_rd (void)
6517{
6518 inst.instruction |= inst.operands[0].reg << 12;
6519}
a737bd4d 6520
c19d1205
ZW
6521static void
6522do_rd_rm (void)
6523{
6524 inst.instruction |= inst.operands[0].reg << 12;
6525 inst.instruction |= inst.operands[1].reg;
6526}
09d92015 6527
c19d1205
ZW
6528static void
6529do_rd_rn (void)
6530{
6531 inst.instruction |= inst.operands[0].reg << 12;
6532 inst.instruction |= inst.operands[1].reg << 16;
6533}
a737bd4d 6534
c19d1205
ZW
6535static void
6536do_rn_rd (void)
6537{
6538 inst.instruction |= inst.operands[0].reg << 16;
6539 inst.instruction |= inst.operands[1].reg << 12;
6540}
09d92015 6541
c19d1205
ZW
6542static void
6543do_rd_rm_rn (void)
6544{
9a64e435 6545 unsigned Rn = inst.operands[2].reg;
708587a4 6546 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6547 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6548 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6549 _("Rn must not overlap other operands"));
c19d1205
ZW
6550 inst.instruction |= inst.operands[0].reg << 12;
6551 inst.instruction |= inst.operands[1].reg;
9a64e435 6552 inst.instruction |= Rn << 16;
c19d1205 6553}
09d92015 6554
c19d1205
ZW
6555static void
6556do_rd_rn_rm (void)
6557{
6558 inst.instruction |= inst.operands[0].reg << 12;
6559 inst.instruction |= inst.operands[1].reg << 16;
6560 inst.instruction |= inst.operands[2].reg;
6561}
a737bd4d 6562
c19d1205
ZW
6563static void
6564do_rm_rd_rn (void)
6565{
6566 inst.instruction |= inst.operands[0].reg;
6567 inst.instruction |= inst.operands[1].reg << 12;
6568 inst.instruction |= inst.operands[2].reg << 16;
6569}
09d92015 6570
c19d1205
ZW
6571static void
6572do_imm0 (void)
6573{
6574 inst.instruction |= inst.operands[0].imm;
6575}
09d92015 6576
c19d1205
ZW
6577static void
6578do_rd_cpaddr (void)
6579{
6580 inst.instruction |= inst.operands[0].reg << 12;
6581 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6582}
a737bd4d 6583
c19d1205
ZW
6584/* ARM instructions, in alphabetical order by function name (except
6585 that wrapper functions appear immediately after the function they
6586 wrap). */
09d92015 6587
c19d1205
ZW
6588/* This is a pseudo-op of the form "adr rd, label" to be converted
6589 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6590
6591static void
c19d1205 6592do_adr (void)
09d92015 6593{
c19d1205 6594 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6595
c19d1205
ZW
6596 /* Frag hacking will turn this into a sub instruction if the offset turns
6597 out to be negative. */
6598 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6599 inst.reloc.pc_rel = 1;
2fc8bdac 6600 inst.reloc.exp.X_add_number -= 8;
c19d1205 6601}
b99bd4ef 6602
c19d1205
ZW
6603/* This is a pseudo-op of the form "adrl rd, label" to be converted
6604 into a relative address of the form:
6605 add rd, pc, #low(label-.-8)"
6606 add rd, rd, #high(label-.-8)" */
b99bd4ef 6607
c19d1205
ZW
6608static void
6609do_adrl (void)
6610{
6611 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6612
c19d1205
ZW
6613 /* Frag hacking will turn this into a sub instruction if the offset turns
6614 out to be negative. */
6615 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6616 inst.reloc.pc_rel = 1;
6617 inst.size = INSN_SIZE * 2;
2fc8bdac 6618 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6619}
6620
b99bd4ef 6621static void
c19d1205 6622do_arit (void)
b99bd4ef 6623{
c19d1205
ZW
6624 if (!inst.operands[1].present)
6625 inst.operands[1].reg = inst.operands[0].reg;
6626 inst.instruction |= inst.operands[0].reg << 12;
6627 inst.instruction |= inst.operands[1].reg << 16;
6628 encode_arm_shifter_operand (2);
6629}
b99bd4ef 6630
62b3e311
PB
6631static void
6632do_barrier (void)
6633{
6634 if (inst.operands[0].present)
6635 {
6636 constraint ((inst.instruction & 0xf0) != 0x40
6637 && inst.operands[0].imm != 0xf,
bd3ba5d1 6638 _("bad barrier type"));
62b3e311
PB
6639 inst.instruction |= inst.operands[0].imm;
6640 }
6641 else
6642 inst.instruction |= 0xf;
6643}
6644
c19d1205
ZW
6645static void
6646do_bfc (void)
6647{
6648 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6649 constraint (msb > 32, _("bit-field extends past end of register"));
6650 /* The instruction encoding stores the LSB and MSB,
6651 not the LSB and width. */
6652 inst.instruction |= inst.operands[0].reg << 12;
6653 inst.instruction |= inst.operands[1].imm << 7;
6654 inst.instruction |= (msb - 1) << 16;
6655}
b99bd4ef 6656
c19d1205
ZW
6657static void
6658do_bfi (void)
6659{
6660 unsigned int msb;
b99bd4ef 6661
c19d1205
ZW
6662 /* #0 in second position is alternative syntax for bfc, which is
6663 the same instruction but with REG_PC in the Rm field. */
6664 if (!inst.operands[1].isreg)
6665 inst.operands[1].reg = REG_PC;
b99bd4ef 6666
c19d1205
ZW
6667 msb = inst.operands[2].imm + inst.operands[3].imm;
6668 constraint (msb > 32, _("bit-field extends past end of register"));
6669 /* The instruction encoding stores the LSB and MSB,
6670 not the LSB and width. */
6671 inst.instruction |= inst.operands[0].reg << 12;
6672 inst.instruction |= inst.operands[1].reg;
6673 inst.instruction |= inst.operands[2].imm << 7;
6674 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6675}
6676
b99bd4ef 6677static void
c19d1205 6678do_bfx (void)
b99bd4ef 6679{
c19d1205
ZW
6680 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6681 _("bit-field extends past end of register"));
6682 inst.instruction |= inst.operands[0].reg << 12;
6683 inst.instruction |= inst.operands[1].reg;
6684 inst.instruction |= inst.operands[2].imm << 7;
6685 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6686}
09d92015 6687
c19d1205
ZW
6688/* ARM V5 breakpoint instruction (argument parse)
6689 BKPT <16 bit unsigned immediate>
6690 Instruction is not conditional.
6691 The bit pattern given in insns[] has the COND_ALWAYS condition,
6692 and it is an error if the caller tried to override that. */
b99bd4ef 6693
c19d1205
ZW
6694static void
6695do_bkpt (void)
6696{
6697 /* Top 12 of 16 bits to bits 19:8. */
6698 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6699
c19d1205
ZW
6700 /* Bottom 4 of 16 bits to bits 3:0. */
6701 inst.instruction |= inst.operands[0].imm & 0xf;
6702}
09d92015 6703
c19d1205
ZW
6704static void
6705encode_branch (int default_reloc)
6706{
6707 if (inst.operands[0].hasreloc)
6708 {
6709 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6710 _("the only suffix valid here is '(plt)'"));
6711 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6712 }
b99bd4ef 6713 else
c19d1205
ZW
6714 {
6715 inst.reloc.type = default_reloc;
c19d1205 6716 }
2fc8bdac 6717 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6718}
6719
b99bd4ef 6720static void
c19d1205 6721do_branch (void)
b99bd4ef 6722{
39b41c9c
PB
6723#ifdef OBJ_ELF
6724 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6725 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6726 else
6727#endif
6728 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6729}
6730
6731static void
6732do_bl (void)
6733{
6734#ifdef OBJ_ELF
6735 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6736 {
6737 if (inst.cond == COND_ALWAYS)
6738 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6739 else
6740 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6741 }
6742 else
6743#endif
6744 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6745}
b99bd4ef 6746
c19d1205
ZW
6747/* ARM V5 branch-link-exchange instruction (argument parse)
6748 BLX <target_addr> ie BLX(1)
6749 BLX{<condition>} <Rm> ie BLX(2)
6750 Unfortunately, there are two different opcodes for this mnemonic.
6751 So, the insns[].value is not used, and the code here zaps values
6752 into inst.instruction.
6753 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6754
c19d1205
ZW
6755static void
6756do_blx (void)
6757{
6758 if (inst.operands[0].isreg)
b99bd4ef 6759 {
c19d1205
ZW
6760 /* Arg is a register; the opcode provided by insns[] is correct.
6761 It is not illegal to do "blx pc", just useless. */
6762 if (inst.operands[0].reg == REG_PC)
6763 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6764
c19d1205
ZW
6765 inst.instruction |= inst.operands[0].reg;
6766 }
6767 else
b99bd4ef 6768 {
c19d1205
ZW
6769 /* Arg is an address; this instruction cannot be executed
6770 conditionally, and the opcode must be adjusted. */
6771 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6772 inst.instruction = 0xfa000000;
39b41c9c
PB
6773#ifdef OBJ_ELF
6774 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6775 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6776 else
6777#endif
6778 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6779 }
c19d1205
ZW
6780}
6781
6782static void
6783do_bx (void)
6784{
845b51d6
PB
6785 bfd_boolean want_reloc;
6786
c19d1205
ZW
6787 if (inst.operands[0].reg == REG_PC)
6788 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6789
c19d1205 6790 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6791 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6792 it is for ARMv4t or earlier. */
6793 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6794 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6795 want_reloc = TRUE;
6796
5ad34203 6797#ifdef OBJ_ELF
845b51d6 6798 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6799#endif
584206db 6800 want_reloc = FALSE;
845b51d6
PB
6801
6802 if (want_reloc)
6803 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6804}
6805
c19d1205
ZW
6806
6807/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6808
6809static void
c19d1205 6810do_bxj (void)
a737bd4d 6811{
c19d1205
ZW
6812 if (inst.operands[0].reg == REG_PC)
6813 as_tsktsk (_("use of r15 in bxj is not really useful"));
6814
6815 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6816}
6817
c19d1205
ZW
6818/* Co-processor data operation:
6819 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6820 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6821static void
6822do_cdp (void)
6823{
6824 inst.instruction |= inst.operands[0].reg << 8;
6825 inst.instruction |= inst.operands[1].imm << 20;
6826 inst.instruction |= inst.operands[2].reg << 12;
6827 inst.instruction |= inst.operands[3].reg << 16;
6828 inst.instruction |= inst.operands[4].reg;
6829 inst.instruction |= inst.operands[5].imm << 5;
6830}
a737bd4d
NC
6831
6832static void
c19d1205 6833do_cmp (void)
a737bd4d 6834{
c19d1205
ZW
6835 inst.instruction |= inst.operands[0].reg << 16;
6836 encode_arm_shifter_operand (1);
a737bd4d
NC
6837}
6838
c19d1205
ZW
6839/* Transfer between coprocessor and ARM registers.
6840 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6841 MRC2
6842 MCR{cond}
6843 MCR2
6844
6845 No special properties. */
09d92015
MM
6846
6847static void
c19d1205 6848do_co_reg (void)
09d92015 6849{
c19d1205
ZW
6850 inst.instruction |= inst.operands[0].reg << 8;
6851 inst.instruction |= inst.operands[1].imm << 21;
6852 inst.instruction |= inst.operands[2].reg << 12;
6853 inst.instruction |= inst.operands[3].reg << 16;
6854 inst.instruction |= inst.operands[4].reg;
6855 inst.instruction |= inst.operands[5].imm << 5;
6856}
09d92015 6857
c19d1205
ZW
6858/* Transfer between coprocessor register and pair of ARM registers.
6859 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6860 MCRR2
6861 MRRC{cond}
6862 MRRC2
b99bd4ef 6863
c19d1205 6864 Two XScale instructions are special cases of these:
09d92015 6865
c19d1205
ZW
6866 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6867 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6868
5f4273c7 6869 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6870
c19d1205
ZW
6871static void
6872do_co_reg2c (void)
6873{
6874 inst.instruction |= inst.operands[0].reg << 8;
6875 inst.instruction |= inst.operands[1].imm << 4;
6876 inst.instruction |= inst.operands[2].reg << 12;
6877 inst.instruction |= inst.operands[3].reg << 16;
6878 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6879}
6880
c19d1205
ZW
6881static void
6882do_cpsi (void)
6883{
6884 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6885 if (inst.operands[1].present)
6886 {
6887 inst.instruction |= CPSI_MMOD;
6888 inst.instruction |= inst.operands[1].imm;
6889 }
c19d1205 6890}
b99bd4ef 6891
62b3e311
PB
6892static void
6893do_dbg (void)
6894{
6895 inst.instruction |= inst.operands[0].imm;
6896}
6897
b99bd4ef 6898static void
c19d1205 6899do_it (void)
b99bd4ef 6900{
c19d1205
ZW
6901 /* There is no IT instruction in ARM mode. We
6902 process it but do not generate code for it. */
6903 inst.size = 0;
09d92015 6904}
b99bd4ef 6905
09d92015 6906static void
c19d1205 6907do_ldmstm (void)
ea6ef066 6908{
c19d1205
ZW
6909 int base_reg = inst.operands[0].reg;
6910 int range = inst.operands[1].imm;
ea6ef066 6911
c19d1205
ZW
6912 inst.instruction |= base_reg << 16;
6913 inst.instruction |= range;
ea6ef066 6914
c19d1205
ZW
6915 if (inst.operands[1].writeback)
6916 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6917
c19d1205 6918 if (inst.operands[0].writeback)
ea6ef066 6919 {
c19d1205
ZW
6920 inst.instruction |= WRITE_BACK;
6921 /* Check for unpredictable uses of writeback. */
6922 if (inst.instruction & LOAD_BIT)
09d92015 6923 {
c19d1205
ZW
6924 /* Not allowed in LDM type 2. */
6925 if ((inst.instruction & LDM_TYPE_2_OR_3)
6926 && ((range & (1 << REG_PC)) == 0))
6927 as_warn (_("writeback of base register is UNPREDICTABLE"));
6928 /* Only allowed if base reg not in list for other types. */
6929 else if (range & (1 << base_reg))
6930 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6931 }
6932 else /* STM. */
6933 {
6934 /* Not allowed for type 2. */
6935 if (inst.instruction & LDM_TYPE_2_OR_3)
6936 as_warn (_("writeback of base register is UNPREDICTABLE"));
6937 /* Only allowed if base reg not in list, or first in list. */
6938 else if ((range & (1 << base_reg))
6939 && (range & ((1 << base_reg) - 1)))
6940 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6941 }
ea6ef066 6942 }
a737bd4d
NC
6943}
6944
c19d1205
ZW
6945/* ARMv5TE load-consecutive (argument parse)
6946 Mode is like LDRH.
6947
6948 LDRccD R, mode
6949 STRccD R, mode. */
6950
a737bd4d 6951static void
c19d1205 6952do_ldrd (void)
a737bd4d 6953{
c19d1205
ZW
6954 constraint (inst.operands[0].reg % 2 != 0,
6955 _("first destination register must be even"));
6956 constraint (inst.operands[1].present
6957 && inst.operands[1].reg != inst.operands[0].reg + 1,
6958 _("can only load two consecutive registers"));
6959 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6960 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6961
c19d1205
ZW
6962 if (!inst.operands[1].present)
6963 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 6964
c19d1205 6965 if (inst.instruction & LOAD_BIT)
a737bd4d 6966 {
c19d1205
ZW
6967 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6968 register and the first register written; we have to diagnose
6969 overlap between the base and the second register written here. */
ea6ef066 6970
c19d1205
ZW
6971 if (inst.operands[2].reg == inst.operands[1].reg
6972 && (inst.operands[2].writeback || inst.operands[2].postind))
6973 as_warn (_("base register written back, and overlaps "
6974 "second destination register"));
b05fe5cf 6975
c19d1205
ZW
6976 /* For an index-register load, the index register must not overlap the
6977 destination (even if not write-back). */
6978 else if (inst.operands[2].immisreg
ca3f61f7
NC
6979 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6980 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6981 as_warn (_("index register overlaps destination register"));
b05fe5cf 6982 }
c19d1205
ZW
6983
6984 inst.instruction |= inst.operands[0].reg << 12;
6985 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6986}
6987
6988static void
c19d1205 6989do_ldrex (void)
b05fe5cf 6990{
c19d1205
ZW
6991 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6992 || inst.operands[1].postind || inst.operands[1].writeback
6993 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6994 || inst.operands[1].negative
6995 /* This can arise if the programmer has written
6996 strex rN, rM, foo
6997 or if they have mistakenly used a register name as the last
6998 operand, eg:
6999 strex rN, rM, rX
7000 It is very difficult to distinguish between these two cases
7001 because "rX" might actually be a label. ie the register
7002 name has been occluded by a symbol of the same name. So we
7003 just generate a general 'bad addressing mode' type error
7004 message and leave it up to the programmer to discover the
7005 true cause and fix their mistake. */
7006 || (inst.operands[1].reg == REG_PC),
7007 BAD_ADDR_MODE);
b05fe5cf 7008
c19d1205
ZW
7009 constraint (inst.reloc.exp.X_op != O_constant
7010 || inst.reloc.exp.X_add_number != 0,
7011 _("offset must be zero in ARM encoding"));
b05fe5cf 7012
c19d1205
ZW
7013 inst.instruction |= inst.operands[0].reg << 12;
7014 inst.instruction |= inst.operands[1].reg << 16;
7015 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7016}
7017
7018static void
c19d1205 7019do_ldrexd (void)
b05fe5cf 7020{
c19d1205
ZW
7021 constraint (inst.operands[0].reg % 2 != 0,
7022 _("even register required"));
7023 constraint (inst.operands[1].present
7024 && inst.operands[1].reg != inst.operands[0].reg + 1,
7025 _("can only load two consecutive registers"));
7026 /* If op 1 were present and equal to PC, this function wouldn't
7027 have been called in the first place. */
7028 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7029
c19d1205
ZW
7030 inst.instruction |= inst.operands[0].reg << 12;
7031 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7032}
7033
7034static void
c19d1205 7035do_ldst (void)
b05fe5cf 7036{
c19d1205
ZW
7037 inst.instruction |= inst.operands[0].reg << 12;
7038 if (!inst.operands[1].isreg)
7039 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7040 return;
c19d1205 7041 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7042}
7043
7044static void
c19d1205 7045do_ldstt (void)
b05fe5cf 7046{
c19d1205
ZW
7047 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7048 reject [Rn,...]. */
7049 if (inst.operands[1].preind)
b05fe5cf 7050 {
bd3ba5d1
NC
7051 constraint (inst.reloc.exp.X_op != O_constant
7052 || inst.reloc.exp.X_add_number != 0,
c19d1205 7053 _("this instruction requires a post-indexed address"));
b05fe5cf 7054
c19d1205
ZW
7055 inst.operands[1].preind = 0;
7056 inst.operands[1].postind = 1;
7057 inst.operands[1].writeback = 1;
b05fe5cf 7058 }
c19d1205
ZW
7059 inst.instruction |= inst.operands[0].reg << 12;
7060 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7061}
b05fe5cf 7062
c19d1205 7063/* Halfword and signed-byte load/store operations. */
b05fe5cf 7064
c19d1205
ZW
7065static void
7066do_ldstv4 (void)
7067{
7068 inst.instruction |= inst.operands[0].reg << 12;
7069 if (!inst.operands[1].isreg)
7070 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7071 return;
c19d1205 7072 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7073}
7074
7075static void
c19d1205 7076do_ldsttv4 (void)
b05fe5cf 7077{
c19d1205
ZW
7078 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7079 reject [Rn,...]. */
7080 if (inst.operands[1].preind)
b05fe5cf 7081 {
bd3ba5d1
NC
7082 constraint (inst.reloc.exp.X_op != O_constant
7083 || inst.reloc.exp.X_add_number != 0,
c19d1205 7084 _("this instruction requires a post-indexed address"));
b05fe5cf 7085
c19d1205
ZW
7086 inst.operands[1].preind = 0;
7087 inst.operands[1].postind = 1;
7088 inst.operands[1].writeback = 1;
b05fe5cf 7089 }
c19d1205
ZW
7090 inst.instruction |= inst.operands[0].reg << 12;
7091 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7092}
b05fe5cf 7093
c19d1205
ZW
7094/* Co-processor register load/store.
7095 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7096static void
7097do_lstc (void)
7098{
7099 inst.instruction |= inst.operands[0].reg << 8;
7100 inst.instruction |= inst.operands[1].reg << 12;
7101 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7102}
7103
b05fe5cf 7104static void
c19d1205 7105do_mlas (void)
b05fe5cf 7106{
8fb9d7b9 7107 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7108 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7109 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7110 && !(inst.instruction & 0x00400000))
8fb9d7b9 7111 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7112
c19d1205
ZW
7113 inst.instruction |= inst.operands[0].reg << 16;
7114 inst.instruction |= inst.operands[1].reg;
7115 inst.instruction |= inst.operands[2].reg << 8;
7116 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7117}
b05fe5cf 7118
c19d1205
ZW
7119static void
7120do_mov (void)
7121{
7122 inst.instruction |= inst.operands[0].reg << 12;
7123 encode_arm_shifter_operand (1);
7124}
b05fe5cf 7125
c19d1205
ZW
7126/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7127static void
7128do_mov16 (void)
7129{
b6895b4f
PB
7130 bfd_vma imm;
7131 bfd_boolean top;
7132
7133 top = (inst.instruction & 0x00400000) != 0;
7134 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7135 _(":lower16: not allowed this instruction"));
7136 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7137 _(":upper16: not allowed instruction"));
c19d1205 7138 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7139 if (inst.reloc.type == BFD_RELOC_UNUSED)
7140 {
7141 imm = inst.reloc.exp.X_add_number;
7142 /* The value is in two pieces: 0:11, 16:19. */
7143 inst.instruction |= (imm & 0x00000fff);
7144 inst.instruction |= (imm & 0x0000f000) << 4;
7145 }
b05fe5cf 7146}
b99bd4ef 7147
037e8744
JB
7148static void do_vfp_nsyn_opcode (const char *);
7149
7150static int
7151do_vfp_nsyn_mrs (void)
7152{
7153 if (inst.operands[0].isvec)
7154 {
7155 if (inst.operands[1].reg != 1)
7156 first_error (_("operand 1 must be FPSCR"));
7157 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7158 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7159 do_vfp_nsyn_opcode ("fmstat");
7160 }
7161 else if (inst.operands[1].isvec)
7162 do_vfp_nsyn_opcode ("fmrx");
7163 else
7164 return FAIL;
5f4273c7 7165
037e8744
JB
7166 return SUCCESS;
7167}
7168
7169static int
7170do_vfp_nsyn_msr (void)
7171{
7172 if (inst.operands[0].isvec)
7173 do_vfp_nsyn_opcode ("fmxr");
7174 else
7175 return FAIL;
7176
7177 return SUCCESS;
7178}
7179
b99bd4ef 7180static void
c19d1205 7181do_mrs (void)
b99bd4ef 7182{
037e8744
JB
7183 if (do_vfp_nsyn_mrs () == SUCCESS)
7184 return;
7185
c19d1205
ZW
7186 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7187 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7188 != (PSR_c|PSR_f),
7189 _("'CPSR' or 'SPSR' expected"));
7190 inst.instruction |= inst.operands[0].reg << 12;
7191 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7192}
b99bd4ef 7193
c19d1205
ZW
7194/* Two possible forms:
7195 "{C|S}PSR_<field>, Rm",
7196 "{C|S}PSR_f, #expression". */
b99bd4ef 7197
c19d1205
ZW
7198static void
7199do_msr (void)
7200{
037e8744
JB
7201 if (do_vfp_nsyn_msr () == SUCCESS)
7202 return;
7203
c19d1205
ZW
7204 inst.instruction |= inst.operands[0].imm;
7205 if (inst.operands[1].isreg)
7206 inst.instruction |= inst.operands[1].reg;
7207 else
b99bd4ef 7208 {
c19d1205
ZW
7209 inst.instruction |= INST_IMMEDIATE;
7210 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7211 inst.reloc.pc_rel = 0;
b99bd4ef 7212 }
b99bd4ef
NC
7213}
7214
c19d1205
ZW
7215static void
7216do_mul (void)
a737bd4d 7217{
c19d1205
ZW
7218 if (!inst.operands[2].present)
7219 inst.operands[2].reg = inst.operands[0].reg;
7220 inst.instruction |= inst.operands[0].reg << 16;
7221 inst.instruction |= inst.operands[1].reg;
7222 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7223
8fb9d7b9
MS
7224 if (inst.operands[0].reg == inst.operands[1].reg
7225 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7226 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7227}
7228
c19d1205
ZW
7229/* Long Multiply Parser
7230 UMULL RdLo, RdHi, Rm, Rs
7231 SMULL RdLo, RdHi, Rm, Rs
7232 UMLAL RdLo, RdHi, Rm, Rs
7233 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7234
7235static void
c19d1205 7236do_mull (void)
b99bd4ef 7237{
c19d1205
ZW
7238 inst.instruction |= inst.operands[0].reg << 12;
7239 inst.instruction |= inst.operands[1].reg << 16;
7240 inst.instruction |= inst.operands[2].reg;
7241 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7242
682b27ad
PB
7243 /* rdhi and rdlo must be different. */
7244 if (inst.operands[0].reg == inst.operands[1].reg)
7245 as_tsktsk (_("rdhi and rdlo must be different"));
7246
7247 /* rdhi, rdlo and rm must all be different before armv6. */
7248 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7249 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7250 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7251 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7252}
b99bd4ef 7253
c19d1205
ZW
7254static void
7255do_nop (void)
7256{
7257 if (inst.operands[0].present)
7258 {
7259 /* Architectural NOP hints are CPSR sets with no bits selected. */
7260 inst.instruction &= 0xf0000000;
7261 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7262 }
b99bd4ef
NC
7263}
7264
c19d1205
ZW
7265/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7266 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7267 Condition defaults to COND_ALWAYS.
7268 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7269
7270static void
c19d1205 7271do_pkhbt (void)
b99bd4ef 7272{
c19d1205
ZW
7273 inst.instruction |= inst.operands[0].reg << 12;
7274 inst.instruction |= inst.operands[1].reg << 16;
7275 inst.instruction |= inst.operands[2].reg;
7276 if (inst.operands[3].present)
7277 encode_arm_shift (3);
7278}
b99bd4ef 7279
c19d1205 7280/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7281
c19d1205
ZW
7282static void
7283do_pkhtb (void)
7284{
7285 if (!inst.operands[3].present)
b99bd4ef 7286 {
c19d1205
ZW
7287 /* If the shift specifier is omitted, turn the instruction
7288 into pkhbt rd, rm, rn. */
7289 inst.instruction &= 0xfff00010;
7290 inst.instruction |= inst.operands[0].reg << 12;
7291 inst.instruction |= inst.operands[1].reg;
7292 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7293 }
7294 else
7295 {
c19d1205
ZW
7296 inst.instruction |= inst.operands[0].reg << 12;
7297 inst.instruction |= inst.operands[1].reg << 16;
7298 inst.instruction |= inst.operands[2].reg;
7299 encode_arm_shift (3);
b99bd4ef
NC
7300 }
7301}
7302
c19d1205
ZW
7303/* ARMv5TE: Preload-Cache
7304
7305 PLD <addr_mode>
7306
7307 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7308
7309static void
c19d1205 7310do_pld (void)
b99bd4ef 7311{
c19d1205
ZW
7312 constraint (!inst.operands[0].isreg,
7313 _("'[' expected after PLD mnemonic"));
7314 constraint (inst.operands[0].postind,
7315 _("post-indexed expression used in preload instruction"));
7316 constraint (inst.operands[0].writeback,
7317 _("writeback used in preload instruction"));
7318 constraint (!inst.operands[0].preind,
7319 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7320 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7321}
b99bd4ef 7322
62b3e311
PB
7323/* ARMv7: PLI <addr_mode> */
7324static void
7325do_pli (void)
7326{
7327 constraint (!inst.operands[0].isreg,
7328 _("'[' expected after PLI mnemonic"));
7329 constraint (inst.operands[0].postind,
7330 _("post-indexed expression used in preload instruction"));
7331 constraint (inst.operands[0].writeback,
7332 _("writeback used in preload instruction"));
7333 constraint (!inst.operands[0].preind,
7334 _("unindexed addressing used in preload instruction"));
7335 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7336 inst.instruction &= ~PRE_INDEX;
7337}
7338
c19d1205
ZW
7339static void
7340do_push_pop (void)
7341{
7342 inst.operands[1] = inst.operands[0];
7343 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7344 inst.operands[0].isreg = 1;
7345 inst.operands[0].writeback = 1;
7346 inst.operands[0].reg = REG_SP;
7347 do_ldmstm ();
7348}
b99bd4ef 7349
c19d1205
ZW
7350/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7351 word at the specified address and the following word
7352 respectively.
7353 Unconditionally executed.
7354 Error if Rn is R15. */
b99bd4ef 7355
c19d1205
ZW
7356static void
7357do_rfe (void)
7358{
7359 inst.instruction |= inst.operands[0].reg << 16;
7360 if (inst.operands[0].writeback)
7361 inst.instruction |= WRITE_BACK;
7362}
b99bd4ef 7363
c19d1205 7364/* ARM V6 ssat (argument parse). */
b99bd4ef 7365
c19d1205
ZW
7366static void
7367do_ssat (void)
7368{
7369 inst.instruction |= inst.operands[0].reg << 12;
7370 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7371 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7372
c19d1205
ZW
7373 if (inst.operands[3].present)
7374 encode_arm_shift (3);
b99bd4ef
NC
7375}
7376
c19d1205 7377/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7378
7379static void
c19d1205 7380do_usat (void)
b99bd4ef 7381{
c19d1205
ZW
7382 inst.instruction |= inst.operands[0].reg << 12;
7383 inst.instruction |= inst.operands[1].imm << 16;
7384 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7385
c19d1205
ZW
7386 if (inst.operands[3].present)
7387 encode_arm_shift (3);
b99bd4ef
NC
7388}
7389
c19d1205 7390/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7391
7392static void
c19d1205 7393do_ssat16 (void)
09d92015 7394{
c19d1205
ZW
7395 inst.instruction |= inst.operands[0].reg << 12;
7396 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7397 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7398}
7399
c19d1205
ZW
7400static void
7401do_usat16 (void)
a737bd4d 7402{
c19d1205
ZW
7403 inst.instruction |= inst.operands[0].reg << 12;
7404 inst.instruction |= inst.operands[1].imm << 16;
7405 inst.instruction |= inst.operands[2].reg;
7406}
a737bd4d 7407
c19d1205
ZW
7408/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7409 preserving the other bits.
a737bd4d 7410
c19d1205
ZW
7411 setend <endian_specifier>, where <endian_specifier> is either
7412 BE or LE. */
a737bd4d 7413
c19d1205
ZW
7414static void
7415do_setend (void)
7416{
7417 if (inst.operands[0].imm)
7418 inst.instruction |= 0x200;
a737bd4d
NC
7419}
7420
7421static void
c19d1205 7422do_shift (void)
a737bd4d 7423{
c19d1205
ZW
7424 unsigned int Rm = (inst.operands[1].present
7425 ? inst.operands[1].reg
7426 : inst.operands[0].reg);
a737bd4d 7427
c19d1205
ZW
7428 inst.instruction |= inst.operands[0].reg << 12;
7429 inst.instruction |= Rm;
7430 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7431 {
c19d1205
ZW
7432 inst.instruction |= inst.operands[2].reg << 8;
7433 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7434 }
7435 else
c19d1205 7436 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7437}
7438
09d92015 7439static void
3eb17e6b 7440do_smc (void)
09d92015 7441{
3eb17e6b 7442 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7443 inst.reloc.pc_rel = 0;
09d92015
MM
7444}
7445
09d92015 7446static void
c19d1205 7447do_swi (void)
09d92015 7448{
c19d1205
ZW
7449 inst.reloc.type = BFD_RELOC_ARM_SWI;
7450 inst.reloc.pc_rel = 0;
09d92015
MM
7451}
7452
c19d1205
ZW
7453/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7454 SMLAxy{cond} Rd,Rm,Rs,Rn
7455 SMLAWy{cond} Rd,Rm,Rs,Rn
7456 Error if any register is R15. */
e16bb312 7457
c19d1205
ZW
7458static void
7459do_smla (void)
e16bb312 7460{
c19d1205
ZW
7461 inst.instruction |= inst.operands[0].reg << 16;
7462 inst.instruction |= inst.operands[1].reg;
7463 inst.instruction |= inst.operands[2].reg << 8;
7464 inst.instruction |= inst.operands[3].reg << 12;
7465}
a737bd4d 7466
c19d1205
ZW
7467/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7468 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7469 Error if any register is R15.
7470 Warning if Rdlo == Rdhi. */
a737bd4d 7471
c19d1205
ZW
7472static void
7473do_smlal (void)
7474{
7475 inst.instruction |= inst.operands[0].reg << 12;
7476 inst.instruction |= inst.operands[1].reg << 16;
7477 inst.instruction |= inst.operands[2].reg;
7478 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7479
c19d1205
ZW
7480 if (inst.operands[0].reg == inst.operands[1].reg)
7481 as_tsktsk (_("rdhi and rdlo must be different"));
7482}
a737bd4d 7483
c19d1205
ZW
7484/* ARM V5E (El Segundo) signed-multiply (argument parse)
7485 SMULxy{cond} Rd,Rm,Rs
7486 Error if any register is R15. */
a737bd4d 7487
c19d1205
ZW
7488static void
7489do_smul (void)
7490{
7491 inst.instruction |= inst.operands[0].reg << 16;
7492 inst.instruction |= inst.operands[1].reg;
7493 inst.instruction |= inst.operands[2].reg << 8;
7494}
a737bd4d 7495
b6702015
PB
7496/* ARM V6 srs (argument parse). The variable fields in the encoding are
7497 the same for both ARM and Thumb-2. */
a737bd4d 7498
c19d1205
ZW
7499static void
7500do_srs (void)
7501{
b6702015
PB
7502 int reg;
7503
7504 if (inst.operands[0].present)
7505 {
7506 reg = inst.operands[0].reg;
7507 constraint (reg != 13, _("SRS base register must be r13"));
7508 }
7509 else
7510 reg = 13;
7511
7512 inst.instruction |= reg << 16;
7513 inst.instruction |= inst.operands[1].imm;
7514 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7515 inst.instruction |= WRITE_BACK;
7516}
a737bd4d 7517
c19d1205 7518/* ARM V6 strex (argument parse). */
a737bd4d 7519
c19d1205
ZW
7520static void
7521do_strex (void)
7522{
7523 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7524 || inst.operands[2].postind || inst.operands[2].writeback
7525 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7526 || inst.operands[2].negative
7527 /* See comment in do_ldrex(). */
7528 || (inst.operands[2].reg == REG_PC),
7529 BAD_ADDR_MODE);
a737bd4d 7530
c19d1205
ZW
7531 constraint (inst.operands[0].reg == inst.operands[1].reg
7532 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7533
c19d1205
ZW
7534 constraint (inst.reloc.exp.X_op != O_constant
7535 || inst.reloc.exp.X_add_number != 0,
7536 _("offset must be zero in ARM encoding"));
a737bd4d 7537
c19d1205
ZW
7538 inst.instruction |= inst.operands[0].reg << 12;
7539 inst.instruction |= inst.operands[1].reg;
7540 inst.instruction |= inst.operands[2].reg << 16;
7541 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7542}
7543
7544static void
c19d1205 7545do_strexd (void)
e16bb312 7546{
c19d1205
ZW
7547 constraint (inst.operands[1].reg % 2 != 0,
7548 _("even register required"));
7549 constraint (inst.operands[2].present
7550 && inst.operands[2].reg != inst.operands[1].reg + 1,
7551 _("can only store two consecutive registers"));
7552 /* If op 2 were present and equal to PC, this function wouldn't
7553 have been called in the first place. */
7554 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7555
c19d1205
ZW
7556 constraint (inst.operands[0].reg == inst.operands[1].reg
7557 || inst.operands[0].reg == inst.operands[1].reg + 1
7558 || inst.operands[0].reg == inst.operands[3].reg,
7559 BAD_OVERLAP);
e16bb312 7560
c19d1205
ZW
7561 inst.instruction |= inst.operands[0].reg << 12;
7562 inst.instruction |= inst.operands[1].reg;
7563 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7564}
7565
c19d1205
ZW
7566/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7567 extends it to 32-bits, and adds the result to a value in another
7568 register. You can specify a rotation by 0, 8, 16, or 24 bits
7569 before extracting the 16-bit value.
7570 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7571 Condition defaults to COND_ALWAYS.
7572 Error if any register uses R15. */
7573
e16bb312 7574static void
c19d1205 7575do_sxtah (void)
e16bb312 7576{
c19d1205
ZW
7577 inst.instruction |= inst.operands[0].reg << 12;
7578 inst.instruction |= inst.operands[1].reg << 16;
7579 inst.instruction |= inst.operands[2].reg;
7580 inst.instruction |= inst.operands[3].imm << 10;
7581}
e16bb312 7582
c19d1205 7583/* ARM V6 SXTH.
e16bb312 7584
c19d1205
ZW
7585 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7586 Condition defaults to COND_ALWAYS.
7587 Error if any register uses R15. */
e16bb312
NC
7588
7589static void
c19d1205 7590do_sxth (void)
e16bb312 7591{
c19d1205
ZW
7592 inst.instruction |= inst.operands[0].reg << 12;
7593 inst.instruction |= inst.operands[1].reg;
7594 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7595}
c19d1205
ZW
7596\f
7597/* VFP instructions. In a logical order: SP variant first, monad
7598 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7599
7600static void
c19d1205 7601do_vfp_sp_monadic (void)
e16bb312 7602{
5287ad62
JB
7603 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7604 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7605}
7606
7607static void
c19d1205 7608do_vfp_sp_dyadic (void)
e16bb312 7609{
5287ad62
JB
7610 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7611 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7612 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7613}
7614
7615static void
c19d1205 7616do_vfp_sp_compare_z (void)
e16bb312 7617{
5287ad62 7618 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7619}
7620
7621static void
c19d1205 7622do_vfp_dp_sp_cvt (void)
e16bb312 7623{
5287ad62
JB
7624 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7625 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7626}
7627
7628static void
c19d1205 7629do_vfp_sp_dp_cvt (void)
e16bb312 7630{
5287ad62
JB
7631 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7632 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7633}
7634
7635static void
c19d1205 7636do_vfp_reg_from_sp (void)
e16bb312 7637{
c19d1205 7638 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7639 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7640}
7641
7642static void
c19d1205 7643do_vfp_reg2_from_sp2 (void)
e16bb312 7644{
c19d1205
ZW
7645 constraint (inst.operands[2].imm != 2,
7646 _("only two consecutive VFP SP registers allowed here"));
7647 inst.instruction |= inst.operands[0].reg << 12;
7648 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7649 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7650}
7651
7652static void
c19d1205 7653do_vfp_sp_from_reg (void)
e16bb312 7654{
5287ad62 7655 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7656 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7657}
7658
7659static void
c19d1205 7660do_vfp_sp2_from_reg2 (void)
e16bb312 7661{
c19d1205
ZW
7662 constraint (inst.operands[0].imm != 2,
7663 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7664 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7665 inst.instruction |= inst.operands[1].reg << 12;
7666 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7667}
7668
7669static void
c19d1205 7670do_vfp_sp_ldst (void)
e16bb312 7671{
5287ad62 7672 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7673 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7674}
7675
7676static void
c19d1205 7677do_vfp_dp_ldst (void)
e16bb312 7678{
5287ad62 7679 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7680 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7681}
7682
c19d1205 7683
e16bb312 7684static void
c19d1205 7685vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7686{
c19d1205
ZW
7687 if (inst.operands[0].writeback)
7688 inst.instruction |= WRITE_BACK;
7689 else
7690 constraint (ldstm_type != VFP_LDSTMIA,
7691 _("this addressing mode requires base-register writeback"));
7692 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7693 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7694 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7695}
7696
7697static void
c19d1205 7698vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7699{
c19d1205 7700 int count;
e16bb312 7701
c19d1205
ZW
7702 if (inst.operands[0].writeback)
7703 inst.instruction |= WRITE_BACK;
7704 else
7705 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7706 _("this addressing mode requires base-register writeback"));
e16bb312 7707
c19d1205 7708 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7709 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7710
c19d1205
ZW
7711 count = inst.operands[1].imm << 1;
7712 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7713 count += 1;
e16bb312 7714
c19d1205 7715 inst.instruction |= count;
e16bb312
NC
7716}
7717
7718static void
c19d1205 7719do_vfp_sp_ldstmia (void)
e16bb312 7720{
c19d1205 7721 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7722}
7723
7724static void
c19d1205 7725do_vfp_sp_ldstmdb (void)
e16bb312 7726{
c19d1205 7727 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7728}
7729
7730static void
c19d1205 7731do_vfp_dp_ldstmia (void)
e16bb312 7732{
c19d1205 7733 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7734}
7735
7736static void
c19d1205 7737do_vfp_dp_ldstmdb (void)
e16bb312 7738{
c19d1205 7739 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7740}
7741
7742static void
c19d1205 7743do_vfp_xp_ldstmia (void)
e16bb312 7744{
c19d1205
ZW
7745 vfp_dp_ldstm (VFP_LDSTMIAX);
7746}
e16bb312 7747
c19d1205
ZW
7748static void
7749do_vfp_xp_ldstmdb (void)
7750{
7751 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7752}
5287ad62
JB
7753
7754static void
7755do_vfp_dp_rd_rm (void)
7756{
7757 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7758 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7759}
7760
7761static void
7762do_vfp_dp_rn_rd (void)
7763{
7764 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7765 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7766}
7767
7768static void
7769do_vfp_dp_rd_rn (void)
7770{
7771 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7772 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7773}
7774
7775static void
7776do_vfp_dp_rd_rn_rm (void)
7777{
7778 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7779 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7780 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7781}
7782
7783static void
7784do_vfp_dp_rd (void)
7785{
7786 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7787}
7788
7789static void
7790do_vfp_dp_rm_rd_rn (void)
7791{
7792 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7793 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7794 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7795}
7796
7797/* VFPv3 instructions. */
7798static void
7799do_vfp_sp_const (void)
7800{
7801 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7802 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7803 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7804}
7805
7806static void
7807do_vfp_dp_const (void)
7808{
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7810 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7811 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7812}
7813
7814static void
7815vfp_conv (int srcsize)
7816{
7817 unsigned immbits = srcsize - inst.operands[1].imm;
7818 inst.instruction |= (immbits & 1) << 5;
7819 inst.instruction |= (immbits >> 1);
7820}
7821
7822static void
7823do_vfp_sp_conv_16 (void)
7824{
7825 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7826 vfp_conv (16);
7827}
7828
7829static void
7830do_vfp_dp_conv_16 (void)
7831{
7832 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7833 vfp_conv (16);
7834}
7835
7836static void
7837do_vfp_sp_conv_32 (void)
7838{
7839 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7840 vfp_conv (32);
7841}
7842
7843static void
7844do_vfp_dp_conv_32 (void)
7845{
7846 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7847 vfp_conv (32);
7848}
c19d1205
ZW
7849\f
7850/* FPA instructions. Also in a logical order. */
e16bb312 7851
c19d1205
ZW
7852static void
7853do_fpa_cmp (void)
7854{
7855 inst.instruction |= inst.operands[0].reg << 16;
7856 inst.instruction |= inst.operands[1].reg;
7857}
b99bd4ef
NC
7858
7859static void
c19d1205 7860do_fpa_ldmstm (void)
b99bd4ef 7861{
c19d1205
ZW
7862 inst.instruction |= inst.operands[0].reg << 12;
7863 switch (inst.operands[1].imm)
7864 {
7865 case 1: inst.instruction |= CP_T_X; break;
7866 case 2: inst.instruction |= CP_T_Y; break;
7867 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7868 case 4: break;
7869 default: abort ();
7870 }
b99bd4ef 7871
c19d1205
ZW
7872 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7873 {
7874 /* The instruction specified "ea" or "fd", so we can only accept
7875 [Rn]{!}. The instruction does not really support stacking or
7876 unstacking, so we have to emulate these by setting appropriate
7877 bits and offsets. */
7878 constraint (inst.reloc.exp.X_op != O_constant
7879 || inst.reloc.exp.X_add_number != 0,
7880 _("this instruction does not support indexing"));
b99bd4ef 7881
c19d1205
ZW
7882 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7883 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7884
c19d1205
ZW
7885 if (!(inst.instruction & INDEX_UP))
7886 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7887
c19d1205
ZW
7888 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7889 {
7890 inst.operands[2].preind = 0;
7891 inst.operands[2].postind = 1;
7892 }
7893 }
b99bd4ef 7894
c19d1205 7895 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7896}
c19d1205
ZW
7897\f
7898/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7899
c19d1205
ZW
7900static void
7901do_iwmmxt_tandorc (void)
7902{
7903 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7904}
b99bd4ef 7905
c19d1205
ZW
7906static void
7907do_iwmmxt_textrc (void)
7908{
7909 inst.instruction |= inst.operands[0].reg << 12;
7910 inst.instruction |= inst.operands[1].imm;
7911}
b99bd4ef
NC
7912
7913static void
c19d1205 7914do_iwmmxt_textrm (void)
b99bd4ef 7915{
c19d1205
ZW
7916 inst.instruction |= inst.operands[0].reg << 12;
7917 inst.instruction |= inst.operands[1].reg << 16;
7918 inst.instruction |= inst.operands[2].imm;
7919}
b99bd4ef 7920
c19d1205
ZW
7921static void
7922do_iwmmxt_tinsr (void)
7923{
7924 inst.instruction |= inst.operands[0].reg << 16;
7925 inst.instruction |= inst.operands[1].reg << 12;
7926 inst.instruction |= inst.operands[2].imm;
7927}
b99bd4ef 7928
c19d1205
ZW
7929static void
7930do_iwmmxt_tmia (void)
7931{
7932 inst.instruction |= inst.operands[0].reg << 5;
7933 inst.instruction |= inst.operands[1].reg;
7934 inst.instruction |= inst.operands[2].reg << 12;
7935}
b99bd4ef 7936
c19d1205
ZW
7937static void
7938do_iwmmxt_waligni (void)
7939{
7940 inst.instruction |= inst.operands[0].reg << 12;
7941 inst.instruction |= inst.operands[1].reg << 16;
7942 inst.instruction |= inst.operands[2].reg;
7943 inst.instruction |= inst.operands[3].imm << 20;
7944}
b99bd4ef 7945
2d447fca
JM
7946static void
7947do_iwmmxt_wmerge (void)
7948{
7949 inst.instruction |= inst.operands[0].reg << 12;
7950 inst.instruction |= inst.operands[1].reg << 16;
7951 inst.instruction |= inst.operands[2].reg;
7952 inst.instruction |= inst.operands[3].imm << 21;
7953}
7954
c19d1205
ZW
7955static void
7956do_iwmmxt_wmov (void)
7957{
7958 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7959 inst.instruction |= inst.operands[0].reg << 12;
7960 inst.instruction |= inst.operands[1].reg << 16;
7961 inst.instruction |= inst.operands[1].reg;
7962}
b99bd4ef 7963
c19d1205
ZW
7964static void
7965do_iwmmxt_wldstbh (void)
7966{
8f06b2d8 7967 int reloc;
c19d1205 7968 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7969 if (thumb_mode)
7970 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7971 else
7972 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7973 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7974}
7975
c19d1205
ZW
7976static void
7977do_iwmmxt_wldstw (void)
7978{
7979 /* RIWR_RIWC clears .isreg for a control register. */
7980 if (!inst.operands[0].isreg)
7981 {
7982 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7983 inst.instruction |= 0xf0000000;
7984 }
b99bd4ef 7985
c19d1205
ZW
7986 inst.instruction |= inst.operands[0].reg << 12;
7987 encode_arm_cp_address (1, TRUE, TRUE, 0);
7988}
b99bd4ef
NC
7989
7990static void
c19d1205 7991do_iwmmxt_wldstd (void)
b99bd4ef 7992{
c19d1205 7993 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7994 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7995 && inst.operands[1].immisreg)
7996 {
7997 inst.instruction &= ~0x1a000ff;
7998 inst.instruction |= (0xf << 28);
7999 if (inst.operands[1].preind)
8000 inst.instruction |= PRE_INDEX;
8001 if (!inst.operands[1].negative)
8002 inst.instruction |= INDEX_UP;
8003 if (inst.operands[1].writeback)
8004 inst.instruction |= WRITE_BACK;
8005 inst.instruction |= inst.operands[1].reg << 16;
8006 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8007 inst.instruction |= inst.operands[1].imm;
8008 }
8009 else
8010 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8011}
b99bd4ef 8012
c19d1205
ZW
8013static void
8014do_iwmmxt_wshufh (void)
8015{
8016 inst.instruction |= inst.operands[0].reg << 12;
8017 inst.instruction |= inst.operands[1].reg << 16;
8018 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8019 inst.instruction |= (inst.operands[2].imm & 0x0f);
8020}
b99bd4ef 8021
c19d1205
ZW
8022static void
8023do_iwmmxt_wzero (void)
8024{
8025 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8026 inst.instruction |= inst.operands[0].reg;
8027 inst.instruction |= inst.operands[0].reg << 12;
8028 inst.instruction |= inst.operands[0].reg << 16;
8029}
2d447fca
JM
8030
8031static void
8032do_iwmmxt_wrwrwr_or_imm5 (void)
8033{
8034 if (inst.operands[2].isreg)
8035 do_rd_rn_rm ();
8036 else {
8037 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8038 _("immediate operand requires iWMMXt2"));
8039 do_rd_rn ();
8040 if (inst.operands[2].imm == 0)
8041 {
8042 switch ((inst.instruction >> 20) & 0xf)
8043 {
8044 case 4:
8045 case 5:
8046 case 6:
5f4273c7 8047 case 7:
2d447fca
JM
8048 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8049 inst.operands[2].imm = 16;
8050 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8051 break;
8052 case 8:
8053 case 9:
8054 case 10:
8055 case 11:
8056 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8057 inst.operands[2].imm = 32;
8058 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8059 break;
8060 case 12:
8061 case 13:
8062 case 14:
8063 case 15:
8064 {
8065 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8066 unsigned long wrn;
8067 wrn = (inst.instruction >> 16) & 0xf;
8068 inst.instruction &= 0xff0fff0f;
8069 inst.instruction |= wrn;
8070 /* Bail out here; the instruction is now assembled. */
8071 return;
8072 }
8073 }
8074 }
8075 /* Map 32 -> 0, etc. */
8076 inst.operands[2].imm &= 0x1f;
8077 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8078 }
8079}
c19d1205
ZW
8080\f
8081/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8082 operations first, then control, shift, and load/store. */
b99bd4ef 8083
c19d1205 8084/* Insns like "foo X,Y,Z". */
b99bd4ef 8085
c19d1205
ZW
8086static void
8087do_mav_triple (void)
8088{
8089 inst.instruction |= inst.operands[0].reg << 16;
8090 inst.instruction |= inst.operands[1].reg;
8091 inst.instruction |= inst.operands[2].reg << 12;
8092}
b99bd4ef 8093
c19d1205
ZW
8094/* Insns like "foo W,X,Y,Z".
8095 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8096
c19d1205
ZW
8097static void
8098do_mav_quad (void)
8099{
8100 inst.instruction |= inst.operands[0].reg << 5;
8101 inst.instruction |= inst.operands[1].reg << 12;
8102 inst.instruction |= inst.operands[2].reg << 16;
8103 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8104}
8105
c19d1205
ZW
8106/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8107static void
8108do_mav_dspsc (void)
a737bd4d 8109{
c19d1205
ZW
8110 inst.instruction |= inst.operands[1].reg << 12;
8111}
a737bd4d 8112
c19d1205
ZW
8113/* Maverick shift immediate instructions.
8114 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8115 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8116
c19d1205
ZW
8117static void
8118do_mav_shift (void)
8119{
8120 int imm = inst.operands[2].imm;
a737bd4d 8121
c19d1205
ZW
8122 inst.instruction |= inst.operands[0].reg << 12;
8123 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8124
c19d1205
ZW
8125 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8126 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8127 Bit 4 should be 0. */
8128 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8129
c19d1205
ZW
8130 inst.instruction |= imm;
8131}
8132\f
8133/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8134
c19d1205
ZW
8135/* Xscale multiply-accumulate (argument parse)
8136 MIAcc acc0,Rm,Rs
8137 MIAPHcc acc0,Rm,Rs
8138 MIAxycc acc0,Rm,Rs. */
a737bd4d 8139
c19d1205
ZW
8140static void
8141do_xsc_mia (void)
8142{
8143 inst.instruction |= inst.operands[1].reg;
8144 inst.instruction |= inst.operands[2].reg << 12;
8145}
a737bd4d 8146
c19d1205 8147/* Xscale move-accumulator-register (argument parse)
a737bd4d 8148
c19d1205 8149 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8150
c19d1205
ZW
8151static void
8152do_xsc_mar (void)
8153{
8154 inst.instruction |= inst.operands[1].reg << 12;
8155 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8156}
8157
c19d1205 8158/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8159
c19d1205 8160 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8161
8162static void
c19d1205 8163do_xsc_mra (void)
b99bd4ef 8164{
c19d1205
ZW
8165 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8166 inst.instruction |= inst.operands[0].reg << 12;
8167 inst.instruction |= inst.operands[1].reg << 16;
8168}
8169\f
8170/* Encoding functions relevant only to Thumb. */
b99bd4ef 8171
c19d1205
ZW
8172/* inst.operands[i] is a shifted-register operand; encode
8173 it into inst.instruction in the format used by Thumb32. */
8174
8175static void
8176encode_thumb32_shifted_operand (int i)
8177{
8178 unsigned int value = inst.reloc.exp.X_add_number;
8179 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8180
9c3c69f2
PB
8181 constraint (inst.operands[i].immisreg,
8182 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8183 inst.instruction |= inst.operands[i].reg;
8184 if (shift == SHIFT_RRX)
8185 inst.instruction |= SHIFT_ROR << 4;
8186 else
b99bd4ef 8187 {
c19d1205
ZW
8188 constraint (inst.reloc.exp.X_op != O_constant,
8189 _("expression too complex"));
8190
8191 constraint (value > 32
8192 || (value == 32 && (shift == SHIFT_LSL
8193 || shift == SHIFT_ROR)),
8194 _("shift expression is too large"));
8195
8196 if (value == 0)
8197 shift = SHIFT_LSL;
8198 else if (value == 32)
8199 value = 0;
8200
8201 inst.instruction |= shift << 4;
8202 inst.instruction |= (value & 0x1c) << 10;
8203 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8204 }
c19d1205 8205}
b99bd4ef 8206
b99bd4ef 8207
c19d1205
ZW
8208/* inst.operands[i] was set up by parse_address. Encode it into a
8209 Thumb32 format load or store instruction. Reject forms that cannot
8210 be used with such instructions. If is_t is true, reject forms that
8211 cannot be used with a T instruction; if is_d is true, reject forms
8212 that cannot be used with a D instruction. */
b99bd4ef 8213
c19d1205
ZW
8214static void
8215encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8216{
8217 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8218
8219 constraint (!inst.operands[i].isreg,
53365c0d 8220 _("Instruction does not support =N addresses"));
b99bd4ef 8221
c19d1205
ZW
8222 inst.instruction |= inst.operands[i].reg << 16;
8223 if (inst.operands[i].immisreg)
b99bd4ef 8224 {
c19d1205
ZW
8225 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8226 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8227 constraint (inst.operands[i].negative,
8228 _("Thumb does not support negative register indexing"));
8229 constraint (inst.operands[i].postind,
8230 _("Thumb does not support register post-indexing"));
8231 constraint (inst.operands[i].writeback,
8232 _("Thumb does not support register indexing with writeback"));
8233 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8234 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8235
f40d1643 8236 inst.instruction |= inst.operands[i].imm;
c19d1205 8237 if (inst.operands[i].shifted)
b99bd4ef 8238 {
c19d1205
ZW
8239 constraint (inst.reloc.exp.X_op != O_constant,
8240 _("expression too complex"));
9c3c69f2
PB
8241 constraint (inst.reloc.exp.X_add_number < 0
8242 || inst.reloc.exp.X_add_number > 3,
c19d1205 8243 _("shift out of range"));
9c3c69f2 8244 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8245 }
8246 inst.reloc.type = BFD_RELOC_UNUSED;
8247 }
8248 else if (inst.operands[i].preind)
8249 {
8250 constraint (is_pc && inst.operands[i].writeback,
8251 _("cannot use writeback with PC-relative addressing"));
f40d1643 8252 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8253 _("cannot use writeback with this instruction"));
8254
8255 if (is_d)
8256 {
8257 inst.instruction |= 0x01000000;
8258 if (inst.operands[i].writeback)
8259 inst.instruction |= 0x00200000;
b99bd4ef 8260 }
c19d1205 8261 else
b99bd4ef 8262 {
c19d1205
ZW
8263 inst.instruction |= 0x00000c00;
8264 if (inst.operands[i].writeback)
8265 inst.instruction |= 0x00000100;
b99bd4ef 8266 }
c19d1205 8267 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8268 }
c19d1205 8269 else if (inst.operands[i].postind)
b99bd4ef 8270 {
c19d1205
ZW
8271 assert (inst.operands[i].writeback);
8272 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8273 constraint (is_t, _("cannot use post-indexing with this instruction"));
8274
8275 if (is_d)
8276 inst.instruction |= 0x00200000;
8277 else
8278 inst.instruction |= 0x00000900;
8279 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8280 }
8281 else /* unindexed - only for coprocessor */
8282 inst.error = _("instruction does not accept unindexed addressing");
8283}
8284
8285/* Table of Thumb instructions which exist in both 16- and 32-bit
8286 encodings (the latter only in post-V6T2 cores). The index is the
8287 value used in the insns table below. When there is more than one
8288 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8289 holds variant (1).
8290 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8291#define T16_32_TAB \
8292 X(adc, 4140, eb400000), \
8293 X(adcs, 4140, eb500000), \
8294 X(add, 1c00, eb000000), \
8295 X(adds, 1c00, eb100000), \
0110f2b8
PB
8296 X(addi, 0000, f1000000), \
8297 X(addis, 0000, f1100000), \
8298 X(add_pc,000f, f20f0000), \
8299 X(add_sp,000d, f10d0000), \
e9f89963 8300 X(adr, 000f, f20f0000), \
c19d1205
ZW
8301 X(and, 4000, ea000000), \
8302 X(ands, 4000, ea100000), \
8303 X(asr, 1000, fa40f000), \
8304 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8305 X(b, e000, f000b000), \
8306 X(bcond, d000, f0008000), \
c19d1205
ZW
8307 X(bic, 4380, ea200000), \
8308 X(bics, 4380, ea300000), \
8309 X(cmn, 42c0, eb100f00), \
8310 X(cmp, 2800, ebb00f00), \
8311 X(cpsie, b660, f3af8400), \
8312 X(cpsid, b670, f3af8600), \
8313 X(cpy, 4600, ea4f0000), \
155257ea 8314 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8315 X(eor, 4040, ea800000), \
8316 X(eors, 4040, ea900000), \
0110f2b8 8317 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8318 X(ldmia, c800, e8900000), \
8319 X(ldr, 6800, f8500000), \
8320 X(ldrb, 7800, f8100000), \
8321 X(ldrh, 8800, f8300000), \
8322 X(ldrsb, 5600, f9100000), \
8323 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8324 X(ldr_pc,4800, f85f0000), \
8325 X(ldr_pc2,4800, f85f0000), \
8326 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8327 X(lsl, 0000, fa00f000), \
8328 X(lsls, 0000, fa10f000), \
8329 X(lsr, 0800, fa20f000), \
8330 X(lsrs, 0800, fa30f000), \
8331 X(mov, 2000, ea4f0000), \
8332 X(movs, 2000, ea5f0000), \
8333 X(mul, 4340, fb00f000), \
8334 X(muls, 4340, ffffffff), /* no 32b muls */ \
8335 X(mvn, 43c0, ea6f0000), \
8336 X(mvns, 43c0, ea7f0000), \
8337 X(neg, 4240, f1c00000), /* rsb #0 */ \
8338 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8339 X(orr, 4300, ea400000), \
8340 X(orrs, 4300, ea500000), \
e9f89963
PB
8341 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8342 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8343 X(rev, ba00, fa90f080), \
8344 X(rev16, ba40, fa90f090), \
8345 X(revsh, bac0, fa90f0b0), \
8346 X(ror, 41c0, fa60f000), \
8347 X(rors, 41c0, fa70f000), \
8348 X(sbc, 4180, eb600000), \
8349 X(sbcs, 4180, eb700000), \
8350 X(stmia, c000, e8800000), \
8351 X(str, 6000, f8400000), \
8352 X(strb, 7000, f8000000), \
8353 X(strh, 8000, f8200000), \
0110f2b8 8354 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8355 X(sub, 1e00, eba00000), \
8356 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8357 X(subi, 8000, f1a00000), \
8358 X(subis, 8000, f1b00000), \
c19d1205
ZW
8359 X(sxtb, b240, fa4ff080), \
8360 X(sxth, b200, fa0ff080), \
8361 X(tst, 4200, ea100f00), \
8362 X(uxtb, b2c0, fa5ff080), \
8363 X(uxth, b280, fa1ff080), \
8364 X(nop, bf00, f3af8000), \
8365 X(yield, bf10, f3af8001), \
8366 X(wfe, bf20, f3af8002), \
8367 X(wfi, bf30, f3af8003), \
8368 X(sev, bf40, f3af9004), /* typo, 8004? */
8369
8370/* To catch errors in encoding functions, the codes are all offset by
8371 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8372 as 16-bit instructions. */
8373#define X(a,b,c) T_MNEM_##a
8374enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8375#undef X
8376
8377#define X(a,b,c) 0x##b
8378static const unsigned short thumb_op16[] = { T16_32_TAB };
8379#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8380#undef X
8381
8382#define X(a,b,c) 0x##c
8383static const unsigned int thumb_op32[] = { T16_32_TAB };
8384#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8385#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8386#undef X
8387#undef T16_32_TAB
8388
8389/* Thumb instruction encoders, in alphabetical order. */
8390
92e90b6e
PB
8391/* ADDW or SUBW. */
8392static void
8393do_t_add_sub_w (void)
8394{
8395 int Rd, Rn;
8396
8397 Rd = inst.operands[0].reg;
8398 Rn = inst.operands[1].reg;
8399
8400 constraint (Rd == 15, _("PC not allowed as destination"));
8401 inst.instruction |= (Rn << 16) | (Rd << 8);
8402 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8403}
8404
c19d1205
ZW
8405/* Parse an add or subtract instruction. We get here with inst.instruction
8406 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8407
8408static void
8409do_t_add_sub (void)
8410{
8411 int Rd, Rs, Rn;
8412
8413 Rd = inst.operands[0].reg;
8414 Rs = (inst.operands[1].present
8415 ? inst.operands[1].reg /* Rd, Rs, foo */
8416 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8417
8418 if (unified_syntax)
8419 {
0110f2b8
PB
8420 bfd_boolean flags;
8421 bfd_boolean narrow;
8422 int opcode;
8423
8424 flags = (inst.instruction == T_MNEM_adds
8425 || inst.instruction == T_MNEM_subs);
8426 if (flags)
8427 narrow = (current_it_mask == 0);
8428 else
8429 narrow = (current_it_mask != 0);
c19d1205 8430 if (!inst.operands[2].isreg)
b99bd4ef 8431 {
16805f35
PB
8432 int add;
8433
8434 add = (inst.instruction == T_MNEM_add
8435 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8436 opcode = 0;
8437 if (inst.size_req != 4)
8438 {
0110f2b8
PB
8439 /* Attempt to use a narrow opcode, with relaxation if
8440 appropriate. */
8441 if (Rd == REG_SP && Rs == REG_SP && !flags)
8442 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8443 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8444 opcode = T_MNEM_add_sp;
8445 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8446 opcode = T_MNEM_add_pc;
8447 else if (Rd <= 7 && Rs <= 7 && narrow)
8448 {
8449 if (flags)
8450 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8451 else
8452 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8453 }
8454 if (opcode)
8455 {
8456 inst.instruction = THUMB_OP16(opcode);
8457 inst.instruction |= (Rd << 4) | Rs;
8458 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8459 if (inst.size_req != 2)
8460 inst.relax = opcode;
8461 }
8462 else
8463 constraint (inst.size_req == 2, BAD_HIREG);
8464 }
8465 if (inst.size_req == 4
8466 || (inst.size_req != 2 && !opcode))
8467 {
efd81785
PB
8468 if (Rd == REG_PC)
8469 {
8470 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8471 _("only SUBS PC, LR, #const allowed"));
8472 constraint (inst.reloc.exp.X_op != O_constant,
8473 _("expression too complex"));
8474 constraint (inst.reloc.exp.X_add_number < 0
8475 || inst.reloc.exp.X_add_number > 0xff,
8476 _("immediate value out of range"));
8477 inst.instruction = T2_SUBS_PC_LR
8478 | inst.reloc.exp.X_add_number;
8479 inst.reloc.type = BFD_RELOC_UNUSED;
8480 return;
8481 }
8482 else if (Rs == REG_PC)
16805f35
PB
8483 {
8484 /* Always use addw/subw. */
8485 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8486 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8487 }
8488 else
8489 {
8490 inst.instruction = THUMB_OP32 (inst.instruction);
8491 inst.instruction = (inst.instruction & 0xe1ffffff)
8492 | 0x10000000;
8493 if (flags)
8494 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8495 else
8496 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8497 }
dc4503c6
PB
8498 inst.instruction |= Rd << 8;
8499 inst.instruction |= Rs << 16;
0110f2b8 8500 }
b99bd4ef 8501 }
c19d1205
ZW
8502 else
8503 {
8504 Rn = inst.operands[2].reg;
8505 /* See if we can do this with a 16-bit instruction. */
8506 if (!inst.operands[2].shifted && inst.size_req != 4)
8507 {
e27ec89e
PB
8508 if (Rd > 7 || Rs > 7 || Rn > 7)
8509 narrow = FALSE;
8510
8511 if (narrow)
c19d1205 8512 {
e27ec89e
PB
8513 inst.instruction = ((inst.instruction == T_MNEM_adds
8514 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8515 ? T_OPCODE_ADD_R3
8516 : T_OPCODE_SUB_R3);
8517 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8518 return;
8519 }
b99bd4ef 8520
7e806470 8521 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8522 {
7e806470
PB
8523 /* Thumb-1 cores (except v6-M) require at least one high
8524 register in a narrow non flag setting add. */
8525 if (Rd > 7 || Rn > 7
8526 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8527 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8528 {
7e806470
PB
8529 if (Rd == Rn)
8530 {
8531 Rn = Rs;
8532 Rs = Rd;
8533 }
c19d1205
ZW
8534 inst.instruction = T_OPCODE_ADD_HI;
8535 inst.instruction |= (Rd & 8) << 4;
8536 inst.instruction |= (Rd & 7);
8537 inst.instruction |= Rn << 3;
8538 return;
8539 }
c19d1205
ZW
8540 }
8541 }
8542 /* If we get here, it can't be done in 16 bits. */
8543 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8544 _("shift must be constant"));
8545 inst.instruction = THUMB_OP32 (inst.instruction);
8546 inst.instruction |= Rd << 8;
8547 inst.instruction |= Rs << 16;
8548 encode_thumb32_shifted_operand (2);
8549 }
8550 }
8551 else
8552 {
8553 constraint (inst.instruction == T_MNEM_adds
8554 || inst.instruction == T_MNEM_subs,
8555 BAD_THUMB32);
b99bd4ef 8556
c19d1205 8557 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8558 {
c19d1205
ZW
8559 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8560 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8561 BAD_HIREG);
8562
8563 inst.instruction = (inst.instruction == T_MNEM_add
8564 ? 0x0000 : 0x8000);
8565 inst.instruction |= (Rd << 4) | Rs;
8566 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8567 return;
8568 }
8569
c19d1205
ZW
8570 Rn = inst.operands[2].reg;
8571 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8572
c19d1205
ZW
8573 /* We now have Rd, Rs, and Rn set to registers. */
8574 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8575 {
c19d1205
ZW
8576 /* Can't do this for SUB. */
8577 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8578 inst.instruction = T_OPCODE_ADD_HI;
8579 inst.instruction |= (Rd & 8) << 4;
8580 inst.instruction |= (Rd & 7);
8581 if (Rs == Rd)
8582 inst.instruction |= Rn << 3;
8583 else if (Rn == Rd)
8584 inst.instruction |= Rs << 3;
8585 else
8586 constraint (1, _("dest must overlap one source register"));
8587 }
8588 else
8589 {
8590 inst.instruction = (inst.instruction == T_MNEM_add
8591 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8592 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8593 }
b99bd4ef 8594 }
b99bd4ef
NC
8595}
8596
c19d1205
ZW
8597static void
8598do_t_adr (void)
8599{
0110f2b8
PB
8600 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8601 {
8602 /* Defer to section relaxation. */
8603 inst.relax = inst.instruction;
8604 inst.instruction = THUMB_OP16 (inst.instruction);
8605 inst.instruction |= inst.operands[0].reg << 4;
8606 }
8607 else if (unified_syntax && inst.size_req != 2)
e9f89963 8608 {
0110f2b8 8609 /* Generate a 32-bit opcode. */
e9f89963
PB
8610 inst.instruction = THUMB_OP32 (inst.instruction);
8611 inst.instruction |= inst.operands[0].reg << 8;
8612 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8613 inst.reloc.pc_rel = 1;
8614 }
8615 else
8616 {
0110f2b8 8617 /* Generate a 16-bit opcode. */
e9f89963
PB
8618 inst.instruction = THUMB_OP16 (inst.instruction);
8619 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8620 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8621 inst.reloc.pc_rel = 1;
b99bd4ef 8622
e9f89963
PB
8623 inst.instruction |= inst.operands[0].reg << 4;
8624 }
c19d1205 8625}
b99bd4ef 8626
c19d1205
ZW
8627/* Arithmetic instructions for which there is just one 16-bit
8628 instruction encoding, and it allows only two low registers.
8629 For maximal compatibility with ARM syntax, we allow three register
8630 operands even when Thumb-32 instructions are not available, as long
8631 as the first two are identical. For instance, both "sbc r0,r1" and
8632 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8633static void
c19d1205 8634do_t_arit3 (void)
b99bd4ef 8635{
c19d1205 8636 int Rd, Rs, Rn;
b99bd4ef 8637
c19d1205
ZW
8638 Rd = inst.operands[0].reg;
8639 Rs = (inst.operands[1].present
8640 ? inst.operands[1].reg /* Rd, Rs, foo */
8641 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8642 Rn = inst.operands[2].reg;
b99bd4ef 8643
c19d1205 8644 if (unified_syntax)
b99bd4ef 8645 {
c19d1205
ZW
8646 if (!inst.operands[2].isreg)
8647 {
8648 /* For an immediate, we always generate a 32-bit opcode;
8649 section relaxation will shrink it later if possible. */
8650 inst.instruction = THUMB_OP32 (inst.instruction);
8651 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8652 inst.instruction |= Rd << 8;
8653 inst.instruction |= Rs << 16;
8654 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8655 }
8656 else
8657 {
e27ec89e
PB
8658 bfd_boolean narrow;
8659
c19d1205 8660 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8661 if (THUMB_SETS_FLAGS (inst.instruction))
8662 narrow = current_it_mask == 0;
8663 else
8664 narrow = current_it_mask != 0;
8665
8666 if (Rd > 7 || Rn > 7 || Rs > 7)
8667 narrow = FALSE;
8668 if (inst.operands[2].shifted)
8669 narrow = FALSE;
8670 if (inst.size_req == 4)
8671 narrow = FALSE;
8672
8673 if (narrow
c19d1205
ZW
8674 && Rd == Rs)
8675 {
8676 inst.instruction = THUMB_OP16 (inst.instruction);
8677 inst.instruction |= Rd;
8678 inst.instruction |= Rn << 3;
8679 return;
8680 }
b99bd4ef 8681
c19d1205
ZW
8682 /* If we get here, it can't be done in 16 bits. */
8683 constraint (inst.operands[2].shifted
8684 && inst.operands[2].immisreg,
8685 _("shift must be constant"));
8686 inst.instruction = THUMB_OP32 (inst.instruction);
8687 inst.instruction |= Rd << 8;
8688 inst.instruction |= Rs << 16;
8689 encode_thumb32_shifted_operand (2);
8690 }
a737bd4d 8691 }
c19d1205 8692 else
b99bd4ef 8693 {
c19d1205
ZW
8694 /* On its face this is a lie - the instruction does set the
8695 flags. However, the only supported mnemonic in this mode
8696 says it doesn't. */
8697 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8698
c19d1205
ZW
8699 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8700 _("unshifted register required"));
8701 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8702 constraint (Rd != Rs,
8703 _("dest and source1 must be the same register"));
a737bd4d 8704
c19d1205
ZW
8705 inst.instruction = THUMB_OP16 (inst.instruction);
8706 inst.instruction |= Rd;
8707 inst.instruction |= Rn << 3;
b99bd4ef 8708 }
a737bd4d 8709}
b99bd4ef 8710
c19d1205
ZW
8711/* Similarly, but for instructions where the arithmetic operation is
8712 commutative, so we can allow either of them to be different from
8713 the destination operand in a 16-bit instruction. For instance, all
8714 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8715 accepted. */
8716static void
8717do_t_arit3c (void)
a737bd4d 8718{
c19d1205 8719 int Rd, Rs, Rn;
b99bd4ef 8720
c19d1205
ZW
8721 Rd = inst.operands[0].reg;
8722 Rs = (inst.operands[1].present
8723 ? inst.operands[1].reg /* Rd, Rs, foo */
8724 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8725 Rn = inst.operands[2].reg;
a737bd4d 8726
c19d1205 8727 if (unified_syntax)
a737bd4d 8728 {
c19d1205 8729 if (!inst.operands[2].isreg)
b99bd4ef 8730 {
c19d1205
ZW
8731 /* For an immediate, we always generate a 32-bit opcode;
8732 section relaxation will shrink it later if possible. */
8733 inst.instruction = THUMB_OP32 (inst.instruction);
8734 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8735 inst.instruction |= Rd << 8;
8736 inst.instruction |= Rs << 16;
8737 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8738 }
c19d1205 8739 else
a737bd4d 8740 {
e27ec89e
PB
8741 bfd_boolean narrow;
8742
c19d1205 8743 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8744 if (THUMB_SETS_FLAGS (inst.instruction))
8745 narrow = current_it_mask == 0;
8746 else
8747 narrow = current_it_mask != 0;
8748
8749 if (Rd > 7 || Rn > 7 || Rs > 7)
8750 narrow = FALSE;
8751 if (inst.operands[2].shifted)
8752 narrow = FALSE;
8753 if (inst.size_req == 4)
8754 narrow = FALSE;
8755
8756 if (narrow)
a737bd4d 8757 {
c19d1205 8758 if (Rd == Rs)
a737bd4d 8759 {
c19d1205
ZW
8760 inst.instruction = THUMB_OP16 (inst.instruction);
8761 inst.instruction |= Rd;
8762 inst.instruction |= Rn << 3;
8763 return;
a737bd4d 8764 }
c19d1205 8765 if (Rd == Rn)
a737bd4d 8766 {
c19d1205
ZW
8767 inst.instruction = THUMB_OP16 (inst.instruction);
8768 inst.instruction |= Rd;
8769 inst.instruction |= Rs << 3;
8770 return;
a737bd4d
NC
8771 }
8772 }
c19d1205
ZW
8773
8774 /* If we get here, it can't be done in 16 bits. */
8775 constraint (inst.operands[2].shifted
8776 && inst.operands[2].immisreg,
8777 _("shift must be constant"));
8778 inst.instruction = THUMB_OP32 (inst.instruction);
8779 inst.instruction |= Rd << 8;
8780 inst.instruction |= Rs << 16;
8781 encode_thumb32_shifted_operand (2);
a737bd4d 8782 }
b99bd4ef 8783 }
c19d1205
ZW
8784 else
8785 {
8786 /* On its face this is a lie - the instruction does set the
8787 flags. However, the only supported mnemonic in this mode
8788 says it doesn't. */
8789 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8790
c19d1205
ZW
8791 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8792 _("unshifted register required"));
8793 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8794
8795 inst.instruction = THUMB_OP16 (inst.instruction);
8796 inst.instruction |= Rd;
8797
8798 if (Rd == Rs)
8799 inst.instruction |= Rn << 3;
8800 else if (Rd == Rn)
8801 inst.instruction |= Rs << 3;
8802 else
8803 constraint (1, _("dest must overlap one source register"));
8804 }
a737bd4d
NC
8805}
8806
62b3e311
PB
8807static void
8808do_t_barrier (void)
8809{
8810 if (inst.operands[0].present)
8811 {
8812 constraint ((inst.instruction & 0xf0) != 0x40
8813 && inst.operands[0].imm != 0xf,
bd3ba5d1 8814 _("bad barrier type"));
62b3e311
PB
8815 inst.instruction |= inst.operands[0].imm;
8816 }
8817 else
8818 inst.instruction |= 0xf;
8819}
8820
c19d1205
ZW
8821static void
8822do_t_bfc (void)
a737bd4d 8823{
c19d1205
ZW
8824 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8825 constraint (msb > 32, _("bit-field extends past end of register"));
8826 /* The instruction encoding stores the LSB and MSB,
8827 not the LSB and width. */
8828 inst.instruction |= inst.operands[0].reg << 8;
8829 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8830 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8831 inst.instruction |= msb - 1;
b99bd4ef
NC
8832}
8833
c19d1205
ZW
8834static void
8835do_t_bfi (void)
b99bd4ef 8836{
c19d1205 8837 unsigned int msb;
b99bd4ef 8838
c19d1205
ZW
8839 /* #0 in second position is alternative syntax for bfc, which is
8840 the same instruction but with REG_PC in the Rm field. */
8841 if (!inst.operands[1].isreg)
8842 inst.operands[1].reg = REG_PC;
b99bd4ef 8843
c19d1205
ZW
8844 msb = inst.operands[2].imm + inst.operands[3].imm;
8845 constraint (msb > 32, _("bit-field extends past end of register"));
8846 /* The instruction encoding stores the LSB and MSB,
8847 not the LSB and width. */
8848 inst.instruction |= inst.operands[0].reg << 8;
8849 inst.instruction |= inst.operands[1].reg << 16;
8850 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8851 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8852 inst.instruction |= msb - 1;
b99bd4ef
NC
8853}
8854
c19d1205
ZW
8855static void
8856do_t_bfx (void)
b99bd4ef 8857{
c19d1205
ZW
8858 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8859 _("bit-field extends past end of register"));
8860 inst.instruction |= inst.operands[0].reg << 8;
8861 inst.instruction |= inst.operands[1].reg << 16;
8862 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8863 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8864 inst.instruction |= inst.operands[3].imm - 1;
8865}
b99bd4ef 8866
c19d1205
ZW
8867/* ARM V5 Thumb BLX (argument parse)
8868 BLX <target_addr> which is BLX(1)
8869 BLX <Rm> which is BLX(2)
8870 Unfortunately, there are two different opcodes for this mnemonic.
8871 So, the insns[].value is not used, and the code here zaps values
8872 into inst.instruction.
b99bd4ef 8873
c19d1205
ZW
8874 ??? How to take advantage of the additional two bits of displacement
8875 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8876
c19d1205
ZW
8877static void
8878do_t_blx (void)
8879{
dfa9f0d5 8880 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8881 if (inst.operands[0].isreg)
8882 /* We have a register, so this is BLX(2). */
8883 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8884 else
8885 {
c19d1205 8886 /* No register. This must be BLX(1). */
2fc8bdac 8887 inst.instruction = 0xf000e800;
39b41c9c
PB
8888#ifdef OBJ_ELF
8889 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8890 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8891 else
8892#endif
8893 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8894 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8895 }
8896}
8897
c19d1205
ZW
8898static void
8899do_t_branch (void)
b99bd4ef 8900{
0110f2b8 8901 int opcode;
dfa9f0d5
PB
8902 int cond;
8903
8904 if (current_it_mask)
8905 {
8906 /* Conditional branches inside IT blocks are encoded as unconditional
8907 branches. */
8908 cond = COND_ALWAYS;
8909 /* A branch must be the last instruction in an IT block. */
8910 constraint (current_it_mask != 0x10, BAD_BRANCH);
8911 }
8912 else
8913 cond = inst.cond;
8914
8915 if (cond != COND_ALWAYS)
0110f2b8
PB
8916 opcode = T_MNEM_bcond;
8917 else
8918 opcode = inst.instruction;
8919
8920 if (unified_syntax && inst.size_req == 4)
c19d1205 8921 {
0110f2b8 8922 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8923 if (cond == COND_ALWAYS)
0110f2b8 8924 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8925 else
8926 {
dfa9f0d5
PB
8927 assert (cond != 0xF);
8928 inst.instruction |= cond << 22;
c19d1205
ZW
8929 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8930 }
8931 }
b99bd4ef
NC
8932 else
8933 {
0110f2b8 8934 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8935 if (cond == COND_ALWAYS)
c19d1205
ZW
8936 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8937 else
b99bd4ef 8938 {
dfa9f0d5 8939 inst.instruction |= cond << 8;
c19d1205 8940 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8941 }
0110f2b8
PB
8942 /* Allow section relaxation. */
8943 if (unified_syntax && inst.size_req != 2)
8944 inst.relax = opcode;
b99bd4ef 8945 }
c19d1205
ZW
8946
8947 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8948}
8949
8950static void
c19d1205 8951do_t_bkpt (void)
b99bd4ef 8952{
dfa9f0d5
PB
8953 constraint (inst.cond != COND_ALWAYS,
8954 _("instruction is always unconditional"));
c19d1205 8955 if (inst.operands[0].present)
b99bd4ef 8956 {
c19d1205
ZW
8957 constraint (inst.operands[0].imm > 255,
8958 _("immediate value out of range"));
8959 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8960 }
b99bd4ef
NC
8961}
8962
8963static void
c19d1205 8964do_t_branch23 (void)
b99bd4ef 8965{
dfa9f0d5 8966 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8967 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8968 inst.reloc.pc_rel = 1;
8969
c19d1205
ZW
8970 /* If the destination of the branch is a defined symbol which does not have
8971 the THUMB_FUNC attribute, then we must be calling a function which has
8972 the (interfacearm) attribute. We look for the Thumb entry point to that
8973 function and change the branch to refer to that function instead. */
8974 if ( inst.reloc.exp.X_op == O_symbol
8975 && inst.reloc.exp.X_add_symbol != NULL
8976 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8977 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8978 inst.reloc.exp.X_add_symbol =
8979 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8980}
8981
8982static void
c19d1205 8983do_t_bx (void)
90e4755a 8984{
dfa9f0d5 8985 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8986 inst.instruction |= inst.operands[0].reg << 3;
8987 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8988 should cause the alignment to be checked once it is known. This is
8989 because BX PC only works if the instruction is word aligned. */
8990}
90e4755a 8991
c19d1205
ZW
8992static void
8993do_t_bxj (void)
8994{
dfa9f0d5 8995 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8996 if (inst.operands[0].reg == REG_PC)
8997 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8998
c19d1205 8999 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
9000}
9001
9002static void
c19d1205 9003do_t_clz (void)
90e4755a 9004{
c19d1205
ZW
9005 inst.instruction |= inst.operands[0].reg << 8;
9006 inst.instruction |= inst.operands[1].reg << 16;
9007 inst.instruction |= inst.operands[1].reg;
9008}
90e4755a 9009
dfa9f0d5
PB
9010static void
9011do_t_cps (void)
9012{
9013 constraint (current_it_mask, BAD_NOT_IT);
9014 inst.instruction |= inst.operands[0].imm;
9015}
9016
c19d1205
ZW
9017static void
9018do_t_cpsi (void)
9019{
dfa9f0d5 9020 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9021 if (unified_syntax
62b3e311
PB
9022 && (inst.operands[1].present || inst.size_req == 4)
9023 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9024 {
c19d1205
ZW
9025 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9026 inst.instruction = 0xf3af8000;
9027 inst.instruction |= imod << 9;
9028 inst.instruction |= inst.operands[0].imm << 5;
9029 if (inst.operands[1].present)
9030 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9031 }
c19d1205 9032 else
90e4755a 9033 {
62b3e311
PB
9034 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9035 && (inst.operands[0].imm & 4),
9036 _("selected processor does not support 'A' form "
9037 "of this instruction"));
9038 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9039 _("Thumb does not support the 2-argument "
9040 "form of this instruction"));
9041 inst.instruction |= inst.operands[0].imm;
90e4755a 9042 }
90e4755a
RE
9043}
9044
c19d1205
ZW
9045/* THUMB CPY instruction (argument parse). */
9046
90e4755a 9047static void
c19d1205 9048do_t_cpy (void)
90e4755a 9049{
c19d1205 9050 if (inst.size_req == 4)
90e4755a 9051 {
c19d1205
ZW
9052 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9053 inst.instruction |= inst.operands[0].reg << 8;
9054 inst.instruction |= inst.operands[1].reg;
90e4755a 9055 }
c19d1205 9056 else
90e4755a 9057 {
c19d1205
ZW
9058 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9059 inst.instruction |= (inst.operands[0].reg & 0x7);
9060 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9061 }
90e4755a
RE
9062}
9063
90e4755a 9064static void
25fe350b 9065do_t_cbz (void)
90e4755a 9066{
dfa9f0d5 9067 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9068 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9069 inst.instruction |= inst.operands[0].reg;
9070 inst.reloc.pc_rel = 1;
9071 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9072}
90e4755a 9073
62b3e311
PB
9074static void
9075do_t_dbg (void)
9076{
9077 inst.instruction |= inst.operands[0].imm;
9078}
9079
9080static void
9081do_t_div (void)
9082{
9083 if (!inst.operands[1].present)
9084 inst.operands[1].reg = inst.operands[0].reg;
9085 inst.instruction |= inst.operands[0].reg << 8;
9086 inst.instruction |= inst.operands[1].reg << 16;
9087 inst.instruction |= inst.operands[2].reg;
9088}
9089
c19d1205
ZW
9090static void
9091do_t_hint (void)
9092{
9093 if (unified_syntax && inst.size_req == 4)
9094 inst.instruction = THUMB_OP32 (inst.instruction);
9095 else
9096 inst.instruction = THUMB_OP16 (inst.instruction);
9097}
90e4755a 9098
c19d1205
ZW
9099static void
9100do_t_it (void)
9101{
9102 unsigned int cond = inst.operands[0].imm;
e27ec89e 9103
dfa9f0d5 9104 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9105 current_it_mask = (inst.instruction & 0xf) | 0x10;
9106 current_cc = cond;
9107
9108 /* If the condition is a negative condition, invert the mask. */
c19d1205 9109 if ((cond & 0x1) == 0x0)
90e4755a 9110 {
c19d1205 9111 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9112
c19d1205
ZW
9113 if ((mask & 0x7) == 0)
9114 /* no conversion needed */;
9115 else if ((mask & 0x3) == 0)
e27ec89e
PB
9116 mask ^= 0x8;
9117 else if ((mask & 0x1) == 0)
9118 mask ^= 0xC;
c19d1205 9119 else
e27ec89e 9120 mask ^= 0xE;
90e4755a 9121
e27ec89e
PB
9122 inst.instruction &= 0xfff0;
9123 inst.instruction |= mask;
c19d1205 9124 }
90e4755a 9125
c19d1205
ZW
9126 inst.instruction |= cond << 4;
9127}
90e4755a 9128
3c707909
PB
9129/* Helper function used for both push/pop and ldm/stm. */
9130static void
9131encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9132{
9133 bfd_boolean load;
9134
9135 load = (inst.instruction & (1 << 20)) != 0;
9136
9137 if (mask & (1 << 13))
9138 inst.error = _("SP not allowed in register list");
9139 if (load)
9140 {
9141 if (mask & (1 << 14)
9142 && mask & (1 << 15))
9143 inst.error = _("LR and PC should not both be in register list");
9144
9145 if ((mask & (1 << base)) != 0
9146 && writeback)
9147 as_warn (_("base register should not be in register list "
9148 "when written back"));
9149 }
9150 else
9151 {
9152 if (mask & (1 << 15))
9153 inst.error = _("PC not allowed in register list");
9154
9155 if (mask & (1 << base))
9156 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9157 }
9158
9159 if ((mask & (mask - 1)) == 0)
9160 {
9161 /* Single register transfers implemented as str/ldr. */
9162 if (writeback)
9163 {
9164 if (inst.instruction & (1 << 23))
9165 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9166 else
9167 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9168 }
9169 else
9170 {
9171 if (inst.instruction & (1 << 23))
9172 inst.instruction = 0x00800000; /* ia -> [base] */
9173 else
9174 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9175 }
9176
9177 inst.instruction |= 0xf8400000;
9178 if (load)
9179 inst.instruction |= 0x00100000;
9180
5f4273c7 9181 mask = ffs (mask) - 1;
3c707909
PB
9182 mask <<= 12;
9183 }
9184 else if (writeback)
9185 inst.instruction |= WRITE_BACK;
9186
9187 inst.instruction |= mask;
9188 inst.instruction |= base << 16;
9189}
9190
c19d1205
ZW
9191static void
9192do_t_ldmstm (void)
9193{
9194 /* This really doesn't seem worth it. */
9195 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9196 _("expression too complex"));
9197 constraint (inst.operands[1].writeback,
9198 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9199
c19d1205
ZW
9200 if (unified_syntax)
9201 {
3c707909
PB
9202 bfd_boolean narrow;
9203 unsigned mask;
9204
9205 narrow = FALSE;
c19d1205
ZW
9206 /* See if we can use a 16-bit instruction. */
9207 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9208 && inst.size_req != 4
3c707909 9209 && !(inst.operands[1].imm & ~0xff))
90e4755a 9210 {
3c707909 9211 mask = 1 << inst.operands[0].reg;
90e4755a 9212
3c707909
PB
9213 if (inst.operands[0].reg <= 7
9214 && (inst.instruction == T_MNEM_stmia
9215 ? inst.operands[0].writeback
9216 : (inst.operands[0].writeback
9217 == !(inst.operands[1].imm & mask))))
90e4755a 9218 {
3c707909
PB
9219 if (inst.instruction == T_MNEM_stmia
9220 && (inst.operands[1].imm & mask)
9221 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9222 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9223 inst.operands[0].reg);
3c707909
PB
9224
9225 inst.instruction = THUMB_OP16 (inst.instruction);
9226 inst.instruction |= inst.operands[0].reg << 8;
9227 inst.instruction |= inst.operands[1].imm;
9228 narrow = TRUE;
90e4755a 9229 }
3c707909
PB
9230 else if (inst.operands[0] .reg == REG_SP
9231 && inst.operands[0].writeback)
90e4755a 9232 {
3c707909
PB
9233 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9234 ? T_MNEM_push : T_MNEM_pop);
9235 inst.instruction |= inst.operands[1].imm;
9236 narrow = TRUE;
90e4755a 9237 }
3c707909
PB
9238 }
9239
9240 if (!narrow)
9241 {
c19d1205
ZW
9242 if (inst.instruction < 0xffff)
9243 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9244
5f4273c7
NC
9245 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9246 inst.operands[0].writeback);
90e4755a
RE
9247 }
9248 }
c19d1205 9249 else
90e4755a 9250 {
c19d1205
ZW
9251 constraint (inst.operands[0].reg > 7
9252 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9253 constraint (inst.instruction != T_MNEM_ldmia
9254 && inst.instruction != T_MNEM_stmia,
9255 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9256 if (inst.instruction == T_MNEM_stmia)
f03698e6 9257 {
c19d1205
ZW
9258 if (!inst.operands[0].writeback)
9259 as_warn (_("this instruction will write back the base register"));
9260 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9261 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9262 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9263 inst.operands[0].reg);
f03698e6 9264 }
c19d1205 9265 else
90e4755a 9266 {
c19d1205
ZW
9267 if (!inst.operands[0].writeback
9268 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9269 as_warn (_("this instruction will write back the base register"));
9270 else if (inst.operands[0].writeback
9271 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9272 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9273 }
9274
c19d1205
ZW
9275 inst.instruction = THUMB_OP16 (inst.instruction);
9276 inst.instruction |= inst.operands[0].reg << 8;
9277 inst.instruction |= inst.operands[1].imm;
9278 }
9279}
e28cd48c 9280
c19d1205
ZW
9281static void
9282do_t_ldrex (void)
9283{
9284 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9285 || inst.operands[1].postind || inst.operands[1].writeback
9286 || inst.operands[1].immisreg || inst.operands[1].shifted
9287 || inst.operands[1].negative,
01cfc07f 9288 BAD_ADDR_MODE);
e28cd48c 9289
c19d1205
ZW
9290 inst.instruction |= inst.operands[0].reg << 12;
9291 inst.instruction |= inst.operands[1].reg << 16;
9292 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9293}
e28cd48c 9294
c19d1205
ZW
9295static void
9296do_t_ldrexd (void)
9297{
9298 if (!inst.operands[1].present)
1cac9012 9299 {
c19d1205
ZW
9300 constraint (inst.operands[0].reg == REG_LR,
9301 _("r14 not allowed as first register "
9302 "when second register is omitted"));
9303 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9304 }
c19d1205
ZW
9305 constraint (inst.operands[0].reg == inst.operands[1].reg,
9306 BAD_OVERLAP);
b99bd4ef 9307
c19d1205
ZW
9308 inst.instruction |= inst.operands[0].reg << 12;
9309 inst.instruction |= inst.operands[1].reg << 8;
9310 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9311}
9312
9313static void
c19d1205 9314do_t_ldst (void)
b99bd4ef 9315{
0110f2b8
PB
9316 unsigned long opcode;
9317 int Rn;
9318
9319 opcode = inst.instruction;
c19d1205 9320 if (unified_syntax)
b99bd4ef 9321 {
53365c0d
PB
9322 if (!inst.operands[1].isreg)
9323 {
9324 if (opcode <= 0xffff)
9325 inst.instruction = THUMB_OP32 (opcode);
9326 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9327 return;
9328 }
0110f2b8
PB
9329 if (inst.operands[1].isreg
9330 && !inst.operands[1].writeback
c19d1205
ZW
9331 && !inst.operands[1].shifted && !inst.operands[1].postind
9332 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9333 && opcode <= 0xffff
9334 && inst.size_req != 4)
c19d1205 9335 {
0110f2b8
PB
9336 /* Insn may have a 16-bit form. */
9337 Rn = inst.operands[1].reg;
9338 if (inst.operands[1].immisreg)
9339 {
9340 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9341 /* [Rn, Rik] */
0110f2b8
PB
9342 if (Rn <= 7 && inst.operands[1].imm <= 7)
9343 goto op16;
9344 }
9345 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9346 && opcode != T_MNEM_ldrsb)
9347 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9348 || (Rn == REG_SP && opcode == T_MNEM_str))
9349 {
9350 /* [Rn, #const] */
9351 if (Rn > 7)
9352 {
9353 if (Rn == REG_PC)
9354 {
9355 if (inst.reloc.pc_rel)
9356 opcode = T_MNEM_ldr_pc2;
9357 else
9358 opcode = T_MNEM_ldr_pc;
9359 }
9360 else
9361 {
9362 if (opcode == T_MNEM_ldr)
9363 opcode = T_MNEM_ldr_sp;
9364 else
9365 opcode = T_MNEM_str_sp;
9366 }
9367 inst.instruction = inst.operands[0].reg << 8;
9368 }
9369 else
9370 {
9371 inst.instruction = inst.operands[0].reg;
9372 inst.instruction |= inst.operands[1].reg << 3;
9373 }
9374 inst.instruction |= THUMB_OP16 (opcode);
9375 if (inst.size_req == 2)
9376 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9377 else
9378 inst.relax = opcode;
9379 return;
9380 }
c19d1205 9381 }
0110f2b8
PB
9382 /* Definitely a 32-bit variant. */
9383 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9384 inst.instruction |= inst.operands[0].reg << 12;
9385 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9386 return;
9387 }
9388
c19d1205
ZW
9389 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9390
9391 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9392 {
c19d1205
ZW
9393 /* Only [Rn,Rm] is acceptable. */
9394 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9395 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9396 || inst.operands[1].postind || inst.operands[1].shifted
9397 || inst.operands[1].negative,
9398 _("Thumb does not support this addressing mode"));
9399 inst.instruction = THUMB_OP16 (inst.instruction);
9400 goto op16;
b99bd4ef 9401 }
5f4273c7 9402
c19d1205
ZW
9403 inst.instruction = THUMB_OP16 (inst.instruction);
9404 if (!inst.operands[1].isreg)
9405 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9406 return;
b99bd4ef 9407
c19d1205
ZW
9408 constraint (!inst.operands[1].preind
9409 || inst.operands[1].shifted
9410 || inst.operands[1].writeback,
9411 _("Thumb does not support this addressing mode"));
9412 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9413 {
c19d1205
ZW
9414 constraint (inst.instruction & 0x0600,
9415 _("byte or halfword not valid for base register"));
9416 constraint (inst.operands[1].reg == REG_PC
9417 && !(inst.instruction & THUMB_LOAD_BIT),
9418 _("r15 based store not allowed"));
9419 constraint (inst.operands[1].immisreg,
9420 _("invalid base register for register offset"));
b99bd4ef 9421
c19d1205
ZW
9422 if (inst.operands[1].reg == REG_PC)
9423 inst.instruction = T_OPCODE_LDR_PC;
9424 else if (inst.instruction & THUMB_LOAD_BIT)
9425 inst.instruction = T_OPCODE_LDR_SP;
9426 else
9427 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9428
c19d1205
ZW
9429 inst.instruction |= inst.operands[0].reg << 8;
9430 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9431 return;
9432 }
90e4755a 9433
c19d1205
ZW
9434 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9435 if (!inst.operands[1].immisreg)
9436 {
9437 /* Immediate offset. */
9438 inst.instruction |= inst.operands[0].reg;
9439 inst.instruction |= inst.operands[1].reg << 3;
9440 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9441 return;
9442 }
90e4755a 9443
c19d1205
ZW
9444 /* Register offset. */
9445 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9446 constraint (inst.operands[1].negative,
9447 _("Thumb does not support this addressing mode"));
90e4755a 9448
c19d1205
ZW
9449 op16:
9450 switch (inst.instruction)
9451 {
9452 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9453 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9454 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9455 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9456 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9457 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9458 case 0x5600 /* ldrsb */:
9459 case 0x5e00 /* ldrsh */: break;
9460 default: abort ();
9461 }
90e4755a 9462
c19d1205
ZW
9463 inst.instruction |= inst.operands[0].reg;
9464 inst.instruction |= inst.operands[1].reg << 3;
9465 inst.instruction |= inst.operands[1].imm << 6;
9466}
90e4755a 9467
c19d1205
ZW
9468static void
9469do_t_ldstd (void)
9470{
9471 if (!inst.operands[1].present)
b99bd4ef 9472 {
c19d1205
ZW
9473 inst.operands[1].reg = inst.operands[0].reg + 1;
9474 constraint (inst.operands[0].reg == REG_LR,
9475 _("r14 not allowed here"));
b99bd4ef 9476 }
c19d1205
ZW
9477 inst.instruction |= inst.operands[0].reg << 12;
9478 inst.instruction |= inst.operands[1].reg << 8;
9479 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9480}
9481
c19d1205
ZW
9482static void
9483do_t_ldstt (void)
9484{
9485 inst.instruction |= inst.operands[0].reg << 12;
9486 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9487}
a737bd4d 9488
b99bd4ef 9489static void
c19d1205 9490do_t_mla (void)
b99bd4ef 9491{
c19d1205
ZW
9492 inst.instruction |= inst.operands[0].reg << 8;
9493 inst.instruction |= inst.operands[1].reg << 16;
9494 inst.instruction |= inst.operands[2].reg;
9495 inst.instruction |= inst.operands[3].reg << 12;
9496}
b99bd4ef 9497
c19d1205
ZW
9498static void
9499do_t_mlal (void)
9500{
9501 inst.instruction |= inst.operands[0].reg << 12;
9502 inst.instruction |= inst.operands[1].reg << 8;
9503 inst.instruction |= inst.operands[2].reg << 16;
9504 inst.instruction |= inst.operands[3].reg;
9505}
b99bd4ef 9506
c19d1205
ZW
9507static void
9508do_t_mov_cmp (void)
9509{
9510 if (unified_syntax)
b99bd4ef 9511 {
c19d1205
ZW
9512 int r0off = (inst.instruction == T_MNEM_mov
9513 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9514 unsigned long opcode;
3d388997
PB
9515 bfd_boolean narrow;
9516 bfd_boolean low_regs;
9517
9518 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9519 opcode = inst.instruction;
3d388997 9520 if (current_it_mask)
0110f2b8 9521 narrow = opcode != T_MNEM_movs;
3d388997 9522 else
0110f2b8 9523 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9524 if (inst.size_req == 4
9525 || inst.operands[1].shifted)
9526 narrow = FALSE;
9527
efd81785
PB
9528 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9529 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9530 && !inst.operands[1].shifted
9531 && inst.operands[0].reg == REG_PC
9532 && inst.operands[1].reg == REG_LR)
9533 {
9534 inst.instruction = T2_SUBS_PC_LR;
9535 return;
9536 }
9537
c19d1205
ZW
9538 if (!inst.operands[1].isreg)
9539 {
0110f2b8
PB
9540 /* Immediate operand. */
9541 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9542 narrow = 0;
9543 if (low_regs && narrow)
9544 {
9545 inst.instruction = THUMB_OP16 (opcode);
9546 inst.instruction |= inst.operands[0].reg << 8;
9547 if (inst.size_req == 2)
9548 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9549 else
9550 inst.relax = opcode;
9551 }
9552 else
9553 {
9554 inst.instruction = THUMB_OP32 (inst.instruction);
9555 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9556 inst.instruction |= inst.operands[0].reg << r0off;
9557 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9558 }
c19d1205 9559 }
728ca7c9
PB
9560 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9561 && (inst.instruction == T_MNEM_mov
9562 || inst.instruction == T_MNEM_movs))
9563 {
9564 /* Register shifts are encoded as separate shift instructions. */
9565 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9566
9567 if (current_it_mask)
9568 narrow = !flags;
9569 else
9570 narrow = flags;
9571
9572 if (inst.size_req == 4)
9573 narrow = FALSE;
9574
9575 if (!low_regs || inst.operands[1].imm > 7)
9576 narrow = FALSE;
9577
9578 if (inst.operands[0].reg != inst.operands[1].reg)
9579 narrow = FALSE;
9580
9581 switch (inst.operands[1].shift_kind)
9582 {
9583 case SHIFT_LSL:
9584 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9585 break;
9586 case SHIFT_ASR:
9587 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9588 break;
9589 case SHIFT_LSR:
9590 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9591 break;
9592 case SHIFT_ROR:
9593 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9594 break;
9595 default:
5f4273c7 9596 abort ();
728ca7c9
PB
9597 }
9598
9599 inst.instruction = opcode;
9600 if (narrow)
9601 {
9602 inst.instruction |= inst.operands[0].reg;
9603 inst.instruction |= inst.operands[1].imm << 3;
9604 }
9605 else
9606 {
9607 if (flags)
9608 inst.instruction |= CONDS_BIT;
9609
9610 inst.instruction |= inst.operands[0].reg << 8;
9611 inst.instruction |= inst.operands[1].reg << 16;
9612 inst.instruction |= inst.operands[1].imm;
9613 }
9614 }
3d388997 9615 else if (!narrow)
c19d1205 9616 {
728ca7c9
PB
9617 /* Some mov with immediate shift have narrow variants.
9618 Register shifts are handled above. */
9619 if (low_regs && inst.operands[1].shifted
9620 && (inst.instruction == T_MNEM_mov
9621 || inst.instruction == T_MNEM_movs))
9622 {
9623 if (current_it_mask)
9624 narrow = (inst.instruction == T_MNEM_mov);
9625 else
9626 narrow = (inst.instruction == T_MNEM_movs);
9627 }
9628
9629 if (narrow)
9630 {
9631 switch (inst.operands[1].shift_kind)
9632 {
9633 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9634 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9635 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9636 default: narrow = FALSE; break;
9637 }
9638 }
9639
9640 if (narrow)
9641 {
9642 inst.instruction |= inst.operands[0].reg;
9643 inst.instruction |= inst.operands[1].reg << 3;
9644 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9645 }
9646 else
9647 {
9648 inst.instruction = THUMB_OP32 (inst.instruction);
9649 inst.instruction |= inst.operands[0].reg << r0off;
9650 encode_thumb32_shifted_operand (1);
9651 }
c19d1205
ZW
9652 }
9653 else
9654 switch (inst.instruction)
9655 {
9656 case T_MNEM_mov:
9657 inst.instruction = T_OPCODE_MOV_HR;
9658 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9659 inst.instruction |= (inst.operands[0].reg & 0x7);
9660 inst.instruction |= inst.operands[1].reg << 3;
9661 break;
b99bd4ef 9662
c19d1205
ZW
9663 case T_MNEM_movs:
9664 /* We know we have low registers at this point.
9665 Generate ADD Rd, Rs, #0. */
9666 inst.instruction = T_OPCODE_ADD_I3;
9667 inst.instruction |= inst.operands[0].reg;
9668 inst.instruction |= inst.operands[1].reg << 3;
9669 break;
9670
9671 case T_MNEM_cmp:
3d388997 9672 if (low_regs)
c19d1205
ZW
9673 {
9674 inst.instruction = T_OPCODE_CMP_LR;
9675 inst.instruction |= inst.operands[0].reg;
9676 inst.instruction |= inst.operands[1].reg << 3;
9677 }
9678 else
9679 {
9680 inst.instruction = T_OPCODE_CMP_HR;
9681 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9682 inst.instruction |= (inst.operands[0].reg & 0x7);
9683 inst.instruction |= inst.operands[1].reg << 3;
9684 }
9685 break;
9686 }
b99bd4ef
NC
9687 return;
9688 }
9689
c19d1205
ZW
9690 inst.instruction = THUMB_OP16 (inst.instruction);
9691 if (inst.operands[1].isreg)
b99bd4ef 9692 {
c19d1205 9693 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9694 {
c19d1205
ZW
9695 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9696 since a MOV instruction produces unpredictable results. */
9697 if (inst.instruction == T_OPCODE_MOV_I8)
9698 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9699 else
c19d1205 9700 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9701
c19d1205
ZW
9702 inst.instruction |= inst.operands[0].reg;
9703 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9704 }
9705 else
9706 {
c19d1205
ZW
9707 if (inst.instruction == T_OPCODE_MOV_I8)
9708 inst.instruction = T_OPCODE_MOV_HR;
9709 else
9710 inst.instruction = T_OPCODE_CMP_HR;
9711 do_t_cpy ();
b99bd4ef
NC
9712 }
9713 }
c19d1205 9714 else
b99bd4ef 9715 {
c19d1205
ZW
9716 constraint (inst.operands[0].reg > 7,
9717 _("only lo regs allowed with immediate"));
9718 inst.instruction |= inst.operands[0].reg << 8;
9719 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9720 }
9721}
b99bd4ef 9722
c19d1205
ZW
9723static void
9724do_t_mov16 (void)
9725{
b6895b4f
PB
9726 bfd_vma imm;
9727 bfd_boolean top;
9728
9729 top = (inst.instruction & 0x00800000) != 0;
9730 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9731 {
9732 constraint (top, _(":lower16: not allowed this instruction"));
9733 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9734 }
9735 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9736 {
9737 constraint (!top, _(":upper16: not allowed this instruction"));
9738 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9739 }
9740
c19d1205 9741 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9742 if (inst.reloc.type == BFD_RELOC_UNUSED)
9743 {
9744 imm = inst.reloc.exp.X_add_number;
9745 inst.instruction |= (imm & 0xf000) << 4;
9746 inst.instruction |= (imm & 0x0800) << 15;
9747 inst.instruction |= (imm & 0x0700) << 4;
9748 inst.instruction |= (imm & 0x00ff);
9749 }
c19d1205 9750}
b99bd4ef 9751
c19d1205
ZW
9752static void
9753do_t_mvn_tst (void)
9754{
9755 if (unified_syntax)
9756 {
9757 int r0off = (inst.instruction == T_MNEM_mvn
9758 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9759 bfd_boolean narrow;
9760
9761 if (inst.size_req == 4
9762 || inst.instruction > 0xffff
9763 || inst.operands[1].shifted
9764 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9765 narrow = FALSE;
9766 else if (inst.instruction == T_MNEM_cmn)
9767 narrow = TRUE;
9768 else if (THUMB_SETS_FLAGS (inst.instruction))
9769 narrow = (current_it_mask == 0);
9770 else
9771 narrow = (current_it_mask != 0);
9772
c19d1205 9773 if (!inst.operands[1].isreg)
b99bd4ef 9774 {
c19d1205
ZW
9775 /* For an immediate, we always generate a 32-bit opcode;
9776 section relaxation will shrink it later if possible. */
9777 if (inst.instruction < 0xffff)
9778 inst.instruction = THUMB_OP32 (inst.instruction);
9779 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9780 inst.instruction |= inst.operands[0].reg << r0off;
9781 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9782 }
c19d1205 9783 else
b99bd4ef 9784 {
c19d1205 9785 /* See if we can do this with a 16-bit instruction. */
3d388997 9786 if (narrow)
b99bd4ef 9787 {
c19d1205
ZW
9788 inst.instruction = THUMB_OP16 (inst.instruction);
9789 inst.instruction |= inst.operands[0].reg;
9790 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9791 }
c19d1205 9792 else
b99bd4ef 9793 {
c19d1205
ZW
9794 constraint (inst.operands[1].shifted
9795 && inst.operands[1].immisreg,
9796 _("shift must be constant"));
9797 if (inst.instruction < 0xffff)
9798 inst.instruction = THUMB_OP32 (inst.instruction);
9799 inst.instruction |= inst.operands[0].reg << r0off;
9800 encode_thumb32_shifted_operand (1);
b99bd4ef 9801 }
b99bd4ef
NC
9802 }
9803 }
9804 else
9805 {
c19d1205
ZW
9806 constraint (inst.instruction > 0xffff
9807 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9808 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9809 _("unshifted register required"));
9810 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9811 BAD_HIREG);
b99bd4ef 9812
c19d1205
ZW
9813 inst.instruction = THUMB_OP16 (inst.instruction);
9814 inst.instruction |= inst.operands[0].reg;
9815 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9816 }
b99bd4ef
NC
9817}
9818
b05fe5cf 9819static void
c19d1205 9820do_t_mrs (void)
b05fe5cf 9821{
62b3e311 9822 int flags;
037e8744
JB
9823
9824 if (do_vfp_nsyn_mrs () == SUCCESS)
9825 return;
9826
62b3e311
PB
9827 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9828 if (flags == 0)
9829 {
7e806470 9830 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9831 _("selected processor does not support "
9832 "requested special purpose register"));
9833 }
9834 else
9835 {
9836 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9837 _("selected processor does not support "
44bf2362 9838 "requested special purpose register"));
62b3e311
PB
9839 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9840 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9841 _("'CPSR' or 'SPSR' expected"));
9842 }
5f4273c7 9843
c19d1205 9844 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9845 inst.instruction |= (flags & SPSR_BIT) >> 2;
9846 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9847}
b05fe5cf 9848
c19d1205
ZW
9849static void
9850do_t_msr (void)
9851{
62b3e311
PB
9852 int flags;
9853
037e8744
JB
9854 if (do_vfp_nsyn_msr () == SUCCESS)
9855 return;
9856
c19d1205
ZW
9857 constraint (!inst.operands[1].isreg,
9858 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9859 flags = inst.operands[0].imm;
9860 if (flags & ~0xff)
9861 {
9862 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9863 _("selected processor does not support "
9864 "requested special purpose register"));
9865 }
9866 else
9867 {
7e806470 9868 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
9869 _("selected processor does not support "
9870 "requested special purpose register"));
9871 flags |= PSR_f;
9872 }
9873 inst.instruction |= (flags & SPSR_BIT) >> 2;
9874 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9875 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9876 inst.instruction |= inst.operands[1].reg << 16;
9877}
b05fe5cf 9878
c19d1205
ZW
9879static void
9880do_t_mul (void)
9881{
17828f45
JM
9882 bfd_boolean narrow;
9883
c19d1205
ZW
9884 if (!inst.operands[2].present)
9885 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9886
17828f45 9887 if (unified_syntax)
b05fe5cf 9888 {
17828f45
JM
9889 if (inst.size_req == 4
9890 || (inst.operands[0].reg != inst.operands[1].reg
9891 && inst.operands[0].reg != inst.operands[2].reg)
9892 || inst.operands[1].reg > 7
9893 || inst.operands[2].reg > 7)
9894 narrow = FALSE;
9895 else if (inst.instruction == T_MNEM_muls)
9896 narrow = (current_it_mask == 0);
9897 else
9898 narrow = (current_it_mask != 0);
b05fe5cf 9899 }
c19d1205 9900 else
b05fe5cf 9901 {
17828f45
JM
9902 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
9903 constraint (inst.operands[1].reg > 7 || inst.operands[2].reg > 7,
c19d1205 9904 BAD_HIREG);
17828f45
JM
9905 narrow = TRUE;
9906 }
b05fe5cf 9907
17828f45
JM
9908 if (narrow)
9909 {
9910 /* 16-bit MULS/Conditional MUL. */
c19d1205
ZW
9911 inst.instruction = THUMB_OP16 (inst.instruction);
9912 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9913
c19d1205
ZW
9914 if (inst.operands[0].reg == inst.operands[1].reg)
9915 inst.instruction |= inst.operands[2].reg << 3;
9916 else if (inst.operands[0].reg == inst.operands[2].reg)
9917 inst.instruction |= inst.operands[1].reg << 3;
9918 else
9919 constraint (1, _("dest must overlap one source register"));
9920 }
17828f45
JM
9921 else
9922 {
9923 constraint(inst.instruction != T_MNEM_mul,
9924 _("Thumb-2 MUL must not set flags"));
9925 /* 32-bit MUL. */
9926 inst.instruction = THUMB_OP32 (inst.instruction);
9927 inst.instruction |= inst.operands[0].reg << 8;
9928 inst.instruction |= inst.operands[1].reg << 16;
9929 inst.instruction |= inst.operands[2].reg << 0;
9930 }
c19d1205 9931}
b05fe5cf 9932
c19d1205
ZW
9933static void
9934do_t_mull (void)
9935{
9936 inst.instruction |= inst.operands[0].reg << 12;
9937 inst.instruction |= inst.operands[1].reg << 8;
9938 inst.instruction |= inst.operands[2].reg << 16;
9939 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9940
c19d1205
ZW
9941 if (inst.operands[0].reg == inst.operands[1].reg)
9942 as_tsktsk (_("rdhi and rdlo must be different"));
9943}
b05fe5cf 9944
c19d1205
ZW
9945static void
9946do_t_nop (void)
9947{
9948 if (unified_syntax)
9949 {
9950 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9951 {
c19d1205
ZW
9952 inst.instruction = THUMB_OP32 (inst.instruction);
9953 inst.instruction |= inst.operands[0].imm;
9954 }
9955 else
9956 {
bc2d1808
NC
9957 /* PR9722: Check for Thumb2 availability before
9958 generating a thumb2 nop instruction. */
9959 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
9960 {
9961 inst.instruction = THUMB_OP16 (inst.instruction);
9962 inst.instruction |= inst.operands[0].imm << 4;
9963 }
9964 else
9965 inst.instruction = 0x46c0;
c19d1205
ZW
9966 }
9967 }
9968 else
9969 {
9970 constraint (inst.operands[0].present,
9971 _("Thumb does not support NOP with hints"));
9972 inst.instruction = 0x46c0;
9973 }
9974}
b05fe5cf 9975
c19d1205
ZW
9976static void
9977do_t_neg (void)
9978{
9979 if (unified_syntax)
9980 {
3d388997
PB
9981 bfd_boolean narrow;
9982
9983 if (THUMB_SETS_FLAGS (inst.instruction))
9984 narrow = (current_it_mask == 0);
9985 else
9986 narrow = (current_it_mask != 0);
9987 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9988 narrow = FALSE;
9989 if (inst.size_req == 4)
9990 narrow = FALSE;
9991
9992 if (!narrow)
c19d1205
ZW
9993 {
9994 inst.instruction = THUMB_OP32 (inst.instruction);
9995 inst.instruction |= inst.operands[0].reg << 8;
9996 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9997 }
9998 else
9999 {
c19d1205
ZW
10000 inst.instruction = THUMB_OP16 (inst.instruction);
10001 inst.instruction |= inst.operands[0].reg;
10002 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10003 }
10004 }
10005 else
10006 {
c19d1205
ZW
10007 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10008 BAD_HIREG);
10009 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10010
10011 inst.instruction = THUMB_OP16 (inst.instruction);
10012 inst.instruction |= inst.operands[0].reg;
10013 inst.instruction |= inst.operands[1].reg << 3;
10014 }
10015}
10016
10017static void
10018do_t_pkhbt (void)
10019{
10020 inst.instruction |= inst.operands[0].reg << 8;
10021 inst.instruction |= inst.operands[1].reg << 16;
10022 inst.instruction |= inst.operands[2].reg;
10023 if (inst.operands[3].present)
10024 {
10025 unsigned int val = inst.reloc.exp.X_add_number;
10026 constraint (inst.reloc.exp.X_op != O_constant,
10027 _("expression too complex"));
10028 inst.instruction |= (val & 0x1c) << 10;
10029 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10030 }
c19d1205 10031}
b05fe5cf 10032
c19d1205
ZW
10033static void
10034do_t_pkhtb (void)
10035{
10036 if (!inst.operands[3].present)
10037 inst.instruction &= ~0x00000020;
10038 do_t_pkhbt ();
b05fe5cf
ZW
10039}
10040
c19d1205
ZW
10041static void
10042do_t_pld (void)
10043{
10044 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10045}
b05fe5cf 10046
c19d1205
ZW
10047static void
10048do_t_push_pop (void)
b99bd4ef 10049{
e9f89963 10050 unsigned mask;
5f4273c7 10051
c19d1205
ZW
10052 constraint (inst.operands[0].writeback,
10053 _("push/pop do not support {reglist}^"));
10054 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10055 _("expression too complex"));
b99bd4ef 10056
e9f89963
PB
10057 mask = inst.operands[0].imm;
10058 if ((mask & ~0xff) == 0)
3c707909 10059 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10060 else if ((inst.instruction == T_MNEM_push
e9f89963 10061 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10062 || (inst.instruction == T_MNEM_pop
e9f89963 10063 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10064 {
c19d1205
ZW
10065 inst.instruction = THUMB_OP16 (inst.instruction);
10066 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10067 inst.instruction |= mask & 0xff;
c19d1205
ZW
10068 }
10069 else if (unified_syntax)
10070 {
3c707909 10071 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10072 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10073 }
10074 else
10075 {
10076 inst.error = _("invalid register list to push/pop instruction");
10077 return;
10078 }
c19d1205 10079}
b99bd4ef 10080
c19d1205
ZW
10081static void
10082do_t_rbit (void)
10083{
10084 inst.instruction |= inst.operands[0].reg << 8;
10085 inst.instruction |= inst.operands[1].reg << 16;
4ecab7d4 10086 inst.instruction |= inst.operands[1].reg;
c19d1205 10087}
b99bd4ef 10088
c19d1205
ZW
10089static void
10090do_t_rev (void)
10091{
10092 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10093 && inst.size_req != 4)
10094 {
10095 inst.instruction = THUMB_OP16 (inst.instruction);
10096 inst.instruction |= inst.operands[0].reg;
10097 inst.instruction |= inst.operands[1].reg << 3;
10098 }
10099 else if (unified_syntax)
10100 {
10101 inst.instruction = THUMB_OP32 (inst.instruction);
10102 inst.instruction |= inst.operands[0].reg << 8;
10103 inst.instruction |= inst.operands[1].reg << 16;
10104 inst.instruction |= inst.operands[1].reg;
10105 }
10106 else
10107 inst.error = BAD_HIREG;
10108}
b99bd4ef 10109
c19d1205
ZW
10110static void
10111do_t_rsb (void)
10112{
10113 int Rd, Rs;
b99bd4ef 10114
c19d1205
ZW
10115 Rd = inst.operands[0].reg;
10116 Rs = (inst.operands[1].present
10117 ? inst.operands[1].reg /* Rd, Rs, foo */
10118 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10119
c19d1205
ZW
10120 inst.instruction |= Rd << 8;
10121 inst.instruction |= Rs << 16;
10122 if (!inst.operands[2].isreg)
10123 {
026d3abb
PB
10124 bfd_boolean narrow;
10125
10126 if ((inst.instruction & 0x00100000) != 0)
10127 narrow = (current_it_mask == 0);
10128 else
10129 narrow = (current_it_mask != 0);
10130
10131 if (Rd > 7 || Rs > 7)
10132 narrow = FALSE;
10133
10134 if (inst.size_req == 4 || !unified_syntax)
10135 narrow = FALSE;
10136
10137 if (inst.reloc.exp.X_op != O_constant
10138 || inst.reloc.exp.X_add_number != 0)
10139 narrow = FALSE;
10140
10141 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10142 relaxation, but it doesn't seem worth the hassle. */
10143 if (narrow)
10144 {
10145 inst.reloc.type = BFD_RELOC_UNUSED;
10146 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10147 inst.instruction |= Rs << 3;
10148 inst.instruction |= Rd;
10149 }
10150 else
10151 {
10152 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10153 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10154 }
c19d1205
ZW
10155 }
10156 else
10157 encode_thumb32_shifted_operand (2);
10158}
b99bd4ef 10159
c19d1205
ZW
10160static void
10161do_t_setend (void)
10162{
dfa9f0d5 10163 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10164 if (inst.operands[0].imm)
10165 inst.instruction |= 0x8;
10166}
b99bd4ef 10167
c19d1205
ZW
10168static void
10169do_t_shift (void)
10170{
10171 if (!inst.operands[1].present)
10172 inst.operands[1].reg = inst.operands[0].reg;
10173
10174 if (unified_syntax)
10175 {
3d388997
PB
10176 bfd_boolean narrow;
10177 int shift_kind;
10178
10179 switch (inst.instruction)
10180 {
10181 case T_MNEM_asr:
10182 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10183 case T_MNEM_lsl:
10184 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10185 case T_MNEM_lsr:
10186 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10187 case T_MNEM_ror:
10188 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10189 default: abort ();
10190 }
10191
10192 if (THUMB_SETS_FLAGS (inst.instruction))
10193 narrow = (current_it_mask == 0);
10194 else
10195 narrow = (current_it_mask != 0);
10196 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10197 narrow = FALSE;
10198 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10199 narrow = FALSE;
10200 if (inst.operands[2].isreg
10201 && (inst.operands[1].reg != inst.operands[0].reg
10202 || inst.operands[2].reg > 7))
10203 narrow = FALSE;
10204 if (inst.size_req == 4)
10205 narrow = FALSE;
10206
10207 if (!narrow)
c19d1205
ZW
10208 {
10209 if (inst.operands[2].isreg)
b99bd4ef 10210 {
c19d1205
ZW
10211 inst.instruction = THUMB_OP32 (inst.instruction);
10212 inst.instruction |= inst.operands[0].reg << 8;
10213 inst.instruction |= inst.operands[1].reg << 16;
10214 inst.instruction |= inst.operands[2].reg;
10215 }
10216 else
10217 {
10218 inst.operands[1].shifted = 1;
3d388997 10219 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10220 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10221 ? T_MNEM_movs : T_MNEM_mov);
10222 inst.instruction |= inst.operands[0].reg << 8;
10223 encode_thumb32_shifted_operand (1);
10224 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10225 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10226 }
10227 }
10228 else
10229 {
c19d1205 10230 if (inst.operands[2].isreg)
b99bd4ef 10231 {
3d388997 10232 switch (shift_kind)
b99bd4ef 10233 {
3d388997
PB
10234 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10235 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10236 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10237 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10238 default: abort ();
b99bd4ef 10239 }
5f4273c7 10240
c19d1205
ZW
10241 inst.instruction |= inst.operands[0].reg;
10242 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10243 }
10244 else
10245 {
3d388997 10246 switch (shift_kind)
b99bd4ef 10247 {
3d388997
PB
10248 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10249 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10250 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10251 default: abort ();
b99bd4ef 10252 }
c19d1205
ZW
10253 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10254 inst.instruction |= inst.operands[0].reg;
10255 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10256 }
10257 }
c19d1205
ZW
10258 }
10259 else
10260 {
10261 constraint (inst.operands[0].reg > 7
10262 || inst.operands[1].reg > 7, BAD_HIREG);
10263 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10264
c19d1205
ZW
10265 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10266 {
10267 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10268 constraint (inst.operands[0].reg != inst.operands[1].reg,
10269 _("source1 and dest must be same register"));
b99bd4ef 10270
c19d1205
ZW
10271 switch (inst.instruction)
10272 {
10273 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10274 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10275 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10276 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10277 default: abort ();
10278 }
5f4273c7 10279
c19d1205
ZW
10280 inst.instruction |= inst.operands[0].reg;
10281 inst.instruction |= inst.operands[2].reg << 3;
10282 }
10283 else
b99bd4ef 10284 {
c19d1205
ZW
10285 switch (inst.instruction)
10286 {
10287 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10288 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10289 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10290 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10291 default: abort ();
10292 }
10293 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10294 inst.instruction |= inst.operands[0].reg;
10295 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10296 }
10297 }
b99bd4ef
NC
10298}
10299
10300static void
c19d1205 10301do_t_simd (void)
b99bd4ef 10302{
c19d1205
ZW
10303 inst.instruction |= inst.operands[0].reg << 8;
10304 inst.instruction |= inst.operands[1].reg << 16;
10305 inst.instruction |= inst.operands[2].reg;
10306}
b99bd4ef 10307
c19d1205 10308static void
3eb17e6b 10309do_t_smc (void)
c19d1205
ZW
10310{
10311 unsigned int value = inst.reloc.exp.X_add_number;
10312 constraint (inst.reloc.exp.X_op != O_constant,
10313 _("expression too complex"));
10314 inst.reloc.type = BFD_RELOC_UNUSED;
10315 inst.instruction |= (value & 0xf000) >> 12;
10316 inst.instruction |= (value & 0x0ff0);
10317 inst.instruction |= (value & 0x000f) << 16;
10318}
b99bd4ef 10319
c19d1205
ZW
10320static void
10321do_t_ssat (void)
10322{
10323 inst.instruction |= inst.operands[0].reg << 8;
10324 inst.instruction |= inst.operands[1].imm - 1;
10325 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10326
c19d1205 10327 if (inst.operands[3].present)
b99bd4ef 10328 {
c19d1205
ZW
10329 constraint (inst.reloc.exp.X_op != O_constant,
10330 _("expression too complex"));
b99bd4ef 10331
c19d1205 10332 if (inst.reloc.exp.X_add_number != 0)
6189168b 10333 {
c19d1205
ZW
10334 if (inst.operands[3].shift_kind == SHIFT_ASR)
10335 inst.instruction |= 0x00200000; /* sh bit */
10336 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10337 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10338 }
c19d1205 10339 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10340 }
b99bd4ef
NC
10341}
10342
0dd132b6 10343static void
c19d1205 10344do_t_ssat16 (void)
0dd132b6 10345{
c19d1205
ZW
10346 inst.instruction |= inst.operands[0].reg << 8;
10347 inst.instruction |= inst.operands[1].imm - 1;
10348 inst.instruction |= inst.operands[2].reg << 16;
10349}
0dd132b6 10350
c19d1205
ZW
10351static void
10352do_t_strex (void)
10353{
10354 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10355 || inst.operands[2].postind || inst.operands[2].writeback
10356 || inst.operands[2].immisreg || inst.operands[2].shifted
10357 || inst.operands[2].negative,
01cfc07f 10358 BAD_ADDR_MODE);
0dd132b6 10359
c19d1205
ZW
10360 inst.instruction |= inst.operands[0].reg << 8;
10361 inst.instruction |= inst.operands[1].reg << 12;
10362 inst.instruction |= inst.operands[2].reg << 16;
10363 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10364}
10365
b99bd4ef 10366static void
c19d1205 10367do_t_strexd (void)
b99bd4ef 10368{
c19d1205
ZW
10369 if (!inst.operands[2].present)
10370 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10371
c19d1205
ZW
10372 constraint (inst.operands[0].reg == inst.operands[1].reg
10373 || inst.operands[0].reg == inst.operands[2].reg
10374 || inst.operands[0].reg == inst.operands[3].reg
10375 || inst.operands[1].reg == inst.operands[2].reg,
10376 BAD_OVERLAP);
b99bd4ef 10377
c19d1205
ZW
10378 inst.instruction |= inst.operands[0].reg;
10379 inst.instruction |= inst.operands[1].reg << 12;
10380 inst.instruction |= inst.operands[2].reg << 8;
10381 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10382}
10383
10384static void
c19d1205 10385do_t_sxtah (void)
b99bd4ef 10386{
c19d1205
ZW
10387 inst.instruction |= inst.operands[0].reg << 8;
10388 inst.instruction |= inst.operands[1].reg << 16;
10389 inst.instruction |= inst.operands[2].reg;
10390 inst.instruction |= inst.operands[3].imm << 4;
10391}
b99bd4ef 10392
c19d1205
ZW
10393static void
10394do_t_sxth (void)
10395{
10396 if (inst.instruction <= 0xffff && inst.size_req != 4
10397 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10398 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10399 {
c19d1205
ZW
10400 inst.instruction = THUMB_OP16 (inst.instruction);
10401 inst.instruction |= inst.operands[0].reg;
10402 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10403 }
c19d1205 10404 else if (unified_syntax)
b99bd4ef 10405 {
c19d1205
ZW
10406 if (inst.instruction <= 0xffff)
10407 inst.instruction = THUMB_OP32 (inst.instruction);
10408 inst.instruction |= inst.operands[0].reg << 8;
10409 inst.instruction |= inst.operands[1].reg;
10410 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10411 }
c19d1205 10412 else
b99bd4ef 10413 {
c19d1205
ZW
10414 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10415 _("Thumb encoding does not support rotation"));
10416 constraint (1, BAD_HIREG);
b99bd4ef 10417 }
c19d1205 10418}
b99bd4ef 10419
c19d1205
ZW
10420static void
10421do_t_swi (void)
10422{
10423 inst.reloc.type = BFD_RELOC_ARM_SWI;
10424}
b99bd4ef 10425
92e90b6e
PB
10426static void
10427do_t_tb (void)
10428{
10429 int half;
10430
10431 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10432 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10433 constraint (inst.operands[0].immisreg,
10434 _("instruction requires register index"));
92e90b6e
PB
10435 constraint (inst.operands[0].imm == 15,
10436 _("PC is not a valid index register"));
10437 constraint (!half && inst.operands[0].shifted,
10438 _("instruction does not allow shifted index"));
92e90b6e
PB
10439 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10440}
10441
c19d1205
ZW
10442static void
10443do_t_usat (void)
10444{
10445 inst.instruction |= inst.operands[0].reg << 8;
10446 inst.instruction |= inst.operands[1].imm;
10447 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10448
c19d1205 10449 if (inst.operands[3].present)
b99bd4ef 10450 {
c19d1205
ZW
10451 constraint (inst.reloc.exp.X_op != O_constant,
10452 _("expression too complex"));
10453 if (inst.reloc.exp.X_add_number != 0)
10454 {
10455 if (inst.operands[3].shift_kind == SHIFT_ASR)
10456 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10457
c19d1205
ZW
10458 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10459 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10460 }
10461 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10462 }
b99bd4ef
NC
10463}
10464
10465static void
c19d1205 10466do_t_usat16 (void)
b99bd4ef 10467{
c19d1205
ZW
10468 inst.instruction |= inst.operands[0].reg << 8;
10469 inst.instruction |= inst.operands[1].imm;
10470 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10471}
c19d1205 10472
5287ad62 10473/* Neon instruction encoder helpers. */
5f4273c7 10474
5287ad62 10475/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10476
5287ad62
JB
10477/* An "invalid" code for the following tables. */
10478#define N_INV -1u
10479
10480struct neon_tab_entry
b99bd4ef 10481{
5287ad62
JB
10482 unsigned integer;
10483 unsigned float_or_poly;
10484 unsigned scalar_or_imm;
10485};
5f4273c7 10486
5287ad62
JB
10487/* Map overloaded Neon opcodes to their respective encodings. */
10488#define NEON_ENC_TAB \
10489 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10490 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10491 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10492 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10493 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10494 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10495 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10496 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10497 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10498 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10499 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10500 /* Register variants of the following two instructions are encoded as
10501 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10502 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10503 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10504 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10505 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10506 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10507 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10508 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10509 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10510 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10511 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10512 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10513 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10514 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10515 X(vshl, 0x0000400, N_INV, 0x0800510), \
10516 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10517 X(vand, 0x0000110, N_INV, 0x0800030), \
10518 X(vbic, 0x0100110, N_INV, 0x0800030), \
10519 X(veor, 0x1000110, N_INV, N_INV), \
10520 X(vorn, 0x0300110, N_INV, 0x0800010), \
10521 X(vorr, 0x0200110, N_INV, 0x0800010), \
10522 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10523 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10524 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10525 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10526 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10527 X(vst1, 0x0000000, 0x0800000, N_INV), \
10528 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10529 X(vst2, 0x0000100, 0x0800100, N_INV), \
10530 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10531 X(vst3, 0x0000200, 0x0800200, N_INV), \
10532 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10533 X(vst4, 0x0000300, 0x0800300, N_INV), \
10534 X(vmovn, 0x1b20200, N_INV, N_INV), \
10535 X(vtrn, 0x1b20080, N_INV, N_INV), \
10536 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10537 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10538 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10539 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10540 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10541 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10542 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10543 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10544 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10545
10546enum neon_opc
10547{
10548#define X(OPC,I,F,S) N_MNEM_##OPC
10549NEON_ENC_TAB
10550#undef X
10551};
b99bd4ef 10552
5287ad62
JB
10553static const struct neon_tab_entry neon_enc_tab[] =
10554{
10555#define X(OPC,I,F,S) { (I), (F), (S) }
10556NEON_ENC_TAB
10557#undef X
10558};
b99bd4ef 10559
5287ad62
JB
10560#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10561#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10562#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10563#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10564#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10565#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10566#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10567#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10568#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10569#define NEON_ENC_SINGLE(X) \
10570 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10571#define NEON_ENC_DOUBLE(X) \
10572 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10573
037e8744
JB
10574/* Define shapes for instruction operands. The following mnemonic characters
10575 are used in this table:
5287ad62 10576
037e8744 10577 F - VFP S<n> register
5287ad62
JB
10578 D - Neon D<n> register
10579 Q - Neon Q<n> register
10580 I - Immediate
10581 S - Scalar
10582 R - ARM register
10583 L - D<n> register list
5f4273c7 10584
037e8744
JB
10585 This table is used to generate various data:
10586 - enumerations of the form NS_DDR to be used as arguments to
10587 neon_select_shape.
10588 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10589 - a table used to drive neon_select_shape. */
b99bd4ef 10590
037e8744
JB
10591#define NEON_SHAPE_DEF \
10592 X(3, (D, D, D), DOUBLE), \
10593 X(3, (Q, Q, Q), QUAD), \
10594 X(3, (D, D, I), DOUBLE), \
10595 X(3, (Q, Q, I), QUAD), \
10596 X(3, (D, D, S), DOUBLE), \
10597 X(3, (Q, Q, S), QUAD), \
10598 X(2, (D, D), DOUBLE), \
10599 X(2, (Q, Q), QUAD), \
10600 X(2, (D, S), DOUBLE), \
10601 X(2, (Q, S), QUAD), \
10602 X(2, (D, R), DOUBLE), \
10603 X(2, (Q, R), QUAD), \
10604 X(2, (D, I), DOUBLE), \
10605 X(2, (Q, I), QUAD), \
10606 X(3, (D, L, D), DOUBLE), \
10607 X(2, (D, Q), MIXED), \
10608 X(2, (Q, D), MIXED), \
10609 X(3, (D, Q, I), MIXED), \
10610 X(3, (Q, D, I), MIXED), \
10611 X(3, (Q, D, D), MIXED), \
10612 X(3, (D, Q, Q), MIXED), \
10613 X(3, (Q, Q, D), MIXED), \
10614 X(3, (Q, D, S), MIXED), \
10615 X(3, (D, Q, S), MIXED), \
10616 X(4, (D, D, D, I), DOUBLE), \
10617 X(4, (Q, Q, Q, I), QUAD), \
10618 X(2, (F, F), SINGLE), \
10619 X(3, (F, F, F), SINGLE), \
10620 X(2, (F, I), SINGLE), \
10621 X(2, (F, D), MIXED), \
10622 X(2, (D, F), MIXED), \
10623 X(3, (F, F, I), MIXED), \
10624 X(4, (R, R, F, F), SINGLE), \
10625 X(4, (F, F, R, R), SINGLE), \
10626 X(3, (D, R, R), DOUBLE), \
10627 X(3, (R, R, D), DOUBLE), \
10628 X(2, (S, R), SINGLE), \
10629 X(2, (R, S), SINGLE), \
10630 X(2, (F, R), SINGLE), \
10631 X(2, (R, F), SINGLE)
10632
10633#define S2(A,B) NS_##A##B
10634#define S3(A,B,C) NS_##A##B##C
10635#define S4(A,B,C,D) NS_##A##B##C##D
10636
10637#define X(N, L, C) S##N L
10638
5287ad62
JB
10639enum neon_shape
10640{
037e8744
JB
10641 NEON_SHAPE_DEF,
10642 NS_NULL
5287ad62 10643};
b99bd4ef 10644
037e8744
JB
10645#undef X
10646#undef S2
10647#undef S3
10648#undef S4
10649
10650enum neon_shape_class
10651{
10652 SC_SINGLE,
10653 SC_DOUBLE,
10654 SC_QUAD,
10655 SC_MIXED
10656};
10657
10658#define X(N, L, C) SC_##C
10659
10660static enum neon_shape_class neon_shape_class[] =
10661{
10662 NEON_SHAPE_DEF
10663};
10664
10665#undef X
10666
10667enum neon_shape_el
10668{
10669 SE_F,
10670 SE_D,
10671 SE_Q,
10672 SE_I,
10673 SE_S,
10674 SE_R,
10675 SE_L
10676};
10677
10678/* Register widths of above. */
10679static unsigned neon_shape_el_size[] =
10680{
10681 32,
10682 64,
10683 128,
10684 0,
10685 32,
10686 32,
10687 0
10688};
10689
10690struct neon_shape_info
10691{
10692 unsigned els;
10693 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10694};
10695
10696#define S2(A,B) { SE_##A, SE_##B }
10697#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10698#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10699
10700#define X(N, L, C) { N, S##N L }
10701
10702static struct neon_shape_info neon_shape_tab[] =
10703{
10704 NEON_SHAPE_DEF
10705};
10706
10707#undef X
10708#undef S2
10709#undef S3
10710#undef S4
10711
5287ad62
JB
10712/* Bit masks used in type checking given instructions.
10713 'N_EQK' means the type must be the same as (or based on in some way) the key
10714 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10715 set, various other bits can be set as well in order to modify the meaning of
10716 the type constraint. */
10717
10718enum neon_type_mask
10719{
8e79c3df
CM
10720 N_S8 = 0x0000001,
10721 N_S16 = 0x0000002,
10722 N_S32 = 0x0000004,
10723 N_S64 = 0x0000008,
10724 N_U8 = 0x0000010,
10725 N_U16 = 0x0000020,
10726 N_U32 = 0x0000040,
10727 N_U64 = 0x0000080,
10728 N_I8 = 0x0000100,
10729 N_I16 = 0x0000200,
10730 N_I32 = 0x0000400,
10731 N_I64 = 0x0000800,
10732 N_8 = 0x0001000,
10733 N_16 = 0x0002000,
10734 N_32 = 0x0004000,
10735 N_64 = 0x0008000,
10736 N_P8 = 0x0010000,
10737 N_P16 = 0x0020000,
10738 N_F16 = 0x0040000,
10739 N_F32 = 0x0080000,
10740 N_F64 = 0x0100000,
10741 N_KEY = 0x1000000, /* key element (main type specifier). */
10742 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
10743 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
10744 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
10745 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
10746 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
10747 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
10748 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
10749 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
10750 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10751 N_UTYP = 0,
037e8744 10752 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10753};
10754
dcbf9037
JB
10755#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10756
5287ad62
JB
10757#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10758#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10759#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10760#define N_SUF_32 (N_SU_32 | N_F32)
10761#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10762#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10763
10764/* Pass this as the first type argument to neon_check_type to ignore types
10765 altogether. */
10766#define N_IGNORE_TYPE (N_KEY | N_EQK)
10767
037e8744
JB
10768/* Select a "shape" for the current instruction (describing register types or
10769 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10770 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10771 function of operand parsing, so this function doesn't need to be called.
10772 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10773
10774static enum neon_shape
037e8744 10775neon_select_shape (enum neon_shape shape, ...)
5287ad62 10776{
037e8744
JB
10777 va_list ap;
10778 enum neon_shape first_shape = shape;
5287ad62
JB
10779
10780 /* Fix missing optional operands. FIXME: we don't know at this point how
10781 many arguments we should have, so this makes the assumption that we have
10782 > 1. This is true of all current Neon opcodes, I think, but may not be
10783 true in the future. */
10784 if (!inst.operands[1].present)
10785 inst.operands[1] = inst.operands[0];
10786
037e8744 10787 va_start (ap, shape);
5f4273c7 10788
037e8744
JB
10789 for (; shape != NS_NULL; shape = va_arg (ap, int))
10790 {
10791 unsigned j;
10792 int matches = 1;
10793
10794 for (j = 0; j < neon_shape_tab[shape].els; j++)
10795 {
10796 if (!inst.operands[j].present)
10797 {
10798 matches = 0;
10799 break;
10800 }
10801
10802 switch (neon_shape_tab[shape].el[j])
10803 {
10804 case SE_F:
10805 if (!(inst.operands[j].isreg
10806 && inst.operands[j].isvec
10807 && inst.operands[j].issingle
10808 && !inst.operands[j].isquad))
10809 matches = 0;
10810 break;
10811
10812 case SE_D:
10813 if (!(inst.operands[j].isreg
10814 && inst.operands[j].isvec
10815 && !inst.operands[j].isquad
10816 && !inst.operands[j].issingle))
10817 matches = 0;
10818 break;
10819
10820 case SE_R:
10821 if (!(inst.operands[j].isreg
10822 && !inst.operands[j].isvec))
10823 matches = 0;
10824 break;
10825
10826 case SE_Q:
10827 if (!(inst.operands[j].isreg
10828 && inst.operands[j].isvec
10829 && inst.operands[j].isquad
10830 && !inst.operands[j].issingle))
10831 matches = 0;
10832 break;
10833
10834 case SE_I:
10835 if (!(!inst.operands[j].isreg
10836 && !inst.operands[j].isscalar))
10837 matches = 0;
10838 break;
10839
10840 case SE_S:
10841 if (!(!inst.operands[j].isreg
10842 && inst.operands[j].isscalar))
10843 matches = 0;
10844 break;
10845
10846 case SE_L:
10847 break;
10848 }
10849 }
10850 if (matches)
5287ad62 10851 break;
037e8744 10852 }
5f4273c7 10853
037e8744 10854 va_end (ap);
5287ad62 10855
037e8744
JB
10856 if (shape == NS_NULL && first_shape != NS_NULL)
10857 first_error (_("invalid instruction shape"));
5287ad62 10858
037e8744
JB
10859 return shape;
10860}
5287ad62 10861
037e8744
JB
10862/* True if SHAPE is predominantly a quadword operation (most of the time, this
10863 means the Q bit should be set). */
10864
10865static int
10866neon_quad (enum neon_shape shape)
10867{
10868 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10869}
037e8744 10870
5287ad62
JB
10871static void
10872neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10873 unsigned *g_size)
10874{
10875 /* Allow modification to be made to types which are constrained to be
10876 based on the key element, based on bits set alongside N_EQK. */
10877 if ((typebits & N_EQK) != 0)
10878 {
10879 if ((typebits & N_HLF) != 0)
10880 *g_size /= 2;
10881 else if ((typebits & N_DBL) != 0)
10882 *g_size *= 2;
10883 if ((typebits & N_SGN) != 0)
10884 *g_type = NT_signed;
10885 else if ((typebits & N_UNS) != 0)
10886 *g_type = NT_unsigned;
10887 else if ((typebits & N_INT) != 0)
10888 *g_type = NT_integer;
10889 else if ((typebits & N_FLT) != 0)
10890 *g_type = NT_float;
dcbf9037
JB
10891 else if ((typebits & N_SIZ) != 0)
10892 *g_type = NT_untyped;
5287ad62
JB
10893 }
10894}
5f4273c7 10895
5287ad62
JB
10896/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10897 operand type, i.e. the single type specified in a Neon instruction when it
10898 is the only one given. */
10899
10900static struct neon_type_el
10901neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10902{
10903 struct neon_type_el dest = *key;
5f4273c7 10904
5287ad62 10905 assert ((thisarg & N_EQK) != 0);
5f4273c7 10906
5287ad62
JB
10907 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10908
10909 return dest;
10910}
10911
10912/* Convert Neon type and size into compact bitmask representation. */
10913
10914static enum neon_type_mask
10915type_chk_of_el_type (enum neon_el_type type, unsigned size)
10916{
10917 switch (type)
10918 {
10919 case NT_untyped:
10920 switch (size)
10921 {
10922 case 8: return N_8;
10923 case 16: return N_16;
10924 case 32: return N_32;
10925 case 64: return N_64;
10926 default: ;
10927 }
10928 break;
10929
10930 case NT_integer:
10931 switch (size)
10932 {
10933 case 8: return N_I8;
10934 case 16: return N_I16;
10935 case 32: return N_I32;
10936 case 64: return N_I64;
10937 default: ;
10938 }
10939 break;
10940
10941 case NT_float:
037e8744
JB
10942 switch (size)
10943 {
8e79c3df 10944 case 16: return N_F16;
037e8744
JB
10945 case 32: return N_F32;
10946 case 64: return N_F64;
10947 default: ;
10948 }
5287ad62
JB
10949 break;
10950
10951 case NT_poly:
10952 switch (size)
10953 {
10954 case 8: return N_P8;
10955 case 16: return N_P16;
10956 default: ;
10957 }
10958 break;
10959
10960 case NT_signed:
10961 switch (size)
10962 {
10963 case 8: return N_S8;
10964 case 16: return N_S16;
10965 case 32: return N_S32;
10966 case 64: return N_S64;
10967 default: ;
10968 }
10969 break;
10970
10971 case NT_unsigned:
10972 switch (size)
10973 {
10974 case 8: return N_U8;
10975 case 16: return N_U16;
10976 case 32: return N_U32;
10977 case 64: return N_U64;
10978 default: ;
10979 }
10980 break;
10981
10982 default: ;
10983 }
5f4273c7 10984
5287ad62
JB
10985 return N_UTYP;
10986}
10987
10988/* Convert compact Neon bitmask type representation to a type and size. Only
10989 handles the case where a single bit is set in the mask. */
10990
dcbf9037 10991static int
5287ad62
JB
10992el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10993 enum neon_type_mask mask)
10994{
dcbf9037
JB
10995 if ((mask & N_EQK) != 0)
10996 return FAIL;
10997
5287ad62
JB
10998 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10999 *size = 8;
dcbf9037 11000 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11001 *size = 16;
dcbf9037 11002 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11003 *size = 32;
037e8744 11004 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11005 *size = 64;
dcbf9037
JB
11006 else
11007 return FAIL;
11008
5287ad62
JB
11009 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11010 *type = NT_signed;
dcbf9037 11011 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11012 *type = NT_unsigned;
dcbf9037 11013 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11014 *type = NT_integer;
dcbf9037 11015 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11016 *type = NT_untyped;
dcbf9037 11017 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11018 *type = NT_poly;
037e8744 11019 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11020 *type = NT_float;
dcbf9037
JB
11021 else
11022 return FAIL;
5f4273c7 11023
dcbf9037 11024 return SUCCESS;
5287ad62
JB
11025}
11026
11027/* Modify a bitmask of allowed types. This is only needed for type
11028 relaxation. */
11029
11030static unsigned
11031modify_types_allowed (unsigned allowed, unsigned mods)
11032{
11033 unsigned size;
11034 enum neon_el_type type;
11035 unsigned destmask;
11036 int i;
5f4273c7 11037
5287ad62 11038 destmask = 0;
5f4273c7 11039
5287ad62
JB
11040 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11041 {
dcbf9037
JB
11042 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11043 {
11044 neon_modify_type_size (mods, &type, &size);
11045 destmask |= type_chk_of_el_type (type, size);
11046 }
5287ad62 11047 }
5f4273c7 11048
5287ad62
JB
11049 return destmask;
11050}
11051
11052/* Check type and return type classification.
11053 The manual states (paraphrase): If one datatype is given, it indicates the
11054 type given in:
11055 - the second operand, if there is one
11056 - the operand, if there is no second operand
11057 - the result, if there are no operands.
11058 This isn't quite good enough though, so we use a concept of a "key" datatype
11059 which is set on a per-instruction basis, which is the one which matters when
11060 only one data type is written.
11061 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11062 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11063
11064static struct neon_type_el
11065neon_check_type (unsigned els, enum neon_shape ns, ...)
11066{
11067 va_list ap;
11068 unsigned i, pass, key_el = 0;
11069 unsigned types[NEON_MAX_TYPE_ELS];
11070 enum neon_el_type k_type = NT_invtype;
11071 unsigned k_size = -1u;
11072 struct neon_type_el badtype = {NT_invtype, -1};
11073 unsigned key_allowed = 0;
11074
11075 /* Optional registers in Neon instructions are always (not) in operand 1.
11076 Fill in the missing operand here, if it was omitted. */
11077 if (els > 1 && !inst.operands[1].present)
11078 inst.operands[1] = inst.operands[0];
11079
11080 /* Suck up all the varargs. */
11081 va_start (ap, ns);
11082 for (i = 0; i < els; i++)
11083 {
11084 unsigned thisarg = va_arg (ap, unsigned);
11085 if (thisarg == N_IGNORE_TYPE)
11086 {
11087 va_end (ap);
11088 return badtype;
11089 }
11090 types[i] = thisarg;
11091 if ((thisarg & N_KEY) != 0)
11092 key_el = i;
11093 }
11094 va_end (ap);
11095
dcbf9037
JB
11096 if (inst.vectype.elems > 0)
11097 for (i = 0; i < els; i++)
11098 if (inst.operands[i].vectype.type != NT_invtype)
11099 {
11100 first_error (_("types specified in both the mnemonic and operands"));
11101 return badtype;
11102 }
11103
5287ad62
JB
11104 /* Duplicate inst.vectype elements here as necessary.
11105 FIXME: No idea if this is exactly the same as the ARM assembler,
11106 particularly when an insn takes one register and one non-register
11107 operand. */
11108 if (inst.vectype.elems == 1 && els > 1)
11109 {
11110 unsigned j;
11111 inst.vectype.elems = els;
11112 inst.vectype.el[key_el] = inst.vectype.el[0];
11113 for (j = 0; j < els; j++)
dcbf9037
JB
11114 if (j != key_el)
11115 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11116 types[j]);
11117 }
11118 else if (inst.vectype.elems == 0 && els > 0)
11119 {
11120 unsigned j;
11121 /* No types were given after the mnemonic, so look for types specified
11122 after each operand. We allow some flexibility here; as long as the
11123 "key" operand has a type, we can infer the others. */
11124 for (j = 0; j < els; j++)
11125 if (inst.operands[j].vectype.type != NT_invtype)
11126 inst.vectype.el[j] = inst.operands[j].vectype;
11127
11128 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11129 {
dcbf9037
JB
11130 for (j = 0; j < els; j++)
11131 if (inst.operands[j].vectype.type == NT_invtype)
11132 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11133 types[j]);
11134 }
11135 else
11136 {
11137 first_error (_("operand types can't be inferred"));
11138 return badtype;
5287ad62
JB
11139 }
11140 }
11141 else if (inst.vectype.elems != els)
11142 {
dcbf9037 11143 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11144 return badtype;
11145 }
11146
11147 for (pass = 0; pass < 2; pass++)
11148 {
11149 for (i = 0; i < els; i++)
11150 {
11151 unsigned thisarg = types[i];
11152 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11153 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11154 enum neon_el_type g_type = inst.vectype.el[i].type;
11155 unsigned g_size = inst.vectype.el[i].size;
11156
11157 /* Decay more-specific signed & unsigned types to sign-insensitive
11158 integer types if sign-specific variants are unavailable. */
11159 if ((g_type == NT_signed || g_type == NT_unsigned)
11160 && (types_allowed & N_SU_ALL) == 0)
11161 g_type = NT_integer;
11162
11163 /* If only untyped args are allowed, decay any more specific types to
11164 them. Some instructions only care about signs for some element
11165 sizes, so handle that properly. */
11166 if ((g_size == 8 && (types_allowed & N_8) != 0)
11167 || (g_size == 16 && (types_allowed & N_16) != 0)
11168 || (g_size == 32 && (types_allowed & N_32) != 0)
11169 || (g_size == 64 && (types_allowed & N_64) != 0))
11170 g_type = NT_untyped;
11171
11172 if (pass == 0)
11173 {
11174 if ((thisarg & N_KEY) != 0)
11175 {
11176 k_type = g_type;
11177 k_size = g_size;
11178 key_allowed = thisarg & ~N_KEY;
11179 }
11180 }
11181 else
11182 {
037e8744
JB
11183 if ((thisarg & N_VFP) != 0)
11184 {
11185 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11186 unsigned regwidth = neon_shape_el_size[regshape], match;
11187
11188 /* In VFP mode, operands must match register widths. If we
11189 have a key operand, use its width, else use the width of
11190 the current operand. */
11191 if (k_size != -1u)
11192 match = k_size;
11193 else
11194 match = g_size;
11195
11196 if (regwidth != match)
11197 {
11198 first_error (_("operand size must match register width"));
11199 return badtype;
11200 }
11201 }
5f4273c7 11202
5287ad62
JB
11203 if ((thisarg & N_EQK) == 0)
11204 {
11205 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11206
11207 if ((given_type & types_allowed) == 0)
11208 {
dcbf9037 11209 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11210 return badtype;
11211 }
11212 }
11213 else
11214 {
11215 enum neon_el_type mod_k_type = k_type;
11216 unsigned mod_k_size = k_size;
11217 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11218 if (g_type != mod_k_type || g_size != mod_k_size)
11219 {
dcbf9037 11220 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11221 return badtype;
11222 }
11223 }
11224 }
11225 }
11226 }
11227
11228 return inst.vectype.el[key_el];
11229}
11230
037e8744 11231/* Neon-style VFP instruction forwarding. */
5287ad62 11232
037e8744
JB
11233/* Thumb VFP instructions have 0xE in the condition field. */
11234
11235static void
11236do_vfp_cond_or_thumb (void)
5287ad62
JB
11237{
11238 if (thumb_mode)
037e8744 11239 inst.instruction |= 0xe0000000;
5287ad62 11240 else
037e8744 11241 inst.instruction |= inst.cond << 28;
5287ad62
JB
11242}
11243
037e8744
JB
11244/* Look up and encode a simple mnemonic, for use as a helper function for the
11245 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11246 etc. It is assumed that operand parsing has already been done, and that the
11247 operands are in the form expected by the given opcode (this isn't necessarily
11248 the same as the form in which they were parsed, hence some massaging must
11249 take place before this function is called).
11250 Checks current arch version against that in the looked-up opcode. */
5287ad62 11251
037e8744
JB
11252static void
11253do_vfp_nsyn_opcode (const char *opname)
5287ad62 11254{
037e8744 11255 const struct asm_opcode *opcode;
5f4273c7 11256
037e8744 11257 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11258
037e8744
JB
11259 if (!opcode)
11260 abort ();
5287ad62 11261
037e8744
JB
11262 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11263 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11264 _(BAD_FPU));
5287ad62 11265
037e8744
JB
11266 if (thumb_mode)
11267 {
11268 inst.instruction = opcode->tvalue;
11269 opcode->tencode ();
11270 }
11271 else
11272 {
11273 inst.instruction = (inst.cond << 28) | opcode->avalue;
11274 opcode->aencode ();
11275 }
11276}
5287ad62
JB
11277
11278static void
037e8744 11279do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11280{
037e8744
JB
11281 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11282
11283 if (rs == NS_FFF)
11284 {
11285 if (is_add)
11286 do_vfp_nsyn_opcode ("fadds");
11287 else
11288 do_vfp_nsyn_opcode ("fsubs");
11289 }
11290 else
11291 {
11292 if (is_add)
11293 do_vfp_nsyn_opcode ("faddd");
11294 else
11295 do_vfp_nsyn_opcode ("fsubd");
11296 }
11297}
11298
11299/* Check operand types to see if this is a VFP instruction, and if so call
11300 PFN (). */
11301
11302static int
11303try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11304{
11305 enum neon_shape rs;
11306 struct neon_type_el et;
11307
11308 switch (args)
11309 {
11310 case 2:
11311 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11312 et = neon_check_type (2, rs,
11313 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11314 break;
5f4273c7 11315
037e8744
JB
11316 case 3:
11317 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11318 et = neon_check_type (3, rs,
11319 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11320 break;
11321
11322 default:
11323 abort ();
11324 }
11325
11326 if (et.type != NT_invtype)
11327 {
11328 pfn (rs);
11329 return SUCCESS;
11330 }
11331 else
11332 inst.error = NULL;
11333
11334 return FAIL;
11335}
11336
11337static void
11338do_vfp_nsyn_mla_mls (enum neon_shape rs)
11339{
11340 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11341
037e8744
JB
11342 if (rs == NS_FFF)
11343 {
11344 if (is_mla)
11345 do_vfp_nsyn_opcode ("fmacs");
11346 else
11347 do_vfp_nsyn_opcode ("fmscs");
11348 }
11349 else
11350 {
11351 if (is_mla)
11352 do_vfp_nsyn_opcode ("fmacd");
11353 else
11354 do_vfp_nsyn_opcode ("fmscd");
11355 }
11356}
11357
11358static void
11359do_vfp_nsyn_mul (enum neon_shape rs)
11360{
11361 if (rs == NS_FFF)
11362 do_vfp_nsyn_opcode ("fmuls");
11363 else
11364 do_vfp_nsyn_opcode ("fmuld");
11365}
11366
11367static void
11368do_vfp_nsyn_abs_neg (enum neon_shape rs)
11369{
11370 int is_neg = (inst.instruction & 0x80) != 0;
11371 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11372
11373 if (rs == NS_FF)
11374 {
11375 if (is_neg)
11376 do_vfp_nsyn_opcode ("fnegs");
11377 else
11378 do_vfp_nsyn_opcode ("fabss");
11379 }
11380 else
11381 {
11382 if (is_neg)
11383 do_vfp_nsyn_opcode ("fnegd");
11384 else
11385 do_vfp_nsyn_opcode ("fabsd");
11386 }
11387}
11388
11389/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11390 insns belong to Neon, and are handled elsewhere. */
11391
11392static void
11393do_vfp_nsyn_ldm_stm (int is_dbmode)
11394{
11395 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11396 if (is_ldm)
11397 {
11398 if (is_dbmode)
11399 do_vfp_nsyn_opcode ("fldmdbs");
11400 else
11401 do_vfp_nsyn_opcode ("fldmias");
11402 }
11403 else
11404 {
11405 if (is_dbmode)
11406 do_vfp_nsyn_opcode ("fstmdbs");
11407 else
11408 do_vfp_nsyn_opcode ("fstmias");
11409 }
11410}
11411
037e8744
JB
11412static void
11413do_vfp_nsyn_sqrt (void)
11414{
11415 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11416 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11417
037e8744
JB
11418 if (rs == NS_FF)
11419 do_vfp_nsyn_opcode ("fsqrts");
11420 else
11421 do_vfp_nsyn_opcode ("fsqrtd");
11422}
11423
11424static void
11425do_vfp_nsyn_div (void)
11426{
11427 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11428 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11429 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11430
037e8744
JB
11431 if (rs == NS_FFF)
11432 do_vfp_nsyn_opcode ("fdivs");
11433 else
11434 do_vfp_nsyn_opcode ("fdivd");
11435}
11436
11437static void
11438do_vfp_nsyn_nmul (void)
11439{
11440 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11441 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11442 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11443
037e8744
JB
11444 if (rs == NS_FFF)
11445 {
11446 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11447 do_vfp_sp_dyadic ();
11448 }
11449 else
11450 {
11451 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11452 do_vfp_dp_rd_rn_rm ();
11453 }
11454 do_vfp_cond_or_thumb ();
11455}
11456
11457static void
11458do_vfp_nsyn_cmp (void)
11459{
11460 if (inst.operands[1].isreg)
11461 {
11462 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11463 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11464
037e8744
JB
11465 if (rs == NS_FF)
11466 {
11467 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11468 do_vfp_sp_monadic ();
11469 }
11470 else
11471 {
11472 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11473 do_vfp_dp_rd_rm ();
11474 }
11475 }
11476 else
11477 {
11478 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11479 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11480
11481 switch (inst.instruction & 0x0fffffff)
11482 {
11483 case N_MNEM_vcmp:
11484 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11485 break;
11486 case N_MNEM_vcmpe:
11487 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11488 break;
11489 default:
11490 abort ();
11491 }
5f4273c7 11492
037e8744
JB
11493 if (rs == NS_FI)
11494 {
11495 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11496 do_vfp_sp_compare_z ();
11497 }
11498 else
11499 {
11500 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11501 do_vfp_dp_rd ();
11502 }
11503 }
11504 do_vfp_cond_or_thumb ();
11505}
11506
11507static void
11508nsyn_insert_sp (void)
11509{
11510 inst.operands[1] = inst.operands[0];
11511 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11512 inst.operands[0].reg = 13;
11513 inst.operands[0].isreg = 1;
11514 inst.operands[0].writeback = 1;
11515 inst.operands[0].present = 1;
11516}
11517
11518static void
11519do_vfp_nsyn_push (void)
11520{
11521 nsyn_insert_sp ();
11522 if (inst.operands[1].issingle)
11523 do_vfp_nsyn_opcode ("fstmdbs");
11524 else
11525 do_vfp_nsyn_opcode ("fstmdbd");
11526}
11527
11528static void
11529do_vfp_nsyn_pop (void)
11530{
11531 nsyn_insert_sp ();
11532 if (inst.operands[1].issingle)
22b5b651 11533 do_vfp_nsyn_opcode ("fldmias");
037e8744 11534 else
22b5b651 11535 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11536}
11537
11538/* Fix up Neon data-processing instructions, ORing in the correct bits for
11539 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11540
11541static unsigned
11542neon_dp_fixup (unsigned i)
11543{
11544 if (thumb_mode)
11545 {
11546 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11547 if (i & (1 << 24))
11548 i |= 1 << 28;
5f4273c7 11549
037e8744 11550 i &= ~(1 << 24);
5f4273c7 11551
037e8744
JB
11552 i |= 0xef000000;
11553 }
11554 else
11555 i |= 0xf2000000;
5f4273c7 11556
037e8744
JB
11557 return i;
11558}
11559
11560/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11561 (0, 1, 2, 3). */
11562
11563static unsigned
11564neon_logbits (unsigned x)
11565{
11566 return ffs (x) - 4;
11567}
11568
11569#define LOW4(R) ((R) & 0xf)
11570#define HI1(R) (((R) >> 4) & 1)
11571
11572/* Encode insns with bit pattern:
11573
11574 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11575 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11576
037e8744
JB
11577 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11578 different meaning for some instruction. */
11579
11580static void
11581neon_three_same (int isquad, int ubit, int size)
11582{
11583 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11584 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11585 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11586 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11587 inst.instruction |= LOW4 (inst.operands[2].reg);
11588 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11589 inst.instruction |= (isquad != 0) << 6;
11590 inst.instruction |= (ubit != 0) << 24;
11591 if (size != -1)
11592 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11593
037e8744
JB
11594 inst.instruction = neon_dp_fixup (inst.instruction);
11595}
11596
11597/* Encode instructions of the form:
11598
11599 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11600 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11601
11602 Don't write size if SIZE == -1. */
11603
11604static void
11605neon_two_same (int qbit, int ubit, int size)
11606{
11607 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11608 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11609 inst.instruction |= LOW4 (inst.operands[1].reg);
11610 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11611 inst.instruction |= (qbit != 0) << 6;
11612 inst.instruction |= (ubit != 0) << 24;
11613
11614 if (size != -1)
11615 inst.instruction |= neon_logbits (size) << 18;
11616
11617 inst.instruction = neon_dp_fixup (inst.instruction);
11618}
11619
11620/* Neon instruction encoders, in approximate order of appearance. */
11621
11622static void
11623do_neon_dyadic_i_su (void)
11624{
037e8744 11625 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11626 struct neon_type_el et = neon_check_type (3, rs,
11627 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11628 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11629}
11630
11631static void
11632do_neon_dyadic_i64_su (void)
11633{
037e8744 11634 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11635 struct neon_type_el et = neon_check_type (3, rs,
11636 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11637 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11638}
11639
11640static void
11641neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11642 unsigned immbits)
11643{
11644 unsigned size = et.size >> 3;
11645 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11646 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11647 inst.instruction |= LOW4 (inst.operands[1].reg);
11648 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11649 inst.instruction |= (isquad != 0) << 6;
11650 inst.instruction |= immbits << 16;
11651 inst.instruction |= (size >> 3) << 7;
11652 inst.instruction |= (size & 0x7) << 19;
11653 if (write_ubit)
11654 inst.instruction |= (uval != 0) << 24;
11655
11656 inst.instruction = neon_dp_fixup (inst.instruction);
11657}
11658
11659static void
11660do_neon_shl_imm (void)
11661{
11662 if (!inst.operands[2].isreg)
11663 {
037e8744 11664 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11665 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11666 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11667 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11668 }
11669 else
11670 {
037e8744 11671 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11672 struct neon_type_el et = neon_check_type (3, rs,
11673 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11674 unsigned int tmp;
11675
11676 /* VSHL/VQSHL 3-register variants have syntax such as:
11677 vshl.xx Dd, Dm, Dn
11678 whereas other 3-register operations encoded by neon_three_same have
11679 syntax like:
11680 vadd.xx Dd, Dn, Dm
11681 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11682 here. */
11683 tmp = inst.operands[2].reg;
11684 inst.operands[2].reg = inst.operands[1].reg;
11685 inst.operands[1].reg = tmp;
5287ad62 11686 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11687 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11688 }
11689}
11690
11691static void
11692do_neon_qshl_imm (void)
11693{
11694 if (!inst.operands[2].isreg)
11695 {
037e8744 11696 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11697 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11698
5287ad62 11699 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11700 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11701 inst.operands[2].imm);
11702 }
11703 else
11704 {
037e8744 11705 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11706 struct neon_type_el et = neon_check_type (3, rs,
11707 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11708 unsigned int tmp;
11709
11710 /* See note in do_neon_shl_imm. */
11711 tmp = inst.operands[2].reg;
11712 inst.operands[2].reg = inst.operands[1].reg;
11713 inst.operands[1].reg = tmp;
5287ad62 11714 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11715 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11716 }
11717}
11718
627907b7
JB
11719static void
11720do_neon_rshl (void)
11721{
11722 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11723 struct neon_type_el et = neon_check_type (3, rs,
11724 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11725 unsigned int tmp;
11726
11727 tmp = inst.operands[2].reg;
11728 inst.operands[2].reg = inst.operands[1].reg;
11729 inst.operands[1].reg = tmp;
11730 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11731}
11732
5287ad62
JB
11733static int
11734neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11735{
036dc3f7
PB
11736 /* Handle .I8 pseudo-instructions. */
11737 if (size == 8)
5287ad62 11738 {
5287ad62
JB
11739 /* Unfortunately, this will make everything apart from zero out-of-range.
11740 FIXME is this the intended semantics? There doesn't seem much point in
11741 accepting .I8 if so. */
11742 immediate |= immediate << 8;
11743 size = 16;
036dc3f7
PB
11744 }
11745
11746 if (size >= 32)
11747 {
11748 if (immediate == (immediate & 0x000000ff))
11749 {
11750 *immbits = immediate;
11751 return 0x1;
11752 }
11753 else if (immediate == (immediate & 0x0000ff00))
11754 {
11755 *immbits = immediate >> 8;
11756 return 0x3;
11757 }
11758 else if (immediate == (immediate & 0x00ff0000))
11759 {
11760 *immbits = immediate >> 16;
11761 return 0x5;
11762 }
11763 else if (immediate == (immediate & 0xff000000))
11764 {
11765 *immbits = immediate >> 24;
11766 return 0x7;
11767 }
11768 if ((immediate & 0xffff) != (immediate >> 16))
11769 goto bad_immediate;
11770 immediate &= 0xffff;
5287ad62
JB
11771 }
11772
11773 if (immediate == (immediate & 0x000000ff))
11774 {
11775 *immbits = immediate;
036dc3f7 11776 return 0x9;
5287ad62
JB
11777 }
11778 else if (immediate == (immediate & 0x0000ff00))
11779 {
11780 *immbits = immediate >> 8;
036dc3f7 11781 return 0xb;
5287ad62
JB
11782 }
11783
11784 bad_immediate:
dcbf9037 11785 first_error (_("immediate value out of range"));
5287ad62
JB
11786 return FAIL;
11787}
11788
11789/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11790 A, B, C, D. */
11791
11792static int
11793neon_bits_same_in_bytes (unsigned imm)
11794{
11795 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11796 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11797 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11798 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11799}
11800
11801/* For immediate of above form, return 0bABCD. */
11802
11803static unsigned
11804neon_squash_bits (unsigned imm)
11805{
11806 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11807 | ((imm & 0x01000000) >> 21);
11808}
11809
136da414 11810/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11811
11812static unsigned
11813neon_qfloat_bits (unsigned imm)
11814{
136da414 11815 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11816}
11817
11818/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11819 the instruction. *OP is passed as the initial value of the op field, and
11820 may be set to a different value depending on the constant (i.e.
11821 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 11822 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 11823 try smaller element sizes. */
5287ad62
JB
11824
11825static int
c96612cc
JB
11826neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11827 unsigned *immbits, int *op, int size,
11828 enum neon_el_type type)
5287ad62 11829{
c96612cc
JB
11830 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11831 float. */
11832 if (type == NT_float && !float_p)
11833 return FAIL;
11834
136da414
JB
11835 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11836 {
11837 if (size != 32 || *op == 1)
11838 return FAIL;
11839 *immbits = neon_qfloat_bits (immlo);
11840 return 0xf;
11841 }
036dc3f7
PB
11842
11843 if (size == 64)
5287ad62 11844 {
036dc3f7
PB
11845 if (neon_bits_same_in_bytes (immhi)
11846 && neon_bits_same_in_bytes (immlo))
11847 {
11848 if (*op == 1)
11849 return FAIL;
11850 *immbits = (neon_squash_bits (immhi) << 4)
11851 | neon_squash_bits (immlo);
11852 *op = 1;
11853 return 0xe;
11854 }
11855
11856 if (immhi != immlo)
11857 return FAIL;
5287ad62 11858 }
036dc3f7
PB
11859
11860 if (size >= 32)
5287ad62 11861 {
036dc3f7
PB
11862 if (immlo == (immlo & 0x000000ff))
11863 {
11864 *immbits = immlo;
11865 return 0x0;
11866 }
11867 else if (immlo == (immlo & 0x0000ff00))
11868 {
11869 *immbits = immlo >> 8;
11870 return 0x2;
11871 }
11872 else if (immlo == (immlo & 0x00ff0000))
11873 {
11874 *immbits = immlo >> 16;
11875 return 0x4;
11876 }
11877 else if (immlo == (immlo & 0xff000000))
11878 {
11879 *immbits = immlo >> 24;
11880 return 0x6;
11881 }
11882 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11883 {
11884 *immbits = (immlo >> 8) & 0xff;
11885 return 0xc;
11886 }
11887 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11888 {
11889 *immbits = (immlo >> 16) & 0xff;
11890 return 0xd;
11891 }
11892
11893 if ((immlo & 0xffff) != (immlo >> 16))
11894 return FAIL;
11895 immlo &= 0xffff;
5287ad62 11896 }
036dc3f7
PB
11897
11898 if (size >= 16)
5287ad62 11899 {
036dc3f7
PB
11900 if (immlo == (immlo & 0x000000ff))
11901 {
11902 *immbits = immlo;
11903 return 0x8;
11904 }
11905 else if (immlo == (immlo & 0x0000ff00))
11906 {
11907 *immbits = immlo >> 8;
11908 return 0xa;
11909 }
11910
11911 if ((immlo & 0xff) != (immlo >> 8))
11912 return FAIL;
11913 immlo &= 0xff;
5287ad62 11914 }
036dc3f7
PB
11915
11916 if (immlo == (immlo & 0x000000ff))
5287ad62 11917 {
036dc3f7
PB
11918 /* Don't allow MVN with 8-bit immediate. */
11919 if (*op == 1)
11920 return FAIL;
11921 *immbits = immlo;
11922 return 0xe;
5287ad62 11923 }
5287ad62
JB
11924
11925 return FAIL;
11926}
11927
11928/* Write immediate bits [7:0] to the following locations:
11929
11930 |28/24|23 19|18 16|15 4|3 0|
11931 | 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|
11932
11933 This function is used by VMOV/VMVN/VORR/VBIC. */
11934
11935static void
11936neon_write_immbits (unsigned immbits)
11937{
11938 inst.instruction |= immbits & 0xf;
11939 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11940 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11941}
11942
11943/* Invert low-order SIZE bits of XHI:XLO. */
11944
11945static void
11946neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11947{
11948 unsigned immlo = xlo ? *xlo : 0;
11949 unsigned immhi = xhi ? *xhi : 0;
11950
11951 switch (size)
11952 {
11953 case 8:
11954 immlo = (~immlo) & 0xff;
11955 break;
11956
11957 case 16:
11958 immlo = (~immlo) & 0xffff;
11959 break;
11960
11961 case 64:
11962 immhi = (~immhi) & 0xffffffff;
11963 /* fall through. */
11964
11965 case 32:
11966 immlo = (~immlo) & 0xffffffff;
11967 break;
11968
11969 default:
11970 abort ();
11971 }
11972
11973 if (xlo)
11974 *xlo = immlo;
11975
11976 if (xhi)
11977 *xhi = immhi;
11978}
11979
11980static void
11981do_neon_logic (void)
11982{
11983 if (inst.operands[2].present && inst.operands[2].isreg)
11984 {
037e8744 11985 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11986 neon_check_type (3, rs, N_IGNORE_TYPE);
11987 /* U bit and size field were set as part of the bitmask. */
11988 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11989 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11990 }
11991 else
11992 {
037e8744
JB
11993 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11994 struct neon_type_el et = neon_check_type (2, rs,
11995 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11996 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11997 unsigned immbits;
11998 int cmode;
5f4273c7 11999
5287ad62
JB
12000 if (et.type == NT_invtype)
12001 return;
5f4273c7 12002
5287ad62
JB
12003 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12004
036dc3f7
PB
12005 immbits = inst.operands[1].imm;
12006 if (et.size == 64)
12007 {
12008 /* .i64 is a pseudo-op, so the immediate must be a repeating
12009 pattern. */
12010 if (immbits != (inst.operands[1].regisimm ?
12011 inst.operands[1].reg : 0))
12012 {
12013 /* Set immbits to an invalid constant. */
12014 immbits = 0xdeadbeef;
12015 }
12016 }
12017
5287ad62
JB
12018 switch (opcode)
12019 {
12020 case N_MNEM_vbic:
036dc3f7 12021 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12022 break;
5f4273c7 12023
5287ad62 12024 case N_MNEM_vorr:
036dc3f7 12025 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12026 break;
5f4273c7 12027
5287ad62
JB
12028 case N_MNEM_vand:
12029 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12030 neon_invert_size (&immbits, 0, et.size);
12031 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12032 break;
5f4273c7 12033
5287ad62
JB
12034 case N_MNEM_vorn:
12035 /* Pseudo-instruction for VORR. */
5287ad62
JB
12036 neon_invert_size (&immbits, 0, et.size);
12037 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12038 break;
5f4273c7 12039
5287ad62
JB
12040 default:
12041 abort ();
12042 }
12043
12044 if (cmode == FAIL)
12045 return;
12046
037e8744 12047 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12048 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12049 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12050 inst.instruction |= cmode << 8;
12051 neon_write_immbits (immbits);
5f4273c7 12052
5287ad62
JB
12053 inst.instruction = neon_dp_fixup (inst.instruction);
12054 }
12055}
12056
12057static void
12058do_neon_bitfield (void)
12059{
037e8744 12060 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12061 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12062 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12063}
12064
12065static void
dcbf9037
JB
12066neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12067 unsigned destbits)
5287ad62 12068{
037e8744 12069 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12070 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12071 types | N_KEY);
5287ad62
JB
12072 if (et.type == NT_float)
12073 {
12074 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12075 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12076 }
12077 else
12078 {
12079 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12080 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12081 }
12082}
12083
12084static void
12085do_neon_dyadic_if_su (void)
12086{
dcbf9037 12087 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12088}
12089
12090static void
12091do_neon_dyadic_if_su_d (void)
12092{
12093 /* This version only allow D registers, but that constraint is enforced during
12094 operand parsing so we don't need to do anything extra here. */
dcbf9037 12095 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12096}
12097
5287ad62
JB
12098static void
12099do_neon_dyadic_if_i_d (void)
12100{
428e3f1f
PB
12101 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12102 affected if we specify unsigned args. */
12103 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12104}
12105
037e8744
JB
12106enum vfp_or_neon_is_neon_bits
12107{
12108 NEON_CHECK_CC = 1,
12109 NEON_CHECK_ARCH = 2
12110};
12111
12112/* Call this function if an instruction which may have belonged to the VFP or
12113 Neon instruction sets, but turned out to be a Neon instruction (due to the
12114 operand types involved, etc.). We have to check and/or fix-up a couple of
12115 things:
12116
12117 - Make sure the user hasn't attempted to make a Neon instruction
12118 conditional.
12119 - Alter the value in the condition code field if necessary.
12120 - Make sure that the arch supports Neon instructions.
12121
12122 Which of these operations take place depends on bits from enum
12123 vfp_or_neon_is_neon_bits.
12124
12125 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12126 current instruction's condition is COND_ALWAYS, the condition field is
12127 changed to inst.uncond_value. This is necessary because instructions shared
12128 between VFP and Neon may be conditional for the VFP variants only, and the
12129 unconditional Neon version must have, e.g., 0xF in the condition field. */
12130
12131static int
12132vfp_or_neon_is_neon (unsigned check)
12133{
12134 /* Conditions are always legal in Thumb mode (IT blocks). */
12135 if (!thumb_mode && (check & NEON_CHECK_CC))
12136 {
12137 if (inst.cond != COND_ALWAYS)
12138 {
12139 first_error (_(BAD_COND));
12140 return FAIL;
12141 }
12142 if (inst.uncond_value != -1)
12143 inst.instruction |= inst.uncond_value << 28;
12144 }
5f4273c7 12145
037e8744
JB
12146 if ((check & NEON_CHECK_ARCH)
12147 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12148 {
12149 first_error (_(BAD_FPU));
12150 return FAIL;
12151 }
5f4273c7 12152
037e8744
JB
12153 return SUCCESS;
12154}
12155
5287ad62
JB
12156static void
12157do_neon_addsub_if_i (void)
12158{
037e8744
JB
12159 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12160 return;
12161
12162 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12163 return;
12164
5287ad62
JB
12165 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12166 affected if we specify unsigned args. */
dcbf9037 12167 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12168}
12169
12170/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12171 result to be:
12172 V<op> A,B (A is operand 0, B is operand 2)
12173 to mean:
12174 V<op> A,B,A
12175 not:
12176 V<op> A,B,B
12177 so handle that case specially. */
12178
12179static void
12180neon_exchange_operands (void)
12181{
12182 void *scratch = alloca (sizeof (inst.operands[0]));
12183 if (inst.operands[1].present)
12184 {
12185 /* Swap operands[1] and operands[2]. */
12186 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12187 inst.operands[1] = inst.operands[2];
12188 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12189 }
12190 else
12191 {
12192 inst.operands[1] = inst.operands[2];
12193 inst.operands[2] = inst.operands[0];
12194 }
12195}
12196
12197static void
12198neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12199{
12200 if (inst.operands[2].isreg)
12201 {
12202 if (invert)
12203 neon_exchange_operands ();
dcbf9037 12204 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12205 }
12206 else
12207 {
037e8744 12208 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12209 struct neon_type_el et = neon_check_type (2, rs,
12210 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12211
12212 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12213 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12214 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12215 inst.instruction |= LOW4 (inst.operands[1].reg);
12216 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12217 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12218 inst.instruction |= (et.type == NT_float) << 10;
12219 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12220
5287ad62
JB
12221 inst.instruction = neon_dp_fixup (inst.instruction);
12222 }
12223}
12224
12225static void
12226do_neon_cmp (void)
12227{
12228 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12229}
12230
12231static void
12232do_neon_cmp_inv (void)
12233{
12234 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12235}
12236
12237static void
12238do_neon_ceq (void)
12239{
12240 neon_compare (N_IF_32, N_IF_32, FALSE);
12241}
12242
12243/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12244 scalars, which are encoded in 5 bits, M : Rm.
12245 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12246 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12247 index in M. */
12248
12249static unsigned
12250neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12251{
dcbf9037
JB
12252 unsigned regno = NEON_SCALAR_REG (scalar);
12253 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12254
12255 switch (elsize)
12256 {
12257 case 16:
12258 if (regno > 7 || elno > 3)
12259 goto bad_scalar;
12260 return regno | (elno << 3);
5f4273c7 12261
5287ad62
JB
12262 case 32:
12263 if (regno > 15 || elno > 1)
12264 goto bad_scalar;
12265 return regno | (elno << 4);
12266
12267 default:
12268 bad_scalar:
dcbf9037 12269 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12270 }
12271
12272 return 0;
12273}
12274
12275/* Encode multiply / multiply-accumulate scalar instructions. */
12276
12277static void
12278neon_mul_mac (struct neon_type_el et, int ubit)
12279{
dcbf9037
JB
12280 unsigned scalar;
12281
12282 /* Give a more helpful error message if we have an invalid type. */
12283 if (et.type == NT_invtype)
12284 return;
5f4273c7 12285
dcbf9037 12286 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12287 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12288 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12289 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12290 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12291 inst.instruction |= LOW4 (scalar);
12292 inst.instruction |= HI1 (scalar) << 5;
12293 inst.instruction |= (et.type == NT_float) << 8;
12294 inst.instruction |= neon_logbits (et.size) << 20;
12295 inst.instruction |= (ubit != 0) << 24;
12296
12297 inst.instruction = neon_dp_fixup (inst.instruction);
12298}
12299
12300static void
12301do_neon_mac_maybe_scalar (void)
12302{
037e8744
JB
12303 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12304 return;
12305
12306 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12307 return;
12308
5287ad62
JB
12309 if (inst.operands[2].isscalar)
12310 {
037e8744 12311 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12312 struct neon_type_el et = neon_check_type (3, rs,
12313 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12314 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12315 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12316 }
12317 else
428e3f1f
PB
12318 {
12319 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12320 affected if we specify unsigned args. */
12321 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12322 }
5287ad62
JB
12323}
12324
12325static void
12326do_neon_tst (void)
12327{
037e8744 12328 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12329 struct neon_type_el et = neon_check_type (3, rs,
12330 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12331 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12332}
12333
12334/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12335 same types as the MAC equivalents. The polynomial type for this instruction
12336 is encoded the same as the integer type. */
12337
12338static void
12339do_neon_mul (void)
12340{
037e8744
JB
12341 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12342 return;
12343
12344 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12345 return;
12346
5287ad62
JB
12347 if (inst.operands[2].isscalar)
12348 do_neon_mac_maybe_scalar ();
12349 else
dcbf9037 12350 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12351}
12352
12353static void
12354do_neon_qdmulh (void)
12355{
12356 if (inst.operands[2].isscalar)
12357 {
037e8744 12358 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12359 struct neon_type_el et = neon_check_type (3, rs,
12360 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12361 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12362 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12363 }
12364 else
12365 {
037e8744 12366 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12367 struct neon_type_el et = neon_check_type (3, rs,
12368 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12369 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12370 /* The U bit (rounding) comes from bit mask. */
037e8744 12371 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12372 }
12373}
12374
12375static void
12376do_neon_fcmp_absolute (void)
12377{
037e8744 12378 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12379 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12380 /* Size field comes from bit mask. */
037e8744 12381 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12382}
12383
12384static void
12385do_neon_fcmp_absolute_inv (void)
12386{
12387 neon_exchange_operands ();
12388 do_neon_fcmp_absolute ();
12389}
12390
12391static void
12392do_neon_step (void)
12393{
037e8744 12394 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12395 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12396 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12397}
12398
12399static void
12400do_neon_abs_neg (void)
12401{
037e8744
JB
12402 enum neon_shape rs;
12403 struct neon_type_el et;
5f4273c7 12404
037e8744
JB
12405 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12406 return;
12407
12408 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12409 return;
12410
12411 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12412 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12413
5287ad62
JB
12414 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12415 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12416 inst.instruction |= LOW4 (inst.operands[1].reg);
12417 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12418 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12419 inst.instruction |= (et.type == NT_float) << 10;
12420 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12421
5287ad62
JB
12422 inst.instruction = neon_dp_fixup (inst.instruction);
12423}
12424
12425static void
12426do_neon_sli (void)
12427{
037e8744 12428 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12429 struct neon_type_el et = neon_check_type (2, rs,
12430 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12431 int imm = inst.operands[2].imm;
12432 constraint (imm < 0 || (unsigned)imm >= et.size,
12433 _("immediate out of range for insert"));
037e8744 12434 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12435}
12436
12437static void
12438do_neon_sri (void)
12439{
037e8744 12440 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12441 struct neon_type_el et = neon_check_type (2, rs,
12442 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12443 int imm = inst.operands[2].imm;
12444 constraint (imm < 1 || (unsigned)imm > et.size,
12445 _("immediate out of range for insert"));
037e8744 12446 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12447}
12448
12449static void
12450do_neon_qshlu_imm (void)
12451{
037e8744 12452 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12453 struct neon_type_el et = neon_check_type (2, rs,
12454 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12455 int imm = inst.operands[2].imm;
12456 constraint (imm < 0 || (unsigned)imm >= et.size,
12457 _("immediate out of range for shift"));
12458 /* Only encodes the 'U present' variant of the instruction.
12459 In this case, signed types have OP (bit 8) set to 0.
12460 Unsigned types have OP set to 1. */
12461 inst.instruction |= (et.type == NT_unsigned) << 8;
12462 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12463 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12464}
12465
12466static void
12467do_neon_qmovn (void)
12468{
12469 struct neon_type_el et = neon_check_type (2, NS_DQ,
12470 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12471 /* Saturating move where operands can be signed or unsigned, and the
12472 destination has the same signedness. */
12473 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12474 if (et.type == NT_unsigned)
12475 inst.instruction |= 0xc0;
12476 else
12477 inst.instruction |= 0x80;
12478 neon_two_same (0, 1, et.size / 2);
12479}
12480
12481static void
12482do_neon_qmovun (void)
12483{
12484 struct neon_type_el et = neon_check_type (2, NS_DQ,
12485 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12486 /* Saturating move with unsigned results. Operands must be signed. */
12487 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12488 neon_two_same (0, 1, et.size / 2);
12489}
12490
12491static void
12492do_neon_rshift_sat_narrow (void)
12493{
12494 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12495 or unsigned. If operands are unsigned, results must also be unsigned. */
12496 struct neon_type_el et = neon_check_type (2, NS_DQI,
12497 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12498 int imm = inst.operands[2].imm;
12499 /* This gets the bounds check, size encoding and immediate bits calculation
12500 right. */
12501 et.size /= 2;
5f4273c7 12502
5287ad62
JB
12503 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12504 VQMOVN.I<size> <Dd>, <Qm>. */
12505 if (imm == 0)
12506 {
12507 inst.operands[2].present = 0;
12508 inst.instruction = N_MNEM_vqmovn;
12509 do_neon_qmovn ();
12510 return;
12511 }
5f4273c7 12512
5287ad62
JB
12513 constraint (imm < 1 || (unsigned)imm > et.size,
12514 _("immediate out of range"));
12515 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12516}
12517
12518static void
12519do_neon_rshift_sat_narrow_u (void)
12520{
12521 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12522 or unsigned. If operands are unsigned, results must also be unsigned. */
12523 struct neon_type_el et = neon_check_type (2, NS_DQI,
12524 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12525 int imm = inst.operands[2].imm;
12526 /* This gets the bounds check, size encoding and immediate bits calculation
12527 right. */
12528 et.size /= 2;
12529
12530 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12531 VQMOVUN.I<size> <Dd>, <Qm>. */
12532 if (imm == 0)
12533 {
12534 inst.operands[2].present = 0;
12535 inst.instruction = N_MNEM_vqmovun;
12536 do_neon_qmovun ();
12537 return;
12538 }
12539
12540 constraint (imm < 1 || (unsigned)imm > et.size,
12541 _("immediate out of range"));
12542 /* FIXME: The manual is kind of unclear about what value U should have in
12543 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12544 must be 1. */
12545 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12546}
12547
12548static void
12549do_neon_movn (void)
12550{
12551 struct neon_type_el et = neon_check_type (2, NS_DQ,
12552 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12553 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12554 neon_two_same (0, 1, et.size / 2);
12555}
12556
12557static void
12558do_neon_rshift_narrow (void)
12559{
12560 struct neon_type_el et = neon_check_type (2, NS_DQI,
12561 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12562 int imm = inst.operands[2].imm;
12563 /* This gets the bounds check, size encoding and immediate bits calculation
12564 right. */
12565 et.size /= 2;
5f4273c7 12566
5287ad62
JB
12567 /* If immediate is zero then we are a pseudo-instruction for
12568 VMOVN.I<size> <Dd>, <Qm> */
12569 if (imm == 0)
12570 {
12571 inst.operands[2].present = 0;
12572 inst.instruction = N_MNEM_vmovn;
12573 do_neon_movn ();
12574 return;
12575 }
5f4273c7 12576
5287ad62
JB
12577 constraint (imm < 1 || (unsigned)imm > et.size,
12578 _("immediate out of range for narrowing operation"));
12579 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12580}
12581
12582static void
12583do_neon_shll (void)
12584{
12585 /* FIXME: Type checking when lengthening. */
12586 struct neon_type_el et = neon_check_type (2, NS_QDI,
12587 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12588 unsigned imm = inst.operands[2].imm;
12589
12590 if (imm == et.size)
12591 {
12592 /* Maximum shift variant. */
12593 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12594 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12595 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12596 inst.instruction |= LOW4 (inst.operands[1].reg);
12597 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12598 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12599
5287ad62
JB
12600 inst.instruction = neon_dp_fixup (inst.instruction);
12601 }
12602 else
12603 {
12604 /* A more-specific type check for non-max versions. */
12605 et = neon_check_type (2, NS_QDI,
12606 N_EQK | N_DBL, N_SU_32 | N_KEY);
12607 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12608 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12609 }
12610}
12611
037e8744 12612/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12613 the current instruction is. */
12614
12615static int
12616neon_cvt_flavour (enum neon_shape rs)
12617{
037e8744
JB
12618#define CVT_VAR(C,X,Y) \
12619 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12620 if (et.type != NT_invtype) \
12621 { \
12622 inst.error = NULL; \
12623 return (C); \
5287ad62
JB
12624 }
12625 struct neon_type_el et;
037e8744
JB
12626 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12627 || rs == NS_FF) ? N_VFP : 0;
12628 /* The instruction versions which take an immediate take one register
12629 argument, which is extended to the width of the full register. Thus the
12630 "source" and "destination" registers must have the same width. Hack that
12631 here by making the size equal to the key (wider, in this case) operand. */
12632 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 12633
5287ad62
JB
12634 CVT_VAR (0, N_S32, N_F32);
12635 CVT_VAR (1, N_U32, N_F32);
12636 CVT_VAR (2, N_F32, N_S32);
12637 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
12638 /* Half-precision conversions. */
12639 CVT_VAR (4, N_F32, N_F16);
12640 CVT_VAR (5, N_F16, N_F32);
5f4273c7 12641
037e8744 12642 whole_reg = N_VFP;
5f4273c7 12643
037e8744 12644 /* VFP instructions. */
8e79c3df
CM
12645 CVT_VAR (6, N_F32, N_F64);
12646 CVT_VAR (7, N_F64, N_F32);
12647 CVT_VAR (8, N_S32, N_F64 | key);
12648 CVT_VAR (9, N_U32, N_F64 | key);
12649 CVT_VAR (10, N_F64 | key, N_S32);
12650 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 12651 /* VFP instructions with bitshift. */
8e79c3df
CM
12652 CVT_VAR (12, N_F32 | key, N_S16);
12653 CVT_VAR (13, N_F32 | key, N_U16);
12654 CVT_VAR (14, N_F64 | key, N_S16);
12655 CVT_VAR (15, N_F64 | key, N_U16);
12656 CVT_VAR (16, N_S16, N_F32 | key);
12657 CVT_VAR (17, N_U16, N_F32 | key);
12658 CVT_VAR (18, N_S16, N_F64 | key);
12659 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 12660
5287ad62
JB
12661 return -1;
12662#undef CVT_VAR
12663}
12664
037e8744
JB
12665/* Neon-syntax VFP conversions. */
12666
5287ad62 12667static void
037e8744 12668do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12669{
037e8744 12670 const char *opname = 0;
5f4273c7 12671
037e8744 12672 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12673 {
037e8744
JB
12674 /* Conversions with immediate bitshift. */
12675 const char *enc[] =
12676 {
12677 "ftosls",
12678 "ftouls",
12679 "fsltos",
12680 "fultos",
12681 NULL,
12682 NULL,
8e79c3df
CM
12683 NULL,
12684 NULL,
037e8744
JB
12685 "ftosld",
12686 "ftould",
12687 "fsltod",
12688 "fultod",
12689 "fshtos",
12690 "fuhtos",
12691 "fshtod",
12692 "fuhtod",
12693 "ftoshs",
12694 "ftouhs",
12695 "ftoshd",
12696 "ftouhd"
12697 };
12698
12699 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12700 {
12701 opname = enc[flavour];
12702 constraint (inst.operands[0].reg != inst.operands[1].reg,
12703 _("operands 0 and 1 must be the same register"));
12704 inst.operands[1] = inst.operands[2];
12705 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12706 }
5287ad62
JB
12707 }
12708 else
12709 {
037e8744
JB
12710 /* Conversions without bitshift. */
12711 const char *enc[] =
12712 {
12713 "ftosis",
12714 "ftouis",
12715 "fsitos",
12716 "fuitos",
8e79c3df
CM
12717 "NULL",
12718 "NULL",
037e8744
JB
12719 "fcvtsd",
12720 "fcvtds",
12721 "ftosid",
12722 "ftouid",
12723 "fsitod",
12724 "fuitod"
12725 };
12726
12727 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12728 opname = enc[flavour];
12729 }
12730
12731 if (opname)
12732 do_vfp_nsyn_opcode (opname);
12733}
12734
12735static void
12736do_vfp_nsyn_cvtz (void)
12737{
12738 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12739 int flavour = neon_cvt_flavour (rs);
12740 const char *enc[] =
12741 {
12742 "ftosizs",
12743 "ftouizs",
12744 NULL,
12745 NULL,
12746 NULL,
12747 NULL,
8e79c3df
CM
12748 NULL,
12749 NULL,
037e8744
JB
12750 "ftosizd",
12751 "ftouizd"
12752 };
12753
12754 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12755 do_vfp_nsyn_opcode (enc[flavour]);
12756}
f31fef98 12757
037e8744
JB
12758static void
12759do_neon_cvt (void)
12760{
12761 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 12762 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
12763 int flavour = neon_cvt_flavour (rs);
12764
12765 /* VFP rather than Neon conversions. */
8e79c3df 12766 if (flavour >= 6)
037e8744
JB
12767 {
12768 do_vfp_nsyn_cvt (rs, flavour);
12769 return;
12770 }
12771
12772 switch (rs)
12773 {
12774 case NS_DDI:
12775 case NS_QQI:
12776 {
35997600
NC
12777 unsigned immbits;
12778 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12779
037e8744
JB
12780 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12781 return;
12782
12783 /* Fixed-point conversion with #0 immediate is encoded as an
12784 integer conversion. */
12785 if (inst.operands[2].present && inst.operands[2].imm == 0)
12786 goto int_encode;
35997600 12787 immbits = 32 - inst.operands[2].imm;
037e8744
JB
12788 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12789 if (flavour != -1)
12790 inst.instruction |= enctab[flavour];
12791 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12792 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12793 inst.instruction |= LOW4 (inst.operands[1].reg);
12794 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12795 inst.instruction |= neon_quad (rs) << 6;
12796 inst.instruction |= 1 << 21;
12797 inst.instruction |= immbits << 16;
12798
12799 inst.instruction = neon_dp_fixup (inst.instruction);
12800 }
12801 break;
12802
12803 case NS_DD:
12804 case NS_QQ:
12805 int_encode:
12806 {
12807 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12808
12809 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12810
12811 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12812 return;
12813
12814 if (flavour != -1)
12815 inst.instruction |= enctab[flavour];
12816
12817 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12818 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12819 inst.instruction |= LOW4 (inst.operands[1].reg);
12820 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12821 inst.instruction |= neon_quad (rs) << 6;
12822 inst.instruction |= 2 << 18;
12823
12824 inst.instruction = neon_dp_fixup (inst.instruction);
12825 }
12826 break;
12827
8e79c3df
CM
12828 /* Half-precision conversions for Advanced SIMD -- neon. */
12829 case NS_QD:
12830 case NS_DQ:
12831
12832 if ((rs == NS_DQ)
12833 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
12834 {
12835 as_bad (_("operand size must match register width"));
12836 break;
12837 }
12838
12839 if ((rs == NS_QD)
12840 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
12841 {
12842 as_bad (_("operand size must match register width"));
12843 break;
12844 }
12845
12846 if (rs == NS_DQ)
12847 inst.instruction = 0x3b60600;
12848 else
12849 inst.instruction = 0x3b60700;
12850
12851 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12852 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12853 inst.instruction |= LOW4 (inst.operands[1].reg);
12854 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12855 inst.instruction = neon_dp_fixup (inst.instruction);
12856 break;
12857
037e8744
JB
12858 default:
12859 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12860 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12861 }
5287ad62
JB
12862}
12863
8e79c3df
CM
12864static void
12865do_neon_cvtb (void)
12866{
12867 inst.instruction = 0xeb20a40;
12868
12869 /* The sizes are attached to the mnemonic. */
12870 if (inst.vectype.el[0].type != NT_invtype
12871 && inst.vectype.el[0].size == 16)
12872 inst.instruction |= 0x00010000;
12873
12874 /* Programmer's syntax: the sizes are attached to the operands. */
12875 else if (inst.operands[0].vectype.type != NT_invtype
12876 && inst.operands[0].vectype.size == 16)
12877 inst.instruction |= 0x00010000;
12878
12879 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
12880 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
12881 do_vfp_cond_or_thumb ();
12882}
12883
12884
12885static void
12886do_neon_cvtt (void)
12887{
12888 do_neon_cvtb ();
12889 inst.instruction |= 0x80;
12890}
12891
5287ad62
JB
12892static void
12893neon_move_immediate (void)
12894{
037e8744
JB
12895 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12896 struct neon_type_el et = neon_check_type (2, rs,
12897 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12898 unsigned immlo, immhi = 0, immbits;
c96612cc 12899 int op, cmode, float_p;
5287ad62 12900
037e8744
JB
12901 constraint (et.type == NT_invtype,
12902 _("operand size must be specified for immediate VMOV"));
12903
5287ad62
JB
12904 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12905 op = (inst.instruction & (1 << 5)) != 0;
12906
12907 immlo = inst.operands[1].imm;
12908 if (inst.operands[1].regisimm)
12909 immhi = inst.operands[1].reg;
12910
12911 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12912 _("immediate has bits set outside the operand size"));
12913
c96612cc
JB
12914 float_p = inst.operands[1].immisfloat;
12915
12916 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12917 et.size, et.type)) == FAIL)
5287ad62
JB
12918 {
12919 /* Invert relevant bits only. */
12920 neon_invert_size (&immlo, &immhi, et.size);
12921 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12922 with one or the other; those cases are caught by
12923 neon_cmode_for_move_imm. */
12924 op = !op;
c96612cc
JB
12925 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12926 &op, et.size, et.type)) == FAIL)
5287ad62 12927 {
dcbf9037 12928 first_error (_("immediate out of range"));
5287ad62
JB
12929 return;
12930 }
12931 }
12932
12933 inst.instruction &= ~(1 << 5);
12934 inst.instruction |= op << 5;
12935
12936 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12938 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12939 inst.instruction |= cmode << 8;
12940
12941 neon_write_immbits (immbits);
12942}
12943
12944static void
12945do_neon_mvn (void)
12946{
12947 if (inst.operands[1].isreg)
12948 {
037e8744 12949 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 12950
5287ad62
JB
12951 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12952 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12953 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12954 inst.instruction |= LOW4 (inst.operands[1].reg);
12955 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12956 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12957 }
12958 else
12959 {
12960 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12961 neon_move_immediate ();
12962 }
12963
12964 inst.instruction = neon_dp_fixup (inst.instruction);
12965}
12966
12967/* Encode instructions of form:
12968
12969 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 12970 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
12971
12972static void
12973neon_mixed_length (struct neon_type_el et, unsigned size)
12974{
12975 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12976 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12977 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12978 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12979 inst.instruction |= LOW4 (inst.operands[2].reg);
12980 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12981 inst.instruction |= (et.type == NT_unsigned) << 24;
12982 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12983
5287ad62
JB
12984 inst.instruction = neon_dp_fixup (inst.instruction);
12985}
12986
12987static void
12988do_neon_dyadic_long (void)
12989{
12990 /* FIXME: Type checking for lengthening op. */
12991 struct neon_type_el et = neon_check_type (3, NS_QDD,
12992 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12993 neon_mixed_length (et, et.size);
12994}
12995
12996static void
12997do_neon_abal (void)
12998{
12999 struct neon_type_el et = neon_check_type (3, NS_QDD,
13000 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13001 neon_mixed_length (et, et.size);
13002}
13003
13004static void
13005neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13006{
13007 if (inst.operands[2].isscalar)
13008 {
dcbf9037
JB
13009 struct neon_type_el et = neon_check_type (3, NS_QDS,
13010 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13011 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13012 neon_mul_mac (et, et.type == NT_unsigned);
13013 }
13014 else
13015 {
13016 struct neon_type_el et = neon_check_type (3, NS_QDD,
13017 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13018 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13019 neon_mixed_length (et, et.size);
13020 }
13021}
13022
13023static void
13024do_neon_mac_maybe_scalar_long (void)
13025{
13026 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13027}
13028
13029static void
13030do_neon_dyadic_wide (void)
13031{
13032 struct neon_type_el et = neon_check_type (3, NS_QQD,
13033 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13034 neon_mixed_length (et, et.size);
13035}
13036
13037static void
13038do_neon_dyadic_narrow (void)
13039{
13040 struct neon_type_el et = neon_check_type (3, NS_QDD,
13041 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13042 /* Operand sign is unimportant, and the U bit is part of the opcode,
13043 so force the operand type to integer. */
13044 et.type = NT_integer;
5287ad62
JB
13045 neon_mixed_length (et, et.size / 2);
13046}
13047
13048static void
13049do_neon_mul_sat_scalar_long (void)
13050{
13051 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13052}
13053
13054static void
13055do_neon_vmull (void)
13056{
13057 if (inst.operands[2].isscalar)
13058 do_neon_mac_maybe_scalar_long ();
13059 else
13060 {
13061 struct neon_type_el et = neon_check_type (3, NS_QDD,
13062 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13063 if (et.type == NT_poly)
13064 inst.instruction = NEON_ENC_POLY (inst.instruction);
13065 else
13066 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13067 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13068 zero. Should be OK as-is. */
13069 neon_mixed_length (et, et.size);
13070 }
13071}
13072
13073static void
13074do_neon_ext (void)
13075{
037e8744 13076 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13077 struct neon_type_el et = neon_check_type (3, rs,
13078 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13079 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13080
13081 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13082 _("shift out of range"));
5287ad62
JB
13083 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13084 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13085 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13086 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13087 inst.instruction |= LOW4 (inst.operands[2].reg);
13088 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13089 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13090 inst.instruction |= imm << 8;
5f4273c7 13091
5287ad62
JB
13092 inst.instruction = neon_dp_fixup (inst.instruction);
13093}
13094
13095static void
13096do_neon_rev (void)
13097{
037e8744 13098 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13099 struct neon_type_el et = neon_check_type (2, rs,
13100 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13101 unsigned op = (inst.instruction >> 7) & 3;
13102 /* N (width of reversed regions) is encoded as part of the bitmask. We
13103 extract it here to check the elements to be reversed are smaller.
13104 Otherwise we'd get a reserved instruction. */
13105 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13106 assert (elsize != 0);
13107 constraint (et.size >= elsize,
13108 _("elements must be smaller than reversal region"));
037e8744 13109 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13110}
13111
13112static void
13113do_neon_dup (void)
13114{
13115 if (inst.operands[1].isscalar)
13116 {
037e8744 13117 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13118 struct neon_type_el et = neon_check_type (2, rs,
13119 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13120 unsigned sizebits = et.size >> 3;
dcbf9037 13121 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13122 int logsize = neon_logbits (et.size);
dcbf9037 13123 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13124
13125 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13126 return;
13127
5287ad62
JB
13128 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13129 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13130 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13131 inst.instruction |= LOW4 (dm);
13132 inst.instruction |= HI1 (dm) << 5;
037e8744 13133 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13134 inst.instruction |= x << 17;
13135 inst.instruction |= sizebits << 16;
5f4273c7 13136
5287ad62
JB
13137 inst.instruction = neon_dp_fixup (inst.instruction);
13138 }
13139 else
13140 {
037e8744
JB
13141 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13142 struct neon_type_el et = neon_check_type (2, rs,
13143 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13144 /* Duplicate ARM register to lanes of vector. */
13145 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13146 switch (et.size)
13147 {
13148 case 8: inst.instruction |= 0x400000; break;
13149 case 16: inst.instruction |= 0x000020; break;
13150 case 32: inst.instruction |= 0x000000; break;
13151 default: break;
13152 }
13153 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13154 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13155 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13156 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13157 /* The encoding for this instruction is identical for the ARM and Thumb
13158 variants, except for the condition field. */
037e8744 13159 do_vfp_cond_or_thumb ();
5287ad62
JB
13160 }
13161}
13162
13163/* VMOV has particularly many variations. It can be one of:
13164 0. VMOV<c><q> <Qd>, <Qm>
13165 1. VMOV<c><q> <Dd>, <Dm>
13166 (Register operations, which are VORR with Rm = Rn.)
13167 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13168 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13169 (Immediate loads.)
13170 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13171 (ARM register to scalar.)
13172 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13173 (Two ARM registers to vector.)
13174 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13175 (Scalar to ARM register.)
13176 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13177 (Vector to two ARM registers.)
037e8744
JB
13178 8. VMOV.F32 <Sd>, <Sm>
13179 9. VMOV.F64 <Dd>, <Dm>
13180 (VFP register moves.)
13181 10. VMOV.F32 <Sd>, #imm
13182 11. VMOV.F64 <Dd>, #imm
13183 (VFP float immediate load.)
13184 12. VMOV <Rd>, <Sm>
13185 (VFP single to ARM reg.)
13186 13. VMOV <Sd>, <Rm>
13187 (ARM reg to VFP single.)
13188 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13189 (Two ARM regs to two VFP singles.)
13190 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13191 (Two VFP singles to two ARM regs.)
5f4273c7 13192
037e8744
JB
13193 These cases can be disambiguated using neon_select_shape, except cases 1/9
13194 and 3/11 which depend on the operand type too.
5f4273c7 13195
5287ad62 13196 All the encoded bits are hardcoded by this function.
5f4273c7 13197
b7fc2769
JB
13198 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13199 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13200
5287ad62 13201 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13202 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13203
13204static void
13205do_neon_mov (void)
13206{
037e8744
JB
13207 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13208 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13209 NS_NULL);
13210 struct neon_type_el et;
13211 const char *ldconst = 0;
5287ad62 13212
037e8744 13213 switch (rs)
5287ad62 13214 {
037e8744
JB
13215 case NS_DD: /* case 1/9. */
13216 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13217 /* It is not an error here if no type is given. */
13218 inst.error = NULL;
13219 if (et.type == NT_float && et.size == 64)
5287ad62 13220 {
037e8744
JB
13221 do_vfp_nsyn_opcode ("fcpyd");
13222 break;
5287ad62 13223 }
037e8744 13224 /* fall through. */
5287ad62 13225
037e8744
JB
13226 case NS_QQ: /* case 0/1. */
13227 {
13228 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13229 return;
13230 /* The architecture manual I have doesn't explicitly state which
13231 value the U bit should have for register->register moves, but
13232 the equivalent VORR instruction has U = 0, so do that. */
13233 inst.instruction = 0x0200110;
13234 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13235 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13236 inst.instruction |= LOW4 (inst.operands[1].reg);
13237 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13238 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13239 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13240 inst.instruction |= neon_quad (rs) << 6;
13241
13242 inst.instruction = neon_dp_fixup (inst.instruction);
13243 }
13244 break;
5f4273c7 13245
037e8744
JB
13246 case NS_DI: /* case 3/11. */
13247 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13248 inst.error = NULL;
13249 if (et.type == NT_float && et.size == 64)
5287ad62 13250 {
037e8744
JB
13251 /* case 11 (fconstd). */
13252 ldconst = "fconstd";
13253 goto encode_fconstd;
5287ad62 13254 }
037e8744
JB
13255 /* fall through. */
13256
13257 case NS_QI: /* case 2/3. */
13258 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13259 return;
13260 inst.instruction = 0x0800010;
13261 neon_move_immediate ();
13262 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13263 break;
5f4273c7 13264
037e8744
JB
13265 case NS_SR: /* case 4. */
13266 {
13267 unsigned bcdebits = 0;
13268 struct neon_type_el et = neon_check_type (2, NS_NULL,
13269 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13270 int logsize = neon_logbits (et.size);
13271 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13272 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13273
13274 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13275 _(BAD_FPU));
13276 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13277 && et.size != 32, _(BAD_FPU));
13278 constraint (et.type == NT_invtype, _("bad type for scalar"));
13279 constraint (x >= 64 / et.size, _("scalar index out of range"));
13280
13281 switch (et.size)
13282 {
13283 case 8: bcdebits = 0x8; break;
13284 case 16: bcdebits = 0x1; break;
13285 case 32: bcdebits = 0x0; break;
13286 default: ;
13287 }
13288
13289 bcdebits |= x << logsize;
13290
13291 inst.instruction = 0xe000b10;
13292 do_vfp_cond_or_thumb ();
13293 inst.instruction |= LOW4 (dn) << 16;
13294 inst.instruction |= HI1 (dn) << 7;
13295 inst.instruction |= inst.operands[1].reg << 12;
13296 inst.instruction |= (bcdebits & 3) << 5;
13297 inst.instruction |= (bcdebits >> 2) << 21;
13298 }
13299 break;
5f4273c7 13300
037e8744 13301 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13302 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13303 _(BAD_FPU));
b7fc2769 13304
037e8744
JB
13305 inst.instruction = 0xc400b10;
13306 do_vfp_cond_or_thumb ();
13307 inst.instruction |= LOW4 (inst.operands[0].reg);
13308 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13309 inst.instruction |= inst.operands[1].reg << 12;
13310 inst.instruction |= inst.operands[2].reg << 16;
13311 break;
5f4273c7 13312
037e8744
JB
13313 case NS_RS: /* case 6. */
13314 {
13315 struct neon_type_el et = neon_check_type (2, NS_NULL,
13316 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13317 unsigned logsize = neon_logbits (et.size);
13318 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13319 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13320 unsigned abcdebits = 0;
13321
13322 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13323 _(BAD_FPU));
13324 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13325 && et.size != 32, _(BAD_FPU));
13326 constraint (et.type == NT_invtype, _("bad type for scalar"));
13327 constraint (x >= 64 / et.size, _("scalar index out of range"));
13328
13329 switch (et.size)
13330 {
13331 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13332 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13333 case 32: abcdebits = 0x00; break;
13334 default: ;
13335 }
13336
13337 abcdebits |= x << logsize;
13338 inst.instruction = 0xe100b10;
13339 do_vfp_cond_or_thumb ();
13340 inst.instruction |= LOW4 (dn) << 16;
13341 inst.instruction |= HI1 (dn) << 7;
13342 inst.instruction |= inst.operands[0].reg << 12;
13343 inst.instruction |= (abcdebits & 3) << 5;
13344 inst.instruction |= (abcdebits >> 2) << 21;
13345 }
13346 break;
5f4273c7 13347
037e8744
JB
13348 case NS_RRD: /* case 7 (fmrrd). */
13349 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13350 _(BAD_FPU));
13351
13352 inst.instruction = 0xc500b10;
13353 do_vfp_cond_or_thumb ();
13354 inst.instruction |= inst.operands[0].reg << 12;
13355 inst.instruction |= inst.operands[1].reg << 16;
13356 inst.instruction |= LOW4 (inst.operands[2].reg);
13357 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13358 break;
5f4273c7 13359
037e8744
JB
13360 case NS_FF: /* case 8 (fcpys). */
13361 do_vfp_nsyn_opcode ("fcpys");
13362 break;
5f4273c7 13363
037e8744
JB
13364 case NS_FI: /* case 10 (fconsts). */
13365 ldconst = "fconsts";
13366 encode_fconstd:
13367 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13368 {
037e8744
JB
13369 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13370 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13371 }
13372 else
037e8744
JB
13373 first_error (_("immediate out of range"));
13374 break;
5f4273c7 13375
037e8744
JB
13376 case NS_RF: /* case 12 (fmrs). */
13377 do_vfp_nsyn_opcode ("fmrs");
13378 break;
5f4273c7 13379
037e8744
JB
13380 case NS_FR: /* case 13 (fmsr). */
13381 do_vfp_nsyn_opcode ("fmsr");
13382 break;
5f4273c7 13383
037e8744
JB
13384 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13385 (one of which is a list), but we have parsed four. Do some fiddling to
13386 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13387 expect. */
13388 case NS_RRFF: /* case 14 (fmrrs). */
13389 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13390 _("VFP registers must be adjacent"));
13391 inst.operands[2].imm = 2;
13392 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13393 do_vfp_nsyn_opcode ("fmrrs");
13394 break;
5f4273c7 13395
037e8744
JB
13396 case NS_FFRR: /* case 15 (fmsrr). */
13397 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13398 _("VFP registers must be adjacent"));
13399 inst.operands[1] = inst.operands[2];
13400 inst.operands[2] = inst.operands[3];
13401 inst.operands[0].imm = 2;
13402 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13403 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13404 break;
5f4273c7 13405
5287ad62
JB
13406 default:
13407 abort ();
13408 }
13409}
13410
13411static void
13412do_neon_rshift_round_imm (void)
13413{
037e8744 13414 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13415 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13416 int imm = inst.operands[2].imm;
13417
13418 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13419 if (imm == 0)
13420 {
13421 inst.operands[2].present = 0;
13422 do_neon_mov ();
13423 return;
13424 }
13425
13426 constraint (imm < 1 || (unsigned)imm > et.size,
13427 _("immediate out of range for shift"));
037e8744 13428 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13429 et.size - imm);
13430}
13431
13432static void
13433do_neon_movl (void)
13434{
13435 struct neon_type_el et = neon_check_type (2, NS_QD,
13436 N_EQK | N_DBL, N_SU_32 | N_KEY);
13437 unsigned sizebits = et.size >> 3;
13438 inst.instruction |= sizebits << 19;
13439 neon_two_same (0, et.type == NT_unsigned, -1);
13440}
13441
13442static void
13443do_neon_trn (void)
13444{
037e8744 13445 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13446 struct neon_type_el et = neon_check_type (2, rs,
13447 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13448 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13449 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13450}
13451
13452static void
13453do_neon_zip_uzp (void)
13454{
037e8744 13455 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13456 struct neon_type_el et = neon_check_type (2, rs,
13457 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13458 if (rs == NS_DD && et.size == 32)
13459 {
13460 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13461 inst.instruction = N_MNEM_vtrn;
13462 do_neon_trn ();
13463 return;
13464 }
037e8744 13465 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13466}
13467
13468static void
13469do_neon_sat_abs_neg (void)
13470{
037e8744 13471 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13472 struct neon_type_el et = neon_check_type (2, rs,
13473 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13474 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13475}
13476
13477static void
13478do_neon_pair_long (void)
13479{
037e8744 13480 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13481 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13482 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13483 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13484 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13485}
13486
13487static void
13488do_neon_recip_est (void)
13489{
037e8744 13490 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13491 struct neon_type_el et = neon_check_type (2, rs,
13492 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13493 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13494 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13495}
13496
13497static void
13498do_neon_cls (void)
13499{
037e8744 13500 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13501 struct neon_type_el et = neon_check_type (2, rs,
13502 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13503 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13504}
13505
13506static void
13507do_neon_clz (void)
13508{
037e8744 13509 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13510 struct neon_type_el et = neon_check_type (2, rs,
13511 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13512 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13513}
13514
13515static void
13516do_neon_cnt (void)
13517{
037e8744 13518 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13519 struct neon_type_el et = neon_check_type (2, rs,
13520 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13521 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13522}
13523
13524static void
13525do_neon_swp (void)
13526{
037e8744
JB
13527 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13528 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13529}
13530
13531static void
13532do_neon_tbl_tbx (void)
13533{
13534 unsigned listlenbits;
dcbf9037 13535 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13536
5287ad62
JB
13537 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13538 {
dcbf9037 13539 first_error (_("bad list length for table lookup"));
5287ad62
JB
13540 return;
13541 }
5f4273c7 13542
5287ad62
JB
13543 listlenbits = inst.operands[1].imm - 1;
13544 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13545 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13546 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13547 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13548 inst.instruction |= LOW4 (inst.operands[2].reg);
13549 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13550 inst.instruction |= listlenbits << 8;
5f4273c7 13551
5287ad62
JB
13552 inst.instruction = neon_dp_fixup (inst.instruction);
13553}
13554
13555static void
13556do_neon_ldm_stm (void)
13557{
13558 /* P, U and L bits are part of bitmask. */
13559 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13560 unsigned offsetbits = inst.operands[1].imm * 2;
13561
037e8744
JB
13562 if (inst.operands[1].issingle)
13563 {
13564 do_vfp_nsyn_ldm_stm (is_dbmode);
13565 return;
13566 }
13567
5287ad62
JB
13568 constraint (is_dbmode && !inst.operands[0].writeback,
13569 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13570
13571 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13572 _("register list must contain at least 1 and at most 16 "
13573 "registers"));
13574
13575 inst.instruction |= inst.operands[0].reg << 16;
13576 inst.instruction |= inst.operands[0].writeback << 21;
13577 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13578 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13579
13580 inst.instruction |= offsetbits;
5f4273c7 13581
037e8744 13582 do_vfp_cond_or_thumb ();
5287ad62
JB
13583}
13584
13585static void
13586do_neon_ldr_str (void)
13587{
5287ad62 13588 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13589
037e8744
JB
13590 if (inst.operands[0].issingle)
13591 {
cd2f129f
JB
13592 if (is_ldr)
13593 do_vfp_nsyn_opcode ("flds");
13594 else
13595 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13596 }
13597 else
5287ad62 13598 {
cd2f129f
JB
13599 if (is_ldr)
13600 do_vfp_nsyn_opcode ("fldd");
5287ad62 13601 else
cd2f129f 13602 do_vfp_nsyn_opcode ("fstd");
5287ad62 13603 }
5287ad62
JB
13604}
13605
13606/* "interleave" version also handles non-interleaving register VLD1/VST1
13607 instructions. */
13608
13609static void
13610do_neon_ld_st_interleave (void)
13611{
037e8744 13612 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13613 N_8 | N_16 | N_32 | N_64);
13614 unsigned alignbits = 0;
13615 unsigned idx;
13616 /* The bits in this table go:
13617 0: register stride of one (0) or two (1)
13618 1,2: register list length, minus one (1, 2, 3, 4).
13619 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13620 We use -1 for invalid entries. */
13621 const int typetable[] =
13622 {
13623 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13624 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13625 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13626 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13627 };
13628 int typebits;
13629
dcbf9037
JB
13630 if (et.type == NT_invtype)
13631 return;
13632
5287ad62
JB
13633 if (inst.operands[1].immisalign)
13634 switch (inst.operands[1].imm >> 8)
13635 {
13636 case 64: alignbits = 1; break;
13637 case 128:
13638 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13639 goto bad_alignment;
13640 alignbits = 2;
13641 break;
13642 case 256:
13643 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13644 goto bad_alignment;
13645 alignbits = 3;
13646 break;
13647 default:
13648 bad_alignment:
dcbf9037 13649 first_error (_("bad alignment"));
5287ad62
JB
13650 return;
13651 }
13652
13653 inst.instruction |= alignbits << 4;
13654 inst.instruction |= neon_logbits (et.size) << 6;
13655
13656 /* Bits [4:6] of the immediate in a list specifier encode register stride
13657 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13658 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13659 up the right value for "type" in a table based on this value and the given
13660 list style, then stick it back. */
13661 idx = ((inst.operands[0].imm >> 4) & 7)
13662 | (((inst.instruction >> 8) & 3) << 3);
13663
13664 typebits = typetable[idx];
5f4273c7 13665
5287ad62
JB
13666 constraint (typebits == -1, _("bad list type for instruction"));
13667
13668 inst.instruction &= ~0xf00;
13669 inst.instruction |= typebits << 8;
13670}
13671
13672/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13673 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13674 otherwise. The variable arguments are a list of pairs of legal (size, align)
13675 values, terminated with -1. */
13676
13677static int
13678neon_alignment_bit (int size, int align, int *do_align, ...)
13679{
13680 va_list ap;
13681 int result = FAIL, thissize, thisalign;
5f4273c7 13682
5287ad62
JB
13683 if (!inst.operands[1].immisalign)
13684 {
13685 *do_align = 0;
13686 return SUCCESS;
13687 }
5f4273c7 13688
5287ad62
JB
13689 va_start (ap, do_align);
13690
13691 do
13692 {
13693 thissize = va_arg (ap, int);
13694 if (thissize == -1)
13695 break;
13696 thisalign = va_arg (ap, int);
13697
13698 if (size == thissize && align == thisalign)
13699 result = SUCCESS;
13700 }
13701 while (result != SUCCESS);
13702
13703 va_end (ap);
13704
13705 if (result == SUCCESS)
13706 *do_align = 1;
13707 else
dcbf9037 13708 first_error (_("unsupported alignment for instruction"));
5f4273c7 13709
5287ad62
JB
13710 return result;
13711}
13712
13713static void
13714do_neon_ld_st_lane (void)
13715{
037e8744 13716 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13717 int align_good, do_align = 0;
13718 int logsize = neon_logbits (et.size);
13719 int align = inst.operands[1].imm >> 8;
13720 int n = (inst.instruction >> 8) & 3;
13721 int max_el = 64 / et.size;
5f4273c7 13722
dcbf9037
JB
13723 if (et.type == NT_invtype)
13724 return;
5f4273c7 13725
5287ad62
JB
13726 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13727 _("bad list length"));
13728 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13729 _("scalar index out of range"));
13730 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13731 && et.size == 8,
13732 _("stride of 2 unavailable when element size is 8"));
5f4273c7 13733
5287ad62
JB
13734 switch (n)
13735 {
13736 case 0: /* VLD1 / VST1. */
13737 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13738 32, 32, -1);
13739 if (align_good == FAIL)
13740 return;
13741 if (do_align)
13742 {
13743 unsigned alignbits = 0;
13744 switch (et.size)
13745 {
13746 case 16: alignbits = 0x1; break;
13747 case 32: alignbits = 0x3; break;
13748 default: ;
13749 }
13750 inst.instruction |= alignbits << 4;
13751 }
13752 break;
13753
13754 case 1: /* VLD2 / VST2. */
13755 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13756 32, 64, -1);
13757 if (align_good == FAIL)
13758 return;
13759 if (do_align)
13760 inst.instruction |= 1 << 4;
13761 break;
13762
13763 case 2: /* VLD3 / VST3. */
13764 constraint (inst.operands[1].immisalign,
13765 _("can't use alignment with this instruction"));
13766 break;
13767
13768 case 3: /* VLD4 / VST4. */
13769 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13770 16, 64, 32, 64, 32, 128, -1);
13771 if (align_good == FAIL)
13772 return;
13773 if (do_align)
13774 {
13775 unsigned alignbits = 0;
13776 switch (et.size)
13777 {
13778 case 8: alignbits = 0x1; break;
13779 case 16: alignbits = 0x1; break;
13780 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13781 default: ;
13782 }
13783 inst.instruction |= alignbits << 4;
13784 }
13785 break;
13786
13787 default: ;
13788 }
13789
13790 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13791 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13792 inst.instruction |= 1 << (4 + logsize);
5f4273c7 13793
5287ad62
JB
13794 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13795 inst.instruction |= logsize << 10;
13796}
13797
13798/* Encode single n-element structure to all lanes VLD<n> instructions. */
13799
13800static void
13801do_neon_ld_dup (void)
13802{
037e8744 13803 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13804 int align_good, do_align = 0;
13805
dcbf9037
JB
13806 if (et.type == NT_invtype)
13807 return;
13808
5287ad62
JB
13809 switch ((inst.instruction >> 8) & 3)
13810 {
13811 case 0: /* VLD1. */
13812 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13813 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13814 &do_align, 16, 16, 32, 32, -1);
13815 if (align_good == FAIL)
13816 return;
13817 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13818 {
13819 case 1: break;
13820 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13821 default: first_error (_("bad list length")); return;
5287ad62
JB
13822 }
13823 inst.instruction |= neon_logbits (et.size) << 6;
13824 break;
13825
13826 case 1: /* VLD2. */
13827 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13828 &do_align, 8, 16, 16, 32, 32, 64, -1);
13829 if (align_good == FAIL)
13830 return;
13831 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13832 _("bad list length"));
13833 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13834 inst.instruction |= 1 << 5;
13835 inst.instruction |= neon_logbits (et.size) << 6;
13836 break;
13837
13838 case 2: /* VLD3. */
13839 constraint (inst.operands[1].immisalign,
13840 _("can't use alignment with this instruction"));
13841 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13842 _("bad list length"));
13843 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13844 inst.instruction |= 1 << 5;
13845 inst.instruction |= neon_logbits (et.size) << 6;
13846 break;
13847
13848 case 3: /* VLD4. */
13849 {
13850 int align = inst.operands[1].imm >> 8;
13851 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13852 16, 64, 32, 64, 32, 128, -1);
13853 if (align_good == FAIL)
13854 return;
13855 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13856 _("bad list length"));
13857 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13858 inst.instruction |= 1 << 5;
13859 if (et.size == 32 && align == 128)
13860 inst.instruction |= 0x3 << 6;
13861 else
13862 inst.instruction |= neon_logbits (et.size) << 6;
13863 }
13864 break;
13865
13866 default: ;
13867 }
13868
13869 inst.instruction |= do_align << 4;
13870}
13871
13872/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13873 apart from bits [11:4]. */
13874
13875static void
13876do_neon_ldx_stx (void)
13877{
13878 switch (NEON_LANE (inst.operands[0].imm))
13879 {
13880 case NEON_INTERLEAVE_LANES:
13881 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13882 do_neon_ld_st_interleave ();
13883 break;
5f4273c7 13884
5287ad62
JB
13885 case NEON_ALL_LANES:
13886 inst.instruction = NEON_ENC_DUP (inst.instruction);
13887 do_neon_ld_dup ();
13888 break;
5f4273c7 13889
5287ad62
JB
13890 default:
13891 inst.instruction = NEON_ENC_LANE (inst.instruction);
13892 do_neon_ld_st_lane ();
13893 }
13894
13895 /* L bit comes from bit mask. */
13896 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13897 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13898 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 13899
5287ad62
JB
13900 if (inst.operands[1].postind)
13901 {
13902 int postreg = inst.operands[1].imm & 0xf;
13903 constraint (!inst.operands[1].immisreg,
13904 _("post-index must be a register"));
13905 constraint (postreg == 0xd || postreg == 0xf,
13906 _("bad register for post-index"));
13907 inst.instruction |= postreg;
13908 }
13909 else if (inst.operands[1].writeback)
13910 {
13911 inst.instruction |= 0xd;
13912 }
13913 else
5f4273c7
NC
13914 inst.instruction |= 0xf;
13915
5287ad62
JB
13916 if (thumb_mode)
13917 inst.instruction |= 0xf9000000;
13918 else
13919 inst.instruction |= 0xf4000000;
13920}
5287ad62
JB
13921\f
13922/* Overall per-instruction processing. */
13923
13924/* We need to be able to fix up arbitrary expressions in some statements.
13925 This is so that we can handle symbols that are an arbitrary distance from
13926 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13927 which returns part of an address in a form which will be valid for
13928 a data instruction. We do this by pushing the expression into a symbol
13929 in the expr_section, and creating a fix for that. */
13930
13931static void
13932fix_new_arm (fragS * frag,
13933 int where,
13934 short int size,
13935 expressionS * exp,
13936 int pc_rel,
13937 int reloc)
13938{
13939 fixS * new_fix;
13940
13941 switch (exp->X_op)
13942 {
13943 case O_constant:
13944 case O_symbol:
13945 case O_add:
13946 case O_subtract:
13947 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13948 break;
13949
13950 default:
13951 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13952 pc_rel, reloc);
13953 break;
13954 }
13955
13956 /* Mark whether the fix is to a THUMB instruction, or an ARM
13957 instruction. */
13958 new_fix->tc_fix_data = thumb_mode;
13959}
13960
13961/* Create a frg for an instruction requiring relaxation. */
13962static void
13963output_relax_insn (void)
13964{
13965 char * to;
13966 symbolS *sym;
0110f2b8
PB
13967 int offset;
13968
6e1cb1a6
PB
13969 /* The size of the instruction is unknown, so tie the debug info to the
13970 start of the instruction. */
13971 dwarf2_emit_insn (0);
6e1cb1a6 13972
0110f2b8
PB
13973 switch (inst.reloc.exp.X_op)
13974 {
13975 case O_symbol:
13976 sym = inst.reloc.exp.X_add_symbol;
13977 offset = inst.reloc.exp.X_add_number;
13978 break;
13979 case O_constant:
13980 sym = NULL;
13981 offset = inst.reloc.exp.X_add_number;
13982 break;
13983 default:
13984 sym = make_expr_symbol (&inst.reloc.exp);
13985 offset = 0;
13986 break;
13987 }
13988 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13989 inst.relax, sym, offset, NULL/*offset, opcode*/);
13990 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13991}
13992
13993/* Write a 32-bit thumb instruction to buf. */
13994static void
13995put_thumb32_insn (char * buf, unsigned long insn)
13996{
13997 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13998 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13999}
14000
b99bd4ef 14001static void
c19d1205 14002output_inst (const char * str)
b99bd4ef 14003{
c19d1205 14004 char * to = NULL;
b99bd4ef 14005
c19d1205 14006 if (inst.error)
b99bd4ef 14007 {
c19d1205 14008 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14009 return;
14010 }
5f4273c7
NC
14011 if (inst.relax)
14012 {
14013 output_relax_insn ();
0110f2b8 14014 return;
5f4273c7 14015 }
c19d1205
ZW
14016 if (inst.size == 0)
14017 return;
b99bd4ef 14018
c19d1205
ZW
14019 to = frag_more (inst.size);
14020
14021 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14022 {
c19d1205 14023 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14024 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14025 }
c19d1205 14026 else if (inst.size > INSN_SIZE)
b99bd4ef 14027 {
c19d1205
ZW
14028 assert (inst.size == (2 * INSN_SIZE));
14029 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14030 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14031 }
c19d1205
ZW
14032 else
14033 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14034
c19d1205
ZW
14035 if (inst.reloc.type != BFD_RELOC_UNUSED)
14036 fix_new_arm (frag_now, to - frag_now->fr_literal,
14037 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14038 inst.reloc.type);
b99bd4ef 14039
c19d1205 14040 dwarf2_emit_insn (inst.size);
c19d1205 14041}
b99bd4ef 14042
c19d1205
ZW
14043/* Tag values used in struct asm_opcode's tag field. */
14044enum opcode_tag
14045{
14046 OT_unconditional, /* Instruction cannot be conditionalized.
14047 The ARM condition field is still 0xE. */
14048 OT_unconditionalF, /* Instruction cannot be conditionalized
14049 and carries 0xF in its ARM condition field. */
14050 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14051 OT_csuffixF, /* Some forms of the instruction take a conditional
14052 suffix, others place 0xF where the condition field
14053 would be. */
c19d1205
ZW
14054 OT_cinfix3, /* Instruction takes a conditional infix,
14055 beginning at character index 3. (In
14056 unified mode, it becomes a suffix.) */
088fa78e
KH
14057 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14058 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14059 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14060 character index 3, even in unified mode. Used for
14061 legacy instructions where suffix and infix forms
14062 may be ambiguous. */
c19d1205 14063 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14064 suffix or an infix at character index 3. */
c19d1205
ZW
14065 OT_odd_infix_unc, /* This is the unconditional variant of an
14066 instruction that takes a conditional infix
14067 at an unusual position. In unified mode,
14068 this variant will accept a suffix. */
14069 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14070 are the conditional variants of instructions that
14071 take conditional infixes in unusual positions.
14072 The infix appears at character index
14073 (tag - OT_odd_infix_0). These are not accepted
14074 in unified mode. */
14075};
b99bd4ef 14076
c19d1205
ZW
14077/* Subroutine of md_assemble, responsible for looking up the primary
14078 opcode from the mnemonic the user wrote. STR points to the
14079 beginning of the mnemonic.
14080
14081 This is not simply a hash table lookup, because of conditional
14082 variants. Most instructions have conditional variants, which are
14083 expressed with a _conditional affix_ to the mnemonic. If we were
14084 to encode each conditional variant as a literal string in the opcode
14085 table, it would have approximately 20,000 entries.
14086
14087 Most mnemonics take this affix as a suffix, and in unified syntax,
14088 'most' is upgraded to 'all'. However, in the divided syntax, some
14089 instructions take the affix as an infix, notably the s-variants of
14090 the arithmetic instructions. Of those instructions, all but six
14091 have the infix appear after the third character of the mnemonic.
14092
14093 Accordingly, the algorithm for looking up primary opcodes given
14094 an identifier is:
14095
14096 1. Look up the identifier in the opcode table.
14097 If we find a match, go to step U.
14098
14099 2. Look up the last two characters of the identifier in the
14100 conditions table. If we find a match, look up the first N-2
14101 characters of the identifier in the opcode table. If we
14102 find a match, go to step CE.
14103
14104 3. Look up the fourth and fifth characters of the identifier in
14105 the conditions table. If we find a match, extract those
14106 characters from the identifier, and look up the remaining
14107 characters in the opcode table. If we find a match, go
14108 to step CM.
14109
14110 4. Fail.
14111
14112 U. Examine the tag field of the opcode structure, in case this is
14113 one of the six instructions with its conditional infix in an
14114 unusual place. If it is, the tag tells us where to find the
14115 infix; look it up in the conditions table and set inst.cond
14116 accordingly. Otherwise, this is an unconditional instruction.
14117 Again set inst.cond accordingly. Return the opcode structure.
14118
14119 CE. Examine the tag field to make sure this is an instruction that
14120 should receive a conditional suffix. If it is not, fail.
14121 Otherwise, set inst.cond from the suffix we already looked up,
14122 and return the opcode structure.
14123
14124 CM. Examine the tag field to make sure this is an instruction that
14125 should receive a conditional infix after the third character.
14126 If it is not, fail. Otherwise, undo the edits to the current
14127 line of input and proceed as for case CE. */
14128
14129static const struct asm_opcode *
14130opcode_lookup (char **str)
14131{
14132 char *end, *base;
14133 char *affix;
14134 const struct asm_opcode *opcode;
14135 const struct asm_cond *cond;
e3cb604e 14136 char save[2];
267d2029 14137 bfd_boolean neon_supported;
5f4273c7 14138
267d2029 14139 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14140
14141 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14142 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14143 for (base = end = *str; *end != '\0'; end++)
267d2029 14144 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14145 break;
b99bd4ef 14146
c19d1205
ZW
14147 if (end == base)
14148 return 0;
b99bd4ef 14149
5287ad62 14150 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14151 if (end[0] == '.')
b99bd4ef 14152 {
5287ad62 14153 int offset = 2;
5f4273c7 14154
267d2029
JB
14155 /* The .w and .n suffixes are only valid if the unified syntax is in
14156 use. */
14157 if (unified_syntax && end[1] == 'w')
c19d1205 14158 inst.size_req = 4;
267d2029 14159 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14160 inst.size_req = 2;
14161 else
5287ad62
JB
14162 offset = 0;
14163
14164 inst.vectype.elems = 0;
14165
14166 *str = end + offset;
b99bd4ef 14167
5f4273c7 14168 if (end[offset] == '.')
5287ad62 14169 {
267d2029
JB
14170 /* See if we have a Neon type suffix (possible in either unified or
14171 non-unified ARM syntax mode). */
dcbf9037 14172 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14173 return 0;
14174 }
14175 else if (end[offset] != '\0' && end[offset] != ' ')
14176 return 0;
b99bd4ef 14177 }
c19d1205
ZW
14178 else
14179 *str = end;
b99bd4ef 14180
c19d1205
ZW
14181 /* Look for unaffixed or special-case affixed mnemonic. */
14182 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14183 if (opcode)
b99bd4ef 14184 {
c19d1205
ZW
14185 /* step U */
14186 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14187 {
c19d1205
ZW
14188 inst.cond = COND_ALWAYS;
14189 return opcode;
b99bd4ef 14190 }
b99bd4ef 14191
278df34e 14192 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
14193 as_warn (_("conditional infixes are deprecated in unified syntax"));
14194 affix = base + (opcode->tag - OT_odd_infix_0);
14195 cond = hash_find_n (arm_cond_hsh, affix, 2);
14196 assert (cond);
b99bd4ef 14197
c19d1205
ZW
14198 inst.cond = cond->value;
14199 return opcode;
14200 }
b99bd4ef 14201
c19d1205
ZW
14202 /* Cannot have a conditional suffix on a mnemonic of less than two
14203 characters. */
14204 if (end - base < 3)
14205 return 0;
b99bd4ef 14206
c19d1205
ZW
14207 /* Look for suffixed mnemonic. */
14208 affix = end - 2;
14209 cond = hash_find_n (arm_cond_hsh, affix, 2);
14210 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14211 if (opcode && cond)
14212 {
14213 /* step CE */
14214 switch (opcode->tag)
14215 {
e3cb604e
PB
14216 case OT_cinfix3_legacy:
14217 /* Ignore conditional suffixes matched on infix only mnemonics. */
14218 break;
14219
c19d1205 14220 case OT_cinfix3:
088fa78e 14221 case OT_cinfix3_deprecated:
c19d1205
ZW
14222 case OT_odd_infix_unc:
14223 if (!unified_syntax)
e3cb604e 14224 return 0;
c19d1205
ZW
14225 /* else fall through */
14226
14227 case OT_csuffix:
037e8744 14228 case OT_csuffixF:
c19d1205
ZW
14229 case OT_csuf_or_in3:
14230 inst.cond = cond->value;
14231 return opcode;
14232
14233 case OT_unconditional:
14234 case OT_unconditionalF:
dfa9f0d5
PB
14235 if (thumb_mode)
14236 {
14237 inst.cond = cond->value;
14238 }
14239 else
14240 {
14241 /* delayed diagnostic */
14242 inst.error = BAD_COND;
14243 inst.cond = COND_ALWAYS;
14244 }
c19d1205 14245 return opcode;
b99bd4ef 14246
c19d1205
ZW
14247 default:
14248 return 0;
14249 }
14250 }
b99bd4ef 14251
c19d1205
ZW
14252 /* Cannot have a usual-position infix on a mnemonic of less than
14253 six characters (five would be a suffix). */
14254 if (end - base < 6)
14255 return 0;
b99bd4ef 14256
c19d1205
ZW
14257 /* Look for infixed mnemonic in the usual position. */
14258 affix = base + 3;
14259 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14260 if (!cond)
14261 return 0;
14262
14263 memcpy (save, affix, 2);
14264 memmove (affix, affix + 2, (end - affix) - 2);
14265 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14266 memmove (affix + 2, affix, (end - affix) - 2);
14267 memcpy (affix, save, 2);
14268
088fa78e
KH
14269 if (opcode
14270 && (opcode->tag == OT_cinfix3
14271 || opcode->tag == OT_cinfix3_deprecated
14272 || opcode->tag == OT_csuf_or_in3
14273 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14274 {
c19d1205 14275 /* step CM */
278df34e 14276 if (warn_on_deprecated && unified_syntax
088fa78e
KH
14277 && (opcode->tag == OT_cinfix3
14278 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14279 as_warn (_("conditional infixes are deprecated in unified syntax"));
14280
14281 inst.cond = cond->value;
14282 return opcode;
b99bd4ef
NC
14283 }
14284
c19d1205 14285 return 0;
b99bd4ef
NC
14286}
14287
c19d1205
ZW
14288void
14289md_assemble (char *str)
b99bd4ef 14290{
c19d1205
ZW
14291 char *p = str;
14292 const struct asm_opcode * opcode;
b99bd4ef 14293
c19d1205
ZW
14294 /* Align the previous label if needed. */
14295 if (last_label_seen != NULL)
b99bd4ef 14296 {
c19d1205
ZW
14297 symbol_set_frag (last_label_seen, frag_now);
14298 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14299 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14300 }
14301
c19d1205
ZW
14302 memset (&inst, '\0', sizeof (inst));
14303 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14304
c19d1205
ZW
14305 opcode = opcode_lookup (&p);
14306 if (!opcode)
b99bd4ef 14307 {
c19d1205 14308 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14309 the form alias .req reg, or a Neon .dn/.qn directive. */
14310 if (!create_register_alias (str, p)
14311 && !create_neon_reg_alias (str, p))
c19d1205 14312 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14313
b99bd4ef
NC
14314 return;
14315 }
14316
278df34e 14317 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
14318 as_warn (_("s suffix on comparison instruction is deprecated"));
14319
037e8744
JB
14320 /* The value which unconditional instructions should have in place of the
14321 condition field. */
14322 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14323
c19d1205 14324 if (thumb_mode)
b99bd4ef 14325 {
e74cfd16 14326 arm_feature_set variant;
8f06b2d8
PB
14327
14328 variant = cpu_variant;
14329 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14330 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14331 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14332 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14333 if (!opcode->tvariant
14334 || (thumb_mode == 1
14335 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14336 {
c19d1205 14337 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14338 return;
14339 }
c19d1205
ZW
14340 if (inst.cond != COND_ALWAYS && !unified_syntax
14341 && opcode->tencode != do_t_branch)
b99bd4ef 14342 {
c19d1205 14343 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14344 return;
14345 }
14346
076d447c
PB
14347 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14348 {
14349 /* Implicit require narrow instructions on Thumb-1. This avoids
14350 relaxation accidentally introducing Thumb-2 instructions. */
7e806470
PB
14351 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
14352 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
076d447c
PB
14353 inst.size_req = 2;
14354 }
14355
e27ec89e
PB
14356 /* Check conditional suffixes. */
14357 if (current_it_mask)
14358 {
14359 int cond;
14360 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14361 current_it_mask <<= 1;
14362 current_it_mask &= 0x1f;
14363 /* The BKPT instruction is unconditional even in an IT block. */
14364 if (!inst.error
14365 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14366 {
14367 as_bad (_("incorrect condition in IT block"));
14368 return;
14369 }
e27ec89e
PB
14370 }
14371 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14372 {
6decc662 14373 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14374 return;
14375 }
14376
c19d1205
ZW
14377 mapping_state (MAP_THUMB);
14378 inst.instruction = opcode->tvalue;
14379
14380 if (!parse_operands (p, opcode->operands))
14381 opcode->tencode ();
14382
e27ec89e
PB
14383 /* Clear current_it_mask at the end of an IT block. */
14384 if (current_it_mask == 0x10)
14385 current_it_mask = 0;
14386
0110f2b8 14387 if (!(inst.error || inst.relax))
b99bd4ef 14388 {
c19d1205
ZW
14389 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14390 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14391 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14392 {
c19d1205 14393 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14394 return;
14395 }
14396 }
076d447c
PB
14397
14398 /* Something has gone badly wrong if we try to relax a fixed size
14399 instruction. */
14400 assert (inst.size_req == 0 || !inst.relax);
14401
e74cfd16
PB
14402 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14403 *opcode->tvariant);
ee065d83 14404 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14405 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14406 anything other than bl/blx and v6-M instructions.
ee065d83 14407 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14408 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14409 || inst.relax)
14410 && !ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr))
e74cfd16
PB
14411 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14412 arm_ext_v6t2);
c19d1205 14413 }
3e9e4fcf 14414 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14415 {
845b51d6
PB
14416 bfd_boolean is_bx;
14417
14418 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14419 is_bx = (opcode->aencode == do_bx);
14420
c19d1205 14421 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14422 if (!(is_bx && fix_v4bx)
14423 && !(opcode->avariant &&
14424 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14425 {
c19d1205
ZW
14426 as_bad (_("selected processor does not support `%s'"), str);
14427 return;
b99bd4ef 14428 }
c19d1205 14429 if (inst.size_req)
b99bd4ef 14430 {
c19d1205
ZW
14431 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14432 return;
b99bd4ef
NC
14433 }
14434
c19d1205
ZW
14435 mapping_state (MAP_ARM);
14436 inst.instruction = opcode->avalue;
14437 if (opcode->tag == OT_unconditionalF)
14438 inst.instruction |= 0xF << 28;
14439 else
14440 inst.instruction |= inst.cond << 28;
14441 inst.size = INSN_SIZE;
14442 if (!parse_operands (p, opcode->operands))
14443 opcode->aencode ();
ee065d83
PB
14444 /* Arm mode bx is marked as both v4T and v5 because it's still required
14445 on a hypothetical non-thumb v5 core. */
845b51d6 14446 if (is_bx)
e74cfd16 14447 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14448 else
e74cfd16
PB
14449 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14450 *opcode->avariant);
b99bd4ef 14451 }
3e9e4fcf
JB
14452 else
14453 {
14454 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14455 "-- `%s'"), str);
14456 return;
14457 }
c19d1205
ZW
14458 output_inst (str);
14459}
b99bd4ef 14460
c19d1205
ZW
14461/* Various frobbings of labels and their addresses. */
14462
14463void
14464arm_start_line_hook (void)
14465{
14466 last_label_seen = NULL;
b99bd4ef
NC
14467}
14468
c19d1205
ZW
14469void
14470arm_frob_label (symbolS * sym)
b99bd4ef 14471{
c19d1205 14472 last_label_seen = sym;
b99bd4ef 14473
c19d1205 14474 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14475
c19d1205
ZW
14476#if defined OBJ_COFF || defined OBJ_ELF
14477 ARM_SET_INTERWORK (sym, support_interwork);
14478#endif
b99bd4ef 14479
5f4273c7 14480 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14481 as Thumb functions. This is because these labels, whilst
14482 they exist inside Thumb code, are not the entry points for
14483 possible ARM->Thumb calls. Also, these labels can be used
14484 as part of a computed goto or switch statement. eg gcc
14485 can generate code that looks like this:
b99bd4ef 14486
c19d1205
ZW
14487 ldr r2, [pc, .Laaa]
14488 lsl r3, r3, #2
14489 ldr r2, [r3, r2]
14490 mov pc, r2
b99bd4ef 14491
c19d1205
ZW
14492 .Lbbb: .word .Lxxx
14493 .Lccc: .word .Lyyy
14494 ..etc...
14495 .Laaa: .word Lbbb
b99bd4ef 14496
c19d1205
ZW
14497 The first instruction loads the address of the jump table.
14498 The second instruction converts a table index into a byte offset.
14499 The third instruction gets the jump address out of the table.
14500 The fourth instruction performs the jump.
b99bd4ef 14501
c19d1205
ZW
14502 If the address stored at .Laaa is that of a symbol which has the
14503 Thumb_Func bit set, then the linker will arrange for this address
14504 to have the bottom bit set, which in turn would mean that the
14505 address computation performed by the third instruction would end
14506 up with the bottom bit set. Since the ARM is capable of unaligned
14507 word loads, the instruction would then load the incorrect address
14508 out of the jump table, and chaos would ensue. */
14509 if (label_is_thumb_function_name
14510 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14511 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14512 {
c19d1205
ZW
14513 /* When the address of a Thumb function is taken the bottom
14514 bit of that address should be set. This will allow
14515 interworking between Arm and Thumb functions to work
14516 correctly. */
b99bd4ef 14517
c19d1205 14518 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14519
c19d1205 14520 label_is_thumb_function_name = FALSE;
b99bd4ef 14521 }
07a53e5c 14522
07a53e5c 14523 dwarf2_emit_label (sym);
b99bd4ef
NC
14524}
14525
c19d1205
ZW
14526int
14527arm_data_in_code (void)
b99bd4ef 14528{
c19d1205 14529 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14530 {
c19d1205
ZW
14531 *input_line_pointer = '/';
14532 input_line_pointer += 5;
14533 *input_line_pointer = 0;
14534 return 1;
b99bd4ef
NC
14535 }
14536
c19d1205 14537 return 0;
b99bd4ef
NC
14538}
14539
c19d1205
ZW
14540char *
14541arm_canonicalize_symbol_name (char * name)
b99bd4ef 14542{
c19d1205 14543 int len;
b99bd4ef 14544
c19d1205
ZW
14545 if (thumb_mode && (len = strlen (name)) > 5
14546 && streq (name + len - 5, "/data"))
14547 *(name + len - 5) = 0;
b99bd4ef 14548
c19d1205 14549 return name;
b99bd4ef 14550}
c19d1205
ZW
14551\f
14552/* Table of all register names defined by default. The user can
14553 define additional names with .req. Note that all register names
14554 should appear in both upper and lowercase variants. Some registers
14555 also have mixed-case names. */
b99bd4ef 14556
dcbf9037 14557#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14558#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14559#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14560#define REGSET(p,t) \
14561 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14562 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14563 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14564 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14565#define REGSETH(p,t) \
14566 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14567 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14568 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14569 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14570#define REGSET2(p,t) \
14571 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14572 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14573 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14574 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14575
c19d1205 14576static const struct reg_entry reg_names[] =
7ed4c4c5 14577{
c19d1205
ZW
14578 /* ARM integer registers. */
14579 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14580
c19d1205
ZW
14581 /* ATPCS synonyms. */
14582 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14583 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14584 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14585
c19d1205
ZW
14586 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14587 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14588 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14589
c19d1205
ZW
14590 /* Well-known aliases. */
14591 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14592 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14593
14594 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14595 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14596
14597 /* Coprocessor numbers. */
14598 REGSET(p, CP), REGSET(P, CP),
14599
14600 /* Coprocessor register numbers. The "cr" variants are for backward
14601 compatibility. */
14602 REGSET(c, CN), REGSET(C, CN),
14603 REGSET(cr, CN), REGSET(CR, CN),
14604
14605 /* FPA registers. */
14606 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14607 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14608
14609 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14610 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14611
14612 /* VFP SP registers. */
5287ad62
JB
14613 REGSET(s,VFS), REGSET(S,VFS),
14614 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14615
14616 /* VFP DP Registers. */
5287ad62
JB
14617 REGSET(d,VFD), REGSET(D,VFD),
14618 /* Extra Neon DP registers. */
14619 REGSETH(d,VFD), REGSETH(D,VFD),
14620
14621 /* Neon QP registers. */
14622 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14623
14624 /* VFP control registers. */
14625 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14626 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14627 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14628 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14629 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14630 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14631
14632 /* Maverick DSP coprocessor registers. */
14633 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14634 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14635
14636 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14637 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14638 REGDEF(dspsc,0,DSPSC),
14639
14640 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14641 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14642 REGDEF(DSPSC,0,DSPSC),
14643
14644 /* iWMMXt data registers - p0, c0-15. */
14645 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14646
14647 /* iWMMXt control registers - p1, c0-3. */
14648 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14649 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14650 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14651 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14652
14653 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14654 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14655 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14656 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14657 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14658
14659 /* XScale accumulator registers. */
14660 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14661};
14662#undef REGDEF
14663#undef REGNUM
14664#undef REGSET
7ed4c4c5 14665
c19d1205
ZW
14666/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14667 within psr_required_here. */
14668static const struct asm_psr psrs[] =
14669{
14670 /* Backward compatibility notation. Note that "all" is no longer
14671 truly all possible PSR bits. */
14672 {"all", PSR_c | PSR_f},
14673 {"flg", PSR_f},
14674 {"ctl", PSR_c},
14675
14676 /* Individual flags. */
14677 {"f", PSR_f},
14678 {"c", PSR_c},
14679 {"x", PSR_x},
14680 {"s", PSR_s},
14681 /* Combinations of flags. */
14682 {"fs", PSR_f | PSR_s},
14683 {"fx", PSR_f | PSR_x},
14684 {"fc", PSR_f | PSR_c},
14685 {"sf", PSR_s | PSR_f},
14686 {"sx", PSR_s | PSR_x},
14687 {"sc", PSR_s | PSR_c},
14688 {"xf", PSR_x | PSR_f},
14689 {"xs", PSR_x | PSR_s},
14690 {"xc", PSR_x | PSR_c},
14691 {"cf", PSR_c | PSR_f},
14692 {"cs", PSR_c | PSR_s},
14693 {"cx", PSR_c | PSR_x},
14694 {"fsx", PSR_f | PSR_s | PSR_x},
14695 {"fsc", PSR_f | PSR_s | PSR_c},
14696 {"fxs", PSR_f | PSR_x | PSR_s},
14697 {"fxc", PSR_f | PSR_x | PSR_c},
14698 {"fcs", PSR_f | PSR_c | PSR_s},
14699 {"fcx", PSR_f | PSR_c | PSR_x},
14700 {"sfx", PSR_s | PSR_f | PSR_x},
14701 {"sfc", PSR_s | PSR_f | PSR_c},
14702 {"sxf", PSR_s | PSR_x | PSR_f},
14703 {"sxc", PSR_s | PSR_x | PSR_c},
14704 {"scf", PSR_s | PSR_c | PSR_f},
14705 {"scx", PSR_s | PSR_c | PSR_x},
14706 {"xfs", PSR_x | PSR_f | PSR_s},
14707 {"xfc", PSR_x | PSR_f | PSR_c},
14708 {"xsf", PSR_x | PSR_s | PSR_f},
14709 {"xsc", PSR_x | PSR_s | PSR_c},
14710 {"xcf", PSR_x | PSR_c | PSR_f},
14711 {"xcs", PSR_x | PSR_c | PSR_s},
14712 {"cfs", PSR_c | PSR_f | PSR_s},
14713 {"cfx", PSR_c | PSR_f | PSR_x},
14714 {"csf", PSR_c | PSR_s | PSR_f},
14715 {"csx", PSR_c | PSR_s | PSR_x},
14716 {"cxf", PSR_c | PSR_x | PSR_f},
14717 {"cxs", PSR_c | PSR_x | PSR_s},
14718 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14719 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14720 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14721 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14722 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14723 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14724 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14725 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14726 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14727 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14728 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14729 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14730 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14731 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14732 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14733 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14734 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14735 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14736 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14737 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14738 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14739 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14740 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14741 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14742};
14743
62b3e311
PB
14744/* Table of V7M psr names. */
14745static const struct asm_psr v7m_psrs[] =
14746{
2b744c99
PB
14747 {"apsr", 0 }, {"APSR", 0 },
14748 {"iapsr", 1 }, {"IAPSR", 1 },
14749 {"eapsr", 2 }, {"EAPSR", 2 },
14750 {"psr", 3 }, {"PSR", 3 },
14751 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14752 {"ipsr", 5 }, {"IPSR", 5 },
14753 {"epsr", 6 }, {"EPSR", 6 },
14754 {"iepsr", 7 }, {"IEPSR", 7 },
14755 {"msp", 8 }, {"MSP", 8 },
14756 {"psp", 9 }, {"PSP", 9 },
14757 {"primask", 16}, {"PRIMASK", 16},
14758 {"basepri", 17}, {"BASEPRI", 17},
14759 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14760 {"faultmask", 19}, {"FAULTMASK", 19},
14761 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14762};
14763
c19d1205
ZW
14764/* Table of all shift-in-operand names. */
14765static const struct asm_shift_name shift_names [] =
b99bd4ef 14766{
c19d1205
ZW
14767 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14768 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14769 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14770 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14771 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14772 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14773};
b99bd4ef 14774
c19d1205
ZW
14775/* Table of all explicit relocation names. */
14776#ifdef OBJ_ELF
14777static struct reloc_entry reloc_names[] =
14778{
14779 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14780 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14781 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14782 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14783 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14784 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14785 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14786 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14787 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14788 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14789 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14790};
14791#endif
b99bd4ef 14792
c19d1205
ZW
14793/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14794static const struct asm_cond conds[] =
14795{
14796 {"eq", 0x0},
14797 {"ne", 0x1},
14798 {"cs", 0x2}, {"hs", 0x2},
14799 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14800 {"mi", 0x4},
14801 {"pl", 0x5},
14802 {"vs", 0x6},
14803 {"vc", 0x7},
14804 {"hi", 0x8},
14805 {"ls", 0x9},
14806 {"ge", 0xa},
14807 {"lt", 0xb},
14808 {"gt", 0xc},
14809 {"le", 0xd},
14810 {"al", 0xe}
14811};
bfae80f2 14812
62b3e311
PB
14813static struct asm_barrier_opt barrier_opt_names[] =
14814{
14815 { "sy", 0xf },
14816 { "un", 0x7 },
14817 { "st", 0xe },
14818 { "unst", 0x6 }
14819};
14820
c19d1205
ZW
14821/* Table of ARM-format instructions. */
14822
14823/* Macros for gluing together operand strings. N.B. In all cases
14824 other than OPS0, the trailing OP_stop comes from default
14825 zero-initialization of the unspecified elements of the array. */
14826#define OPS0() { OP_stop, }
14827#define OPS1(a) { OP_##a, }
14828#define OPS2(a,b) { OP_##a,OP_##b, }
14829#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14830#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14831#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14832#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14833
14834/* These macros abstract out the exact format of the mnemonic table and
14835 save some repeated characters. */
14836
14837/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14838#define TxCE(mnem, op, top, nops, ops, ae, te) \
14839 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14840 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14841
14842/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14843 a T_MNEM_xyz enumerator. */
14844#define TCE(mnem, aop, top, nops, ops, ae, te) \
14845 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14846#define tCE(mnem, aop, top, nops, ops, ae, te) \
14847 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14848
14849/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14850 infix after the third character. */
14851#define TxC3(mnem, op, top, nops, ops, ae, te) \
14852 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14853 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14854#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14855 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14856 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14857#define TC3(mnem, aop, top, nops, ops, ae, te) \
14858 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14859#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14860 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14861#define tC3(mnem, aop, top, nops, ops, ae, te) \
14862 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14863#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14864 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14865
14866/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14867 appear in the condition table. */
14868#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14869 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14870 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14871
14872#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14873 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14874 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14875 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14876 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14877 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14878 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14879 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14880 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14881 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14882 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14883 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14884 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14885 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14886 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14887 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14888 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14889 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14890 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14891 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14892
14893#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14894 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14895#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14896 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14897
14898/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14899 field is still 0xE. Many of the Thumb variants can be executed
14900 conditionally, so this is checked separately. */
c19d1205
ZW
14901#define TUE(mnem, op, top, nops, ops, ae, te) \
14902 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14903 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14904
14905/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14906 condition code field. */
14907#define TUF(mnem, op, top, nops, ops, ae, te) \
14908 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14909 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14910
14911/* ARM-only variants of all the above. */
6a86118a
NC
14912#define CE(mnem, op, nops, ops, ae) \
14913 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14914
14915#define C3(mnem, op, nops, ops, ae) \
14916 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14917
e3cb604e
PB
14918/* Legacy mnemonics that always have conditional infix after the third
14919 character. */
14920#define CL(mnem, op, nops, ops, ae) \
14921 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14922 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14923
8f06b2d8
PB
14924/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14925#define cCE(mnem, op, nops, ops, ae) \
14926 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14927
e3cb604e
PB
14928/* Legacy coprocessor instructions where conditional infix and conditional
14929 suffix are ambiguous. For consistency this includes all FPA instructions,
14930 not just the potentially ambiguous ones. */
14931#define cCL(mnem, op, nops, ops, ae) \
14932 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14933 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14934
14935/* Coprocessor, takes either a suffix or a position-3 infix
14936 (for an FPA corner case). */
14937#define C3E(mnem, op, nops, ops, ae) \
14938 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14939 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14940
6a86118a
NC
14941#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14942 { #m1 #m2 #m3, OPS##nops ops, \
14943 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14944 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14945
14946#define CM(m1, m2, op, nops, ops, ae) \
14947 xCM_(m1, , m2, op, nops, ops, ae), \
14948 xCM_(m1, eq, m2, op, nops, ops, ae), \
14949 xCM_(m1, ne, m2, op, nops, ops, ae), \
14950 xCM_(m1, cs, m2, op, nops, ops, ae), \
14951 xCM_(m1, hs, m2, op, nops, ops, ae), \
14952 xCM_(m1, cc, m2, op, nops, ops, ae), \
14953 xCM_(m1, ul, m2, op, nops, ops, ae), \
14954 xCM_(m1, lo, m2, op, nops, ops, ae), \
14955 xCM_(m1, mi, m2, op, nops, ops, ae), \
14956 xCM_(m1, pl, m2, op, nops, ops, ae), \
14957 xCM_(m1, vs, m2, op, nops, ops, ae), \
14958 xCM_(m1, vc, m2, op, nops, ops, ae), \
14959 xCM_(m1, hi, m2, op, nops, ops, ae), \
14960 xCM_(m1, ls, m2, op, nops, ops, ae), \
14961 xCM_(m1, ge, m2, op, nops, ops, ae), \
14962 xCM_(m1, lt, m2, op, nops, ops, ae), \
14963 xCM_(m1, gt, m2, op, nops, ops, ae), \
14964 xCM_(m1, le, m2, op, nops, ops, ae), \
14965 xCM_(m1, al, m2, op, nops, ops, ae)
14966
14967#define UE(mnem, op, nops, ops, ae) \
14968 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14969
14970#define UF(mnem, op, nops, ops, ae) \
14971 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14972
5287ad62
JB
14973/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14974 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14975 use the same encoding function for each. */
14976#define NUF(mnem, op, nops, ops, enc) \
14977 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14978 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14979
14980/* Neon data processing, version which indirects through neon_enc_tab for
14981 the various overloaded versions of opcodes. */
14982#define nUF(mnem, op, nops, ops, enc) \
14983 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14984 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14985
14986/* Neon insn with conditional suffix for the ARM version, non-overloaded
14987 version. */
037e8744
JB
14988#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14989 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14990 THUMB_VARIANT, do_##enc, do_##enc }
14991
037e8744
JB
14992#define NCE(mnem, op, nops, ops, enc) \
14993 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14994
14995#define NCEF(mnem, op, nops, ops, enc) \
14996 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14997
5287ad62 14998/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14999#define nCE_tag(mnem, op, nops, ops, enc, tag) \
15000 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
15001 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15002
037e8744
JB
15003#define nCE(mnem, op, nops, ops, enc) \
15004 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15005
15006#define nCEF(mnem, op, nops, ops, enc) \
15007 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15008
c19d1205
ZW
15009#define do_0 0
15010
15011/* Thumb-only, unconditional. */
15012#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
15013
c19d1205 15014static const struct asm_opcode insns[] =
bfae80f2 15015{
e74cfd16
PB
15016#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15017#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15018 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15019 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15020 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15021 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15022 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15023 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
15024 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15025 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
15026 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15027 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15028 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15029 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15030 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15031 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15032 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15033 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15034
15035 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15036 for setting PSR flag bits. They are obsolete in V6 and do not
15037 have Thumb equivalents. */
15038 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15039 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15040 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 15041 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 15042 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 15043 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 15044 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15045 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15046 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
15047
15048 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15049 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15050 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15051 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15052
4962c51a
MS
15053 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15054 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15055 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15056 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 15057
f5208ef2 15058 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15059 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15060 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 15061 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15062 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15063 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15064
15065 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 15066 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 15067 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 15068 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 15069
c19d1205 15070 /* Pseudo ops. */
e9f89963 15071 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
15072 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15073 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
15074
15075 /* Thumb-compatibility pseudo ops. */
15076 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15077 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15078 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15079 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15080 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 15081 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
15082 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15083 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15084 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15085 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15086 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15087 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15088
16a4cf17
PB
15089 /* These may simplify to neg. */
15090 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15091 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15092
c19d1205 15093#undef THUMB_VARIANT
e74cfd16 15094#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 15095 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
15096
15097 /* V1 instructions with no Thumb analogue prior to V6T2. */
15098#undef THUMB_VARIANT
e74cfd16 15099#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15100 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15101 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15102 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
15103
15104 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15105 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15106 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15107 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15108
9c3c69f2
PB
15109 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15110 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 15111
9c3c69f2
PB
15112 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15113 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15114
15115 /* V1 instructions with no Thumb analogue at all. */
15116 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15117 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15118
15119 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15120 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15121 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15122 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15123 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15124 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15125 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15126 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15127
15128#undef ARM_VARIANT
e74cfd16 15129#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15130#undef THUMB_VARIANT
e74cfd16 15131#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15132 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15133 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15134
15135#undef THUMB_VARIANT
e74cfd16 15136#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15137 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15138 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15139
15140 /* Generic coprocessor instructions. */
15141 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15142 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15143 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15144 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15145 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15146 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15147 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15148
15149#undef ARM_VARIANT
e74cfd16 15150#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15151 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15152 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15153
15154#undef ARM_VARIANT
e74cfd16 15155#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15156#undef THUMB_VARIANT
15157#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15158 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15159 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15160
15161#undef ARM_VARIANT
e74cfd16 15162#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15163#undef THUMB_VARIANT
15164#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15165 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15166 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15167 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15168 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15169 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15170 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15171 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15172 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15173
15174#undef ARM_VARIANT
e74cfd16 15175#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15176#undef THUMB_VARIANT
e74cfd16 15177#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15178 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15179 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15180 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15181 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15182 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15183 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15184
15185#undef ARM_VARIANT
e74cfd16 15186#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15187 /* ARM Architecture 4T. */
15188 /* Note: bx (and blx) are required on V5, even if the processor does
15189 not support Thumb. */
15190 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15191
15192#undef ARM_VARIANT
e74cfd16 15193#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15194#undef THUMB_VARIANT
e74cfd16 15195#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15196 /* Note: blx has 2 variants; the .value coded here is for
15197 BLX(2). Only this variant has conditional execution. */
15198 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15199 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15200
15201#undef THUMB_VARIANT
e74cfd16 15202#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15203 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15204 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15205 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15206 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15207 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15208 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15209 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15210 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15211
15212#undef ARM_VARIANT
e74cfd16 15213#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15214 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15215 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15216 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15217 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15218
15219 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15220 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15221
15222 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15223 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15224 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15225 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15226
15227 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15228 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15229 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15230 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15231
15232 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15233 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234
087b80de
JM
15235 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15236 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15237 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15238 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205
ZW
15239
15240#undef ARM_VARIANT
e74cfd16 15241#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15242 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15243 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15244 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15245
15246 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15247 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15248
15249#undef ARM_VARIANT
e74cfd16 15250#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15251 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15252
15253#undef ARM_VARIANT
e74cfd16 15254#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15255#undef THUMB_VARIANT
e74cfd16 15256#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15257 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15258 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15259 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15260 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15261 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15262 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15263 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15264 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15265 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15266 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15267
15268#undef THUMB_VARIANT
e74cfd16 15269#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15270 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15271 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15272 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15273 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15274
15275 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15276 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15277
15278/* ARM V6 not included in V7M (eg. integer SIMD). */
15279#undef THUMB_VARIANT
15280#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15281 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15282 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15283 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15284 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15285 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15286 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15287 /* Old name for QASX. */
c19d1205 15288 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15289 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15290 /* Old name for QSAX. */
15291 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15292 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15293 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15294 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15295 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15296 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15297 /* Old name for SASX. */
c19d1205
ZW
15298 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15299 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15300 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15301 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15302 /* Old name for SHASX. */
c19d1205 15303 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15304 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15305 /* Old name for SHSAX. */
15306 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15307 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15308 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15309 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15310 /* Old name for SSAX. */
15311 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15312 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15313 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15314 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15315 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15316 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15317 /* Old name for UASX. */
c19d1205
ZW
15318 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15319 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15320 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15321 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15322 /* Old name for UHASX. */
c19d1205 15323 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15324 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15325 /* Old name for UHSAX. */
15326 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15327 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15328 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15329 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15330 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15331 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15332 /* Old name for UQASX. */
c19d1205 15333 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15334 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15335 /* Old name for UQSAX. */
15336 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15337 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15338 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205 15339 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15340 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15341 /* Old name for USAX. */
c19d1205 15342 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 15343 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15344 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15345 UF(rfeib, 9900a00, 1, (RRw), rfe),
15346 UF(rfeda, 8100a00, 1, (RRw), rfe),
15347 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15348 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15349 UF(rfefa, 9900a00, 1, (RRw), rfe),
15350 UF(rfeea, 8100a00, 1, (RRw), rfe),
15351 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15352 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15353 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15354 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15355 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15356 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15357 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15358 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15359 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15360 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15361 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15362 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15363 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15364 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15365 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15366 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15367 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15368 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15369 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15370 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15371 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15372 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15373 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15374 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15375 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15376 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15377 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15378 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15379 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15380 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15381 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15382 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15383 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15384 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15385 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15386 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15387 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15388
15389#undef ARM_VARIANT
e74cfd16 15390#define ARM_VARIANT &arm_ext_v6k
c19d1205 15391#undef THUMB_VARIANT
e74cfd16 15392#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15393 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15394 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15395 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15396 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15397
ebdca51a
PB
15398#undef THUMB_VARIANT
15399#define THUMB_VARIANT &arm_ext_v6_notm
15400 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15401 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15402
c19d1205 15403#undef THUMB_VARIANT
e74cfd16 15404#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15405 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15406 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15407 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15408 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15409 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15410
15411#undef ARM_VARIANT
e74cfd16 15412#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15413 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15414
15415#undef ARM_VARIANT
e74cfd16 15416#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15417 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15418 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15419 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15420 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15421
15422 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15423 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15424 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15425 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15426
15427 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15428 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15429 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15430 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15431
25fe350b
MS
15432 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15433 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15434 /* ARM does not really have an IT instruction, so always allow it. */
15435#undef ARM_VARIANT
15436#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15437 TUE(it, 0, bf08, 1, (COND), it, t_it),
15438 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15439 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15440 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15441 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15442 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15443 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15444 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15445 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15446 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15447 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15448 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15449 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15450 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15451 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15452
92e90b6e
PB
15453 /* Thumb2 only instructions. */
15454#undef ARM_VARIANT
e74cfd16 15455#define ARM_VARIANT NULL
92e90b6e
PB
15456
15457 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15458 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15459 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15460 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15461
62b3e311
PB
15462 /* Thumb-2 hardware division instructions (R and M profiles only). */
15463#undef THUMB_VARIANT
15464#define THUMB_VARIANT &arm_ext_div
15465 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15466 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15467
7e806470
PB
15468 /* ARM V6M/V7 instructions. */
15469#undef ARM_VARIANT
15470#define ARM_VARIANT &arm_ext_barrier
15471#undef THUMB_VARIANT
15472#define THUMB_VARIANT &arm_ext_barrier
15473 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15474 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15475 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15476
62b3e311
PB
15477 /* ARM V7 instructions. */
15478#undef ARM_VARIANT
15479#define ARM_VARIANT &arm_ext_v7
15480#undef THUMB_VARIANT
15481#define THUMB_VARIANT &arm_ext_v7
15482 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15483 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15484
c19d1205 15485#undef ARM_VARIANT
e74cfd16 15486#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15487 cCE(wfs, e200110, 1, (RR), rd),
15488 cCE(rfs, e300110, 1, (RR), rd),
15489 cCE(wfc, e400110, 1, (RR), rd),
15490 cCE(rfc, e500110, 1, (RR), rd),
15491
4962c51a
MS
15492 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15493 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15494 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15495 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15496
4962c51a
MS
15497 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15498 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15499 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15500 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15501
15502 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15503 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15504 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15505 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15506 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15507 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15508 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15509 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15510 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15511 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15512 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15513 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15514
15515 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15516 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15517 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15518 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15519 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15520 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15521 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15522 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15523 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15524 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15525 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15526 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15527
15528 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15529 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15530 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15531 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15532 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15533 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15534 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15535 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15536 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15537 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15538 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15539 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15540
15541 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15542 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15543 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15544 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15545 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15546 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15547 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15548 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15549 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15550 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15551 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15552 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15553
15554 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15555 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15556 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15557 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15558 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15559 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15560 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15561 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15562 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15563 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15564 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15565 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15566
15567 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15568 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15569 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15570 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15571 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15572 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15573 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15574 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15575 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15576 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15577 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15578 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15579
15580 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15581 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15582 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15583 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15584 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15585 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15586 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15587 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15588 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15589 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15590 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15591 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15592
15593 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15594 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15595 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15596 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15597 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15598 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15599 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15600 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15601 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15602 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15603 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15604 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15605
15606 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15607 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15608 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15609 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15610 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15611 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15612 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15613 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15614 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15615 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15616 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15617 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15618
15619 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15620 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15621 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15622 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15623 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15624 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15625 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15626 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15627 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15628 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15629 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15630 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15631
15632 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15633 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15634 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15635 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15636 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15637 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15638 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15639 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15640 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15641 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15642 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15643 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15644
15645 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15646 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15647 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15648 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15649 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15650 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15651 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15652 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15653 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15654 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15655 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15656 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15657
15658 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15659 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15660 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15661 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15662 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15663 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15664 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15665 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15666 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15667 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15668 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15669 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15670
15671 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15672 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15673 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15674 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15675 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15676 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15677 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15678 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15679 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15680 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15681 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15682 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15683
15684 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15685 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15686 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15687 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15688 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15689 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15690 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15691 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15692 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15693 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15694 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15695 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15696
15697 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15698 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15699 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15700 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15701 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15702 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15703 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15704 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15705 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15706 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15707 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15708 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15709
15710 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15719 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15720 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15722
15723 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15732 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15733 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15734 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15735
15736 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15737 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15738 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15739 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15740 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15741 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15742 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15743 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15744 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15745 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15746 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15747 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15748
15749 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15750 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15751 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15752 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15753 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15754 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15755 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15756 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15757 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15758 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15759 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15760 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15761
15762 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15763 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15764 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15765 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15766 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15767 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15768 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15769 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15770 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15771 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15772 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15773 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15774
15775 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15776 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15777 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15778 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15779 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15780 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15781 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15782 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15783 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15784 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15785 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15786 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15787
15788 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15789 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15790 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15791 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15792 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15793 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15794 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15795 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15796 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15797 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15798 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15799 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15800
15801 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15802 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15803 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15804 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15805 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15806 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15807 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15808 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15809 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15810 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15811 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15812 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15813
15814 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15815 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15816 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15817 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15818 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15819 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15820 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15821 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15822 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15823 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15824 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15825 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15826
15827 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15828 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15829 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15830 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15831 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15832 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15833 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15834 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15835 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15836 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15837 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15838 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15839
15840 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15841 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15842 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15843 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15844 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15845 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15846 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15847 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15848 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15849 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15850 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15851 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15852
15853 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15854 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15855 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15856 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15857 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15858 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15859 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15860 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15861 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15862 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15863 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15864 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15865
15866 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15867 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15868 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15869 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15870 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15871 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15872 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15873 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15874 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15875 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15876 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15877 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15878
15879 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15880 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15881 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15882 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15883
e3cb604e
PB
15884 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15885 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15886 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15887 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15888 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15889 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15890 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15891 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15892 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15893 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15894 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15895 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15896
c19d1205
ZW
15897 /* The implementation of the FIX instruction is broken on some
15898 assemblers, in that it accepts a precision specifier as well as a
15899 rounding specifier, despite the fact that this is meaningless.
15900 To be more compatible, we accept it as well, though of course it
15901 does not set any bits. */
8f06b2d8 15902 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15903 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15904 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15905 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15906 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15907 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15908 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15909 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15910 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15911 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15912 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15913 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15914 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15915
c19d1205
ZW
15916 /* Instructions that were new with the real FPA, call them V2. */
15917#undef ARM_VARIANT
e74cfd16 15918#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15919 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15920 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15921 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15922 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15923 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15924 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15925
15926#undef ARM_VARIANT
e74cfd16 15927#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15928 /* Moves and type conversions. */
8f06b2d8
PB
15929 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15930 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15931 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15932 cCE(fmstat, ef1fa10, 0, (), noargs),
15933 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15934 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15935 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15936 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15937 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15938 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15939 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15940 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15941
15942 /* Memory operations. */
4962c51a
MS
15943 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15944 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15945 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15946 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15947 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15948 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15949 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15950 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15951 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15952 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15953 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15954 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15955 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15956 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15957 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15958 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15959 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15960 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15961
c19d1205 15962 /* Monadic operations. */
8f06b2d8
PB
15963 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15964 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15965 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15966
15967 /* Dyadic operations. */
8f06b2d8
PB
15968 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15969 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15970 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15971 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15972 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15973 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15974 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15975 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15976 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15977
c19d1205 15978 /* Comparisons. */
8f06b2d8
PB
15979 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15980 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15981 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15982 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15983
c19d1205 15984#undef ARM_VARIANT
e74cfd16 15985#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15986 /* Moves and type conversions. */
5287ad62 15987 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15988 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15989 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15990 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15991 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15992 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15993 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15994 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15995 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15996 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15997 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15998 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15999 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
16000
16001 /* Memory operations. */
4962c51a
MS
16002 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16003 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
16004 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16005 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16006 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16007 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16008 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16009 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16010 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16011 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 16012
c19d1205 16013 /* Monadic operations. */
5287ad62
JB
16014 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16015 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16016 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
16017
16018 /* Dyadic operations. */
5287ad62
JB
16019 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16020 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16021 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16022 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16023 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16024 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16025 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16026 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16027 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 16028
c19d1205 16029 /* Comparisons. */
5287ad62
JB
16030 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16031 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16032 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16033 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
16034
16035#undef ARM_VARIANT
e74cfd16 16036#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
16037 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16038 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
16039 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16040 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16041
037e8744
JB
16042/* Instructions which may belong to either the Neon or VFP instruction sets.
16043 Individual encoder functions perform additional architecture checks. */
16044#undef ARM_VARIANT
16045#define ARM_VARIANT &fpu_vfp_ext_v1xd
16046#undef THUMB_VARIANT
16047#define THUMB_VARIANT &fpu_vfp_ext_v1xd
16048 /* These mnemonics are unique to VFP. */
16049 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16050 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16051 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16052 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16053 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16054 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16055 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16056 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16057 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16058 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16059
16060 /* Mnemonics shared by Neon and VFP. */
16061 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16062 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16063 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16064
16065 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16066 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16067
16068 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16069 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16070
16071 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16072 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16073 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16074 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16075 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16076 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
16077 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16078 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
16079
16080 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
8e79c3df
CM
16081 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16082 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 16083
037e8744
JB
16084
16085 /* NOTE: All VMOV encoding is special-cased! */
16086 NCE(vmov, 0, 1, (VMOV), neon_mov),
16087 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16088
5287ad62
JB
16089#undef THUMB_VARIANT
16090#define THUMB_VARIANT &fpu_neon_ext_v1
16091#undef ARM_VARIANT
16092#define ARM_VARIANT &fpu_neon_ext_v1
16093 /* Data processing with three registers of the same length. */
16094 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16095 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16096 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16097 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16098 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16099 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16100 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16101 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16102 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16103 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
16104 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16105 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16106 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16107 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
16108 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16109 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16110 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16111 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
16112 /* If not immediate, fall back to neon_dyadic_i64_su.
16113 shl_imm should accept I8 I16 I32 I64,
16114 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
16115 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
16116 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
16117 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
16118 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
16119 /* Logic ops, types optional & ignored. */
16120 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
16121 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
16122 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
16123 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
16124 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
16125 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
16126 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
16127 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
16128 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
16129 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
16130 /* Bitfield ops, untyped. */
16131 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16132 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16133 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16134 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16135 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16136 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16137 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16138 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16139 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16140 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16141 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16142 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16143 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16144 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16145 back to neon_dyadic_if_su. */
16146 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16147 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16148 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16149 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16150 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16151 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16152 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16153 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16154 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16155 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16156 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16157 /* As above, D registers only. */
16158 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16159 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16160 /* Int and float variants, signedness unimportant. */
5287ad62 16161 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16162 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16163 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16164 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16165 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16166 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16167 /* vtst takes sizes 8, 16, 32. */
16168 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16169 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16170 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16171 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16172 /* VQD{R}MULH takes S16 S32. */
16173 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16174 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16175 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16176 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16177 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16178 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16179 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16180 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16181 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16182 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16183 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16184 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16185 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16186 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16187 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16188 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16189
16190 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16191 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16192 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16193
16194 /* Data processing with two registers and a shift amount. */
16195 /* Right shifts, and variants with rounding.
16196 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16197 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16198 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16199 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16200 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16201 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16202 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16203 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16204 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16205 /* Shift and insert. Sizes accepted 8 16 32 64. */
16206 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16207 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16208 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16209 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16210 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16211 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16212 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16213 /* Right shift immediate, saturating & narrowing, with rounding variants.
16214 Types accepted S16 S32 S64 U16 U32 U64. */
16215 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16216 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16217 /* As above, unsigned. Types accepted S16 S32 S64. */
16218 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16219 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16220 /* Right shift narrowing. Types accepted I16 I32 I64. */
16221 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16222 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16223 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16224 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16225 /* CVT with optional immediate for fixed-point variant. */
037e8744 16226 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16227
5287ad62
JB
16228 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16229 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16230
16231 /* Data processing, three registers of different lengths. */
16232 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16233 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16234 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16235 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16236 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16237 /* If not scalar, fall back to neon_dyadic_long.
16238 Vector types as above, scalar types S16 S32 U16 U32. */
16239 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16240 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16241 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16242 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16243 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16244 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16245 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16246 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16247 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16248 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16249 /* Saturating doubling multiplies. Types S16 S32. */
16250 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16251 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16252 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16253 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16254 S16 S32 U16 U32. */
16255 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16256
16257 /* Extract. Size 8. */
3b8d421e
PB
16258 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16259 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16260
16261 /* Two registers, miscellaneous. */
16262 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16263 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16264 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16265 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16266 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16267 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16268 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16269 /* Vector replicate. Sizes 8 16 32. */
16270 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16271 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16272 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16273 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16274 /* VMOVN. Types I16 I32 I64. */
16275 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16276 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16277 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16278 /* VQMOVUN. Types S16 S32 S64. */
16279 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16280 /* VZIP / VUZP. Sizes 8 16 32. */
16281 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16282 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16283 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16284 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16285 /* VQABS / VQNEG. Types S8 S16 S32. */
16286 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16287 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16288 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16289 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16290 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16291 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16292 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16293 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16294 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16295 /* Reciprocal estimates. Types U32 F32. */
16296 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16297 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16298 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16299 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16300 /* VCLS. Types S8 S16 S32. */
16301 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16302 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16303 /* VCLZ. Types I8 I16 I32. */
16304 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16305 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16306 /* VCNT. Size 8. */
16307 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16308 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16309 /* Two address, untyped. */
16310 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16311 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16312 /* VTRN. Sizes 8 16 32. */
16313 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16314 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16315
16316 /* Table lookup. Size 8. */
16317 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16318 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16319
b7fc2769
JB
16320#undef THUMB_VARIANT
16321#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16322#undef ARM_VARIANT
16323#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16324 /* Neon element/structure load/store. */
16325 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16326 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16327 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16328 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16329 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16330 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16331 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16332 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16333
16334#undef THUMB_VARIANT
16335#define THUMB_VARIANT &fpu_vfp_ext_v3
16336#undef ARM_VARIANT
16337#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16338 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16339 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16340 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16341 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16342 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16343 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16344 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16345 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16346 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16347 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16348 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16349 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16350 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16351 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16352 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16353 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16354 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16355 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16356
5287ad62 16357#undef THUMB_VARIANT
c19d1205 16358#undef ARM_VARIANT
e74cfd16 16359#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16360 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16361 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16362 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16363 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16364 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16365 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16366 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16367 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16368
16369#undef ARM_VARIANT
e74cfd16 16370#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16371 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16372 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16373 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16374 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16375 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16376 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16377 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16378 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16379 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16380 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16381 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16382 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16383 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16384 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16385 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16386 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16387 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16388 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16389 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16390 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16391 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16392 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16393 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16394 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16395 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16396 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16397 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16398 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16399 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16400 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16401 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16402 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16403 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16404 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16405 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16406 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16407 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16408 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16418 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16438 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16439 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16440 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16441 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16445 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16446 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16447 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16448 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16449 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16450 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16451 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16452 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16453 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16454 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16455 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16456 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16457 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16458 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16459 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16460 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16461 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16462 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16463 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16464 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16465 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16466 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16467 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16468 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16469 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16470 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16471 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16472 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16473 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16474 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16475 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16476 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16477 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16478 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16479 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16480 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16481 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16482 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16483 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16484 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16485 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16486 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16487 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16488 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16489 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16490 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16491 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16492 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16493 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16494 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16495 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16496 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16497 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16498 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16499 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16500 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16501 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16502 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16503 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16504 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16505 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16506 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16507 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16508 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16509 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16510 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16511 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16512 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16513 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16514 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16515 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16516 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16517 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16518 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16519 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16520 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16521 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16522 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16523 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16524 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16525 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16526 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16527 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16528 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16529 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16530 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16531 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16532 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16533
2d447fca
JM
16534#undef ARM_VARIANT
16535#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16536 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16537 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16538 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16539 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16540 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16541 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16542 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16543 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16544 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16545 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16546 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16547 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16548 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16549 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16550 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16551 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16552 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16553 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16554 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16555 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16556 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16557 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16558 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16559 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16560 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16561 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16562 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16563 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16564 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16565 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16566 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16567 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16568 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16569 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16570 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16571 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16572 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16573 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16574 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16575 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16576 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16577 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16578 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16579 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16580 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16581 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16582 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16583 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16584 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16585 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16586 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16587 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16588 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16589 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16590 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16591 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16592 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16593
c19d1205 16594#undef ARM_VARIANT
e74cfd16 16595#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16596 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16597 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16598 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16599 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16600 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16601 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16602 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16603 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16604 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16605 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16606 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16607 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16608 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16609 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16610 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16611 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16612 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16613 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16614 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16615 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16616 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16617 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16618 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16619 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16620 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16621 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16622 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16623 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16624 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16625 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16626 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16627 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16628 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16629 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16630 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16631 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16632 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16633 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16634 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16635 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16636 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16637 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16638 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16639 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16640 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16641 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16642 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16643 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16644 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16645 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16646 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16647 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16648 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16649 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16650 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16651 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16652 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16653 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16654 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16655 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16656 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16657 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16658 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16659 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16660 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16661 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16662 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16663 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16664 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16665 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16666 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16667 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16668 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16669 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16670 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16671 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16672};
16673#undef ARM_VARIANT
16674#undef THUMB_VARIANT
16675#undef TCE
16676#undef TCM
16677#undef TUE
16678#undef TUF
16679#undef TCC
8f06b2d8 16680#undef cCE
e3cb604e
PB
16681#undef cCL
16682#undef C3E
c19d1205
ZW
16683#undef CE
16684#undef CM
16685#undef UE
16686#undef UF
16687#undef UT
5287ad62
JB
16688#undef NUF
16689#undef nUF
16690#undef NCE
16691#undef nCE
c19d1205
ZW
16692#undef OPS0
16693#undef OPS1
16694#undef OPS2
16695#undef OPS3
16696#undef OPS4
16697#undef OPS5
16698#undef OPS6
16699#undef do_0
16700\f
16701/* MD interface: bits in the object file. */
bfae80f2 16702
c19d1205
ZW
16703/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16704 for use in the a.out file, and stores them in the array pointed to by buf.
16705 This knows about the endian-ness of the target machine and does
16706 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16707 2 (short) and 4 (long) Floating numbers are put out as a series of
16708 LITTLENUMS (shorts, here at least). */
b99bd4ef 16709
c19d1205
ZW
16710void
16711md_number_to_chars (char * buf, valueT val, int n)
16712{
16713 if (target_big_endian)
16714 number_to_chars_bigendian (buf, val, n);
16715 else
16716 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16717}
16718
c19d1205
ZW
16719static valueT
16720md_chars_to_number (char * buf, int n)
bfae80f2 16721{
c19d1205
ZW
16722 valueT result = 0;
16723 unsigned char * where = (unsigned char *) buf;
bfae80f2 16724
c19d1205 16725 if (target_big_endian)
b99bd4ef 16726 {
c19d1205
ZW
16727 while (n--)
16728 {
16729 result <<= 8;
16730 result |= (*where++ & 255);
16731 }
b99bd4ef 16732 }
c19d1205 16733 else
b99bd4ef 16734 {
c19d1205
ZW
16735 while (n--)
16736 {
16737 result <<= 8;
16738 result |= (where[n] & 255);
16739 }
bfae80f2 16740 }
b99bd4ef 16741
c19d1205 16742 return result;
bfae80f2 16743}
b99bd4ef 16744
c19d1205 16745/* MD interface: Sections. */
b99bd4ef 16746
0110f2b8
PB
16747/* Estimate the size of a frag before relaxing. Assume everything fits in
16748 2 bytes. */
16749
c19d1205 16750int
0110f2b8 16751md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16752 segT segtype ATTRIBUTE_UNUSED)
16753{
0110f2b8
PB
16754 fragp->fr_var = 2;
16755 return 2;
16756}
16757
16758/* Convert a machine dependent frag. */
16759
16760void
16761md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16762{
16763 unsigned long insn;
16764 unsigned long old_op;
16765 char *buf;
16766 expressionS exp;
16767 fixS *fixp;
16768 int reloc_type;
16769 int pc_rel;
16770 int opcode;
16771
16772 buf = fragp->fr_literal + fragp->fr_fix;
16773
16774 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
16775 if (fragp->fr_symbol)
16776 {
0110f2b8
PB
16777 exp.X_op = O_symbol;
16778 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
16779 }
16780 else
16781 {
0110f2b8 16782 exp.X_op = O_constant;
5f4273c7 16783 }
0110f2b8
PB
16784 exp.X_add_number = fragp->fr_offset;
16785 opcode = fragp->fr_subtype;
16786 switch (opcode)
16787 {
16788 case T_MNEM_ldr_pc:
16789 case T_MNEM_ldr_pc2:
16790 case T_MNEM_ldr_sp:
16791 case T_MNEM_str_sp:
16792 case T_MNEM_ldr:
16793 case T_MNEM_ldrb:
16794 case T_MNEM_ldrh:
16795 case T_MNEM_str:
16796 case T_MNEM_strb:
16797 case T_MNEM_strh:
16798 if (fragp->fr_var == 4)
16799 {
5f4273c7 16800 insn = THUMB_OP32 (opcode);
0110f2b8
PB
16801 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16802 {
16803 insn |= (old_op & 0x700) << 4;
16804 }
16805 else
16806 {
16807 insn |= (old_op & 7) << 12;
16808 insn |= (old_op & 0x38) << 13;
16809 }
16810 insn |= 0x00000c00;
16811 put_thumb32_insn (buf, insn);
16812 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16813 }
16814 else
16815 {
16816 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16817 }
16818 pc_rel = (opcode == T_MNEM_ldr_pc2);
16819 break;
16820 case T_MNEM_adr:
16821 if (fragp->fr_var == 4)
16822 {
16823 insn = THUMB_OP32 (opcode);
16824 insn |= (old_op & 0xf0) << 4;
16825 put_thumb32_insn (buf, insn);
16826 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16827 }
16828 else
16829 {
16830 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16831 exp.X_add_number -= 4;
16832 }
16833 pc_rel = 1;
16834 break;
16835 case T_MNEM_mov:
16836 case T_MNEM_movs:
16837 case T_MNEM_cmp:
16838 case T_MNEM_cmn:
16839 if (fragp->fr_var == 4)
16840 {
16841 int r0off = (opcode == T_MNEM_mov
16842 || opcode == T_MNEM_movs) ? 0 : 8;
16843 insn = THUMB_OP32 (opcode);
16844 insn = (insn & 0xe1ffffff) | 0x10000000;
16845 insn |= (old_op & 0x700) << r0off;
16846 put_thumb32_insn (buf, insn);
16847 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16848 }
16849 else
16850 {
16851 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16852 }
16853 pc_rel = 0;
16854 break;
16855 case T_MNEM_b:
16856 if (fragp->fr_var == 4)
16857 {
16858 insn = THUMB_OP32(opcode);
16859 put_thumb32_insn (buf, insn);
16860 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16861 }
16862 else
16863 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16864 pc_rel = 1;
16865 break;
16866 case T_MNEM_bcond:
16867 if (fragp->fr_var == 4)
16868 {
16869 insn = THUMB_OP32(opcode);
16870 insn |= (old_op & 0xf00) << 14;
16871 put_thumb32_insn (buf, insn);
16872 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16873 }
16874 else
16875 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16876 pc_rel = 1;
16877 break;
16878 case T_MNEM_add_sp:
16879 case T_MNEM_add_pc:
16880 case T_MNEM_inc_sp:
16881 case T_MNEM_dec_sp:
16882 if (fragp->fr_var == 4)
16883 {
16884 /* ??? Choose between add and addw. */
16885 insn = THUMB_OP32 (opcode);
16886 insn |= (old_op & 0xf0) << 4;
16887 put_thumb32_insn (buf, insn);
16805f35
PB
16888 if (opcode == T_MNEM_add_pc)
16889 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16890 else
16891 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16892 }
16893 else
16894 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16895 pc_rel = 0;
16896 break;
16897
16898 case T_MNEM_addi:
16899 case T_MNEM_addis:
16900 case T_MNEM_subi:
16901 case T_MNEM_subis:
16902 if (fragp->fr_var == 4)
16903 {
16904 insn = THUMB_OP32 (opcode);
16905 insn |= (old_op & 0xf0) << 4;
16906 insn |= (old_op & 0xf) << 16;
16907 put_thumb32_insn (buf, insn);
16805f35
PB
16908 if (insn & (1 << 20))
16909 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16910 else
16911 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16912 }
16913 else
16914 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16915 pc_rel = 0;
16916 break;
16917 default:
5f4273c7 16918 abort ();
0110f2b8
PB
16919 }
16920 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16921 reloc_type);
16922 fixp->fx_file = fragp->fr_file;
16923 fixp->fx_line = fragp->fr_line;
16924 fragp->fr_fix += fragp->fr_var;
16925}
16926
16927/* Return the size of a relaxable immediate operand instruction.
16928 SHIFT and SIZE specify the form of the allowable immediate. */
16929static int
16930relax_immediate (fragS *fragp, int size, int shift)
16931{
16932 offsetT offset;
16933 offsetT mask;
16934 offsetT low;
16935
16936 /* ??? Should be able to do better than this. */
16937 if (fragp->fr_symbol)
16938 return 4;
16939
16940 low = (1 << shift) - 1;
16941 mask = (1 << (shift + size)) - (1 << shift);
16942 offset = fragp->fr_offset;
16943 /* Force misaligned offsets to 32-bit variant. */
16944 if (offset & low)
5e77afaa 16945 return 4;
0110f2b8
PB
16946 if (offset & ~mask)
16947 return 4;
16948 return 2;
16949}
16950
5e77afaa
PB
16951/* Get the address of a symbol during relaxation. */
16952static addressT
5f4273c7 16953relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
16954{
16955 fragS *sym_frag;
16956 addressT addr;
16957 symbolS *sym;
16958
16959 sym = fragp->fr_symbol;
16960 sym_frag = symbol_get_frag (sym);
16961 know (S_GET_SEGMENT (sym) != absolute_section
16962 || sym_frag == &zero_address_frag);
16963 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16964
16965 /* If frag has yet to be reached on this pass, assume it will
16966 move by STRETCH just as we did. If this is not so, it will
16967 be because some frag between grows, and that will force
16968 another pass. */
16969
16970 if (stretch != 0
16971 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
16972 {
16973 fragS *f;
16974
16975 /* Adjust stretch for any alignment frag. Note that if have
16976 been expanding the earlier code, the symbol may be
16977 defined in what appears to be an earlier frag. FIXME:
16978 This doesn't handle the fr_subtype field, which specifies
16979 a maximum number of bytes to skip when doing an
16980 alignment. */
16981 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
16982 {
16983 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
16984 {
16985 if (stretch < 0)
16986 stretch = - ((- stretch)
16987 & ~ ((1 << (int) f->fr_offset) - 1));
16988 else
16989 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
16990 if (stretch == 0)
16991 break;
16992 }
16993 }
16994 if (f != NULL)
16995 addr += stretch;
16996 }
5e77afaa
PB
16997
16998 return addr;
16999}
17000
0110f2b8
PB
17001/* Return the size of a relaxable adr pseudo-instruction or PC-relative
17002 load. */
17003static int
5e77afaa 17004relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
17005{
17006 addressT addr;
17007 offsetT val;
17008
17009 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17010 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17011 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17012 return 4;
17013
5f4273c7 17014 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17015 addr = fragp->fr_address + fragp->fr_fix;
17016 addr = (addr + 4) & ~3;
5e77afaa 17017 /* Force misaligned targets to 32-bit variant. */
0110f2b8 17018 if (val & 3)
5e77afaa 17019 return 4;
0110f2b8
PB
17020 val -= addr;
17021 if (val < 0 || val > 1020)
17022 return 4;
17023 return 2;
17024}
17025
17026/* Return the size of a relaxable add/sub immediate instruction. */
17027static int
17028relax_addsub (fragS *fragp, asection *sec)
17029{
17030 char *buf;
17031 int op;
17032
17033 buf = fragp->fr_literal + fragp->fr_fix;
17034 op = bfd_get_16(sec->owner, buf);
17035 if ((op & 0xf) == ((op >> 4) & 0xf))
17036 return relax_immediate (fragp, 8, 0);
17037 else
17038 return relax_immediate (fragp, 3, 0);
17039}
17040
17041
17042/* Return the size of a relaxable branch instruction. BITS is the
17043 size of the offset field in the narrow instruction. */
17044
17045static int
5e77afaa 17046relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
17047{
17048 addressT addr;
17049 offsetT val;
17050 offsetT limit;
17051
17052 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17053 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17054 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17055 return 4;
17056
5f4273c7 17057 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17058 addr = fragp->fr_address + fragp->fr_fix + 4;
17059 val -= addr;
17060
17061 /* Offset is a signed value *2 */
17062 limit = 1 << bits;
17063 if (val >= limit || val < -limit)
17064 return 4;
17065 return 2;
17066}
17067
17068
17069/* Relax a machine dependent frag. This returns the amount by which
17070 the current size of the frag should change. */
17071
17072int
5e77afaa 17073arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
17074{
17075 int oldsize;
17076 int newsize;
17077
17078 oldsize = fragp->fr_var;
17079 switch (fragp->fr_subtype)
17080 {
17081 case T_MNEM_ldr_pc2:
5f4273c7 17082 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17083 break;
17084 case T_MNEM_ldr_pc:
17085 case T_MNEM_ldr_sp:
17086 case T_MNEM_str_sp:
5f4273c7 17087 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
17088 break;
17089 case T_MNEM_ldr:
17090 case T_MNEM_str:
5f4273c7 17091 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
17092 break;
17093 case T_MNEM_ldrh:
17094 case T_MNEM_strh:
5f4273c7 17095 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
17096 break;
17097 case T_MNEM_ldrb:
17098 case T_MNEM_strb:
5f4273c7 17099 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
17100 break;
17101 case T_MNEM_adr:
5f4273c7 17102 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17103 break;
17104 case T_MNEM_mov:
17105 case T_MNEM_movs:
17106 case T_MNEM_cmp:
17107 case T_MNEM_cmn:
5f4273c7 17108 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
17109 break;
17110 case T_MNEM_b:
5f4273c7 17111 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
17112 break;
17113 case T_MNEM_bcond:
5f4273c7 17114 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
17115 break;
17116 case T_MNEM_add_sp:
17117 case T_MNEM_add_pc:
17118 newsize = relax_immediate (fragp, 8, 2);
17119 break;
17120 case T_MNEM_inc_sp:
17121 case T_MNEM_dec_sp:
17122 newsize = relax_immediate (fragp, 7, 2);
17123 break;
17124 case T_MNEM_addi:
17125 case T_MNEM_addis:
17126 case T_MNEM_subi:
17127 case T_MNEM_subis:
17128 newsize = relax_addsub (fragp, sec);
17129 break;
17130 default:
5f4273c7 17131 abort ();
0110f2b8 17132 }
5e77afaa
PB
17133
17134 fragp->fr_var = newsize;
17135 /* Freeze wide instructions that are at or before the same location as
17136 in the previous pass. This avoids infinite loops.
5f4273c7
NC
17137 Don't freeze them unconditionally because targets may be artificially
17138 misaligned by the expansion of preceding frags. */
5e77afaa 17139 if (stretch <= 0 && newsize > 2)
0110f2b8 17140 {
0110f2b8 17141 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 17142 frag_wane (fragp);
0110f2b8 17143 }
5e77afaa 17144
0110f2b8 17145 return newsize - oldsize;
c19d1205 17146}
b99bd4ef 17147
c19d1205 17148/* Round up a section size to the appropriate boundary. */
b99bd4ef 17149
c19d1205
ZW
17150valueT
17151md_section_align (segT segment ATTRIBUTE_UNUSED,
17152 valueT size)
17153{
f0927246
NC
17154#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17155 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17156 {
17157 /* For a.out, force the section size to be aligned. If we don't do
17158 this, BFD will align it for us, but it will not write out the
17159 final bytes of the section. This may be a bug in BFD, but it is
17160 easier to fix it here since that is how the other a.out targets
17161 work. */
17162 int align;
17163
17164 align = bfd_get_section_alignment (stdoutput, segment);
17165 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17166 }
c19d1205 17167#endif
f0927246
NC
17168
17169 return size;
bfae80f2 17170}
b99bd4ef 17171
c19d1205
ZW
17172/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17173 of an rs_align_code fragment. */
17174
17175void
17176arm_handle_align (fragS * fragP)
bfae80f2 17177{
c19d1205
ZW
17178 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17179 static char const thumb_noop[2] = { 0xc0, 0x46 };
17180 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17181 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17182
17183 int bytes, fix, noop_size;
17184 char * p;
17185 const char * noop;
bfae80f2 17186
c19d1205 17187 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17188 return;
17189
c19d1205
ZW
17190 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17191 p = fragP->fr_literal + fragP->fr_fix;
17192 fix = 0;
bfae80f2 17193
c19d1205
ZW
17194 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17195 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17196
c19d1205 17197 if (fragP->tc_frag_data)
a737bd4d 17198 {
c19d1205
ZW
17199 if (target_big_endian)
17200 noop = thumb_bigend_noop;
17201 else
17202 noop = thumb_noop;
17203 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17204 }
17205 else
17206 {
c19d1205
ZW
17207 if (target_big_endian)
17208 noop = arm_bigend_noop;
17209 else
17210 noop = arm_noop;
17211 noop_size = sizeof (arm_noop);
7ed4c4c5 17212 }
a737bd4d 17213
c19d1205 17214 if (bytes & (noop_size - 1))
7ed4c4c5 17215 {
c19d1205
ZW
17216 fix = bytes & (noop_size - 1);
17217 memset (p, 0, fix);
17218 p += fix;
17219 bytes -= fix;
a737bd4d 17220 }
a737bd4d 17221
c19d1205 17222 while (bytes >= noop_size)
a737bd4d 17223 {
c19d1205
ZW
17224 memcpy (p, noop, noop_size);
17225 p += noop_size;
17226 bytes -= noop_size;
17227 fix += noop_size;
a737bd4d
NC
17228 }
17229
c19d1205
ZW
17230 fragP->fr_fix += fix;
17231 fragP->fr_var = noop_size;
a737bd4d
NC
17232}
17233
c19d1205
ZW
17234/* Called from md_do_align. Used to create an alignment
17235 frag in a code section. */
17236
17237void
17238arm_frag_align_code (int n, int max)
bfae80f2 17239{
c19d1205 17240 char * p;
7ed4c4c5 17241
c19d1205
ZW
17242 /* We assume that there will never be a requirement
17243 to support alignments greater than 32 bytes. */
17244 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17245 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17246
c19d1205
ZW
17247 p = frag_var (rs_align_code,
17248 MAX_MEM_FOR_RS_ALIGN_CODE,
17249 1,
17250 (relax_substateT) max,
17251 (symbolS *) NULL,
17252 (offsetT) n,
17253 (char *) NULL);
17254 *p = 0;
17255}
bfae80f2 17256
c19d1205 17257/* Perform target specific initialisation of a frag. */
bfae80f2 17258
c19d1205
ZW
17259void
17260arm_init_frag (fragS * fragP)
17261{
17262 /* Record whether this frag is in an ARM or a THUMB area. */
17263 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17264}
17265
c19d1205
ZW
17266#ifdef OBJ_ELF
17267/* When we change sections we need to issue a new mapping symbol. */
17268
17269void
17270arm_elf_change_section (void)
bfae80f2 17271{
c19d1205
ZW
17272 flagword flags;
17273 segment_info_type *seginfo;
bfae80f2 17274
c19d1205
ZW
17275 /* Link an unlinked unwind index table section to the .text section. */
17276 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17277 && elf_linked_to_section (now_seg) == NULL)
17278 elf_linked_to_section (now_seg) = text_section;
17279
17280 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17281 return;
17282
c19d1205
ZW
17283 flags = bfd_get_section_flags (stdoutput, now_seg);
17284
17285 /* We can ignore sections that only contain debug info. */
17286 if ((flags & SEC_ALLOC) == 0)
17287 return;
bfae80f2 17288
c19d1205
ZW
17289 seginfo = seg_info (now_seg);
17290 mapstate = seginfo->tc_segment_info_data.mapstate;
17291 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17292}
17293
c19d1205
ZW
17294int
17295arm_elf_section_type (const char * str, size_t len)
e45d0630 17296{
c19d1205
ZW
17297 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17298 return SHT_ARM_EXIDX;
e45d0630 17299
c19d1205
ZW
17300 return -1;
17301}
17302\f
17303/* Code to deal with unwinding tables. */
e45d0630 17304
c19d1205 17305static void add_unwind_adjustsp (offsetT);
e45d0630 17306
5f4273c7 17307/* Generate any deferred unwind frame offset. */
e45d0630 17308
bfae80f2 17309static void
c19d1205 17310flush_pending_unwind (void)
bfae80f2 17311{
c19d1205 17312 offsetT offset;
bfae80f2 17313
c19d1205
ZW
17314 offset = unwind.pending_offset;
17315 unwind.pending_offset = 0;
17316 if (offset != 0)
17317 add_unwind_adjustsp (offset);
bfae80f2
RE
17318}
17319
c19d1205
ZW
17320/* Add an opcode to this list for this function. Two-byte opcodes should
17321 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17322 order. */
17323
bfae80f2 17324static void
c19d1205 17325add_unwind_opcode (valueT op, int length)
bfae80f2 17326{
c19d1205
ZW
17327 /* Add any deferred stack adjustment. */
17328 if (unwind.pending_offset)
17329 flush_pending_unwind ();
bfae80f2 17330
c19d1205 17331 unwind.sp_restored = 0;
bfae80f2 17332
c19d1205 17333 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17334 {
c19d1205
ZW
17335 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17336 if (unwind.opcodes)
17337 unwind.opcodes = xrealloc (unwind.opcodes,
17338 unwind.opcode_alloc);
17339 else
17340 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17341 }
c19d1205 17342 while (length > 0)
bfae80f2 17343 {
c19d1205
ZW
17344 length--;
17345 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17346 op >>= 8;
17347 unwind.opcode_count++;
bfae80f2 17348 }
bfae80f2
RE
17349}
17350
c19d1205
ZW
17351/* Add unwind opcodes to adjust the stack pointer. */
17352
bfae80f2 17353static void
c19d1205 17354add_unwind_adjustsp (offsetT offset)
bfae80f2 17355{
c19d1205 17356 valueT op;
bfae80f2 17357
c19d1205 17358 if (offset > 0x200)
bfae80f2 17359 {
c19d1205
ZW
17360 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17361 char bytes[5];
17362 int n;
17363 valueT o;
bfae80f2 17364
c19d1205
ZW
17365 /* Long form: 0xb2, uleb128. */
17366 /* This might not fit in a word so add the individual bytes,
17367 remembering the list is built in reverse order. */
17368 o = (valueT) ((offset - 0x204) >> 2);
17369 if (o == 0)
17370 add_unwind_opcode (0, 1);
bfae80f2 17371
c19d1205
ZW
17372 /* Calculate the uleb128 encoding of the offset. */
17373 n = 0;
17374 while (o)
17375 {
17376 bytes[n] = o & 0x7f;
17377 o >>= 7;
17378 if (o)
17379 bytes[n] |= 0x80;
17380 n++;
17381 }
17382 /* Add the insn. */
17383 for (; n; n--)
17384 add_unwind_opcode (bytes[n - 1], 1);
17385 add_unwind_opcode (0xb2, 1);
17386 }
17387 else if (offset > 0x100)
bfae80f2 17388 {
c19d1205
ZW
17389 /* Two short opcodes. */
17390 add_unwind_opcode (0x3f, 1);
17391 op = (offset - 0x104) >> 2;
17392 add_unwind_opcode (op, 1);
bfae80f2 17393 }
c19d1205
ZW
17394 else if (offset > 0)
17395 {
17396 /* Short opcode. */
17397 op = (offset - 4) >> 2;
17398 add_unwind_opcode (op, 1);
17399 }
17400 else if (offset < 0)
bfae80f2 17401 {
c19d1205
ZW
17402 offset = -offset;
17403 while (offset > 0x100)
bfae80f2 17404 {
c19d1205
ZW
17405 add_unwind_opcode (0x7f, 1);
17406 offset -= 0x100;
bfae80f2 17407 }
c19d1205
ZW
17408 op = ((offset - 4) >> 2) | 0x40;
17409 add_unwind_opcode (op, 1);
bfae80f2 17410 }
bfae80f2
RE
17411}
17412
c19d1205
ZW
17413/* Finish the list of unwind opcodes for this function. */
17414static void
17415finish_unwind_opcodes (void)
bfae80f2 17416{
c19d1205 17417 valueT op;
bfae80f2 17418
c19d1205 17419 if (unwind.fp_used)
bfae80f2 17420 {
708587a4 17421 /* Adjust sp as necessary. */
c19d1205
ZW
17422 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17423 flush_pending_unwind ();
bfae80f2 17424
c19d1205
ZW
17425 /* After restoring sp from the frame pointer. */
17426 op = 0x90 | unwind.fp_reg;
17427 add_unwind_opcode (op, 1);
17428 }
17429 else
17430 flush_pending_unwind ();
bfae80f2
RE
17431}
17432
bfae80f2 17433
c19d1205
ZW
17434/* Start an exception table entry. If idx is nonzero this is an index table
17435 entry. */
bfae80f2
RE
17436
17437static void
c19d1205 17438start_unwind_section (const segT text_seg, int idx)
bfae80f2 17439{
c19d1205
ZW
17440 const char * text_name;
17441 const char * prefix;
17442 const char * prefix_once;
17443 const char * group_name;
17444 size_t prefix_len;
17445 size_t text_len;
17446 char * sec_name;
17447 size_t sec_name_len;
17448 int type;
17449 int flags;
17450 int linkonce;
bfae80f2 17451
c19d1205 17452 if (idx)
bfae80f2 17453 {
c19d1205
ZW
17454 prefix = ELF_STRING_ARM_unwind;
17455 prefix_once = ELF_STRING_ARM_unwind_once;
17456 type = SHT_ARM_EXIDX;
bfae80f2 17457 }
c19d1205 17458 else
bfae80f2 17459 {
c19d1205
ZW
17460 prefix = ELF_STRING_ARM_unwind_info;
17461 prefix_once = ELF_STRING_ARM_unwind_info_once;
17462 type = SHT_PROGBITS;
bfae80f2
RE
17463 }
17464
c19d1205
ZW
17465 text_name = segment_name (text_seg);
17466 if (streq (text_name, ".text"))
17467 text_name = "";
17468
17469 if (strncmp (text_name, ".gnu.linkonce.t.",
17470 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17471 {
c19d1205
ZW
17472 prefix = prefix_once;
17473 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17474 }
17475
c19d1205
ZW
17476 prefix_len = strlen (prefix);
17477 text_len = strlen (text_name);
17478 sec_name_len = prefix_len + text_len;
17479 sec_name = xmalloc (sec_name_len + 1);
17480 memcpy (sec_name, prefix, prefix_len);
17481 memcpy (sec_name + prefix_len, text_name, text_len);
17482 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17483
c19d1205
ZW
17484 flags = SHF_ALLOC;
17485 linkonce = 0;
17486 group_name = 0;
bfae80f2 17487
c19d1205
ZW
17488 /* Handle COMDAT group. */
17489 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17490 {
c19d1205
ZW
17491 group_name = elf_group_name (text_seg);
17492 if (group_name == NULL)
17493 {
bd3ba5d1 17494 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17495 segment_name (text_seg));
17496 ignore_rest_of_line ();
17497 return;
17498 }
17499 flags |= SHF_GROUP;
17500 linkonce = 1;
bfae80f2
RE
17501 }
17502
c19d1205 17503 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17504
5f4273c7 17505 /* Set the section link for index tables. */
c19d1205
ZW
17506 if (idx)
17507 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17508}
17509
bfae80f2 17510
c19d1205
ZW
17511/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17512 personality routine data. Returns zero, or the index table value for
17513 and inline entry. */
17514
17515static valueT
17516create_unwind_entry (int have_data)
bfae80f2 17517{
c19d1205
ZW
17518 int size;
17519 addressT where;
17520 char *ptr;
17521 /* The current word of data. */
17522 valueT data;
17523 /* The number of bytes left in this word. */
17524 int n;
bfae80f2 17525
c19d1205 17526 finish_unwind_opcodes ();
bfae80f2 17527
c19d1205
ZW
17528 /* Remember the current text section. */
17529 unwind.saved_seg = now_seg;
17530 unwind.saved_subseg = now_subseg;
bfae80f2 17531
c19d1205 17532 start_unwind_section (now_seg, 0);
bfae80f2 17533
c19d1205 17534 if (unwind.personality_routine == NULL)
bfae80f2 17535 {
c19d1205
ZW
17536 if (unwind.personality_index == -2)
17537 {
17538 if (have_data)
5f4273c7 17539 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17540 return 1; /* EXIDX_CANTUNWIND. */
17541 }
bfae80f2 17542
c19d1205
ZW
17543 /* Use a default personality routine if none is specified. */
17544 if (unwind.personality_index == -1)
17545 {
17546 if (unwind.opcode_count > 3)
17547 unwind.personality_index = 1;
17548 else
17549 unwind.personality_index = 0;
17550 }
bfae80f2 17551
c19d1205
ZW
17552 /* Space for the personality routine entry. */
17553 if (unwind.personality_index == 0)
17554 {
17555 if (unwind.opcode_count > 3)
17556 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17557
c19d1205
ZW
17558 if (!have_data)
17559 {
17560 /* All the data is inline in the index table. */
17561 data = 0x80;
17562 n = 3;
17563 while (unwind.opcode_count > 0)
17564 {
17565 unwind.opcode_count--;
17566 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17567 n--;
17568 }
bfae80f2 17569
c19d1205
ZW
17570 /* Pad with "finish" opcodes. */
17571 while (n--)
17572 data = (data << 8) | 0xb0;
bfae80f2 17573
c19d1205
ZW
17574 return data;
17575 }
17576 size = 0;
17577 }
17578 else
17579 /* We get two opcodes "free" in the first word. */
17580 size = unwind.opcode_count - 2;
17581 }
17582 else
17583 /* An extra byte is required for the opcode count. */
17584 size = unwind.opcode_count + 1;
bfae80f2 17585
c19d1205
ZW
17586 size = (size + 3) >> 2;
17587 if (size > 0xff)
17588 as_bad (_("too many unwind opcodes"));
bfae80f2 17589
c19d1205
ZW
17590 frag_align (2, 0, 0);
17591 record_alignment (now_seg, 2);
17592 unwind.table_entry = expr_build_dot ();
17593
17594 /* Allocate the table entry. */
17595 ptr = frag_more ((size << 2) + 4);
17596 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17597
c19d1205 17598 switch (unwind.personality_index)
bfae80f2 17599 {
c19d1205
ZW
17600 case -1:
17601 /* ??? Should this be a PLT generating relocation? */
17602 /* Custom personality routine. */
17603 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17604 BFD_RELOC_ARM_PREL31);
bfae80f2 17605
c19d1205
ZW
17606 where += 4;
17607 ptr += 4;
bfae80f2 17608
c19d1205
ZW
17609 /* Set the first byte to the number of additional words. */
17610 data = size - 1;
17611 n = 3;
17612 break;
bfae80f2 17613
c19d1205
ZW
17614 /* ABI defined personality routines. */
17615 case 0:
17616 /* Three opcodes bytes are packed into the first word. */
17617 data = 0x80;
17618 n = 3;
17619 break;
bfae80f2 17620
c19d1205
ZW
17621 case 1:
17622 case 2:
17623 /* The size and first two opcode bytes go in the first word. */
17624 data = ((0x80 + unwind.personality_index) << 8) | size;
17625 n = 2;
17626 break;
bfae80f2 17627
c19d1205
ZW
17628 default:
17629 /* Should never happen. */
17630 abort ();
17631 }
bfae80f2 17632
c19d1205
ZW
17633 /* Pack the opcodes into words (MSB first), reversing the list at the same
17634 time. */
17635 while (unwind.opcode_count > 0)
17636 {
17637 if (n == 0)
17638 {
17639 md_number_to_chars (ptr, data, 4);
17640 ptr += 4;
17641 n = 4;
17642 data = 0;
17643 }
17644 unwind.opcode_count--;
17645 n--;
17646 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17647 }
17648
17649 /* Finish off the last word. */
17650 if (n < 4)
17651 {
17652 /* Pad with "finish" opcodes. */
17653 while (n--)
17654 data = (data << 8) | 0xb0;
17655
17656 md_number_to_chars (ptr, data, 4);
17657 }
17658
17659 if (!have_data)
17660 {
17661 /* Add an empty descriptor if there is no user-specified data. */
17662 ptr = frag_more (4);
17663 md_number_to_chars (ptr, 0, 4);
17664 }
17665
17666 return 0;
bfae80f2
RE
17667}
17668
f0927246
NC
17669
17670/* Initialize the DWARF-2 unwind information for this procedure. */
17671
17672void
17673tc_arm_frame_initial_instructions (void)
17674{
17675 cfi_add_CFA_def_cfa (REG_SP, 0);
17676}
17677#endif /* OBJ_ELF */
17678
c19d1205
ZW
17679/* Convert REGNAME to a DWARF-2 register number. */
17680
17681int
1df69f4f 17682tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17683{
1df69f4f 17684 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17685
17686 if (reg == FAIL)
17687 return -1;
17688
17689 return reg;
bfae80f2
RE
17690}
17691
f0927246 17692#ifdef TE_PE
c19d1205 17693void
f0927246 17694tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17695{
f0927246 17696 expressionS expr;
bfae80f2 17697
f0927246
NC
17698 expr.X_op = O_secrel;
17699 expr.X_add_symbol = symbol;
17700 expr.X_add_number = 0;
17701 emit_expr (&expr, size);
17702}
17703#endif
bfae80f2 17704
c19d1205 17705/* MD interface: Symbol and relocation handling. */
bfae80f2 17706
2fc8bdac
ZW
17707/* Return the address within the segment that a PC-relative fixup is
17708 relative to. For ARM, PC-relative fixups applied to instructions
17709 are generally relative to the location of the fixup plus 8 bytes.
17710 Thumb branches are offset by 4, and Thumb loads relative to PC
17711 require special handling. */
bfae80f2 17712
c19d1205 17713long
2fc8bdac 17714md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17715{
2fc8bdac
ZW
17716 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17717
17718 /* If this is pc-relative and we are going to emit a relocation
17719 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17720 will need. Otherwise we want to use the calculated base.
17721 For WinCE we skip the bias for externals as well, since this
17722 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 17723 if (fixP->fx_pcrel
2fc8bdac 17724 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17725 || (arm_force_relocation (fixP)
17726#ifdef TE_WINCE
17727 && !S_IS_EXTERNAL (fixP->fx_addsy)
17728#endif
17729 )))
2fc8bdac 17730 base = 0;
bfae80f2 17731
c19d1205 17732 switch (fixP->fx_r_type)
bfae80f2 17733 {
2fc8bdac
ZW
17734 /* PC relative addressing on the Thumb is slightly odd as the
17735 bottom two bits of the PC are forced to zero for the
17736 calculation. This happens *after* application of the
17737 pipeline offset. However, Thumb adrl already adjusts for
17738 this, so we need not do it again. */
c19d1205 17739 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17740 return base & ~3;
c19d1205
ZW
17741
17742 case BFD_RELOC_ARM_THUMB_OFFSET:
17743 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17744 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17745 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17746 return (base + 4) & ~3;
c19d1205 17747
2fc8bdac
ZW
17748 /* Thumb branches are simply offset by +4. */
17749 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17750 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17751 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17752 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17753 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17754 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17755 case BFD_RELOC_THUMB_PCREL_BLX:
17756 return base + 4;
bfae80f2 17757
2fc8bdac
ZW
17758 /* ARM mode branches are offset by +8. However, the Windows CE
17759 loader expects the relocation not to take this into account. */
17760 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17761 case BFD_RELOC_ARM_PCREL_CALL:
17762 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17763 case BFD_RELOC_ARM_PCREL_BLX:
17764 case BFD_RELOC_ARM_PLT32:
c19d1205 17765#ifdef TE_WINCE
5f4273c7 17766 /* When handling fixups immediately, because we have already
53baae48
NC
17767 discovered the value of a symbol, or the address of the frag involved
17768 we must account for the offset by +8, as the OS loader will never see the reloc.
17769 see fixup_segment() in write.c
17770 The S_IS_EXTERNAL test handles the case of global symbols.
17771 Those need the calculated base, not just the pipe compensation the linker will need. */
17772 if (fixP->fx_pcrel
17773 && fixP->fx_addsy != NULL
17774 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17775 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17776 return base + 8;
2fc8bdac 17777 return base;
c19d1205 17778#else
2fc8bdac 17779 return base + 8;
c19d1205 17780#endif
2fc8bdac
ZW
17781
17782 /* ARM mode loads relative to PC are also offset by +8. Unlike
17783 branches, the Windows CE loader *does* expect the relocation
17784 to take this into account. */
17785 case BFD_RELOC_ARM_OFFSET_IMM:
17786 case BFD_RELOC_ARM_OFFSET_IMM8:
17787 case BFD_RELOC_ARM_HWLITERAL:
17788 case BFD_RELOC_ARM_LITERAL:
17789 case BFD_RELOC_ARM_CP_OFF_IMM:
17790 return base + 8;
17791
17792
17793 /* Other PC-relative relocations are un-offset. */
17794 default:
17795 return base;
17796 }
bfae80f2
RE
17797}
17798
c19d1205
ZW
17799/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17800 Otherwise we have no need to default values of symbols. */
17801
17802symbolS *
17803md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17804{
c19d1205
ZW
17805#ifdef OBJ_ELF
17806 if (name[0] == '_' && name[1] == 'G'
17807 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17808 {
17809 if (!GOT_symbol)
17810 {
17811 if (symbol_find (name))
bd3ba5d1 17812 as_bad (_("GOT already in the symbol table"));
bfae80f2 17813
c19d1205
ZW
17814 GOT_symbol = symbol_new (name, undefined_section,
17815 (valueT) 0, & zero_address_frag);
17816 }
bfae80f2 17817
c19d1205 17818 return GOT_symbol;
bfae80f2 17819 }
c19d1205 17820#endif
bfae80f2 17821
c19d1205 17822 return 0;
bfae80f2
RE
17823}
17824
55cf6793 17825/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17826 computed as two separate immediate values, added together. We
17827 already know that this value cannot be computed by just one ARM
17828 instruction. */
17829
17830static unsigned int
17831validate_immediate_twopart (unsigned int val,
17832 unsigned int * highpart)
bfae80f2 17833{
c19d1205
ZW
17834 unsigned int a;
17835 unsigned int i;
bfae80f2 17836
c19d1205
ZW
17837 for (i = 0; i < 32; i += 2)
17838 if (((a = rotate_left (val, i)) & 0xff) != 0)
17839 {
17840 if (a & 0xff00)
17841 {
17842 if (a & ~ 0xffff)
17843 continue;
17844 * highpart = (a >> 8) | ((i + 24) << 7);
17845 }
17846 else if (a & 0xff0000)
17847 {
17848 if (a & 0xff000000)
17849 continue;
17850 * highpart = (a >> 16) | ((i + 16) << 7);
17851 }
17852 else
17853 {
17854 assert (a & 0xff000000);
17855 * highpart = (a >> 24) | ((i + 8) << 7);
17856 }
bfae80f2 17857
c19d1205
ZW
17858 return (a & 0xff) | (i << 7);
17859 }
bfae80f2 17860
c19d1205 17861 return FAIL;
bfae80f2
RE
17862}
17863
c19d1205
ZW
17864static int
17865validate_offset_imm (unsigned int val, int hwse)
17866{
17867 if ((hwse && val > 255) || val > 4095)
17868 return FAIL;
17869 return val;
17870}
bfae80f2 17871
55cf6793 17872/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17873 negative immediate constant by altering the instruction. A bit of
17874 a hack really.
17875 MOV <-> MVN
17876 AND <-> BIC
17877 ADC <-> SBC
17878 by inverting the second operand, and
17879 ADD <-> SUB
17880 CMP <-> CMN
17881 by negating the second operand. */
bfae80f2 17882
c19d1205
ZW
17883static int
17884negate_data_op (unsigned long * instruction,
17885 unsigned long value)
bfae80f2 17886{
c19d1205
ZW
17887 int op, new_inst;
17888 unsigned long negated, inverted;
bfae80f2 17889
c19d1205
ZW
17890 negated = encode_arm_immediate (-value);
17891 inverted = encode_arm_immediate (~value);
bfae80f2 17892
c19d1205
ZW
17893 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17894 switch (op)
bfae80f2 17895 {
c19d1205
ZW
17896 /* First negates. */
17897 case OPCODE_SUB: /* ADD <-> SUB */
17898 new_inst = OPCODE_ADD;
17899 value = negated;
17900 break;
bfae80f2 17901
c19d1205
ZW
17902 case OPCODE_ADD:
17903 new_inst = OPCODE_SUB;
17904 value = negated;
17905 break;
bfae80f2 17906
c19d1205
ZW
17907 case OPCODE_CMP: /* CMP <-> CMN */
17908 new_inst = OPCODE_CMN;
17909 value = negated;
17910 break;
bfae80f2 17911
c19d1205
ZW
17912 case OPCODE_CMN:
17913 new_inst = OPCODE_CMP;
17914 value = negated;
17915 break;
bfae80f2 17916
c19d1205
ZW
17917 /* Now Inverted ops. */
17918 case OPCODE_MOV: /* MOV <-> MVN */
17919 new_inst = OPCODE_MVN;
17920 value = inverted;
17921 break;
bfae80f2 17922
c19d1205
ZW
17923 case OPCODE_MVN:
17924 new_inst = OPCODE_MOV;
17925 value = inverted;
17926 break;
bfae80f2 17927
c19d1205
ZW
17928 case OPCODE_AND: /* AND <-> BIC */
17929 new_inst = OPCODE_BIC;
17930 value = inverted;
17931 break;
bfae80f2 17932
c19d1205
ZW
17933 case OPCODE_BIC:
17934 new_inst = OPCODE_AND;
17935 value = inverted;
17936 break;
bfae80f2 17937
c19d1205
ZW
17938 case OPCODE_ADC: /* ADC <-> SBC */
17939 new_inst = OPCODE_SBC;
17940 value = inverted;
17941 break;
bfae80f2 17942
c19d1205
ZW
17943 case OPCODE_SBC:
17944 new_inst = OPCODE_ADC;
17945 value = inverted;
17946 break;
bfae80f2 17947
c19d1205
ZW
17948 /* We cannot do anything. */
17949 default:
17950 return FAIL;
b99bd4ef
NC
17951 }
17952
c19d1205
ZW
17953 if (value == (unsigned) FAIL)
17954 return FAIL;
17955
17956 *instruction &= OPCODE_MASK;
17957 *instruction |= new_inst << DATA_OP_SHIFT;
17958 return value;
b99bd4ef
NC
17959}
17960
ef8d22e6
PB
17961/* Like negate_data_op, but for Thumb-2. */
17962
17963static unsigned int
16dd5e42 17964thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17965{
17966 int op, new_inst;
17967 int rd;
16dd5e42 17968 unsigned int negated, inverted;
ef8d22e6
PB
17969
17970 negated = encode_thumb32_immediate (-value);
17971 inverted = encode_thumb32_immediate (~value);
17972
17973 rd = (*instruction >> 8) & 0xf;
17974 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17975 switch (op)
17976 {
17977 /* ADD <-> SUB. Includes CMP <-> CMN. */
17978 case T2_OPCODE_SUB:
17979 new_inst = T2_OPCODE_ADD;
17980 value = negated;
17981 break;
17982
17983 case T2_OPCODE_ADD:
17984 new_inst = T2_OPCODE_SUB;
17985 value = negated;
17986 break;
17987
17988 /* ORR <-> ORN. Includes MOV <-> MVN. */
17989 case T2_OPCODE_ORR:
17990 new_inst = T2_OPCODE_ORN;
17991 value = inverted;
17992 break;
17993
17994 case T2_OPCODE_ORN:
17995 new_inst = T2_OPCODE_ORR;
17996 value = inverted;
17997 break;
17998
17999 /* AND <-> BIC. TST has no inverted equivalent. */
18000 case T2_OPCODE_AND:
18001 new_inst = T2_OPCODE_BIC;
18002 if (rd == 15)
18003 value = FAIL;
18004 else
18005 value = inverted;
18006 break;
18007
18008 case T2_OPCODE_BIC:
18009 new_inst = T2_OPCODE_AND;
18010 value = inverted;
18011 break;
18012
18013 /* ADC <-> SBC */
18014 case T2_OPCODE_ADC:
18015 new_inst = T2_OPCODE_SBC;
18016 value = inverted;
18017 break;
18018
18019 case T2_OPCODE_SBC:
18020 new_inst = T2_OPCODE_ADC;
18021 value = inverted;
18022 break;
18023
18024 /* We cannot do anything. */
18025 default:
18026 return FAIL;
18027 }
18028
16dd5e42 18029 if (value == (unsigned int)FAIL)
ef8d22e6
PB
18030 return FAIL;
18031
18032 *instruction &= T2_OPCODE_MASK;
18033 *instruction |= new_inst << T2_DATA_OP_SHIFT;
18034 return value;
18035}
18036
8f06b2d8
PB
18037/* Read a 32-bit thumb instruction from buf. */
18038static unsigned long
18039get_thumb32_insn (char * buf)
18040{
18041 unsigned long insn;
18042 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
18043 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18044
18045 return insn;
18046}
18047
a8bc6c78
PB
18048
18049/* We usually want to set the low bit on the address of thumb function
18050 symbols. In particular .word foo - . should have the low bit set.
18051 Generic code tries to fold the difference of two symbols to
18052 a constant. Prevent this and force a relocation when the first symbols
18053 is a thumb function. */
18054int
18055arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
18056{
18057 if (op == O_subtract
18058 && l->X_op == O_symbol
18059 && r->X_op == O_symbol
18060 && THUMB_IS_FUNC (l->X_add_symbol))
18061 {
18062 l->X_op = O_subtract;
18063 l->X_op_symbol = r->X_add_symbol;
18064 l->X_add_number -= r->X_add_number;
18065 return 1;
18066 }
18067 /* Process as normal. */
18068 return 0;
18069}
18070
c19d1205 18071void
55cf6793 18072md_apply_fix (fixS * fixP,
c19d1205
ZW
18073 valueT * valP,
18074 segT seg)
18075{
18076 offsetT value = * valP;
18077 offsetT newval;
18078 unsigned int newimm;
18079 unsigned long temp;
18080 int sign;
18081 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 18082
c19d1205 18083 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 18084
c19d1205 18085 /* Note whether this will delete the relocation. */
4962c51a 18086
c19d1205
ZW
18087 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
18088 fixP->fx_done = 1;
b99bd4ef 18089
adbaf948 18090 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 18091 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
18092 for emit_reloc. */
18093 value &= 0xffffffff;
18094 value ^= 0x80000000;
5f4273c7 18095 value -= 0x80000000;
adbaf948
ZW
18096
18097 *valP = value;
c19d1205 18098 fixP->fx_addnumber = value;
b99bd4ef 18099
adbaf948
ZW
18100 /* Same treatment for fixP->fx_offset. */
18101 fixP->fx_offset &= 0xffffffff;
18102 fixP->fx_offset ^= 0x80000000;
18103 fixP->fx_offset -= 0x80000000;
18104
c19d1205 18105 switch (fixP->fx_r_type)
b99bd4ef 18106 {
c19d1205
ZW
18107 case BFD_RELOC_NONE:
18108 /* This will need to go in the object file. */
18109 fixP->fx_done = 0;
18110 break;
b99bd4ef 18111
c19d1205
ZW
18112 case BFD_RELOC_ARM_IMMEDIATE:
18113 /* We claim that this fixup has been processed here,
18114 even if in fact we generate an error because we do
18115 not have a reloc for it, so tc_gen_reloc will reject it. */
18116 fixP->fx_done = 1;
b99bd4ef 18117
c19d1205
ZW
18118 if (fixP->fx_addsy
18119 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 18120 {
c19d1205
ZW
18121 as_bad_where (fixP->fx_file, fixP->fx_line,
18122 _("undefined symbol %s used as an immediate value"),
18123 S_GET_NAME (fixP->fx_addsy));
18124 break;
b99bd4ef
NC
18125 }
18126
c19d1205
ZW
18127 newimm = encode_arm_immediate (value);
18128 temp = md_chars_to_number (buf, INSN_SIZE);
18129
18130 /* If the instruction will fail, see if we can fix things up by
18131 changing the opcode. */
18132 if (newimm == (unsigned int) FAIL
18133 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 18134 {
c19d1205
ZW
18135 as_bad_where (fixP->fx_file, fixP->fx_line,
18136 _("invalid constant (%lx) after fixup"),
18137 (unsigned long) value);
18138 break;
b99bd4ef 18139 }
b99bd4ef 18140
c19d1205
ZW
18141 newimm |= (temp & 0xfffff000);
18142 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18143 break;
b99bd4ef 18144
c19d1205
ZW
18145 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18146 {
18147 unsigned int highpart = 0;
18148 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18149
c19d1205
ZW
18150 newimm = encode_arm_immediate (value);
18151 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18152
c19d1205
ZW
18153 /* If the instruction will fail, see if we can fix things up by
18154 changing the opcode. */
18155 if (newimm == (unsigned int) FAIL
18156 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18157 {
18158 /* No ? OK - try using two ADD instructions to generate
18159 the value. */
18160 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18161
c19d1205
ZW
18162 /* Yes - then make sure that the second instruction is
18163 also an add. */
18164 if (newimm != (unsigned int) FAIL)
18165 newinsn = temp;
18166 /* Still No ? Try using a negated value. */
18167 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18168 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18169 /* Otherwise - give up. */
18170 else
18171 {
18172 as_bad_where (fixP->fx_file, fixP->fx_line,
18173 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18174 (long) value);
18175 break;
18176 }
b99bd4ef 18177
c19d1205
ZW
18178 /* Replace the first operand in the 2nd instruction (which
18179 is the PC) with the destination register. We have
18180 already added in the PC in the first instruction and we
18181 do not want to do it again. */
18182 newinsn &= ~ 0xf0000;
18183 newinsn |= ((newinsn & 0x0f000) << 4);
18184 }
b99bd4ef 18185
c19d1205
ZW
18186 newimm |= (temp & 0xfffff000);
18187 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18188
c19d1205
ZW
18189 highpart |= (newinsn & 0xfffff000);
18190 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18191 }
18192 break;
b99bd4ef 18193
c19d1205 18194 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18195 if (!fixP->fx_done && seg->use_rela_p)
18196 value = 0;
18197
c19d1205
ZW
18198 case BFD_RELOC_ARM_LITERAL:
18199 sign = value >= 0;
b99bd4ef 18200
c19d1205
ZW
18201 if (value < 0)
18202 value = - value;
b99bd4ef 18203
c19d1205 18204 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18205 {
c19d1205
ZW
18206 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18207 as_bad_where (fixP->fx_file, fixP->fx_line,
18208 _("invalid literal constant: pool needs to be closer"));
18209 else
18210 as_bad_where (fixP->fx_file, fixP->fx_line,
18211 _("bad immediate value for offset (%ld)"),
18212 (long) value);
18213 break;
f03698e6
RE
18214 }
18215
c19d1205
ZW
18216 newval = md_chars_to_number (buf, INSN_SIZE);
18217 newval &= 0xff7ff000;
18218 newval |= value | (sign ? INDEX_UP : 0);
18219 md_number_to_chars (buf, newval, INSN_SIZE);
18220 break;
b99bd4ef 18221
c19d1205
ZW
18222 case BFD_RELOC_ARM_OFFSET_IMM8:
18223 case BFD_RELOC_ARM_HWLITERAL:
18224 sign = value >= 0;
b99bd4ef 18225
c19d1205
ZW
18226 if (value < 0)
18227 value = - value;
b99bd4ef 18228
c19d1205 18229 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18230 {
c19d1205
ZW
18231 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18232 as_bad_where (fixP->fx_file, fixP->fx_line,
18233 _("invalid literal constant: pool needs to be closer"));
18234 else
f9d4405b 18235 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18236 (long) value);
18237 break;
b99bd4ef
NC
18238 }
18239
c19d1205
ZW
18240 newval = md_chars_to_number (buf, INSN_SIZE);
18241 newval &= 0xff7ff0f0;
18242 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18243 md_number_to_chars (buf, newval, INSN_SIZE);
18244 break;
b99bd4ef 18245
c19d1205
ZW
18246 case BFD_RELOC_ARM_T32_OFFSET_U8:
18247 if (value < 0 || value > 1020 || value % 4 != 0)
18248 as_bad_where (fixP->fx_file, fixP->fx_line,
18249 _("bad immediate value for offset (%ld)"), (long) value);
18250 value /= 4;
b99bd4ef 18251
c19d1205 18252 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18253 newval |= value;
18254 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18255 break;
b99bd4ef 18256
c19d1205
ZW
18257 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18258 /* This is a complicated relocation used for all varieties of Thumb32
18259 load/store instruction with immediate offset:
18260
18261 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18262 *4, optional writeback(W)
18263 (doubleword load/store)
18264
18265 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18266 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18267 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18268 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18269 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18270
18271 Uppercase letters indicate bits that are already encoded at
18272 this point. Lowercase letters are our problem. For the
18273 second block of instructions, the secondary opcode nybble
18274 (bits 8..11) is present, and bit 23 is zero, even if this is
18275 a PC-relative operation. */
18276 newval = md_chars_to_number (buf, THUMB_SIZE);
18277 newval <<= 16;
18278 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18279
c19d1205 18280 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18281 {
c19d1205
ZW
18282 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18283 if (value >= 0)
18284 newval |= (1 << 23);
18285 else
18286 value = -value;
18287 if (value % 4 != 0)
18288 {
18289 as_bad_where (fixP->fx_file, fixP->fx_line,
18290 _("offset not a multiple of 4"));
18291 break;
18292 }
18293 value /= 4;
216d22bc 18294 if (value > 0xff)
c19d1205
ZW
18295 {
18296 as_bad_where (fixP->fx_file, fixP->fx_line,
18297 _("offset out of range"));
18298 break;
18299 }
18300 newval &= ~0xff;
b99bd4ef 18301 }
c19d1205 18302 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18303 {
c19d1205
ZW
18304 /* PC-relative, 12-bit offset. */
18305 if (value >= 0)
18306 newval |= (1 << 23);
18307 else
18308 value = -value;
216d22bc 18309 if (value > 0xfff)
c19d1205
ZW
18310 {
18311 as_bad_where (fixP->fx_file, fixP->fx_line,
18312 _("offset out of range"));
18313 break;
18314 }
18315 newval &= ~0xfff;
b99bd4ef 18316 }
c19d1205 18317 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18318 {
c19d1205
ZW
18319 /* Writeback: 8-bit, +/- offset. */
18320 if (value >= 0)
18321 newval |= (1 << 9);
18322 else
18323 value = -value;
216d22bc 18324 if (value > 0xff)
c19d1205
ZW
18325 {
18326 as_bad_where (fixP->fx_file, fixP->fx_line,
18327 _("offset out of range"));
18328 break;
18329 }
18330 newval &= ~0xff;
b99bd4ef 18331 }
c19d1205 18332 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18333 {
c19d1205 18334 /* T-instruction: positive 8-bit offset. */
216d22bc 18335 if (value < 0 || value > 0xff)
b99bd4ef 18336 {
c19d1205
ZW
18337 as_bad_where (fixP->fx_file, fixP->fx_line,
18338 _("offset out of range"));
18339 break;
b99bd4ef 18340 }
c19d1205
ZW
18341 newval &= ~0xff;
18342 newval |= value;
b99bd4ef
NC
18343 }
18344 else
b99bd4ef 18345 {
c19d1205
ZW
18346 /* Positive 12-bit or negative 8-bit offset. */
18347 int limit;
18348 if (value >= 0)
b99bd4ef 18349 {
c19d1205
ZW
18350 newval |= (1 << 23);
18351 limit = 0xfff;
18352 }
18353 else
18354 {
18355 value = -value;
18356 limit = 0xff;
18357 }
18358 if (value > limit)
18359 {
18360 as_bad_where (fixP->fx_file, fixP->fx_line,
18361 _("offset out of range"));
18362 break;
b99bd4ef 18363 }
c19d1205 18364 newval &= ~limit;
b99bd4ef 18365 }
b99bd4ef 18366
c19d1205
ZW
18367 newval |= value;
18368 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18369 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18370 break;
404ff6b5 18371
c19d1205
ZW
18372 case BFD_RELOC_ARM_SHIFT_IMM:
18373 newval = md_chars_to_number (buf, INSN_SIZE);
18374 if (((unsigned long) value) > 32
18375 || (value == 32
18376 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18377 {
18378 as_bad_where (fixP->fx_file, fixP->fx_line,
18379 _("shift expression is too large"));
18380 break;
18381 }
404ff6b5 18382
c19d1205
ZW
18383 if (value == 0)
18384 /* Shifts of zero must be done as lsl. */
18385 newval &= ~0x60;
18386 else if (value == 32)
18387 value = 0;
18388 newval &= 0xfffff07f;
18389 newval |= (value & 0x1f) << 7;
18390 md_number_to_chars (buf, newval, INSN_SIZE);
18391 break;
404ff6b5 18392
c19d1205 18393 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18394 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18395 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18396 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18397 /* We claim that this fixup has been processed here,
18398 even if in fact we generate an error because we do
18399 not have a reloc for it, so tc_gen_reloc will reject it. */
18400 fixP->fx_done = 1;
404ff6b5 18401
c19d1205
ZW
18402 if (fixP->fx_addsy
18403 && ! S_IS_DEFINED (fixP->fx_addsy))
18404 {
18405 as_bad_where (fixP->fx_file, fixP->fx_line,
18406 _("undefined symbol %s used as an immediate value"),
18407 S_GET_NAME (fixP->fx_addsy));
18408 break;
18409 }
404ff6b5 18410
c19d1205
ZW
18411 newval = md_chars_to_number (buf, THUMB_SIZE);
18412 newval <<= 16;
18413 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18414
16805f35
PB
18415 newimm = FAIL;
18416 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18417 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18418 {
18419 newimm = encode_thumb32_immediate (value);
18420 if (newimm == (unsigned int) FAIL)
18421 newimm = thumb32_negate_data_op (&newval, value);
18422 }
16805f35
PB
18423 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18424 && newimm == (unsigned int) FAIL)
92e90b6e 18425 {
16805f35
PB
18426 /* Turn add/sum into addw/subw. */
18427 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18428 newval = (newval & 0xfeffffff) | 0x02000000;
18429
e9f89963
PB
18430 /* 12 bit immediate for addw/subw. */
18431 if (value < 0)
18432 {
18433 value = -value;
18434 newval ^= 0x00a00000;
18435 }
92e90b6e
PB
18436 if (value > 0xfff)
18437 newimm = (unsigned int) FAIL;
18438 else
18439 newimm = value;
18440 }
cc8a6dd0 18441
c19d1205 18442 if (newimm == (unsigned int)FAIL)
3631a3c8 18443 {
c19d1205
ZW
18444 as_bad_where (fixP->fx_file, fixP->fx_line,
18445 _("invalid constant (%lx) after fixup"),
18446 (unsigned long) value);
18447 break;
3631a3c8
NC
18448 }
18449
c19d1205
ZW
18450 newval |= (newimm & 0x800) << 15;
18451 newval |= (newimm & 0x700) << 4;
18452 newval |= (newimm & 0x0ff);
cc8a6dd0 18453
c19d1205
ZW
18454 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18455 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18456 break;
a737bd4d 18457
3eb17e6b 18458 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18459 if (((unsigned long) value) > 0xffff)
18460 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18461 _("invalid smc expression"));
2fc8bdac 18462 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18463 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18464 md_number_to_chars (buf, newval, INSN_SIZE);
18465 break;
a737bd4d 18466
c19d1205 18467 case BFD_RELOC_ARM_SWI:
adbaf948 18468 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18469 {
18470 if (((unsigned long) value) > 0xff)
18471 as_bad_where (fixP->fx_file, fixP->fx_line,
18472 _("invalid swi expression"));
2fc8bdac 18473 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18474 newval |= value;
18475 md_number_to_chars (buf, newval, THUMB_SIZE);
18476 }
18477 else
18478 {
18479 if (((unsigned long) value) > 0x00ffffff)
18480 as_bad_where (fixP->fx_file, fixP->fx_line,
18481 _("invalid swi expression"));
2fc8bdac 18482 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18483 newval |= value;
18484 md_number_to_chars (buf, newval, INSN_SIZE);
18485 }
18486 break;
a737bd4d 18487
c19d1205
ZW
18488 case BFD_RELOC_ARM_MULTI:
18489 if (((unsigned long) value) > 0xffff)
18490 as_bad_where (fixP->fx_file, fixP->fx_line,
18491 _("invalid expression in load/store multiple"));
18492 newval = value | md_chars_to_number (buf, INSN_SIZE);
18493 md_number_to_chars (buf, newval, INSN_SIZE);
18494 break;
a737bd4d 18495
c19d1205 18496#ifdef OBJ_ELF
39b41c9c
PB
18497 case BFD_RELOC_ARM_PCREL_CALL:
18498 newval = md_chars_to_number (buf, INSN_SIZE);
18499 if ((newval & 0xf0000000) == 0xf0000000)
18500 temp = 1;
18501 else
18502 temp = 3;
18503 goto arm_branch_common;
18504
18505 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18506 case BFD_RELOC_ARM_PLT32:
c19d1205 18507#endif
39b41c9c
PB
18508 case BFD_RELOC_ARM_PCREL_BRANCH:
18509 temp = 3;
18510 goto arm_branch_common;
a737bd4d 18511
39b41c9c
PB
18512 case BFD_RELOC_ARM_PCREL_BLX:
18513 temp = 1;
18514 arm_branch_common:
c19d1205 18515 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18516 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18517 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18518 also be be clear. */
18519 if (value & temp)
c19d1205 18520 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18521 _("misaligned branch destination"));
18522 if ((value & (offsetT)0xfe000000) != (offsetT)0
18523 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18524 as_bad_where (fixP->fx_file, fixP->fx_line,
18525 _("branch out of range"));
a737bd4d 18526
2fc8bdac 18527 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18528 {
2fc8bdac
ZW
18529 newval = md_chars_to_number (buf, INSN_SIZE);
18530 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18531 /* Set the H bit on BLX instructions. */
18532 if (temp == 1)
18533 {
18534 if (value & 2)
18535 newval |= 0x01000000;
18536 else
18537 newval &= ~0x01000000;
18538 }
2fc8bdac 18539 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18540 }
c19d1205 18541 break;
a737bd4d 18542
25fe350b
MS
18543 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18544 /* CBZ can only branch forward. */
a737bd4d 18545
738755b0
MS
18546 /* Attempts to use CBZ to branch to the next instruction
18547 (which, strictly speaking, are prohibited) will be turned into
18548 no-ops.
18549
18550 FIXME: It may be better to remove the instruction completely and
18551 perform relaxation. */
18552 if (value == -2)
2fc8bdac
ZW
18553 {
18554 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18555 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18556 md_number_to_chars (buf, newval, THUMB_SIZE);
18557 }
738755b0
MS
18558 else
18559 {
18560 if (value & ~0x7e)
18561 as_bad_where (fixP->fx_file, fixP->fx_line,
18562 _("branch out of range"));
18563
18564 if (fixP->fx_done || !seg->use_rela_p)
18565 {
18566 newval = md_chars_to_number (buf, THUMB_SIZE);
18567 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18568 md_number_to_chars (buf, newval, THUMB_SIZE);
18569 }
18570 }
c19d1205 18571 break;
a737bd4d 18572
c19d1205 18573 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18574 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18575 as_bad_where (fixP->fx_file, fixP->fx_line,
18576 _("branch out of range"));
a737bd4d 18577
2fc8bdac
ZW
18578 if (fixP->fx_done || !seg->use_rela_p)
18579 {
18580 newval = md_chars_to_number (buf, THUMB_SIZE);
18581 newval |= (value & 0x1ff) >> 1;
18582 md_number_to_chars (buf, newval, THUMB_SIZE);
18583 }
c19d1205 18584 break;
a737bd4d 18585
c19d1205 18586 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18587 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18588 as_bad_where (fixP->fx_file, fixP->fx_line,
18589 _("branch out of range"));
a737bd4d 18590
2fc8bdac
ZW
18591 if (fixP->fx_done || !seg->use_rela_p)
18592 {
18593 newval = md_chars_to_number (buf, THUMB_SIZE);
18594 newval |= (value & 0xfff) >> 1;
18595 md_number_to_chars (buf, newval, THUMB_SIZE);
18596 }
c19d1205 18597 break;
a737bd4d 18598
c19d1205 18599 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18600 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18601 as_bad_where (fixP->fx_file, fixP->fx_line,
18602 _("conditional branch out of range"));
404ff6b5 18603
2fc8bdac
ZW
18604 if (fixP->fx_done || !seg->use_rela_p)
18605 {
18606 offsetT newval2;
18607 addressT S, J1, J2, lo, hi;
404ff6b5 18608
2fc8bdac
ZW
18609 S = (value & 0x00100000) >> 20;
18610 J2 = (value & 0x00080000) >> 19;
18611 J1 = (value & 0x00040000) >> 18;
18612 hi = (value & 0x0003f000) >> 12;
18613 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18614
2fc8bdac
ZW
18615 newval = md_chars_to_number (buf, THUMB_SIZE);
18616 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18617 newval |= (S << 10) | hi;
18618 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18619 md_number_to_chars (buf, newval, THUMB_SIZE);
18620 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18621 }
c19d1205 18622 break;
6c43fab6 18623
c19d1205
ZW
18624 case BFD_RELOC_THUMB_PCREL_BLX:
18625 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18626 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18627 as_bad_where (fixP->fx_file, fixP->fx_line,
18628 _("branch out of range"));
404ff6b5 18629
2fc8bdac
ZW
18630 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18631 /* For a BLX instruction, make sure that the relocation is rounded up
18632 to a word boundary. This follows the semantics of the instruction
18633 which specifies that bit 1 of the target address will come from bit
18634 1 of the base address. */
18635 value = (value + 1) & ~ 1;
404ff6b5 18636
2fc8bdac 18637 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18638 {
2fc8bdac
ZW
18639 offsetT newval2;
18640
18641 newval = md_chars_to_number (buf, THUMB_SIZE);
18642 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18643 newval |= (value & 0x7fffff) >> 12;
18644 newval2 |= (value & 0xfff) >> 1;
18645 md_number_to_chars (buf, newval, THUMB_SIZE);
18646 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18647 }
c19d1205 18648 break;
404ff6b5 18649
c19d1205 18650 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18651 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18652 as_bad_where (fixP->fx_file, fixP->fx_line,
18653 _("branch out of range"));
6c43fab6 18654
2fc8bdac
ZW
18655 if (fixP->fx_done || !seg->use_rela_p)
18656 {
18657 offsetT newval2;
18658 addressT S, I1, I2, lo, hi;
6c43fab6 18659
2fc8bdac
ZW
18660 S = (value & 0x01000000) >> 24;
18661 I1 = (value & 0x00800000) >> 23;
18662 I2 = (value & 0x00400000) >> 22;
18663 hi = (value & 0x003ff000) >> 12;
18664 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18665
2fc8bdac
ZW
18666 I1 = !(I1 ^ S);
18667 I2 = !(I2 ^ S);
a737bd4d 18668
2fc8bdac
ZW
18669 newval = md_chars_to_number (buf, THUMB_SIZE);
18670 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18671 newval |= (S << 10) | hi;
18672 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18673 md_number_to_chars (buf, newval, THUMB_SIZE);
18674 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18675 }
18676 break;
a737bd4d 18677
2fc8bdac
ZW
18678 case BFD_RELOC_8:
18679 if (fixP->fx_done || !seg->use_rela_p)
18680 md_number_to_chars (buf, value, 1);
c19d1205 18681 break;
a737bd4d 18682
c19d1205 18683 case BFD_RELOC_16:
2fc8bdac 18684 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18685 md_number_to_chars (buf, value, 2);
c19d1205 18686 break;
a737bd4d 18687
c19d1205
ZW
18688#ifdef OBJ_ELF
18689 case BFD_RELOC_ARM_TLS_GD32:
18690 case BFD_RELOC_ARM_TLS_LE32:
18691 case BFD_RELOC_ARM_TLS_IE32:
18692 case BFD_RELOC_ARM_TLS_LDM32:
18693 case BFD_RELOC_ARM_TLS_LDO32:
18694 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18695 /* fall through */
6c43fab6 18696
c19d1205
ZW
18697 case BFD_RELOC_ARM_GOT32:
18698 case BFD_RELOC_ARM_GOTOFF:
18699 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18700 if (fixP->fx_done || !seg->use_rela_p)
18701 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18702 break;
18703#endif
6c43fab6 18704
c19d1205
ZW
18705 case BFD_RELOC_RVA:
18706 case BFD_RELOC_32:
18707 case BFD_RELOC_ARM_TARGET1:
18708 case BFD_RELOC_ARM_ROSEGREL32:
18709 case BFD_RELOC_ARM_SBREL32:
18710 case BFD_RELOC_32_PCREL:
f0927246
NC
18711#ifdef TE_PE
18712 case BFD_RELOC_32_SECREL:
18713#endif
2fc8bdac 18714 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18715#ifdef TE_WINCE
18716 /* For WinCE we only do this for pcrel fixups. */
18717 if (fixP->fx_done || fixP->fx_pcrel)
18718#endif
18719 md_number_to_chars (buf, value, 4);
c19d1205 18720 break;
6c43fab6 18721
c19d1205
ZW
18722#ifdef OBJ_ELF
18723 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18724 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18725 {
18726 newval = md_chars_to_number (buf, 4) & 0x80000000;
18727 if ((value ^ (value >> 1)) & 0x40000000)
18728 {
18729 as_bad_where (fixP->fx_file, fixP->fx_line,
18730 _("rel31 relocation overflow"));
18731 }
18732 newval |= value & 0x7fffffff;
18733 md_number_to_chars (buf, newval, 4);
18734 }
18735 break;
c19d1205 18736#endif
a737bd4d 18737
c19d1205 18738 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18739 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18740 if (value < -1023 || value > 1023 || (value & 3))
18741 as_bad_where (fixP->fx_file, fixP->fx_line,
18742 _("co-processor offset out of range"));
18743 cp_off_common:
18744 sign = value >= 0;
18745 if (value < 0)
18746 value = -value;
8f06b2d8
PB
18747 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18748 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18749 newval = md_chars_to_number (buf, INSN_SIZE);
18750 else
18751 newval = get_thumb32_insn (buf);
18752 newval &= 0xff7fff00;
c19d1205 18753 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18754 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18755 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18756 md_number_to_chars (buf, newval, INSN_SIZE);
18757 else
18758 put_thumb32_insn (buf, newval);
c19d1205 18759 break;
a737bd4d 18760
c19d1205 18761 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18762 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18763 if (value < -255 || value > 255)
18764 as_bad_where (fixP->fx_file, fixP->fx_line,
18765 _("co-processor offset out of range"));
df7849c5 18766 value *= 4;
c19d1205 18767 goto cp_off_common;
6c43fab6 18768
c19d1205
ZW
18769 case BFD_RELOC_ARM_THUMB_OFFSET:
18770 newval = md_chars_to_number (buf, THUMB_SIZE);
18771 /* Exactly what ranges, and where the offset is inserted depends
18772 on the type of instruction, we can establish this from the
18773 top 4 bits. */
18774 switch (newval >> 12)
18775 {
18776 case 4: /* PC load. */
18777 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18778 forced to zero for these loads; md_pcrel_from has already
18779 compensated for this. */
18780 if (value & 3)
18781 as_bad_where (fixP->fx_file, fixP->fx_line,
18782 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18783 (((unsigned long) fixP->fx_frag->fr_address
18784 + (unsigned long) fixP->fx_where) & ~3)
18785 + (unsigned long) value);
a737bd4d 18786
c19d1205
ZW
18787 if (value & ~0x3fc)
18788 as_bad_where (fixP->fx_file, fixP->fx_line,
18789 _("invalid offset, value too big (0x%08lX)"),
18790 (long) value);
a737bd4d 18791
c19d1205
ZW
18792 newval |= value >> 2;
18793 break;
a737bd4d 18794
c19d1205
ZW
18795 case 9: /* SP load/store. */
18796 if (value & ~0x3fc)
18797 as_bad_where (fixP->fx_file, fixP->fx_line,
18798 _("invalid offset, value too big (0x%08lX)"),
18799 (long) value);
18800 newval |= value >> 2;
18801 break;
6c43fab6 18802
c19d1205
ZW
18803 case 6: /* Word load/store. */
18804 if (value & ~0x7c)
18805 as_bad_where (fixP->fx_file, fixP->fx_line,
18806 _("invalid offset, value too big (0x%08lX)"),
18807 (long) value);
18808 newval |= value << 4; /* 6 - 2. */
18809 break;
a737bd4d 18810
c19d1205
ZW
18811 case 7: /* Byte load/store. */
18812 if (value & ~0x1f)
18813 as_bad_where (fixP->fx_file, fixP->fx_line,
18814 _("invalid offset, value too big (0x%08lX)"),
18815 (long) value);
18816 newval |= value << 6;
18817 break;
a737bd4d 18818
c19d1205
ZW
18819 case 8: /* Halfword load/store. */
18820 if (value & ~0x3e)
18821 as_bad_where (fixP->fx_file, fixP->fx_line,
18822 _("invalid offset, value too big (0x%08lX)"),
18823 (long) value);
18824 newval |= value << 5; /* 6 - 1. */
18825 break;
a737bd4d 18826
c19d1205
ZW
18827 default:
18828 as_bad_where (fixP->fx_file, fixP->fx_line,
18829 "Unable to process relocation for thumb opcode: %lx",
18830 (unsigned long) newval);
18831 break;
18832 }
18833 md_number_to_chars (buf, newval, THUMB_SIZE);
18834 break;
a737bd4d 18835
c19d1205
ZW
18836 case BFD_RELOC_ARM_THUMB_ADD:
18837 /* This is a complicated relocation, since we use it for all of
18838 the following immediate relocations:
a737bd4d 18839
c19d1205
ZW
18840 3bit ADD/SUB
18841 8bit ADD/SUB
18842 9bit ADD/SUB SP word-aligned
18843 10bit ADD PC/SP word-aligned
a737bd4d 18844
c19d1205
ZW
18845 The type of instruction being processed is encoded in the
18846 instruction field:
a737bd4d 18847
c19d1205
ZW
18848 0x8000 SUB
18849 0x00F0 Rd
18850 0x000F Rs
18851 */
18852 newval = md_chars_to_number (buf, THUMB_SIZE);
18853 {
18854 int rd = (newval >> 4) & 0xf;
18855 int rs = newval & 0xf;
18856 int subtract = !!(newval & 0x8000);
a737bd4d 18857
c19d1205
ZW
18858 /* Check for HI regs, only very restricted cases allowed:
18859 Adjusting SP, and using PC or SP to get an address. */
18860 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18861 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18862 as_bad_where (fixP->fx_file, fixP->fx_line,
18863 _("invalid Hi register with immediate"));
a737bd4d 18864
c19d1205
ZW
18865 /* If value is negative, choose the opposite instruction. */
18866 if (value < 0)
18867 {
18868 value = -value;
18869 subtract = !subtract;
18870 if (value < 0)
18871 as_bad_where (fixP->fx_file, fixP->fx_line,
18872 _("immediate value out of range"));
18873 }
a737bd4d 18874
c19d1205
ZW
18875 if (rd == REG_SP)
18876 {
18877 if (value & ~0x1fc)
18878 as_bad_where (fixP->fx_file, fixP->fx_line,
18879 _("invalid immediate for stack address calculation"));
18880 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18881 newval |= value >> 2;
18882 }
18883 else if (rs == REG_PC || rs == REG_SP)
18884 {
18885 if (subtract || value & ~0x3fc)
18886 as_bad_where (fixP->fx_file, fixP->fx_line,
18887 _("invalid immediate for address calculation (value = 0x%08lX)"),
18888 (unsigned long) value);
18889 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18890 newval |= rd << 8;
18891 newval |= value >> 2;
18892 }
18893 else if (rs == rd)
18894 {
18895 if (value & ~0xff)
18896 as_bad_where (fixP->fx_file, fixP->fx_line,
18897 _("immediate value out of range"));
18898 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18899 newval |= (rd << 8) | value;
18900 }
18901 else
18902 {
18903 if (value & ~0x7)
18904 as_bad_where (fixP->fx_file, fixP->fx_line,
18905 _("immediate value out of range"));
18906 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18907 newval |= rd | (rs << 3) | (value << 6);
18908 }
18909 }
18910 md_number_to_chars (buf, newval, THUMB_SIZE);
18911 break;
a737bd4d 18912
c19d1205
ZW
18913 case BFD_RELOC_ARM_THUMB_IMM:
18914 newval = md_chars_to_number (buf, THUMB_SIZE);
18915 if (value < 0 || value > 255)
18916 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 18917 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
18918 (long) value);
18919 newval |= value;
18920 md_number_to_chars (buf, newval, THUMB_SIZE);
18921 break;
a737bd4d 18922
c19d1205
ZW
18923 case BFD_RELOC_ARM_THUMB_SHIFT:
18924 /* 5bit shift value (0..32). LSL cannot take 32. */
18925 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18926 temp = newval & 0xf800;
18927 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18928 as_bad_where (fixP->fx_file, fixP->fx_line,
18929 _("invalid shift value: %ld"), (long) value);
18930 /* Shifts of zero must be encoded as LSL. */
18931 if (value == 0)
18932 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18933 /* Shifts of 32 are encoded as zero. */
18934 else if (value == 32)
18935 value = 0;
18936 newval |= value << 6;
18937 md_number_to_chars (buf, newval, THUMB_SIZE);
18938 break;
a737bd4d 18939
c19d1205
ZW
18940 case BFD_RELOC_VTABLE_INHERIT:
18941 case BFD_RELOC_VTABLE_ENTRY:
18942 fixP->fx_done = 0;
18943 return;
6c43fab6 18944
b6895b4f
PB
18945 case BFD_RELOC_ARM_MOVW:
18946 case BFD_RELOC_ARM_MOVT:
18947 case BFD_RELOC_ARM_THUMB_MOVW:
18948 case BFD_RELOC_ARM_THUMB_MOVT:
18949 if (fixP->fx_done || !seg->use_rela_p)
18950 {
18951 /* REL format relocations are limited to a 16-bit addend. */
18952 if (!fixP->fx_done)
18953 {
39623e12 18954 if (value < -0x8000 || value > 0x7fff)
b6895b4f 18955 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 18956 _("offset out of range"));
b6895b4f
PB
18957 }
18958 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18959 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18960 {
18961 value >>= 16;
18962 }
18963
18964 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18965 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18966 {
18967 newval = get_thumb32_insn (buf);
18968 newval &= 0xfbf08f00;
18969 newval |= (value & 0xf000) << 4;
18970 newval |= (value & 0x0800) << 15;
18971 newval |= (value & 0x0700) << 4;
18972 newval |= (value & 0x00ff);
18973 put_thumb32_insn (buf, newval);
18974 }
18975 else
18976 {
18977 newval = md_chars_to_number (buf, 4);
18978 newval &= 0xfff0f000;
18979 newval |= value & 0x0fff;
18980 newval |= (value & 0xf000) << 4;
18981 md_number_to_chars (buf, newval, 4);
18982 }
18983 }
18984 return;
18985
4962c51a
MS
18986 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18987 case BFD_RELOC_ARM_ALU_PC_G0:
18988 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18989 case BFD_RELOC_ARM_ALU_PC_G1:
18990 case BFD_RELOC_ARM_ALU_PC_G2:
18991 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18992 case BFD_RELOC_ARM_ALU_SB_G0:
18993 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18994 case BFD_RELOC_ARM_ALU_SB_G1:
18995 case BFD_RELOC_ARM_ALU_SB_G2:
18996 assert (!fixP->fx_done);
18997 if (!seg->use_rela_p)
18998 {
18999 bfd_vma insn;
19000 bfd_vma encoded_addend;
19001 bfd_vma addend_abs = abs (value);
19002
19003 /* Check that the absolute value of the addend can be
19004 expressed as an 8-bit constant plus a rotation. */
19005 encoded_addend = encode_arm_immediate (addend_abs);
19006 if (encoded_addend == (unsigned int) FAIL)
19007 as_bad_where (fixP->fx_file, fixP->fx_line,
19008 _("the offset 0x%08lX is not representable"),
495bde8e 19009 (unsigned long) addend_abs);
4962c51a
MS
19010
19011 /* Extract the instruction. */
19012 insn = md_chars_to_number (buf, INSN_SIZE);
19013
19014 /* If the addend is positive, use an ADD instruction.
19015 Otherwise use a SUB. Take care not to destroy the S bit. */
19016 insn &= 0xff1fffff;
19017 if (value < 0)
19018 insn |= 1 << 22;
19019 else
19020 insn |= 1 << 23;
19021
19022 /* Place the encoded addend into the first 12 bits of the
19023 instruction. */
19024 insn &= 0xfffff000;
19025 insn |= encoded_addend;
5f4273c7
NC
19026
19027 /* Update the instruction. */
4962c51a
MS
19028 md_number_to_chars (buf, insn, INSN_SIZE);
19029 }
19030 break;
19031
19032 case BFD_RELOC_ARM_LDR_PC_G0:
19033 case BFD_RELOC_ARM_LDR_PC_G1:
19034 case BFD_RELOC_ARM_LDR_PC_G2:
19035 case BFD_RELOC_ARM_LDR_SB_G0:
19036 case BFD_RELOC_ARM_LDR_SB_G1:
19037 case BFD_RELOC_ARM_LDR_SB_G2:
19038 assert (!fixP->fx_done);
19039 if (!seg->use_rela_p)
19040 {
19041 bfd_vma insn;
19042 bfd_vma addend_abs = abs (value);
19043
19044 /* Check that the absolute value of the addend can be
19045 encoded in 12 bits. */
19046 if (addend_abs >= 0x1000)
19047 as_bad_where (fixP->fx_file, fixP->fx_line,
19048 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 19049 (unsigned long) addend_abs);
4962c51a
MS
19050
19051 /* Extract the instruction. */
19052 insn = md_chars_to_number (buf, INSN_SIZE);
19053
19054 /* If the addend is negative, clear bit 23 of the instruction.
19055 Otherwise set it. */
19056 if (value < 0)
19057 insn &= ~(1 << 23);
19058 else
19059 insn |= 1 << 23;
19060
19061 /* Place the absolute value of the addend into the first 12 bits
19062 of the instruction. */
19063 insn &= 0xfffff000;
19064 insn |= addend_abs;
5f4273c7
NC
19065
19066 /* Update the instruction. */
4962c51a
MS
19067 md_number_to_chars (buf, insn, INSN_SIZE);
19068 }
19069 break;
19070
19071 case BFD_RELOC_ARM_LDRS_PC_G0:
19072 case BFD_RELOC_ARM_LDRS_PC_G1:
19073 case BFD_RELOC_ARM_LDRS_PC_G2:
19074 case BFD_RELOC_ARM_LDRS_SB_G0:
19075 case BFD_RELOC_ARM_LDRS_SB_G1:
19076 case BFD_RELOC_ARM_LDRS_SB_G2:
19077 assert (!fixP->fx_done);
19078 if (!seg->use_rela_p)
19079 {
19080 bfd_vma insn;
19081 bfd_vma addend_abs = abs (value);
19082
19083 /* Check that the absolute value of the addend can be
19084 encoded in 8 bits. */
19085 if (addend_abs >= 0x100)
19086 as_bad_where (fixP->fx_file, fixP->fx_line,
19087 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 19088 (unsigned long) addend_abs);
4962c51a
MS
19089
19090 /* Extract the instruction. */
19091 insn = md_chars_to_number (buf, INSN_SIZE);
19092
19093 /* If the addend is negative, clear bit 23 of the instruction.
19094 Otherwise set it. */
19095 if (value < 0)
19096 insn &= ~(1 << 23);
19097 else
19098 insn |= 1 << 23;
19099
19100 /* Place the first four bits of the absolute value of the addend
19101 into the first 4 bits of the instruction, and the remaining
19102 four into bits 8 .. 11. */
19103 insn &= 0xfffff0f0;
19104 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
19105
19106 /* Update the instruction. */
4962c51a
MS
19107 md_number_to_chars (buf, insn, INSN_SIZE);
19108 }
19109 break;
19110
19111 case BFD_RELOC_ARM_LDC_PC_G0:
19112 case BFD_RELOC_ARM_LDC_PC_G1:
19113 case BFD_RELOC_ARM_LDC_PC_G2:
19114 case BFD_RELOC_ARM_LDC_SB_G0:
19115 case BFD_RELOC_ARM_LDC_SB_G1:
19116 case BFD_RELOC_ARM_LDC_SB_G2:
19117 assert (!fixP->fx_done);
19118 if (!seg->use_rela_p)
19119 {
19120 bfd_vma insn;
19121 bfd_vma addend_abs = abs (value);
19122
19123 /* Check that the absolute value of the addend is a multiple of
19124 four and, when divided by four, fits in 8 bits. */
19125 if (addend_abs & 0x3)
19126 as_bad_where (fixP->fx_file, fixP->fx_line,
19127 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 19128 (unsigned long) addend_abs);
4962c51a
MS
19129
19130 if ((addend_abs >> 2) > 0xff)
19131 as_bad_where (fixP->fx_file, fixP->fx_line,
19132 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 19133 (unsigned long) addend_abs);
4962c51a
MS
19134
19135 /* Extract the instruction. */
19136 insn = md_chars_to_number (buf, INSN_SIZE);
19137
19138 /* If the addend is negative, clear bit 23 of the instruction.
19139 Otherwise set it. */
19140 if (value < 0)
19141 insn &= ~(1 << 23);
19142 else
19143 insn |= 1 << 23;
19144
19145 /* Place the addend (divided by four) into the first eight
19146 bits of the instruction. */
19147 insn &= 0xfffffff0;
19148 insn |= addend_abs >> 2;
5f4273c7
NC
19149
19150 /* Update the instruction. */
4962c51a
MS
19151 md_number_to_chars (buf, insn, INSN_SIZE);
19152 }
19153 break;
19154
845b51d6
PB
19155 case BFD_RELOC_ARM_V4BX:
19156 /* This will need to go in the object file. */
19157 fixP->fx_done = 0;
19158 break;
19159
c19d1205
ZW
19160 case BFD_RELOC_UNUSED:
19161 default:
19162 as_bad_where (fixP->fx_file, fixP->fx_line,
19163 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19164 }
6c43fab6
RE
19165}
19166
c19d1205
ZW
19167/* Translate internal representation of relocation info to BFD target
19168 format. */
a737bd4d 19169
c19d1205 19170arelent *
00a97672 19171tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19172{
c19d1205
ZW
19173 arelent * reloc;
19174 bfd_reloc_code_real_type code;
a737bd4d 19175
c19d1205 19176 reloc = xmalloc (sizeof (arelent));
a737bd4d 19177
c19d1205
ZW
19178 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19179 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19180 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19181
2fc8bdac 19182 if (fixp->fx_pcrel)
00a97672
RS
19183 {
19184 if (section->use_rela_p)
19185 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19186 else
19187 fixp->fx_offset = reloc->address;
19188 }
c19d1205 19189 reloc->addend = fixp->fx_offset;
a737bd4d 19190
c19d1205 19191 switch (fixp->fx_r_type)
a737bd4d 19192 {
c19d1205
ZW
19193 case BFD_RELOC_8:
19194 if (fixp->fx_pcrel)
19195 {
19196 code = BFD_RELOC_8_PCREL;
19197 break;
19198 }
a737bd4d 19199
c19d1205
ZW
19200 case BFD_RELOC_16:
19201 if (fixp->fx_pcrel)
19202 {
19203 code = BFD_RELOC_16_PCREL;
19204 break;
19205 }
6c43fab6 19206
c19d1205
ZW
19207 case BFD_RELOC_32:
19208 if (fixp->fx_pcrel)
19209 {
19210 code = BFD_RELOC_32_PCREL;
19211 break;
19212 }
a737bd4d 19213
b6895b4f
PB
19214 case BFD_RELOC_ARM_MOVW:
19215 if (fixp->fx_pcrel)
19216 {
19217 code = BFD_RELOC_ARM_MOVW_PCREL;
19218 break;
19219 }
19220
19221 case BFD_RELOC_ARM_MOVT:
19222 if (fixp->fx_pcrel)
19223 {
19224 code = BFD_RELOC_ARM_MOVT_PCREL;
19225 break;
19226 }
19227
19228 case BFD_RELOC_ARM_THUMB_MOVW:
19229 if (fixp->fx_pcrel)
19230 {
19231 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19232 break;
19233 }
19234
19235 case BFD_RELOC_ARM_THUMB_MOVT:
19236 if (fixp->fx_pcrel)
19237 {
19238 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19239 break;
19240 }
19241
c19d1205
ZW
19242 case BFD_RELOC_NONE:
19243 case BFD_RELOC_ARM_PCREL_BRANCH:
19244 case BFD_RELOC_ARM_PCREL_BLX:
19245 case BFD_RELOC_RVA:
19246 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19247 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19248 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19249 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19250 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19251 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19252 case BFD_RELOC_THUMB_PCREL_BLX:
19253 case BFD_RELOC_VTABLE_ENTRY:
19254 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19255#ifdef TE_PE
19256 case BFD_RELOC_32_SECREL:
19257#endif
c19d1205
ZW
19258 code = fixp->fx_r_type;
19259 break;
a737bd4d 19260
c19d1205
ZW
19261 case BFD_RELOC_ARM_LITERAL:
19262 case BFD_RELOC_ARM_HWLITERAL:
19263 /* If this is called then the a literal has
19264 been referenced across a section boundary. */
19265 as_bad_where (fixp->fx_file, fixp->fx_line,
19266 _("literal referenced across section boundary"));
19267 return NULL;
a737bd4d 19268
c19d1205
ZW
19269#ifdef OBJ_ELF
19270 case BFD_RELOC_ARM_GOT32:
19271 case BFD_RELOC_ARM_GOTOFF:
19272 case BFD_RELOC_ARM_PLT32:
19273 case BFD_RELOC_ARM_TARGET1:
19274 case BFD_RELOC_ARM_ROSEGREL32:
19275 case BFD_RELOC_ARM_SBREL32:
19276 case BFD_RELOC_ARM_PREL31:
19277 case BFD_RELOC_ARM_TARGET2:
19278 case BFD_RELOC_ARM_TLS_LE32:
19279 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19280 case BFD_RELOC_ARM_PCREL_CALL:
19281 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19282 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19283 case BFD_RELOC_ARM_ALU_PC_G0:
19284 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19285 case BFD_RELOC_ARM_ALU_PC_G1:
19286 case BFD_RELOC_ARM_ALU_PC_G2:
19287 case BFD_RELOC_ARM_LDR_PC_G0:
19288 case BFD_RELOC_ARM_LDR_PC_G1:
19289 case BFD_RELOC_ARM_LDR_PC_G2:
19290 case BFD_RELOC_ARM_LDRS_PC_G0:
19291 case BFD_RELOC_ARM_LDRS_PC_G1:
19292 case BFD_RELOC_ARM_LDRS_PC_G2:
19293 case BFD_RELOC_ARM_LDC_PC_G0:
19294 case BFD_RELOC_ARM_LDC_PC_G1:
19295 case BFD_RELOC_ARM_LDC_PC_G2:
19296 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19297 case BFD_RELOC_ARM_ALU_SB_G0:
19298 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19299 case BFD_RELOC_ARM_ALU_SB_G1:
19300 case BFD_RELOC_ARM_ALU_SB_G2:
19301 case BFD_RELOC_ARM_LDR_SB_G0:
19302 case BFD_RELOC_ARM_LDR_SB_G1:
19303 case BFD_RELOC_ARM_LDR_SB_G2:
19304 case BFD_RELOC_ARM_LDRS_SB_G0:
19305 case BFD_RELOC_ARM_LDRS_SB_G1:
19306 case BFD_RELOC_ARM_LDRS_SB_G2:
19307 case BFD_RELOC_ARM_LDC_SB_G0:
19308 case BFD_RELOC_ARM_LDC_SB_G1:
19309 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19310 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19311 code = fixp->fx_r_type;
19312 break;
a737bd4d 19313
c19d1205
ZW
19314 case BFD_RELOC_ARM_TLS_GD32:
19315 case BFD_RELOC_ARM_TLS_IE32:
19316 case BFD_RELOC_ARM_TLS_LDM32:
19317 /* BFD will include the symbol's address in the addend.
19318 But we don't want that, so subtract it out again here. */
19319 if (!S_IS_COMMON (fixp->fx_addsy))
19320 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19321 code = fixp->fx_r_type;
19322 break;
19323#endif
a737bd4d 19324
c19d1205
ZW
19325 case BFD_RELOC_ARM_IMMEDIATE:
19326 as_bad_where (fixp->fx_file, fixp->fx_line,
19327 _("internal relocation (type: IMMEDIATE) not fixed up"));
19328 return NULL;
a737bd4d 19329
c19d1205
ZW
19330 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19331 as_bad_where (fixp->fx_file, fixp->fx_line,
19332 _("ADRL used for a symbol not defined in the same file"));
19333 return NULL;
a737bd4d 19334
c19d1205 19335 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19336 if (section->use_rela_p)
19337 {
19338 code = fixp->fx_r_type;
19339 break;
19340 }
19341
c19d1205
ZW
19342 if (fixp->fx_addsy != NULL
19343 && !S_IS_DEFINED (fixp->fx_addsy)
19344 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19345 {
c19d1205
ZW
19346 as_bad_where (fixp->fx_file, fixp->fx_line,
19347 _("undefined local label `%s'"),
19348 S_GET_NAME (fixp->fx_addsy));
19349 return NULL;
a737bd4d
NC
19350 }
19351
c19d1205
ZW
19352 as_bad_where (fixp->fx_file, fixp->fx_line,
19353 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19354 return NULL;
a737bd4d 19355
c19d1205
ZW
19356 default:
19357 {
19358 char * type;
6c43fab6 19359
c19d1205
ZW
19360 switch (fixp->fx_r_type)
19361 {
19362 case BFD_RELOC_NONE: type = "NONE"; break;
19363 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19364 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19365 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19366 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19367 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19368 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19369 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19370 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19371 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19372 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19373 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19374 default: type = _("<unknown>"); break;
19375 }
19376 as_bad_where (fixp->fx_file, fixp->fx_line,
19377 _("cannot represent %s relocation in this object file format"),
19378 type);
19379 return NULL;
19380 }
a737bd4d 19381 }
6c43fab6 19382
c19d1205
ZW
19383#ifdef OBJ_ELF
19384 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19385 && GOT_symbol
19386 && fixp->fx_addsy == GOT_symbol)
19387 {
19388 code = BFD_RELOC_ARM_GOTPC;
19389 reloc->addend = fixp->fx_offset = reloc->address;
19390 }
19391#endif
6c43fab6 19392
c19d1205 19393 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19394
c19d1205
ZW
19395 if (reloc->howto == NULL)
19396 {
19397 as_bad_where (fixp->fx_file, fixp->fx_line,
19398 _("cannot represent %s relocation in this object file format"),
19399 bfd_get_reloc_code_name (code));
19400 return NULL;
19401 }
6c43fab6 19402
c19d1205
ZW
19403 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19404 vtable entry to be used in the relocation's section offset. */
19405 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19406 reloc->address = fixp->fx_offset;
6c43fab6 19407
c19d1205 19408 return reloc;
6c43fab6
RE
19409}
19410
c19d1205 19411/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19412
c19d1205
ZW
19413void
19414cons_fix_new_arm (fragS * frag,
19415 int where,
19416 int size,
19417 expressionS * exp)
6c43fab6 19418{
c19d1205
ZW
19419 bfd_reloc_code_real_type type;
19420 int pcrel = 0;
6c43fab6 19421
c19d1205
ZW
19422 /* Pick a reloc.
19423 FIXME: @@ Should look at CPU word size. */
19424 switch (size)
19425 {
19426 case 1:
19427 type = BFD_RELOC_8;
19428 break;
19429 case 2:
19430 type = BFD_RELOC_16;
19431 break;
19432 case 4:
19433 default:
19434 type = BFD_RELOC_32;
19435 break;
19436 case 8:
19437 type = BFD_RELOC_64;
19438 break;
19439 }
6c43fab6 19440
f0927246
NC
19441#ifdef TE_PE
19442 if (exp->X_op == O_secrel)
19443 {
19444 exp->X_op = O_symbol;
19445 type = BFD_RELOC_32_SECREL;
19446 }
19447#endif
19448
c19d1205
ZW
19449 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19450}
6c43fab6 19451
c19d1205
ZW
19452#if defined OBJ_COFF || defined OBJ_ELF
19453void
19454arm_validate_fix (fixS * fixP)
6c43fab6 19455{
c19d1205
ZW
19456 /* If the destination of the branch is a defined symbol which does not have
19457 the THUMB_FUNC attribute, then we must be calling a function which has
19458 the (interfacearm) attribute. We look for the Thumb entry point to that
19459 function and change the branch to refer to that function instead. */
19460 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19461 && fixP->fx_addsy != NULL
19462 && S_IS_DEFINED (fixP->fx_addsy)
19463 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19464 {
c19d1205 19465 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19466 }
c19d1205
ZW
19467}
19468#endif
6c43fab6 19469
c19d1205
ZW
19470int
19471arm_force_relocation (struct fix * fixp)
19472{
19473#if defined (OBJ_COFF) && defined (TE_PE)
19474 if (fixp->fx_r_type == BFD_RELOC_RVA)
19475 return 1;
19476#endif
6c43fab6 19477
c19d1205
ZW
19478 /* Resolve these relocations even if the symbol is extern or weak. */
19479 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19480 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19481 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19482 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19483 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19484 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19485 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19486 return 0;
a737bd4d 19487
4962c51a
MS
19488 /* Always leave these relocations for the linker. */
19489 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19490 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19491 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19492 return 1;
19493
f0291e4c
PB
19494 /* Always generate relocations against function symbols. */
19495 if (fixp->fx_r_type == BFD_RELOC_32
19496 && fixp->fx_addsy
19497 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19498 return 1;
19499
c19d1205 19500 return generic_force_reloc (fixp);
404ff6b5
AH
19501}
19502
0ffdc86c 19503#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19504/* Relocations against function names must be left unadjusted,
19505 so that the linker can use this information to generate interworking
19506 stubs. The MIPS version of this function
c19d1205
ZW
19507 also prevents relocations that are mips-16 specific, but I do not
19508 know why it does this.
404ff6b5 19509
c19d1205
ZW
19510 FIXME:
19511 There is one other problem that ought to be addressed here, but
19512 which currently is not: Taking the address of a label (rather
19513 than a function) and then later jumping to that address. Such
19514 addresses also ought to have their bottom bit set (assuming that
19515 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19516
c19d1205
ZW
19517bfd_boolean
19518arm_fix_adjustable (fixS * fixP)
404ff6b5 19519{
c19d1205
ZW
19520 if (fixP->fx_addsy == NULL)
19521 return 1;
404ff6b5 19522
e28387c3
PB
19523 /* Preserve relocations against symbols with function type. */
19524 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19525 return 0;
19526
c19d1205
ZW
19527 if (THUMB_IS_FUNC (fixP->fx_addsy)
19528 && fixP->fx_subsy == NULL)
19529 return 0;
a737bd4d 19530
c19d1205
ZW
19531 /* We need the symbol name for the VTABLE entries. */
19532 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19533 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19534 return 0;
404ff6b5 19535
c19d1205
ZW
19536 /* Don't allow symbols to be discarded on GOT related relocs. */
19537 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19538 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19539 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19540 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19541 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19542 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19543 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19544 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19545 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19546 return 0;
a737bd4d 19547
4962c51a
MS
19548 /* Similarly for group relocations. */
19549 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19550 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19551 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19552 return 0;
19553
79947c54
CD
19554 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
19555 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
19556 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
19557 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
19558 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
19559 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
19560 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
19561 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
19562 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
19563 return 0;
19564
c19d1205 19565 return 1;
a737bd4d 19566}
0ffdc86c
NC
19567#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19568
19569#ifdef OBJ_ELF
404ff6b5 19570
c19d1205
ZW
19571const char *
19572elf32_arm_target_format (void)
404ff6b5 19573{
c19d1205
ZW
19574#ifdef TE_SYMBIAN
19575 return (target_big_endian
19576 ? "elf32-bigarm-symbian"
19577 : "elf32-littlearm-symbian");
19578#elif defined (TE_VXWORKS)
19579 return (target_big_endian
19580 ? "elf32-bigarm-vxworks"
19581 : "elf32-littlearm-vxworks");
19582#else
19583 if (target_big_endian)
19584 return "elf32-bigarm";
19585 else
19586 return "elf32-littlearm";
19587#endif
404ff6b5
AH
19588}
19589
c19d1205
ZW
19590void
19591armelf_frob_symbol (symbolS * symp,
19592 int * puntp)
404ff6b5 19593{
c19d1205
ZW
19594 elf_frob_symbol (symp, puntp);
19595}
19596#endif
404ff6b5 19597
c19d1205 19598/* MD interface: Finalization. */
a737bd4d 19599
c19d1205
ZW
19600/* A good place to do this, although this was probably not intended
19601 for this kind of use. We need to dump the literal pool before
19602 references are made to a null symbol pointer. */
a737bd4d 19603
c19d1205
ZW
19604void
19605arm_cleanup (void)
19606{
19607 literal_pool * pool;
a737bd4d 19608
c19d1205
ZW
19609 for (pool = list_of_pools; pool; pool = pool->next)
19610 {
5f4273c7 19611 /* Put it at the end of the relevant section. */
c19d1205
ZW
19612 subseg_set (pool->section, pool->sub_section);
19613#ifdef OBJ_ELF
19614 arm_elf_change_section ();
19615#endif
19616 s_ltorg (0);
19617 }
404ff6b5
AH
19618}
19619
c19d1205
ZW
19620/* Adjust the symbol table. This marks Thumb symbols as distinct from
19621 ARM ones. */
404ff6b5 19622
c19d1205
ZW
19623void
19624arm_adjust_symtab (void)
404ff6b5 19625{
c19d1205
ZW
19626#ifdef OBJ_COFF
19627 symbolS * sym;
404ff6b5 19628
c19d1205
ZW
19629 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19630 {
19631 if (ARM_IS_THUMB (sym))
19632 {
19633 if (THUMB_IS_FUNC (sym))
19634 {
19635 /* Mark the symbol as a Thumb function. */
19636 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19637 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19638 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19639
c19d1205
ZW
19640 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19641 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19642 else
19643 as_bad (_("%s: unexpected function type: %d"),
19644 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19645 }
19646 else switch (S_GET_STORAGE_CLASS (sym))
19647 {
19648 case C_EXT:
19649 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19650 break;
19651 case C_STAT:
19652 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19653 break;
19654 case C_LABEL:
19655 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19656 break;
19657 default:
19658 /* Do nothing. */
19659 break;
19660 }
19661 }
a737bd4d 19662
c19d1205
ZW
19663 if (ARM_IS_INTERWORK (sym))
19664 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19665 }
c19d1205
ZW
19666#endif
19667#ifdef OBJ_ELF
19668 symbolS * sym;
19669 char bind;
404ff6b5 19670
c19d1205 19671 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19672 {
c19d1205
ZW
19673 if (ARM_IS_THUMB (sym))
19674 {
19675 elf_symbol_type * elf_sym;
404ff6b5 19676
c19d1205
ZW
19677 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19678 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19679
b0796911
PB
19680 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19681 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19682 {
19683 /* If it's a .thumb_func, declare it as so,
19684 otherwise tag label as .code 16. */
19685 if (THUMB_IS_FUNC (sym))
19686 elf_sym->internal_elf_sym.st_info =
19687 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19688 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19689 elf_sym->internal_elf_sym.st_info =
19690 ELF_ST_INFO (bind, STT_ARM_16BIT);
19691 }
19692 }
19693 }
19694#endif
404ff6b5
AH
19695}
19696
c19d1205 19697/* MD interface: Initialization. */
404ff6b5 19698
a737bd4d 19699static void
c19d1205 19700set_constant_flonums (void)
a737bd4d 19701{
c19d1205 19702 int i;
404ff6b5 19703
c19d1205
ZW
19704 for (i = 0; i < NUM_FLOAT_VALS; i++)
19705 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19706 abort ();
a737bd4d 19707}
404ff6b5 19708
3e9e4fcf
JB
19709/* Auto-select Thumb mode if it's the only available instruction set for the
19710 given architecture. */
19711
19712static void
19713autoselect_thumb_from_cpu_variant (void)
19714{
19715 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19716 opcode_select (16);
19717}
19718
c19d1205
ZW
19719void
19720md_begin (void)
a737bd4d 19721{
c19d1205
ZW
19722 unsigned mach;
19723 unsigned int i;
404ff6b5 19724
c19d1205
ZW
19725 if ( (arm_ops_hsh = hash_new ()) == NULL
19726 || (arm_cond_hsh = hash_new ()) == NULL
19727 || (arm_shift_hsh = hash_new ()) == NULL
19728 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19729 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19730 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19731 || (arm_reloc_hsh = hash_new ()) == NULL
19732 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19733 as_fatal (_("virtual memory exhausted"));
19734
19735 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
5a49b8ac 19736 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
c19d1205 19737 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
5a49b8ac 19738 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
c19d1205 19739 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 19740 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 19741 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 19742 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
62b3e311 19743 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 19744 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
c19d1205 19745 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 19746 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
19747 for (i = 0;
19748 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19749 i++)
19750 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
5a49b8ac 19751 (void *) (barrier_opt_names + i));
c19d1205
ZW
19752#ifdef OBJ_ELF
19753 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 19754 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
19755#endif
19756
19757 set_constant_flonums ();
404ff6b5 19758
c19d1205
ZW
19759 /* Set the cpu variant based on the command-line options. We prefer
19760 -mcpu= over -march= if both are set (as for GCC); and we prefer
19761 -mfpu= over any other way of setting the floating point unit.
19762 Use of legacy options with new options are faulted. */
e74cfd16 19763 if (legacy_cpu)
404ff6b5 19764 {
e74cfd16 19765 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19766 as_bad (_("use of old and new-style options to set CPU type"));
19767
19768 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19769 }
e74cfd16 19770 else if (!mcpu_cpu_opt)
c19d1205 19771 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19772
e74cfd16 19773 if (legacy_fpu)
c19d1205 19774 {
e74cfd16 19775 if (mfpu_opt)
c19d1205 19776 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19777
19778 mfpu_opt = legacy_fpu;
19779 }
e74cfd16 19780 else if (!mfpu_opt)
03b1477f 19781 {
c19d1205 19782#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19783 /* Some environments specify a default FPU. If they don't, infer it
19784 from the processor. */
e74cfd16 19785 if (mcpu_fpu_opt)
03b1477f
RE
19786 mfpu_opt = mcpu_fpu_opt;
19787 else
19788 mfpu_opt = march_fpu_opt;
39c2da32 19789#else
e74cfd16 19790 mfpu_opt = &fpu_default;
39c2da32 19791#endif
03b1477f
RE
19792 }
19793
e74cfd16 19794 if (!mfpu_opt)
03b1477f 19795 {
493cb6ef 19796 if (mcpu_cpu_opt != NULL)
e74cfd16 19797 mfpu_opt = &fpu_default;
493cb6ef 19798 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19799 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19800 else
e74cfd16 19801 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19802 }
19803
ee065d83 19804#ifdef CPU_DEFAULT
e74cfd16 19805 if (!mcpu_cpu_opt)
ee065d83 19806 {
e74cfd16
PB
19807 mcpu_cpu_opt = &cpu_default;
19808 selected_cpu = cpu_default;
ee065d83 19809 }
e74cfd16
PB
19810#else
19811 if (mcpu_cpu_opt)
19812 selected_cpu = *mcpu_cpu_opt;
ee065d83 19813 else
e74cfd16 19814 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19815#endif
03b1477f 19816
e74cfd16 19817 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19818
3e9e4fcf
JB
19819 autoselect_thumb_from_cpu_variant ();
19820
e74cfd16 19821 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19822
f17c130b 19823#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19824 {
7cc69913
NC
19825 unsigned int flags = 0;
19826
19827#if defined OBJ_ELF
19828 flags = meabi_flags;
d507cf36
PB
19829
19830 switch (meabi_flags)
33a392fb 19831 {
d507cf36 19832 case EF_ARM_EABI_UNKNOWN:
7cc69913 19833#endif
d507cf36
PB
19834 /* Set the flags in the private structure. */
19835 if (uses_apcs_26) flags |= F_APCS26;
19836 if (support_interwork) flags |= F_INTERWORK;
19837 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19838 if (pic_code) flags |= F_PIC;
e74cfd16 19839 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19840 flags |= F_SOFT_FLOAT;
19841
d507cf36
PB
19842 switch (mfloat_abi_opt)
19843 {
19844 case ARM_FLOAT_ABI_SOFT:
19845 case ARM_FLOAT_ABI_SOFTFP:
19846 flags |= F_SOFT_FLOAT;
19847 break;
33a392fb 19848
d507cf36
PB
19849 case ARM_FLOAT_ABI_HARD:
19850 if (flags & F_SOFT_FLOAT)
19851 as_bad (_("hard-float conflicts with specified fpu"));
19852 break;
19853 }
03b1477f 19854
e74cfd16
PB
19855 /* Using pure-endian doubles (even if soft-float). */
19856 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19857 flags |= F_VFP_FLOAT;
f17c130b 19858
fde78edd 19859#if defined OBJ_ELF
e74cfd16 19860 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19861 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19862 break;
19863
8cb51566 19864 case EF_ARM_EABI_VER4:
3a4a14e9 19865 case EF_ARM_EABI_VER5:
c19d1205 19866 /* No additional flags to set. */
d507cf36
PB
19867 break;
19868
19869 default:
19870 abort ();
19871 }
7cc69913 19872#endif
b99bd4ef
NC
19873 bfd_set_private_flags (stdoutput, flags);
19874
19875 /* We have run out flags in the COFF header to encode the
19876 status of ATPCS support, so instead we create a dummy,
c19d1205 19877 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19878 if (atpcs)
19879 {
19880 asection * sec;
19881
19882 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19883
19884 if (sec != NULL)
19885 {
19886 bfd_set_section_flags
19887 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19888 bfd_set_section_size (stdoutput, sec, 0);
19889 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19890 }
19891 }
7cc69913 19892 }
f17c130b 19893#endif
b99bd4ef
NC
19894
19895 /* Record the CPU type as well. */
2d447fca
JM
19896 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19897 mach = bfd_mach_arm_iWMMXt2;
19898 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19899 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19900 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19901 mach = bfd_mach_arm_XScale;
e74cfd16 19902 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19903 mach = bfd_mach_arm_ep9312;
e74cfd16 19904 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19905 mach = bfd_mach_arm_5TE;
e74cfd16 19906 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19907 {
e74cfd16 19908 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19909 mach = bfd_mach_arm_5T;
19910 else
19911 mach = bfd_mach_arm_5;
19912 }
e74cfd16 19913 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19914 {
e74cfd16 19915 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19916 mach = bfd_mach_arm_4T;
19917 else
19918 mach = bfd_mach_arm_4;
19919 }
e74cfd16 19920 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19921 mach = bfd_mach_arm_3M;
e74cfd16
PB
19922 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19923 mach = bfd_mach_arm_3;
19924 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19925 mach = bfd_mach_arm_2a;
19926 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19927 mach = bfd_mach_arm_2;
19928 else
19929 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19930
19931 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19932}
19933
c19d1205 19934/* Command line processing. */
b99bd4ef 19935
c19d1205
ZW
19936/* md_parse_option
19937 Invocation line includes a switch not recognized by the base assembler.
19938 See if it's a processor-specific option.
b99bd4ef 19939
c19d1205
ZW
19940 This routine is somewhat complicated by the need for backwards
19941 compatibility (since older releases of gcc can't be changed).
19942 The new options try to make the interface as compatible as
19943 possible with GCC.
b99bd4ef 19944
c19d1205 19945 New options (supported) are:
b99bd4ef 19946
c19d1205
ZW
19947 -mcpu=<cpu name> Assemble for selected processor
19948 -march=<architecture name> Assemble for selected architecture
19949 -mfpu=<fpu architecture> Assemble for selected FPU.
19950 -EB/-mbig-endian Big-endian
19951 -EL/-mlittle-endian Little-endian
19952 -k Generate PIC code
19953 -mthumb Start in Thumb mode
19954 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19955
278df34e
NS
19956 -m[no-]warn-deprecated Warn about deprecated features
19957
c19d1205 19958 For now we will also provide support for:
b99bd4ef 19959
c19d1205
ZW
19960 -mapcs-32 32-bit Program counter
19961 -mapcs-26 26-bit Program counter
19962 -macps-float Floats passed in FP registers
19963 -mapcs-reentrant Reentrant code
19964 -matpcs
19965 (sometime these will probably be replaced with -mapcs=<list of options>
19966 and -matpcs=<list of options>)
b99bd4ef 19967
c19d1205
ZW
19968 The remaining options are only supported for back-wards compatibility.
19969 Cpu variants, the arm part is optional:
19970 -m[arm]1 Currently not supported.
19971 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19972 -m[arm]3 Arm 3 processor
19973 -m[arm]6[xx], Arm 6 processors
19974 -m[arm]7[xx][t][[d]m] Arm 7 processors
19975 -m[arm]8[10] Arm 8 processors
19976 -m[arm]9[20][tdmi] Arm 9 processors
19977 -mstrongarm[110[0]] StrongARM processors
19978 -mxscale XScale processors
19979 -m[arm]v[2345[t[e]]] Arm architectures
19980 -mall All (except the ARM1)
19981 FP variants:
19982 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19983 -mfpe-old (No float load/store multiples)
19984 -mvfpxd VFP Single precision
19985 -mvfp All VFP
19986 -mno-fpu Disable all floating point instructions
b99bd4ef 19987
c19d1205
ZW
19988 The following CPU names are recognized:
19989 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19990 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19991 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19992 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19993 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19994 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19995 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19996
c19d1205 19997 */
b99bd4ef 19998
c19d1205 19999const char * md_shortopts = "m:k";
b99bd4ef 20000
c19d1205
ZW
20001#ifdef ARM_BI_ENDIAN
20002#define OPTION_EB (OPTION_MD_BASE + 0)
20003#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 20004#else
c19d1205
ZW
20005#if TARGET_BYTES_BIG_ENDIAN
20006#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 20007#else
c19d1205
ZW
20008#define OPTION_EL (OPTION_MD_BASE + 1)
20009#endif
b99bd4ef 20010#endif
845b51d6 20011#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 20012
c19d1205 20013struct option md_longopts[] =
b99bd4ef 20014{
c19d1205
ZW
20015#ifdef OPTION_EB
20016 {"EB", no_argument, NULL, OPTION_EB},
20017#endif
20018#ifdef OPTION_EL
20019 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 20020#endif
845b51d6 20021 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
20022 {NULL, no_argument, NULL, 0}
20023};
b99bd4ef 20024
c19d1205 20025size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 20026
c19d1205 20027struct arm_option_table
b99bd4ef 20028{
c19d1205
ZW
20029 char *option; /* Option name to match. */
20030 char *help; /* Help information. */
20031 int *var; /* Variable to change. */
20032 int value; /* What to change it to. */
20033 char *deprecated; /* If non-null, print this message. */
20034};
b99bd4ef 20035
c19d1205
ZW
20036struct arm_option_table arm_opts[] =
20037{
20038 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
20039 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
20040 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
20041 &support_interwork, 1, NULL},
20042 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
20043 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
20044 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
20045 1, NULL},
20046 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
20047 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
20048 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
20049 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
20050 NULL},
b99bd4ef 20051
c19d1205
ZW
20052 /* These are recognized by the assembler, but have no affect on code. */
20053 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
20054 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
20055
20056 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
20057 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
20058 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
20059 {NULL, NULL, NULL, 0, NULL}
20060};
20061
20062struct arm_legacy_option_table
20063{
20064 char *option; /* Option name to match. */
20065 const arm_feature_set **var; /* Variable to change. */
20066 const arm_feature_set value; /* What to change it to. */
20067 char *deprecated; /* If non-null, print this message. */
20068};
b99bd4ef 20069
e74cfd16
PB
20070const struct arm_legacy_option_table arm_legacy_opts[] =
20071{
c19d1205
ZW
20072 /* DON'T add any new processors to this list -- we want the whole list
20073 to go away... Add them to the processors table instead. */
e74cfd16
PB
20074 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20075 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20076 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20077 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20078 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20079 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20080 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20081 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20082 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20083 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20084 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20085 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20086 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20087 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20088 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20089 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20090 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20091 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20092 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20093 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20094 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20095 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20096 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20097 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20098 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20099 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20100 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20101 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20102 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20103 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20104 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20105 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20106 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20107 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20108 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20109 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20110 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20111 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20112 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20113 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20114 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20115 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20116 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20117 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20118 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20119 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20120 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20121 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20122 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20123 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20124 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20125 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20126 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20127 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20128 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20129 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20130 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20131 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20132 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20133 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20134 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20135 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20136 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20137 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20138 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20139 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20140 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20141 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20142 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
20143 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20144 N_("use -mcpu=strongarm110")},
e74cfd16 20145 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20146 N_("use -mcpu=strongarm1100")},
e74cfd16 20147 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20148 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
20149 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20150 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20151 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 20152
c19d1205 20153 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
20154 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20155 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20156 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20157 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20158 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20159 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20160 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20161 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20162 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20163 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20164 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20165 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20166 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20167 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20168 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20169 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20170 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20171 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20172
c19d1205 20173 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20174 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20175 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20176 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20177 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20178 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20179
e74cfd16 20180 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20181};
7ed4c4c5 20182
c19d1205 20183struct arm_cpu_option_table
7ed4c4c5 20184{
c19d1205 20185 char *name;
e74cfd16 20186 const arm_feature_set value;
c19d1205
ZW
20187 /* For some CPUs we assume an FPU unless the user explicitly sets
20188 -mfpu=... */
e74cfd16 20189 const arm_feature_set default_fpu;
ee065d83
PB
20190 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20191 case. */
20192 const char *canonical_name;
c19d1205 20193};
7ed4c4c5 20194
c19d1205
ZW
20195/* This list should, at a minimum, contain all the cpu names
20196 recognized by GCC. */
e74cfd16 20197static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20198{
ee065d83
PB
20199 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20200 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20201 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20202 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20203 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20204 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20205 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20206 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20207 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20208 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20209 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20210 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20211 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20212 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20213 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20214 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20215 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20216 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20217 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20218 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20219 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20220 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20221 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20222 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20223 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20224 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20225 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20226 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20227 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20228 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20229 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20230 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20231 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20232 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20233 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20234 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20235 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20236 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20237 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20238 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20239 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20240 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20241 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20242 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
20243 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20244 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20245 /* For V5 or later processors we default to using VFP; but the user
20246 should really set the FPU type explicitly. */
ee065d83
PB
20247 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20248 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20249 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20250 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20251 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20252 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20253 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20254 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20255 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20256 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20257 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20258 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20259 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20260 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20261 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20262 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20263 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20264 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20265 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20266 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20267 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
20268 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20269 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
20270 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20271 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20272 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20273 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20274 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20275 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20276 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20277 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20278 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20279 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20280 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20281 | FPU_NEON_EXT_V1),
15290f0a
PB
20282 NULL},
20283 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20284 | FPU_NEON_EXT_V1),
5287ad62 20285 NULL},
62b3e311
PB
20286 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20287 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20288 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20289 /* ??? XSCALE is really an architecture. */
ee065d83 20290 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20291 /* ??? iwmmxt is not a processor. */
ee065d83 20292 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20293 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20294 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20295 /* Maverick */
e74cfd16
PB
20296 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20297 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20298};
7ed4c4c5 20299
c19d1205 20300struct arm_arch_option_table
7ed4c4c5 20301{
c19d1205 20302 char *name;
e74cfd16
PB
20303 const arm_feature_set value;
20304 const arm_feature_set default_fpu;
c19d1205 20305};
7ed4c4c5 20306
c19d1205
ZW
20307/* This list should, at a minimum, contain all the architecture names
20308 recognized by GCC. */
e74cfd16 20309static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20310{
20311 {"all", ARM_ANY, FPU_ARCH_FPA},
20312 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20313 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20314 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20315 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20316 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20317 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20318 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20319 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20320 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20321 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20322 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20323 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20324 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20325 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20326 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20327 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20328 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20329 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20330 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20331 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20332 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20333 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20334 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20335 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20336 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20337 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20338 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20339 /* The official spelling of the ARMv7 profile variants is the dashed form.
20340 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20341 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20342 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20343 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20344 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20345 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20346 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20347 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20348 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20349 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20350 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20351};
7ed4c4c5 20352
c19d1205 20353/* ISA extensions in the co-processor space. */
e74cfd16 20354struct arm_option_cpu_value_table
c19d1205
ZW
20355{
20356 char *name;
e74cfd16 20357 const arm_feature_set value;
c19d1205 20358};
7ed4c4c5 20359
e74cfd16 20360static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20361{
e74cfd16
PB
20362 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20363 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20364 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20365 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20366 {NULL, ARM_ARCH_NONE}
c19d1205 20367};
7ed4c4c5 20368
c19d1205
ZW
20369/* This list should, at a minimum, contain all the fpu names
20370 recognized by GCC. */
e74cfd16 20371static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20372{
20373 {"softfpa", FPU_NONE},
20374 {"fpe", FPU_ARCH_FPE},
20375 {"fpe2", FPU_ARCH_FPE},
20376 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20377 {"fpa", FPU_ARCH_FPA},
20378 {"fpa10", FPU_ARCH_FPA},
20379 {"fpa11", FPU_ARCH_FPA},
20380 {"arm7500fe", FPU_ARCH_FPA},
20381 {"softvfp", FPU_ARCH_VFP},
20382 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20383 {"vfp", FPU_ARCH_VFP_V2},
20384 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 20385 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
20386 {"vfp10", FPU_ARCH_VFP_V2},
20387 {"vfp10-r0", FPU_ARCH_VFP_V1},
20388 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
20389 {"vfpv2", FPU_ARCH_VFP_V2},
20390 {"vfpv3", FPU_ARCH_VFP_V3},
20391 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
20392 {"arm1020t", FPU_ARCH_VFP_V1},
20393 {"arm1020e", FPU_ARCH_VFP_V2},
20394 {"arm1136jfs", FPU_ARCH_VFP_V2},
20395 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20396 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20397 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 20398 {"neon-fp16", FPU_ARCH_NEON_FP16},
e74cfd16
PB
20399 {NULL, ARM_ARCH_NONE}
20400};
20401
20402struct arm_option_value_table
20403{
20404 char *name;
20405 long value;
c19d1205 20406};
7ed4c4c5 20407
e74cfd16 20408static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20409{
20410 {"hard", ARM_FLOAT_ABI_HARD},
20411 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20412 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20413 {NULL, 0}
c19d1205 20414};
7ed4c4c5 20415
c19d1205 20416#ifdef OBJ_ELF
3a4a14e9 20417/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20418static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20419{
20420 {"gnu", EF_ARM_EABI_UNKNOWN},
20421 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20422 {"5", EF_ARM_EABI_VER5},
e74cfd16 20423 {NULL, 0}
c19d1205
ZW
20424};
20425#endif
7ed4c4c5 20426
c19d1205
ZW
20427struct arm_long_option_table
20428{
20429 char * option; /* Substring to match. */
20430 char * help; /* Help information. */
20431 int (* func) (char * subopt); /* Function to decode sub-option. */
20432 char * deprecated; /* If non-null, print this message. */
20433};
7ed4c4c5
NC
20434
20435static int
e74cfd16 20436arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20437{
e74cfd16
PB
20438 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20439
20440 /* Copy the feature set, so that we can modify it. */
20441 *ext_set = **opt_p;
20442 *opt_p = ext_set;
20443
c19d1205 20444 while (str != NULL && *str != 0)
7ed4c4c5 20445 {
e74cfd16 20446 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20447 char * ext;
20448 int optlen;
7ed4c4c5 20449
c19d1205
ZW
20450 if (*str != '+')
20451 {
20452 as_bad (_("invalid architectural extension"));
20453 return 0;
20454 }
7ed4c4c5 20455
c19d1205
ZW
20456 str++;
20457 ext = strchr (str, '+');
7ed4c4c5 20458
c19d1205
ZW
20459 if (ext != NULL)
20460 optlen = ext - str;
20461 else
20462 optlen = strlen (str);
7ed4c4c5 20463
c19d1205
ZW
20464 if (optlen == 0)
20465 {
20466 as_bad (_("missing architectural extension"));
20467 return 0;
20468 }
7ed4c4c5 20469
c19d1205
ZW
20470 for (opt = arm_extensions; opt->name != NULL; opt++)
20471 if (strncmp (opt->name, str, optlen) == 0)
20472 {
e74cfd16 20473 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20474 break;
20475 }
7ed4c4c5 20476
c19d1205
ZW
20477 if (opt->name == NULL)
20478 {
5f4273c7 20479 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20480 return 0;
20481 }
7ed4c4c5 20482
c19d1205
ZW
20483 str = ext;
20484 };
7ed4c4c5 20485
c19d1205
ZW
20486 return 1;
20487}
7ed4c4c5 20488
c19d1205
ZW
20489static int
20490arm_parse_cpu (char * str)
7ed4c4c5 20491{
e74cfd16 20492 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20493 char * ext = strchr (str, '+');
20494 int optlen;
7ed4c4c5 20495
c19d1205
ZW
20496 if (ext != NULL)
20497 optlen = ext - str;
7ed4c4c5 20498 else
c19d1205 20499 optlen = strlen (str);
7ed4c4c5 20500
c19d1205 20501 if (optlen == 0)
7ed4c4c5 20502 {
c19d1205
ZW
20503 as_bad (_("missing cpu name `%s'"), str);
20504 return 0;
7ed4c4c5
NC
20505 }
20506
c19d1205
ZW
20507 for (opt = arm_cpus; opt->name != NULL; opt++)
20508 if (strncmp (opt->name, str, optlen) == 0)
20509 {
e74cfd16
PB
20510 mcpu_cpu_opt = &opt->value;
20511 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 20512 if (opt->canonical_name)
5f4273c7 20513 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20514 else
20515 {
20516 int i;
20517 for (i = 0; i < optlen; i++)
20518 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20519 selected_cpu_name[i] = 0;
20520 }
7ed4c4c5 20521
c19d1205
ZW
20522 if (ext != NULL)
20523 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20524
c19d1205
ZW
20525 return 1;
20526 }
7ed4c4c5 20527
c19d1205
ZW
20528 as_bad (_("unknown cpu `%s'"), str);
20529 return 0;
7ed4c4c5
NC
20530}
20531
c19d1205
ZW
20532static int
20533arm_parse_arch (char * str)
7ed4c4c5 20534{
e74cfd16 20535 const struct arm_arch_option_table *opt;
c19d1205
ZW
20536 char *ext = strchr (str, '+');
20537 int optlen;
7ed4c4c5 20538
c19d1205
ZW
20539 if (ext != NULL)
20540 optlen = ext - str;
7ed4c4c5 20541 else
c19d1205 20542 optlen = strlen (str);
7ed4c4c5 20543
c19d1205 20544 if (optlen == 0)
7ed4c4c5 20545 {
c19d1205
ZW
20546 as_bad (_("missing architecture name `%s'"), str);
20547 return 0;
7ed4c4c5
NC
20548 }
20549
c19d1205
ZW
20550 for (opt = arm_archs; opt->name != NULL; opt++)
20551 if (streq (opt->name, str))
20552 {
e74cfd16
PB
20553 march_cpu_opt = &opt->value;
20554 march_fpu_opt = &opt->default_fpu;
5f4273c7 20555 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 20556
c19d1205
ZW
20557 if (ext != NULL)
20558 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20559
c19d1205
ZW
20560 return 1;
20561 }
20562
20563 as_bad (_("unknown architecture `%s'\n"), str);
20564 return 0;
7ed4c4c5 20565}
eb043451 20566
c19d1205
ZW
20567static int
20568arm_parse_fpu (char * str)
20569{
e74cfd16 20570 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20571
c19d1205
ZW
20572 for (opt = arm_fpus; opt->name != NULL; opt++)
20573 if (streq (opt->name, str))
20574 {
e74cfd16 20575 mfpu_opt = &opt->value;
c19d1205
ZW
20576 return 1;
20577 }
b99bd4ef 20578
c19d1205
ZW
20579 as_bad (_("unknown floating point format `%s'\n"), str);
20580 return 0;
20581}
20582
20583static int
20584arm_parse_float_abi (char * str)
b99bd4ef 20585{
e74cfd16 20586 const struct arm_option_value_table * opt;
b99bd4ef 20587
c19d1205
ZW
20588 for (opt = arm_float_abis; opt->name != NULL; opt++)
20589 if (streq (opt->name, str))
20590 {
20591 mfloat_abi_opt = opt->value;
20592 return 1;
20593 }
cc8a6dd0 20594
c19d1205
ZW
20595 as_bad (_("unknown floating point abi `%s'\n"), str);
20596 return 0;
20597}
b99bd4ef 20598
c19d1205
ZW
20599#ifdef OBJ_ELF
20600static int
20601arm_parse_eabi (char * str)
20602{
e74cfd16 20603 const struct arm_option_value_table *opt;
cc8a6dd0 20604
c19d1205
ZW
20605 for (opt = arm_eabis; opt->name != NULL; opt++)
20606 if (streq (opt->name, str))
20607 {
20608 meabi_flags = opt->value;
20609 return 1;
20610 }
20611 as_bad (_("unknown EABI `%s'\n"), str);
20612 return 0;
20613}
20614#endif
cc8a6dd0 20615
c19d1205
ZW
20616struct arm_long_option_table arm_long_opts[] =
20617{
20618 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20619 arm_parse_cpu, NULL},
20620 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20621 arm_parse_arch, NULL},
20622 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20623 arm_parse_fpu, NULL},
20624 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20625 arm_parse_float_abi, NULL},
20626#ifdef OBJ_ELF
7fac0536 20627 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
20628 arm_parse_eabi, NULL},
20629#endif
20630 {NULL, NULL, 0, NULL}
20631};
cc8a6dd0 20632
c19d1205
ZW
20633int
20634md_parse_option (int c, char * arg)
20635{
20636 struct arm_option_table *opt;
e74cfd16 20637 const struct arm_legacy_option_table *fopt;
c19d1205 20638 struct arm_long_option_table *lopt;
b99bd4ef 20639
c19d1205 20640 switch (c)
b99bd4ef 20641 {
c19d1205
ZW
20642#ifdef OPTION_EB
20643 case OPTION_EB:
20644 target_big_endian = 1;
20645 break;
20646#endif
cc8a6dd0 20647
c19d1205
ZW
20648#ifdef OPTION_EL
20649 case OPTION_EL:
20650 target_big_endian = 0;
20651 break;
20652#endif
b99bd4ef 20653
845b51d6
PB
20654 case OPTION_FIX_V4BX:
20655 fix_v4bx = TRUE;
20656 break;
20657
c19d1205
ZW
20658 case 'a':
20659 /* Listing option. Just ignore these, we don't support additional
20660 ones. */
20661 return 0;
b99bd4ef 20662
c19d1205
ZW
20663 default:
20664 for (opt = arm_opts; opt->option != NULL; opt++)
20665 {
20666 if (c == opt->option[0]
20667 && ((arg == NULL && opt->option[1] == 0)
20668 || streq (arg, opt->option + 1)))
20669 {
c19d1205 20670 /* If the option is deprecated, tell the user. */
278df34e 20671 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
20672 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20673 arg ? arg : "", _(opt->deprecated));
b99bd4ef 20674
c19d1205
ZW
20675 if (opt->var != NULL)
20676 *opt->var = opt->value;
cc8a6dd0 20677
c19d1205
ZW
20678 return 1;
20679 }
20680 }
b99bd4ef 20681
e74cfd16
PB
20682 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20683 {
20684 if (c == fopt->option[0]
20685 && ((arg == NULL && fopt->option[1] == 0)
20686 || streq (arg, fopt->option + 1)))
20687 {
e74cfd16 20688 /* If the option is deprecated, tell the user. */
278df34e 20689 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
20690 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20691 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
20692
20693 if (fopt->var != NULL)
20694 *fopt->var = &fopt->value;
20695
20696 return 1;
20697 }
20698 }
20699
c19d1205
ZW
20700 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20701 {
20702 /* These options are expected to have an argument. */
20703 if (c == lopt->option[0]
20704 && arg != NULL
20705 && strncmp (arg, lopt->option + 1,
20706 strlen (lopt->option + 1)) == 0)
20707 {
c19d1205 20708 /* If the option is deprecated, tell the user. */
278df34e 20709 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
20710 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20711 _(lopt->deprecated));
b99bd4ef 20712
c19d1205
ZW
20713 /* Call the sup-option parser. */
20714 return lopt->func (arg + strlen (lopt->option) - 1);
20715 }
20716 }
a737bd4d 20717
c19d1205
ZW
20718 return 0;
20719 }
a394c00f 20720
c19d1205
ZW
20721 return 1;
20722}
a394c00f 20723
c19d1205
ZW
20724void
20725md_show_usage (FILE * fp)
a394c00f 20726{
c19d1205
ZW
20727 struct arm_option_table *opt;
20728 struct arm_long_option_table *lopt;
a394c00f 20729
c19d1205 20730 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20731
c19d1205
ZW
20732 for (opt = arm_opts; opt->option != NULL; opt++)
20733 if (opt->help != NULL)
20734 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20735
c19d1205
ZW
20736 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20737 if (lopt->help != NULL)
20738 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20739
c19d1205
ZW
20740#ifdef OPTION_EB
20741 fprintf (fp, _("\
20742 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20743#endif
20744
c19d1205
ZW
20745#ifdef OPTION_EL
20746 fprintf (fp, _("\
20747 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20748#endif
845b51d6
PB
20749
20750 fprintf (fp, _("\
20751 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 20752}
ee065d83
PB
20753
20754
20755#ifdef OBJ_ELF
62b3e311
PB
20756typedef struct
20757{
20758 int val;
20759 arm_feature_set flags;
20760} cpu_arch_ver_table;
20761
20762/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20763 least features first. */
20764static const cpu_arch_ver_table cpu_arch_ver[] =
20765{
20766 {1, ARM_ARCH_V4},
20767 {2, ARM_ARCH_V4T},
20768 {3, ARM_ARCH_V5},
ee3c0378 20769 {3, ARM_ARCH_V5T},
62b3e311
PB
20770 {4, ARM_ARCH_V5TE},
20771 {5, ARM_ARCH_V5TEJ},
20772 {6, ARM_ARCH_V6},
20773 {7, ARM_ARCH_V6Z},
7e806470 20774 {9, ARM_ARCH_V6K},
91e22acd 20775 {11, ARM_ARCH_V6M},
7e806470 20776 {8, ARM_ARCH_V6T2},
62b3e311
PB
20777 {10, ARM_ARCH_V7A},
20778 {10, ARM_ARCH_V7R},
20779 {10, ARM_ARCH_V7M},
20780 {0, ARM_ARCH_NONE}
20781};
20782
ee3c0378
AS
20783/* Set an attribute if it has not already been set by the user. */
20784static void
20785aeabi_set_attribute_int (int tag, int value)
20786{
20787 if (tag < 1
20788 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
20789 || !attributes_set_explicitly[tag])
20790 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
20791}
20792
20793static void
20794aeabi_set_attribute_string (int tag, const char *value)
20795{
20796 if (tag < 1
20797 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
20798 || !attributes_set_explicitly[tag])
20799 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
20800}
20801
ee065d83
PB
20802/* Set the public EABI object attributes. */
20803static void
20804aeabi_set_public_attributes (void)
20805{
20806 int arch;
e74cfd16 20807 arm_feature_set flags;
62b3e311
PB
20808 arm_feature_set tmp;
20809 const cpu_arch_ver_table *p;
ee065d83
PB
20810
20811 /* Choose the architecture based on the capabilities of the requested cpu
20812 (if any) and/or the instructions actually used. */
e74cfd16
PB
20813 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20814 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20815 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20816 /*Allow the user to override the reported architecture. */
20817 if (object_arch)
20818 {
20819 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20820 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20821 }
20822
62b3e311
PB
20823 tmp = flags;
20824 arch = 0;
20825 for (p = cpu_arch_ver; p->val; p++)
20826 {
20827 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20828 {
20829 arch = p->val;
20830 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20831 }
20832 }
ee065d83
PB
20833
20834 /* Tag_CPU_name. */
20835 if (selected_cpu_name[0])
20836 {
20837 char *p;
20838
20839 p = selected_cpu_name;
5f4273c7 20840 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
20841 {
20842 int i;
5f4273c7 20843
ee065d83
PB
20844 p += 4;
20845 for (i = 0; p[i]; i++)
20846 p[i] = TOUPPER (p[i]);
20847 }
ee3c0378 20848 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83
PB
20849 }
20850 /* Tag_CPU_arch. */
ee3c0378 20851 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62b3e311
PB
20852 /* Tag_CPU_arch_profile. */
20853 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 20854 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 20855 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 20856 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 20857 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 20858 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
ee065d83 20859 /* Tag_ARM_ISA_use. */
ee3c0378
AS
20860 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
20861 || arch == 0)
20862 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
ee065d83 20863 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
20864 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
20865 || arch == 0)
20866 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
20867 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
ee065d83 20868 /* Tag_VFP_arch. */
ee3c0378
AS
20869 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
20870 aeabi_set_attribute_int (Tag_VFP_arch, 3);
20871 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
20872 aeabi_set_attribute_int (Tag_VFP_arch, 4);
20873 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
20874 aeabi_set_attribute_int (Tag_VFP_arch, 2);
20875 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
20876 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
20877 aeabi_set_attribute_int (Tag_VFP_arch, 1);
ee065d83 20878 /* Tag_WMMX_arch. */
ee3c0378
AS
20879 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
20880 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
20881 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
20882 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
20883 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 20884 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
ee3c0378
AS
20885 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
20886 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
8e79c3df 20887 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
ee3c0378 20888 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
20889}
20890
104d59d1 20891/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
20892void
20893arm_md_end (void)
20894{
ee065d83
PB
20895 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20896 return;
20897
20898 aeabi_set_public_attributes ();
ee065d83 20899}
8463be01 20900#endif /* OBJ_ELF */
ee065d83
PB
20901
20902
20903/* Parse a .cpu directive. */
20904
20905static void
20906s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20907{
e74cfd16 20908 const struct arm_cpu_option_table *opt;
ee065d83
PB
20909 char *name;
20910 char saved_char;
20911
20912 name = input_line_pointer;
5f4273c7 20913 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20914 input_line_pointer++;
20915 saved_char = *input_line_pointer;
20916 *input_line_pointer = 0;
20917
20918 /* Skip the first "all" entry. */
20919 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20920 if (streq (opt->name, name))
20921 {
e74cfd16
PB
20922 mcpu_cpu_opt = &opt->value;
20923 selected_cpu = opt->value;
ee065d83 20924 if (opt->canonical_name)
5f4273c7 20925 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
20926 else
20927 {
20928 int i;
20929 for (i = 0; opt->name[i]; i++)
20930 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20931 selected_cpu_name[i] = 0;
20932 }
e74cfd16 20933 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20934 *input_line_pointer = saved_char;
20935 demand_empty_rest_of_line ();
20936 return;
20937 }
20938 as_bad (_("unknown cpu `%s'"), name);
20939 *input_line_pointer = saved_char;
20940 ignore_rest_of_line ();
20941}
20942
20943
20944/* Parse a .arch directive. */
20945
20946static void
20947s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20948{
e74cfd16 20949 const struct arm_arch_option_table *opt;
ee065d83
PB
20950 char saved_char;
20951 char *name;
20952
20953 name = input_line_pointer;
5f4273c7 20954 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
20955 input_line_pointer++;
20956 saved_char = *input_line_pointer;
20957 *input_line_pointer = 0;
20958
20959 /* Skip the first "all" entry. */
20960 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20961 if (streq (opt->name, name))
20962 {
e74cfd16
PB
20963 mcpu_cpu_opt = &opt->value;
20964 selected_cpu = opt->value;
5f4273c7 20965 strcpy (selected_cpu_name, opt->name);
e74cfd16 20966 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20967 *input_line_pointer = saved_char;
20968 demand_empty_rest_of_line ();
20969 return;
20970 }
20971
20972 as_bad (_("unknown architecture `%s'\n"), name);
20973 *input_line_pointer = saved_char;
20974 ignore_rest_of_line ();
20975}
20976
20977
7a1d4c38
PB
20978/* Parse a .object_arch directive. */
20979
20980static void
20981s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20982{
20983 const struct arm_arch_option_table *opt;
20984 char saved_char;
20985 char *name;
20986
20987 name = input_line_pointer;
5f4273c7 20988 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
20989 input_line_pointer++;
20990 saved_char = *input_line_pointer;
20991 *input_line_pointer = 0;
20992
20993 /* Skip the first "all" entry. */
20994 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20995 if (streq (opt->name, name))
20996 {
20997 object_arch = &opt->value;
20998 *input_line_pointer = saved_char;
20999 demand_empty_rest_of_line ();
21000 return;
21001 }
21002
21003 as_bad (_("unknown architecture `%s'\n"), name);
21004 *input_line_pointer = saved_char;
21005 ignore_rest_of_line ();
21006}
21007
ee065d83
PB
21008/* Parse a .fpu directive. */
21009
21010static void
21011s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
21012{
e74cfd16 21013 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
21014 char saved_char;
21015 char *name;
21016
21017 name = input_line_pointer;
5f4273c7 21018 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21019 input_line_pointer++;
21020 saved_char = *input_line_pointer;
21021 *input_line_pointer = 0;
5f4273c7 21022
ee065d83
PB
21023 for (opt = arm_fpus; opt->name != NULL; opt++)
21024 if (streq (opt->name, name))
21025 {
e74cfd16
PB
21026 mfpu_opt = &opt->value;
21027 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21028 *input_line_pointer = saved_char;
21029 demand_empty_rest_of_line ();
21030 return;
21031 }
21032
21033 as_bad (_("unknown floating point format `%s'\n"), name);
21034 *input_line_pointer = saved_char;
21035 ignore_rest_of_line ();
21036}
ee065d83 21037
794ba86a 21038/* Copy symbol information. */
f31fef98 21039
794ba86a
DJ
21040void
21041arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
21042{
21043 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
21044}
e04befd0 21045
f31fef98 21046#ifdef OBJ_ELF
e04befd0
AS
21047/* Given a symbolic attribute NAME, return the proper integer value.
21048 Returns -1 if the attribute is not known. */
f31fef98 21049
e04befd0
AS
21050int
21051arm_convert_symbolic_attribute (const char *name)
21052{
f31fef98
NC
21053 static const struct
21054 {
21055 const char * name;
21056 const int tag;
21057 }
21058 attribute_table[] =
21059 {
21060 /* When you modify this table you should
21061 also modify the list in doc/c-arm.texi. */
e04befd0 21062#define T(tag) {#tag, tag}
f31fef98
NC
21063 T (Tag_CPU_raw_name),
21064 T (Tag_CPU_name),
21065 T (Tag_CPU_arch),
21066 T (Tag_CPU_arch_profile),
21067 T (Tag_ARM_ISA_use),
21068 T (Tag_THUMB_ISA_use),
21069 T (Tag_VFP_arch),
21070 T (Tag_WMMX_arch),
21071 T (Tag_Advanced_SIMD_arch),
21072 T (Tag_PCS_config),
21073 T (Tag_ABI_PCS_R9_use),
21074 T (Tag_ABI_PCS_RW_data),
21075 T (Tag_ABI_PCS_RO_data),
21076 T (Tag_ABI_PCS_GOT_use),
21077 T (Tag_ABI_PCS_wchar_t),
21078 T (Tag_ABI_FP_rounding),
21079 T (Tag_ABI_FP_denormal),
21080 T (Tag_ABI_FP_exceptions),
21081 T (Tag_ABI_FP_user_exceptions),
21082 T (Tag_ABI_FP_number_model),
21083 T (Tag_ABI_align8_needed),
21084 T (Tag_ABI_align8_preserved),
21085 T (Tag_ABI_enum_size),
21086 T (Tag_ABI_HardFP_use),
21087 T (Tag_ABI_VFP_args),
21088 T (Tag_ABI_WMMX_args),
21089 T (Tag_ABI_optimization_goals),
21090 T (Tag_ABI_FP_optimization_goals),
21091 T (Tag_compatibility),
21092 T (Tag_CPU_unaligned_access),
21093 T (Tag_VFP_HP_extension),
21094 T (Tag_ABI_FP_16bit_format),
21095 T (Tag_nodefaults),
21096 T (Tag_also_compatible_with),
21097 T (Tag_conformance),
21098 T (Tag_T2EE_use),
21099 T (Tag_Virtualization_use),
21100 T (Tag_MPextension_use)
e04befd0 21101#undef T
f31fef98 21102 };
e04befd0
AS
21103 unsigned int i;
21104
21105 if (name == NULL)
21106 return -1;
21107
f31fef98 21108 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
e04befd0
AS
21109 if (strcmp (name, attribute_table[i].name) == 0)
21110 return attribute_table[i].tag;
21111
21112 return -1;
21113}
f31fef98 21114#endif /* OBJ_ELF */