]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
gdb/
[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;
8dc2430f
NC
263/* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266#define MODE_RECORDED (1 << 4)
b99bd4ef 267
c19d1205
ZW
268/* If unified_syntax is true, we are processing the new unified
269 ARM/Thumb syntax. Important differences from the old ARM mode:
270
271 - Immediate operands do not require a # prefix.
272 - Conditional affixes always appear at the end of the
273 instruction. (For backward compatibility, those instructions
274 that formerly had them in the middle, continue to accept them
275 there.)
276 - The IT instruction may appear, and if it does is validated
277 against subsequent conditional affixes. It does not generate
278 machine code.
279
280 Important differences from the old Thumb mode:
281
282 - Immediate operands do not require a # prefix.
283 - Most of the V6T2 instructions are only available in unified mode.
284 - The .N and .W suffixes are recognized and honored (it is an error
285 if they cannot be honored).
286 - All instructions set the flags if and only if they have an 's' affix.
287 - Conditional affixes may be used. They are validated against
288 preceding IT instructions. Unlike ARM mode, you cannot use a
289 conditional affix except in the scope of an IT instruction. */
290
291static bfd_boolean unified_syntax = FALSE;
b99bd4ef 292
5287ad62
JB
293enum neon_el_type
294{
dcbf9037 295 NT_invtype,
5287ad62
JB
296 NT_untyped,
297 NT_integer,
298 NT_float,
299 NT_poly,
300 NT_signed,
dcbf9037 301 NT_unsigned
5287ad62
JB
302};
303
304struct neon_type_el
305{
306 enum neon_el_type type;
307 unsigned size;
308};
309
310#define NEON_MAX_TYPE_ELS 4
311
312struct neon_type
313{
314 struct neon_type_el el[NEON_MAX_TYPE_ELS];
315 unsigned elems;
316};
317
b99bd4ef
NC
318struct arm_it
319{
c19d1205 320 const char * error;
b99bd4ef 321 unsigned long instruction;
c19d1205
ZW
322 int size;
323 int size_req;
324 int cond;
037e8744
JB
325 /* "uncond_value" is set to the value in place of the conditional field in
326 unconditional versions of the instruction, or -1 if nothing is
327 appropriate. */
328 int uncond_value;
5287ad62 329 struct neon_type vectype;
0110f2b8
PB
330 /* Set to the opcode if the instruction needs relaxation.
331 Zero if the instruction is not relaxed. */
332 unsigned long relax;
b99bd4ef
NC
333 struct
334 {
335 bfd_reloc_code_real_type type;
c19d1205
ZW
336 expressionS exp;
337 int pc_rel;
b99bd4ef 338 } reloc;
b99bd4ef 339
c19d1205
ZW
340 struct
341 {
342 unsigned reg;
ca3f61f7 343 signed int imm;
dcbf9037 344 struct neon_type_el vectype;
ca3f61f7
NC
345 unsigned present : 1; /* Operand present. */
346 unsigned isreg : 1; /* Operand was a register. */
347 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
348 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
349 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 350 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
351 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
352 instructions. This allows us to disambiguate ARM <-> vector insns. */
353 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 354 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 355 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 356 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
357 unsigned hasreloc : 1; /* Operand has relocation suffix. */
358 unsigned writeback : 1; /* Operand has trailing ! */
359 unsigned preind : 1; /* Preindexed address. */
360 unsigned postind : 1; /* Postindexed address. */
361 unsigned negative : 1; /* Index register was negated. */
362 unsigned shifted : 1; /* Shift applied to operation. */
363 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 364 } operands[6];
b99bd4ef
NC
365};
366
c19d1205 367static struct arm_it inst;
b99bd4ef
NC
368
369#define NUM_FLOAT_VALS 8
370
05d2d07e 371const char * fp_const[] =
b99bd4ef
NC
372{
373 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
374};
375
c19d1205 376/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
377#define MAX_LITTLENUMS 6
378
379LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
380
381#define FAIL (-1)
382#define SUCCESS (0)
383
384#define SUFF_S 1
385#define SUFF_D 2
386#define SUFF_E 3
387#define SUFF_P 4
388
c19d1205
ZW
389#define CP_T_X 0x00008000
390#define CP_T_Y 0x00400000
b99bd4ef 391
c19d1205
ZW
392#define CONDS_BIT 0x00100000
393#define LOAD_BIT 0x00100000
b99bd4ef
NC
394
395#define DOUBLE_LOAD_FLAG 0x00000001
396
397struct asm_cond
398{
c19d1205 399 const char * template;
b99bd4ef
NC
400 unsigned long value;
401};
402
c19d1205 403#define COND_ALWAYS 0xE
b99bd4ef 404
b99bd4ef
NC
405struct asm_psr
406{
b34976b6 407 const char *template;
b99bd4ef
NC
408 unsigned long field;
409};
410
62b3e311
PB
411struct asm_barrier_opt
412{
413 const char *template;
414 unsigned long value;
415};
416
2d2255b5 417/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
418#define SPSR_BIT (1 << 22)
419
c19d1205
ZW
420/* The individual PSR flag bits. */
421#define PSR_c (1 << 16)
422#define PSR_x (1 << 17)
423#define PSR_s (1 << 18)
424#define PSR_f (1 << 19)
b99bd4ef 425
c19d1205 426struct reloc_entry
bfae80f2 427{
c19d1205
ZW
428 char *name;
429 bfd_reloc_code_real_type reloc;
bfae80f2
RE
430};
431
5287ad62 432enum vfp_reg_pos
bfae80f2 433{
5287ad62
JB
434 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
435 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
436};
437
438enum vfp_ldstm_type
439{
440 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
441};
442
dcbf9037
JB
443/* Bits for DEFINED field in neon_typed_alias. */
444#define NTA_HASTYPE 1
445#define NTA_HASINDEX 2
446
447struct neon_typed_alias
448{
449 unsigned char defined;
450 unsigned char index;
451 struct neon_type_el eltype;
452};
453
c19d1205
ZW
454/* ARM register categories. This includes coprocessor numbers and various
455 architecture extensions' registers. */
456enum arm_reg_type
bfae80f2 457{
c19d1205
ZW
458 REG_TYPE_RN,
459 REG_TYPE_CP,
460 REG_TYPE_CN,
461 REG_TYPE_FN,
462 REG_TYPE_VFS,
463 REG_TYPE_VFD,
5287ad62 464 REG_TYPE_NQ,
037e8744 465 REG_TYPE_VFSD,
5287ad62 466 REG_TYPE_NDQ,
037e8744 467 REG_TYPE_NSDQ,
c19d1205
ZW
468 REG_TYPE_VFC,
469 REG_TYPE_MVF,
470 REG_TYPE_MVD,
471 REG_TYPE_MVFX,
472 REG_TYPE_MVDX,
473 REG_TYPE_MVAX,
474 REG_TYPE_DSPSC,
475 REG_TYPE_MMXWR,
476 REG_TYPE_MMXWC,
477 REG_TYPE_MMXWCG,
478 REG_TYPE_XSCALE,
bfae80f2
RE
479};
480
dcbf9037
JB
481/* Structure for a hash table entry for a register.
482 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
483 information which states whether a vector type or index is specified (for a
484 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
485struct reg_entry
486{
dcbf9037
JB
487 const char *name;
488 unsigned char number;
489 unsigned char type;
490 unsigned char builtin;
491 struct neon_typed_alias *neon;
6c43fab6
RE
492};
493
c19d1205
ZW
494/* Diagnostics used when we don't get a register of the expected type. */
495const char *const reg_expected_msgs[] =
496{
497 N_("ARM register expected"),
498 N_("bad or missing co-processor number"),
499 N_("co-processor register expected"),
500 N_("FPA register expected"),
501 N_("VFP single precision register expected"),
5287ad62
JB
502 N_("VFP/Neon double precision register expected"),
503 N_("Neon quad precision register expected"),
037e8744 504 N_("VFP single or double precision register expected"),
5287ad62 505 N_("Neon double or quad precision register expected"),
037e8744 506 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
507 N_("VFP system register expected"),
508 N_("Maverick MVF register expected"),
509 N_("Maverick MVD register expected"),
510 N_("Maverick MVFX register expected"),
511 N_("Maverick MVDX register expected"),
512 N_("Maverick MVAX register expected"),
513 N_("Maverick DSPSC register expected"),
514 N_("iWMMXt data register expected"),
515 N_("iWMMXt control register expected"),
516 N_("iWMMXt scalar register expected"),
517 N_("XScale accumulator register expected"),
6c43fab6
RE
518};
519
c19d1205
ZW
520/* Some well known registers that we refer to directly elsewhere. */
521#define REG_SP 13
522#define REG_LR 14
523#define REG_PC 15
404ff6b5 524
b99bd4ef
NC
525/* ARM instructions take 4bytes in the object file, Thumb instructions
526 take 2: */
c19d1205 527#define INSN_SIZE 4
b99bd4ef
NC
528
529struct asm_opcode
530{
531 /* Basic string to match. */
c19d1205
ZW
532 const char *template;
533
534 /* Parameters to instruction. */
535 unsigned char operands[8];
536
537 /* Conditional tag - see opcode_lookup. */
538 unsigned int tag : 4;
b99bd4ef
NC
539
540 /* Basic instruction code. */
c19d1205 541 unsigned int avalue : 28;
b99bd4ef 542
c19d1205
ZW
543 /* Thumb-format instruction code. */
544 unsigned int tvalue;
b99bd4ef 545
90e4755a 546 /* Which architecture variant provides this instruction. */
e74cfd16
PB
547 const arm_feature_set *avariant;
548 const arm_feature_set *tvariant;
c19d1205
ZW
549
550 /* Function to call to encode instruction in ARM format. */
551 void (* aencode) (void);
b99bd4ef 552
c19d1205
ZW
553 /* Function to call to encode instruction in Thumb format. */
554 void (* tencode) (void);
b99bd4ef
NC
555};
556
a737bd4d
NC
557/* Defines for various bits that we will want to toggle. */
558#define INST_IMMEDIATE 0x02000000
559#define OFFSET_REG 0x02000000
c19d1205 560#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
561#define SHIFT_BY_REG 0x00000010
562#define PRE_INDEX 0x01000000
563#define INDEX_UP 0x00800000
564#define WRITE_BACK 0x00200000
565#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 566#define CPSI_MMOD 0x00020000
90e4755a 567
a737bd4d
NC
568#define LITERAL_MASK 0xf000f000
569#define OPCODE_MASK 0xfe1fffff
570#define V4_STR_BIT 0x00000020
90e4755a 571
efd81785
PB
572#define T2_SUBS_PC_LR 0xf3de8f00
573
a737bd4d 574#define DATA_OP_SHIFT 21
90e4755a 575
ef8d22e6
PB
576#define T2_OPCODE_MASK 0xfe1fffff
577#define T2_DATA_OP_SHIFT 21
578
a737bd4d
NC
579/* Codes to distinguish the arithmetic instructions. */
580#define OPCODE_AND 0
581#define OPCODE_EOR 1
582#define OPCODE_SUB 2
583#define OPCODE_RSB 3
584#define OPCODE_ADD 4
585#define OPCODE_ADC 5
586#define OPCODE_SBC 6
587#define OPCODE_RSC 7
588#define OPCODE_TST 8
589#define OPCODE_TEQ 9
590#define OPCODE_CMP 10
591#define OPCODE_CMN 11
592#define OPCODE_ORR 12
593#define OPCODE_MOV 13
594#define OPCODE_BIC 14
595#define OPCODE_MVN 15
90e4755a 596
ef8d22e6
PB
597#define T2_OPCODE_AND 0
598#define T2_OPCODE_BIC 1
599#define T2_OPCODE_ORR 2
600#define T2_OPCODE_ORN 3
601#define T2_OPCODE_EOR 4
602#define T2_OPCODE_ADD 8
603#define T2_OPCODE_ADC 10
604#define T2_OPCODE_SBC 11
605#define T2_OPCODE_SUB 13
606#define T2_OPCODE_RSB 14
607
a737bd4d
NC
608#define T_OPCODE_MUL 0x4340
609#define T_OPCODE_TST 0x4200
610#define T_OPCODE_CMN 0x42c0
611#define T_OPCODE_NEG 0x4240
612#define T_OPCODE_MVN 0x43c0
90e4755a 613
a737bd4d
NC
614#define T_OPCODE_ADD_R3 0x1800
615#define T_OPCODE_SUB_R3 0x1a00
616#define T_OPCODE_ADD_HI 0x4400
617#define T_OPCODE_ADD_ST 0xb000
618#define T_OPCODE_SUB_ST 0xb080
619#define T_OPCODE_ADD_SP 0xa800
620#define T_OPCODE_ADD_PC 0xa000
621#define T_OPCODE_ADD_I8 0x3000
622#define T_OPCODE_SUB_I8 0x3800
623#define T_OPCODE_ADD_I3 0x1c00
624#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 625
a737bd4d
NC
626#define T_OPCODE_ASR_R 0x4100
627#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
628#define T_OPCODE_LSR_R 0x40c0
629#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
630#define T_OPCODE_ASR_I 0x1000
631#define T_OPCODE_LSL_I 0x0000
632#define T_OPCODE_LSR_I 0x0800
b99bd4ef 633
a737bd4d
NC
634#define T_OPCODE_MOV_I8 0x2000
635#define T_OPCODE_CMP_I8 0x2800
636#define T_OPCODE_CMP_LR 0x4280
637#define T_OPCODE_MOV_HR 0x4600
638#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 639
a737bd4d
NC
640#define T_OPCODE_LDR_PC 0x4800
641#define T_OPCODE_LDR_SP 0x9800
642#define T_OPCODE_STR_SP 0x9000
643#define T_OPCODE_LDR_IW 0x6800
644#define T_OPCODE_STR_IW 0x6000
645#define T_OPCODE_LDR_IH 0x8800
646#define T_OPCODE_STR_IH 0x8000
647#define T_OPCODE_LDR_IB 0x7800
648#define T_OPCODE_STR_IB 0x7000
649#define T_OPCODE_LDR_RW 0x5800
650#define T_OPCODE_STR_RW 0x5000
651#define T_OPCODE_LDR_RH 0x5a00
652#define T_OPCODE_STR_RH 0x5200
653#define T_OPCODE_LDR_RB 0x5c00
654#define T_OPCODE_STR_RB 0x5400
c9b604bd 655
a737bd4d
NC
656#define T_OPCODE_PUSH 0xb400
657#define T_OPCODE_POP 0xbc00
b99bd4ef 658
2fc8bdac 659#define T_OPCODE_BRANCH 0xe000
b99bd4ef 660
a737bd4d 661#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 662#define THUMB_PP_PC_LR 0x0100
c19d1205 663#define THUMB_LOAD_BIT 0x0800
53365c0d 664#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
665
666#define BAD_ARGS _("bad arguments to instruction")
fdfde340 667#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
668#define BAD_PC _("r15 not allowed here")
669#define BAD_COND _("instruction cannot be conditional")
670#define BAD_OVERLAP _("registers may not be the same")
671#define BAD_HIREG _("lo register required")
672#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 673#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
674#define BAD_BRANCH _("branch must be last instruction in IT block")
675#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 676#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
677
678static struct hash_control *arm_ops_hsh;
679static struct hash_control *arm_cond_hsh;
680static struct hash_control *arm_shift_hsh;
681static struct hash_control *arm_psr_hsh;
62b3e311 682static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
683static struct hash_control *arm_reg_hsh;
684static struct hash_control *arm_reloc_hsh;
62b3e311 685static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 686
b99bd4ef
NC
687/* Stuff needed to resolve the label ambiguity
688 As:
689 ...
690 label: <insn>
691 may differ from:
692 ...
693 label:
5f4273c7 694 <insn> */
b99bd4ef
NC
695
696symbolS * last_label_seen;
b34976b6 697static int label_is_thumb_function_name = FALSE;
a737bd4d 698\f
3d0c9500
NC
699/* Literal pool structure. Held on a per-section
700 and per-sub-section basis. */
a737bd4d 701
c19d1205 702#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 703typedef struct literal_pool
b99bd4ef 704{
c19d1205
ZW
705 expressionS literals [MAX_LITERAL_POOL_SIZE];
706 unsigned int next_free_entry;
707 unsigned int id;
708 symbolS * symbol;
709 segT section;
710 subsegT sub_section;
61b5f74b 711 struct literal_pool * next;
3d0c9500 712} literal_pool;
b99bd4ef 713
3d0c9500
NC
714/* Pointer to a linked list of literal pools. */
715literal_pool * list_of_pools = NULL;
e27ec89e
PB
716
717/* State variables for IT block handling. */
718static bfd_boolean current_it_mask = 0;
719static int current_cc;
c19d1205
ZW
720\f
721/* Pure syntax. */
b99bd4ef 722
c19d1205
ZW
723/* This array holds the chars that always start a comment. If the
724 pre-processor is disabled, these aren't very useful. */
725const char comment_chars[] = "@";
3d0c9500 726
c19d1205
ZW
727/* This array holds the chars that only start a comment at the beginning of
728 a line. If the line seems to have the form '# 123 filename'
729 .line and .file directives will appear in the pre-processed output. */
730/* Note that input_file.c hand checks for '#' at the beginning of the
731 first line of the input file. This is because the compiler outputs
732 #NO_APP at the beginning of its output. */
733/* Also note that comments like this one will always work. */
734const char line_comment_chars[] = "#";
3d0c9500 735
c19d1205 736const char line_separator_chars[] = ";";
b99bd4ef 737
c19d1205
ZW
738/* Chars that can be used to separate mant
739 from exp in floating point numbers. */
740const char EXP_CHARS[] = "eE";
3d0c9500 741
c19d1205
ZW
742/* Chars that mean this number is a floating point constant. */
743/* As in 0f12.456 */
744/* or 0d1.2345e12 */
b99bd4ef 745
c19d1205 746const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 747
c19d1205
ZW
748/* Prefix characters that indicate the start of an immediate
749 value. */
750#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 751
c19d1205
ZW
752/* Separator character handling. */
753
754#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
755
756static inline int
757skip_past_char (char ** str, char c)
758{
759 if (**str == c)
760 {
761 (*str)++;
762 return SUCCESS;
3d0c9500 763 }
c19d1205
ZW
764 else
765 return FAIL;
766}
767#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 768
c19d1205
ZW
769/* Arithmetic expressions (possibly involving symbols). */
770
771/* Return TRUE if anything in the expression is a bignum. */
772
773static int
774walk_no_bignums (symbolS * sp)
775{
776 if (symbol_get_value_expression (sp)->X_op == O_big)
777 return 1;
778
779 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 780 {
c19d1205
ZW
781 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
782 || (symbol_get_value_expression (sp)->X_op_symbol
783 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
784 }
785
c19d1205 786 return 0;
3d0c9500
NC
787}
788
c19d1205
ZW
789static int in_my_get_expression = 0;
790
791/* Third argument to my_get_expression. */
792#define GE_NO_PREFIX 0
793#define GE_IMM_PREFIX 1
794#define GE_OPT_PREFIX 2
5287ad62
JB
795/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
796 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
797#define GE_OPT_PREFIX_BIG 3
a737bd4d 798
b99bd4ef 799static int
c19d1205 800my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 801{
c19d1205
ZW
802 char * save_in;
803 segT seg;
b99bd4ef 804
c19d1205
ZW
805 /* In unified syntax, all prefixes are optional. */
806 if (unified_syntax)
5287ad62
JB
807 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
808 : GE_OPT_PREFIX;
b99bd4ef 809
c19d1205 810 switch (prefix_mode)
b99bd4ef 811 {
c19d1205
ZW
812 case GE_NO_PREFIX: break;
813 case GE_IMM_PREFIX:
814 if (!is_immediate_prefix (**str))
815 {
816 inst.error = _("immediate expression requires a # prefix");
817 return FAIL;
818 }
819 (*str)++;
820 break;
821 case GE_OPT_PREFIX:
5287ad62 822 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
823 if (is_immediate_prefix (**str))
824 (*str)++;
825 break;
826 default: abort ();
827 }
b99bd4ef 828
c19d1205 829 memset (ep, 0, sizeof (expressionS));
b99bd4ef 830
c19d1205
ZW
831 save_in = input_line_pointer;
832 input_line_pointer = *str;
833 in_my_get_expression = 1;
834 seg = expression (ep);
835 in_my_get_expression = 0;
836
837 if (ep->X_op == O_illegal)
b99bd4ef 838 {
c19d1205
ZW
839 /* We found a bad expression in md_operand(). */
840 *str = input_line_pointer;
841 input_line_pointer = save_in;
842 if (inst.error == NULL)
843 inst.error = _("bad expression");
844 return 1;
845 }
b99bd4ef 846
c19d1205
ZW
847#ifdef OBJ_AOUT
848 if (seg != absolute_section
849 && seg != text_section
850 && seg != data_section
851 && seg != bss_section
852 && seg != undefined_section)
853 {
854 inst.error = _("bad segment");
855 *str = input_line_pointer;
856 input_line_pointer = save_in;
857 return 1;
b99bd4ef 858 }
c19d1205 859#endif
b99bd4ef 860
c19d1205
ZW
861 /* Get rid of any bignums now, so that we don't generate an error for which
862 we can't establish a line number later on. Big numbers are never valid
863 in instructions, which is where this routine is always called. */
5287ad62
JB
864 if (prefix_mode != GE_OPT_PREFIX_BIG
865 && (ep->X_op == O_big
866 || (ep->X_add_symbol
867 && (walk_no_bignums (ep->X_add_symbol)
868 || (ep->X_op_symbol
869 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
870 {
871 inst.error = _("invalid constant");
872 *str = input_line_pointer;
873 input_line_pointer = save_in;
874 return 1;
875 }
b99bd4ef 876
c19d1205
ZW
877 *str = input_line_pointer;
878 input_line_pointer = save_in;
879 return 0;
b99bd4ef
NC
880}
881
c19d1205
ZW
882/* Turn a string in input_line_pointer into a floating point constant
883 of type TYPE, and store the appropriate bytes in *LITP. The number
884 of LITTLENUMS emitted is stored in *SIZEP. An error message is
885 returned, or NULL on OK.
b99bd4ef 886
c19d1205
ZW
887 Note that fp constants aren't represent in the normal way on the ARM.
888 In big endian mode, things are as expected. However, in little endian
889 mode fp constants are big-endian word-wise, and little-endian byte-wise
890 within the words. For example, (double) 1.1 in big endian mode is
891 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
892 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 893
c19d1205 894 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 895
c19d1205
ZW
896char *
897md_atof (int type, char * litP, int * sizeP)
898{
899 int prec;
900 LITTLENUM_TYPE words[MAX_LITTLENUMS];
901 char *t;
902 int i;
b99bd4ef 903
c19d1205
ZW
904 switch (type)
905 {
906 case 'f':
907 case 'F':
908 case 's':
909 case 'S':
910 prec = 2;
911 break;
b99bd4ef 912
c19d1205
ZW
913 case 'd':
914 case 'D':
915 case 'r':
916 case 'R':
917 prec = 4;
918 break;
b99bd4ef 919
c19d1205
ZW
920 case 'x':
921 case 'X':
499ac353 922 prec = 5;
c19d1205 923 break;
b99bd4ef 924
c19d1205
ZW
925 case 'p':
926 case 'P':
499ac353 927 prec = 5;
c19d1205 928 break;
a737bd4d 929
c19d1205
ZW
930 default:
931 *sizeP = 0;
499ac353 932 return _("Unrecognized or unsupported floating point constant");
c19d1205 933 }
b99bd4ef 934
c19d1205
ZW
935 t = atof_ieee (input_line_pointer, type, words);
936 if (t)
937 input_line_pointer = t;
499ac353 938 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 939
c19d1205
ZW
940 if (target_big_endian)
941 {
942 for (i = 0; i < prec; i++)
943 {
499ac353
NC
944 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
945 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
946 }
947 }
948 else
949 {
e74cfd16 950 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
951 for (i = prec - 1; i >= 0; i--)
952 {
499ac353
NC
953 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
954 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
955 }
956 else
957 /* For a 4 byte float the order of elements in `words' is 1 0.
958 For an 8 byte float the order is 1 0 3 2. */
959 for (i = 0; i < prec; i += 2)
960 {
499ac353
NC
961 md_number_to_chars (litP, (valueT) words[i + 1],
962 sizeof (LITTLENUM_TYPE));
963 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
964 (valueT) words[i], sizeof (LITTLENUM_TYPE));
965 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
966 }
967 }
b99bd4ef 968
499ac353 969 return NULL;
c19d1205 970}
b99bd4ef 971
c19d1205
ZW
972/* We handle all bad expressions here, so that we can report the faulty
973 instruction in the error message. */
974void
975md_operand (expressionS * expr)
976{
977 if (in_my_get_expression)
978 expr->X_op = O_illegal;
b99bd4ef
NC
979}
980
c19d1205 981/* Immediate values. */
b99bd4ef 982
c19d1205
ZW
983/* Generic immediate-value read function for use in directives.
984 Accepts anything that 'expression' can fold to a constant.
985 *val receives the number. */
986#ifdef OBJ_ELF
987static int
988immediate_for_directive (int *val)
b99bd4ef 989{
c19d1205
ZW
990 expressionS exp;
991 exp.X_op = O_illegal;
b99bd4ef 992
c19d1205
ZW
993 if (is_immediate_prefix (*input_line_pointer))
994 {
995 input_line_pointer++;
996 expression (&exp);
997 }
b99bd4ef 998
c19d1205
ZW
999 if (exp.X_op != O_constant)
1000 {
1001 as_bad (_("expected #constant"));
1002 ignore_rest_of_line ();
1003 return FAIL;
1004 }
1005 *val = exp.X_add_number;
1006 return SUCCESS;
b99bd4ef 1007}
c19d1205 1008#endif
b99bd4ef 1009
c19d1205 1010/* Register parsing. */
b99bd4ef 1011
c19d1205
ZW
1012/* Generic register parser. CCP points to what should be the
1013 beginning of a register name. If it is indeed a valid register
1014 name, advance CCP over it and return the reg_entry structure;
1015 otherwise return NULL. Does not issue diagnostics. */
1016
1017static struct reg_entry *
1018arm_reg_parse_multi (char **ccp)
b99bd4ef 1019{
c19d1205
ZW
1020 char *start = *ccp;
1021 char *p;
1022 struct reg_entry *reg;
b99bd4ef 1023
c19d1205
ZW
1024#ifdef REGISTER_PREFIX
1025 if (*start != REGISTER_PREFIX)
01cfc07f 1026 return NULL;
c19d1205
ZW
1027 start++;
1028#endif
1029#ifdef OPTIONAL_REGISTER_PREFIX
1030 if (*start == OPTIONAL_REGISTER_PREFIX)
1031 start++;
1032#endif
b99bd4ef 1033
c19d1205
ZW
1034 p = start;
1035 if (!ISALPHA (*p) || !is_name_beginner (*p))
1036 return NULL;
b99bd4ef 1037
c19d1205
ZW
1038 do
1039 p++;
1040 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1041
1042 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1043
1044 if (!reg)
1045 return NULL;
1046
1047 *ccp = p;
1048 return reg;
b99bd4ef
NC
1049}
1050
1051static int
dcbf9037
JB
1052arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1053 enum arm_reg_type type)
b99bd4ef 1054{
c19d1205
ZW
1055 /* Alternative syntaxes are accepted for a few register classes. */
1056 switch (type)
1057 {
1058 case REG_TYPE_MVF:
1059 case REG_TYPE_MVD:
1060 case REG_TYPE_MVFX:
1061 case REG_TYPE_MVDX:
1062 /* Generic coprocessor register names are allowed for these. */
79134647 1063 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1064 return reg->number;
1065 break;
69b97547 1066
c19d1205
ZW
1067 case REG_TYPE_CP:
1068 /* For backward compatibility, a bare number is valid here. */
1069 {
1070 unsigned long processor = strtoul (start, ccp, 10);
1071 if (*ccp != start && processor <= 15)
1072 return processor;
1073 }
6057a28f 1074
c19d1205
ZW
1075 case REG_TYPE_MMXWC:
1076 /* WC includes WCG. ??? I'm not sure this is true for all
1077 instructions that take WC registers. */
79134647 1078 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1079 return reg->number;
6057a28f 1080 break;
c19d1205 1081
6057a28f 1082 default:
c19d1205 1083 break;
6057a28f
NC
1084 }
1085
dcbf9037
JB
1086 return FAIL;
1087}
1088
1089/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1090 return value is the register number or FAIL. */
1091
1092static int
1093arm_reg_parse (char **ccp, enum arm_reg_type type)
1094{
1095 char *start = *ccp;
1096 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1097 int ret;
1098
1099 /* Do not allow a scalar (reg+index) to parse as a register. */
1100 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1101 return FAIL;
1102
1103 if (reg && reg->type == type)
1104 return reg->number;
1105
1106 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1107 return ret;
1108
c19d1205
ZW
1109 *ccp = start;
1110 return FAIL;
1111}
69b97547 1112
dcbf9037
JB
1113/* Parse a Neon type specifier. *STR should point at the leading '.'
1114 character. Does no verification at this stage that the type fits the opcode
1115 properly. E.g.,
1116
1117 .i32.i32.s16
1118 .s32.f32
1119 .u16
1120
1121 Can all be legally parsed by this function.
1122
1123 Fills in neon_type struct pointer with parsed information, and updates STR
1124 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1125 type, FAIL if not. */
1126
1127static int
1128parse_neon_type (struct neon_type *type, char **str)
1129{
1130 char *ptr = *str;
1131
1132 if (type)
1133 type->elems = 0;
1134
1135 while (type->elems < NEON_MAX_TYPE_ELS)
1136 {
1137 enum neon_el_type thistype = NT_untyped;
1138 unsigned thissize = -1u;
1139
1140 if (*ptr != '.')
1141 break;
1142
1143 ptr++;
1144
1145 /* Just a size without an explicit type. */
1146 if (ISDIGIT (*ptr))
1147 goto parsesize;
1148
1149 switch (TOLOWER (*ptr))
1150 {
1151 case 'i': thistype = NT_integer; break;
1152 case 'f': thistype = NT_float; break;
1153 case 'p': thistype = NT_poly; break;
1154 case 's': thistype = NT_signed; break;
1155 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1156 case 'd':
1157 thistype = NT_float;
1158 thissize = 64;
1159 ptr++;
1160 goto done;
dcbf9037
JB
1161 default:
1162 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1163 return FAIL;
1164 }
1165
1166 ptr++;
1167
1168 /* .f is an abbreviation for .f32. */
1169 if (thistype == NT_float && !ISDIGIT (*ptr))
1170 thissize = 32;
1171 else
1172 {
1173 parsesize:
1174 thissize = strtoul (ptr, &ptr, 10);
1175
1176 if (thissize != 8 && thissize != 16 && thissize != 32
1177 && thissize != 64)
1178 {
1179 as_bad (_("bad size %d in type specifier"), thissize);
1180 return FAIL;
1181 }
1182 }
1183
037e8744 1184 done:
dcbf9037
JB
1185 if (type)
1186 {
1187 type->el[type->elems].type = thistype;
1188 type->el[type->elems].size = thissize;
1189 type->elems++;
1190 }
1191 }
1192
1193 /* Empty/missing type is not a successful parse. */
1194 if (type->elems == 0)
1195 return FAIL;
1196
1197 *str = ptr;
1198
1199 return SUCCESS;
1200}
1201
1202/* Errors may be set multiple times during parsing or bit encoding
1203 (particularly in the Neon bits), but usually the earliest error which is set
1204 will be the most meaningful. Avoid overwriting it with later (cascading)
1205 errors by calling this function. */
1206
1207static void
1208first_error (const char *err)
1209{
1210 if (!inst.error)
1211 inst.error = err;
1212}
1213
1214/* Parse a single type, e.g. ".s32", leading period included. */
1215static int
1216parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1217{
1218 char *str = *ccp;
1219 struct neon_type optype;
1220
1221 if (*str == '.')
1222 {
1223 if (parse_neon_type (&optype, &str) == SUCCESS)
1224 {
1225 if (optype.elems == 1)
1226 *vectype = optype.el[0];
1227 else
1228 {
1229 first_error (_("only one type should be specified for operand"));
1230 return FAIL;
1231 }
1232 }
1233 else
1234 {
1235 first_error (_("vector type expected"));
1236 return FAIL;
1237 }
1238 }
1239 else
1240 return FAIL;
5f4273c7 1241
dcbf9037 1242 *ccp = str;
5f4273c7 1243
dcbf9037
JB
1244 return SUCCESS;
1245}
1246
1247/* Special meanings for indices (which have a range of 0-7), which will fit into
1248 a 4-bit integer. */
1249
1250#define NEON_ALL_LANES 15
1251#define NEON_INTERLEAVE_LANES 14
1252
1253/* Parse either a register or a scalar, with an optional type. Return the
1254 register number, and optionally fill in the actual type of the register
1255 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1256 type/index information in *TYPEINFO. */
1257
1258static int
1259parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1260 enum arm_reg_type *rtype,
1261 struct neon_typed_alias *typeinfo)
1262{
1263 char *str = *ccp;
1264 struct reg_entry *reg = arm_reg_parse_multi (&str);
1265 struct neon_typed_alias atype;
1266 struct neon_type_el parsetype;
1267
1268 atype.defined = 0;
1269 atype.index = -1;
1270 atype.eltype.type = NT_invtype;
1271 atype.eltype.size = -1;
1272
1273 /* Try alternate syntax for some types of register. Note these are mutually
1274 exclusive with the Neon syntax extensions. */
1275 if (reg == NULL)
1276 {
1277 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1278 if (altreg != FAIL)
1279 *ccp = str;
1280 if (typeinfo)
1281 *typeinfo = atype;
1282 return altreg;
1283 }
1284
037e8744
JB
1285 /* Undo polymorphism when a set of register types may be accepted. */
1286 if ((type == REG_TYPE_NDQ
1287 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1288 || (type == REG_TYPE_VFSD
1289 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1290 || (type == REG_TYPE_NSDQ
1291 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1292 || reg->type == REG_TYPE_NQ))
1293 || (type == REG_TYPE_MMXWC
1294 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1295 type = reg->type;
1296
1297 if (type != reg->type)
1298 return FAIL;
1299
1300 if (reg->neon)
1301 atype = *reg->neon;
5f4273c7 1302
dcbf9037
JB
1303 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1304 {
1305 if ((atype.defined & NTA_HASTYPE) != 0)
1306 {
1307 first_error (_("can't redefine type for operand"));
1308 return FAIL;
1309 }
1310 atype.defined |= NTA_HASTYPE;
1311 atype.eltype = parsetype;
1312 }
5f4273c7 1313
dcbf9037
JB
1314 if (skip_past_char (&str, '[') == SUCCESS)
1315 {
1316 if (type != REG_TYPE_VFD)
1317 {
1318 first_error (_("only D registers may be indexed"));
1319 return FAIL;
1320 }
5f4273c7 1321
dcbf9037
JB
1322 if ((atype.defined & NTA_HASINDEX) != 0)
1323 {
1324 first_error (_("can't change index for operand"));
1325 return FAIL;
1326 }
1327
1328 atype.defined |= NTA_HASINDEX;
1329
1330 if (skip_past_char (&str, ']') == SUCCESS)
1331 atype.index = NEON_ALL_LANES;
1332 else
1333 {
1334 expressionS exp;
1335
1336 my_get_expression (&exp, &str, GE_NO_PREFIX);
1337
1338 if (exp.X_op != O_constant)
1339 {
1340 first_error (_("constant expression required"));
1341 return FAIL;
1342 }
1343
1344 if (skip_past_char (&str, ']') == FAIL)
1345 return FAIL;
1346
1347 atype.index = exp.X_add_number;
1348 }
1349 }
5f4273c7 1350
dcbf9037
JB
1351 if (typeinfo)
1352 *typeinfo = atype;
5f4273c7 1353
dcbf9037
JB
1354 if (rtype)
1355 *rtype = type;
5f4273c7 1356
dcbf9037 1357 *ccp = str;
5f4273c7 1358
dcbf9037
JB
1359 return reg->number;
1360}
1361
1362/* Like arm_reg_parse, but allow allow the following extra features:
1363 - If RTYPE is non-zero, return the (possibly restricted) type of the
1364 register (e.g. Neon double or quad reg when either has been requested).
1365 - If this is a Neon vector type with additional type information, fill
1366 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1367 This function will fault on encountering a scalar. */
dcbf9037
JB
1368
1369static int
1370arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1371 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1372{
1373 struct neon_typed_alias atype;
1374 char *str = *ccp;
1375 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1376
1377 if (reg == FAIL)
1378 return FAIL;
1379
1380 /* Do not allow a scalar (reg+index) to parse as a register. */
1381 if ((atype.defined & NTA_HASINDEX) != 0)
1382 {
1383 first_error (_("register operand expected, but got scalar"));
1384 return FAIL;
1385 }
1386
1387 if (vectype)
1388 *vectype = atype.eltype;
1389
1390 *ccp = str;
1391
1392 return reg;
1393}
1394
1395#define NEON_SCALAR_REG(X) ((X) >> 4)
1396#define NEON_SCALAR_INDEX(X) ((X) & 15)
1397
5287ad62
JB
1398/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1399 have enough information to be able to do a good job bounds-checking. So, we
1400 just do easy checks here, and do further checks later. */
1401
1402static int
dcbf9037 1403parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1404{
dcbf9037 1405 int reg;
5287ad62 1406 char *str = *ccp;
dcbf9037 1407 struct neon_typed_alias atype;
5f4273c7 1408
dcbf9037 1409 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1410
dcbf9037 1411 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1412 return FAIL;
5f4273c7 1413
dcbf9037 1414 if (atype.index == NEON_ALL_LANES)
5287ad62 1415 {
dcbf9037 1416 first_error (_("scalar must have an index"));
5287ad62
JB
1417 return FAIL;
1418 }
dcbf9037 1419 else if (atype.index >= 64 / elsize)
5287ad62 1420 {
dcbf9037 1421 first_error (_("scalar index out of range"));
5287ad62
JB
1422 return FAIL;
1423 }
5f4273c7 1424
dcbf9037
JB
1425 if (type)
1426 *type = atype.eltype;
5f4273c7 1427
5287ad62 1428 *ccp = str;
5f4273c7 1429
dcbf9037 1430 return reg * 16 + atype.index;
5287ad62
JB
1431}
1432
c19d1205
ZW
1433/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1434static long
1435parse_reg_list (char ** strp)
1436{
1437 char * str = * strp;
1438 long range = 0;
1439 int another_range;
a737bd4d 1440
c19d1205
ZW
1441 /* We come back here if we get ranges concatenated by '+' or '|'. */
1442 do
6057a28f 1443 {
c19d1205 1444 another_range = 0;
a737bd4d 1445
c19d1205
ZW
1446 if (*str == '{')
1447 {
1448 int in_range = 0;
1449 int cur_reg = -1;
a737bd4d 1450
c19d1205
ZW
1451 str++;
1452 do
1453 {
1454 int reg;
6057a28f 1455
dcbf9037 1456 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1457 {
dcbf9037 1458 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1459 return FAIL;
1460 }
a737bd4d 1461
c19d1205
ZW
1462 if (in_range)
1463 {
1464 int i;
a737bd4d 1465
c19d1205
ZW
1466 if (reg <= cur_reg)
1467 {
dcbf9037 1468 first_error (_("bad range in register list"));
c19d1205
ZW
1469 return FAIL;
1470 }
40a18ebd 1471
c19d1205
ZW
1472 for (i = cur_reg + 1; i < reg; i++)
1473 {
1474 if (range & (1 << i))
1475 as_tsktsk
1476 (_("Warning: duplicated register (r%d) in register list"),
1477 i);
1478 else
1479 range |= 1 << i;
1480 }
1481 in_range = 0;
1482 }
a737bd4d 1483
c19d1205
ZW
1484 if (range & (1 << reg))
1485 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1486 reg);
1487 else if (reg <= cur_reg)
1488 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1489
c19d1205
ZW
1490 range |= 1 << reg;
1491 cur_reg = reg;
1492 }
1493 while (skip_past_comma (&str) != FAIL
1494 || (in_range = 1, *str++ == '-'));
1495 str--;
a737bd4d 1496
c19d1205
ZW
1497 if (*str++ != '}')
1498 {
dcbf9037 1499 first_error (_("missing `}'"));
c19d1205
ZW
1500 return FAIL;
1501 }
1502 }
1503 else
1504 {
1505 expressionS expr;
40a18ebd 1506
c19d1205
ZW
1507 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1508 return FAIL;
40a18ebd 1509
c19d1205
ZW
1510 if (expr.X_op == O_constant)
1511 {
1512 if (expr.X_add_number
1513 != (expr.X_add_number & 0x0000ffff))
1514 {
1515 inst.error = _("invalid register mask");
1516 return FAIL;
1517 }
a737bd4d 1518
c19d1205
ZW
1519 if ((range & expr.X_add_number) != 0)
1520 {
1521 int regno = range & expr.X_add_number;
a737bd4d 1522
c19d1205
ZW
1523 regno &= -regno;
1524 regno = (1 << regno) - 1;
1525 as_tsktsk
1526 (_("Warning: duplicated register (r%d) in register list"),
1527 regno);
1528 }
a737bd4d 1529
c19d1205
ZW
1530 range |= expr.X_add_number;
1531 }
1532 else
1533 {
1534 if (inst.reloc.type != 0)
1535 {
1536 inst.error = _("expression too complex");
1537 return FAIL;
1538 }
a737bd4d 1539
c19d1205
ZW
1540 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1541 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1542 inst.reloc.pc_rel = 0;
1543 }
1544 }
a737bd4d 1545
c19d1205
ZW
1546 if (*str == '|' || *str == '+')
1547 {
1548 str++;
1549 another_range = 1;
1550 }
a737bd4d 1551 }
c19d1205 1552 while (another_range);
a737bd4d 1553
c19d1205
ZW
1554 *strp = str;
1555 return range;
a737bd4d
NC
1556}
1557
5287ad62
JB
1558/* Types of registers in a list. */
1559
1560enum reg_list_els
1561{
1562 REGLIST_VFP_S,
1563 REGLIST_VFP_D,
1564 REGLIST_NEON_D
1565};
1566
c19d1205
ZW
1567/* Parse a VFP register list. If the string is invalid return FAIL.
1568 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1569 register. Parses registers of type ETYPE.
1570 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1571 - Q registers can be used to specify pairs of D registers
1572 - { } can be omitted from around a singleton register list
1573 FIXME: This is not implemented, as it would require backtracking in
1574 some cases, e.g.:
1575 vtbl.8 d3,d4,d5
1576 This could be done (the meaning isn't really ambiguous), but doesn't
1577 fit in well with the current parsing framework.
dcbf9037
JB
1578 - 32 D registers may be used (also true for VFPv3).
1579 FIXME: Types are ignored in these register lists, which is probably a
1580 bug. */
6057a28f 1581
c19d1205 1582static int
037e8744 1583parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1584{
037e8744 1585 char *str = *ccp;
c19d1205
ZW
1586 int base_reg;
1587 int new_base;
5287ad62
JB
1588 enum arm_reg_type regtype = 0;
1589 int max_regs = 0;
c19d1205
ZW
1590 int count = 0;
1591 int warned = 0;
1592 unsigned long mask = 0;
a737bd4d 1593 int i;
6057a28f 1594
037e8744 1595 if (*str != '{')
5287ad62
JB
1596 {
1597 inst.error = _("expecting {");
1598 return FAIL;
1599 }
6057a28f 1600
037e8744 1601 str++;
6057a28f 1602
5287ad62 1603 switch (etype)
c19d1205 1604 {
5287ad62 1605 case REGLIST_VFP_S:
c19d1205
ZW
1606 regtype = REG_TYPE_VFS;
1607 max_regs = 32;
5287ad62 1608 break;
5f4273c7 1609
5287ad62
JB
1610 case REGLIST_VFP_D:
1611 regtype = REG_TYPE_VFD;
b7fc2769 1612 break;
5f4273c7 1613
b7fc2769
JB
1614 case REGLIST_NEON_D:
1615 regtype = REG_TYPE_NDQ;
1616 break;
1617 }
1618
1619 if (etype != REGLIST_VFP_S)
1620 {
b1cc4aeb
PB
1621 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1622 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1623 {
1624 max_regs = 32;
1625 if (thumb_mode)
1626 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1627 fpu_vfp_ext_d32);
5287ad62
JB
1628 else
1629 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1630 fpu_vfp_ext_d32);
5287ad62
JB
1631 }
1632 else
1633 max_regs = 16;
c19d1205 1634 }
6057a28f 1635
c19d1205 1636 base_reg = max_regs;
a737bd4d 1637
c19d1205
ZW
1638 do
1639 {
5287ad62 1640 int setmask = 1, addregs = 1;
dcbf9037 1641
037e8744 1642 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1643
c19d1205 1644 if (new_base == FAIL)
a737bd4d 1645 {
dcbf9037 1646 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1647 return FAIL;
1648 }
5f4273c7 1649
b7fc2769
JB
1650 if (new_base >= max_regs)
1651 {
1652 first_error (_("register out of range in list"));
1653 return FAIL;
1654 }
5f4273c7 1655
5287ad62
JB
1656 /* Note: a value of 2 * n is returned for the register Q<n>. */
1657 if (regtype == REG_TYPE_NQ)
1658 {
1659 setmask = 3;
1660 addregs = 2;
1661 }
1662
c19d1205
ZW
1663 if (new_base < base_reg)
1664 base_reg = new_base;
a737bd4d 1665
5287ad62 1666 if (mask & (setmask << new_base))
c19d1205 1667 {
dcbf9037 1668 first_error (_("invalid register list"));
c19d1205 1669 return FAIL;
a737bd4d 1670 }
a737bd4d 1671
c19d1205
ZW
1672 if ((mask >> new_base) != 0 && ! warned)
1673 {
1674 as_tsktsk (_("register list not in ascending order"));
1675 warned = 1;
1676 }
0bbf2aa4 1677
5287ad62
JB
1678 mask |= setmask << new_base;
1679 count += addregs;
0bbf2aa4 1680
037e8744 1681 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1682 {
1683 int high_range;
0bbf2aa4 1684
037e8744 1685 str++;
0bbf2aa4 1686
037e8744 1687 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1688 == FAIL)
c19d1205
ZW
1689 {
1690 inst.error = gettext (reg_expected_msgs[regtype]);
1691 return FAIL;
1692 }
0bbf2aa4 1693
b7fc2769
JB
1694 if (high_range >= max_regs)
1695 {
1696 first_error (_("register out of range in list"));
1697 return FAIL;
1698 }
1699
5287ad62
JB
1700 if (regtype == REG_TYPE_NQ)
1701 high_range = high_range + 1;
1702
c19d1205
ZW
1703 if (high_range <= new_base)
1704 {
1705 inst.error = _("register range not in ascending order");
1706 return FAIL;
1707 }
0bbf2aa4 1708
5287ad62 1709 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1710 {
5287ad62 1711 if (mask & (setmask << new_base))
0bbf2aa4 1712 {
c19d1205
ZW
1713 inst.error = _("invalid register list");
1714 return FAIL;
0bbf2aa4 1715 }
c19d1205 1716
5287ad62
JB
1717 mask |= setmask << new_base;
1718 count += addregs;
0bbf2aa4 1719 }
0bbf2aa4 1720 }
0bbf2aa4 1721 }
037e8744 1722 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1723
037e8744 1724 str++;
0bbf2aa4 1725
c19d1205
ZW
1726 /* Sanity check -- should have raised a parse error above. */
1727 if (count == 0 || count > max_regs)
1728 abort ();
1729
1730 *pbase = base_reg;
1731
1732 /* Final test -- the registers must be consecutive. */
1733 mask >>= base_reg;
1734 for (i = 0; i < count; i++)
1735 {
1736 if ((mask & (1u << i)) == 0)
1737 {
1738 inst.error = _("non-contiguous register range");
1739 return FAIL;
1740 }
1741 }
1742
037e8744
JB
1743 *ccp = str;
1744
c19d1205 1745 return count;
b99bd4ef
NC
1746}
1747
dcbf9037
JB
1748/* True if two alias types are the same. */
1749
1750static int
1751neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1752{
1753 if (!a && !b)
1754 return 1;
5f4273c7 1755
dcbf9037
JB
1756 if (!a || !b)
1757 return 0;
1758
1759 if (a->defined != b->defined)
1760 return 0;
5f4273c7 1761
dcbf9037
JB
1762 if ((a->defined & NTA_HASTYPE) != 0
1763 && (a->eltype.type != b->eltype.type
1764 || a->eltype.size != b->eltype.size))
1765 return 0;
1766
1767 if ((a->defined & NTA_HASINDEX) != 0
1768 && (a->index != b->index))
1769 return 0;
5f4273c7 1770
dcbf9037
JB
1771 return 1;
1772}
1773
5287ad62
JB
1774/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1775 The base register is put in *PBASE.
dcbf9037 1776 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1777 the return value.
1778 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1779 Bits [6:5] encode the list length (minus one).
1780 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1781
5287ad62 1782#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1783#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1784#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1785
1786static int
dcbf9037
JB
1787parse_neon_el_struct_list (char **str, unsigned *pbase,
1788 struct neon_type_el *eltype)
5287ad62
JB
1789{
1790 char *ptr = *str;
1791 int base_reg = -1;
1792 int reg_incr = -1;
1793 int count = 0;
1794 int lane = -1;
1795 int leading_brace = 0;
1796 enum arm_reg_type rtype = REG_TYPE_NDQ;
1797 int addregs = 1;
1798 const char *const incr_error = "register stride must be 1 or 2";
1799 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1800 struct neon_typed_alias firsttype;
5f4273c7 1801
5287ad62
JB
1802 if (skip_past_char (&ptr, '{') == SUCCESS)
1803 leading_brace = 1;
5f4273c7 1804
5287ad62
JB
1805 do
1806 {
dcbf9037
JB
1807 struct neon_typed_alias atype;
1808 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1809
5287ad62
JB
1810 if (getreg == FAIL)
1811 {
dcbf9037 1812 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1813 return FAIL;
1814 }
5f4273c7 1815
5287ad62
JB
1816 if (base_reg == -1)
1817 {
1818 base_reg = getreg;
1819 if (rtype == REG_TYPE_NQ)
1820 {
1821 reg_incr = 1;
1822 addregs = 2;
1823 }
dcbf9037 1824 firsttype = atype;
5287ad62
JB
1825 }
1826 else if (reg_incr == -1)
1827 {
1828 reg_incr = getreg - base_reg;
1829 if (reg_incr < 1 || reg_incr > 2)
1830 {
dcbf9037 1831 first_error (_(incr_error));
5287ad62
JB
1832 return FAIL;
1833 }
1834 }
1835 else if (getreg != base_reg + reg_incr * count)
1836 {
dcbf9037
JB
1837 first_error (_(incr_error));
1838 return FAIL;
1839 }
1840
1841 if (!neon_alias_types_same (&atype, &firsttype))
1842 {
1843 first_error (_(type_error));
5287ad62
JB
1844 return FAIL;
1845 }
5f4273c7 1846
5287ad62
JB
1847 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1848 modes. */
1849 if (ptr[0] == '-')
1850 {
dcbf9037 1851 struct neon_typed_alias htype;
5287ad62
JB
1852 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1853 if (lane == -1)
1854 lane = NEON_INTERLEAVE_LANES;
1855 else if (lane != NEON_INTERLEAVE_LANES)
1856 {
dcbf9037 1857 first_error (_(type_error));
5287ad62
JB
1858 return FAIL;
1859 }
1860 if (reg_incr == -1)
1861 reg_incr = 1;
1862 else if (reg_incr != 1)
1863 {
dcbf9037 1864 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1865 return FAIL;
1866 }
1867 ptr++;
dcbf9037 1868 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1869 if (hireg == FAIL)
1870 {
dcbf9037
JB
1871 first_error (_(reg_expected_msgs[rtype]));
1872 return FAIL;
1873 }
1874 if (!neon_alias_types_same (&htype, &firsttype))
1875 {
1876 first_error (_(type_error));
5287ad62
JB
1877 return FAIL;
1878 }
1879 count += hireg + dregs - getreg;
1880 continue;
1881 }
5f4273c7 1882
5287ad62
JB
1883 /* If we're using Q registers, we can't use [] or [n] syntax. */
1884 if (rtype == REG_TYPE_NQ)
1885 {
1886 count += 2;
1887 continue;
1888 }
5f4273c7 1889
dcbf9037 1890 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1891 {
dcbf9037
JB
1892 if (lane == -1)
1893 lane = atype.index;
1894 else if (lane != atype.index)
5287ad62 1895 {
dcbf9037
JB
1896 first_error (_(type_error));
1897 return FAIL;
5287ad62
JB
1898 }
1899 }
1900 else if (lane == -1)
1901 lane = NEON_INTERLEAVE_LANES;
1902 else if (lane != NEON_INTERLEAVE_LANES)
1903 {
dcbf9037 1904 first_error (_(type_error));
5287ad62
JB
1905 return FAIL;
1906 }
1907 count++;
1908 }
1909 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1910
5287ad62
JB
1911 /* No lane set by [x]. We must be interleaving structures. */
1912 if (lane == -1)
1913 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1914
5287ad62
JB
1915 /* Sanity check. */
1916 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1917 || (count > 1 && reg_incr == -1))
1918 {
dcbf9037 1919 first_error (_("error parsing element/structure list"));
5287ad62
JB
1920 return FAIL;
1921 }
1922
1923 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1924 {
dcbf9037 1925 first_error (_("expected }"));
5287ad62
JB
1926 return FAIL;
1927 }
5f4273c7 1928
5287ad62
JB
1929 if (reg_incr == -1)
1930 reg_incr = 1;
1931
dcbf9037
JB
1932 if (eltype)
1933 *eltype = firsttype.eltype;
1934
5287ad62
JB
1935 *pbase = base_reg;
1936 *str = ptr;
5f4273c7 1937
5287ad62
JB
1938 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1939}
1940
c19d1205
ZW
1941/* Parse an explicit relocation suffix on an expression. This is
1942 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1943 arm_reloc_hsh contains no entries, so this function can only
1944 succeed if there is no () after the word. Returns -1 on error,
1945 BFD_RELOC_UNUSED if there wasn't any suffix. */
1946static int
1947parse_reloc (char **str)
b99bd4ef 1948{
c19d1205
ZW
1949 struct reloc_entry *r;
1950 char *p, *q;
b99bd4ef 1951
c19d1205
ZW
1952 if (**str != '(')
1953 return BFD_RELOC_UNUSED;
b99bd4ef 1954
c19d1205
ZW
1955 p = *str + 1;
1956 q = p;
1957
1958 while (*q && *q != ')' && *q != ',')
1959 q++;
1960 if (*q != ')')
1961 return -1;
1962
1963 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1964 return -1;
1965
1966 *str = q + 1;
1967 return r->reloc;
b99bd4ef
NC
1968}
1969
c19d1205
ZW
1970/* Directives: register aliases. */
1971
dcbf9037 1972static struct reg_entry *
c19d1205 1973insert_reg_alias (char *str, int number, int type)
b99bd4ef 1974{
c19d1205
ZW
1975 struct reg_entry *new;
1976 const char *name;
b99bd4ef 1977
c19d1205
ZW
1978 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1979 {
1980 if (new->builtin)
1981 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1982
c19d1205
ZW
1983 /* Only warn about a redefinition if it's not defined as the
1984 same register. */
1985 else if (new->number != number || new->type != type)
1986 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1987
d929913e 1988 return NULL;
c19d1205 1989 }
b99bd4ef 1990
c19d1205
ZW
1991 name = xstrdup (str);
1992 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1993
c19d1205
ZW
1994 new->name = name;
1995 new->number = number;
1996 new->type = type;
1997 new->builtin = FALSE;
dcbf9037 1998 new->neon = NULL;
b99bd4ef 1999
5a49b8ac 2000 if (hash_insert (arm_reg_hsh, name, (void *) new))
c19d1205 2001 abort ();
5f4273c7 2002
dcbf9037
JB
2003 return new;
2004}
2005
2006static void
2007insert_neon_reg_alias (char *str, int number, int type,
2008 struct neon_typed_alias *atype)
2009{
2010 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2011
dcbf9037
JB
2012 if (!reg)
2013 {
2014 first_error (_("attempt to redefine typed alias"));
2015 return;
2016 }
5f4273c7 2017
dcbf9037
JB
2018 if (atype)
2019 {
2020 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2021 *reg->neon = *atype;
2022 }
c19d1205 2023}
b99bd4ef 2024
c19d1205 2025/* Look for the .req directive. This is of the form:
b99bd4ef 2026
c19d1205 2027 new_register_name .req existing_register_name
b99bd4ef 2028
c19d1205 2029 If we find one, or if it looks sufficiently like one that we want to
d929913e 2030 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2031
d929913e 2032static bfd_boolean
c19d1205
ZW
2033create_register_alias (char * newname, char *p)
2034{
2035 struct reg_entry *old;
2036 char *oldname, *nbuf;
2037 size_t nlen;
b99bd4ef 2038
c19d1205
ZW
2039 /* The input scrubber ensures that whitespace after the mnemonic is
2040 collapsed to single spaces. */
2041 oldname = p;
2042 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2043 return FALSE;
b99bd4ef 2044
c19d1205
ZW
2045 oldname += 6;
2046 if (*oldname == '\0')
d929913e 2047 return FALSE;
b99bd4ef 2048
c19d1205
ZW
2049 old = hash_find (arm_reg_hsh, oldname);
2050 if (!old)
b99bd4ef 2051 {
c19d1205 2052 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2053 return TRUE;
b99bd4ef
NC
2054 }
2055
c19d1205
ZW
2056 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2057 the desired alias name, and p points to its end. If not, then
2058 the desired alias name is in the global original_case_string. */
2059#ifdef TC_CASE_SENSITIVE
2060 nlen = p - newname;
2061#else
2062 newname = original_case_string;
2063 nlen = strlen (newname);
2064#endif
b99bd4ef 2065
c19d1205
ZW
2066 nbuf = alloca (nlen + 1);
2067 memcpy (nbuf, newname, nlen);
2068 nbuf[nlen] = '\0';
b99bd4ef 2069
c19d1205
ZW
2070 /* Create aliases under the new name as stated; an all-lowercase
2071 version of the new name; and an all-uppercase version of the new
2072 name. */
d929913e
NC
2073 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2074 {
2075 for (p = nbuf; *p; p++)
2076 *p = TOUPPER (*p);
c19d1205 2077
d929913e
NC
2078 if (strncmp (nbuf, newname, nlen))
2079 {
2080 /* If this attempt to create an additional alias fails, do not bother
2081 trying to create the all-lower case alias. We will fail and issue
2082 a second, duplicate error message. This situation arises when the
2083 programmer does something like:
2084 foo .req r0
2085 Foo .req r1
2086 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2087 the artificial FOO alias because it has already been created by the
d929913e
NC
2088 first .req. */
2089 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2090 return TRUE;
2091 }
c19d1205 2092
d929913e
NC
2093 for (p = nbuf; *p; p++)
2094 *p = TOLOWER (*p);
c19d1205 2095
d929913e
NC
2096 if (strncmp (nbuf, newname, nlen))
2097 insert_reg_alias (nbuf, old->number, old->type);
2098 }
c19d1205 2099
d929913e 2100 return TRUE;
b99bd4ef
NC
2101}
2102
dcbf9037
JB
2103/* Create a Neon typed/indexed register alias using directives, e.g.:
2104 X .dn d5.s32[1]
2105 Y .qn 6.s16
2106 Z .dn d7
2107 T .dn Z[0]
2108 These typed registers can be used instead of the types specified after the
2109 Neon mnemonic, so long as all operands given have types. Types can also be
2110 specified directly, e.g.:
5f4273c7 2111 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2112
2113static int
2114create_neon_reg_alias (char *newname, char *p)
2115{
2116 enum arm_reg_type basetype;
2117 struct reg_entry *basereg;
2118 struct reg_entry mybasereg;
2119 struct neon_type ntype;
2120 struct neon_typed_alias typeinfo;
2121 char *namebuf, *nameend;
2122 int namelen;
5f4273c7 2123
dcbf9037
JB
2124 typeinfo.defined = 0;
2125 typeinfo.eltype.type = NT_invtype;
2126 typeinfo.eltype.size = -1;
2127 typeinfo.index = -1;
5f4273c7 2128
dcbf9037 2129 nameend = p;
5f4273c7 2130
dcbf9037
JB
2131 if (strncmp (p, " .dn ", 5) == 0)
2132 basetype = REG_TYPE_VFD;
2133 else if (strncmp (p, " .qn ", 5) == 0)
2134 basetype = REG_TYPE_NQ;
2135 else
2136 return 0;
5f4273c7 2137
dcbf9037 2138 p += 5;
5f4273c7 2139
dcbf9037
JB
2140 if (*p == '\0')
2141 return 0;
5f4273c7 2142
dcbf9037
JB
2143 basereg = arm_reg_parse_multi (&p);
2144
2145 if (basereg && basereg->type != basetype)
2146 {
2147 as_bad (_("bad type for register"));
2148 return 0;
2149 }
2150
2151 if (basereg == NULL)
2152 {
2153 expressionS exp;
2154 /* Try parsing as an integer. */
2155 my_get_expression (&exp, &p, GE_NO_PREFIX);
2156 if (exp.X_op != O_constant)
2157 {
2158 as_bad (_("expression must be constant"));
2159 return 0;
2160 }
2161 basereg = &mybasereg;
2162 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2163 : exp.X_add_number;
2164 basereg->neon = 0;
2165 }
2166
2167 if (basereg->neon)
2168 typeinfo = *basereg->neon;
2169
2170 if (parse_neon_type (&ntype, &p) == SUCCESS)
2171 {
2172 /* We got a type. */
2173 if (typeinfo.defined & NTA_HASTYPE)
2174 {
2175 as_bad (_("can't redefine the type of a register alias"));
2176 return 0;
2177 }
5f4273c7 2178
dcbf9037
JB
2179 typeinfo.defined |= NTA_HASTYPE;
2180 if (ntype.elems != 1)
2181 {
2182 as_bad (_("you must specify a single type only"));
2183 return 0;
2184 }
2185 typeinfo.eltype = ntype.el[0];
2186 }
5f4273c7 2187
dcbf9037
JB
2188 if (skip_past_char (&p, '[') == SUCCESS)
2189 {
2190 expressionS exp;
2191 /* We got a scalar index. */
5f4273c7 2192
dcbf9037
JB
2193 if (typeinfo.defined & NTA_HASINDEX)
2194 {
2195 as_bad (_("can't redefine the index of a scalar alias"));
2196 return 0;
2197 }
5f4273c7 2198
dcbf9037 2199 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2200
dcbf9037
JB
2201 if (exp.X_op != O_constant)
2202 {
2203 as_bad (_("scalar index must be constant"));
2204 return 0;
2205 }
5f4273c7 2206
dcbf9037
JB
2207 typeinfo.defined |= NTA_HASINDEX;
2208 typeinfo.index = exp.X_add_number;
5f4273c7 2209
dcbf9037
JB
2210 if (skip_past_char (&p, ']') == FAIL)
2211 {
2212 as_bad (_("expecting ]"));
2213 return 0;
2214 }
2215 }
2216
2217 namelen = nameend - newname;
2218 namebuf = alloca (namelen + 1);
2219 strncpy (namebuf, newname, namelen);
2220 namebuf[namelen] = '\0';
5f4273c7 2221
dcbf9037
JB
2222 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2223 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2224
dcbf9037
JB
2225 /* Insert name in all uppercase. */
2226 for (p = namebuf; *p; p++)
2227 *p = TOUPPER (*p);
5f4273c7 2228
dcbf9037
JB
2229 if (strncmp (namebuf, newname, namelen))
2230 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2231 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2232
dcbf9037
JB
2233 /* Insert name in all lowercase. */
2234 for (p = namebuf; *p; p++)
2235 *p = TOLOWER (*p);
5f4273c7 2236
dcbf9037
JB
2237 if (strncmp (namebuf, newname, namelen))
2238 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2239 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2240
dcbf9037
JB
2241 return 1;
2242}
2243
c19d1205
ZW
2244/* Should never be called, as .req goes between the alias and the
2245 register name, not at the beginning of the line. */
b99bd4ef 2246static void
c19d1205 2247s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2248{
c19d1205
ZW
2249 as_bad (_("invalid syntax for .req directive"));
2250}
b99bd4ef 2251
dcbf9037
JB
2252static void
2253s_dn (int a ATTRIBUTE_UNUSED)
2254{
2255 as_bad (_("invalid syntax for .dn directive"));
2256}
2257
2258static void
2259s_qn (int a ATTRIBUTE_UNUSED)
2260{
2261 as_bad (_("invalid syntax for .qn directive"));
2262}
2263
c19d1205
ZW
2264/* The .unreq directive deletes an alias which was previously defined
2265 by .req. For example:
b99bd4ef 2266
c19d1205
ZW
2267 my_alias .req r11
2268 .unreq my_alias */
b99bd4ef
NC
2269
2270static void
c19d1205 2271s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2272{
c19d1205
ZW
2273 char * name;
2274 char saved_char;
b99bd4ef 2275
c19d1205
ZW
2276 name = input_line_pointer;
2277
2278 while (*input_line_pointer != 0
2279 && *input_line_pointer != ' '
2280 && *input_line_pointer != '\n')
2281 ++input_line_pointer;
2282
2283 saved_char = *input_line_pointer;
2284 *input_line_pointer = 0;
2285
2286 if (!*name)
2287 as_bad (_("invalid syntax for .unreq directive"));
2288 else
2289 {
2290 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2291
2292 if (!reg)
2293 as_bad (_("unknown register alias '%s'"), name);
2294 else if (reg->builtin)
2295 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2296 name);
2297 else
2298 {
d929913e
NC
2299 char * p;
2300 char * nbuf;
2301
db0bc284 2302 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2303 free ((char *) reg->name);
dcbf9037
JB
2304 if (reg->neon)
2305 free (reg->neon);
c19d1205 2306 free (reg);
d929913e
NC
2307
2308 /* Also locate the all upper case and all lower case versions.
2309 Do not complain if we cannot find one or the other as it
2310 was probably deleted above. */
5f4273c7 2311
d929913e
NC
2312 nbuf = strdup (name);
2313 for (p = nbuf; *p; p++)
2314 *p = TOUPPER (*p);
2315 reg = hash_find (arm_reg_hsh, nbuf);
2316 if (reg)
2317 {
db0bc284 2318 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2319 free ((char *) reg->name);
2320 if (reg->neon)
2321 free (reg->neon);
2322 free (reg);
2323 }
2324
2325 for (p = nbuf; *p; p++)
2326 *p = TOLOWER (*p);
2327 reg = hash_find (arm_reg_hsh, nbuf);
2328 if (reg)
2329 {
db0bc284 2330 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2331 free ((char *) reg->name);
2332 if (reg->neon)
2333 free (reg->neon);
2334 free (reg);
2335 }
2336
2337 free (nbuf);
c19d1205
ZW
2338 }
2339 }
b99bd4ef 2340
c19d1205 2341 *input_line_pointer = saved_char;
b99bd4ef
NC
2342 demand_empty_rest_of_line ();
2343}
2344
c19d1205
ZW
2345/* Directives: Instruction set selection. */
2346
2347#ifdef OBJ_ELF
2348/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2349 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2350 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2351 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2352
2353static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2354
e821645d 2355void
c19d1205 2356mapping_state (enum mstate state)
b99bd4ef 2357{
a737bd4d 2358 symbolS * symbolP;
c19d1205
ZW
2359 const char * symname;
2360 int type;
b99bd4ef 2361
c19d1205
ZW
2362 if (mapstate == state)
2363 /* The mapping symbol has already been emitted.
2364 There is nothing else to do. */
2365 return;
b99bd4ef 2366
c19d1205 2367 mapstate = state;
b99bd4ef 2368
c19d1205 2369 switch (state)
b99bd4ef 2370 {
c19d1205
ZW
2371 case MAP_DATA:
2372 symname = "$d";
2373 type = BSF_NO_FLAGS;
2374 break;
2375 case MAP_ARM:
2376 symname = "$a";
2377 type = BSF_NO_FLAGS;
2378 break;
2379 case MAP_THUMB:
2380 symname = "$t";
2381 type = BSF_NO_FLAGS;
2382 break;
2383 case MAP_UNDEFINED:
2384 return;
2385 default:
2386 abort ();
2387 }
2388
2389 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2390
2391 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2392 symbol_table_insert (symbolP);
2393 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2394
2395 switch (state)
2396 {
2397 case MAP_ARM:
2398 THUMB_SET_FUNC (symbolP, 0);
2399 ARM_SET_THUMB (symbolP, 0);
2400 ARM_SET_INTERWORK (symbolP, support_interwork);
2401 break;
2402
2403 case MAP_THUMB:
2404 THUMB_SET_FUNC (symbolP, 1);
2405 ARM_SET_THUMB (symbolP, 1);
2406 ARM_SET_INTERWORK (symbolP, support_interwork);
2407 break;
2408
2409 case MAP_DATA:
2410 default:
2411 return;
2412 }
2413}
2414#else
2415#define mapping_state(x) /* nothing */
2416#endif
2417
2418/* Find the real, Thumb encoded start of a Thumb function. */
2419
4343666d 2420#ifdef OBJ_COFF
c19d1205
ZW
2421static symbolS *
2422find_real_start (symbolS * symbolP)
2423{
2424 char * real_start;
2425 const char * name = S_GET_NAME (symbolP);
2426 symbolS * new_target;
2427
2428 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2429#define STUB_NAME ".real_start_of"
2430
2431 if (name == NULL)
2432 abort ();
2433
37f6032b
ZW
2434 /* The compiler may generate BL instructions to local labels because
2435 it needs to perform a branch to a far away location. These labels
2436 do not have a corresponding ".real_start_of" label. We check
2437 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2438 the ".real_start_of" convention for nonlocal branches. */
2439 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2440 return symbolP;
2441
37f6032b 2442 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2443 new_target = symbol_find (real_start);
2444
2445 if (new_target == NULL)
2446 {
bd3ba5d1 2447 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2448 new_target = symbolP;
2449 }
2450
c19d1205
ZW
2451 return new_target;
2452}
4343666d 2453#endif
c19d1205
ZW
2454
2455static void
2456opcode_select (int width)
2457{
2458 switch (width)
2459 {
2460 case 16:
2461 if (! thumb_mode)
2462 {
e74cfd16 2463 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2464 as_bad (_("selected processor does not support THUMB opcodes"));
2465
2466 thumb_mode = 1;
2467 /* No need to force the alignment, since we will have been
2468 coming from ARM mode, which is word-aligned. */
2469 record_alignment (now_seg, 1);
2470 }
2471 mapping_state (MAP_THUMB);
2472 break;
2473
2474 case 32:
2475 if (thumb_mode)
2476 {
e74cfd16 2477 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2478 as_bad (_("selected processor does not support ARM opcodes"));
2479
2480 thumb_mode = 0;
2481
2482 if (!need_pass_2)
2483 frag_align (2, 0, 0);
2484
2485 record_alignment (now_seg, 1);
2486 }
2487 mapping_state (MAP_ARM);
2488 break;
2489
2490 default:
2491 as_bad (_("invalid instruction size selected (%d)"), width);
2492 }
2493}
2494
2495static void
2496s_arm (int ignore ATTRIBUTE_UNUSED)
2497{
2498 opcode_select (32);
2499 demand_empty_rest_of_line ();
2500}
2501
2502static void
2503s_thumb (int ignore ATTRIBUTE_UNUSED)
2504{
2505 opcode_select (16);
2506 demand_empty_rest_of_line ();
2507}
2508
2509static void
2510s_code (int unused ATTRIBUTE_UNUSED)
2511{
2512 int temp;
2513
2514 temp = get_absolute_expression ();
2515 switch (temp)
2516 {
2517 case 16:
2518 case 32:
2519 opcode_select (temp);
2520 break;
2521
2522 default:
2523 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2524 }
2525}
2526
2527static void
2528s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2529{
2530 /* If we are not already in thumb mode go into it, EVEN if
2531 the target processor does not support thumb instructions.
2532 This is used by gcc/config/arm/lib1funcs.asm for example
2533 to compile interworking support functions even if the
2534 target processor should not support interworking. */
2535 if (! thumb_mode)
2536 {
2537 thumb_mode = 2;
2538 record_alignment (now_seg, 1);
2539 }
2540
2541 demand_empty_rest_of_line ();
2542}
2543
2544static void
2545s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2546{
2547 s_thumb (0);
2548
2549 /* The following label is the name/address of the start of a Thumb function.
2550 We need to know this for the interworking support. */
2551 label_is_thumb_function_name = TRUE;
2552}
2553
2554/* Perform a .set directive, but also mark the alias as
2555 being a thumb function. */
2556
2557static void
2558s_thumb_set (int equiv)
2559{
2560 /* XXX the following is a duplicate of the code for s_set() in read.c
2561 We cannot just call that code as we need to get at the symbol that
2562 is created. */
2563 char * name;
2564 char delim;
2565 char * end_name;
2566 symbolS * symbolP;
2567
2568 /* Especial apologies for the random logic:
2569 This just grew, and could be parsed much more simply!
2570 Dean - in haste. */
2571 name = input_line_pointer;
2572 delim = get_symbol_end ();
2573 end_name = input_line_pointer;
2574 *end_name = delim;
2575
2576 if (*input_line_pointer != ',')
2577 {
2578 *end_name = 0;
2579 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2580 *end_name = delim;
2581 ignore_rest_of_line ();
2582 return;
2583 }
2584
2585 input_line_pointer++;
2586 *end_name = 0;
2587
2588 if (name[0] == '.' && name[1] == '\0')
2589 {
2590 /* XXX - this should not happen to .thumb_set. */
2591 abort ();
2592 }
2593
2594 if ((symbolP = symbol_find (name)) == NULL
2595 && (symbolP = md_undefined_symbol (name)) == NULL)
2596 {
2597#ifndef NO_LISTING
2598 /* When doing symbol listings, play games with dummy fragments living
2599 outside the normal fragment chain to record the file and line info
c19d1205 2600 for this symbol. */
b99bd4ef
NC
2601 if (listing & LISTING_SYMBOLS)
2602 {
2603 extern struct list_info_struct * listing_tail;
a737bd4d 2604 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2605
2606 memset (dummy_frag, 0, sizeof (fragS));
2607 dummy_frag->fr_type = rs_fill;
2608 dummy_frag->line = listing_tail;
2609 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2610 dummy_frag->fr_symbol = symbolP;
2611 }
2612 else
2613#endif
2614 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2615
2616#ifdef OBJ_COFF
2617 /* "set" symbols are local unless otherwise specified. */
2618 SF_SET_LOCAL (symbolP);
2619#endif /* OBJ_COFF */
2620 } /* Make a new symbol. */
2621
2622 symbol_table_insert (symbolP);
2623
2624 * end_name = delim;
2625
2626 if (equiv
2627 && S_IS_DEFINED (symbolP)
2628 && S_GET_SEGMENT (symbolP) != reg_section)
2629 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2630
2631 pseudo_set (symbolP);
2632
2633 demand_empty_rest_of_line ();
2634
c19d1205 2635 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2636
2637 THUMB_SET_FUNC (symbolP, 1);
2638 ARM_SET_THUMB (symbolP, 1);
2639#if defined OBJ_ELF || defined OBJ_COFF
2640 ARM_SET_INTERWORK (symbolP, support_interwork);
2641#endif
2642}
2643
c19d1205 2644/* Directives: Mode selection. */
b99bd4ef 2645
c19d1205
ZW
2646/* .syntax [unified|divided] - choose the new unified syntax
2647 (same for Arm and Thumb encoding, modulo slight differences in what
2648 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2649static void
c19d1205 2650s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2651{
c19d1205
ZW
2652 char *name, delim;
2653
2654 name = input_line_pointer;
2655 delim = get_symbol_end ();
2656
2657 if (!strcasecmp (name, "unified"))
2658 unified_syntax = TRUE;
2659 else if (!strcasecmp (name, "divided"))
2660 unified_syntax = FALSE;
2661 else
2662 {
2663 as_bad (_("unrecognized syntax mode \"%s\""), name);
2664 return;
2665 }
2666 *input_line_pointer = delim;
b99bd4ef
NC
2667 demand_empty_rest_of_line ();
2668}
2669
c19d1205
ZW
2670/* Directives: sectioning and alignment. */
2671
2672/* Same as s_align_ptwo but align 0 => align 2. */
2673
b99bd4ef 2674static void
c19d1205 2675s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2676{
a737bd4d 2677 int temp;
dce323d1 2678 bfd_boolean fill_p;
c19d1205
ZW
2679 long temp_fill;
2680 long max_alignment = 15;
b99bd4ef
NC
2681
2682 temp = get_absolute_expression ();
c19d1205
ZW
2683 if (temp > max_alignment)
2684 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2685 else if (temp < 0)
b99bd4ef 2686 {
c19d1205
ZW
2687 as_bad (_("alignment negative. 0 assumed."));
2688 temp = 0;
2689 }
b99bd4ef 2690
c19d1205
ZW
2691 if (*input_line_pointer == ',')
2692 {
2693 input_line_pointer++;
2694 temp_fill = get_absolute_expression ();
dce323d1 2695 fill_p = TRUE;
b99bd4ef 2696 }
c19d1205 2697 else
dce323d1
PB
2698 {
2699 fill_p = FALSE;
2700 temp_fill = 0;
2701 }
b99bd4ef 2702
c19d1205
ZW
2703 if (!temp)
2704 temp = 2;
b99bd4ef 2705
c19d1205
ZW
2706 /* Only make a frag if we HAVE to. */
2707 if (temp && !need_pass_2)
dce323d1
PB
2708 {
2709 if (!fill_p && subseg_text_p (now_seg))
2710 frag_align_code (temp, 0);
2711 else
2712 frag_align (temp, (int) temp_fill, 0);
2713 }
c19d1205
ZW
2714 demand_empty_rest_of_line ();
2715
2716 record_alignment (now_seg, temp);
b99bd4ef
NC
2717}
2718
c19d1205
ZW
2719static void
2720s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2721{
c19d1205
ZW
2722 /* We don't support putting frags in the BSS segment, we fake it by
2723 marking in_bss, then looking at s_skip for clues. */
2724 subseg_set (bss_section, 0);
2725 demand_empty_rest_of_line ();
2726 mapping_state (MAP_DATA);
2727}
b99bd4ef 2728
c19d1205
ZW
2729static void
2730s_even (int ignore ATTRIBUTE_UNUSED)
2731{
2732 /* Never make frag if expect extra pass. */
2733 if (!need_pass_2)
2734 frag_align (1, 0, 0);
b99bd4ef 2735
c19d1205 2736 record_alignment (now_seg, 1);
b99bd4ef 2737
c19d1205 2738 demand_empty_rest_of_line ();
b99bd4ef
NC
2739}
2740
c19d1205 2741/* Directives: Literal pools. */
a737bd4d 2742
c19d1205
ZW
2743static literal_pool *
2744find_literal_pool (void)
a737bd4d 2745{
c19d1205 2746 literal_pool * pool;
a737bd4d 2747
c19d1205 2748 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2749 {
c19d1205
ZW
2750 if (pool->section == now_seg
2751 && pool->sub_section == now_subseg)
2752 break;
a737bd4d
NC
2753 }
2754
c19d1205 2755 return pool;
a737bd4d
NC
2756}
2757
c19d1205
ZW
2758static literal_pool *
2759find_or_make_literal_pool (void)
a737bd4d 2760{
c19d1205
ZW
2761 /* Next literal pool ID number. */
2762 static unsigned int latest_pool_num = 1;
2763 literal_pool * pool;
a737bd4d 2764
c19d1205 2765 pool = find_literal_pool ();
a737bd4d 2766
c19d1205 2767 if (pool == NULL)
a737bd4d 2768 {
c19d1205
ZW
2769 /* Create a new pool. */
2770 pool = xmalloc (sizeof (* pool));
2771 if (! pool)
2772 return NULL;
a737bd4d 2773
c19d1205
ZW
2774 pool->next_free_entry = 0;
2775 pool->section = now_seg;
2776 pool->sub_section = now_subseg;
2777 pool->next = list_of_pools;
2778 pool->symbol = NULL;
2779
2780 /* Add it to the list. */
2781 list_of_pools = pool;
a737bd4d 2782 }
a737bd4d 2783
c19d1205
ZW
2784 /* New pools, and emptied pools, will have a NULL symbol. */
2785 if (pool->symbol == NULL)
a737bd4d 2786 {
c19d1205
ZW
2787 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2788 (valueT) 0, &zero_address_frag);
2789 pool->id = latest_pool_num ++;
a737bd4d
NC
2790 }
2791
c19d1205
ZW
2792 /* Done. */
2793 return pool;
a737bd4d
NC
2794}
2795
c19d1205 2796/* Add the literal in the global 'inst'
5f4273c7 2797 structure to the relevant literal pool. */
b99bd4ef
NC
2798
2799static int
c19d1205 2800add_to_lit_pool (void)
b99bd4ef 2801{
c19d1205
ZW
2802 literal_pool * pool;
2803 unsigned int entry;
b99bd4ef 2804
c19d1205
ZW
2805 pool = find_or_make_literal_pool ();
2806
2807 /* Check if this literal value is already in the pool. */
2808 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2809 {
c19d1205
ZW
2810 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2811 && (inst.reloc.exp.X_op == O_constant)
2812 && (pool->literals[entry].X_add_number
2813 == inst.reloc.exp.X_add_number)
2814 && (pool->literals[entry].X_unsigned
2815 == inst.reloc.exp.X_unsigned))
2816 break;
2817
2818 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2819 && (inst.reloc.exp.X_op == O_symbol)
2820 && (pool->literals[entry].X_add_number
2821 == inst.reloc.exp.X_add_number)
2822 && (pool->literals[entry].X_add_symbol
2823 == inst.reloc.exp.X_add_symbol)
2824 && (pool->literals[entry].X_op_symbol
2825 == inst.reloc.exp.X_op_symbol))
2826 break;
b99bd4ef
NC
2827 }
2828
c19d1205
ZW
2829 /* Do we need to create a new entry? */
2830 if (entry == pool->next_free_entry)
2831 {
2832 if (entry >= MAX_LITERAL_POOL_SIZE)
2833 {
2834 inst.error = _("literal pool overflow");
2835 return FAIL;
2836 }
2837
2838 pool->literals[entry] = inst.reloc.exp;
2839 pool->next_free_entry += 1;
2840 }
b99bd4ef 2841
c19d1205
ZW
2842 inst.reloc.exp.X_op = O_symbol;
2843 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2844 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2845
c19d1205 2846 return SUCCESS;
b99bd4ef
NC
2847}
2848
c19d1205
ZW
2849/* Can't use symbol_new here, so have to create a symbol and then at
2850 a later date assign it a value. Thats what these functions do. */
e16bb312 2851
c19d1205
ZW
2852static void
2853symbol_locate (symbolS * symbolP,
2854 const char * name, /* It is copied, the caller can modify. */
2855 segT segment, /* Segment identifier (SEG_<something>). */
2856 valueT valu, /* Symbol value. */
2857 fragS * frag) /* Associated fragment. */
2858{
2859 unsigned int name_length;
2860 char * preserved_copy_of_name;
e16bb312 2861
c19d1205
ZW
2862 name_length = strlen (name) + 1; /* +1 for \0. */
2863 obstack_grow (&notes, name, name_length);
2864 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2865
c19d1205
ZW
2866#ifdef tc_canonicalize_symbol_name
2867 preserved_copy_of_name =
2868 tc_canonicalize_symbol_name (preserved_copy_of_name);
2869#endif
b99bd4ef 2870
c19d1205 2871 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2872
c19d1205
ZW
2873 S_SET_SEGMENT (symbolP, segment);
2874 S_SET_VALUE (symbolP, valu);
2875 symbol_clear_list_pointers (symbolP);
b99bd4ef 2876
c19d1205 2877 symbol_set_frag (symbolP, frag);
b99bd4ef 2878
c19d1205
ZW
2879 /* Link to end of symbol chain. */
2880 {
2881 extern int symbol_table_frozen;
b99bd4ef 2882
c19d1205
ZW
2883 if (symbol_table_frozen)
2884 abort ();
2885 }
b99bd4ef 2886
c19d1205 2887 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2888
c19d1205 2889 obj_symbol_new_hook (symbolP);
b99bd4ef 2890
c19d1205
ZW
2891#ifdef tc_symbol_new_hook
2892 tc_symbol_new_hook (symbolP);
2893#endif
2894
2895#ifdef DEBUG_SYMS
2896 verify_symbol_chain (symbol_rootP, symbol_lastP);
2897#endif /* DEBUG_SYMS */
b99bd4ef
NC
2898}
2899
b99bd4ef 2900
c19d1205
ZW
2901static void
2902s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2903{
c19d1205
ZW
2904 unsigned int entry;
2905 literal_pool * pool;
2906 char sym_name[20];
b99bd4ef 2907
c19d1205
ZW
2908 pool = find_literal_pool ();
2909 if (pool == NULL
2910 || pool->symbol == NULL
2911 || pool->next_free_entry == 0)
2912 return;
b99bd4ef 2913
c19d1205 2914 mapping_state (MAP_DATA);
b99bd4ef 2915
c19d1205
ZW
2916 /* Align pool as you have word accesses.
2917 Only make a frag if we have to. */
2918 if (!need_pass_2)
2919 frag_align (2, 0, 0);
b99bd4ef 2920
c19d1205 2921 record_alignment (now_seg, 2);
b99bd4ef 2922
c19d1205 2923 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2924
c19d1205
ZW
2925 symbol_locate (pool->symbol, sym_name, now_seg,
2926 (valueT) frag_now_fix (), frag_now);
2927 symbol_table_insert (pool->symbol);
b99bd4ef 2928
c19d1205 2929 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2930
c19d1205
ZW
2931#if defined OBJ_COFF || defined OBJ_ELF
2932 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2933#endif
6c43fab6 2934
c19d1205
ZW
2935 for (entry = 0; entry < pool->next_free_entry; entry ++)
2936 /* First output the expression in the instruction to the pool. */
2937 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2938
c19d1205
ZW
2939 /* Mark the pool as empty. */
2940 pool->next_free_entry = 0;
2941 pool->symbol = NULL;
b99bd4ef
NC
2942}
2943
c19d1205
ZW
2944#ifdef OBJ_ELF
2945/* Forward declarations for functions below, in the MD interface
2946 section. */
2947static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2948static valueT create_unwind_entry (int);
2949static void start_unwind_section (const segT, int);
2950static void add_unwind_opcode (valueT, int);
2951static void flush_pending_unwind (void);
b99bd4ef 2952
c19d1205 2953/* Directives: Data. */
b99bd4ef 2954
c19d1205
ZW
2955static void
2956s_arm_elf_cons (int nbytes)
2957{
2958 expressionS exp;
b99bd4ef 2959
c19d1205
ZW
2960#ifdef md_flush_pending_output
2961 md_flush_pending_output ();
2962#endif
b99bd4ef 2963
c19d1205 2964 if (is_it_end_of_statement ())
b99bd4ef 2965 {
c19d1205
ZW
2966 demand_empty_rest_of_line ();
2967 return;
b99bd4ef
NC
2968 }
2969
c19d1205
ZW
2970#ifdef md_cons_align
2971 md_cons_align (nbytes);
2972#endif
b99bd4ef 2973
c19d1205
ZW
2974 mapping_state (MAP_DATA);
2975 do
b99bd4ef 2976 {
c19d1205
ZW
2977 int reloc;
2978 char *base = input_line_pointer;
b99bd4ef 2979
c19d1205 2980 expression (& exp);
b99bd4ef 2981
c19d1205
ZW
2982 if (exp.X_op != O_symbol)
2983 emit_expr (&exp, (unsigned int) nbytes);
2984 else
2985 {
2986 char *before_reloc = input_line_pointer;
2987 reloc = parse_reloc (&input_line_pointer);
2988 if (reloc == -1)
2989 {
2990 as_bad (_("unrecognized relocation suffix"));
2991 ignore_rest_of_line ();
2992 return;
2993 }
2994 else if (reloc == BFD_RELOC_UNUSED)
2995 emit_expr (&exp, (unsigned int) nbytes);
2996 else
2997 {
2998 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2999 int size = bfd_get_reloc_size (howto);
b99bd4ef 3000
2fc8bdac
ZW
3001 if (reloc == BFD_RELOC_ARM_PLT32)
3002 {
3003 as_bad (_("(plt) is only valid on branch targets"));
3004 reloc = BFD_RELOC_UNUSED;
3005 size = 0;
3006 }
3007
c19d1205 3008 if (size > nbytes)
2fc8bdac 3009 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3010 howto->name, nbytes);
3011 else
3012 {
3013 /* We've parsed an expression stopping at O_symbol.
3014 But there may be more expression left now that we
3015 have parsed the relocation marker. Parse it again.
3016 XXX Surely there is a cleaner way to do this. */
3017 char *p = input_line_pointer;
3018 int offset;
3019 char *save_buf = alloca (input_line_pointer - base);
3020 memcpy (save_buf, base, input_line_pointer - base);
3021 memmove (base + (input_line_pointer - before_reloc),
3022 base, before_reloc - base);
3023
3024 input_line_pointer = base + (input_line_pointer-before_reloc);
3025 expression (&exp);
3026 memcpy (base, save_buf, p - base);
3027
3028 offset = nbytes - size;
3029 p = frag_more ((int) nbytes);
3030 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3031 size, &exp, 0, reloc);
3032 }
3033 }
3034 }
b99bd4ef 3035 }
c19d1205 3036 while (*input_line_pointer++ == ',');
b99bd4ef 3037
c19d1205
ZW
3038 /* Put terminator back into stream. */
3039 input_line_pointer --;
3040 demand_empty_rest_of_line ();
b99bd4ef
NC
3041}
3042
b99bd4ef 3043
c19d1205 3044/* Parse a .rel31 directive. */
b99bd4ef 3045
c19d1205
ZW
3046static void
3047s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3048{
3049 expressionS exp;
3050 char *p;
3051 valueT highbit;
b99bd4ef 3052
c19d1205
ZW
3053 highbit = 0;
3054 if (*input_line_pointer == '1')
3055 highbit = 0x80000000;
3056 else if (*input_line_pointer != '0')
3057 as_bad (_("expected 0 or 1"));
b99bd4ef 3058
c19d1205
ZW
3059 input_line_pointer++;
3060 if (*input_line_pointer != ',')
3061 as_bad (_("missing comma"));
3062 input_line_pointer++;
b99bd4ef 3063
c19d1205
ZW
3064#ifdef md_flush_pending_output
3065 md_flush_pending_output ();
3066#endif
b99bd4ef 3067
c19d1205
ZW
3068#ifdef md_cons_align
3069 md_cons_align (4);
3070#endif
b99bd4ef 3071
c19d1205 3072 mapping_state (MAP_DATA);
b99bd4ef 3073
c19d1205 3074 expression (&exp);
b99bd4ef 3075
c19d1205
ZW
3076 p = frag_more (4);
3077 md_number_to_chars (p, highbit, 4);
3078 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3079 BFD_RELOC_ARM_PREL31);
b99bd4ef 3080
c19d1205 3081 demand_empty_rest_of_line ();
b99bd4ef
NC
3082}
3083
c19d1205 3084/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3085
c19d1205 3086/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3087
c19d1205
ZW
3088static void
3089s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3090{
3091 demand_empty_rest_of_line ();
3092 /* Mark the start of the function. */
3093 unwind.proc_start = expr_build_dot ();
b99bd4ef 3094
c19d1205
ZW
3095 /* Reset the rest of the unwind info. */
3096 unwind.opcode_count = 0;
3097 unwind.table_entry = NULL;
3098 unwind.personality_routine = NULL;
3099 unwind.personality_index = -1;
3100 unwind.frame_size = 0;
3101 unwind.fp_offset = 0;
fdfde340 3102 unwind.fp_reg = REG_SP;
c19d1205
ZW
3103 unwind.fp_used = 0;
3104 unwind.sp_restored = 0;
3105}
b99bd4ef 3106
b99bd4ef 3107
c19d1205
ZW
3108/* Parse a handlerdata directive. Creates the exception handling table entry
3109 for the function. */
b99bd4ef 3110
c19d1205
ZW
3111static void
3112s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3113{
3114 demand_empty_rest_of_line ();
3115 if (unwind.table_entry)
6decc662 3116 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3117
c19d1205
ZW
3118 create_unwind_entry (1);
3119}
a737bd4d 3120
c19d1205 3121/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3122
c19d1205
ZW
3123static void
3124s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3125{
3126 long where;
3127 char *ptr;
3128 valueT val;
f02232aa 3129
c19d1205 3130 demand_empty_rest_of_line ();
f02232aa 3131
c19d1205
ZW
3132 /* Add eh table entry. */
3133 if (unwind.table_entry == NULL)
3134 val = create_unwind_entry (0);
3135 else
3136 val = 0;
f02232aa 3137
c19d1205
ZW
3138 /* Add index table entry. This is two words. */
3139 start_unwind_section (unwind.saved_seg, 1);
3140 frag_align (2, 0, 0);
3141 record_alignment (now_seg, 2);
b99bd4ef 3142
c19d1205
ZW
3143 ptr = frag_more (8);
3144 where = frag_now_fix () - 8;
f02232aa 3145
c19d1205
ZW
3146 /* Self relative offset of the function start. */
3147 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3148 BFD_RELOC_ARM_PREL31);
f02232aa 3149
c19d1205
ZW
3150 /* Indicate dependency on EHABI-defined personality routines to the
3151 linker, if it hasn't been done already. */
3152 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3153 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3154 {
5f4273c7
NC
3155 static const char *const name[] =
3156 {
3157 "__aeabi_unwind_cpp_pr0",
3158 "__aeabi_unwind_cpp_pr1",
3159 "__aeabi_unwind_cpp_pr2"
3160 };
c19d1205
ZW
3161 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3162 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3163 marked_pr_dependency |= 1 << unwind.personality_index;
3164 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3165 = marked_pr_dependency;
3166 }
f02232aa 3167
c19d1205
ZW
3168 if (val)
3169 /* Inline exception table entry. */
3170 md_number_to_chars (ptr + 4, val, 4);
3171 else
3172 /* Self relative offset of the table entry. */
3173 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3174 BFD_RELOC_ARM_PREL31);
f02232aa 3175
c19d1205
ZW
3176 /* Restore the original section. */
3177 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3178}
f02232aa 3179
f02232aa 3180
c19d1205 3181/* Parse an unwind_cantunwind directive. */
b99bd4ef 3182
c19d1205
ZW
3183static void
3184s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3185{
3186 demand_empty_rest_of_line ();
3187 if (unwind.personality_routine || unwind.personality_index != -1)
3188 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3189
c19d1205
ZW
3190 unwind.personality_index = -2;
3191}
b99bd4ef 3192
b99bd4ef 3193
c19d1205 3194/* Parse a personalityindex directive. */
b99bd4ef 3195
c19d1205
ZW
3196static void
3197s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3198{
3199 expressionS exp;
b99bd4ef 3200
c19d1205
ZW
3201 if (unwind.personality_routine || unwind.personality_index != -1)
3202 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3203
c19d1205 3204 expression (&exp);
b99bd4ef 3205
c19d1205
ZW
3206 if (exp.X_op != O_constant
3207 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3208 {
c19d1205
ZW
3209 as_bad (_("bad personality routine number"));
3210 ignore_rest_of_line ();
3211 return;
b99bd4ef
NC
3212 }
3213
c19d1205 3214 unwind.personality_index = exp.X_add_number;
b99bd4ef 3215
c19d1205
ZW
3216 demand_empty_rest_of_line ();
3217}
e16bb312 3218
e16bb312 3219
c19d1205 3220/* Parse a personality directive. */
e16bb312 3221
c19d1205
ZW
3222static void
3223s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3224{
3225 char *name, *p, c;
a737bd4d 3226
c19d1205
ZW
3227 if (unwind.personality_routine || unwind.personality_index != -1)
3228 as_bad (_("duplicate .personality directive"));
a737bd4d 3229
c19d1205
ZW
3230 name = input_line_pointer;
3231 c = get_symbol_end ();
3232 p = input_line_pointer;
3233 unwind.personality_routine = symbol_find_or_make (name);
3234 *p = c;
3235 demand_empty_rest_of_line ();
3236}
e16bb312 3237
e16bb312 3238
c19d1205 3239/* Parse a directive saving core registers. */
e16bb312 3240
c19d1205
ZW
3241static void
3242s_arm_unwind_save_core (void)
e16bb312 3243{
c19d1205
ZW
3244 valueT op;
3245 long range;
3246 int n;
e16bb312 3247
c19d1205
ZW
3248 range = parse_reg_list (&input_line_pointer);
3249 if (range == FAIL)
e16bb312 3250 {
c19d1205
ZW
3251 as_bad (_("expected register list"));
3252 ignore_rest_of_line ();
3253 return;
3254 }
e16bb312 3255
c19d1205 3256 demand_empty_rest_of_line ();
e16bb312 3257
c19d1205
ZW
3258 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3259 into .unwind_save {..., sp...}. We aren't bothered about the value of
3260 ip because it is clobbered by calls. */
3261 if (unwind.sp_restored && unwind.fp_reg == 12
3262 && (range & 0x3000) == 0x1000)
3263 {
3264 unwind.opcode_count--;
3265 unwind.sp_restored = 0;
3266 range = (range | 0x2000) & ~0x1000;
3267 unwind.pending_offset = 0;
3268 }
e16bb312 3269
01ae4198
DJ
3270 /* Pop r4-r15. */
3271 if (range & 0xfff0)
c19d1205 3272 {
01ae4198
DJ
3273 /* See if we can use the short opcodes. These pop a block of up to 8
3274 registers starting with r4, plus maybe r14. */
3275 for (n = 0; n < 8; n++)
3276 {
3277 /* Break at the first non-saved register. */
3278 if ((range & (1 << (n + 4))) == 0)
3279 break;
3280 }
3281 /* See if there are any other bits set. */
3282 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3283 {
3284 /* Use the long form. */
3285 op = 0x8000 | ((range >> 4) & 0xfff);
3286 add_unwind_opcode (op, 2);
3287 }
0dd132b6 3288 else
01ae4198
DJ
3289 {
3290 /* Use the short form. */
3291 if (range & 0x4000)
3292 op = 0xa8; /* Pop r14. */
3293 else
3294 op = 0xa0; /* Do not pop r14. */
3295 op |= (n - 1);
3296 add_unwind_opcode (op, 1);
3297 }
c19d1205 3298 }
0dd132b6 3299
c19d1205
ZW
3300 /* Pop r0-r3. */
3301 if (range & 0xf)
3302 {
3303 op = 0xb100 | (range & 0xf);
3304 add_unwind_opcode (op, 2);
0dd132b6
NC
3305 }
3306
c19d1205
ZW
3307 /* Record the number of bytes pushed. */
3308 for (n = 0; n < 16; n++)
3309 {
3310 if (range & (1 << n))
3311 unwind.frame_size += 4;
3312 }
0dd132b6
NC
3313}
3314
c19d1205
ZW
3315
3316/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3317
3318static void
c19d1205 3319s_arm_unwind_save_fpa (int reg)
b99bd4ef 3320{
c19d1205
ZW
3321 expressionS exp;
3322 int num_regs;
3323 valueT op;
b99bd4ef 3324
c19d1205
ZW
3325 /* Get Number of registers to transfer. */
3326 if (skip_past_comma (&input_line_pointer) != FAIL)
3327 expression (&exp);
3328 else
3329 exp.X_op = O_illegal;
b99bd4ef 3330
c19d1205 3331 if (exp.X_op != O_constant)
b99bd4ef 3332 {
c19d1205
ZW
3333 as_bad (_("expected , <constant>"));
3334 ignore_rest_of_line ();
b99bd4ef
NC
3335 return;
3336 }
3337
c19d1205
ZW
3338 num_regs = exp.X_add_number;
3339
3340 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3341 {
c19d1205
ZW
3342 as_bad (_("number of registers must be in the range [1:4]"));
3343 ignore_rest_of_line ();
b99bd4ef
NC
3344 return;
3345 }
3346
c19d1205 3347 demand_empty_rest_of_line ();
b99bd4ef 3348
c19d1205
ZW
3349 if (reg == 4)
3350 {
3351 /* Short form. */
3352 op = 0xb4 | (num_regs - 1);
3353 add_unwind_opcode (op, 1);
3354 }
b99bd4ef
NC
3355 else
3356 {
c19d1205
ZW
3357 /* Long form. */
3358 op = 0xc800 | (reg << 4) | (num_regs - 1);
3359 add_unwind_opcode (op, 2);
b99bd4ef 3360 }
c19d1205 3361 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3362}
3363
c19d1205 3364
fa073d69
MS
3365/* Parse a directive saving VFP registers for ARMv6 and above. */
3366
3367static void
3368s_arm_unwind_save_vfp_armv6 (void)
3369{
3370 int count;
3371 unsigned int start;
3372 valueT op;
3373 int num_vfpv3_regs = 0;
3374 int num_regs_below_16;
3375
3376 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3377 if (count == FAIL)
3378 {
3379 as_bad (_("expected register list"));
3380 ignore_rest_of_line ();
3381 return;
3382 }
3383
3384 demand_empty_rest_of_line ();
3385
3386 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3387 than FSTMX/FLDMX-style ones). */
3388
3389 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3390 if (start >= 16)
3391 num_vfpv3_regs = count;
3392 else if (start + count > 16)
3393 num_vfpv3_regs = start + count - 16;
3394
3395 if (num_vfpv3_regs > 0)
3396 {
3397 int start_offset = start > 16 ? start - 16 : 0;
3398 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3399 add_unwind_opcode (op, 2);
3400 }
3401
3402 /* Generate opcode for registers numbered in the range 0 .. 15. */
3403 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3404 assert (num_regs_below_16 + num_vfpv3_regs == count);
3405 if (num_regs_below_16 > 0)
3406 {
3407 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3408 add_unwind_opcode (op, 2);
3409 }
3410
3411 unwind.frame_size += count * 8;
3412}
3413
3414
3415/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3416
3417static void
c19d1205 3418s_arm_unwind_save_vfp (void)
b99bd4ef 3419{
c19d1205 3420 int count;
ca3f61f7 3421 unsigned int reg;
c19d1205 3422 valueT op;
b99bd4ef 3423
5287ad62 3424 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3425 if (count == FAIL)
b99bd4ef 3426 {
c19d1205
ZW
3427 as_bad (_("expected register list"));
3428 ignore_rest_of_line ();
b99bd4ef
NC
3429 return;
3430 }
3431
c19d1205 3432 demand_empty_rest_of_line ();
b99bd4ef 3433
c19d1205 3434 if (reg == 8)
b99bd4ef 3435 {
c19d1205
ZW
3436 /* Short form. */
3437 op = 0xb8 | (count - 1);
3438 add_unwind_opcode (op, 1);
b99bd4ef 3439 }
c19d1205 3440 else
b99bd4ef 3441 {
c19d1205
ZW
3442 /* Long form. */
3443 op = 0xb300 | (reg << 4) | (count - 1);
3444 add_unwind_opcode (op, 2);
b99bd4ef 3445 }
c19d1205
ZW
3446 unwind.frame_size += count * 8 + 4;
3447}
b99bd4ef 3448
b99bd4ef 3449
c19d1205
ZW
3450/* Parse a directive saving iWMMXt data registers. */
3451
3452static void
3453s_arm_unwind_save_mmxwr (void)
3454{
3455 int reg;
3456 int hi_reg;
3457 int i;
3458 unsigned mask = 0;
3459 valueT op;
b99bd4ef 3460
c19d1205
ZW
3461 if (*input_line_pointer == '{')
3462 input_line_pointer++;
b99bd4ef 3463
c19d1205 3464 do
b99bd4ef 3465 {
dcbf9037 3466 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3467
c19d1205 3468 if (reg == FAIL)
b99bd4ef 3469 {
9b7132d3 3470 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3471 goto error;
b99bd4ef
NC
3472 }
3473
c19d1205
ZW
3474 if (mask >> reg)
3475 as_tsktsk (_("register list not in ascending order"));
3476 mask |= 1 << reg;
b99bd4ef 3477
c19d1205
ZW
3478 if (*input_line_pointer == '-')
3479 {
3480 input_line_pointer++;
dcbf9037 3481 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3482 if (hi_reg == FAIL)
3483 {
9b7132d3 3484 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3485 goto error;
3486 }
3487 else if (reg >= hi_reg)
3488 {
3489 as_bad (_("bad register range"));
3490 goto error;
3491 }
3492 for (; reg < hi_reg; reg++)
3493 mask |= 1 << reg;
3494 }
3495 }
3496 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3497
c19d1205
ZW
3498 if (*input_line_pointer == '}')
3499 input_line_pointer++;
b99bd4ef 3500
c19d1205 3501 demand_empty_rest_of_line ();
b99bd4ef 3502
708587a4 3503 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3504 the list. */
3505 flush_pending_unwind ();
b99bd4ef 3506
c19d1205 3507 for (i = 0; i < 16; i++)
b99bd4ef 3508 {
c19d1205
ZW
3509 if (mask & (1 << i))
3510 unwind.frame_size += 8;
b99bd4ef
NC
3511 }
3512
c19d1205
ZW
3513 /* Attempt to combine with a previous opcode. We do this because gcc
3514 likes to output separate unwind directives for a single block of
3515 registers. */
3516 if (unwind.opcode_count > 0)
b99bd4ef 3517 {
c19d1205
ZW
3518 i = unwind.opcodes[unwind.opcode_count - 1];
3519 if ((i & 0xf8) == 0xc0)
3520 {
3521 i &= 7;
3522 /* Only merge if the blocks are contiguous. */
3523 if (i < 6)
3524 {
3525 if ((mask & 0xfe00) == (1 << 9))
3526 {
3527 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3528 unwind.opcode_count--;
3529 }
3530 }
3531 else if (i == 6 && unwind.opcode_count >= 2)
3532 {
3533 i = unwind.opcodes[unwind.opcode_count - 2];
3534 reg = i >> 4;
3535 i &= 0xf;
b99bd4ef 3536
c19d1205
ZW
3537 op = 0xffff << (reg - 1);
3538 if (reg > 0
87a1fd79 3539 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3540 {
3541 op = (1 << (reg + i + 1)) - 1;
3542 op &= ~((1 << reg) - 1);
3543 mask |= op;
3544 unwind.opcode_count -= 2;
3545 }
3546 }
3547 }
b99bd4ef
NC
3548 }
3549
c19d1205
ZW
3550 hi_reg = 15;
3551 /* We want to generate opcodes in the order the registers have been
3552 saved, ie. descending order. */
3553 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3554 {
c19d1205
ZW
3555 /* Save registers in blocks. */
3556 if (reg < 0
3557 || !(mask & (1 << reg)))
3558 {
3559 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3560 preceding block. */
c19d1205
ZW
3561 if (reg != hi_reg)
3562 {
3563 if (reg == 9)
3564 {
3565 /* Short form. */
3566 op = 0xc0 | (hi_reg - 10);
3567 add_unwind_opcode (op, 1);
3568 }
3569 else
3570 {
3571 /* Long form. */
3572 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3573 add_unwind_opcode (op, 2);
3574 }
3575 }
3576 hi_reg = reg - 1;
3577 }
b99bd4ef
NC
3578 }
3579
c19d1205
ZW
3580 return;
3581error:
3582 ignore_rest_of_line ();
b99bd4ef
NC
3583}
3584
3585static void
c19d1205 3586s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3587{
c19d1205
ZW
3588 int reg;
3589 int hi_reg;
3590 unsigned mask = 0;
3591 valueT op;
b99bd4ef 3592
c19d1205
ZW
3593 if (*input_line_pointer == '{')
3594 input_line_pointer++;
b99bd4ef 3595
c19d1205 3596 do
b99bd4ef 3597 {
dcbf9037 3598 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3599
c19d1205
ZW
3600 if (reg == FAIL)
3601 {
9b7132d3 3602 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3603 goto error;
3604 }
b99bd4ef 3605
c19d1205
ZW
3606 reg -= 8;
3607 if (mask >> reg)
3608 as_tsktsk (_("register list not in ascending order"));
3609 mask |= 1 << reg;
b99bd4ef 3610
c19d1205
ZW
3611 if (*input_line_pointer == '-')
3612 {
3613 input_line_pointer++;
dcbf9037 3614 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3615 if (hi_reg == FAIL)
3616 {
9b7132d3 3617 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3618 goto error;
3619 }
3620 else if (reg >= hi_reg)
3621 {
3622 as_bad (_("bad register range"));
3623 goto error;
3624 }
3625 for (; reg < hi_reg; reg++)
3626 mask |= 1 << reg;
3627 }
b99bd4ef 3628 }
c19d1205 3629 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3630
c19d1205
ZW
3631 if (*input_line_pointer == '}')
3632 input_line_pointer++;
b99bd4ef 3633
c19d1205
ZW
3634 demand_empty_rest_of_line ();
3635
708587a4 3636 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3637 the list. */
3638 flush_pending_unwind ();
b99bd4ef 3639
c19d1205 3640 for (reg = 0; reg < 16; reg++)
b99bd4ef 3641 {
c19d1205
ZW
3642 if (mask & (1 << reg))
3643 unwind.frame_size += 4;
b99bd4ef 3644 }
c19d1205
ZW
3645 op = 0xc700 | mask;
3646 add_unwind_opcode (op, 2);
3647 return;
3648error:
3649 ignore_rest_of_line ();
b99bd4ef
NC
3650}
3651
c19d1205 3652
fa073d69
MS
3653/* Parse an unwind_save directive.
3654 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3655
b99bd4ef 3656static void
fa073d69 3657s_arm_unwind_save (int arch_v6)
b99bd4ef 3658{
c19d1205
ZW
3659 char *peek;
3660 struct reg_entry *reg;
3661 bfd_boolean had_brace = FALSE;
b99bd4ef 3662
c19d1205
ZW
3663 /* Figure out what sort of save we have. */
3664 peek = input_line_pointer;
b99bd4ef 3665
c19d1205 3666 if (*peek == '{')
b99bd4ef 3667 {
c19d1205
ZW
3668 had_brace = TRUE;
3669 peek++;
b99bd4ef
NC
3670 }
3671
c19d1205 3672 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3673
c19d1205 3674 if (!reg)
b99bd4ef 3675 {
c19d1205
ZW
3676 as_bad (_("register expected"));
3677 ignore_rest_of_line ();
b99bd4ef
NC
3678 return;
3679 }
3680
c19d1205 3681 switch (reg->type)
b99bd4ef 3682 {
c19d1205
ZW
3683 case REG_TYPE_FN:
3684 if (had_brace)
3685 {
3686 as_bad (_("FPA .unwind_save does not take a register list"));
3687 ignore_rest_of_line ();
3688 return;
3689 }
93ac2687 3690 input_line_pointer = peek;
c19d1205 3691 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3692 return;
c19d1205
ZW
3693
3694 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3695 case REG_TYPE_VFD:
3696 if (arch_v6)
3697 s_arm_unwind_save_vfp_armv6 ();
3698 else
3699 s_arm_unwind_save_vfp ();
3700 return;
c19d1205
ZW
3701 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3702 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3703
3704 default:
3705 as_bad (_(".unwind_save does not support this kind of register"));
3706 ignore_rest_of_line ();
b99bd4ef 3707 }
c19d1205 3708}
b99bd4ef 3709
b99bd4ef 3710
c19d1205
ZW
3711/* Parse an unwind_movsp directive. */
3712
3713static void
3714s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3715{
3716 int reg;
3717 valueT op;
4fa3602b 3718 int offset;
c19d1205 3719
dcbf9037 3720 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3721 if (reg == FAIL)
b99bd4ef 3722 {
9b7132d3 3723 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 3724 ignore_rest_of_line ();
b99bd4ef
NC
3725 return;
3726 }
4fa3602b
PB
3727
3728 /* Optional constant. */
3729 if (skip_past_comma (&input_line_pointer) != FAIL)
3730 {
3731 if (immediate_for_directive (&offset) == FAIL)
3732 return;
3733 }
3734 else
3735 offset = 0;
3736
c19d1205 3737 demand_empty_rest_of_line ();
b99bd4ef 3738
c19d1205 3739 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3740 {
c19d1205 3741 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3742 return;
3743 }
3744
c19d1205
ZW
3745 if (unwind.fp_reg != REG_SP)
3746 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3747
c19d1205
ZW
3748 /* Generate opcode to restore the value. */
3749 op = 0x90 | reg;
3750 add_unwind_opcode (op, 1);
3751
3752 /* Record the information for later. */
3753 unwind.fp_reg = reg;
4fa3602b 3754 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3755 unwind.sp_restored = 1;
b05fe5cf
ZW
3756}
3757
c19d1205
ZW
3758/* Parse an unwind_pad directive. */
3759
b05fe5cf 3760static void
c19d1205 3761s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3762{
c19d1205 3763 int offset;
b05fe5cf 3764
c19d1205
ZW
3765 if (immediate_for_directive (&offset) == FAIL)
3766 return;
b99bd4ef 3767
c19d1205
ZW
3768 if (offset & 3)
3769 {
3770 as_bad (_("stack increment must be multiple of 4"));
3771 ignore_rest_of_line ();
3772 return;
3773 }
b99bd4ef 3774
c19d1205
ZW
3775 /* Don't generate any opcodes, just record the details for later. */
3776 unwind.frame_size += offset;
3777 unwind.pending_offset += offset;
3778
3779 demand_empty_rest_of_line ();
3780}
3781
3782/* Parse an unwind_setfp directive. */
3783
3784static void
3785s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3786{
c19d1205
ZW
3787 int sp_reg;
3788 int fp_reg;
3789 int offset;
3790
dcbf9037 3791 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3792 if (skip_past_comma (&input_line_pointer) == FAIL)
3793 sp_reg = FAIL;
3794 else
dcbf9037 3795 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3796
c19d1205
ZW
3797 if (fp_reg == FAIL || sp_reg == FAIL)
3798 {
3799 as_bad (_("expected <reg>, <reg>"));
3800 ignore_rest_of_line ();
3801 return;
3802 }
b99bd4ef 3803
c19d1205
ZW
3804 /* Optional constant. */
3805 if (skip_past_comma (&input_line_pointer) != FAIL)
3806 {
3807 if (immediate_for_directive (&offset) == FAIL)
3808 return;
3809 }
3810 else
3811 offset = 0;
a737bd4d 3812
c19d1205 3813 demand_empty_rest_of_line ();
a737bd4d 3814
fdfde340 3815 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 3816 {
c19d1205
ZW
3817 as_bad (_("register must be either sp or set by a previous"
3818 "unwind_movsp directive"));
3819 return;
a737bd4d
NC
3820 }
3821
c19d1205
ZW
3822 /* Don't generate any opcodes, just record the information for later. */
3823 unwind.fp_reg = fp_reg;
3824 unwind.fp_used = 1;
fdfde340 3825 if (sp_reg == REG_SP)
c19d1205
ZW
3826 unwind.fp_offset = unwind.frame_size - offset;
3827 else
3828 unwind.fp_offset -= offset;
a737bd4d
NC
3829}
3830
c19d1205
ZW
3831/* Parse an unwind_raw directive. */
3832
3833static void
3834s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3835{
c19d1205 3836 expressionS exp;
708587a4 3837 /* This is an arbitrary limit. */
c19d1205
ZW
3838 unsigned char op[16];
3839 int count;
a737bd4d 3840
c19d1205
ZW
3841 expression (&exp);
3842 if (exp.X_op == O_constant
3843 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3844 {
c19d1205
ZW
3845 unwind.frame_size += exp.X_add_number;
3846 expression (&exp);
3847 }
3848 else
3849 exp.X_op = O_illegal;
a737bd4d 3850
c19d1205
ZW
3851 if (exp.X_op != O_constant)
3852 {
3853 as_bad (_("expected <offset>, <opcode>"));
3854 ignore_rest_of_line ();
3855 return;
3856 }
a737bd4d 3857
c19d1205 3858 count = 0;
a737bd4d 3859
c19d1205
ZW
3860 /* Parse the opcode. */
3861 for (;;)
3862 {
3863 if (count >= 16)
3864 {
3865 as_bad (_("unwind opcode too long"));
3866 ignore_rest_of_line ();
a737bd4d 3867 }
c19d1205 3868 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3869 {
c19d1205
ZW
3870 as_bad (_("invalid unwind opcode"));
3871 ignore_rest_of_line ();
3872 return;
a737bd4d 3873 }
c19d1205 3874 op[count++] = exp.X_add_number;
a737bd4d 3875
c19d1205
ZW
3876 /* Parse the next byte. */
3877 if (skip_past_comma (&input_line_pointer) == FAIL)
3878 break;
a737bd4d 3879
c19d1205
ZW
3880 expression (&exp);
3881 }
b99bd4ef 3882
c19d1205
ZW
3883 /* Add the opcode bytes in reverse order. */
3884 while (count--)
3885 add_unwind_opcode (op[count], 1);
b99bd4ef 3886
c19d1205 3887 demand_empty_rest_of_line ();
b99bd4ef 3888}
ee065d83
PB
3889
3890
3891/* Parse a .eabi_attribute directive. */
3892
3893static void
3894s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3895{
ee3c0378
AS
3896 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
3897
3898 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
3899 attributes_set_explicitly[tag] = 1;
ee065d83 3900}
8463be01 3901#endif /* OBJ_ELF */
ee065d83
PB
3902
3903static void s_arm_arch (int);
7a1d4c38 3904static void s_arm_object_arch (int);
ee065d83
PB
3905static void s_arm_cpu (int);
3906static void s_arm_fpu (int);
b99bd4ef 3907
f0927246
NC
3908#ifdef TE_PE
3909
3910static void
5f4273c7 3911pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
3912{
3913 expressionS exp;
3914
3915 do
3916 {
3917 expression (&exp);
3918 if (exp.X_op == O_symbol)
3919 exp.X_op = O_secrel;
3920
3921 emit_expr (&exp, 4);
3922 }
3923 while (*input_line_pointer++ == ',');
3924
3925 input_line_pointer--;
3926 demand_empty_rest_of_line ();
3927}
3928#endif /* TE_PE */
3929
c19d1205
ZW
3930/* This table describes all the machine specific pseudo-ops the assembler
3931 has to support. The fields are:
3932 pseudo-op name without dot
3933 function to call to execute this pseudo-op
3934 Integer arg to pass to the function. */
b99bd4ef 3935
c19d1205 3936const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3937{
c19d1205
ZW
3938 /* Never called because '.req' does not start a line. */
3939 { "req", s_req, 0 },
dcbf9037
JB
3940 /* Following two are likewise never called. */
3941 { "dn", s_dn, 0 },
3942 { "qn", s_qn, 0 },
c19d1205
ZW
3943 { "unreq", s_unreq, 0 },
3944 { "bss", s_bss, 0 },
3945 { "align", s_align, 0 },
3946 { "arm", s_arm, 0 },
3947 { "thumb", s_thumb, 0 },
3948 { "code", s_code, 0 },
3949 { "force_thumb", s_force_thumb, 0 },
3950 { "thumb_func", s_thumb_func, 0 },
3951 { "thumb_set", s_thumb_set, 0 },
3952 { "even", s_even, 0 },
3953 { "ltorg", s_ltorg, 0 },
3954 { "pool", s_ltorg, 0 },
3955 { "syntax", s_syntax, 0 },
8463be01
PB
3956 { "cpu", s_arm_cpu, 0 },
3957 { "arch", s_arm_arch, 0 },
7a1d4c38 3958 { "object_arch", s_arm_object_arch, 0 },
8463be01 3959 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3960#ifdef OBJ_ELF
3961 { "word", s_arm_elf_cons, 4 },
3962 { "long", s_arm_elf_cons, 4 },
3963 { "rel31", s_arm_rel31, 0 },
3964 { "fnstart", s_arm_unwind_fnstart, 0 },
3965 { "fnend", s_arm_unwind_fnend, 0 },
3966 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3967 { "personality", s_arm_unwind_personality, 0 },
3968 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3969 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3970 { "save", s_arm_unwind_save, 0 },
fa073d69 3971 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3972 { "movsp", s_arm_unwind_movsp, 0 },
3973 { "pad", s_arm_unwind_pad, 0 },
3974 { "setfp", s_arm_unwind_setfp, 0 },
3975 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3976 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3977#else
3978 { "word", cons, 4},
f0927246
NC
3979
3980 /* These are used for dwarf. */
3981 {"2byte", cons, 2},
3982 {"4byte", cons, 4},
3983 {"8byte", cons, 8},
3984 /* These are used for dwarf2. */
3985 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3986 { "loc", dwarf2_directive_loc, 0 },
3987 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3988#endif
3989 { "extend", float_cons, 'x' },
3990 { "ldouble", float_cons, 'x' },
3991 { "packed", float_cons, 'p' },
f0927246
NC
3992#ifdef TE_PE
3993 {"secrel32", pe_directive_secrel, 0},
3994#endif
c19d1205
ZW
3995 { 0, 0, 0 }
3996};
3997\f
3998/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3999
c19d1205
ZW
4000/* Generic immediate-value read function for use in insn parsing.
4001 STR points to the beginning of the immediate (the leading #);
4002 VAL receives the value; if the value is outside [MIN, MAX]
4003 issue an error. PREFIX_OPT is true if the immediate prefix is
4004 optional. */
b99bd4ef 4005
c19d1205
ZW
4006static int
4007parse_immediate (char **str, int *val, int min, int max,
4008 bfd_boolean prefix_opt)
4009{
4010 expressionS exp;
4011 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4012 if (exp.X_op != O_constant)
b99bd4ef 4013 {
c19d1205
ZW
4014 inst.error = _("constant expression required");
4015 return FAIL;
4016 }
b99bd4ef 4017
c19d1205
ZW
4018 if (exp.X_add_number < min || exp.X_add_number > max)
4019 {
4020 inst.error = _("immediate value out of range");
4021 return FAIL;
4022 }
b99bd4ef 4023
c19d1205
ZW
4024 *val = exp.X_add_number;
4025 return SUCCESS;
4026}
b99bd4ef 4027
5287ad62 4028/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4029 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4030 instructions. Puts the result directly in inst.operands[i]. */
4031
4032static int
4033parse_big_immediate (char **str, int i)
4034{
4035 expressionS exp;
4036 char *ptr = *str;
4037
4038 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4039
4040 if (exp.X_op == O_constant)
036dc3f7
PB
4041 {
4042 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4043 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4044 O_constant. We have to be careful not to break compilation for
4045 32-bit X_add_number, though. */
4046 if ((exp.X_add_number & ~0xffffffffl) != 0)
4047 {
4048 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4049 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4050 inst.operands[i].regisimm = 1;
4051 }
4052 }
5287ad62
JB
4053 else if (exp.X_op == O_big
4054 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4055 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4056 {
4057 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4058 /* Bignums have their least significant bits in
4059 generic_bignum[0]. Make sure we put 32 bits in imm and
4060 32 bits in reg, in a (hopefully) portable way. */
4061 assert (parts != 0);
4062 inst.operands[i].imm = 0;
4063 for (j = 0; j < parts; j++, idx++)
4064 inst.operands[i].imm |= generic_bignum[idx]
4065 << (LITTLENUM_NUMBER_OF_BITS * j);
4066 inst.operands[i].reg = 0;
4067 for (j = 0; j < parts; j++, idx++)
4068 inst.operands[i].reg |= generic_bignum[idx]
4069 << (LITTLENUM_NUMBER_OF_BITS * j);
4070 inst.operands[i].regisimm = 1;
4071 }
4072 else
4073 return FAIL;
5f4273c7 4074
5287ad62
JB
4075 *str = ptr;
4076
4077 return SUCCESS;
4078}
4079
c19d1205
ZW
4080/* Returns the pseudo-register number of an FPA immediate constant,
4081 or FAIL if there isn't a valid constant here. */
b99bd4ef 4082
c19d1205
ZW
4083static int
4084parse_fpa_immediate (char ** str)
4085{
4086 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4087 char * save_in;
4088 expressionS exp;
4089 int i;
4090 int j;
b99bd4ef 4091
c19d1205
ZW
4092 /* First try and match exact strings, this is to guarantee
4093 that some formats will work even for cross assembly. */
b99bd4ef 4094
c19d1205
ZW
4095 for (i = 0; fp_const[i]; i++)
4096 {
4097 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4098 {
c19d1205 4099 char *start = *str;
b99bd4ef 4100
c19d1205
ZW
4101 *str += strlen (fp_const[i]);
4102 if (is_end_of_line[(unsigned char) **str])
4103 return i + 8;
4104 *str = start;
4105 }
4106 }
b99bd4ef 4107
c19d1205
ZW
4108 /* Just because we didn't get a match doesn't mean that the constant
4109 isn't valid, just that it is in a format that we don't
4110 automatically recognize. Try parsing it with the standard
4111 expression routines. */
b99bd4ef 4112
c19d1205 4113 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4114
c19d1205
ZW
4115 /* Look for a raw floating point number. */
4116 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4117 && is_end_of_line[(unsigned char) *save_in])
4118 {
4119 for (i = 0; i < NUM_FLOAT_VALS; i++)
4120 {
4121 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4122 {
c19d1205
ZW
4123 if (words[j] != fp_values[i][j])
4124 break;
b99bd4ef
NC
4125 }
4126
c19d1205 4127 if (j == MAX_LITTLENUMS)
b99bd4ef 4128 {
c19d1205
ZW
4129 *str = save_in;
4130 return i + 8;
b99bd4ef
NC
4131 }
4132 }
4133 }
b99bd4ef 4134
c19d1205
ZW
4135 /* Try and parse a more complex expression, this will probably fail
4136 unless the code uses a floating point prefix (eg "0f"). */
4137 save_in = input_line_pointer;
4138 input_line_pointer = *str;
4139 if (expression (&exp) == absolute_section
4140 && exp.X_op == O_big
4141 && exp.X_add_number < 0)
4142 {
4143 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4144 Ditto for 15. */
4145 if (gen_to_words (words, 5, (long) 15) == 0)
4146 {
4147 for (i = 0; i < NUM_FLOAT_VALS; i++)
4148 {
4149 for (j = 0; j < MAX_LITTLENUMS; j++)
4150 {
4151 if (words[j] != fp_values[i][j])
4152 break;
4153 }
b99bd4ef 4154
c19d1205
ZW
4155 if (j == MAX_LITTLENUMS)
4156 {
4157 *str = input_line_pointer;
4158 input_line_pointer = save_in;
4159 return i + 8;
4160 }
4161 }
4162 }
b99bd4ef
NC
4163 }
4164
c19d1205
ZW
4165 *str = input_line_pointer;
4166 input_line_pointer = save_in;
4167 inst.error = _("invalid FPA immediate expression");
4168 return FAIL;
b99bd4ef
NC
4169}
4170
136da414
JB
4171/* Returns 1 if a number has "quarter-precision" float format
4172 0baBbbbbbc defgh000 00000000 00000000. */
4173
4174static int
4175is_quarter_float (unsigned imm)
4176{
4177 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4178 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4179}
4180
4181/* Parse an 8-bit "quarter-precision" floating point number of the form:
4182 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4183 The zero and minus-zero cases need special handling, since they can't be
4184 encoded in the "quarter-precision" float format, but can nonetheless be
4185 loaded as integer constants. */
136da414
JB
4186
4187static unsigned
4188parse_qfloat_immediate (char **ccp, int *immed)
4189{
4190 char *str = *ccp;
c96612cc 4191 char *fpnum;
136da414 4192 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4193 int found_fpchar = 0;
5f4273c7 4194
136da414 4195 skip_past_char (&str, '#');
5f4273c7 4196
c96612cc
JB
4197 /* We must not accidentally parse an integer as a floating-point number. Make
4198 sure that the value we parse is not an integer by checking for special
4199 characters '.' or 'e'.
4200 FIXME: This is a horrible hack, but doing better is tricky because type
4201 information isn't in a very usable state at parse time. */
4202 fpnum = str;
4203 skip_whitespace (fpnum);
4204
4205 if (strncmp (fpnum, "0x", 2) == 0)
4206 return FAIL;
4207 else
4208 {
4209 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4210 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4211 {
4212 found_fpchar = 1;
4213 break;
4214 }
4215
4216 if (!found_fpchar)
4217 return FAIL;
4218 }
5f4273c7 4219
136da414
JB
4220 if ((str = atof_ieee (str, 's', words)) != NULL)
4221 {
4222 unsigned fpword = 0;
4223 int i;
5f4273c7 4224
136da414
JB
4225 /* Our FP word must be 32 bits (single-precision FP). */
4226 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4227 {
4228 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4229 fpword |= words[i];
4230 }
5f4273c7 4231
c96612cc 4232 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4233 *immed = fpword;
4234 else
4235 return FAIL;
4236
4237 *ccp = str;
5f4273c7 4238
136da414
JB
4239 return SUCCESS;
4240 }
5f4273c7 4241
136da414
JB
4242 return FAIL;
4243}
4244
c19d1205
ZW
4245/* Shift operands. */
4246enum shift_kind
b99bd4ef 4247{
c19d1205
ZW
4248 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4249};
b99bd4ef 4250
c19d1205
ZW
4251struct asm_shift_name
4252{
4253 const char *name;
4254 enum shift_kind kind;
4255};
b99bd4ef 4256
c19d1205
ZW
4257/* Third argument to parse_shift. */
4258enum parse_shift_mode
4259{
4260 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4261 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4262 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4263 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4264 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4265};
b99bd4ef 4266
c19d1205
ZW
4267/* Parse a <shift> specifier on an ARM data processing instruction.
4268 This has three forms:
b99bd4ef 4269
c19d1205
ZW
4270 (LSL|LSR|ASL|ASR|ROR) Rs
4271 (LSL|LSR|ASL|ASR|ROR) #imm
4272 RRX
b99bd4ef 4273
c19d1205
ZW
4274 Note that ASL is assimilated to LSL in the instruction encoding, and
4275 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4276
c19d1205
ZW
4277static int
4278parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4279{
c19d1205
ZW
4280 const struct asm_shift_name *shift_name;
4281 enum shift_kind shift;
4282 char *s = *str;
4283 char *p = s;
4284 int reg;
b99bd4ef 4285
c19d1205
ZW
4286 for (p = *str; ISALPHA (*p); p++)
4287 ;
b99bd4ef 4288
c19d1205 4289 if (p == *str)
b99bd4ef 4290 {
c19d1205
ZW
4291 inst.error = _("shift expression expected");
4292 return FAIL;
b99bd4ef
NC
4293 }
4294
c19d1205
ZW
4295 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4296
4297 if (shift_name == NULL)
b99bd4ef 4298 {
c19d1205
ZW
4299 inst.error = _("shift expression expected");
4300 return FAIL;
b99bd4ef
NC
4301 }
4302
c19d1205 4303 shift = shift_name->kind;
b99bd4ef 4304
c19d1205
ZW
4305 switch (mode)
4306 {
4307 case NO_SHIFT_RESTRICT:
4308 case SHIFT_IMMEDIATE: break;
b99bd4ef 4309
c19d1205
ZW
4310 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4311 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4312 {
4313 inst.error = _("'LSL' or 'ASR' required");
4314 return FAIL;
4315 }
4316 break;
b99bd4ef 4317
c19d1205
ZW
4318 case SHIFT_LSL_IMMEDIATE:
4319 if (shift != SHIFT_LSL)
4320 {
4321 inst.error = _("'LSL' required");
4322 return FAIL;
4323 }
4324 break;
b99bd4ef 4325
c19d1205
ZW
4326 case SHIFT_ASR_IMMEDIATE:
4327 if (shift != SHIFT_ASR)
4328 {
4329 inst.error = _("'ASR' required");
4330 return FAIL;
4331 }
4332 break;
b99bd4ef 4333
c19d1205
ZW
4334 default: abort ();
4335 }
b99bd4ef 4336
c19d1205
ZW
4337 if (shift != SHIFT_RRX)
4338 {
4339 /* Whitespace can appear here if the next thing is a bare digit. */
4340 skip_whitespace (p);
b99bd4ef 4341
c19d1205 4342 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4343 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4344 {
4345 inst.operands[i].imm = reg;
4346 inst.operands[i].immisreg = 1;
4347 }
4348 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4349 return FAIL;
4350 }
4351 inst.operands[i].shift_kind = shift;
4352 inst.operands[i].shifted = 1;
4353 *str = p;
4354 return SUCCESS;
b99bd4ef
NC
4355}
4356
c19d1205 4357/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4358
c19d1205
ZW
4359 #<immediate>
4360 #<immediate>, <rotate>
4361 <Rm>
4362 <Rm>, <shift>
b99bd4ef 4363
c19d1205
ZW
4364 where <shift> is defined by parse_shift above, and <rotate> is a
4365 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4366 is deferred to md_apply_fix. */
b99bd4ef 4367
c19d1205
ZW
4368static int
4369parse_shifter_operand (char **str, int i)
4370{
4371 int value;
4372 expressionS expr;
b99bd4ef 4373
dcbf9037 4374 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4375 {
4376 inst.operands[i].reg = value;
4377 inst.operands[i].isreg = 1;
b99bd4ef 4378
c19d1205
ZW
4379 /* parse_shift will override this if appropriate */
4380 inst.reloc.exp.X_op = O_constant;
4381 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4382
c19d1205
ZW
4383 if (skip_past_comma (str) == FAIL)
4384 return SUCCESS;
b99bd4ef 4385
c19d1205
ZW
4386 /* Shift operation on register. */
4387 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4388 }
4389
c19d1205
ZW
4390 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4391 return FAIL;
b99bd4ef 4392
c19d1205 4393 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4394 {
c19d1205
ZW
4395 /* #x, y -- ie explicit rotation by Y. */
4396 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4397 return FAIL;
b99bd4ef 4398
c19d1205
ZW
4399 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4400 {
4401 inst.error = _("constant expression expected");
4402 return FAIL;
4403 }
b99bd4ef 4404
c19d1205
ZW
4405 value = expr.X_add_number;
4406 if (value < 0 || value > 30 || value % 2 != 0)
4407 {
4408 inst.error = _("invalid rotation");
4409 return FAIL;
4410 }
4411 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4412 {
4413 inst.error = _("invalid constant");
4414 return FAIL;
4415 }
09d92015 4416
55cf6793 4417 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4418 inst.reloc.exp.X_add_number
4419 = (((inst.reloc.exp.X_add_number << (32 - value))
4420 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4421 }
4422
c19d1205
ZW
4423 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4424 inst.reloc.pc_rel = 0;
4425 return SUCCESS;
09d92015
MM
4426}
4427
4962c51a
MS
4428/* Group relocation information. Each entry in the table contains the
4429 textual name of the relocation as may appear in assembler source
4430 and must end with a colon.
4431 Along with this textual name are the relocation codes to be used if
4432 the corresponding instruction is an ALU instruction (ADD or SUB only),
4433 an LDR, an LDRS, or an LDC. */
4434
4435struct group_reloc_table_entry
4436{
4437 const char *name;
4438 int alu_code;
4439 int ldr_code;
4440 int ldrs_code;
4441 int ldc_code;
4442};
4443
4444typedef enum
4445{
4446 /* Varieties of non-ALU group relocation. */
4447
4448 GROUP_LDR,
4449 GROUP_LDRS,
4450 GROUP_LDC
4451} group_reloc_type;
4452
4453static struct group_reloc_table_entry group_reloc_table[] =
4454 { /* Program counter relative: */
4455 { "pc_g0_nc",
4456 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4457 0, /* LDR */
4458 0, /* LDRS */
4459 0 }, /* LDC */
4460 { "pc_g0",
4461 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4462 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4463 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4464 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4465 { "pc_g1_nc",
4466 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "pc_g1",
4471 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4472 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4473 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4474 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4475 { "pc_g2",
4476 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4477 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4478 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4479 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4480 /* Section base relative */
4481 { "sb_g0_nc",
4482 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4483 0, /* LDR */
4484 0, /* LDRS */
4485 0 }, /* LDC */
4486 { "sb_g0",
4487 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4488 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4489 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4490 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4491 { "sb_g1_nc",
4492 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4493 0, /* LDR */
4494 0, /* LDRS */
4495 0 }, /* LDC */
4496 { "sb_g1",
4497 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4498 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4499 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4500 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4501 { "sb_g2",
4502 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4503 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4504 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4505 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4506
4507/* Given the address of a pointer pointing to the textual name of a group
4508 relocation as may appear in assembler source, attempt to find its details
4509 in group_reloc_table. The pointer will be updated to the character after
4510 the trailing colon. On failure, FAIL will be returned; SUCCESS
4511 otherwise. On success, *entry will be updated to point at the relevant
4512 group_reloc_table entry. */
4513
4514static int
4515find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4516{
4517 unsigned int i;
4518 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4519 {
4520 int length = strlen (group_reloc_table[i].name);
4521
5f4273c7
NC
4522 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4523 && (*str)[length] == ':')
4962c51a
MS
4524 {
4525 *out = &group_reloc_table[i];
4526 *str += (length + 1);
4527 return SUCCESS;
4528 }
4529 }
4530
4531 return FAIL;
4532}
4533
4534/* Parse a <shifter_operand> for an ARM data processing instruction
4535 (as for parse_shifter_operand) where group relocations are allowed:
4536
4537 #<immediate>
4538 #<immediate>, <rotate>
4539 #:<group_reloc>:<expression>
4540 <Rm>
4541 <Rm>, <shift>
4542
4543 where <group_reloc> is one of the strings defined in group_reloc_table.
4544 The hashes are optional.
4545
4546 Everything else is as for parse_shifter_operand. */
4547
4548static parse_operand_result
4549parse_shifter_operand_group_reloc (char **str, int i)
4550{
4551 /* Determine if we have the sequence of characters #: or just :
4552 coming next. If we do, then we check for a group relocation.
4553 If we don't, punt the whole lot to parse_shifter_operand. */
4554
4555 if (((*str)[0] == '#' && (*str)[1] == ':')
4556 || (*str)[0] == ':')
4557 {
4558 struct group_reloc_table_entry *entry;
4559
4560 if ((*str)[0] == '#')
4561 (*str) += 2;
4562 else
4563 (*str)++;
4564
4565 /* Try to parse a group relocation. Anything else is an error. */
4566 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4567 {
4568 inst.error = _("unknown group relocation");
4569 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4570 }
4571
4572 /* We now have the group relocation table entry corresponding to
4573 the name in the assembler source. Next, we parse the expression. */
4574 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4575 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4576
4577 /* Record the relocation type (always the ALU variant here). */
4578 inst.reloc.type = entry->alu_code;
4579 assert (inst.reloc.type != 0);
4580
4581 return PARSE_OPERAND_SUCCESS;
4582 }
4583 else
4584 return parse_shifter_operand (str, i) == SUCCESS
4585 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4586
4587 /* Never reached. */
4588}
4589
c19d1205
ZW
4590/* Parse all forms of an ARM address expression. Information is written
4591 to inst.operands[i] and/or inst.reloc.
09d92015 4592
c19d1205 4593 Preindexed addressing (.preind=1):
09d92015 4594
c19d1205
ZW
4595 [Rn, #offset] .reg=Rn .reloc.exp=offset
4596 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4597 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4598 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4599
c19d1205 4600 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4601
c19d1205 4602 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4603
c19d1205
ZW
4604 [Rn], #offset .reg=Rn .reloc.exp=offset
4605 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4606 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4607 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4608
c19d1205 4609 Unindexed addressing (.preind=0, .postind=0):
09d92015 4610
c19d1205 4611 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4612
c19d1205 4613 Other:
09d92015 4614
c19d1205
ZW
4615 [Rn]{!} shorthand for [Rn,#0]{!}
4616 =immediate .isreg=0 .reloc.exp=immediate
4617 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4618
c19d1205
ZW
4619 It is the caller's responsibility to check for addressing modes not
4620 supported by the instruction, and to set inst.reloc.type. */
4621
4962c51a
MS
4622static parse_operand_result
4623parse_address_main (char **str, int i, int group_relocations,
4624 group_reloc_type group_type)
09d92015 4625{
c19d1205
ZW
4626 char *p = *str;
4627 int reg;
09d92015 4628
c19d1205 4629 if (skip_past_char (&p, '[') == FAIL)
09d92015 4630 {
c19d1205
ZW
4631 if (skip_past_char (&p, '=') == FAIL)
4632 {
4633 /* bare address - translate to PC-relative offset */
4634 inst.reloc.pc_rel = 1;
4635 inst.operands[i].reg = REG_PC;
4636 inst.operands[i].isreg = 1;
4637 inst.operands[i].preind = 1;
4638 }
4639 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4640
c19d1205 4641 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4642 return PARSE_OPERAND_FAIL;
09d92015 4643
c19d1205 4644 *str = p;
4962c51a 4645 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4646 }
4647
dcbf9037 4648 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4649 {
c19d1205 4650 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4651 return PARSE_OPERAND_FAIL;
09d92015 4652 }
c19d1205
ZW
4653 inst.operands[i].reg = reg;
4654 inst.operands[i].isreg = 1;
09d92015 4655
c19d1205 4656 if (skip_past_comma (&p) == SUCCESS)
09d92015 4657 {
c19d1205 4658 inst.operands[i].preind = 1;
09d92015 4659
c19d1205
ZW
4660 if (*p == '+') p++;
4661 else if (*p == '-') p++, inst.operands[i].negative = 1;
4662
dcbf9037 4663 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4664 {
c19d1205
ZW
4665 inst.operands[i].imm = reg;
4666 inst.operands[i].immisreg = 1;
4667
4668 if (skip_past_comma (&p) == SUCCESS)
4669 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4670 return PARSE_OPERAND_FAIL;
c19d1205 4671 }
5287ad62
JB
4672 else if (skip_past_char (&p, ':') == SUCCESS)
4673 {
4674 /* FIXME: '@' should be used here, but it's filtered out by generic
4675 code before we get to see it here. This may be subject to
4676 change. */
4677 expressionS exp;
4678 my_get_expression (&exp, &p, GE_NO_PREFIX);
4679 if (exp.X_op != O_constant)
4680 {
4681 inst.error = _("alignment must be constant");
4962c51a 4682 return PARSE_OPERAND_FAIL;
5287ad62
JB
4683 }
4684 inst.operands[i].imm = exp.X_add_number << 8;
4685 inst.operands[i].immisalign = 1;
4686 /* Alignments are not pre-indexes. */
4687 inst.operands[i].preind = 0;
4688 }
c19d1205
ZW
4689 else
4690 {
4691 if (inst.operands[i].negative)
4692 {
4693 inst.operands[i].negative = 0;
4694 p--;
4695 }
4962c51a 4696
5f4273c7
NC
4697 if (group_relocations
4698 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4699 {
4700 struct group_reloc_table_entry *entry;
4701
4702 /* Skip over the #: or : sequence. */
4703 if (*p == '#')
4704 p += 2;
4705 else
4706 p++;
4707
4708 /* Try to parse a group relocation. Anything else is an
4709 error. */
4710 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4711 {
4712 inst.error = _("unknown group relocation");
4713 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4714 }
4715
4716 /* We now have the group relocation table entry corresponding to
4717 the name in the assembler source. Next, we parse the
4718 expression. */
4719 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4720 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4721
4722 /* Record the relocation type. */
4723 switch (group_type)
4724 {
4725 case GROUP_LDR:
4726 inst.reloc.type = entry->ldr_code;
4727 break;
4728
4729 case GROUP_LDRS:
4730 inst.reloc.type = entry->ldrs_code;
4731 break;
4732
4733 case GROUP_LDC:
4734 inst.reloc.type = entry->ldc_code;
4735 break;
4736
4737 default:
4738 assert (0);
4739 }
4740
4741 if (inst.reloc.type == 0)
4742 {
4743 inst.error = _("this group relocation is not allowed on this instruction");
4744 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4745 }
4746 }
4747 else
4748 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4749 return PARSE_OPERAND_FAIL;
09d92015
MM
4750 }
4751 }
4752
c19d1205 4753 if (skip_past_char (&p, ']') == FAIL)
09d92015 4754 {
c19d1205 4755 inst.error = _("']' expected");
4962c51a 4756 return PARSE_OPERAND_FAIL;
09d92015
MM
4757 }
4758
c19d1205
ZW
4759 if (skip_past_char (&p, '!') == SUCCESS)
4760 inst.operands[i].writeback = 1;
09d92015 4761
c19d1205 4762 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4763 {
c19d1205
ZW
4764 if (skip_past_char (&p, '{') == SUCCESS)
4765 {
4766 /* [Rn], {expr} - unindexed, with option */
4767 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4768 0, 255, TRUE) == FAIL)
4962c51a 4769 return PARSE_OPERAND_FAIL;
09d92015 4770
c19d1205
ZW
4771 if (skip_past_char (&p, '}') == FAIL)
4772 {
4773 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4774 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4775 }
4776 if (inst.operands[i].preind)
4777 {
4778 inst.error = _("cannot combine index with option");
4962c51a 4779 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4780 }
4781 *str = p;
4962c51a 4782 return PARSE_OPERAND_SUCCESS;
09d92015 4783 }
c19d1205
ZW
4784 else
4785 {
4786 inst.operands[i].postind = 1;
4787 inst.operands[i].writeback = 1;
09d92015 4788
c19d1205
ZW
4789 if (inst.operands[i].preind)
4790 {
4791 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4792 return PARSE_OPERAND_FAIL;
c19d1205 4793 }
09d92015 4794
c19d1205
ZW
4795 if (*p == '+') p++;
4796 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4797
dcbf9037 4798 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4799 {
5287ad62
JB
4800 /* We might be using the immediate for alignment already. If we
4801 are, OR the register number into the low-order bits. */
4802 if (inst.operands[i].immisalign)
4803 inst.operands[i].imm |= reg;
4804 else
4805 inst.operands[i].imm = reg;
c19d1205 4806 inst.operands[i].immisreg = 1;
a737bd4d 4807
c19d1205
ZW
4808 if (skip_past_comma (&p) == SUCCESS)
4809 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4810 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4811 }
4812 else
4813 {
4814 if (inst.operands[i].negative)
4815 {
4816 inst.operands[i].negative = 0;
4817 p--;
4818 }
4819 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4820 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4821 }
4822 }
a737bd4d
NC
4823 }
4824
c19d1205
ZW
4825 /* If at this point neither .preind nor .postind is set, we have a
4826 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4827 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4828 {
4829 inst.operands[i].preind = 1;
4830 inst.reloc.exp.X_op = O_constant;
4831 inst.reloc.exp.X_add_number = 0;
4832 }
4833 *str = p;
4962c51a
MS
4834 return PARSE_OPERAND_SUCCESS;
4835}
4836
4837static int
4838parse_address (char **str, int i)
4839{
4840 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4841 ? SUCCESS : FAIL;
4842}
4843
4844static parse_operand_result
4845parse_address_group_reloc (char **str, int i, group_reloc_type type)
4846{
4847 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4848}
4849
b6895b4f
PB
4850/* Parse an operand for a MOVW or MOVT instruction. */
4851static int
4852parse_half (char **str)
4853{
4854 char * p;
5f4273c7 4855
b6895b4f
PB
4856 p = *str;
4857 skip_past_char (&p, '#');
5f4273c7 4858 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4859 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4860 else if (strncasecmp (p, ":upper16:", 9) == 0)
4861 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4862
4863 if (inst.reloc.type != BFD_RELOC_UNUSED)
4864 {
4865 p += 9;
5f4273c7 4866 skip_whitespace (p);
b6895b4f
PB
4867 }
4868
4869 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4870 return FAIL;
4871
4872 if (inst.reloc.type == BFD_RELOC_UNUSED)
4873 {
4874 if (inst.reloc.exp.X_op != O_constant)
4875 {
4876 inst.error = _("constant expression expected");
4877 return FAIL;
4878 }
4879 if (inst.reloc.exp.X_add_number < 0
4880 || inst.reloc.exp.X_add_number > 0xffff)
4881 {
4882 inst.error = _("immediate value out of range");
4883 return FAIL;
4884 }
4885 }
4886 *str = p;
4887 return SUCCESS;
4888}
4889
c19d1205 4890/* Miscellaneous. */
a737bd4d 4891
c19d1205
ZW
4892/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4893 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4894static int
4895parse_psr (char **str)
09d92015 4896{
c19d1205
ZW
4897 char *p;
4898 unsigned long psr_field;
62b3e311
PB
4899 const struct asm_psr *psr;
4900 char *start;
09d92015 4901
c19d1205
ZW
4902 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4903 feature for ease of use and backwards compatibility. */
4904 p = *str;
62b3e311 4905 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4906 psr_field = SPSR_BIT;
62b3e311 4907 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4908 psr_field = 0;
4909 else
62b3e311
PB
4910 {
4911 start = p;
4912 do
4913 p++;
4914 while (ISALNUM (*p) || *p == '_');
4915
4916 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4917 if (!psr)
4918 return FAIL;
09d92015 4919
62b3e311
PB
4920 *str = p;
4921 return psr->field;
4922 }
09d92015 4923
62b3e311 4924 p += 4;
c19d1205
ZW
4925 if (*p == '_')
4926 {
4927 /* A suffix follows. */
c19d1205
ZW
4928 p++;
4929 start = p;
a737bd4d 4930
c19d1205
ZW
4931 do
4932 p++;
4933 while (ISALNUM (*p) || *p == '_');
a737bd4d 4934
c19d1205
ZW
4935 psr = hash_find_n (arm_psr_hsh, start, p - start);
4936 if (!psr)
4937 goto error;
a737bd4d 4938
c19d1205 4939 psr_field |= psr->field;
a737bd4d 4940 }
c19d1205 4941 else
a737bd4d 4942 {
c19d1205
ZW
4943 if (ISALNUM (*p))
4944 goto error; /* Garbage after "[CS]PSR". */
4945
4946 psr_field |= (PSR_c | PSR_f);
a737bd4d 4947 }
c19d1205
ZW
4948 *str = p;
4949 return psr_field;
a737bd4d 4950
c19d1205
ZW
4951 error:
4952 inst.error = _("flag for {c}psr instruction expected");
4953 return FAIL;
a737bd4d
NC
4954}
4955
c19d1205
ZW
4956/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4957 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4958
c19d1205
ZW
4959static int
4960parse_cps_flags (char **str)
a737bd4d 4961{
c19d1205
ZW
4962 int val = 0;
4963 int saw_a_flag = 0;
4964 char *s = *str;
a737bd4d 4965
c19d1205
ZW
4966 for (;;)
4967 switch (*s++)
4968 {
4969 case '\0': case ',':
4970 goto done;
a737bd4d 4971
c19d1205
ZW
4972 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4973 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4974 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4975
c19d1205
ZW
4976 default:
4977 inst.error = _("unrecognized CPS flag");
4978 return FAIL;
4979 }
a737bd4d 4980
c19d1205
ZW
4981 done:
4982 if (saw_a_flag == 0)
a737bd4d 4983 {
c19d1205
ZW
4984 inst.error = _("missing CPS flags");
4985 return FAIL;
a737bd4d 4986 }
a737bd4d 4987
c19d1205
ZW
4988 *str = s - 1;
4989 return val;
a737bd4d
NC
4990}
4991
c19d1205
ZW
4992/* Parse an endian specifier ("BE" or "LE", case insensitive);
4993 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4994
4995static int
c19d1205 4996parse_endian_specifier (char **str)
a737bd4d 4997{
c19d1205
ZW
4998 int little_endian;
4999 char *s = *str;
a737bd4d 5000
c19d1205
ZW
5001 if (strncasecmp (s, "BE", 2))
5002 little_endian = 0;
5003 else if (strncasecmp (s, "LE", 2))
5004 little_endian = 1;
5005 else
a737bd4d 5006 {
c19d1205 5007 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5008 return FAIL;
5009 }
5010
c19d1205 5011 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5012 {
c19d1205 5013 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5014 return FAIL;
5015 }
5016
c19d1205
ZW
5017 *str = s + 2;
5018 return little_endian;
5019}
a737bd4d 5020
c19d1205
ZW
5021/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5022 value suitable for poking into the rotate field of an sxt or sxta
5023 instruction, or FAIL on error. */
5024
5025static int
5026parse_ror (char **str)
5027{
5028 int rot;
5029 char *s = *str;
5030
5031 if (strncasecmp (s, "ROR", 3) == 0)
5032 s += 3;
5033 else
a737bd4d 5034 {
c19d1205 5035 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5036 return FAIL;
5037 }
c19d1205
ZW
5038
5039 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5040 return FAIL;
5041
5042 switch (rot)
a737bd4d 5043 {
c19d1205
ZW
5044 case 0: *str = s; return 0x0;
5045 case 8: *str = s; return 0x1;
5046 case 16: *str = s; return 0x2;
5047 case 24: *str = s; return 0x3;
5048
5049 default:
5050 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5051 return FAIL;
5052 }
c19d1205 5053}
a737bd4d 5054
c19d1205
ZW
5055/* Parse a conditional code (from conds[] below). The value returned is in the
5056 range 0 .. 14, or FAIL. */
5057static int
5058parse_cond (char **str)
5059{
c462b453 5060 char *q;
c19d1205 5061 const struct asm_cond *c;
c462b453
PB
5062 int n;
5063 /* Condition codes are always 2 characters, so matching up to
5064 3 characters is sufficient. */
5065 char cond[3];
a737bd4d 5066
c462b453
PB
5067 q = *str;
5068 n = 0;
5069 while (ISALPHA (*q) && n < 3)
5070 {
5071 cond[n] = TOLOWER(*q);
5072 q++;
5073 n++;
5074 }
a737bd4d 5075
c462b453 5076 c = hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5077 if (!c)
a737bd4d 5078 {
c19d1205 5079 inst.error = _("condition required");
a737bd4d
NC
5080 return FAIL;
5081 }
5082
c19d1205
ZW
5083 *str = q;
5084 return c->value;
5085}
5086
62b3e311
PB
5087/* Parse an option for a barrier instruction. Returns the encoding for the
5088 option, or FAIL. */
5089static int
5090parse_barrier (char **str)
5091{
5092 char *p, *q;
5093 const struct asm_barrier_opt *o;
5094
5095 p = q = *str;
5096 while (ISALPHA (*q))
5097 q++;
5098
5099 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5100 if (!o)
5101 return FAIL;
5102
5103 *str = q;
5104 return o->value;
5105}
5106
92e90b6e
PB
5107/* Parse the operands of a table branch instruction. Similar to a memory
5108 operand. */
5109static int
5110parse_tb (char **str)
5111{
5112 char * p = *str;
5113 int reg;
5114
5115 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5116 {
5117 inst.error = _("'[' expected");
5118 return FAIL;
5119 }
92e90b6e 5120
dcbf9037 5121 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5122 {
5123 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5124 return FAIL;
5125 }
5126 inst.operands[0].reg = reg;
5127
5128 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5129 {
5130 inst.error = _("',' expected");
5131 return FAIL;
5132 }
5f4273c7 5133
dcbf9037 5134 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5135 {
5136 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5137 return FAIL;
5138 }
5139 inst.operands[0].imm = reg;
5140
5141 if (skip_past_comma (&p) == SUCCESS)
5142 {
5143 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5144 return FAIL;
5145 if (inst.reloc.exp.X_add_number != 1)
5146 {
5147 inst.error = _("invalid shift");
5148 return FAIL;
5149 }
5150 inst.operands[0].shifted = 1;
5151 }
5152
5153 if (skip_past_char (&p, ']') == FAIL)
5154 {
5155 inst.error = _("']' expected");
5156 return FAIL;
5157 }
5158 *str = p;
5159 return SUCCESS;
5160}
5161
5287ad62
JB
5162/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5163 information on the types the operands can take and how they are encoded.
037e8744
JB
5164 Up to four operands may be read; this function handles setting the
5165 ".present" field for each read operand itself.
5287ad62
JB
5166 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5167 else returns FAIL. */
5168
5169static int
5170parse_neon_mov (char **str, int *which_operand)
5171{
5172 int i = *which_operand, val;
5173 enum arm_reg_type rtype;
5174 char *ptr = *str;
dcbf9037 5175 struct neon_type_el optype;
5f4273c7 5176
dcbf9037 5177 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5178 {
5179 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5180 inst.operands[i].reg = val;
5181 inst.operands[i].isscalar = 1;
dcbf9037 5182 inst.operands[i].vectype = optype;
5287ad62
JB
5183 inst.operands[i++].present = 1;
5184
5185 if (skip_past_comma (&ptr) == FAIL)
5186 goto wanted_comma;
5f4273c7 5187
dcbf9037 5188 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5189 goto wanted_arm;
5f4273c7 5190
5287ad62
JB
5191 inst.operands[i].reg = val;
5192 inst.operands[i].isreg = 1;
5193 inst.operands[i].present = 1;
5194 }
037e8744 5195 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5196 != FAIL)
5287ad62
JB
5197 {
5198 /* Cases 0, 1, 2, 3, 5 (D only). */
5199 if (skip_past_comma (&ptr) == FAIL)
5200 goto wanted_comma;
5f4273c7 5201
5287ad62
JB
5202 inst.operands[i].reg = val;
5203 inst.operands[i].isreg = 1;
5204 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5205 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5206 inst.operands[i].isvec = 1;
dcbf9037 5207 inst.operands[i].vectype = optype;
5287ad62
JB
5208 inst.operands[i++].present = 1;
5209
dcbf9037 5210 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5211 {
037e8744
JB
5212 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5213 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5214 inst.operands[i].reg = val;
5215 inst.operands[i].isreg = 1;
037e8744 5216 inst.operands[i].present = 1;
5287ad62
JB
5217
5218 if (rtype == REG_TYPE_NQ)
5219 {
dcbf9037 5220 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5221 return FAIL;
5222 }
037e8744
JB
5223 else if (rtype != REG_TYPE_VFS)
5224 {
5225 i++;
5226 if (skip_past_comma (&ptr) == FAIL)
5227 goto wanted_comma;
5228 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5229 goto wanted_arm;
5230 inst.operands[i].reg = val;
5231 inst.operands[i].isreg = 1;
5232 inst.operands[i].present = 1;
5233 }
5287ad62 5234 }
037e8744
JB
5235 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5236 &optype)) != FAIL)
5287ad62
JB
5237 {
5238 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5239 Case 1: VMOV<c><q> <Dd>, <Dm>
5240 Case 8: VMOV.F32 <Sd>, <Sm>
5241 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5242
5243 inst.operands[i].reg = val;
5244 inst.operands[i].isreg = 1;
5245 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5246 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5247 inst.operands[i].isvec = 1;
dcbf9037 5248 inst.operands[i].vectype = optype;
5287ad62 5249 inst.operands[i].present = 1;
5f4273c7 5250
037e8744
JB
5251 if (skip_past_comma (&ptr) == SUCCESS)
5252 {
5253 /* Case 15. */
5254 i++;
5255
5256 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5257 goto wanted_arm;
5258
5259 inst.operands[i].reg = val;
5260 inst.operands[i].isreg = 1;
5261 inst.operands[i++].present = 1;
5f4273c7 5262
037e8744
JB
5263 if (skip_past_comma (&ptr) == FAIL)
5264 goto wanted_comma;
5f4273c7 5265
037e8744
JB
5266 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5267 goto wanted_arm;
5f4273c7 5268
037e8744
JB
5269 inst.operands[i].reg = val;
5270 inst.operands[i].isreg = 1;
5271 inst.operands[i++].present = 1;
5272 }
5287ad62 5273 }
4641781c
PB
5274 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5275 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5276 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5277 Case 10: VMOV.F32 <Sd>, #<imm>
5278 Case 11: VMOV.F64 <Dd>, #<imm> */
5279 inst.operands[i].immisfloat = 1;
5280 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5281 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5282 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5283 ;
5287ad62
JB
5284 else
5285 {
dcbf9037 5286 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5287 return FAIL;
5288 }
5289 }
dcbf9037 5290 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5291 {
5292 /* Cases 6, 7. */
5293 inst.operands[i].reg = val;
5294 inst.operands[i].isreg = 1;
5295 inst.operands[i++].present = 1;
5f4273c7 5296
5287ad62
JB
5297 if (skip_past_comma (&ptr) == FAIL)
5298 goto wanted_comma;
5f4273c7 5299
dcbf9037 5300 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5301 {
5302 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5303 inst.operands[i].reg = val;
5304 inst.operands[i].isscalar = 1;
5305 inst.operands[i].present = 1;
dcbf9037 5306 inst.operands[i].vectype = optype;
5287ad62 5307 }
dcbf9037 5308 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5309 {
5310 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i++].present = 1;
5f4273c7 5314
5287ad62
JB
5315 if (skip_past_comma (&ptr) == FAIL)
5316 goto wanted_comma;
5f4273c7 5317
037e8744 5318 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5319 == FAIL)
5287ad62 5320 {
037e8744 5321 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5322 return FAIL;
5323 }
5324
5325 inst.operands[i].reg = val;
5326 inst.operands[i].isreg = 1;
037e8744
JB
5327 inst.operands[i].isvec = 1;
5328 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5329 inst.operands[i].vectype = optype;
5287ad62 5330 inst.operands[i].present = 1;
5f4273c7 5331
037e8744
JB
5332 if (rtype == REG_TYPE_VFS)
5333 {
5334 /* Case 14. */
5335 i++;
5336 if (skip_past_comma (&ptr) == FAIL)
5337 goto wanted_comma;
5338 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5339 &optype)) == FAIL)
5340 {
5341 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5342 return FAIL;
5343 }
5344 inst.operands[i].reg = val;
5345 inst.operands[i].isreg = 1;
5346 inst.operands[i].isvec = 1;
5347 inst.operands[i].issingle = 1;
5348 inst.operands[i].vectype = optype;
5349 inst.operands[i].present = 1;
5350 }
5351 }
5352 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5353 != FAIL)
5354 {
5355 /* Case 13. */
5356 inst.operands[i].reg = val;
5357 inst.operands[i].isreg = 1;
5358 inst.operands[i].isvec = 1;
5359 inst.operands[i].issingle = 1;
5360 inst.operands[i].vectype = optype;
5361 inst.operands[i++].present = 1;
5287ad62
JB
5362 }
5363 }
5364 else
5365 {
dcbf9037 5366 first_error (_("parse error"));
5287ad62
JB
5367 return FAIL;
5368 }
5369
5370 /* Successfully parsed the operands. Update args. */
5371 *which_operand = i;
5372 *str = ptr;
5373 return SUCCESS;
5374
5f4273c7 5375 wanted_comma:
dcbf9037 5376 first_error (_("expected comma"));
5287ad62 5377 return FAIL;
5f4273c7
NC
5378
5379 wanted_arm:
dcbf9037 5380 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5381 return FAIL;
5287ad62
JB
5382}
5383
c19d1205
ZW
5384/* Matcher codes for parse_operands. */
5385enum operand_parse_code
5386{
5387 OP_stop, /* end of line */
5388
5389 OP_RR, /* ARM register */
5390 OP_RRnpc, /* ARM register, not r15 */
5391 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5392 OP_RRw, /* ARM register, not r15, optional trailing ! */
5393 OP_RCP, /* Coprocessor number */
5394 OP_RCN, /* Coprocessor register */
5395 OP_RF, /* FPA register */
5396 OP_RVS, /* VFP single precision register */
5287ad62
JB
5397 OP_RVD, /* VFP double precision register (0..15) */
5398 OP_RND, /* Neon double precision register (0..31) */
5399 OP_RNQ, /* Neon quad precision register */
037e8744 5400 OP_RVSD, /* VFP single or double precision register */
5287ad62 5401 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5402 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5403 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5404 OP_RVC, /* VFP control register */
5405 OP_RMF, /* Maverick F register */
5406 OP_RMD, /* Maverick D register */
5407 OP_RMFX, /* Maverick FX register */
5408 OP_RMDX, /* Maverick DX register */
5409 OP_RMAX, /* Maverick AX register */
5410 OP_RMDS, /* Maverick DSPSC register */
5411 OP_RIWR, /* iWMMXt wR register */
5412 OP_RIWC, /* iWMMXt wC register */
5413 OP_RIWG, /* iWMMXt wCG register */
5414 OP_RXA, /* XScale accumulator register */
5415
5416 OP_REGLST, /* ARM register list */
5417 OP_VRSLST, /* VFP single-precision register list */
5418 OP_VRDLST, /* VFP double-precision register list */
037e8744 5419 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5420 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5421 OP_NSTRLST, /* Neon element/structure list */
5422
5423 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5424 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5425 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5426 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5427 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5428 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5429 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5430 OP_VMOV, /* Neon VMOV operands. */
5431 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5432 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5433 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5434
5435 OP_I0, /* immediate zero */
c19d1205
ZW
5436 OP_I7, /* immediate value 0 .. 7 */
5437 OP_I15, /* 0 .. 15 */
5438 OP_I16, /* 1 .. 16 */
5287ad62 5439 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5440 OP_I31, /* 0 .. 31 */
5441 OP_I31w, /* 0 .. 31, optional trailing ! */
5442 OP_I32, /* 1 .. 32 */
5287ad62
JB
5443 OP_I32z, /* 0 .. 32 */
5444 OP_I63, /* 0 .. 63 */
c19d1205 5445 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5446 OP_I64, /* 1 .. 64 */
5447 OP_I64z, /* 0 .. 64 */
c19d1205 5448 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5449
5450 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5451 OP_I7b, /* 0 .. 7 */
5452 OP_I15b, /* 0 .. 15 */
5453 OP_I31b, /* 0 .. 31 */
5454
5455 OP_SH, /* shifter operand */
4962c51a 5456 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5457 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5458 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5459 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5460 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5461 OP_EXP, /* arbitrary expression */
5462 OP_EXPi, /* same, with optional immediate prefix */
5463 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5464 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5465
5466 OP_CPSF, /* CPS flags */
5467 OP_ENDI, /* Endianness specifier */
5468 OP_PSR, /* CPSR/SPSR mask for msr */
5469 OP_COND, /* conditional code */
92e90b6e 5470 OP_TB, /* Table branch. */
c19d1205 5471
037e8744
JB
5472 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5473 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5474
c19d1205
ZW
5475 OP_RRnpc_I0, /* ARM register or literal 0 */
5476 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5477 OP_RR_EXi, /* ARM register or expression with imm prefix */
5478 OP_RF_IF, /* FPA register or immediate */
5479 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5480 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5481
5482 /* Optional operands. */
5483 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5484 OP_oI31b, /* 0 .. 31 */
5287ad62 5485 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5486 OP_oIffffb, /* 0 .. 65535 */
5487 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5488
5489 OP_oRR, /* ARM register */
5490 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5491 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5492 OP_oRND, /* Optional Neon double precision register */
5493 OP_oRNQ, /* Optional Neon quad precision register */
5494 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5495 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5496 OP_oSHll, /* LSL immediate */
5497 OP_oSHar, /* ASR immediate */
5498 OP_oSHllar, /* LSL or ASR immediate */
5499 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5500 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5501
5502 OP_FIRST_OPTIONAL = OP_oI7b
5503};
a737bd4d 5504
c19d1205
ZW
5505/* Generic instruction operand parser. This does no encoding and no
5506 semantic validation; it merely squirrels values away in the inst
5507 structure. Returns SUCCESS or FAIL depending on whether the
5508 specified grammar matched. */
5509static int
ca3f61f7 5510parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5511{
5512 unsigned const char *upat = pattern;
5513 char *backtrack_pos = 0;
5514 const char *backtrack_error = 0;
5515 int i, val, backtrack_index = 0;
5287ad62 5516 enum arm_reg_type rtype;
4962c51a 5517 parse_operand_result result;
c19d1205
ZW
5518
5519#define po_char_or_fail(chr) do { \
5520 if (skip_past_char (&str, chr) == FAIL) \
5521 goto bad_args; \
5522} while (0)
5523
dcbf9037
JB
5524#define po_reg_or_fail(regtype) do { \
5525 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5526 &inst.operands[i].vectype); \
5527 if (val == FAIL) \
5528 { \
5529 first_error (_(reg_expected_msgs[regtype])); \
5530 goto failure; \
5531 } \
5532 inst.operands[i].reg = val; \
5533 inst.operands[i].isreg = 1; \
5534 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5535 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5536 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5537 || rtype == REG_TYPE_VFD \
5538 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5539} while (0)
5540
dcbf9037
JB
5541#define po_reg_or_goto(regtype, label) do { \
5542 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5543 &inst.operands[i].vectype); \
5544 if (val == FAIL) \
5545 goto label; \
5546 \
5547 inst.operands[i].reg = val; \
5548 inst.operands[i].isreg = 1; \
5549 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5550 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5551 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5552 || rtype == REG_TYPE_VFD \
5553 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5554} while (0)
5555
5556#define po_imm_or_fail(min, max, popt) do { \
5557 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5558 goto failure; \
5559 inst.operands[i].imm = val; \
5560} while (0)
5561
dcbf9037
JB
5562#define po_scalar_or_goto(elsz, label) do { \
5563 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5564 if (val == FAIL) \
5565 goto label; \
5566 inst.operands[i].reg = val; \
5567 inst.operands[i].isscalar = 1; \
5287ad62
JB
5568} while (0)
5569
c19d1205
ZW
5570#define po_misc_or_fail(expr) do { \
5571 if (expr) \
5572 goto failure; \
5573} while (0)
5574
4962c51a
MS
5575#define po_misc_or_fail_no_backtrack(expr) do { \
5576 result = expr; \
5577 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5578 backtrack_pos = 0; \
5579 if (result != PARSE_OPERAND_SUCCESS) \
5580 goto failure; \
5581} while (0)
5582
c19d1205
ZW
5583 skip_whitespace (str);
5584
5585 for (i = 0; upat[i] != OP_stop; i++)
5586 {
5587 if (upat[i] >= OP_FIRST_OPTIONAL)
5588 {
5589 /* Remember where we are in case we need to backtrack. */
5590 assert (!backtrack_pos);
5591 backtrack_pos = str;
5592 backtrack_error = inst.error;
5593 backtrack_index = i;
5594 }
5595
b6702015 5596 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5597 po_char_or_fail (',');
5598
5599 switch (upat[i])
5600 {
5601 /* Registers */
5602 case OP_oRRnpc:
5603 case OP_RRnpc:
5604 case OP_oRR:
5605 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5606 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5607 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5608 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5609 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5610 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5611 case OP_oRND:
5612 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5613 case OP_RVC:
5614 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5615 break;
5616 /* Also accept generic coprocessor regs for unknown registers. */
5617 coproc_reg:
5618 po_reg_or_fail (REG_TYPE_CN);
5619 break;
c19d1205
ZW
5620 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5621 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5622 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5623 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5624 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5625 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5626 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5627 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5628 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5629 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5630 case OP_oRNQ:
5631 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5632 case OP_oRNDQ:
5633 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5634 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5635 case OP_oRNSDQ:
5636 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5637
5638 /* Neon scalar. Using an element size of 8 means that some invalid
5639 scalars are accepted here, so deal with those in later code. */
5640 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5641
5642 /* WARNING: We can expand to two operands here. This has the potential
5643 to totally confuse the backtracking mechanism! It will be OK at
5644 least as long as we don't try to use optional args as well,
5645 though. */
5646 case OP_NILO:
5647 {
5648 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5649 inst.operands[i].present = 1;
5287ad62
JB
5650 i++;
5651 skip_past_comma (&str);
5652 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5653 break;
5654 one_reg_only:
5655 /* Optional register operand was omitted. Unfortunately, it's in
5656 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5657 here (this is a bit grotty). */
5658 inst.operands[i] = inst.operands[i-1];
5659 inst.operands[i-1].present = 0;
5660 break;
5661 try_imm:
036dc3f7
PB
5662 /* There's a possibility of getting a 64-bit immediate here, so
5663 we need special handling. */
5664 if (parse_big_immediate (&str, i) == FAIL)
5665 {
5666 inst.error = _("immediate value is out of range");
5667 goto failure;
5668 }
5287ad62
JB
5669 }
5670 break;
5671
5672 case OP_RNDQ_I0:
5673 {
5674 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5675 break;
5676 try_imm0:
5677 po_imm_or_fail (0, 0, TRUE);
5678 }
5679 break;
5680
037e8744
JB
5681 case OP_RVSD_I0:
5682 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5683 break;
5684
5287ad62
JB
5685 case OP_RR_RNSC:
5686 {
5687 po_scalar_or_goto (8, try_rr);
5688 break;
5689 try_rr:
5690 po_reg_or_fail (REG_TYPE_RN);
5691 }
5692 break;
5693
037e8744
JB
5694 case OP_RNSDQ_RNSC:
5695 {
5696 po_scalar_or_goto (8, try_nsdq);
5697 break;
5698 try_nsdq:
5699 po_reg_or_fail (REG_TYPE_NSDQ);
5700 }
5701 break;
5702
5287ad62
JB
5703 case OP_RNDQ_RNSC:
5704 {
5705 po_scalar_or_goto (8, try_ndq);
5706 break;
5707 try_ndq:
5708 po_reg_or_fail (REG_TYPE_NDQ);
5709 }
5710 break;
5711
5712 case OP_RND_RNSC:
5713 {
5714 po_scalar_or_goto (8, try_vfd);
5715 break;
5716 try_vfd:
5717 po_reg_or_fail (REG_TYPE_VFD);
5718 }
5719 break;
5720
5721 case OP_VMOV:
5722 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5723 not careful then bad things might happen. */
5724 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5725 break;
5726
5727 case OP_RNDQ_IMVNb:
5728 {
5729 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5730 break;
5731 try_mvnimm:
5732 /* There's a possibility of getting a 64-bit immediate here, so
5733 we need special handling. */
5734 if (parse_big_immediate (&str, i) == FAIL)
5735 {
5736 inst.error = _("immediate value is out of range");
5737 goto failure;
5738 }
5739 }
5740 break;
5741
5742 case OP_RNDQ_I63b:
5743 {
5744 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5745 break;
5746 try_shimm:
5747 po_imm_or_fail (0, 63, TRUE);
5748 }
5749 break;
c19d1205
ZW
5750
5751 case OP_RRnpcb:
5752 po_char_or_fail ('[');
5753 po_reg_or_fail (REG_TYPE_RN);
5754 po_char_or_fail (']');
5755 break;
a737bd4d 5756
c19d1205 5757 case OP_RRw:
b6702015 5758 case OP_oRRw:
c19d1205
ZW
5759 po_reg_or_fail (REG_TYPE_RN);
5760 if (skip_past_char (&str, '!') == SUCCESS)
5761 inst.operands[i].writeback = 1;
5762 break;
5763
5764 /* Immediates */
5765 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5766 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5767 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5768 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5769 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5770 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5771 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5772 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5773 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5774 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5775 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5776 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5777
5778 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5779 case OP_oI7b:
5780 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5781 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5782 case OP_oI31b:
5783 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5784 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5785 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5786
5787 /* Immediate variants */
5788 case OP_oI255c:
5789 po_char_or_fail ('{');
5790 po_imm_or_fail (0, 255, TRUE);
5791 po_char_or_fail ('}');
5792 break;
5793
5794 case OP_I31w:
5795 /* The expression parser chokes on a trailing !, so we have
5796 to find it first and zap it. */
5797 {
5798 char *s = str;
5799 while (*s && *s != ',')
5800 s++;
5801 if (s[-1] == '!')
5802 {
5803 s[-1] = '\0';
5804 inst.operands[i].writeback = 1;
5805 }
5806 po_imm_or_fail (0, 31, TRUE);
5807 if (str == s - 1)
5808 str = s;
5809 }
5810 break;
5811
5812 /* Expressions */
5813 case OP_EXPi: EXPi:
5814 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5815 GE_OPT_PREFIX));
5816 break;
5817
5818 case OP_EXP:
5819 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5820 GE_NO_PREFIX));
5821 break;
5822
5823 case OP_EXPr: EXPr:
5824 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5825 GE_NO_PREFIX));
5826 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5827 {
c19d1205
ZW
5828 val = parse_reloc (&str);
5829 if (val == -1)
5830 {
5831 inst.error = _("unrecognized relocation suffix");
5832 goto failure;
5833 }
5834 else if (val != BFD_RELOC_UNUSED)
5835 {
5836 inst.operands[i].imm = val;
5837 inst.operands[i].hasreloc = 1;
5838 }
a737bd4d 5839 }
c19d1205 5840 break;
a737bd4d 5841
b6895b4f
PB
5842 /* Operand for MOVW or MOVT. */
5843 case OP_HALF:
5844 po_misc_or_fail (parse_half (&str));
5845 break;
5846
c19d1205
ZW
5847 /* Register or expression */
5848 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5849 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5850
c19d1205
ZW
5851 /* Register or immediate */
5852 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5853 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5854
c19d1205
ZW
5855 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5856 IF:
5857 if (!is_immediate_prefix (*str))
5858 goto bad_args;
5859 str++;
5860 val = parse_fpa_immediate (&str);
5861 if (val == FAIL)
5862 goto failure;
5863 /* FPA immediates are encoded as registers 8-15.
5864 parse_fpa_immediate has already applied the offset. */
5865 inst.operands[i].reg = val;
5866 inst.operands[i].isreg = 1;
5867 break;
09d92015 5868
2d447fca
JM
5869 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5870 I32z: po_imm_or_fail (0, 32, FALSE); break;
5871
c19d1205
ZW
5872 /* Two kinds of register */
5873 case OP_RIWR_RIWC:
5874 {
5875 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5876 if (!rege
5877 || (rege->type != REG_TYPE_MMXWR
5878 && rege->type != REG_TYPE_MMXWC
5879 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5880 {
5881 inst.error = _("iWMMXt data or control register expected");
5882 goto failure;
5883 }
5884 inst.operands[i].reg = rege->number;
5885 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5886 }
5887 break;
09d92015 5888
41adaa5c
JM
5889 case OP_RIWC_RIWG:
5890 {
5891 struct reg_entry *rege = arm_reg_parse_multi (&str);
5892 if (!rege
5893 || (rege->type != REG_TYPE_MMXWC
5894 && rege->type != REG_TYPE_MMXWCG))
5895 {
5896 inst.error = _("iWMMXt control register expected");
5897 goto failure;
5898 }
5899 inst.operands[i].reg = rege->number;
5900 inst.operands[i].isreg = 1;
5901 }
5902 break;
5903
c19d1205
ZW
5904 /* Misc */
5905 case OP_CPSF: val = parse_cps_flags (&str); break;
5906 case OP_ENDI: val = parse_endian_specifier (&str); break;
5907 case OP_oROR: val = parse_ror (&str); break;
5908 case OP_PSR: val = parse_psr (&str); break;
5909 case OP_COND: val = parse_cond (&str); break;
62b3e311 5910 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5911
037e8744
JB
5912 case OP_RVC_PSR:
5913 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5914 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5915 break;
5916 try_psr:
5917 val = parse_psr (&str);
5918 break;
5919
5920 case OP_APSR_RR:
5921 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5922 break;
5923 try_apsr:
5924 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5925 instruction). */
5926 if (strncasecmp (str, "APSR_", 5) == 0)
5927 {
5928 unsigned found = 0;
5929 str += 5;
5930 while (found < 15)
5931 switch (*str++)
5932 {
5933 case 'c': found = (found & 1) ? 16 : found | 1; break;
5934 case 'n': found = (found & 2) ? 16 : found | 2; break;
5935 case 'z': found = (found & 4) ? 16 : found | 4; break;
5936 case 'v': found = (found & 8) ? 16 : found | 8; break;
5937 default: found = 16;
5938 }
5939 if (found != 15)
5940 goto failure;
5941 inst.operands[i].isvec = 1;
5942 }
5943 else
5944 goto failure;
5945 break;
5946
92e90b6e
PB
5947 case OP_TB:
5948 po_misc_or_fail (parse_tb (&str));
5949 break;
5950
c19d1205
ZW
5951 /* Register lists */
5952 case OP_REGLST:
5953 val = parse_reg_list (&str);
5954 if (*str == '^')
5955 {
5956 inst.operands[1].writeback = 1;
5957 str++;
5958 }
5959 break;
09d92015 5960
c19d1205 5961 case OP_VRSLST:
5287ad62 5962 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5963 break;
09d92015 5964
c19d1205 5965 case OP_VRDLST:
5287ad62 5966 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5967 break;
a737bd4d 5968
037e8744
JB
5969 case OP_VRSDLST:
5970 /* Allow Q registers too. */
5971 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5972 REGLIST_NEON_D);
5973 if (val == FAIL)
5974 {
5975 inst.error = NULL;
5976 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5977 REGLIST_VFP_S);
5978 inst.operands[i].issingle = 1;
5979 }
5980 break;
5981
5287ad62
JB
5982 case OP_NRDLST:
5983 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5984 REGLIST_NEON_D);
5985 break;
5986
5987 case OP_NSTRLST:
dcbf9037
JB
5988 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5989 &inst.operands[i].vectype);
5287ad62
JB
5990 break;
5991
c19d1205
ZW
5992 /* Addressing modes */
5993 case OP_ADDR:
5994 po_misc_or_fail (parse_address (&str, i));
5995 break;
09d92015 5996
4962c51a
MS
5997 case OP_ADDRGLDR:
5998 po_misc_or_fail_no_backtrack (
5999 parse_address_group_reloc (&str, i, GROUP_LDR));
6000 break;
6001
6002 case OP_ADDRGLDRS:
6003 po_misc_or_fail_no_backtrack (
6004 parse_address_group_reloc (&str, i, GROUP_LDRS));
6005 break;
6006
6007 case OP_ADDRGLDC:
6008 po_misc_or_fail_no_backtrack (
6009 parse_address_group_reloc (&str, i, GROUP_LDC));
6010 break;
6011
c19d1205
ZW
6012 case OP_SH:
6013 po_misc_or_fail (parse_shifter_operand (&str, i));
6014 break;
09d92015 6015
4962c51a
MS
6016 case OP_SHG:
6017 po_misc_or_fail_no_backtrack (
6018 parse_shifter_operand_group_reloc (&str, i));
6019 break;
6020
c19d1205
ZW
6021 case OP_oSHll:
6022 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6023 break;
09d92015 6024
c19d1205
ZW
6025 case OP_oSHar:
6026 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6027 break;
09d92015 6028
c19d1205
ZW
6029 case OP_oSHllar:
6030 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6031 break;
09d92015 6032
c19d1205 6033 default:
bd3ba5d1 6034 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6035 }
09d92015 6036
c19d1205
ZW
6037 /* Various value-based sanity checks and shared operations. We
6038 do not signal immediate failures for the register constraints;
6039 this allows a syntax error to take precedence. */
6040 switch (upat[i])
6041 {
6042 case OP_oRRnpc:
6043 case OP_RRnpc:
6044 case OP_RRnpcb:
6045 case OP_RRw:
b6702015 6046 case OP_oRRw:
c19d1205
ZW
6047 case OP_RRnpc_I0:
6048 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6049 inst.error = BAD_PC;
6050 break;
09d92015 6051
c19d1205
ZW
6052 case OP_CPSF:
6053 case OP_ENDI:
6054 case OP_oROR:
6055 case OP_PSR:
037e8744 6056 case OP_RVC_PSR:
c19d1205 6057 case OP_COND:
62b3e311 6058 case OP_oBARRIER:
c19d1205
ZW
6059 case OP_REGLST:
6060 case OP_VRSLST:
6061 case OP_VRDLST:
037e8744 6062 case OP_VRSDLST:
5287ad62
JB
6063 case OP_NRDLST:
6064 case OP_NSTRLST:
c19d1205
ZW
6065 if (val == FAIL)
6066 goto failure;
6067 inst.operands[i].imm = val;
6068 break;
a737bd4d 6069
c19d1205
ZW
6070 default:
6071 break;
6072 }
09d92015 6073
c19d1205
ZW
6074 /* If we get here, this operand was successfully parsed. */
6075 inst.operands[i].present = 1;
6076 continue;
09d92015 6077
c19d1205 6078 bad_args:
09d92015 6079 inst.error = BAD_ARGS;
c19d1205
ZW
6080
6081 failure:
6082 if (!backtrack_pos)
d252fdde
PB
6083 {
6084 /* The parse routine should already have set inst.error, but set a
5f4273c7 6085 default here just in case. */
d252fdde
PB
6086 if (!inst.error)
6087 inst.error = _("syntax error");
6088 return FAIL;
6089 }
c19d1205
ZW
6090
6091 /* Do not backtrack over a trailing optional argument that
6092 absorbed some text. We will only fail again, with the
6093 'garbage following instruction' error message, which is
6094 probably less helpful than the current one. */
6095 if (backtrack_index == i && backtrack_pos != str
6096 && upat[i+1] == OP_stop)
d252fdde
PB
6097 {
6098 if (!inst.error)
6099 inst.error = _("syntax error");
6100 return FAIL;
6101 }
c19d1205
ZW
6102
6103 /* Try again, skipping the optional argument at backtrack_pos. */
6104 str = backtrack_pos;
6105 inst.error = backtrack_error;
6106 inst.operands[backtrack_index].present = 0;
6107 i = backtrack_index;
6108 backtrack_pos = 0;
09d92015 6109 }
09d92015 6110
c19d1205
ZW
6111 /* Check that we have parsed all the arguments. */
6112 if (*str != '\0' && !inst.error)
6113 inst.error = _("garbage following instruction");
09d92015 6114
c19d1205 6115 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6116}
6117
c19d1205
ZW
6118#undef po_char_or_fail
6119#undef po_reg_or_fail
6120#undef po_reg_or_goto
6121#undef po_imm_or_fail
5287ad62 6122#undef po_scalar_or_fail
c19d1205
ZW
6123\f
6124/* Shorthand macro for instruction encoding functions issuing errors. */
6125#define constraint(expr, err) do { \
6126 if (expr) \
6127 { \
6128 inst.error = err; \
6129 return; \
6130 } \
6131} while (0)
6132
fdfde340
JM
6133/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6134 instructions are unpredictable if these registers are used. This
6135 is the BadReg predicate in ARM's Thumb-2 documentation. */
6136#define reject_bad_reg(reg) \
6137 do \
6138 if (reg == REG_SP || reg == REG_PC) \
6139 { \
6140 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6141 return; \
6142 } \
6143 while (0)
6144
94206790
MM
6145/* If REG is R13 (the stack pointer), warn that its use is
6146 deprecated. */
6147#define warn_deprecated_sp(reg) \
6148 do \
6149 if (warn_on_deprecated && reg == REG_SP) \
6150 as_warn (_("use of r13 is deprecated")); \
6151 while (0)
6152
c19d1205
ZW
6153/* Functions for operand encoding. ARM, then Thumb. */
6154
6155#define rotate_left(v, n) (v << n | v >> (32 - n))
6156
6157/* If VAL can be encoded in the immediate field of an ARM instruction,
6158 return the encoded form. Otherwise, return FAIL. */
6159
6160static unsigned int
6161encode_arm_immediate (unsigned int val)
09d92015 6162{
c19d1205
ZW
6163 unsigned int a, i;
6164
6165 for (i = 0; i < 32; i += 2)
6166 if ((a = rotate_left (val, i)) <= 0xff)
6167 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6168
6169 return FAIL;
09d92015
MM
6170}
6171
c19d1205
ZW
6172/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6173 return the encoded form. Otherwise, return FAIL. */
6174static unsigned int
6175encode_thumb32_immediate (unsigned int val)
09d92015 6176{
c19d1205 6177 unsigned int a, i;
09d92015 6178
9c3c69f2 6179 if (val <= 0xff)
c19d1205 6180 return val;
a737bd4d 6181
9c3c69f2 6182 for (i = 1; i <= 24; i++)
09d92015 6183 {
9c3c69f2
PB
6184 a = val >> i;
6185 if ((val & ~(0xff << i)) == 0)
6186 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6187 }
a737bd4d 6188
c19d1205
ZW
6189 a = val & 0xff;
6190 if (val == ((a << 16) | a))
6191 return 0x100 | a;
6192 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6193 return 0x300 | a;
09d92015 6194
c19d1205
ZW
6195 a = val & 0xff00;
6196 if (val == ((a << 16) | a))
6197 return 0x200 | (a >> 8);
a737bd4d 6198
c19d1205 6199 return FAIL;
09d92015 6200}
5287ad62 6201/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6202
6203static void
5287ad62
JB
6204encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6205{
6206 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6207 && reg > 15)
6208 {
b1cc4aeb 6209 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6210 {
6211 if (thumb_mode)
6212 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6213 fpu_vfp_ext_d32);
5287ad62
JB
6214 else
6215 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6216 fpu_vfp_ext_d32);
5287ad62
JB
6217 }
6218 else
6219 {
dcbf9037 6220 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6221 return;
6222 }
6223 }
6224
c19d1205 6225 switch (pos)
09d92015 6226 {
c19d1205
ZW
6227 case VFP_REG_Sd:
6228 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6229 break;
6230
6231 case VFP_REG_Sn:
6232 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6233 break;
6234
6235 case VFP_REG_Sm:
6236 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6237 break;
6238
5287ad62
JB
6239 case VFP_REG_Dd:
6240 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6241 break;
5f4273c7 6242
5287ad62
JB
6243 case VFP_REG_Dn:
6244 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6245 break;
5f4273c7 6246
5287ad62
JB
6247 case VFP_REG_Dm:
6248 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6249 break;
6250
c19d1205
ZW
6251 default:
6252 abort ();
09d92015 6253 }
09d92015
MM
6254}
6255
c19d1205 6256/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6257 if any, is handled by md_apply_fix. */
09d92015 6258static void
c19d1205 6259encode_arm_shift (int i)
09d92015 6260{
c19d1205
ZW
6261 if (inst.operands[i].shift_kind == SHIFT_RRX)
6262 inst.instruction |= SHIFT_ROR << 5;
6263 else
09d92015 6264 {
c19d1205
ZW
6265 inst.instruction |= inst.operands[i].shift_kind << 5;
6266 if (inst.operands[i].immisreg)
6267 {
6268 inst.instruction |= SHIFT_BY_REG;
6269 inst.instruction |= inst.operands[i].imm << 8;
6270 }
6271 else
6272 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6273 }
c19d1205 6274}
09d92015 6275
c19d1205
ZW
6276static void
6277encode_arm_shifter_operand (int i)
6278{
6279 if (inst.operands[i].isreg)
09d92015 6280 {
c19d1205
ZW
6281 inst.instruction |= inst.operands[i].reg;
6282 encode_arm_shift (i);
09d92015 6283 }
c19d1205
ZW
6284 else
6285 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6286}
6287
c19d1205 6288/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6289static void
c19d1205 6290encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6291{
c19d1205
ZW
6292 assert (inst.operands[i].isreg);
6293 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6294
c19d1205 6295 if (inst.operands[i].preind)
09d92015 6296 {
c19d1205
ZW
6297 if (is_t)
6298 {
6299 inst.error = _("instruction does not accept preindexed addressing");
6300 return;
6301 }
6302 inst.instruction |= PRE_INDEX;
6303 if (inst.operands[i].writeback)
6304 inst.instruction |= WRITE_BACK;
09d92015 6305
c19d1205
ZW
6306 }
6307 else if (inst.operands[i].postind)
6308 {
6309 assert (inst.operands[i].writeback);
6310 if (is_t)
6311 inst.instruction |= WRITE_BACK;
6312 }
6313 else /* unindexed - only for coprocessor */
09d92015 6314 {
c19d1205 6315 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6316 return;
6317 }
6318
c19d1205
ZW
6319 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6320 && (((inst.instruction & 0x000f0000) >> 16)
6321 == ((inst.instruction & 0x0000f000) >> 12)))
6322 as_warn ((inst.instruction & LOAD_BIT)
6323 ? _("destination register same as write-back base")
6324 : _("source register same as write-back base"));
09d92015
MM
6325}
6326
c19d1205
ZW
6327/* inst.operands[i] was set up by parse_address. Encode it into an
6328 ARM-format mode 2 load or store instruction. If is_t is true,
6329 reject forms that cannot be used with a T instruction (i.e. not
6330 post-indexed). */
a737bd4d 6331static void
c19d1205 6332encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6333{
c19d1205 6334 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6335
c19d1205 6336 if (inst.operands[i].immisreg)
09d92015 6337 {
c19d1205
ZW
6338 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6339 inst.instruction |= inst.operands[i].imm;
6340 if (!inst.operands[i].negative)
6341 inst.instruction |= INDEX_UP;
6342 if (inst.operands[i].shifted)
6343 {
6344 if (inst.operands[i].shift_kind == SHIFT_RRX)
6345 inst.instruction |= SHIFT_ROR << 5;
6346 else
6347 {
6348 inst.instruction |= inst.operands[i].shift_kind << 5;
6349 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6350 }
6351 }
09d92015 6352 }
c19d1205 6353 else /* immediate offset in inst.reloc */
09d92015 6354 {
c19d1205
ZW
6355 if (inst.reloc.type == BFD_RELOC_UNUSED)
6356 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6357 }
09d92015
MM
6358}
6359
c19d1205
ZW
6360/* inst.operands[i] was set up by parse_address. Encode it into an
6361 ARM-format mode 3 load or store instruction. Reject forms that
6362 cannot be used with such instructions. If is_t is true, reject
6363 forms that cannot be used with a T instruction (i.e. not
6364 post-indexed). */
6365static void
6366encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6367{
c19d1205 6368 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6369 {
c19d1205
ZW
6370 inst.error = _("instruction does not accept scaled register index");
6371 return;
09d92015 6372 }
a737bd4d 6373
c19d1205 6374 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6375
c19d1205
ZW
6376 if (inst.operands[i].immisreg)
6377 {
6378 inst.instruction |= inst.operands[i].imm;
6379 if (!inst.operands[i].negative)
6380 inst.instruction |= INDEX_UP;
6381 }
6382 else /* immediate offset in inst.reloc */
6383 {
6384 inst.instruction |= HWOFFSET_IMM;
6385 if (inst.reloc.type == BFD_RELOC_UNUSED)
6386 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6387 }
a737bd4d
NC
6388}
6389
c19d1205
ZW
6390/* inst.operands[i] was set up by parse_address. Encode it into an
6391 ARM-format instruction. Reject all forms which cannot be encoded
6392 into a coprocessor load/store instruction. If wb_ok is false,
6393 reject use of writeback; if unind_ok is false, reject use of
6394 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6395 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6396 (in which case it is preserved). */
09d92015 6397
c19d1205
ZW
6398static int
6399encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6400{
c19d1205 6401 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6402
c19d1205 6403 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6404
c19d1205 6405 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6406 {
c19d1205
ZW
6407 assert (!inst.operands[i].writeback);
6408 if (!unind_ok)
6409 {
6410 inst.error = _("instruction does not support unindexed addressing");
6411 return FAIL;
6412 }
6413 inst.instruction |= inst.operands[i].imm;
6414 inst.instruction |= INDEX_UP;
6415 return SUCCESS;
09d92015 6416 }
a737bd4d 6417
c19d1205
ZW
6418 if (inst.operands[i].preind)
6419 inst.instruction |= PRE_INDEX;
a737bd4d 6420
c19d1205 6421 if (inst.operands[i].writeback)
09d92015 6422 {
c19d1205
ZW
6423 if (inst.operands[i].reg == REG_PC)
6424 {
6425 inst.error = _("pc may not be used with write-back");
6426 return FAIL;
6427 }
6428 if (!wb_ok)
6429 {
6430 inst.error = _("instruction does not support writeback");
6431 return FAIL;
6432 }
6433 inst.instruction |= WRITE_BACK;
09d92015 6434 }
a737bd4d 6435
c19d1205
ZW
6436 if (reloc_override)
6437 inst.reloc.type = reloc_override;
4962c51a
MS
6438 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6439 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6440 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6441 {
6442 if (thumb_mode)
6443 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6444 else
6445 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6446 }
6447
c19d1205
ZW
6448 return SUCCESS;
6449}
a737bd4d 6450
c19d1205
ZW
6451/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6452 Determine whether it can be performed with a move instruction; if
6453 it can, convert inst.instruction to that move instruction and
6454 return 1; if it can't, convert inst.instruction to a literal-pool
6455 load and return 0. If this is not a valid thing to do in the
6456 current context, set inst.error and return 1.
a737bd4d 6457
c19d1205
ZW
6458 inst.operands[i] describes the destination register. */
6459
6460static int
6461move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6462{
53365c0d
PB
6463 unsigned long tbit;
6464
6465 if (thumb_p)
6466 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6467 else
6468 tbit = LOAD_BIT;
6469
6470 if ((inst.instruction & tbit) == 0)
09d92015 6471 {
c19d1205
ZW
6472 inst.error = _("invalid pseudo operation");
6473 return 1;
09d92015 6474 }
c19d1205 6475 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6476 {
6477 inst.error = _("constant expression expected");
c19d1205 6478 return 1;
09d92015 6479 }
c19d1205 6480 if (inst.reloc.exp.X_op == O_constant)
09d92015 6481 {
c19d1205
ZW
6482 if (thumb_p)
6483 {
53365c0d 6484 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6485 {
6486 /* This can be done with a mov(1) instruction. */
6487 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6488 inst.instruction |= inst.reloc.exp.X_add_number;
6489 return 1;
6490 }
6491 }
6492 else
6493 {
6494 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6495 if (value != FAIL)
6496 {
6497 /* This can be done with a mov instruction. */
6498 inst.instruction &= LITERAL_MASK;
6499 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6500 inst.instruction |= value & 0xfff;
6501 return 1;
6502 }
09d92015 6503
c19d1205
ZW
6504 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6505 if (value != FAIL)
6506 {
6507 /* This can be done with a mvn instruction. */
6508 inst.instruction &= LITERAL_MASK;
6509 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6510 inst.instruction |= value & 0xfff;
6511 return 1;
6512 }
6513 }
09d92015
MM
6514 }
6515
c19d1205
ZW
6516 if (add_to_lit_pool () == FAIL)
6517 {
6518 inst.error = _("literal pool insertion failed");
6519 return 1;
6520 }
6521 inst.operands[1].reg = REG_PC;
6522 inst.operands[1].isreg = 1;
6523 inst.operands[1].preind = 1;
6524 inst.reloc.pc_rel = 1;
6525 inst.reloc.type = (thumb_p
6526 ? BFD_RELOC_ARM_THUMB_OFFSET
6527 : (mode_3
6528 ? BFD_RELOC_ARM_HWLITERAL
6529 : BFD_RELOC_ARM_LITERAL));
6530 return 0;
09d92015
MM
6531}
6532
5f4273c7 6533/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6534 First some generics; their names are taken from the conventional
6535 bit positions for register arguments in ARM format instructions. */
09d92015 6536
a737bd4d 6537static void
c19d1205 6538do_noargs (void)
09d92015 6539{
c19d1205 6540}
a737bd4d 6541
c19d1205
ZW
6542static void
6543do_rd (void)
6544{
6545 inst.instruction |= inst.operands[0].reg << 12;
6546}
a737bd4d 6547
c19d1205
ZW
6548static void
6549do_rd_rm (void)
6550{
6551 inst.instruction |= inst.operands[0].reg << 12;
6552 inst.instruction |= inst.operands[1].reg;
6553}
09d92015 6554
c19d1205
ZW
6555static void
6556do_rd_rn (void)
6557{
6558 inst.instruction |= inst.operands[0].reg << 12;
6559 inst.instruction |= inst.operands[1].reg << 16;
6560}
a737bd4d 6561
c19d1205
ZW
6562static void
6563do_rn_rd (void)
6564{
6565 inst.instruction |= inst.operands[0].reg << 16;
6566 inst.instruction |= inst.operands[1].reg << 12;
6567}
09d92015 6568
c19d1205
ZW
6569static void
6570do_rd_rm_rn (void)
6571{
9a64e435 6572 unsigned Rn = inst.operands[2].reg;
708587a4 6573 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6574 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6575 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6576 _("Rn must not overlap other operands"));
c19d1205
ZW
6577 inst.instruction |= inst.operands[0].reg << 12;
6578 inst.instruction |= inst.operands[1].reg;
9a64e435 6579 inst.instruction |= Rn << 16;
c19d1205 6580}
09d92015 6581
c19d1205
ZW
6582static void
6583do_rd_rn_rm (void)
6584{
6585 inst.instruction |= inst.operands[0].reg << 12;
6586 inst.instruction |= inst.operands[1].reg << 16;
6587 inst.instruction |= inst.operands[2].reg;
6588}
a737bd4d 6589
c19d1205
ZW
6590static void
6591do_rm_rd_rn (void)
6592{
6593 inst.instruction |= inst.operands[0].reg;
6594 inst.instruction |= inst.operands[1].reg << 12;
6595 inst.instruction |= inst.operands[2].reg << 16;
6596}
09d92015 6597
c19d1205
ZW
6598static void
6599do_imm0 (void)
6600{
6601 inst.instruction |= inst.operands[0].imm;
6602}
09d92015 6603
c19d1205
ZW
6604static void
6605do_rd_cpaddr (void)
6606{
6607 inst.instruction |= inst.operands[0].reg << 12;
6608 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6609}
a737bd4d 6610
c19d1205
ZW
6611/* ARM instructions, in alphabetical order by function name (except
6612 that wrapper functions appear immediately after the function they
6613 wrap). */
09d92015 6614
c19d1205
ZW
6615/* This is a pseudo-op of the form "adr rd, label" to be converted
6616 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6617
6618static void
c19d1205 6619do_adr (void)
09d92015 6620{
c19d1205 6621 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6622
c19d1205
ZW
6623 /* Frag hacking will turn this into a sub instruction if the offset turns
6624 out to be negative. */
6625 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6626 inst.reloc.pc_rel = 1;
2fc8bdac 6627 inst.reloc.exp.X_add_number -= 8;
c19d1205 6628}
b99bd4ef 6629
c19d1205
ZW
6630/* This is a pseudo-op of the form "adrl rd, label" to be converted
6631 into a relative address of the form:
6632 add rd, pc, #low(label-.-8)"
6633 add rd, rd, #high(label-.-8)" */
b99bd4ef 6634
c19d1205
ZW
6635static void
6636do_adrl (void)
6637{
6638 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6639
c19d1205
ZW
6640 /* Frag hacking will turn this into a sub instruction if the offset turns
6641 out to be negative. */
6642 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6643 inst.reloc.pc_rel = 1;
6644 inst.size = INSN_SIZE * 2;
2fc8bdac 6645 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6646}
6647
b99bd4ef 6648static void
c19d1205 6649do_arit (void)
b99bd4ef 6650{
c19d1205
ZW
6651 if (!inst.operands[1].present)
6652 inst.operands[1].reg = inst.operands[0].reg;
6653 inst.instruction |= inst.operands[0].reg << 12;
6654 inst.instruction |= inst.operands[1].reg << 16;
6655 encode_arm_shifter_operand (2);
6656}
b99bd4ef 6657
62b3e311
PB
6658static void
6659do_barrier (void)
6660{
6661 if (inst.operands[0].present)
6662 {
6663 constraint ((inst.instruction & 0xf0) != 0x40
6664 && inst.operands[0].imm != 0xf,
bd3ba5d1 6665 _("bad barrier type"));
62b3e311
PB
6666 inst.instruction |= inst.operands[0].imm;
6667 }
6668 else
6669 inst.instruction |= 0xf;
6670}
6671
c19d1205
ZW
6672static void
6673do_bfc (void)
6674{
6675 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6676 constraint (msb > 32, _("bit-field extends past end of register"));
6677 /* The instruction encoding stores the LSB and MSB,
6678 not the LSB and width. */
6679 inst.instruction |= inst.operands[0].reg << 12;
6680 inst.instruction |= inst.operands[1].imm << 7;
6681 inst.instruction |= (msb - 1) << 16;
6682}
b99bd4ef 6683
c19d1205
ZW
6684static void
6685do_bfi (void)
6686{
6687 unsigned int msb;
b99bd4ef 6688
c19d1205
ZW
6689 /* #0 in second position is alternative syntax for bfc, which is
6690 the same instruction but with REG_PC in the Rm field. */
6691 if (!inst.operands[1].isreg)
6692 inst.operands[1].reg = REG_PC;
b99bd4ef 6693
c19d1205
ZW
6694 msb = inst.operands[2].imm + inst.operands[3].imm;
6695 constraint (msb > 32, _("bit-field extends past end of register"));
6696 /* The instruction encoding stores the LSB and MSB,
6697 not the LSB and width. */
6698 inst.instruction |= inst.operands[0].reg << 12;
6699 inst.instruction |= inst.operands[1].reg;
6700 inst.instruction |= inst.operands[2].imm << 7;
6701 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6702}
6703
b99bd4ef 6704static void
c19d1205 6705do_bfx (void)
b99bd4ef 6706{
c19d1205
ZW
6707 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6708 _("bit-field extends past end of register"));
6709 inst.instruction |= inst.operands[0].reg << 12;
6710 inst.instruction |= inst.operands[1].reg;
6711 inst.instruction |= inst.operands[2].imm << 7;
6712 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6713}
09d92015 6714
c19d1205
ZW
6715/* ARM V5 breakpoint instruction (argument parse)
6716 BKPT <16 bit unsigned immediate>
6717 Instruction is not conditional.
6718 The bit pattern given in insns[] has the COND_ALWAYS condition,
6719 and it is an error if the caller tried to override that. */
b99bd4ef 6720
c19d1205
ZW
6721static void
6722do_bkpt (void)
6723{
6724 /* Top 12 of 16 bits to bits 19:8. */
6725 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6726
c19d1205
ZW
6727 /* Bottom 4 of 16 bits to bits 3:0. */
6728 inst.instruction |= inst.operands[0].imm & 0xf;
6729}
09d92015 6730
c19d1205
ZW
6731static void
6732encode_branch (int default_reloc)
6733{
6734 if (inst.operands[0].hasreloc)
6735 {
6736 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6737 _("the only suffix valid here is '(plt)'"));
6738 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6739 }
b99bd4ef 6740 else
c19d1205
ZW
6741 {
6742 inst.reloc.type = default_reloc;
c19d1205 6743 }
2fc8bdac 6744 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6745}
6746
b99bd4ef 6747static void
c19d1205 6748do_branch (void)
b99bd4ef 6749{
39b41c9c
PB
6750#ifdef OBJ_ELF
6751 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6752 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6753 else
6754#endif
6755 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6756}
6757
6758static void
6759do_bl (void)
6760{
6761#ifdef OBJ_ELF
6762 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6763 {
6764 if (inst.cond == COND_ALWAYS)
6765 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6766 else
6767 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6768 }
6769 else
6770#endif
6771 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6772}
b99bd4ef 6773
c19d1205
ZW
6774/* ARM V5 branch-link-exchange instruction (argument parse)
6775 BLX <target_addr> ie BLX(1)
6776 BLX{<condition>} <Rm> ie BLX(2)
6777 Unfortunately, there are two different opcodes for this mnemonic.
6778 So, the insns[].value is not used, and the code here zaps values
6779 into inst.instruction.
6780 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6781
c19d1205
ZW
6782static void
6783do_blx (void)
6784{
6785 if (inst.operands[0].isreg)
b99bd4ef 6786 {
c19d1205
ZW
6787 /* Arg is a register; the opcode provided by insns[] is correct.
6788 It is not illegal to do "blx pc", just useless. */
6789 if (inst.operands[0].reg == REG_PC)
6790 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6791
c19d1205
ZW
6792 inst.instruction |= inst.operands[0].reg;
6793 }
6794 else
b99bd4ef 6795 {
c19d1205
ZW
6796 /* Arg is an address; this instruction cannot be executed
6797 conditionally, and the opcode must be adjusted. */
6798 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6799 inst.instruction = 0xfa000000;
39b41c9c
PB
6800#ifdef OBJ_ELF
6801 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6802 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6803 else
6804#endif
6805 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6806 }
c19d1205
ZW
6807}
6808
6809static void
6810do_bx (void)
6811{
845b51d6
PB
6812 bfd_boolean want_reloc;
6813
c19d1205
ZW
6814 if (inst.operands[0].reg == REG_PC)
6815 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6816
c19d1205 6817 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6818 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6819 it is for ARMv4t or earlier. */
6820 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6821 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6822 want_reloc = TRUE;
6823
5ad34203 6824#ifdef OBJ_ELF
845b51d6 6825 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6826#endif
584206db 6827 want_reloc = FALSE;
845b51d6
PB
6828
6829 if (want_reloc)
6830 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6831}
6832
c19d1205
ZW
6833
6834/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6835
6836static void
c19d1205 6837do_bxj (void)
a737bd4d 6838{
c19d1205
ZW
6839 if (inst.operands[0].reg == REG_PC)
6840 as_tsktsk (_("use of r15 in bxj is not really useful"));
6841
6842 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6843}
6844
c19d1205
ZW
6845/* Co-processor data operation:
6846 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6847 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6848static void
6849do_cdp (void)
6850{
6851 inst.instruction |= inst.operands[0].reg << 8;
6852 inst.instruction |= inst.operands[1].imm << 20;
6853 inst.instruction |= inst.operands[2].reg << 12;
6854 inst.instruction |= inst.operands[3].reg << 16;
6855 inst.instruction |= inst.operands[4].reg;
6856 inst.instruction |= inst.operands[5].imm << 5;
6857}
a737bd4d
NC
6858
6859static void
c19d1205 6860do_cmp (void)
a737bd4d 6861{
c19d1205
ZW
6862 inst.instruction |= inst.operands[0].reg << 16;
6863 encode_arm_shifter_operand (1);
a737bd4d
NC
6864}
6865
c19d1205
ZW
6866/* Transfer between coprocessor and ARM registers.
6867 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6868 MRC2
6869 MCR{cond}
6870 MCR2
6871
6872 No special properties. */
09d92015
MM
6873
6874static void
c19d1205 6875do_co_reg (void)
09d92015 6876{
fdfde340
JM
6877 unsigned Rd;
6878
6879 Rd = inst.operands[2].reg;
6880 if (thumb_mode)
6881 {
6882 if (inst.instruction == 0xee000010
6883 || inst.instruction == 0xfe000010)
6884 /* MCR, MCR2 */
6885 reject_bad_reg (Rd);
6886 else
6887 /* MRC, MRC2 */
6888 constraint (Rd == REG_SP, BAD_SP);
6889 }
6890 else
6891 {
6892 /* MCR */
6893 if (inst.instruction == 0xe000010)
6894 constraint (Rd == REG_PC, BAD_PC);
6895 }
6896
6897
c19d1205
ZW
6898 inst.instruction |= inst.operands[0].reg << 8;
6899 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 6900 inst.instruction |= Rd << 12;
c19d1205
ZW
6901 inst.instruction |= inst.operands[3].reg << 16;
6902 inst.instruction |= inst.operands[4].reg;
6903 inst.instruction |= inst.operands[5].imm << 5;
6904}
09d92015 6905
c19d1205
ZW
6906/* Transfer between coprocessor register and pair of ARM registers.
6907 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6908 MCRR2
6909 MRRC{cond}
6910 MRRC2
b99bd4ef 6911
c19d1205 6912 Two XScale instructions are special cases of these:
09d92015 6913
c19d1205
ZW
6914 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6915 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6916
5f4273c7 6917 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6918
c19d1205
ZW
6919static void
6920do_co_reg2c (void)
6921{
fdfde340
JM
6922 unsigned Rd, Rn;
6923
6924 Rd = inst.operands[2].reg;
6925 Rn = inst.operands[3].reg;
6926
6927 if (thumb_mode)
6928 {
6929 reject_bad_reg (Rd);
6930 reject_bad_reg (Rn);
6931 }
6932 else
6933 {
6934 constraint (Rd == REG_PC, BAD_PC);
6935 constraint (Rn == REG_PC, BAD_PC);
6936 }
6937
c19d1205
ZW
6938 inst.instruction |= inst.operands[0].reg << 8;
6939 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
6940 inst.instruction |= Rd << 12;
6941 inst.instruction |= Rn << 16;
c19d1205 6942 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6943}
6944
c19d1205
ZW
6945static void
6946do_cpsi (void)
6947{
6948 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6949 if (inst.operands[1].present)
6950 {
6951 inst.instruction |= CPSI_MMOD;
6952 inst.instruction |= inst.operands[1].imm;
6953 }
c19d1205 6954}
b99bd4ef 6955
62b3e311
PB
6956static void
6957do_dbg (void)
6958{
6959 inst.instruction |= inst.operands[0].imm;
6960}
6961
b99bd4ef 6962static void
c19d1205 6963do_it (void)
b99bd4ef 6964{
c19d1205
ZW
6965 /* There is no IT instruction in ARM mode. We
6966 process it but do not generate code for it. */
6967 inst.size = 0;
09d92015 6968}
b99bd4ef 6969
09d92015 6970static void
c19d1205 6971do_ldmstm (void)
ea6ef066 6972{
c19d1205
ZW
6973 int base_reg = inst.operands[0].reg;
6974 int range = inst.operands[1].imm;
ea6ef066 6975
c19d1205
ZW
6976 inst.instruction |= base_reg << 16;
6977 inst.instruction |= range;
ea6ef066 6978
c19d1205
ZW
6979 if (inst.operands[1].writeback)
6980 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6981
c19d1205 6982 if (inst.operands[0].writeback)
ea6ef066 6983 {
c19d1205
ZW
6984 inst.instruction |= WRITE_BACK;
6985 /* Check for unpredictable uses of writeback. */
6986 if (inst.instruction & LOAD_BIT)
09d92015 6987 {
c19d1205
ZW
6988 /* Not allowed in LDM type 2. */
6989 if ((inst.instruction & LDM_TYPE_2_OR_3)
6990 && ((range & (1 << REG_PC)) == 0))
6991 as_warn (_("writeback of base register is UNPREDICTABLE"));
6992 /* Only allowed if base reg not in list for other types. */
6993 else if (range & (1 << base_reg))
6994 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6995 }
6996 else /* STM. */
6997 {
6998 /* Not allowed for type 2. */
6999 if (inst.instruction & LDM_TYPE_2_OR_3)
7000 as_warn (_("writeback of base register is UNPREDICTABLE"));
7001 /* Only allowed if base reg not in list, or first in list. */
7002 else if ((range & (1 << base_reg))
7003 && (range & ((1 << base_reg) - 1)))
7004 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7005 }
ea6ef066 7006 }
a737bd4d
NC
7007}
7008
c19d1205
ZW
7009/* ARMv5TE load-consecutive (argument parse)
7010 Mode is like LDRH.
7011
7012 LDRccD R, mode
7013 STRccD R, mode. */
7014
a737bd4d 7015static void
c19d1205 7016do_ldrd (void)
a737bd4d 7017{
c19d1205
ZW
7018 constraint (inst.operands[0].reg % 2 != 0,
7019 _("first destination register must be even"));
7020 constraint (inst.operands[1].present
7021 && inst.operands[1].reg != inst.operands[0].reg + 1,
7022 _("can only load two consecutive registers"));
7023 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7024 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7025
c19d1205
ZW
7026 if (!inst.operands[1].present)
7027 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7028
c19d1205 7029 if (inst.instruction & LOAD_BIT)
a737bd4d 7030 {
c19d1205
ZW
7031 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7032 register and the first register written; we have to diagnose
7033 overlap between the base and the second register written here. */
ea6ef066 7034
c19d1205
ZW
7035 if (inst.operands[2].reg == inst.operands[1].reg
7036 && (inst.operands[2].writeback || inst.operands[2].postind))
7037 as_warn (_("base register written back, and overlaps "
7038 "second destination register"));
b05fe5cf 7039
c19d1205
ZW
7040 /* For an index-register load, the index register must not overlap the
7041 destination (even if not write-back). */
7042 else if (inst.operands[2].immisreg
ca3f61f7
NC
7043 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7044 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7045 as_warn (_("index register overlaps destination register"));
b05fe5cf 7046 }
c19d1205
ZW
7047
7048 inst.instruction |= inst.operands[0].reg << 12;
7049 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7050}
7051
7052static void
c19d1205 7053do_ldrex (void)
b05fe5cf 7054{
c19d1205
ZW
7055 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7056 || inst.operands[1].postind || inst.operands[1].writeback
7057 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7058 || inst.operands[1].negative
7059 /* This can arise if the programmer has written
7060 strex rN, rM, foo
7061 or if they have mistakenly used a register name as the last
7062 operand, eg:
7063 strex rN, rM, rX
7064 It is very difficult to distinguish between these two cases
7065 because "rX" might actually be a label. ie the register
7066 name has been occluded by a symbol of the same name. So we
7067 just generate a general 'bad addressing mode' type error
7068 message and leave it up to the programmer to discover the
7069 true cause and fix their mistake. */
7070 || (inst.operands[1].reg == REG_PC),
7071 BAD_ADDR_MODE);
b05fe5cf 7072
c19d1205
ZW
7073 constraint (inst.reloc.exp.X_op != O_constant
7074 || inst.reloc.exp.X_add_number != 0,
7075 _("offset must be zero in ARM encoding"));
b05fe5cf 7076
c19d1205
ZW
7077 inst.instruction |= inst.operands[0].reg << 12;
7078 inst.instruction |= inst.operands[1].reg << 16;
7079 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7080}
7081
7082static void
c19d1205 7083do_ldrexd (void)
b05fe5cf 7084{
c19d1205
ZW
7085 constraint (inst.operands[0].reg % 2 != 0,
7086 _("even register required"));
7087 constraint (inst.operands[1].present
7088 && inst.operands[1].reg != inst.operands[0].reg + 1,
7089 _("can only load two consecutive registers"));
7090 /* If op 1 were present and equal to PC, this function wouldn't
7091 have been called in the first place. */
7092 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7093
c19d1205
ZW
7094 inst.instruction |= inst.operands[0].reg << 12;
7095 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7096}
7097
7098static void
c19d1205 7099do_ldst (void)
b05fe5cf 7100{
c19d1205
ZW
7101 inst.instruction |= inst.operands[0].reg << 12;
7102 if (!inst.operands[1].isreg)
7103 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7104 return;
c19d1205 7105 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7106}
7107
7108static void
c19d1205 7109do_ldstt (void)
b05fe5cf 7110{
c19d1205
ZW
7111 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7112 reject [Rn,...]. */
7113 if (inst.operands[1].preind)
b05fe5cf 7114 {
bd3ba5d1
NC
7115 constraint (inst.reloc.exp.X_op != O_constant
7116 || inst.reloc.exp.X_add_number != 0,
c19d1205 7117 _("this instruction requires a post-indexed address"));
b05fe5cf 7118
c19d1205
ZW
7119 inst.operands[1].preind = 0;
7120 inst.operands[1].postind = 1;
7121 inst.operands[1].writeback = 1;
b05fe5cf 7122 }
c19d1205
ZW
7123 inst.instruction |= inst.operands[0].reg << 12;
7124 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7125}
b05fe5cf 7126
c19d1205 7127/* Halfword and signed-byte load/store operations. */
b05fe5cf 7128
c19d1205
ZW
7129static void
7130do_ldstv4 (void)
7131{
7132 inst.instruction |= inst.operands[0].reg << 12;
7133 if (!inst.operands[1].isreg)
7134 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7135 return;
c19d1205 7136 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7137}
7138
7139static void
c19d1205 7140do_ldsttv4 (void)
b05fe5cf 7141{
c19d1205
ZW
7142 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7143 reject [Rn,...]. */
7144 if (inst.operands[1].preind)
b05fe5cf 7145 {
bd3ba5d1
NC
7146 constraint (inst.reloc.exp.X_op != O_constant
7147 || inst.reloc.exp.X_add_number != 0,
c19d1205 7148 _("this instruction requires a post-indexed address"));
b05fe5cf 7149
c19d1205
ZW
7150 inst.operands[1].preind = 0;
7151 inst.operands[1].postind = 1;
7152 inst.operands[1].writeback = 1;
b05fe5cf 7153 }
c19d1205
ZW
7154 inst.instruction |= inst.operands[0].reg << 12;
7155 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7156}
b05fe5cf 7157
c19d1205
ZW
7158/* Co-processor register load/store.
7159 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7160static void
7161do_lstc (void)
7162{
7163 inst.instruction |= inst.operands[0].reg << 8;
7164 inst.instruction |= inst.operands[1].reg << 12;
7165 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7166}
7167
b05fe5cf 7168static void
c19d1205 7169do_mlas (void)
b05fe5cf 7170{
8fb9d7b9 7171 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7172 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7173 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7174 && !(inst.instruction & 0x00400000))
8fb9d7b9 7175 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7176
c19d1205
ZW
7177 inst.instruction |= inst.operands[0].reg << 16;
7178 inst.instruction |= inst.operands[1].reg;
7179 inst.instruction |= inst.operands[2].reg << 8;
7180 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7181}
b05fe5cf 7182
c19d1205
ZW
7183static void
7184do_mov (void)
7185{
7186 inst.instruction |= inst.operands[0].reg << 12;
7187 encode_arm_shifter_operand (1);
7188}
b05fe5cf 7189
c19d1205
ZW
7190/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7191static void
7192do_mov16 (void)
7193{
b6895b4f
PB
7194 bfd_vma imm;
7195 bfd_boolean top;
7196
7197 top = (inst.instruction & 0x00400000) != 0;
7198 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7199 _(":lower16: not allowed this instruction"));
7200 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7201 _(":upper16: not allowed instruction"));
c19d1205 7202 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7203 if (inst.reloc.type == BFD_RELOC_UNUSED)
7204 {
7205 imm = inst.reloc.exp.X_add_number;
7206 /* The value is in two pieces: 0:11, 16:19. */
7207 inst.instruction |= (imm & 0x00000fff);
7208 inst.instruction |= (imm & 0x0000f000) << 4;
7209 }
b05fe5cf 7210}
b99bd4ef 7211
037e8744
JB
7212static void do_vfp_nsyn_opcode (const char *);
7213
7214static int
7215do_vfp_nsyn_mrs (void)
7216{
7217 if (inst.operands[0].isvec)
7218 {
7219 if (inst.operands[1].reg != 1)
7220 first_error (_("operand 1 must be FPSCR"));
7221 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7222 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7223 do_vfp_nsyn_opcode ("fmstat");
7224 }
7225 else if (inst.operands[1].isvec)
7226 do_vfp_nsyn_opcode ("fmrx");
7227 else
7228 return FAIL;
5f4273c7 7229
037e8744
JB
7230 return SUCCESS;
7231}
7232
7233static int
7234do_vfp_nsyn_msr (void)
7235{
7236 if (inst.operands[0].isvec)
7237 do_vfp_nsyn_opcode ("fmxr");
7238 else
7239 return FAIL;
7240
7241 return SUCCESS;
7242}
7243
b99bd4ef 7244static void
c19d1205 7245do_mrs (void)
b99bd4ef 7246{
037e8744
JB
7247 if (do_vfp_nsyn_mrs () == SUCCESS)
7248 return;
7249
c19d1205
ZW
7250 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7251 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7252 != (PSR_c|PSR_f),
7253 _("'CPSR' or 'SPSR' expected"));
7254 inst.instruction |= inst.operands[0].reg << 12;
7255 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7256}
b99bd4ef 7257
c19d1205
ZW
7258/* Two possible forms:
7259 "{C|S}PSR_<field>, Rm",
7260 "{C|S}PSR_f, #expression". */
b99bd4ef 7261
c19d1205
ZW
7262static void
7263do_msr (void)
7264{
037e8744
JB
7265 if (do_vfp_nsyn_msr () == SUCCESS)
7266 return;
7267
c19d1205
ZW
7268 inst.instruction |= inst.operands[0].imm;
7269 if (inst.operands[1].isreg)
7270 inst.instruction |= inst.operands[1].reg;
7271 else
b99bd4ef 7272 {
c19d1205
ZW
7273 inst.instruction |= INST_IMMEDIATE;
7274 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7275 inst.reloc.pc_rel = 0;
b99bd4ef 7276 }
b99bd4ef
NC
7277}
7278
c19d1205
ZW
7279static void
7280do_mul (void)
a737bd4d 7281{
c19d1205
ZW
7282 if (!inst.operands[2].present)
7283 inst.operands[2].reg = inst.operands[0].reg;
7284 inst.instruction |= inst.operands[0].reg << 16;
7285 inst.instruction |= inst.operands[1].reg;
7286 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7287
8fb9d7b9
MS
7288 if (inst.operands[0].reg == inst.operands[1].reg
7289 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7290 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7291}
7292
c19d1205
ZW
7293/* Long Multiply Parser
7294 UMULL RdLo, RdHi, Rm, Rs
7295 SMULL RdLo, RdHi, Rm, Rs
7296 UMLAL RdLo, RdHi, Rm, Rs
7297 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7298
7299static void
c19d1205 7300do_mull (void)
b99bd4ef 7301{
c19d1205
ZW
7302 inst.instruction |= inst.operands[0].reg << 12;
7303 inst.instruction |= inst.operands[1].reg << 16;
7304 inst.instruction |= inst.operands[2].reg;
7305 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7306
682b27ad
PB
7307 /* rdhi and rdlo must be different. */
7308 if (inst.operands[0].reg == inst.operands[1].reg)
7309 as_tsktsk (_("rdhi and rdlo must be different"));
7310
7311 /* rdhi, rdlo and rm must all be different before armv6. */
7312 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7313 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7314 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7315 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7316}
b99bd4ef 7317
c19d1205
ZW
7318static void
7319do_nop (void)
7320{
e7495e45
NS
7321 if (inst.operands[0].present
7322 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7323 {
7324 /* Architectural NOP hints are CPSR sets with no bits selected. */
7325 inst.instruction &= 0xf0000000;
e7495e45
NS
7326 inst.instruction |= 0x0320f000;
7327 if (inst.operands[0].present)
7328 inst.instruction |= inst.operands[0].imm;
c19d1205 7329 }
b99bd4ef
NC
7330}
7331
c19d1205
ZW
7332/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7333 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7334 Condition defaults to COND_ALWAYS.
7335 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7336
7337static void
c19d1205 7338do_pkhbt (void)
b99bd4ef 7339{
c19d1205
ZW
7340 inst.instruction |= inst.operands[0].reg << 12;
7341 inst.instruction |= inst.operands[1].reg << 16;
7342 inst.instruction |= inst.operands[2].reg;
7343 if (inst.operands[3].present)
7344 encode_arm_shift (3);
7345}
b99bd4ef 7346
c19d1205 7347/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7348
c19d1205
ZW
7349static void
7350do_pkhtb (void)
7351{
7352 if (!inst.operands[3].present)
b99bd4ef 7353 {
c19d1205
ZW
7354 /* If the shift specifier is omitted, turn the instruction
7355 into pkhbt rd, rm, rn. */
7356 inst.instruction &= 0xfff00010;
7357 inst.instruction |= inst.operands[0].reg << 12;
7358 inst.instruction |= inst.operands[1].reg;
7359 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7360 }
7361 else
7362 {
c19d1205
ZW
7363 inst.instruction |= inst.operands[0].reg << 12;
7364 inst.instruction |= inst.operands[1].reg << 16;
7365 inst.instruction |= inst.operands[2].reg;
7366 encode_arm_shift (3);
b99bd4ef
NC
7367 }
7368}
7369
c19d1205
ZW
7370/* ARMv5TE: Preload-Cache
7371
7372 PLD <addr_mode>
7373
7374 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7375
7376static void
c19d1205 7377do_pld (void)
b99bd4ef 7378{
c19d1205
ZW
7379 constraint (!inst.operands[0].isreg,
7380 _("'[' expected after PLD mnemonic"));
7381 constraint (inst.operands[0].postind,
7382 _("post-indexed expression used in preload instruction"));
7383 constraint (inst.operands[0].writeback,
7384 _("writeback used in preload instruction"));
7385 constraint (!inst.operands[0].preind,
7386 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7387 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7388}
b99bd4ef 7389
62b3e311
PB
7390/* ARMv7: PLI <addr_mode> */
7391static void
7392do_pli (void)
7393{
7394 constraint (!inst.operands[0].isreg,
7395 _("'[' expected after PLI mnemonic"));
7396 constraint (inst.operands[0].postind,
7397 _("post-indexed expression used in preload instruction"));
7398 constraint (inst.operands[0].writeback,
7399 _("writeback used in preload instruction"));
7400 constraint (!inst.operands[0].preind,
7401 _("unindexed addressing used in preload instruction"));
7402 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7403 inst.instruction &= ~PRE_INDEX;
7404}
7405
c19d1205
ZW
7406static void
7407do_push_pop (void)
7408{
7409 inst.operands[1] = inst.operands[0];
7410 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7411 inst.operands[0].isreg = 1;
7412 inst.operands[0].writeback = 1;
7413 inst.operands[0].reg = REG_SP;
7414 do_ldmstm ();
7415}
b99bd4ef 7416
c19d1205
ZW
7417/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7418 word at the specified address and the following word
7419 respectively.
7420 Unconditionally executed.
7421 Error if Rn is R15. */
b99bd4ef 7422
c19d1205
ZW
7423static void
7424do_rfe (void)
7425{
7426 inst.instruction |= inst.operands[0].reg << 16;
7427 if (inst.operands[0].writeback)
7428 inst.instruction |= WRITE_BACK;
7429}
b99bd4ef 7430
c19d1205 7431/* ARM V6 ssat (argument parse). */
b99bd4ef 7432
c19d1205
ZW
7433static void
7434do_ssat (void)
7435{
7436 inst.instruction |= inst.operands[0].reg << 12;
7437 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7438 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7439
c19d1205
ZW
7440 if (inst.operands[3].present)
7441 encode_arm_shift (3);
b99bd4ef
NC
7442}
7443
c19d1205 7444/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7445
7446static void
c19d1205 7447do_usat (void)
b99bd4ef 7448{
c19d1205
ZW
7449 inst.instruction |= inst.operands[0].reg << 12;
7450 inst.instruction |= inst.operands[1].imm << 16;
7451 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7452
c19d1205
ZW
7453 if (inst.operands[3].present)
7454 encode_arm_shift (3);
b99bd4ef
NC
7455}
7456
c19d1205 7457/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7458
7459static void
c19d1205 7460do_ssat16 (void)
09d92015 7461{
c19d1205
ZW
7462 inst.instruction |= inst.operands[0].reg << 12;
7463 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7464 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7465}
7466
c19d1205
ZW
7467static void
7468do_usat16 (void)
a737bd4d 7469{
c19d1205
ZW
7470 inst.instruction |= inst.operands[0].reg << 12;
7471 inst.instruction |= inst.operands[1].imm << 16;
7472 inst.instruction |= inst.operands[2].reg;
7473}
a737bd4d 7474
c19d1205
ZW
7475/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7476 preserving the other bits.
a737bd4d 7477
c19d1205
ZW
7478 setend <endian_specifier>, where <endian_specifier> is either
7479 BE or LE. */
a737bd4d 7480
c19d1205
ZW
7481static void
7482do_setend (void)
7483{
7484 if (inst.operands[0].imm)
7485 inst.instruction |= 0x200;
a737bd4d
NC
7486}
7487
7488static void
c19d1205 7489do_shift (void)
a737bd4d 7490{
c19d1205
ZW
7491 unsigned int Rm = (inst.operands[1].present
7492 ? inst.operands[1].reg
7493 : inst.operands[0].reg);
a737bd4d 7494
c19d1205
ZW
7495 inst.instruction |= inst.operands[0].reg << 12;
7496 inst.instruction |= Rm;
7497 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7498 {
c19d1205
ZW
7499 inst.instruction |= inst.operands[2].reg << 8;
7500 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7501 }
7502 else
c19d1205 7503 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7504}
7505
09d92015 7506static void
3eb17e6b 7507do_smc (void)
09d92015 7508{
3eb17e6b 7509 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7510 inst.reloc.pc_rel = 0;
09d92015
MM
7511}
7512
09d92015 7513static void
c19d1205 7514do_swi (void)
09d92015 7515{
c19d1205
ZW
7516 inst.reloc.type = BFD_RELOC_ARM_SWI;
7517 inst.reloc.pc_rel = 0;
09d92015
MM
7518}
7519
c19d1205
ZW
7520/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7521 SMLAxy{cond} Rd,Rm,Rs,Rn
7522 SMLAWy{cond} Rd,Rm,Rs,Rn
7523 Error if any register is R15. */
e16bb312 7524
c19d1205
ZW
7525static void
7526do_smla (void)
e16bb312 7527{
c19d1205
ZW
7528 inst.instruction |= inst.operands[0].reg << 16;
7529 inst.instruction |= inst.operands[1].reg;
7530 inst.instruction |= inst.operands[2].reg << 8;
7531 inst.instruction |= inst.operands[3].reg << 12;
7532}
a737bd4d 7533
c19d1205
ZW
7534/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7535 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7536 Error if any register is R15.
7537 Warning if Rdlo == Rdhi. */
a737bd4d 7538
c19d1205
ZW
7539static void
7540do_smlal (void)
7541{
7542 inst.instruction |= inst.operands[0].reg << 12;
7543 inst.instruction |= inst.operands[1].reg << 16;
7544 inst.instruction |= inst.operands[2].reg;
7545 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7546
c19d1205
ZW
7547 if (inst.operands[0].reg == inst.operands[1].reg)
7548 as_tsktsk (_("rdhi and rdlo must be different"));
7549}
a737bd4d 7550
c19d1205
ZW
7551/* ARM V5E (El Segundo) signed-multiply (argument parse)
7552 SMULxy{cond} Rd,Rm,Rs
7553 Error if any register is R15. */
a737bd4d 7554
c19d1205
ZW
7555static void
7556do_smul (void)
7557{
7558 inst.instruction |= inst.operands[0].reg << 16;
7559 inst.instruction |= inst.operands[1].reg;
7560 inst.instruction |= inst.operands[2].reg << 8;
7561}
a737bd4d 7562
b6702015
PB
7563/* ARM V6 srs (argument parse). The variable fields in the encoding are
7564 the same for both ARM and Thumb-2. */
a737bd4d 7565
c19d1205
ZW
7566static void
7567do_srs (void)
7568{
b6702015
PB
7569 int reg;
7570
7571 if (inst.operands[0].present)
7572 {
7573 reg = inst.operands[0].reg;
fdfde340 7574 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7575 }
7576 else
fdfde340 7577 reg = REG_SP;
b6702015
PB
7578
7579 inst.instruction |= reg << 16;
7580 inst.instruction |= inst.operands[1].imm;
7581 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7582 inst.instruction |= WRITE_BACK;
7583}
a737bd4d 7584
c19d1205 7585/* ARM V6 strex (argument parse). */
a737bd4d 7586
c19d1205
ZW
7587static void
7588do_strex (void)
7589{
7590 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7591 || inst.operands[2].postind || inst.operands[2].writeback
7592 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7593 || inst.operands[2].negative
7594 /* See comment in do_ldrex(). */
7595 || (inst.operands[2].reg == REG_PC),
7596 BAD_ADDR_MODE);
a737bd4d 7597
c19d1205
ZW
7598 constraint (inst.operands[0].reg == inst.operands[1].reg
7599 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7600
c19d1205
ZW
7601 constraint (inst.reloc.exp.X_op != O_constant
7602 || inst.reloc.exp.X_add_number != 0,
7603 _("offset must be zero in ARM encoding"));
a737bd4d 7604
c19d1205
ZW
7605 inst.instruction |= inst.operands[0].reg << 12;
7606 inst.instruction |= inst.operands[1].reg;
7607 inst.instruction |= inst.operands[2].reg << 16;
7608 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7609}
7610
7611static void
c19d1205 7612do_strexd (void)
e16bb312 7613{
c19d1205
ZW
7614 constraint (inst.operands[1].reg % 2 != 0,
7615 _("even register required"));
7616 constraint (inst.operands[2].present
7617 && inst.operands[2].reg != inst.operands[1].reg + 1,
7618 _("can only store two consecutive registers"));
7619 /* If op 2 were present and equal to PC, this function wouldn't
7620 have been called in the first place. */
7621 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7622
c19d1205
ZW
7623 constraint (inst.operands[0].reg == inst.operands[1].reg
7624 || inst.operands[0].reg == inst.operands[1].reg + 1
7625 || inst.operands[0].reg == inst.operands[3].reg,
7626 BAD_OVERLAP);
e16bb312 7627
c19d1205
ZW
7628 inst.instruction |= inst.operands[0].reg << 12;
7629 inst.instruction |= inst.operands[1].reg;
7630 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7631}
7632
c19d1205
ZW
7633/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7634 extends it to 32-bits, and adds the result to a value in another
7635 register. You can specify a rotation by 0, 8, 16, or 24 bits
7636 before extracting the 16-bit value.
7637 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7638 Condition defaults to COND_ALWAYS.
7639 Error if any register uses R15. */
7640
e16bb312 7641static void
c19d1205 7642do_sxtah (void)
e16bb312 7643{
c19d1205
ZW
7644 inst.instruction |= inst.operands[0].reg << 12;
7645 inst.instruction |= inst.operands[1].reg << 16;
7646 inst.instruction |= inst.operands[2].reg;
7647 inst.instruction |= inst.operands[3].imm << 10;
7648}
e16bb312 7649
c19d1205 7650/* ARM V6 SXTH.
e16bb312 7651
c19d1205
ZW
7652 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7653 Condition defaults to COND_ALWAYS.
7654 Error if any register uses R15. */
e16bb312
NC
7655
7656static void
c19d1205 7657do_sxth (void)
e16bb312 7658{
c19d1205
ZW
7659 inst.instruction |= inst.operands[0].reg << 12;
7660 inst.instruction |= inst.operands[1].reg;
7661 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7662}
c19d1205
ZW
7663\f
7664/* VFP instructions. In a logical order: SP variant first, monad
7665 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7666
7667static void
c19d1205 7668do_vfp_sp_monadic (void)
e16bb312 7669{
5287ad62
JB
7670 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7671 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7672}
7673
7674static void
c19d1205 7675do_vfp_sp_dyadic (void)
e16bb312 7676{
5287ad62
JB
7677 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7678 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7679 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7680}
7681
7682static void
c19d1205 7683do_vfp_sp_compare_z (void)
e16bb312 7684{
5287ad62 7685 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7686}
7687
7688static void
c19d1205 7689do_vfp_dp_sp_cvt (void)
e16bb312 7690{
5287ad62
JB
7691 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7692 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7693}
7694
7695static void
c19d1205 7696do_vfp_sp_dp_cvt (void)
e16bb312 7697{
5287ad62
JB
7698 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7700}
7701
7702static void
c19d1205 7703do_vfp_reg_from_sp (void)
e16bb312 7704{
c19d1205 7705 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7706 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7707}
7708
7709static void
c19d1205 7710do_vfp_reg2_from_sp2 (void)
e16bb312 7711{
c19d1205
ZW
7712 constraint (inst.operands[2].imm != 2,
7713 _("only two consecutive VFP SP registers allowed here"));
7714 inst.instruction |= inst.operands[0].reg << 12;
7715 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7716 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7717}
7718
7719static void
c19d1205 7720do_vfp_sp_from_reg (void)
e16bb312 7721{
5287ad62 7722 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7723 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7724}
7725
7726static void
c19d1205 7727do_vfp_sp2_from_reg2 (void)
e16bb312 7728{
c19d1205
ZW
7729 constraint (inst.operands[0].imm != 2,
7730 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7731 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7732 inst.instruction |= inst.operands[1].reg << 12;
7733 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7734}
7735
7736static void
c19d1205 7737do_vfp_sp_ldst (void)
e16bb312 7738{
5287ad62 7739 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7740 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7741}
7742
7743static void
c19d1205 7744do_vfp_dp_ldst (void)
e16bb312 7745{
5287ad62 7746 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7747 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7748}
7749
c19d1205 7750
e16bb312 7751static void
c19d1205 7752vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7753{
c19d1205
ZW
7754 if (inst.operands[0].writeback)
7755 inst.instruction |= WRITE_BACK;
7756 else
7757 constraint (ldstm_type != VFP_LDSTMIA,
7758 _("this addressing mode requires base-register writeback"));
7759 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7760 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7761 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7762}
7763
7764static void
c19d1205 7765vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7766{
c19d1205 7767 int count;
e16bb312 7768
c19d1205
ZW
7769 if (inst.operands[0].writeback)
7770 inst.instruction |= WRITE_BACK;
7771 else
7772 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7773 _("this addressing mode requires base-register writeback"));
e16bb312 7774
c19d1205 7775 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7776 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7777
c19d1205
ZW
7778 count = inst.operands[1].imm << 1;
7779 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7780 count += 1;
e16bb312 7781
c19d1205 7782 inst.instruction |= count;
e16bb312
NC
7783}
7784
7785static void
c19d1205 7786do_vfp_sp_ldstmia (void)
e16bb312 7787{
c19d1205 7788 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7789}
7790
7791static void
c19d1205 7792do_vfp_sp_ldstmdb (void)
e16bb312 7793{
c19d1205 7794 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7795}
7796
7797static void
c19d1205 7798do_vfp_dp_ldstmia (void)
e16bb312 7799{
c19d1205 7800 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7801}
7802
7803static void
c19d1205 7804do_vfp_dp_ldstmdb (void)
e16bb312 7805{
c19d1205 7806 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7807}
7808
7809static void
c19d1205 7810do_vfp_xp_ldstmia (void)
e16bb312 7811{
c19d1205
ZW
7812 vfp_dp_ldstm (VFP_LDSTMIAX);
7813}
e16bb312 7814
c19d1205
ZW
7815static void
7816do_vfp_xp_ldstmdb (void)
7817{
7818 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7819}
5287ad62
JB
7820
7821static void
7822do_vfp_dp_rd_rm (void)
7823{
7824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7825 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7826}
7827
7828static void
7829do_vfp_dp_rn_rd (void)
7830{
7831 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7832 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7833}
7834
7835static void
7836do_vfp_dp_rd_rn (void)
7837{
7838 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7839 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7840}
7841
7842static void
7843do_vfp_dp_rd_rn_rm (void)
7844{
7845 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7846 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7847 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7848}
7849
7850static void
7851do_vfp_dp_rd (void)
7852{
7853 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7854}
7855
7856static void
7857do_vfp_dp_rm_rd_rn (void)
7858{
7859 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7860 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7861 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7862}
7863
7864/* VFPv3 instructions. */
7865static void
7866do_vfp_sp_const (void)
7867{
7868 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7869 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7870 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7871}
7872
7873static void
7874do_vfp_dp_const (void)
7875{
7876 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7877 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7878 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7879}
7880
7881static void
7882vfp_conv (int srcsize)
7883{
7884 unsigned immbits = srcsize - inst.operands[1].imm;
7885 inst.instruction |= (immbits & 1) << 5;
7886 inst.instruction |= (immbits >> 1);
7887}
7888
7889static void
7890do_vfp_sp_conv_16 (void)
7891{
7892 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7893 vfp_conv (16);
7894}
7895
7896static void
7897do_vfp_dp_conv_16 (void)
7898{
7899 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7900 vfp_conv (16);
7901}
7902
7903static void
7904do_vfp_sp_conv_32 (void)
7905{
7906 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7907 vfp_conv (32);
7908}
7909
7910static void
7911do_vfp_dp_conv_32 (void)
7912{
7913 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7914 vfp_conv (32);
7915}
c19d1205
ZW
7916\f
7917/* FPA instructions. Also in a logical order. */
e16bb312 7918
c19d1205
ZW
7919static void
7920do_fpa_cmp (void)
7921{
7922 inst.instruction |= inst.operands[0].reg << 16;
7923 inst.instruction |= inst.operands[1].reg;
7924}
b99bd4ef
NC
7925
7926static void
c19d1205 7927do_fpa_ldmstm (void)
b99bd4ef 7928{
c19d1205
ZW
7929 inst.instruction |= inst.operands[0].reg << 12;
7930 switch (inst.operands[1].imm)
7931 {
7932 case 1: inst.instruction |= CP_T_X; break;
7933 case 2: inst.instruction |= CP_T_Y; break;
7934 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7935 case 4: break;
7936 default: abort ();
7937 }
b99bd4ef 7938
c19d1205
ZW
7939 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7940 {
7941 /* The instruction specified "ea" or "fd", so we can only accept
7942 [Rn]{!}. The instruction does not really support stacking or
7943 unstacking, so we have to emulate these by setting appropriate
7944 bits and offsets. */
7945 constraint (inst.reloc.exp.X_op != O_constant
7946 || inst.reloc.exp.X_add_number != 0,
7947 _("this instruction does not support indexing"));
b99bd4ef 7948
c19d1205
ZW
7949 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7950 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7951
c19d1205
ZW
7952 if (!(inst.instruction & INDEX_UP))
7953 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7954
c19d1205
ZW
7955 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7956 {
7957 inst.operands[2].preind = 0;
7958 inst.operands[2].postind = 1;
7959 }
7960 }
b99bd4ef 7961
c19d1205 7962 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7963}
c19d1205
ZW
7964\f
7965/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7966
c19d1205
ZW
7967static void
7968do_iwmmxt_tandorc (void)
7969{
7970 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7971}
b99bd4ef 7972
c19d1205
ZW
7973static void
7974do_iwmmxt_textrc (void)
7975{
7976 inst.instruction |= inst.operands[0].reg << 12;
7977 inst.instruction |= inst.operands[1].imm;
7978}
b99bd4ef
NC
7979
7980static void
c19d1205 7981do_iwmmxt_textrm (void)
b99bd4ef 7982{
c19d1205
ZW
7983 inst.instruction |= inst.operands[0].reg << 12;
7984 inst.instruction |= inst.operands[1].reg << 16;
7985 inst.instruction |= inst.operands[2].imm;
7986}
b99bd4ef 7987
c19d1205
ZW
7988static void
7989do_iwmmxt_tinsr (void)
7990{
7991 inst.instruction |= inst.operands[0].reg << 16;
7992 inst.instruction |= inst.operands[1].reg << 12;
7993 inst.instruction |= inst.operands[2].imm;
7994}
b99bd4ef 7995
c19d1205
ZW
7996static void
7997do_iwmmxt_tmia (void)
7998{
7999 inst.instruction |= inst.operands[0].reg << 5;
8000 inst.instruction |= inst.operands[1].reg;
8001 inst.instruction |= inst.operands[2].reg << 12;
8002}
b99bd4ef 8003
c19d1205
ZW
8004static void
8005do_iwmmxt_waligni (void)
8006{
8007 inst.instruction |= inst.operands[0].reg << 12;
8008 inst.instruction |= inst.operands[1].reg << 16;
8009 inst.instruction |= inst.operands[2].reg;
8010 inst.instruction |= inst.operands[3].imm << 20;
8011}
b99bd4ef 8012
2d447fca
JM
8013static void
8014do_iwmmxt_wmerge (void)
8015{
8016 inst.instruction |= inst.operands[0].reg << 12;
8017 inst.instruction |= inst.operands[1].reg << 16;
8018 inst.instruction |= inst.operands[2].reg;
8019 inst.instruction |= inst.operands[3].imm << 21;
8020}
8021
c19d1205
ZW
8022static void
8023do_iwmmxt_wmov (void)
8024{
8025 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8026 inst.instruction |= inst.operands[0].reg << 12;
8027 inst.instruction |= inst.operands[1].reg << 16;
8028 inst.instruction |= inst.operands[1].reg;
8029}
b99bd4ef 8030
c19d1205
ZW
8031static void
8032do_iwmmxt_wldstbh (void)
8033{
8f06b2d8 8034 int reloc;
c19d1205 8035 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8036 if (thumb_mode)
8037 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8038 else
8039 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8040 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8041}
8042
c19d1205
ZW
8043static void
8044do_iwmmxt_wldstw (void)
8045{
8046 /* RIWR_RIWC clears .isreg for a control register. */
8047 if (!inst.operands[0].isreg)
8048 {
8049 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8050 inst.instruction |= 0xf0000000;
8051 }
b99bd4ef 8052
c19d1205
ZW
8053 inst.instruction |= inst.operands[0].reg << 12;
8054 encode_arm_cp_address (1, TRUE, TRUE, 0);
8055}
b99bd4ef
NC
8056
8057static void
c19d1205 8058do_iwmmxt_wldstd (void)
b99bd4ef 8059{
c19d1205 8060 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8061 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8062 && inst.operands[1].immisreg)
8063 {
8064 inst.instruction &= ~0x1a000ff;
8065 inst.instruction |= (0xf << 28);
8066 if (inst.operands[1].preind)
8067 inst.instruction |= PRE_INDEX;
8068 if (!inst.operands[1].negative)
8069 inst.instruction |= INDEX_UP;
8070 if (inst.operands[1].writeback)
8071 inst.instruction |= WRITE_BACK;
8072 inst.instruction |= inst.operands[1].reg << 16;
8073 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8074 inst.instruction |= inst.operands[1].imm;
8075 }
8076 else
8077 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8078}
b99bd4ef 8079
c19d1205
ZW
8080static void
8081do_iwmmxt_wshufh (void)
8082{
8083 inst.instruction |= inst.operands[0].reg << 12;
8084 inst.instruction |= inst.operands[1].reg << 16;
8085 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8086 inst.instruction |= (inst.operands[2].imm & 0x0f);
8087}
b99bd4ef 8088
c19d1205
ZW
8089static void
8090do_iwmmxt_wzero (void)
8091{
8092 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8093 inst.instruction |= inst.operands[0].reg;
8094 inst.instruction |= inst.operands[0].reg << 12;
8095 inst.instruction |= inst.operands[0].reg << 16;
8096}
2d447fca
JM
8097
8098static void
8099do_iwmmxt_wrwrwr_or_imm5 (void)
8100{
8101 if (inst.operands[2].isreg)
8102 do_rd_rn_rm ();
8103 else {
8104 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8105 _("immediate operand requires iWMMXt2"));
8106 do_rd_rn ();
8107 if (inst.operands[2].imm == 0)
8108 {
8109 switch ((inst.instruction >> 20) & 0xf)
8110 {
8111 case 4:
8112 case 5:
8113 case 6:
5f4273c7 8114 case 7:
2d447fca
JM
8115 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8116 inst.operands[2].imm = 16;
8117 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8118 break;
8119 case 8:
8120 case 9:
8121 case 10:
8122 case 11:
8123 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8124 inst.operands[2].imm = 32;
8125 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8126 break;
8127 case 12:
8128 case 13:
8129 case 14:
8130 case 15:
8131 {
8132 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8133 unsigned long wrn;
8134 wrn = (inst.instruction >> 16) & 0xf;
8135 inst.instruction &= 0xff0fff0f;
8136 inst.instruction |= wrn;
8137 /* Bail out here; the instruction is now assembled. */
8138 return;
8139 }
8140 }
8141 }
8142 /* Map 32 -> 0, etc. */
8143 inst.operands[2].imm &= 0x1f;
8144 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8145 }
8146}
c19d1205
ZW
8147\f
8148/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8149 operations first, then control, shift, and load/store. */
b99bd4ef 8150
c19d1205 8151/* Insns like "foo X,Y,Z". */
b99bd4ef 8152
c19d1205
ZW
8153static void
8154do_mav_triple (void)
8155{
8156 inst.instruction |= inst.operands[0].reg << 16;
8157 inst.instruction |= inst.operands[1].reg;
8158 inst.instruction |= inst.operands[2].reg << 12;
8159}
b99bd4ef 8160
c19d1205
ZW
8161/* Insns like "foo W,X,Y,Z".
8162 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8163
c19d1205
ZW
8164static void
8165do_mav_quad (void)
8166{
8167 inst.instruction |= inst.operands[0].reg << 5;
8168 inst.instruction |= inst.operands[1].reg << 12;
8169 inst.instruction |= inst.operands[2].reg << 16;
8170 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8171}
8172
c19d1205
ZW
8173/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8174static void
8175do_mav_dspsc (void)
a737bd4d 8176{
c19d1205
ZW
8177 inst.instruction |= inst.operands[1].reg << 12;
8178}
a737bd4d 8179
c19d1205
ZW
8180/* Maverick shift immediate instructions.
8181 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8182 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8183
c19d1205
ZW
8184static void
8185do_mav_shift (void)
8186{
8187 int imm = inst.operands[2].imm;
a737bd4d 8188
c19d1205
ZW
8189 inst.instruction |= inst.operands[0].reg << 12;
8190 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8191
c19d1205
ZW
8192 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8193 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8194 Bit 4 should be 0. */
8195 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8196
c19d1205
ZW
8197 inst.instruction |= imm;
8198}
8199\f
8200/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8201
c19d1205
ZW
8202/* Xscale multiply-accumulate (argument parse)
8203 MIAcc acc0,Rm,Rs
8204 MIAPHcc acc0,Rm,Rs
8205 MIAxycc acc0,Rm,Rs. */
a737bd4d 8206
c19d1205
ZW
8207static void
8208do_xsc_mia (void)
8209{
8210 inst.instruction |= inst.operands[1].reg;
8211 inst.instruction |= inst.operands[2].reg << 12;
8212}
a737bd4d 8213
c19d1205 8214/* Xscale move-accumulator-register (argument parse)
a737bd4d 8215
c19d1205 8216 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8217
c19d1205
ZW
8218static void
8219do_xsc_mar (void)
8220{
8221 inst.instruction |= inst.operands[1].reg << 12;
8222 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8223}
8224
c19d1205 8225/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8226
c19d1205 8227 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8228
8229static void
c19d1205 8230do_xsc_mra (void)
b99bd4ef 8231{
c19d1205
ZW
8232 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8233 inst.instruction |= inst.operands[0].reg << 12;
8234 inst.instruction |= inst.operands[1].reg << 16;
8235}
8236\f
8237/* Encoding functions relevant only to Thumb. */
b99bd4ef 8238
c19d1205
ZW
8239/* inst.operands[i] is a shifted-register operand; encode
8240 it into inst.instruction in the format used by Thumb32. */
8241
8242static void
8243encode_thumb32_shifted_operand (int i)
8244{
8245 unsigned int value = inst.reloc.exp.X_add_number;
8246 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8247
9c3c69f2
PB
8248 constraint (inst.operands[i].immisreg,
8249 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8250 inst.instruction |= inst.operands[i].reg;
8251 if (shift == SHIFT_RRX)
8252 inst.instruction |= SHIFT_ROR << 4;
8253 else
b99bd4ef 8254 {
c19d1205
ZW
8255 constraint (inst.reloc.exp.X_op != O_constant,
8256 _("expression too complex"));
8257
8258 constraint (value > 32
8259 || (value == 32 && (shift == SHIFT_LSL
8260 || shift == SHIFT_ROR)),
8261 _("shift expression is too large"));
8262
8263 if (value == 0)
8264 shift = SHIFT_LSL;
8265 else if (value == 32)
8266 value = 0;
8267
8268 inst.instruction |= shift << 4;
8269 inst.instruction |= (value & 0x1c) << 10;
8270 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8271 }
c19d1205 8272}
b99bd4ef 8273
b99bd4ef 8274
c19d1205
ZW
8275/* inst.operands[i] was set up by parse_address. Encode it into a
8276 Thumb32 format load or store instruction. Reject forms that cannot
8277 be used with such instructions. If is_t is true, reject forms that
8278 cannot be used with a T instruction; if is_d is true, reject forms
8279 that cannot be used with a D instruction. */
b99bd4ef 8280
c19d1205
ZW
8281static void
8282encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8283{
8284 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8285
8286 constraint (!inst.operands[i].isreg,
53365c0d 8287 _("Instruction does not support =N addresses"));
b99bd4ef 8288
c19d1205
ZW
8289 inst.instruction |= inst.operands[i].reg << 16;
8290 if (inst.operands[i].immisreg)
b99bd4ef 8291 {
c19d1205
ZW
8292 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8293 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8294 constraint (inst.operands[i].negative,
8295 _("Thumb does not support negative register indexing"));
8296 constraint (inst.operands[i].postind,
8297 _("Thumb does not support register post-indexing"));
8298 constraint (inst.operands[i].writeback,
8299 _("Thumb does not support register indexing with writeback"));
8300 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8301 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8302
f40d1643 8303 inst.instruction |= inst.operands[i].imm;
c19d1205 8304 if (inst.operands[i].shifted)
b99bd4ef 8305 {
c19d1205
ZW
8306 constraint (inst.reloc.exp.X_op != O_constant,
8307 _("expression too complex"));
9c3c69f2
PB
8308 constraint (inst.reloc.exp.X_add_number < 0
8309 || inst.reloc.exp.X_add_number > 3,
c19d1205 8310 _("shift out of range"));
9c3c69f2 8311 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8312 }
8313 inst.reloc.type = BFD_RELOC_UNUSED;
8314 }
8315 else if (inst.operands[i].preind)
8316 {
8317 constraint (is_pc && inst.operands[i].writeback,
8318 _("cannot use writeback with PC-relative addressing"));
f40d1643 8319 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8320 _("cannot use writeback with this instruction"));
8321
8322 if (is_d)
8323 {
8324 inst.instruction |= 0x01000000;
8325 if (inst.operands[i].writeback)
8326 inst.instruction |= 0x00200000;
b99bd4ef 8327 }
c19d1205 8328 else
b99bd4ef 8329 {
c19d1205
ZW
8330 inst.instruction |= 0x00000c00;
8331 if (inst.operands[i].writeback)
8332 inst.instruction |= 0x00000100;
b99bd4ef 8333 }
c19d1205 8334 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8335 }
c19d1205 8336 else if (inst.operands[i].postind)
b99bd4ef 8337 {
c19d1205
ZW
8338 assert (inst.operands[i].writeback);
8339 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8340 constraint (is_t, _("cannot use post-indexing with this instruction"));
8341
8342 if (is_d)
8343 inst.instruction |= 0x00200000;
8344 else
8345 inst.instruction |= 0x00000900;
8346 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8347 }
8348 else /* unindexed - only for coprocessor */
8349 inst.error = _("instruction does not accept unindexed addressing");
8350}
8351
8352/* Table of Thumb instructions which exist in both 16- and 32-bit
8353 encodings (the latter only in post-V6T2 cores). The index is the
8354 value used in the insns table below. When there is more than one
8355 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8356 holds variant (1).
8357 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8358#define T16_32_TAB \
8359 X(adc, 4140, eb400000), \
8360 X(adcs, 4140, eb500000), \
8361 X(add, 1c00, eb000000), \
8362 X(adds, 1c00, eb100000), \
0110f2b8
PB
8363 X(addi, 0000, f1000000), \
8364 X(addis, 0000, f1100000), \
8365 X(add_pc,000f, f20f0000), \
8366 X(add_sp,000d, f10d0000), \
e9f89963 8367 X(adr, 000f, f20f0000), \
c19d1205
ZW
8368 X(and, 4000, ea000000), \
8369 X(ands, 4000, ea100000), \
8370 X(asr, 1000, fa40f000), \
8371 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8372 X(b, e000, f000b000), \
8373 X(bcond, d000, f0008000), \
c19d1205
ZW
8374 X(bic, 4380, ea200000), \
8375 X(bics, 4380, ea300000), \
8376 X(cmn, 42c0, eb100f00), \
8377 X(cmp, 2800, ebb00f00), \
8378 X(cpsie, b660, f3af8400), \
8379 X(cpsid, b670, f3af8600), \
8380 X(cpy, 4600, ea4f0000), \
155257ea 8381 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8382 X(eor, 4040, ea800000), \
8383 X(eors, 4040, ea900000), \
0110f2b8 8384 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8385 X(ldmia, c800, e8900000), \
8386 X(ldr, 6800, f8500000), \
8387 X(ldrb, 7800, f8100000), \
8388 X(ldrh, 8800, f8300000), \
8389 X(ldrsb, 5600, f9100000), \
8390 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8391 X(ldr_pc,4800, f85f0000), \
8392 X(ldr_pc2,4800, f85f0000), \
8393 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8394 X(lsl, 0000, fa00f000), \
8395 X(lsls, 0000, fa10f000), \
8396 X(lsr, 0800, fa20f000), \
8397 X(lsrs, 0800, fa30f000), \
8398 X(mov, 2000, ea4f0000), \
8399 X(movs, 2000, ea5f0000), \
8400 X(mul, 4340, fb00f000), \
8401 X(muls, 4340, ffffffff), /* no 32b muls */ \
8402 X(mvn, 43c0, ea6f0000), \
8403 X(mvns, 43c0, ea7f0000), \
8404 X(neg, 4240, f1c00000), /* rsb #0 */ \
8405 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8406 X(orr, 4300, ea400000), \
8407 X(orrs, 4300, ea500000), \
e9f89963
PB
8408 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8409 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8410 X(rev, ba00, fa90f080), \
8411 X(rev16, ba40, fa90f090), \
8412 X(revsh, bac0, fa90f0b0), \
8413 X(ror, 41c0, fa60f000), \
8414 X(rors, 41c0, fa70f000), \
8415 X(sbc, 4180, eb600000), \
8416 X(sbcs, 4180, eb700000), \
8417 X(stmia, c000, e8800000), \
8418 X(str, 6000, f8400000), \
8419 X(strb, 7000, f8000000), \
8420 X(strh, 8000, f8200000), \
0110f2b8 8421 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8422 X(sub, 1e00, eba00000), \
8423 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8424 X(subi, 8000, f1a00000), \
8425 X(subis, 8000, f1b00000), \
c19d1205
ZW
8426 X(sxtb, b240, fa4ff080), \
8427 X(sxth, b200, fa0ff080), \
8428 X(tst, 4200, ea100f00), \
8429 X(uxtb, b2c0, fa5ff080), \
8430 X(uxth, b280, fa1ff080), \
8431 X(nop, bf00, f3af8000), \
8432 X(yield, bf10, f3af8001), \
8433 X(wfe, bf20, f3af8002), \
8434 X(wfi, bf30, f3af8003), \
8435 X(sev, bf40, f3af9004), /* typo, 8004? */
8436
8437/* To catch errors in encoding functions, the codes are all offset by
8438 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8439 as 16-bit instructions. */
8440#define X(a,b,c) T_MNEM_##a
8441enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8442#undef X
8443
8444#define X(a,b,c) 0x##b
8445static const unsigned short thumb_op16[] = { T16_32_TAB };
8446#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8447#undef X
8448
8449#define X(a,b,c) 0x##c
8450static const unsigned int thumb_op32[] = { T16_32_TAB };
8451#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8452#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8453#undef X
8454#undef T16_32_TAB
8455
8456/* Thumb instruction encoders, in alphabetical order. */
8457
92e90b6e
PB
8458/* ADDW or SUBW. */
8459static void
8460do_t_add_sub_w (void)
8461{
8462 int Rd, Rn;
8463
8464 Rd = inst.operands[0].reg;
8465 Rn = inst.operands[1].reg;
8466
fdfde340
JM
8467 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8468 SP-{plus,minute}-immediate form of the instruction. */
8469 reject_bad_reg (Rd);
8470
92e90b6e
PB
8471 inst.instruction |= (Rn << 16) | (Rd << 8);
8472 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8473}
8474
c19d1205
ZW
8475/* Parse an add or subtract instruction. We get here with inst.instruction
8476 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8477
8478static void
8479do_t_add_sub (void)
8480{
8481 int Rd, Rs, Rn;
8482
8483 Rd = inst.operands[0].reg;
8484 Rs = (inst.operands[1].present
8485 ? inst.operands[1].reg /* Rd, Rs, foo */
8486 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8487
8488 if (unified_syntax)
8489 {
0110f2b8
PB
8490 bfd_boolean flags;
8491 bfd_boolean narrow;
8492 int opcode;
8493
8494 flags = (inst.instruction == T_MNEM_adds
8495 || inst.instruction == T_MNEM_subs);
8496 if (flags)
8497 narrow = (current_it_mask == 0);
8498 else
8499 narrow = (current_it_mask != 0);
c19d1205 8500 if (!inst.operands[2].isreg)
b99bd4ef 8501 {
16805f35
PB
8502 int add;
8503
fdfde340
JM
8504 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8505
16805f35
PB
8506 add = (inst.instruction == T_MNEM_add
8507 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8508 opcode = 0;
8509 if (inst.size_req != 4)
8510 {
0110f2b8
PB
8511 /* Attempt to use a narrow opcode, with relaxation if
8512 appropriate. */
8513 if (Rd == REG_SP && Rs == REG_SP && !flags)
8514 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8515 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8516 opcode = T_MNEM_add_sp;
8517 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8518 opcode = T_MNEM_add_pc;
8519 else if (Rd <= 7 && Rs <= 7 && narrow)
8520 {
8521 if (flags)
8522 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8523 else
8524 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8525 }
8526 if (opcode)
8527 {
8528 inst.instruction = THUMB_OP16(opcode);
8529 inst.instruction |= (Rd << 4) | Rs;
8530 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8531 if (inst.size_req != 2)
8532 inst.relax = opcode;
8533 }
8534 else
8535 constraint (inst.size_req == 2, BAD_HIREG);
8536 }
8537 if (inst.size_req == 4
8538 || (inst.size_req != 2 && !opcode))
8539 {
efd81785
PB
8540 if (Rd == REG_PC)
8541 {
fdfde340 8542 constraint (add, BAD_PC);
efd81785
PB
8543 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8544 _("only SUBS PC, LR, #const allowed"));
8545 constraint (inst.reloc.exp.X_op != O_constant,
8546 _("expression too complex"));
8547 constraint (inst.reloc.exp.X_add_number < 0
8548 || inst.reloc.exp.X_add_number > 0xff,
8549 _("immediate value out of range"));
8550 inst.instruction = T2_SUBS_PC_LR
8551 | inst.reloc.exp.X_add_number;
8552 inst.reloc.type = BFD_RELOC_UNUSED;
8553 return;
8554 }
8555 else if (Rs == REG_PC)
16805f35
PB
8556 {
8557 /* Always use addw/subw. */
8558 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8559 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8560 }
8561 else
8562 {
8563 inst.instruction = THUMB_OP32 (inst.instruction);
8564 inst.instruction = (inst.instruction & 0xe1ffffff)
8565 | 0x10000000;
8566 if (flags)
8567 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8568 else
8569 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8570 }
dc4503c6
PB
8571 inst.instruction |= Rd << 8;
8572 inst.instruction |= Rs << 16;
0110f2b8 8573 }
b99bd4ef 8574 }
c19d1205
ZW
8575 else
8576 {
8577 Rn = inst.operands[2].reg;
8578 /* See if we can do this with a 16-bit instruction. */
8579 if (!inst.operands[2].shifted && inst.size_req != 4)
8580 {
e27ec89e
PB
8581 if (Rd > 7 || Rs > 7 || Rn > 7)
8582 narrow = FALSE;
8583
8584 if (narrow)
c19d1205 8585 {
e27ec89e
PB
8586 inst.instruction = ((inst.instruction == T_MNEM_adds
8587 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8588 ? T_OPCODE_ADD_R3
8589 : T_OPCODE_SUB_R3);
8590 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8591 return;
8592 }
b99bd4ef 8593
7e806470 8594 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8595 {
7e806470
PB
8596 /* Thumb-1 cores (except v6-M) require at least one high
8597 register in a narrow non flag setting add. */
8598 if (Rd > 7 || Rn > 7
8599 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8600 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8601 {
7e806470
PB
8602 if (Rd == Rn)
8603 {
8604 Rn = Rs;
8605 Rs = Rd;
8606 }
c19d1205
ZW
8607 inst.instruction = T_OPCODE_ADD_HI;
8608 inst.instruction |= (Rd & 8) << 4;
8609 inst.instruction |= (Rd & 7);
8610 inst.instruction |= Rn << 3;
8611 return;
8612 }
c19d1205
ZW
8613 }
8614 }
fdfde340
JM
8615
8616 constraint (Rd == REG_PC, BAD_PC);
8617 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8618 constraint (Rs == REG_PC, BAD_PC);
8619 reject_bad_reg (Rn);
8620
c19d1205
ZW
8621 /* If we get here, it can't be done in 16 bits. */
8622 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8623 _("shift must be constant"));
8624 inst.instruction = THUMB_OP32 (inst.instruction);
8625 inst.instruction |= Rd << 8;
8626 inst.instruction |= Rs << 16;
8627 encode_thumb32_shifted_operand (2);
8628 }
8629 }
8630 else
8631 {
8632 constraint (inst.instruction == T_MNEM_adds
8633 || inst.instruction == T_MNEM_subs,
8634 BAD_THUMB32);
b99bd4ef 8635
c19d1205 8636 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8637 {
c19d1205
ZW
8638 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8639 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8640 BAD_HIREG);
8641
8642 inst.instruction = (inst.instruction == T_MNEM_add
8643 ? 0x0000 : 0x8000);
8644 inst.instruction |= (Rd << 4) | Rs;
8645 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8646 return;
8647 }
8648
c19d1205
ZW
8649 Rn = inst.operands[2].reg;
8650 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8651
c19d1205
ZW
8652 /* We now have Rd, Rs, and Rn set to registers. */
8653 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8654 {
c19d1205
ZW
8655 /* Can't do this for SUB. */
8656 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8657 inst.instruction = T_OPCODE_ADD_HI;
8658 inst.instruction |= (Rd & 8) << 4;
8659 inst.instruction |= (Rd & 7);
8660 if (Rs == Rd)
8661 inst.instruction |= Rn << 3;
8662 else if (Rn == Rd)
8663 inst.instruction |= Rs << 3;
8664 else
8665 constraint (1, _("dest must overlap one source register"));
8666 }
8667 else
8668 {
8669 inst.instruction = (inst.instruction == T_MNEM_add
8670 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8671 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8672 }
b99bd4ef 8673 }
b99bd4ef
NC
8674}
8675
c19d1205
ZW
8676static void
8677do_t_adr (void)
8678{
fdfde340
JM
8679 unsigned Rd;
8680
8681 Rd = inst.operands[0].reg;
8682 reject_bad_reg (Rd);
8683
8684 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
8685 {
8686 /* Defer to section relaxation. */
8687 inst.relax = inst.instruction;
8688 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 8689 inst.instruction |= Rd << 4;
0110f2b8
PB
8690 }
8691 else if (unified_syntax && inst.size_req != 2)
e9f89963 8692 {
0110f2b8 8693 /* Generate a 32-bit opcode. */
e9f89963 8694 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 8695 inst.instruction |= Rd << 8;
e9f89963
PB
8696 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8697 inst.reloc.pc_rel = 1;
8698 }
8699 else
8700 {
0110f2b8 8701 /* Generate a 16-bit opcode. */
e9f89963
PB
8702 inst.instruction = THUMB_OP16 (inst.instruction);
8703 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8704 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8705 inst.reloc.pc_rel = 1;
b99bd4ef 8706
fdfde340 8707 inst.instruction |= Rd << 4;
e9f89963 8708 }
c19d1205 8709}
b99bd4ef 8710
c19d1205
ZW
8711/* Arithmetic instructions for which there is just one 16-bit
8712 instruction encoding, and it allows only two low registers.
8713 For maximal compatibility with ARM syntax, we allow three register
8714 operands even when Thumb-32 instructions are not available, as long
8715 as the first two are identical. For instance, both "sbc r0,r1" and
8716 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8717static void
c19d1205 8718do_t_arit3 (void)
b99bd4ef 8719{
c19d1205 8720 int Rd, Rs, Rn;
b99bd4ef 8721
c19d1205
ZW
8722 Rd = inst.operands[0].reg;
8723 Rs = (inst.operands[1].present
8724 ? inst.operands[1].reg /* Rd, Rs, foo */
8725 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8726 Rn = inst.operands[2].reg;
b99bd4ef 8727
fdfde340
JM
8728 reject_bad_reg (Rd);
8729 reject_bad_reg (Rs);
8730 if (inst.operands[2].isreg)
8731 reject_bad_reg (Rn);
8732
c19d1205 8733 if (unified_syntax)
b99bd4ef 8734 {
c19d1205
ZW
8735 if (!inst.operands[2].isreg)
8736 {
8737 /* For an immediate, we always generate a 32-bit opcode;
8738 section relaxation will shrink it later if possible. */
8739 inst.instruction = THUMB_OP32 (inst.instruction);
8740 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8741 inst.instruction |= Rd << 8;
8742 inst.instruction |= Rs << 16;
8743 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8744 }
8745 else
8746 {
e27ec89e
PB
8747 bfd_boolean narrow;
8748
c19d1205 8749 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8750 if (THUMB_SETS_FLAGS (inst.instruction))
8751 narrow = current_it_mask == 0;
8752 else
8753 narrow = current_it_mask != 0;
8754
8755 if (Rd > 7 || Rn > 7 || Rs > 7)
8756 narrow = FALSE;
8757 if (inst.operands[2].shifted)
8758 narrow = FALSE;
8759 if (inst.size_req == 4)
8760 narrow = FALSE;
8761
8762 if (narrow
c19d1205
ZW
8763 && Rd == Rs)
8764 {
8765 inst.instruction = THUMB_OP16 (inst.instruction);
8766 inst.instruction |= Rd;
8767 inst.instruction |= Rn << 3;
8768 return;
8769 }
b99bd4ef 8770
c19d1205
ZW
8771 /* If we get here, it can't be done in 16 bits. */
8772 constraint (inst.operands[2].shifted
8773 && inst.operands[2].immisreg,
8774 _("shift must be constant"));
8775 inst.instruction = THUMB_OP32 (inst.instruction);
8776 inst.instruction |= Rd << 8;
8777 inst.instruction |= Rs << 16;
8778 encode_thumb32_shifted_operand (2);
8779 }
a737bd4d 8780 }
c19d1205 8781 else
b99bd4ef 8782 {
c19d1205
ZW
8783 /* On its face this is a lie - the instruction does set the
8784 flags. However, the only supported mnemonic in this mode
8785 says it doesn't. */
8786 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8787
c19d1205
ZW
8788 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8789 _("unshifted register required"));
8790 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8791 constraint (Rd != Rs,
8792 _("dest and source1 must be the same register"));
a737bd4d 8793
c19d1205
ZW
8794 inst.instruction = THUMB_OP16 (inst.instruction);
8795 inst.instruction |= Rd;
8796 inst.instruction |= Rn << 3;
b99bd4ef 8797 }
a737bd4d 8798}
b99bd4ef 8799
c19d1205
ZW
8800/* Similarly, but for instructions where the arithmetic operation is
8801 commutative, so we can allow either of them to be different from
8802 the destination operand in a 16-bit instruction. For instance, all
8803 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8804 accepted. */
8805static void
8806do_t_arit3c (void)
a737bd4d 8807{
c19d1205 8808 int Rd, Rs, Rn;
b99bd4ef 8809
c19d1205
ZW
8810 Rd = inst.operands[0].reg;
8811 Rs = (inst.operands[1].present
8812 ? inst.operands[1].reg /* Rd, Rs, foo */
8813 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8814 Rn = inst.operands[2].reg;
fdfde340
JM
8815
8816 reject_bad_reg (Rd);
8817 reject_bad_reg (Rs);
8818 if (inst.operands[2].isreg)
8819 reject_bad_reg (Rn);
a737bd4d 8820
c19d1205 8821 if (unified_syntax)
a737bd4d 8822 {
c19d1205 8823 if (!inst.operands[2].isreg)
b99bd4ef 8824 {
c19d1205
ZW
8825 /* For an immediate, we always generate a 32-bit opcode;
8826 section relaxation will shrink it later if possible. */
8827 inst.instruction = THUMB_OP32 (inst.instruction);
8828 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8829 inst.instruction |= Rd << 8;
8830 inst.instruction |= Rs << 16;
8831 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8832 }
c19d1205 8833 else
a737bd4d 8834 {
e27ec89e
PB
8835 bfd_boolean narrow;
8836
c19d1205 8837 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8838 if (THUMB_SETS_FLAGS (inst.instruction))
8839 narrow = current_it_mask == 0;
8840 else
8841 narrow = current_it_mask != 0;
8842
8843 if (Rd > 7 || Rn > 7 || Rs > 7)
8844 narrow = FALSE;
8845 if (inst.operands[2].shifted)
8846 narrow = FALSE;
8847 if (inst.size_req == 4)
8848 narrow = FALSE;
8849
8850 if (narrow)
a737bd4d 8851 {
c19d1205 8852 if (Rd == Rs)
a737bd4d 8853 {
c19d1205
ZW
8854 inst.instruction = THUMB_OP16 (inst.instruction);
8855 inst.instruction |= Rd;
8856 inst.instruction |= Rn << 3;
8857 return;
a737bd4d 8858 }
c19d1205 8859 if (Rd == Rn)
a737bd4d 8860 {
c19d1205
ZW
8861 inst.instruction = THUMB_OP16 (inst.instruction);
8862 inst.instruction |= Rd;
8863 inst.instruction |= Rs << 3;
8864 return;
a737bd4d
NC
8865 }
8866 }
c19d1205
ZW
8867
8868 /* If we get here, it can't be done in 16 bits. */
8869 constraint (inst.operands[2].shifted
8870 && inst.operands[2].immisreg,
8871 _("shift must be constant"));
8872 inst.instruction = THUMB_OP32 (inst.instruction);
8873 inst.instruction |= Rd << 8;
8874 inst.instruction |= Rs << 16;
8875 encode_thumb32_shifted_operand (2);
a737bd4d 8876 }
b99bd4ef 8877 }
c19d1205
ZW
8878 else
8879 {
8880 /* On its face this is a lie - the instruction does set the
8881 flags. However, the only supported mnemonic in this mode
8882 says it doesn't. */
8883 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8884
c19d1205
ZW
8885 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8886 _("unshifted register required"));
8887 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8888
8889 inst.instruction = THUMB_OP16 (inst.instruction);
8890 inst.instruction |= Rd;
8891
8892 if (Rd == Rs)
8893 inst.instruction |= Rn << 3;
8894 else if (Rd == Rn)
8895 inst.instruction |= Rs << 3;
8896 else
8897 constraint (1, _("dest must overlap one source register"));
8898 }
a737bd4d
NC
8899}
8900
62b3e311
PB
8901static void
8902do_t_barrier (void)
8903{
8904 if (inst.operands[0].present)
8905 {
8906 constraint ((inst.instruction & 0xf0) != 0x40
8907 && inst.operands[0].imm != 0xf,
bd3ba5d1 8908 _("bad barrier type"));
62b3e311
PB
8909 inst.instruction |= inst.operands[0].imm;
8910 }
8911 else
8912 inst.instruction |= 0xf;
8913}
8914
c19d1205
ZW
8915static void
8916do_t_bfc (void)
a737bd4d 8917{
fdfde340 8918 unsigned Rd;
c19d1205
ZW
8919 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8920 constraint (msb > 32, _("bit-field extends past end of register"));
8921 /* The instruction encoding stores the LSB and MSB,
8922 not the LSB and width. */
fdfde340
JM
8923 Rd = inst.operands[0].reg;
8924 reject_bad_reg (Rd);
8925 inst.instruction |= Rd << 8;
c19d1205
ZW
8926 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8927 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8928 inst.instruction |= msb - 1;
b99bd4ef
NC
8929}
8930
c19d1205
ZW
8931static void
8932do_t_bfi (void)
b99bd4ef 8933{
fdfde340 8934 int Rd, Rn;
c19d1205 8935 unsigned int msb;
b99bd4ef 8936
fdfde340
JM
8937 Rd = inst.operands[0].reg;
8938 reject_bad_reg (Rd);
8939
c19d1205
ZW
8940 /* #0 in second position is alternative syntax for bfc, which is
8941 the same instruction but with REG_PC in the Rm field. */
8942 if (!inst.operands[1].isreg)
fdfde340
JM
8943 Rn = REG_PC;
8944 else
8945 {
8946 Rn = inst.operands[1].reg;
8947 reject_bad_reg (Rn);
8948 }
b99bd4ef 8949
c19d1205
ZW
8950 msb = inst.operands[2].imm + inst.operands[3].imm;
8951 constraint (msb > 32, _("bit-field extends past end of register"));
8952 /* The instruction encoding stores the LSB and MSB,
8953 not the LSB and width. */
fdfde340
JM
8954 inst.instruction |= Rd << 8;
8955 inst.instruction |= Rn << 16;
c19d1205
ZW
8956 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8957 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8958 inst.instruction |= msb - 1;
b99bd4ef
NC
8959}
8960
c19d1205
ZW
8961static void
8962do_t_bfx (void)
b99bd4ef 8963{
fdfde340
JM
8964 unsigned Rd, Rn;
8965
8966 Rd = inst.operands[0].reg;
8967 Rn = inst.operands[1].reg;
8968
8969 reject_bad_reg (Rd);
8970 reject_bad_reg (Rn);
8971
c19d1205
ZW
8972 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8973 _("bit-field extends past end of register"));
fdfde340
JM
8974 inst.instruction |= Rd << 8;
8975 inst.instruction |= Rn << 16;
c19d1205
ZW
8976 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8977 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8978 inst.instruction |= inst.operands[3].imm - 1;
8979}
b99bd4ef 8980
c19d1205
ZW
8981/* ARM V5 Thumb BLX (argument parse)
8982 BLX <target_addr> which is BLX(1)
8983 BLX <Rm> which is BLX(2)
8984 Unfortunately, there are two different opcodes for this mnemonic.
8985 So, the insns[].value is not used, and the code here zaps values
8986 into inst.instruction.
b99bd4ef 8987
c19d1205
ZW
8988 ??? How to take advantage of the additional two bits of displacement
8989 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8990
c19d1205
ZW
8991static void
8992do_t_blx (void)
8993{
dfa9f0d5 8994 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8995 if (inst.operands[0].isreg)
fdfde340
JM
8996 {
8997 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8998 /* We have a register, so this is BLX(2). */
8999 inst.instruction |= inst.operands[0].reg << 3;
9000 }
b99bd4ef
NC
9001 else
9002 {
c19d1205 9003 /* No register. This must be BLX(1). */
2fc8bdac 9004 inst.instruction = 0xf000e800;
00adf2d4 9005 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9006 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9007 }
9008}
9009
c19d1205
ZW
9010static void
9011do_t_branch (void)
b99bd4ef 9012{
0110f2b8 9013 int opcode;
dfa9f0d5
PB
9014 int cond;
9015
9016 if (current_it_mask)
9017 {
9018 /* Conditional branches inside IT blocks are encoded as unconditional
9019 branches. */
9020 cond = COND_ALWAYS;
9021 /* A branch must be the last instruction in an IT block. */
9022 constraint (current_it_mask != 0x10, BAD_BRANCH);
9023 }
9024 else
9025 cond = inst.cond;
9026
9027 if (cond != COND_ALWAYS)
0110f2b8
PB
9028 opcode = T_MNEM_bcond;
9029 else
9030 opcode = inst.instruction;
9031
9032 if (unified_syntax && inst.size_req == 4)
c19d1205 9033 {
0110f2b8 9034 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9035 if (cond == COND_ALWAYS)
0110f2b8 9036 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9037 else
9038 {
dfa9f0d5
PB
9039 assert (cond != 0xF);
9040 inst.instruction |= cond << 22;
c19d1205
ZW
9041 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9042 }
9043 }
b99bd4ef
NC
9044 else
9045 {
0110f2b8 9046 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9047 if (cond == COND_ALWAYS)
c19d1205
ZW
9048 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9049 else
b99bd4ef 9050 {
dfa9f0d5 9051 inst.instruction |= cond << 8;
c19d1205 9052 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9053 }
0110f2b8
PB
9054 /* Allow section relaxation. */
9055 if (unified_syntax && inst.size_req != 2)
9056 inst.relax = opcode;
b99bd4ef 9057 }
c19d1205
ZW
9058
9059 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9060}
9061
9062static void
c19d1205 9063do_t_bkpt (void)
b99bd4ef 9064{
dfa9f0d5
PB
9065 constraint (inst.cond != COND_ALWAYS,
9066 _("instruction is always unconditional"));
c19d1205 9067 if (inst.operands[0].present)
b99bd4ef 9068 {
c19d1205
ZW
9069 constraint (inst.operands[0].imm > 255,
9070 _("immediate value out of range"));
9071 inst.instruction |= inst.operands[0].imm;
b99bd4ef 9072 }
b99bd4ef
NC
9073}
9074
9075static void
c19d1205 9076do_t_branch23 (void)
b99bd4ef 9077{
dfa9f0d5 9078 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 9079 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9080 inst.reloc.pc_rel = 1;
9081
4343666d 9082#if defined(OBJ_COFF)
c19d1205
ZW
9083 /* If the destination of the branch is a defined symbol which does not have
9084 the THUMB_FUNC attribute, then we must be calling a function which has
9085 the (interfacearm) attribute. We look for the Thumb entry point to that
9086 function and change the branch to refer to that function instead. */
9087 if ( inst.reloc.exp.X_op == O_symbol
9088 && inst.reloc.exp.X_add_symbol != NULL
9089 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9090 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9091 inst.reloc.exp.X_add_symbol =
9092 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9093#endif
90e4755a
RE
9094}
9095
9096static void
c19d1205 9097do_t_bx (void)
90e4755a 9098{
dfa9f0d5 9099 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
9100 inst.instruction |= inst.operands[0].reg << 3;
9101 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9102 should cause the alignment to be checked once it is known. This is
9103 because BX PC only works if the instruction is word aligned. */
9104}
90e4755a 9105
c19d1205
ZW
9106static void
9107do_t_bxj (void)
9108{
fdfde340 9109 int Rm;
90e4755a 9110
fdfde340
JM
9111 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9112 Rm = inst.operands[0].reg;
9113 reject_bad_reg (Rm);
9114 inst.instruction |= Rm << 16;
90e4755a
RE
9115}
9116
9117static void
c19d1205 9118do_t_clz (void)
90e4755a 9119{
fdfde340
JM
9120 unsigned Rd;
9121 unsigned Rm;
9122
9123 Rd = inst.operands[0].reg;
9124 Rm = inst.operands[1].reg;
9125
9126 reject_bad_reg (Rd);
9127 reject_bad_reg (Rm);
9128
9129 inst.instruction |= Rd << 8;
9130 inst.instruction |= Rm << 16;
9131 inst.instruction |= Rm;
c19d1205 9132}
90e4755a 9133
dfa9f0d5
PB
9134static void
9135do_t_cps (void)
9136{
9137 constraint (current_it_mask, BAD_NOT_IT);
9138 inst.instruction |= inst.operands[0].imm;
9139}
9140
c19d1205
ZW
9141static void
9142do_t_cpsi (void)
9143{
dfa9f0d5 9144 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9145 if (unified_syntax
62b3e311
PB
9146 && (inst.operands[1].present || inst.size_req == 4)
9147 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9148 {
c19d1205
ZW
9149 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9150 inst.instruction = 0xf3af8000;
9151 inst.instruction |= imod << 9;
9152 inst.instruction |= inst.operands[0].imm << 5;
9153 if (inst.operands[1].present)
9154 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9155 }
c19d1205 9156 else
90e4755a 9157 {
62b3e311
PB
9158 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9159 && (inst.operands[0].imm & 4),
9160 _("selected processor does not support 'A' form "
9161 "of this instruction"));
9162 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9163 _("Thumb does not support the 2-argument "
9164 "form of this instruction"));
9165 inst.instruction |= inst.operands[0].imm;
90e4755a 9166 }
90e4755a
RE
9167}
9168
c19d1205
ZW
9169/* THUMB CPY instruction (argument parse). */
9170
90e4755a 9171static void
c19d1205 9172do_t_cpy (void)
90e4755a 9173{
c19d1205 9174 if (inst.size_req == 4)
90e4755a 9175 {
c19d1205
ZW
9176 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9177 inst.instruction |= inst.operands[0].reg << 8;
9178 inst.instruction |= inst.operands[1].reg;
90e4755a 9179 }
c19d1205 9180 else
90e4755a 9181 {
c19d1205
ZW
9182 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9183 inst.instruction |= (inst.operands[0].reg & 0x7);
9184 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9185 }
90e4755a
RE
9186}
9187
90e4755a 9188static void
25fe350b 9189do_t_cbz (void)
90e4755a 9190{
dfa9f0d5 9191 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9192 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9193 inst.instruction |= inst.operands[0].reg;
9194 inst.reloc.pc_rel = 1;
9195 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9196}
90e4755a 9197
62b3e311
PB
9198static void
9199do_t_dbg (void)
9200{
9201 inst.instruction |= inst.operands[0].imm;
9202}
9203
9204static void
9205do_t_div (void)
9206{
fdfde340
JM
9207 unsigned Rd, Rn, Rm;
9208
9209 Rd = inst.operands[0].reg;
9210 Rn = (inst.operands[1].present
9211 ? inst.operands[1].reg : Rd);
9212 Rm = inst.operands[2].reg;
9213
9214 reject_bad_reg (Rd);
9215 reject_bad_reg (Rn);
9216 reject_bad_reg (Rm);
9217
9218 inst.instruction |= Rd << 8;
9219 inst.instruction |= Rn << 16;
9220 inst.instruction |= Rm;
62b3e311
PB
9221}
9222
c19d1205
ZW
9223static void
9224do_t_hint (void)
9225{
9226 if (unified_syntax && inst.size_req == 4)
9227 inst.instruction = THUMB_OP32 (inst.instruction);
9228 else
9229 inst.instruction = THUMB_OP16 (inst.instruction);
9230}
90e4755a 9231
c19d1205
ZW
9232static void
9233do_t_it (void)
9234{
9235 unsigned int cond = inst.operands[0].imm;
e27ec89e 9236
dfa9f0d5 9237 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9238 current_it_mask = (inst.instruction & 0xf) | 0x10;
9239 current_cc = cond;
9240
9241 /* If the condition is a negative condition, invert the mask. */
c19d1205 9242 if ((cond & 0x1) == 0x0)
90e4755a 9243 {
c19d1205 9244 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9245
c19d1205
ZW
9246 if ((mask & 0x7) == 0)
9247 /* no conversion needed */;
9248 else if ((mask & 0x3) == 0)
e27ec89e
PB
9249 mask ^= 0x8;
9250 else if ((mask & 0x1) == 0)
9251 mask ^= 0xC;
c19d1205 9252 else
e27ec89e 9253 mask ^= 0xE;
90e4755a 9254
e27ec89e
PB
9255 inst.instruction &= 0xfff0;
9256 inst.instruction |= mask;
c19d1205 9257 }
90e4755a 9258
c19d1205
ZW
9259 inst.instruction |= cond << 4;
9260}
90e4755a 9261
3c707909
PB
9262/* Helper function used for both push/pop and ldm/stm. */
9263static void
9264encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9265{
9266 bfd_boolean load;
9267
9268 load = (inst.instruction & (1 << 20)) != 0;
9269
9270 if (mask & (1 << 13))
9271 inst.error = _("SP not allowed in register list");
9272 if (load)
9273 {
9274 if (mask & (1 << 14)
9275 && mask & (1 << 15))
9276 inst.error = _("LR and PC should not both be in register list");
9277
9278 if ((mask & (1 << base)) != 0
9279 && writeback)
9280 as_warn (_("base register should not be in register list "
9281 "when written back"));
9282 }
9283 else
9284 {
9285 if (mask & (1 << 15))
9286 inst.error = _("PC not allowed in register list");
9287
9288 if (mask & (1 << base))
9289 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9290 }
9291
9292 if ((mask & (mask - 1)) == 0)
9293 {
9294 /* Single register transfers implemented as str/ldr. */
9295 if (writeback)
9296 {
9297 if (inst.instruction & (1 << 23))
9298 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9299 else
9300 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9301 }
9302 else
9303 {
9304 if (inst.instruction & (1 << 23))
9305 inst.instruction = 0x00800000; /* ia -> [base] */
9306 else
9307 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9308 }
9309
9310 inst.instruction |= 0xf8400000;
9311 if (load)
9312 inst.instruction |= 0x00100000;
9313
5f4273c7 9314 mask = ffs (mask) - 1;
3c707909
PB
9315 mask <<= 12;
9316 }
9317 else if (writeback)
9318 inst.instruction |= WRITE_BACK;
9319
9320 inst.instruction |= mask;
9321 inst.instruction |= base << 16;
9322}
9323
c19d1205
ZW
9324static void
9325do_t_ldmstm (void)
9326{
9327 /* This really doesn't seem worth it. */
9328 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9329 _("expression too complex"));
9330 constraint (inst.operands[1].writeback,
9331 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9332
c19d1205
ZW
9333 if (unified_syntax)
9334 {
3c707909
PB
9335 bfd_boolean narrow;
9336 unsigned mask;
9337
9338 narrow = FALSE;
c19d1205
ZW
9339 /* See if we can use a 16-bit instruction. */
9340 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9341 && inst.size_req != 4
3c707909 9342 && !(inst.operands[1].imm & ~0xff))
90e4755a 9343 {
3c707909 9344 mask = 1 << inst.operands[0].reg;
90e4755a 9345
3c707909
PB
9346 if (inst.operands[0].reg <= 7
9347 && (inst.instruction == T_MNEM_stmia
9348 ? inst.operands[0].writeback
9349 : (inst.operands[0].writeback
9350 == !(inst.operands[1].imm & mask))))
90e4755a 9351 {
3c707909
PB
9352 if (inst.instruction == T_MNEM_stmia
9353 && (inst.operands[1].imm & mask)
9354 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9355 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9356 inst.operands[0].reg);
3c707909
PB
9357
9358 inst.instruction = THUMB_OP16 (inst.instruction);
9359 inst.instruction |= inst.operands[0].reg << 8;
9360 inst.instruction |= inst.operands[1].imm;
9361 narrow = TRUE;
90e4755a 9362 }
3c707909
PB
9363 else if (inst.operands[0] .reg == REG_SP
9364 && inst.operands[0].writeback)
90e4755a 9365 {
3c707909
PB
9366 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9367 ? T_MNEM_push : T_MNEM_pop);
9368 inst.instruction |= inst.operands[1].imm;
9369 narrow = TRUE;
90e4755a 9370 }
3c707909
PB
9371 }
9372
9373 if (!narrow)
9374 {
c19d1205
ZW
9375 if (inst.instruction < 0xffff)
9376 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9377
5f4273c7
NC
9378 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9379 inst.operands[0].writeback);
90e4755a
RE
9380 }
9381 }
c19d1205 9382 else
90e4755a 9383 {
c19d1205
ZW
9384 constraint (inst.operands[0].reg > 7
9385 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9386 constraint (inst.instruction != T_MNEM_ldmia
9387 && inst.instruction != T_MNEM_stmia,
9388 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9389 if (inst.instruction == T_MNEM_stmia)
f03698e6 9390 {
c19d1205
ZW
9391 if (!inst.operands[0].writeback)
9392 as_warn (_("this instruction will write back the base register"));
9393 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9394 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9395 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9396 inst.operands[0].reg);
f03698e6 9397 }
c19d1205 9398 else
90e4755a 9399 {
c19d1205
ZW
9400 if (!inst.operands[0].writeback
9401 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9402 as_warn (_("this instruction will write back the base register"));
9403 else if (inst.operands[0].writeback
9404 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9405 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9406 }
9407
c19d1205
ZW
9408 inst.instruction = THUMB_OP16 (inst.instruction);
9409 inst.instruction |= inst.operands[0].reg << 8;
9410 inst.instruction |= inst.operands[1].imm;
9411 }
9412}
e28cd48c 9413
c19d1205
ZW
9414static void
9415do_t_ldrex (void)
9416{
9417 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9418 || inst.operands[1].postind || inst.operands[1].writeback
9419 || inst.operands[1].immisreg || inst.operands[1].shifted
9420 || inst.operands[1].negative,
01cfc07f 9421 BAD_ADDR_MODE);
e28cd48c 9422
c19d1205
ZW
9423 inst.instruction |= inst.operands[0].reg << 12;
9424 inst.instruction |= inst.operands[1].reg << 16;
9425 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9426}
e28cd48c 9427
c19d1205
ZW
9428static void
9429do_t_ldrexd (void)
9430{
9431 if (!inst.operands[1].present)
1cac9012 9432 {
c19d1205
ZW
9433 constraint (inst.operands[0].reg == REG_LR,
9434 _("r14 not allowed as first register "
9435 "when second register is omitted"));
9436 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9437 }
c19d1205
ZW
9438 constraint (inst.operands[0].reg == inst.operands[1].reg,
9439 BAD_OVERLAP);
b99bd4ef 9440
c19d1205
ZW
9441 inst.instruction |= inst.operands[0].reg << 12;
9442 inst.instruction |= inst.operands[1].reg << 8;
9443 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9444}
9445
9446static void
c19d1205 9447do_t_ldst (void)
b99bd4ef 9448{
0110f2b8
PB
9449 unsigned long opcode;
9450 int Rn;
9451
9452 opcode = inst.instruction;
c19d1205 9453 if (unified_syntax)
b99bd4ef 9454 {
53365c0d
PB
9455 if (!inst.operands[1].isreg)
9456 {
9457 if (opcode <= 0xffff)
9458 inst.instruction = THUMB_OP32 (opcode);
9459 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9460 return;
9461 }
0110f2b8
PB
9462 if (inst.operands[1].isreg
9463 && !inst.operands[1].writeback
c19d1205
ZW
9464 && !inst.operands[1].shifted && !inst.operands[1].postind
9465 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9466 && opcode <= 0xffff
9467 && inst.size_req != 4)
c19d1205 9468 {
0110f2b8
PB
9469 /* Insn may have a 16-bit form. */
9470 Rn = inst.operands[1].reg;
9471 if (inst.operands[1].immisreg)
9472 {
9473 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9474 /* [Rn, Rik] */
0110f2b8
PB
9475 if (Rn <= 7 && inst.operands[1].imm <= 7)
9476 goto op16;
9477 }
9478 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9479 && opcode != T_MNEM_ldrsb)
9480 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9481 || (Rn == REG_SP && opcode == T_MNEM_str))
9482 {
9483 /* [Rn, #const] */
9484 if (Rn > 7)
9485 {
9486 if (Rn == REG_PC)
9487 {
9488 if (inst.reloc.pc_rel)
9489 opcode = T_MNEM_ldr_pc2;
9490 else
9491 opcode = T_MNEM_ldr_pc;
9492 }
9493 else
9494 {
9495 if (opcode == T_MNEM_ldr)
9496 opcode = T_MNEM_ldr_sp;
9497 else
9498 opcode = T_MNEM_str_sp;
9499 }
9500 inst.instruction = inst.operands[0].reg << 8;
9501 }
9502 else
9503 {
9504 inst.instruction = inst.operands[0].reg;
9505 inst.instruction |= inst.operands[1].reg << 3;
9506 }
9507 inst.instruction |= THUMB_OP16 (opcode);
9508 if (inst.size_req == 2)
9509 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9510 else
9511 inst.relax = opcode;
9512 return;
9513 }
c19d1205 9514 }
0110f2b8
PB
9515 /* Definitely a 32-bit variant. */
9516 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9517 inst.instruction |= inst.operands[0].reg << 12;
9518 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9519 return;
9520 }
9521
c19d1205
ZW
9522 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9523
9524 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9525 {
c19d1205
ZW
9526 /* Only [Rn,Rm] is acceptable. */
9527 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9528 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9529 || inst.operands[1].postind || inst.operands[1].shifted
9530 || inst.operands[1].negative,
9531 _("Thumb does not support this addressing mode"));
9532 inst.instruction = THUMB_OP16 (inst.instruction);
9533 goto op16;
b99bd4ef 9534 }
5f4273c7 9535
c19d1205
ZW
9536 inst.instruction = THUMB_OP16 (inst.instruction);
9537 if (!inst.operands[1].isreg)
9538 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9539 return;
b99bd4ef 9540
c19d1205
ZW
9541 constraint (!inst.operands[1].preind
9542 || inst.operands[1].shifted
9543 || inst.operands[1].writeback,
9544 _("Thumb does not support this addressing mode"));
9545 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9546 {
c19d1205
ZW
9547 constraint (inst.instruction & 0x0600,
9548 _("byte or halfword not valid for base register"));
9549 constraint (inst.operands[1].reg == REG_PC
9550 && !(inst.instruction & THUMB_LOAD_BIT),
9551 _("r15 based store not allowed"));
9552 constraint (inst.operands[1].immisreg,
9553 _("invalid base register for register offset"));
b99bd4ef 9554
c19d1205
ZW
9555 if (inst.operands[1].reg == REG_PC)
9556 inst.instruction = T_OPCODE_LDR_PC;
9557 else if (inst.instruction & THUMB_LOAD_BIT)
9558 inst.instruction = T_OPCODE_LDR_SP;
9559 else
9560 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9561
c19d1205
ZW
9562 inst.instruction |= inst.operands[0].reg << 8;
9563 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9564 return;
9565 }
90e4755a 9566
c19d1205
ZW
9567 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9568 if (!inst.operands[1].immisreg)
9569 {
9570 /* Immediate offset. */
9571 inst.instruction |= inst.operands[0].reg;
9572 inst.instruction |= inst.operands[1].reg << 3;
9573 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9574 return;
9575 }
90e4755a 9576
c19d1205
ZW
9577 /* Register offset. */
9578 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9579 constraint (inst.operands[1].negative,
9580 _("Thumb does not support this addressing mode"));
90e4755a 9581
c19d1205
ZW
9582 op16:
9583 switch (inst.instruction)
9584 {
9585 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9586 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9587 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9588 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9589 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9590 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9591 case 0x5600 /* ldrsb */:
9592 case 0x5e00 /* ldrsh */: break;
9593 default: abort ();
9594 }
90e4755a 9595
c19d1205
ZW
9596 inst.instruction |= inst.operands[0].reg;
9597 inst.instruction |= inst.operands[1].reg << 3;
9598 inst.instruction |= inst.operands[1].imm << 6;
9599}
90e4755a 9600
c19d1205
ZW
9601static void
9602do_t_ldstd (void)
9603{
9604 if (!inst.operands[1].present)
b99bd4ef 9605 {
c19d1205
ZW
9606 inst.operands[1].reg = inst.operands[0].reg + 1;
9607 constraint (inst.operands[0].reg == REG_LR,
9608 _("r14 not allowed here"));
b99bd4ef 9609 }
c19d1205
ZW
9610 inst.instruction |= inst.operands[0].reg << 12;
9611 inst.instruction |= inst.operands[1].reg << 8;
9612 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9613}
9614
c19d1205
ZW
9615static void
9616do_t_ldstt (void)
9617{
9618 inst.instruction |= inst.operands[0].reg << 12;
9619 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9620}
a737bd4d 9621
b99bd4ef 9622static void
c19d1205 9623do_t_mla (void)
b99bd4ef 9624{
fdfde340
JM
9625 unsigned Rd, Rn, Rm, Ra;
9626
9627 Rd = inst.operands[0].reg;
9628 Rn = inst.operands[1].reg;
9629 Rm = inst.operands[2].reg;
9630 Ra = inst.operands[3].reg;
9631
9632 reject_bad_reg (Rd);
9633 reject_bad_reg (Rn);
9634 reject_bad_reg (Rm);
9635 reject_bad_reg (Ra);
9636
9637 inst.instruction |= Rd << 8;
9638 inst.instruction |= Rn << 16;
9639 inst.instruction |= Rm;
9640 inst.instruction |= Ra << 12;
c19d1205 9641}
b99bd4ef 9642
c19d1205
ZW
9643static void
9644do_t_mlal (void)
9645{
fdfde340
JM
9646 unsigned RdLo, RdHi, Rn, Rm;
9647
9648 RdLo = inst.operands[0].reg;
9649 RdHi = inst.operands[1].reg;
9650 Rn = inst.operands[2].reg;
9651 Rm = inst.operands[3].reg;
9652
9653 reject_bad_reg (RdLo);
9654 reject_bad_reg (RdHi);
9655 reject_bad_reg (Rn);
9656 reject_bad_reg (Rm);
9657
9658 inst.instruction |= RdLo << 12;
9659 inst.instruction |= RdHi << 8;
9660 inst.instruction |= Rn << 16;
9661 inst.instruction |= Rm;
c19d1205 9662}
b99bd4ef 9663
c19d1205
ZW
9664static void
9665do_t_mov_cmp (void)
9666{
fdfde340
JM
9667 unsigned Rn, Rm;
9668
9669 Rn = inst.operands[0].reg;
9670 Rm = inst.operands[1].reg;
9671
c19d1205 9672 if (unified_syntax)
b99bd4ef 9673 {
c19d1205
ZW
9674 int r0off = (inst.instruction == T_MNEM_mov
9675 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9676 unsigned long opcode;
3d388997
PB
9677 bfd_boolean narrow;
9678 bfd_boolean low_regs;
9679
fdfde340 9680 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 9681 opcode = inst.instruction;
3d388997 9682 if (current_it_mask)
0110f2b8 9683 narrow = opcode != T_MNEM_movs;
3d388997 9684 else
0110f2b8 9685 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9686 if (inst.size_req == 4
9687 || inst.operands[1].shifted)
9688 narrow = FALSE;
9689
efd81785
PB
9690 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9691 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9692 && !inst.operands[1].shifted
fdfde340
JM
9693 && Rn == REG_PC
9694 && Rm == REG_LR)
efd81785
PB
9695 {
9696 inst.instruction = T2_SUBS_PC_LR;
9697 return;
9698 }
9699
fdfde340
JM
9700 if (opcode == T_MNEM_cmp)
9701 {
9702 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
9703 if (narrow)
9704 {
9705 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9706 but valid. */
9707 warn_deprecated_sp (Rm);
9708 /* R15 was documented as a valid choice for Rm in ARMv6,
9709 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9710 tools reject R15, so we do too. */
9711 constraint (Rm == REG_PC, BAD_PC);
9712 }
9713 else
9714 reject_bad_reg (Rm);
fdfde340
JM
9715 }
9716 else if (opcode == T_MNEM_mov
9717 || opcode == T_MNEM_movs)
9718 {
9719 if (inst.operands[1].isreg)
9720 {
9721 if (opcode == T_MNEM_movs)
9722 {
9723 reject_bad_reg (Rn);
9724 reject_bad_reg (Rm);
9725 }
9726 else if ((Rn == REG_SP || Rn == REG_PC)
9727 && (Rm == REG_SP || Rm == REG_PC))
9728 reject_bad_reg (Rm);
9729 }
9730 else
9731 reject_bad_reg (Rn);
9732 }
9733
c19d1205
ZW
9734 if (!inst.operands[1].isreg)
9735 {
0110f2b8
PB
9736 /* Immediate operand. */
9737 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9738 narrow = 0;
9739 if (low_regs && narrow)
9740 {
9741 inst.instruction = THUMB_OP16 (opcode);
fdfde340 9742 inst.instruction |= Rn << 8;
0110f2b8
PB
9743 if (inst.size_req == 2)
9744 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9745 else
9746 inst.relax = opcode;
9747 }
9748 else
9749 {
9750 inst.instruction = THUMB_OP32 (inst.instruction);
9751 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9752 inst.instruction |= Rn << r0off;
0110f2b8
PB
9753 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9754 }
c19d1205 9755 }
728ca7c9
PB
9756 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9757 && (inst.instruction == T_MNEM_mov
9758 || inst.instruction == T_MNEM_movs))
9759 {
9760 /* Register shifts are encoded as separate shift instructions. */
9761 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9762
9763 if (current_it_mask)
9764 narrow = !flags;
9765 else
9766 narrow = flags;
9767
9768 if (inst.size_req == 4)
9769 narrow = FALSE;
9770
9771 if (!low_regs || inst.operands[1].imm > 7)
9772 narrow = FALSE;
9773
fdfde340 9774 if (Rn != Rm)
728ca7c9
PB
9775 narrow = FALSE;
9776
9777 switch (inst.operands[1].shift_kind)
9778 {
9779 case SHIFT_LSL:
9780 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9781 break;
9782 case SHIFT_ASR:
9783 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9784 break;
9785 case SHIFT_LSR:
9786 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9787 break;
9788 case SHIFT_ROR:
9789 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9790 break;
9791 default:
5f4273c7 9792 abort ();
728ca7c9
PB
9793 }
9794
9795 inst.instruction = opcode;
9796 if (narrow)
9797 {
fdfde340 9798 inst.instruction |= Rn;
728ca7c9
PB
9799 inst.instruction |= inst.operands[1].imm << 3;
9800 }
9801 else
9802 {
9803 if (flags)
9804 inst.instruction |= CONDS_BIT;
9805
fdfde340
JM
9806 inst.instruction |= Rn << 8;
9807 inst.instruction |= Rm << 16;
728ca7c9
PB
9808 inst.instruction |= inst.operands[1].imm;
9809 }
9810 }
3d388997 9811 else if (!narrow)
c19d1205 9812 {
728ca7c9
PB
9813 /* Some mov with immediate shift have narrow variants.
9814 Register shifts are handled above. */
9815 if (low_regs && inst.operands[1].shifted
9816 && (inst.instruction == T_MNEM_mov
9817 || inst.instruction == T_MNEM_movs))
9818 {
9819 if (current_it_mask)
9820 narrow = (inst.instruction == T_MNEM_mov);
9821 else
9822 narrow = (inst.instruction == T_MNEM_movs);
9823 }
9824
9825 if (narrow)
9826 {
9827 switch (inst.operands[1].shift_kind)
9828 {
9829 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9830 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9831 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9832 default: narrow = FALSE; break;
9833 }
9834 }
9835
9836 if (narrow)
9837 {
fdfde340
JM
9838 inst.instruction |= Rn;
9839 inst.instruction |= Rm << 3;
728ca7c9
PB
9840 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9841 }
9842 else
9843 {
9844 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9845 inst.instruction |= Rn << r0off;
728ca7c9
PB
9846 encode_thumb32_shifted_operand (1);
9847 }
c19d1205
ZW
9848 }
9849 else
9850 switch (inst.instruction)
9851 {
9852 case T_MNEM_mov:
9853 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
9854 inst.instruction |= (Rn & 0x8) << 4;
9855 inst.instruction |= (Rn & 0x7);
9856 inst.instruction |= Rm << 3;
c19d1205 9857 break;
b99bd4ef 9858
c19d1205
ZW
9859 case T_MNEM_movs:
9860 /* We know we have low registers at this point.
9861 Generate ADD Rd, Rs, #0. */
9862 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
9863 inst.instruction |= Rn;
9864 inst.instruction |= Rm << 3;
c19d1205
ZW
9865 break;
9866
9867 case T_MNEM_cmp:
3d388997 9868 if (low_regs)
c19d1205
ZW
9869 {
9870 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
9871 inst.instruction |= Rn;
9872 inst.instruction |= Rm << 3;
c19d1205
ZW
9873 }
9874 else
9875 {
9876 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
9877 inst.instruction |= (Rn & 0x8) << 4;
9878 inst.instruction |= (Rn & 0x7);
9879 inst.instruction |= Rm << 3;
c19d1205
ZW
9880 }
9881 break;
9882 }
b99bd4ef
NC
9883 return;
9884 }
9885
c19d1205
ZW
9886 inst.instruction = THUMB_OP16 (inst.instruction);
9887 if (inst.operands[1].isreg)
b99bd4ef 9888 {
fdfde340 9889 if (Rn < 8 && Rm < 8)
b99bd4ef 9890 {
c19d1205
ZW
9891 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9892 since a MOV instruction produces unpredictable results. */
9893 if (inst.instruction == T_OPCODE_MOV_I8)
9894 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9895 else
c19d1205 9896 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9897
fdfde340
JM
9898 inst.instruction |= Rn;
9899 inst.instruction |= Rm << 3;
b99bd4ef
NC
9900 }
9901 else
9902 {
c19d1205
ZW
9903 if (inst.instruction == T_OPCODE_MOV_I8)
9904 inst.instruction = T_OPCODE_MOV_HR;
9905 else
9906 inst.instruction = T_OPCODE_CMP_HR;
9907 do_t_cpy ();
b99bd4ef
NC
9908 }
9909 }
c19d1205 9910 else
b99bd4ef 9911 {
fdfde340 9912 constraint (Rn > 7,
c19d1205 9913 _("only lo regs allowed with immediate"));
fdfde340 9914 inst.instruction |= Rn << 8;
c19d1205
ZW
9915 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9916 }
9917}
b99bd4ef 9918
c19d1205
ZW
9919static void
9920do_t_mov16 (void)
9921{
fdfde340 9922 unsigned Rd;
b6895b4f
PB
9923 bfd_vma imm;
9924 bfd_boolean top;
9925
9926 top = (inst.instruction & 0x00800000) != 0;
9927 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9928 {
9929 constraint (top, _(":lower16: not allowed this instruction"));
9930 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9931 }
9932 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9933 {
9934 constraint (!top, _(":upper16: not allowed this instruction"));
9935 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9936 }
9937
fdfde340
JM
9938 Rd = inst.operands[0].reg;
9939 reject_bad_reg (Rd);
9940
9941 inst.instruction |= Rd << 8;
b6895b4f
PB
9942 if (inst.reloc.type == BFD_RELOC_UNUSED)
9943 {
9944 imm = inst.reloc.exp.X_add_number;
9945 inst.instruction |= (imm & 0xf000) << 4;
9946 inst.instruction |= (imm & 0x0800) << 15;
9947 inst.instruction |= (imm & 0x0700) << 4;
9948 inst.instruction |= (imm & 0x00ff);
9949 }
c19d1205 9950}
b99bd4ef 9951
c19d1205
ZW
9952static void
9953do_t_mvn_tst (void)
9954{
fdfde340
JM
9955 unsigned Rn, Rm;
9956
9957 Rn = inst.operands[0].reg;
9958 Rm = inst.operands[1].reg;
9959
9960 if (inst.instruction == T_MNEM_cmp
9961 || inst.instruction == T_MNEM_cmn)
9962 constraint (Rn == REG_PC, BAD_PC);
9963 else
9964 reject_bad_reg (Rn);
9965 reject_bad_reg (Rm);
9966
c19d1205
ZW
9967 if (unified_syntax)
9968 {
9969 int r0off = (inst.instruction == T_MNEM_mvn
9970 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9971 bfd_boolean narrow;
9972
9973 if (inst.size_req == 4
9974 || inst.instruction > 0xffff
9975 || inst.operands[1].shifted
fdfde340 9976 || Rn > 7 || Rm > 7)
3d388997
PB
9977 narrow = FALSE;
9978 else if (inst.instruction == T_MNEM_cmn)
9979 narrow = TRUE;
9980 else if (THUMB_SETS_FLAGS (inst.instruction))
9981 narrow = (current_it_mask == 0);
9982 else
9983 narrow = (current_it_mask != 0);
9984
c19d1205 9985 if (!inst.operands[1].isreg)
b99bd4ef 9986 {
c19d1205
ZW
9987 /* For an immediate, we always generate a 32-bit opcode;
9988 section relaxation will shrink it later if possible. */
9989 if (inst.instruction < 0xffff)
9990 inst.instruction = THUMB_OP32 (inst.instruction);
9991 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9992 inst.instruction |= Rn << r0off;
c19d1205 9993 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9994 }
c19d1205 9995 else
b99bd4ef 9996 {
c19d1205 9997 /* See if we can do this with a 16-bit instruction. */
3d388997 9998 if (narrow)
b99bd4ef 9999 {
c19d1205 10000 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10001 inst.instruction |= Rn;
10002 inst.instruction |= Rm << 3;
b99bd4ef 10003 }
c19d1205 10004 else
b99bd4ef 10005 {
c19d1205
ZW
10006 constraint (inst.operands[1].shifted
10007 && inst.operands[1].immisreg,
10008 _("shift must be constant"));
10009 if (inst.instruction < 0xffff)
10010 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10011 inst.instruction |= Rn << r0off;
c19d1205 10012 encode_thumb32_shifted_operand (1);
b99bd4ef 10013 }
b99bd4ef
NC
10014 }
10015 }
10016 else
10017 {
c19d1205
ZW
10018 constraint (inst.instruction > 0xffff
10019 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10020 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10021 _("unshifted register required"));
fdfde340 10022 constraint (Rn > 7 || Rm > 7,
c19d1205 10023 BAD_HIREG);
b99bd4ef 10024
c19d1205 10025 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10026 inst.instruction |= Rn;
10027 inst.instruction |= Rm << 3;
b99bd4ef 10028 }
b99bd4ef
NC
10029}
10030
b05fe5cf 10031static void
c19d1205 10032do_t_mrs (void)
b05fe5cf 10033{
fdfde340 10034 unsigned Rd;
62b3e311 10035 int flags;
037e8744
JB
10036
10037 if (do_vfp_nsyn_mrs () == SUCCESS)
10038 return;
10039
62b3e311
PB
10040 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10041 if (flags == 0)
10042 {
7e806470 10043 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10044 _("selected processor does not support "
10045 "requested special purpose register"));
10046 }
10047 else
10048 {
10049 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10050 _("selected processor does not support "
44bf2362 10051 "requested special purpose register"));
62b3e311
PB
10052 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10053 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10054 _("'CPSR' or 'SPSR' expected"));
10055 }
5f4273c7 10056
fdfde340
JM
10057 Rd = inst.operands[0].reg;
10058 reject_bad_reg (Rd);
10059
10060 inst.instruction |= Rd << 8;
62b3e311
PB
10061 inst.instruction |= (flags & SPSR_BIT) >> 2;
10062 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10063}
b05fe5cf 10064
c19d1205
ZW
10065static void
10066do_t_msr (void)
10067{
62b3e311 10068 int flags;
fdfde340 10069 unsigned Rn;
62b3e311 10070
037e8744
JB
10071 if (do_vfp_nsyn_msr () == SUCCESS)
10072 return;
10073
c19d1205
ZW
10074 constraint (!inst.operands[1].isreg,
10075 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10076 flags = inst.operands[0].imm;
10077 if (flags & ~0xff)
10078 {
10079 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10080 _("selected processor does not support "
10081 "requested special purpose register"));
10082 }
10083 else
10084 {
7e806470 10085 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10086 _("selected processor does not support "
10087 "requested special purpose register"));
10088 flags |= PSR_f;
10089 }
fdfde340
JM
10090
10091 Rn = inst.operands[1].reg;
10092 reject_bad_reg (Rn);
10093
62b3e311
PB
10094 inst.instruction |= (flags & SPSR_BIT) >> 2;
10095 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10096 inst.instruction |= (flags & 0xff);
fdfde340 10097 inst.instruction |= Rn << 16;
c19d1205 10098}
b05fe5cf 10099
c19d1205
ZW
10100static void
10101do_t_mul (void)
10102{
17828f45 10103 bfd_boolean narrow;
fdfde340 10104 unsigned Rd, Rn, Rm;
17828f45 10105
c19d1205
ZW
10106 if (!inst.operands[2].present)
10107 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10108
fdfde340
JM
10109 Rd = inst.operands[0].reg;
10110 Rn = inst.operands[1].reg;
10111 Rm = inst.operands[2].reg;
10112
17828f45 10113 if (unified_syntax)
b05fe5cf 10114 {
17828f45 10115 if (inst.size_req == 4
fdfde340
JM
10116 || (Rd != Rn
10117 && Rd != Rm)
10118 || Rn > 7
10119 || Rm > 7)
17828f45
JM
10120 narrow = FALSE;
10121 else if (inst.instruction == T_MNEM_muls)
10122 narrow = (current_it_mask == 0);
10123 else
10124 narrow = (current_it_mask != 0);
b05fe5cf 10125 }
c19d1205 10126 else
b05fe5cf 10127 {
17828f45 10128 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10129 constraint (Rn > 7 || Rm > 7,
c19d1205 10130 BAD_HIREG);
17828f45
JM
10131 narrow = TRUE;
10132 }
b05fe5cf 10133
17828f45
JM
10134 if (narrow)
10135 {
10136 /* 16-bit MULS/Conditional MUL. */
c19d1205 10137 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10138 inst.instruction |= Rd;
b05fe5cf 10139
fdfde340
JM
10140 if (Rd == Rn)
10141 inst.instruction |= Rm << 3;
10142 else if (Rd == Rm)
10143 inst.instruction |= Rn << 3;
c19d1205
ZW
10144 else
10145 constraint (1, _("dest must overlap one source register"));
10146 }
17828f45
JM
10147 else
10148 {
10149 constraint(inst.instruction != T_MNEM_mul,
10150 _("Thumb-2 MUL must not set flags"));
10151 /* 32-bit MUL. */
10152 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10153 inst.instruction |= Rd << 8;
10154 inst.instruction |= Rn << 16;
10155 inst.instruction |= Rm << 0;
10156
10157 reject_bad_reg (Rd);
10158 reject_bad_reg (Rn);
10159 reject_bad_reg (Rm);
17828f45 10160 }
c19d1205 10161}
b05fe5cf 10162
c19d1205
ZW
10163static void
10164do_t_mull (void)
10165{
fdfde340 10166 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10167
fdfde340
JM
10168 RdLo = inst.operands[0].reg;
10169 RdHi = inst.operands[1].reg;
10170 Rn = inst.operands[2].reg;
10171 Rm = inst.operands[3].reg;
10172
10173 reject_bad_reg (RdLo);
10174 reject_bad_reg (RdHi);
10175 reject_bad_reg (Rn);
10176 reject_bad_reg (Rm);
10177
10178 inst.instruction |= RdLo << 12;
10179 inst.instruction |= RdHi << 8;
10180 inst.instruction |= Rn << 16;
10181 inst.instruction |= Rm;
10182
10183 if (RdLo == RdHi)
c19d1205
ZW
10184 as_tsktsk (_("rdhi and rdlo must be different"));
10185}
b05fe5cf 10186
c19d1205
ZW
10187static void
10188do_t_nop (void)
10189{
10190 if (unified_syntax)
10191 {
10192 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10193 {
c19d1205
ZW
10194 inst.instruction = THUMB_OP32 (inst.instruction);
10195 inst.instruction |= inst.operands[0].imm;
10196 }
10197 else
10198 {
bc2d1808
NC
10199 /* PR9722: Check for Thumb2 availability before
10200 generating a thumb2 nop instruction. */
10201 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10202 {
10203 inst.instruction = THUMB_OP16 (inst.instruction);
10204 inst.instruction |= inst.operands[0].imm << 4;
10205 }
10206 else
10207 inst.instruction = 0x46c0;
c19d1205
ZW
10208 }
10209 }
10210 else
10211 {
10212 constraint (inst.operands[0].present,
10213 _("Thumb does not support NOP with hints"));
10214 inst.instruction = 0x46c0;
10215 }
10216}
b05fe5cf 10217
c19d1205
ZW
10218static void
10219do_t_neg (void)
10220{
10221 if (unified_syntax)
10222 {
3d388997
PB
10223 bfd_boolean narrow;
10224
10225 if (THUMB_SETS_FLAGS (inst.instruction))
10226 narrow = (current_it_mask == 0);
10227 else
10228 narrow = (current_it_mask != 0);
10229 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10230 narrow = FALSE;
10231 if (inst.size_req == 4)
10232 narrow = FALSE;
10233
10234 if (!narrow)
c19d1205
ZW
10235 {
10236 inst.instruction = THUMB_OP32 (inst.instruction);
10237 inst.instruction |= inst.operands[0].reg << 8;
10238 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10239 }
10240 else
10241 {
c19d1205
ZW
10242 inst.instruction = THUMB_OP16 (inst.instruction);
10243 inst.instruction |= inst.operands[0].reg;
10244 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10245 }
10246 }
10247 else
10248 {
c19d1205
ZW
10249 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10250 BAD_HIREG);
10251 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10252
10253 inst.instruction = THUMB_OP16 (inst.instruction);
10254 inst.instruction |= inst.operands[0].reg;
10255 inst.instruction |= inst.operands[1].reg << 3;
10256 }
10257}
10258
1c444d06
JM
10259static void
10260do_t_orn (void)
10261{
10262 unsigned Rd, Rn;
10263
10264 Rd = inst.operands[0].reg;
10265 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10266
fdfde340
JM
10267 reject_bad_reg (Rd);
10268 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10269 reject_bad_reg (Rn);
10270
1c444d06
JM
10271 inst.instruction |= Rd << 8;
10272 inst.instruction |= Rn << 16;
10273
10274 if (!inst.operands[2].isreg)
10275 {
10276 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10277 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10278 }
10279 else
10280 {
10281 unsigned Rm;
10282
10283 Rm = inst.operands[2].reg;
fdfde340 10284 reject_bad_reg (Rm);
1c444d06
JM
10285
10286 constraint (inst.operands[2].shifted
10287 && inst.operands[2].immisreg,
10288 _("shift must be constant"));
10289 encode_thumb32_shifted_operand (2);
10290 }
10291}
10292
c19d1205
ZW
10293static void
10294do_t_pkhbt (void)
10295{
fdfde340
JM
10296 unsigned Rd, Rn, Rm;
10297
10298 Rd = inst.operands[0].reg;
10299 Rn = inst.operands[1].reg;
10300 Rm = inst.operands[2].reg;
10301
10302 reject_bad_reg (Rd);
10303 reject_bad_reg (Rn);
10304 reject_bad_reg (Rm);
10305
10306 inst.instruction |= Rd << 8;
10307 inst.instruction |= Rn << 16;
10308 inst.instruction |= Rm;
c19d1205
ZW
10309 if (inst.operands[3].present)
10310 {
10311 unsigned int val = inst.reloc.exp.X_add_number;
10312 constraint (inst.reloc.exp.X_op != O_constant,
10313 _("expression too complex"));
10314 inst.instruction |= (val & 0x1c) << 10;
10315 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10316 }
c19d1205 10317}
b05fe5cf 10318
c19d1205
ZW
10319static void
10320do_t_pkhtb (void)
10321{
10322 if (!inst.operands[3].present)
10323 inst.instruction &= ~0x00000020;
10324 do_t_pkhbt ();
b05fe5cf
ZW
10325}
10326
c19d1205
ZW
10327static void
10328do_t_pld (void)
10329{
fdfde340
JM
10330 if (inst.operands[0].immisreg)
10331 reject_bad_reg (inst.operands[0].imm);
10332
c19d1205
ZW
10333 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10334}
b05fe5cf 10335
c19d1205
ZW
10336static void
10337do_t_push_pop (void)
b99bd4ef 10338{
e9f89963 10339 unsigned mask;
5f4273c7 10340
c19d1205
ZW
10341 constraint (inst.operands[0].writeback,
10342 _("push/pop do not support {reglist}^"));
10343 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10344 _("expression too complex"));
b99bd4ef 10345
e9f89963
PB
10346 mask = inst.operands[0].imm;
10347 if ((mask & ~0xff) == 0)
3c707909 10348 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10349 else if ((inst.instruction == T_MNEM_push
e9f89963 10350 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10351 || (inst.instruction == T_MNEM_pop
e9f89963 10352 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10353 {
c19d1205
ZW
10354 inst.instruction = THUMB_OP16 (inst.instruction);
10355 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10356 inst.instruction |= mask & 0xff;
c19d1205
ZW
10357 }
10358 else if (unified_syntax)
10359 {
3c707909 10360 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10361 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10362 }
10363 else
10364 {
10365 inst.error = _("invalid register list to push/pop instruction");
10366 return;
10367 }
c19d1205 10368}
b99bd4ef 10369
c19d1205
ZW
10370static void
10371do_t_rbit (void)
10372{
fdfde340
JM
10373 unsigned Rd, Rm;
10374
10375 Rd = inst.operands[0].reg;
10376 Rm = inst.operands[1].reg;
10377
10378 reject_bad_reg (Rd);
10379 reject_bad_reg (Rm);
10380
10381 inst.instruction |= Rd << 8;
10382 inst.instruction |= Rm << 16;
10383 inst.instruction |= Rm;
c19d1205 10384}
b99bd4ef 10385
c19d1205
ZW
10386static void
10387do_t_rev (void)
10388{
fdfde340
JM
10389 unsigned Rd, Rm;
10390
10391 Rd = inst.operands[0].reg;
10392 Rm = inst.operands[1].reg;
10393
10394 reject_bad_reg (Rd);
10395 reject_bad_reg (Rm);
10396
10397 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10398 && inst.size_req != 4)
10399 {
10400 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10401 inst.instruction |= Rd;
10402 inst.instruction |= Rm << 3;
c19d1205
ZW
10403 }
10404 else if (unified_syntax)
10405 {
10406 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10407 inst.instruction |= Rd << 8;
10408 inst.instruction |= Rm << 16;
10409 inst.instruction |= Rm;
c19d1205
ZW
10410 }
10411 else
10412 inst.error = BAD_HIREG;
10413}
b99bd4ef 10414
1c444d06
JM
10415static void
10416do_t_rrx (void)
10417{
10418 unsigned Rd, Rm;
10419
10420 Rd = inst.operands[0].reg;
10421 Rm = inst.operands[1].reg;
10422
fdfde340
JM
10423 reject_bad_reg (Rd);
10424 reject_bad_reg (Rm);
10425
1c444d06
JM
10426 inst.instruction |= Rd << 8;
10427 inst.instruction |= Rm;
10428}
10429
c19d1205
ZW
10430static void
10431do_t_rsb (void)
10432{
fdfde340 10433 unsigned Rd, Rs;
b99bd4ef 10434
c19d1205
ZW
10435 Rd = inst.operands[0].reg;
10436 Rs = (inst.operands[1].present
10437 ? inst.operands[1].reg /* Rd, Rs, foo */
10438 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10439
fdfde340
JM
10440 reject_bad_reg (Rd);
10441 reject_bad_reg (Rs);
10442 if (inst.operands[2].isreg)
10443 reject_bad_reg (inst.operands[2].reg);
10444
c19d1205
ZW
10445 inst.instruction |= Rd << 8;
10446 inst.instruction |= Rs << 16;
10447 if (!inst.operands[2].isreg)
10448 {
026d3abb
PB
10449 bfd_boolean narrow;
10450
10451 if ((inst.instruction & 0x00100000) != 0)
10452 narrow = (current_it_mask == 0);
10453 else
10454 narrow = (current_it_mask != 0);
10455
10456 if (Rd > 7 || Rs > 7)
10457 narrow = FALSE;
10458
10459 if (inst.size_req == 4 || !unified_syntax)
10460 narrow = FALSE;
10461
10462 if (inst.reloc.exp.X_op != O_constant
10463 || inst.reloc.exp.X_add_number != 0)
10464 narrow = FALSE;
10465
10466 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10467 relaxation, but it doesn't seem worth the hassle. */
10468 if (narrow)
10469 {
10470 inst.reloc.type = BFD_RELOC_UNUSED;
10471 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10472 inst.instruction |= Rs << 3;
10473 inst.instruction |= Rd;
10474 }
10475 else
10476 {
10477 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10478 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10479 }
c19d1205
ZW
10480 }
10481 else
10482 encode_thumb32_shifted_operand (2);
10483}
b99bd4ef 10484
c19d1205
ZW
10485static void
10486do_t_setend (void)
10487{
dfa9f0d5 10488 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10489 if (inst.operands[0].imm)
10490 inst.instruction |= 0x8;
10491}
b99bd4ef 10492
c19d1205
ZW
10493static void
10494do_t_shift (void)
10495{
10496 if (!inst.operands[1].present)
10497 inst.operands[1].reg = inst.operands[0].reg;
10498
10499 if (unified_syntax)
10500 {
3d388997
PB
10501 bfd_boolean narrow;
10502 int shift_kind;
10503
10504 switch (inst.instruction)
10505 {
10506 case T_MNEM_asr:
10507 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10508 case T_MNEM_lsl:
10509 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10510 case T_MNEM_lsr:
10511 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10512 case T_MNEM_ror:
10513 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10514 default: abort ();
10515 }
10516
10517 if (THUMB_SETS_FLAGS (inst.instruction))
10518 narrow = (current_it_mask == 0);
10519 else
10520 narrow = (current_it_mask != 0);
10521 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10522 narrow = FALSE;
10523 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10524 narrow = FALSE;
10525 if (inst.operands[2].isreg
10526 && (inst.operands[1].reg != inst.operands[0].reg
10527 || inst.operands[2].reg > 7))
10528 narrow = FALSE;
10529 if (inst.size_req == 4)
10530 narrow = FALSE;
10531
fdfde340
JM
10532 reject_bad_reg (inst.operands[0].reg);
10533 reject_bad_reg (inst.operands[1].reg);
10534
3d388997 10535 if (!narrow)
c19d1205
ZW
10536 {
10537 if (inst.operands[2].isreg)
b99bd4ef 10538 {
fdfde340 10539 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10540 inst.instruction = THUMB_OP32 (inst.instruction);
10541 inst.instruction |= inst.operands[0].reg << 8;
10542 inst.instruction |= inst.operands[1].reg << 16;
10543 inst.instruction |= inst.operands[2].reg;
10544 }
10545 else
10546 {
10547 inst.operands[1].shifted = 1;
3d388997 10548 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10549 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10550 ? T_MNEM_movs : T_MNEM_mov);
10551 inst.instruction |= inst.operands[0].reg << 8;
10552 encode_thumb32_shifted_operand (1);
10553 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10554 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10555 }
10556 }
10557 else
10558 {
c19d1205 10559 if (inst.operands[2].isreg)
b99bd4ef 10560 {
3d388997 10561 switch (shift_kind)
b99bd4ef 10562 {
3d388997
PB
10563 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10564 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10565 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10566 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10567 default: abort ();
b99bd4ef 10568 }
5f4273c7 10569
c19d1205
ZW
10570 inst.instruction |= inst.operands[0].reg;
10571 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10572 }
10573 else
10574 {
3d388997 10575 switch (shift_kind)
b99bd4ef 10576 {
3d388997
PB
10577 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10578 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10579 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10580 default: abort ();
b99bd4ef 10581 }
c19d1205
ZW
10582 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10583 inst.instruction |= inst.operands[0].reg;
10584 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10585 }
10586 }
c19d1205
ZW
10587 }
10588 else
10589 {
10590 constraint (inst.operands[0].reg > 7
10591 || inst.operands[1].reg > 7, BAD_HIREG);
10592 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10593
c19d1205
ZW
10594 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10595 {
10596 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10597 constraint (inst.operands[0].reg != inst.operands[1].reg,
10598 _("source1 and dest must be same register"));
b99bd4ef 10599
c19d1205
ZW
10600 switch (inst.instruction)
10601 {
10602 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10603 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10604 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10605 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10606 default: abort ();
10607 }
5f4273c7 10608
c19d1205
ZW
10609 inst.instruction |= inst.operands[0].reg;
10610 inst.instruction |= inst.operands[2].reg << 3;
10611 }
10612 else
b99bd4ef 10613 {
c19d1205
ZW
10614 switch (inst.instruction)
10615 {
10616 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10617 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10618 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10619 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10620 default: abort ();
10621 }
10622 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10623 inst.instruction |= inst.operands[0].reg;
10624 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10625 }
10626 }
b99bd4ef
NC
10627}
10628
10629static void
c19d1205 10630do_t_simd (void)
b99bd4ef 10631{
fdfde340
JM
10632 unsigned Rd, Rn, Rm;
10633
10634 Rd = inst.operands[0].reg;
10635 Rn = inst.operands[1].reg;
10636 Rm = inst.operands[2].reg;
10637
10638 reject_bad_reg (Rd);
10639 reject_bad_reg (Rn);
10640 reject_bad_reg (Rm);
10641
10642 inst.instruction |= Rd << 8;
10643 inst.instruction |= Rn << 16;
10644 inst.instruction |= Rm;
c19d1205 10645}
b99bd4ef 10646
c19d1205 10647static void
3eb17e6b 10648do_t_smc (void)
c19d1205
ZW
10649{
10650 unsigned int value = inst.reloc.exp.X_add_number;
10651 constraint (inst.reloc.exp.X_op != O_constant,
10652 _("expression too complex"));
10653 inst.reloc.type = BFD_RELOC_UNUSED;
10654 inst.instruction |= (value & 0xf000) >> 12;
10655 inst.instruction |= (value & 0x0ff0);
10656 inst.instruction |= (value & 0x000f) << 16;
10657}
b99bd4ef 10658
c19d1205
ZW
10659static void
10660do_t_ssat (void)
10661{
fdfde340
JM
10662 unsigned Rd, Rn;
10663
10664 Rd = inst.operands[0].reg;
10665 Rn = inst.operands[2].reg;
10666
10667 reject_bad_reg (Rd);
10668 reject_bad_reg (Rn);
10669
10670 inst.instruction |= Rd << 8;
c19d1205 10671 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 10672 inst.instruction |= Rn << 16;
b99bd4ef 10673
c19d1205 10674 if (inst.operands[3].present)
b99bd4ef 10675 {
c19d1205
ZW
10676 constraint (inst.reloc.exp.X_op != O_constant,
10677 _("expression too complex"));
b99bd4ef 10678
c19d1205 10679 if (inst.reloc.exp.X_add_number != 0)
6189168b 10680 {
c19d1205
ZW
10681 if (inst.operands[3].shift_kind == SHIFT_ASR)
10682 inst.instruction |= 0x00200000; /* sh bit */
10683 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10684 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10685 }
c19d1205 10686 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10687 }
b99bd4ef
NC
10688}
10689
0dd132b6 10690static void
c19d1205 10691do_t_ssat16 (void)
0dd132b6 10692{
fdfde340
JM
10693 unsigned Rd, Rn;
10694
10695 Rd = inst.operands[0].reg;
10696 Rn = inst.operands[2].reg;
10697
10698 reject_bad_reg (Rd);
10699 reject_bad_reg (Rn);
10700
10701 inst.instruction |= Rd << 8;
c19d1205 10702 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 10703 inst.instruction |= Rn << 16;
c19d1205 10704}
0dd132b6 10705
c19d1205
ZW
10706static void
10707do_t_strex (void)
10708{
10709 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10710 || inst.operands[2].postind || inst.operands[2].writeback
10711 || inst.operands[2].immisreg || inst.operands[2].shifted
10712 || inst.operands[2].negative,
01cfc07f 10713 BAD_ADDR_MODE);
0dd132b6 10714
c19d1205
ZW
10715 inst.instruction |= inst.operands[0].reg << 8;
10716 inst.instruction |= inst.operands[1].reg << 12;
10717 inst.instruction |= inst.operands[2].reg << 16;
10718 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10719}
10720
b99bd4ef 10721static void
c19d1205 10722do_t_strexd (void)
b99bd4ef 10723{
c19d1205
ZW
10724 if (!inst.operands[2].present)
10725 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10726
c19d1205
ZW
10727 constraint (inst.operands[0].reg == inst.operands[1].reg
10728 || inst.operands[0].reg == inst.operands[2].reg
10729 || inst.operands[0].reg == inst.operands[3].reg
10730 || inst.operands[1].reg == inst.operands[2].reg,
10731 BAD_OVERLAP);
b99bd4ef 10732
c19d1205
ZW
10733 inst.instruction |= inst.operands[0].reg;
10734 inst.instruction |= inst.operands[1].reg << 12;
10735 inst.instruction |= inst.operands[2].reg << 8;
10736 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10737}
10738
10739static void
c19d1205 10740do_t_sxtah (void)
b99bd4ef 10741{
fdfde340
JM
10742 unsigned Rd, Rn, Rm;
10743
10744 Rd = inst.operands[0].reg;
10745 Rn = inst.operands[1].reg;
10746 Rm = inst.operands[2].reg;
10747
10748 reject_bad_reg (Rd);
10749 reject_bad_reg (Rn);
10750 reject_bad_reg (Rm);
10751
10752 inst.instruction |= Rd << 8;
10753 inst.instruction |= Rn << 16;
10754 inst.instruction |= Rm;
c19d1205
ZW
10755 inst.instruction |= inst.operands[3].imm << 4;
10756}
b99bd4ef 10757
c19d1205
ZW
10758static void
10759do_t_sxth (void)
10760{
fdfde340
JM
10761 unsigned Rd, Rm;
10762
10763 Rd = inst.operands[0].reg;
10764 Rm = inst.operands[1].reg;
10765
10766 reject_bad_reg (Rd);
10767 reject_bad_reg (Rm);
10768
c19d1205 10769 if (inst.instruction <= 0xffff && inst.size_req != 4
fdfde340 10770 && Rd <= 7 && Rm <= 7
c19d1205 10771 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10772 {
c19d1205 10773 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10774 inst.instruction |= Rd;
10775 inst.instruction |= Rm << 3;
b99bd4ef 10776 }
c19d1205 10777 else if (unified_syntax)
b99bd4ef 10778 {
c19d1205
ZW
10779 if (inst.instruction <= 0xffff)
10780 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10781 inst.instruction |= Rd << 8;
10782 inst.instruction |= Rm;
c19d1205 10783 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10784 }
c19d1205 10785 else
b99bd4ef 10786 {
c19d1205
ZW
10787 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10788 _("Thumb encoding does not support rotation"));
10789 constraint (1, BAD_HIREG);
b99bd4ef 10790 }
c19d1205 10791}
b99bd4ef 10792
c19d1205
ZW
10793static void
10794do_t_swi (void)
10795{
10796 inst.reloc.type = BFD_RELOC_ARM_SWI;
10797}
b99bd4ef 10798
92e90b6e
PB
10799static void
10800do_t_tb (void)
10801{
fdfde340 10802 unsigned Rn, Rm;
92e90b6e
PB
10803 int half;
10804
10805 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10806 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10807 constraint (inst.operands[0].immisreg,
10808 _("instruction requires register index"));
fdfde340
JM
10809
10810 Rn = inst.operands[0].reg;
10811 Rm = inst.operands[0].imm;
10812
10813 constraint (Rn == REG_SP, BAD_SP);
10814 reject_bad_reg (Rm);
10815
92e90b6e
PB
10816 constraint (!half && inst.operands[0].shifted,
10817 _("instruction does not allow shifted index"));
fdfde340 10818 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
10819}
10820
c19d1205
ZW
10821static void
10822do_t_usat (void)
10823{
fdfde340
JM
10824 unsigned Rd, Rn;
10825
10826 Rd = inst.operands[0].reg;
10827 Rn = inst.operands[2].reg;
10828
10829 reject_bad_reg (Rd);
10830 reject_bad_reg (Rn);
10831
10832 inst.instruction |= Rd << 8;
c19d1205 10833 inst.instruction |= inst.operands[1].imm;
fdfde340 10834 inst.instruction |= Rn << 16;
b99bd4ef 10835
c19d1205 10836 if (inst.operands[3].present)
b99bd4ef 10837 {
c19d1205
ZW
10838 constraint (inst.reloc.exp.X_op != O_constant,
10839 _("expression too complex"));
10840 if (inst.reloc.exp.X_add_number != 0)
10841 {
10842 if (inst.operands[3].shift_kind == SHIFT_ASR)
10843 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10844
c19d1205
ZW
10845 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10846 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10847 }
10848 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10849 }
b99bd4ef
NC
10850}
10851
10852static void
c19d1205 10853do_t_usat16 (void)
b99bd4ef 10854{
fdfde340
JM
10855 unsigned Rd, Rn;
10856
10857 Rd = inst.operands[0].reg;
10858 Rn = inst.operands[2].reg;
10859
10860 reject_bad_reg (Rd);
10861 reject_bad_reg (Rn);
10862
10863 inst.instruction |= Rd << 8;
c19d1205 10864 inst.instruction |= inst.operands[1].imm;
fdfde340 10865 inst.instruction |= Rn << 16;
b99bd4ef 10866}
c19d1205 10867
5287ad62 10868/* Neon instruction encoder helpers. */
5f4273c7 10869
5287ad62 10870/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10871
5287ad62
JB
10872/* An "invalid" code for the following tables. */
10873#define N_INV -1u
10874
10875struct neon_tab_entry
b99bd4ef 10876{
5287ad62
JB
10877 unsigned integer;
10878 unsigned float_or_poly;
10879 unsigned scalar_or_imm;
10880};
5f4273c7 10881
5287ad62
JB
10882/* Map overloaded Neon opcodes to their respective encodings. */
10883#define NEON_ENC_TAB \
10884 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10885 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10886 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10887 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10888 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10889 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10890 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10891 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10892 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10893 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10894 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10895 /* Register variants of the following two instructions are encoded as
10896 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10897 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10898 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10899 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10900 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10901 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10902 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10903 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10904 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10905 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10906 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10907 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10908 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10909 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10910 X(vshl, 0x0000400, N_INV, 0x0800510), \
10911 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10912 X(vand, 0x0000110, N_INV, 0x0800030), \
10913 X(vbic, 0x0100110, N_INV, 0x0800030), \
10914 X(veor, 0x1000110, N_INV, N_INV), \
10915 X(vorn, 0x0300110, N_INV, 0x0800010), \
10916 X(vorr, 0x0200110, N_INV, 0x0800010), \
10917 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10918 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10919 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10920 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10921 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10922 X(vst1, 0x0000000, 0x0800000, N_INV), \
10923 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10924 X(vst2, 0x0000100, 0x0800100, N_INV), \
10925 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10926 X(vst3, 0x0000200, 0x0800200, N_INV), \
10927 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10928 X(vst4, 0x0000300, 0x0800300, N_INV), \
10929 X(vmovn, 0x1b20200, N_INV, N_INV), \
10930 X(vtrn, 0x1b20080, N_INV, N_INV), \
10931 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10932 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10933 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10934 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10935 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10936 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10937 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10938 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10939 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10940
10941enum neon_opc
10942{
10943#define X(OPC,I,F,S) N_MNEM_##OPC
10944NEON_ENC_TAB
10945#undef X
10946};
b99bd4ef 10947
5287ad62
JB
10948static const struct neon_tab_entry neon_enc_tab[] =
10949{
10950#define X(OPC,I,F,S) { (I), (F), (S) }
10951NEON_ENC_TAB
10952#undef X
10953};
b99bd4ef 10954
5287ad62
JB
10955#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10956#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10957#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10958#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10959#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10960#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10961#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10962#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10963#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10964#define NEON_ENC_SINGLE(X) \
10965 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10966#define NEON_ENC_DOUBLE(X) \
10967 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10968
037e8744
JB
10969/* Define shapes for instruction operands. The following mnemonic characters
10970 are used in this table:
5287ad62 10971
037e8744 10972 F - VFP S<n> register
5287ad62
JB
10973 D - Neon D<n> register
10974 Q - Neon Q<n> register
10975 I - Immediate
10976 S - Scalar
10977 R - ARM register
10978 L - D<n> register list
5f4273c7 10979
037e8744
JB
10980 This table is used to generate various data:
10981 - enumerations of the form NS_DDR to be used as arguments to
10982 neon_select_shape.
10983 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10984 - a table used to drive neon_select_shape. */
b99bd4ef 10985
037e8744
JB
10986#define NEON_SHAPE_DEF \
10987 X(3, (D, D, D), DOUBLE), \
10988 X(3, (Q, Q, Q), QUAD), \
10989 X(3, (D, D, I), DOUBLE), \
10990 X(3, (Q, Q, I), QUAD), \
10991 X(3, (D, D, S), DOUBLE), \
10992 X(3, (Q, Q, S), QUAD), \
10993 X(2, (D, D), DOUBLE), \
10994 X(2, (Q, Q), QUAD), \
10995 X(2, (D, S), DOUBLE), \
10996 X(2, (Q, S), QUAD), \
10997 X(2, (D, R), DOUBLE), \
10998 X(2, (Q, R), QUAD), \
10999 X(2, (D, I), DOUBLE), \
11000 X(2, (Q, I), QUAD), \
11001 X(3, (D, L, D), DOUBLE), \
11002 X(2, (D, Q), MIXED), \
11003 X(2, (Q, D), MIXED), \
11004 X(3, (D, Q, I), MIXED), \
11005 X(3, (Q, D, I), MIXED), \
11006 X(3, (Q, D, D), MIXED), \
11007 X(3, (D, Q, Q), MIXED), \
11008 X(3, (Q, Q, D), MIXED), \
11009 X(3, (Q, D, S), MIXED), \
11010 X(3, (D, Q, S), MIXED), \
11011 X(4, (D, D, D, I), DOUBLE), \
11012 X(4, (Q, Q, Q, I), QUAD), \
11013 X(2, (F, F), SINGLE), \
11014 X(3, (F, F, F), SINGLE), \
11015 X(2, (F, I), SINGLE), \
11016 X(2, (F, D), MIXED), \
11017 X(2, (D, F), MIXED), \
11018 X(3, (F, F, I), MIXED), \
11019 X(4, (R, R, F, F), SINGLE), \
11020 X(4, (F, F, R, R), SINGLE), \
11021 X(3, (D, R, R), DOUBLE), \
11022 X(3, (R, R, D), DOUBLE), \
11023 X(2, (S, R), SINGLE), \
11024 X(2, (R, S), SINGLE), \
11025 X(2, (F, R), SINGLE), \
11026 X(2, (R, F), SINGLE)
11027
11028#define S2(A,B) NS_##A##B
11029#define S3(A,B,C) NS_##A##B##C
11030#define S4(A,B,C,D) NS_##A##B##C##D
11031
11032#define X(N, L, C) S##N L
11033
5287ad62
JB
11034enum neon_shape
11035{
037e8744
JB
11036 NEON_SHAPE_DEF,
11037 NS_NULL
5287ad62 11038};
b99bd4ef 11039
037e8744
JB
11040#undef X
11041#undef S2
11042#undef S3
11043#undef S4
11044
11045enum neon_shape_class
11046{
11047 SC_SINGLE,
11048 SC_DOUBLE,
11049 SC_QUAD,
11050 SC_MIXED
11051};
11052
11053#define X(N, L, C) SC_##C
11054
11055static enum neon_shape_class neon_shape_class[] =
11056{
11057 NEON_SHAPE_DEF
11058};
11059
11060#undef X
11061
11062enum neon_shape_el
11063{
11064 SE_F,
11065 SE_D,
11066 SE_Q,
11067 SE_I,
11068 SE_S,
11069 SE_R,
11070 SE_L
11071};
11072
11073/* Register widths of above. */
11074static unsigned neon_shape_el_size[] =
11075{
11076 32,
11077 64,
11078 128,
11079 0,
11080 32,
11081 32,
11082 0
11083};
11084
11085struct neon_shape_info
11086{
11087 unsigned els;
11088 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11089};
11090
11091#define S2(A,B) { SE_##A, SE_##B }
11092#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11093#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11094
11095#define X(N, L, C) { N, S##N L }
11096
11097static struct neon_shape_info neon_shape_tab[] =
11098{
11099 NEON_SHAPE_DEF
11100};
11101
11102#undef X
11103#undef S2
11104#undef S3
11105#undef S4
11106
5287ad62
JB
11107/* Bit masks used in type checking given instructions.
11108 'N_EQK' means the type must be the same as (or based on in some way) the key
11109 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11110 set, various other bits can be set as well in order to modify the meaning of
11111 the type constraint. */
11112
11113enum neon_type_mask
11114{
8e79c3df
CM
11115 N_S8 = 0x0000001,
11116 N_S16 = 0x0000002,
11117 N_S32 = 0x0000004,
11118 N_S64 = 0x0000008,
11119 N_U8 = 0x0000010,
11120 N_U16 = 0x0000020,
11121 N_U32 = 0x0000040,
11122 N_U64 = 0x0000080,
11123 N_I8 = 0x0000100,
11124 N_I16 = 0x0000200,
11125 N_I32 = 0x0000400,
11126 N_I64 = 0x0000800,
11127 N_8 = 0x0001000,
11128 N_16 = 0x0002000,
11129 N_32 = 0x0004000,
11130 N_64 = 0x0008000,
11131 N_P8 = 0x0010000,
11132 N_P16 = 0x0020000,
11133 N_F16 = 0x0040000,
11134 N_F32 = 0x0080000,
11135 N_F64 = 0x0100000,
11136 N_KEY = 0x1000000, /* key element (main type specifier). */
11137 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11138 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11139 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11140 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11141 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11142 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11143 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11144 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11145 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 11146 N_UTYP = 0,
037e8744 11147 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11148};
11149
dcbf9037
JB
11150#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11151
5287ad62
JB
11152#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11153#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11154#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11155#define N_SUF_32 (N_SU_32 | N_F32)
11156#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11157#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11158
11159/* Pass this as the first type argument to neon_check_type to ignore types
11160 altogether. */
11161#define N_IGNORE_TYPE (N_KEY | N_EQK)
11162
037e8744
JB
11163/* Select a "shape" for the current instruction (describing register types or
11164 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11165 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11166 function of operand parsing, so this function doesn't need to be called.
11167 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11168
11169static enum neon_shape
037e8744 11170neon_select_shape (enum neon_shape shape, ...)
5287ad62 11171{
037e8744
JB
11172 va_list ap;
11173 enum neon_shape first_shape = shape;
5287ad62
JB
11174
11175 /* Fix missing optional operands. FIXME: we don't know at this point how
11176 many arguments we should have, so this makes the assumption that we have
11177 > 1. This is true of all current Neon opcodes, I think, but may not be
11178 true in the future. */
11179 if (!inst.operands[1].present)
11180 inst.operands[1] = inst.operands[0];
11181
037e8744 11182 va_start (ap, shape);
5f4273c7 11183
037e8744
JB
11184 for (; shape != NS_NULL; shape = va_arg (ap, int))
11185 {
11186 unsigned j;
11187 int matches = 1;
11188
11189 for (j = 0; j < neon_shape_tab[shape].els; j++)
11190 {
11191 if (!inst.operands[j].present)
11192 {
11193 matches = 0;
11194 break;
11195 }
11196
11197 switch (neon_shape_tab[shape].el[j])
11198 {
11199 case SE_F:
11200 if (!(inst.operands[j].isreg
11201 && inst.operands[j].isvec
11202 && inst.operands[j].issingle
11203 && !inst.operands[j].isquad))
11204 matches = 0;
11205 break;
11206
11207 case SE_D:
11208 if (!(inst.operands[j].isreg
11209 && inst.operands[j].isvec
11210 && !inst.operands[j].isquad
11211 && !inst.operands[j].issingle))
11212 matches = 0;
11213 break;
11214
11215 case SE_R:
11216 if (!(inst.operands[j].isreg
11217 && !inst.operands[j].isvec))
11218 matches = 0;
11219 break;
11220
11221 case SE_Q:
11222 if (!(inst.operands[j].isreg
11223 && inst.operands[j].isvec
11224 && inst.operands[j].isquad
11225 && !inst.operands[j].issingle))
11226 matches = 0;
11227 break;
11228
11229 case SE_I:
11230 if (!(!inst.operands[j].isreg
11231 && !inst.operands[j].isscalar))
11232 matches = 0;
11233 break;
11234
11235 case SE_S:
11236 if (!(!inst.operands[j].isreg
11237 && inst.operands[j].isscalar))
11238 matches = 0;
11239 break;
11240
11241 case SE_L:
11242 break;
11243 }
11244 }
11245 if (matches)
5287ad62 11246 break;
037e8744 11247 }
5f4273c7 11248
037e8744 11249 va_end (ap);
5287ad62 11250
037e8744
JB
11251 if (shape == NS_NULL && first_shape != NS_NULL)
11252 first_error (_("invalid instruction shape"));
5287ad62 11253
037e8744
JB
11254 return shape;
11255}
5287ad62 11256
037e8744
JB
11257/* True if SHAPE is predominantly a quadword operation (most of the time, this
11258 means the Q bit should be set). */
11259
11260static int
11261neon_quad (enum neon_shape shape)
11262{
11263 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11264}
037e8744 11265
5287ad62
JB
11266static void
11267neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11268 unsigned *g_size)
11269{
11270 /* Allow modification to be made to types which are constrained to be
11271 based on the key element, based on bits set alongside N_EQK. */
11272 if ((typebits & N_EQK) != 0)
11273 {
11274 if ((typebits & N_HLF) != 0)
11275 *g_size /= 2;
11276 else if ((typebits & N_DBL) != 0)
11277 *g_size *= 2;
11278 if ((typebits & N_SGN) != 0)
11279 *g_type = NT_signed;
11280 else if ((typebits & N_UNS) != 0)
11281 *g_type = NT_unsigned;
11282 else if ((typebits & N_INT) != 0)
11283 *g_type = NT_integer;
11284 else if ((typebits & N_FLT) != 0)
11285 *g_type = NT_float;
dcbf9037
JB
11286 else if ((typebits & N_SIZ) != 0)
11287 *g_type = NT_untyped;
5287ad62
JB
11288 }
11289}
5f4273c7 11290
5287ad62
JB
11291/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11292 operand type, i.e. the single type specified in a Neon instruction when it
11293 is the only one given. */
11294
11295static struct neon_type_el
11296neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11297{
11298 struct neon_type_el dest = *key;
5f4273c7 11299
5287ad62 11300 assert ((thisarg & N_EQK) != 0);
5f4273c7 11301
5287ad62
JB
11302 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11303
11304 return dest;
11305}
11306
11307/* Convert Neon type and size into compact bitmask representation. */
11308
11309static enum neon_type_mask
11310type_chk_of_el_type (enum neon_el_type type, unsigned size)
11311{
11312 switch (type)
11313 {
11314 case NT_untyped:
11315 switch (size)
11316 {
11317 case 8: return N_8;
11318 case 16: return N_16;
11319 case 32: return N_32;
11320 case 64: return N_64;
11321 default: ;
11322 }
11323 break;
11324
11325 case NT_integer:
11326 switch (size)
11327 {
11328 case 8: return N_I8;
11329 case 16: return N_I16;
11330 case 32: return N_I32;
11331 case 64: return N_I64;
11332 default: ;
11333 }
11334 break;
11335
11336 case NT_float:
037e8744
JB
11337 switch (size)
11338 {
8e79c3df 11339 case 16: return N_F16;
037e8744
JB
11340 case 32: return N_F32;
11341 case 64: return N_F64;
11342 default: ;
11343 }
5287ad62
JB
11344 break;
11345
11346 case NT_poly:
11347 switch (size)
11348 {
11349 case 8: return N_P8;
11350 case 16: return N_P16;
11351 default: ;
11352 }
11353 break;
11354
11355 case NT_signed:
11356 switch (size)
11357 {
11358 case 8: return N_S8;
11359 case 16: return N_S16;
11360 case 32: return N_S32;
11361 case 64: return N_S64;
11362 default: ;
11363 }
11364 break;
11365
11366 case NT_unsigned:
11367 switch (size)
11368 {
11369 case 8: return N_U8;
11370 case 16: return N_U16;
11371 case 32: return N_U32;
11372 case 64: return N_U64;
11373 default: ;
11374 }
11375 break;
11376
11377 default: ;
11378 }
5f4273c7 11379
5287ad62
JB
11380 return N_UTYP;
11381}
11382
11383/* Convert compact Neon bitmask type representation to a type and size. Only
11384 handles the case where a single bit is set in the mask. */
11385
dcbf9037 11386static int
5287ad62
JB
11387el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11388 enum neon_type_mask mask)
11389{
dcbf9037
JB
11390 if ((mask & N_EQK) != 0)
11391 return FAIL;
11392
5287ad62
JB
11393 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11394 *size = 8;
dcbf9037 11395 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11396 *size = 16;
dcbf9037 11397 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11398 *size = 32;
037e8744 11399 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11400 *size = 64;
dcbf9037
JB
11401 else
11402 return FAIL;
11403
5287ad62
JB
11404 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11405 *type = NT_signed;
dcbf9037 11406 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11407 *type = NT_unsigned;
dcbf9037 11408 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11409 *type = NT_integer;
dcbf9037 11410 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11411 *type = NT_untyped;
dcbf9037 11412 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11413 *type = NT_poly;
037e8744 11414 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11415 *type = NT_float;
dcbf9037
JB
11416 else
11417 return FAIL;
5f4273c7 11418
dcbf9037 11419 return SUCCESS;
5287ad62
JB
11420}
11421
11422/* Modify a bitmask of allowed types. This is only needed for type
11423 relaxation. */
11424
11425static unsigned
11426modify_types_allowed (unsigned allowed, unsigned mods)
11427{
11428 unsigned size;
11429 enum neon_el_type type;
11430 unsigned destmask;
11431 int i;
5f4273c7 11432
5287ad62 11433 destmask = 0;
5f4273c7 11434
5287ad62
JB
11435 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11436 {
dcbf9037
JB
11437 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11438 {
11439 neon_modify_type_size (mods, &type, &size);
11440 destmask |= type_chk_of_el_type (type, size);
11441 }
5287ad62 11442 }
5f4273c7 11443
5287ad62
JB
11444 return destmask;
11445}
11446
11447/* Check type and return type classification.
11448 The manual states (paraphrase): If one datatype is given, it indicates the
11449 type given in:
11450 - the second operand, if there is one
11451 - the operand, if there is no second operand
11452 - the result, if there are no operands.
11453 This isn't quite good enough though, so we use a concept of a "key" datatype
11454 which is set on a per-instruction basis, which is the one which matters when
11455 only one data type is written.
11456 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11457 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11458
11459static struct neon_type_el
11460neon_check_type (unsigned els, enum neon_shape ns, ...)
11461{
11462 va_list ap;
11463 unsigned i, pass, key_el = 0;
11464 unsigned types[NEON_MAX_TYPE_ELS];
11465 enum neon_el_type k_type = NT_invtype;
11466 unsigned k_size = -1u;
11467 struct neon_type_el badtype = {NT_invtype, -1};
11468 unsigned key_allowed = 0;
11469
11470 /* Optional registers in Neon instructions are always (not) in operand 1.
11471 Fill in the missing operand here, if it was omitted. */
11472 if (els > 1 && !inst.operands[1].present)
11473 inst.operands[1] = inst.operands[0];
11474
11475 /* Suck up all the varargs. */
11476 va_start (ap, ns);
11477 for (i = 0; i < els; i++)
11478 {
11479 unsigned thisarg = va_arg (ap, unsigned);
11480 if (thisarg == N_IGNORE_TYPE)
11481 {
11482 va_end (ap);
11483 return badtype;
11484 }
11485 types[i] = thisarg;
11486 if ((thisarg & N_KEY) != 0)
11487 key_el = i;
11488 }
11489 va_end (ap);
11490
dcbf9037
JB
11491 if (inst.vectype.elems > 0)
11492 for (i = 0; i < els; i++)
11493 if (inst.operands[i].vectype.type != NT_invtype)
11494 {
11495 first_error (_("types specified in both the mnemonic and operands"));
11496 return badtype;
11497 }
11498
5287ad62
JB
11499 /* Duplicate inst.vectype elements here as necessary.
11500 FIXME: No idea if this is exactly the same as the ARM assembler,
11501 particularly when an insn takes one register and one non-register
11502 operand. */
11503 if (inst.vectype.elems == 1 && els > 1)
11504 {
11505 unsigned j;
11506 inst.vectype.elems = els;
11507 inst.vectype.el[key_el] = inst.vectype.el[0];
11508 for (j = 0; j < els; j++)
dcbf9037
JB
11509 if (j != key_el)
11510 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11511 types[j]);
11512 }
11513 else if (inst.vectype.elems == 0 && els > 0)
11514 {
11515 unsigned j;
11516 /* No types were given after the mnemonic, so look for types specified
11517 after each operand. We allow some flexibility here; as long as the
11518 "key" operand has a type, we can infer the others. */
11519 for (j = 0; j < els; j++)
11520 if (inst.operands[j].vectype.type != NT_invtype)
11521 inst.vectype.el[j] = inst.operands[j].vectype;
11522
11523 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11524 {
dcbf9037
JB
11525 for (j = 0; j < els; j++)
11526 if (inst.operands[j].vectype.type == NT_invtype)
11527 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11528 types[j]);
11529 }
11530 else
11531 {
11532 first_error (_("operand types can't be inferred"));
11533 return badtype;
5287ad62
JB
11534 }
11535 }
11536 else if (inst.vectype.elems != els)
11537 {
dcbf9037 11538 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11539 return badtype;
11540 }
11541
11542 for (pass = 0; pass < 2; pass++)
11543 {
11544 for (i = 0; i < els; i++)
11545 {
11546 unsigned thisarg = types[i];
11547 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11548 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11549 enum neon_el_type g_type = inst.vectype.el[i].type;
11550 unsigned g_size = inst.vectype.el[i].size;
11551
11552 /* Decay more-specific signed & unsigned types to sign-insensitive
11553 integer types if sign-specific variants are unavailable. */
11554 if ((g_type == NT_signed || g_type == NT_unsigned)
11555 && (types_allowed & N_SU_ALL) == 0)
11556 g_type = NT_integer;
11557
11558 /* If only untyped args are allowed, decay any more specific types to
11559 them. Some instructions only care about signs for some element
11560 sizes, so handle that properly. */
11561 if ((g_size == 8 && (types_allowed & N_8) != 0)
11562 || (g_size == 16 && (types_allowed & N_16) != 0)
11563 || (g_size == 32 && (types_allowed & N_32) != 0)
11564 || (g_size == 64 && (types_allowed & N_64) != 0))
11565 g_type = NT_untyped;
11566
11567 if (pass == 0)
11568 {
11569 if ((thisarg & N_KEY) != 0)
11570 {
11571 k_type = g_type;
11572 k_size = g_size;
11573 key_allowed = thisarg & ~N_KEY;
11574 }
11575 }
11576 else
11577 {
037e8744
JB
11578 if ((thisarg & N_VFP) != 0)
11579 {
11580 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11581 unsigned regwidth = neon_shape_el_size[regshape], match;
11582
11583 /* In VFP mode, operands must match register widths. If we
11584 have a key operand, use its width, else use the width of
11585 the current operand. */
11586 if (k_size != -1u)
11587 match = k_size;
11588 else
11589 match = g_size;
11590
11591 if (regwidth != match)
11592 {
11593 first_error (_("operand size must match register width"));
11594 return badtype;
11595 }
11596 }
5f4273c7 11597
5287ad62
JB
11598 if ((thisarg & N_EQK) == 0)
11599 {
11600 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11601
11602 if ((given_type & types_allowed) == 0)
11603 {
dcbf9037 11604 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11605 return badtype;
11606 }
11607 }
11608 else
11609 {
11610 enum neon_el_type mod_k_type = k_type;
11611 unsigned mod_k_size = k_size;
11612 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11613 if (g_type != mod_k_type || g_size != mod_k_size)
11614 {
dcbf9037 11615 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11616 return badtype;
11617 }
11618 }
11619 }
11620 }
11621 }
11622
11623 return inst.vectype.el[key_el];
11624}
11625
037e8744 11626/* Neon-style VFP instruction forwarding. */
5287ad62 11627
037e8744
JB
11628/* Thumb VFP instructions have 0xE in the condition field. */
11629
11630static void
11631do_vfp_cond_or_thumb (void)
5287ad62
JB
11632{
11633 if (thumb_mode)
037e8744 11634 inst.instruction |= 0xe0000000;
5287ad62 11635 else
037e8744 11636 inst.instruction |= inst.cond << 28;
5287ad62
JB
11637}
11638
037e8744
JB
11639/* Look up and encode a simple mnemonic, for use as a helper function for the
11640 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11641 etc. It is assumed that operand parsing has already been done, and that the
11642 operands are in the form expected by the given opcode (this isn't necessarily
11643 the same as the form in which they were parsed, hence some massaging must
11644 take place before this function is called).
11645 Checks current arch version against that in the looked-up opcode. */
5287ad62 11646
037e8744
JB
11647static void
11648do_vfp_nsyn_opcode (const char *opname)
5287ad62 11649{
037e8744 11650 const struct asm_opcode *opcode;
5f4273c7 11651
037e8744 11652 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11653
037e8744
JB
11654 if (!opcode)
11655 abort ();
5287ad62 11656
037e8744
JB
11657 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11658 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11659 _(BAD_FPU));
5287ad62 11660
037e8744
JB
11661 if (thumb_mode)
11662 {
11663 inst.instruction = opcode->tvalue;
11664 opcode->tencode ();
11665 }
11666 else
11667 {
11668 inst.instruction = (inst.cond << 28) | opcode->avalue;
11669 opcode->aencode ();
11670 }
11671}
5287ad62
JB
11672
11673static void
037e8744 11674do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11675{
037e8744
JB
11676 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11677
11678 if (rs == NS_FFF)
11679 {
11680 if (is_add)
11681 do_vfp_nsyn_opcode ("fadds");
11682 else
11683 do_vfp_nsyn_opcode ("fsubs");
11684 }
11685 else
11686 {
11687 if (is_add)
11688 do_vfp_nsyn_opcode ("faddd");
11689 else
11690 do_vfp_nsyn_opcode ("fsubd");
11691 }
11692}
11693
11694/* Check operand types to see if this is a VFP instruction, and if so call
11695 PFN (). */
11696
11697static int
11698try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11699{
11700 enum neon_shape rs;
11701 struct neon_type_el et;
11702
11703 switch (args)
11704 {
11705 case 2:
11706 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11707 et = neon_check_type (2, rs,
11708 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11709 break;
5f4273c7 11710
037e8744
JB
11711 case 3:
11712 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11713 et = neon_check_type (3, rs,
11714 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11715 break;
11716
11717 default:
11718 abort ();
11719 }
11720
11721 if (et.type != NT_invtype)
11722 {
11723 pfn (rs);
11724 return SUCCESS;
11725 }
11726 else
11727 inst.error = NULL;
11728
11729 return FAIL;
11730}
11731
11732static void
11733do_vfp_nsyn_mla_mls (enum neon_shape rs)
11734{
11735 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11736
037e8744
JB
11737 if (rs == NS_FFF)
11738 {
11739 if (is_mla)
11740 do_vfp_nsyn_opcode ("fmacs");
11741 else
11742 do_vfp_nsyn_opcode ("fmscs");
11743 }
11744 else
11745 {
11746 if (is_mla)
11747 do_vfp_nsyn_opcode ("fmacd");
11748 else
11749 do_vfp_nsyn_opcode ("fmscd");
11750 }
11751}
11752
11753static void
11754do_vfp_nsyn_mul (enum neon_shape rs)
11755{
11756 if (rs == NS_FFF)
11757 do_vfp_nsyn_opcode ("fmuls");
11758 else
11759 do_vfp_nsyn_opcode ("fmuld");
11760}
11761
11762static void
11763do_vfp_nsyn_abs_neg (enum neon_shape rs)
11764{
11765 int is_neg = (inst.instruction & 0x80) != 0;
11766 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11767
11768 if (rs == NS_FF)
11769 {
11770 if (is_neg)
11771 do_vfp_nsyn_opcode ("fnegs");
11772 else
11773 do_vfp_nsyn_opcode ("fabss");
11774 }
11775 else
11776 {
11777 if (is_neg)
11778 do_vfp_nsyn_opcode ("fnegd");
11779 else
11780 do_vfp_nsyn_opcode ("fabsd");
11781 }
11782}
11783
11784/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11785 insns belong to Neon, and are handled elsewhere. */
11786
11787static void
11788do_vfp_nsyn_ldm_stm (int is_dbmode)
11789{
11790 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11791 if (is_ldm)
11792 {
11793 if (is_dbmode)
11794 do_vfp_nsyn_opcode ("fldmdbs");
11795 else
11796 do_vfp_nsyn_opcode ("fldmias");
11797 }
11798 else
11799 {
11800 if (is_dbmode)
11801 do_vfp_nsyn_opcode ("fstmdbs");
11802 else
11803 do_vfp_nsyn_opcode ("fstmias");
11804 }
11805}
11806
037e8744
JB
11807static void
11808do_vfp_nsyn_sqrt (void)
11809{
11810 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11811 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11812
037e8744
JB
11813 if (rs == NS_FF)
11814 do_vfp_nsyn_opcode ("fsqrts");
11815 else
11816 do_vfp_nsyn_opcode ("fsqrtd");
11817}
11818
11819static void
11820do_vfp_nsyn_div (void)
11821{
11822 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11823 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11824 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11825
037e8744
JB
11826 if (rs == NS_FFF)
11827 do_vfp_nsyn_opcode ("fdivs");
11828 else
11829 do_vfp_nsyn_opcode ("fdivd");
11830}
11831
11832static void
11833do_vfp_nsyn_nmul (void)
11834{
11835 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11836 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11837 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11838
037e8744
JB
11839 if (rs == NS_FFF)
11840 {
11841 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11842 do_vfp_sp_dyadic ();
11843 }
11844 else
11845 {
11846 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11847 do_vfp_dp_rd_rn_rm ();
11848 }
11849 do_vfp_cond_or_thumb ();
11850}
11851
11852static void
11853do_vfp_nsyn_cmp (void)
11854{
11855 if (inst.operands[1].isreg)
11856 {
11857 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11858 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11859
037e8744
JB
11860 if (rs == NS_FF)
11861 {
11862 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11863 do_vfp_sp_monadic ();
11864 }
11865 else
11866 {
11867 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11868 do_vfp_dp_rd_rm ();
11869 }
11870 }
11871 else
11872 {
11873 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11874 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11875
11876 switch (inst.instruction & 0x0fffffff)
11877 {
11878 case N_MNEM_vcmp:
11879 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11880 break;
11881 case N_MNEM_vcmpe:
11882 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11883 break;
11884 default:
11885 abort ();
11886 }
5f4273c7 11887
037e8744
JB
11888 if (rs == NS_FI)
11889 {
11890 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11891 do_vfp_sp_compare_z ();
11892 }
11893 else
11894 {
11895 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11896 do_vfp_dp_rd ();
11897 }
11898 }
11899 do_vfp_cond_or_thumb ();
11900}
11901
11902static void
11903nsyn_insert_sp (void)
11904{
11905 inst.operands[1] = inst.operands[0];
11906 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 11907 inst.operands[0].reg = REG_SP;
037e8744
JB
11908 inst.operands[0].isreg = 1;
11909 inst.operands[0].writeback = 1;
11910 inst.operands[0].present = 1;
11911}
11912
11913static void
11914do_vfp_nsyn_push (void)
11915{
11916 nsyn_insert_sp ();
11917 if (inst.operands[1].issingle)
11918 do_vfp_nsyn_opcode ("fstmdbs");
11919 else
11920 do_vfp_nsyn_opcode ("fstmdbd");
11921}
11922
11923static void
11924do_vfp_nsyn_pop (void)
11925{
11926 nsyn_insert_sp ();
11927 if (inst.operands[1].issingle)
22b5b651 11928 do_vfp_nsyn_opcode ("fldmias");
037e8744 11929 else
22b5b651 11930 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11931}
11932
11933/* Fix up Neon data-processing instructions, ORing in the correct bits for
11934 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11935
11936static unsigned
11937neon_dp_fixup (unsigned i)
11938{
11939 if (thumb_mode)
11940 {
11941 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11942 if (i & (1 << 24))
11943 i |= 1 << 28;
5f4273c7 11944
037e8744 11945 i &= ~(1 << 24);
5f4273c7 11946
037e8744
JB
11947 i |= 0xef000000;
11948 }
11949 else
11950 i |= 0xf2000000;
5f4273c7 11951
037e8744
JB
11952 return i;
11953}
11954
11955/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11956 (0, 1, 2, 3). */
11957
11958static unsigned
11959neon_logbits (unsigned x)
11960{
11961 return ffs (x) - 4;
11962}
11963
11964#define LOW4(R) ((R) & 0xf)
11965#define HI1(R) (((R) >> 4) & 1)
11966
11967/* Encode insns with bit pattern:
11968
11969 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11970 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11971
037e8744
JB
11972 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11973 different meaning for some instruction. */
11974
11975static void
11976neon_three_same (int isquad, int ubit, int size)
11977{
11978 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11979 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11980 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11981 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11982 inst.instruction |= LOW4 (inst.operands[2].reg);
11983 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11984 inst.instruction |= (isquad != 0) << 6;
11985 inst.instruction |= (ubit != 0) << 24;
11986 if (size != -1)
11987 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11988
037e8744
JB
11989 inst.instruction = neon_dp_fixup (inst.instruction);
11990}
11991
11992/* Encode instructions of the form:
11993
11994 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11995 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11996
11997 Don't write size if SIZE == -1. */
11998
11999static void
12000neon_two_same (int qbit, int ubit, int size)
12001{
12002 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12003 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12004 inst.instruction |= LOW4 (inst.operands[1].reg);
12005 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12006 inst.instruction |= (qbit != 0) << 6;
12007 inst.instruction |= (ubit != 0) << 24;
12008
12009 if (size != -1)
12010 inst.instruction |= neon_logbits (size) << 18;
12011
12012 inst.instruction = neon_dp_fixup (inst.instruction);
12013}
12014
12015/* Neon instruction encoders, in approximate order of appearance. */
12016
12017static void
12018do_neon_dyadic_i_su (void)
12019{
037e8744 12020 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12021 struct neon_type_el et = neon_check_type (3, rs,
12022 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12023 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12024}
12025
12026static void
12027do_neon_dyadic_i64_su (void)
12028{
037e8744 12029 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12030 struct neon_type_el et = neon_check_type (3, rs,
12031 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12032 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12033}
12034
12035static void
12036neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12037 unsigned immbits)
12038{
12039 unsigned size = et.size >> 3;
12040 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12041 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12042 inst.instruction |= LOW4 (inst.operands[1].reg);
12043 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12044 inst.instruction |= (isquad != 0) << 6;
12045 inst.instruction |= immbits << 16;
12046 inst.instruction |= (size >> 3) << 7;
12047 inst.instruction |= (size & 0x7) << 19;
12048 if (write_ubit)
12049 inst.instruction |= (uval != 0) << 24;
12050
12051 inst.instruction = neon_dp_fixup (inst.instruction);
12052}
12053
12054static void
12055do_neon_shl_imm (void)
12056{
12057 if (!inst.operands[2].isreg)
12058 {
037e8744 12059 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12060 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12061 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12062 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12063 }
12064 else
12065 {
037e8744 12066 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12067 struct neon_type_el et = neon_check_type (3, rs,
12068 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12069 unsigned int tmp;
12070
12071 /* VSHL/VQSHL 3-register variants have syntax such as:
12072 vshl.xx Dd, Dm, Dn
12073 whereas other 3-register operations encoded by neon_three_same have
12074 syntax like:
12075 vadd.xx Dd, Dn, Dm
12076 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12077 here. */
12078 tmp = inst.operands[2].reg;
12079 inst.operands[2].reg = inst.operands[1].reg;
12080 inst.operands[1].reg = tmp;
5287ad62 12081 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12082 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12083 }
12084}
12085
12086static void
12087do_neon_qshl_imm (void)
12088{
12089 if (!inst.operands[2].isreg)
12090 {
037e8744 12091 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12092 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12093
5287ad62 12094 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12095 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12096 inst.operands[2].imm);
12097 }
12098 else
12099 {
037e8744 12100 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12101 struct neon_type_el et = neon_check_type (3, rs,
12102 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12103 unsigned int tmp;
12104
12105 /* See note in do_neon_shl_imm. */
12106 tmp = inst.operands[2].reg;
12107 inst.operands[2].reg = inst.operands[1].reg;
12108 inst.operands[1].reg = tmp;
5287ad62 12109 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12110 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12111 }
12112}
12113
627907b7
JB
12114static void
12115do_neon_rshl (void)
12116{
12117 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12118 struct neon_type_el et = neon_check_type (3, rs,
12119 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12120 unsigned int tmp;
12121
12122 tmp = inst.operands[2].reg;
12123 inst.operands[2].reg = inst.operands[1].reg;
12124 inst.operands[1].reg = tmp;
12125 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12126}
12127
5287ad62
JB
12128static int
12129neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12130{
036dc3f7
PB
12131 /* Handle .I8 pseudo-instructions. */
12132 if (size == 8)
5287ad62 12133 {
5287ad62
JB
12134 /* Unfortunately, this will make everything apart from zero out-of-range.
12135 FIXME is this the intended semantics? There doesn't seem much point in
12136 accepting .I8 if so. */
12137 immediate |= immediate << 8;
12138 size = 16;
036dc3f7
PB
12139 }
12140
12141 if (size >= 32)
12142 {
12143 if (immediate == (immediate & 0x000000ff))
12144 {
12145 *immbits = immediate;
12146 return 0x1;
12147 }
12148 else if (immediate == (immediate & 0x0000ff00))
12149 {
12150 *immbits = immediate >> 8;
12151 return 0x3;
12152 }
12153 else if (immediate == (immediate & 0x00ff0000))
12154 {
12155 *immbits = immediate >> 16;
12156 return 0x5;
12157 }
12158 else if (immediate == (immediate & 0xff000000))
12159 {
12160 *immbits = immediate >> 24;
12161 return 0x7;
12162 }
12163 if ((immediate & 0xffff) != (immediate >> 16))
12164 goto bad_immediate;
12165 immediate &= 0xffff;
5287ad62
JB
12166 }
12167
12168 if (immediate == (immediate & 0x000000ff))
12169 {
12170 *immbits = immediate;
036dc3f7 12171 return 0x9;
5287ad62
JB
12172 }
12173 else if (immediate == (immediate & 0x0000ff00))
12174 {
12175 *immbits = immediate >> 8;
036dc3f7 12176 return 0xb;
5287ad62
JB
12177 }
12178
12179 bad_immediate:
dcbf9037 12180 first_error (_("immediate value out of range"));
5287ad62
JB
12181 return FAIL;
12182}
12183
12184/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12185 A, B, C, D. */
12186
12187static int
12188neon_bits_same_in_bytes (unsigned imm)
12189{
12190 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12191 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12192 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12193 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12194}
12195
12196/* For immediate of above form, return 0bABCD. */
12197
12198static unsigned
12199neon_squash_bits (unsigned imm)
12200{
12201 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12202 | ((imm & 0x01000000) >> 21);
12203}
12204
136da414 12205/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12206
12207static unsigned
12208neon_qfloat_bits (unsigned imm)
12209{
136da414 12210 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12211}
12212
12213/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12214 the instruction. *OP is passed as the initial value of the op field, and
12215 may be set to a different value depending on the constant (i.e.
12216 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12217 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12218 try smaller element sizes. */
5287ad62
JB
12219
12220static int
c96612cc
JB
12221neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12222 unsigned *immbits, int *op, int size,
12223 enum neon_el_type type)
5287ad62 12224{
c96612cc
JB
12225 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12226 float. */
12227 if (type == NT_float && !float_p)
12228 return FAIL;
12229
136da414
JB
12230 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12231 {
12232 if (size != 32 || *op == 1)
12233 return FAIL;
12234 *immbits = neon_qfloat_bits (immlo);
12235 return 0xf;
12236 }
036dc3f7
PB
12237
12238 if (size == 64)
5287ad62 12239 {
036dc3f7
PB
12240 if (neon_bits_same_in_bytes (immhi)
12241 && neon_bits_same_in_bytes (immlo))
12242 {
12243 if (*op == 1)
12244 return FAIL;
12245 *immbits = (neon_squash_bits (immhi) << 4)
12246 | neon_squash_bits (immlo);
12247 *op = 1;
12248 return 0xe;
12249 }
12250
12251 if (immhi != immlo)
12252 return FAIL;
5287ad62 12253 }
036dc3f7
PB
12254
12255 if (size >= 32)
5287ad62 12256 {
036dc3f7
PB
12257 if (immlo == (immlo & 0x000000ff))
12258 {
12259 *immbits = immlo;
12260 return 0x0;
12261 }
12262 else if (immlo == (immlo & 0x0000ff00))
12263 {
12264 *immbits = immlo >> 8;
12265 return 0x2;
12266 }
12267 else if (immlo == (immlo & 0x00ff0000))
12268 {
12269 *immbits = immlo >> 16;
12270 return 0x4;
12271 }
12272 else if (immlo == (immlo & 0xff000000))
12273 {
12274 *immbits = immlo >> 24;
12275 return 0x6;
12276 }
12277 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12278 {
12279 *immbits = (immlo >> 8) & 0xff;
12280 return 0xc;
12281 }
12282 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12283 {
12284 *immbits = (immlo >> 16) & 0xff;
12285 return 0xd;
12286 }
12287
12288 if ((immlo & 0xffff) != (immlo >> 16))
12289 return FAIL;
12290 immlo &= 0xffff;
5287ad62 12291 }
036dc3f7
PB
12292
12293 if (size >= 16)
5287ad62 12294 {
036dc3f7
PB
12295 if (immlo == (immlo & 0x000000ff))
12296 {
12297 *immbits = immlo;
12298 return 0x8;
12299 }
12300 else if (immlo == (immlo & 0x0000ff00))
12301 {
12302 *immbits = immlo >> 8;
12303 return 0xa;
12304 }
12305
12306 if ((immlo & 0xff) != (immlo >> 8))
12307 return FAIL;
12308 immlo &= 0xff;
5287ad62 12309 }
036dc3f7
PB
12310
12311 if (immlo == (immlo & 0x000000ff))
5287ad62 12312 {
036dc3f7
PB
12313 /* Don't allow MVN with 8-bit immediate. */
12314 if (*op == 1)
12315 return FAIL;
12316 *immbits = immlo;
12317 return 0xe;
5287ad62 12318 }
5287ad62
JB
12319
12320 return FAIL;
12321}
12322
12323/* Write immediate bits [7:0] to the following locations:
12324
12325 |28/24|23 19|18 16|15 4|3 0|
12326 | 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|
12327
12328 This function is used by VMOV/VMVN/VORR/VBIC. */
12329
12330static void
12331neon_write_immbits (unsigned immbits)
12332{
12333 inst.instruction |= immbits & 0xf;
12334 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12335 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12336}
12337
12338/* Invert low-order SIZE bits of XHI:XLO. */
12339
12340static void
12341neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12342{
12343 unsigned immlo = xlo ? *xlo : 0;
12344 unsigned immhi = xhi ? *xhi : 0;
12345
12346 switch (size)
12347 {
12348 case 8:
12349 immlo = (~immlo) & 0xff;
12350 break;
12351
12352 case 16:
12353 immlo = (~immlo) & 0xffff;
12354 break;
12355
12356 case 64:
12357 immhi = (~immhi) & 0xffffffff;
12358 /* fall through. */
12359
12360 case 32:
12361 immlo = (~immlo) & 0xffffffff;
12362 break;
12363
12364 default:
12365 abort ();
12366 }
12367
12368 if (xlo)
12369 *xlo = immlo;
12370
12371 if (xhi)
12372 *xhi = immhi;
12373}
12374
12375static void
12376do_neon_logic (void)
12377{
12378 if (inst.operands[2].present && inst.operands[2].isreg)
12379 {
037e8744 12380 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12381 neon_check_type (3, rs, N_IGNORE_TYPE);
12382 /* U bit and size field were set as part of the bitmask. */
12383 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12384 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12385 }
12386 else
12387 {
037e8744
JB
12388 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12389 struct neon_type_el et = neon_check_type (2, rs,
12390 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
12391 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12392 unsigned immbits;
12393 int cmode;
5f4273c7 12394
5287ad62
JB
12395 if (et.type == NT_invtype)
12396 return;
5f4273c7 12397
5287ad62
JB
12398 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12399
036dc3f7
PB
12400 immbits = inst.operands[1].imm;
12401 if (et.size == 64)
12402 {
12403 /* .i64 is a pseudo-op, so the immediate must be a repeating
12404 pattern. */
12405 if (immbits != (inst.operands[1].regisimm ?
12406 inst.operands[1].reg : 0))
12407 {
12408 /* Set immbits to an invalid constant. */
12409 immbits = 0xdeadbeef;
12410 }
12411 }
12412
5287ad62
JB
12413 switch (opcode)
12414 {
12415 case N_MNEM_vbic:
036dc3f7 12416 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12417 break;
5f4273c7 12418
5287ad62 12419 case N_MNEM_vorr:
036dc3f7 12420 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12421 break;
5f4273c7 12422
5287ad62
JB
12423 case N_MNEM_vand:
12424 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12425 neon_invert_size (&immbits, 0, et.size);
12426 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12427 break;
5f4273c7 12428
5287ad62
JB
12429 case N_MNEM_vorn:
12430 /* Pseudo-instruction for VORR. */
5287ad62
JB
12431 neon_invert_size (&immbits, 0, et.size);
12432 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12433 break;
5f4273c7 12434
5287ad62
JB
12435 default:
12436 abort ();
12437 }
12438
12439 if (cmode == FAIL)
12440 return;
12441
037e8744 12442 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12443 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12444 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12445 inst.instruction |= cmode << 8;
12446 neon_write_immbits (immbits);
5f4273c7 12447
5287ad62
JB
12448 inst.instruction = neon_dp_fixup (inst.instruction);
12449 }
12450}
12451
12452static void
12453do_neon_bitfield (void)
12454{
037e8744 12455 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12456 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12457 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12458}
12459
12460static void
dcbf9037
JB
12461neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12462 unsigned destbits)
5287ad62 12463{
037e8744 12464 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12465 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12466 types | N_KEY);
5287ad62
JB
12467 if (et.type == NT_float)
12468 {
12469 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12470 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12471 }
12472 else
12473 {
12474 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12475 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12476 }
12477}
12478
12479static void
12480do_neon_dyadic_if_su (void)
12481{
dcbf9037 12482 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12483}
12484
12485static void
12486do_neon_dyadic_if_su_d (void)
12487{
12488 /* This version only allow D registers, but that constraint is enforced during
12489 operand parsing so we don't need to do anything extra here. */
dcbf9037 12490 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12491}
12492
5287ad62
JB
12493static void
12494do_neon_dyadic_if_i_d (void)
12495{
428e3f1f
PB
12496 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12497 affected if we specify unsigned args. */
12498 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12499}
12500
037e8744
JB
12501enum vfp_or_neon_is_neon_bits
12502{
12503 NEON_CHECK_CC = 1,
12504 NEON_CHECK_ARCH = 2
12505};
12506
12507/* Call this function if an instruction which may have belonged to the VFP or
12508 Neon instruction sets, but turned out to be a Neon instruction (due to the
12509 operand types involved, etc.). We have to check and/or fix-up a couple of
12510 things:
12511
12512 - Make sure the user hasn't attempted to make a Neon instruction
12513 conditional.
12514 - Alter the value in the condition code field if necessary.
12515 - Make sure that the arch supports Neon instructions.
12516
12517 Which of these operations take place depends on bits from enum
12518 vfp_or_neon_is_neon_bits.
12519
12520 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12521 current instruction's condition is COND_ALWAYS, the condition field is
12522 changed to inst.uncond_value. This is necessary because instructions shared
12523 between VFP and Neon may be conditional for the VFP variants only, and the
12524 unconditional Neon version must have, e.g., 0xF in the condition field. */
12525
12526static int
12527vfp_or_neon_is_neon (unsigned check)
12528{
12529 /* Conditions are always legal in Thumb mode (IT blocks). */
12530 if (!thumb_mode && (check & NEON_CHECK_CC))
12531 {
12532 if (inst.cond != COND_ALWAYS)
12533 {
12534 first_error (_(BAD_COND));
12535 return FAIL;
12536 }
12537 if (inst.uncond_value != -1)
12538 inst.instruction |= inst.uncond_value << 28;
12539 }
5f4273c7 12540
037e8744
JB
12541 if ((check & NEON_CHECK_ARCH)
12542 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12543 {
12544 first_error (_(BAD_FPU));
12545 return FAIL;
12546 }
5f4273c7 12547
037e8744
JB
12548 return SUCCESS;
12549}
12550
5287ad62
JB
12551static void
12552do_neon_addsub_if_i (void)
12553{
037e8744
JB
12554 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12555 return;
12556
12557 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12558 return;
12559
5287ad62
JB
12560 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12561 affected if we specify unsigned args. */
dcbf9037 12562 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12563}
12564
12565/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12566 result to be:
12567 V<op> A,B (A is operand 0, B is operand 2)
12568 to mean:
12569 V<op> A,B,A
12570 not:
12571 V<op> A,B,B
12572 so handle that case specially. */
12573
12574static void
12575neon_exchange_operands (void)
12576{
12577 void *scratch = alloca (sizeof (inst.operands[0]));
12578 if (inst.operands[1].present)
12579 {
12580 /* Swap operands[1] and operands[2]. */
12581 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12582 inst.operands[1] = inst.operands[2];
12583 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12584 }
12585 else
12586 {
12587 inst.operands[1] = inst.operands[2];
12588 inst.operands[2] = inst.operands[0];
12589 }
12590}
12591
12592static void
12593neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12594{
12595 if (inst.operands[2].isreg)
12596 {
12597 if (invert)
12598 neon_exchange_operands ();
dcbf9037 12599 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12600 }
12601 else
12602 {
037e8744 12603 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12604 struct neon_type_el et = neon_check_type (2, rs,
12605 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12606
12607 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12608 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12609 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12610 inst.instruction |= LOW4 (inst.operands[1].reg);
12611 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12612 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12613 inst.instruction |= (et.type == NT_float) << 10;
12614 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12615
5287ad62
JB
12616 inst.instruction = neon_dp_fixup (inst.instruction);
12617 }
12618}
12619
12620static void
12621do_neon_cmp (void)
12622{
12623 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12624}
12625
12626static void
12627do_neon_cmp_inv (void)
12628{
12629 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12630}
12631
12632static void
12633do_neon_ceq (void)
12634{
12635 neon_compare (N_IF_32, N_IF_32, FALSE);
12636}
12637
12638/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12639 scalars, which are encoded in 5 bits, M : Rm.
12640 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12641 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12642 index in M. */
12643
12644static unsigned
12645neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12646{
dcbf9037
JB
12647 unsigned regno = NEON_SCALAR_REG (scalar);
12648 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12649
12650 switch (elsize)
12651 {
12652 case 16:
12653 if (regno > 7 || elno > 3)
12654 goto bad_scalar;
12655 return regno | (elno << 3);
5f4273c7 12656
5287ad62
JB
12657 case 32:
12658 if (regno > 15 || elno > 1)
12659 goto bad_scalar;
12660 return regno | (elno << 4);
12661
12662 default:
12663 bad_scalar:
dcbf9037 12664 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12665 }
12666
12667 return 0;
12668}
12669
12670/* Encode multiply / multiply-accumulate scalar instructions. */
12671
12672static void
12673neon_mul_mac (struct neon_type_el et, int ubit)
12674{
dcbf9037
JB
12675 unsigned scalar;
12676
12677 /* Give a more helpful error message if we have an invalid type. */
12678 if (et.type == NT_invtype)
12679 return;
5f4273c7 12680
dcbf9037 12681 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12682 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12683 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12684 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12685 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12686 inst.instruction |= LOW4 (scalar);
12687 inst.instruction |= HI1 (scalar) << 5;
12688 inst.instruction |= (et.type == NT_float) << 8;
12689 inst.instruction |= neon_logbits (et.size) << 20;
12690 inst.instruction |= (ubit != 0) << 24;
12691
12692 inst.instruction = neon_dp_fixup (inst.instruction);
12693}
12694
12695static void
12696do_neon_mac_maybe_scalar (void)
12697{
037e8744
JB
12698 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12699 return;
12700
12701 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12702 return;
12703
5287ad62
JB
12704 if (inst.operands[2].isscalar)
12705 {
037e8744 12706 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12707 struct neon_type_el et = neon_check_type (3, rs,
12708 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12709 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12710 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12711 }
12712 else
428e3f1f
PB
12713 {
12714 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12715 affected if we specify unsigned args. */
12716 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12717 }
5287ad62
JB
12718}
12719
12720static void
12721do_neon_tst (void)
12722{
037e8744 12723 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12724 struct neon_type_el et = neon_check_type (3, rs,
12725 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12726 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12727}
12728
12729/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12730 same types as the MAC equivalents. The polynomial type for this instruction
12731 is encoded the same as the integer type. */
12732
12733static void
12734do_neon_mul (void)
12735{
037e8744
JB
12736 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12737 return;
12738
12739 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12740 return;
12741
5287ad62
JB
12742 if (inst.operands[2].isscalar)
12743 do_neon_mac_maybe_scalar ();
12744 else
dcbf9037 12745 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12746}
12747
12748static void
12749do_neon_qdmulh (void)
12750{
12751 if (inst.operands[2].isscalar)
12752 {
037e8744 12753 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12754 struct neon_type_el et = neon_check_type (3, rs,
12755 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12756 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12757 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12758 }
12759 else
12760 {
037e8744 12761 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12762 struct neon_type_el et = neon_check_type (3, rs,
12763 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12764 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12765 /* The U bit (rounding) comes from bit mask. */
037e8744 12766 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12767 }
12768}
12769
12770static void
12771do_neon_fcmp_absolute (void)
12772{
037e8744 12773 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12774 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12775 /* Size field comes from bit mask. */
037e8744 12776 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12777}
12778
12779static void
12780do_neon_fcmp_absolute_inv (void)
12781{
12782 neon_exchange_operands ();
12783 do_neon_fcmp_absolute ();
12784}
12785
12786static void
12787do_neon_step (void)
12788{
037e8744 12789 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12790 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12791 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12792}
12793
12794static void
12795do_neon_abs_neg (void)
12796{
037e8744
JB
12797 enum neon_shape rs;
12798 struct neon_type_el et;
5f4273c7 12799
037e8744
JB
12800 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12801 return;
12802
12803 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12804 return;
12805
12806 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12807 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12808
5287ad62
JB
12809 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12810 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12811 inst.instruction |= LOW4 (inst.operands[1].reg);
12812 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12813 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12814 inst.instruction |= (et.type == NT_float) << 10;
12815 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12816
5287ad62
JB
12817 inst.instruction = neon_dp_fixup (inst.instruction);
12818}
12819
12820static void
12821do_neon_sli (void)
12822{
037e8744 12823 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12824 struct neon_type_el et = neon_check_type (2, rs,
12825 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12826 int imm = inst.operands[2].imm;
12827 constraint (imm < 0 || (unsigned)imm >= et.size,
12828 _("immediate out of range for insert"));
037e8744 12829 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12830}
12831
12832static void
12833do_neon_sri (void)
12834{
037e8744 12835 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12836 struct neon_type_el et = neon_check_type (2, rs,
12837 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12838 int imm = inst.operands[2].imm;
12839 constraint (imm < 1 || (unsigned)imm > et.size,
12840 _("immediate out of range for insert"));
037e8744 12841 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12842}
12843
12844static void
12845do_neon_qshlu_imm (void)
12846{
037e8744 12847 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12848 struct neon_type_el et = neon_check_type (2, rs,
12849 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12850 int imm = inst.operands[2].imm;
12851 constraint (imm < 0 || (unsigned)imm >= et.size,
12852 _("immediate out of range for shift"));
12853 /* Only encodes the 'U present' variant of the instruction.
12854 In this case, signed types have OP (bit 8) set to 0.
12855 Unsigned types have OP set to 1. */
12856 inst.instruction |= (et.type == NT_unsigned) << 8;
12857 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12858 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12859}
12860
12861static void
12862do_neon_qmovn (void)
12863{
12864 struct neon_type_el et = neon_check_type (2, NS_DQ,
12865 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12866 /* Saturating move where operands can be signed or unsigned, and the
12867 destination has the same signedness. */
12868 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12869 if (et.type == NT_unsigned)
12870 inst.instruction |= 0xc0;
12871 else
12872 inst.instruction |= 0x80;
12873 neon_two_same (0, 1, et.size / 2);
12874}
12875
12876static void
12877do_neon_qmovun (void)
12878{
12879 struct neon_type_el et = neon_check_type (2, NS_DQ,
12880 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12881 /* Saturating move with unsigned results. Operands must be signed. */
12882 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12883 neon_two_same (0, 1, et.size / 2);
12884}
12885
12886static void
12887do_neon_rshift_sat_narrow (void)
12888{
12889 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12890 or unsigned. If operands are unsigned, results must also be unsigned. */
12891 struct neon_type_el et = neon_check_type (2, NS_DQI,
12892 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12893 int imm = inst.operands[2].imm;
12894 /* This gets the bounds check, size encoding and immediate bits calculation
12895 right. */
12896 et.size /= 2;
5f4273c7 12897
5287ad62
JB
12898 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12899 VQMOVN.I<size> <Dd>, <Qm>. */
12900 if (imm == 0)
12901 {
12902 inst.operands[2].present = 0;
12903 inst.instruction = N_MNEM_vqmovn;
12904 do_neon_qmovn ();
12905 return;
12906 }
5f4273c7 12907
5287ad62
JB
12908 constraint (imm < 1 || (unsigned)imm > et.size,
12909 _("immediate out of range"));
12910 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12911}
12912
12913static void
12914do_neon_rshift_sat_narrow_u (void)
12915{
12916 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12917 or unsigned. If operands are unsigned, results must also be unsigned. */
12918 struct neon_type_el et = neon_check_type (2, NS_DQI,
12919 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12920 int imm = inst.operands[2].imm;
12921 /* This gets the bounds check, size encoding and immediate bits calculation
12922 right. */
12923 et.size /= 2;
12924
12925 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12926 VQMOVUN.I<size> <Dd>, <Qm>. */
12927 if (imm == 0)
12928 {
12929 inst.operands[2].present = 0;
12930 inst.instruction = N_MNEM_vqmovun;
12931 do_neon_qmovun ();
12932 return;
12933 }
12934
12935 constraint (imm < 1 || (unsigned)imm > et.size,
12936 _("immediate out of range"));
12937 /* FIXME: The manual is kind of unclear about what value U should have in
12938 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12939 must be 1. */
12940 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12941}
12942
12943static void
12944do_neon_movn (void)
12945{
12946 struct neon_type_el et = neon_check_type (2, NS_DQ,
12947 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12948 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12949 neon_two_same (0, 1, et.size / 2);
12950}
12951
12952static void
12953do_neon_rshift_narrow (void)
12954{
12955 struct neon_type_el et = neon_check_type (2, NS_DQI,
12956 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12957 int imm = inst.operands[2].imm;
12958 /* This gets the bounds check, size encoding and immediate bits calculation
12959 right. */
12960 et.size /= 2;
5f4273c7 12961
5287ad62
JB
12962 /* If immediate is zero then we are a pseudo-instruction for
12963 VMOVN.I<size> <Dd>, <Qm> */
12964 if (imm == 0)
12965 {
12966 inst.operands[2].present = 0;
12967 inst.instruction = N_MNEM_vmovn;
12968 do_neon_movn ();
12969 return;
12970 }
5f4273c7 12971
5287ad62
JB
12972 constraint (imm < 1 || (unsigned)imm > et.size,
12973 _("immediate out of range for narrowing operation"));
12974 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12975}
12976
12977static void
12978do_neon_shll (void)
12979{
12980 /* FIXME: Type checking when lengthening. */
12981 struct neon_type_el et = neon_check_type (2, NS_QDI,
12982 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12983 unsigned imm = inst.operands[2].imm;
12984
12985 if (imm == et.size)
12986 {
12987 /* Maximum shift variant. */
12988 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12989 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12990 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12991 inst.instruction |= LOW4 (inst.operands[1].reg);
12992 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12993 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12994
5287ad62
JB
12995 inst.instruction = neon_dp_fixup (inst.instruction);
12996 }
12997 else
12998 {
12999 /* A more-specific type check for non-max versions. */
13000 et = neon_check_type (2, NS_QDI,
13001 N_EQK | N_DBL, N_SU_32 | N_KEY);
13002 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13003 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13004 }
13005}
13006
037e8744 13007/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13008 the current instruction is. */
13009
13010static int
13011neon_cvt_flavour (enum neon_shape rs)
13012{
037e8744
JB
13013#define CVT_VAR(C,X,Y) \
13014 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13015 if (et.type != NT_invtype) \
13016 { \
13017 inst.error = NULL; \
13018 return (C); \
5287ad62
JB
13019 }
13020 struct neon_type_el et;
037e8744
JB
13021 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13022 || rs == NS_FF) ? N_VFP : 0;
13023 /* The instruction versions which take an immediate take one register
13024 argument, which is extended to the width of the full register. Thus the
13025 "source" and "destination" registers must have the same width. Hack that
13026 here by making the size equal to the key (wider, in this case) operand. */
13027 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13028
5287ad62
JB
13029 CVT_VAR (0, N_S32, N_F32);
13030 CVT_VAR (1, N_U32, N_F32);
13031 CVT_VAR (2, N_F32, N_S32);
13032 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13033 /* Half-precision conversions. */
13034 CVT_VAR (4, N_F32, N_F16);
13035 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13036
037e8744 13037 whole_reg = N_VFP;
5f4273c7 13038
037e8744 13039 /* VFP instructions. */
8e79c3df
CM
13040 CVT_VAR (6, N_F32, N_F64);
13041 CVT_VAR (7, N_F64, N_F32);
13042 CVT_VAR (8, N_S32, N_F64 | key);
13043 CVT_VAR (9, N_U32, N_F64 | key);
13044 CVT_VAR (10, N_F64 | key, N_S32);
13045 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13046 /* VFP instructions with bitshift. */
8e79c3df
CM
13047 CVT_VAR (12, N_F32 | key, N_S16);
13048 CVT_VAR (13, N_F32 | key, N_U16);
13049 CVT_VAR (14, N_F64 | key, N_S16);
13050 CVT_VAR (15, N_F64 | key, N_U16);
13051 CVT_VAR (16, N_S16, N_F32 | key);
13052 CVT_VAR (17, N_U16, N_F32 | key);
13053 CVT_VAR (18, N_S16, N_F64 | key);
13054 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13055
5287ad62
JB
13056 return -1;
13057#undef CVT_VAR
13058}
13059
037e8744
JB
13060/* Neon-syntax VFP conversions. */
13061
5287ad62 13062static void
037e8744 13063do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13064{
037e8744 13065 const char *opname = 0;
5f4273c7 13066
037e8744 13067 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13068 {
037e8744
JB
13069 /* Conversions with immediate bitshift. */
13070 const char *enc[] =
13071 {
13072 "ftosls",
13073 "ftouls",
13074 "fsltos",
13075 "fultos",
13076 NULL,
13077 NULL,
8e79c3df
CM
13078 NULL,
13079 NULL,
037e8744
JB
13080 "ftosld",
13081 "ftould",
13082 "fsltod",
13083 "fultod",
13084 "fshtos",
13085 "fuhtos",
13086 "fshtod",
13087 "fuhtod",
13088 "ftoshs",
13089 "ftouhs",
13090 "ftoshd",
13091 "ftouhd"
13092 };
13093
13094 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13095 {
13096 opname = enc[flavour];
13097 constraint (inst.operands[0].reg != inst.operands[1].reg,
13098 _("operands 0 and 1 must be the same register"));
13099 inst.operands[1] = inst.operands[2];
13100 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13101 }
5287ad62
JB
13102 }
13103 else
13104 {
037e8744
JB
13105 /* Conversions without bitshift. */
13106 const char *enc[] =
13107 {
13108 "ftosis",
13109 "ftouis",
13110 "fsitos",
13111 "fuitos",
8e79c3df
CM
13112 "NULL",
13113 "NULL",
037e8744
JB
13114 "fcvtsd",
13115 "fcvtds",
13116 "ftosid",
13117 "ftouid",
13118 "fsitod",
13119 "fuitod"
13120 };
13121
13122 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13123 opname = enc[flavour];
13124 }
13125
13126 if (opname)
13127 do_vfp_nsyn_opcode (opname);
13128}
13129
13130static void
13131do_vfp_nsyn_cvtz (void)
13132{
13133 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13134 int flavour = neon_cvt_flavour (rs);
13135 const char *enc[] =
13136 {
13137 "ftosizs",
13138 "ftouizs",
13139 NULL,
13140 NULL,
13141 NULL,
13142 NULL,
8e79c3df
CM
13143 NULL,
13144 NULL,
037e8744
JB
13145 "ftosizd",
13146 "ftouizd"
13147 };
13148
13149 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13150 do_vfp_nsyn_opcode (enc[flavour]);
13151}
f31fef98 13152
037e8744
JB
13153static void
13154do_neon_cvt (void)
13155{
13156 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13157 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13158 int flavour = neon_cvt_flavour (rs);
13159
13160 /* VFP rather than Neon conversions. */
8e79c3df 13161 if (flavour >= 6)
037e8744
JB
13162 {
13163 do_vfp_nsyn_cvt (rs, flavour);
13164 return;
13165 }
13166
13167 switch (rs)
13168 {
13169 case NS_DDI:
13170 case NS_QQI:
13171 {
35997600
NC
13172 unsigned immbits;
13173 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13174
037e8744
JB
13175 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13176 return;
13177
13178 /* Fixed-point conversion with #0 immediate is encoded as an
13179 integer conversion. */
13180 if (inst.operands[2].present && inst.operands[2].imm == 0)
13181 goto int_encode;
35997600 13182 immbits = 32 - inst.operands[2].imm;
037e8744
JB
13183 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13184 if (flavour != -1)
13185 inst.instruction |= enctab[flavour];
13186 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13187 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13188 inst.instruction |= LOW4 (inst.operands[1].reg);
13189 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13190 inst.instruction |= neon_quad (rs) << 6;
13191 inst.instruction |= 1 << 21;
13192 inst.instruction |= immbits << 16;
13193
13194 inst.instruction = neon_dp_fixup (inst.instruction);
13195 }
13196 break;
13197
13198 case NS_DD:
13199 case NS_QQ:
13200 int_encode:
13201 {
13202 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13203
13204 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13205
13206 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13207 return;
13208
13209 if (flavour != -1)
13210 inst.instruction |= enctab[flavour];
13211
13212 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13213 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13214 inst.instruction |= LOW4 (inst.operands[1].reg);
13215 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13216 inst.instruction |= neon_quad (rs) << 6;
13217 inst.instruction |= 2 << 18;
13218
13219 inst.instruction = neon_dp_fixup (inst.instruction);
13220 }
13221 break;
13222
8e79c3df
CM
13223 /* Half-precision conversions for Advanced SIMD -- neon. */
13224 case NS_QD:
13225 case NS_DQ:
13226
13227 if ((rs == NS_DQ)
13228 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13229 {
13230 as_bad (_("operand size must match register width"));
13231 break;
13232 }
13233
13234 if ((rs == NS_QD)
13235 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13236 {
13237 as_bad (_("operand size must match register width"));
13238 break;
13239 }
13240
13241 if (rs == NS_DQ)
13242 inst.instruction = 0x3b60600;
13243 else
13244 inst.instruction = 0x3b60700;
13245
13246 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13247 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13248 inst.instruction |= LOW4 (inst.operands[1].reg);
13249 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13250 inst.instruction = neon_dp_fixup (inst.instruction);
13251 break;
13252
037e8744
JB
13253 default:
13254 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13255 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13256 }
5287ad62
JB
13257}
13258
8e79c3df
CM
13259static void
13260do_neon_cvtb (void)
13261{
13262 inst.instruction = 0xeb20a40;
13263
13264 /* The sizes are attached to the mnemonic. */
13265 if (inst.vectype.el[0].type != NT_invtype
13266 && inst.vectype.el[0].size == 16)
13267 inst.instruction |= 0x00010000;
13268
13269 /* Programmer's syntax: the sizes are attached to the operands. */
13270 else if (inst.operands[0].vectype.type != NT_invtype
13271 && inst.operands[0].vectype.size == 16)
13272 inst.instruction |= 0x00010000;
13273
13274 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13275 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13276 do_vfp_cond_or_thumb ();
13277}
13278
13279
13280static void
13281do_neon_cvtt (void)
13282{
13283 do_neon_cvtb ();
13284 inst.instruction |= 0x80;
13285}
13286
5287ad62
JB
13287static void
13288neon_move_immediate (void)
13289{
037e8744
JB
13290 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13291 struct neon_type_el et = neon_check_type (2, rs,
13292 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13293 unsigned immlo, immhi = 0, immbits;
c96612cc 13294 int op, cmode, float_p;
5287ad62 13295
037e8744
JB
13296 constraint (et.type == NT_invtype,
13297 _("operand size must be specified for immediate VMOV"));
13298
5287ad62
JB
13299 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13300 op = (inst.instruction & (1 << 5)) != 0;
13301
13302 immlo = inst.operands[1].imm;
13303 if (inst.operands[1].regisimm)
13304 immhi = inst.operands[1].reg;
13305
13306 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13307 _("immediate has bits set outside the operand size"));
13308
c96612cc
JB
13309 float_p = inst.operands[1].immisfloat;
13310
13311 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13312 et.size, et.type)) == FAIL)
5287ad62
JB
13313 {
13314 /* Invert relevant bits only. */
13315 neon_invert_size (&immlo, &immhi, et.size);
13316 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13317 with one or the other; those cases are caught by
13318 neon_cmode_for_move_imm. */
13319 op = !op;
c96612cc
JB
13320 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13321 &op, et.size, et.type)) == FAIL)
5287ad62 13322 {
dcbf9037 13323 first_error (_("immediate out of range"));
5287ad62
JB
13324 return;
13325 }
13326 }
13327
13328 inst.instruction &= ~(1 << 5);
13329 inst.instruction |= op << 5;
13330
13331 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13332 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13333 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13334 inst.instruction |= cmode << 8;
13335
13336 neon_write_immbits (immbits);
13337}
13338
13339static void
13340do_neon_mvn (void)
13341{
13342 if (inst.operands[1].isreg)
13343 {
037e8744 13344 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13345
5287ad62
JB
13346 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13347 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13348 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13349 inst.instruction |= LOW4 (inst.operands[1].reg);
13350 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13351 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13352 }
13353 else
13354 {
13355 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13356 neon_move_immediate ();
13357 }
13358
13359 inst.instruction = neon_dp_fixup (inst.instruction);
13360}
13361
13362/* Encode instructions of form:
13363
13364 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13365 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13366
13367static void
13368neon_mixed_length (struct neon_type_el et, unsigned size)
13369{
13370 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13371 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13372 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13373 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13374 inst.instruction |= LOW4 (inst.operands[2].reg);
13375 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13376 inst.instruction |= (et.type == NT_unsigned) << 24;
13377 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13378
5287ad62
JB
13379 inst.instruction = neon_dp_fixup (inst.instruction);
13380}
13381
13382static void
13383do_neon_dyadic_long (void)
13384{
13385 /* FIXME: Type checking for lengthening op. */
13386 struct neon_type_el et = neon_check_type (3, NS_QDD,
13387 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13388 neon_mixed_length (et, et.size);
13389}
13390
13391static void
13392do_neon_abal (void)
13393{
13394 struct neon_type_el et = neon_check_type (3, NS_QDD,
13395 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13396 neon_mixed_length (et, et.size);
13397}
13398
13399static void
13400neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13401{
13402 if (inst.operands[2].isscalar)
13403 {
dcbf9037
JB
13404 struct neon_type_el et = neon_check_type (3, NS_QDS,
13405 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13406 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13407 neon_mul_mac (et, et.type == NT_unsigned);
13408 }
13409 else
13410 {
13411 struct neon_type_el et = neon_check_type (3, NS_QDD,
13412 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13413 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13414 neon_mixed_length (et, et.size);
13415 }
13416}
13417
13418static void
13419do_neon_mac_maybe_scalar_long (void)
13420{
13421 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13422}
13423
13424static void
13425do_neon_dyadic_wide (void)
13426{
13427 struct neon_type_el et = neon_check_type (3, NS_QQD,
13428 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13429 neon_mixed_length (et, et.size);
13430}
13431
13432static void
13433do_neon_dyadic_narrow (void)
13434{
13435 struct neon_type_el et = neon_check_type (3, NS_QDD,
13436 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13437 /* Operand sign is unimportant, and the U bit is part of the opcode,
13438 so force the operand type to integer. */
13439 et.type = NT_integer;
5287ad62
JB
13440 neon_mixed_length (et, et.size / 2);
13441}
13442
13443static void
13444do_neon_mul_sat_scalar_long (void)
13445{
13446 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13447}
13448
13449static void
13450do_neon_vmull (void)
13451{
13452 if (inst.operands[2].isscalar)
13453 do_neon_mac_maybe_scalar_long ();
13454 else
13455 {
13456 struct neon_type_el et = neon_check_type (3, NS_QDD,
13457 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13458 if (et.type == NT_poly)
13459 inst.instruction = NEON_ENC_POLY (inst.instruction);
13460 else
13461 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13462 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13463 zero. Should be OK as-is. */
13464 neon_mixed_length (et, et.size);
13465 }
13466}
13467
13468static void
13469do_neon_ext (void)
13470{
037e8744 13471 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13472 struct neon_type_el et = neon_check_type (3, rs,
13473 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13474 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13475
13476 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13477 _("shift out of range"));
5287ad62
JB
13478 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13479 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13480 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13481 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13482 inst.instruction |= LOW4 (inst.operands[2].reg);
13483 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13484 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13485 inst.instruction |= imm << 8;
5f4273c7 13486
5287ad62
JB
13487 inst.instruction = neon_dp_fixup (inst.instruction);
13488}
13489
13490static void
13491do_neon_rev (void)
13492{
037e8744 13493 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13494 struct neon_type_el et = neon_check_type (2, rs,
13495 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13496 unsigned op = (inst.instruction >> 7) & 3;
13497 /* N (width of reversed regions) is encoded as part of the bitmask. We
13498 extract it here to check the elements to be reversed are smaller.
13499 Otherwise we'd get a reserved instruction. */
13500 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13501 assert (elsize != 0);
13502 constraint (et.size >= elsize,
13503 _("elements must be smaller than reversal region"));
037e8744 13504 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13505}
13506
13507static void
13508do_neon_dup (void)
13509{
13510 if (inst.operands[1].isscalar)
13511 {
037e8744 13512 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13513 struct neon_type_el et = neon_check_type (2, rs,
13514 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13515 unsigned sizebits = et.size >> 3;
dcbf9037 13516 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13517 int logsize = neon_logbits (et.size);
dcbf9037 13518 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13519
13520 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13521 return;
13522
5287ad62
JB
13523 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13524 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13525 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13526 inst.instruction |= LOW4 (dm);
13527 inst.instruction |= HI1 (dm) << 5;
037e8744 13528 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13529 inst.instruction |= x << 17;
13530 inst.instruction |= sizebits << 16;
5f4273c7 13531
5287ad62
JB
13532 inst.instruction = neon_dp_fixup (inst.instruction);
13533 }
13534 else
13535 {
037e8744
JB
13536 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13537 struct neon_type_el et = neon_check_type (2, rs,
13538 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13539 /* Duplicate ARM register to lanes of vector. */
13540 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13541 switch (et.size)
13542 {
13543 case 8: inst.instruction |= 0x400000; break;
13544 case 16: inst.instruction |= 0x000020; break;
13545 case 32: inst.instruction |= 0x000000; break;
13546 default: break;
13547 }
13548 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13549 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13550 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13551 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13552 /* The encoding for this instruction is identical for the ARM and Thumb
13553 variants, except for the condition field. */
037e8744 13554 do_vfp_cond_or_thumb ();
5287ad62
JB
13555 }
13556}
13557
13558/* VMOV has particularly many variations. It can be one of:
13559 0. VMOV<c><q> <Qd>, <Qm>
13560 1. VMOV<c><q> <Dd>, <Dm>
13561 (Register operations, which are VORR with Rm = Rn.)
13562 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13563 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13564 (Immediate loads.)
13565 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13566 (ARM register to scalar.)
13567 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13568 (Two ARM registers to vector.)
13569 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13570 (Scalar to ARM register.)
13571 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13572 (Vector to two ARM registers.)
037e8744
JB
13573 8. VMOV.F32 <Sd>, <Sm>
13574 9. VMOV.F64 <Dd>, <Dm>
13575 (VFP register moves.)
13576 10. VMOV.F32 <Sd>, #imm
13577 11. VMOV.F64 <Dd>, #imm
13578 (VFP float immediate load.)
13579 12. VMOV <Rd>, <Sm>
13580 (VFP single to ARM reg.)
13581 13. VMOV <Sd>, <Rm>
13582 (ARM reg to VFP single.)
13583 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13584 (Two ARM regs to two VFP singles.)
13585 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13586 (Two VFP singles to two ARM regs.)
5f4273c7 13587
037e8744
JB
13588 These cases can be disambiguated using neon_select_shape, except cases 1/9
13589 and 3/11 which depend on the operand type too.
5f4273c7 13590
5287ad62 13591 All the encoded bits are hardcoded by this function.
5f4273c7 13592
b7fc2769
JB
13593 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13594 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13595
5287ad62 13596 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13597 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13598
13599static void
13600do_neon_mov (void)
13601{
037e8744
JB
13602 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13603 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13604 NS_NULL);
13605 struct neon_type_el et;
13606 const char *ldconst = 0;
5287ad62 13607
037e8744 13608 switch (rs)
5287ad62 13609 {
037e8744
JB
13610 case NS_DD: /* case 1/9. */
13611 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13612 /* It is not an error here if no type is given. */
13613 inst.error = NULL;
13614 if (et.type == NT_float && et.size == 64)
5287ad62 13615 {
037e8744
JB
13616 do_vfp_nsyn_opcode ("fcpyd");
13617 break;
5287ad62 13618 }
037e8744 13619 /* fall through. */
5287ad62 13620
037e8744
JB
13621 case NS_QQ: /* case 0/1. */
13622 {
13623 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13624 return;
13625 /* The architecture manual I have doesn't explicitly state which
13626 value the U bit should have for register->register moves, but
13627 the equivalent VORR instruction has U = 0, so do that. */
13628 inst.instruction = 0x0200110;
13629 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13630 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13631 inst.instruction |= LOW4 (inst.operands[1].reg);
13632 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13633 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13634 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13635 inst.instruction |= neon_quad (rs) << 6;
13636
13637 inst.instruction = neon_dp_fixup (inst.instruction);
13638 }
13639 break;
5f4273c7 13640
037e8744
JB
13641 case NS_DI: /* case 3/11. */
13642 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13643 inst.error = NULL;
13644 if (et.type == NT_float && et.size == 64)
5287ad62 13645 {
037e8744
JB
13646 /* case 11 (fconstd). */
13647 ldconst = "fconstd";
13648 goto encode_fconstd;
5287ad62 13649 }
037e8744
JB
13650 /* fall through. */
13651
13652 case NS_QI: /* case 2/3. */
13653 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13654 return;
13655 inst.instruction = 0x0800010;
13656 neon_move_immediate ();
13657 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13658 break;
5f4273c7 13659
037e8744
JB
13660 case NS_SR: /* case 4. */
13661 {
13662 unsigned bcdebits = 0;
13663 struct neon_type_el et = neon_check_type (2, NS_NULL,
13664 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13665 int logsize = neon_logbits (et.size);
13666 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13667 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13668
13669 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13670 _(BAD_FPU));
13671 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13672 && et.size != 32, _(BAD_FPU));
13673 constraint (et.type == NT_invtype, _("bad type for scalar"));
13674 constraint (x >= 64 / et.size, _("scalar index out of range"));
13675
13676 switch (et.size)
13677 {
13678 case 8: bcdebits = 0x8; break;
13679 case 16: bcdebits = 0x1; break;
13680 case 32: bcdebits = 0x0; break;
13681 default: ;
13682 }
13683
13684 bcdebits |= x << logsize;
13685
13686 inst.instruction = 0xe000b10;
13687 do_vfp_cond_or_thumb ();
13688 inst.instruction |= LOW4 (dn) << 16;
13689 inst.instruction |= HI1 (dn) << 7;
13690 inst.instruction |= inst.operands[1].reg << 12;
13691 inst.instruction |= (bcdebits & 3) << 5;
13692 inst.instruction |= (bcdebits >> 2) << 21;
13693 }
13694 break;
5f4273c7 13695
037e8744 13696 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13697 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13698 _(BAD_FPU));
b7fc2769 13699
037e8744
JB
13700 inst.instruction = 0xc400b10;
13701 do_vfp_cond_or_thumb ();
13702 inst.instruction |= LOW4 (inst.operands[0].reg);
13703 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13704 inst.instruction |= inst.operands[1].reg << 12;
13705 inst.instruction |= inst.operands[2].reg << 16;
13706 break;
5f4273c7 13707
037e8744
JB
13708 case NS_RS: /* case 6. */
13709 {
13710 struct neon_type_el et = neon_check_type (2, NS_NULL,
13711 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13712 unsigned logsize = neon_logbits (et.size);
13713 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13714 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13715 unsigned abcdebits = 0;
13716
13717 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13718 _(BAD_FPU));
13719 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13720 && et.size != 32, _(BAD_FPU));
13721 constraint (et.type == NT_invtype, _("bad type for scalar"));
13722 constraint (x >= 64 / et.size, _("scalar index out of range"));
13723
13724 switch (et.size)
13725 {
13726 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13727 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13728 case 32: abcdebits = 0x00; break;
13729 default: ;
13730 }
13731
13732 abcdebits |= x << logsize;
13733 inst.instruction = 0xe100b10;
13734 do_vfp_cond_or_thumb ();
13735 inst.instruction |= LOW4 (dn) << 16;
13736 inst.instruction |= HI1 (dn) << 7;
13737 inst.instruction |= inst.operands[0].reg << 12;
13738 inst.instruction |= (abcdebits & 3) << 5;
13739 inst.instruction |= (abcdebits >> 2) << 21;
13740 }
13741 break;
5f4273c7 13742
037e8744
JB
13743 case NS_RRD: /* case 7 (fmrrd). */
13744 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13745 _(BAD_FPU));
13746
13747 inst.instruction = 0xc500b10;
13748 do_vfp_cond_or_thumb ();
13749 inst.instruction |= inst.operands[0].reg << 12;
13750 inst.instruction |= inst.operands[1].reg << 16;
13751 inst.instruction |= LOW4 (inst.operands[2].reg);
13752 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13753 break;
5f4273c7 13754
037e8744
JB
13755 case NS_FF: /* case 8 (fcpys). */
13756 do_vfp_nsyn_opcode ("fcpys");
13757 break;
5f4273c7 13758
037e8744
JB
13759 case NS_FI: /* case 10 (fconsts). */
13760 ldconst = "fconsts";
13761 encode_fconstd:
13762 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13763 {
037e8744
JB
13764 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13765 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13766 }
13767 else
037e8744
JB
13768 first_error (_("immediate out of range"));
13769 break;
5f4273c7 13770
037e8744
JB
13771 case NS_RF: /* case 12 (fmrs). */
13772 do_vfp_nsyn_opcode ("fmrs");
13773 break;
5f4273c7 13774
037e8744
JB
13775 case NS_FR: /* case 13 (fmsr). */
13776 do_vfp_nsyn_opcode ("fmsr");
13777 break;
5f4273c7 13778
037e8744
JB
13779 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13780 (one of which is a list), but we have parsed four. Do some fiddling to
13781 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13782 expect. */
13783 case NS_RRFF: /* case 14 (fmrrs). */
13784 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13785 _("VFP registers must be adjacent"));
13786 inst.operands[2].imm = 2;
13787 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13788 do_vfp_nsyn_opcode ("fmrrs");
13789 break;
5f4273c7 13790
037e8744
JB
13791 case NS_FFRR: /* case 15 (fmsrr). */
13792 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13793 _("VFP registers must be adjacent"));
13794 inst.operands[1] = inst.operands[2];
13795 inst.operands[2] = inst.operands[3];
13796 inst.operands[0].imm = 2;
13797 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13798 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13799 break;
5f4273c7 13800
5287ad62
JB
13801 default:
13802 abort ();
13803 }
13804}
13805
13806static void
13807do_neon_rshift_round_imm (void)
13808{
037e8744 13809 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13810 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13811 int imm = inst.operands[2].imm;
13812
13813 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13814 if (imm == 0)
13815 {
13816 inst.operands[2].present = 0;
13817 do_neon_mov ();
13818 return;
13819 }
13820
13821 constraint (imm < 1 || (unsigned)imm > et.size,
13822 _("immediate out of range for shift"));
037e8744 13823 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13824 et.size - imm);
13825}
13826
13827static void
13828do_neon_movl (void)
13829{
13830 struct neon_type_el et = neon_check_type (2, NS_QD,
13831 N_EQK | N_DBL, N_SU_32 | N_KEY);
13832 unsigned sizebits = et.size >> 3;
13833 inst.instruction |= sizebits << 19;
13834 neon_two_same (0, et.type == NT_unsigned, -1);
13835}
13836
13837static void
13838do_neon_trn (void)
13839{
037e8744 13840 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13841 struct neon_type_el et = neon_check_type (2, rs,
13842 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13843 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13844 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13845}
13846
13847static void
13848do_neon_zip_uzp (void)
13849{
037e8744 13850 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13851 struct neon_type_el et = neon_check_type (2, rs,
13852 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13853 if (rs == NS_DD && et.size == 32)
13854 {
13855 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13856 inst.instruction = N_MNEM_vtrn;
13857 do_neon_trn ();
13858 return;
13859 }
037e8744 13860 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13861}
13862
13863static void
13864do_neon_sat_abs_neg (void)
13865{
037e8744 13866 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13867 struct neon_type_el et = neon_check_type (2, rs,
13868 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13869 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13870}
13871
13872static void
13873do_neon_pair_long (void)
13874{
037e8744 13875 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13876 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13877 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13878 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13879 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13880}
13881
13882static void
13883do_neon_recip_est (void)
13884{
037e8744 13885 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13886 struct neon_type_el et = neon_check_type (2, rs,
13887 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13888 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13889 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13890}
13891
13892static void
13893do_neon_cls (void)
13894{
037e8744 13895 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13896 struct neon_type_el et = neon_check_type (2, rs,
13897 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13898 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13899}
13900
13901static void
13902do_neon_clz (void)
13903{
037e8744 13904 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13905 struct neon_type_el et = neon_check_type (2, rs,
13906 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13907 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13908}
13909
13910static void
13911do_neon_cnt (void)
13912{
037e8744 13913 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13914 struct neon_type_el et = neon_check_type (2, rs,
13915 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13916 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13917}
13918
13919static void
13920do_neon_swp (void)
13921{
037e8744
JB
13922 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13923 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13924}
13925
13926static void
13927do_neon_tbl_tbx (void)
13928{
13929 unsigned listlenbits;
dcbf9037 13930 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13931
5287ad62
JB
13932 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13933 {
dcbf9037 13934 first_error (_("bad list length for table lookup"));
5287ad62
JB
13935 return;
13936 }
5f4273c7 13937
5287ad62
JB
13938 listlenbits = inst.operands[1].imm - 1;
13939 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13940 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13941 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13942 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13943 inst.instruction |= LOW4 (inst.operands[2].reg);
13944 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13945 inst.instruction |= listlenbits << 8;
5f4273c7 13946
5287ad62
JB
13947 inst.instruction = neon_dp_fixup (inst.instruction);
13948}
13949
13950static void
13951do_neon_ldm_stm (void)
13952{
13953 /* P, U and L bits are part of bitmask. */
13954 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13955 unsigned offsetbits = inst.operands[1].imm * 2;
13956
037e8744
JB
13957 if (inst.operands[1].issingle)
13958 {
13959 do_vfp_nsyn_ldm_stm (is_dbmode);
13960 return;
13961 }
13962
5287ad62
JB
13963 constraint (is_dbmode && !inst.operands[0].writeback,
13964 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13965
13966 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13967 _("register list must contain at least 1 and at most 16 "
13968 "registers"));
13969
13970 inst.instruction |= inst.operands[0].reg << 16;
13971 inst.instruction |= inst.operands[0].writeback << 21;
13972 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13973 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13974
13975 inst.instruction |= offsetbits;
5f4273c7 13976
037e8744 13977 do_vfp_cond_or_thumb ();
5287ad62
JB
13978}
13979
13980static void
13981do_neon_ldr_str (void)
13982{
5287ad62 13983 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13984
037e8744
JB
13985 if (inst.operands[0].issingle)
13986 {
cd2f129f
JB
13987 if (is_ldr)
13988 do_vfp_nsyn_opcode ("flds");
13989 else
13990 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13991 }
13992 else
5287ad62 13993 {
cd2f129f
JB
13994 if (is_ldr)
13995 do_vfp_nsyn_opcode ("fldd");
5287ad62 13996 else
cd2f129f 13997 do_vfp_nsyn_opcode ("fstd");
5287ad62 13998 }
5287ad62
JB
13999}
14000
14001/* "interleave" version also handles non-interleaving register VLD1/VST1
14002 instructions. */
14003
14004static void
14005do_neon_ld_st_interleave (void)
14006{
037e8744 14007 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14008 N_8 | N_16 | N_32 | N_64);
14009 unsigned alignbits = 0;
14010 unsigned idx;
14011 /* The bits in this table go:
14012 0: register stride of one (0) or two (1)
14013 1,2: register list length, minus one (1, 2, 3, 4).
14014 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14015 We use -1 for invalid entries. */
14016 const int typetable[] =
14017 {
14018 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14019 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14020 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14021 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14022 };
14023 int typebits;
14024
dcbf9037
JB
14025 if (et.type == NT_invtype)
14026 return;
14027
5287ad62
JB
14028 if (inst.operands[1].immisalign)
14029 switch (inst.operands[1].imm >> 8)
14030 {
14031 case 64: alignbits = 1; break;
14032 case 128:
14033 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14034 goto bad_alignment;
14035 alignbits = 2;
14036 break;
14037 case 256:
14038 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14039 goto bad_alignment;
14040 alignbits = 3;
14041 break;
14042 default:
14043 bad_alignment:
dcbf9037 14044 first_error (_("bad alignment"));
5287ad62
JB
14045 return;
14046 }
14047
14048 inst.instruction |= alignbits << 4;
14049 inst.instruction |= neon_logbits (et.size) << 6;
14050
14051 /* Bits [4:6] of the immediate in a list specifier encode register stride
14052 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14053 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14054 up the right value for "type" in a table based on this value and the given
14055 list style, then stick it back. */
14056 idx = ((inst.operands[0].imm >> 4) & 7)
14057 | (((inst.instruction >> 8) & 3) << 3);
14058
14059 typebits = typetable[idx];
5f4273c7 14060
5287ad62
JB
14061 constraint (typebits == -1, _("bad list type for instruction"));
14062
14063 inst.instruction &= ~0xf00;
14064 inst.instruction |= typebits << 8;
14065}
14066
14067/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14068 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14069 otherwise. The variable arguments are a list of pairs of legal (size, align)
14070 values, terminated with -1. */
14071
14072static int
14073neon_alignment_bit (int size, int align, int *do_align, ...)
14074{
14075 va_list ap;
14076 int result = FAIL, thissize, thisalign;
5f4273c7 14077
5287ad62
JB
14078 if (!inst.operands[1].immisalign)
14079 {
14080 *do_align = 0;
14081 return SUCCESS;
14082 }
5f4273c7 14083
5287ad62
JB
14084 va_start (ap, do_align);
14085
14086 do
14087 {
14088 thissize = va_arg (ap, int);
14089 if (thissize == -1)
14090 break;
14091 thisalign = va_arg (ap, int);
14092
14093 if (size == thissize && align == thisalign)
14094 result = SUCCESS;
14095 }
14096 while (result != SUCCESS);
14097
14098 va_end (ap);
14099
14100 if (result == SUCCESS)
14101 *do_align = 1;
14102 else
dcbf9037 14103 first_error (_("unsupported alignment for instruction"));
5f4273c7 14104
5287ad62
JB
14105 return result;
14106}
14107
14108static void
14109do_neon_ld_st_lane (void)
14110{
037e8744 14111 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14112 int align_good, do_align = 0;
14113 int logsize = neon_logbits (et.size);
14114 int align = inst.operands[1].imm >> 8;
14115 int n = (inst.instruction >> 8) & 3;
14116 int max_el = 64 / et.size;
5f4273c7 14117
dcbf9037
JB
14118 if (et.type == NT_invtype)
14119 return;
5f4273c7 14120
5287ad62
JB
14121 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14122 _("bad list length"));
14123 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14124 _("scalar index out of range"));
14125 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14126 && et.size == 8,
14127 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14128
5287ad62
JB
14129 switch (n)
14130 {
14131 case 0: /* VLD1 / VST1. */
14132 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14133 32, 32, -1);
14134 if (align_good == FAIL)
14135 return;
14136 if (do_align)
14137 {
14138 unsigned alignbits = 0;
14139 switch (et.size)
14140 {
14141 case 16: alignbits = 0x1; break;
14142 case 32: alignbits = 0x3; break;
14143 default: ;
14144 }
14145 inst.instruction |= alignbits << 4;
14146 }
14147 break;
14148
14149 case 1: /* VLD2 / VST2. */
14150 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14151 32, 64, -1);
14152 if (align_good == FAIL)
14153 return;
14154 if (do_align)
14155 inst.instruction |= 1 << 4;
14156 break;
14157
14158 case 2: /* VLD3 / VST3. */
14159 constraint (inst.operands[1].immisalign,
14160 _("can't use alignment with this instruction"));
14161 break;
14162
14163 case 3: /* VLD4 / VST4. */
14164 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14165 16, 64, 32, 64, 32, 128, -1);
14166 if (align_good == FAIL)
14167 return;
14168 if (do_align)
14169 {
14170 unsigned alignbits = 0;
14171 switch (et.size)
14172 {
14173 case 8: alignbits = 0x1; break;
14174 case 16: alignbits = 0x1; break;
14175 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14176 default: ;
14177 }
14178 inst.instruction |= alignbits << 4;
14179 }
14180 break;
14181
14182 default: ;
14183 }
14184
14185 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14186 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14187 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14188
5287ad62
JB
14189 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14190 inst.instruction |= logsize << 10;
14191}
14192
14193/* Encode single n-element structure to all lanes VLD<n> instructions. */
14194
14195static void
14196do_neon_ld_dup (void)
14197{
037e8744 14198 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14199 int align_good, do_align = 0;
14200
dcbf9037
JB
14201 if (et.type == NT_invtype)
14202 return;
14203
5287ad62
JB
14204 switch ((inst.instruction >> 8) & 3)
14205 {
14206 case 0: /* VLD1. */
14207 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14208 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14209 &do_align, 16, 16, 32, 32, -1);
14210 if (align_good == FAIL)
14211 return;
14212 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14213 {
14214 case 1: break;
14215 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14216 default: first_error (_("bad list length")); return;
5287ad62
JB
14217 }
14218 inst.instruction |= neon_logbits (et.size) << 6;
14219 break;
14220
14221 case 1: /* VLD2. */
14222 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14223 &do_align, 8, 16, 16, 32, 32, 64, -1);
14224 if (align_good == FAIL)
14225 return;
14226 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14227 _("bad list length"));
14228 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14229 inst.instruction |= 1 << 5;
14230 inst.instruction |= neon_logbits (et.size) << 6;
14231 break;
14232
14233 case 2: /* VLD3. */
14234 constraint (inst.operands[1].immisalign,
14235 _("can't use alignment with this instruction"));
14236 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14237 _("bad list length"));
14238 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14239 inst.instruction |= 1 << 5;
14240 inst.instruction |= neon_logbits (et.size) << 6;
14241 break;
14242
14243 case 3: /* VLD4. */
14244 {
14245 int align = inst.operands[1].imm >> 8;
14246 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14247 16, 64, 32, 64, 32, 128, -1);
14248 if (align_good == FAIL)
14249 return;
14250 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14251 _("bad list length"));
14252 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14253 inst.instruction |= 1 << 5;
14254 if (et.size == 32 && align == 128)
14255 inst.instruction |= 0x3 << 6;
14256 else
14257 inst.instruction |= neon_logbits (et.size) << 6;
14258 }
14259 break;
14260
14261 default: ;
14262 }
14263
14264 inst.instruction |= do_align << 4;
14265}
14266
14267/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14268 apart from bits [11:4]. */
14269
14270static void
14271do_neon_ldx_stx (void)
14272{
14273 switch (NEON_LANE (inst.operands[0].imm))
14274 {
14275 case NEON_INTERLEAVE_LANES:
14276 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14277 do_neon_ld_st_interleave ();
14278 break;
5f4273c7 14279
5287ad62
JB
14280 case NEON_ALL_LANES:
14281 inst.instruction = NEON_ENC_DUP (inst.instruction);
14282 do_neon_ld_dup ();
14283 break;
5f4273c7 14284
5287ad62
JB
14285 default:
14286 inst.instruction = NEON_ENC_LANE (inst.instruction);
14287 do_neon_ld_st_lane ();
14288 }
14289
14290 /* L bit comes from bit mask. */
14291 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14292 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14293 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14294
5287ad62
JB
14295 if (inst.operands[1].postind)
14296 {
14297 int postreg = inst.operands[1].imm & 0xf;
14298 constraint (!inst.operands[1].immisreg,
14299 _("post-index must be a register"));
14300 constraint (postreg == 0xd || postreg == 0xf,
14301 _("bad register for post-index"));
14302 inst.instruction |= postreg;
14303 }
14304 else if (inst.operands[1].writeback)
14305 {
14306 inst.instruction |= 0xd;
14307 }
14308 else
5f4273c7
NC
14309 inst.instruction |= 0xf;
14310
5287ad62
JB
14311 if (thumb_mode)
14312 inst.instruction |= 0xf9000000;
14313 else
14314 inst.instruction |= 0xf4000000;
14315}
5287ad62
JB
14316\f
14317/* Overall per-instruction processing. */
14318
14319/* We need to be able to fix up arbitrary expressions in some statements.
14320 This is so that we can handle symbols that are an arbitrary distance from
14321 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14322 which returns part of an address in a form which will be valid for
14323 a data instruction. We do this by pushing the expression into a symbol
14324 in the expr_section, and creating a fix for that. */
14325
14326static void
14327fix_new_arm (fragS * frag,
14328 int where,
14329 short int size,
14330 expressionS * exp,
14331 int pc_rel,
14332 int reloc)
14333{
14334 fixS * new_fix;
14335
14336 switch (exp->X_op)
14337 {
14338 case O_constant:
14339 case O_symbol:
14340 case O_add:
14341 case O_subtract:
14342 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14343 break;
14344
14345 default:
14346 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14347 pc_rel, reloc);
14348 break;
14349 }
14350
14351 /* Mark whether the fix is to a THUMB instruction, or an ARM
14352 instruction. */
14353 new_fix->tc_fix_data = thumb_mode;
14354}
14355
14356/* Create a frg for an instruction requiring relaxation. */
14357static void
14358output_relax_insn (void)
14359{
14360 char * to;
14361 symbolS *sym;
0110f2b8
PB
14362 int offset;
14363
6e1cb1a6
PB
14364 /* The size of the instruction is unknown, so tie the debug info to the
14365 start of the instruction. */
14366 dwarf2_emit_insn (0);
6e1cb1a6 14367
0110f2b8
PB
14368 switch (inst.reloc.exp.X_op)
14369 {
14370 case O_symbol:
14371 sym = inst.reloc.exp.X_add_symbol;
14372 offset = inst.reloc.exp.X_add_number;
14373 break;
14374 case O_constant:
14375 sym = NULL;
14376 offset = inst.reloc.exp.X_add_number;
14377 break;
14378 default:
14379 sym = make_expr_symbol (&inst.reloc.exp);
14380 offset = 0;
14381 break;
14382 }
14383 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14384 inst.relax, sym, offset, NULL/*offset, opcode*/);
14385 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14386}
14387
14388/* Write a 32-bit thumb instruction to buf. */
14389static void
14390put_thumb32_insn (char * buf, unsigned long insn)
14391{
14392 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14393 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14394}
14395
b99bd4ef 14396static void
c19d1205 14397output_inst (const char * str)
b99bd4ef 14398{
c19d1205 14399 char * to = NULL;
b99bd4ef 14400
c19d1205 14401 if (inst.error)
b99bd4ef 14402 {
c19d1205 14403 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14404 return;
14405 }
5f4273c7
NC
14406 if (inst.relax)
14407 {
14408 output_relax_insn ();
0110f2b8 14409 return;
5f4273c7 14410 }
c19d1205
ZW
14411 if (inst.size == 0)
14412 return;
b99bd4ef 14413
c19d1205 14414 to = frag_more (inst.size);
8dc2430f
NC
14415 /* PR 9814: Record the thumb mode into the current frag so that we know
14416 what type of NOP padding to use, if necessary. We override any previous
14417 setting so that if the mode has changed then the NOPS that we use will
14418 match the encoding of the last instruction in the frag. */
14419 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14420
14421 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14422 {
c19d1205 14423 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14424 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14425 }
c19d1205 14426 else if (inst.size > INSN_SIZE)
b99bd4ef 14427 {
c19d1205
ZW
14428 assert (inst.size == (2 * INSN_SIZE));
14429 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14430 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14431 }
c19d1205
ZW
14432 else
14433 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14434
c19d1205
ZW
14435 if (inst.reloc.type != BFD_RELOC_UNUSED)
14436 fix_new_arm (frag_now, to - frag_now->fr_literal,
14437 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14438 inst.reloc.type);
b99bd4ef 14439
c19d1205 14440 dwarf2_emit_insn (inst.size);
c19d1205 14441}
b99bd4ef 14442
c19d1205
ZW
14443/* Tag values used in struct asm_opcode's tag field. */
14444enum opcode_tag
14445{
14446 OT_unconditional, /* Instruction cannot be conditionalized.
14447 The ARM condition field is still 0xE. */
14448 OT_unconditionalF, /* Instruction cannot be conditionalized
14449 and carries 0xF in its ARM condition field. */
14450 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14451 OT_csuffixF, /* Some forms of the instruction take a conditional
14452 suffix, others place 0xF where the condition field
14453 would be. */
c19d1205
ZW
14454 OT_cinfix3, /* Instruction takes a conditional infix,
14455 beginning at character index 3. (In
14456 unified mode, it becomes a suffix.) */
088fa78e
KH
14457 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14458 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14459 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14460 character index 3, even in unified mode. Used for
14461 legacy instructions where suffix and infix forms
14462 may be ambiguous. */
c19d1205 14463 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14464 suffix or an infix at character index 3. */
c19d1205
ZW
14465 OT_odd_infix_unc, /* This is the unconditional variant of an
14466 instruction that takes a conditional infix
14467 at an unusual position. In unified mode,
14468 this variant will accept a suffix. */
14469 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14470 are the conditional variants of instructions that
14471 take conditional infixes in unusual positions.
14472 The infix appears at character index
14473 (tag - OT_odd_infix_0). These are not accepted
14474 in unified mode. */
14475};
b99bd4ef 14476
c19d1205
ZW
14477/* Subroutine of md_assemble, responsible for looking up the primary
14478 opcode from the mnemonic the user wrote. STR points to the
14479 beginning of the mnemonic.
14480
14481 This is not simply a hash table lookup, because of conditional
14482 variants. Most instructions have conditional variants, which are
14483 expressed with a _conditional affix_ to the mnemonic. If we were
14484 to encode each conditional variant as a literal string in the opcode
14485 table, it would have approximately 20,000 entries.
14486
14487 Most mnemonics take this affix as a suffix, and in unified syntax,
14488 'most' is upgraded to 'all'. However, in the divided syntax, some
14489 instructions take the affix as an infix, notably the s-variants of
14490 the arithmetic instructions. Of those instructions, all but six
14491 have the infix appear after the third character of the mnemonic.
14492
14493 Accordingly, the algorithm for looking up primary opcodes given
14494 an identifier is:
14495
14496 1. Look up the identifier in the opcode table.
14497 If we find a match, go to step U.
14498
14499 2. Look up the last two characters of the identifier in the
14500 conditions table. If we find a match, look up the first N-2
14501 characters of the identifier in the opcode table. If we
14502 find a match, go to step CE.
14503
14504 3. Look up the fourth and fifth characters of the identifier in
14505 the conditions table. If we find a match, extract those
14506 characters from the identifier, and look up the remaining
14507 characters in the opcode table. If we find a match, go
14508 to step CM.
14509
14510 4. Fail.
14511
14512 U. Examine the tag field of the opcode structure, in case this is
14513 one of the six instructions with its conditional infix in an
14514 unusual place. If it is, the tag tells us where to find the
14515 infix; look it up in the conditions table and set inst.cond
14516 accordingly. Otherwise, this is an unconditional instruction.
14517 Again set inst.cond accordingly. Return the opcode structure.
14518
14519 CE. Examine the tag field to make sure this is an instruction that
14520 should receive a conditional suffix. If it is not, fail.
14521 Otherwise, set inst.cond from the suffix we already looked up,
14522 and return the opcode structure.
14523
14524 CM. Examine the tag field to make sure this is an instruction that
14525 should receive a conditional infix after the third character.
14526 If it is not, fail. Otherwise, undo the edits to the current
14527 line of input and proceed as for case CE. */
14528
14529static const struct asm_opcode *
14530opcode_lookup (char **str)
14531{
14532 char *end, *base;
14533 char *affix;
14534 const struct asm_opcode *opcode;
14535 const struct asm_cond *cond;
e3cb604e 14536 char save[2];
267d2029 14537 bfd_boolean neon_supported;
5f4273c7 14538
267d2029 14539 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14540
14541 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14542 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14543 for (base = end = *str; *end != '\0'; end++)
267d2029 14544 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14545 break;
b99bd4ef 14546
c19d1205
ZW
14547 if (end == base)
14548 return 0;
b99bd4ef 14549
5287ad62 14550 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14551 if (end[0] == '.')
b99bd4ef 14552 {
5287ad62 14553 int offset = 2;
5f4273c7 14554
267d2029
JB
14555 /* The .w and .n suffixes are only valid if the unified syntax is in
14556 use. */
14557 if (unified_syntax && end[1] == 'w')
c19d1205 14558 inst.size_req = 4;
267d2029 14559 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14560 inst.size_req = 2;
14561 else
5287ad62
JB
14562 offset = 0;
14563
14564 inst.vectype.elems = 0;
14565
14566 *str = end + offset;
b99bd4ef 14567
5f4273c7 14568 if (end[offset] == '.')
5287ad62 14569 {
267d2029
JB
14570 /* See if we have a Neon type suffix (possible in either unified or
14571 non-unified ARM syntax mode). */
dcbf9037 14572 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14573 return 0;
14574 }
14575 else if (end[offset] != '\0' && end[offset] != ' ')
14576 return 0;
b99bd4ef 14577 }
c19d1205
ZW
14578 else
14579 *str = end;
b99bd4ef 14580
c19d1205
ZW
14581 /* Look for unaffixed or special-case affixed mnemonic. */
14582 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14583 if (opcode)
b99bd4ef 14584 {
c19d1205
ZW
14585 /* step U */
14586 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14587 {
c19d1205
ZW
14588 inst.cond = COND_ALWAYS;
14589 return opcode;
b99bd4ef 14590 }
b99bd4ef 14591
278df34e 14592 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
14593 as_warn (_("conditional infixes are deprecated in unified syntax"));
14594 affix = base + (opcode->tag - OT_odd_infix_0);
14595 cond = hash_find_n (arm_cond_hsh, affix, 2);
14596 assert (cond);
b99bd4ef 14597
c19d1205
ZW
14598 inst.cond = cond->value;
14599 return opcode;
14600 }
b99bd4ef 14601
c19d1205
ZW
14602 /* Cannot have a conditional suffix on a mnemonic of less than two
14603 characters. */
14604 if (end - base < 3)
14605 return 0;
b99bd4ef 14606
c19d1205
ZW
14607 /* Look for suffixed mnemonic. */
14608 affix = end - 2;
14609 cond = hash_find_n (arm_cond_hsh, affix, 2);
14610 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14611 if (opcode && cond)
14612 {
14613 /* step CE */
14614 switch (opcode->tag)
14615 {
e3cb604e
PB
14616 case OT_cinfix3_legacy:
14617 /* Ignore conditional suffixes matched on infix only mnemonics. */
14618 break;
14619
c19d1205 14620 case OT_cinfix3:
088fa78e 14621 case OT_cinfix3_deprecated:
c19d1205
ZW
14622 case OT_odd_infix_unc:
14623 if (!unified_syntax)
e3cb604e 14624 return 0;
c19d1205
ZW
14625 /* else fall through */
14626
14627 case OT_csuffix:
037e8744 14628 case OT_csuffixF:
c19d1205
ZW
14629 case OT_csuf_or_in3:
14630 inst.cond = cond->value;
14631 return opcode;
14632
14633 case OT_unconditional:
14634 case OT_unconditionalF:
dfa9f0d5
PB
14635 if (thumb_mode)
14636 {
14637 inst.cond = cond->value;
14638 }
14639 else
14640 {
14641 /* delayed diagnostic */
14642 inst.error = BAD_COND;
14643 inst.cond = COND_ALWAYS;
14644 }
c19d1205 14645 return opcode;
b99bd4ef 14646
c19d1205
ZW
14647 default:
14648 return 0;
14649 }
14650 }
b99bd4ef 14651
c19d1205
ZW
14652 /* Cannot have a usual-position infix on a mnemonic of less than
14653 six characters (five would be a suffix). */
14654 if (end - base < 6)
14655 return 0;
b99bd4ef 14656
c19d1205
ZW
14657 /* Look for infixed mnemonic in the usual position. */
14658 affix = base + 3;
14659 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14660 if (!cond)
14661 return 0;
14662
14663 memcpy (save, affix, 2);
14664 memmove (affix, affix + 2, (end - affix) - 2);
14665 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14666 memmove (affix + 2, affix, (end - affix) - 2);
14667 memcpy (affix, save, 2);
14668
088fa78e
KH
14669 if (opcode
14670 && (opcode->tag == OT_cinfix3
14671 || opcode->tag == OT_cinfix3_deprecated
14672 || opcode->tag == OT_csuf_or_in3
14673 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14674 {
c19d1205 14675 /* step CM */
278df34e 14676 if (warn_on_deprecated && unified_syntax
088fa78e
KH
14677 && (opcode->tag == OT_cinfix3
14678 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14679 as_warn (_("conditional infixes are deprecated in unified syntax"));
14680
14681 inst.cond = cond->value;
14682 return opcode;
b99bd4ef
NC
14683 }
14684
c19d1205 14685 return 0;
b99bd4ef
NC
14686}
14687
c19d1205
ZW
14688void
14689md_assemble (char *str)
b99bd4ef 14690{
c19d1205
ZW
14691 char *p = str;
14692 const struct asm_opcode * opcode;
b99bd4ef 14693
c19d1205
ZW
14694 /* Align the previous label if needed. */
14695 if (last_label_seen != NULL)
b99bd4ef 14696 {
c19d1205
ZW
14697 symbol_set_frag (last_label_seen, frag_now);
14698 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14699 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14700 }
14701
c19d1205
ZW
14702 memset (&inst, '\0', sizeof (inst));
14703 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14704
c19d1205
ZW
14705 opcode = opcode_lookup (&p);
14706 if (!opcode)
b99bd4ef 14707 {
c19d1205 14708 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14709 the form alias .req reg, or a Neon .dn/.qn directive. */
14710 if (!create_register_alias (str, p)
14711 && !create_neon_reg_alias (str, p))
c19d1205 14712 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14713
b99bd4ef
NC
14714 return;
14715 }
14716
278df34e 14717 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
14718 as_warn (_("s suffix on comparison instruction is deprecated"));
14719
037e8744
JB
14720 /* The value which unconditional instructions should have in place of the
14721 condition field. */
14722 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14723
c19d1205 14724 if (thumb_mode)
b99bd4ef 14725 {
e74cfd16 14726 arm_feature_set variant;
8f06b2d8
PB
14727
14728 variant = cpu_variant;
14729 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14730 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14731 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14732 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14733 if (!opcode->tvariant
14734 || (thumb_mode == 1
14735 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14736 {
c19d1205 14737 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14738 return;
14739 }
c19d1205
ZW
14740 if (inst.cond != COND_ALWAYS && !unified_syntax
14741 && opcode->tencode != do_t_branch)
b99bd4ef 14742 {
c19d1205 14743 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14744 return;
14745 }
14746
076d447c
PB
14747 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14748 {
14749 /* Implicit require narrow instructions on Thumb-1. This avoids
14750 relaxation accidentally introducing Thumb-2 instructions. */
7e806470 14751 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
04e2c417
MM
14752 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14753 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
076d447c
PB
14754 inst.size_req = 2;
14755 }
14756
e27ec89e
PB
14757 /* Check conditional suffixes. */
14758 if (current_it_mask)
14759 {
14760 int cond;
14761 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14762 current_it_mask <<= 1;
14763 current_it_mask &= 0x1f;
14764 /* The BKPT instruction is unconditional even in an IT block. */
14765 if (!inst.error
14766 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14767 {
14768 as_bad (_("incorrect condition in IT block"));
14769 return;
14770 }
e27ec89e
PB
14771 }
14772 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14773 {
6decc662 14774 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14775 return;
14776 }
14777
c19d1205
ZW
14778 mapping_state (MAP_THUMB);
14779 inst.instruction = opcode->tvalue;
14780
14781 if (!parse_operands (p, opcode->operands))
14782 opcode->tencode ();
14783
e27ec89e
PB
14784 /* Clear current_it_mask at the end of an IT block. */
14785 if (current_it_mask == 0x10)
14786 current_it_mask = 0;
14787
0110f2b8 14788 if (!(inst.error || inst.relax))
b99bd4ef 14789 {
c19d1205
ZW
14790 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14791 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14792 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14793 {
c19d1205 14794 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14795 return;
14796 }
14797 }
076d447c
PB
14798
14799 /* Something has gone badly wrong if we try to relax a fixed size
14800 instruction. */
14801 assert (inst.size_req == 0 || !inst.relax);
14802
e74cfd16
PB
14803 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14804 *opcode->tvariant);
ee065d83 14805 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14806 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14807 anything other than bl/blx and v6-M instructions.
ee065d83 14808 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14809 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14810 || inst.relax)
04e2c417
MM
14811 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14812 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
14813 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14814 arm_ext_v6t2);
c19d1205 14815 }
3e9e4fcf 14816 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14817 {
845b51d6
PB
14818 bfd_boolean is_bx;
14819
14820 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14821 is_bx = (opcode->aencode == do_bx);
14822
c19d1205 14823 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14824 if (!(is_bx && fix_v4bx)
14825 && !(opcode->avariant &&
14826 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14827 {
c19d1205
ZW
14828 as_bad (_("selected processor does not support `%s'"), str);
14829 return;
b99bd4ef 14830 }
c19d1205 14831 if (inst.size_req)
b99bd4ef 14832 {
c19d1205
ZW
14833 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14834 return;
b99bd4ef
NC
14835 }
14836
c19d1205
ZW
14837 mapping_state (MAP_ARM);
14838 inst.instruction = opcode->avalue;
14839 if (opcode->tag == OT_unconditionalF)
14840 inst.instruction |= 0xF << 28;
14841 else
14842 inst.instruction |= inst.cond << 28;
14843 inst.size = INSN_SIZE;
14844 if (!parse_operands (p, opcode->operands))
14845 opcode->aencode ();
ee065d83
PB
14846 /* Arm mode bx is marked as both v4T and v5 because it's still required
14847 on a hypothetical non-thumb v5 core. */
845b51d6 14848 if (is_bx)
e74cfd16 14849 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14850 else
e74cfd16
PB
14851 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14852 *opcode->avariant);
b99bd4ef 14853 }
3e9e4fcf
JB
14854 else
14855 {
14856 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14857 "-- `%s'"), str);
14858 return;
14859 }
c19d1205
ZW
14860 output_inst (str);
14861}
b99bd4ef 14862
c19d1205
ZW
14863/* Various frobbings of labels and their addresses. */
14864
14865void
14866arm_start_line_hook (void)
14867{
14868 last_label_seen = NULL;
b99bd4ef
NC
14869}
14870
c19d1205
ZW
14871void
14872arm_frob_label (symbolS * sym)
b99bd4ef 14873{
c19d1205 14874 last_label_seen = sym;
b99bd4ef 14875
c19d1205 14876 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14877
c19d1205
ZW
14878#if defined OBJ_COFF || defined OBJ_ELF
14879 ARM_SET_INTERWORK (sym, support_interwork);
14880#endif
b99bd4ef 14881
5f4273c7 14882 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14883 as Thumb functions. This is because these labels, whilst
14884 they exist inside Thumb code, are not the entry points for
14885 possible ARM->Thumb calls. Also, these labels can be used
14886 as part of a computed goto or switch statement. eg gcc
14887 can generate code that looks like this:
b99bd4ef 14888
c19d1205
ZW
14889 ldr r2, [pc, .Laaa]
14890 lsl r3, r3, #2
14891 ldr r2, [r3, r2]
14892 mov pc, r2
b99bd4ef 14893
c19d1205
ZW
14894 .Lbbb: .word .Lxxx
14895 .Lccc: .word .Lyyy
14896 ..etc...
14897 .Laaa: .word Lbbb
b99bd4ef 14898
c19d1205
ZW
14899 The first instruction loads the address of the jump table.
14900 The second instruction converts a table index into a byte offset.
14901 The third instruction gets the jump address out of the table.
14902 The fourth instruction performs the jump.
b99bd4ef 14903
c19d1205
ZW
14904 If the address stored at .Laaa is that of a symbol which has the
14905 Thumb_Func bit set, then the linker will arrange for this address
14906 to have the bottom bit set, which in turn would mean that the
14907 address computation performed by the third instruction would end
14908 up with the bottom bit set. Since the ARM is capable of unaligned
14909 word loads, the instruction would then load the incorrect address
14910 out of the jump table, and chaos would ensue. */
14911 if (label_is_thumb_function_name
14912 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14913 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14914 {
c19d1205
ZW
14915 /* When the address of a Thumb function is taken the bottom
14916 bit of that address should be set. This will allow
14917 interworking between Arm and Thumb functions to work
14918 correctly. */
b99bd4ef 14919
c19d1205 14920 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14921
c19d1205 14922 label_is_thumb_function_name = FALSE;
b99bd4ef 14923 }
07a53e5c 14924
07a53e5c 14925 dwarf2_emit_label (sym);
b99bd4ef
NC
14926}
14927
c19d1205
ZW
14928int
14929arm_data_in_code (void)
b99bd4ef 14930{
c19d1205 14931 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14932 {
c19d1205
ZW
14933 *input_line_pointer = '/';
14934 input_line_pointer += 5;
14935 *input_line_pointer = 0;
14936 return 1;
b99bd4ef
NC
14937 }
14938
c19d1205 14939 return 0;
b99bd4ef
NC
14940}
14941
c19d1205
ZW
14942char *
14943arm_canonicalize_symbol_name (char * name)
b99bd4ef 14944{
c19d1205 14945 int len;
b99bd4ef 14946
c19d1205
ZW
14947 if (thumb_mode && (len = strlen (name)) > 5
14948 && streq (name + len - 5, "/data"))
14949 *(name + len - 5) = 0;
b99bd4ef 14950
c19d1205 14951 return name;
b99bd4ef 14952}
c19d1205
ZW
14953\f
14954/* Table of all register names defined by default. The user can
14955 define additional names with .req. Note that all register names
14956 should appear in both upper and lowercase variants. Some registers
14957 also have mixed-case names. */
b99bd4ef 14958
dcbf9037 14959#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14960#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14961#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14962#define REGSET(p,t) \
14963 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14964 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14965 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14966 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14967#define REGSETH(p,t) \
14968 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14969 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14970 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14971 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14972#define REGSET2(p,t) \
14973 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14974 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14975 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14976 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14977
c19d1205 14978static const struct reg_entry reg_names[] =
7ed4c4c5 14979{
c19d1205
ZW
14980 /* ARM integer registers. */
14981 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14982
c19d1205
ZW
14983 /* ATPCS synonyms. */
14984 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14985 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14986 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14987
c19d1205
ZW
14988 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14989 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14990 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14991
c19d1205
ZW
14992 /* Well-known aliases. */
14993 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14994 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14995
14996 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14997 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14998
14999 /* Coprocessor numbers. */
15000 REGSET(p, CP), REGSET(P, CP),
15001
15002 /* Coprocessor register numbers. The "cr" variants are for backward
15003 compatibility. */
15004 REGSET(c, CN), REGSET(C, CN),
15005 REGSET(cr, CN), REGSET(CR, CN),
15006
15007 /* FPA registers. */
15008 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15009 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15010
15011 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15012 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15013
15014 /* VFP SP registers. */
5287ad62
JB
15015 REGSET(s,VFS), REGSET(S,VFS),
15016 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15017
15018 /* VFP DP Registers. */
5287ad62
JB
15019 REGSET(d,VFD), REGSET(D,VFD),
15020 /* Extra Neon DP registers. */
15021 REGSETH(d,VFD), REGSETH(D,VFD),
15022
15023 /* Neon QP registers. */
15024 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15025
15026 /* VFP control registers. */
15027 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15028 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15029 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15030 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15031 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15032 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15033
15034 /* Maverick DSP coprocessor registers. */
15035 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15036 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15037
15038 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15039 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15040 REGDEF(dspsc,0,DSPSC),
15041
15042 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15043 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15044 REGDEF(DSPSC,0,DSPSC),
15045
15046 /* iWMMXt data registers - p0, c0-15. */
15047 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15048
15049 /* iWMMXt control registers - p1, c0-3. */
15050 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15051 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15052 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15053 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15054
15055 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15056 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15057 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15058 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15059 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15060
15061 /* XScale accumulator registers. */
15062 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15063};
15064#undef REGDEF
15065#undef REGNUM
15066#undef REGSET
7ed4c4c5 15067
c19d1205
ZW
15068/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15069 within psr_required_here. */
15070static const struct asm_psr psrs[] =
15071{
15072 /* Backward compatibility notation. Note that "all" is no longer
15073 truly all possible PSR bits. */
15074 {"all", PSR_c | PSR_f},
15075 {"flg", PSR_f},
15076 {"ctl", PSR_c},
15077
15078 /* Individual flags. */
15079 {"f", PSR_f},
15080 {"c", PSR_c},
15081 {"x", PSR_x},
15082 {"s", PSR_s},
15083 /* Combinations of flags. */
15084 {"fs", PSR_f | PSR_s},
15085 {"fx", PSR_f | PSR_x},
15086 {"fc", PSR_f | PSR_c},
15087 {"sf", PSR_s | PSR_f},
15088 {"sx", PSR_s | PSR_x},
15089 {"sc", PSR_s | PSR_c},
15090 {"xf", PSR_x | PSR_f},
15091 {"xs", PSR_x | PSR_s},
15092 {"xc", PSR_x | PSR_c},
15093 {"cf", PSR_c | PSR_f},
15094 {"cs", PSR_c | PSR_s},
15095 {"cx", PSR_c | PSR_x},
15096 {"fsx", PSR_f | PSR_s | PSR_x},
15097 {"fsc", PSR_f | PSR_s | PSR_c},
15098 {"fxs", PSR_f | PSR_x | PSR_s},
15099 {"fxc", PSR_f | PSR_x | PSR_c},
15100 {"fcs", PSR_f | PSR_c | PSR_s},
15101 {"fcx", PSR_f | PSR_c | PSR_x},
15102 {"sfx", PSR_s | PSR_f | PSR_x},
15103 {"sfc", PSR_s | PSR_f | PSR_c},
15104 {"sxf", PSR_s | PSR_x | PSR_f},
15105 {"sxc", PSR_s | PSR_x | PSR_c},
15106 {"scf", PSR_s | PSR_c | PSR_f},
15107 {"scx", PSR_s | PSR_c | PSR_x},
15108 {"xfs", PSR_x | PSR_f | PSR_s},
15109 {"xfc", PSR_x | PSR_f | PSR_c},
15110 {"xsf", PSR_x | PSR_s | PSR_f},
15111 {"xsc", PSR_x | PSR_s | PSR_c},
15112 {"xcf", PSR_x | PSR_c | PSR_f},
15113 {"xcs", PSR_x | PSR_c | PSR_s},
15114 {"cfs", PSR_c | PSR_f | PSR_s},
15115 {"cfx", PSR_c | PSR_f | PSR_x},
15116 {"csf", PSR_c | PSR_s | PSR_f},
15117 {"csx", PSR_c | PSR_s | PSR_x},
15118 {"cxf", PSR_c | PSR_x | PSR_f},
15119 {"cxs", PSR_c | PSR_x | PSR_s},
15120 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15121 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15122 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15123 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15124 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15125 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15126 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15127 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15128 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15129 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15130 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15131 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15132 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15133 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15134 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15135 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15136 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15137 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15138 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15139 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15140 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15141 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15142 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15143 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15144};
15145
62b3e311
PB
15146/* Table of V7M psr names. */
15147static const struct asm_psr v7m_psrs[] =
15148{
2b744c99
PB
15149 {"apsr", 0 }, {"APSR", 0 },
15150 {"iapsr", 1 }, {"IAPSR", 1 },
15151 {"eapsr", 2 }, {"EAPSR", 2 },
15152 {"psr", 3 }, {"PSR", 3 },
15153 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15154 {"ipsr", 5 }, {"IPSR", 5 },
15155 {"epsr", 6 }, {"EPSR", 6 },
15156 {"iepsr", 7 }, {"IEPSR", 7 },
15157 {"msp", 8 }, {"MSP", 8 },
15158 {"psp", 9 }, {"PSP", 9 },
15159 {"primask", 16}, {"PRIMASK", 16},
15160 {"basepri", 17}, {"BASEPRI", 17},
15161 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15162 {"faultmask", 19}, {"FAULTMASK", 19},
15163 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
15164};
15165
c19d1205
ZW
15166/* Table of all shift-in-operand names. */
15167static const struct asm_shift_name shift_names [] =
b99bd4ef 15168{
c19d1205
ZW
15169 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15170 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15171 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15172 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15173 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15174 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15175};
b99bd4ef 15176
c19d1205
ZW
15177/* Table of all explicit relocation names. */
15178#ifdef OBJ_ELF
15179static struct reloc_entry reloc_names[] =
15180{
15181 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15182 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15183 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15184 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15185 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15186 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15187 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15188 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15189 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15190 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15191 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15192};
15193#endif
b99bd4ef 15194
c19d1205
ZW
15195/* Table of all conditional affixes. 0xF is not defined as a condition code. */
15196static const struct asm_cond conds[] =
15197{
15198 {"eq", 0x0},
15199 {"ne", 0x1},
15200 {"cs", 0x2}, {"hs", 0x2},
15201 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15202 {"mi", 0x4},
15203 {"pl", 0x5},
15204 {"vs", 0x6},
15205 {"vc", 0x7},
15206 {"hi", 0x8},
15207 {"ls", 0x9},
15208 {"ge", 0xa},
15209 {"lt", 0xb},
15210 {"gt", 0xc},
15211 {"le", 0xd},
15212 {"al", 0xe}
15213};
bfae80f2 15214
62b3e311
PB
15215static struct asm_barrier_opt barrier_opt_names[] =
15216{
15217 { "sy", 0xf },
15218 { "un", 0x7 },
15219 { "st", 0xe },
15220 { "unst", 0x6 }
15221};
15222
c19d1205
ZW
15223/* Table of ARM-format instructions. */
15224
15225/* Macros for gluing together operand strings. N.B. In all cases
15226 other than OPS0, the trailing OP_stop comes from default
15227 zero-initialization of the unspecified elements of the array. */
15228#define OPS0() { OP_stop, }
15229#define OPS1(a) { OP_##a, }
15230#define OPS2(a,b) { OP_##a,OP_##b, }
15231#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15232#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15233#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15234#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15235
15236/* These macros abstract out the exact format of the mnemonic table and
15237 save some repeated characters. */
15238
15239/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15240#define TxCE(mnem, op, top, nops, ops, ae, te) \
15241 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 15242 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15243
15244/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15245 a T_MNEM_xyz enumerator. */
15246#define TCE(mnem, aop, top, nops, ops, ae, te) \
15247 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
15248#define tCE(mnem, aop, top, nops, ops, ae, te) \
15249 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15250
15251/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15252 infix after the third character. */
15253#define TxC3(mnem, op, top, nops, ops, ae, te) \
15254 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 15255 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
15256#define TxC3w(mnem, op, top, nops, ops, ae, te) \
15257 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15258 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15259#define TC3(mnem, aop, top, nops, ops, ae, te) \
15260 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
15261#define TC3w(mnem, aop, top, nops, ops, ae, te) \
15262 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
15263#define tC3(mnem, aop, top, nops, ops, ae, te) \
15264 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
15265#define tC3w(mnem, aop, top, nops, ops, ae, te) \
15266 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15267
15268/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15269 appear in the condition table. */
15270#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
15271 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 15272 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15273
15274#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
15275 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
15276 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
15277 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
15278 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
15279 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
15280 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
15281 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
15282 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
15283 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
15284 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
15285 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
15286 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
15287 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
15288 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
15289 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
15290 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
15291 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
15292 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
15293 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
15294
15295#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
15296 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
15297#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15298 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
15299
15300/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
15301 field is still 0xE. Many of the Thumb variants can be executed
15302 conditionally, so this is checked separately. */
c19d1205
ZW
15303#define TUE(mnem, op, top, nops, ops, ae, te) \
15304 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15305 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15306
15307/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15308 condition code field. */
15309#define TUF(mnem, op, top, nops, ops, ae, te) \
15310 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15311 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15312
15313/* ARM-only variants of all the above. */
6a86118a
NC
15314#define CE(mnem, op, nops, ops, ae) \
15315 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15316
15317#define C3(mnem, op, nops, ops, ae) \
15318 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15319
e3cb604e
PB
15320/* Legacy mnemonics that always have conditional infix after the third
15321 character. */
15322#define CL(mnem, op, nops, ops, ae) \
15323 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15324 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15325
8f06b2d8
PB
15326/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15327#define cCE(mnem, op, nops, ops, ae) \
15328 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15329
e3cb604e
PB
15330/* Legacy coprocessor instructions where conditional infix and conditional
15331 suffix are ambiguous. For consistency this includes all FPA instructions,
15332 not just the potentially ambiguous ones. */
15333#define cCL(mnem, op, nops, ops, ae) \
15334 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15335 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15336
15337/* Coprocessor, takes either a suffix or a position-3 infix
15338 (for an FPA corner case). */
15339#define C3E(mnem, op, nops, ops, ae) \
15340 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15341 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 15342
6a86118a
NC
15343#define xCM_(m1, m2, m3, op, nops, ops, ae) \
15344 { #m1 #m2 #m3, OPS##nops ops, \
15345 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15346 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15347
15348#define CM(m1, m2, op, nops, ops, ae) \
15349 xCM_(m1, , m2, op, nops, ops, ae), \
15350 xCM_(m1, eq, m2, op, nops, ops, ae), \
15351 xCM_(m1, ne, m2, op, nops, ops, ae), \
15352 xCM_(m1, cs, m2, op, nops, ops, ae), \
15353 xCM_(m1, hs, m2, op, nops, ops, ae), \
15354 xCM_(m1, cc, m2, op, nops, ops, ae), \
15355 xCM_(m1, ul, m2, op, nops, ops, ae), \
15356 xCM_(m1, lo, m2, op, nops, ops, ae), \
15357 xCM_(m1, mi, m2, op, nops, ops, ae), \
15358 xCM_(m1, pl, m2, op, nops, ops, ae), \
15359 xCM_(m1, vs, m2, op, nops, ops, ae), \
15360 xCM_(m1, vc, m2, op, nops, ops, ae), \
15361 xCM_(m1, hi, m2, op, nops, ops, ae), \
15362 xCM_(m1, ls, m2, op, nops, ops, ae), \
15363 xCM_(m1, ge, m2, op, nops, ops, ae), \
15364 xCM_(m1, lt, m2, op, nops, ops, ae), \
15365 xCM_(m1, gt, m2, op, nops, ops, ae), \
15366 xCM_(m1, le, m2, op, nops, ops, ae), \
15367 xCM_(m1, al, m2, op, nops, ops, ae)
15368
15369#define UE(mnem, op, nops, ops, ae) \
15370 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15371
15372#define UF(mnem, op, nops, ops, ae) \
15373 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15374
5287ad62
JB
15375/* Neon data-processing. ARM versions are unconditional with cond=0xf.
15376 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15377 use the same encoding function for each. */
15378#define NUF(mnem, op, nops, ops, enc) \
15379 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15380 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15381
15382/* Neon data processing, version which indirects through neon_enc_tab for
15383 the various overloaded versions of opcodes. */
15384#define nUF(mnem, op, nops, ops, enc) \
15385 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15386 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15387
15388/* Neon insn with conditional suffix for the ARM version, non-overloaded
15389 version. */
037e8744
JB
15390#define NCE_tag(mnem, op, nops, ops, enc, tag) \
15391 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
15392 THUMB_VARIANT, do_##enc, do_##enc }
15393
037e8744
JB
15394#define NCE(mnem, op, nops, ops, enc) \
15395 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15396
15397#define NCEF(mnem, op, nops, ops, enc) \
15398 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15399
5287ad62 15400/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
15401#define nCE_tag(mnem, op, nops, ops, enc, tag) \
15402 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
15403 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15404
037e8744
JB
15405#define nCE(mnem, op, nops, ops, enc) \
15406 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15407
15408#define nCEF(mnem, op, nops, ops, enc) \
15409 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15410
c19d1205
ZW
15411#define do_0 0
15412
15413/* Thumb-only, unconditional. */
15414#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
15415
c19d1205 15416static const struct asm_opcode insns[] =
bfae80f2 15417{
e74cfd16
PB
15418#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15419#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15420 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15421 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15422 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15423 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15424 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15425 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
15426 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15427 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
15428 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15429 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15430 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15431 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15432 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15433 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15434 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15435 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15436
15437 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15438 for setting PSR flag bits. They are obsolete in V6 and do not
15439 have Thumb equivalents. */
15440 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15441 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15442 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 15443 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 15444 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 15445 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 15446 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15447 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15448 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
15449
15450 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15451 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15452 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15453 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15454
4962c51a
MS
15455 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15456 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15457 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15458 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 15459
f5208ef2 15460 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15461 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15462 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 15463 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15464 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15465 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15466
15467 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 15468 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 15469 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 15470 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 15471
c19d1205 15472 /* Pseudo ops. */
e9f89963 15473 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
15474 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15475 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
15476
15477 /* Thumb-compatibility pseudo ops. */
15478 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15479 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15480 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15481 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15482 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 15483 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
15484 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15485 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15486 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15487 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15488 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15489 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15490
16a4cf17
PB
15491 /* These may simplify to neg. */
15492 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15493 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15494
c19d1205 15495#undef THUMB_VARIANT
e74cfd16 15496#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 15497 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
15498
15499 /* V1 instructions with no Thumb analogue prior to V6T2. */
15500#undef THUMB_VARIANT
e74cfd16 15501#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15502 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15503 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15504 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
15505
15506 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15507 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15508 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15509 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15510
9c3c69f2
PB
15511 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15512 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 15513
9c3c69f2
PB
15514 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15515 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15516
15517 /* V1 instructions with no Thumb analogue at all. */
15518 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15519 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15520
15521 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15522 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15523 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15524 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15525 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15526 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15527 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15528 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15529
15530#undef ARM_VARIANT
e74cfd16 15531#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15532#undef THUMB_VARIANT
e74cfd16 15533#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15534 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15535 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15536
15537#undef THUMB_VARIANT
e74cfd16 15538#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15539 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15540 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15541
15542 /* Generic coprocessor instructions. */
15543 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15544 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15545 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15546 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15547 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15548 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15549 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15550
15551#undef ARM_VARIANT
e74cfd16 15552#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15553 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15554 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15555
15556#undef ARM_VARIANT
e74cfd16 15557#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15558#undef THUMB_VARIANT
15559#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15560 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15561 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15562
15563#undef ARM_VARIANT
e74cfd16 15564#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15565#undef THUMB_VARIANT
15566#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15567 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15568 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15569 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15570 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15571 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15572 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15573 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15574 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15575
15576#undef ARM_VARIANT
e74cfd16 15577#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15578#undef THUMB_VARIANT
e74cfd16 15579#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15580 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15581 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15582 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15583 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15584 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15585 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15586
15587#undef ARM_VARIANT
e74cfd16 15588#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15589 /* ARM Architecture 4T. */
15590 /* Note: bx (and blx) are required on V5, even if the processor does
15591 not support Thumb. */
15592 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15593
15594#undef ARM_VARIANT
e74cfd16 15595#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15596#undef THUMB_VARIANT
e74cfd16 15597#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15598 /* Note: blx has 2 variants; the .value coded here is for
15599 BLX(2). Only this variant has conditional execution. */
15600 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15601 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15602
15603#undef THUMB_VARIANT
e74cfd16 15604#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15605 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15606 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15607 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15608 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15609 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15610 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15611 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15612 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15613
15614#undef ARM_VARIANT
e74cfd16 15615#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15616 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15617 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15618 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15619 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15620
15621 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15622 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15623
15624 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15625 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15626 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15627 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15628
15629 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15630 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15631 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15632 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15633
15634 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15635 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15636
087b80de
JM
15637 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15638 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15639 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15640 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205
ZW
15641
15642#undef ARM_VARIANT
e74cfd16 15643#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15644 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15645 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15646 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15647
15648 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15649 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15650
15651#undef ARM_VARIANT
e74cfd16 15652#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15653 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15654
15655#undef ARM_VARIANT
e74cfd16 15656#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15657#undef THUMB_VARIANT
e74cfd16 15658#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15659 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15660 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15661 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15662 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15663 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15664 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15665 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15666 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15667 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15668 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15669
15670#undef THUMB_VARIANT
e74cfd16 15671#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15672 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15673 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15674 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15675 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15676
15677 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15678 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15679
15680/* ARM V6 not included in V7M (eg. integer SIMD). */
15681#undef THUMB_VARIANT
15682#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15683 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15684 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15685 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15686 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15687 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15688 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15689 /* Old name for QASX. */
c19d1205 15690 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15691 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15692 /* Old name for QSAX. */
15693 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15694 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15695 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15696 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15697 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15698 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15699 /* Old name for SASX. */
c19d1205
ZW
15700 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15701 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15702 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15703 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15704 /* Old name for SHASX. */
c19d1205 15705 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15706 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15707 /* Old name for SHSAX. */
15708 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15709 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15710 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15711 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15712 /* Old name for SSAX. */
15713 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15714 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15715 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15716 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15717 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15718 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15719 /* Old name for UASX. */
c19d1205
ZW
15720 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15721 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15722 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15723 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15724 /* Old name for UHASX. */
c19d1205 15725 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15726 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15727 /* Old name for UHSAX. */
15728 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15729 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15730 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15731 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15732 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15733 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15734 /* Old name for UQASX. */
c19d1205 15735 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15736 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15737 /* Old name for UQSAX. */
15738 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15739 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15740 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205 15741 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15742 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15743 /* Old name for USAX. */
c19d1205 15744 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 15745 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15746 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15747 UF(rfeib, 9900a00, 1, (RRw), rfe),
15748 UF(rfeda, 8100a00, 1, (RRw), rfe),
15749 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15750 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15751 UF(rfefa, 9900a00, 1, (RRw), rfe),
15752 UF(rfeea, 8100a00, 1, (RRw), rfe),
15753 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15754 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15755 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15756 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15757 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15758 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15759 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15760 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15761 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15762 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15763 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15764 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15765 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15766 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15767 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15768 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15769 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15770 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15771 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15772 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15773 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15774 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15775 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15776 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15777 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15778 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15779 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15780 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15781 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15782 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15783 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15784 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15785 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15786 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15787 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15788 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15789 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15790
15791#undef ARM_VARIANT
e74cfd16 15792#define ARM_VARIANT &arm_ext_v6k
c19d1205 15793#undef THUMB_VARIANT
e74cfd16 15794#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15795 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15796 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15797 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15798 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15799
ebdca51a
PB
15800#undef THUMB_VARIANT
15801#define THUMB_VARIANT &arm_ext_v6_notm
15802 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15803 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15804
c19d1205 15805#undef THUMB_VARIANT
e74cfd16 15806#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15807 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15808 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15809 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15810 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15811 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15812
15813#undef ARM_VARIANT
e74cfd16 15814#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15815 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15816
15817#undef ARM_VARIANT
e74cfd16 15818#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15819 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15820 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15821 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15822 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15823
15824 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15825 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15826 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15827 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15828
15829 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15830 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15831 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15832 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15833
25fe350b
MS
15834 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15835 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15836 /* ARM does not really have an IT instruction, so always allow it. */
15837#undef ARM_VARIANT
15838#define ARM_VARIANT &arm_ext_v1
1c444d06
JM
15839 TUE(it, 0, bf08, 1, (COND), it, t_it),
15840 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15841 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15842 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15843 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15844 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15845 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15846 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15847 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15848 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15849 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15850 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15851 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15852 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15853 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15854 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
15855 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
15856 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 15857
92e90b6e
PB
15858 /* Thumb2 only instructions. */
15859#undef ARM_VARIANT
e74cfd16 15860#define ARM_VARIANT NULL
92e90b6e
PB
15861
15862 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15863 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
1c444d06
JM
15864 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
15865 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
92e90b6e
PB
15866 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15867 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15868
62b3e311
PB
15869 /* Thumb-2 hardware division instructions (R and M profiles only). */
15870#undef THUMB_VARIANT
15871#define THUMB_VARIANT &arm_ext_div
15872 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15873 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15874
7e806470
PB
15875 /* ARM V6M/V7 instructions. */
15876#undef ARM_VARIANT
15877#define ARM_VARIANT &arm_ext_barrier
15878#undef THUMB_VARIANT
15879#define THUMB_VARIANT &arm_ext_barrier
15880 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15881 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15882 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15883
62b3e311
PB
15884 /* ARM V7 instructions. */
15885#undef ARM_VARIANT
15886#define ARM_VARIANT &arm_ext_v7
15887#undef THUMB_VARIANT
15888#define THUMB_VARIANT &arm_ext_v7
15889 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15890 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15891
c19d1205 15892#undef ARM_VARIANT
e74cfd16 15893#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15894 cCE(wfs, e200110, 1, (RR), rd),
15895 cCE(rfs, e300110, 1, (RR), rd),
15896 cCE(wfc, e400110, 1, (RR), rd),
15897 cCE(rfc, e500110, 1, (RR), rd),
15898
4962c51a
MS
15899 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15900 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15901 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15902 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15903
4962c51a
MS
15904 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15905 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15906 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15907 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15908
15909 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15910 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15911 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15912 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15913 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15914 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15915 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15916 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15917 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15918 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15919 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15920 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15921
15922 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15923 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15924 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15925 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15926 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15927 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15928 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15929 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15930 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15931 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15932 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15933 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15934
15935 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15936 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15937 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15938 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15939 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15940 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15941 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15942 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15943 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15944 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15945 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15946 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15947
15948 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15949 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15950 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15951 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15952 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15953 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15954 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15955 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15956 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15957 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15958 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15959 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15960
15961 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15962 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15963 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15964 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15965 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15966 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15967 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15968 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15969 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15970 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15971 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15972 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15973
15974 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15975 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15976 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15977 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15978 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15979 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15980 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15981 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15982 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15983 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15984 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15985 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15986
15987 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15988 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15989 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15990 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15991 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15992 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15993 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15994 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15995 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15996 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15997 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15998 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15999
16000 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
16001 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
16002 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
16003 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
16004 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
16005 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
16006 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
16007 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
16008 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
16009 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
16010 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
16011 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
16012
16013 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
16014 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16015 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16016 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16017 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16018 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16019 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16020 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16021 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16022 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16023 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16024 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16025
16026 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16027 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16028 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16029 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16030 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16031 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16032 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16033 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16034 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16035 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16036 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16037 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16038
16039 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16040 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16041 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16042 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16043 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16044 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16045 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16046 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16047 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16048 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16049 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16050 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16051
16052 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16053 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16054 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16055 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16056 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16057 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16058 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16059 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16060 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16061 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16062 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16063 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16064
16065 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16066 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16067 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16068 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16069 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16070 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16071 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16072 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16073 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16074 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16075 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16076 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16077
16078 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16079 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16080 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16081 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16082 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16083 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16084 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16085 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16086 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16087 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16088 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16089 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16090
16091 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16092 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16093 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16094 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16095 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16096 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16097 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16098 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16099 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16100 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16101 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16102 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16103
16104 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16105 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16106 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16107 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16108 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16109 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16110 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16111 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16112 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16113 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16114 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16115 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16116
16117 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16118 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16119 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16120 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16121 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16122 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16123 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16124 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16125 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16126 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16127 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16128 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16129
16130 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16131 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16132 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16133 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16134 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16135 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16136 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16137 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16138 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16139 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16140 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16141 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16142
16143 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16144 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16145 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16146 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16147 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16148 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16149 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16150 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16151 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16152 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16153 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16154 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16155
16156 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16157 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16158 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16159 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16160 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16161 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16162 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16163 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16164 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16165 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16166 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16167 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16168
16169 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16170 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16171 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16172 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16173 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16174 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16175 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16176 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16177 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16178 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16179 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16180 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16181
16182 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16183 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16184 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16185 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16186 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16187 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16188 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16189 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16190 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16191 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16192 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16193 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16194
16195 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16196 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16197 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16198 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16199 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16200 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16201 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16202 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16203 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16204 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16205 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16206 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16207
16208 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16209 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16210 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16211 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16212 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16213 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16214 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16215 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16216 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16217 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16218 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16219 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16220
16221 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16222 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16223 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16224 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16225 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16226 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16227 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16228 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16229 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16230 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16231 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16232 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16233
16234 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16235 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16236 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16237 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16238 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16239 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16240 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16241 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16242 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16243 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16244 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16245 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16246
16247 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16248 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16249 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16250 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16251 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16252 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16253 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16254 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16255 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16256 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16257 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16258 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16259
16260 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16261 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16262 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16263 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16264 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16265 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16266 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16267 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16268 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16269 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16270 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16271 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16272
16273 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16274 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16275 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16276 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16277 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16278 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16279 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16280 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16281 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16282 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16283 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16284 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
16285
16286 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 16287 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 16288 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
16289 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16290
e3cb604e
PB
16291 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16292 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16293 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16294 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16295 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16296 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16297 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16298 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16299 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16300 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16301 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16302 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 16303
c19d1205
ZW
16304 /* The implementation of the FIX instruction is broken on some
16305 assemblers, in that it accepts a precision specifier as well as a
16306 rounding specifier, despite the fact that this is meaningless.
16307 To be more compatible, we accept it as well, though of course it
16308 does not set any bits. */
8f06b2d8 16309 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
16310 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16311 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16312 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16313 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16314 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16315 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16316 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16317 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16318 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16319 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16320 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16321 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 16322
c19d1205
ZW
16323 /* Instructions that were new with the real FPA, call them V2. */
16324#undef ARM_VARIANT
e74cfd16 16325#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 16326 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16327 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16328 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 16329 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16330 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16331 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
16332
16333#undef ARM_VARIANT
e74cfd16 16334#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 16335 /* Moves and type conversions. */
8f06b2d8
PB
16336 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16337 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16338 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16339 cCE(fmstat, ef1fa10, 0, (), noargs),
16340 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16341 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16342 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16343 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16344 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16345 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16346 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16347 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
16348
16349 /* Memory operations. */
4962c51a
MS
16350 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16351 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
16352 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16353 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16354 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16355 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16356 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16357 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16358 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16359 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16360 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16361 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16362 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16363 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16364 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16365 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16366 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16367 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 16368
c19d1205 16369 /* Monadic operations. */
8f06b2d8
PB
16370 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16371 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16372 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
16373
16374 /* Dyadic operations. */
8f06b2d8
PB
16375 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16376 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16377 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16378 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16379 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16380 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16381 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16382 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16383 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 16384
c19d1205 16385 /* Comparisons. */
8f06b2d8
PB
16386 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16387 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16388 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16389 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 16390
c19d1205 16391#undef ARM_VARIANT
e74cfd16 16392#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 16393 /* Moves and type conversions. */
5287ad62 16394 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
16395 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16396 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
16397 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16398 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16399 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16400 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
16401 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16402 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16403 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16404 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16405 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16406 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
16407
16408 /* Memory operations. */
4962c51a
MS
16409 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16410 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
16411 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16412 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16413 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16414 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16415 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16416 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16417 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16418 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 16419
c19d1205 16420 /* Monadic operations. */
5287ad62
JB
16421 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16422 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16423 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
16424
16425 /* Dyadic operations. */
5287ad62
JB
16426 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16427 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16428 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16429 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16430 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16431 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16432 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16433 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16434 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 16435
c19d1205 16436 /* Comparisons. */
5287ad62
JB
16437 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16438 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16439 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16440 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
16441
16442#undef ARM_VARIANT
e74cfd16 16443#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
16444 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16445 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
16446 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16447 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16448
037e8744
JB
16449/* Instructions which may belong to either the Neon or VFP instruction sets.
16450 Individual encoder functions perform additional architecture checks. */
16451#undef ARM_VARIANT
16452#define ARM_VARIANT &fpu_vfp_ext_v1xd
16453#undef THUMB_VARIANT
16454#define THUMB_VARIANT &fpu_vfp_ext_v1xd
16455 /* These mnemonics are unique to VFP. */
16456 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16457 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16458 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16459 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16460 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16461 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16462 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16463 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16464 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16465 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16466
16467 /* Mnemonics shared by Neon and VFP. */
16468 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16469 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16470 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16471
16472 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16473 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16474
16475 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16476 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16477
16478 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16479 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16480 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16481 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16482 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16483 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
16484 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16485 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
16486
16487 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
8e79c3df
CM
16488 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16489 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 16490
037e8744
JB
16491
16492 /* NOTE: All VMOV encoding is special-cased! */
16493 NCE(vmov, 0, 1, (VMOV), neon_mov),
16494 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16495
5287ad62
JB
16496#undef THUMB_VARIANT
16497#define THUMB_VARIANT &fpu_neon_ext_v1
16498#undef ARM_VARIANT
16499#define ARM_VARIANT &fpu_neon_ext_v1
16500 /* Data processing with three registers of the same length. */
16501 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16502 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16503 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16504 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16505 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16506 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16507 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16508 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16509 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16510 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
16511 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16512 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16513 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16514 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
16515 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16516 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16517 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16518 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
16519 /* If not immediate, fall back to neon_dyadic_i64_su.
16520 shl_imm should accept I8 I16 I32 I64,
16521 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
16522 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
16523 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
16524 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
16525 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
16526 /* Logic ops, types optional & ignored. */
16527 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
16528 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
16529 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
16530 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
16531 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
16532 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
16533 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
16534 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
16535 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
16536 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
16537 /* Bitfield ops, untyped. */
16538 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16539 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16540 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16541 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16542 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16543 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16544 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16545 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16546 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16547 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16548 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16549 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16550 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16551 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16552 back to neon_dyadic_if_su. */
16553 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16554 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16555 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16556 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16557 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16558 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16559 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16560 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16561 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16562 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16563 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16564 /* As above, D registers only. */
16565 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16566 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16567 /* Int and float variants, signedness unimportant. */
5287ad62 16568 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16569 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16570 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16571 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16572 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16573 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16574 /* vtst takes sizes 8, 16, 32. */
16575 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16576 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16577 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16578 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16579 /* VQD{R}MULH takes S16 S32. */
16580 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16581 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16582 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16583 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16584 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16585 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16586 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16587 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16588 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16589 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16590 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16591 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16592 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16593 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16594 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16595 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16596
16597 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16598 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16599 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16600
16601 /* Data processing with two registers and a shift amount. */
16602 /* Right shifts, and variants with rounding.
16603 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16604 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16605 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16606 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16607 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16608 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16609 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16610 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16611 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16612 /* Shift and insert. Sizes accepted 8 16 32 64. */
16613 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16614 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16615 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16616 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16617 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16618 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16619 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16620 /* Right shift immediate, saturating & narrowing, with rounding variants.
16621 Types accepted S16 S32 S64 U16 U32 U64. */
16622 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16623 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16624 /* As above, unsigned. Types accepted S16 S32 S64. */
16625 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16626 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16627 /* Right shift narrowing. Types accepted I16 I32 I64. */
16628 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16629 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16630 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16631 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16632 /* CVT with optional immediate for fixed-point variant. */
037e8744 16633 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16634
5287ad62
JB
16635 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16636 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16637
16638 /* Data processing, three registers of different lengths. */
16639 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16640 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16641 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16642 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16643 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16644 /* If not scalar, fall back to neon_dyadic_long.
16645 Vector types as above, scalar types S16 S32 U16 U32. */
16646 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16647 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16648 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16649 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16650 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16651 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16652 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16653 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16654 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16655 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16656 /* Saturating doubling multiplies. Types S16 S32. */
16657 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16658 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16659 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16660 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16661 S16 S32 U16 U32. */
16662 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16663
16664 /* Extract. Size 8. */
3b8d421e
PB
16665 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16666 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16667
16668 /* Two registers, miscellaneous. */
16669 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16670 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16671 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16672 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16673 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16674 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16675 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16676 /* Vector replicate. Sizes 8 16 32. */
16677 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16678 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16679 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16680 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16681 /* VMOVN. Types I16 I32 I64. */
16682 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16683 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16684 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16685 /* VQMOVUN. Types S16 S32 S64. */
16686 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16687 /* VZIP / VUZP. Sizes 8 16 32. */
16688 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16689 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16690 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16691 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16692 /* VQABS / VQNEG. Types S8 S16 S32. */
16693 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16694 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16695 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16696 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16697 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16698 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16699 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16700 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16701 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16702 /* Reciprocal estimates. Types U32 F32. */
16703 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16704 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16705 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16706 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16707 /* VCLS. Types S8 S16 S32. */
16708 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16709 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16710 /* VCLZ. Types I8 I16 I32. */
16711 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16712 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16713 /* VCNT. Size 8. */
16714 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16715 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16716 /* Two address, untyped. */
16717 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16718 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16719 /* VTRN. Sizes 8 16 32. */
16720 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16721 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16722
16723 /* Table lookup. Size 8. */
16724 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16725 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16726
b7fc2769
JB
16727#undef THUMB_VARIANT
16728#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16729#undef ARM_VARIANT
16730#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16731 /* Neon element/structure load/store. */
16732 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16733 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16734 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16735 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16736 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16737 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16738 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16739 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16740
16741#undef THUMB_VARIANT
16742#define THUMB_VARIANT &fpu_vfp_ext_v3
16743#undef ARM_VARIANT
16744#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16745 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16746 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16747 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16748 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16749 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16750 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16751 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16752 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16753 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16754 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16755 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16756 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16757 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16758 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16759 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16760 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16761 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16762 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16763
5287ad62 16764#undef THUMB_VARIANT
c19d1205 16765#undef ARM_VARIANT
e74cfd16 16766#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16767 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16768 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16769 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16770 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16771 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16772 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16773 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16774 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16775
16776#undef ARM_VARIANT
e74cfd16 16777#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16778 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16779 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16780 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16781 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16782 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16783 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16784 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16785 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16786 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16787 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16788 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16789 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16790 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16791 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16792 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16793 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16794 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16795 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16796 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16797 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16798 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16799 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16800 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16801 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16802 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16803 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16804 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16805 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16806 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16807 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16808 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16809 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16810 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16811 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16812 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16813 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16814 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16815 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16816 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16817 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16818 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16819 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16820 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16821 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16822 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16823 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16824 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16825 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16826 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16827 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16828 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16829 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16830 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16831 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16832 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16833 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16834 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16835 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16836 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16837 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16838 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16839 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16840 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16841 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16842 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16843 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16844 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16845 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16846 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16847 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16848 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16849 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16850 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16851 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16852 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16853 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16854 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16855 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16856 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16857 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16858 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16859 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16860 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16861 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16862 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16863 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16864 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16865 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16866 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16867 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16868 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16869 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16870 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16871 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16872 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16873 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16874 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16875 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16876 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16877 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16878 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16879 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16880 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16881 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16882 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16883 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16884 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16885 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16886 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16887 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16888 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16889 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16890 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16891 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16892 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16893 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16894 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16895 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16896 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16897 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16898 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16899 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16900 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16901 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16902 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16903 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16904 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16905 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16906 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16907 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16908 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16909 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16910 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16911 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16912 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16913 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16914 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16915 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16916 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16917 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16918 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16919 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16920 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16921 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16922 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16923 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16924 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16925 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16926 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16927 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16928 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16929 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16930 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16931 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16932 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16933 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16934 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16935 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16936 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16937 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16938 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16939 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16940
2d447fca
JM
16941#undef ARM_VARIANT
16942#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16943 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16944 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16945 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16946 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16947 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16948 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16949 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16950 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16951 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16952 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16953 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16954 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16955 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16956 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16957 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16958 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16959 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16960 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16961 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16962 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16963 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16964 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16965 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16966 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16967 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16968 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16969 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16970 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16971 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16972 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16973 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16974 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16975 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16976 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16977 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16978 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16979 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16980 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16981 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16982 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16983 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16984 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16985 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16986 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16987 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16988 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16989 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16990 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16991 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16992 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16993 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16994 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16995 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16996 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16997 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16998 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16999 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17000
c19d1205 17001#undef ARM_VARIANT
e74cfd16 17002#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
17003 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17004 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17005 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17006 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17007 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17008 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17009 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17010 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
17011 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
17012 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
17013 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
17014 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17015 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17016 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17017 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17018 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17019 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17020 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17021 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17022 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17023 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17024 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17025 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17026 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17027 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17028 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17029 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17030 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17031 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17032 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17033 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17034 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17035 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17036 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17037 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17038 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17039 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17040 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17041 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17042 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17043 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17044 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17045 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17046 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17047 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17048 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17049 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17050 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17051 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17052 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17053 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17054 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17055 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17056 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17057 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17058 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17059 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17060 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17061 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17062 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17063 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17064 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17065 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17066 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17067 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17068 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17069 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17070 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17071 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17072 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17073 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17074 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17075 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17076 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17077 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17078 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
17079};
17080#undef ARM_VARIANT
17081#undef THUMB_VARIANT
17082#undef TCE
17083#undef TCM
17084#undef TUE
17085#undef TUF
17086#undef TCC
8f06b2d8 17087#undef cCE
e3cb604e
PB
17088#undef cCL
17089#undef C3E
c19d1205
ZW
17090#undef CE
17091#undef CM
17092#undef UE
17093#undef UF
17094#undef UT
5287ad62
JB
17095#undef NUF
17096#undef nUF
17097#undef NCE
17098#undef nCE
c19d1205
ZW
17099#undef OPS0
17100#undef OPS1
17101#undef OPS2
17102#undef OPS3
17103#undef OPS4
17104#undef OPS5
17105#undef OPS6
17106#undef do_0
17107\f
17108/* MD interface: bits in the object file. */
bfae80f2 17109
c19d1205
ZW
17110/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17111 for use in the a.out file, and stores them in the array pointed to by buf.
17112 This knows about the endian-ness of the target machine and does
17113 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17114 2 (short) and 4 (long) Floating numbers are put out as a series of
17115 LITTLENUMS (shorts, here at least). */
b99bd4ef 17116
c19d1205
ZW
17117void
17118md_number_to_chars (char * buf, valueT val, int n)
17119{
17120 if (target_big_endian)
17121 number_to_chars_bigendian (buf, val, n);
17122 else
17123 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
17124}
17125
c19d1205
ZW
17126static valueT
17127md_chars_to_number (char * buf, int n)
bfae80f2 17128{
c19d1205
ZW
17129 valueT result = 0;
17130 unsigned char * where = (unsigned char *) buf;
bfae80f2 17131
c19d1205 17132 if (target_big_endian)
b99bd4ef 17133 {
c19d1205
ZW
17134 while (n--)
17135 {
17136 result <<= 8;
17137 result |= (*where++ & 255);
17138 }
b99bd4ef 17139 }
c19d1205 17140 else
b99bd4ef 17141 {
c19d1205
ZW
17142 while (n--)
17143 {
17144 result <<= 8;
17145 result |= (where[n] & 255);
17146 }
bfae80f2 17147 }
b99bd4ef 17148
c19d1205 17149 return result;
bfae80f2 17150}
b99bd4ef 17151
c19d1205 17152/* MD interface: Sections. */
b99bd4ef 17153
0110f2b8
PB
17154/* Estimate the size of a frag before relaxing. Assume everything fits in
17155 2 bytes. */
17156
c19d1205 17157int
0110f2b8 17158md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
17159 segT segtype ATTRIBUTE_UNUSED)
17160{
0110f2b8
PB
17161 fragp->fr_var = 2;
17162 return 2;
17163}
17164
17165/* Convert a machine dependent frag. */
17166
17167void
17168md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17169{
17170 unsigned long insn;
17171 unsigned long old_op;
17172 char *buf;
17173 expressionS exp;
17174 fixS *fixp;
17175 int reloc_type;
17176 int pc_rel;
17177 int opcode;
17178
17179 buf = fragp->fr_literal + fragp->fr_fix;
17180
17181 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
17182 if (fragp->fr_symbol)
17183 {
0110f2b8
PB
17184 exp.X_op = O_symbol;
17185 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
17186 }
17187 else
17188 {
0110f2b8 17189 exp.X_op = O_constant;
5f4273c7 17190 }
0110f2b8
PB
17191 exp.X_add_number = fragp->fr_offset;
17192 opcode = fragp->fr_subtype;
17193 switch (opcode)
17194 {
17195 case T_MNEM_ldr_pc:
17196 case T_MNEM_ldr_pc2:
17197 case T_MNEM_ldr_sp:
17198 case T_MNEM_str_sp:
17199 case T_MNEM_ldr:
17200 case T_MNEM_ldrb:
17201 case T_MNEM_ldrh:
17202 case T_MNEM_str:
17203 case T_MNEM_strb:
17204 case T_MNEM_strh:
17205 if (fragp->fr_var == 4)
17206 {
5f4273c7 17207 insn = THUMB_OP32 (opcode);
0110f2b8
PB
17208 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17209 {
17210 insn |= (old_op & 0x700) << 4;
17211 }
17212 else
17213 {
17214 insn |= (old_op & 7) << 12;
17215 insn |= (old_op & 0x38) << 13;
17216 }
17217 insn |= 0x00000c00;
17218 put_thumb32_insn (buf, insn);
17219 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17220 }
17221 else
17222 {
17223 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17224 }
17225 pc_rel = (opcode == T_MNEM_ldr_pc2);
17226 break;
17227 case T_MNEM_adr:
17228 if (fragp->fr_var == 4)
17229 {
17230 insn = THUMB_OP32 (opcode);
17231 insn |= (old_op & 0xf0) << 4;
17232 put_thumb32_insn (buf, insn);
17233 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17234 }
17235 else
17236 {
17237 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17238 exp.X_add_number -= 4;
17239 }
17240 pc_rel = 1;
17241 break;
17242 case T_MNEM_mov:
17243 case T_MNEM_movs:
17244 case T_MNEM_cmp:
17245 case T_MNEM_cmn:
17246 if (fragp->fr_var == 4)
17247 {
17248 int r0off = (opcode == T_MNEM_mov
17249 || opcode == T_MNEM_movs) ? 0 : 8;
17250 insn = THUMB_OP32 (opcode);
17251 insn = (insn & 0xe1ffffff) | 0x10000000;
17252 insn |= (old_op & 0x700) << r0off;
17253 put_thumb32_insn (buf, insn);
17254 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17255 }
17256 else
17257 {
17258 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17259 }
17260 pc_rel = 0;
17261 break;
17262 case T_MNEM_b:
17263 if (fragp->fr_var == 4)
17264 {
17265 insn = THUMB_OP32(opcode);
17266 put_thumb32_insn (buf, insn);
17267 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17268 }
17269 else
17270 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17271 pc_rel = 1;
17272 break;
17273 case T_MNEM_bcond:
17274 if (fragp->fr_var == 4)
17275 {
17276 insn = THUMB_OP32(opcode);
17277 insn |= (old_op & 0xf00) << 14;
17278 put_thumb32_insn (buf, insn);
17279 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17280 }
17281 else
17282 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17283 pc_rel = 1;
17284 break;
17285 case T_MNEM_add_sp:
17286 case T_MNEM_add_pc:
17287 case T_MNEM_inc_sp:
17288 case T_MNEM_dec_sp:
17289 if (fragp->fr_var == 4)
17290 {
17291 /* ??? Choose between add and addw. */
17292 insn = THUMB_OP32 (opcode);
17293 insn |= (old_op & 0xf0) << 4;
17294 put_thumb32_insn (buf, insn);
16805f35
PB
17295 if (opcode == T_MNEM_add_pc)
17296 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17297 else
17298 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
17299 }
17300 else
17301 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17302 pc_rel = 0;
17303 break;
17304
17305 case T_MNEM_addi:
17306 case T_MNEM_addis:
17307 case T_MNEM_subi:
17308 case T_MNEM_subis:
17309 if (fragp->fr_var == 4)
17310 {
17311 insn = THUMB_OP32 (opcode);
17312 insn |= (old_op & 0xf0) << 4;
17313 insn |= (old_op & 0xf) << 16;
17314 put_thumb32_insn (buf, insn);
16805f35
PB
17315 if (insn & (1 << 20))
17316 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17317 else
17318 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
17319 }
17320 else
17321 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17322 pc_rel = 0;
17323 break;
17324 default:
5f4273c7 17325 abort ();
0110f2b8
PB
17326 }
17327 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17328 reloc_type);
17329 fixp->fx_file = fragp->fr_file;
17330 fixp->fx_line = fragp->fr_line;
17331 fragp->fr_fix += fragp->fr_var;
17332}
17333
17334/* Return the size of a relaxable immediate operand instruction.
17335 SHIFT and SIZE specify the form of the allowable immediate. */
17336static int
17337relax_immediate (fragS *fragp, int size, int shift)
17338{
17339 offsetT offset;
17340 offsetT mask;
17341 offsetT low;
17342
17343 /* ??? Should be able to do better than this. */
17344 if (fragp->fr_symbol)
17345 return 4;
17346
17347 low = (1 << shift) - 1;
17348 mask = (1 << (shift + size)) - (1 << shift);
17349 offset = fragp->fr_offset;
17350 /* Force misaligned offsets to 32-bit variant. */
17351 if (offset & low)
5e77afaa 17352 return 4;
0110f2b8
PB
17353 if (offset & ~mask)
17354 return 4;
17355 return 2;
17356}
17357
5e77afaa
PB
17358/* Get the address of a symbol during relaxation. */
17359static addressT
5f4273c7 17360relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
17361{
17362 fragS *sym_frag;
17363 addressT addr;
17364 symbolS *sym;
17365
17366 sym = fragp->fr_symbol;
17367 sym_frag = symbol_get_frag (sym);
17368 know (S_GET_SEGMENT (sym) != absolute_section
17369 || sym_frag == &zero_address_frag);
17370 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17371
17372 /* If frag has yet to be reached on this pass, assume it will
17373 move by STRETCH just as we did. If this is not so, it will
17374 be because some frag between grows, and that will force
17375 another pass. */
17376
17377 if (stretch != 0
17378 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
17379 {
17380 fragS *f;
17381
17382 /* Adjust stretch for any alignment frag. Note that if have
17383 been expanding the earlier code, the symbol may be
17384 defined in what appears to be an earlier frag. FIXME:
17385 This doesn't handle the fr_subtype field, which specifies
17386 a maximum number of bytes to skip when doing an
17387 alignment. */
17388 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17389 {
17390 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17391 {
17392 if (stretch < 0)
17393 stretch = - ((- stretch)
17394 & ~ ((1 << (int) f->fr_offset) - 1));
17395 else
17396 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17397 if (stretch == 0)
17398 break;
17399 }
17400 }
17401 if (f != NULL)
17402 addr += stretch;
17403 }
5e77afaa
PB
17404
17405 return addr;
17406}
17407
0110f2b8
PB
17408/* Return the size of a relaxable adr pseudo-instruction or PC-relative
17409 load. */
17410static int
5e77afaa 17411relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
17412{
17413 addressT addr;
17414 offsetT val;
17415
17416 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17417 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17418 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17419 return 4;
17420
5f4273c7 17421 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17422 addr = fragp->fr_address + fragp->fr_fix;
17423 addr = (addr + 4) & ~3;
5e77afaa 17424 /* Force misaligned targets to 32-bit variant. */
0110f2b8 17425 if (val & 3)
5e77afaa 17426 return 4;
0110f2b8
PB
17427 val -= addr;
17428 if (val < 0 || val > 1020)
17429 return 4;
17430 return 2;
17431}
17432
17433/* Return the size of a relaxable add/sub immediate instruction. */
17434static int
17435relax_addsub (fragS *fragp, asection *sec)
17436{
17437 char *buf;
17438 int op;
17439
17440 buf = fragp->fr_literal + fragp->fr_fix;
17441 op = bfd_get_16(sec->owner, buf);
17442 if ((op & 0xf) == ((op >> 4) & 0xf))
17443 return relax_immediate (fragp, 8, 0);
17444 else
17445 return relax_immediate (fragp, 3, 0);
17446}
17447
17448
17449/* Return the size of a relaxable branch instruction. BITS is the
17450 size of the offset field in the narrow instruction. */
17451
17452static int
5e77afaa 17453relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
17454{
17455 addressT addr;
17456 offsetT val;
17457 offsetT limit;
17458
17459 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17460 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17461 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17462 return 4;
17463
5f4273c7 17464 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17465 addr = fragp->fr_address + fragp->fr_fix + 4;
17466 val -= addr;
17467
17468 /* Offset is a signed value *2 */
17469 limit = 1 << bits;
17470 if (val >= limit || val < -limit)
17471 return 4;
17472 return 2;
17473}
17474
17475
17476/* Relax a machine dependent frag. This returns the amount by which
17477 the current size of the frag should change. */
17478
17479int
5e77afaa 17480arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
17481{
17482 int oldsize;
17483 int newsize;
17484
17485 oldsize = fragp->fr_var;
17486 switch (fragp->fr_subtype)
17487 {
17488 case T_MNEM_ldr_pc2:
5f4273c7 17489 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17490 break;
17491 case T_MNEM_ldr_pc:
17492 case T_MNEM_ldr_sp:
17493 case T_MNEM_str_sp:
5f4273c7 17494 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
17495 break;
17496 case T_MNEM_ldr:
17497 case T_MNEM_str:
5f4273c7 17498 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
17499 break;
17500 case T_MNEM_ldrh:
17501 case T_MNEM_strh:
5f4273c7 17502 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
17503 break;
17504 case T_MNEM_ldrb:
17505 case T_MNEM_strb:
5f4273c7 17506 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
17507 break;
17508 case T_MNEM_adr:
5f4273c7 17509 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17510 break;
17511 case T_MNEM_mov:
17512 case T_MNEM_movs:
17513 case T_MNEM_cmp:
17514 case T_MNEM_cmn:
5f4273c7 17515 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
17516 break;
17517 case T_MNEM_b:
5f4273c7 17518 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
17519 break;
17520 case T_MNEM_bcond:
5f4273c7 17521 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
17522 break;
17523 case T_MNEM_add_sp:
17524 case T_MNEM_add_pc:
17525 newsize = relax_immediate (fragp, 8, 2);
17526 break;
17527 case T_MNEM_inc_sp:
17528 case T_MNEM_dec_sp:
17529 newsize = relax_immediate (fragp, 7, 2);
17530 break;
17531 case T_MNEM_addi:
17532 case T_MNEM_addis:
17533 case T_MNEM_subi:
17534 case T_MNEM_subis:
17535 newsize = relax_addsub (fragp, sec);
17536 break;
17537 default:
5f4273c7 17538 abort ();
0110f2b8 17539 }
5e77afaa
PB
17540
17541 fragp->fr_var = newsize;
17542 /* Freeze wide instructions that are at or before the same location as
17543 in the previous pass. This avoids infinite loops.
5f4273c7
NC
17544 Don't freeze them unconditionally because targets may be artificially
17545 misaligned by the expansion of preceding frags. */
5e77afaa 17546 if (stretch <= 0 && newsize > 2)
0110f2b8 17547 {
0110f2b8 17548 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 17549 frag_wane (fragp);
0110f2b8 17550 }
5e77afaa 17551
0110f2b8 17552 return newsize - oldsize;
c19d1205 17553}
b99bd4ef 17554
c19d1205 17555/* Round up a section size to the appropriate boundary. */
b99bd4ef 17556
c19d1205
ZW
17557valueT
17558md_section_align (segT segment ATTRIBUTE_UNUSED,
17559 valueT size)
17560{
f0927246
NC
17561#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17562 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17563 {
17564 /* For a.out, force the section size to be aligned. If we don't do
17565 this, BFD will align it for us, but it will not write out the
17566 final bytes of the section. This may be a bug in BFD, but it is
17567 easier to fix it here since that is how the other a.out targets
17568 work. */
17569 int align;
17570
17571 align = bfd_get_section_alignment (stdoutput, segment);
17572 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17573 }
c19d1205 17574#endif
f0927246
NC
17575
17576 return size;
bfae80f2 17577}
b99bd4ef 17578
c19d1205
ZW
17579/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17580 of an rs_align_code fragment. */
17581
17582void
17583arm_handle_align (fragS * fragP)
bfae80f2 17584{
e7495e45
NS
17585 static char const arm_noop[2][2][4] =
17586 {
17587 { /* ARMv1 */
17588 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
17589 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
17590 },
17591 { /* ARMv6k */
17592 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
17593 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
17594 },
17595 };
17596 static char const thumb_noop[2][2][2] =
17597 {
17598 { /* Thumb-1 */
17599 {0xc0, 0x46}, /* LE */
17600 {0x46, 0xc0}, /* BE */
17601 },
17602 { /* Thumb-2 */
17603 {0x00, 0xbf}, /* LE */
17604 {0xbf, 0x00} /* BE */
17605 }
17606 };
17607 static char const wide_thumb_noop[2][4] =
17608 { /* Wide Thumb-2 */
17609 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
17610 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
17611 };
17612
17613 unsigned bytes, fix, noop_size;
c19d1205
ZW
17614 char * p;
17615 const char * noop;
e7495e45 17616 const char *narrow_noop = NULL;
bfae80f2 17617
c19d1205 17618 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17619 return;
17620
c19d1205
ZW
17621 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17622 p = fragP->fr_literal + fragP->fr_fix;
17623 fix = 0;
bfae80f2 17624
c19d1205
ZW
17625 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17626 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17627
8dc2430f
NC
17628 assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
17629
17630 if (fragP->tc_frag_data & (~ MODE_RECORDED))
a737bd4d 17631 {
e7495e45
NS
17632 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
17633 {
17634 narrow_noop = thumb_noop[1][target_big_endian];
17635 noop = wide_thumb_noop[target_big_endian];
17636 }
c19d1205 17637 else
e7495e45
NS
17638 noop = thumb_noop[0][target_big_endian];
17639 noop_size = 2;
7ed4c4c5
NC
17640 }
17641 else
17642 {
e7495e45
NS
17643 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
17644 [target_big_endian];
17645 noop_size = 4;
7ed4c4c5 17646 }
e7495e45
NS
17647
17648 fragP->fr_var = noop_size;
17649
c19d1205 17650 if (bytes & (noop_size - 1))
7ed4c4c5 17651 {
c19d1205
ZW
17652 fix = bytes & (noop_size - 1);
17653 memset (p, 0, fix);
17654 p += fix;
17655 bytes -= fix;
a737bd4d 17656 }
a737bd4d 17657
e7495e45
NS
17658 if (narrow_noop)
17659 {
17660 if (bytes & noop_size)
17661 {
17662 /* Insert a narrow noop. */
17663 memcpy (p, narrow_noop, noop_size);
17664 p += noop_size;
17665 bytes -= noop_size;
17666 fix += noop_size;
17667 }
17668
17669 /* Use wide noops for the remainder */
17670 noop_size = 4;
17671 }
17672
c19d1205 17673 while (bytes >= noop_size)
a737bd4d 17674 {
c19d1205
ZW
17675 memcpy (p, noop, noop_size);
17676 p += noop_size;
17677 bytes -= noop_size;
17678 fix += noop_size;
a737bd4d
NC
17679 }
17680
c19d1205 17681 fragP->fr_fix += fix;
a737bd4d
NC
17682}
17683
c19d1205
ZW
17684/* Called from md_do_align. Used to create an alignment
17685 frag in a code section. */
17686
17687void
17688arm_frag_align_code (int n, int max)
bfae80f2 17689{
c19d1205 17690 char * p;
7ed4c4c5 17691
c19d1205
ZW
17692 /* We assume that there will never be a requirement
17693 to support alignments greater than 32 bytes. */
17694 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17695 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17696
c19d1205
ZW
17697 p = frag_var (rs_align_code,
17698 MAX_MEM_FOR_RS_ALIGN_CODE,
17699 1,
17700 (relax_substateT) max,
17701 (symbolS *) NULL,
17702 (offsetT) n,
17703 (char *) NULL);
17704 *p = 0;
17705}
bfae80f2 17706
8dc2430f
NC
17707/* Perform target specific initialisation of a frag.
17708 Note - despite the name this initialisation is not done when the frag
17709 is created, but only when its type is assigned. A frag can be created
17710 and used a long time before its type is set, so beware of assuming that
17711 this initialisationis performed first. */
bfae80f2 17712
c19d1205
ZW
17713void
17714arm_init_frag (fragS * fragP)
17715{
8dc2430f
NC
17716 /* If the current ARM vs THUMB mode has not already
17717 been recorded into this frag then do so now. */
17718 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
17719 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
bfae80f2
RE
17720}
17721
c19d1205
ZW
17722#ifdef OBJ_ELF
17723/* When we change sections we need to issue a new mapping symbol. */
17724
17725void
17726arm_elf_change_section (void)
bfae80f2 17727{
c19d1205
ZW
17728 flagword flags;
17729 segment_info_type *seginfo;
bfae80f2 17730
c19d1205
ZW
17731 /* Link an unlinked unwind index table section to the .text section. */
17732 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17733 && elf_linked_to_section (now_seg) == NULL)
17734 elf_linked_to_section (now_seg) = text_section;
17735
17736 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17737 return;
17738
c19d1205
ZW
17739 flags = bfd_get_section_flags (stdoutput, now_seg);
17740
17741 /* We can ignore sections that only contain debug info. */
17742 if ((flags & SEC_ALLOC) == 0)
17743 return;
bfae80f2 17744
c19d1205
ZW
17745 seginfo = seg_info (now_seg);
17746 mapstate = seginfo->tc_segment_info_data.mapstate;
17747 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17748}
17749
c19d1205
ZW
17750int
17751arm_elf_section_type (const char * str, size_t len)
e45d0630 17752{
c19d1205
ZW
17753 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17754 return SHT_ARM_EXIDX;
e45d0630 17755
c19d1205
ZW
17756 return -1;
17757}
17758\f
17759/* Code to deal with unwinding tables. */
e45d0630 17760
c19d1205 17761static void add_unwind_adjustsp (offsetT);
e45d0630 17762
5f4273c7 17763/* Generate any deferred unwind frame offset. */
e45d0630 17764
bfae80f2 17765static void
c19d1205 17766flush_pending_unwind (void)
bfae80f2 17767{
c19d1205 17768 offsetT offset;
bfae80f2 17769
c19d1205
ZW
17770 offset = unwind.pending_offset;
17771 unwind.pending_offset = 0;
17772 if (offset != 0)
17773 add_unwind_adjustsp (offset);
bfae80f2
RE
17774}
17775
c19d1205
ZW
17776/* Add an opcode to this list for this function. Two-byte opcodes should
17777 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17778 order. */
17779
bfae80f2 17780static void
c19d1205 17781add_unwind_opcode (valueT op, int length)
bfae80f2 17782{
c19d1205
ZW
17783 /* Add any deferred stack adjustment. */
17784 if (unwind.pending_offset)
17785 flush_pending_unwind ();
bfae80f2 17786
c19d1205 17787 unwind.sp_restored = 0;
bfae80f2 17788
c19d1205 17789 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17790 {
c19d1205
ZW
17791 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17792 if (unwind.opcodes)
17793 unwind.opcodes = xrealloc (unwind.opcodes,
17794 unwind.opcode_alloc);
17795 else
17796 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17797 }
c19d1205 17798 while (length > 0)
bfae80f2 17799 {
c19d1205
ZW
17800 length--;
17801 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17802 op >>= 8;
17803 unwind.opcode_count++;
bfae80f2 17804 }
bfae80f2
RE
17805}
17806
c19d1205
ZW
17807/* Add unwind opcodes to adjust the stack pointer. */
17808
bfae80f2 17809static void
c19d1205 17810add_unwind_adjustsp (offsetT offset)
bfae80f2 17811{
c19d1205 17812 valueT op;
bfae80f2 17813
c19d1205 17814 if (offset > 0x200)
bfae80f2 17815 {
c19d1205
ZW
17816 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17817 char bytes[5];
17818 int n;
17819 valueT o;
bfae80f2 17820
c19d1205
ZW
17821 /* Long form: 0xb2, uleb128. */
17822 /* This might not fit in a word so add the individual bytes,
17823 remembering the list is built in reverse order. */
17824 o = (valueT) ((offset - 0x204) >> 2);
17825 if (o == 0)
17826 add_unwind_opcode (0, 1);
bfae80f2 17827
c19d1205
ZW
17828 /* Calculate the uleb128 encoding of the offset. */
17829 n = 0;
17830 while (o)
17831 {
17832 bytes[n] = o & 0x7f;
17833 o >>= 7;
17834 if (o)
17835 bytes[n] |= 0x80;
17836 n++;
17837 }
17838 /* Add the insn. */
17839 for (; n; n--)
17840 add_unwind_opcode (bytes[n - 1], 1);
17841 add_unwind_opcode (0xb2, 1);
17842 }
17843 else if (offset > 0x100)
bfae80f2 17844 {
c19d1205
ZW
17845 /* Two short opcodes. */
17846 add_unwind_opcode (0x3f, 1);
17847 op = (offset - 0x104) >> 2;
17848 add_unwind_opcode (op, 1);
bfae80f2 17849 }
c19d1205
ZW
17850 else if (offset > 0)
17851 {
17852 /* Short opcode. */
17853 op = (offset - 4) >> 2;
17854 add_unwind_opcode (op, 1);
17855 }
17856 else if (offset < 0)
bfae80f2 17857 {
c19d1205
ZW
17858 offset = -offset;
17859 while (offset > 0x100)
bfae80f2 17860 {
c19d1205
ZW
17861 add_unwind_opcode (0x7f, 1);
17862 offset -= 0x100;
bfae80f2 17863 }
c19d1205
ZW
17864 op = ((offset - 4) >> 2) | 0x40;
17865 add_unwind_opcode (op, 1);
bfae80f2 17866 }
bfae80f2
RE
17867}
17868
c19d1205
ZW
17869/* Finish the list of unwind opcodes for this function. */
17870static void
17871finish_unwind_opcodes (void)
bfae80f2 17872{
c19d1205 17873 valueT op;
bfae80f2 17874
c19d1205 17875 if (unwind.fp_used)
bfae80f2 17876 {
708587a4 17877 /* Adjust sp as necessary. */
c19d1205
ZW
17878 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17879 flush_pending_unwind ();
bfae80f2 17880
c19d1205
ZW
17881 /* After restoring sp from the frame pointer. */
17882 op = 0x90 | unwind.fp_reg;
17883 add_unwind_opcode (op, 1);
17884 }
17885 else
17886 flush_pending_unwind ();
bfae80f2
RE
17887}
17888
bfae80f2 17889
c19d1205
ZW
17890/* Start an exception table entry. If idx is nonzero this is an index table
17891 entry. */
bfae80f2
RE
17892
17893static void
c19d1205 17894start_unwind_section (const segT text_seg, int idx)
bfae80f2 17895{
c19d1205
ZW
17896 const char * text_name;
17897 const char * prefix;
17898 const char * prefix_once;
17899 const char * group_name;
17900 size_t prefix_len;
17901 size_t text_len;
17902 char * sec_name;
17903 size_t sec_name_len;
17904 int type;
17905 int flags;
17906 int linkonce;
bfae80f2 17907
c19d1205 17908 if (idx)
bfae80f2 17909 {
c19d1205
ZW
17910 prefix = ELF_STRING_ARM_unwind;
17911 prefix_once = ELF_STRING_ARM_unwind_once;
17912 type = SHT_ARM_EXIDX;
bfae80f2 17913 }
c19d1205 17914 else
bfae80f2 17915 {
c19d1205
ZW
17916 prefix = ELF_STRING_ARM_unwind_info;
17917 prefix_once = ELF_STRING_ARM_unwind_info_once;
17918 type = SHT_PROGBITS;
bfae80f2
RE
17919 }
17920
c19d1205
ZW
17921 text_name = segment_name (text_seg);
17922 if (streq (text_name, ".text"))
17923 text_name = "";
17924
17925 if (strncmp (text_name, ".gnu.linkonce.t.",
17926 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17927 {
c19d1205
ZW
17928 prefix = prefix_once;
17929 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17930 }
17931
c19d1205
ZW
17932 prefix_len = strlen (prefix);
17933 text_len = strlen (text_name);
17934 sec_name_len = prefix_len + text_len;
17935 sec_name = xmalloc (sec_name_len + 1);
17936 memcpy (sec_name, prefix, prefix_len);
17937 memcpy (sec_name + prefix_len, text_name, text_len);
17938 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17939
c19d1205
ZW
17940 flags = SHF_ALLOC;
17941 linkonce = 0;
17942 group_name = 0;
bfae80f2 17943
c19d1205
ZW
17944 /* Handle COMDAT group. */
17945 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17946 {
c19d1205
ZW
17947 group_name = elf_group_name (text_seg);
17948 if (group_name == NULL)
17949 {
bd3ba5d1 17950 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17951 segment_name (text_seg));
17952 ignore_rest_of_line ();
17953 return;
17954 }
17955 flags |= SHF_GROUP;
17956 linkonce = 1;
bfae80f2
RE
17957 }
17958
c19d1205 17959 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17960
5f4273c7 17961 /* Set the section link for index tables. */
c19d1205
ZW
17962 if (idx)
17963 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17964}
17965
bfae80f2 17966
c19d1205
ZW
17967/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17968 personality routine data. Returns zero, or the index table value for
17969 and inline entry. */
17970
17971static valueT
17972create_unwind_entry (int have_data)
bfae80f2 17973{
c19d1205
ZW
17974 int size;
17975 addressT where;
17976 char *ptr;
17977 /* The current word of data. */
17978 valueT data;
17979 /* The number of bytes left in this word. */
17980 int n;
bfae80f2 17981
c19d1205 17982 finish_unwind_opcodes ();
bfae80f2 17983
c19d1205
ZW
17984 /* Remember the current text section. */
17985 unwind.saved_seg = now_seg;
17986 unwind.saved_subseg = now_subseg;
bfae80f2 17987
c19d1205 17988 start_unwind_section (now_seg, 0);
bfae80f2 17989
c19d1205 17990 if (unwind.personality_routine == NULL)
bfae80f2 17991 {
c19d1205
ZW
17992 if (unwind.personality_index == -2)
17993 {
17994 if (have_data)
5f4273c7 17995 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17996 return 1; /* EXIDX_CANTUNWIND. */
17997 }
bfae80f2 17998
c19d1205
ZW
17999 /* Use a default personality routine if none is specified. */
18000 if (unwind.personality_index == -1)
18001 {
18002 if (unwind.opcode_count > 3)
18003 unwind.personality_index = 1;
18004 else
18005 unwind.personality_index = 0;
18006 }
bfae80f2 18007
c19d1205
ZW
18008 /* Space for the personality routine entry. */
18009 if (unwind.personality_index == 0)
18010 {
18011 if (unwind.opcode_count > 3)
18012 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 18013
c19d1205
ZW
18014 if (!have_data)
18015 {
18016 /* All the data is inline in the index table. */
18017 data = 0x80;
18018 n = 3;
18019 while (unwind.opcode_count > 0)
18020 {
18021 unwind.opcode_count--;
18022 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18023 n--;
18024 }
bfae80f2 18025
c19d1205
ZW
18026 /* Pad with "finish" opcodes. */
18027 while (n--)
18028 data = (data << 8) | 0xb0;
bfae80f2 18029
c19d1205
ZW
18030 return data;
18031 }
18032 size = 0;
18033 }
18034 else
18035 /* We get two opcodes "free" in the first word. */
18036 size = unwind.opcode_count - 2;
18037 }
18038 else
18039 /* An extra byte is required for the opcode count. */
18040 size = unwind.opcode_count + 1;
bfae80f2 18041
c19d1205
ZW
18042 size = (size + 3) >> 2;
18043 if (size > 0xff)
18044 as_bad (_("too many unwind opcodes"));
bfae80f2 18045
c19d1205
ZW
18046 frag_align (2, 0, 0);
18047 record_alignment (now_seg, 2);
18048 unwind.table_entry = expr_build_dot ();
18049
18050 /* Allocate the table entry. */
18051 ptr = frag_more ((size << 2) + 4);
18052 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 18053
c19d1205 18054 switch (unwind.personality_index)
bfae80f2 18055 {
c19d1205
ZW
18056 case -1:
18057 /* ??? Should this be a PLT generating relocation? */
18058 /* Custom personality routine. */
18059 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18060 BFD_RELOC_ARM_PREL31);
bfae80f2 18061
c19d1205
ZW
18062 where += 4;
18063 ptr += 4;
bfae80f2 18064
c19d1205
ZW
18065 /* Set the first byte to the number of additional words. */
18066 data = size - 1;
18067 n = 3;
18068 break;
bfae80f2 18069
c19d1205
ZW
18070 /* ABI defined personality routines. */
18071 case 0:
18072 /* Three opcodes bytes are packed into the first word. */
18073 data = 0x80;
18074 n = 3;
18075 break;
bfae80f2 18076
c19d1205
ZW
18077 case 1:
18078 case 2:
18079 /* The size and first two opcode bytes go in the first word. */
18080 data = ((0x80 + unwind.personality_index) << 8) | size;
18081 n = 2;
18082 break;
bfae80f2 18083
c19d1205
ZW
18084 default:
18085 /* Should never happen. */
18086 abort ();
18087 }
bfae80f2 18088
c19d1205
ZW
18089 /* Pack the opcodes into words (MSB first), reversing the list at the same
18090 time. */
18091 while (unwind.opcode_count > 0)
18092 {
18093 if (n == 0)
18094 {
18095 md_number_to_chars (ptr, data, 4);
18096 ptr += 4;
18097 n = 4;
18098 data = 0;
18099 }
18100 unwind.opcode_count--;
18101 n--;
18102 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18103 }
18104
18105 /* Finish off the last word. */
18106 if (n < 4)
18107 {
18108 /* Pad with "finish" opcodes. */
18109 while (n--)
18110 data = (data << 8) | 0xb0;
18111
18112 md_number_to_chars (ptr, data, 4);
18113 }
18114
18115 if (!have_data)
18116 {
18117 /* Add an empty descriptor if there is no user-specified data. */
18118 ptr = frag_more (4);
18119 md_number_to_chars (ptr, 0, 4);
18120 }
18121
18122 return 0;
bfae80f2
RE
18123}
18124
f0927246
NC
18125
18126/* Initialize the DWARF-2 unwind information for this procedure. */
18127
18128void
18129tc_arm_frame_initial_instructions (void)
18130{
18131 cfi_add_CFA_def_cfa (REG_SP, 0);
18132}
18133#endif /* OBJ_ELF */
18134
c19d1205
ZW
18135/* Convert REGNAME to a DWARF-2 register number. */
18136
18137int
1df69f4f 18138tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 18139{
1df69f4f 18140 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
18141
18142 if (reg == FAIL)
18143 return -1;
18144
18145 return reg;
bfae80f2
RE
18146}
18147
f0927246 18148#ifdef TE_PE
c19d1205 18149void
f0927246 18150tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 18151{
f0927246 18152 expressionS expr;
bfae80f2 18153
f0927246
NC
18154 expr.X_op = O_secrel;
18155 expr.X_add_symbol = symbol;
18156 expr.X_add_number = 0;
18157 emit_expr (&expr, size);
18158}
18159#endif
bfae80f2 18160
c19d1205 18161/* MD interface: Symbol and relocation handling. */
bfae80f2 18162
2fc8bdac
ZW
18163/* Return the address within the segment that a PC-relative fixup is
18164 relative to. For ARM, PC-relative fixups applied to instructions
18165 are generally relative to the location of the fixup plus 8 bytes.
18166 Thumb branches are offset by 4, and Thumb loads relative to PC
18167 require special handling. */
bfae80f2 18168
c19d1205 18169long
2fc8bdac 18170md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 18171{
2fc8bdac
ZW
18172 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18173
18174 /* If this is pc-relative and we are going to emit a relocation
18175 then we just want to put out any pipeline compensation that the linker
53baae48
NC
18176 will need. Otherwise we want to use the calculated base.
18177 For WinCE we skip the bias for externals as well, since this
18178 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 18179 if (fixP->fx_pcrel
2fc8bdac 18180 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
18181 || (arm_force_relocation (fixP)
18182#ifdef TE_WINCE
18183 && !S_IS_EXTERNAL (fixP->fx_addsy)
18184#endif
18185 )))
2fc8bdac 18186 base = 0;
bfae80f2 18187
c19d1205 18188 switch (fixP->fx_r_type)
bfae80f2 18189 {
2fc8bdac
ZW
18190 /* PC relative addressing on the Thumb is slightly odd as the
18191 bottom two bits of the PC are forced to zero for the
18192 calculation. This happens *after* application of the
18193 pipeline offset. However, Thumb adrl already adjusts for
18194 this, so we need not do it again. */
c19d1205 18195 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 18196 return base & ~3;
c19d1205
ZW
18197
18198 case BFD_RELOC_ARM_THUMB_OFFSET:
18199 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 18200 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 18201 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 18202 return (base + 4) & ~3;
c19d1205 18203
2fc8bdac
ZW
18204 /* Thumb branches are simply offset by +4. */
18205 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18206 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18207 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18208 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18209 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18210 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 18211 return base + 4;
bfae80f2 18212
00adf2d4
JB
18213 /* BLX is like branches above, but forces the low two bits of PC to
18214 zero. */
18215 case BFD_RELOC_THUMB_PCREL_BLX:
18216 return (base + 4) & ~3;
18217
2fc8bdac
ZW
18218 /* ARM mode branches are offset by +8. However, the Windows CE
18219 loader expects the relocation not to take this into account. */
18220 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
18221 case BFD_RELOC_ARM_PCREL_CALL:
18222 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
18223 case BFD_RELOC_ARM_PCREL_BLX:
18224 case BFD_RELOC_ARM_PLT32:
c19d1205 18225#ifdef TE_WINCE
5f4273c7 18226 /* When handling fixups immediately, because we have already
53baae48
NC
18227 discovered the value of a symbol, or the address of the frag involved
18228 we must account for the offset by +8, as the OS loader will never see the reloc.
18229 see fixup_segment() in write.c
18230 The S_IS_EXTERNAL test handles the case of global symbols.
18231 Those need the calculated base, not just the pipe compensation the linker will need. */
18232 if (fixP->fx_pcrel
18233 && fixP->fx_addsy != NULL
18234 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18235 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18236 return base + 8;
2fc8bdac 18237 return base;
c19d1205 18238#else
2fc8bdac 18239 return base + 8;
c19d1205 18240#endif
2fc8bdac
ZW
18241
18242 /* ARM mode loads relative to PC are also offset by +8. Unlike
18243 branches, the Windows CE loader *does* expect the relocation
18244 to take this into account. */
18245 case BFD_RELOC_ARM_OFFSET_IMM:
18246 case BFD_RELOC_ARM_OFFSET_IMM8:
18247 case BFD_RELOC_ARM_HWLITERAL:
18248 case BFD_RELOC_ARM_LITERAL:
18249 case BFD_RELOC_ARM_CP_OFF_IMM:
18250 return base + 8;
18251
18252
18253 /* Other PC-relative relocations are un-offset. */
18254 default:
18255 return base;
18256 }
bfae80f2
RE
18257}
18258
c19d1205
ZW
18259/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18260 Otherwise we have no need to default values of symbols. */
18261
18262symbolS *
18263md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 18264{
c19d1205
ZW
18265#ifdef OBJ_ELF
18266 if (name[0] == '_' && name[1] == 'G'
18267 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18268 {
18269 if (!GOT_symbol)
18270 {
18271 if (symbol_find (name))
bd3ba5d1 18272 as_bad (_("GOT already in the symbol table"));
bfae80f2 18273
c19d1205
ZW
18274 GOT_symbol = symbol_new (name, undefined_section,
18275 (valueT) 0, & zero_address_frag);
18276 }
bfae80f2 18277
c19d1205 18278 return GOT_symbol;
bfae80f2 18279 }
c19d1205 18280#endif
bfae80f2 18281
c19d1205 18282 return 0;
bfae80f2
RE
18283}
18284
55cf6793 18285/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
18286 computed as two separate immediate values, added together. We
18287 already know that this value cannot be computed by just one ARM
18288 instruction. */
18289
18290static unsigned int
18291validate_immediate_twopart (unsigned int val,
18292 unsigned int * highpart)
bfae80f2 18293{
c19d1205
ZW
18294 unsigned int a;
18295 unsigned int i;
bfae80f2 18296
c19d1205
ZW
18297 for (i = 0; i < 32; i += 2)
18298 if (((a = rotate_left (val, i)) & 0xff) != 0)
18299 {
18300 if (a & 0xff00)
18301 {
18302 if (a & ~ 0xffff)
18303 continue;
18304 * highpart = (a >> 8) | ((i + 24) << 7);
18305 }
18306 else if (a & 0xff0000)
18307 {
18308 if (a & 0xff000000)
18309 continue;
18310 * highpart = (a >> 16) | ((i + 16) << 7);
18311 }
18312 else
18313 {
18314 assert (a & 0xff000000);
18315 * highpart = (a >> 24) | ((i + 8) << 7);
18316 }
bfae80f2 18317
c19d1205
ZW
18318 return (a & 0xff) | (i << 7);
18319 }
bfae80f2 18320
c19d1205 18321 return FAIL;
bfae80f2
RE
18322}
18323
c19d1205
ZW
18324static int
18325validate_offset_imm (unsigned int val, int hwse)
18326{
18327 if ((hwse && val > 255) || val > 4095)
18328 return FAIL;
18329 return val;
18330}
bfae80f2 18331
55cf6793 18332/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
18333 negative immediate constant by altering the instruction. A bit of
18334 a hack really.
18335 MOV <-> MVN
18336 AND <-> BIC
18337 ADC <-> SBC
18338 by inverting the second operand, and
18339 ADD <-> SUB
18340 CMP <-> CMN
18341 by negating the second operand. */
bfae80f2 18342
c19d1205
ZW
18343static int
18344negate_data_op (unsigned long * instruction,
18345 unsigned long value)
bfae80f2 18346{
c19d1205
ZW
18347 int op, new_inst;
18348 unsigned long negated, inverted;
bfae80f2 18349
c19d1205
ZW
18350 negated = encode_arm_immediate (-value);
18351 inverted = encode_arm_immediate (~value);
bfae80f2 18352
c19d1205
ZW
18353 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18354 switch (op)
bfae80f2 18355 {
c19d1205
ZW
18356 /* First negates. */
18357 case OPCODE_SUB: /* ADD <-> SUB */
18358 new_inst = OPCODE_ADD;
18359 value = negated;
18360 break;
bfae80f2 18361
c19d1205
ZW
18362 case OPCODE_ADD:
18363 new_inst = OPCODE_SUB;
18364 value = negated;
18365 break;
bfae80f2 18366
c19d1205
ZW
18367 case OPCODE_CMP: /* CMP <-> CMN */
18368 new_inst = OPCODE_CMN;
18369 value = negated;
18370 break;
bfae80f2 18371
c19d1205
ZW
18372 case OPCODE_CMN:
18373 new_inst = OPCODE_CMP;
18374 value = negated;
18375 break;
bfae80f2 18376
c19d1205
ZW
18377 /* Now Inverted ops. */
18378 case OPCODE_MOV: /* MOV <-> MVN */
18379 new_inst = OPCODE_MVN;
18380 value = inverted;
18381 break;
bfae80f2 18382
c19d1205
ZW
18383 case OPCODE_MVN:
18384 new_inst = OPCODE_MOV;
18385 value = inverted;
18386 break;
bfae80f2 18387
c19d1205
ZW
18388 case OPCODE_AND: /* AND <-> BIC */
18389 new_inst = OPCODE_BIC;
18390 value = inverted;
18391 break;
bfae80f2 18392
c19d1205
ZW
18393 case OPCODE_BIC:
18394 new_inst = OPCODE_AND;
18395 value = inverted;
18396 break;
bfae80f2 18397
c19d1205
ZW
18398 case OPCODE_ADC: /* ADC <-> SBC */
18399 new_inst = OPCODE_SBC;
18400 value = inverted;
18401 break;
bfae80f2 18402
c19d1205
ZW
18403 case OPCODE_SBC:
18404 new_inst = OPCODE_ADC;
18405 value = inverted;
18406 break;
bfae80f2 18407
c19d1205
ZW
18408 /* We cannot do anything. */
18409 default:
18410 return FAIL;
b99bd4ef
NC
18411 }
18412
c19d1205
ZW
18413 if (value == (unsigned) FAIL)
18414 return FAIL;
18415
18416 *instruction &= OPCODE_MASK;
18417 *instruction |= new_inst << DATA_OP_SHIFT;
18418 return value;
b99bd4ef
NC
18419}
18420
ef8d22e6
PB
18421/* Like negate_data_op, but for Thumb-2. */
18422
18423static unsigned int
16dd5e42 18424thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
18425{
18426 int op, new_inst;
18427 int rd;
16dd5e42 18428 unsigned int negated, inverted;
ef8d22e6
PB
18429
18430 negated = encode_thumb32_immediate (-value);
18431 inverted = encode_thumb32_immediate (~value);
18432
18433 rd = (*instruction >> 8) & 0xf;
18434 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18435 switch (op)
18436 {
18437 /* ADD <-> SUB. Includes CMP <-> CMN. */
18438 case T2_OPCODE_SUB:
18439 new_inst = T2_OPCODE_ADD;
18440 value = negated;
18441 break;
18442
18443 case T2_OPCODE_ADD:
18444 new_inst = T2_OPCODE_SUB;
18445 value = negated;
18446 break;
18447
18448 /* ORR <-> ORN. Includes MOV <-> MVN. */
18449 case T2_OPCODE_ORR:
18450 new_inst = T2_OPCODE_ORN;
18451 value = inverted;
18452 break;
18453
18454 case T2_OPCODE_ORN:
18455 new_inst = T2_OPCODE_ORR;
18456 value = inverted;
18457 break;
18458
18459 /* AND <-> BIC. TST has no inverted equivalent. */
18460 case T2_OPCODE_AND:
18461 new_inst = T2_OPCODE_BIC;
18462 if (rd == 15)
18463 value = FAIL;
18464 else
18465 value = inverted;
18466 break;
18467
18468 case T2_OPCODE_BIC:
18469 new_inst = T2_OPCODE_AND;
18470 value = inverted;
18471 break;
18472
18473 /* ADC <-> SBC */
18474 case T2_OPCODE_ADC:
18475 new_inst = T2_OPCODE_SBC;
18476 value = inverted;
18477 break;
18478
18479 case T2_OPCODE_SBC:
18480 new_inst = T2_OPCODE_ADC;
18481 value = inverted;
18482 break;
18483
18484 /* We cannot do anything. */
18485 default:
18486 return FAIL;
18487 }
18488
16dd5e42 18489 if (value == (unsigned int)FAIL)
ef8d22e6
PB
18490 return FAIL;
18491
18492 *instruction &= T2_OPCODE_MASK;
18493 *instruction |= new_inst << T2_DATA_OP_SHIFT;
18494 return value;
18495}
18496
8f06b2d8
PB
18497/* Read a 32-bit thumb instruction from buf. */
18498static unsigned long
18499get_thumb32_insn (char * buf)
18500{
18501 unsigned long insn;
18502 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
18503 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18504
18505 return insn;
18506}
18507
a8bc6c78
PB
18508
18509/* We usually want to set the low bit on the address of thumb function
18510 symbols. In particular .word foo - . should have the low bit set.
18511 Generic code tries to fold the difference of two symbols to
18512 a constant. Prevent this and force a relocation when the first symbols
18513 is a thumb function. */
18514int
18515arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
18516{
18517 if (op == O_subtract
18518 && l->X_op == O_symbol
18519 && r->X_op == O_symbol
18520 && THUMB_IS_FUNC (l->X_add_symbol))
18521 {
18522 l->X_op = O_subtract;
18523 l->X_op_symbol = r->X_add_symbol;
18524 l->X_add_number -= r->X_add_number;
18525 return 1;
18526 }
18527 /* Process as normal. */
18528 return 0;
18529}
18530
c19d1205 18531void
55cf6793 18532md_apply_fix (fixS * fixP,
c19d1205
ZW
18533 valueT * valP,
18534 segT seg)
18535{
18536 offsetT value = * valP;
18537 offsetT newval;
18538 unsigned int newimm;
18539 unsigned long temp;
18540 int sign;
18541 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 18542
c19d1205 18543 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 18544
c19d1205 18545 /* Note whether this will delete the relocation. */
4962c51a 18546
c19d1205
ZW
18547 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
18548 fixP->fx_done = 1;
b99bd4ef 18549
adbaf948 18550 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 18551 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
18552 for emit_reloc. */
18553 value &= 0xffffffff;
18554 value ^= 0x80000000;
5f4273c7 18555 value -= 0x80000000;
adbaf948
ZW
18556
18557 *valP = value;
c19d1205 18558 fixP->fx_addnumber = value;
b99bd4ef 18559
adbaf948
ZW
18560 /* Same treatment for fixP->fx_offset. */
18561 fixP->fx_offset &= 0xffffffff;
18562 fixP->fx_offset ^= 0x80000000;
18563 fixP->fx_offset -= 0x80000000;
18564
c19d1205 18565 switch (fixP->fx_r_type)
b99bd4ef 18566 {
c19d1205
ZW
18567 case BFD_RELOC_NONE:
18568 /* This will need to go in the object file. */
18569 fixP->fx_done = 0;
18570 break;
b99bd4ef 18571
c19d1205
ZW
18572 case BFD_RELOC_ARM_IMMEDIATE:
18573 /* We claim that this fixup has been processed here,
18574 even if in fact we generate an error because we do
18575 not have a reloc for it, so tc_gen_reloc will reject it. */
18576 fixP->fx_done = 1;
b99bd4ef 18577
c19d1205
ZW
18578 if (fixP->fx_addsy
18579 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 18580 {
c19d1205
ZW
18581 as_bad_where (fixP->fx_file, fixP->fx_line,
18582 _("undefined symbol %s used as an immediate value"),
18583 S_GET_NAME (fixP->fx_addsy));
18584 break;
b99bd4ef
NC
18585 }
18586
42e5fcbf
AS
18587 if (fixP->fx_addsy
18588 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18589 {
18590 as_bad_where (fixP->fx_file, fixP->fx_line,
18591 _("symbol %s is in a different section"),
18592 S_GET_NAME (fixP->fx_addsy));
18593 break;
18594 }
18595
c19d1205
ZW
18596 newimm = encode_arm_immediate (value);
18597 temp = md_chars_to_number (buf, INSN_SIZE);
18598
18599 /* If the instruction will fail, see if we can fix things up by
18600 changing the opcode. */
18601 if (newimm == (unsigned int) FAIL
18602 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 18603 {
c19d1205
ZW
18604 as_bad_where (fixP->fx_file, fixP->fx_line,
18605 _("invalid constant (%lx) after fixup"),
18606 (unsigned long) value);
18607 break;
b99bd4ef 18608 }
b99bd4ef 18609
c19d1205
ZW
18610 newimm |= (temp & 0xfffff000);
18611 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18612 break;
b99bd4ef 18613
c19d1205
ZW
18614 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18615 {
18616 unsigned int highpart = 0;
18617 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18618
42e5fcbf
AS
18619 if (fixP->fx_addsy
18620 && ! S_IS_DEFINED (fixP->fx_addsy))
18621 {
18622 as_bad_where (fixP->fx_file, fixP->fx_line,
18623 _("undefined symbol %s used as an immediate value"),
18624 S_GET_NAME (fixP->fx_addsy));
18625 break;
18626 }
18627
18628 if (fixP->fx_addsy
18629 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18630 {
18631 as_bad_where (fixP->fx_file, fixP->fx_line,
18632 _("symbol %s is in a different section"),
18633 S_GET_NAME (fixP->fx_addsy));
18634 break;
18635 }
18636
c19d1205
ZW
18637 newimm = encode_arm_immediate (value);
18638 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18639
c19d1205
ZW
18640 /* If the instruction will fail, see if we can fix things up by
18641 changing the opcode. */
18642 if (newimm == (unsigned int) FAIL
18643 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18644 {
18645 /* No ? OK - try using two ADD instructions to generate
18646 the value. */
18647 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18648
c19d1205
ZW
18649 /* Yes - then make sure that the second instruction is
18650 also an add. */
18651 if (newimm != (unsigned int) FAIL)
18652 newinsn = temp;
18653 /* Still No ? Try using a negated value. */
18654 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18655 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18656 /* Otherwise - give up. */
18657 else
18658 {
18659 as_bad_where (fixP->fx_file, fixP->fx_line,
18660 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18661 (long) value);
18662 break;
18663 }
b99bd4ef 18664
c19d1205
ZW
18665 /* Replace the first operand in the 2nd instruction (which
18666 is the PC) with the destination register. We have
18667 already added in the PC in the first instruction and we
18668 do not want to do it again. */
18669 newinsn &= ~ 0xf0000;
18670 newinsn |= ((newinsn & 0x0f000) << 4);
18671 }
b99bd4ef 18672
c19d1205
ZW
18673 newimm |= (temp & 0xfffff000);
18674 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18675
c19d1205
ZW
18676 highpart |= (newinsn & 0xfffff000);
18677 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18678 }
18679 break;
b99bd4ef 18680
c19d1205 18681 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18682 if (!fixP->fx_done && seg->use_rela_p)
18683 value = 0;
18684
c19d1205
ZW
18685 case BFD_RELOC_ARM_LITERAL:
18686 sign = value >= 0;
b99bd4ef 18687
c19d1205
ZW
18688 if (value < 0)
18689 value = - value;
b99bd4ef 18690
c19d1205 18691 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18692 {
c19d1205
ZW
18693 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18694 as_bad_where (fixP->fx_file, fixP->fx_line,
18695 _("invalid literal constant: pool needs to be closer"));
18696 else
18697 as_bad_where (fixP->fx_file, fixP->fx_line,
18698 _("bad immediate value for offset (%ld)"),
18699 (long) value);
18700 break;
f03698e6
RE
18701 }
18702
c19d1205
ZW
18703 newval = md_chars_to_number (buf, INSN_SIZE);
18704 newval &= 0xff7ff000;
18705 newval |= value | (sign ? INDEX_UP : 0);
18706 md_number_to_chars (buf, newval, INSN_SIZE);
18707 break;
b99bd4ef 18708
c19d1205
ZW
18709 case BFD_RELOC_ARM_OFFSET_IMM8:
18710 case BFD_RELOC_ARM_HWLITERAL:
18711 sign = value >= 0;
b99bd4ef 18712
c19d1205
ZW
18713 if (value < 0)
18714 value = - value;
b99bd4ef 18715
c19d1205 18716 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18717 {
c19d1205
ZW
18718 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18719 as_bad_where (fixP->fx_file, fixP->fx_line,
18720 _("invalid literal constant: pool needs to be closer"));
18721 else
f9d4405b 18722 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18723 (long) value);
18724 break;
b99bd4ef
NC
18725 }
18726
c19d1205
ZW
18727 newval = md_chars_to_number (buf, INSN_SIZE);
18728 newval &= 0xff7ff0f0;
18729 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18730 md_number_to_chars (buf, newval, INSN_SIZE);
18731 break;
b99bd4ef 18732
c19d1205
ZW
18733 case BFD_RELOC_ARM_T32_OFFSET_U8:
18734 if (value < 0 || value > 1020 || value % 4 != 0)
18735 as_bad_where (fixP->fx_file, fixP->fx_line,
18736 _("bad immediate value for offset (%ld)"), (long) value);
18737 value /= 4;
b99bd4ef 18738
c19d1205 18739 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18740 newval |= value;
18741 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18742 break;
b99bd4ef 18743
c19d1205
ZW
18744 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18745 /* This is a complicated relocation used for all varieties of Thumb32
18746 load/store instruction with immediate offset:
18747
18748 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18749 *4, optional writeback(W)
18750 (doubleword load/store)
18751
18752 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18753 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18754 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18755 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18756 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18757
18758 Uppercase letters indicate bits that are already encoded at
18759 this point. Lowercase letters are our problem. For the
18760 second block of instructions, the secondary opcode nybble
18761 (bits 8..11) is present, and bit 23 is zero, even if this is
18762 a PC-relative operation. */
18763 newval = md_chars_to_number (buf, THUMB_SIZE);
18764 newval <<= 16;
18765 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18766
c19d1205 18767 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18768 {
c19d1205
ZW
18769 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18770 if (value >= 0)
18771 newval |= (1 << 23);
18772 else
18773 value = -value;
18774 if (value % 4 != 0)
18775 {
18776 as_bad_where (fixP->fx_file, fixP->fx_line,
18777 _("offset not a multiple of 4"));
18778 break;
18779 }
18780 value /= 4;
216d22bc 18781 if (value > 0xff)
c19d1205
ZW
18782 {
18783 as_bad_where (fixP->fx_file, fixP->fx_line,
18784 _("offset out of range"));
18785 break;
18786 }
18787 newval &= ~0xff;
b99bd4ef 18788 }
c19d1205 18789 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18790 {
c19d1205
ZW
18791 /* PC-relative, 12-bit offset. */
18792 if (value >= 0)
18793 newval |= (1 << 23);
18794 else
18795 value = -value;
216d22bc 18796 if (value > 0xfff)
c19d1205
ZW
18797 {
18798 as_bad_where (fixP->fx_file, fixP->fx_line,
18799 _("offset out of range"));
18800 break;
18801 }
18802 newval &= ~0xfff;
b99bd4ef 18803 }
c19d1205 18804 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18805 {
c19d1205
ZW
18806 /* Writeback: 8-bit, +/- offset. */
18807 if (value >= 0)
18808 newval |= (1 << 9);
18809 else
18810 value = -value;
216d22bc 18811 if (value > 0xff)
c19d1205
ZW
18812 {
18813 as_bad_where (fixP->fx_file, fixP->fx_line,
18814 _("offset out of range"));
18815 break;
18816 }
18817 newval &= ~0xff;
b99bd4ef 18818 }
c19d1205 18819 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18820 {
c19d1205 18821 /* T-instruction: positive 8-bit offset. */
216d22bc 18822 if (value < 0 || value > 0xff)
b99bd4ef 18823 {
c19d1205
ZW
18824 as_bad_where (fixP->fx_file, fixP->fx_line,
18825 _("offset out of range"));
18826 break;
b99bd4ef 18827 }
c19d1205
ZW
18828 newval &= ~0xff;
18829 newval |= value;
b99bd4ef
NC
18830 }
18831 else
b99bd4ef 18832 {
c19d1205
ZW
18833 /* Positive 12-bit or negative 8-bit offset. */
18834 int limit;
18835 if (value >= 0)
b99bd4ef 18836 {
c19d1205
ZW
18837 newval |= (1 << 23);
18838 limit = 0xfff;
18839 }
18840 else
18841 {
18842 value = -value;
18843 limit = 0xff;
18844 }
18845 if (value > limit)
18846 {
18847 as_bad_where (fixP->fx_file, fixP->fx_line,
18848 _("offset out of range"));
18849 break;
b99bd4ef 18850 }
c19d1205 18851 newval &= ~limit;
b99bd4ef 18852 }
b99bd4ef 18853
c19d1205
ZW
18854 newval |= value;
18855 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18856 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18857 break;
404ff6b5 18858
c19d1205
ZW
18859 case BFD_RELOC_ARM_SHIFT_IMM:
18860 newval = md_chars_to_number (buf, INSN_SIZE);
18861 if (((unsigned long) value) > 32
18862 || (value == 32
18863 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18864 {
18865 as_bad_where (fixP->fx_file, fixP->fx_line,
18866 _("shift expression is too large"));
18867 break;
18868 }
404ff6b5 18869
c19d1205
ZW
18870 if (value == 0)
18871 /* Shifts of zero must be done as lsl. */
18872 newval &= ~0x60;
18873 else if (value == 32)
18874 value = 0;
18875 newval &= 0xfffff07f;
18876 newval |= (value & 0x1f) << 7;
18877 md_number_to_chars (buf, newval, INSN_SIZE);
18878 break;
404ff6b5 18879
c19d1205 18880 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18881 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18882 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18883 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18884 /* We claim that this fixup has been processed here,
18885 even if in fact we generate an error because we do
18886 not have a reloc for it, so tc_gen_reloc will reject it. */
18887 fixP->fx_done = 1;
404ff6b5 18888
c19d1205
ZW
18889 if (fixP->fx_addsy
18890 && ! S_IS_DEFINED (fixP->fx_addsy))
18891 {
18892 as_bad_where (fixP->fx_file, fixP->fx_line,
18893 _("undefined symbol %s used as an immediate value"),
18894 S_GET_NAME (fixP->fx_addsy));
18895 break;
18896 }
404ff6b5 18897
c19d1205
ZW
18898 newval = md_chars_to_number (buf, THUMB_SIZE);
18899 newval <<= 16;
18900 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18901
16805f35
PB
18902 newimm = FAIL;
18903 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18904 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18905 {
18906 newimm = encode_thumb32_immediate (value);
18907 if (newimm == (unsigned int) FAIL)
18908 newimm = thumb32_negate_data_op (&newval, value);
18909 }
16805f35
PB
18910 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18911 && newimm == (unsigned int) FAIL)
92e90b6e 18912 {
16805f35
PB
18913 /* Turn add/sum into addw/subw. */
18914 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18915 newval = (newval & 0xfeffffff) | 0x02000000;
18916
e9f89963
PB
18917 /* 12 bit immediate for addw/subw. */
18918 if (value < 0)
18919 {
18920 value = -value;
18921 newval ^= 0x00a00000;
18922 }
92e90b6e
PB
18923 if (value > 0xfff)
18924 newimm = (unsigned int) FAIL;
18925 else
18926 newimm = value;
18927 }
cc8a6dd0 18928
c19d1205 18929 if (newimm == (unsigned int)FAIL)
3631a3c8 18930 {
c19d1205
ZW
18931 as_bad_where (fixP->fx_file, fixP->fx_line,
18932 _("invalid constant (%lx) after fixup"),
18933 (unsigned long) value);
18934 break;
3631a3c8
NC
18935 }
18936
c19d1205
ZW
18937 newval |= (newimm & 0x800) << 15;
18938 newval |= (newimm & 0x700) << 4;
18939 newval |= (newimm & 0x0ff);
cc8a6dd0 18940
c19d1205
ZW
18941 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18942 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18943 break;
a737bd4d 18944
3eb17e6b 18945 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18946 if (((unsigned long) value) > 0xffff)
18947 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18948 _("invalid smc expression"));
2fc8bdac 18949 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18950 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18951 md_number_to_chars (buf, newval, INSN_SIZE);
18952 break;
a737bd4d 18953
c19d1205 18954 case BFD_RELOC_ARM_SWI:
adbaf948 18955 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18956 {
18957 if (((unsigned long) value) > 0xff)
18958 as_bad_where (fixP->fx_file, fixP->fx_line,
18959 _("invalid swi expression"));
2fc8bdac 18960 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18961 newval |= value;
18962 md_number_to_chars (buf, newval, THUMB_SIZE);
18963 }
18964 else
18965 {
18966 if (((unsigned long) value) > 0x00ffffff)
18967 as_bad_where (fixP->fx_file, fixP->fx_line,
18968 _("invalid swi expression"));
2fc8bdac 18969 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18970 newval |= value;
18971 md_number_to_chars (buf, newval, INSN_SIZE);
18972 }
18973 break;
a737bd4d 18974
c19d1205
ZW
18975 case BFD_RELOC_ARM_MULTI:
18976 if (((unsigned long) value) > 0xffff)
18977 as_bad_where (fixP->fx_file, fixP->fx_line,
18978 _("invalid expression in load/store multiple"));
18979 newval = value | md_chars_to_number (buf, INSN_SIZE);
18980 md_number_to_chars (buf, newval, INSN_SIZE);
18981 break;
a737bd4d 18982
c19d1205 18983#ifdef OBJ_ELF
39b41c9c
PB
18984 case BFD_RELOC_ARM_PCREL_CALL:
18985 newval = md_chars_to_number (buf, INSN_SIZE);
18986 if ((newval & 0xf0000000) == 0xf0000000)
18987 temp = 1;
18988 else
18989 temp = 3;
18990 goto arm_branch_common;
18991
18992 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18993 case BFD_RELOC_ARM_PLT32:
c19d1205 18994#endif
39b41c9c
PB
18995 case BFD_RELOC_ARM_PCREL_BRANCH:
18996 temp = 3;
18997 goto arm_branch_common;
a737bd4d 18998
39b41c9c
PB
18999 case BFD_RELOC_ARM_PCREL_BLX:
19000 temp = 1;
19001 arm_branch_common:
c19d1205 19002 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
19003 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19004 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19005 also be be clear. */
19006 if (value & temp)
c19d1205 19007 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
19008 _("misaligned branch destination"));
19009 if ((value & (offsetT)0xfe000000) != (offsetT)0
19010 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19011 as_bad_where (fixP->fx_file, fixP->fx_line,
19012 _("branch out of range"));
a737bd4d 19013
2fc8bdac 19014 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19015 {
2fc8bdac
ZW
19016 newval = md_chars_to_number (buf, INSN_SIZE);
19017 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
19018 /* Set the H bit on BLX instructions. */
19019 if (temp == 1)
19020 {
19021 if (value & 2)
19022 newval |= 0x01000000;
19023 else
19024 newval &= ~0x01000000;
19025 }
2fc8bdac 19026 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 19027 }
c19d1205 19028 break;
a737bd4d 19029
25fe350b
MS
19030 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19031 /* CBZ can only branch forward. */
a737bd4d 19032
738755b0
MS
19033 /* Attempts to use CBZ to branch to the next instruction
19034 (which, strictly speaking, are prohibited) will be turned into
19035 no-ops.
19036
19037 FIXME: It may be better to remove the instruction completely and
19038 perform relaxation. */
19039 if (value == -2)
2fc8bdac
ZW
19040 {
19041 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 19042 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
19043 md_number_to_chars (buf, newval, THUMB_SIZE);
19044 }
738755b0
MS
19045 else
19046 {
19047 if (value & ~0x7e)
19048 as_bad_where (fixP->fx_file, fixP->fx_line,
19049 _("branch out of range"));
19050
19051 if (fixP->fx_done || !seg->use_rela_p)
19052 {
19053 newval = md_chars_to_number (buf, THUMB_SIZE);
19054 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19055 md_number_to_chars (buf, newval, THUMB_SIZE);
19056 }
19057 }
c19d1205 19058 break;
a737bd4d 19059
c19d1205 19060 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
19061 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19062 as_bad_where (fixP->fx_file, fixP->fx_line,
19063 _("branch out of range"));
a737bd4d 19064
2fc8bdac
ZW
19065 if (fixP->fx_done || !seg->use_rela_p)
19066 {
19067 newval = md_chars_to_number (buf, THUMB_SIZE);
19068 newval |= (value & 0x1ff) >> 1;
19069 md_number_to_chars (buf, newval, THUMB_SIZE);
19070 }
c19d1205 19071 break;
a737bd4d 19072
c19d1205 19073 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
19074 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19075 as_bad_where (fixP->fx_file, fixP->fx_line,
19076 _("branch out of range"));
a737bd4d 19077
2fc8bdac
ZW
19078 if (fixP->fx_done || !seg->use_rela_p)
19079 {
19080 newval = md_chars_to_number (buf, THUMB_SIZE);
19081 newval |= (value & 0xfff) >> 1;
19082 md_number_to_chars (buf, newval, THUMB_SIZE);
19083 }
c19d1205 19084 break;
a737bd4d 19085
c19d1205 19086 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
19087 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19088 as_bad_where (fixP->fx_file, fixP->fx_line,
19089 _("conditional branch out of range"));
404ff6b5 19090
2fc8bdac
ZW
19091 if (fixP->fx_done || !seg->use_rela_p)
19092 {
19093 offsetT newval2;
19094 addressT S, J1, J2, lo, hi;
404ff6b5 19095
2fc8bdac
ZW
19096 S = (value & 0x00100000) >> 20;
19097 J2 = (value & 0x00080000) >> 19;
19098 J1 = (value & 0x00040000) >> 18;
19099 hi = (value & 0x0003f000) >> 12;
19100 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19101
2fc8bdac
ZW
19102 newval = md_chars_to_number (buf, THUMB_SIZE);
19103 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19104 newval |= (S << 10) | hi;
19105 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19106 md_number_to_chars (buf, newval, THUMB_SIZE);
19107 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19108 }
c19d1205 19109 break;
6c43fab6 19110
c19d1205
ZW
19111 case BFD_RELOC_THUMB_PCREL_BLX:
19112 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
19113 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19114 as_bad_where (fixP->fx_file, fixP->fx_line,
19115 _("branch out of range"));
404ff6b5 19116
2fc8bdac
ZW
19117 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19118 /* For a BLX instruction, make sure that the relocation is rounded up
19119 to a word boundary. This follows the semantics of the instruction
19120 which specifies that bit 1 of the target address will come from bit
19121 1 of the base address. */
19122 value = (value + 1) & ~ 1;
404ff6b5 19123
2fc8bdac 19124 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19125 {
2fc8bdac
ZW
19126 offsetT newval2;
19127
19128 newval = md_chars_to_number (buf, THUMB_SIZE);
19129 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19130 newval |= (value & 0x7fffff) >> 12;
19131 newval2 |= (value & 0xfff) >> 1;
19132 md_number_to_chars (buf, newval, THUMB_SIZE);
19133 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 19134 }
c19d1205 19135 break;
404ff6b5 19136
c19d1205 19137 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
19138 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19139 as_bad_where (fixP->fx_file, fixP->fx_line,
19140 _("branch out of range"));
6c43fab6 19141
2fc8bdac
ZW
19142 if (fixP->fx_done || !seg->use_rela_p)
19143 {
19144 offsetT newval2;
19145 addressT S, I1, I2, lo, hi;
6c43fab6 19146
2fc8bdac
ZW
19147 S = (value & 0x01000000) >> 24;
19148 I1 = (value & 0x00800000) >> 23;
19149 I2 = (value & 0x00400000) >> 22;
19150 hi = (value & 0x003ff000) >> 12;
19151 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19152
2fc8bdac
ZW
19153 I1 = !(I1 ^ S);
19154 I2 = !(I2 ^ S);
a737bd4d 19155
2fc8bdac
ZW
19156 newval = md_chars_to_number (buf, THUMB_SIZE);
19157 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19158 newval |= (S << 10) | hi;
19159 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19160 md_number_to_chars (buf, newval, THUMB_SIZE);
19161 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19162 }
19163 break;
a737bd4d 19164
2fc8bdac
ZW
19165 case BFD_RELOC_8:
19166 if (fixP->fx_done || !seg->use_rela_p)
19167 md_number_to_chars (buf, value, 1);
c19d1205 19168 break;
a737bd4d 19169
c19d1205 19170 case BFD_RELOC_16:
2fc8bdac 19171 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19172 md_number_to_chars (buf, value, 2);
c19d1205 19173 break;
a737bd4d 19174
c19d1205
ZW
19175#ifdef OBJ_ELF
19176 case BFD_RELOC_ARM_TLS_GD32:
19177 case BFD_RELOC_ARM_TLS_LE32:
19178 case BFD_RELOC_ARM_TLS_IE32:
19179 case BFD_RELOC_ARM_TLS_LDM32:
19180 case BFD_RELOC_ARM_TLS_LDO32:
19181 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19182 /* fall through */
6c43fab6 19183
c19d1205
ZW
19184 case BFD_RELOC_ARM_GOT32:
19185 case BFD_RELOC_ARM_GOTOFF:
19186 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
19187 if (fixP->fx_done || !seg->use_rela_p)
19188 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
19189 break;
19190#endif
6c43fab6 19191
c19d1205
ZW
19192 case BFD_RELOC_RVA:
19193 case BFD_RELOC_32:
19194 case BFD_RELOC_ARM_TARGET1:
19195 case BFD_RELOC_ARM_ROSEGREL32:
19196 case BFD_RELOC_ARM_SBREL32:
19197 case BFD_RELOC_32_PCREL:
f0927246
NC
19198#ifdef TE_PE
19199 case BFD_RELOC_32_SECREL:
19200#endif
2fc8bdac 19201 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
19202#ifdef TE_WINCE
19203 /* For WinCE we only do this for pcrel fixups. */
19204 if (fixP->fx_done || fixP->fx_pcrel)
19205#endif
19206 md_number_to_chars (buf, value, 4);
c19d1205 19207 break;
6c43fab6 19208
c19d1205
ZW
19209#ifdef OBJ_ELF
19210 case BFD_RELOC_ARM_PREL31:
2fc8bdac 19211 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
19212 {
19213 newval = md_chars_to_number (buf, 4) & 0x80000000;
19214 if ((value ^ (value >> 1)) & 0x40000000)
19215 {
19216 as_bad_where (fixP->fx_file, fixP->fx_line,
19217 _("rel31 relocation overflow"));
19218 }
19219 newval |= value & 0x7fffffff;
19220 md_number_to_chars (buf, newval, 4);
19221 }
19222 break;
c19d1205 19223#endif
a737bd4d 19224
c19d1205 19225 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 19226 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
19227 if (value < -1023 || value > 1023 || (value & 3))
19228 as_bad_where (fixP->fx_file, fixP->fx_line,
19229 _("co-processor offset out of range"));
19230 cp_off_common:
19231 sign = value >= 0;
19232 if (value < 0)
19233 value = -value;
8f06b2d8
PB
19234 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19235 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19236 newval = md_chars_to_number (buf, INSN_SIZE);
19237 else
19238 newval = get_thumb32_insn (buf);
19239 newval &= 0xff7fff00;
c19d1205 19240 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
19241 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19242 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19243 md_number_to_chars (buf, newval, INSN_SIZE);
19244 else
19245 put_thumb32_insn (buf, newval);
c19d1205 19246 break;
a737bd4d 19247
c19d1205 19248 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 19249 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
19250 if (value < -255 || value > 255)
19251 as_bad_where (fixP->fx_file, fixP->fx_line,
19252 _("co-processor offset out of range"));
df7849c5 19253 value *= 4;
c19d1205 19254 goto cp_off_common;
6c43fab6 19255
c19d1205
ZW
19256 case BFD_RELOC_ARM_THUMB_OFFSET:
19257 newval = md_chars_to_number (buf, THUMB_SIZE);
19258 /* Exactly what ranges, and where the offset is inserted depends
19259 on the type of instruction, we can establish this from the
19260 top 4 bits. */
19261 switch (newval >> 12)
19262 {
19263 case 4: /* PC load. */
19264 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19265 forced to zero for these loads; md_pcrel_from has already
19266 compensated for this. */
19267 if (value & 3)
19268 as_bad_where (fixP->fx_file, fixP->fx_line,
19269 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
19270 (((unsigned long) fixP->fx_frag->fr_address
19271 + (unsigned long) fixP->fx_where) & ~3)
19272 + (unsigned long) value);
a737bd4d 19273
c19d1205
ZW
19274 if (value & ~0x3fc)
19275 as_bad_where (fixP->fx_file, fixP->fx_line,
19276 _("invalid offset, value too big (0x%08lX)"),
19277 (long) value);
a737bd4d 19278
c19d1205
ZW
19279 newval |= value >> 2;
19280 break;
a737bd4d 19281
c19d1205
ZW
19282 case 9: /* SP load/store. */
19283 if (value & ~0x3fc)
19284 as_bad_where (fixP->fx_file, fixP->fx_line,
19285 _("invalid offset, value too big (0x%08lX)"),
19286 (long) value);
19287 newval |= value >> 2;
19288 break;
6c43fab6 19289
c19d1205
ZW
19290 case 6: /* Word load/store. */
19291 if (value & ~0x7c)
19292 as_bad_where (fixP->fx_file, fixP->fx_line,
19293 _("invalid offset, value too big (0x%08lX)"),
19294 (long) value);
19295 newval |= value << 4; /* 6 - 2. */
19296 break;
a737bd4d 19297
c19d1205
ZW
19298 case 7: /* Byte load/store. */
19299 if (value & ~0x1f)
19300 as_bad_where (fixP->fx_file, fixP->fx_line,
19301 _("invalid offset, value too big (0x%08lX)"),
19302 (long) value);
19303 newval |= value << 6;
19304 break;
a737bd4d 19305
c19d1205
ZW
19306 case 8: /* Halfword load/store. */
19307 if (value & ~0x3e)
19308 as_bad_where (fixP->fx_file, fixP->fx_line,
19309 _("invalid offset, value too big (0x%08lX)"),
19310 (long) value);
19311 newval |= value << 5; /* 6 - 1. */
19312 break;
a737bd4d 19313
c19d1205
ZW
19314 default:
19315 as_bad_where (fixP->fx_file, fixP->fx_line,
19316 "Unable to process relocation for thumb opcode: %lx",
19317 (unsigned long) newval);
19318 break;
19319 }
19320 md_number_to_chars (buf, newval, THUMB_SIZE);
19321 break;
a737bd4d 19322
c19d1205
ZW
19323 case BFD_RELOC_ARM_THUMB_ADD:
19324 /* This is a complicated relocation, since we use it for all of
19325 the following immediate relocations:
a737bd4d 19326
c19d1205
ZW
19327 3bit ADD/SUB
19328 8bit ADD/SUB
19329 9bit ADD/SUB SP word-aligned
19330 10bit ADD PC/SP word-aligned
a737bd4d 19331
c19d1205
ZW
19332 The type of instruction being processed is encoded in the
19333 instruction field:
a737bd4d 19334
c19d1205
ZW
19335 0x8000 SUB
19336 0x00F0 Rd
19337 0x000F Rs
19338 */
19339 newval = md_chars_to_number (buf, THUMB_SIZE);
19340 {
19341 int rd = (newval >> 4) & 0xf;
19342 int rs = newval & 0xf;
19343 int subtract = !!(newval & 0x8000);
a737bd4d 19344
c19d1205
ZW
19345 /* Check for HI regs, only very restricted cases allowed:
19346 Adjusting SP, and using PC or SP to get an address. */
19347 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19348 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19349 as_bad_where (fixP->fx_file, fixP->fx_line,
19350 _("invalid Hi register with immediate"));
a737bd4d 19351
c19d1205
ZW
19352 /* If value is negative, choose the opposite instruction. */
19353 if (value < 0)
19354 {
19355 value = -value;
19356 subtract = !subtract;
19357 if (value < 0)
19358 as_bad_where (fixP->fx_file, fixP->fx_line,
19359 _("immediate value out of range"));
19360 }
a737bd4d 19361
c19d1205
ZW
19362 if (rd == REG_SP)
19363 {
19364 if (value & ~0x1fc)
19365 as_bad_where (fixP->fx_file, fixP->fx_line,
19366 _("invalid immediate for stack address calculation"));
19367 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
19368 newval |= value >> 2;
19369 }
19370 else if (rs == REG_PC || rs == REG_SP)
19371 {
19372 if (subtract || value & ~0x3fc)
19373 as_bad_where (fixP->fx_file, fixP->fx_line,
19374 _("invalid immediate for address calculation (value = 0x%08lX)"),
19375 (unsigned long) value);
19376 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
19377 newval |= rd << 8;
19378 newval |= value >> 2;
19379 }
19380 else if (rs == rd)
19381 {
19382 if (value & ~0xff)
19383 as_bad_where (fixP->fx_file, fixP->fx_line,
19384 _("immediate value out of range"));
19385 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
19386 newval |= (rd << 8) | value;
19387 }
19388 else
19389 {
19390 if (value & ~0x7)
19391 as_bad_where (fixP->fx_file, fixP->fx_line,
19392 _("immediate value out of range"));
19393 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
19394 newval |= rd | (rs << 3) | (value << 6);
19395 }
19396 }
19397 md_number_to_chars (buf, newval, THUMB_SIZE);
19398 break;
a737bd4d 19399
c19d1205
ZW
19400 case BFD_RELOC_ARM_THUMB_IMM:
19401 newval = md_chars_to_number (buf, THUMB_SIZE);
19402 if (value < 0 || value > 255)
19403 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 19404 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
19405 (long) value);
19406 newval |= value;
19407 md_number_to_chars (buf, newval, THUMB_SIZE);
19408 break;
a737bd4d 19409
c19d1205
ZW
19410 case BFD_RELOC_ARM_THUMB_SHIFT:
19411 /* 5bit shift value (0..32). LSL cannot take 32. */
19412 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
19413 temp = newval & 0xf800;
19414 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
19415 as_bad_where (fixP->fx_file, fixP->fx_line,
19416 _("invalid shift value: %ld"), (long) value);
19417 /* Shifts of zero must be encoded as LSL. */
19418 if (value == 0)
19419 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
19420 /* Shifts of 32 are encoded as zero. */
19421 else if (value == 32)
19422 value = 0;
19423 newval |= value << 6;
19424 md_number_to_chars (buf, newval, THUMB_SIZE);
19425 break;
a737bd4d 19426
c19d1205
ZW
19427 case BFD_RELOC_VTABLE_INHERIT:
19428 case BFD_RELOC_VTABLE_ENTRY:
19429 fixP->fx_done = 0;
19430 return;
6c43fab6 19431
b6895b4f
PB
19432 case BFD_RELOC_ARM_MOVW:
19433 case BFD_RELOC_ARM_MOVT:
19434 case BFD_RELOC_ARM_THUMB_MOVW:
19435 case BFD_RELOC_ARM_THUMB_MOVT:
19436 if (fixP->fx_done || !seg->use_rela_p)
19437 {
19438 /* REL format relocations are limited to a 16-bit addend. */
19439 if (!fixP->fx_done)
19440 {
39623e12 19441 if (value < -0x8000 || value > 0x7fff)
b6895b4f 19442 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 19443 _("offset out of range"));
b6895b4f
PB
19444 }
19445 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
19446 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19447 {
19448 value >>= 16;
19449 }
19450
19451 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
19452 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19453 {
19454 newval = get_thumb32_insn (buf);
19455 newval &= 0xfbf08f00;
19456 newval |= (value & 0xf000) << 4;
19457 newval |= (value & 0x0800) << 15;
19458 newval |= (value & 0x0700) << 4;
19459 newval |= (value & 0x00ff);
19460 put_thumb32_insn (buf, newval);
19461 }
19462 else
19463 {
19464 newval = md_chars_to_number (buf, 4);
19465 newval &= 0xfff0f000;
19466 newval |= value & 0x0fff;
19467 newval |= (value & 0xf000) << 4;
19468 md_number_to_chars (buf, newval, 4);
19469 }
19470 }
19471 return;
19472
4962c51a
MS
19473 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19474 case BFD_RELOC_ARM_ALU_PC_G0:
19475 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19476 case BFD_RELOC_ARM_ALU_PC_G1:
19477 case BFD_RELOC_ARM_ALU_PC_G2:
19478 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19479 case BFD_RELOC_ARM_ALU_SB_G0:
19480 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19481 case BFD_RELOC_ARM_ALU_SB_G1:
19482 case BFD_RELOC_ARM_ALU_SB_G2:
19483 assert (!fixP->fx_done);
19484 if (!seg->use_rela_p)
19485 {
19486 bfd_vma insn;
19487 bfd_vma encoded_addend;
19488 bfd_vma addend_abs = abs (value);
19489
19490 /* Check that the absolute value of the addend can be
19491 expressed as an 8-bit constant plus a rotation. */
19492 encoded_addend = encode_arm_immediate (addend_abs);
19493 if (encoded_addend == (unsigned int) FAIL)
19494 as_bad_where (fixP->fx_file, fixP->fx_line,
19495 _("the offset 0x%08lX is not representable"),
495bde8e 19496 (unsigned long) addend_abs);
4962c51a
MS
19497
19498 /* Extract the instruction. */
19499 insn = md_chars_to_number (buf, INSN_SIZE);
19500
19501 /* If the addend is positive, use an ADD instruction.
19502 Otherwise use a SUB. Take care not to destroy the S bit. */
19503 insn &= 0xff1fffff;
19504 if (value < 0)
19505 insn |= 1 << 22;
19506 else
19507 insn |= 1 << 23;
19508
19509 /* Place the encoded addend into the first 12 bits of the
19510 instruction. */
19511 insn &= 0xfffff000;
19512 insn |= encoded_addend;
5f4273c7
NC
19513
19514 /* Update the instruction. */
4962c51a
MS
19515 md_number_to_chars (buf, insn, INSN_SIZE);
19516 }
19517 break;
19518
19519 case BFD_RELOC_ARM_LDR_PC_G0:
19520 case BFD_RELOC_ARM_LDR_PC_G1:
19521 case BFD_RELOC_ARM_LDR_PC_G2:
19522 case BFD_RELOC_ARM_LDR_SB_G0:
19523 case BFD_RELOC_ARM_LDR_SB_G1:
19524 case BFD_RELOC_ARM_LDR_SB_G2:
19525 assert (!fixP->fx_done);
19526 if (!seg->use_rela_p)
19527 {
19528 bfd_vma insn;
19529 bfd_vma addend_abs = abs (value);
19530
19531 /* Check that the absolute value of the addend can be
19532 encoded in 12 bits. */
19533 if (addend_abs >= 0x1000)
19534 as_bad_where (fixP->fx_file, fixP->fx_line,
19535 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 19536 (unsigned long) addend_abs);
4962c51a
MS
19537
19538 /* Extract the instruction. */
19539 insn = md_chars_to_number (buf, INSN_SIZE);
19540
19541 /* If the addend is negative, clear bit 23 of the instruction.
19542 Otherwise set it. */
19543 if (value < 0)
19544 insn &= ~(1 << 23);
19545 else
19546 insn |= 1 << 23;
19547
19548 /* Place the absolute value of the addend into the first 12 bits
19549 of the instruction. */
19550 insn &= 0xfffff000;
19551 insn |= addend_abs;
5f4273c7
NC
19552
19553 /* Update the instruction. */
4962c51a
MS
19554 md_number_to_chars (buf, insn, INSN_SIZE);
19555 }
19556 break;
19557
19558 case BFD_RELOC_ARM_LDRS_PC_G0:
19559 case BFD_RELOC_ARM_LDRS_PC_G1:
19560 case BFD_RELOC_ARM_LDRS_PC_G2:
19561 case BFD_RELOC_ARM_LDRS_SB_G0:
19562 case BFD_RELOC_ARM_LDRS_SB_G1:
19563 case BFD_RELOC_ARM_LDRS_SB_G2:
19564 assert (!fixP->fx_done);
19565 if (!seg->use_rela_p)
19566 {
19567 bfd_vma insn;
19568 bfd_vma addend_abs = abs (value);
19569
19570 /* Check that the absolute value of the addend can be
19571 encoded in 8 bits. */
19572 if (addend_abs >= 0x100)
19573 as_bad_where (fixP->fx_file, fixP->fx_line,
19574 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 19575 (unsigned long) addend_abs);
4962c51a
MS
19576
19577 /* Extract the instruction. */
19578 insn = md_chars_to_number (buf, INSN_SIZE);
19579
19580 /* If the addend is negative, clear bit 23 of the instruction.
19581 Otherwise set it. */
19582 if (value < 0)
19583 insn &= ~(1 << 23);
19584 else
19585 insn |= 1 << 23;
19586
19587 /* Place the first four bits of the absolute value of the addend
19588 into the first 4 bits of the instruction, and the remaining
19589 four into bits 8 .. 11. */
19590 insn &= 0xfffff0f0;
19591 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
19592
19593 /* Update the instruction. */
4962c51a
MS
19594 md_number_to_chars (buf, insn, INSN_SIZE);
19595 }
19596 break;
19597
19598 case BFD_RELOC_ARM_LDC_PC_G0:
19599 case BFD_RELOC_ARM_LDC_PC_G1:
19600 case BFD_RELOC_ARM_LDC_PC_G2:
19601 case BFD_RELOC_ARM_LDC_SB_G0:
19602 case BFD_RELOC_ARM_LDC_SB_G1:
19603 case BFD_RELOC_ARM_LDC_SB_G2:
19604 assert (!fixP->fx_done);
19605 if (!seg->use_rela_p)
19606 {
19607 bfd_vma insn;
19608 bfd_vma addend_abs = abs (value);
19609
19610 /* Check that the absolute value of the addend is a multiple of
19611 four and, when divided by four, fits in 8 bits. */
19612 if (addend_abs & 0x3)
19613 as_bad_where (fixP->fx_file, fixP->fx_line,
19614 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 19615 (unsigned long) addend_abs);
4962c51a
MS
19616
19617 if ((addend_abs >> 2) > 0xff)
19618 as_bad_where (fixP->fx_file, fixP->fx_line,
19619 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 19620 (unsigned long) addend_abs);
4962c51a
MS
19621
19622 /* Extract the instruction. */
19623 insn = md_chars_to_number (buf, INSN_SIZE);
19624
19625 /* If the addend is negative, clear bit 23 of the instruction.
19626 Otherwise set it. */
19627 if (value < 0)
19628 insn &= ~(1 << 23);
19629 else
19630 insn |= 1 << 23;
19631
19632 /* Place the addend (divided by four) into the first eight
19633 bits of the instruction. */
19634 insn &= 0xfffffff0;
19635 insn |= addend_abs >> 2;
5f4273c7
NC
19636
19637 /* Update the instruction. */
4962c51a
MS
19638 md_number_to_chars (buf, insn, INSN_SIZE);
19639 }
19640 break;
19641
845b51d6
PB
19642 case BFD_RELOC_ARM_V4BX:
19643 /* This will need to go in the object file. */
19644 fixP->fx_done = 0;
19645 break;
19646
c19d1205
ZW
19647 case BFD_RELOC_UNUSED:
19648 default:
19649 as_bad_where (fixP->fx_file, fixP->fx_line,
19650 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19651 }
6c43fab6
RE
19652}
19653
c19d1205
ZW
19654/* Translate internal representation of relocation info to BFD target
19655 format. */
a737bd4d 19656
c19d1205 19657arelent *
00a97672 19658tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19659{
c19d1205
ZW
19660 arelent * reloc;
19661 bfd_reloc_code_real_type code;
a737bd4d 19662
c19d1205 19663 reloc = xmalloc (sizeof (arelent));
a737bd4d 19664
c19d1205
ZW
19665 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19666 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19667 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19668
2fc8bdac 19669 if (fixp->fx_pcrel)
00a97672
RS
19670 {
19671 if (section->use_rela_p)
19672 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19673 else
19674 fixp->fx_offset = reloc->address;
19675 }
c19d1205 19676 reloc->addend = fixp->fx_offset;
a737bd4d 19677
c19d1205 19678 switch (fixp->fx_r_type)
a737bd4d 19679 {
c19d1205
ZW
19680 case BFD_RELOC_8:
19681 if (fixp->fx_pcrel)
19682 {
19683 code = BFD_RELOC_8_PCREL;
19684 break;
19685 }
a737bd4d 19686
c19d1205
ZW
19687 case BFD_RELOC_16:
19688 if (fixp->fx_pcrel)
19689 {
19690 code = BFD_RELOC_16_PCREL;
19691 break;
19692 }
6c43fab6 19693
c19d1205
ZW
19694 case BFD_RELOC_32:
19695 if (fixp->fx_pcrel)
19696 {
19697 code = BFD_RELOC_32_PCREL;
19698 break;
19699 }
a737bd4d 19700
b6895b4f
PB
19701 case BFD_RELOC_ARM_MOVW:
19702 if (fixp->fx_pcrel)
19703 {
19704 code = BFD_RELOC_ARM_MOVW_PCREL;
19705 break;
19706 }
19707
19708 case BFD_RELOC_ARM_MOVT:
19709 if (fixp->fx_pcrel)
19710 {
19711 code = BFD_RELOC_ARM_MOVT_PCREL;
19712 break;
19713 }
19714
19715 case BFD_RELOC_ARM_THUMB_MOVW:
19716 if (fixp->fx_pcrel)
19717 {
19718 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19719 break;
19720 }
19721
19722 case BFD_RELOC_ARM_THUMB_MOVT:
19723 if (fixp->fx_pcrel)
19724 {
19725 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19726 break;
19727 }
19728
c19d1205
ZW
19729 case BFD_RELOC_NONE:
19730 case BFD_RELOC_ARM_PCREL_BRANCH:
19731 case BFD_RELOC_ARM_PCREL_BLX:
19732 case BFD_RELOC_RVA:
19733 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19734 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19735 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19736 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19737 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19738 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
19739 case BFD_RELOC_VTABLE_ENTRY:
19740 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19741#ifdef TE_PE
19742 case BFD_RELOC_32_SECREL:
19743#endif
c19d1205
ZW
19744 code = fixp->fx_r_type;
19745 break;
a737bd4d 19746
00adf2d4
JB
19747 case BFD_RELOC_THUMB_PCREL_BLX:
19748#ifdef OBJ_ELF
19749 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
19750 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
19751 else
19752#endif
19753 code = BFD_RELOC_THUMB_PCREL_BLX;
19754 break;
19755
c19d1205
ZW
19756 case BFD_RELOC_ARM_LITERAL:
19757 case BFD_RELOC_ARM_HWLITERAL:
19758 /* If this is called then the a literal has
19759 been referenced across a section boundary. */
19760 as_bad_where (fixp->fx_file, fixp->fx_line,
19761 _("literal referenced across section boundary"));
19762 return NULL;
a737bd4d 19763
c19d1205
ZW
19764#ifdef OBJ_ELF
19765 case BFD_RELOC_ARM_GOT32:
19766 case BFD_RELOC_ARM_GOTOFF:
19767 case BFD_RELOC_ARM_PLT32:
19768 case BFD_RELOC_ARM_TARGET1:
19769 case BFD_RELOC_ARM_ROSEGREL32:
19770 case BFD_RELOC_ARM_SBREL32:
19771 case BFD_RELOC_ARM_PREL31:
19772 case BFD_RELOC_ARM_TARGET2:
19773 case BFD_RELOC_ARM_TLS_LE32:
19774 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19775 case BFD_RELOC_ARM_PCREL_CALL:
19776 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19777 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19778 case BFD_RELOC_ARM_ALU_PC_G0:
19779 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19780 case BFD_RELOC_ARM_ALU_PC_G1:
19781 case BFD_RELOC_ARM_ALU_PC_G2:
19782 case BFD_RELOC_ARM_LDR_PC_G0:
19783 case BFD_RELOC_ARM_LDR_PC_G1:
19784 case BFD_RELOC_ARM_LDR_PC_G2:
19785 case BFD_RELOC_ARM_LDRS_PC_G0:
19786 case BFD_RELOC_ARM_LDRS_PC_G1:
19787 case BFD_RELOC_ARM_LDRS_PC_G2:
19788 case BFD_RELOC_ARM_LDC_PC_G0:
19789 case BFD_RELOC_ARM_LDC_PC_G1:
19790 case BFD_RELOC_ARM_LDC_PC_G2:
19791 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19792 case BFD_RELOC_ARM_ALU_SB_G0:
19793 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19794 case BFD_RELOC_ARM_ALU_SB_G1:
19795 case BFD_RELOC_ARM_ALU_SB_G2:
19796 case BFD_RELOC_ARM_LDR_SB_G0:
19797 case BFD_RELOC_ARM_LDR_SB_G1:
19798 case BFD_RELOC_ARM_LDR_SB_G2:
19799 case BFD_RELOC_ARM_LDRS_SB_G0:
19800 case BFD_RELOC_ARM_LDRS_SB_G1:
19801 case BFD_RELOC_ARM_LDRS_SB_G2:
19802 case BFD_RELOC_ARM_LDC_SB_G0:
19803 case BFD_RELOC_ARM_LDC_SB_G1:
19804 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19805 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19806 code = fixp->fx_r_type;
19807 break;
a737bd4d 19808
c19d1205
ZW
19809 case BFD_RELOC_ARM_TLS_GD32:
19810 case BFD_RELOC_ARM_TLS_IE32:
19811 case BFD_RELOC_ARM_TLS_LDM32:
19812 /* BFD will include the symbol's address in the addend.
19813 But we don't want that, so subtract it out again here. */
19814 if (!S_IS_COMMON (fixp->fx_addsy))
19815 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19816 code = fixp->fx_r_type;
19817 break;
19818#endif
a737bd4d 19819
c19d1205
ZW
19820 case BFD_RELOC_ARM_IMMEDIATE:
19821 as_bad_where (fixp->fx_file, fixp->fx_line,
19822 _("internal relocation (type: IMMEDIATE) not fixed up"));
19823 return NULL;
a737bd4d 19824
c19d1205
ZW
19825 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19826 as_bad_where (fixp->fx_file, fixp->fx_line,
19827 _("ADRL used for a symbol not defined in the same file"));
19828 return NULL;
a737bd4d 19829
c19d1205 19830 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19831 if (section->use_rela_p)
19832 {
19833 code = fixp->fx_r_type;
19834 break;
19835 }
19836
c19d1205
ZW
19837 if (fixp->fx_addsy != NULL
19838 && !S_IS_DEFINED (fixp->fx_addsy)
19839 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19840 {
c19d1205
ZW
19841 as_bad_where (fixp->fx_file, fixp->fx_line,
19842 _("undefined local label `%s'"),
19843 S_GET_NAME (fixp->fx_addsy));
19844 return NULL;
a737bd4d
NC
19845 }
19846
c19d1205
ZW
19847 as_bad_where (fixp->fx_file, fixp->fx_line,
19848 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19849 return NULL;
a737bd4d 19850
c19d1205
ZW
19851 default:
19852 {
19853 char * type;
6c43fab6 19854
c19d1205
ZW
19855 switch (fixp->fx_r_type)
19856 {
19857 case BFD_RELOC_NONE: type = "NONE"; break;
19858 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19859 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19860 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19861 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19862 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19863 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19864 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19865 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19866 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19867 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19868 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19869 default: type = _("<unknown>"); break;
19870 }
19871 as_bad_where (fixp->fx_file, fixp->fx_line,
19872 _("cannot represent %s relocation in this object file format"),
19873 type);
19874 return NULL;
19875 }
a737bd4d 19876 }
6c43fab6 19877
c19d1205
ZW
19878#ifdef OBJ_ELF
19879 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19880 && GOT_symbol
19881 && fixp->fx_addsy == GOT_symbol)
19882 {
19883 code = BFD_RELOC_ARM_GOTPC;
19884 reloc->addend = fixp->fx_offset = reloc->address;
19885 }
19886#endif
6c43fab6 19887
c19d1205 19888 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19889
c19d1205
ZW
19890 if (reloc->howto == NULL)
19891 {
19892 as_bad_where (fixp->fx_file, fixp->fx_line,
19893 _("cannot represent %s relocation in this object file format"),
19894 bfd_get_reloc_code_name (code));
19895 return NULL;
19896 }
6c43fab6 19897
c19d1205
ZW
19898 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19899 vtable entry to be used in the relocation's section offset. */
19900 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19901 reloc->address = fixp->fx_offset;
6c43fab6 19902
c19d1205 19903 return reloc;
6c43fab6
RE
19904}
19905
c19d1205 19906/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19907
c19d1205
ZW
19908void
19909cons_fix_new_arm (fragS * frag,
19910 int where,
19911 int size,
19912 expressionS * exp)
6c43fab6 19913{
c19d1205
ZW
19914 bfd_reloc_code_real_type type;
19915 int pcrel = 0;
6c43fab6 19916
c19d1205
ZW
19917 /* Pick a reloc.
19918 FIXME: @@ Should look at CPU word size. */
19919 switch (size)
19920 {
19921 case 1:
19922 type = BFD_RELOC_8;
19923 break;
19924 case 2:
19925 type = BFD_RELOC_16;
19926 break;
19927 case 4:
19928 default:
19929 type = BFD_RELOC_32;
19930 break;
19931 case 8:
19932 type = BFD_RELOC_64;
19933 break;
19934 }
6c43fab6 19935
f0927246
NC
19936#ifdef TE_PE
19937 if (exp->X_op == O_secrel)
19938 {
19939 exp->X_op = O_symbol;
19940 type = BFD_RELOC_32_SECREL;
19941 }
19942#endif
19943
c19d1205
ZW
19944 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19945}
6c43fab6 19946
4343666d 19947#if defined (OBJ_COFF)
c19d1205
ZW
19948void
19949arm_validate_fix (fixS * fixP)
6c43fab6 19950{
c19d1205
ZW
19951 /* If the destination of the branch is a defined symbol which does not have
19952 the THUMB_FUNC attribute, then we must be calling a function which has
19953 the (interfacearm) attribute. We look for the Thumb entry point to that
19954 function and change the branch to refer to that function instead. */
19955 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19956 && fixP->fx_addsy != NULL
19957 && S_IS_DEFINED (fixP->fx_addsy)
19958 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19959 {
c19d1205 19960 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19961 }
c19d1205
ZW
19962}
19963#endif
6c43fab6 19964
c19d1205
ZW
19965int
19966arm_force_relocation (struct fix * fixp)
19967{
19968#if defined (OBJ_COFF) && defined (TE_PE)
19969 if (fixp->fx_r_type == BFD_RELOC_RVA)
19970 return 1;
19971#endif
6c43fab6 19972
c19d1205
ZW
19973 /* Resolve these relocations even if the symbol is extern or weak. */
19974 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19975 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19976 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19977 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19978 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19979 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19980 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19981 return 0;
a737bd4d 19982
4962c51a
MS
19983 /* Always leave these relocations for the linker. */
19984 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19985 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19986 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19987 return 1;
19988
f0291e4c
PB
19989 /* Always generate relocations against function symbols. */
19990 if (fixp->fx_r_type == BFD_RELOC_32
19991 && fixp->fx_addsy
19992 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19993 return 1;
19994
c19d1205 19995 return generic_force_reloc (fixp);
404ff6b5
AH
19996}
19997
0ffdc86c 19998#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19999/* Relocations against function names must be left unadjusted,
20000 so that the linker can use this information to generate interworking
20001 stubs. The MIPS version of this function
c19d1205
ZW
20002 also prevents relocations that are mips-16 specific, but I do not
20003 know why it does this.
404ff6b5 20004
c19d1205
ZW
20005 FIXME:
20006 There is one other problem that ought to be addressed here, but
20007 which currently is not: Taking the address of a label (rather
20008 than a function) and then later jumping to that address. Such
20009 addresses also ought to have their bottom bit set (assuming that
20010 they reside in Thumb code), but at the moment they will not. */
404ff6b5 20011
c19d1205
ZW
20012bfd_boolean
20013arm_fix_adjustable (fixS * fixP)
404ff6b5 20014{
c19d1205
ZW
20015 if (fixP->fx_addsy == NULL)
20016 return 1;
404ff6b5 20017
e28387c3
PB
20018 /* Preserve relocations against symbols with function type. */
20019 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20020 return 0;
20021
c19d1205
ZW
20022 if (THUMB_IS_FUNC (fixP->fx_addsy)
20023 && fixP->fx_subsy == NULL)
20024 return 0;
a737bd4d 20025
c19d1205
ZW
20026 /* We need the symbol name for the VTABLE entries. */
20027 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20028 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20029 return 0;
404ff6b5 20030
c19d1205
ZW
20031 /* Don't allow symbols to be discarded on GOT related relocs. */
20032 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20033 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20034 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20035 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20036 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20037 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20038 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20039 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20040 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20041 return 0;
a737bd4d 20042
4962c51a
MS
20043 /* Similarly for group relocations. */
20044 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20045 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20046 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20047 return 0;
20048
79947c54
CD
20049 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20050 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20051 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20052 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20053 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20054 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20055 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20056 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20057 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20058 return 0;
20059
c19d1205 20060 return 1;
a737bd4d 20061}
0ffdc86c
NC
20062#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20063
20064#ifdef OBJ_ELF
404ff6b5 20065
c19d1205
ZW
20066const char *
20067elf32_arm_target_format (void)
404ff6b5 20068{
c19d1205
ZW
20069#ifdef TE_SYMBIAN
20070 return (target_big_endian
20071 ? "elf32-bigarm-symbian"
20072 : "elf32-littlearm-symbian");
20073#elif defined (TE_VXWORKS)
20074 return (target_big_endian
20075 ? "elf32-bigarm-vxworks"
20076 : "elf32-littlearm-vxworks");
20077#else
20078 if (target_big_endian)
20079 return "elf32-bigarm";
20080 else
20081 return "elf32-littlearm";
20082#endif
404ff6b5
AH
20083}
20084
c19d1205
ZW
20085void
20086armelf_frob_symbol (symbolS * symp,
20087 int * puntp)
404ff6b5 20088{
c19d1205
ZW
20089 elf_frob_symbol (symp, puntp);
20090}
20091#endif
404ff6b5 20092
c19d1205 20093/* MD interface: Finalization. */
a737bd4d 20094
c19d1205
ZW
20095/* A good place to do this, although this was probably not intended
20096 for this kind of use. We need to dump the literal pool before
20097 references are made to a null symbol pointer. */
a737bd4d 20098
c19d1205
ZW
20099void
20100arm_cleanup (void)
20101{
20102 literal_pool * pool;
a737bd4d 20103
c19d1205
ZW
20104 for (pool = list_of_pools; pool; pool = pool->next)
20105 {
5f4273c7 20106 /* Put it at the end of the relevant section. */
c19d1205
ZW
20107 subseg_set (pool->section, pool->sub_section);
20108#ifdef OBJ_ELF
20109 arm_elf_change_section ();
20110#endif
20111 s_ltorg (0);
20112 }
404ff6b5
AH
20113}
20114
c19d1205
ZW
20115/* Adjust the symbol table. This marks Thumb symbols as distinct from
20116 ARM ones. */
404ff6b5 20117
c19d1205
ZW
20118void
20119arm_adjust_symtab (void)
404ff6b5 20120{
c19d1205
ZW
20121#ifdef OBJ_COFF
20122 symbolS * sym;
404ff6b5 20123
c19d1205
ZW
20124 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20125 {
20126 if (ARM_IS_THUMB (sym))
20127 {
20128 if (THUMB_IS_FUNC (sym))
20129 {
20130 /* Mark the symbol as a Thumb function. */
20131 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20132 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20133 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 20134
c19d1205
ZW
20135 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20136 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20137 else
20138 as_bad (_("%s: unexpected function type: %d"),
20139 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20140 }
20141 else switch (S_GET_STORAGE_CLASS (sym))
20142 {
20143 case C_EXT:
20144 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20145 break;
20146 case C_STAT:
20147 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20148 break;
20149 case C_LABEL:
20150 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20151 break;
20152 default:
20153 /* Do nothing. */
20154 break;
20155 }
20156 }
a737bd4d 20157
c19d1205
ZW
20158 if (ARM_IS_INTERWORK (sym))
20159 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 20160 }
c19d1205
ZW
20161#endif
20162#ifdef OBJ_ELF
20163 symbolS * sym;
20164 char bind;
404ff6b5 20165
c19d1205 20166 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 20167 {
c19d1205
ZW
20168 if (ARM_IS_THUMB (sym))
20169 {
20170 elf_symbol_type * elf_sym;
404ff6b5 20171
c19d1205
ZW
20172 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20173 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 20174
b0796911
PB
20175 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20176 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
20177 {
20178 /* If it's a .thumb_func, declare it as so,
20179 otherwise tag label as .code 16. */
20180 if (THUMB_IS_FUNC (sym))
20181 elf_sym->internal_elf_sym.st_info =
20182 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 20183 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
20184 elf_sym->internal_elf_sym.st_info =
20185 ELF_ST_INFO (bind, STT_ARM_16BIT);
20186 }
20187 }
20188 }
20189#endif
404ff6b5
AH
20190}
20191
c19d1205 20192/* MD interface: Initialization. */
404ff6b5 20193
a737bd4d 20194static void
c19d1205 20195set_constant_flonums (void)
a737bd4d 20196{
c19d1205 20197 int i;
404ff6b5 20198
c19d1205
ZW
20199 for (i = 0; i < NUM_FLOAT_VALS; i++)
20200 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20201 abort ();
a737bd4d 20202}
404ff6b5 20203
3e9e4fcf
JB
20204/* Auto-select Thumb mode if it's the only available instruction set for the
20205 given architecture. */
20206
20207static void
20208autoselect_thumb_from_cpu_variant (void)
20209{
20210 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20211 opcode_select (16);
20212}
20213
c19d1205
ZW
20214void
20215md_begin (void)
a737bd4d 20216{
c19d1205
ZW
20217 unsigned mach;
20218 unsigned int i;
404ff6b5 20219
c19d1205
ZW
20220 if ( (arm_ops_hsh = hash_new ()) == NULL
20221 || (arm_cond_hsh = hash_new ()) == NULL
20222 || (arm_shift_hsh = hash_new ()) == NULL
20223 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 20224 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 20225 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
20226 || (arm_reloc_hsh = hash_new ()) == NULL
20227 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
20228 as_fatal (_("virtual memory exhausted"));
20229
20230 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
5a49b8ac 20231 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
c19d1205 20232 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
5a49b8ac 20233 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
c19d1205 20234 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 20235 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 20236 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20237 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
62b3e311 20238 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20239 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
c19d1205 20240 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 20241 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
20242 for (i = 0;
20243 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20244 i++)
20245 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
5a49b8ac 20246 (void *) (barrier_opt_names + i));
c19d1205
ZW
20247#ifdef OBJ_ELF
20248 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 20249 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
20250#endif
20251
20252 set_constant_flonums ();
404ff6b5 20253
c19d1205
ZW
20254 /* Set the cpu variant based on the command-line options. We prefer
20255 -mcpu= over -march= if both are set (as for GCC); and we prefer
20256 -mfpu= over any other way of setting the floating point unit.
20257 Use of legacy options with new options are faulted. */
e74cfd16 20258 if (legacy_cpu)
404ff6b5 20259 {
e74cfd16 20260 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
20261 as_bad (_("use of old and new-style options to set CPU type"));
20262
20263 mcpu_cpu_opt = legacy_cpu;
404ff6b5 20264 }
e74cfd16 20265 else if (!mcpu_cpu_opt)
c19d1205 20266 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 20267
e74cfd16 20268 if (legacy_fpu)
c19d1205 20269 {
e74cfd16 20270 if (mfpu_opt)
c19d1205 20271 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
20272
20273 mfpu_opt = legacy_fpu;
20274 }
e74cfd16 20275 else if (!mfpu_opt)
03b1477f 20276 {
c19d1205 20277#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
20278 /* Some environments specify a default FPU. If they don't, infer it
20279 from the processor. */
e74cfd16 20280 if (mcpu_fpu_opt)
03b1477f
RE
20281 mfpu_opt = mcpu_fpu_opt;
20282 else
20283 mfpu_opt = march_fpu_opt;
39c2da32 20284#else
e74cfd16 20285 mfpu_opt = &fpu_default;
39c2da32 20286#endif
03b1477f
RE
20287 }
20288
e74cfd16 20289 if (!mfpu_opt)
03b1477f 20290 {
493cb6ef 20291 if (mcpu_cpu_opt != NULL)
e74cfd16 20292 mfpu_opt = &fpu_default;
493cb6ef 20293 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 20294 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 20295 else
e74cfd16 20296 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
20297 }
20298
ee065d83 20299#ifdef CPU_DEFAULT
e74cfd16 20300 if (!mcpu_cpu_opt)
ee065d83 20301 {
e74cfd16
PB
20302 mcpu_cpu_opt = &cpu_default;
20303 selected_cpu = cpu_default;
ee065d83 20304 }
e74cfd16
PB
20305#else
20306 if (mcpu_cpu_opt)
20307 selected_cpu = *mcpu_cpu_opt;
ee065d83 20308 else
e74cfd16 20309 mcpu_cpu_opt = &arm_arch_any;
ee065d83 20310#endif
03b1477f 20311
e74cfd16 20312 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 20313
3e9e4fcf
JB
20314 autoselect_thumb_from_cpu_variant ();
20315
e74cfd16 20316 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 20317
f17c130b 20318#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 20319 {
7cc69913
NC
20320 unsigned int flags = 0;
20321
20322#if defined OBJ_ELF
20323 flags = meabi_flags;
d507cf36
PB
20324
20325 switch (meabi_flags)
33a392fb 20326 {
d507cf36 20327 case EF_ARM_EABI_UNKNOWN:
7cc69913 20328#endif
d507cf36
PB
20329 /* Set the flags in the private structure. */
20330 if (uses_apcs_26) flags |= F_APCS26;
20331 if (support_interwork) flags |= F_INTERWORK;
20332 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 20333 if (pic_code) flags |= F_PIC;
e74cfd16 20334 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
20335 flags |= F_SOFT_FLOAT;
20336
d507cf36
PB
20337 switch (mfloat_abi_opt)
20338 {
20339 case ARM_FLOAT_ABI_SOFT:
20340 case ARM_FLOAT_ABI_SOFTFP:
20341 flags |= F_SOFT_FLOAT;
20342 break;
33a392fb 20343
d507cf36
PB
20344 case ARM_FLOAT_ABI_HARD:
20345 if (flags & F_SOFT_FLOAT)
20346 as_bad (_("hard-float conflicts with specified fpu"));
20347 break;
20348 }
03b1477f 20349
e74cfd16
PB
20350 /* Using pure-endian doubles (even if soft-float). */
20351 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 20352 flags |= F_VFP_FLOAT;
f17c130b 20353
fde78edd 20354#if defined OBJ_ELF
e74cfd16 20355 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 20356 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
20357 break;
20358
8cb51566 20359 case EF_ARM_EABI_VER4:
3a4a14e9 20360 case EF_ARM_EABI_VER5:
c19d1205 20361 /* No additional flags to set. */
d507cf36
PB
20362 break;
20363
20364 default:
20365 abort ();
20366 }
7cc69913 20367#endif
b99bd4ef
NC
20368 bfd_set_private_flags (stdoutput, flags);
20369
20370 /* We have run out flags in the COFF header to encode the
20371 status of ATPCS support, so instead we create a dummy,
c19d1205 20372 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
20373 if (atpcs)
20374 {
20375 asection * sec;
20376
20377 sec = bfd_make_section (stdoutput, ".arm.atpcs");
20378
20379 if (sec != NULL)
20380 {
20381 bfd_set_section_flags
20382 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
20383 bfd_set_section_size (stdoutput, sec, 0);
20384 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
20385 }
20386 }
7cc69913 20387 }
f17c130b 20388#endif
b99bd4ef
NC
20389
20390 /* Record the CPU type as well. */
2d447fca
JM
20391 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
20392 mach = bfd_mach_arm_iWMMXt2;
20393 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 20394 mach = bfd_mach_arm_iWMMXt;
e74cfd16 20395 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 20396 mach = bfd_mach_arm_XScale;
e74cfd16 20397 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 20398 mach = bfd_mach_arm_ep9312;
e74cfd16 20399 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 20400 mach = bfd_mach_arm_5TE;
e74cfd16 20401 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 20402 {
e74cfd16 20403 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
20404 mach = bfd_mach_arm_5T;
20405 else
20406 mach = bfd_mach_arm_5;
20407 }
e74cfd16 20408 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 20409 {
e74cfd16 20410 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
20411 mach = bfd_mach_arm_4T;
20412 else
20413 mach = bfd_mach_arm_4;
20414 }
e74cfd16 20415 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 20416 mach = bfd_mach_arm_3M;
e74cfd16
PB
20417 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
20418 mach = bfd_mach_arm_3;
20419 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
20420 mach = bfd_mach_arm_2a;
20421 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
20422 mach = bfd_mach_arm_2;
20423 else
20424 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
20425
20426 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
20427}
20428
c19d1205 20429/* Command line processing. */
b99bd4ef 20430
c19d1205
ZW
20431/* md_parse_option
20432 Invocation line includes a switch not recognized by the base assembler.
20433 See if it's a processor-specific option.
b99bd4ef 20434
c19d1205
ZW
20435 This routine is somewhat complicated by the need for backwards
20436 compatibility (since older releases of gcc can't be changed).
20437 The new options try to make the interface as compatible as
20438 possible with GCC.
b99bd4ef 20439
c19d1205 20440 New options (supported) are:
b99bd4ef 20441
c19d1205
ZW
20442 -mcpu=<cpu name> Assemble for selected processor
20443 -march=<architecture name> Assemble for selected architecture
20444 -mfpu=<fpu architecture> Assemble for selected FPU.
20445 -EB/-mbig-endian Big-endian
20446 -EL/-mlittle-endian Little-endian
20447 -k Generate PIC code
20448 -mthumb Start in Thumb mode
20449 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 20450
278df34e
NS
20451 -m[no-]warn-deprecated Warn about deprecated features
20452
c19d1205 20453 For now we will also provide support for:
b99bd4ef 20454
c19d1205
ZW
20455 -mapcs-32 32-bit Program counter
20456 -mapcs-26 26-bit Program counter
20457 -macps-float Floats passed in FP registers
20458 -mapcs-reentrant Reentrant code
20459 -matpcs
20460 (sometime these will probably be replaced with -mapcs=<list of options>
20461 and -matpcs=<list of options>)
b99bd4ef 20462
c19d1205
ZW
20463 The remaining options are only supported for back-wards compatibility.
20464 Cpu variants, the arm part is optional:
20465 -m[arm]1 Currently not supported.
20466 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
20467 -m[arm]3 Arm 3 processor
20468 -m[arm]6[xx], Arm 6 processors
20469 -m[arm]7[xx][t][[d]m] Arm 7 processors
20470 -m[arm]8[10] Arm 8 processors
20471 -m[arm]9[20][tdmi] Arm 9 processors
20472 -mstrongarm[110[0]] StrongARM processors
20473 -mxscale XScale processors
20474 -m[arm]v[2345[t[e]]] Arm architectures
20475 -mall All (except the ARM1)
20476 FP variants:
20477 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
20478 -mfpe-old (No float load/store multiples)
20479 -mvfpxd VFP Single precision
20480 -mvfp All VFP
20481 -mno-fpu Disable all floating point instructions
b99bd4ef 20482
c19d1205
ZW
20483 The following CPU names are recognized:
20484 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
20485 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
20486 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
20487 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
20488 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
20489 arm10t arm10e, arm1020t, arm1020e, arm10200e,
20490 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 20491
c19d1205 20492 */
b99bd4ef 20493
c19d1205 20494const char * md_shortopts = "m:k";
b99bd4ef 20495
c19d1205
ZW
20496#ifdef ARM_BI_ENDIAN
20497#define OPTION_EB (OPTION_MD_BASE + 0)
20498#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 20499#else
c19d1205
ZW
20500#if TARGET_BYTES_BIG_ENDIAN
20501#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 20502#else
c19d1205
ZW
20503#define OPTION_EL (OPTION_MD_BASE + 1)
20504#endif
b99bd4ef 20505#endif
845b51d6 20506#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 20507
c19d1205 20508struct option md_longopts[] =
b99bd4ef 20509{
c19d1205
ZW
20510#ifdef OPTION_EB
20511 {"EB", no_argument, NULL, OPTION_EB},
20512#endif
20513#ifdef OPTION_EL
20514 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 20515#endif
845b51d6 20516 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
20517 {NULL, no_argument, NULL, 0}
20518};
b99bd4ef 20519
c19d1205 20520size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 20521
c19d1205 20522struct arm_option_table
b99bd4ef 20523{
c19d1205
ZW
20524 char *option; /* Option name to match. */
20525 char *help; /* Help information. */
20526 int *var; /* Variable to change. */
20527 int value; /* What to change it to. */
20528 char *deprecated; /* If non-null, print this message. */
20529};
b99bd4ef 20530
c19d1205
ZW
20531struct arm_option_table arm_opts[] =
20532{
20533 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
20534 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
20535 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
20536 &support_interwork, 1, NULL},
20537 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
20538 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
20539 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
20540 1, NULL},
20541 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
20542 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
20543 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
20544 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
20545 NULL},
b99bd4ef 20546
c19d1205
ZW
20547 /* These are recognized by the assembler, but have no affect on code. */
20548 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
20549 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
20550
20551 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
20552 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
20553 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
20554 {NULL, NULL, NULL, 0, NULL}
20555};
20556
20557struct arm_legacy_option_table
20558{
20559 char *option; /* Option name to match. */
20560 const arm_feature_set **var; /* Variable to change. */
20561 const arm_feature_set value; /* What to change it to. */
20562 char *deprecated; /* If non-null, print this message. */
20563};
b99bd4ef 20564
e74cfd16
PB
20565const struct arm_legacy_option_table arm_legacy_opts[] =
20566{
c19d1205
ZW
20567 /* DON'T add any new processors to this list -- we want the whole list
20568 to go away... Add them to the processors table instead. */
e74cfd16
PB
20569 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20570 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20571 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20572 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20573 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20574 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20575 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20576 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20577 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20578 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20579 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20580 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20581 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20582 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20583 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20584 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20585 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20586 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20587 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20588 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20589 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20590 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20591 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20592 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20593 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20594 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20595 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20596 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20597 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20598 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20599 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20600 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20601 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20602 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20603 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20604 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20605 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20606 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20607 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20608 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20609 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20610 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20611 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20612 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20613 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20614 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20615 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20616 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20617 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20618 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20619 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20620 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20621 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20622 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20623 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20624 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20625 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20626 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20627 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20628 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20629 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20630 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20631 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20632 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20633 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20634 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20635 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20636 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20637 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
20638 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20639 N_("use -mcpu=strongarm110")},
e74cfd16 20640 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20641 N_("use -mcpu=strongarm1100")},
e74cfd16 20642 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20643 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
20644 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20645 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20646 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 20647
c19d1205 20648 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
20649 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20650 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20651 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20652 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20653 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20654 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20655 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20656 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20657 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20658 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20659 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20660 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20661 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20662 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20663 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20664 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20665 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20666 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20667
c19d1205 20668 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20669 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20670 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20671 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20672 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20673 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20674
e74cfd16 20675 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20676};
7ed4c4c5 20677
c19d1205 20678struct arm_cpu_option_table
7ed4c4c5 20679{
c19d1205 20680 char *name;
e74cfd16 20681 const arm_feature_set value;
c19d1205
ZW
20682 /* For some CPUs we assume an FPU unless the user explicitly sets
20683 -mfpu=... */
e74cfd16 20684 const arm_feature_set default_fpu;
ee065d83
PB
20685 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20686 case. */
20687 const char *canonical_name;
c19d1205 20688};
7ed4c4c5 20689
c19d1205
ZW
20690/* This list should, at a minimum, contain all the cpu names
20691 recognized by GCC. */
e74cfd16 20692static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20693{
ee065d83
PB
20694 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20695 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20696 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20697 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20698 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20699 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20700 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20701 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20702 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20703 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20704 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20705 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20706 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20707 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20708 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20709 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20710 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20711 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20712 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20713 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20714 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20715 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20716 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20717 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20718 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20719 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20720 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20721 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20722 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20723 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20724 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20725 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20726 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20727 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20728 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20729 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20730 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20731 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20732 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20733 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20734 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20735 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20736 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20737 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
20738 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20739 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20740 /* For V5 or later processors we default to using VFP; but the user
20741 should really set the FPU type explicitly. */
ee065d83
PB
20742 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20743 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20744 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20745 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20746 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20747 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20748 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20749 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20750 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20751 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20752 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20753 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20754 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20755 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20756 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20757 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20758 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20759 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20760 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20761 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20762 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
20763 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20764 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
20765 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20766 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20767 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20768 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20769 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20770 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20771 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20772 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20773 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20774 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20775 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20776 | FPU_NEON_EXT_V1),
15290f0a
PB
20777 NULL},
20778 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20779 | FPU_NEON_EXT_V1),
5287ad62 20780 NULL},
62b3e311
PB
20781 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20782 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20783 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 20784 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20785 /* ??? XSCALE is really an architecture. */
ee065d83 20786 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20787 /* ??? iwmmxt is not a processor. */
ee065d83 20788 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20789 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20790 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20791 /* Maverick */
e74cfd16
PB
20792 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20793 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20794};
7ed4c4c5 20795
c19d1205 20796struct arm_arch_option_table
7ed4c4c5 20797{
c19d1205 20798 char *name;
e74cfd16
PB
20799 const arm_feature_set value;
20800 const arm_feature_set default_fpu;
c19d1205 20801};
7ed4c4c5 20802
c19d1205
ZW
20803/* This list should, at a minimum, contain all the architecture names
20804 recognized by GCC. */
e74cfd16 20805static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20806{
20807 {"all", ARM_ANY, FPU_ARCH_FPA},
20808 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20809 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20810 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20811 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20812 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20813 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20814 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20815 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20816 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20817 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20818 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20819 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20820 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20821 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20822 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20823 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20824 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20825 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20826 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20827 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20828 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20829 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20830 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20831 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20832 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20833 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20834 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20835 /* The official spelling of the ARMv7 profile variants is the dashed form.
20836 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20837 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20838 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20839 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20840 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20841 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20842 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20843 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20844 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20845 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20846 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20847};
7ed4c4c5 20848
c19d1205 20849/* ISA extensions in the co-processor space. */
e74cfd16 20850struct arm_option_cpu_value_table
c19d1205
ZW
20851{
20852 char *name;
e74cfd16 20853 const arm_feature_set value;
c19d1205 20854};
7ed4c4c5 20855
e74cfd16 20856static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20857{
e74cfd16
PB
20858 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20859 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20860 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20861 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20862 {NULL, ARM_ARCH_NONE}
c19d1205 20863};
7ed4c4c5 20864
c19d1205
ZW
20865/* This list should, at a minimum, contain all the fpu names
20866 recognized by GCC. */
e74cfd16 20867static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20868{
20869 {"softfpa", FPU_NONE},
20870 {"fpe", FPU_ARCH_FPE},
20871 {"fpe2", FPU_ARCH_FPE},
20872 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20873 {"fpa", FPU_ARCH_FPA},
20874 {"fpa10", FPU_ARCH_FPA},
20875 {"fpa11", FPU_ARCH_FPA},
20876 {"arm7500fe", FPU_ARCH_FPA},
20877 {"softvfp", FPU_ARCH_VFP},
20878 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20879 {"vfp", FPU_ARCH_VFP_V2},
20880 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 20881 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
20882 {"vfp10", FPU_ARCH_VFP_V2},
20883 {"vfp10-r0", FPU_ARCH_VFP_V1},
20884 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
20885 {"vfpv2", FPU_ARCH_VFP_V2},
20886 {"vfpv3", FPU_ARCH_VFP_V3},
20887 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
20888 {"arm1020t", FPU_ARCH_VFP_V1},
20889 {"arm1020e", FPU_ARCH_VFP_V2},
20890 {"arm1136jfs", FPU_ARCH_VFP_V2},
20891 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20892 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20893 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 20894 {"neon-fp16", FPU_ARCH_NEON_FP16},
e74cfd16
PB
20895 {NULL, ARM_ARCH_NONE}
20896};
20897
20898struct arm_option_value_table
20899{
20900 char *name;
20901 long value;
c19d1205 20902};
7ed4c4c5 20903
e74cfd16 20904static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20905{
20906 {"hard", ARM_FLOAT_ABI_HARD},
20907 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20908 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20909 {NULL, 0}
c19d1205 20910};
7ed4c4c5 20911
c19d1205 20912#ifdef OBJ_ELF
3a4a14e9 20913/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20914static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20915{
20916 {"gnu", EF_ARM_EABI_UNKNOWN},
20917 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20918 {"5", EF_ARM_EABI_VER5},
e74cfd16 20919 {NULL, 0}
c19d1205
ZW
20920};
20921#endif
7ed4c4c5 20922
c19d1205
ZW
20923struct arm_long_option_table
20924{
20925 char * option; /* Substring to match. */
20926 char * help; /* Help information. */
20927 int (* func) (char * subopt); /* Function to decode sub-option. */
20928 char * deprecated; /* If non-null, print this message. */
20929};
7ed4c4c5
NC
20930
20931static int
e74cfd16 20932arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20933{
e74cfd16
PB
20934 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20935
20936 /* Copy the feature set, so that we can modify it. */
20937 *ext_set = **opt_p;
20938 *opt_p = ext_set;
20939
c19d1205 20940 while (str != NULL && *str != 0)
7ed4c4c5 20941 {
e74cfd16 20942 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20943 char * ext;
20944 int optlen;
7ed4c4c5 20945
c19d1205
ZW
20946 if (*str != '+')
20947 {
20948 as_bad (_("invalid architectural extension"));
20949 return 0;
20950 }
7ed4c4c5 20951
c19d1205
ZW
20952 str++;
20953 ext = strchr (str, '+');
7ed4c4c5 20954
c19d1205
ZW
20955 if (ext != NULL)
20956 optlen = ext - str;
20957 else
20958 optlen = strlen (str);
7ed4c4c5 20959
c19d1205
ZW
20960 if (optlen == 0)
20961 {
20962 as_bad (_("missing architectural extension"));
20963 return 0;
20964 }
7ed4c4c5 20965
c19d1205
ZW
20966 for (opt = arm_extensions; opt->name != NULL; opt++)
20967 if (strncmp (opt->name, str, optlen) == 0)
20968 {
e74cfd16 20969 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20970 break;
20971 }
7ed4c4c5 20972
c19d1205
ZW
20973 if (opt->name == NULL)
20974 {
5f4273c7 20975 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
20976 return 0;
20977 }
7ed4c4c5 20978
c19d1205
ZW
20979 str = ext;
20980 };
7ed4c4c5 20981
c19d1205
ZW
20982 return 1;
20983}
7ed4c4c5 20984
c19d1205
ZW
20985static int
20986arm_parse_cpu (char * str)
7ed4c4c5 20987{
e74cfd16 20988 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20989 char * ext = strchr (str, '+');
20990 int optlen;
7ed4c4c5 20991
c19d1205
ZW
20992 if (ext != NULL)
20993 optlen = ext - str;
7ed4c4c5 20994 else
c19d1205 20995 optlen = strlen (str);
7ed4c4c5 20996
c19d1205 20997 if (optlen == 0)
7ed4c4c5 20998 {
c19d1205
ZW
20999 as_bad (_("missing cpu name `%s'"), str);
21000 return 0;
7ed4c4c5
NC
21001 }
21002
c19d1205
ZW
21003 for (opt = arm_cpus; opt->name != NULL; opt++)
21004 if (strncmp (opt->name, str, optlen) == 0)
21005 {
e74cfd16
PB
21006 mcpu_cpu_opt = &opt->value;
21007 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 21008 if (opt->canonical_name)
5f4273c7 21009 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21010 else
21011 {
21012 int i;
21013 for (i = 0; i < optlen; i++)
21014 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21015 selected_cpu_name[i] = 0;
21016 }
7ed4c4c5 21017
c19d1205
ZW
21018 if (ext != NULL)
21019 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 21020
c19d1205
ZW
21021 return 1;
21022 }
7ed4c4c5 21023
c19d1205
ZW
21024 as_bad (_("unknown cpu `%s'"), str);
21025 return 0;
7ed4c4c5
NC
21026}
21027
c19d1205
ZW
21028static int
21029arm_parse_arch (char * str)
7ed4c4c5 21030{
e74cfd16 21031 const struct arm_arch_option_table *opt;
c19d1205
ZW
21032 char *ext = strchr (str, '+');
21033 int optlen;
7ed4c4c5 21034
c19d1205
ZW
21035 if (ext != NULL)
21036 optlen = ext - str;
7ed4c4c5 21037 else
c19d1205 21038 optlen = strlen (str);
7ed4c4c5 21039
c19d1205 21040 if (optlen == 0)
7ed4c4c5 21041 {
c19d1205
ZW
21042 as_bad (_("missing architecture name `%s'"), str);
21043 return 0;
7ed4c4c5
NC
21044 }
21045
c19d1205
ZW
21046 for (opt = arm_archs; opt->name != NULL; opt++)
21047 if (streq (opt->name, str))
21048 {
e74cfd16
PB
21049 march_cpu_opt = &opt->value;
21050 march_fpu_opt = &opt->default_fpu;
5f4273c7 21051 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 21052
c19d1205
ZW
21053 if (ext != NULL)
21054 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 21055
c19d1205
ZW
21056 return 1;
21057 }
21058
21059 as_bad (_("unknown architecture `%s'\n"), str);
21060 return 0;
7ed4c4c5 21061}
eb043451 21062
c19d1205
ZW
21063static int
21064arm_parse_fpu (char * str)
21065{
e74cfd16 21066 const struct arm_option_cpu_value_table * opt;
b99bd4ef 21067
c19d1205
ZW
21068 for (opt = arm_fpus; opt->name != NULL; opt++)
21069 if (streq (opt->name, str))
21070 {
e74cfd16 21071 mfpu_opt = &opt->value;
c19d1205
ZW
21072 return 1;
21073 }
b99bd4ef 21074
c19d1205
ZW
21075 as_bad (_("unknown floating point format `%s'\n"), str);
21076 return 0;
21077}
21078
21079static int
21080arm_parse_float_abi (char * str)
b99bd4ef 21081{
e74cfd16 21082 const struct arm_option_value_table * opt;
b99bd4ef 21083
c19d1205
ZW
21084 for (opt = arm_float_abis; opt->name != NULL; opt++)
21085 if (streq (opt->name, str))
21086 {
21087 mfloat_abi_opt = opt->value;
21088 return 1;
21089 }
cc8a6dd0 21090
c19d1205
ZW
21091 as_bad (_("unknown floating point abi `%s'\n"), str);
21092 return 0;
21093}
b99bd4ef 21094
c19d1205
ZW
21095#ifdef OBJ_ELF
21096static int
21097arm_parse_eabi (char * str)
21098{
e74cfd16 21099 const struct arm_option_value_table *opt;
cc8a6dd0 21100
c19d1205
ZW
21101 for (opt = arm_eabis; opt->name != NULL; opt++)
21102 if (streq (opt->name, str))
21103 {
21104 meabi_flags = opt->value;
21105 return 1;
21106 }
21107 as_bad (_("unknown EABI `%s'\n"), str);
21108 return 0;
21109}
21110#endif
cc8a6dd0 21111
c19d1205
ZW
21112struct arm_long_option_table arm_long_opts[] =
21113{
21114 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21115 arm_parse_cpu, NULL},
21116 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21117 arm_parse_arch, NULL},
21118 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21119 arm_parse_fpu, NULL},
21120 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21121 arm_parse_float_abi, NULL},
21122#ifdef OBJ_ELF
7fac0536 21123 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
21124 arm_parse_eabi, NULL},
21125#endif
21126 {NULL, NULL, 0, NULL}
21127};
cc8a6dd0 21128
c19d1205
ZW
21129int
21130md_parse_option (int c, char * arg)
21131{
21132 struct arm_option_table *opt;
e74cfd16 21133 const struct arm_legacy_option_table *fopt;
c19d1205 21134 struct arm_long_option_table *lopt;
b99bd4ef 21135
c19d1205 21136 switch (c)
b99bd4ef 21137 {
c19d1205
ZW
21138#ifdef OPTION_EB
21139 case OPTION_EB:
21140 target_big_endian = 1;
21141 break;
21142#endif
cc8a6dd0 21143
c19d1205
ZW
21144#ifdef OPTION_EL
21145 case OPTION_EL:
21146 target_big_endian = 0;
21147 break;
21148#endif
b99bd4ef 21149
845b51d6
PB
21150 case OPTION_FIX_V4BX:
21151 fix_v4bx = TRUE;
21152 break;
21153
c19d1205
ZW
21154 case 'a':
21155 /* Listing option. Just ignore these, we don't support additional
21156 ones. */
21157 return 0;
b99bd4ef 21158
c19d1205
ZW
21159 default:
21160 for (opt = arm_opts; opt->option != NULL; opt++)
21161 {
21162 if (c == opt->option[0]
21163 && ((arg == NULL && opt->option[1] == 0)
21164 || streq (arg, opt->option + 1)))
21165 {
c19d1205 21166 /* If the option is deprecated, tell the user. */
278df34e 21167 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
21168 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21169 arg ? arg : "", _(opt->deprecated));
b99bd4ef 21170
c19d1205
ZW
21171 if (opt->var != NULL)
21172 *opt->var = opt->value;
cc8a6dd0 21173
c19d1205
ZW
21174 return 1;
21175 }
21176 }
b99bd4ef 21177
e74cfd16
PB
21178 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21179 {
21180 if (c == fopt->option[0]
21181 && ((arg == NULL && fopt->option[1] == 0)
21182 || streq (arg, fopt->option + 1)))
21183 {
e74cfd16 21184 /* If the option is deprecated, tell the user. */
278df34e 21185 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
21186 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21187 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
21188
21189 if (fopt->var != NULL)
21190 *fopt->var = &fopt->value;
21191
21192 return 1;
21193 }
21194 }
21195
c19d1205
ZW
21196 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21197 {
21198 /* These options are expected to have an argument. */
21199 if (c == lopt->option[0]
21200 && arg != NULL
21201 && strncmp (arg, lopt->option + 1,
21202 strlen (lopt->option + 1)) == 0)
21203 {
c19d1205 21204 /* If the option is deprecated, tell the user. */
278df34e 21205 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
21206 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21207 _(lopt->deprecated));
b99bd4ef 21208
c19d1205
ZW
21209 /* Call the sup-option parser. */
21210 return lopt->func (arg + strlen (lopt->option) - 1);
21211 }
21212 }
a737bd4d 21213
c19d1205
ZW
21214 return 0;
21215 }
a394c00f 21216
c19d1205
ZW
21217 return 1;
21218}
a394c00f 21219
c19d1205
ZW
21220void
21221md_show_usage (FILE * fp)
a394c00f 21222{
c19d1205
ZW
21223 struct arm_option_table *opt;
21224 struct arm_long_option_table *lopt;
a394c00f 21225
c19d1205 21226 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 21227
c19d1205
ZW
21228 for (opt = arm_opts; opt->option != NULL; opt++)
21229 if (opt->help != NULL)
21230 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 21231
c19d1205
ZW
21232 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21233 if (lopt->help != NULL)
21234 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 21235
c19d1205
ZW
21236#ifdef OPTION_EB
21237 fprintf (fp, _("\
21238 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
21239#endif
21240
c19d1205
ZW
21241#ifdef OPTION_EL
21242 fprintf (fp, _("\
21243 -EL assemble code for a little-endian cpu\n"));
a737bd4d 21244#endif
845b51d6
PB
21245
21246 fprintf (fp, _("\
21247 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 21248}
ee065d83
PB
21249
21250
21251#ifdef OBJ_ELF
62b3e311
PB
21252typedef struct
21253{
21254 int val;
21255 arm_feature_set flags;
21256} cpu_arch_ver_table;
21257
21258/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21259 least features first. */
21260static const cpu_arch_ver_table cpu_arch_ver[] =
21261{
21262 {1, ARM_ARCH_V4},
21263 {2, ARM_ARCH_V4T},
21264 {3, ARM_ARCH_V5},
ee3c0378 21265 {3, ARM_ARCH_V5T},
62b3e311
PB
21266 {4, ARM_ARCH_V5TE},
21267 {5, ARM_ARCH_V5TEJ},
21268 {6, ARM_ARCH_V6},
21269 {7, ARM_ARCH_V6Z},
7e806470 21270 {9, ARM_ARCH_V6K},
91e22acd 21271 {11, ARM_ARCH_V6M},
7e806470 21272 {8, ARM_ARCH_V6T2},
62b3e311
PB
21273 {10, ARM_ARCH_V7A},
21274 {10, ARM_ARCH_V7R},
21275 {10, ARM_ARCH_V7M},
21276 {0, ARM_ARCH_NONE}
21277};
21278
ee3c0378
AS
21279/* Set an attribute if it has not already been set by the user. */
21280static void
21281aeabi_set_attribute_int (int tag, int value)
21282{
21283 if (tag < 1
21284 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21285 || !attributes_set_explicitly[tag])
21286 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21287}
21288
21289static void
21290aeabi_set_attribute_string (int tag, const char *value)
21291{
21292 if (tag < 1
21293 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21294 || !attributes_set_explicitly[tag])
21295 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21296}
21297
ee065d83
PB
21298/* Set the public EABI object attributes. */
21299static void
21300aeabi_set_public_attributes (void)
21301{
21302 int arch;
e74cfd16 21303 arm_feature_set flags;
62b3e311
PB
21304 arm_feature_set tmp;
21305 const cpu_arch_ver_table *p;
ee065d83
PB
21306
21307 /* Choose the architecture based on the capabilities of the requested cpu
21308 (if any) and/or the instructions actually used. */
e74cfd16
PB
21309 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
21310 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
21311 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
21312 /*Allow the user to override the reported architecture. */
21313 if (object_arch)
21314 {
21315 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
21316 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
21317 }
21318
62b3e311
PB
21319 tmp = flags;
21320 arch = 0;
21321 for (p = cpu_arch_ver; p->val; p++)
21322 {
21323 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
21324 {
21325 arch = p->val;
21326 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
21327 }
21328 }
ee065d83
PB
21329
21330 /* Tag_CPU_name. */
21331 if (selected_cpu_name[0])
21332 {
21333 char *p;
21334
21335 p = selected_cpu_name;
5f4273c7 21336 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
21337 {
21338 int i;
5f4273c7 21339
ee065d83
PB
21340 p += 4;
21341 for (i = 0; p[i]; i++)
21342 p[i] = TOUPPER (p[i]);
21343 }
ee3c0378 21344 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83
PB
21345 }
21346 /* Tag_CPU_arch. */
ee3c0378 21347 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62b3e311
PB
21348 /* Tag_CPU_arch_profile. */
21349 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 21350 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 21351 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 21352 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 21353 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 21354 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
ee065d83 21355 /* Tag_ARM_ISA_use. */
ee3c0378
AS
21356 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
21357 || arch == 0)
21358 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
ee065d83 21359 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
21360 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
21361 || arch == 0)
21362 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
21363 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
ee065d83 21364 /* Tag_VFP_arch. */
ee3c0378
AS
21365 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
21366 aeabi_set_attribute_int (Tag_VFP_arch, 3);
21367 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
21368 aeabi_set_attribute_int (Tag_VFP_arch, 4);
21369 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
21370 aeabi_set_attribute_int (Tag_VFP_arch, 2);
21371 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
21372 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
21373 aeabi_set_attribute_int (Tag_VFP_arch, 1);
ee065d83 21374 /* Tag_WMMX_arch. */
ee3c0378
AS
21375 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
21376 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
21377 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
21378 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
21379 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 21380 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
ee3c0378
AS
21381 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
21382 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
8e79c3df 21383 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
ee3c0378 21384 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
21385}
21386
104d59d1 21387/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
21388void
21389arm_md_end (void)
21390{
ee065d83
PB
21391 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21392 return;
21393
21394 aeabi_set_public_attributes ();
ee065d83 21395}
8463be01 21396#endif /* OBJ_ELF */
ee065d83
PB
21397
21398
21399/* Parse a .cpu directive. */
21400
21401static void
21402s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
21403{
e74cfd16 21404 const struct arm_cpu_option_table *opt;
ee065d83
PB
21405 char *name;
21406 char saved_char;
21407
21408 name = input_line_pointer;
5f4273c7 21409 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21410 input_line_pointer++;
21411 saved_char = *input_line_pointer;
21412 *input_line_pointer = 0;
21413
21414 /* Skip the first "all" entry. */
21415 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
21416 if (streq (opt->name, name))
21417 {
e74cfd16
PB
21418 mcpu_cpu_opt = &opt->value;
21419 selected_cpu = opt->value;
ee065d83 21420 if (opt->canonical_name)
5f4273c7 21421 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21422 else
21423 {
21424 int i;
21425 for (i = 0; opt->name[i]; i++)
21426 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21427 selected_cpu_name[i] = 0;
21428 }
e74cfd16 21429 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21430 *input_line_pointer = saved_char;
21431 demand_empty_rest_of_line ();
21432 return;
21433 }
21434 as_bad (_("unknown cpu `%s'"), name);
21435 *input_line_pointer = saved_char;
21436 ignore_rest_of_line ();
21437}
21438
21439
21440/* Parse a .arch directive. */
21441
21442static void
21443s_arm_arch (int ignored ATTRIBUTE_UNUSED)
21444{
e74cfd16 21445 const struct arm_arch_option_table *opt;
ee065d83
PB
21446 char saved_char;
21447 char *name;
21448
21449 name = input_line_pointer;
5f4273c7 21450 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21451 input_line_pointer++;
21452 saved_char = *input_line_pointer;
21453 *input_line_pointer = 0;
21454
21455 /* Skip the first "all" entry. */
21456 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21457 if (streq (opt->name, name))
21458 {
e74cfd16
PB
21459 mcpu_cpu_opt = &opt->value;
21460 selected_cpu = opt->value;
5f4273c7 21461 strcpy (selected_cpu_name, opt->name);
e74cfd16 21462 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21463 *input_line_pointer = saved_char;
21464 demand_empty_rest_of_line ();
21465 return;
21466 }
21467
21468 as_bad (_("unknown architecture `%s'\n"), name);
21469 *input_line_pointer = saved_char;
21470 ignore_rest_of_line ();
21471}
21472
21473
7a1d4c38
PB
21474/* Parse a .object_arch directive. */
21475
21476static void
21477s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
21478{
21479 const struct arm_arch_option_table *opt;
21480 char saved_char;
21481 char *name;
21482
21483 name = input_line_pointer;
5f4273c7 21484 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
21485 input_line_pointer++;
21486 saved_char = *input_line_pointer;
21487 *input_line_pointer = 0;
21488
21489 /* Skip the first "all" entry. */
21490 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21491 if (streq (opt->name, name))
21492 {
21493 object_arch = &opt->value;
21494 *input_line_pointer = saved_char;
21495 demand_empty_rest_of_line ();
21496 return;
21497 }
21498
21499 as_bad (_("unknown architecture `%s'\n"), name);
21500 *input_line_pointer = saved_char;
21501 ignore_rest_of_line ();
21502}
21503
ee065d83
PB
21504/* Parse a .fpu directive. */
21505
21506static void
21507s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
21508{
e74cfd16 21509 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
21510 char saved_char;
21511 char *name;
21512
21513 name = input_line_pointer;
5f4273c7 21514 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21515 input_line_pointer++;
21516 saved_char = *input_line_pointer;
21517 *input_line_pointer = 0;
5f4273c7 21518
ee065d83
PB
21519 for (opt = arm_fpus; opt->name != NULL; opt++)
21520 if (streq (opt->name, name))
21521 {
e74cfd16
PB
21522 mfpu_opt = &opt->value;
21523 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21524 *input_line_pointer = saved_char;
21525 demand_empty_rest_of_line ();
21526 return;
21527 }
21528
21529 as_bad (_("unknown floating point format `%s'\n"), name);
21530 *input_line_pointer = saved_char;
21531 ignore_rest_of_line ();
21532}
ee065d83 21533
794ba86a 21534/* Copy symbol information. */
f31fef98 21535
794ba86a
DJ
21536void
21537arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
21538{
21539 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
21540}
e04befd0 21541
f31fef98 21542#ifdef OBJ_ELF
e04befd0
AS
21543/* Given a symbolic attribute NAME, return the proper integer value.
21544 Returns -1 if the attribute is not known. */
f31fef98 21545
e04befd0
AS
21546int
21547arm_convert_symbolic_attribute (const char *name)
21548{
f31fef98
NC
21549 static const struct
21550 {
21551 const char * name;
21552 const int tag;
21553 }
21554 attribute_table[] =
21555 {
21556 /* When you modify this table you should
21557 also modify the list in doc/c-arm.texi. */
e04befd0 21558#define T(tag) {#tag, tag}
f31fef98
NC
21559 T (Tag_CPU_raw_name),
21560 T (Tag_CPU_name),
21561 T (Tag_CPU_arch),
21562 T (Tag_CPU_arch_profile),
21563 T (Tag_ARM_ISA_use),
21564 T (Tag_THUMB_ISA_use),
21565 T (Tag_VFP_arch),
21566 T (Tag_WMMX_arch),
21567 T (Tag_Advanced_SIMD_arch),
21568 T (Tag_PCS_config),
21569 T (Tag_ABI_PCS_R9_use),
21570 T (Tag_ABI_PCS_RW_data),
21571 T (Tag_ABI_PCS_RO_data),
21572 T (Tag_ABI_PCS_GOT_use),
21573 T (Tag_ABI_PCS_wchar_t),
21574 T (Tag_ABI_FP_rounding),
21575 T (Tag_ABI_FP_denormal),
21576 T (Tag_ABI_FP_exceptions),
21577 T (Tag_ABI_FP_user_exceptions),
21578 T (Tag_ABI_FP_number_model),
21579 T (Tag_ABI_align8_needed),
21580 T (Tag_ABI_align8_preserved),
21581 T (Tag_ABI_enum_size),
21582 T (Tag_ABI_HardFP_use),
21583 T (Tag_ABI_VFP_args),
21584 T (Tag_ABI_WMMX_args),
21585 T (Tag_ABI_optimization_goals),
21586 T (Tag_ABI_FP_optimization_goals),
21587 T (Tag_compatibility),
21588 T (Tag_CPU_unaligned_access),
21589 T (Tag_VFP_HP_extension),
21590 T (Tag_ABI_FP_16bit_format),
21591 T (Tag_nodefaults),
21592 T (Tag_also_compatible_with),
21593 T (Tag_conformance),
21594 T (Tag_T2EE_use),
21595 T (Tag_Virtualization_use),
21596 T (Tag_MPextension_use)
e04befd0 21597#undef T
f31fef98 21598 };
e04befd0
AS
21599 unsigned int i;
21600
21601 if (name == NULL)
21602 return -1;
21603
f31fef98 21604 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
e04befd0
AS
21605 if (strcmp (name, attribute_table[i].name) == 0)
21606 return attribute_table[i].tag;
21607
21608 return -1;
21609}
f31fef98 21610#endif /* OBJ_ELF */