2007-06-29 Paul Brook <paul@codesourcery.com>
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
ebd1c875 3 2004, 2005, 2006
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
5287ad62 28#include <limits.h>
037e8744 29#include <stdarg.h>
c19d1205 30#define NO_RELOC 0
b99bd4ef 31#include "as.h"
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
720abc60 45#define WARN_DEPRECATED 1
03b1477f 46
7ed4c4c5
NC
47#ifdef OBJ_ELF
48/* Must be at least the size of the largest unwind opcode (currently two). */
49#define ARM_OPCODE_CHUNK_SIZE 8
50
51/* This structure holds the unwinding state. */
52
53static struct
54{
c19d1205
ZW
55 symbolS * proc_start;
56 symbolS * table_entry;
57 symbolS * personality_routine;
58 int personality_index;
7ed4c4c5 59 /* The segment containing the function. */
c19d1205
ZW
60 segT saved_seg;
61 subsegT saved_subseg;
7ed4c4c5
NC
62 /* Opcodes generated from this function. */
63 unsigned char * opcodes;
c19d1205
ZW
64 int opcode_count;
65 int opcode_alloc;
7ed4c4c5 66 /* The number of bytes pushed to the stack. */
c19d1205 67 offsetT frame_size;
7ed4c4c5
NC
68 /* We don't add stack adjustment opcodes immediately so that we can merge
69 multiple adjustments. We can also omit the final adjustment
70 when using a frame pointer. */
c19d1205 71 offsetT pending_offset;
7ed4c4c5 72 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
73 hold the reg+offset to use when restoring sp from a frame pointer. */
74 offsetT fp_offset;
75 int fp_reg;
7ed4c4c5 76 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 77 unsigned fp_used:1;
7ed4c4c5 78 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 79 unsigned sp_restored:1;
7ed4c4c5
NC
80} unwind;
81
8b1ad454
NC
82/* Bit N indicates that an R_ARM_NONE relocation has been output for
83 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
84 emitted only once per section, to save unnecessary bloat. */
85static unsigned int marked_pr_dependency = 0;
86
87#endif /* OBJ_ELF */
88
4962c51a
MS
89/* Results from operand parsing worker functions. */
90
91typedef enum
92{
93 PARSE_OPERAND_SUCCESS,
94 PARSE_OPERAND_FAIL,
95 PARSE_OPERAND_FAIL_NO_BACKTRACK
96} parse_operand_result;
97
33a392fb
PB
98enum arm_float_abi
99{
100 ARM_FLOAT_ABI_HARD,
101 ARM_FLOAT_ABI_SOFTFP,
102 ARM_FLOAT_ABI_SOFT
103};
104
c19d1205 105/* Types of processor to assemble for. */
b99bd4ef
NC
106#ifndef CPU_DEFAULT
107#if defined __XSCALE__
e74cfd16 108#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
109#else
110#if defined __thumb__
e74cfd16 111#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
112#endif
113#endif
114#endif
115
116#ifndef FPU_DEFAULT
c820d418
MM
117# ifdef TE_LINUX
118# define FPU_DEFAULT FPU_ARCH_FPA
119# elif defined (TE_NetBSD)
120# ifdef OBJ_ELF
121# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
122# else
123 /* Legacy a.out format. */
124# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
125# endif
4e7fd91e
PB
126# elif defined (TE_VXWORKS)
127# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
128# else
129 /* For backwards compatibility, default to FPA. */
130# define FPU_DEFAULT FPU_ARCH_FPA
131# endif
132#endif /* ifndef FPU_DEFAULT */
b99bd4ef 133
c19d1205 134#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 135
e74cfd16
PB
136static arm_feature_set cpu_variant;
137static arm_feature_set arm_arch_used;
138static arm_feature_set thumb_arch_used;
b99bd4ef 139
b99bd4ef 140/* Flags stored in private area of BFD structure. */
c19d1205
ZW
141static int uses_apcs_26 = FALSE;
142static int atpcs = FALSE;
b34976b6
AM
143static int support_interwork = FALSE;
144static int uses_apcs_float = FALSE;
c19d1205 145static int pic_code = FALSE;
03b1477f
RE
146
147/* Variables that we set while parsing command-line options. Once all
148 options have been read we re-process these values to set the real
149 assembly flags. */
e74cfd16
PB
150static const arm_feature_set *legacy_cpu = NULL;
151static const arm_feature_set *legacy_fpu = NULL;
152
153static const arm_feature_set *mcpu_cpu_opt = NULL;
154static const arm_feature_set *mcpu_fpu_opt = NULL;
155static const arm_feature_set *march_cpu_opt = NULL;
156static const arm_feature_set *march_fpu_opt = NULL;
157static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 158static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
159
160/* Constants for known architecture features. */
161static const arm_feature_set fpu_default = FPU_DEFAULT;
162static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
163static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
164static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
165static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
166static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
167static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
168static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
169static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
170
171#ifdef CPU_DEFAULT
172static const arm_feature_set cpu_default = CPU_DEFAULT;
173#endif
174
175static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
176static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
177static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
178static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
179static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
180static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
181static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
182static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
183static const arm_feature_set arm_ext_v4t_5 =
184 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
185static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
186static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
187static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
188static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
189static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
190static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
191static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
192static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311
PB
193static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
194static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
198static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
e74cfd16
PB
199
200static const arm_feature_set arm_arch_any = ARM_ANY;
201static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
202static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
203static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
204
2d447fca
JM
205static const arm_feature_set arm_cext_iwmmxt2 =
206 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
207static const arm_feature_set arm_cext_iwmmxt =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
209static const arm_feature_set arm_cext_xscale =
210 ARM_FEATURE (0, ARM_CEXT_XSCALE);
211static const arm_feature_set arm_cext_maverick =
212 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
213static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
214static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
215static const arm_feature_set fpu_vfp_ext_v1xd =
216 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
217static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
218static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62
JB
219static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
220static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
221static const arm_feature_set fpu_vfp_v3_or_neon_ext =
222 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
e74cfd16 223
33a392fb 224static int mfloat_abi_opt = -1;
e74cfd16
PB
225/* Record user cpu selection for object attributes. */
226static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
227/* Must be long enough to hold any of the names in arm_cpus. */
228static char selected_cpu_name[16];
7cc69913 229#ifdef OBJ_ELF
deeaaff8
DJ
230# ifdef EABI_DEFAULT
231static int meabi_flags = EABI_DEFAULT;
232# else
d507cf36 233static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 234# endif
e1da3f5b
PB
235
236bfd_boolean
237arm_is_eabi(void)
238{
239 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
240}
7cc69913 241#endif
b99bd4ef 242
b99bd4ef 243#ifdef OBJ_ELF
c19d1205 244/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
245symbolS * GOT_symbol;
246#endif
247
b99bd4ef
NC
248/* 0: assemble for ARM,
249 1: assemble for Thumb,
250 2: assemble for Thumb even though target CPU does not support thumb
251 instructions. */
252static int thumb_mode = 0;
253
c19d1205
ZW
254/* If unified_syntax is true, we are processing the new unified
255 ARM/Thumb syntax. Important differences from the old ARM mode:
256
257 - Immediate operands do not require a # prefix.
258 - Conditional affixes always appear at the end of the
259 instruction. (For backward compatibility, those instructions
260 that formerly had them in the middle, continue to accept them
261 there.)
262 - The IT instruction may appear, and if it does is validated
263 against subsequent conditional affixes. It does not generate
264 machine code.
265
266 Important differences from the old Thumb mode:
267
268 - Immediate operands do not require a # prefix.
269 - Most of the V6T2 instructions are only available in unified mode.
270 - The .N and .W suffixes are recognized and honored (it is an error
271 if they cannot be honored).
272 - All instructions set the flags if and only if they have an 's' affix.
273 - Conditional affixes may be used. They are validated against
274 preceding IT instructions. Unlike ARM mode, you cannot use a
275 conditional affix except in the scope of an IT instruction. */
276
277static bfd_boolean unified_syntax = FALSE;
b99bd4ef 278
5287ad62
JB
279enum neon_el_type
280{
dcbf9037 281 NT_invtype,
5287ad62
JB
282 NT_untyped,
283 NT_integer,
284 NT_float,
285 NT_poly,
286 NT_signed,
dcbf9037 287 NT_unsigned
5287ad62
JB
288};
289
290struct neon_type_el
291{
292 enum neon_el_type type;
293 unsigned size;
294};
295
296#define NEON_MAX_TYPE_ELS 4
297
298struct neon_type
299{
300 struct neon_type_el el[NEON_MAX_TYPE_ELS];
301 unsigned elems;
302};
303
b99bd4ef
NC
304struct arm_it
305{
c19d1205 306 const char * error;
b99bd4ef 307 unsigned long instruction;
c19d1205
ZW
308 int size;
309 int size_req;
310 int cond;
037e8744
JB
311 /* "uncond_value" is set to the value in place of the conditional field in
312 unconditional versions of the instruction, or -1 if nothing is
313 appropriate. */
314 int uncond_value;
5287ad62 315 struct neon_type vectype;
0110f2b8
PB
316 /* Set to the opcode if the instruction needs relaxation.
317 Zero if the instruction is not relaxed. */
318 unsigned long relax;
b99bd4ef
NC
319 struct
320 {
321 bfd_reloc_code_real_type type;
c19d1205
ZW
322 expressionS exp;
323 int pc_rel;
b99bd4ef 324 } reloc;
b99bd4ef 325
c19d1205
ZW
326 struct
327 {
328 unsigned reg;
ca3f61f7 329 signed int imm;
dcbf9037 330 struct neon_type_el vectype;
ca3f61f7
NC
331 unsigned present : 1; /* Operand present. */
332 unsigned isreg : 1; /* Operand was a register. */
333 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
334 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
335 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 336 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
337 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
338 instructions. This allows us to disambiguate ARM <-> vector insns. */
339 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 340 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 341 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 342 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
343 unsigned hasreloc : 1; /* Operand has relocation suffix. */
344 unsigned writeback : 1; /* Operand has trailing ! */
345 unsigned preind : 1; /* Preindexed address. */
346 unsigned postind : 1; /* Postindexed address. */
347 unsigned negative : 1; /* Index register was negated. */
348 unsigned shifted : 1; /* Shift applied to operation. */
349 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 350 } operands[6];
b99bd4ef
NC
351};
352
c19d1205 353static struct arm_it inst;
b99bd4ef
NC
354
355#define NUM_FLOAT_VALS 8
356
05d2d07e 357const char * fp_const[] =
b99bd4ef
NC
358{
359 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
360};
361
c19d1205 362/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
363#define MAX_LITTLENUMS 6
364
365LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
366
367#define FAIL (-1)
368#define SUCCESS (0)
369
370#define SUFF_S 1
371#define SUFF_D 2
372#define SUFF_E 3
373#define SUFF_P 4
374
c19d1205
ZW
375#define CP_T_X 0x00008000
376#define CP_T_Y 0x00400000
b99bd4ef 377
c19d1205
ZW
378#define CONDS_BIT 0x00100000
379#define LOAD_BIT 0x00100000
b99bd4ef
NC
380
381#define DOUBLE_LOAD_FLAG 0x00000001
382
383struct asm_cond
384{
c19d1205 385 const char * template;
b99bd4ef
NC
386 unsigned long value;
387};
388
c19d1205 389#define COND_ALWAYS 0xE
b99bd4ef 390
b99bd4ef
NC
391struct asm_psr
392{
b34976b6 393 const char *template;
b99bd4ef
NC
394 unsigned long field;
395};
396
62b3e311
PB
397struct asm_barrier_opt
398{
399 const char *template;
400 unsigned long value;
401};
402
2d2255b5 403/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
404#define SPSR_BIT (1 << 22)
405
c19d1205
ZW
406/* The individual PSR flag bits. */
407#define PSR_c (1 << 16)
408#define PSR_x (1 << 17)
409#define PSR_s (1 << 18)
410#define PSR_f (1 << 19)
b99bd4ef 411
c19d1205 412struct reloc_entry
bfae80f2 413{
c19d1205
ZW
414 char *name;
415 bfd_reloc_code_real_type reloc;
bfae80f2
RE
416};
417
5287ad62 418enum vfp_reg_pos
bfae80f2 419{
5287ad62
JB
420 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
421 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
422};
423
424enum vfp_ldstm_type
425{
426 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
427};
428
dcbf9037
JB
429/* Bits for DEFINED field in neon_typed_alias. */
430#define NTA_HASTYPE 1
431#define NTA_HASINDEX 2
432
433struct neon_typed_alias
434{
435 unsigned char defined;
436 unsigned char index;
437 struct neon_type_el eltype;
438};
439
c19d1205
ZW
440/* ARM register categories. This includes coprocessor numbers and various
441 architecture extensions' registers. */
442enum arm_reg_type
bfae80f2 443{
c19d1205
ZW
444 REG_TYPE_RN,
445 REG_TYPE_CP,
446 REG_TYPE_CN,
447 REG_TYPE_FN,
448 REG_TYPE_VFS,
449 REG_TYPE_VFD,
5287ad62 450 REG_TYPE_NQ,
037e8744 451 REG_TYPE_VFSD,
5287ad62 452 REG_TYPE_NDQ,
037e8744 453 REG_TYPE_NSDQ,
c19d1205
ZW
454 REG_TYPE_VFC,
455 REG_TYPE_MVF,
456 REG_TYPE_MVD,
457 REG_TYPE_MVFX,
458 REG_TYPE_MVDX,
459 REG_TYPE_MVAX,
460 REG_TYPE_DSPSC,
461 REG_TYPE_MMXWR,
462 REG_TYPE_MMXWC,
463 REG_TYPE_MMXWCG,
464 REG_TYPE_XSCALE,
bfae80f2
RE
465};
466
dcbf9037
JB
467/* Structure for a hash table entry for a register.
468 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
469 information which states whether a vector type or index is specified (for a
470 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
471struct reg_entry
472{
dcbf9037
JB
473 const char *name;
474 unsigned char number;
475 unsigned char type;
476 unsigned char builtin;
477 struct neon_typed_alias *neon;
6c43fab6
RE
478};
479
c19d1205
ZW
480/* Diagnostics used when we don't get a register of the expected type. */
481const char *const reg_expected_msgs[] =
482{
483 N_("ARM register expected"),
484 N_("bad or missing co-processor number"),
485 N_("co-processor register expected"),
486 N_("FPA register expected"),
487 N_("VFP single precision register expected"),
5287ad62
JB
488 N_("VFP/Neon double precision register expected"),
489 N_("Neon quad precision register expected"),
037e8744 490 N_("VFP single or double precision register expected"),
5287ad62 491 N_("Neon double or quad precision register expected"),
037e8744 492 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
493 N_("VFP system register expected"),
494 N_("Maverick MVF register expected"),
495 N_("Maverick MVD register expected"),
496 N_("Maverick MVFX register expected"),
497 N_("Maverick MVDX register expected"),
498 N_("Maverick MVAX register expected"),
499 N_("Maverick DSPSC register expected"),
500 N_("iWMMXt data register expected"),
501 N_("iWMMXt control register expected"),
502 N_("iWMMXt scalar register expected"),
503 N_("XScale accumulator register expected"),
6c43fab6
RE
504};
505
c19d1205
ZW
506/* Some well known registers that we refer to directly elsewhere. */
507#define REG_SP 13
508#define REG_LR 14
509#define REG_PC 15
404ff6b5 510
b99bd4ef
NC
511/* ARM instructions take 4bytes in the object file, Thumb instructions
512 take 2: */
c19d1205 513#define INSN_SIZE 4
b99bd4ef
NC
514
515struct asm_opcode
516{
517 /* Basic string to match. */
c19d1205
ZW
518 const char *template;
519
520 /* Parameters to instruction. */
521 unsigned char operands[8];
522
523 /* Conditional tag - see opcode_lookup. */
524 unsigned int tag : 4;
b99bd4ef
NC
525
526 /* Basic instruction code. */
c19d1205 527 unsigned int avalue : 28;
b99bd4ef 528
c19d1205
ZW
529 /* Thumb-format instruction code. */
530 unsigned int tvalue;
b99bd4ef 531
90e4755a 532 /* Which architecture variant provides this instruction. */
e74cfd16
PB
533 const arm_feature_set *avariant;
534 const arm_feature_set *tvariant;
c19d1205
ZW
535
536 /* Function to call to encode instruction in ARM format. */
537 void (* aencode) (void);
b99bd4ef 538
c19d1205
ZW
539 /* Function to call to encode instruction in Thumb format. */
540 void (* tencode) (void);
b99bd4ef
NC
541};
542
a737bd4d
NC
543/* Defines for various bits that we will want to toggle. */
544#define INST_IMMEDIATE 0x02000000
545#define OFFSET_REG 0x02000000
c19d1205 546#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
547#define SHIFT_BY_REG 0x00000010
548#define PRE_INDEX 0x01000000
549#define INDEX_UP 0x00800000
550#define WRITE_BACK 0x00200000
551#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 552#define CPSI_MMOD 0x00020000
90e4755a 553
a737bd4d
NC
554#define LITERAL_MASK 0xf000f000
555#define OPCODE_MASK 0xfe1fffff
556#define V4_STR_BIT 0x00000020
90e4755a 557
efd81785
PB
558#define T2_SUBS_PC_LR 0xf3de8f00
559
a737bd4d 560#define DATA_OP_SHIFT 21
90e4755a 561
ef8d22e6
PB
562#define T2_OPCODE_MASK 0xfe1fffff
563#define T2_DATA_OP_SHIFT 21
564
a737bd4d
NC
565/* Codes to distinguish the arithmetic instructions. */
566#define OPCODE_AND 0
567#define OPCODE_EOR 1
568#define OPCODE_SUB 2
569#define OPCODE_RSB 3
570#define OPCODE_ADD 4
571#define OPCODE_ADC 5
572#define OPCODE_SBC 6
573#define OPCODE_RSC 7
574#define OPCODE_TST 8
575#define OPCODE_TEQ 9
576#define OPCODE_CMP 10
577#define OPCODE_CMN 11
578#define OPCODE_ORR 12
579#define OPCODE_MOV 13
580#define OPCODE_BIC 14
581#define OPCODE_MVN 15
90e4755a 582
ef8d22e6
PB
583#define T2_OPCODE_AND 0
584#define T2_OPCODE_BIC 1
585#define T2_OPCODE_ORR 2
586#define T2_OPCODE_ORN 3
587#define T2_OPCODE_EOR 4
588#define T2_OPCODE_ADD 8
589#define T2_OPCODE_ADC 10
590#define T2_OPCODE_SBC 11
591#define T2_OPCODE_SUB 13
592#define T2_OPCODE_RSB 14
593
a737bd4d
NC
594#define T_OPCODE_MUL 0x4340
595#define T_OPCODE_TST 0x4200
596#define T_OPCODE_CMN 0x42c0
597#define T_OPCODE_NEG 0x4240
598#define T_OPCODE_MVN 0x43c0
90e4755a 599
a737bd4d
NC
600#define T_OPCODE_ADD_R3 0x1800
601#define T_OPCODE_SUB_R3 0x1a00
602#define T_OPCODE_ADD_HI 0x4400
603#define T_OPCODE_ADD_ST 0xb000
604#define T_OPCODE_SUB_ST 0xb080
605#define T_OPCODE_ADD_SP 0xa800
606#define T_OPCODE_ADD_PC 0xa000
607#define T_OPCODE_ADD_I8 0x3000
608#define T_OPCODE_SUB_I8 0x3800
609#define T_OPCODE_ADD_I3 0x1c00
610#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 611
a737bd4d
NC
612#define T_OPCODE_ASR_R 0x4100
613#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
614#define T_OPCODE_LSR_R 0x40c0
615#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
616#define T_OPCODE_ASR_I 0x1000
617#define T_OPCODE_LSL_I 0x0000
618#define T_OPCODE_LSR_I 0x0800
b99bd4ef 619
a737bd4d
NC
620#define T_OPCODE_MOV_I8 0x2000
621#define T_OPCODE_CMP_I8 0x2800
622#define T_OPCODE_CMP_LR 0x4280
623#define T_OPCODE_MOV_HR 0x4600
624#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 625
a737bd4d
NC
626#define T_OPCODE_LDR_PC 0x4800
627#define T_OPCODE_LDR_SP 0x9800
628#define T_OPCODE_STR_SP 0x9000
629#define T_OPCODE_LDR_IW 0x6800
630#define T_OPCODE_STR_IW 0x6000
631#define T_OPCODE_LDR_IH 0x8800
632#define T_OPCODE_STR_IH 0x8000
633#define T_OPCODE_LDR_IB 0x7800
634#define T_OPCODE_STR_IB 0x7000
635#define T_OPCODE_LDR_RW 0x5800
636#define T_OPCODE_STR_RW 0x5000
637#define T_OPCODE_LDR_RH 0x5a00
638#define T_OPCODE_STR_RH 0x5200
639#define T_OPCODE_LDR_RB 0x5c00
640#define T_OPCODE_STR_RB 0x5400
c9b604bd 641
a737bd4d
NC
642#define T_OPCODE_PUSH 0xb400
643#define T_OPCODE_POP 0xbc00
b99bd4ef 644
2fc8bdac 645#define T_OPCODE_BRANCH 0xe000
b99bd4ef 646
a737bd4d 647#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 648#define THUMB_PP_PC_LR 0x0100
c19d1205 649#define THUMB_LOAD_BIT 0x0800
53365c0d 650#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
651
652#define BAD_ARGS _("bad arguments to instruction")
653#define BAD_PC _("r15 not allowed here")
654#define BAD_COND _("instruction cannot be conditional")
655#define BAD_OVERLAP _("registers may not be the same")
656#define BAD_HIREG _("lo register required")
657#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 658#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
659#define BAD_BRANCH _("branch must be last instruction in IT block")
660#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 661#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
662
663static struct hash_control *arm_ops_hsh;
664static struct hash_control *arm_cond_hsh;
665static struct hash_control *arm_shift_hsh;
666static struct hash_control *arm_psr_hsh;
62b3e311 667static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
668static struct hash_control *arm_reg_hsh;
669static struct hash_control *arm_reloc_hsh;
62b3e311 670static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 671
b99bd4ef
NC
672/* Stuff needed to resolve the label ambiguity
673 As:
674 ...
675 label: <insn>
676 may differ from:
677 ...
678 label:
c19d1205 679 <insn>
b99bd4ef
NC
680*/
681
682symbolS * last_label_seen;
b34976b6 683static int label_is_thumb_function_name = FALSE;
a737bd4d 684\f
3d0c9500
NC
685/* Literal pool structure. Held on a per-section
686 and per-sub-section basis. */
a737bd4d 687
c19d1205 688#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 689typedef struct literal_pool
b99bd4ef 690{
c19d1205
ZW
691 expressionS literals [MAX_LITERAL_POOL_SIZE];
692 unsigned int next_free_entry;
693 unsigned int id;
694 symbolS * symbol;
695 segT section;
696 subsegT sub_section;
61b5f74b 697 struct literal_pool * next;
3d0c9500 698} literal_pool;
b99bd4ef 699
3d0c9500
NC
700/* Pointer to a linked list of literal pools. */
701literal_pool * list_of_pools = NULL;
e27ec89e
PB
702
703/* State variables for IT block handling. */
704static bfd_boolean current_it_mask = 0;
705static int current_cc;
706
c19d1205
ZW
707\f
708/* Pure syntax. */
b99bd4ef 709
c19d1205
ZW
710/* This array holds the chars that always start a comment. If the
711 pre-processor is disabled, these aren't very useful. */
712const char comment_chars[] = "@";
3d0c9500 713
c19d1205
ZW
714/* This array holds the chars that only start a comment at the beginning of
715 a line. If the line seems to have the form '# 123 filename'
716 .line and .file directives will appear in the pre-processed output. */
717/* Note that input_file.c hand checks for '#' at the beginning of the
718 first line of the input file. This is because the compiler outputs
719 #NO_APP at the beginning of its output. */
720/* Also note that comments like this one will always work. */
721const char line_comment_chars[] = "#";
3d0c9500 722
c19d1205 723const char line_separator_chars[] = ";";
b99bd4ef 724
c19d1205
ZW
725/* Chars that can be used to separate mant
726 from exp in floating point numbers. */
727const char EXP_CHARS[] = "eE";
3d0c9500 728
c19d1205
ZW
729/* Chars that mean this number is a floating point constant. */
730/* As in 0f12.456 */
731/* or 0d1.2345e12 */
b99bd4ef 732
c19d1205 733const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 734
c19d1205
ZW
735/* Prefix characters that indicate the start of an immediate
736 value. */
737#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 738
c19d1205
ZW
739/* Separator character handling. */
740
741#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
742
743static inline int
744skip_past_char (char ** str, char c)
745{
746 if (**str == c)
747 {
748 (*str)++;
749 return SUCCESS;
3d0c9500 750 }
c19d1205
ZW
751 else
752 return FAIL;
753}
754#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 755
c19d1205
ZW
756/* Arithmetic expressions (possibly involving symbols). */
757
758/* Return TRUE if anything in the expression is a bignum. */
759
760static int
761walk_no_bignums (symbolS * sp)
762{
763 if (symbol_get_value_expression (sp)->X_op == O_big)
764 return 1;
765
766 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 767 {
c19d1205
ZW
768 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
769 || (symbol_get_value_expression (sp)->X_op_symbol
770 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
771 }
772
c19d1205 773 return 0;
3d0c9500
NC
774}
775
c19d1205
ZW
776static int in_my_get_expression = 0;
777
778/* Third argument to my_get_expression. */
779#define GE_NO_PREFIX 0
780#define GE_IMM_PREFIX 1
781#define GE_OPT_PREFIX 2
5287ad62
JB
782/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
783 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
784#define GE_OPT_PREFIX_BIG 3
a737bd4d 785
b99bd4ef 786static int
c19d1205 787my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 788{
c19d1205
ZW
789 char * save_in;
790 segT seg;
b99bd4ef 791
c19d1205
ZW
792 /* In unified syntax, all prefixes are optional. */
793 if (unified_syntax)
5287ad62
JB
794 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
795 : GE_OPT_PREFIX;
b99bd4ef 796
c19d1205 797 switch (prefix_mode)
b99bd4ef 798 {
c19d1205
ZW
799 case GE_NO_PREFIX: break;
800 case GE_IMM_PREFIX:
801 if (!is_immediate_prefix (**str))
802 {
803 inst.error = _("immediate expression requires a # prefix");
804 return FAIL;
805 }
806 (*str)++;
807 break;
808 case GE_OPT_PREFIX:
5287ad62 809 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
810 if (is_immediate_prefix (**str))
811 (*str)++;
812 break;
813 default: abort ();
814 }
b99bd4ef 815
c19d1205 816 memset (ep, 0, sizeof (expressionS));
b99bd4ef 817
c19d1205
ZW
818 save_in = input_line_pointer;
819 input_line_pointer = *str;
820 in_my_get_expression = 1;
821 seg = expression (ep);
822 in_my_get_expression = 0;
823
824 if (ep->X_op == O_illegal)
b99bd4ef 825 {
c19d1205
ZW
826 /* We found a bad expression in md_operand(). */
827 *str = input_line_pointer;
828 input_line_pointer = save_in;
829 if (inst.error == NULL)
830 inst.error = _("bad expression");
831 return 1;
832 }
b99bd4ef 833
c19d1205
ZW
834#ifdef OBJ_AOUT
835 if (seg != absolute_section
836 && seg != text_section
837 && seg != data_section
838 && seg != bss_section
839 && seg != undefined_section)
840 {
841 inst.error = _("bad segment");
842 *str = input_line_pointer;
843 input_line_pointer = save_in;
844 return 1;
b99bd4ef 845 }
c19d1205 846#endif
b99bd4ef 847
c19d1205
ZW
848 /* Get rid of any bignums now, so that we don't generate an error for which
849 we can't establish a line number later on. Big numbers are never valid
850 in instructions, which is where this routine is always called. */
5287ad62
JB
851 if (prefix_mode != GE_OPT_PREFIX_BIG
852 && (ep->X_op == O_big
853 || (ep->X_add_symbol
854 && (walk_no_bignums (ep->X_add_symbol)
855 || (ep->X_op_symbol
856 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
857 {
858 inst.error = _("invalid constant");
859 *str = input_line_pointer;
860 input_line_pointer = save_in;
861 return 1;
862 }
b99bd4ef 863
c19d1205
ZW
864 *str = input_line_pointer;
865 input_line_pointer = save_in;
866 return 0;
b99bd4ef
NC
867}
868
c19d1205
ZW
869/* Turn a string in input_line_pointer into a floating point constant
870 of type TYPE, and store the appropriate bytes in *LITP. The number
871 of LITTLENUMS emitted is stored in *SIZEP. An error message is
872 returned, or NULL on OK.
b99bd4ef 873
c19d1205
ZW
874 Note that fp constants aren't represent in the normal way on the ARM.
875 In big endian mode, things are as expected. However, in little endian
876 mode fp constants are big-endian word-wise, and little-endian byte-wise
877 within the words. For example, (double) 1.1 in big endian mode is
878 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
879 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 880
c19d1205 881 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 882
c19d1205
ZW
883char *
884md_atof (int type, char * litP, int * sizeP)
885{
886 int prec;
887 LITTLENUM_TYPE words[MAX_LITTLENUMS];
888 char *t;
889 int i;
b99bd4ef 890
c19d1205
ZW
891 switch (type)
892 {
893 case 'f':
894 case 'F':
895 case 's':
896 case 'S':
897 prec = 2;
898 break;
b99bd4ef 899
c19d1205
ZW
900 case 'd':
901 case 'D':
902 case 'r':
903 case 'R':
904 prec = 4;
905 break;
b99bd4ef 906
c19d1205
ZW
907 case 'x':
908 case 'X':
909 prec = 6;
910 break;
b99bd4ef 911
c19d1205
ZW
912 case 'p':
913 case 'P':
914 prec = 6;
915 break;
a737bd4d 916
c19d1205
ZW
917 default:
918 *sizeP = 0;
919 return _("bad call to MD_ATOF()");
920 }
b99bd4ef 921
c19d1205
ZW
922 t = atof_ieee (input_line_pointer, type, words);
923 if (t)
924 input_line_pointer = t;
925 *sizeP = prec * 2;
b99bd4ef 926
c19d1205
ZW
927 if (target_big_endian)
928 {
929 for (i = 0; i < prec; i++)
930 {
931 md_number_to_chars (litP, (valueT) words[i], 2);
932 litP += 2;
933 }
934 }
935 else
936 {
e74cfd16 937 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
938 for (i = prec - 1; i >= 0; i--)
939 {
940 md_number_to_chars (litP, (valueT) words[i], 2);
941 litP += 2;
942 }
943 else
944 /* For a 4 byte float the order of elements in `words' is 1 0.
945 For an 8 byte float the order is 1 0 3 2. */
946 for (i = 0; i < prec; i += 2)
947 {
948 md_number_to_chars (litP, (valueT) words[i + 1], 2);
949 md_number_to_chars (litP + 2, (valueT) words[i], 2);
950 litP += 4;
951 }
952 }
b99bd4ef 953
c19d1205
ZW
954 return 0;
955}
b99bd4ef 956
c19d1205
ZW
957/* We handle all bad expressions here, so that we can report the faulty
958 instruction in the error message. */
959void
960md_operand (expressionS * expr)
961{
962 if (in_my_get_expression)
963 expr->X_op = O_illegal;
b99bd4ef
NC
964}
965
c19d1205 966/* Immediate values. */
b99bd4ef 967
c19d1205
ZW
968/* Generic immediate-value read function for use in directives.
969 Accepts anything that 'expression' can fold to a constant.
970 *val receives the number. */
971#ifdef OBJ_ELF
972static int
973immediate_for_directive (int *val)
b99bd4ef 974{
c19d1205
ZW
975 expressionS exp;
976 exp.X_op = O_illegal;
b99bd4ef 977
c19d1205
ZW
978 if (is_immediate_prefix (*input_line_pointer))
979 {
980 input_line_pointer++;
981 expression (&exp);
982 }
b99bd4ef 983
c19d1205
ZW
984 if (exp.X_op != O_constant)
985 {
986 as_bad (_("expected #constant"));
987 ignore_rest_of_line ();
988 return FAIL;
989 }
990 *val = exp.X_add_number;
991 return SUCCESS;
b99bd4ef 992}
c19d1205 993#endif
b99bd4ef 994
c19d1205 995/* Register parsing. */
b99bd4ef 996
c19d1205
ZW
997/* Generic register parser. CCP points to what should be the
998 beginning of a register name. If it is indeed a valid register
999 name, advance CCP over it and return the reg_entry structure;
1000 otherwise return NULL. Does not issue diagnostics. */
1001
1002static struct reg_entry *
1003arm_reg_parse_multi (char **ccp)
b99bd4ef 1004{
c19d1205
ZW
1005 char *start = *ccp;
1006 char *p;
1007 struct reg_entry *reg;
b99bd4ef 1008
c19d1205
ZW
1009#ifdef REGISTER_PREFIX
1010 if (*start != REGISTER_PREFIX)
01cfc07f 1011 return NULL;
c19d1205
ZW
1012 start++;
1013#endif
1014#ifdef OPTIONAL_REGISTER_PREFIX
1015 if (*start == OPTIONAL_REGISTER_PREFIX)
1016 start++;
1017#endif
b99bd4ef 1018
c19d1205
ZW
1019 p = start;
1020 if (!ISALPHA (*p) || !is_name_beginner (*p))
1021 return NULL;
b99bd4ef 1022
c19d1205
ZW
1023 do
1024 p++;
1025 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1026
1027 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1028
1029 if (!reg)
1030 return NULL;
1031
1032 *ccp = p;
1033 return reg;
b99bd4ef
NC
1034}
1035
1036static int
dcbf9037
JB
1037arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1038 enum arm_reg_type type)
b99bd4ef 1039{
c19d1205
ZW
1040 /* Alternative syntaxes are accepted for a few register classes. */
1041 switch (type)
1042 {
1043 case REG_TYPE_MVF:
1044 case REG_TYPE_MVD:
1045 case REG_TYPE_MVFX:
1046 case REG_TYPE_MVDX:
1047 /* Generic coprocessor register names are allowed for these. */
79134647 1048 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1049 return reg->number;
1050 break;
69b97547 1051
c19d1205
ZW
1052 case REG_TYPE_CP:
1053 /* For backward compatibility, a bare number is valid here. */
1054 {
1055 unsigned long processor = strtoul (start, ccp, 10);
1056 if (*ccp != start && processor <= 15)
1057 return processor;
1058 }
6057a28f 1059
c19d1205
ZW
1060 case REG_TYPE_MMXWC:
1061 /* WC includes WCG. ??? I'm not sure this is true for all
1062 instructions that take WC registers. */
79134647 1063 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1064 return reg->number;
6057a28f 1065 break;
c19d1205 1066
6057a28f 1067 default:
c19d1205 1068 break;
6057a28f
NC
1069 }
1070
dcbf9037
JB
1071 return FAIL;
1072}
1073
1074/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1075 return value is the register number or FAIL. */
1076
1077static int
1078arm_reg_parse (char **ccp, enum arm_reg_type type)
1079{
1080 char *start = *ccp;
1081 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1082 int ret;
1083
1084 /* Do not allow a scalar (reg+index) to parse as a register. */
1085 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1086 return FAIL;
1087
1088 if (reg && reg->type == type)
1089 return reg->number;
1090
1091 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1092 return ret;
1093
c19d1205
ZW
1094 *ccp = start;
1095 return FAIL;
1096}
69b97547 1097
dcbf9037
JB
1098/* Parse a Neon type specifier. *STR should point at the leading '.'
1099 character. Does no verification at this stage that the type fits the opcode
1100 properly. E.g.,
1101
1102 .i32.i32.s16
1103 .s32.f32
1104 .u16
1105
1106 Can all be legally parsed by this function.
1107
1108 Fills in neon_type struct pointer with parsed information, and updates STR
1109 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1110 type, FAIL if not. */
1111
1112static int
1113parse_neon_type (struct neon_type *type, char **str)
1114{
1115 char *ptr = *str;
1116
1117 if (type)
1118 type->elems = 0;
1119
1120 while (type->elems < NEON_MAX_TYPE_ELS)
1121 {
1122 enum neon_el_type thistype = NT_untyped;
1123 unsigned thissize = -1u;
1124
1125 if (*ptr != '.')
1126 break;
1127
1128 ptr++;
1129
1130 /* Just a size without an explicit type. */
1131 if (ISDIGIT (*ptr))
1132 goto parsesize;
1133
1134 switch (TOLOWER (*ptr))
1135 {
1136 case 'i': thistype = NT_integer; break;
1137 case 'f': thistype = NT_float; break;
1138 case 'p': thistype = NT_poly; break;
1139 case 's': thistype = NT_signed; break;
1140 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1141 case 'd':
1142 thistype = NT_float;
1143 thissize = 64;
1144 ptr++;
1145 goto done;
dcbf9037
JB
1146 default:
1147 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1148 return FAIL;
1149 }
1150
1151 ptr++;
1152
1153 /* .f is an abbreviation for .f32. */
1154 if (thistype == NT_float && !ISDIGIT (*ptr))
1155 thissize = 32;
1156 else
1157 {
1158 parsesize:
1159 thissize = strtoul (ptr, &ptr, 10);
1160
1161 if (thissize != 8 && thissize != 16 && thissize != 32
1162 && thissize != 64)
1163 {
1164 as_bad (_("bad size %d in type specifier"), thissize);
1165 return FAIL;
1166 }
1167 }
1168
037e8744 1169 done:
dcbf9037
JB
1170 if (type)
1171 {
1172 type->el[type->elems].type = thistype;
1173 type->el[type->elems].size = thissize;
1174 type->elems++;
1175 }
1176 }
1177
1178 /* Empty/missing type is not a successful parse. */
1179 if (type->elems == 0)
1180 return FAIL;
1181
1182 *str = ptr;
1183
1184 return SUCCESS;
1185}
1186
1187/* Errors may be set multiple times during parsing or bit encoding
1188 (particularly in the Neon bits), but usually the earliest error which is set
1189 will be the most meaningful. Avoid overwriting it with later (cascading)
1190 errors by calling this function. */
1191
1192static void
1193first_error (const char *err)
1194{
1195 if (!inst.error)
1196 inst.error = err;
1197}
1198
1199/* Parse a single type, e.g. ".s32", leading period included. */
1200static int
1201parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1202{
1203 char *str = *ccp;
1204 struct neon_type optype;
1205
1206 if (*str == '.')
1207 {
1208 if (parse_neon_type (&optype, &str) == SUCCESS)
1209 {
1210 if (optype.elems == 1)
1211 *vectype = optype.el[0];
1212 else
1213 {
1214 first_error (_("only one type should be specified for operand"));
1215 return FAIL;
1216 }
1217 }
1218 else
1219 {
1220 first_error (_("vector type expected"));
1221 return FAIL;
1222 }
1223 }
1224 else
1225 return FAIL;
1226
1227 *ccp = str;
1228
1229 return SUCCESS;
1230}
1231
1232/* Special meanings for indices (which have a range of 0-7), which will fit into
1233 a 4-bit integer. */
1234
1235#define NEON_ALL_LANES 15
1236#define NEON_INTERLEAVE_LANES 14
1237
1238/* Parse either a register or a scalar, with an optional type. Return the
1239 register number, and optionally fill in the actual type of the register
1240 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1241 type/index information in *TYPEINFO. */
1242
1243static int
1244parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1245 enum arm_reg_type *rtype,
1246 struct neon_typed_alias *typeinfo)
1247{
1248 char *str = *ccp;
1249 struct reg_entry *reg = arm_reg_parse_multi (&str);
1250 struct neon_typed_alias atype;
1251 struct neon_type_el parsetype;
1252
1253 atype.defined = 0;
1254 atype.index = -1;
1255 atype.eltype.type = NT_invtype;
1256 atype.eltype.size = -1;
1257
1258 /* Try alternate syntax for some types of register. Note these are mutually
1259 exclusive with the Neon syntax extensions. */
1260 if (reg == NULL)
1261 {
1262 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1263 if (altreg != FAIL)
1264 *ccp = str;
1265 if (typeinfo)
1266 *typeinfo = atype;
1267 return altreg;
1268 }
1269
037e8744
JB
1270 /* Undo polymorphism when a set of register types may be accepted. */
1271 if ((type == REG_TYPE_NDQ
1272 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1273 || (type == REG_TYPE_VFSD
1274 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1275 || (type == REG_TYPE_NSDQ
1276 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1277 || reg->type == REG_TYPE_NQ))
1278 || (type == REG_TYPE_MMXWC
1279 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1280 type = reg->type;
1281
1282 if (type != reg->type)
1283 return FAIL;
1284
1285 if (reg->neon)
1286 atype = *reg->neon;
1287
1288 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1289 {
1290 if ((atype.defined & NTA_HASTYPE) != 0)
1291 {
1292 first_error (_("can't redefine type for operand"));
1293 return FAIL;
1294 }
1295 atype.defined |= NTA_HASTYPE;
1296 atype.eltype = parsetype;
1297 }
1298
1299 if (skip_past_char (&str, '[') == SUCCESS)
1300 {
1301 if (type != REG_TYPE_VFD)
1302 {
1303 first_error (_("only D registers may be indexed"));
1304 return FAIL;
1305 }
1306
1307 if ((atype.defined & NTA_HASINDEX) != 0)
1308 {
1309 first_error (_("can't change index for operand"));
1310 return FAIL;
1311 }
1312
1313 atype.defined |= NTA_HASINDEX;
1314
1315 if (skip_past_char (&str, ']') == SUCCESS)
1316 atype.index = NEON_ALL_LANES;
1317 else
1318 {
1319 expressionS exp;
1320
1321 my_get_expression (&exp, &str, GE_NO_PREFIX);
1322
1323 if (exp.X_op != O_constant)
1324 {
1325 first_error (_("constant expression required"));
1326 return FAIL;
1327 }
1328
1329 if (skip_past_char (&str, ']') == FAIL)
1330 return FAIL;
1331
1332 atype.index = exp.X_add_number;
1333 }
1334 }
1335
1336 if (typeinfo)
1337 *typeinfo = atype;
1338
1339 if (rtype)
1340 *rtype = type;
1341
1342 *ccp = str;
1343
1344 return reg->number;
1345}
1346
1347/* Like arm_reg_parse, but allow allow the following extra features:
1348 - If RTYPE is non-zero, return the (possibly restricted) type of the
1349 register (e.g. Neon double or quad reg when either has been requested).
1350 - If this is a Neon vector type with additional type information, fill
1351 in the struct pointed to by VECTYPE (if non-NULL).
1352 This function will fault on encountering a scalar.
1353*/
1354
1355static int
1356arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1357 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1358{
1359 struct neon_typed_alias atype;
1360 char *str = *ccp;
1361 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1362
1363 if (reg == FAIL)
1364 return FAIL;
1365
1366 /* Do not allow a scalar (reg+index) to parse as a register. */
1367 if ((atype.defined & NTA_HASINDEX) != 0)
1368 {
1369 first_error (_("register operand expected, but got scalar"));
1370 return FAIL;
1371 }
1372
1373 if (vectype)
1374 *vectype = atype.eltype;
1375
1376 *ccp = str;
1377
1378 return reg;
1379}
1380
1381#define NEON_SCALAR_REG(X) ((X) >> 4)
1382#define NEON_SCALAR_INDEX(X) ((X) & 15)
1383
5287ad62
JB
1384/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1385 have enough information to be able to do a good job bounds-checking. So, we
1386 just do easy checks here, and do further checks later. */
1387
1388static int
dcbf9037 1389parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1390{
dcbf9037 1391 int reg;
5287ad62 1392 char *str = *ccp;
dcbf9037 1393 struct neon_typed_alias atype;
5287ad62 1394
dcbf9037 1395 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5287ad62 1396
dcbf9037 1397 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62
JB
1398 return FAIL;
1399
dcbf9037 1400 if (atype.index == NEON_ALL_LANES)
5287ad62 1401 {
dcbf9037 1402 first_error (_("scalar must have an index"));
5287ad62
JB
1403 return FAIL;
1404 }
dcbf9037 1405 else if (atype.index >= 64 / elsize)
5287ad62 1406 {
dcbf9037 1407 first_error (_("scalar index out of range"));
5287ad62
JB
1408 return FAIL;
1409 }
1410
dcbf9037
JB
1411 if (type)
1412 *type = atype.eltype;
5287ad62 1413
5287ad62
JB
1414 *ccp = str;
1415
dcbf9037 1416 return reg * 16 + atype.index;
5287ad62
JB
1417}
1418
c19d1205
ZW
1419/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1420static long
1421parse_reg_list (char ** strp)
1422{
1423 char * str = * strp;
1424 long range = 0;
1425 int another_range;
a737bd4d 1426
c19d1205
ZW
1427 /* We come back here if we get ranges concatenated by '+' or '|'. */
1428 do
6057a28f 1429 {
c19d1205 1430 another_range = 0;
a737bd4d 1431
c19d1205
ZW
1432 if (*str == '{')
1433 {
1434 int in_range = 0;
1435 int cur_reg = -1;
a737bd4d 1436
c19d1205
ZW
1437 str++;
1438 do
1439 {
1440 int reg;
6057a28f 1441
dcbf9037 1442 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1443 {
dcbf9037 1444 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1445 return FAIL;
1446 }
a737bd4d 1447
c19d1205
ZW
1448 if (in_range)
1449 {
1450 int i;
a737bd4d 1451
c19d1205
ZW
1452 if (reg <= cur_reg)
1453 {
dcbf9037 1454 first_error (_("bad range in register list"));
c19d1205
ZW
1455 return FAIL;
1456 }
40a18ebd 1457
c19d1205
ZW
1458 for (i = cur_reg + 1; i < reg; i++)
1459 {
1460 if (range & (1 << i))
1461 as_tsktsk
1462 (_("Warning: duplicated register (r%d) in register list"),
1463 i);
1464 else
1465 range |= 1 << i;
1466 }
1467 in_range = 0;
1468 }
a737bd4d 1469
c19d1205
ZW
1470 if (range & (1 << reg))
1471 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1472 reg);
1473 else if (reg <= cur_reg)
1474 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1475
c19d1205
ZW
1476 range |= 1 << reg;
1477 cur_reg = reg;
1478 }
1479 while (skip_past_comma (&str) != FAIL
1480 || (in_range = 1, *str++ == '-'));
1481 str--;
a737bd4d 1482
c19d1205
ZW
1483 if (*str++ != '}')
1484 {
dcbf9037 1485 first_error (_("missing `}'"));
c19d1205
ZW
1486 return FAIL;
1487 }
1488 }
1489 else
1490 {
1491 expressionS expr;
40a18ebd 1492
c19d1205
ZW
1493 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1494 return FAIL;
40a18ebd 1495
c19d1205
ZW
1496 if (expr.X_op == O_constant)
1497 {
1498 if (expr.X_add_number
1499 != (expr.X_add_number & 0x0000ffff))
1500 {
1501 inst.error = _("invalid register mask");
1502 return FAIL;
1503 }
a737bd4d 1504
c19d1205
ZW
1505 if ((range & expr.X_add_number) != 0)
1506 {
1507 int regno = range & expr.X_add_number;
a737bd4d 1508
c19d1205
ZW
1509 regno &= -regno;
1510 regno = (1 << regno) - 1;
1511 as_tsktsk
1512 (_("Warning: duplicated register (r%d) in register list"),
1513 regno);
1514 }
a737bd4d 1515
c19d1205
ZW
1516 range |= expr.X_add_number;
1517 }
1518 else
1519 {
1520 if (inst.reloc.type != 0)
1521 {
1522 inst.error = _("expression too complex");
1523 return FAIL;
1524 }
a737bd4d 1525
c19d1205
ZW
1526 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1527 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1528 inst.reloc.pc_rel = 0;
1529 }
1530 }
a737bd4d 1531
c19d1205
ZW
1532 if (*str == '|' || *str == '+')
1533 {
1534 str++;
1535 another_range = 1;
1536 }
a737bd4d 1537 }
c19d1205 1538 while (another_range);
a737bd4d 1539
c19d1205
ZW
1540 *strp = str;
1541 return range;
a737bd4d
NC
1542}
1543
5287ad62
JB
1544/* Types of registers in a list. */
1545
1546enum reg_list_els
1547{
1548 REGLIST_VFP_S,
1549 REGLIST_VFP_D,
1550 REGLIST_NEON_D
1551};
1552
c19d1205
ZW
1553/* Parse a VFP register list. If the string is invalid return FAIL.
1554 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1555 register. Parses registers of type ETYPE.
1556 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1557 - Q registers can be used to specify pairs of D registers
1558 - { } can be omitted from around a singleton register list
1559 FIXME: This is not implemented, as it would require backtracking in
1560 some cases, e.g.:
1561 vtbl.8 d3,d4,d5
1562 This could be done (the meaning isn't really ambiguous), but doesn't
1563 fit in well with the current parsing framework.
dcbf9037
JB
1564 - 32 D registers may be used (also true for VFPv3).
1565 FIXME: Types are ignored in these register lists, which is probably a
1566 bug. */
6057a28f 1567
c19d1205 1568static int
037e8744 1569parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1570{
037e8744 1571 char *str = *ccp;
c19d1205
ZW
1572 int base_reg;
1573 int new_base;
5287ad62
JB
1574 enum arm_reg_type regtype = 0;
1575 int max_regs = 0;
c19d1205
ZW
1576 int count = 0;
1577 int warned = 0;
1578 unsigned long mask = 0;
a737bd4d 1579 int i;
6057a28f 1580
037e8744 1581 if (*str != '{')
5287ad62
JB
1582 {
1583 inst.error = _("expecting {");
1584 return FAIL;
1585 }
6057a28f 1586
037e8744 1587 str++;
6057a28f 1588
5287ad62 1589 switch (etype)
c19d1205 1590 {
5287ad62 1591 case REGLIST_VFP_S:
c19d1205
ZW
1592 regtype = REG_TYPE_VFS;
1593 max_regs = 32;
5287ad62
JB
1594 break;
1595
1596 case REGLIST_VFP_D:
1597 regtype = REG_TYPE_VFD;
b7fc2769
JB
1598 break;
1599
1600 case REGLIST_NEON_D:
1601 regtype = REG_TYPE_NDQ;
1602 break;
1603 }
1604
1605 if (etype != REGLIST_VFP_S)
1606 {
5287ad62
JB
1607 /* VFPv3 allows 32 D registers. */
1608 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1609 {
1610 max_regs = 32;
1611 if (thumb_mode)
1612 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1613 fpu_vfp_ext_v3);
1614 else
1615 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1616 fpu_vfp_ext_v3);
1617 }
1618 else
1619 max_regs = 16;
c19d1205 1620 }
6057a28f 1621
c19d1205 1622 base_reg = max_regs;
a737bd4d 1623
c19d1205
ZW
1624 do
1625 {
5287ad62 1626 int setmask = 1, addregs = 1;
dcbf9037 1627
037e8744 1628 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1629
c19d1205 1630 if (new_base == FAIL)
a737bd4d 1631 {
dcbf9037 1632 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1633 return FAIL;
1634 }
dcbf9037 1635
b7fc2769
JB
1636 if (new_base >= max_regs)
1637 {
1638 first_error (_("register out of range in list"));
1639 return FAIL;
1640 }
1641
5287ad62
JB
1642 /* Note: a value of 2 * n is returned for the register Q<n>. */
1643 if (regtype == REG_TYPE_NQ)
1644 {
1645 setmask = 3;
1646 addregs = 2;
1647 }
1648
c19d1205
ZW
1649 if (new_base < base_reg)
1650 base_reg = new_base;
a737bd4d 1651
5287ad62 1652 if (mask & (setmask << new_base))
c19d1205 1653 {
dcbf9037 1654 first_error (_("invalid register list"));
c19d1205 1655 return FAIL;
a737bd4d 1656 }
a737bd4d 1657
c19d1205
ZW
1658 if ((mask >> new_base) != 0 && ! warned)
1659 {
1660 as_tsktsk (_("register list not in ascending order"));
1661 warned = 1;
1662 }
0bbf2aa4 1663
5287ad62
JB
1664 mask |= setmask << new_base;
1665 count += addregs;
0bbf2aa4 1666
037e8744 1667 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1668 {
1669 int high_range;
0bbf2aa4 1670
037e8744 1671 str++;
0bbf2aa4 1672
037e8744 1673 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1674 == FAIL)
c19d1205
ZW
1675 {
1676 inst.error = gettext (reg_expected_msgs[regtype]);
1677 return FAIL;
1678 }
0bbf2aa4 1679
b7fc2769
JB
1680 if (high_range >= max_regs)
1681 {
1682 first_error (_("register out of range in list"));
1683 return FAIL;
1684 }
1685
5287ad62
JB
1686 if (regtype == REG_TYPE_NQ)
1687 high_range = high_range + 1;
1688
c19d1205
ZW
1689 if (high_range <= new_base)
1690 {
1691 inst.error = _("register range not in ascending order");
1692 return FAIL;
1693 }
0bbf2aa4 1694
5287ad62 1695 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1696 {
5287ad62 1697 if (mask & (setmask << new_base))
0bbf2aa4 1698 {
c19d1205
ZW
1699 inst.error = _("invalid register list");
1700 return FAIL;
0bbf2aa4 1701 }
c19d1205 1702
5287ad62
JB
1703 mask |= setmask << new_base;
1704 count += addregs;
0bbf2aa4 1705 }
0bbf2aa4 1706 }
0bbf2aa4 1707 }
037e8744 1708 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1709
037e8744 1710 str++;
0bbf2aa4 1711
c19d1205
ZW
1712 /* Sanity check -- should have raised a parse error above. */
1713 if (count == 0 || count > max_regs)
1714 abort ();
1715
1716 *pbase = base_reg;
1717
1718 /* Final test -- the registers must be consecutive. */
1719 mask >>= base_reg;
1720 for (i = 0; i < count; i++)
1721 {
1722 if ((mask & (1u << i)) == 0)
1723 {
1724 inst.error = _("non-contiguous register range");
1725 return FAIL;
1726 }
1727 }
1728
037e8744
JB
1729 *ccp = str;
1730
c19d1205 1731 return count;
b99bd4ef
NC
1732}
1733
dcbf9037
JB
1734/* True if two alias types are the same. */
1735
1736static int
1737neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1738{
1739 if (!a && !b)
1740 return 1;
1741
1742 if (!a || !b)
1743 return 0;
1744
1745 if (a->defined != b->defined)
1746 return 0;
1747
1748 if ((a->defined & NTA_HASTYPE) != 0
1749 && (a->eltype.type != b->eltype.type
1750 || a->eltype.size != b->eltype.size))
1751 return 0;
1752
1753 if ((a->defined & NTA_HASINDEX) != 0
1754 && (a->index != b->index))
1755 return 0;
1756
1757 return 1;
1758}
1759
5287ad62
JB
1760/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1761 The base register is put in *PBASE.
dcbf9037 1762 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1763 the return value.
1764 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1765 Bits [6:5] encode the list length (minus one).
1766 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1767
5287ad62 1768#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1769#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1770#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1771
1772static int
dcbf9037
JB
1773parse_neon_el_struct_list (char **str, unsigned *pbase,
1774 struct neon_type_el *eltype)
5287ad62
JB
1775{
1776 char *ptr = *str;
1777 int base_reg = -1;
1778 int reg_incr = -1;
1779 int count = 0;
1780 int lane = -1;
1781 int leading_brace = 0;
1782 enum arm_reg_type rtype = REG_TYPE_NDQ;
1783 int addregs = 1;
1784 const char *const incr_error = "register stride must be 1 or 2";
1785 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1786 struct neon_typed_alias firsttype;
5287ad62
JB
1787
1788 if (skip_past_char (&ptr, '{') == SUCCESS)
1789 leading_brace = 1;
1790
1791 do
1792 {
dcbf9037
JB
1793 struct neon_typed_alias atype;
1794 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1795
5287ad62
JB
1796 if (getreg == FAIL)
1797 {
dcbf9037 1798 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1799 return FAIL;
1800 }
1801
1802 if (base_reg == -1)
1803 {
1804 base_reg = getreg;
1805 if (rtype == REG_TYPE_NQ)
1806 {
1807 reg_incr = 1;
1808 addregs = 2;
1809 }
dcbf9037 1810 firsttype = atype;
5287ad62
JB
1811 }
1812 else if (reg_incr == -1)
1813 {
1814 reg_incr = getreg - base_reg;
1815 if (reg_incr < 1 || reg_incr > 2)
1816 {
dcbf9037 1817 first_error (_(incr_error));
5287ad62
JB
1818 return FAIL;
1819 }
1820 }
1821 else if (getreg != base_reg + reg_incr * count)
1822 {
dcbf9037
JB
1823 first_error (_(incr_error));
1824 return FAIL;
1825 }
1826
1827 if (!neon_alias_types_same (&atype, &firsttype))
1828 {
1829 first_error (_(type_error));
5287ad62
JB
1830 return FAIL;
1831 }
1832
1833 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1834 modes. */
1835 if (ptr[0] == '-')
1836 {
dcbf9037 1837 struct neon_typed_alias htype;
5287ad62
JB
1838 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1839 if (lane == -1)
1840 lane = NEON_INTERLEAVE_LANES;
1841 else if (lane != NEON_INTERLEAVE_LANES)
1842 {
dcbf9037 1843 first_error (_(type_error));
5287ad62
JB
1844 return FAIL;
1845 }
1846 if (reg_incr == -1)
1847 reg_incr = 1;
1848 else if (reg_incr != 1)
1849 {
dcbf9037 1850 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1851 return FAIL;
1852 }
1853 ptr++;
dcbf9037 1854 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1855 if (hireg == FAIL)
1856 {
dcbf9037
JB
1857 first_error (_(reg_expected_msgs[rtype]));
1858 return FAIL;
1859 }
1860 if (!neon_alias_types_same (&htype, &firsttype))
1861 {
1862 first_error (_(type_error));
5287ad62
JB
1863 return FAIL;
1864 }
1865 count += hireg + dregs - getreg;
1866 continue;
1867 }
1868
1869 /* If we're using Q registers, we can't use [] or [n] syntax. */
1870 if (rtype == REG_TYPE_NQ)
1871 {
1872 count += 2;
1873 continue;
1874 }
1875
dcbf9037 1876 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1877 {
dcbf9037
JB
1878 if (lane == -1)
1879 lane = atype.index;
1880 else if (lane != atype.index)
5287ad62 1881 {
dcbf9037
JB
1882 first_error (_(type_error));
1883 return FAIL;
5287ad62
JB
1884 }
1885 }
1886 else if (lane == -1)
1887 lane = NEON_INTERLEAVE_LANES;
1888 else if (lane != NEON_INTERLEAVE_LANES)
1889 {
dcbf9037 1890 first_error (_(type_error));
5287ad62
JB
1891 return FAIL;
1892 }
1893 count++;
1894 }
1895 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1896
1897 /* No lane set by [x]. We must be interleaving structures. */
1898 if (lane == -1)
1899 lane = NEON_INTERLEAVE_LANES;
1900
1901 /* Sanity check. */
1902 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1903 || (count > 1 && reg_incr == -1))
1904 {
dcbf9037 1905 first_error (_("error parsing element/structure list"));
5287ad62
JB
1906 return FAIL;
1907 }
1908
1909 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1910 {
dcbf9037 1911 first_error (_("expected }"));
5287ad62
JB
1912 return FAIL;
1913 }
1914
1915 if (reg_incr == -1)
1916 reg_incr = 1;
1917
dcbf9037
JB
1918 if (eltype)
1919 *eltype = firsttype.eltype;
1920
5287ad62
JB
1921 *pbase = base_reg;
1922 *str = ptr;
1923
1924 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1925}
1926
c19d1205
ZW
1927/* Parse an explicit relocation suffix on an expression. This is
1928 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1929 arm_reloc_hsh contains no entries, so this function can only
1930 succeed if there is no () after the word. Returns -1 on error,
1931 BFD_RELOC_UNUSED if there wasn't any suffix. */
1932static int
1933parse_reloc (char **str)
b99bd4ef 1934{
c19d1205
ZW
1935 struct reloc_entry *r;
1936 char *p, *q;
b99bd4ef 1937
c19d1205
ZW
1938 if (**str != '(')
1939 return BFD_RELOC_UNUSED;
b99bd4ef 1940
c19d1205
ZW
1941 p = *str + 1;
1942 q = p;
1943
1944 while (*q && *q != ')' && *q != ',')
1945 q++;
1946 if (*q != ')')
1947 return -1;
1948
1949 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1950 return -1;
1951
1952 *str = q + 1;
1953 return r->reloc;
b99bd4ef
NC
1954}
1955
c19d1205
ZW
1956/* Directives: register aliases. */
1957
dcbf9037 1958static struct reg_entry *
c19d1205 1959insert_reg_alias (char *str, int number, int type)
b99bd4ef 1960{
c19d1205
ZW
1961 struct reg_entry *new;
1962 const char *name;
b99bd4ef 1963
c19d1205
ZW
1964 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1965 {
1966 if (new->builtin)
1967 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1968
c19d1205
ZW
1969 /* Only warn about a redefinition if it's not defined as the
1970 same register. */
1971 else if (new->number != number || new->type != type)
1972 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1973
dcbf9037 1974 return 0;
c19d1205 1975 }
b99bd4ef 1976
c19d1205
ZW
1977 name = xstrdup (str);
1978 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1979
c19d1205
ZW
1980 new->name = name;
1981 new->number = number;
1982 new->type = type;
1983 new->builtin = FALSE;
dcbf9037 1984 new->neon = NULL;
b99bd4ef 1985
c19d1205
ZW
1986 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1987 abort ();
dcbf9037
JB
1988
1989 return new;
1990}
1991
1992static void
1993insert_neon_reg_alias (char *str, int number, int type,
1994 struct neon_typed_alias *atype)
1995{
1996 struct reg_entry *reg = insert_reg_alias (str, number, type);
1997
1998 if (!reg)
1999 {
2000 first_error (_("attempt to redefine typed alias"));
2001 return;
2002 }
2003
2004 if (atype)
2005 {
2006 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2007 *reg->neon = *atype;
2008 }
c19d1205 2009}
b99bd4ef 2010
c19d1205 2011/* Look for the .req directive. This is of the form:
b99bd4ef 2012
c19d1205 2013 new_register_name .req existing_register_name
b99bd4ef 2014
c19d1205
ZW
2015 If we find one, or if it looks sufficiently like one that we want to
2016 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 2017
c19d1205
ZW
2018static int
2019create_register_alias (char * newname, char *p)
2020{
2021 struct reg_entry *old;
2022 char *oldname, *nbuf;
2023 size_t nlen;
b99bd4ef 2024
c19d1205
ZW
2025 /* The input scrubber ensures that whitespace after the mnemonic is
2026 collapsed to single spaces. */
2027 oldname = p;
2028 if (strncmp (oldname, " .req ", 6) != 0)
2029 return 0;
b99bd4ef 2030
c19d1205
ZW
2031 oldname += 6;
2032 if (*oldname == '\0')
2033 return 0;
b99bd4ef 2034
c19d1205
ZW
2035 old = hash_find (arm_reg_hsh, oldname);
2036 if (!old)
b99bd4ef 2037 {
c19d1205
ZW
2038 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2039 return 1;
b99bd4ef
NC
2040 }
2041
c19d1205
ZW
2042 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2043 the desired alias name, and p points to its end. If not, then
2044 the desired alias name is in the global original_case_string. */
2045#ifdef TC_CASE_SENSITIVE
2046 nlen = p - newname;
2047#else
2048 newname = original_case_string;
2049 nlen = strlen (newname);
2050#endif
b99bd4ef 2051
c19d1205
ZW
2052 nbuf = alloca (nlen + 1);
2053 memcpy (nbuf, newname, nlen);
2054 nbuf[nlen] = '\0';
b99bd4ef 2055
c19d1205
ZW
2056 /* Create aliases under the new name as stated; an all-lowercase
2057 version of the new name; and an all-uppercase version of the new
2058 name. */
2059 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 2060
c19d1205
ZW
2061 for (p = nbuf; *p; p++)
2062 *p = TOUPPER (*p);
2063
2064 if (strncmp (nbuf, newname, nlen))
2065 insert_reg_alias (nbuf, old->number, old->type);
2066
2067 for (p = nbuf; *p; p++)
2068 *p = TOLOWER (*p);
2069
2070 if (strncmp (nbuf, newname, nlen))
2071 insert_reg_alias (nbuf, old->number, old->type);
2072
2073 return 1;
b99bd4ef
NC
2074}
2075
dcbf9037
JB
2076/* Create a Neon typed/indexed register alias using directives, e.g.:
2077 X .dn d5.s32[1]
2078 Y .qn 6.s16
2079 Z .dn d7
2080 T .dn Z[0]
2081 These typed registers can be used instead of the types specified after the
2082 Neon mnemonic, so long as all operands given have types. Types can also be
2083 specified directly, e.g.:
2084 vadd d0.s32, d1.s32, d2.s32
2085*/
2086
2087static int
2088create_neon_reg_alias (char *newname, char *p)
2089{
2090 enum arm_reg_type basetype;
2091 struct reg_entry *basereg;
2092 struct reg_entry mybasereg;
2093 struct neon_type ntype;
2094 struct neon_typed_alias typeinfo;
2095 char *namebuf, *nameend;
2096 int namelen;
2097
2098 typeinfo.defined = 0;
2099 typeinfo.eltype.type = NT_invtype;
2100 typeinfo.eltype.size = -1;
2101 typeinfo.index = -1;
2102
2103 nameend = p;
2104
2105 if (strncmp (p, " .dn ", 5) == 0)
2106 basetype = REG_TYPE_VFD;
2107 else if (strncmp (p, " .qn ", 5) == 0)
2108 basetype = REG_TYPE_NQ;
2109 else
2110 return 0;
2111
2112 p += 5;
2113
2114 if (*p == '\0')
2115 return 0;
2116
2117 basereg = arm_reg_parse_multi (&p);
2118
2119 if (basereg && basereg->type != basetype)
2120 {
2121 as_bad (_("bad type for register"));
2122 return 0;
2123 }
2124
2125 if (basereg == NULL)
2126 {
2127 expressionS exp;
2128 /* Try parsing as an integer. */
2129 my_get_expression (&exp, &p, GE_NO_PREFIX);
2130 if (exp.X_op != O_constant)
2131 {
2132 as_bad (_("expression must be constant"));
2133 return 0;
2134 }
2135 basereg = &mybasereg;
2136 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2137 : exp.X_add_number;
2138 basereg->neon = 0;
2139 }
2140
2141 if (basereg->neon)
2142 typeinfo = *basereg->neon;
2143
2144 if (parse_neon_type (&ntype, &p) == SUCCESS)
2145 {
2146 /* We got a type. */
2147 if (typeinfo.defined & NTA_HASTYPE)
2148 {
2149 as_bad (_("can't redefine the type of a register alias"));
2150 return 0;
2151 }
2152
2153 typeinfo.defined |= NTA_HASTYPE;
2154 if (ntype.elems != 1)
2155 {
2156 as_bad (_("you must specify a single type only"));
2157 return 0;
2158 }
2159 typeinfo.eltype = ntype.el[0];
2160 }
2161
2162 if (skip_past_char (&p, '[') == SUCCESS)
2163 {
2164 expressionS exp;
2165 /* We got a scalar index. */
2166
2167 if (typeinfo.defined & NTA_HASINDEX)
2168 {
2169 as_bad (_("can't redefine the index of a scalar alias"));
2170 return 0;
2171 }
2172
2173 my_get_expression (&exp, &p, GE_NO_PREFIX);
2174
2175 if (exp.X_op != O_constant)
2176 {
2177 as_bad (_("scalar index must be constant"));
2178 return 0;
2179 }
2180
2181 typeinfo.defined |= NTA_HASINDEX;
2182 typeinfo.index = exp.X_add_number;
2183
2184 if (skip_past_char (&p, ']') == FAIL)
2185 {
2186 as_bad (_("expecting ]"));
2187 return 0;
2188 }
2189 }
2190
2191 namelen = nameend - newname;
2192 namebuf = alloca (namelen + 1);
2193 strncpy (namebuf, newname, namelen);
2194 namebuf[namelen] = '\0';
2195
2196 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2197 typeinfo.defined != 0 ? &typeinfo : NULL);
2198
2199 /* Insert name in all uppercase. */
2200 for (p = namebuf; *p; p++)
2201 *p = TOUPPER (*p);
2202
2203 if (strncmp (namebuf, newname, namelen))
2204 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2205 typeinfo.defined != 0 ? &typeinfo : NULL);
2206
2207 /* Insert name in all lowercase. */
2208 for (p = namebuf; *p; p++)
2209 *p = TOLOWER (*p);
2210
2211 if (strncmp (namebuf, newname, namelen))
2212 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2213 typeinfo.defined != 0 ? &typeinfo : NULL);
2214
2215 return 1;
2216}
2217
c19d1205
ZW
2218/* Should never be called, as .req goes between the alias and the
2219 register name, not at the beginning of the line. */
b99bd4ef 2220static void
c19d1205 2221s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2222{
c19d1205
ZW
2223 as_bad (_("invalid syntax for .req directive"));
2224}
b99bd4ef 2225
dcbf9037
JB
2226static void
2227s_dn (int a ATTRIBUTE_UNUSED)
2228{
2229 as_bad (_("invalid syntax for .dn directive"));
2230}
2231
2232static void
2233s_qn (int a ATTRIBUTE_UNUSED)
2234{
2235 as_bad (_("invalid syntax for .qn directive"));
2236}
2237
c19d1205
ZW
2238/* The .unreq directive deletes an alias which was previously defined
2239 by .req. For example:
b99bd4ef 2240
c19d1205
ZW
2241 my_alias .req r11
2242 .unreq my_alias */
b99bd4ef
NC
2243
2244static void
c19d1205 2245s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2246{
c19d1205
ZW
2247 char * name;
2248 char saved_char;
b99bd4ef 2249
c19d1205
ZW
2250 name = input_line_pointer;
2251
2252 while (*input_line_pointer != 0
2253 && *input_line_pointer != ' '
2254 && *input_line_pointer != '\n')
2255 ++input_line_pointer;
2256
2257 saved_char = *input_line_pointer;
2258 *input_line_pointer = 0;
2259
2260 if (!*name)
2261 as_bad (_("invalid syntax for .unreq directive"));
2262 else
2263 {
2264 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2265
2266 if (!reg)
2267 as_bad (_("unknown register alias '%s'"), name);
2268 else if (reg->builtin)
2269 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2270 name);
2271 else
2272 {
2273 hash_delete (arm_reg_hsh, name);
2274 free ((char *) reg->name);
dcbf9037
JB
2275 if (reg->neon)
2276 free (reg->neon);
c19d1205
ZW
2277 free (reg);
2278 }
2279 }
b99bd4ef 2280
c19d1205 2281 *input_line_pointer = saved_char;
b99bd4ef
NC
2282 demand_empty_rest_of_line ();
2283}
2284
c19d1205
ZW
2285/* Directives: Instruction set selection. */
2286
2287#ifdef OBJ_ELF
2288/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2289 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2290 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2291 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2292
2293static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2294
e821645d 2295void
c19d1205 2296mapping_state (enum mstate state)
b99bd4ef 2297{
a737bd4d 2298 symbolS * symbolP;
c19d1205
ZW
2299 const char * symname;
2300 int type;
b99bd4ef 2301
c19d1205
ZW
2302 if (mapstate == state)
2303 /* The mapping symbol has already been emitted.
2304 There is nothing else to do. */
2305 return;
b99bd4ef 2306
c19d1205 2307 mapstate = state;
b99bd4ef 2308
c19d1205 2309 switch (state)
b99bd4ef 2310 {
c19d1205
ZW
2311 case MAP_DATA:
2312 symname = "$d";
2313 type = BSF_NO_FLAGS;
2314 break;
2315 case MAP_ARM:
2316 symname = "$a";
2317 type = BSF_NO_FLAGS;
2318 break;
2319 case MAP_THUMB:
2320 symname = "$t";
2321 type = BSF_NO_FLAGS;
2322 break;
2323 case MAP_UNDEFINED:
2324 return;
2325 default:
2326 abort ();
2327 }
2328
2329 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2330
2331 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2332 symbol_table_insert (symbolP);
2333 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2334
2335 switch (state)
2336 {
2337 case MAP_ARM:
2338 THUMB_SET_FUNC (symbolP, 0);
2339 ARM_SET_THUMB (symbolP, 0);
2340 ARM_SET_INTERWORK (symbolP, support_interwork);
2341 break;
2342
2343 case MAP_THUMB:
2344 THUMB_SET_FUNC (symbolP, 1);
2345 ARM_SET_THUMB (symbolP, 1);
2346 ARM_SET_INTERWORK (symbolP, support_interwork);
2347 break;
2348
2349 case MAP_DATA:
2350 default:
2351 return;
2352 }
2353}
2354#else
2355#define mapping_state(x) /* nothing */
2356#endif
2357
2358/* Find the real, Thumb encoded start of a Thumb function. */
2359
2360static symbolS *
2361find_real_start (symbolS * symbolP)
2362{
2363 char * real_start;
2364 const char * name = S_GET_NAME (symbolP);
2365 symbolS * new_target;
2366
2367 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2368#define STUB_NAME ".real_start_of"
2369
2370 if (name == NULL)
2371 abort ();
2372
37f6032b
ZW
2373 /* The compiler may generate BL instructions to local labels because
2374 it needs to perform a branch to a far away location. These labels
2375 do not have a corresponding ".real_start_of" label. We check
2376 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2377 the ".real_start_of" convention for nonlocal branches. */
2378 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2379 return symbolP;
2380
37f6032b 2381 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2382 new_target = symbol_find (real_start);
2383
2384 if (new_target == NULL)
2385 {
2386 as_warn ("Failed to find real start of function: %s\n", name);
2387 new_target = symbolP;
2388 }
2389
c19d1205
ZW
2390 return new_target;
2391}
2392
2393static void
2394opcode_select (int width)
2395{
2396 switch (width)
2397 {
2398 case 16:
2399 if (! thumb_mode)
2400 {
e74cfd16 2401 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2402 as_bad (_("selected processor does not support THUMB opcodes"));
2403
2404 thumb_mode = 1;
2405 /* No need to force the alignment, since we will have been
2406 coming from ARM mode, which is word-aligned. */
2407 record_alignment (now_seg, 1);
2408 }
2409 mapping_state (MAP_THUMB);
2410 break;
2411
2412 case 32:
2413 if (thumb_mode)
2414 {
e74cfd16 2415 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2416 as_bad (_("selected processor does not support ARM opcodes"));
2417
2418 thumb_mode = 0;
2419
2420 if (!need_pass_2)
2421 frag_align (2, 0, 0);
2422
2423 record_alignment (now_seg, 1);
2424 }
2425 mapping_state (MAP_ARM);
2426 break;
2427
2428 default:
2429 as_bad (_("invalid instruction size selected (%d)"), width);
2430 }
2431}
2432
2433static void
2434s_arm (int ignore ATTRIBUTE_UNUSED)
2435{
2436 opcode_select (32);
2437 demand_empty_rest_of_line ();
2438}
2439
2440static void
2441s_thumb (int ignore ATTRIBUTE_UNUSED)
2442{
2443 opcode_select (16);
2444 demand_empty_rest_of_line ();
2445}
2446
2447static void
2448s_code (int unused ATTRIBUTE_UNUSED)
2449{
2450 int temp;
2451
2452 temp = get_absolute_expression ();
2453 switch (temp)
2454 {
2455 case 16:
2456 case 32:
2457 opcode_select (temp);
2458 break;
2459
2460 default:
2461 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2462 }
2463}
2464
2465static void
2466s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2467{
2468 /* If we are not already in thumb mode go into it, EVEN if
2469 the target processor does not support thumb instructions.
2470 This is used by gcc/config/arm/lib1funcs.asm for example
2471 to compile interworking support functions even if the
2472 target processor should not support interworking. */
2473 if (! thumb_mode)
2474 {
2475 thumb_mode = 2;
2476 record_alignment (now_seg, 1);
2477 }
2478
2479 demand_empty_rest_of_line ();
2480}
2481
2482static void
2483s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2484{
2485 s_thumb (0);
2486
2487 /* The following label is the name/address of the start of a Thumb function.
2488 We need to know this for the interworking support. */
2489 label_is_thumb_function_name = TRUE;
2490}
2491
2492/* Perform a .set directive, but also mark the alias as
2493 being a thumb function. */
2494
2495static void
2496s_thumb_set (int equiv)
2497{
2498 /* XXX the following is a duplicate of the code for s_set() in read.c
2499 We cannot just call that code as we need to get at the symbol that
2500 is created. */
2501 char * name;
2502 char delim;
2503 char * end_name;
2504 symbolS * symbolP;
2505
2506 /* Especial apologies for the random logic:
2507 This just grew, and could be parsed much more simply!
2508 Dean - in haste. */
2509 name = input_line_pointer;
2510 delim = get_symbol_end ();
2511 end_name = input_line_pointer;
2512 *end_name = delim;
2513
2514 if (*input_line_pointer != ',')
2515 {
2516 *end_name = 0;
2517 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2518 *end_name = delim;
2519 ignore_rest_of_line ();
2520 return;
2521 }
2522
2523 input_line_pointer++;
2524 *end_name = 0;
2525
2526 if (name[0] == '.' && name[1] == '\0')
2527 {
2528 /* XXX - this should not happen to .thumb_set. */
2529 abort ();
2530 }
2531
2532 if ((symbolP = symbol_find (name)) == NULL
2533 && (symbolP = md_undefined_symbol (name)) == NULL)
2534 {
2535#ifndef NO_LISTING
2536 /* When doing symbol listings, play games with dummy fragments living
2537 outside the normal fragment chain to record the file and line info
c19d1205 2538 for this symbol. */
b99bd4ef
NC
2539 if (listing & LISTING_SYMBOLS)
2540 {
2541 extern struct list_info_struct * listing_tail;
a737bd4d 2542 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2543
2544 memset (dummy_frag, 0, sizeof (fragS));
2545 dummy_frag->fr_type = rs_fill;
2546 dummy_frag->line = listing_tail;
2547 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2548 dummy_frag->fr_symbol = symbolP;
2549 }
2550 else
2551#endif
2552 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2553
2554#ifdef OBJ_COFF
2555 /* "set" symbols are local unless otherwise specified. */
2556 SF_SET_LOCAL (symbolP);
2557#endif /* OBJ_COFF */
2558 } /* Make a new symbol. */
2559
2560 symbol_table_insert (symbolP);
2561
2562 * end_name = delim;
2563
2564 if (equiv
2565 && S_IS_DEFINED (symbolP)
2566 && S_GET_SEGMENT (symbolP) != reg_section)
2567 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2568
2569 pseudo_set (symbolP);
2570
2571 demand_empty_rest_of_line ();
2572
c19d1205 2573 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2574
2575 THUMB_SET_FUNC (symbolP, 1);
2576 ARM_SET_THUMB (symbolP, 1);
2577#if defined OBJ_ELF || defined OBJ_COFF
2578 ARM_SET_INTERWORK (symbolP, support_interwork);
2579#endif
2580}
2581
c19d1205 2582/* Directives: Mode selection. */
b99bd4ef 2583
c19d1205
ZW
2584/* .syntax [unified|divided] - choose the new unified syntax
2585 (same for Arm and Thumb encoding, modulo slight differences in what
2586 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2587static void
c19d1205 2588s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2589{
c19d1205
ZW
2590 char *name, delim;
2591
2592 name = input_line_pointer;
2593 delim = get_symbol_end ();
2594
2595 if (!strcasecmp (name, "unified"))
2596 unified_syntax = TRUE;
2597 else if (!strcasecmp (name, "divided"))
2598 unified_syntax = FALSE;
2599 else
2600 {
2601 as_bad (_("unrecognized syntax mode \"%s\""), name);
2602 return;
2603 }
2604 *input_line_pointer = delim;
b99bd4ef
NC
2605 demand_empty_rest_of_line ();
2606}
2607
c19d1205
ZW
2608/* Directives: sectioning and alignment. */
2609
2610/* Same as s_align_ptwo but align 0 => align 2. */
2611
b99bd4ef 2612static void
c19d1205 2613s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2614{
a737bd4d 2615 int temp;
dce323d1 2616 bfd_boolean fill_p;
c19d1205
ZW
2617 long temp_fill;
2618 long max_alignment = 15;
b99bd4ef
NC
2619
2620 temp = get_absolute_expression ();
c19d1205
ZW
2621 if (temp > max_alignment)
2622 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2623 else if (temp < 0)
b99bd4ef 2624 {
c19d1205
ZW
2625 as_bad (_("alignment negative. 0 assumed."));
2626 temp = 0;
2627 }
b99bd4ef 2628
c19d1205
ZW
2629 if (*input_line_pointer == ',')
2630 {
2631 input_line_pointer++;
2632 temp_fill = get_absolute_expression ();
dce323d1 2633 fill_p = TRUE;
b99bd4ef 2634 }
c19d1205 2635 else
dce323d1
PB
2636 {
2637 fill_p = FALSE;
2638 temp_fill = 0;
2639 }
b99bd4ef 2640
c19d1205
ZW
2641 if (!temp)
2642 temp = 2;
b99bd4ef 2643
c19d1205
ZW
2644 /* Only make a frag if we HAVE to. */
2645 if (temp && !need_pass_2)
dce323d1
PB
2646 {
2647 if (!fill_p && subseg_text_p (now_seg))
2648 frag_align_code (temp, 0);
2649 else
2650 frag_align (temp, (int) temp_fill, 0);
2651 }
c19d1205
ZW
2652 demand_empty_rest_of_line ();
2653
2654 record_alignment (now_seg, temp);
b99bd4ef
NC
2655}
2656
c19d1205
ZW
2657static void
2658s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2659{
c19d1205
ZW
2660 /* We don't support putting frags in the BSS segment, we fake it by
2661 marking in_bss, then looking at s_skip for clues. */
2662 subseg_set (bss_section, 0);
2663 demand_empty_rest_of_line ();
2664 mapping_state (MAP_DATA);
2665}
b99bd4ef 2666
c19d1205
ZW
2667static void
2668s_even (int ignore ATTRIBUTE_UNUSED)
2669{
2670 /* Never make frag if expect extra pass. */
2671 if (!need_pass_2)
2672 frag_align (1, 0, 0);
b99bd4ef 2673
c19d1205 2674 record_alignment (now_seg, 1);
b99bd4ef 2675
c19d1205 2676 demand_empty_rest_of_line ();
b99bd4ef
NC
2677}
2678
c19d1205 2679/* Directives: Literal pools. */
a737bd4d 2680
c19d1205
ZW
2681static literal_pool *
2682find_literal_pool (void)
a737bd4d 2683{
c19d1205 2684 literal_pool * pool;
a737bd4d 2685
c19d1205 2686 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2687 {
c19d1205
ZW
2688 if (pool->section == now_seg
2689 && pool->sub_section == now_subseg)
2690 break;
a737bd4d
NC
2691 }
2692
c19d1205 2693 return pool;
a737bd4d
NC
2694}
2695
c19d1205
ZW
2696static literal_pool *
2697find_or_make_literal_pool (void)
a737bd4d 2698{
c19d1205
ZW
2699 /* Next literal pool ID number. */
2700 static unsigned int latest_pool_num = 1;
2701 literal_pool * pool;
a737bd4d 2702
c19d1205 2703 pool = find_literal_pool ();
a737bd4d 2704
c19d1205 2705 if (pool == NULL)
a737bd4d 2706 {
c19d1205
ZW
2707 /* Create a new pool. */
2708 pool = xmalloc (sizeof (* pool));
2709 if (! pool)
2710 return NULL;
a737bd4d 2711
c19d1205
ZW
2712 pool->next_free_entry = 0;
2713 pool->section = now_seg;
2714 pool->sub_section = now_subseg;
2715 pool->next = list_of_pools;
2716 pool->symbol = NULL;
2717
2718 /* Add it to the list. */
2719 list_of_pools = pool;
a737bd4d 2720 }
a737bd4d 2721
c19d1205
ZW
2722 /* New pools, and emptied pools, will have a NULL symbol. */
2723 if (pool->symbol == NULL)
a737bd4d 2724 {
c19d1205
ZW
2725 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2726 (valueT) 0, &zero_address_frag);
2727 pool->id = latest_pool_num ++;
a737bd4d
NC
2728 }
2729
c19d1205
ZW
2730 /* Done. */
2731 return pool;
a737bd4d
NC
2732}
2733
c19d1205
ZW
2734/* Add the literal in the global 'inst'
2735 structure to the relevent literal pool. */
b99bd4ef
NC
2736
2737static int
c19d1205 2738add_to_lit_pool (void)
b99bd4ef 2739{
c19d1205
ZW
2740 literal_pool * pool;
2741 unsigned int entry;
b99bd4ef 2742
c19d1205
ZW
2743 pool = find_or_make_literal_pool ();
2744
2745 /* Check if this literal value is already in the pool. */
2746 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2747 {
c19d1205
ZW
2748 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2749 && (inst.reloc.exp.X_op == O_constant)
2750 && (pool->literals[entry].X_add_number
2751 == inst.reloc.exp.X_add_number)
2752 && (pool->literals[entry].X_unsigned
2753 == inst.reloc.exp.X_unsigned))
2754 break;
2755
2756 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2757 && (inst.reloc.exp.X_op == O_symbol)
2758 && (pool->literals[entry].X_add_number
2759 == inst.reloc.exp.X_add_number)
2760 && (pool->literals[entry].X_add_symbol
2761 == inst.reloc.exp.X_add_symbol)
2762 && (pool->literals[entry].X_op_symbol
2763 == inst.reloc.exp.X_op_symbol))
2764 break;
b99bd4ef
NC
2765 }
2766
c19d1205
ZW
2767 /* Do we need to create a new entry? */
2768 if (entry == pool->next_free_entry)
2769 {
2770 if (entry >= MAX_LITERAL_POOL_SIZE)
2771 {
2772 inst.error = _("literal pool overflow");
2773 return FAIL;
2774 }
2775
2776 pool->literals[entry] = inst.reloc.exp;
2777 pool->next_free_entry += 1;
2778 }
b99bd4ef 2779
c19d1205
ZW
2780 inst.reloc.exp.X_op = O_symbol;
2781 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2782 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2783
c19d1205 2784 return SUCCESS;
b99bd4ef
NC
2785}
2786
c19d1205
ZW
2787/* Can't use symbol_new here, so have to create a symbol and then at
2788 a later date assign it a value. Thats what these functions do. */
e16bb312 2789
c19d1205
ZW
2790static void
2791symbol_locate (symbolS * symbolP,
2792 const char * name, /* It is copied, the caller can modify. */
2793 segT segment, /* Segment identifier (SEG_<something>). */
2794 valueT valu, /* Symbol value. */
2795 fragS * frag) /* Associated fragment. */
2796{
2797 unsigned int name_length;
2798 char * preserved_copy_of_name;
e16bb312 2799
c19d1205
ZW
2800 name_length = strlen (name) + 1; /* +1 for \0. */
2801 obstack_grow (&notes, name, name_length);
2802 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2803
c19d1205
ZW
2804#ifdef tc_canonicalize_symbol_name
2805 preserved_copy_of_name =
2806 tc_canonicalize_symbol_name (preserved_copy_of_name);
2807#endif
b99bd4ef 2808
c19d1205 2809 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2810
c19d1205
ZW
2811 S_SET_SEGMENT (symbolP, segment);
2812 S_SET_VALUE (symbolP, valu);
2813 symbol_clear_list_pointers (symbolP);
b99bd4ef 2814
c19d1205 2815 symbol_set_frag (symbolP, frag);
b99bd4ef 2816
c19d1205
ZW
2817 /* Link to end of symbol chain. */
2818 {
2819 extern int symbol_table_frozen;
b99bd4ef 2820
c19d1205
ZW
2821 if (symbol_table_frozen)
2822 abort ();
2823 }
b99bd4ef 2824
c19d1205 2825 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2826
c19d1205 2827 obj_symbol_new_hook (symbolP);
b99bd4ef 2828
c19d1205
ZW
2829#ifdef tc_symbol_new_hook
2830 tc_symbol_new_hook (symbolP);
2831#endif
2832
2833#ifdef DEBUG_SYMS
2834 verify_symbol_chain (symbol_rootP, symbol_lastP);
2835#endif /* DEBUG_SYMS */
b99bd4ef
NC
2836}
2837
b99bd4ef 2838
c19d1205
ZW
2839static void
2840s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2841{
c19d1205
ZW
2842 unsigned int entry;
2843 literal_pool * pool;
2844 char sym_name[20];
b99bd4ef 2845
c19d1205
ZW
2846 pool = find_literal_pool ();
2847 if (pool == NULL
2848 || pool->symbol == NULL
2849 || pool->next_free_entry == 0)
2850 return;
b99bd4ef 2851
c19d1205 2852 mapping_state (MAP_DATA);
b99bd4ef 2853
c19d1205
ZW
2854 /* Align pool as you have word accesses.
2855 Only make a frag if we have to. */
2856 if (!need_pass_2)
2857 frag_align (2, 0, 0);
b99bd4ef 2858
c19d1205 2859 record_alignment (now_seg, 2);
b99bd4ef 2860
c19d1205 2861 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2862
c19d1205
ZW
2863 symbol_locate (pool->symbol, sym_name, now_seg,
2864 (valueT) frag_now_fix (), frag_now);
2865 symbol_table_insert (pool->symbol);
b99bd4ef 2866
c19d1205 2867 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2868
c19d1205
ZW
2869#if defined OBJ_COFF || defined OBJ_ELF
2870 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2871#endif
6c43fab6 2872
c19d1205
ZW
2873 for (entry = 0; entry < pool->next_free_entry; entry ++)
2874 /* First output the expression in the instruction to the pool. */
2875 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2876
c19d1205
ZW
2877 /* Mark the pool as empty. */
2878 pool->next_free_entry = 0;
2879 pool->symbol = NULL;
b99bd4ef
NC
2880}
2881
c19d1205
ZW
2882#ifdef OBJ_ELF
2883/* Forward declarations for functions below, in the MD interface
2884 section. */
2885static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2886static valueT create_unwind_entry (int);
2887static void start_unwind_section (const segT, int);
2888static void add_unwind_opcode (valueT, int);
2889static void flush_pending_unwind (void);
b99bd4ef 2890
c19d1205 2891/* Directives: Data. */
b99bd4ef 2892
c19d1205
ZW
2893static void
2894s_arm_elf_cons (int nbytes)
2895{
2896 expressionS exp;
b99bd4ef 2897
c19d1205
ZW
2898#ifdef md_flush_pending_output
2899 md_flush_pending_output ();
2900#endif
b99bd4ef 2901
c19d1205 2902 if (is_it_end_of_statement ())
b99bd4ef 2903 {
c19d1205
ZW
2904 demand_empty_rest_of_line ();
2905 return;
b99bd4ef
NC
2906 }
2907
c19d1205
ZW
2908#ifdef md_cons_align
2909 md_cons_align (nbytes);
2910#endif
b99bd4ef 2911
c19d1205
ZW
2912 mapping_state (MAP_DATA);
2913 do
b99bd4ef 2914 {
c19d1205
ZW
2915 int reloc;
2916 char *base = input_line_pointer;
b99bd4ef 2917
c19d1205 2918 expression (& exp);
b99bd4ef 2919
c19d1205
ZW
2920 if (exp.X_op != O_symbol)
2921 emit_expr (&exp, (unsigned int) nbytes);
2922 else
2923 {
2924 char *before_reloc = input_line_pointer;
2925 reloc = parse_reloc (&input_line_pointer);
2926 if (reloc == -1)
2927 {
2928 as_bad (_("unrecognized relocation suffix"));
2929 ignore_rest_of_line ();
2930 return;
2931 }
2932 else if (reloc == BFD_RELOC_UNUSED)
2933 emit_expr (&exp, (unsigned int) nbytes);
2934 else
2935 {
2936 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2937 int size = bfd_get_reloc_size (howto);
b99bd4ef 2938
2fc8bdac
ZW
2939 if (reloc == BFD_RELOC_ARM_PLT32)
2940 {
2941 as_bad (_("(plt) is only valid on branch targets"));
2942 reloc = BFD_RELOC_UNUSED;
2943 size = 0;
2944 }
2945
c19d1205 2946 if (size > nbytes)
2fc8bdac 2947 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2948 howto->name, nbytes);
2949 else
2950 {
2951 /* We've parsed an expression stopping at O_symbol.
2952 But there may be more expression left now that we
2953 have parsed the relocation marker. Parse it again.
2954 XXX Surely there is a cleaner way to do this. */
2955 char *p = input_line_pointer;
2956 int offset;
2957 char *save_buf = alloca (input_line_pointer - base);
2958 memcpy (save_buf, base, input_line_pointer - base);
2959 memmove (base + (input_line_pointer - before_reloc),
2960 base, before_reloc - base);
2961
2962 input_line_pointer = base + (input_line_pointer-before_reloc);
2963 expression (&exp);
2964 memcpy (base, save_buf, p - base);
2965
2966 offset = nbytes - size;
2967 p = frag_more ((int) nbytes);
2968 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2969 size, &exp, 0, reloc);
2970 }
2971 }
2972 }
b99bd4ef 2973 }
c19d1205 2974 while (*input_line_pointer++ == ',');
b99bd4ef 2975
c19d1205
ZW
2976 /* Put terminator back into stream. */
2977 input_line_pointer --;
2978 demand_empty_rest_of_line ();
b99bd4ef
NC
2979}
2980
b99bd4ef 2981
c19d1205 2982/* Parse a .rel31 directive. */
b99bd4ef 2983
c19d1205
ZW
2984static void
2985s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2986{
2987 expressionS exp;
2988 char *p;
2989 valueT highbit;
b99bd4ef 2990
c19d1205
ZW
2991 highbit = 0;
2992 if (*input_line_pointer == '1')
2993 highbit = 0x80000000;
2994 else if (*input_line_pointer != '0')
2995 as_bad (_("expected 0 or 1"));
b99bd4ef 2996
c19d1205
ZW
2997 input_line_pointer++;
2998 if (*input_line_pointer != ',')
2999 as_bad (_("missing comma"));
3000 input_line_pointer++;
b99bd4ef 3001
c19d1205
ZW
3002#ifdef md_flush_pending_output
3003 md_flush_pending_output ();
3004#endif
b99bd4ef 3005
c19d1205
ZW
3006#ifdef md_cons_align
3007 md_cons_align (4);
3008#endif
b99bd4ef 3009
c19d1205 3010 mapping_state (MAP_DATA);
b99bd4ef 3011
c19d1205 3012 expression (&exp);
b99bd4ef 3013
c19d1205
ZW
3014 p = frag_more (4);
3015 md_number_to_chars (p, highbit, 4);
3016 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3017 BFD_RELOC_ARM_PREL31);
b99bd4ef 3018
c19d1205 3019 demand_empty_rest_of_line ();
b99bd4ef
NC
3020}
3021
c19d1205 3022/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3023
c19d1205 3024/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3025
c19d1205
ZW
3026static void
3027s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3028{
3029 demand_empty_rest_of_line ();
3030 /* Mark the start of the function. */
3031 unwind.proc_start = expr_build_dot ();
b99bd4ef 3032
c19d1205
ZW
3033 /* Reset the rest of the unwind info. */
3034 unwind.opcode_count = 0;
3035 unwind.table_entry = NULL;
3036 unwind.personality_routine = NULL;
3037 unwind.personality_index = -1;
3038 unwind.frame_size = 0;
3039 unwind.fp_offset = 0;
3040 unwind.fp_reg = 13;
3041 unwind.fp_used = 0;
3042 unwind.sp_restored = 0;
3043}
b99bd4ef 3044
b99bd4ef 3045
c19d1205
ZW
3046/* Parse a handlerdata directive. Creates the exception handling table entry
3047 for the function. */
b99bd4ef 3048
c19d1205
ZW
3049static void
3050s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3051{
3052 demand_empty_rest_of_line ();
3053 if (unwind.table_entry)
3054 as_bad (_("dupicate .handlerdata directive"));
f02232aa 3055
c19d1205
ZW
3056 create_unwind_entry (1);
3057}
a737bd4d 3058
c19d1205 3059/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3060
c19d1205
ZW
3061static void
3062s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3063{
3064 long where;
3065 char *ptr;
3066 valueT val;
f02232aa 3067
c19d1205 3068 demand_empty_rest_of_line ();
f02232aa 3069
c19d1205
ZW
3070 /* Add eh table entry. */
3071 if (unwind.table_entry == NULL)
3072 val = create_unwind_entry (0);
3073 else
3074 val = 0;
f02232aa 3075
c19d1205
ZW
3076 /* Add index table entry. This is two words. */
3077 start_unwind_section (unwind.saved_seg, 1);
3078 frag_align (2, 0, 0);
3079 record_alignment (now_seg, 2);
b99bd4ef 3080
c19d1205
ZW
3081 ptr = frag_more (8);
3082 where = frag_now_fix () - 8;
f02232aa 3083
c19d1205
ZW
3084 /* Self relative offset of the function start. */
3085 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3086 BFD_RELOC_ARM_PREL31);
f02232aa 3087
c19d1205
ZW
3088 /* Indicate dependency on EHABI-defined personality routines to the
3089 linker, if it hasn't been done already. */
3090 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3091 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3092 {
3093 static const char *const name[] = {
3094 "__aeabi_unwind_cpp_pr0",
3095 "__aeabi_unwind_cpp_pr1",
3096 "__aeabi_unwind_cpp_pr2"
3097 };
3098 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3099 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3100 marked_pr_dependency |= 1 << unwind.personality_index;
3101 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3102 = marked_pr_dependency;
3103 }
f02232aa 3104
c19d1205
ZW
3105 if (val)
3106 /* Inline exception table entry. */
3107 md_number_to_chars (ptr + 4, val, 4);
3108 else
3109 /* Self relative offset of the table entry. */
3110 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3111 BFD_RELOC_ARM_PREL31);
f02232aa 3112
c19d1205
ZW
3113 /* Restore the original section. */
3114 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3115}
f02232aa 3116
f02232aa 3117
c19d1205 3118/* Parse an unwind_cantunwind directive. */
b99bd4ef 3119
c19d1205
ZW
3120static void
3121s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3122{
3123 demand_empty_rest_of_line ();
3124 if (unwind.personality_routine || unwind.personality_index != -1)
3125 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3126
c19d1205
ZW
3127 unwind.personality_index = -2;
3128}
b99bd4ef 3129
b99bd4ef 3130
c19d1205 3131/* Parse a personalityindex directive. */
b99bd4ef 3132
c19d1205
ZW
3133static void
3134s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3135{
3136 expressionS exp;
b99bd4ef 3137
c19d1205
ZW
3138 if (unwind.personality_routine || unwind.personality_index != -1)
3139 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3140
c19d1205 3141 expression (&exp);
b99bd4ef 3142
c19d1205
ZW
3143 if (exp.X_op != O_constant
3144 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3145 {
c19d1205
ZW
3146 as_bad (_("bad personality routine number"));
3147 ignore_rest_of_line ();
3148 return;
b99bd4ef
NC
3149 }
3150
c19d1205 3151 unwind.personality_index = exp.X_add_number;
b99bd4ef 3152
c19d1205
ZW
3153 demand_empty_rest_of_line ();
3154}
e16bb312 3155
e16bb312 3156
c19d1205 3157/* Parse a personality directive. */
e16bb312 3158
c19d1205
ZW
3159static void
3160s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3161{
3162 char *name, *p, c;
a737bd4d 3163
c19d1205
ZW
3164 if (unwind.personality_routine || unwind.personality_index != -1)
3165 as_bad (_("duplicate .personality directive"));
a737bd4d 3166
c19d1205
ZW
3167 name = input_line_pointer;
3168 c = get_symbol_end ();
3169 p = input_line_pointer;
3170 unwind.personality_routine = symbol_find_or_make (name);
3171 *p = c;
3172 demand_empty_rest_of_line ();
3173}
e16bb312 3174
e16bb312 3175
c19d1205 3176/* Parse a directive saving core registers. */
e16bb312 3177
c19d1205
ZW
3178static void
3179s_arm_unwind_save_core (void)
e16bb312 3180{
c19d1205
ZW
3181 valueT op;
3182 long range;
3183 int n;
e16bb312 3184
c19d1205
ZW
3185 range = parse_reg_list (&input_line_pointer);
3186 if (range == FAIL)
e16bb312 3187 {
c19d1205
ZW
3188 as_bad (_("expected register list"));
3189 ignore_rest_of_line ();
3190 return;
3191 }
e16bb312 3192
c19d1205 3193 demand_empty_rest_of_line ();
e16bb312 3194
c19d1205
ZW
3195 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3196 into .unwind_save {..., sp...}. We aren't bothered about the value of
3197 ip because it is clobbered by calls. */
3198 if (unwind.sp_restored && unwind.fp_reg == 12
3199 && (range & 0x3000) == 0x1000)
3200 {
3201 unwind.opcode_count--;
3202 unwind.sp_restored = 0;
3203 range = (range | 0x2000) & ~0x1000;
3204 unwind.pending_offset = 0;
3205 }
e16bb312 3206
01ae4198
DJ
3207 /* Pop r4-r15. */
3208 if (range & 0xfff0)
c19d1205 3209 {
01ae4198
DJ
3210 /* See if we can use the short opcodes. These pop a block of up to 8
3211 registers starting with r4, plus maybe r14. */
3212 for (n = 0; n < 8; n++)
3213 {
3214 /* Break at the first non-saved register. */
3215 if ((range & (1 << (n + 4))) == 0)
3216 break;
3217 }
3218 /* See if there are any other bits set. */
3219 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3220 {
3221 /* Use the long form. */
3222 op = 0x8000 | ((range >> 4) & 0xfff);
3223 add_unwind_opcode (op, 2);
3224 }
0dd132b6 3225 else
01ae4198
DJ
3226 {
3227 /* Use the short form. */
3228 if (range & 0x4000)
3229 op = 0xa8; /* Pop r14. */
3230 else
3231 op = 0xa0; /* Do not pop r14. */
3232 op |= (n - 1);
3233 add_unwind_opcode (op, 1);
3234 }
c19d1205 3235 }
0dd132b6 3236
c19d1205
ZW
3237 /* Pop r0-r3. */
3238 if (range & 0xf)
3239 {
3240 op = 0xb100 | (range & 0xf);
3241 add_unwind_opcode (op, 2);
0dd132b6
NC
3242 }
3243
c19d1205
ZW
3244 /* Record the number of bytes pushed. */
3245 for (n = 0; n < 16; n++)
3246 {
3247 if (range & (1 << n))
3248 unwind.frame_size += 4;
3249 }
0dd132b6
NC
3250}
3251
c19d1205
ZW
3252
3253/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3254
3255static void
c19d1205 3256s_arm_unwind_save_fpa (int reg)
b99bd4ef 3257{
c19d1205
ZW
3258 expressionS exp;
3259 int num_regs;
3260 valueT op;
b99bd4ef 3261
c19d1205
ZW
3262 /* Get Number of registers to transfer. */
3263 if (skip_past_comma (&input_line_pointer) != FAIL)
3264 expression (&exp);
3265 else
3266 exp.X_op = O_illegal;
b99bd4ef 3267
c19d1205 3268 if (exp.X_op != O_constant)
b99bd4ef 3269 {
c19d1205
ZW
3270 as_bad (_("expected , <constant>"));
3271 ignore_rest_of_line ();
b99bd4ef
NC
3272 return;
3273 }
3274
c19d1205
ZW
3275 num_regs = exp.X_add_number;
3276
3277 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3278 {
c19d1205
ZW
3279 as_bad (_("number of registers must be in the range [1:4]"));
3280 ignore_rest_of_line ();
b99bd4ef
NC
3281 return;
3282 }
3283
c19d1205 3284 demand_empty_rest_of_line ();
b99bd4ef 3285
c19d1205
ZW
3286 if (reg == 4)
3287 {
3288 /* Short form. */
3289 op = 0xb4 | (num_regs - 1);
3290 add_unwind_opcode (op, 1);
3291 }
b99bd4ef
NC
3292 else
3293 {
c19d1205
ZW
3294 /* Long form. */
3295 op = 0xc800 | (reg << 4) | (num_regs - 1);
3296 add_unwind_opcode (op, 2);
b99bd4ef 3297 }
c19d1205 3298 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3299}
3300
c19d1205 3301
fa073d69
MS
3302/* Parse a directive saving VFP registers for ARMv6 and above. */
3303
3304static void
3305s_arm_unwind_save_vfp_armv6 (void)
3306{
3307 int count;
3308 unsigned int start;
3309 valueT op;
3310 int num_vfpv3_regs = 0;
3311 int num_regs_below_16;
3312
3313 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3314 if (count == FAIL)
3315 {
3316 as_bad (_("expected register list"));
3317 ignore_rest_of_line ();
3318 return;
3319 }
3320
3321 demand_empty_rest_of_line ();
3322
3323 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3324 than FSTMX/FLDMX-style ones). */
3325
3326 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3327 if (start >= 16)
3328 num_vfpv3_regs = count;
3329 else if (start + count > 16)
3330 num_vfpv3_regs = start + count - 16;
3331
3332 if (num_vfpv3_regs > 0)
3333 {
3334 int start_offset = start > 16 ? start - 16 : 0;
3335 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3336 add_unwind_opcode (op, 2);
3337 }
3338
3339 /* Generate opcode for registers numbered in the range 0 .. 15. */
3340 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3341 assert (num_regs_below_16 + num_vfpv3_regs == count);
3342 if (num_regs_below_16 > 0)
3343 {
3344 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3345 add_unwind_opcode (op, 2);
3346 }
3347
3348 unwind.frame_size += count * 8;
3349}
3350
3351
3352/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3353
3354static void
c19d1205 3355s_arm_unwind_save_vfp (void)
b99bd4ef 3356{
c19d1205 3357 int count;
ca3f61f7 3358 unsigned int reg;
c19d1205 3359 valueT op;
b99bd4ef 3360
5287ad62 3361 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3362 if (count == FAIL)
b99bd4ef 3363 {
c19d1205
ZW
3364 as_bad (_("expected register list"));
3365 ignore_rest_of_line ();
b99bd4ef
NC
3366 return;
3367 }
3368
c19d1205 3369 demand_empty_rest_of_line ();
b99bd4ef 3370
c19d1205 3371 if (reg == 8)
b99bd4ef 3372 {
c19d1205
ZW
3373 /* Short form. */
3374 op = 0xb8 | (count - 1);
3375 add_unwind_opcode (op, 1);
b99bd4ef 3376 }
c19d1205 3377 else
b99bd4ef 3378 {
c19d1205
ZW
3379 /* Long form. */
3380 op = 0xb300 | (reg << 4) | (count - 1);
3381 add_unwind_opcode (op, 2);
b99bd4ef 3382 }
c19d1205
ZW
3383 unwind.frame_size += count * 8 + 4;
3384}
b99bd4ef 3385
b99bd4ef 3386
c19d1205
ZW
3387/* Parse a directive saving iWMMXt data registers. */
3388
3389static void
3390s_arm_unwind_save_mmxwr (void)
3391{
3392 int reg;
3393 int hi_reg;
3394 int i;
3395 unsigned mask = 0;
3396 valueT op;
b99bd4ef 3397
c19d1205
ZW
3398 if (*input_line_pointer == '{')
3399 input_line_pointer++;
b99bd4ef 3400
c19d1205 3401 do
b99bd4ef 3402 {
dcbf9037 3403 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3404
c19d1205 3405 if (reg == FAIL)
b99bd4ef 3406 {
c19d1205
ZW
3407 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3408 goto error;
b99bd4ef
NC
3409 }
3410
c19d1205
ZW
3411 if (mask >> reg)
3412 as_tsktsk (_("register list not in ascending order"));
3413 mask |= 1 << reg;
b99bd4ef 3414
c19d1205
ZW
3415 if (*input_line_pointer == '-')
3416 {
3417 input_line_pointer++;
dcbf9037 3418 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3419 if (hi_reg == FAIL)
3420 {
3421 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3422 goto error;
3423 }
3424 else if (reg >= hi_reg)
3425 {
3426 as_bad (_("bad register range"));
3427 goto error;
3428 }
3429 for (; reg < hi_reg; reg++)
3430 mask |= 1 << reg;
3431 }
3432 }
3433 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3434
c19d1205
ZW
3435 if (*input_line_pointer == '}')
3436 input_line_pointer++;
b99bd4ef 3437
c19d1205 3438 demand_empty_rest_of_line ();
b99bd4ef 3439
708587a4 3440 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3441 the list. */
3442 flush_pending_unwind ();
b99bd4ef 3443
c19d1205 3444 for (i = 0; i < 16; i++)
b99bd4ef 3445 {
c19d1205
ZW
3446 if (mask & (1 << i))
3447 unwind.frame_size += 8;
b99bd4ef
NC
3448 }
3449
c19d1205
ZW
3450 /* Attempt to combine with a previous opcode. We do this because gcc
3451 likes to output separate unwind directives for a single block of
3452 registers. */
3453 if (unwind.opcode_count > 0)
b99bd4ef 3454 {
c19d1205
ZW
3455 i = unwind.opcodes[unwind.opcode_count - 1];
3456 if ((i & 0xf8) == 0xc0)
3457 {
3458 i &= 7;
3459 /* Only merge if the blocks are contiguous. */
3460 if (i < 6)
3461 {
3462 if ((mask & 0xfe00) == (1 << 9))
3463 {
3464 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3465 unwind.opcode_count--;
3466 }
3467 }
3468 else if (i == 6 && unwind.opcode_count >= 2)
3469 {
3470 i = unwind.opcodes[unwind.opcode_count - 2];
3471 reg = i >> 4;
3472 i &= 0xf;
b99bd4ef 3473
c19d1205
ZW
3474 op = 0xffff << (reg - 1);
3475 if (reg > 0
87a1fd79 3476 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3477 {
3478 op = (1 << (reg + i + 1)) - 1;
3479 op &= ~((1 << reg) - 1);
3480 mask |= op;
3481 unwind.opcode_count -= 2;
3482 }
3483 }
3484 }
b99bd4ef
NC
3485 }
3486
c19d1205
ZW
3487 hi_reg = 15;
3488 /* We want to generate opcodes in the order the registers have been
3489 saved, ie. descending order. */
3490 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3491 {
c19d1205
ZW
3492 /* Save registers in blocks. */
3493 if (reg < 0
3494 || !(mask & (1 << reg)))
3495 {
3496 /* We found an unsaved reg. Generate opcodes to save the
3497 preceeding block. */
3498 if (reg != hi_reg)
3499 {
3500 if (reg == 9)
3501 {
3502 /* Short form. */
3503 op = 0xc0 | (hi_reg - 10);
3504 add_unwind_opcode (op, 1);
3505 }
3506 else
3507 {
3508 /* Long form. */
3509 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3510 add_unwind_opcode (op, 2);
3511 }
3512 }
3513 hi_reg = reg - 1;
3514 }
b99bd4ef
NC
3515 }
3516
c19d1205
ZW
3517 return;
3518error:
3519 ignore_rest_of_line ();
b99bd4ef
NC
3520}
3521
3522static void
c19d1205 3523s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3524{
c19d1205
ZW
3525 int reg;
3526 int hi_reg;
3527 unsigned mask = 0;
3528 valueT op;
b99bd4ef 3529
c19d1205
ZW
3530 if (*input_line_pointer == '{')
3531 input_line_pointer++;
b99bd4ef 3532
c19d1205 3533 do
b99bd4ef 3534 {
dcbf9037 3535 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3536
c19d1205
ZW
3537 if (reg == FAIL)
3538 {
3539 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3540 goto error;
3541 }
b99bd4ef 3542
c19d1205
ZW
3543 reg -= 8;
3544 if (mask >> reg)
3545 as_tsktsk (_("register list not in ascending order"));
3546 mask |= 1 << reg;
b99bd4ef 3547
c19d1205
ZW
3548 if (*input_line_pointer == '-')
3549 {
3550 input_line_pointer++;
dcbf9037 3551 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3552 if (hi_reg == FAIL)
3553 {
3554 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3555 goto error;
3556 }
3557 else if (reg >= hi_reg)
3558 {
3559 as_bad (_("bad register range"));
3560 goto error;
3561 }
3562 for (; reg < hi_reg; reg++)
3563 mask |= 1 << reg;
3564 }
b99bd4ef 3565 }
c19d1205 3566 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3567
c19d1205
ZW
3568 if (*input_line_pointer == '}')
3569 input_line_pointer++;
b99bd4ef 3570
c19d1205
ZW
3571 demand_empty_rest_of_line ();
3572
708587a4 3573 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3574 the list. */
3575 flush_pending_unwind ();
b99bd4ef 3576
c19d1205 3577 for (reg = 0; reg < 16; reg++)
b99bd4ef 3578 {
c19d1205
ZW
3579 if (mask & (1 << reg))
3580 unwind.frame_size += 4;
b99bd4ef 3581 }
c19d1205
ZW
3582 op = 0xc700 | mask;
3583 add_unwind_opcode (op, 2);
3584 return;
3585error:
3586 ignore_rest_of_line ();
b99bd4ef
NC
3587}
3588
c19d1205 3589
fa073d69
MS
3590/* Parse an unwind_save directive.
3591 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3592
b99bd4ef 3593static void
fa073d69 3594s_arm_unwind_save (int arch_v6)
b99bd4ef 3595{
c19d1205
ZW
3596 char *peek;
3597 struct reg_entry *reg;
3598 bfd_boolean had_brace = FALSE;
b99bd4ef 3599
c19d1205
ZW
3600 /* Figure out what sort of save we have. */
3601 peek = input_line_pointer;
b99bd4ef 3602
c19d1205 3603 if (*peek == '{')
b99bd4ef 3604 {
c19d1205
ZW
3605 had_brace = TRUE;
3606 peek++;
b99bd4ef
NC
3607 }
3608
c19d1205 3609 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3610
c19d1205 3611 if (!reg)
b99bd4ef 3612 {
c19d1205
ZW
3613 as_bad (_("register expected"));
3614 ignore_rest_of_line ();
b99bd4ef
NC
3615 return;
3616 }
3617
c19d1205 3618 switch (reg->type)
b99bd4ef 3619 {
c19d1205
ZW
3620 case REG_TYPE_FN:
3621 if (had_brace)
3622 {
3623 as_bad (_("FPA .unwind_save does not take a register list"));
3624 ignore_rest_of_line ();
3625 return;
3626 }
3627 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3628 return;
c19d1205
ZW
3629
3630 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3631 case REG_TYPE_VFD:
3632 if (arch_v6)
3633 s_arm_unwind_save_vfp_armv6 ();
3634 else
3635 s_arm_unwind_save_vfp ();
3636 return;
c19d1205
ZW
3637 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3638 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3639
3640 default:
3641 as_bad (_(".unwind_save does not support this kind of register"));
3642 ignore_rest_of_line ();
b99bd4ef 3643 }
c19d1205 3644}
b99bd4ef 3645
b99bd4ef 3646
c19d1205
ZW
3647/* Parse an unwind_movsp directive. */
3648
3649static void
3650s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3651{
3652 int reg;
3653 valueT op;
4fa3602b 3654 int offset;
c19d1205 3655
dcbf9037 3656 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3657 if (reg == FAIL)
b99bd4ef 3658 {
c19d1205
ZW
3659 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3660 ignore_rest_of_line ();
b99bd4ef
NC
3661 return;
3662 }
4fa3602b
PB
3663
3664 /* Optional constant. */
3665 if (skip_past_comma (&input_line_pointer) != FAIL)
3666 {
3667 if (immediate_for_directive (&offset) == FAIL)
3668 return;
3669 }
3670 else
3671 offset = 0;
3672
c19d1205 3673 demand_empty_rest_of_line ();
b99bd4ef 3674
c19d1205 3675 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3676 {
c19d1205 3677 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3678 return;
3679 }
3680
c19d1205
ZW
3681 if (unwind.fp_reg != REG_SP)
3682 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3683
c19d1205
ZW
3684 /* Generate opcode to restore the value. */
3685 op = 0x90 | reg;
3686 add_unwind_opcode (op, 1);
3687
3688 /* Record the information for later. */
3689 unwind.fp_reg = reg;
4fa3602b 3690 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3691 unwind.sp_restored = 1;
b05fe5cf
ZW
3692}
3693
c19d1205
ZW
3694/* Parse an unwind_pad directive. */
3695
b05fe5cf 3696static void
c19d1205 3697s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3698{
c19d1205 3699 int offset;
b05fe5cf 3700
c19d1205
ZW
3701 if (immediate_for_directive (&offset) == FAIL)
3702 return;
b99bd4ef 3703
c19d1205
ZW
3704 if (offset & 3)
3705 {
3706 as_bad (_("stack increment must be multiple of 4"));
3707 ignore_rest_of_line ();
3708 return;
3709 }
b99bd4ef 3710
c19d1205
ZW
3711 /* Don't generate any opcodes, just record the details for later. */
3712 unwind.frame_size += offset;
3713 unwind.pending_offset += offset;
3714
3715 demand_empty_rest_of_line ();
3716}
3717
3718/* Parse an unwind_setfp directive. */
3719
3720static void
3721s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3722{
c19d1205
ZW
3723 int sp_reg;
3724 int fp_reg;
3725 int offset;
3726
dcbf9037 3727 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3728 if (skip_past_comma (&input_line_pointer) == FAIL)
3729 sp_reg = FAIL;
3730 else
dcbf9037 3731 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3732
c19d1205
ZW
3733 if (fp_reg == FAIL || sp_reg == FAIL)
3734 {
3735 as_bad (_("expected <reg>, <reg>"));
3736 ignore_rest_of_line ();
3737 return;
3738 }
b99bd4ef 3739
c19d1205
ZW
3740 /* Optional constant. */
3741 if (skip_past_comma (&input_line_pointer) != FAIL)
3742 {
3743 if (immediate_for_directive (&offset) == FAIL)
3744 return;
3745 }
3746 else
3747 offset = 0;
a737bd4d 3748
c19d1205 3749 demand_empty_rest_of_line ();
a737bd4d 3750
c19d1205 3751 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3752 {
c19d1205
ZW
3753 as_bad (_("register must be either sp or set by a previous"
3754 "unwind_movsp directive"));
3755 return;
a737bd4d
NC
3756 }
3757
c19d1205
ZW
3758 /* Don't generate any opcodes, just record the information for later. */
3759 unwind.fp_reg = fp_reg;
3760 unwind.fp_used = 1;
3761 if (sp_reg == 13)
3762 unwind.fp_offset = unwind.frame_size - offset;
3763 else
3764 unwind.fp_offset -= offset;
a737bd4d
NC
3765}
3766
c19d1205
ZW
3767/* Parse an unwind_raw directive. */
3768
3769static void
3770s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3771{
c19d1205 3772 expressionS exp;
708587a4 3773 /* This is an arbitrary limit. */
c19d1205
ZW
3774 unsigned char op[16];
3775 int count;
a737bd4d 3776
c19d1205
ZW
3777 expression (&exp);
3778 if (exp.X_op == O_constant
3779 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3780 {
c19d1205
ZW
3781 unwind.frame_size += exp.X_add_number;
3782 expression (&exp);
3783 }
3784 else
3785 exp.X_op = O_illegal;
a737bd4d 3786
c19d1205
ZW
3787 if (exp.X_op != O_constant)
3788 {
3789 as_bad (_("expected <offset>, <opcode>"));
3790 ignore_rest_of_line ();
3791 return;
3792 }
a737bd4d 3793
c19d1205 3794 count = 0;
a737bd4d 3795
c19d1205
ZW
3796 /* Parse the opcode. */
3797 for (;;)
3798 {
3799 if (count >= 16)
3800 {
3801 as_bad (_("unwind opcode too long"));
3802 ignore_rest_of_line ();
a737bd4d 3803 }
c19d1205 3804 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3805 {
c19d1205
ZW
3806 as_bad (_("invalid unwind opcode"));
3807 ignore_rest_of_line ();
3808 return;
a737bd4d 3809 }
c19d1205 3810 op[count++] = exp.X_add_number;
a737bd4d 3811
c19d1205
ZW
3812 /* Parse the next byte. */
3813 if (skip_past_comma (&input_line_pointer) == FAIL)
3814 break;
a737bd4d 3815
c19d1205
ZW
3816 expression (&exp);
3817 }
b99bd4ef 3818
c19d1205
ZW
3819 /* Add the opcode bytes in reverse order. */
3820 while (count--)
3821 add_unwind_opcode (op[count], 1);
b99bd4ef 3822
c19d1205 3823 demand_empty_rest_of_line ();
b99bd4ef 3824}
ee065d83
PB
3825
3826
3827/* Parse a .eabi_attribute directive. */
3828
3829static void
3830s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3831{
3832 expressionS exp;
3833 bfd_boolean is_string;
3834 int tag;
3835 unsigned int i = 0;
3836 char *s = NULL;
3837 char saved_char;
3838
3839 expression (& exp);
3840 if (exp.X_op != O_constant)
3841 goto bad;
3842
3843 tag = exp.X_add_number;
3844 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3845 is_string = 1;
3846 else
3847 is_string = 0;
3848
3849 if (skip_past_comma (&input_line_pointer) == FAIL)
3850 goto bad;
3851 if (tag == 32 || !is_string)
3852 {
3853 expression (& exp);
3854 if (exp.X_op != O_constant)
3855 {
3856 as_bad (_("expected numeric constant"));
3857 ignore_rest_of_line ();
3858 return;
3859 }
3860 i = exp.X_add_number;
3861 }
3862 if (tag == Tag_compatibility
3863 && skip_past_comma (&input_line_pointer) == FAIL)
3864 {
3865 as_bad (_("expected comma"));
3866 ignore_rest_of_line ();
3867 return;
3868 }
3869 if (is_string)
3870 {
3871 skip_whitespace(input_line_pointer);
3872 if (*input_line_pointer != '"')
3873 goto bad_string;
3874 input_line_pointer++;
3875 s = input_line_pointer;
3876 while (*input_line_pointer && *input_line_pointer != '"')
3877 input_line_pointer++;
3878 if (*input_line_pointer != '"')
3879 goto bad_string;
3880 saved_char = *input_line_pointer;
3881 *input_line_pointer = 0;
3882 }
3883 else
3884 {
3885 s = NULL;
3886 saved_char = 0;
3887 }
3888
3889 if (tag == Tag_compatibility)
3890 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3891 else if (is_string)
3892 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3893 else
3894 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3895
3896 if (s)
3897 {
3898 *input_line_pointer = saved_char;
3899 input_line_pointer++;
3900 }
3901 demand_empty_rest_of_line ();
3902 return;
3903bad_string:
3904 as_bad (_("bad string constant"));
3905 ignore_rest_of_line ();
3906 return;
3907bad:
3908 as_bad (_("expected <tag> , <value>"));
3909 ignore_rest_of_line ();
3910}
8463be01 3911#endif /* OBJ_ELF */
ee065d83
PB
3912
3913static void s_arm_arch (int);
7a1d4c38 3914static void s_arm_object_arch (int);
ee065d83
PB
3915static void s_arm_cpu (int);
3916static void s_arm_fpu (int);
b99bd4ef 3917
f0927246
NC
3918#ifdef TE_PE
3919
3920static void
3921pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3922{
3923 expressionS exp;
3924
3925 do
3926 {
3927 expression (&exp);
3928 if (exp.X_op == O_symbol)
3929 exp.X_op = O_secrel;
3930
3931 emit_expr (&exp, 4);
3932 }
3933 while (*input_line_pointer++ == ',');
3934
3935 input_line_pointer--;
3936 demand_empty_rest_of_line ();
3937}
3938#endif /* TE_PE */
3939
c19d1205
ZW
3940/* This table describes all the machine specific pseudo-ops the assembler
3941 has to support. The fields are:
3942 pseudo-op name without dot
3943 function to call to execute this pseudo-op
3944 Integer arg to pass to the function. */
b99bd4ef 3945
c19d1205 3946const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3947{
c19d1205
ZW
3948 /* Never called because '.req' does not start a line. */
3949 { "req", s_req, 0 },
dcbf9037
JB
3950 /* Following two are likewise never called. */
3951 { "dn", s_dn, 0 },
3952 { "qn", s_qn, 0 },
c19d1205
ZW
3953 { "unreq", s_unreq, 0 },
3954 { "bss", s_bss, 0 },
3955 { "align", s_align, 0 },
3956 { "arm", s_arm, 0 },
3957 { "thumb", s_thumb, 0 },
3958 { "code", s_code, 0 },
3959 { "force_thumb", s_force_thumb, 0 },
3960 { "thumb_func", s_thumb_func, 0 },
3961 { "thumb_set", s_thumb_set, 0 },
3962 { "even", s_even, 0 },
3963 { "ltorg", s_ltorg, 0 },
3964 { "pool", s_ltorg, 0 },
3965 { "syntax", s_syntax, 0 },
8463be01
PB
3966 { "cpu", s_arm_cpu, 0 },
3967 { "arch", s_arm_arch, 0 },
7a1d4c38 3968 { "object_arch", s_arm_object_arch, 0 },
8463be01 3969 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3970#ifdef OBJ_ELF
3971 { "word", s_arm_elf_cons, 4 },
3972 { "long", s_arm_elf_cons, 4 },
3973 { "rel31", s_arm_rel31, 0 },
3974 { "fnstart", s_arm_unwind_fnstart, 0 },
3975 { "fnend", s_arm_unwind_fnend, 0 },
3976 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3977 { "personality", s_arm_unwind_personality, 0 },
3978 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3979 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3980 { "save", s_arm_unwind_save, 0 },
fa073d69 3981 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3982 { "movsp", s_arm_unwind_movsp, 0 },
3983 { "pad", s_arm_unwind_pad, 0 },
3984 { "setfp", s_arm_unwind_setfp, 0 },
3985 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3986 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3987#else
3988 { "word", cons, 4},
f0927246
NC
3989
3990 /* These are used for dwarf. */
3991 {"2byte", cons, 2},
3992 {"4byte", cons, 4},
3993 {"8byte", cons, 8},
3994 /* These are used for dwarf2. */
3995 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3996 { "loc", dwarf2_directive_loc, 0 },
3997 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3998#endif
3999 { "extend", float_cons, 'x' },
4000 { "ldouble", float_cons, 'x' },
4001 { "packed", float_cons, 'p' },
f0927246
NC
4002#ifdef TE_PE
4003 {"secrel32", pe_directive_secrel, 0},
4004#endif
c19d1205
ZW
4005 { 0, 0, 0 }
4006};
4007\f
4008/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4009
c19d1205
ZW
4010/* Generic immediate-value read function for use in insn parsing.
4011 STR points to the beginning of the immediate (the leading #);
4012 VAL receives the value; if the value is outside [MIN, MAX]
4013 issue an error. PREFIX_OPT is true if the immediate prefix is
4014 optional. */
b99bd4ef 4015
c19d1205
ZW
4016static int
4017parse_immediate (char **str, int *val, int min, int max,
4018 bfd_boolean prefix_opt)
4019{
4020 expressionS exp;
4021 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4022 if (exp.X_op != O_constant)
b99bd4ef 4023 {
c19d1205
ZW
4024 inst.error = _("constant expression required");
4025 return FAIL;
4026 }
b99bd4ef 4027
c19d1205
ZW
4028 if (exp.X_add_number < min || exp.X_add_number > max)
4029 {
4030 inst.error = _("immediate value out of range");
4031 return FAIL;
4032 }
b99bd4ef 4033
c19d1205
ZW
4034 *val = exp.X_add_number;
4035 return SUCCESS;
4036}
b99bd4ef 4037
5287ad62 4038/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4039 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4040 instructions. Puts the result directly in inst.operands[i]. */
4041
4042static int
4043parse_big_immediate (char **str, int i)
4044{
4045 expressionS exp;
4046 char *ptr = *str;
4047
4048 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4049
4050 if (exp.X_op == O_constant)
036dc3f7
PB
4051 {
4052 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4053 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4054 O_constant. We have to be careful not to break compilation for
4055 32-bit X_add_number, though. */
4056 if ((exp.X_add_number & ~0xffffffffl) != 0)
4057 {
4058 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4059 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4060 inst.operands[i].regisimm = 1;
4061 }
4062 }
5287ad62
JB
4063 else if (exp.X_op == O_big
4064 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4065 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4066 {
4067 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4068 /* Bignums have their least significant bits in
4069 generic_bignum[0]. Make sure we put 32 bits in imm and
4070 32 bits in reg, in a (hopefully) portable way. */
4071 assert (parts != 0);
4072 inst.operands[i].imm = 0;
4073 for (j = 0; j < parts; j++, idx++)
4074 inst.operands[i].imm |= generic_bignum[idx]
4075 << (LITTLENUM_NUMBER_OF_BITS * j);
4076 inst.operands[i].reg = 0;
4077 for (j = 0; j < parts; j++, idx++)
4078 inst.operands[i].reg |= generic_bignum[idx]
4079 << (LITTLENUM_NUMBER_OF_BITS * j);
4080 inst.operands[i].regisimm = 1;
4081 }
4082 else
4083 return FAIL;
4084
4085 *str = ptr;
4086
4087 return SUCCESS;
4088}
4089
c19d1205
ZW
4090/* Returns the pseudo-register number of an FPA immediate constant,
4091 or FAIL if there isn't a valid constant here. */
b99bd4ef 4092
c19d1205
ZW
4093static int
4094parse_fpa_immediate (char ** str)
4095{
4096 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4097 char * save_in;
4098 expressionS exp;
4099 int i;
4100 int j;
b99bd4ef 4101
c19d1205
ZW
4102 /* First try and match exact strings, this is to guarantee
4103 that some formats will work even for cross assembly. */
b99bd4ef 4104
c19d1205
ZW
4105 for (i = 0; fp_const[i]; i++)
4106 {
4107 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4108 {
c19d1205 4109 char *start = *str;
b99bd4ef 4110
c19d1205
ZW
4111 *str += strlen (fp_const[i]);
4112 if (is_end_of_line[(unsigned char) **str])
4113 return i + 8;
4114 *str = start;
4115 }
4116 }
b99bd4ef 4117
c19d1205
ZW
4118 /* Just because we didn't get a match doesn't mean that the constant
4119 isn't valid, just that it is in a format that we don't
4120 automatically recognize. Try parsing it with the standard
4121 expression routines. */
b99bd4ef 4122
c19d1205 4123 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4124
c19d1205
ZW
4125 /* Look for a raw floating point number. */
4126 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4127 && is_end_of_line[(unsigned char) *save_in])
4128 {
4129 for (i = 0; i < NUM_FLOAT_VALS; i++)
4130 {
4131 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4132 {
c19d1205
ZW
4133 if (words[j] != fp_values[i][j])
4134 break;
b99bd4ef
NC
4135 }
4136
c19d1205 4137 if (j == MAX_LITTLENUMS)
b99bd4ef 4138 {
c19d1205
ZW
4139 *str = save_in;
4140 return i + 8;
b99bd4ef
NC
4141 }
4142 }
4143 }
b99bd4ef 4144
c19d1205
ZW
4145 /* Try and parse a more complex expression, this will probably fail
4146 unless the code uses a floating point prefix (eg "0f"). */
4147 save_in = input_line_pointer;
4148 input_line_pointer = *str;
4149 if (expression (&exp) == absolute_section
4150 && exp.X_op == O_big
4151 && exp.X_add_number < 0)
4152 {
4153 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4154 Ditto for 15. */
4155 if (gen_to_words (words, 5, (long) 15) == 0)
4156 {
4157 for (i = 0; i < NUM_FLOAT_VALS; i++)
4158 {
4159 for (j = 0; j < MAX_LITTLENUMS; j++)
4160 {
4161 if (words[j] != fp_values[i][j])
4162 break;
4163 }
b99bd4ef 4164
c19d1205
ZW
4165 if (j == MAX_LITTLENUMS)
4166 {
4167 *str = input_line_pointer;
4168 input_line_pointer = save_in;
4169 return i + 8;
4170 }
4171 }
4172 }
b99bd4ef
NC
4173 }
4174
c19d1205
ZW
4175 *str = input_line_pointer;
4176 input_line_pointer = save_in;
4177 inst.error = _("invalid FPA immediate expression");
4178 return FAIL;
b99bd4ef
NC
4179}
4180
136da414
JB
4181/* Returns 1 if a number has "quarter-precision" float format
4182 0baBbbbbbc defgh000 00000000 00000000. */
4183
4184static int
4185is_quarter_float (unsigned imm)
4186{
4187 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4188 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4189}
4190
4191/* Parse an 8-bit "quarter-precision" floating point number of the form:
4192 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4193 The zero and minus-zero cases need special handling, since they can't be
4194 encoded in the "quarter-precision" float format, but can nonetheless be
4195 loaded as integer constants. */
136da414
JB
4196
4197static unsigned
4198parse_qfloat_immediate (char **ccp, int *immed)
4199{
4200 char *str = *ccp;
c96612cc 4201 char *fpnum;
136da414 4202 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4203 int found_fpchar = 0;
136da414
JB
4204
4205 skip_past_char (&str, '#');
4206
c96612cc
JB
4207 /* We must not accidentally parse an integer as a floating-point number. Make
4208 sure that the value we parse is not an integer by checking for special
4209 characters '.' or 'e'.
4210 FIXME: This is a horrible hack, but doing better is tricky because type
4211 information isn't in a very usable state at parse time. */
4212 fpnum = str;
4213 skip_whitespace (fpnum);
4214
4215 if (strncmp (fpnum, "0x", 2) == 0)
4216 return FAIL;
4217 else
4218 {
4219 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4220 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4221 {
4222 found_fpchar = 1;
4223 break;
4224 }
4225
4226 if (!found_fpchar)
4227 return FAIL;
4228 }
4229
136da414
JB
4230 if ((str = atof_ieee (str, 's', words)) != NULL)
4231 {
4232 unsigned fpword = 0;
4233 int i;
4234
4235 /* Our FP word must be 32 bits (single-precision FP). */
4236 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4237 {
4238 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4239 fpword |= words[i];
4240 }
4241
c96612cc 4242 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4243 *immed = fpword;
4244 else
4245 return FAIL;
4246
4247 *ccp = str;
4248
4249 return SUCCESS;
4250 }
4251
4252 return FAIL;
4253}
4254
c19d1205
ZW
4255/* Shift operands. */
4256enum shift_kind
b99bd4ef 4257{
c19d1205
ZW
4258 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4259};
b99bd4ef 4260
c19d1205
ZW
4261struct asm_shift_name
4262{
4263 const char *name;
4264 enum shift_kind kind;
4265};
b99bd4ef 4266
c19d1205
ZW
4267/* Third argument to parse_shift. */
4268enum parse_shift_mode
4269{
4270 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4271 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4272 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4273 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4274 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4275};
b99bd4ef 4276
c19d1205
ZW
4277/* Parse a <shift> specifier on an ARM data processing instruction.
4278 This has three forms:
b99bd4ef 4279
c19d1205
ZW
4280 (LSL|LSR|ASL|ASR|ROR) Rs
4281 (LSL|LSR|ASL|ASR|ROR) #imm
4282 RRX
b99bd4ef 4283
c19d1205
ZW
4284 Note that ASL is assimilated to LSL in the instruction encoding, and
4285 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4286
c19d1205
ZW
4287static int
4288parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4289{
c19d1205
ZW
4290 const struct asm_shift_name *shift_name;
4291 enum shift_kind shift;
4292 char *s = *str;
4293 char *p = s;
4294 int reg;
b99bd4ef 4295
c19d1205
ZW
4296 for (p = *str; ISALPHA (*p); p++)
4297 ;
b99bd4ef 4298
c19d1205 4299 if (p == *str)
b99bd4ef 4300 {
c19d1205
ZW
4301 inst.error = _("shift expression expected");
4302 return FAIL;
b99bd4ef
NC
4303 }
4304
c19d1205
ZW
4305 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4306
4307 if (shift_name == NULL)
b99bd4ef 4308 {
c19d1205
ZW
4309 inst.error = _("shift expression expected");
4310 return FAIL;
b99bd4ef
NC
4311 }
4312
c19d1205 4313 shift = shift_name->kind;
b99bd4ef 4314
c19d1205
ZW
4315 switch (mode)
4316 {
4317 case NO_SHIFT_RESTRICT:
4318 case SHIFT_IMMEDIATE: break;
b99bd4ef 4319
c19d1205
ZW
4320 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4321 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4322 {
4323 inst.error = _("'LSL' or 'ASR' required");
4324 return FAIL;
4325 }
4326 break;
b99bd4ef 4327
c19d1205
ZW
4328 case SHIFT_LSL_IMMEDIATE:
4329 if (shift != SHIFT_LSL)
4330 {
4331 inst.error = _("'LSL' required");
4332 return FAIL;
4333 }
4334 break;
b99bd4ef 4335
c19d1205
ZW
4336 case SHIFT_ASR_IMMEDIATE:
4337 if (shift != SHIFT_ASR)
4338 {
4339 inst.error = _("'ASR' required");
4340 return FAIL;
4341 }
4342 break;
b99bd4ef 4343
c19d1205
ZW
4344 default: abort ();
4345 }
b99bd4ef 4346
c19d1205
ZW
4347 if (shift != SHIFT_RRX)
4348 {
4349 /* Whitespace can appear here if the next thing is a bare digit. */
4350 skip_whitespace (p);
b99bd4ef 4351
c19d1205 4352 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4353 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4354 {
4355 inst.operands[i].imm = reg;
4356 inst.operands[i].immisreg = 1;
4357 }
4358 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4359 return FAIL;
4360 }
4361 inst.operands[i].shift_kind = shift;
4362 inst.operands[i].shifted = 1;
4363 *str = p;
4364 return SUCCESS;
b99bd4ef
NC
4365}
4366
c19d1205 4367/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4368
c19d1205
ZW
4369 #<immediate>
4370 #<immediate>, <rotate>
4371 <Rm>
4372 <Rm>, <shift>
b99bd4ef 4373
c19d1205
ZW
4374 where <shift> is defined by parse_shift above, and <rotate> is a
4375 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4376 is deferred to md_apply_fix. */
b99bd4ef 4377
c19d1205
ZW
4378static int
4379parse_shifter_operand (char **str, int i)
4380{
4381 int value;
4382 expressionS expr;
b99bd4ef 4383
dcbf9037 4384 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4385 {
4386 inst.operands[i].reg = value;
4387 inst.operands[i].isreg = 1;
b99bd4ef 4388
c19d1205
ZW
4389 /* parse_shift will override this if appropriate */
4390 inst.reloc.exp.X_op = O_constant;
4391 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4392
c19d1205
ZW
4393 if (skip_past_comma (str) == FAIL)
4394 return SUCCESS;
b99bd4ef 4395
c19d1205
ZW
4396 /* Shift operation on register. */
4397 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4398 }
4399
c19d1205
ZW
4400 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4401 return FAIL;
b99bd4ef 4402
c19d1205 4403 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4404 {
c19d1205
ZW
4405 /* #x, y -- ie explicit rotation by Y. */
4406 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4407 return FAIL;
b99bd4ef 4408
c19d1205
ZW
4409 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4410 {
4411 inst.error = _("constant expression expected");
4412 return FAIL;
4413 }
b99bd4ef 4414
c19d1205
ZW
4415 value = expr.X_add_number;
4416 if (value < 0 || value > 30 || value % 2 != 0)
4417 {
4418 inst.error = _("invalid rotation");
4419 return FAIL;
4420 }
4421 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4422 {
4423 inst.error = _("invalid constant");
4424 return FAIL;
4425 }
09d92015 4426
55cf6793 4427 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4428 inst.reloc.exp.X_add_number
4429 = (((inst.reloc.exp.X_add_number << (32 - value))
4430 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4431 }
4432
c19d1205
ZW
4433 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4434 inst.reloc.pc_rel = 0;
4435 return SUCCESS;
09d92015
MM
4436}
4437
4962c51a
MS
4438/* Group relocation information. Each entry in the table contains the
4439 textual name of the relocation as may appear in assembler source
4440 and must end with a colon.
4441 Along with this textual name are the relocation codes to be used if
4442 the corresponding instruction is an ALU instruction (ADD or SUB only),
4443 an LDR, an LDRS, or an LDC. */
4444
4445struct group_reloc_table_entry
4446{
4447 const char *name;
4448 int alu_code;
4449 int ldr_code;
4450 int ldrs_code;
4451 int ldc_code;
4452};
4453
4454typedef enum
4455{
4456 /* Varieties of non-ALU group relocation. */
4457
4458 GROUP_LDR,
4459 GROUP_LDRS,
4460 GROUP_LDC
4461} group_reloc_type;
4462
4463static struct group_reloc_table_entry group_reloc_table[] =
4464 { /* Program counter relative: */
4465 { "pc_g0_nc",
4466 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4467 0, /* LDR */
4468 0, /* LDRS */
4469 0 }, /* LDC */
4470 { "pc_g0",
4471 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4472 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4473 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4474 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4475 { "pc_g1_nc",
4476 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4477 0, /* LDR */
4478 0, /* LDRS */
4479 0 }, /* LDC */
4480 { "pc_g1",
4481 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4482 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4483 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4484 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4485 { "pc_g2",
4486 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4487 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4488 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4489 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4490 /* Section base relative */
4491 { "sb_g0_nc",
4492 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4493 0, /* LDR */
4494 0, /* LDRS */
4495 0 }, /* LDC */
4496 { "sb_g0",
4497 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4498 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4499 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4500 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4501 { "sb_g1_nc",
4502 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4503 0, /* LDR */
4504 0, /* LDRS */
4505 0 }, /* LDC */
4506 { "sb_g1",
4507 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4508 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4509 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4510 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4511 { "sb_g2",
4512 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4513 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4514 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4515 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4516
4517/* Given the address of a pointer pointing to the textual name of a group
4518 relocation as may appear in assembler source, attempt to find its details
4519 in group_reloc_table. The pointer will be updated to the character after
4520 the trailing colon. On failure, FAIL will be returned; SUCCESS
4521 otherwise. On success, *entry will be updated to point at the relevant
4522 group_reloc_table entry. */
4523
4524static int
4525find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4526{
4527 unsigned int i;
4528 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4529 {
4530 int length = strlen (group_reloc_table[i].name);
4531
4532 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4533 (*str)[length] == ':')
4534 {
4535 *out = &group_reloc_table[i];
4536 *str += (length + 1);
4537 return SUCCESS;
4538 }
4539 }
4540
4541 return FAIL;
4542}
4543
4544/* Parse a <shifter_operand> for an ARM data processing instruction
4545 (as for parse_shifter_operand) where group relocations are allowed:
4546
4547 #<immediate>
4548 #<immediate>, <rotate>
4549 #:<group_reloc>:<expression>
4550 <Rm>
4551 <Rm>, <shift>
4552
4553 where <group_reloc> is one of the strings defined in group_reloc_table.
4554 The hashes are optional.
4555
4556 Everything else is as for parse_shifter_operand. */
4557
4558static parse_operand_result
4559parse_shifter_operand_group_reloc (char **str, int i)
4560{
4561 /* Determine if we have the sequence of characters #: or just :
4562 coming next. If we do, then we check for a group relocation.
4563 If we don't, punt the whole lot to parse_shifter_operand. */
4564
4565 if (((*str)[0] == '#' && (*str)[1] == ':')
4566 || (*str)[0] == ':')
4567 {
4568 struct group_reloc_table_entry *entry;
4569
4570 if ((*str)[0] == '#')
4571 (*str) += 2;
4572 else
4573 (*str)++;
4574
4575 /* Try to parse a group relocation. Anything else is an error. */
4576 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4577 {
4578 inst.error = _("unknown group relocation");
4579 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4580 }
4581
4582 /* We now have the group relocation table entry corresponding to
4583 the name in the assembler source. Next, we parse the expression. */
4584 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4585 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4586
4587 /* Record the relocation type (always the ALU variant here). */
4588 inst.reloc.type = entry->alu_code;
4589 assert (inst.reloc.type != 0);
4590
4591 return PARSE_OPERAND_SUCCESS;
4592 }
4593 else
4594 return parse_shifter_operand (str, i) == SUCCESS
4595 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4596
4597 /* Never reached. */
4598}
4599
c19d1205
ZW
4600/* Parse all forms of an ARM address expression. Information is written
4601 to inst.operands[i] and/or inst.reloc.
09d92015 4602
c19d1205 4603 Preindexed addressing (.preind=1):
09d92015 4604
c19d1205
ZW
4605 [Rn, #offset] .reg=Rn .reloc.exp=offset
4606 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4607 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4608 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4609
c19d1205 4610 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4611
c19d1205 4612 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4613
c19d1205
ZW
4614 [Rn], #offset .reg=Rn .reloc.exp=offset
4615 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4616 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4617 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4618
c19d1205 4619 Unindexed addressing (.preind=0, .postind=0):
09d92015 4620
c19d1205 4621 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4622
c19d1205 4623 Other:
09d92015 4624
c19d1205
ZW
4625 [Rn]{!} shorthand for [Rn,#0]{!}
4626 =immediate .isreg=0 .reloc.exp=immediate
4627 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4628
c19d1205
ZW
4629 It is the caller's responsibility to check for addressing modes not
4630 supported by the instruction, and to set inst.reloc.type. */
4631
4962c51a
MS
4632static parse_operand_result
4633parse_address_main (char **str, int i, int group_relocations,
4634 group_reloc_type group_type)
09d92015 4635{
c19d1205
ZW
4636 char *p = *str;
4637 int reg;
09d92015 4638
c19d1205 4639 if (skip_past_char (&p, '[') == FAIL)
09d92015 4640 {
c19d1205
ZW
4641 if (skip_past_char (&p, '=') == FAIL)
4642 {
4643 /* bare address - translate to PC-relative offset */
4644 inst.reloc.pc_rel = 1;
4645 inst.operands[i].reg = REG_PC;
4646 inst.operands[i].isreg = 1;
4647 inst.operands[i].preind = 1;
4648 }
4649 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4650
c19d1205 4651 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4652 return PARSE_OPERAND_FAIL;
09d92015 4653
c19d1205 4654 *str = p;
4962c51a 4655 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4656 }
4657
dcbf9037 4658 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4659 {
c19d1205 4660 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4661 return PARSE_OPERAND_FAIL;
09d92015 4662 }
c19d1205
ZW
4663 inst.operands[i].reg = reg;
4664 inst.operands[i].isreg = 1;
09d92015 4665
c19d1205 4666 if (skip_past_comma (&p) == SUCCESS)
09d92015 4667 {
c19d1205 4668 inst.operands[i].preind = 1;
09d92015 4669
c19d1205
ZW
4670 if (*p == '+') p++;
4671 else if (*p == '-') p++, inst.operands[i].negative = 1;
4672
dcbf9037 4673 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4674 {
c19d1205
ZW
4675 inst.operands[i].imm = reg;
4676 inst.operands[i].immisreg = 1;
4677
4678 if (skip_past_comma (&p) == SUCCESS)
4679 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4680 return PARSE_OPERAND_FAIL;
c19d1205 4681 }
5287ad62
JB
4682 else if (skip_past_char (&p, ':') == SUCCESS)
4683 {
4684 /* FIXME: '@' should be used here, but it's filtered out by generic
4685 code before we get to see it here. This may be subject to
4686 change. */
4687 expressionS exp;
4688 my_get_expression (&exp, &p, GE_NO_PREFIX);
4689 if (exp.X_op != O_constant)
4690 {
4691 inst.error = _("alignment must be constant");
4962c51a 4692 return PARSE_OPERAND_FAIL;
5287ad62
JB
4693 }
4694 inst.operands[i].imm = exp.X_add_number << 8;
4695 inst.operands[i].immisalign = 1;
4696 /* Alignments are not pre-indexes. */
4697 inst.operands[i].preind = 0;
4698 }
c19d1205
ZW
4699 else
4700 {
4701 if (inst.operands[i].negative)
4702 {
4703 inst.operands[i].negative = 0;
4704 p--;
4705 }
4962c51a
MS
4706
4707 if (group_relocations &&
4708 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4709
4710 {
4711 struct group_reloc_table_entry *entry;
4712
4713 /* Skip over the #: or : sequence. */
4714 if (*p == '#')
4715 p += 2;
4716 else
4717 p++;
4718
4719 /* Try to parse a group relocation. Anything else is an
4720 error. */
4721 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4722 {
4723 inst.error = _("unknown group relocation");
4724 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4725 }
4726
4727 /* We now have the group relocation table entry corresponding to
4728 the name in the assembler source. Next, we parse the
4729 expression. */
4730 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4731 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4732
4733 /* Record the relocation type. */
4734 switch (group_type)
4735 {
4736 case GROUP_LDR:
4737 inst.reloc.type = entry->ldr_code;
4738 break;
4739
4740 case GROUP_LDRS:
4741 inst.reloc.type = entry->ldrs_code;
4742 break;
4743
4744 case GROUP_LDC:
4745 inst.reloc.type = entry->ldc_code;
4746 break;
4747
4748 default:
4749 assert (0);
4750 }
4751
4752 if (inst.reloc.type == 0)
4753 {
4754 inst.error = _("this group relocation is not allowed on this instruction");
4755 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4756 }
4757 }
4758 else
4759 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4760 return PARSE_OPERAND_FAIL;
09d92015
MM
4761 }
4762 }
4763
c19d1205 4764 if (skip_past_char (&p, ']') == FAIL)
09d92015 4765 {
c19d1205 4766 inst.error = _("']' expected");
4962c51a 4767 return PARSE_OPERAND_FAIL;
09d92015
MM
4768 }
4769
c19d1205
ZW
4770 if (skip_past_char (&p, '!') == SUCCESS)
4771 inst.operands[i].writeback = 1;
09d92015 4772
c19d1205 4773 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4774 {
c19d1205
ZW
4775 if (skip_past_char (&p, '{') == SUCCESS)
4776 {
4777 /* [Rn], {expr} - unindexed, with option */
4778 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4779 0, 255, TRUE) == FAIL)
4962c51a 4780 return PARSE_OPERAND_FAIL;
09d92015 4781
c19d1205
ZW
4782 if (skip_past_char (&p, '}') == FAIL)
4783 {
4784 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4785 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4786 }
4787 if (inst.operands[i].preind)
4788 {
4789 inst.error = _("cannot combine index with option");
4962c51a 4790 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4791 }
4792 *str = p;
4962c51a 4793 return PARSE_OPERAND_SUCCESS;
09d92015 4794 }
c19d1205
ZW
4795 else
4796 {
4797 inst.operands[i].postind = 1;
4798 inst.operands[i].writeback = 1;
09d92015 4799
c19d1205
ZW
4800 if (inst.operands[i].preind)
4801 {
4802 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4803 return PARSE_OPERAND_FAIL;
c19d1205 4804 }
09d92015 4805
c19d1205
ZW
4806 if (*p == '+') p++;
4807 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4808
dcbf9037 4809 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4810 {
5287ad62
JB
4811 /* We might be using the immediate for alignment already. If we
4812 are, OR the register number into the low-order bits. */
4813 if (inst.operands[i].immisalign)
4814 inst.operands[i].imm |= reg;
4815 else
4816 inst.operands[i].imm = reg;
c19d1205 4817 inst.operands[i].immisreg = 1;
a737bd4d 4818
c19d1205
ZW
4819 if (skip_past_comma (&p) == SUCCESS)
4820 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4821 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4822 }
4823 else
4824 {
4825 if (inst.operands[i].negative)
4826 {
4827 inst.operands[i].negative = 0;
4828 p--;
4829 }
4830 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4831 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4832 }
4833 }
a737bd4d
NC
4834 }
4835
c19d1205
ZW
4836 /* If at this point neither .preind nor .postind is set, we have a
4837 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4838 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4839 {
4840 inst.operands[i].preind = 1;
4841 inst.reloc.exp.X_op = O_constant;
4842 inst.reloc.exp.X_add_number = 0;
4843 }
4844 *str = p;
4962c51a
MS
4845 return PARSE_OPERAND_SUCCESS;
4846}
4847
4848static int
4849parse_address (char **str, int i)
4850{
4851 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4852 ? SUCCESS : FAIL;
4853}
4854
4855static parse_operand_result
4856parse_address_group_reloc (char **str, int i, group_reloc_type type)
4857{
4858 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4859}
4860
b6895b4f
PB
4861/* Parse an operand for a MOVW or MOVT instruction. */
4862static int
4863parse_half (char **str)
4864{
4865 char * p;
4866
4867 p = *str;
4868 skip_past_char (&p, '#');
4869 if (strncasecmp (p, ":lower16:", 9) == 0)
4870 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4871 else if (strncasecmp (p, ":upper16:", 9) == 0)
4872 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4873
4874 if (inst.reloc.type != BFD_RELOC_UNUSED)
4875 {
4876 p += 9;
4877 skip_whitespace(p);
4878 }
4879
4880 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4881 return FAIL;
4882
4883 if (inst.reloc.type == BFD_RELOC_UNUSED)
4884 {
4885 if (inst.reloc.exp.X_op != O_constant)
4886 {
4887 inst.error = _("constant expression expected");
4888 return FAIL;
4889 }
4890 if (inst.reloc.exp.X_add_number < 0
4891 || inst.reloc.exp.X_add_number > 0xffff)
4892 {
4893 inst.error = _("immediate value out of range");
4894 return FAIL;
4895 }
4896 }
4897 *str = p;
4898 return SUCCESS;
4899}
4900
c19d1205 4901/* Miscellaneous. */
a737bd4d 4902
c19d1205
ZW
4903/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4904 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4905static int
4906parse_psr (char **str)
09d92015 4907{
c19d1205
ZW
4908 char *p;
4909 unsigned long psr_field;
62b3e311
PB
4910 const struct asm_psr *psr;
4911 char *start;
09d92015 4912
c19d1205
ZW
4913 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4914 feature for ease of use and backwards compatibility. */
4915 p = *str;
62b3e311 4916 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4917 psr_field = SPSR_BIT;
62b3e311 4918 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4919 psr_field = 0;
4920 else
62b3e311
PB
4921 {
4922 start = p;
4923 do
4924 p++;
4925 while (ISALNUM (*p) || *p == '_');
4926
4927 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4928 if (!psr)
4929 return FAIL;
09d92015 4930
62b3e311
PB
4931 *str = p;
4932 return psr->field;
4933 }
09d92015 4934
62b3e311 4935 p += 4;
c19d1205
ZW
4936 if (*p == '_')
4937 {
4938 /* A suffix follows. */
c19d1205
ZW
4939 p++;
4940 start = p;
a737bd4d 4941
c19d1205
ZW
4942 do
4943 p++;
4944 while (ISALNUM (*p) || *p == '_');
a737bd4d 4945
c19d1205
ZW
4946 psr = hash_find_n (arm_psr_hsh, start, p - start);
4947 if (!psr)
4948 goto error;
a737bd4d 4949
c19d1205 4950 psr_field |= psr->field;
a737bd4d 4951 }
c19d1205 4952 else
a737bd4d 4953 {
c19d1205
ZW
4954 if (ISALNUM (*p))
4955 goto error; /* Garbage after "[CS]PSR". */
4956
4957 psr_field |= (PSR_c | PSR_f);
a737bd4d 4958 }
c19d1205
ZW
4959 *str = p;
4960 return psr_field;
a737bd4d 4961
c19d1205
ZW
4962 error:
4963 inst.error = _("flag for {c}psr instruction expected");
4964 return FAIL;
a737bd4d
NC
4965}
4966
c19d1205
ZW
4967/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4968 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4969
c19d1205
ZW
4970static int
4971parse_cps_flags (char **str)
a737bd4d 4972{
c19d1205
ZW
4973 int val = 0;
4974 int saw_a_flag = 0;
4975 char *s = *str;
a737bd4d 4976
c19d1205
ZW
4977 for (;;)
4978 switch (*s++)
4979 {
4980 case '\0': case ',':
4981 goto done;
a737bd4d 4982
c19d1205
ZW
4983 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4984 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4985 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4986
c19d1205
ZW
4987 default:
4988 inst.error = _("unrecognized CPS flag");
4989 return FAIL;
4990 }
a737bd4d 4991
c19d1205
ZW
4992 done:
4993 if (saw_a_flag == 0)
a737bd4d 4994 {
c19d1205
ZW
4995 inst.error = _("missing CPS flags");
4996 return FAIL;
a737bd4d 4997 }
a737bd4d 4998
c19d1205
ZW
4999 *str = s - 1;
5000 return val;
a737bd4d
NC
5001}
5002
c19d1205
ZW
5003/* Parse an endian specifier ("BE" or "LE", case insensitive);
5004 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5005
5006static int
c19d1205 5007parse_endian_specifier (char **str)
a737bd4d 5008{
c19d1205
ZW
5009 int little_endian;
5010 char *s = *str;
a737bd4d 5011
c19d1205
ZW
5012 if (strncasecmp (s, "BE", 2))
5013 little_endian = 0;
5014 else if (strncasecmp (s, "LE", 2))
5015 little_endian = 1;
5016 else
a737bd4d 5017 {
c19d1205 5018 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5019 return FAIL;
5020 }
5021
c19d1205 5022 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5023 {
c19d1205 5024 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5025 return FAIL;
5026 }
5027
c19d1205
ZW
5028 *str = s + 2;
5029 return little_endian;
5030}
a737bd4d 5031
c19d1205
ZW
5032/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5033 value suitable for poking into the rotate field of an sxt or sxta
5034 instruction, or FAIL on error. */
5035
5036static int
5037parse_ror (char **str)
5038{
5039 int rot;
5040 char *s = *str;
5041
5042 if (strncasecmp (s, "ROR", 3) == 0)
5043 s += 3;
5044 else
a737bd4d 5045 {
c19d1205 5046 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5047 return FAIL;
5048 }
c19d1205
ZW
5049
5050 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5051 return FAIL;
5052
5053 switch (rot)
a737bd4d 5054 {
c19d1205
ZW
5055 case 0: *str = s; return 0x0;
5056 case 8: *str = s; return 0x1;
5057 case 16: *str = s; return 0x2;
5058 case 24: *str = s; return 0x3;
5059
5060 default:
5061 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5062 return FAIL;
5063 }
c19d1205 5064}
a737bd4d 5065
c19d1205
ZW
5066/* Parse a conditional code (from conds[] below). The value returned is in the
5067 range 0 .. 14, or FAIL. */
5068static int
5069parse_cond (char **str)
5070{
5071 char *p, *q;
5072 const struct asm_cond *c;
a737bd4d 5073
c19d1205
ZW
5074 p = q = *str;
5075 while (ISALPHA (*q))
5076 q++;
a737bd4d 5077
c19d1205
ZW
5078 c = hash_find_n (arm_cond_hsh, p, q - p);
5079 if (!c)
a737bd4d 5080 {
c19d1205 5081 inst.error = _("condition required");
a737bd4d
NC
5082 return FAIL;
5083 }
5084
c19d1205
ZW
5085 *str = q;
5086 return c->value;
5087}
5088
62b3e311
PB
5089/* Parse an option for a barrier instruction. Returns the encoding for the
5090 option, or FAIL. */
5091static int
5092parse_barrier (char **str)
5093{
5094 char *p, *q;
5095 const struct asm_barrier_opt *o;
5096
5097 p = q = *str;
5098 while (ISALPHA (*q))
5099 q++;
5100
5101 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5102 if (!o)
5103 return FAIL;
5104
5105 *str = q;
5106 return o->value;
5107}
5108
92e90b6e
PB
5109/* Parse the operands of a table branch instruction. Similar to a memory
5110 operand. */
5111static int
5112parse_tb (char **str)
5113{
5114 char * p = *str;
5115 int reg;
5116
5117 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5118 {
5119 inst.error = _("'[' expected");
5120 return FAIL;
5121 }
92e90b6e 5122
dcbf9037 5123 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5124 {
5125 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5126 return FAIL;
5127 }
5128 inst.operands[0].reg = reg;
5129
5130 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5131 {
5132 inst.error = _("',' expected");
5133 return FAIL;
5134 }
92e90b6e 5135
dcbf9037 5136 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5137 {
5138 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5139 return FAIL;
5140 }
5141 inst.operands[0].imm = reg;
5142
5143 if (skip_past_comma (&p) == SUCCESS)
5144 {
5145 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5146 return FAIL;
5147 if (inst.reloc.exp.X_add_number != 1)
5148 {
5149 inst.error = _("invalid shift");
5150 return FAIL;
5151 }
5152 inst.operands[0].shifted = 1;
5153 }
5154
5155 if (skip_past_char (&p, ']') == FAIL)
5156 {
5157 inst.error = _("']' expected");
5158 return FAIL;
5159 }
5160 *str = p;
5161 return SUCCESS;
5162}
5163
5287ad62
JB
5164/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5165 information on the types the operands can take and how they are encoded.
037e8744
JB
5166 Up to four operands may be read; this function handles setting the
5167 ".present" field for each read operand itself.
5287ad62
JB
5168 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5169 else returns FAIL. */
5170
5171static int
5172parse_neon_mov (char **str, int *which_operand)
5173{
5174 int i = *which_operand, val;
5175 enum arm_reg_type rtype;
5176 char *ptr = *str;
dcbf9037 5177 struct neon_type_el optype;
5287ad62 5178
dcbf9037 5179 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5180 {
5181 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5182 inst.operands[i].reg = val;
5183 inst.operands[i].isscalar = 1;
dcbf9037 5184 inst.operands[i].vectype = optype;
5287ad62
JB
5185 inst.operands[i++].present = 1;
5186
5187 if (skip_past_comma (&ptr) == FAIL)
5188 goto wanted_comma;
5189
dcbf9037 5190 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62
JB
5191 goto wanted_arm;
5192
5193 inst.operands[i].reg = val;
5194 inst.operands[i].isreg = 1;
5195 inst.operands[i].present = 1;
5196 }
037e8744 5197 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5198 != FAIL)
5287ad62
JB
5199 {
5200 /* Cases 0, 1, 2, 3, 5 (D only). */
5201 if (skip_past_comma (&ptr) == FAIL)
5202 goto wanted_comma;
5203
5204 inst.operands[i].reg = val;
5205 inst.operands[i].isreg = 1;
5206 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5207 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5208 inst.operands[i].isvec = 1;
dcbf9037 5209 inst.operands[i].vectype = optype;
5287ad62
JB
5210 inst.operands[i++].present = 1;
5211
dcbf9037 5212 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5213 {
037e8744
JB
5214 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5215 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5216 inst.operands[i].reg = val;
5217 inst.operands[i].isreg = 1;
037e8744 5218 inst.operands[i].present = 1;
5287ad62
JB
5219
5220 if (rtype == REG_TYPE_NQ)
5221 {
dcbf9037 5222 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5223 return FAIL;
5224 }
037e8744
JB
5225 else if (rtype != REG_TYPE_VFS)
5226 {
5227 i++;
5228 if (skip_past_comma (&ptr) == FAIL)
5229 goto wanted_comma;
5230 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5231 goto wanted_arm;
5232 inst.operands[i].reg = val;
5233 inst.operands[i].isreg = 1;
5234 inst.operands[i].present = 1;
5235 }
5287ad62 5236 }
136da414 5237 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5238 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5239 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5240 Case 10: VMOV.F32 <Sd>, #<imm>
5241 Case 11: VMOV.F64 <Dd>, #<imm> */
c96612cc 5242 inst.operands[i].immisfloat = 1;
5287ad62 5243 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5244 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5245 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5246 ;
5247 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5248 &optype)) != FAIL)
5287ad62
JB
5249 {
5250 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5251 Case 1: VMOV<c><q> <Dd>, <Dm>
5252 Case 8: VMOV.F32 <Sd>, <Sm>
5253 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5254
5255 inst.operands[i].reg = val;
5256 inst.operands[i].isreg = 1;
5257 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5258 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5259 inst.operands[i].isvec = 1;
dcbf9037 5260 inst.operands[i].vectype = optype;
5287ad62 5261 inst.operands[i].present = 1;
037e8744
JB
5262
5263 if (skip_past_comma (&ptr) == SUCCESS)
5264 {
5265 /* Case 15. */
5266 i++;
5267
5268 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5269 goto wanted_arm;
5270
5271 inst.operands[i].reg = val;
5272 inst.operands[i].isreg = 1;
5273 inst.operands[i++].present = 1;
5274
5275 if (skip_past_comma (&ptr) == FAIL)
5276 goto wanted_comma;
5277
5278 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5279 goto wanted_arm;
5280
5281 inst.operands[i].reg = val;
5282 inst.operands[i].isreg = 1;
5283 inst.operands[i++].present = 1;
5284 }
5287ad62
JB
5285 }
5286 else
5287 {
dcbf9037 5288 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5289 return FAIL;
5290 }
5291 }
dcbf9037 5292 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5293 {
5294 /* Cases 6, 7. */
5295 inst.operands[i].reg = val;
5296 inst.operands[i].isreg = 1;
5297 inst.operands[i++].present = 1;
5298
5299 if (skip_past_comma (&ptr) == FAIL)
5300 goto wanted_comma;
5301
dcbf9037 5302 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5303 {
5304 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5305 inst.operands[i].reg = val;
5306 inst.operands[i].isscalar = 1;
5307 inst.operands[i].present = 1;
dcbf9037 5308 inst.operands[i].vectype = optype;
5287ad62 5309 }
dcbf9037 5310 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5311 {
5312 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5313 inst.operands[i].reg = val;
5314 inst.operands[i].isreg = 1;
5315 inst.operands[i++].present = 1;
5316
5317 if (skip_past_comma (&ptr) == FAIL)
5318 goto wanted_comma;
5319
037e8744 5320 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5321 == FAIL)
5287ad62 5322 {
037e8744 5323 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5324 return FAIL;
5325 }
5326
5327 inst.operands[i].reg = val;
5328 inst.operands[i].isreg = 1;
037e8744
JB
5329 inst.operands[i].isvec = 1;
5330 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5331 inst.operands[i].vectype = optype;
5287ad62 5332 inst.operands[i].present = 1;
037e8744
JB
5333
5334 if (rtype == REG_TYPE_VFS)
5335 {
5336 /* Case 14. */
5337 i++;
5338 if (skip_past_comma (&ptr) == FAIL)
5339 goto wanted_comma;
5340 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5341 &optype)) == FAIL)
5342 {
5343 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5344 return FAIL;
5345 }
5346 inst.operands[i].reg = val;
5347 inst.operands[i].isreg = 1;
5348 inst.operands[i].isvec = 1;
5349 inst.operands[i].issingle = 1;
5350 inst.operands[i].vectype = optype;
5351 inst.operands[i].present = 1;
5352 }
5353 }
5354 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5355 != FAIL)
5356 {
5357 /* Case 13. */
5358 inst.operands[i].reg = val;
5359 inst.operands[i].isreg = 1;
5360 inst.operands[i].isvec = 1;
5361 inst.operands[i].issingle = 1;
5362 inst.operands[i].vectype = optype;
5363 inst.operands[i++].present = 1;
5287ad62
JB
5364 }
5365 }
5366 else
5367 {
dcbf9037 5368 first_error (_("parse error"));
5287ad62
JB
5369 return FAIL;
5370 }
5371
5372 /* Successfully parsed the operands. Update args. */
5373 *which_operand = i;
5374 *str = ptr;
5375 return SUCCESS;
5376
5377 wanted_comma:
dcbf9037 5378 first_error (_("expected comma"));
5287ad62
JB
5379 return FAIL;
5380
5381 wanted_arm:
dcbf9037 5382 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5383 return FAIL;
5287ad62
JB
5384}
5385
c19d1205
ZW
5386/* Matcher codes for parse_operands. */
5387enum operand_parse_code
5388{
5389 OP_stop, /* end of line */
5390
5391 OP_RR, /* ARM register */
5392 OP_RRnpc, /* ARM register, not r15 */
5393 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5394 OP_RRw, /* ARM register, not r15, optional trailing ! */
5395 OP_RCP, /* Coprocessor number */
5396 OP_RCN, /* Coprocessor register */
5397 OP_RF, /* FPA register */
5398 OP_RVS, /* VFP single precision register */
5287ad62
JB
5399 OP_RVD, /* VFP double precision register (0..15) */
5400 OP_RND, /* Neon double precision register (0..31) */
5401 OP_RNQ, /* Neon quad precision register */
037e8744 5402 OP_RVSD, /* VFP single or double precision register */
5287ad62 5403 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5404 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5405 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5406 OP_RVC, /* VFP control register */
5407 OP_RMF, /* Maverick F register */
5408 OP_RMD, /* Maverick D register */
5409 OP_RMFX, /* Maverick FX register */
5410 OP_RMDX, /* Maverick DX register */
5411 OP_RMAX, /* Maverick AX register */
5412 OP_RMDS, /* Maverick DSPSC register */
5413 OP_RIWR, /* iWMMXt wR register */
5414 OP_RIWC, /* iWMMXt wC register */
5415 OP_RIWG, /* iWMMXt wCG register */
5416 OP_RXA, /* XScale accumulator register */
5417
5418 OP_REGLST, /* ARM register list */
5419 OP_VRSLST, /* VFP single-precision register list */
5420 OP_VRDLST, /* VFP double-precision register list */
037e8744 5421 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5422 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5423 OP_NSTRLST, /* Neon element/structure list */
5424
5425 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5426 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5427 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5428 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5429 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5430 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5431 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5432 OP_VMOV, /* Neon VMOV operands. */
5433 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5434 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5435 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5436
5437 OP_I0, /* immediate zero */
c19d1205
ZW
5438 OP_I7, /* immediate value 0 .. 7 */
5439 OP_I15, /* 0 .. 15 */
5440 OP_I16, /* 1 .. 16 */
5287ad62 5441 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5442 OP_I31, /* 0 .. 31 */
5443 OP_I31w, /* 0 .. 31, optional trailing ! */
5444 OP_I32, /* 1 .. 32 */
5287ad62
JB
5445 OP_I32z, /* 0 .. 32 */
5446 OP_I63, /* 0 .. 63 */
c19d1205 5447 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5448 OP_I64, /* 1 .. 64 */
5449 OP_I64z, /* 0 .. 64 */
c19d1205 5450 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5451
5452 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5453 OP_I7b, /* 0 .. 7 */
5454 OP_I15b, /* 0 .. 15 */
5455 OP_I31b, /* 0 .. 31 */
5456
5457 OP_SH, /* shifter operand */
4962c51a 5458 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5459 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5460 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5461 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5462 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5463 OP_EXP, /* arbitrary expression */
5464 OP_EXPi, /* same, with optional immediate prefix */
5465 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5466 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5467
5468 OP_CPSF, /* CPS flags */
5469 OP_ENDI, /* Endianness specifier */
5470 OP_PSR, /* CPSR/SPSR mask for msr */
5471 OP_COND, /* conditional code */
92e90b6e 5472 OP_TB, /* Table branch. */
c19d1205 5473
037e8744
JB
5474 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5475 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5476
c19d1205
ZW
5477 OP_RRnpc_I0, /* ARM register or literal 0 */
5478 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5479 OP_RR_EXi, /* ARM register or expression with imm prefix */
5480 OP_RF_IF, /* FPA register or immediate */
5481 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5482 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5483
5484 /* Optional operands. */
5485 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5486 OP_oI31b, /* 0 .. 31 */
5287ad62 5487 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5488 OP_oIffffb, /* 0 .. 65535 */
5489 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5490
5491 OP_oRR, /* ARM register */
5492 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5493 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5494 OP_oRND, /* Optional Neon double precision register */
5495 OP_oRNQ, /* Optional Neon quad precision register */
5496 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5497 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5498 OP_oSHll, /* LSL immediate */
5499 OP_oSHar, /* ASR immediate */
5500 OP_oSHllar, /* LSL or ASR immediate */
5501 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5502 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5503
5504 OP_FIRST_OPTIONAL = OP_oI7b
5505};
a737bd4d 5506
c19d1205
ZW
5507/* Generic instruction operand parser. This does no encoding and no
5508 semantic validation; it merely squirrels values away in the inst
5509 structure. Returns SUCCESS or FAIL depending on whether the
5510 specified grammar matched. */
5511static int
ca3f61f7 5512parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5513{
5514 unsigned const char *upat = pattern;
5515 char *backtrack_pos = 0;
5516 const char *backtrack_error = 0;
5517 int i, val, backtrack_index = 0;
5287ad62 5518 enum arm_reg_type rtype;
4962c51a 5519 parse_operand_result result;
c19d1205
ZW
5520
5521#define po_char_or_fail(chr) do { \
5522 if (skip_past_char (&str, chr) == FAIL) \
5523 goto bad_args; \
5524} while (0)
5525
dcbf9037
JB
5526#define po_reg_or_fail(regtype) do { \
5527 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5528 &inst.operands[i].vectype); \
5529 if (val == FAIL) \
5530 { \
5531 first_error (_(reg_expected_msgs[regtype])); \
5532 goto failure; \
5533 } \
5534 inst.operands[i].reg = val; \
5535 inst.operands[i].isreg = 1; \
5536 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5537 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5538 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5539 || rtype == REG_TYPE_VFD \
5540 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5541} while (0)
5542
dcbf9037
JB
5543#define po_reg_or_goto(regtype, label) do { \
5544 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5545 &inst.operands[i].vectype); \
5546 if (val == FAIL) \
5547 goto label; \
5548 \
5549 inst.operands[i].reg = val; \
5550 inst.operands[i].isreg = 1; \
5551 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5552 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5553 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5554 || rtype == REG_TYPE_VFD \
5555 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5556} while (0)
5557
5558#define po_imm_or_fail(min, max, popt) do { \
5559 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5560 goto failure; \
5561 inst.operands[i].imm = val; \
5562} while (0)
5563
dcbf9037
JB
5564#define po_scalar_or_goto(elsz, label) do { \
5565 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5566 if (val == FAIL) \
5567 goto label; \
5568 inst.operands[i].reg = val; \
5569 inst.operands[i].isscalar = 1; \
5287ad62
JB
5570} while (0)
5571
c19d1205
ZW
5572#define po_misc_or_fail(expr) do { \
5573 if (expr) \
5574 goto failure; \
5575} while (0)
5576
4962c51a
MS
5577#define po_misc_or_fail_no_backtrack(expr) do { \
5578 result = expr; \
5579 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5580 backtrack_pos = 0; \
5581 if (result != PARSE_OPERAND_SUCCESS) \
5582 goto failure; \
5583} while (0)
5584
c19d1205
ZW
5585 skip_whitespace (str);
5586
5587 for (i = 0; upat[i] != OP_stop; i++)
5588 {
5589 if (upat[i] >= OP_FIRST_OPTIONAL)
5590 {
5591 /* Remember where we are in case we need to backtrack. */
5592 assert (!backtrack_pos);
5593 backtrack_pos = str;
5594 backtrack_error = inst.error;
5595 backtrack_index = i;
5596 }
5597
b6702015 5598 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5599 po_char_or_fail (',');
5600
5601 switch (upat[i])
5602 {
5603 /* Registers */
5604 case OP_oRRnpc:
5605 case OP_RRnpc:
5606 case OP_oRR:
5607 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5608 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5609 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5610 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5611 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5612 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5613 case OP_oRND:
5614 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5615 case OP_RVC:
5616 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5617 break;
5618 /* Also accept generic coprocessor regs for unknown registers. */
5619 coproc_reg:
5620 po_reg_or_fail (REG_TYPE_CN);
5621 break;
c19d1205
ZW
5622 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5623 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5624 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5625 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5626 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5627 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5628 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5629 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5630 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5631 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5632 case OP_oRNQ:
5633 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5634 case OP_oRNDQ:
5635 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5636 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5637 case OP_oRNSDQ:
5638 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5639
5640 /* Neon scalar. Using an element size of 8 means that some invalid
5641 scalars are accepted here, so deal with those in later code. */
5642 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5643
5644 /* WARNING: We can expand to two operands here. This has the potential
5645 to totally confuse the backtracking mechanism! It will be OK at
5646 least as long as we don't try to use optional args as well,
5647 though. */
5648 case OP_NILO:
5649 {
5650 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5651 inst.operands[i].present = 1;
5287ad62
JB
5652 i++;
5653 skip_past_comma (&str);
5654 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5655 break;
5656 one_reg_only:
5657 /* Optional register operand was omitted. Unfortunately, it's in
5658 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5659 here (this is a bit grotty). */
5660 inst.operands[i] = inst.operands[i-1];
5661 inst.operands[i-1].present = 0;
5662 break;
5663 try_imm:
036dc3f7
PB
5664 /* There's a possibility of getting a 64-bit immediate here, so
5665 we need special handling. */
5666 if (parse_big_immediate (&str, i) == FAIL)
5667 {
5668 inst.error = _("immediate value is out of range");
5669 goto failure;
5670 }
5287ad62
JB
5671 }
5672 break;
5673
5674 case OP_RNDQ_I0:
5675 {
5676 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5677 break;
5678 try_imm0:
5679 po_imm_or_fail (0, 0, TRUE);
5680 }
5681 break;
5682
037e8744
JB
5683 case OP_RVSD_I0:
5684 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5685 break;
5686
5287ad62
JB
5687 case OP_RR_RNSC:
5688 {
5689 po_scalar_or_goto (8, try_rr);
5690 break;
5691 try_rr:
5692 po_reg_or_fail (REG_TYPE_RN);
5693 }
5694 break;
5695
037e8744
JB
5696 case OP_RNSDQ_RNSC:
5697 {
5698 po_scalar_or_goto (8, try_nsdq);
5699 break;
5700 try_nsdq:
5701 po_reg_or_fail (REG_TYPE_NSDQ);
5702 }
5703 break;
5704
5287ad62
JB
5705 case OP_RNDQ_RNSC:
5706 {
5707 po_scalar_or_goto (8, try_ndq);
5708 break;
5709 try_ndq:
5710 po_reg_or_fail (REG_TYPE_NDQ);
5711 }
5712 break;
5713
5714 case OP_RND_RNSC:
5715 {
5716 po_scalar_or_goto (8, try_vfd);
5717 break;
5718 try_vfd:
5719 po_reg_or_fail (REG_TYPE_VFD);
5720 }
5721 break;
5722
5723 case OP_VMOV:
5724 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5725 not careful then bad things might happen. */
5726 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5727 break;
5728
5729 case OP_RNDQ_IMVNb:
5730 {
5731 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5732 break;
5733 try_mvnimm:
5734 /* There's a possibility of getting a 64-bit immediate here, so
5735 we need special handling. */
5736 if (parse_big_immediate (&str, i) == FAIL)
5737 {
5738 inst.error = _("immediate value is out of range");
5739 goto failure;
5740 }
5741 }
5742 break;
5743
5744 case OP_RNDQ_I63b:
5745 {
5746 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5747 break;
5748 try_shimm:
5749 po_imm_or_fail (0, 63, TRUE);
5750 }
5751 break;
c19d1205
ZW
5752
5753 case OP_RRnpcb:
5754 po_char_or_fail ('[');
5755 po_reg_or_fail (REG_TYPE_RN);
5756 po_char_or_fail (']');
5757 break;
a737bd4d 5758
c19d1205 5759 case OP_RRw:
b6702015 5760 case OP_oRRw:
c19d1205
ZW
5761 po_reg_or_fail (REG_TYPE_RN);
5762 if (skip_past_char (&str, '!') == SUCCESS)
5763 inst.operands[i].writeback = 1;
5764 break;
5765
5766 /* Immediates */
5767 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5768 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5769 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5770 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5771 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5772 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5773 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5774 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5775 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5776 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5777 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5778 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5779
5780 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5781 case OP_oI7b:
5782 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5783 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5784 case OP_oI31b:
5785 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5786 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5787 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5788
5789 /* Immediate variants */
5790 case OP_oI255c:
5791 po_char_or_fail ('{');
5792 po_imm_or_fail (0, 255, TRUE);
5793 po_char_or_fail ('}');
5794 break;
5795
5796 case OP_I31w:
5797 /* The expression parser chokes on a trailing !, so we have
5798 to find it first and zap it. */
5799 {
5800 char *s = str;
5801 while (*s && *s != ',')
5802 s++;
5803 if (s[-1] == '!')
5804 {
5805 s[-1] = '\0';
5806 inst.operands[i].writeback = 1;
5807 }
5808 po_imm_or_fail (0, 31, TRUE);
5809 if (str == s - 1)
5810 str = s;
5811 }
5812 break;
5813
5814 /* Expressions */
5815 case OP_EXPi: EXPi:
5816 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5817 GE_OPT_PREFIX));
5818 break;
5819
5820 case OP_EXP:
5821 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5822 GE_NO_PREFIX));
5823 break;
5824
5825 case OP_EXPr: EXPr:
5826 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5827 GE_NO_PREFIX));
5828 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5829 {
c19d1205
ZW
5830 val = parse_reloc (&str);
5831 if (val == -1)
5832 {
5833 inst.error = _("unrecognized relocation suffix");
5834 goto failure;
5835 }
5836 else if (val != BFD_RELOC_UNUSED)
5837 {
5838 inst.operands[i].imm = val;
5839 inst.operands[i].hasreloc = 1;
5840 }
a737bd4d 5841 }
c19d1205 5842 break;
a737bd4d 5843
b6895b4f
PB
5844 /* Operand for MOVW or MOVT. */
5845 case OP_HALF:
5846 po_misc_or_fail (parse_half (&str));
5847 break;
5848
c19d1205
ZW
5849 /* Register or expression */
5850 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5851 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5852
c19d1205
ZW
5853 /* Register or immediate */
5854 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5855 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5856
c19d1205
ZW
5857 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5858 IF:
5859 if (!is_immediate_prefix (*str))
5860 goto bad_args;
5861 str++;
5862 val = parse_fpa_immediate (&str);
5863 if (val == FAIL)
5864 goto failure;
5865 /* FPA immediates are encoded as registers 8-15.
5866 parse_fpa_immediate has already applied the offset. */
5867 inst.operands[i].reg = val;
5868 inst.operands[i].isreg = 1;
5869 break;
09d92015 5870
2d447fca
JM
5871 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
5872 I32z: po_imm_or_fail (0, 32, FALSE); break;
5873
c19d1205
ZW
5874 /* Two kinds of register */
5875 case OP_RIWR_RIWC:
5876 {
5877 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5878 if (!rege
5879 || (rege->type != REG_TYPE_MMXWR
5880 && rege->type != REG_TYPE_MMXWC
5881 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5882 {
5883 inst.error = _("iWMMXt data or control register expected");
5884 goto failure;
5885 }
5886 inst.operands[i].reg = rege->number;
5887 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5888 }
5889 break;
09d92015 5890
41adaa5c
JM
5891 case OP_RIWC_RIWG:
5892 {
5893 struct reg_entry *rege = arm_reg_parse_multi (&str);
5894 if (!rege
5895 || (rege->type != REG_TYPE_MMXWC
5896 && rege->type != REG_TYPE_MMXWCG))
5897 {
5898 inst.error = _("iWMMXt control register expected");
5899 goto failure;
5900 }
5901 inst.operands[i].reg = rege->number;
5902 inst.operands[i].isreg = 1;
5903 }
5904 break;
5905
c19d1205
ZW
5906 /* Misc */
5907 case OP_CPSF: val = parse_cps_flags (&str); break;
5908 case OP_ENDI: val = parse_endian_specifier (&str); break;
5909 case OP_oROR: val = parse_ror (&str); break;
5910 case OP_PSR: val = parse_psr (&str); break;
5911 case OP_COND: val = parse_cond (&str); break;
62b3e311 5912 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5913
037e8744
JB
5914 case OP_RVC_PSR:
5915 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5916 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5917 break;
5918 try_psr:
5919 val = parse_psr (&str);
5920 break;
5921
5922 case OP_APSR_RR:
5923 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5924 break;
5925 try_apsr:
5926 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5927 instruction). */
5928 if (strncasecmp (str, "APSR_", 5) == 0)
5929 {
5930 unsigned found = 0;
5931 str += 5;
5932 while (found < 15)
5933 switch (*str++)
5934 {
5935 case 'c': found = (found & 1) ? 16 : found | 1; break;
5936 case 'n': found = (found & 2) ? 16 : found | 2; break;
5937 case 'z': found = (found & 4) ? 16 : found | 4; break;
5938 case 'v': found = (found & 8) ? 16 : found | 8; break;
5939 default: found = 16;
5940 }
5941 if (found != 15)
5942 goto failure;
5943 inst.operands[i].isvec = 1;
5944 }
5945 else
5946 goto failure;
5947 break;
5948
92e90b6e
PB
5949 case OP_TB:
5950 po_misc_or_fail (parse_tb (&str));
5951 break;
5952
c19d1205
ZW
5953 /* Register lists */
5954 case OP_REGLST:
5955 val = parse_reg_list (&str);
5956 if (*str == '^')
5957 {
5958 inst.operands[1].writeback = 1;
5959 str++;
5960 }
5961 break;
09d92015 5962
c19d1205 5963 case OP_VRSLST:
5287ad62 5964 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5965 break;
09d92015 5966
c19d1205 5967 case OP_VRDLST:
5287ad62 5968 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5969 break;
a737bd4d 5970
037e8744
JB
5971 case OP_VRSDLST:
5972 /* Allow Q registers too. */
5973 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5974 REGLIST_NEON_D);
5975 if (val == FAIL)
5976 {
5977 inst.error = NULL;
5978 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5979 REGLIST_VFP_S);
5980 inst.operands[i].issingle = 1;
5981 }
5982 break;
5983
5287ad62
JB
5984 case OP_NRDLST:
5985 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5986 REGLIST_NEON_D);
5987 break;
5988
5989 case OP_NSTRLST:
dcbf9037
JB
5990 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5991 &inst.operands[i].vectype);
5287ad62
JB
5992 break;
5993
c19d1205
ZW
5994 /* Addressing modes */
5995 case OP_ADDR:
5996 po_misc_or_fail (parse_address (&str, i));
5997 break;
09d92015 5998
4962c51a
MS
5999 case OP_ADDRGLDR:
6000 po_misc_or_fail_no_backtrack (
6001 parse_address_group_reloc (&str, i, GROUP_LDR));
6002 break;
6003
6004 case OP_ADDRGLDRS:
6005 po_misc_or_fail_no_backtrack (
6006 parse_address_group_reloc (&str, i, GROUP_LDRS));
6007 break;
6008
6009 case OP_ADDRGLDC:
6010 po_misc_or_fail_no_backtrack (
6011 parse_address_group_reloc (&str, i, GROUP_LDC));
6012 break;
6013
c19d1205
ZW
6014 case OP_SH:
6015 po_misc_or_fail (parse_shifter_operand (&str, i));
6016 break;
09d92015 6017
4962c51a
MS
6018 case OP_SHG:
6019 po_misc_or_fail_no_backtrack (
6020 parse_shifter_operand_group_reloc (&str, i));
6021 break;
6022
c19d1205
ZW
6023 case OP_oSHll:
6024 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6025 break;
09d92015 6026
c19d1205
ZW
6027 case OP_oSHar:
6028 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6029 break;
09d92015 6030
c19d1205
ZW
6031 case OP_oSHllar:
6032 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6033 break;
09d92015 6034
c19d1205
ZW
6035 default:
6036 as_fatal ("unhandled operand code %d", upat[i]);
6037 }
09d92015 6038
c19d1205
ZW
6039 /* Various value-based sanity checks and shared operations. We
6040 do not signal immediate failures for the register constraints;
6041 this allows a syntax error to take precedence. */
6042 switch (upat[i])
6043 {
6044 case OP_oRRnpc:
6045 case OP_RRnpc:
6046 case OP_RRnpcb:
6047 case OP_RRw:
b6702015 6048 case OP_oRRw:
c19d1205
ZW
6049 case OP_RRnpc_I0:
6050 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6051 inst.error = BAD_PC;
6052 break;
09d92015 6053
c19d1205
ZW
6054 case OP_CPSF:
6055 case OP_ENDI:
6056 case OP_oROR:
6057 case OP_PSR:
037e8744 6058 case OP_RVC_PSR:
c19d1205 6059 case OP_COND:
62b3e311 6060 case OP_oBARRIER:
c19d1205
ZW
6061 case OP_REGLST:
6062 case OP_VRSLST:
6063 case OP_VRDLST:
037e8744 6064 case OP_VRSDLST:
5287ad62
JB
6065 case OP_NRDLST:
6066 case OP_NSTRLST:
c19d1205
ZW
6067 if (val == FAIL)
6068 goto failure;
6069 inst.operands[i].imm = val;
6070 break;
a737bd4d 6071
c19d1205
ZW
6072 default:
6073 break;
6074 }
09d92015 6075
c19d1205
ZW
6076 /* If we get here, this operand was successfully parsed. */
6077 inst.operands[i].present = 1;
6078 continue;
09d92015 6079
c19d1205 6080 bad_args:
09d92015 6081 inst.error = BAD_ARGS;
c19d1205
ZW
6082
6083 failure:
6084 if (!backtrack_pos)
d252fdde
PB
6085 {
6086 /* The parse routine should already have set inst.error, but set a
6087 defaut here just in case. */
6088 if (!inst.error)
6089 inst.error = _("syntax error");
6090 return FAIL;
6091 }
c19d1205
ZW
6092
6093 /* Do not backtrack over a trailing optional argument that
6094 absorbed some text. We will only fail again, with the
6095 'garbage following instruction' error message, which is
6096 probably less helpful than the current one. */
6097 if (backtrack_index == i && backtrack_pos != str
6098 && upat[i+1] == OP_stop)
d252fdde
PB
6099 {
6100 if (!inst.error)
6101 inst.error = _("syntax error");
6102 return FAIL;
6103 }
c19d1205
ZW
6104
6105 /* Try again, skipping the optional argument at backtrack_pos. */
6106 str = backtrack_pos;
6107 inst.error = backtrack_error;
6108 inst.operands[backtrack_index].present = 0;
6109 i = backtrack_index;
6110 backtrack_pos = 0;
09d92015 6111 }
09d92015 6112
c19d1205
ZW
6113 /* Check that we have parsed all the arguments. */
6114 if (*str != '\0' && !inst.error)
6115 inst.error = _("garbage following instruction");
09d92015 6116
c19d1205 6117 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6118}
6119
c19d1205
ZW
6120#undef po_char_or_fail
6121#undef po_reg_or_fail
6122#undef po_reg_or_goto
6123#undef po_imm_or_fail
5287ad62 6124#undef po_scalar_or_fail
c19d1205
ZW
6125\f
6126/* Shorthand macro for instruction encoding functions issuing errors. */
6127#define constraint(expr, err) do { \
6128 if (expr) \
6129 { \
6130 inst.error = err; \
6131 return; \
6132 } \
6133} while (0)
6134
6135/* Functions for operand encoding. ARM, then Thumb. */
6136
6137#define rotate_left(v, n) (v << n | v >> (32 - n))
6138
6139/* If VAL can be encoded in the immediate field of an ARM instruction,
6140 return the encoded form. Otherwise, return FAIL. */
6141
6142static unsigned int
6143encode_arm_immediate (unsigned int val)
09d92015 6144{
c19d1205
ZW
6145 unsigned int a, i;
6146
6147 for (i = 0; i < 32; i += 2)
6148 if ((a = rotate_left (val, i)) <= 0xff)
6149 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6150
6151 return FAIL;
09d92015
MM
6152}
6153
c19d1205
ZW
6154/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6155 return the encoded form. Otherwise, return FAIL. */
6156static unsigned int
6157encode_thumb32_immediate (unsigned int val)
09d92015 6158{
c19d1205 6159 unsigned int a, i;
09d92015 6160
9c3c69f2 6161 if (val <= 0xff)
c19d1205 6162 return val;
a737bd4d 6163
9c3c69f2 6164 for (i = 1; i <= 24; i++)
09d92015 6165 {
9c3c69f2
PB
6166 a = val >> i;
6167 if ((val & ~(0xff << i)) == 0)
6168 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6169 }
a737bd4d 6170
c19d1205
ZW
6171 a = val & 0xff;
6172 if (val == ((a << 16) | a))
6173 return 0x100 | a;
6174 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6175 return 0x300 | a;
09d92015 6176
c19d1205
ZW
6177 a = val & 0xff00;
6178 if (val == ((a << 16) | a))
6179 return 0x200 | (a >> 8);
a737bd4d 6180
c19d1205 6181 return FAIL;
09d92015 6182}
5287ad62 6183/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6184
6185static void
5287ad62
JB
6186encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6187{
6188 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6189 && reg > 15)
6190 {
6191 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6192 {
6193 if (thumb_mode)
6194 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6195 fpu_vfp_ext_v3);
6196 else
6197 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6198 fpu_vfp_ext_v3);
6199 }
6200 else
6201 {
dcbf9037 6202 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6203 return;
6204 }
6205 }
6206
c19d1205 6207 switch (pos)
09d92015 6208 {
c19d1205
ZW
6209 case VFP_REG_Sd:
6210 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6211 break;
6212
6213 case VFP_REG_Sn:
6214 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6215 break;
6216
6217 case VFP_REG_Sm:
6218 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6219 break;
6220
5287ad62
JB
6221 case VFP_REG_Dd:
6222 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6223 break;
6224
6225 case VFP_REG_Dn:
6226 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6227 break;
6228
6229 case VFP_REG_Dm:
6230 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6231 break;
6232
c19d1205
ZW
6233 default:
6234 abort ();
09d92015 6235 }
09d92015
MM
6236}
6237
c19d1205 6238/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6239 if any, is handled by md_apply_fix. */
09d92015 6240static void
c19d1205 6241encode_arm_shift (int i)
09d92015 6242{
c19d1205
ZW
6243 if (inst.operands[i].shift_kind == SHIFT_RRX)
6244 inst.instruction |= SHIFT_ROR << 5;
6245 else
09d92015 6246 {
c19d1205
ZW
6247 inst.instruction |= inst.operands[i].shift_kind << 5;
6248 if (inst.operands[i].immisreg)
6249 {
6250 inst.instruction |= SHIFT_BY_REG;
6251 inst.instruction |= inst.operands[i].imm << 8;
6252 }
6253 else
6254 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6255 }
c19d1205 6256}
09d92015 6257
c19d1205
ZW
6258static void
6259encode_arm_shifter_operand (int i)
6260{
6261 if (inst.operands[i].isreg)
09d92015 6262 {
c19d1205
ZW
6263 inst.instruction |= inst.operands[i].reg;
6264 encode_arm_shift (i);
09d92015 6265 }
c19d1205
ZW
6266 else
6267 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6268}
6269
c19d1205 6270/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6271static void
c19d1205 6272encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6273{
c19d1205
ZW
6274 assert (inst.operands[i].isreg);
6275 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6276
c19d1205 6277 if (inst.operands[i].preind)
09d92015 6278 {
c19d1205
ZW
6279 if (is_t)
6280 {
6281 inst.error = _("instruction does not accept preindexed addressing");
6282 return;
6283 }
6284 inst.instruction |= PRE_INDEX;
6285 if (inst.operands[i].writeback)
6286 inst.instruction |= WRITE_BACK;
09d92015 6287
c19d1205
ZW
6288 }
6289 else if (inst.operands[i].postind)
6290 {
6291 assert (inst.operands[i].writeback);
6292 if (is_t)
6293 inst.instruction |= WRITE_BACK;
6294 }
6295 else /* unindexed - only for coprocessor */
09d92015 6296 {
c19d1205 6297 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6298 return;
6299 }
6300
c19d1205
ZW
6301 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6302 && (((inst.instruction & 0x000f0000) >> 16)
6303 == ((inst.instruction & 0x0000f000) >> 12)))
6304 as_warn ((inst.instruction & LOAD_BIT)
6305 ? _("destination register same as write-back base")
6306 : _("source register same as write-back base"));
09d92015
MM
6307}
6308
c19d1205
ZW
6309/* inst.operands[i] was set up by parse_address. Encode it into an
6310 ARM-format mode 2 load or store instruction. If is_t is true,
6311 reject forms that cannot be used with a T instruction (i.e. not
6312 post-indexed). */
a737bd4d 6313static void
c19d1205 6314encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6315{
c19d1205 6316 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6317
c19d1205 6318 if (inst.operands[i].immisreg)
09d92015 6319 {
c19d1205
ZW
6320 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6321 inst.instruction |= inst.operands[i].imm;
6322 if (!inst.operands[i].negative)
6323 inst.instruction |= INDEX_UP;
6324 if (inst.operands[i].shifted)
6325 {
6326 if (inst.operands[i].shift_kind == SHIFT_RRX)
6327 inst.instruction |= SHIFT_ROR << 5;
6328 else
6329 {
6330 inst.instruction |= inst.operands[i].shift_kind << 5;
6331 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6332 }
6333 }
09d92015 6334 }
c19d1205 6335 else /* immediate offset in inst.reloc */
09d92015 6336 {
c19d1205
ZW
6337 if (inst.reloc.type == BFD_RELOC_UNUSED)
6338 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6339 }
09d92015
MM
6340}
6341
c19d1205
ZW
6342/* inst.operands[i] was set up by parse_address. Encode it into an
6343 ARM-format mode 3 load or store instruction. Reject forms that
6344 cannot be used with such instructions. If is_t is true, reject
6345 forms that cannot be used with a T instruction (i.e. not
6346 post-indexed). */
6347static void
6348encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6349{
c19d1205 6350 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6351 {
c19d1205
ZW
6352 inst.error = _("instruction does not accept scaled register index");
6353 return;
09d92015 6354 }
a737bd4d 6355
c19d1205 6356 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6357
c19d1205
ZW
6358 if (inst.operands[i].immisreg)
6359 {
6360 inst.instruction |= inst.operands[i].imm;
6361 if (!inst.operands[i].negative)
6362 inst.instruction |= INDEX_UP;
6363 }
6364 else /* immediate offset in inst.reloc */
6365 {
6366 inst.instruction |= HWOFFSET_IMM;
6367 if (inst.reloc.type == BFD_RELOC_UNUSED)
6368 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6369 }
a737bd4d
NC
6370}
6371
c19d1205
ZW
6372/* inst.operands[i] was set up by parse_address. Encode it into an
6373 ARM-format instruction. Reject all forms which cannot be encoded
6374 into a coprocessor load/store instruction. If wb_ok is false,
6375 reject use of writeback; if unind_ok is false, reject use of
6376 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6377 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6378 (in which case it is preserved). */
09d92015 6379
c19d1205
ZW
6380static int
6381encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6382{
c19d1205 6383 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6384
c19d1205 6385 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6386
c19d1205 6387 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6388 {
c19d1205
ZW
6389 assert (!inst.operands[i].writeback);
6390 if (!unind_ok)
6391 {
6392 inst.error = _("instruction does not support unindexed addressing");
6393 return FAIL;
6394 }
6395 inst.instruction |= inst.operands[i].imm;
6396 inst.instruction |= INDEX_UP;
6397 return SUCCESS;
09d92015 6398 }
a737bd4d 6399
c19d1205
ZW
6400 if (inst.operands[i].preind)
6401 inst.instruction |= PRE_INDEX;
a737bd4d 6402
c19d1205 6403 if (inst.operands[i].writeback)
09d92015 6404 {
c19d1205
ZW
6405 if (inst.operands[i].reg == REG_PC)
6406 {
6407 inst.error = _("pc may not be used with write-back");
6408 return FAIL;
6409 }
6410 if (!wb_ok)
6411 {
6412 inst.error = _("instruction does not support writeback");
6413 return FAIL;
6414 }
6415 inst.instruction |= WRITE_BACK;
09d92015 6416 }
a737bd4d 6417
c19d1205
ZW
6418 if (reloc_override)
6419 inst.reloc.type = reloc_override;
4962c51a
MS
6420 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6421 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6422 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6423 {
6424 if (thumb_mode)
6425 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6426 else
6427 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6428 }
6429
c19d1205
ZW
6430 return SUCCESS;
6431}
a737bd4d 6432
c19d1205
ZW
6433/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6434 Determine whether it can be performed with a move instruction; if
6435 it can, convert inst.instruction to that move instruction and
6436 return 1; if it can't, convert inst.instruction to a literal-pool
6437 load and return 0. If this is not a valid thing to do in the
6438 current context, set inst.error and return 1.
a737bd4d 6439
c19d1205
ZW
6440 inst.operands[i] describes the destination register. */
6441
6442static int
6443move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6444{
53365c0d
PB
6445 unsigned long tbit;
6446
6447 if (thumb_p)
6448 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6449 else
6450 tbit = LOAD_BIT;
6451
6452 if ((inst.instruction & tbit) == 0)
09d92015 6453 {
c19d1205
ZW
6454 inst.error = _("invalid pseudo operation");
6455 return 1;
09d92015 6456 }
c19d1205 6457 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6458 {
6459 inst.error = _("constant expression expected");
c19d1205 6460 return 1;
09d92015 6461 }
c19d1205 6462 if (inst.reloc.exp.X_op == O_constant)
09d92015 6463 {
c19d1205
ZW
6464 if (thumb_p)
6465 {
53365c0d 6466 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6467 {
6468 /* This can be done with a mov(1) instruction. */
6469 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6470 inst.instruction |= inst.reloc.exp.X_add_number;
6471 return 1;
6472 }
6473 }
6474 else
6475 {
6476 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6477 if (value != FAIL)
6478 {
6479 /* This can be done with a mov instruction. */
6480 inst.instruction &= LITERAL_MASK;
6481 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6482 inst.instruction |= value & 0xfff;
6483 return 1;
6484 }
09d92015 6485
c19d1205
ZW
6486 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6487 if (value != FAIL)
6488 {
6489 /* This can be done with a mvn instruction. */
6490 inst.instruction &= LITERAL_MASK;
6491 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6492 inst.instruction |= value & 0xfff;
6493 return 1;
6494 }
6495 }
09d92015
MM
6496 }
6497
c19d1205
ZW
6498 if (add_to_lit_pool () == FAIL)
6499 {
6500 inst.error = _("literal pool insertion failed");
6501 return 1;
6502 }
6503 inst.operands[1].reg = REG_PC;
6504 inst.operands[1].isreg = 1;
6505 inst.operands[1].preind = 1;
6506 inst.reloc.pc_rel = 1;
6507 inst.reloc.type = (thumb_p
6508 ? BFD_RELOC_ARM_THUMB_OFFSET
6509 : (mode_3
6510 ? BFD_RELOC_ARM_HWLITERAL
6511 : BFD_RELOC_ARM_LITERAL));
6512 return 0;
09d92015
MM
6513}
6514
c19d1205
ZW
6515/* Functions for instruction encoding, sorted by subarchitecture.
6516 First some generics; their names are taken from the conventional
6517 bit positions for register arguments in ARM format instructions. */
09d92015 6518
a737bd4d 6519static void
c19d1205 6520do_noargs (void)
09d92015 6521{
c19d1205 6522}
a737bd4d 6523
c19d1205
ZW
6524static void
6525do_rd (void)
6526{
6527 inst.instruction |= inst.operands[0].reg << 12;
6528}
a737bd4d 6529
c19d1205
ZW
6530static void
6531do_rd_rm (void)
6532{
6533 inst.instruction |= inst.operands[0].reg << 12;
6534 inst.instruction |= inst.operands[1].reg;
6535}
09d92015 6536
c19d1205
ZW
6537static void
6538do_rd_rn (void)
6539{
6540 inst.instruction |= inst.operands[0].reg << 12;
6541 inst.instruction |= inst.operands[1].reg << 16;
6542}
a737bd4d 6543
c19d1205
ZW
6544static void
6545do_rn_rd (void)
6546{
6547 inst.instruction |= inst.operands[0].reg << 16;
6548 inst.instruction |= inst.operands[1].reg << 12;
6549}
09d92015 6550
c19d1205
ZW
6551static void
6552do_rd_rm_rn (void)
6553{
9a64e435 6554 unsigned Rn = inst.operands[2].reg;
708587a4 6555 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6556 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6557 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6558 _("Rn must not overlap other operands"));
c19d1205
ZW
6559 inst.instruction |= inst.operands[0].reg << 12;
6560 inst.instruction |= inst.operands[1].reg;
9a64e435 6561 inst.instruction |= Rn << 16;
c19d1205 6562}
09d92015 6563
c19d1205
ZW
6564static void
6565do_rd_rn_rm (void)
6566{
6567 inst.instruction |= inst.operands[0].reg << 12;
6568 inst.instruction |= inst.operands[1].reg << 16;
6569 inst.instruction |= inst.operands[2].reg;
6570}
a737bd4d 6571
c19d1205
ZW
6572static void
6573do_rm_rd_rn (void)
6574{
6575 inst.instruction |= inst.operands[0].reg;
6576 inst.instruction |= inst.operands[1].reg << 12;
6577 inst.instruction |= inst.operands[2].reg << 16;
6578}
09d92015 6579
c19d1205
ZW
6580static void
6581do_imm0 (void)
6582{
6583 inst.instruction |= inst.operands[0].imm;
6584}
09d92015 6585
c19d1205
ZW
6586static void
6587do_rd_cpaddr (void)
6588{
6589 inst.instruction |= inst.operands[0].reg << 12;
6590 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6591}
a737bd4d 6592
c19d1205
ZW
6593/* ARM instructions, in alphabetical order by function name (except
6594 that wrapper functions appear immediately after the function they
6595 wrap). */
09d92015 6596
c19d1205
ZW
6597/* This is a pseudo-op of the form "adr rd, label" to be converted
6598 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6599
6600static void
c19d1205 6601do_adr (void)
09d92015 6602{
c19d1205 6603 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6604
c19d1205
ZW
6605 /* Frag hacking will turn this into a sub instruction if the offset turns
6606 out to be negative. */
6607 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6608 inst.reloc.pc_rel = 1;
2fc8bdac 6609 inst.reloc.exp.X_add_number -= 8;
c19d1205 6610}
b99bd4ef 6611
c19d1205
ZW
6612/* This is a pseudo-op of the form "adrl rd, label" to be converted
6613 into a relative address of the form:
6614 add rd, pc, #low(label-.-8)"
6615 add rd, rd, #high(label-.-8)" */
b99bd4ef 6616
c19d1205
ZW
6617static void
6618do_adrl (void)
6619{
6620 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6621
c19d1205
ZW
6622 /* Frag hacking will turn this into a sub instruction if the offset turns
6623 out to be negative. */
6624 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6625 inst.reloc.pc_rel = 1;
6626 inst.size = INSN_SIZE * 2;
2fc8bdac 6627 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6628}
6629
b99bd4ef 6630static void
c19d1205 6631do_arit (void)
b99bd4ef 6632{
c19d1205
ZW
6633 if (!inst.operands[1].present)
6634 inst.operands[1].reg = inst.operands[0].reg;
6635 inst.instruction |= inst.operands[0].reg << 12;
6636 inst.instruction |= inst.operands[1].reg << 16;
6637 encode_arm_shifter_operand (2);
6638}
b99bd4ef 6639
62b3e311
PB
6640static void
6641do_barrier (void)
6642{
6643 if (inst.operands[0].present)
6644 {
6645 constraint ((inst.instruction & 0xf0) != 0x40
6646 && inst.operands[0].imm != 0xf,
6647 "bad barrier type");
6648 inst.instruction |= inst.operands[0].imm;
6649 }
6650 else
6651 inst.instruction |= 0xf;
6652}
6653
c19d1205
ZW
6654static void
6655do_bfc (void)
6656{
6657 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6658 constraint (msb > 32, _("bit-field extends past end of register"));
6659 /* The instruction encoding stores the LSB and MSB,
6660 not the LSB and width. */
6661 inst.instruction |= inst.operands[0].reg << 12;
6662 inst.instruction |= inst.operands[1].imm << 7;
6663 inst.instruction |= (msb - 1) << 16;
6664}
b99bd4ef 6665
c19d1205
ZW
6666static void
6667do_bfi (void)
6668{
6669 unsigned int msb;
b99bd4ef 6670
c19d1205
ZW
6671 /* #0 in second position is alternative syntax for bfc, which is
6672 the same instruction but with REG_PC in the Rm field. */
6673 if (!inst.operands[1].isreg)
6674 inst.operands[1].reg = REG_PC;
b99bd4ef 6675
c19d1205
ZW
6676 msb = inst.operands[2].imm + inst.operands[3].imm;
6677 constraint (msb > 32, _("bit-field extends past end of register"));
6678 /* The instruction encoding stores the LSB and MSB,
6679 not the LSB and width. */
6680 inst.instruction |= inst.operands[0].reg << 12;
6681 inst.instruction |= inst.operands[1].reg;
6682 inst.instruction |= inst.operands[2].imm << 7;
6683 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6684}
6685
b99bd4ef 6686static void
c19d1205 6687do_bfx (void)
b99bd4ef 6688{
c19d1205
ZW
6689 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6690 _("bit-field extends past end of register"));
6691 inst.instruction |= inst.operands[0].reg << 12;
6692 inst.instruction |= inst.operands[1].reg;
6693 inst.instruction |= inst.operands[2].imm << 7;
6694 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6695}
09d92015 6696
c19d1205
ZW
6697/* ARM V5 breakpoint instruction (argument parse)
6698 BKPT <16 bit unsigned immediate>
6699 Instruction is not conditional.
6700 The bit pattern given in insns[] has the COND_ALWAYS condition,
6701 and it is an error if the caller tried to override that. */
b99bd4ef 6702
c19d1205
ZW
6703static void
6704do_bkpt (void)
6705{
6706 /* Top 12 of 16 bits to bits 19:8. */
6707 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6708
c19d1205
ZW
6709 /* Bottom 4 of 16 bits to bits 3:0. */
6710 inst.instruction |= inst.operands[0].imm & 0xf;
6711}
09d92015 6712
c19d1205
ZW
6713static void
6714encode_branch (int default_reloc)
6715{
6716 if (inst.operands[0].hasreloc)
6717 {
6718 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6719 _("the only suffix valid here is '(plt)'"));
6720 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6721 }
b99bd4ef 6722 else
c19d1205
ZW
6723 {
6724 inst.reloc.type = default_reloc;
c19d1205 6725 }
2fc8bdac 6726 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6727}
6728
b99bd4ef 6729static void
c19d1205 6730do_branch (void)
b99bd4ef 6731{
39b41c9c
PB
6732#ifdef OBJ_ELF
6733 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6734 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6735 else
6736#endif
6737 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6738}
6739
6740static void
6741do_bl (void)
6742{
6743#ifdef OBJ_ELF
6744 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6745 {
6746 if (inst.cond == COND_ALWAYS)
6747 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6748 else
6749 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6750 }
6751 else
6752#endif
6753 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6754}
b99bd4ef 6755
c19d1205
ZW
6756/* ARM V5 branch-link-exchange instruction (argument parse)
6757 BLX <target_addr> ie BLX(1)
6758 BLX{<condition>} <Rm> ie BLX(2)
6759 Unfortunately, there are two different opcodes for this mnemonic.
6760 So, the insns[].value is not used, and the code here zaps values
6761 into inst.instruction.
6762 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6763
c19d1205
ZW
6764static void
6765do_blx (void)
6766{
6767 if (inst.operands[0].isreg)
b99bd4ef 6768 {
c19d1205
ZW
6769 /* Arg is a register; the opcode provided by insns[] is correct.
6770 It is not illegal to do "blx pc", just useless. */
6771 if (inst.operands[0].reg == REG_PC)
6772 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6773
c19d1205
ZW
6774 inst.instruction |= inst.operands[0].reg;
6775 }
6776 else
b99bd4ef 6777 {
c19d1205
ZW
6778 /* Arg is an address; this instruction cannot be executed
6779 conditionally, and the opcode must be adjusted. */
6780 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6781 inst.instruction = 0xfa000000;
39b41c9c
PB
6782#ifdef OBJ_ELF
6783 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6784 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6785 else
6786#endif
6787 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6788 }
c19d1205
ZW
6789}
6790
6791static void
6792do_bx (void)
6793{
6794 if (inst.operands[0].reg == REG_PC)
6795 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6796
c19d1205 6797 inst.instruction |= inst.operands[0].reg;
09d92015
MM
6798}
6799
c19d1205
ZW
6800
6801/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6802
6803static void
c19d1205 6804do_bxj (void)
a737bd4d 6805{
c19d1205
ZW
6806 if (inst.operands[0].reg == REG_PC)
6807 as_tsktsk (_("use of r15 in bxj is not really useful"));
6808
6809 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6810}
6811
c19d1205
ZW
6812/* Co-processor data operation:
6813 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6814 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6815static void
6816do_cdp (void)
6817{
6818 inst.instruction |= inst.operands[0].reg << 8;
6819 inst.instruction |= inst.operands[1].imm << 20;
6820 inst.instruction |= inst.operands[2].reg << 12;
6821 inst.instruction |= inst.operands[3].reg << 16;
6822 inst.instruction |= inst.operands[4].reg;
6823 inst.instruction |= inst.operands[5].imm << 5;
6824}
a737bd4d
NC
6825
6826static void
c19d1205 6827do_cmp (void)
a737bd4d 6828{
c19d1205
ZW
6829 inst.instruction |= inst.operands[0].reg << 16;
6830 encode_arm_shifter_operand (1);
a737bd4d
NC
6831}
6832
c19d1205
ZW
6833/* Transfer between coprocessor and ARM registers.
6834 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6835 MRC2
6836 MCR{cond}
6837 MCR2
6838
6839 No special properties. */
09d92015
MM
6840
6841static void
c19d1205 6842do_co_reg (void)
09d92015 6843{
c19d1205
ZW
6844 inst.instruction |= inst.operands[0].reg << 8;
6845 inst.instruction |= inst.operands[1].imm << 21;
6846 inst.instruction |= inst.operands[2].reg << 12;
6847 inst.instruction |= inst.operands[3].reg << 16;
6848 inst.instruction |= inst.operands[4].reg;
6849 inst.instruction |= inst.operands[5].imm << 5;
6850}
09d92015 6851
c19d1205
ZW
6852/* Transfer between coprocessor register and pair of ARM registers.
6853 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6854 MCRR2
6855 MRRC{cond}
6856 MRRC2
b99bd4ef 6857
c19d1205 6858 Two XScale instructions are special cases of these:
09d92015 6859
c19d1205
ZW
6860 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6861 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6862
c19d1205 6863 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 6864
c19d1205
ZW
6865static void
6866do_co_reg2c (void)
6867{
6868 inst.instruction |= inst.operands[0].reg << 8;
6869 inst.instruction |= inst.operands[1].imm << 4;
6870 inst.instruction |= inst.operands[2].reg << 12;
6871 inst.instruction |= inst.operands[3].reg << 16;
6872 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6873}
6874
c19d1205
ZW
6875static void
6876do_cpsi (void)
6877{
6878 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
6879 if (inst.operands[1].present)
6880 {
6881 inst.instruction |= CPSI_MMOD;
6882 inst.instruction |= inst.operands[1].imm;
6883 }
c19d1205 6884}
b99bd4ef 6885
62b3e311
PB
6886static void
6887do_dbg (void)
6888{
6889 inst.instruction |= inst.operands[0].imm;
6890}
6891
b99bd4ef 6892static void
c19d1205 6893do_it (void)
b99bd4ef 6894{
c19d1205
ZW
6895 /* There is no IT instruction in ARM mode. We
6896 process it but do not generate code for it. */
6897 inst.size = 0;
09d92015 6898}
b99bd4ef 6899
09d92015 6900static void
c19d1205 6901do_ldmstm (void)
ea6ef066 6902{
c19d1205
ZW
6903 int base_reg = inst.operands[0].reg;
6904 int range = inst.operands[1].imm;
ea6ef066 6905
c19d1205
ZW
6906 inst.instruction |= base_reg << 16;
6907 inst.instruction |= range;
ea6ef066 6908
c19d1205
ZW
6909 if (inst.operands[1].writeback)
6910 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6911
c19d1205 6912 if (inst.operands[0].writeback)
ea6ef066 6913 {
c19d1205
ZW
6914 inst.instruction |= WRITE_BACK;
6915 /* Check for unpredictable uses of writeback. */
6916 if (inst.instruction & LOAD_BIT)
09d92015 6917 {
c19d1205
ZW
6918 /* Not allowed in LDM type 2. */
6919 if ((inst.instruction & LDM_TYPE_2_OR_3)
6920 && ((range & (1 << REG_PC)) == 0))
6921 as_warn (_("writeback of base register is UNPREDICTABLE"));
6922 /* Only allowed if base reg not in list for other types. */
6923 else if (range & (1 << base_reg))
6924 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6925 }
6926 else /* STM. */
6927 {
6928 /* Not allowed for type 2. */
6929 if (inst.instruction & LDM_TYPE_2_OR_3)
6930 as_warn (_("writeback of base register is UNPREDICTABLE"));
6931 /* Only allowed if base reg not in list, or first in list. */
6932 else if ((range & (1 << base_reg))
6933 && (range & ((1 << base_reg) - 1)))
6934 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6935 }
ea6ef066 6936 }
a737bd4d
NC
6937}
6938
c19d1205
ZW
6939/* ARMv5TE load-consecutive (argument parse)
6940 Mode is like LDRH.
6941
6942 LDRccD R, mode
6943 STRccD R, mode. */
6944
a737bd4d 6945static void
c19d1205 6946do_ldrd (void)
a737bd4d 6947{
c19d1205
ZW
6948 constraint (inst.operands[0].reg % 2 != 0,
6949 _("first destination register must be even"));
6950 constraint (inst.operands[1].present
6951 && inst.operands[1].reg != inst.operands[0].reg + 1,
6952 _("can only load two consecutive registers"));
6953 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6954 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6955
c19d1205
ZW
6956 if (!inst.operands[1].present)
6957 inst.operands[1].reg = inst.operands[0].reg + 1;
6958
6959 if (inst.instruction & LOAD_BIT)
a737bd4d 6960 {
c19d1205
ZW
6961 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6962 register and the first register written; we have to diagnose
6963 overlap between the base and the second register written here. */
ea6ef066 6964
c19d1205
ZW
6965 if (inst.operands[2].reg == inst.operands[1].reg
6966 && (inst.operands[2].writeback || inst.operands[2].postind))
6967 as_warn (_("base register written back, and overlaps "
6968 "second destination register"));
b05fe5cf 6969
c19d1205
ZW
6970 /* For an index-register load, the index register must not overlap the
6971 destination (even if not write-back). */
6972 else if (inst.operands[2].immisreg
ca3f61f7
NC
6973 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6974 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6975 as_warn (_("index register overlaps destination register"));
b05fe5cf 6976 }
c19d1205
ZW
6977
6978 inst.instruction |= inst.operands[0].reg << 12;
6979 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6980}
6981
6982static void
c19d1205 6983do_ldrex (void)
b05fe5cf 6984{
c19d1205
ZW
6985 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6986 || inst.operands[1].postind || inst.operands[1].writeback
6987 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6988 || inst.operands[1].negative
6989 /* This can arise if the programmer has written
6990 strex rN, rM, foo
6991 or if they have mistakenly used a register name as the last
6992 operand, eg:
6993 strex rN, rM, rX
6994 It is very difficult to distinguish between these two cases
6995 because "rX" might actually be a label. ie the register
6996 name has been occluded by a symbol of the same name. So we
6997 just generate a general 'bad addressing mode' type error
6998 message and leave it up to the programmer to discover the
6999 true cause and fix their mistake. */
7000 || (inst.operands[1].reg == REG_PC),
7001 BAD_ADDR_MODE);
b05fe5cf 7002
c19d1205
ZW
7003 constraint (inst.reloc.exp.X_op != O_constant
7004 || inst.reloc.exp.X_add_number != 0,
7005 _("offset must be zero in ARM encoding"));
b05fe5cf 7006
c19d1205
ZW
7007 inst.instruction |= inst.operands[0].reg << 12;
7008 inst.instruction |= inst.operands[1].reg << 16;
7009 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7010}
7011
7012static void
c19d1205 7013do_ldrexd (void)
b05fe5cf 7014{
c19d1205
ZW
7015 constraint (inst.operands[0].reg % 2 != 0,
7016 _("even register required"));
7017 constraint (inst.operands[1].present
7018 && inst.operands[1].reg != inst.operands[0].reg + 1,
7019 _("can only load two consecutive registers"));
7020 /* If op 1 were present and equal to PC, this function wouldn't
7021 have been called in the first place. */
7022 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7023
c19d1205
ZW
7024 inst.instruction |= inst.operands[0].reg << 12;
7025 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7026}
7027
7028static void
c19d1205 7029do_ldst (void)
b05fe5cf 7030{
c19d1205
ZW
7031 inst.instruction |= inst.operands[0].reg << 12;
7032 if (!inst.operands[1].isreg)
7033 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7034 return;
c19d1205 7035 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7036}
7037
7038static void
c19d1205 7039do_ldstt (void)
b05fe5cf 7040{
c19d1205
ZW
7041 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7042 reject [Rn,...]. */
7043 if (inst.operands[1].preind)
b05fe5cf 7044 {
c19d1205
ZW
7045 constraint (inst.reloc.exp.X_op != O_constant ||
7046 inst.reloc.exp.X_add_number != 0,
7047 _("this instruction requires a post-indexed address"));
b05fe5cf 7048
c19d1205
ZW
7049 inst.operands[1].preind = 0;
7050 inst.operands[1].postind = 1;
7051 inst.operands[1].writeback = 1;
b05fe5cf 7052 }
c19d1205
ZW
7053 inst.instruction |= inst.operands[0].reg << 12;
7054 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7055}
b05fe5cf 7056
c19d1205 7057/* Halfword and signed-byte load/store operations. */
b05fe5cf 7058
c19d1205
ZW
7059static void
7060do_ldstv4 (void)
7061{
7062 inst.instruction |= inst.operands[0].reg << 12;
7063 if (!inst.operands[1].isreg)
7064 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7065 return;
c19d1205 7066 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7067}
7068
7069static void
c19d1205 7070do_ldsttv4 (void)
b05fe5cf 7071{
c19d1205
ZW
7072 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7073 reject [Rn,...]. */
7074 if (inst.operands[1].preind)
b05fe5cf 7075 {
c19d1205
ZW
7076 constraint (inst.reloc.exp.X_op != O_constant ||
7077 inst.reloc.exp.X_add_number != 0,
7078 _("this instruction requires a post-indexed address"));
b05fe5cf 7079
c19d1205
ZW
7080 inst.operands[1].preind = 0;
7081 inst.operands[1].postind = 1;
7082 inst.operands[1].writeback = 1;
b05fe5cf 7083 }
c19d1205
ZW
7084 inst.instruction |= inst.operands[0].reg << 12;
7085 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7086}
b05fe5cf 7087
c19d1205
ZW
7088/* Co-processor register load/store.
7089 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7090static void
7091do_lstc (void)
7092{
7093 inst.instruction |= inst.operands[0].reg << 8;
7094 inst.instruction |= inst.operands[1].reg << 12;
7095 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7096}
7097
b05fe5cf 7098static void
c19d1205 7099do_mlas (void)
b05fe5cf 7100{
8fb9d7b9 7101 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7102 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7103 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7104 && !(inst.instruction & 0x00400000))
8fb9d7b9 7105 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7106
c19d1205
ZW
7107 inst.instruction |= inst.operands[0].reg << 16;
7108 inst.instruction |= inst.operands[1].reg;
7109 inst.instruction |= inst.operands[2].reg << 8;
7110 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7111}
b05fe5cf 7112
c19d1205
ZW
7113static void
7114do_mov (void)
7115{
7116 inst.instruction |= inst.operands[0].reg << 12;
7117 encode_arm_shifter_operand (1);
7118}
b05fe5cf 7119
c19d1205
ZW
7120/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7121static void
7122do_mov16 (void)
7123{
b6895b4f
PB
7124 bfd_vma imm;
7125 bfd_boolean top;
7126
7127 top = (inst.instruction & 0x00400000) != 0;
7128 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7129 _(":lower16: not allowed this instruction"));
7130 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7131 _(":upper16: not allowed instruction"));
c19d1205 7132 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7133 if (inst.reloc.type == BFD_RELOC_UNUSED)
7134 {
7135 imm = inst.reloc.exp.X_add_number;
7136 /* The value is in two pieces: 0:11, 16:19. */
7137 inst.instruction |= (imm & 0x00000fff);
7138 inst.instruction |= (imm & 0x0000f000) << 4;
7139 }
b05fe5cf 7140}
b99bd4ef 7141
037e8744
JB
7142static void do_vfp_nsyn_opcode (const char *);
7143
7144static int
7145do_vfp_nsyn_mrs (void)
7146{
7147 if (inst.operands[0].isvec)
7148 {
7149 if (inst.operands[1].reg != 1)
7150 first_error (_("operand 1 must be FPSCR"));
7151 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7152 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7153 do_vfp_nsyn_opcode ("fmstat");
7154 }
7155 else if (inst.operands[1].isvec)
7156 do_vfp_nsyn_opcode ("fmrx");
7157 else
7158 return FAIL;
7159
7160 return SUCCESS;
7161}
7162
7163static int
7164do_vfp_nsyn_msr (void)
7165{
7166 if (inst.operands[0].isvec)
7167 do_vfp_nsyn_opcode ("fmxr");
7168 else
7169 return FAIL;
7170
7171 return SUCCESS;
7172}
7173
b99bd4ef 7174static void
c19d1205 7175do_mrs (void)
b99bd4ef 7176{
037e8744
JB
7177 if (do_vfp_nsyn_mrs () == SUCCESS)
7178 return;
7179
c19d1205
ZW
7180 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7181 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7182 != (PSR_c|PSR_f),
7183 _("'CPSR' or 'SPSR' expected"));
7184 inst.instruction |= inst.operands[0].reg << 12;
7185 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7186}
b99bd4ef 7187
c19d1205
ZW
7188/* Two possible forms:
7189 "{C|S}PSR_<field>, Rm",
7190 "{C|S}PSR_f, #expression". */
b99bd4ef 7191
c19d1205
ZW
7192static void
7193do_msr (void)
7194{
037e8744
JB
7195 if (do_vfp_nsyn_msr () == SUCCESS)
7196 return;
7197
c19d1205
ZW
7198 inst.instruction |= inst.operands[0].imm;
7199 if (inst.operands[1].isreg)
7200 inst.instruction |= inst.operands[1].reg;
7201 else
b99bd4ef 7202 {
c19d1205
ZW
7203 inst.instruction |= INST_IMMEDIATE;
7204 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7205 inst.reloc.pc_rel = 0;
b99bd4ef 7206 }
b99bd4ef
NC
7207}
7208
c19d1205
ZW
7209static void
7210do_mul (void)
a737bd4d 7211{
c19d1205
ZW
7212 if (!inst.operands[2].present)
7213 inst.operands[2].reg = inst.operands[0].reg;
7214 inst.instruction |= inst.operands[0].reg << 16;
7215 inst.instruction |= inst.operands[1].reg;
7216 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7217
8fb9d7b9
MS
7218 if (inst.operands[0].reg == inst.operands[1].reg
7219 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7220 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7221}
7222
c19d1205
ZW
7223/* Long Multiply Parser
7224 UMULL RdLo, RdHi, Rm, Rs
7225 SMULL RdLo, RdHi, Rm, Rs
7226 UMLAL RdLo, RdHi, Rm, Rs
7227 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7228
7229static void
c19d1205 7230do_mull (void)
b99bd4ef 7231{
c19d1205
ZW
7232 inst.instruction |= inst.operands[0].reg << 12;
7233 inst.instruction |= inst.operands[1].reg << 16;
7234 inst.instruction |= inst.operands[2].reg;
7235 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7236
c19d1205
ZW
7237 /* rdhi, rdlo and rm must all be different. */
7238 if (inst.operands[0].reg == inst.operands[1].reg
7239 || inst.operands[0].reg == inst.operands[2].reg
7240 || inst.operands[1].reg == inst.operands[2].reg)
7241 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7242}
b99bd4ef 7243
c19d1205
ZW
7244static void
7245do_nop (void)
7246{
7247 if (inst.operands[0].present)
7248 {
7249 /* Architectural NOP hints are CPSR sets with no bits selected. */
7250 inst.instruction &= 0xf0000000;
7251 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7252 }
b99bd4ef
NC
7253}
7254
c19d1205
ZW
7255/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7256 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7257 Condition defaults to COND_ALWAYS.
7258 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7259
7260static void
c19d1205 7261do_pkhbt (void)
b99bd4ef 7262{
c19d1205
ZW
7263 inst.instruction |= inst.operands[0].reg << 12;
7264 inst.instruction |= inst.operands[1].reg << 16;
7265 inst.instruction |= inst.operands[2].reg;
7266 if (inst.operands[3].present)
7267 encode_arm_shift (3);
7268}
b99bd4ef 7269
c19d1205 7270/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7271
c19d1205
ZW
7272static void
7273do_pkhtb (void)
7274{
7275 if (!inst.operands[3].present)
b99bd4ef 7276 {
c19d1205
ZW
7277 /* If the shift specifier is omitted, turn the instruction
7278 into pkhbt rd, rm, rn. */
7279 inst.instruction &= 0xfff00010;
7280 inst.instruction |= inst.operands[0].reg << 12;
7281 inst.instruction |= inst.operands[1].reg;
7282 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7283 }
7284 else
7285 {
c19d1205
ZW
7286 inst.instruction |= inst.operands[0].reg << 12;
7287 inst.instruction |= inst.operands[1].reg << 16;
7288 inst.instruction |= inst.operands[2].reg;
7289 encode_arm_shift (3);
b99bd4ef
NC
7290 }
7291}
7292
c19d1205
ZW
7293/* ARMv5TE: Preload-Cache
7294
7295 PLD <addr_mode>
7296
7297 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7298
7299static void
c19d1205 7300do_pld (void)
b99bd4ef 7301{
c19d1205
ZW
7302 constraint (!inst.operands[0].isreg,
7303 _("'[' expected after PLD mnemonic"));
7304 constraint (inst.operands[0].postind,
7305 _("post-indexed expression used in preload instruction"));
7306 constraint (inst.operands[0].writeback,
7307 _("writeback used in preload instruction"));
7308 constraint (!inst.operands[0].preind,
7309 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7310 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7311}
b99bd4ef 7312
62b3e311
PB
7313/* ARMv7: PLI <addr_mode> */
7314static void
7315do_pli (void)
7316{
7317 constraint (!inst.operands[0].isreg,
7318 _("'[' expected after PLI mnemonic"));
7319 constraint (inst.operands[0].postind,
7320 _("post-indexed expression used in preload instruction"));
7321 constraint (inst.operands[0].writeback,
7322 _("writeback used in preload instruction"));
7323 constraint (!inst.operands[0].preind,
7324 _("unindexed addressing used in preload instruction"));
7325 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7326 inst.instruction &= ~PRE_INDEX;
7327}
7328
c19d1205
ZW
7329static void
7330do_push_pop (void)
7331{
7332 inst.operands[1] = inst.operands[0];
7333 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7334 inst.operands[0].isreg = 1;
7335 inst.operands[0].writeback = 1;
7336 inst.operands[0].reg = REG_SP;
7337 do_ldmstm ();
7338}
b99bd4ef 7339
c19d1205
ZW
7340/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7341 word at the specified address and the following word
7342 respectively.
7343 Unconditionally executed.
7344 Error if Rn is R15. */
b99bd4ef 7345
c19d1205
ZW
7346static void
7347do_rfe (void)
7348{
7349 inst.instruction |= inst.operands[0].reg << 16;
7350 if (inst.operands[0].writeback)
7351 inst.instruction |= WRITE_BACK;
7352}
b99bd4ef 7353
c19d1205 7354/* ARM V6 ssat (argument parse). */
b99bd4ef 7355
c19d1205
ZW
7356static void
7357do_ssat (void)
7358{
7359 inst.instruction |= inst.operands[0].reg << 12;
7360 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7361 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7362
c19d1205
ZW
7363 if (inst.operands[3].present)
7364 encode_arm_shift (3);
b99bd4ef
NC
7365}
7366
c19d1205 7367/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7368
7369static void
c19d1205 7370do_usat (void)
b99bd4ef 7371{
c19d1205
ZW
7372 inst.instruction |= inst.operands[0].reg << 12;
7373 inst.instruction |= inst.operands[1].imm << 16;
7374 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7375
c19d1205
ZW
7376 if (inst.operands[3].present)
7377 encode_arm_shift (3);
b99bd4ef
NC
7378}
7379
c19d1205 7380/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7381
7382static void
c19d1205 7383do_ssat16 (void)
09d92015 7384{
c19d1205
ZW
7385 inst.instruction |= inst.operands[0].reg << 12;
7386 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7387 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7388}
7389
c19d1205
ZW
7390static void
7391do_usat16 (void)
a737bd4d 7392{
c19d1205
ZW
7393 inst.instruction |= inst.operands[0].reg << 12;
7394 inst.instruction |= inst.operands[1].imm << 16;
7395 inst.instruction |= inst.operands[2].reg;
7396}
a737bd4d 7397
c19d1205
ZW
7398/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7399 preserving the other bits.
a737bd4d 7400
c19d1205
ZW
7401 setend <endian_specifier>, where <endian_specifier> is either
7402 BE or LE. */
a737bd4d 7403
c19d1205
ZW
7404static void
7405do_setend (void)
7406{
7407 if (inst.operands[0].imm)
7408 inst.instruction |= 0x200;
a737bd4d
NC
7409}
7410
7411static void
c19d1205 7412do_shift (void)
a737bd4d 7413{
c19d1205
ZW
7414 unsigned int Rm = (inst.operands[1].present
7415 ? inst.operands[1].reg
7416 : inst.operands[0].reg);
a737bd4d 7417
c19d1205
ZW
7418 inst.instruction |= inst.operands[0].reg << 12;
7419 inst.instruction |= Rm;
7420 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7421 {
c19d1205
ZW
7422 inst.instruction |= inst.operands[2].reg << 8;
7423 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7424 }
7425 else
c19d1205 7426 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7427}
7428
09d92015 7429static void
3eb17e6b 7430do_smc (void)
09d92015 7431{
3eb17e6b 7432 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7433 inst.reloc.pc_rel = 0;
09d92015
MM
7434}
7435
09d92015 7436static void
c19d1205 7437do_swi (void)
09d92015 7438{
c19d1205
ZW
7439 inst.reloc.type = BFD_RELOC_ARM_SWI;
7440 inst.reloc.pc_rel = 0;
09d92015
MM
7441}
7442
c19d1205
ZW
7443/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7444 SMLAxy{cond} Rd,Rm,Rs,Rn
7445 SMLAWy{cond} Rd,Rm,Rs,Rn
7446 Error if any register is R15. */
e16bb312 7447
c19d1205
ZW
7448static void
7449do_smla (void)
e16bb312 7450{
c19d1205
ZW
7451 inst.instruction |= inst.operands[0].reg << 16;
7452 inst.instruction |= inst.operands[1].reg;
7453 inst.instruction |= inst.operands[2].reg << 8;
7454 inst.instruction |= inst.operands[3].reg << 12;
7455}
a737bd4d 7456
c19d1205
ZW
7457/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7458 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7459 Error if any register is R15.
7460 Warning if Rdlo == Rdhi. */
a737bd4d 7461
c19d1205
ZW
7462static void
7463do_smlal (void)
7464{
7465 inst.instruction |= inst.operands[0].reg << 12;
7466 inst.instruction |= inst.operands[1].reg << 16;
7467 inst.instruction |= inst.operands[2].reg;
7468 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7469
c19d1205
ZW
7470 if (inst.operands[0].reg == inst.operands[1].reg)
7471 as_tsktsk (_("rdhi and rdlo must be different"));
7472}
a737bd4d 7473
c19d1205
ZW
7474/* ARM V5E (El Segundo) signed-multiply (argument parse)
7475 SMULxy{cond} Rd,Rm,Rs
7476 Error if any register is R15. */
a737bd4d 7477
c19d1205
ZW
7478static void
7479do_smul (void)
7480{
7481 inst.instruction |= inst.operands[0].reg << 16;
7482 inst.instruction |= inst.operands[1].reg;
7483 inst.instruction |= inst.operands[2].reg << 8;
7484}
a737bd4d 7485
b6702015
PB
7486/* ARM V6 srs (argument parse). The variable fields in the encoding are
7487 the same for both ARM and Thumb-2. */
a737bd4d 7488
c19d1205
ZW
7489static void
7490do_srs (void)
7491{
b6702015
PB
7492 int reg;
7493
7494 if (inst.operands[0].present)
7495 {
7496 reg = inst.operands[0].reg;
7497 constraint (reg != 13, _("SRS base register must be r13"));
7498 }
7499 else
7500 reg = 13;
7501
7502 inst.instruction |= reg << 16;
7503 inst.instruction |= inst.operands[1].imm;
7504 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7505 inst.instruction |= WRITE_BACK;
7506}
a737bd4d 7507
c19d1205 7508/* ARM V6 strex (argument parse). */
a737bd4d 7509
c19d1205
ZW
7510static void
7511do_strex (void)
7512{
7513 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7514 || inst.operands[2].postind || inst.operands[2].writeback
7515 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7516 || inst.operands[2].negative
7517 /* See comment in do_ldrex(). */
7518 || (inst.operands[2].reg == REG_PC),
7519 BAD_ADDR_MODE);
a737bd4d 7520
c19d1205
ZW
7521 constraint (inst.operands[0].reg == inst.operands[1].reg
7522 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7523
c19d1205
ZW
7524 constraint (inst.reloc.exp.X_op != O_constant
7525 || inst.reloc.exp.X_add_number != 0,
7526 _("offset must be zero in ARM encoding"));
a737bd4d 7527
c19d1205
ZW
7528 inst.instruction |= inst.operands[0].reg << 12;
7529 inst.instruction |= inst.operands[1].reg;
7530 inst.instruction |= inst.operands[2].reg << 16;
7531 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7532}
7533
7534static void
c19d1205 7535do_strexd (void)
e16bb312 7536{
c19d1205
ZW
7537 constraint (inst.operands[1].reg % 2 != 0,
7538 _("even register required"));
7539 constraint (inst.operands[2].present
7540 && inst.operands[2].reg != inst.operands[1].reg + 1,
7541 _("can only store two consecutive registers"));
7542 /* If op 2 were present and equal to PC, this function wouldn't
7543 have been called in the first place. */
7544 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7545
c19d1205
ZW
7546 constraint (inst.operands[0].reg == inst.operands[1].reg
7547 || inst.operands[0].reg == inst.operands[1].reg + 1
7548 || inst.operands[0].reg == inst.operands[3].reg,
7549 BAD_OVERLAP);
e16bb312 7550
c19d1205
ZW
7551 inst.instruction |= inst.operands[0].reg << 12;
7552 inst.instruction |= inst.operands[1].reg;
7553 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7554}
7555
c19d1205
ZW
7556/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7557 extends it to 32-bits, and adds the result to a value in another
7558 register. You can specify a rotation by 0, 8, 16, or 24 bits
7559 before extracting the 16-bit value.
7560 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7561 Condition defaults to COND_ALWAYS.
7562 Error if any register uses R15. */
7563
e16bb312 7564static void
c19d1205 7565do_sxtah (void)
e16bb312 7566{
c19d1205
ZW
7567 inst.instruction |= inst.operands[0].reg << 12;
7568 inst.instruction |= inst.operands[1].reg << 16;
7569 inst.instruction |= inst.operands[2].reg;
7570 inst.instruction |= inst.operands[3].imm << 10;
7571}
e16bb312 7572
c19d1205 7573/* ARM V6 SXTH.
e16bb312 7574
c19d1205
ZW
7575 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7576 Condition defaults to COND_ALWAYS.
7577 Error if any register uses R15. */
e16bb312
NC
7578
7579static void
c19d1205 7580do_sxth (void)
e16bb312 7581{
c19d1205
ZW
7582 inst.instruction |= inst.operands[0].reg << 12;
7583 inst.instruction |= inst.operands[1].reg;
7584 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7585}
c19d1205
ZW
7586\f
7587/* VFP instructions. In a logical order: SP variant first, monad
7588 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7589
7590static void
c19d1205 7591do_vfp_sp_monadic (void)
e16bb312 7592{
5287ad62
JB
7593 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7594 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7595}
7596
7597static void
c19d1205 7598do_vfp_sp_dyadic (void)
e16bb312 7599{
5287ad62
JB
7600 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7601 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7602 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7603}
7604
7605static void
c19d1205 7606do_vfp_sp_compare_z (void)
e16bb312 7607{
5287ad62 7608 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7609}
7610
7611static void
c19d1205 7612do_vfp_dp_sp_cvt (void)
e16bb312 7613{
5287ad62
JB
7614 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7615 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7616}
7617
7618static void
c19d1205 7619do_vfp_sp_dp_cvt (void)
e16bb312 7620{
5287ad62
JB
7621 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7622 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7623}
7624
7625static void
c19d1205 7626do_vfp_reg_from_sp (void)
e16bb312 7627{
c19d1205 7628 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7629 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7630}
7631
7632static void
c19d1205 7633do_vfp_reg2_from_sp2 (void)
e16bb312 7634{
c19d1205
ZW
7635 constraint (inst.operands[2].imm != 2,
7636 _("only two consecutive VFP SP registers allowed here"));
7637 inst.instruction |= inst.operands[0].reg << 12;
7638 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7639 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7640}
7641
7642static void
c19d1205 7643do_vfp_sp_from_reg (void)
e16bb312 7644{
5287ad62 7645 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7646 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7647}
7648
7649static void
c19d1205 7650do_vfp_sp2_from_reg2 (void)
e16bb312 7651{
c19d1205
ZW
7652 constraint (inst.operands[0].imm != 2,
7653 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7654 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7655 inst.instruction |= inst.operands[1].reg << 12;
7656 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7657}
7658
7659static void
c19d1205 7660do_vfp_sp_ldst (void)
e16bb312 7661{
5287ad62 7662 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7663 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7664}
7665
7666static void
c19d1205 7667do_vfp_dp_ldst (void)
e16bb312 7668{
5287ad62 7669 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7670 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7671}
7672
c19d1205 7673
e16bb312 7674static void
c19d1205 7675vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7676{
c19d1205
ZW
7677 if (inst.operands[0].writeback)
7678 inst.instruction |= WRITE_BACK;
7679 else
7680 constraint (ldstm_type != VFP_LDSTMIA,
7681 _("this addressing mode requires base-register writeback"));
7682 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7683 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7684 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7685}
7686
7687static void
c19d1205 7688vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7689{
c19d1205 7690 int count;
e16bb312 7691
c19d1205
ZW
7692 if (inst.operands[0].writeback)
7693 inst.instruction |= WRITE_BACK;
7694 else
7695 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7696 _("this addressing mode requires base-register writeback"));
e16bb312 7697
c19d1205 7698 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7699 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7700
c19d1205
ZW
7701 count = inst.operands[1].imm << 1;
7702 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7703 count += 1;
e16bb312 7704
c19d1205 7705 inst.instruction |= count;
e16bb312
NC
7706}
7707
7708static void
c19d1205 7709do_vfp_sp_ldstmia (void)
e16bb312 7710{
c19d1205 7711 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7712}
7713
7714static void
c19d1205 7715do_vfp_sp_ldstmdb (void)
e16bb312 7716{
c19d1205 7717 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7718}
7719
7720static void
c19d1205 7721do_vfp_dp_ldstmia (void)
e16bb312 7722{
c19d1205 7723 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7724}
7725
7726static void
c19d1205 7727do_vfp_dp_ldstmdb (void)
e16bb312 7728{
c19d1205 7729 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7730}
7731
7732static void
c19d1205 7733do_vfp_xp_ldstmia (void)
e16bb312 7734{
c19d1205
ZW
7735 vfp_dp_ldstm (VFP_LDSTMIAX);
7736}
e16bb312 7737
c19d1205
ZW
7738static void
7739do_vfp_xp_ldstmdb (void)
7740{
7741 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7742}
5287ad62
JB
7743
7744static void
7745do_vfp_dp_rd_rm (void)
7746{
7747 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7748 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7749}
7750
7751static void
7752do_vfp_dp_rn_rd (void)
7753{
7754 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7755 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7756}
7757
7758static void
7759do_vfp_dp_rd_rn (void)
7760{
7761 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7762 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7763}
7764
7765static void
7766do_vfp_dp_rd_rn_rm (void)
7767{
7768 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7769 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7770 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7771}
7772
7773static void
7774do_vfp_dp_rd (void)
7775{
7776 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7777}
7778
7779static void
7780do_vfp_dp_rm_rd_rn (void)
7781{
7782 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7783 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7784 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7785}
7786
7787/* VFPv3 instructions. */
7788static void
7789do_vfp_sp_const (void)
7790{
7791 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
7792 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7793 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7794}
7795
7796static void
7797do_vfp_dp_const (void)
7798{
7799 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
7800 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
7801 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
7802}
7803
7804static void
7805vfp_conv (int srcsize)
7806{
7807 unsigned immbits = srcsize - inst.operands[1].imm;
7808 inst.instruction |= (immbits & 1) << 5;
7809 inst.instruction |= (immbits >> 1);
7810}
7811
7812static void
7813do_vfp_sp_conv_16 (void)
7814{
7815 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7816 vfp_conv (16);
7817}
7818
7819static void
7820do_vfp_dp_conv_16 (void)
7821{
7822 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7823 vfp_conv (16);
7824}
7825
7826static void
7827do_vfp_sp_conv_32 (void)
7828{
7829 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7830 vfp_conv (32);
7831}
7832
7833static void
7834do_vfp_dp_conv_32 (void)
7835{
7836 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7837 vfp_conv (32);
7838}
7839
c19d1205
ZW
7840\f
7841/* FPA instructions. Also in a logical order. */
e16bb312 7842
c19d1205
ZW
7843static void
7844do_fpa_cmp (void)
7845{
7846 inst.instruction |= inst.operands[0].reg << 16;
7847 inst.instruction |= inst.operands[1].reg;
7848}
b99bd4ef
NC
7849
7850static void
c19d1205 7851do_fpa_ldmstm (void)
b99bd4ef 7852{
c19d1205
ZW
7853 inst.instruction |= inst.operands[0].reg << 12;
7854 switch (inst.operands[1].imm)
7855 {
7856 case 1: inst.instruction |= CP_T_X; break;
7857 case 2: inst.instruction |= CP_T_Y; break;
7858 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7859 case 4: break;
7860 default: abort ();
7861 }
b99bd4ef 7862
c19d1205
ZW
7863 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7864 {
7865 /* The instruction specified "ea" or "fd", so we can only accept
7866 [Rn]{!}. The instruction does not really support stacking or
7867 unstacking, so we have to emulate these by setting appropriate
7868 bits and offsets. */
7869 constraint (inst.reloc.exp.X_op != O_constant
7870 || inst.reloc.exp.X_add_number != 0,
7871 _("this instruction does not support indexing"));
b99bd4ef 7872
c19d1205
ZW
7873 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7874 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7875
c19d1205
ZW
7876 if (!(inst.instruction & INDEX_UP))
7877 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7878
c19d1205
ZW
7879 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7880 {
7881 inst.operands[2].preind = 0;
7882 inst.operands[2].postind = 1;
7883 }
7884 }
b99bd4ef 7885
c19d1205 7886 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7887}
037e8744 7888
c19d1205
ZW
7889\f
7890/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7891
c19d1205
ZW
7892static void
7893do_iwmmxt_tandorc (void)
7894{
7895 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7896}
b99bd4ef 7897
c19d1205
ZW
7898static void
7899do_iwmmxt_textrc (void)
7900{
7901 inst.instruction |= inst.operands[0].reg << 12;
7902 inst.instruction |= inst.operands[1].imm;
7903}
b99bd4ef
NC
7904
7905static void
c19d1205 7906do_iwmmxt_textrm (void)
b99bd4ef 7907{
c19d1205
ZW
7908 inst.instruction |= inst.operands[0].reg << 12;
7909 inst.instruction |= inst.operands[1].reg << 16;
7910 inst.instruction |= inst.operands[2].imm;
7911}
b99bd4ef 7912
c19d1205
ZW
7913static void
7914do_iwmmxt_tinsr (void)
7915{
7916 inst.instruction |= inst.operands[0].reg << 16;
7917 inst.instruction |= inst.operands[1].reg << 12;
7918 inst.instruction |= inst.operands[2].imm;
7919}
b99bd4ef 7920
c19d1205
ZW
7921static void
7922do_iwmmxt_tmia (void)
7923{
7924 inst.instruction |= inst.operands[0].reg << 5;
7925 inst.instruction |= inst.operands[1].reg;
7926 inst.instruction |= inst.operands[2].reg << 12;
7927}
b99bd4ef 7928
c19d1205
ZW
7929static void
7930do_iwmmxt_waligni (void)
7931{
7932 inst.instruction |= inst.operands[0].reg << 12;
7933 inst.instruction |= inst.operands[1].reg << 16;
7934 inst.instruction |= inst.operands[2].reg;
7935 inst.instruction |= inst.operands[3].imm << 20;
7936}
b99bd4ef 7937
2d447fca
JM
7938static void
7939do_iwmmxt_wmerge (void)
7940{
7941 inst.instruction |= inst.operands[0].reg << 12;
7942 inst.instruction |= inst.operands[1].reg << 16;
7943 inst.instruction |= inst.operands[2].reg;
7944 inst.instruction |= inst.operands[3].imm << 21;
7945}
7946
c19d1205
ZW
7947static void
7948do_iwmmxt_wmov (void)
7949{
7950 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7951 inst.instruction |= inst.operands[0].reg << 12;
7952 inst.instruction |= inst.operands[1].reg << 16;
7953 inst.instruction |= inst.operands[1].reg;
7954}
b99bd4ef 7955
c19d1205
ZW
7956static void
7957do_iwmmxt_wldstbh (void)
7958{
8f06b2d8 7959 int reloc;
c19d1205 7960 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7961 if (thumb_mode)
7962 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7963 else
7964 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7965 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7966}
7967
c19d1205
ZW
7968static void
7969do_iwmmxt_wldstw (void)
7970{
7971 /* RIWR_RIWC clears .isreg for a control register. */
7972 if (!inst.operands[0].isreg)
7973 {
7974 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7975 inst.instruction |= 0xf0000000;
7976 }
b99bd4ef 7977
c19d1205
ZW
7978 inst.instruction |= inst.operands[0].reg << 12;
7979 encode_arm_cp_address (1, TRUE, TRUE, 0);
7980}
b99bd4ef
NC
7981
7982static void
c19d1205 7983do_iwmmxt_wldstd (void)
b99bd4ef 7984{
c19d1205 7985 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
7986 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
7987 && inst.operands[1].immisreg)
7988 {
7989 inst.instruction &= ~0x1a000ff;
7990 inst.instruction |= (0xf << 28);
7991 if (inst.operands[1].preind)
7992 inst.instruction |= PRE_INDEX;
7993 if (!inst.operands[1].negative)
7994 inst.instruction |= INDEX_UP;
7995 if (inst.operands[1].writeback)
7996 inst.instruction |= WRITE_BACK;
7997 inst.instruction |= inst.operands[1].reg << 16;
7998 inst.instruction |= inst.reloc.exp.X_add_number << 4;
7999 inst.instruction |= inst.operands[1].imm;
8000 }
8001 else
8002 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8003}
b99bd4ef 8004
c19d1205
ZW
8005static void
8006do_iwmmxt_wshufh (void)
8007{
8008 inst.instruction |= inst.operands[0].reg << 12;
8009 inst.instruction |= inst.operands[1].reg << 16;
8010 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8011 inst.instruction |= (inst.operands[2].imm & 0x0f);
8012}
b99bd4ef 8013
c19d1205
ZW
8014static void
8015do_iwmmxt_wzero (void)
8016{
8017 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8018 inst.instruction |= inst.operands[0].reg;
8019 inst.instruction |= inst.operands[0].reg << 12;
8020 inst.instruction |= inst.operands[0].reg << 16;
8021}
2d447fca
JM
8022
8023static void
8024do_iwmmxt_wrwrwr_or_imm5 (void)
8025{
8026 if (inst.operands[2].isreg)
8027 do_rd_rn_rm ();
8028 else {
8029 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8030 _("immediate operand requires iWMMXt2"));
8031 do_rd_rn ();
8032 if (inst.operands[2].imm == 0)
8033 {
8034 switch ((inst.instruction >> 20) & 0xf)
8035 {
8036 case 4:
8037 case 5:
8038 case 6:
8039 case 7:
8040 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8041 inst.operands[2].imm = 16;
8042 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8043 break;
8044 case 8:
8045 case 9:
8046 case 10:
8047 case 11:
8048 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8049 inst.operands[2].imm = 32;
8050 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8051 break;
8052 case 12:
8053 case 13:
8054 case 14:
8055 case 15:
8056 {
8057 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8058 unsigned long wrn;
8059 wrn = (inst.instruction >> 16) & 0xf;
8060 inst.instruction &= 0xff0fff0f;
8061 inst.instruction |= wrn;
8062 /* Bail out here; the instruction is now assembled. */
8063 return;
8064 }
8065 }
8066 }
8067 /* Map 32 -> 0, etc. */
8068 inst.operands[2].imm &= 0x1f;
8069 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8070 }
8071}
c19d1205
ZW
8072\f
8073/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8074 operations first, then control, shift, and load/store. */
b99bd4ef 8075
c19d1205 8076/* Insns like "foo X,Y,Z". */
b99bd4ef 8077
c19d1205
ZW
8078static void
8079do_mav_triple (void)
8080{
8081 inst.instruction |= inst.operands[0].reg << 16;
8082 inst.instruction |= inst.operands[1].reg;
8083 inst.instruction |= inst.operands[2].reg << 12;
8084}
b99bd4ef 8085
c19d1205
ZW
8086/* Insns like "foo W,X,Y,Z".
8087 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8088
c19d1205
ZW
8089static void
8090do_mav_quad (void)
8091{
8092 inst.instruction |= inst.operands[0].reg << 5;
8093 inst.instruction |= inst.operands[1].reg << 12;
8094 inst.instruction |= inst.operands[2].reg << 16;
8095 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8096}
8097
c19d1205
ZW
8098/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8099static void
8100do_mav_dspsc (void)
a737bd4d 8101{
c19d1205
ZW
8102 inst.instruction |= inst.operands[1].reg << 12;
8103}
a737bd4d 8104
c19d1205
ZW
8105/* Maverick shift immediate instructions.
8106 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8107 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8108
c19d1205
ZW
8109static void
8110do_mav_shift (void)
8111{
8112 int imm = inst.operands[2].imm;
a737bd4d 8113
c19d1205
ZW
8114 inst.instruction |= inst.operands[0].reg << 12;
8115 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8116
c19d1205
ZW
8117 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8118 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8119 Bit 4 should be 0. */
8120 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8121
c19d1205
ZW
8122 inst.instruction |= imm;
8123}
8124\f
8125/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8126
c19d1205
ZW
8127/* Xscale multiply-accumulate (argument parse)
8128 MIAcc acc0,Rm,Rs
8129 MIAPHcc acc0,Rm,Rs
8130 MIAxycc acc0,Rm,Rs. */
a737bd4d 8131
c19d1205
ZW
8132static void
8133do_xsc_mia (void)
8134{
8135 inst.instruction |= inst.operands[1].reg;
8136 inst.instruction |= inst.operands[2].reg << 12;
8137}
a737bd4d 8138
c19d1205 8139/* Xscale move-accumulator-register (argument parse)
a737bd4d 8140
c19d1205 8141 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8142
c19d1205
ZW
8143static void
8144do_xsc_mar (void)
8145{
8146 inst.instruction |= inst.operands[1].reg << 12;
8147 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8148}
8149
c19d1205 8150/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8151
c19d1205 8152 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8153
8154static void
c19d1205 8155do_xsc_mra (void)
b99bd4ef 8156{
c19d1205
ZW
8157 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8158 inst.instruction |= inst.operands[0].reg << 12;
8159 inst.instruction |= inst.operands[1].reg << 16;
8160}
8161\f
8162/* Encoding functions relevant only to Thumb. */
b99bd4ef 8163
c19d1205
ZW
8164/* inst.operands[i] is a shifted-register operand; encode
8165 it into inst.instruction in the format used by Thumb32. */
8166
8167static void
8168encode_thumb32_shifted_operand (int i)
8169{
8170 unsigned int value = inst.reloc.exp.X_add_number;
8171 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8172
9c3c69f2
PB
8173 constraint (inst.operands[i].immisreg,
8174 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8175 inst.instruction |= inst.operands[i].reg;
8176 if (shift == SHIFT_RRX)
8177 inst.instruction |= SHIFT_ROR << 4;
8178 else
b99bd4ef 8179 {
c19d1205
ZW
8180 constraint (inst.reloc.exp.X_op != O_constant,
8181 _("expression too complex"));
8182
8183 constraint (value > 32
8184 || (value == 32 && (shift == SHIFT_LSL
8185 || shift == SHIFT_ROR)),
8186 _("shift expression is too large"));
8187
8188 if (value == 0)
8189 shift = SHIFT_LSL;
8190 else if (value == 32)
8191 value = 0;
8192
8193 inst.instruction |= shift << 4;
8194 inst.instruction |= (value & 0x1c) << 10;
8195 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8196 }
c19d1205 8197}
b99bd4ef 8198
b99bd4ef 8199
c19d1205
ZW
8200/* inst.operands[i] was set up by parse_address. Encode it into a
8201 Thumb32 format load or store instruction. Reject forms that cannot
8202 be used with such instructions. If is_t is true, reject forms that
8203 cannot be used with a T instruction; if is_d is true, reject forms
8204 that cannot be used with a D instruction. */
b99bd4ef 8205
c19d1205
ZW
8206static void
8207encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8208{
8209 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8210
8211 constraint (!inst.operands[i].isreg,
53365c0d 8212 _("Instruction does not support =N addresses"));
b99bd4ef 8213
c19d1205
ZW
8214 inst.instruction |= inst.operands[i].reg << 16;
8215 if (inst.operands[i].immisreg)
b99bd4ef 8216 {
c19d1205
ZW
8217 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8218 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8219 constraint (inst.operands[i].negative,
8220 _("Thumb does not support negative register indexing"));
8221 constraint (inst.operands[i].postind,
8222 _("Thumb does not support register post-indexing"));
8223 constraint (inst.operands[i].writeback,
8224 _("Thumb does not support register indexing with writeback"));
8225 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8226 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8227
f40d1643 8228 inst.instruction |= inst.operands[i].imm;
c19d1205 8229 if (inst.operands[i].shifted)
b99bd4ef 8230 {
c19d1205
ZW
8231 constraint (inst.reloc.exp.X_op != O_constant,
8232 _("expression too complex"));
9c3c69f2
PB
8233 constraint (inst.reloc.exp.X_add_number < 0
8234 || inst.reloc.exp.X_add_number > 3,
c19d1205 8235 _("shift out of range"));
9c3c69f2 8236 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8237 }
8238 inst.reloc.type = BFD_RELOC_UNUSED;
8239 }
8240 else if (inst.operands[i].preind)
8241 {
8242 constraint (is_pc && inst.operands[i].writeback,
8243 _("cannot use writeback with PC-relative addressing"));
f40d1643 8244 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8245 _("cannot use writeback with this instruction"));
8246
8247 if (is_d)
8248 {
8249 inst.instruction |= 0x01000000;
8250 if (inst.operands[i].writeback)
8251 inst.instruction |= 0x00200000;
b99bd4ef 8252 }
c19d1205 8253 else
b99bd4ef 8254 {
c19d1205
ZW
8255 inst.instruction |= 0x00000c00;
8256 if (inst.operands[i].writeback)
8257 inst.instruction |= 0x00000100;
b99bd4ef 8258 }
c19d1205 8259 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8260 }
c19d1205 8261 else if (inst.operands[i].postind)
b99bd4ef 8262 {
c19d1205
ZW
8263 assert (inst.operands[i].writeback);
8264 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8265 constraint (is_t, _("cannot use post-indexing with this instruction"));
8266
8267 if (is_d)
8268 inst.instruction |= 0x00200000;
8269 else
8270 inst.instruction |= 0x00000900;
8271 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8272 }
8273 else /* unindexed - only for coprocessor */
8274 inst.error = _("instruction does not accept unindexed addressing");
8275}
8276
8277/* Table of Thumb instructions which exist in both 16- and 32-bit
8278 encodings (the latter only in post-V6T2 cores). The index is the
8279 value used in the insns table below. When there is more than one
8280 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8281 holds variant (1).
8282 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8283#define T16_32_TAB \
8284 X(adc, 4140, eb400000), \
8285 X(adcs, 4140, eb500000), \
8286 X(add, 1c00, eb000000), \
8287 X(adds, 1c00, eb100000), \
0110f2b8
PB
8288 X(addi, 0000, f1000000), \
8289 X(addis, 0000, f1100000), \
8290 X(add_pc,000f, f20f0000), \
8291 X(add_sp,000d, f10d0000), \
e9f89963 8292 X(adr, 000f, f20f0000), \
c19d1205
ZW
8293 X(and, 4000, ea000000), \
8294 X(ands, 4000, ea100000), \
8295 X(asr, 1000, fa40f000), \
8296 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8297 X(b, e000, f000b000), \
8298 X(bcond, d000, f0008000), \
c19d1205
ZW
8299 X(bic, 4380, ea200000), \
8300 X(bics, 4380, ea300000), \
8301 X(cmn, 42c0, eb100f00), \
8302 X(cmp, 2800, ebb00f00), \
8303 X(cpsie, b660, f3af8400), \
8304 X(cpsid, b670, f3af8600), \
8305 X(cpy, 4600, ea4f0000), \
155257ea 8306 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8307 X(eor, 4040, ea800000), \
8308 X(eors, 4040, ea900000), \
0110f2b8 8309 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8310 X(ldmia, c800, e8900000), \
8311 X(ldr, 6800, f8500000), \
8312 X(ldrb, 7800, f8100000), \
8313 X(ldrh, 8800, f8300000), \
8314 X(ldrsb, 5600, f9100000), \
8315 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8316 X(ldr_pc,4800, f85f0000), \
8317 X(ldr_pc2,4800, f85f0000), \
8318 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8319 X(lsl, 0000, fa00f000), \
8320 X(lsls, 0000, fa10f000), \
8321 X(lsr, 0800, fa20f000), \
8322 X(lsrs, 0800, fa30f000), \
8323 X(mov, 2000, ea4f0000), \
8324 X(movs, 2000, ea5f0000), \
8325 X(mul, 4340, fb00f000), \
8326 X(muls, 4340, ffffffff), /* no 32b muls */ \
8327 X(mvn, 43c0, ea6f0000), \
8328 X(mvns, 43c0, ea7f0000), \
8329 X(neg, 4240, f1c00000), /* rsb #0 */ \
8330 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8331 X(orr, 4300, ea400000), \
8332 X(orrs, 4300, ea500000), \
e9f89963
PB
8333 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8334 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8335 X(rev, ba00, fa90f080), \
8336 X(rev16, ba40, fa90f090), \
8337 X(revsh, bac0, fa90f0b0), \
8338 X(ror, 41c0, fa60f000), \
8339 X(rors, 41c0, fa70f000), \
8340 X(sbc, 4180, eb600000), \
8341 X(sbcs, 4180, eb700000), \
8342 X(stmia, c000, e8800000), \
8343 X(str, 6000, f8400000), \
8344 X(strb, 7000, f8000000), \
8345 X(strh, 8000, f8200000), \
0110f2b8 8346 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8347 X(sub, 1e00, eba00000), \
8348 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8349 X(subi, 8000, f1a00000), \
8350 X(subis, 8000, f1b00000), \
c19d1205
ZW
8351 X(sxtb, b240, fa4ff080), \
8352 X(sxth, b200, fa0ff080), \
8353 X(tst, 4200, ea100f00), \
8354 X(uxtb, b2c0, fa5ff080), \
8355 X(uxth, b280, fa1ff080), \
8356 X(nop, bf00, f3af8000), \
8357 X(yield, bf10, f3af8001), \
8358 X(wfe, bf20, f3af8002), \
8359 X(wfi, bf30, f3af8003), \
8360 X(sev, bf40, f3af9004), /* typo, 8004? */
8361
8362/* To catch errors in encoding functions, the codes are all offset by
8363 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8364 as 16-bit instructions. */
8365#define X(a,b,c) T_MNEM_##a
8366enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8367#undef X
8368
8369#define X(a,b,c) 0x##b
8370static const unsigned short thumb_op16[] = { T16_32_TAB };
8371#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8372#undef X
8373
8374#define X(a,b,c) 0x##c
8375static const unsigned int thumb_op32[] = { T16_32_TAB };
8376#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8377#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8378#undef X
8379#undef T16_32_TAB
8380
8381/* Thumb instruction encoders, in alphabetical order. */
8382
92e90b6e
PB
8383/* ADDW or SUBW. */
8384static void
8385do_t_add_sub_w (void)
8386{
8387 int Rd, Rn;
8388
8389 Rd = inst.operands[0].reg;
8390 Rn = inst.operands[1].reg;
8391
8392 constraint (Rd == 15, _("PC not allowed as destination"));
8393 inst.instruction |= (Rn << 16) | (Rd << 8);
8394 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8395}
8396
c19d1205
ZW
8397/* Parse an add or subtract instruction. We get here with inst.instruction
8398 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8399
8400static void
8401do_t_add_sub (void)
8402{
8403 int Rd, Rs, Rn;
8404
8405 Rd = inst.operands[0].reg;
8406 Rs = (inst.operands[1].present
8407 ? inst.operands[1].reg /* Rd, Rs, foo */
8408 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8409
8410 if (unified_syntax)
8411 {
0110f2b8
PB
8412 bfd_boolean flags;
8413 bfd_boolean narrow;
8414 int opcode;
8415
8416 flags = (inst.instruction == T_MNEM_adds
8417 || inst.instruction == T_MNEM_subs);
8418 if (flags)
8419 narrow = (current_it_mask == 0);
8420 else
8421 narrow = (current_it_mask != 0);
c19d1205 8422 if (!inst.operands[2].isreg)
b99bd4ef 8423 {
16805f35
PB
8424 int add;
8425
8426 add = (inst.instruction == T_MNEM_add
8427 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8428 opcode = 0;
8429 if (inst.size_req != 4)
8430 {
0110f2b8
PB
8431 /* Attempt to use a narrow opcode, with relaxation if
8432 appropriate. */
8433 if (Rd == REG_SP && Rs == REG_SP && !flags)
8434 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8435 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8436 opcode = T_MNEM_add_sp;
8437 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8438 opcode = T_MNEM_add_pc;
8439 else if (Rd <= 7 && Rs <= 7 && narrow)
8440 {
8441 if (flags)
8442 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8443 else
8444 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8445 }
8446 if (opcode)
8447 {
8448 inst.instruction = THUMB_OP16(opcode);
8449 inst.instruction |= (Rd << 4) | Rs;
8450 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8451 if (inst.size_req != 2)
8452 inst.relax = opcode;
8453 }
8454 else
8455 constraint (inst.size_req == 2, BAD_HIREG);
8456 }
8457 if (inst.size_req == 4
8458 || (inst.size_req != 2 && !opcode))
8459 {
efd81785
PB
8460 if (Rd == REG_PC)
8461 {
8462 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8463 _("only SUBS PC, LR, #const allowed"));
8464 constraint (inst.reloc.exp.X_op != O_constant,
8465 _("expression too complex"));
8466 constraint (inst.reloc.exp.X_add_number < 0
8467 || inst.reloc.exp.X_add_number > 0xff,
8468 _("immediate value out of range"));
8469 inst.instruction = T2_SUBS_PC_LR
8470 | inst.reloc.exp.X_add_number;
8471 inst.reloc.type = BFD_RELOC_UNUSED;
8472 return;
8473 }
8474 else if (Rs == REG_PC)
16805f35
PB
8475 {
8476 /* Always use addw/subw. */
8477 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8478 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8479 }
8480 else
8481 {
8482 inst.instruction = THUMB_OP32 (inst.instruction);
8483 inst.instruction = (inst.instruction & 0xe1ffffff)
8484 | 0x10000000;
8485 if (flags)
8486 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8487 else
8488 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8489 }
dc4503c6
PB
8490 inst.instruction |= Rd << 8;
8491 inst.instruction |= Rs << 16;
0110f2b8 8492 }
b99bd4ef 8493 }
c19d1205
ZW
8494 else
8495 {
8496 Rn = inst.operands[2].reg;
8497 /* See if we can do this with a 16-bit instruction. */
8498 if (!inst.operands[2].shifted && inst.size_req != 4)
8499 {
e27ec89e
PB
8500 if (Rd > 7 || Rs > 7 || Rn > 7)
8501 narrow = FALSE;
8502
8503 if (narrow)
c19d1205 8504 {
e27ec89e
PB
8505 inst.instruction = ((inst.instruction == T_MNEM_adds
8506 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8507 ? T_OPCODE_ADD_R3
8508 : T_OPCODE_SUB_R3);
8509 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8510 return;
8511 }
b99bd4ef 8512
c19d1205
ZW
8513 if (inst.instruction == T_MNEM_add)
8514 {
8515 if (Rd == Rs)
8516 {
8517 inst.instruction = T_OPCODE_ADD_HI;
8518 inst.instruction |= (Rd & 8) << 4;
8519 inst.instruction |= (Rd & 7);
8520 inst.instruction |= Rn << 3;
8521 return;
8522 }
8523 /* ... because addition is commutative! */
8524 else if (Rd == Rn)
8525 {
8526 inst.instruction = T_OPCODE_ADD_HI;
8527 inst.instruction |= (Rd & 8) << 4;
8528 inst.instruction |= (Rd & 7);
8529 inst.instruction |= Rs << 3;
8530 return;
8531 }
8532 }
8533 }
8534 /* If we get here, it can't be done in 16 bits. */
8535 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8536 _("shift must be constant"));
8537 inst.instruction = THUMB_OP32 (inst.instruction);
8538 inst.instruction |= Rd << 8;
8539 inst.instruction |= Rs << 16;
8540 encode_thumb32_shifted_operand (2);
8541 }
8542 }
8543 else
8544 {
8545 constraint (inst.instruction == T_MNEM_adds
8546 || inst.instruction == T_MNEM_subs,
8547 BAD_THUMB32);
b99bd4ef 8548
c19d1205 8549 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8550 {
c19d1205
ZW
8551 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8552 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8553 BAD_HIREG);
8554
8555 inst.instruction = (inst.instruction == T_MNEM_add
8556 ? 0x0000 : 0x8000);
8557 inst.instruction |= (Rd << 4) | Rs;
8558 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8559 return;
8560 }
8561
c19d1205
ZW
8562 Rn = inst.operands[2].reg;
8563 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8564
c19d1205
ZW
8565 /* We now have Rd, Rs, and Rn set to registers. */
8566 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8567 {
c19d1205
ZW
8568 /* Can't do this for SUB. */
8569 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8570 inst.instruction = T_OPCODE_ADD_HI;
8571 inst.instruction |= (Rd & 8) << 4;
8572 inst.instruction |= (Rd & 7);
8573 if (Rs == Rd)
8574 inst.instruction |= Rn << 3;
8575 else if (Rn == Rd)
8576 inst.instruction |= Rs << 3;
8577 else
8578 constraint (1, _("dest must overlap one source register"));
8579 }
8580 else
8581 {
8582 inst.instruction = (inst.instruction == T_MNEM_add
8583 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8584 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8585 }
b99bd4ef 8586 }
b99bd4ef
NC
8587}
8588
c19d1205
ZW
8589static void
8590do_t_adr (void)
8591{
0110f2b8
PB
8592 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8593 {
8594 /* Defer to section relaxation. */
8595 inst.relax = inst.instruction;
8596 inst.instruction = THUMB_OP16 (inst.instruction);
8597 inst.instruction |= inst.operands[0].reg << 4;
8598 }
8599 else if (unified_syntax && inst.size_req != 2)
e9f89963 8600 {
0110f2b8 8601 /* Generate a 32-bit opcode. */
e9f89963
PB
8602 inst.instruction = THUMB_OP32 (inst.instruction);
8603 inst.instruction |= inst.operands[0].reg << 8;
8604 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8605 inst.reloc.pc_rel = 1;
8606 }
8607 else
8608 {
0110f2b8 8609 /* Generate a 16-bit opcode. */
e9f89963
PB
8610 inst.instruction = THUMB_OP16 (inst.instruction);
8611 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8612 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8613 inst.reloc.pc_rel = 1;
b99bd4ef 8614
e9f89963
PB
8615 inst.instruction |= inst.operands[0].reg << 4;
8616 }
c19d1205 8617}
b99bd4ef 8618
c19d1205
ZW
8619/* Arithmetic instructions for which there is just one 16-bit
8620 instruction encoding, and it allows only two low registers.
8621 For maximal compatibility with ARM syntax, we allow three register
8622 operands even when Thumb-32 instructions are not available, as long
8623 as the first two are identical. For instance, both "sbc r0,r1" and
8624 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8625static void
c19d1205 8626do_t_arit3 (void)
b99bd4ef 8627{
c19d1205 8628 int Rd, Rs, Rn;
b99bd4ef 8629
c19d1205
ZW
8630 Rd = inst.operands[0].reg;
8631 Rs = (inst.operands[1].present
8632 ? inst.operands[1].reg /* Rd, Rs, foo */
8633 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8634 Rn = inst.operands[2].reg;
b99bd4ef 8635
c19d1205 8636 if (unified_syntax)
b99bd4ef 8637 {
c19d1205
ZW
8638 if (!inst.operands[2].isreg)
8639 {
8640 /* For an immediate, we always generate a 32-bit opcode;
8641 section relaxation will shrink it later if possible. */
8642 inst.instruction = THUMB_OP32 (inst.instruction);
8643 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8644 inst.instruction |= Rd << 8;
8645 inst.instruction |= Rs << 16;
8646 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8647 }
8648 else
8649 {
e27ec89e
PB
8650 bfd_boolean narrow;
8651
c19d1205 8652 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8653 if (THUMB_SETS_FLAGS (inst.instruction))
8654 narrow = current_it_mask == 0;
8655 else
8656 narrow = current_it_mask != 0;
8657
8658 if (Rd > 7 || Rn > 7 || Rs > 7)
8659 narrow = FALSE;
8660 if (inst.operands[2].shifted)
8661 narrow = FALSE;
8662 if (inst.size_req == 4)
8663 narrow = FALSE;
8664
8665 if (narrow
c19d1205
ZW
8666 && Rd == Rs)
8667 {
8668 inst.instruction = THUMB_OP16 (inst.instruction);
8669 inst.instruction |= Rd;
8670 inst.instruction |= Rn << 3;
8671 return;
8672 }
b99bd4ef 8673
c19d1205
ZW
8674 /* If we get here, it can't be done in 16 bits. */
8675 constraint (inst.operands[2].shifted
8676 && inst.operands[2].immisreg,
8677 _("shift must be constant"));
8678 inst.instruction = THUMB_OP32 (inst.instruction);
8679 inst.instruction |= Rd << 8;
8680 inst.instruction |= Rs << 16;
8681 encode_thumb32_shifted_operand (2);
8682 }
a737bd4d 8683 }
c19d1205 8684 else
b99bd4ef 8685 {
c19d1205
ZW
8686 /* On its face this is a lie - the instruction does set the
8687 flags. However, the only supported mnemonic in this mode
8688 says it doesn't. */
8689 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8690
c19d1205
ZW
8691 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8692 _("unshifted register required"));
8693 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8694 constraint (Rd != Rs,
8695 _("dest and source1 must be the same register"));
a737bd4d 8696
c19d1205
ZW
8697 inst.instruction = THUMB_OP16 (inst.instruction);
8698 inst.instruction |= Rd;
8699 inst.instruction |= Rn << 3;
b99bd4ef 8700 }
a737bd4d 8701}
b99bd4ef 8702
c19d1205
ZW
8703/* Similarly, but for instructions where the arithmetic operation is
8704 commutative, so we can allow either of them to be different from
8705 the destination operand in a 16-bit instruction. For instance, all
8706 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8707 accepted. */
8708static void
8709do_t_arit3c (void)
a737bd4d 8710{
c19d1205 8711 int Rd, Rs, Rn;
b99bd4ef 8712
c19d1205
ZW
8713 Rd = inst.operands[0].reg;
8714 Rs = (inst.operands[1].present
8715 ? inst.operands[1].reg /* Rd, Rs, foo */
8716 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8717 Rn = inst.operands[2].reg;
a737bd4d 8718
c19d1205 8719 if (unified_syntax)
a737bd4d 8720 {
c19d1205 8721 if (!inst.operands[2].isreg)
b99bd4ef 8722 {
c19d1205
ZW
8723 /* For an immediate, we always generate a 32-bit opcode;
8724 section relaxation will shrink it later if possible. */
8725 inst.instruction = THUMB_OP32 (inst.instruction);
8726 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8727 inst.instruction |= Rd << 8;
8728 inst.instruction |= Rs << 16;
8729 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8730 }
c19d1205 8731 else
a737bd4d 8732 {
e27ec89e
PB
8733 bfd_boolean narrow;
8734
c19d1205 8735 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8736 if (THUMB_SETS_FLAGS (inst.instruction))
8737 narrow = current_it_mask == 0;
8738 else
8739 narrow = current_it_mask != 0;
8740
8741 if (Rd > 7 || Rn > 7 || Rs > 7)
8742 narrow = FALSE;
8743 if (inst.operands[2].shifted)
8744 narrow = FALSE;
8745 if (inst.size_req == 4)
8746 narrow = FALSE;
8747
8748 if (narrow)
a737bd4d 8749 {
c19d1205 8750 if (Rd == Rs)
a737bd4d 8751 {
c19d1205
ZW
8752 inst.instruction = THUMB_OP16 (inst.instruction);
8753 inst.instruction |= Rd;
8754 inst.instruction |= Rn << 3;
8755 return;
a737bd4d 8756 }
c19d1205 8757 if (Rd == Rn)
a737bd4d 8758 {
c19d1205
ZW
8759 inst.instruction = THUMB_OP16 (inst.instruction);
8760 inst.instruction |= Rd;
8761 inst.instruction |= Rs << 3;
8762 return;
a737bd4d
NC
8763 }
8764 }
c19d1205
ZW
8765
8766 /* If we get here, it can't be done in 16 bits. */
8767 constraint (inst.operands[2].shifted
8768 && inst.operands[2].immisreg,
8769 _("shift must be constant"));
8770 inst.instruction = THUMB_OP32 (inst.instruction);
8771 inst.instruction |= Rd << 8;
8772 inst.instruction |= Rs << 16;
8773 encode_thumb32_shifted_operand (2);
a737bd4d 8774 }
b99bd4ef 8775 }
c19d1205
ZW
8776 else
8777 {
8778 /* On its face this is a lie - the instruction does set the
8779 flags. However, the only supported mnemonic in this mode
8780 says it doesn't. */
8781 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8782
c19d1205
ZW
8783 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8784 _("unshifted register required"));
8785 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8786
8787 inst.instruction = THUMB_OP16 (inst.instruction);
8788 inst.instruction |= Rd;
8789
8790 if (Rd == Rs)
8791 inst.instruction |= Rn << 3;
8792 else if (Rd == Rn)
8793 inst.instruction |= Rs << 3;
8794 else
8795 constraint (1, _("dest must overlap one source register"));
8796 }
a737bd4d
NC
8797}
8798
62b3e311
PB
8799static void
8800do_t_barrier (void)
8801{
8802 if (inst.operands[0].present)
8803 {
8804 constraint ((inst.instruction & 0xf0) != 0x40
8805 && inst.operands[0].imm != 0xf,
8806 "bad barrier type");
8807 inst.instruction |= inst.operands[0].imm;
8808 }
8809 else
8810 inst.instruction |= 0xf;
8811}
8812
c19d1205
ZW
8813static void
8814do_t_bfc (void)
a737bd4d 8815{
c19d1205
ZW
8816 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8817 constraint (msb > 32, _("bit-field extends past end of register"));
8818 /* The instruction encoding stores the LSB and MSB,
8819 not the LSB and width. */
8820 inst.instruction |= inst.operands[0].reg << 8;
8821 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8822 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8823 inst.instruction |= msb - 1;
b99bd4ef
NC
8824}
8825
c19d1205
ZW
8826static void
8827do_t_bfi (void)
b99bd4ef 8828{
c19d1205 8829 unsigned int msb;
b99bd4ef 8830
c19d1205
ZW
8831 /* #0 in second position is alternative syntax for bfc, which is
8832 the same instruction but with REG_PC in the Rm field. */
8833 if (!inst.operands[1].isreg)
8834 inst.operands[1].reg = REG_PC;
b99bd4ef 8835
c19d1205
ZW
8836 msb = inst.operands[2].imm + inst.operands[3].imm;
8837 constraint (msb > 32, _("bit-field extends past end of register"));
8838 /* The instruction encoding stores the LSB and MSB,
8839 not the LSB and width. */
8840 inst.instruction |= inst.operands[0].reg << 8;
8841 inst.instruction |= inst.operands[1].reg << 16;
8842 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8843 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8844 inst.instruction |= msb - 1;
b99bd4ef
NC
8845}
8846
c19d1205
ZW
8847static void
8848do_t_bfx (void)
b99bd4ef 8849{
c19d1205
ZW
8850 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8851 _("bit-field extends past end of register"));
8852 inst.instruction |= inst.operands[0].reg << 8;
8853 inst.instruction |= inst.operands[1].reg << 16;
8854 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8855 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8856 inst.instruction |= inst.operands[3].imm - 1;
8857}
b99bd4ef 8858
c19d1205
ZW
8859/* ARM V5 Thumb BLX (argument parse)
8860 BLX <target_addr> which is BLX(1)
8861 BLX <Rm> which is BLX(2)
8862 Unfortunately, there are two different opcodes for this mnemonic.
8863 So, the insns[].value is not used, and the code here zaps values
8864 into inst.instruction.
b99bd4ef 8865
c19d1205
ZW
8866 ??? How to take advantage of the additional two bits of displacement
8867 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8868
c19d1205
ZW
8869static void
8870do_t_blx (void)
8871{
dfa9f0d5 8872 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8873 if (inst.operands[0].isreg)
8874 /* We have a register, so this is BLX(2). */
8875 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8876 else
8877 {
c19d1205 8878 /* No register. This must be BLX(1). */
2fc8bdac 8879 inst.instruction = 0xf000e800;
39b41c9c
PB
8880#ifdef OBJ_ELF
8881 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8882 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8883 else
8884#endif
8885 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8886 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8887 }
8888}
8889
c19d1205
ZW
8890static void
8891do_t_branch (void)
b99bd4ef 8892{
0110f2b8 8893 int opcode;
dfa9f0d5
PB
8894 int cond;
8895
8896 if (current_it_mask)
8897 {
8898 /* Conditional branches inside IT blocks are encoded as unconditional
8899 branches. */
8900 cond = COND_ALWAYS;
8901 /* A branch must be the last instruction in an IT block. */
8902 constraint (current_it_mask != 0x10, BAD_BRANCH);
8903 }
8904 else
8905 cond = inst.cond;
8906
8907 if (cond != COND_ALWAYS)
0110f2b8
PB
8908 opcode = T_MNEM_bcond;
8909 else
8910 opcode = inst.instruction;
8911
8912 if (unified_syntax && inst.size_req == 4)
c19d1205 8913 {
0110f2b8 8914 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8915 if (cond == COND_ALWAYS)
0110f2b8 8916 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8917 else
8918 {
dfa9f0d5
PB
8919 assert (cond != 0xF);
8920 inst.instruction |= cond << 22;
c19d1205
ZW
8921 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8922 }
8923 }
b99bd4ef
NC
8924 else
8925 {
0110f2b8 8926 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8927 if (cond == COND_ALWAYS)
c19d1205
ZW
8928 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8929 else
b99bd4ef 8930 {
dfa9f0d5 8931 inst.instruction |= cond << 8;
c19d1205 8932 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8933 }
0110f2b8
PB
8934 /* Allow section relaxation. */
8935 if (unified_syntax && inst.size_req != 2)
8936 inst.relax = opcode;
b99bd4ef 8937 }
c19d1205
ZW
8938
8939 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8940}
8941
8942static void
c19d1205 8943do_t_bkpt (void)
b99bd4ef 8944{
dfa9f0d5
PB
8945 constraint (inst.cond != COND_ALWAYS,
8946 _("instruction is always unconditional"));
c19d1205 8947 if (inst.operands[0].present)
b99bd4ef 8948 {
c19d1205
ZW
8949 constraint (inst.operands[0].imm > 255,
8950 _("immediate value out of range"));
8951 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8952 }
b99bd4ef
NC
8953}
8954
8955static void
c19d1205 8956do_t_branch23 (void)
b99bd4ef 8957{
dfa9f0d5 8958 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8959 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8960 inst.reloc.pc_rel = 1;
8961
c19d1205
ZW
8962 /* If the destination of the branch is a defined symbol which does not have
8963 the THUMB_FUNC attribute, then we must be calling a function which has
8964 the (interfacearm) attribute. We look for the Thumb entry point to that
8965 function and change the branch to refer to that function instead. */
8966 if ( inst.reloc.exp.X_op == O_symbol
8967 && inst.reloc.exp.X_add_symbol != NULL
8968 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8969 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8970 inst.reloc.exp.X_add_symbol =
8971 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8972}
8973
8974static void
c19d1205 8975do_t_bx (void)
90e4755a 8976{
dfa9f0d5 8977 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8978 inst.instruction |= inst.operands[0].reg << 3;
8979 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8980 should cause the alignment to be checked once it is known. This is
8981 because BX PC only works if the instruction is word aligned. */
8982}
90e4755a 8983
c19d1205
ZW
8984static void
8985do_t_bxj (void)
8986{
dfa9f0d5 8987 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8988 if (inst.operands[0].reg == REG_PC)
8989 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8990
c19d1205 8991 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8992}
8993
8994static void
c19d1205 8995do_t_clz (void)
90e4755a 8996{
c19d1205
ZW
8997 inst.instruction |= inst.operands[0].reg << 8;
8998 inst.instruction |= inst.operands[1].reg << 16;
8999 inst.instruction |= inst.operands[1].reg;
9000}
90e4755a 9001
dfa9f0d5
PB
9002static void
9003do_t_cps (void)
9004{
9005 constraint (current_it_mask, BAD_NOT_IT);
9006 inst.instruction |= inst.operands[0].imm;
9007}
9008
c19d1205
ZW
9009static void
9010do_t_cpsi (void)
9011{
dfa9f0d5 9012 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 9013 if (unified_syntax
62b3e311
PB
9014 && (inst.operands[1].present || inst.size_req == 4)
9015 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9016 {
c19d1205
ZW
9017 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9018 inst.instruction = 0xf3af8000;
9019 inst.instruction |= imod << 9;
9020 inst.instruction |= inst.operands[0].imm << 5;
9021 if (inst.operands[1].present)
9022 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9023 }
c19d1205 9024 else
90e4755a 9025 {
62b3e311
PB
9026 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9027 && (inst.operands[0].imm & 4),
9028 _("selected processor does not support 'A' form "
9029 "of this instruction"));
9030 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9031 _("Thumb does not support the 2-argument "
9032 "form of this instruction"));
9033 inst.instruction |= inst.operands[0].imm;
90e4755a 9034 }
90e4755a
RE
9035}
9036
c19d1205
ZW
9037/* THUMB CPY instruction (argument parse). */
9038
90e4755a 9039static void
c19d1205 9040do_t_cpy (void)
90e4755a 9041{
c19d1205 9042 if (inst.size_req == 4)
90e4755a 9043 {
c19d1205
ZW
9044 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9045 inst.instruction |= inst.operands[0].reg << 8;
9046 inst.instruction |= inst.operands[1].reg;
90e4755a 9047 }
c19d1205 9048 else
90e4755a 9049 {
c19d1205
ZW
9050 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9051 inst.instruction |= (inst.operands[0].reg & 0x7);
9052 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9053 }
90e4755a
RE
9054}
9055
90e4755a 9056static void
25fe350b 9057do_t_cbz (void)
90e4755a 9058{
dfa9f0d5 9059 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9060 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9061 inst.instruction |= inst.operands[0].reg;
9062 inst.reloc.pc_rel = 1;
9063 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9064}
90e4755a 9065
62b3e311
PB
9066static void
9067do_t_dbg (void)
9068{
9069 inst.instruction |= inst.operands[0].imm;
9070}
9071
9072static void
9073do_t_div (void)
9074{
9075 if (!inst.operands[1].present)
9076 inst.operands[1].reg = inst.operands[0].reg;
9077 inst.instruction |= inst.operands[0].reg << 8;
9078 inst.instruction |= inst.operands[1].reg << 16;
9079 inst.instruction |= inst.operands[2].reg;
9080}
9081
c19d1205
ZW
9082static void
9083do_t_hint (void)
9084{
9085 if (unified_syntax && inst.size_req == 4)
9086 inst.instruction = THUMB_OP32 (inst.instruction);
9087 else
9088 inst.instruction = THUMB_OP16 (inst.instruction);
9089}
90e4755a 9090
c19d1205
ZW
9091static void
9092do_t_it (void)
9093{
9094 unsigned int cond = inst.operands[0].imm;
e27ec89e 9095
dfa9f0d5 9096 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
9097 current_it_mask = (inst.instruction & 0xf) | 0x10;
9098 current_cc = cond;
9099
9100 /* If the condition is a negative condition, invert the mask. */
c19d1205 9101 if ((cond & 0x1) == 0x0)
90e4755a 9102 {
c19d1205 9103 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9104
c19d1205
ZW
9105 if ((mask & 0x7) == 0)
9106 /* no conversion needed */;
9107 else if ((mask & 0x3) == 0)
e27ec89e
PB
9108 mask ^= 0x8;
9109 else if ((mask & 0x1) == 0)
9110 mask ^= 0xC;
c19d1205 9111 else
e27ec89e 9112 mask ^= 0xE;
90e4755a 9113
e27ec89e
PB
9114 inst.instruction &= 0xfff0;
9115 inst.instruction |= mask;
c19d1205 9116 }
90e4755a 9117
c19d1205
ZW
9118 inst.instruction |= cond << 4;
9119}
90e4755a 9120
3c707909
PB
9121/* Helper function used for both push/pop and ldm/stm. */
9122static void
9123encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9124{
9125 bfd_boolean load;
9126
9127 load = (inst.instruction & (1 << 20)) != 0;
9128
9129 if (mask & (1 << 13))
9130 inst.error = _("SP not allowed in register list");
9131 if (load)
9132 {
9133 if (mask & (1 << 14)
9134 && mask & (1 << 15))
9135 inst.error = _("LR and PC should not both be in register list");
9136
9137 if ((mask & (1 << base)) != 0
9138 && writeback)
9139 as_warn (_("base register should not be in register list "
9140 "when written back"));
9141 }
9142 else
9143 {
9144 if (mask & (1 << 15))
9145 inst.error = _("PC not allowed in register list");
9146
9147 if (mask & (1 << base))
9148 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9149 }
9150
9151 if ((mask & (mask - 1)) == 0)
9152 {
9153 /* Single register transfers implemented as str/ldr. */
9154 if (writeback)
9155 {
9156 if (inst.instruction & (1 << 23))
9157 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9158 else
9159 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9160 }
9161 else
9162 {
9163 if (inst.instruction & (1 << 23))
9164 inst.instruction = 0x00800000; /* ia -> [base] */
9165 else
9166 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9167 }
9168
9169 inst.instruction |= 0xf8400000;
9170 if (load)
9171 inst.instruction |= 0x00100000;
9172
9173 mask = ffs(mask) - 1;
9174 mask <<= 12;
9175 }
9176 else if (writeback)
9177 inst.instruction |= WRITE_BACK;
9178
9179 inst.instruction |= mask;
9180 inst.instruction |= base << 16;
9181}
9182
c19d1205
ZW
9183static void
9184do_t_ldmstm (void)
9185{
9186 /* This really doesn't seem worth it. */
9187 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9188 _("expression too complex"));
9189 constraint (inst.operands[1].writeback,
9190 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9191
c19d1205
ZW
9192 if (unified_syntax)
9193 {
3c707909
PB
9194 bfd_boolean narrow;
9195 unsigned mask;
9196
9197 narrow = FALSE;
c19d1205
ZW
9198 /* See if we can use a 16-bit instruction. */
9199 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9200 && inst.size_req != 4
3c707909 9201 && !(inst.operands[1].imm & ~0xff))
90e4755a 9202 {
3c707909 9203 mask = 1 << inst.operands[0].reg;
90e4755a 9204
3c707909
PB
9205 if (inst.operands[0].reg <= 7
9206 && (inst.instruction == T_MNEM_stmia
9207 ? inst.operands[0].writeback
9208 : (inst.operands[0].writeback
9209 == !(inst.operands[1].imm & mask))))
90e4755a 9210 {
3c707909
PB
9211 if (inst.instruction == T_MNEM_stmia
9212 && (inst.operands[1].imm & mask)
9213 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9214 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9215 inst.operands[0].reg);
3c707909
PB
9216
9217 inst.instruction = THUMB_OP16 (inst.instruction);
9218 inst.instruction |= inst.operands[0].reg << 8;
9219 inst.instruction |= inst.operands[1].imm;
9220 narrow = TRUE;
90e4755a 9221 }
3c707909
PB
9222 else if (inst.operands[0] .reg == REG_SP
9223 && inst.operands[0].writeback)
90e4755a 9224 {
3c707909
PB
9225 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9226 ? T_MNEM_push : T_MNEM_pop);
9227 inst.instruction |= inst.operands[1].imm;
9228 narrow = TRUE;
90e4755a 9229 }
3c707909
PB
9230 }
9231
9232 if (!narrow)
9233 {
c19d1205
ZW
9234 if (inst.instruction < 0xffff)
9235 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909
PB
9236
9237 encode_thumb2_ldmstm(inst.operands[0].reg, inst.operands[1].imm,
9238 inst.operands[0].writeback);
90e4755a
RE
9239 }
9240 }
c19d1205 9241 else
90e4755a 9242 {
c19d1205
ZW
9243 constraint (inst.operands[0].reg > 7
9244 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9245 constraint (inst.instruction != T_MNEM_ldmia
9246 && inst.instruction != T_MNEM_stmia,
9247 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9248 if (inst.instruction == T_MNEM_stmia)
f03698e6 9249 {
c19d1205
ZW
9250 if (!inst.operands[0].writeback)
9251 as_warn (_("this instruction will write back the base register"));
9252 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9253 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9254 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9255 inst.operands[0].reg);
f03698e6 9256 }
c19d1205 9257 else
90e4755a 9258 {
c19d1205
ZW
9259 if (!inst.operands[0].writeback
9260 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9261 as_warn (_("this instruction will write back the base register"));
9262 else if (inst.operands[0].writeback
9263 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9264 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9265 }
9266
c19d1205
ZW
9267 inst.instruction = THUMB_OP16 (inst.instruction);
9268 inst.instruction |= inst.operands[0].reg << 8;
9269 inst.instruction |= inst.operands[1].imm;
9270 }
9271}
e28cd48c 9272
c19d1205
ZW
9273static void
9274do_t_ldrex (void)
9275{
9276 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9277 || inst.operands[1].postind || inst.operands[1].writeback
9278 || inst.operands[1].immisreg || inst.operands[1].shifted
9279 || inst.operands[1].negative,
01cfc07f 9280 BAD_ADDR_MODE);
e28cd48c 9281
c19d1205
ZW
9282 inst.instruction |= inst.operands[0].reg << 12;
9283 inst.instruction |= inst.operands[1].reg << 16;
9284 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9285}
e28cd48c 9286
c19d1205
ZW
9287static void
9288do_t_ldrexd (void)
9289{
9290 if (!inst.operands[1].present)
1cac9012 9291 {
c19d1205
ZW
9292 constraint (inst.operands[0].reg == REG_LR,
9293 _("r14 not allowed as first register "
9294 "when second register is omitted"));
9295 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9296 }
c19d1205
ZW
9297 constraint (inst.operands[0].reg == inst.operands[1].reg,
9298 BAD_OVERLAP);
b99bd4ef 9299
c19d1205
ZW
9300 inst.instruction |= inst.operands[0].reg << 12;
9301 inst.instruction |= inst.operands[1].reg << 8;
9302 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9303}
9304
9305static void
c19d1205 9306do_t_ldst (void)
b99bd4ef 9307{
0110f2b8
PB
9308 unsigned long opcode;
9309 int Rn;
9310
9311 opcode = inst.instruction;
c19d1205 9312 if (unified_syntax)
b99bd4ef 9313 {
53365c0d
PB
9314 if (!inst.operands[1].isreg)
9315 {
9316 if (opcode <= 0xffff)
9317 inst.instruction = THUMB_OP32 (opcode);
9318 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9319 return;
9320 }
0110f2b8
PB
9321 if (inst.operands[1].isreg
9322 && !inst.operands[1].writeback
c19d1205
ZW
9323 && !inst.operands[1].shifted && !inst.operands[1].postind
9324 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9325 && opcode <= 0xffff
9326 && inst.size_req != 4)
c19d1205 9327 {
0110f2b8
PB
9328 /* Insn may have a 16-bit form. */
9329 Rn = inst.operands[1].reg;
9330 if (inst.operands[1].immisreg)
9331 {
9332 inst.instruction = THUMB_OP16 (opcode);
9333 /* [Rn, Ri] */
9334 if (Rn <= 7 && inst.operands[1].imm <= 7)
9335 goto op16;
9336 }
9337 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9338 && opcode != T_MNEM_ldrsb)
9339 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9340 || (Rn == REG_SP && opcode == T_MNEM_str))
9341 {
9342 /* [Rn, #const] */
9343 if (Rn > 7)
9344 {
9345 if (Rn == REG_PC)
9346 {
9347 if (inst.reloc.pc_rel)
9348 opcode = T_MNEM_ldr_pc2;
9349 else
9350 opcode = T_MNEM_ldr_pc;
9351 }
9352 else
9353 {
9354 if (opcode == T_MNEM_ldr)
9355 opcode = T_MNEM_ldr_sp;
9356 else
9357 opcode = T_MNEM_str_sp;
9358 }
9359 inst.instruction = inst.operands[0].reg << 8;
9360 }
9361 else
9362 {
9363 inst.instruction = inst.operands[0].reg;
9364 inst.instruction |= inst.operands[1].reg << 3;
9365 }
9366 inst.instruction |= THUMB_OP16 (opcode);
9367 if (inst.size_req == 2)
9368 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9369 else
9370 inst.relax = opcode;
9371 return;
9372 }
c19d1205 9373 }
0110f2b8
PB
9374 /* Definitely a 32-bit variant. */
9375 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9376 inst.instruction |= inst.operands[0].reg << 12;
9377 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9378 return;
9379 }
9380
c19d1205
ZW
9381 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9382
9383 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9384 {
c19d1205
ZW
9385 /* Only [Rn,Rm] is acceptable. */
9386 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9387 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9388 || inst.operands[1].postind || inst.operands[1].shifted
9389 || inst.operands[1].negative,
9390 _("Thumb does not support this addressing mode"));
9391 inst.instruction = THUMB_OP16 (inst.instruction);
9392 goto op16;
b99bd4ef 9393 }
c19d1205
ZW
9394
9395 inst.instruction = THUMB_OP16 (inst.instruction);
9396 if (!inst.operands[1].isreg)
9397 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9398 return;
b99bd4ef 9399
c19d1205
ZW
9400 constraint (!inst.operands[1].preind
9401 || inst.operands[1].shifted
9402 || inst.operands[1].writeback,
9403 _("Thumb does not support this addressing mode"));
9404 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9405 {
c19d1205
ZW
9406 constraint (inst.instruction & 0x0600,
9407 _("byte or halfword not valid for base register"));
9408 constraint (inst.operands[1].reg == REG_PC
9409 && !(inst.instruction & THUMB_LOAD_BIT),
9410 _("r15 based store not allowed"));
9411 constraint (inst.operands[1].immisreg,
9412 _("invalid base register for register offset"));
b99bd4ef 9413
c19d1205
ZW
9414 if (inst.operands[1].reg == REG_PC)
9415 inst.instruction = T_OPCODE_LDR_PC;
9416 else if (inst.instruction & THUMB_LOAD_BIT)
9417 inst.instruction = T_OPCODE_LDR_SP;
9418 else
9419 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9420
c19d1205
ZW
9421 inst.instruction |= inst.operands[0].reg << 8;
9422 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9423 return;
9424 }
90e4755a 9425
c19d1205
ZW
9426 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9427 if (!inst.operands[1].immisreg)
9428 {
9429 /* Immediate offset. */
9430 inst.instruction |= inst.operands[0].reg;
9431 inst.instruction |= inst.operands[1].reg << 3;
9432 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9433 return;
9434 }
90e4755a 9435
c19d1205
ZW
9436 /* Register offset. */
9437 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9438 constraint (inst.operands[1].negative,
9439 _("Thumb does not support this addressing mode"));
90e4755a 9440
c19d1205
ZW
9441 op16:
9442 switch (inst.instruction)
9443 {
9444 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9445 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9446 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9447 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9448 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9449 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9450 case 0x5600 /* ldrsb */:
9451 case 0x5e00 /* ldrsh */: break;
9452 default: abort ();
9453 }
90e4755a 9454
c19d1205
ZW
9455 inst.instruction |= inst.operands[0].reg;
9456 inst.instruction |= inst.operands[1].reg << 3;
9457 inst.instruction |= inst.operands[1].imm << 6;
9458}
90e4755a 9459
c19d1205
ZW
9460static void
9461do_t_ldstd (void)
9462{
9463 if (!inst.operands[1].present)
b99bd4ef 9464 {
c19d1205
ZW
9465 inst.operands[1].reg = inst.operands[0].reg + 1;
9466 constraint (inst.operands[0].reg == REG_LR,
9467 _("r14 not allowed here"));
b99bd4ef 9468 }
c19d1205
ZW
9469 inst.instruction |= inst.operands[0].reg << 12;
9470 inst.instruction |= inst.operands[1].reg << 8;
9471 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9472
b99bd4ef
NC
9473}
9474
c19d1205
ZW
9475static void
9476do_t_ldstt (void)
9477{
9478 inst.instruction |= inst.operands[0].reg << 12;
9479 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9480}
a737bd4d 9481
b99bd4ef 9482static void
c19d1205 9483do_t_mla (void)
b99bd4ef 9484{
c19d1205
ZW
9485 inst.instruction |= inst.operands[0].reg << 8;
9486 inst.instruction |= inst.operands[1].reg << 16;
9487 inst.instruction |= inst.operands[2].reg;
9488 inst.instruction |= inst.operands[3].reg << 12;
9489}
b99bd4ef 9490
c19d1205
ZW
9491static void
9492do_t_mlal (void)
9493{
9494 inst.instruction |= inst.operands[0].reg << 12;
9495 inst.instruction |= inst.operands[1].reg << 8;
9496 inst.instruction |= inst.operands[2].reg << 16;
9497 inst.instruction |= inst.operands[3].reg;
9498}
b99bd4ef 9499
c19d1205
ZW
9500static void
9501do_t_mov_cmp (void)
9502{
9503 if (unified_syntax)
b99bd4ef 9504 {
c19d1205
ZW
9505 int r0off = (inst.instruction == T_MNEM_mov
9506 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9507 unsigned long opcode;
3d388997
PB
9508 bfd_boolean narrow;
9509 bfd_boolean low_regs;
9510
9511 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9512 opcode = inst.instruction;
3d388997 9513 if (current_it_mask)
0110f2b8 9514 narrow = opcode != T_MNEM_movs;
3d388997 9515 else
0110f2b8 9516 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9517 if (inst.size_req == 4
9518 || inst.operands[1].shifted)
9519 narrow = FALSE;
9520
efd81785
PB
9521 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9522 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9523 && !inst.operands[1].shifted
9524 && inst.operands[0].reg == REG_PC
9525 && inst.operands[1].reg == REG_LR)
9526 {
9527 inst.instruction = T2_SUBS_PC_LR;
9528 return;
9529 }
9530
c19d1205
ZW
9531 if (!inst.operands[1].isreg)
9532 {
0110f2b8
PB
9533 /* Immediate operand. */
9534 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9535 narrow = 0;
9536 if (low_regs && narrow)
9537 {
9538 inst.instruction = THUMB_OP16 (opcode);
9539 inst.instruction |= inst.operands[0].reg << 8;
9540 if (inst.size_req == 2)
9541 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9542 else
9543 inst.relax = opcode;
9544 }
9545 else
9546 {
9547 inst.instruction = THUMB_OP32 (inst.instruction);
9548 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9549 inst.instruction |= inst.operands[0].reg << r0off;
9550 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9551 }
c19d1205 9552 }
728ca7c9
PB
9553 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9554 && (inst.instruction == T_MNEM_mov
9555 || inst.instruction == T_MNEM_movs))
9556 {
9557 /* Register shifts are encoded as separate shift instructions. */
9558 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9559
9560 if (current_it_mask)
9561 narrow = !flags;
9562 else
9563 narrow = flags;
9564
9565 if (inst.size_req == 4)
9566 narrow = FALSE;
9567
9568 if (!low_regs || inst.operands[1].imm > 7)
9569 narrow = FALSE;
9570
9571 if (inst.operands[0].reg != inst.operands[1].reg)
9572 narrow = FALSE;
9573
9574 switch (inst.operands[1].shift_kind)
9575 {
9576 case SHIFT_LSL:
9577 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9578 break;
9579 case SHIFT_ASR:
9580 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9581 break;
9582 case SHIFT_LSR:
9583 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9584 break;
9585 case SHIFT_ROR:
9586 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9587 break;
9588 default:
9589 abort();
9590 }
9591
9592 inst.instruction = opcode;
9593 if (narrow)
9594 {
9595 inst.instruction |= inst.operands[0].reg;
9596 inst.instruction |= inst.operands[1].imm << 3;
9597 }
9598 else
9599 {
9600 if (flags)
9601 inst.instruction |= CONDS_BIT;
9602
9603 inst.instruction |= inst.operands[0].reg << 8;
9604 inst.instruction |= inst.operands[1].reg << 16;
9605 inst.instruction |= inst.operands[1].imm;
9606 }
9607 }
3d388997 9608 else if (!narrow)
c19d1205 9609 {
728ca7c9
PB
9610 /* Some mov with immediate shift have narrow variants.
9611 Register shifts are handled above. */
9612 if (low_regs && inst.operands[1].shifted
9613 && (inst.instruction == T_MNEM_mov
9614 || inst.instruction == T_MNEM_movs))
9615 {
9616 if (current_it_mask)
9617 narrow = (inst.instruction == T_MNEM_mov);
9618 else
9619 narrow = (inst.instruction == T_MNEM_movs);
9620 }
9621
9622 if (narrow)
9623 {
9624 switch (inst.operands[1].shift_kind)
9625 {
9626 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9627 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9628 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9629 default: narrow = FALSE; break;
9630 }
9631 }
9632
9633 if (narrow)
9634 {
9635 inst.instruction |= inst.operands[0].reg;
9636 inst.instruction |= inst.operands[1].reg << 3;
9637 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9638 }
9639 else
9640 {
9641 inst.instruction = THUMB_OP32 (inst.instruction);
9642 inst.instruction |= inst.operands[0].reg << r0off;
9643 encode_thumb32_shifted_operand (1);
9644 }
c19d1205
ZW
9645 }
9646 else
9647 switch (inst.instruction)
9648 {
9649 case T_MNEM_mov:
9650 inst.instruction = T_OPCODE_MOV_HR;
9651 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9652 inst.instruction |= (inst.operands[0].reg & 0x7);
9653 inst.instruction |= inst.operands[1].reg << 3;
9654 break;
b99bd4ef 9655
c19d1205
ZW
9656 case T_MNEM_movs:
9657 /* We know we have low registers at this point.
9658 Generate ADD Rd, Rs, #0. */
9659 inst.instruction = T_OPCODE_ADD_I3;
9660 inst.instruction |= inst.operands[0].reg;
9661 inst.instruction |= inst.operands[1].reg << 3;
9662 break;
9663
9664 case T_MNEM_cmp:
3d388997 9665 if (low_regs)
c19d1205
ZW
9666 {
9667 inst.instruction = T_OPCODE_CMP_LR;
9668 inst.instruction |= inst.operands[0].reg;
9669 inst.instruction |= inst.operands[1].reg << 3;
9670 }
9671 else
9672 {
9673 inst.instruction = T_OPCODE_CMP_HR;
9674 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9675 inst.instruction |= (inst.operands[0].reg & 0x7);
9676 inst.instruction |= inst.operands[1].reg << 3;
9677 }
9678 break;
9679 }
b99bd4ef
NC
9680 return;
9681 }
9682
c19d1205
ZW
9683 inst.instruction = THUMB_OP16 (inst.instruction);
9684 if (inst.operands[1].isreg)
b99bd4ef 9685 {
c19d1205 9686 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9687 {
c19d1205
ZW
9688 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9689 since a MOV instruction produces unpredictable results. */
9690 if (inst.instruction == T_OPCODE_MOV_I8)
9691 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9692 else
c19d1205 9693 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9694
c19d1205
ZW
9695 inst.instruction |= inst.operands[0].reg;
9696 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9697 }
9698 else
9699 {
c19d1205
ZW
9700 if (inst.instruction == T_OPCODE_MOV_I8)
9701 inst.instruction = T_OPCODE_MOV_HR;
9702 else
9703 inst.instruction = T_OPCODE_CMP_HR;
9704 do_t_cpy ();
b99bd4ef
NC
9705 }
9706 }
c19d1205 9707 else
b99bd4ef 9708 {
c19d1205
ZW
9709 constraint (inst.operands[0].reg > 7,
9710 _("only lo regs allowed with immediate"));
9711 inst.instruction |= inst.operands[0].reg << 8;
9712 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9713 }
9714}
b99bd4ef 9715
c19d1205
ZW
9716static void
9717do_t_mov16 (void)
9718{
b6895b4f
PB
9719 bfd_vma imm;
9720 bfd_boolean top;
9721
9722 top = (inst.instruction & 0x00800000) != 0;
9723 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9724 {
9725 constraint (top, _(":lower16: not allowed this instruction"));
9726 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9727 }
9728 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9729 {
9730 constraint (!top, _(":upper16: not allowed this instruction"));
9731 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9732 }
9733
c19d1205 9734 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9735 if (inst.reloc.type == BFD_RELOC_UNUSED)
9736 {
9737 imm = inst.reloc.exp.X_add_number;
9738 inst.instruction |= (imm & 0xf000) << 4;
9739 inst.instruction |= (imm & 0x0800) << 15;
9740 inst.instruction |= (imm & 0x0700) << 4;
9741 inst.instruction |= (imm & 0x00ff);
9742 }
c19d1205 9743}
b99bd4ef 9744
c19d1205
ZW
9745static void
9746do_t_mvn_tst (void)
9747{
9748 if (unified_syntax)
9749 {
9750 int r0off = (inst.instruction == T_MNEM_mvn
9751 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9752 bfd_boolean narrow;
9753
9754 if (inst.size_req == 4
9755 || inst.instruction > 0xffff
9756 || inst.operands[1].shifted
9757 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9758 narrow = FALSE;
9759 else if (inst.instruction == T_MNEM_cmn)
9760 narrow = TRUE;
9761 else if (THUMB_SETS_FLAGS (inst.instruction))
9762 narrow = (current_it_mask == 0);
9763 else
9764 narrow = (current_it_mask != 0);
9765
c19d1205 9766 if (!inst.operands[1].isreg)
b99bd4ef 9767 {
c19d1205
ZW
9768 /* For an immediate, we always generate a 32-bit opcode;
9769 section relaxation will shrink it later if possible. */
9770 if (inst.instruction < 0xffff)
9771 inst.instruction = THUMB_OP32 (inst.instruction);
9772 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9773 inst.instruction |= inst.operands[0].reg << r0off;
9774 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9775 }
c19d1205 9776 else
b99bd4ef 9777 {
c19d1205 9778 /* See if we can do this with a 16-bit instruction. */
3d388997 9779 if (narrow)
b99bd4ef 9780 {
c19d1205
ZW
9781 inst.instruction = THUMB_OP16 (inst.instruction);
9782 inst.instruction |= inst.operands[0].reg;
9783 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9784 }
c19d1205 9785 else
b99bd4ef 9786 {
c19d1205
ZW
9787 constraint (inst.operands[1].shifted
9788 && inst.operands[1].immisreg,
9789 _("shift must be constant"));
9790 if (inst.instruction < 0xffff)
9791 inst.instruction = THUMB_OP32 (inst.instruction);
9792 inst.instruction |= inst.operands[0].reg << r0off;
9793 encode_thumb32_shifted_operand (1);
b99bd4ef 9794 }
b99bd4ef
NC
9795 }
9796 }
9797 else
9798 {
c19d1205
ZW
9799 constraint (inst.instruction > 0xffff
9800 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9801 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9802 _("unshifted register required"));
9803 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9804 BAD_HIREG);
b99bd4ef 9805
c19d1205
ZW
9806 inst.instruction = THUMB_OP16 (inst.instruction);
9807 inst.instruction |= inst.operands[0].reg;
9808 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9809 }
b99bd4ef
NC
9810}
9811
b05fe5cf 9812static void
c19d1205 9813do_t_mrs (void)
b05fe5cf 9814{
62b3e311 9815 int flags;
037e8744
JB
9816
9817 if (do_vfp_nsyn_mrs () == SUCCESS)
9818 return;
9819
62b3e311
PB
9820 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9821 if (flags == 0)
9822 {
9823 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9824 _("selected processor does not support "
9825 "requested special purpose register"));
9826 }
9827 else
9828 {
9829 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9830 _("selected processor does not support "
9831 "requested special purpose register %x"));
9832 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9833 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9834 _("'CPSR' or 'SPSR' expected"));
9835 }
9836
c19d1205 9837 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9838 inst.instruction |= (flags & SPSR_BIT) >> 2;
9839 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9840}
b05fe5cf 9841
c19d1205
ZW
9842static void
9843do_t_msr (void)
9844{
62b3e311
PB
9845 int flags;
9846
037e8744
JB
9847 if (do_vfp_nsyn_msr () == SUCCESS)
9848 return;
9849
c19d1205
ZW
9850 constraint (!inst.operands[1].isreg,
9851 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9852 flags = inst.operands[0].imm;
9853 if (flags & ~0xff)
9854 {
9855 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9856 _("selected processor does not support "
9857 "requested special purpose register"));
9858 }
9859 else
9860 {
9861 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9862 _("selected processor does not support "
9863 "requested special purpose register"));
9864 flags |= PSR_f;
9865 }
9866 inst.instruction |= (flags & SPSR_BIT) >> 2;
9867 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9868 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9869 inst.instruction |= inst.operands[1].reg << 16;
9870}
b05fe5cf 9871
c19d1205
ZW
9872static void
9873do_t_mul (void)
9874{
9875 if (!inst.operands[2].present)
9876 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9877
c19d1205
ZW
9878 /* There is no 32-bit MULS and no 16-bit MUL. */
9879 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9880 {
c19d1205
ZW
9881 inst.instruction = THUMB_OP32 (inst.instruction);
9882 inst.instruction |= inst.operands[0].reg << 8;
9883 inst.instruction |= inst.operands[1].reg << 16;
9884 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9885 }
c19d1205 9886 else
b05fe5cf 9887 {
c19d1205
ZW
9888 constraint (!unified_syntax
9889 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9890 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9891 BAD_HIREG);
b05fe5cf 9892
c19d1205
ZW
9893 inst.instruction = THUMB_OP16 (inst.instruction);
9894 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9895
c19d1205
ZW
9896 if (inst.operands[0].reg == inst.operands[1].reg)
9897 inst.instruction |= inst.operands[2].reg << 3;
9898 else if (inst.operands[0].reg == inst.operands[2].reg)
9899 inst.instruction |= inst.operands[1].reg << 3;
9900 else
9901 constraint (1, _("dest must overlap one source register"));
9902 }
9903}
b05fe5cf 9904
c19d1205
ZW
9905static void
9906do_t_mull (void)
9907{
9908 inst.instruction |= inst.operands[0].reg << 12;
9909 inst.instruction |= inst.operands[1].reg << 8;
9910 inst.instruction |= inst.operands[2].reg << 16;
9911 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9912
c19d1205
ZW
9913 if (inst.operands[0].reg == inst.operands[1].reg)
9914 as_tsktsk (_("rdhi and rdlo must be different"));
9915}
b05fe5cf 9916
c19d1205
ZW
9917static void
9918do_t_nop (void)
9919{
9920 if (unified_syntax)
9921 {
9922 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9923 {
c19d1205
ZW
9924 inst.instruction = THUMB_OP32 (inst.instruction);
9925 inst.instruction |= inst.operands[0].imm;
9926 }
9927 else
9928 {
9929 inst.instruction = THUMB_OP16 (inst.instruction);
9930 inst.instruction |= inst.operands[0].imm << 4;
9931 }
9932 }
9933 else
9934 {
9935 constraint (inst.operands[0].present,
9936 _("Thumb does not support NOP with hints"));
9937 inst.instruction = 0x46c0;
9938 }
9939}
b05fe5cf 9940
c19d1205
ZW
9941static void
9942do_t_neg (void)
9943{
9944 if (unified_syntax)
9945 {
3d388997
PB
9946 bfd_boolean narrow;
9947
9948 if (THUMB_SETS_FLAGS (inst.instruction))
9949 narrow = (current_it_mask == 0);
9950 else
9951 narrow = (current_it_mask != 0);
9952 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9953 narrow = FALSE;
9954 if (inst.size_req == 4)
9955 narrow = FALSE;
9956
9957 if (!narrow)
c19d1205
ZW
9958 {
9959 inst.instruction = THUMB_OP32 (inst.instruction);
9960 inst.instruction |= inst.operands[0].reg << 8;
9961 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9962 }
9963 else
9964 {
c19d1205
ZW
9965 inst.instruction = THUMB_OP16 (inst.instruction);
9966 inst.instruction |= inst.operands[0].reg;
9967 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9968 }
9969 }
9970 else
9971 {
c19d1205
ZW
9972 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9973 BAD_HIREG);
9974 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9975
9976 inst.instruction = THUMB_OP16 (inst.instruction);
9977 inst.instruction |= inst.operands[0].reg;
9978 inst.instruction |= inst.operands[1].reg << 3;
9979 }
9980}
9981
9982static void
9983do_t_pkhbt (void)
9984{
9985 inst.instruction |= inst.operands[0].reg << 8;
9986 inst.instruction |= inst.operands[1].reg << 16;
9987 inst.instruction |= inst.operands[2].reg;
9988 if (inst.operands[3].present)
9989 {
9990 unsigned int val = inst.reloc.exp.X_add_number;
9991 constraint (inst.reloc.exp.X_op != O_constant,
9992 _("expression too complex"));
9993 inst.instruction |= (val & 0x1c) << 10;
9994 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9995 }
c19d1205 9996}
b05fe5cf 9997
c19d1205
ZW
9998static void
9999do_t_pkhtb (void)
10000{
10001 if (!inst.operands[3].present)
10002 inst.instruction &= ~0x00000020;
10003 do_t_pkhbt ();
b05fe5cf
ZW
10004}
10005
c19d1205
ZW
10006static void
10007do_t_pld (void)
10008{
10009 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10010}
b05fe5cf 10011
c19d1205
ZW
10012static void
10013do_t_push_pop (void)
b99bd4ef 10014{
e9f89963
PB
10015 unsigned mask;
10016
c19d1205
ZW
10017 constraint (inst.operands[0].writeback,
10018 _("push/pop do not support {reglist}^"));
10019 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10020 _("expression too complex"));
b99bd4ef 10021
e9f89963
PB
10022 mask = inst.operands[0].imm;
10023 if ((mask & ~0xff) == 0)
3c707909 10024 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10025 else if ((inst.instruction == T_MNEM_push
e9f89963 10026 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10027 || (inst.instruction == T_MNEM_pop
e9f89963 10028 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10029 {
c19d1205
ZW
10030 inst.instruction = THUMB_OP16 (inst.instruction);
10031 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10032 inst.instruction |= mask & 0xff;
c19d1205
ZW
10033 }
10034 else if (unified_syntax)
10035 {
3c707909
PB
10036 inst.instruction = THUMB_OP32 (inst.instruction);
10037 encode_thumb2_ldmstm(13, mask, TRUE);
c19d1205
ZW
10038 }
10039 else
10040 {
10041 inst.error = _("invalid register list to push/pop instruction");
10042 return;
10043 }
c19d1205 10044}
b99bd4ef 10045
c19d1205
ZW
10046static void
10047do_t_rbit (void)
10048{
10049 inst.instruction |= inst.operands[0].reg << 8;
10050 inst.instruction |= inst.operands[1].reg << 16;
10051}
b99bd4ef 10052
c19d1205
ZW
10053static void
10054do_t_rev (void)
10055{
10056 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10057 && inst.size_req != 4)
10058 {
10059 inst.instruction = THUMB_OP16 (inst.instruction);
10060 inst.instruction |= inst.operands[0].reg;
10061 inst.instruction |= inst.operands[1].reg << 3;
10062 }
10063 else if (unified_syntax)
10064 {
10065 inst.instruction = THUMB_OP32 (inst.instruction);
10066 inst.instruction |= inst.operands[0].reg << 8;
10067 inst.instruction |= inst.operands[1].reg << 16;
10068 inst.instruction |= inst.operands[1].reg;
10069 }
10070 else
10071 inst.error = BAD_HIREG;
10072}
b99bd4ef 10073
c19d1205
ZW
10074static void
10075do_t_rsb (void)
10076{
10077 int Rd, Rs;
b99bd4ef 10078
c19d1205
ZW
10079 Rd = inst.operands[0].reg;
10080 Rs = (inst.operands[1].present
10081 ? inst.operands[1].reg /* Rd, Rs, foo */
10082 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10083
c19d1205
ZW
10084 inst.instruction |= Rd << 8;
10085 inst.instruction |= Rs << 16;
10086 if (!inst.operands[2].isreg)
10087 {
026d3abb
PB
10088 bfd_boolean narrow;
10089
10090 if ((inst.instruction & 0x00100000) != 0)
10091 narrow = (current_it_mask == 0);
10092 else
10093 narrow = (current_it_mask != 0);
10094
10095 if (Rd > 7 || Rs > 7)
10096 narrow = FALSE;
10097
10098 if (inst.size_req == 4 || !unified_syntax)
10099 narrow = FALSE;
10100
10101 if (inst.reloc.exp.X_op != O_constant
10102 || inst.reloc.exp.X_add_number != 0)
10103 narrow = FALSE;
10104
10105 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10106 relaxation, but it doesn't seem worth the hassle. */
10107 if (narrow)
10108 {
10109 inst.reloc.type = BFD_RELOC_UNUSED;
10110 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10111 inst.instruction |= Rs << 3;
10112 inst.instruction |= Rd;
10113 }
10114 else
10115 {
10116 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10117 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10118 }
c19d1205
ZW
10119 }
10120 else
10121 encode_thumb32_shifted_operand (2);
10122}
b99bd4ef 10123
c19d1205
ZW
10124static void
10125do_t_setend (void)
10126{
dfa9f0d5 10127 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
10128 if (inst.operands[0].imm)
10129 inst.instruction |= 0x8;
10130}
b99bd4ef 10131
c19d1205
ZW
10132static void
10133do_t_shift (void)
10134{
10135 if (!inst.operands[1].present)
10136 inst.operands[1].reg = inst.operands[0].reg;
10137
10138 if (unified_syntax)
10139 {
3d388997
PB
10140 bfd_boolean narrow;
10141 int shift_kind;
10142
10143 switch (inst.instruction)
10144 {
10145 case T_MNEM_asr:
10146 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10147 case T_MNEM_lsl:
10148 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10149 case T_MNEM_lsr:
10150 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10151 case T_MNEM_ror:
10152 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10153 default: abort ();
10154 }
10155
10156 if (THUMB_SETS_FLAGS (inst.instruction))
10157 narrow = (current_it_mask == 0);
10158 else
10159 narrow = (current_it_mask != 0);
10160 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10161 narrow = FALSE;
10162 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10163 narrow = FALSE;
10164 if (inst.operands[2].isreg
10165 && (inst.operands[1].reg != inst.operands[0].reg
10166 || inst.operands[2].reg > 7))
10167 narrow = FALSE;
10168 if (inst.size_req == 4)
10169 narrow = FALSE;
10170
10171 if (!narrow)
c19d1205
ZW
10172 {
10173 if (inst.operands[2].isreg)
b99bd4ef 10174 {
c19d1205
ZW
10175 inst.instruction = THUMB_OP32 (inst.instruction);
10176 inst.instruction |= inst.operands[0].reg << 8;
10177 inst.instruction |= inst.operands[1].reg << 16;
10178 inst.instruction |= inst.operands[2].reg;
10179 }
10180 else
10181 {
10182 inst.operands[1].shifted = 1;
3d388997 10183 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10184 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10185 ? T_MNEM_movs : T_MNEM_mov);
10186 inst.instruction |= inst.operands[0].reg << 8;
10187 encode_thumb32_shifted_operand (1);
10188 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10189 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10190 }
10191 }
10192 else
10193 {
c19d1205 10194 if (inst.operands[2].isreg)
b99bd4ef 10195 {
3d388997 10196 switch (shift_kind)
b99bd4ef 10197 {
3d388997
PB
10198 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10199 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10200 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10201 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10202 default: abort ();
b99bd4ef 10203 }
c19d1205
ZW
10204
10205 inst.instruction |= inst.operands[0].reg;
10206 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10207 }
10208 else
10209 {
3d388997 10210 switch (shift_kind)
b99bd4ef 10211 {
3d388997
PB
10212 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10213 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10214 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10215 default: abort ();
b99bd4ef 10216 }
c19d1205
ZW
10217 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10218 inst.instruction |= inst.operands[0].reg;
10219 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10220 }
10221 }
c19d1205
ZW
10222 }
10223 else
10224 {
10225 constraint (inst.operands[0].reg > 7
10226 || inst.operands[1].reg > 7, BAD_HIREG);
10227 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10228
c19d1205
ZW
10229 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10230 {
10231 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10232 constraint (inst.operands[0].reg != inst.operands[1].reg,
10233 _("source1 and dest must be same register"));
b99bd4ef 10234
c19d1205
ZW
10235 switch (inst.instruction)
10236 {
10237 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10238 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10239 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10240 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10241 default: abort ();
10242 }
10243
10244 inst.instruction |= inst.operands[0].reg;
10245 inst.instruction |= inst.operands[2].reg << 3;
10246 }
10247 else
b99bd4ef 10248 {
c19d1205
ZW
10249 switch (inst.instruction)
10250 {
10251 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10252 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10253 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10254 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10255 default: abort ();
10256 }
10257 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10258 inst.instruction |= inst.operands[0].reg;
10259 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10260 }
10261 }
b99bd4ef
NC
10262}
10263
10264static void
c19d1205 10265do_t_simd (void)
b99bd4ef 10266{
c19d1205
ZW
10267 inst.instruction |= inst.operands[0].reg << 8;
10268 inst.instruction |= inst.operands[1].reg << 16;
10269 inst.instruction |= inst.operands[2].reg;
10270}
b99bd4ef 10271
c19d1205 10272static void
3eb17e6b 10273do_t_smc (void)
c19d1205
ZW
10274{
10275 unsigned int value = inst.reloc.exp.X_add_number;
10276 constraint (inst.reloc.exp.X_op != O_constant,
10277 _("expression too complex"));
10278 inst.reloc.type = BFD_RELOC_UNUSED;
10279 inst.instruction |= (value & 0xf000) >> 12;
10280 inst.instruction |= (value & 0x0ff0);
10281 inst.instruction |= (value & 0x000f) << 16;
10282}
b99bd4ef 10283
c19d1205
ZW
10284static void
10285do_t_ssat (void)
10286{
10287 inst.instruction |= inst.operands[0].reg << 8;
10288 inst.instruction |= inst.operands[1].imm - 1;
10289 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10290
c19d1205 10291 if (inst.operands[3].present)
b99bd4ef 10292 {
c19d1205
ZW
10293 constraint (inst.reloc.exp.X_op != O_constant,
10294 _("expression too complex"));
b99bd4ef 10295
c19d1205 10296 if (inst.reloc.exp.X_add_number != 0)
6189168b 10297 {
c19d1205
ZW
10298 if (inst.operands[3].shift_kind == SHIFT_ASR)
10299 inst.instruction |= 0x00200000; /* sh bit */
10300 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10301 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 10302 }
c19d1205 10303 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 10304 }
b99bd4ef
NC
10305}
10306
0dd132b6 10307static void
c19d1205 10308do_t_ssat16 (void)
0dd132b6 10309{
c19d1205
ZW
10310 inst.instruction |= inst.operands[0].reg << 8;
10311 inst.instruction |= inst.operands[1].imm - 1;
10312 inst.instruction |= inst.operands[2].reg << 16;
10313}
0dd132b6 10314
c19d1205
ZW
10315static void
10316do_t_strex (void)
10317{
10318 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10319 || inst.operands[2].postind || inst.operands[2].writeback
10320 || inst.operands[2].immisreg || inst.operands[2].shifted
10321 || inst.operands[2].negative,
01cfc07f 10322 BAD_ADDR_MODE);
0dd132b6 10323
c19d1205
ZW
10324 inst.instruction |= inst.operands[0].reg << 8;
10325 inst.instruction |= inst.operands[1].reg << 12;
10326 inst.instruction |= inst.operands[2].reg << 16;
10327 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10328}
10329
b99bd4ef 10330static void
c19d1205 10331do_t_strexd (void)
b99bd4ef 10332{
c19d1205
ZW
10333 if (!inst.operands[2].present)
10334 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10335
c19d1205
ZW
10336 constraint (inst.operands[0].reg == inst.operands[1].reg
10337 || inst.operands[0].reg == inst.operands[2].reg
10338 || inst.operands[0].reg == inst.operands[3].reg
10339 || inst.operands[1].reg == inst.operands[2].reg,
10340 BAD_OVERLAP);
b99bd4ef 10341
c19d1205
ZW
10342 inst.instruction |= inst.operands[0].reg;
10343 inst.instruction |= inst.operands[1].reg << 12;
10344 inst.instruction |= inst.operands[2].reg << 8;
10345 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10346}
10347
10348static void
c19d1205 10349do_t_sxtah (void)
b99bd4ef 10350{
c19d1205
ZW
10351 inst.instruction |= inst.operands[0].reg << 8;
10352 inst.instruction |= inst.operands[1].reg << 16;
10353 inst.instruction |= inst.operands[2].reg;
10354 inst.instruction |= inst.operands[3].imm << 4;
10355}
b99bd4ef 10356
c19d1205
ZW
10357static void
10358do_t_sxth (void)
10359{
10360 if (inst.instruction <= 0xffff && inst.size_req != 4
10361 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10362 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10363 {
c19d1205
ZW
10364 inst.instruction = THUMB_OP16 (inst.instruction);
10365 inst.instruction |= inst.operands[0].reg;
10366 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10367 }
c19d1205 10368 else if (unified_syntax)
b99bd4ef 10369 {
c19d1205
ZW
10370 if (inst.instruction <= 0xffff)
10371 inst.instruction = THUMB_OP32 (inst.instruction);
10372 inst.instruction |= inst.operands[0].reg << 8;
10373 inst.instruction |= inst.operands[1].reg;
10374 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10375 }
c19d1205 10376 else
b99bd4ef 10377 {
c19d1205
ZW
10378 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10379 _("Thumb encoding does not support rotation"));
10380 constraint (1, BAD_HIREG);
b99bd4ef 10381 }
c19d1205 10382}
b99bd4ef 10383
c19d1205
ZW
10384static void
10385do_t_swi (void)
10386{
10387 inst.reloc.type = BFD_RELOC_ARM_SWI;
10388}
b99bd4ef 10389
92e90b6e
PB
10390static void
10391do_t_tb (void)
10392{
10393 int half;
10394
10395 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10396 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10397 constraint (inst.operands[0].immisreg,
10398 _("instruction requires register index"));
92e90b6e
PB
10399 constraint (inst.operands[0].imm == 15,
10400 _("PC is not a valid index register"));
10401 constraint (!half && inst.operands[0].shifted,
10402 _("instruction does not allow shifted index"));
92e90b6e
PB
10403 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10404}
10405
c19d1205
ZW
10406static void
10407do_t_usat (void)
10408{
10409 inst.instruction |= inst.operands[0].reg << 8;
10410 inst.instruction |= inst.operands[1].imm;
10411 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10412
c19d1205 10413 if (inst.operands[3].present)
b99bd4ef 10414 {
c19d1205
ZW
10415 constraint (inst.reloc.exp.X_op != O_constant,
10416 _("expression too complex"));
10417 if (inst.reloc.exp.X_add_number != 0)
10418 {
10419 if (inst.operands[3].shift_kind == SHIFT_ASR)
10420 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10421
c19d1205
ZW
10422 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10423 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10424 }
10425 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10426 }
b99bd4ef
NC
10427}
10428
10429static void
c19d1205 10430do_t_usat16 (void)
b99bd4ef 10431{
c19d1205
ZW
10432 inst.instruction |= inst.operands[0].reg << 8;
10433 inst.instruction |= inst.operands[1].imm;
10434 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10435}
c19d1205 10436
5287ad62
JB
10437/* Neon instruction encoder helpers. */
10438
10439/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10440
5287ad62
JB
10441/* An "invalid" code for the following tables. */
10442#define N_INV -1u
10443
10444struct neon_tab_entry
b99bd4ef 10445{
5287ad62
JB
10446 unsigned integer;
10447 unsigned float_or_poly;
10448 unsigned scalar_or_imm;
10449};
10450
10451/* Map overloaded Neon opcodes to their respective encodings. */
10452#define NEON_ENC_TAB \
10453 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10454 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10455 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10456 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10457 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10458 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10459 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10460 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10461 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10462 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10463 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10464 /* Register variants of the following two instructions are encoded as
10465 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
10466 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
10467 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
10468 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10469 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10470 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10471 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10472 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10473 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10474 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10475 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10476 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10477 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10478 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10479 X(vshl, 0x0000400, N_INV, 0x0800510), \
10480 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10481 X(vand, 0x0000110, N_INV, 0x0800030), \
10482 X(vbic, 0x0100110, N_INV, 0x0800030), \
10483 X(veor, 0x1000110, N_INV, N_INV), \
10484 X(vorn, 0x0300110, N_INV, 0x0800010), \
10485 X(vorr, 0x0200110, N_INV, 0x0800010), \
10486 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10487 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10488 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10489 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10490 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10491 X(vst1, 0x0000000, 0x0800000, N_INV), \
10492 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10493 X(vst2, 0x0000100, 0x0800100, N_INV), \
10494 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10495 X(vst3, 0x0000200, 0x0800200, N_INV), \
10496 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10497 X(vst4, 0x0000300, 0x0800300, N_INV), \
10498 X(vmovn, 0x1b20200, N_INV, N_INV), \
10499 X(vtrn, 0x1b20080, N_INV, N_INV), \
10500 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10501 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10502 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10503 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10504 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10505 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10506 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10507 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10508 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10509
10510enum neon_opc
10511{
10512#define X(OPC,I,F,S) N_MNEM_##OPC
10513NEON_ENC_TAB
10514#undef X
10515};
b99bd4ef 10516
5287ad62
JB
10517static const struct neon_tab_entry neon_enc_tab[] =
10518{
10519#define X(OPC,I,F,S) { (I), (F), (S) }
10520NEON_ENC_TAB
10521#undef X
10522};
b99bd4ef 10523
5287ad62
JB
10524#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10525#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10526#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10527#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10528#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10529#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10530#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10531#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10532#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10533#define NEON_ENC_SINGLE(X) \
10534 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10535#define NEON_ENC_DOUBLE(X) \
10536 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10537
037e8744
JB
10538/* Define shapes for instruction operands. The following mnemonic characters
10539 are used in this table:
5287ad62 10540
037e8744 10541 F - VFP S<n> register
5287ad62
JB
10542 D - Neon D<n> register
10543 Q - Neon Q<n> register
10544 I - Immediate
10545 S - Scalar
10546 R - ARM register
10547 L - D<n> register list
037e8744
JB
10548
10549 This table is used to generate various data:
10550 - enumerations of the form NS_DDR to be used as arguments to
10551 neon_select_shape.
10552 - a table classifying shapes into single, double, quad, mixed.
10553 - a table used to drive neon_select_shape.
5287ad62 10554*/
b99bd4ef 10555
037e8744
JB
10556#define NEON_SHAPE_DEF \
10557 X(3, (D, D, D), DOUBLE), \
10558 X(3, (Q, Q, Q), QUAD), \
10559 X(3, (D, D, I), DOUBLE), \
10560 X(3, (Q, Q, I), QUAD), \
10561 X(3, (D, D, S), DOUBLE), \
10562 X(3, (Q, Q, S), QUAD), \
10563 X(2, (D, D), DOUBLE), \
10564 X(2, (Q, Q), QUAD), \
10565 X(2, (D, S), DOUBLE), \
10566 X(2, (Q, S), QUAD), \
10567 X(2, (D, R), DOUBLE), \
10568 X(2, (Q, R), QUAD), \
10569 X(2, (D, I), DOUBLE), \
10570 X(2, (Q, I), QUAD), \
10571 X(3, (D, L, D), DOUBLE), \
10572 X(2, (D, Q), MIXED), \
10573 X(2, (Q, D), MIXED), \
10574 X(3, (D, Q, I), MIXED), \
10575 X(3, (Q, D, I), MIXED), \
10576 X(3, (Q, D, D), MIXED), \
10577 X(3, (D, Q, Q), MIXED), \
10578 X(3, (Q, Q, D), MIXED), \
10579 X(3, (Q, D, S), MIXED), \
10580 X(3, (D, Q, S), MIXED), \
10581 X(4, (D, D, D, I), DOUBLE), \
10582 X(4, (Q, Q, Q, I), QUAD), \
10583 X(2, (F, F), SINGLE), \
10584 X(3, (F, F, F), SINGLE), \
10585 X(2, (F, I), SINGLE), \
10586 X(2, (F, D), MIXED), \
10587 X(2, (D, F), MIXED), \
10588 X(3, (F, F, I), MIXED), \
10589 X(4, (R, R, F, F), SINGLE), \
10590 X(4, (F, F, R, R), SINGLE), \
10591 X(3, (D, R, R), DOUBLE), \
10592 X(3, (R, R, D), DOUBLE), \
10593 X(2, (S, R), SINGLE), \
10594 X(2, (R, S), SINGLE), \
10595 X(2, (F, R), SINGLE), \
10596 X(2, (R, F), SINGLE)
10597
10598#define S2(A,B) NS_##A##B
10599#define S3(A,B,C) NS_##A##B##C
10600#define S4(A,B,C,D) NS_##A##B##C##D
10601
10602#define X(N, L, C) S##N L
10603
5287ad62
JB
10604enum neon_shape
10605{
037e8744
JB
10606 NEON_SHAPE_DEF,
10607 NS_NULL
5287ad62 10608};
b99bd4ef 10609
037e8744
JB
10610#undef X
10611#undef S2
10612#undef S3
10613#undef S4
10614
10615enum neon_shape_class
10616{
10617 SC_SINGLE,
10618 SC_DOUBLE,
10619 SC_QUAD,
10620 SC_MIXED
10621};
10622
10623#define X(N, L, C) SC_##C
10624
10625static enum neon_shape_class neon_shape_class[] =
10626{
10627 NEON_SHAPE_DEF
10628};
10629
10630#undef X
10631
10632enum neon_shape_el
10633{
10634 SE_F,
10635 SE_D,
10636 SE_Q,
10637 SE_I,
10638 SE_S,
10639 SE_R,
10640 SE_L
10641};
10642
10643/* Register widths of above. */
10644static unsigned neon_shape_el_size[] =
10645{
10646 32,
10647 64,
10648 128,
10649 0,
10650 32,
10651 32,
10652 0
10653};
10654
10655struct neon_shape_info
10656{
10657 unsigned els;
10658 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10659};
10660
10661#define S2(A,B) { SE_##A, SE_##B }
10662#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10663#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10664
10665#define X(N, L, C) { N, S##N L }
10666
10667static struct neon_shape_info neon_shape_tab[] =
10668{
10669 NEON_SHAPE_DEF
10670};
10671
10672#undef X
10673#undef S2
10674#undef S3
10675#undef S4
10676
5287ad62
JB
10677/* Bit masks used in type checking given instructions.
10678 'N_EQK' means the type must be the same as (or based on in some way) the key
10679 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10680 set, various other bits can be set as well in order to modify the meaning of
10681 the type constraint. */
10682
10683enum neon_type_mask
10684{
10685 N_S8 = 0x000001,
10686 N_S16 = 0x000002,
10687 N_S32 = 0x000004,
10688 N_S64 = 0x000008,
10689 N_U8 = 0x000010,
10690 N_U16 = 0x000020,
10691 N_U32 = 0x000040,
10692 N_U64 = 0x000080,
10693 N_I8 = 0x000100,
10694 N_I16 = 0x000200,
10695 N_I32 = 0x000400,
10696 N_I64 = 0x000800,
10697 N_8 = 0x001000,
10698 N_16 = 0x002000,
10699 N_32 = 0x004000,
10700 N_64 = 0x008000,
10701 N_P8 = 0x010000,
10702 N_P16 = 0x020000,
10703 N_F32 = 0x040000,
037e8744
JB
10704 N_F64 = 0x080000,
10705 N_KEY = 0x100000, /* key element (main type specifier). */
10706 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10707 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10708 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10709 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10710 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10711 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10712 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10713 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10714 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10715 N_UTYP = 0,
037e8744 10716 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10717};
10718
dcbf9037
JB
10719#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10720
5287ad62
JB
10721#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10722#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10723#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10724#define N_SUF_32 (N_SU_32 | N_F32)
10725#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10726#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10727
10728/* Pass this as the first type argument to neon_check_type to ignore types
10729 altogether. */
10730#define N_IGNORE_TYPE (N_KEY | N_EQK)
10731
037e8744
JB
10732/* Select a "shape" for the current instruction (describing register types or
10733 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10734 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10735 function of operand parsing, so this function doesn't need to be called.
10736 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10737
10738static enum neon_shape
037e8744 10739neon_select_shape (enum neon_shape shape, ...)
5287ad62 10740{
037e8744
JB
10741 va_list ap;
10742 enum neon_shape first_shape = shape;
5287ad62
JB
10743
10744 /* Fix missing optional operands. FIXME: we don't know at this point how
10745 many arguments we should have, so this makes the assumption that we have
10746 > 1. This is true of all current Neon opcodes, I think, but may not be
10747 true in the future. */
10748 if (!inst.operands[1].present)
10749 inst.operands[1] = inst.operands[0];
10750
037e8744 10751 va_start (ap, shape);
5287ad62 10752
037e8744
JB
10753 for (; shape != NS_NULL; shape = va_arg (ap, int))
10754 {
10755 unsigned j;
10756 int matches = 1;
10757
10758 for (j = 0; j < neon_shape_tab[shape].els; j++)
10759 {
10760 if (!inst.operands[j].present)
10761 {
10762 matches = 0;
10763 break;
10764 }
10765
10766 switch (neon_shape_tab[shape].el[j])
10767 {
10768 case SE_F:
10769 if (!(inst.operands[j].isreg
10770 && inst.operands[j].isvec
10771 && inst.operands[j].issingle
10772 && !inst.operands[j].isquad))
10773 matches = 0;
10774 break;
10775
10776 case SE_D:
10777 if (!(inst.operands[j].isreg
10778 && inst.operands[j].isvec
10779 && !inst.operands[j].isquad
10780 && !inst.operands[j].issingle))
10781 matches = 0;
10782 break;
10783
10784 case SE_R:
10785 if (!(inst.operands[j].isreg
10786 && !inst.operands[j].isvec))
10787 matches = 0;
10788 break;
10789
10790 case SE_Q:
10791 if (!(inst.operands[j].isreg
10792 && inst.operands[j].isvec
10793 && inst.operands[j].isquad
10794 && !inst.operands[j].issingle))
10795 matches = 0;
10796 break;
10797
10798 case SE_I:
10799 if (!(!inst.operands[j].isreg
10800 && !inst.operands[j].isscalar))
10801 matches = 0;
10802 break;
10803
10804 case SE_S:
10805 if (!(!inst.operands[j].isreg
10806 && inst.operands[j].isscalar))
10807 matches = 0;
10808 break;
10809
10810 case SE_L:
10811 break;
10812 }
10813 }
10814 if (matches)
5287ad62 10815 break;
037e8744 10816 }
5287ad62 10817
037e8744 10818 va_end (ap);
5287ad62 10819
037e8744
JB
10820 if (shape == NS_NULL && first_shape != NS_NULL)
10821 first_error (_("invalid instruction shape"));
5287ad62 10822
037e8744
JB
10823 return shape;
10824}
5287ad62 10825
037e8744
JB
10826/* True if SHAPE is predominantly a quadword operation (most of the time, this
10827 means the Q bit should be set). */
10828
10829static int
10830neon_quad (enum neon_shape shape)
10831{
10832 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10833}
037e8744 10834
5287ad62
JB
10835static void
10836neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10837 unsigned *g_size)
10838{
10839 /* Allow modification to be made to types which are constrained to be
10840 based on the key element, based on bits set alongside N_EQK. */
10841 if ((typebits & N_EQK) != 0)
10842 {
10843 if ((typebits & N_HLF) != 0)
10844 *g_size /= 2;
10845 else if ((typebits & N_DBL) != 0)
10846 *g_size *= 2;
10847 if ((typebits & N_SGN) != 0)
10848 *g_type = NT_signed;
10849 else if ((typebits & N_UNS) != 0)
10850 *g_type = NT_unsigned;
10851 else if ((typebits & N_INT) != 0)
10852 *g_type = NT_integer;
10853 else if ((typebits & N_FLT) != 0)
10854 *g_type = NT_float;
dcbf9037
JB
10855 else if ((typebits & N_SIZ) != 0)
10856 *g_type = NT_untyped;
5287ad62
JB
10857 }
10858}
10859
10860/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10861 operand type, i.e. the single type specified in a Neon instruction when it
10862 is the only one given. */
10863
10864static struct neon_type_el
10865neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10866{
10867 struct neon_type_el dest = *key;
10868
10869 assert ((thisarg & N_EQK) != 0);
10870
10871 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10872
10873 return dest;
10874}
10875
10876/* Convert Neon type and size into compact bitmask representation. */
10877
10878static enum neon_type_mask
10879type_chk_of_el_type (enum neon_el_type type, unsigned size)
10880{
10881 switch (type)
10882 {
10883 case NT_untyped:
10884 switch (size)
10885 {
10886 case 8: return N_8;
10887 case 16: return N_16;
10888 case 32: return N_32;
10889 case 64: return N_64;
10890 default: ;
10891 }
10892 break;
10893
10894 case NT_integer:
10895 switch (size)
10896 {
10897 case 8: return N_I8;
10898 case 16: return N_I16;
10899 case 32: return N_I32;
10900 case 64: return N_I64;
10901 default: ;
10902 }
10903 break;
10904
10905 case NT_float:
037e8744
JB
10906 switch (size)
10907 {
10908 case 32: return N_F32;
10909 case 64: return N_F64;
10910 default: ;
10911 }
5287ad62
JB
10912 break;
10913
10914 case NT_poly:
10915 switch (size)
10916 {
10917 case 8: return N_P8;
10918 case 16: return N_P16;
10919 default: ;
10920 }
10921 break;
10922
10923 case NT_signed:
10924 switch (size)
10925 {
10926 case 8: return N_S8;
10927 case 16: return N_S16;
10928 case 32: return N_S32;
10929 case 64: return N_S64;
10930 default: ;
10931 }
10932 break;
10933
10934 case NT_unsigned:
10935 switch (size)
10936 {
10937 case 8: return N_U8;
10938 case 16: return N_U16;
10939 case 32: return N_U32;
10940 case 64: return N_U64;
10941 default: ;
10942 }
10943 break;
10944
10945 default: ;
10946 }
10947
10948 return N_UTYP;
10949}
10950
10951/* Convert compact Neon bitmask type representation to a type and size. Only
10952 handles the case where a single bit is set in the mask. */
10953
dcbf9037 10954static int
5287ad62
JB
10955el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10956 enum neon_type_mask mask)
10957{
dcbf9037
JB
10958 if ((mask & N_EQK) != 0)
10959 return FAIL;
10960
5287ad62
JB
10961 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10962 *size = 8;
dcbf9037 10963 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10964 *size = 16;
dcbf9037 10965 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10966 *size = 32;
037e8744 10967 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10968 *size = 64;
dcbf9037
JB
10969 else
10970 return FAIL;
10971
5287ad62
JB
10972 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10973 *type = NT_signed;
dcbf9037 10974 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10975 *type = NT_unsigned;
dcbf9037 10976 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10977 *type = NT_integer;
dcbf9037 10978 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10979 *type = NT_untyped;
dcbf9037 10980 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10981 *type = NT_poly;
037e8744 10982 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10983 *type = NT_float;
dcbf9037
JB
10984 else
10985 return FAIL;
10986
10987 return SUCCESS;
5287ad62
JB
10988}
10989
10990/* Modify a bitmask of allowed types. This is only needed for type
10991 relaxation. */
10992
10993static unsigned
10994modify_types_allowed (unsigned allowed, unsigned mods)
10995{
10996 unsigned size;
10997 enum neon_el_type type;
10998 unsigned destmask;
10999 int i;
11000
11001 destmask = 0;
11002
11003 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11004 {
dcbf9037
JB
11005 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11006 {
11007 neon_modify_type_size (mods, &type, &size);
11008 destmask |= type_chk_of_el_type (type, size);
11009 }
5287ad62
JB
11010 }
11011
11012 return destmask;
11013}
11014
11015/* Check type and return type classification.
11016 The manual states (paraphrase): If one datatype is given, it indicates the
11017 type given in:
11018 - the second operand, if there is one
11019 - the operand, if there is no second operand
11020 - the result, if there are no operands.
11021 This isn't quite good enough though, so we use a concept of a "key" datatype
11022 which is set on a per-instruction basis, which is the one which matters when
11023 only one data type is written.
11024 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11025 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11026
11027static struct neon_type_el
11028neon_check_type (unsigned els, enum neon_shape ns, ...)
11029{
11030 va_list ap;
11031 unsigned i, pass, key_el = 0;
11032 unsigned types[NEON_MAX_TYPE_ELS];
11033 enum neon_el_type k_type = NT_invtype;
11034 unsigned k_size = -1u;
11035 struct neon_type_el badtype = {NT_invtype, -1};
11036 unsigned key_allowed = 0;
11037
11038 /* Optional registers in Neon instructions are always (not) in operand 1.
11039 Fill in the missing operand here, if it was omitted. */
11040 if (els > 1 && !inst.operands[1].present)
11041 inst.operands[1] = inst.operands[0];
11042
11043 /* Suck up all the varargs. */
11044 va_start (ap, ns);
11045 for (i = 0; i < els; i++)
11046 {
11047 unsigned thisarg = va_arg (ap, unsigned);
11048 if (thisarg == N_IGNORE_TYPE)
11049 {
11050 va_end (ap);
11051 return badtype;
11052 }
11053 types[i] = thisarg;
11054 if ((thisarg & N_KEY) != 0)
11055 key_el = i;
11056 }
11057 va_end (ap);
11058
dcbf9037
JB
11059 if (inst.vectype.elems > 0)
11060 for (i = 0; i < els; i++)
11061 if (inst.operands[i].vectype.type != NT_invtype)
11062 {
11063 first_error (_("types specified in both the mnemonic and operands"));
11064 return badtype;
11065 }
11066
5287ad62
JB
11067 /* Duplicate inst.vectype elements here as necessary.
11068 FIXME: No idea if this is exactly the same as the ARM assembler,
11069 particularly when an insn takes one register and one non-register
11070 operand. */
11071 if (inst.vectype.elems == 1 && els > 1)
11072 {
11073 unsigned j;
11074 inst.vectype.elems = els;
11075 inst.vectype.el[key_el] = inst.vectype.el[0];
11076 for (j = 0; j < els; j++)
dcbf9037
JB
11077 if (j != key_el)
11078 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11079 types[j]);
11080 }
11081 else if (inst.vectype.elems == 0 && els > 0)
11082 {
11083 unsigned j;
11084 /* No types were given after the mnemonic, so look for types specified
11085 after each operand. We allow some flexibility here; as long as the
11086 "key" operand has a type, we can infer the others. */
11087 for (j = 0; j < els; j++)
11088 if (inst.operands[j].vectype.type != NT_invtype)
11089 inst.vectype.el[j] = inst.operands[j].vectype;
11090
11091 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11092 {
dcbf9037
JB
11093 for (j = 0; j < els; j++)
11094 if (inst.operands[j].vectype.type == NT_invtype)
11095 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11096 types[j]);
11097 }
11098 else
11099 {
11100 first_error (_("operand types can't be inferred"));
11101 return badtype;
5287ad62
JB
11102 }
11103 }
11104 else if (inst.vectype.elems != els)
11105 {
dcbf9037 11106 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11107 return badtype;
11108 }
11109
11110 for (pass = 0; pass < 2; pass++)
11111 {
11112 for (i = 0; i < els; i++)
11113 {
11114 unsigned thisarg = types[i];
11115 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11116 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11117 enum neon_el_type g_type = inst.vectype.el[i].type;
11118 unsigned g_size = inst.vectype.el[i].size;
11119
11120 /* Decay more-specific signed & unsigned types to sign-insensitive
11121 integer types if sign-specific variants are unavailable. */
11122 if ((g_type == NT_signed || g_type == NT_unsigned)
11123 && (types_allowed & N_SU_ALL) == 0)
11124 g_type = NT_integer;
11125
11126 /* If only untyped args are allowed, decay any more specific types to
11127 them. Some instructions only care about signs for some element
11128 sizes, so handle that properly. */
11129 if ((g_size == 8 && (types_allowed & N_8) != 0)
11130 || (g_size == 16 && (types_allowed & N_16) != 0)
11131 || (g_size == 32 && (types_allowed & N_32) != 0)
11132 || (g_size == 64 && (types_allowed & N_64) != 0))
11133 g_type = NT_untyped;
11134
11135 if (pass == 0)
11136 {
11137 if ((thisarg & N_KEY) != 0)
11138 {
11139 k_type = g_type;
11140 k_size = g_size;
11141 key_allowed = thisarg & ~N_KEY;
11142 }
11143 }
11144 else
11145 {
037e8744
JB
11146 if ((thisarg & N_VFP) != 0)
11147 {
11148 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11149 unsigned regwidth = neon_shape_el_size[regshape], match;
11150
11151 /* In VFP mode, operands must match register widths. If we
11152 have a key operand, use its width, else use the width of
11153 the current operand. */
11154 if (k_size != -1u)
11155 match = k_size;
11156 else
11157 match = g_size;
11158
11159 if (regwidth != match)
11160 {
11161 first_error (_("operand size must match register width"));
11162 return badtype;
11163 }
11164 }
11165
5287ad62
JB
11166 if ((thisarg & N_EQK) == 0)
11167 {
11168 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11169
11170 if ((given_type & types_allowed) == 0)
11171 {
dcbf9037 11172 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11173 return badtype;
11174 }
11175 }
11176 else
11177 {
11178 enum neon_el_type mod_k_type = k_type;
11179 unsigned mod_k_size = k_size;
11180 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11181 if (g_type != mod_k_type || g_size != mod_k_size)
11182 {
dcbf9037 11183 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11184 return badtype;
11185 }
11186 }
11187 }
11188 }
11189 }
11190
11191 return inst.vectype.el[key_el];
11192}
11193
037e8744 11194/* Neon-style VFP instruction forwarding. */
5287ad62 11195
037e8744
JB
11196/* Thumb VFP instructions have 0xE in the condition field. */
11197
11198static void
11199do_vfp_cond_or_thumb (void)
5287ad62
JB
11200{
11201 if (thumb_mode)
037e8744 11202 inst.instruction |= 0xe0000000;
5287ad62 11203 else
037e8744 11204 inst.instruction |= inst.cond << 28;
5287ad62
JB
11205}
11206
037e8744
JB
11207/* Look up and encode a simple mnemonic, for use as a helper function for the
11208 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11209 etc. It is assumed that operand parsing has already been done, and that the
11210 operands are in the form expected by the given opcode (this isn't necessarily
11211 the same as the form in which they were parsed, hence some massaging must
11212 take place before this function is called).
11213 Checks current arch version against that in the looked-up opcode. */
5287ad62 11214
037e8744
JB
11215static void
11216do_vfp_nsyn_opcode (const char *opname)
5287ad62 11217{
037e8744
JB
11218 const struct asm_opcode *opcode;
11219
11220 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11221
037e8744
JB
11222 if (!opcode)
11223 abort ();
5287ad62 11224
037e8744
JB
11225 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11226 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11227 _(BAD_FPU));
5287ad62 11228
037e8744
JB
11229 if (thumb_mode)
11230 {
11231 inst.instruction = opcode->tvalue;
11232 opcode->tencode ();
11233 }
11234 else
11235 {
11236 inst.instruction = (inst.cond << 28) | opcode->avalue;
11237 opcode->aencode ();
11238 }
11239}
5287ad62
JB
11240
11241static void
037e8744 11242do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11243{
037e8744
JB
11244 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11245
11246 if (rs == NS_FFF)
11247 {
11248 if (is_add)
11249 do_vfp_nsyn_opcode ("fadds");
11250 else
11251 do_vfp_nsyn_opcode ("fsubs");
11252 }
11253 else
11254 {
11255 if (is_add)
11256 do_vfp_nsyn_opcode ("faddd");
11257 else
11258 do_vfp_nsyn_opcode ("fsubd");
11259 }
11260}
11261
11262/* Check operand types to see if this is a VFP instruction, and if so call
11263 PFN (). */
11264
11265static int
11266try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11267{
11268 enum neon_shape rs;
11269 struct neon_type_el et;
11270
11271 switch (args)
11272 {
11273 case 2:
11274 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11275 et = neon_check_type (2, rs,
11276 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11277 break;
11278
11279 case 3:
11280 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11281 et = neon_check_type (3, rs,
11282 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11283 break;
11284
11285 default:
11286 abort ();
11287 }
11288
11289 if (et.type != NT_invtype)
11290 {
11291 pfn (rs);
11292 return SUCCESS;
11293 }
11294 else
11295 inst.error = NULL;
11296
11297 return FAIL;
11298}
11299
11300static void
11301do_vfp_nsyn_mla_mls (enum neon_shape rs)
11302{
11303 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11304
11305 if (rs == NS_FFF)
11306 {
11307 if (is_mla)
11308 do_vfp_nsyn_opcode ("fmacs");
11309 else
11310 do_vfp_nsyn_opcode ("fmscs");
11311 }
11312 else
11313 {
11314 if (is_mla)
11315 do_vfp_nsyn_opcode ("fmacd");
11316 else
11317 do_vfp_nsyn_opcode ("fmscd");
11318 }
11319}
11320
11321static void
11322do_vfp_nsyn_mul (enum neon_shape rs)
11323{
11324 if (rs == NS_FFF)
11325 do_vfp_nsyn_opcode ("fmuls");
11326 else
11327 do_vfp_nsyn_opcode ("fmuld");
11328}
11329
11330static void
11331do_vfp_nsyn_abs_neg (enum neon_shape rs)
11332{
11333 int is_neg = (inst.instruction & 0x80) != 0;
11334 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11335
11336 if (rs == NS_FF)
11337 {
11338 if (is_neg)
11339 do_vfp_nsyn_opcode ("fnegs");
11340 else
11341 do_vfp_nsyn_opcode ("fabss");
11342 }
11343 else
11344 {
11345 if (is_neg)
11346 do_vfp_nsyn_opcode ("fnegd");
11347 else
11348 do_vfp_nsyn_opcode ("fabsd");
11349 }
11350}
11351
11352/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11353 insns belong to Neon, and are handled elsewhere. */
11354
11355static void
11356do_vfp_nsyn_ldm_stm (int is_dbmode)
11357{
11358 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11359 if (is_ldm)
11360 {
11361 if (is_dbmode)
11362 do_vfp_nsyn_opcode ("fldmdbs");
11363 else
11364 do_vfp_nsyn_opcode ("fldmias");
11365 }
11366 else
11367 {
11368 if (is_dbmode)
11369 do_vfp_nsyn_opcode ("fstmdbs");
11370 else
11371 do_vfp_nsyn_opcode ("fstmias");
11372 }
11373}
11374
037e8744
JB
11375static void
11376do_vfp_nsyn_sqrt (void)
11377{
11378 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11379 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11380
11381 if (rs == NS_FF)
11382 do_vfp_nsyn_opcode ("fsqrts");
11383 else
11384 do_vfp_nsyn_opcode ("fsqrtd");
11385}
11386
11387static void
11388do_vfp_nsyn_div (void)
11389{
11390 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11391 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11392 N_F32 | N_F64 | N_KEY | N_VFP);
11393
11394 if (rs == NS_FFF)
11395 do_vfp_nsyn_opcode ("fdivs");
11396 else
11397 do_vfp_nsyn_opcode ("fdivd");
11398}
11399
11400static void
11401do_vfp_nsyn_nmul (void)
11402{
11403 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11404 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11405 N_F32 | N_F64 | N_KEY | N_VFP);
11406
11407 if (rs == NS_FFF)
11408 {
11409 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11410 do_vfp_sp_dyadic ();
11411 }
11412 else
11413 {
11414 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11415 do_vfp_dp_rd_rn_rm ();
11416 }
11417 do_vfp_cond_or_thumb ();
11418}
11419
11420static void
11421do_vfp_nsyn_cmp (void)
11422{
11423 if (inst.operands[1].isreg)
11424 {
11425 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11426 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11427
11428 if (rs == NS_FF)
11429 {
11430 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11431 do_vfp_sp_monadic ();
11432 }
11433 else
11434 {
11435 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11436 do_vfp_dp_rd_rm ();
11437 }
11438 }
11439 else
11440 {
11441 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11442 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11443
11444 switch (inst.instruction & 0x0fffffff)
11445 {
11446 case N_MNEM_vcmp:
11447 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11448 break;
11449 case N_MNEM_vcmpe:
11450 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11451 break;
11452 default:
11453 abort ();
11454 }
11455
11456 if (rs == NS_FI)
11457 {
11458 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11459 do_vfp_sp_compare_z ();
11460 }
11461 else
11462 {
11463 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11464 do_vfp_dp_rd ();
11465 }
11466 }
11467 do_vfp_cond_or_thumb ();
11468}
11469
11470static void
11471nsyn_insert_sp (void)
11472{
11473 inst.operands[1] = inst.operands[0];
11474 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11475 inst.operands[0].reg = 13;
11476 inst.operands[0].isreg = 1;
11477 inst.operands[0].writeback = 1;
11478 inst.operands[0].present = 1;
11479}
11480
11481static void
11482do_vfp_nsyn_push (void)
11483{
11484 nsyn_insert_sp ();
11485 if (inst.operands[1].issingle)
11486 do_vfp_nsyn_opcode ("fstmdbs");
11487 else
11488 do_vfp_nsyn_opcode ("fstmdbd");
11489}
11490
11491static void
11492do_vfp_nsyn_pop (void)
11493{
11494 nsyn_insert_sp ();
11495 if (inst.operands[1].issingle)
22b5b651 11496 do_vfp_nsyn_opcode ("fldmias");
037e8744 11497 else
22b5b651 11498 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
11499}
11500
11501/* Fix up Neon data-processing instructions, ORing in the correct bits for
11502 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11503
11504static unsigned
11505neon_dp_fixup (unsigned i)
11506{
11507 if (thumb_mode)
11508 {
11509 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11510 if (i & (1 << 24))
11511 i |= 1 << 28;
11512
11513 i &= ~(1 << 24);
11514
11515 i |= 0xef000000;
11516 }
11517 else
11518 i |= 0xf2000000;
11519
11520 return i;
11521}
11522
11523/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11524 (0, 1, 2, 3). */
11525
11526static unsigned
11527neon_logbits (unsigned x)
11528{
11529 return ffs (x) - 4;
11530}
11531
11532#define LOW4(R) ((R) & 0xf)
11533#define HI1(R) (((R) >> 4) & 1)
11534
11535/* Encode insns with bit pattern:
11536
11537 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11538 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11539
11540 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11541 different meaning for some instruction. */
11542
11543static void
11544neon_three_same (int isquad, int ubit, int size)
11545{
11546 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11547 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11548 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11549 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11550 inst.instruction |= LOW4 (inst.operands[2].reg);
11551 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11552 inst.instruction |= (isquad != 0) << 6;
11553 inst.instruction |= (ubit != 0) << 24;
11554 if (size != -1)
11555 inst.instruction |= neon_logbits (size) << 20;
11556
11557 inst.instruction = neon_dp_fixup (inst.instruction);
11558}
11559
11560/* Encode instructions of the form:
11561
11562 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11563 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11564
11565 Don't write size if SIZE == -1. */
11566
11567static void
11568neon_two_same (int qbit, int ubit, int size)
11569{
11570 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11571 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11572 inst.instruction |= LOW4 (inst.operands[1].reg);
11573 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11574 inst.instruction |= (qbit != 0) << 6;
11575 inst.instruction |= (ubit != 0) << 24;
11576
11577 if (size != -1)
11578 inst.instruction |= neon_logbits (size) << 18;
11579
11580 inst.instruction = neon_dp_fixup (inst.instruction);
11581}
11582
11583/* Neon instruction encoders, in approximate order of appearance. */
11584
11585static void
11586do_neon_dyadic_i_su (void)
11587{
037e8744 11588 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11589 struct neon_type_el et = neon_check_type (3, rs,
11590 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11591 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11592}
11593
11594static void
11595do_neon_dyadic_i64_su (void)
11596{
037e8744 11597 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11598 struct neon_type_el et = neon_check_type (3, rs,
11599 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11600 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11601}
11602
11603static void
11604neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11605 unsigned immbits)
11606{
11607 unsigned size = et.size >> 3;
11608 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11609 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11610 inst.instruction |= LOW4 (inst.operands[1].reg);
11611 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11612 inst.instruction |= (isquad != 0) << 6;
11613 inst.instruction |= immbits << 16;
11614 inst.instruction |= (size >> 3) << 7;
11615 inst.instruction |= (size & 0x7) << 19;
11616 if (write_ubit)
11617 inst.instruction |= (uval != 0) << 24;
11618
11619 inst.instruction = neon_dp_fixup (inst.instruction);
11620}
11621
11622static void
11623do_neon_shl_imm (void)
11624{
11625 if (!inst.operands[2].isreg)
11626 {
037e8744 11627 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11628 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11629 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11630 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11631 }
11632 else
11633 {
037e8744 11634 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11635 struct neon_type_el et = neon_check_type (3, rs,
11636 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11637 unsigned int tmp;
11638
11639 /* VSHL/VQSHL 3-register variants have syntax such as:
11640 vshl.xx Dd, Dm, Dn
11641 whereas other 3-register operations encoded by neon_three_same have
11642 syntax like:
11643 vadd.xx Dd, Dn, Dm
11644 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
11645 here. */
11646 tmp = inst.operands[2].reg;
11647 inst.operands[2].reg = inst.operands[1].reg;
11648 inst.operands[1].reg = tmp;
5287ad62 11649 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11650 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11651 }
11652}
11653
11654static void
11655do_neon_qshl_imm (void)
11656{
11657 if (!inst.operands[2].isreg)
11658 {
037e8744 11659 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 11660 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 11661
5287ad62 11662 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11663 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11664 inst.operands[2].imm);
11665 }
11666 else
11667 {
037e8744 11668 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11669 struct neon_type_el et = neon_check_type (3, rs,
11670 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
11671 unsigned int tmp;
11672
11673 /* See note in do_neon_shl_imm. */
11674 tmp = inst.operands[2].reg;
11675 inst.operands[2].reg = inst.operands[1].reg;
11676 inst.operands[1].reg = tmp;
5287ad62 11677 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11678 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11679 }
11680}
11681
627907b7
JB
11682static void
11683do_neon_rshl (void)
11684{
11685 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
11686 struct neon_type_el et = neon_check_type (3, rs,
11687 N_EQK, N_EQK, N_SU_ALL | N_KEY);
11688 unsigned int tmp;
11689
11690 tmp = inst.operands[2].reg;
11691 inst.operands[2].reg = inst.operands[1].reg;
11692 inst.operands[1].reg = tmp;
11693 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
11694}
11695
5287ad62
JB
11696static int
11697neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11698{
036dc3f7
PB
11699 /* Handle .I8 pseudo-instructions. */
11700 if (size == 8)
5287ad62 11701 {
5287ad62
JB
11702 /* Unfortunately, this will make everything apart from zero out-of-range.
11703 FIXME is this the intended semantics? There doesn't seem much point in
11704 accepting .I8 if so. */
11705 immediate |= immediate << 8;
11706 size = 16;
036dc3f7
PB
11707 }
11708
11709 if (size >= 32)
11710 {
11711 if (immediate == (immediate & 0x000000ff))
11712 {
11713 *immbits = immediate;
11714 return 0x1;
11715 }
11716 else if (immediate == (immediate & 0x0000ff00))
11717 {
11718 *immbits = immediate >> 8;
11719 return 0x3;
11720 }
11721 else if (immediate == (immediate & 0x00ff0000))
11722 {
11723 *immbits = immediate >> 16;
11724 return 0x5;
11725 }
11726 else if (immediate == (immediate & 0xff000000))
11727 {
11728 *immbits = immediate >> 24;
11729 return 0x7;
11730 }
11731 if ((immediate & 0xffff) != (immediate >> 16))
11732 goto bad_immediate;
11733 immediate &= 0xffff;
5287ad62
JB
11734 }
11735
11736 if (immediate == (immediate & 0x000000ff))
11737 {
11738 *immbits = immediate;
036dc3f7 11739 return 0x9;
5287ad62
JB
11740 }
11741 else if (immediate == (immediate & 0x0000ff00))
11742 {
11743 *immbits = immediate >> 8;
036dc3f7 11744 return 0xb;
5287ad62
JB
11745 }
11746
11747 bad_immediate:
dcbf9037 11748 first_error (_("immediate value out of range"));
5287ad62
JB
11749 return FAIL;
11750}
11751
11752/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11753 A, B, C, D. */
11754
11755static int
11756neon_bits_same_in_bytes (unsigned imm)
11757{
11758 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11759 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11760 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11761 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11762}
11763
11764/* For immediate of above form, return 0bABCD. */
11765
11766static unsigned
11767neon_squash_bits (unsigned imm)
11768{
11769 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11770 | ((imm & 0x01000000) >> 21);
11771}
11772
136da414 11773/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11774
11775static unsigned
11776neon_qfloat_bits (unsigned imm)
11777{
136da414 11778 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11779}
11780
11781/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11782 the instruction. *OP is passed as the initial value of the op field, and
11783 may be set to a different value depending on the constant (i.e.
11784 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
036dc3f7
PB
11785 MVN). If the immediate looks like a repeated parttern then also
11786 try smaller element sizes. */
5287ad62
JB
11787
11788static int
c96612cc
JB
11789neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
11790 unsigned *immbits, int *op, int size,
11791 enum neon_el_type type)
5287ad62 11792{
c96612cc
JB
11793 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
11794 float. */
11795 if (type == NT_float && !float_p)
11796 return FAIL;
11797
136da414
JB
11798 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11799 {
11800 if (size != 32 || *op == 1)
11801 return FAIL;
11802 *immbits = neon_qfloat_bits (immlo);
11803 return 0xf;
11804 }
036dc3f7
PB
11805
11806 if (size == 64)
5287ad62 11807 {
036dc3f7
PB
11808 if (neon_bits_same_in_bytes (immhi)
11809 && neon_bits_same_in_bytes (immlo))
11810 {
11811 if (*op == 1)
11812 return FAIL;
11813 *immbits = (neon_squash_bits (immhi) << 4)
11814 | neon_squash_bits (immlo);
11815 *op = 1;
11816 return 0xe;
11817 }
11818
11819 if (immhi != immlo)
11820 return FAIL;
5287ad62 11821 }
036dc3f7
PB
11822
11823 if (size >= 32)
5287ad62 11824 {
036dc3f7
PB
11825 if (immlo == (immlo & 0x000000ff))
11826 {
11827 *immbits = immlo;
11828 return 0x0;
11829 }
11830 else if (immlo == (immlo & 0x0000ff00))
11831 {
11832 *immbits = immlo >> 8;
11833 return 0x2;
11834 }
11835 else if (immlo == (immlo & 0x00ff0000))
11836 {
11837 *immbits = immlo >> 16;
11838 return 0x4;
11839 }
11840 else if (immlo == (immlo & 0xff000000))
11841 {
11842 *immbits = immlo >> 24;
11843 return 0x6;
11844 }
11845 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11846 {
11847 *immbits = (immlo >> 8) & 0xff;
11848 return 0xc;
11849 }
11850 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11851 {
11852 *immbits = (immlo >> 16) & 0xff;
11853 return 0xd;
11854 }
11855
11856 if ((immlo & 0xffff) != (immlo >> 16))
11857 return FAIL;
11858 immlo &= 0xffff;
5287ad62 11859 }
036dc3f7
PB
11860
11861 if (size >= 16)
5287ad62 11862 {
036dc3f7
PB
11863 if (immlo == (immlo & 0x000000ff))
11864 {
11865 *immbits = immlo;
11866 return 0x8;
11867 }
11868 else if (immlo == (immlo & 0x0000ff00))
11869 {
11870 *immbits = immlo >> 8;
11871 return 0xa;
11872 }
11873
11874 if ((immlo & 0xff) != (immlo >> 8))
11875 return FAIL;
11876 immlo &= 0xff;
5287ad62 11877 }
036dc3f7
PB
11878
11879 if (immlo == (immlo & 0x000000ff))
5287ad62 11880 {
036dc3f7
PB
11881 /* Don't allow MVN with 8-bit immediate. */
11882 if (*op == 1)
11883 return FAIL;
11884 *immbits = immlo;
11885 return 0xe;
5287ad62 11886 }
5287ad62
JB
11887
11888 return FAIL;
11889}
11890
11891/* Write immediate bits [7:0] to the following locations:
11892
11893 |28/24|23 19|18 16|15 4|3 0|
11894 | 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|
11895
11896 This function is used by VMOV/VMVN/VORR/VBIC. */
11897
11898static void
11899neon_write_immbits (unsigned immbits)
11900{
11901 inst.instruction |= immbits & 0xf;
11902 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11903 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11904}
11905
11906/* Invert low-order SIZE bits of XHI:XLO. */
11907
11908static void
11909neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11910{
11911 unsigned immlo = xlo ? *xlo : 0;
11912 unsigned immhi = xhi ? *xhi : 0;
11913
11914 switch (size)
11915 {
11916 case 8:
11917 immlo = (~immlo) & 0xff;
11918 break;
11919
11920 case 16:
11921 immlo = (~immlo) & 0xffff;
11922 break;
11923
11924 case 64:
11925 immhi = (~immhi) & 0xffffffff;
11926 /* fall through. */
11927
11928 case 32:
11929 immlo = (~immlo) & 0xffffffff;
11930 break;
11931
11932 default:
11933 abort ();
11934 }
11935
11936 if (xlo)
11937 *xlo = immlo;
11938
11939 if (xhi)
11940 *xhi = immhi;
11941}
11942
11943static void
11944do_neon_logic (void)
11945{
11946 if (inst.operands[2].present && inst.operands[2].isreg)
11947 {
037e8744 11948 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11949 neon_check_type (3, rs, N_IGNORE_TYPE);
11950 /* U bit and size field were set as part of the bitmask. */
11951 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11952 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11953 }
11954 else
11955 {
037e8744
JB
11956 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11957 struct neon_type_el et = neon_check_type (2, rs,
11958 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11959 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11960 unsigned immbits;
11961 int cmode;
11962
11963 if (et.type == NT_invtype)
11964 return;
11965
11966 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11967
036dc3f7
PB
11968 immbits = inst.operands[1].imm;
11969 if (et.size == 64)
11970 {
11971 /* .i64 is a pseudo-op, so the immediate must be a repeating
11972 pattern. */
11973 if (immbits != (inst.operands[1].regisimm ?
11974 inst.operands[1].reg : 0))
11975 {
11976 /* Set immbits to an invalid constant. */
11977 immbits = 0xdeadbeef;
11978 }
11979 }
11980
5287ad62
JB
11981 switch (opcode)
11982 {
11983 case N_MNEM_vbic:
036dc3f7 11984 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62
JB
11985 break;
11986
11987 case N_MNEM_vorr:
036dc3f7 11988 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62
JB
11989 break;
11990
11991 case N_MNEM_vand:
11992 /* Pseudo-instruction for VBIC. */
5287ad62
JB
11993 neon_invert_size (&immbits, 0, et.size);
11994 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11995 break;
11996
11997 case N_MNEM_vorn:
11998 /* Pseudo-instruction for VORR. */
5287ad62
JB
11999 neon_invert_size (&immbits, 0, et.size);
12000 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12001 break;
12002
12003 default:
12004 abort ();
12005 }
12006
12007 if (cmode == FAIL)
12008 return;
12009
037e8744 12010 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12011 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12012 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12013 inst.instruction |= cmode << 8;
12014 neon_write_immbits (immbits);
12015
12016 inst.instruction = neon_dp_fixup (inst.instruction);
12017 }
12018}
12019
12020static void
12021do_neon_bitfield (void)
12022{
037e8744 12023 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12024 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12025 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12026}
12027
12028static void
dcbf9037
JB
12029neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12030 unsigned destbits)
5287ad62 12031{
037e8744 12032 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12033 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12034 types | N_KEY);
5287ad62
JB
12035 if (et.type == NT_float)
12036 {
12037 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12038 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12039 }
12040 else
12041 {
12042 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12043 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12044 }
12045}
12046
12047static void
12048do_neon_dyadic_if_su (void)
12049{
dcbf9037 12050 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12051}
12052
12053static void
12054do_neon_dyadic_if_su_d (void)
12055{
12056 /* This version only allow D registers, but that constraint is enforced during
12057 operand parsing so we don't need to do anything extra here. */
dcbf9037 12058 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12059}
12060
5287ad62
JB
12061static void
12062do_neon_dyadic_if_i_d (void)
12063{
428e3f1f
PB
12064 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12065 affected if we specify unsigned args. */
12066 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12067}
12068
037e8744
JB
12069enum vfp_or_neon_is_neon_bits
12070{
12071 NEON_CHECK_CC = 1,
12072 NEON_CHECK_ARCH = 2
12073};
12074
12075/* Call this function if an instruction which may have belonged to the VFP or
12076 Neon instruction sets, but turned out to be a Neon instruction (due to the
12077 operand types involved, etc.). We have to check and/or fix-up a couple of
12078 things:
12079
12080 - Make sure the user hasn't attempted to make a Neon instruction
12081 conditional.
12082 - Alter the value in the condition code field if necessary.
12083 - Make sure that the arch supports Neon instructions.
12084
12085 Which of these operations take place depends on bits from enum
12086 vfp_or_neon_is_neon_bits.
12087
12088 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12089 current instruction's condition is COND_ALWAYS, the condition field is
12090 changed to inst.uncond_value. This is necessary because instructions shared
12091 between VFP and Neon may be conditional for the VFP variants only, and the
12092 unconditional Neon version must have, e.g., 0xF in the condition field. */
12093
12094static int
12095vfp_or_neon_is_neon (unsigned check)
12096{
12097 /* Conditions are always legal in Thumb mode (IT blocks). */
12098 if (!thumb_mode && (check & NEON_CHECK_CC))
12099 {
12100 if (inst.cond != COND_ALWAYS)
12101 {
12102 first_error (_(BAD_COND));
12103 return FAIL;
12104 }
12105 if (inst.uncond_value != -1)
12106 inst.instruction |= inst.uncond_value << 28;
12107 }
12108
12109 if ((check & NEON_CHECK_ARCH)
12110 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12111 {
12112 first_error (_(BAD_FPU));
12113 return FAIL;
12114 }
12115
12116 return SUCCESS;
12117}
12118
5287ad62
JB
12119static void
12120do_neon_addsub_if_i (void)
12121{
037e8744
JB
12122 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12123 return;
12124
12125 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12126 return;
12127
5287ad62
JB
12128 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12129 affected if we specify unsigned args. */
dcbf9037 12130 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12131}
12132
12133/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12134 result to be:
12135 V<op> A,B (A is operand 0, B is operand 2)
12136 to mean:
12137 V<op> A,B,A
12138 not:
12139 V<op> A,B,B
12140 so handle that case specially. */
12141
12142static void
12143neon_exchange_operands (void)
12144{
12145 void *scratch = alloca (sizeof (inst.operands[0]));
12146 if (inst.operands[1].present)
12147 {
12148 /* Swap operands[1] and operands[2]. */
12149 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12150 inst.operands[1] = inst.operands[2];
12151 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12152 }
12153 else
12154 {
12155 inst.operands[1] = inst.operands[2];
12156 inst.operands[2] = inst.operands[0];
12157 }
12158}
12159
12160static void
12161neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12162{
12163 if (inst.operands[2].isreg)
12164 {
12165 if (invert)
12166 neon_exchange_operands ();
dcbf9037 12167 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12168 }
12169 else
12170 {
037e8744 12171 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12172 struct neon_type_el et = neon_check_type (2, rs,
12173 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12174
12175 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12176 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12177 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12178 inst.instruction |= LOW4 (inst.operands[1].reg);
12179 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12180 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12181 inst.instruction |= (et.type == NT_float) << 10;
12182 inst.instruction |= neon_logbits (et.size) << 18;
12183
12184 inst.instruction = neon_dp_fixup (inst.instruction);
12185 }
12186}
12187
12188static void
12189do_neon_cmp (void)
12190{
12191 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12192}
12193
12194static void
12195do_neon_cmp_inv (void)
12196{
12197 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12198}
12199
12200static void
12201do_neon_ceq (void)
12202{
12203 neon_compare (N_IF_32, N_IF_32, FALSE);
12204}
12205
12206/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12207 scalars, which are encoded in 5 bits, M : Rm.
12208 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12209 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12210 index in M. */
12211
12212static unsigned
12213neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12214{
dcbf9037
JB
12215 unsigned regno = NEON_SCALAR_REG (scalar);
12216 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12217
12218 switch (elsize)
12219 {
12220 case 16:
12221 if (regno > 7 || elno > 3)
12222 goto bad_scalar;
12223 return regno | (elno << 3);
12224
12225 case 32:
12226 if (regno > 15 || elno > 1)
12227 goto bad_scalar;
12228 return regno | (elno << 4);
12229
12230 default:
12231 bad_scalar:
dcbf9037 12232 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12233 }
12234
12235 return 0;
12236}
12237
12238/* Encode multiply / multiply-accumulate scalar instructions. */
12239
12240static void
12241neon_mul_mac (struct neon_type_el et, int ubit)
12242{
dcbf9037
JB
12243 unsigned scalar;
12244
12245 /* Give a more helpful error message if we have an invalid type. */
12246 if (et.type == NT_invtype)
12247 return;
12248
12249 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12250 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12251 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12252 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12253 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12254 inst.instruction |= LOW4 (scalar);
12255 inst.instruction |= HI1 (scalar) << 5;
12256 inst.instruction |= (et.type == NT_float) << 8;
12257 inst.instruction |= neon_logbits (et.size) << 20;
12258 inst.instruction |= (ubit != 0) << 24;
12259
12260 inst.instruction = neon_dp_fixup (inst.instruction);
12261}
12262
12263static void
12264do_neon_mac_maybe_scalar (void)
12265{
037e8744
JB
12266 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12267 return;
12268
12269 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12270 return;
12271
5287ad62
JB
12272 if (inst.operands[2].isscalar)
12273 {
037e8744 12274 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12275 struct neon_type_el et = neon_check_type (3, rs,
12276 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12277 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12278 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12279 }
12280 else
428e3f1f
PB
12281 {
12282 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12283 affected if we specify unsigned args. */
12284 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12285 }
5287ad62
JB
12286}
12287
12288static void
12289do_neon_tst (void)
12290{
037e8744 12291 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12292 struct neon_type_el et = neon_check_type (3, rs,
12293 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12294 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12295}
12296
12297/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12298 same types as the MAC equivalents. The polynomial type for this instruction
12299 is encoded the same as the integer type. */
12300
12301static void
12302do_neon_mul (void)
12303{
037e8744
JB
12304 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12305 return;
12306
12307 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12308 return;
12309
5287ad62
JB
12310 if (inst.operands[2].isscalar)
12311 do_neon_mac_maybe_scalar ();
12312 else
dcbf9037 12313 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12314}
12315
12316static void
12317do_neon_qdmulh (void)
12318{
12319 if (inst.operands[2].isscalar)
12320 {
037e8744 12321 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12322 struct neon_type_el et = neon_check_type (3, rs,
12323 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12324 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12325 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12326 }
12327 else
12328 {
037e8744 12329 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12330 struct neon_type_el et = neon_check_type (3, rs,
12331 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12332 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12333 /* The U bit (rounding) comes from bit mask. */
037e8744 12334 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12335 }
12336}
12337
12338static void
12339do_neon_fcmp_absolute (void)
12340{
037e8744 12341 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12342 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12343 /* Size field comes from bit mask. */
037e8744 12344 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12345}
12346
12347static void
12348do_neon_fcmp_absolute_inv (void)
12349{
12350 neon_exchange_operands ();
12351 do_neon_fcmp_absolute ();
12352}
12353
12354static void
12355do_neon_step (void)
12356{
037e8744 12357 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12358 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12359 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12360}
12361
12362static void
12363do_neon_abs_neg (void)
12364{
037e8744
JB
12365 enum neon_shape rs;
12366 struct neon_type_el et;
12367
12368 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12369 return;
12370
12371 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12372 return;
12373
12374 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12375 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
12376
5287ad62
JB
12377 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12378 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12379 inst.instruction |= LOW4 (inst.operands[1].reg);
12380 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12381 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12382 inst.instruction |= (et.type == NT_float) << 10;
12383 inst.instruction |= neon_logbits (et.size) << 18;
12384
12385 inst.instruction = neon_dp_fixup (inst.instruction);
12386}
12387
12388static void
12389do_neon_sli (void)
12390{
037e8744 12391 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12392 struct neon_type_el et = neon_check_type (2, rs,
12393 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12394 int imm = inst.operands[2].imm;
12395 constraint (imm < 0 || (unsigned)imm >= et.size,
12396 _("immediate out of range for insert"));
037e8744 12397 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12398}
12399
12400static void
12401do_neon_sri (void)
12402{
037e8744 12403 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12404 struct neon_type_el et = neon_check_type (2, rs,
12405 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12406 int imm = inst.operands[2].imm;
12407 constraint (imm < 1 || (unsigned)imm > et.size,
12408 _("immediate out of range for insert"));
037e8744 12409 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12410}
12411
12412static void
12413do_neon_qshlu_imm (void)
12414{
037e8744 12415 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12416 struct neon_type_el et = neon_check_type (2, rs,
12417 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12418 int imm = inst.operands[2].imm;
12419 constraint (imm < 0 || (unsigned)imm >= et.size,
12420 _("immediate out of range for shift"));
12421 /* Only encodes the 'U present' variant of the instruction.
12422 In this case, signed types have OP (bit 8) set to 0.
12423 Unsigned types have OP set to 1. */
12424 inst.instruction |= (et.type == NT_unsigned) << 8;
12425 /* The rest of the bits are the same as other immediate shifts. */
037e8744 12426 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12427}
12428
12429static void
12430do_neon_qmovn (void)
12431{
12432 struct neon_type_el et = neon_check_type (2, NS_DQ,
12433 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12434 /* Saturating move where operands can be signed or unsigned, and the
12435 destination has the same signedness. */
12436 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12437 if (et.type == NT_unsigned)
12438 inst.instruction |= 0xc0;
12439 else
12440 inst.instruction |= 0x80;
12441 neon_two_same (0, 1, et.size / 2);
12442}
12443
12444static void
12445do_neon_qmovun (void)
12446{
12447 struct neon_type_el et = neon_check_type (2, NS_DQ,
12448 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12449 /* Saturating move with unsigned results. Operands must be signed. */
12450 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12451 neon_two_same (0, 1, et.size / 2);
12452}
12453
12454static void
12455do_neon_rshift_sat_narrow (void)
12456{
12457 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12458 or unsigned. If operands are unsigned, results must also be unsigned. */
12459 struct neon_type_el et = neon_check_type (2, NS_DQI,
12460 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12461 int imm = inst.operands[2].imm;
12462 /* This gets the bounds check, size encoding and immediate bits calculation
12463 right. */
12464 et.size /= 2;
12465
12466 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12467 VQMOVN.I<size> <Dd>, <Qm>. */
12468 if (imm == 0)
12469 {
12470 inst.operands[2].present = 0;
12471 inst.instruction = N_MNEM_vqmovn;
12472 do_neon_qmovn ();
12473 return;
12474 }
12475
12476 constraint (imm < 1 || (unsigned)imm > et.size,
12477 _("immediate out of range"));
12478 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12479}
12480
12481static void
12482do_neon_rshift_sat_narrow_u (void)
12483{
12484 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12485 or unsigned. If operands are unsigned, results must also be unsigned. */
12486 struct neon_type_el et = neon_check_type (2, NS_DQI,
12487 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12488 int imm = inst.operands[2].imm;
12489 /* This gets the bounds check, size encoding and immediate bits calculation
12490 right. */
12491 et.size /= 2;
12492
12493 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12494 VQMOVUN.I<size> <Dd>, <Qm>. */
12495 if (imm == 0)
12496 {
12497 inst.operands[2].present = 0;
12498 inst.instruction = N_MNEM_vqmovun;
12499 do_neon_qmovun ();
12500 return;
12501 }
12502
12503 constraint (imm < 1 || (unsigned)imm > et.size,
12504 _("immediate out of range"));
12505 /* FIXME: The manual is kind of unclear about what value U should have in
12506 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12507 must be 1. */
12508 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12509}
12510
12511static void
12512do_neon_movn (void)
12513{
12514 struct neon_type_el et = neon_check_type (2, NS_DQ,
12515 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12516 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12517 neon_two_same (0, 1, et.size / 2);
12518}
12519
12520static void
12521do_neon_rshift_narrow (void)
12522{
12523 struct neon_type_el et = neon_check_type (2, NS_DQI,
12524 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12525 int imm = inst.operands[2].imm;
12526 /* This gets the bounds check, size encoding and immediate bits calculation
12527 right. */
12528 et.size /= 2;
12529
12530 /* If immediate is zero then we are a pseudo-instruction for
12531 VMOVN.I<size> <Dd>, <Qm> */
12532 if (imm == 0)
12533 {
12534 inst.operands[2].present = 0;
12535 inst.instruction = N_MNEM_vmovn;
12536 do_neon_movn ();
12537 return;
12538 }
12539
12540 constraint (imm < 1 || (unsigned)imm > et.size,
12541 _("immediate out of range for narrowing operation"));
12542 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12543}
12544
12545static void
12546do_neon_shll (void)
12547{
12548 /* FIXME: Type checking when lengthening. */
12549 struct neon_type_el et = neon_check_type (2, NS_QDI,
12550 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12551 unsigned imm = inst.operands[2].imm;
12552
12553 if (imm == et.size)
12554 {
12555 /* Maximum shift variant. */
12556 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12557 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12558 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12559 inst.instruction |= LOW4 (inst.operands[1].reg);
12560 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12561 inst.instruction |= neon_logbits (et.size) << 18;
12562
12563 inst.instruction = neon_dp_fixup (inst.instruction);
12564 }
12565 else
12566 {
12567 /* A more-specific type check for non-max versions. */
12568 et = neon_check_type (2, NS_QDI,
12569 N_EQK | N_DBL, N_SU_32 | N_KEY);
12570 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12571 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12572 }
12573}
12574
037e8744 12575/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12576 the current instruction is. */
12577
12578static int
12579neon_cvt_flavour (enum neon_shape rs)
12580{
037e8744
JB
12581#define CVT_VAR(C,X,Y) \
12582 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12583 if (et.type != NT_invtype) \
12584 { \
12585 inst.error = NULL; \
12586 return (C); \
5287ad62
JB
12587 }
12588 struct neon_type_el et;
037e8744
JB
12589 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12590 || rs == NS_FF) ? N_VFP : 0;
12591 /* The instruction versions which take an immediate take one register
12592 argument, which is extended to the width of the full register. Thus the
12593 "source" and "destination" registers must have the same width. Hack that
12594 here by making the size equal to the key (wider, in this case) operand. */
12595 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5287ad62
JB
12596
12597 CVT_VAR (0, N_S32, N_F32);
12598 CVT_VAR (1, N_U32, N_F32);
12599 CVT_VAR (2, N_F32, N_S32);
12600 CVT_VAR (3, N_F32, N_U32);
12601
037e8744
JB
12602 whole_reg = N_VFP;
12603
12604 /* VFP instructions. */
12605 CVT_VAR (4, N_F32, N_F64);
12606 CVT_VAR (5, N_F64, N_F32);
12607 CVT_VAR (6, N_S32, N_F64 | key);
12608 CVT_VAR (7, N_U32, N_F64 | key);
12609 CVT_VAR (8, N_F64 | key, N_S32);
12610 CVT_VAR (9, N_F64 | key, N_U32);
12611 /* VFP instructions with bitshift. */
12612 CVT_VAR (10, N_F32 | key, N_S16);
12613 CVT_VAR (11, N_F32 | key, N_U16);
12614 CVT_VAR (12, N_F64 | key, N_S16);
12615 CVT_VAR (13, N_F64 | key, N_U16);
12616 CVT_VAR (14, N_S16, N_F32 | key);
12617 CVT_VAR (15, N_U16, N_F32 | key);
12618 CVT_VAR (16, N_S16, N_F64 | key);
12619 CVT_VAR (17, N_U16, N_F64 | key);
12620
5287ad62
JB
12621 return -1;
12622#undef CVT_VAR
12623}
12624
037e8744
JB
12625/* Neon-syntax VFP conversions. */
12626
5287ad62 12627static void
037e8744 12628do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12629{
037e8744
JB
12630 const char *opname = 0;
12631
12632 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12633 {
037e8744
JB
12634 /* Conversions with immediate bitshift. */
12635 const char *enc[] =
12636 {
12637 "ftosls",
12638 "ftouls",
12639 "fsltos",
12640 "fultos",
12641 NULL,
12642 NULL,
12643 "ftosld",
12644 "ftould",
12645 "fsltod",
12646 "fultod",
12647 "fshtos",
12648 "fuhtos",
12649 "fshtod",
12650 "fuhtod",
12651 "ftoshs",
12652 "ftouhs",
12653 "ftoshd",
12654 "ftouhd"
12655 };
12656
12657 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12658 {
12659 opname = enc[flavour];
12660 constraint (inst.operands[0].reg != inst.operands[1].reg,
12661 _("operands 0 and 1 must be the same register"));
12662 inst.operands[1] = inst.operands[2];
12663 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12664 }
5287ad62
JB
12665 }
12666 else
12667 {
037e8744
JB
12668 /* Conversions without bitshift. */
12669 const char *enc[] =
12670 {
12671 "ftosis",
12672 "ftouis",
12673 "fsitos",
12674 "fuitos",
12675 "fcvtsd",
12676 "fcvtds",
12677 "ftosid",
12678 "ftouid",
12679 "fsitod",
12680 "fuitod"
12681 };
12682
12683 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12684 opname = enc[flavour];
12685 }
12686
12687 if (opname)
12688 do_vfp_nsyn_opcode (opname);
12689}
12690
12691static void
12692do_vfp_nsyn_cvtz (void)
12693{
12694 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12695 int flavour = neon_cvt_flavour (rs);
12696 const char *enc[] =
12697 {
12698 "ftosizs",
12699 "ftouizs",
12700 NULL,
12701 NULL,
12702 NULL,
12703 NULL,
12704 "ftosizd",
12705 "ftouizd"
12706 };
12707
12708 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12709 do_vfp_nsyn_opcode (enc[flavour]);
12710}
12711
12712static void
12713do_neon_cvt (void)
12714{
12715 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12716 NS_FD, NS_DF, NS_FF, NS_NULL);
12717 int flavour = neon_cvt_flavour (rs);
12718
12719 /* VFP rather than Neon conversions. */
12720 if (flavour >= 4)
12721 {
12722 do_vfp_nsyn_cvt (rs, flavour);
12723 return;
12724 }
12725
12726 switch (rs)
12727 {
12728 case NS_DDI:
12729 case NS_QQI:
12730 {
12731 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12732 return;
12733
12734 /* Fixed-point conversion with #0 immediate is encoded as an
12735 integer conversion. */
12736 if (inst.operands[2].present && inst.operands[2].imm == 0)
12737 goto int_encode;
12738 unsigned immbits = 32 - inst.operands[2].imm;
12739 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12740 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12741 if (flavour != -1)
12742 inst.instruction |= enctab[flavour];
12743 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12744 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12745 inst.instruction |= LOW4 (inst.operands[1].reg);
12746 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12747 inst.instruction |= neon_quad (rs) << 6;
12748 inst.instruction |= 1 << 21;
12749 inst.instruction |= immbits << 16;
12750
12751 inst.instruction = neon_dp_fixup (inst.instruction);
12752 }
12753 break;
12754
12755 case NS_DD:
12756 case NS_QQ:
12757 int_encode:
12758 {
12759 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12760
12761 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12762
12763 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12764 return;
12765
12766 if (flavour != -1)
12767 inst.instruction |= enctab[flavour];
12768
12769 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12770 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12771 inst.instruction |= LOW4 (inst.operands[1].reg);
12772 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12773 inst.instruction |= neon_quad (rs) << 6;
12774 inst.instruction |= 2 << 18;
12775
12776 inst.instruction = neon_dp_fixup (inst.instruction);
12777 }
12778 break;
12779
12780 default:
12781 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12782 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12783 }
5287ad62
JB
12784}
12785
12786static void
12787neon_move_immediate (void)
12788{
037e8744
JB
12789 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12790 struct neon_type_el et = neon_check_type (2, rs,
12791 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 12792 unsigned immlo, immhi = 0, immbits;
c96612cc 12793 int op, cmode, float_p;
5287ad62 12794
037e8744
JB
12795 constraint (et.type == NT_invtype,
12796 _("operand size must be specified for immediate VMOV"));
12797
5287ad62
JB
12798 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12799 op = (inst.instruction & (1 << 5)) != 0;
12800
12801 immlo = inst.operands[1].imm;
12802 if (inst.operands[1].regisimm)
12803 immhi = inst.operands[1].reg;
12804
12805 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12806 _("immediate has bits set outside the operand size"));
12807
c96612cc
JB
12808 float_p = inst.operands[1].immisfloat;
12809
12810 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 12811 et.size, et.type)) == FAIL)
5287ad62
JB
12812 {
12813 /* Invert relevant bits only. */
12814 neon_invert_size (&immlo, &immhi, et.size);
12815 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12816 with one or the other; those cases are caught by
12817 neon_cmode_for_move_imm. */
12818 op = !op;
c96612cc
JB
12819 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
12820 &op, et.size, et.type)) == FAIL)
5287ad62 12821 {
dcbf9037 12822 first_error (_("immediate out of range"));
5287ad62
JB
12823 return;
12824 }
12825 }
12826
12827 inst.instruction &= ~(1 << 5);
12828 inst.instruction |= op << 5;
12829
12830 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12831 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12832 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12833 inst.instruction |= cmode << 8;
12834
12835 neon_write_immbits (immbits);
12836}
12837
12838static void
12839do_neon_mvn (void)
12840{
12841 if (inst.operands[1].isreg)
12842 {
037e8744 12843 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12844
12845 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12846 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12847 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12848 inst.instruction |= LOW4 (inst.operands[1].reg);
12849 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12850 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12851 }
12852 else
12853 {
12854 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12855 neon_move_immediate ();
12856 }
12857
12858 inst.instruction = neon_dp_fixup (inst.instruction);
12859}
12860
12861/* Encode instructions of form:
12862
12863 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12864 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12865
12866*/
12867
12868static void
12869neon_mixed_length (struct neon_type_el et, unsigned size)
12870{
12871 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12872 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12873 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12874 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12875 inst.instruction |= LOW4 (inst.operands[2].reg);
12876 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12877 inst.instruction |= (et.type == NT_unsigned) << 24;
12878 inst.instruction |= neon_logbits (size) << 20;
12879
12880 inst.instruction = neon_dp_fixup (inst.instruction);
12881}
12882
12883static void
12884do_neon_dyadic_long (void)
12885{
12886 /* FIXME: Type checking for lengthening op. */
12887 struct neon_type_el et = neon_check_type (3, NS_QDD,
12888 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12889 neon_mixed_length (et, et.size);
12890}
12891
12892static void
12893do_neon_abal (void)
12894{
12895 struct neon_type_el et = neon_check_type (3, NS_QDD,
12896 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12897 neon_mixed_length (et, et.size);
12898}
12899
12900static void
12901neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12902{
12903 if (inst.operands[2].isscalar)
12904 {
dcbf9037
JB
12905 struct neon_type_el et = neon_check_type (3, NS_QDS,
12906 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12907 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12908 neon_mul_mac (et, et.type == NT_unsigned);
12909 }
12910 else
12911 {
12912 struct neon_type_el et = neon_check_type (3, NS_QDD,
12913 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12914 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12915 neon_mixed_length (et, et.size);
12916 }
12917}
12918
12919static void
12920do_neon_mac_maybe_scalar_long (void)
12921{
12922 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12923}
12924
12925static void
12926do_neon_dyadic_wide (void)
12927{
12928 struct neon_type_el et = neon_check_type (3, NS_QQD,
12929 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12930 neon_mixed_length (et, et.size);
12931}
12932
12933static void
12934do_neon_dyadic_narrow (void)
12935{
12936 struct neon_type_el et = neon_check_type (3, NS_QDD,
12937 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
12938 /* Operand sign is unimportant, and the U bit is part of the opcode,
12939 so force the operand type to integer. */
12940 et.type = NT_integer;
5287ad62
JB
12941 neon_mixed_length (et, et.size / 2);
12942}
12943
12944static void
12945do_neon_mul_sat_scalar_long (void)
12946{
12947 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12948}
12949
12950static void
12951do_neon_vmull (void)
12952{
12953 if (inst.operands[2].isscalar)
12954 do_neon_mac_maybe_scalar_long ();
12955 else
12956 {
12957 struct neon_type_el et = neon_check_type (3, NS_QDD,
12958 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12959 if (et.type == NT_poly)
12960 inst.instruction = NEON_ENC_POLY (inst.instruction);
12961 else
12962 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12963 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12964 zero. Should be OK as-is. */
12965 neon_mixed_length (et, et.size);
12966 }
12967}
12968
12969static void
12970do_neon_ext (void)
12971{
037e8744 12972 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12973 struct neon_type_el et = neon_check_type (3, rs,
12974 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12975 unsigned imm = (inst.operands[3].imm * et.size) / 8;
3b8d421e 12976 constraint (imm >= (neon_quad (rs) ? 16 : 8), _("shift out of range"));
5287ad62
JB
12977 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12978 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12979 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12980 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12981 inst.instruction |= LOW4 (inst.operands[2].reg);
12982 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12983 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12984 inst.instruction |= imm << 8;
12985
12986 inst.instruction = neon_dp_fixup (inst.instruction);
12987}
12988
12989static void
12990do_neon_rev (void)
12991{
037e8744 12992 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12993 struct neon_type_el et = neon_check_type (2, rs,
12994 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12995 unsigned op = (inst.instruction >> 7) & 3;
12996 /* N (width of reversed regions) is encoded as part of the bitmask. We
12997 extract it here to check the elements to be reversed are smaller.
12998 Otherwise we'd get a reserved instruction. */
12999 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
13000 assert (elsize != 0);
13001 constraint (et.size >= elsize,
13002 _("elements must be smaller than reversal region"));
037e8744 13003 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13004}
13005
13006static void
13007do_neon_dup (void)
13008{
13009 if (inst.operands[1].isscalar)
13010 {
037e8744 13011 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13012 struct neon_type_el et = neon_check_type (2, rs,
13013 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13014 unsigned sizebits = et.size >> 3;
dcbf9037 13015 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13016 int logsize = neon_logbits (et.size);
dcbf9037 13017 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13018
13019 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13020 return;
13021
5287ad62
JB
13022 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13023 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13024 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13025 inst.instruction |= LOW4 (dm);
13026 inst.instruction |= HI1 (dm) << 5;
037e8744 13027 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13028 inst.instruction |= x << 17;
13029 inst.instruction |= sizebits << 16;
13030
13031 inst.instruction = neon_dp_fixup (inst.instruction);
13032 }
13033 else
13034 {
037e8744
JB
13035 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13036 struct neon_type_el et = neon_check_type (2, rs,
13037 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13038 /* Duplicate ARM register to lanes of vector. */
13039 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13040 switch (et.size)
13041 {
13042 case 8: inst.instruction |= 0x400000; break;
13043 case 16: inst.instruction |= 0x000020; break;
13044 case 32: inst.instruction |= 0x000000; break;
13045 default: break;
13046 }
13047 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13048 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13049 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13050 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13051 /* The encoding for this instruction is identical for the ARM and Thumb
13052 variants, except for the condition field. */
037e8744 13053 do_vfp_cond_or_thumb ();
5287ad62
JB
13054 }
13055}
13056
13057/* VMOV has particularly many variations. It can be one of:
13058 0. VMOV<c><q> <Qd>, <Qm>
13059 1. VMOV<c><q> <Dd>, <Dm>
13060 (Register operations, which are VORR with Rm = Rn.)
13061 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13062 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13063 (Immediate loads.)
13064 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13065 (ARM register to scalar.)
13066 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13067 (Two ARM registers to vector.)
13068 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13069 (Scalar to ARM register.)
13070 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13071 (Vector to two ARM registers.)
037e8744
JB
13072 8. VMOV.F32 <Sd>, <Sm>
13073 9. VMOV.F64 <Dd>, <Dm>
13074 (VFP register moves.)
13075 10. VMOV.F32 <Sd>, #imm
13076 11. VMOV.F64 <Dd>, #imm
13077 (VFP float immediate load.)
13078 12. VMOV <Rd>, <Sm>
13079 (VFP single to ARM reg.)
13080 13. VMOV <Sd>, <Rm>
13081 (ARM reg to VFP single.)
13082 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13083 (Two ARM regs to two VFP singles.)
13084 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13085 (Two VFP singles to two ARM regs.)
5287ad62 13086
037e8744
JB
13087 These cases can be disambiguated using neon_select_shape, except cases 1/9
13088 and 3/11 which depend on the operand type too.
5287ad62
JB
13089
13090 All the encoded bits are hardcoded by this function.
13091
b7fc2769
JB
13092 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13093 Cases 5, 7 may be used with VFPv2 and above.
13094
5287ad62
JB
13095 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13096 can specify a type where it doesn't make sense to, and is ignored).
13097*/
13098
13099static void
13100do_neon_mov (void)
13101{
037e8744
JB
13102 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13103 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13104 NS_NULL);
13105 struct neon_type_el et;
13106 const char *ldconst = 0;
5287ad62 13107
037e8744 13108 switch (rs)
5287ad62 13109 {
037e8744
JB
13110 case NS_DD: /* case 1/9. */
13111 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13112 /* It is not an error here if no type is given. */
13113 inst.error = NULL;
13114 if (et.type == NT_float && et.size == 64)
5287ad62 13115 {
037e8744
JB
13116 do_vfp_nsyn_opcode ("fcpyd");
13117 break;
5287ad62 13118 }
037e8744 13119 /* fall through. */
5287ad62 13120
037e8744
JB
13121 case NS_QQ: /* case 0/1. */
13122 {
13123 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13124 return;
13125 /* The architecture manual I have doesn't explicitly state which
13126 value the U bit should have for register->register moves, but
13127 the equivalent VORR instruction has U = 0, so do that. */
13128 inst.instruction = 0x0200110;
13129 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13130 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13131 inst.instruction |= LOW4 (inst.operands[1].reg);
13132 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13133 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13134 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13135 inst.instruction |= neon_quad (rs) << 6;
13136
13137 inst.instruction = neon_dp_fixup (inst.instruction);
13138 }
13139 break;
13140
13141 case NS_DI: /* case 3/11. */
13142 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13143 inst.error = NULL;
13144 if (et.type == NT_float && et.size == 64)
5287ad62 13145 {
037e8744
JB
13146 /* case 11 (fconstd). */
13147 ldconst = "fconstd";
13148 goto encode_fconstd;
5287ad62 13149 }
037e8744
JB
13150 /* fall through. */
13151
13152 case NS_QI: /* case 2/3. */
13153 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13154 return;
13155 inst.instruction = 0x0800010;
13156 neon_move_immediate ();
13157 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62
JB
13158 break;
13159
037e8744
JB
13160 case NS_SR: /* case 4. */
13161 {
13162 unsigned bcdebits = 0;
13163 struct neon_type_el et = neon_check_type (2, NS_NULL,
13164 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13165 int logsize = neon_logbits (et.size);
13166 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13167 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13168
13169 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13170 _(BAD_FPU));
13171 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13172 && et.size != 32, _(BAD_FPU));
13173 constraint (et.type == NT_invtype, _("bad type for scalar"));
13174 constraint (x >= 64 / et.size, _("scalar index out of range"));
13175
13176 switch (et.size)
13177 {
13178 case 8: bcdebits = 0x8; break;
13179 case 16: bcdebits = 0x1; break;
13180 case 32: bcdebits = 0x0; break;
13181 default: ;
13182 }
13183
13184 bcdebits |= x << logsize;
13185
13186 inst.instruction = 0xe000b10;
13187 do_vfp_cond_or_thumb ();
13188 inst.instruction |= LOW4 (dn) << 16;
13189 inst.instruction |= HI1 (dn) << 7;
13190 inst.instruction |= inst.operands[1].reg << 12;
13191 inst.instruction |= (bcdebits & 3) << 5;
13192 inst.instruction |= (bcdebits >> 2) << 21;
13193 }
13194 break;
13195
13196 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13197 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13198 _(BAD_FPU));
b7fc2769 13199
037e8744
JB
13200 inst.instruction = 0xc400b10;
13201 do_vfp_cond_or_thumb ();
13202 inst.instruction |= LOW4 (inst.operands[0].reg);
13203 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13204 inst.instruction |= inst.operands[1].reg << 12;
13205 inst.instruction |= inst.operands[2].reg << 16;
13206 break;
13207
13208 case NS_RS: /* case 6. */
13209 {
13210 struct neon_type_el et = neon_check_type (2, NS_NULL,
13211 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13212 unsigned logsize = neon_logbits (et.size);
13213 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13214 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13215 unsigned abcdebits = 0;
13216
13217 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13218 _(BAD_FPU));
13219 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13220 && et.size != 32, _(BAD_FPU));
13221 constraint (et.type == NT_invtype, _("bad type for scalar"));
13222 constraint (x >= 64 / et.size, _("scalar index out of range"));
13223
13224 switch (et.size)
13225 {
13226 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13227 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13228 case 32: abcdebits = 0x00; break;
13229 default: ;
13230 }
13231
13232 abcdebits |= x << logsize;
13233 inst.instruction = 0xe100b10;
13234 do_vfp_cond_or_thumb ();
13235 inst.instruction |= LOW4 (dn) << 16;
13236 inst.instruction |= HI1 (dn) << 7;
13237 inst.instruction |= inst.operands[0].reg << 12;
13238 inst.instruction |= (abcdebits & 3) << 5;
13239 inst.instruction |= (abcdebits >> 2) << 21;
13240 }
13241 break;
13242
13243 case NS_RRD: /* case 7 (fmrrd). */
13244 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13245 _(BAD_FPU));
13246
13247 inst.instruction = 0xc500b10;
13248 do_vfp_cond_or_thumb ();
13249 inst.instruction |= inst.operands[0].reg << 12;
13250 inst.instruction |= inst.operands[1].reg << 16;
13251 inst.instruction |= LOW4 (inst.operands[2].reg);
13252 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13253 break;
13254
13255 case NS_FF: /* case 8 (fcpys). */
13256 do_vfp_nsyn_opcode ("fcpys");
13257 break;
13258
13259 case NS_FI: /* case 10 (fconsts). */
13260 ldconst = "fconsts";
13261 encode_fconstd:
13262 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13263 {
037e8744
JB
13264 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13265 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13266 }
13267 else
037e8744
JB
13268 first_error (_("immediate out of range"));
13269 break;
13270
13271 case NS_RF: /* case 12 (fmrs). */
13272 do_vfp_nsyn_opcode ("fmrs");
13273 break;
13274
13275 case NS_FR: /* case 13 (fmsr). */
13276 do_vfp_nsyn_opcode ("fmsr");
13277 break;
13278
13279 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13280 (one of which is a list), but we have parsed four. Do some fiddling to
13281 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13282 expect. */
13283 case NS_RRFF: /* case 14 (fmrrs). */
13284 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13285 _("VFP registers must be adjacent"));
13286 inst.operands[2].imm = 2;
13287 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13288 do_vfp_nsyn_opcode ("fmrrs");
13289 break;
13290
13291 case NS_FFRR: /* case 15 (fmsrr). */
13292 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13293 _("VFP registers must be adjacent"));
13294 inst.operands[1] = inst.operands[2];
13295 inst.operands[2] = inst.operands[3];
13296 inst.operands[0].imm = 2;
13297 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13298 do_vfp_nsyn_opcode ("fmsrr");
5287ad62
JB
13299 break;
13300
13301 default:
13302 abort ();
13303 }
13304}
13305
13306static void
13307do_neon_rshift_round_imm (void)
13308{
037e8744 13309 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13310 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13311 int imm = inst.operands[2].imm;
13312
13313 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13314 if (imm == 0)
13315 {
13316 inst.operands[2].present = 0;
13317 do_neon_mov ();
13318 return;
13319 }
13320
13321 constraint (imm < 1 || (unsigned)imm > et.size,
13322 _("immediate out of range for shift"));
037e8744 13323 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13324 et.size - imm);
13325}
13326
13327static void
13328do_neon_movl (void)
13329{
13330 struct neon_type_el et = neon_check_type (2, NS_QD,
13331 N_EQK | N_DBL, N_SU_32 | N_KEY);
13332 unsigned sizebits = et.size >> 3;
13333 inst.instruction |= sizebits << 19;
13334 neon_two_same (0, et.type == NT_unsigned, -1);
13335}
13336
13337static void
13338do_neon_trn (void)
13339{
037e8744 13340 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13341 struct neon_type_el et = neon_check_type (2, rs,
13342 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13343 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13344 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13345}
13346
13347static void
13348do_neon_zip_uzp (void)
13349{
037e8744 13350 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13351 struct neon_type_el et = neon_check_type (2, rs,
13352 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13353 if (rs == NS_DD && et.size == 32)
13354 {
13355 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
13356 inst.instruction = N_MNEM_vtrn;
13357 do_neon_trn ();
13358 return;
13359 }
037e8744 13360 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13361}
13362
13363static void
13364do_neon_sat_abs_neg (void)
13365{
037e8744 13366 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13367 struct neon_type_el et = neon_check_type (2, rs,
13368 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13369 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13370}
13371
13372static void
13373do_neon_pair_long (void)
13374{
037e8744 13375 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13376 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
13377 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
13378 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 13379 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13380}
13381
13382static void
13383do_neon_recip_est (void)
13384{
037e8744 13385 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13386 struct neon_type_el et = neon_check_type (2, rs,
13387 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
13388 inst.instruction |= (et.type == NT_float) << 8;
037e8744 13389 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13390}
13391
13392static void
13393do_neon_cls (void)
13394{
037e8744 13395 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13396 struct neon_type_el et = neon_check_type (2, rs,
13397 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 13398 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13399}
13400
13401static void
13402do_neon_clz (void)
13403{
037e8744 13404 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13405 struct neon_type_el et = neon_check_type (2, rs,
13406 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 13407 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13408}
13409
13410static void
13411do_neon_cnt (void)
13412{
037e8744 13413 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13414 struct neon_type_el et = neon_check_type (2, rs,
13415 N_EQK | N_INT, N_8 | N_KEY);
037e8744 13416 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13417}
13418
13419static void
13420do_neon_swp (void)
13421{
037e8744
JB
13422 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13423 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
13424}
13425
13426static void
13427do_neon_tbl_tbx (void)
13428{
13429 unsigned listlenbits;
dcbf9037 13430 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5287ad62
JB
13431
13432 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
13433 {
dcbf9037 13434 first_error (_("bad list length for table lookup"));
5287ad62
JB
13435 return;
13436 }
13437
13438 listlenbits = inst.operands[1].imm - 1;
13439 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13440 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13441 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13442 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13443 inst.instruction |= LOW4 (inst.operands[2].reg);
13444 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13445 inst.instruction |= listlenbits << 8;
13446
13447 inst.instruction = neon_dp_fixup (inst.instruction);
13448}
13449
13450static void
13451do_neon_ldm_stm (void)
13452{
13453 /* P, U and L bits are part of bitmask. */
13454 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13455 unsigned offsetbits = inst.operands[1].imm * 2;
13456
037e8744
JB
13457 if (inst.operands[1].issingle)
13458 {
13459 do_vfp_nsyn_ldm_stm (is_dbmode);
13460 return;
13461 }
13462
5287ad62
JB
13463 constraint (is_dbmode && !inst.operands[0].writeback,
13464 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13465
13466 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13467 _("register list must contain at least 1 and at most 16 "
13468 "registers"));
13469
13470 inst.instruction |= inst.operands[0].reg << 16;
13471 inst.instruction |= inst.operands[0].writeback << 21;
13472 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13473 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13474
13475 inst.instruction |= offsetbits;
13476
037e8744 13477 do_vfp_cond_or_thumb ();
5287ad62
JB
13478}
13479
13480static void
13481do_neon_ldr_str (void)
13482{
5287ad62
JB
13483 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13484
037e8744
JB
13485 if (inst.operands[0].issingle)
13486 {
cd2f129f
JB
13487 if (is_ldr)
13488 do_vfp_nsyn_opcode ("flds");
13489 else
13490 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13491 }
13492 else
5287ad62 13493 {
cd2f129f
JB
13494 if (is_ldr)
13495 do_vfp_nsyn_opcode ("fldd");
5287ad62 13496 else
cd2f129f 13497 do_vfp_nsyn_opcode ("fstd");
5287ad62 13498 }
5287ad62
JB
13499}
13500
13501/* "interleave" version also handles non-interleaving register VLD1/VST1
13502 instructions. */
13503
13504static void
13505do_neon_ld_st_interleave (void)
13506{
037e8744 13507 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13508 N_8 | N_16 | N_32 | N_64);
13509 unsigned alignbits = 0;
13510 unsigned idx;
13511 /* The bits in this table go:
13512 0: register stride of one (0) or two (1)
13513 1,2: register list length, minus one (1, 2, 3, 4).
13514 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13515 We use -1 for invalid entries. */
13516 const int typetable[] =
13517 {
13518 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13519 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13520 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13521 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13522 };
13523 int typebits;
13524
dcbf9037
JB
13525 if (et.type == NT_invtype)
13526 return;
13527
5287ad62
JB
13528 if (inst.operands[1].immisalign)
13529 switch (inst.operands[1].imm >> 8)
13530 {
13531 case 64: alignbits = 1; break;
13532 case 128:
13533 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13534 goto bad_alignment;
13535 alignbits = 2;
13536 break;
13537 case 256:
13538 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13539 goto bad_alignment;
13540 alignbits = 3;
13541 break;
13542 default:
13543 bad_alignment:
dcbf9037 13544 first_error (_("bad alignment"));
5287ad62
JB
13545 return;
13546 }
13547
13548 inst.instruction |= alignbits << 4;
13549 inst.instruction |= neon_logbits (et.size) << 6;
13550
13551 /* Bits [4:6] of the immediate in a list specifier encode register stride
13552 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13553 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13554 up the right value for "type" in a table based on this value and the given
13555 list style, then stick it back. */
13556 idx = ((inst.operands[0].imm >> 4) & 7)
13557 | (((inst.instruction >> 8) & 3) << 3);
13558
13559 typebits = typetable[idx];
13560
13561 constraint (typebits == -1, _("bad list type for instruction"));
13562
13563 inst.instruction &= ~0xf00;
13564 inst.instruction |= typebits << 8;
13565}
13566
13567/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13568 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13569 otherwise. The variable arguments are a list of pairs of legal (size, align)
13570 values, terminated with -1. */
13571
13572static int
13573neon_alignment_bit (int size, int align, int *do_align, ...)
13574{
13575 va_list ap;
13576 int result = FAIL, thissize, thisalign;
13577
13578 if (!inst.operands[1].immisalign)
13579 {
13580 *do_align = 0;
13581 return SUCCESS;
13582 }
13583
13584 va_start (ap, do_align);
13585
13586 do
13587 {
13588 thissize = va_arg (ap, int);
13589 if (thissize == -1)
13590 break;
13591 thisalign = va_arg (ap, int);
13592
13593 if (size == thissize && align == thisalign)
13594 result = SUCCESS;
13595 }
13596 while (result != SUCCESS);
13597
13598 va_end (ap);
13599
13600 if (result == SUCCESS)
13601 *do_align = 1;
13602 else
dcbf9037 13603 first_error (_("unsupported alignment for instruction"));
5287ad62
JB
13604
13605 return result;
13606}
13607
13608static void
13609do_neon_ld_st_lane (void)
13610{
037e8744 13611 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13612 int align_good, do_align = 0;
13613 int logsize = neon_logbits (et.size);
13614 int align = inst.operands[1].imm >> 8;
13615 int n = (inst.instruction >> 8) & 3;
13616 int max_el = 64 / et.size;
13617
dcbf9037
JB
13618 if (et.type == NT_invtype)
13619 return;
13620
5287ad62
JB
13621 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13622 _("bad list length"));
13623 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13624 _("scalar index out of range"));
13625 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13626 && et.size == 8,
13627 _("stride of 2 unavailable when element size is 8"));
13628
13629 switch (n)
13630 {
13631 case 0: /* VLD1 / VST1. */
13632 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13633 32, 32, -1);
13634 if (align_good == FAIL)
13635 return;
13636 if (do_align)
13637 {
13638 unsigned alignbits = 0;
13639 switch (et.size)
13640 {
13641 case 16: alignbits = 0x1; break;
13642 case 32: alignbits = 0x3; break;
13643 default: ;
13644 }
13645 inst.instruction |= alignbits << 4;
13646 }
13647 break;
13648
13649 case 1: /* VLD2 / VST2. */
13650 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13651 32, 64, -1);
13652 if (align_good == FAIL)
13653 return;
13654 if (do_align)
13655 inst.instruction |= 1 << 4;
13656 break;
13657
13658 case 2: /* VLD3 / VST3. */
13659 constraint (inst.operands[1].immisalign,
13660 _("can't use alignment with this instruction"));
13661 break;
13662
13663 case 3: /* VLD4 / VST4. */
13664 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13665 16, 64, 32, 64, 32, 128, -1);
13666 if (align_good == FAIL)
13667 return;
13668 if (do_align)
13669 {
13670 unsigned alignbits = 0;
13671 switch (et.size)
13672 {
13673 case 8: alignbits = 0x1; break;
13674 case 16: alignbits = 0x1; break;
13675 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13676 default: ;
13677 }
13678 inst.instruction |= alignbits << 4;
13679 }
13680 break;
13681
13682 default: ;
13683 }
13684
13685 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13686 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13687 inst.instruction |= 1 << (4 + logsize);
13688
13689 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13690 inst.instruction |= logsize << 10;
13691}
13692
13693/* Encode single n-element structure to all lanes VLD<n> instructions. */
13694
13695static void
13696do_neon_ld_dup (void)
13697{
037e8744 13698 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13699 int align_good, do_align = 0;
13700
dcbf9037
JB
13701 if (et.type == NT_invtype)
13702 return;
13703
5287ad62
JB
13704 switch ((inst.instruction >> 8) & 3)
13705 {
13706 case 0: /* VLD1. */
13707 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13708 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13709 &do_align, 16, 16, 32, 32, -1);
13710 if (align_good == FAIL)
13711 return;
13712 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13713 {
13714 case 1: break;
13715 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13716 default: first_error (_("bad list length")); return;
5287ad62
JB
13717 }
13718 inst.instruction |= neon_logbits (et.size) << 6;
13719 break;
13720
13721 case 1: /* VLD2. */
13722 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13723 &do_align, 8, 16, 16, 32, 32, 64, -1);
13724 if (align_good == FAIL)
13725 return;
13726 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13727 _("bad list length"));
13728 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13729 inst.instruction |= 1 << 5;
13730 inst.instruction |= neon_logbits (et.size) << 6;
13731 break;
13732
13733 case 2: /* VLD3. */
13734 constraint (inst.operands[1].immisalign,
13735 _("can't use alignment with this instruction"));
13736 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13737 _("bad list length"));
13738 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13739 inst.instruction |= 1 << 5;
13740 inst.instruction |= neon_logbits (et.size) << 6;
13741 break;
13742
13743 case 3: /* VLD4. */
13744 {
13745 int align = inst.operands[1].imm >> 8;
13746 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13747 16, 64, 32, 64, 32, 128, -1);
13748 if (align_good == FAIL)
13749 return;
13750 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13751 _("bad list length"));
13752 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13753 inst.instruction |= 1 << 5;
13754 if (et.size == 32 && align == 128)
13755 inst.instruction |= 0x3 << 6;
13756 else
13757 inst.instruction |= neon_logbits (et.size) << 6;
13758 }
13759 break;
13760
13761 default: ;
13762 }
13763
13764 inst.instruction |= do_align << 4;
13765}
13766
13767/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13768 apart from bits [11:4]. */
13769
13770static void
13771do_neon_ldx_stx (void)
13772{
13773 switch (NEON_LANE (inst.operands[0].imm))
13774 {
13775 case NEON_INTERLEAVE_LANES:
13776 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13777 do_neon_ld_st_interleave ();
13778 break;
13779
13780 case NEON_ALL_LANES:
13781 inst.instruction = NEON_ENC_DUP (inst.instruction);
13782 do_neon_ld_dup ();
13783 break;
13784
13785 default:
13786 inst.instruction = NEON_ENC_LANE (inst.instruction);
13787 do_neon_ld_st_lane ();
13788 }
13789
13790 /* L bit comes from bit mask. */
13791 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13792 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13793 inst.instruction |= inst.operands[1].reg << 16;
13794
13795 if (inst.operands[1].postind)
13796 {
13797 int postreg = inst.operands[1].imm & 0xf;
13798 constraint (!inst.operands[1].immisreg,
13799 _("post-index must be a register"));
13800 constraint (postreg == 0xd || postreg == 0xf,
13801 _("bad register for post-index"));
13802 inst.instruction |= postreg;
13803 }
13804 else if (inst.operands[1].writeback)
13805 {
13806 inst.instruction |= 0xd;
13807 }
13808 else
13809 inst.instruction |= 0xf;
13810
13811 if (thumb_mode)
13812 inst.instruction |= 0xf9000000;
13813 else
13814 inst.instruction |= 0xf4000000;
13815}
13816
13817\f
13818/* Overall per-instruction processing. */
13819
13820/* We need to be able to fix up arbitrary expressions in some statements.
13821 This is so that we can handle symbols that are an arbitrary distance from
13822 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13823 which returns part of an address in a form which will be valid for
13824 a data instruction. We do this by pushing the expression into a symbol
13825 in the expr_section, and creating a fix for that. */
13826
13827static void
13828fix_new_arm (fragS * frag,
13829 int where,
13830 short int size,
13831 expressionS * exp,
13832 int pc_rel,
13833 int reloc)
13834{
13835 fixS * new_fix;
13836
13837 switch (exp->X_op)
13838 {
13839 case O_constant:
13840 case O_symbol:
13841 case O_add:
13842 case O_subtract:
13843 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13844 break;
13845
13846 default:
13847 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13848 pc_rel, reloc);
13849 break;
13850 }
13851
13852 /* Mark whether the fix is to a THUMB instruction, or an ARM
13853 instruction. */
13854 new_fix->tc_fix_data = thumb_mode;
13855}
13856
13857/* Create a frg for an instruction requiring relaxation. */
13858static void
13859output_relax_insn (void)
13860{
13861 char * to;
13862 symbolS *sym;
0110f2b8
PB
13863 int offset;
13864
6e1cb1a6
PB
13865 /* The size of the instruction is unknown, so tie the debug info to the
13866 start of the instruction. */
13867 dwarf2_emit_insn (0);
6e1cb1a6 13868
0110f2b8
PB
13869 switch (inst.reloc.exp.X_op)
13870 {
13871 case O_symbol:
13872 sym = inst.reloc.exp.X_add_symbol;
13873 offset = inst.reloc.exp.X_add_number;
13874 break;
13875 case O_constant:
13876 sym = NULL;
13877 offset = inst.reloc.exp.X_add_number;
13878 break;
13879 default:
13880 sym = make_expr_symbol (&inst.reloc.exp);
13881 offset = 0;
13882 break;
13883 }
13884 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13885 inst.relax, sym, offset, NULL/*offset, opcode*/);
13886 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13887}
13888
13889/* Write a 32-bit thumb instruction to buf. */
13890static void
13891put_thumb32_insn (char * buf, unsigned long insn)
13892{
13893 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13894 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13895}
13896
b99bd4ef 13897static void
c19d1205 13898output_inst (const char * str)
b99bd4ef 13899{
c19d1205 13900 char * to = NULL;
b99bd4ef 13901
c19d1205 13902 if (inst.error)
b99bd4ef 13903 {
c19d1205 13904 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13905 return;
13906 }
0110f2b8
PB
13907 if (inst.relax) {
13908 output_relax_insn();
13909 return;
13910 }
c19d1205
ZW
13911 if (inst.size == 0)
13912 return;
b99bd4ef 13913
c19d1205
ZW
13914 to = frag_more (inst.size);
13915
13916 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13917 {
c19d1205 13918 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13919 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13920 }
c19d1205 13921 else if (inst.size > INSN_SIZE)
b99bd4ef 13922 {
c19d1205
ZW
13923 assert (inst.size == (2 * INSN_SIZE));
13924 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13925 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13926 }
c19d1205
ZW
13927 else
13928 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13929
c19d1205
ZW
13930 if (inst.reloc.type != BFD_RELOC_UNUSED)
13931 fix_new_arm (frag_now, to - frag_now->fr_literal,
13932 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13933 inst.reloc.type);
b99bd4ef 13934
c19d1205 13935 dwarf2_emit_insn (inst.size);
c19d1205 13936}
b99bd4ef 13937
c19d1205
ZW
13938/* Tag values used in struct asm_opcode's tag field. */
13939enum opcode_tag
13940{
13941 OT_unconditional, /* Instruction cannot be conditionalized.
13942 The ARM condition field is still 0xE. */
13943 OT_unconditionalF, /* Instruction cannot be conditionalized
13944 and carries 0xF in its ARM condition field. */
13945 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13946 OT_csuffixF, /* Some forms of the instruction take a conditional
13947 suffix, others place 0xF where the condition field
13948 would be. */
c19d1205
ZW
13949 OT_cinfix3, /* Instruction takes a conditional infix,
13950 beginning at character index 3. (In
13951 unified mode, it becomes a suffix.) */
088fa78e
KH
13952 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13953 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13954 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13955 character index 3, even in unified mode. Used for
13956 legacy instructions where suffix and infix forms
13957 may be ambiguous. */
c19d1205 13958 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13959 suffix or an infix at character index 3. */
c19d1205
ZW
13960 OT_odd_infix_unc, /* This is the unconditional variant of an
13961 instruction that takes a conditional infix
13962 at an unusual position. In unified mode,
13963 this variant will accept a suffix. */
13964 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13965 are the conditional variants of instructions that
13966 take conditional infixes in unusual positions.
13967 The infix appears at character index
13968 (tag - OT_odd_infix_0). These are not accepted
13969 in unified mode. */
13970};
b99bd4ef 13971
c19d1205
ZW
13972/* Subroutine of md_assemble, responsible for looking up the primary
13973 opcode from the mnemonic the user wrote. STR points to the
13974 beginning of the mnemonic.
13975
13976 This is not simply a hash table lookup, because of conditional
13977 variants. Most instructions have conditional variants, which are
13978 expressed with a _conditional affix_ to the mnemonic. If we were
13979 to encode each conditional variant as a literal string in the opcode
13980 table, it would have approximately 20,000 entries.
13981
13982 Most mnemonics take this affix as a suffix, and in unified syntax,
13983 'most' is upgraded to 'all'. However, in the divided syntax, some
13984 instructions take the affix as an infix, notably the s-variants of
13985 the arithmetic instructions. Of those instructions, all but six
13986 have the infix appear after the third character of the mnemonic.
13987
13988 Accordingly, the algorithm for looking up primary opcodes given
13989 an identifier is:
13990
13991 1. Look up the identifier in the opcode table.
13992 If we find a match, go to step U.
13993
13994 2. Look up the last two characters of the identifier in the
13995 conditions table. If we find a match, look up the first N-2
13996 characters of the identifier in the opcode table. If we
13997 find a match, go to step CE.
13998
13999 3. Look up the fourth and fifth characters of the identifier in
14000 the conditions table. If we find a match, extract those
14001 characters from the identifier, and look up the remaining
14002 characters in the opcode table. If we find a match, go
14003 to step CM.
14004
14005 4. Fail.
14006
14007 U. Examine the tag field of the opcode structure, in case this is
14008 one of the six instructions with its conditional infix in an
14009 unusual place. If it is, the tag tells us where to find the
14010 infix; look it up in the conditions table and set inst.cond
14011 accordingly. Otherwise, this is an unconditional instruction.
14012 Again set inst.cond accordingly. Return the opcode structure.
14013
14014 CE. Examine the tag field to make sure this is an instruction that
14015 should receive a conditional suffix. If it is not, fail.
14016 Otherwise, set inst.cond from the suffix we already looked up,
14017 and return the opcode structure.
14018
14019 CM. Examine the tag field to make sure this is an instruction that
14020 should receive a conditional infix after the third character.
14021 If it is not, fail. Otherwise, undo the edits to the current
14022 line of input and proceed as for case CE. */
14023
14024static const struct asm_opcode *
14025opcode_lookup (char **str)
14026{
14027 char *end, *base;
14028 char *affix;
14029 const struct asm_opcode *opcode;
14030 const struct asm_cond *cond;
e3cb604e 14031 char save[2];
267d2029
JB
14032 bfd_boolean neon_supported;
14033
14034 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14035
14036 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14037 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14038 for (base = end = *str; *end != '\0'; end++)
267d2029 14039 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14040 break;
b99bd4ef 14041
c19d1205
ZW
14042 if (end == base)
14043 return 0;
b99bd4ef 14044
5287ad62 14045 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14046 if (end[0] == '.')
b99bd4ef 14047 {
5287ad62
JB
14048 int offset = 2;
14049
267d2029
JB
14050 /* The .w and .n suffixes are only valid if the unified syntax is in
14051 use. */
14052 if (unified_syntax && end[1] == 'w')
c19d1205 14053 inst.size_req = 4;
267d2029 14054 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14055 inst.size_req = 2;
14056 else
5287ad62
JB
14057 offset = 0;
14058
14059 inst.vectype.elems = 0;
14060
14061 *str = end + offset;
b99bd4ef 14062
5287ad62
JB
14063 if (end[offset] == '.')
14064 {
267d2029
JB
14065 /* See if we have a Neon type suffix (possible in either unified or
14066 non-unified ARM syntax mode). */
dcbf9037 14067 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14068 return 0;
14069 }
14070 else if (end[offset] != '\0' && end[offset] != ' ')
14071 return 0;
b99bd4ef 14072 }
c19d1205
ZW
14073 else
14074 *str = end;
b99bd4ef 14075
c19d1205
ZW
14076 /* Look for unaffixed or special-case affixed mnemonic. */
14077 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14078 if (opcode)
b99bd4ef 14079 {
c19d1205
ZW
14080 /* step U */
14081 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14082 {
c19d1205
ZW
14083 inst.cond = COND_ALWAYS;
14084 return opcode;
b99bd4ef 14085 }
b99bd4ef 14086
c19d1205
ZW
14087 if (unified_syntax)
14088 as_warn (_("conditional infixes are deprecated in unified syntax"));
14089 affix = base + (opcode->tag - OT_odd_infix_0);
14090 cond = hash_find_n (arm_cond_hsh, affix, 2);
14091 assert (cond);
b99bd4ef 14092
c19d1205
ZW
14093 inst.cond = cond->value;
14094 return opcode;
14095 }
b99bd4ef 14096
c19d1205
ZW
14097 /* Cannot have a conditional suffix on a mnemonic of less than two
14098 characters. */
14099 if (end - base < 3)
14100 return 0;
b99bd4ef 14101
c19d1205
ZW
14102 /* Look for suffixed mnemonic. */
14103 affix = end - 2;
14104 cond = hash_find_n (arm_cond_hsh, affix, 2);
14105 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14106 if (opcode && cond)
14107 {
14108 /* step CE */
14109 switch (opcode->tag)
14110 {
e3cb604e
PB
14111 case OT_cinfix3_legacy:
14112 /* Ignore conditional suffixes matched on infix only mnemonics. */
14113 break;
14114
c19d1205 14115 case OT_cinfix3:
088fa78e 14116 case OT_cinfix3_deprecated:
c19d1205
ZW
14117 case OT_odd_infix_unc:
14118 if (!unified_syntax)
e3cb604e 14119 return 0;
c19d1205
ZW
14120 /* else fall through */
14121
14122 case OT_csuffix:
037e8744 14123 case OT_csuffixF:
c19d1205
ZW
14124 case OT_csuf_or_in3:
14125 inst.cond = cond->value;
14126 return opcode;
14127
14128 case OT_unconditional:
14129 case OT_unconditionalF:
dfa9f0d5
PB
14130 if (thumb_mode)
14131 {
14132 inst.cond = cond->value;
14133 }
14134 else
14135 {
14136 /* delayed diagnostic */
14137 inst.error = BAD_COND;
14138 inst.cond = COND_ALWAYS;
14139 }
c19d1205 14140 return opcode;
b99bd4ef 14141
c19d1205
ZW
14142 default:
14143 return 0;
14144 }
14145 }
b99bd4ef 14146
c19d1205
ZW
14147 /* Cannot have a usual-position infix on a mnemonic of less than
14148 six characters (five would be a suffix). */
14149 if (end - base < 6)
14150 return 0;
b99bd4ef 14151
c19d1205
ZW
14152 /* Look for infixed mnemonic in the usual position. */
14153 affix = base + 3;
14154 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14155 if (!cond)
14156 return 0;
14157
14158 memcpy (save, affix, 2);
14159 memmove (affix, affix + 2, (end - affix) - 2);
14160 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14161 memmove (affix + 2, affix, (end - affix) - 2);
14162 memcpy (affix, save, 2);
14163
088fa78e
KH
14164 if (opcode
14165 && (opcode->tag == OT_cinfix3
14166 || opcode->tag == OT_cinfix3_deprecated
14167 || opcode->tag == OT_csuf_or_in3
14168 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14169 {
c19d1205 14170 /* step CM */
088fa78e
KH
14171 if (unified_syntax
14172 && (opcode->tag == OT_cinfix3
14173 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14174 as_warn (_("conditional infixes are deprecated in unified syntax"));
14175
14176 inst.cond = cond->value;
14177 return opcode;
b99bd4ef
NC
14178 }
14179
c19d1205 14180 return 0;
b99bd4ef
NC
14181}
14182
c19d1205
ZW
14183void
14184md_assemble (char *str)
b99bd4ef 14185{
c19d1205
ZW
14186 char *p = str;
14187 const struct asm_opcode * opcode;
b99bd4ef 14188
c19d1205
ZW
14189 /* Align the previous label if needed. */
14190 if (last_label_seen != NULL)
b99bd4ef 14191 {
c19d1205
ZW
14192 symbol_set_frag (last_label_seen, frag_now);
14193 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
14194 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
14195 }
14196
c19d1205
ZW
14197 memset (&inst, '\0', sizeof (inst));
14198 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 14199
c19d1205
ZW
14200 opcode = opcode_lookup (&p);
14201 if (!opcode)
b99bd4ef 14202 {
c19d1205 14203 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
14204 the form alias .req reg, or a Neon .dn/.qn directive. */
14205 if (!create_register_alias (str, p)
14206 && !create_neon_reg_alias (str, p))
c19d1205 14207 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 14208
b99bd4ef
NC
14209 return;
14210 }
14211
088fa78e
KH
14212 if (opcode->tag == OT_cinfix3_deprecated)
14213 as_warn (_("s suffix on comparison instruction is deprecated"));
14214
037e8744
JB
14215 /* The value which unconditional instructions should have in place of the
14216 condition field. */
14217 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
14218
c19d1205 14219 if (thumb_mode)
b99bd4ef 14220 {
e74cfd16 14221 arm_feature_set variant;
8f06b2d8
PB
14222
14223 variant = cpu_variant;
14224 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
14225 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
14226 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 14227 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14228 if (!opcode->tvariant
14229 || (thumb_mode == 1
14230 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 14231 {
c19d1205 14232 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
14233 return;
14234 }
c19d1205
ZW
14235 if (inst.cond != COND_ALWAYS && !unified_syntax
14236 && opcode->tencode != do_t_branch)
b99bd4ef 14237 {
c19d1205 14238 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
14239 return;
14240 }
14241
076d447c
PB
14242 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
14243 {
14244 /* Implicit require narrow instructions on Thumb-1. This avoids
14245 relaxation accidentally introducing Thumb-2 instructions. */
14246 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23)
14247 inst.size_req = 2;
14248 }
14249
e27ec89e
PB
14250 /* Check conditional suffixes. */
14251 if (current_it_mask)
14252 {
14253 int cond;
14254 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
14255 current_it_mask <<= 1;
14256 current_it_mask &= 0x1f;
14257 /* The BKPT instruction is unconditional even in an IT block. */
14258 if (!inst.error
14259 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
14260 {
14261 as_bad (_("incorrect condition in IT block"));
14262 return;
14263 }
e27ec89e
PB
14264 }
14265 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
14266 {
14267 as_bad (_("thumb conditional instrunction not in IT block"));
14268 return;
14269 }
14270
c19d1205
ZW
14271 mapping_state (MAP_THUMB);
14272 inst.instruction = opcode->tvalue;
14273
14274 if (!parse_operands (p, opcode->operands))
14275 opcode->tencode ();
14276
e27ec89e
PB
14277 /* Clear current_it_mask at the end of an IT block. */
14278 if (current_it_mask == 0x10)
14279 current_it_mask = 0;
14280
0110f2b8 14281 if (!(inst.error || inst.relax))
b99bd4ef 14282 {
c19d1205
ZW
14283 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
14284 inst.size = (inst.instruction > 0xffff ? 4 : 2);
14285 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 14286 {
c19d1205 14287 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
14288 return;
14289 }
14290 }
076d447c
PB
14291
14292 /* Something has gone badly wrong if we try to relax a fixed size
14293 instruction. */
14294 assert (inst.size_req == 0 || !inst.relax);
14295
e74cfd16
PB
14296 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14297 *opcode->tvariant);
ee065d83 14298 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 14299 set those bits when Thumb-2 32-bit instructions are seen. ie.
ee065d83
PB
14300 anything other than bl/blx.
14301 This is overly pessimistic for relaxable instructions. */
14302 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
14303 || inst.relax)
e74cfd16
PB
14304 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
14305 arm_ext_v6t2);
c19d1205 14306 }
3e9e4fcf 14307 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
14308 {
14309 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
14310 if (!opcode->avariant ||
14311 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 14312 {
c19d1205
ZW
14313 as_bad (_("selected processor does not support `%s'"), str);
14314 return;
b99bd4ef 14315 }
c19d1205 14316 if (inst.size_req)
b99bd4ef 14317 {
c19d1205
ZW
14318 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
14319 return;
b99bd4ef
NC
14320 }
14321
c19d1205
ZW
14322 mapping_state (MAP_ARM);
14323 inst.instruction = opcode->avalue;
14324 if (opcode->tag == OT_unconditionalF)
14325 inst.instruction |= 0xF << 28;
14326 else
14327 inst.instruction |= inst.cond << 28;
14328 inst.size = INSN_SIZE;
14329 if (!parse_operands (p, opcode->operands))
14330 opcode->aencode ();
ee065d83
PB
14331 /* Arm mode bx is marked as both v4T and v5 because it's still required
14332 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
14333 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
14334 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
14335 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 14336 else
e74cfd16
PB
14337 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
14338 *opcode->avariant);
b99bd4ef 14339 }
3e9e4fcf
JB
14340 else
14341 {
14342 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
14343 "-- `%s'"), str);
14344 return;
14345 }
c19d1205
ZW
14346 output_inst (str);
14347}
b99bd4ef 14348
c19d1205
ZW
14349/* Various frobbings of labels and their addresses. */
14350
14351void
14352arm_start_line_hook (void)
14353{
14354 last_label_seen = NULL;
b99bd4ef
NC
14355}
14356
c19d1205
ZW
14357void
14358arm_frob_label (symbolS * sym)
b99bd4ef 14359{
c19d1205 14360 last_label_seen = sym;
b99bd4ef 14361
c19d1205 14362 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 14363
c19d1205
ZW
14364#if defined OBJ_COFF || defined OBJ_ELF
14365 ARM_SET_INTERWORK (sym, support_interwork);
14366#endif
b99bd4ef 14367
c19d1205
ZW
14368 /* Note - do not allow local symbols (.Lxxx) to be labeled
14369 as Thumb functions. This is because these labels, whilst
14370 they exist inside Thumb code, are not the entry points for
14371 possible ARM->Thumb calls. Also, these labels can be used
14372 as part of a computed goto or switch statement. eg gcc
14373 can generate code that looks like this:
b99bd4ef 14374
c19d1205
ZW
14375 ldr r2, [pc, .Laaa]
14376 lsl r3, r3, #2
14377 ldr r2, [r3, r2]
14378 mov pc, r2
b99bd4ef 14379
c19d1205
ZW
14380 .Lbbb: .word .Lxxx
14381 .Lccc: .word .Lyyy
14382 ..etc...
14383 .Laaa: .word Lbbb
b99bd4ef 14384
c19d1205
ZW
14385 The first instruction loads the address of the jump table.
14386 The second instruction converts a table index into a byte offset.
14387 The third instruction gets the jump address out of the table.
14388 The fourth instruction performs the jump.
b99bd4ef 14389
c19d1205
ZW
14390 If the address stored at .Laaa is that of a symbol which has the
14391 Thumb_Func bit set, then the linker will arrange for this address
14392 to have the bottom bit set, which in turn would mean that the
14393 address computation performed by the third instruction would end
14394 up with the bottom bit set. Since the ARM is capable of unaligned
14395 word loads, the instruction would then load the incorrect address
14396 out of the jump table, and chaos would ensue. */
14397 if (label_is_thumb_function_name
14398 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
14399 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 14400 {
c19d1205
ZW
14401 /* When the address of a Thumb function is taken the bottom
14402 bit of that address should be set. This will allow
14403 interworking between Arm and Thumb functions to work
14404 correctly. */
b99bd4ef 14405
c19d1205 14406 THUMB_SET_FUNC (sym, 1);
b99bd4ef 14407
c19d1205 14408 label_is_thumb_function_name = FALSE;
b99bd4ef 14409 }
07a53e5c 14410
07a53e5c 14411 dwarf2_emit_label (sym);
b99bd4ef
NC
14412}
14413
c19d1205
ZW
14414int
14415arm_data_in_code (void)
b99bd4ef 14416{
c19d1205 14417 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 14418 {
c19d1205
ZW
14419 *input_line_pointer = '/';
14420 input_line_pointer += 5;
14421 *input_line_pointer = 0;
14422 return 1;
b99bd4ef
NC
14423 }
14424
c19d1205 14425 return 0;
b99bd4ef
NC
14426}
14427
c19d1205
ZW
14428char *
14429arm_canonicalize_symbol_name (char * name)
b99bd4ef 14430{
c19d1205 14431 int len;
b99bd4ef 14432
c19d1205
ZW
14433 if (thumb_mode && (len = strlen (name)) > 5
14434 && streq (name + len - 5, "/data"))
14435 *(name + len - 5) = 0;
b99bd4ef 14436
c19d1205 14437 return name;
b99bd4ef 14438}
c19d1205
ZW
14439\f
14440/* Table of all register names defined by default. The user can
14441 define additional names with .req. Note that all register names
14442 should appear in both upper and lowercase variants. Some registers
14443 also have mixed-case names. */
b99bd4ef 14444
dcbf9037 14445#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 14446#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 14447#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
14448#define REGSET(p,t) \
14449 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
14450 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
14451 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
14452 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
14453#define REGSETH(p,t) \
14454 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
14455 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
14456 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
14457 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
14458#define REGSET2(p,t) \
14459 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14460 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14461 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14462 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14463
c19d1205 14464static const struct reg_entry reg_names[] =
7ed4c4c5 14465{
c19d1205
ZW
14466 /* ARM integer registers. */
14467 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14468
c19d1205
ZW
14469 /* ATPCS synonyms. */
14470 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14471 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14472 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14473
c19d1205
ZW
14474 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14475 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14476 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14477
c19d1205
ZW
14478 /* Well-known aliases. */
14479 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14480 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14481
14482 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14483 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14484
14485 /* Coprocessor numbers. */
14486 REGSET(p, CP), REGSET(P, CP),
14487
14488 /* Coprocessor register numbers. The "cr" variants are for backward
14489 compatibility. */
14490 REGSET(c, CN), REGSET(C, CN),
14491 REGSET(cr, CN), REGSET(CR, CN),
14492
14493 /* FPA registers. */
14494 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14495 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14496
14497 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14498 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14499
14500 /* VFP SP registers. */
5287ad62
JB
14501 REGSET(s,VFS), REGSET(S,VFS),
14502 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14503
14504 /* VFP DP Registers. */
5287ad62
JB
14505 REGSET(d,VFD), REGSET(D,VFD),
14506 /* Extra Neon DP registers. */
14507 REGSETH(d,VFD), REGSETH(D,VFD),
14508
14509 /* Neon QP registers. */
14510 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14511
14512 /* VFP control registers. */
14513 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14514 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
14515 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
14516 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
14517 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
14518 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
14519
14520 /* Maverick DSP coprocessor registers. */
14521 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14522 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14523
14524 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14525 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14526 REGDEF(dspsc,0,DSPSC),
14527
14528 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14529 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14530 REGDEF(DSPSC,0,DSPSC),
14531
14532 /* iWMMXt data registers - p0, c0-15. */
14533 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14534
14535 /* iWMMXt control registers - p1, c0-3. */
14536 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14537 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14538 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14539 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14540
14541 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14542 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14543 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14544 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14545 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14546
14547 /* XScale accumulator registers. */
14548 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14549};
14550#undef REGDEF
14551#undef REGNUM
14552#undef REGSET
7ed4c4c5 14553
c19d1205
ZW
14554/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14555 within psr_required_here. */
14556static const struct asm_psr psrs[] =
14557{
14558 /* Backward compatibility notation. Note that "all" is no longer
14559 truly all possible PSR bits. */
14560 {"all", PSR_c | PSR_f},
14561 {"flg", PSR_f},
14562 {"ctl", PSR_c},
14563
14564 /* Individual flags. */
14565 {"f", PSR_f},
14566 {"c", PSR_c},
14567 {"x", PSR_x},
14568 {"s", PSR_s},
14569 /* Combinations of flags. */
14570 {"fs", PSR_f | PSR_s},
14571 {"fx", PSR_f | PSR_x},
14572 {"fc", PSR_f | PSR_c},
14573 {"sf", PSR_s | PSR_f},
14574 {"sx", PSR_s | PSR_x},
14575 {"sc", PSR_s | PSR_c},
14576 {"xf", PSR_x | PSR_f},
14577 {"xs", PSR_x | PSR_s},
14578 {"xc", PSR_x | PSR_c},
14579 {"cf", PSR_c | PSR_f},
14580 {"cs", PSR_c | PSR_s},
14581 {"cx", PSR_c | PSR_x},
14582 {"fsx", PSR_f | PSR_s | PSR_x},
14583 {"fsc", PSR_f | PSR_s | PSR_c},
14584 {"fxs", PSR_f | PSR_x | PSR_s},
14585 {"fxc", PSR_f | PSR_x | PSR_c},
14586 {"fcs", PSR_f | PSR_c | PSR_s},
14587 {"fcx", PSR_f | PSR_c | PSR_x},
14588 {"sfx", PSR_s | PSR_f | PSR_x},
14589 {"sfc", PSR_s | PSR_f | PSR_c},
14590 {"sxf", PSR_s | PSR_x | PSR_f},
14591 {"sxc", PSR_s | PSR_x | PSR_c},
14592 {"scf", PSR_s | PSR_c | PSR_f},
14593 {"scx", PSR_s | PSR_c | PSR_x},
14594 {"xfs", PSR_x | PSR_f | PSR_s},
14595 {"xfc", PSR_x | PSR_f | PSR_c},
14596 {"xsf", PSR_x | PSR_s | PSR_f},
14597 {"xsc", PSR_x | PSR_s | PSR_c},
14598 {"xcf", PSR_x | PSR_c | PSR_f},
14599 {"xcs", PSR_x | PSR_c | PSR_s},
14600 {"cfs", PSR_c | PSR_f | PSR_s},
14601 {"cfx", PSR_c | PSR_f | PSR_x},
14602 {"csf", PSR_c | PSR_s | PSR_f},
14603 {"csx", PSR_c | PSR_s | PSR_x},
14604 {"cxf", PSR_c | PSR_x | PSR_f},
14605 {"cxs", PSR_c | PSR_x | PSR_s},
14606 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14607 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14608 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14609 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14610 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14611 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14612 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14613 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14614 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14615 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14616 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14617 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14618 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14619 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14620 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14621 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14622 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14623 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14624 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14625 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14626 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14627 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14628 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14629 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14630};
14631
62b3e311
PB
14632/* Table of V7M psr names. */
14633static const struct asm_psr v7m_psrs[] =
14634{
2b744c99
PB
14635 {"apsr", 0 }, {"APSR", 0 },
14636 {"iapsr", 1 }, {"IAPSR", 1 },
14637 {"eapsr", 2 }, {"EAPSR", 2 },
14638 {"psr", 3 }, {"PSR", 3 },
14639 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
14640 {"ipsr", 5 }, {"IPSR", 5 },
14641 {"epsr", 6 }, {"EPSR", 6 },
14642 {"iepsr", 7 }, {"IEPSR", 7 },
14643 {"msp", 8 }, {"MSP", 8 },
14644 {"psp", 9 }, {"PSP", 9 },
14645 {"primask", 16}, {"PRIMASK", 16},
14646 {"basepri", 17}, {"BASEPRI", 17},
14647 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
14648 {"faultmask", 19}, {"FAULTMASK", 19},
14649 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
14650};
14651
c19d1205
ZW
14652/* Table of all shift-in-operand names. */
14653static const struct asm_shift_name shift_names [] =
b99bd4ef 14654{
c19d1205
ZW
14655 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14656 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14657 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14658 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14659 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14660 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14661};
b99bd4ef 14662
c19d1205
ZW
14663/* Table of all explicit relocation names. */
14664#ifdef OBJ_ELF
14665static struct reloc_entry reloc_names[] =
14666{
14667 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14668 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14669 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14670 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14671 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14672 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14673 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14674 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14675 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14676 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14677 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14678};
14679#endif
b99bd4ef 14680
c19d1205
ZW
14681/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14682static const struct asm_cond conds[] =
14683{
14684 {"eq", 0x0},
14685 {"ne", 0x1},
14686 {"cs", 0x2}, {"hs", 0x2},
14687 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14688 {"mi", 0x4},
14689 {"pl", 0x5},
14690 {"vs", 0x6},
14691 {"vc", 0x7},
14692 {"hi", 0x8},
14693 {"ls", 0x9},
14694 {"ge", 0xa},
14695 {"lt", 0xb},
14696 {"gt", 0xc},
14697 {"le", 0xd},
14698 {"al", 0xe}
14699};
bfae80f2 14700
62b3e311
PB
14701static struct asm_barrier_opt barrier_opt_names[] =
14702{
14703 { "sy", 0xf },
14704 { "un", 0x7 },
14705 { "st", 0xe },
14706 { "unst", 0x6 }
14707};
14708
c19d1205
ZW
14709/* Table of ARM-format instructions. */
14710
14711/* Macros for gluing together operand strings. N.B. In all cases
14712 other than OPS0, the trailing OP_stop comes from default
14713 zero-initialization of the unspecified elements of the array. */
14714#define OPS0() { OP_stop, }
14715#define OPS1(a) { OP_##a, }
14716#define OPS2(a,b) { OP_##a,OP_##b, }
14717#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14718#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14719#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14720#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14721
14722/* These macros abstract out the exact format of the mnemonic table and
14723 save some repeated characters. */
14724
14725/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14726#define TxCE(mnem, op, top, nops, ops, ae, te) \
14727 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14728 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14729
14730/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14731 a T_MNEM_xyz enumerator. */
14732#define TCE(mnem, aop, top, nops, ops, ae, te) \
14733 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14734#define tCE(mnem, aop, top, nops, ops, ae, te) \
14735 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14736
14737/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14738 infix after the third character. */
14739#define TxC3(mnem, op, top, nops, ops, ae, te) \
14740 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14741 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14742#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14743 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14744 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14745#define TC3(mnem, aop, top, nops, ops, ae, te) \
14746 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14747#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14748 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14749#define tC3(mnem, aop, top, nops, ops, ae, te) \
14750 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14751#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14752 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14753
14754/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14755 appear in the condition table. */
14756#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14757 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14758 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14759
14760#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14761 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14762 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14763 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14764 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14765 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14766 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14767 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14768 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14769 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14770 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14771 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14772 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14773 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14774 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14775 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14776 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14777 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14778 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14779 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14780
14781#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14782 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14783#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14784 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14785
14786/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14787 field is still 0xE. Many of the Thumb variants can be executed
14788 conditionally, so this is checked separately. */
c19d1205
ZW
14789#define TUE(mnem, op, top, nops, ops, ae, te) \
14790 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14791 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14792
14793/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14794 condition code field. */
14795#define TUF(mnem, op, top, nops, ops, ae, te) \
14796 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14797 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14798
14799/* ARM-only variants of all the above. */
6a86118a
NC
14800#define CE(mnem, op, nops, ops, ae) \
14801 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14802
14803#define C3(mnem, op, nops, ops, ae) \
14804 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14805
e3cb604e
PB
14806/* Legacy mnemonics that always have conditional infix after the third
14807 character. */
14808#define CL(mnem, op, nops, ops, ae) \
14809 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14810 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14811
8f06b2d8
PB
14812/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14813#define cCE(mnem, op, nops, ops, ae) \
14814 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14815
e3cb604e
PB
14816/* Legacy coprocessor instructions where conditional infix and conditional
14817 suffix are ambiguous. For consistency this includes all FPA instructions,
14818 not just the potentially ambiguous ones. */
14819#define cCL(mnem, op, nops, ops, ae) \
14820 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14821 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14822
14823/* Coprocessor, takes either a suffix or a position-3 infix
14824 (for an FPA corner case). */
14825#define C3E(mnem, op, nops, ops, ae) \
14826 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14827 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14828
6a86118a
NC
14829#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14830 { #m1 #m2 #m3, OPS##nops ops, \
14831 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14832 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14833
14834#define CM(m1, m2, op, nops, ops, ae) \
14835 xCM_(m1, , m2, op, nops, ops, ae), \
14836 xCM_(m1, eq, m2, op, nops, ops, ae), \
14837 xCM_(m1, ne, m2, op, nops, ops, ae), \
14838 xCM_(m1, cs, m2, op, nops, ops, ae), \
14839 xCM_(m1, hs, m2, op, nops, ops, ae), \
14840 xCM_(m1, cc, m2, op, nops, ops, ae), \
14841 xCM_(m1, ul, m2, op, nops, ops, ae), \
14842 xCM_(m1, lo, m2, op, nops, ops, ae), \
14843 xCM_(m1, mi, m2, op, nops, ops, ae), \
14844 xCM_(m1, pl, m2, op, nops, ops, ae), \
14845 xCM_(m1, vs, m2, op, nops, ops, ae), \
14846 xCM_(m1, vc, m2, op, nops, ops, ae), \
14847 xCM_(m1, hi, m2, op, nops, ops, ae), \
14848 xCM_(m1, ls, m2, op, nops, ops, ae), \
14849 xCM_(m1, ge, m2, op, nops, ops, ae), \
14850 xCM_(m1, lt, m2, op, nops, ops, ae), \
14851 xCM_(m1, gt, m2, op, nops, ops, ae), \
14852 xCM_(m1, le, m2, op, nops, ops, ae), \
14853 xCM_(m1, al, m2, op, nops, ops, ae)
14854
14855#define UE(mnem, op, nops, ops, ae) \
14856 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14857
14858#define UF(mnem, op, nops, ops, ae) \
14859 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14860
5287ad62
JB
14861/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14862 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14863 use the same encoding function for each. */
14864#define NUF(mnem, op, nops, ops, enc) \
14865 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14866 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14867
14868/* Neon data processing, version which indirects through neon_enc_tab for
14869 the various overloaded versions of opcodes. */
14870#define nUF(mnem, op, nops, ops, enc) \
14871 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14872 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14873
14874/* Neon insn with conditional suffix for the ARM version, non-overloaded
14875 version. */
037e8744
JB
14876#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14877 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14878 THUMB_VARIANT, do_##enc, do_##enc }
14879
037e8744
JB
14880#define NCE(mnem, op, nops, ops, enc) \
14881 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14882
14883#define NCEF(mnem, op, nops, ops, enc) \
14884 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14885
5287ad62 14886/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14887#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14888 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14889 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14890
037e8744
JB
14891#define nCE(mnem, op, nops, ops, enc) \
14892 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14893
14894#define nCEF(mnem, op, nops, ops, enc) \
14895 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14896
c19d1205
ZW
14897#define do_0 0
14898
14899/* Thumb-only, unconditional. */
14900#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14901
c19d1205 14902static const struct asm_opcode insns[] =
bfae80f2 14903{
e74cfd16
PB
14904#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14905#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14906 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14907 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14908 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14909 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14910 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14911 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14912 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14913 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14914 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14915 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14916 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14917 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14918 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14919 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14920 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14921 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14922
14923 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14924 for setting PSR flag bits. They are obsolete in V6 and do not
14925 have Thumb equivalents. */
14926 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14927 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14928 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14929 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14930 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14931 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14932 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14933 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14934 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14935
14936 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14937 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14938 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14939 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14940
4962c51a
MS
14941 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14942 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14943 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14944 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14945
f5208ef2 14946 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14947 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14948 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14949 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14950 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14951 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14952
14953 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14954 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14955 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14956 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14957
c19d1205 14958 /* Pseudo ops. */
e9f89963 14959 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14960 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14961 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14962
14963 /* Thumb-compatibility pseudo ops. */
14964 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14965 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14966 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14967 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14968 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14969 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14970 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14971 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14972 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14973 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14974 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14975 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14976
16a4cf17
PB
14977 /* These may simplify to neg. */
14978 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14979 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14980
c19d1205 14981#undef THUMB_VARIANT
e74cfd16 14982#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14983 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14984
14985 /* V1 instructions with no Thumb analogue prior to V6T2. */
14986#undef THUMB_VARIANT
e74cfd16 14987#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14988 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14989 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14990 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14991
14992 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14993 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14994 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14995 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14996
9c3c69f2
PB
14997 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14998 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14999
9c3c69f2
PB
15000 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15001 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15002
15003 /* V1 instructions with no Thumb analogue at all. */
15004 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
15005 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
15006
15007 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
15008 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
15009 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
15010 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
15011 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
15012 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
15013 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
15014 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
15015
15016#undef ARM_VARIANT
e74cfd16 15017#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 15018#undef THUMB_VARIANT
e74cfd16 15019#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15020 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15021 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
15022
15023#undef THUMB_VARIANT
e74cfd16 15024#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15025 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
15026 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
15027
15028 /* Generic coprocessor instructions. */
15029 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
15030 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15031 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15032 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15033 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15034 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15035 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15036
15037#undef ARM_VARIANT
e74cfd16 15038#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
15039 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15040 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
15041
15042#undef ARM_VARIANT
e74cfd16 15043#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
037e8744
JB
15044 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
15045 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
15046
15047#undef ARM_VARIANT
e74cfd16 15048#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
15049 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15050 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15051 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15052 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15053 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15054 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15055 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
15056 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
15057
15058#undef ARM_VARIANT
e74cfd16 15059#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 15060#undef THUMB_VARIANT
e74cfd16 15061#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
15062 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15063 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15064 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15065 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15066 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
15067 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
15068
15069#undef ARM_VARIANT
e74cfd16 15070#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
15071 /* ARM Architecture 4T. */
15072 /* Note: bx (and blx) are required on V5, even if the processor does
15073 not support Thumb. */
15074 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
15075
15076#undef ARM_VARIANT
e74cfd16 15077#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 15078#undef THUMB_VARIANT
e74cfd16 15079#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
15080 /* Note: blx has 2 variants; the .value coded here is for
15081 BLX(2). Only this variant has conditional execution. */
15082 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
15083 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
15084
15085#undef THUMB_VARIANT
e74cfd16 15086#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15087 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
15088 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15089 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15090 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
15091 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
15092 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
15093 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15094 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
15095
15096#undef ARM_VARIANT
e74cfd16 15097#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
15098 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15099 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15100 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15101 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15102
15103 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15104 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
15105
15106 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15107 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15108 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15109 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
15110
15111 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15112 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15113 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15114 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15115
15116 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15117 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15118
15119 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15120 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15121 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15122 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
15123
15124#undef ARM_VARIANT
e74cfd16 15125#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 15126 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
15127 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
15128 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
15129
15130 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15131 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15132
15133#undef ARM_VARIANT
e74cfd16 15134#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
15135 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
15136
15137#undef ARM_VARIANT
e74cfd16 15138#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 15139#undef THUMB_VARIANT
e74cfd16 15140#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
15141 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
15142 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
15143 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15144 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15145 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
15146 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15147 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15148 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15149 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15150 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
15151
15152#undef THUMB_VARIANT
e74cfd16 15153#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15154 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 15155 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
15156 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
15157 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
15158
15159 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
15160 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
15161
15162/* ARM V6 not included in V7M (eg. integer SIMD). */
15163#undef THUMB_VARIANT
15164#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 15165 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
15166 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
15167 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
15168 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15169 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15170 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15171 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15172 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15173 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15174 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15175 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15176 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15177 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15178 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15179 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15180 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15181 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15182 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15183 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15184 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15185 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15186 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15187 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15188 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15189 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15190 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15191 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15192 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15193 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15194 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15195 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15196 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15197 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15198 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15199 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15200 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15201 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15202 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15203 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
15204 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15205 UF(rfeib, 9900a00, 1, (RRw), rfe),
15206 UF(rfeda, 8100a00, 1, (RRw), rfe),
15207 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15208 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
15209 UF(rfefa, 9900a00, 1, (RRw), rfe),
15210 UF(rfeea, 8100a00, 1, (RRw), rfe),
15211 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
15212 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15213 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15214 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15215 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
15216 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15217 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15218 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
15219 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 15220 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
15221 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15222 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15223 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15224 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15225 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15226 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15227 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15228 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
15229 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15230 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15231 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15232 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
15233 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15234 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15235 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15236 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15237 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15238 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
15239 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
15240 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
15241 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
15242 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 15243 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
15244 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
15245 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
15246 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
15247 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
15248
15249#undef ARM_VARIANT
e74cfd16 15250#define ARM_VARIANT &arm_ext_v6k
c19d1205 15251#undef THUMB_VARIANT
e74cfd16 15252#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
15253 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
15254 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
15255 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
15256 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
15257
ebdca51a
PB
15258#undef THUMB_VARIANT
15259#define THUMB_VARIANT &arm_ext_v6_notm
15260 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
15261 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
15262
c19d1205 15263#undef THUMB_VARIANT
e74cfd16 15264#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
15265 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
15266 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
15267 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
15268 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
15269 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
15270
15271#undef ARM_VARIANT
e74cfd16 15272#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 15273 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
15274
15275#undef ARM_VARIANT
e74cfd16 15276#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
15277 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
15278 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
15279 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15280 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
15281
15282 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
15283 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
15284 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 15285 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
15286
15287 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15288 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15289 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15290 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
15291
25fe350b
MS
15292 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
15293 UT(cbz, b100, 2, (RR, EXP), t_cbz),
f91e006c
PB
15294 /* ARM does not really have an IT instruction, so always allow it. */
15295#undef ARM_VARIANT
15296#define ARM_VARIANT &arm_ext_v1
c19d1205
ZW
15297 TUE(it, 0, bf08, 1, (COND), it, t_it),
15298 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
15299 TUE(ite, 0, bf04, 1, (COND), it, t_it),
15300 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
15301 TUE(itet, 0, bf06, 1, (COND), it, t_it),
15302 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
15303 TUE(itee, 0, bf02, 1, (COND), it, t_it),
15304 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
15305 TUE(itett, 0, bf07, 1, (COND), it, t_it),
15306 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
15307 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
15308 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
15309 TUE(itete, 0, bf05, 1, (COND), it, t_it),
15310 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
15311 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
15312
92e90b6e
PB
15313 /* Thumb2 only instructions. */
15314#undef ARM_VARIANT
e74cfd16 15315#define ARM_VARIANT NULL
92e90b6e
PB
15316
15317 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15318 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
15319 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
15320 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
15321
62b3e311
PB
15322 /* Thumb-2 hardware division instructions (R and M profiles only). */
15323#undef THUMB_VARIANT
15324#define THUMB_VARIANT &arm_ext_div
15325 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
15326 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
15327
15328 /* ARM V7 instructions. */
15329#undef ARM_VARIANT
15330#define ARM_VARIANT &arm_ext_v7
15331#undef THUMB_VARIANT
15332#define THUMB_VARIANT &arm_ext_v7
15333 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
15334 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
15335 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
15336 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
15337 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
15338
c19d1205 15339#undef ARM_VARIANT
e74cfd16 15340#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
15341 cCE(wfs, e200110, 1, (RR), rd),
15342 cCE(rfs, e300110, 1, (RR), rd),
15343 cCE(wfc, e400110, 1, (RR), rd),
15344 cCE(rfc, e500110, 1, (RR), rd),
15345
4962c51a
MS
15346 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
15347 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
15348 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
15349 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 15350
4962c51a
MS
15351 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
15352 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
15353 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
15354 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
15355
15356 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
15357 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
15358 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
15359 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
15360 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
15361 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
15362 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
15363 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
15364 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
15365 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
15366 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
15367 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
15368
15369 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
15370 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
15371 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
15372 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
15373 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
15374 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
15375 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
15376 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
15377 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
15378 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
15379 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
15380 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
15381
15382 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
15383 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
15384 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
15385 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
15386 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
15387 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
15388 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
15389 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
15390 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
15391 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
15392 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
15393 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
15394
15395 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
15396 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
15397 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
15398 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
15399 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
15400 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
15401 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
15402 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
15403 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
15404 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
15405 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
15406 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
15407
15408 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
15409 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
15410 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
15411 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
15412 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
15413 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
15414 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
15415 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
15416 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
15417 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
15418 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
15419 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
15420
15421 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
15422 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
15423 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
15424 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
15425 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
15426 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
15427 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
15428 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
15429 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
15430 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
15431 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
15432 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
15433
15434 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
15435 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
15436 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
15437 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
15438 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
15439 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
15440 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
15441 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
15442 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
15443 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
15444 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
15445 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
15446
15447 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
15448 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
15449 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
15450 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
15451 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
15452 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
15453 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
15454 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
15455 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
15456 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
15457 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
15458 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
15459
15460 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
15461 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
15462 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
15463 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
15464 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
15465 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
15466 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
15467 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
15468 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15469 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15470 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15471 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15472
15473 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15474 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15475 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15476 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15477 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15478 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15479 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15480 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15481 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15482 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15483 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15484 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15485
15486 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15487 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15488 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15489 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15490 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15491 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15492 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15493 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15494 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15495 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15496 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15497 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15498
15499 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15500 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15501 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15502 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15503 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15504 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15505 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15506 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15507 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15508 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15509 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15510 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15511
15512 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15513 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15514 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15515 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15516 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15517 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15518 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15519 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15520 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15521 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15522 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15523 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15524
15525 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15526 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15527 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15528 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15529 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15530 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15531 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15532 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15533 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15534 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15535 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15536 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15537
15538 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15539 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15540 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15541 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15542 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15543 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15544 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15545 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15546 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15547 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15548 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15549 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15550
15551 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15552 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15553 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15554 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15555 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15556 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15557 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15558 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15559 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15560 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15561 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15562 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15563
15564 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15565 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15566 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15567 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15568 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15569 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15570 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15571 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15572 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15573 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15574 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15575 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15576
15577 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15578 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15579 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15580 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15581 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15582 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15583 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15584 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15585 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15586 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15587 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15588 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15589
15590 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15591 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15592 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15593 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15594 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15595 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15596 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15597 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15598 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15599 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15600 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15601 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15602
15603 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15604 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15605 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15606 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15607 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15608 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15609 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15610 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15611 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15612 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15613 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15614 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15615
15616 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15617 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15618 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15619 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15620 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15621 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15622 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15623 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15624 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15625 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15626 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15627 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15628
15629 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15630 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15631 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15632 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15633 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15634 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15635 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15636 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15637 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15638 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15639 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15640 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15641
15642 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15643 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15644 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15645 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15646 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15647 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15648 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15649 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15650 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15651 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15652 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15653 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15654
15655 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15656 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15657 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15658 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15659 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15660 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15661 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15662 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15663 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15664 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15665 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15666 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15667
15668 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15669 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15670 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15671 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15672 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15673 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15674 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15675 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15676 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15677 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15678 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15679 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15680
15681 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15682 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15683 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15684 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15685 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15686 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15687 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15688 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15689 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15690 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15691 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15692 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15693
15694 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15695 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15696 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15697 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15698 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15699 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15700 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15701 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15702 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15703 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15704 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15705 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15706
15707 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15708 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15709 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15710 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15711 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15712 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15713 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15714 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15715 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15716 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15717 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15718 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15719
15720 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15721 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15722 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15723 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15724 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15725 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15726 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15727 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15728 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15729 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15730 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15731 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15732
15733 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15734 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15735 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15736 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15737
e3cb604e
PB
15738 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15739 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15740 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15741 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15742 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15743 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15744 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15745 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15746 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15747 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15748 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15749 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15750
c19d1205
ZW
15751 /* The implementation of the FIX instruction is broken on some
15752 assemblers, in that it accepts a precision specifier as well as a
15753 rounding specifier, despite the fact that this is meaningless.
15754 To be more compatible, we accept it as well, though of course it
15755 does not set any bits. */
8f06b2d8 15756 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15757 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15758 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15759 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15760 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15761 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15762 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15763 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15764 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15765 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15766 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15767 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15768 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15769
c19d1205
ZW
15770 /* Instructions that were new with the real FPA, call them V2. */
15771#undef ARM_VARIANT
e74cfd16 15772#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15773 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15774 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15775 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15776 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15777 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15778 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15779
15780#undef ARM_VARIANT
e74cfd16 15781#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15782 /* Moves and type conversions. */
8f06b2d8
PB
15783 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15784 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15785 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15786 cCE(fmstat, ef1fa10, 0, (), noargs),
15787 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15788 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15789 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15790 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15791 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15792 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15793 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15794 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15795
15796 /* Memory operations. */
4962c51a
MS
15797 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15798 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15799 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15800 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15801 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15802 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15803 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15804 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15805 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15806 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15807 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15808 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15809 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15810 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15811 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15812 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15813 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15814 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15815
c19d1205 15816 /* Monadic operations. */
8f06b2d8
PB
15817 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15818 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15819 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15820
15821 /* Dyadic operations. */
8f06b2d8
PB
15822 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15823 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15824 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15825 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15826 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15827 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15828 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15829 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15830 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15831
c19d1205 15832 /* Comparisons. */
8f06b2d8
PB
15833 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15834 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15835 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15836 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15837
c19d1205 15838#undef ARM_VARIANT
e74cfd16 15839#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15840 /* Moves and type conversions. */
5287ad62 15841 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15842 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15843 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15844 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15845 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15846 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15847 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15848 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15849 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15850 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15851 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15852 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15853 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15854
15855 /* Memory operations. */
4962c51a
MS
15856 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15857 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15858 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15859 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15860 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15861 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15862 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15863 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15864 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15865 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15866
c19d1205 15867 /* Monadic operations. */
5287ad62
JB
15868 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15869 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15870 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15871
15872 /* Dyadic operations. */
5287ad62
JB
15873 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15874 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15875 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15876 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15877 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15878 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15879 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15880 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15881 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15882
c19d1205 15883 /* Comparisons. */
5287ad62
JB
15884 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15885 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15886 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15887 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15888
15889#undef ARM_VARIANT
e74cfd16 15890#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15891 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15892 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15893 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15894 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15895
037e8744
JB
15896/* Instructions which may belong to either the Neon or VFP instruction sets.
15897 Individual encoder functions perform additional architecture checks. */
15898#undef ARM_VARIANT
15899#define ARM_VARIANT &fpu_vfp_ext_v1xd
15900#undef THUMB_VARIANT
15901#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15902 /* These mnemonics are unique to VFP. */
15903 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15904 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15905 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15906 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15907 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15908 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15909 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15910 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15911 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15912 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15913
15914 /* Mnemonics shared by Neon and VFP. */
15915 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15916 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15917 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15918
15919 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15920 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15921
15922 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15923 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15924
15925 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15926 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15927 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15928 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15929 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15930 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15931 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15932 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15933
15934 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15935
15936 /* NOTE: All VMOV encoding is special-cased! */
15937 NCE(vmov, 0, 1, (VMOV), neon_mov),
15938 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15939
5287ad62
JB
15940#undef THUMB_VARIANT
15941#define THUMB_VARIANT &fpu_neon_ext_v1
15942#undef ARM_VARIANT
15943#define ARM_VARIANT &fpu_neon_ext_v1
15944 /* Data processing with three registers of the same length. */
15945 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15946 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15947 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15948 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15949 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15950 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15951 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15952 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15953 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15954 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15955 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15956 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15957 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15958 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
15959 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15960 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
15961 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
15962 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
15963 /* If not immediate, fall back to neon_dyadic_i64_su.
15964 shl_imm should accept I8 I16 I32 I64,
15965 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15966 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15967 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15968 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15969 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15970 /* Logic ops, types optional & ignored. */
15971 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15972 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15973 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15974 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15975 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15976 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15977 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15978 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15979 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15980 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15981 /* Bitfield ops, untyped. */
15982 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15983 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15984 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15985 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15986 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15987 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15988 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15989 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15990 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15991 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15992 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15993 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15994 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15995 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15996 back to neon_dyadic_if_su. */
15997 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15998 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15999 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
16000 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
16001 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16002 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
16003 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
16004 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 16005 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
16006 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
16007 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
16008 /* As above, D registers only. */
16009 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16010 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
16011 /* Int and float variants, signedness unimportant. */
5287ad62 16012 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
16013 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
16014 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
16015 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 16016 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
16017 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
16018 /* vtst takes sizes 8, 16, 32. */
16019 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
16020 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
16021 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 16022 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
16023 /* VQD{R}MULH takes S16 S32. */
16024 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16025 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16026 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
16027 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
16028 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16029 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
16030 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
16031 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
16032 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16033 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
16034 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
16035 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
16036 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16037 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16038 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
16039 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
16040
16041 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 16042 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
16043 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
16044
16045 /* Data processing with two registers and a shift amount. */
16046 /* Right shifts, and variants with rounding.
16047 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
16048 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16049 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16050 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
16051 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
16052 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16053 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16054 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
16055 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
16056 /* Shift and insert. Sizes accepted 8 16 32 64. */
16057 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
16058 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
16059 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
16060 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
16061 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
16062 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
16063 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
16064 /* Right shift immediate, saturating & narrowing, with rounding variants.
16065 Types accepted S16 S32 S64 U16 U32 U64. */
16066 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16067 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
16068 /* As above, unsigned. Types accepted S16 S32 S64. */
16069 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16070 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
16071 /* Right shift narrowing. Types accepted I16 I32 I64. */
16072 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16073 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
16074 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
16075 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
16076 /* CVT with optional immediate for fixed-point variant. */
037e8744 16077 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 16078
5287ad62
JB
16079 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
16080 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
16081
16082 /* Data processing, three registers of different lengths. */
16083 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
16084 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
16085 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
16086 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
16087 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
16088 /* If not scalar, fall back to neon_dyadic_long.
16089 Vector types as above, scalar types S16 S32 U16 U32. */
16090 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16091 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
16092 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
16093 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16094 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
16095 /* Dyadic, narrowing insns. Types I16 I32 I64. */
16096 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16097 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16098 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16099 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
16100 /* Saturating doubling multiplies. Types S16 S32. */
16101 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16102 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16103 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
16104 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
16105 S16 S32 U16 U32. */
16106 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
16107
16108 /* Extract. Size 8. */
3b8d421e
PB
16109 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
16110 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
16111
16112 /* Two registers, miscellaneous. */
16113 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
16114 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
16115 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
16116 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
16117 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
16118 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
16119 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
16120 /* Vector replicate. Sizes 8 16 32. */
16121 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
16122 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
16123 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
16124 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
16125 /* VMOVN. Types I16 I32 I64. */
16126 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
16127 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
16128 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
16129 /* VQMOVUN. Types S16 S32 S64. */
16130 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
16131 /* VZIP / VUZP. Sizes 8 16 32. */
16132 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
16133 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
16134 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
16135 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
16136 /* VQABS / VQNEG. Types S8 S16 S32. */
16137 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16138 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
16139 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
16140 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
16141 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
16142 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
16143 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
16144 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
16145 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
16146 /* Reciprocal estimates. Types U32 F32. */
16147 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
16148 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
16149 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
16150 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
16151 /* VCLS. Types S8 S16 S32. */
16152 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
16153 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
16154 /* VCLZ. Types I8 I16 I32. */
16155 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
16156 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
16157 /* VCNT. Size 8. */
16158 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
16159 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
16160 /* Two address, untyped. */
16161 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
16162 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
16163 /* VTRN. Sizes 8 16 32. */
16164 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
16165 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
16166
16167 /* Table lookup. Size 8. */
16168 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16169 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
16170
b7fc2769
JB
16171#undef THUMB_VARIANT
16172#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
16173#undef ARM_VARIANT
16174#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
16175 /* Neon element/structure load/store. */
16176 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16177 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
16178 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16179 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
16180 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16181 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
16182 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16183 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
16184
16185#undef THUMB_VARIANT
16186#define THUMB_VARIANT &fpu_vfp_ext_v3
16187#undef ARM_VARIANT
16188#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
16189 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
16190 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
16191 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16192 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16193 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16194 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16195 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16196 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16197 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16198 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16199 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16200 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16201 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16202 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
16203 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
16204 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
16205 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
16206 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 16207
5287ad62 16208#undef THUMB_VARIANT
c19d1205 16209#undef ARM_VARIANT
e74cfd16 16210#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
16211 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16212 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16213 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16214 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16215 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16216 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
16217 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
16218 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
16219
16220#undef ARM_VARIANT
e74cfd16 16221#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
16222 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
16223 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
16224 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
16225 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
16226 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
16227 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
16228 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
16229 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
16230 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
16231 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16232 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16233 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
16234 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16235 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16236 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
16237 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16238 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
16239 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 16240 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
16241 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
16242 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16243 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16244 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16245 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16246 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16247 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
16248 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
16249 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
16250 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 16251 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
16252 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
16253 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
16254 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
16255 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
16256 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
16257 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
16258 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
16259 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16260 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16261 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16262 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16263 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16264 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16265 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16266 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16267 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16268 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
16269 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16270 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16271 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16272 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16273 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16274 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16275 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16276 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16277 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16278 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16279 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16280 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16281 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16282 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16283 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16284 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16285 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16286 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16287 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16288 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16289 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16290 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16291 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16292 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16293 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16294 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16295 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16296 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16297 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16298 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16299 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16300 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16301 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16302 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16303 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16304 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16305 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16306 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16307 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16308 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16309 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16310 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
16311 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16312 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16313 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16314 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16315 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16316 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16317 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16318 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16319 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16320 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16321 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 16322 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16323 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16324 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16325 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16326 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16327 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16328 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16329 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16330 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16331 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16332 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 16333 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16334 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16335 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16336 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16337 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16338 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16339 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16340 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16341 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16342 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16343 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16344 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16345 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16346 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16347 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 16348 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 16349 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
16350 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
16351 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16352 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
16353 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
16354 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
16355 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16356 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16357 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16358 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16359 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16360 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16361 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16362 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16363 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16364 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
16365 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
16366 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
16367 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
16368 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
16369 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
16370 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16371 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16372 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16373 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
16374 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
16375 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
16376 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
16377 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
16378 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
16379 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16380 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16381 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16382 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16383 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 16384
2d447fca
JM
16385#undef ARM_VARIANT
16386#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
16387 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
16388 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
16389 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
16390 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
16391 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
16392 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
16393 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16394 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16395 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16396 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16397 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16398 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16399 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16400 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16401 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16402 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16403 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16404 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16405 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16406 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16407 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
16408 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16409 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16410 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16411 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16412 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16413 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16414 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16415 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16416 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16417 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16418 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16419 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16420 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16421 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16422 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16423 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16424 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16425 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16426 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16427 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16428 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16429 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16430 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16431 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16432 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16433 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16434 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16435 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16436 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16437 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16438 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16439 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16440 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16441 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16442 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16443 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
16444
c19d1205 16445#undef ARM_VARIANT
e74cfd16 16446#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
16447 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16448 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16449 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16450 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
16451 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
16452 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
16453 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
16454 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
16455 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
16456 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
16457 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
16458 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
16459 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
16460 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
16461 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
16462 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
16463 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
16464 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
16465 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
16466 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
16467 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
16468 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
16469 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
16470 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
16471 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
16472 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
16473 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
16474 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
16475 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
16476 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
16477 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
16478 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
16479 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
16480 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
16481 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
16482 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
16483 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
16484 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
16485 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
16486 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
16487 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
16488 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
16489 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
16490 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
16491 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
16492 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
16493 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
16494 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
16495 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
16496 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
16497 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
16498 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
16499 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
16500 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
16501 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
16502 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
16503 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
16504 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
16505 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
16506 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
16507 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
16508 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
16509 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
16510 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
16511 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16512 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16513 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16514 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16515 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16516 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
16517 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16518 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
16519 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16520 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
16521 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
16522 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
16523};
16524#undef ARM_VARIANT
16525#undef THUMB_VARIANT
16526#undef TCE
16527#undef TCM
16528#undef TUE
16529#undef TUF
16530#undef TCC
8f06b2d8 16531#undef cCE
e3cb604e
PB
16532#undef cCL
16533#undef C3E
c19d1205
ZW
16534#undef CE
16535#undef CM
16536#undef UE
16537#undef UF
16538#undef UT
5287ad62
JB
16539#undef NUF
16540#undef nUF
16541#undef NCE
16542#undef nCE
c19d1205
ZW
16543#undef OPS0
16544#undef OPS1
16545#undef OPS2
16546#undef OPS3
16547#undef OPS4
16548#undef OPS5
16549#undef OPS6
16550#undef do_0
16551\f
16552/* MD interface: bits in the object file. */
bfae80f2 16553
c19d1205
ZW
16554/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16555 for use in the a.out file, and stores them in the array pointed to by buf.
16556 This knows about the endian-ness of the target machine and does
16557 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16558 2 (short) and 4 (long) Floating numbers are put out as a series of
16559 LITTLENUMS (shorts, here at least). */
b99bd4ef 16560
c19d1205
ZW
16561void
16562md_number_to_chars (char * buf, valueT val, int n)
16563{
16564 if (target_big_endian)
16565 number_to_chars_bigendian (buf, val, n);
16566 else
16567 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16568}
16569
c19d1205
ZW
16570static valueT
16571md_chars_to_number (char * buf, int n)
bfae80f2 16572{
c19d1205
ZW
16573 valueT result = 0;
16574 unsigned char * where = (unsigned char *) buf;
bfae80f2 16575
c19d1205 16576 if (target_big_endian)
b99bd4ef 16577 {
c19d1205
ZW
16578 while (n--)
16579 {
16580 result <<= 8;
16581 result |= (*where++ & 255);
16582 }
b99bd4ef 16583 }
c19d1205 16584 else
b99bd4ef 16585 {
c19d1205
ZW
16586 while (n--)
16587 {
16588 result <<= 8;
16589 result |= (where[n] & 255);
16590 }
bfae80f2 16591 }
b99bd4ef 16592
c19d1205 16593 return result;
bfae80f2 16594}
b99bd4ef 16595
c19d1205 16596/* MD interface: Sections. */
b99bd4ef 16597
0110f2b8
PB
16598/* Estimate the size of a frag before relaxing. Assume everything fits in
16599 2 bytes. */
16600
c19d1205 16601int
0110f2b8 16602md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16603 segT segtype ATTRIBUTE_UNUSED)
16604{
0110f2b8
PB
16605 fragp->fr_var = 2;
16606 return 2;
16607}
16608
16609/* Convert a machine dependent frag. */
16610
16611void
16612md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16613{
16614 unsigned long insn;
16615 unsigned long old_op;
16616 char *buf;
16617 expressionS exp;
16618 fixS *fixp;
16619 int reloc_type;
16620 int pc_rel;
16621 int opcode;
16622
16623 buf = fragp->fr_literal + fragp->fr_fix;
16624
16625 old_op = bfd_get_16(abfd, buf);
16626 if (fragp->fr_symbol) {
16627 exp.X_op = O_symbol;
16628 exp.X_add_symbol = fragp->fr_symbol;
16629 } else {
16630 exp.X_op = O_constant;
16631 }
16632 exp.X_add_number = fragp->fr_offset;
16633 opcode = fragp->fr_subtype;
16634 switch (opcode)
16635 {
16636 case T_MNEM_ldr_pc:
16637 case T_MNEM_ldr_pc2:
16638 case T_MNEM_ldr_sp:
16639 case T_MNEM_str_sp:
16640 case T_MNEM_ldr:
16641 case T_MNEM_ldrb:
16642 case T_MNEM_ldrh:
16643 case T_MNEM_str:
16644 case T_MNEM_strb:
16645 case T_MNEM_strh:
16646 if (fragp->fr_var == 4)
16647 {
16648 insn = THUMB_OP32(opcode);
16649 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16650 {
16651 insn |= (old_op & 0x700) << 4;
16652 }
16653 else
16654 {
16655 insn |= (old_op & 7) << 12;
16656 insn |= (old_op & 0x38) << 13;
16657 }
16658 insn |= 0x00000c00;
16659 put_thumb32_insn (buf, insn);
16660 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16661 }
16662 else
16663 {
16664 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16665 }
16666 pc_rel = (opcode == T_MNEM_ldr_pc2);
16667 break;
16668 case T_MNEM_adr:
16669 if (fragp->fr_var == 4)
16670 {
16671 insn = THUMB_OP32 (opcode);
16672 insn |= (old_op & 0xf0) << 4;
16673 put_thumb32_insn (buf, insn);
16674 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16675 }
16676 else
16677 {
16678 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16679 exp.X_add_number -= 4;
16680 }
16681 pc_rel = 1;
16682 break;
16683 case T_MNEM_mov:
16684 case T_MNEM_movs:
16685 case T_MNEM_cmp:
16686 case T_MNEM_cmn:
16687 if (fragp->fr_var == 4)
16688 {
16689 int r0off = (opcode == T_MNEM_mov
16690 || opcode == T_MNEM_movs) ? 0 : 8;
16691 insn = THUMB_OP32 (opcode);
16692 insn = (insn & 0xe1ffffff) | 0x10000000;
16693 insn |= (old_op & 0x700) << r0off;
16694 put_thumb32_insn (buf, insn);
16695 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16696 }
16697 else
16698 {
16699 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16700 }
16701 pc_rel = 0;
16702 break;
16703 case T_MNEM_b:
16704 if (fragp->fr_var == 4)
16705 {
16706 insn = THUMB_OP32(opcode);
16707 put_thumb32_insn (buf, insn);
16708 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16709 }
16710 else
16711 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16712 pc_rel = 1;
16713 break;
16714 case T_MNEM_bcond:
16715 if (fragp->fr_var == 4)
16716 {
16717 insn = THUMB_OP32(opcode);
16718 insn |= (old_op & 0xf00) << 14;
16719 put_thumb32_insn (buf, insn);
16720 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16721 }
16722 else
16723 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16724 pc_rel = 1;
16725 break;
16726 case T_MNEM_add_sp:
16727 case T_MNEM_add_pc:
16728 case T_MNEM_inc_sp:
16729 case T_MNEM_dec_sp:
16730 if (fragp->fr_var == 4)
16731 {
16732 /* ??? Choose between add and addw. */
16733 insn = THUMB_OP32 (opcode);
16734 insn |= (old_op & 0xf0) << 4;
16735 put_thumb32_insn (buf, insn);
16805f35
PB
16736 if (opcode == T_MNEM_add_pc)
16737 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16738 else
16739 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16740 }
16741 else
16742 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16743 pc_rel = 0;
16744 break;
16745
16746 case T_MNEM_addi:
16747 case T_MNEM_addis:
16748 case T_MNEM_subi:
16749 case T_MNEM_subis:
16750 if (fragp->fr_var == 4)
16751 {
16752 insn = THUMB_OP32 (opcode);
16753 insn |= (old_op & 0xf0) << 4;
16754 insn |= (old_op & 0xf) << 16;
16755 put_thumb32_insn (buf, insn);
16805f35
PB
16756 if (insn & (1 << 20))
16757 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16758 else
16759 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16760 }
16761 else
16762 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16763 pc_rel = 0;
16764 break;
16765 default:
16766 abort();
16767 }
16768 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16769 reloc_type);
16770 fixp->fx_file = fragp->fr_file;
16771 fixp->fx_line = fragp->fr_line;
16772 fragp->fr_fix += fragp->fr_var;
16773}
16774
16775/* Return the size of a relaxable immediate operand instruction.
16776 SHIFT and SIZE specify the form of the allowable immediate. */
16777static int
16778relax_immediate (fragS *fragp, int size, int shift)
16779{
16780 offsetT offset;
16781 offsetT mask;
16782 offsetT low;
16783
16784 /* ??? Should be able to do better than this. */
16785 if (fragp->fr_symbol)
16786 return 4;
16787
16788 low = (1 << shift) - 1;
16789 mask = (1 << (shift + size)) - (1 << shift);
16790 offset = fragp->fr_offset;
16791 /* Force misaligned offsets to 32-bit variant. */
16792 if (offset & low)
5e77afaa 16793 return 4;
0110f2b8
PB
16794 if (offset & ~mask)
16795 return 4;
16796 return 2;
16797}
16798
5e77afaa
PB
16799/* Get the address of a symbol during relaxation. */
16800static addressT
16801relaxed_symbol_addr(fragS *fragp, long stretch)
16802{
16803 fragS *sym_frag;
16804 addressT addr;
16805 symbolS *sym;
16806
16807 sym = fragp->fr_symbol;
16808 sym_frag = symbol_get_frag (sym);
16809 know (S_GET_SEGMENT (sym) != absolute_section
16810 || sym_frag == &zero_address_frag);
16811 addr = S_GET_VALUE (sym) + fragp->fr_offset;
16812
16813 /* If frag has yet to be reached on this pass, assume it will
16814 move by STRETCH just as we did. If this is not so, it will
16815 be because some frag between grows, and that will force
16816 another pass. */
16817
16818 if (stretch != 0
16819 && sym_frag->relax_marker != fragp->relax_marker)
16820 addr += stretch;
16821
16822 return addr;
16823}
16824
0110f2b8
PB
16825/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16826 load. */
16827static int
5e77afaa 16828relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
16829{
16830 addressT addr;
16831 offsetT val;
16832
16833 /* Assume worst case for symbols not known to be in the same section. */
16834 if (!S_IS_DEFINED(fragp->fr_symbol)
16835 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16836 return 4;
16837
5e77afaa 16838 val = relaxed_symbol_addr(fragp, stretch);
0110f2b8
PB
16839 addr = fragp->fr_address + fragp->fr_fix;
16840 addr = (addr + 4) & ~3;
5e77afaa 16841 /* Force misaligned targets to 32-bit variant. */
0110f2b8 16842 if (val & 3)
5e77afaa 16843 return 4;
0110f2b8
PB
16844 val -= addr;
16845 if (val < 0 || val > 1020)
16846 return 4;
16847 return 2;
16848}
16849
16850/* Return the size of a relaxable add/sub immediate instruction. */
16851static int
16852relax_addsub (fragS *fragp, asection *sec)
16853{
16854 char *buf;
16855 int op;
16856
16857 buf = fragp->fr_literal + fragp->fr_fix;
16858 op = bfd_get_16(sec->owner, buf);
16859 if ((op & 0xf) == ((op >> 4) & 0xf))
16860 return relax_immediate (fragp, 8, 0);
16861 else
16862 return relax_immediate (fragp, 3, 0);
16863}
16864
16865
16866/* Return the size of a relaxable branch instruction. BITS is the
16867 size of the offset field in the narrow instruction. */
16868
16869static int
5e77afaa 16870relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
16871{
16872 addressT addr;
16873 offsetT val;
16874 offsetT limit;
16875
16876 /* Assume worst case for symbols not known to be in the same section. */
16877 if (!S_IS_DEFINED(fragp->fr_symbol)
16878 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16879 return 4;
16880
5e77afaa 16881 val = relaxed_symbol_addr(fragp, stretch);
0110f2b8
PB
16882 addr = fragp->fr_address + fragp->fr_fix + 4;
16883 val -= addr;
16884
16885 /* Offset is a signed value *2 */
16886 limit = 1 << bits;
16887 if (val >= limit || val < -limit)
16888 return 4;
16889 return 2;
16890}
16891
16892
16893/* Relax a machine dependent frag. This returns the amount by which
16894 the current size of the frag should change. */
16895
16896int
5e77afaa 16897arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
16898{
16899 int oldsize;
16900 int newsize;
16901
16902 oldsize = fragp->fr_var;
16903 switch (fragp->fr_subtype)
16904 {
16905 case T_MNEM_ldr_pc2:
5e77afaa 16906 newsize = relax_adr(fragp, sec, stretch);
0110f2b8
PB
16907 break;
16908 case T_MNEM_ldr_pc:
16909 case T_MNEM_ldr_sp:
16910 case T_MNEM_str_sp:
16911 newsize = relax_immediate(fragp, 8, 2);
16912 break;
16913 case T_MNEM_ldr:
16914 case T_MNEM_str:
16915 newsize = relax_immediate(fragp, 5, 2);
16916 break;
16917 case T_MNEM_ldrh:
16918 case T_MNEM_strh:
16919 newsize = relax_immediate(fragp, 5, 1);
16920 break;
16921 case T_MNEM_ldrb:
16922 case T_MNEM_strb:
16923 newsize = relax_immediate(fragp, 5, 0);
16924 break;
16925 case T_MNEM_adr:
5e77afaa 16926 newsize = relax_adr(fragp, sec, stretch);
0110f2b8
PB
16927 break;
16928 case T_MNEM_mov:
16929 case T_MNEM_movs:
16930 case T_MNEM_cmp:
16931 case T_MNEM_cmn:
16932 newsize = relax_immediate(fragp, 8, 0);
16933 break;
16934 case T_MNEM_b:
5e77afaa 16935 newsize = relax_branch(fragp, sec, 11, stretch);
0110f2b8
PB
16936 break;
16937 case T_MNEM_bcond:
5e77afaa 16938 newsize = relax_branch(fragp, sec, 8, stretch);
0110f2b8
PB
16939 break;
16940 case T_MNEM_add_sp:
16941 case T_MNEM_add_pc:
16942 newsize = relax_immediate (fragp, 8, 2);
16943 break;
16944 case T_MNEM_inc_sp:
16945 case T_MNEM_dec_sp:
16946 newsize = relax_immediate (fragp, 7, 2);
16947 break;
16948 case T_MNEM_addi:
16949 case T_MNEM_addis:
16950 case T_MNEM_subi:
16951 case T_MNEM_subis:
16952 newsize = relax_addsub (fragp, sec);
16953 break;
16954 default:
16955 abort();
16956 }
5e77afaa
PB
16957
16958 fragp->fr_var = newsize;
16959 /* Freeze wide instructions that are at or before the same location as
16960 in the previous pass. This avoids infinite loops.
16961 Don't freeze them unconditionally because targets may be artificialy
16962 misaligned by the expansion of preceeding frags. */
16963 if (stretch <= 0 && newsize > 2)
0110f2b8 16964 {
0110f2b8
PB
16965 md_convert_frag (sec->owner, sec, fragp);
16966 frag_wane(fragp);
0110f2b8 16967 }
5e77afaa 16968
0110f2b8 16969 return newsize - oldsize;
c19d1205 16970}
b99bd4ef 16971
c19d1205 16972/* Round up a section size to the appropriate boundary. */
b99bd4ef 16973
c19d1205
ZW
16974valueT
16975md_section_align (segT segment ATTRIBUTE_UNUSED,
16976 valueT size)
16977{
f0927246
NC
16978#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16979 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16980 {
16981 /* For a.out, force the section size to be aligned. If we don't do
16982 this, BFD will align it for us, but it will not write out the
16983 final bytes of the section. This may be a bug in BFD, but it is
16984 easier to fix it here since that is how the other a.out targets
16985 work. */
16986 int align;
16987
16988 align = bfd_get_section_alignment (stdoutput, segment);
16989 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16990 }
c19d1205 16991#endif
f0927246
NC
16992
16993 return size;
bfae80f2 16994}
b99bd4ef 16995
c19d1205
ZW
16996/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16997 of an rs_align_code fragment. */
16998
16999void
17000arm_handle_align (fragS * fragP)
bfae80f2 17001{
c19d1205
ZW
17002 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
17003 static char const thumb_noop[2] = { 0xc0, 0x46 };
17004 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
17005 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
17006
17007 int bytes, fix, noop_size;
17008 char * p;
17009 const char * noop;
bfae80f2 17010
c19d1205 17011 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
17012 return;
17013
c19d1205
ZW
17014 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
17015 p = fragP->fr_literal + fragP->fr_fix;
17016 fix = 0;
bfae80f2 17017
c19d1205
ZW
17018 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
17019 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 17020
c19d1205 17021 if (fragP->tc_frag_data)
a737bd4d 17022 {
c19d1205
ZW
17023 if (target_big_endian)
17024 noop = thumb_bigend_noop;
17025 else
17026 noop = thumb_noop;
17027 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
17028 }
17029 else
17030 {
c19d1205
ZW
17031 if (target_big_endian)
17032 noop = arm_bigend_noop;
17033 else
17034 noop = arm_noop;
17035 noop_size = sizeof (arm_noop);
7ed4c4c5 17036 }
a737bd4d 17037
c19d1205 17038 if (bytes & (noop_size - 1))
7ed4c4c5 17039 {
c19d1205
ZW
17040 fix = bytes & (noop_size - 1);
17041 memset (p, 0, fix);
17042 p += fix;
17043 bytes -= fix;
a737bd4d 17044 }
a737bd4d 17045
c19d1205 17046 while (bytes >= noop_size)
a737bd4d 17047 {
c19d1205
ZW
17048 memcpy (p, noop, noop_size);
17049 p += noop_size;
17050 bytes -= noop_size;
17051 fix += noop_size;
a737bd4d
NC
17052 }
17053
c19d1205
ZW
17054 fragP->fr_fix += fix;
17055 fragP->fr_var = noop_size;
a737bd4d
NC
17056}
17057
c19d1205
ZW
17058/* Called from md_do_align. Used to create an alignment
17059 frag in a code section. */
17060
17061void
17062arm_frag_align_code (int n, int max)
bfae80f2 17063{
c19d1205 17064 char * p;
7ed4c4c5 17065
c19d1205
ZW
17066 /* We assume that there will never be a requirement
17067 to support alignments greater than 32 bytes. */
17068 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
17069 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 17070
c19d1205
ZW
17071 p = frag_var (rs_align_code,
17072 MAX_MEM_FOR_RS_ALIGN_CODE,
17073 1,
17074 (relax_substateT) max,
17075 (symbolS *) NULL,
17076 (offsetT) n,
17077 (char *) NULL);
17078 *p = 0;
17079}
bfae80f2 17080
c19d1205 17081/* Perform target specific initialisation of a frag. */
bfae80f2 17082
c19d1205
ZW
17083void
17084arm_init_frag (fragS * fragP)
17085{
17086 /* Record whether this frag is in an ARM or a THUMB area. */
17087 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
17088}
17089
c19d1205
ZW
17090#ifdef OBJ_ELF
17091/* When we change sections we need to issue a new mapping symbol. */
17092
17093void
17094arm_elf_change_section (void)
bfae80f2 17095{
c19d1205
ZW
17096 flagword flags;
17097 segment_info_type *seginfo;
bfae80f2 17098
c19d1205
ZW
17099 /* Link an unlinked unwind index table section to the .text section. */
17100 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
17101 && elf_linked_to_section (now_seg) == NULL)
17102 elf_linked_to_section (now_seg) = text_section;
17103
17104 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
17105 return;
17106
c19d1205
ZW
17107 flags = bfd_get_section_flags (stdoutput, now_seg);
17108
17109 /* We can ignore sections that only contain debug info. */
17110 if ((flags & SEC_ALLOC) == 0)
17111 return;
bfae80f2 17112
c19d1205
ZW
17113 seginfo = seg_info (now_seg);
17114 mapstate = seginfo->tc_segment_info_data.mapstate;
17115 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
17116}
17117
c19d1205
ZW
17118int
17119arm_elf_section_type (const char * str, size_t len)
e45d0630 17120{
c19d1205
ZW
17121 if (len == 5 && strncmp (str, "exidx", 5) == 0)
17122 return SHT_ARM_EXIDX;
e45d0630 17123
c19d1205
ZW
17124 return -1;
17125}
17126\f
17127/* Code to deal with unwinding tables. */
e45d0630 17128
c19d1205 17129static void add_unwind_adjustsp (offsetT);
e45d0630 17130
c19d1205 17131/* Cenerate and deferred unwind frame offset. */
e45d0630 17132
bfae80f2 17133static void
c19d1205 17134flush_pending_unwind (void)
bfae80f2 17135{
c19d1205 17136 offsetT offset;
bfae80f2 17137
c19d1205
ZW
17138 offset = unwind.pending_offset;
17139 unwind.pending_offset = 0;
17140 if (offset != 0)
17141 add_unwind_adjustsp (offset);
bfae80f2
RE
17142}
17143
c19d1205
ZW
17144/* Add an opcode to this list for this function. Two-byte opcodes should
17145 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
17146 order. */
17147
bfae80f2 17148static void
c19d1205 17149add_unwind_opcode (valueT op, int length)
bfae80f2 17150{
c19d1205
ZW
17151 /* Add any deferred stack adjustment. */
17152 if (unwind.pending_offset)
17153 flush_pending_unwind ();
bfae80f2 17154
c19d1205 17155 unwind.sp_restored = 0;
bfae80f2 17156
c19d1205 17157 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 17158 {
c19d1205
ZW
17159 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
17160 if (unwind.opcodes)
17161 unwind.opcodes = xrealloc (unwind.opcodes,
17162 unwind.opcode_alloc);
17163 else
17164 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 17165 }
c19d1205 17166 while (length > 0)
bfae80f2 17167 {
c19d1205
ZW
17168 length--;
17169 unwind.opcodes[unwind.opcode_count] = op & 0xff;
17170 op >>= 8;
17171 unwind.opcode_count++;
bfae80f2 17172 }
bfae80f2
RE
17173}
17174
c19d1205
ZW
17175/* Add unwind opcodes to adjust the stack pointer. */
17176
bfae80f2 17177static void
c19d1205 17178add_unwind_adjustsp (offsetT offset)
bfae80f2 17179{
c19d1205 17180 valueT op;
bfae80f2 17181
c19d1205 17182 if (offset > 0x200)
bfae80f2 17183 {
c19d1205
ZW
17184 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
17185 char bytes[5];
17186 int n;
17187 valueT o;
bfae80f2 17188
c19d1205
ZW
17189 /* Long form: 0xb2, uleb128. */
17190 /* This might not fit in a word so add the individual bytes,
17191 remembering the list is built in reverse order. */
17192 o = (valueT) ((offset - 0x204) >> 2);
17193 if (o == 0)
17194 add_unwind_opcode (0, 1);
bfae80f2 17195
c19d1205
ZW
17196 /* Calculate the uleb128 encoding of the offset. */
17197 n = 0;
17198 while (o)
17199 {
17200 bytes[n] = o & 0x7f;
17201 o >>= 7;
17202 if (o)
17203 bytes[n] |= 0x80;
17204 n++;
17205 }
17206 /* Add the insn. */
17207 for (; n; n--)
17208 add_unwind_opcode (bytes[n - 1], 1);
17209 add_unwind_opcode (0xb2, 1);
17210 }
17211 else if (offset > 0x100)
bfae80f2 17212 {
c19d1205
ZW
17213 /* Two short opcodes. */
17214 add_unwind_opcode (0x3f, 1);
17215 op = (offset - 0x104) >> 2;
17216 add_unwind_opcode (op, 1);
bfae80f2 17217 }
c19d1205
ZW
17218 else if (offset > 0)
17219 {
17220 /* Short opcode. */
17221 op = (offset - 4) >> 2;
17222 add_unwind_opcode (op, 1);
17223 }
17224 else if (offset < 0)
bfae80f2 17225 {
c19d1205
ZW
17226 offset = -offset;
17227 while (offset > 0x100)
bfae80f2 17228 {
c19d1205
ZW
17229 add_unwind_opcode (0x7f, 1);
17230 offset -= 0x100;
bfae80f2 17231 }
c19d1205
ZW
17232 op = ((offset - 4) >> 2) | 0x40;
17233 add_unwind_opcode (op, 1);
bfae80f2 17234 }
bfae80f2
RE
17235}
17236
c19d1205
ZW
17237/* Finish the list of unwind opcodes for this function. */
17238static void
17239finish_unwind_opcodes (void)
bfae80f2 17240{
c19d1205 17241 valueT op;
bfae80f2 17242
c19d1205 17243 if (unwind.fp_used)
bfae80f2 17244 {
708587a4 17245 /* Adjust sp as necessary. */
c19d1205
ZW
17246 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
17247 flush_pending_unwind ();
bfae80f2 17248
c19d1205
ZW
17249 /* After restoring sp from the frame pointer. */
17250 op = 0x90 | unwind.fp_reg;
17251 add_unwind_opcode (op, 1);
17252 }
17253 else
17254 flush_pending_unwind ();
bfae80f2
RE
17255}
17256
bfae80f2 17257
c19d1205
ZW
17258/* Start an exception table entry. If idx is nonzero this is an index table
17259 entry. */
bfae80f2
RE
17260
17261static void
c19d1205 17262start_unwind_section (const segT text_seg, int idx)
bfae80f2 17263{
c19d1205
ZW
17264 const char * text_name;
17265 const char * prefix;
17266 const char * prefix_once;
17267 const char * group_name;
17268 size_t prefix_len;
17269 size_t text_len;
17270 char * sec_name;
17271 size_t sec_name_len;
17272 int type;
17273 int flags;
17274 int linkonce;
bfae80f2 17275
c19d1205 17276 if (idx)
bfae80f2 17277 {
c19d1205
ZW
17278 prefix = ELF_STRING_ARM_unwind;
17279 prefix_once = ELF_STRING_ARM_unwind_once;
17280 type = SHT_ARM_EXIDX;
bfae80f2 17281 }
c19d1205 17282 else
bfae80f2 17283 {
c19d1205
ZW
17284 prefix = ELF_STRING_ARM_unwind_info;
17285 prefix_once = ELF_STRING_ARM_unwind_info_once;
17286 type = SHT_PROGBITS;
bfae80f2
RE
17287 }
17288
c19d1205
ZW
17289 text_name = segment_name (text_seg);
17290 if (streq (text_name, ".text"))
17291 text_name = "";
17292
17293 if (strncmp (text_name, ".gnu.linkonce.t.",
17294 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 17295 {
c19d1205
ZW
17296 prefix = prefix_once;
17297 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
17298 }
17299
c19d1205
ZW
17300 prefix_len = strlen (prefix);
17301 text_len = strlen (text_name);
17302 sec_name_len = prefix_len + text_len;
17303 sec_name = xmalloc (sec_name_len + 1);
17304 memcpy (sec_name, prefix, prefix_len);
17305 memcpy (sec_name + prefix_len, text_name, text_len);
17306 sec_name[prefix_len + text_len] = '\0';
bfae80f2 17307
c19d1205
ZW
17308 flags = SHF_ALLOC;
17309 linkonce = 0;
17310 group_name = 0;
bfae80f2 17311
c19d1205
ZW
17312 /* Handle COMDAT group. */
17313 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 17314 {
c19d1205
ZW
17315 group_name = elf_group_name (text_seg);
17316 if (group_name == NULL)
17317 {
17318 as_bad ("Group section `%s' has no group signature",
17319 segment_name (text_seg));
17320 ignore_rest_of_line ();
17321 return;
17322 }
17323 flags |= SHF_GROUP;
17324 linkonce = 1;
bfae80f2
RE
17325 }
17326
c19d1205 17327 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 17328
c19d1205
ZW
17329 /* Set the setion link for index tables. */
17330 if (idx)
17331 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
17332}
17333
bfae80f2 17334
c19d1205
ZW
17335/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
17336 personality routine data. Returns zero, or the index table value for
17337 and inline entry. */
17338
17339static valueT
17340create_unwind_entry (int have_data)
bfae80f2 17341{
c19d1205
ZW
17342 int size;
17343 addressT where;
17344 char *ptr;
17345 /* The current word of data. */
17346 valueT data;
17347 /* The number of bytes left in this word. */
17348 int n;
bfae80f2 17349
c19d1205 17350 finish_unwind_opcodes ();
bfae80f2 17351
c19d1205
ZW
17352 /* Remember the current text section. */
17353 unwind.saved_seg = now_seg;
17354 unwind.saved_subseg = now_subseg;
bfae80f2 17355
c19d1205 17356 start_unwind_section (now_seg, 0);
bfae80f2 17357
c19d1205 17358 if (unwind.personality_routine == NULL)
bfae80f2 17359 {
c19d1205
ZW
17360 if (unwind.personality_index == -2)
17361 {
17362 if (have_data)
17363 as_bad (_("handerdata in cantunwind frame"));
17364 return 1; /* EXIDX_CANTUNWIND. */
17365 }
bfae80f2 17366
c19d1205
ZW
17367 /* Use a default personality routine if none is specified. */
17368 if (unwind.personality_index == -1)
17369 {
17370 if (unwind.opcode_count > 3)
17371 unwind.personality_index = 1;
17372 else
17373 unwind.personality_index = 0;
17374 }
bfae80f2 17375
c19d1205
ZW
17376 /* Space for the personality routine entry. */
17377 if (unwind.personality_index == 0)
17378 {
17379 if (unwind.opcode_count > 3)
17380 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 17381
c19d1205
ZW
17382 if (!have_data)
17383 {
17384 /* All the data is inline in the index table. */
17385 data = 0x80;
17386 n = 3;
17387 while (unwind.opcode_count > 0)
17388 {
17389 unwind.opcode_count--;
17390 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17391 n--;
17392 }
bfae80f2 17393
c19d1205
ZW
17394 /* Pad with "finish" opcodes. */
17395 while (n--)
17396 data = (data << 8) | 0xb0;
bfae80f2 17397
c19d1205
ZW
17398 return data;
17399 }
17400 size = 0;
17401 }
17402 else
17403 /* We get two opcodes "free" in the first word. */
17404 size = unwind.opcode_count - 2;
17405 }
17406 else
17407 /* An extra byte is required for the opcode count. */
17408 size = unwind.opcode_count + 1;
bfae80f2 17409
c19d1205
ZW
17410 size = (size + 3) >> 2;
17411 if (size > 0xff)
17412 as_bad (_("too many unwind opcodes"));
bfae80f2 17413
c19d1205
ZW
17414 frag_align (2, 0, 0);
17415 record_alignment (now_seg, 2);
17416 unwind.table_entry = expr_build_dot ();
17417
17418 /* Allocate the table entry. */
17419 ptr = frag_more ((size << 2) + 4);
17420 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 17421
c19d1205 17422 switch (unwind.personality_index)
bfae80f2 17423 {
c19d1205
ZW
17424 case -1:
17425 /* ??? Should this be a PLT generating relocation? */
17426 /* Custom personality routine. */
17427 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
17428 BFD_RELOC_ARM_PREL31);
bfae80f2 17429
c19d1205
ZW
17430 where += 4;
17431 ptr += 4;
bfae80f2 17432
c19d1205
ZW
17433 /* Set the first byte to the number of additional words. */
17434 data = size - 1;
17435 n = 3;
17436 break;
bfae80f2 17437
c19d1205
ZW
17438 /* ABI defined personality routines. */
17439 case 0:
17440 /* Three opcodes bytes are packed into the first word. */
17441 data = 0x80;
17442 n = 3;
17443 break;
bfae80f2 17444
c19d1205
ZW
17445 case 1:
17446 case 2:
17447 /* The size and first two opcode bytes go in the first word. */
17448 data = ((0x80 + unwind.personality_index) << 8) | size;
17449 n = 2;
17450 break;
bfae80f2 17451
c19d1205
ZW
17452 default:
17453 /* Should never happen. */
17454 abort ();
17455 }
bfae80f2 17456
c19d1205
ZW
17457 /* Pack the opcodes into words (MSB first), reversing the list at the same
17458 time. */
17459 while (unwind.opcode_count > 0)
17460 {
17461 if (n == 0)
17462 {
17463 md_number_to_chars (ptr, data, 4);
17464 ptr += 4;
17465 n = 4;
17466 data = 0;
17467 }
17468 unwind.opcode_count--;
17469 n--;
17470 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
17471 }
17472
17473 /* Finish off the last word. */
17474 if (n < 4)
17475 {
17476 /* Pad with "finish" opcodes. */
17477 while (n--)
17478 data = (data << 8) | 0xb0;
17479
17480 md_number_to_chars (ptr, data, 4);
17481 }
17482
17483 if (!have_data)
17484 {
17485 /* Add an empty descriptor if there is no user-specified data. */
17486 ptr = frag_more (4);
17487 md_number_to_chars (ptr, 0, 4);
17488 }
17489
17490 return 0;
bfae80f2
RE
17491}
17492
f0927246
NC
17493
17494/* Initialize the DWARF-2 unwind information for this procedure. */
17495
17496void
17497tc_arm_frame_initial_instructions (void)
17498{
17499 cfi_add_CFA_def_cfa (REG_SP, 0);
17500}
17501#endif /* OBJ_ELF */
17502
c19d1205
ZW
17503/* Convert REGNAME to a DWARF-2 register number. */
17504
17505int
1df69f4f 17506tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 17507{
1df69f4f 17508 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
17509
17510 if (reg == FAIL)
17511 return -1;
17512
17513 return reg;
bfae80f2
RE
17514}
17515
f0927246 17516#ifdef TE_PE
c19d1205 17517void
f0927246 17518tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 17519{
f0927246 17520 expressionS expr;
bfae80f2 17521
f0927246
NC
17522 expr.X_op = O_secrel;
17523 expr.X_add_symbol = symbol;
17524 expr.X_add_number = 0;
17525 emit_expr (&expr, size);
17526}
17527#endif
bfae80f2 17528
c19d1205 17529/* MD interface: Symbol and relocation handling. */
bfae80f2 17530
2fc8bdac
ZW
17531/* Return the address within the segment that a PC-relative fixup is
17532 relative to. For ARM, PC-relative fixups applied to instructions
17533 are generally relative to the location of the fixup plus 8 bytes.
17534 Thumb branches are offset by 4, and Thumb loads relative to PC
17535 require special handling. */
bfae80f2 17536
c19d1205 17537long
2fc8bdac 17538md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 17539{
2fc8bdac
ZW
17540 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
17541
17542 /* If this is pc-relative and we are going to emit a relocation
17543 then we just want to put out any pipeline compensation that the linker
53baae48
NC
17544 will need. Otherwise we want to use the calculated base.
17545 For WinCE we skip the bias for externals as well, since this
17546 is how the MS ARM-CE assembler behaves and we want to be compatible. */
2fc8bdac
ZW
17547 if (fixP->fx_pcrel
17548 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
17549 || (arm_force_relocation (fixP)
17550#ifdef TE_WINCE
17551 && !S_IS_EXTERNAL (fixP->fx_addsy)
17552#endif
17553 )))
2fc8bdac 17554 base = 0;
bfae80f2 17555
c19d1205 17556 switch (fixP->fx_r_type)
bfae80f2 17557 {
2fc8bdac
ZW
17558 /* PC relative addressing on the Thumb is slightly odd as the
17559 bottom two bits of the PC are forced to zero for the
17560 calculation. This happens *after* application of the
17561 pipeline offset. However, Thumb adrl already adjusts for
17562 this, so we need not do it again. */
c19d1205 17563 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17564 return base & ~3;
c19d1205
ZW
17565
17566 case BFD_RELOC_ARM_THUMB_OFFSET:
17567 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17568 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17569 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17570 return (base + 4) & ~3;
c19d1205 17571
2fc8bdac
ZW
17572 /* Thumb branches are simply offset by +4. */
17573 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17574 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17575 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17576 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17577 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17578 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17579 case BFD_RELOC_THUMB_PCREL_BLX:
17580 return base + 4;
bfae80f2 17581
2fc8bdac
ZW
17582 /* ARM mode branches are offset by +8. However, the Windows CE
17583 loader expects the relocation not to take this into account. */
17584 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17585 case BFD_RELOC_ARM_PCREL_CALL:
17586 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17587 case BFD_RELOC_ARM_PCREL_BLX:
17588 case BFD_RELOC_ARM_PLT32:
c19d1205 17589#ifdef TE_WINCE
53baae48
NC
17590 /* When handling fixups immediately, because we have already
17591 discovered the value of a symbol, or the address of the frag involved
17592 we must account for the offset by +8, as the OS loader will never see the reloc.
17593 see fixup_segment() in write.c
17594 The S_IS_EXTERNAL test handles the case of global symbols.
17595 Those need the calculated base, not just the pipe compensation the linker will need. */
17596 if (fixP->fx_pcrel
17597 && fixP->fx_addsy != NULL
17598 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17599 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17600 return base + 8;
2fc8bdac 17601 return base;
c19d1205 17602#else
2fc8bdac 17603 return base + 8;
c19d1205 17604#endif
2fc8bdac
ZW
17605
17606 /* ARM mode loads relative to PC are also offset by +8. Unlike
17607 branches, the Windows CE loader *does* expect the relocation
17608 to take this into account. */
17609 case BFD_RELOC_ARM_OFFSET_IMM:
17610 case BFD_RELOC_ARM_OFFSET_IMM8:
17611 case BFD_RELOC_ARM_HWLITERAL:
17612 case BFD_RELOC_ARM_LITERAL:
17613 case BFD_RELOC_ARM_CP_OFF_IMM:
17614 return base + 8;
17615
17616
17617 /* Other PC-relative relocations are un-offset. */
17618 default:
17619 return base;
17620 }
bfae80f2
RE
17621}
17622
c19d1205
ZW
17623/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17624 Otherwise we have no need to default values of symbols. */
17625
17626symbolS *
17627md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17628{
c19d1205
ZW
17629#ifdef OBJ_ELF
17630 if (name[0] == '_' && name[1] == 'G'
17631 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17632 {
17633 if (!GOT_symbol)
17634 {
17635 if (symbol_find (name))
17636 as_bad ("GOT already in the symbol table");
bfae80f2 17637
c19d1205
ZW
17638 GOT_symbol = symbol_new (name, undefined_section,
17639 (valueT) 0, & zero_address_frag);
17640 }
bfae80f2 17641
c19d1205 17642 return GOT_symbol;
bfae80f2 17643 }
c19d1205 17644#endif
bfae80f2 17645
c19d1205 17646 return 0;
bfae80f2
RE
17647}
17648
55cf6793 17649/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17650 computed as two separate immediate values, added together. We
17651 already know that this value cannot be computed by just one ARM
17652 instruction. */
17653
17654static unsigned int
17655validate_immediate_twopart (unsigned int val,
17656 unsigned int * highpart)
bfae80f2 17657{
c19d1205
ZW
17658 unsigned int a;
17659 unsigned int i;
bfae80f2 17660
c19d1205
ZW
17661 for (i = 0; i < 32; i += 2)
17662 if (((a = rotate_left (val, i)) & 0xff) != 0)
17663 {
17664 if (a & 0xff00)
17665 {
17666 if (a & ~ 0xffff)
17667 continue;
17668 * highpart = (a >> 8) | ((i + 24) << 7);
17669 }
17670 else if (a & 0xff0000)
17671 {
17672 if (a & 0xff000000)
17673 continue;
17674 * highpart = (a >> 16) | ((i + 16) << 7);
17675 }
17676 else
17677 {
17678 assert (a & 0xff000000);
17679 * highpart = (a >> 24) | ((i + 8) << 7);
17680 }
bfae80f2 17681
c19d1205
ZW
17682 return (a & 0xff) | (i << 7);
17683 }
bfae80f2 17684
c19d1205 17685 return FAIL;
bfae80f2
RE
17686}
17687
c19d1205
ZW
17688static int
17689validate_offset_imm (unsigned int val, int hwse)
17690{
17691 if ((hwse && val > 255) || val > 4095)
17692 return FAIL;
17693 return val;
17694}
bfae80f2 17695
55cf6793 17696/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17697 negative immediate constant by altering the instruction. A bit of
17698 a hack really.
17699 MOV <-> MVN
17700 AND <-> BIC
17701 ADC <-> SBC
17702 by inverting the second operand, and
17703 ADD <-> SUB
17704 CMP <-> CMN
17705 by negating the second operand. */
bfae80f2 17706
c19d1205
ZW
17707static int
17708negate_data_op (unsigned long * instruction,
17709 unsigned long value)
bfae80f2 17710{
c19d1205
ZW
17711 int op, new_inst;
17712 unsigned long negated, inverted;
bfae80f2 17713
c19d1205
ZW
17714 negated = encode_arm_immediate (-value);
17715 inverted = encode_arm_immediate (~value);
bfae80f2 17716
c19d1205
ZW
17717 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17718 switch (op)
bfae80f2 17719 {
c19d1205
ZW
17720 /* First negates. */
17721 case OPCODE_SUB: /* ADD <-> SUB */
17722 new_inst = OPCODE_ADD;
17723 value = negated;
17724 break;
bfae80f2 17725
c19d1205
ZW
17726 case OPCODE_ADD:
17727 new_inst = OPCODE_SUB;
17728 value = negated;
17729 break;
bfae80f2 17730
c19d1205
ZW
17731 case OPCODE_CMP: /* CMP <-> CMN */
17732 new_inst = OPCODE_CMN;
17733 value = negated;
17734 break;
bfae80f2 17735
c19d1205
ZW
17736 case OPCODE_CMN:
17737 new_inst = OPCODE_CMP;
17738 value = negated;
17739 break;
bfae80f2 17740
c19d1205
ZW
17741 /* Now Inverted ops. */
17742 case OPCODE_MOV: /* MOV <-> MVN */
17743 new_inst = OPCODE_MVN;
17744 value = inverted;
17745 break;
bfae80f2 17746
c19d1205
ZW
17747 case OPCODE_MVN:
17748 new_inst = OPCODE_MOV;
17749 value = inverted;
17750 break;
bfae80f2 17751
c19d1205
ZW
17752 case OPCODE_AND: /* AND <-> BIC */
17753 new_inst = OPCODE_BIC;
17754 value = inverted;
17755 break;
bfae80f2 17756
c19d1205
ZW
17757 case OPCODE_BIC:
17758 new_inst = OPCODE_AND;
17759 value = inverted;
17760 break;
bfae80f2 17761
c19d1205
ZW
17762 case OPCODE_ADC: /* ADC <-> SBC */
17763 new_inst = OPCODE_SBC;
17764 value = inverted;
17765 break;
bfae80f2 17766
c19d1205
ZW
17767 case OPCODE_SBC:
17768 new_inst = OPCODE_ADC;
17769 value = inverted;
17770 break;
bfae80f2 17771
c19d1205
ZW
17772 /* We cannot do anything. */
17773 default:
17774 return FAIL;
b99bd4ef
NC
17775 }
17776
c19d1205
ZW
17777 if (value == (unsigned) FAIL)
17778 return FAIL;
17779
17780 *instruction &= OPCODE_MASK;
17781 *instruction |= new_inst << DATA_OP_SHIFT;
17782 return value;
b99bd4ef
NC
17783}
17784
ef8d22e6
PB
17785/* Like negate_data_op, but for Thumb-2. */
17786
17787static unsigned int
16dd5e42 17788thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
17789{
17790 int op, new_inst;
17791 int rd;
16dd5e42 17792 unsigned int negated, inverted;
ef8d22e6
PB
17793
17794 negated = encode_thumb32_immediate (-value);
17795 inverted = encode_thumb32_immediate (~value);
17796
17797 rd = (*instruction >> 8) & 0xf;
17798 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17799 switch (op)
17800 {
17801 /* ADD <-> SUB. Includes CMP <-> CMN. */
17802 case T2_OPCODE_SUB:
17803 new_inst = T2_OPCODE_ADD;
17804 value = negated;
17805 break;
17806
17807 case T2_OPCODE_ADD:
17808 new_inst = T2_OPCODE_SUB;
17809 value = negated;
17810 break;
17811
17812 /* ORR <-> ORN. Includes MOV <-> MVN. */
17813 case T2_OPCODE_ORR:
17814 new_inst = T2_OPCODE_ORN;
17815 value = inverted;
17816 break;
17817
17818 case T2_OPCODE_ORN:
17819 new_inst = T2_OPCODE_ORR;
17820 value = inverted;
17821 break;
17822
17823 /* AND <-> BIC. TST has no inverted equivalent. */
17824 case T2_OPCODE_AND:
17825 new_inst = T2_OPCODE_BIC;
17826 if (rd == 15)
17827 value = FAIL;
17828 else
17829 value = inverted;
17830 break;
17831
17832 case T2_OPCODE_BIC:
17833 new_inst = T2_OPCODE_AND;
17834 value = inverted;
17835 break;
17836
17837 /* ADC <-> SBC */
17838 case T2_OPCODE_ADC:
17839 new_inst = T2_OPCODE_SBC;
17840 value = inverted;
17841 break;
17842
17843 case T2_OPCODE_SBC:
17844 new_inst = T2_OPCODE_ADC;
17845 value = inverted;
17846 break;
17847
17848 /* We cannot do anything. */
17849 default:
17850 return FAIL;
17851 }
17852
16dd5e42 17853 if (value == (unsigned int)FAIL)
ef8d22e6
PB
17854 return FAIL;
17855
17856 *instruction &= T2_OPCODE_MASK;
17857 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17858 return value;
17859}
17860
8f06b2d8
PB
17861/* Read a 32-bit thumb instruction from buf. */
17862static unsigned long
17863get_thumb32_insn (char * buf)
17864{
17865 unsigned long insn;
17866 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17867 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17868
17869 return insn;
17870}
17871
a8bc6c78
PB
17872
17873/* We usually want to set the low bit on the address of thumb function
17874 symbols. In particular .word foo - . should have the low bit set.
17875 Generic code tries to fold the difference of two symbols to
17876 a constant. Prevent this and force a relocation when the first symbols
17877 is a thumb function. */
17878int
17879arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17880{
17881 if (op == O_subtract
17882 && l->X_op == O_symbol
17883 && r->X_op == O_symbol
17884 && THUMB_IS_FUNC (l->X_add_symbol))
17885 {
17886 l->X_op = O_subtract;
17887 l->X_op_symbol = r->X_add_symbol;
17888 l->X_add_number -= r->X_add_number;
17889 return 1;
17890 }
17891 /* Process as normal. */
17892 return 0;
17893}
17894
c19d1205 17895void
55cf6793 17896md_apply_fix (fixS * fixP,
c19d1205
ZW
17897 valueT * valP,
17898 segT seg)
17899{
17900 offsetT value = * valP;
17901 offsetT newval;
17902 unsigned int newimm;
17903 unsigned long temp;
17904 int sign;
17905 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17906
c19d1205 17907 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17908
c19d1205 17909 /* Note whether this will delete the relocation. */
4962c51a 17910
c19d1205
ZW
17911 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17912 fixP->fx_done = 1;
b99bd4ef 17913
adbaf948
ZW
17914 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17915 consistency with the behavior on 32-bit hosts. Remember value
17916 for emit_reloc. */
17917 value &= 0xffffffff;
17918 value ^= 0x80000000;
17919 value -= 0x80000000;
17920
17921 *valP = value;
c19d1205 17922 fixP->fx_addnumber = value;
b99bd4ef 17923
adbaf948
ZW
17924 /* Same treatment for fixP->fx_offset. */
17925 fixP->fx_offset &= 0xffffffff;
17926 fixP->fx_offset ^= 0x80000000;
17927 fixP->fx_offset -= 0x80000000;
17928
c19d1205 17929 switch (fixP->fx_r_type)
b99bd4ef 17930 {
c19d1205
ZW
17931 case BFD_RELOC_NONE:
17932 /* This will need to go in the object file. */
17933 fixP->fx_done = 0;
17934 break;
b99bd4ef 17935
c19d1205
ZW
17936 case BFD_RELOC_ARM_IMMEDIATE:
17937 /* We claim that this fixup has been processed here,
17938 even if in fact we generate an error because we do
17939 not have a reloc for it, so tc_gen_reloc will reject it. */
17940 fixP->fx_done = 1;
b99bd4ef 17941
c19d1205
ZW
17942 if (fixP->fx_addsy
17943 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17944 {
c19d1205
ZW
17945 as_bad_where (fixP->fx_file, fixP->fx_line,
17946 _("undefined symbol %s used as an immediate value"),
17947 S_GET_NAME (fixP->fx_addsy));
17948 break;
b99bd4ef
NC
17949 }
17950
c19d1205
ZW
17951 newimm = encode_arm_immediate (value);
17952 temp = md_chars_to_number (buf, INSN_SIZE);
17953
17954 /* If the instruction will fail, see if we can fix things up by
17955 changing the opcode. */
17956 if (newimm == (unsigned int) FAIL
17957 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17958 {
c19d1205
ZW
17959 as_bad_where (fixP->fx_file, fixP->fx_line,
17960 _("invalid constant (%lx) after fixup"),
17961 (unsigned long) value);
17962 break;
b99bd4ef 17963 }
b99bd4ef 17964
c19d1205
ZW
17965 newimm |= (temp & 0xfffff000);
17966 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17967 break;
b99bd4ef 17968
c19d1205
ZW
17969 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17970 {
17971 unsigned int highpart = 0;
17972 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 17973
c19d1205
ZW
17974 newimm = encode_arm_immediate (value);
17975 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 17976
c19d1205
ZW
17977 /* If the instruction will fail, see if we can fix things up by
17978 changing the opcode. */
17979 if (newimm == (unsigned int) FAIL
17980 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17981 {
17982 /* No ? OK - try using two ADD instructions to generate
17983 the value. */
17984 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 17985
c19d1205
ZW
17986 /* Yes - then make sure that the second instruction is
17987 also an add. */
17988 if (newimm != (unsigned int) FAIL)
17989 newinsn = temp;
17990 /* Still No ? Try using a negated value. */
17991 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17992 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17993 /* Otherwise - give up. */
17994 else
17995 {
17996 as_bad_where (fixP->fx_file, fixP->fx_line,
17997 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17998 (long) value);
17999 break;
18000 }
b99bd4ef 18001
c19d1205
ZW
18002 /* Replace the first operand in the 2nd instruction (which
18003 is the PC) with the destination register. We have
18004 already added in the PC in the first instruction and we
18005 do not want to do it again. */
18006 newinsn &= ~ 0xf0000;
18007 newinsn |= ((newinsn & 0x0f000) << 4);
18008 }
b99bd4ef 18009
c19d1205
ZW
18010 newimm |= (temp & 0xfffff000);
18011 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 18012
c19d1205
ZW
18013 highpart |= (newinsn & 0xfffff000);
18014 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
18015 }
18016 break;
b99bd4ef 18017
c19d1205 18018 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18019 if (!fixP->fx_done && seg->use_rela_p)
18020 value = 0;
18021
c19d1205
ZW
18022 case BFD_RELOC_ARM_LITERAL:
18023 sign = value >= 0;
b99bd4ef 18024
c19d1205
ZW
18025 if (value < 0)
18026 value = - value;
b99bd4ef 18027
c19d1205 18028 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 18029 {
c19d1205
ZW
18030 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
18031 as_bad_where (fixP->fx_file, fixP->fx_line,
18032 _("invalid literal constant: pool needs to be closer"));
18033 else
18034 as_bad_where (fixP->fx_file, fixP->fx_line,
18035 _("bad immediate value for offset (%ld)"),
18036 (long) value);
18037 break;
f03698e6
RE
18038 }
18039
c19d1205
ZW
18040 newval = md_chars_to_number (buf, INSN_SIZE);
18041 newval &= 0xff7ff000;
18042 newval |= value | (sign ? INDEX_UP : 0);
18043 md_number_to_chars (buf, newval, INSN_SIZE);
18044 break;
b99bd4ef 18045
c19d1205
ZW
18046 case BFD_RELOC_ARM_OFFSET_IMM8:
18047 case BFD_RELOC_ARM_HWLITERAL:
18048 sign = value >= 0;
b99bd4ef 18049
c19d1205
ZW
18050 if (value < 0)
18051 value = - value;
b99bd4ef 18052
c19d1205 18053 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 18054 {
c19d1205
ZW
18055 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
18056 as_bad_where (fixP->fx_file, fixP->fx_line,
18057 _("invalid literal constant: pool needs to be closer"));
18058 else
f9d4405b 18059 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
18060 (long) value);
18061 break;
b99bd4ef
NC
18062 }
18063
c19d1205
ZW
18064 newval = md_chars_to_number (buf, INSN_SIZE);
18065 newval &= 0xff7ff0f0;
18066 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
18067 md_number_to_chars (buf, newval, INSN_SIZE);
18068 break;
b99bd4ef 18069
c19d1205
ZW
18070 case BFD_RELOC_ARM_T32_OFFSET_U8:
18071 if (value < 0 || value > 1020 || value % 4 != 0)
18072 as_bad_where (fixP->fx_file, fixP->fx_line,
18073 _("bad immediate value for offset (%ld)"), (long) value);
18074 value /= 4;
b99bd4ef 18075
c19d1205 18076 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
18077 newval |= value;
18078 md_number_to_chars (buf+2, newval, THUMB_SIZE);
18079 break;
b99bd4ef 18080
c19d1205
ZW
18081 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18082 /* This is a complicated relocation used for all varieties of Thumb32
18083 load/store instruction with immediate offset:
18084
18085 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
18086 *4, optional writeback(W)
18087 (doubleword load/store)
18088
18089 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
18090 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
18091 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
18092 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
18093 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
18094
18095 Uppercase letters indicate bits that are already encoded at
18096 this point. Lowercase letters are our problem. For the
18097 second block of instructions, the secondary opcode nybble
18098 (bits 8..11) is present, and bit 23 is zero, even if this is
18099 a PC-relative operation. */
18100 newval = md_chars_to_number (buf, THUMB_SIZE);
18101 newval <<= 16;
18102 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 18103
c19d1205 18104 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 18105 {
c19d1205
ZW
18106 /* Doubleword load/store: 8-bit offset, scaled by 4. */
18107 if (value >= 0)
18108 newval |= (1 << 23);
18109 else
18110 value = -value;
18111 if (value % 4 != 0)
18112 {
18113 as_bad_where (fixP->fx_file, fixP->fx_line,
18114 _("offset not a multiple of 4"));
18115 break;
18116 }
18117 value /= 4;
216d22bc 18118 if (value > 0xff)
c19d1205
ZW
18119 {
18120 as_bad_where (fixP->fx_file, fixP->fx_line,
18121 _("offset out of range"));
18122 break;
18123 }
18124 newval &= ~0xff;
b99bd4ef 18125 }
c19d1205 18126 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 18127 {
c19d1205
ZW
18128 /* PC-relative, 12-bit offset. */
18129 if (value >= 0)
18130 newval |= (1 << 23);
18131 else
18132 value = -value;
216d22bc 18133 if (value > 0xfff)
c19d1205
ZW
18134 {
18135 as_bad_where (fixP->fx_file, fixP->fx_line,
18136 _("offset out of range"));
18137 break;
18138 }
18139 newval &= ~0xfff;
b99bd4ef 18140 }
c19d1205 18141 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 18142 {
c19d1205
ZW
18143 /* Writeback: 8-bit, +/- offset. */
18144 if (value >= 0)
18145 newval |= (1 << 9);
18146 else
18147 value = -value;
216d22bc 18148 if (value > 0xff)
c19d1205
ZW
18149 {
18150 as_bad_where (fixP->fx_file, fixP->fx_line,
18151 _("offset out of range"));
18152 break;
18153 }
18154 newval &= ~0xff;
b99bd4ef 18155 }
c19d1205 18156 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 18157 {
c19d1205 18158 /* T-instruction: positive 8-bit offset. */
216d22bc 18159 if (value < 0 || value > 0xff)
b99bd4ef 18160 {
c19d1205
ZW
18161 as_bad_where (fixP->fx_file, fixP->fx_line,
18162 _("offset out of range"));
18163 break;
b99bd4ef 18164 }
c19d1205
ZW
18165 newval &= ~0xff;
18166 newval |= value;
b99bd4ef
NC
18167 }
18168 else
b99bd4ef 18169 {
c19d1205
ZW
18170 /* Positive 12-bit or negative 8-bit offset. */
18171 int limit;
18172 if (value >= 0)
b99bd4ef 18173 {
c19d1205
ZW
18174 newval |= (1 << 23);
18175 limit = 0xfff;
18176 }
18177 else
18178 {
18179 value = -value;
18180 limit = 0xff;
18181 }
18182 if (value > limit)
18183 {
18184 as_bad_where (fixP->fx_file, fixP->fx_line,
18185 _("offset out of range"));
18186 break;
b99bd4ef 18187 }
c19d1205 18188 newval &= ~limit;
b99bd4ef 18189 }
b99bd4ef 18190
c19d1205
ZW
18191 newval |= value;
18192 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
18193 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
18194 break;
404ff6b5 18195
c19d1205
ZW
18196 case BFD_RELOC_ARM_SHIFT_IMM:
18197 newval = md_chars_to_number (buf, INSN_SIZE);
18198 if (((unsigned long) value) > 32
18199 || (value == 32
18200 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
18201 {
18202 as_bad_where (fixP->fx_file, fixP->fx_line,
18203 _("shift expression is too large"));
18204 break;
18205 }
404ff6b5 18206
c19d1205
ZW
18207 if (value == 0)
18208 /* Shifts of zero must be done as lsl. */
18209 newval &= ~0x60;
18210 else if (value == 32)
18211 value = 0;
18212 newval &= 0xfffff07f;
18213 newval |= (value & 0x1f) << 7;
18214 md_number_to_chars (buf, newval, INSN_SIZE);
18215 break;
404ff6b5 18216
c19d1205 18217 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 18218 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 18219 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 18220 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
18221 /* We claim that this fixup has been processed here,
18222 even if in fact we generate an error because we do
18223 not have a reloc for it, so tc_gen_reloc will reject it. */
18224 fixP->fx_done = 1;
404ff6b5 18225
c19d1205
ZW
18226 if (fixP->fx_addsy
18227 && ! S_IS_DEFINED (fixP->fx_addsy))
18228 {
18229 as_bad_where (fixP->fx_file, fixP->fx_line,
18230 _("undefined symbol %s used as an immediate value"),
18231 S_GET_NAME (fixP->fx_addsy));
18232 break;
18233 }
404ff6b5 18234
c19d1205
ZW
18235 newval = md_chars_to_number (buf, THUMB_SIZE);
18236 newval <<= 16;
18237 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 18238
16805f35
PB
18239 newimm = FAIL;
18240 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18241 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
18242 {
18243 newimm = encode_thumb32_immediate (value);
18244 if (newimm == (unsigned int) FAIL)
18245 newimm = thumb32_negate_data_op (&newval, value);
18246 }
16805f35
PB
18247 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
18248 && newimm == (unsigned int) FAIL)
92e90b6e 18249 {
16805f35
PB
18250 /* Turn add/sum into addw/subw. */
18251 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
18252 newval = (newval & 0xfeffffff) | 0x02000000;
18253
e9f89963
PB
18254 /* 12 bit immediate for addw/subw. */
18255 if (value < 0)
18256 {
18257 value = -value;
18258 newval ^= 0x00a00000;
18259 }
92e90b6e
PB
18260 if (value > 0xfff)
18261 newimm = (unsigned int) FAIL;
18262 else
18263 newimm = value;
18264 }
cc8a6dd0 18265
c19d1205 18266 if (newimm == (unsigned int)FAIL)
3631a3c8 18267 {
c19d1205
ZW
18268 as_bad_where (fixP->fx_file, fixP->fx_line,
18269 _("invalid constant (%lx) after fixup"),
18270 (unsigned long) value);
18271 break;
3631a3c8
NC
18272 }
18273
c19d1205
ZW
18274 newval |= (newimm & 0x800) << 15;
18275 newval |= (newimm & 0x700) << 4;
18276 newval |= (newimm & 0x0ff);
cc8a6dd0 18277
c19d1205
ZW
18278 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
18279 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
18280 break;
a737bd4d 18281
3eb17e6b 18282 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
18283 if (((unsigned long) value) > 0xffff)
18284 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 18285 _("invalid smc expression"));
2fc8bdac 18286 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18287 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
18288 md_number_to_chars (buf, newval, INSN_SIZE);
18289 break;
a737bd4d 18290
c19d1205 18291 case BFD_RELOC_ARM_SWI:
adbaf948 18292 if (fixP->tc_fix_data != 0)
c19d1205
ZW
18293 {
18294 if (((unsigned long) value) > 0xff)
18295 as_bad_where (fixP->fx_file, fixP->fx_line,
18296 _("invalid swi expression"));
2fc8bdac 18297 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
18298 newval |= value;
18299 md_number_to_chars (buf, newval, THUMB_SIZE);
18300 }
18301 else
18302 {
18303 if (((unsigned long) value) > 0x00ffffff)
18304 as_bad_where (fixP->fx_file, fixP->fx_line,
18305 _("invalid swi expression"));
2fc8bdac 18306 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
18307 newval |= value;
18308 md_number_to_chars (buf, newval, INSN_SIZE);
18309 }
18310 break;
a737bd4d 18311
c19d1205
ZW
18312 case BFD_RELOC_ARM_MULTI:
18313 if (((unsigned long) value) > 0xffff)
18314 as_bad_where (fixP->fx_file, fixP->fx_line,
18315 _("invalid expression in load/store multiple"));
18316 newval = value | md_chars_to_number (buf, INSN_SIZE);
18317 md_number_to_chars (buf, newval, INSN_SIZE);
18318 break;
a737bd4d 18319
c19d1205 18320#ifdef OBJ_ELF
39b41c9c
PB
18321 case BFD_RELOC_ARM_PCREL_CALL:
18322 newval = md_chars_to_number (buf, INSN_SIZE);
18323 if ((newval & 0xf0000000) == 0xf0000000)
18324 temp = 1;
18325 else
18326 temp = 3;
18327 goto arm_branch_common;
18328
18329 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18330 case BFD_RELOC_ARM_PLT32:
c19d1205 18331#endif
39b41c9c
PB
18332 case BFD_RELOC_ARM_PCREL_BRANCH:
18333 temp = 3;
18334 goto arm_branch_common;
a737bd4d 18335
39b41c9c
PB
18336 case BFD_RELOC_ARM_PCREL_BLX:
18337 temp = 1;
18338 arm_branch_common:
c19d1205 18339 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
18340 instruction, in a 24 bit, signed field. Bits 26 through 32 either
18341 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
18342 also be be clear. */
18343 if (value & temp)
c19d1205 18344 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
18345 _("misaligned branch destination"));
18346 if ((value & (offsetT)0xfe000000) != (offsetT)0
18347 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
18348 as_bad_where (fixP->fx_file, fixP->fx_line,
18349 _("branch out of range"));
a737bd4d 18350
2fc8bdac 18351 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18352 {
2fc8bdac
ZW
18353 newval = md_chars_to_number (buf, INSN_SIZE);
18354 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
18355 /* Set the H bit on BLX instructions. */
18356 if (temp == 1)
18357 {
18358 if (value & 2)
18359 newval |= 0x01000000;
18360 else
18361 newval &= ~0x01000000;
18362 }
2fc8bdac 18363 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 18364 }
c19d1205 18365 break;
a737bd4d 18366
25fe350b
MS
18367 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
18368 /* CBZ can only branch forward. */
a737bd4d 18369
738755b0
MS
18370 /* Attempts to use CBZ to branch to the next instruction
18371 (which, strictly speaking, are prohibited) will be turned into
18372 no-ops.
18373
18374 FIXME: It may be better to remove the instruction completely and
18375 perform relaxation. */
18376 if (value == -2)
2fc8bdac
ZW
18377 {
18378 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 18379 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
18380 md_number_to_chars (buf, newval, THUMB_SIZE);
18381 }
738755b0
MS
18382 else
18383 {
18384 if (value & ~0x7e)
18385 as_bad_where (fixP->fx_file, fixP->fx_line,
18386 _("branch out of range"));
18387
18388 if (fixP->fx_done || !seg->use_rela_p)
18389 {
18390 newval = md_chars_to_number (buf, THUMB_SIZE);
18391 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
18392 md_number_to_chars (buf, newval, THUMB_SIZE);
18393 }
18394 }
c19d1205 18395 break;
a737bd4d 18396
c19d1205 18397 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
18398 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
18399 as_bad_where (fixP->fx_file, fixP->fx_line,
18400 _("branch out of range"));
a737bd4d 18401
2fc8bdac
ZW
18402 if (fixP->fx_done || !seg->use_rela_p)
18403 {
18404 newval = md_chars_to_number (buf, THUMB_SIZE);
18405 newval |= (value & 0x1ff) >> 1;
18406 md_number_to_chars (buf, newval, THUMB_SIZE);
18407 }
c19d1205 18408 break;
a737bd4d 18409
c19d1205 18410 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
18411 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
18412 as_bad_where (fixP->fx_file, fixP->fx_line,
18413 _("branch out of range"));
a737bd4d 18414
2fc8bdac
ZW
18415 if (fixP->fx_done || !seg->use_rela_p)
18416 {
18417 newval = md_chars_to_number (buf, THUMB_SIZE);
18418 newval |= (value & 0xfff) >> 1;
18419 md_number_to_chars (buf, newval, THUMB_SIZE);
18420 }
c19d1205 18421 break;
a737bd4d 18422
c19d1205 18423 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
18424 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
18425 as_bad_where (fixP->fx_file, fixP->fx_line,
18426 _("conditional branch out of range"));
404ff6b5 18427
2fc8bdac
ZW
18428 if (fixP->fx_done || !seg->use_rela_p)
18429 {
18430 offsetT newval2;
18431 addressT S, J1, J2, lo, hi;
404ff6b5 18432
2fc8bdac
ZW
18433 S = (value & 0x00100000) >> 20;
18434 J2 = (value & 0x00080000) >> 19;
18435 J1 = (value & 0x00040000) >> 18;
18436 hi = (value & 0x0003f000) >> 12;
18437 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18438
2fc8bdac
ZW
18439 newval = md_chars_to_number (buf, THUMB_SIZE);
18440 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18441 newval |= (S << 10) | hi;
18442 newval2 |= (J1 << 13) | (J2 << 11) | lo;
18443 md_number_to_chars (buf, newval, THUMB_SIZE);
18444 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18445 }
c19d1205 18446 break;
6c43fab6 18447
c19d1205
ZW
18448 case BFD_RELOC_THUMB_PCREL_BLX:
18449 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
18450 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
18451 as_bad_where (fixP->fx_file, fixP->fx_line,
18452 _("branch out of range"));
404ff6b5 18453
2fc8bdac
ZW
18454 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
18455 /* For a BLX instruction, make sure that the relocation is rounded up
18456 to a word boundary. This follows the semantics of the instruction
18457 which specifies that bit 1 of the target address will come from bit
18458 1 of the base address. */
18459 value = (value + 1) & ~ 1;
404ff6b5 18460
2fc8bdac 18461 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18462 {
2fc8bdac
ZW
18463 offsetT newval2;
18464
18465 newval = md_chars_to_number (buf, THUMB_SIZE);
18466 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18467 newval |= (value & 0x7fffff) >> 12;
18468 newval2 |= (value & 0xfff) >> 1;
18469 md_number_to_chars (buf, newval, THUMB_SIZE);
18470 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 18471 }
c19d1205 18472 break;
404ff6b5 18473
c19d1205 18474 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
18475 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
18476 as_bad_where (fixP->fx_file, fixP->fx_line,
18477 _("branch out of range"));
6c43fab6 18478
2fc8bdac
ZW
18479 if (fixP->fx_done || !seg->use_rela_p)
18480 {
18481 offsetT newval2;
18482 addressT S, I1, I2, lo, hi;
6c43fab6 18483
2fc8bdac
ZW
18484 S = (value & 0x01000000) >> 24;
18485 I1 = (value & 0x00800000) >> 23;
18486 I2 = (value & 0x00400000) >> 22;
18487 hi = (value & 0x003ff000) >> 12;
18488 lo = (value & 0x00000ffe) >> 1;
6c43fab6 18489
2fc8bdac
ZW
18490 I1 = !(I1 ^ S);
18491 I2 = !(I2 ^ S);
a737bd4d 18492
2fc8bdac
ZW
18493 newval = md_chars_to_number (buf, THUMB_SIZE);
18494 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
18495 newval |= (S << 10) | hi;
18496 newval2 |= (I1 << 13) | (I2 << 11) | lo;
18497 md_number_to_chars (buf, newval, THUMB_SIZE);
18498 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
18499 }
18500 break;
a737bd4d 18501
2fc8bdac
ZW
18502 case BFD_RELOC_8:
18503 if (fixP->fx_done || !seg->use_rela_p)
18504 md_number_to_chars (buf, value, 1);
c19d1205 18505 break;
a737bd4d 18506
c19d1205 18507 case BFD_RELOC_16:
2fc8bdac 18508 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 18509 md_number_to_chars (buf, value, 2);
c19d1205 18510 break;
a737bd4d 18511
c19d1205
ZW
18512#ifdef OBJ_ELF
18513 case BFD_RELOC_ARM_TLS_GD32:
18514 case BFD_RELOC_ARM_TLS_LE32:
18515 case BFD_RELOC_ARM_TLS_IE32:
18516 case BFD_RELOC_ARM_TLS_LDM32:
18517 case BFD_RELOC_ARM_TLS_LDO32:
18518 S_SET_THREAD_LOCAL (fixP->fx_addsy);
18519 /* fall through */
6c43fab6 18520
c19d1205
ZW
18521 case BFD_RELOC_ARM_GOT32:
18522 case BFD_RELOC_ARM_GOTOFF:
18523 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
18524 if (fixP->fx_done || !seg->use_rela_p)
18525 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
18526 break;
18527#endif
6c43fab6 18528
c19d1205
ZW
18529 case BFD_RELOC_RVA:
18530 case BFD_RELOC_32:
18531 case BFD_RELOC_ARM_TARGET1:
18532 case BFD_RELOC_ARM_ROSEGREL32:
18533 case BFD_RELOC_ARM_SBREL32:
18534 case BFD_RELOC_32_PCREL:
f0927246
NC
18535#ifdef TE_PE
18536 case BFD_RELOC_32_SECREL:
18537#endif
2fc8bdac 18538 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
18539#ifdef TE_WINCE
18540 /* For WinCE we only do this for pcrel fixups. */
18541 if (fixP->fx_done || fixP->fx_pcrel)
18542#endif
18543 md_number_to_chars (buf, value, 4);
c19d1205 18544 break;
6c43fab6 18545
c19d1205
ZW
18546#ifdef OBJ_ELF
18547 case BFD_RELOC_ARM_PREL31:
2fc8bdac 18548 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
18549 {
18550 newval = md_chars_to_number (buf, 4) & 0x80000000;
18551 if ((value ^ (value >> 1)) & 0x40000000)
18552 {
18553 as_bad_where (fixP->fx_file, fixP->fx_line,
18554 _("rel31 relocation overflow"));
18555 }
18556 newval |= value & 0x7fffffff;
18557 md_number_to_chars (buf, newval, 4);
18558 }
18559 break;
c19d1205 18560#endif
a737bd4d 18561
c19d1205 18562 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 18563 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
18564 if (value < -1023 || value > 1023 || (value & 3))
18565 as_bad_where (fixP->fx_file, fixP->fx_line,
18566 _("co-processor offset out of range"));
18567 cp_off_common:
18568 sign = value >= 0;
18569 if (value < 0)
18570 value = -value;
8f06b2d8
PB
18571 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18572 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18573 newval = md_chars_to_number (buf, INSN_SIZE);
18574 else
18575 newval = get_thumb32_insn (buf);
18576 newval &= 0xff7fff00;
c19d1205 18577 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
18578 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18579 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18580 md_number_to_chars (buf, newval, INSN_SIZE);
18581 else
18582 put_thumb32_insn (buf, newval);
c19d1205 18583 break;
a737bd4d 18584
c19d1205 18585 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18586 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18587 if (value < -255 || value > 255)
18588 as_bad_where (fixP->fx_file, fixP->fx_line,
18589 _("co-processor offset out of range"));
df7849c5 18590 value *= 4;
c19d1205 18591 goto cp_off_common;
6c43fab6 18592
c19d1205
ZW
18593 case BFD_RELOC_ARM_THUMB_OFFSET:
18594 newval = md_chars_to_number (buf, THUMB_SIZE);
18595 /* Exactly what ranges, and where the offset is inserted depends
18596 on the type of instruction, we can establish this from the
18597 top 4 bits. */
18598 switch (newval >> 12)
18599 {
18600 case 4: /* PC load. */
18601 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18602 forced to zero for these loads; md_pcrel_from has already
18603 compensated for this. */
18604 if (value & 3)
18605 as_bad_where (fixP->fx_file, fixP->fx_line,
18606 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18607 (((unsigned long) fixP->fx_frag->fr_address
18608 + (unsigned long) fixP->fx_where) & ~3)
18609 + (unsigned long) value);
a737bd4d 18610
c19d1205
ZW
18611 if (value & ~0x3fc)
18612 as_bad_where (fixP->fx_file, fixP->fx_line,
18613 _("invalid offset, value too big (0x%08lX)"),
18614 (long) value);
a737bd4d 18615
c19d1205
ZW
18616 newval |= value >> 2;
18617 break;
a737bd4d 18618
c19d1205
ZW
18619 case 9: /* SP load/store. */
18620 if (value & ~0x3fc)
18621 as_bad_where (fixP->fx_file, fixP->fx_line,
18622 _("invalid offset, value too big (0x%08lX)"),
18623 (long) value);
18624 newval |= value >> 2;
18625 break;
6c43fab6 18626
c19d1205
ZW
18627 case 6: /* Word load/store. */
18628 if (value & ~0x7c)
18629 as_bad_where (fixP->fx_file, fixP->fx_line,
18630 _("invalid offset, value too big (0x%08lX)"),
18631 (long) value);
18632 newval |= value << 4; /* 6 - 2. */
18633 break;
a737bd4d 18634
c19d1205
ZW
18635 case 7: /* Byte load/store. */
18636 if (value & ~0x1f)
18637 as_bad_where (fixP->fx_file, fixP->fx_line,
18638 _("invalid offset, value too big (0x%08lX)"),
18639 (long) value);
18640 newval |= value << 6;
18641 break;
a737bd4d 18642
c19d1205
ZW
18643 case 8: /* Halfword load/store. */
18644 if (value & ~0x3e)
18645 as_bad_where (fixP->fx_file, fixP->fx_line,
18646 _("invalid offset, value too big (0x%08lX)"),
18647 (long) value);
18648 newval |= value << 5; /* 6 - 1. */
18649 break;
a737bd4d 18650
c19d1205
ZW
18651 default:
18652 as_bad_where (fixP->fx_file, fixP->fx_line,
18653 "Unable to process relocation for thumb opcode: %lx",
18654 (unsigned long) newval);
18655 break;
18656 }
18657 md_number_to_chars (buf, newval, THUMB_SIZE);
18658 break;
a737bd4d 18659
c19d1205
ZW
18660 case BFD_RELOC_ARM_THUMB_ADD:
18661 /* This is a complicated relocation, since we use it for all of
18662 the following immediate relocations:
a737bd4d 18663
c19d1205
ZW
18664 3bit ADD/SUB
18665 8bit ADD/SUB
18666 9bit ADD/SUB SP word-aligned
18667 10bit ADD PC/SP word-aligned
a737bd4d 18668
c19d1205
ZW
18669 The type of instruction being processed is encoded in the
18670 instruction field:
a737bd4d 18671
c19d1205
ZW
18672 0x8000 SUB
18673 0x00F0 Rd
18674 0x000F Rs
18675 */
18676 newval = md_chars_to_number (buf, THUMB_SIZE);
18677 {
18678 int rd = (newval >> 4) & 0xf;
18679 int rs = newval & 0xf;
18680 int subtract = !!(newval & 0x8000);
a737bd4d 18681
c19d1205
ZW
18682 /* Check for HI regs, only very restricted cases allowed:
18683 Adjusting SP, and using PC or SP to get an address. */
18684 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18685 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18686 as_bad_where (fixP->fx_file, fixP->fx_line,
18687 _("invalid Hi register with immediate"));
a737bd4d 18688
c19d1205
ZW
18689 /* If value is negative, choose the opposite instruction. */
18690 if (value < 0)
18691 {
18692 value = -value;
18693 subtract = !subtract;
18694 if (value < 0)
18695 as_bad_where (fixP->fx_file, fixP->fx_line,
18696 _("immediate value out of range"));
18697 }
a737bd4d 18698
c19d1205
ZW
18699 if (rd == REG_SP)
18700 {
18701 if (value & ~0x1fc)
18702 as_bad_where (fixP->fx_file, fixP->fx_line,
18703 _("invalid immediate for stack address calculation"));
18704 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18705 newval |= value >> 2;
18706 }
18707 else if (rs == REG_PC || rs == REG_SP)
18708 {
18709 if (subtract || value & ~0x3fc)
18710 as_bad_where (fixP->fx_file, fixP->fx_line,
18711 _("invalid immediate for address calculation (value = 0x%08lX)"),
18712 (unsigned long) value);
18713 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18714 newval |= rd << 8;
18715 newval |= value >> 2;
18716 }
18717 else if (rs == rd)
18718 {
18719 if (value & ~0xff)
18720 as_bad_where (fixP->fx_file, fixP->fx_line,
18721 _("immediate value out of range"));
18722 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18723 newval |= (rd << 8) | value;
18724 }
18725 else
18726 {
18727 if (value & ~0x7)
18728 as_bad_where (fixP->fx_file, fixP->fx_line,
18729 _("immediate value out of range"));
18730 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18731 newval |= rd | (rs << 3) | (value << 6);
18732 }
18733 }
18734 md_number_to_chars (buf, newval, THUMB_SIZE);
18735 break;
a737bd4d 18736
c19d1205
ZW
18737 case BFD_RELOC_ARM_THUMB_IMM:
18738 newval = md_chars_to_number (buf, THUMB_SIZE);
18739 if (value < 0 || value > 255)
18740 as_bad_where (fixP->fx_file, fixP->fx_line,
18741 _("invalid immediate: %ld is too large"),
18742 (long) value);
18743 newval |= value;
18744 md_number_to_chars (buf, newval, THUMB_SIZE);
18745 break;
a737bd4d 18746
c19d1205
ZW
18747 case BFD_RELOC_ARM_THUMB_SHIFT:
18748 /* 5bit shift value (0..32). LSL cannot take 32. */
18749 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18750 temp = newval & 0xf800;
18751 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18752 as_bad_where (fixP->fx_file, fixP->fx_line,
18753 _("invalid shift value: %ld"), (long) value);
18754 /* Shifts of zero must be encoded as LSL. */
18755 if (value == 0)
18756 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18757 /* Shifts of 32 are encoded as zero. */
18758 else if (value == 32)
18759 value = 0;
18760 newval |= value << 6;
18761 md_number_to_chars (buf, newval, THUMB_SIZE);
18762 break;
a737bd4d 18763
c19d1205
ZW
18764 case BFD_RELOC_VTABLE_INHERIT:
18765 case BFD_RELOC_VTABLE_ENTRY:
18766 fixP->fx_done = 0;
18767 return;
6c43fab6 18768
b6895b4f
PB
18769 case BFD_RELOC_ARM_MOVW:
18770 case BFD_RELOC_ARM_MOVT:
18771 case BFD_RELOC_ARM_THUMB_MOVW:
18772 case BFD_RELOC_ARM_THUMB_MOVT:
18773 if (fixP->fx_done || !seg->use_rela_p)
18774 {
18775 /* REL format relocations are limited to a 16-bit addend. */
18776 if (!fixP->fx_done)
18777 {
18778 if (value < -0x1000 || value > 0xffff)
18779 as_bad_where (fixP->fx_file, fixP->fx_line,
18780 _("offset too big"));
18781 }
18782 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18783 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18784 {
18785 value >>= 16;
18786 }
18787
18788 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18789 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18790 {
18791 newval = get_thumb32_insn (buf);
18792 newval &= 0xfbf08f00;
18793 newval |= (value & 0xf000) << 4;
18794 newval |= (value & 0x0800) << 15;
18795 newval |= (value & 0x0700) << 4;
18796 newval |= (value & 0x00ff);
18797 put_thumb32_insn (buf, newval);
18798 }
18799 else
18800 {
18801 newval = md_chars_to_number (buf, 4);
18802 newval &= 0xfff0f000;
18803 newval |= value & 0x0fff;
18804 newval |= (value & 0xf000) << 4;
18805 md_number_to_chars (buf, newval, 4);
18806 }
18807 }
18808 return;
18809
4962c51a
MS
18810 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18811 case BFD_RELOC_ARM_ALU_PC_G0:
18812 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18813 case BFD_RELOC_ARM_ALU_PC_G1:
18814 case BFD_RELOC_ARM_ALU_PC_G2:
18815 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18816 case BFD_RELOC_ARM_ALU_SB_G0:
18817 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18818 case BFD_RELOC_ARM_ALU_SB_G1:
18819 case BFD_RELOC_ARM_ALU_SB_G2:
18820 assert (!fixP->fx_done);
18821 if (!seg->use_rela_p)
18822 {
18823 bfd_vma insn;
18824 bfd_vma encoded_addend;
18825 bfd_vma addend_abs = abs (value);
18826
18827 /* Check that the absolute value of the addend can be
18828 expressed as an 8-bit constant plus a rotation. */
18829 encoded_addend = encode_arm_immediate (addend_abs);
18830 if (encoded_addend == (unsigned int) FAIL)
18831 as_bad_where (fixP->fx_file, fixP->fx_line,
18832 _("the offset 0x%08lX is not representable"),
18833 addend_abs);
18834
18835 /* Extract the instruction. */
18836 insn = md_chars_to_number (buf, INSN_SIZE);
18837
18838 /* If the addend is positive, use an ADD instruction.
18839 Otherwise use a SUB. Take care not to destroy the S bit. */
18840 insn &= 0xff1fffff;
18841 if (value < 0)
18842 insn |= 1 << 22;
18843 else
18844 insn |= 1 << 23;
18845
18846 /* Place the encoded addend into the first 12 bits of the
18847 instruction. */
18848 insn &= 0xfffff000;
18849 insn |= encoded_addend;
18850
18851 /* Update the instruction. */
18852 md_number_to_chars (buf, insn, INSN_SIZE);
18853 }
18854 break;
18855
18856 case BFD_RELOC_ARM_LDR_PC_G0:
18857 case BFD_RELOC_ARM_LDR_PC_G1:
18858 case BFD_RELOC_ARM_LDR_PC_G2:
18859 case BFD_RELOC_ARM_LDR_SB_G0:
18860 case BFD_RELOC_ARM_LDR_SB_G1:
18861 case BFD_RELOC_ARM_LDR_SB_G2:
18862 assert (!fixP->fx_done);
18863 if (!seg->use_rela_p)
18864 {
18865 bfd_vma insn;
18866 bfd_vma addend_abs = abs (value);
18867
18868 /* Check that the absolute value of the addend can be
18869 encoded in 12 bits. */
18870 if (addend_abs >= 0x1000)
18871 as_bad_where (fixP->fx_file, fixP->fx_line,
18872 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18873 addend_abs);
18874
18875 /* Extract the instruction. */
18876 insn = md_chars_to_number (buf, INSN_SIZE);
18877
18878 /* If the addend is negative, clear bit 23 of the instruction.
18879 Otherwise set it. */
18880 if (value < 0)
18881 insn &= ~(1 << 23);
18882 else
18883 insn |= 1 << 23;
18884
18885 /* Place the absolute value of the addend into the first 12 bits
18886 of the instruction. */
18887 insn &= 0xfffff000;
18888 insn |= addend_abs;
18889
18890 /* Update the instruction. */
18891 md_number_to_chars (buf, insn, INSN_SIZE);
18892 }
18893 break;
18894
18895 case BFD_RELOC_ARM_LDRS_PC_G0:
18896 case BFD_RELOC_ARM_LDRS_PC_G1:
18897 case BFD_RELOC_ARM_LDRS_PC_G2:
18898 case BFD_RELOC_ARM_LDRS_SB_G0:
18899 case BFD_RELOC_ARM_LDRS_SB_G1:
18900 case BFD_RELOC_ARM_LDRS_SB_G2:
18901 assert (!fixP->fx_done);
18902 if (!seg->use_rela_p)
18903 {
18904 bfd_vma insn;
18905 bfd_vma addend_abs = abs (value);
18906
18907 /* Check that the absolute value of the addend can be
18908 encoded in 8 bits. */
18909 if (addend_abs >= 0x100)
18910 as_bad_where (fixP->fx_file, fixP->fx_line,
18911 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18912 addend_abs);
18913
18914 /* Extract the instruction. */
18915 insn = md_chars_to_number (buf, INSN_SIZE);
18916
18917 /* If the addend is negative, clear bit 23 of the instruction.
18918 Otherwise set it. */
18919 if (value < 0)
18920 insn &= ~(1 << 23);
18921 else
18922 insn |= 1 << 23;
18923
18924 /* Place the first four bits of the absolute value of the addend
18925 into the first 4 bits of the instruction, and the remaining
18926 four into bits 8 .. 11. */
18927 insn &= 0xfffff0f0;
18928 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18929
18930 /* Update the instruction. */
18931 md_number_to_chars (buf, insn, INSN_SIZE);
18932 }
18933 break;
18934
18935 case BFD_RELOC_ARM_LDC_PC_G0:
18936 case BFD_RELOC_ARM_LDC_PC_G1:
18937 case BFD_RELOC_ARM_LDC_PC_G2:
18938 case BFD_RELOC_ARM_LDC_SB_G0:
18939 case BFD_RELOC_ARM_LDC_SB_G1:
18940 case BFD_RELOC_ARM_LDC_SB_G2:
18941 assert (!fixP->fx_done);
18942 if (!seg->use_rela_p)
18943 {
18944 bfd_vma insn;
18945 bfd_vma addend_abs = abs (value);
18946
18947 /* Check that the absolute value of the addend is a multiple of
18948 four and, when divided by four, fits in 8 bits. */
18949 if (addend_abs & 0x3)
18950 as_bad_where (fixP->fx_file, fixP->fx_line,
18951 _("bad offset 0x%08lX (must be word-aligned)"),
18952 addend_abs);
18953
18954 if ((addend_abs >> 2) > 0xff)
18955 as_bad_where (fixP->fx_file, fixP->fx_line,
18956 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18957 addend_abs);
18958
18959 /* Extract the instruction. */
18960 insn = md_chars_to_number (buf, INSN_SIZE);
18961
18962 /* If the addend is negative, clear bit 23 of the instruction.
18963 Otherwise set it. */
18964 if (value < 0)
18965 insn &= ~(1 << 23);
18966 else
18967 insn |= 1 << 23;
18968
18969 /* Place the addend (divided by four) into the first eight
18970 bits of the instruction. */
18971 insn &= 0xfffffff0;
18972 insn |= addend_abs >> 2;
18973
18974 /* Update the instruction. */
18975 md_number_to_chars (buf, insn, INSN_SIZE);
18976 }
18977 break;
18978
c19d1205
ZW
18979 case BFD_RELOC_UNUSED:
18980 default:
18981 as_bad_where (fixP->fx_file, fixP->fx_line,
18982 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18983 }
6c43fab6
RE
18984}
18985
c19d1205
ZW
18986/* Translate internal representation of relocation info to BFD target
18987 format. */
a737bd4d 18988
c19d1205 18989arelent *
00a97672 18990tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 18991{
c19d1205
ZW
18992 arelent * reloc;
18993 bfd_reloc_code_real_type code;
a737bd4d 18994
c19d1205 18995 reloc = xmalloc (sizeof (arelent));
a737bd4d 18996
c19d1205
ZW
18997 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18998 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18999 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 19000
2fc8bdac 19001 if (fixp->fx_pcrel)
00a97672
RS
19002 {
19003 if (section->use_rela_p)
19004 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
19005 else
19006 fixp->fx_offset = reloc->address;
19007 }
c19d1205 19008 reloc->addend = fixp->fx_offset;
a737bd4d 19009
c19d1205 19010 switch (fixp->fx_r_type)
a737bd4d 19011 {
c19d1205
ZW
19012 case BFD_RELOC_8:
19013 if (fixp->fx_pcrel)
19014 {
19015 code = BFD_RELOC_8_PCREL;
19016 break;
19017 }
a737bd4d 19018
c19d1205
ZW
19019 case BFD_RELOC_16:
19020 if (fixp->fx_pcrel)
19021 {
19022 code = BFD_RELOC_16_PCREL;
19023 break;
19024 }
6c43fab6 19025
c19d1205
ZW
19026 case BFD_RELOC_32:
19027 if (fixp->fx_pcrel)
19028 {
19029 code = BFD_RELOC_32_PCREL;
19030 break;
19031 }
a737bd4d 19032
b6895b4f
PB
19033 case BFD_RELOC_ARM_MOVW:
19034 if (fixp->fx_pcrel)
19035 {
19036 code = BFD_RELOC_ARM_MOVW_PCREL;
19037 break;
19038 }
19039
19040 case BFD_RELOC_ARM_MOVT:
19041 if (fixp->fx_pcrel)
19042 {
19043 code = BFD_RELOC_ARM_MOVT_PCREL;
19044 break;
19045 }
19046
19047 case BFD_RELOC_ARM_THUMB_MOVW:
19048 if (fixp->fx_pcrel)
19049 {
19050 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
19051 break;
19052 }
19053
19054 case BFD_RELOC_ARM_THUMB_MOVT:
19055 if (fixp->fx_pcrel)
19056 {
19057 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
19058 break;
19059 }
19060
c19d1205
ZW
19061 case BFD_RELOC_NONE:
19062 case BFD_RELOC_ARM_PCREL_BRANCH:
19063 case BFD_RELOC_ARM_PCREL_BLX:
19064 case BFD_RELOC_RVA:
19065 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19066 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19067 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19068 case BFD_RELOC_THUMB_PCREL_BRANCH20:
19069 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19070 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19071 case BFD_RELOC_THUMB_PCREL_BLX:
19072 case BFD_RELOC_VTABLE_ENTRY:
19073 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
19074#ifdef TE_PE
19075 case BFD_RELOC_32_SECREL:
19076#endif
c19d1205
ZW
19077 code = fixp->fx_r_type;
19078 break;
a737bd4d 19079
c19d1205
ZW
19080 case BFD_RELOC_ARM_LITERAL:
19081 case BFD_RELOC_ARM_HWLITERAL:
19082 /* If this is called then the a literal has
19083 been referenced across a section boundary. */
19084 as_bad_where (fixp->fx_file, fixp->fx_line,
19085 _("literal referenced across section boundary"));
19086 return NULL;
a737bd4d 19087
c19d1205
ZW
19088#ifdef OBJ_ELF
19089 case BFD_RELOC_ARM_GOT32:
19090 case BFD_RELOC_ARM_GOTOFF:
19091 case BFD_RELOC_ARM_PLT32:
19092 case BFD_RELOC_ARM_TARGET1:
19093 case BFD_RELOC_ARM_ROSEGREL32:
19094 case BFD_RELOC_ARM_SBREL32:
19095 case BFD_RELOC_ARM_PREL31:
19096 case BFD_RELOC_ARM_TARGET2:
19097 case BFD_RELOC_ARM_TLS_LE32:
19098 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
19099 case BFD_RELOC_ARM_PCREL_CALL:
19100 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
19101 case BFD_RELOC_ARM_ALU_PC_G0_NC:
19102 case BFD_RELOC_ARM_ALU_PC_G0:
19103 case BFD_RELOC_ARM_ALU_PC_G1_NC:
19104 case BFD_RELOC_ARM_ALU_PC_G1:
19105 case BFD_RELOC_ARM_ALU_PC_G2:
19106 case BFD_RELOC_ARM_LDR_PC_G0:
19107 case BFD_RELOC_ARM_LDR_PC_G1:
19108 case BFD_RELOC_ARM_LDR_PC_G2:
19109 case BFD_RELOC_ARM_LDRS_PC_G0:
19110 case BFD_RELOC_ARM_LDRS_PC_G1:
19111 case BFD_RELOC_ARM_LDRS_PC_G2:
19112 case BFD_RELOC_ARM_LDC_PC_G0:
19113 case BFD_RELOC_ARM_LDC_PC_G1:
19114 case BFD_RELOC_ARM_LDC_PC_G2:
19115 case BFD_RELOC_ARM_ALU_SB_G0_NC:
19116 case BFD_RELOC_ARM_ALU_SB_G0:
19117 case BFD_RELOC_ARM_ALU_SB_G1_NC:
19118 case BFD_RELOC_ARM_ALU_SB_G1:
19119 case BFD_RELOC_ARM_ALU_SB_G2:
19120 case BFD_RELOC_ARM_LDR_SB_G0:
19121 case BFD_RELOC_ARM_LDR_SB_G1:
19122 case BFD_RELOC_ARM_LDR_SB_G2:
19123 case BFD_RELOC_ARM_LDRS_SB_G0:
19124 case BFD_RELOC_ARM_LDRS_SB_G1:
19125 case BFD_RELOC_ARM_LDRS_SB_G2:
19126 case BFD_RELOC_ARM_LDC_SB_G0:
19127 case BFD_RELOC_ARM_LDC_SB_G1:
19128 case BFD_RELOC_ARM_LDC_SB_G2:
c19d1205
ZW
19129 code = fixp->fx_r_type;
19130 break;
a737bd4d 19131
c19d1205
ZW
19132 case BFD_RELOC_ARM_TLS_GD32:
19133 case BFD_RELOC_ARM_TLS_IE32:
19134 case BFD_RELOC_ARM_TLS_LDM32:
19135 /* BFD will include the symbol's address in the addend.
19136 But we don't want that, so subtract it out again here. */
19137 if (!S_IS_COMMON (fixp->fx_addsy))
19138 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
19139 code = fixp->fx_r_type;
19140 break;
19141#endif
a737bd4d 19142
c19d1205
ZW
19143 case BFD_RELOC_ARM_IMMEDIATE:
19144 as_bad_where (fixp->fx_file, fixp->fx_line,
19145 _("internal relocation (type: IMMEDIATE) not fixed up"));
19146 return NULL;
a737bd4d 19147
c19d1205
ZW
19148 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19149 as_bad_where (fixp->fx_file, fixp->fx_line,
19150 _("ADRL used for a symbol not defined in the same file"));
19151 return NULL;
a737bd4d 19152
c19d1205 19153 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19154 if (section->use_rela_p)
19155 {
19156 code = fixp->fx_r_type;
19157 break;
19158 }
19159
c19d1205
ZW
19160 if (fixp->fx_addsy != NULL
19161 && !S_IS_DEFINED (fixp->fx_addsy)
19162 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 19163 {
c19d1205
ZW
19164 as_bad_where (fixp->fx_file, fixp->fx_line,
19165 _("undefined local label `%s'"),
19166 S_GET_NAME (fixp->fx_addsy));
19167 return NULL;
a737bd4d
NC
19168 }
19169
c19d1205
ZW
19170 as_bad_where (fixp->fx_file, fixp->fx_line,
19171 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
19172 return NULL;
a737bd4d 19173
c19d1205
ZW
19174 default:
19175 {
19176 char * type;
6c43fab6 19177
c19d1205
ZW
19178 switch (fixp->fx_r_type)
19179 {
19180 case BFD_RELOC_NONE: type = "NONE"; break;
19181 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
19182 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 19183 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
19184 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
19185 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
19186 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 19187 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
19188 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
19189 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
19190 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
19191 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
19192 default: type = _("<unknown>"); break;
19193 }
19194 as_bad_where (fixp->fx_file, fixp->fx_line,
19195 _("cannot represent %s relocation in this object file format"),
19196 type);
19197 return NULL;
19198 }
a737bd4d 19199 }
6c43fab6 19200
c19d1205
ZW
19201#ifdef OBJ_ELF
19202 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
19203 && GOT_symbol
19204 && fixp->fx_addsy == GOT_symbol)
19205 {
19206 code = BFD_RELOC_ARM_GOTPC;
19207 reloc->addend = fixp->fx_offset = reloc->address;
19208 }
19209#endif
6c43fab6 19210
c19d1205 19211 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 19212
c19d1205
ZW
19213 if (reloc->howto == NULL)
19214 {
19215 as_bad_where (fixp->fx_file, fixp->fx_line,
19216 _("cannot represent %s relocation in this object file format"),
19217 bfd_get_reloc_code_name (code));
19218 return NULL;
19219 }
6c43fab6 19220
c19d1205
ZW
19221 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
19222 vtable entry to be used in the relocation's section offset. */
19223 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19224 reloc->address = fixp->fx_offset;
6c43fab6 19225
c19d1205 19226 return reloc;
6c43fab6
RE
19227}
19228
c19d1205 19229/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 19230
c19d1205
ZW
19231void
19232cons_fix_new_arm (fragS * frag,
19233 int where,
19234 int size,
19235 expressionS * exp)
6c43fab6 19236{
c19d1205
ZW
19237 bfd_reloc_code_real_type type;
19238 int pcrel = 0;
6c43fab6 19239
c19d1205
ZW
19240 /* Pick a reloc.
19241 FIXME: @@ Should look at CPU word size. */
19242 switch (size)
19243 {
19244 case 1:
19245 type = BFD_RELOC_8;
19246 break;
19247 case 2:
19248 type = BFD_RELOC_16;
19249 break;
19250 case 4:
19251 default:
19252 type = BFD_RELOC_32;
19253 break;
19254 case 8:
19255 type = BFD_RELOC_64;
19256 break;
19257 }
6c43fab6 19258
f0927246
NC
19259#ifdef TE_PE
19260 if (exp->X_op == O_secrel)
19261 {
19262 exp->X_op = O_symbol;
19263 type = BFD_RELOC_32_SECREL;
19264 }
19265#endif
19266
c19d1205
ZW
19267 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
19268}
6c43fab6 19269
c19d1205
ZW
19270#if defined OBJ_COFF || defined OBJ_ELF
19271void
19272arm_validate_fix (fixS * fixP)
6c43fab6 19273{
c19d1205
ZW
19274 /* If the destination of the branch is a defined symbol which does not have
19275 the THUMB_FUNC attribute, then we must be calling a function which has
19276 the (interfacearm) attribute. We look for the Thumb entry point to that
19277 function and change the branch to refer to that function instead. */
19278 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
19279 && fixP->fx_addsy != NULL
19280 && S_IS_DEFINED (fixP->fx_addsy)
19281 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 19282 {
c19d1205 19283 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 19284 }
c19d1205
ZW
19285}
19286#endif
6c43fab6 19287
c19d1205
ZW
19288int
19289arm_force_relocation (struct fix * fixp)
19290{
19291#if defined (OBJ_COFF) && defined (TE_PE)
19292 if (fixp->fx_r_type == BFD_RELOC_RVA)
19293 return 1;
19294#endif
6c43fab6 19295
c19d1205
ZW
19296 /* Resolve these relocations even if the symbol is extern or weak. */
19297 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
19298 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 19299 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 19300 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
19301 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19302 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
19303 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 19304 return 0;
a737bd4d 19305
4962c51a
MS
19306 /* Always leave these relocations for the linker. */
19307 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19308 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19309 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19310 return 1;
19311
f0291e4c
PB
19312 /* Always generate relocations against function symbols. */
19313 if (fixp->fx_r_type == BFD_RELOC_32
19314 && fixp->fx_addsy
19315 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
19316 return 1;
19317
c19d1205 19318 return generic_force_reloc (fixp);
404ff6b5
AH
19319}
19320
0ffdc86c 19321#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
19322/* Relocations against function names must be left unadjusted,
19323 so that the linker can use this information to generate interworking
19324 stubs. The MIPS version of this function
c19d1205
ZW
19325 also prevents relocations that are mips-16 specific, but I do not
19326 know why it does this.
404ff6b5 19327
c19d1205
ZW
19328 FIXME:
19329 There is one other problem that ought to be addressed here, but
19330 which currently is not: Taking the address of a label (rather
19331 than a function) and then later jumping to that address. Such
19332 addresses also ought to have their bottom bit set (assuming that
19333 they reside in Thumb code), but at the moment they will not. */
404ff6b5 19334
c19d1205
ZW
19335bfd_boolean
19336arm_fix_adjustable (fixS * fixP)
404ff6b5 19337{
c19d1205
ZW
19338 if (fixP->fx_addsy == NULL)
19339 return 1;
404ff6b5 19340
e28387c3
PB
19341 /* Preserve relocations against symbols with function type. */
19342 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
19343 return 0;
19344
c19d1205
ZW
19345 if (THUMB_IS_FUNC (fixP->fx_addsy)
19346 && fixP->fx_subsy == NULL)
19347 return 0;
a737bd4d 19348
c19d1205
ZW
19349 /* We need the symbol name for the VTABLE entries. */
19350 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
19351 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
19352 return 0;
404ff6b5 19353
c19d1205
ZW
19354 /* Don't allow symbols to be discarded on GOT related relocs. */
19355 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
19356 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
19357 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
19358 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
19359 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
19360 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
19361 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
19362 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
19363 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
19364 return 0;
a737bd4d 19365
4962c51a
MS
19366 /* Similarly for group relocations. */
19367 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
19368 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
19369 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
19370 return 0;
19371
c19d1205 19372 return 1;
a737bd4d 19373}
0ffdc86c
NC
19374#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
19375
19376#ifdef OBJ_ELF
404ff6b5 19377
c19d1205
ZW
19378const char *
19379elf32_arm_target_format (void)
404ff6b5 19380{
c19d1205
ZW
19381#ifdef TE_SYMBIAN
19382 return (target_big_endian
19383 ? "elf32-bigarm-symbian"
19384 : "elf32-littlearm-symbian");
19385#elif defined (TE_VXWORKS)
19386 return (target_big_endian
19387 ? "elf32-bigarm-vxworks"
19388 : "elf32-littlearm-vxworks");
19389#else
19390 if (target_big_endian)
19391 return "elf32-bigarm";
19392 else
19393 return "elf32-littlearm";
19394#endif
404ff6b5
AH
19395}
19396
c19d1205
ZW
19397void
19398armelf_frob_symbol (symbolS * symp,
19399 int * puntp)
404ff6b5 19400{
c19d1205
ZW
19401 elf_frob_symbol (symp, puntp);
19402}
19403#endif
404ff6b5 19404
c19d1205 19405/* MD interface: Finalization. */
a737bd4d 19406
c19d1205
ZW
19407/* A good place to do this, although this was probably not intended
19408 for this kind of use. We need to dump the literal pool before
19409 references are made to a null symbol pointer. */
a737bd4d 19410
c19d1205
ZW
19411void
19412arm_cleanup (void)
19413{
19414 literal_pool * pool;
a737bd4d 19415
c19d1205
ZW
19416 for (pool = list_of_pools; pool; pool = pool->next)
19417 {
19418 /* Put it at the end of the relevent section. */
19419 subseg_set (pool->section, pool->sub_section);
19420#ifdef OBJ_ELF
19421 arm_elf_change_section ();
19422#endif
19423 s_ltorg (0);
19424 }
404ff6b5
AH
19425}
19426
c19d1205
ZW
19427/* Adjust the symbol table. This marks Thumb symbols as distinct from
19428 ARM ones. */
404ff6b5 19429
c19d1205
ZW
19430void
19431arm_adjust_symtab (void)
404ff6b5 19432{
c19d1205
ZW
19433#ifdef OBJ_COFF
19434 symbolS * sym;
404ff6b5 19435
c19d1205
ZW
19436 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
19437 {
19438 if (ARM_IS_THUMB (sym))
19439 {
19440 if (THUMB_IS_FUNC (sym))
19441 {
19442 /* Mark the symbol as a Thumb function. */
19443 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
19444 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
19445 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 19446
c19d1205
ZW
19447 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
19448 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
19449 else
19450 as_bad (_("%s: unexpected function type: %d"),
19451 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
19452 }
19453 else switch (S_GET_STORAGE_CLASS (sym))
19454 {
19455 case C_EXT:
19456 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
19457 break;
19458 case C_STAT:
19459 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
19460 break;
19461 case C_LABEL:
19462 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
19463 break;
19464 default:
19465 /* Do nothing. */
19466 break;
19467 }
19468 }
a737bd4d 19469
c19d1205
ZW
19470 if (ARM_IS_INTERWORK (sym))
19471 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 19472 }
c19d1205
ZW
19473#endif
19474#ifdef OBJ_ELF
19475 symbolS * sym;
19476 char bind;
404ff6b5 19477
c19d1205 19478 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 19479 {
c19d1205
ZW
19480 if (ARM_IS_THUMB (sym))
19481 {
19482 elf_symbol_type * elf_sym;
404ff6b5 19483
c19d1205
ZW
19484 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
19485 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 19486
b0796911
PB
19487 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
19488 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
19489 {
19490 /* If it's a .thumb_func, declare it as so,
19491 otherwise tag label as .code 16. */
19492 if (THUMB_IS_FUNC (sym))
19493 elf_sym->internal_elf_sym.st_info =
19494 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 19495 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
19496 elf_sym->internal_elf_sym.st_info =
19497 ELF_ST_INFO (bind, STT_ARM_16BIT);
19498 }
19499 }
19500 }
19501#endif
404ff6b5
AH
19502}
19503
c19d1205 19504/* MD interface: Initialization. */
404ff6b5 19505
a737bd4d 19506static void
c19d1205 19507set_constant_flonums (void)
a737bd4d 19508{
c19d1205 19509 int i;
404ff6b5 19510
c19d1205
ZW
19511 for (i = 0; i < NUM_FLOAT_VALS; i++)
19512 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
19513 abort ();
a737bd4d 19514}
404ff6b5 19515
3e9e4fcf
JB
19516/* Auto-select Thumb mode if it's the only available instruction set for the
19517 given architecture. */
19518
19519static void
19520autoselect_thumb_from_cpu_variant (void)
19521{
19522 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
19523 opcode_select (16);
19524}
19525
c19d1205
ZW
19526void
19527md_begin (void)
a737bd4d 19528{
c19d1205
ZW
19529 unsigned mach;
19530 unsigned int i;
404ff6b5 19531
c19d1205
ZW
19532 if ( (arm_ops_hsh = hash_new ()) == NULL
19533 || (arm_cond_hsh = hash_new ()) == NULL
19534 || (arm_shift_hsh = hash_new ()) == NULL
19535 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 19536 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 19537 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
19538 || (arm_reloc_hsh = hash_new ()) == NULL
19539 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
19540 as_fatal (_("virtual memory exhausted"));
19541
19542 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
19543 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
19544 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
19545 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
19546 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
19547 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
19548 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
19549 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19550 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19551 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19552 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19553 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19554 for (i = 0;
19555 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19556 i++)
19557 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19558 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19559#ifdef OBJ_ELF
19560 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19561 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19562#endif
19563
19564 set_constant_flonums ();
404ff6b5 19565
c19d1205
ZW
19566 /* Set the cpu variant based on the command-line options. We prefer
19567 -mcpu= over -march= if both are set (as for GCC); and we prefer
19568 -mfpu= over any other way of setting the floating point unit.
19569 Use of legacy options with new options are faulted. */
e74cfd16 19570 if (legacy_cpu)
404ff6b5 19571 {
e74cfd16 19572 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19573 as_bad (_("use of old and new-style options to set CPU type"));
19574
19575 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19576 }
e74cfd16 19577 else if (!mcpu_cpu_opt)
c19d1205 19578 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19579
e74cfd16 19580 if (legacy_fpu)
c19d1205 19581 {
e74cfd16 19582 if (mfpu_opt)
c19d1205 19583 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19584
19585 mfpu_opt = legacy_fpu;
19586 }
e74cfd16 19587 else if (!mfpu_opt)
03b1477f 19588 {
c19d1205 19589#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19590 /* Some environments specify a default FPU. If they don't, infer it
19591 from the processor. */
e74cfd16 19592 if (mcpu_fpu_opt)
03b1477f
RE
19593 mfpu_opt = mcpu_fpu_opt;
19594 else
19595 mfpu_opt = march_fpu_opt;
39c2da32 19596#else
e74cfd16 19597 mfpu_opt = &fpu_default;
39c2da32 19598#endif
03b1477f
RE
19599 }
19600
e74cfd16 19601 if (!mfpu_opt)
03b1477f 19602 {
493cb6ef 19603 if (mcpu_cpu_opt != NULL)
e74cfd16 19604 mfpu_opt = &fpu_default;
493cb6ef 19605 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 19606 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19607 else
e74cfd16 19608 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19609 }
19610
ee065d83 19611#ifdef CPU_DEFAULT
e74cfd16 19612 if (!mcpu_cpu_opt)
ee065d83 19613 {
e74cfd16
PB
19614 mcpu_cpu_opt = &cpu_default;
19615 selected_cpu = cpu_default;
ee065d83 19616 }
e74cfd16
PB
19617#else
19618 if (mcpu_cpu_opt)
19619 selected_cpu = *mcpu_cpu_opt;
ee065d83 19620 else
e74cfd16 19621 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19622#endif
03b1477f 19623
e74cfd16 19624 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19625
3e9e4fcf
JB
19626 autoselect_thumb_from_cpu_variant ();
19627
e74cfd16 19628 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19629
f17c130b 19630#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19631 {
7cc69913
NC
19632 unsigned int flags = 0;
19633
19634#if defined OBJ_ELF
19635 flags = meabi_flags;
d507cf36
PB
19636
19637 switch (meabi_flags)
33a392fb 19638 {
d507cf36 19639 case EF_ARM_EABI_UNKNOWN:
7cc69913 19640#endif
d507cf36
PB
19641 /* Set the flags in the private structure. */
19642 if (uses_apcs_26) flags |= F_APCS26;
19643 if (support_interwork) flags |= F_INTERWORK;
19644 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19645 if (pic_code) flags |= F_PIC;
e74cfd16 19646 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19647 flags |= F_SOFT_FLOAT;
19648
d507cf36
PB
19649 switch (mfloat_abi_opt)
19650 {
19651 case ARM_FLOAT_ABI_SOFT:
19652 case ARM_FLOAT_ABI_SOFTFP:
19653 flags |= F_SOFT_FLOAT;
19654 break;
33a392fb 19655
d507cf36
PB
19656 case ARM_FLOAT_ABI_HARD:
19657 if (flags & F_SOFT_FLOAT)
19658 as_bad (_("hard-float conflicts with specified fpu"));
19659 break;
19660 }
03b1477f 19661
e74cfd16
PB
19662 /* Using pure-endian doubles (even if soft-float). */
19663 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19664 flags |= F_VFP_FLOAT;
f17c130b 19665
fde78edd 19666#if defined OBJ_ELF
e74cfd16 19667 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19668 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19669 break;
19670
8cb51566 19671 case EF_ARM_EABI_VER4:
3a4a14e9 19672 case EF_ARM_EABI_VER5:
c19d1205 19673 /* No additional flags to set. */
d507cf36
PB
19674 break;
19675
19676 default:
19677 abort ();
19678 }
7cc69913 19679#endif
b99bd4ef
NC
19680 bfd_set_private_flags (stdoutput, flags);
19681
19682 /* We have run out flags in the COFF header to encode the
19683 status of ATPCS support, so instead we create a dummy,
c19d1205 19684 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19685 if (atpcs)
19686 {
19687 asection * sec;
19688
19689 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19690
19691 if (sec != NULL)
19692 {
19693 bfd_set_section_flags
19694 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19695 bfd_set_section_size (stdoutput, sec, 0);
19696 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19697 }
19698 }
7cc69913 19699 }
f17c130b 19700#endif
b99bd4ef
NC
19701
19702 /* Record the CPU type as well. */
2d447fca
JM
19703 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
19704 mach = bfd_mach_arm_iWMMXt2;
19705 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19706 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19707 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19708 mach = bfd_mach_arm_XScale;
e74cfd16 19709 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19710 mach = bfd_mach_arm_ep9312;
e74cfd16 19711 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19712 mach = bfd_mach_arm_5TE;
e74cfd16 19713 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19714 {
e74cfd16 19715 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19716 mach = bfd_mach_arm_5T;
19717 else
19718 mach = bfd_mach_arm_5;
19719 }
e74cfd16 19720 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19721 {
e74cfd16 19722 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19723 mach = bfd_mach_arm_4T;
19724 else
19725 mach = bfd_mach_arm_4;
19726 }
e74cfd16 19727 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19728 mach = bfd_mach_arm_3M;
e74cfd16
PB
19729 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19730 mach = bfd_mach_arm_3;
19731 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19732 mach = bfd_mach_arm_2a;
19733 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19734 mach = bfd_mach_arm_2;
19735 else
19736 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19737
19738 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19739}
19740
c19d1205 19741/* Command line processing. */
b99bd4ef 19742
c19d1205
ZW
19743/* md_parse_option
19744 Invocation line includes a switch not recognized by the base assembler.
19745 See if it's a processor-specific option.
b99bd4ef 19746
c19d1205
ZW
19747 This routine is somewhat complicated by the need for backwards
19748 compatibility (since older releases of gcc can't be changed).
19749 The new options try to make the interface as compatible as
19750 possible with GCC.
b99bd4ef 19751
c19d1205 19752 New options (supported) are:
b99bd4ef 19753
c19d1205
ZW
19754 -mcpu=<cpu name> Assemble for selected processor
19755 -march=<architecture name> Assemble for selected architecture
19756 -mfpu=<fpu architecture> Assemble for selected FPU.
19757 -EB/-mbig-endian Big-endian
19758 -EL/-mlittle-endian Little-endian
19759 -k Generate PIC code
19760 -mthumb Start in Thumb mode
19761 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19762
c19d1205 19763 For now we will also provide support for:
b99bd4ef 19764
c19d1205
ZW
19765 -mapcs-32 32-bit Program counter
19766 -mapcs-26 26-bit Program counter
19767 -macps-float Floats passed in FP registers
19768 -mapcs-reentrant Reentrant code
19769 -matpcs
19770 (sometime these will probably be replaced with -mapcs=<list of options>
19771 and -matpcs=<list of options>)
b99bd4ef 19772
c19d1205
ZW
19773 The remaining options are only supported for back-wards compatibility.
19774 Cpu variants, the arm part is optional:
19775 -m[arm]1 Currently not supported.
19776 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19777 -m[arm]3 Arm 3 processor
19778 -m[arm]6[xx], Arm 6 processors
19779 -m[arm]7[xx][t][[d]m] Arm 7 processors
19780 -m[arm]8[10] Arm 8 processors
19781 -m[arm]9[20][tdmi] Arm 9 processors
19782 -mstrongarm[110[0]] StrongARM processors
19783 -mxscale XScale processors
19784 -m[arm]v[2345[t[e]]] Arm architectures
19785 -mall All (except the ARM1)
19786 FP variants:
19787 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19788 -mfpe-old (No float load/store multiples)
19789 -mvfpxd VFP Single precision
19790 -mvfp All VFP
19791 -mno-fpu Disable all floating point instructions
b99bd4ef 19792
c19d1205
ZW
19793 The following CPU names are recognized:
19794 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19795 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19796 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19797 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19798 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19799 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19800 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19801
c19d1205 19802 */
b99bd4ef 19803
c19d1205 19804const char * md_shortopts = "m:k";
b99bd4ef 19805
c19d1205
ZW
19806#ifdef ARM_BI_ENDIAN
19807#define OPTION_EB (OPTION_MD_BASE + 0)
19808#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19809#else
c19d1205
ZW
19810#if TARGET_BYTES_BIG_ENDIAN
19811#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19812#else
c19d1205
ZW
19813#define OPTION_EL (OPTION_MD_BASE + 1)
19814#endif
b99bd4ef 19815#endif
b99bd4ef 19816
c19d1205 19817struct option md_longopts[] =
b99bd4ef 19818{
c19d1205
ZW
19819#ifdef OPTION_EB
19820 {"EB", no_argument, NULL, OPTION_EB},
19821#endif
19822#ifdef OPTION_EL
19823 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19824#endif
c19d1205
ZW
19825 {NULL, no_argument, NULL, 0}
19826};
b99bd4ef 19827
c19d1205 19828size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19829
c19d1205 19830struct arm_option_table
b99bd4ef 19831{
c19d1205
ZW
19832 char *option; /* Option name to match. */
19833 char *help; /* Help information. */
19834 int *var; /* Variable to change. */
19835 int value; /* What to change it to. */
19836 char *deprecated; /* If non-null, print this message. */
19837};
b99bd4ef 19838
c19d1205
ZW
19839struct arm_option_table arm_opts[] =
19840{
19841 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19842 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19843 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19844 &support_interwork, 1, NULL},
19845 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19846 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19847 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19848 1, NULL},
19849 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19850 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19851 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19852 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19853 NULL},
b99bd4ef 19854
c19d1205
ZW
19855 /* These are recognized by the assembler, but have no affect on code. */
19856 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19857 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19858 {NULL, NULL, NULL, 0, NULL}
19859};
19860
19861struct arm_legacy_option_table
19862{
19863 char *option; /* Option name to match. */
19864 const arm_feature_set **var; /* Variable to change. */
19865 const arm_feature_set value; /* What to change it to. */
19866 char *deprecated; /* If non-null, print this message. */
19867};
b99bd4ef 19868
e74cfd16
PB
19869const struct arm_legacy_option_table arm_legacy_opts[] =
19870{
c19d1205
ZW
19871 /* DON'T add any new processors to this list -- we want the whole list
19872 to go away... Add them to the processors table instead. */
e74cfd16
PB
19873 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19874 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19875 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19876 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19877 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19878 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19879 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19880 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19881 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19882 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19883 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19884 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19885 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19886 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19887 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19888 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19889 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19890 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19891 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19892 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19893 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19894 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19895 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19896 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19897 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19898 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19899 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19900 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19901 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19902 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19903 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19904 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19905 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19906 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19907 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19908 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19909 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19910 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19911 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19912 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19913 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19914 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19915 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19916 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19917 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19918 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19919 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19920 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19921 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19922 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19923 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19924 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19925 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19926 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19927 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19928 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19929 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19930 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19931 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19932 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19933 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19934 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19935 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19936 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19937 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19938 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19939 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19940 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19941 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19942 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19943 N_("use -mcpu=strongarm110")},
e74cfd16 19944 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19945 N_("use -mcpu=strongarm1100")},
e74cfd16 19946 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19947 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19948 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19949 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19950 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19951
c19d1205 19952 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19953 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19954 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19955 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19956 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19957 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19958 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19959 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19960 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19961 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19962 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19963 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19964 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19965 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19966 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19967 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19968 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19969 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19970 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 19971
c19d1205 19972 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
19973 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19974 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19975 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19976 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 19977 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 19978
e74cfd16 19979 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 19980};
7ed4c4c5 19981
c19d1205 19982struct arm_cpu_option_table
7ed4c4c5 19983{
c19d1205 19984 char *name;
e74cfd16 19985 const arm_feature_set value;
c19d1205
ZW
19986 /* For some CPUs we assume an FPU unless the user explicitly sets
19987 -mfpu=... */
e74cfd16 19988 const arm_feature_set default_fpu;
ee065d83
PB
19989 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19990 case. */
19991 const char *canonical_name;
c19d1205 19992};
7ed4c4c5 19993
c19d1205
ZW
19994/* This list should, at a minimum, contain all the cpu names
19995 recognized by GCC. */
e74cfd16 19996static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 19997{
ee065d83
PB
19998 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19999 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
20000 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
20001 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20002 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
20003 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20004 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20005 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20006 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20007 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20008 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20009 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20010 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20011 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20012 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20013 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
20014 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20015 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20016 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20017 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20018 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20019 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20020 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20021 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20022 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20023 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20024 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20025 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
20026 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20027 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20028 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20029 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20030 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20031 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20032 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20033 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20034 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20035 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
20036 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20037 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
20038 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20039 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20040 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
20041 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
20042 /* For V5 or later processors we default to using VFP; but the user
20043 should really set the FPU type explicitly. */
ee065d83
PB
20044 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20045 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20046 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20047 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
20048 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20049 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20050 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
20051 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20052 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
20053 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
20054 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20055 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20056 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20057 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20058 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20059 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
20060 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
20061 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20062 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
20063 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
20064 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
20065 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
20066 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
20067 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
20068 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
20069 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
20070 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
20071 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
20072 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
20073 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
20074 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
20075 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
20076 | FPU_NEON_EXT_V1),
20077 NULL},
62b3e311
PB
20078 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
20079 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 20080 /* ??? XSCALE is really an architecture. */
ee065d83 20081 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20082 /* ??? iwmmxt is not a processor. */
ee065d83 20083 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 20084 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 20085 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 20086 /* Maverick */
e74cfd16
PB
20087 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
20088 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 20089};
7ed4c4c5 20090
c19d1205 20091struct arm_arch_option_table
7ed4c4c5 20092{
c19d1205 20093 char *name;
e74cfd16
PB
20094 const arm_feature_set value;
20095 const arm_feature_set default_fpu;
c19d1205 20096};
7ed4c4c5 20097
c19d1205
ZW
20098/* This list should, at a minimum, contain all the architecture names
20099 recognized by GCC. */
e74cfd16 20100static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
20101{
20102 {"all", ARM_ANY, FPU_ARCH_FPA},
20103 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
20104 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
20105 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
20106 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
20107 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
20108 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
20109 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
20110 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
20111 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
20112 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
20113 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
20114 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
20115 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
20116 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
20117 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
20118 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
20119 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
20120 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
20121 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
20122 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
20123 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
20124 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
20125 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
20126 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
20127 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311 20128 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
20129 /* The official spelling of the ARMv7 profile variants is the dashed form.
20130 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
20131 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20132 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20133 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
20134 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
20135 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
20136 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
20137 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
20138 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 20139 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 20140 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 20141};
7ed4c4c5 20142
c19d1205 20143/* ISA extensions in the co-processor space. */
e74cfd16 20144struct arm_option_cpu_value_table
c19d1205
ZW
20145{
20146 char *name;
e74cfd16 20147 const arm_feature_set value;
c19d1205 20148};
7ed4c4c5 20149
e74cfd16 20150static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 20151{
e74cfd16
PB
20152 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
20153 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
20154 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 20155 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 20156 {NULL, ARM_ARCH_NONE}
c19d1205 20157};
7ed4c4c5 20158
c19d1205
ZW
20159/* This list should, at a minimum, contain all the fpu names
20160 recognized by GCC. */
e74cfd16 20161static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
20162{
20163 {"softfpa", FPU_NONE},
20164 {"fpe", FPU_ARCH_FPE},
20165 {"fpe2", FPU_ARCH_FPE},
20166 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
20167 {"fpa", FPU_ARCH_FPA},
20168 {"fpa10", FPU_ARCH_FPA},
20169 {"fpa11", FPU_ARCH_FPA},
20170 {"arm7500fe", FPU_ARCH_FPA},
20171 {"softvfp", FPU_ARCH_VFP},
20172 {"softvfp+vfp", FPU_ARCH_VFP_V2},
20173 {"vfp", FPU_ARCH_VFP_V2},
20174 {"vfp9", FPU_ARCH_VFP_V2},
5287ad62 20175 {"vfp3", FPU_ARCH_VFP_V3},
c19d1205
ZW
20176 {"vfp10", FPU_ARCH_VFP_V2},
20177 {"vfp10-r0", FPU_ARCH_VFP_V1},
20178 {"vfpxd", FPU_ARCH_VFP_V1xD},
20179 {"arm1020t", FPU_ARCH_VFP_V1},
20180 {"arm1020e", FPU_ARCH_VFP_V2},
20181 {"arm1136jfs", FPU_ARCH_VFP_V2},
20182 {"arm1136jf-s", FPU_ARCH_VFP_V2},
20183 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 20184 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
20185 {NULL, ARM_ARCH_NONE}
20186};
20187
20188struct arm_option_value_table
20189{
20190 char *name;
20191 long value;
c19d1205 20192};
7ed4c4c5 20193
e74cfd16 20194static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
20195{
20196 {"hard", ARM_FLOAT_ABI_HARD},
20197 {"softfp", ARM_FLOAT_ABI_SOFTFP},
20198 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 20199 {NULL, 0}
c19d1205 20200};
7ed4c4c5 20201
c19d1205 20202#ifdef OBJ_ELF
3a4a14e9 20203/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 20204static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
20205{
20206 {"gnu", EF_ARM_EABI_UNKNOWN},
20207 {"4", EF_ARM_EABI_VER4},
3a4a14e9 20208 {"5", EF_ARM_EABI_VER5},
e74cfd16 20209 {NULL, 0}
c19d1205
ZW
20210};
20211#endif
7ed4c4c5 20212
c19d1205
ZW
20213struct arm_long_option_table
20214{
20215 char * option; /* Substring to match. */
20216 char * help; /* Help information. */
20217 int (* func) (char * subopt); /* Function to decode sub-option. */
20218 char * deprecated; /* If non-null, print this message. */
20219};
7ed4c4c5
NC
20220
20221static int
e74cfd16 20222arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 20223{
e74cfd16
PB
20224 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
20225
20226 /* Copy the feature set, so that we can modify it. */
20227 *ext_set = **opt_p;
20228 *opt_p = ext_set;
20229
c19d1205 20230 while (str != NULL && *str != 0)
7ed4c4c5 20231 {
e74cfd16 20232 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
20233 char * ext;
20234 int optlen;
7ed4c4c5 20235
c19d1205
ZW
20236 if (*str != '+')
20237 {
20238 as_bad (_("invalid architectural extension"));
20239 return 0;
20240 }
7ed4c4c5 20241
c19d1205
ZW
20242 str++;
20243 ext = strchr (str, '+');
7ed4c4c5 20244
c19d1205
ZW
20245 if (ext != NULL)
20246 optlen = ext - str;
20247 else
20248 optlen = strlen (str);
7ed4c4c5 20249
c19d1205
ZW
20250 if (optlen == 0)
20251 {
20252 as_bad (_("missing architectural extension"));
20253 return 0;
20254 }
7ed4c4c5 20255
c19d1205
ZW
20256 for (opt = arm_extensions; opt->name != NULL; opt++)
20257 if (strncmp (opt->name, str, optlen) == 0)
20258 {
e74cfd16 20259 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
20260 break;
20261 }
7ed4c4c5 20262
c19d1205
ZW
20263 if (opt->name == NULL)
20264 {
20265 as_bad (_("unknown architectural extnsion `%s'"), str);
20266 return 0;
20267 }
7ed4c4c5 20268
c19d1205
ZW
20269 str = ext;
20270 };
7ed4c4c5 20271
c19d1205
ZW
20272 return 1;
20273}
7ed4c4c5 20274
c19d1205
ZW
20275static int
20276arm_parse_cpu (char * str)
7ed4c4c5 20277{
e74cfd16 20278 const struct arm_cpu_option_table * opt;
c19d1205
ZW
20279 char * ext = strchr (str, '+');
20280 int optlen;
7ed4c4c5 20281
c19d1205
ZW
20282 if (ext != NULL)
20283 optlen = ext - str;
7ed4c4c5 20284 else
c19d1205 20285 optlen = strlen (str);
7ed4c4c5 20286
c19d1205 20287 if (optlen == 0)
7ed4c4c5 20288 {
c19d1205
ZW
20289 as_bad (_("missing cpu name `%s'"), str);
20290 return 0;
7ed4c4c5
NC
20291 }
20292
c19d1205
ZW
20293 for (opt = arm_cpus; opt->name != NULL; opt++)
20294 if (strncmp (opt->name, str, optlen) == 0)
20295 {
e74cfd16
PB
20296 mcpu_cpu_opt = &opt->value;
20297 mcpu_fpu_opt = &opt->default_fpu;
ee065d83
PB
20298 if (opt->canonical_name)
20299 strcpy(selected_cpu_name, opt->canonical_name);
20300 else
20301 {
20302 int i;
20303 for (i = 0; i < optlen; i++)
20304 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20305 selected_cpu_name[i] = 0;
20306 }
7ed4c4c5 20307
c19d1205
ZW
20308 if (ext != NULL)
20309 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 20310
c19d1205
ZW
20311 return 1;
20312 }
7ed4c4c5 20313
c19d1205
ZW
20314 as_bad (_("unknown cpu `%s'"), str);
20315 return 0;
7ed4c4c5
NC
20316}
20317
c19d1205
ZW
20318static int
20319arm_parse_arch (char * str)
7ed4c4c5 20320{
e74cfd16 20321 const struct arm_arch_option_table *opt;
c19d1205
ZW
20322 char *ext = strchr (str, '+');
20323 int optlen;
7ed4c4c5 20324
c19d1205
ZW
20325 if (ext != NULL)
20326 optlen = ext - str;
7ed4c4c5 20327 else
c19d1205 20328 optlen = strlen (str);
7ed4c4c5 20329
c19d1205 20330 if (optlen == 0)
7ed4c4c5 20331 {
c19d1205
ZW
20332 as_bad (_("missing architecture name `%s'"), str);
20333 return 0;
7ed4c4c5
NC
20334 }
20335
c19d1205
ZW
20336 for (opt = arm_archs; opt->name != NULL; opt++)
20337 if (streq (opt->name, str))
20338 {
e74cfd16
PB
20339 march_cpu_opt = &opt->value;
20340 march_fpu_opt = &opt->default_fpu;
ee065d83 20341 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 20342
c19d1205
ZW
20343 if (ext != NULL)
20344 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 20345
c19d1205
ZW
20346 return 1;
20347 }
20348
20349 as_bad (_("unknown architecture `%s'\n"), str);
20350 return 0;
7ed4c4c5 20351}
eb043451 20352
c19d1205
ZW
20353static int
20354arm_parse_fpu (char * str)
20355{
e74cfd16 20356 const struct arm_option_cpu_value_table * opt;
b99bd4ef 20357
c19d1205
ZW
20358 for (opt = arm_fpus; opt->name != NULL; opt++)
20359 if (streq (opt->name, str))
20360 {
e74cfd16 20361 mfpu_opt = &opt->value;
c19d1205
ZW
20362 return 1;
20363 }
b99bd4ef 20364
c19d1205
ZW
20365 as_bad (_("unknown floating point format `%s'\n"), str);
20366 return 0;
20367}
20368
20369static int
20370arm_parse_float_abi (char * str)
b99bd4ef 20371{
e74cfd16 20372 const struct arm_option_value_table * opt;
b99bd4ef 20373
c19d1205
ZW
20374 for (opt = arm_float_abis; opt->name != NULL; opt++)
20375 if (streq (opt->name, str))
20376 {
20377 mfloat_abi_opt = opt->value;
20378 return 1;
20379 }
cc8a6dd0 20380
c19d1205
ZW
20381 as_bad (_("unknown floating point abi `%s'\n"), str);
20382 return 0;
20383}
b99bd4ef 20384
c19d1205
ZW
20385#ifdef OBJ_ELF
20386static int
20387arm_parse_eabi (char * str)
20388{
e74cfd16 20389 const struct arm_option_value_table *opt;
cc8a6dd0 20390
c19d1205
ZW
20391 for (opt = arm_eabis; opt->name != NULL; opt++)
20392 if (streq (opt->name, str))
20393 {
20394 meabi_flags = opt->value;
20395 return 1;
20396 }
20397 as_bad (_("unknown EABI `%s'\n"), str);
20398 return 0;
20399}
20400#endif
cc8a6dd0 20401
c19d1205
ZW
20402struct arm_long_option_table arm_long_opts[] =
20403{
20404 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
20405 arm_parse_cpu, NULL},
20406 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
20407 arm_parse_arch, NULL},
20408 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
20409 arm_parse_fpu, NULL},
20410 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
20411 arm_parse_float_abi, NULL},
20412#ifdef OBJ_ELF
20413 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
20414 arm_parse_eabi, NULL},
20415#endif
20416 {NULL, NULL, 0, NULL}
20417};
cc8a6dd0 20418
c19d1205
ZW
20419int
20420md_parse_option (int c, char * arg)
20421{
20422 struct arm_option_table *opt;
e74cfd16 20423 const struct arm_legacy_option_table *fopt;
c19d1205 20424 struct arm_long_option_table *lopt;
b99bd4ef 20425
c19d1205 20426 switch (c)
b99bd4ef 20427 {
c19d1205
ZW
20428#ifdef OPTION_EB
20429 case OPTION_EB:
20430 target_big_endian = 1;
20431 break;
20432#endif
cc8a6dd0 20433
c19d1205
ZW
20434#ifdef OPTION_EL
20435 case OPTION_EL:
20436 target_big_endian = 0;
20437 break;
20438#endif
b99bd4ef 20439
c19d1205
ZW
20440 case 'a':
20441 /* Listing option. Just ignore these, we don't support additional
20442 ones. */
20443 return 0;
b99bd4ef 20444
c19d1205
ZW
20445 default:
20446 for (opt = arm_opts; opt->option != NULL; opt++)
20447 {
20448 if (c == opt->option[0]
20449 && ((arg == NULL && opt->option[1] == 0)
20450 || streq (arg, opt->option + 1)))
20451 {
20452#if WARN_DEPRECATED
20453 /* If the option is deprecated, tell the user. */
20454 if (opt->deprecated != NULL)
20455 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20456 arg ? arg : "", _(opt->deprecated));
20457#endif
b99bd4ef 20458
c19d1205
ZW
20459 if (opt->var != NULL)
20460 *opt->var = opt->value;
cc8a6dd0 20461
c19d1205
ZW
20462 return 1;
20463 }
20464 }
b99bd4ef 20465
e74cfd16
PB
20466 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
20467 {
20468 if (c == fopt->option[0]
20469 && ((arg == NULL && fopt->option[1] == 0)
20470 || streq (arg, fopt->option + 1)))
20471 {
20472#if WARN_DEPRECATED
20473 /* If the option is deprecated, tell the user. */
20474 if (fopt->deprecated != NULL)
20475 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
20476 arg ? arg : "", _(fopt->deprecated));
20477#endif
20478
20479 if (fopt->var != NULL)
20480 *fopt->var = &fopt->value;
20481
20482 return 1;
20483 }
20484 }
20485
c19d1205
ZW
20486 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20487 {
20488 /* These options are expected to have an argument. */
20489 if (c == lopt->option[0]
20490 && arg != NULL
20491 && strncmp (arg, lopt->option + 1,
20492 strlen (lopt->option + 1)) == 0)
20493 {
20494#if WARN_DEPRECATED
20495 /* If the option is deprecated, tell the user. */
20496 if (lopt->deprecated != NULL)
20497 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
20498 _(lopt->deprecated));
20499#endif
b99bd4ef 20500
c19d1205
ZW
20501 /* Call the sup-option parser. */
20502 return lopt->func (arg + strlen (lopt->option) - 1);
20503 }
20504 }
a737bd4d 20505
c19d1205
ZW
20506 return 0;
20507 }
a394c00f 20508
c19d1205
ZW
20509 return 1;
20510}
a394c00f 20511
c19d1205
ZW
20512void
20513md_show_usage (FILE * fp)
a394c00f 20514{
c19d1205
ZW
20515 struct arm_option_table *opt;
20516 struct arm_long_option_table *lopt;
a394c00f 20517
c19d1205 20518 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 20519
c19d1205
ZW
20520 for (opt = arm_opts; opt->option != NULL; opt++)
20521 if (opt->help != NULL)
20522 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 20523
c19d1205
ZW
20524 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
20525 if (lopt->help != NULL)
20526 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 20527
c19d1205
ZW
20528#ifdef OPTION_EB
20529 fprintf (fp, _("\
20530 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
20531#endif
20532
c19d1205
ZW
20533#ifdef OPTION_EL
20534 fprintf (fp, _("\
20535 -EL assemble code for a little-endian cpu\n"));
a737bd4d 20536#endif
c19d1205 20537}
ee065d83
PB
20538
20539
20540#ifdef OBJ_ELF
62b3e311
PB
20541typedef struct
20542{
20543 int val;
20544 arm_feature_set flags;
20545} cpu_arch_ver_table;
20546
20547/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
20548 least features first. */
20549static const cpu_arch_ver_table cpu_arch_ver[] =
20550{
20551 {1, ARM_ARCH_V4},
20552 {2, ARM_ARCH_V4T},
20553 {3, ARM_ARCH_V5},
20554 {4, ARM_ARCH_V5TE},
20555 {5, ARM_ARCH_V5TEJ},
20556 {6, ARM_ARCH_V6},
20557 {7, ARM_ARCH_V6Z},
20558 {8, ARM_ARCH_V6K},
20559 {9, ARM_ARCH_V6T2},
20560 {10, ARM_ARCH_V7A},
20561 {10, ARM_ARCH_V7R},
20562 {10, ARM_ARCH_V7M},
20563 {0, ARM_ARCH_NONE}
20564};
20565
ee065d83
PB
20566/* Set the public EABI object attributes. */
20567static void
20568aeabi_set_public_attributes (void)
20569{
20570 int arch;
e74cfd16 20571 arm_feature_set flags;
62b3e311
PB
20572 arm_feature_set tmp;
20573 const cpu_arch_ver_table *p;
ee065d83
PB
20574
20575 /* Choose the architecture based on the capabilities of the requested cpu
20576 (if any) and/or the instructions actually used. */
e74cfd16
PB
20577 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20578 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20579 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
20580 /*Allow the user to override the reported architecture. */
20581 if (object_arch)
20582 {
20583 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
20584 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
20585 }
20586
62b3e311
PB
20587 tmp = flags;
20588 arch = 0;
20589 for (p = cpu_arch_ver; p->val; p++)
20590 {
20591 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20592 {
20593 arch = p->val;
20594 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20595 }
20596 }
ee065d83
PB
20597
20598 /* Tag_CPU_name. */
20599 if (selected_cpu_name[0])
20600 {
20601 char *p;
20602
20603 p = selected_cpu_name;
20604 if (strncmp(p, "armv", 4) == 0)
20605 {
20606 int i;
20607
20608 p += 4;
20609 for (i = 0; p[i]; i++)
20610 p[i] = TOUPPER (p[i]);
20611 }
20612 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
20613 }
20614 /* Tag_CPU_arch. */
20615 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
62b3e311
PB
20616 /* Tag_CPU_arch_profile. */
20617 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20618 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
20619 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20620 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
20621 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20622 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
ee065d83 20623 /* Tag_ARM_ISA_use. */
e74cfd16 20624 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
ee065d83
PB
20625 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
20626 /* Tag_THUMB_ISA_use. */
e74cfd16 20627 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
ee065d83 20628 elf32_arm_add_eabi_attr_int (stdoutput, 9,
e74cfd16 20629 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20630 /* Tag_VFP_arch. */
5287ad62
JB
20631 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20632 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20633 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
20634 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20635 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
ee065d83 20636 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
5287ad62
JB
20637 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20638 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20639 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20640 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
ee065d83
PB
20641 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
20642 /* Tag_WMMX_arch. */
e74cfd16
PB
20643 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20644 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
ee065d83 20645 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
5287ad62
JB
20646 /* Tag_NEON_arch. */
20647 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20648 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20649 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
ee065d83
PB
20650}
20651
20652/* Add the .ARM.attributes section. */
20653void
20654arm_md_end (void)
20655{
20656 segT s;
20657 char *p;
20658 addressT addr;
20659 offsetT size;
20660
20661 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20662 return;
20663
20664 aeabi_set_public_attributes ();
20665 size = elf32_arm_eabi_attr_size (stdoutput);
20666 s = subseg_new (".ARM.attributes", 0);
20667 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
20668 addr = frag_now_fix ();
20669 p = frag_more (size);
20670 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
20671}
8463be01 20672#endif /* OBJ_ELF */
ee065d83
PB
20673
20674
20675/* Parse a .cpu directive. */
20676
20677static void
20678s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20679{
e74cfd16 20680 const struct arm_cpu_option_table *opt;
ee065d83
PB
20681 char *name;
20682 char saved_char;
20683
20684 name = input_line_pointer;
20685 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20686 input_line_pointer++;
20687 saved_char = *input_line_pointer;
20688 *input_line_pointer = 0;
20689
20690 /* Skip the first "all" entry. */
20691 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20692 if (streq (opt->name, name))
20693 {
e74cfd16
PB
20694 mcpu_cpu_opt = &opt->value;
20695 selected_cpu = opt->value;
ee065d83
PB
20696 if (opt->canonical_name)
20697 strcpy(selected_cpu_name, opt->canonical_name);
20698 else
20699 {
20700 int i;
20701 for (i = 0; opt->name[i]; i++)
20702 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20703 selected_cpu_name[i] = 0;
20704 }
e74cfd16 20705 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20706 *input_line_pointer = saved_char;
20707 demand_empty_rest_of_line ();
20708 return;
20709 }
20710 as_bad (_("unknown cpu `%s'"), name);
20711 *input_line_pointer = saved_char;
20712 ignore_rest_of_line ();
20713}
20714
20715
20716/* Parse a .arch directive. */
20717
20718static void
20719s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20720{
e74cfd16 20721 const struct arm_arch_option_table *opt;
ee065d83
PB
20722 char saved_char;
20723 char *name;
20724
20725 name = input_line_pointer;
20726 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20727 input_line_pointer++;
20728 saved_char = *input_line_pointer;
20729 *input_line_pointer = 0;
20730
20731 /* Skip the first "all" entry. */
20732 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20733 if (streq (opt->name, name))
20734 {
e74cfd16
PB
20735 mcpu_cpu_opt = &opt->value;
20736 selected_cpu = opt->value;
ee065d83 20737 strcpy(selected_cpu_name, opt->name);
e74cfd16 20738 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20739 *input_line_pointer = saved_char;
20740 demand_empty_rest_of_line ();
20741 return;
20742 }
20743
20744 as_bad (_("unknown architecture `%s'\n"), name);
20745 *input_line_pointer = saved_char;
20746 ignore_rest_of_line ();
20747}
20748
20749
7a1d4c38
PB
20750/* Parse a .object_arch directive. */
20751
20752static void
20753s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
20754{
20755 const struct arm_arch_option_table *opt;
20756 char saved_char;
20757 char *name;
20758
20759 name = input_line_pointer;
20760 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20761 input_line_pointer++;
20762 saved_char = *input_line_pointer;
20763 *input_line_pointer = 0;
20764
20765 /* Skip the first "all" entry. */
20766 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20767 if (streq (opt->name, name))
20768 {
20769 object_arch = &opt->value;
20770 *input_line_pointer = saved_char;
20771 demand_empty_rest_of_line ();
20772 return;
20773 }
20774
20775 as_bad (_("unknown architecture `%s'\n"), name);
20776 *input_line_pointer = saved_char;
20777 ignore_rest_of_line ();
20778}
20779
20780
ee065d83
PB
20781/* Parse a .fpu directive. */
20782
20783static void
20784s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20785{
e74cfd16 20786 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20787 char saved_char;
20788 char *name;
20789
20790 name = input_line_pointer;
20791 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20792 input_line_pointer++;
20793 saved_char = *input_line_pointer;
20794 *input_line_pointer = 0;
20795
20796 for (opt = arm_fpus; opt->name != NULL; opt++)
20797 if (streq (opt->name, name))
20798 {
e74cfd16
PB
20799 mfpu_opt = &opt->value;
20800 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20801 *input_line_pointer = saved_char;
20802 demand_empty_rest_of_line ();
20803 return;
20804 }
20805
20806 as_bad (_("unknown floating point format `%s'\n"), name);
20807 *input_line_pointer = saved_char;
20808 ignore_rest_of_line ();
20809}
ee065d83 20810
794ba86a
DJ
20811/* Copy symbol information. */
20812void
20813arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
20814{
20815 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
20816}
This page took 1.81612 seconds and 4 git commands to generate.