PR 10169
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
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
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
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)'"));
267bf995 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 6796 /* Arg is an address; this instruction cannot be executed
267bf995
RR
6797 conditionally, and the opcode must be adjusted.
6798 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
6799 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 6800 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6801 inst.instruction = 0xfa000000;
267bf995 6802 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6803 }
c19d1205
ZW
6804}
6805
6806static void
6807do_bx (void)
6808{
845b51d6
PB
6809 bfd_boolean want_reloc;
6810
c19d1205
ZW
6811 if (inst.operands[0].reg == REG_PC)
6812 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6813
c19d1205 6814 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6815 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6816 it is for ARMv4t or earlier. */
6817 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6818 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6819 want_reloc = TRUE;
6820
5ad34203 6821#ifdef OBJ_ELF
845b51d6 6822 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6823#endif
584206db 6824 want_reloc = FALSE;
845b51d6
PB
6825
6826 if (want_reloc)
6827 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6828}
6829
c19d1205
ZW
6830
6831/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6832
6833static void
c19d1205 6834do_bxj (void)
a737bd4d 6835{
c19d1205
ZW
6836 if (inst.operands[0].reg == REG_PC)
6837 as_tsktsk (_("use of r15 in bxj is not really useful"));
6838
6839 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6840}
6841
c19d1205
ZW
6842/* Co-processor data operation:
6843 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6844 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6845static void
6846do_cdp (void)
6847{
6848 inst.instruction |= inst.operands[0].reg << 8;
6849 inst.instruction |= inst.operands[1].imm << 20;
6850 inst.instruction |= inst.operands[2].reg << 12;
6851 inst.instruction |= inst.operands[3].reg << 16;
6852 inst.instruction |= inst.operands[4].reg;
6853 inst.instruction |= inst.operands[5].imm << 5;
6854}
a737bd4d
NC
6855
6856static void
c19d1205 6857do_cmp (void)
a737bd4d 6858{
c19d1205
ZW
6859 inst.instruction |= inst.operands[0].reg << 16;
6860 encode_arm_shifter_operand (1);
a737bd4d
NC
6861}
6862
c19d1205
ZW
6863/* Transfer between coprocessor and ARM registers.
6864 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6865 MRC2
6866 MCR{cond}
6867 MCR2
6868
6869 No special properties. */
09d92015
MM
6870
6871static void
c19d1205 6872do_co_reg (void)
09d92015 6873{
fdfde340
JM
6874 unsigned Rd;
6875
6876 Rd = inst.operands[2].reg;
6877 if (thumb_mode)
6878 {
6879 if (inst.instruction == 0xee000010
6880 || inst.instruction == 0xfe000010)
6881 /* MCR, MCR2 */
6882 reject_bad_reg (Rd);
6883 else
6884 /* MRC, MRC2 */
6885 constraint (Rd == REG_SP, BAD_SP);
6886 }
6887 else
6888 {
6889 /* MCR */
6890 if (inst.instruction == 0xe000010)
6891 constraint (Rd == REG_PC, BAD_PC);
6892 }
6893
6894
c19d1205
ZW
6895 inst.instruction |= inst.operands[0].reg << 8;
6896 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 6897 inst.instruction |= Rd << 12;
c19d1205
ZW
6898 inst.instruction |= inst.operands[3].reg << 16;
6899 inst.instruction |= inst.operands[4].reg;
6900 inst.instruction |= inst.operands[5].imm << 5;
6901}
09d92015 6902
c19d1205
ZW
6903/* Transfer between coprocessor register and pair of ARM registers.
6904 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6905 MCRR2
6906 MRRC{cond}
6907 MRRC2
b99bd4ef 6908
c19d1205 6909 Two XScale instructions are special cases of these:
09d92015 6910
c19d1205
ZW
6911 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6912 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6913
5f4273c7 6914 Result unpredictable if Rd or Rn is R15. */
a737bd4d 6915
c19d1205
ZW
6916static void
6917do_co_reg2c (void)
6918{
fdfde340
JM
6919 unsigned Rd, Rn;
6920
6921 Rd = inst.operands[2].reg;
6922 Rn = inst.operands[3].reg;
6923
6924 if (thumb_mode)
6925 {
6926 reject_bad_reg (Rd);
6927 reject_bad_reg (Rn);
6928 }
6929 else
6930 {
6931 constraint (Rd == REG_PC, BAD_PC);
6932 constraint (Rn == REG_PC, BAD_PC);
6933 }
6934
c19d1205
ZW
6935 inst.instruction |= inst.operands[0].reg << 8;
6936 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
6937 inst.instruction |= Rd << 12;
6938 inst.instruction |= Rn << 16;
c19d1205 6939 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6940}
6941
c19d1205
ZW
6942static void
6943do_cpsi (void)
6944{
6945 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6946 if (inst.operands[1].present)
6947 {
6948 inst.instruction |= CPSI_MMOD;
6949 inst.instruction |= inst.operands[1].imm;
6950 }
c19d1205 6951}
b99bd4ef 6952
62b3e311
PB
6953static void
6954do_dbg (void)
6955{
6956 inst.instruction |= inst.operands[0].imm;
6957}
6958
b99bd4ef 6959static void
c19d1205 6960do_it (void)
b99bd4ef 6961{
c19d1205
ZW
6962 /* There is no IT instruction in ARM mode. We
6963 process it but do not generate code for it. */
6964 inst.size = 0;
09d92015 6965}
b99bd4ef 6966
09d92015 6967static void
c19d1205 6968do_ldmstm (void)
ea6ef066 6969{
c19d1205
ZW
6970 int base_reg = inst.operands[0].reg;
6971 int range = inst.operands[1].imm;
ea6ef066 6972
c19d1205
ZW
6973 inst.instruction |= base_reg << 16;
6974 inst.instruction |= range;
ea6ef066 6975
c19d1205
ZW
6976 if (inst.operands[1].writeback)
6977 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6978
c19d1205 6979 if (inst.operands[0].writeback)
ea6ef066 6980 {
c19d1205
ZW
6981 inst.instruction |= WRITE_BACK;
6982 /* Check for unpredictable uses of writeback. */
6983 if (inst.instruction & LOAD_BIT)
09d92015 6984 {
c19d1205
ZW
6985 /* Not allowed in LDM type 2. */
6986 if ((inst.instruction & LDM_TYPE_2_OR_3)
6987 && ((range & (1 << REG_PC)) == 0))
6988 as_warn (_("writeback of base register is UNPREDICTABLE"));
6989 /* Only allowed if base reg not in list for other types. */
6990 else if (range & (1 << base_reg))
6991 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6992 }
6993 else /* STM. */
6994 {
6995 /* Not allowed for type 2. */
6996 if (inst.instruction & LDM_TYPE_2_OR_3)
6997 as_warn (_("writeback of base register is UNPREDICTABLE"));
6998 /* Only allowed if base reg not in list, or first in list. */
6999 else if ((range & (1 << base_reg))
7000 && (range & ((1 << base_reg) - 1)))
7001 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7002 }
ea6ef066 7003 }
a737bd4d
NC
7004}
7005
c19d1205
ZW
7006/* ARMv5TE load-consecutive (argument parse)
7007 Mode is like LDRH.
7008
7009 LDRccD R, mode
7010 STRccD R, mode. */
7011
a737bd4d 7012static void
c19d1205 7013do_ldrd (void)
a737bd4d 7014{
c19d1205
ZW
7015 constraint (inst.operands[0].reg % 2 != 0,
7016 _("first destination register must be even"));
7017 constraint (inst.operands[1].present
7018 && inst.operands[1].reg != inst.operands[0].reg + 1,
7019 _("can only load two consecutive registers"));
7020 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7021 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7022
c19d1205
ZW
7023 if (!inst.operands[1].present)
7024 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7025
c19d1205 7026 if (inst.instruction & LOAD_BIT)
a737bd4d 7027 {
c19d1205
ZW
7028 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7029 register and the first register written; we have to diagnose
7030 overlap between the base and the second register written here. */
ea6ef066 7031
c19d1205
ZW
7032 if (inst.operands[2].reg == inst.operands[1].reg
7033 && (inst.operands[2].writeback || inst.operands[2].postind))
7034 as_warn (_("base register written back, and overlaps "
7035 "second destination register"));
b05fe5cf 7036
c19d1205
ZW
7037 /* For an index-register load, the index register must not overlap the
7038 destination (even if not write-back). */
7039 else if (inst.operands[2].immisreg
ca3f61f7
NC
7040 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7041 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7042 as_warn (_("index register overlaps destination register"));
b05fe5cf 7043 }
c19d1205
ZW
7044
7045 inst.instruction |= inst.operands[0].reg << 12;
7046 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7047}
7048
7049static void
c19d1205 7050do_ldrex (void)
b05fe5cf 7051{
c19d1205
ZW
7052 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7053 || inst.operands[1].postind || inst.operands[1].writeback
7054 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7055 || inst.operands[1].negative
7056 /* This can arise if the programmer has written
7057 strex rN, rM, foo
7058 or if they have mistakenly used a register name as the last
7059 operand, eg:
7060 strex rN, rM, rX
7061 It is very difficult to distinguish between these two cases
7062 because "rX" might actually be a label. ie the register
7063 name has been occluded by a symbol of the same name. So we
7064 just generate a general 'bad addressing mode' type error
7065 message and leave it up to the programmer to discover the
7066 true cause and fix their mistake. */
7067 || (inst.operands[1].reg == REG_PC),
7068 BAD_ADDR_MODE);
b05fe5cf 7069
c19d1205
ZW
7070 constraint (inst.reloc.exp.X_op != O_constant
7071 || inst.reloc.exp.X_add_number != 0,
7072 _("offset must be zero in ARM encoding"));
b05fe5cf 7073
c19d1205
ZW
7074 inst.instruction |= inst.operands[0].reg << 12;
7075 inst.instruction |= inst.operands[1].reg << 16;
7076 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7077}
7078
7079static void
c19d1205 7080do_ldrexd (void)
b05fe5cf 7081{
c19d1205
ZW
7082 constraint (inst.operands[0].reg % 2 != 0,
7083 _("even register required"));
7084 constraint (inst.operands[1].present
7085 && inst.operands[1].reg != inst.operands[0].reg + 1,
7086 _("can only load two consecutive registers"));
7087 /* If op 1 were present and equal to PC, this function wouldn't
7088 have been called in the first place. */
7089 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7090
c19d1205
ZW
7091 inst.instruction |= inst.operands[0].reg << 12;
7092 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7093}
7094
7095static void
c19d1205 7096do_ldst (void)
b05fe5cf 7097{
c19d1205
ZW
7098 inst.instruction |= inst.operands[0].reg << 12;
7099 if (!inst.operands[1].isreg)
7100 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7101 return;
c19d1205 7102 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7103}
7104
7105static void
c19d1205 7106do_ldstt (void)
b05fe5cf 7107{
c19d1205
ZW
7108 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7109 reject [Rn,...]. */
7110 if (inst.operands[1].preind)
b05fe5cf 7111 {
bd3ba5d1
NC
7112 constraint (inst.reloc.exp.X_op != O_constant
7113 || inst.reloc.exp.X_add_number != 0,
c19d1205 7114 _("this instruction requires a post-indexed address"));
b05fe5cf 7115
c19d1205
ZW
7116 inst.operands[1].preind = 0;
7117 inst.operands[1].postind = 1;
7118 inst.operands[1].writeback = 1;
b05fe5cf 7119 }
c19d1205
ZW
7120 inst.instruction |= inst.operands[0].reg << 12;
7121 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7122}
b05fe5cf 7123
c19d1205 7124/* Halfword and signed-byte load/store operations. */
b05fe5cf 7125
c19d1205
ZW
7126static void
7127do_ldstv4 (void)
7128{
7129 inst.instruction |= inst.operands[0].reg << 12;
7130 if (!inst.operands[1].isreg)
7131 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7132 return;
c19d1205 7133 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7134}
7135
7136static void
c19d1205 7137do_ldsttv4 (void)
b05fe5cf 7138{
c19d1205
ZW
7139 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7140 reject [Rn,...]. */
7141 if (inst.operands[1].preind)
b05fe5cf 7142 {
bd3ba5d1
NC
7143 constraint (inst.reloc.exp.X_op != O_constant
7144 || inst.reloc.exp.X_add_number != 0,
c19d1205 7145 _("this instruction requires a post-indexed address"));
b05fe5cf 7146
c19d1205
ZW
7147 inst.operands[1].preind = 0;
7148 inst.operands[1].postind = 1;
7149 inst.operands[1].writeback = 1;
b05fe5cf 7150 }
c19d1205
ZW
7151 inst.instruction |= inst.operands[0].reg << 12;
7152 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7153}
b05fe5cf 7154
c19d1205
ZW
7155/* Co-processor register load/store.
7156 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7157static void
7158do_lstc (void)
7159{
7160 inst.instruction |= inst.operands[0].reg << 8;
7161 inst.instruction |= inst.operands[1].reg << 12;
7162 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7163}
7164
b05fe5cf 7165static void
c19d1205 7166do_mlas (void)
b05fe5cf 7167{
8fb9d7b9 7168 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7169 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7170 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7171 && !(inst.instruction & 0x00400000))
8fb9d7b9 7172 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7173
c19d1205
ZW
7174 inst.instruction |= inst.operands[0].reg << 16;
7175 inst.instruction |= inst.operands[1].reg;
7176 inst.instruction |= inst.operands[2].reg << 8;
7177 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7178}
b05fe5cf 7179
c19d1205
ZW
7180static void
7181do_mov (void)
7182{
7183 inst.instruction |= inst.operands[0].reg << 12;
7184 encode_arm_shifter_operand (1);
7185}
b05fe5cf 7186
c19d1205
ZW
7187/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7188static void
7189do_mov16 (void)
7190{
b6895b4f
PB
7191 bfd_vma imm;
7192 bfd_boolean top;
7193
7194 top = (inst.instruction & 0x00400000) != 0;
7195 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7196 _(":lower16: not allowed this instruction"));
7197 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7198 _(":upper16: not allowed instruction"));
c19d1205 7199 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7200 if (inst.reloc.type == BFD_RELOC_UNUSED)
7201 {
7202 imm = inst.reloc.exp.X_add_number;
7203 /* The value is in two pieces: 0:11, 16:19. */
7204 inst.instruction |= (imm & 0x00000fff);
7205 inst.instruction |= (imm & 0x0000f000) << 4;
7206 }
b05fe5cf 7207}
b99bd4ef 7208
037e8744
JB
7209static void do_vfp_nsyn_opcode (const char *);
7210
7211static int
7212do_vfp_nsyn_mrs (void)
7213{
7214 if (inst.operands[0].isvec)
7215 {
7216 if (inst.operands[1].reg != 1)
7217 first_error (_("operand 1 must be FPSCR"));
7218 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7219 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7220 do_vfp_nsyn_opcode ("fmstat");
7221 }
7222 else if (inst.operands[1].isvec)
7223 do_vfp_nsyn_opcode ("fmrx");
7224 else
7225 return FAIL;
5f4273c7 7226
037e8744
JB
7227 return SUCCESS;
7228}
7229
7230static int
7231do_vfp_nsyn_msr (void)
7232{
7233 if (inst.operands[0].isvec)
7234 do_vfp_nsyn_opcode ("fmxr");
7235 else
7236 return FAIL;
7237
7238 return SUCCESS;
7239}
7240
b99bd4ef 7241static void
c19d1205 7242do_mrs (void)
b99bd4ef 7243{
037e8744
JB
7244 if (do_vfp_nsyn_mrs () == SUCCESS)
7245 return;
7246
c19d1205
ZW
7247 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7248 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7249 != (PSR_c|PSR_f),
7250 _("'CPSR' or 'SPSR' expected"));
7251 inst.instruction |= inst.operands[0].reg << 12;
7252 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7253}
b99bd4ef 7254
c19d1205
ZW
7255/* Two possible forms:
7256 "{C|S}PSR_<field>, Rm",
7257 "{C|S}PSR_f, #expression". */
b99bd4ef 7258
c19d1205
ZW
7259static void
7260do_msr (void)
7261{
037e8744
JB
7262 if (do_vfp_nsyn_msr () == SUCCESS)
7263 return;
7264
c19d1205
ZW
7265 inst.instruction |= inst.operands[0].imm;
7266 if (inst.operands[1].isreg)
7267 inst.instruction |= inst.operands[1].reg;
7268 else
b99bd4ef 7269 {
c19d1205
ZW
7270 inst.instruction |= INST_IMMEDIATE;
7271 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7272 inst.reloc.pc_rel = 0;
b99bd4ef 7273 }
b99bd4ef
NC
7274}
7275
c19d1205
ZW
7276static void
7277do_mul (void)
a737bd4d 7278{
c19d1205
ZW
7279 if (!inst.operands[2].present)
7280 inst.operands[2].reg = inst.operands[0].reg;
7281 inst.instruction |= inst.operands[0].reg << 16;
7282 inst.instruction |= inst.operands[1].reg;
7283 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7284
8fb9d7b9
MS
7285 if (inst.operands[0].reg == inst.operands[1].reg
7286 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7287 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7288}
7289
c19d1205
ZW
7290/* Long Multiply Parser
7291 UMULL RdLo, RdHi, Rm, Rs
7292 SMULL RdLo, RdHi, Rm, Rs
7293 UMLAL RdLo, RdHi, Rm, Rs
7294 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7295
7296static void
c19d1205 7297do_mull (void)
b99bd4ef 7298{
c19d1205
ZW
7299 inst.instruction |= inst.operands[0].reg << 12;
7300 inst.instruction |= inst.operands[1].reg << 16;
7301 inst.instruction |= inst.operands[2].reg;
7302 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7303
682b27ad
PB
7304 /* rdhi and rdlo must be different. */
7305 if (inst.operands[0].reg == inst.operands[1].reg)
7306 as_tsktsk (_("rdhi and rdlo must be different"));
7307
7308 /* rdhi, rdlo and rm must all be different before armv6. */
7309 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7310 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7311 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7312 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7313}
b99bd4ef 7314
c19d1205
ZW
7315static void
7316do_nop (void)
7317{
e7495e45
NS
7318 if (inst.operands[0].present
7319 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7320 {
7321 /* Architectural NOP hints are CPSR sets with no bits selected. */
7322 inst.instruction &= 0xf0000000;
e7495e45
NS
7323 inst.instruction |= 0x0320f000;
7324 if (inst.operands[0].present)
7325 inst.instruction |= inst.operands[0].imm;
c19d1205 7326 }
b99bd4ef
NC
7327}
7328
c19d1205
ZW
7329/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7330 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7331 Condition defaults to COND_ALWAYS.
7332 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7333
7334static void
c19d1205 7335do_pkhbt (void)
b99bd4ef 7336{
c19d1205
ZW
7337 inst.instruction |= inst.operands[0].reg << 12;
7338 inst.instruction |= inst.operands[1].reg << 16;
7339 inst.instruction |= inst.operands[2].reg;
7340 if (inst.operands[3].present)
7341 encode_arm_shift (3);
7342}
b99bd4ef 7343
c19d1205 7344/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7345
c19d1205
ZW
7346static void
7347do_pkhtb (void)
7348{
7349 if (!inst.operands[3].present)
b99bd4ef 7350 {
c19d1205
ZW
7351 /* If the shift specifier is omitted, turn the instruction
7352 into pkhbt rd, rm, rn. */
7353 inst.instruction &= 0xfff00010;
7354 inst.instruction |= inst.operands[0].reg << 12;
7355 inst.instruction |= inst.operands[1].reg;
7356 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7357 }
7358 else
7359 {
c19d1205
ZW
7360 inst.instruction |= inst.operands[0].reg << 12;
7361 inst.instruction |= inst.operands[1].reg << 16;
7362 inst.instruction |= inst.operands[2].reg;
7363 encode_arm_shift (3);
b99bd4ef
NC
7364 }
7365}
7366
c19d1205
ZW
7367/* ARMv5TE: Preload-Cache
7368
7369 PLD <addr_mode>
7370
7371 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7372
7373static void
c19d1205 7374do_pld (void)
b99bd4ef 7375{
c19d1205
ZW
7376 constraint (!inst.operands[0].isreg,
7377 _("'[' expected after PLD mnemonic"));
7378 constraint (inst.operands[0].postind,
7379 _("post-indexed expression used in preload instruction"));
7380 constraint (inst.operands[0].writeback,
7381 _("writeback used in preload instruction"));
7382 constraint (!inst.operands[0].preind,
7383 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7384 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7385}
b99bd4ef 7386
62b3e311
PB
7387/* ARMv7: PLI <addr_mode> */
7388static void
7389do_pli (void)
7390{
7391 constraint (!inst.operands[0].isreg,
7392 _("'[' expected after PLI mnemonic"));
7393 constraint (inst.operands[0].postind,
7394 _("post-indexed expression used in preload instruction"));
7395 constraint (inst.operands[0].writeback,
7396 _("writeback used in preload instruction"));
7397 constraint (!inst.operands[0].preind,
7398 _("unindexed addressing used in preload instruction"));
7399 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7400 inst.instruction &= ~PRE_INDEX;
7401}
7402
c19d1205
ZW
7403static void
7404do_push_pop (void)
7405{
7406 inst.operands[1] = inst.operands[0];
7407 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7408 inst.operands[0].isreg = 1;
7409 inst.operands[0].writeback = 1;
7410 inst.operands[0].reg = REG_SP;
7411 do_ldmstm ();
7412}
b99bd4ef 7413
c19d1205
ZW
7414/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7415 word at the specified address and the following word
7416 respectively.
7417 Unconditionally executed.
7418 Error if Rn is R15. */
b99bd4ef 7419
c19d1205
ZW
7420static void
7421do_rfe (void)
7422{
7423 inst.instruction |= inst.operands[0].reg << 16;
7424 if (inst.operands[0].writeback)
7425 inst.instruction |= WRITE_BACK;
7426}
b99bd4ef 7427
c19d1205 7428/* ARM V6 ssat (argument parse). */
b99bd4ef 7429
c19d1205
ZW
7430static void
7431do_ssat (void)
7432{
7433 inst.instruction |= inst.operands[0].reg << 12;
7434 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7435 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7436
c19d1205
ZW
7437 if (inst.operands[3].present)
7438 encode_arm_shift (3);
b99bd4ef
NC
7439}
7440
c19d1205 7441/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7442
7443static void
c19d1205 7444do_usat (void)
b99bd4ef 7445{
c19d1205
ZW
7446 inst.instruction |= inst.operands[0].reg << 12;
7447 inst.instruction |= inst.operands[1].imm << 16;
7448 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7449
c19d1205
ZW
7450 if (inst.operands[3].present)
7451 encode_arm_shift (3);
b99bd4ef
NC
7452}
7453
c19d1205 7454/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7455
7456static void
c19d1205 7457do_ssat16 (void)
09d92015 7458{
c19d1205
ZW
7459 inst.instruction |= inst.operands[0].reg << 12;
7460 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7461 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7462}
7463
c19d1205
ZW
7464static void
7465do_usat16 (void)
a737bd4d 7466{
c19d1205
ZW
7467 inst.instruction |= inst.operands[0].reg << 12;
7468 inst.instruction |= inst.operands[1].imm << 16;
7469 inst.instruction |= inst.operands[2].reg;
7470}
a737bd4d 7471
c19d1205
ZW
7472/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7473 preserving the other bits.
a737bd4d 7474
c19d1205
ZW
7475 setend <endian_specifier>, where <endian_specifier> is either
7476 BE or LE. */
a737bd4d 7477
c19d1205
ZW
7478static void
7479do_setend (void)
7480{
7481 if (inst.operands[0].imm)
7482 inst.instruction |= 0x200;
a737bd4d
NC
7483}
7484
7485static void
c19d1205 7486do_shift (void)
a737bd4d 7487{
c19d1205
ZW
7488 unsigned int Rm = (inst.operands[1].present
7489 ? inst.operands[1].reg
7490 : inst.operands[0].reg);
a737bd4d 7491
c19d1205
ZW
7492 inst.instruction |= inst.operands[0].reg << 12;
7493 inst.instruction |= Rm;
7494 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7495 {
c19d1205
ZW
7496 inst.instruction |= inst.operands[2].reg << 8;
7497 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7498 }
7499 else
c19d1205 7500 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7501}
7502
09d92015 7503static void
3eb17e6b 7504do_smc (void)
09d92015 7505{
3eb17e6b 7506 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7507 inst.reloc.pc_rel = 0;
09d92015
MM
7508}
7509
09d92015 7510static void
c19d1205 7511do_swi (void)
09d92015 7512{
c19d1205
ZW
7513 inst.reloc.type = BFD_RELOC_ARM_SWI;
7514 inst.reloc.pc_rel = 0;
09d92015
MM
7515}
7516
c19d1205
ZW
7517/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7518 SMLAxy{cond} Rd,Rm,Rs,Rn
7519 SMLAWy{cond} Rd,Rm,Rs,Rn
7520 Error if any register is R15. */
e16bb312 7521
c19d1205
ZW
7522static void
7523do_smla (void)
e16bb312 7524{
c19d1205
ZW
7525 inst.instruction |= inst.operands[0].reg << 16;
7526 inst.instruction |= inst.operands[1].reg;
7527 inst.instruction |= inst.operands[2].reg << 8;
7528 inst.instruction |= inst.operands[3].reg << 12;
7529}
a737bd4d 7530
c19d1205
ZW
7531/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7532 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7533 Error if any register is R15.
7534 Warning if Rdlo == Rdhi. */
a737bd4d 7535
c19d1205
ZW
7536static void
7537do_smlal (void)
7538{
7539 inst.instruction |= inst.operands[0].reg << 12;
7540 inst.instruction |= inst.operands[1].reg << 16;
7541 inst.instruction |= inst.operands[2].reg;
7542 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7543
c19d1205
ZW
7544 if (inst.operands[0].reg == inst.operands[1].reg)
7545 as_tsktsk (_("rdhi and rdlo must be different"));
7546}
a737bd4d 7547
c19d1205
ZW
7548/* ARM V5E (El Segundo) signed-multiply (argument parse)
7549 SMULxy{cond} Rd,Rm,Rs
7550 Error if any register is R15. */
a737bd4d 7551
c19d1205
ZW
7552static void
7553do_smul (void)
7554{
7555 inst.instruction |= inst.operands[0].reg << 16;
7556 inst.instruction |= inst.operands[1].reg;
7557 inst.instruction |= inst.operands[2].reg << 8;
7558}
a737bd4d 7559
b6702015
PB
7560/* ARM V6 srs (argument parse). The variable fields in the encoding are
7561 the same for both ARM and Thumb-2. */
a737bd4d 7562
c19d1205
ZW
7563static void
7564do_srs (void)
7565{
b6702015
PB
7566 int reg;
7567
7568 if (inst.operands[0].present)
7569 {
7570 reg = inst.operands[0].reg;
fdfde340 7571 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7572 }
7573 else
fdfde340 7574 reg = REG_SP;
b6702015
PB
7575
7576 inst.instruction |= reg << 16;
7577 inst.instruction |= inst.operands[1].imm;
7578 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7579 inst.instruction |= WRITE_BACK;
7580}
a737bd4d 7581
c19d1205 7582/* ARM V6 strex (argument parse). */
a737bd4d 7583
c19d1205
ZW
7584static void
7585do_strex (void)
7586{
7587 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7588 || inst.operands[2].postind || inst.operands[2].writeback
7589 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7590 || inst.operands[2].negative
7591 /* See comment in do_ldrex(). */
7592 || (inst.operands[2].reg == REG_PC),
7593 BAD_ADDR_MODE);
a737bd4d 7594
c19d1205
ZW
7595 constraint (inst.operands[0].reg == inst.operands[1].reg
7596 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7597
c19d1205
ZW
7598 constraint (inst.reloc.exp.X_op != O_constant
7599 || inst.reloc.exp.X_add_number != 0,
7600 _("offset must be zero in ARM encoding"));
a737bd4d 7601
c19d1205
ZW
7602 inst.instruction |= inst.operands[0].reg << 12;
7603 inst.instruction |= inst.operands[1].reg;
7604 inst.instruction |= inst.operands[2].reg << 16;
7605 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7606}
7607
7608static void
c19d1205 7609do_strexd (void)
e16bb312 7610{
c19d1205
ZW
7611 constraint (inst.operands[1].reg % 2 != 0,
7612 _("even register required"));
7613 constraint (inst.operands[2].present
7614 && inst.operands[2].reg != inst.operands[1].reg + 1,
7615 _("can only store two consecutive registers"));
7616 /* If op 2 were present and equal to PC, this function wouldn't
7617 have been called in the first place. */
7618 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7619
c19d1205
ZW
7620 constraint (inst.operands[0].reg == inst.operands[1].reg
7621 || inst.operands[0].reg == inst.operands[1].reg + 1
7622 || inst.operands[0].reg == inst.operands[3].reg,
7623 BAD_OVERLAP);
e16bb312 7624
c19d1205
ZW
7625 inst.instruction |= inst.operands[0].reg << 12;
7626 inst.instruction |= inst.operands[1].reg;
7627 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7628}
7629
c19d1205
ZW
7630/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7631 extends it to 32-bits, and adds the result to a value in another
7632 register. You can specify a rotation by 0, 8, 16, or 24 bits
7633 before extracting the 16-bit value.
7634 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7635 Condition defaults to COND_ALWAYS.
7636 Error if any register uses R15. */
7637
e16bb312 7638static void
c19d1205 7639do_sxtah (void)
e16bb312 7640{
c19d1205
ZW
7641 inst.instruction |= inst.operands[0].reg << 12;
7642 inst.instruction |= inst.operands[1].reg << 16;
7643 inst.instruction |= inst.operands[2].reg;
7644 inst.instruction |= inst.operands[3].imm << 10;
7645}
e16bb312 7646
c19d1205 7647/* ARM V6 SXTH.
e16bb312 7648
c19d1205
ZW
7649 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7650 Condition defaults to COND_ALWAYS.
7651 Error if any register uses R15. */
e16bb312
NC
7652
7653static void
c19d1205 7654do_sxth (void)
e16bb312 7655{
c19d1205
ZW
7656 inst.instruction |= inst.operands[0].reg << 12;
7657 inst.instruction |= inst.operands[1].reg;
7658 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7659}
c19d1205
ZW
7660\f
7661/* VFP instructions. In a logical order: SP variant first, monad
7662 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7663
7664static void
c19d1205 7665do_vfp_sp_monadic (void)
e16bb312 7666{
5287ad62
JB
7667 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7668 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7669}
7670
7671static void
c19d1205 7672do_vfp_sp_dyadic (void)
e16bb312 7673{
5287ad62
JB
7674 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7675 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7676 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7677}
7678
7679static void
c19d1205 7680do_vfp_sp_compare_z (void)
e16bb312 7681{
5287ad62 7682 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7683}
7684
7685static void
c19d1205 7686do_vfp_dp_sp_cvt (void)
e16bb312 7687{
5287ad62
JB
7688 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7689 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7690}
7691
7692static void
c19d1205 7693do_vfp_sp_dp_cvt (void)
e16bb312 7694{
5287ad62
JB
7695 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7696 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7697}
7698
7699static void
c19d1205 7700do_vfp_reg_from_sp (void)
e16bb312 7701{
c19d1205 7702 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7703 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7704}
7705
7706static void
c19d1205 7707do_vfp_reg2_from_sp2 (void)
e16bb312 7708{
c19d1205
ZW
7709 constraint (inst.operands[2].imm != 2,
7710 _("only two consecutive VFP SP registers allowed here"));
7711 inst.instruction |= inst.operands[0].reg << 12;
7712 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7713 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7714}
7715
7716static void
c19d1205 7717do_vfp_sp_from_reg (void)
e16bb312 7718{
5287ad62 7719 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7720 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7721}
7722
7723static void
c19d1205 7724do_vfp_sp2_from_reg2 (void)
e16bb312 7725{
c19d1205
ZW
7726 constraint (inst.operands[0].imm != 2,
7727 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7728 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7729 inst.instruction |= inst.operands[1].reg << 12;
7730 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7731}
7732
7733static void
c19d1205 7734do_vfp_sp_ldst (void)
e16bb312 7735{
5287ad62 7736 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7737 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7738}
7739
7740static void
c19d1205 7741do_vfp_dp_ldst (void)
e16bb312 7742{
5287ad62 7743 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7744 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7745}
7746
c19d1205 7747
e16bb312 7748static void
c19d1205 7749vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7750{
c19d1205
ZW
7751 if (inst.operands[0].writeback)
7752 inst.instruction |= WRITE_BACK;
7753 else
7754 constraint (ldstm_type != VFP_LDSTMIA,
7755 _("this addressing mode requires base-register writeback"));
7756 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7757 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7758 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7759}
7760
7761static void
c19d1205 7762vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7763{
c19d1205 7764 int count;
e16bb312 7765
c19d1205
ZW
7766 if (inst.operands[0].writeback)
7767 inst.instruction |= WRITE_BACK;
7768 else
7769 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7770 _("this addressing mode requires base-register writeback"));
e16bb312 7771
c19d1205 7772 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7773 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7774
c19d1205
ZW
7775 count = inst.operands[1].imm << 1;
7776 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7777 count += 1;
e16bb312 7778
c19d1205 7779 inst.instruction |= count;
e16bb312
NC
7780}
7781
7782static void
c19d1205 7783do_vfp_sp_ldstmia (void)
e16bb312 7784{
c19d1205 7785 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7786}
7787
7788static void
c19d1205 7789do_vfp_sp_ldstmdb (void)
e16bb312 7790{
c19d1205 7791 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7792}
7793
7794static void
c19d1205 7795do_vfp_dp_ldstmia (void)
e16bb312 7796{
c19d1205 7797 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7798}
7799
7800static void
c19d1205 7801do_vfp_dp_ldstmdb (void)
e16bb312 7802{
c19d1205 7803 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7804}
7805
7806static void
c19d1205 7807do_vfp_xp_ldstmia (void)
e16bb312 7808{
c19d1205
ZW
7809 vfp_dp_ldstm (VFP_LDSTMIAX);
7810}
e16bb312 7811
c19d1205
ZW
7812static void
7813do_vfp_xp_ldstmdb (void)
7814{
7815 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7816}
5287ad62
JB
7817
7818static void
7819do_vfp_dp_rd_rm (void)
7820{
7821 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7822 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7823}
7824
7825static void
7826do_vfp_dp_rn_rd (void)
7827{
7828 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7829 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7830}
7831
7832static void
7833do_vfp_dp_rd_rn (void)
7834{
7835 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7836 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7837}
7838
7839static void
7840do_vfp_dp_rd_rn_rm (void)
7841{
7842 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7843 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7844 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7845}
7846
7847static void
7848do_vfp_dp_rd (void)
7849{
7850 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7851}
7852
7853static void
7854do_vfp_dp_rm_rd_rn (void)
7855{
7856 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7857 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7858 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7859}
7860
7861/* VFPv3 instructions. */
7862static void
7863do_vfp_sp_const (void)
7864{
7865 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7866 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7867 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7868}
7869
7870static void
7871do_vfp_dp_const (void)
7872{
7873 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7874 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7875 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7876}
7877
7878static void
7879vfp_conv (int srcsize)
7880{
7881 unsigned immbits = srcsize - inst.operands[1].imm;
7882 inst.instruction |= (immbits & 1) << 5;
7883 inst.instruction |= (immbits >> 1);
7884}
7885
7886static void
7887do_vfp_sp_conv_16 (void)
7888{
7889 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7890 vfp_conv (16);
7891}
7892
7893static void
7894do_vfp_dp_conv_16 (void)
7895{
7896 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7897 vfp_conv (16);
7898}
7899
7900static void
7901do_vfp_sp_conv_32 (void)
7902{
7903 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7904 vfp_conv (32);
7905}
7906
7907static void
7908do_vfp_dp_conv_32 (void)
7909{
7910 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7911 vfp_conv (32);
7912}
c19d1205
ZW
7913\f
7914/* FPA instructions. Also in a logical order. */
e16bb312 7915
c19d1205
ZW
7916static void
7917do_fpa_cmp (void)
7918{
7919 inst.instruction |= inst.operands[0].reg << 16;
7920 inst.instruction |= inst.operands[1].reg;
7921}
b99bd4ef
NC
7922
7923static void
c19d1205 7924do_fpa_ldmstm (void)
b99bd4ef 7925{
c19d1205
ZW
7926 inst.instruction |= inst.operands[0].reg << 12;
7927 switch (inst.operands[1].imm)
7928 {
7929 case 1: inst.instruction |= CP_T_X; break;
7930 case 2: inst.instruction |= CP_T_Y; break;
7931 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7932 case 4: break;
7933 default: abort ();
7934 }
b99bd4ef 7935
c19d1205
ZW
7936 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7937 {
7938 /* The instruction specified "ea" or "fd", so we can only accept
7939 [Rn]{!}. The instruction does not really support stacking or
7940 unstacking, so we have to emulate these by setting appropriate
7941 bits and offsets. */
7942 constraint (inst.reloc.exp.X_op != O_constant
7943 || inst.reloc.exp.X_add_number != 0,
7944 _("this instruction does not support indexing"));
b99bd4ef 7945
c19d1205
ZW
7946 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7947 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7948
c19d1205
ZW
7949 if (!(inst.instruction & INDEX_UP))
7950 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7951
c19d1205
ZW
7952 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7953 {
7954 inst.operands[2].preind = 0;
7955 inst.operands[2].postind = 1;
7956 }
7957 }
b99bd4ef 7958
c19d1205 7959 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7960}
c19d1205
ZW
7961\f
7962/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7963
c19d1205
ZW
7964static void
7965do_iwmmxt_tandorc (void)
7966{
7967 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7968}
b99bd4ef 7969
c19d1205
ZW
7970static void
7971do_iwmmxt_textrc (void)
7972{
7973 inst.instruction |= inst.operands[0].reg << 12;
7974 inst.instruction |= inst.operands[1].imm;
7975}
b99bd4ef
NC
7976
7977static void
c19d1205 7978do_iwmmxt_textrm (void)
b99bd4ef 7979{
c19d1205
ZW
7980 inst.instruction |= inst.operands[0].reg << 12;
7981 inst.instruction |= inst.operands[1].reg << 16;
7982 inst.instruction |= inst.operands[2].imm;
7983}
b99bd4ef 7984
c19d1205
ZW
7985static void
7986do_iwmmxt_tinsr (void)
7987{
7988 inst.instruction |= inst.operands[0].reg << 16;
7989 inst.instruction |= inst.operands[1].reg << 12;
7990 inst.instruction |= inst.operands[2].imm;
7991}
b99bd4ef 7992
c19d1205
ZW
7993static void
7994do_iwmmxt_tmia (void)
7995{
7996 inst.instruction |= inst.operands[0].reg << 5;
7997 inst.instruction |= inst.operands[1].reg;
7998 inst.instruction |= inst.operands[2].reg << 12;
7999}
b99bd4ef 8000
c19d1205
ZW
8001static void
8002do_iwmmxt_waligni (void)
8003{
8004 inst.instruction |= inst.operands[0].reg << 12;
8005 inst.instruction |= inst.operands[1].reg << 16;
8006 inst.instruction |= inst.operands[2].reg;
8007 inst.instruction |= inst.operands[3].imm << 20;
8008}
b99bd4ef 8009
2d447fca
JM
8010static void
8011do_iwmmxt_wmerge (void)
8012{
8013 inst.instruction |= inst.operands[0].reg << 12;
8014 inst.instruction |= inst.operands[1].reg << 16;
8015 inst.instruction |= inst.operands[2].reg;
8016 inst.instruction |= inst.operands[3].imm << 21;
8017}
8018
c19d1205
ZW
8019static void
8020do_iwmmxt_wmov (void)
8021{
8022 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8023 inst.instruction |= inst.operands[0].reg << 12;
8024 inst.instruction |= inst.operands[1].reg << 16;
8025 inst.instruction |= inst.operands[1].reg;
8026}
b99bd4ef 8027
c19d1205
ZW
8028static void
8029do_iwmmxt_wldstbh (void)
8030{
8f06b2d8 8031 int reloc;
c19d1205 8032 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8033 if (thumb_mode)
8034 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8035 else
8036 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8037 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8038}
8039
c19d1205
ZW
8040static void
8041do_iwmmxt_wldstw (void)
8042{
8043 /* RIWR_RIWC clears .isreg for a control register. */
8044 if (!inst.operands[0].isreg)
8045 {
8046 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8047 inst.instruction |= 0xf0000000;
8048 }
b99bd4ef 8049
c19d1205
ZW
8050 inst.instruction |= inst.operands[0].reg << 12;
8051 encode_arm_cp_address (1, TRUE, TRUE, 0);
8052}
b99bd4ef
NC
8053
8054static void
c19d1205 8055do_iwmmxt_wldstd (void)
b99bd4ef 8056{
c19d1205 8057 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8058 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8059 && inst.operands[1].immisreg)
8060 {
8061 inst.instruction &= ~0x1a000ff;
8062 inst.instruction |= (0xf << 28);
8063 if (inst.operands[1].preind)
8064 inst.instruction |= PRE_INDEX;
8065 if (!inst.operands[1].negative)
8066 inst.instruction |= INDEX_UP;
8067 if (inst.operands[1].writeback)
8068 inst.instruction |= WRITE_BACK;
8069 inst.instruction |= inst.operands[1].reg << 16;
8070 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8071 inst.instruction |= inst.operands[1].imm;
8072 }
8073 else
8074 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8075}
b99bd4ef 8076
c19d1205
ZW
8077static void
8078do_iwmmxt_wshufh (void)
8079{
8080 inst.instruction |= inst.operands[0].reg << 12;
8081 inst.instruction |= inst.operands[1].reg << 16;
8082 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8083 inst.instruction |= (inst.operands[2].imm & 0x0f);
8084}
b99bd4ef 8085
c19d1205
ZW
8086static void
8087do_iwmmxt_wzero (void)
8088{
8089 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8090 inst.instruction |= inst.operands[0].reg;
8091 inst.instruction |= inst.operands[0].reg << 12;
8092 inst.instruction |= inst.operands[0].reg << 16;
8093}
2d447fca
JM
8094
8095static void
8096do_iwmmxt_wrwrwr_or_imm5 (void)
8097{
8098 if (inst.operands[2].isreg)
8099 do_rd_rn_rm ();
8100 else {
8101 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8102 _("immediate operand requires iWMMXt2"));
8103 do_rd_rn ();
8104 if (inst.operands[2].imm == 0)
8105 {
8106 switch ((inst.instruction >> 20) & 0xf)
8107 {
8108 case 4:
8109 case 5:
8110 case 6:
5f4273c7 8111 case 7:
2d447fca
JM
8112 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8113 inst.operands[2].imm = 16;
8114 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8115 break;
8116 case 8:
8117 case 9:
8118 case 10:
8119 case 11:
8120 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8121 inst.operands[2].imm = 32;
8122 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8123 break;
8124 case 12:
8125 case 13:
8126 case 14:
8127 case 15:
8128 {
8129 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8130 unsigned long wrn;
8131 wrn = (inst.instruction >> 16) & 0xf;
8132 inst.instruction &= 0xff0fff0f;
8133 inst.instruction |= wrn;
8134 /* Bail out here; the instruction is now assembled. */
8135 return;
8136 }
8137 }
8138 }
8139 /* Map 32 -> 0, etc. */
8140 inst.operands[2].imm &= 0x1f;
8141 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8142 }
8143}
c19d1205
ZW
8144\f
8145/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8146 operations first, then control, shift, and load/store. */
b99bd4ef 8147
c19d1205 8148/* Insns like "foo X,Y,Z". */
b99bd4ef 8149
c19d1205
ZW
8150static void
8151do_mav_triple (void)
8152{
8153 inst.instruction |= inst.operands[0].reg << 16;
8154 inst.instruction |= inst.operands[1].reg;
8155 inst.instruction |= inst.operands[2].reg << 12;
8156}
b99bd4ef 8157
c19d1205
ZW
8158/* Insns like "foo W,X,Y,Z".
8159 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8160
c19d1205
ZW
8161static void
8162do_mav_quad (void)
8163{
8164 inst.instruction |= inst.operands[0].reg << 5;
8165 inst.instruction |= inst.operands[1].reg << 12;
8166 inst.instruction |= inst.operands[2].reg << 16;
8167 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8168}
8169
c19d1205
ZW
8170/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8171static void
8172do_mav_dspsc (void)
a737bd4d 8173{
c19d1205
ZW
8174 inst.instruction |= inst.operands[1].reg << 12;
8175}
a737bd4d 8176
c19d1205
ZW
8177/* Maverick shift immediate instructions.
8178 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8179 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8180
c19d1205
ZW
8181static void
8182do_mav_shift (void)
8183{
8184 int imm = inst.operands[2].imm;
a737bd4d 8185
c19d1205
ZW
8186 inst.instruction |= inst.operands[0].reg << 12;
8187 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8188
c19d1205
ZW
8189 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8190 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8191 Bit 4 should be 0. */
8192 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8193
c19d1205
ZW
8194 inst.instruction |= imm;
8195}
8196\f
8197/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8198
c19d1205
ZW
8199/* Xscale multiply-accumulate (argument parse)
8200 MIAcc acc0,Rm,Rs
8201 MIAPHcc acc0,Rm,Rs
8202 MIAxycc acc0,Rm,Rs. */
a737bd4d 8203
c19d1205
ZW
8204static void
8205do_xsc_mia (void)
8206{
8207 inst.instruction |= inst.operands[1].reg;
8208 inst.instruction |= inst.operands[2].reg << 12;
8209}
a737bd4d 8210
c19d1205 8211/* Xscale move-accumulator-register (argument parse)
a737bd4d 8212
c19d1205 8213 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8214
c19d1205
ZW
8215static void
8216do_xsc_mar (void)
8217{
8218 inst.instruction |= inst.operands[1].reg << 12;
8219 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8220}
8221
c19d1205 8222/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8223
c19d1205 8224 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8225
8226static void
c19d1205 8227do_xsc_mra (void)
b99bd4ef 8228{
c19d1205
ZW
8229 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8230 inst.instruction |= inst.operands[0].reg << 12;
8231 inst.instruction |= inst.operands[1].reg << 16;
8232}
8233\f
8234/* Encoding functions relevant only to Thumb. */
b99bd4ef 8235
c19d1205
ZW
8236/* inst.operands[i] is a shifted-register operand; encode
8237 it into inst.instruction in the format used by Thumb32. */
8238
8239static void
8240encode_thumb32_shifted_operand (int i)
8241{
8242 unsigned int value = inst.reloc.exp.X_add_number;
8243 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8244
9c3c69f2
PB
8245 constraint (inst.operands[i].immisreg,
8246 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8247 inst.instruction |= inst.operands[i].reg;
8248 if (shift == SHIFT_RRX)
8249 inst.instruction |= SHIFT_ROR << 4;
8250 else
b99bd4ef 8251 {
c19d1205
ZW
8252 constraint (inst.reloc.exp.X_op != O_constant,
8253 _("expression too complex"));
8254
8255 constraint (value > 32
8256 || (value == 32 && (shift == SHIFT_LSL
8257 || shift == SHIFT_ROR)),
8258 _("shift expression is too large"));
8259
8260 if (value == 0)
8261 shift = SHIFT_LSL;
8262 else if (value == 32)
8263 value = 0;
8264
8265 inst.instruction |= shift << 4;
8266 inst.instruction |= (value & 0x1c) << 10;
8267 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8268 }
c19d1205 8269}
b99bd4ef 8270
b99bd4ef 8271
c19d1205
ZW
8272/* inst.operands[i] was set up by parse_address. Encode it into a
8273 Thumb32 format load or store instruction. Reject forms that cannot
8274 be used with such instructions. If is_t is true, reject forms that
8275 cannot be used with a T instruction; if is_d is true, reject forms
8276 that cannot be used with a D instruction. */
b99bd4ef 8277
c19d1205
ZW
8278static void
8279encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8280{
8281 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8282
8283 constraint (!inst.operands[i].isreg,
53365c0d 8284 _("Instruction does not support =N addresses"));
b99bd4ef 8285
c19d1205
ZW
8286 inst.instruction |= inst.operands[i].reg << 16;
8287 if (inst.operands[i].immisreg)
b99bd4ef 8288 {
c19d1205
ZW
8289 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8290 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8291 constraint (inst.operands[i].negative,
8292 _("Thumb does not support negative register indexing"));
8293 constraint (inst.operands[i].postind,
8294 _("Thumb does not support register post-indexing"));
8295 constraint (inst.operands[i].writeback,
8296 _("Thumb does not support register indexing with writeback"));
8297 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8298 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8299
f40d1643 8300 inst.instruction |= inst.operands[i].imm;
c19d1205 8301 if (inst.operands[i].shifted)
b99bd4ef 8302 {
c19d1205
ZW
8303 constraint (inst.reloc.exp.X_op != O_constant,
8304 _("expression too complex"));
9c3c69f2
PB
8305 constraint (inst.reloc.exp.X_add_number < 0
8306 || inst.reloc.exp.X_add_number > 3,
c19d1205 8307 _("shift out of range"));
9c3c69f2 8308 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8309 }
8310 inst.reloc.type = BFD_RELOC_UNUSED;
8311 }
8312 else if (inst.operands[i].preind)
8313 {
8314 constraint (is_pc && inst.operands[i].writeback,
8315 _("cannot use writeback with PC-relative addressing"));
f40d1643 8316 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8317 _("cannot use writeback with this instruction"));
8318
8319 if (is_d)
8320 {
8321 inst.instruction |= 0x01000000;
8322 if (inst.operands[i].writeback)
8323 inst.instruction |= 0x00200000;
b99bd4ef 8324 }
c19d1205 8325 else
b99bd4ef 8326 {
c19d1205
ZW
8327 inst.instruction |= 0x00000c00;
8328 if (inst.operands[i].writeback)
8329 inst.instruction |= 0x00000100;
b99bd4ef 8330 }
c19d1205 8331 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8332 }
c19d1205 8333 else if (inst.operands[i].postind)
b99bd4ef 8334 {
c19d1205
ZW
8335 assert (inst.operands[i].writeback);
8336 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8337 constraint (is_t, _("cannot use post-indexing with this instruction"));
8338
8339 if (is_d)
8340 inst.instruction |= 0x00200000;
8341 else
8342 inst.instruction |= 0x00000900;
8343 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8344 }
8345 else /* unindexed - only for coprocessor */
8346 inst.error = _("instruction does not accept unindexed addressing");
8347}
8348
8349/* Table of Thumb instructions which exist in both 16- and 32-bit
8350 encodings (the latter only in post-V6T2 cores). The index is the
8351 value used in the insns table below. When there is more than one
8352 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8353 holds variant (1).
8354 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8355#define T16_32_TAB \
8356 X(adc, 4140, eb400000), \
8357 X(adcs, 4140, eb500000), \
8358 X(add, 1c00, eb000000), \
8359 X(adds, 1c00, eb100000), \
0110f2b8
PB
8360 X(addi, 0000, f1000000), \
8361 X(addis, 0000, f1100000), \
8362 X(add_pc,000f, f20f0000), \
8363 X(add_sp,000d, f10d0000), \
e9f89963 8364 X(adr, 000f, f20f0000), \
c19d1205
ZW
8365 X(and, 4000, ea000000), \
8366 X(ands, 4000, ea100000), \
8367 X(asr, 1000, fa40f000), \
8368 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8369 X(b, e000, f000b000), \
8370 X(bcond, d000, f0008000), \
c19d1205
ZW
8371 X(bic, 4380, ea200000), \
8372 X(bics, 4380, ea300000), \
8373 X(cmn, 42c0, eb100f00), \
8374 X(cmp, 2800, ebb00f00), \
8375 X(cpsie, b660, f3af8400), \
8376 X(cpsid, b670, f3af8600), \
8377 X(cpy, 4600, ea4f0000), \
155257ea 8378 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8379 X(eor, 4040, ea800000), \
8380 X(eors, 4040, ea900000), \
0110f2b8 8381 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8382 X(ldmia, c800, e8900000), \
8383 X(ldr, 6800, f8500000), \
8384 X(ldrb, 7800, f8100000), \
8385 X(ldrh, 8800, f8300000), \
8386 X(ldrsb, 5600, f9100000), \
8387 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8388 X(ldr_pc,4800, f85f0000), \
8389 X(ldr_pc2,4800, f85f0000), \
8390 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8391 X(lsl, 0000, fa00f000), \
8392 X(lsls, 0000, fa10f000), \
8393 X(lsr, 0800, fa20f000), \
8394 X(lsrs, 0800, fa30f000), \
8395 X(mov, 2000, ea4f0000), \
8396 X(movs, 2000, ea5f0000), \
8397 X(mul, 4340, fb00f000), \
8398 X(muls, 4340, ffffffff), /* no 32b muls */ \
8399 X(mvn, 43c0, ea6f0000), \
8400 X(mvns, 43c0, ea7f0000), \
8401 X(neg, 4240, f1c00000), /* rsb #0 */ \
8402 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8403 X(orr, 4300, ea400000), \
8404 X(orrs, 4300, ea500000), \
e9f89963
PB
8405 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8406 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8407 X(rev, ba00, fa90f080), \
8408 X(rev16, ba40, fa90f090), \
8409 X(revsh, bac0, fa90f0b0), \
8410 X(ror, 41c0, fa60f000), \
8411 X(rors, 41c0, fa70f000), \
8412 X(sbc, 4180, eb600000), \
8413 X(sbcs, 4180, eb700000), \
8414 X(stmia, c000, e8800000), \
8415 X(str, 6000, f8400000), \
8416 X(strb, 7000, f8000000), \
8417 X(strh, 8000, f8200000), \
0110f2b8 8418 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8419 X(sub, 1e00, eba00000), \
8420 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8421 X(subi, 8000, f1a00000), \
8422 X(subis, 8000, f1b00000), \
c19d1205
ZW
8423 X(sxtb, b240, fa4ff080), \
8424 X(sxth, b200, fa0ff080), \
8425 X(tst, 4200, ea100f00), \
8426 X(uxtb, b2c0, fa5ff080), \
8427 X(uxth, b280, fa1ff080), \
8428 X(nop, bf00, f3af8000), \
8429 X(yield, bf10, f3af8001), \
8430 X(wfe, bf20, f3af8002), \
8431 X(wfi, bf30, f3af8003), \
fe2ceba1 8432 X(sev, bf40, f3af8004),
c19d1205
ZW
8433
8434/* To catch errors in encoding functions, the codes are all offset by
8435 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8436 as 16-bit instructions. */
8437#define X(a,b,c) T_MNEM_##a
8438enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8439#undef X
8440
8441#define X(a,b,c) 0x##b
8442static const unsigned short thumb_op16[] = { T16_32_TAB };
8443#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8444#undef X
8445
8446#define X(a,b,c) 0x##c
8447static const unsigned int thumb_op32[] = { T16_32_TAB };
8448#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8449#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8450#undef X
8451#undef T16_32_TAB
8452
8453/* Thumb instruction encoders, in alphabetical order. */
8454
92e90b6e
PB
8455/* ADDW or SUBW. */
8456static void
8457do_t_add_sub_w (void)
8458{
8459 int Rd, Rn;
8460
8461 Rd = inst.operands[0].reg;
8462 Rn = inst.operands[1].reg;
8463
fdfde340
JM
8464 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8465 SP-{plus,minute}-immediate form of the instruction. */
8466 reject_bad_reg (Rd);
8467
92e90b6e
PB
8468 inst.instruction |= (Rn << 16) | (Rd << 8);
8469 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8470}
8471
c19d1205
ZW
8472/* Parse an add or subtract instruction. We get here with inst.instruction
8473 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8474
8475static void
8476do_t_add_sub (void)
8477{
8478 int Rd, Rs, Rn;
8479
8480 Rd = inst.operands[0].reg;
8481 Rs = (inst.operands[1].present
8482 ? inst.operands[1].reg /* Rd, Rs, foo */
8483 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8484
8485 if (unified_syntax)
8486 {
0110f2b8
PB
8487 bfd_boolean flags;
8488 bfd_boolean narrow;
8489 int opcode;
8490
8491 flags = (inst.instruction == T_MNEM_adds
8492 || inst.instruction == T_MNEM_subs);
8493 if (flags)
8494 narrow = (current_it_mask == 0);
8495 else
8496 narrow = (current_it_mask != 0);
c19d1205 8497 if (!inst.operands[2].isreg)
b99bd4ef 8498 {
16805f35
PB
8499 int add;
8500
fdfde340
JM
8501 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8502
16805f35
PB
8503 add = (inst.instruction == T_MNEM_add
8504 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8505 opcode = 0;
8506 if (inst.size_req != 4)
8507 {
0110f2b8
PB
8508 /* Attempt to use a narrow opcode, with relaxation if
8509 appropriate. */
8510 if (Rd == REG_SP && Rs == REG_SP && !flags)
8511 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8512 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8513 opcode = T_MNEM_add_sp;
8514 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8515 opcode = T_MNEM_add_pc;
8516 else if (Rd <= 7 && Rs <= 7 && narrow)
8517 {
8518 if (flags)
8519 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8520 else
8521 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8522 }
8523 if (opcode)
8524 {
8525 inst.instruction = THUMB_OP16(opcode);
8526 inst.instruction |= (Rd << 4) | Rs;
8527 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8528 if (inst.size_req != 2)
8529 inst.relax = opcode;
8530 }
8531 else
8532 constraint (inst.size_req == 2, BAD_HIREG);
8533 }
8534 if (inst.size_req == 4
8535 || (inst.size_req != 2 && !opcode))
8536 {
efd81785
PB
8537 if (Rd == REG_PC)
8538 {
fdfde340 8539 constraint (add, BAD_PC);
efd81785
PB
8540 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8541 _("only SUBS PC, LR, #const allowed"));
8542 constraint (inst.reloc.exp.X_op != O_constant,
8543 _("expression too complex"));
8544 constraint (inst.reloc.exp.X_add_number < 0
8545 || inst.reloc.exp.X_add_number > 0xff,
8546 _("immediate value out of range"));
8547 inst.instruction = T2_SUBS_PC_LR
8548 | inst.reloc.exp.X_add_number;
8549 inst.reloc.type = BFD_RELOC_UNUSED;
8550 return;
8551 }
8552 else if (Rs == REG_PC)
16805f35
PB
8553 {
8554 /* Always use addw/subw. */
8555 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8556 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8557 }
8558 else
8559 {
8560 inst.instruction = THUMB_OP32 (inst.instruction);
8561 inst.instruction = (inst.instruction & 0xe1ffffff)
8562 | 0x10000000;
8563 if (flags)
8564 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8565 else
8566 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8567 }
dc4503c6
PB
8568 inst.instruction |= Rd << 8;
8569 inst.instruction |= Rs << 16;
0110f2b8 8570 }
b99bd4ef 8571 }
c19d1205
ZW
8572 else
8573 {
8574 Rn = inst.operands[2].reg;
8575 /* See if we can do this with a 16-bit instruction. */
8576 if (!inst.operands[2].shifted && inst.size_req != 4)
8577 {
e27ec89e
PB
8578 if (Rd > 7 || Rs > 7 || Rn > 7)
8579 narrow = FALSE;
8580
8581 if (narrow)
c19d1205 8582 {
e27ec89e
PB
8583 inst.instruction = ((inst.instruction == T_MNEM_adds
8584 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8585 ? T_OPCODE_ADD_R3
8586 : T_OPCODE_SUB_R3);
8587 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8588 return;
8589 }
b99bd4ef 8590
7e806470 8591 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8592 {
7e806470
PB
8593 /* Thumb-1 cores (except v6-M) require at least one high
8594 register in a narrow non flag setting add. */
8595 if (Rd > 7 || Rn > 7
8596 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8597 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8598 {
7e806470
PB
8599 if (Rd == Rn)
8600 {
8601 Rn = Rs;
8602 Rs = Rd;
8603 }
c19d1205
ZW
8604 inst.instruction = T_OPCODE_ADD_HI;
8605 inst.instruction |= (Rd & 8) << 4;
8606 inst.instruction |= (Rd & 7);
8607 inst.instruction |= Rn << 3;
8608 return;
8609 }
c19d1205
ZW
8610 }
8611 }
fdfde340
JM
8612
8613 constraint (Rd == REG_PC, BAD_PC);
8614 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8615 constraint (Rs == REG_PC, BAD_PC);
8616 reject_bad_reg (Rn);
8617
c19d1205
ZW
8618 /* If we get here, it can't be done in 16 bits. */
8619 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8620 _("shift must be constant"));
8621 inst.instruction = THUMB_OP32 (inst.instruction);
8622 inst.instruction |= Rd << 8;
8623 inst.instruction |= Rs << 16;
8624 encode_thumb32_shifted_operand (2);
8625 }
8626 }
8627 else
8628 {
8629 constraint (inst.instruction == T_MNEM_adds
8630 || inst.instruction == T_MNEM_subs,
8631 BAD_THUMB32);
b99bd4ef 8632
c19d1205 8633 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8634 {
c19d1205
ZW
8635 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8636 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8637 BAD_HIREG);
8638
8639 inst.instruction = (inst.instruction == T_MNEM_add
8640 ? 0x0000 : 0x8000);
8641 inst.instruction |= (Rd << 4) | Rs;
8642 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8643 return;
8644 }
8645
c19d1205
ZW
8646 Rn = inst.operands[2].reg;
8647 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8648
c19d1205
ZW
8649 /* We now have Rd, Rs, and Rn set to registers. */
8650 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8651 {
c19d1205
ZW
8652 /* Can't do this for SUB. */
8653 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8654 inst.instruction = T_OPCODE_ADD_HI;
8655 inst.instruction |= (Rd & 8) << 4;
8656 inst.instruction |= (Rd & 7);
8657 if (Rs == Rd)
8658 inst.instruction |= Rn << 3;
8659 else if (Rn == Rd)
8660 inst.instruction |= Rs << 3;
8661 else
8662 constraint (1, _("dest must overlap one source register"));
8663 }
8664 else
8665 {
8666 inst.instruction = (inst.instruction == T_MNEM_add
8667 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8668 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8669 }
b99bd4ef 8670 }
b99bd4ef
NC
8671}
8672
c19d1205
ZW
8673static void
8674do_t_adr (void)
8675{
fdfde340
JM
8676 unsigned Rd;
8677
8678 Rd = inst.operands[0].reg;
8679 reject_bad_reg (Rd);
8680
8681 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
8682 {
8683 /* Defer to section relaxation. */
8684 inst.relax = inst.instruction;
8685 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 8686 inst.instruction |= Rd << 4;
0110f2b8
PB
8687 }
8688 else if (unified_syntax && inst.size_req != 2)
e9f89963 8689 {
0110f2b8 8690 /* Generate a 32-bit opcode. */
e9f89963 8691 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 8692 inst.instruction |= Rd << 8;
e9f89963
PB
8693 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8694 inst.reloc.pc_rel = 1;
8695 }
8696 else
8697 {
0110f2b8 8698 /* Generate a 16-bit opcode. */
e9f89963
PB
8699 inst.instruction = THUMB_OP16 (inst.instruction);
8700 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8701 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8702 inst.reloc.pc_rel = 1;
b99bd4ef 8703
fdfde340 8704 inst.instruction |= Rd << 4;
e9f89963 8705 }
c19d1205 8706}
b99bd4ef 8707
c19d1205
ZW
8708/* Arithmetic instructions for which there is just one 16-bit
8709 instruction encoding, and it allows only two low registers.
8710 For maximal compatibility with ARM syntax, we allow three register
8711 operands even when Thumb-32 instructions are not available, as long
8712 as the first two are identical. For instance, both "sbc r0,r1" and
8713 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8714static void
c19d1205 8715do_t_arit3 (void)
b99bd4ef 8716{
c19d1205 8717 int Rd, Rs, Rn;
b99bd4ef 8718
c19d1205
ZW
8719 Rd = inst.operands[0].reg;
8720 Rs = (inst.operands[1].present
8721 ? inst.operands[1].reg /* Rd, Rs, foo */
8722 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8723 Rn = inst.operands[2].reg;
b99bd4ef 8724
fdfde340
JM
8725 reject_bad_reg (Rd);
8726 reject_bad_reg (Rs);
8727 if (inst.operands[2].isreg)
8728 reject_bad_reg (Rn);
8729
c19d1205 8730 if (unified_syntax)
b99bd4ef 8731 {
c19d1205
ZW
8732 if (!inst.operands[2].isreg)
8733 {
8734 /* For an immediate, we always generate a 32-bit opcode;
8735 section relaxation will shrink it later if possible. */
8736 inst.instruction = THUMB_OP32 (inst.instruction);
8737 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8738 inst.instruction |= Rd << 8;
8739 inst.instruction |= Rs << 16;
8740 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8741 }
8742 else
8743 {
e27ec89e
PB
8744 bfd_boolean narrow;
8745
c19d1205 8746 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8747 if (THUMB_SETS_FLAGS (inst.instruction))
8748 narrow = current_it_mask == 0;
8749 else
8750 narrow = current_it_mask != 0;
8751
8752 if (Rd > 7 || Rn > 7 || Rs > 7)
8753 narrow = FALSE;
8754 if (inst.operands[2].shifted)
8755 narrow = FALSE;
8756 if (inst.size_req == 4)
8757 narrow = FALSE;
8758
8759 if (narrow
c19d1205
ZW
8760 && Rd == Rs)
8761 {
8762 inst.instruction = THUMB_OP16 (inst.instruction);
8763 inst.instruction |= Rd;
8764 inst.instruction |= Rn << 3;
8765 return;
8766 }
b99bd4ef 8767
c19d1205
ZW
8768 /* If we get here, it can't be done in 16 bits. */
8769 constraint (inst.operands[2].shifted
8770 && inst.operands[2].immisreg,
8771 _("shift must be constant"));
8772 inst.instruction = THUMB_OP32 (inst.instruction);
8773 inst.instruction |= Rd << 8;
8774 inst.instruction |= Rs << 16;
8775 encode_thumb32_shifted_operand (2);
8776 }
a737bd4d 8777 }
c19d1205 8778 else
b99bd4ef 8779 {
c19d1205
ZW
8780 /* On its face this is a lie - the instruction does set the
8781 flags. However, the only supported mnemonic in this mode
8782 says it doesn't. */
8783 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8784
c19d1205
ZW
8785 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8786 _("unshifted register required"));
8787 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8788 constraint (Rd != Rs,
8789 _("dest and source1 must be the same register"));
a737bd4d 8790
c19d1205
ZW
8791 inst.instruction = THUMB_OP16 (inst.instruction);
8792 inst.instruction |= Rd;
8793 inst.instruction |= Rn << 3;
b99bd4ef 8794 }
a737bd4d 8795}
b99bd4ef 8796
c19d1205
ZW
8797/* Similarly, but for instructions where the arithmetic operation is
8798 commutative, so we can allow either of them to be different from
8799 the destination operand in a 16-bit instruction. For instance, all
8800 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8801 accepted. */
8802static void
8803do_t_arit3c (void)
a737bd4d 8804{
c19d1205 8805 int Rd, Rs, Rn;
b99bd4ef 8806
c19d1205
ZW
8807 Rd = inst.operands[0].reg;
8808 Rs = (inst.operands[1].present
8809 ? inst.operands[1].reg /* Rd, Rs, foo */
8810 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8811 Rn = inst.operands[2].reg;
fdfde340
JM
8812
8813 reject_bad_reg (Rd);
8814 reject_bad_reg (Rs);
8815 if (inst.operands[2].isreg)
8816 reject_bad_reg (Rn);
a737bd4d 8817
c19d1205 8818 if (unified_syntax)
a737bd4d 8819 {
c19d1205 8820 if (!inst.operands[2].isreg)
b99bd4ef 8821 {
c19d1205
ZW
8822 /* For an immediate, we always generate a 32-bit opcode;
8823 section relaxation will shrink it later if possible. */
8824 inst.instruction = THUMB_OP32 (inst.instruction);
8825 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8826 inst.instruction |= Rd << 8;
8827 inst.instruction |= Rs << 16;
8828 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8829 }
c19d1205 8830 else
a737bd4d 8831 {
e27ec89e
PB
8832 bfd_boolean narrow;
8833
c19d1205 8834 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8835 if (THUMB_SETS_FLAGS (inst.instruction))
8836 narrow = current_it_mask == 0;
8837 else
8838 narrow = current_it_mask != 0;
8839
8840 if (Rd > 7 || Rn > 7 || Rs > 7)
8841 narrow = FALSE;
8842 if (inst.operands[2].shifted)
8843 narrow = FALSE;
8844 if (inst.size_req == 4)
8845 narrow = FALSE;
8846
8847 if (narrow)
a737bd4d 8848 {
c19d1205 8849 if (Rd == Rs)
a737bd4d 8850 {
c19d1205
ZW
8851 inst.instruction = THUMB_OP16 (inst.instruction);
8852 inst.instruction |= Rd;
8853 inst.instruction |= Rn << 3;
8854 return;
a737bd4d 8855 }
c19d1205 8856 if (Rd == Rn)
a737bd4d 8857 {
c19d1205
ZW
8858 inst.instruction = THUMB_OP16 (inst.instruction);
8859 inst.instruction |= Rd;
8860 inst.instruction |= Rs << 3;
8861 return;
a737bd4d
NC
8862 }
8863 }
c19d1205
ZW
8864
8865 /* If we get here, it can't be done in 16 bits. */
8866 constraint (inst.operands[2].shifted
8867 && inst.operands[2].immisreg,
8868 _("shift must be constant"));
8869 inst.instruction = THUMB_OP32 (inst.instruction);
8870 inst.instruction |= Rd << 8;
8871 inst.instruction |= Rs << 16;
8872 encode_thumb32_shifted_operand (2);
a737bd4d 8873 }
b99bd4ef 8874 }
c19d1205
ZW
8875 else
8876 {
8877 /* On its face this is a lie - the instruction does set the
8878 flags. However, the only supported mnemonic in this mode
8879 says it doesn't. */
8880 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8881
c19d1205
ZW
8882 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8883 _("unshifted register required"));
8884 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8885
8886 inst.instruction = THUMB_OP16 (inst.instruction);
8887 inst.instruction |= Rd;
8888
8889 if (Rd == Rs)
8890 inst.instruction |= Rn << 3;
8891 else if (Rd == Rn)
8892 inst.instruction |= Rs << 3;
8893 else
8894 constraint (1, _("dest must overlap one source register"));
8895 }
a737bd4d
NC
8896}
8897
62b3e311
PB
8898static void
8899do_t_barrier (void)
8900{
8901 if (inst.operands[0].present)
8902 {
8903 constraint ((inst.instruction & 0xf0) != 0x40
8904 && inst.operands[0].imm != 0xf,
bd3ba5d1 8905 _("bad barrier type"));
62b3e311
PB
8906 inst.instruction |= inst.operands[0].imm;
8907 }
8908 else
8909 inst.instruction |= 0xf;
8910}
8911
c19d1205
ZW
8912static void
8913do_t_bfc (void)
a737bd4d 8914{
fdfde340 8915 unsigned Rd;
c19d1205
ZW
8916 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8917 constraint (msb > 32, _("bit-field extends past end of register"));
8918 /* The instruction encoding stores the LSB and MSB,
8919 not the LSB and width. */
fdfde340
JM
8920 Rd = inst.operands[0].reg;
8921 reject_bad_reg (Rd);
8922 inst.instruction |= Rd << 8;
c19d1205
ZW
8923 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8924 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8925 inst.instruction |= msb - 1;
b99bd4ef
NC
8926}
8927
c19d1205
ZW
8928static void
8929do_t_bfi (void)
b99bd4ef 8930{
fdfde340 8931 int Rd, Rn;
c19d1205 8932 unsigned int msb;
b99bd4ef 8933
fdfde340
JM
8934 Rd = inst.operands[0].reg;
8935 reject_bad_reg (Rd);
8936
c19d1205
ZW
8937 /* #0 in second position is alternative syntax for bfc, which is
8938 the same instruction but with REG_PC in the Rm field. */
8939 if (!inst.operands[1].isreg)
fdfde340
JM
8940 Rn = REG_PC;
8941 else
8942 {
8943 Rn = inst.operands[1].reg;
8944 reject_bad_reg (Rn);
8945 }
b99bd4ef 8946
c19d1205
ZW
8947 msb = inst.operands[2].imm + inst.operands[3].imm;
8948 constraint (msb > 32, _("bit-field extends past end of register"));
8949 /* The instruction encoding stores the LSB and MSB,
8950 not the LSB and width. */
fdfde340
JM
8951 inst.instruction |= Rd << 8;
8952 inst.instruction |= Rn << 16;
c19d1205
ZW
8953 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8954 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8955 inst.instruction |= msb - 1;
b99bd4ef
NC
8956}
8957
c19d1205
ZW
8958static void
8959do_t_bfx (void)
b99bd4ef 8960{
fdfde340
JM
8961 unsigned Rd, Rn;
8962
8963 Rd = inst.operands[0].reg;
8964 Rn = inst.operands[1].reg;
8965
8966 reject_bad_reg (Rd);
8967 reject_bad_reg (Rn);
8968
c19d1205
ZW
8969 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8970 _("bit-field extends past end of register"));
fdfde340
JM
8971 inst.instruction |= Rd << 8;
8972 inst.instruction |= Rn << 16;
c19d1205
ZW
8973 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8974 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8975 inst.instruction |= inst.operands[3].imm - 1;
8976}
b99bd4ef 8977
c19d1205
ZW
8978/* ARM V5 Thumb BLX (argument parse)
8979 BLX <target_addr> which is BLX(1)
8980 BLX <Rm> which is BLX(2)
8981 Unfortunately, there are two different opcodes for this mnemonic.
8982 So, the insns[].value is not used, and the code here zaps values
8983 into inst.instruction.
b99bd4ef 8984
c19d1205
ZW
8985 ??? How to take advantage of the additional two bits of displacement
8986 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8987
c19d1205
ZW
8988static void
8989do_t_blx (void)
8990{
dfa9f0d5 8991 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8992 if (inst.operands[0].isreg)
fdfde340
JM
8993 {
8994 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
8995 /* We have a register, so this is BLX(2). */
8996 inst.instruction |= inst.operands[0].reg << 3;
8997 }
b99bd4ef
NC
8998 else
8999 {
c19d1205 9000 /* No register. This must be BLX(1). */
2fc8bdac 9001 inst.instruction = 0xf000e800;
00adf2d4 9002 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9003 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9004 }
9005}
9006
c19d1205
ZW
9007static void
9008do_t_branch (void)
b99bd4ef 9009{
0110f2b8 9010 int opcode;
dfa9f0d5
PB
9011 int cond;
9012
9013 if (current_it_mask)
9014 {
9015 /* Conditional branches inside IT blocks are encoded as unconditional
9016 branches. */
9017 cond = COND_ALWAYS;
9018 /* A branch must be the last instruction in an IT block. */
9019 constraint (current_it_mask != 0x10, BAD_BRANCH);
9020 }
9021 else
9022 cond = inst.cond;
9023
9024 if (cond != COND_ALWAYS)
0110f2b8
PB
9025 opcode = T_MNEM_bcond;
9026 else
9027 opcode = inst.instruction;
9028
9029 if (unified_syntax && inst.size_req == 4)
c19d1205 9030 {
0110f2b8 9031 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9032 if (cond == COND_ALWAYS)
0110f2b8 9033 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9034 else
9035 {
dfa9f0d5
PB
9036 assert (cond != 0xF);
9037 inst.instruction |= cond << 22;
c19d1205
ZW
9038 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9039 }
9040 }
b99bd4ef
NC
9041 else
9042 {
0110f2b8 9043 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9044 if (cond == COND_ALWAYS)
c19d1205
ZW
9045 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9046 else
b99bd4ef 9047 {
dfa9f0d5 9048 inst.instruction |= cond << 8;
c19d1205 9049 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9050 }
0110f2b8
PB
9051 /* Allow section relaxation. */
9052 if (unified_syntax && inst.size_req != 2)
9053 inst.relax = opcode;
b99bd4ef 9054 }
c19d1205
ZW
9055
9056 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9057}
9058
9059static void
c19d1205 9060do_t_bkpt (void)
b99bd4ef 9061{
dfa9f0d5
PB
9062 constraint (inst.cond != COND_ALWAYS,
9063 _("instruction is always unconditional"));
c19d1205 9064 if (inst.operands[0].present)
b99bd4ef 9065 {
c19d1205
ZW
9066 constraint (inst.operands[0].imm > 255,
9067 _("immediate value out of range"));
9068 inst.instruction |= inst.operands[0].imm;
b99bd4ef 9069 }
b99bd4ef
NC
9070}
9071
9072static void
c19d1205 9073do_t_branch23 (void)
b99bd4ef 9074{
dfa9f0d5 9075 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 9076 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9077 inst.reloc.pc_rel = 1;
9078
4343666d 9079#if defined(OBJ_COFF)
c19d1205
ZW
9080 /* If the destination of the branch is a defined symbol which does not have
9081 the THUMB_FUNC attribute, then we must be calling a function which has
9082 the (interfacearm) attribute. We look for the Thumb entry point to that
9083 function and change the branch to refer to that function instead. */
9084 if ( inst.reloc.exp.X_op == O_symbol
9085 && inst.reloc.exp.X_add_symbol != NULL
9086 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9087 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9088 inst.reloc.exp.X_add_symbol =
9089 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9090#endif
90e4755a
RE
9091}
9092
9093static void
c19d1205 9094do_t_bx (void)
90e4755a 9095{
dfa9f0d5 9096 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
9097 inst.instruction |= inst.operands[0].reg << 3;
9098 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9099 should cause the alignment to be checked once it is known. This is
9100 because BX PC only works if the instruction is word aligned. */
9101}
90e4755a 9102
c19d1205
ZW
9103static void
9104do_t_bxj (void)
9105{
fdfde340 9106 int Rm;
90e4755a 9107
fdfde340
JM
9108 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
9109 Rm = inst.operands[0].reg;
9110 reject_bad_reg (Rm);
9111 inst.instruction |= Rm << 16;
90e4755a
RE
9112}
9113
9114static void
c19d1205 9115do_t_clz (void)
90e4755a 9116{
fdfde340
JM
9117 unsigned Rd;
9118 unsigned Rm;
9119
9120 Rd = inst.operands[0].reg;
9121 Rm = inst.operands[1].reg;
9122
9123 reject_bad_reg (Rd);
9124 reject_bad_reg (Rm);
9125
9126 inst.instruction |= Rd << 8;
9127 inst.instruction |= Rm << 16;
9128 inst.instruction |= Rm;
c19d1205 9129}
90e4755a 9130
dfa9f0d5
PB
9131static void
9132do_t_cps (void)
9133{
9134 constraint (current_it_mask, BAD_NOT_IT);
9135 inst.instruction |= inst.operands[0].imm;
9136}
9137
c19d1205
ZW
9138static void
9139do_t_cpsi (void)
9140{
dfa9f0d5 9141 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9142 if (unified_syntax
62b3e311
PB
9143 && (inst.operands[1].present || inst.size_req == 4)
9144 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9145 {
c19d1205
ZW
9146 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9147 inst.instruction = 0xf3af8000;
9148 inst.instruction |= imod << 9;
9149 inst.instruction |= inst.operands[0].imm << 5;
9150 if (inst.operands[1].present)
9151 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9152 }
c19d1205 9153 else
90e4755a 9154 {
62b3e311
PB
9155 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9156 && (inst.operands[0].imm & 4),
9157 _("selected processor does not support 'A' form "
9158 "of this instruction"));
9159 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9160 _("Thumb does not support the 2-argument "
9161 "form of this instruction"));
9162 inst.instruction |= inst.operands[0].imm;
90e4755a 9163 }
90e4755a
RE
9164}
9165
c19d1205
ZW
9166/* THUMB CPY instruction (argument parse). */
9167
90e4755a 9168static void
c19d1205 9169do_t_cpy (void)
90e4755a 9170{
c19d1205 9171 if (inst.size_req == 4)
90e4755a 9172 {
c19d1205
ZW
9173 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9174 inst.instruction |= inst.operands[0].reg << 8;
9175 inst.instruction |= inst.operands[1].reg;
90e4755a 9176 }
c19d1205 9177 else
90e4755a 9178 {
c19d1205
ZW
9179 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9180 inst.instruction |= (inst.operands[0].reg & 0x7);
9181 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9182 }
90e4755a
RE
9183}
9184
90e4755a 9185static void
25fe350b 9186do_t_cbz (void)
90e4755a 9187{
dfa9f0d5 9188 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9189 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9190 inst.instruction |= inst.operands[0].reg;
9191 inst.reloc.pc_rel = 1;
9192 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9193}
90e4755a 9194
62b3e311
PB
9195static void
9196do_t_dbg (void)
9197{
9198 inst.instruction |= inst.operands[0].imm;
9199}
9200
9201static void
9202do_t_div (void)
9203{
fdfde340
JM
9204 unsigned Rd, Rn, Rm;
9205
9206 Rd = inst.operands[0].reg;
9207 Rn = (inst.operands[1].present
9208 ? inst.operands[1].reg : Rd);
9209 Rm = inst.operands[2].reg;
9210
9211 reject_bad_reg (Rd);
9212 reject_bad_reg (Rn);
9213 reject_bad_reg (Rm);
9214
9215 inst.instruction |= Rd << 8;
9216 inst.instruction |= Rn << 16;
9217 inst.instruction |= Rm;
62b3e311
PB
9218}
9219
c19d1205
ZW
9220static void
9221do_t_hint (void)
9222{
9223 if (unified_syntax && inst.size_req == 4)
9224 inst.instruction = THUMB_OP32 (inst.instruction);
9225 else
9226 inst.instruction = THUMB_OP16 (inst.instruction);
9227}
90e4755a 9228
c19d1205
ZW
9229static void
9230do_t_it (void)
9231{
9232 unsigned int cond = inst.operands[0].imm;
e27ec89e 9233
dfa9f0d5 9234 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9235 current_it_mask = (inst.instruction & 0xf) | 0x10;
9236 current_cc = cond;
9237
9238 /* If the condition is a negative condition, invert the mask. */
c19d1205 9239 if ((cond & 0x1) == 0x0)
90e4755a 9240 {
c19d1205 9241 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9242
c19d1205
ZW
9243 if ((mask & 0x7) == 0)
9244 /* no conversion needed */;
9245 else if ((mask & 0x3) == 0)
e27ec89e
PB
9246 mask ^= 0x8;
9247 else if ((mask & 0x1) == 0)
9248 mask ^= 0xC;
c19d1205 9249 else
e27ec89e 9250 mask ^= 0xE;
90e4755a 9251
e27ec89e
PB
9252 inst.instruction &= 0xfff0;
9253 inst.instruction |= mask;
c19d1205 9254 }
90e4755a 9255
c19d1205
ZW
9256 inst.instruction |= cond << 4;
9257}
90e4755a 9258
3c707909
PB
9259/* Helper function used for both push/pop and ldm/stm. */
9260static void
9261encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9262{
9263 bfd_boolean load;
9264
9265 load = (inst.instruction & (1 << 20)) != 0;
9266
9267 if (mask & (1 << 13))
9268 inst.error = _("SP not allowed in register list");
9269 if (load)
9270 {
9271 if (mask & (1 << 14)
9272 && mask & (1 << 15))
9273 inst.error = _("LR and PC should not both be in register list");
9274
9275 if ((mask & (1 << base)) != 0
9276 && writeback)
9277 as_warn (_("base register should not be in register list "
9278 "when written back"));
9279 }
9280 else
9281 {
9282 if (mask & (1 << 15))
9283 inst.error = _("PC not allowed in register list");
9284
9285 if (mask & (1 << base))
9286 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9287 }
9288
9289 if ((mask & (mask - 1)) == 0)
9290 {
9291 /* Single register transfers implemented as str/ldr. */
9292 if (writeback)
9293 {
9294 if (inst.instruction & (1 << 23))
9295 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9296 else
9297 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9298 }
9299 else
9300 {
9301 if (inst.instruction & (1 << 23))
9302 inst.instruction = 0x00800000; /* ia -> [base] */
9303 else
9304 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9305 }
9306
9307 inst.instruction |= 0xf8400000;
9308 if (load)
9309 inst.instruction |= 0x00100000;
9310
5f4273c7 9311 mask = ffs (mask) - 1;
3c707909
PB
9312 mask <<= 12;
9313 }
9314 else if (writeback)
9315 inst.instruction |= WRITE_BACK;
9316
9317 inst.instruction |= mask;
9318 inst.instruction |= base << 16;
9319}
9320
c19d1205
ZW
9321static void
9322do_t_ldmstm (void)
9323{
9324 /* This really doesn't seem worth it. */
9325 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9326 _("expression too complex"));
9327 constraint (inst.operands[1].writeback,
9328 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9329
c19d1205
ZW
9330 if (unified_syntax)
9331 {
3c707909
PB
9332 bfd_boolean narrow;
9333 unsigned mask;
9334
9335 narrow = FALSE;
c19d1205
ZW
9336 /* See if we can use a 16-bit instruction. */
9337 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9338 && inst.size_req != 4
3c707909 9339 && !(inst.operands[1].imm & ~0xff))
90e4755a 9340 {
3c707909 9341 mask = 1 << inst.operands[0].reg;
90e4755a 9342
3c707909
PB
9343 if (inst.operands[0].reg <= 7
9344 && (inst.instruction == T_MNEM_stmia
9345 ? inst.operands[0].writeback
9346 : (inst.operands[0].writeback
9347 == !(inst.operands[1].imm & mask))))
90e4755a 9348 {
3c707909
PB
9349 if (inst.instruction == T_MNEM_stmia
9350 && (inst.operands[1].imm & mask)
9351 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9352 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9353 inst.operands[0].reg);
3c707909
PB
9354
9355 inst.instruction = THUMB_OP16 (inst.instruction);
9356 inst.instruction |= inst.operands[0].reg << 8;
9357 inst.instruction |= inst.operands[1].imm;
9358 narrow = TRUE;
90e4755a 9359 }
3c707909
PB
9360 else if (inst.operands[0] .reg == REG_SP
9361 && inst.operands[0].writeback)
90e4755a 9362 {
3c707909
PB
9363 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9364 ? T_MNEM_push : T_MNEM_pop);
9365 inst.instruction |= inst.operands[1].imm;
9366 narrow = TRUE;
90e4755a 9367 }
3c707909
PB
9368 }
9369
9370 if (!narrow)
9371 {
c19d1205
ZW
9372 if (inst.instruction < 0xffff)
9373 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9374
5f4273c7
NC
9375 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9376 inst.operands[0].writeback);
90e4755a
RE
9377 }
9378 }
c19d1205 9379 else
90e4755a 9380 {
c19d1205
ZW
9381 constraint (inst.operands[0].reg > 7
9382 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9383 constraint (inst.instruction != T_MNEM_ldmia
9384 && inst.instruction != T_MNEM_stmia,
9385 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9386 if (inst.instruction == T_MNEM_stmia)
f03698e6 9387 {
c19d1205
ZW
9388 if (!inst.operands[0].writeback)
9389 as_warn (_("this instruction will write back the base register"));
9390 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9391 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9392 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9393 inst.operands[0].reg);
f03698e6 9394 }
c19d1205 9395 else
90e4755a 9396 {
c19d1205
ZW
9397 if (!inst.operands[0].writeback
9398 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9399 as_warn (_("this instruction will write back the base register"));
9400 else if (inst.operands[0].writeback
9401 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9402 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9403 }
9404
c19d1205
ZW
9405 inst.instruction = THUMB_OP16 (inst.instruction);
9406 inst.instruction |= inst.operands[0].reg << 8;
9407 inst.instruction |= inst.operands[1].imm;
9408 }
9409}
e28cd48c 9410
c19d1205
ZW
9411static void
9412do_t_ldrex (void)
9413{
9414 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9415 || inst.operands[1].postind || inst.operands[1].writeback
9416 || inst.operands[1].immisreg || inst.operands[1].shifted
9417 || inst.operands[1].negative,
01cfc07f 9418 BAD_ADDR_MODE);
e28cd48c 9419
c19d1205
ZW
9420 inst.instruction |= inst.operands[0].reg << 12;
9421 inst.instruction |= inst.operands[1].reg << 16;
9422 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9423}
e28cd48c 9424
c19d1205
ZW
9425static void
9426do_t_ldrexd (void)
9427{
9428 if (!inst.operands[1].present)
1cac9012 9429 {
c19d1205
ZW
9430 constraint (inst.operands[0].reg == REG_LR,
9431 _("r14 not allowed as first register "
9432 "when second register is omitted"));
9433 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9434 }
c19d1205
ZW
9435 constraint (inst.operands[0].reg == inst.operands[1].reg,
9436 BAD_OVERLAP);
b99bd4ef 9437
c19d1205
ZW
9438 inst.instruction |= inst.operands[0].reg << 12;
9439 inst.instruction |= inst.operands[1].reg << 8;
9440 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9441}
9442
9443static void
c19d1205 9444do_t_ldst (void)
b99bd4ef 9445{
0110f2b8
PB
9446 unsigned long opcode;
9447 int Rn;
9448
9449 opcode = inst.instruction;
c19d1205 9450 if (unified_syntax)
b99bd4ef 9451 {
53365c0d
PB
9452 if (!inst.operands[1].isreg)
9453 {
9454 if (opcode <= 0xffff)
9455 inst.instruction = THUMB_OP32 (opcode);
9456 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9457 return;
9458 }
0110f2b8
PB
9459 if (inst.operands[1].isreg
9460 && !inst.operands[1].writeback
c19d1205
ZW
9461 && !inst.operands[1].shifted && !inst.operands[1].postind
9462 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9463 && opcode <= 0xffff
9464 && inst.size_req != 4)
c19d1205 9465 {
0110f2b8
PB
9466 /* Insn may have a 16-bit form. */
9467 Rn = inst.operands[1].reg;
9468 if (inst.operands[1].immisreg)
9469 {
9470 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9471 /* [Rn, Rik] */
0110f2b8
PB
9472 if (Rn <= 7 && inst.operands[1].imm <= 7)
9473 goto op16;
9474 }
9475 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9476 && opcode != T_MNEM_ldrsb)
9477 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9478 || (Rn == REG_SP && opcode == T_MNEM_str))
9479 {
9480 /* [Rn, #const] */
9481 if (Rn > 7)
9482 {
9483 if (Rn == REG_PC)
9484 {
9485 if (inst.reloc.pc_rel)
9486 opcode = T_MNEM_ldr_pc2;
9487 else
9488 opcode = T_MNEM_ldr_pc;
9489 }
9490 else
9491 {
9492 if (opcode == T_MNEM_ldr)
9493 opcode = T_MNEM_ldr_sp;
9494 else
9495 opcode = T_MNEM_str_sp;
9496 }
9497 inst.instruction = inst.operands[0].reg << 8;
9498 }
9499 else
9500 {
9501 inst.instruction = inst.operands[0].reg;
9502 inst.instruction |= inst.operands[1].reg << 3;
9503 }
9504 inst.instruction |= THUMB_OP16 (opcode);
9505 if (inst.size_req == 2)
9506 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9507 else
9508 inst.relax = opcode;
9509 return;
9510 }
c19d1205 9511 }
0110f2b8
PB
9512 /* Definitely a 32-bit variant. */
9513 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9514 inst.instruction |= inst.operands[0].reg << 12;
9515 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9516 return;
9517 }
9518
c19d1205
ZW
9519 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9520
9521 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9522 {
c19d1205
ZW
9523 /* Only [Rn,Rm] is acceptable. */
9524 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9525 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9526 || inst.operands[1].postind || inst.operands[1].shifted
9527 || inst.operands[1].negative,
9528 _("Thumb does not support this addressing mode"));
9529 inst.instruction = THUMB_OP16 (inst.instruction);
9530 goto op16;
b99bd4ef 9531 }
5f4273c7 9532
c19d1205
ZW
9533 inst.instruction = THUMB_OP16 (inst.instruction);
9534 if (!inst.operands[1].isreg)
9535 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9536 return;
b99bd4ef 9537
c19d1205
ZW
9538 constraint (!inst.operands[1].preind
9539 || inst.operands[1].shifted
9540 || inst.operands[1].writeback,
9541 _("Thumb does not support this addressing mode"));
9542 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9543 {
c19d1205
ZW
9544 constraint (inst.instruction & 0x0600,
9545 _("byte or halfword not valid for base register"));
9546 constraint (inst.operands[1].reg == REG_PC
9547 && !(inst.instruction & THUMB_LOAD_BIT),
9548 _("r15 based store not allowed"));
9549 constraint (inst.operands[1].immisreg,
9550 _("invalid base register for register offset"));
b99bd4ef 9551
c19d1205
ZW
9552 if (inst.operands[1].reg == REG_PC)
9553 inst.instruction = T_OPCODE_LDR_PC;
9554 else if (inst.instruction & THUMB_LOAD_BIT)
9555 inst.instruction = T_OPCODE_LDR_SP;
9556 else
9557 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9558
c19d1205
ZW
9559 inst.instruction |= inst.operands[0].reg << 8;
9560 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9561 return;
9562 }
90e4755a 9563
c19d1205
ZW
9564 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9565 if (!inst.operands[1].immisreg)
9566 {
9567 /* Immediate offset. */
9568 inst.instruction |= inst.operands[0].reg;
9569 inst.instruction |= inst.operands[1].reg << 3;
9570 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9571 return;
9572 }
90e4755a 9573
c19d1205
ZW
9574 /* Register offset. */
9575 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9576 constraint (inst.operands[1].negative,
9577 _("Thumb does not support this addressing mode"));
90e4755a 9578
c19d1205
ZW
9579 op16:
9580 switch (inst.instruction)
9581 {
9582 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9583 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9584 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9585 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9586 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9587 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9588 case 0x5600 /* ldrsb */:
9589 case 0x5e00 /* ldrsh */: break;
9590 default: abort ();
9591 }
90e4755a 9592
c19d1205
ZW
9593 inst.instruction |= inst.operands[0].reg;
9594 inst.instruction |= inst.operands[1].reg << 3;
9595 inst.instruction |= inst.operands[1].imm << 6;
9596}
90e4755a 9597
c19d1205
ZW
9598static void
9599do_t_ldstd (void)
9600{
9601 if (!inst.operands[1].present)
b99bd4ef 9602 {
c19d1205
ZW
9603 inst.operands[1].reg = inst.operands[0].reg + 1;
9604 constraint (inst.operands[0].reg == REG_LR,
9605 _("r14 not allowed here"));
b99bd4ef 9606 }
c19d1205
ZW
9607 inst.instruction |= inst.operands[0].reg << 12;
9608 inst.instruction |= inst.operands[1].reg << 8;
9609 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9610}
9611
c19d1205
ZW
9612static void
9613do_t_ldstt (void)
9614{
9615 inst.instruction |= inst.operands[0].reg << 12;
9616 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9617}
a737bd4d 9618
b99bd4ef 9619static void
c19d1205 9620do_t_mla (void)
b99bd4ef 9621{
fdfde340
JM
9622 unsigned Rd, Rn, Rm, Ra;
9623
9624 Rd = inst.operands[0].reg;
9625 Rn = inst.operands[1].reg;
9626 Rm = inst.operands[2].reg;
9627 Ra = inst.operands[3].reg;
9628
9629 reject_bad_reg (Rd);
9630 reject_bad_reg (Rn);
9631 reject_bad_reg (Rm);
9632 reject_bad_reg (Ra);
9633
9634 inst.instruction |= Rd << 8;
9635 inst.instruction |= Rn << 16;
9636 inst.instruction |= Rm;
9637 inst.instruction |= Ra << 12;
c19d1205 9638}
b99bd4ef 9639
c19d1205
ZW
9640static void
9641do_t_mlal (void)
9642{
fdfde340
JM
9643 unsigned RdLo, RdHi, Rn, Rm;
9644
9645 RdLo = inst.operands[0].reg;
9646 RdHi = inst.operands[1].reg;
9647 Rn = inst.operands[2].reg;
9648 Rm = inst.operands[3].reg;
9649
9650 reject_bad_reg (RdLo);
9651 reject_bad_reg (RdHi);
9652 reject_bad_reg (Rn);
9653 reject_bad_reg (Rm);
9654
9655 inst.instruction |= RdLo << 12;
9656 inst.instruction |= RdHi << 8;
9657 inst.instruction |= Rn << 16;
9658 inst.instruction |= Rm;
c19d1205 9659}
b99bd4ef 9660
c19d1205
ZW
9661static void
9662do_t_mov_cmp (void)
9663{
fdfde340
JM
9664 unsigned Rn, Rm;
9665
9666 Rn = inst.operands[0].reg;
9667 Rm = inst.operands[1].reg;
9668
c19d1205 9669 if (unified_syntax)
b99bd4ef 9670 {
c19d1205
ZW
9671 int r0off = (inst.instruction == T_MNEM_mov
9672 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9673 unsigned long opcode;
3d388997
PB
9674 bfd_boolean narrow;
9675 bfd_boolean low_regs;
9676
fdfde340 9677 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 9678 opcode = inst.instruction;
3d388997 9679 if (current_it_mask)
0110f2b8 9680 narrow = opcode != T_MNEM_movs;
3d388997 9681 else
0110f2b8 9682 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9683 if (inst.size_req == 4
9684 || inst.operands[1].shifted)
9685 narrow = FALSE;
9686
efd81785
PB
9687 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9688 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9689 && !inst.operands[1].shifted
fdfde340
JM
9690 && Rn == REG_PC
9691 && Rm == REG_LR)
efd81785
PB
9692 {
9693 inst.instruction = T2_SUBS_PC_LR;
9694 return;
9695 }
9696
fdfde340
JM
9697 if (opcode == T_MNEM_cmp)
9698 {
9699 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
9700 if (narrow)
9701 {
9702 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9703 but valid. */
9704 warn_deprecated_sp (Rm);
9705 /* R15 was documented as a valid choice for Rm in ARMv6,
9706 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9707 tools reject R15, so we do too. */
9708 constraint (Rm == REG_PC, BAD_PC);
9709 }
9710 else
9711 reject_bad_reg (Rm);
fdfde340
JM
9712 }
9713 else if (opcode == T_MNEM_mov
9714 || opcode == T_MNEM_movs)
9715 {
9716 if (inst.operands[1].isreg)
9717 {
9718 if (opcode == T_MNEM_movs)
9719 {
9720 reject_bad_reg (Rn);
9721 reject_bad_reg (Rm);
9722 }
9723 else if ((Rn == REG_SP || Rn == REG_PC)
9724 && (Rm == REG_SP || Rm == REG_PC))
9725 reject_bad_reg (Rm);
9726 }
9727 else
9728 reject_bad_reg (Rn);
9729 }
9730
c19d1205
ZW
9731 if (!inst.operands[1].isreg)
9732 {
0110f2b8
PB
9733 /* Immediate operand. */
9734 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9735 narrow = 0;
9736 if (low_regs && narrow)
9737 {
9738 inst.instruction = THUMB_OP16 (opcode);
fdfde340 9739 inst.instruction |= Rn << 8;
0110f2b8
PB
9740 if (inst.size_req == 2)
9741 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9742 else
9743 inst.relax = opcode;
9744 }
9745 else
9746 {
9747 inst.instruction = THUMB_OP32 (inst.instruction);
9748 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9749 inst.instruction |= Rn << r0off;
0110f2b8
PB
9750 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9751 }
c19d1205 9752 }
728ca7c9
PB
9753 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9754 && (inst.instruction == T_MNEM_mov
9755 || inst.instruction == T_MNEM_movs))
9756 {
9757 /* Register shifts are encoded as separate shift instructions. */
9758 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9759
9760 if (current_it_mask)
9761 narrow = !flags;
9762 else
9763 narrow = flags;
9764
9765 if (inst.size_req == 4)
9766 narrow = FALSE;
9767
9768 if (!low_regs || inst.operands[1].imm > 7)
9769 narrow = FALSE;
9770
fdfde340 9771 if (Rn != Rm)
728ca7c9
PB
9772 narrow = FALSE;
9773
9774 switch (inst.operands[1].shift_kind)
9775 {
9776 case SHIFT_LSL:
9777 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9778 break;
9779 case SHIFT_ASR:
9780 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9781 break;
9782 case SHIFT_LSR:
9783 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9784 break;
9785 case SHIFT_ROR:
9786 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9787 break;
9788 default:
5f4273c7 9789 abort ();
728ca7c9
PB
9790 }
9791
9792 inst.instruction = opcode;
9793 if (narrow)
9794 {
fdfde340 9795 inst.instruction |= Rn;
728ca7c9
PB
9796 inst.instruction |= inst.operands[1].imm << 3;
9797 }
9798 else
9799 {
9800 if (flags)
9801 inst.instruction |= CONDS_BIT;
9802
fdfde340
JM
9803 inst.instruction |= Rn << 8;
9804 inst.instruction |= Rm << 16;
728ca7c9
PB
9805 inst.instruction |= inst.operands[1].imm;
9806 }
9807 }
3d388997 9808 else if (!narrow)
c19d1205 9809 {
728ca7c9
PB
9810 /* Some mov with immediate shift have narrow variants.
9811 Register shifts are handled above. */
9812 if (low_regs && inst.operands[1].shifted
9813 && (inst.instruction == T_MNEM_mov
9814 || inst.instruction == T_MNEM_movs))
9815 {
9816 if (current_it_mask)
9817 narrow = (inst.instruction == T_MNEM_mov);
9818 else
9819 narrow = (inst.instruction == T_MNEM_movs);
9820 }
9821
9822 if (narrow)
9823 {
9824 switch (inst.operands[1].shift_kind)
9825 {
9826 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9827 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9828 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9829 default: narrow = FALSE; break;
9830 }
9831 }
9832
9833 if (narrow)
9834 {
fdfde340
JM
9835 inst.instruction |= Rn;
9836 inst.instruction |= Rm << 3;
728ca7c9
PB
9837 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9838 }
9839 else
9840 {
9841 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9842 inst.instruction |= Rn << r0off;
728ca7c9
PB
9843 encode_thumb32_shifted_operand (1);
9844 }
c19d1205
ZW
9845 }
9846 else
9847 switch (inst.instruction)
9848 {
9849 case T_MNEM_mov:
9850 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
9851 inst.instruction |= (Rn & 0x8) << 4;
9852 inst.instruction |= (Rn & 0x7);
9853 inst.instruction |= Rm << 3;
c19d1205 9854 break;
b99bd4ef 9855
c19d1205
ZW
9856 case T_MNEM_movs:
9857 /* We know we have low registers at this point.
9858 Generate ADD Rd, Rs, #0. */
9859 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
9860 inst.instruction |= Rn;
9861 inst.instruction |= Rm << 3;
c19d1205
ZW
9862 break;
9863
9864 case T_MNEM_cmp:
3d388997 9865 if (low_regs)
c19d1205
ZW
9866 {
9867 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
9868 inst.instruction |= Rn;
9869 inst.instruction |= Rm << 3;
c19d1205
ZW
9870 }
9871 else
9872 {
9873 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
9874 inst.instruction |= (Rn & 0x8) << 4;
9875 inst.instruction |= (Rn & 0x7);
9876 inst.instruction |= Rm << 3;
c19d1205
ZW
9877 }
9878 break;
9879 }
b99bd4ef
NC
9880 return;
9881 }
9882
c19d1205
ZW
9883 inst.instruction = THUMB_OP16 (inst.instruction);
9884 if (inst.operands[1].isreg)
b99bd4ef 9885 {
fdfde340 9886 if (Rn < 8 && Rm < 8)
b99bd4ef 9887 {
c19d1205
ZW
9888 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9889 since a MOV instruction produces unpredictable results. */
9890 if (inst.instruction == T_OPCODE_MOV_I8)
9891 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9892 else
c19d1205 9893 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9894
fdfde340
JM
9895 inst.instruction |= Rn;
9896 inst.instruction |= Rm << 3;
b99bd4ef
NC
9897 }
9898 else
9899 {
c19d1205
ZW
9900 if (inst.instruction == T_OPCODE_MOV_I8)
9901 inst.instruction = T_OPCODE_MOV_HR;
9902 else
9903 inst.instruction = T_OPCODE_CMP_HR;
9904 do_t_cpy ();
b99bd4ef
NC
9905 }
9906 }
c19d1205 9907 else
b99bd4ef 9908 {
fdfde340 9909 constraint (Rn > 7,
c19d1205 9910 _("only lo regs allowed with immediate"));
fdfde340 9911 inst.instruction |= Rn << 8;
c19d1205
ZW
9912 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9913 }
9914}
b99bd4ef 9915
c19d1205
ZW
9916static void
9917do_t_mov16 (void)
9918{
fdfde340 9919 unsigned Rd;
b6895b4f
PB
9920 bfd_vma imm;
9921 bfd_boolean top;
9922
9923 top = (inst.instruction & 0x00800000) != 0;
9924 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9925 {
9926 constraint (top, _(":lower16: not allowed this instruction"));
9927 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9928 }
9929 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9930 {
9931 constraint (!top, _(":upper16: not allowed this instruction"));
9932 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9933 }
9934
fdfde340
JM
9935 Rd = inst.operands[0].reg;
9936 reject_bad_reg (Rd);
9937
9938 inst.instruction |= Rd << 8;
b6895b4f
PB
9939 if (inst.reloc.type == BFD_RELOC_UNUSED)
9940 {
9941 imm = inst.reloc.exp.X_add_number;
9942 inst.instruction |= (imm & 0xf000) << 4;
9943 inst.instruction |= (imm & 0x0800) << 15;
9944 inst.instruction |= (imm & 0x0700) << 4;
9945 inst.instruction |= (imm & 0x00ff);
9946 }
c19d1205 9947}
b99bd4ef 9948
c19d1205
ZW
9949static void
9950do_t_mvn_tst (void)
9951{
fdfde340
JM
9952 unsigned Rn, Rm;
9953
9954 Rn = inst.operands[0].reg;
9955 Rm = inst.operands[1].reg;
9956
9957 if (inst.instruction == T_MNEM_cmp
9958 || inst.instruction == T_MNEM_cmn)
9959 constraint (Rn == REG_PC, BAD_PC);
9960 else
9961 reject_bad_reg (Rn);
9962 reject_bad_reg (Rm);
9963
c19d1205
ZW
9964 if (unified_syntax)
9965 {
9966 int r0off = (inst.instruction == T_MNEM_mvn
9967 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9968 bfd_boolean narrow;
9969
9970 if (inst.size_req == 4
9971 || inst.instruction > 0xffff
9972 || inst.operands[1].shifted
fdfde340 9973 || Rn > 7 || Rm > 7)
3d388997
PB
9974 narrow = FALSE;
9975 else if (inst.instruction == T_MNEM_cmn)
9976 narrow = TRUE;
9977 else if (THUMB_SETS_FLAGS (inst.instruction))
9978 narrow = (current_it_mask == 0);
9979 else
9980 narrow = (current_it_mask != 0);
9981
c19d1205 9982 if (!inst.operands[1].isreg)
b99bd4ef 9983 {
c19d1205
ZW
9984 /* For an immediate, we always generate a 32-bit opcode;
9985 section relaxation will shrink it later if possible. */
9986 if (inst.instruction < 0xffff)
9987 inst.instruction = THUMB_OP32 (inst.instruction);
9988 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9989 inst.instruction |= Rn << r0off;
c19d1205 9990 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9991 }
c19d1205 9992 else
b99bd4ef 9993 {
c19d1205 9994 /* See if we can do this with a 16-bit instruction. */
3d388997 9995 if (narrow)
b99bd4ef 9996 {
c19d1205 9997 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
9998 inst.instruction |= Rn;
9999 inst.instruction |= Rm << 3;
b99bd4ef 10000 }
c19d1205 10001 else
b99bd4ef 10002 {
c19d1205
ZW
10003 constraint (inst.operands[1].shifted
10004 && inst.operands[1].immisreg,
10005 _("shift must be constant"));
10006 if (inst.instruction < 0xffff)
10007 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10008 inst.instruction |= Rn << r0off;
c19d1205 10009 encode_thumb32_shifted_operand (1);
b99bd4ef 10010 }
b99bd4ef
NC
10011 }
10012 }
10013 else
10014 {
c19d1205
ZW
10015 constraint (inst.instruction > 0xffff
10016 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10017 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10018 _("unshifted register required"));
fdfde340 10019 constraint (Rn > 7 || Rm > 7,
c19d1205 10020 BAD_HIREG);
b99bd4ef 10021
c19d1205 10022 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10023 inst.instruction |= Rn;
10024 inst.instruction |= Rm << 3;
b99bd4ef 10025 }
b99bd4ef
NC
10026}
10027
b05fe5cf 10028static void
c19d1205 10029do_t_mrs (void)
b05fe5cf 10030{
fdfde340 10031 unsigned Rd;
62b3e311 10032 int flags;
037e8744
JB
10033
10034 if (do_vfp_nsyn_mrs () == SUCCESS)
10035 return;
10036
62b3e311
PB
10037 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10038 if (flags == 0)
10039 {
7e806470 10040 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10041 _("selected processor does not support "
10042 "requested special purpose register"));
10043 }
10044 else
10045 {
10046 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10047 _("selected processor does not support "
44bf2362 10048 "requested special purpose register"));
62b3e311
PB
10049 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10050 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10051 _("'CPSR' or 'SPSR' expected"));
10052 }
5f4273c7 10053
fdfde340
JM
10054 Rd = inst.operands[0].reg;
10055 reject_bad_reg (Rd);
10056
10057 inst.instruction |= Rd << 8;
62b3e311
PB
10058 inst.instruction |= (flags & SPSR_BIT) >> 2;
10059 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10060}
b05fe5cf 10061
c19d1205
ZW
10062static void
10063do_t_msr (void)
10064{
62b3e311 10065 int flags;
fdfde340 10066 unsigned Rn;
62b3e311 10067
037e8744
JB
10068 if (do_vfp_nsyn_msr () == SUCCESS)
10069 return;
10070
c19d1205
ZW
10071 constraint (!inst.operands[1].isreg,
10072 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10073 flags = inst.operands[0].imm;
10074 if (flags & ~0xff)
10075 {
10076 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10077 _("selected processor does not support "
10078 "requested special purpose register"));
10079 }
10080 else
10081 {
7e806470 10082 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10083 _("selected processor does not support "
10084 "requested special purpose register"));
10085 flags |= PSR_f;
10086 }
fdfde340
JM
10087
10088 Rn = inst.operands[1].reg;
10089 reject_bad_reg (Rn);
10090
62b3e311
PB
10091 inst.instruction |= (flags & SPSR_BIT) >> 2;
10092 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10093 inst.instruction |= (flags & 0xff);
fdfde340 10094 inst.instruction |= Rn << 16;
c19d1205 10095}
b05fe5cf 10096
c19d1205
ZW
10097static void
10098do_t_mul (void)
10099{
17828f45 10100 bfd_boolean narrow;
fdfde340 10101 unsigned Rd, Rn, Rm;
17828f45 10102
c19d1205
ZW
10103 if (!inst.operands[2].present)
10104 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10105
fdfde340
JM
10106 Rd = inst.operands[0].reg;
10107 Rn = inst.operands[1].reg;
10108 Rm = inst.operands[2].reg;
10109
17828f45 10110 if (unified_syntax)
b05fe5cf 10111 {
17828f45 10112 if (inst.size_req == 4
fdfde340
JM
10113 || (Rd != Rn
10114 && Rd != Rm)
10115 || Rn > 7
10116 || Rm > 7)
17828f45
JM
10117 narrow = FALSE;
10118 else if (inst.instruction == T_MNEM_muls)
10119 narrow = (current_it_mask == 0);
10120 else
10121 narrow = (current_it_mask != 0);
b05fe5cf 10122 }
c19d1205 10123 else
b05fe5cf 10124 {
17828f45 10125 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10126 constraint (Rn > 7 || Rm > 7,
c19d1205 10127 BAD_HIREG);
17828f45
JM
10128 narrow = TRUE;
10129 }
b05fe5cf 10130
17828f45
JM
10131 if (narrow)
10132 {
10133 /* 16-bit MULS/Conditional MUL. */
c19d1205 10134 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10135 inst.instruction |= Rd;
b05fe5cf 10136
fdfde340
JM
10137 if (Rd == Rn)
10138 inst.instruction |= Rm << 3;
10139 else if (Rd == Rm)
10140 inst.instruction |= Rn << 3;
c19d1205
ZW
10141 else
10142 constraint (1, _("dest must overlap one source register"));
10143 }
17828f45
JM
10144 else
10145 {
10146 constraint(inst.instruction != T_MNEM_mul,
10147 _("Thumb-2 MUL must not set flags"));
10148 /* 32-bit MUL. */
10149 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10150 inst.instruction |= Rd << 8;
10151 inst.instruction |= Rn << 16;
10152 inst.instruction |= Rm << 0;
10153
10154 reject_bad_reg (Rd);
10155 reject_bad_reg (Rn);
10156 reject_bad_reg (Rm);
17828f45 10157 }
c19d1205 10158}
b05fe5cf 10159
c19d1205
ZW
10160static void
10161do_t_mull (void)
10162{
fdfde340 10163 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10164
fdfde340
JM
10165 RdLo = inst.operands[0].reg;
10166 RdHi = inst.operands[1].reg;
10167 Rn = inst.operands[2].reg;
10168 Rm = inst.operands[3].reg;
10169
10170 reject_bad_reg (RdLo);
10171 reject_bad_reg (RdHi);
10172 reject_bad_reg (Rn);
10173 reject_bad_reg (Rm);
10174
10175 inst.instruction |= RdLo << 12;
10176 inst.instruction |= RdHi << 8;
10177 inst.instruction |= Rn << 16;
10178 inst.instruction |= Rm;
10179
10180 if (RdLo == RdHi)
c19d1205
ZW
10181 as_tsktsk (_("rdhi and rdlo must be different"));
10182}
b05fe5cf 10183
c19d1205
ZW
10184static void
10185do_t_nop (void)
10186{
10187 if (unified_syntax)
10188 {
10189 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10190 {
c19d1205
ZW
10191 inst.instruction = THUMB_OP32 (inst.instruction);
10192 inst.instruction |= inst.operands[0].imm;
10193 }
10194 else
10195 {
bc2d1808
NC
10196 /* PR9722: Check for Thumb2 availability before
10197 generating a thumb2 nop instruction. */
10198 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10199 {
10200 inst.instruction = THUMB_OP16 (inst.instruction);
10201 inst.instruction |= inst.operands[0].imm << 4;
10202 }
10203 else
10204 inst.instruction = 0x46c0;
c19d1205
ZW
10205 }
10206 }
10207 else
10208 {
10209 constraint (inst.operands[0].present,
10210 _("Thumb does not support NOP with hints"));
10211 inst.instruction = 0x46c0;
10212 }
10213}
b05fe5cf 10214
c19d1205
ZW
10215static void
10216do_t_neg (void)
10217{
10218 if (unified_syntax)
10219 {
3d388997
PB
10220 bfd_boolean narrow;
10221
10222 if (THUMB_SETS_FLAGS (inst.instruction))
10223 narrow = (current_it_mask == 0);
10224 else
10225 narrow = (current_it_mask != 0);
10226 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10227 narrow = FALSE;
10228 if (inst.size_req == 4)
10229 narrow = FALSE;
10230
10231 if (!narrow)
c19d1205
ZW
10232 {
10233 inst.instruction = THUMB_OP32 (inst.instruction);
10234 inst.instruction |= inst.operands[0].reg << 8;
10235 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10236 }
10237 else
10238 {
c19d1205
ZW
10239 inst.instruction = THUMB_OP16 (inst.instruction);
10240 inst.instruction |= inst.operands[0].reg;
10241 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10242 }
10243 }
10244 else
10245 {
c19d1205
ZW
10246 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10247 BAD_HIREG);
10248 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10249
10250 inst.instruction = THUMB_OP16 (inst.instruction);
10251 inst.instruction |= inst.operands[0].reg;
10252 inst.instruction |= inst.operands[1].reg << 3;
10253 }
10254}
10255
1c444d06
JM
10256static void
10257do_t_orn (void)
10258{
10259 unsigned Rd, Rn;
10260
10261 Rd = inst.operands[0].reg;
10262 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10263
fdfde340
JM
10264 reject_bad_reg (Rd);
10265 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10266 reject_bad_reg (Rn);
10267
1c444d06
JM
10268 inst.instruction |= Rd << 8;
10269 inst.instruction |= Rn << 16;
10270
10271 if (!inst.operands[2].isreg)
10272 {
10273 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10274 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10275 }
10276 else
10277 {
10278 unsigned Rm;
10279
10280 Rm = inst.operands[2].reg;
fdfde340 10281 reject_bad_reg (Rm);
1c444d06
JM
10282
10283 constraint (inst.operands[2].shifted
10284 && inst.operands[2].immisreg,
10285 _("shift must be constant"));
10286 encode_thumb32_shifted_operand (2);
10287 }
10288}
10289
c19d1205
ZW
10290static void
10291do_t_pkhbt (void)
10292{
fdfde340
JM
10293 unsigned Rd, Rn, Rm;
10294
10295 Rd = inst.operands[0].reg;
10296 Rn = inst.operands[1].reg;
10297 Rm = inst.operands[2].reg;
10298
10299 reject_bad_reg (Rd);
10300 reject_bad_reg (Rn);
10301 reject_bad_reg (Rm);
10302
10303 inst.instruction |= Rd << 8;
10304 inst.instruction |= Rn << 16;
10305 inst.instruction |= Rm;
c19d1205
ZW
10306 if (inst.operands[3].present)
10307 {
10308 unsigned int val = inst.reloc.exp.X_add_number;
10309 constraint (inst.reloc.exp.X_op != O_constant,
10310 _("expression too complex"));
10311 inst.instruction |= (val & 0x1c) << 10;
10312 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10313 }
c19d1205 10314}
b05fe5cf 10315
c19d1205
ZW
10316static void
10317do_t_pkhtb (void)
10318{
10319 if (!inst.operands[3].present)
10320 inst.instruction &= ~0x00000020;
10321 do_t_pkhbt ();
b05fe5cf
ZW
10322}
10323
c19d1205
ZW
10324static void
10325do_t_pld (void)
10326{
fdfde340
JM
10327 if (inst.operands[0].immisreg)
10328 reject_bad_reg (inst.operands[0].imm);
10329
c19d1205
ZW
10330 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10331}
b05fe5cf 10332
c19d1205
ZW
10333static void
10334do_t_push_pop (void)
b99bd4ef 10335{
e9f89963 10336 unsigned mask;
5f4273c7 10337
c19d1205
ZW
10338 constraint (inst.operands[0].writeback,
10339 _("push/pop do not support {reglist}^"));
10340 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10341 _("expression too complex"));
b99bd4ef 10342
e9f89963
PB
10343 mask = inst.operands[0].imm;
10344 if ((mask & ~0xff) == 0)
3c707909 10345 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10346 else if ((inst.instruction == T_MNEM_push
e9f89963 10347 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10348 || (inst.instruction == T_MNEM_pop
e9f89963 10349 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10350 {
c19d1205
ZW
10351 inst.instruction = THUMB_OP16 (inst.instruction);
10352 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10353 inst.instruction |= mask & 0xff;
c19d1205
ZW
10354 }
10355 else if (unified_syntax)
10356 {
3c707909 10357 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10358 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10359 }
10360 else
10361 {
10362 inst.error = _("invalid register list to push/pop instruction");
10363 return;
10364 }
c19d1205 10365}
b99bd4ef 10366
c19d1205
ZW
10367static void
10368do_t_rbit (void)
10369{
fdfde340
JM
10370 unsigned Rd, Rm;
10371
10372 Rd = inst.operands[0].reg;
10373 Rm = inst.operands[1].reg;
10374
10375 reject_bad_reg (Rd);
10376 reject_bad_reg (Rm);
10377
10378 inst.instruction |= Rd << 8;
10379 inst.instruction |= Rm << 16;
10380 inst.instruction |= Rm;
c19d1205 10381}
b99bd4ef 10382
c19d1205
ZW
10383static void
10384do_t_rev (void)
10385{
fdfde340
JM
10386 unsigned Rd, Rm;
10387
10388 Rd = inst.operands[0].reg;
10389 Rm = inst.operands[1].reg;
10390
10391 reject_bad_reg (Rd);
10392 reject_bad_reg (Rm);
10393
10394 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10395 && inst.size_req != 4)
10396 {
10397 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10398 inst.instruction |= Rd;
10399 inst.instruction |= Rm << 3;
c19d1205
ZW
10400 }
10401 else if (unified_syntax)
10402 {
10403 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10404 inst.instruction |= Rd << 8;
10405 inst.instruction |= Rm << 16;
10406 inst.instruction |= Rm;
c19d1205
ZW
10407 }
10408 else
10409 inst.error = BAD_HIREG;
10410}
b99bd4ef 10411
1c444d06
JM
10412static void
10413do_t_rrx (void)
10414{
10415 unsigned Rd, Rm;
10416
10417 Rd = inst.operands[0].reg;
10418 Rm = inst.operands[1].reg;
10419
fdfde340
JM
10420 reject_bad_reg (Rd);
10421 reject_bad_reg (Rm);
10422
1c444d06
JM
10423 inst.instruction |= Rd << 8;
10424 inst.instruction |= Rm;
10425}
10426
c19d1205
ZW
10427static void
10428do_t_rsb (void)
10429{
fdfde340 10430 unsigned Rd, Rs;
b99bd4ef 10431
c19d1205
ZW
10432 Rd = inst.operands[0].reg;
10433 Rs = (inst.operands[1].present
10434 ? inst.operands[1].reg /* Rd, Rs, foo */
10435 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10436
fdfde340
JM
10437 reject_bad_reg (Rd);
10438 reject_bad_reg (Rs);
10439 if (inst.operands[2].isreg)
10440 reject_bad_reg (inst.operands[2].reg);
10441
c19d1205
ZW
10442 inst.instruction |= Rd << 8;
10443 inst.instruction |= Rs << 16;
10444 if (!inst.operands[2].isreg)
10445 {
026d3abb
PB
10446 bfd_boolean narrow;
10447
10448 if ((inst.instruction & 0x00100000) != 0)
10449 narrow = (current_it_mask == 0);
10450 else
10451 narrow = (current_it_mask != 0);
10452
10453 if (Rd > 7 || Rs > 7)
10454 narrow = FALSE;
10455
10456 if (inst.size_req == 4 || !unified_syntax)
10457 narrow = FALSE;
10458
10459 if (inst.reloc.exp.X_op != O_constant
10460 || inst.reloc.exp.X_add_number != 0)
10461 narrow = FALSE;
10462
10463 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10464 relaxation, but it doesn't seem worth the hassle. */
10465 if (narrow)
10466 {
10467 inst.reloc.type = BFD_RELOC_UNUSED;
10468 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10469 inst.instruction |= Rs << 3;
10470 inst.instruction |= Rd;
10471 }
10472 else
10473 {
10474 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10475 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10476 }
c19d1205
ZW
10477 }
10478 else
10479 encode_thumb32_shifted_operand (2);
10480}
b99bd4ef 10481
c19d1205
ZW
10482static void
10483do_t_setend (void)
10484{
dfa9f0d5 10485 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10486 if (inst.operands[0].imm)
10487 inst.instruction |= 0x8;
10488}
b99bd4ef 10489
c19d1205
ZW
10490static void
10491do_t_shift (void)
10492{
10493 if (!inst.operands[1].present)
10494 inst.operands[1].reg = inst.operands[0].reg;
10495
10496 if (unified_syntax)
10497 {
3d388997
PB
10498 bfd_boolean narrow;
10499 int shift_kind;
10500
10501 switch (inst.instruction)
10502 {
10503 case T_MNEM_asr:
10504 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10505 case T_MNEM_lsl:
10506 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10507 case T_MNEM_lsr:
10508 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10509 case T_MNEM_ror:
10510 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10511 default: abort ();
10512 }
10513
10514 if (THUMB_SETS_FLAGS (inst.instruction))
10515 narrow = (current_it_mask == 0);
10516 else
10517 narrow = (current_it_mask != 0);
10518 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10519 narrow = FALSE;
10520 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10521 narrow = FALSE;
10522 if (inst.operands[2].isreg
10523 && (inst.operands[1].reg != inst.operands[0].reg
10524 || inst.operands[2].reg > 7))
10525 narrow = FALSE;
10526 if (inst.size_req == 4)
10527 narrow = FALSE;
10528
fdfde340
JM
10529 reject_bad_reg (inst.operands[0].reg);
10530 reject_bad_reg (inst.operands[1].reg);
10531
3d388997 10532 if (!narrow)
c19d1205
ZW
10533 {
10534 if (inst.operands[2].isreg)
b99bd4ef 10535 {
fdfde340 10536 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10537 inst.instruction = THUMB_OP32 (inst.instruction);
10538 inst.instruction |= inst.operands[0].reg << 8;
10539 inst.instruction |= inst.operands[1].reg << 16;
10540 inst.instruction |= inst.operands[2].reg;
10541 }
10542 else
10543 {
10544 inst.operands[1].shifted = 1;
3d388997 10545 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10546 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10547 ? T_MNEM_movs : T_MNEM_mov);
10548 inst.instruction |= inst.operands[0].reg << 8;
10549 encode_thumb32_shifted_operand (1);
10550 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10551 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10552 }
10553 }
10554 else
10555 {
c19d1205 10556 if (inst.operands[2].isreg)
b99bd4ef 10557 {
3d388997 10558 switch (shift_kind)
b99bd4ef 10559 {
3d388997
PB
10560 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10561 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10562 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10563 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10564 default: abort ();
b99bd4ef 10565 }
5f4273c7 10566
c19d1205
ZW
10567 inst.instruction |= inst.operands[0].reg;
10568 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10569 }
10570 else
10571 {
3d388997 10572 switch (shift_kind)
b99bd4ef 10573 {
3d388997
PB
10574 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10575 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10576 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10577 default: abort ();
b99bd4ef 10578 }
c19d1205
ZW
10579 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10580 inst.instruction |= inst.operands[0].reg;
10581 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10582 }
10583 }
c19d1205
ZW
10584 }
10585 else
10586 {
10587 constraint (inst.operands[0].reg > 7
10588 || inst.operands[1].reg > 7, BAD_HIREG);
10589 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10590
c19d1205
ZW
10591 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10592 {
10593 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10594 constraint (inst.operands[0].reg != inst.operands[1].reg,
10595 _("source1 and dest must be same register"));
b99bd4ef 10596
c19d1205
ZW
10597 switch (inst.instruction)
10598 {
10599 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10600 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10601 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10602 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10603 default: abort ();
10604 }
5f4273c7 10605
c19d1205
ZW
10606 inst.instruction |= inst.operands[0].reg;
10607 inst.instruction |= inst.operands[2].reg << 3;
10608 }
10609 else
b99bd4ef 10610 {
c19d1205
ZW
10611 switch (inst.instruction)
10612 {
10613 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10614 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10615 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10616 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10617 default: abort ();
10618 }
10619 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10620 inst.instruction |= inst.operands[0].reg;
10621 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10622 }
10623 }
b99bd4ef
NC
10624}
10625
10626static void
c19d1205 10627do_t_simd (void)
b99bd4ef 10628{
fdfde340
JM
10629 unsigned Rd, Rn, Rm;
10630
10631 Rd = inst.operands[0].reg;
10632 Rn = inst.operands[1].reg;
10633 Rm = inst.operands[2].reg;
10634
10635 reject_bad_reg (Rd);
10636 reject_bad_reg (Rn);
10637 reject_bad_reg (Rm);
10638
10639 inst.instruction |= Rd << 8;
10640 inst.instruction |= Rn << 16;
10641 inst.instruction |= Rm;
c19d1205 10642}
b99bd4ef 10643
c19d1205 10644static void
3eb17e6b 10645do_t_smc (void)
c19d1205
ZW
10646{
10647 unsigned int value = inst.reloc.exp.X_add_number;
10648 constraint (inst.reloc.exp.X_op != O_constant,
10649 _("expression too complex"));
10650 inst.reloc.type = BFD_RELOC_UNUSED;
10651 inst.instruction |= (value & 0xf000) >> 12;
10652 inst.instruction |= (value & 0x0ff0);
10653 inst.instruction |= (value & 0x000f) << 16;
10654}
b99bd4ef 10655
c19d1205 10656static void
3a21c15a 10657do_t_ssat_usat (int bias)
c19d1205 10658{
fdfde340
JM
10659 unsigned Rd, Rn;
10660
10661 Rd = inst.operands[0].reg;
10662 Rn = inst.operands[2].reg;
10663
10664 reject_bad_reg (Rd);
10665 reject_bad_reg (Rn);
10666
10667 inst.instruction |= Rd << 8;
3a21c15a 10668 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 10669 inst.instruction |= Rn << 16;
b99bd4ef 10670
c19d1205 10671 if (inst.operands[3].present)
b99bd4ef 10672 {
3a21c15a
NC
10673 offsetT shift_amount = inst.reloc.exp.X_add_number;
10674
10675 inst.reloc.type = BFD_RELOC_UNUSED;
10676
c19d1205
ZW
10677 constraint (inst.reloc.exp.X_op != O_constant,
10678 _("expression too complex"));
b99bd4ef 10679
3a21c15a 10680 if (shift_amount != 0)
6189168b 10681 {
3a21c15a
NC
10682 constraint (shift_amount > 31,
10683 _("shift expression is too large"));
10684
c19d1205 10685 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
10686 inst.instruction |= 0x00200000; /* sh bit. */
10687
10688 inst.instruction |= (shift_amount & 0x1c) << 10;
10689 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
10690 }
10691 }
b99bd4ef 10692}
3a21c15a
NC
10693
10694static void
10695do_t_ssat (void)
10696{
10697 do_t_ssat_usat (1);
10698}
b99bd4ef 10699
0dd132b6 10700static void
c19d1205 10701do_t_ssat16 (void)
0dd132b6 10702{
fdfde340
JM
10703 unsigned Rd, Rn;
10704
10705 Rd = inst.operands[0].reg;
10706 Rn = inst.operands[2].reg;
10707
10708 reject_bad_reg (Rd);
10709 reject_bad_reg (Rn);
10710
10711 inst.instruction |= Rd << 8;
c19d1205 10712 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 10713 inst.instruction |= Rn << 16;
c19d1205 10714}
0dd132b6 10715
c19d1205
ZW
10716static void
10717do_t_strex (void)
10718{
10719 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10720 || inst.operands[2].postind || inst.operands[2].writeback
10721 || inst.operands[2].immisreg || inst.operands[2].shifted
10722 || inst.operands[2].negative,
01cfc07f 10723 BAD_ADDR_MODE);
0dd132b6 10724
c19d1205
ZW
10725 inst.instruction |= inst.operands[0].reg << 8;
10726 inst.instruction |= inst.operands[1].reg << 12;
10727 inst.instruction |= inst.operands[2].reg << 16;
10728 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10729}
10730
b99bd4ef 10731static void
c19d1205 10732do_t_strexd (void)
b99bd4ef 10733{
c19d1205
ZW
10734 if (!inst.operands[2].present)
10735 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10736
c19d1205
ZW
10737 constraint (inst.operands[0].reg == inst.operands[1].reg
10738 || inst.operands[0].reg == inst.operands[2].reg
10739 || inst.operands[0].reg == inst.operands[3].reg
10740 || inst.operands[1].reg == inst.operands[2].reg,
10741 BAD_OVERLAP);
b99bd4ef 10742
c19d1205
ZW
10743 inst.instruction |= inst.operands[0].reg;
10744 inst.instruction |= inst.operands[1].reg << 12;
10745 inst.instruction |= inst.operands[2].reg << 8;
10746 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10747}
10748
10749static void
c19d1205 10750do_t_sxtah (void)
b99bd4ef 10751{
fdfde340
JM
10752 unsigned Rd, Rn, Rm;
10753
10754 Rd = inst.operands[0].reg;
10755 Rn = inst.operands[1].reg;
10756 Rm = inst.operands[2].reg;
10757
10758 reject_bad_reg (Rd);
10759 reject_bad_reg (Rn);
10760 reject_bad_reg (Rm);
10761
10762 inst.instruction |= Rd << 8;
10763 inst.instruction |= Rn << 16;
10764 inst.instruction |= Rm;
c19d1205
ZW
10765 inst.instruction |= inst.operands[3].imm << 4;
10766}
b99bd4ef 10767
c19d1205
ZW
10768static void
10769do_t_sxth (void)
10770{
fdfde340
JM
10771 unsigned Rd, Rm;
10772
10773 Rd = inst.operands[0].reg;
10774 Rm = inst.operands[1].reg;
10775
10776 reject_bad_reg (Rd);
10777 reject_bad_reg (Rm);
10778
c19d1205 10779 if (inst.instruction <= 0xffff && inst.size_req != 4
fdfde340 10780 && Rd <= 7 && Rm <= 7
c19d1205 10781 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10782 {
c19d1205 10783 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10784 inst.instruction |= Rd;
10785 inst.instruction |= Rm << 3;
b99bd4ef 10786 }
c19d1205 10787 else if (unified_syntax)
b99bd4ef 10788 {
c19d1205
ZW
10789 if (inst.instruction <= 0xffff)
10790 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10791 inst.instruction |= Rd << 8;
10792 inst.instruction |= Rm;
c19d1205 10793 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10794 }
c19d1205 10795 else
b99bd4ef 10796 {
c19d1205
ZW
10797 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10798 _("Thumb encoding does not support rotation"));
10799 constraint (1, BAD_HIREG);
b99bd4ef 10800 }
c19d1205 10801}
b99bd4ef 10802
c19d1205
ZW
10803static void
10804do_t_swi (void)
10805{
10806 inst.reloc.type = BFD_RELOC_ARM_SWI;
10807}
b99bd4ef 10808
92e90b6e
PB
10809static void
10810do_t_tb (void)
10811{
fdfde340 10812 unsigned Rn, Rm;
92e90b6e
PB
10813 int half;
10814
10815 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10816 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10817 constraint (inst.operands[0].immisreg,
10818 _("instruction requires register index"));
fdfde340
JM
10819
10820 Rn = inst.operands[0].reg;
10821 Rm = inst.operands[0].imm;
10822
10823 constraint (Rn == REG_SP, BAD_SP);
10824 reject_bad_reg (Rm);
10825
92e90b6e
PB
10826 constraint (!half && inst.operands[0].shifted,
10827 _("instruction does not allow shifted index"));
fdfde340 10828 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
10829}
10830
c19d1205
ZW
10831static void
10832do_t_usat (void)
10833{
3a21c15a 10834 do_t_ssat_usat (0);
b99bd4ef
NC
10835}
10836
10837static void
c19d1205 10838do_t_usat16 (void)
b99bd4ef 10839{
fdfde340
JM
10840 unsigned Rd, Rn;
10841
10842 Rd = inst.operands[0].reg;
10843 Rn = inst.operands[2].reg;
10844
10845 reject_bad_reg (Rd);
10846 reject_bad_reg (Rn);
10847
10848 inst.instruction |= Rd << 8;
c19d1205 10849 inst.instruction |= inst.operands[1].imm;
fdfde340 10850 inst.instruction |= Rn << 16;
b99bd4ef 10851}
c19d1205 10852
5287ad62 10853/* Neon instruction encoder helpers. */
5f4273c7 10854
5287ad62 10855/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10856
5287ad62
JB
10857/* An "invalid" code for the following tables. */
10858#define N_INV -1u
10859
10860struct neon_tab_entry
b99bd4ef 10861{
5287ad62
JB
10862 unsigned integer;
10863 unsigned float_or_poly;
10864 unsigned scalar_or_imm;
10865};
5f4273c7 10866
5287ad62
JB
10867/* Map overloaded Neon opcodes to their respective encodings. */
10868#define NEON_ENC_TAB \
10869 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10870 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10871 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10872 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10873 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10874 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10875 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10876 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10877 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10878 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10879 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10880 /* Register variants of the following two instructions are encoded as
10881 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10882 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10883 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10884 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10885 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10886 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10887 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10888 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10889 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10890 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10891 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10892 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10893 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10894 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10895 X(vshl, 0x0000400, N_INV, 0x0800510), \
10896 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10897 X(vand, 0x0000110, N_INV, 0x0800030), \
10898 X(vbic, 0x0100110, N_INV, 0x0800030), \
10899 X(veor, 0x1000110, N_INV, N_INV), \
10900 X(vorn, 0x0300110, N_INV, 0x0800010), \
10901 X(vorr, 0x0200110, N_INV, 0x0800010), \
10902 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10903 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10904 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10905 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10906 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10907 X(vst1, 0x0000000, 0x0800000, N_INV), \
10908 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10909 X(vst2, 0x0000100, 0x0800100, N_INV), \
10910 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10911 X(vst3, 0x0000200, 0x0800200, N_INV), \
10912 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10913 X(vst4, 0x0000300, 0x0800300, N_INV), \
10914 X(vmovn, 0x1b20200, N_INV, N_INV), \
10915 X(vtrn, 0x1b20080, N_INV, N_INV), \
10916 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10917 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10918 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10919 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10920 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10921 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10922 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10923 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10924 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10925
10926enum neon_opc
10927{
10928#define X(OPC,I,F,S) N_MNEM_##OPC
10929NEON_ENC_TAB
10930#undef X
10931};
b99bd4ef 10932
5287ad62
JB
10933static const struct neon_tab_entry neon_enc_tab[] =
10934{
10935#define X(OPC,I,F,S) { (I), (F), (S) }
10936NEON_ENC_TAB
10937#undef X
10938};
b99bd4ef 10939
5287ad62
JB
10940#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10941#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10942#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10943#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10944#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10945#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10946#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10947#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10948#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10949#define NEON_ENC_SINGLE(X) \
10950 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10951#define NEON_ENC_DOUBLE(X) \
10952 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10953
037e8744
JB
10954/* Define shapes for instruction operands. The following mnemonic characters
10955 are used in this table:
5287ad62 10956
037e8744 10957 F - VFP S<n> register
5287ad62
JB
10958 D - Neon D<n> register
10959 Q - Neon Q<n> register
10960 I - Immediate
10961 S - Scalar
10962 R - ARM register
10963 L - D<n> register list
5f4273c7 10964
037e8744
JB
10965 This table is used to generate various data:
10966 - enumerations of the form NS_DDR to be used as arguments to
10967 neon_select_shape.
10968 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 10969 - a table used to drive neon_select_shape. */
b99bd4ef 10970
037e8744
JB
10971#define NEON_SHAPE_DEF \
10972 X(3, (D, D, D), DOUBLE), \
10973 X(3, (Q, Q, Q), QUAD), \
10974 X(3, (D, D, I), DOUBLE), \
10975 X(3, (Q, Q, I), QUAD), \
10976 X(3, (D, D, S), DOUBLE), \
10977 X(3, (Q, Q, S), QUAD), \
10978 X(2, (D, D), DOUBLE), \
10979 X(2, (Q, Q), QUAD), \
10980 X(2, (D, S), DOUBLE), \
10981 X(2, (Q, S), QUAD), \
10982 X(2, (D, R), DOUBLE), \
10983 X(2, (Q, R), QUAD), \
10984 X(2, (D, I), DOUBLE), \
10985 X(2, (Q, I), QUAD), \
10986 X(3, (D, L, D), DOUBLE), \
10987 X(2, (D, Q), MIXED), \
10988 X(2, (Q, D), MIXED), \
10989 X(3, (D, Q, I), MIXED), \
10990 X(3, (Q, D, I), MIXED), \
10991 X(3, (Q, D, D), MIXED), \
10992 X(3, (D, Q, Q), MIXED), \
10993 X(3, (Q, Q, D), MIXED), \
10994 X(3, (Q, D, S), MIXED), \
10995 X(3, (D, Q, S), MIXED), \
10996 X(4, (D, D, D, I), DOUBLE), \
10997 X(4, (Q, Q, Q, I), QUAD), \
10998 X(2, (F, F), SINGLE), \
10999 X(3, (F, F, F), SINGLE), \
11000 X(2, (F, I), SINGLE), \
11001 X(2, (F, D), MIXED), \
11002 X(2, (D, F), MIXED), \
11003 X(3, (F, F, I), MIXED), \
11004 X(4, (R, R, F, F), SINGLE), \
11005 X(4, (F, F, R, R), SINGLE), \
11006 X(3, (D, R, R), DOUBLE), \
11007 X(3, (R, R, D), DOUBLE), \
11008 X(2, (S, R), SINGLE), \
11009 X(2, (R, S), SINGLE), \
11010 X(2, (F, R), SINGLE), \
11011 X(2, (R, F), SINGLE)
11012
11013#define S2(A,B) NS_##A##B
11014#define S3(A,B,C) NS_##A##B##C
11015#define S4(A,B,C,D) NS_##A##B##C##D
11016
11017#define X(N, L, C) S##N L
11018
5287ad62
JB
11019enum neon_shape
11020{
037e8744
JB
11021 NEON_SHAPE_DEF,
11022 NS_NULL
5287ad62 11023};
b99bd4ef 11024
037e8744
JB
11025#undef X
11026#undef S2
11027#undef S3
11028#undef S4
11029
11030enum neon_shape_class
11031{
11032 SC_SINGLE,
11033 SC_DOUBLE,
11034 SC_QUAD,
11035 SC_MIXED
11036};
11037
11038#define X(N, L, C) SC_##C
11039
11040static enum neon_shape_class neon_shape_class[] =
11041{
11042 NEON_SHAPE_DEF
11043};
11044
11045#undef X
11046
11047enum neon_shape_el
11048{
11049 SE_F,
11050 SE_D,
11051 SE_Q,
11052 SE_I,
11053 SE_S,
11054 SE_R,
11055 SE_L
11056};
11057
11058/* Register widths of above. */
11059static unsigned neon_shape_el_size[] =
11060{
11061 32,
11062 64,
11063 128,
11064 0,
11065 32,
11066 32,
11067 0
11068};
11069
11070struct neon_shape_info
11071{
11072 unsigned els;
11073 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11074};
11075
11076#define S2(A,B) { SE_##A, SE_##B }
11077#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11078#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11079
11080#define X(N, L, C) { N, S##N L }
11081
11082static struct neon_shape_info neon_shape_tab[] =
11083{
11084 NEON_SHAPE_DEF
11085};
11086
11087#undef X
11088#undef S2
11089#undef S3
11090#undef S4
11091
5287ad62
JB
11092/* Bit masks used in type checking given instructions.
11093 'N_EQK' means the type must be the same as (or based on in some way) the key
11094 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11095 set, various other bits can be set as well in order to modify the meaning of
11096 the type constraint. */
11097
11098enum neon_type_mask
11099{
8e79c3df
CM
11100 N_S8 = 0x0000001,
11101 N_S16 = 0x0000002,
11102 N_S32 = 0x0000004,
11103 N_S64 = 0x0000008,
11104 N_U8 = 0x0000010,
11105 N_U16 = 0x0000020,
11106 N_U32 = 0x0000040,
11107 N_U64 = 0x0000080,
11108 N_I8 = 0x0000100,
11109 N_I16 = 0x0000200,
11110 N_I32 = 0x0000400,
11111 N_I64 = 0x0000800,
11112 N_8 = 0x0001000,
11113 N_16 = 0x0002000,
11114 N_32 = 0x0004000,
11115 N_64 = 0x0008000,
11116 N_P8 = 0x0010000,
11117 N_P16 = 0x0020000,
11118 N_F16 = 0x0040000,
11119 N_F32 = 0x0080000,
11120 N_F64 = 0x0100000,
11121 N_KEY = 0x1000000, /* key element (main type specifier). */
11122 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11123 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11124 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11125 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11126 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11127 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11128 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11129 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11130 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 11131 N_UTYP = 0,
037e8744 11132 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11133};
11134
dcbf9037
JB
11135#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11136
5287ad62
JB
11137#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11138#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11139#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11140#define N_SUF_32 (N_SU_32 | N_F32)
11141#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11142#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11143
11144/* Pass this as the first type argument to neon_check_type to ignore types
11145 altogether. */
11146#define N_IGNORE_TYPE (N_KEY | N_EQK)
11147
037e8744
JB
11148/* Select a "shape" for the current instruction (describing register types or
11149 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11150 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11151 function of operand parsing, so this function doesn't need to be called.
11152 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11153
11154static enum neon_shape
037e8744 11155neon_select_shape (enum neon_shape shape, ...)
5287ad62 11156{
037e8744
JB
11157 va_list ap;
11158 enum neon_shape first_shape = shape;
5287ad62
JB
11159
11160 /* Fix missing optional operands. FIXME: we don't know at this point how
11161 many arguments we should have, so this makes the assumption that we have
11162 > 1. This is true of all current Neon opcodes, I think, but may not be
11163 true in the future. */
11164 if (!inst.operands[1].present)
11165 inst.operands[1] = inst.operands[0];
11166
037e8744 11167 va_start (ap, shape);
5f4273c7 11168
037e8744
JB
11169 for (; shape != NS_NULL; shape = va_arg (ap, int))
11170 {
11171 unsigned j;
11172 int matches = 1;
11173
11174 for (j = 0; j < neon_shape_tab[shape].els; j++)
11175 {
11176 if (!inst.operands[j].present)
11177 {
11178 matches = 0;
11179 break;
11180 }
11181
11182 switch (neon_shape_tab[shape].el[j])
11183 {
11184 case SE_F:
11185 if (!(inst.operands[j].isreg
11186 && inst.operands[j].isvec
11187 && inst.operands[j].issingle
11188 && !inst.operands[j].isquad))
11189 matches = 0;
11190 break;
11191
11192 case SE_D:
11193 if (!(inst.operands[j].isreg
11194 && inst.operands[j].isvec
11195 && !inst.operands[j].isquad
11196 && !inst.operands[j].issingle))
11197 matches = 0;
11198 break;
11199
11200 case SE_R:
11201 if (!(inst.operands[j].isreg
11202 && !inst.operands[j].isvec))
11203 matches = 0;
11204 break;
11205
11206 case SE_Q:
11207 if (!(inst.operands[j].isreg
11208 && inst.operands[j].isvec
11209 && inst.operands[j].isquad
11210 && !inst.operands[j].issingle))
11211 matches = 0;
11212 break;
11213
11214 case SE_I:
11215 if (!(!inst.operands[j].isreg
11216 && !inst.operands[j].isscalar))
11217 matches = 0;
11218 break;
11219
11220 case SE_S:
11221 if (!(!inst.operands[j].isreg
11222 && inst.operands[j].isscalar))
11223 matches = 0;
11224 break;
11225
11226 case SE_L:
11227 break;
11228 }
11229 }
11230 if (matches)
5287ad62 11231 break;
037e8744 11232 }
5f4273c7 11233
037e8744 11234 va_end (ap);
5287ad62 11235
037e8744
JB
11236 if (shape == NS_NULL && first_shape != NS_NULL)
11237 first_error (_("invalid instruction shape"));
5287ad62 11238
037e8744
JB
11239 return shape;
11240}
5287ad62 11241
037e8744
JB
11242/* True if SHAPE is predominantly a quadword operation (most of the time, this
11243 means the Q bit should be set). */
11244
11245static int
11246neon_quad (enum neon_shape shape)
11247{
11248 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11249}
037e8744 11250
5287ad62
JB
11251static void
11252neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11253 unsigned *g_size)
11254{
11255 /* Allow modification to be made to types which are constrained to be
11256 based on the key element, based on bits set alongside N_EQK. */
11257 if ((typebits & N_EQK) != 0)
11258 {
11259 if ((typebits & N_HLF) != 0)
11260 *g_size /= 2;
11261 else if ((typebits & N_DBL) != 0)
11262 *g_size *= 2;
11263 if ((typebits & N_SGN) != 0)
11264 *g_type = NT_signed;
11265 else if ((typebits & N_UNS) != 0)
11266 *g_type = NT_unsigned;
11267 else if ((typebits & N_INT) != 0)
11268 *g_type = NT_integer;
11269 else if ((typebits & N_FLT) != 0)
11270 *g_type = NT_float;
dcbf9037
JB
11271 else if ((typebits & N_SIZ) != 0)
11272 *g_type = NT_untyped;
5287ad62
JB
11273 }
11274}
5f4273c7 11275
5287ad62
JB
11276/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11277 operand type, i.e. the single type specified in a Neon instruction when it
11278 is the only one given. */
11279
11280static struct neon_type_el
11281neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11282{
11283 struct neon_type_el dest = *key;
5f4273c7 11284
5287ad62 11285 assert ((thisarg & N_EQK) != 0);
5f4273c7 11286
5287ad62
JB
11287 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11288
11289 return dest;
11290}
11291
11292/* Convert Neon type and size into compact bitmask representation. */
11293
11294static enum neon_type_mask
11295type_chk_of_el_type (enum neon_el_type type, unsigned size)
11296{
11297 switch (type)
11298 {
11299 case NT_untyped:
11300 switch (size)
11301 {
11302 case 8: return N_8;
11303 case 16: return N_16;
11304 case 32: return N_32;
11305 case 64: return N_64;
11306 default: ;
11307 }
11308 break;
11309
11310 case NT_integer:
11311 switch (size)
11312 {
11313 case 8: return N_I8;
11314 case 16: return N_I16;
11315 case 32: return N_I32;
11316 case 64: return N_I64;
11317 default: ;
11318 }
11319 break;
11320
11321 case NT_float:
037e8744
JB
11322 switch (size)
11323 {
8e79c3df 11324 case 16: return N_F16;
037e8744
JB
11325 case 32: return N_F32;
11326 case 64: return N_F64;
11327 default: ;
11328 }
5287ad62
JB
11329 break;
11330
11331 case NT_poly:
11332 switch (size)
11333 {
11334 case 8: return N_P8;
11335 case 16: return N_P16;
11336 default: ;
11337 }
11338 break;
11339
11340 case NT_signed:
11341 switch (size)
11342 {
11343 case 8: return N_S8;
11344 case 16: return N_S16;
11345 case 32: return N_S32;
11346 case 64: return N_S64;
11347 default: ;
11348 }
11349 break;
11350
11351 case NT_unsigned:
11352 switch (size)
11353 {
11354 case 8: return N_U8;
11355 case 16: return N_U16;
11356 case 32: return N_U32;
11357 case 64: return N_U64;
11358 default: ;
11359 }
11360 break;
11361
11362 default: ;
11363 }
5f4273c7 11364
5287ad62
JB
11365 return N_UTYP;
11366}
11367
11368/* Convert compact Neon bitmask type representation to a type and size. Only
11369 handles the case where a single bit is set in the mask. */
11370
dcbf9037 11371static int
5287ad62
JB
11372el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11373 enum neon_type_mask mask)
11374{
dcbf9037
JB
11375 if ((mask & N_EQK) != 0)
11376 return FAIL;
11377
5287ad62
JB
11378 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11379 *size = 8;
dcbf9037 11380 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11381 *size = 16;
dcbf9037 11382 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11383 *size = 32;
037e8744 11384 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11385 *size = 64;
dcbf9037
JB
11386 else
11387 return FAIL;
11388
5287ad62
JB
11389 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11390 *type = NT_signed;
dcbf9037 11391 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11392 *type = NT_unsigned;
dcbf9037 11393 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11394 *type = NT_integer;
dcbf9037 11395 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11396 *type = NT_untyped;
dcbf9037 11397 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11398 *type = NT_poly;
037e8744 11399 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11400 *type = NT_float;
dcbf9037
JB
11401 else
11402 return FAIL;
5f4273c7 11403
dcbf9037 11404 return SUCCESS;
5287ad62
JB
11405}
11406
11407/* Modify a bitmask of allowed types. This is only needed for type
11408 relaxation. */
11409
11410static unsigned
11411modify_types_allowed (unsigned allowed, unsigned mods)
11412{
11413 unsigned size;
11414 enum neon_el_type type;
11415 unsigned destmask;
11416 int i;
5f4273c7 11417
5287ad62 11418 destmask = 0;
5f4273c7 11419
5287ad62
JB
11420 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11421 {
dcbf9037
JB
11422 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11423 {
11424 neon_modify_type_size (mods, &type, &size);
11425 destmask |= type_chk_of_el_type (type, size);
11426 }
5287ad62 11427 }
5f4273c7 11428
5287ad62
JB
11429 return destmask;
11430}
11431
11432/* Check type and return type classification.
11433 The manual states (paraphrase): If one datatype is given, it indicates the
11434 type given in:
11435 - the second operand, if there is one
11436 - the operand, if there is no second operand
11437 - the result, if there are no operands.
11438 This isn't quite good enough though, so we use a concept of a "key" datatype
11439 which is set on a per-instruction basis, which is the one which matters when
11440 only one data type is written.
11441 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11442 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11443
11444static struct neon_type_el
11445neon_check_type (unsigned els, enum neon_shape ns, ...)
11446{
11447 va_list ap;
11448 unsigned i, pass, key_el = 0;
11449 unsigned types[NEON_MAX_TYPE_ELS];
11450 enum neon_el_type k_type = NT_invtype;
11451 unsigned k_size = -1u;
11452 struct neon_type_el badtype = {NT_invtype, -1};
11453 unsigned key_allowed = 0;
11454
11455 /* Optional registers in Neon instructions are always (not) in operand 1.
11456 Fill in the missing operand here, if it was omitted. */
11457 if (els > 1 && !inst.operands[1].present)
11458 inst.operands[1] = inst.operands[0];
11459
11460 /* Suck up all the varargs. */
11461 va_start (ap, ns);
11462 for (i = 0; i < els; i++)
11463 {
11464 unsigned thisarg = va_arg (ap, unsigned);
11465 if (thisarg == N_IGNORE_TYPE)
11466 {
11467 va_end (ap);
11468 return badtype;
11469 }
11470 types[i] = thisarg;
11471 if ((thisarg & N_KEY) != 0)
11472 key_el = i;
11473 }
11474 va_end (ap);
11475
dcbf9037
JB
11476 if (inst.vectype.elems > 0)
11477 for (i = 0; i < els; i++)
11478 if (inst.operands[i].vectype.type != NT_invtype)
11479 {
11480 first_error (_("types specified in both the mnemonic and operands"));
11481 return badtype;
11482 }
11483
5287ad62
JB
11484 /* Duplicate inst.vectype elements here as necessary.
11485 FIXME: No idea if this is exactly the same as the ARM assembler,
11486 particularly when an insn takes one register and one non-register
11487 operand. */
11488 if (inst.vectype.elems == 1 && els > 1)
11489 {
11490 unsigned j;
11491 inst.vectype.elems = els;
11492 inst.vectype.el[key_el] = inst.vectype.el[0];
11493 for (j = 0; j < els; j++)
dcbf9037
JB
11494 if (j != key_el)
11495 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11496 types[j]);
11497 }
11498 else if (inst.vectype.elems == 0 && els > 0)
11499 {
11500 unsigned j;
11501 /* No types were given after the mnemonic, so look for types specified
11502 after each operand. We allow some flexibility here; as long as the
11503 "key" operand has a type, we can infer the others. */
11504 for (j = 0; j < els; j++)
11505 if (inst.operands[j].vectype.type != NT_invtype)
11506 inst.vectype.el[j] = inst.operands[j].vectype;
11507
11508 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11509 {
dcbf9037
JB
11510 for (j = 0; j < els; j++)
11511 if (inst.operands[j].vectype.type == NT_invtype)
11512 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11513 types[j]);
11514 }
11515 else
11516 {
11517 first_error (_("operand types can't be inferred"));
11518 return badtype;
5287ad62
JB
11519 }
11520 }
11521 else if (inst.vectype.elems != els)
11522 {
dcbf9037 11523 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11524 return badtype;
11525 }
11526
11527 for (pass = 0; pass < 2; pass++)
11528 {
11529 for (i = 0; i < els; i++)
11530 {
11531 unsigned thisarg = types[i];
11532 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11533 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11534 enum neon_el_type g_type = inst.vectype.el[i].type;
11535 unsigned g_size = inst.vectype.el[i].size;
11536
11537 /* Decay more-specific signed & unsigned types to sign-insensitive
11538 integer types if sign-specific variants are unavailable. */
11539 if ((g_type == NT_signed || g_type == NT_unsigned)
11540 && (types_allowed & N_SU_ALL) == 0)
11541 g_type = NT_integer;
11542
11543 /* If only untyped args are allowed, decay any more specific types to
11544 them. Some instructions only care about signs for some element
11545 sizes, so handle that properly. */
11546 if ((g_size == 8 && (types_allowed & N_8) != 0)
11547 || (g_size == 16 && (types_allowed & N_16) != 0)
11548 || (g_size == 32 && (types_allowed & N_32) != 0)
11549 || (g_size == 64 && (types_allowed & N_64) != 0))
11550 g_type = NT_untyped;
11551
11552 if (pass == 0)
11553 {
11554 if ((thisarg & N_KEY) != 0)
11555 {
11556 k_type = g_type;
11557 k_size = g_size;
11558 key_allowed = thisarg & ~N_KEY;
11559 }
11560 }
11561 else
11562 {
037e8744
JB
11563 if ((thisarg & N_VFP) != 0)
11564 {
11565 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11566 unsigned regwidth = neon_shape_el_size[regshape], match;
11567
11568 /* In VFP mode, operands must match register widths. If we
11569 have a key operand, use its width, else use the width of
11570 the current operand. */
11571 if (k_size != -1u)
11572 match = k_size;
11573 else
11574 match = g_size;
11575
11576 if (regwidth != match)
11577 {
11578 first_error (_("operand size must match register width"));
11579 return badtype;
11580 }
11581 }
5f4273c7 11582
5287ad62
JB
11583 if ((thisarg & N_EQK) == 0)
11584 {
11585 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11586
11587 if ((given_type & types_allowed) == 0)
11588 {
dcbf9037 11589 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11590 return badtype;
11591 }
11592 }
11593 else
11594 {
11595 enum neon_el_type mod_k_type = k_type;
11596 unsigned mod_k_size = k_size;
11597 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11598 if (g_type != mod_k_type || g_size != mod_k_size)
11599 {
dcbf9037 11600 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11601 return badtype;
11602 }
11603 }
11604 }
11605 }
11606 }
11607
11608 return inst.vectype.el[key_el];
11609}
11610
037e8744 11611/* Neon-style VFP instruction forwarding. */
5287ad62 11612
037e8744
JB
11613/* Thumb VFP instructions have 0xE in the condition field. */
11614
11615static void
11616do_vfp_cond_or_thumb (void)
5287ad62
JB
11617{
11618 if (thumb_mode)
037e8744 11619 inst.instruction |= 0xe0000000;
5287ad62 11620 else
037e8744 11621 inst.instruction |= inst.cond << 28;
5287ad62
JB
11622}
11623
037e8744
JB
11624/* Look up and encode a simple mnemonic, for use as a helper function for the
11625 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11626 etc. It is assumed that operand parsing has already been done, and that the
11627 operands are in the form expected by the given opcode (this isn't necessarily
11628 the same as the form in which they were parsed, hence some massaging must
11629 take place before this function is called).
11630 Checks current arch version against that in the looked-up opcode. */
5287ad62 11631
037e8744
JB
11632static void
11633do_vfp_nsyn_opcode (const char *opname)
5287ad62 11634{
037e8744 11635 const struct asm_opcode *opcode;
5f4273c7 11636
037e8744 11637 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11638
037e8744
JB
11639 if (!opcode)
11640 abort ();
5287ad62 11641
037e8744
JB
11642 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11643 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11644 _(BAD_FPU));
5287ad62 11645
037e8744
JB
11646 if (thumb_mode)
11647 {
11648 inst.instruction = opcode->tvalue;
11649 opcode->tencode ();
11650 }
11651 else
11652 {
11653 inst.instruction = (inst.cond << 28) | opcode->avalue;
11654 opcode->aencode ();
11655 }
11656}
5287ad62
JB
11657
11658static void
037e8744 11659do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11660{
037e8744
JB
11661 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11662
11663 if (rs == NS_FFF)
11664 {
11665 if (is_add)
11666 do_vfp_nsyn_opcode ("fadds");
11667 else
11668 do_vfp_nsyn_opcode ("fsubs");
11669 }
11670 else
11671 {
11672 if (is_add)
11673 do_vfp_nsyn_opcode ("faddd");
11674 else
11675 do_vfp_nsyn_opcode ("fsubd");
11676 }
11677}
11678
11679/* Check operand types to see if this is a VFP instruction, and if so call
11680 PFN (). */
11681
11682static int
11683try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11684{
11685 enum neon_shape rs;
11686 struct neon_type_el et;
11687
11688 switch (args)
11689 {
11690 case 2:
11691 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11692 et = neon_check_type (2, rs,
11693 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11694 break;
5f4273c7 11695
037e8744
JB
11696 case 3:
11697 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11698 et = neon_check_type (3, rs,
11699 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11700 break;
11701
11702 default:
11703 abort ();
11704 }
11705
11706 if (et.type != NT_invtype)
11707 {
11708 pfn (rs);
11709 return SUCCESS;
11710 }
11711 else
11712 inst.error = NULL;
11713
11714 return FAIL;
11715}
11716
11717static void
11718do_vfp_nsyn_mla_mls (enum neon_shape rs)
11719{
11720 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11721
037e8744
JB
11722 if (rs == NS_FFF)
11723 {
11724 if (is_mla)
11725 do_vfp_nsyn_opcode ("fmacs");
11726 else
11727 do_vfp_nsyn_opcode ("fmscs");
11728 }
11729 else
11730 {
11731 if (is_mla)
11732 do_vfp_nsyn_opcode ("fmacd");
11733 else
11734 do_vfp_nsyn_opcode ("fmscd");
11735 }
11736}
11737
11738static void
11739do_vfp_nsyn_mul (enum neon_shape rs)
11740{
11741 if (rs == NS_FFF)
11742 do_vfp_nsyn_opcode ("fmuls");
11743 else
11744 do_vfp_nsyn_opcode ("fmuld");
11745}
11746
11747static void
11748do_vfp_nsyn_abs_neg (enum neon_shape rs)
11749{
11750 int is_neg = (inst.instruction & 0x80) != 0;
11751 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11752
11753 if (rs == NS_FF)
11754 {
11755 if (is_neg)
11756 do_vfp_nsyn_opcode ("fnegs");
11757 else
11758 do_vfp_nsyn_opcode ("fabss");
11759 }
11760 else
11761 {
11762 if (is_neg)
11763 do_vfp_nsyn_opcode ("fnegd");
11764 else
11765 do_vfp_nsyn_opcode ("fabsd");
11766 }
11767}
11768
11769/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11770 insns belong to Neon, and are handled elsewhere. */
11771
11772static void
11773do_vfp_nsyn_ldm_stm (int is_dbmode)
11774{
11775 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11776 if (is_ldm)
11777 {
11778 if (is_dbmode)
11779 do_vfp_nsyn_opcode ("fldmdbs");
11780 else
11781 do_vfp_nsyn_opcode ("fldmias");
11782 }
11783 else
11784 {
11785 if (is_dbmode)
11786 do_vfp_nsyn_opcode ("fstmdbs");
11787 else
11788 do_vfp_nsyn_opcode ("fstmias");
11789 }
11790}
11791
037e8744
JB
11792static void
11793do_vfp_nsyn_sqrt (void)
11794{
11795 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11796 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11797
037e8744
JB
11798 if (rs == NS_FF)
11799 do_vfp_nsyn_opcode ("fsqrts");
11800 else
11801 do_vfp_nsyn_opcode ("fsqrtd");
11802}
11803
11804static void
11805do_vfp_nsyn_div (void)
11806{
11807 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11808 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11809 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11810
037e8744
JB
11811 if (rs == NS_FFF)
11812 do_vfp_nsyn_opcode ("fdivs");
11813 else
11814 do_vfp_nsyn_opcode ("fdivd");
11815}
11816
11817static void
11818do_vfp_nsyn_nmul (void)
11819{
11820 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11821 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11822 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11823
037e8744
JB
11824 if (rs == NS_FFF)
11825 {
11826 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11827 do_vfp_sp_dyadic ();
11828 }
11829 else
11830 {
11831 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11832 do_vfp_dp_rd_rn_rm ();
11833 }
11834 do_vfp_cond_or_thumb ();
11835}
11836
11837static void
11838do_vfp_nsyn_cmp (void)
11839{
11840 if (inst.operands[1].isreg)
11841 {
11842 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11843 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11844
037e8744
JB
11845 if (rs == NS_FF)
11846 {
11847 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11848 do_vfp_sp_monadic ();
11849 }
11850 else
11851 {
11852 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11853 do_vfp_dp_rd_rm ();
11854 }
11855 }
11856 else
11857 {
11858 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11859 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11860
11861 switch (inst.instruction & 0x0fffffff)
11862 {
11863 case N_MNEM_vcmp:
11864 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11865 break;
11866 case N_MNEM_vcmpe:
11867 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11868 break;
11869 default:
11870 abort ();
11871 }
5f4273c7 11872
037e8744
JB
11873 if (rs == NS_FI)
11874 {
11875 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11876 do_vfp_sp_compare_z ();
11877 }
11878 else
11879 {
11880 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11881 do_vfp_dp_rd ();
11882 }
11883 }
11884 do_vfp_cond_or_thumb ();
11885}
11886
11887static void
11888nsyn_insert_sp (void)
11889{
11890 inst.operands[1] = inst.operands[0];
11891 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 11892 inst.operands[0].reg = REG_SP;
037e8744
JB
11893 inst.operands[0].isreg = 1;
11894 inst.operands[0].writeback = 1;
11895 inst.operands[0].present = 1;
11896}
11897
11898static void
11899do_vfp_nsyn_push (void)
11900{
11901 nsyn_insert_sp ();
11902 if (inst.operands[1].issingle)
11903 do_vfp_nsyn_opcode ("fstmdbs");
11904 else
11905 do_vfp_nsyn_opcode ("fstmdbd");
11906}
11907
11908static void
11909do_vfp_nsyn_pop (void)
11910{
11911 nsyn_insert_sp ();
11912 if (inst.operands[1].issingle)
22b5b651 11913 do_vfp_nsyn_opcode ("fldmias");
037e8744 11914 else
22b5b651 11915 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11916}
11917
11918/* Fix up Neon data-processing instructions, ORing in the correct bits for
11919 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11920
11921static unsigned
11922neon_dp_fixup (unsigned i)
11923{
11924 if (thumb_mode)
11925 {
11926 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11927 if (i & (1 << 24))
11928 i |= 1 << 28;
5f4273c7 11929
037e8744 11930 i &= ~(1 << 24);
5f4273c7 11931
037e8744
JB
11932 i |= 0xef000000;
11933 }
11934 else
11935 i |= 0xf2000000;
5f4273c7 11936
037e8744
JB
11937 return i;
11938}
11939
11940/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11941 (0, 1, 2, 3). */
11942
11943static unsigned
11944neon_logbits (unsigned x)
11945{
11946 return ffs (x) - 4;
11947}
11948
11949#define LOW4(R) ((R) & 0xf)
11950#define HI1(R) (((R) >> 4) & 1)
11951
11952/* Encode insns with bit pattern:
11953
11954 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11955 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 11956
037e8744
JB
11957 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11958 different meaning for some instruction. */
11959
11960static void
11961neon_three_same (int isquad, int ubit, int size)
11962{
11963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11965 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11966 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11967 inst.instruction |= LOW4 (inst.operands[2].reg);
11968 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11969 inst.instruction |= (isquad != 0) << 6;
11970 inst.instruction |= (ubit != 0) << 24;
11971 if (size != -1)
11972 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 11973
037e8744
JB
11974 inst.instruction = neon_dp_fixup (inst.instruction);
11975}
11976
11977/* Encode instructions of the form:
11978
11979 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11980 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11981
11982 Don't write size if SIZE == -1. */
11983
11984static void
11985neon_two_same (int qbit, int ubit, int size)
11986{
11987 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11988 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11989 inst.instruction |= LOW4 (inst.operands[1].reg);
11990 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11991 inst.instruction |= (qbit != 0) << 6;
11992 inst.instruction |= (ubit != 0) << 24;
11993
11994 if (size != -1)
11995 inst.instruction |= neon_logbits (size) << 18;
11996
11997 inst.instruction = neon_dp_fixup (inst.instruction);
11998}
11999
12000/* Neon instruction encoders, in approximate order of appearance. */
12001
12002static void
12003do_neon_dyadic_i_su (void)
12004{
037e8744 12005 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12006 struct neon_type_el et = neon_check_type (3, rs,
12007 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12008 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12009}
12010
12011static void
12012do_neon_dyadic_i64_su (void)
12013{
037e8744 12014 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12015 struct neon_type_el et = neon_check_type (3, rs,
12016 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12017 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12018}
12019
12020static void
12021neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12022 unsigned immbits)
12023{
12024 unsigned size = et.size >> 3;
12025 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12026 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12027 inst.instruction |= LOW4 (inst.operands[1].reg);
12028 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12029 inst.instruction |= (isquad != 0) << 6;
12030 inst.instruction |= immbits << 16;
12031 inst.instruction |= (size >> 3) << 7;
12032 inst.instruction |= (size & 0x7) << 19;
12033 if (write_ubit)
12034 inst.instruction |= (uval != 0) << 24;
12035
12036 inst.instruction = neon_dp_fixup (inst.instruction);
12037}
12038
12039static void
12040do_neon_shl_imm (void)
12041{
12042 if (!inst.operands[2].isreg)
12043 {
037e8744 12044 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12045 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12046 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12047 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12048 }
12049 else
12050 {
037e8744 12051 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12052 struct neon_type_el et = neon_check_type (3, rs,
12053 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12054 unsigned int tmp;
12055
12056 /* VSHL/VQSHL 3-register variants have syntax such as:
12057 vshl.xx Dd, Dm, Dn
12058 whereas other 3-register operations encoded by neon_three_same have
12059 syntax like:
12060 vadd.xx Dd, Dn, Dm
12061 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12062 here. */
12063 tmp = inst.operands[2].reg;
12064 inst.operands[2].reg = inst.operands[1].reg;
12065 inst.operands[1].reg = tmp;
5287ad62 12066 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12067 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12068 }
12069}
12070
12071static void
12072do_neon_qshl_imm (void)
12073{
12074 if (!inst.operands[2].isreg)
12075 {
037e8744 12076 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12077 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12078
5287ad62 12079 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12080 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12081 inst.operands[2].imm);
12082 }
12083 else
12084 {
037e8744 12085 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12086 struct neon_type_el et = neon_check_type (3, rs,
12087 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12088 unsigned int tmp;
12089
12090 /* See note in do_neon_shl_imm. */
12091 tmp = inst.operands[2].reg;
12092 inst.operands[2].reg = inst.operands[1].reg;
12093 inst.operands[1].reg = tmp;
5287ad62 12094 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12095 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12096 }
12097}
12098
627907b7
JB
12099static void
12100do_neon_rshl (void)
12101{
12102 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12103 struct neon_type_el et = neon_check_type (3, rs,
12104 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12105 unsigned int tmp;
12106
12107 tmp = inst.operands[2].reg;
12108 inst.operands[2].reg = inst.operands[1].reg;
12109 inst.operands[1].reg = tmp;
12110 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12111}
12112
5287ad62
JB
12113static int
12114neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12115{
036dc3f7
PB
12116 /* Handle .I8 pseudo-instructions. */
12117 if (size == 8)
5287ad62 12118 {
5287ad62
JB
12119 /* Unfortunately, this will make everything apart from zero out-of-range.
12120 FIXME is this the intended semantics? There doesn't seem much point in
12121 accepting .I8 if so. */
12122 immediate |= immediate << 8;
12123 size = 16;
036dc3f7
PB
12124 }
12125
12126 if (size >= 32)
12127 {
12128 if (immediate == (immediate & 0x000000ff))
12129 {
12130 *immbits = immediate;
12131 return 0x1;
12132 }
12133 else if (immediate == (immediate & 0x0000ff00))
12134 {
12135 *immbits = immediate >> 8;
12136 return 0x3;
12137 }
12138 else if (immediate == (immediate & 0x00ff0000))
12139 {
12140 *immbits = immediate >> 16;
12141 return 0x5;
12142 }
12143 else if (immediate == (immediate & 0xff000000))
12144 {
12145 *immbits = immediate >> 24;
12146 return 0x7;
12147 }
12148 if ((immediate & 0xffff) != (immediate >> 16))
12149 goto bad_immediate;
12150 immediate &= 0xffff;
5287ad62
JB
12151 }
12152
12153 if (immediate == (immediate & 0x000000ff))
12154 {
12155 *immbits = immediate;
036dc3f7 12156 return 0x9;
5287ad62
JB
12157 }
12158 else if (immediate == (immediate & 0x0000ff00))
12159 {
12160 *immbits = immediate >> 8;
036dc3f7 12161 return 0xb;
5287ad62
JB
12162 }
12163
12164 bad_immediate:
dcbf9037 12165 first_error (_("immediate value out of range"));
5287ad62
JB
12166 return FAIL;
12167}
12168
12169/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12170 A, B, C, D. */
12171
12172static int
12173neon_bits_same_in_bytes (unsigned imm)
12174{
12175 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12176 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12177 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12178 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12179}
12180
12181/* For immediate of above form, return 0bABCD. */
12182
12183static unsigned
12184neon_squash_bits (unsigned imm)
12185{
12186 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12187 | ((imm & 0x01000000) >> 21);
12188}
12189
136da414 12190/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12191
12192static unsigned
12193neon_qfloat_bits (unsigned imm)
12194{
136da414 12195 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12196}
12197
12198/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12199 the instruction. *OP is passed as the initial value of the op field, and
12200 may be set to a different value depending on the constant (i.e.
12201 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12202 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12203 try smaller element sizes. */
5287ad62
JB
12204
12205static int
c96612cc
JB
12206neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12207 unsigned *immbits, int *op, int size,
12208 enum neon_el_type type)
5287ad62 12209{
c96612cc
JB
12210 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12211 float. */
12212 if (type == NT_float && !float_p)
12213 return FAIL;
12214
136da414
JB
12215 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12216 {
12217 if (size != 32 || *op == 1)
12218 return FAIL;
12219 *immbits = neon_qfloat_bits (immlo);
12220 return 0xf;
12221 }
036dc3f7
PB
12222
12223 if (size == 64)
5287ad62 12224 {
036dc3f7
PB
12225 if (neon_bits_same_in_bytes (immhi)
12226 && neon_bits_same_in_bytes (immlo))
12227 {
12228 if (*op == 1)
12229 return FAIL;
12230 *immbits = (neon_squash_bits (immhi) << 4)
12231 | neon_squash_bits (immlo);
12232 *op = 1;
12233 return 0xe;
12234 }
12235
12236 if (immhi != immlo)
12237 return FAIL;
5287ad62 12238 }
036dc3f7
PB
12239
12240 if (size >= 32)
5287ad62 12241 {
036dc3f7
PB
12242 if (immlo == (immlo & 0x000000ff))
12243 {
12244 *immbits = immlo;
12245 return 0x0;
12246 }
12247 else if (immlo == (immlo & 0x0000ff00))
12248 {
12249 *immbits = immlo >> 8;
12250 return 0x2;
12251 }
12252 else if (immlo == (immlo & 0x00ff0000))
12253 {
12254 *immbits = immlo >> 16;
12255 return 0x4;
12256 }
12257 else if (immlo == (immlo & 0xff000000))
12258 {
12259 *immbits = immlo >> 24;
12260 return 0x6;
12261 }
12262 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12263 {
12264 *immbits = (immlo >> 8) & 0xff;
12265 return 0xc;
12266 }
12267 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12268 {
12269 *immbits = (immlo >> 16) & 0xff;
12270 return 0xd;
12271 }
12272
12273 if ((immlo & 0xffff) != (immlo >> 16))
12274 return FAIL;
12275 immlo &= 0xffff;
5287ad62 12276 }
036dc3f7
PB
12277
12278 if (size >= 16)
5287ad62 12279 {
036dc3f7
PB
12280 if (immlo == (immlo & 0x000000ff))
12281 {
12282 *immbits = immlo;
12283 return 0x8;
12284 }
12285 else if (immlo == (immlo & 0x0000ff00))
12286 {
12287 *immbits = immlo >> 8;
12288 return 0xa;
12289 }
12290
12291 if ((immlo & 0xff) != (immlo >> 8))
12292 return FAIL;
12293 immlo &= 0xff;
5287ad62 12294 }
036dc3f7
PB
12295
12296 if (immlo == (immlo & 0x000000ff))
5287ad62 12297 {
036dc3f7
PB
12298 /* Don't allow MVN with 8-bit immediate. */
12299 if (*op == 1)
12300 return FAIL;
12301 *immbits = immlo;
12302 return 0xe;
5287ad62 12303 }
5287ad62
JB
12304
12305 return FAIL;
12306}
12307
12308/* Write immediate bits [7:0] to the following locations:
12309
12310 |28/24|23 19|18 16|15 4|3 0|
12311 | 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|
12312
12313 This function is used by VMOV/VMVN/VORR/VBIC. */
12314
12315static void
12316neon_write_immbits (unsigned immbits)
12317{
12318 inst.instruction |= immbits & 0xf;
12319 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12320 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12321}
12322
12323/* Invert low-order SIZE bits of XHI:XLO. */
12324
12325static void
12326neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12327{
12328 unsigned immlo = xlo ? *xlo : 0;
12329 unsigned immhi = xhi ? *xhi : 0;
12330
12331 switch (size)
12332 {
12333 case 8:
12334 immlo = (~immlo) & 0xff;
12335 break;
12336
12337 case 16:
12338 immlo = (~immlo) & 0xffff;
12339 break;
12340
12341 case 64:
12342 immhi = (~immhi) & 0xffffffff;
12343 /* fall through. */
12344
12345 case 32:
12346 immlo = (~immlo) & 0xffffffff;
12347 break;
12348
12349 default:
12350 abort ();
12351 }
12352
12353 if (xlo)
12354 *xlo = immlo;
12355
12356 if (xhi)
12357 *xhi = immhi;
12358}
12359
12360static void
12361do_neon_logic (void)
12362{
12363 if (inst.operands[2].present && inst.operands[2].isreg)
12364 {
037e8744 12365 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12366 neon_check_type (3, rs, N_IGNORE_TYPE);
12367 /* U bit and size field were set as part of the bitmask. */
12368 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12369 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12370 }
12371 else
12372 {
037e8744
JB
12373 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12374 struct neon_type_el et = neon_check_type (2, rs,
12375 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
12376 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12377 unsigned immbits;
12378 int cmode;
5f4273c7 12379
5287ad62
JB
12380 if (et.type == NT_invtype)
12381 return;
5f4273c7 12382
5287ad62
JB
12383 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12384
036dc3f7
PB
12385 immbits = inst.operands[1].imm;
12386 if (et.size == 64)
12387 {
12388 /* .i64 is a pseudo-op, so the immediate must be a repeating
12389 pattern. */
12390 if (immbits != (inst.operands[1].regisimm ?
12391 inst.operands[1].reg : 0))
12392 {
12393 /* Set immbits to an invalid constant. */
12394 immbits = 0xdeadbeef;
12395 }
12396 }
12397
5287ad62
JB
12398 switch (opcode)
12399 {
12400 case N_MNEM_vbic:
036dc3f7 12401 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12402 break;
5f4273c7 12403
5287ad62 12404 case N_MNEM_vorr:
036dc3f7 12405 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12406 break;
5f4273c7 12407
5287ad62
JB
12408 case N_MNEM_vand:
12409 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12410 neon_invert_size (&immbits, 0, et.size);
12411 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12412 break;
5f4273c7 12413
5287ad62
JB
12414 case N_MNEM_vorn:
12415 /* Pseudo-instruction for VORR. */
5287ad62
JB
12416 neon_invert_size (&immbits, 0, et.size);
12417 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12418 break;
5f4273c7 12419
5287ad62
JB
12420 default:
12421 abort ();
12422 }
12423
12424 if (cmode == FAIL)
12425 return;
12426
037e8744 12427 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12429 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12430 inst.instruction |= cmode << 8;
12431 neon_write_immbits (immbits);
5f4273c7 12432
5287ad62
JB
12433 inst.instruction = neon_dp_fixup (inst.instruction);
12434 }
12435}
12436
12437static void
12438do_neon_bitfield (void)
12439{
037e8744 12440 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12441 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12442 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12443}
12444
12445static void
dcbf9037
JB
12446neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12447 unsigned destbits)
5287ad62 12448{
037e8744 12449 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12450 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12451 types | N_KEY);
5287ad62
JB
12452 if (et.type == NT_float)
12453 {
12454 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12455 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12456 }
12457 else
12458 {
12459 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12460 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12461 }
12462}
12463
12464static void
12465do_neon_dyadic_if_su (void)
12466{
dcbf9037 12467 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12468}
12469
12470static void
12471do_neon_dyadic_if_su_d (void)
12472{
12473 /* This version only allow D registers, but that constraint is enforced during
12474 operand parsing so we don't need to do anything extra here. */
dcbf9037 12475 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12476}
12477
5287ad62
JB
12478static void
12479do_neon_dyadic_if_i_d (void)
12480{
428e3f1f
PB
12481 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12482 affected if we specify unsigned args. */
12483 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12484}
12485
037e8744
JB
12486enum vfp_or_neon_is_neon_bits
12487{
12488 NEON_CHECK_CC = 1,
12489 NEON_CHECK_ARCH = 2
12490};
12491
12492/* Call this function if an instruction which may have belonged to the VFP or
12493 Neon instruction sets, but turned out to be a Neon instruction (due to the
12494 operand types involved, etc.). We have to check and/or fix-up a couple of
12495 things:
12496
12497 - Make sure the user hasn't attempted to make a Neon instruction
12498 conditional.
12499 - Alter the value in the condition code field if necessary.
12500 - Make sure that the arch supports Neon instructions.
12501
12502 Which of these operations take place depends on bits from enum
12503 vfp_or_neon_is_neon_bits.
12504
12505 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12506 current instruction's condition is COND_ALWAYS, the condition field is
12507 changed to inst.uncond_value. This is necessary because instructions shared
12508 between VFP and Neon may be conditional for the VFP variants only, and the
12509 unconditional Neon version must have, e.g., 0xF in the condition field. */
12510
12511static int
12512vfp_or_neon_is_neon (unsigned check)
12513{
12514 /* Conditions are always legal in Thumb mode (IT blocks). */
12515 if (!thumb_mode && (check & NEON_CHECK_CC))
12516 {
12517 if (inst.cond != COND_ALWAYS)
12518 {
12519 first_error (_(BAD_COND));
12520 return FAIL;
12521 }
12522 if (inst.uncond_value != -1)
12523 inst.instruction |= inst.uncond_value << 28;
12524 }
5f4273c7 12525
037e8744
JB
12526 if ((check & NEON_CHECK_ARCH)
12527 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12528 {
12529 first_error (_(BAD_FPU));
12530 return FAIL;
12531 }
5f4273c7 12532
037e8744
JB
12533 return SUCCESS;
12534}
12535
5287ad62
JB
12536static void
12537do_neon_addsub_if_i (void)
12538{
037e8744
JB
12539 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12540 return;
12541
12542 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12543 return;
12544
5287ad62
JB
12545 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12546 affected if we specify unsigned args. */
dcbf9037 12547 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12548}
12549
12550/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12551 result to be:
12552 V<op> A,B (A is operand 0, B is operand 2)
12553 to mean:
12554 V<op> A,B,A
12555 not:
12556 V<op> A,B,B
12557 so handle that case specially. */
12558
12559static void
12560neon_exchange_operands (void)
12561{
12562 void *scratch = alloca (sizeof (inst.operands[0]));
12563 if (inst.operands[1].present)
12564 {
12565 /* Swap operands[1] and operands[2]. */
12566 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12567 inst.operands[1] = inst.operands[2];
12568 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12569 }
12570 else
12571 {
12572 inst.operands[1] = inst.operands[2];
12573 inst.operands[2] = inst.operands[0];
12574 }
12575}
12576
12577static void
12578neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12579{
12580 if (inst.operands[2].isreg)
12581 {
12582 if (invert)
12583 neon_exchange_operands ();
dcbf9037 12584 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12585 }
12586 else
12587 {
037e8744 12588 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12589 struct neon_type_el et = neon_check_type (2, rs,
12590 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12591
12592 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12593 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12594 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12595 inst.instruction |= LOW4 (inst.operands[1].reg);
12596 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12597 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12598 inst.instruction |= (et.type == NT_float) << 10;
12599 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12600
5287ad62
JB
12601 inst.instruction = neon_dp_fixup (inst.instruction);
12602 }
12603}
12604
12605static void
12606do_neon_cmp (void)
12607{
12608 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12609}
12610
12611static void
12612do_neon_cmp_inv (void)
12613{
12614 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12615}
12616
12617static void
12618do_neon_ceq (void)
12619{
12620 neon_compare (N_IF_32, N_IF_32, FALSE);
12621}
12622
12623/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12624 scalars, which are encoded in 5 bits, M : Rm.
12625 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12626 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12627 index in M. */
12628
12629static unsigned
12630neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12631{
dcbf9037
JB
12632 unsigned regno = NEON_SCALAR_REG (scalar);
12633 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12634
12635 switch (elsize)
12636 {
12637 case 16:
12638 if (regno > 7 || elno > 3)
12639 goto bad_scalar;
12640 return regno | (elno << 3);
5f4273c7 12641
5287ad62
JB
12642 case 32:
12643 if (regno > 15 || elno > 1)
12644 goto bad_scalar;
12645 return regno | (elno << 4);
12646
12647 default:
12648 bad_scalar:
dcbf9037 12649 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12650 }
12651
12652 return 0;
12653}
12654
12655/* Encode multiply / multiply-accumulate scalar instructions. */
12656
12657static void
12658neon_mul_mac (struct neon_type_el et, int ubit)
12659{
dcbf9037
JB
12660 unsigned scalar;
12661
12662 /* Give a more helpful error message if we have an invalid type. */
12663 if (et.type == NT_invtype)
12664 return;
5f4273c7 12665
dcbf9037 12666 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12667 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12668 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12669 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12670 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12671 inst.instruction |= LOW4 (scalar);
12672 inst.instruction |= HI1 (scalar) << 5;
12673 inst.instruction |= (et.type == NT_float) << 8;
12674 inst.instruction |= neon_logbits (et.size) << 20;
12675 inst.instruction |= (ubit != 0) << 24;
12676
12677 inst.instruction = neon_dp_fixup (inst.instruction);
12678}
12679
12680static void
12681do_neon_mac_maybe_scalar (void)
12682{
037e8744
JB
12683 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12684 return;
12685
12686 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12687 return;
12688
5287ad62
JB
12689 if (inst.operands[2].isscalar)
12690 {
037e8744 12691 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12692 struct neon_type_el et = neon_check_type (3, rs,
12693 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12694 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12695 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12696 }
12697 else
428e3f1f
PB
12698 {
12699 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12700 affected if we specify unsigned args. */
12701 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12702 }
5287ad62
JB
12703}
12704
12705static void
12706do_neon_tst (void)
12707{
037e8744 12708 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12709 struct neon_type_el et = neon_check_type (3, rs,
12710 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12711 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12712}
12713
12714/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12715 same types as the MAC equivalents. The polynomial type for this instruction
12716 is encoded the same as the integer type. */
12717
12718static void
12719do_neon_mul (void)
12720{
037e8744
JB
12721 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12722 return;
12723
12724 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12725 return;
12726
5287ad62
JB
12727 if (inst.operands[2].isscalar)
12728 do_neon_mac_maybe_scalar ();
12729 else
dcbf9037 12730 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12731}
12732
12733static void
12734do_neon_qdmulh (void)
12735{
12736 if (inst.operands[2].isscalar)
12737 {
037e8744 12738 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12739 struct neon_type_el et = neon_check_type (3, rs,
12740 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12741 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12742 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12743 }
12744 else
12745 {
037e8744 12746 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12747 struct neon_type_el et = neon_check_type (3, rs,
12748 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12749 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12750 /* The U bit (rounding) comes from bit mask. */
037e8744 12751 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12752 }
12753}
12754
12755static void
12756do_neon_fcmp_absolute (void)
12757{
037e8744 12758 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12759 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12760 /* Size field comes from bit mask. */
037e8744 12761 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12762}
12763
12764static void
12765do_neon_fcmp_absolute_inv (void)
12766{
12767 neon_exchange_operands ();
12768 do_neon_fcmp_absolute ();
12769}
12770
12771static void
12772do_neon_step (void)
12773{
037e8744 12774 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12775 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12776 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12777}
12778
12779static void
12780do_neon_abs_neg (void)
12781{
037e8744
JB
12782 enum neon_shape rs;
12783 struct neon_type_el et;
5f4273c7 12784
037e8744
JB
12785 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12786 return;
12787
12788 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12789 return;
12790
12791 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12792 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12793
5287ad62
JB
12794 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12795 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12796 inst.instruction |= LOW4 (inst.operands[1].reg);
12797 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12798 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12799 inst.instruction |= (et.type == NT_float) << 10;
12800 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12801
5287ad62
JB
12802 inst.instruction = neon_dp_fixup (inst.instruction);
12803}
12804
12805static void
12806do_neon_sli (void)
12807{
037e8744 12808 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12809 struct neon_type_el et = neon_check_type (2, rs,
12810 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12811 int imm = inst.operands[2].imm;
12812 constraint (imm < 0 || (unsigned)imm >= et.size,
12813 _("immediate out of range for insert"));
037e8744 12814 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12815}
12816
12817static void
12818do_neon_sri (void)
12819{
037e8744 12820 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12821 struct neon_type_el et = neon_check_type (2, rs,
12822 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12823 int imm = inst.operands[2].imm;
12824 constraint (imm < 1 || (unsigned)imm > et.size,
12825 _("immediate out of range for insert"));
037e8744 12826 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12827}
12828
12829static void
12830do_neon_qshlu_imm (void)
12831{
037e8744 12832 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12833 struct neon_type_el et = neon_check_type (2, rs,
12834 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12835 int imm = inst.operands[2].imm;
12836 constraint (imm < 0 || (unsigned)imm >= et.size,
12837 _("immediate out of range for shift"));
12838 /* Only encodes the 'U present' variant of the instruction.
12839 In this case, signed types have OP (bit 8) set to 0.
12840 Unsigned types have OP set to 1. */
12841 inst.instruction |= (et.type == NT_unsigned) << 8;
12842 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12843 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12844}
12845
12846static void
12847do_neon_qmovn (void)
12848{
12849 struct neon_type_el et = neon_check_type (2, NS_DQ,
12850 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12851 /* Saturating move where operands can be signed or unsigned, and the
12852 destination has the same signedness. */
12853 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12854 if (et.type == NT_unsigned)
12855 inst.instruction |= 0xc0;
12856 else
12857 inst.instruction |= 0x80;
12858 neon_two_same (0, 1, et.size / 2);
12859}
12860
12861static void
12862do_neon_qmovun (void)
12863{
12864 struct neon_type_el et = neon_check_type (2, NS_DQ,
12865 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12866 /* Saturating move with unsigned results. Operands must be signed. */
12867 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12868 neon_two_same (0, 1, et.size / 2);
12869}
12870
12871static void
12872do_neon_rshift_sat_narrow (void)
12873{
12874 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12875 or unsigned. If operands are unsigned, results must also be unsigned. */
12876 struct neon_type_el et = neon_check_type (2, NS_DQI,
12877 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12878 int imm = inst.operands[2].imm;
12879 /* This gets the bounds check, size encoding and immediate bits calculation
12880 right. */
12881 et.size /= 2;
5f4273c7 12882
5287ad62
JB
12883 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12884 VQMOVN.I<size> <Dd>, <Qm>. */
12885 if (imm == 0)
12886 {
12887 inst.operands[2].present = 0;
12888 inst.instruction = N_MNEM_vqmovn;
12889 do_neon_qmovn ();
12890 return;
12891 }
5f4273c7 12892
5287ad62
JB
12893 constraint (imm < 1 || (unsigned)imm > et.size,
12894 _("immediate out of range"));
12895 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12896}
12897
12898static void
12899do_neon_rshift_sat_narrow_u (void)
12900{
12901 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12902 or unsigned. If operands are unsigned, results must also be unsigned. */
12903 struct neon_type_el et = neon_check_type (2, NS_DQI,
12904 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12905 int imm = inst.operands[2].imm;
12906 /* This gets the bounds check, size encoding and immediate bits calculation
12907 right. */
12908 et.size /= 2;
12909
12910 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12911 VQMOVUN.I<size> <Dd>, <Qm>. */
12912 if (imm == 0)
12913 {
12914 inst.operands[2].present = 0;
12915 inst.instruction = N_MNEM_vqmovun;
12916 do_neon_qmovun ();
12917 return;
12918 }
12919
12920 constraint (imm < 1 || (unsigned)imm > et.size,
12921 _("immediate out of range"));
12922 /* FIXME: The manual is kind of unclear about what value U should have in
12923 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12924 must be 1. */
12925 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12926}
12927
12928static void
12929do_neon_movn (void)
12930{
12931 struct neon_type_el et = neon_check_type (2, NS_DQ,
12932 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12933 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12934 neon_two_same (0, 1, et.size / 2);
12935}
12936
12937static void
12938do_neon_rshift_narrow (void)
12939{
12940 struct neon_type_el et = neon_check_type (2, NS_DQI,
12941 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12942 int imm = inst.operands[2].imm;
12943 /* This gets the bounds check, size encoding and immediate bits calculation
12944 right. */
12945 et.size /= 2;
5f4273c7 12946
5287ad62
JB
12947 /* If immediate is zero then we are a pseudo-instruction for
12948 VMOVN.I<size> <Dd>, <Qm> */
12949 if (imm == 0)
12950 {
12951 inst.operands[2].present = 0;
12952 inst.instruction = N_MNEM_vmovn;
12953 do_neon_movn ();
12954 return;
12955 }
5f4273c7 12956
5287ad62
JB
12957 constraint (imm < 1 || (unsigned)imm > et.size,
12958 _("immediate out of range for narrowing operation"));
12959 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12960}
12961
12962static void
12963do_neon_shll (void)
12964{
12965 /* FIXME: Type checking when lengthening. */
12966 struct neon_type_el et = neon_check_type (2, NS_QDI,
12967 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12968 unsigned imm = inst.operands[2].imm;
12969
12970 if (imm == et.size)
12971 {
12972 /* Maximum shift variant. */
12973 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12974 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12975 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12976 inst.instruction |= LOW4 (inst.operands[1].reg);
12977 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12978 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12979
5287ad62
JB
12980 inst.instruction = neon_dp_fixup (inst.instruction);
12981 }
12982 else
12983 {
12984 /* A more-specific type check for non-max versions. */
12985 et = neon_check_type (2, NS_QDI,
12986 N_EQK | N_DBL, N_SU_32 | N_KEY);
12987 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12988 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12989 }
12990}
12991
037e8744 12992/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12993 the current instruction is. */
12994
12995static int
12996neon_cvt_flavour (enum neon_shape rs)
12997{
037e8744
JB
12998#define CVT_VAR(C,X,Y) \
12999 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13000 if (et.type != NT_invtype) \
13001 { \
13002 inst.error = NULL; \
13003 return (C); \
5287ad62
JB
13004 }
13005 struct neon_type_el et;
037e8744
JB
13006 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13007 || rs == NS_FF) ? N_VFP : 0;
13008 /* The instruction versions which take an immediate take one register
13009 argument, which is extended to the width of the full register. Thus the
13010 "source" and "destination" registers must have the same width. Hack that
13011 here by making the size equal to the key (wider, in this case) operand. */
13012 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13013
5287ad62
JB
13014 CVT_VAR (0, N_S32, N_F32);
13015 CVT_VAR (1, N_U32, N_F32);
13016 CVT_VAR (2, N_F32, N_S32);
13017 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13018 /* Half-precision conversions. */
13019 CVT_VAR (4, N_F32, N_F16);
13020 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13021
037e8744 13022 whole_reg = N_VFP;
5f4273c7 13023
037e8744 13024 /* VFP instructions. */
8e79c3df
CM
13025 CVT_VAR (6, N_F32, N_F64);
13026 CVT_VAR (7, N_F64, N_F32);
13027 CVT_VAR (8, N_S32, N_F64 | key);
13028 CVT_VAR (9, N_U32, N_F64 | key);
13029 CVT_VAR (10, N_F64 | key, N_S32);
13030 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13031 /* VFP instructions with bitshift. */
8e79c3df
CM
13032 CVT_VAR (12, N_F32 | key, N_S16);
13033 CVT_VAR (13, N_F32 | key, N_U16);
13034 CVT_VAR (14, N_F64 | key, N_S16);
13035 CVT_VAR (15, N_F64 | key, N_U16);
13036 CVT_VAR (16, N_S16, N_F32 | key);
13037 CVT_VAR (17, N_U16, N_F32 | key);
13038 CVT_VAR (18, N_S16, N_F64 | key);
13039 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13040
5287ad62
JB
13041 return -1;
13042#undef CVT_VAR
13043}
13044
037e8744
JB
13045/* Neon-syntax VFP conversions. */
13046
5287ad62 13047static void
037e8744 13048do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13049{
037e8744 13050 const char *opname = 0;
5f4273c7 13051
037e8744 13052 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13053 {
037e8744
JB
13054 /* Conversions with immediate bitshift. */
13055 const char *enc[] =
13056 {
13057 "ftosls",
13058 "ftouls",
13059 "fsltos",
13060 "fultos",
13061 NULL,
13062 NULL,
8e79c3df
CM
13063 NULL,
13064 NULL,
037e8744
JB
13065 "ftosld",
13066 "ftould",
13067 "fsltod",
13068 "fultod",
13069 "fshtos",
13070 "fuhtos",
13071 "fshtod",
13072 "fuhtod",
13073 "ftoshs",
13074 "ftouhs",
13075 "ftoshd",
13076 "ftouhd"
13077 };
13078
13079 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13080 {
13081 opname = enc[flavour];
13082 constraint (inst.operands[0].reg != inst.operands[1].reg,
13083 _("operands 0 and 1 must be the same register"));
13084 inst.operands[1] = inst.operands[2];
13085 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13086 }
5287ad62
JB
13087 }
13088 else
13089 {
037e8744
JB
13090 /* Conversions without bitshift. */
13091 const char *enc[] =
13092 {
13093 "ftosis",
13094 "ftouis",
13095 "fsitos",
13096 "fuitos",
8e79c3df
CM
13097 "NULL",
13098 "NULL",
037e8744
JB
13099 "fcvtsd",
13100 "fcvtds",
13101 "ftosid",
13102 "ftouid",
13103 "fsitod",
13104 "fuitod"
13105 };
13106
13107 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13108 opname = enc[flavour];
13109 }
13110
13111 if (opname)
13112 do_vfp_nsyn_opcode (opname);
13113}
13114
13115static void
13116do_vfp_nsyn_cvtz (void)
13117{
13118 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13119 int flavour = neon_cvt_flavour (rs);
13120 const char *enc[] =
13121 {
13122 "ftosizs",
13123 "ftouizs",
13124 NULL,
13125 NULL,
13126 NULL,
13127 NULL,
8e79c3df
CM
13128 NULL,
13129 NULL,
037e8744
JB
13130 "ftosizd",
13131 "ftouizd"
13132 };
13133
13134 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13135 do_vfp_nsyn_opcode (enc[flavour]);
13136}
f31fef98 13137
037e8744
JB
13138static void
13139do_neon_cvt (void)
13140{
13141 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13142 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13143 int flavour = neon_cvt_flavour (rs);
13144
13145 /* VFP rather than Neon conversions. */
8e79c3df 13146 if (flavour >= 6)
037e8744
JB
13147 {
13148 do_vfp_nsyn_cvt (rs, flavour);
13149 return;
13150 }
13151
13152 switch (rs)
13153 {
13154 case NS_DDI:
13155 case NS_QQI:
13156 {
35997600
NC
13157 unsigned immbits;
13158 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13159
037e8744
JB
13160 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13161 return;
13162
13163 /* Fixed-point conversion with #0 immediate is encoded as an
13164 integer conversion. */
13165 if (inst.operands[2].present && inst.operands[2].imm == 0)
13166 goto int_encode;
35997600 13167 immbits = 32 - inst.operands[2].imm;
037e8744
JB
13168 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13169 if (flavour != -1)
13170 inst.instruction |= enctab[flavour];
13171 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13172 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13173 inst.instruction |= LOW4 (inst.operands[1].reg);
13174 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13175 inst.instruction |= neon_quad (rs) << 6;
13176 inst.instruction |= 1 << 21;
13177 inst.instruction |= immbits << 16;
13178
13179 inst.instruction = neon_dp_fixup (inst.instruction);
13180 }
13181 break;
13182
13183 case NS_DD:
13184 case NS_QQ:
13185 int_encode:
13186 {
13187 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13188
13189 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13190
13191 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13192 return;
13193
13194 if (flavour != -1)
13195 inst.instruction |= enctab[flavour];
13196
13197 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13198 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13199 inst.instruction |= LOW4 (inst.operands[1].reg);
13200 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13201 inst.instruction |= neon_quad (rs) << 6;
13202 inst.instruction |= 2 << 18;
13203
13204 inst.instruction = neon_dp_fixup (inst.instruction);
13205 }
13206 break;
13207
8e79c3df
CM
13208 /* Half-precision conversions for Advanced SIMD -- neon. */
13209 case NS_QD:
13210 case NS_DQ:
13211
13212 if ((rs == NS_DQ)
13213 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13214 {
13215 as_bad (_("operand size must match register width"));
13216 break;
13217 }
13218
13219 if ((rs == NS_QD)
13220 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13221 {
13222 as_bad (_("operand size must match register width"));
13223 break;
13224 }
13225
13226 if (rs == NS_DQ)
13227 inst.instruction = 0x3b60600;
13228 else
13229 inst.instruction = 0x3b60700;
13230
13231 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13232 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13233 inst.instruction |= LOW4 (inst.operands[1].reg);
13234 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13235 inst.instruction = neon_dp_fixup (inst.instruction);
13236 break;
13237
037e8744
JB
13238 default:
13239 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13240 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13241 }
5287ad62
JB
13242}
13243
8e79c3df
CM
13244static void
13245do_neon_cvtb (void)
13246{
13247 inst.instruction = 0xeb20a40;
13248
13249 /* The sizes are attached to the mnemonic. */
13250 if (inst.vectype.el[0].type != NT_invtype
13251 && inst.vectype.el[0].size == 16)
13252 inst.instruction |= 0x00010000;
13253
13254 /* Programmer's syntax: the sizes are attached to the operands. */
13255 else if (inst.operands[0].vectype.type != NT_invtype
13256 && inst.operands[0].vectype.size == 16)
13257 inst.instruction |= 0x00010000;
13258
13259 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13260 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13261 do_vfp_cond_or_thumb ();
13262}
13263
13264
13265static void
13266do_neon_cvtt (void)
13267{
13268 do_neon_cvtb ();
13269 inst.instruction |= 0x80;
13270}
13271
5287ad62
JB
13272static void
13273neon_move_immediate (void)
13274{
037e8744
JB
13275 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13276 struct neon_type_el et = neon_check_type (2, rs,
13277 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13278 unsigned immlo, immhi = 0, immbits;
c96612cc 13279 int op, cmode, float_p;
5287ad62 13280
037e8744
JB
13281 constraint (et.type == NT_invtype,
13282 _("operand size must be specified for immediate VMOV"));
13283
5287ad62
JB
13284 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13285 op = (inst.instruction & (1 << 5)) != 0;
13286
13287 immlo = inst.operands[1].imm;
13288 if (inst.operands[1].regisimm)
13289 immhi = inst.operands[1].reg;
13290
13291 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13292 _("immediate has bits set outside the operand size"));
13293
c96612cc
JB
13294 float_p = inst.operands[1].immisfloat;
13295
13296 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13297 et.size, et.type)) == FAIL)
5287ad62
JB
13298 {
13299 /* Invert relevant bits only. */
13300 neon_invert_size (&immlo, &immhi, et.size);
13301 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13302 with one or the other; those cases are caught by
13303 neon_cmode_for_move_imm. */
13304 op = !op;
c96612cc
JB
13305 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13306 &op, et.size, et.type)) == FAIL)
5287ad62 13307 {
dcbf9037 13308 first_error (_("immediate out of range"));
5287ad62
JB
13309 return;
13310 }
13311 }
13312
13313 inst.instruction &= ~(1 << 5);
13314 inst.instruction |= op << 5;
13315
13316 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13317 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13318 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13319 inst.instruction |= cmode << 8;
13320
13321 neon_write_immbits (immbits);
13322}
13323
13324static void
13325do_neon_mvn (void)
13326{
13327 if (inst.operands[1].isreg)
13328 {
037e8744 13329 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13330
5287ad62
JB
13331 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13332 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13333 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13334 inst.instruction |= LOW4 (inst.operands[1].reg);
13335 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13336 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13337 }
13338 else
13339 {
13340 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13341 neon_move_immediate ();
13342 }
13343
13344 inst.instruction = neon_dp_fixup (inst.instruction);
13345}
13346
13347/* Encode instructions of form:
13348
13349 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13350 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13351
13352static void
13353neon_mixed_length (struct neon_type_el et, unsigned size)
13354{
13355 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13356 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13357 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13358 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13359 inst.instruction |= LOW4 (inst.operands[2].reg);
13360 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13361 inst.instruction |= (et.type == NT_unsigned) << 24;
13362 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13363
5287ad62
JB
13364 inst.instruction = neon_dp_fixup (inst.instruction);
13365}
13366
13367static void
13368do_neon_dyadic_long (void)
13369{
13370 /* FIXME: Type checking for lengthening op. */
13371 struct neon_type_el et = neon_check_type (3, NS_QDD,
13372 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13373 neon_mixed_length (et, et.size);
13374}
13375
13376static void
13377do_neon_abal (void)
13378{
13379 struct neon_type_el et = neon_check_type (3, NS_QDD,
13380 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13381 neon_mixed_length (et, et.size);
13382}
13383
13384static void
13385neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13386{
13387 if (inst.operands[2].isscalar)
13388 {
dcbf9037
JB
13389 struct neon_type_el et = neon_check_type (3, NS_QDS,
13390 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13391 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13392 neon_mul_mac (et, et.type == NT_unsigned);
13393 }
13394 else
13395 {
13396 struct neon_type_el et = neon_check_type (3, NS_QDD,
13397 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13398 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13399 neon_mixed_length (et, et.size);
13400 }
13401}
13402
13403static void
13404do_neon_mac_maybe_scalar_long (void)
13405{
13406 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13407}
13408
13409static void
13410do_neon_dyadic_wide (void)
13411{
13412 struct neon_type_el et = neon_check_type (3, NS_QQD,
13413 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13414 neon_mixed_length (et, et.size);
13415}
13416
13417static void
13418do_neon_dyadic_narrow (void)
13419{
13420 struct neon_type_el et = neon_check_type (3, NS_QDD,
13421 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13422 /* Operand sign is unimportant, and the U bit is part of the opcode,
13423 so force the operand type to integer. */
13424 et.type = NT_integer;
5287ad62
JB
13425 neon_mixed_length (et, et.size / 2);
13426}
13427
13428static void
13429do_neon_mul_sat_scalar_long (void)
13430{
13431 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13432}
13433
13434static void
13435do_neon_vmull (void)
13436{
13437 if (inst.operands[2].isscalar)
13438 do_neon_mac_maybe_scalar_long ();
13439 else
13440 {
13441 struct neon_type_el et = neon_check_type (3, NS_QDD,
13442 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13443 if (et.type == NT_poly)
13444 inst.instruction = NEON_ENC_POLY (inst.instruction);
13445 else
13446 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13447 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13448 zero. Should be OK as-is. */
13449 neon_mixed_length (et, et.size);
13450 }
13451}
13452
13453static void
13454do_neon_ext (void)
13455{
037e8744 13456 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13457 struct neon_type_el et = neon_check_type (3, rs,
13458 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13459 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13460
13461 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13462 _("shift out of range"));
5287ad62
JB
13463 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13464 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13465 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13466 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13467 inst.instruction |= LOW4 (inst.operands[2].reg);
13468 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13469 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13470 inst.instruction |= imm << 8;
5f4273c7 13471
5287ad62
JB
13472 inst.instruction = neon_dp_fixup (inst.instruction);
13473}
13474
13475static void
13476do_neon_rev (void)
13477{
037e8744 13478 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13479 struct neon_type_el et = neon_check_type (2, rs,
13480 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13481 unsigned op = (inst.instruction >> 7) & 3;
13482 /* N (width of reversed regions) is encoded as part of the bitmask. We
13483 extract it here to check the elements to be reversed are smaller.
13484 Otherwise we'd get a reserved instruction. */
13485 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13486 assert (elsize != 0);
13487 constraint (et.size >= elsize,
13488 _("elements must be smaller than reversal region"));
037e8744 13489 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13490}
13491
13492static void
13493do_neon_dup (void)
13494{
13495 if (inst.operands[1].isscalar)
13496 {
037e8744 13497 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13498 struct neon_type_el et = neon_check_type (2, rs,
13499 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13500 unsigned sizebits = et.size >> 3;
dcbf9037 13501 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13502 int logsize = neon_logbits (et.size);
dcbf9037 13503 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13504
13505 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13506 return;
13507
5287ad62
JB
13508 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13509 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13510 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13511 inst.instruction |= LOW4 (dm);
13512 inst.instruction |= HI1 (dm) << 5;
037e8744 13513 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13514 inst.instruction |= x << 17;
13515 inst.instruction |= sizebits << 16;
5f4273c7 13516
5287ad62
JB
13517 inst.instruction = neon_dp_fixup (inst.instruction);
13518 }
13519 else
13520 {
037e8744
JB
13521 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13522 struct neon_type_el et = neon_check_type (2, rs,
13523 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13524 /* Duplicate ARM register to lanes of vector. */
13525 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13526 switch (et.size)
13527 {
13528 case 8: inst.instruction |= 0x400000; break;
13529 case 16: inst.instruction |= 0x000020; break;
13530 case 32: inst.instruction |= 0x000000; break;
13531 default: break;
13532 }
13533 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13534 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13535 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13536 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13537 /* The encoding for this instruction is identical for the ARM and Thumb
13538 variants, except for the condition field. */
037e8744 13539 do_vfp_cond_or_thumb ();
5287ad62
JB
13540 }
13541}
13542
13543/* VMOV has particularly many variations. It can be one of:
13544 0. VMOV<c><q> <Qd>, <Qm>
13545 1. VMOV<c><q> <Dd>, <Dm>
13546 (Register operations, which are VORR with Rm = Rn.)
13547 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13548 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13549 (Immediate loads.)
13550 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13551 (ARM register to scalar.)
13552 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13553 (Two ARM registers to vector.)
13554 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13555 (Scalar to ARM register.)
13556 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13557 (Vector to two ARM registers.)
037e8744
JB
13558 8. VMOV.F32 <Sd>, <Sm>
13559 9. VMOV.F64 <Dd>, <Dm>
13560 (VFP register moves.)
13561 10. VMOV.F32 <Sd>, #imm
13562 11. VMOV.F64 <Dd>, #imm
13563 (VFP float immediate load.)
13564 12. VMOV <Rd>, <Sm>
13565 (VFP single to ARM reg.)
13566 13. VMOV <Sd>, <Rm>
13567 (ARM reg to VFP single.)
13568 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13569 (Two ARM regs to two VFP singles.)
13570 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13571 (Two VFP singles to two ARM regs.)
5f4273c7 13572
037e8744
JB
13573 These cases can be disambiguated using neon_select_shape, except cases 1/9
13574 and 3/11 which depend on the operand type too.
5f4273c7 13575
5287ad62 13576 All the encoded bits are hardcoded by this function.
5f4273c7 13577
b7fc2769
JB
13578 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13579 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13580
5287ad62 13581 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13582 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13583
13584static void
13585do_neon_mov (void)
13586{
037e8744
JB
13587 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13588 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13589 NS_NULL);
13590 struct neon_type_el et;
13591 const char *ldconst = 0;
5287ad62 13592
037e8744 13593 switch (rs)
5287ad62 13594 {
037e8744
JB
13595 case NS_DD: /* case 1/9. */
13596 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13597 /* It is not an error here if no type is given. */
13598 inst.error = NULL;
13599 if (et.type == NT_float && et.size == 64)
5287ad62 13600 {
037e8744
JB
13601 do_vfp_nsyn_opcode ("fcpyd");
13602 break;
5287ad62 13603 }
037e8744 13604 /* fall through. */
5287ad62 13605
037e8744
JB
13606 case NS_QQ: /* case 0/1. */
13607 {
13608 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13609 return;
13610 /* The architecture manual I have doesn't explicitly state which
13611 value the U bit should have for register->register moves, but
13612 the equivalent VORR instruction has U = 0, so do that. */
13613 inst.instruction = 0x0200110;
13614 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13615 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13616 inst.instruction |= LOW4 (inst.operands[1].reg);
13617 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13618 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13619 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13620 inst.instruction |= neon_quad (rs) << 6;
13621
13622 inst.instruction = neon_dp_fixup (inst.instruction);
13623 }
13624 break;
5f4273c7 13625
037e8744
JB
13626 case NS_DI: /* case 3/11. */
13627 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13628 inst.error = NULL;
13629 if (et.type == NT_float && et.size == 64)
5287ad62 13630 {
037e8744
JB
13631 /* case 11 (fconstd). */
13632 ldconst = "fconstd";
13633 goto encode_fconstd;
5287ad62 13634 }
037e8744
JB
13635 /* fall through. */
13636
13637 case NS_QI: /* case 2/3. */
13638 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13639 return;
13640 inst.instruction = 0x0800010;
13641 neon_move_immediate ();
13642 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13643 break;
5f4273c7 13644
037e8744
JB
13645 case NS_SR: /* case 4. */
13646 {
13647 unsigned bcdebits = 0;
13648 struct neon_type_el et = neon_check_type (2, NS_NULL,
13649 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13650 int logsize = neon_logbits (et.size);
13651 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13652 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13653
13654 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13655 _(BAD_FPU));
13656 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13657 && et.size != 32, _(BAD_FPU));
13658 constraint (et.type == NT_invtype, _("bad type for scalar"));
13659 constraint (x >= 64 / et.size, _("scalar index out of range"));
13660
13661 switch (et.size)
13662 {
13663 case 8: bcdebits = 0x8; break;
13664 case 16: bcdebits = 0x1; break;
13665 case 32: bcdebits = 0x0; break;
13666 default: ;
13667 }
13668
13669 bcdebits |= x << logsize;
13670
13671 inst.instruction = 0xe000b10;
13672 do_vfp_cond_or_thumb ();
13673 inst.instruction |= LOW4 (dn) << 16;
13674 inst.instruction |= HI1 (dn) << 7;
13675 inst.instruction |= inst.operands[1].reg << 12;
13676 inst.instruction |= (bcdebits & 3) << 5;
13677 inst.instruction |= (bcdebits >> 2) << 21;
13678 }
13679 break;
5f4273c7 13680
037e8744 13681 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13682 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13683 _(BAD_FPU));
b7fc2769 13684
037e8744
JB
13685 inst.instruction = 0xc400b10;
13686 do_vfp_cond_or_thumb ();
13687 inst.instruction |= LOW4 (inst.operands[0].reg);
13688 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13689 inst.instruction |= inst.operands[1].reg << 12;
13690 inst.instruction |= inst.operands[2].reg << 16;
13691 break;
5f4273c7 13692
037e8744
JB
13693 case NS_RS: /* case 6. */
13694 {
13695 struct neon_type_el et = neon_check_type (2, NS_NULL,
13696 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13697 unsigned logsize = neon_logbits (et.size);
13698 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13699 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13700 unsigned abcdebits = 0;
13701
13702 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13703 _(BAD_FPU));
13704 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13705 && et.size != 32, _(BAD_FPU));
13706 constraint (et.type == NT_invtype, _("bad type for scalar"));
13707 constraint (x >= 64 / et.size, _("scalar index out of range"));
13708
13709 switch (et.size)
13710 {
13711 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13712 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13713 case 32: abcdebits = 0x00; break;
13714 default: ;
13715 }
13716
13717 abcdebits |= x << logsize;
13718 inst.instruction = 0xe100b10;
13719 do_vfp_cond_or_thumb ();
13720 inst.instruction |= LOW4 (dn) << 16;
13721 inst.instruction |= HI1 (dn) << 7;
13722 inst.instruction |= inst.operands[0].reg << 12;
13723 inst.instruction |= (abcdebits & 3) << 5;
13724 inst.instruction |= (abcdebits >> 2) << 21;
13725 }
13726 break;
5f4273c7 13727
037e8744
JB
13728 case NS_RRD: /* case 7 (fmrrd). */
13729 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13730 _(BAD_FPU));
13731
13732 inst.instruction = 0xc500b10;
13733 do_vfp_cond_or_thumb ();
13734 inst.instruction |= inst.operands[0].reg << 12;
13735 inst.instruction |= inst.operands[1].reg << 16;
13736 inst.instruction |= LOW4 (inst.operands[2].reg);
13737 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13738 break;
5f4273c7 13739
037e8744
JB
13740 case NS_FF: /* case 8 (fcpys). */
13741 do_vfp_nsyn_opcode ("fcpys");
13742 break;
5f4273c7 13743
037e8744
JB
13744 case NS_FI: /* case 10 (fconsts). */
13745 ldconst = "fconsts";
13746 encode_fconstd:
13747 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13748 {
037e8744
JB
13749 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13750 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13751 }
13752 else
037e8744
JB
13753 first_error (_("immediate out of range"));
13754 break;
5f4273c7 13755
037e8744
JB
13756 case NS_RF: /* case 12 (fmrs). */
13757 do_vfp_nsyn_opcode ("fmrs");
13758 break;
5f4273c7 13759
037e8744
JB
13760 case NS_FR: /* case 13 (fmsr). */
13761 do_vfp_nsyn_opcode ("fmsr");
13762 break;
5f4273c7 13763
037e8744
JB
13764 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13765 (one of which is a list), but we have parsed four. Do some fiddling to
13766 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13767 expect. */
13768 case NS_RRFF: /* case 14 (fmrrs). */
13769 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13770 _("VFP registers must be adjacent"));
13771 inst.operands[2].imm = 2;
13772 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13773 do_vfp_nsyn_opcode ("fmrrs");
13774 break;
5f4273c7 13775
037e8744
JB
13776 case NS_FFRR: /* case 15 (fmsrr). */
13777 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13778 _("VFP registers must be adjacent"));
13779 inst.operands[1] = inst.operands[2];
13780 inst.operands[2] = inst.operands[3];
13781 inst.operands[0].imm = 2;
13782 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13783 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13784 break;
5f4273c7 13785
5287ad62
JB
13786 default:
13787 abort ();
13788 }
13789}
13790
13791static void
13792do_neon_rshift_round_imm (void)
13793{
037e8744 13794 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13795 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13796 int imm = inst.operands[2].imm;
13797
13798 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13799 if (imm == 0)
13800 {
13801 inst.operands[2].present = 0;
13802 do_neon_mov ();
13803 return;
13804 }
13805
13806 constraint (imm < 1 || (unsigned)imm > et.size,
13807 _("immediate out of range for shift"));
037e8744 13808 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13809 et.size - imm);
13810}
13811
13812static void
13813do_neon_movl (void)
13814{
13815 struct neon_type_el et = neon_check_type (2, NS_QD,
13816 N_EQK | N_DBL, N_SU_32 | N_KEY);
13817 unsigned sizebits = et.size >> 3;
13818 inst.instruction |= sizebits << 19;
13819 neon_two_same (0, et.type == NT_unsigned, -1);
13820}
13821
13822static void
13823do_neon_trn (void)
13824{
037e8744 13825 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13826 struct neon_type_el et = neon_check_type (2, rs,
13827 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13828 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13829 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13830}
13831
13832static void
13833do_neon_zip_uzp (void)
13834{
037e8744 13835 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13836 struct neon_type_el et = neon_check_type (2, rs,
13837 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13838 if (rs == NS_DD && et.size == 32)
13839 {
13840 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13841 inst.instruction = N_MNEM_vtrn;
13842 do_neon_trn ();
13843 return;
13844 }
037e8744 13845 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13846}
13847
13848static void
13849do_neon_sat_abs_neg (void)
13850{
037e8744 13851 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13852 struct neon_type_el et = neon_check_type (2, rs,
13853 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13854 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13855}
13856
13857static void
13858do_neon_pair_long (void)
13859{
037e8744 13860 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13861 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13862 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13863 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13864 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13865}
13866
13867static void
13868do_neon_recip_est (void)
13869{
037e8744 13870 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13871 struct neon_type_el et = neon_check_type (2, rs,
13872 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13873 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13874 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13875}
13876
13877static void
13878do_neon_cls (void)
13879{
037e8744 13880 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13881 struct neon_type_el et = neon_check_type (2, rs,
13882 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13883 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13884}
13885
13886static void
13887do_neon_clz (void)
13888{
037e8744 13889 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13890 struct neon_type_el et = neon_check_type (2, rs,
13891 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13892 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13893}
13894
13895static void
13896do_neon_cnt (void)
13897{
037e8744 13898 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13899 struct neon_type_el et = neon_check_type (2, rs,
13900 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13901 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13902}
13903
13904static void
13905do_neon_swp (void)
13906{
037e8744
JB
13907 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13908 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13909}
13910
13911static void
13912do_neon_tbl_tbx (void)
13913{
13914 unsigned listlenbits;
dcbf9037 13915 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 13916
5287ad62
JB
13917 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13918 {
dcbf9037 13919 first_error (_("bad list length for table lookup"));
5287ad62
JB
13920 return;
13921 }
5f4273c7 13922
5287ad62
JB
13923 listlenbits = inst.operands[1].imm - 1;
13924 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13925 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13926 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13927 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13928 inst.instruction |= LOW4 (inst.operands[2].reg);
13929 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13930 inst.instruction |= listlenbits << 8;
5f4273c7 13931
5287ad62
JB
13932 inst.instruction = neon_dp_fixup (inst.instruction);
13933}
13934
13935static void
13936do_neon_ldm_stm (void)
13937{
13938 /* P, U and L bits are part of bitmask. */
13939 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13940 unsigned offsetbits = inst.operands[1].imm * 2;
13941
037e8744
JB
13942 if (inst.operands[1].issingle)
13943 {
13944 do_vfp_nsyn_ldm_stm (is_dbmode);
13945 return;
13946 }
13947
5287ad62
JB
13948 constraint (is_dbmode && !inst.operands[0].writeback,
13949 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13950
13951 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13952 _("register list must contain at least 1 and at most 16 "
13953 "registers"));
13954
13955 inst.instruction |= inst.operands[0].reg << 16;
13956 inst.instruction |= inst.operands[0].writeback << 21;
13957 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13958 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13959
13960 inst.instruction |= offsetbits;
5f4273c7 13961
037e8744 13962 do_vfp_cond_or_thumb ();
5287ad62
JB
13963}
13964
13965static void
13966do_neon_ldr_str (void)
13967{
5287ad62 13968 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 13969
037e8744
JB
13970 if (inst.operands[0].issingle)
13971 {
cd2f129f
JB
13972 if (is_ldr)
13973 do_vfp_nsyn_opcode ("flds");
13974 else
13975 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13976 }
13977 else
5287ad62 13978 {
cd2f129f
JB
13979 if (is_ldr)
13980 do_vfp_nsyn_opcode ("fldd");
5287ad62 13981 else
cd2f129f 13982 do_vfp_nsyn_opcode ("fstd");
5287ad62 13983 }
5287ad62
JB
13984}
13985
13986/* "interleave" version also handles non-interleaving register VLD1/VST1
13987 instructions. */
13988
13989static void
13990do_neon_ld_st_interleave (void)
13991{
037e8744 13992 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13993 N_8 | N_16 | N_32 | N_64);
13994 unsigned alignbits = 0;
13995 unsigned idx;
13996 /* The bits in this table go:
13997 0: register stride of one (0) or two (1)
13998 1,2: register list length, minus one (1, 2, 3, 4).
13999 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14000 We use -1 for invalid entries. */
14001 const int typetable[] =
14002 {
14003 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14004 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14005 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14006 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14007 };
14008 int typebits;
14009
dcbf9037
JB
14010 if (et.type == NT_invtype)
14011 return;
14012
5287ad62
JB
14013 if (inst.operands[1].immisalign)
14014 switch (inst.operands[1].imm >> 8)
14015 {
14016 case 64: alignbits = 1; break;
14017 case 128:
14018 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14019 goto bad_alignment;
14020 alignbits = 2;
14021 break;
14022 case 256:
14023 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14024 goto bad_alignment;
14025 alignbits = 3;
14026 break;
14027 default:
14028 bad_alignment:
dcbf9037 14029 first_error (_("bad alignment"));
5287ad62
JB
14030 return;
14031 }
14032
14033 inst.instruction |= alignbits << 4;
14034 inst.instruction |= neon_logbits (et.size) << 6;
14035
14036 /* Bits [4:6] of the immediate in a list specifier encode register stride
14037 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14038 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14039 up the right value for "type" in a table based on this value and the given
14040 list style, then stick it back. */
14041 idx = ((inst.operands[0].imm >> 4) & 7)
14042 | (((inst.instruction >> 8) & 3) << 3);
14043
14044 typebits = typetable[idx];
5f4273c7 14045
5287ad62
JB
14046 constraint (typebits == -1, _("bad list type for instruction"));
14047
14048 inst.instruction &= ~0xf00;
14049 inst.instruction |= typebits << 8;
14050}
14051
14052/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14053 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14054 otherwise. The variable arguments are a list of pairs of legal (size, align)
14055 values, terminated with -1. */
14056
14057static int
14058neon_alignment_bit (int size, int align, int *do_align, ...)
14059{
14060 va_list ap;
14061 int result = FAIL, thissize, thisalign;
5f4273c7 14062
5287ad62
JB
14063 if (!inst.operands[1].immisalign)
14064 {
14065 *do_align = 0;
14066 return SUCCESS;
14067 }
5f4273c7 14068
5287ad62
JB
14069 va_start (ap, do_align);
14070
14071 do
14072 {
14073 thissize = va_arg (ap, int);
14074 if (thissize == -1)
14075 break;
14076 thisalign = va_arg (ap, int);
14077
14078 if (size == thissize && align == thisalign)
14079 result = SUCCESS;
14080 }
14081 while (result != SUCCESS);
14082
14083 va_end (ap);
14084
14085 if (result == SUCCESS)
14086 *do_align = 1;
14087 else
dcbf9037 14088 first_error (_("unsupported alignment for instruction"));
5f4273c7 14089
5287ad62
JB
14090 return result;
14091}
14092
14093static void
14094do_neon_ld_st_lane (void)
14095{
037e8744 14096 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14097 int align_good, do_align = 0;
14098 int logsize = neon_logbits (et.size);
14099 int align = inst.operands[1].imm >> 8;
14100 int n = (inst.instruction >> 8) & 3;
14101 int max_el = 64 / et.size;
5f4273c7 14102
dcbf9037
JB
14103 if (et.type == NT_invtype)
14104 return;
5f4273c7 14105
5287ad62
JB
14106 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14107 _("bad list length"));
14108 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14109 _("scalar index out of range"));
14110 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14111 && et.size == 8,
14112 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14113
5287ad62
JB
14114 switch (n)
14115 {
14116 case 0: /* VLD1 / VST1. */
14117 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14118 32, 32, -1);
14119 if (align_good == FAIL)
14120 return;
14121 if (do_align)
14122 {
14123 unsigned alignbits = 0;
14124 switch (et.size)
14125 {
14126 case 16: alignbits = 0x1; break;
14127 case 32: alignbits = 0x3; break;
14128 default: ;
14129 }
14130 inst.instruction |= alignbits << 4;
14131 }
14132 break;
14133
14134 case 1: /* VLD2 / VST2. */
14135 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14136 32, 64, -1);
14137 if (align_good == FAIL)
14138 return;
14139 if (do_align)
14140 inst.instruction |= 1 << 4;
14141 break;
14142
14143 case 2: /* VLD3 / VST3. */
14144 constraint (inst.operands[1].immisalign,
14145 _("can't use alignment with this instruction"));
14146 break;
14147
14148 case 3: /* VLD4 / VST4. */
14149 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14150 16, 64, 32, 64, 32, 128, -1);
14151 if (align_good == FAIL)
14152 return;
14153 if (do_align)
14154 {
14155 unsigned alignbits = 0;
14156 switch (et.size)
14157 {
14158 case 8: alignbits = 0x1; break;
14159 case 16: alignbits = 0x1; break;
14160 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14161 default: ;
14162 }
14163 inst.instruction |= alignbits << 4;
14164 }
14165 break;
14166
14167 default: ;
14168 }
14169
14170 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14171 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14172 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14173
5287ad62
JB
14174 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14175 inst.instruction |= logsize << 10;
14176}
14177
14178/* Encode single n-element structure to all lanes VLD<n> instructions. */
14179
14180static void
14181do_neon_ld_dup (void)
14182{
037e8744 14183 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14184 int align_good, do_align = 0;
14185
dcbf9037
JB
14186 if (et.type == NT_invtype)
14187 return;
14188
5287ad62
JB
14189 switch ((inst.instruction >> 8) & 3)
14190 {
14191 case 0: /* VLD1. */
14192 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
14193 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14194 &do_align, 16, 16, 32, 32, -1);
14195 if (align_good == FAIL)
14196 return;
14197 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14198 {
14199 case 1: break;
14200 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14201 default: first_error (_("bad list length")); return;
5287ad62
JB
14202 }
14203 inst.instruction |= neon_logbits (et.size) << 6;
14204 break;
14205
14206 case 1: /* VLD2. */
14207 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14208 &do_align, 8, 16, 16, 32, 32, 64, -1);
14209 if (align_good == FAIL)
14210 return;
14211 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14212 _("bad list length"));
14213 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14214 inst.instruction |= 1 << 5;
14215 inst.instruction |= neon_logbits (et.size) << 6;
14216 break;
14217
14218 case 2: /* VLD3. */
14219 constraint (inst.operands[1].immisalign,
14220 _("can't use alignment with this instruction"));
14221 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14222 _("bad list length"));
14223 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14224 inst.instruction |= 1 << 5;
14225 inst.instruction |= neon_logbits (et.size) << 6;
14226 break;
14227
14228 case 3: /* VLD4. */
14229 {
14230 int align = inst.operands[1].imm >> 8;
14231 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14232 16, 64, 32, 64, 32, 128, -1);
14233 if (align_good == FAIL)
14234 return;
14235 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14236 _("bad list length"));
14237 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14238 inst.instruction |= 1 << 5;
14239 if (et.size == 32 && align == 128)
14240 inst.instruction |= 0x3 << 6;
14241 else
14242 inst.instruction |= neon_logbits (et.size) << 6;
14243 }
14244 break;
14245
14246 default: ;
14247 }
14248
14249 inst.instruction |= do_align << 4;
14250}
14251
14252/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14253 apart from bits [11:4]. */
14254
14255static void
14256do_neon_ldx_stx (void)
14257{
14258 switch (NEON_LANE (inst.operands[0].imm))
14259 {
14260 case NEON_INTERLEAVE_LANES:
14261 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14262 do_neon_ld_st_interleave ();
14263 break;
5f4273c7 14264
5287ad62
JB
14265 case NEON_ALL_LANES:
14266 inst.instruction = NEON_ENC_DUP (inst.instruction);
14267 do_neon_ld_dup ();
14268 break;
5f4273c7 14269
5287ad62
JB
14270 default:
14271 inst.instruction = NEON_ENC_LANE (inst.instruction);
14272 do_neon_ld_st_lane ();
14273 }
14274
14275 /* L bit comes from bit mask. */
14276 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14277 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14278 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14279
5287ad62
JB
14280 if (inst.operands[1].postind)
14281 {
14282 int postreg = inst.operands[1].imm & 0xf;
14283 constraint (!inst.operands[1].immisreg,
14284 _("post-index must be a register"));
14285 constraint (postreg == 0xd || postreg == 0xf,
14286 _("bad register for post-index"));
14287 inst.instruction |= postreg;
14288 }
14289 else if (inst.operands[1].writeback)
14290 {
14291 inst.instruction |= 0xd;
14292 }
14293 else
5f4273c7
NC
14294 inst.instruction |= 0xf;
14295
5287ad62
JB
14296 if (thumb_mode)
14297 inst.instruction |= 0xf9000000;
14298 else
14299 inst.instruction |= 0xf4000000;
14300}
5287ad62
JB
14301\f
14302/* Overall per-instruction processing. */
14303
14304/* We need to be able to fix up arbitrary expressions in some statements.
14305 This is so that we can handle symbols that are an arbitrary distance from
14306 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14307 which returns part of an address in a form which will be valid for
14308 a data instruction. We do this by pushing the expression into a symbol
14309 in the expr_section, and creating a fix for that. */
14310
14311static void
14312fix_new_arm (fragS * frag,
14313 int where,
14314 short int size,
14315 expressionS * exp,
14316 int pc_rel,
14317 int reloc)
14318{
14319 fixS * new_fix;
14320
14321 switch (exp->X_op)
14322 {
14323 case O_constant:
14324 case O_symbol:
14325 case O_add:
14326 case O_subtract:
14327 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14328 break;
14329
14330 default:
14331 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14332 pc_rel, reloc);
14333 break;
14334 }
14335
14336 /* Mark whether the fix is to a THUMB instruction, or an ARM
14337 instruction. */
14338 new_fix->tc_fix_data = thumb_mode;
14339}
14340
14341/* Create a frg for an instruction requiring relaxation. */
14342static void
14343output_relax_insn (void)
14344{
14345 char * to;
14346 symbolS *sym;
0110f2b8
PB
14347 int offset;
14348
6e1cb1a6
PB
14349 /* The size of the instruction is unknown, so tie the debug info to the
14350 start of the instruction. */
14351 dwarf2_emit_insn (0);
6e1cb1a6 14352
0110f2b8
PB
14353 switch (inst.reloc.exp.X_op)
14354 {
14355 case O_symbol:
14356 sym = inst.reloc.exp.X_add_symbol;
14357 offset = inst.reloc.exp.X_add_number;
14358 break;
14359 case O_constant:
14360 sym = NULL;
14361 offset = inst.reloc.exp.X_add_number;
14362 break;
14363 default:
14364 sym = make_expr_symbol (&inst.reloc.exp);
14365 offset = 0;
14366 break;
14367 }
14368 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14369 inst.relax, sym, offset, NULL/*offset, opcode*/);
14370 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14371}
14372
14373/* Write a 32-bit thumb instruction to buf. */
14374static void
14375put_thumb32_insn (char * buf, unsigned long insn)
14376{
14377 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14378 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14379}
14380
b99bd4ef 14381static void
c19d1205 14382output_inst (const char * str)
b99bd4ef 14383{
c19d1205 14384 char * to = NULL;
b99bd4ef 14385
c19d1205 14386 if (inst.error)
b99bd4ef 14387 {
c19d1205 14388 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14389 return;
14390 }
5f4273c7
NC
14391 if (inst.relax)
14392 {
14393 output_relax_insn ();
0110f2b8 14394 return;
5f4273c7 14395 }
c19d1205
ZW
14396 if (inst.size == 0)
14397 return;
b99bd4ef 14398
c19d1205 14399 to = frag_more (inst.size);
8dc2430f
NC
14400 /* PR 9814: Record the thumb mode into the current frag so that we know
14401 what type of NOP padding to use, if necessary. We override any previous
14402 setting so that if the mode has changed then the NOPS that we use will
14403 match the encoding of the last instruction in the frag. */
14404 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14405
14406 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14407 {
c19d1205 14408 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14409 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14410 }
c19d1205 14411 else if (inst.size > INSN_SIZE)
b99bd4ef 14412 {
c19d1205
ZW
14413 assert (inst.size == (2 * INSN_SIZE));
14414 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14415 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14416 }
c19d1205
ZW
14417 else
14418 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14419
c19d1205
ZW
14420 if (inst.reloc.type != BFD_RELOC_UNUSED)
14421 fix_new_arm (frag_now, to - frag_now->fr_literal,
14422 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14423 inst.reloc.type);
b99bd4ef 14424
c19d1205 14425 dwarf2_emit_insn (inst.size);
c19d1205 14426}
b99bd4ef 14427
c19d1205
ZW
14428/* Tag values used in struct asm_opcode's tag field. */
14429enum opcode_tag
14430{
14431 OT_unconditional, /* Instruction cannot be conditionalized.
14432 The ARM condition field is still 0xE. */
14433 OT_unconditionalF, /* Instruction cannot be conditionalized
14434 and carries 0xF in its ARM condition field. */
14435 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14436 OT_csuffixF, /* Some forms of the instruction take a conditional
14437 suffix, others place 0xF where the condition field
14438 would be. */
c19d1205
ZW
14439 OT_cinfix3, /* Instruction takes a conditional infix,
14440 beginning at character index 3. (In
14441 unified mode, it becomes a suffix.) */
088fa78e
KH
14442 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14443 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14444 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14445 character index 3, even in unified mode. Used for
14446 legacy instructions where suffix and infix forms
14447 may be ambiguous. */
c19d1205 14448 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14449 suffix or an infix at character index 3. */
c19d1205
ZW
14450 OT_odd_infix_unc, /* This is the unconditional variant of an
14451 instruction that takes a conditional infix
14452 at an unusual position. In unified mode,
14453 this variant will accept a suffix. */
14454 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14455 are the conditional variants of instructions that
14456 take conditional infixes in unusual positions.
14457 The infix appears at character index
14458 (tag - OT_odd_infix_0). These are not accepted
14459 in unified mode. */
14460};
b99bd4ef 14461
c19d1205
ZW
14462/* Subroutine of md_assemble, responsible for looking up the primary
14463 opcode from the mnemonic the user wrote. STR points to the
14464 beginning of the mnemonic.
14465
14466 This is not simply a hash table lookup, because of conditional
14467 variants. Most instructions have conditional variants, which are
14468 expressed with a _conditional affix_ to the mnemonic. If we were
14469 to encode each conditional variant as a literal string in the opcode
14470 table, it would have approximately 20,000 entries.
14471
14472 Most mnemonics take this affix as a suffix, and in unified syntax,
14473 'most' is upgraded to 'all'. However, in the divided syntax, some
14474 instructions take the affix as an infix, notably the s-variants of
14475 the arithmetic instructions. Of those instructions, all but six
14476 have the infix appear after the third character of the mnemonic.
14477
14478 Accordingly, the algorithm for looking up primary opcodes given
14479 an identifier is:
14480
14481 1. Look up the identifier in the opcode table.
14482 If we find a match, go to step U.
14483
14484 2. Look up the last two characters of the identifier in the
14485 conditions table. If we find a match, look up the first N-2
14486 characters of the identifier in the opcode table. If we
14487 find a match, go to step CE.
14488
14489 3. Look up the fourth and fifth characters of the identifier in
14490 the conditions table. If we find a match, extract those
14491 characters from the identifier, and look up the remaining
14492 characters in the opcode table. If we find a match, go
14493 to step CM.
14494
14495 4. Fail.
14496
14497 U. Examine the tag field of the opcode structure, in case this is
14498 one of the six instructions with its conditional infix in an
14499 unusual place. If it is, the tag tells us where to find the
14500 infix; look it up in the conditions table and set inst.cond
14501 accordingly. Otherwise, this is an unconditional instruction.
14502 Again set inst.cond accordingly. Return the opcode structure.
14503
14504 CE. Examine the tag field to make sure this is an instruction that
14505 should receive a conditional suffix. If it is not, fail.
14506 Otherwise, set inst.cond from the suffix we already looked up,
14507 and return the opcode structure.
14508
14509 CM. Examine the tag field to make sure this is an instruction that
14510 should receive a conditional infix after the third character.
14511 If it is not, fail. Otherwise, undo the edits to the current
14512 line of input and proceed as for case CE. */
14513
14514static const struct asm_opcode *
14515opcode_lookup (char **str)
14516{
14517 char *end, *base;
14518 char *affix;
14519 const struct asm_opcode *opcode;
14520 const struct asm_cond *cond;
e3cb604e 14521 char save[2];
267d2029 14522 bfd_boolean neon_supported;
5f4273c7 14523
267d2029 14524 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14525
14526 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14527 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14528 for (base = end = *str; *end != '\0'; end++)
267d2029 14529 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14530 break;
b99bd4ef 14531
c19d1205
ZW
14532 if (end == base)
14533 return 0;
b99bd4ef 14534
5287ad62 14535 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14536 if (end[0] == '.')
b99bd4ef 14537 {
5287ad62 14538 int offset = 2;
5f4273c7 14539
267d2029
JB
14540 /* The .w and .n suffixes are only valid if the unified syntax is in
14541 use. */
14542 if (unified_syntax && end[1] == 'w')
c19d1205 14543 inst.size_req = 4;
267d2029 14544 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14545 inst.size_req = 2;
14546 else
5287ad62
JB
14547 offset = 0;
14548
14549 inst.vectype.elems = 0;
14550
14551 *str = end + offset;
b99bd4ef 14552
5f4273c7 14553 if (end[offset] == '.')
5287ad62 14554 {
267d2029
JB
14555 /* See if we have a Neon type suffix (possible in either unified or
14556 non-unified ARM syntax mode). */
dcbf9037 14557 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14558 return 0;
14559 }
14560 else if (end[offset] != '\0' && end[offset] != ' ')
14561 return 0;
b99bd4ef 14562 }
c19d1205
ZW
14563 else
14564 *str = end;
b99bd4ef 14565
c19d1205
ZW
14566 /* Look for unaffixed or special-case affixed mnemonic. */
14567 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14568 if (opcode)
b99bd4ef 14569 {
c19d1205
ZW
14570 /* step U */
14571 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14572 {
c19d1205
ZW
14573 inst.cond = COND_ALWAYS;
14574 return opcode;
b99bd4ef 14575 }
b99bd4ef 14576
278df34e 14577 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
14578 as_warn (_("conditional infixes are deprecated in unified syntax"));
14579 affix = base + (opcode->tag - OT_odd_infix_0);
14580 cond = hash_find_n (arm_cond_hsh, affix, 2);
14581 assert (cond);
b99bd4ef 14582
c19d1205
ZW
14583 inst.cond = cond->value;
14584 return opcode;
14585 }
b99bd4ef 14586
c19d1205
ZW
14587 /* Cannot have a conditional suffix on a mnemonic of less than two
14588 characters. */
14589 if (end - base < 3)
14590 return 0;
b99bd4ef 14591
c19d1205
ZW
14592 /* Look for suffixed mnemonic. */
14593 affix = end - 2;
14594 cond = hash_find_n (arm_cond_hsh, affix, 2);
14595 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14596 if (opcode && cond)
14597 {
14598 /* step CE */
14599 switch (opcode->tag)
14600 {
e3cb604e
PB
14601 case OT_cinfix3_legacy:
14602 /* Ignore conditional suffixes matched on infix only mnemonics. */
14603 break;
14604
c19d1205 14605 case OT_cinfix3:
088fa78e 14606 case OT_cinfix3_deprecated:
c19d1205
ZW
14607 case OT_odd_infix_unc:
14608 if (!unified_syntax)
e3cb604e 14609 return 0;
c19d1205
ZW
14610 /* else fall through */
14611
14612 case OT_csuffix:
037e8744 14613 case OT_csuffixF:
c19d1205
ZW
14614 case OT_csuf_or_in3:
14615 inst.cond = cond->value;
14616 return opcode;
14617
14618 case OT_unconditional:
14619 case OT_unconditionalF:
dfa9f0d5
PB
14620 if (thumb_mode)
14621 {
14622 inst.cond = cond->value;
14623 }
14624 else
14625 {
14626 /* delayed diagnostic */
14627 inst.error = BAD_COND;
14628 inst.cond = COND_ALWAYS;
14629 }
c19d1205 14630 return opcode;
b99bd4ef 14631
c19d1205
ZW
14632 default:
14633 return 0;
14634 }
14635 }
b99bd4ef 14636
c19d1205
ZW
14637 /* Cannot have a usual-position infix on a mnemonic of less than
14638 six characters (five would be a suffix). */
14639 if (end - base < 6)
14640 return 0;
b99bd4ef 14641
c19d1205
ZW
14642 /* Look for infixed mnemonic in the usual position. */
14643 affix = base + 3;
14644 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14645 if (!cond)
14646 return 0;
14647
14648 memcpy (save, affix, 2);
14649 memmove (affix, affix + 2, (end - affix) - 2);
14650 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14651 memmove (affix + 2, affix, (end - affix) - 2);
14652 memcpy (affix, save, 2);
14653
088fa78e
KH
14654 if (opcode
14655 && (opcode->tag == OT_cinfix3
14656 || opcode->tag == OT_cinfix3_deprecated
14657 || opcode->tag == OT_csuf_or_in3
14658 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14659 {
c19d1205 14660 /* step CM */
278df34e 14661 if (warn_on_deprecated && unified_syntax
088fa78e
KH
14662 && (opcode->tag == OT_cinfix3
14663 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14664 as_warn (_("conditional infixes are deprecated in unified syntax"));
14665
14666 inst.cond = cond->value;
14667 return opcode;
b99bd4ef
NC
14668 }
14669
c19d1205 14670 return 0;
b99bd4ef
NC
14671}
14672
c19d1205
ZW
14673void
14674md_assemble (char *str)
b99bd4ef 14675{
c19d1205
ZW
14676 char *p = str;
14677 const struct asm_opcode * opcode;
b99bd4ef 14678
c19d1205
ZW
14679 /* Align the previous label if needed. */
14680 if (last_label_seen != NULL)
b99bd4ef 14681 {
c19d1205
ZW
14682 symbol_set_frag (last_label_seen, frag_now);
14683 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14684 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14685 }
14686
c19d1205
ZW
14687 memset (&inst, '\0', sizeof (inst));
14688 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14689
c19d1205
ZW
14690 opcode = opcode_lookup (&p);
14691 if (!opcode)
b99bd4ef 14692 {
c19d1205 14693 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14694 the form alias .req reg, or a Neon .dn/.qn directive. */
14695 if (!create_register_alias (str, p)
14696 && !create_neon_reg_alias (str, p))
c19d1205 14697 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14698
b99bd4ef
NC
14699 return;
14700 }
14701
278df34e 14702 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
14703 as_warn (_("s suffix on comparison instruction is deprecated"));
14704
037e8744
JB
14705 /* The value which unconditional instructions should have in place of the
14706 condition field. */
14707 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14708
c19d1205 14709 if (thumb_mode)
b99bd4ef 14710 {
e74cfd16 14711 arm_feature_set variant;
8f06b2d8
PB
14712
14713 variant = cpu_variant;
14714 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14715 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14716 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14717 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14718 if (!opcode->tvariant
14719 || (thumb_mode == 1
14720 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14721 {
c19d1205 14722 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14723 return;
14724 }
c19d1205
ZW
14725 if (inst.cond != COND_ALWAYS && !unified_syntax
14726 && opcode->tencode != do_t_branch)
b99bd4ef 14727 {
c19d1205 14728 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14729 return;
14730 }
14731
076d447c
PB
14732 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14733 {
14734 /* Implicit require narrow instructions on Thumb-1. This avoids
14735 relaxation accidentally introducing Thumb-2 instructions. */
7e806470 14736 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
04e2c417
MM
14737 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14738 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
076d447c
PB
14739 inst.size_req = 2;
14740 }
14741
e27ec89e
PB
14742 /* Check conditional suffixes. */
14743 if (current_it_mask)
14744 {
14745 int cond;
14746 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14747 current_it_mask <<= 1;
14748 current_it_mask &= 0x1f;
14749 /* The BKPT instruction is unconditional even in an IT block. */
14750 if (!inst.error
14751 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14752 {
14753 as_bad (_("incorrect condition in IT block"));
14754 return;
14755 }
e27ec89e
PB
14756 }
14757 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14758 {
6decc662 14759 as_bad (_("thumb conditional instruction not in IT block"));
e27ec89e
PB
14760 return;
14761 }
14762
c19d1205
ZW
14763 mapping_state (MAP_THUMB);
14764 inst.instruction = opcode->tvalue;
14765
14766 if (!parse_operands (p, opcode->operands))
14767 opcode->tencode ();
14768
e27ec89e
PB
14769 /* Clear current_it_mask at the end of an IT block. */
14770 if (current_it_mask == 0x10)
14771 current_it_mask = 0;
14772
0110f2b8 14773 if (!(inst.error || inst.relax))
b99bd4ef 14774 {
c19d1205
ZW
14775 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14776 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14777 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14778 {
c19d1205 14779 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14780 return;
14781 }
14782 }
076d447c
PB
14783
14784 /* Something has gone badly wrong if we try to relax a fixed size
14785 instruction. */
14786 assert (inst.size_req == 0 || !inst.relax);
14787
e74cfd16
PB
14788 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14789 *opcode->tvariant);
ee065d83 14790 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14791 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 14792 anything other than bl/blx and v6-M instructions.
ee065d83 14793 This is overly pessimistic for relaxable instructions. */
7e806470
PB
14794 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14795 || inst.relax)
04e2c417
MM
14796 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
14797 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
14798 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14799 arm_ext_v6t2);
c19d1205 14800 }
3e9e4fcf 14801 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 14802 {
845b51d6
PB
14803 bfd_boolean is_bx;
14804
14805 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
14806 is_bx = (opcode->aencode == do_bx);
14807
c19d1205 14808 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
14809 if (!(is_bx && fix_v4bx)
14810 && !(opcode->avariant &&
14811 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 14812 {
c19d1205
ZW
14813 as_bad (_("selected processor does not support `%s'"), str);
14814 return;
b99bd4ef 14815 }
c19d1205 14816 if (inst.size_req)
b99bd4ef 14817 {
c19d1205
ZW
14818 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14819 return;
b99bd4ef
NC
14820 }
14821
c19d1205
ZW
14822 mapping_state (MAP_ARM);
14823 inst.instruction = opcode->avalue;
14824 if (opcode->tag == OT_unconditionalF)
14825 inst.instruction |= 0xF << 28;
14826 else
14827 inst.instruction |= inst.cond << 28;
14828 inst.size = INSN_SIZE;
14829 if (!parse_operands (p, opcode->operands))
14830 opcode->aencode ();
ee065d83
PB
14831 /* Arm mode bx is marked as both v4T and v5 because it's still required
14832 on a hypothetical non-thumb v5 core. */
845b51d6 14833 if (is_bx)
e74cfd16 14834 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14835 else
e74cfd16
PB
14836 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14837 *opcode->avariant);
b99bd4ef 14838 }
3e9e4fcf
JB
14839 else
14840 {
14841 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14842 "-- `%s'"), str);
14843 return;
14844 }
c19d1205
ZW
14845 output_inst (str);
14846}
b99bd4ef 14847
c19d1205
ZW
14848/* Various frobbings of labels and their addresses. */
14849
14850void
14851arm_start_line_hook (void)
14852{
14853 last_label_seen = NULL;
b99bd4ef
NC
14854}
14855
c19d1205
ZW
14856void
14857arm_frob_label (symbolS * sym)
b99bd4ef 14858{
c19d1205 14859 last_label_seen = sym;
b99bd4ef 14860
c19d1205 14861 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14862
c19d1205
ZW
14863#if defined OBJ_COFF || defined OBJ_ELF
14864 ARM_SET_INTERWORK (sym, support_interwork);
14865#endif
b99bd4ef 14866
5f4273c7 14867 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
14868 as Thumb functions. This is because these labels, whilst
14869 they exist inside Thumb code, are not the entry points for
14870 possible ARM->Thumb calls. Also, these labels can be used
14871 as part of a computed goto or switch statement. eg gcc
14872 can generate code that looks like this:
b99bd4ef 14873
c19d1205
ZW
14874 ldr r2, [pc, .Laaa]
14875 lsl r3, r3, #2
14876 ldr r2, [r3, r2]
14877 mov pc, r2
b99bd4ef 14878
c19d1205
ZW
14879 .Lbbb: .word .Lxxx
14880 .Lccc: .word .Lyyy
14881 ..etc...
14882 .Laaa: .word Lbbb
b99bd4ef 14883
c19d1205
ZW
14884 The first instruction loads the address of the jump table.
14885 The second instruction converts a table index into a byte offset.
14886 The third instruction gets the jump address out of the table.
14887 The fourth instruction performs the jump.
b99bd4ef 14888
c19d1205
ZW
14889 If the address stored at .Laaa is that of a symbol which has the
14890 Thumb_Func bit set, then the linker will arrange for this address
14891 to have the bottom bit set, which in turn would mean that the
14892 address computation performed by the third instruction would end
14893 up with the bottom bit set. Since the ARM is capable of unaligned
14894 word loads, the instruction would then load the incorrect address
14895 out of the jump table, and chaos would ensue. */
14896 if (label_is_thumb_function_name
14897 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14898 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14899 {
c19d1205
ZW
14900 /* When the address of a Thumb function is taken the bottom
14901 bit of that address should be set. This will allow
14902 interworking between Arm and Thumb functions to work
14903 correctly. */
b99bd4ef 14904
c19d1205 14905 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14906
c19d1205 14907 label_is_thumb_function_name = FALSE;
b99bd4ef 14908 }
07a53e5c 14909
07a53e5c 14910 dwarf2_emit_label (sym);
b99bd4ef
NC
14911}
14912
c19d1205
ZW
14913int
14914arm_data_in_code (void)
b99bd4ef 14915{
c19d1205 14916 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14917 {
c19d1205
ZW
14918 *input_line_pointer = '/';
14919 input_line_pointer += 5;
14920 *input_line_pointer = 0;
14921 return 1;
b99bd4ef
NC
14922 }
14923
c19d1205 14924 return 0;
b99bd4ef
NC
14925}
14926
c19d1205
ZW
14927char *
14928arm_canonicalize_symbol_name (char * name)
b99bd4ef 14929{
c19d1205 14930 int len;
b99bd4ef 14931
c19d1205
ZW
14932 if (thumb_mode && (len = strlen (name)) > 5
14933 && streq (name + len - 5, "/data"))
14934 *(name + len - 5) = 0;
b99bd4ef 14935
c19d1205 14936 return name;
b99bd4ef 14937}
c19d1205
ZW
14938\f
14939/* Table of all register names defined by default. The user can
14940 define additional names with .req. Note that all register names
14941 should appear in both upper and lowercase variants. Some registers
14942 also have mixed-case names. */
b99bd4ef 14943
dcbf9037 14944#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14945#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14946#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14947#define REGSET(p,t) \
14948 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14949 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14950 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14951 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14952#define REGSETH(p,t) \
14953 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14954 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14955 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14956 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14957#define REGSET2(p,t) \
14958 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14959 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14960 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14961 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14962
c19d1205 14963static const struct reg_entry reg_names[] =
7ed4c4c5 14964{
c19d1205
ZW
14965 /* ARM integer registers. */
14966 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14967
c19d1205
ZW
14968 /* ATPCS synonyms. */
14969 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14970 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14971 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14972
c19d1205
ZW
14973 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14974 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14975 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14976
c19d1205
ZW
14977 /* Well-known aliases. */
14978 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14979 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14980
14981 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14982 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14983
14984 /* Coprocessor numbers. */
14985 REGSET(p, CP), REGSET(P, CP),
14986
14987 /* Coprocessor register numbers. The "cr" variants are for backward
14988 compatibility. */
14989 REGSET(c, CN), REGSET(C, CN),
14990 REGSET(cr, CN), REGSET(CR, CN),
14991
14992 /* FPA registers. */
14993 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14994 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14995
14996 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14997 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14998
14999 /* VFP SP registers. */
5287ad62
JB
15000 REGSET(s,VFS), REGSET(S,VFS),
15001 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15002
15003 /* VFP DP Registers. */
5287ad62
JB
15004 REGSET(d,VFD), REGSET(D,VFD),
15005 /* Extra Neon DP registers. */
15006 REGSETH(d,VFD), REGSETH(D,VFD),
15007
15008 /* Neon QP registers. */
15009 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15010
15011 /* VFP control registers. */
15012 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15013 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15014 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15015 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15016 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15017 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15018
15019 /* Maverick DSP coprocessor registers. */
15020 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15021 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15022
15023 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15024 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15025 REGDEF(dspsc,0,DSPSC),
15026
15027 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15028 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15029 REGDEF(DSPSC,0,DSPSC),
15030
15031 /* iWMMXt data registers - p0, c0-15. */
15032 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15033
15034 /* iWMMXt control registers - p1, c0-3. */
15035 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15036 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15037 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15038 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15039
15040 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15041 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15042 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15043 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15044 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15045
15046 /* XScale accumulator registers. */
15047 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15048};
15049#undef REGDEF
15050#undef REGNUM
15051#undef REGSET
7ed4c4c5 15052
c19d1205
ZW
15053/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15054 within psr_required_here. */
15055static const struct asm_psr psrs[] =
15056{
15057 /* Backward compatibility notation. Note that "all" is no longer
15058 truly all possible PSR bits. */
15059 {"all", PSR_c | PSR_f},
15060 {"flg", PSR_f},
15061 {"ctl", PSR_c},
15062
15063 /* Individual flags. */
15064 {"f", PSR_f},
15065 {"c", PSR_c},
15066 {"x", PSR_x},
15067 {"s", PSR_s},
15068 /* Combinations of flags. */
15069 {"fs", PSR_f | PSR_s},
15070 {"fx", PSR_f | PSR_x},
15071 {"fc", PSR_f | PSR_c},
15072 {"sf", PSR_s | PSR_f},
15073 {"sx", PSR_s | PSR_x},
15074 {"sc", PSR_s | PSR_c},
15075 {"xf", PSR_x | PSR_f},
15076 {"xs", PSR_x | PSR_s},
15077 {"xc", PSR_x | PSR_c},
15078 {"cf", PSR_c | PSR_f},
15079 {"cs", PSR_c | PSR_s},
15080 {"cx", PSR_c | PSR_x},
15081 {"fsx", PSR_f | PSR_s | PSR_x},
15082 {"fsc", PSR_f | PSR_s | PSR_c},
15083 {"fxs", PSR_f | PSR_x | PSR_s},
15084 {"fxc", PSR_f | PSR_x | PSR_c},
15085 {"fcs", PSR_f | PSR_c | PSR_s},
15086 {"fcx", PSR_f | PSR_c | PSR_x},
15087 {"sfx", PSR_s | PSR_f | PSR_x},
15088 {"sfc", PSR_s | PSR_f | PSR_c},
15089 {"sxf", PSR_s | PSR_x | PSR_f},
15090 {"sxc", PSR_s | PSR_x | PSR_c},
15091 {"scf", PSR_s | PSR_c | PSR_f},
15092 {"scx", PSR_s | PSR_c | PSR_x},
15093 {"xfs", PSR_x | PSR_f | PSR_s},
15094 {"xfc", PSR_x | PSR_f | PSR_c},
15095 {"xsf", PSR_x | PSR_s | PSR_f},
15096 {"xsc", PSR_x | PSR_s | PSR_c},
15097 {"xcf", PSR_x | PSR_c | PSR_f},
15098 {"xcs", PSR_x | PSR_c | PSR_s},
15099 {"cfs", PSR_c | PSR_f | PSR_s},
15100 {"cfx", PSR_c | PSR_f | PSR_x},
15101 {"csf", PSR_c | PSR_s | PSR_f},
15102 {"csx", PSR_c | PSR_s | PSR_x},
15103 {"cxf", PSR_c | PSR_x | PSR_f},
15104 {"cxs", PSR_c | PSR_x | PSR_s},
15105 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15106 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15107 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15108 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15109 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15110 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15111 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15112 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15113 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15114 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15115 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15116 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15117 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15118 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15119 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15120 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15121 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15122 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15123 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15124 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15125 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15126 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15127 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15128 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15129};
15130
62b3e311
PB
15131/* Table of V7M psr names. */
15132static const struct asm_psr v7m_psrs[] =
15133{
2b744c99
PB
15134 {"apsr", 0 }, {"APSR", 0 },
15135 {"iapsr", 1 }, {"IAPSR", 1 },
15136 {"eapsr", 2 }, {"EAPSR", 2 },
15137 {"psr", 3 }, {"PSR", 3 },
15138 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15139 {"ipsr", 5 }, {"IPSR", 5 },
15140 {"epsr", 6 }, {"EPSR", 6 },
15141 {"iepsr", 7 }, {"IEPSR", 7 },
15142 {"msp", 8 }, {"MSP", 8 },
15143 {"psp", 9 }, {"PSP", 9 },
15144 {"primask", 16}, {"PRIMASK", 16},
15145 {"basepri", 17}, {"BASEPRI", 17},
15146 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15147 {"faultmask", 19}, {"FAULTMASK", 19},
15148 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
15149};
15150
c19d1205
ZW
15151/* Table of all shift-in-operand names. */
15152static const struct asm_shift_name shift_names [] =
b99bd4ef 15153{
c19d1205
ZW
15154 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15155 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15156 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15157 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15158 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15159 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15160};
b99bd4ef 15161
c19d1205
ZW
15162/* Table of all explicit relocation names. */
15163#ifdef OBJ_ELF
15164static struct reloc_entry reloc_names[] =
15165{
15166 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15167 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15168 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15169 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15170 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15171 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15172 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15173 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15174 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15175 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15176 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15177};
15178#endif
b99bd4ef 15179
c19d1205
ZW
15180/* Table of all conditional affixes. 0xF is not defined as a condition code. */
15181static const struct asm_cond conds[] =
15182{
15183 {"eq", 0x0},
15184 {"ne", 0x1},
15185 {"cs", 0x2}, {"hs", 0x2},
15186 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15187 {"mi", 0x4},
15188 {"pl", 0x5},
15189 {"vs", 0x6},
15190 {"vc", 0x7},
15191 {"hi", 0x8},
15192 {"ls", 0x9},
15193 {"ge", 0xa},
15194 {"lt", 0xb},
15195 {"gt", 0xc},
15196 {"le", 0xd},
15197 {"al", 0xe}
15198};
bfae80f2 15199
62b3e311
PB
15200static struct asm_barrier_opt barrier_opt_names[] =
15201{
15202 { "sy", 0xf },
15203 { "un", 0x7 },
15204 { "st", 0xe },
15205 { "unst", 0x6 }
15206};
15207
c19d1205
ZW
15208/* Table of ARM-format instructions. */
15209
15210/* Macros for gluing together operand strings. N.B. In all cases
15211 other than OPS0, the trailing OP_stop comes from default
15212 zero-initialization of the unspecified elements of the array. */
15213#define OPS0() { OP_stop, }
15214#define OPS1(a) { OP_##a, }
15215#define OPS2(a,b) { OP_##a,OP_##b, }
15216#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15217#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15218#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15219#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15220
15221/* These macros abstract out the exact format of the mnemonic table and
15222 save some repeated characters. */
15223
15224/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15225#define TxCE(mnem, op, top, nops, ops, ae, te) \
15226 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 15227 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15228
15229/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15230 a T_MNEM_xyz enumerator. */
15231#define TCE(mnem, aop, top, nops, ops, ae, te) \
15232 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
15233#define tCE(mnem, aop, top, nops, ops, ae, te) \
15234 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15235
15236/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15237 infix after the third character. */
15238#define TxC3(mnem, op, top, nops, ops, ae, te) \
15239 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 15240 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
15241#define TxC3w(mnem, op, top, nops, ops, ae, te) \
15242 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15243 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15244#define TC3(mnem, aop, top, nops, ops, ae, te) \
15245 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
15246#define TC3w(mnem, aop, top, nops, ops, ae, te) \
15247 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
15248#define tC3(mnem, aop, top, nops, ops, ae, te) \
15249 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
15250#define tC3w(mnem, aop, top, nops, ops, ae, te) \
15251 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15252
15253/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15254 appear in the condition table. */
15255#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
15256 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 15257 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15258
15259#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
15260 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
15261 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
15262 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
15263 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
15264 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
15265 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
15266 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
15267 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
15268 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
15269 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
15270 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
15271 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
15272 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
15273 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
15274 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
15275 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
15276 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
15277 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
15278 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
15279
15280#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
15281 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
15282#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15283 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
15284
15285/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
15286 field is still 0xE. Many of the Thumb variants can be executed
15287 conditionally, so this is checked separately. */
c19d1205
ZW
15288#define TUE(mnem, op, top, nops, ops, ae, te) \
15289 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15290 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15291
15292/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15293 condition code field. */
15294#define TUF(mnem, op, top, nops, ops, ae, te) \
15295 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15296 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15297
15298/* ARM-only variants of all the above. */
6a86118a
NC
15299#define CE(mnem, op, nops, ops, ae) \
15300 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15301
15302#define C3(mnem, op, nops, ops, ae) \
15303 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15304
e3cb604e
PB
15305/* Legacy mnemonics that always have conditional infix after the third
15306 character. */
15307#define CL(mnem, op, nops, ops, ae) \
15308 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15309 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15310
8f06b2d8
PB
15311/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15312#define cCE(mnem, op, nops, ops, ae) \
15313 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15314
e3cb604e
PB
15315/* Legacy coprocessor instructions where conditional infix and conditional
15316 suffix are ambiguous. For consistency this includes all FPA instructions,
15317 not just the potentially ambiguous ones. */
15318#define cCL(mnem, op, nops, ops, ae) \
15319 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15320 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15321
15322/* Coprocessor, takes either a suffix or a position-3 infix
15323 (for an FPA corner case). */
15324#define C3E(mnem, op, nops, ops, ae) \
15325 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15326 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 15327
6a86118a
NC
15328#define xCM_(m1, m2, m3, op, nops, ops, ae) \
15329 { #m1 #m2 #m3, OPS##nops ops, \
15330 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
15331 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15332
15333#define CM(m1, m2, op, nops, ops, ae) \
15334 xCM_(m1, , m2, op, nops, ops, ae), \
15335 xCM_(m1, eq, m2, op, nops, ops, ae), \
15336 xCM_(m1, ne, m2, op, nops, ops, ae), \
15337 xCM_(m1, cs, m2, op, nops, ops, ae), \
15338 xCM_(m1, hs, m2, op, nops, ops, ae), \
15339 xCM_(m1, cc, m2, op, nops, ops, ae), \
15340 xCM_(m1, ul, m2, op, nops, ops, ae), \
15341 xCM_(m1, lo, m2, op, nops, ops, ae), \
15342 xCM_(m1, mi, m2, op, nops, ops, ae), \
15343 xCM_(m1, pl, m2, op, nops, ops, ae), \
15344 xCM_(m1, vs, m2, op, nops, ops, ae), \
15345 xCM_(m1, vc, m2, op, nops, ops, ae), \
15346 xCM_(m1, hi, m2, op, nops, ops, ae), \
15347 xCM_(m1, ls, m2, op, nops, ops, ae), \
15348 xCM_(m1, ge, m2, op, nops, ops, ae), \
15349 xCM_(m1, lt, m2, op, nops, ops, ae), \
15350 xCM_(m1, gt, m2, op, nops, ops, ae), \
15351 xCM_(m1, le, m2, op, nops, ops, ae), \
15352 xCM_(m1, al, m2, op, nops, ops, ae)
15353
15354#define UE(mnem, op, nops, ops, ae) \
15355 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15356
15357#define UF(mnem, op, nops, ops, ae) \
15358 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15359
5287ad62
JB
15360/* Neon data-processing. ARM versions are unconditional with cond=0xf.
15361 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15362 use the same encoding function for each. */
15363#define NUF(mnem, op, nops, ops, enc) \
15364 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15365 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15366
15367/* Neon data processing, version which indirects through neon_enc_tab for
15368 the various overloaded versions of opcodes. */
15369#define nUF(mnem, op, nops, ops, enc) \
15370 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15371 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15372
15373/* Neon insn with conditional suffix for the ARM version, non-overloaded
15374 version. */
037e8744
JB
15375#define NCE_tag(mnem, op, nops, ops, enc, tag) \
15376 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
15377 THUMB_VARIANT, do_##enc, do_##enc }
15378
037e8744
JB
15379#define NCE(mnem, op, nops, ops, enc) \
15380 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15381
15382#define NCEF(mnem, op, nops, ops, enc) \
15383 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15384
5287ad62 15385/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
15386#define nCE_tag(mnem, op, nops, ops, enc, tag) \
15387 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
15388 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15389
037e8744
JB
15390#define nCE(mnem, op, nops, ops, enc) \
15391 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
15392
15393#define nCEF(mnem, op, nops, ops, enc) \
15394 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
15395
c19d1205
ZW
15396#define do_0 0
15397
15398/* Thumb-only, unconditional. */
15399#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
15400
c19d1205 15401static const struct asm_opcode insns[] =
bfae80f2 15402{
e74cfd16
PB
15403#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15404#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15405 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15406 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15407 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15408 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15409 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15410 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
15411 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15412 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
15413 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15414 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15415 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15416 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15417 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15418 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15419 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15420 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15421
15422 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15423 for setting PSR flag bits. They are obsolete in V6 and do not
15424 have Thumb equivalents. */
15425 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15426 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15427 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 15428 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 15429 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 15430 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 15431 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15432 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15433 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
15434
15435 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15436 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15437 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15438 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15439
4962c51a
MS
15440 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15441 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15442 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15443 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 15444
f5208ef2 15445 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15446 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15447 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 15448 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15449 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15450 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15451
15452 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 15453 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 15454 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 15455 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 15456
c19d1205 15457 /* Pseudo ops. */
e9f89963 15458 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
15459 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15460 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
15461
15462 /* Thumb-compatibility pseudo ops. */
15463 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15464 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15465 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15466 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15467 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 15468 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
15469 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15470 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15471 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15472 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15473 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15474 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15475
16a4cf17
PB
15476 /* These may simplify to neg. */
15477 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15478 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15479
c19d1205 15480#undef THUMB_VARIANT
e74cfd16 15481#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 15482 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
15483
15484 /* V1 instructions with no Thumb analogue prior to V6T2. */
15485#undef THUMB_VARIANT
e74cfd16 15486#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15487 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15488 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15489 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
15490
15491 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15492 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15493 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15494 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15495
9c3c69f2
PB
15496 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15497 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 15498
9c3c69f2
PB
15499 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15500 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15501
15502 /* V1 instructions with no Thumb analogue at all. */
15503 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15504 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15505
15506 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15507 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15508 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15509 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15510 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15511 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15512 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15513 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15514
15515#undef ARM_VARIANT
e74cfd16 15516#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15517#undef THUMB_VARIANT
e74cfd16 15518#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15519 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15520 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15521
15522#undef THUMB_VARIANT
e74cfd16 15523#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15524 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15525 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15526
15527 /* Generic coprocessor instructions. */
15528 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15529 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15530 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15531 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15532 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15533 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15534 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15535
15536#undef ARM_VARIANT
e74cfd16 15537#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15538 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15539 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15540
15541#undef ARM_VARIANT
e74cfd16 15542#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
15543#undef THUMB_VARIANT
15544#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
15545 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15546 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15547
15548#undef ARM_VARIANT
e74cfd16 15549#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
15550#undef THUMB_VARIANT
15551#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15552 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15553 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15554 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15555 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15556 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15557 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15558 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15559 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15560
15561#undef ARM_VARIANT
e74cfd16 15562#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15563#undef THUMB_VARIANT
e74cfd16 15564#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15565 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15566 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15567 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15568 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15569 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15570 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15571
15572#undef ARM_VARIANT
e74cfd16 15573#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15574 /* ARM Architecture 4T. */
15575 /* Note: bx (and blx) are required on V5, even if the processor does
15576 not support Thumb. */
15577 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15578
15579#undef ARM_VARIANT
e74cfd16 15580#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15581#undef THUMB_VARIANT
e74cfd16 15582#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15583 /* Note: blx has 2 variants; the .value coded here is for
15584 BLX(2). Only this variant has conditional execution. */
15585 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15586 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15587
15588#undef THUMB_VARIANT
e74cfd16 15589#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15590 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15591 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15592 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15593 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15594 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15595 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15596 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15597 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15598
15599#undef ARM_VARIANT
e74cfd16 15600#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15601 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15602 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15603 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15604 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15605
15606 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15607 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15608
15609 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15610 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15611 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15612 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15613
15614 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15615 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15616 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15617 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15618
15619 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15620 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15621
087b80de
JM
15622 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15623 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15624 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
15625 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205
ZW
15626
15627#undef ARM_VARIANT
e74cfd16 15628#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15629 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15630 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15631 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15632
15633 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15634 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15635
15636#undef ARM_VARIANT
e74cfd16 15637#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15638 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15639
15640#undef ARM_VARIANT
e74cfd16 15641#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15642#undef THUMB_VARIANT
e74cfd16 15643#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15644 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15645 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15646 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15647 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15648 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15649 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15650 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15651 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15652 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15653 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15654
15655#undef THUMB_VARIANT
e74cfd16 15656#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15657 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15658 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15659 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15660 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15661
15662 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15663 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15664
15665/* ARM V6 not included in V7M (eg. integer SIMD). */
15666#undef THUMB_VARIANT
15667#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15668 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15669 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15670 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15671 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15672 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15673 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15674 /* Old name for QASX. */
c19d1205 15675 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15676 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15677 /* Old name for QSAX. */
15678 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15679 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15680 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15681 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15682 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15683 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15684 /* Old name for SASX. */
c19d1205
ZW
15685 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15686 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15687 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15688 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15689 /* Old name for SHASX. */
c19d1205 15690 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15691 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15692 /* Old name for SHSAX. */
15693 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15694 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15695 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15696 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15697 /* Old name for SSAX. */
15698 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15699 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15700 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15701 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15702 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15703 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15704 /* Old name for UASX. */
c19d1205
ZW
15705 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15706 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15707 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15708 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15709 /* Old name for UHASX. */
c19d1205 15710 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15711 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15712 /* Old name for UHSAX. */
15713 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15714 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15715 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15716 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15717 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15718 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15719 /* Old name for UQASX. */
c19d1205 15720 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15721 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15722 /* Old name for UQSAX. */
15723 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15724 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15725 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205 15726 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
15727 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15728 /* Old name for USAX. */
c19d1205 15729 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 15730 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15731 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15732 UF(rfeib, 9900a00, 1, (RRw), rfe),
15733 UF(rfeda, 8100a00, 1, (RRw), rfe),
15734 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15735 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15736 UF(rfefa, 9900a00, 1, (RRw), rfe),
15737 UF(rfeea, 8100a00, 1, (RRw), rfe),
15738 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15739 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15740 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15741 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15742 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15743 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15744 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15745 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15746 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15747 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15748 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15749 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15750 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15751 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15752 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15753 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15754 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15755 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15756 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15757 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15758 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15759 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15760 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15761 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15762 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15763 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15764 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15765 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15766 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15767 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15768 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15769 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15770 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15771 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15772 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15773 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15774 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15775
15776#undef ARM_VARIANT
e74cfd16 15777#define ARM_VARIANT &arm_ext_v6k
c19d1205 15778#undef THUMB_VARIANT
e74cfd16 15779#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15780 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15781 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15782 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15783 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15784
ebdca51a
PB
15785#undef THUMB_VARIANT
15786#define THUMB_VARIANT &arm_ext_v6_notm
15787 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15788 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15789
c19d1205 15790#undef THUMB_VARIANT
e74cfd16 15791#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15792 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15793 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15794 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15795 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15796 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15797
15798#undef ARM_VARIANT
e74cfd16 15799#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15800 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15801
15802#undef ARM_VARIANT
e74cfd16 15803#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15804 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15805 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15806 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15807 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15808
15809 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15810 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15811 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15812 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15813
15814 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15815 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15816 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15817 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15818
25fe350b
MS
15819 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15820 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15821 /* ARM does not really have an IT instruction, so always allow it. */
15822#undef ARM_VARIANT
15823#define ARM_VARIANT &arm_ext_v1
1c444d06
JM
15824 TUE(it, 0, bf08, 1, (COND), it, t_it),
15825 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15826 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15827 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15828 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15829 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15830 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15831 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15832 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15833 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15834 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15835 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15836 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15837 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15838 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15839 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
15840 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
15841 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 15842
92e90b6e
PB
15843 /* Thumb2 only instructions. */
15844#undef ARM_VARIANT
e74cfd16 15845#define ARM_VARIANT NULL
92e90b6e
PB
15846
15847 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15848 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
1c444d06
JM
15849 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
15850 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
92e90b6e
PB
15851 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15852 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15853
62b3e311
PB
15854 /* Thumb-2 hardware division instructions (R and M profiles only). */
15855#undef THUMB_VARIANT
15856#define THUMB_VARIANT &arm_ext_div
15857 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15858 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15859
7e806470
PB
15860 /* ARM V6M/V7 instructions. */
15861#undef ARM_VARIANT
15862#define ARM_VARIANT &arm_ext_barrier
15863#undef THUMB_VARIANT
15864#define THUMB_VARIANT &arm_ext_barrier
15865 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15866 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15867 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15868
62b3e311
PB
15869 /* ARM V7 instructions. */
15870#undef ARM_VARIANT
15871#define ARM_VARIANT &arm_ext_v7
15872#undef THUMB_VARIANT
15873#define THUMB_VARIANT &arm_ext_v7
15874 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15875 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 15876
c19d1205 15877#undef ARM_VARIANT
e74cfd16 15878#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15879 cCE(wfs, e200110, 1, (RR), rd),
15880 cCE(rfs, e300110, 1, (RR), rd),
15881 cCE(wfc, e400110, 1, (RR), rd),
15882 cCE(rfc, e500110, 1, (RR), rd),
15883
4962c51a
MS
15884 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15885 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15886 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15887 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15888
4962c51a
MS
15889 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15890 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15891 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15892 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15893
15894 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15895 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15896 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15897 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15898 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15899 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15900 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15901 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15902 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15903 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15904 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15905 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15906
15907 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15908 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15909 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15910 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15911 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15912 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15913 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15914 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15915 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15916 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15917 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15918 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15919
15920 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15921 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15922 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15923 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15924 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15925 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15926 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15927 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15928 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15929 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15930 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15931 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15932
15933 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15934 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15935 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15936 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15937 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15938 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15939 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15940 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15941 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15942 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15943 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15944 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15945
15946 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15947 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15948 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15949 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15950 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15951 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15952 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15953 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15954 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15955 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15956 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15957 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15958
15959 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15960 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15961 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15962 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15963 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15964 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15965 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15966 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15967 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15968 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15969 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15970 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15971
15972 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15973 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15974 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15975 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15976 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15977 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15978 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15979 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15980 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15981 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15982 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15983 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15984
15985 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15986 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15987 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15988 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15989 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15990 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15991 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15992 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15993 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15994 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15995 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15996 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15997
15998 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15999 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16000 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16001 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16002 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16003 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16004 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16005 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16006 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16007 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16008 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16009 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16010
16011 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16012 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16013 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16014 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16015 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16016 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16017 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16018 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16019 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16020 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16021 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16022 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16023
16024 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16025 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16026 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16027 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16028 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16029 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16030 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16031 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16032 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16033 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16034 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16035 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16036
16037 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16038 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16039 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16040 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16041 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16042 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16043 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16044 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16045 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16046 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16047 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16048 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16049
16050 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16051 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16052 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16053 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16054 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16055 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16056 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16057 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16058 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16059 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16060 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16061 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16062
16063 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16064 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16065 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16066 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16067 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16068 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16069 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16070 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16071 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16072 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16073 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16074 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16075
16076 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16077 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16078 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16079 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16080 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16081 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16082 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16083 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16084 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16085 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16086 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16087 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16088
16089 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16090 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16091 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16092 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16093 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16094 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16095 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16096 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16097 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16098 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16099 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16100 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16101
16102 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16103 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16104 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16105 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16106 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16107 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16108 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16109 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16110 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16111 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16112 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16113 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16114
16115 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16116 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16117 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16118 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16119 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16120 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16121 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16122 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16123 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16124 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16125 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16126 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16127
16128 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16129 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16130 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16131 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16132 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16133 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16134 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16135 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16136 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16137 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16138 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16139 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16140
16141 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16142 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16143 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16144 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16145 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16146 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16147 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16148 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16149 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16150 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16151 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16152 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16153
16154 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16155 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16156 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16157 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16158 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16159 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16160 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16161 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16162 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16163 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16164 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16165 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16166
16167 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16168 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16169 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16170 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16171 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16172 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16173 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16174 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16175 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16176 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16177 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16178 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16179
16180 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16181 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16182 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16183 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16184 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16185 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16186 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16187 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16188 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16189 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16190 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16191 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16192
16193 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16194 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16195 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16196 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16197 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16198 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16199 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16200 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16201 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16202 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16203 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16204 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16205
16206 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16207 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16208 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16209 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16210 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16211 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16212 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16213 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16214 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16215 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16216 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16217 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16218
16219 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16220 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16221 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16222 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16223 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16224 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16225 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16226 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16227 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16228 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16229 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16230 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16231
16232 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16233 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16234 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16235 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16236 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16237 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16238 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16239 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16240 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16241 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16242 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16243 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16244
16245 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16246 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16247 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16248 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16249 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16250 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16251 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16252 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16253 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16254 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16255 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16256 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16257
16258 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16259 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16260 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16261 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16262 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16263 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16264 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16265 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16266 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16267 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16268 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16269 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
16270
16271 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 16272 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 16273 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
16274 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16275
e3cb604e
PB
16276 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16277 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16278 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16279 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16280 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16281 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16282 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16283 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16284 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16285 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16286 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16287 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 16288
c19d1205
ZW
16289 /* The implementation of the FIX instruction is broken on some
16290 assemblers, in that it accepts a precision specifier as well as a
16291 rounding specifier, despite the fact that this is meaningless.
16292 To be more compatible, we accept it as well, though of course it
16293 does not set any bits. */
8f06b2d8 16294 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
16295 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16296 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16297 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16298 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16299 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16300 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16301 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16302 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16303 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16304 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16305 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16306 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 16307
c19d1205
ZW
16308 /* Instructions that were new with the real FPA, call them V2. */
16309#undef ARM_VARIANT
e74cfd16 16310#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 16311 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16312 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16313 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 16314 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16315 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16316 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
16317
16318#undef ARM_VARIANT
e74cfd16 16319#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 16320 /* Moves and type conversions. */
8f06b2d8
PB
16321 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16322 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16323 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16324 cCE(fmstat, ef1fa10, 0, (), noargs),
16325 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16326 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16327 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16328 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16329 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16330 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16331 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16332 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
16333
16334 /* Memory operations. */
4962c51a
MS
16335 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16336 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
16337 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16338 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16339 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16340 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16341 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16342 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16343 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16344 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16345 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16346 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16347 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16348 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16349 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16350 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16351 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16352 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 16353
c19d1205 16354 /* Monadic operations. */
8f06b2d8
PB
16355 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16356 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16357 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
16358
16359 /* Dyadic operations. */
8f06b2d8
PB
16360 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16361 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16362 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16363 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16364 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16365 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16366 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16367 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16368 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 16369
c19d1205 16370 /* Comparisons. */
8f06b2d8
PB
16371 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16372 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16373 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16374 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 16375
c19d1205 16376#undef ARM_VARIANT
e74cfd16 16377#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 16378 /* Moves and type conversions. */
5287ad62 16379 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
16380 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16381 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
16382 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16383 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16384 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16385 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
16386 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16387 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16388 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16389 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16390 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16391 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
16392
16393 /* Memory operations. */
4962c51a
MS
16394 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16395 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
16396 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16397 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16398 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16399 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16400 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16401 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16402 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16403 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 16404
c19d1205 16405 /* Monadic operations. */
5287ad62
JB
16406 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16407 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16408 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
16409
16410 /* Dyadic operations. */
5287ad62
JB
16411 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16412 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16413 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16414 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16415 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16416 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16417 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16418 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16419 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 16420
c19d1205 16421 /* Comparisons. */
5287ad62
JB
16422 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16423 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16424 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16425 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
16426
16427#undef ARM_VARIANT
e74cfd16 16428#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
16429 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16430 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
16431 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16432 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16433
037e8744
JB
16434/* Instructions which may belong to either the Neon or VFP instruction sets.
16435 Individual encoder functions perform additional architecture checks. */
16436#undef ARM_VARIANT
16437#define ARM_VARIANT &fpu_vfp_ext_v1xd
16438#undef THUMB_VARIANT
16439#define THUMB_VARIANT &fpu_vfp_ext_v1xd
16440 /* These mnemonics are unique to VFP. */
16441 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16442 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16443 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16444 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16445 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16446 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16447 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16448 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16449 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16450 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16451
16452 /* Mnemonics shared by Neon and VFP. */
16453 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16454 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16455 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16456
16457 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16458 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16459
16460 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16461 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16462
16463 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16464 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16465 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16466 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16467 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16468 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
16469 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16470 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
16471
16472 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
8e79c3df
CM
16473 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16474 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 16475
037e8744
JB
16476
16477 /* NOTE: All VMOV encoding is special-cased! */
16478 NCE(vmov, 0, 1, (VMOV), neon_mov),
16479 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16480
5287ad62
JB
16481#undef THUMB_VARIANT
16482#define THUMB_VARIANT &fpu_neon_ext_v1
16483#undef ARM_VARIANT
16484#define ARM_VARIANT &fpu_neon_ext_v1
16485 /* Data processing with three registers of the same length. */
16486 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16487 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16488 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16489 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16490 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16491 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16492 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16493 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16494 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16495 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
16496 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16497 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
16498 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
16499 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
16500 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16501 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
16502 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
16503 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
16504 /* If not immediate, fall back to neon_dyadic_i64_su.
16505 shl_imm should accept I8 I16 I32 I64,
16506 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
16507 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
16508 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
16509 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
16510 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
16511 /* Logic ops, types optional & ignored. */
16512 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
16513 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
16514 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
16515 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
16516 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
16517 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
16518 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
16519 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
16520 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
16521 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
16522 /* Bitfield ops, untyped. */
16523 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16524 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16525 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16526 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16527 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
16528 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
16529 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
16530 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16531 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16532 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16533 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16534 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
16535 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
16536 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
16537 back to neon_dyadic_if_su. */
16538 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16539 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16540 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16541 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16542 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16543 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16544 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16545 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16546 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16547 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16548 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16549 /* As above, D registers only. */
16550 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16551 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16552 /* Int and float variants, signedness unimportant. */
5287ad62 16553 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16554 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16555 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16556 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16557 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16558 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16559 /* vtst takes sizes 8, 16, 32. */
16560 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16561 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16562 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16563 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16564 /* VQD{R}MULH takes S16 S32. */
16565 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16566 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16567 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16568 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16569 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16570 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16571 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16572 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16573 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16574 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16575 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16576 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16577 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16578 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16579 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16580 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16581
16582 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16583 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16584 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16585
16586 /* Data processing with two registers and a shift amount. */
16587 /* Right shifts, and variants with rounding.
16588 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16589 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16590 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16591 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16592 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16593 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16594 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16595 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16596 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16597 /* Shift and insert. Sizes accepted 8 16 32 64. */
16598 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16599 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16600 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16601 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16602 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16603 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16604 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16605 /* Right shift immediate, saturating & narrowing, with rounding variants.
16606 Types accepted S16 S32 S64 U16 U32 U64. */
16607 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16608 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16609 /* As above, unsigned. Types accepted S16 S32 S64. */
16610 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16611 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16612 /* Right shift narrowing. Types accepted I16 I32 I64. */
16613 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16614 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16615 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16616 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16617 /* CVT with optional immediate for fixed-point variant. */
037e8744 16618 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16619
5287ad62
JB
16620 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16621 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16622
16623 /* Data processing, three registers of different lengths. */
16624 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16625 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16626 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16627 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16628 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16629 /* If not scalar, fall back to neon_dyadic_long.
16630 Vector types as above, scalar types S16 S32 U16 U32. */
16631 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16632 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16633 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16634 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16635 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16636 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16637 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16638 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16639 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16640 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16641 /* Saturating doubling multiplies. Types S16 S32. */
16642 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16643 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16644 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16645 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16646 S16 S32 U16 U32. */
16647 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16648
16649 /* Extract. Size 8. */
3b8d421e
PB
16650 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16651 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16652
16653 /* Two registers, miscellaneous. */
16654 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16655 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16656 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16657 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16658 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16659 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16660 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16661 /* Vector replicate. Sizes 8 16 32. */
16662 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16663 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16664 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16665 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16666 /* VMOVN. Types I16 I32 I64. */
16667 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16668 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16669 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16670 /* VQMOVUN. Types S16 S32 S64. */
16671 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16672 /* VZIP / VUZP. Sizes 8 16 32. */
16673 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16674 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16675 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16676 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16677 /* VQABS / VQNEG. Types S8 S16 S32. */
16678 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16679 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16680 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16681 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16682 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16683 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16684 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16685 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16686 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16687 /* Reciprocal estimates. Types U32 F32. */
16688 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16689 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16690 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16691 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16692 /* VCLS. Types S8 S16 S32. */
16693 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16694 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16695 /* VCLZ. Types I8 I16 I32. */
16696 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16697 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16698 /* VCNT. Size 8. */
16699 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16700 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16701 /* Two address, untyped. */
16702 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16703 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16704 /* VTRN. Sizes 8 16 32. */
16705 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16706 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16707
16708 /* Table lookup. Size 8. */
16709 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16710 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16711
b7fc2769
JB
16712#undef THUMB_VARIANT
16713#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16714#undef ARM_VARIANT
16715#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16716 /* Neon element/structure load/store. */
16717 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16718 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16719 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16720 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16721 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16722 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16723 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16724 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16725
16726#undef THUMB_VARIANT
16727#define THUMB_VARIANT &fpu_vfp_ext_v3
16728#undef ARM_VARIANT
16729#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16730 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16731 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16732 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16733 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16734 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16735 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16736 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16737 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16738 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16739 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16740 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16741 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16742 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16743 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16744 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16745 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16746 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16747 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16748
5287ad62 16749#undef THUMB_VARIANT
c19d1205 16750#undef ARM_VARIANT
e74cfd16 16751#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16752 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16753 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16754 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16755 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16756 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16757 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16758 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16759 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16760
16761#undef ARM_VARIANT
e74cfd16 16762#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16763 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16764 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16765 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16766 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16767 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16768 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16769 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16770 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16771 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16772 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16773 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16774 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16775 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16776 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16777 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16778 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16779 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16780 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16781 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16782 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16783 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16784 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16785 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16786 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16787 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16788 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16789 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16790 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16791 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16792 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16793 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16794 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16795 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16796 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16797 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16798 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16799 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16800 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16801 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16802 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16803 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16804 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16805 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16806 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16807 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16808 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16809 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16810 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16811 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16812 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16813 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16814 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16815 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16816 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16817 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16818 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16819 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16820 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16821 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16822 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16823 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16824 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16825 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16826 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16827 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16828 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16829 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16830 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16831 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16832 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16833 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16834 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16835 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16836 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16837 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16838 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16839 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16840 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16841 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16842 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16843 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16844 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16845 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16846 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16847 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16848 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16849 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16850 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16851 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16852 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16853 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16854 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16855 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16856 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16857 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16858 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16859 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16860 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16861 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16862 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16863 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16864 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16865 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16866 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16867 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16868 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16869 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16870 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16871 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16872 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16873 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16874 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16875 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16876 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16877 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16878 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16879 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16880 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16881 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16882 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16883 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16884 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16885 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16886 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16887 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16888 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16889 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16890 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16891 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16892 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16893 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16894 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16895 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16896 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16897 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16898 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16899 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16900 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16901 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16902 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16903 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16904 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16905 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16906 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16907 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16908 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16909 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16910 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16911 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16912 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16913 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16914 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16915 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16916 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16917 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16918 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16919 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16920 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16921 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16922 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16923 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16924 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16925
2d447fca
JM
16926#undef ARM_VARIANT
16927#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16928 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16929 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16930 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16931 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16932 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16933 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16934 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16935 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16936 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16937 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16938 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16939 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16940 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16941 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16942 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16943 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16944 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16945 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16946 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16947 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16948 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16949 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16950 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16951 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16952 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16953 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16954 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16955 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16956 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16957 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16958 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16959 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16960 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16961 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16962 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16963 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16964 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16965 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16966 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16967 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16968 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16969 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16970 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16971 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16972 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16973 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16974 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16975 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16976 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16977 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16978 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16979 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16980 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16981 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16982 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16983 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16984 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16985
c19d1205 16986#undef ARM_VARIANT
e74cfd16 16987#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16988 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16989 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16990 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16991 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16992 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16993 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16994 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16995 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16996 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16997 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16998 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16999 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17000 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17001 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17002 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17003 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17004 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17005 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17006 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17007 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17008 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17009 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17010 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17011 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17012 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17013 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17014 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17015 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17016 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17017 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17018 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17019 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17020 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17021 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17022 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17023 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17024 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17025 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17026 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17027 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17028 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17029 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17030 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17031 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17032 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17033 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17034 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17035 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17036 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17037 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17038 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17039 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17040 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17041 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17042 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17043 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17044 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17045 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17046 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17047 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17048 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17049 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17050 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17051 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17052 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17053 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17054 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17055 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17056 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17057 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17058 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17059 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17060 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17061 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17062 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17063 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
17064};
17065#undef ARM_VARIANT
17066#undef THUMB_VARIANT
17067#undef TCE
17068#undef TCM
17069#undef TUE
17070#undef TUF
17071#undef TCC
8f06b2d8 17072#undef cCE
e3cb604e
PB
17073#undef cCL
17074#undef C3E
c19d1205
ZW
17075#undef CE
17076#undef CM
17077#undef UE
17078#undef UF
17079#undef UT
5287ad62
JB
17080#undef NUF
17081#undef nUF
17082#undef NCE
17083#undef nCE
c19d1205
ZW
17084#undef OPS0
17085#undef OPS1
17086#undef OPS2
17087#undef OPS3
17088#undef OPS4
17089#undef OPS5
17090#undef OPS6
17091#undef do_0
17092\f
17093/* MD interface: bits in the object file. */
bfae80f2 17094
c19d1205
ZW
17095/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17096 for use in the a.out file, and stores them in the array pointed to by buf.
17097 This knows about the endian-ness of the target machine and does
17098 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17099 2 (short) and 4 (long) Floating numbers are put out as a series of
17100 LITTLENUMS (shorts, here at least). */
b99bd4ef 17101
c19d1205
ZW
17102void
17103md_number_to_chars (char * buf, valueT val, int n)
17104{
17105 if (target_big_endian)
17106 number_to_chars_bigendian (buf, val, n);
17107 else
17108 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
17109}
17110
c19d1205
ZW
17111static valueT
17112md_chars_to_number (char * buf, int n)
bfae80f2 17113{
c19d1205
ZW
17114 valueT result = 0;
17115 unsigned char * where = (unsigned char *) buf;
bfae80f2 17116
c19d1205 17117 if (target_big_endian)
b99bd4ef 17118 {
c19d1205
ZW
17119 while (n--)
17120 {
17121 result <<= 8;
17122 result |= (*where++ & 255);
17123 }
b99bd4ef 17124 }
c19d1205 17125 else
b99bd4ef 17126 {
c19d1205
ZW
17127 while (n--)
17128 {
17129 result <<= 8;
17130 result |= (where[n] & 255);
17131 }
bfae80f2 17132 }
b99bd4ef 17133
c19d1205 17134 return result;
bfae80f2 17135}
b99bd4ef 17136
c19d1205 17137/* MD interface: Sections. */
b99bd4ef 17138
0110f2b8
PB
17139/* Estimate the size of a frag before relaxing. Assume everything fits in
17140 2 bytes. */
17141
c19d1205 17142int
0110f2b8 17143md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
17144 segT segtype ATTRIBUTE_UNUSED)
17145{
0110f2b8
PB
17146 fragp->fr_var = 2;
17147 return 2;
17148}
17149
17150/* Convert a machine dependent frag. */
17151
17152void
17153md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17154{
17155 unsigned long insn;
17156 unsigned long old_op;
17157 char *buf;
17158 expressionS exp;
17159 fixS *fixp;
17160 int reloc_type;
17161 int pc_rel;
17162 int opcode;
17163
17164 buf = fragp->fr_literal + fragp->fr_fix;
17165
17166 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
17167 if (fragp->fr_symbol)
17168 {
0110f2b8
PB
17169 exp.X_op = O_symbol;
17170 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
17171 }
17172 else
17173 {
0110f2b8 17174 exp.X_op = O_constant;
5f4273c7 17175 }
0110f2b8
PB
17176 exp.X_add_number = fragp->fr_offset;
17177 opcode = fragp->fr_subtype;
17178 switch (opcode)
17179 {
17180 case T_MNEM_ldr_pc:
17181 case T_MNEM_ldr_pc2:
17182 case T_MNEM_ldr_sp:
17183 case T_MNEM_str_sp:
17184 case T_MNEM_ldr:
17185 case T_MNEM_ldrb:
17186 case T_MNEM_ldrh:
17187 case T_MNEM_str:
17188 case T_MNEM_strb:
17189 case T_MNEM_strh:
17190 if (fragp->fr_var == 4)
17191 {
5f4273c7 17192 insn = THUMB_OP32 (opcode);
0110f2b8
PB
17193 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17194 {
17195 insn |= (old_op & 0x700) << 4;
17196 }
17197 else
17198 {
17199 insn |= (old_op & 7) << 12;
17200 insn |= (old_op & 0x38) << 13;
17201 }
17202 insn |= 0x00000c00;
17203 put_thumb32_insn (buf, insn);
17204 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17205 }
17206 else
17207 {
17208 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17209 }
17210 pc_rel = (opcode == T_MNEM_ldr_pc2);
17211 break;
17212 case T_MNEM_adr:
17213 if (fragp->fr_var == 4)
17214 {
17215 insn = THUMB_OP32 (opcode);
17216 insn |= (old_op & 0xf0) << 4;
17217 put_thumb32_insn (buf, insn);
17218 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17219 }
17220 else
17221 {
17222 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17223 exp.X_add_number -= 4;
17224 }
17225 pc_rel = 1;
17226 break;
17227 case T_MNEM_mov:
17228 case T_MNEM_movs:
17229 case T_MNEM_cmp:
17230 case T_MNEM_cmn:
17231 if (fragp->fr_var == 4)
17232 {
17233 int r0off = (opcode == T_MNEM_mov
17234 || opcode == T_MNEM_movs) ? 0 : 8;
17235 insn = THUMB_OP32 (opcode);
17236 insn = (insn & 0xe1ffffff) | 0x10000000;
17237 insn |= (old_op & 0x700) << r0off;
17238 put_thumb32_insn (buf, insn);
17239 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17240 }
17241 else
17242 {
17243 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17244 }
17245 pc_rel = 0;
17246 break;
17247 case T_MNEM_b:
17248 if (fragp->fr_var == 4)
17249 {
17250 insn = THUMB_OP32(opcode);
17251 put_thumb32_insn (buf, insn);
17252 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17253 }
17254 else
17255 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17256 pc_rel = 1;
17257 break;
17258 case T_MNEM_bcond:
17259 if (fragp->fr_var == 4)
17260 {
17261 insn = THUMB_OP32(opcode);
17262 insn |= (old_op & 0xf00) << 14;
17263 put_thumb32_insn (buf, insn);
17264 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17265 }
17266 else
17267 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17268 pc_rel = 1;
17269 break;
17270 case T_MNEM_add_sp:
17271 case T_MNEM_add_pc:
17272 case T_MNEM_inc_sp:
17273 case T_MNEM_dec_sp:
17274 if (fragp->fr_var == 4)
17275 {
17276 /* ??? Choose between add and addw. */
17277 insn = THUMB_OP32 (opcode);
17278 insn |= (old_op & 0xf0) << 4;
17279 put_thumb32_insn (buf, insn);
16805f35
PB
17280 if (opcode == T_MNEM_add_pc)
17281 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17282 else
17283 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
17284 }
17285 else
17286 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17287 pc_rel = 0;
17288 break;
17289
17290 case T_MNEM_addi:
17291 case T_MNEM_addis:
17292 case T_MNEM_subi:
17293 case T_MNEM_subis:
17294 if (fragp->fr_var == 4)
17295 {
17296 insn = THUMB_OP32 (opcode);
17297 insn |= (old_op & 0xf0) << 4;
17298 insn |= (old_op & 0xf) << 16;
17299 put_thumb32_insn (buf, insn);
16805f35
PB
17300 if (insn & (1 << 20))
17301 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17302 else
17303 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
17304 }
17305 else
17306 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17307 pc_rel = 0;
17308 break;
17309 default:
5f4273c7 17310 abort ();
0110f2b8
PB
17311 }
17312 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17313 reloc_type);
17314 fixp->fx_file = fragp->fr_file;
17315 fixp->fx_line = fragp->fr_line;
17316 fragp->fr_fix += fragp->fr_var;
17317}
17318
17319/* Return the size of a relaxable immediate operand instruction.
17320 SHIFT and SIZE specify the form of the allowable immediate. */
17321static int
17322relax_immediate (fragS *fragp, int size, int shift)
17323{
17324 offsetT offset;
17325 offsetT mask;
17326 offsetT low;
17327
17328 /* ??? Should be able to do better than this. */
17329 if (fragp->fr_symbol)
17330 return 4;
17331
17332 low = (1 << shift) - 1;
17333 mask = (1 << (shift + size)) - (1 << shift);
17334 offset = fragp->fr_offset;
17335 /* Force misaligned offsets to 32-bit variant. */
17336 if (offset & low)
5e77afaa 17337 return 4;
0110f2b8
PB
17338 if (offset & ~mask)
17339 return 4;
17340 return 2;
17341}
17342
5e77afaa
PB
17343/* Get the address of a symbol during relaxation. */
17344static addressT
5f4273c7 17345relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
17346{
17347 fragS *sym_frag;
17348 addressT addr;
17349 symbolS *sym;
17350
17351 sym = fragp->fr_symbol;
17352 sym_frag = symbol_get_frag (sym);
17353 know (S_GET_SEGMENT (sym) != absolute_section
17354 || sym_frag == &zero_address_frag);
17355 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17356
17357 /* If frag has yet to be reached on this pass, assume it will
17358 move by STRETCH just as we did. If this is not so, it will
17359 be because some frag between grows, and that will force
17360 another pass. */
17361
17362 if (stretch != 0
17363 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
17364 {
17365 fragS *f;
17366
17367 /* Adjust stretch for any alignment frag. Note that if have
17368 been expanding the earlier code, the symbol may be
17369 defined in what appears to be an earlier frag. FIXME:
17370 This doesn't handle the fr_subtype field, which specifies
17371 a maximum number of bytes to skip when doing an
17372 alignment. */
17373 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17374 {
17375 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17376 {
17377 if (stretch < 0)
17378 stretch = - ((- stretch)
17379 & ~ ((1 << (int) f->fr_offset) - 1));
17380 else
17381 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17382 if (stretch == 0)
17383 break;
17384 }
17385 }
17386 if (f != NULL)
17387 addr += stretch;
17388 }
5e77afaa
PB
17389
17390 return addr;
17391}
17392
0110f2b8
PB
17393/* Return the size of a relaxable adr pseudo-instruction or PC-relative
17394 load. */
17395static int
5e77afaa 17396relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
17397{
17398 addressT addr;
17399 offsetT val;
17400
17401 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17402 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17403 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17404 return 4;
17405
5f4273c7 17406 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17407 addr = fragp->fr_address + fragp->fr_fix;
17408 addr = (addr + 4) & ~3;
5e77afaa 17409 /* Force misaligned targets to 32-bit variant. */
0110f2b8 17410 if (val & 3)
5e77afaa 17411 return 4;
0110f2b8
PB
17412 val -= addr;
17413 if (val < 0 || val > 1020)
17414 return 4;
17415 return 2;
17416}
17417
17418/* Return the size of a relaxable add/sub immediate instruction. */
17419static int
17420relax_addsub (fragS *fragp, asection *sec)
17421{
17422 char *buf;
17423 int op;
17424
17425 buf = fragp->fr_literal + fragp->fr_fix;
17426 op = bfd_get_16(sec->owner, buf);
17427 if ((op & 0xf) == ((op >> 4) & 0xf))
17428 return relax_immediate (fragp, 8, 0);
17429 else
17430 return relax_immediate (fragp, 3, 0);
17431}
17432
17433
17434/* Return the size of a relaxable branch instruction. BITS is the
17435 size of the offset field in the narrow instruction. */
17436
17437static int
5e77afaa 17438relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
17439{
17440 addressT addr;
17441 offsetT val;
17442 offsetT limit;
17443
17444 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17445 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17446 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17447 return 4;
17448
267bf995
RR
17449#ifdef OBJ_ELF
17450 if (S_IS_DEFINED (fragp->fr_symbol)
17451 && ARM_IS_FUNC (fragp->fr_symbol))
17452 return 4;
17453#endif
17454
5f4273c7 17455 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17456 addr = fragp->fr_address + fragp->fr_fix + 4;
17457 val -= addr;
17458
17459 /* Offset is a signed value *2 */
17460 limit = 1 << bits;
17461 if (val >= limit || val < -limit)
17462 return 4;
17463 return 2;
17464}
17465
17466
17467/* Relax a machine dependent frag. This returns the amount by which
17468 the current size of the frag should change. */
17469
17470int
5e77afaa 17471arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
17472{
17473 int oldsize;
17474 int newsize;
17475
17476 oldsize = fragp->fr_var;
17477 switch (fragp->fr_subtype)
17478 {
17479 case T_MNEM_ldr_pc2:
5f4273c7 17480 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17481 break;
17482 case T_MNEM_ldr_pc:
17483 case T_MNEM_ldr_sp:
17484 case T_MNEM_str_sp:
5f4273c7 17485 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
17486 break;
17487 case T_MNEM_ldr:
17488 case T_MNEM_str:
5f4273c7 17489 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
17490 break;
17491 case T_MNEM_ldrh:
17492 case T_MNEM_strh:
5f4273c7 17493 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
17494 break;
17495 case T_MNEM_ldrb:
17496 case T_MNEM_strb:
5f4273c7 17497 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
17498 break;
17499 case T_MNEM_adr:
5f4273c7 17500 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17501 break;
17502 case T_MNEM_mov:
17503 case T_MNEM_movs:
17504 case T_MNEM_cmp:
17505 case T_MNEM_cmn:
5f4273c7 17506 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
17507 break;
17508 case T_MNEM_b:
5f4273c7 17509 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
17510 break;
17511 case T_MNEM_bcond:
5f4273c7 17512 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
17513 break;
17514 case T_MNEM_add_sp:
17515 case T_MNEM_add_pc:
17516 newsize = relax_immediate (fragp, 8, 2);
17517 break;
17518 case T_MNEM_inc_sp:
17519 case T_MNEM_dec_sp:
17520 newsize = relax_immediate (fragp, 7, 2);
17521 break;
17522 case T_MNEM_addi:
17523 case T_MNEM_addis:
17524 case T_MNEM_subi:
17525 case T_MNEM_subis:
17526 newsize = relax_addsub (fragp, sec);
17527 break;
17528 default:
5f4273c7 17529 abort ();
0110f2b8 17530 }
5e77afaa
PB
17531
17532 fragp->fr_var = newsize;
17533 /* Freeze wide instructions that are at or before the same location as
17534 in the previous pass. This avoids infinite loops.
5f4273c7
NC
17535 Don't freeze them unconditionally because targets may be artificially
17536 misaligned by the expansion of preceding frags. */
5e77afaa 17537 if (stretch <= 0 && newsize > 2)
0110f2b8 17538 {
0110f2b8 17539 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 17540 frag_wane (fragp);
0110f2b8 17541 }
5e77afaa 17542
0110f2b8 17543 return newsize - oldsize;
c19d1205 17544}
b99bd4ef 17545
c19d1205 17546/* Round up a section size to the appropriate boundary. */
b99bd4ef 17547
c19d1205
ZW
17548valueT
17549md_section_align (segT segment ATTRIBUTE_UNUSED,
17550 valueT size)
17551{
f0927246
NC
17552#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
17553 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
17554 {
17555 /* For a.out, force the section size to be aligned. If we don't do
17556 this, BFD will align it for us, but it will not write out the
17557 final bytes of the section. This may be a bug in BFD, but it is
17558 easier to fix it here since that is how the other a.out targets
17559 work. */
17560 int align;
17561
17562 align = bfd_get_section_alignment (stdoutput, segment);
17563 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
17564 }
c19d1205 17565#endif
f0927246
NC
17566
17567 return size;
bfae80f2 17568}
b99bd4ef 17569
c19d1205
ZW
17570/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
17571 of an rs_align_code fragment. */
17572
17573void
17574arm_handle_align (fragS * fragP)
bfae80f2 17575{
e7495e45
NS
17576 static char const arm_noop[2][2][4] =
17577 {
17578 { /* ARMv1 */
17579 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
17580 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
17581 },
17582 { /* ARMv6k */
17583 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
17584 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
17585 },
17586 };
17587 static char const thumb_noop[2][2][2] =
17588 {
17589 { /* Thumb-1 */
17590 {0xc0, 0x46}, /* LE */
17591 {0x46, 0xc0}, /* BE */
17592 },
17593 { /* Thumb-2 */
17594 {0x00, 0xbf}, /* LE */
17595 {0xbf, 0x00} /* BE */
17596 }
17597 };
17598 static char const wide_thumb_noop[2][4] =
17599 { /* Wide Thumb-2 */
17600 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
17601 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
17602 };
17603
17604 unsigned bytes, fix, noop_size;
c19d1205
ZW
17605 char * p;
17606 const char * noop;
e7495e45 17607 const char *narrow_noop = NULL;
bfae80f2 17608
c19d1205 17609 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17610 return;
17611
c19d1205
ZW
17612 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17613 p = fragP->fr_literal + fragP->fr_fix;
17614 fix = 0;
bfae80f2 17615
c19d1205
ZW
17616 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17617 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17618
8dc2430f
NC
17619 assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
17620
17621 if (fragP->tc_frag_data & (~ MODE_RECORDED))
a737bd4d 17622 {
e7495e45
NS
17623 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
17624 {
17625 narrow_noop = thumb_noop[1][target_big_endian];
17626 noop = wide_thumb_noop[target_big_endian];
17627 }
c19d1205 17628 else
e7495e45
NS
17629 noop = thumb_noop[0][target_big_endian];
17630 noop_size = 2;
7ed4c4c5
NC
17631 }
17632 else
17633 {
e7495e45
NS
17634 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
17635 [target_big_endian];
17636 noop_size = 4;
7ed4c4c5 17637 }
e7495e45
NS
17638
17639 fragP->fr_var = noop_size;
17640
c19d1205 17641 if (bytes & (noop_size - 1))
7ed4c4c5 17642 {
c19d1205
ZW
17643 fix = bytes & (noop_size - 1);
17644 memset (p, 0, fix);
17645 p += fix;
17646 bytes -= fix;
a737bd4d 17647 }
a737bd4d 17648
e7495e45
NS
17649 if (narrow_noop)
17650 {
17651 if (bytes & noop_size)
17652 {
17653 /* Insert a narrow noop. */
17654 memcpy (p, narrow_noop, noop_size);
17655 p += noop_size;
17656 bytes -= noop_size;
17657 fix += noop_size;
17658 }
17659
17660 /* Use wide noops for the remainder */
17661 noop_size = 4;
17662 }
17663
c19d1205 17664 while (bytes >= noop_size)
a737bd4d 17665 {
c19d1205
ZW
17666 memcpy (p, noop, noop_size);
17667 p += noop_size;
17668 bytes -= noop_size;
17669 fix += noop_size;
a737bd4d
NC
17670 }
17671
c19d1205 17672 fragP->fr_fix += fix;
a737bd4d
NC
17673}
17674
c19d1205
ZW
17675/* Called from md_do_align. Used to create an alignment
17676 frag in a code section. */
17677
17678void
17679arm_frag_align_code (int n, int max)
bfae80f2 17680{
c19d1205 17681 char * p;
7ed4c4c5 17682
c19d1205
ZW
17683 /* We assume that there will never be a requirement
17684 to support alignments greater than 32 bytes. */
17685 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17686 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17687
c19d1205
ZW
17688 p = frag_var (rs_align_code,
17689 MAX_MEM_FOR_RS_ALIGN_CODE,
17690 1,
17691 (relax_substateT) max,
17692 (symbolS *) NULL,
17693 (offsetT) n,
17694 (char *) NULL);
17695 *p = 0;
17696}
bfae80f2 17697
8dc2430f
NC
17698/* Perform target specific initialisation of a frag.
17699 Note - despite the name this initialisation is not done when the frag
17700 is created, but only when its type is assigned. A frag can be created
17701 and used a long time before its type is set, so beware of assuming that
17702 this initialisationis performed first. */
bfae80f2 17703
c19d1205
ZW
17704void
17705arm_init_frag (fragS * fragP)
17706{
8dc2430f
NC
17707 /* If the current ARM vs THUMB mode has not already
17708 been recorded into this frag then do so now. */
17709 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
17710 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
bfae80f2
RE
17711}
17712
c19d1205
ZW
17713#ifdef OBJ_ELF
17714/* When we change sections we need to issue a new mapping symbol. */
17715
17716void
17717arm_elf_change_section (void)
bfae80f2 17718{
c19d1205
ZW
17719 flagword flags;
17720 segment_info_type *seginfo;
bfae80f2 17721
c19d1205
ZW
17722 /* Link an unlinked unwind index table section to the .text section. */
17723 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17724 && elf_linked_to_section (now_seg) == NULL)
17725 elf_linked_to_section (now_seg) = text_section;
17726
17727 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17728 return;
17729
c19d1205
ZW
17730 flags = bfd_get_section_flags (stdoutput, now_seg);
17731
17732 /* We can ignore sections that only contain debug info. */
17733 if ((flags & SEC_ALLOC) == 0)
17734 return;
bfae80f2 17735
c19d1205
ZW
17736 seginfo = seg_info (now_seg);
17737 mapstate = seginfo->tc_segment_info_data.mapstate;
17738 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17739}
17740
c19d1205
ZW
17741int
17742arm_elf_section_type (const char * str, size_t len)
e45d0630 17743{
c19d1205
ZW
17744 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17745 return SHT_ARM_EXIDX;
e45d0630 17746
c19d1205
ZW
17747 return -1;
17748}
17749\f
17750/* Code to deal with unwinding tables. */
e45d0630 17751
c19d1205 17752static void add_unwind_adjustsp (offsetT);
e45d0630 17753
5f4273c7 17754/* Generate any deferred unwind frame offset. */
e45d0630 17755
bfae80f2 17756static void
c19d1205 17757flush_pending_unwind (void)
bfae80f2 17758{
c19d1205 17759 offsetT offset;
bfae80f2 17760
c19d1205
ZW
17761 offset = unwind.pending_offset;
17762 unwind.pending_offset = 0;
17763 if (offset != 0)
17764 add_unwind_adjustsp (offset);
bfae80f2
RE
17765}
17766
c19d1205
ZW
17767/* Add an opcode to this list for this function. Two-byte opcodes should
17768 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17769 order. */
17770
bfae80f2 17771static void
c19d1205 17772add_unwind_opcode (valueT op, int length)
bfae80f2 17773{
c19d1205
ZW
17774 /* Add any deferred stack adjustment. */
17775 if (unwind.pending_offset)
17776 flush_pending_unwind ();
bfae80f2 17777
c19d1205 17778 unwind.sp_restored = 0;
bfae80f2 17779
c19d1205 17780 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17781 {
c19d1205
ZW
17782 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17783 if (unwind.opcodes)
17784 unwind.opcodes = xrealloc (unwind.opcodes,
17785 unwind.opcode_alloc);
17786 else
17787 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17788 }
c19d1205 17789 while (length > 0)
bfae80f2 17790 {
c19d1205
ZW
17791 length--;
17792 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17793 op >>= 8;
17794 unwind.opcode_count++;
bfae80f2 17795 }
bfae80f2
RE
17796}
17797
c19d1205
ZW
17798/* Add unwind opcodes to adjust the stack pointer. */
17799
bfae80f2 17800static void
c19d1205 17801add_unwind_adjustsp (offsetT offset)
bfae80f2 17802{
c19d1205 17803 valueT op;
bfae80f2 17804
c19d1205 17805 if (offset > 0x200)
bfae80f2 17806 {
c19d1205
ZW
17807 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17808 char bytes[5];
17809 int n;
17810 valueT o;
bfae80f2 17811
c19d1205
ZW
17812 /* Long form: 0xb2, uleb128. */
17813 /* This might not fit in a word so add the individual bytes,
17814 remembering the list is built in reverse order. */
17815 o = (valueT) ((offset - 0x204) >> 2);
17816 if (o == 0)
17817 add_unwind_opcode (0, 1);
bfae80f2 17818
c19d1205
ZW
17819 /* Calculate the uleb128 encoding of the offset. */
17820 n = 0;
17821 while (o)
17822 {
17823 bytes[n] = o & 0x7f;
17824 o >>= 7;
17825 if (o)
17826 bytes[n] |= 0x80;
17827 n++;
17828 }
17829 /* Add the insn. */
17830 for (; n; n--)
17831 add_unwind_opcode (bytes[n - 1], 1);
17832 add_unwind_opcode (0xb2, 1);
17833 }
17834 else if (offset > 0x100)
bfae80f2 17835 {
c19d1205
ZW
17836 /* Two short opcodes. */
17837 add_unwind_opcode (0x3f, 1);
17838 op = (offset - 0x104) >> 2;
17839 add_unwind_opcode (op, 1);
bfae80f2 17840 }
c19d1205
ZW
17841 else if (offset > 0)
17842 {
17843 /* Short opcode. */
17844 op = (offset - 4) >> 2;
17845 add_unwind_opcode (op, 1);
17846 }
17847 else if (offset < 0)
bfae80f2 17848 {
c19d1205
ZW
17849 offset = -offset;
17850 while (offset > 0x100)
bfae80f2 17851 {
c19d1205
ZW
17852 add_unwind_opcode (0x7f, 1);
17853 offset -= 0x100;
bfae80f2 17854 }
c19d1205
ZW
17855 op = ((offset - 4) >> 2) | 0x40;
17856 add_unwind_opcode (op, 1);
bfae80f2 17857 }
bfae80f2
RE
17858}
17859
c19d1205
ZW
17860/* Finish the list of unwind opcodes for this function. */
17861static void
17862finish_unwind_opcodes (void)
bfae80f2 17863{
c19d1205 17864 valueT op;
bfae80f2 17865
c19d1205 17866 if (unwind.fp_used)
bfae80f2 17867 {
708587a4 17868 /* Adjust sp as necessary. */
c19d1205
ZW
17869 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17870 flush_pending_unwind ();
bfae80f2 17871
c19d1205
ZW
17872 /* After restoring sp from the frame pointer. */
17873 op = 0x90 | unwind.fp_reg;
17874 add_unwind_opcode (op, 1);
17875 }
17876 else
17877 flush_pending_unwind ();
bfae80f2
RE
17878}
17879
bfae80f2 17880
c19d1205
ZW
17881/* Start an exception table entry. If idx is nonzero this is an index table
17882 entry. */
bfae80f2
RE
17883
17884static void
c19d1205 17885start_unwind_section (const segT text_seg, int idx)
bfae80f2 17886{
c19d1205
ZW
17887 const char * text_name;
17888 const char * prefix;
17889 const char * prefix_once;
17890 const char * group_name;
17891 size_t prefix_len;
17892 size_t text_len;
17893 char * sec_name;
17894 size_t sec_name_len;
17895 int type;
17896 int flags;
17897 int linkonce;
bfae80f2 17898
c19d1205 17899 if (idx)
bfae80f2 17900 {
c19d1205
ZW
17901 prefix = ELF_STRING_ARM_unwind;
17902 prefix_once = ELF_STRING_ARM_unwind_once;
17903 type = SHT_ARM_EXIDX;
bfae80f2 17904 }
c19d1205 17905 else
bfae80f2 17906 {
c19d1205
ZW
17907 prefix = ELF_STRING_ARM_unwind_info;
17908 prefix_once = ELF_STRING_ARM_unwind_info_once;
17909 type = SHT_PROGBITS;
bfae80f2
RE
17910 }
17911
c19d1205
ZW
17912 text_name = segment_name (text_seg);
17913 if (streq (text_name, ".text"))
17914 text_name = "";
17915
17916 if (strncmp (text_name, ".gnu.linkonce.t.",
17917 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17918 {
c19d1205
ZW
17919 prefix = prefix_once;
17920 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17921 }
17922
c19d1205
ZW
17923 prefix_len = strlen (prefix);
17924 text_len = strlen (text_name);
17925 sec_name_len = prefix_len + text_len;
17926 sec_name = xmalloc (sec_name_len + 1);
17927 memcpy (sec_name, prefix, prefix_len);
17928 memcpy (sec_name + prefix_len, text_name, text_len);
17929 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17930
c19d1205
ZW
17931 flags = SHF_ALLOC;
17932 linkonce = 0;
17933 group_name = 0;
bfae80f2 17934
c19d1205
ZW
17935 /* Handle COMDAT group. */
17936 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17937 {
c19d1205
ZW
17938 group_name = elf_group_name (text_seg);
17939 if (group_name == NULL)
17940 {
bd3ba5d1 17941 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
17942 segment_name (text_seg));
17943 ignore_rest_of_line ();
17944 return;
17945 }
17946 flags |= SHF_GROUP;
17947 linkonce = 1;
bfae80f2
RE
17948 }
17949
c19d1205 17950 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17951
5f4273c7 17952 /* Set the section link for index tables. */
c19d1205
ZW
17953 if (idx)
17954 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17955}
17956
bfae80f2 17957
c19d1205
ZW
17958/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17959 personality routine data. Returns zero, or the index table value for
17960 and inline entry. */
17961
17962static valueT
17963create_unwind_entry (int have_data)
bfae80f2 17964{
c19d1205
ZW
17965 int size;
17966 addressT where;
17967 char *ptr;
17968 /* The current word of data. */
17969 valueT data;
17970 /* The number of bytes left in this word. */
17971 int n;
bfae80f2 17972
c19d1205 17973 finish_unwind_opcodes ();
bfae80f2 17974
c19d1205
ZW
17975 /* Remember the current text section. */
17976 unwind.saved_seg = now_seg;
17977 unwind.saved_subseg = now_subseg;
bfae80f2 17978
c19d1205 17979 start_unwind_section (now_seg, 0);
bfae80f2 17980
c19d1205 17981 if (unwind.personality_routine == NULL)
bfae80f2 17982 {
c19d1205
ZW
17983 if (unwind.personality_index == -2)
17984 {
17985 if (have_data)
5f4273c7 17986 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
17987 return 1; /* EXIDX_CANTUNWIND. */
17988 }
bfae80f2 17989
c19d1205
ZW
17990 /* Use a default personality routine if none is specified. */
17991 if (unwind.personality_index == -1)
17992 {
17993 if (unwind.opcode_count > 3)
17994 unwind.personality_index = 1;
17995 else
17996 unwind.personality_index = 0;
17997 }
bfae80f2 17998
c19d1205
ZW
17999 /* Space for the personality routine entry. */
18000 if (unwind.personality_index == 0)
18001 {
18002 if (unwind.opcode_count > 3)
18003 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 18004
c19d1205
ZW
18005 if (!have_data)
18006 {
18007 /* All the data is inline in the index table. */
18008 data = 0x80;
18009 n = 3;
18010 while (unwind.opcode_count > 0)
18011 {
18012 unwind.opcode_count--;
18013 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18014 n--;
18015 }
bfae80f2 18016
c19d1205
ZW
18017 /* Pad with "finish" opcodes. */
18018 while (n--)
18019 data = (data << 8) | 0xb0;
bfae80f2 18020
c19d1205
ZW
18021 return data;
18022 }
18023 size = 0;
18024 }
18025 else
18026 /* We get two opcodes "free" in the first word. */
18027 size = unwind.opcode_count - 2;
18028 }
18029 else
18030 /* An extra byte is required for the opcode count. */
18031 size = unwind.opcode_count + 1;
bfae80f2 18032
c19d1205
ZW
18033 size = (size + 3) >> 2;
18034 if (size > 0xff)
18035 as_bad (_("too many unwind opcodes"));
bfae80f2 18036
c19d1205
ZW
18037 frag_align (2, 0, 0);
18038 record_alignment (now_seg, 2);
18039 unwind.table_entry = expr_build_dot ();
18040
18041 /* Allocate the table entry. */
18042 ptr = frag_more ((size << 2) + 4);
18043 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 18044
c19d1205 18045 switch (unwind.personality_index)
bfae80f2 18046 {
c19d1205
ZW
18047 case -1:
18048 /* ??? Should this be a PLT generating relocation? */
18049 /* Custom personality routine. */
18050 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18051 BFD_RELOC_ARM_PREL31);
bfae80f2 18052
c19d1205
ZW
18053 where += 4;
18054 ptr += 4;
bfae80f2 18055
c19d1205
ZW
18056 /* Set the first byte to the number of additional words. */
18057 data = size - 1;
18058 n = 3;
18059 break;
bfae80f2 18060
c19d1205
ZW
18061 /* ABI defined personality routines. */
18062 case 0:
18063 /* Three opcodes bytes are packed into the first word. */
18064 data = 0x80;
18065 n = 3;
18066 break;
bfae80f2 18067
c19d1205
ZW
18068 case 1:
18069 case 2:
18070 /* The size and first two opcode bytes go in the first word. */
18071 data = ((0x80 + unwind.personality_index) << 8) | size;
18072 n = 2;
18073 break;
bfae80f2 18074
c19d1205
ZW
18075 default:
18076 /* Should never happen. */
18077 abort ();
18078 }
bfae80f2 18079
c19d1205
ZW
18080 /* Pack the opcodes into words (MSB first), reversing the list at the same
18081 time. */
18082 while (unwind.opcode_count > 0)
18083 {
18084 if (n == 0)
18085 {
18086 md_number_to_chars (ptr, data, 4);
18087 ptr += 4;
18088 n = 4;
18089 data = 0;
18090 }
18091 unwind.opcode_count--;
18092 n--;
18093 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18094 }
18095
18096 /* Finish off the last word. */
18097 if (n < 4)
18098 {
18099 /* Pad with "finish" opcodes. */
18100 while (n--)
18101 data = (data << 8) | 0xb0;
18102
18103 md_number_to_chars (ptr, data, 4);
18104 }
18105
18106 if (!have_data)
18107 {
18108 /* Add an empty descriptor if there is no user-specified data. */
18109 ptr = frag_more (4);
18110 md_number_to_chars (ptr, 0, 4);
18111 }
18112
18113 return 0;
bfae80f2
RE
18114}
18115
f0927246
NC
18116
18117/* Initialize the DWARF-2 unwind information for this procedure. */
18118
18119void
18120tc_arm_frame_initial_instructions (void)
18121{
18122 cfi_add_CFA_def_cfa (REG_SP, 0);
18123}
18124#endif /* OBJ_ELF */
18125
c19d1205
ZW
18126/* Convert REGNAME to a DWARF-2 register number. */
18127
18128int
1df69f4f 18129tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 18130{
1df69f4f 18131 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
18132
18133 if (reg == FAIL)
18134 return -1;
18135
18136 return reg;
bfae80f2
RE
18137}
18138
f0927246 18139#ifdef TE_PE
c19d1205 18140void
f0927246 18141tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 18142{
f0927246 18143 expressionS expr;
bfae80f2 18144
f0927246
NC
18145 expr.X_op = O_secrel;
18146 expr.X_add_symbol = symbol;
18147 expr.X_add_number = 0;
18148 emit_expr (&expr, size);
18149}
18150#endif
bfae80f2 18151
c19d1205 18152/* MD interface: Symbol and relocation handling. */
bfae80f2 18153
2fc8bdac
ZW
18154/* Return the address within the segment that a PC-relative fixup is
18155 relative to. For ARM, PC-relative fixups applied to instructions
18156 are generally relative to the location of the fixup plus 8 bytes.
18157 Thumb branches are offset by 4, and Thumb loads relative to PC
18158 require special handling. */
bfae80f2 18159
c19d1205 18160long
2fc8bdac 18161md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 18162{
2fc8bdac
ZW
18163 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18164
18165 /* If this is pc-relative and we are going to emit a relocation
18166 then we just want to put out any pipeline compensation that the linker
53baae48
NC
18167 will need. Otherwise we want to use the calculated base.
18168 For WinCE we skip the bias for externals as well, since this
18169 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 18170 if (fixP->fx_pcrel
2fc8bdac 18171 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
18172 || (arm_force_relocation (fixP)
18173#ifdef TE_WINCE
18174 && !S_IS_EXTERNAL (fixP->fx_addsy)
18175#endif
18176 )))
2fc8bdac 18177 base = 0;
bfae80f2 18178
267bf995 18179
c19d1205 18180 switch (fixP->fx_r_type)
bfae80f2 18181 {
2fc8bdac
ZW
18182 /* PC relative addressing on the Thumb is slightly odd as the
18183 bottom two bits of the PC are forced to zero for the
18184 calculation. This happens *after* application of the
18185 pipeline offset. However, Thumb adrl already adjusts for
18186 this, so we need not do it again. */
c19d1205 18187 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 18188 return base & ~3;
c19d1205
ZW
18189
18190 case BFD_RELOC_ARM_THUMB_OFFSET:
18191 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 18192 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 18193 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 18194 return (base + 4) & ~3;
c19d1205 18195
2fc8bdac
ZW
18196 /* Thumb branches are simply offset by +4. */
18197 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18198 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18199 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18200 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 18201 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 18202 return base + 4;
bfae80f2 18203
267bf995
RR
18204 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18205 if (fixP->fx_addsy
18206 && ARM_IS_FUNC (fixP->fx_addsy)
18207 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18208 base = fixP->fx_where + fixP->fx_frag->fr_address;
18209 return base + 4;
18210
00adf2d4
JB
18211 /* BLX is like branches above, but forces the low two bits of PC to
18212 zero. */
267bf995
RR
18213 case BFD_RELOC_THUMB_PCREL_BLX:
18214 if (fixP->fx_addsy
18215 && THUMB_IS_FUNC (fixP->fx_addsy)
18216 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18217 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
18218 return (base + 4) & ~3;
18219
2fc8bdac
ZW
18220 /* ARM mode branches are offset by +8. However, the Windows CE
18221 loader expects the relocation not to take this into account. */
267bf995
RR
18222 case BFD_RELOC_ARM_PCREL_BLX:
18223 if (fixP->fx_addsy
18224 && ARM_IS_FUNC (fixP->fx_addsy)
18225 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18226 base = fixP->fx_where + fixP->fx_frag->fr_address;
18227 return base + 8;
18228
18229 case BFD_RELOC_ARM_PCREL_CALL:
18230 if (fixP->fx_addsy
18231 && THUMB_IS_FUNC (fixP->fx_addsy)
18232 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18233 base = fixP->fx_where + fixP->fx_frag->fr_address;
18234 return base + 8;
18235
2fc8bdac 18236 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 18237 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18238 case BFD_RELOC_ARM_PLT32:
c19d1205 18239#ifdef TE_WINCE
5f4273c7 18240 /* When handling fixups immediately, because we have already
53baae48
NC
18241 discovered the value of a symbol, or the address of the frag involved
18242 we must account for the offset by +8, as the OS loader will never see the reloc.
18243 see fixup_segment() in write.c
18244 The S_IS_EXTERNAL test handles the case of global symbols.
18245 Those need the calculated base, not just the pipe compensation the linker will need. */
18246 if (fixP->fx_pcrel
18247 && fixP->fx_addsy != NULL
18248 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18249 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18250 return base + 8;
2fc8bdac 18251 return base;
c19d1205 18252#else
2fc8bdac 18253 return base + 8;
c19d1205 18254#endif
2fc8bdac 18255
267bf995 18256
2fc8bdac
ZW
18257 /* ARM mode loads relative to PC are also offset by +8. Unlike
18258 branches, the Windows CE loader *does* expect the relocation
18259 to take this into account. */
18260 case BFD_RELOC_ARM_OFFSET_IMM:
18261 case BFD_RELOC_ARM_OFFSET_IMM8:
18262 case BFD_RELOC_ARM_HWLITERAL:
18263 case BFD_RELOC_ARM_LITERAL:
18264 case BFD_RELOC_ARM_CP_OFF_IMM:
18265 return base + 8;
18266
18267
18268 /* Other PC-relative relocations are un-offset. */
18269 default:
18270 return base;
18271 }
bfae80f2
RE
18272}
18273
c19d1205
ZW
18274/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18275 Otherwise we have no need to default values of symbols. */
18276
18277symbolS *
18278md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 18279{
c19d1205
ZW
18280#ifdef OBJ_ELF
18281 if (name[0] == '_' && name[1] == 'G'
18282 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18283 {
18284 if (!GOT_symbol)
18285 {
18286 if (symbol_find (name))
bd3ba5d1 18287 as_bad (_("GOT already in the symbol table"));
bfae80f2 18288
c19d1205
ZW
18289 GOT_symbol = symbol_new (name, undefined_section,
18290 (valueT) 0, & zero_address_frag);
18291 }
bfae80f2 18292
c19d1205 18293 return GOT_symbol;
bfae80f2 18294 }
c19d1205 18295#endif
bfae80f2 18296
c19d1205 18297 return 0;
bfae80f2
RE
18298}
18299
55cf6793 18300/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
18301 computed as two separate immediate values, added together. We
18302 already know that this value cannot be computed by just one ARM
18303 instruction. */
18304
18305static unsigned int
18306validate_immediate_twopart (unsigned int val,
18307 unsigned int * highpart)
bfae80f2 18308{
c19d1205
ZW
18309 unsigned int a;
18310 unsigned int i;
bfae80f2 18311
c19d1205
ZW
18312 for (i = 0; i < 32; i += 2)
18313 if (((a = rotate_left (val, i)) & 0xff) != 0)
18314 {
18315 if (a & 0xff00)
18316 {
18317 if (a & ~ 0xffff)
18318 continue;
18319 * highpart = (a >> 8) | ((i + 24) << 7);
18320 }
18321 else if (a & 0xff0000)
18322 {
18323 if (a & 0xff000000)
18324 continue;
18325 * highpart = (a >> 16) | ((i + 16) << 7);
18326 }
18327 else
18328 {
18329 assert (a & 0xff000000);
18330 * highpart = (a >> 24) | ((i + 8) << 7);
18331 }
bfae80f2 18332
c19d1205
ZW
18333 return (a & 0xff) | (i << 7);
18334 }
bfae80f2 18335
c19d1205 18336 return FAIL;
bfae80f2
RE
18337}
18338
c19d1205
ZW
18339static int
18340validate_offset_imm (unsigned int val, int hwse)
18341{
18342 if ((hwse && val > 255) || val > 4095)
18343 return FAIL;
18344 return val;
18345}
bfae80f2 18346
55cf6793 18347/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
18348 negative immediate constant by altering the instruction. A bit of
18349 a hack really.
18350 MOV <-> MVN
18351 AND <-> BIC
18352 ADC <-> SBC
18353 by inverting the second operand, and
18354 ADD <-> SUB
18355 CMP <-> CMN
18356 by negating the second operand. */
bfae80f2 18357
c19d1205
ZW
18358static int
18359negate_data_op (unsigned long * instruction,
18360 unsigned long value)
bfae80f2 18361{
c19d1205
ZW
18362 int op, new_inst;
18363 unsigned long negated, inverted;
bfae80f2 18364
c19d1205
ZW
18365 negated = encode_arm_immediate (-value);
18366 inverted = encode_arm_immediate (~value);
bfae80f2 18367
c19d1205
ZW
18368 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18369 switch (op)
bfae80f2 18370 {
c19d1205
ZW
18371 /* First negates. */
18372 case OPCODE_SUB: /* ADD <-> SUB */
18373 new_inst = OPCODE_ADD;
18374 value = negated;
18375 break;
bfae80f2 18376
c19d1205
ZW
18377 case OPCODE_ADD:
18378 new_inst = OPCODE_SUB;
18379 value = negated;
18380 break;
bfae80f2 18381
c19d1205
ZW
18382 case OPCODE_CMP: /* CMP <-> CMN */
18383 new_inst = OPCODE_CMN;
18384 value = negated;
18385 break;
bfae80f2 18386
c19d1205
ZW
18387 case OPCODE_CMN:
18388 new_inst = OPCODE_CMP;
18389 value = negated;
18390 break;
bfae80f2 18391
c19d1205
ZW
18392 /* Now Inverted ops. */
18393 case OPCODE_MOV: /* MOV <-> MVN */
18394 new_inst = OPCODE_MVN;
18395 value = inverted;
18396 break;
bfae80f2 18397
c19d1205
ZW
18398 case OPCODE_MVN:
18399 new_inst = OPCODE_MOV;
18400 value = inverted;
18401 break;
bfae80f2 18402
c19d1205
ZW
18403 case OPCODE_AND: /* AND <-> BIC */
18404 new_inst = OPCODE_BIC;
18405 value = inverted;
18406 break;
bfae80f2 18407
c19d1205
ZW
18408 case OPCODE_BIC:
18409 new_inst = OPCODE_AND;
18410 value = inverted;
18411 break;
bfae80f2 18412
c19d1205
ZW
18413 case OPCODE_ADC: /* ADC <-> SBC */
18414 new_inst = OPCODE_SBC;
18415 value = inverted;
18416 break;
bfae80f2 18417
c19d1205
ZW
18418 case OPCODE_SBC:
18419 new_inst = OPCODE_ADC;
18420 value = inverted;
18421 break;
bfae80f2 18422
c19d1205
ZW
18423 /* We cannot do anything. */
18424 default:
18425 return FAIL;
b99bd4ef
NC
18426 }
18427
c19d1205
ZW
18428 if (value == (unsigned) FAIL)
18429 return FAIL;
18430
18431 *instruction &= OPCODE_MASK;
18432 *instruction |= new_inst << DATA_OP_SHIFT;
18433 return value;
b99bd4ef
NC
18434}
18435
ef8d22e6
PB
18436/* Like negate_data_op, but for Thumb-2. */
18437
18438static unsigned int
16dd5e42 18439thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
18440{
18441 int op, new_inst;
18442 int rd;
16dd5e42 18443 unsigned int negated, inverted;
ef8d22e6
PB
18444
18445 negated = encode_thumb32_immediate (-value);
18446 inverted = encode_thumb32_immediate (~value);
18447
18448 rd = (*instruction >> 8) & 0xf;
18449 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18450 switch (op)
18451 {
18452 /* ADD <-> SUB. Includes CMP <-> CMN. */
18453 case T2_OPCODE_SUB:
18454 new_inst = T2_OPCODE_ADD;
18455 value = negated;
18456 break;
18457
18458 case T2_OPCODE_ADD:
18459 new_inst = T2_OPCODE_SUB;
18460 value = negated;
18461 break;
18462
18463 /* ORR <-> ORN. Includes MOV <-> MVN. */
18464 case T2_OPCODE_ORR:
18465 new_inst = T2_OPCODE_ORN;
18466 value = inverted;
18467 break;
18468
18469 case T2_OPCODE_ORN:
18470 new_inst = T2_OPCODE_ORR;
18471 value = inverted;
18472 break;
18473
18474 /* AND <-> BIC. TST has no inverted equivalent. */
18475 case T2_OPCODE_AND:
18476 new_inst = T2_OPCODE_BIC;
18477 if (rd == 15)
18478 value = FAIL;
18479 else
18480 value = inverted;
18481 break;
18482
18483 case T2_OPCODE_BIC:
18484 new_inst = T2_OPCODE_AND;
18485 value = inverted;
18486 break;
18487
18488 /* ADC <-> SBC */
18489 case T2_OPCODE_ADC:
18490 new_inst = T2_OPCODE_SBC;
18491 value = inverted;
18492 break;
18493
18494 case T2_OPCODE_SBC:
18495 new_inst = T2_OPCODE_ADC;
18496 value = inverted;
18497 break;
18498
18499 /* We cannot do anything. */
18500 default:
18501 return FAIL;
18502 }
18503
16dd5e42 18504 if (value == (unsigned int)FAIL)
ef8d22e6
PB
18505 return FAIL;
18506
18507 *instruction &= T2_OPCODE_MASK;
18508 *instruction |= new_inst << T2_DATA_OP_SHIFT;
18509 return value;
18510}
18511
8f06b2d8
PB
18512/* Read a 32-bit thumb instruction from buf. */
18513static unsigned long
18514get_thumb32_insn (char * buf)
18515{
18516 unsigned long insn;
18517 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
18518 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18519
18520 return insn;
18521}
18522
a8bc6c78
PB
18523
18524/* We usually want to set the low bit on the address of thumb function
18525 symbols. In particular .word foo - . should have the low bit set.
18526 Generic code tries to fold the difference of two symbols to
18527 a constant. Prevent this and force a relocation when the first symbols
18528 is a thumb function. */
18529int
18530arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
18531{
18532 if (op == O_subtract
18533 && l->X_op == O_symbol
18534 && r->X_op == O_symbol
18535 && THUMB_IS_FUNC (l->X_add_symbol))
18536 {
18537 l->X_op = O_subtract;
18538 l->X_op_symbol = r->X_add_symbol;
18539 l->X_add_number -= r->X_add_number;
18540 return 1;
18541 }
18542 /* Process as normal. */
18543 return 0;
18544}
18545
c19d1205 18546void
55cf6793 18547md_apply_fix (fixS * fixP,
c19d1205
ZW
18548 valueT * valP,
18549 segT seg)
18550{
18551 offsetT value = * valP;
18552 offsetT newval;
18553 unsigned int newimm;
18554 unsigned long temp;
18555 int sign;
18556 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 18557
c19d1205 18558 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 18559
c19d1205 18560 /* Note whether this will delete the relocation. */
4962c51a 18561
c19d1205
ZW
18562 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
18563 fixP->fx_done = 1;
b99bd4ef 18564
adbaf948 18565 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 18566 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
18567 for emit_reloc. */
18568 value &= 0xffffffff;
18569 value ^= 0x80000000;
5f4273c7 18570 value -= 0x80000000;
adbaf948
ZW
18571
18572 *valP = value;
c19d1205 18573 fixP->fx_addnumber = value;
b99bd4ef 18574
adbaf948
ZW
18575 /* Same treatment for fixP->fx_offset. */
18576 fixP->fx_offset &= 0xffffffff;
18577 fixP->fx_offset ^= 0x80000000;
18578 fixP->fx_offset -= 0x80000000;
18579
c19d1205 18580 switch (fixP->fx_r_type)
b99bd4ef 18581 {
c19d1205
ZW
18582 case BFD_RELOC_NONE:
18583 /* This will need to go in the object file. */
18584 fixP->fx_done = 0;
18585 break;
b99bd4ef 18586
c19d1205
ZW
18587 case BFD_RELOC_ARM_IMMEDIATE:
18588 /* We claim that this fixup has been processed here,
18589 even if in fact we generate an error because we do
18590 not have a reloc for it, so tc_gen_reloc will reject it. */
18591 fixP->fx_done = 1;
b99bd4ef 18592
c19d1205
ZW
18593 if (fixP->fx_addsy
18594 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 18595 {
c19d1205
ZW
18596 as_bad_where (fixP->fx_file, fixP->fx_line,
18597 _("undefined symbol %s used as an immediate value"),
18598 S_GET_NAME (fixP->fx_addsy));
18599 break;
b99bd4ef
NC
18600 }
18601
42e5fcbf
AS
18602 if (fixP->fx_addsy
18603 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18604 {
18605 as_bad_where (fixP->fx_file, fixP->fx_line,
18606 _("symbol %s is in a different section"),
18607 S_GET_NAME (fixP->fx_addsy));
18608 break;
18609 }
18610
c19d1205
ZW
18611 newimm = encode_arm_immediate (value);
18612 temp = md_chars_to_number (buf, INSN_SIZE);
18613
18614 /* If the instruction will fail, see if we can fix things up by
18615 changing the opcode. */
18616 if (newimm == (unsigned int) FAIL
18617 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 18618 {
c19d1205
ZW
18619 as_bad_where (fixP->fx_file, fixP->fx_line,
18620 _("invalid constant (%lx) after fixup"),
18621 (unsigned long) value);
18622 break;
b99bd4ef 18623 }
b99bd4ef 18624
c19d1205
ZW
18625 newimm |= (temp & 0xfffff000);
18626 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
18627 break;
b99bd4ef 18628
c19d1205
ZW
18629 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18630 {
18631 unsigned int highpart = 0;
18632 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 18633
42e5fcbf
AS
18634 if (fixP->fx_addsy
18635 && ! S_IS_DEFINED (fixP->fx_addsy))
18636 {
18637 as_bad_where (fixP->fx_file, fixP->fx_line,
18638 _("undefined symbol %s used as an immediate value"),
18639 S_GET_NAME (fixP->fx_addsy));
18640 break;
18641 }
18642
18643 if (fixP->fx_addsy
18644 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18645 {
18646 as_bad_where (fixP->fx_file, fixP->fx_line,
18647 _("symbol %s is in a different section"),
18648 S_GET_NAME (fixP->fx_addsy));
18649 break;
18650 }
18651
c19d1205
ZW
18652 newimm = encode_arm_immediate (value);
18653 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 18654
c19d1205
ZW
18655 /* If the instruction will fail, see if we can fix things up by
18656 changing the opcode. */
18657 if (newimm == (unsigned int) FAIL
18658 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
18659 {
18660 /* No ? OK - try using two ADD instructions to generate
18661 the value. */
18662 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 18663
c19d1205
ZW
18664 /* Yes - then make sure that the second instruction is
18665 also an add. */
18666 if (newimm != (unsigned int) FAIL)
18667 newinsn = temp;
18668 /* Still No ? Try using a negated value. */
18669 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
18670 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
18671 /* Otherwise - give up. */
18672 else
18673 {
18674 as_bad_where (fixP->fx_file, fixP->fx_line,
18675 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
18676 (long) value);
18677 break;
18678 }
b99bd4ef 18679
c19d1205
ZW
18680 /* Replace the first operand in the 2nd instruction (which
18681 is the PC) with the destination register. We have
18682 already added in the PC in the first instruction and we
18683 do not want to do it again. */
18684 newinsn &= ~ 0xf0000;
18685 newinsn |= ((newinsn & 0x0f000) << 4);
18686 }
b99bd4ef 18687
c19d1205
ZW
18688 newimm |= (temp & 0xfffff000);
18689 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18690
c19d1205
ZW
18691 highpart |= (newinsn & 0xfffff000);
18692 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18693 }
18694 break;
b99bd4ef 18695
c19d1205 18696 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18697 if (!fixP->fx_done && seg->use_rela_p)
18698 value = 0;
18699
c19d1205
ZW
18700 case BFD_RELOC_ARM_LITERAL:
18701 sign = value >= 0;
b99bd4ef 18702
c19d1205
ZW
18703 if (value < 0)
18704 value = - value;
b99bd4ef 18705
c19d1205 18706 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18707 {
c19d1205
ZW
18708 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18709 as_bad_where (fixP->fx_file, fixP->fx_line,
18710 _("invalid literal constant: pool needs to be closer"));
18711 else
18712 as_bad_where (fixP->fx_file, fixP->fx_line,
18713 _("bad immediate value for offset (%ld)"),
18714 (long) value);
18715 break;
f03698e6
RE
18716 }
18717
c19d1205
ZW
18718 newval = md_chars_to_number (buf, INSN_SIZE);
18719 newval &= 0xff7ff000;
18720 newval |= value | (sign ? INDEX_UP : 0);
18721 md_number_to_chars (buf, newval, INSN_SIZE);
18722 break;
b99bd4ef 18723
c19d1205
ZW
18724 case BFD_RELOC_ARM_OFFSET_IMM8:
18725 case BFD_RELOC_ARM_HWLITERAL:
18726 sign = value >= 0;
b99bd4ef 18727
c19d1205
ZW
18728 if (value < 0)
18729 value = - value;
b99bd4ef 18730
c19d1205 18731 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18732 {
c19d1205
ZW
18733 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18734 as_bad_where (fixP->fx_file, fixP->fx_line,
18735 _("invalid literal constant: pool needs to be closer"));
18736 else
f9d4405b 18737 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18738 (long) value);
18739 break;
b99bd4ef
NC
18740 }
18741
c19d1205
ZW
18742 newval = md_chars_to_number (buf, INSN_SIZE);
18743 newval &= 0xff7ff0f0;
18744 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18745 md_number_to_chars (buf, newval, INSN_SIZE);
18746 break;
b99bd4ef 18747
c19d1205
ZW
18748 case BFD_RELOC_ARM_T32_OFFSET_U8:
18749 if (value < 0 || value > 1020 || value % 4 != 0)
18750 as_bad_where (fixP->fx_file, fixP->fx_line,
18751 _("bad immediate value for offset (%ld)"), (long) value);
18752 value /= 4;
b99bd4ef 18753
c19d1205 18754 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18755 newval |= value;
18756 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18757 break;
b99bd4ef 18758
c19d1205
ZW
18759 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18760 /* This is a complicated relocation used for all varieties of Thumb32
18761 load/store instruction with immediate offset:
18762
18763 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18764 *4, optional writeback(W)
18765 (doubleword load/store)
18766
18767 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18768 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18769 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18770 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18771 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18772
18773 Uppercase letters indicate bits that are already encoded at
18774 this point. Lowercase letters are our problem. For the
18775 second block of instructions, the secondary opcode nybble
18776 (bits 8..11) is present, and bit 23 is zero, even if this is
18777 a PC-relative operation. */
18778 newval = md_chars_to_number (buf, THUMB_SIZE);
18779 newval <<= 16;
18780 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18781
c19d1205 18782 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18783 {
c19d1205
ZW
18784 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18785 if (value >= 0)
18786 newval |= (1 << 23);
18787 else
18788 value = -value;
18789 if (value % 4 != 0)
18790 {
18791 as_bad_where (fixP->fx_file, fixP->fx_line,
18792 _("offset not a multiple of 4"));
18793 break;
18794 }
18795 value /= 4;
216d22bc 18796 if (value > 0xff)
c19d1205
ZW
18797 {
18798 as_bad_where (fixP->fx_file, fixP->fx_line,
18799 _("offset out of range"));
18800 break;
18801 }
18802 newval &= ~0xff;
b99bd4ef 18803 }
c19d1205 18804 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18805 {
c19d1205
ZW
18806 /* PC-relative, 12-bit offset. */
18807 if (value >= 0)
18808 newval |= (1 << 23);
18809 else
18810 value = -value;
216d22bc 18811 if (value > 0xfff)
c19d1205
ZW
18812 {
18813 as_bad_where (fixP->fx_file, fixP->fx_line,
18814 _("offset out of range"));
18815 break;
18816 }
18817 newval &= ~0xfff;
b99bd4ef 18818 }
c19d1205 18819 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18820 {
c19d1205
ZW
18821 /* Writeback: 8-bit, +/- offset. */
18822 if (value >= 0)
18823 newval |= (1 << 9);
18824 else
18825 value = -value;
216d22bc 18826 if (value > 0xff)
c19d1205
ZW
18827 {
18828 as_bad_where (fixP->fx_file, fixP->fx_line,
18829 _("offset out of range"));
18830 break;
18831 }
18832 newval &= ~0xff;
b99bd4ef 18833 }
c19d1205 18834 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18835 {
c19d1205 18836 /* T-instruction: positive 8-bit offset. */
216d22bc 18837 if (value < 0 || value > 0xff)
b99bd4ef 18838 {
c19d1205
ZW
18839 as_bad_where (fixP->fx_file, fixP->fx_line,
18840 _("offset out of range"));
18841 break;
b99bd4ef 18842 }
c19d1205
ZW
18843 newval &= ~0xff;
18844 newval |= value;
b99bd4ef
NC
18845 }
18846 else
b99bd4ef 18847 {
c19d1205
ZW
18848 /* Positive 12-bit or negative 8-bit offset. */
18849 int limit;
18850 if (value >= 0)
b99bd4ef 18851 {
c19d1205
ZW
18852 newval |= (1 << 23);
18853 limit = 0xfff;
18854 }
18855 else
18856 {
18857 value = -value;
18858 limit = 0xff;
18859 }
18860 if (value > limit)
18861 {
18862 as_bad_where (fixP->fx_file, fixP->fx_line,
18863 _("offset out of range"));
18864 break;
b99bd4ef 18865 }
c19d1205 18866 newval &= ~limit;
b99bd4ef 18867 }
b99bd4ef 18868
c19d1205
ZW
18869 newval |= value;
18870 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18871 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18872 break;
404ff6b5 18873
c19d1205
ZW
18874 case BFD_RELOC_ARM_SHIFT_IMM:
18875 newval = md_chars_to_number (buf, INSN_SIZE);
18876 if (((unsigned long) value) > 32
18877 || (value == 32
18878 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18879 {
18880 as_bad_where (fixP->fx_file, fixP->fx_line,
18881 _("shift expression is too large"));
18882 break;
18883 }
404ff6b5 18884
c19d1205
ZW
18885 if (value == 0)
18886 /* Shifts of zero must be done as lsl. */
18887 newval &= ~0x60;
18888 else if (value == 32)
18889 value = 0;
18890 newval &= 0xfffff07f;
18891 newval |= (value & 0x1f) << 7;
18892 md_number_to_chars (buf, newval, INSN_SIZE);
18893 break;
404ff6b5 18894
c19d1205 18895 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18896 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18897 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18898 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18899 /* We claim that this fixup has been processed here,
18900 even if in fact we generate an error because we do
18901 not have a reloc for it, so tc_gen_reloc will reject it. */
18902 fixP->fx_done = 1;
404ff6b5 18903
c19d1205
ZW
18904 if (fixP->fx_addsy
18905 && ! S_IS_DEFINED (fixP->fx_addsy))
18906 {
18907 as_bad_where (fixP->fx_file, fixP->fx_line,
18908 _("undefined symbol %s used as an immediate value"),
18909 S_GET_NAME (fixP->fx_addsy));
18910 break;
18911 }
404ff6b5 18912
c19d1205
ZW
18913 newval = md_chars_to_number (buf, THUMB_SIZE);
18914 newval <<= 16;
18915 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18916
16805f35
PB
18917 newimm = FAIL;
18918 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18919 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18920 {
18921 newimm = encode_thumb32_immediate (value);
18922 if (newimm == (unsigned int) FAIL)
18923 newimm = thumb32_negate_data_op (&newval, value);
18924 }
16805f35
PB
18925 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18926 && newimm == (unsigned int) FAIL)
92e90b6e 18927 {
16805f35
PB
18928 /* Turn add/sum into addw/subw. */
18929 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18930 newval = (newval & 0xfeffffff) | 0x02000000;
18931
e9f89963
PB
18932 /* 12 bit immediate for addw/subw. */
18933 if (value < 0)
18934 {
18935 value = -value;
18936 newval ^= 0x00a00000;
18937 }
92e90b6e
PB
18938 if (value > 0xfff)
18939 newimm = (unsigned int) FAIL;
18940 else
18941 newimm = value;
18942 }
cc8a6dd0 18943
c19d1205 18944 if (newimm == (unsigned int)FAIL)
3631a3c8 18945 {
c19d1205
ZW
18946 as_bad_where (fixP->fx_file, fixP->fx_line,
18947 _("invalid constant (%lx) after fixup"),
18948 (unsigned long) value);
18949 break;
3631a3c8
NC
18950 }
18951
c19d1205
ZW
18952 newval |= (newimm & 0x800) << 15;
18953 newval |= (newimm & 0x700) << 4;
18954 newval |= (newimm & 0x0ff);
cc8a6dd0 18955
c19d1205
ZW
18956 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18957 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18958 break;
a737bd4d 18959
3eb17e6b 18960 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18961 if (((unsigned long) value) > 0xffff)
18962 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18963 _("invalid smc expression"));
2fc8bdac 18964 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18965 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18966 md_number_to_chars (buf, newval, INSN_SIZE);
18967 break;
a737bd4d 18968
c19d1205 18969 case BFD_RELOC_ARM_SWI:
adbaf948 18970 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18971 {
18972 if (((unsigned long) value) > 0xff)
18973 as_bad_where (fixP->fx_file, fixP->fx_line,
18974 _("invalid swi expression"));
2fc8bdac 18975 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18976 newval |= value;
18977 md_number_to_chars (buf, newval, THUMB_SIZE);
18978 }
18979 else
18980 {
18981 if (((unsigned long) value) > 0x00ffffff)
18982 as_bad_where (fixP->fx_file, fixP->fx_line,
18983 _("invalid swi expression"));
2fc8bdac 18984 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18985 newval |= value;
18986 md_number_to_chars (buf, newval, INSN_SIZE);
18987 }
18988 break;
a737bd4d 18989
c19d1205
ZW
18990 case BFD_RELOC_ARM_MULTI:
18991 if (((unsigned long) value) > 0xffff)
18992 as_bad_where (fixP->fx_file, fixP->fx_line,
18993 _("invalid expression in load/store multiple"));
18994 newval = value | md_chars_to_number (buf, INSN_SIZE);
18995 md_number_to_chars (buf, newval, INSN_SIZE);
18996 break;
a737bd4d 18997
c19d1205 18998#ifdef OBJ_ELF
39b41c9c 18999 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
19000
19001 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19002 && fixP->fx_addsy
19003 && !S_IS_EXTERNAL (fixP->fx_addsy)
19004 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19005 && THUMB_IS_FUNC (fixP->fx_addsy))
19006 /* Flip the bl to blx. This is a simple flip
19007 bit here because we generate PCREL_CALL for
19008 unconditional bls. */
19009 {
19010 newval = md_chars_to_number (buf, INSN_SIZE);
19011 newval = newval | 0x10000000;
19012 md_number_to_chars (buf, newval, INSN_SIZE);
19013 temp = 1;
19014 fixP->fx_done = 1;
19015 }
39b41c9c
PB
19016 else
19017 temp = 3;
19018 goto arm_branch_common;
19019
19020 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
19021 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19022 && fixP->fx_addsy
19023 && !S_IS_EXTERNAL (fixP->fx_addsy)
19024 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19025 && THUMB_IS_FUNC (fixP->fx_addsy))
19026 {
19027 /* This would map to a bl<cond>, b<cond>,
19028 b<always> to a Thumb function. We
19029 need to force a relocation for this particular
19030 case. */
19031 newval = md_chars_to_number (buf, INSN_SIZE);
19032 fixP->fx_done = 0;
19033 }
19034
2fc8bdac 19035 case BFD_RELOC_ARM_PLT32:
c19d1205 19036#endif
39b41c9c
PB
19037 case BFD_RELOC_ARM_PCREL_BRANCH:
19038 temp = 3;
19039 goto arm_branch_common;
a737bd4d 19040
39b41c9c 19041 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 19042
39b41c9c 19043 temp = 1;
267bf995
RR
19044 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19045 && fixP->fx_addsy
19046 && !S_IS_EXTERNAL (fixP->fx_addsy)
19047 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19048 && ARM_IS_FUNC (fixP->fx_addsy))
19049 {
19050 /* Flip the blx to a bl and warn. */
19051 const char *name = S_GET_NAME (fixP->fx_addsy);
19052 newval = 0xeb000000;
19053 as_warn_where (fixP->fx_file, fixP->fx_line,
19054 _("blx to '%s' an ARM ISA state function changed to bl"),
19055 name);
19056 md_number_to_chars (buf, newval, INSN_SIZE);
19057 temp = 3;
19058 fixP->fx_done = 1;
19059 }
19060
19061#ifdef OBJ_ELF
19062 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
19063 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
19064#endif
19065
39b41c9c 19066 arm_branch_common:
c19d1205 19067 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
19068 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19069 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19070 also be be clear. */
19071 if (value & temp)
c19d1205 19072 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
19073 _("misaligned branch destination"));
19074 if ((value & (offsetT)0xfe000000) != (offsetT)0
19075 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19076 as_bad_where (fixP->fx_file, fixP->fx_line,
19077 _("branch out of range"));
a737bd4d 19078
2fc8bdac 19079 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19080 {
2fc8bdac
ZW
19081 newval = md_chars_to_number (buf, INSN_SIZE);
19082 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
19083 /* Set the H bit on BLX instructions. */
19084 if (temp == 1)
19085 {
19086 if (value & 2)
19087 newval |= 0x01000000;
19088 else
19089 newval &= ~0x01000000;
19090 }
2fc8bdac 19091 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 19092 }
c19d1205 19093 break;
a737bd4d 19094
25fe350b
MS
19095 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19096 /* CBZ can only branch forward. */
a737bd4d 19097
738755b0
MS
19098 /* Attempts to use CBZ to branch to the next instruction
19099 (which, strictly speaking, are prohibited) will be turned into
19100 no-ops.
19101
19102 FIXME: It may be better to remove the instruction completely and
19103 perform relaxation. */
19104 if (value == -2)
2fc8bdac
ZW
19105 {
19106 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 19107 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
19108 md_number_to_chars (buf, newval, THUMB_SIZE);
19109 }
738755b0
MS
19110 else
19111 {
19112 if (value & ~0x7e)
19113 as_bad_where (fixP->fx_file, fixP->fx_line,
19114 _("branch out of range"));
19115
19116 if (fixP->fx_done || !seg->use_rela_p)
19117 {
19118 newval = md_chars_to_number (buf, THUMB_SIZE);
19119 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19120 md_number_to_chars (buf, newval, THUMB_SIZE);
19121 }
19122 }
c19d1205 19123 break;
a737bd4d 19124
c19d1205 19125 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
19126 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19127 as_bad_where (fixP->fx_file, fixP->fx_line,
19128 _("branch out of range"));
a737bd4d 19129
2fc8bdac
ZW
19130 if (fixP->fx_done || !seg->use_rela_p)
19131 {
19132 newval = md_chars_to_number (buf, THUMB_SIZE);
19133 newval |= (value & 0x1ff) >> 1;
19134 md_number_to_chars (buf, newval, THUMB_SIZE);
19135 }
c19d1205 19136 break;
a737bd4d 19137
c19d1205 19138 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
19139 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19140 as_bad_where (fixP->fx_file, fixP->fx_line,
19141 _("branch out of range"));
a737bd4d 19142
2fc8bdac
ZW
19143 if (fixP->fx_done || !seg->use_rela_p)
19144 {
19145 newval = md_chars_to_number (buf, THUMB_SIZE);
19146 newval |= (value & 0xfff) >> 1;
19147 md_number_to_chars (buf, newval, THUMB_SIZE);
19148 }
c19d1205 19149 break;
a737bd4d 19150
c19d1205 19151 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
19152 if (fixP->fx_addsy
19153 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19154 && !S_IS_EXTERNAL (fixP->fx_addsy)
19155 && S_IS_DEFINED (fixP->fx_addsy)
19156 && ARM_IS_FUNC (fixP->fx_addsy)
19157 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19158 {
19159 /* Force a relocation for a branch 20 bits wide. */
19160 fixP->fx_done = 0;
19161 }
2fc8bdac
ZW
19162 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19163 as_bad_where (fixP->fx_file, fixP->fx_line,
19164 _("conditional branch out of range"));
404ff6b5 19165
2fc8bdac
ZW
19166 if (fixP->fx_done || !seg->use_rela_p)
19167 {
19168 offsetT newval2;
19169 addressT S, J1, J2, lo, hi;
404ff6b5 19170
2fc8bdac
ZW
19171 S = (value & 0x00100000) >> 20;
19172 J2 = (value & 0x00080000) >> 19;
19173 J1 = (value & 0x00040000) >> 18;
19174 hi = (value & 0x0003f000) >> 12;
19175 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19176
2fc8bdac
ZW
19177 newval = md_chars_to_number (buf, THUMB_SIZE);
19178 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19179 newval |= (S << 10) | hi;
19180 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19181 md_number_to_chars (buf, newval, THUMB_SIZE);
19182 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19183 }
c19d1205 19184 break;
6c43fab6 19185
c19d1205 19186 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
19187
19188 /* If there is a blx from a thumb state function to
19189 another thumb function flip this to a bl and warn
19190 about it. */
19191
19192 if (fixP->fx_addsy
19193 && S_IS_DEFINED (fixP->fx_addsy)
19194 && !S_IS_EXTERNAL (fixP->fx_addsy)
19195 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19196 && THUMB_IS_FUNC (fixP->fx_addsy))
19197 {
19198 const char *name = S_GET_NAME (fixP->fx_addsy);
19199 as_warn_where (fixP->fx_file, fixP->fx_line,
19200 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
19201 name);
19202 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19203 newval = newval | 0x1000;
19204 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19205 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19206 fixP->fx_done = 1;
19207 }
19208
19209
19210 goto thumb_bl_common;
19211
c19d1205 19212 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
19213
19214 /* A bl from Thumb state ISA to an internal ARM state function
19215 is converted to a blx. */
19216 if (fixP->fx_addsy
19217 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19218 && !S_IS_EXTERNAL (fixP->fx_addsy)
19219 && S_IS_DEFINED (fixP->fx_addsy)
19220 && ARM_IS_FUNC (fixP->fx_addsy)
19221 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19222 {
19223 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19224 newval = newval & ~0x1000;
19225 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19226 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
19227 fixP->fx_done = 1;
19228 }
19229
19230 thumb_bl_common:
19231
19232#ifdef OBJ_ELF
19233 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
19234 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19235 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19236#endif
19237
2fc8bdac
ZW
19238 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19239 as_bad_where (fixP->fx_file, fixP->fx_line,
19240 _("branch out of range"));
404ff6b5 19241
2fc8bdac
ZW
19242 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19243 /* For a BLX instruction, make sure that the relocation is rounded up
19244 to a word boundary. This follows the semantics of the instruction
19245 which specifies that bit 1 of the target address will come from bit
19246 1 of the base address. */
19247 value = (value + 1) & ~ 1;
404ff6b5 19248
2fc8bdac 19249 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19250 {
2fc8bdac
ZW
19251 offsetT newval2;
19252
19253 newval = md_chars_to_number (buf, THUMB_SIZE);
19254 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19255 newval |= (value & 0x7fffff) >> 12;
19256 newval2 |= (value & 0xfff) >> 1;
19257 md_number_to_chars (buf, newval, THUMB_SIZE);
19258 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 19259 }
c19d1205 19260 break;
404ff6b5 19261
c19d1205 19262 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
19263 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19264 as_bad_where (fixP->fx_file, fixP->fx_line,
19265 _("branch out of range"));
6c43fab6 19266
2fc8bdac
ZW
19267 if (fixP->fx_done || !seg->use_rela_p)
19268 {
19269 offsetT newval2;
19270 addressT S, I1, I2, lo, hi;
6c43fab6 19271
2fc8bdac
ZW
19272 S = (value & 0x01000000) >> 24;
19273 I1 = (value & 0x00800000) >> 23;
19274 I2 = (value & 0x00400000) >> 22;
19275 hi = (value & 0x003ff000) >> 12;
19276 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19277
2fc8bdac
ZW
19278 I1 = !(I1 ^ S);
19279 I2 = !(I2 ^ S);
a737bd4d 19280
2fc8bdac
ZW
19281 newval = md_chars_to_number (buf, THUMB_SIZE);
19282 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19283 newval |= (S << 10) | hi;
19284 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19285 md_number_to_chars (buf, newval, THUMB_SIZE);
19286 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19287 }
19288 break;
a737bd4d 19289
2fc8bdac
ZW
19290 case BFD_RELOC_8:
19291 if (fixP->fx_done || !seg->use_rela_p)
19292 md_number_to_chars (buf, value, 1);
c19d1205 19293 break;
a737bd4d 19294
c19d1205 19295 case BFD_RELOC_16:
2fc8bdac 19296 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19297 md_number_to_chars (buf, value, 2);
c19d1205 19298 break;
a737bd4d 19299
c19d1205
ZW
19300#ifdef OBJ_ELF
19301 case BFD_RELOC_ARM_TLS_GD32:
19302 case BFD_RELOC_ARM_TLS_LE32:
19303 case BFD_RELOC_ARM_TLS_IE32:
19304 case BFD_RELOC_ARM_TLS_LDM32:
19305 case BFD_RELOC_ARM_TLS_LDO32:
19306 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19307 /* fall through */
6c43fab6 19308
c19d1205
ZW
19309 case BFD_RELOC_ARM_GOT32:
19310 case BFD_RELOC_ARM_GOTOFF:
19311 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
19312 if (fixP->fx_done || !seg->use_rela_p)
19313 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
19314 break;
19315#endif
6c43fab6 19316
c19d1205
ZW
19317 case BFD_RELOC_RVA:
19318 case BFD_RELOC_32:
19319 case BFD_RELOC_ARM_TARGET1:
19320 case BFD_RELOC_ARM_ROSEGREL32:
19321 case BFD_RELOC_ARM_SBREL32:
19322 case BFD_RELOC_32_PCREL:
f0927246
NC
19323#ifdef TE_PE
19324 case BFD_RELOC_32_SECREL:
19325#endif
2fc8bdac 19326 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
19327#ifdef TE_WINCE
19328 /* For WinCE we only do this for pcrel fixups. */
19329 if (fixP->fx_done || fixP->fx_pcrel)
19330#endif
19331 md_number_to_chars (buf, value, 4);
c19d1205 19332 break;
6c43fab6 19333
c19d1205
ZW
19334#ifdef OBJ_ELF
19335 case BFD_RELOC_ARM_PREL31:
2fc8bdac 19336 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
19337 {
19338 newval = md_chars_to_number (buf, 4) & 0x80000000;
19339 if ((value ^ (value >> 1)) & 0x40000000)
19340 {
19341 as_bad_where (fixP->fx_file, fixP->fx_line,
19342 _("rel31 relocation overflow"));
19343 }
19344 newval |= value & 0x7fffffff;
19345 md_number_to_chars (buf, newval, 4);
19346 }
19347 break;
c19d1205 19348#endif
a737bd4d 19349
c19d1205 19350 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 19351 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
19352 if (value < -1023 || value > 1023 || (value & 3))
19353 as_bad_where (fixP->fx_file, fixP->fx_line,
19354 _("co-processor offset out of range"));
19355 cp_off_common:
19356 sign = value >= 0;
19357 if (value < 0)
19358 value = -value;
8f06b2d8
PB
19359 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19360 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19361 newval = md_chars_to_number (buf, INSN_SIZE);
19362 else
19363 newval = get_thumb32_insn (buf);
19364 newval &= 0xff7fff00;
c19d1205 19365 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
19366 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19367 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19368 md_number_to_chars (buf, newval, INSN_SIZE);
19369 else
19370 put_thumb32_insn (buf, newval);
c19d1205 19371 break;
a737bd4d 19372
c19d1205 19373 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 19374 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
19375 if (value < -255 || value > 255)
19376 as_bad_where (fixP->fx_file, fixP->fx_line,
19377 _("co-processor offset out of range"));
df7849c5 19378 value *= 4;
c19d1205 19379 goto cp_off_common;
6c43fab6 19380
c19d1205
ZW
19381 case BFD_RELOC_ARM_THUMB_OFFSET:
19382 newval = md_chars_to_number (buf, THUMB_SIZE);
19383 /* Exactly what ranges, and where the offset is inserted depends
19384 on the type of instruction, we can establish this from the
19385 top 4 bits. */
19386 switch (newval >> 12)
19387 {
19388 case 4: /* PC load. */
19389 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19390 forced to zero for these loads; md_pcrel_from has already
19391 compensated for this. */
19392 if (value & 3)
19393 as_bad_where (fixP->fx_file, fixP->fx_line,
19394 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
19395 (((unsigned long) fixP->fx_frag->fr_address
19396 + (unsigned long) fixP->fx_where) & ~3)
19397 + (unsigned long) value);
a737bd4d 19398
c19d1205
ZW
19399 if (value & ~0x3fc)
19400 as_bad_where (fixP->fx_file, fixP->fx_line,
19401 _("invalid offset, value too big (0x%08lX)"),
19402 (long) value);
a737bd4d 19403
c19d1205
ZW
19404 newval |= value >> 2;
19405 break;
a737bd4d 19406
c19d1205
ZW
19407 case 9: /* SP load/store. */
19408 if (value & ~0x3fc)
19409 as_bad_where (fixP->fx_file, fixP->fx_line,
19410 _("invalid offset, value too big (0x%08lX)"),
19411 (long) value);
19412 newval |= value >> 2;
19413 break;
6c43fab6 19414
c19d1205
ZW
19415 case 6: /* Word load/store. */
19416 if (value & ~0x7c)
19417 as_bad_where (fixP->fx_file, fixP->fx_line,
19418 _("invalid offset, value too big (0x%08lX)"),
19419 (long) value);
19420 newval |= value << 4; /* 6 - 2. */
19421 break;
a737bd4d 19422
c19d1205
ZW
19423 case 7: /* Byte load/store. */
19424 if (value & ~0x1f)
19425 as_bad_where (fixP->fx_file, fixP->fx_line,
19426 _("invalid offset, value too big (0x%08lX)"),
19427 (long) value);
19428 newval |= value << 6;
19429 break;
a737bd4d 19430
c19d1205
ZW
19431 case 8: /* Halfword load/store. */
19432 if (value & ~0x3e)
19433 as_bad_where (fixP->fx_file, fixP->fx_line,
19434 _("invalid offset, value too big (0x%08lX)"),
19435 (long) value);
19436 newval |= value << 5; /* 6 - 1. */
19437 break;
a737bd4d 19438
c19d1205
ZW
19439 default:
19440 as_bad_where (fixP->fx_file, fixP->fx_line,
19441 "Unable to process relocation for thumb opcode: %lx",
19442 (unsigned long) newval);
19443 break;
19444 }
19445 md_number_to_chars (buf, newval, THUMB_SIZE);
19446 break;
a737bd4d 19447
c19d1205
ZW
19448 case BFD_RELOC_ARM_THUMB_ADD:
19449 /* This is a complicated relocation, since we use it for all of
19450 the following immediate relocations:
a737bd4d 19451
c19d1205
ZW
19452 3bit ADD/SUB
19453 8bit ADD/SUB
19454 9bit ADD/SUB SP word-aligned
19455 10bit ADD PC/SP word-aligned
a737bd4d 19456
c19d1205
ZW
19457 The type of instruction being processed is encoded in the
19458 instruction field:
a737bd4d 19459
c19d1205
ZW
19460 0x8000 SUB
19461 0x00F0 Rd
19462 0x000F Rs
19463 */
19464 newval = md_chars_to_number (buf, THUMB_SIZE);
19465 {
19466 int rd = (newval >> 4) & 0xf;
19467 int rs = newval & 0xf;
19468 int subtract = !!(newval & 0x8000);
a737bd4d 19469
c19d1205
ZW
19470 /* Check for HI regs, only very restricted cases allowed:
19471 Adjusting SP, and using PC or SP to get an address. */
19472 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19473 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19474 as_bad_where (fixP->fx_file, fixP->fx_line,
19475 _("invalid Hi register with immediate"));
a737bd4d 19476
c19d1205
ZW
19477 /* If value is negative, choose the opposite instruction. */
19478 if (value < 0)
19479 {
19480 value = -value;
19481 subtract = !subtract;
19482 if (value < 0)
19483 as_bad_where (fixP->fx_file, fixP->fx_line,
19484 _("immediate value out of range"));
19485 }
a737bd4d 19486
c19d1205
ZW
19487 if (rd == REG_SP)
19488 {
19489 if (value & ~0x1fc)
19490 as_bad_where (fixP->fx_file, fixP->fx_line,
19491 _("invalid immediate for stack address calculation"));
19492 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
19493 newval |= value >> 2;
19494 }
19495 else if (rs == REG_PC || rs == REG_SP)
19496 {
19497 if (subtract || value & ~0x3fc)
19498 as_bad_where (fixP->fx_file, fixP->fx_line,
19499 _("invalid immediate for address calculation (value = 0x%08lX)"),
19500 (unsigned long) value);
19501 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
19502 newval |= rd << 8;
19503 newval |= value >> 2;
19504 }
19505 else if (rs == rd)
19506 {
19507 if (value & ~0xff)
19508 as_bad_where (fixP->fx_file, fixP->fx_line,
19509 _("immediate value out of range"));
19510 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
19511 newval |= (rd << 8) | value;
19512 }
19513 else
19514 {
19515 if (value & ~0x7)
19516 as_bad_where (fixP->fx_file, fixP->fx_line,
19517 _("immediate value out of range"));
19518 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
19519 newval |= rd | (rs << 3) | (value << 6);
19520 }
19521 }
19522 md_number_to_chars (buf, newval, THUMB_SIZE);
19523 break;
a737bd4d 19524
c19d1205
ZW
19525 case BFD_RELOC_ARM_THUMB_IMM:
19526 newval = md_chars_to_number (buf, THUMB_SIZE);
19527 if (value < 0 || value > 255)
19528 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 19529 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
19530 (long) value);
19531 newval |= value;
19532 md_number_to_chars (buf, newval, THUMB_SIZE);
19533 break;
a737bd4d 19534
c19d1205
ZW
19535 case BFD_RELOC_ARM_THUMB_SHIFT:
19536 /* 5bit shift value (0..32). LSL cannot take 32. */
19537 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
19538 temp = newval & 0xf800;
19539 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
19540 as_bad_where (fixP->fx_file, fixP->fx_line,
19541 _("invalid shift value: %ld"), (long) value);
19542 /* Shifts of zero must be encoded as LSL. */
19543 if (value == 0)
19544 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
19545 /* Shifts of 32 are encoded as zero. */
19546 else if (value == 32)
19547 value = 0;
19548 newval |= value << 6;
19549 md_number_to_chars (buf, newval, THUMB_SIZE);
19550 break;
a737bd4d 19551
c19d1205
ZW
19552 case BFD_RELOC_VTABLE_INHERIT:
19553 case BFD_RELOC_VTABLE_ENTRY:
19554 fixP->fx_done = 0;
19555 return;
6c43fab6 19556
b6895b4f
PB
19557 case BFD_RELOC_ARM_MOVW:
19558 case BFD_RELOC_ARM_MOVT:
19559 case BFD_RELOC_ARM_THUMB_MOVW:
19560 case BFD_RELOC_ARM_THUMB_MOVT:
19561 if (fixP->fx_done || !seg->use_rela_p)
19562 {
19563 /* REL format relocations are limited to a 16-bit addend. */
19564 if (!fixP->fx_done)
19565 {
39623e12 19566 if (value < -0x8000 || value > 0x7fff)
b6895b4f 19567 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 19568 _("offset out of range"));
b6895b4f
PB
19569 }
19570 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
19571 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19572 {
19573 value >>= 16;
19574 }
19575
19576 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
19577 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
19578 {
19579 newval = get_thumb32_insn (buf);
19580 newval &= 0xfbf08f00;
19581 newval |= (value & 0xf000) << 4;
19582 newval |= (value & 0x0800) << 15;
19583 newval |= (value & 0x0700) << 4;
19584 newval |= (value & 0x00ff);
19585 put_thumb32_insn (buf, newval);
19586 }
19587 else
19588 {
19589 newval = md_chars_to_number (buf, 4);
19590 newval &= 0xfff0f000;
19591 newval |= value & 0x0fff;
19592 newval |= (value & 0xf000) << 4;
19593 md_number_to_chars (buf, newval, 4);
19594 }
19595 }
19596 return;
19597
4962c51a
MS
19598 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19599 case BFD_RELOC_ARM_ALU_PC_G0:
19600 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19601 case BFD_RELOC_ARM_ALU_PC_G1:
19602 case BFD_RELOC_ARM_ALU_PC_G2:
19603 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19604 case BFD_RELOC_ARM_ALU_SB_G0:
19605 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19606 case BFD_RELOC_ARM_ALU_SB_G1:
19607 case BFD_RELOC_ARM_ALU_SB_G2:
19608 assert (!fixP->fx_done);
19609 if (!seg->use_rela_p)
19610 {
19611 bfd_vma insn;
19612 bfd_vma encoded_addend;
19613 bfd_vma addend_abs = abs (value);
19614
19615 /* Check that the absolute value of the addend can be
19616 expressed as an 8-bit constant plus a rotation. */
19617 encoded_addend = encode_arm_immediate (addend_abs);
19618 if (encoded_addend == (unsigned int) FAIL)
19619 as_bad_where (fixP->fx_file, fixP->fx_line,
19620 _("the offset 0x%08lX is not representable"),
495bde8e 19621 (unsigned long) addend_abs);
4962c51a
MS
19622
19623 /* Extract the instruction. */
19624 insn = md_chars_to_number (buf, INSN_SIZE);
19625
19626 /* If the addend is positive, use an ADD instruction.
19627 Otherwise use a SUB. Take care not to destroy the S bit. */
19628 insn &= 0xff1fffff;
19629 if (value < 0)
19630 insn |= 1 << 22;
19631 else
19632 insn |= 1 << 23;
19633
19634 /* Place the encoded addend into the first 12 bits of the
19635 instruction. */
19636 insn &= 0xfffff000;
19637 insn |= encoded_addend;
5f4273c7
NC
19638
19639 /* Update the instruction. */
4962c51a
MS
19640 md_number_to_chars (buf, insn, INSN_SIZE);
19641 }
19642 break;
19643
19644 case BFD_RELOC_ARM_LDR_PC_G0:
19645 case BFD_RELOC_ARM_LDR_PC_G1:
19646 case BFD_RELOC_ARM_LDR_PC_G2:
19647 case BFD_RELOC_ARM_LDR_SB_G0:
19648 case BFD_RELOC_ARM_LDR_SB_G1:
19649 case BFD_RELOC_ARM_LDR_SB_G2:
19650 assert (!fixP->fx_done);
19651 if (!seg->use_rela_p)
19652 {
19653 bfd_vma insn;
19654 bfd_vma addend_abs = abs (value);
19655
19656 /* Check that the absolute value of the addend can be
19657 encoded in 12 bits. */
19658 if (addend_abs >= 0x1000)
19659 as_bad_where (fixP->fx_file, fixP->fx_line,
19660 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 19661 (unsigned long) addend_abs);
4962c51a
MS
19662
19663 /* Extract the instruction. */
19664 insn = md_chars_to_number (buf, INSN_SIZE);
19665
19666 /* If the addend is negative, clear bit 23 of the instruction.
19667 Otherwise set it. */
19668 if (value < 0)
19669 insn &= ~(1 << 23);
19670 else
19671 insn |= 1 << 23;
19672
19673 /* Place the absolute value of the addend into the first 12 bits
19674 of the instruction. */
19675 insn &= 0xfffff000;
19676 insn |= addend_abs;
5f4273c7
NC
19677
19678 /* Update the instruction. */
4962c51a
MS
19679 md_number_to_chars (buf, insn, INSN_SIZE);
19680 }
19681 break;
19682
19683 case BFD_RELOC_ARM_LDRS_PC_G0:
19684 case BFD_RELOC_ARM_LDRS_PC_G1:
19685 case BFD_RELOC_ARM_LDRS_PC_G2:
19686 case BFD_RELOC_ARM_LDRS_SB_G0:
19687 case BFD_RELOC_ARM_LDRS_SB_G1:
19688 case BFD_RELOC_ARM_LDRS_SB_G2:
19689 assert (!fixP->fx_done);
19690 if (!seg->use_rela_p)
19691 {
19692 bfd_vma insn;
19693 bfd_vma addend_abs = abs (value);
19694
19695 /* Check that the absolute value of the addend can be
19696 encoded in 8 bits. */
19697 if (addend_abs >= 0x100)
19698 as_bad_where (fixP->fx_file, fixP->fx_line,
19699 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 19700 (unsigned long) addend_abs);
4962c51a
MS
19701
19702 /* Extract the instruction. */
19703 insn = md_chars_to_number (buf, INSN_SIZE);
19704
19705 /* If the addend is negative, clear bit 23 of the instruction.
19706 Otherwise set it. */
19707 if (value < 0)
19708 insn &= ~(1 << 23);
19709 else
19710 insn |= 1 << 23;
19711
19712 /* Place the first four bits of the absolute value of the addend
19713 into the first 4 bits of the instruction, and the remaining
19714 four into bits 8 .. 11. */
19715 insn &= 0xfffff0f0;
19716 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
19717
19718 /* Update the instruction. */
4962c51a
MS
19719 md_number_to_chars (buf, insn, INSN_SIZE);
19720 }
19721 break;
19722
19723 case BFD_RELOC_ARM_LDC_PC_G0:
19724 case BFD_RELOC_ARM_LDC_PC_G1:
19725 case BFD_RELOC_ARM_LDC_PC_G2:
19726 case BFD_RELOC_ARM_LDC_SB_G0:
19727 case BFD_RELOC_ARM_LDC_SB_G1:
19728 case BFD_RELOC_ARM_LDC_SB_G2:
19729 assert (!fixP->fx_done);
19730 if (!seg->use_rela_p)
19731 {
19732 bfd_vma insn;
19733 bfd_vma addend_abs = abs (value);
19734
19735 /* Check that the absolute value of the addend is a multiple of
19736 four and, when divided by four, fits in 8 bits. */
19737 if (addend_abs & 0x3)
19738 as_bad_where (fixP->fx_file, fixP->fx_line,
19739 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 19740 (unsigned long) addend_abs);
4962c51a
MS
19741
19742 if ((addend_abs >> 2) > 0xff)
19743 as_bad_where (fixP->fx_file, fixP->fx_line,
19744 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 19745 (unsigned long) addend_abs);
4962c51a
MS
19746
19747 /* Extract the instruction. */
19748 insn = md_chars_to_number (buf, INSN_SIZE);
19749
19750 /* If the addend is negative, clear bit 23 of the instruction.
19751 Otherwise set it. */
19752 if (value < 0)
19753 insn &= ~(1 << 23);
19754 else
19755 insn |= 1 << 23;
19756
19757 /* Place the addend (divided by four) into the first eight
19758 bits of the instruction. */
19759 insn &= 0xfffffff0;
19760 insn |= addend_abs >> 2;
5f4273c7
NC
19761
19762 /* Update the instruction. */
4962c51a
MS
19763 md_number_to_chars (buf, insn, INSN_SIZE);
19764 }
19765 break;
19766
845b51d6
PB
19767 case BFD_RELOC_ARM_V4BX:
19768 /* This will need to go in the object file. */
19769 fixP->fx_done = 0;
19770 break;
19771
c19d1205
ZW
19772 case BFD_RELOC_UNUSED:
19773 default:
19774 as_bad_where (fixP->fx_file, fixP->fx_line,
19775 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
19776 }
6c43fab6
RE
19777}
19778
c19d1205
ZW
19779/* Translate internal representation of relocation info to BFD target
19780 format. */
a737bd4d 19781
c19d1205 19782arelent *
00a97672 19783tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 19784{
c19d1205
ZW
19785 arelent * reloc;
19786 bfd_reloc_code_real_type code;
a737bd4d 19787
c19d1205 19788 reloc = xmalloc (sizeof (arelent));
a737bd4d 19789
c19d1205
ZW
19790 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
19791 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
19792 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19793
2fc8bdac 19794 if (fixp->fx_pcrel)
00a97672
RS
19795 {
19796 if (section->use_rela_p)
19797 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19798 else
19799 fixp->fx_offset = reloc->address;
19800 }
c19d1205 19801 reloc->addend = fixp->fx_offset;
a737bd4d 19802
c19d1205 19803 switch (fixp->fx_r_type)
a737bd4d 19804 {
c19d1205
ZW
19805 case BFD_RELOC_8:
19806 if (fixp->fx_pcrel)
19807 {
19808 code = BFD_RELOC_8_PCREL;
19809 break;
19810 }
a737bd4d 19811
c19d1205
ZW
19812 case BFD_RELOC_16:
19813 if (fixp->fx_pcrel)
19814 {
19815 code = BFD_RELOC_16_PCREL;
19816 break;
19817 }
6c43fab6 19818
c19d1205
ZW
19819 case BFD_RELOC_32:
19820 if (fixp->fx_pcrel)
19821 {
19822 code = BFD_RELOC_32_PCREL;
19823 break;
19824 }
a737bd4d 19825
b6895b4f
PB
19826 case BFD_RELOC_ARM_MOVW:
19827 if (fixp->fx_pcrel)
19828 {
19829 code = BFD_RELOC_ARM_MOVW_PCREL;
19830 break;
19831 }
19832
19833 case BFD_RELOC_ARM_MOVT:
19834 if (fixp->fx_pcrel)
19835 {
19836 code = BFD_RELOC_ARM_MOVT_PCREL;
19837 break;
19838 }
19839
19840 case BFD_RELOC_ARM_THUMB_MOVW:
19841 if (fixp->fx_pcrel)
19842 {
19843 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19844 break;
19845 }
19846
19847 case BFD_RELOC_ARM_THUMB_MOVT:
19848 if (fixp->fx_pcrel)
19849 {
19850 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19851 break;
19852 }
19853
c19d1205
ZW
19854 case BFD_RELOC_NONE:
19855 case BFD_RELOC_ARM_PCREL_BRANCH:
19856 case BFD_RELOC_ARM_PCREL_BLX:
19857 case BFD_RELOC_RVA:
19858 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19859 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19860 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19861 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19862 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19863 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
19864 case BFD_RELOC_VTABLE_ENTRY:
19865 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19866#ifdef TE_PE
19867 case BFD_RELOC_32_SECREL:
19868#endif
c19d1205
ZW
19869 code = fixp->fx_r_type;
19870 break;
a737bd4d 19871
00adf2d4
JB
19872 case BFD_RELOC_THUMB_PCREL_BLX:
19873#ifdef OBJ_ELF
19874 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
19875 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
19876 else
19877#endif
19878 code = BFD_RELOC_THUMB_PCREL_BLX;
19879 break;
19880
c19d1205
ZW
19881 case BFD_RELOC_ARM_LITERAL:
19882 case BFD_RELOC_ARM_HWLITERAL:
19883 /* If this is called then the a literal has
19884 been referenced across a section boundary. */
19885 as_bad_where (fixp->fx_file, fixp->fx_line,
19886 _("literal referenced across section boundary"));
19887 return NULL;
a737bd4d 19888
c19d1205
ZW
19889#ifdef OBJ_ELF
19890 case BFD_RELOC_ARM_GOT32:
19891 case BFD_RELOC_ARM_GOTOFF:
19892 case BFD_RELOC_ARM_PLT32:
19893 case BFD_RELOC_ARM_TARGET1:
19894 case BFD_RELOC_ARM_ROSEGREL32:
19895 case BFD_RELOC_ARM_SBREL32:
19896 case BFD_RELOC_ARM_PREL31:
19897 case BFD_RELOC_ARM_TARGET2:
19898 case BFD_RELOC_ARM_TLS_LE32:
19899 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19900 case BFD_RELOC_ARM_PCREL_CALL:
19901 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19902 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19903 case BFD_RELOC_ARM_ALU_PC_G0:
19904 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19905 case BFD_RELOC_ARM_ALU_PC_G1:
19906 case BFD_RELOC_ARM_ALU_PC_G2:
19907 case BFD_RELOC_ARM_LDR_PC_G0:
19908 case BFD_RELOC_ARM_LDR_PC_G1:
19909 case BFD_RELOC_ARM_LDR_PC_G2:
19910 case BFD_RELOC_ARM_LDRS_PC_G0:
19911 case BFD_RELOC_ARM_LDRS_PC_G1:
19912 case BFD_RELOC_ARM_LDRS_PC_G2:
19913 case BFD_RELOC_ARM_LDC_PC_G0:
19914 case BFD_RELOC_ARM_LDC_PC_G1:
19915 case BFD_RELOC_ARM_LDC_PC_G2:
19916 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19917 case BFD_RELOC_ARM_ALU_SB_G0:
19918 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19919 case BFD_RELOC_ARM_ALU_SB_G1:
19920 case BFD_RELOC_ARM_ALU_SB_G2:
19921 case BFD_RELOC_ARM_LDR_SB_G0:
19922 case BFD_RELOC_ARM_LDR_SB_G1:
19923 case BFD_RELOC_ARM_LDR_SB_G2:
19924 case BFD_RELOC_ARM_LDRS_SB_G0:
19925 case BFD_RELOC_ARM_LDRS_SB_G1:
19926 case BFD_RELOC_ARM_LDRS_SB_G2:
19927 case BFD_RELOC_ARM_LDC_SB_G0:
19928 case BFD_RELOC_ARM_LDC_SB_G1:
19929 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 19930 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
19931 code = fixp->fx_r_type;
19932 break;
a737bd4d 19933
c19d1205
ZW
19934 case BFD_RELOC_ARM_TLS_GD32:
19935 case BFD_RELOC_ARM_TLS_IE32:
19936 case BFD_RELOC_ARM_TLS_LDM32:
19937 /* BFD will include the symbol's address in the addend.
19938 But we don't want that, so subtract it out again here. */
19939 if (!S_IS_COMMON (fixp->fx_addsy))
19940 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19941 code = fixp->fx_r_type;
19942 break;
19943#endif
a737bd4d 19944
c19d1205
ZW
19945 case BFD_RELOC_ARM_IMMEDIATE:
19946 as_bad_where (fixp->fx_file, fixp->fx_line,
19947 _("internal relocation (type: IMMEDIATE) not fixed up"));
19948 return NULL;
a737bd4d 19949
c19d1205
ZW
19950 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19951 as_bad_where (fixp->fx_file, fixp->fx_line,
19952 _("ADRL used for a symbol not defined in the same file"));
19953 return NULL;
a737bd4d 19954
c19d1205 19955 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19956 if (section->use_rela_p)
19957 {
19958 code = fixp->fx_r_type;
19959 break;
19960 }
19961
c19d1205
ZW
19962 if (fixp->fx_addsy != NULL
19963 && !S_IS_DEFINED (fixp->fx_addsy)
19964 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19965 {
c19d1205
ZW
19966 as_bad_where (fixp->fx_file, fixp->fx_line,
19967 _("undefined local label `%s'"),
19968 S_GET_NAME (fixp->fx_addsy));
19969 return NULL;
a737bd4d
NC
19970 }
19971
c19d1205
ZW
19972 as_bad_where (fixp->fx_file, fixp->fx_line,
19973 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19974 return NULL;
a737bd4d 19975
c19d1205
ZW
19976 default:
19977 {
19978 char * type;
6c43fab6 19979
c19d1205
ZW
19980 switch (fixp->fx_r_type)
19981 {
19982 case BFD_RELOC_NONE: type = "NONE"; break;
19983 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19984 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19985 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19986 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19987 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19988 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19989 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19990 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19991 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19992 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19993 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19994 default: type = _("<unknown>"); break;
19995 }
19996 as_bad_where (fixp->fx_file, fixp->fx_line,
19997 _("cannot represent %s relocation in this object file format"),
19998 type);
19999 return NULL;
20000 }
a737bd4d 20001 }
6c43fab6 20002
c19d1205
ZW
20003#ifdef OBJ_ELF
20004 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
20005 && GOT_symbol
20006 && fixp->fx_addsy == GOT_symbol)
20007 {
20008 code = BFD_RELOC_ARM_GOTPC;
20009 reloc->addend = fixp->fx_offset = reloc->address;
20010 }
20011#endif
6c43fab6 20012
c19d1205 20013 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 20014
c19d1205
ZW
20015 if (reloc->howto == NULL)
20016 {
20017 as_bad_where (fixp->fx_file, fixp->fx_line,
20018 _("cannot represent %s relocation in this object file format"),
20019 bfd_get_reloc_code_name (code));
20020 return NULL;
20021 }
6c43fab6 20022
c19d1205
ZW
20023 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
20024 vtable entry to be used in the relocation's section offset. */
20025 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20026 reloc->address = fixp->fx_offset;
6c43fab6 20027
c19d1205 20028 return reloc;
6c43fab6
RE
20029}
20030
c19d1205 20031/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 20032
c19d1205
ZW
20033void
20034cons_fix_new_arm (fragS * frag,
20035 int where,
20036 int size,
20037 expressionS * exp)
6c43fab6 20038{
c19d1205
ZW
20039 bfd_reloc_code_real_type type;
20040 int pcrel = 0;
6c43fab6 20041
c19d1205
ZW
20042 /* Pick a reloc.
20043 FIXME: @@ Should look at CPU word size. */
20044 switch (size)
20045 {
20046 case 1:
20047 type = BFD_RELOC_8;
20048 break;
20049 case 2:
20050 type = BFD_RELOC_16;
20051 break;
20052 case 4:
20053 default:
20054 type = BFD_RELOC_32;
20055 break;
20056 case 8:
20057 type = BFD_RELOC_64;
20058 break;
20059 }
6c43fab6 20060
f0927246
NC
20061#ifdef TE_PE
20062 if (exp->X_op == O_secrel)
20063 {
20064 exp->X_op = O_symbol;
20065 type = BFD_RELOC_32_SECREL;
20066 }
20067#endif
20068
c19d1205
ZW
20069 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
20070}
6c43fab6 20071
4343666d 20072#if defined (OBJ_COFF)
c19d1205
ZW
20073void
20074arm_validate_fix (fixS * fixP)
6c43fab6 20075{
c19d1205
ZW
20076 /* If the destination of the branch is a defined symbol which does not have
20077 the THUMB_FUNC attribute, then we must be calling a function which has
20078 the (interfacearm) attribute. We look for the Thumb entry point to that
20079 function and change the branch to refer to that function instead. */
20080 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
20081 && fixP->fx_addsy != NULL
20082 && S_IS_DEFINED (fixP->fx_addsy)
20083 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 20084 {
c19d1205 20085 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 20086 }
c19d1205
ZW
20087}
20088#endif
6c43fab6 20089
267bf995 20090
c19d1205
ZW
20091int
20092arm_force_relocation (struct fix * fixp)
20093{
20094#if defined (OBJ_COFF) && defined (TE_PE)
20095 if (fixp->fx_r_type == BFD_RELOC_RVA)
20096 return 1;
20097#endif
6c43fab6 20098
267bf995
RR
20099 /* In case we have a call or a branch to a function in ARM ISA mode from
20100 a thumb function or vice-versa force the relocation. These relocations
20101 are cleared off for some cores that might have blx and simple transformations
20102 are possible. */
20103
20104#ifdef OBJ_ELF
20105 switch (fixp->fx_r_type)
20106 {
20107 case BFD_RELOC_ARM_PCREL_JUMP:
20108 case BFD_RELOC_ARM_PCREL_CALL:
20109 case BFD_RELOC_THUMB_PCREL_BLX:
20110 if (THUMB_IS_FUNC (fixp->fx_addsy))
20111 return 1;
20112 break;
20113
20114 case BFD_RELOC_ARM_PCREL_BLX:
20115 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20116 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20117 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20118 if (ARM_IS_FUNC (fixp->fx_addsy))
20119 return 1;
20120 break;
20121
20122 default:
20123 break;
20124 }
20125#endif
20126
c19d1205
ZW
20127 /* Resolve these relocations even if the symbol is extern or weak. */
20128 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
20129 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 20130 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 20131 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
20132 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20133 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
20134 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 20135 return 0;
a737bd4d 20136
4962c51a
MS
20137 /* Always leave these relocations for the linker. */
20138 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20139 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20140 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20141 return 1;
20142
f0291e4c
PB
20143 /* Always generate relocations against function symbols. */
20144 if (fixp->fx_r_type == BFD_RELOC_32
20145 && fixp->fx_addsy
20146 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
20147 return 1;
20148
c19d1205 20149 return generic_force_reloc (fixp);
404ff6b5
AH
20150}
20151
0ffdc86c 20152#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
20153/* Relocations against function names must be left unadjusted,
20154 so that the linker can use this information to generate interworking
20155 stubs. The MIPS version of this function
c19d1205
ZW
20156 also prevents relocations that are mips-16 specific, but I do not
20157 know why it does this.
404ff6b5 20158
c19d1205
ZW
20159 FIXME:
20160 There is one other problem that ought to be addressed here, but
20161 which currently is not: Taking the address of a label (rather
20162 than a function) and then later jumping to that address. Such
20163 addresses also ought to have their bottom bit set (assuming that
20164 they reside in Thumb code), but at the moment they will not. */
404ff6b5 20165
c19d1205
ZW
20166bfd_boolean
20167arm_fix_adjustable (fixS * fixP)
404ff6b5 20168{
c19d1205
ZW
20169 if (fixP->fx_addsy == NULL)
20170 return 1;
404ff6b5 20171
e28387c3
PB
20172 /* Preserve relocations against symbols with function type. */
20173 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20174 return 0;
20175
c19d1205
ZW
20176 if (THUMB_IS_FUNC (fixP->fx_addsy)
20177 && fixP->fx_subsy == NULL)
20178 return 0;
a737bd4d 20179
c19d1205
ZW
20180 /* We need the symbol name for the VTABLE entries. */
20181 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20182 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20183 return 0;
404ff6b5 20184
c19d1205
ZW
20185 /* Don't allow symbols to be discarded on GOT related relocs. */
20186 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20187 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20188 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20189 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20190 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20191 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20192 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20193 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20194 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20195 return 0;
a737bd4d 20196
4962c51a
MS
20197 /* Similarly for group relocations. */
20198 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20199 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20200 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20201 return 0;
20202
79947c54
CD
20203 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20204 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20205 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20206 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20207 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20208 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20209 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20210 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20211 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20212 return 0;
20213
c19d1205 20214 return 1;
a737bd4d 20215}
0ffdc86c
NC
20216#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20217
20218#ifdef OBJ_ELF
404ff6b5 20219
c19d1205
ZW
20220const char *
20221elf32_arm_target_format (void)
404ff6b5 20222{
c19d1205
ZW
20223#ifdef TE_SYMBIAN
20224 return (target_big_endian
20225 ? "elf32-bigarm-symbian"
20226 : "elf32-littlearm-symbian");
20227#elif defined (TE_VXWORKS)
20228 return (target_big_endian
20229 ? "elf32-bigarm-vxworks"
20230 : "elf32-littlearm-vxworks");
20231#else
20232 if (target_big_endian)
20233 return "elf32-bigarm";
20234 else
20235 return "elf32-littlearm";
20236#endif
404ff6b5
AH
20237}
20238
c19d1205
ZW
20239void
20240armelf_frob_symbol (symbolS * symp,
20241 int * puntp)
404ff6b5 20242{
c19d1205
ZW
20243 elf_frob_symbol (symp, puntp);
20244}
20245#endif
404ff6b5 20246
c19d1205 20247/* MD interface: Finalization. */
a737bd4d 20248
c19d1205
ZW
20249/* A good place to do this, although this was probably not intended
20250 for this kind of use. We need to dump the literal pool before
20251 references are made to a null symbol pointer. */
a737bd4d 20252
c19d1205
ZW
20253void
20254arm_cleanup (void)
20255{
20256 literal_pool * pool;
a737bd4d 20257
c19d1205
ZW
20258 for (pool = list_of_pools; pool; pool = pool->next)
20259 {
5f4273c7 20260 /* Put it at the end of the relevant section. */
c19d1205
ZW
20261 subseg_set (pool->section, pool->sub_section);
20262#ifdef OBJ_ELF
20263 arm_elf_change_section ();
20264#endif
20265 s_ltorg (0);
20266 }
404ff6b5
AH
20267}
20268
c19d1205
ZW
20269/* Adjust the symbol table. This marks Thumb symbols as distinct from
20270 ARM ones. */
404ff6b5 20271
c19d1205
ZW
20272void
20273arm_adjust_symtab (void)
404ff6b5 20274{
c19d1205
ZW
20275#ifdef OBJ_COFF
20276 symbolS * sym;
404ff6b5 20277
c19d1205
ZW
20278 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20279 {
20280 if (ARM_IS_THUMB (sym))
20281 {
20282 if (THUMB_IS_FUNC (sym))
20283 {
20284 /* Mark the symbol as a Thumb function. */
20285 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20286 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20287 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 20288
c19d1205
ZW
20289 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20290 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20291 else
20292 as_bad (_("%s: unexpected function type: %d"),
20293 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20294 }
20295 else switch (S_GET_STORAGE_CLASS (sym))
20296 {
20297 case C_EXT:
20298 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20299 break;
20300 case C_STAT:
20301 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20302 break;
20303 case C_LABEL:
20304 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20305 break;
20306 default:
20307 /* Do nothing. */
20308 break;
20309 }
20310 }
a737bd4d 20311
c19d1205
ZW
20312 if (ARM_IS_INTERWORK (sym))
20313 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 20314 }
c19d1205
ZW
20315#endif
20316#ifdef OBJ_ELF
20317 symbolS * sym;
20318 char bind;
404ff6b5 20319
c19d1205 20320 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 20321 {
c19d1205
ZW
20322 if (ARM_IS_THUMB (sym))
20323 {
20324 elf_symbol_type * elf_sym;
404ff6b5 20325
c19d1205
ZW
20326 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20327 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 20328
b0796911
PB
20329 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20330 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
20331 {
20332 /* If it's a .thumb_func, declare it as so,
20333 otherwise tag label as .code 16. */
20334 if (THUMB_IS_FUNC (sym))
20335 elf_sym->internal_elf_sym.st_info =
20336 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 20337 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
20338 elf_sym->internal_elf_sym.st_info =
20339 ELF_ST_INFO (bind, STT_ARM_16BIT);
20340 }
20341 }
20342 }
20343#endif
404ff6b5
AH
20344}
20345
c19d1205 20346/* MD interface: Initialization. */
404ff6b5 20347
a737bd4d 20348static void
c19d1205 20349set_constant_flonums (void)
a737bd4d 20350{
c19d1205 20351 int i;
404ff6b5 20352
c19d1205
ZW
20353 for (i = 0; i < NUM_FLOAT_VALS; i++)
20354 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20355 abort ();
a737bd4d 20356}
404ff6b5 20357
3e9e4fcf
JB
20358/* Auto-select Thumb mode if it's the only available instruction set for the
20359 given architecture. */
20360
20361static void
20362autoselect_thumb_from_cpu_variant (void)
20363{
20364 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20365 opcode_select (16);
20366}
20367
c19d1205
ZW
20368void
20369md_begin (void)
a737bd4d 20370{
c19d1205
ZW
20371 unsigned mach;
20372 unsigned int i;
404ff6b5 20373
c19d1205
ZW
20374 if ( (arm_ops_hsh = hash_new ()) == NULL
20375 || (arm_cond_hsh = hash_new ()) == NULL
20376 || (arm_shift_hsh = hash_new ()) == NULL
20377 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 20378 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 20379 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
20380 || (arm_reloc_hsh = hash_new ()) == NULL
20381 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
20382 as_fatal (_("virtual memory exhausted"));
20383
20384 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
5a49b8ac 20385 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
c19d1205 20386 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
5a49b8ac 20387 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
c19d1205 20388 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 20389 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 20390 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20391 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
62b3e311 20392 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20393 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
c19d1205 20394 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 20395 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
20396 for (i = 0;
20397 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20398 i++)
20399 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
5a49b8ac 20400 (void *) (barrier_opt_names + i));
c19d1205
ZW
20401#ifdef OBJ_ELF
20402 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 20403 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
20404#endif
20405
20406 set_constant_flonums ();
404ff6b5 20407
c19d1205
ZW
20408 /* Set the cpu variant based on the command-line options. We prefer
20409 -mcpu= over -march= if both are set (as for GCC); and we prefer
20410 -mfpu= over any other way of setting the floating point unit.
20411 Use of legacy options with new options are faulted. */
e74cfd16 20412 if (legacy_cpu)
404ff6b5 20413 {
e74cfd16 20414 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
20415 as_bad (_("use of old and new-style options to set CPU type"));
20416
20417 mcpu_cpu_opt = legacy_cpu;
404ff6b5 20418 }
e74cfd16 20419 else if (!mcpu_cpu_opt)
c19d1205 20420 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 20421
e74cfd16 20422 if (legacy_fpu)
c19d1205 20423 {
e74cfd16 20424 if (mfpu_opt)
c19d1205 20425 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
20426
20427 mfpu_opt = legacy_fpu;
20428 }
e74cfd16 20429 else if (!mfpu_opt)
03b1477f 20430 {
45eb4c1b
NS
20431#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
20432 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
20433 /* Some environments specify a default FPU. If they don't, infer it
20434 from the processor. */
e74cfd16 20435 if (mcpu_fpu_opt)
03b1477f
RE
20436 mfpu_opt = mcpu_fpu_opt;
20437 else
20438 mfpu_opt = march_fpu_opt;
39c2da32 20439#else
e74cfd16 20440 mfpu_opt = &fpu_default;
39c2da32 20441#endif
03b1477f
RE
20442 }
20443
e74cfd16 20444 if (!mfpu_opt)
03b1477f 20445 {
493cb6ef 20446 if (mcpu_cpu_opt != NULL)
e74cfd16 20447 mfpu_opt = &fpu_default;
493cb6ef 20448 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 20449 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 20450 else
e74cfd16 20451 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
20452 }
20453
ee065d83 20454#ifdef CPU_DEFAULT
e74cfd16 20455 if (!mcpu_cpu_opt)
ee065d83 20456 {
e74cfd16
PB
20457 mcpu_cpu_opt = &cpu_default;
20458 selected_cpu = cpu_default;
ee065d83 20459 }
e74cfd16
PB
20460#else
20461 if (mcpu_cpu_opt)
20462 selected_cpu = *mcpu_cpu_opt;
ee065d83 20463 else
e74cfd16 20464 mcpu_cpu_opt = &arm_arch_any;
ee065d83 20465#endif
03b1477f 20466
e74cfd16 20467 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 20468
3e9e4fcf
JB
20469 autoselect_thumb_from_cpu_variant ();
20470
e74cfd16 20471 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 20472
f17c130b 20473#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 20474 {
7cc69913
NC
20475 unsigned int flags = 0;
20476
20477#if defined OBJ_ELF
20478 flags = meabi_flags;
d507cf36
PB
20479
20480 switch (meabi_flags)
33a392fb 20481 {
d507cf36 20482 case EF_ARM_EABI_UNKNOWN:
7cc69913 20483#endif
d507cf36
PB
20484 /* Set the flags in the private structure. */
20485 if (uses_apcs_26) flags |= F_APCS26;
20486 if (support_interwork) flags |= F_INTERWORK;
20487 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 20488 if (pic_code) flags |= F_PIC;
e74cfd16 20489 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
20490 flags |= F_SOFT_FLOAT;
20491
d507cf36
PB
20492 switch (mfloat_abi_opt)
20493 {
20494 case ARM_FLOAT_ABI_SOFT:
20495 case ARM_FLOAT_ABI_SOFTFP:
20496 flags |= F_SOFT_FLOAT;
20497 break;
33a392fb 20498
d507cf36
PB
20499 case ARM_FLOAT_ABI_HARD:
20500 if (flags & F_SOFT_FLOAT)
20501 as_bad (_("hard-float conflicts with specified fpu"));
20502 break;
20503 }
03b1477f 20504
e74cfd16
PB
20505 /* Using pure-endian doubles (even if soft-float). */
20506 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 20507 flags |= F_VFP_FLOAT;
f17c130b 20508
fde78edd 20509#if defined OBJ_ELF
e74cfd16 20510 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 20511 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
20512 break;
20513
8cb51566 20514 case EF_ARM_EABI_VER4:
3a4a14e9 20515 case EF_ARM_EABI_VER5:
c19d1205 20516 /* No additional flags to set. */
d507cf36
PB
20517 break;
20518
20519 default:
20520 abort ();
20521 }
7cc69913 20522#endif
b99bd4ef
NC
20523 bfd_set_private_flags (stdoutput, flags);
20524
20525 /* We have run out flags in the COFF header to encode the
20526 status of ATPCS support, so instead we create a dummy,
c19d1205 20527 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
20528 if (atpcs)
20529 {
20530 asection * sec;
20531
20532 sec = bfd_make_section (stdoutput, ".arm.atpcs");
20533
20534 if (sec != NULL)
20535 {
20536 bfd_set_section_flags
20537 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
20538 bfd_set_section_size (stdoutput, sec, 0);
20539 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
20540 }
20541 }
7cc69913 20542 }
f17c130b 20543#endif
b99bd4ef
NC
20544
20545 /* Record the CPU type as well. */
2d447fca
JM
20546 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
20547 mach = bfd_mach_arm_iWMMXt2;
20548 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 20549 mach = bfd_mach_arm_iWMMXt;
e74cfd16 20550 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 20551 mach = bfd_mach_arm_XScale;
e74cfd16 20552 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 20553 mach = bfd_mach_arm_ep9312;
e74cfd16 20554 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 20555 mach = bfd_mach_arm_5TE;
e74cfd16 20556 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 20557 {
e74cfd16 20558 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
20559 mach = bfd_mach_arm_5T;
20560 else
20561 mach = bfd_mach_arm_5;
20562 }
e74cfd16 20563 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 20564 {
e74cfd16 20565 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
20566 mach = bfd_mach_arm_4T;
20567 else
20568 mach = bfd_mach_arm_4;
20569 }
e74cfd16 20570 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 20571 mach = bfd_mach_arm_3M;
e74cfd16
PB
20572 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
20573 mach = bfd_mach_arm_3;
20574 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
20575 mach = bfd_mach_arm_2a;
20576 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
20577 mach = bfd_mach_arm_2;
20578 else
20579 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
20580
20581 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
20582}
20583
c19d1205 20584/* Command line processing. */
b99bd4ef 20585
c19d1205
ZW
20586/* md_parse_option
20587 Invocation line includes a switch not recognized by the base assembler.
20588 See if it's a processor-specific option.
b99bd4ef 20589
c19d1205
ZW
20590 This routine is somewhat complicated by the need for backwards
20591 compatibility (since older releases of gcc can't be changed).
20592 The new options try to make the interface as compatible as
20593 possible with GCC.
b99bd4ef 20594
c19d1205 20595 New options (supported) are:
b99bd4ef 20596
c19d1205
ZW
20597 -mcpu=<cpu name> Assemble for selected processor
20598 -march=<architecture name> Assemble for selected architecture
20599 -mfpu=<fpu architecture> Assemble for selected FPU.
20600 -EB/-mbig-endian Big-endian
20601 -EL/-mlittle-endian Little-endian
20602 -k Generate PIC code
20603 -mthumb Start in Thumb mode
20604 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 20605
278df34e 20606 -m[no-]warn-deprecated Warn about deprecated features
267bf995 20607
c19d1205 20608 For now we will also provide support for:
b99bd4ef 20609
c19d1205
ZW
20610 -mapcs-32 32-bit Program counter
20611 -mapcs-26 26-bit Program counter
20612 -macps-float Floats passed in FP registers
20613 -mapcs-reentrant Reentrant code
20614 -matpcs
20615 (sometime these will probably be replaced with -mapcs=<list of options>
20616 and -matpcs=<list of options>)
b99bd4ef 20617
c19d1205
ZW
20618 The remaining options are only supported for back-wards compatibility.
20619 Cpu variants, the arm part is optional:
20620 -m[arm]1 Currently not supported.
20621 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
20622 -m[arm]3 Arm 3 processor
20623 -m[arm]6[xx], Arm 6 processors
20624 -m[arm]7[xx][t][[d]m] Arm 7 processors
20625 -m[arm]8[10] Arm 8 processors
20626 -m[arm]9[20][tdmi] Arm 9 processors
20627 -mstrongarm[110[0]] StrongARM processors
20628 -mxscale XScale processors
20629 -m[arm]v[2345[t[e]]] Arm architectures
20630 -mall All (except the ARM1)
20631 FP variants:
20632 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
20633 -mfpe-old (No float load/store multiples)
20634 -mvfpxd VFP Single precision
20635 -mvfp All VFP
20636 -mno-fpu Disable all floating point instructions
b99bd4ef 20637
c19d1205
ZW
20638 The following CPU names are recognized:
20639 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
20640 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
20641 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
20642 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
20643 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
20644 arm10t arm10e, arm1020t, arm1020e, arm10200e,
20645 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 20646
c19d1205 20647 */
b99bd4ef 20648
c19d1205 20649const char * md_shortopts = "m:k";
b99bd4ef 20650
c19d1205
ZW
20651#ifdef ARM_BI_ENDIAN
20652#define OPTION_EB (OPTION_MD_BASE + 0)
20653#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 20654#else
c19d1205
ZW
20655#if TARGET_BYTES_BIG_ENDIAN
20656#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 20657#else
c19d1205
ZW
20658#define OPTION_EL (OPTION_MD_BASE + 1)
20659#endif
b99bd4ef 20660#endif
845b51d6 20661#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 20662
c19d1205 20663struct option md_longopts[] =
b99bd4ef 20664{
c19d1205
ZW
20665#ifdef OPTION_EB
20666 {"EB", no_argument, NULL, OPTION_EB},
20667#endif
20668#ifdef OPTION_EL
20669 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 20670#endif
845b51d6 20671 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
20672 {NULL, no_argument, NULL, 0}
20673};
b99bd4ef 20674
c19d1205 20675size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 20676
c19d1205 20677struct arm_option_table
b99bd4ef 20678{
c19d1205
ZW
20679 char *option; /* Option name to match. */
20680 char *help; /* Help information. */
20681 int *var; /* Variable to change. */
20682 int value; /* What to change it to. */
20683 char *deprecated; /* If non-null, print this message. */
20684};
b99bd4ef 20685
c19d1205
ZW
20686struct arm_option_table arm_opts[] =
20687{
20688 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
20689 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
20690 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
20691 &support_interwork, 1, NULL},
20692 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
20693 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
20694 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
20695 1, NULL},
20696 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
20697 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
20698 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
20699 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
20700 NULL},
b99bd4ef 20701
c19d1205
ZW
20702 /* These are recognized by the assembler, but have no affect on code. */
20703 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
20704 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
20705
20706 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
20707 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
20708 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
20709 {NULL, NULL, NULL, 0, NULL}
20710};
20711
20712struct arm_legacy_option_table
20713{
20714 char *option; /* Option name to match. */
20715 const arm_feature_set **var; /* Variable to change. */
20716 const arm_feature_set value; /* What to change it to. */
20717 char *deprecated; /* If non-null, print this message. */
20718};
b99bd4ef 20719
e74cfd16
PB
20720const struct arm_legacy_option_table arm_legacy_opts[] =
20721{
c19d1205
ZW
20722 /* DON'T add any new processors to this list -- we want the whole list
20723 to go away... Add them to the processors table instead. */
e74cfd16
PB
20724 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20725 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
20726 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20727 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
20728 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20729 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
20730 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20731 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
20732 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20733 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
20734 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20735 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
20736 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20737 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
20738 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20739 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
20740 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20741 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
20742 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20743 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
20744 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20745 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
20746 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20747 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
20748 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20749 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
20750 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20751 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
20752 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20753 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
20754 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20755 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
20756 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20757 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
20758 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20759 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
20760 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20761 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
20762 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20763 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
20764 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20765 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
20766 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20767 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
20768 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20769 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
20770 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20771 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20772 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20773 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
20774 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20775 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
20776 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20777 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
20778 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20779 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
20780 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20781 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
20782 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20783 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
20784 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20785 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
20786 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20787 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
20788 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20789 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
20790 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20791 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
20792 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
20793 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20794 N_("use -mcpu=strongarm110")},
e74cfd16 20795 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20796 N_("use -mcpu=strongarm1100")},
e74cfd16 20797 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 20798 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
20799 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
20800 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
20801 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 20802
c19d1205 20803 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
20804 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20805 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
20806 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20807 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
20808 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20809 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
20810 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20811 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
20812 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20813 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
20814 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20815 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
20816 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20817 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
20818 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20819 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
20820 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
20821 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 20822
c19d1205 20823 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
20824 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
20825 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
20826 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
20827 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 20828 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 20829
e74cfd16 20830 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 20831};
7ed4c4c5 20832
c19d1205 20833struct arm_cpu_option_table
7ed4c4c5 20834{
c19d1205 20835 char *name;
e74cfd16 20836 const arm_feature_set value;
c19d1205
ZW
20837 /* For some CPUs we assume an FPU unless the user explicitly sets
20838 -mfpu=... */
e74cfd16 20839 const arm_feature_set default_fpu;
ee065d83
PB
20840 /* The canonical name of the CPU, or NULL to use NAME converted to upper
20841 case. */
20842 const char *canonical_name;
c19d1205 20843};
7ed4c4c5 20844
c19d1205
ZW
20845/* This list should, at a minimum, contain all the cpu names
20846 recognized by GCC. */
e74cfd16 20847static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 20848{
ee065d83
PB
20849 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
20850 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20851 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20852 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20853 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20854 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20855 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20856 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20857 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20858 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20859 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20860 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20861 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20862 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20863 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20864 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20865 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20866 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20867 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20868 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20869 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20870 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20871 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20872 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20873 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20874 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20875 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20876 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20877 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20878 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20879 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20880 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20881 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20882 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20883 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20884 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20885 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20886 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20887 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20888 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20889 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20890 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20891 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20892 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
20893 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20894 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20895 /* For V5 or later processors we default to using VFP; but the user
20896 should really set the FPU type explicitly. */
ee065d83
PB
20897 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20898 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20899 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20900 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20901 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20902 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20903 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20904 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20905 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20906 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20907 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20908 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20909 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20910 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20911 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20912 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20913 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20914 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20915 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20916 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20917 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
20918 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
20919 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
20920 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20921 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20922 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20923 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20924 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20925 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20926 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20927 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20928 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20929 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20930 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20931 | FPU_NEON_EXT_V1),
15290f0a
PB
20932 NULL},
20933 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20934 | FPU_NEON_EXT_V1),
5287ad62 20935 NULL},
62b3e311
PB
20936 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20937 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 20938 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 20939 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 20940 /* ??? XSCALE is really an architecture. */
ee065d83 20941 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20942 /* ??? iwmmxt is not a processor. */
ee065d83 20943 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20944 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20945 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20946 /* Maverick */
e74cfd16
PB
20947 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20948 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20949};
7ed4c4c5 20950
c19d1205 20951struct arm_arch_option_table
7ed4c4c5 20952{
c19d1205 20953 char *name;
e74cfd16
PB
20954 const arm_feature_set value;
20955 const arm_feature_set default_fpu;
c19d1205 20956};
7ed4c4c5 20957
c19d1205
ZW
20958/* This list should, at a minimum, contain all the architecture names
20959 recognized by GCC. */
e74cfd16 20960static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20961{
20962 {"all", ARM_ANY, FPU_ARCH_FPA},
20963 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20964 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20965 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20966 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20967 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20968 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20969 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20970 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20971 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20972 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20973 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20974 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20975 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20976 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20977 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20978 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20979 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20980 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20981 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20982 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20983 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20984 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20985 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20986 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20987 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 20988 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 20989 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20990 /* The official spelling of the ARMv7 profile variants is the dashed form.
20991 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20992 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20993 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20994 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20995 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20996 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20997 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20998 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20999 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 21000 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 21001 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 21002};
7ed4c4c5 21003
c19d1205 21004/* ISA extensions in the co-processor space. */
e74cfd16 21005struct arm_option_cpu_value_table
c19d1205
ZW
21006{
21007 char *name;
e74cfd16 21008 const arm_feature_set value;
c19d1205 21009};
7ed4c4c5 21010
e74cfd16 21011static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 21012{
e74cfd16
PB
21013 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
21014 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
21015 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 21016 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 21017 {NULL, ARM_ARCH_NONE}
c19d1205 21018};
7ed4c4c5 21019
c19d1205
ZW
21020/* This list should, at a minimum, contain all the fpu names
21021 recognized by GCC. */
e74cfd16 21022static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
21023{
21024 {"softfpa", FPU_NONE},
21025 {"fpe", FPU_ARCH_FPE},
21026 {"fpe2", FPU_ARCH_FPE},
21027 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
21028 {"fpa", FPU_ARCH_FPA},
21029 {"fpa10", FPU_ARCH_FPA},
21030 {"fpa11", FPU_ARCH_FPA},
21031 {"arm7500fe", FPU_ARCH_FPA},
21032 {"softvfp", FPU_ARCH_VFP},
21033 {"softvfp+vfp", FPU_ARCH_VFP_V2},
21034 {"vfp", FPU_ARCH_VFP_V2},
21035 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 21036 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
21037 {"vfp10", FPU_ARCH_VFP_V2},
21038 {"vfp10-r0", FPU_ARCH_VFP_V1},
21039 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
21040 {"vfpv2", FPU_ARCH_VFP_V2},
21041 {"vfpv3", FPU_ARCH_VFP_V3},
21042 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
21043 {"arm1020t", FPU_ARCH_VFP_V1},
21044 {"arm1020e", FPU_ARCH_VFP_V2},
21045 {"arm1136jfs", FPU_ARCH_VFP_V2},
21046 {"arm1136jf-s", FPU_ARCH_VFP_V2},
21047 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 21048 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 21049 {"neon-fp16", FPU_ARCH_NEON_FP16},
e74cfd16
PB
21050 {NULL, ARM_ARCH_NONE}
21051};
21052
21053struct arm_option_value_table
21054{
21055 char *name;
21056 long value;
c19d1205 21057};
7ed4c4c5 21058
e74cfd16 21059static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
21060{
21061 {"hard", ARM_FLOAT_ABI_HARD},
21062 {"softfp", ARM_FLOAT_ABI_SOFTFP},
21063 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 21064 {NULL, 0}
c19d1205 21065};
7ed4c4c5 21066
c19d1205 21067#ifdef OBJ_ELF
3a4a14e9 21068/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 21069static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
21070{
21071 {"gnu", EF_ARM_EABI_UNKNOWN},
21072 {"4", EF_ARM_EABI_VER4},
3a4a14e9 21073 {"5", EF_ARM_EABI_VER5},
e74cfd16 21074 {NULL, 0}
c19d1205
ZW
21075};
21076#endif
7ed4c4c5 21077
c19d1205
ZW
21078struct arm_long_option_table
21079{
21080 char * option; /* Substring to match. */
21081 char * help; /* Help information. */
21082 int (* func) (char * subopt); /* Function to decode sub-option. */
21083 char * deprecated; /* If non-null, print this message. */
21084};
7ed4c4c5
NC
21085
21086static int
e74cfd16 21087arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 21088{
e74cfd16
PB
21089 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
21090
21091 /* Copy the feature set, so that we can modify it. */
21092 *ext_set = **opt_p;
21093 *opt_p = ext_set;
21094
c19d1205 21095 while (str != NULL && *str != 0)
7ed4c4c5 21096 {
e74cfd16 21097 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
21098 char * ext;
21099 int optlen;
7ed4c4c5 21100
c19d1205
ZW
21101 if (*str != '+')
21102 {
21103 as_bad (_("invalid architectural extension"));
21104 return 0;
21105 }
7ed4c4c5 21106
c19d1205
ZW
21107 str++;
21108 ext = strchr (str, '+');
7ed4c4c5 21109
c19d1205
ZW
21110 if (ext != NULL)
21111 optlen = ext - str;
21112 else
21113 optlen = strlen (str);
7ed4c4c5 21114
c19d1205
ZW
21115 if (optlen == 0)
21116 {
21117 as_bad (_("missing architectural extension"));
21118 return 0;
21119 }
7ed4c4c5 21120
c19d1205
ZW
21121 for (opt = arm_extensions; opt->name != NULL; opt++)
21122 if (strncmp (opt->name, str, optlen) == 0)
21123 {
e74cfd16 21124 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
21125 break;
21126 }
7ed4c4c5 21127
c19d1205
ZW
21128 if (opt->name == NULL)
21129 {
5f4273c7 21130 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
21131 return 0;
21132 }
7ed4c4c5 21133
c19d1205
ZW
21134 str = ext;
21135 };
7ed4c4c5 21136
c19d1205
ZW
21137 return 1;
21138}
7ed4c4c5 21139
c19d1205
ZW
21140static int
21141arm_parse_cpu (char * str)
7ed4c4c5 21142{
e74cfd16 21143 const struct arm_cpu_option_table * opt;
c19d1205
ZW
21144 char * ext = strchr (str, '+');
21145 int optlen;
7ed4c4c5 21146
c19d1205
ZW
21147 if (ext != NULL)
21148 optlen = ext - str;
7ed4c4c5 21149 else
c19d1205 21150 optlen = strlen (str);
7ed4c4c5 21151
c19d1205 21152 if (optlen == 0)
7ed4c4c5 21153 {
c19d1205
ZW
21154 as_bad (_("missing cpu name `%s'"), str);
21155 return 0;
7ed4c4c5
NC
21156 }
21157
c19d1205
ZW
21158 for (opt = arm_cpus; opt->name != NULL; opt++)
21159 if (strncmp (opt->name, str, optlen) == 0)
21160 {
e74cfd16
PB
21161 mcpu_cpu_opt = &opt->value;
21162 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 21163 if (opt->canonical_name)
5f4273c7 21164 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21165 else
21166 {
21167 int i;
21168 for (i = 0; i < optlen; i++)
21169 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21170 selected_cpu_name[i] = 0;
21171 }
7ed4c4c5 21172
c19d1205
ZW
21173 if (ext != NULL)
21174 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 21175
c19d1205
ZW
21176 return 1;
21177 }
7ed4c4c5 21178
c19d1205
ZW
21179 as_bad (_("unknown cpu `%s'"), str);
21180 return 0;
7ed4c4c5
NC
21181}
21182
c19d1205
ZW
21183static int
21184arm_parse_arch (char * str)
7ed4c4c5 21185{
e74cfd16 21186 const struct arm_arch_option_table *opt;
c19d1205
ZW
21187 char *ext = strchr (str, '+');
21188 int optlen;
7ed4c4c5 21189
c19d1205
ZW
21190 if (ext != NULL)
21191 optlen = ext - str;
7ed4c4c5 21192 else
c19d1205 21193 optlen = strlen (str);
7ed4c4c5 21194
c19d1205 21195 if (optlen == 0)
7ed4c4c5 21196 {
c19d1205
ZW
21197 as_bad (_("missing architecture name `%s'"), str);
21198 return 0;
7ed4c4c5
NC
21199 }
21200
c19d1205
ZW
21201 for (opt = arm_archs; opt->name != NULL; opt++)
21202 if (streq (opt->name, str))
21203 {
e74cfd16
PB
21204 march_cpu_opt = &opt->value;
21205 march_fpu_opt = &opt->default_fpu;
5f4273c7 21206 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 21207
c19d1205
ZW
21208 if (ext != NULL)
21209 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 21210
c19d1205
ZW
21211 return 1;
21212 }
21213
21214 as_bad (_("unknown architecture `%s'\n"), str);
21215 return 0;
7ed4c4c5 21216}
eb043451 21217
c19d1205
ZW
21218static int
21219arm_parse_fpu (char * str)
21220{
e74cfd16 21221 const struct arm_option_cpu_value_table * opt;
b99bd4ef 21222
c19d1205
ZW
21223 for (opt = arm_fpus; opt->name != NULL; opt++)
21224 if (streq (opt->name, str))
21225 {
e74cfd16 21226 mfpu_opt = &opt->value;
c19d1205
ZW
21227 return 1;
21228 }
b99bd4ef 21229
c19d1205
ZW
21230 as_bad (_("unknown floating point format `%s'\n"), str);
21231 return 0;
21232}
21233
21234static int
21235arm_parse_float_abi (char * str)
b99bd4ef 21236{
e74cfd16 21237 const struct arm_option_value_table * opt;
b99bd4ef 21238
c19d1205
ZW
21239 for (opt = arm_float_abis; opt->name != NULL; opt++)
21240 if (streq (opt->name, str))
21241 {
21242 mfloat_abi_opt = opt->value;
21243 return 1;
21244 }
cc8a6dd0 21245
c19d1205
ZW
21246 as_bad (_("unknown floating point abi `%s'\n"), str);
21247 return 0;
21248}
b99bd4ef 21249
c19d1205
ZW
21250#ifdef OBJ_ELF
21251static int
21252arm_parse_eabi (char * str)
21253{
e74cfd16 21254 const struct arm_option_value_table *opt;
cc8a6dd0 21255
c19d1205
ZW
21256 for (opt = arm_eabis; opt->name != NULL; opt++)
21257 if (streq (opt->name, str))
21258 {
21259 meabi_flags = opt->value;
21260 return 1;
21261 }
21262 as_bad (_("unknown EABI `%s'\n"), str);
21263 return 0;
21264}
21265#endif
cc8a6dd0 21266
c19d1205
ZW
21267struct arm_long_option_table arm_long_opts[] =
21268{
21269 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21270 arm_parse_cpu, NULL},
21271 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21272 arm_parse_arch, NULL},
21273 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21274 arm_parse_fpu, NULL},
21275 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21276 arm_parse_float_abi, NULL},
21277#ifdef OBJ_ELF
7fac0536 21278 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
21279 arm_parse_eabi, NULL},
21280#endif
21281 {NULL, NULL, 0, NULL}
21282};
cc8a6dd0 21283
c19d1205
ZW
21284int
21285md_parse_option (int c, char * arg)
21286{
21287 struct arm_option_table *opt;
e74cfd16 21288 const struct arm_legacy_option_table *fopt;
c19d1205 21289 struct arm_long_option_table *lopt;
b99bd4ef 21290
c19d1205 21291 switch (c)
b99bd4ef 21292 {
c19d1205
ZW
21293#ifdef OPTION_EB
21294 case OPTION_EB:
21295 target_big_endian = 1;
21296 break;
21297#endif
cc8a6dd0 21298
c19d1205
ZW
21299#ifdef OPTION_EL
21300 case OPTION_EL:
21301 target_big_endian = 0;
21302 break;
21303#endif
b99bd4ef 21304
845b51d6
PB
21305 case OPTION_FIX_V4BX:
21306 fix_v4bx = TRUE;
21307 break;
21308
c19d1205
ZW
21309 case 'a':
21310 /* Listing option. Just ignore these, we don't support additional
21311 ones. */
21312 return 0;
b99bd4ef 21313
c19d1205
ZW
21314 default:
21315 for (opt = arm_opts; opt->option != NULL; opt++)
21316 {
21317 if (c == opt->option[0]
21318 && ((arg == NULL && opt->option[1] == 0)
21319 || streq (arg, opt->option + 1)))
21320 {
c19d1205 21321 /* If the option is deprecated, tell the user. */
278df34e 21322 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
21323 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21324 arg ? arg : "", _(opt->deprecated));
b99bd4ef 21325
c19d1205
ZW
21326 if (opt->var != NULL)
21327 *opt->var = opt->value;
cc8a6dd0 21328
c19d1205
ZW
21329 return 1;
21330 }
21331 }
b99bd4ef 21332
e74cfd16
PB
21333 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21334 {
21335 if (c == fopt->option[0]
21336 && ((arg == NULL && fopt->option[1] == 0)
21337 || streq (arg, fopt->option + 1)))
21338 {
e74cfd16 21339 /* If the option is deprecated, tell the user. */
278df34e 21340 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
21341 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21342 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
21343
21344 if (fopt->var != NULL)
21345 *fopt->var = &fopt->value;
21346
21347 return 1;
21348 }
21349 }
21350
c19d1205
ZW
21351 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21352 {
21353 /* These options are expected to have an argument. */
21354 if (c == lopt->option[0]
21355 && arg != NULL
21356 && strncmp (arg, lopt->option + 1,
21357 strlen (lopt->option + 1)) == 0)
21358 {
c19d1205 21359 /* If the option is deprecated, tell the user. */
278df34e 21360 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
21361 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21362 _(lopt->deprecated));
b99bd4ef 21363
c19d1205
ZW
21364 /* Call the sup-option parser. */
21365 return lopt->func (arg + strlen (lopt->option) - 1);
21366 }
21367 }
a737bd4d 21368
c19d1205
ZW
21369 return 0;
21370 }
a394c00f 21371
c19d1205
ZW
21372 return 1;
21373}
a394c00f 21374
c19d1205
ZW
21375void
21376md_show_usage (FILE * fp)
a394c00f 21377{
c19d1205
ZW
21378 struct arm_option_table *opt;
21379 struct arm_long_option_table *lopt;
a394c00f 21380
c19d1205 21381 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 21382
c19d1205
ZW
21383 for (opt = arm_opts; opt->option != NULL; opt++)
21384 if (opt->help != NULL)
21385 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 21386
c19d1205
ZW
21387 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21388 if (lopt->help != NULL)
21389 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 21390
c19d1205
ZW
21391#ifdef OPTION_EB
21392 fprintf (fp, _("\
21393 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
21394#endif
21395
c19d1205
ZW
21396#ifdef OPTION_EL
21397 fprintf (fp, _("\
21398 -EL assemble code for a little-endian cpu\n"));
a737bd4d 21399#endif
845b51d6
PB
21400
21401 fprintf (fp, _("\
21402 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 21403}
ee065d83
PB
21404
21405
21406#ifdef OBJ_ELF
62b3e311
PB
21407typedef struct
21408{
21409 int val;
21410 arm_feature_set flags;
21411} cpu_arch_ver_table;
21412
21413/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21414 least features first. */
21415static const cpu_arch_ver_table cpu_arch_ver[] =
21416{
21417 {1, ARM_ARCH_V4},
21418 {2, ARM_ARCH_V4T},
21419 {3, ARM_ARCH_V5},
ee3c0378 21420 {3, ARM_ARCH_V5T},
62b3e311
PB
21421 {4, ARM_ARCH_V5TE},
21422 {5, ARM_ARCH_V5TEJ},
21423 {6, ARM_ARCH_V6},
21424 {7, ARM_ARCH_V6Z},
7e806470 21425 {9, ARM_ARCH_V6K},
91e22acd 21426 {11, ARM_ARCH_V6M},
7e806470 21427 {8, ARM_ARCH_V6T2},
62b3e311
PB
21428 {10, ARM_ARCH_V7A},
21429 {10, ARM_ARCH_V7R},
21430 {10, ARM_ARCH_V7M},
21431 {0, ARM_ARCH_NONE}
21432};
21433
ee3c0378
AS
21434/* Set an attribute if it has not already been set by the user. */
21435static void
21436aeabi_set_attribute_int (int tag, int value)
21437{
21438 if (tag < 1
21439 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21440 || !attributes_set_explicitly[tag])
21441 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21442}
21443
21444static void
21445aeabi_set_attribute_string (int tag, const char *value)
21446{
21447 if (tag < 1
21448 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21449 || !attributes_set_explicitly[tag])
21450 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21451}
21452
ee065d83
PB
21453/* Set the public EABI object attributes. */
21454static void
21455aeabi_set_public_attributes (void)
21456{
21457 int arch;
e74cfd16 21458 arm_feature_set flags;
62b3e311
PB
21459 arm_feature_set tmp;
21460 const cpu_arch_ver_table *p;
ee065d83
PB
21461
21462 /* Choose the architecture based on the capabilities of the requested cpu
21463 (if any) and/or the instructions actually used. */
e74cfd16
PB
21464 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
21465 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
21466 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
21467 /*Allow the user to override the reported architecture. */
21468 if (object_arch)
21469 {
21470 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
21471 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
21472 }
21473
62b3e311
PB
21474 tmp = flags;
21475 arch = 0;
21476 for (p = cpu_arch_ver; p->val; p++)
21477 {
21478 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
21479 {
21480 arch = p->val;
21481 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
21482 }
21483 }
ee065d83
PB
21484
21485 /* Tag_CPU_name. */
21486 if (selected_cpu_name[0])
21487 {
21488 char *p;
21489
21490 p = selected_cpu_name;
5f4273c7 21491 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
21492 {
21493 int i;
5f4273c7 21494
ee065d83
PB
21495 p += 4;
21496 for (i = 0; p[i]; i++)
21497 p[i] = TOUPPER (p[i]);
21498 }
ee3c0378 21499 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83
PB
21500 }
21501 /* Tag_CPU_arch. */
ee3c0378 21502 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62b3e311
PB
21503 /* Tag_CPU_arch_profile. */
21504 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 21505 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 21506 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 21507 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 21508 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 21509 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
ee065d83 21510 /* Tag_ARM_ISA_use. */
ee3c0378
AS
21511 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
21512 || arch == 0)
21513 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
ee065d83 21514 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
21515 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
21516 || arch == 0)
21517 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
21518 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
ee065d83 21519 /* Tag_VFP_arch. */
ee3c0378
AS
21520 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
21521 aeabi_set_attribute_int (Tag_VFP_arch, 3);
21522 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
21523 aeabi_set_attribute_int (Tag_VFP_arch, 4);
21524 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
21525 aeabi_set_attribute_int (Tag_VFP_arch, 2);
21526 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
21527 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
21528 aeabi_set_attribute_int (Tag_VFP_arch, 1);
ee065d83 21529 /* Tag_WMMX_arch. */
ee3c0378
AS
21530 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
21531 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
21532 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
21533 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
21534 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 21535 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
ee3c0378
AS
21536 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
21537 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
8e79c3df 21538 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
ee3c0378 21539 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
21540}
21541
104d59d1 21542/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
21543void
21544arm_md_end (void)
21545{
ee065d83
PB
21546 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
21547 return;
21548
21549 aeabi_set_public_attributes ();
ee065d83 21550}
8463be01 21551#endif /* OBJ_ELF */
ee065d83
PB
21552
21553
21554/* Parse a .cpu directive. */
21555
21556static void
21557s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
21558{
e74cfd16 21559 const struct arm_cpu_option_table *opt;
ee065d83
PB
21560 char *name;
21561 char saved_char;
21562
21563 name = input_line_pointer;
5f4273c7 21564 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21565 input_line_pointer++;
21566 saved_char = *input_line_pointer;
21567 *input_line_pointer = 0;
21568
21569 /* Skip the first "all" entry. */
21570 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
21571 if (streq (opt->name, name))
21572 {
e74cfd16
PB
21573 mcpu_cpu_opt = &opt->value;
21574 selected_cpu = opt->value;
ee065d83 21575 if (opt->canonical_name)
5f4273c7 21576 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21577 else
21578 {
21579 int i;
21580 for (i = 0; opt->name[i]; i++)
21581 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21582 selected_cpu_name[i] = 0;
21583 }
e74cfd16 21584 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21585 *input_line_pointer = saved_char;
21586 demand_empty_rest_of_line ();
21587 return;
21588 }
21589 as_bad (_("unknown cpu `%s'"), name);
21590 *input_line_pointer = saved_char;
21591 ignore_rest_of_line ();
21592}
21593
21594
21595/* Parse a .arch directive. */
21596
21597static void
21598s_arm_arch (int ignored ATTRIBUTE_UNUSED)
21599{
e74cfd16 21600 const struct arm_arch_option_table *opt;
ee065d83
PB
21601 char saved_char;
21602 char *name;
21603
21604 name = input_line_pointer;
5f4273c7 21605 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21606 input_line_pointer++;
21607 saved_char = *input_line_pointer;
21608 *input_line_pointer = 0;
21609
21610 /* Skip the first "all" entry. */
21611 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21612 if (streq (opt->name, name))
21613 {
e74cfd16
PB
21614 mcpu_cpu_opt = &opt->value;
21615 selected_cpu = opt->value;
5f4273c7 21616 strcpy (selected_cpu_name, opt->name);
e74cfd16 21617 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21618 *input_line_pointer = saved_char;
21619 demand_empty_rest_of_line ();
21620 return;
21621 }
21622
21623 as_bad (_("unknown architecture `%s'\n"), name);
21624 *input_line_pointer = saved_char;
21625 ignore_rest_of_line ();
21626}
21627
21628
7a1d4c38
PB
21629/* Parse a .object_arch directive. */
21630
21631static void
21632s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
21633{
21634 const struct arm_arch_option_table *opt;
21635 char saved_char;
21636 char *name;
21637
21638 name = input_line_pointer;
5f4273c7 21639 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
21640 input_line_pointer++;
21641 saved_char = *input_line_pointer;
21642 *input_line_pointer = 0;
21643
21644 /* Skip the first "all" entry. */
21645 for (opt = arm_archs + 1; opt->name != NULL; opt++)
21646 if (streq (opt->name, name))
21647 {
21648 object_arch = &opt->value;
21649 *input_line_pointer = saved_char;
21650 demand_empty_rest_of_line ();
21651 return;
21652 }
21653
21654 as_bad (_("unknown architecture `%s'\n"), name);
21655 *input_line_pointer = saved_char;
21656 ignore_rest_of_line ();
21657}
21658
ee065d83
PB
21659/* Parse a .fpu directive. */
21660
21661static void
21662s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
21663{
e74cfd16 21664 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
21665 char saved_char;
21666 char *name;
21667
21668 name = input_line_pointer;
5f4273c7 21669 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
21670 input_line_pointer++;
21671 saved_char = *input_line_pointer;
21672 *input_line_pointer = 0;
5f4273c7 21673
ee065d83
PB
21674 for (opt = arm_fpus; opt->name != NULL; opt++)
21675 if (streq (opt->name, name))
21676 {
e74cfd16
PB
21677 mfpu_opt = &opt->value;
21678 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
21679 *input_line_pointer = saved_char;
21680 demand_empty_rest_of_line ();
21681 return;
21682 }
21683
21684 as_bad (_("unknown floating point format `%s'\n"), name);
21685 *input_line_pointer = saved_char;
21686 ignore_rest_of_line ();
21687}
ee065d83 21688
794ba86a 21689/* Copy symbol information. */
f31fef98 21690
794ba86a
DJ
21691void
21692arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
21693{
21694 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
21695}
e04befd0 21696
f31fef98 21697#ifdef OBJ_ELF
e04befd0
AS
21698/* Given a symbolic attribute NAME, return the proper integer value.
21699 Returns -1 if the attribute is not known. */
f31fef98 21700
e04befd0
AS
21701int
21702arm_convert_symbolic_attribute (const char *name)
21703{
f31fef98
NC
21704 static const struct
21705 {
21706 const char * name;
21707 const int tag;
21708 }
21709 attribute_table[] =
21710 {
21711 /* When you modify this table you should
21712 also modify the list in doc/c-arm.texi. */
e04befd0 21713#define T(tag) {#tag, tag}
f31fef98
NC
21714 T (Tag_CPU_raw_name),
21715 T (Tag_CPU_name),
21716 T (Tag_CPU_arch),
21717 T (Tag_CPU_arch_profile),
21718 T (Tag_ARM_ISA_use),
21719 T (Tag_THUMB_ISA_use),
21720 T (Tag_VFP_arch),
21721 T (Tag_WMMX_arch),
21722 T (Tag_Advanced_SIMD_arch),
21723 T (Tag_PCS_config),
21724 T (Tag_ABI_PCS_R9_use),
21725 T (Tag_ABI_PCS_RW_data),
21726 T (Tag_ABI_PCS_RO_data),
21727 T (Tag_ABI_PCS_GOT_use),
21728 T (Tag_ABI_PCS_wchar_t),
21729 T (Tag_ABI_FP_rounding),
21730 T (Tag_ABI_FP_denormal),
21731 T (Tag_ABI_FP_exceptions),
21732 T (Tag_ABI_FP_user_exceptions),
21733 T (Tag_ABI_FP_number_model),
21734 T (Tag_ABI_align8_needed),
21735 T (Tag_ABI_align8_preserved),
21736 T (Tag_ABI_enum_size),
21737 T (Tag_ABI_HardFP_use),
21738 T (Tag_ABI_VFP_args),
21739 T (Tag_ABI_WMMX_args),
21740 T (Tag_ABI_optimization_goals),
21741 T (Tag_ABI_FP_optimization_goals),
21742 T (Tag_compatibility),
21743 T (Tag_CPU_unaligned_access),
21744 T (Tag_VFP_HP_extension),
21745 T (Tag_ABI_FP_16bit_format),
21746 T (Tag_nodefaults),
21747 T (Tag_also_compatible_with),
21748 T (Tag_conformance),
21749 T (Tag_T2EE_use),
21750 T (Tag_Virtualization_use),
21751 T (Tag_MPextension_use)
e04befd0 21752#undef T
f31fef98 21753 };
e04befd0
AS
21754 unsigned int i;
21755
21756 if (name == NULL)
21757 return -1;
21758
f31fef98 21759 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
e04befd0
AS
21760 if (strcmp (name, attribute_table[i].name) == 0)
21761 return attribute_table[i].tag;
21762
21763 return -1;
21764}
267bf995
RR
21765
21766
21767/* Apply sym value for relocations only in the case that
21768 they are for local symbols and you have the respective
21769 architectural feature for blx and simple switches. */
21770int
21771arm_apply_sym_value (struct fix * fixP)
21772{
21773 if (fixP->fx_addsy
21774 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
21775 && !S_IS_EXTERNAL (fixP->fx_addsy))
21776 {
21777 switch (fixP->fx_r_type)
21778 {
21779 case BFD_RELOC_ARM_PCREL_BLX:
21780 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21781 if (ARM_IS_FUNC (fixP->fx_addsy))
21782 return 1;
21783 break;
21784
21785 case BFD_RELOC_ARM_PCREL_CALL:
21786 case BFD_RELOC_THUMB_PCREL_BLX:
21787 if (THUMB_IS_FUNC (fixP->fx_addsy))
21788 return 1;
21789 break;
21790
21791 default:
21792 break;
21793 }
21794
21795 }
21796 return 0;
21797}
f31fef98 21798#endif /* OBJ_ELF */
267bf995
RR
21799
21800
This page took 1.878616 seconds and 4 git commands to generate.