]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
PR binutils/3166
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
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;
158
159/* Constants for known architecture features. */
160static const arm_feature_set fpu_default = FPU_DEFAULT;
161static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
162static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
163static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
164static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
165static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
166static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
167static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
168static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
169
170#ifdef CPU_DEFAULT
171static const arm_feature_set cpu_default = CPU_DEFAULT;
172#endif
173
174static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
175static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
176static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
177static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
178static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
179static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
180static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
181static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
182static const arm_feature_set arm_ext_v4t_5 =
183 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
184static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
185static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
186static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
187static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
188static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
189static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
190static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
191static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311
PB
192static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
193static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
194static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
195static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
196static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
197static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
e74cfd16
PB
198
199static const arm_feature_set arm_arch_any = ARM_ANY;
200static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
201static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
202static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
203
204static const arm_feature_set arm_cext_iwmmxt =
205 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
206static const arm_feature_set arm_cext_xscale =
207 ARM_FEATURE (0, ARM_CEXT_XSCALE);
208static const arm_feature_set arm_cext_maverick =
209 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
210static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
211static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
212static const arm_feature_set fpu_vfp_ext_v1xd =
213 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
214static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
215static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62
JB
216static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
217static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
218static const arm_feature_set fpu_vfp_v3_or_neon_ext =
219 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
e74cfd16 220
33a392fb 221static int mfloat_abi_opt = -1;
e74cfd16
PB
222/* Record user cpu selection for object attributes. */
223static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
224/* Must be long enough to hold any of the names in arm_cpus. */
225static char selected_cpu_name[16];
7cc69913 226#ifdef OBJ_ELF
deeaaff8
DJ
227# ifdef EABI_DEFAULT
228static int meabi_flags = EABI_DEFAULT;
229# else
d507cf36 230static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 231# endif
7cc69913 232#endif
b99bd4ef 233
b99bd4ef 234#ifdef OBJ_ELF
c19d1205 235/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
236symbolS * GOT_symbol;
237#endif
238
b99bd4ef
NC
239/* 0: assemble for ARM,
240 1: assemble for Thumb,
241 2: assemble for Thumb even though target CPU does not support thumb
242 instructions. */
243static int thumb_mode = 0;
244
c19d1205
ZW
245/* If unified_syntax is true, we are processing the new unified
246 ARM/Thumb syntax. Important differences from the old ARM mode:
247
248 - Immediate operands do not require a # prefix.
249 - Conditional affixes always appear at the end of the
250 instruction. (For backward compatibility, those instructions
251 that formerly had them in the middle, continue to accept them
252 there.)
253 - The IT instruction may appear, and if it does is validated
254 against subsequent conditional affixes. It does not generate
255 machine code.
256
257 Important differences from the old Thumb mode:
258
259 - Immediate operands do not require a # prefix.
260 - Most of the V6T2 instructions are only available in unified mode.
261 - The .N and .W suffixes are recognized and honored (it is an error
262 if they cannot be honored).
263 - All instructions set the flags if and only if they have an 's' affix.
264 - Conditional affixes may be used. They are validated against
265 preceding IT instructions. Unlike ARM mode, you cannot use a
266 conditional affix except in the scope of an IT instruction. */
267
268static bfd_boolean unified_syntax = FALSE;
b99bd4ef 269
5287ad62
JB
270enum neon_el_type
271{
dcbf9037 272 NT_invtype,
5287ad62
JB
273 NT_untyped,
274 NT_integer,
275 NT_float,
276 NT_poly,
277 NT_signed,
dcbf9037 278 NT_unsigned
5287ad62
JB
279};
280
281struct neon_type_el
282{
283 enum neon_el_type type;
284 unsigned size;
285};
286
287#define NEON_MAX_TYPE_ELS 4
288
289struct neon_type
290{
291 struct neon_type_el el[NEON_MAX_TYPE_ELS];
292 unsigned elems;
293};
294
b99bd4ef
NC
295struct arm_it
296{
c19d1205 297 const char * error;
b99bd4ef 298 unsigned long instruction;
c19d1205
ZW
299 int size;
300 int size_req;
301 int cond;
037e8744
JB
302 /* "uncond_value" is set to the value in place of the conditional field in
303 unconditional versions of the instruction, or -1 if nothing is
304 appropriate. */
305 int uncond_value;
5287ad62 306 struct neon_type vectype;
0110f2b8
PB
307 /* Set to the opcode if the instruction needs relaxation.
308 Zero if the instruction is not relaxed. */
309 unsigned long relax;
b99bd4ef
NC
310 struct
311 {
312 bfd_reloc_code_real_type type;
c19d1205
ZW
313 expressionS exp;
314 int pc_rel;
b99bd4ef 315 } reloc;
b99bd4ef 316
c19d1205
ZW
317 struct
318 {
319 unsigned reg;
ca3f61f7 320 signed int imm;
dcbf9037 321 struct neon_type_el vectype;
ca3f61f7
NC
322 unsigned present : 1; /* Operand present. */
323 unsigned isreg : 1; /* Operand was a register. */
324 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
325 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
326 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
327 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
328 instructions. This allows us to disambiguate ARM <-> vector insns. */
329 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 330 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 331 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 332 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
333 unsigned hasreloc : 1; /* Operand has relocation suffix. */
334 unsigned writeback : 1; /* Operand has trailing ! */
335 unsigned preind : 1; /* Preindexed address. */
336 unsigned postind : 1; /* Postindexed address. */
337 unsigned negative : 1; /* Index register was negated. */
338 unsigned shifted : 1; /* Shift applied to operation. */
339 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 340 } operands[6];
b99bd4ef
NC
341};
342
c19d1205 343static struct arm_it inst;
b99bd4ef
NC
344
345#define NUM_FLOAT_VALS 8
346
05d2d07e 347const char * fp_const[] =
b99bd4ef
NC
348{
349 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
350};
351
c19d1205 352/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
353#define MAX_LITTLENUMS 6
354
355LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
356
357#define FAIL (-1)
358#define SUCCESS (0)
359
360#define SUFF_S 1
361#define SUFF_D 2
362#define SUFF_E 3
363#define SUFF_P 4
364
c19d1205
ZW
365#define CP_T_X 0x00008000
366#define CP_T_Y 0x00400000
b99bd4ef 367
c19d1205
ZW
368#define CONDS_BIT 0x00100000
369#define LOAD_BIT 0x00100000
b99bd4ef
NC
370
371#define DOUBLE_LOAD_FLAG 0x00000001
372
373struct asm_cond
374{
c19d1205 375 const char * template;
b99bd4ef
NC
376 unsigned long value;
377};
378
c19d1205 379#define COND_ALWAYS 0xE
b99bd4ef 380
b99bd4ef
NC
381struct asm_psr
382{
b34976b6 383 const char *template;
b99bd4ef
NC
384 unsigned long field;
385};
386
62b3e311
PB
387struct asm_barrier_opt
388{
389 const char *template;
390 unsigned long value;
391};
392
2d2255b5 393/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
394#define SPSR_BIT (1 << 22)
395
c19d1205
ZW
396/* The individual PSR flag bits. */
397#define PSR_c (1 << 16)
398#define PSR_x (1 << 17)
399#define PSR_s (1 << 18)
400#define PSR_f (1 << 19)
b99bd4ef 401
c19d1205 402struct reloc_entry
bfae80f2 403{
c19d1205
ZW
404 char *name;
405 bfd_reloc_code_real_type reloc;
bfae80f2
RE
406};
407
5287ad62 408enum vfp_reg_pos
bfae80f2 409{
5287ad62
JB
410 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
411 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
412};
413
414enum vfp_ldstm_type
415{
416 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
417};
418
dcbf9037
JB
419/* Bits for DEFINED field in neon_typed_alias. */
420#define NTA_HASTYPE 1
421#define NTA_HASINDEX 2
422
423struct neon_typed_alias
424{
425 unsigned char defined;
426 unsigned char index;
427 struct neon_type_el eltype;
428};
429
c19d1205
ZW
430/* ARM register categories. This includes coprocessor numbers and various
431 architecture extensions' registers. */
432enum arm_reg_type
bfae80f2 433{
c19d1205
ZW
434 REG_TYPE_RN,
435 REG_TYPE_CP,
436 REG_TYPE_CN,
437 REG_TYPE_FN,
438 REG_TYPE_VFS,
439 REG_TYPE_VFD,
5287ad62 440 REG_TYPE_NQ,
037e8744 441 REG_TYPE_VFSD,
5287ad62 442 REG_TYPE_NDQ,
037e8744 443 REG_TYPE_NSDQ,
c19d1205
ZW
444 REG_TYPE_VFC,
445 REG_TYPE_MVF,
446 REG_TYPE_MVD,
447 REG_TYPE_MVFX,
448 REG_TYPE_MVDX,
449 REG_TYPE_MVAX,
450 REG_TYPE_DSPSC,
451 REG_TYPE_MMXWR,
452 REG_TYPE_MMXWC,
453 REG_TYPE_MMXWCG,
454 REG_TYPE_XSCALE,
bfae80f2
RE
455};
456
dcbf9037
JB
457/* Structure for a hash table entry for a register.
458 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
459 information which states whether a vector type or index is specified (for a
460 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
461struct reg_entry
462{
dcbf9037
JB
463 const char *name;
464 unsigned char number;
465 unsigned char type;
466 unsigned char builtin;
467 struct neon_typed_alias *neon;
6c43fab6
RE
468};
469
c19d1205
ZW
470/* Diagnostics used when we don't get a register of the expected type. */
471const char *const reg_expected_msgs[] =
472{
473 N_("ARM register expected"),
474 N_("bad or missing co-processor number"),
475 N_("co-processor register expected"),
476 N_("FPA register expected"),
477 N_("VFP single precision register expected"),
5287ad62
JB
478 N_("VFP/Neon double precision register expected"),
479 N_("Neon quad precision register expected"),
037e8744 480 N_("VFP single or double precision register expected"),
5287ad62 481 N_("Neon double or quad precision register expected"),
037e8744 482 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
483 N_("VFP system register expected"),
484 N_("Maverick MVF register expected"),
485 N_("Maverick MVD register expected"),
486 N_("Maverick MVFX register expected"),
487 N_("Maverick MVDX register expected"),
488 N_("Maverick MVAX register expected"),
489 N_("Maverick DSPSC register expected"),
490 N_("iWMMXt data register expected"),
491 N_("iWMMXt control register expected"),
492 N_("iWMMXt scalar register expected"),
493 N_("XScale accumulator register expected"),
6c43fab6
RE
494};
495
c19d1205
ZW
496/* Some well known registers that we refer to directly elsewhere. */
497#define REG_SP 13
498#define REG_LR 14
499#define REG_PC 15
404ff6b5 500
b99bd4ef
NC
501/* ARM instructions take 4bytes in the object file, Thumb instructions
502 take 2: */
c19d1205 503#define INSN_SIZE 4
b99bd4ef
NC
504
505struct asm_opcode
506{
507 /* Basic string to match. */
c19d1205
ZW
508 const char *template;
509
510 /* Parameters to instruction. */
511 unsigned char operands[8];
512
513 /* Conditional tag - see opcode_lookup. */
514 unsigned int tag : 4;
b99bd4ef
NC
515
516 /* Basic instruction code. */
c19d1205 517 unsigned int avalue : 28;
b99bd4ef 518
c19d1205
ZW
519 /* Thumb-format instruction code. */
520 unsigned int tvalue;
b99bd4ef 521
90e4755a 522 /* Which architecture variant provides this instruction. */
e74cfd16
PB
523 const arm_feature_set *avariant;
524 const arm_feature_set *tvariant;
c19d1205
ZW
525
526 /* Function to call to encode instruction in ARM format. */
527 void (* aencode) (void);
b99bd4ef 528
c19d1205
ZW
529 /* Function to call to encode instruction in Thumb format. */
530 void (* tencode) (void);
b99bd4ef
NC
531};
532
a737bd4d
NC
533/* Defines for various bits that we will want to toggle. */
534#define INST_IMMEDIATE 0x02000000
535#define OFFSET_REG 0x02000000
c19d1205 536#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
537#define SHIFT_BY_REG 0x00000010
538#define PRE_INDEX 0x01000000
539#define INDEX_UP 0x00800000
540#define WRITE_BACK 0x00200000
541#define LDM_TYPE_2_OR_3 0x00400000
90e4755a 542
a737bd4d
NC
543#define LITERAL_MASK 0xf000f000
544#define OPCODE_MASK 0xfe1fffff
545#define V4_STR_BIT 0x00000020
90e4755a 546
a737bd4d 547#define DATA_OP_SHIFT 21
90e4755a 548
ef8d22e6
PB
549#define T2_OPCODE_MASK 0xfe1fffff
550#define T2_DATA_OP_SHIFT 21
551
a737bd4d
NC
552/* Codes to distinguish the arithmetic instructions. */
553#define OPCODE_AND 0
554#define OPCODE_EOR 1
555#define OPCODE_SUB 2
556#define OPCODE_RSB 3
557#define OPCODE_ADD 4
558#define OPCODE_ADC 5
559#define OPCODE_SBC 6
560#define OPCODE_RSC 7
561#define OPCODE_TST 8
562#define OPCODE_TEQ 9
563#define OPCODE_CMP 10
564#define OPCODE_CMN 11
565#define OPCODE_ORR 12
566#define OPCODE_MOV 13
567#define OPCODE_BIC 14
568#define OPCODE_MVN 15
90e4755a 569
ef8d22e6
PB
570#define T2_OPCODE_AND 0
571#define T2_OPCODE_BIC 1
572#define T2_OPCODE_ORR 2
573#define T2_OPCODE_ORN 3
574#define T2_OPCODE_EOR 4
575#define T2_OPCODE_ADD 8
576#define T2_OPCODE_ADC 10
577#define T2_OPCODE_SBC 11
578#define T2_OPCODE_SUB 13
579#define T2_OPCODE_RSB 14
580
a737bd4d
NC
581#define T_OPCODE_MUL 0x4340
582#define T_OPCODE_TST 0x4200
583#define T_OPCODE_CMN 0x42c0
584#define T_OPCODE_NEG 0x4240
585#define T_OPCODE_MVN 0x43c0
90e4755a 586
a737bd4d
NC
587#define T_OPCODE_ADD_R3 0x1800
588#define T_OPCODE_SUB_R3 0x1a00
589#define T_OPCODE_ADD_HI 0x4400
590#define T_OPCODE_ADD_ST 0xb000
591#define T_OPCODE_SUB_ST 0xb080
592#define T_OPCODE_ADD_SP 0xa800
593#define T_OPCODE_ADD_PC 0xa000
594#define T_OPCODE_ADD_I8 0x3000
595#define T_OPCODE_SUB_I8 0x3800
596#define T_OPCODE_ADD_I3 0x1c00
597#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 598
a737bd4d
NC
599#define T_OPCODE_ASR_R 0x4100
600#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
601#define T_OPCODE_LSR_R 0x40c0
602#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
603#define T_OPCODE_ASR_I 0x1000
604#define T_OPCODE_LSL_I 0x0000
605#define T_OPCODE_LSR_I 0x0800
b99bd4ef 606
a737bd4d
NC
607#define T_OPCODE_MOV_I8 0x2000
608#define T_OPCODE_CMP_I8 0x2800
609#define T_OPCODE_CMP_LR 0x4280
610#define T_OPCODE_MOV_HR 0x4600
611#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 612
a737bd4d
NC
613#define T_OPCODE_LDR_PC 0x4800
614#define T_OPCODE_LDR_SP 0x9800
615#define T_OPCODE_STR_SP 0x9000
616#define T_OPCODE_LDR_IW 0x6800
617#define T_OPCODE_STR_IW 0x6000
618#define T_OPCODE_LDR_IH 0x8800
619#define T_OPCODE_STR_IH 0x8000
620#define T_OPCODE_LDR_IB 0x7800
621#define T_OPCODE_STR_IB 0x7000
622#define T_OPCODE_LDR_RW 0x5800
623#define T_OPCODE_STR_RW 0x5000
624#define T_OPCODE_LDR_RH 0x5a00
625#define T_OPCODE_STR_RH 0x5200
626#define T_OPCODE_LDR_RB 0x5c00
627#define T_OPCODE_STR_RB 0x5400
c9b604bd 628
a737bd4d
NC
629#define T_OPCODE_PUSH 0xb400
630#define T_OPCODE_POP 0xbc00
b99bd4ef 631
2fc8bdac 632#define T_OPCODE_BRANCH 0xe000
b99bd4ef 633
a737bd4d 634#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 635#define THUMB_PP_PC_LR 0x0100
c19d1205 636#define THUMB_LOAD_BIT 0x0800
53365c0d 637#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
638
639#define BAD_ARGS _("bad arguments to instruction")
640#define BAD_PC _("r15 not allowed here")
641#define BAD_COND _("instruction cannot be conditional")
642#define BAD_OVERLAP _("registers may not be the same")
643#define BAD_HIREG _("lo register required")
644#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 645#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
646#define BAD_BRANCH _("branch must be last instruction in IT block")
647#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 648#define BAD_FPU _("selected FPU does not support instruction")
c19d1205
ZW
649
650static struct hash_control *arm_ops_hsh;
651static struct hash_control *arm_cond_hsh;
652static struct hash_control *arm_shift_hsh;
653static struct hash_control *arm_psr_hsh;
62b3e311 654static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
655static struct hash_control *arm_reg_hsh;
656static struct hash_control *arm_reloc_hsh;
62b3e311 657static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 658
b99bd4ef
NC
659/* Stuff needed to resolve the label ambiguity
660 As:
661 ...
662 label: <insn>
663 may differ from:
664 ...
665 label:
c19d1205 666 <insn>
b99bd4ef
NC
667*/
668
669symbolS * last_label_seen;
b34976b6 670static int label_is_thumb_function_name = FALSE;
a737bd4d 671\f
3d0c9500
NC
672/* Literal pool structure. Held on a per-section
673 and per-sub-section basis. */
a737bd4d 674
c19d1205 675#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 676typedef struct literal_pool
b99bd4ef 677{
c19d1205
ZW
678 expressionS literals [MAX_LITERAL_POOL_SIZE];
679 unsigned int next_free_entry;
680 unsigned int id;
681 symbolS * symbol;
682 segT section;
683 subsegT sub_section;
61b5f74b 684 struct literal_pool * next;
3d0c9500 685} literal_pool;
b99bd4ef 686
3d0c9500
NC
687/* Pointer to a linked list of literal pools. */
688literal_pool * list_of_pools = NULL;
e27ec89e
PB
689
690/* State variables for IT block handling. */
691static bfd_boolean current_it_mask = 0;
692static int current_cc;
693
c19d1205
ZW
694\f
695/* Pure syntax. */
b99bd4ef 696
c19d1205
ZW
697/* This array holds the chars that always start a comment. If the
698 pre-processor is disabled, these aren't very useful. */
699const char comment_chars[] = "@";
3d0c9500 700
c19d1205
ZW
701/* This array holds the chars that only start a comment at the beginning of
702 a line. If the line seems to have the form '# 123 filename'
703 .line and .file directives will appear in the pre-processed output. */
704/* Note that input_file.c hand checks for '#' at the beginning of the
705 first line of the input file. This is because the compiler outputs
706 #NO_APP at the beginning of its output. */
707/* Also note that comments like this one will always work. */
708const char line_comment_chars[] = "#";
3d0c9500 709
c19d1205 710const char line_separator_chars[] = ";";
b99bd4ef 711
c19d1205
ZW
712/* Chars that can be used to separate mant
713 from exp in floating point numbers. */
714const char EXP_CHARS[] = "eE";
3d0c9500 715
c19d1205
ZW
716/* Chars that mean this number is a floating point constant. */
717/* As in 0f12.456 */
718/* or 0d1.2345e12 */
b99bd4ef 719
c19d1205 720const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 721
c19d1205
ZW
722/* Prefix characters that indicate the start of an immediate
723 value. */
724#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 725
c19d1205
ZW
726/* Separator character handling. */
727
728#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
729
730static inline int
731skip_past_char (char ** str, char c)
732{
733 if (**str == c)
734 {
735 (*str)++;
736 return SUCCESS;
3d0c9500 737 }
c19d1205
ZW
738 else
739 return FAIL;
740}
741#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 742
c19d1205
ZW
743/* Arithmetic expressions (possibly involving symbols). */
744
745/* Return TRUE if anything in the expression is a bignum. */
746
747static int
748walk_no_bignums (symbolS * sp)
749{
750 if (symbol_get_value_expression (sp)->X_op == O_big)
751 return 1;
752
753 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 754 {
c19d1205
ZW
755 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
756 || (symbol_get_value_expression (sp)->X_op_symbol
757 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
758 }
759
c19d1205 760 return 0;
3d0c9500
NC
761}
762
c19d1205
ZW
763static int in_my_get_expression = 0;
764
765/* Third argument to my_get_expression. */
766#define GE_NO_PREFIX 0
767#define GE_IMM_PREFIX 1
768#define GE_OPT_PREFIX 2
5287ad62
JB
769/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
770 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
771#define GE_OPT_PREFIX_BIG 3
a737bd4d 772
b99bd4ef 773static int
c19d1205 774my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 775{
c19d1205
ZW
776 char * save_in;
777 segT seg;
b99bd4ef 778
c19d1205
ZW
779 /* In unified syntax, all prefixes are optional. */
780 if (unified_syntax)
5287ad62
JB
781 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
782 : GE_OPT_PREFIX;
b99bd4ef 783
c19d1205 784 switch (prefix_mode)
b99bd4ef 785 {
c19d1205
ZW
786 case GE_NO_PREFIX: break;
787 case GE_IMM_PREFIX:
788 if (!is_immediate_prefix (**str))
789 {
790 inst.error = _("immediate expression requires a # prefix");
791 return FAIL;
792 }
793 (*str)++;
794 break;
795 case GE_OPT_PREFIX:
5287ad62 796 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
797 if (is_immediate_prefix (**str))
798 (*str)++;
799 break;
800 default: abort ();
801 }
b99bd4ef 802
c19d1205 803 memset (ep, 0, sizeof (expressionS));
b99bd4ef 804
c19d1205
ZW
805 save_in = input_line_pointer;
806 input_line_pointer = *str;
807 in_my_get_expression = 1;
808 seg = expression (ep);
809 in_my_get_expression = 0;
810
811 if (ep->X_op == O_illegal)
b99bd4ef 812 {
c19d1205
ZW
813 /* We found a bad expression in md_operand(). */
814 *str = input_line_pointer;
815 input_line_pointer = save_in;
816 if (inst.error == NULL)
817 inst.error = _("bad expression");
818 return 1;
819 }
b99bd4ef 820
c19d1205
ZW
821#ifdef OBJ_AOUT
822 if (seg != absolute_section
823 && seg != text_section
824 && seg != data_section
825 && seg != bss_section
826 && seg != undefined_section)
827 {
828 inst.error = _("bad segment");
829 *str = input_line_pointer;
830 input_line_pointer = save_in;
831 return 1;
b99bd4ef 832 }
c19d1205 833#endif
b99bd4ef 834
c19d1205
ZW
835 /* Get rid of any bignums now, so that we don't generate an error for which
836 we can't establish a line number later on. Big numbers are never valid
837 in instructions, which is where this routine is always called. */
5287ad62
JB
838 if (prefix_mode != GE_OPT_PREFIX_BIG
839 && (ep->X_op == O_big
840 || (ep->X_add_symbol
841 && (walk_no_bignums (ep->X_add_symbol)
842 || (ep->X_op_symbol
843 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
844 {
845 inst.error = _("invalid constant");
846 *str = input_line_pointer;
847 input_line_pointer = save_in;
848 return 1;
849 }
b99bd4ef 850
c19d1205
ZW
851 *str = input_line_pointer;
852 input_line_pointer = save_in;
853 return 0;
b99bd4ef
NC
854}
855
c19d1205
ZW
856/* Turn a string in input_line_pointer into a floating point constant
857 of type TYPE, and store the appropriate bytes in *LITP. The number
858 of LITTLENUMS emitted is stored in *SIZEP. An error message is
859 returned, or NULL on OK.
b99bd4ef 860
c19d1205
ZW
861 Note that fp constants aren't represent in the normal way on the ARM.
862 In big endian mode, things are as expected. However, in little endian
863 mode fp constants are big-endian word-wise, and little-endian byte-wise
864 within the words. For example, (double) 1.1 in big endian mode is
865 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
866 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 867
c19d1205 868 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 869
c19d1205
ZW
870char *
871md_atof (int type, char * litP, int * sizeP)
872{
873 int prec;
874 LITTLENUM_TYPE words[MAX_LITTLENUMS];
875 char *t;
876 int i;
b99bd4ef 877
c19d1205
ZW
878 switch (type)
879 {
880 case 'f':
881 case 'F':
882 case 's':
883 case 'S':
884 prec = 2;
885 break;
b99bd4ef 886
c19d1205
ZW
887 case 'd':
888 case 'D':
889 case 'r':
890 case 'R':
891 prec = 4;
892 break;
b99bd4ef 893
c19d1205
ZW
894 case 'x':
895 case 'X':
896 prec = 6;
897 break;
b99bd4ef 898
c19d1205
ZW
899 case 'p':
900 case 'P':
901 prec = 6;
902 break;
a737bd4d 903
c19d1205
ZW
904 default:
905 *sizeP = 0;
906 return _("bad call to MD_ATOF()");
907 }
b99bd4ef 908
c19d1205
ZW
909 t = atof_ieee (input_line_pointer, type, words);
910 if (t)
911 input_line_pointer = t;
912 *sizeP = prec * 2;
b99bd4ef 913
c19d1205
ZW
914 if (target_big_endian)
915 {
916 for (i = 0; i < prec; i++)
917 {
918 md_number_to_chars (litP, (valueT) words[i], 2);
919 litP += 2;
920 }
921 }
922 else
923 {
e74cfd16 924 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
925 for (i = prec - 1; i >= 0; i--)
926 {
927 md_number_to_chars (litP, (valueT) words[i], 2);
928 litP += 2;
929 }
930 else
931 /* For a 4 byte float the order of elements in `words' is 1 0.
932 For an 8 byte float the order is 1 0 3 2. */
933 for (i = 0; i < prec; i += 2)
934 {
935 md_number_to_chars (litP, (valueT) words[i + 1], 2);
936 md_number_to_chars (litP + 2, (valueT) words[i], 2);
937 litP += 4;
938 }
939 }
b99bd4ef 940
c19d1205
ZW
941 return 0;
942}
b99bd4ef 943
c19d1205
ZW
944/* We handle all bad expressions here, so that we can report the faulty
945 instruction in the error message. */
946void
947md_operand (expressionS * expr)
948{
949 if (in_my_get_expression)
950 expr->X_op = O_illegal;
b99bd4ef
NC
951}
952
c19d1205 953/* Immediate values. */
b99bd4ef 954
c19d1205
ZW
955/* Generic immediate-value read function for use in directives.
956 Accepts anything that 'expression' can fold to a constant.
957 *val receives the number. */
958#ifdef OBJ_ELF
959static int
960immediate_for_directive (int *val)
b99bd4ef 961{
c19d1205
ZW
962 expressionS exp;
963 exp.X_op = O_illegal;
b99bd4ef 964
c19d1205
ZW
965 if (is_immediate_prefix (*input_line_pointer))
966 {
967 input_line_pointer++;
968 expression (&exp);
969 }
b99bd4ef 970
c19d1205
ZW
971 if (exp.X_op != O_constant)
972 {
973 as_bad (_("expected #constant"));
974 ignore_rest_of_line ();
975 return FAIL;
976 }
977 *val = exp.X_add_number;
978 return SUCCESS;
b99bd4ef 979}
c19d1205 980#endif
b99bd4ef 981
c19d1205 982/* Register parsing. */
b99bd4ef 983
c19d1205
ZW
984/* Generic register parser. CCP points to what should be the
985 beginning of a register name. If it is indeed a valid register
986 name, advance CCP over it and return the reg_entry structure;
987 otherwise return NULL. Does not issue diagnostics. */
988
989static struct reg_entry *
990arm_reg_parse_multi (char **ccp)
b99bd4ef 991{
c19d1205
ZW
992 char *start = *ccp;
993 char *p;
994 struct reg_entry *reg;
b99bd4ef 995
c19d1205
ZW
996#ifdef REGISTER_PREFIX
997 if (*start != REGISTER_PREFIX)
01cfc07f 998 return NULL;
c19d1205
ZW
999 start++;
1000#endif
1001#ifdef OPTIONAL_REGISTER_PREFIX
1002 if (*start == OPTIONAL_REGISTER_PREFIX)
1003 start++;
1004#endif
b99bd4ef 1005
c19d1205
ZW
1006 p = start;
1007 if (!ISALPHA (*p) || !is_name_beginner (*p))
1008 return NULL;
b99bd4ef 1009
c19d1205
ZW
1010 do
1011 p++;
1012 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1013
1014 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1015
1016 if (!reg)
1017 return NULL;
1018
1019 *ccp = p;
1020 return reg;
b99bd4ef
NC
1021}
1022
1023static int
dcbf9037
JB
1024arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1025 enum arm_reg_type type)
b99bd4ef 1026{
c19d1205
ZW
1027 /* Alternative syntaxes are accepted for a few register classes. */
1028 switch (type)
1029 {
1030 case REG_TYPE_MVF:
1031 case REG_TYPE_MVD:
1032 case REG_TYPE_MVFX:
1033 case REG_TYPE_MVDX:
1034 /* Generic coprocessor register names are allowed for these. */
79134647 1035 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1036 return reg->number;
1037 break;
69b97547 1038
c19d1205
ZW
1039 case REG_TYPE_CP:
1040 /* For backward compatibility, a bare number is valid here. */
1041 {
1042 unsigned long processor = strtoul (start, ccp, 10);
1043 if (*ccp != start && processor <= 15)
1044 return processor;
1045 }
6057a28f 1046
c19d1205
ZW
1047 case REG_TYPE_MMXWC:
1048 /* WC includes WCG. ??? I'm not sure this is true for all
1049 instructions that take WC registers. */
79134647 1050 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1051 return reg->number;
6057a28f 1052 break;
c19d1205 1053
6057a28f 1054 default:
c19d1205 1055 break;
6057a28f
NC
1056 }
1057
dcbf9037
JB
1058 return FAIL;
1059}
1060
1061/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1062 return value is the register number or FAIL. */
1063
1064static int
1065arm_reg_parse (char **ccp, enum arm_reg_type type)
1066{
1067 char *start = *ccp;
1068 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1069 int ret;
1070
1071 /* Do not allow a scalar (reg+index) to parse as a register. */
1072 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1073 return FAIL;
1074
1075 if (reg && reg->type == type)
1076 return reg->number;
1077
1078 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1079 return ret;
1080
c19d1205
ZW
1081 *ccp = start;
1082 return FAIL;
1083}
69b97547 1084
dcbf9037
JB
1085/* Parse a Neon type specifier. *STR should point at the leading '.'
1086 character. Does no verification at this stage that the type fits the opcode
1087 properly. E.g.,
1088
1089 .i32.i32.s16
1090 .s32.f32
1091 .u16
1092
1093 Can all be legally parsed by this function.
1094
1095 Fills in neon_type struct pointer with parsed information, and updates STR
1096 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1097 type, FAIL if not. */
1098
1099static int
1100parse_neon_type (struct neon_type *type, char **str)
1101{
1102 char *ptr = *str;
1103
1104 if (type)
1105 type->elems = 0;
1106
1107 while (type->elems < NEON_MAX_TYPE_ELS)
1108 {
1109 enum neon_el_type thistype = NT_untyped;
1110 unsigned thissize = -1u;
1111
1112 if (*ptr != '.')
1113 break;
1114
1115 ptr++;
1116
1117 /* Just a size without an explicit type. */
1118 if (ISDIGIT (*ptr))
1119 goto parsesize;
1120
1121 switch (TOLOWER (*ptr))
1122 {
1123 case 'i': thistype = NT_integer; break;
1124 case 'f': thistype = NT_float; break;
1125 case 'p': thistype = NT_poly; break;
1126 case 's': thistype = NT_signed; break;
1127 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1128 case 'd':
1129 thistype = NT_float;
1130 thissize = 64;
1131 ptr++;
1132 goto done;
dcbf9037
JB
1133 default:
1134 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1135 return FAIL;
1136 }
1137
1138 ptr++;
1139
1140 /* .f is an abbreviation for .f32. */
1141 if (thistype == NT_float && !ISDIGIT (*ptr))
1142 thissize = 32;
1143 else
1144 {
1145 parsesize:
1146 thissize = strtoul (ptr, &ptr, 10);
1147
1148 if (thissize != 8 && thissize != 16 && thissize != 32
1149 && thissize != 64)
1150 {
1151 as_bad (_("bad size %d in type specifier"), thissize);
1152 return FAIL;
1153 }
1154 }
1155
037e8744 1156 done:
dcbf9037
JB
1157 if (type)
1158 {
1159 type->el[type->elems].type = thistype;
1160 type->el[type->elems].size = thissize;
1161 type->elems++;
1162 }
1163 }
1164
1165 /* Empty/missing type is not a successful parse. */
1166 if (type->elems == 0)
1167 return FAIL;
1168
1169 *str = ptr;
1170
1171 return SUCCESS;
1172}
1173
1174/* Errors may be set multiple times during parsing or bit encoding
1175 (particularly in the Neon bits), but usually the earliest error which is set
1176 will be the most meaningful. Avoid overwriting it with later (cascading)
1177 errors by calling this function. */
1178
1179static void
1180first_error (const char *err)
1181{
1182 if (!inst.error)
1183 inst.error = err;
1184}
1185
1186/* Parse a single type, e.g. ".s32", leading period included. */
1187static int
1188parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1189{
1190 char *str = *ccp;
1191 struct neon_type optype;
1192
1193 if (*str == '.')
1194 {
1195 if (parse_neon_type (&optype, &str) == SUCCESS)
1196 {
1197 if (optype.elems == 1)
1198 *vectype = optype.el[0];
1199 else
1200 {
1201 first_error (_("only one type should be specified for operand"));
1202 return FAIL;
1203 }
1204 }
1205 else
1206 {
1207 first_error (_("vector type expected"));
1208 return FAIL;
1209 }
1210 }
1211 else
1212 return FAIL;
1213
1214 *ccp = str;
1215
1216 return SUCCESS;
1217}
1218
1219/* Special meanings for indices (which have a range of 0-7), which will fit into
1220 a 4-bit integer. */
1221
1222#define NEON_ALL_LANES 15
1223#define NEON_INTERLEAVE_LANES 14
1224
1225/* Parse either a register or a scalar, with an optional type. Return the
1226 register number, and optionally fill in the actual type of the register
1227 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1228 type/index information in *TYPEINFO. */
1229
1230static int
1231parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1232 enum arm_reg_type *rtype,
1233 struct neon_typed_alias *typeinfo)
1234{
1235 char *str = *ccp;
1236 struct reg_entry *reg = arm_reg_parse_multi (&str);
1237 struct neon_typed_alias atype;
1238 struct neon_type_el parsetype;
1239
1240 atype.defined = 0;
1241 atype.index = -1;
1242 atype.eltype.type = NT_invtype;
1243 atype.eltype.size = -1;
1244
1245 /* Try alternate syntax for some types of register. Note these are mutually
1246 exclusive with the Neon syntax extensions. */
1247 if (reg == NULL)
1248 {
1249 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1250 if (altreg != FAIL)
1251 *ccp = str;
1252 if (typeinfo)
1253 *typeinfo = atype;
1254 return altreg;
1255 }
1256
037e8744
JB
1257 /* Undo polymorphism when a set of register types may be accepted. */
1258 if ((type == REG_TYPE_NDQ
1259 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1260 || (type == REG_TYPE_VFSD
1261 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1262 || (type == REG_TYPE_NSDQ
1263 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
1264 || reg->type == REG_TYPE_NQ)))
dcbf9037
JB
1265 type = reg->type;
1266
1267 if (type != reg->type)
1268 return FAIL;
1269
1270 if (reg->neon)
1271 atype = *reg->neon;
1272
1273 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1274 {
1275 if ((atype.defined & NTA_HASTYPE) != 0)
1276 {
1277 first_error (_("can't redefine type for operand"));
1278 return FAIL;
1279 }
1280 atype.defined |= NTA_HASTYPE;
1281 atype.eltype = parsetype;
1282 }
1283
1284 if (skip_past_char (&str, '[') == SUCCESS)
1285 {
1286 if (type != REG_TYPE_VFD)
1287 {
1288 first_error (_("only D registers may be indexed"));
1289 return FAIL;
1290 }
1291
1292 if ((atype.defined & NTA_HASINDEX) != 0)
1293 {
1294 first_error (_("can't change index for operand"));
1295 return FAIL;
1296 }
1297
1298 atype.defined |= NTA_HASINDEX;
1299
1300 if (skip_past_char (&str, ']') == SUCCESS)
1301 atype.index = NEON_ALL_LANES;
1302 else
1303 {
1304 expressionS exp;
1305
1306 my_get_expression (&exp, &str, GE_NO_PREFIX);
1307
1308 if (exp.X_op != O_constant)
1309 {
1310 first_error (_("constant expression required"));
1311 return FAIL;
1312 }
1313
1314 if (skip_past_char (&str, ']') == FAIL)
1315 return FAIL;
1316
1317 atype.index = exp.X_add_number;
1318 }
1319 }
1320
1321 if (typeinfo)
1322 *typeinfo = atype;
1323
1324 if (rtype)
1325 *rtype = type;
1326
1327 *ccp = str;
1328
1329 return reg->number;
1330}
1331
1332/* Like arm_reg_parse, but allow allow the following extra features:
1333 - If RTYPE is non-zero, return the (possibly restricted) type of the
1334 register (e.g. Neon double or quad reg when either has been requested).
1335 - If this is a Neon vector type with additional type information, fill
1336 in the struct pointed to by VECTYPE (if non-NULL).
1337 This function will fault on encountering a scalar.
1338*/
1339
1340static int
1341arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1342 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1343{
1344 struct neon_typed_alias atype;
1345 char *str = *ccp;
1346 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1347
1348 if (reg == FAIL)
1349 return FAIL;
1350
1351 /* Do not allow a scalar (reg+index) to parse as a register. */
1352 if ((atype.defined & NTA_HASINDEX) != 0)
1353 {
1354 first_error (_("register operand expected, but got scalar"));
1355 return FAIL;
1356 }
1357
1358 if (vectype)
1359 *vectype = atype.eltype;
1360
1361 *ccp = str;
1362
1363 return reg;
1364}
1365
1366#define NEON_SCALAR_REG(X) ((X) >> 4)
1367#define NEON_SCALAR_INDEX(X) ((X) & 15)
1368
5287ad62
JB
1369/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1370 have enough information to be able to do a good job bounds-checking. So, we
1371 just do easy checks here, and do further checks later. */
1372
1373static int
dcbf9037 1374parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1375{
dcbf9037 1376 int reg;
5287ad62 1377 char *str = *ccp;
dcbf9037 1378 struct neon_typed_alias atype;
5287ad62 1379
dcbf9037 1380 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5287ad62 1381
dcbf9037 1382 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62
JB
1383 return FAIL;
1384
dcbf9037 1385 if (atype.index == NEON_ALL_LANES)
5287ad62 1386 {
dcbf9037 1387 first_error (_("scalar must have an index"));
5287ad62
JB
1388 return FAIL;
1389 }
dcbf9037 1390 else if (atype.index >= 64 / elsize)
5287ad62 1391 {
dcbf9037 1392 first_error (_("scalar index out of range"));
5287ad62
JB
1393 return FAIL;
1394 }
1395
dcbf9037
JB
1396 if (type)
1397 *type = atype.eltype;
5287ad62 1398
5287ad62
JB
1399 *ccp = str;
1400
dcbf9037 1401 return reg * 16 + atype.index;
5287ad62
JB
1402}
1403
c19d1205
ZW
1404/* Parse an ARM register list. Returns the bitmask, or FAIL. */
1405static long
1406parse_reg_list (char ** strp)
1407{
1408 char * str = * strp;
1409 long range = 0;
1410 int another_range;
a737bd4d 1411
c19d1205
ZW
1412 /* We come back here if we get ranges concatenated by '+' or '|'. */
1413 do
6057a28f 1414 {
c19d1205 1415 another_range = 0;
a737bd4d 1416
c19d1205
ZW
1417 if (*str == '{')
1418 {
1419 int in_range = 0;
1420 int cur_reg = -1;
a737bd4d 1421
c19d1205
ZW
1422 str++;
1423 do
1424 {
1425 int reg;
6057a28f 1426
dcbf9037 1427 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1428 {
dcbf9037 1429 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1430 return FAIL;
1431 }
a737bd4d 1432
c19d1205
ZW
1433 if (in_range)
1434 {
1435 int i;
a737bd4d 1436
c19d1205
ZW
1437 if (reg <= cur_reg)
1438 {
dcbf9037 1439 first_error (_("bad range in register list"));
c19d1205
ZW
1440 return FAIL;
1441 }
40a18ebd 1442
c19d1205
ZW
1443 for (i = cur_reg + 1; i < reg; i++)
1444 {
1445 if (range & (1 << i))
1446 as_tsktsk
1447 (_("Warning: duplicated register (r%d) in register list"),
1448 i);
1449 else
1450 range |= 1 << i;
1451 }
1452 in_range = 0;
1453 }
a737bd4d 1454
c19d1205
ZW
1455 if (range & (1 << reg))
1456 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1457 reg);
1458 else if (reg <= cur_reg)
1459 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1460
c19d1205
ZW
1461 range |= 1 << reg;
1462 cur_reg = reg;
1463 }
1464 while (skip_past_comma (&str) != FAIL
1465 || (in_range = 1, *str++ == '-'));
1466 str--;
a737bd4d 1467
c19d1205
ZW
1468 if (*str++ != '}')
1469 {
dcbf9037 1470 first_error (_("missing `}'"));
c19d1205
ZW
1471 return FAIL;
1472 }
1473 }
1474 else
1475 {
1476 expressionS expr;
40a18ebd 1477
c19d1205
ZW
1478 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1479 return FAIL;
40a18ebd 1480
c19d1205
ZW
1481 if (expr.X_op == O_constant)
1482 {
1483 if (expr.X_add_number
1484 != (expr.X_add_number & 0x0000ffff))
1485 {
1486 inst.error = _("invalid register mask");
1487 return FAIL;
1488 }
a737bd4d 1489
c19d1205
ZW
1490 if ((range & expr.X_add_number) != 0)
1491 {
1492 int regno = range & expr.X_add_number;
a737bd4d 1493
c19d1205
ZW
1494 regno &= -regno;
1495 regno = (1 << regno) - 1;
1496 as_tsktsk
1497 (_("Warning: duplicated register (r%d) in register list"),
1498 regno);
1499 }
a737bd4d 1500
c19d1205
ZW
1501 range |= expr.X_add_number;
1502 }
1503 else
1504 {
1505 if (inst.reloc.type != 0)
1506 {
1507 inst.error = _("expression too complex");
1508 return FAIL;
1509 }
a737bd4d 1510
c19d1205
ZW
1511 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1512 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1513 inst.reloc.pc_rel = 0;
1514 }
1515 }
a737bd4d 1516
c19d1205
ZW
1517 if (*str == '|' || *str == '+')
1518 {
1519 str++;
1520 another_range = 1;
1521 }
a737bd4d 1522 }
c19d1205 1523 while (another_range);
a737bd4d 1524
c19d1205
ZW
1525 *strp = str;
1526 return range;
a737bd4d
NC
1527}
1528
5287ad62
JB
1529/* Types of registers in a list. */
1530
1531enum reg_list_els
1532{
1533 REGLIST_VFP_S,
1534 REGLIST_VFP_D,
1535 REGLIST_NEON_D
1536};
1537
c19d1205
ZW
1538/* Parse a VFP register list. If the string is invalid return FAIL.
1539 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1540 register. Parses registers of type ETYPE.
1541 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1542 - Q registers can be used to specify pairs of D registers
1543 - { } can be omitted from around a singleton register list
1544 FIXME: This is not implemented, as it would require backtracking in
1545 some cases, e.g.:
1546 vtbl.8 d3,d4,d5
1547 This could be done (the meaning isn't really ambiguous), but doesn't
1548 fit in well with the current parsing framework.
dcbf9037
JB
1549 - 32 D registers may be used (also true for VFPv3).
1550 FIXME: Types are ignored in these register lists, which is probably a
1551 bug. */
6057a28f 1552
c19d1205 1553static int
037e8744 1554parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1555{
037e8744 1556 char *str = *ccp;
c19d1205
ZW
1557 int base_reg;
1558 int new_base;
5287ad62
JB
1559 enum arm_reg_type regtype = 0;
1560 int max_regs = 0;
c19d1205
ZW
1561 int count = 0;
1562 int warned = 0;
1563 unsigned long mask = 0;
a737bd4d 1564 int i;
6057a28f 1565
037e8744 1566 if (*str != '{')
5287ad62
JB
1567 {
1568 inst.error = _("expecting {");
1569 return FAIL;
1570 }
6057a28f 1571
037e8744 1572 str++;
6057a28f 1573
5287ad62 1574 switch (etype)
c19d1205 1575 {
5287ad62 1576 case REGLIST_VFP_S:
c19d1205
ZW
1577 regtype = REG_TYPE_VFS;
1578 max_regs = 32;
5287ad62
JB
1579 break;
1580
1581 case REGLIST_VFP_D:
1582 regtype = REG_TYPE_VFD;
b7fc2769
JB
1583 break;
1584
1585 case REGLIST_NEON_D:
1586 regtype = REG_TYPE_NDQ;
1587 break;
1588 }
1589
1590 if (etype != REGLIST_VFP_S)
1591 {
5287ad62
JB
1592 /* VFPv3 allows 32 D registers. */
1593 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
1594 {
1595 max_regs = 32;
1596 if (thumb_mode)
1597 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1598 fpu_vfp_ext_v3);
1599 else
1600 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1601 fpu_vfp_ext_v3);
1602 }
1603 else
1604 max_regs = 16;
c19d1205 1605 }
6057a28f 1606
c19d1205 1607 base_reg = max_regs;
a737bd4d 1608
c19d1205
ZW
1609 do
1610 {
5287ad62 1611 int setmask = 1, addregs = 1;
dcbf9037 1612
037e8744 1613 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1614
c19d1205 1615 if (new_base == FAIL)
a737bd4d 1616 {
dcbf9037 1617 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1618 return FAIL;
1619 }
dcbf9037 1620
b7fc2769
JB
1621 if (new_base >= max_regs)
1622 {
1623 first_error (_("register out of range in list"));
1624 return FAIL;
1625 }
1626
5287ad62
JB
1627 /* Note: a value of 2 * n is returned for the register Q<n>. */
1628 if (regtype == REG_TYPE_NQ)
1629 {
1630 setmask = 3;
1631 addregs = 2;
1632 }
1633
c19d1205
ZW
1634 if (new_base < base_reg)
1635 base_reg = new_base;
a737bd4d 1636
5287ad62 1637 if (mask & (setmask << new_base))
c19d1205 1638 {
dcbf9037 1639 first_error (_("invalid register list"));
c19d1205 1640 return FAIL;
a737bd4d 1641 }
a737bd4d 1642
c19d1205
ZW
1643 if ((mask >> new_base) != 0 && ! warned)
1644 {
1645 as_tsktsk (_("register list not in ascending order"));
1646 warned = 1;
1647 }
0bbf2aa4 1648
5287ad62
JB
1649 mask |= setmask << new_base;
1650 count += addregs;
0bbf2aa4 1651
037e8744 1652 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1653 {
1654 int high_range;
0bbf2aa4 1655
037e8744 1656 str++;
0bbf2aa4 1657
037e8744 1658 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1659 == FAIL)
c19d1205
ZW
1660 {
1661 inst.error = gettext (reg_expected_msgs[regtype]);
1662 return FAIL;
1663 }
0bbf2aa4 1664
b7fc2769
JB
1665 if (high_range >= max_regs)
1666 {
1667 first_error (_("register out of range in list"));
1668 return FAIL;
1669 }
1670
5287ad62
JB
1671 if (regtype == REG_TYPE_NQ)
1672 high_range = high_range + 1;
1673
c19d1205
ZW
1674 if (high_range <= new_base)
1675 {
1676 inst.error = _("register range not in ascending order");
1677 return FAIL;
1678 }
0bbf2aa4 1679
5287ad62 1680 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1681 {
5287ad62 1682 if (mask & (setmask << new_base))
0bbf2aa4 1683 {
c19d1205
ZW
1684 inst.error = _("invalid register list");
1685 return FAIL;
0bbf2aa4 1686 }
c19d1205 1687
5287ad62
JB
1688 mask |= setmask << new_base;
1689 count += addregs;
0bbf2aa4 1690 }
0bbf2aa4 1691 }
0bbf2aa4 1692 }
037e8744 1693 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1694
037e8744 1695 str++;
0bbf2aa4 1696
c19d1205
ZW
1697 /* Sanity check -- should have raised a parse error above. */
1698 if (count == 0 || count > max_regs)
1699 abort ();
1700
1701 *pbase = base_reg;
1702
1703 /* Final test -- the registers must be consecutive. */
1704 mask >>= base_reg;
1705 for (i = 0; i < count; i++)
1706 {
1707 if ((mask & (1u << i)) == 0)
1708 {
1709 inst.error = _("non-contiguous register range");
1710 return FAIL;
1711 }
1712 }
1713
037e8744
JB
1714 *ccp = str;
1715
c19d1205 1716 return count;
b99bd4ef
NC
1717}
1718
dcbf9037
JB
1719/* True if two alias types are the same. */
1720
1721static int
1722neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1723{
1724 if (!a && !b)
1725 return 1;
1726
1727 if (!a || !b)
1728 return 0;
1729
1730 if (a->defined != b->defined)
1731 return 0;
1732
1733 if ((a->defined & NTA_HASTYPE) != 0
1734 && (a->eltype.type != b->eltype.type
1735 || a->eltype.size != b->eltype.size))
1736 return 0;
1737
1738 if ((a->defined & NTA_HASINDEX) != 0
1739 && (a->index != b->index))
1740 return 0;
1741
1742 return 1;
1743}
1744
5287ad62
JB
1745/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1746 The base register is put in *PBASE.
dcbf9037 1747 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1748 the return value.
1749 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1750 Bits [6:5] encode the list length (minus one).
1751 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1752
5287ad62 1753#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1754#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1755#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1756
1757static int
dcbf9037
JB
1758parse_neon_el_struct_list (char **str, unsigned *pbase,
1759 struct neon_type_el *eltype)
5287ad62
JB
1760{
1761 char *ptr = *str;
1762 int base_reg = -1;
1763 int reg_incr = -1;
1764 int count = 0;
1765 int lane = -1;
1766 int leading_brace = 0;
1767 enum arm_reg_type rtype = REG_TYPE_NDQ;
1768 int addregs = 1;
1769 const char *const incr_error = "register stride must be 1 or 2";
1770 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1771 struct neon_typed_alias firsttype;
5287ad62
JB
1772
1773 if (skip_past_char (&ptr, '{') == SUCCESS)
1774 leading_brace = 1;
1775
1776 do
1777 {
dcbf9037
JB
1778 struct neon_typed_alias atype;
1779 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1780
5287ad62
JB
1781 if (getreg == FAIL)
1782 {
dcbf9037 1783 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1784 return FAIL;
1785 }
1786
1787 if (base_reg == -1)
1788 {
1789 base_reg = getreg;
1790 if (rtype == REG_TYPE_NQ)
1791 {
1792 reg_incr = 1;
1793 addregs = 2;
1794 }
dcbf9037 1795 firsttype = atype;
5287ad62
JB
1796 }
1797 else if (reg_incr == -1)
1798 {
1799 reg_incr = getreg - base_reg;
1800 if (reg_incr < 1 || reg_incr > 2)
1801 {
dcbf9037 1802 first_error (_(incr_error));
5287ad62
JB
1803 return FAIL;
1804 }
1805 }
1806 else if (getreg != base_reg + reg_incr * count)
1807 {
dcbf9037
JB
1808 first_error (_(incr_error));
1809 return FAIL;
1810 }
1811
1812 if (!neon_alias_types_same (&atype, &firsttype))
1813 {
1814 first_error (_(type_error));
5287ad62
JB
1815 return FAIL;
1816 }
1817
1818 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1819 modes. */
1820 if (ptr[0] == '-')
1821 {
dcbf9037 1822 struct neon_typed_alias htype;
5287ad62
JB
1823 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1824 if (lane == -1)
1825 lane = NEON_INTERLEAVE_LANES;
1826 else if (lane != NEON_INTERLEAVE_LANES)
1827 {
dcbf9037 1828 first_error (_(type_error));
5287ad62
JB
1829 return FAIL;
1830 }
1831 if (reg_incr == -1)
1832 reg_incr = 1;
1833 else if (reg_incr != 1)
1834 {
dcbf9037 1835 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1836 return FAIL;
1837 }
1838 ptr++;
dcbf9037 1839 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1840 if (hireg == FAIL)
1841 {
dcbf9037
JB
1842 first_error (_(reg_expected_msgs[rtype]));
1843 return FAIL;
1844 }
1845 if (!neon_alias_types_same (&htype, &firsttype))
1846 {
1847 first_error (_(type_error));
5287ad62
JB
1848 return FAIL;
1849 }
1850 count += hireg + dregs - getreg;
1851 continue;
1852 }
1853
1854 /* If we're using Q registers, we can't use [] or [n] syntax. */
1855 if (rtype == REG_TYPE_NQ)
1856 {
1857 count += 2;
1858 continue;
1859 }
1860
dcbf9037 1861 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1862 {
dcbf9037
JB
1863 if (lane == -1)
1864 lane = atype.index;
1865 else if (lane != atype.index)
5287ad62 1866 {
dcbf9037
JB
1867 first_error (_(type_error));
1868 return FAIL;
5287ad62
JB
1869 }
1870 }
1871 else if (lane == -1)
1872 lane = NEON_INTERLEAVE_LANES;
1873 else if (lane != NEON_INTERLEAVE_LANES)
1874 {
dcbf9037 1875 first_error (_(type_error));
5287ad62
JB
1876 return FAIL;
1877 }
1878 count++;
1879 }
1880 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1881
1882 /* No lane set by [x]. We must be interleaving structures. */
1883 if (lane == -1)
1884 lane = NEON_INTERLEAVE_LANES;
1885
1886 /* Sanity check. */
1887 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1888 || (count > 1 && reg_incr == -1))
1889 {
dcbf9037 1890 first_error (_("error parsing element/structure list"));
5287ad62
JB
1891 return FAIL;
1892 }
1893
1894 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1895 {
dcbf9037 1896 first_error (_("expected }"));
5287ad62
JB
1897 return FAIL;
1898 }
1899
1900 if (reg_incr == -1)
1901 reg_incr = 1;
1902
dcbf9037
JB
1903 if (eltype)
1904 *eltype = firsttype.eltype;
1905
5287ad62
JB
1906 *pbase = base_reg;
1907 *str = ptr;
1908
1909 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
1910}
1911
c19d1205
ZW
1912/* Parse an explicit relocation suffix on an expression. This is
1913 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
1914 arm_reloc_hsh contains no entries, so this function can only
1915 succeed if there is no () after the word. Returns -1 on error,
1916 BFD_RELOC_UNUSED if there wasn't any suffix. */
1917static int
1918parse_reloc (char **str)
b99bd4ef 1919{
c19d1205
ZW
1920 struct reloc_entry *r;
1921 char *p, *q;
b99bd4ef 1922
c19d1205
ZW
1923 if (**str != '(')
1924 return BFD_RELOC_UNUSED;
b99bd4ef 1925
c19d1205
ZW
1926 p = *str + 1;
1927 q = p;
1928
1929 while (*q && *q != ')' && *q != ',')
1930 q++;
1931 if (*q != ')')
1932 return -1;
1933
1934 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
1935 return -1;
1936
1937 *str = q + 1;
1938 return r->reloc;
b99bd4ef
NC
1939}
1940
c19d1205
ZW
1941/* Directives: register aliases. */
1942
dcbf9037 1943static struct reg_entry *
c19d1205 1944insert_reg_alias (char *str, int number, int type)
b99bd4ef 1945{
c19d1205
ZW
1946 struct reg_entry *new;
1947 const char *name;
b99bd4ef 1948
c19d1205
ZW
1949 if ((new = hash_find (arm_reg_hsh, str)) != 0)
1950 {
1951 if (new->builtin)
1952 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 1953
c19d1205
ZW
1954 /* Only warn about a redefinition if it's not defined as the
1955 same register. */
1956 else if (new->number != number || new->type != type)
1957 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 1958
dcbf9037 1959 return 0;
c19d1205 1960 }
b99bd4ef 1961
c19d1205
ZW
1962 name = xstrdup (str);
1963 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 1964
c19d1205
ZW
1965 new->name = name;
1966 new->number = number;
1967 new->type = type;
1968 new->builtin = FALSE;
dcbf9037 1969 new->neon = NULL;
b99bd4ef 1970
c19d1205
ZW
1971 if (hash_insert (arm_reg_hsh, name, (PTR) new))
1972 abort ();
dcbf9037
JB
1973
1974 return new;
1975}
1976
1977static void
1978insert_neon_reg_alias (char *str, int number, int type,
1979 struct neon_typed_alias *atype)
1980{
1981 struct reg_entry *reg = insert_reg_alias (str, number, type);
1982
1983 if (!reg)
1984 {
1985 first_error (_("attempt to redefine typed alias"));
1986 return;
1987 }
1988
1989 if (atype)
1990 {
1991 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
1992 *reg->neon = *atype;
1993 }
c19d1205 1994}
b99bd4ef 1995
c19d1205 1996/* Look for the .req directive. This is of the form:
b99bd4ef 1997
c19d1205 1998 new_register_name .req existing_register_name
b99bd4ef 1999
c19d1205
ZW
2000 If we find one, or if it looks sufficiently like one that we want to
2001 handle any error here, return non-zero. Otherwise return zero. */
b99bd4ef 2002
c19d1205
ZW
2003static int
2004create_register_alias (char * newname, char *p)
2005{
2006 struct reg_entry *old;
2007 char *oldname, *nbuf;
2008 size_t nlen;
b99bd4ef 2009
c19d1205
ZW
2010 /* The input scrubber ensures that whitespace after the mnemonic is
2011 collapsed to single spaces. */
2012 oldname = p;
2013 if (strncmp (oldname, " .req ", 6) != 0)
2014 return 0;
b99bd4ef 2015
c19d1205
ZW
2016 oldname += 6;
2017 if (*oldname == '\0')
2018 return 0;
b99bd4ef 2019
c19d1205
ZW
2020 old = hash_find (arm_reg_hsh, oldname);
2021 if (!old)
b99bd4ef 2022 {
c19d1205
ZW
2023 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2024 return 1;
b99bd4ef
NC
2025 }
2026
c19d1205
ZW
2027 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2028 the desired alias name, and p points to its end. If not, then
2029 the desired alias name is in the global original_case_string. */
2030#ifdef TC_CASE_SENSITIVE
2031 nlen = p - newname;
2032#else
2033 newname = original_case_string;
2034 nlen = strlen (newname);
2035#endif
b99bd4ef 2036
c19d1205
ZW
2037 nbuf = alloca (nlen + 1);
2038 memcpy (nbuf, newname, nlen);
2039 nbuf[nlen] = '\0';
b99bd4ef 2040
c19d1205
ZW
2041 /* Create aliases under the new name as stated; an all-lowercase
2042 version of the new name; and an all-uppercase version of the new
2043 name. */
2044 insert_reg_alias (nbuf, old->number, old->type);
b99bd4ef 2045
c19d1205
ZW
2046 for (p = nbuf; *p; p++)
2047 *p = TOUPPER (*p);
2048
2049 if (strncmp (nbuf, newname, nlen))
2050 insert_reg_alias (nbuf, old->number, old->type);
2051
2052 for (p = nbuf; *p; p++)
2053 *p = TOLOWER (*p);
2054
2055 if (strncmp (nbuf, newname, nlen))
2056 insert_reg_alias (nbuf, old->number, old->type);
2057
2058 return 1;
b99bd4ef
NC
2059}
2060
dcbf9037
JB
2061/* Create a Neon typed/indexed register alias using directives, e.g.:
2062 X .dn d5.s32[1]
2063 Y .qn 6.s16
2064 Z .dn d7
2065 T .dn Z[0]
2066 These typed registers can be used instead of the types specified after the
2067 Neon mnemonic, so long as all operands given have types. Types can also be
2068 specified directly, e.g.:
2069 vadd d0.s32, d1.s32, d2.s32
2070*/
2071
2072static int
2073create_neon_reg_alias (char *newname, char *p)
2074{
2075 enum arm_reg_type basetype;
2076 struct reg_entry *basereg;
2077 struct reg_entry mybasereg;
2078 struct neon_type ntype;
2079 struct neon_typed_alias typeinfo;
2080 char *namebuf, *nameend;
2081 int namelen;
2082
2083 typeinfo.defined = 0;
2084 typeinfo.eltype.type = NT_invtype;
2085 typeinfo.eltype.size = -1;
2086 typeinfo.index = -1;
2087
2088 nameend = p;
2089
2090 if (strncmp (p, " .dn ", 5) == 0)
2091 basetype = REG_TYPE_VFD;
2092 else if (strncmp (p, " .qn ", 5) == 0)
2093 basetype = REG_TYPE_NQ;
2094 else
2095 return 0;
2096
2097 p += 5;
2098
2099 if (*p == '\0')
2100 return 0;
2101
2102 basereg = arm_reg_parse_multi (&p);
2103
2104 if (basereg && basereg->type != basetype)
2105 {
2106 as_bad (_("bad type for register"));
2107 return 0;
2108 }
2109
2110 if (basereg == NULL)
2111 {
2112 expressionS exp;
2113 /* Try parsing as an integer. */
2114 my_get_expression (&exp, &p, GE_NO_PREFIX);
2115 if (exp.X_op != O_constant)
2116 {
2117 as_bad (_("expression must be constant"));
2118 return 0;
2119 }
2120 basereg = &mybasereg;
2121 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2122 : exp.X_add_number;
2123 basereg->neon = 0;
2124 }
2125
2126 if (basereg->neon)
2127 typeinfo = *basereg->neon;
2128
2129 if (parse_neon_type (&ntype, &p) == SUCCESS)
2130 {
2131 /* We got a type. */
2132 if (typeinfo.defined & NTA_HASTYPE)
2133 {
2134 as_bad (_("can't redefine the type of a register alias"));
2135 return 0;
2136 }
2137
2138 typeinfo.defined |= NTA_HASTYPE;
2139 if (ntype.elems != 1)
2140 {
2141 as_bad (_("you must specify a single type only"));
2142 return 0;
2143 }
2144 typeinfo.eltype = ntype.el[0];
2145 }
2146
2147 if (skip_past_char (&p, '[') == SUCCESS)
2148 {
2149 expressionS exp;
2150 /* We got a scalar index. */
2151
2152 if (typeinfo.defined & NTA_HASINDEX)
2153 {
2154 as_bad (_("can't redefine the index of a scalar alias"));
2155 return 0;
2156 }
2157
2158 my_get_expression (&exp, &p, GE_NO_PREFIX);
2159
2160 if (exp.X_op != O_constant)
2161 {
2162 as_bad (_("scalar index must be constant"));
2163 return 0;
2164 }
2165
2166 typeinfo.defined |= NTA_HASINDEX;
2167 typeinfo.index = exp.X_add_number;
2168
2169 if (skip_past_char (&p, ']') == FAIL)
2170 {
2171 as_bad (_("expecting ]"));
2172 return 0;
2173 }
2174 }
2175
2176 namelen = nameend - newname;
2177 namebuf = alloca (namelen + 1);
2178 strncpy (namebuf, newname, namelen);
2179 namebuf[namelen] = '\0';
2180
2181 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2182 typeinfo.defined != 0 ? &typeinfo : NULL);
2183
2184 /* Insert name in all uppercase. */
2185 for (p = namebuf; *p; p++)
2186 *p = TOUPPER (*p);
2187
2188 if (strncmp (namebuf, newname, namelen))
2189 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2190 typeinfo.defined != 0 ? &typeinfo : NULL);
2191
2192 /* Insert name in all lowercase. */
2193 for (p = namebuf; *p; p++)
2194 *p = TOLOWER (*p);
2195
2196 if (strncmp (namebuf, newname, namelen))
2197 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2198 typeinfo.defined != 0 ? &typeinfo : NULL);
2199
2200 return 1;
2201}
2202
c19d1205
ZW
2203/* Should never be called, as .req goes between the alias and the
2204 register name, not at the beginning of the line. */
b99bd4ef 2205static void
c19d1205 2206s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2207{
c19d1205
ZW
2208 as_bad (_("invalid syntax for .req directive"));
2209}
b99bd4ef 2210
dcbf9037
JB
2211static void
2212s_dn (int a ATTRIBUTE_UNUSED)
2213{
2214 as_bad (_("invalid syntax for .dn directive"));
2215}
2216
2217static void
2218s_qn (int a ATTRIBUTE_UNUSED)
2219{
2220 as_bad (_("invalid syntax for .qn directive"));
2221}
2222
c19d1205
ZW
2223/* The .unreq directive deletes an alias which was previously defined
2224 by .req. For example:
b99bd4ef 2225
c19d1205
ZW
2226 my_alias .req r11
2227 .unreq my_alias */
b99bd4ef
NC
2228
2229static void
c19d1205 2230s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2231{
c19d1205
ZW
2232 char * name;
2233 char saved_char;
b99bd4ef 2234
c19d1205
ZW
2235 name = input_line_pointer;
2236
2237 while (*input_line_pointer != 0
2238 && *input_line_pointer != ' '
2239 && *input_line_pointer != '\n')
2240 ++input_line_pointer;
2241
2242 saved_char = *input_line_pointer;
2243 *input_line_pointer = 0;
2244
2245 if (!*name)
2246 as_bad (_("invalid syntax for .unreq directive"));
2247 else
2248 {
2249 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2250
2251 if (!reg)
2252 as_bad (_("unknown register alias '%s'"), name);
2253 else if (reg->builtin)
2254 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2255 name);
2256 else
2257 {
2258 hash_delete (arm_reg_hsh, name);
2259 free ((char *) reg->name);
dcbf9037
JB
2260 if (reg->neon)
2261 free (reg->neon);
c19d1205
ZW
2262 free (reg);
2263 }
2264 }
b99bd4ef 2265
c19d1205 2266 *input_line_pointer = saved_char;
b99bd4ef
NC
2267 demand_empty_rest_of_line ();
2268}
2269
c19d1205
ZW
2270/* Directives: Instruction set selection. */
2271
2272#ifdef OBJ_ELF
2273/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2274 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2275 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2276 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2277
2278static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef
NC
2279
2280static void
c19d1205 2281mapping_state (enum mstate state)
b99bd4ef 2282{
a737bd4d 2283 symbolS * symbolP;
c19d1205
ZW
2284 const char * symname;
2285 int type;
b99bd4ef 2286
c19d1205
ZW
2287 if (mapstate == state)
2288 /* The mapping symbol has already been emitted.
2289 There is nothing else to do. */
2290 return;
b99bd4ef 2291
c19d1205 2292 mapstate = state;
b99bd4ef 2293
c19d1205 2294 switch (state)
b99bd4ef 2295 {
c19d1205
ZW
2296 case MAP_DATA:
2297 symname = "$d";
2298 type = BSF_NO_FLAGS;
2299 break;
2300 case MAP_ARM:
2301 symname = "$a";
2302 type = BSF_NO_FLAGS;
2303 break;
2304 case MAP_THUMB:
2305 symname = "$t";
2306 type = BSF_NO_FLAGS;
2307 break;
2308 case MAP_UNDEFINED:
2309 return;
2310 default:
2311 abort ();
2312 }
2313
2314 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2315
2316 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2317 symbol_table_insert (symbolP);
2318 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2319
2320 switch (state)
2321 {
2322 case MAP_ARM:
2323 THUMB_SET_FUNC (symbolP, 0);
2324 ARM_SET_THUMB (symbolP, 0);
2325 ARM_SET_INTERWORK (symbolP, support_interwork);
2326 break;
2327
2328 case MAP_THUMB:
2329 THUMB_SET_FUNC (symbolP, 1);
2330 ARM_SET_THUMB (symbolP, 1);
2331 ARM_SET_INTERWORK (symbolP, support_interwork);
2332 break;
2333
2334 case MAP_DATA:
2335 default:
2336 return;
2337 }
2338}
2339#else
2340#define mapping_state(x) /* nothing */
2341#endif
2342
2343/* Find the real, Thumb encoded start of a Thumb function. */
2344
2345static symbolS *
2346find_real_start (symbolS * symbolP)
2347{
2348 char * real_start;
2349 const char * name = S_GET_NAME (symbolP);
2350 symbolS * new_target;
2351
2352 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2353#define STUB_NAME ".real_start_of"
2354
2355 if (name == NULL)
2356 abort ();
2357
37f6032b
ZW
2358 /* The compiler may generate BL instructions to local labels because
2359 it needs to perform a branch to a far away location. These labels
2360 do not have a corresponding ".real_start_of" label. We check
2361 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2362 the ".real_start_of" convention for nonlocal branches. */
2363 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2364 return symbolP;
2365
37f6032b 2366 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2367 new_target = symbol_find (real_start);
2368
2369 if (new_target == NULL)
2370 {
2371 as_warn ("Failed to find real start of function: %s\n", name);
2372 new_target = symbolP;
2373 }
2374
c19d1205
ZW
2375 return new_target;
2376}
2377
2378static void
2379opcode_select (int width)
2380{
2381 switch (width)
2382 {
2383 case 16:
2384 if (! thumb_mode)
2385 {
e74cfd16 2386 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2387 as_bad (_("selected processor does not support THUMB opcodes"));
2388
2389 thumb_mode = 1;
2390 /* No need to force the alignment, since we will have been
2391 coming from ARM mode, which is word-aligned. */
2392 record_alignment (now_seg, 1);
2393 }
2394 mapping_state (MAP_THUMB);
2395 break;
2396
2397 case 32:
2398 if (thumb_mode)
2399 {
e74cfd16 2400 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2401 as_bad (_("selected processor does not support ARM opcodes"));
2402
2403 thumb_mode = 0;
2404
2405 if (!need_pass_2)
2406 frag_align (2, 0, 0);
2407
2408 record_alignment (now_seg, 1);
2409 }
2410 mapping_state (MAP_ARM);
2411 break;
2412
2413 default:
2414 as_bad (_("invalid instruction size selected (%d)"), width);
2415 }
2416}
2417
2418static void
2419s_arm (int ignore ATTRIBUTE_UNUSED)
2420{
2421 opcode_select (32);
2422 demand_empty_rest_of_line ();
2423}
2424
2425static void
2426s_thumb (int ignore ATTRIBUTE_UNUSED)
2427{
2428 opcode_select (16);
2429 demand_empty_rest_of_line ();
2430}
2431
2432static void
2433s_code (int unused ATTRIBUTE_UNUSED)
2434{
2435 int temp;
2436
2437 temp = get_absolute_expression ();
2438 switch (temp)
2439 {
2440 case 16:
2441 case 32:
2442 opcode_select (temp);
2443 break;
2444
2445 default:
2446 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2447 }
2448}
2449
2450static void
2451s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2452{
2453 /* If we are not already in thumb mode go into it, EVEN if
2454 the target processor does not support thumb instructions.
2455 This is used by gcc/config/arm/lib1funcs.asm for example
2456 to compile interworking support functions even if the
2457 target processor should not support interworking. */
2458 if (! thumb_mode)
2459 {
2460 thumb_mode = 2;
2461 record_alignment (now_seg, 1);
2462 }
2463
2464 demand_empty_rest_of_line ();
2465}
2466
2467static void
2468s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2469{
2470 s_thumb (0);
2471
2472 /* The following label is the name/address of the start of a Thumb function.
2473 We need to know this for the interworking support. */
2474 label_is_thumb_function_name = TRUE;
2475}
2476
2477/* Perform a .set directive, but also mark the alias as
2478 being a thumb function. */
2479
2480static void
2481s_thumb_set (int equiv)
2482{
2483 /* XXX the following is a duplicate of the code for s_set() in read.c
2484 We cannot just call that code as we need to get at the symbol that
2485 is created. */
2486 char * name;
2487 char delim;
2488 char * end_name;
2489 symbolS * symbolP;
2490
2491 /* Especial apologies for the random logic:
2492 This just grew, and could be parsed much more simply!
2493 Dean - in haste. */
2494 name = input_line_pointer;
2495 delim = get_symbol_end ();
2496 end_name = input_line_pointer;
2497 *end_name = delim;
2498
2499 if (*input_line_pointer != ',')
2500 {
2501 *end_name = 0;
2502 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2503 *end_name = delim;
2504 ignore_rest_of_line ();
2505 return;
2506 }
2507
2508 input_line_pointer++;
2509 *end_name = 0;
2510
2511 if (name[0] == '.' && name[1] == '\0')
2512 {
2513 /* XXX - this should not happen to .thumb_set. */
2514 abort ();
2515 }
2516
2517 if ((symbolP = symbol_find (name)) == NULL
2518 && (symbolP = md_undefined_symbol (name)) == NULL)
2519 {
2520#ifndef NO_LISTING
2521 /* When doing symbol listings, play games with dummy fragments living
2522 outside the normal fragment chain to record the file and line info
c19d1205 2523 for this symbol. */
b99bd4ef
NC
2524 if (listing & LISTING_SYMBOLS)
2525 {
2526 extern struct list_info_struct * listing_tail;
a737bd4d 2527 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2528
2529 memset (dummy_frag, 0, sizeof (fragS));
2530 dummy_frag->fr_type = rs_fill;
2531 dummy_frag->line = listing_tail;
2532 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2533 dummy_frag->fr_symbol = symbolP;
2534 }
2535 else
2536#endif
2537 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2538
2539#ifdef OBJ_COFF
2540 /* "set" symbols are local unless otherwise specified. */
2541 SF_SET_LOCAL (symbolP);
2542#endif /* OBJ_COFF */
2543 } /* Make a new symbol. */
2544
2545 symbol_table_insert (symbolP);
2546
2547 * end_name = delim;
2548
2549 if (equiv
2550 && S_IS_DEFINED (symbolP)
2551 && S_GET_SEGMENT (symbolP) != reg_section)
2552 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2553
2554 pseudo_set (symbolP);
2555
2556 demand_empty_rest_of_line ();
2557
c19d1205 2558 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2559
2560 THUMB_SET_FUNC (symbolP, 1);
2561 ARM_SET_THUMB (symbolP, 1);
2562#if defined OBJ_ELF || defined OBJ_COFF
2563 ARM_SET_INTERWORK (symbolP, support_interwork);
2564#endif
2565}
2566
c19d1205 2567/* Directives: Mode selection. */
b99bd4ef 2568
c19d1205
ZW
2569/* .syntax [unified|divided] - choose the new unified syntax
2570 (same for Arm and Thumb encoding, modulo slight differences in what
2571 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2572static void
c19d1205 2573s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2574{
c19d1205
ZW
2575 char *name, delim;
2576
2577 name = input_line_pointer;
2578 delim = get_symbol_end ();
2579
2580 if (!strcasecmp (name, "unified"))
2581 unified_syntax = TRUE;
2582 else if (!strcasecmp (name, "divided"))
2583 unified_syntax = FALSE;
2584 else
2585 {
2586 as_bad (_("unrecognized syntax mode \"%s\""), name);
2587 return;
2588 }
2589 *input_line_pointer = delim;
b99bd4ef
NC
2590 demand_empty_rest_of_line ();
2591}
2592
c19d1205
ZW
2593/* Directives: sectioning and alignment. */
2594
2595/* Same as s_align_ptwo but align 0 => align 2. */
2596
b99bd4ef 2597static void
c19d1205 2598s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2599{
a737bd4d 2600 int temp;
c19d1205
ZW
2601 long temp_fill;
2602 long max_alignment = 15;
b99bd4ef
NC
2603
2604 temp = get_absolute_expression ();
c19d1205
ZW
2605 if (temp > max_alignment)
2606 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2607 else if (temp < 0)
b99bd4ef 2608 {
c19d1205
ZW
2609 as_bad (_("alignment negative. 0 assumed."));
2610 temp = 0;
2611 }
b99bd4ef 2612
c19d1205
ZW
2613 if (*input_line_pointer == ',')
2614 {
2615 input_line_pointer++;
2616 temp_fill = get_absolute_expression ();
b99bd4ef 2617 }
c19d1205
ZW
2618 else
2619 temp_fill = 0;
b99bd4ef 2620
c19d1205
ZW
2621 if (!temp)
2622 temp = 2;
b99bd4ef 2623
c19d1205
ZW
2624 /* Only make a frag if we HAVE to. */
2625 if (temp && !need_pass_2)
2626 frag_align (temp, (int) temp_fill, 0);
2627 demand_empty_rest_of_line ();
2628
2629 record_alignment (now_seg, temp);
b99bd4ef
NC
2630}
2631
c19d1205
ZW
2632static void
2633s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2634{
c19d1205
ZW
2635 /* We don't support putting frags in the BSS segment, we fake it by
2636 marking in_bss, then looking at s_skip for clues. */
2637 subseg_set (bss_section, 0);
2638 demand_empty_rest_of_line ();
2639 mapping_state (MAP_DATA);
2640}
b99bd4ef 2641
c19d1205
ZW
2642static void
2643s_even (int ignore ATTRIBUTE_UNUSED)
2644{
2645 /* Never make frag if expect extra pass. */
2646 if (!need_pass_2)
2647 frag_align (1, 0, 0);
b99bd4ef 2648
c19d1205 2649 record_alignment (now_seg, 1);
b99bd4ef 2650
c19d1205 2651 demand_empty_rest_of_line ();
b99bd4ef
NC
2652}
2653
c19d1205 2654/* Directives: Literal pools. */
a737bd4d 2655
c19d1205
ZW
2656static literal_pool *
2657find_literal_pool (void)
a737bd4d 2658{
c19d1205 2659 literal_pool * pool;
a737bd4d 2660
c19d1205 2661 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2662 {
c19d1205
ZW
2663 if (pool->section == now_seg
2664 && pool->sub_section == now_subseg)
2665 break;
a737bd4d
NC
2666 }
2667
c19d1205 2668 return pool;
a737bd4d
NC
2669}
2670
c19d1205
ZW
2671static literal_pool *
2672find_or_make_literal_pool (void)
a737bd4d 2673{
c19d1205
ZW
2674 /* Next literal pool ID number. */
2675 static unsigned int latest_pool_num = 1;
2676 literal_pool * pool;
a737bd4d 2677
c19d1205 2678 pool = find_literal_pool ();
a737bd4d 2679
c19d1205 2680 if (pool == NULL)
a737bd4d 2681 {
c19d1205
ZW
2682 /* Create a new pool. */
2683 pool = xmalloc (sizeof (* pool));
2684 if (! pool)
2685 return NULL;
a737bd4d 2686
c19d1205
ZW
2687 pool->next_free_entry = 0;
2688 pool->section = now_seg;
2689 pool->sub_section = now_subseg;
2690 pool->next = list_of_pools;
2691 pool->symbol = NULL;
2692
2693 /* Add it to the list. */
2694 list_of_pools = pool;
a737bd4d 2695 }
a737bd4d 2696
c19d1205
ZW
2697 /* New pools, and emptied pools, will have a NULL symbol. */
2698 if (pool->symbol == NULL)
a737bd4d 2699 {
c19d1205
ZW
2700 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2701 (valueT) 0, &zero_address_frag);
2702 pool->id = latest_pool_num ++;
a737bd4d
NC
2703 }
2704
c19d1205
ZW
2705 /* Done. */
2706 return pool;
a737bd4d
NC
2707}
2708
c19d1205
ZW
2709/* Add the literal in the global 'inst'
2710 structure to the relevent literal pool. */
b99bd4ef
NC
2711
2712static int
c19d1205 2713add_to_lit_pool (void)
b99bd4ef 2714{
c19d1205
ZW
2715 literal_pool * pool;
2716 unsigned int entry;
b99bd4ef 2717
c19d1205
ZW
2718 pool = find_or_make_literal_pool ();
2719
2720 /* Check if this literal value is already in the pool. */
2721 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2722 {
c19d1205
ZW
2723 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2724 && (inst.reloc.exp.X_op == O_constant)
2725 && (pool->literals[entry].X_add_number
2726 == inst.reloc.exp.X_add_number)
2727 && (pool->literals[entry].X_unsigned
2728 == inst.reloc.exp.X_unsigned))
2729 break;
2730
2731 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2732 && (inst.reloc.exp.X_op == O_symbol)
2733 && (pool->literals[entry].X_add_number
2734 == inst.reloc.exp.X_add_number)
2735 && (pool->literals[entry].X_add_symbol
2736 == inst.reloc.exp.X_add_symbol)
2737 && (pool->literals[entry].X_op_symbol
2738 == inst.reloc.exp.X_op_symbol))
2739 break;
b99bd4ef
NC
2740 }
2741
c19d1205
ZW
2742 /* Do we need to create a new entry? */
2743 if (entry == pool->next_free_entry)
2744 {
2745 if (entry >= MAX_LITERAL_POOL_SIZE)
2746 {
2747 inst.error = _("literal pool overflow");
2748 return FAIL;
2749 }
2750
2751 pool->literals[entry] = inst.reloc.exp;
2752 pool->next_free_entry += 1;
2753 }
b99bd4ef 2754
c19d1205
ZW
2755 inst.reloc.exp.X_op = O_symbol;
2756 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2757 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2758
c19d1205 2759 return SUCCESS;
b99bd4ef
NC
2760}
2761
c19d1205
ZW
2762/* Can't use symbol_new here, so have to create a symbol and then at
2763 a later date assign it a value. Thats what these functions do. */
e16bb312 2764
c19d1205
ZW
2765static void
2766symbol_locate (symbolS * symbolP,
2767 const char * name, /* It is copied, the caller can modify. */
2768 segT segment, /* Segment identifier (SEG_<something>). */
2769 valueT valu, /* Symbol value. */
2770 fragS * frag) /* Associated fragment. */
2771{
2772 unsigned int name_length;
2773 char * preserved_copy_of_name;
e16bb312 2774
c19d1205
ZW
2775 name_length = strlen (name) + 1; /* +1 for \0. */
2776 obstack_grow (&notes, name, name_length);
2777 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2778
c19d1205
ZW
2779#ifdef tc_canonicalize_symbol_name
2780 preserved_copy_of_name =
2781 tc_canonicalize_symbol_name (preserved_copy_of_name);
2782#endif
b99bd4ef 2783
c19d1205 2784 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2785
c19d1205
ZW
2786 S_SET_SEGMENT (symbolP, segment);
2787 S_SET_VALUE (symbolP, valu);
2788 symbol_clear_list_pointers (symbolP);
b99bd4ef 2789
c19d1205 2790 symbol_set_frag (symbolP, frag);
b99bd4ef 2791
c19d1205
ZW
2792 /* Link to end of symbol chain. */
2793 {
2794 extern int symbol_table_frozen;
b99bd4ef 2795
c19d1205
ZW
2796 if (symbol_table_frozen)
2797 abort ();
2798 }
b99bd4ef 2799
c19d1205 2800 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2801
c19d1205 2802 obj_symbol_new_hook (symbolP);
b99bd4ef 2803
c19d1205
ZW
2804#ifdef tc_symbol_new_hook
2805 tc_symbol_new_hook (symbolP);
2806#endif
2807
2808#ifdef DEBUG_SYMS
2809 verify_symbol_chain (symbol_rootP, symbol_lastP);
2810#endif /* DEBUG_SYMS */
b99bd4ef
NC
2811}
2812
b99bd4ef 2813
c19d1205
ZW
2814static void
2815s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2816{
c19d1205
ZW
2817 unsigned int entry;
2818 literal_pool * pool;
2819 char sym_name[20];
b99bd4ef 2820
c19d1205
ZW
2821 pool = find_literal_pool ();
2822 if (pool == NULL
2823 || pool->symbol == NULL
2824 || pool->next_free_entry == 0)
2825 return;
b99bd4ef 2826
c19d1205 2827 mapping_state (MAP_DATA);
b99bd4ef 2828
c19d1205
ZW
2829 /* Align pool as you have word accesses.
2830 Only make a frag if we have to. */
2831 if (!need_pass_2)
2832 frag_align (2, 0, 0);
b99bd4ef 2833
c19d1205 2834 record_alignment (now_seg, 2);
b99bd4ef 2835
c19d1205 2836 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2837
c19d1205
ZW
2838 symbol_locate (pool->symbol, sym_name, now_seg,
2839 (valueT) frag_now_fix (), frag_now);
2840 symbol_table_insert (pool->symbol);
b99bd4ef 2841
c19d1205 2842 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2843
c19d1205
ZW
2844#if defined OBJ_COFF || defined OBJ_ELF
2845 ARM_SET_INTERWORK (pool->symbol, support_interwork);
2846#endif
6c43fab6 2847
c19d1205
ZW
2848 for (entry = 0; entry < pool->next_free_entry; entry ++)
2849 /* First output the expression in the instruction to the pool. */
2850 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 2851
c19d1205
ZW
2852 /* Mark the pool as empty. */
2853 pool->next_free_entry = 0;
2854 pool->symbol = NULL;
b99bd4ef
NC
2855}
2856
c19d1205
ZW
2857#ifdef OBJ_ELF
2858/* Forward declarations for functions below, in the MD interface
2859 section. */
2860static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
2861static valueT create_unwind_entry (int);
2862static void start_unwind_section (const segT, int);
2863static void add_unwind_opcode (valueT, int);
2864static void flush_pending_unwind (void);
b99bd4ef 2865
c19d1205 2866/* Directives: Data. */
b99bd4ef 2867
c19d1205
ZW
2868static void
2869s_arm_elf_cons (int nbytes)
2870{
2871 expressionS exp;
b99bd4ef 2872
c19d1205
ZW
2873#ifdef md_flush_pending_output
2874 md_flush_pending_output ();
2875#endif
b99bd4ef 2876
c19d1205 2877 if (is_it_end_of_statement ())
b99bd4ef 2878 {
c19d1205
ZW
2879 demand_empty_rest_of_line ();
2880 return;
b99bd4ef
NC
2881 }
2882
c19d1205
ZW
2883#ifdef md_cons_align
2884 md_cons_align (nbytes);
2885#endif
b99bd4ef 2886
c19d1205
ZW
2887 mapping_state (MAP_DATA);
2888 do
b99bd4ef 2889 {
c19d1205
ZW
2890 int reloc;
2891 char *base = input_line_pointer;
b99bd4ef 2892
c19d1205 2893 expression (& exp);
b99bd4ef 2894
c19d1205
ZW
2895 if (exp.X_op != O_symbol)
2896 emit_expr (&exp, (unsigned int) nbytes);
2897 else
2898 {
2899 char *before_reloc = input_line_pointer;
2900 reloc = parse_reloc (&input_line_pointer);
2901 if (reloc == -1)
2902 {
2903 as_bad (_("unrecognized relocation suffix"));
2904 ignore_rest_of_line ();
2905 return;
2906 }
2907 else if (reloc == BFD_RELOC_UNUSED)
2908 emit_expr (&exp, (unsigned int) nbytes);
2909 else
2910 {
2911 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
2912 int size = bfd_get_reloc_size (howto);
b99bd4ef 2913
2fc8bdac
ZW
2914 if (reloc == BFD_RELOC_ARM_PLT32)
2915 {
2916 as_bad (_("(plt) is only valid on branch targets"));
2917 reloc = BFD_RELOC_UNUSED;
2918 size = 0;
2919 }
2920
c19d1205 2921 if (size > nbytes)
2fc8bdac 2922 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
2923 howto->name, nbytes);
2924 else
2925 {
2926 /* We've parsed an expression stopping at O_symbol.
2927 But there may be more expression left now that we
2928 have parsed the relocation marker. Parse it again.
2929 XXX Surely there is a cleaner way to do this. */
2930 char *p = input_line_pointer;
2931 int offset;
2932 char *save_buf = alloca (input_line_pointer - base);
2933 memcpy (save_buf, base, input_line_pointer - base);
2934 memmove (base + (input_line_pointer - before_reloc),
2935 base, before_reloc - base);
2936
2937 input_line_pointer = base + (input_line_pointer-before_reloc);
2938 expression (&exp);
2939 memcpy (base, save_buf, p - base);
2940
2941 offset = nbytes - size;
2942 p = frag_more ((int) nbytes);
2943 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
2944 size, &exp, 0, reloc);
2945 }
2946 }
2947 }
b99bd4ef 2948 }
c19d1205 2949 while (*input_line_pointer++ == ',');
b99bd4ef 2950
c19d1205
ZW
2951 /* Put terminator back into stream. */
2952 input_line_pointer --;
2953 demand_empty_rest_of_line ();
b99bd4ef
NC
2954}
2955
b99bd4ef 2956
c19d1205 2957/* Parse a .rel31 directive. */
b99bd4ef 2958
c19d1205
ZW
2959static void
2960s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
2961{
2962 expressionS exp;
2963 char *p;
2964 valueT highbit;
b99bd4ef 2965
c19d1205
ZW
2966 highbit = 0;
2967 if (*input_line_pointer == '1')
2968 highbit = 0x80000000;
2969 else if (*input_line_pointer != '0')
2970 as_bad (_("expected 0 or 1"));
b99bd4ef 2971
c19d1205
ZW
2972 input_line_pointer++;
2973 if (*input_line_pointer != ',')
2974 as_bad (_("missing comma"));
2975 input_line_pointer++;
b99bd4ef 2976
c19d1205
ZW
2977#ifdef md_flush_pending_output
2978 md_flush_pending_output ();
2979#endif
b99bd4ef 2980
c19d1205
ZW
2981#ifdef md_cons_align
2982 md_cons_align (4);
2983#endif
b99bd4ef 2984
c19d1205 2985 mapping_state (MAP_DATA);
b99bd4ef 2986
c19d1205 2987 expression (&exp);
b99bd4ef 2988
c19d1205
ZW
2989 p = frag_more (4);
2990 md_number_to_chars (p, highbit, 4);
2991 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
2992 BFD_RELOC_ARM_PREL31);
b99bd4ef 2993
c19d1205 2994 demand_empty_rest_of_line ();
b99bd4ef
NC
2995}
2996
c19d1205 2997/* Directives: AEABI stack-unwind tables. */
b99bd4ef 2998
c19d1205 2999/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3000
c19d1205
ZW
3001static void
3002s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3003{
3004 demand_empty_rest_of_line ();
3005 /* Mark the start of the function. */
3006 unwind.proc_start = expr_build_dot ();
b99bd4ef 3007
c19d1205
ZW
3008 /* Reset the rest of the unwind info. */
3009 unwind.opcode_count = 0;
3010 unwind.table_entry = NULL;
3011 unwind.personality_routine = NULL;
3012 unwind.personality_index = -1;
3013 unwind.frame_size = 0;
3014 unwind.fp_offset = 0;
3015 unwind.fp_reg = 13;
3016 unwind.fp_used = 0;
3017 unwind.sp_restored = 0;
3018}
b99bd4ef 3019
b99bd4ef 3020
c19d1205
ZW
3021/* Parse a handlerdata directive. Creates the exception handling table entry
3022 for the function. */
b99bd4ef 3023
c19d1205
ZW
3024static void
3025s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3026{
3027 demand_empty_rest_of_line ();
3028 if (unwind.table_entry)
3029 as_bad (_("dupicate .handlerdata directive"));
f02232aa 3030
c19d1205
ZW
3031 create_unwind_entry (1);
3032}
a737bd4d 3033
c19d1205 3034/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3035
c19d1205
ZW
3036static void
3037s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3038{
3039 long where;
3040 char *ptr;
3041 valueT val;
f02232aa 3042
c19d1205 3043 demand_empty_rest_of_line ();
f02232aa 3044
c19d1205
ZW
3045 /* Add eh table entry. */
3046 if (unwind.table_entry == NULL)
3047 val = create_unwind_entry (0);
3048 else
3049 val = 0;
f02232aa 3050
c19d1205
ZW
3051 /* Add index table entry. This is two words. */
3052 start_unwind_section (unwind.saved_seg, 1);
3053 frag_align (2, 0, 0);
3054 record_alignment (now_seg, 2);
b99bd4ef 3055
c19d1205
ZW
3056 ptr = frag_more (8);
3057 where = frag_now_fix () - 8;
f02232aa 3058
c19d1205
ZW
3059 /* Self relative offset of the function start. */
3060 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3061 BFD_RELOC_ARM_PREL31);
f02232aa 3062
c19d1205
ZW
3063 /* Indicate dependency on EHABI-defined personality routines to the
3064 linker, if it hasn't been done already. */
3065 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3066 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3067 {
3068 static const char *const name[] = {
3069 "__aeabi_unwind_cpp_pr0",
3070 "__aeabi_unwind_cpp_pr1",
3071 "__aeabi_unwind_cpp_pr2"
3072 };
3073 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3074 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3075 marked_pr_dependency |= 1 << unwind.personality_index;
3076 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3077 = marked_pr_dependency;
3078 }
f02232aa 3079
c19d1205
ZW
3080 if (val)
3081 /* Inline exception table entry. */
3082 md_number_to_chars (ptr + 4, val, 4);
3083 else
3084 /* Self relative offset of the table entry. */
3085 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3086 BFD_RELOC_ARM_PREL31);
f02232aa 3087
c19d1205
ZW
3088 /* Restore the original section. */
3089 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3090}
f02232aa 3091
f02232aa 3092
c19d1205 3093/* Parse an unwind_cantunwind directive. */
b99bd4ef 3094
c19d1205
ZW
3095static void
3096s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3097{
3098 demand_empty_rest_of_line ();
3099 if (unwind.personality_routine || unwind.personality_index != -1)
3100 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3101
c19d1205
ZW
3102 unwind.personality_index = -2;
3103}
b99bd4ef 3104
b99bd4ef 3105
c19d1205 3106/* Parse a personalityindex directive. */
b99bd4ef 3107
c19d1205
ZW
3108static void
3109s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3110{
3111 expressionS exp;
b99bd4ef 3112
c19d1205
ZW
3113 if (unwind.personality_routine || unwind.personality_index != -1)
3114 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3115
c19d1205 3116 expression (&exp);
b99bd4ef 3117
c19d1205
ZW
3118 if (exp.X_op != O_constant
3119 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3120 {
c19d1205
ZW
3121 as_bad (_("bad personality routine number"));
3122 ignore_rest_of_line ();
3123 return;
b99bd4ef
NC
3124 }
3125
c19d1205 3126 unwind.personality_index = exp.X_add_number;
b99bd4ef 3127
c19d1205
ZW
3128 demand_empty_rest_of_line ();
3129}
e16bb312 3130
e16bb312 3131
c19d1205 3132/* Parse a personality directive. */
e16bb312 3133
c19d1205
ZW
3134static void
3135s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3136{
3137 char *name, *p, c;
a737bd4d 3138
c19d1205
ZW
3139 if (unwind.personality_routine || unwind.personality_index != -1)
3140 as_bad (_("duplicate .personality directive"));
a737bd4d 3141
c19d1205
ZW
3142 name = input_line_pointer;
3143 c = get_symbol_end ();
3144 p = input_line_pointer;
3145 unwind.personality_routine = symbol_find_or_make (name);
3146 *p = c;
3147 demand_empty_rest_of_line ();
3148}
e16bb312 3149
e16bb312 3150
c19d1205 3151/* Parse a directive saving core registers. */
e16bb312 3152
c19d1205
ZW
3153static void
3154s_arm_unwind_save_core (void)
e16bb312 3155{
c19d1205
ZW
3156 valueT op;
3157 long range;
3158 int n;
e16bb312 3159
c19d1205
ZW
3160 range = parse_reg_list (&input_line_pointer);
3161 if (range == FAIL)
e16bb312 3162 {
c19d1205
ZW
3163 as_bad (_("expected register list"));
3164 ignore_rest_of_line ();
3165 return;
3166 }
e16bb312 3167
c19d1205 3168 demand_empty_rest_of_line ();
e16bb312 3169
c19d1205
ZW
3170 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3171 into .unwind_save {..., sp...}. We aren't bothered about the value of
3172 ip because it is clobbered by calls. */
3173 if (unwind.sp_restored && unwind.fp_reg == 12
3174 && (range & 0x3000) == 0x1000)
3175 {
3176 unwind.opcode_count--;
3177 unwind.sp_restored = 0;
3178 range = (range | 0x2000) & ~0x1000;
3179 unwind.pending_offset = 0;
3180 }
e16bb312 3181
01ae4198
DJ
3182 /* Pop r4-r15. */
3183 if (range & 0xfff0)
c19d1205 3184 {
01ae4198
DJ
3185 /* See if we can use the short opcodes. These pop a block of up to 8
3186 registers starting with r4, plus maybe r14. */
3187 for (n = 0; n < 8; n++)
3188 {
3189 /* Break at the first non-saved register. */
3190 if ((range & (1 << (n + 4))) == 0)
3191 break;
3192 }
3193 /* See if there are any other bits set. */
3194 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3195 {
3196 /* Use the long form. */
3197 op = 0x8000 | ((range >> 4) & 0xfff);
3198 add_unwind_opcode (op, 2);
3199 }
0dd132b6 3200 else
01ae4198
DJ
3201 {
3202 /* Use the short form. */
3203 if (range & 0x4000)
3204 op = 0xa8; /* Pop r14. */
3205 else
3206 op = 0xa0; /* Do not pop r14. */
3207 op |= (n - 1);
3208 add_unwind_opcode (op, 1);
3209 }
c19d1205 3210 }
0dd132b6 3211
c19d1205
ZW
3212 /* Pop r0-r3. */
3213 if (range & 0xf)
3214 {
3215 op = 0xb100 | (range & 0xf);
3216 add_unwind_opcode (op, 2);
0dd132b6
NC
3217 }
3218
c19d1205
ZW
3219 /* Record the number of bytes pushed. */
3220 for (n = 0; n < 16; n++)
3221 {
3222 if (range & (1 << n))
3223 unwind.frame_size += 4;
3224 }
0dd132b6
NC
3225}
3226
c19d1205
ZW
3227
3228/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3229
3230static void
c19d1205 3231s_arm_unwind_save_fpa (int reg)
b99bd4ef 3232{
c19d1205
ZW
3233 expressionS exp;
3234 int num_regs;
3235 valueT op;
b99bd4ef 3236
c19d1205
ZW
3237 /* Get Number of registers to transfer. */
3238 if (skip_past_comma (&input_line_pointer) != FAIL)
3239 expression (&exp);
3240 else
3241 exp.X_op = O_illegal;
b99bd4ef 3242
c19d1205 3243 if (exp.X_op != O_constant)
b99bd4ef 3244 {
c19d1205
ZW
3245 as_bad (_("expected , <constant>"));
3246 ignore_rest_of_line ();
b99bd4ef
NC
3247 return;
3248 }
3249
c19d1205
ZW
3250 num_regs = exp.X_add_number;
3251
3252 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3253 {
c19d1205
ZW
3254 as_bad (_("number of registers must be in the range [1:4]"));
3255 ignore_rest_of_line ();
b99bd4ef
NC
3256 return;
3257 }
3258
c19d1205 3259 demand_empty_rest_of_line ();
b99bd4ef 3260
c19d1205
ZW
3261 if (reg == 4)
3262 {
3263 /* Short form. */
3264 op = 0xb4 | (num_regs - 1);
3265 add_unwind_opcode (op, 1);
3266 }
b99bd4ef
NC
3267 else
3268 {
c19d1205
ZW
3269 /* Long form. */
3270 op = 0xc800 | (reg << 4) | (num_regs - 1);
3271 add_unwind_opcode (op, 2);
b99bd4ef 3272 }
c19d1205 3273 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3274}
3275
c19d1205 3276
fa073d69
MS
3277/* Parse a directive saving VFP registers for ARMv6 and above. */
3278
3279static void
3280s_arm_unwind_save_vfp_armv6 (void)
3281{
3282 int count;
3283 unsigned int start;
3284 valueT op;
3285 int num_vfpv3_regs = 0;
3286 int num_regs_below_16;
3287
3288 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3289 if (count == FAIL)
3290 {
3291 as_bad (_("expected register list"));
3292 ignore_rest_of_line ();
3293 return;
3294 }
3295
3296 demand_empty_rest_of_line ();
3297
3298 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3299 than FSTMX/FLDMX-style ones). */
3300
3301 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3302 if (start >= 16)
3303 num_vfpv3_regs = count;
3304 else if (start + count > 16)
3305 num_vfpv3_regs = start + count - 16;
3306
3307 if (num_vfpv3_regs > 0)
3308 {
3309 int start_offset = start > 16 ? start - 16 : 0;
3310 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3311 add_unwind_opcode (op, 2);
3312 }
3313
3314 /* Generate opcode for registers numbered in the range 0 .. 15. */
3315 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3316 assert (num_regs_below_16 + num_vfpv3_regs == count);
3317 if (num_regs_below_16 > 0)
3318 {
3319 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3320 add_unwind_opcode (op, 2);
3321 }
3322
3323 unwind.frame_size += count * 8;
3324}
3325
3326
3327/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3328
3329static void
c19d1205 3330s_arm_unwind_save_vfp (void)
b99bd4ef 3331{
c19d1205 3332 int count;
ca3f61f7 3333 unsigned int reg;
c19d1205 3334 valueT op;
b99bd4ef 3335
5287ad62 3336 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3337 if (count == FAIL)
b99bd4ef 3338 {
c19d1205
ZW
3339 as_bad (_("expected register list"));
3340 ignore_rest_of_line ();
b99bd4ef
NC
3341 return;
3342 }
3343
c19d1205 3344 demand_empty_rest_of_line ();
b99bd4ef 3345
c19d1205 3346 if (reg == 8)
b99bd4ef 3347 {
c19d1205
ZW
3348 /* Short form. */
3349 op = 0xb8 | (count - 1);
3350 add_unwind_opcode (op, 1);
b99bd4ef 3351 }
c19d1205 3352 else
b99bd4ef 3353 {
c19d1205
ZW
3354 /* Long form. */
3355 op = 0xb300 | (reg << 4) | (count - 1);
3356 add_unwind_opcode (op, 2);
b99bd4ef 3357 }
c19d1205
ZW
3358 unwind.frame_size += count * 8 + 4;
3359}
b99bd4ef 3360
b99bd4ef 3361
c19d1205
ZW
3362/* Parse a directive saving iWMMXt data registers. */
3363
3364static void
3365s_arm_unwind_save_mmxwr (void)
3366{
3367 int reg;
3368 int hi_reg;
3369 int i;
3370 unsigned mask = 0;
3371 valueT op;
b99bd4ef 3372
c19d1205
ZW
3373 if (*input_line_pointer == '{')
3374 input_line_pointer++;
b99bd4ef 3375
c19d1205 3376 do
b99bd4ef 3377 {
dcbf9037 3378 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3379
c19d1205 3380 if (reg == FAIL)
b99bd4ef 3381 {
c19d1205
ZW
3382 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3383 goto error;
b99bd4ef
NC
3384 }
3385
c19d1205
ZW
3386 if (mask >> reg)
3387 as_tsktsk (_("register list not in ascending order"));
3388 mask |= 1 << reg;
b99bd4ef 3389
c19d1205
ZW
3390 if (*input_line_pointer == '-')
3391 {
3392 input_line_pointer++;
dcbf9037 3393 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3394 if (hi_reg == FAIL)
3395 {
3396 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWR]));
3397 goto error;
3398 }
3399 else if (reg >= hi_reg)
3400 {
3401 as_bad (_("bad register range"));
3402 goto error;
3403 }
3404 for (; reg < hi_reg; reg++)
3405 mask |= 1 << reg;
3406 }
3407 }
3408 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3409
c19d1205
ZW
3410 if (*input_line_pointer == '}')
3411 input_line_pointer++;
b99bd4ef 3412
c19d1205 3413 demand_empty_rest_of_line ();
b99bd4ef 3414
708587a4 3415 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3416 the list. */
3417 flush_pending_unwind ();
b99bd4ef 3418
c19d1205 3419 for (i = 0; i < 16; i++)
b99bd4ef 3420 {
c19d1205
ZW
3421 if (mask & (1 << i))
3422 unwind.frame_size += 8;
b99bd4ef
NC
3423 }
3424
c19d1205
ZW
3425 /* Attempt to combine with a previous opcode. We do this because gcc
3426 likes to output separate unwind directives for a single block of
3427 registers. */
3428 if (unwind.opcode_count > 0)
b99bd4ef 3429 {
c19d1205
ZW
3430 i = unwind.opcodes[unwind.opcode_count - 1];
3431 if ((i & 0xf8) == 0xc0)
3432 {
3433 i &= 7;
3434 /* Only merge if the blocks are contiguous. */
3435 if (i < 6)
3436 {
3437 if ((mask & 0xfe00) == (1 << 9))
3438 {
3439 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3440 unwind.opcode_count--;
3441 }
3442 }
3443 else if (i == 6 && unwind.opcode_count >= 2)
3444 {
3445 i = unwind.opcodes[unwind.opcode_count - 2];
3446 reg = i >> 4;
3447 i &= 0xf;
b99bd4ef 3448
c19d1205
ZW
3449 op = 0xffff << (reg - 1);
3450 if (reg > 0
87a1fd79 3451 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3452 {
3453 op = (1 << (reg + i + 1)) - 1;
3454 op &= ~((1 << reg) - 1);
3455 mask |= op;
3456 unwind.opcode_count -= 2;
3457 }
3458 }
3459 }
b99bd4ef
NC
3460 }
3461
c19d1205
ZW
3462 hi_reg = 15;
3463 /* We want to generate opcodes in the order the registers have been
3464 saved, ie. descending order. */
3465 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3466 {
c19d1205
ZW
3467 /* Save registers in blocks. */
3468 if (reg < 0
3469 || !(mask & (1 << reg)))
3470 {
3471 /* We found an unsaved reg. Generate opcodes to save the
3472 preceeding block. */
3473 if (reg != hi_reg)
3474 {
3475 if (reg == 9)
3476 {
3477 /* Short form. */
3478 op = 0xc0 | (hi_reg - 10);
3479 add_unwind_opcode (op, 1);
3480 }
3481 else
3482 {
3483 /* Long form. */
3484 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3485 add_unwind_opcode (op, 2);
3486 }
3487 }
3488 hi_reg = reg - 1;
3489 }
b99bd4ef
NC
3490 }
3491
c19d1205
ZW
3492 return;
3493error:
3494 ignore_rest_of_line ();
b99bd4ef
NC
3495}
3496
3497static void
c19d1205 3498s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3499{
c19d1205
ZW
3500 int reg;
3501 int hi_reg;
3502 unsigned mask = 0;
3503 valueT op;
b99bd4ef 3504
c19d1205
ZW
3505 if (*input_line_pointer == '{')
3506 input_line_pointer++;
b99bd4ef 3507
c19d1205 3508 do
b99bd4ef 3509 {
dcbf9037 3510 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3511
c19d1205
ZW
3512 if (reg == FAIL)
3513 {
3514 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3515 goto error;
3516 }
b99bd4ef 3517
c19d1205
ZW
3518 reg -= 8;
3519 if (mask >> reg)
3520 as_tsktsk (_("register list not in ascending order"));
3521 mask |= 1 << reg;
b99bd4ef 3522
c19d1205
ZW
3523 if (*input_line_pointer == '-')
3524 {
3525 input_line_pointer++;
dcbf9037 3526 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3527 if (hi_reg == FAIL)
3528 {
3529 as_bad (_(reg_expected_msgs[REG_TYPE_MMXWCG]));
3530 goto error;
3531 }
3532 else if (reg >= hi_reg)
3533 {
3534 as_bad (_("bad register range"));
3535 goto error;
3536 }
3537 for (; reg < hi_reg; reg++)
3538 mask |= 1 << reg;
3539 }
b99bd4ef 3540 }
c19d1205 3541 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3542
c19d1205
ZW
3543 if (*input_line_pointer == '}')
3544 input_line_pointer++;
b99bd4ef 3545
c19d1205
ZW
3546 demand_empty_rest_of_line ();
3547
708587a4 3548 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3549 the list. */
3550 flush_pending_unwind ();
b99bd4ef 3551
c19d1205 3552 for (reg = 0; reg < 16; reg++)
b99bd4ef 3553 {
c19d1205
ZW
3554 if (mask & (1 << reg))
3555 unwind.frame_size += 4;
b99bd4ef 3556 }
c19d1205
ZW
3557 op = 0xc700 | mask;
3558 add_unwind_opcode (op, 2);
3559 return;
3560error:
3561 ignore_rest_of_line ();
b99bd4ef
NC
3562}
3563
c19d1205 3564
fa073d69
MS
3565/* Parse an unwind_save directive.
3566 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3567
b99bd4ef 3568static void
fa073d69 3569s_arm_unwind_save (int arch_v6)
b99bd4ef 3570{
c19d1205
ZW
3571 char *peek;
3572 struct reg_entry *reg;
3573 bfd_boolean had_brace = FALSE;
b99bd4ef 3574
c19d1205
ZW
3575 /* Figure out what sort of save we have. */
3576 peek = input_line_pointer;
b99bd4ef 3577
c19d1205 3578 if (*peek == '{')
b99bd4ef 3579 {
c19d1205
ZW
3580 had_brace = TRUE;
3581 peek++;
b99bd4ef
NC
3582 }
3583
c19d1205 3584 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3585
c19d1205 3586 if (!reg)
b99bd4ef 3587 {
c19d1205
ZW
3588 as_bad (_("register expected"));
3589 ignore_rest_of_line ();
b99bd4ef
NC
3590 return;
3591 }
3592
c19d1205 3593 switch (reg->type)
b99bd4ef 3594 {
c19d1205
ZW
3595 case REG_TYPE_FN:
3596 if (had_brace)
3597 {
3598 as_bad (_("FPA .unwind_save does not take a register list"));
3599 ignore_rest_of_line ();
3600 return;
3601 }
3602 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3603 return;
c19d1205
ZW
3604
3605 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3606 case REG_TYPE_VFD:
3607 if (arch_v6)
3608 s_arm_unwind_save_vfp_armv6 ();
3609 else
3610 s_arm_unwind_save_vfp ();
3611 return;
c19d1205
ZW
3612 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3613 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3614
3615 default:
3616 as_bad (_(".unwind_save does not support this kind of register"));
3617 ignore_rest_of_line ();
b99bd4ef 3618 }
c19d1205 3619}
b99bd4ef 3620
b99bd4ef 3621
c19d1205
ZW
3622/* Parse an unwind_movsp directive. */
3623
3624static void
3625s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3626{
3627 int reg;
3628 valueT op;
3629
dcbf9037 3630 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3631 if (reg == FAIL)
b99bd4ef 3632 {
c19d1205
ZW
3633 as_bad (_(reg_expected_msgs[REG_TYPE_RN]));
3634 ignore_rest_of_line ();
b99bd4ef
NC
3635 return;
3636 }
c19d1205 3637 demand_empty_rest_of_line ();
b99bd4ef 3638
c19d1205 3639 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3640 {
c19d1205 3641 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3642 return;
3643 }
3644
c19d1205
ZW
3645 if (unwind.fp_reg != REG_SP)
3646 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3647
c19d1205
ZW
3648 /* Generate opcode to restore the value. */
3649 op = 0x90 | reg;
3650 add_unwind_opcode (op, 1);
3651
3652 /* Record the information for later. */
3653 unwind.fp_reg = reg;
3654 unwind.fp_offset = unwind.frame_size;
3655 unwind.sp_restored = 1;
b05fe5cf
ZW
3656}
3657
c19d1205
ZW
3658/* Parse an unwind_pad directive. */
3659
b05fe5cf 3660static void
c19d1205 3661s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3662{
c19d1205 3663 int offset;
b05fe5cf 3664
c19d1205
ZW
3665 if (immediate_for_directive (&offset) == FAIL)
3666 return;
b99bd4ef 3667
c19d1205
ZW
3668 if (offset & 3)
3669 {
3670 as_bad (_("stack increment must be multiple of 4"));
3671 ignore_rest_of_line ();
3672 return;
3673 }
b99bd4ef 3674
c19d1205
ZW
3675 /* Don't generate any opcodes, just record the details for later. */
3676 unwind.frame_size += offset;
3677 unwind.pending_offset += offset;
3678
3679 demand_empty_rest_of_line ();
3680}
3681
3682/* Parse an unwind_setfp directive. */
3683
3684static void
3685s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3686{
c19d1205
ZW
3687 int sp_reg;
3688 int fp_reg;
3689 int offset;
3690
dcbf9037 3691 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3692 if (skip_past_comma (&input_line_pointer) == FAIL)
3693 sp_reg = FAIL;
3694 else
dcbf9037 3695 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3696
c19d1205
ZW
3697 if (fp_reg == FAIL || sp_reg == FAIL)
3698 {
3699 as_bad (_("expected <reg>, <reg>"));
3700 ignore_rest_of_line ();
3701 return;
3702 }
b99bd4ef 3703
c19d1205
ZW
3704 /* Optional constant. */
3705 if (skip_past_comma (&input_line_pointer) != FAIL)
3706 {
3707 if (immediate_for_directive (&offset) == FAIL)
3708 return;
3709 }
3710 else
3711 offset = 0;
a737bd4d 3712
c19d1205 3713 demand_empty_rest_of_line ();
a737bd4d 3714
c19d1205 3715 if (sp_reg != 13 && sp_reg != unwind.fp_reg)
a737bd4d 3716 {
c19d1205
ZW
3717 as_bad (_("register must be either sp or set by a previous"
3718 "unwind_movsp directive"));
3719 return;
a737bd4d
NC
3720 }
3721
c19d1205
ZW
3722 /* Don't generate any opcodes, just record the information for later. */
3723 unwind.fp_reg = fp_reg;
3724 unwind.fp_used = 1;
3725 if (sp_reg == 13)
3726 unwind.fp_offset = unwind.frame_size - offset;
3727 else
3728 unwind.fp_offset -= offset;
a737bd4d
NC
3729}
3730
c19d1205
ZW
3731/* Parse an unwind_raw directive. */
3732
3733static void
3734s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3735{
c19d1205 3736 expressionS exp;
708587a4 3737 /* This is an arbitrary limit. */
c19d1205
ZW
3738 unsigned char op[16];
3739 int count;
a737bd4d 3740
c19d1205
ZW
3741 expression (&exp);
3742 if (exp.X_op == O_constant
3743 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3744 {
c19d1205
ZW
3745 unwind.frame_size += exp.X_add_number;
3746 expression (&exp);
3747 }
3748 else
3749 exp.X_op = O_illegal;
a737bd4d 3750
c19d1205
ZW
3751 if (exp.X_op != O_constant)
3752 {
3753 as_bad (_("expected <offset>, <opcode>"));
3754 ignore_rest_of_line ();
3755 return;
3756 }
a737bd4d 3757
c19d1205 3758 count = 0;
a737bd4d 3759
c19d1205
ZW
3760 /* Parse the opcode. */
3761 for (;;)
3762 {
3763 if (count >= 16)
3764 {
3765 as_bad (_("unwind opcode too long"));
3766 ignore_rest_of_line ();
a737bd4d 3767 }
c19d1205 3768 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3769 {
c19d1205
ZW
3770 as_bad (_("invalid unwind opcode"));
3771 ignore_rest_of_line ();
3772 return;
a737bd4d 3773 }
c19d1205 3774 op[count++] = exp.X_add_number;
a737bd4d 3775
c19d1205
ZW
3776 /* Parse the next byte. */
3777 if (skip_past_comma (&input_line_pointer) == FAIL)
3778 break;
a737bd4d 3779
c19d1205
ZW
3780 expression (&exp);
3781 }
b99bd4ef 3782
c19d1205
ZW
3783 /* Add the opcode bytes in reverse order. */
3784 while (count--)
3785 add_unwind_opcode (op[count], 1);
b99bd4ef 3786
c19d1205 3787 demand_empty_rest_of_line ();
b99bd4ef 3788}
ee065d83
PB
3789
3790
3791/* Parse a .eabi_attribute directive. */
3792
3793static void
3794s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
3795{
3796 expressionS exp;
3797 bfd_boolean is_string;
3798 int tag;
3799 unsigned int i = 0;
3800 char *s = NULL;
3801 char saved_char;
3802
3803 expression (& exp);
3804 if (exp.X_op != O_constant)
3805 goto bad;
3806
3807 tag = exp.X_add_number;
3808 if (tag == 4 || tag == 5 || tag == 32 || (tag > 32 && (tag & 1) != 0))
3809 is_string = 1;
3810 else
3811 is_string = 0;
3812
3813 if (skip_past_comma (&input_line_pointer) == FAIL)
3814 goto bad;
3815 if (tag == 32 || !is_string)
3816 {
3817 expression (& exp);
3818 if (exp.X_op != O_constant)
3819 {
3820 as_bad (_("expected numeric constant"));
3821 ignore_rest_of_line ();
3822 return;
3823 }
3824 i = exp.X_add_number;
3825 }
3826 if (tag == Tag_compatibility
3827 && skip_past_comma (&input_line_pointer) == FAIL)
3828 {
3829 as_bad (_("expected comma"));
3830 ignore_rest_of_line ();
3831 return;
3832 }
3833 if (is_string)
3834 {
3835 skip_whitespace(input_line_pointer);
3836 if (*input_line_pointer != '"')
3837 goto bad_string;
3838 input_line_pointer++;
3839 s = input_line_pointer;
3840 while (*input_line_pointer && *input_line_pointer != '"')
3841 input_line_pointer++;
3842 if (*input_line_pointer != '"')
3843 goto bad_string;
3844 saved_char = *input_line_pointer;
3845 *input_line_pointer = 0;
3846 }
3847 else
3848 {
3849 s = NULL;
3850 saved_char = 0;
3851 }
3852
3853 if (tag == Tag_compatibility)
3854 elf32_arm_add_eabi_attr_compat (stdoutput, i, s);
3855 else if (is_string)
3856 elf32_arm_add_eabi_attr_string (stdoutput, tag, s);
3857 else
3858 elf32_arm_add_eabi_attr_int (stdoutput, tag, i);
3859
3860 if (s)
3861 {
3862 *input_line_pointer = saved_char;
3863 input_line_pointer++;
3864 }
3865 demand_empty_rest_of_line ();
3866 return;
3867bad_string:
3868 as_bad (_("bad string constant"));
3869 ignore_rest_of_line ();
3870 return;
3871bad:
3872 as_bad (_("expected <tag> , <value>"));
3873 ignore_rest_of_line ();
3874}
8463be01 3875#endif /* OBJ_ELF */
ee065d83
PB
3876
3877static void s_arm_arch (int);
3878static void s_arm_cpu (int);
3879static void s_arm_fpu (int);
b99bd4ef 3880
f0927246
NC
3881#ifdef TE_PE
3882
3883static void
3884pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
3885{
3886 expressionS exp;
3887
3888 do
3889 {
3890 expression (&exp);
3891 if (exp.X_op == O_symbol)
3892 exp.X_op = O_secrel;
3893
3894 emit_expr (&exp, 4);
3895 }
3896 while (*input_line_pointer++ == ',');
3897
3898 input_line_pointer--;
3899 demand_empty_rest_of_line ();
3900}
3901#endif /* TE_PE */
3902
c19d1205
ZW
3903/* This table describes all the machine specific pseudo-ops the assembler
3904 has to support. The fields are:
3905 pseudo-op name without dot
3906 function to call to execute this pseudo-op
3907 Integer arg to pass to the function. */
b99bd4ef 3908
c19d1205 3909const pseudo_typeS md_pseudo_table[] =
b99bd4ef 3910{
c19d1205
ZW
3911 /* Never called because '.req' does not start a line. */
3912 { "req", s_req, 0 },
dcbf9037
JB
3913 /* Following two are likewise never called. */
3914 { "dn", s_dn, 0 },
3915 { "qn", s_qn, 0 },
c19d1205
ZW
3916 { "unreq", s_unreq, 0 },
3917 { "bss", s_bss, 0 },
3918 { "align", s_align, 0 },
3919 { "arm", s_arm, 0 },
3920 { "thumb", s_thumb, 0 },
3921 { "code", s_code, 0 },
3922 { "force_thumb", s_force_thumb, 0 },
3923 { "thumb_func", s_thumb_func, 0 },
3924 { "thumb_set", s_thumb_set, 0 },
3925 { "even", s_even, 0 },
3926 { "ltorg", s_ltorg, 0 },
3927 { "pool", s_ltorg, 0 },
3928 { "syntax", s_syntax, 0 },
8463be01
PB
3929 { "cpu", s_arm_cpu, 0 },
3930 { "arch", s_arm_arch, 0 },
3931 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
3932#ifdef OBJ_ELF
3933 { "word", s_arm_elf_cons, 4 },
3934 { "long", s_arm_elf_cons, 4 },
3935 { "rel31", s_arm_rel31, 0 },
3936 { "fnstart", s_arm_unwind_fnstart, 0 },
3937 { "fnend", s_arm_unwind_fnend, 0 },
3938 { "cantunwind", s_arm_unwind_cantunwind, 0 },
3939 { "personality", s_arm_unwind_personality, 0 },
3940 { "personalityindex", s_arm_unwind_personalityindex, 0 },
3941 { "handlerdata", s_arm_unwind_handlerdata, 0 },
3942 { "save", s_arm_unwind_save, 0 },
fa073d69 3943 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
3944 { "movsp", s_arm_unwind_movsp, 0 },
3945 { "pad", s_arm_unwind_pad, 0 },
3946 { "setfp", s_arm_unwind_setfp, 0 },
3947 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 3948 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
3949#else
3950 { "word", cons, 4},
f0927246
NC
3951
3952 /* These are used for dwarf. */
3953 {"2byte", cons, 2},
3954 {"4byte", cons, 4},
3955 {"8byte", cons, 8},
3956 /* These are used for dwarf2. */
3957 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
3958 { "loc", dwarf2_directive_loc, 0 },
3959 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
3960#endif
3961 { "extend", float_cons, 'x' },
3962 { "ldouble", float_cons, 'x' },
3963 { "packed", float_cons, 'p' },
f0927246
NC
3964#ifdef TE_PE
3965 {"secrel32", pe_directive_secrel, 0},
3966#endif
c19d1205
ZW
3967 { 0, 0, 0 }
3968};
3969\f
3970/* Parser functions used exclusively in instruction operands. */
b99bd4ef 3971
c19d1205
ZW
3972/* Generic immediate-value read function for use in insn parsing.
3973 STR points to the beginning of the immediate (the leading #);
3974 VAL receives the value; if the value is outside [MIN, MAX]
3975 issue an error. PREFIX_OPT is true if the immediate prefix is
3976 optional. */
b99bd4ef 3977
c19d1205
ZW
3978static int
3979parse_immediate (char **str, int *val, int min, int max,
3980 bfd_boolean prefix_opt)
3981{
3982 expressionS exp;
3983 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
3984 if (exp.X_op != O_constant)
b99bd4ef 3985 {
c19d1205
ZW
3986 inst.error = _("constant expression required");
3987 return FAIL;
3988 }
b99bd4ef 3989
c19d1205
ZW
3990 if (exp.X_add_number < min || exp.X_add_number > max)
3991 {
3992 inst.error = _("immediate value out of range");
3993 return FAIL;
3994 }
b99bd4ef 3995
c19d1205
ZW
3996 *val = exp.X_add_number;
3997 return SUCCESS;
3998}
b99bd4ef 3999
5287ad62
JB
4000/* Less-generic immediate-value read function with the possibility of loading a
4001 big (64-bit) immediate, as required by Neon VMOV and VMVN immediate
4002 instructions. Puts the result directly in inst.operands[i]. */
4003
4004static int
4005parse_big_immediate (char **str, int i)
4006{
4007 expressionS exp;
4008 char *ptr = *str;
4009
4010 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4011
4012 if (exp.X_op == O_constant)
4013 inst.operands[i].imm = exp.X_add_number;
4014 else if (exp.X_op == O_big
4015 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4016 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4017 {
4018 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4019 /* Bignums have their least significant bits in
4020 generic_bignum[0]. Make sure we put 32 bits in imm and
4021 32 bits in reg, in a (hopefully) portable way. */
4022 assert (parts != 0);
4023 inst.operands[i].imm = 0;
4024 for (j = 0; j < parts; j++, idx++)
4025 inst.operands[i].imm |= generic_bignum[idx]
4026 << (LITTLENUM_NUMBER_OF_BITS * j);
4027 inst.operands[i].reg = 0;
4028 for (j = 0; j < parts; j++, idx++)
4029 inst.operands[i].reg |= generic_bignum[idx]
4030 << (LITTLENUM_NUMBER_OF_BITS * j);
4031 inst.operands[i].regisimm = 1;
4032 }
4033 else
4034 return FAIL;
4035
4036 *str = ptr;
4037
4038 return SUCCESS;
4039}
4040
c19d1205
ZW
4041/* Returns the pseudo-register number of an FPA immediate constant,
4042 or FAIL if there isn't a valid constant here. */
b99bd4ef 4043
c19d1205
ZW
4044static int
4045parse_fpa_immediate (char ** str)
4046{
4047 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4048 char * save_in;
4049 expressionS exp;
4050 int i;
4051 int j;
b99bd4ef 4052
c19d1205
ZW
4053 /* First try and match exact strings, this is to guarantee
4054 that some formats will work even for cross assembly. */
b99bd4ef 4055
c19d1205
ZW
4056 for (i = 0; fp_const[i]; i++)
4057 {
4058 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4059 {
c19d1205 4060 char *start = *str;
b99bd4ef 4061
c19d1205
ZW
4062 *str += strlen (fp_const[i]);
4063 if (is_end_of_line[(unsigned char) **str])
4064 return i + 8;
4065 *str = start;
4066 }
4067 }
b99bd4ef 4068
c19d1205
ZW
4069 /* Just because we didn't get a match doesn't mean that the constant
4070 isn't valid, just that it is in a format that we don't
4071 automatically recognize. Try parsing it with the standard
4072 expression routines. */
b99bd4ef 4073
c19d1205 4074 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4075
c19d1205
ZW
4076 /* Look for a raw floating point number. */
4077 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4078 && is_end_of_line[(unsigned char) *save_in])
4079 {
4080 for (i = 0; i < NUM_FLOAT_VALS; i++)
4081 {
4082 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4083 {
c19d1205
ZW
4084 if (words[j] != fp_values[i][j])
4085 break;
b99bd4ef
NC
4086 }
4087
c19d1205 4088 if (j == MAX_LITTLENUMS)
b99bd4ef 4089 {
c19d1205
ZW
4090 *str = save_in;
4091 return i + 8;
b99bd4ef
NC
4092 }
4093 }
4094 }
b99bd4ef 4095
c19d1205
ZW
4096 /* Try and parse a more complex expression, this will probably fail
4097 unless the code uses a floating point prefix (eg "0f"). */
4098 save_in = input_line_pointer;
4099 input_line_pointer = *str;
4100 if (expression (&exp) == absolute_section
4101 && exp.X_op == O_big
4102 && exp.X_add_number < 0)
4103 {
4104 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4105 Ditto for 15. */
4106 if (gen_to_words (words, 5, (long) 15) == 0)
4107 {
4108 for (i = 0; i < NUM_FLOAT_VALS; i++)
4109 {
4110 for (j = 0; j < MAX_LITTLENUMS; j++)
4111 {
4112 if (words[j] != fp_values[i][j])
4113 break;
4114 }
b99bd4ef 4115
c19d1205
ZW
4116 if (j == MAX_LITTLENUMS)
4117 {
4118 *str = input_line_pointer;
4119 input_line_pointer = save_in;
4120 return i + 8;
4121 }
4122 }
4123 }
b99bd4ef
NC
4124 }
4125
c19d1205
ZW
4126 *str = input_line_pointer;
4127 input_line_pointer = save_in;
4128 inst.error = _("invalid FPA immediate expression");
4129 return FAIL;
b99bd4ef
NC
4130}
4131
136da414
JB
4132/* Returns 1 if a number has "quarter-precision" float format
4133 0baBbbbbbc defgh000 00000000 00000000. */
4134
4135static int
4136is_quarter_float (unsigned imm)
4137{
4138 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4139 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4140}
4141
4142/* Parse an 8-bit "quarter-precision" floating point number of the form:
4143 0baBbbbbbc defgh000 00000000 00000000.
4144 The minus-zero case needs special handling, since it can't be encoded in the
4145 "quarter-precision" float format, but can nonetheless be loaded as an integer
4146 constant. */
4147
4148static unsigned
4149parse_qfloat_immediate (char **ccp, int *immed)
4150{
4151 char *str = *ccp;
4152 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4153
4154 skip_past_char (&str, '#');
4155
4156 if ((str = atof_ieee (str, 's', words)) != NULL)
4157 {
4158 unsigned fpword = 0;
4159 int i;
4160
4161 /* Our FP word must be 32 bits (single-precision FP). */
4162 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4163 {
4164 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4165 fpword |= words[i];
4166 }
4167
4168 if (is_quarter_float (fpword) || fpword == 0x80000000)
4169 *immed = fpword;
4170 else
4171 return FAIL;
4172
4173 *ccp = str;
4174
4175 return SUCCESS;
4176 }
4177
4178 return FAIL;
4179}
4180
c19d1205
ZW
4181/* Shift operands. */
4182enum shift_kind
b99bd4ef 4183{
c19d1205
ZW
4184 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4185};
b99bd4ef 4186
c19d1205
ZW
4187struct asm_shift_name
4188{
4189 const char *name;
4190 enum shift_kind kind;
4191};
b99bd4ef 4192
c19d1205
ZW
4193/* Third argument to parse_shift. */
4194enum parse_shift_mode
4195{
4196 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4197 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4198 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4199 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4200 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4201};
b99bd4ef 4202
c19d1205
ZW
4203/* Parse a <shift> specifier on an ARM data processing instruction.
4204 This has three forms:
b99bd4ef 4205
c19d1205
ZW
4206 (LSL|LSR|ASL|ASR|ROR) Rs
4207 (LSL|LSR|ASL|ASR|ROR) #imm
4208 RRX
b99bd4ef 4209
c19d1205
ZW
4210 Note that ASL is assimilated to LSL in the instruction encoding, and
4211 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4212
c19d1205
ZW
4213static int
4214parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4215{
c19d1205
ZW
4216 const struct asm_shift_name *shift_name;
4217 enum shift_kind shift;
4218 char *s = *str;
4219 char *p = s;
4220 int reg;
b99bd4ef 4221
c19d1205
ZW
4222 for (p = *str; ISALPHA (*p); p++)
4223 ;
b99bd4ef 4224
c19d1205 4225 if (p == *str)
b99bd4ef 4226 {
c19d1205
ZW
4227 inst.error = _("shift expression expected");
4228 return FAIL;
b99bd4ef
NC
4229 }
4230
c19d1205
ZW
4231 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4232
4233 if (shift_name == NULL)
b99bd4ef 4234 {
c19d1205
ZW
4235 inst.error = _("shift expression expected");
4236 return FAIL;
b99bd4ef
NC
4237 }
4238
c19d1205 4239 shift = shift_name->kind;
b99bd4ef 4240
c19d1205
ZW
4241 switch (mode)
4242 {
4243 case NO_SHIFT_RESTRICT:
4244 case SHIFT_IMMEDIATE: break;
b99bd4ef 4245
c19d1205
ZW
4246 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4247 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4248 {
4249 inst.error = _("'LSL' or 'ASR' required");
4250 return FAIL;
4251 }
4252 break;
b99bd4ef 4253
c19d1205
ZW
4254 case SHIFT_LSL_IMMEDIATE:
4255 if (shift != SHIFT_LSL)
4256 {
4257 inst.error = _("'LSL' required");
4258 return FAIL;
4259 }
4260 break;
b99bd4ef 4261
c19d1205
ZW
4262 case SHIFT_ASR_IMMEDIATE:
4263 if (shift != SHIFT_ASR)
4264 {
4265 inst.error = _("'ASR' required");
4266 return FAIL;
4267 }
4268 break;
b99bd4ef 4269
c19d1205
ZW
4270 default: abort ();
4271 }
b99bd4ef 4272
c19d1205
ZW
4273 if (shift != SHIFT_RRX)
4274 {
4275 /* Whitespace can appear here if the next thing is a bare digit. */
4276 skip_whitespace (p);
b99bd4ef 4277
c19d1205 4278 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4279 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4280 {
4281 inst.operands[i].imm = reg;
4282 inst.operands[i].immisreg = 1;
4283 }
4284 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4285 return FAIL;
4286 }
4287 inst.operands[i].shift_kind = shift;
4288 inst.operands[i].shifted = 1;
4289 *str = p;
4290 return SUCCESS;
b99bd4ef
NC
4291}
4292
c19d1205 4293/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4294
c19d1205
ZW
4295 #<immediate>
4296 #<immediate>, <rotate>
4297 <Rm>
4298 <Rm>, <shift>
b99bd4ef 4299
c19d1205
ZW
4300 where <shift> is defined by parse_shift above, and <rotate> is a
4301 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4302 is deferred to md_apply_fix. */
b99bd4ef 4303
c19d1205
ZW
4304static int
4305parse_shifter_operand (char **str, int i)
4306{
4307 int value;
4308 expressionS expr;
b99bd4ef 4309
dcbf9037 4310 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4311 {
4312 inst.operands[i].reg = value;
4313 inst.operands[i].isreg = 1;
b99bd4ef 4314
c19d1205
ZW
4315 /* parse_shift will override this if appropriate */
4316 inst.reloc.exp.X_op = O_constant;
4317 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4318
c19d1205
ZW
4319 if (skip_past_comma (str) == FAIL)
4320 return SUCCESS;
b99bd4ef 4321
c19d1205
ZW
4322 /* Shift operation on register. */
4323 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4324 }
4325
c19d1205
ZW
4326 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4327 return FAIL;
b99bd4ef 4328
c19d1205 4329 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4330 {
c19d1205
ZW
4331 /* #x, y -- ie explicit rotation by Y. */
4332 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4333 return FAIL;
b99bd4ef 4334
c19d1205
ZW
4335 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4336 {
4337 inst.error = _("constant expression expected");
4338 return FAIL;
4339 }
b99bd4ef 4340
c19d1205
ZW
4341 value = expr.X_add_number;
4342 if (value < 0 || value > 30 || value % 2 != 0)
4343 {
4344 inst.error = _("invalid rotation");
4345 return FAIL;
4346 }
4347 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4348 {
4349 inst.error = _("invalid constant");
4350 return FAIL;
4351 }
09d92015 4352
55cf6793 4353 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4354 inst.reloc.exp.X_add_number
4355 = (((inst.reloc.exp.X_add_number << (32 - value))
4356 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4357 }
4358
c19d1205
ZW
4359 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4360 inst.reloc.pc_rel = 0;
4361 return SUCCESS;
09d92015
MM
4362}
4363
4962c51a
MS
4364/* Group relocation information. Each entry in the table contains the
4365 textual name of the relocation as may appear in assembler source
4366 and must end with a colon.
4367 Along with this textual name are the relocation codes to be used if
4368 the corresponding instruction is an ALU instruction (ADD or SUB only),
4369 an LDR, an LDRS, or an LDC. */
4370
4371struct group_reloc_table_entry
4372{
4373 const char *name;
4374 int alu_code;
4375 int ldr_code;
4376 int ldrs_code;
4377 int ldc_code;
4378};
4379
4380typedef enum
4381{
4382 /* Varieties of non-ALU group relocation. */
4383
4384 GROUP_LDR,
4385 GROUP_LDRS,
4386 GROUP_LDC
4387} group_reloc_type;
4388
4389static struct group_reloc_table_entry group_reloc_table[] =
4390 { /* Program counter relative: */
4391 { "pc_g0_nc",
4392 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4393 0, /* LDR */
4394 0, /* LDRS */
4395 0 }, /* LDC */
4396 { "pc_g0",
4397 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4398 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4399 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4400 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4401 { "pc_g1_nc",
4402 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4403 0, /* LDR */
4404 0, /* LDRS */
4405 0 }, /* LDC */
4406 { "pc_g1",
4407 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4408 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4409 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4410 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4411 { "pc_g2",
4412 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4413 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4414 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4415 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4416 /* Section base relative */
4417 { "sb_g0_nc",
4418 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4419 0, /* LDR */
4420 0, /* LDRS */
4421 0 }, /* LDC */
4422 { "sb_g0",
4423 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4424 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4425 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4426 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4427 { "sb_g1_nc",
4428 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4429 0, /* LDR */
4430 0, /* LDRS */
4431 0 }, /* LDC */
4432 { "sb_g1",
4433 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4434 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4435 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4436 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4437 { "sb_g2",
4438 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4439 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4440 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4441 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4442
4443/* Given the address of a pointer pointing to the textual name of a group
4444 relocation as may appear in assembler source, attempt to find its details
4445 in group_reloc_table. The pointer will be updated to the character after
4446 the trailing colon. On failure, FAIL will be returned; SUCCESS
4447 otherwise. On success, *entry will be updated to point at the relevant
4448 group_reloc_table entry. */
4449
4450static int
4451find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4452{
4453 unsigned int i;
4454 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4455 {
4456 int length = strlen (group_reloc_table[i].name);
4457
4458 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0 &&
4459 (*str)[length] == ':')
4460 {
4461 *out = &group_reloc_table[i];
4462 *str += (length + 1);
4463 return SUCCESS;
4464 }
4465 }
4466
4467 return FAIL;
4468}
4469
4470/* Parse a <shifter_operand> for an ARM data processing instruction
4471 (as for parse_shifter_operand) where group relocations are allowed:
4472
4473 #<immediate>
4474 #<immediate>, <rotate>
4475 #:<group_reloc>:<expression>
4476 <Rm>
4477 <Rm>, <shift>
4478
4479 where <group_reloc> is one of the strings defined in group_reloc_table.
4480 The hashes are optional.
4481
4482 Everything else is as for parse_shifter_operand. */
4483
4484static parse_operand_result
4485parse_shifter_operand_group_reloc (char **str, int i)
4486{
4487 /* Determine if we have the sequence of characters #: or just :
4488 coming next. If we do, then we check for a group relocation.
4489 If we don't, punt the whole lot to parse_shifter_operand. */
4490
4491 if (((*str)[0] == '#' && (*str)[1] == ':')
4492 || (*str)[0] == ':')
4493 {
4494 struct group_reloc_table_entry *entry;
4495
4496 if ((*str)[0] == '#')
4497 (*str) += 2;
4498 else
4499 (*str)++;
4500
4501 /* Try to parse a group relocation. Anything else is an error. */
4502 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4503 {
4504 inst.error = _("unknown group relocation");
4505 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4506 }
4507
4508 /* We now have the group relocation table entry corresponding to
4509 the name in the assembler source. Next, we parse the expression. */
4510 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4511 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4512
4513 /* Record the relocation type (always the ALU variant here). */
4514 inst.reloc.type = entry->alu_code;
4515 assert (inst.reloc.type != 0);
4516
4517 return PARSE_OPERAND_SUCCESS;
4518 }
4519 else
4520 return parse_shifter_operand (str, i) == SUCCESS
4521 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4522
4523 /* Never reached. */
4524}
4525
c19d1205
ZW
4526/* Parse all forms of an ARM address expression. Information is written
4527 to inst.operands[i] and/or inst.reloc.
09d92015 4528
c19d1205 4529 Preindexed addressing (.preind=1):
09d92015 4530
c19d1205
ZW
4531 [Rn, #offset] .reg=Rn .reloc.exp=offset
4532 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4533 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4534 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4535
c19d1205 4536 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4537
c19d1205 4538 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4539
c19d1205
ZW
4540 [Rn], #offset .reg=Rn .reloc.exp=offset
4541 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4542 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4543 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4544
c19d1205 4545 Unindexed addressing (.preind=0, .postind=0):
09d92015 4546
c19d1205 4547 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4548
c19d1205 4549 Other:
09d92015 4550
c19d1205
ZW
4551 [Rn]{!} shorthand for [Rn,#0]{!}
4552 =immediate .isreg=0 .reloc.exp=immediate
4553 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4554
c19d1205
ZW
4555 It is the caller's responsibility to check for addressing modes not
4556 supported by the instruction, and to set inst.reloc.type. */
4557
4962c51a
MS
4558static parse_operand_result
4559parse_address_main (char **str, int i, int group_relocations,
4560 group_reloc_type group_type)
09d92015 4561{
c19d1205
ZW
4562 char *p = *str;
4563 int reg;
09d92015 4564
c19d1205 4565 if (skip_past_char (&p, '[') == FAIL)
09d92015 4566 {
c19d1205
ZW
4567 if (skip_past_char (&p, '=') == FAIL)
4568 {
4569 /* bare address - translate to PC-relative offset */
4570 inst.reloc.pc_rel = 1;
4571 inst.operands[i].reg = REG_PC;
4572 inst.operands[i].isreg = 1;
4573 inst.operands[i].preind = 1;
4574 }
4575 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4576
c19d1205 4577 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4578 return PARSE_OPERAND_FAIL;
09d92015 4579
c19d1205 4580 *str = p;
4962c51a 4581 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4582 }
4583
dcbf9037 4584 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4585 {
c19d1205 4586 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4587 return PARSE_OPERAND_FAIL;
09d92015 4588 }
c19d1205
ZW
4589 inst.operands[i].reg = reg;
4590 inst.operands[i].isreg = 1;
09d92015 4591
c19d1205 4592 if (skip_past_comma (&p) == SUCCESS)
09d92015 4593 {
c19d1205 4594 inst.operands[i].preind = 1;
09d92015 4595
c19d1205
ZW
4596 if (*p == '+') p++;
4597 else if (*p == '-') p++, inst.operands[i].negative = 1;
4598
dcbf9037 4599 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4600 {
c19d1205
ZW
4601 inst.operands[i].imm = reg;
4602 inst.operands[i].immisreg = 1;
4603
4604 if (skip_past_comma (&p) == SUCCESS)
4605 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4606 return PARSE_OPERAND_FAIL;
c19d1205 4607 }
5287ad62
JB
4608 else if (skip_past_char (&p, ':') == SUCCESS)
4609 {
4610 /* FIXME: '@' should be used here, but it's filtered out by generic
4611 code before we get to see it here. This may be subject to
4612 change. */
4613 expressionS exp;
4614 my_get_expression (&exp, &p, GE_NO_PREFIX);
4615 if (exp.X_op != O_constant)
4616 {
4617 inst.error = _("alignment must be constant");
4962c51a 4618 return PARSE_OPERAND_FAIL;
5287ad62
JB
4619 }
4620 inst.operands[i].imm = exp.X_add_number << 8;
4621 inst.operands[i].immisalign = 1;
4622 /* Alignments are not pre-indexes. */
4623 inst.operands[i].preind = 0;
4624 }
c19d1205
ZW
4625 else
4626 {
4627 if (inst.operands[i].negative)
4628 {
4629 inst.operands[i].negative = 0;
4630 p--;
4631 }
4962c51a
MS
4632
4633 if (group_relocations &&
4634 ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4635
4636 {
4637 struct group_reloc_table_entry *entry;
4638
4639 /* Skip over the #: or : sequence. */
4640 if (*p == '#')
4641 p += 2;
4642 else
4643 p++;
4644
4645 /* Try to parse a group relocation. Anything else is an
4646 error. */
4647 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4648 {
4649 inst.error = _("unknown group relocation");
4650 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4651 }
4652
4653 /* We now have the group relocation table entry corresponding to
4654 the name in the assembler source. Next, we parse the
4655 expression. */
4656 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4657 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4658
4659 /* Record the relocation type. */
4660 switch (group_type)
4661 {
4662 case GROUP_LDR:
4663 inst.reloc.type = entry->ldr_code;
4664 break;
4665
4666 case GROUP_LDRS:
4667 inst.reloc.type = entry->ldrs_code;
4668 break;
4669
4670 case GROUP_LDC:
4671 inst.reloc.type = entry->ldc_code;
4672 break;
4673
4674 default:
4675 assert (0);
4676 }
4677
4678 if (inst.reloc.type == 0)
4679 {
4680 inst.error = _("this group relocation is not allowed on this instruction");
4681 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4682 }
4683 }
4684 else
4685 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4686 return PARSE_OPERAND_FAIL;
09d92015
MM
4687 }
4688 }
4689
c19d1205 4690 if (skip_past_char (&p, ']') == FAIL)
09d92015 4691 {
c19d1205 4692 inst.error = _("']' expected");
4962c51a 4693 return PARSE_OPERAND_FAIL;
09d92015
MM
4694 }
4695
c19d1205
ZW
4696 if (skip_past_char (&p, '!') == SUCCESS)
4697 inst.operands[i].writeback = 1;
09d92015 4698
c19d1205 4699 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4700 {
c19d1205
ZW
4701 if (skip_past_char (&p, '{') == SUCCESS)
4702 {
4703 /* [Rn], {expr} - unindexed, with option */
4704 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4705 0, 255, TRUE) == FAIL)
4962c51a 4706 return PARSE_OPERAND_FAIL;
09d92015 4707
c19d1205
ZW
4708 if (skip_past_char (&p, '}') == FAIL)
4709 {
4710 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4711 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4712 }
4713 if (inst.operands[i].preind)
4714 {
4715 inst.error = _("cannot combine index with option");
4962c51a 4716 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4717 }
4718 *str = p;
4962c51a 4719 return PARSE_OPERAND_SUCCESS;
09d92015 4720 }
c19d1205
ZW
4721 else
4722 {
4723 inst.operands[i].postind = 1;
4724 inst.operands[i].writeback = 1;
09d92015 4725
c19d1205
ZW
4726 if (inst.operands[i].preind)
4727 {
4728 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4729 return PARSE_OPERAND_FAIL;
c19d1205 4730 }
09d92015 4731
c19d1205
ZW
4732 if (*p == '+') p++;
4733 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4734
dcbf9037 4735 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4736 {
5287ad62
JB
4737 /* We might be using the immediate for alignment already. If we
4738 are, OR the register number into the low-order bits. */
4739 if (inst.operands[i].immisalign)
4740 inst.operands[i].imm |= reg;
4741 else
4742 inst.operands[i].imm = reg;
c19d1205 4743 inst.operands[i].immisreg = 1;
a737bd4d 4744
c19d1205
ZW
4745 if (skip_past_comma (&p) == SUCCESS)
4746 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4747 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4748 }
4749 else
4750 {
4751 if (inst.operands[i].negative)
4752 {
4753 inst.operands[i].negative = 0;
4754 p--;
4755 }
4756 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4757 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4758 }
4759 }
a737bd4d
NC
4760 }
4761
c19d1205
ZW
4762 /* If at this point neither .preind nor .postind is set, we have a
4763 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4764 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4765 {
4766 inst.operands[i].preind = 1;
4767 inst.reloc.exp.X_op = O_constant;
4768 inst.reloc.exp.X_add_number = 0;
4769 }
4770 *str = p;
4962c51a
MS
4771 return PARSE_OPERAND_SUCCESS;
4772}
4773
4774static int
4775parse_address (char **str, int i)
4776{
4777 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4778 ? SUCCESS : FAIL;
4779}
4780
4781static parse_operand_result
4782parse_address_group_reloc (char **str, int i, group_reloc_type type)
4783{
4784 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4785}
4786
b6895b4f
PB
4787/* Parse an operand for a MOVW or MOVT instruction. */
4788static int
4789parse_half (char **str)
4790{
4791 char * p;
4792
4793 p = *str;
4794 skip_past_char (&p, '#');
4795 if (strncasecmp (p, ":lower16:", 9) == 0)
4796 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4797 else if (strncasecmp (p, ":upper16:", 9) == 0)
4798 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4799
4800 if (inst.reloc.type != BFD_RELOC_UNUSED)
4801 {
4802 p += 9;
4803 skip_whitespace(p);
4804 }
4805
4806 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4807 return FAIL;
4808
4809 if (inst.reloc.type == BFD_RELOC_UNUSED)
4810 {
4811 if (inst.reloc.exp.X_op != O_constant)
4812 {
4813 inst.error = _("constant expression expected");
4814 return FAIL;
4815 }
4816 if (inst.reloc.exp.X_add_number < 0
4817 || inst.reloc.exp.X_add_number > 0xffff)
4818 {
4819 inst.error = _("immediate value out of range");
4820 return FAIL;
4821 }
4822 }
4823 *str = p;
4824 return SUCCESS;
4825}
4826
c19d1205 4827/* Miscellaneous. */
a737bd4d 4828
c19d1205
ZW
4829/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
4830 or a bitmask suitable to be or-ed into the ARM msr instruction. */
4831static int
4832parse_psr (char **str)
09d92015 4833{
c19d1205
ZW
4834 char *p;
4835 unsigned long psr_field;
62b3e311
PB
4836 const struct asm_psr *psr;
4837 char *start;
09d92015 4838
c19d1205
ZW
4839 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
4840 feature for ease of use and backwards compatibility. */
4841 p = *str;
62b3e311 4842 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 4843 psr_field = SPSR_BIT;
62b3e311 4844 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
4845 psr_field = 0;
4846 else
62b3e311
PB
4847 {
4848 start = p;
4849 do
4850 p++;
4851 while (ISALNUM (*p) || *p == '_');
4852
4853 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
4854 if (!psr)
4855 return FAIL;
09d92015 4856
62b3e311
PB
4857 *str = p;
4858 return psr->field;
4859 }
09d92015 4860
62b3e311 4861 p += 4;
c19d1205
ZW
4862 if (*p == '_')
4863 {
4864 /* A suffix follows. */
c19d1205
ZW
4865 p++;
4866 start = p;
a737bd4d 4867
c19d1205
ZW
4868 do
4869 p++;
4870 while (ISALNUM (*p) || *p == '_');
a737bd4d 4871
c19d1205
ZW
4872 psr = hash_find_n (arm_psr_hsh, start, p - start);
4873 if (!psr)
4874 goto error;
a737bd4d 4875
c19d1205 4876 psr_field |= psr->field;
a737bd4d 4877 }
c19d1205 4878 else
a737bd4d 4879 {
c19d1205
ZW
4880 if (ISALNUM (*p))
4881 goto error; /* Garbage after "[CS]PSR". */
4882
4883 psr_field |= (PSR_c | PSR_f);
a737bd4d 4884 }
c19d1205
ZW
4885 *str = p;
4886 return psr_field;
a737bd4d 4887
c19d1205
ZW
4888 error:
4889 inst.error = _("flag for {c}psr instruction expected");
4890 return FAIL;
a737bd4d
NC
4891}
4892
c19d1205
ZW
4893/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
4894 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 4895
c19d1205
ZW
4896static int
4897parse_cps_flags (char **str)
a737bd4d 4898{
c19d1205
ZW
4899 int val = 0;
4900 int saw_a_flag = 0;
4901 char *s = *str;
a737bd4d 4902
c19d1205
ZW
4903 for (;;)
4904 switch (*s++)
4905 {
4906 case '\0': case ',':
4907 goto done;
a737bd4d 4908
c19d1205
ZW
4909 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
4910 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
4911 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 4912
c19d1205
ZW
4913 default:
4914 inst.error = _("unrecognized CPS flag");
4915 return FAIL;
4916 }
a737bd4d 4917
c19d1205
ZW
4918 done:
4919 if (saw_a_flag == 0)
a737bd4d 4920 {
c19d1205
ZW
4921 inst.error = _("missing CPS flags");
4922 return FAIL;
a737bd4d 4923 }
a737bd4d 4924
c19d1205
ZW
4925 *str = s - 1;
4926 return val;
a737bd4d
NC
4927}
4928
c19d1205
ZW
4929/* Parse an endian specifier ("BE" or "LE", case insensitive);
4930 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
4931
4932static int
c19d1205 4933parse_endian_specifier (char **str)
a737bd4d 4934{
c19d1205
ZW
4935 int little_endian;
4936 char *s = *str;
a737bd4d 4937
c19d1205
ZW
4938 if (strncasecmp (s, "BE", 2))
4939 little_endian = 0;
4940 else if (strncasecmp (s, "LE", 2))
4941 little_endian = 1;
4942 else
a737bd4d 4943 {
c19d1205 4944 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4945 return FAIL;
4946 }
4947
c19d1205 4948 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 4949 {
c19d1205 4950 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
4951 return FAIL;
4952 }
4953
c19d1205
ZW
4954 *str = s + 2;
4955 return little_endian;
4956}
a737bd4d 4957
c19d1205
ZW
4958/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
4959 value suitable for poking into the rotate field of an sxt or sxta
4960 instruction, or FAIL on error. */
4961
4962static int
4963parse_ror (char **str)
4964{
4965 int rot;
4966 char *s = *str;
4967
4968 if (strncasecmp (s, "ROR", 3) == 0)
4969 s += 3;
4970 else
a737bd4d 4971 {
c19d1205 4972 inst.error = _("missing rotation field after comma");
a737bd4d
NC
4973 return FAIL;
4974 }
c19d1205
ZW
4975
4976 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
4977 return FAIL;
4978
4979 switch (rot)
a737bd4d 4980 {
c19d1205
ZW
4981 case 0: *str = s; return 0x0;
4982 case 8: *str = s; return 0x1;
4983 case 16: *str = s; return 0x2;
4984 case 24: *str = s; return 0x3;
4985
4986 default:
4987 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
4988 return FAIL;
4989 }
c19d1205 4990}
a737bd4d 4991
c19d1205
ZW
4992/* Parse a conditional code (from conds[] below). The value returned is in the
4993 range 0 .. 14, or FAIL. */
4994static int
4995parse_cond (char **str)
4996{
4997 char *p, *q;
4998 const struct asm_cond *c;
a737bd4d 4999
c19d1205
ZW
5000 p = q = *str;
5001 while (ISALPHA (*q))
5002 q++;
a737bd4d 5003
c19d1205
ZW
5004 c = hash_find_n (arm_cond_hsh, p, q - p);
5005 if (!c)
a737bd4d 5006 {
c19d1205 5007 inst.error = _("condition required");
a737bd4d
NC
5008 return FAIL;
5009 }
5010
c19d1205
ZW
5011 *str = q;
5012 return c->value;
5013}
5014
62b3e311
PB
5015/* Parse an option for a barrier instruction. Returns the encoding for the
5016 option, or FAIL. */
5017static int
5018parse_barrier (char **str)
5019{
5020 char *p, *q;
5021 const struct asm_barrier_opt *o;
5022
5023 p = q = *str;
5024 while (ISALPHA (*q))
5025 q++;
5026
5027 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5028 if (!o)
5029 return FAIL;
5030
5031 *str = q;
5032 return o->value;
5033}
5034
92e90b6e
PB
5035/* Parse the operands of a table branch instruction. Similar to a memory
5036 operand. */
5037static int
5038parse_tb (char **str)
5039{
5040 char * p = *str;
5041 int reg;
5042
5043 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5044 {
5045 inst.error = _("'[' expected");
5046 return FAIL;
5047 }
92e90b6e 5048
dcbf9037 5049 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5050 {
5051 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5052 return FAIL;
5053 }
5054 inst.operands[0].reg = reg;
5055
5056 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5057 {
5058 inst.error = _("',' expected");
5059 return FAIL;
5060 }
92e90b6e 5061
dcbf9037 5062 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5063 {
5064 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5065 return FAIL;
5066 }
5067 inst.operands[0].imm = reg;
5068
5069 if (skip_past_comma (&p) == SUCCESS)
5070 {
5071 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5072 return FAIL;
5073 if (inst.reloc.exp.X_add_number != 1)
5074 {
5075 inst.error = _("invalid shift");
5076 return FAIL;
5077 }
5078 inst.operands[0].shifted = 1;
5079 }
5080
5081 if (skip_past_char (&p, ']') == FAIL)
5082 {
5083 inst.error = _("']' expected");
5084 return FAIL;
5085 }
5086 *str = p;
5087 return SUCCESS;
5088}
5089
5287ad62
JB
5090/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5091 information on the types the operands can take and how they are encoded.
037e8744
JB
5092 Up to four operands may be read; this function handles setting the
5093 ".present" field for each read operand itself.
5287ad62
JB
5094 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5095 else returns FAIL. */
5096
5097static int
5098parse_neon_mov (char **str, int *which_operand)
5099{
5100 int i = *which_operand, val;
5101 enum arm_reg_type rtype;
5102 char *ptr = *str;
dcbf9037 5103 struct neon_type_el optype;
5287ad62 5104
dcbf9037 5105 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5106 {
5107 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5108 inst.operands[i].reg = val;
5109 inst.operands[i].isscalar = 1;
dcbf9037 5110 inst.operands[i].vectype = optype;
5287ad62
JB
5111 inst.operands[i++].present = 1;
5112
5113 if (skip_past_comma (&ptr) == FAIL)
5114 goto wanted_comma;
5115
dcbf9037 5116 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62
JB
5117 goto wanted_arm;
5118
5119 inst.operands[i].reg = val;
5120 inst.operands[i].isreg = 1;
5121 inst.operands[i].present = 1;
5122 }
037e8744 5123 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5124 != FAIL)
5287ad62
JB
5125 {
5126 /* Cases 0, 1, 2, 3, 5 (D only). */
5127 if (skip_past_comma (&ptr) == FAIL)
5128 goto wanted_comma;
5129
5130 inst.operands[i].reg = val;
5131 inst.operands[i].isreg = 1;
5132 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5133 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5134 inst.operands[i].isvec = 1;
dcbf9037 5135 inst.operands[i].vectype = optype;
5287ad62
JB
5136 inst.operands[i++].present = 1;
5137
dcbf9037 5138 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5139 {
037e8744
JB
5140 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5141 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5142 inst.operands[i].reg = val;
5143 inst.operands[i].isreg = 1;
037e8744 5144 inst.operands[i].present = 1;
5287ad62
JB
5145
5146 if (rtype == REG_TYPE_NQ)
5147 {
dcbf9037 5148 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5149 return FAIL;
5150 }
037e8744
JB
5151 else if (rtype != REG_TYPE_VFS)
5152 {
5153 i++;
5154 if (skip_past_comma (&ptr) == FAIL)
5155 goto wanted_comma;
5156 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5157 goto wanted_arm;
5158 inst.operands[i].reg = val;
5159 inst.operands[i].isreg = 1;
5160 inst.operands[i].present = 1;
5161 }
5287ad62 5162 }
136da414 5163 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
136da414 5164 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
037e8744
JB
5165 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5166 Case 10: VMOV.F32 <Sd>, #<imm>
5167 Case 11: VMOV.F64 <Dd>, #<imm> */
5168 ;
5287ad62 5169 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5287ad62
JB
5170 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5171 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
037e8744
JB
5172 ;
5173 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5174 &optype)) != FAIL)
5287ad62
JB
5175 {
5176 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5177 Case 1: VMOV<c><q> <Dd>, <Dm>
5178 Case 8: VMOV.F32 <Sd>, <Sm>
5179 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5180
5181 inst.operands[i].reg = val;
5182 inst.operands[i].isreg = 1;
5183 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5184 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5185 inst.operands[i].isvec = 1;
dcbf9037 5186 inst.operands[i].vectype = optype;
5287ad62 5187 inst.operands[i].present = 1;
037e8744
JB
5188
5189 if (skip_past_comma (&ptr) == SUCCESS)
5190 {
5191 /* Case 15. */
5192 i++;
5193
5194 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5195 goto wanted_arm;
5196
5197 inst.operands[i].reg = val;
5198 inst.operands[i].isreg = 1;
5199 inst.operands[i++].present = 1;
5200
5201 if (skip_past_comma (&ptr) == FAIL)
5202 goto wanted_comma;
5203
5204 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5205 goto wanted_arm;
5206
5207 inst.operands[i].reg = val;
5208 inst.operands[i].isreg = 1;
5209 inst.operands[i++].present = 1;
5210 }
5287ad62
JB
5211 }
5212 else
5213 {
dcbf9037 5214 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5215 return FAIL;
5216 }
5217 }
dcbf9037 5218 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5219 {
5220 /* Cases 6, 7. */
5221 inst.operands[i].reg = val;
5222 inst.operands[i].isreg = 1;
5223 inst.operands[i++].present = 1;
5224
5225 if (skip_past_comma (&ptr) == FAIL)
5226 goto wanted_comma;
5227
dcbf9037 5228 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5229 {
5230 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5231 inst.operands[i].reg = val;
5232 inst.operands[i].isscalar = 1;
5233 inst.operands[i].present = 1;
dcbf9037 5234 inst.operands[i].vectype = optype;
5287ad62 5235 }
dcbf9037 5236 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5237 {
5238 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5239 inst.operands[i].reg = val;
5240 inst.operands[i].isreg = 1;
5241 inst.operands[i++].present = 1;
5242
5243 if (skip_past_comma (&ptr) == FAIL)
5244 goto wanted_comma;
5245
037e8744 5246 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5247 == FAIL)
5287ad62 5248 {
037e8744 5249 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5250 return FAIL;
5251 }
5252
5253 inst.operands[i].reg = val;
5254 inst.operands[i].isreg = 1;
037e8744
JB
5255 inst.operands[i].isvec = 1;
5256 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5257 inst.operands[i].vectype = optype;
5287ad62 5258 inst.operands[i].present = 1;
037e8744
JB
5259
5260 if (rtype == REG_TYPE_VFS)
5261 {
5262 /* Case 14. */
5263 i++;
5264 if (skip_past_comma (&ptr) == FAIL)
5265 goto wanted_comma;
5266 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5267 &optype)) == FAIL)
5268 {
5269 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5270 return FAIL;
5271 }
5272 inst.operands[i].reg = val;
5273 inst.operands[i].isreg = 1;
5274 inst.operands[i].isvec = 1;
5275 inst.operands[i].issingle = 1;
5276 inst.operands[i].vectype = optype;
5277 inst.operands[i].present = 1;
5278 }
5279 }
5280 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5281 != FAIL)
5282 {
5283 /* Case 13. */
5284 inst.operands[i].reg = val;
5285 inst.operands[i].isreg = 1;
5286 inst.operands[i].isvec = 1;
5287 inst.operands[i].issingle = 1;
5288 inst.operands[i].vectype = optype;
5289 inst.operands[i++].present = 1;
5287ad62
JB
5290 }
5291 }
5292 else
5293 {
dcbf9037 5294 first_error (_("parse error"));
5287ad62
JB
5295 return FAIL;
5296 }
5297
5298 /* Successfully parsed the operands. Update args. */
5299 *which_operand = i;
5300 *str = ptr;
5301 return SUCCESS;
5302
5303 wanted_comma:
dcbf9037 5304 first_error (_("expected comma"));
5287ad62
JB
5305 return FAIL;
5306
5307 wanted_arm:
dcbf9037 5308 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5309 return FAIL;
5287ad62
JB
5310}
5311
c19d1205
ZW
5312/* Matcher codes for parse_operands. */
5313enum operand_parse_code
5314{
5315 OP_stop, /* end of line */
5316
5317 OP_RR, /* ARM register */
5318 OP_RRnpc, /* ARM register, not r15 */
5319 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5320 OP_RRw, /* ARM register, not r15, optional trailing ! */
5321 OP_RCP, /* Coprocessor number */
5322 OP_RCN, /* Coprocessor register */
5323 OP_RF, /* FPA register */
5324 OP_RVS, /* VFP single precision register */
5287ad62
JB
5325 OP_RVD, /* VFP double precision register (0..15) */
5326 OP_RND, /* Neon double precision register (0..31) */
5327 OP_RNQ, /* Neon quad precision register */
037e8744 5328 OP_RVSD, /* VFP single or double precision register */
5287ad62 5329 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5330 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5331 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5332 OP_RVC, /* VFP control register */
5333 OP_RMF, /* Maverick F register */
5334 OP_RMD, /* Maverick D register */
5335 OP_RMFX, /* Maverick FX register */
5336 OP_RMDX, /* Maverick DX register */
5337 OP_RMAX, /* Maverick AX register */
5338 OP_RMDS, /* Maverick DSPSC register */
5339 OP_RIWR, /* iWMMXt wR register */
5340 OP_RIWC, /* iWMMXt wC register */
5341 OP_RIWG, /* iWMMXt wCG register */
5342 OP_RXA, /* XScale accumulator register */
5343
5344 OP_REGLST, /* ARM register list */
5345 OP_VRSLST, /* VFP single-precision register list */
5346 OP_VRDLST, /* VFP double-precision register list */
037e8744 5347 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5348 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5349 OP_NSTRLST, /* Neon element/structure list */
5350
5351 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5352 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5353 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5354 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5355 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5356 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5357 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5358 OP_VMOV, /* Neon VMOV operands. */
5359 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5360 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
5361
5362 OP_I0, /* immediate zero */
c19d1205
ZW
5363 OP_I7, /* immediate value 0 .. 7 */
5364 OP_I15, /* 0 .. 15 */
5365 OP_I16, /* 1 .. 16 */
5287ad62 5366 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5367 OP_I31, /* 0 .. 31 */
5368 OP_I31w, /* 0 .. 31, optional trailing ! */
5369 OP_I32, /* 1 .. 32 */
5287ad62
JB
5370 OP_I32z, /* 0 .. 32 */
5371 OP_I63, /* 0 .. 63 */
c19d1205 5372 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5373 OP_I64, /* 1 .. 64 */
5374 OP_I64z, /* 0 .. 64 */
c19d1205 5375 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5376
5377 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5378 OP_I7b, /* 0 .. 7 */
5379 OP_I15b, /* 0 .. 15 */
5380 OP_I31b, /* 0 .. 31 */
5381
5382 OP_SH, /* shifter operand */
4962c51a 5383 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5384 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5385 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5386 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5387 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5388 OP_EXP, /* arbitrary expression */
5389 OP_EXPi, /* same, with optional immediate prefix */
5390 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5391 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5392
5393 OP_CPSF, /* CPS flags */
5394 OP_ENDI, /* Endianness specifier */
5395 OP_PSR, /* CPSR/SPSR mask for msr */
5396 OP_COND, /* conditional code */
92e90b6e 5397 OP_TB, /* Table branch. */
c19d1205 5398
037e8744
JB
5399 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5400 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5401
c19d1205
ZW
5402 OP_RRnpc_I0, /* ARM register or literal 0 */
5403 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5404 OP_RR_EXi, /* ARM register or expression with imm prefix */
5405 OP_RF_IF, /* FPA register or immediate */
5406 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5407 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5408
5409 /* Optional operands. */
5410 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5411 OP_oI31b, /* 0 .. 31 */
5287ad62 5412 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5413 OP_oIffffb, /* 0 .. 65535 */
5414 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5415
5416 OP_oRR, /* ARM register */
5417 OP_oRRnpc, /* ARM register, not the PC */
5287ad62
JB
5418 OP_oRND, /* Optional Neon double precision register */
5419 OP_oRNQ, /* Optional Neon quad precision register */
5420 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5421 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5422 OP_oSHll, /* LSL immediate */
5423 OP_oSHar, /* ASR immediate */
5424 OP_oSHllar, /* LSL or ASR immediate */
5425 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5426 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5427
5428 OP_FIRST_OPTIONAL = OP_oI7b
5429};
a737bd4d 5430
c19d1205
ZW
5431/* Generic instruction operand parser. This does no encoding and no
5432 semantic validation; it merely squirrels values away in the inst
5433 structure. Returns SUCCESS or FAIL depending on whether the
5434 specified grammar matched. */
5435static int
ca3f61f7 5436parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5437{
5438 unsigned const char *upat = pattern;
5439 char *backtrack_pos = 0;
5440 const char *backtrack_error = 0;
5441 int i, val, backtrack_index = 0;
5287ad62 5442 enum arm_reg_type rtype;
4962c51a 5443 parse_operand_result result;
c19d1205
ZW
5444
5445#define po_char_or_fail(chr) do { \
5446 if (skip_past_char (&str, chr) == FAIL) \
5447 goto bad_args; \
5448} while (0)
5449
dcbf9037
JB
5450#define po_reg_or_fail(regtype) do { \
5451 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5452 &inst.operands[i].vectype); \
5453 if (val == FAIL) \
5454 { \
5455 first_error (_(reg_expected_msgs[regtype])); \
5456 goto failure; \
5457 } \
5458 inst.operands[i].reg = val; \
5459 inst.operands[i].isreg = 1; \
5460 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5461 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5462 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5463 || rtype == REG_TYPE_VFD \
5464 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5465} while (0)
5466
dcbf9037
JB
5467#define po_reg_or_goto(regtype, label) do { \
5468 val = arm_typed_reg_parse (&str, regtype, &rtype, \
5469 &inst.operands[i].vectype); \
5470 if (val == FAIL) \
5471 goto label; \
5472 \
5473 inst.operands[i].reg = val; \
5474 inst.operands[i].isreg = 1; \
5475 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
037e8744
JB
5476 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5477 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5478 || rtype == REG_TYPE_VFD \
5479 || rtype == REG_TYPE_NQ); \
c19d1205
ZW
5480} while (0)
5481
5482#define po_imm_or_fail(min, max, popt) do { \
5483 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5484 goto failure; \
5485 inst.operands[i].imm = val; \
5486} while (0)
5487
dcbf9037
JB
5488#define po_scalar_or_goto(elsz, label) do { \
5489 val = parse_scalar (&str, elsz, &inst.operands[i].vectype); \
5490 if (val == FAIL) \
5491 goto label; \
5492 inst.operands[i].reg = val; \
5493 inst.operands[i].isscalar = 1; \
5287ad62
JB
5494} while (0)
5495
c19d1205
ZW
5496#define po_misc_or_fail(expr) do { \
5497 if (expr) \
5498 goto failure; \
5499} while (0)
5500
4962c51a
MS
5501#define po_misc_or_fail_no_backtrack(expr) do { \
5502 result = expr; \
5503 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK)\
5504 backtrack_pos = 0; \
5505 if (result != PARSE_OPERAND_SUCCESS) \
5506 goto failure; \
5507} while (0)
5508
c19d1205
ZW
5509 skip_whitespace (str);
5510
5511 for (i = 0; upat[i] != OP_stop; i++)
5512 {
5513 if (upat[i] >= OP_FIRST_OPTIONAL)
5514 {
5515 /* Remember where we are in case we need to backtrack. */
5516 assert (!backtrack_pos);
5517 backtrack_pos = str;
5518 backtrack_error = inst.error;
5519 backtrack_index = i;
5520 }
5521
5522 if (i > 0)
5523 po_char_or_fail (',');
5524
5525 switch (upat[i])
5526 {
5527 /* Registers */
5528 case OP_oRRnpc:
5529 case OP_RRnpc:
5530 case OP_oRR:
5531 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5532 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5533 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5534 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5535 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5536 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5537 case OP_oRND:
5538 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
c19d1205
ZW
5539 case OP_RVC: po_reg_or_fail (REG_TYPE_VFC); break;
5540 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5541 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5542 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5543 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5544 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5545 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5546 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5547 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5548 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5549 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5550 case OP_oRNQ:
5551 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5552 case OP_oRNDQ:
5553 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5554 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5555 case OP_oRNSDQ:
5556 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5557
5558 /* Neon scalar. Using an element size of 8 means that some invalid
5559 scalars are accepted here, so deal with those in later code. */
5560 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5561
5562 /* WARNING: We can expand to two operands here. This has the potential
5563 to totally confuse the backtracking mechanism! It will be OK at
5564 least as long as we don't try to use optional args as well,
5565 though. */
5566 case OP_NILO:
5567 {
5568 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5569 i++;
5570 skip_past_comma (&str);
5571 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5572 break;
5573 one_reg_only:
5574 /* Optional register operand was omitted. Unfortunately, it's in
5575 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5576 here (this is a bit grotty). */
5577 inst.operands[i] = inst.operands[i-1];
5578 inst.operands[i-1].present = 0;
5579 break;
5580 try_imm:
5581 /* Immediate gets verified properly later, so accept any now. */
5582 po_imm_or_fail (INT_MIN, INT_MAX, TRUE);
5583 }
5584 break;
5585
5586 case OP_RNDQ_I0:
5587 {
5588 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5589 break;
5590 try_imm0:
5591 po_imm_or_fail (0, 0, TRUE);
5592 }
5593 break;
5594
037e8744
JB
5595 case OP_RVSD_I0:
5596 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5597 break;
5598
5287ad62
JB
5599 case OP_RR_RNSC:
5600 {
5601 po_scalar_or_goto (8, try_rr);
5602 break;
5603 try_rr:
5604 po_reg_or_fail (REG_TYPE_RN);
5605 }
5606 break;
5607
037e8744
JB
5608 case OP_RNSDQ_RNSC:
5609 {
5610 po_scalar_or_goto (8, try_nsdq);
5611 break;
5612 try_nsdq:
5613 po_reg_or_fail (REG_TYPE_NSDQ);
5614 }
5615 break;
5616
5287ad62
JB
5617 case OP_RNDQ_RNSC:
5618 {
5619 po_scalar_or_goto (8, try_ndq);
5620 break;
5621 try_ndq:
5622 po_reg_or_fail (REG_TYPE_NDQ);
5623 }
5624 break;
5625
5626 case OP_RND_RNSC:
5627 {
5628 po_scalar_or_goto (8, try_vfd);
5629 break;
5630 try_vfd:
5631 po_reg_or_fail (REG_TYPE_VFD);
5632 }
5633 break;
5634
5635 case OP_VMOV:
5636 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5637 not careful then bad things might happen. */
5638 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5639 break;
5640
5641 case OP_RNDQ_IMVNb:
5642 {
5643 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5644 break;
5645 try_mvnimm:
5646 /* There's a possibility of getting a 64-bit immediate here, so
5647 we need special handling. */
5648 if (parse_big_immediate (&str, i) == FAIL)
5649 {
5650 inst.error = _("immediate value is out of range");
5651 goto failure;
5652 }
5653 }
5654 break;
5655
5656 case OP_RNDQ_I63b:
5657 {
5658 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5659 break;
5660 try_shimm:
5661 po_imm_or_fail (0, 63, TRUE);
5662 }
5663 break;
c19d1205
ZW
5664
5665 case OP_RRnpcb:
5666 po_char_or_fail ('[');
5667 po_reg_or_fail (REG_TYPE_RN);
5668 po_char_or_fail (']');
5669 break;
a737bd4d 5670
c19d1205
ZW
5671 case OP_RRw:
5672 po_reg_or_fail (REG_TYPE_RN);
5673 if (skip_past_char (&str, '!') == SUCCESS)
5674 inst.operands[i].writeback = 1;
5675 break;
5676
5677 /* Immediates */
5678 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5679 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5680 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5681 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5682 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5683 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5684 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5685 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5686 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5687 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5688 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5689 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5690
5691 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5692 case OP_oI7b:
5693 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5694 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5695 case OP_oI31b:
5696 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5697 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5698 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5699
5700 /* Immediate variants */
5701 case OP_oI255c:
5702 po_char_or_fail ('{');
5703 po_imm_or_fail (0, 255, TRUE);
5704 po_char_or_fail ('}');
5705 break;
5706
5707 case OP_I31w:
5708 /* The expression parser chokes on a trailing !, so we have
5709 to find it first and zap it. */
5710 {
5711 char *s = str;
5712 while (*s && *s != ',')
5713 s++;
5714 if (s[-1] == '!')
5715 {
5716 s[-1] = '\0';
5717 inst.operands[i].writeback = 1;
5718 }
5719 po_imm_or_fail (0, 31, TRUE);
5720 if (str == s - 1)
5721 str = s;
5722 }
5723 break;
5724
5725 /* Expressions */
5726 case OP_EXPi: EXPi:
5727 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5728 GE_OPT_PREFIX));
5729 break;
5730
5731 case OP_EXP:
5732 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5733 GE_NO_PREFIX));
5734 break;
5735
5736 case OP_EXPr: EXPr:
5737 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5738 GE_NO_PREFIX));
5739 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5740 {
c19d1205
ZW
5741 val = parse_reloc (&str);
5742 if (val == -1)
5743 {
5744 inst.error = _("unrecognized relocation suffix");
5745 goto failure;
5746 }
5747 else if (val != BFD_RELOC_UNUSED)
5748 {
5749 inst.operands[i].imm = val;
5750 inst.operands[i].hasreloc = 1;
5751 }
a737bd4d 5752 }
c19d1205 5753 break;
a737bd4d 5754
b6895b4f
PB
5755 /* Operand for MOVW or MOVT. */
5756 case OP_HALF:
5757 po_misc_or_fail (parse_half (&str));
5758 break;
5759
c19d1205
ZW
5760 /* Register or expression */
5761 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5762 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5763
c19d1205
ZW
5764 /* Register or immediate */
5765 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5766 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5767
c19d1205
ZW
5768 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5769 IF:
5770 if (!is_immediate_prefix (*str))
5771 goto bad_args;
5772 str++;
5773 val = parse_fpa_immediate (&str);
5774 if (val == FAIL)
5775 goto failure;
5776 /* FPA immediates are encoded as registers 8-15.
5777 parse_fpa_immediate has already applied the offset. */
5778 inst.operands[i].reg = val;
5779 inst.operands[i].isreg = 1;
5780 break;
09d92015 5781
c19d1205
ZW
5782 /* Two kinds of register */
5783 case OP_RIWR_RIWC:
5784 {
5785 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
5786 if (!rege
5787 || (rege->type != REG_TYPE_MMXWR
5788 && rege->type != REG_TYPE_MMXWC
5789 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
5790 {
5791 inst.error = _("iWMMXt data or control register expected");
5792 goto failure;
5793 }
5794 inst.operands[i].reg = rege->number;
5795 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
5796 }
5797 break;
09d92015 5798
41adaa5c
JM
5799 case OP_RIWC_RIWG:
5800 {
5801 struct reg_entry *rege = arm_reg_parse_multi (&str);
5802 if (!rege
5803 || (rege->type != REG_TYPE_MMXWC
5804 && rege->type != REG_TYPE_MMXWCG))
5805 {
5806 inst.error = _("iWMMXt control register expected");
5807 goto failure;
5808 }
5809 inst.operands[i].reg = rege->number;
5810 inst.operands[i].isreg = 1;
5811 }
5812 break;
5813
c19d1205
ZW
5814 /* Misc */
5815 case OP_CPSF: val = parse_cps_flags (&str); break;
5816 case OP_ENDI: val = parse_endian_specifier (&str); break;
5817 case OP_oROR: val = parse_ror (&str); break;
5818 case OP_PSR: val = parse_psr (&str); break;
5819 case OP_COND: val = parse_cond (&str); break;
62b3e311 5820 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 5821
037e8744
JB
5822 case OP_RVC_PSR:
5823 po_reg_or_goto (REG_TYPE_VFC, try_psr);
5824 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
5825 break;
5826 try_psr:
5827 val = parse_psr (&str);
5828 break;
5829
5830 case OP_APSR_RR:
5831 po_reg_or_goto (REG_TYPE_RN, try_apsr);
5832 break;
5833 try_apsr:
5834 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
5835 instruction). */
5836 if (strncasecmp (str, "APSR_", 5) == 0)
5837 {
5838 unsigned found = 0;
5839 str += 5;
5840 while (found < 15)
5841 switch (*str++)
5842 {
5843 case 'c': found = (found & 1) ? 16 : found | 1; break;
5844 case 'n': found = (found & 2) ? 16 : found | 2; break;
5845 case 'z': found = (found & 4) ? 16 : found | 4; break;
5846 case 'v': found = (found & 8) ? 16 : found | 8; break;
5847 default: found = 16;
5848 }
5849 if (found != 15)
5850 goto failure;
5851 inst.operands[i].isvec = 1;
5852 }
5853 else
5854 goto failure;
5855 break;
5856
92e90b6e
PB
5857 case OP_TB:
5858 po_misc_or_fail (parse_tb (&str));
5859 break;
5860
c19d1205
ZW
5861 /* Register lists */
5862 case OP_REGLST:
5863 val = parse_reg_list (&str);
5864 if (*str == '^')
5865 {
5866 inst.operands[1].writeback = 1;
5867 str++;
5868 }
5869 break;
09d92015 5870
c19d1205 5871 case OP_VRSLST:
5287ad62 5872 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 5873 break;
09d92015 5874
c19d1205 5875 case OP_VRDLST:
5287ad62 5876 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 5877 break;
a737bd4d 5878
037e8744
JB
5879 case OP_VRSDLST:
5880 /* Allow Q registers too. */
5881 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5882 REGLIST_NEON_D);
5883 if (val == FAIL)
5884 {
5885 inst.error = NULL;
5886 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5887 REGLIST_VFP_S);
5888 inst.operands[i].issingle = 1;
5889 }
5890 break;
5891
5287ad62
JB
5892 case OP_NRDLST:
5893 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
5894 REGLIST_NEON_D);
5895 break;
5896
5897 case OP_NSTRLST:
dcbf9037
JB
5898 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
5899 &inst.operands[i].vectype);
5287ad62
JB
5900 break;
5901
c19d1205
ZW
5902 /* Addressing modes */
5903 case OP_ADDR:
5904 po_misc_or_fail (parse_address (&str, i));
5905 break;
09d92015 5906
4962c51a
MS
5907 case OP_ADDRGLDR:
5908 po_misc_or_fail_no_backtrack (
5909 parse_address_group_reloc (&str, i, GROUP_LDR));
5910 break;
5911
5912 case OP_ADDRGLDRS:
5913 po_misc_or_fail_no_backtrack (
5914 parse_address_group_reloc (&str, i, GROUP_LDRS));
5915 break;
5916
5917 case OP_ADDRGLDC:
5918 po_misc_or_fail_no_backtrack (
5919 parse_address_group_reloc (&str, i, GROUP_LDC));
5920 break;
5921
c19d1205
ZW
5922 case OP_SH:
5923 po_misc_or_fail (parse_shifter_operand (&str, i));
5924 break;
09d92015 5925
4962c51a
MS
5926 case OP_SHG:
5927 po_misc_or_fail_no_backtrack (
5928 parse_shifter_operand_group_reloc (&str, i));
5929 break;
5930
c19d1205
ZW
5931 case OP_oSHll:
5932 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
5933 break;
09d92015 5934
c19d1205
ZW
5935 case OP_oSHar:
5936 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
5937 break;
09d92015 5938
c19d1205
ZW
5939 case OP_oSHllar:
5940 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
5941 break;
09d92015 5942
c19d1205
ZW
5943 default:
5944 as_fatal ("unhandled operand code %d", upat[i]);
5945 }
09d92015 5946
c19d1205
ZW
5947 /* Various value-based sanity checks and shared operations. We
5948 do not signal immediate failures for the register constraints;
5949 this allows a syntax error to take precedence. */
5950 switch (upat[i])
5951 {
5952 case OP_oRRnpc:
5953 case OP_RRnpc:
5954 case OP_RRnpcb:
5955 case OP_RRw:
5956 case OP_RRnpc_I0:
5957 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
5958 inst.error = BAD_PC;
5959 break;
09d92015 5960
c19d1205
ZW
5961 case OP_CPSF:
5962 case OP_ENDI:
5963 case OP_oROR:
5964 case OP_PSR:
037e8744 5965 case OP_RVC_PSR:
c19d1205 5966 case OP_COND:
62b3e311 5967 case OP_oBARRIER:
c19d1205
ZW
5968 case OP_REGLST:
5969 case OP_VRSLST:
5970 case OP_VRDLST:
037e8744 5971 case OP_VRSDLST:
5287ad62
JB
5972 case OP_NRDLST:
5973 case OP_NSTRLST:
c19d1205
ZW
5974 if (val == FAIL)
5975 goto failure;
5976 inst.operands[i].imm = val;
5977 break;
a737bd4d 5978
c19d1205
ZW
5979 default:
5980 break;
5981 }
09d92015 5982
c19d1205
ZW
5983 /* If we get here, this operand was successfully parsed. */
5984 inst.operands[i].present = 1;
5985 continue;
09d92015 5986
c19d1205 5987 bad_args:
09d92015 5988 inst.error = BAD_ARGS;
c19d1205
ZW
5989
5990 failure:
5991 if (!backtrack_pos)
d252fdde
PB
5992 {
5993 /* The parse routine should already have set inst.error, but set a
5994 defaut here just in case. */
5995 if (!inst.error)
5996 inst.error = _("syntax error");
5997 return FAIL;
5998 }
c19d1205
ZW
5999
6000 /* Do not backtrack over a trailing optional argument that
6001 absorbed some text. We will only fail again, with the
6002 'garbage following instruction' error message, which is
6003 probably less helpful than the current one. */
6004 if (backtrack_index == i && backtrack_pos != str
6005 && upat[i+1] == OP_stop)
d252fdde
PB
6006 {
6007 if (!inst.error)
6008 inst.error = _("syntax error");
6009 return FAIL;
6010 }
c19d1205
ZW
6011
6012 /* Try again, skipping the optional argument at backtrack_pos. */
6013 str = backtrack_pos;
6014 inst.error = backtrack_error;
6015 inst.operands[backtrack_index].present = 0;
6016 i = backtrack_index;
6017 backtrack_pos = 0;
09d92015 6018 }
09d92015 6019
c19d1205
ZW
6020 /* Check that we have parsed all the arguments. */
6021 if (*str != '\0' && !inst.error)
6022 inst.error = _("garbage following instruction");
09d92015 6023
c19d1205 6024 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6025}
6026
c19d1205
ZW
6027#undef po_char_or_fail
6028#undef po_reg_or_fail
6029#undef po_reg_or_goto
6030#undef po_imm_or_fail
5287ad62 6031#undef po_scalar_or_fail
c19d1205
ZW
6032\f
6033/* Shorthand macro for instruction encoding functions issuing errors. */
6034#define constraint(expr, err) do { \
6035 if (expr) \
6036 { \
6037 inst.error = err; \
6038 return; \
6039 } \
6040} while (0)
6041
6042/* Functions for operand encoding. ARM, then Thumb. */
6043
6044#define rotate_left(v, n) (v << n | v >> (32 - n))
6045
6046/* If VAL can be encoded in the immediate field of an ARM instruction,
6047 return the encoded form. Otherwise, return FAIL. */
6048
6049static unsigned int
6050encode_arm_immediate (unsigned int val)
09d92015 6051{
c19d1205
ZW
6052 unsigned int a, i;
6053
6054 for (i = 0; i < 32; i += 2)
6055 if ((a = rotate_left (val, i)) <= 0xff)
6056 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6057
6058 return FAIL;
09d92015
MM
6059}
6060
c19d1205
ZW
6061/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6062 return the encoded form. Otherwise, return FAIL. */
6063static unsigned int
6064encode_thumb32_immediate (unsigned int val)
09d92015 6065{
c19d1205 6066 unsigned int a, i;
09d92015 6067
9c3c69f2 6068 if (val <= 0xff)
c19d1205 6069 return val;
a737bd4d 6070
9c3c69f2 6071 for (i = 1; i <= 24; i++)
09d92015 6072 {
9c3c69f2
PB
6073 a = val >> i;
6074 if ((val & ~(0xff << i)) == 0)
6075 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6076 }
a737bd4d 6077
c19d1205
ZW
6078 a = val & 0xff;
6079 if (val == ((a << 16) | a))
6080 return 0x100 | a;
6081 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6082 return 0x300 | a;
09d92015 6083
c19d1205
ZW
6084 a = val & 0xff00;
6085 if (val == ((a << 16) | a))
6086 return 0x200 | (a >> 8);
a737bd4d 6087
c19d1205 6088 return FAIL;
09d92015 6089}
5287ad62 6090/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6091
6092static void
5287ad62
JB
6093encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6094{
6095 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6096 && reg > 15)
6097 {
6098 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v3))
6099 {
6100 if (thumb_mode)
6101 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6102 fpu_vfp_ext_v3);
6103 else
6104 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6105 fpu_vfp_ext_v3);
6106 }
6107 else
6108 {
dcbf9037 6109 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6110 return;
6111 }
6112 }
6113
c19d1205 6114 switch (pos)
09d92015 6115 {
c19d1205
ZW
6116 case VFP_REG_Sd:
6117 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6118 break;
6119
6120 case VFP_REG_Sn:
6121 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6122 break;
6123
6124 case VFP_REG_Sm:
6125 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6126 break;
6127
5287ad62
JB
6128 case VFP_REG_Dd:
6129 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6130 break;
6131
6132 case VFP_REG_Dn:
6133 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6134 break;
6135
6136 case VFP_REG_Dm:
6137 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6138 break;
6139
c19d1205
ZW
6140 default:
6141 abort ();
09d92015 6142 }
09d92015
MM
6143}
6144
c19d1205 6145/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6146 if any, is handled by md_apply_fix. */
09d92015 6147static void
c19d1205 6148encode_arm_shift (int i)
09d92015 6149{
c19d1205
ZW
6150 if (inst.operands[i].shift_kind == SHIFT_RRX)
6151 inst.instruction |= SHIFT_ROR << 5;
6152 else
09d92015 6153 {
c19d1205
ZW
6154 inst.instruction |= inst.operands[i].shift_kind << 5;
6155 if (inst.operands[i].immisreg)
6156 {
6157 inst.instruction |= SHIFT_BY_REG;
6158 inst.instruction |= inst.operands[i].imm << 8;
6159 }
6160 else
6161 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6162 }
c19d1205 6163}
09d92015 6164
c19d1205
ZW
6165static void
6166encode_arm_shifter_operand (int i)
6167{
6168 if (inst.operands[i].isreg)
09d92015 6169 {
c19d1205
ZW
6170 inst.instruction |= inst.operands[i].reg;
6171 encode_arm_shift (i);
09d92015 6172 }
c19d1205
ZW
6173 else
6174 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6175}
6176
c19d1205 6177/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6178static void
c19d1205 6179encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6180{
c19d1205
ZW
6181 assert (inst.operands[i].isreg);
6182 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6183
c19d1205 6184 if (inst.operands[i].preind)
09d92015 6185 {
c19d1205
ZW
6186 if (is_t)
6187 {
6188 inst.error = _("instruction does not accept preindexed addressing");
6189 return;
6190 }
6191 inst.instruction |= PRE_INDEX;
6192 if (inst.operands[i].writeback)
6193 inst.instruction |= WRITE_BACK;
09d92015 6194
c19d1205
ZW
6195 }
6196 else if (inst.operands[i].postind)
6197 {
6198 assert (inst.operands[i].writeback);
6199 if (is_t)
6200 inst.instruction |= WRITE_BACK;
6201 }
6202 else /* unindexed - only for coprocessor */
09d92015 6203 {
c19d1205 6204 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6205 return;
6206 }
6207
c19d1205
ZW
6208 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6209 && (((inst.instruction & 0x000f0000) >> 16)
6210 == ((inst.instruction & 0x0000f000) >> 12)))
6211 as_warn ((inst.instruction & LOAD_BIT)
6212 ? _("destination register same as write-back base")
6213 : _("source register same as write-back base"));
09d92015
MM
6214}
6215
c19d1205
ZW
6216/* inst.operands[i] was set up by parse_address. Encode it into an
6217 ARM-format mode 2 load or store instruction. If is_t is true,
6218 reject forms that cannot be used with a T instruction (i.e. not
6219 post-indexed). */
a737bd4d 6220static void
c19d1205 6221encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6222{
c19d1205 6223 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6224
c19d1205 6225 if (inst.operands[i].immisreg)
09d92015 6226 {
c19d1205
ZW
6227 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6228 inst.instruction |= inst.operands[i].imm;
6229 if (!inst.operands[i].negative)
6230 inst.instruction |= INDEX_UP;
6231 if (inst.operands[i].shifted)
6232 {
6233 if (inst.operands[i].shift_kind == SHIFT_RRX)
6234 inst.instruction |= SHIFT_ROR << 5;
6235 else
6236 {
6237 inst.instruction |= inst.operands[i].shift_kind << 5;
6238 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6239 }
6240 }
09d92015 6241 }
c19d1205 6242 else /* immediate offset in inst.reloc */
09d92015 6243 {
c19d1205
ZW
6244 if (inst.reloc.type == BFD_RELOC_UNUSED)
6245 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6246 }
09d92015
MM
6247}
6248
c19d1205
ZW
6249/* inst.operands[i] was set up by parse_address. Encode it into an
6250 ARM-format mode 3 load or store instruction. Reject forms that
6251 cannot be used with such instructions. If is_t is true, reject
6252 forms that cannot be used with a T instruction (i.e. not
6253 post-indexed). */
6254static void
6255encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6256{
c19d1205 6257 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6258 {
c19d1205
ZW
6259 inst.error = _("instruction does not accept scaled register index");
6260 return;
09d92015 6261 }
a737bd4d 6262
c19d1205 6263 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6264
c19d1205
ZW
6265 if (inst.operands[i].immisreg)
6266 {
6267 inst.instruction |= inst.operands[i].imm;
6268 if (!inst.operands[i].negative)
6269 inst.instruction |= INDEX_UP;
6270 }
6271 else /* immediate offset in inst.reloc */
6272 {
6273 inst.instruction |= HWOFFSET_IMM;
6274 if (inst.reloc.type == BFD_RELOC_UNUSED)
6275 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6276 }
a737bd4d
NC
6277}
6278
c19d1205
ZW
6279/* inst.operands[i] was set up by parse_address. Encode it into an
6280 ARM-format instruction. Reject all forms which cannot be encoded
6281 into a coprocessor load/store instruction. If wb_ok is false,
6282 reject use of writeback; if unind_ok is false, reject use of
6283 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6284 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6285 (in which case it is preserved). */
09d92015 6286
c19d1205
ZW
6287static int
6288encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6289{
c19d1205 6290 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6291
c19d1205 6292 assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6293
c19d1205 6294 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6295 {
c19d1205
ZW
6296 assert (!inst.operands[i].writeback);
6297 if (!unind_ok)
6298 {
6299 inst.error = _("instruction does not support unindexed addressing");
6300 return FAIL;
6301 }
6302 inst.instruction |= inst.operands[i].imm;
6303 inst.instruction |= INDEX_UP;
6304 return SUCCESS;
09d92015 6305 }
a737bd4d 6306
c19d1205
ZW
6307 if (inst.operands[i].preind)
6308 inst.instruction |= PRE_INDEX;
a737bd4d 6309
c19d1205 6310 if (inst.operands[i].writeback)
09d92015 6311 {
c19d1205
ZW
6312 if (inst.operands[i].reg == REG_PC)
6313 {
6314 inst.error = _("pc may not be used with write-back");
6315 return FAIL;
6316 }
6317 if (!wb_ok)
6318 {
6319 inst.error = _("instruction does not support writeback");
6320 return FAIL;
6321 }
6322 inst.instruction |= WRITE_BACK;
09d92015 6323 }
a737bd4d 6324
c19d1205
ZW
6325 if (reloc_override)
6326 inst.reloc.type = reloc_override;
4962c51a
MS
6327 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6328 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6329 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6330 {
6331 if (thumb_mode)
6332 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6333 else
6334 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6335 }
6336
c19d1205
ZW
6337 return SUCCESS;
6338}
a737bd4d 6339
c19d1205
ZW
6340/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6341 Determine whether it can be performed with a move instruction; if
6342 it can, convert inst.instruction to that move instruction and
6343 return 1; if it can't, convert inst.instruction to a literal-pool
6344 load and return 0. If this is not a valid thing to do in the
6345 current context, set inst.error and return 1.
a737bd4d 6346
c19d1205
ZW
6347 inst.operands[i] describes the destination register. */
6348
6349static int
6350move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6351{
53365c0d
PB
6352 unsigned long tbit;
6353
6354 if (thumb_p)
6355 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6356 else
6357 tbit = LOAD_BIT;
6358
6359 if ((inst.instruction & tbit) == 0)
09d92015 6360 {
c19d1205
ZW
6361 inst.error = _("invalid pseudo operation");
6362 return 1;
09d92015 6363 }
c19d1205 6364 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6365 {
6366 inst.error = _("constant expression expected");
c19d1205 6367 return 1;
09d92015 6368 }
c19d1205 6369 if (inst.reloc.exp.X_op == O_constant)
09d92015 6370 {
c19d1205
ZW
6371 if (thumb_p)
6372 {
53365c0d 6373 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6374 {
6375 /* This can be done with a mov(1) instruction. */
6376 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6377 inst.instruction |= inst.reloc.exp.X_add_number;
6378 return 1;
6379 }
6380 }
6381 else
6382 {
6383 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6384 if (value != FAIL)
6385 {
6386 /* This can be done with a mov instruction. */
6387 inst.instruction &= LITERAL_MASK;
6388 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6389 inst.instruction |= value & 0xfff;
6390 return 1;
6391 }
09d92015 6392
c19d1205
ZW
6393 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6394 if (value != FAIL)
6395 {
6396 /* This can be done with a mvn instruction. */
6397 inst.instruction &= LITERAL_MASK;
6398 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6399 inst.instruction |= value & 0xfff;
6400 return 1;
6401 }
6402 }
09d92015
MM
6403 }
6404
c19d1205
ZW
6405 if (add_to_lit_pool () == FAIL)
6406 {
6407 inst.error = _("literal pool insertion failed");
6408 return 1;
6409 }
6410 inst.operands[1].reg = REG_PC;
6411 inst.operands[1].isreg = 1;
6412 inst.operands[1].preind = 1;
6413 inst.reloc.pc_rel = 1;
6414 inst.reloc.type = (thumb_p
6415 ? BFD_RELOC_ARM_THUMB_OFFSET
6416 : (mode_3
6417 ? BFD_RELOC_ARM_HWLITERAL
6418 : BFD_RELOC_ARM_LITERAL));
6419 return 0;
09d92015
MM
6420}
6421
c19d1205
ZW
6422/* Functions for instruction encoding, sorted by subarchitecture.
6423 First some generics; their names are taken from the conventional
6424 bit positions for register arguments in ARM format instructions. */
09d92015 6425
a737bd4d 6426static void
c19d1205 6427do_noargs (void)
09d92015 6428{
c19d1205 6429}
a737bd4d 6430
c19d1205
ZW
6431static void
6432do_rd (void)
6433{
6434 inst.instruction |= inst.operands[0].reg << 12;
6435}
a737bd4d 6436
c19d1205
ZW
6437static void
6438do_rd_rm (void)
6439{
6440 inst.instruction |= inst.operands[0].reg << 12;
6441 inst.instruction |= inst.operands[1].reg;
6442}
09d92015 6443
c19d1205
ZW
6444static void
6445do_rd_rn (void)
6446{
6447 inst.instruction |= inst.operands[0].reg << 12;
6448 inst.instruction |= inst.operands[1].reg << 16;
6449}
a737bd4d 6450
c19d1205
ZW
6451static void
6452do_rn_rd (void)
6453{
6454 inst.instruction |= inst.operands[0].reg << 16;
6455 inst.instruction |= inst.operands[1].reg << 12;
6456}
09d92015 6457
c19d1205
ZW
6458static void
6459do_rd_rm_rn (void)
6460{
9a64e435 6461 unsigned Rn = inst.operands[2].reg;
708587a4 6462 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6463 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6464 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6465 _("Rn must not overlap other operands"));
c19d1205
ZW
6466 inst.instruction |= inst.operands[0].reg << 12;
6467 inst.instruction |= inst.operands[1].reg;
9a64e435 6468 inst.instruction |= Rn << 16;
c19d1205 6469}
09d92015 6470
c19d1205
ZW
6471static void
6472do_rd_rn_rm (void)
6473{
6474 inst.instruction |= inst.operands[0].reg << 12;
6475 inst.instruction |= inst.operands[1].reg << 16;
6476 inst.instruction |= inst.operands[2].reg;
6477}
a737bd4d 6478
c19d1205
ZW
6479static void
6480do_rm_rd_rn (void)
6481{
6482 inst.instruction |= inst.operands[0].reg;
6483 inst.instruction |= inst.operands[1].reg << 12;
6484 inst.instruction |= inst.operands[2].reg << 16;
6485}
09d92015 6486
c19d1205
ZW
6487static void
6488do_imm0 (void)
6489{
6490 inst.instruction |= inst.operands[0].imm;
6491}
09d92015 6492
c19d1205
ZW
6493static void
6494do_rd_cpaddr (void)
6495{
6496 inst.instruction |= inst.operands[0].reg << 12;
6497 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6498}
a737bd4d 6499
c19d1205
ZW
6500/* ARM instructions, in alphabetical order by function name (except
6501 that wrapper functions appear immediately after the function they
6502 wrap). */
09d92015 6503
c19d1205
ZW
6504/* This is a pseudo-op of the form "adr rd, label" to be converted
6505 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6506
6507static void
c19d1205 6508do_adr (void)
09d92015 6509{
c19d1205 6510 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6511
c19d1205
ZW
6512 /* Frag hacking will turn this into a sub instruction if the offset turns
6513 out to be negative. */
6514 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6515 inst.reloc.pc_rel = 1;
2fc8bdac 6516 inst.reloc.exp.X_add_number -= 8;
c19d1205 6517}
b99bd4ef 6518
c19d1205
ZW
6519/* This is a pseudo-op of the form "adrl rd, label" to be converted
6520 into a relative address of the form:
6521 add rd, pc, #low(label-.-8)"
6522 add rd, rd, #high(label-.-8)" */
b99bd4ef 6523
c19d1205
ZW
6524static void
6525do_adrl (void)
6526{
6527 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6528
c19d1205
ZW
6529 /* Frag hacking will turn this into a sub instruction if the offset turns
6530 out to be negative. */
6531 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6532 inst.reloc.pc_rel = 1;
6533 inst.size = INSN_SIZE * 2;
2fc8bdac 6534 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6535}
6536
b99bd4ef 6537static void
c19d1205 6538do_arit (void)
b99bd4ef 6539{
c19d1205
ZW
6540 if (!inst.operands[1].present)
6541 inst.operands[1].reg = inst.operands[0].reg;
6542 inst.instruction |= inst.operands[0].reg << 12;
6543 inst.instruction |= inst.operands[1].reg << 16;
6544 encode_arm_shifter_operand (2);
6545}
b99bd4ef 6546
62b3e311
PB
6547static void
6548do_barrier (void)
6549{
6550 if (inst.operands[0].present)
6551 {
6552 constraint ((inst.instruction & 0xf0) != 0x40
6553 && inst.operands[0].imm != 0xf,
6554 "bad barrier type");
6555 inst.instruction |= inst.operands[0].imm;
6556 }
6557 else
6558 inst.instruction |= 0xf;
6559}
6560
c19d1205
ZW
6561static void
6562do_bfc (void)
6563{
6564 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6565 constraint (msb > 32, _("bit-field extends past end of register"));
6566 /* The instruction encoding stores the LSB and MSB,
6567 not the LSB and width. */
6568 inst.instruction |= inst.operands[0].reg << 12;
6569 inst.instruction |= inst.operands[1].imm << 7;
6570 inst.instruction |= (msb - 1) << 16;
6571}
b99bd4ef 6572
c19d1205
ZW
6573static void
6574do_bfi (void)
6575{
6576 unsigned int msb;
b99bd4ef 6577
c19d1205
ZW
6578 /* #0 in second position is alternative syntax for bfc, which is
6579 the same instruction but with REG_PC in the Rm field. */
6580 if (!inst.operands[1].isreg)
6581 inst.operands[1].reg = REG_PC;
b99bd4ef 6582
c19d1205
ZW
6583 msb = inst.operands[2].imm + inst.operands[3].imm;
6584 constraint (msb > 32, _("bit-field extends past end of register"));
6585 /* The instruction encoding stores the LSB and MSB,
6586 not the LSB and width. */
6587 inst.instruction |= inst.operands[0].reg << 12;
6588 inst.instruction |= inst.operands[1].reg;
6589 inst.instruction |= inst.operands[2].imm << 7;
6590 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6591}
6592
b99bd4ef 6593static void
c19d1205 6594do_bfx (void)
b99bd4ef 6595{
c19d1205
ZW
6596 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6597 _("bit-field extends past end of register"));
6598 inst.instruction |= inst.operands[0].reg << 12;
6599 inst.instruction |= inst.operands[1].reg;
6600 inst.instruction |= inst.operands[2].imm << 7;
6601 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6602}
09d92015 6603
c19d1205
ZW
6604/* ARM V5 breakpoint instruction (argument parse)
6605 BKPT <16 bit unsigned immediate>
6606 Instruction is not conditional.
6607 The bit pattern given in insns[] has the COND_ALWAYS condition,
6608 and it is an error if the caller tried to override that. */
b99bd4ef 6609
c19d1205
ZW
6610static void
6611do_bkpt (void)
6612{
6613 /* Top 12 of 16 bits to bits 19:8. */
6614 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6615
c19d1205
ZW
6616 /* Bottom 4 of 16 bits to bits 3:0. */
6617 inst.instruction |= inst.operands[0].imm & 0xf;
6618}
09d92015 6619
c19d1205
ZW
6620static void
6621encode_branch (int default_reloc)
6622{
6623 if (inst.operands[0].hasreloc)
6624 {
6625 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6626 _("the only suffix valid here is '(plt)'"));
6627 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6628 }
b99bd4ef 6629 else
c19d1205
ZW
6630 {
6631 inst.reloc.type = default_reloc;
c19d1205 6632 }
2fc8bdac 6633 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6634}
6635
b99bd4ef 6636static void
c19d1205 6637do_branch (void)
b99bd4ef 6638{
39b41c9c
PB
6639#ifdef OBJ_ELF
6640 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6641 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6642 else
6643#endif
6644 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6645}
6646
6647static void
6648do_bl (void)
6649{
6650#ifdef OBJ_ELF
6651 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6652 {
6653 if (inst.cond == COND_ALWAYS)
6654 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6655 else
6656 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6657 }
6658 else
6659#endif
6660 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6661}
b99bd4ef 6662
c19d1205
ZW
6663/* ARM V5 branch-link-exchange instruction (argument parse)
6664 BLX <target_addr> ie BLX(1)
6665 BLX{<condition>} <Rm> ie BLX(2)
6666 Unfortunately, there are two different opcodes for this mnemonic.
6667 So, the insns[].value is not used, and the code here zaps values
6668 into inst.instruction.
6669 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6670
c19d1205
ZW
6671static void
6672do_blx (void)
6673{
6674 if (inst.operands[0].isreg)
b99bd4ef 6675 {
c19d1205
ZW
6676 /* Arg is a register; the opcode provided by insns[] is correct.
6677 It is not illegal to do "blx pc", just useless. */
6678 if (inst.operands[0].reg == REG_PC)
6679 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6680
c19d1205
ZW
6681 inst.instruction |= inst.operands[0].reg;
6682 }
6683 else
b99bd4ef 6684 {
c19d1205
ZW
6685 /* Arg is an address; this instruction cannot be executed
6686 conditionally, and the opcode must be adjusted. */
6687 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6688 inst.instruction = 0xfa000000;
39b41c9c
PB
6689#ifdef OBJ_ELF
6690 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6691 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6692 else
6693#endif
6694 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6695 }
c19d1205
ZW
6696}
6697
6698static void
6699do_bx (void)
6700{
6701 if (inst.operands[0].reg == REG_PC)
6702 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6703
c19d1205 6704 inst.instruction |= inst.operands[0].reg;
09d92015
MM
6705}
6706
c19d1205
ZW
6707
6708/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6709
6710static void
c19d1205 6711do_bxj (void)
a737bd4d 6712{
c19d1205
ZW
6713 if (inst.operands[0].reg == REG_PC)
6714 as_tsktsk (_("use of r15 in bxj is not really useful"));
6715
6716 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6717}
6718
c19d1205
ZW
6719/* Co-processor data operation:
6720 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6721 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6722static void
6723do_cdp (void)
6724{
6725 inst.instruction |= inst.operands[0].reg << 8;
6726 inst.instruction |= inst.operands[1].imm << 20;
6727 inst.instruction |= inst.operands[2].reg << 12;
6728 inst.instruction |= inst.operands[3].reg << 16;
6729 inst.instruction |= inst.operands[4].reg;
6730 inst.instruction |= inst.operands[5].imm << 5;
6731}
a737bd4d
NC
6732
6733static void
c19d1205 6734do_cmp (void)
a737bd4d 6735{
c19d1205
ZW
6736 inst.instruction |= inst.operands[0].reg << 16;
6737 encode_arm_shifter_operand (1);
a737bd4d
NC
6738}
6739
c19d1205
ZW
6740/* Transfer between coprocessor and ARM registers.
6741 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6742 MRC2
6743 MCR{cond}
6744 MCR2
6745
6746 No special properties. */
09d92015
MM
6747
6748static void
c19d1205 6749do_co_reg (void)
09d92015 6750{
c19d1205
ZW
6751 inst.instruction |= inst.operands[0].reg << 8;
6752 inst.instruction |= inst.operands[1].imm << 21;
6753 inst.instruction |= inst.operands[2].reg << 12;
6754 inst.instruction |= inst.operands[3].reg << 16;
6755 inst.instruction |= inst.operands[4].reg;
6756 inst.instruction |= inst.operands[5].imm << 5;
6757}
09d92015 6758
c19d1205
ZW
6759/* Transfer between coprocessor register and pair of ARM registers.
6760 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
6761 MCRR2
6762 MRRC{cond}
6763 MRRC2
b99bd4ef 6764
c19d1205 6765 Two XScale instructions are special cases of these:
09d92015 6766
c19d1205
ZW
6767 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
6768 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 6769
c19d1205 6770 Result unpredicatable if Rd or Rn is R15. */
a737bd4d 6771
c19d1205
ZW
6772static void
6773do_co_reg2c (void)
6774{
6775 inst.instruction |= inst.operands[0].reg << 8;
6776 inst.instruction |= inst.operands[1].imm << 4;
6777 inst.instruction |= inst.operands[2].reg << 12;
6778 inst.instruction |= inst.operands[3].reg << 16;
6779 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
6780}
6781
c19d1205
ZW
6782static void
6783do_cpsi (void)
6784{
6785 inst.instruction |= inst.operands[0].imm << 6;
6786 inst.instruction |= inst.operands[1].imm;
6787}
b99bd4ef 6788
62b3e311
PB
6789static void
6790do_dbg (void)
6791{
6792 inst.instruction |= inst.operands[0].imm;
6793}
6794
b99bd4ef 6795static void
c19d1205 6796do_it (void)
b99bd4ef 6797{
c19d1205
ZW
6798 /* There is no IT instruction in ARM mode. We
6799 process it but do not generate code for it. */
6800 inst.size = 0;
09d92015 6801}
b99bd4ef 6802
09d92015 6803static void
c19d1205 6804do_ldmstm (void)
ea6ef066 6805{
c19d1205
ZW
6806 int base_reg = inst.operands[0].reg;
6807 int range = inst.operands[1].imm;
ea6ef066 6808
c19d1205
ZW
6809 inst.instruction |= base_reg << 16;
6810 inst.instruction |= range;
ea6ef066 6811
c19d1205
ZW
6812 if (inst.operands[1].writeback)
6813 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 6814
c19d1205 6815 if (inst.operands[0].writeback)
ea6ef066 6816 {
c19d1205
ZW
6817 inst.instruction |= WRITE_BACK;
6818 /* Check for unpredictable uses of writeback. */
6819 if (inst.instruction & LOAD_BIT)
09d92015 6820 {
c19d1205
ZW
6821 /* Not allowed in LDM type 2. */
6822 if ((inst.instruction & LDM_TYPE_2_OR_3)
6823 && ((range & (1 << REG_PC)) == 0))
6824 as_warn (_("writeback of base register is UNPREDICTABLE"));
6825 /* Only allowed if base reg not in list for other types. */
6826 else if (range & (1 << base_reg))
6827 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
6828 }
6829 else /* STM. */
6830 {
6831 /* Not allowed for type 2. */
6832 if (inst.instruction & LDM_TYPE_2_OR_3)
6833 as_warn (_("writeback of base register is UNPREDICTABLE"));
6834 /* Only allowed if base reg not in list, or first in list. */
6835 else if ((range & (1 << base_reg))
6836 && (range & ((1 << base_reg) - 1)))
6837 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 6838 }
ea6ef066 6839 }
a737bd4d
NC
6840}
6841
c19d1205
ZW
6842/* ARMv5TE load-consecutive (argument parse)
6843 Mode is like LDRH.
6844
6845 LDRccD R, mode
6846 STRccD R, mode. */
6847
a737bd4d 6848static void
c19d1205 6849do_ldrd (void)
a737bd4d 6850{
c19d1205
ZW
6851 constraint (inst.operands[0].reg % 2 != 0,
6852 _("first destination register must be even"));
6853 constraint (inst.operands[1].present
6854 && inst.operands[1].reg != inst.operands[0].reg + 1,
6855 _("can only load two consecutive registers"));
6856 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
6857 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 6858
c19d1205
ZW
6859 if (!inst.operands[1].present)
6860 inst.operands[1].reg = inst.operands[0].reg + 1;
6861
6862 if (inst.instruction & LOAD_BIT)
a737bd4d 6863 {
c19d1205
ZW
6864 /* encode_arm_addr_mode_3 will diagnose overlap between the base
6865 register and the first register written; we have to diagnose
6866 overlap between the base and the second register written here. */
ea6ef066 6867
c19d1205
ZW
6868 if (inst.operands[2].reg == inst.operands[1].reg
6869 && (inst.operands[2].writeback || inst.operands[2].postind))
6870 as_warn (_("base register written back, and overlaps "
6871 "second destination register"));
b05fe5cf 6872
c19d1205
ZW
6873 /* For an index-register load, the index register must not overlap the
6874 destination (even if not write-back). */
6875 else if (inst.operands[2].immisreg
ca3f61f7
NC
6876 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
6877 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 6878 as_warn (_("index register overlaps destination register"));
b05fe5cf 6879 }
c19d1205
ZW
6880
6881 inst.instruction |= inst.operands[0].reg << 12;
6882 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
6883}
6884
6885static void
c19d1205 6886do_ldrex (void)
b05fe5cf 6887{
c19d1205
ZW
6888 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
6889 || inst.operands[1].postind || inst.operands[1].writeback
6890 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
6891 || inst.operands[1].negative
6892 /* This can arise if the programmer has written
6893 strex rN, rM, foo
6894 or if they have mistakenly used a register name as the last
6895 operand, eg:
6896 strex rN, rM, rX
6897 It is very difficult to distinguish between these two cases
6898 because "rX" might actually be a label. ie the register
6899 name has been occluded by a symbol of the same name. So we
6900 just generate a general 'bad addressing mode' type error
6901 message and leave it up to the programmer to discover the
6902 true cause and fix their mistake. */
6903 || (inst.operands[1].reg == REG_PC),
6904 BAD_ADDR_MODE);
b05fe5cf 6905
c19d1205
ZW
6906 constraint (inst.reloc.exp.X_op != O_constant
6907 || inst.reloc.exp.X_add_number != 0,
6908 _("offset must be zero in ARM encoding"));
b05fe5cf 6909
c19d1205
ZW
6910 inst.instruction |= inst.operands[0].reg << 12;
6911 inst.instruction |= inst.operands[1].reg << 16;
6912 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
6913}
6914
6915static void
c19d1205 6916do_ldrexd (void)
b05fe5cf 6917{
c19d1205
ZW
6918 constraint (inst.operands[0].reg % 2 != 0,
6919 _("even register required"));
6920 constraint (inst.operands[1].present
6921 && inst.operands[1].reg != inst.operands[0].reg + 1,
6922 _("can only load two consecutive registers"));
6923 /* If op 1 were present and equal to PC, this function wouldn't
6924 have been called in the first place. */
6925 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 6926
c19d1205
ZW
6927 inst.instruction |= inst.operands[0].reg << 12;
6928 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
6929}
6930
6931static void
c19d1205 6932do_ldst (void)
b05fe5cf 6933{
c19d1205
ZW
6934 inst.instruction |= inst.operands[0].reg << 12;
6935 if (!inst.operands[1].isreg)
6936 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 6937 return;
c19d1205 6938 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
6939}
6940
6941static void
c19d1205 6942do_ldstt (void)
b05fe5cf 6943{
c19d1205
ZW
6944 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6945 reject [Rn,...]. */
6946 if (inst.operands[1].preind)
b05fe5cf 6947 {
c19d1205
ZW
6948 constraint (inst.reloc.exp.X_op != O_constant ||
6949 inst.reloc.exp.X_add_number != 0,
6950 _("this instruction requires a post-indexed address"));
b05fe5cf 6951
c19d1205
ZW
6952 inst.operands[1].preind = 0;
6953 inst.operands[1].postind = 1;
6954 inst.operands[1].writeback = 1;
b05fe5cf 6955 }
c19d1205
ZW
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
6958}
b05fe5cf 6959
c19d1205 6960/* Halfword and signed-byte load/store operations. */
b05fe5cf 6961
c19d1205
ZW
6962static void
6963do_ldstv4 (void)
6964{
6965 inst.instruction |= inst.operands[0].reg << 12;
6966 if (!inst.operands[1].isreg)
6967 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 6968 return;
c19d1205 6969 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
6970}
6971
6972static void
c19d1205 6973do_ldsttv4 (void)
b05fe5cf 6974{
c19d1205
ZW
6975 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
6976 reject [Rn,...]. */
6977 if (inst.operands[1].preind)
b05fe5cf 6978 {
c19d1205
ZW
6979 constraint (inst.reloc.exp.X_op != O_constant ||
6980 inst.reloc.exp.X_add_number != 0,
6981 _("this instruction requires a post-indexed address"));
b05fe5cf 6982
c19d1205
ZW
6983 inst.operands[1].preind = 0;
6984 inst.operands[1].postind = 1;
6985 inst.operands[1].writeback = 1;
b05fe5cf 6986 }
c19d1205
ZW
6987 inst.instruction |= inst.operands[0].reg << 12;
6988 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
6989}
b05fe5cf 6990
c19d1205
ZW
6991/* Co-processor register load/store.
6992 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
6993static void
6994do_lstc (void)
6995{
6996 inst.instruction |= inst.operands[0].reg << 8;
6997 inst.instruction |= inst.operands[1].reg << 12;
6998 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
6999}
7000
b05fe5cf 7001static void
c19d1205 7002do_mlas (void)
b05fe5cf 7003{
c19d1205
ZW
7004 /* This restriction does not apply to mls (nor to mla in v6, but
7005 that's hard to detect at present). */
7006 if (inst.operands[0].reg == inst.operands[1].reg
7007 && !(inst.instruction & 0x00400000))
7008 as_tsktsk (_("rd and rm should be different in mla"));
b05fe5cf 7009
c19d1205
ZW
7010 inst.instruction |= inst.operands[0].reg << 16;
7011 inst.instruction |= inst.operands[1].reg;
7012 inst.instruction |= inst.operands[2].reg << 8;
7013 inst.instruction |= inst.operands[3].reg << 12;
b05fe5cf 7014
c19d1205 7015}
b05fe5cf 7016
c19d1205
ZW
7017static void
7018do_mov (void)
7019{
7020 inst.instruction |= inst.operands[0].reg << 12;
7021 encode_arm_shifter_operand (1);
7022}
b05fe5cf 7023
c19d1205
ZW
7024/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7025static void
7026do_mov16 (void)
7027{
b6895b4f
PB
7028 bfd_vma imm;
7029 bfd_boolean top;
7030
7031 top = (inst.instruction & 0x00400000) != 0;
7032 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7033 _(":lower16: not allowed this instruction"));
7034 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7035 _(":upper16: not allowed instruction"));
c19d1205 7036 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7037 if (inst.reloc.type == BFD_RELOC_UNUSED)
7038 {
7039 imm = inst.reloc.exp.X_add_number;
7040 /* The value is in two pieces: 0:11, 16:19. */
7041 inst.instruction |= (imm & 0x00000fff);
7042 inst.instruction |= (imm & 0x0000f000) << 4;
7043 }
b05fe5cf 7044}
b99bd4ef 7045
037e8744
JB
7046static void do_vfp_nsyn_opcode (const char *);
7047
7048static int
7049do_vfp_nsyn_mrs (void)
7050{
7051 if (inst.operands[0].isvec)
7052 {
7053 if (inst.operands[1].reg != 1)
7054 first_error (_("operand 1 must be FPSCR"));
7055 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7056 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7057 do_vfp_nsyn_opcode ("fmstat");
7058 }
7059 else if (inst.operands[1].isvec)
7060 do_vfp_nsyn_opcode ("fmrx");
7061 else
7062 return FAIL;
7063
7064 return SUCCESS;
7065}
7066
7067static int
7068do_vfp_nsyn_msr (void)
7069{
7070 if (inst.operands[0].isvec)
7071 do_vfp_nsyn_opcode ("fmxr");
7072 else
7073 return FAIL;
7074
7075 return SUCCESS;
7076}
7077
b99bd4ef 7078static void
c19d1205 7079do_mrs (void)
b99bd4ef 7080{
037e8744
JB
7081 if (do_vfp_nsyn_mrs () == SUCCESS)
7082 return;
7083
c19d1205
ZW
7084 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7085 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7086 != (PSR_c|PSR_f),
7087 _("'CPSR' or 'SPSR' expected"));
7088 inst.instruction |= inst.operands[0].reg << 12;
7089 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7090}
b99bd4ef 7091
c19d1205
ZW
7092/* Two possible forms:
7093 "{C|S}PSR_<field>, Rm",
7094 "{C|S}PSR_f, #expression". */
b99bd4ef 7095
c19d1205
ZW
7096static void
7097do_msr (void)
7098{
037e8744
JB
7099 if (do_vfp_nsyn_msr () == SUCCESS)
7100 return;
7101
c19d1205
ZW
7102 inst.instruction |= inst.operands[0].imm;
7103 if (inst.operands[1].isreg)
7104 inst.instruction |= inst.operands[1].reg;
7105 else
b99bd4ef 7106 {
c19d1205
ZW
7107 inst.instruction |= INST_IMMEDIATE;
7108 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7109 inst.reloc.pc_rel = 0;
b99bd4ef 7110 }
b99bd4ef
NC
7111}
7112
c19d1205
ZW
7113static void
7114do_mul (void)
a737bd4d 7115{
c19d1205
ZW
7116 if (!inst.operands[2].present)
7117 inst.operands[2].reg = inst.operands[0].reg;
7118 inst.instruction |= inst.operands[0].reg << 16;
7119 inst.instruction |= inst.operands[1].reg;
7120 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7121
c19d1205
ZW
7122 if (inst.operands[0].reg == inst.operands[1].reg)
7123 as_tsktsk (_("rd and rm should be different in mul"));
a737bd4d
NC
7124}
7125
c19d1205
ZW
7126/* Long Multiply Parser
7127 UMULL RdLo, RdHi, Rm, Rs
7128 SMULL RdLo, RdHi, Rm, Rs
7129 UMLAL RdLo, RdHi, Rm, Rs
7130 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7131
7132static void
c19d1205 7133do_mull (void)
b99bd4ef 7134{
c19d1205
ZW
7135 inst.instruction |= inst.operands[0].reg << 12;
7136 inst.instruction |= inst.operands[1].reg << 16;
7137 inst.instruction |= inst.operands[2].reg;
7138 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7139
c19d1205
ZW
7140 /* rdhi, rdlo and rm must all be different. */
7141 if (inst.operands[0].reg == inst.operands[1].reg
7142 || inst.operands[0].reg == inst.operands[2].reg
7143 || inst.operands[1].reg == inst.operands[2].reg)
7144 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7145}
b99bd4ef 7146
c19d1205
ZW
7147static void
7148do_nop (void)
7149{
7150 if (inst.operands[0].present)
7151 {
7152 /* Architectural NOP hints are CPSR sets with no bits selected. */
7153 inst.instruction &= 0xf0000000;
7154 inst.instruction |= 0x0320f000 + inst.operands[0].imm;
7155 }
b99bd4ef
NC
7156}
7157
c19d1205
ZW
7158/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7159 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7160 Condition defaults to COND_ALWAYS.
7161 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7162
7163static void
c19d1205 7164do_pkhbt (void)
b99bd4ef 7165{
c19d1205
ZW
7166 inst.instruction |= inst.operands[0].reg << 12;
7167 inst.instruction |= inst.operands[1].reg << 16;
7168 inst.instruction |= inst.operands[2].reg;
7169 if (inst.operands[3].present)
7170 encode_arm_shift (3);
7171}
b99bd4ef 7172
c19d1205 7173/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7174
c19d1205
ZW
7175static void
7176do_pkhtb (void)
7177{
7178 if (!inst.operands[3].present)
b99bd4ef 7179 {
c19d1205
ZW
7180 /* If the shift specifier is omitted, turn the instruction
7181 into pkhbt rd, rm, rn. */
7182 inst.instruction &= 0xfff00010;
7183 inst.instruction |= inst.operands[0].reg << 12;
7184 inst.instruction |= inst.operands[1].reg;
7185 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7186 }
7187 else
7188 {
c19d1205
ZW
7189 inst.instruction |= inst.operands[0].reg << 12;
7190 inst.instruction |= inst.operands[1].reg << 16;
7191 inst.instruction |= inst.operands[2].reg;
7192 encode_arm_shift (3);
b99bd4ef
NC
7193 }
7194}
7195
c19d1205
ZW
7196/* ARMv5TE: Preload-Cache
7197
7198 PLD <addr_mode>
7199
7200 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7201
7202static void
c19d1205 7203do_pld (void)
b99bd4ef 7204{
c19d1205
ZW
7205 constraint (!inst.operands[0].isreg,
7206 _("'[' expected after PLD mnemonic"));
7207 constraint (inst.operands[0].postind,
7208 _("post-indexed expression used in preload instruction"));
7209 constraint (inst.operands[0].writeback,
7210 _("writeback used in preload instruction"));
7211 constraint (!inst.operands[0].preind,
7212 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7213 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7214}
b99bd4ef 7215
62b3e311
PB
7216/* ARMv7: PLI <addr_mode> */
7217static void
7218do_pli (void)
7219{
7220 constraint (!inst.operands[0].isreg,
7221 _("'[' expected after PLI mnemonic"));
7222 constraint (inst.operands[0].postind,
7223 _("post-indexed expression used in preload instruction"));
7224 constraint (inst.operands[0].writeback,
7225 _("writeback used in preload instruction"));
7226 constraint (!inst.operands[0].preind,
7227 _("unindexed addressing used in preload instruction"));
7228 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7229 inst.instruction &= ~PRE_INDEX;
7230}
7231
c19d1205
ZW
7232static void
7233do_push_pop (void)
7234{
7235 inst.operands[1] = inst.operands[0];
7236 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7237 inst.operands[0].isreg = 1;
7238 inst.operands[0].writeback = 1;
7239 inst.operands[0].reg = REG_SP;
7240 do_ldmstm ();
7241}
b99bd4ef 7242
c19d1205
ZW
7243/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7244 word at the specified address and the following word
7245 respectively.
7246 Unconditionally executed.
7247 Error if Rn is R15. */
b99bd4ef 7248
c19d1205
ZW
7249static void
7250do_rfe (void)
7251{
7252 inst.instruction |= inst.operands[0].reg << 16;
7253 if (inst.operands[0].writeback)
7254 inst.instruction |= WRITE_BACK;
7255}
b99bd4ef 7256
c19d1205 7257/* ARM V6 ssat (argument parse). */
b99bd4ef 7258
c19d1205
ZW
7259static void
7260do_ssat (void)
7261{
7262 inst.instruction |= inst.operands[0].reg << 12;
7263 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7264 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7265
c19d1205
ZW
7266 if (inst.operands[3].present)
7267 encode_arm_shift (3);
b99bd4ef
NC
7268}
7269
c19d1205 7270/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7271
7272static void
c19d1205 7273do_usat (void)
b99bd4ef 7274{
c19d1205
ZW
7275 inst.instruction |= inst.operands[0].reg << 12;
7276 inst.instruction |= inst.operands[1].imm << 16;
7277 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7278
c19d1205
ZW
7279 if (inst.operands[3].present)
7280 encode_arm_shift (3);
b99bd4ef
NC
7281}
7282
c19d1205 7283/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7284
7285static void
c19d1205 7286do_ssat16 (void)
09d92015 7287{
c19d1205
ZW
7288 inst.instruction |= inst.operands[0].reg << 12;
7289 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7290 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7291}
7292
c19d1205
ZW
7293static void
7294do_usat16 (void)
a737bd4d 7295{
c19d1205
ZW
7296 inst.instruction |= inst.operands[0].reg << 12;
7297 inst.instruction |= inst.operands[1].imm << 16;
7298 inst.instruction |= inst.operands[2].reg;
7299}
a737bd4d 7300
c19d1205
ZW
7301/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7302 preserving the other bits.
a737bd4d 7303
c19d1205
ZW
7304 setend <endian_specifier>, where <endian_specifier> is either
7305 BE or LE. */
a737bd4d 7306
c19d1205
ZW
7307static void
7308do_setend (void)
7309{
7310 if (inst.operands[0].imm)
7311 inst.instruction |= 0x200;
a737bd4d
NC
7312}
7313
7314static void
c19d1205 7315do_shift (void)
a737bd4d 7316{
c19d1205
ZW
7317 unsigned int Rm = (inst.operands[1].present
7318 ? inst.operands[1].reg
7319 : inst.operands[0].reg);
a737bd4d 7320
c19d1205
ZW
7321 inst.instruction |= inst.operands[0].reg << 12;
7322 inst.instruction |= Rm;
7323 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7324 {
c19d1205
ZW
7325 inst.instruction |= inst.operands[2].reg << 8;
7326 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7327 }
7328 else
c19d1205 7329 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7330}
7331
09d92015 7332static void
3eb17e6b 7333do_smc (void)
09d92015 7334{
3eb17e6b 7335 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7336 inst.reloc.pc_rel = 0;
09d92015
MM
7337}
7338
09d92015 7339static void
c19d1205 7340do_swi (void)
09d92015 7341{
c19d1205
ZW
7342 inst.reloc.type = BFD_RELOC_ARM_SWI;
7343 inst.reloc.pc_rel = 0;
09d92015
MM
7344}
7345
c19d1205
ZW
7346/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7347 SMLAxy{cond} Rd,Rm,Rs,Rn
7348 SMLAWy{cond} Rd,Rm,Rs,Rn
7349 Error if any register is R15. */
e16bb312 7350
c19d1205
ZW
7351static void
7352do_smla (void)
e16bb312 7353{
c19d1205
ZW
7354 inst.instruction |= inst.operands[0].reg << 16;
7355 inst.instruction |= inst.operands[1].reg;
7356 inst.instruction |= inst.operands[2].reg << 8;
7357 inst.instruction |= inst.operands[3].reg << 12;
7358}
a737bd4d 7359
c19d1205
ZW
7360/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7361 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7362 Error if any register is R15.
7363 Warning if Rdlo == Rdhi. */
a737bd4d 7364
c19d1205
ZW
7365static void
7366do_smlal (void)
7367{
7368 inst.instruction |= inst.operands[0].reg << 12;
7369 inst.instruction |= inst.operands[1].reg << 16;
7370 inst.instruction |= inst.operands[2].reg;
7371 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7372
c19d1205
ZW
7373 if (inst.operands[0].reg == inst.operands[1].reg)
7374 as_tsktsk (_("rdhi and rdlo must be different"));
7375}
a737bd4d 7376
c19d1205
ZW
7377/* ARM V5E (El Segundo) signed-multiply (argument parse)
7378 SMULxy{cond} Rd,Rm,Rs
7379 Error if any register is R15. */
a737bd4d 7380
c19d1205
ZW
7381static void
7382do_smul (void)
7383{
7384 inst.instruction |= inst.operands[0].reg << 16;
7385 inst.instruction |= inst.operands[1].reg;
7386 inst.instruction |= inst.operands[2].reg << 8;
7387}
a737bd4d 7388
c19d1205 7389/* ARM V6 srs (argument parse). */
a737bd4d 7390
c19d1205
ZW
7391static void
7392do_srs (void)
7393{
7394 inst.instruction |= inst.operands[0].imm;
7395 if (inst.operands[0].writeback)
7396 inst.instruction |= WRITE_BACK;
7397}
a737bd4d 7398
c19d1205 7399/* ARM V6 strex (argument parse). */
a737bd4d 7400
c19d1205
ZW
7401static void
7402do_strex (void)
7403{
7404 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7405 || inst.operands[2].postind || inst.operands[2].writeback
7406 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7407 || inst.operands[2].negative
7408 /* See comment in do_ldrex(). */
7409 || (inst.operands[2].reg == REG_PC),
7410 BAD_ADDR_MODE);
a737bd4d 7411
c19d1205
ZW
7412 constraint (inst.operands[0].reg == inst.operands[1].reg
7413 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7414
c19d1205
ZW
7415 constraint (inst.reloc.exp.X_op != O_constant
7416 || inst.reloc.exp.X_add_number != 0,
7417 _("offset must be zero in ARM encoding"));
a737bd4d 7418
c19d1205
ZW
7419 inst.instruction |= inst.operands[0].reg << 12;
7420 inst.instruction |= inst.operands[1].reg;
7421 inst.instruction |= inst.operands[2].reg << 16;
7422 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7423}
7424
7425static void
c19d1205 7426do_strexd (void)
e16bb312 7427{
c19d1205
ZW
7428 constraint (inst.operands[1].reg % 2 != 0,
7429 _("even register required"));
7430 constraint (inst.operands[2].present
7431 && inst.operands[2].reg != inst.operands[1].reg + 1,
7432 _("can only store two consecutive registers"));
7433 /* If op 2 were present and equal to PC, this function wouldn't
7434 have been called in the first place. */
7435 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7436
c19d1205
ZW
7437 constraint (inst.operands[0].reg == inst.operands[1].reg
7438 || inst.operands[0].reg == inst.operands[1].reg + 1
7439 || inst.operands[0].reg == inst.operands[3].reg,
7440 BAD_OVERLAP);
e16bb312 7441
c19d1205
ZW
7442 inst.instruction |= inst.operands[0].reg << 12;
7443 inst.instruction |= inst.operands[1].reg;
7444 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7445}
7446
c19d1205
ZW
7447/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7448 extends it to 32-bits, and adds the result to a value in another
7449 register. You can specify a rotation by 0, 8, 16, or 24 bits
7450 before extracting the 16-bit value.
7451 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7452 Condition defaults to COND_ALWAYS.
7453 Error if any register uses R15. */
7454
e16bb312 7455static void
c19d1205 7456do_sxtah (void)
e16bb312 7457{
c19d1205
ZW
7458 inst.instruction |= inst.operands[0].reg << 12;
7459 inst.instruction |= inst.operands[1].reg << 16;
7460 inst.instruction |= inst.operands[2].reg;
7461 inst.instruction |= inst.operands[3].imm << 10;
7462}
e16bb312 7463
c19d1205 7464/* ARM V6 SXTH.
e16bb312 7465
c19d1205
ZW
7466 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7467 Condition defaults to COND_ALWAYS.
7468 Error if any register uses R15. */
e16bb312
NC
7469
7470static void
c19d1205 7471do_sxth (void)
e16bb312 7472{
c19d1205
ZW
7473 inst.instruction |= inst.operands[0].reg << 12;
7474 inst.instruction |= inst.operands[1].reg;
7475 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7476}
c19d1205
ZW
7477\f
7478/* VFP instructions. In a logical order: SP variant first, monad
7479 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7480
7481static void
c19d1205 7482do_vfp_sp_monadic (void)
e16bb312 7483{
5287ad62
JB
7484 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7485 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7486}
7487
7488static void
c19d1205 7489do_vfp_sp_dyadic (void)
e16bb312 7490{
5287ad62
JB
7491 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7492 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7493 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7494}
7495
7496static void
c19d1205 7497do_vfp_sp_compare_z (void)
e16bb312 7498{
5287ad62 7499 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7500}
7501
7502static void
c19d1205 7503do_vfp_dp_sp_cvt (void)
e16bb312 7504{
5287ad62
JB
7505 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7506 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7507}
7508
7509static void
c19d1205 7510do_vfp_sp_dp_cvt (void)
e16bb312 7511{
5287ad62
JB
7512 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7513 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7514}
7515
7516static void
c19d1205 7517do_vfp_reg_from_sp (void)
e16bb312 7518{
c19d1205 7519 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7520 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7521}
7522
7523static void
c19d1205 7524do_vfp_reg2_from_sp2 (void)
e16bb312 7525{
c19d1205
ZW
7526 constraint (inst.operands[2].imm != 2,
7527 _("only two consecutive VFP SP registers allowed here"));
7528 inst.instruction |= inst.operands[0].reg << 12;
7529 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7530 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7531}
7532
7533static void
c19d1205 7534do_vfp_sp_from_reg (void)
e16bb312 7535{
5287ad62 7536 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7537 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7538}
7539
7540static void
c19d1205 7541do_vfp_sp2_from_reg2 (void)
e16bb312 7542{
c19d1205
ZW
7543 constraint (inst.operands[0].imm != 2,
7544 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7545 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7546 inst.instruction |= inst.operands[1].reg << 12;
7547 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7548}
7549
7550static void
c19d1205 7551do_vfp_sp_ldst (void)
e16bb312 7552{
5287ad62 7553 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7554 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7555}
7556
7557static void
c19d1205 7558do_vfp_dp_ldst (void)
e16bb312 7559{
5287ad62 7560 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7561 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7562}
7563
c19d1205 7564
e16bb312 7565static void
c19d1205 7566vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7567{
c19d1205
ZW
7568 if (inst.operands[0].writeback)
7569 inst.instruction |= WRITE_BACK;
7570 else
7571 constraint (ldstm_type != VFP_LDSTMIA,
7572 _("this addressing mode requires base-register writeback"));
7573 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7574 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7575 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7576}
7577
7578static void
c19d1205 7579vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7580{
c19d1205 7581 int count;
e16bb312 7582
c19d1205
ZW
7583 if (inst.operands[0].writeback)
7584 inst.instruction |= WRITE_BACK;
7585 else
7586 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7587 _("this addressing mode requires base-register writeback"));
e16bb312 7588
c19d1205 7589 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7590 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7591
c19d1205
ZW
7592 count = inst.operands[1].imm << 1;
7593 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7594 count += 1;
e16bb312 7595
c19d1205 7596 inst.instruction |= count;
e16bb312
NC
7597}
7598
7599static void
c19d1205 7600do_vfp_sp_ldstmia (void)
e16bb312 7601{
c19d1205 7602 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7603}
7604
7605static void
c19d1205 7606do_vfp_sp_ldstmdb (void)
e16bb312 7607{
c19d1205 7608 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7609}
7610
7611static void
c19d1205 7612do_vfp_dp_ldstmia (void)
e16bb312 7613{
c19d1205 7614 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7615}
7616
7617static void
c19d1205 7618do_vfp_dp_ldstmdb (void)
e16bb312 7619{
c19d1205 7620 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7621}
7622
7623static void
c19d1205 7624do_vfp_xp_ldstmia (void)
e16bb312 7625{
c19d1205
ZW
7626 vfp_dp_ldstm (VFP_LDSTMIAX);
7627}
e16bb312 7628
c19d1205
ZW
7629static void
7630do_vfp_xp_ldstmdb (void)
7631{
7632 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7633}
5287ad62
JB
7634
7635static void
7636do_vfp_dp_rd_rm (void)
7637{
7638 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7639 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7640}
7641
7642static void
7643do_vfp_dp_rn_rd (void)
7644{
7645 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7646 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7647}
7648
7649static void
7650do_vfp_dp_rd_rn (void)
7651{
7652 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7653 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7654}
7655
7656static void
7657do_vfp_dp_rd_rn_rm (void)
7658{
7659 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7660 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7661 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7662}
7663
7664static void
7665do_vfp_dp_rd (void)
7666{
7667 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7668}
7669
7670static void
7671do_vfp_dp_rm_rd_rn (void)
7672{
7673 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7674 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7675 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
7676}
7677
7678/* VFPv3 instructions. */
7679static void
7680do_vfp_sp_const (void)
7681{
7682 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7683 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7684 inst.instruction |= (inst.operands[1].imm >> 4);
7685}
7686
7687static void
7688do_vfp_dp_const (void)
7689{
7690 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7691 inst.instruction |= (inst.operands[1].imm & 15) << 16;
7692 inst.instruction |= (inst.operands[1].imm >> 4);
7693}
7694
7695static void
7696vfp_conv (int srcsize)
7697{
7698 unsigned immbits = srcsize - inst.operands[1].imm;
7699 inst.instruction |= (immbits & 1) << 5;
7700 inst.instruction |= (immbits >> 1);
7701}
7702
7703static void
7704do_vfp_sp_conv_16 (void)
7705{
7706 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7707 vfp_conv (16);
7708}
7709
7710static void
7711do_vfp_dp_conv_16 (void)
7712{
7713 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7714 vfp_conv (16);
7715}
7716
7717static void
7718do_vfp_sp_conv_32 (void)
7719{
7720 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7721 vfp_conv (32);
7722}
7723
7724static void
7725do_vfp_dp_conv_32 (void)
7726{
7727 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7728 vfp_conv (32);
7729}
7730
c19d1205
ZW
7731\f
7732/* FPA instructions. Also in a logical order. */
e16bb312 7733
c19d1205
ZW
7734static void
7735do_fpa_cmp (void)
7736{
7737 inst.instruction |= inst.operands[0].reg << 16;
7738 inst.instruction |= inst.operands[1].reg;
7739}
b99bd4ef
NC
7740
7741static void
c19d1205 7742do_fpa_ldmstm (void)
b99bd4ef 7743{
c19d1205
ZW
7744 inst.instruction |= inst.operands[0].reg << 12;
7745 switch (inst.operands[1].imm)
7746 {
7747 case 1: inst.instruction |= CP_T_X; break;
7748 case 2: inst.instruction |= CP_T_Y; break;
7749 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
7750 case 4: break;
7751 default: abort ();
7752 }
b99bd4ef 7753
c19d1205
ZW
7754 if (inst.instruction & (PRE_INDEX | INDEX_UP))
7755 {
7756 /* The instruction specified "ea" or "fd", so we can only accept
7757 [Rn]{!}. The instruction does not really support stacking or
7758 unstacking, so we have to emulate these by setting appropriate
7759 bits and offsets. */
7760 constraint (inst.reloc.exp.X_op != O_constant
7761 || inst.reloc.exp.X_add_number != 0,
7762 _("this instruction does not support indexing"));
b99bd4ef 7763
c19d1205
ZW
7764 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
7765 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 7766
c19d1205
ZW
7767 if (!(inst.instruction & INDEX_UP))
7768 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 7769
c19d1205
ZW
7770 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
7771 {
7772 inst.operands[2].preind = 0;
7773 inst.operands[2].postind = 1;
7774 }
7775 }
b99bd4ef 7776
c19d1205 7777 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 7778}
037e8744 7779
c19d1205
ZW
7780\f
7781/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 7782
c19d1205
ZW
7783static void
7784do_iwmmxt_tandorc (void)
7785{
7786 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
7787}
b99bd4ef 7788
c19d1205
ZW
7789static void
7790do_iwmmxt_textrc (void)
7791{
7792 inst.instruction |= inst.operands[0].reg << 12;
7793 inst.instruction |= inst.operands[1].imm;
7794}
b99bd4ef
NC
7795
7796static void
c19d1205 7797do_iwmmxt_textrm (void)
b99bd4ef 7798{
c19d1205
ZW
7799 inst.instruction |= inst.operands[0].reg << 12;
7800 inst.instruction |= inst.operands[1].reg << 16;
7801 inst.instruction |= inst.operands[2].imm;
7802}
b99bd4ef 7803
c19d1205
ZW
7804static void
7805do_iwmmxt_tinsr (void)
7806{
7807 inst.instruction |= inst.operands[0].reg << 16;
7808 inst.instruction |= inst.operands[1].reg << 12;
7809 inst.instruction |= inst.operands[2].imm;
7810}
b99bd4ef 7811
c19d1205
ZW
7812static void
7813do_iwmmxt_tmia (void)
7814{
7815 inst.instruction |= inst.operands[0].reg << 5;
7816 inst.instruction |= inst.operands[1].reg;
7817 inst.instruction |= inst.operands[2].reg << 12;
7818}
b99bd4ef 7819
c19d1205
ZW
7820static void
7821do_iwmmxt_waligni (void)
7822{
7823 inst.instruction |= inst.operands[0].reg << 12;
7824 inst.instruction |= inst.operands[1].reg << 16;
7825 inst.instruction |= inst.operands[2].reg;
7826 inst.instruction |= inst.operands[3].imm << 20;
7827}
b99bd4ef 7828
c19d1205
ZW
7829static void
7830do_iwmmxt_wmov (void)
7831{
7832 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
7833 inst.instruction |= inst.operands[0].reg << 12;
7834 inst.instruction |= inst.operands[1].reg << 16;
7835 inst.instruction |= inst.operands[1].reg;
7836}
b99bd4ef 7837
c19d1205
ZW
7838static void
7839do_iwmmxt_wldstbh (void)
7840{
8f06b2d8 7841 int reloc;
c19d1205 7842 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
7843 if (thumb_mode)
7844 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
7845 else
7846 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
7847 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
7848}
7849
c19d1205
ZW
7850static void
7851do_iwmmxt_wldstw (void)
7852{
7853 /* RIWR_RIWC clears .isreg for a control register. */
7854 if (!inst.operands[0].isreg)
7855 {
7856 constraint (inst.cond != COND_ALWAYS, BAD_COND);
7857 inst.instruction |= 0xf0000000;
7858 }
b99bd4ef 7859
c19d1205
ZW
7860 inst.instruction |= inst.operands[0].reg << 12;
7861 encode_arm_cp_address (1, TRUE, TRUE, 0);
7862}
b99bd4ef
NC
7863
7864static void
c19d1205 7865do_iwmmxt_wldstd (void)
b99bd4ef 7866{
c19d1205 7867 inst.instruction |= inst.operands[0].reg << 12;
f2184508 7868 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 7869}
b99bd4ef 7870
c19d1205
ZW
7871static void
7872do_iwmmxt_wshufh (void)
7873{
7874 inst.instruction |= inst.operands[0].reg << 12;
7875 inst.instruction |= inst.operands[1].reg << 16;
7876 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
7877 inst.instruction |= (inst.operands[2].imm & 0x0f);
7878}
b99bd4ef 7879
c19d1205
ZW
7880static void
7881do_iwmmxt_wzero (void)
7882{
7883 /* WZERO reg is an alias for WANDN reg, reg, reg. */
7884 inst.instruction |= inst.operands[0].reg;
7885 inst.instruction |= inst.operands[0].reg << 12;
7886 inst.instruction |= inst.operands[0].reg << 16;
7887}
7888\f
7889/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
7890 operations first, then control, shift, and load/store. */
b99bd4ef 7891
c19d1205 7892/* Insns like "foo X,Y,Z". */
b99bd4ef 7893
c19d1205
ZW
7894static void
7895do_mav_triple (void)
7896{
7897 inst.instruction |= inst.operands[0].reg << 16;
7898 inst.instruction |= inst.operands[1].reg;
7899 inst.instruction |= inst.operands[2].reg << 12;
7900}
b99bd4ef 7901
c19d1205
ZW
7902/* Insns like "foo W,X,Y,Z".
7903 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 7904
c19d1205
ZW
7905static void
7906do_mav_quad (void)
7907{
7908 inst.instruction |= inst.operands[0].reg << 5;
7909 inst.instruction |= inst.operands[1].reg << 12;
7910 inst.instruction |= inst.operands[2].reg << 16;
7911 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
7912}
7913
c19d1205
ZW
7914/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
7915static void
7916do_mav_dspsc (void)
a737bd4d 7917{
c19d1205
ZW
7918 inst.instruction |= inst.operands[1].reg << 12;
7919}
a737bd4d 7920
c19d1205
ZW
7921/* Maverick shift immediate instructions.
7922 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
7923 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 7924
c19d1205
ZW
7925static void
7926do_mav_shift (void)
7927{
7928 int imm = inst.operands[2].imm;
a737bd4d 7929
c19d1205
ZW
7930 inst.instruction |= inst.operands[0].reg << 12;
7931 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 7932
c19d1205
ZW
7933 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
7934 Bits 5-7 of the insn should have bits 4-6 of the immediate.
7935 Bit 4 should be 0. */
7936 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 7937
c19d1205
ZW
7938 inst.instruction |= imm;
7939}
7940\f
7941/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 7942
c19d1205
ZW
7943/* Xscale multiply-accumulate (argument parse)
7944 MIAcc acc0,Rm,Rs
7945 MIAPHcc acc0,Rm,Rs
7946 MIAxycc acc0,Rm,Rs. */
a737bd4d 7947
c19d1205
ZW
7948static void
7949do_xsc_mia (void)
7950{
7951 inst.instruction |= inst.operands[1].reg;
7952 inst.instruction |= inst.operands[2].reg << 12;
7953}
a737bd4d 7954
c19d1205 7955/* Xscale move-accumulator-register (argument parse)
a737bd4d 7956
c19d1205 7957 MARcc acc0,RdLo,RdHi. */
b99bd4ef 7958
c19d1205
ZW
7959static void
7960do_xsc_mar (void)
7961{
7962 inst.instruction |= inst.operands[1].reg << 12;
7963 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7964}
7965
c19d1205 7966/* Xscale move-register-accumulator (argument parse)
b99bd4ef 7967
c19d1205 7968 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
7969
7970static void
c19d1205 7971do_xsc_mra (void)
b99bd4ef 7972{
c19d1205
ZW
7973 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
7974 inst.instruction |= inst.operands[0].reg << 12;
7975 inst.instruction |= inst.operands[1].reg << 16;
7976}
7977\f
7978/* Encoding functions relevant only to Thumb. */
b99bd4ef 7979
c19d1205
ZW
7980/* inst.operands[i] is a shifted-register operand; encode
7981 it into inst.instruction in the format used by Thumb32. */
7982
7983static void
7984encode_thumb32_shifted_operand (int i)
7985{
7986 unsigned int value = inst.reloc.exp.X_add_number;
7987 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 7988
9c3c69f2
PB
7989 constraint (inst.operands[i].immisreg,
7990 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
7991 inst.instruction |= inst.operands[i].reg;
7992 if (shift == SHIFT_RRX)
7993 inst.instruction |= SHIFT_ROR << 4;
7994 else
b99bd4ef 7995 {
c19d1205
ZW
7996 constraint (inst.reloc.exp.X_op != O_constant,
7997 _("expression too complex"));
7998
7999 constraint (value > 32
8000 || (value == 32 && (shift == SHIFT_LSL
8001 || shift == SHIFT_ROR)),
8002 _("shift expression is too large"));
8003
8004 if (value == 0)
8005 shift = SHIFT_LSL;
8006 else if (value == 32)
8007 value = 0;
8008
8009 inst.instruction |= shift << 4;
8010 inst.instruction |= (value & 0x1c) << 10;
8011 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8012 }
c19d1205 8013}
b99bd4ef 8014
b99bd4ef 8015
c19d1205
ZW
8016/* inst.operands[i] was set up by parse_address. Encode it into a
8017 Thumb32 format load or store instruction. Reject forms that cannot
8018 be used with such instructions. If is_t is true, reject forms that
8019 cannot be used with a T instruction; if is_d is true, reject forms
8020 that cannot be used with a D instruction. */
b99bd4ef 8021
c19d1205
ZW
8022static void
8023encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8024{
8025 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8026
8027 constraint (!inst.operands[i].isreg,
53365c0d 8028 _("Instruction does not support =N addresses"));
b99bd4ef 8029
c19d1205
ZW
8030 inst.instruction |= inst.operands[i].reg << 16;
8031 if (inst.operands[i].immisreg)
b99bd4ef 8032 {
c19d1205
ZW
8033 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8034 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8035 constraint (inst.operands[i].negative,
8036 _("Thumb does not support negative register indexing"));
8037 constraint (inst.operands[i].postind,
8038 _("Thumb does not support register post-indexing"));
8039 constraint (inst.operands[i].writeback,
8040 _("Thumb does not support register indexing with writeback"));
8041 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8042 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8043
f40d1643 8044 inst.instruction |= inst.operands[i].imm;
c19d1205 8045 if (inst.operands[i].shifted)
b99bd4ef 8046 {
c19d1205
ZW
8047 constraint (inst.reloc.exp.X_op != O_constant,
8048 _("expression too complex"));
9c3c69f2
PB
8049 constraint (inst.reloc.exp.X_add_number < 0
8050 || inst.reloc.exp.X_add_number > 3,
c19d1205 8051 _("shift out of range"));
9c3c69f2 8052 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8053 }
8054 inst.reloc.type = BFD_RELOC_UNUSED;
8055 }
8056 else if (inst.operands[i].preind)
8057 {
8058 constraint (is_pc && inst.operands[i].writeback,
8059 _("cannot use writeback with PC-relative addressing"));
f40d1643 8060 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8061 _("cannot use writeback with this instruction"));
8062
8063 if (is_d)
8064 {
8065 inst.instruction |= 0x01000000;
8066 if (inst.operands[i].writeback)
8067 inst.instruction |= 0x00200000;
b99bd4ef 8068 }
c19d1205 8069 else
b99bd4ef 8070 {
c19d1205
ZW
8071 inst.instruction |= 0x00000c00;
8072 if (inst.operands[i].writeback)
8073 inst.instruction |= 0x00000100;
b99bd4ef 8074 }
c19d1205 8075 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8076 }
c19d1205 8077 else if (inst.operands[i].postind)
b99bd4ef 8078 {
c19d1205
ZW
8079 assert (inst.operands[i].writeback);
8080 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8081 constraint (is_t, _("cannot use post-indexing with this instruction"));
8082
8083 if (is_d)
8084 inst.instruction |= 0x00200000;
8085 else
8086 inst.instruction |= 0x00000900;
8087 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8088 }
8089 else /* unindexed - only for coprocessor */
8090 inst.error = _("instruction does not accept unindexed addressing");
8091}
8092
8093/* Table of Thumb instructions which exist in both 16- and 32-bit
8094 encodings (the latter only in post-V6T2 cores). The index is the
8095 value used in the insns table below. When there is more than one
8096 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8097 holds variant (1).
8098 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8099#define T16_32_TAB \
8100 X(adc, 4140, eb400000), \
8101 X(adcs, 4140, eb500000), \
8102 X(add, 1c00, eb000000), \
8103 X(adds, 1c00, eb100000), \
0110f2b8
PB
8104 X(addi, 0000, f1000000), \
8105 X(addis, 0000, f1100000), \
8106 X(add_pc,000f, f20f0000), \
8107 X(add_sp,000d, f10d0000), \
e9f89963 8108 X(adr, 000f, f20f0000), \
c19d1205
ZW
8109 X(and, 4000, ea000000), \
8110 X(ands, 4000, ea100000), \
8111 X(asr, 1000, fa40f000), \
8112 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8113 X(b, e000, f000b000), \
8114 X(bcond, d000, f0008000), \
c19d1205
ZW
8115 X(bic, 4380, ea200000), \
8116 X(bics, 4380, ea300000), \
8117 X(cmn, 42c0, eb100f00), \
8118 X(cmp, 2800, ebb00f00), \
8119 X(cpsie, b660, f3af8400), \
8120 X(cpsid, b670, f3af8600), \
8121 X(cpy, 4600, ea4f0000), \
0110f2b8 8122 X(dec_sp,80dd, f1bd0d00), \
c19d1205
ZW
8123 X(eor, 4040, ea800000), \
8124 X(eors, 4040, ea900000), \
0110f2b8 8125 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8126 X(ldmia, c800, e8900000), \
8127 X(ldr, 6800, f8500000), \
8128 X(ldrb, 7800, f8100000), \
8129 X(ldrh, 8800, f8300000), \
8130 X(ldrsb, 5600, f9100000), \
8131 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8132 X(ldr_pc,4800, f85f0000), \
8133 X(ldr_pc2,4800, f85f0000), \
8134 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8135 X(lsl, 0000, fa00f000), \
8136 X(lsls, 0000, fa10f000), \
8137 X(lsr, 0800, fa20f000), \
8138 X(lsrs, 0800, fa30f000), \
8139 X(mov, 2000, ea4f0000), \
8140 X(movs, 2000, ea5f0000), \
8141 X(mul, 4340, fb00f000), \
8142 X(muls, 4340, ffffffff), /* no 32b muls */ \
8143 X(mvn, 43c0, ea6f0000), \
8144 X(mvns, 43c0, ea7f0000), \
8145 X(neg, 4240, f1c00000), /* rsb #0 */ \
8146 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8147 X(orr, 4300, ea400000), \
8148 X(orrs, 4300, ea500000), \
e9f89963
PB
8149 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8150 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8151 X(rev, ba00, fa90f080), \
8152 X(rev16, ba40, fa90f090), \
8153 X(revsh, bac0, fa90f0b0), \
8154 X(ror, 41c0, fa60f000), \
8155 X(rors, 41c0, fa70f000), \
8156 X(sbc, 4180, eb600000), \
8157 X(sbcs, 4180, eb700000), \
8158 X(stmia, c000, e8800000), \
8159 X(str, 6000, f8400000), \
8160 X(strb, 7000, f8000000), \
8161 X(strh, 8000, f8200000), \
0110f2b8 8162 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8163 X(sub, 1e00, eba00000), \
8164 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8165 X(subi, 8000, f1a00000), \
8166 X(subis, 8000, f1b00000), \
c19d1205
ZW
8167 X(sxtb, b240, fa4ff080), \
8168 X(sxth, b200, fa0ff080), \
8169 X(tst, 4200, ea100f00), \
8170 X(uxtb, b2c0, fa5ff080), \
8171 X(uxth, b280, fa1ff080), \
8172 X(nop, bf00, f3af8000), \
8173 X(yield, bf10, f3af8001), \
8174 X(wfe, bf20, f3af8002), \
8175 X(wfi, bf30, f3af8003), \
8176 X(sev, bf40, f3af9004), /* typo, 8004? */
8177
8178/* To catch errors in encoding functions, the codes are all offset by
8179 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8180 as 16-bit instructions. */
8181#define X(a,b,c) T_MNEM_##a
8182enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8183#undef X
8184
8185#define X(a,b,c) 0x##b
8186static const unsigned short thumb_op16[] = { T16_32_TAB };
8187#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8188#undef X
8189
8190#define X(a,b,c) 0x##c
8191static const unsigned int thumb_op32[] = { T16_32_TAB };
8192#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8193#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8194#undef X
8195#undef T16_32_TAB
8196
8197/* Thumb instruction encoders, in alphabetical order. */
8198
92e90b6e
PB
8199/* ADDW or SUBW. */
8200static void
8201do_t_add_sub_w (void)
8202{
8203 int Rd, Rn;
8204
8205 Rd = inst.operands[0].reg;
8206 Rn = inst.operands[1].reg;
8207
8208 constraint (Rd == 15, _("PC not allowed as destination"));
8209 inst.instruction |= (Rn << 16) | (Rd << 8);
8210 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8211}
8212
c19d1205
ZW
8213/* Parse an add or subtract instruction. We get here with inst.instruction
8214 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8215
8216static void
8217do_t_add_sub (void)
8218{
8219 int Rd, Rs, Rn;
8220
8221 Rd = inst.operands[0].reg;
8222 Rs = (inst.operands[1].present
8223 ? inst.operands[1].reg /* Rd, Rs, foo */
8224 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8225
8226 if (unified_syntax)
8227 {
0110f2b8
PB
8228 bfd_boolean flags;
8229 bfd_boolean narrow;
8230 int opcode;
8231
8232 flags = (inst.instruction == T_MNEM_adds
8233 || inst.instruction == T_MNEM_subs);
8234 if (flags)
8235 narrow = (current_it_mask == 0);
8236 else
8237 narrow = (current_it_mask != 0);
c19d1205 8238 if (!inst.operands[2].isreg)
b99bd4ef 8239 {
16805f35
PB
8240 int add;
8241
8242 add = (inst.instruction == T_MNEM_add
8243 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8244 opcode = 0;
8245 if (inst.size_req != 4)
8246 {
0110f2b8
PB
8247 /* Attempt to use a narrow opcode, with relaxation if
8248 appropriate. */
8249 if (Rd == REG_SP && Rs == REG_SP && !flags)
8250 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8251 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8252 opcode = T_MNEM_add_sp;
8253 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8254 opcode = T_MNEM_add_pc;
8255 else if (Rd <= 7 && Rs <= 7 && narrow)
8256 {
8257 if (flags)
8258 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8259 else
8260 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8261 }
8262 if (opcode)
8263 {
8264 inst.instruction = THUMB_OP16(opcode);
8265 inst.instruction |= (Rd << 4) | Rs;
8266 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8267 if (inst.size_req != 2)
8268 inst.relax = opcode;
8269 }
8270 else
8271 constraint (inst.size_req == 2, BAD_HIREG);
8272 }
8273 if (inst.size_req == 4
8274 || (inst.size_req != 2 && !opcode))
8275 {
16805f35
PB
8276 if (Rs == REG_PC)
8277 {
8278 /* Always use addw/subw. */
8279 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8280 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8281 }
8282 else
8283 {
8284 inst.instruction = THUMB_OP32 (inst.instruction);
8285 inst.instruction = (inst.instruction & 0xe1ffffff)
8286 | 0x10000000;
8287 if (flags)
8288 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8289 else
8290 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8291 }
0110f2b8
PB
8292 inst.instruction |= inst.operands[0].reg << 8;
8293 inst.instruction |= inst.operands[1].reg << 16;
0110f2b8 8294 }
b99bd4ef 8295 }
c19d1205
ZW
8296 else
8297 {
8298 Rn = inst.operands[2].reg;
8299 /* See if we can do this with a 16-bit instruction. */
8300 if (!inst.operands[2].shifted && inst.size_req != 4)
8301 {
e27ec89e
PB
8302 if (Rd > 7 || Rs > 7 || Rn > 7)
8303 narrow = FALSE;
8304
8305 if (narrow)
c19d1205 8306 {
e27ec89e
PB
8307 inst.instruction = ((inst.instruction == T_MNEM_adds
8308 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8309 ? T_OPCODE_ADD_R3
8310 : T_OPCODE_SUB_R3);
8311 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8312 return;
8313 }
b99bd4ef 8314
c19d1205
ZW
8315 if (inst.instruction == T_MNEM_add)
8316 {
8317 if (Rd == Rs)
8318 {
8319 inst.instruction = T_OPCODE_ADD_HI;
8320 inst.instruction |= (Rd & 8) << 4;
8321 inst.instruction |= (Rd & 7);
8322 inst.instruction |= Rn << 3;
8323 return;
8324 }
8325 /* ... because addition is commutative! */
8326 else if (Rd == Rn)
8327 {
8328 inst.instruction = T_OPCODE_ADD_HI;
8329 inst.instruction |= (Rd & 8) << 4;
8330 inst.instruction |= (Rd & 7);
8331 inst.instruction |= Rs << 3;
8332 return;
8333 }
8334 }
8335 }
8336 /* If we get here, it can't be done in 16 bits. */
8337 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8338 _("shift must be constant"));
8339 inst.instruction = THUMB_OP32 (inst.instruction);
8340 inst.instruction |= Rd << 8;
8341 inst.instruction |= Rs << 16;
8342 encode_thumb32_shifted_operand (2);
8343 }
8344 }
8345 else
8346 {
8347 constraint (inst.instruction == T_MNEM_adds
8348 || inst.instruction == T_MNEM_subs,
8349 BAD_THUMB32);
b99bd4ef 8350
c19d1205 8351 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8352 {
c19d1205
ZW
8353 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8354 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8355 BAD_HIREG);
8356
8357 inst.instruction = (inst.instruction == T_MNEM_add
8358 ? 0x0000 : 0x8000);
8359 inst.instruction |= (Rd << 4) | Rs;
8360 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8361 return;
8362 }
8363
c19d1205
ZW
8364 Rn = inst.operands[2].reg;
8365 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8366
c19d1205
ZW
8367 /* We now have Rd, Rs, and Rn set to registers. */
8368 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8369 {
c19d1205
ZW
8370 /* Can't do this for SUB. */
8371 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8372 inst.instruction = T_OPCODE_ADD_HI;
8373 inst.instruction |= (Rd & 8) << 4;
8374 inst.instruction |= (Rd & 7);
8375 if (Rs == Rd)
8376 inst.instruction |= Rn << 3;
8377 else if (Rn == Rd)
8378 inst.instruction |= Rs << 3;
8379 else
8380 constraint (1, _("dest must overlap one source register"));
8381 }
8382 else
8383 {
8384 inst.instruction = (inst.instruction == T_MNEM_add
8385 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8386 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8387 }
b99bd4ef 8388 }
b99bd4ef
NC
8389}
8390
c19d1205
ZW
8391static void
8392do_t_adr (void)
8393{
0110f2b8
PB
8394 if (unified_syntax && inst.size_req == 0 && inst.operands[0].reg <= 7)
8395 {
8396 /* Defer to section relaxation. */
8397 inst.relax = inst.instruction;
8398 inst.instruction = THUMB_OP16 (inst.instruction);
8399 inst.instruction |= inst.operands[0].reg << 4;
8400 }
8401 else if (unified_syntax && inst.size_req != 2)
e9f89963 8402 {
0110f2b8 8403 /* Generate a 32-bit opcode. */
e9f89963
PB
8404 inst.instruction = THUMB_OP32 (inst.instruction);
8405 inst.instruction |= inst.operands[0].reg << 8;
8406 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8407 inst.reloc.pc_rel = 1;
8408 }
8409 else
8410 {
0110f2b8 8411 /* Generate a 16-bit opcode. */
e9f89963
PB
8412 inst.instruction = THUMB_OP16 (inst.instruction);
8413 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8414 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8415 inst.reloc.pc_rel = 1;
b99bd4ef 8416
e9f89963
PB
8417 inst.instruction |= inst.operands[0].reg << 4;
8418 }
c19d1205 8419}
b99bd4ef 8420
c19d1205
ZW
8421/* Arithmetic instructions for which there is just one 16-bit
8422 instruction encoding, and it allows only two low registers.
8423 For maximal compatibility with ARM syntax, we allow three register
8424 operands even when Thumb-32 instructions are not available, as long
8425 as the first two are identical. For instance, both "sbc r0,r1" and
8426 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8427static void
c19d1205 8428do_t_arit3 (void)
b99bd4ef 8429{
c19d1205 8430 int Rd, Rs, Rn;
b99bd4ef 8431
c19d1205
ZW
8432 Rd = inst.operands[0].reg;
8433 Rs = (inst.operands[1].present
8434 ? inst.operands[1].reg /* Rd, Rs, foo */
8435 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8436 Rn = inst.operands[2].reg;
b99bd4ef 8437
c19d1205 8438 if (unified_syntax)
b99bd4ef 8439 {
c19d1205
ZW
8440 if (!inst.operands[2].isreg)
8441 {
8442 /* For an immediate, we always generate a 32-bit opcode;
8443 section relaxation will shrink it later if possible. */
8444 inst.instruction = THUMB_OP32 (inst.instruction);
8445 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8446 inst.instruction |= Rd << 8;
8447 inst.instruction |= Rs << 16;
8448 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8449 }
8450 else
8451 {
e27ec89e
PB
8452 bfd_boolean narrow;
8453
c19d1205 8454 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8455 if (THUMB_SETS_FLAGS (inst.instruction))
8456 narrow = current_it_mask == 0;
8457 else
8458 narrow = current_it_mask != 0;
8459
8460 if (Rd > 7 || Rn > 7 || Rs > 7)
8461 narrow = FALSE;
8462 if (inst.operands[2].shifted)
8463 narrow = FALSE;
8464 if (inst.size_req == 4)
8465 narrow = FALSE;
8466
8467 if (narrow
c19d1205
ZW
8468 && Rd == Rs)
8469 {
8470 inst.instruction = THUMB_OP16 (inst.instruction);
8471 inst.instruction |= Rd;
8472 inst.instruction |= Rn << 3;
8473 return;
8474 }
b99bd4ef 8475
c19d1205
ZW
8476 /* If we get here, it can't be done in 16 bits. */
8477 constraint (inst.operands[2].shifted
8478 && inst.operands[2].immisreg,
8479 _("shift must be constant"));
8480 inst.instruction = THUMB_OP32 (inst.instruction);
8481 inst.instruction |= Rd << 8;
8482 inst.instruction |= Rs << 16;
8483 encode_thumb32_shifted_operand (2);
8484 }
a737bd4d 8485 }
c19d1205 8486 else
b99bd4ef 8487 {
c19d1205
ZW
8488 /* On its face this is a lie - the instruction does set the
8489 flags. However, the only supported mnemonic in this mode
8490 says it doesn't. */
8491 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8492
c19d1205
ZW
8493 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8494 _("unshifted register required"));
8495 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8496 constraint (Rd != Rs,
8497 _("dest and source1 must be the same register"));
a737bd4d 8498
c19d1205
ZW
8499 inst.instruction = THUMB_OP16 (inst.instruction);
8500 inst.instruction |= Rd;
8501 inst.instruction |= Rn << 3;
b99bd4ef 8502 }
a737bd4d 8503}
b99bd4ef 8504
c19d1205
ZW
8505/* Similarly, but for instructions where the arithmetic operation is
8506 commutative, so we can allow either of them to be different from
8507 the destination operand in a 16-bit instruction. For instance, all
8508 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8509 accepted. */
8510static void
8511do_t_arit3c (void)
a737bd4d 8512{
c19d1205 8513 int Rd, Rs, Rn;
b99bd4ef 8514
c19d1205
ZW
8515 Rd = inst.operands[0].reg;
8516 Rs = (inst.operands[1].present
8517 ? inst.operands[1].reg /* Rd, Rs, foo */
8518 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8519 Rn = inst.operands[2].reg;
a737bd4d 8520
c19d1205 8521 if (unified_syntax)
a737bd4d 8522 {
c19d1205 8523 if (!inst.operands[2].isreg)
b99bd4ef 8524 {
c19d1205
ZW
8525 /* For an immediate, we always generate a 32-bit opcode;
8526 section relaxation will shrink it later if possible. */
8527 inst.instruction = THUMB_OP32 (inst.instruction);
8528 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8529 inst.instruction |= Rd << 8;
8530 inst.instruction |= Rs << 16;
8531 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8532 }
c19d1205 8533 else
a737bd4d 8534 {
e27ec89e
PB
8535 bfd_boolean narrow;
8536
c19d1205 8537 /* See if we can do this with a 16-bit instruction. */
e27ec89e
PB
8538 if (THUMB_SETS_FLAGS (inst.instruction))
8539 narrow = current_it_mask == 0;
8540 else
8541 narrow = current_it_mask != 0;
8542
8543 if (Rd > 7 || Rn > 7 || Rs > 7)
8544 narrow = FALSE;
8545 if (inst.operands[2].shifted)
8546 narrow = FALSE;
8547 if (inst.size_req == 4)
8548 narrow = FALSE;
8549
8550 if (narrow)
a737bd4d 8551 {
c19d1205 8552 if (Rd == Rs)
a737bd4d 8553 {
c19d1205
ZW
8554 inst.instruction = THUMB_OP16 (inst.instruction);
8555 inst.instruction |= Rd;
8556 inst.instruction |= Rn << 3;
8557 return;
a737bd4d 8558 }
c19d1205 8559 if (Rd == Rn)
a737bd4d 8560 {
c19d1205
ZW
8561 inst.instruction = THUMB_OP16 (inst.instruction);
8562 inst.instruction |= Rd;
8563 inst.instruction |= Rs << 3;
8564 return;
a737bd4d
NC
8565 }
8566 }
c19d1205
ZW
8567
8568 /* If we get here, it can't be done in 16 bits. */
8569 constraint (inst.operands[2].shifted
8570 && inst.operands[2].immisreg,
8571 _("shift must be constant"));
8572 inst.instruction = THUMB_OP32 (inst.instruction);
8573 inst.instruction |= Rd << 8;
8574 inst.instruction |= Rs << 16;
8575 encode_thumb32_shifted_operand (2);
a737bd4d 8576 }
b99bd4ef 8577 }
c19d1205
ZW
8578 else
8579 {
8580 /* On its face this is a lie - the instruction does set the
8581 flags. However, the only supported mnemonic in this mode
8582 says it doesn't. */
8583 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8584
c19d1205
ZW
8585 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8586 _("unshifted register required"));
8587 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8588
8589 inst.instruction = THUMB_OP16 (inst.instruction);
8590 inst.instruction |= Rd;
8591
8592 if (Rd == Rs)
8593 inst.instruction |= Rn << 3;
8594 else if (Rd == Rn)
8595 inst.instruction |= Rs << 3;
8596 else
8597 constraint (1, _("dest must overlap one source register"));
8598 }
a737bd4d
NC
8599}
8600
62b3e311
PB
8601static void
8602do_t_barrier (void)
8603{
8604 if (inst.operands[0].present)
8605 {
8606 constraint ((inst.instruction & 0xf0) != 0x40
8607 && inst.operands[0].imm != 0xf,
8608 "bad barrier type");
8609 inst.instruction |= inst.operands[0].imm;
8610 }
8611 else
8612 inst.instruction |= 0xf;
8613}
8614
c19d1205
ZW
8615static void
8616do_t_bfc (void)
a737bd4d 8617{
c19d1205
ZW
8618 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
8619 constraint (msb > 32, _("bit-field extends past end of register"));
8620 /* The instruction encoding stores the LSB and MSB,
8621 not the LSB and width. */
8622 inst.instruction |= inst.operands[0].reg << 8;
8623 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
8624 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
8625 inst.instruction |= msb - 1;
b99bd4ef
NC
8626}
8627
c19d1205
ZW
8628static void
8629do_t_bfi (void)
b99bd4ef 8630{
c19d1205 8631 unsigned int msb;
b99bd4ef 8632
c19d1205
ZW
8633 /* #0 in second position is alternative syntax for bfc, which is
8634 the same instruction but with REG_PC in the Rm field. */
8635 if (!inst.operands[1].isreg)
8636 inst.operands[1].reg = REG_PC;
b99bd4ef 8637
c19d1205
ZW
8638 msb = inst.operands[2].imm + inst.operands[3].imm;
8639 constraint (msb > 32, _("bit-field extends past end of register"));
8640 /* The instruction encoding stores the LSB and MSB,
8641 not the LSB and width. */
8642 inst.instruction |= inst.operands[0].reg << 8;
8643 inst.instruction |= inst.operands[1].reg << 16;
8644 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8645 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8646 inst.instruction |= msb - 1;
b99bd4ef
NC
8647}
8648
c19d1205
ZW
8649static void
8650do_t_bfx (void)
b99bd4ef 8651{
c19d1205
ZW
8652 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
8653 _("bit-field extends past end of register"));
8654 inst.instruction |= inst.operands[0].reg << 8;
8655 inst.instruction |= inst.operands[1].reg << 16;
8656 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
8657 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
8658 inst.instruction |= inst.operands[3].imm - 1;
8659}
b99bd4ef 8660
c19d1205
ZW
8661/* ARM V5 Thumb BLX (argument parse)
8662 BLX <target_addr> which is BLX(1)
8663 BLX <Rm> which is BLX(2)
8664 Unfortunately, there are two different opcodes for this mnemonic.
8665 So, the insns[].value is not used, and the code here zaps values
8666 into inst.instruction.
b99bd4ef 8667
c19d1205
ZW
8668 ??? How to take advantage of the additional two bits of displacement
8669 available in Thumb32 mode? Need new relocation? */
b99bd4ef 8670
c19d1205
ZW
8671static void
8672do_t_blx (void)
8673{
dfa9f0d5 8674 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8675 if (inst.operands[0].isreg)
8676 /* We have a register, so this is BLX(2). */
8677 inst.instruction |= inst.operands[0].reg << 3;
b99bd4ef
NC
8678 else
8679 {
c19d1205 8680 /* No register. This must be BLX(1). */
2fc8bdac 8681 inst.instruction = 0xf000e800;
39b41c9c
PB
8682#ifdef OBJ_ELF
8683 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
8684 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
8685 else
8686#endif
8687 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 8688 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8689 }
8690}
8691
c19d1205
ZW
8692static void
8693do_t_branch (void)
b99bd4ef 8694{
0110f2b8 8695 int opcode;
dfa9f0d5
PB
8696 int cond;
8697
8698 if (current_it_mask)
8699 {
8700 /* Conditional branches inside IT blocks are encoded as unconditional
8701 branches. */
8702 cond = COND_ALWAYS;
8703 /* A branch must be the last instruction in an IT block. */
8704 constraint (current_it_mask != 0x10, BAD_BRANCH);
8705 }
8706 else
8707 cond = inst.cond;
8708
8709 if (cond != COND_ALWAYS)
0110f2b8
PB
8710 opcode = T_MNEM_bcond;
8711 else
8712 opcode = inst.instruction;
8713
8714 if (unified_syntax && inst.size_req == 4)
c19d1205 8715 {
0110f2b8 8716 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 8717 if (cond == COND_ALWAYS)
0110f2b8 8718 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
8719 else
8720 {
dfa9f0d5
PB
8721 assert (cond != 0xF);
8722 inst.instruction |= cond << 22;
c19d1205
ZW
8723 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
8724 }
8725 }
b99bd4ef
NC
8726 else
8727 {
0110f2b8 8728 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 8729 if (cond == COND_ALWAYS)
c19d1205
ZW
8730 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
8731 else
b99bd4ef 8732 {
dfa9f0d5 8733 inst.instruction |= cond << 8;
c19d1205 8734 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 8735 }
0110f2b8
PB
8736 /* Allow section relaxation. */
8737 if (unified_syntax && inst.size_req != 2)
8738 inst.relax = opcode;
b99bd4ef 8739 }
c19d1205
ZW
8740
8741 inst.reloc.pc_rel = 1;
b99bd4ef
NC
8742}
8743
8744static void
c19d1205 8745do_t_bkpt (void)
b99bd4ef 8746{
dfa9f0d5
PB
8747 constraint (inst.cond != COND_ALWAYS,
8748 _("instruction is always unconditional"));
c19d1205 8749 if (inst.operands[0].present)
b99bd4ef 8750 {
c19d1205
ZW
8751 constraint (inst.operands[0].imm > 255,
8752 _("immediate value out of range"));
8753 inst.instruction |= inst.operands[0].imm;
b99bd4ef 8754 }
b99bd4ef
NC
8755}
8756
8757static void
c19d1205 8758do_t_branch23 (void)
b99bd4ef 8759{
dfa9f0d5 8760 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205 8761 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
8762 inst.reloc.pc_rel = 1;
8763
c19d1205
ZW
8764 /* If the destination of the branch is a defined symbol which does not have
8765 the THUMB_FUNC attribute, then we must be calling a function which has
8766 the (interfacearm) attribute. We look for the Thumb entry point to that
8767 function and change the branch to refer to that function instead. */
8768 if ( inst.reloc.exp.X_op == O_symbol
8769 && inst.reloc.exp.X_add_symbol != NULL
8770 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
8771 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
8772 inst.reloc.exp.X_add_symbol =
8773 find_real_start (inst.reloc.exp.X_add_symbol);
90e4755a
RE
8774}
8775
8776static void
c19d1205 8777do_t_bx (void)
90e4755a 8778{
dfa9f0d5 8779 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8780 inst.instruction |= inst.operands[0].reg << 3;
8781 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
8782 should cause the alignment to be checked once it is known. This is
8783 because BX PC only works if the instruction is word aligned. */
8784}
90e4755a 8785
c19d1205
ZW
8786static void
8787do_t_bxj (void)
8788{
dfa9f0d5 8789 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
c19d1205
ZW
8790 if (inst.operands[0].reg == REG_PC)
8791 as_tsktsk (_("use of r15 in bxj is not really useful"));
90e4755a 8792
c19d1205 8793 inst.instruction |= inst.operands[0].reg << 16;
90e4755a
RE
8794}
8795
8796static void
c19d1205 8797do_t_clz (void)
90e4755a 8798{
c19d1205
ZW
8799 inst.instruction |= inst.operands[0].reg << 8;
8800 inst.instruction |= inst.operands[1].reg << 16;
8801 inst.instruction |= inst.operands[1].reg;
8802}
90e4755a 8803
dfa9f0d5
PB
8804static void
8805do_t_cps (void)
8806{
8807 constraint (current_it_mask, BAD_NOT_IT);
8808 inst.instruction |= inst.operands[0].imm;
8809}
8810
c19d1205
ZW
8811static void
8812do_t_cpsi (void)
8813{
dfa9f0d5 8814 constraint (current_it_mask, BAD_NOT_IT);
c19d1205 8815 if (unified_syntax
62b3e311
PB
8816 && (inst.operands[1].present || inst.size_req == 4)
8817 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 8818 {
c19d1205
ZW
8819 unsigned int imod = (inst.instruction & 0x0030) >> 4;
8820 inst.instruction = 0xf3af8000;
8821 inst.instruction |= imod << 9;
8822 inst.instruction |= inst.operands[0].imm << 5;
8823 if (inst.operands[1].present)
8824 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 8825 }
c19d1205 8826 else
90e4755a 8827 {
62b3e311
PB
8828 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
8829 && (inst.operands[0].imm & 4),
8830 _("selected processor does not support 'A' form "
8831 "of this instruction"));
8832 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
8833 _("Thumb does not support the 2-argument "
8834 "form of this instruction"));
8835 inst.instruction |= inst.operands[0].imm;
90e4755a 8836 }
90e4755a
RE
8837}
8838
c19d1205
ZW
8839/* THUMB CPY instruction (argument parse). */
8840
90e4755a 8841static void
c19d1205 8842do_t_cpy (void)
90e4755a 8843{
c19d1205 8844 if (inst.size_req == 4)
90e4755a 8845 {
c19d1205
ZW
8846 inst.instruction = THUMB_OP32 (T_MNEM_mov);
8847 inst.instruction |= inst.operands[0].reg << 8;
8848 inst.instruction |= inst.operands[1].reg;
90e4755a 8849 }
c19d1205 8850 else
90e4755a 8851 {
c19d1205
ZW
8852 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
8853 inst.instruction |= (inst.operands[0].reg & 0x7);
8854 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 8855 }
90e4755a
RE
8856}
8857
90e4755a 8858static void
c19d1205 8859do_t_czb (void)
90e4755a 8860{
dfa9f0d5 8861 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
8862 constraint (inst.operands[0].reg > 7, BAD_HIREG);
8863 inst.instruction |= inst.operands[0].reg;
8864 inst.reloc.pc_rel = 1;
8865 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
8866}
90e4755a 8867
62b3e311
PB
8868static void
8869do_t_dbg (void)
8870{
8871 inst.instruction |= inst.operands[0].imm;
8872}
8873
8874static void
8875do_t_div (void)
8876{
8877 if (!inst.operands[1].present)
8878 inst.operands[1].reg = inst.operands[0].reg;
8879 inst.instruction |= inst.operands[0].reg << 8;
8880 inst.instruction |= inst.operands[1].reg << 16;
8881 inst.instruction |= inst.operands[2].reg;
8882}
8883
c19d1205
ZW
8884static void
8885do_t_hint (void)
8886{
8887 if (unified_syntax && inst.size_req == 4)
8888 inst.instruction = THUMB_OP32 (inst.instruction);
8889 else
8890 inst.instruction = THUMB_OP16 (inst.instruction);
8891}
90e4755a 8892
c19d1205
ZW
8893static void
8894do_t_it (void)
8895{
8896 unsigned int cond = inst.operands[0].imm;
e27ec89e 8897
dfa9f0d5 8898 constraint (current_it_mask, BAD_NOT_IT);
e27ec89e
PB
8899 current_it_mask = (inst.instruction & 0xf) | 0x10;
8900 current_cc = cond;
8901
8902 /* If the condition is a negative condition, invert the mask. */
c19d1205 8903 if ((cond & 0x1) == 0x0)
90e4755a 8904 {
c19d1205 8905 unsigned int mask = inst.instruction & 0x000f;
90e4755a 8906
c19d1205
ZW
8907 if ((mask & 0x7) == 0)
8908 /* no conversion needed */;
8909 else if ((mask & 0x3) == 0)
e27ec89e
PB
8910 mask ^= 0x8;
8911 else if ((mask & 0x1) == 0)
8912 mask ^= 0xC;
c19d1205 8913 else
e27ec89e 8914 mask ^= 0xE;
90e4755a 8915
e27ec89e
PB
8916 inst.instruction &= 0xfff0;
8917 inst.instruction |= mask;
c19d1205 8918 }
90e4755a 8919
c19d1205
ZW
8920 inst.instruction |= cond << 4;
8921}
90e4755a 8922
c19d1205
ZW
8923static void
8924do_t_ldmstm (void)
8925{
8926 /* This really doesn't seem worth it. */
8927 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
8928 _("expression too complex"));
8929 constraint (inst.operands[1].writeback,
8930 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 8931
c19d1205
ZW
8932 if (unified_syntax)
8933 {
8934 /* See if we can use a 16-bit instruction. */
8935 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
8936 && inst.size_req != 4
8937 && inst.operands[0].reg <= 7
8938 && !(inst.operands[1].imm & ~0xff)
8939 && (inst.instruction == T_MNEM_stmia
8940 ? inst.operands[0].writeback
8941 : (inst.operands[0].writeback
8942 == !(inst.operands[1].imm & (1 << inst.operands[0].reg)))))
90e4755a 8943 {
c19d1205
ZW
8944 if (inst.instruction == T_MNEM_stmia
8945 && (inst.operands[1].imm & (1 << inst.operands[0].reg))
8946 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8947 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8948 inst.operands[0].reg);
90e4755a 8949
c19d1205
ZW
8950 inst.instruction = THUMB_OP16 (inst.instruction);
8951 inst.instruction |= inst.operands[0].reg << 8;
8952 inst.instruction |= inst.operands[1].imm;
8953 }
8954 else
8955 {
8956 if (inst.operands[1].imm & (1 << 13))
8957 as_warn (_("SP should not be in register list"));
8958 if (inst.instruction == T_MNEM_stmia)
90e4755a 8959 {
c19d1205
ZW
8960 if (inst.operands[1].imm & (1 << 15))
8961 as_warn (_("PC should not be in register list"));
8962 if (inst.operands[1].imm & (1 << inst.operands[0].reg))
8963 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8964 inst.operands[0].reg);
90e4755a
RE
8965 }
8966 else
8967 {
c19d1205
ZW
8968 if (inst.operands[1].imm & (1 << 14)
8969 && inst.operands[1].imm & (1 << 15))
8970 as_warn (_("LR and PC should not both be in register list"));
8971 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8972 && inst.operands[0].writeback)
8973 as_warn (_("base register should not be in register list "
8974 "when written back"));
90e4755a 8975 }
c19d1205
ZW
8976 if (inst.instruction < 0xffff)
8977 inst.instruction = THUMB_OP32 (inst.instruction);
8978 inst.instruction |= inst.operands[0].reg << 16;
8979 inst.instruction |= inst.operands[1].imm;
8980 if (inst.operands[0].writeback)
8981 inst.instruction |= WRITE_BACK;
90e4755a
RE
8982 }
8983 }
c19d1205 8984 else
90e4755a 8985 {
c19d1205
ZW
8986 constraint (inst.operands[0].reg > 7
8987 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
8988 if (inst.instruction == T_MNEM_stmia)
f03698e6 8989 {
c19d1205
ZW
8990 if (!inst.operands[0].writeback)
8991 as_warn (_("this instruction will write back the base register"));
8992 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
8993 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
8994 as_warn (_("value stored for r%d is UNPREDICTABLE"),
8995 inst.operands[0].reg);
f03698e6 8996 }
c19d1205 8997 else
90e4755a 8998 {
c19d1205
ZW
8999 if (!inst.operands[0].writeback
9000 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9001 as_warn (_("this instruction will write back the base register"));
9002 else if (inst.operands[0].writeback
9003 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9004 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9005 }
9006
c19d1205
ZW
9007 inst.instruction = THUMB_OP16 (inst.instruction);
9008 inst.instruction |= inst.operands[0].reg << 8;
9009 inst.instruction |= inst.operands[1].imm;
9010 }
9011}
e28cd48c 9012
c19d1205
ZW
9013static void
9014do_t_ldrex (void)
9015{
9016 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9017 || inst.operands[1].postind || inst.operands[1].writeback
9018 || inst.operands[1].immisreg || inst.operands[1].shifted
9019 || inst.operands[1].negative,
01cfc07f 9020 BAD_ADDR_MODE);
e28cd48c 9021
c19d1205
ZW
9022 inst.instruction |= inst.operands[0].reg << 12;
9023 inst.instruction |= inst.operands[1].reg << 16;
9024 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9025}
e28cd48c 9026
c19d1205
ZW
9027static void
9028do_t_ldrexd (void)
9029{
9030 if (!inst.operands[1].present)
1cac9012 9031 {
c19d1205
ZW
9032 constraint (inst.operands[0].reg == REG_LR,
9033 _("r14 not allowed as first register "
9034 "when second register is omitted"));
9035 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9036 }
c19d1205
ZW
9037 constraint (inst.operands[0].reg == inst.operands[1].reg,
9038 BAD_OVERLAP);
b99bd4ef 9039
c19d1205
ZW
9040 inst.instruction |= inst.operands[0].reg << 12;
9041 inst.instruction |= inst.operands[1].reg << 8;
9042 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9043}
9044
9045static void
c19d1205 9046do_t_ldst (void)
b99bd4ef 9047{
0110f2b8
PB
9048 unsigned long opcode;
9049 int Rn;
9050
9051 opcode = inst.instruction;
c19d1205 9052 if (unified_syntax)
b99bd4ef 9053 {
53365c0d
PB
9054 if (!inst.operands[1].isreg)
9055 {
9056 if (opcode <= 0xffff)
9057 inst.instruction = THUMB_OP32 (opcode);
9058 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9059 return;
9060 }
0110f2b8
PB
9061 if (inst.operands[1].isreg
9062 && !inst.operands[1].writeback
c19d1205
ZW
9063 && !inst.operands[1].shifted && !inst.operands[1].postind
9064 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9065 && opcode <= 0xffff
9066 && inst.size_req != 4)
c19d1205 9067 {
0110f2b8
PB
9068 /* Insn may have a 16-bit form. */
9069 Rn = inst.operands[1].reg;
9070 if (inst.operands[1].immisreg)
9071 {
9072 inst.instruction = THUMB_OP16 (opcode);
9073 /* [Rn, Ri] */
9074 if (Rn <= 7 && inst.operands[1].imm <= 7)
9075 goto op16;
9076 }
9077 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9078 && opcode != T_MNEM_ldrsb)
9079 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9080 || (Rn == REG_SP && opcode == T_MNEM_str))
9081 {
9082 /* [Rn, #const] */
9083 if (Rn > 7)
9084 {
9085 if (Rn == REG_PC)
9086 {
9087 if (inst.reloc.pc_rel)
9088 opcode = T_MNEM_ldr_pc2;
9089 else
9090 opcode = T_MNEM_ldr_pc;
9091 }
9092 else
9093 {
9094 if (opcode == T_MNEM_ldr)
9095 opcode = T_MNEM_ldr_sp;
9096 else
9097 opcode = T_MNEM_str_sp;
9098 }
9099 inst.instruction = inst.operands[0].reg << 8;
9100 }
9101 else
9102 {
9103 inst.instruction = inst.operands[0].reg;
9104 inst.instruction |= inst.operands[1].reg << 3;
9105 }
9106 inst.instruction |= THUMB_OP16 (opcode);
9107 if (inst.size_req == 2)
9108 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9109 else
9110 inst.relax = opcode;
9111 return;
9112 }
c19d1205 9113 }
0110f2b8
PB
9114 /* Definitely a 32-bit variant. */
9115 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9116 inst.instruction |= inst.operands[0].reg << 12;
9117 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9118 return;
9119 }
9120
c19d1205
ZW
9121 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9122
9123 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9124 {
c19d1205
ZW
9125 /* Only [Rn,Rm] is acceptable. */
9126 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9127 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9128 || inst.operands[1].postind || inst.operands[1].shifted
9129 || inst.operands[1].negative,
9130 _("Thumb does not support this addressing mode"));
9131 inst.instruction = THUMB_OP16 (inst.instruction);
9132 goto op16;
b99bd4ef 9133 }
c19d1205
ZW
9134
9135 inst.instruction = THUMB_OP16 (inst.instruction);
9136 if (!inst.operands[1].isreg)
9137 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9138 return;
b99bd4ef 9139
c19d1205
ZW
9140 constraint (!inst.operands[1].preind
9141 || inst.operands[1].shifted
9142 || inst.operands[1].writeback,
9143 _("Thumb does not support this addressing mode"));
9144 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9145 {
c19d1205
ZW
9146 constraint (inst.instruction & 0x0600,
9147 _("byte or halfword not valid for base register"));
9148 constraint (inst.operands[1].reg == REG_PC
9149 && !(inst.instruction & THUMB_LOAD_BIT),
9150 _("r15 based store not allowed"));
9151 constraint (inst.operands[1].immisreg,
9152 _("invalid base register for register offset"));
b99bd4ef 9153
c19d1205
ZW
9154 if (inst.operands[1].reg == REG_PC)
9155 inst.instruction = T_OPCODE_LDR_PC;
9156 else if (inst.instruction & THUMB_LOAD_BIT)
9157 inst.instruction = T_OPCODE_LDR_SP;
9158 else
9159 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9160
c19d1205
ZW
9161 inst.instruction |= inst.operands[0].reg << 8;
9162 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9163 return;
9164 }
90e4755a 9165
c19d1205
ZW
9166 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9167 if (!inst.operands[1].immisreg)
9168 {
9169 /* Immediate offset. */
9170 inst.instruction |= inst.operands[0].reg;
9171 inst.instruction |= inst.operands[1].reg << 3;
9172 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9173 return;
9174 }
90e4755a 9175
c19d1205
ZW
9176 /* Register offset. */
9177 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9178 constraint (inst.operands[1].negative,
9179 _("Thumb does not support this addressing mode"));
90e4755a 9180
c19d1205
ZW
9181 op16:
9182 switch (inst.instruction)
9183 {
9184 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9185 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9186 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9187 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9188 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9189 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9190 case 0x5600 /* ldrsb */:
9191 case 0x5e00 /* ldrsh */: break;
9192 default: abort ();
9193 }
90e4755a 9194
c19d1205
ZW
9195 inst.instruction |= inst.operands[0].reg;
9196 inst.instruction |= inst.operands[1].reg << 3;
9197 inst.instruction |= inst.operands[1].imm << 6;
9198}
90e4755a 9199
c19d1205
ZW
9200static void
9201do_t_ldstd (void)
9202{
9203 if (!inst.operands[1].present)
b99bd4ef 9204 {
c19d1205
ZW
9205 inst.operands[1].reg = inst.operands[0].reg + 1;
9206 constraint (inst.operands[0].reg == REG_LR,
9207 _("r14 not allowed here"));
b99bd4ef 9208 }
c19d1205
ZW
9209 inst.instruction |= inst.operands[0].reg << 12;
9210 inst.instruction |= inst.operands[1].reg << 8;
9211 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
9212
b99bd4ef
NC
9213}
9214
c19d1205
ZW
9215static void
9216do_t_ldstt (void)
9217{
9218 inst.instruction |= inst.operands[0].reg << 12;
9219 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9220}
a737bd4d 9221
b99bd4ef 9222static void
c19d1205 9223do_t_mla (void)
b99bd4ef 9224{
c19d1205
ZW
9225 inst.instruction |= inst.operands[0].reg << 8;
9226 inst.instruction |= inst.operands[1].reg << 16;
9227 inst.instruction |= inst.operands[2].reg;
9228 inst.instruction |= inst.operands[3].reg << 12;
9229}
b99bd4ef 9230
c19d1205
ZW
9231static void
9232do_t_mlal (void)
9233{
9234 inst.instruction |= inst.operands[0].reg << 12;
9235 inst.instruction |= inst.operands[1].reg << 8;
9236 inst.instruction |= inst.operands[2].reg << 16;
9237 inst.instruction |= inst.operands[3].reg;
9238}
b99bd4ef 9239
c19d1205
ZW
9240static void
9241do_t_mov_cmp (void)
9242{
9243 if (unified_syntax)
b99bd4ef 9244 {
c19d1205
ZW
9245 int r0off = (inst.instruction == T_MNEM_mov
9246 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9247 unsigned long opcode;
3d388997
PB
9248 bfd_boolean narrow;
9249 bfd_boolean low_regs;
9250
9251 low_regs = (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7);
0110f2b8 9252 opcode = inst.instruction;
3d388997 9253 if (current_it_mask)
0110f2b8 9254 narrow = opcode != T_MNEM_movs;
3d388997 9255 else
0110f2b8 9256 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9257 if (inst.size_req == 4
9258 || inst.operands[1].shifted)
9259 narrow = FALSE;
9260
c19d1205
ZW
9261 if (!inst.operands[1].isreg)
9262 {
0110f2b8
PB
9263 /* Immediate operand. */
9264 if (current_it_mask == 0 && opcode == T_MNEM_mov)
9265 narrow = 0;
9266 if (low_regs && narrow)
9267 {
9268 inst.instruction = THUMB_OP16 (opcode);
9269 inst.instruction |= inst.operands[0].reg << 8;
9270 if (inst.size_req == 2)
9271 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9272 else
9273 inst.relax = opcode;
9274 }
9275 else
9276 {
9277 inst.instruction = THUMB_OP32 (inst.instruction);
9278 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9279 inst.instruction |= inst.operands[0].reg << r0off;
9280 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9281 }
c19d1205 9282 }
3d388997 9283 else if (!narrow)
c19d1205
ZW
9284 {
9285 inst.instruction = THUMB_OP32 (inst.instruction);
9286 inst.instruction |= inst.operands[0].reg << r0off;
9287 encode_thumb32_shifted_operand (1);
9288 }
9289 else
9290 switch (inst.instruction)
9291 {
9292 case T_MNEM_mov:
9293 inst.instruction = T_OPCODE_MOV_HR;
9294 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9295 inst.instruction |= (inst.operands[0].reg & 0x7);
9296 inst.instruction |= inst.operands[1].reg << 3;
9297 break;
b99bd4ef 9298
c19d1205
ZW
9299 case T_MNEM_movs:
9300 /* We know we have low registers at this point.
9301 Generate ADD Rd, Rs, #0. */
9302 inst.instruction = T_OPCODE_ADD_I3;
9303 inst.instruction |= inst.operands[0].reg;
9304 inst.instruction |= inst.operands[1].reg << 3;
9305 break;
9306
9307 case T_MNEM_cmp:
3d388997 9308 if (low_regs)
c19d1205
ZW
9309 {
9310 inst.instruction = T_OPCODE_CMP_LR;
9311 inst.instruction |= inst.operands[0].reg;
9312 inst.instruction |= inst.operands[1].reg << 3;
9313 }
9314 else
9315 {
9316 inst.instruction = T_OPCODE_CMP_HR;
9317 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9318 inst.instruction |= (inst.operands[0].reg & 0x7);
9319 inst.instruction |= inst.operands[1].reg << 3;
9320 }
9321 break;
9322 }
b99bd4ef
NC
9323 return;
9324 }
9325
c19d1205
ZW
9326 inst.instruction = THUMB_OP16 (inst.instruction);
9327 if (inst.operands[1].isreg)
b99bd4ef 9328 {
c19d1205 9329 if (inst.operands[0].reg < 8 && inst.operands[1].reg < 8)
b99bd4ef 9330 {
c19d1205
ZW
9331 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
9332 since a MOV instruction produces unpredictable results. */
9333 if (inst.instruction == T_OPCODE_MOV_I8)
9334 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 9335 else
c19d1205 9336 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 9337
c19d1205
ZW
9338 inst.instruction |= inst.operands[0].reg;
9339 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9340 }
9341 else
9342 {
c19d1205
ZW
9343 if (inst.instruction == T_OPCODE_MOV_I8)
9344 inst.instruction = T_OPCODE_MOV_HR;
9345 else
9346 inst.instruction = T_OPCODE_CMP_HR;
9347 do_t_cpy ();
b99bd4ef
NC
9348 }
9349 }
c19d1205 9350 else
b99bd4ef 9351 {
c19d1205
ZW
9352 constraint (inst.operands[0].reg > 7,
9353 _("only lo regs allowed with immediate"));
9354 inst.instruction |= inst.operands[0].reg << 8;
9355 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9356 }
9357}
b99bd4ef 9358
c19d1205
ZW
9359static void
9360do_t_mov16 (void)
9361{
b6895b4f
PB
9362 bfd_vma imm;
9363 bfd_boolean top;
9364
9365 top = (inst.instruction & 0x00800000) != 0;
9366 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
9367 {
9368 constraint (top, _(":lower16: not allowed this instruction"));
9369 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
9370 }
9371 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
9372 {
9373 constraint (!top, _(":upper16: not allowed this instruction"));
9374 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
9375 }
9376
c19d1205 9377 inst.instruction |= inst.operands[0].reg << 8;
b6895b4f
PB
9378 if (inst.reloc.type == BFD_RELOC_UNUSED)
9379 {
9380 imm = inst.reloc.exp.X_add_number;
9381 inst.instruction |= (imm & 0xf000) << 4;
9382 inst.instruction |= (imm & 0x0800) << 15;
9383 inst.instruction |= (imm & 0x0700) << 4;
9384 inst.instruction |= (imm & 0x00ff);
9385 }
c19d1205 9386}
b99bd4ef 9387
c19d1205
ZW
9388static void
9389do_t_mvn_tst (void)
9390{
9391 if (unified_syntax)
9392 {
9393 int r0off = (inst.instruction == T_MNEM_mvn
9394 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
9395 bfd_boolean narrow;
9396
9397 if (inst.size_req == 4
9398 || inst.instruction > 0xffff
9399 || inst.operands[1].shifted
9400 || inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9401 narrow = FALSE;
9402 else if (inst.instruction == T_MNEM_cmn)
9403 narrow = TRUE;
9404 else if (THUMB_SETS_FLAGS (inst.instruction))
9405 narrow = (current_it_mask == 0);
9406 else
9407 narrow = (current_it_mask != 0);
9408
c19d1205 9409 if (!inst.operands[1].isreg)
b99bd4ef 9410 {
c19d1205
ZW
9411 /* For an immediate, we always generate a 32-bit opcode;
9412 section relaxation will shrink it later if possible. */
9413 if (inst.instruction < 0xffff)
9414 inst.instruction = THUMB_OP32 (inst.instruction);
9415 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9416 inst.instruction |= inst.operands[0].reg << r0off;
9417 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9418 }
c19d1205 9419 else
b99bd4ef 9420 {
c19d1205 9421 /* See if we can do this with a 16-bit instruction. */
3d388997 9422 if (narrow)
b99bd4ef 9423 {
c19d1205
ZW
9424 inst.instruction = THUMB_OP16 (inst.instruction);
9425 inst.instruction |= inst.operands[0].reg;
9426 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9427 }
c19d1205 9428 else
b99bd4ef 9429 {
c19d1205
ZW
9430 constraint (inst.operands[1].shifted
9431 && inst.operands[1].immisreg,
9432 _("shift must be constant"));
9433 if (inst.instruction < 0xffff)
9434 inst.instruction = THUMB_OP32 (inst.instruction);
9435 inst.instruction |= inst.operands[0].reg << r0off;
9436 encode_thumb32_shifted_operand (1);
b99bd4ef 9437 }
b99bd4ef
NC
9438 }
9439 }
9440 else
9441 {
c19d1205
ZW
9442 constraint (inst.instruction > 0xffff
9443 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
9444 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
9445 _("unshifted register required"));
9446 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9447 BAD_HIREG);
b99bd4ef 9448
c19d1205
ZW
9449 inst.instruction = THUMB_OP16 (inst.instruction);
9450 inst.instruction |= inst.operands[0].reg;
9451 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 9452 }
b99bd4ef
NC
9453}
9454
b05fe5cf 9455static void
c19d1205 9456do_t_mrs (void)
b05fe5cf 9457{
62b3e311 9458 int flags;
037e8744
JB
9459
9460 if (do_vfp_nsyn_mrs () == SUCCESS)
9461 return;
9462
62b3e311
PB
9463 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
9464 if (flags == 0)
9465 {
9466 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9467 _("selected processor does not support "
9468 "requested special purpose register"));
9469 }
9470 else
9471 {
9472 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9473 _("selected processor does not support "
9474 "requested special purpose register %x"));
9475 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
9476 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
9477 _("'CPSR' or 'SPSR' expected"));
9478 }
9479
c19d1205 9480 inst.instruction |= inst.operands[0].reg << 8;
62b3e311
PB
9481 inst.instruction |= (flags & SPSR_BIT) >> 2;
9482 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 9483}
b05fe5cf 9484
c19d1205
ZW
9485static void
9486do_t_msr (void)
9487{
62b3e311
PB
9488 int flags;
9489
037e8744
JB
9490 if (do_vfp_nsyn_msr () == SUCCESS)
9491 return;
9492
c19d1205
ZW
9493 constraint (!inst.operands[1].isreg,
9494 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
9495 flags = inst.operands[0].imm;
9496 if (flags & ~0xff)
9497 {
9498 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
9499 _("selected processor does not support "
9500 "requested special purpose register"));
9501 }
9502 else
9503 {
9504 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v7m),
9505 _("selected processor does not support "
9506 "requested special purpose register"));
9507 flags |= PSR_f;
9508 }
9509 inst.instruction |= (flags & SPSR_BIT) >> 2;
9510 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
9511 inst.instruction |= (flags & 0xff);
c19d1205
ZW
9512 inst.instruction |= inst.operands[1].reg << 16;
9513}
b05fe5cf 9514
c19d1205
ZW
9515static void
9516do_t_mul (void)
9517{
9518 if (!inst.operands[2].present)
9519 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 9520
c19d1205
ZW
9521 /* There is no 32-bit MULS and no 16-bit MUL. */
9522 if (unified_syntax && inst.instruction == T_MNEM_mul)
b05fe5cf 9523 {
c19d1205
ZW
9524 inst.instruction = THUMB_OP32 (inst.instruction);
9525 inst.instruction |= inst.operands[0].reg << 8;
9526 inst.instruction |= inst.operands[1].reg << 16;
9527 inst.instruction |= inst.operands[2].reg << 0;
b05fe5cf 9528 }
c19d1205 9529 else
b05fe5cf 9530 {
c19d1205
ZW
9531 constraint (!unified_syntax
9532 && inst.instruction == T_MNEM_muls, BAD_THUMB32);
9533 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9534 BAD_HIREG);
b05fe5cf 9535
c19d1205
ZW
9536 inst.instruction = THUMB_OP16 (inst.instruction);
9537 inst.instruction |= inst.operands[0].reg;
b05fe5cf 9538
c19d1205
ZW
9539 if (inst.operands[0].reg == inst.operands[1].reg)
9540 inst.instruction |= inst.operands[2].reg << 3;
9541 else if (inst.operands[0].reg == inst.operands[2].reg)
9542 inst.instruction |= inst.operands[1].reg << 3;
9543 else
9544 constraint (1, _("dest must overlap one source register"));
9545 }
9546}
b05fe5cf 9547
c19d1205
ZW
9548static void
9549do_t_mull (void)
9550{
9551 inst.instruction |= inst.operands[0].reg << 12;
9552 inst.instruction |= inst.operands[1].reg << 8;
9553 inst.instruction |= inst.operands[2].reg << 16;
9554 inst.instruction |= inst.operands[3].reg;
b05fe5cf 9555
c19d1205
ZW
9556 if (inst.operands[0].reg == inst.operands[1].reg)
9557 as_tsktsk (_("rdhi and rdlo must be different"));
9558}
b05fe5cf 9559
c19d1205
ZW
9560static void
9561do_t_nop (void)
9562{
9563 if (unified_syntax)
9564 {
9565 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 9566 {
c19d1205
ZW
9567 inst.instruction = THUMB_OP32 (inst.instruction);
9568 inst.instruction |= inst.operands[0].imm;
9569 }
9570 else
9571 {
9572 inst.instruction = THUMB_OP16 (inst.instruction);
9573 inst.instruction |= inst.operands[0].imm << 4;
9574 }
9575 }
9576 else
9577 {
9578 constraint (inst.operands[0].present,
9579 _("Thumb does not support NOP with hints"));
9580 inst.instruction = 0x46c0;
9581 }
9582}
b05fe5cf 9583
c19d1205
ZW
9584static void
9585do_t_neg (void)
9586{
9587 if (unified_syntax)
9588 {
3d388997
PB
9589 bfd_boolean narrow;
9590
9591 if (THUMB_SETS_FLAGS (inst.instruction))
9592 narrow = (current_it_mask == 0);
9593 else
9594 narrow = (current_it_mask != 0);
9595 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9596 narrow = FALSE;
9597 if (inst.size_req == 4)
9598 narrow = FALSE;
9599
9600 if (!narrow)
c19d1205
ZW
9601 {
9602 inst.instruction = THUMB_OP32 (inst.instruction);
9603 inst.instruction |= inst.operands[0].reg << 8;
9604 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
9605 }
9606 else
9607 {
c19d1205
ZW
9608 inst.instruction = THUMB_OP16 (inst.instruction);
9609 inst.instruction |= inst.operands[0].reg;
9610 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
9611 }
9612 }
9613 else
9614 {
c19d1205
ZW
9615 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
9616 BAD_HIREG);
9617 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
9618
9619 inst.instruction = THUMB_OP16 (inst.instruction);
9620 inst.instruction |= inst.operands[0].reg;
9621 inst.instruction |= inst.operands[1].reg << 3;
9622 }
9623}
9624
9625static void
9626do_t_pkhbt (void)
9627{
9628 inst.instruction |= inst.operands[0].reg << 8;
9629 inst.instruction |= inst.operands[1].reg << 16;
9630 inst.instruction |= inst.operands[2].reg;
9631 if (inst.operands[3].present)
9632 {
9633 unsigned int val = inst.reloc.exp.X_add_number;
9634 constraint (inst.reloc.exp.X_op != O_constant,
9635 _("expression too complex"));
9636 inst.instruction |= (val & 0x1c) << 10;
9637 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 9638 }
c19d1205 9639}
b05fe5cf 9640
c19d1205
ZW
9641static void
9642do_t_pkhtb (void)
9643{
9644 if (!inst.operands[3].present)
9645 inst.instruction &= ~0x00000020;
9646 do_t_pkhbt ();
b05fe5cf
ZW
9647}
9648
c19d1205
ZW
9649static void
9650do_t_pld (void)
9651{
9652 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
9653}
b05fe5cf 9654
c19d1205
ZW
9655static void
9656do_t_push_pop (void)
b99bd4ef 9657{
e9f89963
PB
9658 unsigned mask;
9659
c19d1205
ZW
9660 constraint (inst.operands[0].writeback,
9661 _("push/pop do not support {reglist}^"));
9662 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9663 _("expression too complex"));
b99bd4ef 9664
e9f89963
PB
9665 mask = inst.operands[0].imm;
9666 if ((mask & ~0xff) == 0)
c19d1205
ZW
9667 inst.instruction = THUMB_OP16 (inst.instruction);
9668 else if ((inst.instruction == T_MNEM_push
e9f89963 9669 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 9670 || (inst.instruction == T_MNEM_pop
e9f89963 9671 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 9672 {
c19d1205
ZW
9673 inst.instruction = THUMB_OP16 (inst.instruction);
9674 inst.instruction |= THUMB_PP_PC_LR;
e9f89963 9675 mask &= 0xff;
c19d1205
ZW
9676 }
9677 else if (unified_syntax)
9678 {
e9f89963
PB
9679 if (mask & (1 << 13))
9680 inst.error = _("SP not allowed in register list");
c19d1205 9681 if (inst.instruction == T_MNEM_push)
b99bd4ef 9682 {
e9f89963
PB
9683 if (mask & (1 << 15))
9684 inst.error = _("PC not allowed in register list");
c19d1205
ZW
9685 }
9686 else
9687 {
e9f89963
PB
9688 if (mask & (1 << 14)
9689 && mask & (1 << 15))
9690 inst.error = _("LR and PC should not both be in register list");
c19d1205 9691 }
e9f89963
PB
9692 if ((mask & (mask - 1)) == 0)
9693 {
9694 /* Single register push/pop implemented as str/ldr. */
9695 if (inst.instruction == T_MNEM_push)
9696 inst.instruction = 0xf84d0d04; /* str reg, [sp, #-4]! */
9697 else
9698 inst.instruction = 0xf85d0b04; /* ldr reg, [sp], #4 */
9699 mask = ffs(mask) - 1;
9700 mask <<= 12;
9701 }
9702 else
9703 inst.instruction = THUMB_OP32 (inst.instruction);
c19d1205
ZW
9704 }
9705 else
9706 {
9707 inst.error = _("invalid register list to push/pop instruction");
9708 return;
9709 }
b99bd4ef 9710
e9f89963 9711 inst.instruction |= mask;
c19d1205 9712}
b99bd4ef 9713
c19d1205
ZW
9714static void
9715do_t_rbit (void)
9716{
9717 inst.instruction |= inst.operands[0].reg << 8;
9718 inst.instruction |= inst.operands[1].reg << 16;
9719}
b99bd4ef 9720
c19d1205
ZW
9721static void
9722do_t_rev (void)
9723{
9724 if (inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
9725 && inst.size_req != 4)
9726 {
9727 inst.instruction = THUMB_OP16 (inst.instruction);
9728 inst.instruction |= inst.operands[0].reg;
9729 inst.instruction |= inst.operands[1].reg << 3;
9730 }
9731 else if (unified_syntax)
9732 {
9733 inst.instruction = THUMB_OP32 (inst.instruction);
9734 inst.instruction |= inst.operands[0].reg << 8;
9735 inst.instruction |= inst.operands[1].reg << 16;
9736 inst.instruction |= inst.operands[1].reg;
9737 }
9738 else
9739 inst.error = BAD_HIREG;
9740}
b99bd4ef 9741
c19d1205
ZW
9742static void
9743do_t_rsb (void)
9744{
9745 int Rd, Rs;
b99bd4ef 9746
c19d1205
ZW
9747 Rd = inst.operands[0].reg;
9748 Rs = (inst.operands[1].present
9749 ? inst.operands[1].reg /* Rd, Rs, foo */
9750 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 9751
c19d1205
ZW
9752 inst.instruction |= Rd << 8;
9753 inst.instruction |= Rs << 16;
9754 if (!inst.operands[2].isreg)
9755 {
9756 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9757 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9758 }
9759 else
9760 encode_thumb32_shifted_operand (2);
9761}
b99bd4ef 9762
c19d1205
ZW
9763static void
9764do_t_setend (void)
9765{
dfa9f0d5 9766 constraint (current_it_mask, BAD_NOT_IT);
c19d1205
ZW
9767 if (inst.operands[0].imm)
9768 inst.instruction |= 0x8;
9769}
b99bd4ef 9770
c19d1205
ZW
9771static void
9772do_t_shift (void)
9773{
9774 if (!inst.operands[1].present)
9775 inst.operands[1].reg = inst.operands[0].reg;
9776
9777 if (unified_syntax)
9778 {
3d388997
PB
9779 bfd_boolean narrow;
9780 int shift_kind;
9781
9782 switch (inst.instruction)
9783 {
9784 case T_MNEM_asr:
9785 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
9786 case T_MNEM_lsl:
9787 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
9788 case T_MNEM_lsr:
9789 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
9790 case T_MNEM_ror:
9791 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
9792 default: abort ();
9793 }
9794
9795 if (THUMB_SETS_FLAGS (inst.instruction))
9796 narrow = (current_it_mask == 0);
9797 else
9798 narrow = (current_it_mask != 0);
9799 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
9800 narrow = FALSE;
9801 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
9802 narrow = FALSE;
9803 if (inst.operands[2].isreg
9804 && (inst.operands[1].reg != inst.operands[0].reg
9805 || inst.operands[2].reg > 7))
9806 narrow = FALSE;
9807 if (inst.size_req == 4)
9808 narrow = FALSE;
9809
9810 if (!narrow)
c19d1205
ZW
9811 {
9812 if (inst.operands[2].isreg)
b99bd4ef 9813 {
c19d1205
ZW
9814 inst.instruction = THUMB_OP32 (inst.instruction);
9815 inst.instruction |= inst.operands[0].reg << 8;
9816 inst.instruction |= inst.operands[1].reg << 16;
9817 inst.instruction |= inst.operands[2].reg;
9818 }
9819 else
9820 {
9821 inst.operands[1].shifted = 1;
3d388997 9822 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
9823 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
9824 ? T_MNEM_movs : T_MNEM_mov);
9825 inst.instruction |= inst.operands[0].reg << 8;
9826 encode_thumb32_shifted_operand (1);
9827 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
9828 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
9829 }
9830 }
9831 else
9832 {
c19d1205 9833 if (inst.operands[2].isreg)
b99bd4ef 9834 {
3d388997 9835 switch (shift_kind)
b99bd4ef 9836 {
3d388997
PB
9837 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
9838 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
9839 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
9840 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 9841 default: abort ();
b99bd4ef 9842 }
c19d1205
ZW
9843
9844 inst.instruction |= inst.operands[0].reg;
9845 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
9846 }
9847 else
9848 {
3d388997 9849 switch (shift_kind)
b99bd4ef 9850 {
3d388997
PB
9851 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9852 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9853 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 9854 default: abort ();
b99bd4ef 9855 }
c19d1205
ZW
9856 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9857 inst.instruction |= inst.operands[0].reg;
9858 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9859 }
9860 }
c19d1205
ZW
9861 }
9862 else
9863 {
9864 constraint (inst.operands[0].reg > 7
9865 || inst.operands[1].reg > 7, BAD_HIREG);
9866 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 9867
c19d1205
ZW
9868 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
9869 {
9870 constraint (inst.operands[2].reg > 7, BAD_HIREG);
9871 constraint (inst.operands[0].reg != inst.operands[1].reg,
9872 _("source1 and dest must be same register"));
b99bd4ef 9873
c19d1205
ZW
9874 switch (inst.instruction)
9875 {
9876 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
9877 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
9878 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
9879 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
9880 default: abort ();
9881 }
9882
9883 inst.instruction |= inst.operands[0].reg;
9884 inst.instruction |= inst.operands[2].reg << 3;
9885 }
9886 else
b99bd4ef 9887 {
c19d1205
ZW
9888 switch (inst.instruction)
9889 {
9890 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
9891 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
9892 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
9893 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
9894 default: abort ();
9895 }
9896 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9897 inst.instruction |= inst.operands[0].reg;
9898 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
9899 }
9900 }
b99bd4ef
NC
9901}
9902
9903static void
c19d1205 9904do_t_simd (void)
b99bd4ef 9905{
c19d1205
ZW
9906 inst.instruction |= inst.operands[0].reg << 8;
9907 inst.instruction |= inst.operands[1].reg << 16;
9908 inst.instruction |= inst.operands[2].reg;
9909}
b99bd4ef 9910
c19d1205 9911static void
3eb17e6b 9912do_t_smc (void)
c19d1205
ZW
9913{
9914 unsigned int value = inst.reloc.exp.X_add_number;
9915 constraint (inst.reloc.exp.X_op != O_constant,
9916 _("expression too complex"));
9917 inst.reloc.type = BFD_RELOC_UNUSED;
9918 inst.instruction |= (value & 0xf000) >> 12;
9919 inst.instruction |= (value & 0x0ff0);
9920 inst.instruction |= (value & 0x000f) << 16;
9921}
b99bd4ef 9922
c19d1205
ZW
9923static void
9924do_t_ssat (void)
9925{
9926 inst.instruction |= inst.operands[0].reg << 8;
9927 inst.instruction |= inst.operands[1].imm - 1;
9928 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 9929
c19d1205 9930 if (inst.operands[3].present)
b99bd4ef 9931 {
c19d1205
ZW
9932 constraint (inst.reloc.exp.X_op != O_constant,
9933 _("expression too complex"));
b99bd4ef 9934
c19d1205 9935 if (inst.reloc.exp.X_add_number != 0)
6189168b 9936 {
c19d1205
ZW
9937 if (inst.operands[3].shift_kind == SHIFT_ASR)
9938 inst.instruction |= 0x00200000; /* sh bit */
9939 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
9940 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
6189168b 9941 }
c19d1205 9942 inst.reloc.type = BFD_RELOC_UNUSED;
6189168b 9943 }
b99bd4ef
NC
9944}
9945
0dd132b6 9946static void
c19d1205 9947do_t_ssat16 (void)
0dd132b6 9948{
c19d1205
ZW
9949 inst.instruction |= inst.operands[0].reg << 8;
9950 inst.instruction |= inst.operands[1].imm - 1;
9951 inst.instruction |= inst.operands[2].reg << 16;
9952}
0dd132b6 9953
c19d1205
ZW
9954static void
9955do_t_strex (void)
9956{
9957 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
9958 || inst.operands[2].postind || inst.operands[2].writeback
9959 || inst.operands[2].immisreg || inst.operands[2].shifted
9960 || inst.operands[2].negative,
01cfc07f 9961 BAD_ADDR_MODE);
0dd132b6 9962
c19d1205
ZW
9963 inst.instruction |= inst.operands[0].reg << 8;
9964 inst.instruction |= inst.operands[1].reg << 12;
9965 inst.instruction |= inst.operands[2].reg << 16;
9966 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
9967}
9968
b99bd4ef 9969static void
c19d1205 9970do_t_strexd (void)
b99bd4ef 9971{
c19d1205
ZW
9972 if (!inst.operands[2].present)
9973 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 9974
c19d1205
ZW
9975 constraint (inst.operands[0].reg == inst.operands[1].reg
9976 || inst.operands[0].reg == inst.operands[2].reg
9977 || inst.operands[0].reg == inst.operands[3].reg
9978 || inst.operands[1].reg == inst.operands[2].reg,
9979 BAD_OVERLAP);
b99bd4ef 9980
c19d1205
ZW
9981 inst.instruction |= inst.operands[0].reg;
9982 inst.instruction |= inst.operands[1].reg << 12;
9983 inst.instruction |= inst.operands[2].reg << 8;
9984 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
9985}
9986
9987static void
c19d1205 9988do_t_sxtah (void)
b99bd4ef 9989{
c19d1205
ZW
9990 inst.instruction |= inst.operands[0].reg << 8;
9991 inst.instruction |= inst.operands[1].reg << 16;
9992 inst.instruction |= inst.operands[2].reg;
9993 inst.instruction |= inst.operands[3].imm << 4;
9994}
b99bd4ef 9995
c19d1205
ZW
9996static void
9997do_t_sxth (void)
9998{
9999 if (inst.instruction <= 0xffff && inst.size_req != 4
10000 && inst.operands[0].reg <= 7 && inst.operands[1].reg <= 7
10001 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10002 {
c19d1205
ZW
10003 inst.instruction = THUMB_OP16 (inst.instruction);
10004 inst.instruction |= inst.operands[0].reg;
10005 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef 10006 }
c19d1205 10007 else if (unified_syntax)
b99bd4ef 10008 {
c19d1205
ZW
10009 if (inst.instruction <= 0xffff)
10010 inst.instruction = THUMB_OP32 (inst.instruction);
10011 inst.instruction |= inst.operands[0].reg << 8;
10012 inst.instruction |= inst.operands[1].reg;
10013 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10014 }
c19d1205 10015 else
b99bd4ef 10016 {
c19d1205
ZW
10017 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10018 _("Thumb encoding does not support rotation"));
10019 constraint (1, BAD_HIREG);
b99bd4ef 10020 }
c19d1205 10021}
b99bd4ef 10022
c19d1205
ZW
10023static void
10024do_t_swi (void)
10025{
10026 inst.reloc.type = BFD_RELOC_ARM_SWI;
10027}
b99bd4ef 10028
92e90b6e
PB
10029static void
10030do_t_tb (void)
10031{
10032 int half;
10033
10034 half = (inst.instruction & 0x10) != 0;
dfa9f0d5
PB
10035 constraint (current_it_mask && current_it_mask != 0x10, BAD_BRANCH);
10036 constraint (inst.operands[0].immisreg,
10037 _("instruction requires register index"));
92e90b6e
PB
10038 constraint (inst.operands[0].imm == 15,
10039 _("PC is not a valid index register"));
10040 constraint (!half && inst.operands[0].shifted,
10041 _("instruction does not allow shifted index"));
92e90b6e
PB
10042 inst.instruction |= (inst.operands[0].reg << 16) | inst.operands[0].imm;
10043}
10044
c19d1205
ZW
10045static void
10046do_t_usat (void)
10047{
10048 inst.instruction |= inst.operands[0].reg << 8;
10049 inst.instruction |= inst.operands[1].imm;
10050 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10051
c19d1205 10052 if (inst.operands[3].present)
b99bd4ef 10053 {
c19d1205
ZW
10054 constraint (inst.reloc.exp.X_op != O_constant,
10055 _("expression too complex"));
10056 if (inst.reloc.exp.X_add_number != 0)
10057 {
10058 if (inst.operands[3].shift_kind == SHIFT_ASR)
10059 inst.instruction |= 0x00200000; /* sh bit */
b99bd4ef 10060
c19d1205
ZW
10061 inst.instruction |= (inst.reloc.exp.X_add_number & 0x1c) << 10;
10062 inst.instruction |= (inst.reloc.exp.X_add_number & 0x03) << 6;
10063 }
10064 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 10065 }
b99bd4ef
NC
10066}
10067
10068static void
c19d1205 10069do_t_usat16 (void)
b99bd4ef 10070{
c19d1205
ZW
10071 inst.instruction |= inst.operands[0].reg << 8;
10072 inst.instruction |= inst.operands[1].imm;
10073 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef 10074}
c19d1205 10075
5287ad62
JB
10076/* Neon instruction encoder helpers. */
10077
10078/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 10079
5287ad62
JB
10080/* An "invalid" code for the following tables. */
10081#define N_INV -1u
10082
10083struct neon_tab_entry
b99bd4ef 10084{
5287ad62
JB
10085 unsigned integer;
10086 unsigned float_or_poly;
10087 unsigned scalar_or_imm;
10088};
10089
10090/* Map overloaded Neon opcodes to their respective encodings. */
10091#define NEON_ENC_TAB \
10092 X(vabd, 0x0000700, 0x1200d00, N_INV), \
10093 X(vmax, 0x0000600, 0x0000f00, N_INV), \
10094 X(vmin, 0x0000610, 0x0200f00, N_INV), \
10095 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
10096 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
10097 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
10098 X(vadd, 0x0000800, 0x0000d00, N_INV), \
10099 X(vsub, 0x1000800, 0x0200d00, N_INV), \
10100 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
10101 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
10102 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
10103 /* Register variants of the following two instructions are encoded as
10104 vcge / vcgt with the operands reversed. */ \
10105 X(vclt, 0x0000310, 0x1000e00, 0x1b10200), \
10106 X(vcle, 0x0000300, 0x1200e00, 0x1b10180), \
10107 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
10108 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
10109 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
10110 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
10111 X(vmlal, 0x0800800, N_INV, 0x0800240), \
10112 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
10113 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
10114 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
10115 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
10116 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
10117 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
10118 X(vshl, 0x0000400, N_INV, 0x0800510), \
10119 X(vqshl, 0x0000410, N_INV, 0x0800710), \
10120 X(vand, 0x0000110, N_INV, 0x0800030), \
10121 X(vbic, 0x0100110, N_INV, 0x0800030), \
10122 X(veor, 0x1000110, N_INV, N_INV), \
10123 X(vorn, 0x0300110, N_INV, 0x0800010), \
10124 X(vorr, 0x0200110, N_INV, 0x0800010), \
10125 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
10126 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
10127 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
10128 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
10129 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
10130 X(vst1, 0x0000000, 0x0800000, N_INV), \
10131 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
10132 X(vst2, 0x0000100, 0x0800100, N_INV), \
10133 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
10134 X(vst3, 0x0000200, 0x0800200, N_INV), \
10135 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
10136 X(vst4, 0x0000300, 0x0800300, N_INV), \
10137 X(vmovn, 0x1b20200, N_INV, N_INV), \
10138 X(vtrn, 0x1b20080, N_INV, N_INV), \
10139 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
10140 X(vqmovun, 0x1b20240, N_INV, N_INV), \
10141 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
10142 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
10143 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
10144 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
10145 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
10146 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
10147 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
10148
10149enum neon_opc
10150{
10151#define X(OPC,I,F,S) N_MNEM_##OPC
10152NEON_ENC_TAB
10153#undef X
10154};
b99bd4ef 10155
5287ad62
JB
10156static const struct neon_tab_entry neon_enc_tab[] =
10157{
10158#define X(OPC,I,F,S) { (I), (F), (S) }
10159NEON_ENC_TAB
10160#undef X
10161};
b99bd4ef 10162
5287ad62
JB
10163#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10164#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10165#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10166#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10167#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10168#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
10169#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
10170#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
10171#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
10172#define NEON_ENC_SINGLE(X) \
10173 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
10174#define NEON_ENC_DOUBLE(X) \
10175 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 10176
037e8744
JB
10177/* Define shapes for instruction operands. The following mnemonic characters
10178 are used in this table:
5287ad62 10179
037e8744 10180 F - VFP S<n> register
5287ad62
JB
10181 D - Neon D<n> register
10182 Q - Neon Q<n> register
10183 I - Immediate
10184 S - Scalar
10185 R - ARM register
10186 L - D<n> register list
037e8744
JB
10187
10188 This table is used to generate various data:
10189 - enumerations of the form NS_DDR to be used as arguments to
10190 neon_select_shape.
10191 - a table classifying shapes into single, double, quad, mixed.
10192 - a table used to drive neon_select_shape.
5287ad62 10193*/
b99bd4ef 10194
037e8744
JB
10195#define NEON_SHAPE_DEF \
10196 X(3, (D, D, D), DOUBLE), \
10197 X(3, (Q, Q, Q), QUAD), \
10198 X(3, (D, D, I), DOUBLE), \
10199 X(3, (Q, Q, I), QUAD), \
10200 X(3, (D, D, S), DOUBLE), \
10201 X(3, (Q, Q, S), QUAD), \
10202 X(2, (D, D), DOUBLE), \
10203 X(2, (Q, Q), QUAD), \
10204 X(2, (D, S), DOUBLE), \
10205 X(2, (Q, S), QUAD), \
10206 X(2, (D, R), DOUBLE), \
10207 X(2, (Q, R), QUAD), \
10208 X(2, (D, I), DOUBLE), \
10209 X(2, (Q, I), QUAD), \
10210 X(3, (D, L, D), DOUBLE), \
10211 X(2, (D, Q), MIXED), \
10212 X(2, (Q, D), MIXED), \
10213 X(3, (D, Q, I), MIXED), \
10214 X(3, (Q, D, I), MIXED), \
10215 X(3, (Q, D, D), MIXED), \
10216 X(3, (D, Q, Q), MIXED), \
10217 X(3, (Q, Q, D), MIXED), \
10218 X(3, (Q, D, S), MIXED), \
10219 X(3, (D, Q, S), MIXED), \
10220 X(4, (D, D, D, I), DOUBLE), \
10221 X(4, (Q, Q, Q, I), QUAD), \
10222 X(2, (F, F), SINGLE), \
10223 X(3, (F, F, F), SINGLE), \
10224 X(2, (F, I), SINGLE), \
10225 X(2, (F, D), MIXED), \
10226 X(2, (D, F), MIXED), \
10227 X(3, (F, F, I), MIXED), \
10228 X(4, (R, R, F, F), SINGLE), \
10229 X(4, (F, F, R, R), SINGLE), \
10230 X(3, (D, R, R), DOUBLE), \
10231 X(3, (R, R, D), DOUBLE), \
10232 X(2, (S, R), SINGLE), \
10233 X(2, (R, S), SINGLE), \
10234 X(2, (F, R), SINGLE), \
10235 X(2, (R, F), SINGLE)
10236
10237#define S2(A,B) NS_##A##B
10238#define S3(A,B,C) NS_##A##B##C
10239#define S4(A,B,C,D) NS_##A##B##C##D
10240
10241#define X(N, L, C) S##N L
10242
5287ad62
JB
10243enum neon_shape
10244{
037e8744
JB
10245 NEON_SHAPE_DEF,
10246 NS_NULL
5287ad62 10247};
b99bd4ef 10248
037e8744
JB
10249#undef X
10250#undef S2
10251#undef S3
10252#undef S4
10253
10254enum neon_shape_class
10255{
10256 SC_SINGLE,
10257 SC_DOUBLE,
10258 SC_QUAD,
10259 SC_MIXED
10260};
10261
10262#define X(N, L, C) SC_##C
10263
10264static enum neon_shape_class neon_shape_class[] =
10265{
10266 NEON_SHAPE_DEF
10267};
10268
10269#undef X
10270
10271enum neon_shape_el
10272{
10273 SE_F,
10274 SE_D,
10275 SE_Q,
10276 SE_I,
10277 SE_S,
10278 SE_R,
10279 SE_L
10280};
10281
10282/* Register widths of above. */
10283static unsigned neon_shape_el_size[] =
10284{
10285 32,
10286 64,
10287 128,
10288 0,
10289 32,
10290 32,
10291 0
10292};
10293
10294struct neon_shape_info
10295{
10296 unsigned els;
10297 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
10298};
10299
10300#define S2(A,B) { SE_##A, SE_##B }
10301#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
10302#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
10303
10304#define X(N, L, C) { N, S##N L }
10305
10306static struct neon_shape_info neon_shape_tab[] =
10307{
10308 NEON_SHAPE_DEF
10309};
10310
10311#undef X
10312#undef S2
10313#undef S3
10314#undef S4
10315
5287ad62
JB
10316/* Bit masks used in type checking given instructions.
10317 'N_EQK' means the type must be the same as (or based on in some way) the key
10318 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
10319 set, various other bits can be set as well in order to modify the meaning of
10320 the type constraint. */
10321
10322enum neon_type_mask
10323{
10324 N_S8 = 0x000001,
10325 N_S16 = 0x000002,
10326 N_S32 = 0x000004,
10327 N_S64 = 0x000008,
10328 N_U8 = 0x000010,
10329 N_U16 = 0x000020,
10330 N_U32 = 0x000040,
10331 N_U64 = 0x000080,
10332 N_I8 = 0x000100,
10333 N_I16 = 0x000200,
10334 N_I32 = 0x000400,
10335 N_I64 = 0x000800,
10336 N_8 = 0x001000,
10337 N_16 = 0x002000,
10338 N_32 = 0x004000,
10339 N_64 = 0x008000,
10340 N_P8 = 0x010000,
10341 N_P16 = 0x020000,
10342 N_F32 = 0x040000,
037e8744
JB
10343 N_F64 = 0x080000,
10344 N_KEY = 0x100000, /* key element (main type specifier). */
10345 N_EQK = 0x200000, /* given operand has the same type & size as the key. */
10346 N_VFP = 0x400000, /* VFP mode: operand size must match register width. */
5287ad62
JB
10347 N_DBL = 0x000001, /* if N_EQK, this operand is twice the size. */
10348 N_HLF = 0x000002, /* if N_EQK, this operand is half the size. */
10349 N_SGN = 0x000004, /* if N_EQK, this operand is forced to be signed. */
10350 N_UNS = 0x000008, /* if N_EQK, this operand is forced to be unsigned. */
10351 N_INT = 0x000010, /* if N_EQK, this operand is forced to be integer. */
10352 N_FLT = 0x000020, /* if N_EQK, this operand is forced to be float. */
dcbf9037 10353 N_SIZ = 0x000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 10354 N_UTYP = 0,
037e8744 10355 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
10356};
10357
dcbf9037
JB
10358#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
10359
5287ad62
JB
10360#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
10361#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
10362#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
10363#define N_SUF_32 (N_SU_32 | N_F32)
10364#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
10365#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
10366
10367/* Pass this as the first type argument to neon_check_type to ignore types
10368 altogether. */
10369#define N_IGNORE_TYPE (N_KEY | N_EQK)
10370
037e8744
JB
10371/* Select a "shape" for the current instruction (describing register types or
10372 sizes) from a list of alternatives. Return NS_NULL if the current instruction
10373 doesn't fit. For non-polymorphic shapes, checking is usually done as a
10374 function of operand parsing, so this function doesn't need to be called.
10375 Shapes should be listed in order of decreasing length. */
5287ad62
JB
10376
10377static enum neon_shape
037e8744 10378neon_select_shape (enum neon_shape shape, ...)
5287ad62 10379{
037e8744
JB
10380 va_list ap;
10381 enum neon_shape first_shape = shape;
5287ad62
JB
10382
10383 /* Fix missing optional operands. FIXME: we don't know at this point how
10384 many arguments we should have, so this makes the assumption that we have
10385 > 1. This is true of all current Neon opcodes, I think, but may not be
10386 true in the future. */
10387 if (!inst.operands[1].present)
10388 inst.operands[1] = inst.operands[0];
10389
037e8744 10390 va_start (ap, shape);
5287ad62 10391
037e8744
JB
10392 for (; shape != NS_NULL; shape = va_arg (ap, int))
10393 {
10394 unsigned j;
10395 int matches = 1;
10396
10397 for (j = 0; j < neon_shape_tab[shape].els; j++)
10398 {
10399 if (!inst.operands[j].present)
10400 {
10401 matches = 0;
10402 break;
10403 }
10404
10405 switch (neon_shape_tab[shape].el[j])
10406 {
10407 case SE_F:
10408 if (!(inst.operands[j].isreg
10409 && inst.operands[j].isvec
10410 && inst.operands[j].issingle
10411 && !inst.operands[j].isquad))
10412 matches = 0;
10413 break;
10414
10415 case SE_D:
10416 if (!(inst.operands[j].isreg
10417 && inst.operands[j].isvec
10418 && !inst.operands[j].isquad
10419 && !inst.operands[j].issingle))
10420 matches = 0;
10421 break;
10422
10423 case SE_R:
10424 if (!(inst.operands[j].isreg
10425 && !inst.operands[j].isvec))
10426 matches = 0;
10427 break;
10428
10429 case SE_Q:
10430 if (!(inst.operands[j].isreg
10431 && inst.operands[j].isvec
10432 && inst.operands[j].isquad
10433 && !inst.operands[j].issingle))
10434 matches = 0;
10435 break;
10436
10437 case SE_I:
10438 if (!(!inst.operands[j].isreg
10439 && !inst.operands[j].isscalar))
10440 matches = 0;
10441 break;
10442
10443 case SE_S:
10444 if (!(!inst.operands[j].isreg
10445 && inst.operands[j].isscalar))
10446 matches = 0;
10447 break;
10448
10449 case SE_L:
10450 break;
10451 }
10452 }
10453 if (matches)
5287ad62 10454 break;
037e8744 10455 }
5287ad62 10456
037e8744 10457 va_end (ap);
5287ad62 10458
037e8744
JB
10459 if (shape == NS_NULL && first_shape != NS_NULL)
10460 first_error (_("invalid instruction shape"));
5287ad62 10461
037e8744
JB
10462 return shape;
10463}
5287ad62 10464
037e8744
JB
10465/* True if SHAPE is predominantly a quadword operation (most of the time, this
10466 means the Q bit should be set). */
10467
10468static int
10469neon_quad (enum neon_shape shape)
10470{
10471 return neon_shape_class[shape] == SC_QUAD;
5287ad62 10472}
037e8744 10473
5287ad62
JB
10474static void
10475neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
10476 unsigned *g_size)
10477{
10478 /* Allow modification to be made to types which are constrained to be
10479 based on the key element, based on bits set alongside N_EQK. */
10480 if ((typebits & N_EQK) != 0)
10481 {
10482 if ((typebits & N_HLF) != 0)
10483 *g_size /= 2;
10484 else if ((typebits & N_DBL) != 0)
10485 *g_size *= 2;
10486 if ((typebits & N_SGN) != 0)
10487 *g_type = NT_signed;
10488 else if ((typebits & N_UNS) != 0)
10489 *g_type = NT_unsigned;
10490 else if ((typebits & N_INT) != 0)
10491 *g_type = NT_integer;
10492 else if ((typebits & N_FLT) != 0)
10493 *g_type = NT_float;
dcbf9037
JB
10494 else if ((typebits & N_SIZ) != 0)
10495 *g_type = NT_untyped;
5287ad62
JB
10496 }
10497}
10498
10499/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
10500 operand type, i.e. the single type specified in a Neon instruction when it
10501 is the only one given. */
10502
10503static struct neon_type_el
10504neon_type_promote (struct neon_type_el *key, unsigned thisarg)
10505{
10506 struct neon_type_el dest = *key;
10507
10508 assert ((thisarg & N_EQK) != 0);
10509
10510 neon_modify_type_size (thisarg, &dest.type, &dest.size);
10511
10512 return dest;
10513}
10514
10515/* Convert Neon type and size into compact bitmask representation. */
10516
10517static enum neon_type_mask
10518type_chk_of_el_type (enum neon_el_type type, unsigned size)
10519{
10520 switch (type)
10521 {
10522 case NT_untyped:
10523 switch (size)
10524 {
10525 case 8: return N_8;
10526 case 16: return N_16;
10527 case 32: return N_32;
10528 case 64: return N_64;
10529 default: ;
10530 }
10531 break;
10532
10533 case NT_integer:
10534 switch (size)
10535 {
10536 case 8: return N_I8;
10537 case 16: return N_I16;
10538 case 32: return N_I32;
10539 case 64: return N_I64;
10540 default: ;
10541 }
10542 break;
10543
10544 case NT_float:
037e8744
JB
10545 switch (size)
10546 {
10547 case 32: return N_F32;
10548 case 64: return N_F64;
10549 default: ;
10550 }
5287ad62
JB
10551 break;
10552
10553 case NT_poly:
10554 switch (size)
10555 {
10556 case 8: return N_P8;
10557 case 16: return N_P16;
10558 default: ;
10559 }
10560 break;
10561
10562 case NT_signed:
10563 switch (size)
10564 {
10565 case 8: return N_S8;
10566 case 16: return N_S16;
10567 case 32: return N_S32;
10568 case 64: return N_S64;
10569 default: ;
10570 }
10571 break;
10572
10573 case NT_unsigned:
10574 switch (size)
10575 {
10576 case 8: return N_U8;
10577 case 16: return N_U16;
10578 case 32: return N_U32;
10579 case 64: return N_U64;
10580 default: ;
10581 }
10582 break;
10583
10584 default: ;
10585 }
10586
10587 return N_UTYP;
10588}
10589
10590/* Convert compact Neon bitmask type representation to a type and size. Only
10591 handles the case where a single bit is set in the mask. */
10592
dcbf9037 10593static int
5287ad62
JB
10594el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
10595 enum neon_type_mask mask)
10596{
dcbf9037
JB
10597 if ((mask & N_EQK) != 0)
10598 return FAIL;
10599
5287ad62
JB
10600 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
10601 *size = 8;
dcbf9037 10602 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 10603 *size = 16;
dcbf9037 10604 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 10605 *size = 32;
037e8744 10606 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 10607 *size = 64;
dcbf9037
JB
10608 else
10609 return FAIL;
10610
5287ad62
JB
10611 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
10612 *type = NT_signed;
dcbf9037 10613 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 10614 *type = NT_unsigned;
dcbf9037 10615 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 10616 *type = NT_integer;
dcbf9037 10617 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 10618 *type = NT_untyped;
dcbf9037 10619 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 10620 *type = NT_poly;
037e8744 10621 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 10622 *type = NT_float;
dcbf9037
JB
10623 else
10624 return FAIL;
10625
10626 return SUCCESS;
5287ad62
JB
10627}
10628
10629/* Modify a bitmask of allowed types. This is only needed for type
10630 relaxation. */
10631
10632static unsigned
10633modify_types_allowed (unsigned allowed, unsigned mods)
10634{
10635 unsigned size;
10636 enum neon_el_type type;
10637 unsigned destmask;
10638 int i;
10639
10640 destmask = 0;
10641
10642 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
10643 {
dcbf9037
JB
10644 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
10645 {
10646 neon_modify_type_size (mods, &type, &size);
10647 destmask |= type_chk_of_el_type (type, size);
10648 }
5287ad62
JB
10649 }
10650
10651 return destmask;
10652}
10653
10654/* Check type and return type classification.
10655 The manual states (paraphrase): If one datatype is given, it indicates the
10656 type given in:
10657 - the second operand, if there is one
10658 - the operand, if there is no second operand
10659 - the result, if there are no operands.
10660 This isn't quite good enough though, so we use a concept of a "key" datatype
10661 which is set on a per-instruction basis, which is the one which matters when
10662 only one data type is written.
10663 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 10664 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
10665
10666static struct neon_type_el
10667neon_check_type (unsigned els, enum neon_shape ns, ...)
10668{
10669 va_list ap;
10670 unsigned i, pass, key_el = 0;
10671 unsigned types[NEON_MAX_TYPE_ELS];
10672 enum neon_el_type k_type = NT_invtype;
10673 unsigned k_size = -1u;
10674 struct neon_type_el badtype = {NT_invtype, -1};
10675 unsigned key_allowed = 0;
10676
10677 /* Optional registers in Neon instructions are always (not) in operand 1.
10678 Fill in the missing operand here, if it was omitted. */
10679 if (els > 1 && !inst.operands[1].present)
10680 inst.operands[1] = inst.operands[0];
10681
10682 /* Suck up all the varargs. */
10683 va_start (ap, ns);
10684 for (i = 0; i < els; i++)
10685 {
10686 unsigned thisarg = va_arg (ap, unsigned);
10687 if (thisarg == N_IGNORE_TYPE)
10688 {
10689 va_end (ap);
10690 return badtype;
10691 }
10692 types[i] = thisarg;
10693 if ((thisarg & N_KEY) != 0)
10694 key_el = i;
10695 }
10696 va_end (ap);
10697
dcbf9037
JB
10698 if (inst.vectype.elems > 0)
10699 for (i = 0; i < els; i++)
10700 if (inst.operands[i].vectype.type != NT_invtype)
10701 {
10702 first_error (_("types specified in both the mnemonic and operands"));
10703 return badtype;
10704 }
10705
5287ad62
JB
10706 /* Duplicate inst.vectype elements here as necessary.
10707 FIXME: No idea if this is exactly the same as the ARM assembler,
10708 particularly when an insn takes one register and one non-register
10709 operand. */
10710 if (inst.vectype.elems == 1 && els > 1)
10711 {
10712 unsigned j;
10713 inst.vectype.elems = els;
10714 inst.vectype.el[key_el] = inst.vectype.el[0];
10715 for (j = 0; j < els; j++)
dcbf9037
JB
10716 if (j != key_el)
10717 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10718 types[j]);
10719 }
10720 else if (inst.vectype.elems == 0 && els > 0)
10721 {
10722 unsigned j;
10723 /* No types were given after the mnemonic, so look for types specified
10724 after each operand. We allow some flexibility here; as long as the
10725 "key" operand has a type, we can infer the others. */
10726 for (j = 0; j < els; j++)
10727 if (inst.operands[j].vectype.type != NT_invtype)
10728 inst.vectype.el[j] = inst.operands[j].vectype;
10729
10730 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 10731 {
dcbf9037
JB
10732 for (j = 0; j < els; j++)
10733 if (inst.operands[j].vectype.type == NT_invtype)
10734 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
10735 types[j]);
10736 }
10737 else
10738 {
10739 first_error (_("operand types can't be inferred"));
10740 return badtype;
5287ad62
JB
10741 }
10742 }
10743 else if (inst.vectype.elems != els)
10744 {
dcbf9037 10745 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
10746 return badtype;
10747 }
10748
10749 for (pass = 0; pass < 2; pass++)
10750 {
10751 for (i = 0; i < els; i++)
10752 {
10753 unsigned thisarg = types[i];
10754 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
10755 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
10756 enum neon_el_type g_type = inst.vectype.el[i].type;
10757 unsigned g_size = inst.vectype.el[i].size;
10758
10759 /* Decay more-specific signed & unsigned types to sign-insensitive
10760 integer types if sign-specific variants are unavailable. */
10761 if ((g_type == NT_signed || g_type == NT_unsigned)
10762 && (types_allowed & N_SU_ALL) == 0)
10763 g_type = NT_integer;
10764
10765 /* If only untyped args are allowed, decay any more specific types to
10766 them. Some instructions only care about signs for some element
10767 sizes, so handle that properly. */
10768 if ((g_size == 8 && (types_allowed & N_8) != 0)
10769 || (g_size == 16 && (types_allowed & N_16) != 0)
10770 || (g_size == 32 && (types_allowed & N_32) != 0)
10771 || (g_size == 64 && (types_allowed & N_64) != 0))
10772 g_type = NT_untyped;
10773
10774 if (pass == 0)
10775 {
10776 if ((thisarg & N_KEY) != 0)
10777 {
10778 k_type = g_type;
10779 k_size = g_size;
10780 key_allowed = thisarg & ~N_KEY;
10781 }
10782 }
10783 else
10784 {
037e8744
JB
10785 if ((thisarg & N_VFP) != 0)
10786 {
10787 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
10788 unsigned regwidth = neon_shape_el_size[regshape], match;
10789
10790 /* In VFP mode, operands must match register widths. If we
10791 have a key operand, use its width, else use the width of
10792 the current operand. */
10793 if (k_size != -1u)
10794 match = k_size;
10795 else
10796 match = g_size;
10797
10798 if (regwidth != match)
10799 {
10800 first_error (_("operand size must match register width"));
10801 return badtype;
10802 }
10803 }
10804
5287ad62
JB
10805 if ((thisarg & N_EQK) == 0)
10806 {
10807 unsigned given_type = type_chk_of_el_type (g_type, g_size);
10808
10809 if ((given_type & types_allowed) == 0)
10810 {
dcbf9037 10811 first_error (_("bad type in Neon instruction"));
5287ad62
JB
10812 return badtype;
10813 }
10814 }
10815 else
10816 {
10817 enum neon_el_type mod_k_type = k_type;
10818 unsigned mod_k_size = k_size;
10819 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
10820 if (g_type != mod_k_type || g_size != mod_k_size)
10821 {
dcbf9037 10822 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
10823 return badtype;
10824 }
10825 }
10826 }
10827 }
10828 }
10829
10830 return inst.vectype.el[key_el];
10831}
10832
037e8744 10833/* Neon-style VFP instruction forwarding. */
5287ad62 10834
037e8744
JB
10835/* Thumb VFP instructions have 0xE in the condition field. */
10836
10837static void
10838do_vfp_cond_or_thumb (void)
5287ad62
JB
10839{
10840 if (thumb_mode)
037e8744 10841 inst.instruction |= 0xe0000000;
5287ad62 10842 else
037e8744 10843 inst.instruction |= inst.cond << 28;
5287ad62
JB
10844}
10845
037e8744
JB
10846/* Look up and encode a simple mnemonic, for use as a helper function for the
10847 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
10848 etc. It is assumed that operand parsing has already been done, and that the
10849 operands are in the form expected by the given opcode (this isn't necessarily
10850 the same as the form in which they were parsed, hence some massaging must
10851 take place before this function is called).
10852 Checks current arch version against that in the looked-up opcode. */
5287ad62 10853
037e8744
JB
10854static void
10855do_vfp_nsyn_opcode (const char *opname)
5287ad62 10856{
037e8744
JB
10857 const struct asm_opcode *opcode;
10858
10859 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 10860
037e8744
JB
10861 if (!opcode)
10862 abort ();
5287ad62 10863
037e8744
JB
10864 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
10865 thumb_mode ? *opcode->tvariant : *opcode->avariant),
10866 _(BAD_FPU));
5287ad62 10867
037e8744
JB
10868 if (thumb_mode)
10869 {
10870 inst.instruction = opcode->tvalue;
10871 opcode->tencode ();
10872 }
10873 else
10874 {
10875 inst.instruction = (inst.cond << 28) | opcode->avalue;
10876 opcode->aencode ();
10877 }
10878}
5287ad62
JB
10879
10880static void
037e8744 10881do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 10882{
037e8744
JB
10883 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
10884
10885 if (rs == NS_FFF)
10886 {
10887 if (is_add)
10888 do_vfp_nsyn_opcode ("fadds");
10889 else
10890 do_vfp_nsyn_opcode ("fsubs");
10891 }
10892 else
10893 {
10894 if (is_add)
10895 do_vfp_nsyn_opcode ("faddd");
10896 else
10897 do_vfp_nsyn_opcode ("fsubd");
10898 }
10899}
10900
10901/* Check operand types to see if this is a VFP instruction, and if so call
10902 PFN (). */
10903
10904static int
10905try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
10906{
10907 enum neon_shape rs;
10908 struct neon_type_el et;
10909
10910 switch (args)
10911 {
10912 case 2:
10913 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
10914 et = neon_check_type (2, rs,
10915 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10916 break;
10917
10918 case 3:
10919 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
10920 et = neon_check_type (3, rs,
10921 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
10922 break;
10923
10924 default:
10925 abort ();
10926 }
10927
10928 if (et.type != NT_invtype)
10929 {
10930 pfn (rs);
10931 return SUCCESS;
10932 }
10933 else
10934 inst.error = NULL;
10935
10936 return FAIL;
10937}
10938
10939static void
10940do_vfp_nsyn_mla_mls (enum neon_shape rs)
10941{
10942 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
10943
10944 if (rs == NS_FFF)
10945 {
10946 if (is_mla)
10947 do_vfp_nsyn_opcode ("fmacs");
10948 else
10949 do_vfp_nsyn_opcode ("fmscs");
10950 }
10951 else
10952 {
10953 if (is_mla)
10954 do_vfp_nsyn_opcode ("fmacd");
10955 else
10956 do_vfp_nsyn_opcode ("fmscd");
10957 }
10958}
10959
10960static void
10961do_vfp_nsyn_mul (enum neon_shape rs)
10962{
10963 if (rs == NS_FFF)
10964 do_vfp_nsyn_opcode ("fmuls");
10965 else
10966 do_vfp_nsyn_opcode ("fmuld");
10967}
10968
10969static void
10970do_vfp_nsyn_abs_neg (enum neon_shape rs)
10971{
10972 int is_neg = (inst.instruction & 0x80) != 0;
10973 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
10974
10975 if (rs == NS_FF)
10976 {
10977 if (is_neg)
10978 do_vfp_nsyn_opcode ("fnegs");
10979 else
10980 do_vfp_nsyn_opcode ("fabss");
10981 }
10982 else
10983 {
10984 if (is_neg)
10985 do_vfp_nsyn_opcode ("fnegd");
10986 else
10987 do_vfp_nsyn_opcode ("fabsd");
10988 }
10989}
10990
10991/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
10992 insns belong to Neon, and are handled elsewhere. */
10993
10994static void
10995do_vfp_nsyn_ldm_stm (int is_dbmode)
10996{
10997 int is_ldm = (inst.instruction & (1 << 20)) != 0;
10998 if (is_ldm)
10999 {
11000 if (is_dbmode)
11001 do_vfp_nsyn_opcode ("fldmdbs");
11002 else
11003 do_vfp_nsyn_opcode ("fldmias");
11004 }
11005 else
11006 {
11007 if (is_dbmode)
11008 do_vfp_nsyn_opcode ("fstmdbs");
11009 else
11010 do_vfp_nsyn_opcode ("fstmias");
11011 }
11012}
11013
037e8744
JB
11014static void
11015do_vfp_nsyn_sqrt (void)
11016{
11017 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11018 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11019
11020 if (rs == NS_FF)
11021 do_vfp_nsyn_opcode ("fsqrts");
11022 else
11023 do_vfp_nsyn_opcode ("fsqrtd");
11024}
11025
11026static void
11027do_vfp_nsyn_div (void)
11028{
11029 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11030 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11031 N_F32 | N_F64 | N_KEY | N_VFP);
11032
11033 if (rs == NS_FFF)
11034 do_vfp_nsyn_opcode ("fdivs");
11035 else
11036 do_vfp_nsyn_opcode ("fdivd");
11037}
11038
11039static void
11040do_vfp_nsyn_nmul (void)
11041{
11042 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11043 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11044 N_F32 | N_F64 | N_KEY | N_VFP);
11045
11046 if (rs == NS_FFF)
11047 {
11048 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11049 do_vfp_sp_dyadic ();
11050 }
11051 else
11052 {
11053 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11054 do_vfp_dp_rd_rn_rm ();
11055 }
11056 do_vfp_cond_or_thumb ();
11057}
11058
11059static void
11060do_vfp_nsyn_cmp (void)
11061{
11062 if (inst.operands[1].isreg)
11063 {
11064 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11065 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11066
11067 if (rs == NS_FF)
11068 {
11069 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11070 do_vfp_sp_monadic ();
11071 }
11072 else
11073 {
11074 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11075 do_vfp_dp_rd_rm ();
11076 }
11077 }
11078 else
11079 {
11080 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
11081 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
11082
11083 switch (inst.instruction & 0x0fffffff)
11084 {
11085 case N_MNEM_vcmp:
11086 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
11087 break;
11088 case N_MNEM_vcmpe:
11089 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
11090 break;
11091 default:
11092 abort ();
11093 }
11094
11095 if (rs == NS_FI)
11096 {
11097 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11098 do_vfp_sp_compare_z ();
11099 }
11100 else
11101 {
11102 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11103 do_vfp_dp_rd ();
11104 }
11105 }
11106 do_vfp_cond_or_thumb ();
11107}
11108
11109static void
11110nsyn_insert_sp (void)
11111{
11112 inst.operands[1] = inst.operands[0];
11113 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
11114 inst.operands[0].reg = 13;
11115 inst.operands[0].isreg = 1;
11116 inst.operands[0].writeback = 1;
11117 inst.operands[0].present = 1;
11118}
11119
11120static void
11121do_vfp_nsyn_push (void)
11122{
11123 nsyn_insert_sp ();
11124 if (inst.operands[1].issingle)
11125 do_vfp_nsyn_opcode ("fstmdbs");
11126 else
11127 do_vfp_nsyn_opcode ("fstmdbd");
11128}
11129
11130static void
11131do_vfp_nsyn_pop (void)
11132{
11133 nsyn_insert_sp ();
11134 if (inst.operands[1].issingle)
11135 do_vfp_nsyn_opcode ("fldmdbs");
11136 else
11137 do_vfp_nsyn_opcode ("fldmdbd");
11138}
11139
11140/* Fix up Neon data-processing instructions, ORing in the correct bits for
11141 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
11142
11143static unsigned
11144neon_dp_fixup (unsigned i)
11145{
11146 if (thumb_mode)
11147 {
11148 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
11149 if (i & (1 << 24))
11150 i |= 1 << 28;
11151
11152 i &= ~(1 << 24);
11153
11154 i |= 0xef000000;
11155 }
11156 else
11157 i |= 0xf2000000;
11158
11159 return i;
11160}
11161
11162/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
11163 (0, 1, 2, 3). */
11164
11165static unsigned
11166neon_logbits (unsigned x)
11167{
11168 return ffs (x) - 4;
11169}
11170
11171#define LOW4(R) ((R) & 0xf)
11172#define HI1(R) (((R) >> 4) & 1)
11173
11174/* Encode insns with bit pattern:
11175
11176 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
11177 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
11178
11179 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
11180 different meaning for some instruction. */
11181
11182static void
11183neon_three_same (int isquad, int ubit, int size)
11184{
11185 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11186 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11187 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11188 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11189 inst.instruction |= LOW4 (inst.operands[2].reg);
11190 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
11191 inst.instruction |= (isquad != 0) << 6;
11192 inst.instruction |= (ubit != 0) << 24;
11193 if (size != -1)
11194 inst.instruction |= neon_logbits (size) << 20;
11195
11196 inst.instruction = neon_dp_fixup (inst.instruction);
11197}
11198
11199/* Encode instructions of the form:
11200
11201 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
11202 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
11203
11204 Don't write size if SIZE == -1. */
11205
11206static void
11207neon_two_same (int qbit, int ubit, int size)
11208{
11209 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11210 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11211 inst.instruction |= LOW4 (inst.operands[1].reg);
11212 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11213 inst.instruction |= (qbit != 0) << 6;
11214 inst.instruction |= (ubit != 0) << 24;
11215
11216 if (size != -1)
11217 inst.instruction |= neon_logbits (size) << 18;
11218
11219 inst.instruction = neon_dp_fixup (inst.instruction);
11220}
11221
11222/* Neon instruction encoders, in approximate order of appearance. */
11223
11224static void
11225do_neon_dyadic_i_su (void)
11226{
037e8744 11227 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11228 struct neon_type_el et = neon_check_type (3, rs,
11229 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 11230 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11231}
11232
11233static void
11234do_neon_dyadic_i64_su (void)
11235{
037e8744 11236 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11237 struct neon_type_el et = neon_check_type (3, rs,
11238 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 11239 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11240}
11241
11242static void
11243neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
11244 unsigned immbits)
11245{
11246 unsigned size = et.size >> 3;
11247 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11248 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11249 inst.instruction |= LOW4 (inst.operands[1].reg);
11250 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
11251 inst.instruction |= (isquad != 0) << 6;
11252 inst.instruction |= immbits << 16;
11253 inst.instruction |= (size >> 3) << 7;
11254 inst.instruction |= (size & 0x7) << 19;
11255 if (write_ubit)
11256 inst.instruction |= (uval != 0) << 24;
11257
11258 inst.instruction = neon_dp_fixup (inst.instruction);
11259}
11260
11261static void
11262do_neon_shl_imm (void)
11263{
11264 if (!inst.operands[2].isreg)
11265 {
037e8744 11266 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11267 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
11268 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11269 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
11270 }
11271 else
11272 {
037e8744 11273 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11274 struct neon_type_el et = neon_check_type (3, rs,
11275 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11276 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11277 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11278 }
11279}
11280
11281static void
11282do_neon_qshl_imm (void)
11283{
11284 if (!inst.operands[2].isreg)
11285 {
037e8744 11286 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11287 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
11288 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 11289 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
11290 inst.operands[2].imm);
11291 }
11292 else
11293 {
037e8744 11294 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11295 struct neon_type_el et = neon_check_type (3, rs,
11296 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
11297 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11298 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
11299 }
11300}
11301
11302static int
11303neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
11304{
11305 /* Handle .I8 and .I64 as pseudo-instructions. */
11306 switch (size)
11307 {
11308 case 8:
11309 /* Unfortunately, this will make everything apart from zero out-of-range.
11310 FIXME is this the intended semantics? There doesn't seem much point in
11311 accepting .I8 if so. */
11312 immediate |= immediate << 8;
11313 size = 16;
11314 break;
11315 case 64:
11316 /* Similarly, anything other than zero will be replicated in bits [63:32],
11317 which probably isn't want we want if we specified .I64. */
11318 if (immediate != 0)
11319 goto bad_immediate;
11320 size = 32;
11321 break;
11322 default: ;
11323 }
11324
11325 if (immediate == (immediate & 0x000000ff))
11326 {
11327 *immbits = immediate;
11328 return (size == 16) ? 0x9 : 0x1;
11329 }
11330 else if (immediate == (immediate & 0x0000ff00))
11331 {
11332 *immbits = immediate >> 8;
11333 return (size == 16) ? 0xb : 0x3;
11334 }
11335 else if (immediate == (immediate & 0x00ff0000))
11336 {
11337 *immbits = immediate >> 16;
11338 return 0x5;
11339 }
11340 else if (immediate == (immediate & 0xff000000))
11341 {
11342 *immbits = immediate >> 24;
11343 return 0x7;
11344 }
11345
11346 bad_immediate:
dcbf9037 11347 first_error (_("immediate value out of range"));
5287ad62
JB
11348 return FAIL;
11349}
11350
11351/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
11352 A, B, C, D. */
11353
11354static int
11355neon_bits_same_in_bytes (unsigned imm)
11356{
11357 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
11358 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
11359 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
11360 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
11361}
11362
11363/* For immediate of above form, return 0bABCD. */
11364
11365static unsigned
11366neon_squash_bits (unsigned imm)
11367{
11368 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
11369 | ((imm & 0x01000000) >> 21);
11370}
11371
136da414 11372/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
11373
11374static unsigned
11375neon_qfloat_bits (unsigned imm)
11376{
136da414 11377 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
11378}
11379
11380/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
11381 the instruction. *OP is passed as the initial value of the op field, and
11382 may be set to a different value depending on the constant (i.e.
11383 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
11384 MVN). */
11385
11386static int
11387neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, unsigned *immbits,
136da414 11388 int *op, int size, enum neon_el_type type)
5287ad62 11389{
136da414
JB
11390 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
11391 {
11392 if (size != 32 || *op == 1)
11393 return FAIL;
11394 *immbits = neon_qfloat_bits (immlo);
11395 return 0xf;
11396 }
11397 else if (size == 64 && neon_bits_same_in_bytes (immhi)
5287ad62
JB
11398 && neon_bits_same_in_bytes (immlo))
11399 {
11400 /* Check this one first so we don't have to bother with immhi in later
11401 tests. */
11402 if (*op == 1)
11403 return FAIL;
11404 *immbits = (neon_squash_bits (immhi) << 4) | neon_squash_bits (immlo);
11405 *op = 1;
11406 return 0xe;
11407 }
11408 else if (immhi != 0)
11409 return FAIL;
11410 else if (immlo == (immlo & 0x000000ff))
11411 {
11412 /* 64-bit case was already handled. Don't allow MVN with 8-bit
11413 immediate. */
11414 if ((size != 8 && size != 16 && size != 32)
11415 || (size == 8 && *op == 1))
11416 return FAIL;
11417 *immbits = immlo;
11418 return (size == 8) ? 0xe : (size == 16) ? 0x8 : 0x0;
11419 }
11420 else if (immlo == (immlo & 0x0000ff00))
11421 {
11422 if (size != 16 && size != 32)
11423 return FAIL;
11424 *immbits = immlo >> 8;
11425 return (size == 16) ? 0xa : 0x2;
11426 }
11427 else if (immlo == (immlo & 0x00ff0000))
11428 {
11429 if (size != 32)
11430 return FAIL;
11431 *immbits = immlo >> 16;
11432 return 0x4;
11433 }
11434 else if (immlo == (immlo & 0xff000000))
11435 {
11436 if (size != 32)
11437 return FAIL;
11438 *immbits = immlo >> 24;
11439 return 0x6;
11440 }
11441 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
11442 {
11443 if (size != 32)
11444 return FAIL;
11445 *immbits = (immlo >> 8) & 0xff;
11446 return 0xc;
11447 }
11448 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
11449 {
11450 if (size != 32)
11451 return FAIL;
11452 *immbits = (immlo >> 16) & 0xff;
11453 return 0xd;
11454 }
5287ad62
JB
11455
11456 return FAIL;
11457}
11458
11459/* Write immediate bits [7:0] to the following locations:
11460
11461 |28/24|23 19|18 16|15 4|3 0|
11462 | 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|
11463
11464 This function is used by VMOV/VMVN/VORR/VBIC. */
11465
11466static void
11467neon_write_immbits (unsigned immbits)
11468{
11469 inst.instruction |= immbits & 0xf;
11470 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
11471 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
11472}
11473
11474/* Invert low-order SIZE bits of XHI:XLO. */
11475
11476static void
11477neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
11478{
11479 unsigned immlo = xlo ? *xlo : 0;
11480 unsigned immhi = xhi ? *xhi : 0;
11481
11482 switch (size)
11483 {
11484 case 8:
11485 immlo = (~immlo) & 0xff;
11486 break;
11487
11488 case 16:
11489 immlo = (~immlo) & 0xffff;
11490 break;
11491
11492 case 64:
11493 immhi = (~immhi) & 0xffffffff;
11494 /* fall through. */
11495
11496 case 32:
11497 immlo = (~immlo) & 0xffffffff;
11498 break;
11499
11500 default:
11501 abort ();
11502 }
11503
11504 if (xlo)
11505 *xlo = immlo;
11506
11507 if (xhi)
11508 *xhi = immhi;
11509}
11510
11511static void
11512do_neon_logic (void)
11513{
11514 if (inst.operands[2].present && inst.operands[2].isreg)
11515 {
037e8744 11516 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11517 neon_check_type (3, rs, N_IGNORE_TYPE);
11518 /* U bit and size field were set as part of the bitmask. */
11519 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11520 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11521 }
11522 else
11523 {
037e8744
JB
11524 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
11525 struct neon_type_el et = neon_check_type (2, rs,
11526 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
11527 enum neon_opc opcode = inst.instruction & 0x0fffffff;
11528 unsigned immbits;
11529 int cmode;
11530
11531 if (et.type == NT_invtype)
11532 return;
11533
11534 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11535
11536 switch (opcode)
11537 {
11538 case N_MNEM_vbic:
11539 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11540 et.size);
11541 break;
11542
11543 case N_MNEM_vorr:
11544 cmode = neon_cmode_for_logic_imm (inst.operands[1].imm, &immbits,
11545 et.size);
11546 break;
11547
11548 case N_MNEM_vand:
11549 /* Pseudo-instruction for VBIC. */
11550 immbits = inst.operands[1].imm;
11551 neon_invert_size (&immbits, 0, et.size);
11552 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11553 break;
11554
11555 case N_MNEM_vorn:
11556 /* Pseudo-instruction for VORR. */
11557 immbits = inst.operands[1].imm;
11558 neon_invert_size (&immbits, 0, et.size);
11559 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
11560 break;
11561
11562 default:
11563 abort ();
11564 }
11565
11566 if (cmode == FAIL)
11567 return;
11568
037e8744 11569 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11570 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11571 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11572 inst.instruction |= cmode << 8;
11573 neon_write_immbits (immbits);
11574
11575 inst.instruction = neon_dp_fixup (inst.instruction);
11576 }
11577}
11578
11579static void
11580do_neon_bitfield (void)
11581{
037e8744 11582 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 11583 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 11584 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11585}
11586
11587static void
dcbf9037
JB
11588neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
11589 unsigned destbits)
5287ad62 11590{
037e8744 11591 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
11592 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
11593 types | N_KEY);
5287ad62
JB
11594 if (et.type == NT_float)
11595 {
11596 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 11597 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11598 }
11599 else
11600 {
11601 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 11602 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
11603 }
11604}
11605
11606static void
11607do_neon_dyadic_if_su (void)
11608{
dcbf9037 11609 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
11610}
11611
11612static void
11613do_neon_dyadic_if_su_d (void)
11614{
11615 /* This version only allow D registers, but that constraint is enforced during
11616 operand parsing so we don't need to do anything extra here. */
dcbf9037 11617 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
11618}
11619
11620static void
11621do_neon_dyadic_if_i (void)
11622{
dcbf9037 11623 neon_dyadic_misc (NT_unsigned, N_IF_32, 0);
5287ad62
JB
11624}
11625
11626static void
11627do_neon_dyadic_if_i_d (void)
11628{
dcbf9037 11629 neon_dyadic_misc (NT_unsigned, N_IF_32, 0);
5287ad62
JB
11630}
11631
037e8744
JB
11632enum vfp_or_neon_is_neon_bits
11633{
11634 NEON_CHECK_CC = 1,
11635 NEON_CHECK_ARCH = 2
11636};
11637
11638/* Call this function if an instruction which may have belonged to the VFP or
11639 Neon instruction sets, but turned out to be a Neon instruction (due to the
11640 operand types involved, etc.). We have to check and/or fix-up a couple of
11641 things:
11642
11643 - Make sure the user hasn't attempted to make a Neon instruction
11644 conditional.
11645 - Alter the value in the condition code field if necessary.
11646 - Make sure that the arch supports Neon instructions.
11647
11648 Which of these operations take place depends on bits from enum
11649 vfp_or_neon_is_neon_bits.
11650
11651 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
11652 current instruction's condition is COND_ALWAYS, the condition field is
11653 changed to inst.uncond_value. This is necessary because instructions shared
11654 between VFP and Neon may be conditional for the VFP variants only, and the
11655 unconditional Neon version must have, e.g., 0xF in the condition field. */
11656
11657static int
11658vfp_or_neon_is_neon (unsigned check)
11659{
11660 /* Conditions are always legal in Thumb mode (IT blocks). */
11661 if (!thumb_mode && (check & NEON_CHECK_CC))
11662 {
11663 if (inst.cond != COND_ALWAYS)
11664 {
11665 first_error (_(BAD_COND));
11666 return FAIL;
11667 }
11668 if (inst.uncond_value != -1)
11669 inst.instruction |= inst.uncond_value << 28;
11670 }
11671
11672 if ((check & NEON_CHECK_ARCH)
11673 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
11674 {
11675 first_error (_(BAD_FPU));
11676 return FAIL;
11677 }
11678
11679 return SUCCESS;
11680}
11681
5287ad62
JB
11682static void
11683do_neon_addsub_if_i (void)
11684{
037e8744
JB
11685 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
11686 return;
11687
11688 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11689 return;
11690
5287ad62
JB
11691 /* The "untyped" case can't happen. Do this to stop the "U" bit being
11692 affected if we specify unsigned args. */
dcbf9037 11693 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
11694}
11695
11696/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
11697 result to be:
11698 V<op> A,B (A is operand 0, B is operand 2)
11699 to mean:
11700 V<op> A,B,A
11701 not:
11702 V<op> A,B,B
11703 so handle that case specially. */
11704
11705static void
11706neon_exchange_operands (void)
11707{
11708 void *scratch = alloca (sizeof (inst.operands[0]));
11709 if (inst.operands[1].present)
11710 {
11711 /* Swap operands[1] and operands[2]. */
11712 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
11713 inst.operands[1] = inst.operands[2];
11714 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
11715 }
11716 else
11717 {
11718 inst.operands[1] = inst.operands[2];
11719 inst.operands[2] = inst.operands[0];
11720 }
11721}
11722
11723static void
11724neon_compare (unsigned regtypes, unsigned immtypes, int invert)
11725{
11726 if (inst.operands[2].isreg)
11727 {
11728 if (invert)
11729 neon_exchange_operands ();
dcbf9037 11730 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
11731 }
11732 else
11733 {
037e8744 11734 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
11735 struct neon_type_el et = neon_check_type (2, rs,
11736 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
11737
11738 inst.instruction = NEON_ENC_IMMED (inst.instruction);
11739 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11740 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11741 inst.instruction |= LOW4 (inst.operands[1].reg);
11742 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 11743 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11744 inst.instruction |= (et.type == NT_float) << 10;
11745 inst.instruction |= neon_logbits (et.size) << 18;
11746
11747 inst.instruction = neon_dp_fixup (inst.instruction);
11748 }
11749}
11750
11751static void
11752do_neon_cmp (void)
11753{
11754 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
11755}
11756
11757static void
11758do_neon_cmp_inv (void)
11759{
11760 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
11761}
11762
11763static void
11764do_neon_ceq (void)
11765{
11766 neon_compare (N_IF_32, N_IF_32, FALSE);
11767}
11768
11769/* For multiply instructions, we have the possibility of 16-bit or 32-bit
11770 scalars, which are encoded in 5 bits, M : Rm.
11771 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
11772 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
11773 index in M. */
11774
11775static unsigned
11776neon_scalar_for_mul (unsigned scalar, unsigned elsize)
11777{
dcbf9037
JB
11778 unsigned regno = NEON_SCALAR_REG (scalar);
11779 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
11780
11781 switch (elsize)
11782 {
11783 case 16:
11784 if (regno > 7 || elno > 3)
11785 goto bad_scalar;
11786 return regno | (elno << 3);
11787
11788 case 32:
11789 if (regno > 15 || elno > 1)
11790 goto bad_scalar;
11791 return regno | (elno << 4);
11792
11793 default:
11794 bad_scalar:
dcbf9037 11795 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
11796 }
11797
11798 return 0;
11799}
11800
11801/* Encode multiply / multiply-accumulate scalar instructions. */
11802
11803static void
11804neon_mul_mac (struct neon_type_el et, int ubit)
11805{
dcbf9037
JB
11806 unsigned scalar;
11807
11808 /* Give a more helpful error message if we have an invalid type. */
11809 if (et.type == NT_invtype)
11810 return;
11811
11812 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
11813 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11814 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11815 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
11816 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
11817 inst.instruction |= LOW4 (scalar);
11818 inst.instruction |= HI1 (scalar) << 5;
11819 inst.instruction |= (et.type == NT_float) << 8;
11820 inst.instruction |= neon_logbits (et.size) << 20;
11821 inst.instruction |= (ubit != 0) << 24;
11822
11823 inst.instruction = neon_dp_fixup (inst.instruction);
11824}
11825
11826static void
11827do_neon_mac_maybe_scalar (void)
11828{
037e8744
JB
11829 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
11830 return;
11831
11832 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11833 return;
11834
5287ad62
JB
11835 if (inst.operands[2].isscalar)
11836 {
037e8744 11837 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
11838 struct neon_type_el et = neon_check_type (3, rs,
11839 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
11840 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 11841 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
11842 }
11843 else
11844 do_neon_dyadic_if_i ();
11845}
11846
11847static void
11848do_neon_tst (void)
11849{
037e8744 11850 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11851 struct neon_type_el et = neon_check_type (3, rs,
11852 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 11853 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
11854}
11855
11856/* VMUL with 3 registers allows the P8 type. The scalar version supports the
11857 same types as the MAC equivalents. The polynomial type for this instruction
11858 is encoded the same as the integer type. */
11859
11860static void
11861do_neon_mul (void)
11862{
037e8744
JB
11863 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
11864 return;
11865
11866 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11867 return;
11868
5287ad62
JB
11869 if (inst.operands[2].isscalar)
11870 do_neon_mac_maybe_scalar ();
11871 else
dcbf9037 11872 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
11873}
11874
11875static void
11876do_neon_qdmulh (void)
11877{
11878 if (inst.operands[2].isscalar)
11879 {
037e8744 11880 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
11881 struct neon_type_el et = neon_check_type (3, rs,
11882 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11883 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 11884 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
11885 }
11886 else
11887 {
037e8744 11888 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11889 struct neon_type_el et = neon_check_type (3, rs,
11890 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
11891 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11892 /* The U bit (rounding) comes from bit mask. */
037e8744 11893 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
11894 }
11895}
11896
11897static void
11898do_neon_fcmp_absolute (void)
11899{
037e8744 11900 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
11901 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
11902 /* Size field comes from bit mask. */
037e8744 11903 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
11904}
11905
11906static void
11907do_neon_fcmp_absolute_inv (void)
11908{
11909 neon_exchange_operands ();
11910 do_neon_fcmp_absolute ();
11911}
11912
11913static void
11914do_neon_step (void)
11915{
037e8744 11916 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 11917 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 11918 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
11919}
11920
11921static void
11922do_neon_abs_neg (void)
11923{
037e8744
JB
11924 enum neon_shape rs;
11925 struct neon_type_el et;
11926
11927 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
11928 return;
11929
11930 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
11931 return;
11932
11933 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
11934 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
11935
5287ad62
JB
11936 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
11937 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
11938 inst.instruction |= LOW4 (inst.operands[1].reg);
11939 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 11940 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
11941 inst.instruction |= (et.type == NT_float) << 10;
11942 inst.instruction |= neon_logbits (et.size) << 18;
11943
11944 inst.instruction = neon_dp_fixup (inst.instruction);
11945}
11946
11947static void
11948do_neon_sli (void)
11949{
037e8744 11950 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11951 struct neon_type_el et = neon_check_type (2, rs,
11952 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11953 int imm = inst.operands[2].imm;
11954 constraint (imm < 0 || (unsigned)imm >= et.size,
11955 _("immediate out of range for insert"));
037e8744 11956 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
11957}
11958
11959static void
11960do_neon_sri (void)
11961{
037e8744 11962 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11963 struct neon_type_el et = neon_check_type (2, rs,
11964 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
11965 int imm = inst.operands[2].imm;
11966 constraint (imm < 1 || (unsigned)imm > et.size,
11967 _("immediate out of range for insert"));
037e8744 11968 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
11969}
11970
11971static void
11972do_neon_qshlu_imm (void)
11973{
037e8744 11974 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
11975 struct neon_type_el et = neon_check_type (2, rs,
11976 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
11977 int imm = inst.operands[2].imm;
11978 constraint (imm < 0 || (unsigned)imm >= et.size,
11979 _("immediate out of range for shift"));
11980 /* Only encodes the 'U present' variant of the instruction.
11981 In this case, signed types have OP (bit 8) set to 0.
11982 Unsigned types have OP set to 1. */
11983 inst.instruction |= (et.type == NT_unsigned) << 8;
11984 /* The rest of the bits are the same as other immediate shifts. */
037e8744 11985 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
11986}
11987
11988static void
11989do_neon_qmovn (void)
11990{
11991 struct neon_type_el et = neon_check_type (2, NS_DQ,
11992 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
11993 /* Saturating move where operands can be signed or unsigned, and the
11994 destination has the same signedness. */
11995 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
11996 if (et.type == NT_unsigned)
11997 inst.instruction |= 0xc0;
11998 else
11999 inst.instruction |= 0x80;
12000 neon_two_same (0, 1, et.size / 2);
12001}
12002
12003static void
12004do_neon_qmovun (void)
12005{
12006 struct neon_type_el et = neon_check_type (2, NS_DQ,
12007 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12008 /* Saturating move with unsigned results. Operands must be signed. */
12009 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12010 neon_two_same (0, 1, et.size / 2);
12011}
12012
12013static void
12014do_neon_rshift_sat_narrow (void)
12015{
12016 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12017 or unsigned. If operands are unsigned, results must also be unsigned. */
12018 struct neon_type_el et = neon_check_type (2, NS_DQI,
12019 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
12020 int imm = inst.operands[2].imm;
12021 /* This gets the bounds check, size encoding and immediate bits calculation
12022 right. */
12023 et.size /= 2;
12024
12025 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
12026 VQMOVN.I<size> <Dd>, <Qm>. */
12027 if (imm == 0)
12028 {
12029 inst.operands[2].present = 0;
12030 inst.instruction = N_MNEM_vqmovn;
12031 do_neon_qmovn ();
12032 return;
12033 }
12034
12035 constraint (imm < 1 || (unsigned)imm > et.size,
12036 _("immediate out of range"));
12037 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
12038}
12039
12040static void
12041do_neon_rshift_sat_narrow_u (void)
12042{
12043 /* FIXME: Types for narrowing. If operands are signed, results can be signed
12044 or unsigned. If operands are unsigned, results must also be unsigned. */
12045 struct neon_type_el et = neon_check_type (2, NS_DQI,
12046 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
12047 int imm = inst.operands[2].imm;
12048 /* This gets the bounds check, size encoding and immediate bits calculation
12049 right. */
12050 et.size /= 2;
12051
12052 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
12053 VQMOVUN.I<size> <Dd>, <Qm>. */
12054 if (imm == 0)
12055 {
12056 inst.operands[2].present = 0;
12057 inst.instruction = N_MNEM_vqmovun;
12058 do_neon_qmovun ();
12059 return;
12060 }
12061
12062 constraint (imm < 1 || (unsigned)imm > et.size,
12063 _("immediate out of range"));
12064 /* FIXME: The manual is kind of unclear about what value U should have in
12065 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
12066 must be 1. */
12067 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
12068}
12069
12070static void
12071do_neon_movn (void)
12072{
12073 struct neon_type_el et = neon_check_type (2, NS_DQ,
12074 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12075 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12076 neon_two_same (0, 1, et.size / 2);
12077}
12078
12079static void
12080do_neon_rshift_narrow (void)
12081{
12082 struct neon_type_el et = neon_check_type (2, NS_DQI,
12083 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
12084 int imm = inst.operands[2].imm;
12085 /* This gets the bounds check, size encoding and immediate bits calculation
12086 right. */
12087 et.size /= 2;
12088
12089 /* If immediate is zero then we are a pseudo-instruction for
12090 VMOVN.I<size> <Dd>, <Qm> */
12091 if (imm == 0)
12092 {
12093 inst.operands[2].present = 0;
12094 inst.instruction = N_MNEM_vmovn;
12095 do_neon_movn ();
12096 return;
12097 }
12098
12099 constraint (imm < 1 || (unsigned)imm > et.size,
12100 _("immediate out of range for narrowing operation"));
12101 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
12102}
12103
12104static void
12105do_neon_shll (void)
12106{
12107 /* FIXME: Type checking when lengthening. */
12108 struct neon_type_el et = neon_check_type (2, NS_QDI,
12109 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
12110 unsigned imm = inst.operands[2].imm;
12111
12112 if (imm == et.size)
12113 {
12114 /* Maximum shift variant. */
12115 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12116 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12117 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12118 inst.instruction |= LOW4 (inst.operands[1].reg);
12119 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12120 inst.instruction |= neon_logbits (et.size) << 18;
12121
12122 inst.instruction = neon_dp_fixup (inst.instruction);
12123 }
12124 else
12125 {
12126 /* A more-specific type check for non-max versions. */
12127 et = neon_check_type (2, NS_QDI,
12128 N_EQK | N_DBL, N_SU_32 | N_KEY);
12129 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12130 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
12131 }
12132}
12133
037e8744 12134/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
12135 the current instruction is. */
12136
12137static int
12138neon_cvt_flavour (enum neon_shape rs)
12139{
037e8744
JB
12140#define CVT_VAR(C,X,Y) \
12141 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
12142 if (et.type != NT_invtype) \
12143 { \
12144 inst.error = NULL; \
12145 return (C); \
5287ad62
JB
12146 }
12147 struct neon_type_el et;
037e8744
JB
12148 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
12149 || rs == NS_FF) ? N_VFP : 0;
12150 /* The instruction versions which take an immediate take one register
12151 argument, which is extended to the width of the full register. Thus the
12152 "source" and "destination" registers must have the same width. Hack that
12153 here by making the size equal to the key (wider, in this case) operand. */
12154 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5287ad62
JB
12155
12156 CVT_VAR (0, N_S32, N_F32);
12157 CVT_VAR (1, N_U32, N_F32);
12158 CVT_VAR (2, N_F32, N_S32);
12159 CVT_VAR (3, N_F32, N_U32);
12160
037e8744
JB
12161 whole_reg = N_VFP;
12162
12163 /* VFP instructions. */
12164 CVT_VAR (4, N_F32, N_F64);
12165 CVT_VAR (5, N_F64, N_F32);
12166 CVT_VAR (6, N_S32, N_F64 | key);
12167 CVT_VAR (7, N_U32, N_F64 | key);
12168 CVT_VAR (8, N_F64 | key, N_S32);
12169 CVT_VAR (9, N_F64 | key, N_U32);
12170 /* VFP instructions with bitshift. */
12171 CVT_VAR (10, N_F32 | key, N_S16);
12172 CVT_VAR (11, N_F32 | key, N_U16);
12173 CVT_VAR (12, N_F64 | key, N_S16);
12174 CVT_VAR (13, N_F64 | key, N_U16);
12175 CVT_VAR (14, N_S16, N_F32 | key);
12176 CVT_VAR (15, N_U16, N_F32 | key);
12177 CVT_VAR (16, N_S16, N_F64 | key);
12178 CVT_VAR (17, N_U16, N_F64 | key);
12179
5287ad62
JB
12180 return -1;
12181#undef CVT_VAR
12182}
12183
037e8744
JB
12184/* Neon-syntax VFP conversions. */
12185
5287ad62 12186static void
037e8744 12187do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 12188{
037e8744
JB
12189 const char *opname = 0;
12190
12191 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 12192 {
037e8744
JB
12193 /* Conversions with immediate bitshift. */
12194 const char *enc[] =
12195 {
12196 "ftosls",
12197 "ftouls",
12198 "fsltos",
12199 "fultos",
12200 NULL,
12201 NULL,
12202 "ftosld",
12203 "ftould",
12204 "fsltod",
12205 "fultod",
12206 "fshtos",
12207 "fuhtos",
12208 "fshtod",
12209 "fuhtod",
12210 "ftoshs",
12211 "ftouhs",
12212 "ftoshd",
12213 "ftouhd"
12214 };
12215
12216 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12217 {
12218 opname = enc[flavour];
12219 constraint (inst.operands[0].reg != inst.operands[1].reg,
12220 _("operands 0 and 1 must be the same register"));
12221 inst.operands[1] = inst.operands[2];
12222 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
12223 }
5287ad62
JB
12224 }
12225 else
12226 {
037e8744
JB
12227 /* Conversions without bitshift. */
12228 const char *enc[] =
12229 {
12230 "ftosis",
12231 "ftouis",
12232 "fsitos",
12233 "fuitos",
12234 "fcvtsd",
12235 "fcvtds",
12236 "ftosid",
12237 "ftouid",
12238 "fsitod",
12239 "fuitod"
12240 };
12241
12242 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
12243 opname = enc[flavour];
12244 }
12245
12246 if (opname)
12247 do_vfp_nsyn_opcode (opname);
12248}
12249
12250static void
12251do_vfp_nsyn_cvtz (void)
12252{
12253 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
12254 int flavour = neon_cvt_flavour (rs);
12255 const char *enc[] =
12256 {
12257 "ftosizs",
12258 "ftouizs",
12259 NULL,
12260 NULL,
12261 NULL,
12262 NULL,
12263 "ftosizd",
12264 "ftouizd"
12265 };
12266
12267 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
12268 do_vfp_nsyn_opcode (enc[flavour]);
12269}
12270
12271static void
12272do_neon_cvt (void)
12273{
12274 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
12275 NS_FD, NS_DF, NS_FF, NS_NULL);
12276 int flavour = neon_cvt_flavour (rs);
12277
12278 /* VFP rather than Neon conversions. */
12279 if (flavour >= 4)
12280 {
12281 do_vfp_nsyn_cvt (rs, flavour);
12282 return;
12283 }
12284
12285 switch (rs)
12286 {
12287 case NS_DDI:
12288 case NS_QQI:
12289 {
12290 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12291 return;
12292
12293 /* Fixed-point conversion with #0 immediate is encoded as an
12294 integer conversion. */
12295 if (inst.operands[2].present && inst.operands[2].imm == 0)
12296 goto int_encode;
12297 unsigned immbits = 32 - inst.operands[2].imm;
12298 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
12299 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12300 if (flavour != -1)
12301 inst.instruction |= enctab[flavour];
12302 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12303 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12304 inst.instruction |= LOW4 (inst.operands[1].reg);
12305 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12306 inst.instruction |= neon_quad (rs) << 6;
12307 inst.instruction |= 1 << 21;
12308 inst.instruction |= immbits << 16;
12309
12310 inst.instruction = neon_dp_fixup (inst.instruction);
12311 }
12312 break;
12313
12314 case NS_DD:
12315 case NS_QQ:
12316 int_encode:
12317 {
12318 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
12319
12320 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12321
12322 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12323 return;
12324
12325 if (flavour != -1)
12326 inst.instruction |= enctab[flavour];
12327
12328 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12329 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12330 inst.instruction |= LOW4 (inst.operands[1].reg);
12331 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12332 inst.instruction |= neon_quad (rs) << 6;
12333 inst.instruction |= 2 << 18;
12334
12335 inst.instruction = neon_dp_fixup (inst.instruction);
12336 }
12337 break;
12338
12339 default:
12340 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
12341 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 12342 }
5287ad62
JB
12343}
12344
12345static void
12346neon_move_immediate (void)
12347{
037e8744
JB
12348 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12349 struct neon_type_el et = neon_check_type (2, rs,
12350 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
12351 unsigned immlo, immhi = 0, immbits;
12352 int op, cmode;
12353
037e8744
JB
12354 constraint (et.type == NT_invtype,
12355 _("operand size must be specified for immediate VMOV"));
12356
5287ad62
JB
12357 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
12358 op = (inst.instruction & (1 << 5)) != 0;
12359
12360 immlo = inst.operands[1].imm;
12361 if (inst.operands[1].regisimm)
12362 immhi = inst.operands[1].reg;
12363
12364 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
12365 _("immediate has bits set outside the operand size"));
12366
12367 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
136da414 12368 et.size, et.type)) == FAIL)
5287ad62
JB
12369 {
12370 /* Invert relevant bits only. */
12371 neon_invert_size (&immlo, &immhi, et.size);
12372 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
12373 with one or the other; those cases are caught by
12374 neon_cmode_for_move_imm. */
12375 op = !op;
12376 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, &immbits, &op,
136da414 12377 et.size, et.type)) == FAIL)
5287ad62 12378 {
dcbf9037 12379 first_error (_("immediate out of range"));
5287ad62
JB
12380 return;
12381 }
12382 }
12383
12384 inst.instruction &= ~(1 << 5);
12385 inst.instruction |= op << 5;
12386
12387 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12388 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 12389 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12390 inst.instruction |= cmode << 8;
12391
12392 neon_write_immbits (immbits);
12393}
12394
12395static void
12396do_neon_mvn (void)
12397{
12398 if (inst.operands[1].isreg)
12399 {
037e8744 12400 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12401
12402 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12403 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12404 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12405 inst.instruction |= LOW4 (inst.operands[1].reg);
12406 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12407 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12408 }
12409 else
12410 {
12411 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12412 neon_move_immediate ();
12413 }
12414
12415 inst.instruction = neon_dp_fixup (inst.instruction);
12416}
12417
12418/* Encode instructions of form:
12419
12420 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12421 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm |
12422
12423*/
12424
12425static void
12426neon_mixed_length (struct neon_type_el et, unsigned size)
12427{
12428 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12429 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12430 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12431 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12432 inst.instruction |= LOW4 (inst.operands[2].reg);
12433 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12434 inst.instruction |= (et.type == NT_unsigned) << 24;
12435 inst.instruction |= neon_logbits (size) << 20;
12436
12437 inst.instruction = neon_dp_fixup (inst.instruction);
12438}
12439
12440static void
12441do_neon_dyadic_long (void)
12442{
12443 /* FIXME: Type checking for lengthening op. */
12444 struct neon_type_el et = neon_check_type (3, NS_QDD,
12445 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
12446 neon_mixed_length (et, et.size);
12447}
12448
12449static void
12450do_neon_abal (void)
12451{
12452 struct neon_type_el et = neon_check_type (3, NS_QDD,
12453 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
12454 neon_mixed_length (et, et.size);
12455}
12456
12457static void
12458neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
12459{
12460 if (inst.operands[2].isscalar)
12461 {
dcbf9037
JB
12462 struct neon_type_el et = neon_check_type (3, NS_QDS,
12463 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
12464 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12465 neon_mul_mac (et, et.type == NT_unsigned);
12466 }
12467 else
12468 {
12469 struct neon_type_el et = neon_check_type (3, NS_QDD,
12470 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
12471 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12472 neon_mixed_length (et, et.size);
12473 }
12474}
12475
12476static void
12477do_neon_mac_maybe_scalar_long (void)
12478{
12479 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
12480}
12481
12482static void
12483do_neon_dyadic_wide (void)
12484{
12485 struct neon_type_el et = neon_check_type (3, NS_QQD,
12486 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
12487 neon_mixed_length (et, et.size);
12488}
12489
12490static void
12491do_neon_dyadic_narrow (void)
12492{
12493 struct neon_type_el et = neon_check_type (3, NS_QDD,
12494 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
12495 neon_mixed_length (et, et.size / 2);
12496}
12497
12498static void
12499do_neon_mul_sat_scalar_long (void)
12500{
12501 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
12502}
12503
12504static void
12505do_neon_vmull (void)
12506{
12507 if (inst.operands[2].isscalar)
12508 do_neon_mac_maybe_scalar_long ();
12509 else
12510 {
12511 struct neon_type_el et = neon_check_type (3, NS_QDD,
12512 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
12513 if (et.type == NT_poly)
12514 inst.instruction = NEON_ENC_POLY (inst.instruction);
12515 else
12516 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12517 /* For polynomial encoding, size field must be 0b00 and the U bit must be
12518 zero. Should be OK as-is. */
12519 neon_mixed_length (et, et.size);
12520 }
12521}
12522
12523static void
12524do_neon_ext (void)
12525{
037e8744 12526 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
12527 struct neon_type_el et = neon_check_type (3, rs,
12528 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12529 unsigned imm = (inst.operands[3].imm * et.size) / 8;
12530 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12531 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12532 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12533 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12534 inst.instruction |= LOW4 (inst.operands[2].reg);
12535 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 12536 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12537 inst.instruction |= imm << 8;
12538
12539 inst.instruction = neon_dp_fixup (inst.instruction);
12540}
12541
12542static void
12543do_neon_rev (void)
12544{
037e8744 12545 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12546 struct neon_type_el et = neon_check_type (2, rs,
12547 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12548 unsigned op = (inst.instruction >> 7) & 3;
12549 /* N (width of reversed regions) is encoded as part of the bitmask. We
12550 extract it here to check the elements to be reversed are smaller.
12551 Otherwise we'd get a reserved instruction. */
12552 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
12553 assert (elsize != 0);
12554 constraint (et.size >= elsize,
12555 _("elements must be smaller than reversal region"));
037e8744 12556 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12557}
12558
12559static void
12560do_neon_dup (void)
12561{
12562 if (inst.operands[1].isscalar)
12563 {
037e8744 12564 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
12565 struct neon_type_el et = neon_check_type (2, rs,
12566 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 12567 unsigned sizebits = et.size >> 3;
dcbf9037 12568 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 12569 int logsize = neon_logbits (et.size);
dcbf9037 12570 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
12571
12572 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
12573 return;
12574
5287ad62
JB
12575 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
12576 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12577 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12578 inst.instruction |= LOW4 (dm);
12579 inst.instruction |= HI1 (dm) << 5;
037e8744 12580 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12581 inst.instruction |= x << 17;
12582 inst.instruction |= sizebits << 16;
12583
12584 inst.instruction = neon_dp_fixup (inst.instruction);
12585 }
12586 else
12587 {
037e8744
JB
12588 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
12589 struct neon_type_el et = neon_check_type (2, rs,
12590 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
12591 /* Duplicate ARM register to lanes of vector. */
12592 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
12593 switch (et.size)
12594 {
12595 case 8: inst.instruction |= 0x400000; break;
12596 case 16: inst.instruction |= 0x000020; break;
12597 case 32: inst.instruction |= 0x000000; break;
12598 default: break;
12599 }
12600 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
12601 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
12602 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 12603 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
12604 /* The encoding for this instruction is identical for the ARM and Thumb
12605 variants, except for the condition field. */
037e8744 12606 do_vfp_cond_or_thumb ();
5287ad62
JB
12607 }
12608}
12609
12610/* VMOV has particularly many variations. It can be one of:
12611 0. VMOV<c><q> <Qd>, <Qm>
12612 1. VMOV<c><q> <Dd>, <Dm>
12613 (Register operations, which are VORR with Rm = Rn.)
12614 2. VMOV<c><q>.<dt> <Qd>, #<imm>
12615 3. VMOV<c><q>.<dt> <Dd>, #<imm>
12616 (Immediate loads.)
12617 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
12618 (ARM register to scalar.)
12619 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
12620 (Two ARM registers to vector.)
12621 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
12622 (Scalar to ARM register.)
12623 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
12624 (Vector to two ARM registers.)
037e8744
JB
12625 8. VMOV.F32 <Sd>, <Sm>
12626 9. VMOV.F64 <Dd>, <Dm>
12627 (VFP register moves.)
12628 10. VMOV.F32 <Sd>, #imm
12629 11. VMOV.F64 <Dd>, #imm
12630 (VFP float immediate load.)
12631 12. VMOV <Rd>, <Sm>
12632 (VFP single to ARM reg.)
12633 13. VMOV <Sd>, <Rm>
12634 (ARM reg to VFP single.)
12635 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
12636 (Two ARM regs to two VFP singles.)
12637 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
12638 (Two VFP singles to two ARM regs.)
5287ad62 12639
037e8744
JB
12640 These cases can be disambiguated using neon_select_shape, except cases 1/9
12641 and 3/11 which depend on the operand type too.
5287ad62
JB
12642
12643 All the encoded bits are hardcoded by this function.
12644
b7fc2769
JB
12645 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
12646 Cases 5, 7 may be used with VFPv2 and above.
12647
5287ad62
JB
12648 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
12649 can specify a type where it doesn't make sense to, and is ignored).
12650*/
12651
12652static void
12653do_neon_mov (void)
12654{
037e8744
JB
12655 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
12656 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
12657 NS_NULL);
12658 struct neon_type_el et;
12659 const char *ldconst = 0;
5287ad62 12660
037e8744 12661 switch (rs)
5287ad62 12662 {
037e8744
JB
12663 case NS_DD: /* case 1/9. */
12664 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12665 /* It is not an error here if no type is given. */
12666 inst.error = NULL;
12667 if (et.type == NT_float && et.size == 64)
5287ad62 12668 {
037e8744
JB
12669 do_vfp_nsyn_opcode ("fcpyd");
12670 break;
5287ad62 12671 }
037e8744 12672 /* fall through. */
5287ad62 12673
037e8744
JB
12674 case NS_QQ: /* case 0/1. */
12675 {
12676 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12677 return;
12678 /* The architecture manual I have doesn't explicitly state which
12679 value the U bit should have for register->register moves, but
12680 the equivalent VORR instruction has U = 0, so do that. */
12681 inst.instruction = 0x0200110;
12682 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12683 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12684 inst.instruction |= LOW4 (inst.operands[1].reg);
12685 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12686 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12687 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12688 inst.instruction |= neon_quad (rs) << 6;
12689
12690 inst.instruction = neon_dp_fixup (inst.instruction);
12691 }
12692 break;
12693
12694 case NS_DI: /* case 3/11. */
12695 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
12696 inst.error = NULL;
12697 if (et.type == NT_float && et.size == 64)
5287ad62 12698 {
037e8744
JB
12699 /* case 11 (fconstd). */
12700 ldconst = "fconstd";
12701 goto encode_fconstd;
5287ad62 12702 }
037e8744
JB
12703 /* fall through. */
12704
12705 case NS_QI: /* case 2/3. */
12706 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12707 return;
12708 inst.instruction = 0x0800010;
12709 neon_move_immediate ();
12710 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62
JB
12711 break;
12712
037e8744
JB
12713 case NS_SR: /* case 4. */
12714 {
12715 unsigned bcdebits = 0;
12716 struct neon_type_el et = neon_check_type (2, NS_NULL,
12717 N_8 | N_16 | N_32 | N_KEY, N_EQK);
12718 int logsize = neon_logbits (et.size);
12719 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
12720 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
12721
12722 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12723 _(BAD_FPU));
12724 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12725 && et.size != 32, _(BAD_FPU));
12726 constraint (et.type == NT_invtype, _("bad type for scalar"));
12727 constraint (x >= 64 / et.size, _("scalar index out of range"));
12728
12729 switch (et.size)
12730 {
12731 case 8: bcdebits = 0x8; break;
12732 case 16: bcdebits = 0x1; break;
12733 case 32: bcdebits = 0x0; break;
12734 default: ;
12735 }
12736
12737 bcdebits |= x << logsize;
12738
12739 inst.instruction = 0xe000b10;
12740 do_vfp_cond_or_thumb ();
12741 inst.instruction |= LOW4 (dn) << 16;
12742 inst.instruction |= HI1 (dn) << 7;
12743 inst.instruction |= inst.operands[1].reg << 12;
12744 inst.instruction |= (bcdebits & 3) << 5;
12745 inst.instruction |= (bcdebits >> 2) << 21;
12746 }
12747 break;
12748
12749 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 12750 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 12751 _(BAD_FPU));
b7fc2769 12752
037e8744
JB
12753 inst.instruction = 0xc400b10;
12754 do_vfp_cond_or_thumb ();
12755 inst.instruction |= LOW4 (inst.operands[0].reg);
12756 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
12757 inst.instruction |= inst.operands[1].reg << 12;
12758 inst.instruction |= inst.operands[2].reg << 16;
12759 break;
12760
12761 case NS_RS: /* case 6. */
12762 {
12763 struct neon_type_el et = neon_check_type (2, NS_NULL,
12764 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
12765 unsigned logsize = neon_logbits (et.size);
12766 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
12767 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
12768 unsigned abcdebits = 0;
12769
12770 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
12771 _(BAD_FPU));
12772 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
12773 && et.size != 32, _(BAD_FPU));
12774 constraint (et.type == NT_invtype, _("bad type for scalar"));
12775 constraint (x >= 64 / et.size, _("scalar index out of range"));
12776
12777 switch (et.size)
12778 {
12779 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
12780 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
12781 case 32: abcdebits = 0x00; break;
12782 default: ;
12783 }
12784
12785 abcdebits |= x << logsize;
12786 inst.instruction = 0xe100b10;
12787 do_vfp_cond_or_thumb ();
12788 inst.instruction |= LOW4 (dn) << 16;
12789 inst.instruction |= HI1 (dn) << 7;
12790 inst.instruction |= inst.operands[0].reg << 12;
12791 inst.instruction |= (abcdebits & 3) << 5;
12792 inst.instruction |= (abcdebits >> 2) << 21;
12793 }
12794 break;
12795
12796 case NS_RRD: /* case 7 (fmrrd). */
12797 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
12798 _(BAD_FPU));
12799
12800 inst.instruction = 0xc500b10;
12801 do_vfp_cond_or_thumb ();
12802 inst.instruction |= inst.operands[0].reg << 12;
12803 inst.instruction |= inst.operands[1].reg << 16;
12804 inst.instruction |= LOW4 (inst.operands[2].reg);
12805 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12806 break;
12807
12808 case NS_FF: /* case 8 (fcpys). */
12809 do_vfp_nsyn_opcode ("fcpys");
12810 break;
12811
12812 case NS_FI: /* case 10 (fconsts). */
12813 ldconst = "fconsts";
12814 encode_fconstd:
12815 if (is_quarter_float (inst.operands[1].imm))
5287ad62 12816 {
037e8744
JB
12817 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
12818 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
12819 }
12820 else
037e8744
JB
12821 first_error (_("immediate out of range"));
12822 break;
12823
12824 case NS_RF: /* case 12 (fmrs). */
12825 do_vfp_nsyn_opcode ("fmrs");
12826 break;
12827
12828 case NS_FR: /* case 13 (fmsr). */
12829 do_vfp_nsyn_opcode ("fmsr");
12830 break;
12831
12832 /* The encoders for the fmrrs and fmsrr instructions expect three operands
12833 (one of which is a list), but we have parsed four. Do some fiddling to
12834 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
12835 expect. */
12836 case NS_RRFF: /* case 14 (fmrrs). */
12837 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
12838 _("VFP registers must be adjacent"));
12839 inst.operands[2].imm = 2;
12840 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12841 do_vfp_nsyn_opcode ("fmrrs");
12842 break;
12843
12844 case NS_FFRR: /* case 15 (fmsrr). */
12845 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
12846 _("VFP registers must be adjacent"));
12847 inst.operands[1] = inst.operands[2];
12848 inst.operands[2] = inst.operands[3];
12849 inst.operands[0].imm = 2;
12850 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
12851 do_vfp_nsyn_opcode ("fmsrr");
5287ad62
JB
12852 break;
12853
12854 default:
12855 abort ();
12856 }
12857}
12858
12859static void
12860do_neon_rshift_round_imm (void)
12861{
037e8744 12862 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12863 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12864 int imm = inst.operands[2].imm;
12865
12866 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
12867 if (imm == 0)
12868 {
12869 inst.operands[2].present = 0;
12870 do_neon_mov ();
12871 return;
12872 }
12873
12874 constraint (imm < 1 || (unsigned)imm > et.size,
12875 _("immediate out of range for shift"));
037e8744 12876 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12877 et.size - imm);
12878}
12879
12880static void
12881do_neon_movl (void)
12882{
12883 struct neon_type_el et = neon_check_type (2, NS_QD,
12884 N_EQK | N_DBL, N_SU_32 | N_KEY);
12885 unsigned sizebits = et.size >> 3;
12886 inst.instruction |= sizebits << 19;
12887 neon_two_same (0, et.type == NT_unsigned, -1);
12888}
12889
12890static void
12891do_neon_trn (void)
12892{
037e8744 12893 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12894 struct neon_type_el et = neon_check_type (2, rs,
12895 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12896 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12897 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12898}
12899
12900static void
12901do_neon_zip_uzp (void)
12902{
037e8744 12903 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12904 struct neon_type_el et = neon_check_type (2, rs,
12905 N_EQK, N_8 | N_16 | N_32 | N_KEY);
12906 if (rs == NS_DD && et.size == 32)
12907 {
12908 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
12909 inst.instruction = N_MNEM_vtrn;
12910 do_neon_trn ();
12911 return;
12912 }
037e8744 12913 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12914}
12915
12916static void
12917do_neon_sat_abs_neg (void)
12918{
037e8744 12919 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12920 struct neon_type_el et = neon_check_type (2, rs,
12921 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 12922 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12923}
12924
12925static void
12926do_neon_pair_long (void)
12927{
037e8744 12928 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12929 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
12930 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
12931 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 12932 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12933}
12934
12935static void
12936do_neon_recip_est (void)
12937{
037e8744 12938 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12939 struct neon_type_el et = neon_check_type (2, rs,
12940 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
12941 inst.instruction |= (et.type == NT_float) << 8;
037e8744 12942 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12943}
12944
12945static void
12946do_neon_cls (void)
12947{
037e8744 12948 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12949 struct neon_type_el et = neon_check_type (2, rs,
12950 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 12951 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12952}
12953
12954static void
12955do_neon_clz (void)
12956{
037e8744 12957 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12958 struct neon_type_el et = neon_check_type (2, rs,
12959 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 12960 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12961}
12962
12963static void
12964do_neon_cnt (void)
12965{
037e8744 12966 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
12967 struct neon_type_el et = neon_check_type (2, rs,
12968 N_EQK | N_INT, N_8 | N_KEY);
037e8744 12969 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
12970}
12971
12972static void
12973do_neon_swp (void)
12974{
037e8744
JB
12975 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12976 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
12977}
12978
12979static void
12980do_neon_tbl_tbx (void)
12981{
12982 unsigned listlenbits;
dcbf9037 12983 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5287ad62
JB
12984
12985 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
12986 {
dcbf9037 12987 first_error (_("bad list length for table lookup"));
5287ad62
JB
12988 return;
12989 }
12990
12991 listlenbits = inst.operands[1].imm - 1;
12992 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12993 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12994 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12995 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12996 inst.instruction |= LOW4 (inst.operands[2].reg);
12997 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12998 inst.instruction |= listlenbits << 8;
12999
13000 inst.instruction = neon_dp_fixup (inst.instruction);
13001}
13002
13003static void
13004do_neon_ldm_stm (void)
13005{
13006 /* P, U and L bits are part of bitmask. */
13007 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
13008 unsigned offsetbits = inst.operands[1].imm * 2;
13009
037e8744
JB
13010 if (inst.operands[1].issingle)
13011 {
13012 do_vfp_nsyn_ldm_stm (is_dbmode);
13013 return;
13014 }
13015
5287ad62
JB
13016 constraint (is_dbmode && !inst.operands[0].writeback,
13017 _("writeback (!) must be used for VLDMDB and VSTMDB"));
13018
13019 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
13020 _("register list must contain at least 1 and at most 16 "
13021 "registers"));
13022
13023 inst.instruction |= inst.operands[0].reg << 16;
13024 inst.instruction |= inst.operands[0].writeback << 21;
13025 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13026 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
13027
13028 inst.instruction |= offsetbits;
13029
037e8744 13030 do_vfp_cond_or_thumb ();
5287ad62
JB
13031}
13032
13033static void
13034do_neon_ldr_str (void)
13035{
5287ad62
JB
13036 int is_ldr = (inst.instruction & (1 << 20)) != 0;
13037
037e8744
JB
13038 if (inst.operands[0].issingle)
13039 {
cd2f129f
JB
13040 if (is_ldr)
13041 do_vfp_nsyn_opcode ("flds");
13042 else
13043 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
13044 }
13045 else
5287ad62 13046 {
cd2f129f
JB
13047 if (is_ldr)
13048 do_vfp_nsyn_opcode ("fldd");
5287ad62 13049 else
cd2f129f 13050 do_vfp_nsyn_opcode ("fstd");
5287ad62 13051 }
5287ad62
JB
13052}
13053
13054/* "interleave" version also handles non-interleaving register VLD1/VST1
13055 instructions. */
13056
13057static void
13058do_neon_ld_st_interleave (void)
13059{
037e8744 13060 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
13061 N_8 | N_16 | N_32 | N_64);
13062 unsigned alignbits = 0;
13063 unsigned idx;
13064 /* The bits in this table go:
13065 0: register stride of one (0) or two (1)
13066 1,2: register list length, minus one (1, 2, 3, 4).
13067 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
13068 We use -1 for invalid entries. */
13069 const int typetable[] =
13070 {
13071 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
13072 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
13073 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
13074 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
13075 };
13076 int typebits;
13077
dcbf9037
JB
13078 if (et.type == NT_invtype)
13079 return;
13080
5287ad62
JB
13081 if (inst.operands[1].immisalign)
13082 switch (inst.operands[1].imm >> 8)
13083 {
13084 case 64: alignbits = 1; break;
13085 case 128:
13086 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13087 goto bad_alignment;
13088 alignbits = 2;
13089 break;
13090 case 256:
13091 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
13092 goto bad_alignment;
13093 alignbits = 3;
13094 break;
13095 default:
13096 bad_alignment:
dcbf9037 13097 first_error (_("bad alignment"));
5287ad62
JB
13098 return;
13099 }
13100
13101 inst.instruction |= alignbits << 4;
13102 inst.instruction |= neon_logbits (et.size) << 6;
13103
13104 /* Bits [4:6] of the immediate in a list specifier encode register stride
13105 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
13106 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
13107 up the right value for "type" in a table based on this value and the given
13108 list style, then stick it back. */
13109 idx = ((inst.operands[0].imm >> 4) & 7)
13110 | (((inst.instruction >> 8) & 3) << 3);
13111
13112 typebits = typetable[idx];
13113
13114 constraint (typebits == -1, _("bad list type for instruction"));
13115
13116 inst.instruction &= ~0xf00;
13117 inst.instruction |= typebits << 8;
13118}
13119
13120/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
13121 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
13122 otherwise. The variable arguments are a list of pairs of legal (size, align)
13123 values, terminated with -1. */
13124
13125static int
13126neon_alignment_bit (int size, int align, int *do_align, ...)
13127{
13128 va_list ap;
13129 int result = FAIL, thissize, thisalign;
13130
13131 if (!inst.operands[1].immisalign)
13132 {
13133 *do_align = 0;
13134 return SUCCESS;
13135 }
13136
13137 va_start (ap, do_align);
13138
13139 do
13140 {
13141 thissize = va_arg (ap, int);
13142 if (thissize == -1)
13143 break;
13144 thisalign = va_arg (ap, int);
13145
13146 if (size == thissize && align == thisalign)
13147 result = SUCCESS;
13148 }
13149 while (result != SUCCESS);
13150
13151 va_end (ap);
13152
13153 if (result == SUCCESS)
13154 *do_align = 1;
13155 else
dcbf9037 13156 first_error (_("unsupported alignment for instruction"));
5287ad62
JB
13157
13158 return result;
13159}
13160
13161static void
13162do_neon_ld_st_lane (void)
13163{
037e8744 13164 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13165 int align_good, do_align = 0;
13166 int logsize = neon_logbits (et.size);
13167 int align = inst.operands[1].imm >> 8;
13168 int n = (inst.instruction >> 8) & 3;
13169 int max_el = 64 / et.size;
13170
dcbf9037
JB
13171 if (et.type == NT_invtype)
13172 return;
13173
5287ad62
JB
13174 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
13175 _("bad list length"));
13176 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
13177 _("scalar index out of range"));
13178 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
13179 && et.size == 8,
13180 _("stride of 2 unavailable when element size is 8"));
13181
13182 switch (n)
13183 {
13184 case 0: /* VLD1 / VST1. */
13185 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
13186 32, 32, -1);
13187 if (align_good == FAIL)
13188 return;
13189 if (do_align)
13190 {
13191 unsigned alignbits = 0;
13192 switch (et.size)
13193 {
13194 case 16: alignbits = 0x1; break;
13195 case 32: alignbits = 0x3; break;
13196 default: ;
13197 }
13198 inst.instruction |= alignbits << 4;
13199 }
13200 break;
13201
13202 case 1: /* VLD2 / VST2. */
13203 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
13204 32, 64, -1);
13205 if (align_good == FAIL)
13206 return;
13207 if (do_align)
13208 inst.instruction |= 1 << 4;
13209 break;
13210
13211 case 2: /* VLD3 / VST3. */
13212 constraint (inst.operands[1].immisalign,
13213 _("can't use alignment with this instruction"));
13214 break;
13215
13216 case 3: /* VLD4 / VST4. */
13217 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13218 16, 64, 32, 64, 32, 128, -1);
13219 if (align_good == FAIL)
13220 return;
13221 if (do_align)
13222 {
13223 unsigned alignbits = 0;
13224 switch (et.size)
13225 {
13226 case 8: alignbits = 0x1; break;
13227 case 16: alignbits = 0x1; break;
13228 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
13229 default: ;
13230 }
13231 inst.instruction |= alignbits << 4;
13232 }
13233 break;
13234
13235 default: ;
13236 }
13237
13238 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
13239 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13240 inst.instruction |= 1 << (4 + logsize);
13241
13242 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
13243 inst.instruction |= logsize << 10;
13244}
13245
13246/* Encode single n-element structure to all lanes VLD<n> instructions. */
13247
13248static void
13249do_neon_ld_dup (void)
13250{
037e8744 13251 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
13252 int align_good, do_align = 0;
13253
dcbf9037
JB
13254 if (et.type == NT_invtype)
13255 return;
13256
5287ad62
JB
13257 switch ((inst.instruction >> 8) & 3)
13258 {
13259 case 0: /* VLD1. */
13260 assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
13261 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13262 &do_align, 16, 16, 32, 32, -1);
13263 if (align_good == FAIL)
13264 return;
13265 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
13266 {
13267 case 1: break;
13268 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 13269 default: first_error (_("bad list length")); return;
5287ad62
JB
13270 }
13271 inst.instruction |= neon_logbits (et.size) << 6;
13272 break;
13273
13274 case 1: /* VLD2. */
13275 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
13276 &do_align, 8, 16, 16, 32, 32, 64, -1);
13277 if (align_good == FAIL)
13278 return;
13279 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
13280 _("bad list length"));
13281 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13282 inst.instruction |= 1 << 5;
13283 inst.instruction |= neon_logbits (et.size) << 6;
13284 break;
13285
13286 case 2: /* VLD3. */
13287 constraint (inst.operands[1].immisalign,
13288 _("can't use alignment with this instruction"));
13289 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
13290 _("bad list length"));
13291 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13292 inst.instruction |= 1 << 5;
13293 inst.instruction |= neon_logbits (et.size) << 6;
13294 break;
13295
13296 case 3: /* VLD4. */
13297 {
13298 int align = inst.operands[1].imm >> 8;
13299 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
13300 16, 64, 32, 64, 32, 128, -1);
13301 if (align_good == FAIL)
13302 return;
13303 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
13304 _("bad list length"));
13305 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
13306 inst.instruction |= 1 << 5;
13307 if (et.size == 32 && align == 128)
13308 inst.instruction |= 0x3 << 6;
13309 else
13310 inst.instruction |= neon_logbits (et.size) << 6;
13311 }
13312 break;
13313
13314 default: ;
13315 }
13316
13317 inst.instruction |= do_align << 4;
13318}
13319
13320/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
13321 apart from bits [11:4]. */
13322
13323static void
13324do_neon_ldx_stx (void)
13325{
13326 switch (NEON_LANE (inst.operands[0].imm))
13327 {
13328 case NEON_INTERLEAVE_LANES:
13329 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
13330 do_neon_ld_st_interleave ();
13331 break;
13332
13333 case NEON_ALL_LANES:
13334 inst.instruction = NEON_ENC_DUP (inst.instruction);
13335 do_neon_ld_dup ();
13336 break;
13337
13338 default:
13339 inst.instruction = NEON_ENC_LANE (inst.instruction);
13340 do_neon_ld_st_lane ();
13341 }
13342
13343 /* L bit comes from bit mask. */
13344 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13345 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13346 inst.instruction |= inst.operands[1].reg << 16;
13347
13348 if (inst.operands[1].postind)
13349 {
13350 int postreg = inst.operands[1].imm & 0xf;
13351 constraint (!inst.operands[1].immisreg,
13352 _("post-index must be a register"));
13353 constraint (postreg == 0xd || postreg == 0xf,
13354 _("bad register for post-index"));
13355 inst.instruction |= postreg;
13356 }
13357 else if (inst.operands[1].writeback)
13358 {
13359 inst.instruction |= 0xd;
13360 }
13361 else
13362 inst.instruction |= 0xf;
13363
13364 if (thumb_mode)
13365 inst.instruction |= 0xf9000000;
13366 else
13367 inst.instruction |= 0xf4000000;
13368}
13369
13370\f
13371/* Overall per-instruction processing. */
13372
13373/* We need to be able to fix up arbitrary expressions in some statements.
13374 This is so that we can handle symbols that are an arbitrary distance from
13375 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
13376 which returns part of an address in a form which will be valid for
13377 a data instruction. We do this by pushing the expression into a symbol
13378 in the expr_section, and creating a fix for that. */
13379
13380static void
13381fix_new_arm (fragS * frag,
13382 int where,
13383 short int size,
13384 expressionS * exp,
13385 int pc_rel,
13386 int reloc)
13387{
13388 fixS * new_fix;
13389
13390 switch (exp->X_op)
13391 {
13392 case O_constant:
13393 case O_symbol:
13394 case O_add:
13395 case O_subtract:
13396 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
13397 break;
13398
13399 default:
13400 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
13401 pc_rel, reloc);
13402 break;
13403 }
13404
13405 /* Mark whether the fix is to a THUMB instruction, or an ARM
13406 instruction. */
13407 new_fix->tc_fix_data = thumb_mode;
13408}
13409
13410/* Create a frg for an instruction requiring relaxation. */
13411static void
13412output_relax_insn (void)
13413{
13414 char * to;
13415 symbolS *sym;
0110f2b8
PB
13416 int offset;
13417
6e1cb1a6
PB
13418 /* The size of the instruction is unknown, so tie the debug info to the
13419 start of the instruction. */
13420 dwarf2_emit_insn (0);
6e1cb1a6 13421
0110f2b8
PB
13422 switch (inst.reloc.exp.X_op)
13423 {
13424 case O_symbol:
13425 sym = inst.reloc.exp.X_add_symbol;
13426 offset = inst.reloc.exp.X_add_number;
13427 break;
13428 case O_constant:
13429 sym = NULL;
13430 offset = inst.reloc.exp.X_add_number;
13431 break;
13432 default:
13433 sym = make_expr_symbol (&inst.reloc.exp);
13434 offset = 0;
13435 break;
13436 }
13437 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
13438 inst.relax, sym, offset, NULL/*offset, opcode*/);
13439 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
13440}
13441
13442/* Write a 32-bit thumb instruction to buf. */
13443static void
13444put_thumb32_insn (char * buf, unsigned long insn)
13445{
13446 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
13447 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
13448}
13449
b99bd4ef 13450static void
c19d1205 13451output_inst (const char * str)
b99bd4ef 13452{
c19d1205 13453 char * to = NULL;
b99bd4ef 13454
c19d1205 13455 if (inst.error)
b99bd4ef 13456 {
c19d1205 13457 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
13458 return;
13459 }
0110f2b8
PB
13460 if (inst.relax) {
13461 output_relax_insn();
13462 return;
13463 }
c19d1205
ZW
13464 if (inst.size == 0)
13465 return;
b99bd4ef 13466
c19d1205
ZW
13467 to = frag_more (inst.size);
13468
13469 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 13470 {
c19d1205 13471 assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 13472 put_thumb32_insn (to, inst.instruction);
b99bd4ef 13473 }
c19d1205 13474 else if (inst.size > INSN_SIZE)
b99bd4ef 13475 {
c19d1205
ZW
13476 assert (inst.size == (2 * INSN_SIZE));
13477 md_number_to_chars (to, inst.instruction, INSN_SIZE);
13478 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 13479 }
c19d1205
ZW
13480 else
13481 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 13482
c19d1205
ZW
13483 if (inst.reloc.type != BFD_RELOC_UNUSED)
13484 fix_new_arm (frag_now, to - frag_now->fr_literal,
13485 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
13486 inst.reloc.type);
b99bd4ef 13487
c19d1205 13488 dwarf2_emit_insn (inst.size);
c19d1205 13489}
b99bd4ef 13490
c19d1205
ZW
13491/* Tag values used in struct asm_opcode's tag field. */
13492enum opcode_tag
13493{
13494 OT_unconditional, /* Instruction cannot be conditionalized.
13495 The ARM condition field is still 0xE. */
13496 OT_unconditionalF, /* Instruction cannot be conditionalized
13497 and carries 0xF in its ARM condition field. */
13498 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
13499 OT_csuffixF, /* Some forms of the instruction take a conditional
13500 suffix, others place 0xF where the condition field
13501 would be. */
c19d1205
ZW
13502 OT_cinfix3, /* Instruction takes a conditional infix,
13503 beginning at character index 3. (In
13504 unified mode, it becomes a suffix.) */
088fa78e
KH
13505 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
13506 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
13507 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
13508 character index 3, even in unified mode. Used for
13509 legacy instructions where suffix and infix forms
13510 may be ambiguous. */
c19d1205 13511 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 13512 suffix or an infix at character index 3. */
c19d1205
ZW
13513 OT_odd_infix_unc, /* This is the unconditional variant of an
13514 instruction that takes a conditional infix
13515 at an unusual position. In unified mode,
13516 this variant will accept a suffix. */
13517 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
13518 are the conditional variants of instructions that
13519 take conditional infixes in unusual positions.
13520 The infix appears at character index
13521 (tag - OT_odd_infix_0). These are not accepted
13522 in unified mode. */
13523};
b99bd4ef 13524
c19d1205
ZW
13525/* Subroutine of md_assemble, responsible for looking up the primary
13526 opcode from the mnemonic the user wrote. STR points to the
13527 beginning of the mnemonic.
13528
13529 This is not simply a hash table lookup, because of conditional
13530 variants. Most instructions have conditional variants, which are
13531 expressed with a _conditional affix_ to the mnemonic. If we were
13532 to encode each conditional variant as a literal string in the opcode
13533 table, it would have approximately 20,000 entries.
13534
13535 Most mnemonics take this affix as a suffix, and in unified syntax,
13536 'most' is upgraded to 'all'. However, in the divided syntax, some
13537 instructions take the affix as an infix, notably the s-variants of
13538 the arithmetic instructions. Of those instructions, all but six
13539 have the infix appear after the third character of the mnemonic.
13540
13541 Accordingly, the algorithm for looking up primary opcodes given
13542 an identifier is:
13543
13544 1. Look up the identifier in the opcode table.
13545 If we find a match, go to step U.
13546
13547 2. Look up the last two characters of the identifier in the
13548 conditions table. If we find a match, look up the first N-2
13549 characters of the identifier in the opcode table. If we
13550 find a match, go to step CE.
13551
13552 3. Look up the fourth and fifth characters of the identifier in
13553 the conditions table. If we find a match, extract those
13554 characters from the identifier, and look up the remaining
13555 characters in the opcode table. If we find a match, go
13556 to step CM.
13557
13558 4. Fail.
13559
13560 U. Examine the tag field of the opcode structure, in case this is
13561 one of the six instructions with its conditional infix in an
13562 unusual place. If it is, the tag tells us where to find the
13563 infix; look it up in the conditions table and set inst.cond
13564 accordingly. Otherwise, this is an unconditional instruction.
13565 Again set inst.cond accordingly. Return the opcode structure.
13566
13567 CE. Examine the tag field to make sure this is an instruction that
13568 should receive a conditional suffix. If it is not, fail.
13569 Otherwise, set inst.cond from the suffix we already looked up,
13570 and return the opcode structure.
13571
13572 CM. Examine the tag field to make sure this is an instruction that
13573 should receive a conditional infix after the third character.
13574 If it is not, fail. Otherwise, undo the edits to the current
13575 line of input and proceed as for case CE. */
13576
13577static const struct asm_opcode *
13578opcode_lookup (char **str)
13579{
13580 char *end, *base;
13581 char *affix;
13582 const struct asm_opcode *opcode;
13583 const struct asm_cond *cond;
e3cb604e 13584 char save[2];
267d2029
JB
13585 bfd_boolean neon_supported;
13586
13587 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
13588
13589 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 13590 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 13591 for (base = end = *str; *end != '\0'; end++)
267d2029 13592 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 13593 break;
b99bd4ef 13594
c19d1205
ZW
13595 if (end == base)
13596 return 0;
b99bd4ef 13597
5287ad62 13598 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 13599 if (end[0] == '.')
b99bd4ef 13600 {
5287ad62
JB
13601 int offset = 2;
13602
267d2029
JB
13603 /* The .w and .n suffixes are only valid if the unified syntax is in
13604 use. */
13605 if (unified_syntax && end[1] == 'w')
c19d1205 13606 inst.size_req = 4;
267d2029 13607 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
13608 inst.size_req = 2;
13609 else
5287ad62
JB
13610 offset = 0;
13611
13612 inst.vectype.elems = 0;
13613
13614 *str = end + offset;
b99bd4ef 13615
5287ad62
JB
13616 if (end[offset] == '.')
13617 {
267d2029
JB
13618 /* See if we have a Neon type suffix (possible in either unified or
13619 non-unified ARM syntax mode). */
dcbf9037 13620 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
13621 return 0;
13622 }
13623 else if (end[offset] != '\0' && end[offset] != ' ')
13624 return 0;
b99bd4ef 13625 }
c19d1205
ZW
13626 else
13627 *str = end;
b99bd4ef 13628
c19d1205
ZW
13629 /* Look for unaffixed or special-case affixed mnemonic. */
13630 opcode = hash_find_n (arm_ops_hsh, base, end - base);
13631 if (opcode)
b99bd4ef 13632 {
c19d1205
ZW
13633 /* step U */
13634 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 13635 {
c19d1205
ZW
13636 inst.cond = COND_ALWAYS;
13637 return opcode;
b99bd4ef 13638 }
b99bd4ef 13639
c19d1205
ZW
13640 if (unified_syntax)
13641 as_warn (_("conditional infixes are deprecated in unified syntax"));
13642 affix = base + (opcode->tag - OT_odd_infix_0);
13643 cond = hash_find_n (arm_cond_hsh, affix, 2);
13644 assert (cond);
b99bd4ef 13645
c19d1205
ZW
13646 inst.cond = cond->value;
13647 return opcode;
13648 }
b99bd4ef 13649
c19d1205
ZW
13650 /* Cannot have a conditional suffix on a mnemonic of less than two
13651 characters. */
13652 if (end - base < 3)
13653 return 0;
b99bd4ef 13654
c19d1205
ZW
13655 /* Look for suffixed mnemonic. */
13656 affix = end - 2;
13657 cond = hash_find_n (arm_cond_hsh, affix, 2);
13658 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
13659 if (opcode && cond)
13660 {
13661 /* step CE */
13662 switch (opcode->tag)
13663 {
e3cb604e
PB
13664 case OT_cinfix3_legacy:
13665 /* Ignore conditional suffixes matched on infix only mnemonics. */
13666 break;
13667
c19d1205 13668 case OT_cinfix3:
088fa78e 13669 case OT_cinfix3_deprecated:
c19d1205
ZW
13670 case OT_odd_infix_unc:
13671 if (!unified_syntax)
e3cb604e 13672 return 0;
c19d1205
ZW
13673 /* else fall through */
13674
13675 case OT_csuffix:
037e8744 13676 case OT_csuffixF:
c19d1205
ZW
13677 case OT_csuf_or_in3:
13678 inst.cond = cond->value;
13679 return opcode;
13680
13681 case OT_unconditional:
13682 case OT_unconditionalF:
dfa9f0d5
PB
13683 if (thumb_mode)
13684 {
13685 inst.cond = cond->value;
13686 }
13687 else
13688 {
13689 /* delayed diagnostic */
13690 inst.error = BAD_COND;
13691 inst.cond = COND_ALWAYS;
13692 }
c19d1205 13693 return opcode;
b99bd4ef 13694
c19d1205
ZW
13695 default:
13696 return 0;
13697 }
13698 }
b99bd4ef 13699
c19d1205
ZW
13700 /* Cannot have a usual-position infix on a mnemonic of less than
13701 six characters (five would be a suffix). */
13702 if (end - base < 6)
13703 return 0;
b99bd4ef 13704
c19d1205
ZW
13705 /* Look for infixed mnemonic in the usual position. */
13706 affix = base + 3;
13707 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
13708 if (!cond)
13709 return 0;
13710
13711 memcpy (save, affix, 2);
13712 memmove (affix, affix + 2, (end - affix) - 2);
13713 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
13714 memmove (affix + 2, affix, (end - affix) - 2);
13715 memcpy (affix, save, 2);
13716
088fa78e
KH
13717 if (opcode
13718 && (opcode->tag == OT_cinfix3
13719 || opcode->tag == OT_cinfix3_deprecated
13720 || opcode->tag == OT_csuf_or_in3
13721 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 13722 {
c19d1205 13723 /* step CM */
088fa78e
KH
13724 if (unified_syntax
13725 && (opcode->tag == OT_cinfix3
13726 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
13727 as_warn (_("conditional infixes are deprecated in unified syntax"));
13728
13729 inst.cond = cond->value;
13730 return opcode;
b99bd4ef
NC
13731 }
13732
c19d1205 13733 return 0;
b99bd4ef
NC
13734}
13735
c19d1205
ZW
13736void
13737md_assemble (char *str)
b99bd4ef 13738{
c19d1205
ZW
13739 char *p = str;
13740 const struct asm_opcode * opcode;
b99bd4ef 13741
c19d1205
ZW
13742 /* Align the previous label if needed. */
13743 if (last_label_seen != NULL)
b99bd4ef 13744 {
c19d1205
ZW
13745 symbol_set_frag (last_label_seen, frag_now);
13746 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
13747 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
13748 }
13749
c19d1205
ZW
13750 memset (&inst, '\0', sizeof (inst));
13751 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 13752
c19d1205
ZW
13753 opcode = opcode_lookup (&p);
13754 if (!opcode)
b99bd4ef 13755 {
c19d1205 13756 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
13757 the form alias .req reg, or a Neon .dn/.qn directive. */
13758 if (!create_register_alias (str, p)
13759 && !create_neon_reg_alias (str, p))
c19d1205 13760 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 13761
b99bd4ef
NC
13762 return;
13763 }
13764
088fa78e
KH
13765 if (opcode->tag == OT_cinfix3_deprecated)
13766 as_warn (_("s suffix on comparison instruction is deprecated"));
13767
037e8744
JB
13768 /* The value which unconditional instructions should have in place of the
13769 condition field. */
13770 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
13771
c19d1205 13772 if (thumb_mode)
b99bd4ef 13773 {
e74cfd16 13774 arm_feature_set variant;
8f06b2d8
PB
13775
13776 variant = cpu_variant;
13777 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
13778 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
13779 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 13780 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
13781 if (!opcode->tvariant
13782 || (thumb_mode == 1
13783 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 13784 {
c19d1205 13785 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
13786 return;
13787 }
c19d1205
ZW
13788 if (inst.cond != COND_ALWAYS && !unified_syntax
13789 && opcode->tencode != do_t_branch)
b99bd4ef 13790 {
c19d1205 13791 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
13792 return;
13793 }
13794
e27ec89e
PB
13795 /* Check conditional suffixes. */
13796 if (current_it_mask)
13797 {
13798 int cond;
13799 cond = current_cc ^ ((current_it_mask >> 4) & 1) ^ 1;
dfa9f0d5
PB
13800 current_it_mask <<= 1;
13801 current_it_mask &= 0x1f;
13802 /* The BKPT instruction is unconditional even in an IT block. */
13803 if (!inst.error
13804 && cond != inst.cond && opcode->tencode != do_t_bkpt)
e27ec89e
PB
13805 {
13806 as_bad (_("incorrect condition in IT block"));
13807 return;
13808 }
e27ec89e
PB
13809 }
13810 else if (inst.cond != COND_ALWAYS && opcode->tencode != do_t_branch)
13811 {
13812 as_bad (_("thumb conditional instrunction not in IT block"));
13813 return;
13814 }
13815
c19d1205
ZW
13816 mapping_state (MAP_THUMB);
13817 inst.instruction = opcode->tvalue;
13818
13819 if (!parse_operands (p, opcode->operands))
13820 opcode->tencode ();
13821
e27ec89e
PB
13822 /* Clear current_it_mask at the end of an IT block. */
13823 if (current_it_mask == 0x10)
13824 current_it_mask = 0;
13825
0110f2b8 13826 if (!(inst.error || inst.relax))
b99bd4ef 13827 {
c19d1205
ZW
13828 assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
13829 inst.size = (inst.instruction > 0xffff ? 4 : 2);
13830 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 13831 {
c19d1205 13832 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
13833 return;
13834 }
13835 }
e74cfd16
PB
13836 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13837 *opcode->tvariant);
ee065d83 13838 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 13839 set those bits when Thumb-2 32-bit instructions are seen. ie.
ee065d83
PB
13840 anything other than bl/blx.
13841 This is overly pessimistic for relaxable instructions. */
13842 if ((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
13843 || inst.relax)
e74cfd16
PB
13844 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
13845 arm_ext_v6t2);
c19d1205 13846 }
3e9e4fcf 13847 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
13848 {
13849 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
13850 if (!opcode->avariant ||
13851 !ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant))
b99bd4ef 13852 {
c19d1205
ZW
13853 as_bad (_("selected processor does not support `%s'"), str);
13854 return;
b99bd4ef 13855 }
c19d1205 13856 if (inst.size_req)
b99bd4ef 13857 {
c19d1205
ZW
13858 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
13859 return;
b99bd4ef
NC
13860 }
13861
c19d1205
ZW
13862 mapping_state (MAP_ARM);
13863 inst.instruction = opcode->avalue;
13864 if (opcode->tag == OT_unconditionalF)
13865 inst.instruction |= 0xF << 28;
13866 else
13867 inst.instruction |= inst.cond << 28;
13868 inst.size = INSN_SIZE;
13869 if (!parse_operands (p, opcode->operands))
13870 opcode->aencode ();
ee065d83
PB
13871 /* Arm mode bx is marked as both v4T and v5 because it's still required
13872 on a hypothetical non-thumb v5 core. */
e74cfd16
PB
13873 if (ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v4t)
13874 || ARM_CPU_HAS_FEATURE (*opcode->avariant, arm_ext_v5))
13875 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 13876 else
e74cfd16
PB
13877 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
13878 *opcode->avariant);
b99bd4ef 13879 }
3e9e4fcf
JB
13880 else
13881 {
13882 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
13883 "-- `%s'"), str);
13884 return;
13885 }
c19d1205
ZW
13886 output_inst (str);
13887}
b99bd4ef 13888
c19d1205
ZW
13889/* Various frobbings of labels and their addresses. */
13890
13891void
13892arm_start_line_hook (void)
13893{
13894 last_label_seen = NULL;
b99bd4ef
NC
13895}
13896
c19d1205
ZW
13897void
13898arm_frob_label (symbolS * sym)
b99bd4ef 13899{
c19d1205 13900 last_label_seen = sym;
b99bd4ef 13901
c19d1205 13902 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 13903
c19d1205
ZW
13904#if defined OBJ_COFF || defined OBJ_ELF
13905 ARM_SET_INTERWORK (sym, support_interwork);
13906#endif
b99bd4ef 13907
c19d1205
ZW
13908 /* Note - do not allow local symbols (.Lxxx) to be labeled
13909 as Thumb functions. This is because these labels, whilst
13910 they exist inside Thumb code, are not the entry points for
13911 possible ARM->Thumb calls. Also, these labels can be used
13912 as part of a computed goto or switch statement. eg gcc
13913 can generate code that looks like this:
b99bd4ef 13914
c19d1205
ZW
13915 ldr r2, [pc, .Laaa]
13916 lsl r3, r3, #2
13917 ldr r2, [r3, r2]
13918 mov pc, r2
b99bd4ef 13919
c19d1205
ZW
13920 .Lbbb: .word .Lxxx
13921 .Lccc: .word .Lyyy
13922 ..etc...
13923 .Laaa: .word Lbbb
b99bd4ef 13924
c19d1205
ZW
13925 The first instruction loads the address of the jump table.
13926 The second instruction converts a table index into a byte offset.
13927 The third instruction gets the jump address out of the table.
13928 The fourth instruction performs the jump.
b99bd4ef 13929
c19d1205
ZW
13930 If the address stored at .Laaa is that of a symbol which has the
13931 Thumb_Func bit set, then the linker will arrange for this address
13932 to have the bottom bit set, which in turn would mean that the
13933 address computation performed by the third instruction would end
13934 up with the bottom bit set. Since the ARM is capable of unaligned
13935 word loads, the instruction would then load the incorrect address
13936 out of the jump table, and chaos would ensue. */
13937 if (label_is_thumb_function_name
13938 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
13939 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 13940 {
c19d1205
ZW
13941 /* When the address of a Thumb function is taken the bottom
13942 bit of that address should be set. This will allow
13943 interworking between Arm and Thumb functions to work
13944 correctly. */
b99bd4ef 13945
c19d1205 13946 THUMB_SET_FUNC (sym, 1);
b99bd4ef 13947
c19d1205 13948 label_is_thumb_function_name = FALSE;
b99bd4ef 13949 }
07a53e5c 13950
07a53e5c 13951 dwarf2_emit_label (sym);
b99bd4ef
NC
13952}
13953
c19d1205
ZW
13954int
13955arm_data_in_code (void)
b99bd4ef 13956{
c19d1205 13957 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 13958 {
c19d1205
ZW
13959 *input_line_pointer = '/';
13960 input_line_pointer += 5;
13961 *input_line_pointer = 0;
13962 return 1;
b99bd4ef
NC
13963 }
13964
c19d1205 13965 return 0;
b99bd4ef
NC
13966}
13967
c19d1205
ZW
13968char *
13969arm_canonicalize_symbol_name (char * name)
b99bd4ef 13970{
c19d1205 13971 int len;
b99bd4ef 13972
c19d1205
ZW
13973 if (thumb_mode && (len = strlen (name)) > 5
13974 && streq (name + len - 5, "/data"))
13975 *(name + len - 5) = 0;
b99bd4ef 13976
c19d1205 13977 return name;
b99bd4ef 13978}
c19d1205
ZW
13979\f
13980/* Table of all register names defined by default. The user can
13981 define additional names with .req. Note that all register names
13982 should appear in both upper and lowercase variants. Some registers
13983 also have mixed-case names. */
b99bd4ef 13984
dcbf9037 13985#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 13986#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 13987#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
13988#define REGSET(p,t) \
13989 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
13990 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
13991 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
13992 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
13993#define REGSETH(p,t) \
13994 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
13995 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
13996 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
13997 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
13998#define REGSET2(p,t) \
13999 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
14000 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
14001 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
14002 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 14003
c19d1205 14004static const struct reg_entry reg_names[] =
7ed4c4c5 14005{
c19d1205
ZW
14006 /* ARM integer registers. */
14007 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 14008
c19d1205
ZW
14009 /* ATPCS synonyms. */
14010 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
14011 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
14012 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 14013
c19d1205
ZW
14014 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
14015 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
14016 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 14017
c19d1205
ZW
14018 /* Well-known aliases. */
14019 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
14020 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
14021
14022 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
14023 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
14024
14025 /* Coprocessor numbers. */
14026 REGSET(p, CP), REGSET(P, CP),
14027
14028 /* Coprocessor register numbers. The "cr" variants are for backward
14029 compatibility. */
14030 REGSET(c, CN), REGSET(C, CN),
14031 REGSET(cr, CN), REGSET(CR, CN),
14032
14033 /* FPA registers. */
14034 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
14035 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
14036
14037 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
14038 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
14039
14040 /* VFP SP registers. */
5287ad62
JB
14041 REGSET(s,VFS), REGSET(S,VFS),
14042 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
14043
14044 /* VFP DP Registers. */
5287ad62
JB
14045 REGSET(d,VFD), REGSET(D,VFD),
14046 /* Extra Neon DP registers. */
14047 REGSETH(d,VFD), REGSETH(D,VFD),
14048
14049 /* Neon QP registers. */
14050 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
14051
14052 /* VFP control registers. */
14053 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
14054 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
14055
14056 /* Maverick DSP coprocessor registers. */
14057 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
14058 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
14059
14060 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
14061 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
14062 REGDEF(dspsc,0,DSPSC),
14063
14064 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
14065 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
14066 REGDEF(DSPSC,0,DSPSC),
14067
14068 /* iWMMXt data registers - p0, c0-15. */
14069 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
14070
14071 /* iWMMXt control registers - p1, c0-3. */
14072 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
14073 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
14074 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
14075 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
14076
14077 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
14078 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
14079 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
14080 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
14081 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
14082
14083 /* XScale accumulator registers. */
14084 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
14085};
14086#undef REGDEF
14087#undef REGNUM
14088#undef REGSET
7ed4c4c5 14089
c19d1205
ZW
14090/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
14091 within psr_required_here. */
14092static const struct asm_psr psrs[] =
14093{
14094 /* Backward compatibility notation. Note that "all" is no longer
14095 truly all possible PSR bits. */
14096 {"all", PSR_c | PSR_f},
14097 {"flg", PSR_f},
14098 {"ctl", PSR_c},
14099
14100 /* Individual flags. */
14101 {"f", PSR_f},
14102 {"c", PSR_c},
14103 {"x", PSR_x},
14104 {"s", PSR_s},
14105 /* Combinations of flags. */
14106 {"fs", PSR_f | PSR_s},
14107 {"fx", PSR_f | PSR_x},
14108 {"fc", PSR_f | PSR_c},
14109 {"sf", PSR_s | PSR_f},
14110 {"sx", PSR_s | PSR_x},
14111 {"sc", PSR_s | PSR_c},
14112 {"xf", PSR_x | PSR_f},
14113 {"xs", PSR_x | PSR_s},
14114 {"xc", PSR_x | PSR_c},
14115 {"cf", PSR_c | PSR_f},
14116 {"cs", PSR_c | PSR_s},
14117 {"cx", PSR_c | PSR_x},
14118 {"fsx", PSR_f | PSR_s | PSR_x},
14119 {"fsc", PSR_f | PSR_s | PSR_c},
14120 {"fxs", PSR_f | PSR_x | PSR_s},
14121 {"fxc", PSR_f | PSR_x | PSR_c},
14122 {"fcs", PSR_f | PSR_c | PSR_s},
14123 {"fcx", PSR_f | PSR_c | PSR_x},
14124 {"sfx", PSR_s | PSR_f | PSR_x},
14125 {"sfc", PSR_s | PSR_f | PSR_c},
14126 {"sxf", PSR_s | PSR_x | PSR_f},
14127 {"sxc", PSR_s | PSR_x | PSR_c},
14128 {"scf", PSR_s | PSR_c | PSR_f},
14129 {"scx", PSR_s | PSR_c | PSR_x},
14130 {"xfs", PSR_x | PSR_f | PSR_s},
14131 {"xfc", PSR_x | PSR_f | PSR_c},
14132 {"xsf", PSR_x | PSR_s | PSR_f},
14133 {"xsc", PSR_x | PSR_s | PSR_c},
14134 {"xcf", PSR_x | PSR_c | PSR_f},
14135 {"xcs", PSR_x | PSR_c | PSR_s},
14136 {"cfs", PSR_c | PSR_f | PSR_s},
14137 {"cfx", PSR_c | PSR_f | PSR_x},
14138 {"csf", PSR_c | PSR_s | PSR_f},
14139 {"csx", PSR_c | PSR_s | PSR_x},
14140 {"cxf", PSR_c | PSR_x | PSR_f},
14141 {"cxs", PSR_c | PSR_x | PSR_s},
14142 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
14143 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
14144 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
14145 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
14146 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
14147 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
14148 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
14149 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
14150 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
14151 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
14152 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
14153 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
14154 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
14155 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
14156 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
14157 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
14158 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
14159 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
14160 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
14161 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
14162 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
14163 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
14164 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
14165 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
14166};
14167
62b3e311
PB
14168/* Table of V7M psr names. */
14169static const struct asm_psr v7m_psrs[] =
14170{
14171 {"apsr", 0 },
14172 {"iapsr", 1 },
14173 {"eapsr", 2 },
14174 {"psr", 3 },
14175 {"ipsr", 5 },
14176 {"epsr", 6 },
14177 {"iepsr", 7 },
14178 {"msp", 8 },
14179 {"psp", 9 },
14180 {"primask", 16},
14181 {"basepri", 17},
14182 {"basepri_max", 18},
14183 {"faultmask", 19},
14184 {"control", 20}
14185};
14186
c19d1205
ZW
14187/* Table of all shift-in-operand names. */
14188static const struct asm_shift_name shift_names [] =
b99bd4ef 14189{
c19d1205
ZW
14190 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
14191 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
14192 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
14193 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
14194 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
14195 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
14196};
b99bd4ef 14197
c19d1205
ZW
14198/* Table of all explicit relocation names. */
14199#ifdef OBJ_ELF
14200static struct reloc_entry reloc_names[] =
14201{
14202 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
14203 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
14204 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
14205 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
14206 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
14207 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
14208 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
14209 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
14210 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
14211 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
14212 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
14213};
14214#endif
b99bd4ef 14215
c19d1205
ZW
14216/* Table of all conditional affixes. 0xF is not defined as a condition code. */
14217static const struct asm_cond conds[] =
14218{
14219 {"eq", 0x0},
14220 {"ne", 0x1},
14221 {"cs", 0x2}, {"hs", 0x2},
14222 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
14223 {"mi", 0x4},
14224 {"pl", 0x5},
14225 {"vs", 0x6},
14226 {"vc", 0x7},
14227 {"hi", 0x8},
14228 {"ls", 0x9},
14229 {"ge", 0xa},
14230 {"lt", 0xb},
14231 {"gt", 0xc},
14232 {"le", 0xd},
14233 {"al", 0xe}
14234};
bfae80f2 14235
62b3e311
PB
14236static struct asm_barrier_opt barrier_opt_names[] =
14237{
14238 { "sy", 0xf },
14239 { "un", 0x7 },
14240 { "st", 0xe },
14241 { "unst", 0x6 }
14242};
14243
c19d1205
ZW
14244/* Table of ARM-format instructions. */
14245
14246/* Macros for gluing together operand strings. N.B. In all cases
14247 other than OPS0, the trailing OP_stop comes from default
14248 zero-initialization of the unspecified elements of the array. */
14249#define OPS0() { OP_stop, }
14250#define OPS1(a) { OP_##a, }
14251#define OPS2(a,b) { OP_##a,OP_##b, }
14252#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
14253#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
14254#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
14255#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
14256
14257/* These macros abstract out the exact format of the mnemonic table and
14258 save some repeated characters. */
14259
14260/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
14261#define TxCE(mnem, op, top, nops, ops, ae, te) \
14262 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 14263 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14264
14265/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
14266 a T_MNEM_xyz enumerator. */
14267#define TCE(mnem, aop, top, nops, ops, ae, te) \
14268 TxCE(mnem, aop, 0x##top, nops, ops, ae, te)
14269#define tCE(mnem, aop, top, nops, ops, ae, te) \
14270 TxCE(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
14271
14272/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
14273 infix after the third character. */
14274#define TxC3(mnem, op, top, nops, ops, ae, te) \
14275 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 14276 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
14277#define TxC3w(mnem, op, top, nops, ops, ae, te) \
14278 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
14279 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14280#define TC3(mnem, aop, top, nops, ops, ae, te) \
14281 TxC3(mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e
KH
14282#define TC3w(mnem, aop, top, nops, ops, ae, te) \
14283 TxC3w(mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205
ZW
14284#define tC3(mnem, aop, top, nops, ops, ae, te) \
14285 TxC3(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e
KH
14286#define tC3w(mnem, aop, top, nops, ops, ae, te) \
14287 TxC3w(mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
14288
14289/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
14290 appear in the condition table. */
14291#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
14292 { #m1 #m2 #m3, OPS##nops ops, sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
1887dd22 14293 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14294
14295#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
14296 TxCM_(m1, , m2, op, top, nops, ops, ae, te), \
14297 TxCM_(m1, eq, m2, op, top, nops, ops, ae, te), \
14298 TxCM_(m1, ne, m2, op, top, nops, ops, ae, te), \
14299 TxCM_(m1, cs, m2, op, top, nops, ops, ae, te), \
14300 TxCM_(m1, hs, m2, op, top, nops, ops, ae, te), \
14301 TxCM_(m1, cc, m2, op, top, nops, ops, ae, te), \
14302 TxCM_(m1, ul, m2, op, top, nops, ops, ae, te), \
14303 TxCM_(m1, lo, m2, op, top, nops, ops, ae, te), \
14304 TxCM_(m1, mi, m2, op, top, nops, ops, ae, te), \
14305 TxCM_(m1, pl, m2, op, top, nops, ops, ae, te), \
14306 TxCM_(m1, vs, m2, op, top, nops, ops, ae, te), \
14307 TxCM_(m1, vc, m2, op, top, nops, ops, ae, te), \
14308 TxCM_(m1, hi, m2, op, top, nops, ops, ae, te), \
14309 TxCM_(m1, ls, m2, op, top, nops, ops, ae, te), \
14310 TxCM_(m1, ge, m2, op, top, nops, ops, ae, te), \
14311 TxCM_(m1, lt, m2, op, top, nops, ops, ae, te), \
14312 TxCM_(m1, gt, m2, op, top, nops, ops, ae, te), \
14313 TxCM_(m1, le, m2, op, top, nops, ops, ae, te), \
14314 TxCM_(m1, al, m2, op, top, nops, ops, ae, te)
14315
14316#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
14317 TxCM(m1,m2, aop, 0x##top, nops, ops, ae, te)
14318#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
14319 TxCM(m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
14320
14321/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
14322 field is still 0xE. Many of the Thumb variants can be executed
14323 conditionally, so this is checked separately. */
c19d1205
ZW
14324#define TUE(mnem, op, top, nops, ops, ae, te) \
14325 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14326 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14327
14328/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
14329 condition code field. */
14330#define TUF(mnem, op, top, nops, ops, ae, te) \
14331 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 14332 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
14333
14334/* ARM-only variants of all the above. */
6a86118a
NC
14335#define CE(mnem, op, nops, ops, ae) \
14336 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14337
14338#define C3(mnem, op, nops, ops, ae) \
14339 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14340
e3cb604e
PB
14341/* Legacy mnemonics that always have conditional infix after the third
14342 character. */
14343#define CL(mnem, op, nops, ops, ae) \
14344 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14345 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14346
8f06b2d8
PB
14347/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
14348#define cCE(mnem, op, nops, ops, ae) \
14349 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14350
e3cb604e
PB
14351/* Legacy coprocessor instructions where conditional infix and conditional
14352 suffix are ambiguous. For consistency this includes all FPA instructions,
14353 not just the potentially ambiguous ones. */
14354#define cCL(mnem, op, nops, ops, ae) \
14355 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
14356 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
14357
14358/* Coprocessor, takes either a suffix or a position-3 infix
14359 (for an FPA corner case). */
14360#define C3E(mnem, op, nops, ops, ae) \
14361 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
14362 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 14363
6a86118a
NC
14364#define xCM_(m1, m2, m3, op, nops, ops, ae) \
14365 { #m1 #m2 #m3, OPS##nops ops, \
14366 sizeof(#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof(#m1) - 1, \
14367 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
14368
14369#define CM(m1, m2, op, nops, ops, ae) \
14370 xCM_(m1, , m2, op, nops, ops, ae), \
14371 xCM_(m1, eq, m2, op, nops, ops, ae), \
14372 xCM_(m1, ne, m2, op, nops, ops, ae), \
14373 xCM_(m1, cs, m2, op, nops, ops, ae), \
14374 xCM_(m1, hs, m2, op, nops, ops, ae), \
14375 xCM_(m1, cc, m2, op, nops, ops, ae), \
14376 xCM_(m1, ul, m2, op, nops, ops, ae), \
14377 xCM_(m1, lo, m2, op, nops, ops, ae), \
14378 xCM_(m1, mi, m2, op, nops, ops, ae), \
14379 xCM_(m1, pl, m2, op, nops, ops, ae), \
14380 xCM_(m1, vs, m2, op, nops, ops, ae), \
14381 xCM_(m1, vc, m2, op, nops, ops, ae), \
14382 xCM_(m1, hi, m2, op, nops, ops, ae), \
14383 xCM_(m1, ls, m2, op, nops, ops, ae), \
14384 xCM_(m1, ge, m2, op, nops, ops, ae), \
14385 xCM_(m1, lt, m2, op, nops, ops, ae), \
14386 xCM_(m1, gt, m2, op, nops, ops, ae), \
14387 xCM_(m1, le, m2, op, nops, ops, ae), \
14388 xCM_(m1, al, m2, op, nops, ops, ae)
14389
14390#define UE(mnem, op, nops, ops, ae) \
14391 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14392
14393#define UF(mnem, op, nops, ops, ae) \
14394 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
14395
5287ad62
JB
14396/* Neon data-processing. ARM versions are unconditional with cond=0xf.
14397 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
14398 use the same encoding function for each. */
14399#define NUF(mnem, op, nops, ops, enc) \
14400 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
14401 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14402
14403/* Neon data processing, version which indirects through neon_enc_tab for
14404 the various overloaded versions of opcodes. */
14405#define nUF(mnem, op, nops, ops, enc) \
14406 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
14407 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14408
14409/* Neon insn with conditional suffix for the ARM version, non-overloaded
14410 version. */
037e8744
JB
14411#define NCE_tag(mnem, op, nops, ops, enc, tag) \
14412 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
14413 THUMB_VARIANT, do_##enc, do_##enc }
14414
037e8744
JB
14415#define NCE(mnem, op, nops, ops, enc) \
14416 NCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14417
14418#define NCEF(mnem, op, nops, ops, enc) \
14419 NCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14420
5287ad62 14421/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
14422#define nCE_tag(mnem, op, nops, ops, enc, tag) \
14423 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
14424 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
14425
037e8744
JB
14426#define nCE(mnem, op, nops, ops, enc) \
14427 nCE_tag(mnem, op, nops, ops, enc, OT_csuffix)
14428
14429#define nCEF(mnem, op, nops, ops, enc) \
14430 nCE_tag(mnem, op, nops, ops, enc, OT_csuffixF)
14431
c19d1205
ZW
14432#define do_0 0
14433
14434/* Thumb-only, unconditional. */
14435#define UT(mnem, op, nops, ops, te) TUE(mnem, 0, op, nops, ops, 0, te)
14436
c19d1205 14437static const struct asm_opcode insns[] =
bfae80f2 14438{
e74cfd16
PB
14439#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
14440#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14441 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
14442 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
14443 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
14444 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
14445 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
14446 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
14447 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
14448 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
14449 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
14450 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
14451 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
14452 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
14453 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
14454 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
14455 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
14456 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
14457
14458 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
14459 for setting PSR flag bits. They are obsolete in V6 and do not
14460 have Thumb equivalents. */
14461 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14462 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14463 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 14464 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 14465 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 14466 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 14467 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14468 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14469 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
14470
14471 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
14472 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
14473 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
14474 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
14475
4962c51a
MS
14476 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
14477 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
14478 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
14479 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 14480
f5208ef2 14481 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14482 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14483 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 14484 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14485 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14486 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14487
14488 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 14489 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 14490 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 14491 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 14492
c19d1205 14493 /* Pseudo ops. */
e9f89963 14494 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
14495 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
14496 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
14497
14498 /* Thumb-compatibility pseudo ops. */
14499 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
14500 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
14501 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
14502 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
14503 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 14504 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
14505 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
14506 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
14507 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
14508 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
14509 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
14510 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
14511
14512#undef THUMB_VARIANT
e74cfd16 14513#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 14514 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
14515
14516 /* V1 instructions with no Thumb analogue prior to V6T2. */
14517#undef THUMB_VARIANT
e74cfd16 14518#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14519 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
14520 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
14521 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 14522 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 14523 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
14524
14525 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14526 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14527 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 14528 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 14529
9c3c69f2
PB
14530 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14531 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 14532
9c3c69f2
PB
14533 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
14534 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
14535
14536 /* V1 instructions with no Thumb analogue at all. */
14537 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
14538 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
14539
14540 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
14541 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
14542 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
14543 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
14544 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
14545 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
14546 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
14547 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
14548
14549#undef ARM_VARIANT
e74cfd16 14550#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 14551#undef THUMB_VARIANT
e74cfd16 14552#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
14553 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14554 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
14555
14556#undef THUMB_VARIANT
e74cfd16 14557#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14558 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
14559 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
14560
14561 /* Generic coprocessor instructions. */
14562 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
14563 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14564 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14565 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14566 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
14567 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14568 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14569
14570#undef ARM_VARIANT
e74cfd16 14571#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
14572 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14573 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
14574
14575#undef ARM_VARIANT
e74cfd16 14576#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
037e8744
JB
14577 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
14578 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
14579
14580#undef ARM_VARIANT
e74cfd16 14581#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
c19d1205
ZW
14582 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14583 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14584 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14585 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14586 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14587 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14588 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
14589 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
14590
14591#undef ARM_VARIANT
e74cfd16 14592#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 14593#undef THUMB_VARIANT
e74cfd16 14594#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
14595 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14596 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14597 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14598 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14599 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
14600 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
14601
14602#undef ARM_VARIANT
e74cfd16 14603#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
14604 /* ARM Architecture 4T. */
14605 /* Note: bx (and blx) are required on V5, even if the processor does
14606 not support Thumb. */
14607 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
14608
14609#undef ARM_VARIANT
e74cfd16 14610#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 14611#undef THUMB_VARIANT
e74cfd16 14612#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
14613 /* Note: blx has 2 variants; the .value coded here is for
14614 BLX(2). Only this variant has conditional execution. */
14615 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
14616 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
14617
14618#undef THUMB_VARIANT
e74cfd16 14619#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 14620 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
14621 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14622 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14623 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
14624 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
14625 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
14626 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14627 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
14628
14629#undef ARM_VARIANT
e74cfd16 14630#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
14631 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14632 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14633 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14634 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14635
14636 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14637 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
14638
14639 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14640 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14641 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14642 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
14643
14644 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14645 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14646 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14647 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14648
14649 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14650 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14651
14652 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14653 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14654 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14655 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, rd_rm_rn),
14656
14657#undef ARM_VARIANT
e74cfd16 14658#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 14659 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
4962c51a
MS
14660 TC3(ldrd, 00000d0, e9500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
14661 TC3(strd, 00000f0, e9400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
14662
14663 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14664 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14665
14666#undef ARM_VARIANT
e74cfd16 14667#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
14668 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
14669
14670#undef ARM_VARIANT
e74cfd16 14671#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 14672#undef THUMB_VARIANT
e74cfd16 14673#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
14674 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
14675 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
14676 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14677 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14678 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
14679 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14680 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14681 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14682 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14683 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
14684
14685#undef THUMB_VARIANT
e74cfd16 14686#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14687 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
14688 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
14689 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
14690
14691 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
14692 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
14693
14694/* ARM V6 not included in V7M (eg. integer SIMD). */
14695#undef THUMB_VARIANT
14696#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 14697 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
14698 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
14699 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
14700 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14701 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14702 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14703 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14704 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14705 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14706 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14707 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14708 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14709 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14710 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14711 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14712 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14713 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14714 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14715 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14716 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14717 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14718 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14719 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14720 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14721 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14722 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14723 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14724 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14725 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14726 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14727 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14728 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14729 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14730 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14731 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14732 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14733 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14734 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14735 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
14736 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14737 UF(rfeib, 9900a00, 1, (RRw), rfe),
14738 UF(rfeda, 8100a00, 1, (RRw), rfe),
14739 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14740 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
14741 UF(rfefa, 9900a00, 1, (RRw), rfe),
14742 UF(rfeea, 8100a00, 1, (RRw), rfe),
14743 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
14744 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14745 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14746 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14747 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
14748 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14749 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14750 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
14751 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 14752 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
14753 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14754 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14755 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14756 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14757 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14758 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14759 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14760 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
14761 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14762 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14763 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14764 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
14765 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14766 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14767 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14768 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14769 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14770 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14771 TUF(srsia, 8cd0500, e980c000, 1, (I31w), srs, srs),
14772 UF(srsib, 9cd0500, 1, (I31w), srs),
14773 UF(srsda, 84d0500, 1, (I31w), srs),
14774 TUF(srsdb, 94d0500, e800c000, 1, (I31w), srs, srs),
c19d1205
ZW
14775 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
14776 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
14777 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
14778 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
14779 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
14780 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
14781
14782#undef ARM_VARIANT
e74cfd16 14783#define ARM_VARIANT &arm_ext_v6k
c19d1205 14784#undef THUMB_VARIANT
e74cfd16 14785#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
14786 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
14787 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
14788 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
14789 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
14790
ebdca51a
PB
14791#undef THUMB_VARIANT
14792#define THUMB_VARIANT &arm_ext_v6_notm
14793 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
14794 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
14795
c19d1205 14796#undef THUMB_VARIANT
e74cfd16 14797#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
14798 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
14799 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
14800 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
14801 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
14802 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
14803
14804#undef ARM_VARIANT
e74cfd16 14805#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 14806 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
14807
14808#undef ARM_VARIANT
e74cfd16 14809#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
14810 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
14811 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
14812 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14813 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
14814
14815 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
14816 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
14817 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 14818 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
14819
14820 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14821 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14822 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14823 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
14824
14825 UT(cbnz, b900, 2, (RR, EXP), t_czb),
14826 UT(cbz, b100, 2, (RR, EXP), t_czb),
14827 /* ARM does not really have an IT instruction. */
14828 TUE(it, 0, bf08, 1, (COND), it, t_it),
14829 TUE(itt, 0, bf0c, 1, (COND), it, t_it),
14830 TUE(ite, 0, bf04, 1, (COND), it, t_it),
14831 TUE(ittt, 0, bf0e, 1, (COND), it, t_it),
14832 TUE(itet, 0, bf06, 1, (COND), it, t_it),
14833 TUE(itte, 0, bf0a, 1, (COND), it, t_it),
14834 TUE(itee, 0, bf02, 1, (COND), it, t_it),
14835 TUE(itttt, 0, bf0f, 1, (COND), it, t_it),
14836 TUE(itett, 0, bf07, 1, (COND), it, t_it),
14837 TUE(ittet, 0, bf0b, 1, (COND), it, t_it),
14838 TUE(iteet, 0, bf03, 1, (COND), it, t_it),
14839 TUE(ittte, 0, bf0d, 1, (COND), it, t_it),
14840 TUE(itete, 0, bf05, 1, (COND), it, t_it),
14841 TUE(ittee, 0, bf09, 1, (COND), it, t_it),
14842 TUE(iteee, 0, bf01, 1, (COND), it, t_it),
14843
92e90b6e
PB
14844 /* Thumb2 only instructions. */
14845#undef ARM_VARIANT
e74cfd16 14846#define ARM_VARIANT NULL
92e90b6e
PB
14847
14848 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14849 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
14850 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
14851 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
14852
62b3e311
PB
14853 /* Thumb-2 hardware division instructions (R and M profiles only). */
14854#undef THUMB_VARIANT
14855#define THUMB_VARIANT &arm_ext_div
14856 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
14857 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
14858
14859 /* ARM V7 instructions. */
14860#undef ARM_VARIANT
14861#define ARM_VARIANT &arm_ext_v7
14862#undef THUMB_VARIANT
14863#define THUMB_VARIANT &arm_ext_v7
14864 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
14865 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
14866 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
14867 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
14868 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
14869
c19d1205 14870#undef ARM_VARIANT
e74cfd16 14871#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
14872 cCE(wfs, e200110, 1, (RR), rd),
14873 cCE(rfs, e300110, 1, (RR), rd),
14874 cCE(wfc, e400110, 1, (RR), rd),
14875 cCE(rfc, e500110, 1, (RR), rd),
14876
4962c51a
MS
14877 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
14878 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
14879 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
14880 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 14881
4962c51a
MS
14882 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
14883 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
14884 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
14885 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
14886
14887 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
14888 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
14889 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
14890 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
14891 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
14892 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
14893 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
14894 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
14895 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
14896 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
14897 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
14898 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
14899
14900 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
14901 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
14902 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
14903 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
14904 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
14905 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
14906 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
14907 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
14908 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
14909 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
14910 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
14911 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
14912
14913 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
14914 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
14915 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
14916 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
14917 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
14918 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
14919 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
14920 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
14921 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
14922 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
14923 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
14924 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
14925
14926 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
14927 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
14928 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
14929 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
14930 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
14931 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
14932 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
14933 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
14934 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
14935 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
14936 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
14937 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
14938
14939 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
14940 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
14941 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
14942 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
14943 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
14944 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
14945 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
14946 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
14947 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
14948 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
14949 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
14950 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
14951
14952 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
14953 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
14954 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
14955 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
14956 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
14957 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
14958 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
14959 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
14960 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
14961 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
14962 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
14963 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
14964
14965 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
14966 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
14967 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
14968 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
14969 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
14970 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
14971 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
14972 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
14973 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
14974 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
14975 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
14976 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
14977
14978 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
14979 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
14980 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
14981 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
14982 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
14983 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
14984 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
14985 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
14986 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
14987 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
14988 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
14989 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
14990
14991 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
14992 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
14993 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
14994 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
14995 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
14996 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
14997 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
14998 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
14999 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
15000 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
15001 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
15002 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
15003
15004 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
15005 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
15006 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
15007 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
15008 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
15009 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
15010 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
15011 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
15012 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
15013 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
15014 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
15015 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
15016
15017 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
15018 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
15019 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
15020 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
15021 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
15022 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
15023 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
15024 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
15025 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
15026 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
15027 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
15028 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
15029
15030 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
15031 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
15032 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
15033 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
15034 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
15035 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
15036 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
15037 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
15038 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
15039 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
15040 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
15041 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
15042
15043 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
15044 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
15045 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
15046 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
15047 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
15048 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
15049 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
15050 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
15051 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
15052 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
15053 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
15054 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
15055
15056 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
15057 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
15058 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
15059 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
15060 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
15061 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
15062 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
15063 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
15064 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
15065 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
15066 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
15067 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
15068
15069 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
15070 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
15071 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
15072 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
15073 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
15074 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
15075 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
15076 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
15077 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
15078 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
15079 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
15080 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
15081
15082 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
15083 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
15084 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
15085 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
15086 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
15087 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
15088 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
15089 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
15090 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
15091 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
15092 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
15093 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
15094
15095 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
15096 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
15097 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
15098 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
15099 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
15100 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15101 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15102 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15103 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
15104 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
15105 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
15106 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
15107
15108 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
15109 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
15110 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
15111 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
15112 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
15113 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15114 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15115 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15116 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
15117 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
15118 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
15119 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
15120
15121 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
15122 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
15123 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
15124 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
15125 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
15126 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15127 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15128 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15129 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
15130 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
15131 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
15132 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
15133
15134 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
15135 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
15136 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
15137 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
15138 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
15139 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15140 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15141 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15142 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
15143 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
15144 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
15145 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
15146
15147 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
15148 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
15149 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
15150 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
15151 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
15152 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15153 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15154 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15155 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
15156 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
15157 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
15158 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
15159
15160 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
15161 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
15162 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
15163 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
15164 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
15165 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15166 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15167 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15168 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
15169 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
15170 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
15171 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
15172
15173 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
15174 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
15175 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
15176 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
15177 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
15178 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15179 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15180 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15181 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
15182 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
15183 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
15184 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
15185
15186 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
15187 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
15188 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
15189 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
15190 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
15191 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15192 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15193 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15194 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
15195 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
15196 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
15197 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
15198
15199 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
15200 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
15201 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
15202 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
15203 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
15204 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15205 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15206 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15207 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
15208 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
15209 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
15210 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
15211
15212 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
15213 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
15214 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
15215 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
15216 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
15217 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15218 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15219 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15220 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
15221 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
15222 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
15223 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
15224
15225 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15226 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15227 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15228 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15229 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15230 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15231 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15232 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15233 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15234 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15235 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15236 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15237
15238 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15239 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15240 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15241 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15242 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15243 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15244 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15245 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15246 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15247 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15248 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15249 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
15250
15251 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
15252 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
15253 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
15254 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
15255 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
15256 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
15257 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
15258 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
15259 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
15260 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
15261 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
15262 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
15263
15264 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 15265 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 15266 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
15267 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
15268
e3cb604e
PB
15269 cCL(flts, e000110, 2, (RF, RR), rn_rd),
15270 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
15271 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
15272 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
15273 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
15274 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
15275 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
15276 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
15277 cCL(flte, e080110, 2, (RF, RR), rn_rd),
15278 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
15279 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
15280 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 15281
c19d1205
ZW
15282 /* The implementation of the FIX instruction is broken on some
15283 assemblers, in that it accepts a precision specifier as well as a
15284 rounding specifier, despite the fact that this is meaningless.
15285 To be more compatible, we accept it as well, though of course it
15286 does not set any bits. */
8f06b2d8 15287 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
15288 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
15289 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
15290 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
15291 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
15292 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
15293 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
15294 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
15295 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
15296 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
15297 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
15298 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
15299 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 15300
c19d1205
ZW
15301 /* Instructions that were new with the real FPA, call them V2. */
15302#undef ARM_VARIANT
e74cfd16 15303#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 15304 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15305 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15306 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 15307 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
15308 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
15309 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
15310
15311#undef ARM_VARIANT
e74cfd16 15312#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 15313 /* Moves and type conversions. */
8f06b2d8
PB
15314 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
15315 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
15316 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
15317 cCE(fmstat, ef1fa10, 0, (), noargs),
15318 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
15319 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
15320 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
15321 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15322 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
15323 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
15324 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
15325 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
15326
15327 /* Memory operations. */
4962c51a
MS
15328 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
15329 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
15330 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15331 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15332 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15333 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15334 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15335 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15336 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15337 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15338 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15339 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
15340 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15341 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
15342 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15343 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
15344 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
15345 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 15346
c19d1205 15347 /* Monadic operations. */
8f06b2d8
PB
15348 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
15349 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
15350 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
15351
15352 /* Dyadic operations. */
8f06b2d8
PB
15353 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15354 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15355 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15356 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15357 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15358 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15359 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15360 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
15361 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 15362
c19d1205 15363 /* Comparisons. */
8f06b2d8
PB
15364 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
15365 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
15366 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
15367 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 15368
c19d1205 15369#undef ARM_VARIANT
e74cfd16 15370#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 15371 /* Moves and type conversions. */
5287ad62 15372 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
15373 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15374 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
15375 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
15376 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
15377 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
15378 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
15379 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
15380 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
15381 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15382 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
15383 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
15384 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
15385
15386 /* Memory operations. */
4962c51a
MS
15387 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
15388 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
15389 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15390 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15391 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15392 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15393 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15394 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
15395 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
15396 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 15397
c19d1205 15398 /* Monadic operations. */
5287ad62
JB
15399 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15400 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15401 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
15402
15403 /* Dyadic operations. */
5287ad62
JB
15404 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15405 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15406 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15407 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15408 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15409 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15410 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15411 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
15412 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 15413
c19d1205 15414 /* Comparisons. */
5287ad62
JB
15415 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
15416 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
15417 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
15418 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
15419
15420#undef ARM_VARIANT
e74cfd16 15421#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
15422 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
15423 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
15424 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
15425 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
15426
037e8744
JB
15427/* Instructions which may belong to either the Neon or VFP instruction sets.
15428 Individual encoder functions perform additional architecture checks. */
15429#undef ARM_VARIANT
15430#define ARM_VARIANT &fpu_vfp_ext_v1xd
15431#undef THUMB_VARIANT
15432#define THUMB_VARIANT &fpu_vfp_ext_v1xd
15433 /* These mnemonics are unique to VFP. */
15434 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
15435 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
15436 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15437 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15438 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
15439 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15440 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
15441 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
15442 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
15443 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
15444
15445 /* Mnemonics shared by Neon and VFP. */
15446 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
15447 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15448 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
15449
15450 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15451 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
15452
15453 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15454 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
15455
15456 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15457 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15458 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15459 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15460 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
15461 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
15462 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
15463 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
15464
15465 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
15466
15467 /* NOTE: All VMOV encoding is special-cased! */
15468 NCE(vmov, 0, 1, (VMOV), neon_mov),
15469 NCE(vmovq, 0, 1, (VMOV), neon_mov),
15470
5287ad62
JB
15471#undef THUMB_VARIANT
15472#define THUMB_VARIANT &fpu_neon_ext_v1
15473#undef ARM_VARIANT
15474#define ARM_VARIANT &fpu_neon_ext_v1
15475 /* Data processing with three registers of the same length. */
15476 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
15477 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
15478 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
15479 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15480 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15481 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15482 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15483 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
15484 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
15485 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
15486 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15487 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15488 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15489 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15490 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15491 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15492 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
15493 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
15494 /* If not immediate, fall back to neon_dyadic_i64_su.
15495 shl_imm should accept I8 I16 I32 I64,
15496 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
15497 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
15498 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
15499 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
15500 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
15501 /* Logic ops, types optional & ignored. */
15502 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
15503 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
15504 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
15505 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
15506 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
15507 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
15508 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
15509 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
15510 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
15511 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
15512 /* Bitfield ops, untyped. */
15513 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15514 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15515 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15516 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15517 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
15518 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
15519 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
15520 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15521 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15522 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15523 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15524 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
15525 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
15526 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
15527 back to neon_dyadic_if_su. */
15528 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15529 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15530 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
15531 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
15532 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15533 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15534 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
15535 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
15536 /* Comparison. Type I8 I16 I32 F32. Non-immediate -> neon_dyadic_if_i. */
15537 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
15538 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
15539 /* As above, D registers only. */
15540 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15541 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
15542 /* Int and float variants, signedness unimportant. */
15543 /* If not scalar, fall back to neon_dyadic_if_i. */
5287ad62 15544 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
15545 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
15546 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
15547 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 15548 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
15549 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
15550 /* vtst takes sizes 8, 16, 32. */
15551 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
15552 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
15553 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 15554 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
15555 /* VQD{R}MULH takes S16 S32. */
15556 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15557 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15558 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
15559 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
15560 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15561 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15562 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
15563 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
15564 NUF(vaclt, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15565 NUF(vacltq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15566 NUF(vacle, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
15567 NUF(vacleq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
15568 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15569 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15570 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
15571 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
15572
15573 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 15574 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
15575 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
15576
15577 /* Data processing with two registers and a shift amount. */
15578 /* Right shifts, and variants with rounding.
15579 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
15580 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15581 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15582 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
15583 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
15584 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15585 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15586 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
15587 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
15588 /* Shift and insert. Sizes accepted 8 16 32 64. */
15589 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
15590 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
15591 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
15592 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
15593 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
15594 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
15595 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
15596 /* Right shift immediate, saturating & narrowing, with rounding variants.
15597 Types accepted S16 S32 S64 U16 U32 U64. */
15598 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15599 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
15600 /* As above, unsigned. Types accepted S16 S32 S64. */
15601 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15602 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
15603 /* Right shift narrowing. Types accepted I16 I32 I64. */
15604 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15605 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
15606 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
15607 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
15608 /* CVT with optional immediate for fixed-point variant. */
037e8744 15609 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 15610
5287ad62
JB
15611 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
15612 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
15613
15614 /* Data processing, three registers of different lengths. */
15615 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
15616 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
15617 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
15618 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
15619 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
15620 /* If not scalar, fall back to neon_dyadic_long.
15621 Vector types as above, scalar types S16 S32 U16 U32. */
15622 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15623 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
15624 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
15625 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15626 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
15627 /* Dyadic, narrowing insns. Types I16 I32 I64. */
15628 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15629 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15630 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15631 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
15632 /* Saturating doubling multiplies. Types S16 S32. */
15633 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15634 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15635 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
15636 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
15637 S16 S32 U16 U32. */
15638 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
15639
15640 /* Extract. Size 8. */
15641 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I7), neon_ext),
15642 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I7), neon_ext),
15643
15644 /* Two registers, miscellaneous. */
15645 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
15646 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
15647 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
15648 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
15649 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
15650 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
15651 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
15652 /* Vector replicate. Sizes 8 16 32. */
15653 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
15654 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
15655 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
15656 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
15657 /* VMOVN. Types I16 I32 I64. */
15658 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
15659 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
15660 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
15661 /* VQMOVUN. Types S16 S32 S64. */
15662 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
15663 /* VZIP / VUZP. Sizes 8 16 32. */
15664 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
15665 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
15666 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
15667 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
15668 /* VQABS / VQNEG. Types S8 S16 S32. */
15669 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15670 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
15671 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
15672 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
15673 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
15674 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
15675 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
15676 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
15677 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
15678 /* Reciprocal estimates. Types U32 F32. */
15679 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
15680 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
15681 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
15682 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
15683 /* VCLS. Types S8 S16 S32. */
15684 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
15685 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
15686 /* VCLZ. Types I8 I16 I32. */
15687 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
15688 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
15689 /* VCNT. Size 8. */
15690 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
15691 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
15692 /* Two address, untyped. */
15693 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
15694 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
15695 /* VTRN. Sizes 8 16 32. */
15696 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
15697 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
15698
15699 /* Table lookup. Size 8. */
15700 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15701 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
15702
b7fc2769
JB
15703#undef THUMB_VARIANT
15704#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
15705#undef ARM_VARIANT
15706#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
15707 /* Neon element/structure load/store. */
15708 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15709 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
15710 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15711 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
15712 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15713 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
15714 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15715 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
15716
15717#undef THUMB_VARIANT
15718#define THUMB_VARIANT &fpu_vfp_ext_v3
15719#undef ARM_VARIANT
15720#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
15721 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
15722 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
15723 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15724 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15725 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15726 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15727 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15728 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15729 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15730 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15731 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15732 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15733 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15734 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
15735 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
15736 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
15737 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
15738 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 15739
5287ad62 15740#undef THUMB_VARIANT
c19d1205 15741#undef ARM_VARIANT
e74cfd16 15742#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
15743 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15744 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15745 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15746 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15747 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15748 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
15749 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
15750 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
15751
15752#undef ARM_VARIANT
e74cfd16 15753#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
15754 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
15755 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
15756 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
15757 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
15758 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
15759 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
15760 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
15761 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
15762 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
15763 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15764 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15765 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
15766 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15767 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15768 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
15769 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15770 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
15771 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 15772 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
15773 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
15774 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15775 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15776 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15777 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15778 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15779 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
15780 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
15781 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
15782 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 15783 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
15784 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
15785 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
15786 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
15787 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
15788 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
15789 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
15790 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
15791 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15792 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15793 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15794 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15795 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15796 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15797 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15798 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15799 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15800 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
15801 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15802 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15803 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15804 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15805 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15806 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15807 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15808 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15809 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15810 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15811 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15812 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15813 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15814 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15815 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15816 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15817 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15818 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15819 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15820 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15821 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15822 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15823 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15824 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15825 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15826 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15827 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15828 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15829 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15830 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15831 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15832 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15833 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15834 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15835 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15836 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15837 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15838 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15839 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15840 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15841 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15842 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
15843 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15844 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15845 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15846 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15847 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15848 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15849 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15850 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15851 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15852 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15853 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15854 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15855 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15856 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15857 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15858 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15859 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15860 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15861 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15862 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15863 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15864 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
15865 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15866 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15867 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15868 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15869 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15870 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15871 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15872 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15873 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15874 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15875 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15876 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15877 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15878 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15879 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15880 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15881 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15882 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
15883 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15884 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
15885 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
15886 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
15887 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15888 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15889 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15890 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15891 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15892 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15893 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15894 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15895 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15896 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
15897 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
15898 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
15899 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
15900 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
15901 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
15902 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15903 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15904 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15905 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
15906 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
15907 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
15908 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
15909 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
15910 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
15911 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15912 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15913 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15914 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
15915 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205
ZW
15916
15917#undef ARM_VARIANT
e74cfd16 15918#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
15919 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15920 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15921 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15922 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
15923 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
15924 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
15925 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
15926 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
15927 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
15928 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
15929 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
15930 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
15931 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
15932 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
15933 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
15934 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
15935 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
15936 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
15937 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
15938 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
15939 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
15940 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
15941 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
15942 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
15943 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
15944 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
15945 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
15946 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
15947 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
15948 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
15949 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
15950 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
15951 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
15952 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
15953 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
15954 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
15955 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
15956 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
15957 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
15958 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
15959 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
15960 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
15961 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
15962 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
15963 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
15964 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
15965 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
15966 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
15967 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
15968 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
15969 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
15970 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
15971 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
15972 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
15973 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
15974 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
15975 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
15976 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
15977 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
15978 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
15979 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
15980 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
15981 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
15982 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
15983 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15984 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15985 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15986 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15987 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15988 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
15989 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15990 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
15991 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15992 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
15993 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
15994 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
15995};
15996#undef ARM_VARIANT
15997#undef THUMB_VARIANT
15998#undef TCE
15999#undef TCM
16000#undef TUE
16001#undef TUF
16002#undef TCC
8f06b2d8 16003#undef cCE
e3cb604e
PB
16004#undef cCL
16005#undef C3E
c19d1205
ZW
16006#undef CE
16007#undef CM
16008#undef UE
16009#undef UF
16010#undef UT
5287ad62
JB
16011#undef NUF
16012#undef nUF
16013#undef NCE
16014#undef nCE
c19d1205
ZW
16015#undef OPS0
16016#undef OPS1
16017#undef OPS2
16018#undef OPS3
16019#undef OPS4
16020#undef OPS5
16021#undef OPS6
16022#undef do_0
16023\f
16024/* MD interface: bits in the object file. */
bfae80f2 16025
c19d1205
ZW
16026/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
16027 for use in the a.out file, and stores them in the array pointed to by buf.
16028 This knows about the endian-ness of the target machine and does
16029 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
16030 2 (short) and 4 (long) Floating numbers are put out as a series of
16031 LITTLENUMS (shorts, here at least). */
b99bd4ef 16032
c19d1205
ZW
16033void
16034md_number_to_chars (char * buf, valueT val, int n)
16035{
16036 if (target_big_endian)
16037 number_to_chars_bigendian (buf, val, n);
16038 else
16039 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
16040}
16041
c19d1205
ZW
16042static valueT
16043md_chars_to_number (char * buf, int n)
bfae80f2 16044{
c19d1205
ZW
16045 valueT result = 0;
16046 unsigned char * where = (unsigned char *) buf;
bfae80f2 16047
c19d1205 16048 if (target_big_endian)
b99bd4ef 16049 {
c19d1205
ZW
16050 while (n--)
16051 {
16052 result <<= 8;
16053 result |= (*where++ & 255);
16054 }
b99bd4ef 16055 }
c19d1205 16056 else
b99bd4ef 16057 {
c19d1205
ZW
16058 while (n--)
16059 {
16060 result <<= 8;
16061 result |= (where[n] & 255);
16062 }
bfae80f2 16063 }
b99bd4ef 16064
c19d1205 16065 return result;
bfae80f2 16066}
b99bd4ef 16067
c19d1205 16068/* MD interface: Sections. */
b99bd4ef 16069
0110f2b8
PB
16070/* Estimate the size of a frag before relaxing. Assume everything fits in
16071 2 bytes. */
16072
c19d1205 16073int
0110f2b8 16074md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
16075 segT segtype ATTRIBUTE_UNUSED)
16076{
0110f2b8
PB
16077 fragp->fr_var = 2;
16078 return 2;
16079}
16080
16081/* Convert a machine dependent frag. */
16082
16083void
16084md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
16085{
16086 unsigned long insn;
16087 unsigned long old_op;
16088 char *buf;
16089 expressionS exp;
16090 fixS *fixp;
16091 int reloc_type;
16092 int pc_rel;
16093 int opcode;
16094
16095 buf = fragp->fr_literal + fragp->fr_fix;
16096
16097 old_op = bfd_get_16(abfd, buf);
16098 if (fragp->fr_symbol) {
16099 exp.X_op = O_symbol;
16100 exp.X_add_symbol = fragp->fr_symbol;
16101 } else {
16102 exp.X_op = O_constant;
16103 }
16104 exp.X_add_number = fragp->fr_offset;
16105 opcode = fragp->fr_subtype;
16106 switch (opcode)
16107 {
16108 case T_MNEM_ldr_pc:
16109 case T_MNEM_ldr_pc2:
16110 case T_MNEM_ldr_sp:
16111 case T_MNEM_str_sp:
16112 case T_MNEM_ldr:
16113 case T_MNEM_ldrb:
16114 case T_MNEM_ldrh:
16115 case T_MNEM_str:
16116 case T_MNEM_strb:
16117 case T_MNEM_strh:
16118 if (fragp->fr_var == 4)
16119 {
16120 insn = THUMB_OP32(opcode);
16121 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
16122 {
16123 insn |= (old_op & 0x700) << 4;
16124 }
16125 else
16126 {
16127 insn |= (old_op & 7) << 12;
16128 insn |= (old_op & 0x38) << 13;
16129 }
16130 insn |= 0x00000c00;
16131 put_thumb32_insn (buf, insn);
16132 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
16133 }
16134 else
16135 {
16136 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
16137 }
16138 pc_rel = (opcode == T_MNEM_ldr_pc2);
16139 break;
16140 case T_MNEM_adr:
16141 if (fragp->fr_var == 4)
16142 {
16143 insn = THUMB_OP32 (opcode);
16144 insn |= (old_op & 0xf0) << 4;
16145 put_thumb32_insn (buf, insn);
16146 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
16147 }
16148 else
16149 {
16150 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16151 exp.X_add_number -= 4;
16152 }
16153 pc_rel = 1;
16154 break;
16155 case T_MNEM_mov:
16156 case T_MNEM_movs:
16157 case T_MNEM_cmp:
16158 case T_MNEM_cmn:
16159 if (fragp->fr_var == 4)
16160 {
16161 int r0off = (opcode == T_MNEM_mov
16162 || opcode == T_MNEM_movs) ? 0 : 8;
16163 insn = THUMB_OP32 (opcode);
16164 insn = (insn & 0xe1ffffff) | 0x10000000;
16165 insn |= (old_op & 0x700) << r0off;
16166 put_thumb32_insn (buf, insn);
16167 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
16168 }
16169 else
16170 {
16171 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
16172 }
16173 pc_rel = 0;
16174 break;
16175 case T_MNEM_b:
16176 if (fragp->fr_var == 4)
16177 {
16178 insn = THUMB_OP32(opcode);
16179 put_thumb32_insn (buf, insn);
16180 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
16181 }
16182 else
16183 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
16184 pc_rel = 1;
16185 break;
16186 case T_MNEM_bcond:
16187 if (fragp->fr_var == 4)
16188 {
16189 insn = THUMB_OP32(opcode);
16190 insn |= (old_op & 0xf00) << 14;
16191 put_thumb32_insn (buf, insn);
16192 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
16193 }
16194 else
16195 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
16196 pc_rel = 1;
16197 break;
16198 case T_MNEM_add_sp:
16199 case T_MNEM_add_pc:
16200 case T_MNEM_inc_sp:
16201 case T_MNEM_dec_sp:
16202 if (fragp->fr_var == 4)
16203 {
16204 /* ??? Choose between add and addw. */
16205 insn = THUMB_OP32 (opcode);
16206 insn |= (old_op & 0xf0) << 4;
16207 put_thumb32_insn (buf, insn);
16805f35
PB
16208 if (opcode == T_MNEM_add_pc)
16209 reloc_type = BFD_RELOC_ARM_T32_IMM12;
16210 else
16211 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
16212 }
16213 else
16214 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16215 pc_rel = 0;
16216 break;
16217
16218 case T_MNEM_addi:
16219 case T_MNEM_addis:
16220 case T_MNEM_subi:
16221 case T_MNEM_subis:
16222 if (fragp->fr_var == 4)
16223 {
16224 insn = THUMB_OP32 (opcode);
16225 insn |= (old_op & 0xf0) << 4;
16226 insn |= (old_op & 0xf) << 16;
16227 put_thumb32_insn (buf, insn);
16805f35
PB
16228 if (insn & (1 << 20))
16229 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
16230 else
16231 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
16232 }
16233 else
16234 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
16235 pc_rel = 0;
16236 break;
16237 default:
16238 abort();
16239 }
16240 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
16241 reloc_type);
16242 fixp->fx_file = fragp->fr_file;
16243 fixp->fx_line = fragp->fr_line;
16244 fragp->fr_fix += fragp->fr_var;
16245}
16246
16247/* Return the size of a relaxable immediate operand instruction.
16248 SHIFT and SIZE specify the form of the allowable immediate. */
16249static int
16250relax_immediate (fragS *fragp, int size, int shift)
16251{
16252 offsetT offset;
16253 offsetT mask;
16254 offsetT low;
16255
16256 /* ??? Should be able to do better than this. */
16257 if (fragp->fr_symbol)
16258 return 4;
16259
16260 low = (1 << shift) - 1;
16261 mask = (1 << (shift + size)) - (1 << shift);
16262 offset = fragp->fr_offset;
16263 /* Force misaligned offsets to 32-bit variant. */
16264 if (offset & low)
16265 return -4;
16266 if (offset & ~mask)
16267 return 4;
16268 return 2;
16269}
16270
16271/* Return the size of a relaxable adr pseudo-instruction or PC-relative
16272 load. */
16273static int
16274relax_adr (fragS *fragp, asection *sec)
16275{
16276 addressT addr;
16277 offsetT val;
16278
16279 /* Assume worst case for symbols not known to be in the same section. */
16280 if (!S_IS_DEFINED(fragp->fr_symbol)
16281 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16282 return 4;
16283
16284 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16285 addr = fragp->fr_address + fragp->fr_fix;
16286 addr = (addr + 4) & ~3;
16287 /* Fix the insn as the 4-byte version if the target address is not
16288 sufficiently aligned. This is prevents an infinite loop when two
16289 instructions have contradictory range/alignment requirements. */
16290 if (val & 3)
16291 return -4;
16292 val -= addr;
16293 if (val < 0 || val > 1020)
16294 return 4;
16295 return 2;
16296}
16297
16298/* Return the size of a relaxable add/sub immediate instruction. */
16299static int
16300relax_addsub (fragS *fragp, asection *sec)
16301{
16302 char *buf;
16303 int op;
16304
16305 buf = fragp->fr_literal + fragp->fr_fix;
16306 op = bfd_get_16(sec->owner, buf);
16307 if ((op & 0xf) == ((op >> 4) & 0xf))
16308 return relax_immediate (fragp, 8, 0);
16309 else
16310 return relax_immediate (fragp, 3, 0);
16311}
16312
16313
16314/* Return the size of a relaxable branch instruction. BITS is the
16315 size of the offset field in the narrow instruction. */
16316
16317static int
16318relax_branch (fragS *fragp, asection *sec, int bits)
16319{
16320 addressT addr;
16321 offsetT val;
16322 offsetT limit;
16323
16324 /* Assume worst case for symbols not known to be in the same section. */
16325 if (!S_IS_DEFINED(fragp->fr_symbol)
16326 || sec != S_GET_SEGMENT (fragp->fr_symbol))
16327 return 4;
16328
16329 val = S_GET_VALUE(fragp->fr_symbol) + fragp->fr_offset;
16330 addr = fragp->fr_address + fragp->fr_fix + 4;
16331 val -= addr;
16332
16333 /* Offset is a signed value *2 */
16334 limit = 1 << bits;
16335 if (val >= limit || val < -limit)
16336 return 4;
16337 return 2;
16338}
16339
16340
16341/* Relax a machine dependent frag. This returns the amount by which
16342 the current size of the frag should change. */
16343
16344int
16345arm_relax_frag (asection *sec, fragS *fragp, long stretch ATTRIBUTE_UNUSED)
16346{
16347 int oldsize;
16348 int newsize;
16349
16350 oldsize = fragp->fr_var;
16351 switch (fragp->fr_subtype)
16352 {
16353 case T_MNEM_ldr_pc2:
16354 newsize = relax_adr(fragp, sec);
16355 break;
16356 case T_MNEM_ldr_pc:
16357 case T_MNEM_ldr_sp:
16358 case T_MNEM_str_sp:
16359 newsize = relax_immediate(fragp, 8, 2);
16360 break;
16361 case T_MNEM_ldr:
16362 case T_MNEM_str:
16363 newsize = relax_immediate(fragp, 5, 2);
16364 break;
16365 case T_MNEM_ldrh:
16366 case T_MNEM_strh:
16367 newsize = relax_immediate(fragp, 5, 1);
16368 break;
16369 case T_MNEM_ldrb:
16370 case T_MNEM_strb:
16371 newsize = relax_immediate(fragp, 5, 0);
16372 break;
16373 case T_MNEM_adr:
16374 newsize = relax_adr(fragp, sec);
16375 break;
16376 case T_MNEM_mov:
16377 case T_MNEM_movs:
16378 case T_MNEM_cmp:
16379 case T_MNEM_cmn:
16380 newsize = relax_immediate(fragp, 8, 0);
16381 break;
16382 case T_MNEM_b:
16383 newsize = relax_branch(fragp, sec, 11);
16384 break;
16385 case T_MNEM_bcond:
16386 newsize = relax_branch(fragp, sec, 8);
16387 break;
16388 case T_MNEM_add_sp:
16389 case T_MNEM_add_pc:
16390 newsize = relax_immediate (fragp, 8, 2);
16391 break;
16392 case T_MNEM_inc_sp:
16393 case T_MNEM_dec_sp:
16394 newsize = relax_immediate (fragp, 7, 2);
16395 break;
16396 case T_MNEM_addi:
16397 case T_MNEM_addis:
16398 case T_MNEM_subi:
16399 case T_MNEM_subis:
16400 newsize = relax_addsub (fragp, sec);
16401 break;
16402 default:
16403 abort();
16404 }
16405 if (newsize < 0)
16406 {
16407 fragp->fr_var = -newsize;
16408 md_convert_frag (sec->owner, sec, fragp);
16409 frag_wane(fragp);
16410 return -(newsize + oldsize);
16411 }
16412 fragp->fr_var = newsize;
16413 return newsize - oldsize;
c19d1205 16414}
b99bd4ef 16415
c19d1205 16416/* Round up a section size to the appropriate boundary. */
b99bd4ef 16417
c19d1205
ZW
16418valueT
16419md_section_align (segT segment ATTRIBUTE_UNUSED,
16420 valueT size)
16421{
f0927246
NC
16422#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
16423 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
16424 {
16425 /* For a.out, force the section size to be aligned. If we don't do
16426 this, BFD will align it for us, but it will not write out the
16427 final bytes of the section. This may be a bug in BFD, but it is
16428 easier to fix it here since that is how the other a.out targets
16429 work. */
16430 int align;
16431
16432 align = bfd_get_section_alignment (stdoutput, segment);
16433 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
16434 }
c19d1205 16435#endif
f0927246
NC
16436
16437 return size;
bfae80f2 16438}
b99bd4ef 16439
c19d1205
ZW
16440/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
16441 of an rs_align_code fragment. */
16442
16443void
16444arm_handle_align (fragS * fragP)
bfae80f2 16445{
c19d1205
ZW
16446 static char const arm_noop[4] = { 0x00, 0x00, 0xa0, 0xe1 };
16447 static char const thumb_noop[2] = { 0xc0, 0x46 };
16448 static char const arm_bigend_noop[4] = { 0xe1, 0xa0, 0x00, 0x00 };
16449 static char const thumb_bigend_noop[2] = { 0x46, 0xc0 };
16450
16451 int bytes, fix, noop_size;
16452 char * p;
16453 const char * noop;
bfae80f2 16454
c19d1205 16455 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
16456 return;
16457
c19d1205
ZW
16458 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
16459 p = fragP->fr_literal + fragP->fr_fix;
16460 fix = 0;
bfae80f2 16461
c19d1205
ZW
16462 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
16463 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 16464
c19d1205 16465 if (fragP->tc_frag_data)
a737bd4d 16466 {
c19d1205
ZW
16467 if (target_big_endian)
16468 noop = thumb_bigend_noop;
16469 else
16470 noop = thumb_noop;
16471 noop_size = sizeof (thumb_noop);
7ed4c4c5
NC
16472 }
16473 else
16474 {
c19d1205
ZW
16475 if (target_big_endian)
16476 noop = arm_bigend_noop;
16477 else
16478 noop = arm_noop;
16479 noop_size = sizeof (arm_noop);
7ed4c4c5 16480 }
a737bd4d 16481
c19d1205 16482 if (bytes & (noop_size - 1))
7ed4c4c5 16483 {
c19d1205
ZW
16484 fix = bytes & (noop_size - 1);
16485 memset (p, 0, fix);
16486 p += fix;
16487 bytes -= fix;
a737bd4d 16488 }
a737bd4d 16489
c19d1205 16490 while (bytes >= noop_size)
a737bd4d 16491 {
c19d1205
ZW
16492 memcpy (p, noop, noop_size);
16493 p += noop_size;
16494 bytes -= noop_size;
16495 fix += noop_size;
a737bd4d
NC
16496 }
16497
c19d1205
ZW
16498 fragP->fr_fix += fix;
16499 fragP->fr_var = noop_size;
a737bd4d
NC
16500}
16501
c19d1205
ZW
16502/* Called from md_do_align. Used to create an alignment
16503 frag in a code section. */
16504
16505void
16506arm_frag_align_code (int n, int max)
bfae80f2 16507{
c19d1205 16508 char * p;
7ed4c4c5 16509
c19d1205
ZW
16510 /* We assume that there will never be a requirement
16511 to support alignments greater than 32 bytes. */
16512 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
16513 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 16514
c19d1205
ZW
16515 p = frag_var (rs_align_code,
16516 MAX_MEM_FOR_RS_ALIGN_CODE,
16517 1,
16518 (relax_substateT) max,
16519 (symbolS *) NULL,
16520 (offsetT) n,
16521 (char *) NULL);
16522 *p = 0;
16523}
bfae80f2 16524
c19d1205 16525/* Perform target specific initialisation of a frag. */
bfae80f2 16526
c19d1205
ZW
16527void
16528arm_init_frag (fragS * fragP)
16529{
16530 /* Record whether this frag is in an ARM or a THUMB area. */
16531 fragP->tc_frag_data = thumb_mode;
bfae80f2
RE
16532}
16533
c19d1205
ZW
16534#ifdef OBJ_ELF
16535/* When we change sections we need to issue a new mapping symbol. */
16536
16537void
16538arm_elf_change_section (void)
bfae80f2 16539{
c19d1205
ZW
16540 flagword flags;
16541 segment_info_type *seginfo;
bfae80f2 16542
c19d1205
ZW
16543 /* Link an unlinked unwind index table section to the .text section. */
16544 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
16545 && elf_linked_to_section (now_seg) == NULL)
16546 elf_linked_to_section (now_seg) = text_section;
16547
16548 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
16549 return;
16550
c19d1205
ZW
16551 flags = bfd_get_section_flags (stdoutput, now_seg);
16552
16553 /* We can ignore sections that only contain debug info. */
16554 if ((flags & SEC_ALLOC) == 0)
16555 return;
bfae80f2 16556
c19d1205
ZW
16557 seginfo = seg_info (now_seg);
16558 mapstate = seginfo->tc_segment_info_data.mapstate;
16559 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
16560}
16561
c19d1205
ZW
16562int
16563arm_elf_section_type (const char * str, size_t len)
e45d0630 16564{
c19d1205
ZW
16565 if (len == 5 && strncmp (str, "exidx", 5) == 0)
16566 return SHT_ARM_EXIDX;
e45d0630 16567
c19d1205
ZW
16568 return -1;
16569}
16570\f
16571/* Code to deal with unwinding tables. */
e45d0630 16572
c19d1205 16573static void add_unwind_adjustsp (offsetT);
e45d0630 16574
c19d1205 16575/* Cenerate and deferred unwind frame offset. */
e45d0630 16576
bfae80f2 16577static void
c19d1205 16578flush_pending_unwind (void)
bfae80f2 16579{
c19d1205 16580 offsetT offset;
bfae80f2 16581
c19d1205
ZW
16582 offset = unwind.pending_offset;
16583 unwind.pending_offset = 0;
16584 if (offset != 0)
16585 add_unwind_adjustsp (offset);
bfae80f2
RE
16586}
16587
c19d1205
ZW
16588/* Add an opcode to this list for this function. Two-byte opcodes should
16589 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
16590 order. */
16591
bfae80f2 16592static void
c19d1205 16593add_unwind_opcode (valueT op, int length)
bfae80f2 16594{
c19d1205
ZW
16595 /* Add any deferred stack adjustment. */
16596 if (unwind.pending_offset)
16597 flush_pending_unwind ();
bfae80f2 16598
c19d1205 16599 unwind.sp_restored = 0;
bfae80f2 16600
c19d1205 16601 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 16602 {
c19d1205
ZW
16603 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
16604 if (unwind.opcodes)
16605 unwind.opcodes = xrealloc (unwind.opcodes,
16606 unwind.opcode_alloc);
16607 else
16608 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 16609 }
c19d1205 16610 while (length > 0)
bfae80f2 16611 {
c19d1205
ZW
16612 length--;
16613 unwind.opcodes[unwind.opcode_count] = op & 0xff;
16614 op >>= 8;
16615 unwind.opcode_count++;
bfae80f2 16616 }
bfae80f2
RE
16617}
16618
c19d1205
ZW
16619/* Add unwind opcodes to adjust the stack pointer. */
16620
bfae80f2 16621static void
c19d1205 16622add_unwind_adjustsp (offsetT offset)
bfae80f2 16623{
c19d1205 16624 valueT op;
bfae80f2 16625
c19d1205 16626 if (offset > 0x200)
bfae80f2 16627 {
c19d1205
ZW
16628 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
16629 char bytes[5];
16630 int n;
16631 valueT o;
bfae80f2 16632
c19d1205
ZW
16633 /* Long form: 0xb2, uleb128. */
16634 /* This might not fit in a word so add the individual bytes,
16635 remembering the list is built in reverse order. */
16636 o = (valueT) ((offset - 0x204) >> 2);
16637 if (o == 0)
16638 add_unwind_opcode (0, 1);
bfae80f2 16639
c19d1205
ZW
16640 /* Calculate the uleb128 encoding of the offset. */
16641 n = 0;
16642 while (o)
16643 {
16644 bytes[n] = o & 0x7f;
16645 o >>= 7;
16646 if (o)
16647 bytes[n] |= 0x80;
16648 n++;
16649 }
16650 /* Add the insn. */
16651 for (; n; n--)
16652 add_unwind_opcode (bytes[n - 1], 1);
16653 add_unwind_opcode (0xb2, 1);
16654 }
16655 else if (offset > 0x100)
bfae80f2 16656 {
c19d1205
ZW
16657 /* Two short opcodes. */
16658 add_unwind_opcode (0x3f, 1);
16659 op = (offset - 0x104) >> 2;
16660 add_unwind_opcode (op, 1);
bfae80f2 16661 }
c19d1205
ZW
16662 else if (offset > 0)
16663 {
16664 /* Short opcode. */
16665 op = (offset - 4) >> 2;
16666 add_unwind_opcode (op, 1);
16667 }
16668 else if (offset < 0)
bfae80f2 16669 {
c19d1205
ZW
16670 offset = -offset;
16671 while (offset > 0x100)
bfae80f2 16672 {
c19d1205
ZW
16673 add_unwind_opcode (0x7f, 1);
16674 offset -= 0x100;
bfae80f2 16675 }
c19d1205
ZW
16676 op = ((offset - 4) >> 2) | 0x40;
16677 add_unwind_opcode (op, 1);
bfae80f2 16678 }
bfae80f2
RE
16679}
16680
c19d1205
ZW
16681/* Finish the list of unwind opcodes for this function. */
16682static void
16683finish_unwind_opcodes (void)
bfae80f2 16684{
c19d1205 16685 valueT op;
bfae80f2 16686
c19d1205 16687 if (unwind.fp_used)
bfae80f2 16688 {
708587a4 16689 /* Adjust sp as necessary. */
c19d1205
ZW
16690 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
16691 flush_pending_unwind ();
bfae80f2 16692
c19d1205
ZW
16693 /* After restoring sp from the frame pointer. */
16694 op = 0x90 | unwind.fp_reg;
16695 add_unwind_opcode (op, 1);
16696 }
16697 else
16698 flush_pending_unwind ();
bfae80f2
RE
16699}
16700
bfae80f2 16701
c19d1205
ZW
16702/* Start an exception table entry. If idx is nonzero this is an index table
16703 entry. */
bfae80f2
RE
16704
16705static void
c19d1205 16706start_unwind_section (const segT text_seg, int idx)
bfae80f2 16707{
c19d1205
ZW
16708 const char * text_name;
16709 const char * prefix;
16710 const char * prefix_once;
16711 const char * group_name;
16712 size_t prefix_len;
16713 size_t text_len;
16714 char * sec_name;
16715 size_t sec_name_len;
16716 int type;
16717 int flags;
16718 int linkonce;
bfae80f2 16719
c19d1205 16720 if (idx)
bfae80f2 16721 {
c19d1205
ZW
16722 prefix = ELF_STRING_ARM_unwind;
16723 prefix_once = ELF_STRING_ARM_unwind_once;
16724 type = SHT_ARM_EXIDX;
bfae80f2 16725 }
c19d1205 16726 else
bfae80f2 16727 {
c19d1205
ZW
16728 prefix = ELF_STRING_ARM_unwind_info;
16729 prefix_once = ELF_STRING_ARM_unwind_info_once;
16730 type = SHT_PROGBITS;
bfae80f2
RE
16731 }
16732
c19d1205
ZW
16733 text_name = segment_name (text_seg);
16734 if (streq (text_name, ".text"))
16735 text_name = "";
16736
16737 if (strncmp (text_name, ".gnu.linkonce.t.",
16738 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 16739 {
c19d1205
ZW
16740 prefix = prefix_once;
16741 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
16742 }
16743
c19d1205
ZW
16744 prefix_len = strlen (prefix);
16745 text_len = strlen (text_name);
16746 sec_name_len = prefix_len + text_len;
16747 sec_name = xmalloc (sec_name_len + 1);
16748 memcpy (sec_name, prefix, prefix_len);
16749 memcpy (sec_name + prefix_len, text_name, text_len);
16750 sec_name[prefix_len + text_len] = '\0';
bfae80f2 16751
c19d1205
ZW
16752 flags = SHF_ALLOC;
16753 linkonce = 0;
16754 group_name = 0;
bfae80f2 16755
c19d1205
ZW
16756 /* Handle COMDAT group. */
16757 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 16758 {
c19d1205
ZW
16759 group_name = elf_group_name (text_seg);
16760 if (group_name == NULL)
16761 {
16762 as_bad ("Group section `%s' has no group signature",
16763 segment_name (text_seg));
16764 ignore_rest_of_line ();
16765 return;
16766 }
16767 flags |= SHF_GROUP;
16768 linkonce = 1;
bfae80f2
RE
16769 }
16770
c19d1205 16771 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 16772
c19d1205
ZW
16773 /* Set the setion link for index tables. */
16774 if (idx)
16775 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
16776}
16777
bfae80f2 16778
c19d1205
ZW
16779/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
16780 personality routine data. Returns zero, or the index table value for
16781 and inline entry. */
16782
16783static valueT
16784create_unwind_entry (int have_data)
bfae80f2 16785{
c19d1205
ZW
16786 int size;
16787 addressT where;
16788 char *ptr;
16789 /* The current word of data. */
16790 valueT data;
16791 /* The number of bytes left in this word. */
16792 int n;
bfae80f2 16793
c19d1205 16794 finish_unwind_opcodes ();
bfae80f2 16795
c19d1205
ZW
16796 /* Remember the current text section. */
16797 unwind.saved_seg = now_seg;
16798 unwind.saved_subseg = now_subseg;
bfae80f2 16799
c19d1205 16800 start_unwind_section (now_seg, 0);
bfae80f2 16801
c19d1205 16802 if (unwind.personality_routine == NULL)
bfae80f2 16803 {
c19d1205
ZW
16804 if (unwind.personality_index == -2)
16805 {
16806 if (have_data)
16807 as_bad (_("handerdata in cantunwind frame"));
16808 return 1; /* EXIDX_CANTUNWIND. */
16809 }
bfae80f2 16810
c19d1205
ZW
16811 /* Use a default personality routine if none is specified. */
16812 if (unwind.personality_index == -1)
16813 {
16814 if (unwind.opcode_count > 3)
16815 unwind.personality_index = 1;
16816 else
16817 unwind.personality_index = 0;
16818 }
bfae80f2 16819
c19d1205
ZW
16820 /* Space for the personality routine entry. */
16821 if (unwind.personality_index == 0)
16822 {
16823 if (unwind.opcode_count > 3)
16824 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 16825
c19d1205
ZW
16826 if (!have_data)
16827 {
16828 /* All the data is inline in the index table. */
16829 data = 0x80;
16830 n = 3;
16831 while (unwind.opcode_count > 0)
16832 {
16833 unwind.opcode_count--;
16834 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16835 n--;
16836 }
bfae80f2 16837
c19d1205
ZW
16838 /* Pad with "finish" opcodes. */
16839 while (n--)
16840 data = (data << 8) | 0xb0;
bfae80f2 16841
c19d1205
ZW
16842 return data;
16843 }
16844 size = 0;
16845 }
16846 else
16847 /* We get two opcodes "free" in the first word. */
16848 size = unwind.opcode_count - 2;
16849 }
16850 else
16851 /* An extra byte is required for the opcode count. */
16852 size = unwind.opcode_count + 1;
bfae80f2 16853
c19d1205
ZW
16854 size = (size + 3) >> 2;
16855 if (size > 0xff)
16856 as_bad (_("too many unwind opcodes"));
bfae80f2 16857
c19d1205
ZW
16858 frag_align (2, 0, 0);
16859 record_alignment (now_seg, 2);
16860 unwind.table_entry = expr_build_dot ();
16861
16862 /* Allocate the table entry. */
16863 ptr = frag_more ((size << 2) + 4);
16864 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 16865
c19d1205 16866 switch (unwind.personality_index)
bfae80f2 16867 {
c19d1205
ZW
16868 case -1:
16869 /* ??? Should this be a PLT generating relocation? */
16870 /* Custom personality routine. */
16871 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
16872 BFD_RELOC_ARM_PREL31);
bfae80f2 16873
c19d1205
ZW
16874 where += 4;
16875 ptr += 4;
bfae80f2 16876
c19d1205
ZW
16877 /* Set the first byte to the number of additional words. */
16878 data = size - 1;
16879 n = 3;
16880 break;
bfae80f2 16881
c19d1205
ZW
16882 /* ABI defined personality routines. */
16883 case 0:
16884 /* Three opcodes bytes are packed into the first word. */
16885 data = 0x80;
16886 n = 3;
16887 break;
bfae80f2 16888
c19d1205
ZW
16889 case 1:
16890 case 2:
16891 /* The size and first two opcode bytes go in the first word. */
16892 data = ((0x80 + unwind.personality_index) << 8) | size;
16893 n = 2;
16894 break;
bfae80f2 16895
c19d1205
ZW
16896 default:
16897 /* Should never happen. */
16898 abort ();
16899 }
bfae80f2 16900
c19d1205
ZW
16901 /* Pack the opcodes into words (MSB first), reversing the list at the same
16902 time. */
16903 while (unwind.opcode_count > 0)
16904 {
16905 if (n == 0)
16906 {
16907 md_number_to_chars (ptr, data, 4);
16908 ptr += 4;
16909 n = 4;
16910 data = 0;
16911 }
16912 unwind.opcode_count--;
16913 n--;
16914 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
16915 }
16916
16917 /* Finish off the last word. */
16918 if (n < 4)
16919 {
16920 /* Pad with "finish" opcodes. */
16921 while (n--)
16922 data = (data << 8) | 0xb0;
16923
16924 md_number_to_chars (ptr, data, 4);
16925 }
16926
16927 if (!have_data)
16928 {
16929 /* Add an empty descriptor if there is no user-specified data. */
16930 ptr = frag_more (4);
16931 md_number_to_chars (ptr, 0, 4);
16932 }
16933
16934 return 0;
bfae80f2
RE
16935}
16936
f0927246
NC
16937
16938/* Initialize the DWARF-2 unwind information for this procedure. */
16939
16940void
16941tc_arm_frame_initial_instructions (void)
16942{
16943 cfi_add_CFA_def_cfa (REG_SP, 0);
16944}
16945#endif /* OBJ_ELF */
16946
c19d1205
ZW
16947/* Convert REGNAME to a DWARF-2 register number. */
16948
16949int
1df69f4f 16950tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 16951{
1df69f4f 16952 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
16953
16954 if (reg == FAIL)
16955 return -1;
16956
16957 return reg;
bfae80f2
RE
16958}
16959
f0927246 16960#ifdef TE_PE
c19d1205 16961void
f0927246 16962tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 16963{
f0927246 16964 expressionS expr;
bfae80f2 16965
f0927246
NC
16966 expr.X_op = O_secrel;
16967 expr.X_add_symbol = symbol;
16968 expr.X_add_number = 0;
16969 emit_expr (&expr, size);
16970}
16971#endif
bfae80f2 16972
c19d1205 16973/* MD interface: Symbol and relocation handling. */
bfae80f2 16974
2fc8bdac
ZW
16975/* Return the address within the segment that a PC-relative fixup is
16976 relative to. For ARM, PC-relative fixups applied to instructions
16977 are generally relative to the location of the fixup plus 8 bytes.
16978 Thumb branches are offset by 4, and Thumb loads relative to PC
16979 require special handling. */
bfae80f2 16980
c19d1205 16981long
2fc8bdac 16982md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 16983{
2fc8bdac
ZW
16984 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
16985
16986 /* If this is pc-relative and we are going to emit a relocation
16987 then we just want to put out any pipeline compensation that the linker
53baae48
NC
16988 will need. Otherwise we want to use the calculated base.
16989 For WinCE we skip the bias for externals as well, since this
16990 is how the MS ARM-CE assembler behaves and we want to be compatible. */
2fc8bdac
ZW
16991 if (fixP->fx_pcrel
16992 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
16993 || (arm_force_relocation (fixP)
16994#ifdef TE_WINCE
16995 && !S_IS_EXTERNAL (fixP->fx_addsy)
16996#endif
16997 )))
2fc8bdac 16998 base = 0;
bfae80f2 16999
c19d1205 17000 switch (fixP->fx_r_type)
bfae80f2 17001 {
2fc8bdac
ZW
17002 /* PC relative addressing on the Thumb is slightly odd as the
17003 bottom two bits of the PC are forced to zero for the
17004 calculation. This happens *after* application of the
17005 pipeline offset. However, Thumb adrl already adjusts for
17006 this, so we need not do it again. */
c19d1205 17007 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 17008 return base & ~3;
c19d1205
ZW
17009
17010 case BFD_RELOC_ARM_THUMB_OFFSET:
17011 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 17012 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 17013 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 17014 return (base + 4) & ~3;
c19d1205 17015
2fc8bdac
ZW
17016 /* Thumb branches are simply offset by +4. */
17017 case BFD_RELOC_THUMB_PCREL_BRANCH7:
17018 case BFD_RELOC_THUMB_PCREL_BRANCH9:
17019 case BFD_RELOC_THUMB_PCREL_BRANCH12:
17020 case BFD_RELOC_THUMB_PCREL_BRANCH20:
17021 case BFD_RELOC_THUMB_PCREL_BRANCH23:
17022 case BFD_RELOC_THUMB_PCREL_BRANCH25:
17023 case BFD_RELOC_THUMB_PCREL_BLX:
17024 return base + 4;
bfae80f2 17025
2fc8bdac
ZW
17026 /* ARM mode branches are offset by +8. However, the Windows CE
17027 loader expects the relocation not to take this into account. */
17028 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c
PB
17029 case BFD_RELOC_ARM_PCREL_CALL:
17030 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac
ZW
17031 case BFD_RELOC_ARM_PCREL_BLX:
17032 case BFD_RELOC_ARM_PLT32:
c19d1205 17033#ifdef TE_WINCE
53baae48
NC
17034 /* When handling fixups immediately, because we have already
17035 discovered the value of a symbol, or the address of the frag involved
17036 we must account for the offset by +8, as the OS loader will never see the reloc.
17037 see fixup_segment() in write.c
17038 The S_IS_EXTERNAL test handles the case of global symbols.
17039 Those need the calculated base, not just the pipe compensation the linker will need. */
17040 if (fixP->fx_pcrel
17041 && fixP->fx_addsy != NULL
17042 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
17043 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
17044 return base + 8;
2fc8bdac 17045 return base;
c19d1205 17046#else
2fc8bdac 17047 return base + 8;
c19d1205 17048#endif
2fc8bdac
ZW
17049
17050 /* ARM mode loads relative to PC are also offset by +8. Unlike
17051 branches, the Windows CE loader *does* expect the relocation
17052 to take this into account. */
17053 case BFD_RELOC_ARM_OFFSET_IMM:
17054 case BFD_RELOC_ARM_OFFSET_IMM8:
17055 case BFD_RELOC_ARM_HWLITERAL:
17056 case BFD_RELOC_ARM_LITERAL:
17057 case BFD_RELOC_ARM_CP_OFF_IMM:
17058 return base + 8;
17059
17060
17061 /* Other PC-relative relocations are un-offset. */
17062 default:
17063 return base;
17064 }
bfae80f2
RE
17065}
17066
c19d1205
ZW
17067/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
17068 Otherwise we have no need to default values of symbols. */
17069
17070symbolS *
17071md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 17072{
c19d1205
ZW
17073#ifdef OBJ_ELF
17074 if (name[0] == '_' && name[1] == 'G'
17075 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
17076 {
17077 if (!GOT_symbol)
17078 {
17079 if (symbol_find (name))
17080 as_bad ("GOT already in the symbol table");
bfae80f2 17081
c19d1205
ZW
17082 GOT_symbol = symbol_new (name, undefined_section,
17083 (valueT) 0, & zero_address_frag);
17084 }
bfae80f2 17085
c19d1205 17086 return GOT_symbol;
bfae80f2 17087 }
c19d1205 17088#endif
bfae80f2 17089
c19d1205 17090 return 0;
bfae80f2
RE
17091}
17092
55cf6793 17093/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
17094 computed as two separate immediate values, added together. We
17095 already know that this value cannot be computed by just one ARM
17096 instruction. */
17097
17098static unsigned int
17099validate_immediate_twopart (unsigned int val,
17100 unsigned int * highpart)
bfae80f2 17101{
c19d1205
ZW
17102 unsigned int a;
17103 unsigned int i;
bfae80f2 17104
c19d1205
ZW
17105 for (i = 0; i < 32; i += 2)
17106 if (((a = rotate_left (val, i)) & 0xff) != 0)
17107 {
17108 if (a & 0xff00)
17109 {
17110 if (a & ~ 0xffff)
17111 continue;
17112 * highpart = (a >> 8) | ((i + 24) << 7);
17113 }
17114 else if (a & 0xff0000)
17115 {
17116 if (a & 0xff000000)
17117 continue;
17118 * highpart = (a >> 16) | ((i + 16) << 7);
17119 }
17120 else
17121 {
17122 assert (a & 0xff000000);
17123 * highpart = (a >> 24) | ((i + 8) << 7);
17124 }
bfae80f2 17125
c19d1205
ZW
17126 return (a & 0xff) | (i << 7);
17127 }
bfae80f2 17128
c19d1205 17129 return FAIL;
bfae80f2
RE
17130}
17131
c19d1205
ZW
17132static int
17133validate_offset_imm (unsigned int val, int hwse)
17134{
17135 if ((hwse && val > 255) || val > 4095)
17136 return FAIL;
17137 return val;
17138}
bfae80f2 17139
55cf6793 17140/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
17141 negative immediate constant by altering the instruction. A bit of
17142 a hack really.
17143 MOV <-> MVN
17144 AND <-> BIC
17145 ADC <-> SBC
17146 by inverting the second operand, and
17147 ADD <-> SUB
17148 CMP <-> CMN
17149 by negating the second operand. */
bfae80f2 17150
c19d1205
ZW
17151static int
17152negate_data_op (unsigned long * instruction,
17153 unsigned long value)
bfae80f2 17154{
c19d1205
ZW
17155 int op, new_inst;
17156 unsigned long negated, inverted;
bfae80f2 17157
c19d1205
ZW
17158 negated = encode_arm_immediate (-value);
17159 inverted = encode_arm_immediate (~value);
bfae80f2 17160
c19d1205
ZW
17161 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
17162 switch (op)
bfae80f2 17163 {
c19d1205
ZW
17164 /* First negates. */
17165 case OPCODE_SUB: /* ADD <-> SUB */
17166 new_inst = OPCODE_ADD;
17167 value = negated;
17168 break;
bfae80f2 17169
c19d1205
ZW
17170 case OPCODE_ADD:
17171 new_inst = OPCODE_SUB;
17172 value = negated;
17173 break;
bfae80f2 17174
c19d1205
ZW
17175 case OPCODE_CMP: /* CMP <-> CMN */
17176 new_inst = OPCODE_CMN;
17177 value = negated;
17178 break;
bfae80f2 17179
c19d1205
ZW
17180 case OPCODE_CMN:
17181 new_inst = OPCODE_CMP;
17182 value = negated;
17183 break;
bfae80f2 17184
c19d1205
ZW
17185 /* Now Inverted ops. */
17186 case OPCODE_MOV: /* MOV <-> MVN */
17187 new_inst = OPCODE_MVN;
17188 value = inverted;
17189 break;
bfae80f2 17190
c19d1205
ZW
17191 case OPCODE_MVN:
17192 new_inst = OPCODE_MOV;
17193 value = inverted;
17194 break;
bfae80f2 17195
c19d1205
ZW
17196 case OPCODE_AND: /* AND <-> BIC */
17197 new_inst = OPCODE_BIC;
17198 value = inverted;
17199 break;
bfae80f2 17200
c19d1205
ZW
17201 case OPCODE_BIC:
17202 new_inst = OPCODE_AND;
17203 value = inverted;
17204 break;
bfae80f2 17205
c19d1205
ZW
17206 case OPCODE_ADC: /* ADC <-> SBC */
17207 new_inst = OPCODE_SBC;
17208 value = inverted;
17209 break;
bfae80f2 17210
c19d1205
ZW
17211 case OPCODE_SBC:
17212 new_inst = OPCODE_ADC;
17213 value = inverted;
17214 break;
bfae80f2 17215
c19d1205
ZW
17216 /* We cannot do anything. */
17217 default:
17218 return FAIL;
b99bd4ef
NC
17219 }
17220
c19d1205
ZW
17221 if (value == (unsigned) FAIL)
17222 return FAIL;
17223
17224 *instruction &= OPCODE_MASK;
17225 *instruction |= new_inst << DATA_OP_SHIFT;
17226 return value;
b99bd4ef
NC
17227}
17228
ef8d22e6
PB
17229/* Like negate_data_op, but for Thumb-2. */
17230
17231static unsigned int
17232thumb32_negate_data_op (offsetT *instruction, offsetT value)
17233{
17234 int op, new_inst;
17235 int rd;
17236 offsetT negated, inverted;
17237
17238 negated = encode_thumb32_immediate (-value);
17239 inverted = encode_thumb32_immediate (~value);
17240
17241 rd = (*instruction >> 8) & 0xf;
17242 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
17243 switch (op)
17244 {
17245 /* ADD <-> SUB. Includes CMP <-> CMN. */
17246 case T2_OPCODE_SUB:
17247 new_inst = T2_OPCODE_ADD;
17248 value = negated;
17249 break;
17250
17251 case T2_OPCODE_ADD:
17252 new_inst = T2_OPCODE_SUB;
17253 value = negated;
17254 break;
17255
17256 /* ORR <-> ORN. Includes MOV <-> MVN. */
17257 case T2_OPCODE_ORR:
17258 new_inst = T2_OPCODE_ORN;
17259 value = inverted;
17260 break;
17261
17262 case T2_OPCODE_ORN:
17263 new_inst = T2_OPCODE_ORR;
17264 value = inverted;
17265 break;
17266
17267 /* AND <-> BIC. TST has no inverted equivalent. */
17268 case T2_OPCODE_AND:
17269 new_inst = T2_OPCODE_BIC;
17270 if (rd == 15)
17271 value = FAIL;
17272 else
17273 value = inverted;
17274 break;
17275
17276 case T2_OPCODE_BIC:
17277 new_inst = T2_OPCODE_AND;
17278 value = inverted;
17279 break;
17280
17281 /* ADC <-> SBC */
17282 case T2_OPCODE_ADC:
17283 new_inst = T2_OPCODE_SBC;
17284 value = inverted;
17285 break;
17286
17287 case T2_OPCODE_SBC:
17288 new_inst = T2_OPCODE_ADC;
17289 value = inverted;
17290 break;
17291
17292 /* We cannot do anything. */
17293 default:
17294 return FAIL;
17295 }
17296
17297 if (value == FAIL)
17298 return FAIL;
17299
17300 *instruction &= T2_OPCODE_MASK;
17301 *instruction |= new_inst << T2_DATA_OP_SHIFT;
17302 return value;
17303}
17304
8f06b2d8
PB
17305/* Read a 32-bit thumb instruction from buf. */
17306static unsigned long
17307get_thumb32_insn (char * buf)
17308{
17309 unsigned long insn;
17310 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
17311 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17312
17313 return insn;
17314}
17315
a8bc6c78
PB
17316
17317/* We usually want to set the low bit on the address of thumb function
17318 symbols. In particular .word foo - . should have the low bit set.
17319 Generic code tries to fold the difference of two symbols to
17320 a constant. Prevent this and force a relocation when the first symbols
17321 is a thumb function. */
17322int
17323arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
17324{
17325 if (op == O_subtract
17326 && l->X_op == O_symbol
17327 && r->X_op == O_symbol
17328 && THUMB_IS_FUNC (l->X_add_symbol))
17329 {
17330 l->X_op = O_subtract;
17331 l->X_op_symbol = r->X_add_symbol;
17332 l->X_add_number -= r->X_add_number;
17333 return 1;
17334 }
17335 /* Process as normal. */
17336 return 0;
17337}
17338
c19d1205 17339void
55cf6793 17340md_apply_fix (fixS * fixP,
c19d1205
ZW
17341 valueT * valP,
17342 segT seg)
17343{
17344 offsetT value = * valP;
17345 offsetT newval;
17346 unsigned int newimm;
17347 unsigned long temp;
17348 int sign;
17349 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 17350
c19d1205 17351 assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 17352
c19d1205 17353 /* Note whether this will delete the relocation. */
4962c51a 17354
c19d1205
ZW
17355 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
17356 fixP->fx_done = 1;
b99bd4ef 17357
adbaf948
ZW
17358 /* On a 64-bit host, silently truncate 'value' to 32 bits for
17359 consistency with the behavior on 32-bit hosts. Remember value
17360 for emit_reloc. */
17361 value &= 0xffffffff;
17362 value ^= 0x80000000;
17363 value -= 0x80000000;
17364
17365 *valP = value;
c19d1205 17366 fixP->fx_addnumber = value;
b99bd4ef 17367
adbaf948
ZW
17368 /* Same treatment for fixP->fx_offset. */
17369 fixP->fx_offset &= 0xffffffff;
17370 fixP->fx_offset ^= 0x80000000;
17371 fixP->fx_offset -= 0x80000000;
17372
c19d1205 17373 switch (fixP->fx_r_type)
b99bd4ef 17374 {
c19d1205
ZW
17375 case BFD_RELOC_NONE:
17376 /* This will need to go in the object file. */
17377 fixP->fx_done = 0;
17378 break;
b99bd4ef 17379
c19d1205
ZW
17380 case BFD_RELOC_ARM_IMMEDIATE:
17381 /* We claim that this fixup has been processed here,
17382 even if in fact we generate an error because we do
17383 not have a reloc for it, so tc_gen_reloc will reject it. */
17384 fixP->fx_done = 1;
b99bd4ef 17385
c19d1205
ZW
17386 if (fixP->fx_addsy
17387 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 17388 {
c19d1205
ZW
17389 as_bad_where (fixP->fx_file, fixP->fx_line,
17390 _("undefined symbol %s used as an immediate value"),
17391 S_GET_NAME (fixP->fx_addsy));
17392 break;
b99bd4ef
NC
17393 }
17394
c19d1205
ZW
17395 newimm = encode_arm_immediate (value);
17396 temp = md_chars_to_number (buf, INSN_SIZE);
17397
17398 /* If the instruction will fail, see if we can fix things up by
17399 changing the opcode. */
17400 if (newimm == (unsigned int) FAIL
17401 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 17402 {
c19d1205
ZW
17403 as_bad_where (fixP->fx_file, fixP->fx_line,
17404 _("invalid constant (%lx) after fixup"),
17405 (unsigned long) value);
17406 break;
b99bd4ef 17407 }
b99bd4ef 17408
c19d1205
ZW
17409 newimm |= (temp & 0xfffff000);
17410 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
17411 break;
b99bd4ef 17412
c19d1205
ZW
17413 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
17414 {
17415 unsigned int highpart = 0;
17416 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 17417
c19d1205
ZW
17418 newimm = encode_arm_immediate (value);
17419 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 17420
c19d1205
ZW
17421 /* If the instruction will fail, see if we can fix things up by
17422 changing the opcode. */
17423 if (newimm == (unsigned int) FAIL
17424 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
17425 {
17426 /* No ? OK - try using two ADD instructions to generate
17427 the value. */
17428 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 17429
c19d1205
ZW
17430 /* Yes - then make sure that the second instruction is
17431 also an add. */
17432 if (newimm != (unsigned int) FAIL)
17433 newinsn = temp;
17434 /* Still No ? Try using a negated value. */
17435 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
17436 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
17437 /* Otherwise - give up. */
17438 else
17439 {
17440 as_bad_where (fixP->fx_file, fixP->fx_line,
17441 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
17442 (long) value);
17443 break;
17444 }
b99bd4ef 17445
c19d1205
ZW
17446 /* Replace the first operand in the 2nd instruction (which
17447 is the PC) with the destination register. We have
17448 already added in the PC in the first instruction and we
17449 do not want to do it again. */
17450 newinsn &= ~ 0xf0000;
17451 newinsn |= ((newinsn & 0x0f000) << 4);
17452 }
b99bd4ef 17453
c19d1205
ZW
17454 newimm |= (temp & 0xfffff000);
17455 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 17456
c19d1205
ZW
17457 highpart |= (newinsn & 0xfffff000);
17458 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
17459 }
17460 break;
b99bd4ef 17461
c19d1205 17462 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
17463 if (!fixP->fx_done && seg->use_rela_p)
17464 value = 0;
17465
c19d1205
ZW
17466 case BFD_RELOC_ARM_LITERAL:
17467 sign = value >= 0;
b99bd4ef 17468
c19d1205
ZW
17469 if (value < 0)
17470 value = - value;
b99bd4ef 17471
c19d1205 17472 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 17473 {
c19d1205
ZW
17474 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
17475 as_bad_where (fixP->fx_file, fixP->fx_line,
17476 _("invalid literal constant: pool needs to be closer"));
17477 else
17478 as_bad_where (fixP->fx_file, fixP->fx_line,
17479 _("bad immediate value for offset (%ld)"),
17480 (long) value);
17481 break;
f03698e6
RE
17482 }
17483
c19d1205
ZW
17484 newval = md_chars_to_number (buf, INSN_SIZE);
17485 newval &= 0xff7ff000;
17486 newval |= value | (sign ? INDEX_UP : 0);
17487 md_number_to_chars (buf, newval, INSN_SIZE);
17488 break;
b99bd4ef 17489
c19d1205
ZW
17490 case BFD_RELOC_ARM_OFFSET_IMM8:
17491 case BFD_RELOC_ARM_HWLITERAL:
17492 sign = value >= 0;
b99bd4ef 17493
c19d1205
ZW
17494 if (value < 0)
17495 value = - value;
b99bd4ef 17496
c19d1205 17497 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 17498 {
c19d1205
ZW
17499 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
17500 as_bad_where (fixP->fx_file, fixP->fx_line,
17501 _("invalid literal constant: pool needs to be closer"));
17502 else
17503 as_bad (_("bad immediate value for half-word offset (%ld)"),
17504 (long) value);
17505 break;
b99bd4ef
NC
17506 }
17507
c19d1205
ZW
17508 newval = md_chars_to_number (buf, INSN_SIZE);
17509 newval &= 0xff7ff0f0;
17510 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
17511 md_number_to_chars (buf, newval, INSN_SIZE);
17512 break;
b99bd4ef 17513
c19d1205
ZW
17514 case BFD_RELOC_ARM_T32_OFFSET_U8:
17515 if (value < 0 || value > 1020 || value % 4 != 0)
17516 as_bad_where (fixP->fx_file, fixP->fx_line,
17517 _("bad immediate value for offset (%ld)"), (long) value);
17518 value /= 4;
b99bd4ef 17519
c19d1205 17520 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
17521 newval |= value;
17522 md_number_to_chars (buf+2, newval, THUMB_SIZE);
17523 break;
b99bd4ef 17524
c19d1205
ZW
17525 case BFD_RELOC_ARM_T32_OFFSET_IMM:
17526 /* This is a complicated relocation used for all varieties of Thumb32
17527 load/store instruction with immediate offset:
17528
17529 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
17530 *4, optional writeback(W)
17531 (doubleword load/store)
17532
17533 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
17534 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
17535 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
17536 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
17537 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
17538
17539 Uppercase letters indicate bits that are already encoded at
17540 this point. Lowercase letters are our problem. For the
17541 second block of instructions, the secondary opcode nybble
17542 (bits 8..11) is present, and bit 23 is zero, even if this is
17543 a PC-relative operation. */
17544 newval = md_chars_to_number (buf, THUMB_SIZE);
17545 newval <<= 16;
17546 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 17547
c19d1205 17548 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 17549 {
c19d1205
ZW
17550 /* Doubleword load/store: 8-bit offset, scaled by 4. */
17551 if (value >= 0)
17552 newval |= (1 << 23);
17553 else
17554 value = -value;
17555 if (value % 4 != 0)
17556 {
17557 as_bad_where (fixP->fx_file, fixP->fx_line,
17558 _("offset not a multiple of 4"));
17559 break;
17560 }
17561 value /= 4;
216d22bc 17562 if (value > 0xff)
c19d1205
ZW
17563 {
17564 as_bad_where (fixP->fx_file, fixP->fx_line,
17565 _("offset out of range"));
17566 break;
17567 }
17568 newval &= ~0xff;
b99bd4ef 17569 }
c19d1205 17570 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 17571 {
c19d1205
ZW
17572 /* PC-relative, 12-bit offset. */
17573 if (value >= 0)
17574 newval |= (1 << 23);
17575 else
17576 value = -value;
216d22bc 17577 if (value > 0xfff)
c19d1205
ZW
17578 {
17579 as_bad_where (fixP->fx_file, fixP->fx_line,
17580 _("offset out of range"));
17581 break;
17582 }
17583 newval &= ~0xfff;
b99bd4ef 17584 }
c19d1205 17585 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 17586 {
c19d1205
ZW
17587 /* Writeback: 8-bit, +/- offset. */
17588 if (value >= 0)
17589 newval |= (1 << 9);
17590 else
17591 value = -value;
216d22bc 17592 if (value > 0xff)
c19d1205
ZW
17593 {
17594 as_bad_where (fixP->fx_file, fixP->fx_line,
17595 _("offset out of range"));
17596 break;
17597 }
17598 newval &= ~0xff;
b99bd4ef 17599 }
c19d1205 17600 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 17601 {
c19d1205 17602 /* T-instruction: positive 8-bit offset. */
216d22bc 17603 if (value < 0 || value > 0xff)
b99bd4ef 17604 {
c19d1205
ZW
17605 as_bad_where (fixP->fx_file, fixP->fx_line,
17606 _("offset out of range"));
17607 break;
b99bd4ef 17608 }
c19d1205
ZW
17609 newval &= ~0xff;
17610 newval |= value;
b99bd4ef
NC
17611 }
17612 else
b99bd4ef 17613 {
c19d1205
ZW
17614 /* Positive 12-bit or negative 8-bit offset. */
17615 int limit;
17616 if (value >= 0)
b99bd4ef 17617 {
c19d1205
ZW
17618 newval |= (1 << 23);
17619 limit = 0xfff;
17620 }
17621 else
17622 {
17623 value = -value;
17624 limit = 0xff;
17625 }
17626 if (value > limit)
17627 {
17628 as_bad_where (fixP->fx_file, fixP->fx_line,
17629 _("offset out of range"));
17630 break;
b99bd4ef 17631 }
c19d1205 17632 newval &= ~limit;
b99bd4ef 17633 }
b99bd4ef 17634
c19d1205
ZW
17635 newval |= value;
17636 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
17637 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
17638 break;
404ff6b5 17639
c19d1205
ZW
17640 case BFD_RELOC_ARM_SHIFT_IMM:
17641 newval = md_chars_to_number (buf, INSN_SIZE);
17642 if (((unsigned long) value) > 32
17643 || (value == 32
17644 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
17645 {
17646 as_bad_where (fixP->fx_file, fixP->fx_line,
17647 _("shift expression is too large"));
17648 break;
17649 }
404ff6b5 17650
c19d1205
ZW
17651 if (value == 0)
17652 /* Shifts of zero must be done as lsl. */
17653 newval &= ~0x60;
17654 else if (value == 32)
17655 value = 0;
17656 newval &= 0xfffff07f;
17657 newval |= (value & 0x1f) << 7;
17658 md_number_to_chars (buf, newval, INSN_SIZE);
17659 break;
404ff6b5 17660
c19d1205 17661 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 17662 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 17663 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 17664 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
17665 /* We claim that this fixup has been processed here,
17666 even if in fact we generate an error because we do
17667 not have a reloc for it, so tc_gen_reloc will reject it. */
17668 fixP->fx_done = 1;
404ff6b5 17669
c19d1205
ZW
17670 if (fixP->fx_addsy
17671 && ! S_IS_DEFINED (fixP->fx_addsy))
17672 {
17673 as_bad_where (fixP->fx_file, fixP->fx_line,
17674 _("undefined symbol %s used as an immediate value"),
17675 S_GET_NAME (fixP->fx_addsy));
17676 break;
17677 }
404ff6b5 17678
c19d1205
ZW
17679 newval = md_chars_to_number (buf, THUMB_SIZE);
17680 newval <<= 16;
17681 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 17682
16805f35
PB
17683 newimm = FAIL;
17684 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
17685 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
17686 {
17687 newimm = encode_thumb32_immediate (value);
17688 if (newimm == (unsigned int) FAIL)
17689 newimm = thumb32_negate_data_op (&newval, value);
17690 }
16805f35
PB
17691 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
17692 && newimm == (unsigned int) FAIL)
92e90b6e 17693 {
16805f35
PB
17694 /* Turn add/sum into addw/subw. */
17695 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
17696 newval = (newval & 0xfeffffff) | 0x02000000;
17697
e9f89963
PB
17698 /* 12 bit immediate for addw/subw. */
17699 if (value < 0)
17700 {
17701 value = -value;
17702 newval ^= 0x00a00000;
17703 }
92e90b6e
PB
17704 if (value > 0xfff)
17705 newimm = (unsigned int) FAIL;
17706 else
17707 newimm = value;
17708 }
cc8a6dd0 17709
c19d1205 17710 if (newimm == (unsigned int)FAIL)
3631a3c8 17711 {
c19d1205
ZW
17712 as_bad_where (fixP->fx_file, fixP->fx_line,
17713 _("invalid constant (%lx) after fixup"),
17714 (unsigned long) value);
17715 break;
3631a3c8
NC
17716 }
17717
c19d1205
ZW
17718 newval |= (newimm & 0x800) << 15;
17719 newval |= (newimm & 0x700) << 4;
17720 newval |= (newimm & 0x0ff);
cc8a6dd0 17721
c19d1205
ZW
17722 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
17723 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
17724 break;
a737bd4d 17725
3eb17e6b 17726 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
17727 if (((unsigned long) value) > 0xffff)
17728 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 17729 _("invalid smc expression"));
2fc8bdac 17730 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
17731 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
17732 md_number_to_chars (buf, newval, INSN_SIZE);
17733 break;
a737bd4d 17734
c19d1205 17735 case BFD_RELOC_ARM_SWI:
adbaf948 17736 if (fixP->tc_fix_data != 0)
c19d1205
ZW
17737 {
17738 if (((unsigned long) value) > 0xff)
17739 as_bad_where (fixP->fx_file, fixP->fx_line,
17740 _("invalid swi expression"));
2fc8bdac 17741 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
17742 newval |= value;
17743 md_number_to_chars (buf, newval, THUMB_SIZE);
17744 }
17745 else
17746 {
17747 if (((unsigned long) value) > 0x00ffffff)
17748 as_bad_where (fixP->fx_file, fixP->fx_line,
17749 _("invalid swi expression"));
2fc8bdac 17750 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
17751 newval |= value;
17752 md_number_to_chars (buf, newval, INSN_SIZE);
17753 }
17754 break;
a737bd4d 17755
c19d1205
ZW
17756 case BFD_RELOC_ARM_MULTI:
17757 if (((unsigned long) value) > 0xffff)
17758 as_bad_where (fixP->fx_file, fixP->fx_line,
17759 _("invalid expression in load/store multiple"));
17760 newval = value | md_chars_to_number (buf, INSN_SIZE);
17761 md_number_to_chars (buf, newval, INSN_SIZE);
17762 break;
a737bd4d 17763
c19d1205 17764#ifdef OBJ_ELF
39b41c9c
PB
17765 case BFD_RELOC_ARM_PCREL_CALL:
17766 newval = md_chars_to_number (buf, INSN_SIZE);
17767 if ((newval & 0xf0000000) == 0xf0000000)
17768 temp = 1;
17769 else
17770 temp = 3;
17771 goto arm_branch_common;
17772
17773 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 17774 case BFD_RELOC_ARM_PLT32:
c19d1205 17775#endif
39b41c9c
PB
17776 case BFD_RELOC_ARM_PCREL_BRANCH:
17777 temp = 3;
17778 goto arm_branch_common;
a737bd4d 17779
39b41c9c
PB
17780 case BFD_RELOC_ARM_PCREL_BLX:
17781 temp = 1;
17782 arm_branch_common:
c19d1205 17783 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
17784 instruction, in a 24 bit, signed field. Bits 26 through 32 either
17785 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
17786 also be be clear. */
17787 if (value & temp)
c19d1205 17788 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
17789 _("misaligned branch destination"));
17790 if ((value & (offsetT)0xfe000000) != (offsetT)0
17791 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
17792 as_bad_where (fixP->fx_file, fixP->fx_line,
17793 _("branch out of range"));
a737bd4d 17794
2fc8bdac 17795 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 17796 {
2fc8bdac
ZW
17797 newval = md_chars_to_number (buf, INSN_SIZE);
17798 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
17799 /* Set the H bit on BLX instructions. */
17800 if (temp == 1)
17801 {
17802 if (value & 2)
17803 newval |= 0x01000000;
17804 else
17805 newval &= ~0x01000000;
17806 }
2fc8bdac 17807 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 17808 }
c19d1205 17809 break;
a737bd4d 17810
c19d1205 17811 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CZB */
2fc8bdac
ZW
17812 /* CZB can only branch forward. */
17813 if (value & ~0x7e)
17814 as_bad_where (fixP->fx_file, fixP->fx_line,
17815 _("branch out of range"));
a737bd4d 17816
2fc8bdac
ZW
17817 if (fixP->fx_done || !seg->use_rela_p)
17818 {
17819 newval = md_chars_to_number (buf, THUMB_SIZE);
080eb7fe 17820 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
2fc8bdac
ZW
17821 md_number_to_chars (buf, newval, THUMB_SIZE);
17822 }
c19d1205 17823 break;
a737bd4d 17824
c19d1205 17825 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
17826 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
17827 as_bad_where (fixP->fx_file, fixP->fx_line,
17828 _("branch out of range"));
a737bd4d 17829
2fc8bdac
ZW
17830 if (fixP->fx_done || !seg->use_rela_p)
17831 {
17832 newval = md_chars_to_number (buf, THUMB_SIZE);
17833 newval |= (value & 0x1ff) >> 1;
17834 md_number_to_chars (buf, newval, THUMB_SIZE);
17835 }
c19d1205 17836 break;
a737bd4d 17837
c19d1205 17838 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
17839 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
17840 as_bad_where (fixP->fx_file, fixP->fx_line,
17841 _("branch out of range"));
a737bd4d 17842
2fc8bdac
ZW
17843 if (fixP->fx_done || !seg->use_rela_p)
17844 {
17845 newval = md_chars_to_number (buf, THUMB_SIZE);
17846 newval |= (value & 0xfff) >> 1;
17847 md_number_to_chars (buf, newval, THUMB_SIZE);
17848 }
c19d1205 17849 break;
a737bd4d 17850
c19d1205 17851 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac
ZW
17852 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
17853 as_bad_where (fixP->fx_file, fixP->fx_line,
17854 _("conditional branch out of range"));
404ff6b5 17855
2fc8bdac
ZW
17856 if (fixP->fx_done || !seg->use_rela_p)
17857 {
17858 offsetT newval2;
17859 addressT S, J1, J2, lo, hi;
404ff6b5 17860
2fc8bdac
ZW
17861 S = (value & 0x00100000) >> 20;
17862 J2 = (value & 0x00080000) >> 19;
17863 J1 = (value & 0x00040000) >> 18;
17864 hi = (value & 0x0003f000) >> 12;
17865 lo = (value & 0x00000ffe) >> 1;
6c43fab6 17866
2fc8bdac
ZW
17867 newval = md_chars_to_number (buf, THUMB_SIZE);
17868 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17869 newval |= (S << 10) | hi;
17870 newval2 |= (J1 << 13) | (J2 << 11) | lo;
17871 md_number_to_chars (buf, newval, THUMB_SIZE);
17872 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17873 }
c19d1205 17874 break;
6c43fab6 17875
c19d1205
ZW
17876 case BFD_RELOC_THUMB_PCREL_BLX:
17877 case BFD_RELOC_THUMB_PCREL_BRANCH23:
2fc8bdac
ZW
17878 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
17879 as_bad_where (fixP->fx_file, fixP->fx_line,
17880 _("branch out of range"));
404ff6b5 17881
2fc8bdac
ZW
17882 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
17883 /* For a BLX instruction, make sure that the relocation is rounded up
17884 to a word boundary. This follows the semantics of the instruction
17885 which specifies that bit 1 of the target address will come from bit
17886 1 of the base address. */
17887 value = (value + 1) & ~ 1;
404ff6b5 17888
2fc8bdac 17889 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 17890 {
2fc8bdac
ZW
17891 offsetT newval2;
17892
17893 newval = md_chars_to_number (buf, THUMB_SIZE);
17894 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17895 newval |= (value & 0x7fffff) >> 12;
17896 newval2 |= (value & 0xfff) >> 1;
17897 md_number_to_chars (buf, newval, THUMB_SIZE);
17898 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 17899 }
c19d1205 17900 break;
404ff6b5 17901
c19d1205 17902 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
17903 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
17904 as_bad_where (fixP->fx_file, fixP->fx_line,
17905 _("branch out of range"));
6c43fab6 17906
2fc8bdac
ZW
17907 if (fixP->fx_done || !seg->use_rela_p)
17908 {
17909 offsetT newval2;
17910 addressT S, I1, I2, lo, hi;
6c43fab6 17911
2fc8bdac
ZW
17912 S = (value & 0x01000000) >> 24;
17913 I1 = (value & 0x00800000) >> 23;
17914 I2 = (value & 0x00400000) >> 22;
17915 hi = (value & 0x003ff000) >> 12;
17916 lo = (value & 0x00000ffe) >> 1;
6c43fab6 17917
2fc8bdac
ZW
17918 I1 = !(I1 ^ S);
17919 I2 = !(I2 ^ S);
a737bd4d 17920
2fc8bdac
ZW
17921 newval = md_chars_to_number (buf, THUMB_SIZE);
17922 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
17923 newval |= (S << 10) | hi;
17924 newval2 |= (I1 << 13) | (I2 << 11) | lo;
17925 md_number_to_chars (buf, newval, THUMB_SIZE);
17926 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
17927 }
17928 break;
a737bd4d 17929
2fc8bdac
ZW
17930 case BFD_RELOC_8:
17931 if (fixP->fx_done || !seg->use_rela_p)
17932 md_number_to_chars (buf, value, 1);
c19d1205 17933 break;
a737bd4d 17934
c19d1205 17935 case BFD_RELOC_16:
2fc8bdac 17936 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 17937 md_number_to_chars (buf, value, 2);
c19d1205 17938 break;
a737bd4d 17939
c19d1205
ZW
17940#ifdef OBJ_ELF
17941 case BFD_RELOC_ARM_TLS_GD32:
17942 case BFD_RELOC_ARM_TLS_LE32:
17943 case BFD_RELOC_ARM_TLS_IE32:
17944 case BFD_RELOC_ARM_TLS_LDM32:
17945 case BFD_RELOC_ARM_TLS_LDO32:
17946 S_SET_THREAD_LOCAL (fixP->fx_addsy);
17947 /* fall through */
6c43fab6 17948
c19d1205
ZW
17949 case BFD_RELOC_ARM_GOT32:
17950 case BFD_RELOC_ARM_GOTOFF:
17951 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
17952 if (fixP->fx_done || !seg->use_rela_p)
17953 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
17954 break;
17955#endif
6c43fab6 17956
c19d1205
ZW
17957 case BFD_RELOC_RVA:
17958 case BFD_RELOC_32:
17959 case BFD_RELOC_ARM_TARGET1:
17960 case BFD_RELOC_ARM_ROSEGREL32:
17961 case BFD_RELOC_ARM_SBREL32:
17962 case BFD_RELOC_32_PCREL:
f0927246
NC
17963#ifdef TE_PE
17964 case BFD_RELOC_32_SECREL:
17965#endif
2fc8bdac 17966 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
17967#ifdef TE_WINCE
17968 /* For WinCE we only do this for pcrel fixups. */
17969 if (fixP->fx_done || fixP->fx_pcrel)
17970#endif
17971 md_number_to_chars (buf, value, 4);
c19d1205 17972 break;
6c43fab6 17973
c19d1205
ZW
17974#ifdef OBJ_ELF
17975 case BFD_RELOC_ARM_PREL31:
2fc8bdac 17976 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
17977 {
17978 newval = md_chars_to_number (buf, 4) & 0x80000000;
17979 if ((value ^ (value >> 1)) & 0x40000000)
17980 {
17981 as_bad_where (fixP->fx_file, fixP->fx_line,
17982 _("rel31 relocation overflow"));
17983 }
17984 newval |= value & 0x7fffffff;
17985 md_number_to_chars (buf, newval, 4);
17986 }
17987 break;
c19d1205 17988#endif
a737bd4d 17989
c19d1205 17990 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 17991 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
17992 if (value < -1023 || value > 1023 || (value & 3))
17993 as_bad_where (fixP->fx_file, fixP->fx_line,
17994 _("co-processor offset out of range"));
17995 cp_off_common:
17996 sign = value >= 0;
17997 if (value < 0)
17998 value = -value;
8f06b2d8
PB
17999 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18000 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18001 newval = md_chars_to_number (buf, INSN_SIZE);
18002 else
18003 newval = get_thumb32_insn (buf);
18004 newval &= 0xff7fff00;
c19d1205
ZW
18005 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
18006 if (value == 0)
18007 newval &= ~WRITE_BACK;
8f06b2d8
PB
18008 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
18009 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
18010 md_number_to_chars (buf, newval, INSN_SIZE);
18011 else
18012 put_thumb32_insn (buf, newval);
c19d1205 18013 break;
a737bd4d 18014
c19d1205 18015 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 18016 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
18017 if (value < -255 || value > 255)
18018 as_bad_where (fixP->fx_file, fixP->fx_line,
18019 _("co-processor offset out of range"));
df7849c5 18020 value *= 4;
c19d1205 18021 goto cp_off_common;
6c43fab6 18022
c19d1205
ZW
18023 case BFD_RELOC_ARM_THUMB_OFFSET:
18024 newval = md_chars_to_number (buf, THUMB_SIZE);
18025 /* Exactly what ranges, and where the offset is inserted depends
18026 on the type of instruction, we can establish this from the
18027 top 4 bits. */
18028 switch (newval >> 12)
18029 {
18030 case 4: /* PC load. */
18031 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
18032 forced to zero for these loads; md_pcrel_from has already
18033 compensated for this. */
18034 if (value & 3)
18035 as_bad_where (fixP->fx_file, fixP->fx_line,
18036 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
18037 (((unsigned long) fixP->fx_frag->fr_address
18038 + (unsigned long) fixP->fx_where) & ~3)
18039 + (unsigned long) value);
a737bd4d 18040
c19d1205
ZW
18041 if (value & ~0x3fc)
18042 as_bad_where (fixP->fx_file, fixP->fx_line,
18043 _("invalid offset, value too big (0x%08lX)"),
18044 (long) value);
a737bd4d 18045
c19d1205
ZW
18046 newval |= value >> 2;
18047 break;
a737bd4d 18048
c19d1205
ZW
18049 case 9: /* SP load/store. */
18050 if (value & ~0x3fc)
18051 as_bad_where (fixP->fx_file, fixP->fx_line,
18052 _("invalid offset, value too big (0x%08lX)"),
18053 (long) value);
18054 newval |= value >> 2;
18055 break;
6c43fab6 18056
c19d1205
ZW
18057 case 6: /* Word load/store. */
18058 if (value & ~0x7c)
18059 as_bad_where (fixP->fx_file, fixP->fx_line,
18060 _("invalid offset, value too big (0x%08lX)"),
18061 (long) value);
18062 newval |= value << 4; /* 6 - 2. */
18063 break;
a737bd4d 18064
c19d1205
ZW
18065 case 7: /* Byte load/store. */
18066 if (value & ~0x1f)
18067 as_bad_where (fixP->fx_file, fixP->fx_line,
18068 _("invalid offset, value too big (0x%08lX)"),
18069 (long) value);
18070 newval |= value << 6;
18071 break;
a737bd4d 18072
c19d1205
ZW
18073 case 8: /* Halfword load/store. */
18074 if (value & ~0x3e)
18075 as_bad_where (fixP->fx_file, fixP->fx_line,
18076 _("invalid offset, value too big (0x%08lX)"),
18077 (long) value);
18078 newval |= value << 5; /* 6 - 1. */
18079 break;
a737bd4d 18080
c19d1205
ZW
18081 default:
18082 as_bad_where (fixP->fx_file, fixP->fx_line,
18083 "Unable to process relocation for thumb opcode: %lx",
18084 (unsigned long) newval);
18085 break;
18086 }
18087 md_number_to_chars (buf, newval, THUMB_SIZE);
18088 break;
a737bd4d 18089
c19d1205
ZW
18090 case BFD_RELOC_ARM_THUMB_ADD:
18091 /* This is a complicated relocation, since we use it for all of
18092 the following immediate relocations:
a737bd4d 18093
c19d1205
ZW
18094 3bit ADD/SUB
18095 8bit ADD/SUB
18096 9bit ADD/SUB SP word-aligned
18097 10bit ADD PC/SP word-aligned
a737bd4d 18098
c19d1205
ZW
18099 The type of instruction being processed is encoded in the
18100 instruction field:
a737bd4d 18101
c19d1205
ZW
18102 0x8000 SUB
18103 0x00F0 Rd
18104 0x000F Rs
18105 */
18106 newval = md_chars_to_number (buf, THUMB_SIZE);
18107 {
18108 int rd = (newval >> 4) & 0xf;
18109 int rs = newval & 0xf;
18110 int subtract = !!(newval & 0x8000);
a737bd4d 18111
c19d1205
ZW
18112 /* Check for HI regs, only very restricted cases allowed:
18113 Adjusting SP, and using PC or SP to get an address. */
18114 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
18115 || (rs > 7 && rs != REG_SP && rs != REG_PC))
18116 as_bad_where (fixP->fx_file, fixP->fx_line,
18117 _("invalid Hi register with immediate"));
a737bd4d 18118
c19d1205
ZW
18119 /* If value is negative, choose the opposite instruction. */
18120 if (value < 0)
18121 {
18122 value = -value;
18123 subtract = !subtract;
18124 if (value < 0)
18125 as_bad_where (fixP->fx_file, fixP->fx_line,
18126 _("immediate value out of range"));
18127 }
a737bd4d 18128
c19d1205
ZW
18129 if (rd == REG_SP)
18130 {
18131 if (value & ~0x1fc)
18132 as_bad_where (fixP->fx_file, fixP->fx_line,
18133 _("invalid immediate for stack address calculation"));
18134 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
18135 newval |= value >> 2;
18136 }
18137 else if (rs == REG_PC || rs == REG_SP)
18138 {
18139 if (subtract || value & ~0x3fc)
18140 as_bad_where (fixP->fx_file, fixP->fx_line,
18141 _("invalid immediate for address calculation (value = 0x%08lX)"),
18142 (unsigned long) value);
18143 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
18144 newval |= rd << 8;
18145 newval |= value >> 2;
18146 }
18147 else if (rs == rd)
18148 {
18149 if (value & ~0xff)
18150 as_bad_where (fixP->fx_file, fixP->fx_line,
18151 _("immediate value out of range"));
18152 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
18153 newval |= (rd << 8) | value;
18154 }
18155 else
18156 {
18157 if (value & ~0x7)
18158 as_bad_where (fixP->fx_file, fixP->fx_line,
18159 _("immediate value out of range"));
18160 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
18161 newval |= rd | (rs << 3) | (value << 6);
18162 }
18163 }
18164 md_number_to_chars (buf, newval, THUMB_SIZE);
18165 break;
a737bd4d 18166
c19d1205
ZW
18167 case BFD_RELOC_ARM_THUMB_IMM:
18168 newval = md_chars_to_number (buf, THUMB_SIZE);
18169 if (value < 0 || value > 255)
18170 as_bad_where (fixP->fx_file, fixP->fx_line,
18171 _("invalid immediate: %ld is too large"),
18172 (long) value);
18173 newval |= value;
18174 md_number_to_chars (buf, newval, THUMB_SIZE);
18175 break;
a737bd4d 18176
c19d1205
ZW
18177 case BFD_RELOC_ARM_THUMB_SHIFT:
18178 /* 5bit shift value (0..32). LSL cannot take 32. */
18179 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
18180 temp = newval & 0xf800;
18181 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
18182 as_bad_where (fixP->fx_file, fixP->fx_line,
18183 _("invalid shift value: %ld"), (long) value);
18184 /* Shifts of zero must be encoded as LSL. */
18185 if (value == 0)
18186 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
18187 /* Shifts of 32 are encoded as zero. */
18188 else if (value == 32)
18189 value = 0;
18190 newval |= value << 6;
18191 md_number_to_chars (buf, newval, THUMB_SIZE);
18192 break;
a737bd4d 18193
c19d1205
ZW
18194 case BFD_RELOC_VTABLE_INHERIT:
18195 case BFD_RELOC_VTABLE_ENTRY:
18196 fixP->fx_done = 0;
18197 return;
6c43fab6 18198
b6895b4f
PB
18199 case BFD_RELOC_ARM_MOVW:
18200 case BFD_RELOC_ARM_MOVT:
18201 case BFD_RELOC_ARM_THUMB_MOVW:
18202 case BFD_RELOC_ARM_THUMB_MOVT:
18203 if (fixP->fx_done || !seg->use_rela_p)
18204 {
18205 /* REL format relocations are limited to a 16-bit addend. */
18206 if (!fixP->fx_done)
18207 {
18208 if (value < -0x1000 || value > 0xffff)
18209 as_bad_where (fixP->fx_file, fixP->fx_line,
18210 _("offset too big"));
18211 }
18212 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
18213 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18214 {
18215 value >>= 16;
18216 }
18217
18218 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
18219 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
18220 {
18221 newval = get_thumb32_insn (buf);
18222 newval &= 0xfbf08f00;
18223 newval |= (value & 0xf000) << 4;
18224 newval |= (value & 0x0800) << 15;
18225 newval |= (value & 0x0700) << 4;
18226 newval |= (value & 0x00ff);
18227 put_thumb32_insn (buf, newval);
18228 }
18229 else
18230 {
18231 newval = md_chars_to_number (buf, 4);
18232 newval &= 0xfff0f000;
18233 newval |= value & 0x0fff;
18234 newval |= (value & 0xf000) << 4;
18235 md_number_to_chars (buf, newval, 4);
18236 }
18237 }
18238 return;
18239
4962c51a
MS
18240 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18241 case BFD_RELOC_ARM_ALU_PC_G0:
18242 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18243 case BFD_RELOC_ARM_ALU_PC_G1:
18244 case BFD_RELOC_ARM_ALU_PC_G2:
18245 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18246 case BFD_RELOC_ARM_ALU_SB_G0:
18247 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18248 case BFD_RELOC_ARM_ALU_SB_G1:
18249 case BFD_RELOC_ARM_ALU_SB_G2:
18250 assert (!fixP->fx_done);
18251 if (!seg->use_rela_p)
18252 {
18253 bfd_vma insn;
18254 bfd_vma encoded_addend;
18255 bfd_vma addend_abs = abs (value);
18256
18257 /* Check that the absolute value of the addend can be
18258 expressed as an 8-bit constant plus a rotation. */
18259 encoded_addend = encode_arm_immediate (addend_abs);
18260 if (encoded_addend == (unsigned int) FAIL)
18261 as_bad_where (fixP->fx_file, fixP->fx_line,
18262 _("the offset 0x%08lX is not representable"),
18263 addend_abs);
18264
18265 /* Extract the instruction. */
18266 insn = md_chars_to_number (buf, INSN_SIZE);
18267
18268 /* If the addend is positive, use an ADD instruction.
18269 Otherwise use a SUB. Take care not to destroy the S bit. */
18270 insn &= 0xff1fffff;
18271 if (value < 0)
18272 insn |= 1 << 22;
18273 else
18274 insn |= 1 << 23;
18275
18276 /* Place the encoded addend into the first 12 bits of the
18277 instruction. */
18278 insn &= 0xfffff000;
18279 insn |= encoded_addend;
18280
18281 /* Update the instruction. */
18282 md_number_to_chars (buf, insn, INSN_SIZE);
18283 }
18284 break;
18285
18286 case BFD_RELOC_ARM_LDR_PC_G0:
18287 case BFD_RELOC_ARM_LDR_PC_G1:
18288 case BFD_RELOC_ARM_LDR_PC_G2:
18289 case BFD_RELOC_ARM_LDR_SB_G0:
18290 case BFD_RELOC_ARM_LDR_SB_G1:
18291 case BFD_RELOC_ARM_LDR_SB_G2:
18292 assert (!fixP->fx_done);
18293 if (!seg->use_rela_p)
18294 {
18295 bfd_vma insn;
18296 bfd_vma addend_abs = abs (value);
18297
18298 /* Check that the absolute value of the addend can be
18299 encoded in 12 bits. */
18300 if (addend_abs >= 0x1000)
18301 as_bad_where (fixP->fx_file, fixP->fx_line,
18302 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
18303 addend_abs);
18304
18305 /* Extract the instruction. */
18306 insn = md_chars_to_number (buf, INSN_SIZE);
18307
18308 /* If the addend is negative, clear bit 23 of the instruction.
18309 Otherwise set it. */
18310 if (value < 0)
18311 insn &= ~(1 << 23);
18312 else
18313 insn |= 1 << 23;
18314
18315 /* Place the absolute value of the addend into the first 12 bits
18316 of the instruction. */
18317 insn &= 0xfffff000;
18318 insn |= addend_abs;
18319
18320 /* Update the instruction. */
18321 md_number_to_chars (buf, insn, INSN_SIZE);
18322 }
18323 break;
18324
18325 case BFD_RELOC_ARM_LDRS_PC_G0:
18326 case BFD_RELOC_ARM_LDRS_PC_G1:
18327 case BFD_RELOC_ARM_LDRS_PC_G2:
18328 case BFD_RELOC_ARM_LDRS_SB_G0:
18329 case BFD_RELOC_ARM_LDRS_SB_G1:
18330 case BFD_RELOC_ARM_LDRS_SB_G2:
18331 assert (!fixP->fx_done);
18332 if (!seg->use_rela_p)
18333 {
18334 bfd_vma insn;
18335 bfd_vma addend_abs = abs (value);
18336
18337 /* Check that the absolute value of the addend can be
18338 encoded in 8 bits. */
18339 if (addend_abs >= 0x100)
18340 as_bad_where (fixP->fx_file, fixP->fx_line,
18341 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
18342 addend_abs);
18343
18344 /* Extract the instruction. */
18345 insn = md_chars_to_number (buf, INSN_SIZE);
18346
18347 /* If the addend is negative, clear bit 23 of the instruction.
18348 Otherwise set it. */
18349 if (value < 0)
18350 insn &= ~(1 << 23);
18351 else
18352 insn |= 1 << 23;
18353
18354 /* Place the first four bits of the absolute value of the addend
18355 into the first 4 bits of the instruction, and the remaining
18356 four into bits 8 .. 11. */
18357 insn &= 0xfffff0f0;
18358 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
18359
18360 /* Update the instruction. */
18361 md_number_to_chars (buf, insn, INSN_SIZE);
18362 }
18363 break;
18364
18365 case BFD_RELOC_ARM_LDC_PC_G0:
18366 case BFD_RELOC_ARM_LDC_PC_G1:
18367 case BFD_RELOC_ARM_LDC_PC_G2:
18368 case BFD_RELOC_ARM_LDC_SB_G0:
18369 case BFD_RELOC_ARM_LDC_SB_G1:
18370 case BFD_RELOC_ARM_LDC_SB_G2:
18371 assert (!fixP->fx_done);
18372 if (!seg->use_rela_p)
18373 {
18374 bfd_vma insn;
18375 bfd_vma addend_abs = abs (value);
18376
18377 /* Check that the absolute value of the addend is a multiple of
18378 four and, when divided by four, fits in 8 bits. */
18379 if (addend_abs & 0x3)
18380 as_bad_where (fixP->fx_file, fixP->fx_line,
18381 _("bad offset 0x%08lX (must be word-aligned)"),
18382 addend_abs);
18383
18384 if ((addend_abs >> 2) > 0xff)
18385 as_bad_where (fixP->fx_file, fixP->fx_line,
18386 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
18387 addend_abs);
18388
18389 /* Extract the instruction. */
18390 insn = md_chars_to_number (buf, INSN_SIZE);
18391
18392 /* If the addend is negative, clear bit 23 of the instruction.
18393 Otherwise set it. */
18394 if (value < 0)
18395 insn &= ~(1 << 23);
18396 else
18397 insn |= 1 << 23;
18398
18399 /* Place the addend (divided by four) into the first eight
18400 bits of the instruction. */
18401 insn &= 0xfffffff0;
18402 insn |= addend_abs >> 2;
18403
18404 /* Update the instruction. */
18405 md_number_to_chars (buf, insn, INSN_SIZE);
18406 }
18407 break;
18408
c19d1205
ZW
18409 case BFD_RELOC_UNUSED:
18410 default:
18411 as_bad_where (fixP->fx_file, fixP->fx_line,
18412 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
18413 }
6c43fab6
RE
18414}
18415
c19d1205
ZW
18416/* Translate internal representation of relocation info to BFD target
18417 format. */
a737bd4d 18418
c19d1205 18419arelent *
00a97672 18420tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 18421{
c19d1205
ZW
18422 arelent * reloc;
18423 bfd_reloc_code_real_type code;
a737bd4d 18424
c19d1205 18425 reloc = xmalloc (sizeof (arelent));
a737bd4d 18426
c19d1205
ZW
18427 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
18428 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
18429 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 18430
2fc8bdac 18431 if (fixp->fx_pcrel)
00a97672
RS
18432 {
18433 if (section->use_rela_p)
18434 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
18435 else
18436 fixp->fx_offset = reloc->address;
18437 }
c19d1205 18438 reloc->addend = fixp->fx_offset;
a737bd4d 18439
c19d1205 18440 switch (fixp->fx_r_type)
a737bd4d 18441 {
c19d1205
ZW
18442 case BFD_RELOC_8:
18443 if (fixp->fx_pcrel)
18444 {
18445 code = BFD_RELOC_8_PCREL;
18446 break;
18447 }
a737bd4d 18448
c19d1205
ZW
18449 case BFD_RELOC_16:
18450 if (fixp->fx_pcrel)
18451 {
18452 code = BFD_RELOC_16_PCREL;
18453 break;
18454 }
6c43fab6 18455
c19d1205
ZW
18456 case BFD_RELOC_32:
18457 if (fixp->fx_pcrel)
18458 {
18459 code = BFD_RELOC_32_PCREL;
18460 break;
18461 }
a737bd4d 18462
b6895b4f
PB
18463 case BFD_RELOC_ARM_MOVW:
18464 if (fixp->fx_pcrel)
18465 {
18466 code = BFD_RELOC_ARM_MOVW_PCREL;
18467 break;
18468 }
18469
18470 case BFD_RELOC_ARM_MOVT:
18471 if (fixp->fx_pcrel)
18472 {
18473 code = BFD_RELOC_ARM_MOVT_PCREL;
18474 break;
18475 }
18476
18477 case BFD_RELOC_ARM_THUMB_MOVW:
18478 if (fixp->fx_pcrel)
18479 {
18480 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
18481 break;
18482 }
18483
18484 case BFD_RELOC_ARM_THUMB_MOVT:
18485 if (fixp->fx_pcrel)
18486 {
18487 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
18488 break;
18489 }
18490
c19d1205
ZW
18491 case BFD_RELOC_NONE:
18492 case BFD_RELOC_ARM_PCREL_BRANCH:
18493 case BFD_RELOC_ARM_PCREL_BLX:
18494 case BFD_RELOC_RVA:
18495 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18496 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18497 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18498 case BFD_RELOC_THUMB_PCREL_BRANCH20:
18499 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18500 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18501 case BFD_RELOC_THUMB_PCREL_BLX:
18502 case BFD_RELOC_VTABLE_ENTRY:
18503 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
18504#ifdef TE_PE
18505 case BFD_RELOC_32_SECREL:
18506#endif
c19d1205
ZW
18507 code = fixp->fx_r_type;
18508 break;
a737bd4d 18509
c19d1205
ZW
18510 case BFD_RELOC_ARM_LITERAL:
18511 case BFD_RELOC_ARM_HWLITERAL:
18512 /* If this is called then the a literal has
18513 been referenced across a section boundary. */
18514 as_bad_where (fixp->fx_file, fixp->fx_line,
18515 _("literal referenced across section boundary"));
18516 return NULL;
a737bd4d 18517
c19d1205
ZW
18518#ifdef OBJ_ELF
18519 case BFD_RELOC_ARM_GOT32:
18520 case BFD_RELOC_ARM_GOTOFF:
18521 case BFD_RELOC_ARM_PLT32:
18522 case BFD_RELOC_ARM_TARGET1:
18523 case BFD_RELOC_ARM_ROSEGREL32:
18524 case BFD_RELOC_ARM_SBREL32:
18525 case BFD_RELOC_ARM_PREL31:
18526 case BFD_RELOC_ARM_TARGET2:
18527 case BFD_RELOC_ARM_TLS_LE32:
18528 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
18529 case BFD_RELOC_ARM_PCREL_CALL:
18530 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
18531 case BFD_RELOC_ARM_ALU_PC_G0_NC:
18532 case BFD_RELOC_ARM_ALU_PC_G0:
18533 case BFD_RELOC_ARM_ALU_PC_G1_NC:
18534 case BFD_RELOC_ARM_ALU_PC_G1:
18535 case BFD_RELOC_ARM_ALU_PC_G2:
18536 case BFD_RELOC_ARM_LDR_PC_G0:
18537 case BFD_RELOC_ARM_LDR_PC_G1:
18538 case BFD_RELOC_ARM_LDR_PC_G2:
18539 case BFD_RELOC_ARM_LDRS_PC_G0:
18540 case BFD_RELOC_ARM_LDRS_PC_G1:
18541 case BFD_RELOC_ARM_LDRS_PC_G2:
18542 case BFD_RELOC_ARM_LDC_PC_G0:
18543 case BFD_RELOC_ARM_LDC_PC_G1:
18544 case BFD_RELOC_ARM_LDC_PC_G2:
18545 case BFD_RELOC_ARM_ALU_SB_G0_NC:
18546 case BFD_RELOC_ARM_ALU_SB_G0:
18547 case BFD_RELOC_ARM_ALU_SB_G1_NC:
18548 case BFD_RELOC_ARM_ALU_SB_G1:
18549 case BFD_RELOC_ARM_ALU_SB_G2:
18550 case BFD_RELOC_ARM_LDR_SB_G0:
18551 case BFD_RELOC_ARM_LDR_SB_G1:
18552 case BFD_RELOC_ARM_LDR_SB_G2:
18553 case BFD_RELOC_ARM_LDRS_SB_G0:
18554 case BFD_RELOC_ARM_LDRS_SB_G1:
18555 case BFD_RELOC_ARM_LDRS_SB_G2:
18556 case BFD_RELOC_ARM_LDC_SB_G0:
18557 case BFD_RELOC_ARM_LDC_SB_G1:
18558 case BFD_RELOC_ARM_LDC_SB_G2:
c19d1205
ZW
18559 code = fixp->fx_r_type;
18560 break;
a737bd4d 18561
c19d1205
ZW
18562 case BFD_RELOC_ARM_TLS_GD32:
18563 case BFD_RELOC_ARM_TLS_IE32:
18564 case BFD_RELOC_ARM_TLS_LDM32:
18565 /* BFD will include the symbol's address in the addend.
18566 But we don't want that, so subtract it out again here. */
18567 if (!S_IS_COMMON (fixp->fx_addsy))
18568 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
18569 code = fixp->fx_r_type;
18570 break;
18571#endif
a737bd4d 18572
c19d1205
ZW
18573 case BFD_RELOC_ARM_IMMEDIATE:
18574 as_bad_where (fixp->fx_file, fixp->fx_line,
18575 _("internal relocation (type: IMMEDIATE) not fixed up"));
18576 return NULL;
a737bd4d 18577
c19d1205
ZW
18578 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
18579 as_bad_where (fixp->fx_file, fixp->fx_line,
18580 _("ADRL used for a symbol not defined in the same file"));
18581 return NULL;
a737bd4d 18582
c19d1205 18583 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
18584 if (section->use_rela_p)
18585 {
18586 code = fixp->fx_r_type;
18587 break;
18588 }
18589
c19d1205
ZW
18590 if (fixp->fx_addsy != NULL
18591 && !S_IS_DEFINED (fixp->fx_addsy)
18592 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 18593 {
c19d1205
ZW
18594 as_bad_where (fixp->fx_file, fixp->fx_line,
18595 _("undefined local label `%s'"),
18596 S_GET_NAME (fixp->fx_addsy));
18597 return NULL;
a737bd4d
NC
18598 }
18599
c19d1205
ZW
18600 as_bad_where (fixp->fx_file, fixp->fx_line,
18601 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
18602 return NULL;
a737bd4d 18603
c19d1205
ZW
18604 default:
18605 {
18606 char * type;
6c43fab6 18607
c19d1205
ZW
18608 switch (fixp->fx_r_type)
18609 {
18610 case BFD_RELOC_NONE: type = "NONE"; break;
18611 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
18612 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 18613 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
18614 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
18615 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
18616 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 18617 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
18618 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
18619 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
18620 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
18621 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
18622 default: type = _("<unknown>"); break;
18623 }
18624 as_bad_where (fixp->fx_file, fixp->fx_line,
18625 _("cannot represent %s relocation in this object file format"),
18626 type);
18627 return NULL;
18628 }
a737bd4d 18629 }
6c43fab6 18630
c19d1205
ZW
18631#ifdef OBJ_ELF
18632 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
18633 && GOT_symbol
18634 && fixp->fx_addsy == GOT_symbol)
18635 {
18636 code = BFD_RELOC_ARM_GOTPC;
18637 reloc->addend = fixp->fx_offset = reloc->address;
18638 }
18639#endif
6c43fab6 18640
c19d1205 18641 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 18642
c19d1205
ZW
18643 if (reloc->howto == NULL)
18644 {
18645 as_bad_where (fixp->fx_file, fixp->fx_line,
18646 _("cannot represent %s relocation in this object file format"),
18647 bfd_get_reloc_code_name (code));
18648 return NULL;
18649 }
6c43fab6 18650
c19d1205
ZW
18651 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
18652 vtable entry to be used in the relocation's section offset. */
18653 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18654 reloc->address = fixp->fx_offset;
6c43fab6 18655
c19d1205 18656 return reloc;
6c43fab6
RE
18657}
18658
c19d1205 18659/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 18660
c19d1205
ZW
18661void
18662cons_fix_new_arm (fragS * frag,
18663 int where,
18664 int size,
18665 expressionS * exp)
6c43fab6 18666{
c19d1205
ZW
18667 bfd_reloc_code_real_type type;
18668 int pcrel = 0;
6c43fab6 18669
c19d1205
ZW
18670 /* Pick a reloc.
18671 FIXME: @@ Should look at CPU word size. */
18672 switch (size)
18673 {
18674 case 1:
18675 type = BFD_RELOC_8;
18676 break;
18677 case 2:
18678 type = BFD_RELOC_16;
18679 break;
18680 case 4:
18681 default:
18682 type = BFD_RELOC_32;
18683 break;
18684 case 8:
18685 type = BFD_RELOC_64;
18686 break;
18687 }
6c43fab6 18688
f0927246
NC
18689#ifdef TE_PE
18690 if (exp->X_op == O_secrel)
18691 {
18692 exp->X_op = O_symbol;
18693 type = BFD_RELOC_32_SECREL;
18694 }
18695#endif
18696
c19d1205
ZW
18697 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
18698}
6c43fab6 18699
c19d1205
ZW
18700#if defined OBJ_COFF || defined OBJ_ELF
18701void
18702arm_validate_fix (fixS * fixP)
6c43fab6 18703{
c19d1205
ZW
18704 /* If the destination of the branch is a defined symbol which does not have
18705 the THUMB_FUNC attribute, then we must be calling a function which has
18706 the (interfacearm) attribute. We look for the Thumb entry point to that
18707 function and change the branch to refer to that function instead. */
18708 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
18709 && fixP->fx_addsy != NULL
18710 && S_IS_DEFINED (fixP->fx_addsy)
18711 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 18712 {
c19d1205 18713 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 18714 }
c19d1205
ZW
18715}
18716#endif
6c43fab6 18717
c19d1205
ZW
18718int
18719arm_force_relocation (struct fix * fixp)
18720{
18721#if defined (OBJ_COFF) && defined (TE_PE)
18722 if (fixp->fx_r_type == BFD_RELOC_RVA)
18723 return 1;
18724#endif
6c43fab6 18725
c19d1205
ZW
18726 /* Resolve these relocations even if the symbol is extern or weak. */
18727 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
18728 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 18729 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 18730 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
18731 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
18732 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
18733 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 18734 return 0;
a737bd4d 18735
4962c51a
MS
18736 /* Always leave these relocations for the linker. */
18737 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18738 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18739 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18740 return 1;
18741
c19d1205 18742 return generic_force_reloc (fixp);
404ff6b5
AH
18743}
18744
c19d1205 18745#ifdef OBJ_COFF
c19d1205
ZW
18746bfd_boolean
18747arm_fix_adjustable (fixS * fixP)
404ff6b5 18748{
337ff0a5
NC
18749 /* This is a little hack to help the gas/arm/adrl.s test. It prevents
18750 local labels from being added to the output symbol table when they
18751 are used with the ADRL pseudo op. The ADRL relocation should always
18752 be resolved before the binbary is emitted, so it is safe to say that
18753 it is adjustable. */
c19d1205
ZW
18754 if (fixP->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE)
18755 return 1;
337ff0a5
NC
18756
18757 /* This is a hack for the gas/all/redef2.s test. This test causes symbols
18758 to be cloned, and without this test relocs would still be generated
6e0080dd 18759 against the original, pre-cloned symbol. Such symbols would not appear
337ff0a5
NC
18760 in the symbol table however, and so a valid reloc could not be
18761 generated. So check to see if the fixup is against a symbol which has
18762 been removed from the symbol chain, and if it is, then allow it to be
18763 adjusted into a reloc against a section symbol. */
6e0080dd
NC
18764 if (fixP->fx_addsy != NULL
18765 && ! S_IS_LOCAL (fixP->fx_addsy)
18766 && symbol_next (fixP->fx_addsy) == NULL
18767 && symbol_next (fixP->fx_addsy) == symbol_previous (fixP->fx_addsy))
18768 return 1;
337ff0a5 18769
c19d1205 18770 return 0;
404ff6b5 18771}
c19d1205 18772#endif
404ff6b5 18773
c19d1205 18774#ifdef OBJ_ELF
e28387c3
PB
18775/* Relocations against function names must be left unadjusted,
18776 so that the linker can use this information to generate interworking
18777 stubs. The MIPS version of this function
c19d1205
ZW
18778 also prevents relocations that are mips-16 specific, but I do not
18779 know why it does this.
404ff6b5 18780
c19d1205
ZW
18781 FIXME:
18782 There is one other problem that ought to be addressed here, but
18783 which currently is not: Taking the address of a label (rather
18784 than a function) and then later jumping to that address. Such
18785 addresses also ought to have their bottom bit set (assuming that
18786 they reside in Thumb code), but at the moment they will not. */
404ff6b5 18787
c19d1205
ZW
18788bfd_boolean
18789arm_fix_adjustable (fixS * fixP)
404ff6b5 18790{
c19d1205
ZW
18791 if (fixP->fx_addsy == NULL)
18792 return 1;
404ff6b5 18793
e28387c3
PB
18794 /* Preserve relocations against symbols with function type. */
18795 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
18796 return 0;
18797
c19d1205
ZW
18798 if (THUMB_IS_FUNC (fixP->fx_addsy)
18799 && fixP->fx_subsy == NULL)
18800 return 0;
a737bd4d 18801
c19d1205
ZW
18802 /* We need the symbol name for the VTABLE entries. */
18803 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
18804 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
18805 return 0;
404ff6b5 18806
c19d1205
ZW
18807 /* Don't allow symbols to be discarded on GOT related relocs. */
18808 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
18809 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
18810 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
18811 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
18812 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
18813 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
18814 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
18815 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
18816 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
18817 return 0;
a737bd4d 18818
4962c51a
MS
18819 /* Similarly for group relocations. */
18820 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
18821 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
18822 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
18823 return 0;
18824
c19d1205 18825 return 1;
a737bd4d 18826}
404ff6b5 18827
c19d1205
ZW
18828const char *
18829elf32_arm_target_format (void)
404ff6b5 18830{
c19d1205
ZW
18831#ifdef TE_SYMBIAN
18832 return (target_big_endian
18833 ? "elf32-bigarm-symbian"
18834 : "elf32-littlearm-symbian");
18835#elif defined (TE_VXWORKS)
18836 return (target_big_endian
18837 ? "elf32-bigarm-vxworks"
18838 : "elf32-littlearm-vxworks");
18839#else
18840 if (target_big_endian)
18841 return "elf32-bigarm";
18842 else
18843 return "elf32-littlearm";
18844#endif
404ff6b5
AH
18845}
18846
c19d1205
ZW
18847void
18848armelf_frob_symbol (symbolS * symp,
18849 int * puntp)
404ff6b5 18850{
c19d1205
ZW
18851 elf_frob_symbol (symp, puntp);
18852}
18853#endif
404ff6b5 18854
c19d1205 18855/* MD interface: Finalization. */
a737bd4d 18856
c19d1205
ZW
18857/* A good place to do this, although this was probably not intended
18858 for this kind of use. We need to dump the literal pool before
18859 references are made to a null symbol pointer. */
a737bd4d 18860
c19d1205
ZW
18861void
18862arm_cleanup (void)
18863{
18864 literal_pool * pool;
a737bd4d 18865
c19d1205
ZW
18866 for (pool = list_of_pools; pool; pool = pool->next)
18867 {
18868 /* Put it at the end of the relevent section. */
18869 subseg_set (pool->section, pool->sub_section);
18870#ifdef OBJ_ELF
18871 arm_elf_change_section ();
18872#endif
18873 s_ltorg (0);
18874 }
404ff6b5
AH
18875}
18876
c19d1205
ZW
18877/* Adjust the symbol table. This marks Thumb symbols as distinct from
18878 ARM ones. */
404ff6b5 18879
c19d1205
ZW
18880void
18881arm_adjust_symtab (void)
404ff6b5 18882{
c19d1205
ZW
18883#ifdef OBJ_COFF
18884 symbolS * sym;
404ff6b5 18885
c19d1205
ZW
18886 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
18887 {
18888 if (ARM_IS_THUMB (sym))
18889 {
18890 if (THUMB_IS_FUNC (sym))
18891 {
18892 /* Mark the symbol as a Thumb function. */
18893 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
18894 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
18895 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 18896
c19d1205
ZW
18897 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
18898 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
18899 else
18900 as_bad (_("%s: unexpected function type: %d"),
18901 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
18902 }
18903 else switch (S_GET_STORAGE_CLASS (sym))
18904 {
18905 case C_EXT:
18906 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
18907 break;
18908 case C_STAT:
18909 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
18910 break;
18911 case C_LABEL:
18912 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
18913 break;
18914 default:
18915 /* Do nothing. */
18916 break;
18917 }
18918 }
a737bd4d 18919
c19d1205
ZW
18920 if (ARM_IS_INTERWORK (sym))
18921 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 18922 }
c19d1205
ZW
18923#endif
18924#ifdef OBJ_ELF
18925 symbolS * sym;
18926 char bind;
404ff6b5 18927
c19d1205 18928 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 18929 {
c19d1205
ZW
18930 if (ARM_IS_THUMB (sym))
18931 {
18932 elf_symbol_type * elf_sym;
404ff6b5 18933
c19d1205
ZW
18934 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
18935 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 18936
b0796911
PB
18937 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
18938 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
18939 {
18940 /* If it's a .thumb_func, declare it as so,
18941 otherwise tag label as .code 16. */
18942 if (THUMB_IS_FUNC (sym))
18943 elf_sym->internal_elf_sym.st_info =
18944 ELF_ST_INFO (bind, STT_ARM_TFUNC);
18945 else
18946 elf_sym->internal_elf_sym.st_info =
18947 ELF_ST_INFO (bind, STT_ARM_16BIT);
18948 }
18949 }
18950 }
18951#endif
404ff6b5
AH
18952}
18953
c19d1205 18954/* MD interface: Initialization. */
404ff6b5 18955
a737bd4d 18956static void
c19d1205 18957set_constant_flonums (void)
a737bd4d 18958{
c19d1205 18959 int i;
404ff6b5 18960
c19d1205
ZW
18961 for (i = 0; i < NUM_FLOAT_VALS; i++)
18962 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
18963 abort ();
a737bd4d 18964}
404ff6b5 18965
3e9e4fcf
JB
18966/* Auto-select Thumb mode if it's the only available instruction set for the
18967 given architecture. */
18968
18969static void
18970autoselect_thumb_from_cpu_variant (void)
18971{
18972 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
18973 opcode_select (16);
18974}
18975
c19d1205
ZW
18976void
18977md_begin (void)
a737bd4d 18978{
c19d1205
ZW
18979 unsigned mach;
18980 unsigned int i;
404ff6b5 18981
c19d1205
ZW
18982 if ( (arm_ops_hsh = hash_new ()) == NULL
18983 || (arm_cond_hsh = hash_new ()) == NULL
18984 || (arm_shift_hsh = hash_new ()) == NULL
18985 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 18986 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 18987 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
18988 || (arm_reloc_hsh = hash_new ()) == NULL
18989 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
18990 as_fatal (_("virtual memory exhausted"));
18991
18992 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
18993 hash_insert (arm_ops_hsh, insns[i].template, (PTR) (insns + i));
18994 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
18995 hash_insert (arm_cond_hsh, conds[i].template, (PTR) (conds + i));
18996 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
18997 hash_insert (arm_shift_hsh, shift_names[i].name, (PTR) (shift_names + i));
18998 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
18999 hash_insert (arm_psr_hsh, psrs[i].template, (PTR) (psrs + i));
62b3e311
PB
19000 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
19001 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (PTR) (v7m_psrs + i));
c19d1205
ZW
19002 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
19003 hash_insert (arm_reg_hsh, reg_names[i].name, (PTR) (reg_names + i));
62b3e311
PB
19004 for (i = 0;
19005 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
19006 i++)
19007 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
19008 (PTR) (barrier_opt_names + i));
c19d1205
ZW
19009#ifdef OBJ_ELF
19010 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
19011 hash_insert (arm_reloc_hsh, reloc_names[i].name, (PTR) (reloc_names + i));
19012#endif
19013
19014 set_constant_flonums ();
404ff6b5 19015
c19d1205
ZW
19016 /* Set the cpu variant based on the command-line options. We prefer
19017 -mcpu= over -march= if both are set (as for GCC); and we prefer
19018 -mfpu= over any other way of setting the floating point unit.
19019 Use of legacy options with new options are faulted. */
e74cfd16 19020 if (legacy_cpu)
404ff6b5 19021 {
e74cfd16 19022 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
19023 as_bad (_("use of old and new-style options to set CPU type"));
19024
19025 mcpu_cpu_opt = legacy_cpu;
404ff6b5 19026 }
e74cfd16 19027 else if (!mcpu_cpu_opt)
c19d1205 19028 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 19029
e74cfd16 19030 if (legacy_fpu)
c19d1205 19031 {
e74cfd16 19032 if (mfpu_opt)
c19d1205 19033 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
19034
19035 mfpu_opt = legacy_fpu;
19036 }
e74cfd16 19037 else if (!mfpu_opt)
03b1477f 19038 {
c19d1205 19039#if !(defined (TE_LINUX) || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
19040 /* Some environments specify a default FPU. If they don't, infer it
19041 from the processor. */
e74cfd16 19042 if (mcpu_fpu_opt)
03b1477f
RE
19043 mfpu_opt = mcpu_fpu_opt;
19044 else
19045 mfpu_opt = march_fpu_opt;
39c2da32 19046#else
e74cfd16 19047 mfpu_opt = &fpu_default;
39c2da32 19048#endif
03b1477f
RE
19049 }
19050
e74cfd16 19051 if (!mfpu_opt)
03b1477f 19052 {
e74cfd16
PB
19053 if (!mcpu_cpu_opt)
19054 mfpu_opt = &fpu_default;
19055 else if (ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
19056 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 19057 else
e74cfd16 19058 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
19059 }
19060
ee065d83 19061#ifdef CPU_DEFAULT
e74cfd16 19062 if (!mcpu_cpu_opt)
ee065d83 19063 {
e74cfd16
PB
19064 mcpu_cpu_opt = &cpu_default;
19065 selected_cpu = cpu_default;
ee065d83 19066 }
e74cfd16
PB
19067#else
19068 if (mcpu_cpu_opt)
19069 selected_cpu = *mcpu_cpu_opt;
ee065d83 19070 else
e74cfd16 19071 mcpu_cpu_opt = &arm_arch_any;
ee065d83 19072#endif
03b1477f 19073
e74cfd16 19074 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 19075
3e9e4fcf
JB
19076 autoselect_thumb_from_cpu_variant ();
19077
e74cfd16 19078 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 19079
f17c130b 19080#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 19081 {
7cc69913
NC
19082 unsigned int flags = 0;
19083
19084#if defined OBJ_ELF
19085 flags = meabi_flags;
d507cf36
PB
19086
19087 switch (meabi_flags)
33a392fb 19088 {
d507cf36 19089 case EF_ARM_EABI_UNKNOWN:
7cc69913 19090#endif
d507cf36
PB
19091 /* Set the flags in the private structure. */
19092 if (uses_apcs_26) flags |= F_APCS26;
19093 if (support_interwork) flags |= F_INTERWORK;
19094 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 19095 if (pic_code) flags |= F_PIC;
e74cfd16 19096 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
19097 flags |= F_SOFT_FLOAT;
19098
d507cf36
PB
19099 switch (mfloat_abi_opt)
19100 {
19101 case ARM_FLOAT_ABI_SOFT:
19102 case ARM_FLOAT_ABI_SOFTFP:
19103 flags |= F_SOFT_FLOAT;
19104 break;
33a392fb 19105
d507cf36
PB
19106 case ARM_FLOAT_ABI_HARD:
19107 if (flags & F_SOFT_FLOAT)
19108 as_bad (_("hard-float conflicts with specified fpu"));
19109 break;
19110 }
03b1477f 19111
e74cfd16
PB
19112 /* Using pure-endian doubles (even if soft-float). */
19113 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 19114 flags |= F_VFP_FLOAT;
f17c130b 19115
fde78edd 19116#if defined OBJ_ELF
e74cfd16 19117 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 19118 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
19119 break;
19120
8cb51566 19121 case EF_ARM_EABI_VER4:
3a4a14e9 19122 case EF_ARM_EABI_VER5:
c19d1205 19123 /* No additional flags to set. */
d507cf36
PB
19124 break;
19125
19126 default:
19127 abort ();
19128 }
7cc69913 19129#endif
b99bd4ef
NC
19130 bfd_set_private_flags (stdoutput, flags);
19131
19132 /* We have run out flags in the COFF header to encode the
19133 status of ATPCS support, so instead we create a dummy,
c19d1205 19134 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
19135 if (atpcs)
19136 {
19137 asection * sec;
19138
19139 sec = bfd_make_section (stdoutput, ".arm.atpcs");
19140
19141 if (sec != NULL)
19142 {
19143 bfd_set_section_flags
19144 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
19145 bfd_set_section_size (stdoutput, sec, 0);
19146 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
19147 }
19148 }
7cc69913 19149 }
f17c130b 19150#endif
b99bd4ef
NC
19151
19152 /* Record the CPU type as well. */
e74cfd16 19153 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 19154 mach = bfd_mach_arm_iWMMXt;
e74cfd16 19155 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 19156 mach = bfd_mach_arm_XScale;
e74cfd16 19157 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 19158 mach = bfd_mach_arm_ep9312;
e74cfd16 19159 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 19160 mach = bfd_mach_arm_5TE;
e74cfd16 19161 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 19162 {
e74cfd16 19163 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19164 mach = bfd_mach_arm_5T;
19165 else
19166 mach = bfd_mach_arm_5;
19167 }
e74cfd16 19168 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 19169 {
e74cfd16 19170 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
19171 mach = bfd_mach_arm_4T;
19172 else
19173 mach = bfd_mach_arm_4;
19174 }
e74cfd16 19175 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 19176 mach = bfd_mach_arm_3M;
e74cfd16
PB
19177 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
19178 mach = bfd_mach_arm_3;
19179 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
19180 mach = bfd_mach_arm_2a;
19181 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
19182 mach = bfd_mach_arm_2;
19183 else
19184 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
19185
19186 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
19187}
19188
c19d1205 19189/* Command line processing. */
b99bd4ef 19190
c19d1205
ZW
19191/* md_parse_option
19192 Invocation line includes a switch not recognized by the base assembler.
19193 See if it's a processor-specific option.
b99bd4ef 19194
c19d1205
ZW
19195 This routine is somewhat complicated by the need for backwards
19196 compatibility (since older releases of gcc can't be changed).
19197 The new options try to make the interface as compatible as
19198 possible with GCC.
b99bd4ef 19199
c19d1205 19200 New options (supported) are:
b99bd4ef 19201
c19d1205
ZW
19202 -mcpu=<cpu name> Assemble for selected processor
19203 -march=<architecture name> Assemble for selected architecture
19204 -mfpu=<fpu architecture> Assemble for selected FPU.
19205 -EB/-mbig-endian Big-endian
19206 -EL/-mlittle-endian Little-endian
19207 -k Generate PIC code
19208 -mthumb Start in Thumb mode
19209 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 19210
c19d1205 19211 For now we will also provide support for:
b99bd4ef 19212
c19d1205
ZW
19213 -mapcs-32 32-bit Program counter
19214 -mapcs-26 26-bit Program counter
19215 -macps-float Floats passed in FP registers
19216 -mapcs-reentrant Reentrant code
19217 -matpcs
19218 (sometime these will probably be replaced with -mapcs=<list of options>
19219 and -matpcs=<list of options>)
b99bd4ef 19220
c19d1205
ZW
19221 The remaining options are only supported for back-wards compatibility.
19222 Cpu variants, the arm part is optional:
19223 -m[arm]1 Currently not supported.
19224 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
19225 -m[arm]3 Arm 3 processor
19226 -m[arm]6[xx], Arm 6 processors
19227 -m[arm]7[xx][t][[d]m] Arm 7 processors
19228 -m[arm]8[10] Arm 8 processors
19229 -m[arm]9[20][tdmi] Arm 9 processors
19230 -mstrongarm[110[0]] StrongARM processors
19231 -mxscale XScale processors
19232 -m[arm]v[2345[t[e]]] Arm architectures
19233 -mall All (except the ARM1)
19234 FP variants:
19235 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
19236 -mfpe-old (No float load/store multiples)
19237 -mvfpxd VFP Single precision
19238 -mvfp All VFP
19239 -mno-fpu Disable all floating point instructions
b99bd4ef 19240
c19d1205
ZW
19241 The following CPU names are recognized:
19242 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
19243 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
19244 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
19245 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
19246 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
19247 arm10t arm10e, arm1020t, arm1020e, arm10200e,
19248 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 19249
c19d1205 19250 */
b99bd4ef 19251
c19d1205 19252const char * md_shortopts = "m:k";
b99bd4ef 19253
c19d1205
ZW
19254#ifdef ARM_BI_ENDIAN
19255#define OPTION_EB (OPTION_MD_BASE + 0)
19256#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 19257#else
c19d1205
ZW
19258#if TARGET_BYTES_BIG_ENDIAN
19259#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 19260#else
c19d1205
ZW
19261#define OPTION_EL (OPTION_MD_BASE + 1)
19262#endif
b99bd4ef 19263#endif
b99bd4ef 19264
c19d1205 19265struct option md_longopts[] =
b99bd4ef 19266{
c19d1205
ZW
19267#ifdef OPTION_EB
19268 {"EB", no_argument, NULL, OPTION_EB},
19269#endif
19270#ifdef OPTION_EL
19271 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 19272#endif
c19d1205
ZW
19273 {NULL, no_argument, NULL, 0}
19274};
b99bd4ef 19275
c19d1205 19276size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 19277
c19d1205 19278struct arm_option_table
b99bd4ef 19279{
c19d1205
ZW
19280 char *option; /* Option name to match. */
19281 char *help; /* Help information. */
19282 int *var; /* Variable to change. */
19283 int value; /* What to change it to. */
19284 char *deprecated; /* If non-null, print this message. */
19285};
b99bd4ef 19286
c19d1205
ZW
19287struct arm_option_table arm_opts[] =
19288{
19289 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
19290 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
19291 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
19292 &support_interwork, 1, NULL},
19293 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
19294 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
19295 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
19296 1, NULL},
19297 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
19298 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
19299 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
19300 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
19301 NULL},
b99bd4ef 19302
c19d1205
ZW
19303 /* These are recognized by the assembler, but have no affect on code. */
19304 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
19305 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
e74cfd16
PB
19306 {NULL, NULL, NULL, 0, NULL}
19307};
19308
19309struct arm_legacy_option_table
19310{
19311 char *option; /* Option name to match. */
19312 const arm_feature_set **var; /* Variable to change. */
19313 const arm_feature_set value; /* What to change it to. */
19314 char *deprecated; /* If non-null, print this message. */
19315};
b99bd4ef 19316
e74cfd16
PB
19317const struct arm_legacy_option_table arm_legacy_opts[] =
19318{
c19d1205
ZW
19319 /* DON'T add any new processors to this list -- we want the whole list
19320 to go away... Add them to the processors table instead. */
e74cfd16
PB
19321 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19322 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
19323 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19324 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
19325 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19326 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
19327 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19328 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
19329 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19330 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
19331 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19332 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
19333 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19334 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
19335 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19336 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
19337 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19338 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
19339 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19340 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
19341 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19342 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
19343 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19344 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
19345 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19346 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
19347 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19348 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
19349 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19350 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
19351 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19352 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
19353 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19354 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
19355 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19356 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
19357 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19358 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
19359 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19360 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
19361 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19362 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
19363 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19364 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
19365 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19366 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
19367 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19368 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19369 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19370 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
19371 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19372 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
19373 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19374 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
19375 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19376 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
19377 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19378 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
19379 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19380 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
19381 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19382 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
19383 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19384 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
19385 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19386 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
19387 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19388 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
19389 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
19390 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19391 N_("use -mcpu=strongarm110")},
e74cfd16 19392 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19393 N_("use -mcpu=strongarm1100")},
e74cfd16 19394 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 19395 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
19396 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
19397 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
19398 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 19399
c19d1205 19400 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
19401 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19402 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
19403 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19404 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
19405 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19406 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
19407 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19408 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
19409 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19410 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
19411 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19412 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
19413 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19414 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
19415 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19416 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
19417 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
19418 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 19419
c19d1205 19420 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
19421 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
19422 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
19423 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
19424 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 19425 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 19426
e74cfd16 19427 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 19428};
7ed4c4c5 19429
c19d1205 19430struct arm_cpu_option_table
7ed4c4c5 19431{
c19d1205 19432 char *name;
e74cfd16 19433 const arm_feature_set value;
c19d1205
ZW
19434 /* For some CPUs we assume an FPU unless the user explicitly sets
19435 -mfpu=... */
e74cfd16 19436 const arm_feature_set default_fpu;
ee065d83
PB
19437 /* The canonical name of the CPU, or NULL to use NAME converted to upper
19438 case. */
19439 const char *canonical_name;
c19d1205 19440};
7ed4c4c5 19441
c19d1205
ZW
19442/* This list should, at a minimum, contain all the cpu names
19443 recognized by GCC. */
e74cfd16 19444static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 19445{
ee065d83
PB
19446 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
19447 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
19448 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
19449 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19450 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
19451 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19452 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19453 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19454 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19455 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19456 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19457 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19458 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19459 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19460 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19461 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
19462 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19463 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19464 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19465 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19466 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19467 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19468 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19469 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19470 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19471 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19472 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19473 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
19474 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19475 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19476 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19477 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19478 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19479 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19480 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19481 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19482 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19483 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
19484 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19485 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
19486 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19487 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19488 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
19489 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
c19d1205
ZW
19490 /* For V5 or later processors we default to using VFP; but the user
19491 should really set the FPU type explicitly. */
ee065d83
PB
19492 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19493 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19494 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19495 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
19496 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19497 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19498 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
19499 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19500 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
19501 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
19502 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19503 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19504 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19505 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19506 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19507 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
19508 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
19509 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19510 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
19511 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
19512 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
19513 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
19514 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
19515 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
19516 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
19517 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
19518 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
19519 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
19520 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
19521 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
19522 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
5287ad62
JB
19523 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE(0, FPU_VFP_V3
19524 | FPU_NEON_EXT_V1),
19525 NULL},
62b3e311
PB
19526 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
19527 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
c19d1205 19528 /* ??? XSCALE is really an architecture. */
ee065d83 19529 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 19530 /* ??? iwmmxt is not a processor. */
ee065d83
PB
19531 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
19532 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 19533 /* Maverick */
e74cfd16
PB
19534 {"ep9312", ARM_FEATURE(ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
19535 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 19536};
7ed4c4c5 19537
c19d1205 19538struct arm_arch_option_table
7ed4c4c5 19539{
c19d1205 19540 char *name;
e74cfd16
PB
19541 const arm_feature_set value;
19542 const arm_feature_set default_fpu;
c19d1205 19543};
7ed4c4c5 19544
c19d1205
ZW
19545/* This list should, at a minimum, contain all the architecture names
19546 recognized by GCC. */
e74cfd16 19547static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
19548{
19549 {"all", ARM_ANY, FPU_ARCH_FPA},
19550 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
19551 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
19552 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
19553 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
19554 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
19555 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
19556 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
19557 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
19558 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
19559 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
19560 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
19561 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
19562 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
19563 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
19564 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
19565 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
19566 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
19567 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
19568 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
19569 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
19570 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
19571 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
19572 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
19573 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
19574 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
62b3e311
PB
19575 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
19576 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
19577 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
19578 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
19579 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
19580 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
e74cfd16 19581 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 19582};
7ed4c4c5 19583
c19d1205 19584/* ISA extensions in the co-processor space. */
e74cfd16 19585struct arm_option_cpu_value_table
c19d1205
ZW
19586{
19587 char *name;
e74cfd16 19588 const arm_feature_set value;
c19d1205 19589};
7ed4c4c5 19590
e74cfd16 19591static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 19592{
e74cfd16
PB
19593 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
19594 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
19595 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
19596 {NULL, ARM_ARCH_NONE}
c19d1205 19597};
7ed4c4c5 19598
c19d1205
ZW
19599/* This list should, at a minimum, contain all the fpu names
19600 recognized by GCC. */
e74cfd16 19601static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
19602{
19603 {"softfpa", FPU_NONE},
19604 {"fpe", FPU_ARCH_FPE},
19605 {"fpe2", FPU_ARCH_FPE},
19606 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
19607 {"fpa", FPU_ARCH_FPA},
19608 {"fpa10", FPU_ARCH_FPA},
19609 {"fpa11", FPU_ARCH_FPA},
19610 {"arm7500fe", FPU_ARCH_FPA},
19611 {"softvfp", FPU_ARCH_VFP},
19612 {"softvfp+vfp", FPU_ARCH_VFP_V2},
19613 {"vfp", FPU_ARCH_VFP_V2},
19614 {"vfp9", FPU_ARCH_VFP_V2},
5287ad62 19615 {"vfp3", FPU_ARCH_VFP_V3},
c19d1205
ZW
19616 {"vfp10", FPU_ARCH_VFP_V2},
19617 {"vfp10-r0", FPU_ARCH_VFP_V1},
19618 {"vfpxd", FPU_ARCH_VFP_V1xD},
19619 {"arm1020t", FPU_ARCH_VFP_V1},
19620 {"arm1020e", FPU_ARCH_VFP_V2},
19621 {"arm1136jfs", FPU_ARCH_VFP_V2},
19622 {"arm1136jf-s", FPU_ARCH_VFP_V2},
19623 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 19624 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
e74cfd16
PB
19625 {NULL, ARM_ARCH_NONE}
19626};
19627
19628struct arm_option_value_table
19629{
19630 char *name;
19631 long value;
c19d1205 19632};
7ed4c4c5 19633
e74cfd16 19634static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
19635{
19636 {"hard", ARM_FLOAT_ABI_HARD},
19637 {"softfp", ARM_FLOAT_ABI_SOFTFP},
19638 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 19639 {NULL, 0}
c19d1205 19640};
7ed4c4c5 19641
c19d1205 19642#ifdef OBJ_ELF
3a4a14e9 19643/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 19644static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
19645{
19646 {"gnu", EF_ARM_EABI_UNKNOWN},
19647 {"4", EF_ARM_EABI_VER4},
3a4a14e9 19648 {"5", EF_ARM_EABI_VER5},
e74cfd16 19649 {NULL, 0}
c19d1205
ZW
19650};
19651#endif
7ed4c4c5 19652
c19d1205
ZW
19653struct arm_long_option_table
19654{
19655 char * option; /* Substring to match. */
19656 char * help; /* Help information. */
19657 int (* func) (char * subopt); /* Function to decode sub-option. */
19658 char * deprecated; /* If non-null, print this message. */
19659};
7ed4c4c5
NC
19660
19661static int
e74cfd16 19662arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 19663{
e74cfd16
PB
19664 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
19665
19666 /* Copy the feature set, so that we can modify it. */
19667 *ext_set = **opt_p;
19668 *opt_p = ext_set;
19669
c19d1205 19670 while (str != NULL && *str != 0)
7ed4c4c5 19671 {
e74cfd16 19672 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
19673 char * ext;
19674 int optlen;
7ed4c4c5 19675
c19d1205
ZW
19676 if (*str != '+')
19677 {
19678 as_bad (_("invalid architectural extension"));
19679 return 0;
19680 }
7ed4c4c5 19681
c19d1205
ZW
19682 str++;
19683 ext = strchr (str, '+');
7ed4c4c5 19684
c19d1205
ZW
19685 if (ext != NULL)
19686 optlen = ext - str;
19687 else
19688 optlen = strlen (str);
7ed4c4c5 19689
c19d1205
ZW
19690 if (optlen == 0)
19691 {
19692 as_bad (_("missing architectural extension"));
19693 return 0;
19694 }
7ed4c4c5 19695
c19d1205
ZW
19696 for (opt = arm_extensions; opt->name != NULL; opt++)
19697 if (strncmp (opt->name, str, optlen) == 0)
19698 {
e74cfd16 19699 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
19700 break;
19701 }
7ed4c4c5 19702
c19d1205
ZW
19703 if (opt->name == NULL)
19704 {
19705 as_bad (_("unknown architectural extnsion `%s'"), str);
19706 return 0;
19707 }
7ed4c4c5 19708
c19d1205
ZW
19709 str = ext;
19710 };
7ed4c4c5 19711
c19d1205
ZW
19712 return 1;
19713}
7ed4c4c5 19714
c19d1205
ZW
19715static int
19716arm_parse_cpu (char * str)
7ed4c4c5 19717{
e74cfd16 19718 const struct arm_cpu_option_table * opt;
c19d1205
ZW
19719 char * ext = strchr (str, '+');
19720 int optlen;
7ed4c4c5 19721
c19d1205
ZW
19722 if (ext != NULL)
19723 optlen = ext - str;
7ed4c4c5 19724 else
c19d1205 19725 optlen = strlen (str);
7ed4c4c5 19726
c19d1205 19727 if (optlen == 0)
7ed4c4c5 19728 {
c19d1205
ZW
19729 as_bad (_("missing cpu name `%s'"), str);
19730 return 0;
7ed4c4c5
NC
19731 }
19732
c19d1205
ZW
19733 for (opt = arm_cpus; opt->name != NULL; opt++)
19734 if (strncmp (opt->name, str, optlen) == 0)
19735 {
e74cfd16
PB
19736 mcpu_cpu_opt = &opt->value;
19737 mcpu_fpu_opt = &opt->default_fpu;
ee065d83
PB
19738 if (opt->canonical_name)
19739 strcpy(selected_cpu_name, opt->canonical_name);
19740 else
19741 {
19742 int i;
19743 for (i = 0; i < optlen; i++)
19744 selected_cpu_name[i] = TOUPPER (opt->name[i]);
19745 selected_cpu_name[i] = 0;
19746 }
7ed4c4c5 19747
c19d1205
ZW
19748 if (ext != NULL)
19749 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 19750
c19d1205
ZW
19751 return 1;
19752 }
7ed4c4c5 19753
c19d1205
ZW
19754 as_bad (_("unknown cpu `%s'"), str);
19755 return 0;
7ed4c4c5
NC
19756}
19757
c19d1205
ZW
19758static int
19759arm_parse_arch (char * str)
7ed4c4c5 19760{
e74cfd16 19761 const struct arm_arch_option_table *opt;
c19d1205
ZW
19762 char *ext = strchr (str, '+');
19763 int optlen;
7ed4c4c5 19764
c19d1205
ZW
19765 if (ext != NULL)
19766 optlen = ext - str;
7ed4c4c5 19767 else
c19d1205 19768 optlen = strlen (str);
7ed4c4c5 19769
c19d1205 19770 if (optlen == 0)
7ed4c4c5 19771 {
c19d1205
ZW
19772 as_bad (_("missing architecture name `%s'"), str);
19773 return 0;
7ed4c4c5
NC
19774 }
19775
c19d1205
ZW
19776 for (opt = arm_archs; opt->name != NULL; opt++)
19777 if (streq (opt->name, str))
19778 {
e74cfd16
PB
19779 march_cpu_opt = &opt->value;
19780 march_fpu_opt = &opt->default_fpu;
ee065d83 19781 strcpy(selected_cpu_name, opt->name);
7ed4c4c5 19782
c19d1205
ZW
19783 if (ext != NULL)
19784 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 19785
c19d1205
ZW
19786 return 1;
19787 }
19788
19789 as_bad (_("unknown architecture `%s'\n"), str);
19790 return 0;
7ed4c4c5 19791}
eb043451 19792
c19d1205
ZW
19793static int
19794arm_parse_fpu (char * str)
19795{
e74cfd16 19796 const struct arm_option_cpu_value_table * opt;
b99bd4ef 19797
c19d1205
ZW
19798 for (opt = arm_fpus; opt->name != NULL; opt++)
19799 if (streq (opt->name, str))
19800 {
e74cfd16 19801 mfpu_opt = &opt->value;
c19d1205
ZW
19802 return 1;
19803 }
b99bd4ef 19804
c19d1205
ZW
19805 as_bad (_("unknown floating point format `%s'\n"), str);
19806 return 0;
19807}
19808
19809static int
19810arm_parse_float_abi (char * str)
b99bd4ef 19811{
e74cfd16 19812 const struct arm_option_value_table * opt;
b99bd4ef 19813
c19d1205
ZW
19814 for (opt = arm_float_abis; opt->name != NULL; opt++)
19815 if (streq (opt->name, str))
19816 {
19817 mfloat_abi_opt = opt->value;
19818 return 1;
19819 }
cc8a6dd0 19820
c19d1205
ZW
19821 as_bad (_("unknown floating point abi `%s'\n"), str);
19822 return 0;
19823}
b99bd4ef 19824
c19d1205
ZW
19825#ifdef OBJ_ELF
19826static int
19827arm_parse_eabi (char * str)
19828{
e74cfd16 19829 const struct arm_option_value_table *opt;
cc8a6dd0 19830
c19d1205
ZW
19831 for (opt = arm_eabis; opt->name != NULL; opt++)
19832 if (streq (opt->name, str))
19833 {
19834 meabi_flags = opt->value;
19835 return 1;
19836 }
19837 as_bad (_("unknown EABI `%s'\n"), str);
19838 return 0;
19839}
19840#endif
cc8a6dd0 19841
c19d1205
ZW
19842struct arm_long_option_table arm_long_opts[] =
19843{
19844 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
19845 arm_parse_cpu, NULL},
19846 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
19847 arm_parse_arch, NULL},
19848 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
19849 arm_parse_fpu, NULL},
19850 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
19851 arm_parse_float_abi, NULL},
19852#ifdef OBJ_ELF
19853 {"meabi=", N_("<ver>\t assemble for eabi version <ver>"),
19854 arm_parse_eabi, NULL},
19855#endif
19856 {NULL, NULL, 0, NULL}
19857};
cc8a6dd0 19858
c19d1205
ZW
19859int
19860md_parse_option (int c, char * arg)
19861{
19862 struct arm_option_table *opt;
e74cfd16 19863 const struct arm_legacy_option_table *fopt;
c19d1205 19864 struct arm_long_option_table *lopt;
b99bd4ef 19865
c19d1205 19866 switch (c)
b99bd4ef 19867 {
c19d1205
ZW
19868#ifdef OPTION_EB
19869 case OPTION_EB:
19870 target_big_endian = 1;
19871 break;
19872#endif
cc8a6dd0 19873
c19d1205
ZW
19874#ifdef OPTION_EL
19875 case OPTION_EL:
19876 target_big_endian = 0;
19877 break;
19878#endif
b99bd4ef 19879
c19d1205
ZW
19880 case 'a':
19881 /* Listing option. Just ignore these, we don't support additional
19882 ones. */
19883 return 0;
b99bd4ef 19884
c19d1205
ZW
19885 default:
19886 for (opt = arm_opts; opt->option != NULL; opt++)
19887 {
19888 if (c == opt->option[0]
19889 && ((arg == NULL && opt->option[1] == 0)
19890 || streq (arg, opt->option + 1)))
19891 {
19892#if WARN_DEPRECATED
19893 /* If the option is deprecated, tell the user. */
19894 if (opt->deprecated != NULL)
19895 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19896 arg ? arg : "", _(opt->deprecated));
19897#endif
b99bd4ef 19898
c19d1205
ZW
19899 if (opt->var != NULL)
19900 *opt->var = opt->value;
cc8a6dd0 19901
c19d1205
ZW
19902 return 1;
19903 }
19904 }
b99bd4ef 19905
e74cfd16
PB
19906 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
19907 {
19908 if (c == fopt->option[0]
19909 && ((arg == NULL && fopt->option[1] == 0)
19910 || streq (arg, fopt->option + 1)))
19911 {
19912#if WARN_DEPRECATED
19913 /* If the option is deprecated, tell the user. */
19914 if (fopt->deprecated != NULL)
19915 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
19916 arg ? arg : "", _(fopt->deprecated));
19917#endif
19918
19919 if (fopt->var != NULL)
19920 *fopt->var = &fopt->value;
19921
19922 return 1;
19923 }
19924 }
19925
c19d1205
ZW
19926 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19927 {
19928 /* These options are expected to have an argument. */
19929 if (c == lopt->option[0]
19930 && arg != NULL
19931 && strncmp (arg, lopt->option + 1,
19932 strlen (lopt->option + 1)) == 0)
19933 {
19934#if WARN_DEPRECATED
19935 /* If the option is deprecated, tell the user. */
19936 if (lopt->deprecated != NULL)
19937 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
19938 _(lopt->deprecated));
19939#endif
b99bd4ef 19940
c19d1205
ZW
19941 /* Call the sup-option parser. */
19942 return lopt->func (arg + strlen (lopt->option) - 1);
19943 }
19944 }
a737bd4d 19945
c19d1205
ZW
19946 return 0;
19947 }
a394c00f 19948
c19d1205
ZW
19949 return 1;
19950}
a394c00f 19951
c19d1205
ZW
19952void
19953md_show_usage (FILE * fp)
a394c00f 19954{
c19d1205
ZW
19955 struct arm_option_table *opt;
19956 struct arm_long_option_table *lopt;
a394c00f 19957
c19d1205 19958 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 19959
c19d1205
ZW
19960 for (opt = arm_opts; opt->option != NULL; opt++)
19961 if (opt->help != NULL)
19962 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 19963
c19d1205
ZW
19964 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
19965 if (lopt->help != NULL)
19966 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 19967
c19d1205
ZW
19968#ifdef OPTION_EB
19969 fprintf (fp, _("\
19970 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
19971#endif
19972
c19d1205
ZW
19973#ifdef OPTION_EL
19974 fprintf (fp, _("\
19975 -EL assemble code for a little-endian cpu\n"));
a737bd4d 19976#endif
c19d1205 19977}
ee065d83
PB
19978
19979
19980#ifdef OBJ_ELF
62b3e311
PB
19981typedef struct
19982{
19983 int val;
19984 arm_feature_set flags;
19985} cpu_arch_ver_table;
19986
19987/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
19988 least features first. */
19989static const cpu_arch_ver_table cpu_arch_ver[] =
19990{
19991 {1, ARM_ARCH_V4},
19992 {2, ARM_ARCH_V4T},
19993 {3, ARM_ARCH_V5},
19994 {4, ARM_ARCH_V5TE},
19995 {5, ARM_ARCH_V5TEJ},
19996 {6, ARM_ARCH_V6},
19997 {7, ARM_ARCH_V6Z},
19998 {8, ARM_ARCH_V6K},
19999 {9, ARM_ARCH_V6T2},
20000 {10, ARM_ARCH_V7A},
20001 {10, ARM_ARCH_V7R},
20002 {10, ARM_ARCH_V7M},
20003 {0, ARM_ARCH_NONE}
20004};
20005
ee065d83
PB
20006/* Set the public EABI object attributes. */
20007static void
20008aeabi_set_public_attributes (void)
20009{
20010 int arch;
e74cfd16 20011 arm_feature_set flags;
62b3e311
PB
20012 arm_feature_set tmp;
20013 const cpu_arch_ver_table *p;
ee065d83
PB
20014
20015 /* Choose the architecture based on the capabilities of the requested cpu
20016 (if any) and/or the instructions actually used. */
e74cfd16
PB
20017 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
20018 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
20019 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
5287ad62 20020
62b3e311
PB
20021 tmp = flags;
20022 arch = 0;
20023 for (p = cpu_arch_ver; p->val; p++)
20024 {
20025 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
20026 {
20027 arch = p->val;
20028 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
20029 }
20030 }
ee065d83
PB
20031
20032 /* Tag_CPU_name. */
20033 if (selected_cpu_name[0])
20034 {
20035 char *p;
20036
20037 p = selected_cpu_name;
20038 if (strncmp(p, "armv", 4) == 0)
20039 {
20040 int i;
20041
20042 p += 4;
20043 for (i = 0; p[i]; i++)
20044 p[i] = TOUPPER (p[i]);
20045 }
20046 elf32_arm_add_eabi_attr_string (stdoutput, 5, p);
20047 }
20048 /* Tag_CPU_arch. */
20049 elf32_arm_add_eabi_attr_int (stdoutput, 6, arch);
62b3e311
PB
20050 /* Tag_CPU_arch_profile. */
20051 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
20052 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'A');
20053 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
20054 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'R');
20055 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m))
20056 elf32_arm_add_eabi_attr_int (stdoutput, 7, 'M');
ee065d83 20057 /* Tag_ARM_ISA_use. */
e74cfd16 20058 if (ARM_CPU_HAS_FEATURE (arm_arch_used, arm_arch_full))
ee065d83
PB
20059 elf32_arm_add_eabi_attr_int (stdoutput, 8, 1);
20060 /* Tag_THUMB_ISA_use. */
e74cfd16 20061 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_full))
ee065d83 20062 elf32_arm_add_eabi_attr_int (stdoutput, 9,
e74cfd16 20063 ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_arch_t2) ? 2 : 1);
ee065d83 20064 /* Tag_VFP_arch. */
5287ad62
JB
20065 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v3)
20066 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v3))
20067 elf32_arm_add_eabi_attr_int (stdoutput, 10, 3);
20068 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v2)
20069 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v2))
ee065d83 20070 elf32_arm_add_eabi_attr_int (stdoutput, 10, 2);
5287ad62
JB
20071 else if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1)
20072 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1)
20073 || ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_vfp_ext_v1xd)
20074 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_vfp_ext_v1xd))
ee065d83
PB
20075 elf32_arm_add_eabi_attr_int (stdoutput, 10, 1);
20076 /* Tag_WMMX_arch. */
e74cfd16
PB
20077 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, arm_cext_iwmmxt)
20078 || ARM_CPU_HAS_FEATURE (arm_arch_used, arm_cext_iwmmxt))
ee065d83 20079 elf32_arm_add_eabi_attr_int (stdoutput, 11, 1);
5287ad62
JB
20080 /* Tag_NEON_arch. */
20081 if (ARM_CPU_HAS_FEATURE (thumb_arch_used, fpu_neon_ext_v1)
20082 || ARM_CPU_HAS_FEATURE (arm_arch_used, fpu_neon_ext_v1))
20083 elf32_arm_add_eabi_attr_int (stdoutput, 12, 1);
ee065d83
PB
20084}
20085
20086/* Add the .ARM.attributes section. */
20087void
20088arm_md_end (void)
20089{
20090 segT s;
20091 char *p;
20092 addressT addr;
20093 offsetT size;
20094
20095 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20096 return;
20097
20098 aeabi_set_public_attributes ();
20099 size = elf32_arm_eabi_attr_size (stdoutput);
20100 s = subseg_new (".ARM.attributes", 0);
20101 bfd_set_section_flags (stdoutput, s, SEC_READONLY | SEC_DATA);
20102 addr = frag_now_fix ();
20103 p = frag_more (size);
20104 elf32_arm_set_eabi_attr_contents (stdoutput, (bfd_byte *)p, size);
20105}
8463be01 20106#endif /* OBJ_ELF */
ee065d83
PB
20107
20108
20109/* Parse a .cpu directive. */
20110
20111static void
20112s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
20113{
e74cfd16 20114 const struct arm_cpu_option_table *opt;
ee065d83
PB
20115 char *name;
20116 char saved_char;
20117
20118 name = input_line_pointer;
20119 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20120 input_line_pointer++;
20121 saved_char = *input_line_pointer;
20122 *input_line_pointer = 0;
20123
20124 /* Skip the first "all" entry. */
20125 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
20126 if (streq (opt->name, name))
20127 {
e74cfd16
PB
20128 mcpu_cpu_opt = &opt->value;
20129 selected_cpu = opt->value;
ee065d83
PB
20130 if (opt->canonical_name)
20131 strcpy(selected_cpu_name, opt->canonical_name);
20132 else
20133 {
20134 int i;
20135 for (i = 0; opt->name[i]; i++)
20136 selected_cpu_name[i] = TOUPPER (opt->name[i]);
20137 selected_cpu_name[i] = 0;
20138 }
e74cfd16 20139 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20140 *input_line_pointer = saved_char;
20141 demand_empty_rest_of_line ();
20142 return;
20143 }
20144 as_bad (_("unknown cpu `%s'"), name);
20145 *input_line_pointer = saved_char;
20146 ignore_rest_of_line ();
20147}
20148
20149
20150/* Parse a .arch directive. */
20151
20152static void
20153s_arm_arch (int ignored ATTRIBUTE_UNUSED)
20154{
e74cfd16 20155 const struct arm_arch_option_table *opt;
ee065d83
PB
20156 char saved_char;
20157 char *name;
20158
20159 name = input_line_pointer;
20160 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20161 input_line_pointer++;
20162 saved_char = *input_line_pointer;
20163 *input_line_pointer = 0;
20164
20165 /* Skip the first "all" entry. */
20166 for (opt = arm_archs + 1; opt->name != NULL; opt++)
20167 if (streq (opt->name, name))
20168 {
e74cfd16
PB
20169 mcpu_cpu_opt = &opt->value;
20170 selected_cpu = opt->value;
ee065d83 20171 strcpy(selected_cpu_name, opt->name);
e74cfd16 20172 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20173 *input_line_pointer = saved_char;
20174 demand_empty_rest_of_line ();
20175 return;
20176 }
20177
20178 as_bad (_("unknown architecture `%s'\n"), name);
20179 *input_line_pointer = saved_char;
20180 ignore_rest_of_line ();
20181}
20182
20183
20184/* Parse a .fpu directive. */
20185
20186static void
20187s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
20188{
e74cfd16 20189 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
20190 char saved_char;
20191 char *name;
20192
20193 name = input_line_pointer;
20194 while (*input_line_pointer && !ISSPACE(*input_line_pointer))
20195 input_line_pointer++;
20196 saved_char = *input_line_pointer;
20197 *input_line_pointer = 0;
20198
20199 for (opt = arm_fpus; opt->name != NULL; opt++)
20200 if (streq (opt->name, name))
20201 {
e74cfd16
PB
20202 mfpu_opt = &opt->value;
20203 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
20204 *input_line_pointer = saved_char;
20205 demand_empty_rest_of_line ();
20206 return;
20207 }
20208
20209 as_bad (_("unknown floating point format `%s'\n"), name);
20210 *input_line_pointer = saved_char;
20211 ignore_rest_of_line ();
20212}
ee065d83 20213