* freebsd.h (Target_freebsd::do_adjust_elf_header): Use size
[deliverable/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
f31fef98 3 2004, 2005, 2006, 2007, 2008, 2009
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
42a68e18 28#include "as.h"
5287ad62 29#include <limits.h>
037e8744 30#include <stdarg.h>
c19d1205 31#define NO_RELOC 0
3882b010 32#include "safe-ctype.h"
b99bd4ef
NC
33#include "subsegs.h"
34#include "obstack.h"
b99bd4ef 35
f263249b
RE
36#include "opcode/arm.h"
37
b99bd4ef
NC
38#ifdef OBJ_ELF
39#include "elf/arm.h"
a394c00f 40#include "dw2gencfi.h"
b99bd4ef
NC
41#endif
42
f0927246
NC
43#include "dwarf2dbg.h"
44
7ed4c4c5
NC
45#ifdef OBJ_ELF
46/* Must be at least the size of the largest unwind opcode (currently two). */
47#define ARM_OPCODE_CHUNK_SIZE 8
48
49/* This structure holds the unwinding state. */
50
51static struct
52{
c19d1205
ZW
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
7ed4c4c5 57 /* The segment containing the function. */
c19d1205
ZW
58 segT saved_seg;
59 subsegT saved_subseg;
7ed4c4c5
NC
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
c19d1205
ZW
62 int opcode_count;
63 int opcode_alloc;
7ed4c4c5 64 /* The number of bytes pushed to the stack. */
c19d1205 65 offsetT frame_size;
7ed4c4c5
NC
66 /* We don't add stack adjustment opcodes immediately so that we can merge
67 multiple adjustments. We can also omit the final adjustment
68 when using a frame pointer. */
c19d1205 69 offsetT pending_offset;
7ed4c4c5 70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
c19d1205
ZW
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
7ed4c4c5 74 /* Nonzero if an unwind_setfp directive has been seen. */
c19d1205 75 unsigned fp_used:1;
7ed4c4c5 76 /* Nonzero if the last opcode restores sp from fp_reg. */
c19d1205 77 unsigned sp_restored:1;
7ed4c4c5
NC
78} unwind;
79
8b1ad454
NC
80/* Bit N indicates that an R_ARM_NONE relocation has been output for
81 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
82 emitted only once per section, to save unnecessary bloat. */
83static unsigned int marked_pr_dependency = 0;
84
85#endif /* OBJ_ELF */
86
4962c51a
MS
87/* Results from operand parsing worker functions. */
88
89typedef enum
90{
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94} parse_operand_result;
95
33a392fb
PB
96enum arm_float_abi
97{
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
101};
102
c19d1205 103/* Types of processor to assemble for. */
b99bd4ef
NC
104#ifndef CPU_DEFAULT
105#if defined __XSCALE__
e74cfd16 106#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
107#else
108#if defined __thumb__
e74cfd16 109#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
110#endif
111#endif
112#endif
113
114#ifndef FPU_DEFAULT
c820d418
MM
115# ifdef TE_LINUX
116# define FPU_DEFAULT FPU_ARCH_FPA
117# elif defined (TE_NetBSD)
118# ifdef OBJ_ELF
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
120# else
121 /* Legacy a.out format. */
122# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
123# endif
4e7fd91e
PB
124# elif defined (TE_VXWORKS)
125# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
126# else
127 /* For backwards compatibility, default to FPA. */
128# define FPU_DEFAULT FPU_ARCH_FPA
129# endif
130#endif /* ifndef FPU_DEFAULT */
b99bd4ef 131
c19d1205 132#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 133
e74cfd16
PB
134static arm_feature_set cpu_variant;
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
03b1477f
RE
148
149/* Variables that we set while parsing command-line options. Once all
150 options have been read we re-process these values to set the real
151 assembly flags. */
e74cfd16
PB
152static const arm_feature_set *legacy_cpu = NULL;
153static const arm_feature_set *legacy_fpu = NULL;
154
155static const arm_feature_set *mcpu_cpu_opt = NULL;
156static const arm_feature_set *mcpu_fpu_opt = NULL;
157static const arm_feature_set *march_cpu_opt = NULL;
158static const arm_feature_set *march_fpu_opt = NULL;
159static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 160static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
161
162/* Constants for known architecture features. */
163static const arm_feature_set fpu_default = FPU_DEFAULT;
164static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
166static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
168static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
172
173#ifdef CPU_DEFAULT
174static const arm_feature_set cpu_default = CPU_DEFAULT;
175#endif
176
177static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 195static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
7e806470
PB
196static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
198static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
7e806470
PB
202static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
204
205static const arm_feature_set arm_arch_any = ARM_ANY;
206static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209
2d447fca
JM
210static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
212static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62 224static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
225static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
227static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
8e79c3df 230static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
e74cfd16 231
33a392fb 232static int mfloat_abi_opt = -1;
e74cfd16
PB
233/* Record user cpu selection for object attributes. */
234static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
235/* Must be long enough to hold any of the names in arm_cpus. */
236static char selected_cpu_name[16];
7cc69913 237#ifdef OBJ_ELF
deeaaff8
DJ
238# ifdef EABI_DEFAULT
239static int meabi_flags = EABI_DEFAULT;
240# else
d507cf36 241static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 242# endif
e1da3f5b 243
ee3c0378
AS
244static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
e1da3f5b 246bfd_boolean
5f4273c7 247arm_is_eabi (void)
e1da3f5b
PB
248{
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250}
7cc69913 251#endif
b99bd4ef 252
b99bd4ef 253#ifdef OBJ_ELF
c19d1205 254/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
255symbolS * GOT_symbol;
256#endif
257
b99bd4ef
NC
258/* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262static int thumb_mode = 0;
8dc2430f
NC
263/* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266#define MODE_RECORDED (1 << 4)
b99bd4ef 267
e07e6e58
NC
268/* Specifies the intrinsic IT insn behavior mode. */
269enum implicit_it_mode
270{
271 IMPLICIT_IT_MODE_NEVER = 0x00,
272 IMPLICIT_IT_MODE_ARM = 0x01,
273 IMPLICIT_IT_MODE_THUMB = 0x02,
274 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
275};
276static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
277
c19d1205
ZW
278/* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
280
281 - Immediate operands do not require a # prefix.
282 - Conditional affixes always appear at the end of the
283 instruction. (For backward compatibility, those instructions
284 that formerly had them in the middle, continue to accept them
285 there.)
286 - The IT instruction may appear, and if it does is validated
287 against subsequent conditional affixes. It does not generate
288 machine code.
289
290 Important differences from the old Thumb mode:
291
292 - Immediate operands do not require a # prefix.
293 - Most of the V6T2 instructions are only available in unified mode.
294 - The .N and .W suffixes are recognized and honored (it is an error
295 if they cannot be honored).
296 - All instructions set the flags if and only if they have an 's' affix.
297 - Conditional affixes may be used. They are validated against
298 preceding IT instructions. Unlike ARM mode, you cannot use a
299 conditional affix except in the scope of an IT instruction. */
300
301static bfd_boolean unified_syntax = FALSE;
b99bd4ef 302
5287ad62
JB
303enum neon_el_type
304{
dcbf9037 305 NT_invtype,
5287ad62
JB
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
dcbf9037 311 NT_unsigned
5287ad62
JB
312};
313
314struct neon_type_el
315{
316 enum neon_el_type type;
317 unsigned size;
318};
319
320#define NEON_MAX_TYPE_ELS 4
321
322struct neon_type
323{
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
326};
327
e07e6e58
NC
328enum it_instruction_type
329{
330 OUTSIDE_IT_INSN,
331 INSIDE_IT_INSN,
332 INSIDE_IT_LAST_INSN,
333 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
334 if inside, should be the last one. */
335 NEUTRAL_IT_INSN, /* This could be either inside or outside,
336 i.e. BKPT and NOP. */
337 IT_INSN /* The IT insn has been parsed. */
338};
339
b99bd4ef
NC
340struct arm_it
341{
c19d1205 342 const char * error;
b99bd4ef 343 unsigned long instruction;
c19d1205
ZW
344 int size;
345 int size_req;
346 int cond;
037e8744
JB
347 /* "uncond_value" is set to the value in place of the conditional field in
348 unconditional versions of the instruction, or -1 if nothing is
349 appropriate. */
350 int uncond_value;
5287ad62 351 struct neon_type vectype;
0110f2b8
PB
352 /* Set to the opcode if the instruction needs relaxation.
353 Zero if the instruction is not relaxed. */
354 unsigned long relax;
b99bd4ef
NC
355 struct
356 {
357 bfd_reloc_code_real_type type;
c19d1205
ZW
358 expressionS exp;
359 int pc_rel;
b99bd4ef 360 } reloc;
b99bd4ef 361
e07e6e58
NC
362 enum it_instruction_type it_insn_type;
363
c19d1205
ZW
364 struct
365 {
366 unsigned reg;
ca3f61f7 367 signed int imm;
dcbf9037 368 struct neon_type_el vectype;
ca3f61f7
NC
369 unsigned present : 1; /* Operand present. */
370 unsigned isreg : 1; /* Operand was a register. */
371 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
372 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
373 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 374 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
375 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
376 instructions. This allows us to disambiguate ARM <-> vector insns. */
377 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 378 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 379 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 380 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
381 unsigned hasreloc : 1; /* Operand has relocation suffix. */
382 unsigned writeback : 1; /* Operand has trailing ! */
383 unsigned preind : 1; /* Preindexed address. */
384 unsigned postind : 1; /* Postindexed address. */
385 unsigned negative : 1; /* Index register was negated. */
386 unsigned shifted : 1; /* Shift applied to operation. */
387 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 388 } operands[6];
b99bd4ef
NC
389};
390
c19d1205 391static struct arm_it inst;
b99bd4ef
NC
392
393#define NUM_FLOAT_VALS 8
394
05d2d07e 395const char * fp_const[] =
b99bd4ef
NC
396{
397 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
398};
399
c19d1205 400/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
401#define MAX_LITTLENUMS 6
402
403LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
404
405#define FAIL (-1)
406#define SUCCESS (0)
407
408#define SUFF_S 1
409#define SUFF_D 2
410#define SUFF_E 3
411#define SUFF_P 4
412
c19d1205
ZW
413#define CP_T_X 0x00008000
414#define CP_T_Y 0x00400000
b99bd4ef 415
c19d1205
ZW
416#define CONDS_BIT 0x00100000
417#define LOAD_BIT 0x00100000
b99bd4ef
NC
418
419#define DOUBLE_LOAD_FLAG 0x00000001
420
421struct asm_cond
422{
c19d1205 423 const char * template;
b99bd4ef
NC
424 unsigned long value;
425};
426
c19d1205 427#define COND_ALWAYS 0xE
b99bd4ef 428
b99bd4ef
NC
429struct asm_psr
430{
b34976b6 431 const char *template;
b99bd4ef
NC
432 unsigned long field;
433};
434
62b3e311
PB
435struct asm_barrier_opt
436{
437 const char *template;
438 unsigned long value;
439};
440
2d2255b5 441/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
442#define SPSR_BIT (1 << 22)
443
c19d1205
ZW
444/* The individual PSR flag bits. */
445#define PSR_c (1 << 16)
446#define PSR_x (1 << 17)
447#define PSR_s (1 << 18)
448#define PSR_f (1 << 19)
b99bd4ef 449
c19d1205 450struct reloc_entry
bfae80f2 451{
c19d1205
ZW
452 char *name;
453 bfd_reloc_code_real_type reloc;
bfae80f2
RE
454};
455
5287ad62 456enum vfp_reg_pos
bfae80f2 457{
5287ad62
JB
458 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
459 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
460};
461
462enum vfp_ldstm_type
463{
464 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
465};
466
dcbf9037
JB
467/* Bits for DEFINED field in neon_typed_alias. */
468#define NTA_HASTYPE 1
469#define NTA_HASINDEX 2
470
471struct neon_typed_alias
472{
473 unsigned char defined;
474 unsigned char index;
475 struct neon_type_el eltype;
476};
477
c19d1205
ZW
478/* ARM register categories. This includes coprocessor numbers and various
479 architecture extensions' registers. */
480enum arm_reg_type
bfae80f2 481{
c19d1205
ZW
482 REG_TYPE_RN,
483 REG_TYPE_CP,
484 REG_TYPE_CN,
485 REG_TYPE_FN,
486 REG_TYPE_VFS,
487 REG_TYPE_VFD,
5287ad62 488 REG_TYPE_NQ,
037e8744 489 REG_TYPE_VFSD,
5287ad62 490 REG_TYPE_NDQ,
037e8744 491 REG_TYPE_NSDQ,
c19d1205
ZW
492 REG_TYPE_VFC,
493 REG_TYPE_MVF,
494 REG_TYPE_MVD,
495 REG_TYPE_MVFX,
496 REG_TYPE_MVDX,
497 REG_TYPE_MVAX,
498 REG_TYPE_DSPSC,
499 REG_TYPE_MMXWR,
500 REG_TYPE_MMXWC,
501 REG_TYPE_MMXWCG,
502 REG_TYPE_XSCALE,
bfae80f2
RE
503};
504
dcbf9037
JB
505/* Structure for a hash table entry for a register.
506 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
507 information which states whether a vector type or index is specified (for a
508 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
509struct reg_entry
510{
dcbf9037
JB
511 const char *name;
512 unsigned char number;
513 unsigned char type;
514 unsigned char builtin;
515 struct neon_typed_alias *neon;
6c43fab6
RE
516};
517
c19d1205
ZW
518/* Diagnostics used when we don't get a register of the expected type. */
519const char *const reg_expected_msgs[] =
520{
521 N_("ARM register expected"),
522 N_("bad or missing co-processor number"),
523 N_("co-processor register expected"),
524 N_("FPA register expected"),
525 N_("VFP single precision register expected"),
5287ad62
JB
526 N_("VFP/Neon double precision register expected"),
527 N_("Neon quad precision register expected"),
037e8744 528 N_("VFP single or double precision register expected"),
5287ad62 529 N_("Neon double or quad precision register expected"),
037e8744 530 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
531 N_("VFP system register expected"),
532 N_("Maverick MVF register expected"),
533 N_("Maverick MVD register expected"),
534 N_("Maverick MVFX register expected"),
535 N_("Maverick MVDX register expected"),
536 N_("Maverick MVAX register expected"),
537 N_("Maverick DSPSC register expected"),
538 N_("iWMMXt data register expected"),
539 N_("iWMMXt control register expected"),
540 N_("iWMMXt scalar register expected"),
541 N_("XScale accumulator register expected"),
6c43fab6
RE
542};
543
c19d1205
ZW
544/* Some well known registers that we refer to directly elsewhere. */
545#define REG_SP 13
546#define REG_LR 14
547#define REG_PC 15
404ff6b5 548
b99bd4ef
NC
549/* ARM instructions take 4bytes in the object file, Thumb instructions
550 take 2: */
c19d1205 551#define INSN_SIZE 4
b99bd4ef
NC
552
553struct asm_opcode
554{
555 /* Basic string to match. */
c19d1205
ZW
556 const char *template;
557
558 /* Parameters to instruction. */
559 unsigned char operands[8];
560
561 /* Conditional tag - see opcode_lookup. */
562 unsigned int tag : 4;
b99bd4ef
NC
563
564 /* Basic instruction code. */
c19d1205 565 unsigned int avalue : 28;
b99bd4ef 566
c19d1205
ZW
567 /* Thumb-format instruction code. */
568 unsigned int tvalue;
b99bd4ef 569
90e4755a 570 /* Which architecture variant provides this instruction. */
e74cfd16
PB
571 const arm_feature_set *avariant;
572 const arm_feature_set *tvariant;
c19d1205
ZW
573
574 /* Function to call to encode instruction in ARM format. */
575 void (* aencode) (void);
b99bd4ef 576
c19d1205
ZW
577 /* Function to call to encode instruction in Thumb format. */
578 void (* tencode) (void);
b99bd4ef
NC
579};
580
a737bd4d
NC
581/* Defines for various bits that we will want to toggle. */
582#define INST_IMMEDIATE 0x02000000
583#define OFFSET_REG 0x02000000
c19d1205 584#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
585#define SHIFT_BY_REG 0x00000010
586#define PRE_INDEX 0x01000000
587#define INDEX_UP 0x00800000
588#define WRITE_BACK 0x00200000
589#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 590#define CPSI_MMOD 0x00020000
90e4755a 591
a737bd4d
NC
592#define LITERAL_MASK 0xf000f000
593#define OPCODE_MASK 0xfe1fffff
594#define V4_STR_BIT 0x00000020
90e4755a 595
efd81785
PB
596#define T2_SUBS_PC_LR 0xf3de8f00
597
a737bd4d 598#define DATA_OP_SHIFT 21
90e4755a 599
ef8d22e6
PB
600#define T2_OPCODE_MASK 0xfe1fffff
601#define T2_DATA_OP_SHIFT 21
602
a737bd4d
NC
603/* Codes to distinguish the arithmetic instructions. */
604#define OPCODE_AND 0
605#define OPCODE_EOR 1
606#define OPCODE_SUB 2
607#define OPCODE_RSB 3
608#define OPCODE_ADD 4
609#define OPCODE_ADC 5
610#define OPCODE_SBC 6
611#define OPCODE_RSC 7
612#define OPCODE_TST 8
613#define OPCODE_TEQ 9
614#define OPCODE_CMP 10
615#define OPCODE_CMN 11
616#define OPCODE_ORR 12
617#define OPCODE_MOV 13
618#define OPCODE_BIC 14
619#define OPCODE_MVN 15
90e4755a 620
ef8d22e6
PB
621#define T2_OPCODE_AND 0
622#define T2_OPCODE_BIC 1
623#define T2_OPCODE_ORR 2
624#define T2_OPCODE_ORN 3
625#define T2_OPCODE_EOR 4
626#define T2_OPCODE_ADD 8
627#define T2_OPCODE_ADC 10
628#define T2_OPCODE_SBC 11
629#define T2_OPCODE_SUB 13
630#define T2_OPCODE_RSB 14
631
a737bd4d
NC
632#define T_OPCODE_MUL 0x4340
633#define T_OPCODE_TST 0x4200
634#define T_OPCODE_CMN 0x42c0
635#define T_OPCODE_NEG 0x4240
636#define T_OPCODE_MVN 0x43c0
90e4755a 637
a737bd4d
NC
638#define T_OPCODE_ADD_R3 0x1800
639#define T_OPCODE_SUB_R3 0x1a00
640#define T_OPCODE_ADD_HI 0x4400
641#define T_OPCODE_ADD_ST 0xb000
642#define T_OPCODE_SUB_ST 0xb080
643#define T_OPCODE_ADD_SP 0xa800
644#define T_OPCODE_ADD_PC 0xa000
645#define T_OPCODE_ADD_I8 0x3000
646#define T_OPCODE_SUB_I8 0x3800
647#define T_OPCODE_ADD_I3 0x1c00
648#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 649
a737bd4d
NC
650#define T_OPCODE_ASR_R 0x4100
651#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
652#define T_OPCODE_LSR_R 0x40c0
653#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
654#define T_OPCODE_ASR_I 0x1000
655#define T_OPCODE_LSL_I 0x0000
656#define T_OPCODE_LSR_I 0x0800
b99bd4ef 657
a737bd4d
NC
658#define T_OPCODE_MOV_I8 0x2000
659#define T_OPCODE_CMP_I8 0x2800
660#define T_OPCODE_CMP_LR 0x4280
661#define T_OPCODE_MOV_HR 0x4600
662#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 663
a737bd4d
NC
664#define T_OPCODE_LDR_PC 0x4800
665#define T_OPCODE_LDR_SP 0x9800
666#define T_OPCODE_STR_SP 0x9000
667#define T_OPCODE_LDR_IW 0x6800
668#define T_OPCODE_STR_IW 0x6000
669#define T_OPCODE_LDR_IH 0x8800
670#define T_OPCODE_STR_IH 0x8000
671#define T_OPCODE_LDR_IB 0x7800
672#define T_OPCODE_STR_IB 0x7000
673#define T_OPCODE_LDR_RW 0x5800
674#define T_OPCODE_STR_RW 0x5000
675#define T_OPCODE_LDR_RH 0x5a00
676#define T_OPCODE_STR_RH 0x5200
677#define T_OPCODE_LDR_RB 0x5c00
678#define T_OPCODE_STR_RB 0x5400
c9b604bd 679
a737bd4d
NC
680#define T_OPCODE_PUSH 0xb400
681#define T_OPCODE_POP 0xbc00
b99bd4ef 682
2fc8bdac 683#define T_OPCODE_BRANCH 0xe000
b99bd4ef 684
a737bd4d 685#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 686#define THUMB_PP_PC_LR 0x0100
c19d1205 687#define THUMB_LOAD_BIT 0x0800
53365c0d 688#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
689
690#define BAD_ARGS _("bad arguments to instruction")
fdfde340 691#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
692#define BAD_PC _("r15 not allowed here")
693#define BAD_COND _("instruction cannot be conditional")
694#define BAD_OVERLAP _("registers may not be the same")
695#define BAD_HIREG _("lo register required")
696#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 697#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
698#define BAD_BRANCH _("branch must be last instruction in IT block")
699#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 700#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
701#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
702#define BAD_IT_COND _("incorrect condition in IT block")
703#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 704#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
c19d1205
ZW
705
706static struct hash_control *arm_ops_hsh;
707static struct hash_control *arm_cond_hsh;
708static struct hash_control *arm_shift_hsh;
709static struct hash_control *arm_psr_hsh;
62b3e311 710static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
711static struct hash_control *arm_reg_hsh;
712static struct hash_control *arm_reloc_hsh;
62b3e311 713static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 714
b99bd4ef
NC
715/* Stuff needed to resolve the label ambiguity
716 As:
717 ...
718 label: <insn>
719 may differ from:
720 ...
721 label:
5f4273c7 722 <insn> */
b99bd4ef
NC
723
724symbolS * last_label_seen;
b34976b6 725static int label_is_thumb_function_name = FALSE;
e07e6e58 726
3d0c9500
NC
727/* Literal pool structure. Held on a per-section
728 and per-sub-section basis. */
a737bd4d 729
c19d1205 730#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 731typedef struct literal_pool
b99bd4ef 732{
c19d1205
ZW
733 expressionS literals [MAX_LITERAL_POOL_SIZE];
734 unsigned int next_free_entry;
735 unsigned int id;
736 symbolS * symbol;
737 segT section;
738 subsegT sub_section;
61b5f74b 739 struct literal_pool * next;
3d0c9500 740} literal_pool;
b99bd4ef 741
3d0c9500
NC
742/* Pointer to a linked list of literal pools. */
743literal_pool * list_of_pools = NULL;
e27ec89e 744
e07e6e58
NC
745#ifdef OBJ_ELF
746# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
747#else
748static struct current_it now_it;
749#endif
750
751static inline int
752now_it_compatible (int cond)
753{
754 return (cond & ~1) == (now_it.cc & ~1);
755}
756
757static inline int
758conditional_insn (void)
759{
760 return inst.cond != COND_ALWAYS;
761}
762
763static int in_it_block (void);
764
765static int handle_it_state (void);
766
767static void force_automatic_it_block_close (void);
768
769#define set_it_insn_type(type) \
770 do \
771 { \
772 inst.it_insn_type = type; \
773 if (handle_it_state () == FAIL) \
774 return; \
775 } \
776 while (0)
777
778#define set_it_insn_type_last() \
779 do \
780 { \
781 if (inst.cond == COND_ALWAYS) \
782 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
783 else \
784 set_it_insn_type (INSIDE_IT_LAST_INSN); \
785 } \
786 while (0)
787
c19d1205 788/* Pure syntax. */
b99bd4ef 789
c19d1205
ZW
790/* This array holds the chars that always start a comment. If the
791 pre-processor is disabled, these aren't very useful. */
792const char comment_chars[] = "@";
3d0c9500 793
c19d1205
ZW
794/* This array holds the chars that only start a comment at the beginning of
795 a line. If the line seems to have the form '# 123 filename'
796 .line and .file directives will appear in the pre-processed output. */
797/* Note that input_file.c hand checks for '#' at the beginning of the
798 first line of the input file. This is because the compiler outputs
799 #NO_APP at the beginning of its output. */
800/* Also note that comments like this one will always work. */
801const char line_comment_chars[] = "#";
3d0c9500 802
c19d1205 803const char line_separator_chars[] = ";";
b99bd4ef 804
c19d1205
ZW
805/* Chars that can be used to separate mant
806 from exp in floating point numbers. */
807const char EXP_CHARS[] = "eE";
3d0c9500 808
c19d1205
ZW
809/* Chars that mean this number is a floating point constant. */
810/* As in 0f12.456 */
811/* or 0d1.2345e12 */
b99bd4ef 812
c19d1205 813const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 814
c19d1205
ZW
815/* Prefix characters that indicate the start of an immediate
816 value. */
817#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 818
c19d1205
ZW
819/* Separator character handling. */
820
821#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
822
823static inline int
824skip_past_char (char ** str, char c)
825{
826 if (**str == c)
827 {
828 (*str)++;
829 return SUCCESS;
3d0c9500 830 }
c19d1205
ZW
831 else
832 return FAIL;
833}
834#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 835
c19d1205
ZW
836/* Arithmetic expressions (possibly involving symbols). */
837
838/* Return TRUE if anything in the expression is a bignum. */
839
840static int
841walk_no_bignums (symbolS * sp)
842{
843 if (symbol_get_value_expression (sp)->X_op == O_big)
844 return 1;
845
846 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 847 {
c19d1205
ZW
848 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
849 || (symbol_get_value_expression (sp)->X_op_symbol
850 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
851 }
852
c19d1205 853 return 0;
3d0c9500
NC
854}
855
c19d1205
ZW
856static int in_my_get_expression = 0;
857
858/* Third argument to my_get_expression. */
859#define GE_NO_PREFIX 0
860#define GE_IMM_PREFIX 1
861#define GE_OPT_PREFIX 2
5287ad62
JB
862/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
863 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
864#define GE_OPT_PREFIX_BIG 3
a737bd4d 865
b99bd4ef 866static int
c19d1205 867my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 868{
c19d1205
ZW
869 char * save_in;
870 segT seg;
b99bd4ef 871
c19d1205
ZW
872 /* In unified syntax, all prefixes are optional. */
873 if (unified_syntax)
5287ad62
JB
874 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
875 : GE_OPT_PREFIX;
b99bd4ef 876
c19d1205 877 switch (prefix_mode)
b99bd4ef 878 {
c19d1205
ZW
879 case GE_NO_PREFIX: break;
880 case GE_IMM_PREFIX:
881 if (!is_immediate_prefix (**str))
882 {
883 inst.error = _("immediate expression requires a # prefix");
884 return FAIL;
885 }
886 (*str)++;
887 break;
888 case GE_OPT_PREFIX:
5287ad62 889 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
890 if (is_immediate_prefix (**str))
891 (*str)++;
892 break;
893 default: abort ();
894 }
b99bd4ef 895
c19d1205 896 memset (ep, 0, sizeof (expressionS));
b99bd4ef 897
c19d1205
ZW
898 save_in = input_line_pointer;
899 input_line_pointer = *str;
900 in_my_get_expression = 1;
901 seg = expression (ep);
902 in_my_get_expression = 0;
903
904 if (ep->X_op == O_illegal)
b99bd4ef 905 {
c19d1205
ZW
906 /* We found a bad expression in md_operand(). */
907 *str = input_line_pointer;
908 input_line_pointer = save_in;
909 if (inst.error == NULL)
910 inst.error = _("bad expression");
911 return 1;
912 }
b99bd4ef 913
c19d1205
ZW
914#ifdef OBJ_AOUT
915 if (seg != absolute_section
916 && seg != text_section
917 && seg != data_section
918 && seg != bss_section
919 && seg != undefined_section)
920 {
921 inst.error = _("bad segment");
922 *str = input_line_pointer;
923 input_line_pointer = save_in;
924 return 1;
b99bd4ef 925 }
c19d1205 926#endif
b99bd4ef 927
c19d1205
ZW
928 /* Get rid of any bignums now, so that we don't generate an error for which
929 we can't establish a line number later on. Big numbers are never valid
930 in instructions, which is where this routine is always called. */
5287ad62
JB
931 if (prefix_mode != GE_OPT_PREFIX_BIG
932 && (ep->X_op == O_big
933 || (ep->X_add_symbol
934 && (walk_no_bignums (ep->X_add_symbol)
935 || (ep->X_op_symbol
936 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
937 {
938 inst.error = _("invalid constant");
939 *str = input_line_pointer;
940 input_line_pointer = save_in;
941 return 1;
942 }
b99bd4ef 943
c19d1205
ZW
944 *str = input_line_pointer;
945 input_line_pointer = save_in;
946 return 0;
b99bd4ef
NC
947}
948
c19d1205
ZW
949/* Turn a string in input_line_pointer into a floating point constant
950 of type TYPE, and store the appropriate bytes in *LITP. The number
951 of LITTLENUMS emitted is stored in *SIZEP. An error message is
952 returned, or NULL on OK.
b99bd4ef 953
c19d1205
ZW
954 Note that fp constants aren't represent in the normal way on the ARM.
955 In big endian mode, things are as expected. However, in little endian
956 mode fp constants are big-endian word-wise, and little-endian byte-wise
957 within the words. For example, (double) 1.1 in big endian mode is
958 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
959 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 960
c19d1205 961 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 962
c19d1205
ZW
963char *
964md_atof (int type, char * litP, int * sizeP)
965{
966 int prec;
967 LITTLENUM_TYPE words[MAX_LITTLENUMS];
968 char *t;
969 int i;
b99bd4ef 970
c19d1205
ZW
971 switch (type)
972 {
973 case 'f':
974 case 'F':
975 case 's':
976 case 'S':
977 prec = 2;
978 break;
b99bd4ef 979
c19d1205
ZW
980 case 'd':
981 case 'D':
982 case 'r':
983 case 'R':
984 prec = 4;
985 break;
b99bd4ef 986
c19d1205
ZW
987 case 'x':
988 case 'X':
499ac353 989 prec = 5;
c19d1205 990 break;
b99bd4ef 991
c19d1205
ZW
992 case 'p':
993 case 'P':
499ac353 994 prec = 5;
c19d1205 995 break;
a737bd4d 996
c19d1205
ZW
997 default:
998 *sizeP = 0;
499ac353 999 return _("Unrecognized or unsupported floating point constant");
c19d1205 1000 }
b99bd4ef 1001
c19d1205
ZW
1002 t = atof_ieee (input_line_pointer, type, words);
1003 if (t)
1004 input_line_pointer = t;
499ac353 1005 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1006
c19d1205
ZW
1007 if (target_big_endian)
1008 {
1009 for (i = 0; i < prec; i++)
1010 {
499ac353
NC
1011 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1012 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1013 }
1014 }
1015 else
1016 {
e74cfd16 1017 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1018 for (i = prec - 1; i >= 0; i--)
1019 {
499ac353
NC
1020 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1021 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1022 }
1023 else
1024 /* For a 4 byte float the order of elements in `words' is 1 0.
1025 For an 8 byte float the order is 1 0 3 2. */
1026 for (i = 0; i < prec; i += 2)
1027 {
499ac353
NC
1028 md_number_to_chars (litP, (valueT) words[i + 1],
1029 sizeof (LITTLENUM_TYPE));
1030 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1031 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1032 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1033 }
1034 }
b99bd4ef 1035
499ac353 1036 return NULL;
c19d1205 1037}
b99bd4ef 1038
c19d1205
ZW
1039/* We handle all bad expressions here, so that we can report the faulty
1040 instruction in the error message. */
1041void
1042md_operand (expressionS * expr)
1043{
1044 if (in_my_get_expression)
1045 expr->X_op = O_illegal;
b99bd4ef
NC
1046}
1047
c19d1205 1048/* Immediate values. */
b99bd4ef 1049
c19d1205
ZW
1050/* Generic immediate-value read function for use in directives.
1051 Accepts anything that 'expression' can fold to a constant.
1052 *val receives the number. */
1053#ifdef OBJ_ELF
1054static int
1055immediate_for_directive (int *val)
b99bd4ef 1056{
c19d1205
ZW
1057 expressionS exp;
1058 exp.X_op = O_illegal;
b99bd4ef 1059
c19d1205
ZW
1060 if (is_immediate_prefix (*input_line_pointer))
1061 {
1062 input_line_pointer++;
1063 expression (&exp);
1064 }
b99bd4ef 1065
c19d1205
ZW
1066 if (exp.X_op != O_constant)
1067 {
1068 as_bad (_("expected #constant"));
1069 ignore_rest_of_line ();
1070 return FAIL;
1071 }
1072 *val = exp.X_add_number;
1073 return SUCCESS;
b99bd4ef 1074}
c19d1205 1075#endif
b99bd4ef 1076
c19d1205 1077/* Register parsing. */
b99bd4ef 1078
c19d1205
ZW
1079/* Generic register parser. CCP points to what should be the
1080 beginning of a register name. If it is indeed a valid register
1081 name, advance CCP over it and return the reg_entry structure;
1082 otherwise return NULL. Does not issue diagnostics. */
1083
1084static struct reg_entry *
1085arm_reg_parse_multi (char **ccp)
b99bd4ef 1086{
c19d1205
ZW
1087 char *start = *ccp;
1088 char *p;
1089 struct reg_entry *reg;
b99bd4ef 1090
c19d1205
ZW
1091#ifdef REGISTER_PREFIX
1092 if (*start != REGISTER_PREFIX)
01cfc07f 1093 return NULL;
c19d1205
ZW
1094 start++;
1095#endif
1096#ifdef OPTIONAL_REGISTER_PREFIX
1097 if (*start == OPTIONAL_REGISTER_PREFIX)
1098 start++;
1099#endif
b99bd4ef 1100
c19d1205
ZW
1101 p = start;
1102 if (!ISALPHA (*p) || !is_name_beginner (*p))
1103 return NULL;
b99bd4ef 1104
c19d1205
ZW
1105 do
1106 p++;
1107 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1108
1109 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1110
1111 if (!reg)
1112 return NULL;
1113
1114 *ccp = p;
1115 return reg;
b99bd4ef
NC
1116}
1117
1118static int
dcbf9037
JB
1119arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1120 enum arm_reg_type type)
b99bd4ef 1121{
c19d1205
ZW
1122 /* Alternative syntaxes are accepted for a few register classes. */
1123 switch (type)
1124 {
1125 case REG_TYPE_MVF:
1126 case REG_TYPE_MVD:
1127 case REG_TYPE_MVFX:
1128 case REG_TYPE_MVDX:
1129 /* Generic coprocessor register names are allowed for these. */
79134647 1130 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1131 return reg->number;
1132 break;
69b97547 1133
c19d1205
ZW
1134 case REG_TYPE_CP:
1135 /* For backward compatibility, a bare number is valid here. */
1136 {
1137 unsigned long processor = strtoul (start, ccp, 10);
1138 if (*ccp != start && processor <= 15)
1139 return processor;
1140 }
6057a28f 1141
c19d1205
ZW
1142 case REG_TYPE_MMXWC:
1143 /* WC includes WCG. ??? I'm not sure this is true for all
1144 instructions that take WC registers. */
79134647 1145 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1146 return reg->number;
6057a28f 1147 break;
c19d1205 1148
6057a28f 1149 default:
c19d1205 1150 break;
6057a28f
NC
1151 }
1152
dcbf9037
JB
1153 return FAIL;
1154}
1155
1156/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1157 return value is the register number or FAIL. */
1158
1159static int
1160arm_reg_parse (char **ccp, enum arm_reg_type type)
1161{
1162 char *start = *ccp;
1163 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1164 int ret;
1165
1166 /* Do not allow a scalar (reg+index) to parse as a register. */
1167 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1168 return FAIL;
1169
1170 if (reg && reg->type == type)
1171 return reg->number;
1172
1173 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1174 return ret;
1175
c19d1205
ZW
1176 *ccp = start;
1177 return FAIL;
1178}
69b97547 1179
dcbf9037
JB
1180/* Parse a Neon type specifier. *STR should point at the leading '.'
1181 character. Does no verification at this stage that the type fits the opcode
1182 properly. E.g.,
1183
1184 .i32.i32.s16
1185 .s32.f32
1186 .u16
1187
1188 Can all be legally parsed by this function.
1189
1190 Fills in neon_type struct pointer with parsed information, and updates STR
1191 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1192 type, FAIL if not. */
1193
1194static int
1195parse_neon_type (struct neon_type *type, char **str)
1196{
1197 char *ptr = *str;
1198
1199 if (type)
1200 type->elems = 0;
1201
1202 while (type->elems < NEON_MAX_TYPE_ELS)
1203 {
1204 enum neon_el_type thistype = NT_untyped;
1205 unsigned thissize = -1u;
1206
1207 if (*ptr != '.')
1208 break;
1209
1210 ptr++;
1211
1212 /* Just a size without an explicit type. */
1213 if (ISDIGIT (*ptr))
1214 goto parsesize;
1215
1216 switch (TOLOWER (*ptr))
1217 {
1218 case 'i': thistype = NT_integer; break;
1219 case 'f': thistype = NT_float; break;
1220 case 'p': thistype = NT_poly; break;
1221 case 's': thistype = NT_signed; break;
1222 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1223 case 'd':
1224 thistype = NT_float;
1225 thissize = 64;
1226 ptr++;
1227 goto done;
dcbf9037
JB
1228 default:
1229 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1230 return FAIL;
1231 }
1232
1233 ptr++;
1234
1235 /* .f is an abbreviation for .f32. */
1236 if (thistype == NT_float && !ISDIGIT (*ptr))
1237 thissize = 32;
1238 else
1239 {
1240 parsesize:
1241 thissize = strtoul (ptr, &ptr, 10);
1242
1243 if (thissize != 8 && thissize != 16 && thissize != 32
1244 && thissize != 64)
1245 {
1246 as_bad (_("bad size %d in type specifier"), thissize);
1247 return FAIL;
1248 }
1249 }
1250
037e8744 1251 done:
dcbf9037
JB
1252 if (type)
1253 {
1254 type->el[type->elems].type = thistype;
1255 type->el[type->elems].size = thissize;
1256 type->elems++;
1257 }
1258 }
1259
1260 /* Empty/missing type is not a successful parse. */
1261 if (type->elems == 0)
1262 return FAIL;
1263
1264 *str = ptr;
1265
1266 return SUCCESS;
1267}
1268
1269/* Errors may be set multiple times during parsing or bit encoding
1270 (particularly in the Neon bits), but usually the earliest error which is set
1271 will be the most meaningful. Avoid overwriting it with later (cascading)
1272 errors by calling this function. */
1273
1274static void
1275first_error (const char *err)
1276{
1277 if (!inst.error)
1278 inst.error = err;
1279}
1280
1281/* Parse a single type, e.g. ".s32", leading period included. */
1282static int
1283parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1284{
1285 char *str = *ccp;
1286 struct neon_type optype;
1287
1288 if (*str == '.')
1289 {
1290 if (parse_neon_type (&optype, &str) == SUCCESS)
1291 {
1292 if (optype.elems == 1)
1293 *vectype = optype.el[0];
1294 else
1295 {
1296 first_error (_("only one type should be specified for operand"));
1297 return FAIL;
1298 }
1299 }
1300 else
1301 {
1302 first_error (_("vector type expected"));
1303 return FAIL;
1304 }
1305 }
1306 else
1307 return FAIL;
5f4273c7 1308
dcbf9037 1309 *ccp = str;
5f4273c7 1310
dcbf9037
JB
1311 return SUCCESS;
1312}
1313
1314/* Special meanings for indices (which have a range of 0-7), which will fit into
1315 a 4-bit integer. */
1316
1317#define NEON_ALL_LANES 15
1318#define NEON_INTERLEAVE_LANES 14
1319
1320/* Parse either a register or a scalar, with an optional type. Return the
1321 register number, and optionally fill in the actual type of the register
1322 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1323 type/index information in *TYPEINFO. */
1324
1325static int
1326parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1327 enum arm_reg_type *rtype,
1328 struct neon_typed_alias *typeinfo)
1329{
1330 char *str = *ccp;
1331 struct reg_entry *reg = arm_reg_parse_multi (&str);
1332 struct neon_typed_alias atype;
1333 struct neon_type_el parsetype;
1334
1335 atype.defined = 0;
1336 atype.index = -1;
1337 atype.eltype.type = NT_invtype;
1338 atype.eltype.size = -1;
1339
1340 /* Try alternate syntax for some types of register. Note these are mutually
1341 exclusive with the Neon syntax extensions. */
1342 if (reg == NULL)
1343 {
1344 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1345 if (altreg != FAIL)
1346 *ccp = str;
1347 if (typeinfo)
1348 *typeinfo = atype;
1349 return altreg;
1350 }
1351
037e8744
JB
1352 /* Undo polymorphism when a set of register types may be accepted. */
1353 if ((type == REG_TYPE_NDQ
1354 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1355 || (type == REG_TYPE_VFSD
1356 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1357 || (type == REG_TYPE_NSDQ
1358 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1359 || reg->type == REG_TYPE_NQ))
1360 || (type == REG_TYPE_MMXWC
1361 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1362 type = reg->type;
1363
1364 if (type != reg->type)
1365 return FAIL;
1366
1367 if (reg->neon)
1368 atype = *reg->neon;
5f4273c7 1369
dcbf9037
JB
1370 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1371 {
1372 if ((atype.defined & NTA_HASTYPE) != 0)
1373 {
1374 first_error (_("can't redefine type for operand"));
1375 return FAIL;
1376 }
1377 atype.defined |= NTA_HASTYPE;
1378 atype.eltype = parsetype;
1379 }
5f4273c7 1380
dcbf9037
JB
1381 if (skip_past_char (&str, '[') == SUCCESS)
1382 {
1383 if (type != REG_TYPE_VFD)
1384 {
1385 first_error (_("only D registers may be indexed"));
1386 return FAIL;
1387 }
5f4273c7 1388
dcbf9037
JB
1389 if ((atype.defined & NTA_HASINDEX) != 0)
1390 {
1391 first_error (_("can't change index for operand"));
1392 return FAIL;
1393 }
1394
1395 atype.defined |= NTA_HASINDEX;
1396
1397 if (skip_past_char (&str, ']') == SUCCESS)
1398 atype.index = NEON_ALL_LANES;
1399 else
1400 {
1401 expressionS exp;
1402
1403 my_get_expression (&exp, &str, GE_NO_PREFIX);
1404
1405 if (exp.X_op != O_constant)
1406 {
1407 first_error (_("constant expression required"));
1408 return FAIL;
1409 }
1410
1411 if (skip_past_char (&str, ']') == FAIL)
1412 return FAIL;
1413
1414 atype.index = exp.X_add_number;
1415 }
1416 }
5f4273c7 1417
dcbf9037
JB
1418 if (typeinfo)
1419 *typeinfo = atype;
5f4273c7 1420
dcbf9037
JB
1421 if (rtype)
1422 *rtype = type;
5f4273c7 1423
dcbf9037 1424 *ccp = str;
5f4273c7 1425
dcbf9037
JB
1426 return reg->number;
1427}
1428
1429/* Like arm_reg_parse, but allow allow the following extra features:
1430 - If RTYPE is non-zero, return the (possibly restricted) type of the
1431 register (e.g. Neon double or quad reg when either has been requested).
1432 - If this is a Neon vector type with additional type information, fill
1433 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1434 This function will fault on encountering a scalar. */
dcbf9037
JB
1435
1436static int
1437arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1438 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1439{
1440 struct neon_typed_alias atype;
1441 char *str = *ccp;
1442 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1443
1444 if (reg == FAIL)
1445 return FAIL;
1446
1447 /* Do not allow a scalar (reg+index) to parse as a register. */
1448 if ((atype.defined & NTA_HASINDEX) != 0)
1449 {
1450 first_error (_("register operand expected, but got scalar"));
1451 return FAIL;
1452 }
1453
1454 if (vectype)
1455 *vectype = atype.eltype;
1456
1457 *ccp = str;
1458
1459 return reg;
1460}
1461
1462#define NEON_SCALAR_REG(X) ((X) >> 4)
1463#define NEON_SCALAR_INDEX(X) ((X) & 15)
1464
5287ad62
JB
1465/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1466 have enough information to be able to do a good job bounds-checking. So, we
1467 just do easy checks here, and do further checks later. */
1468
1469static int
dcbf9037 1470parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1471{
dcbf9037 1472 int reg;
5287ad62 1473 char *str = *ccp;
dcbf9037 1474 struct neon_typed_alias atype;
5f4273c7 1475
dcbf9037 1476 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1477
dcbf9037 1478 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1479 return FAIL;
5f4273c7 1480
dcbf9037 1481 if (atype.index == NEON_ALL_LANES)
5287ad62 1482 {
dcbf9037 1483 first_error (_("scalar must have an index"));
5287ad62
JB
1484 return FAIL;
1485 }
dcbf9037 1486 else if (atype.index >= 64 / elsize)
5287ad62 1487 {
dcbf9037 1488 first_error (_("scalar index out of range"));
5287ad62
JB
1489 return FAIL;
1490 }
5f4273c7 1491
dcbf9037
JB
1492 if (type)
1493 *type = atype.eltype;
5f4273c7 1494
5287ad62 1495 *ccp = str;
5f4273c7 1496
dcbf9037 1497 return reg * 16 + atype.index;
5287ad62
JB
1498}
1499
c19d1205 1500/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1501
c19d1205
ZW
1502static long
1503parse_reg_list (char ** strp)
1504{
1505 char * str = * strp;
1506 long range = 0;
1507 int another_range;
a737bd4d 1508
c19d1205
ZW
1509 /* We come back here if we get ranges concatenated by '+' or '|'. */
1510 do
6057a28f 1511 {
c19d1205 1512 another_range = 0;
a737bd4d 1513
c19d1205
ZW
1514 if (*str == '{')
1515 {
1516 int in_range = 0;
1517 int cur_reg = -1;
a737bd4d 1518
c19d1205
ZW
1519 str++;
1520 do
1521 {
1522 int reg;
6057a28f 1523
dcbf9037 1524 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1525 {
dcbf9037 1526 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1527 return FAIL;
1528 }
a737bd4d 1529
c19d1205
ZW
1530 if (in_range)
1531 {
1532 int i;
a737bd4d 1533
c19d1205
ZW
1534 if (reg <= cur_reg)
1535 {
dcbf9037 1536 first_error (_("bad range in register list"));
c19d1205
ZW
1537 return FAIL;
1538 }
40a18ebd 1539
c19d1205
ZW
1540 for (i = cur_reg + 1; i < reg; i++)
1541 {
1542 if (range & (1 << i))
1543 as_tsktsk
1544 (_("Warning: duplicated register (r%d) in register list"),
1545 i);
1546 else
1547 range |= 1 << i;
1548 }
1549 in_range = 0;
1550 }
a737bd4d 1551
c19d1205
ZW
1552 if (range & (1 << reg))
1553 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1554 reg);
1555 else if (reg <= cur_reg)
1556 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1557
c19d1205
ZW
1558 range |= 1 << reg;
1559 cur_reg = reg;
1560 }
1561 while (skip_past_comma (&str) != FAIL
1562 || (in_range = 1, *str++ == '-'));
1563 str--;
a737bd4d 1564
c19d1205
ZW
1565 if (*str++ != '}')
1566 {
dcbf9037 1567 first_error (_("missing `}'"));
c19d1205
ZW
1568 return FAIL;
1569 }
1570 }
1571 else
1572 {
1573 expressionS expr;
40a18ebd 1574
c19d1205
ZW
1575 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1576 return FAIL;
40a18ebd 1577
c19d1205
ZW
1578 if (expr.X_op == O_constant)
1579 {
1580 if (expr.X_add_number
1581 != (expr.X_add_number & 0x0000ffff))
1582 {
1583 inst.error = _("invalid register mask");
1584 return FAIL;
1585 }
a737bd4d 1586
c19d1205
ZW
1587 if ((range & expr.X_add_number) != 0)
1588 {
1589 int regno = range & expr.X_add_number;
a737bd4d 1590
c19d1205
ZW
1591 regno &= -regno;
1592 regno = (1 << regno) - 1;
1593 as_tsktsk
1594 (_("Warning: duplicated register (r%d) in register list"),
1595 regno);
1596 }
a737bd4d 1597
c19d1205
ZW
1598 range |= expr.X_add_number;
1599 }
1600 else
1601 {
1602 if (inst.reloc.type != 0)
1603 {
1604 inst.error = _("expression too complex");
1605 return FAIL;
1606 }
a737bd4d 1607
c19d1205
ZW
1608 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1609 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1610 inst.reloc.pc_rel = 0;
1611 }
1612 }
a737bd4d 1613
c19d1205
ZW
1614 if (*str == '|' || *str == '+')
1615 {
1616 str++;
1617 another_range = 1;
1618 }
a737bd4d 1619 }
c19d1205 1620 while (another_range);
a737bd4d 1621
c19d1205
ZW
1622 *strp = str;
1623 return range;
a737bd4d
NC
1624}
1625
5287ad62
JB
1626/* Types of registers in a list. */
1627
1628enum reg_list_els
1629{
1630 REGLIST_VFP_S,
1631 REGLIST_VFP_D,
1632 REGLIST_NEON_D
1633};
1634
c19d1205
ZW
1635/* Parse a VFP register list. If the string is invalid return FAIL.
1636 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1637 register. Parses registers of type ETYPE.
1638 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1639 - Q registers can be used to specify pairs of D registers
1640 - { } can be omitted from around a singleton register list
1641 FIXME: This is not implemented, as it would require backtracking in
1642 some cases, e.g.:
1643 vtbl.8 d3,d4,d5
1644 This could be done (the meaning isn't really ambiguous), but doesn't
1645 fit in well with the current parsing framework.
dcbf9037
JB
1646 - 32 D registers may be used (also true for VFPv3).
1647 FIXME: Types are ignored in these register lists, which is probably a
1648 bug. */
6057a28f 1649
c19d1205 1650static int
037e8744 1651parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1652{
037e8744 1653 char *str = *ccp;
c19d1205
ZW
1654 int base_reg;
1655 int new_base;
5287ad62
JB
1656 enum arm_reg_type regtype = 0;
1657 int max_regs = 0;
c19d1205
ZW
1658 int count = 0;
1659 int warned = 0;
1660 unsigned long mask = 0;
a737bd4d 1661 int i;
6057a28f 1662
037e8744 1663 if (*str != '{')
5287ad62
JB
1664 {
1665 inst.error = _("expecting {");
1666 return FAIL;
1667 }
6057a28f 1668
037e8744 1669 str++;
6057a28f 1670
5287ad62 1671 switch (etype)
c19d1205 1672 {
5287ad62 1673 case REGLIST_VFP_S:
c19d1205
ZW
1674 regtype = REG_TYPE_VFS;
1675 max_regs = 32;
5287ad62 1676 break;
5f4273c7 1677
5287ad62
JB
1678 case REGLIST_VFP_D:
1679 regtype = REG_TYPE_VFD;
b7fc2769 1680 break;
5f4273c7 1681
b7fc2769
JB
1682 case REGLIST_NEON_D:
1683 regtype = REG_TYPE_NDQ;
1684 break;
1685 }
1686
1687 if (etype != REGLIST_VFP_S)
1688 {
b1cc4aeb
PB
1689 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1690 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1691 {
1692 max_regs = 32;
1693 if (thumb_mode)
1694 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1695 fpu_vfp_ext_d32);
5287ad62
JB
1696 else
1697 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1698 fpu_vfp_ext_d32);
5287ad62
JB
1699 }
1700 else
1701 max_regs = 16;
c19d1205 1702 }
6057a28f 1703
c19d1205 1704 base_reg = max_regs;
a737bd4d 1705
c19d1205
ZW
1706 do
1707 {
5287ad62 1708 int setmask = 1, addregs = 1;
dcbf9037 1709
037e8744 1710 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1711
c19d1205 1712 if (new_base == FAIL)
a737bd4d 1713 {
dcbf9037 1714 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1715 return FAIL;
1716 }
5f4273c7 1717
b7fc2769
JB
1718 if (new_base >= max_regs)
1719 {
1720 first_error (_("register out of range in list"));
1721 return FAIL;
1722 }
5f4273c7 1723
5287ad62
JB
1724 /* Note: a value of 2 * n is returned for the register Q<n>. */
1725 if (regtype == REG_TYPE_NQ)
1726 {
1727 setmask = 3;
1728 addregs = 2;
1729 }
1730
c19d1205
ZW
1731 if (new_base < base_reg)
1732 base_reg = new_base;
a737bd4d 1733
5287ad62 1734 if (mask & (setmask << new_base))
c19d1205 1735 {
dcbf9037 1736 first_error (_("invalid register list"));
c19d1205 1737 return FAIL;
a737bd4d 1738 }
a737bd4d 1739
c19d1205
ZW
1740 if ((mask >> new_base) != 0 && ! warned)
1741 {
1742 as_tsktsk (_("register list not in ascending order"));
1743 warned = 1;
1744 }
0bbf2aa4 1745
5287ad62
JB
1746 mask |= setmask << new_base;
1747 count += addregs;
0bbf2aa4 1748
037e8744 1749 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1750 {
1751 int high_range;
0bbf2aa4 1752
037e8744 1753 str++;
0bbf2aa4 1754
037e8744 1755 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1756 == FAIL)
c19d1205
ZW
1757 {
1758 inst.error = gettext (reg_expected_msgs[regtype]);
1759 return FAIL;
1760 }
0bbf2aa4 1761
b7fc2769
JB
1762 if (high_range >= max_regs)
1763 {
1764 first_error (_("register out of range in list"));
1765 return FAIL;
1766 }
1767
5287ad62
JB
1768 if (regtype == REG_TYPE_NQ)
1769 high_range = high_range + 1;
1770
c19d1205
ZW
1771 if (high_range <= new_base)
1772 {
1773 inst.error = _("register range not in ascending order");
1774 return FAIL;
1775 }
0bbf2aa4 1776
5287ad62 1777 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1778 {
5287ad62 1779 if (mask & (setmask << new_base))
0bbf2aa4 1780 {
c19d1205
ZW
1781 inst.error = _("invalid register list");
1782 return FAIL;
0bbf2aa4 1783 }
c19d1205 1784
5287ad62
JB
1785 mask |= setmask << new_base;
1786 count += addregs;
0bbf2aa4 1787 }
0bbf2aa4 1788 }
0bbf2aa4 1789 }
037e8744 1790 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1791
037e8744 1792 str++;
0bbf2aa4 1793
c19d1205
ZW
1794 /* Sanity check -- should have raised a parse error above. */
1795 if (count == 0 || count > max_regs)
1796 abort ();
1797
1798 *pbase = base_reg;
1799
1800 /* Final test -- the registers must be consecutive. */
1801 mask >>= base_reg;
1802 for (i = 0; i < count; i++)
1803 {
1804 if ((mask & (1u << i)) == 0)
1805 {
1806 inst.error = _("non-contiguous register range");
1807 return FAIL;
1808 }
1809 }
1810
037e8744
JB
1811 *ccp = str;
1812
c19d1205 1813 return count;
b99bd4ef
NC
1814}
1815
dcbf9037
JB
1816/* True if two alias types are the same. */
1817
1818static int
1819neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1820{
1821 if (!a && !b)
1822 return 1;
5f4273c7 1823
dcbf9037
JB
1824 if (!a || !b)
1825 return 0;
1826
1827 if (a->defined != b->defined)
1828 return 0;
5f4273c7 1829
dcbf9037
JB
1830 if ((a->defined & NTA_HASTYPE) != 0
1831 && (a->eltype.type != b->eltype.type
1832 || a->eltype.size != b->eltype.size))
1833 return 0;
1834
1835 if ((a->defined & NTA_HASINDEX) != 0
1836 && (a->index != b->index))
1837 return 0;
5f4273c7 1838
dcbf9037
JB
1839 return 1;
1840}
1841
5287ad62
JB
1842/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1843 The base register is put in *PBASE.
dcbf9037 1844 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1845 the return value.
1846 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1847 Bits [6:5] encode the list length (minus one).
1848 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1849
5287ad62 1850#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1851#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1852#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1853
1854static int
dcbf9037
JB
1855parse_neon_el_struct_list (char **str, unsigned *pbase,
1856 struct neon_type_el *eltype)
5287ad62
JB
1857{
1858 char *ptr = *str;
1859 int base_reg = -1;
1860 int reg_incr = -1;
1861 int count = 0;
1862 int lane = -1;
1863 int leading_brace = 0;
1864 enum arm_reg_type rtype = REG_TYPE_NDQ;
1865 int addregs = 1;
1866 const char *const incr_error = "register stride must be 1 or 2";
1867 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1868 struct neon_typed_alias firsttype;
5f4273c7 1869
5287ad62
JB
1870 if (skip_past_char (&ptr, '{') == SUCCESS)
1871 leading_brace = 1;
5f4273c7 1872
5287ad62
JB
1873 do
1874 {
dcbf9037
JB
1875 struct neon_typed_alias atype;
1876 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1877
5287ad62
JB
1878 if (getreg == FAIL)
1879 {
dcbf9037 1880 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1881 return FAIL;
1882 }
5f4273c7 1883
5287ad62
JB
1884 if (base_reg == -1)
1885 {
1886 base_reg = getreg;
1887 if (rtype == REG_TYPE_NQ)
1888 {
1889 reg_incr = 1;
1890 addregs = 2;
1891 }
dcbf9037 1892 firsttype = atype;
5287ad62
JB
1893 }
1894 else if (reg_incr == -1)
1895 {
1896 reg_incr = getreg - base_reg;
1897 if (reg_incr < 1 || reg_incr > 2)
1898 {
dcbf9037 1899 first_error (_(incr_error));
5287ad62
JB
1900 return FAIL;
1901 }
1902 }
1903 else if (getreg != base_reg + reg_incr * count)
1904 {
dcbf9037
JB
1905 first_error (_(incr_error));
1906 return FAIL;
1907 }
1908
1909 if (!neon_alias_types_same (&atype, &firsttype))
1910 {
1911 first_error (_(type_error));
5287ad62
JB
1912 return FAIL;
1913 }
5f4273c7 1914
5287ad62
JB
1915 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1916 modes. */
1917 if (ptr[0] == '-')
1918 {
dcbf9037 1919 struct neon_typed_alias htype;
5287ad62
JB
1920 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1921 if (lane == -1)
1922 lane = NEON_INTERLEAVE_LANES;
1923 else if (lane != NEON_INTERLEAVE_LANES)
1924 {
dcbf9037 1925 first_error (_(type_error));
5287ad62
JB
1926 return FAIL;
1927 }
1928 if (reg_incr == -1)
1929 reg_incr = 1;
1930 else if (reg_incr != 1)
1931 {
dcbf9037 1932 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1933 return FAIL;
1934 }
1935 ptr++;
dcbf9037 1936 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1937 if (hireg == FAIL)
1938 {
dcbf9037
JB
1939 first_error (_(reg_expected_msgs[rtype]));
1940 return FAIL;
1941 }
1942 if (!neon_alias_types_same (&htype, &firsttype))
1943 {
1944 first_error (_(type_error));
5287ad62
JB
1945 return FAIL;
1946 }
1947 count += hireg + dregs - getreg;
1948 continue;
1949 }
5f4273c7 1950
5287ad62
JB
1951 /* If we're using Q registers, we can't use [] or [n] syntax. */
1952 if (rtype == REG_TYPE_NQ)
1953 {
1954 count += 2;
1955 continue;
1956 }
5f4273c7 1957
dcbf9037 1958 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1959 {
dcbf9037
JB
1960 if (lane == -1)
1961 lane = atype.index;
1962 else if (lane != atype.index)
5287ad62 1963 {
dcbf9037
JB
1964 first_error (_(type_error));
1965 return FAIL;
5287ad62
JB
1966 }
1967 }
1968 else if (lane == -1)
1969 lane = NEON_INTERLEAVE_LANES;
1970 else if (lane != NEON_INTERLEAVE_LANES)
1971 {
dcbf9037 1972 first_error (_(type_error));
5287ad62
JB
1973 return FAIL;
1974 }
1975 count++;
1976 }
1977 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1978
5287ad62
JB
1979 /* No lane set by [x]. We must be interleaving structures. */
1980 if (lane == -1)
1981 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1982
5287ad62
JB
1983 /* Sanity check. */
1984 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1985 || (count > 1 && reg_incr == -1))
1986 {
dcbf9037 1987 first_error (_("error parsing element/structure list"));
5287ad62
JB
1988 return FAIL;
1989 }
1990
1991 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1992 {
dcbf9037 1993 first_error (_("expected }"));
5287ad62
JB
1994 return FAIL;
1995 }
5f4273c7 1996
5287ad62
JB
1997 if (reg_incr == -1)
1998 reg_incr = 1;
1999
dcbf9037
JB
2000 if (eltype)
2001 *eltype = firsttype.eltype;
2002
5287ad62
JB
2003 *pbase = base_reg;
2004 *str = ptr;
5f4273c7 2005
5287ad62
JB
2006 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2007}
2008
c19d1205
ZW
2009/* Parse an explicit relocation suffix on an expression. This is
2010 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2011 arm_reloc_hsh contains no entries, so this function can only
2012 succeed if there is no () after the word. Returns -1 on error,
2013 BFD_RELOC_UNUSED if there wasn't any suffix. */
2014static int
2015parse_reloc (char **str)
b99bd4ef 2016{
c19d1205
ZW
2017 struct reloc_entry *r;
2018 char *p, *q;
b99bd4ef 2019
c19d1205
ZW
2020 if (**str != '(')
2021 return BFD_RELOC_UNUSED;
b99bd4ef 2022
c19d1205
ZW
2023 p = *str + 1;
2024 q = p;
2025
2026 while (*q && *q != ')' && *q != ',')
2027 q++;
2028 if (*q != ')')
2029 return -1;
2030
2031 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2032 return -1;
2033
2034 *str = q + 1;
2035 return r->reloc;
b99bd4ef
NC
2036}
2037
c19d1205
ZW
2038/* Directives: register aliases. */
2039
dcbf9037 2040static struct reg_entry *
c19d1205 2041insert_reg_alias (char *str, int number, int type)
b99bd4ef 2042{
c19d1205
ZW
2043 struct reg_entry *new;
2044 const char *name;
b99bd4ef 2045
c19d1205
ZW
2046 if ((new = hash_find (arm_reg_hsh, str)) != 0)
2047 {
2048 if (new->builtin)
2049 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2050
c19d1205
ZW
2051 /* Only warn about a redefinition if it's not defined as the
2052 same register. */
2053 else if (new->number != number || new->type != type)
2054 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2055
d929913e 2056 return NULL;
c19d1205 2057 }
b99bd4ef 2058
c19d1205
ZW
2059 name = xstrdup (str);
2060 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 2061
c19d1205
ZW
2062 new->name = name;
2063 new->number = number;
2064 new->type = type;
2065 new->builtin = FALSE;
dcbf9037 2066 new->neon = NULL;
b99bd4ef 2067
5a49b8ac 2068 if (hash_insert (arm_reg_hsh, name, (void *) new))
c19d1205 2069 abort ();
5f4273c7 2070
dcbf9037
JB
2071 return new;
2072}
2073
2074static void
2075insert_neon_reg_alias (char *str, int number, int type,
2076 struct neon_typed_alias *atype)
2077{
2078 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2079
dcbf9037
JB
2080 if (!reg)
2081 {
2082 first_error (_("attempt to redefine typed alias"));
2083 return;
2084 }
5f4273c7 2085
dcbf9037
JB
2086 if (atype)
2087 {
2088 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2089 *reg->neon = *atype;
2090 }
c19d1205 2091}
b99bd4ef 2092
c19d1205 2093/* Look for the .req directive. This is of the form:
b99bd4ef 2094
c19d1205 2095 new_register_name .req existing_register_name
b99bd4ef 2096
c19d1205 2097 If we find one, or if it looks sufficiently like one that we want to
d929913e 2098 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2099
d929913e 2100static bfd_boolean
c19d1205
ZW
2101create_register_alias (char * newname, char *p)
2102{
2103 struct reg_entry *old;
2104 char *oldname, *nbuf;
2105 size_t nlen;
b99bd4ef 2106
c19d1205
ZW
2107 /* The input scrubber ensures that whitespace after the mnemonic is
2108 collapsed to single spaces. */
2109 oldname = p;
2110 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2111 return FALSE;
b99bd4ef 2112
c19d1205
ZW
2113 oldname += 6;
2114 if (*oldname == '\0')
d929913e 2115 return FALSE;
b99bd4ef 2116
c19d1205
ZW
2117 old = hash_find (arm_reg_hsh, oldname);
2118 if (!old)
b99bd4ef 2119 {
c19d1205 2120 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2121 return TRUE;
b99bd4ef
NC
2122 }
2123
c19d1205
ZW
2124 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2125 the desired alias name, and p points to its end. If not, then
2126 the desired alias name is in the global original_case_string. */
2127#ifdef TC_CASE_SENSITIVE
2128 nlen = p - newname;
2129#else
2130 newname = original_case_string;
2131 nlen = strlen (newname);
2132#endif
b99bd4ef 2133
c19d1205
ZW
2134 nbuf = alloca (nlen + 1);
2135 memcpy (nbuf, newname, nlen);
2136 nbuf[nlen] = '\0';
b99bd4ef 2137
c19d1205
ZW
2138 /* Create aliases under the new name as stated; an all-lowercase
2139 version of the new name; and an all-uppercase version of the new
2140 name. */
d929913e
NC
2141 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2142 {
2143 for (p = nbuf; *p; p++)
2144 *p = TOUPPER (*p);
c19d1205 2145
d929913e
NC
2146 if (strncmp (nbuf, newname, nlen))
2147 {
2148 /* If this attempt to create an additional alias fails, do not bother
2149 trying to create the all-lower case alias. We will fail and issue
2150 a second, duplicate error message. This situation arises when the
2151 programmer does something like:
2152 foo .req r0
2153 Foo .req r1
2154 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2155 the artificial FOO alias because it has already been created by the
d929913e
NC
2156 first .req. */
2157 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2158 return TRUE;
2159 }
c19d1205 2160
d929913e
NC
2161 for (p = nbuf; *p; p++)
2162 *p = TOLOWER (*p);
c19d1205 2163
d929913e
NC
2164 if (strncmp (nbuf, newname, nlen))
2165 insert_reg_alias (nbuf, old->number, old->type);
2166 }
c19d1205 2167
d929913e 2168 return TRUE;
b99bd4ef
NC
2169}
2170
dcbf9037
JB
2171/* Create a Neon typed/indexed register alias using directives, e.g.:
2172 X .dn d5.s32[1]
2173 Y .qn 6.s16
2174 Z .dn d7
2175 T .dn Z[0]
2176 These typed registers can be used instead of the types specified after the
2177 Neon mnemonic, so long as all operands given have types. Types can also be
2178 specified directly, e.g.:
5f4273c7 2179 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2180
2181static int
2182create_neon_reg_alias (char *newname, char *p)
2183{
2184 enum arm_reg_type basetype;
2185 struct reg_entry *basereg;
2186 struct reg_entry mybasereg;
2187 struct neon_type ntype;
2188 struct neon_typed_alias typeinfo;
2189 char *namebuf, *nameend;
2190 int namelen;
5f4273c7 2191
dcbf9037
JB
2192 typeinfo.defined = 0;
2193 typeinfo.eltype.type = NT_invtype;
2194 typeinfo.eltype.size = -1;
2195 typeinfo.index = -1;
5f4273c7 2196
dcbf9037 2197 nameend = p;
5f4273c7 2198
dcbf9037
JB
2199 if (strncmp (p, " .dn ", 5) == 0)
2200 basetype = REG_TYPE_VFD;
2201 else if (strncmp (p, " .qn ", 5) == 0)
2202 basetype = REG_TYPE_NQ;
2203 else
2204 return 0;
5f4273c7 2205
dcbf9037 2206 p += 5;
5f4273c7 2207
dcbf9037
JB
2208 if (*p == '\0')
2209 return 0;
5f4273c7 2210
dcbf9037
JB
2211 basereg = arm_reg_parse_multi (&p);
2212
2213 if (basereg && basereg->type != basetype)
2214 {
2215 as_bad (_("bad type for register"));
2216 return 0;
2217 }
2218
2219 if (basereg == NULL)
2220 {
2221 expressionS exp;
2222 /* Try parsing as an integer. */
2223 my_get_expression (&exp, &p, GE_NO_PREFIX);
2224 if (exp.X_op != O_constant)
2225 {
2226 as_bad (_("expression must be constant"));
2227 return 0;
2228 }
2229 basereg = &mybasereg;
2230 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2231 : exp.X_add_number;
2232 basereg->neon = 0;
2233 }
2234
2235 if (basereg->neon)
2236 typeinfo = *basereg->neon;
2237
2238 if (parse_neon_type (&ntype, &p) == SUCCESS)
2239 {
2240 /* We got a type. */
2241 if (typeinfo.defined & NTA_HASTYPE)
2242 {
2243 as_bad (_("can't redefine the type of a register alias"));
2244 return 0;
2245 }
5f4273c7 2246
dcbf9037
JB
2247 typeinfo.defined |= NTA_HASTYPE;
2248 if (ntype.elems != 1)
2249 {
2250 as_bad (_("you must specify a single type only"));
2251 return 0;
2252 }
2253 typeinfo.eltype = ntype.el[0];
2254 }
5f4273c7 2255
dcbf9037
JB
2256 if (skip_past_char (&p, '[') == SUCCESS)
2257 {
2258 expressionS exp;
2259 /* We got a scalar index. */
5f4273c7 2260
dcbf9037
JB
2261 if (typeinfo.defined & NTA_HASINDEX)
2262 {
2263 as_bad (_("can't redefine the index of a scalar alias"));
2264 return 0;
2265 }
5f4273c7 2266
dcbf9037 2267 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2268
dcbf9037
JB
2269 if (exp.X_op != O_constant)
2270 {
2271 as_bad (_("scalar index must be constant"));
2272 return 0;
2273 }
5f4273c7 2274
dcbf9037
JB
2275 typeinfo.defined |= NTA_HASINDEX;
2276 typeinfo.index = exp.X_add_number;
5f4273c7 2277
dcbf9037
JB
2278 if (skip_past_char (&p, ']') == FAIL)
2279 {
2280 as_bad (_("expecting ]"));
2281 return 0;
2282 }
2283 }
2284
2285 namelen = nameend - newname;
2286 namebuf = alloca (namelen + 1);
2287 strncpy (namebuf, newname, namelen);
2288 namebuf[namelen] = '\0';
5f4273c7 2289
dcbf9037
JB
2290 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2291 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2292
dcbf9037
JB
2293 /* Insert name in all uppercase. */
2294 for (p = namebuf; *p; p++)
2295 *p = TOUPPER (*p);
5f4273c7 2296
dcbf9037
JB
2297 if (strncmp (namebuf, newname, namelen))
2298 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2299 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2300
dcbf9037
JB
2301 /* Insert name in all lowercase. */
2302 for (p = namebuf; *p; p++)
2303 *p = TOLOWER (*p);
5f4273c7 2304
dcbf9037
JB
2305 if (strncmp (namebuf, newname, namelen))
2306 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2307 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2308
dcbf9037
JB
2309 return 1;
2310}
2311
c19d1205
ZW
2312/* Should never be called, as .req goes between the alias and the
2313 register name, not at the beginning of the line. */
b99bd4ef 2314static void
c19d1205 2315s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2316{
c19d1205
ZW
2317 as_bad (_("invalid syntax for .req directive"));
2318}
b99bd4ef 2319
dcbf9037
JB
2320static void
2321s_dn (int a ATTRIBUTE_UNUSED)
2322{
2323 as_bad (_("invalid syntax for .dn directive"));
2324}
2325
2326static void
2327s_qn (int a ATTRIBUTE_UNUSED)
2328{
2329 as_bad (_("invalid syntax for .qn directive"));
2330}
2331
c19d1205
ZW
2332/* The .unreq directive deletes an alias which was previously defined
2333 by .req. For example:
b99bd4ef 2334
c19d1205
ZW
2335 my_alias .req r11
2336 .unreq my_alias */
b99bd4ef
NC
2337
2338static void
c19d1205 2339s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2340{
c19d1205
ZW
2341 char * name;
2342 char saved_char;
b99bd4ef 2343
c19d1205
ZW
2344 name = input_line_pointer;
2345
2346 while (*input_line_pointer != 0
2347 && *input_line_pointer != ' '
2348 && *input_line_pointer != '\n')
2349 ++input_line_pointer;
2350
2351 saved_char = *input_line_pointer;
2352 *input_line_pointer = 0;
2353
2354 if (!*name)
2355 as_bad (_("invalid syntax for .unreq directive"));
2356 else
2357 {
2358 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2359
2360 if (!reg)
2361 as_bad (_("unknown register alias '%s'"), name);
2362 else if (reg->builtin)
2363 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2364 name);
2365 else
2366 {
d929913e
NC
2367 char * p;
2368 char * nbuf;
2369
db0bc284 2370 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2371 free ((char *) reg->name);
dcbf9037
JB
2372 if (reg->neon)
2373 free (reg->neon);
c19d1205 2374 free (reg);
d929913e
NC
2375
2376 /* Also locate the all upper case and all lower case versions.
2377 Do not complain if we cannot find one or the other as it
2378 was probably deleted above. */
5f4273c7 2379
d929913e
NC
2380 nbuf = strdup (name);
2381 for (p = nbuf; *p; p++)
2382 *p = TOUPPER (*p);
2383 reg = hash_find (arm_reg_hsh, nbuf);
2384 if (reg)
2385 {
db0bc284 2386 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2387 free ((char *) reg->name);
2388 if (reg->neon)
2389 free (reg->neon);
2390 free (reg);
2391 }
2392
2393 for (p = nbuf; *p; p++)
2394 *p = TOLOWER (*p);
2395 reg = hash_find (arm_reg_hsh, nbuf);
2396 if (reg)
2397 {
db0bc284 2398 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2399 free ((char *) reg->name);
2400 if (reg->neon)
2401 free (reg->neon);
2402 free (reg);
2403 }
2404
2405 free (nbuf);
c19d1205
ZW
2406 }
2407 }
b99bd4ef 2408
c19d1205 2409 *input_line_pointer = saved_char;
b99bd4ef
NC
2410 demand_empty_rest_of_line ();
2411}
2412
c19d1205
ZW
2413/* Directives: Instruction set selection. */
2414
2415#ifdef OBJ_ELF
2416/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2417 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2418 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2419 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2420
2421static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2422
e821645d 2423void
c19d1205 2424mapping_state (enum mstate state)
b99bd4ef 2425{
a737bd4d 2426 symbolS * symbolP;
c19d1205
ZW
2427 const char * symname;
2428 int type;
b99bd4ef 2429
c19d1205
ZW
2430 if (mapstate == state)
2431 /* The mapping symbol has already been emitted.
2432 There is nothing else to do. */
2433 return;
b99bd4ef 2434
c19d1205 2435 mapstate = state;
b99bd4ef 2436
c19d1205 2437 switch (state)
b99bd4ef 2438 {
c19d1205
ZW
2439 case MAP_DATA:
2440 symname = "$d";
2441 type = BSF_NO_FLAGS;
2442 break;
2443 case MAP_ARM:
2444 symname = "$a";
2445 type = BSF_NO_FLAGS;
2446 break;
2447 case MAP_THUMB:
2448 symname = "$t";
2449 type = BSF_NO_FLAGS;
2450 break;
2451 case MAP_UNDEFINED:
2452 return;
2453 default:
2454 abort ();
2455 }
2456
2457 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2458
2459 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2460 symbol_table_insert (symbolP);
2461 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2462
2463 switch (state)
2464 {
2465 case MAP_ARM:
2466 THUMB_SET_FUNC (symbolP, 0);
2467 ARM_SET_THUMB (symbolP, 0);
2468 ARM_SET_INTERWORK (symbolP, support_interwork);
2469 break;
2470
2471 case MAP_THUMB:
2472 THUMB_SET_FUNC (symbolP, 1);
2473 ARM_SET_THUMB (symbolP, 1);
2474 ARM_SET_INTERWORK (symbolP, support_interwork);
2475 break;
2476
2477 case MAP_DATA:
2478 default:
2479 return;
2480 }
2481}
2482#else
2483#define mapping_state(x) /* nothing */
2484#endif
2485
2486/* Find the real, Thumb encoded start of a Thumb function. */
2487
4343666d 2488#ifdef OBJ_COFF
c19d1205
ZW
2489static symbolS *
2490find_real_start (symbolS * symbolP)
2491{
2492 char * real_start;
2493 const char * name = S_GET_NAME (symbolP);
2494 symbolS * new_target;
2495
2496 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2497#define STUB_NAME ".real_start_of"
2498
2499 if (name == NULL)
2500 abort ();
2501
37f6032b
ZW
2502 /* The compiler may generate BL instructions to local labels because
2503 it needs to perform a branch to a far away location. These labels
2504 do not have a corresponding ".real_start_of" label. We check
2505 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2506 the ".real_start_of" convention for nonlocal branches. */
2507 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2508 return symbolP;
2509
37f6032b 2510 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2511 new_target = symbol_find (real_start);
2512
2513 if (new_target == NULL)
2514 {
bd3ba5d1 2515 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2516 new_target = symbolP;
2517 }
2518
c19d1205
ZW
2519 return new_target;
2520}
4343666d 2521#endif
c19d1205
ZW
2522
2523static void
2524opcode_select (int width)
2525{
2526 switch (width)
2527 {
2528 case 16:
2529 if (! thumb_mode)
2530 {
e74cfd16 2531 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2532 as_bad (_("selected processor does not support THUMB opcodes"));
2533
2534 thumb_mode = 1;
2535 /* No need to force the alignment, since we will have been
2536 coming from ARM mode, which is word-aligned. */
2537 record_alignment (now_seg, 1);
2538 }
2539 mapping_state (MAP_THUMB);
2540 break;
2541
2542 case 32:
2543 if (thumb_mode)
2544 {
e74cfd16 2545 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2546 as_bad (_("selected processor does not support ARM opcodes"));
2547
2548 thumb_mode = 0;
2549
2550 if (!need_pass_2)
2551 frag_align (2, 0, 0);
2552
2553 record_alignment (now_seg, 1);
2554 }
2555 mapping_state (MAP_ARM);
2556 break;
2557
2558 default:
2559 as_bad (_("invalid instruction size selected (%d)"), width);
2560 }
2561}
2562
2563static void
2564s_arm (int ignore ATTRIBUTE_UNUSED)
2565{
2566 opcode_select (32);
2567 demand_empty_rest_of_line ();
2568}
2569
2570static void
2571s_thumb (int ignore ATTRIBUTE_UNUSED)
2572{
2573 opcode_select (16);
2574 demand_empty_rest_of_line ();
2575}
2576
2577static void
2578s_code (int unused ATTRIBUTE_UNUSED)
2579{
2580 int temp;
2581
2582 temp = get_absolute_expression ();
2583 switch (temp)
2584 {
2585 case 16:
2586 case 32:
2587 opcode_select (temp);
2588 break;
2589
2590 default:
2591 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2592 }
2593}
2594
2595static void
2596s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2597{
2598 /* If we are not already in thumb mode go into it, EVEN if
2599 the target processor does not support thumb instructions.
2600 This is used by gcc/config/arm/lib1funcs.asm for example
2601 to compile interworking support functions even if the
2602 target processor should not support interworking. */
2603 if (! thumb_mode)
2604 {
2605 thumb_mode = 2;
2606 record_alignment (now_seg, 1);
2607 }
2608
2609 demand_empty_rest_of_line ();
2610}
2611
2612static void
2613s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2614{
2615 s_thumb (0);
2616
2617 /* The following label is the name/address of the start of a Thumb function.
2618 We need to know this for the interworking support. */
2619 label_is_thumb_function_name = TRUE;
2620}
2621
2622/* Perform a .set directive, but also mark the alias as
2623 being a thumb function. */
2624
2625static void
2626s_thumb_set (int equiv)
2627{
2628 /* XXX the following is a duplicate of the code for s_set() in read.c
2629 We cannot just call that code as we need to get at the symbol that
2630 is created. */
2631 char * name;
2632 char delim;
2633 char * end_name;
2634 symbolS * symbolP;
2635
2636 /* Especial apologies for the random logic:
2637 This just grew, and could be parsed much more simply!
2638 Dean - in haste. */
2639 name = input_line_pointer;
2640 delim = get_symbol_end ();
2641 end_name = input_line_pointer;
2642 *end_name = delim;
2643
2644 if (*input_line_pointer != ',')
2645 {
2646 *end_name = 0;
2647 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2648 *end_name = delim;
2649 ignore_rest_of_line ();
2650 return;
2651 }
2652
2653 input_line_pointer++;
2654 *end_name = 0;
2655
2656 if (name[0] == '.' && name[1] == '\0')
2657 {
2658 /* XXX - this should not happen to .thumb_set. */
2659 abort ();
2660 }
2661
2662 if ((symbolP = symbol_find (name)) == NULL
2663 && (symbolP = md_undefined_symbol (name)) == NULL)
2664 {
2665#ifndef NO_LISTING
2666 /* When doing symbol listings, play games with dummy fragments living
2667 outside the normal fragment chain to record the file and line info
c19d1205 2668 for this symbol. */
b99bd4ef
NC
2669 if (listing & LISTING_SYMBOLS)
2670 {
2671 extern struct list_info_struct * listing_tail;
a737bd4d 2672 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2673
2674 memset (dummy_frag, 0, sizeof (fragS));
2675 dummy_frag->fr_type = rs_fill;
2676 dummy_frag->line = listing_tail;
2677 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2678 dummy_frag->fr_symbol = symbolP;
2679 }
2680 else
2681#endif
2682 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2683
2684#ifdef OBJ_COFF
2685 /* "set" symbols are local unless otherwise specified. */
2686 SF_SET_LOCAL (symbolP);
2687#endif /* OBJ_COFF */
2688 } /* Make a new symbol. */
2689
2690 symbol_table_insert (symbolP);
2691
2692 * end_name = delim;
2693
2694 if (equiv
2695 && S_IS_DEFINED (symbolP)
2696 && S_GET_SEGMENT (symbolP) != reg_section)
2697 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2698
2699 pseudo_set (symbolP);
2700
2701 demand_empty_rest_of_line ();
2702
c19d1205 2703 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2704
2705 THUMB_SET_FUNC (symbolP, 1);
2706 ARM_SET_THUMB (symbolP, 1);
2707#if defined OBJ_ELF || defined OBJ_COFF
2708 ARM_SET_INTERWORK (symbolP, support_interwork);
2709#endif
2710}
2711
c19d1205 2712/* Directives: Mode selection. */
b99bd4ef 2713
c19d1205
ZW
2714/* .syntax [unified|divided] - choose the new unified syntax
2715 (same for Arm and Thumb encoding, modulo slight differences in what
2716 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2717static void
c19d1205 2718s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2719{
c19d1205
ZW
2720 char *name, delim;
2721
2722 name = input_line_pointer;
2723 delim = get_symbol_end ();
2724
2725 if (!strcasecmp (name, "unified"))
2726 unified_syntax = TRUE;
2727 else if (!strcasecmp (name, "divided"))
2728 unified_syntax = FALSE;
2729 else
2730 {
2731 as_bad (_("unrecognized syntax mode \"%s\""), name);
2732 return;
2733 }
2734 *input_line_pointer = delim;
b99bd4ef
NC
2735 demand_empty_rest_of_line ();
2736}
2737
c19d1205
ZW
2738/* Directives: sectioning and alignment. */
2739
2740/* Same as s_align_ptwo but align 0 => align 2. */
2741
b99bd4ef 2742static void
c19d1205 2743s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2744{
a737bd4d 2745 int temp;
dce323d1 2746 bfd_boolean fill_p;
c19d1205
ZW
2747 long temp_fill;
2748 long max_alignment = 15;
b99bd4ef
NC
2749
2750 temp = get_absolute_expression ();
c19d1205
ZW
2751 if (temp > max_alignment)
2752 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2753 else if (temp < 0)
b99bd4ef 2754 {
c19d1205
ZW
2755 as_bad (_("alignment negative. 0 assumed."));
2756 temp = 0;
2757 }
b99bd4ef 2758
c19d1205
ZW
2759 if (*input_line_pointer == ',')
2760 {
2761 input_line_pointer++;
2762 temp_fill = get_absolute_expression ();
dce323d1 2763 fill_p = TRUE;
b99bd4ef 2764 }
c19d1205 2765 else
dce323d1
PB
2766 {
2767 fill_p = FALSE;
2768 temp_fill = 0;
2769 }
b99bd4ef 2770
c19d1205
ZW
2771 if (!temp)
2772 temp = 2;
b99bd4ef 2773
c19d1205
ZW
2774 /* Only make a frag if we HAVE to. */
2775 if (temp && !need_pass_2)
dce323d1
PB
2776 {
2777 if (!fill_p && subseg_text_p (now_seg))
2778 frag_align_code (temp, 0);
2779 else
2780 frag_align (temp, (int) temp_fill, 0);
2781 }
c19d1205
ZW
2782 demand_empty_rest_of_line ();
2783
2784 record_alignment (now_seg, temp);
b99bd4ef
NC
2785}
2786
c19d1205
ZW
2787static void
2788s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2789{
c19d1205
ZW
2790 /* We don't support putting frags in the BSS segment, we fake it by
2791 marking in_bss, then looking at s_skip for clues. */
2792 subseg_set (bss_section, 0);
2793 demand_empty_rest_of_line ();
2794 mapping_state (MAP_DATA);
2795}
b99bd4ef 2796
c19d1205
ZW
2797static void
2798s_even (int ignore ATTRIBUTE_UNUSED)
2799{
2800 /* Never make frag if expect extra pass. */
2801 if (!need_pass_2)
2802 frag_align (1, 0, 0);
b99bd4ef 2803
c19d1205 2804 record_alignment (now_seg, 1);
b99bd4ef 2805
c19d1205 2806 demand_empty_rest_of_line ();
b99bd4ef
NC
2807}
2808
c19d1205 2809/* Directives: Literal pools. */
a737bd4d 2810
c19d1205
ZW
2811static literal_pool *
2812find_literal_pool (void)
a737bd4d 2813{
c19d1205 2814 literal_pool * pool;
a737bd4d 2815
c19d1205 2816 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2817 {
c19d1205
ZW
2818 if (pool->section == now_seg
2819 && pool->sub_section == now_subseg)
2820 break;
a737bd4d
NC
2821 }
2822
c19d1205 2823 return pool;
a737bd4d
NC
2824}
2825
c19d1205
ZW
2826static literal_pool *
2827find_or_make_literal_pool (void)
a737bd4d 2828{
c19d1205
ZW
2829 /* Next literal pool ID number. */
2830 static unsigned int latest_pool_num = 1;
2831 literal_pool * pool;
a737bd4d 2832
c19d1205 2833 pool = find_literal_pool ();
a737bd4d 2834
c19d1205 2835 if (pool == NULL)
a737bd4d 2836 {
c19d1205
ZW
2837 /* Create a new pool. */
2838 pool = xmalloc (sizeof (* pool));
2839 if (! pool)
2840 return NULL;
a737bd4d 2841
c19d1205
ZW
2842 pool->next_free_entry = 0;
2843 pool->section = now_seg;
2844 pool->sub_section = now_subseg;
2845 pool->next = list_of_pools;
2846 pool->symbol = NULL;
2847
2848 /* Add it to the list. */
2849 list_of_pools = pool;
a737bd4d 2850 }
a737bd4d 2851
c19d1205
ZW
2852 /* New pools, and emptied pools, will have a NULL symbol. */
2853 if (pool->symbol == NULL)
a737bd4d 2854 {
c19d1205
ZW
2855 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2856 (valueT) 0, &zero_address_frag);
2857 pool->id = latest_pool_num ++;
a737bd4d
NC
2858 }
2859
c19d1205
ZW
2860 /* Done. */
2861 return pool;
a737bd4d
NC
2862}
2863
c19d1205 2864/* Add the literal in the global 'inst'
5f4273c7 2865 structure to the relevant literal pool. */
b99bd4ef
NC
2866
2867static int
c19d1205 2868add_to_lit_pool (void)
b99bd4ef 2869{
c19d1205
ZW
2870 literal_pool * pool;
2871 unsigned int entry;
b99bd4ef 2872
c19d1205
ZW
2873 pool = find_or_make_literal_pool ();
2874
2875 /* Check if this literal value is already in the pool. */
2876 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2877 {
c19d1205
ZW
2878 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2879 && (inst.reloc.exp.X_op == O_constant)
2880 && (pool->literals[entry].X_add_number
2881 == inst.reloc.exp.X_add_number)
2882 && (pool->literals[entry].X_unsigned
2883 == inst.reloc.exp.X_unsigned))
2884 break;
2885
2886 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2887 && (inst.reloc.exp.X_op == O_symbol)
2888 && (pool->literals[entry].X_add_number
2889 == inst.reloc.exp.X_add_number)
2890 && (pool->literals[entry].X_add_symbol
2891 == inst.reloc.exp.X_add_symbol)
2892 && (pool->literals[entry].X_op_symbol
2893 == inst.reloc.exp.X_op_symbol))
2894 break;
b99bd4ef
NC
2895 }
2896
c19d1205
ZW
2897 /* Do we need to create a new entry? */
2898 if (entry == pool->next_free_entry)
2899 {
2900 if (entry >= MAX_LITERAL_POOL_SIZE)
2901 {
2902 inst.error = _("literal pool overflow");
2903 return FAIL;
2904 }
2905
2906 pool->literals[entry] = inst.reloc.exp;
2907 pool->next_free_entry += 1;
2908 }
b99bd4ef 2909
c19d1205
ZW
2910 inst.reloc.exp.X_op = O_symbol;
2911 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2912 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2913
c19d1205 2914 return SUCCESS;
b99bd4ef
NC
2915}
2916
c19d1205
ZW
2917/* Can't use symbol_new here, so have to create a symbol and then at
2918 a later date assign it a value. Thats what these functions do. */
e16bb312 2919
c19d1205
ZW
2920static void
2921symbol_locate (symbolS * symbolP,
2922 const char * name, /* It is copied, the caller can modify. */
2923 segT segment, /* Segment identifier (SEG_<something>). */
2924 valueT valu, /* Symbol value. */
2925 fragS * frag) /* Associated fragment. */
2926{
2927 unsigned int name_length;
2928 char * preserved_copy_of_name;
e16bb312 2929
c19d1205
ZW
2930 name_length = strlen (name) + 1; /* +1 for \0. */
2931 obstack_grow (&notes, name, name_length);
2932 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2933
c19d1205
ZW
2934#ifdef tc_canonicalize_symbol_name
2935 preserved_copy_of_name =
2936 tc_canonicalize_symbol_name (preserved_copy_of_name);
2937#endif
b99bd4ef 2938
c19d1205 2939 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2940
c19d1205
ZW
2941 S_SET_SEGMENT (symbolP, segment);
2942 S_SET_VALUE (symbolP, valu);
2943 symbol_clear_list_pointers (symbolP);
b99bd4ef 2944
c19d1205 2945 symbol_set_frag (symbolP, frag);
b99bd4ef 2946
c19d1205
ZW
2947 /* Link to end of symbol chain. */
2948 {
2949 extern int symbol_table_frozen;
b99bd4ef 2950
c19d1205
ZW
2951 if (symbol_table_frozen)
2952 abort ();
2953 }
b99bd4ef 2954
c19d1205 2955 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2956
c19d1205 2957 obj_symbol_new_hook (symbolP);
b99bd4ef 2958
c19d1205
ZW
2959#ifdef tc_symbol_new_hook
2960 tc_symbol_new_hook (symbolP);
2961#endif
2962
2963#ifdef DEBUG_SYMS
2964 verify_symbol_chain (symbol_rootP, symbol_lastP);
2965#endif /* DEBUG_SYMS */
b99bd4ef
NC
2966}
2967
b99bd4ef 2968
c19d1205
ZW
2969static void
2970s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2971{
c19d1205
ZW
2972 unsigned int entry;
2973 literal_pool * pool;
2974 char sym_name[20];
b99bd4ef 2975
c19d1205
ZW
2976 pool = find_literal_pool ();
2977 if (pool == NULL
2978 || pool->symbol == NULL
2979 || pool->next_free_entry == 0)
2980 return;
b99bd4ef 2981
c19d1205 2982 mapping_state (MAP_DATA);
b99bd4ef 2983
c19d1205
ZW
2984 /* Align pool as you have word accesses.
2985 Only make a frag if we have to. */
2986 if (!need_pass_2)
2987 frag_align (2, 0, 0);
b99bd4ef 2988
c19d1205 2989 record_alignment (now_seg, 2);
b99bd4ef 2990
c19d1205 2991 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2992
c19d1205
ZW
2993 symbol_locate (pool->symbol, sym_name, now_seg,
2994 (valueT) frag_now_fix (), frag_now);
2995 symbol_table_insert (pool->symbol);
b99bd4ef 2996
c19d1205 2997 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2998
c19d1205
ZW
2999#if defined OBJ_COFF || defined OBJ_ELF
3000 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3001#endif
6c43fab6 3002
c19d1205
ZW
3003 for (entry = 0; entry < pool->next_free_entry; entry ++)
3004 /* First output the expression in the instruction to the pool. */
3005 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3006
c19d1205
ZW
3007 /* Mark the pool as empty. */
3008 pool->next_free_entry = 0;
3009 pool->symbol = NULL;
b99bd4ef
NC
3010}
3011
c19d1205
ZW
3012#ifdef OBJ_ELF
3013/* Forward declarations for functions below, in the MD interface
3014 section. */
3015static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3016static valueT create_unwind_entry (int);
3017static void start_unwind_section (const segT, int);
3018static void add_unwind_opcode (valueT, int);
3019static void flush_pending_unwind (void);
b99bd4ef 3020
c19d1205 3021/* Directives: Data. */
b99bd4ef 3022
c19d1205
ZW
3023static void
3024s_arm_elf_cons (int nbytes)
3025{
3026 expressionS exp;
b99bd4ef 3027
c19d1205
ZW
3028#ifdef md_flush_pending_output
3029 md_flush_pending_output ();
3030#endif
b99bd4ef 3031
c19d1205 3032 if (is_it_end_of_statement ())
b99bd4ef 3033 {
c19d1205
ZW
3034 demand_empty_rest_of_line ();
3035 return;
b99bd4ef
NC
3036 }
3037
c19d1205
ZW
3038#ifdef md_cons_align
3039 md_cons_align (nbytes);
3040#endif
b99bd4ef 3041
c19d1205
ZW
3042 mapping_state (MAP_DATA);
3043 do
b99bd4ef 3044 {
c19d1205
ZW
3045 int reloc;
3046 char *base = input_line_pointer;
b99bd4ef 3047
c19d1205 3048 expression (& exp);
b99bd4ef 3049
c19d1205
ZW
3050 if (exp.X_op != O_symbol)
3051 emit_expr (&exp, (unsigned int) nbytes);
3052 else
3053 {
3054 char *before_reloc = input_line_pointer;
3055 reloc = parse_reloc (&input_line_pointer);
3056 if (reloc == -1)
3057 {
3058 as_bad (_("unrecognized relocation suffix"));
3059 ignore_rest_of_line ();
3060 return;
3061 }
3062 else if (reloc == BFD_RELOC_UNUSED)
3063 emit_expr (&exp, (unsigned int) nbytes);
3064 else
3065 {
3066 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
3067 int size = bfd_get_reloc_size (howto);
b99bd4ef 3068
2fc8bdac
ZW
3069 if (reloc == BFD_RELOC_ARM_PLT32)
3070 {
3071 as_bad (_("(plt) is only valid on branch targets"));
3072 reloc = BFD_RELOC_UNUSED;
3073 size = 0;
3074 }
3075
c19d1205 3076 if (size > nbytes)
2fc8bdac 3077 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3078 howto->name, nbytes);
3079 else
3080 {
3081 /* We've parsed an expression stopping at O_symbol.
3082 But there may be more expression left now that we
3083 have parsed the relocation marker. Parse it again.
3084 XXX Surely there is a cleaner way to do this. */
3085 char *p = input_line_pointer;
3086 int offset;
3087 char *save_buf = alloca (input_line_pointer - base);
3088 memcpy (save_buf, base, input_line_pointer - base);
3089 memmove (base + (input_line_pointer - before_reloc),
3090 base, before_reloc - base);
3091
3092 input_line_pointer = base + (input_line_pointer-before_reloc);
3093 expression (&exp);
3094 memcpy (base, save_buf, p - base);
3095
3096 offset = nbytes - size;
3097 p = frag_more ((int) nbytes);
3098 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3099 size, &exp, 0, reloc);
3100 }
3101 }
3102 }
b99bd4ef 3103 }
c19d1205 3104 while (*input_line_pointer++ == ',');
b99bd4ef 3105
c19d1205
ZW
3106 /* Put terminator back into stream. */
3107 input_line_pointer --;
3108 demand_empty_rest_of_line ();
b99bd4ef
NC
3109}
3110
b99bd4ef 3111
c19d1205 3112/* Parse a .rel31 directive. */
b99bd4ef 3113
c19d1205
ZW
3114static void
3115s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3116{
3117 expressionS exp;
3118 char *p;
3119 valueT highbit;
b99bd4ef 3120
c19d1205
ZW
3121 highbit = 0;
3122 if (*input_line_pointer == '1')
3123 highbit = 0x80000000;
3124 else if (*input_line_pointer != '0')
3125 as_bad (_("expected 0 or 1"));
b99bd4ef 3126
c19d1205
ZW
3127 input_line_pointer++;
3128 if (*input_line_pointer != ',')
3129 as_bad (_("missing comma"));
3130 input_line_pointer++;
b99bd4ef 3131
c19d1205
ZW
3132#ifdef md_flush_pending_output
3133 md_flush_pending_output ();
3134#endif
b99bd4ef 3135
c19d1205
ZW
3136#ifdef md_cons_align
3137 md_cons_align (4);
3138#endif
b99bd4ef 3139
c19d1205 3140 mapping_state (MAP_DATA);
b99bd4ef 3141
c19d1205 3142 expression (&exp);
b99bd4ef 3143
c19d1205
ZW
3144 p = frag_more (4);
3145 md_number_to_chars (p, highbit, 4);
3146 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3147 BFD_RELOC_ARM_PREL31);
b99bd4ef 3148
c19d1205 3149 demand_empty_rest_of_line ();
b99bd4ef
NC
3150}
3151
c19d1205 3152/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3153
c19d1205 3154/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3155
c19d1205
ZW
3156static void
3157s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3158{
3159 demand_empty_rest_of_line ();
921e5f0a
PB
3160 if (unwind.proc_start)
3161 {
3162 as_bad(_("duplicate .fnstart directive"));
3163 return;
3164 }
3165
c19d1205
ZW
3166 /* Mark the start of the function. */
3167 unwind.proc_start = expr_build_dot ();
b99bd4ef 3168
c19d1205
ZW
3169 /* Reset the rest of the unwind info. */
3170 unwind.opcode_count = 0;
3171 unwind.table_entry = NULL;
3172 unwind.personality_routine = NULL;
3173 unwind.personality_index = -1;
3174 unwind.frame_size = 0;
3175 unwind.fp_offset = 0;
fdfde340 3176 unwind.fp_reg = REG_SP;
c19d1205
ZW
3177 unwind.fp_used = 0;
3178 unwind.sp_restored = 0;
3179}
b99bd4ef 3180
b99bd4ef 3181
c19d1205
ZW
3182/* Parse a handlerdata directive. Creates the exception handling table entry
3183 for the function. */
b99bd4ef 3184
c19d1205
ZW
3185static void
3186s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3187{
3188 demand_empty_rest_of_line ();
921e5f0a
PB
3189 if (!unwind.proc_start)
3190 as_bad(MISSING_FNSTART);
3191
c19d1205 3192 if (unwind.table_entry)
6decc662 3193 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3194
c19d1205
ZW
3195 create_unwind_entry (1);
3196}
a737bd4d 3197
c19d1205 3198/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3199
c19d1205
ZW
3200static void
3201s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3202{
3203 long where;
3204 char *ptr;
3205 valueT val;
f02232aa 3206
c19d1205 3207 demand_empty_rest_of_line ();
f02232aa 3208
921e5f0a
PB
3209 if (!unwind.proc_start)
3210 {
3211 as_bad(_(".fnend directive without .fnstart"));
3212 return;
3213 }
3214
c19d1205
ZW
3215 /* Add eh table entry. */
3216 if (unwind.table_entry == NULL)
3217 val = create_unwind_entry (0);
3218 else
3219 val = 0;
f02232aa 3220
c19d1205
ZW
3221 /* Add index table entry. This is two words. */
3222 start_unwind_section (unwind.saved_seg, 1);
3223 frag_align (2, 0, 0);
3224 record_alignment (now_seg, 2);
b99bd4ef 3225
c19d1205
ZW
3226 ptr = frag_more (8);
3227 where = frag_now_fix () - 8;
f02232aa 3228
c19d1205
ZW
3229 /* Self relative offset of the function start. */
3230 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3231 BFD_RELOC_ARM_PREL31);
f02232aa 3232
c19d1205
ZW
3233 /* Indicate dependency on EHABI-defined personality routines to the
3234 linker, if it hasn't been done already. */
3235 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3236 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3237 {
5f4273c7
NC
3238 static const char *const name[] =
3239 {
3240 "__aeabi_unwind_cpp_pr0",
3241 "__aeabi_unwind_cpp_pr1",
3242 "__aeabi_unwind_cpp_pr2"
3243 };
c19d1205
ZW
3244 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3245 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3246 marked_pr_dependency |= 1 << unwind.personality_index;
3247 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3248 = marked_pr_dependency;
3249 }
f02232aa 3250
c19d1205
ZW
3251 if (val)
3252 /* Inline exception table entry. */
3253 md_number_to_chars (ptr + 4, val, 4);
3254 else
3255 /* Self relative offset of the table entry. */
3256 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3257 BFD_RELOC_ARM_PREL31);
f02232aa 3258
c19d1205
ZW
3259 /* Restore the original section. */
3260 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3261
3262 unwind.proc_start = NULL;
c19d1205 3263}
f02232aa 3264
f02232aa 3265
c19d1205 3266/* Parse an unwind_cantunwind directive. */
b99bd4ef 3267
c19d1205
ZW
3268static void
3269s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3270{
3271 demand_empty_rest_of_line ();
921e5f0a
PB
3272 if (!unwind.proc_start)
3273 as_bad(MISSING_FNSTART);
3274
c19d1205
ZW
3275 if (unwind.personality_routine || unwind.personality_index != -1)
3276 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3277
c19d1205
ZW
3278 unwind.personality_index = -2;
3279}
b99bd4ef 3280
b99bd4ef 3281
c19d1205 3282/* Parse a personalityindex directive. */
b99bd4ef 3283
c19d1205
ZW
3284static void
3285s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3286{
3287 expressionS exp;
b99bd4ef 3288
921e5f0a
PB
3289 if (!unwind.proc_start)
3290 as_bad(MISSING_FNSTART);
3291
c19d1205
ZW
3292 if (unwind.personality_routine || unwind.personality_index != -1)
3293 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3294
c19d1205 3295 expression (&exp);
b99bd4ef 3296
c19d1205
ZW
3297 if (exp.X_op != O_constant
3298 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3299 {
c19d1205
ZW
3300 as_bad (_("bad personality routine number"));
3301 ignore_rest_of_line ();
3302 return;
b99bd4ef
NC
3303 }
3304
c19d1205 3305 unwind.personality_index = exp.X_add_number;
b99bd4ef 3306
c19d1205
ZW
3307 demand_empty_rest_of_line ();
3308}
e16bb312 3309
e16bb312 3310
c19d1205 3311/* Parse a personality directive. */
e16bb312 3312
c19d1205
ZW
3313static void
3314s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3315{
3316 char *name, *p, c;
a737bd4d 3317
921e5f0a
PB
3318 if (!unwind.proc_start)
3319 as_bad(MISSING_FNSTART);
3320
c19d1205
ZW
3321 if (unwind.personality_routine || unwind.personality_index != -1)
3322 as_bad (_("duplicate .personality directive"));
a737bd4d 3323
c19d1205
ZW
3324 name = input_line_pointer;
3325 c = get_symbol_end ();
3326 p = input_line_pointer;
3327 unwind.personality_routine = symbol_find_or_make (name);
3328 *p = c;
3329 demand_empty_rest_of_line ();
3330}
e16bb312 3331
e16bb312 3332
c19d1205 3333/* Parse a directive saving core registers. */
e16bb312 3334
c19d1205
ZW
3335static void
3336s_arm_unwind_save_core (void)
e16bb312 3337{
c19d1205
ZW
3338 valueT op;
3339 long range;
3340 int n;
e16bb312 3341
c19d1205
ZW
3342 range = parse_reg_list (&input_line_pointer);
3343 if (range == FAIL)
e16bb312 3344 {
c19d1205
ZW
3345 as_bad (_("expected register list"));
3346 ignore_rest_of_line ();
3347 return;
3348 }
e16bb312 3349
c19d1205 3350 demand_empty_rest_of_line ();
e16bb312 3351
c19d1205
ZW
3352 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3353 into .unwind_save {..., sp...}. We aren't bothered about the value of
3354 ip because it is clobbered by calls. */
3355 if (unwind.sp_restored && unwind.fp_reg == 12
3356 && (range & 0x3000) == 0x1000)
3357 {
3358 unwind.opcode_count--;
3359 unwind.sp_restored = 0;
3360 range = (range | 0x2000) & ~0x1000;
3361 unwind.pending_offset = 0;
3362 }
e16bb312 3363
01ae4198
DJ
3364 /* Pop r4-r15. */
3365 if (range & 0xfff0)
c19d1205 3366 {
01ae4198
DJ
3367 /* See if we can use the short opcodes. These pop a block of up to 8
3368 registers starting with r4, plus maybe r14. */
3369 for (n = 0; n < 8; n++)
3370 {
3371 /* Break at the first non-saved register. */
3372 if ((range & (1 << (n + 4))) == 0)
3373 break;
3374 }
3375 /* See if there are any other bits set. */
3376 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3377 {
3378 /* Use the long form. */
3379 op = 0x8000 | ((range >> 4) & 0xfff);
3380 add_unwind_opcode (op, 2);
3381 }
0dd132b6 3382 else
01ae4198
DJ
3383 {
3384 /* Use the short form. */
3385 if (range & 0x4000)
3386 op = 0xa8; /* Pop r14. */
3387 else
3388 op = 0xa0; /* Do not pop r14. */
3389 op |= (n - 1);
3390 add_unwind_opcode (op, 1);
3391 }
c19d1205 3392 }
0dd132b6 3393
c19d1205
ZW
3394 /* Pop r0-r3. */
3395 if (range & 0xf)
3396 {
3397 op = 0xb100 | (range & 0xf);
3398 add_unwind_opcode (op, 2);
0dd132b6
NC
3399 }
3400
c19d1205
ZW
3401 /* Record the number of bytes pushed. */
3402 for (n = 0; n < 16; n++)
3403 {
3404 if (range & (1 << n))
3405 unwind.frame_size += 4;
3406 }
0dd132b6
NC
3407}
3408
c19d1205
ZW
3409
3410/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3411
3412static void
c19d1205 3413s_arm_unwind_save_fpa (int reg)
b99bd4ef 3414{
c19d1205
ZW
3415 expressionS exp;
3416 int num_regs;
3417 valueT op;
b99bd4ef 3418
c19d1205
ZW
3419 /* Get Number of registers to transfer. */
3420 if (skip_past_comma (&input_line_pointer) != FAIL)
3421 expression (&exp);
3422 else
3423 exp.X_op = O_illegal;
b99bd4ef 3424
c19d1205 3425 if (exp.X_op != O_constant)
b99bd4ef 3426 {
c19d1205
ZW
3427 as_bad (_("expected , <constant>"));
3428 ignore_rest_of_line ();
b99bd4ef
NC
3429 return;
3430 }
3431
c19d1205
ZW
3432 num_regs = exp.X_add_number;
3433
3434 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3435 {
c19d1205
ZW
3436 as_bad (_("number of registers must be in the range [1:4]"));
3437 ignore_rest_of_line ();
b99bd4ef
NC
3438 return;
3439 }
3440
c19d1205 3441 demand_empty_rest_of_line ();
b99bd4ef 3442
c19d1205
ZW
3443 if (reg == 4)
3444 {
3445 /* Short form. */
3446 op = 0xb4 | (num_regs - 1);
3447 add_unwind_opcode (op, 1);
3448 }
b99bd4ef
NC
3449 else
3450 {
c19d1205
ZW
3451 /* Long form. */
3452 op = 0xc800 | (reg << 4) | (num_regs - 1);
3453 add_unwind_opcode (op, 2);
b99bd4ef 3454 }
c19d1205 3455 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3456}
3457
c19d1205 3458
fa073d69
MS
3459/* Parse a directive saving VFP registers for ARMv6 and above. */
3460
3461static void
3462s_arm_unwind_save_vfp_armv6 (void)
3463{
3464 int count;
3465 unsigned int start;
3466 valueT op;
3467 int num_vfpv3_regs = 0;
3468 int num_regs_below_16;
3469
3470 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3471 if (count == FAIL)
3472 {
3473 as_bad (_("expected register list"));
3474 ignore_rest_of_line ();
3475 return;
3476 }
3477
3478 demand_empty_rest_of_line ();
3479
3480 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3481 than FSTMX/FLDMX-style ones). */
3482
3483 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3484 if (start >= 16)
3485 num_vfpv3_regs = count;
3486 else if (start + count > 16)
3487 num_vfpv3_regs = start + count - 16;
3488
3489 if (num_vfpv3_regs > 0)
3490 {
3491 int start_offset = start > 16 ? start - 16 : 0;
3492 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3493 add_unwind_opcode (op, 2);
3494 }
3495
3496 /* Generate opcode for registers numbered in the range 0 .. 15. */
3497 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3498 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3499 if (num_regs_below_16 > 0)
3500 {
3501 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3502 add_unwind_opcode (op, 2);
3503 }
3504
3505 unwind.frame_size += count * 8;
3506}
3507
3508
3509/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3510
3511static void
c19d1205 3512s_arm_unwind_save_vfp (void)
b99bd4ef 3513{
c19d1205 3514 int count;
ca3f61f7 3515 unsigned int reg;
c19d1205 3516 valueT op;
b99bd4ef 3517
5287ad62 3518 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3519 if (count == FAIL)
b99bd4ef 3520 {
c19d1205
ZW
3521 as_bad (_("expected register list"));
3522 ignore_rest_of_line ();
b99bd4ef
NC
3523 return;
3524 }
3525
c19d1205 3526 demand_empty_rest_of_line ();
b99bd4ef 3527
c19d1205 3528 if (reg == 8)
b99bd4ef 3529 {
c19d1205
ZW
3530 /* Short form. */
3531 op = 0xb8 | (count - 1);
3532 add_unwind_opcode (op, 1);
b99bd4ef 3533 }
c19d1205 3534 else
b99bd4ef 3535 {
c19d1205
ZW
3536 /* Long form. */
3537 op = 0xb300 | (reg << 4) | (count - 1);
3538 add_unwind_opcode (op, 2);
b99bd4ef 3539 }
c19d1205
ZW
3540 unwind.frame_size += count * 8 + 4;
3541}
b99bd4ef 3542
b99bd4ef 3543
c19d1205
ZW
3544/* Parse a directive saving iWMMXt data registers. */
3545
3546static void
3547s_arm_unwind_save_mmxwr (void)
3548{
3549 int reg;
3550 int hi_reg;
3551 int i;
3552 unsigned mask = 0;
3553 valueT op;
b99bd4ef 3554
c19d1205
ZW
3555 if (*input_line_pointer == '{')
3556 input_line_pointer++;
b99bd4ef 3557
c19d1205 3558 do
b99bd4ef 3559 {
dcbf9037 3560 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3561
c19d1205 3562 if (reg == FAIL)
b99bd4ef 3563 {
9b7132d3 3564 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3565 goto error;
b99bd4ef
NC
3566 }
3567
c19d1205
ZW
3568 if (mask >> reg)
3569 as_tsktsk (_("register list not in ascending order"));
3570 mask |= 1 << reg;
b99bd4ef 3571
c19d1205
ZW
3572 if (*input_line_pointer == '-')
3573 {
3574 input_line_pointer++;
dcbf9037 3575 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3576 if (hi_reg == FAIL)
3577 {
9b7132d3 3578 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3579 goto error;
3580 }
3581 else if (reg >= hi_reg)
3582 {
3583 as_bad (_("bad register range"));
3584 goto error;
3585 }
3586 for (; reg < hi_reg; reg++)
3587 mask |= 1 << reg;
3588 }
3589 }
3590 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3591
c19d1205
ZW
3592 if (*input_line_pointer == '}')
3593 input_line_pointer++;
b99bd4ef 3594
c19d1205 3595 demand_empty_rest_of_line ();
b99bd4ef 3596
708587a4 3597 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3598 the list. */
3599 flush_pending_unwind ();
b99bd4ef 3600
c19d1205 3601 for (i = 0; i < 16; i++)
b99bd4ef 3602 {
c19d1205
ZW
3603 if (mask & (1 << i))
3604 unwind.frame_size += 8;
b99bd4ef
NC
3605 }
3606
c19d1205
ZW
3607 /* Attempt to combine with a previous opcode. We do this because gcc
3608 likes to output separate unwind directives for a single block of
3609 registers. */
3610 if (unwind.opcode_count > 0)
b99bd4ef 3611 {
c19d1205
ZW
3612 i = unwind.opcodes[unwind.opcode_count - 1];
3613 if ((i & 0xf8) == 0xc0)
3614 {
3615 i &= 7;
3616 /* Only merge if the blocks are contiguous. */
3617 if (i < 6)
3618 {
3619 if ((mask & 0xfe00) == (1 << 9))
3620 {
3621 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3622 unwind.opcode_count--;
3623 }
3624 }
3625 else if (i == 6 && unwind.opcode_count >= 2)
3626 {
3627 i = unwind.opcodes[unwind.opcode_count - 2];
3628 reg = i >> 4;
3629 i &= 0xf;
b99bd4ef 3630
c19d1205
ZW
3631 op = 0xffff << (reg - 1);
3632 if (reg > 0
87a1fd79 3633 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3634 {
3635 op = (1 << (reg + i + 1)) - 1;
3636 op &= ~((1 << reg) - 1);
3637 mask |= op;
3638 unwind.opcode_count -= 2;
3639 }
3640 }
3641 }
b99bd4ef
NC
3642 }
3643
c19d1205
ZW
3644 hi_reg = 15;
3645 /* We want to generate opcodes in the order the registers have been
3646 saved, ie. descending order. */
3647 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3648 {
c19d1205
ZW
3649 /* Save registers in blocks. */
3650 if (reg < 0
3651 || !(mask & (1 << reg)))
3652 {
3653 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3654 preceding block. */
c19d1205
ZW
3655 if (reg != hi_reg)
3656 {
3657 if (reg == 9)
3658 {
3659 /* Short form. */
3660 op = 0xc0 | (hi_reg - 10);
3661 add_unwind_opcode (op, 1);
3662 }
3663 else
3664 {
3665 /* Long form. */
3666 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3667 add_unwind_opcode (op, 2);
3668 }
3669 }
3670 hi_reg = reg - 1;
3671 }
b99bd4ef
NC
3672 }
3673
c19d1205
ZW
3674 return;
3675error:
3676 ignore_rest_of_line ();
b99bd4ef
NC
3677}
3678
3679static void
c19d1205 3680s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3681{
c19d1205
ZW
3682 int reg;
3683 int hi_reg;
3684 unsigned mask = 0;
3685 valueT op;
b99bd4ef 3686
c19d1205
ZW
3687 if (*input_line_pointer == '{')
3688 input_line_pointer++;
b99bd4ef 3689
c19d1205 3690 do
b99bd4ef 3691 {
dcbf9037 3692 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3693
c19d1205
ZW
3694 if (reg == FAIL)
3695 {
9b7132d3 3696 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3697 goto error;
3698 }
b99bd4ef 3699
c19d1205
ZW
3700 reg -= 8;
3701 if (mask >> reg)
3702 as_tsktsk (_("register list not in ascending order"));
3703 mask |= 1 << reg;
b99bd4ef 3704
c19d1205
ZW
3705 if (*input_line_pointer == '-')
3706 {
3707 input_line_pointer++;
dcbf9037 3708 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3709 if (hi_reg == FAIL)
3710 {
9b7132d3 3711 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3712 goto error;
3713 }
3714 else if (reg >= hi_reg)
3715 {
3716 as_bad (_("bad register range"));
3717 goto error;
3718 }
3719 for (; reg < hi_reg; reg++)
3720 mask |= 1 << reg;
3721 }
b99bd4ef 3722 }
c19d1205 3723 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3724
c19d1205
ZW
3725 if (*input_line_pointer == '}')
3726 input_line_pointer++;
b99bd4ef 3727
c19d1205
ZW
3728 demand_empty_rest_of_line ();
3729
708587a4 3730 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3731 the list. */
3732 flush_pending_unwind ();
b99bd4ef 3733
c19d1205 3734 for (reg = 0; reg < 16; reg++)
b99bd4ef 3735 {
c19d1205
ZW
3736 if (mask & (1 << reg))
3737 unwind.frame_size += 4;
b99bd4ef 3738 }
c19d1205
ZW
3739 op = 0xc700 | mask;
3740 add_unwind_opcode (op, 2);
3741 return;
3742error:
3743 ignore_rest_of_line ();
b99bd4ef
NC
3744}
3745
c19d1205 3746
fa073d69
MS
3747/* Parse an unwind_save directive.
3748 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3749
b99bd4ef 3750static void
fa073d69 3751s_arm_unwind_save (int arch_v6)
b99bd4ef 3752{
c19d1205
ZW
3753 char *peek;
3754 struct reg_entry *reg;
3755 bfd_boolean had_brace = FALSE;
b99bd4ef 3756
921e5f0a
PB
3757 if (!unwind.proc_start)
3758 as_bad(MISSING_FNSTART);
3759
c19d1205
ZW
3760 /* Figure out what sort of save we have. */
3761 peek = input_line_pointer;
b99bd4ef 3762
c19d1205 3763 if (*peek == '{')
b99bd4ef 3764 {
c19d1205
ZW
3765 had_brace = TRUE;
3766 peek++;
b99bd4ef
NC
3767 }
3768
c19d1205 3769 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3770
c19d1205 3771 if (!reg)
b99bd4ef 3772 {
c19d1205
ZW
3773 as_bad (_("register expected"));
3774 ignore_rest_of_line ();
b99bd4ef
NC
3775 return;
3776 }
3777
c19d1205 3778 switch (reg->type)
b99bd4ef 3779 {
c19d1205
ZW
3780 case REG_TYPE_FN:
3781 if (had_brace)
3782 {
3783 as_bad (_("FPA .unwind_save does not take a register list"));
3784 ignore_rest_of_line ();
3785 return;
3786 }
93ac2687 3787 input_line_pointer = peek;
c19d1205 3788 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3789 return;
c19d1205
ZW
3790
3791 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3792 case REG_TYPE_VFD:
3793 if (arch_v6)
3794 s_arm_unwind_save_vfp_armv6 ();
3795 else
3796 s_arm_unwind_save_vfp ();
3797 return;
c19d1205
ZW
3798 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3799 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3800
3801 default:
3802 as_bad (_(".unwind_save does not support this kind of register"));
3803 ignore_rest_of_line ();
b99bd4ef 3804 }
c19d1205 3805}
b99bd4ef 3806
b99bd4ef 3807
c19d1205
ZW
3808/* Parse an unwind_movsp directive. */
3809
3810static void
3811s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3812{
3813 int reg;
3814 valueT op;
4fa3602b 3815 int offset;
c19d1205 3816
921e5f0a
PB
3817 if (!unwind.proc_start)
3818 as_bad(MISSING_FNSTART);
3819
dcbf9037 3820 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3821 if (reg == FAIL)
b99bd4ef 3822 {
9b7132d3 3823 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 3824 ignore_rest_of_line ();
b99bd4ef
NC
3825 return;
3826 }
4fa3602b
PB
3827
3828 /* Optional constant. */
3829 if (skip_past_comma (&input_line_pointer) != FAIL)
3830 {
3831 if (immediate_for_directive (&offset) == FAIL)
3832 return;
3833 }
3834 else
3835 offset = 0;
3836
c19d1205 3837 demand_empty_rest_of_line ();
b99bd4ef 3838
c19d1205 3839 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3840 {
c19d1205 3841 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3842 return;
3843 }
3844
c19d1205
ZW
3845 if (unwind.fp_reg != REG_SP)
3846 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3847
c19d1205
ZW
3848 /* Generate opcode to restore the value. */
3849 op = 0x90 | reg;
3850 add_unwind_opcode (op, 1);
3851
3852 /* Record the information for later. */
3853 unwind.fp_reg = reg;
4fa3602b 3854 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3855 unwind.sp_restored = 1;
b05fe5cf
ZW
3856}
3857
c19d1205
ZW
3858/* Parse an unwind_pad directive. */
3859
b05fe5cf 3860static void
c19d1205 3861s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3862{
c19d1205 3863 int offset;
b05fe5cf 3864
921e5f0a
PB
3865 if (!unwind.proc_start)
3866 as_bad(MISSING_FNSTART);
3867
c19d1205
ZW
3868 if (immediate_for_directive (&offset) == FAIL)
3869 return;
b99bd4ef 3870
c19d1205
ZW
3871 if (offset & 3)
3872 {
3873 as_bad (_("stack increment must be multiple of 4"));
3874 ignore_rest_of_line ();
3875 return;
3876 }
b99bd4ef 3877
c19d1205
ZW
3878 /* Don't generate any opcodes, just record the details for later. */
3879 unwind.frame_size += offset;
3880 unwind.pending_offset += offset;
3881
3882 demand_empty_rest_of_line ();
3883}
3884
3885/* Parse an unwind_setfp directive. */
3886
3887static void
3888s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3889{
c19d1205
ZW
3890 int sp_reg;
3891 int fp_reg;
3892 int offset;
3893
921e5f0a
PB
3894 if (!unwind.proc_start)
3895 as_bad(MISSING_FNSTART);
3896
dcbf9037 3897 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3898 if (skip_past_comma (&input_line_pointer) == FAIL)
3899 sp_reg = FAIL;
3900 else
dcbf9037 3901 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3902
c19d1205
ZW
3903 if (fp_reg == FAIL || sp_reg == FAIL)
3904 {
3905 as_bad (_("expected <reg>, <reg>"));
3906 ignore_rest_of_line ();
3907 return;
3908 }
b99bd4ef 3909
c19d1205
ZW
3910 /* Optional constant. */
3911 if (skip_past_comma (&input_line_pointer) != FAIL)
3912 {
3913 if (immediate_for_directive (&offset) == FAIL)
3914 return;
3915 }
3916 else
3917 offset = 0;
a737bd4d 3918
c19d1205 3919 demand_empty_rest_of_line ();
a737bd4d 3920
fdfde340 3921 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 3922 {
c19d1205
ZW
3923 as_bad (_("register must be either sp or set by a previous"
3924 "unwind_movsp directive"));
3925 return;
a737bd4d
NC
3926 }
3927
c19d1205
ZW
3928 /* Don't generate any opcodes, just record the information for later. */
3929 unwind.fp_reg = fp_reg;
3930 unwind.fp_used = 1;
fdfde340 3931 if (sp_reg == REG_SP)
c19d1205
ZW
3932 unwind.fp_offset = unwind.frame_size - offset;
3933 else
3934 unwind.fp_offset -= offset;
a737bd4d
NC
3935}
3936
c19d1205
ZW
3937/* Parse an unwind_raw directive. */
3938
3939static void
3940s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3941{
c19d1205 3942 expressionS exp;
708587a4 3943 /* This is an arbitrary limit. */
c19d1205
ZW
3944 unsigned char op[16];
3945 int count;
a737bd4d 3946
921e5f0a
PB
3947 if (!unwind.proc_start)
3948 as_bad(MISSING_FNSTART);
3949
c19d1205
ZW
3950 expression (&exp);
3951 if (exp.X_op == O_constant
3952 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3953 {
c19d1205
ZW
3954 unwind.frame_size += exp.X_add_number;
3955 expression (&exp);
3956 }
3957 else
3958 exp.X_op = O_illegal;
a737bd4d 3959
c19d1205
ZW
3960 if (exp.X_op != O_constant)
3961 {
3962 as_bad (_("expected <offset>, <opcode>"));
3963 ignore_rest_of_line ();
3964 return;
3965 }
a737bd4d 3966
c19d1205 3967 count = 0;
a737bd4d 3968
c19d1205
ZW
3969 /* Parse the opcode. */
3970 for (;;)
3971 {
3972 if (count >= 16)
3973 {
3974 as_bad (_("unwind opcode too long"));
3975 ignore_rest_of_line ();
a737bd4d 3976 }
c19d1205 3977 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3978 {
c19d1205
ZW
3979 as_bad (_("invalid unwind opcode"));
3980 ignore_rest_of_line ();
3981 return;
a737bd4d 3982 }
c19d1205 3983 op[count++] = exp.X_add_number;
a737bd4d 3984
c19d1205
ZW
3985 /* Parse the next byte. */
3986 if (skip_past_comma (&input_line_pointer) == FAIL)
3987 break;
a737bd4d 3988
c19d1205
ZW
3989 expression (&exp);
3990 }
b99bd4ef 3991
c19d1205
ZW
3992 /* Add the opcode bytes in reverse order. */
3993 while (count--)
3994 add_unwind_opcode (op[count], 1);
b99bd4ef 3995
c19d1205 3996 demand_empty_rest_of_line ();
b99bd4ef 3997}
ee065d83
PB
3998
3999
4000/* Parse a .eabi_attribute directive. */
4001
4002static void
4003s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4004{
ee3c0378
AS
4005 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4006
4007 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4008 attributes_set_explicitly[tag] = 1;
ee065d83 4009}
8463be01 4010#endif /* OBJ_ELF */
ee065d83
PB
4011
4012static void s_arm_arch (int);
7a1d4c38 4013static void s_arm_object_arch (int);
ee065d83
PB
4014static void s_arm_cpu (int);
4015static void s_arm_fpu (int);
b99bd4ef 4016
f0927246
NC
4017#ifdef TE_PE
4018
4019static void
5f4273c7 4020pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4021{
4022 expressionS exp;
4023
4024 do
4025 {
4026 expression (&exp);
4027 if (exp.X_op == O_symbol)
4028 exp.X_op = O_secrel;
4029
4030 emit_expr (&exp, 4);
4031 }
4032 while (*input_line_pointer++ == ',');
4033
4034 input_line_pointer--;
4035 demand_empty_rest_of_line ();
4036}
4037#endif /* TE_PE */
4038
c19d1205
ZW
4039/* This table describes all the machine specific pseudo-ops the assembler
4040 has to support. The fields are:
4041 pseudo-op name without dot
4042 function to call to execute this pseudo-op
4043 Integer arg to pass to the function. */
b99bd4ef 4044
c19d1205 4045const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4046{
c19d1205
ZW
4047 /* Never called because '.req' does not start a line. */
4048 { "req", s_req, 0 },
dcbf9037
JB
4049 /* Following two are likewise never called. */
4050 { "dn", s_dn, 0 },
4051 { "qn", s_qn, 0 },
c19d1205
ZW
4052 { "unreq", s_unreq, 0 },
4053 { "bss", s_bss, 0 },
4054 { "align", s_align, 0 },
4055 { "arm", s_arm, 0 },
4056 { "thumb", s_thumb, 0 },
4057 { "code", s_code, 0 },
4058 { "force_thumb", s_force_thumb, 0 },
4059 { "thumb_func", s_thumb_func, 0 },
4060 { "thumb_set", s_thumb_set, 0 },
4061 { "even", s_even, 0 },
4062 { "ltorg", s_ltorg, 0 },
4063 { "pool", s_ltorg, 0 },
4064 { "syntax", s_syntax, 0 },
8463be01
PB
4065 { "cpu", s_arm_cpu, 0 },
4066 { "arch", s_arm_arch, 0 },
7a1d4c38 4067 { "object_arch", s_arm_object_arch, 0 },
8463be01 4068 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
4069#ifdef OBJ_ELF
4070 { "word", s_arm_elf_cons, 4 },
4071 { "long", s_arm_elf_cons, 4 },
4072 { "rel31", s_arm_rel31, 0 },
4073 { "fnstart", s_arm_unwind_fnstart, 0 },
4074 { "fnend", s_arm_unwind_fnend, 0 },
4075 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4076 { "personality", s_arm_unwind_personality, 0 },
4077 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4078 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4079 { "save", s_arm_unwind_save, 0 },
fa073d69 4080 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4081 { "movsp", s_arm_unwind_movsp, 0 },
4082 { "pad", s_arm_unwind_pad, 0 },
4083 { "setfp", s_arm_unwind_setfp, 0 },
4084 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4085 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4086#else
4087 { "word", cons, 4},
f0927246
NC
4088
4089 /* These are used for dwarf. */
4090 {"2byte", cons, 2},
4091 {"4byte", cons, 4},
4092 {"8byte", cons, 8},
4093 /* These are used for dwarf2. */
4094 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4095 { "loc", dwarf2_directive_loc, 0 },
4096 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4097#endif
4098 { "extend", float_cons, 'x' },
4099 { "ldouble", float_cons, 'x' },
4100 { "packed", float_cons, 'p' },
f0927246
NC
4101#ifdef TE_PE
4102 {"secrel32", pe_directive_secrel, 0},
4103#endif
c19d1205
ZW
4104 { 0, 0, 0 }
4105};
4106\f
4107/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4108
c19d1205
ZW
4109/* Generic immediate-value read function for use in insn parsing.
4110 STR points to the beginning of the immediate (the leading #);
4111 VAL receives the value; if the value is outside [MIN, MAX]
4112 issue an error. PREFIX_OPT is true if the immediate prefix is
4113 optional. */
b99bd4ef 4114
c19d1205
ZW
4115static int
4116parse_immediate (char **str, int *val, int min, int max,
4117 bfd_boolean prefix_opt)
4118{
4119 expressionS exp;
4120 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4121 if (exp.X_op != O_constant)
b99bd4ef 4122 {
c19d1205
ZW
4123 inst.error = _("constant expression required");
4124 return FAIL;
4125 }
b99bd4ef 4126
c19d1205
ZW
4127 if (exp.X_add_number < min || exp.X_add_number > max)
4128 {
4129 inst.error = _("immediate value out of range");
4130 return FAIL;
4131 }
b99bd4ef 4132
c19d1205
ZW
4133 *val = exp.X_add_number;
4134 return SUCCESS;
4135}
b99bd4ef 4136
5287ad62 4137/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4138 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4139 instructions. Puts the result directly in inst.operands[i]. */
4140
4141static int
4142parse_big_immediate (char **str, int i)
4143{
4144 expressionS exp;
4145 char *ptr = *str;
4146
4147 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4148
4149 if (exp.X_op == O_constant)
036dc3f7
PB
4150 {
4151 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4152 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4153 O_constant. We have to be careful not to break compilation for
4154 32-bit X_add_number, though. */
4155 if ((exp.X_add_number & ~0xffffffffl) != 0)
4156 {
4157 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4158 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4159 inst.operands[i].regisimm = 1;
4160 }
4161 }
5287ad62
JB
4162 else if (exp.X_op == O_big
4163 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4164 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4165 {
4166 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4167 /* Bignums have their least significant bits in
4168 generic_bignum[0]. Make sure we put 32 bits in imm and
4169 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4170 gas_assert (parts != 0);
5287ad62
JB
4171 inst.operands[i].imm = 0;
4172 for (j = 0; j < parts; j++, idx++)
4173 inst.operands[i].imm |= generic_bignum[idx]
4174 << (LITTLENUM_NUMBER_OF_BITS * j);
4175 inst.operands[i].reg = 0;
4176 for (j = 0; j < parts; j++, idx++)
4177 inst.operands[i].reg |= generic_bignum[idx]
4178 << (LITTLENUM_NUMBER_OF_BITS * j);
4179 inst.operands[i].regisimm = 1;
4180 }
4181 else
4182 return FAIL;
5f4273c7 4183
5287ad62
JB
4184 *str = ptr;
4185
4186 return SUCCESS;
4187}
4188
c19d1205
ZW
4189/* Returns the pseudo-register number of an FPA immediate constant,
4190 or FAIL if there isn't a valid constant here. */
b99bd4ef 4191
c19d1205
ZW
4192static int
4193parse_fpa_immediate (char ** str)
4194{
4195 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4196 char * save_in;
4197 expressionS exp;
4198 int i;
4199 int j;
b99bd4ef 4200
c19d1205
ZW
4201 /* First try and match exact strings, this is to guarantee
4202 that some formats will work even for cross assembly. */
b99bd4ef 4203
c19d1205
ZW
4204 for (i = 0; fp_const[i]; i++)
4205 {
4206 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4207 {
c19d1205 4208 char *start = *str;
b99bd4ef 4209
c19d1205
ZW
4210 *str += strlen (fp_const[i]);
4211 if (is_end_of_line[(unsigned char) **str])
4212 return i + 8;
4213 *str = start;
4214 }
4215 }
b99bd4ef 4216
c19d1205
ZW
4217 /* Just because we didn't get a match doesn't mean that the constant
4218 isn't valid, just that it is in a format that we don't
4219 automatically recognize. Try parsing it with the standard
4220 expression routines. */
b99bd4ef 4221
c19d1205 4222 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4223
c19d1205
ZW
4224 /* Look for a raw floating point number. */
4225 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4226 && is_end_of_line[(unsigned char) *save_in])
4227 {
4228 for (i = 0; i < NUM_FLOAT_VALS; i++)
4229 {
4230 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4231 {
c19d1205
ZW
4232 if (words[j] != fp_values[i][j])
4233 break;
b99bd4ef
NC
4234 }
4235
c19d1205 4236 if (j == MAX_LITTLENUMS)
b99bd4ef 4237 {
c19d1205
ZW
4238 *str = save_in;
4239 return i + 8;
b99bd4ef
NC
4240 }
4241 }
4242 }
b99bd4ef 4243
c19d1205
ZW
4244 /* Try and parse a more complex expression, this will probably fail
4245 unless the code uses a floating point prefix (eg "0f"). */
4246 save_in = input_line_pointer;
4247 input_line_pointer = *str;
4248 if (expression (&exp) == absolute_section
4249 && exp.X_op == O_big
4250 && exp.X_add_number < 0)
4251 {
4252 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4253 Ditto for 15. */
4254 if (gen_to_words (words, 5, (long) 15) == 0)
4255 {
4256 for (i = 0; i < NUM_FLOAT_VALS; i++)
4257 {
4258 for (j = 0; j < MAX_LITTLENUMS; j++)
4259 {
4260 if (words[j] != fp_values[i][j])
4261 break;
4262 }
b99bd4ef 4263
c19d1205
ZW
4264 if (j == MAX_LITTLENUMS)
4265 {
4266 *str = input_line_pointer;
4267 input_line_pointer = save_in;
4268 return i + 8;
4269 }
4270 }
4271 }
b99bd4ef
NC
4272 }
4273
c19d1205
ZW
4274 *str = input_line_pointer;
4275 input_line_pointer = save_in;
4276 inst.error = _("invalid FPA immediate expression");
4277 return FAIL;
b99bd4ef
NC
4278}
4279
136da414
JB
4280/* Returns 1 if a number has "quarter-precision" float format
4281 0baBbbbbbc defgh000 00000000 00000000. */
4282
4283static int
4284is_quarter_float (unsigned imm)
4285{
4286 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4287 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4288}
4289
4290/* Parse an 8-bit "quarter-precision" floating point number of the form:
4291 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4292 The zero and minus-zero cases need special handling, since they can't be
4293 encoded in the "quarter-precision" float format, but can nonetheless be
4294 loaded as integer constants. */
136da414
JB
4295
4296static unsigned
4297parse_qfloat_immediate (char **ccp, int *immed)
4298{
4299 char *str = *ccp;
c96612cc 4300 char *fpnum;
136da414 4301 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4302 int found_fpchar = 0;
5f4273c7 4303
136da414 4304 skip_past_char (&str, '#');
5f4273c7 4305
c96612cc
JB
4306 /* We must not accidentally parse an integer as a floating-point number. Make
4307 sure that the value we parse is not an integer by checking for special
4308 characters '.' or 'e'.
4309 FIXME: This is a horrible hack, but doing better is tricky because type
4310 information isn't in a very usable state at parse time. */
4311 fpnum = str;
4312 skip_whitespace (fpnum);
4313
4314 if (strncmp (fpnum, "0x", 2) == 0)
4315 return FAIL;
4316 else
4317 {
4318 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4319 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4320 {
4321 found_fpchar = 1;
4322 break;
4323 }
4324
4325 if (!found_fpchar)
4326 return FAIL;
4327 }
5f4273c7 4328
136da414
JB
4329 if ((str = atof_ieee (str, 's', words)) != NULL)
4330 {
4331 unsigned fpword = 0;
4332 int i;
5f4273c7 4333
136da414
JB
4334 /* Our FP word must be 32 bits (single-precision FP). */
4335 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4336 {
4337 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4338 fpword |= words[i];
4339 }
5f4273c7 4340
c96612cc 4341 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4342 *immed = fpword;
4343 else
4344 return FAIL;
4345
4346 *ccp = str;
5f4273c7 4347
136da414
JB
4348 return SUCCESS;
4349 }
5f4273c7 4350
136da414
JB
4351 return FAIL;
4352}
4353
c19d1205
ZW
4354/* Shift operands. */
4355enum shift_kind
b99bd4ef 4356{
c19d1205
ZW
4357 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4358};
b99bd4ef 4359
c19d1205
ZW
4360struct asm_shift_name
4361{
4362 const char *name;
4363 enum shift_kind kind;
4364};
b99bd4ef 4365
c19d1205
ZW
4366/* Third argument to parse_shift. */
4367enum parse_shift_mode
4368{
4369 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4370 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4371 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4372 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4373 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4374};
b99bd4ef 4375
c19d1205
ZW
4376/* Parse a <shift> specifier on an ARM data processing instruction.
4377 This has three forms:
b99bd4ef 4378
c19d1205
ZW
4379 (LSL|LSR|ASL|ASR|ROR) Rs
4380 (LSL|LSR|ASL|ASR|ROR) #imm
4381 RRX
b99bd4ef 4382
c19d1205
ZW
4383 Note that ASL is assimilated to LSL in the instruction encoding, and
4384 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4385
c19d1205
ZW
4386static int
4387parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4388{
c19d1205
ZW
4389 const struct asm_shift_name *shift_name;
4390 enum shift_kind shift;
4391 char *s = *str;
4392 char *p = s;
4393 int reg;
b99bd4ef 4394
c19d1205
ZW
4395 for (p = *str; ISALPHA (*p); p++)
4396 ;
b99bd4ef 4397
c19d1205 4398 if (p == *str)
b99bd4ef 4399 {
c19d1205
ZW
4400 inst.error = _("shift expression expected");
4401 return FAIL;
b99bd4ef
NC
4402 }
4403
c19d1205
ZW
4404 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4405
4406 if (shift_name == NULL)
b99bd4ef 4407 {
c19d1205
ZW
4408 inst.error = _("shift expression expected");
4409 return FAIL;
b99bd4ef
NC
4410 }
4411
c19d1205 4412 shift = shift_name->kind;
b99bd4ef 4413
c19d1205
ZW
4414 switch (mode)
4415 {
4416 case NO_SHIFT_RESTRICT:
4417 case SHIFT_IMMEDIATE: break;
b99bd4ef 4418
c19d1205
ZW
4419 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4420 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4421 {
4422 inst.error = _("'LSL' or 'ASR' required");
4423 return FAIL;
4424 }
4425 break;
b99bd4ef 4426
c19d1205
ZW
4427 case SHIFT_LSL_IMMEDIATE:
4428 if (shift != SHIFT_LSL)
4429 {
4430 inst.error = _("'LSL' required");
4431 return FAIL;
4432 }
4433 break;
b99bd4ef 4434
c19d1205
ZW
4435 case SHIFT_ASR_IMMEDIATE:
4436 if (shift != SHIFT_ASR)
4437 {
4438 inst.error = _("'ASR' required");
4439 return FAIL;
4440 }
4441 break;
b99bd4ef 4442
c19d1205
ZW
4443 default: abort ();
4444 }
b99bd4ef 4445
c19d1205
ZW
4446 if (shift != SHIFT_RRX)
4447 {
4448 /* Whitespace can appear here if the next thing is a bare digit. */
4449 skip_whitespace (p);
b99bd4ef 4450
c19d1205 4451 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4452 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4453 {
4454 inst.operands[i].imm = reg;
4455 inst.operands[i].immisreg = 1;
4456 }
4457 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4458 return FAIL;
4459 }
4460 inst.operands[i].shift_kind = shift;
4461 inst.operands[i].shifted = 1;
4462 *str = p;
4463 return SUCCESS;
b99bd4ef
NC
4464}
4465
c19d1205 4466/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4467
c19d1205
ZW
4468 #<immediate>
4469 #<immediate>, <rotate>
4470 <Rm>
4471 <Rm>, <shift>
b99bd4ef 4472
c19d1205
ZW
4473 where <shift> is defined by parse_shift above, and <rotate> is a
4474 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4475 is deferred to md_apply_fix. */
b99bd4ef 4476
c19d1205
ZW
4477static int
4478parse_shifter_operand (char **str, int i)
4479{
4480 int value;
4481 expressionS expr;
b99bd4ef 4482
dcbf9037 4483 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4484 {
4485 inst.operands[i].reg = value;
4486 inst.operands[i].isreg = 1;
b99bd4ef 4487
c19d1205
ZW
4488 /* parse_shift will override this if appropriate */
4489 inst.reloc.exp.X_op = O_constant;
4490 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4491
c19d1205
ZW
4492 if (skip_past_comma (str) == FAIL)
4493 return SUCCESS;
b99bd4ef 4494
c19d1205
ZW
4495 /* Shift operation on register. */
4496 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4497 }
4498
c19d1205
ZW
4499 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4500 return FAIL;
b99bd4ef 4501
c19d1205 4502 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4503 {
c19d1205
ZW
4504 /* #x, y -- ie explicit rotation by Y. */
4505 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4506 return FAIL;
b99bd4ef 4507
c19d1205
ZW
4508 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4509 {
4510 inst.error = _("constant expression expected");
4511 return FAIL;
4512 }
b99bd4ef 4513
c19d1205
ZW
4514 value = expr.X_add_number;
4515 if (value < 0 || value > 30 || value % 2 != 0)
4516 {
4517 inst.error = _("invalid rotation");
4518 return FAIL;
4519 }
4520 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4521 {
4522 inst.error = _("invalid constant");
4523 return FAIL;
4524 }
09d92015 4525
55cf6793 4526 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4527 inst.reloc.exp.X_add_number
4528 = (((inst.reloc.exp.X_add_number << (32 - value))
4529 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4530 }
4531
c19d1205
ZW
4532 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4533 inst.reloc.pc_rel = 0;
4534 return SUCCESS;
09d92015
MM
4535}
4536
4962c51a
MS
4537/* Group relocation information. Each entry in the table contains the
4538 textual name of the relocation as may appear in assembler source
4539 and must end with a colon.
4540 Along with this textual name are the relocation codes to be used if
4541 the corresponding instruction is an ALU instruction (ADD or SUB only),
4542 an LDR, an LDRS, or an LDC. */
4543
4544struct group_reloc_table_entry
4545{
4546 const char *name;
4547 int alu_code;
4548 int ldr_code;
4549 int ldrs_code;
4550 int ldc_code;
4551};
4552
4553typedef enum
4554{
4555 /* Varieties of non-ALU group relocation. */
4556
4557 GROUP_LDR,
4558 GROUP_LDRS,
4559 GROUP_LDC
4560} group_reloc_type;
4561
4562static struct group_reloc_table_entry group_reloc_table[] =
4563 { /* Program counter relative: */
4564 { "pc_g0_nc",
4565 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4566 0, /* LDR */
4567 0, /* LDRS */
4568 0 }, /* LDC */
4569 { "pc_g0",
4570 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4571 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4572 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4573 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4574 { "pc_g1_nc",
4575 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4576 0, /* LDR */
4577 0, /* LDRS */
4578 0 }, /* LDC */
4579 { "pc_g1",
4580 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4581 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4582 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4583 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4584 { "pc_g2",
4585 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4586 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4587 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4588 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4589 /* Section base relative */
4590 { "sb_g0_nc",
4591 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4592 0, /* LDR */
4593 0, /* LDRS */
4594 0 }, /* LDC */
4595 { "sb_g0",
4596 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4597 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4598 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4599 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4600 { "sb_g1_nc",
4601 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4602 0, /* LDR */
4603 0, /* LDRS */
4604 0 }, /* LDC */
4605 { "sb_g1",
4606 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4607 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4608 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4609 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4610 { "sb_g2",
4611 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4612 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4613 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4614 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4615
4616/* Given the address of a pointer pointing to the textual name of a group
4617 relocation as may appear in assembler source, attempt to find its details
4618 in group_reloc_table. The pointer will be updated to the character after
4619 the trailing colon. On failure, FAIL will be returned; SUCCESS
4620 otherwise. On success, *entry will be updated to point at the relevant
4621 group_reloc_table entry. */
4622
4623static int
4624find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4625{
4626 unsigned int i;
4627 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4628 {
4629 int length = strlen (group_reloc_table[i].name);
4630
5f4273c7
NC
4631 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4632 && (*str)[length] == ':')
4962c51a
MS
4633 {
4634 *out = &group_reloc_table[i];
4635 *str += (length + 1);
4636 return SUCCESS;
4637 }
4638 }
4639
4640 return FAIL;
4641}
4642
4643/* Parse a <shifter_operand> for an ARM data processing instruction
4644 (as for parse_shifter_operand) where group relocations are allowed:
4645
4646 #<immediate>
4647 #<immediate>, <rotate>
4648 #:<group_reloc>:<expression>
4649 <Rm>
4650 <Rm>, <shift>
4651
4652 where <group_reloc> is one of the strings defined in group_reloc_table.
4653 The hashes are optional.
4654
4655 Everything else is as for parse_shifter_operand. */
4656
4657static parse_operand_result
4658parse_shifter_operand_group_reloc (char **str, int i)
4659{
4660 /* Determine if we have the sequence of characters #: or just :
4661 coming next. If we do, then we check for a group relocation.
4662 If we don't, punt the whole lot to parse_shifter_operand. */
4663
4664 if (((*str)[0] == '#' && (*str)[1] == ':')
4665 || (*str)[0] == ':')
4666 {
4667 struct group_reloc_table_entry *entry;
4668
4669 if ((*str)[0] == '#')
4670 (*str) += 2;
4671 else
4672 (*str)++;
4673
4674 /* Try to parse a group relocation. Anything else is an error. */
4675 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4676 {
4677 inst.error = _("unknown group relocation");
4678 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4679 }
4680
4681 /* We now have the group relocation table entry corresponding to
4682 the name in the assembler source. Next, we parse the expression. */
4683 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4684 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4685
4686 /* Record the relocation type (always the ALU variant here). */
4687 inst.reloc.type = entry->alu_code;
9c2799c2 4688 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4689
4690 return PARSE_OPERAND_SUCCESS;
4691 }
4692 else
4693 return parse_shifter_operand (str, i) == SUCCESS
4694 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4695
4696 /* Never reached. */
4697}
4698
c19d1205
ZW
4699/* Parse all forms of an ARM address expression. Information is written
4700 to inst.operands[i] and/or inst.reloc.
09d92015 4701
c19d1205 4702 Preindexed addressing (.preind=1):
09d92015 4703
c19d1205
ZW
4704 [Rn, #offset] .reg=Rn .reloc.exp=offset
4705 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4706 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4707 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4708
c19d1205 4709 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4710
c19d1205 4711 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4712
c19d1205
ZW
4713 [Rn], #offset .reg=Rn .reloc.exp=offset
4714 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4715 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4716 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4717
c19d1205 4718 Unindexed addressing (.preind=0, .postind=0):
09d92015 4719
c19d1205 4720 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4721
c19d1205 4722 Other:
09d92015 4723
c19d1205
ZW
4724 [Rn]{!} shorthand for [Rn,#0]{!}
4725 =immediate .isreg=0 .reloc.exp=immediate
4726 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4727
c19d1205
ZW
4728 It is the caller's responsibility to check for addressing modes not
4729 supported by the instruction, and to set inst.reloc.type. */
4730
4962c51a
MS
4731static parse_operand_result
4732parse_address_main (char **str, int i, int group_relocations,
4733 group_reloc_type group_type)
09d92015 4734{
c19d1205
ZW
4735 char *p = *str;
4736 int reg;
09d92015 4737
c19d1205 4738 if (skip_past_char (&p, '[') == FAIL)
09d92015 4739 {
c19d1205
ZW
4740 if (skip_past_char (&p, '=') == FAIL)
4741 {
4742 /* bare address - translate to PC-relative offset */
4743 inst.reloc.pc_rel = 1;
4744 inst.operands[i].reg = REG_PC;
4745 inst.operands[i].isreg = 1;
4746 inst.operands[i].preind = 1;
4747 }
4748 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4749
c19d1205 4750 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4751 return PARSE_OPERAND_FAIL;
09d92015 4752
c19d1205 4753 *str = p;
4962c51a 4754 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4755 }
4756
dcbf9037 4757 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4758 {
c19d1205 4759 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4760 return PARSE_OPERAND_FAIL;
09d92015 4761 }
c19d1205
ZW
4762 inst.operands[i].reg = reg;
4763 inst.operands[i].isreg = 1;
09d92015 4764
c19d1205 4765 if (skip_past_comma (&p) == SUCCESS)
09d92015 4766 {
c19d1205 4767 inst.operands[i].preind = 1;
09d92015 4768
c19d1205
ZW
4769 if (*p == '+') p++;
4770 else if (*p == '-') p++, inst.operands[i].negative = 1;
4771
dcbf9037 4772 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4773 {
c19d1205
ZW
4774 inst.operands[i].imm = reg;
4775 inst.operands[i].immisreg = 1;
4776
4777 if (skip_past_comma (&p) == SUCCESS)
4778 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4779 return PARSE_OPERAND_FAIL;
c19d1205 4780 }
5287ad62
JB
4781 else if (skip_past_char (&p, ':') == SUCCESS)
4782 {
4783 /* FIXME: '@' should be used here, but it's filtered out by generic
4784 code before we get to see it here. This may be subject to
4785 change. */
4786 expressionS exp;
4787 my_get_expression (&exp, &p, GE_NO_PREFIX);
4788 if (exp.X_op != O_constant)
4789 {
4790 inst.error = _("alignment must be constant");
4962c51a 4791 return PARSE_OPERAND_FAIL;
5287ad62
JB
4792 }
4793 inst.operands[i].imm = exp.X_add_number << 8;
4794 inst.operands[i].immisalign = 1;
4795 /* Alignments are not pre-indexes. */
4796 inst.operands[i].preind = 0;
4797 }
c19d1205
ZW
4798 else
4799 {
4800 if (inst.operands[i].negative)
4801 {
4802 inst.operands[i].negative = 0;
4803 p--;
4804 }
4962c51a 4805
5f4273c7
NC
4806 if (group_relocations
4807 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4808 {
4809 struct group_reloc_table_entry *entry;
4810
4811 /* Skip over the #: or : sequence. */
4812 if (*p == '#')
4813 p += 2;
4814 else
4815 p++;
4816
4817 /* Try to parse a group relocation. Anything else is an
4818 error. */
4819 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4820 {
4821 inst.error = _("unknown group relocation");
4822 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4823 }
4824
4825 /* We now have the group relocation table entry corresponding to
4826 the name in the assembler source. Next, we parse the
4827 expression. */
4828 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4829 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4830
4831 /* Record the relocation type. */
4832 switch (group_type)
4833 {
4834 case GROUP_LDR:
4835 inst.reloc.type = entry->ldr_code;
4836 break;
4837
4838 case GROUP_LDRS:
4839 inst.reloc.type = entry->ldrs_code;
4840 break;
4841
4842 case GROUP_LDC:
4843 inst.reloc.type = entry->ldc_code;
4844 break;
4845
4846 default:
9c2799c2 4847 gas_assert (0);
4962c51a
MS
4848 }
4849
4850 if (inst.reloc.type == 0)
4851 {
4852 inst.error = _("this group relocation is not allowed on this instruction");
4853 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4854 }
4855 }
4856 else
4857 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4858 return PARSE_OPERAND_FAIL;
09d92015
MM
4859 }
4860 }
4861
c19d1205 4862 if (skip_past_char (&p, ']') == FAIL)
09d92015 4863 {
c19d1205 4864 inst.error = _("']' expected");
4962c51a 4865 return PARSE_OPERAND_FAIL;
09d92015
MM
4866 }
4867
c19d1205
ZW
4868 if (skip_past_char (&p, '!') == SUCCESS)
4869 inst.operands[i].writeback = 1;
09d92015 4870
c19d1205 4871 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4872 {
c19d1205
ZW
4873 if (skip_past_char (&p, '{') == SUCCESS)
4874 {
4875 /* [Rn], {expr} - unindexed, with option */
4876 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4877 0, 255, TRUE) == FAIL)
4962c51a 4878 return PARSE_OPERAND_FAIL;
09d92015 4879
c19d1205
ZW
4880 if (skip_past_char (&p, '}') == FAIL)
4881 {
4882 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4883 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4884 }
4885 if (inst.operands[i].preind)
4886 {
4887 inst.error = _("cannot combine index with option");
4962c51a 4888 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4889 }
4890 *str = p;
4962c51a 4891 return PARSE_OPERAND_SUCCESS;
09d92015 4892 }
c19d1205
ZW
4893 else
4894 {
4895 inst.operands[i].postind = 1;
4896 inst.operands[i].writeback = 1;
09d92015 4897
c19d1205
ZW
4898 if (inst.operands[i].preind)
4899 {
4900 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4901 return PARSE_OPERAND_FAIL;
c19d1205 4902 }
09d92015 4903
c19d1205
ZW
4904 if (*p == '+') p++;
4905 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4906
dcbf9037 4907 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4908 {
5287ad62
JB
4909 /* We might be using the immediate for alignment already. If we
4910 are, OR the register number into the low-order bits. */
4911 if (inst.operands[i].immisalign)
4912 inst.operands[i].imm |= reg;
4913 else
4914 inst.operands[i].imm = reg;
c19d1205 4915 inst.operands[i].immisreg = 1;
a737bd4d 4916
c19d1205
ZW
4917 if (skip_past_comma (&p) == SUCCESS)
4918 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4919 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4920 }
4921 else
4922 {
4923 if (inst.operands[i].negative)
4924 {
4925 inst.operands[i].negative = 0;
4926 p--;
4927 }
4928 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4929 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4930 }
4931 }
a737bd4d
NC
4932 }
4933
c19d1205
ZW
4934 /* If at this point neither .preind nor .postind is set, we have a
4935 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4936 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4937 {
4938 inst.operands[i].preind = 1;
4939 inst.reloc.exp.X_op = O_constant;
4940 inst.reloc.exp.X_add_number = 0;
4941 }
4942 *str = p;
4962c51a
MS
4943 return PARSE_OPERAND_SUCCESS;
4944}
4945
4946static int
4947parse_address (char **str, int i)
4948{
4949 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4950 ? SUCCESS : FAIL;
4951}
4952
4953static parse_operand_result
4954parse_address_group_reloc (char **str, int i, group_reloc_type type)
4955{
4956 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4957}
4958
b6895b4f
PB
4959/* Parse an operand for a MOVW or MOVT instruction. */
4960static int
4961parse_half (char **str)
4962{
4963 char * p;
5f4273c7 4964
b6895b4f
PB
4965 p = *str;
4966 skip_past_char (&p, '#');
5f4273c7 4967 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4968 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4969 else if (strncasecmp (p, ":upper16:", 9) == 0)
4970 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4971
4972 if (inst.reloc.type != BFD_RELOC_UNUSED)
4973 {
4974 p += 9;
5f4273c7 4975 skip_whitespace (p);
b6895b4f
PB
4976 }
4977
4978 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4979 return FAIL;
4980
4981 if (inst.reloc.type == BFD_RELOC_UNUSED)
4982 {
4983 if (inst.reloc.exp.X_op != O_constant)
4984 {
4985 inst.error = _("constant expression expected");
4986 return FAIL;
4987 }
4988 if (inst.reloc.exp.X_add_number < 0
4989 || inst.reloc.exp.X_add_number > 0xffff)
4990 {
4991 inst.error = _("immediate value out of range");
4992 return FAIL;
4993 }
4994 }
4995 *str = p;
4996 return SUCCESS;
4997}
4998
c19d1205 4999/* Miscellaneous. */
a737bd4d 5000
c19d1205
ZW
5001/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5002 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5003static int
5004parse_psr (char **str)
09d92015 5005{
c19d1205
ZW
5006 char *p;
5007 unsigned long psr_field;
62b3e311
PB
5008 const struct asm_psr *psr;
5009 char *start;
09d92015 5010
c19d1205
ZW
5011 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5012 feature for ease of use and backwards compatibility. */
5013 p = *str;
62b3e311 5014 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5015 psr_field = SPSR_BIT;
62b3e311 5016 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5017 psr_field = 0;
5018 else
62b3e311
PB
5019 {
5020 start = p;
5021 do
5022 p++;
5023 while (ISALNUM (*p) || *p == '_');
5024
5025 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
5026 if (!psr)
5027 return FAIL;
09d92015 5028
62b3e311
PB
5029 *str = p;
5030 return psr->field;
5031 }
09d92015 5032
62b3e311 5033 p += 4;
c19d1205
ZW
5034 if (*p == '_')
5035 {
5036 /* A suffix follows. */
c19d1205
ZW
5037 p++;
5038 start = p;
a737bd4d 5039
c19d1205
ZW
5040 do
5041 p++;
5042 while (ISALNUM (*p) || *p == '_');
a737bd4d 5043
c19d1205
ZW
5044 psr = hash_find_n (arm_psr_hsh, start, p - start);
5045 if (!psr)
5046 goto error;
a737bd4d 5047
c19d1205 5048 psr_field |= psr->field;
a737bd4d 5049 }
c19d1205 5050 else
a737bd4d 5051 {
c19d1205
ZW
5052 if (ISALNUM (*p))
5053 goto error; /* Garbage after "[CS]PSR". */
5054
5055 psr_field |= (PSR_c | PSR_f);
a737bd4d 5056 }
c19d1205
ZW
5057 *str = p;
5058 return psr_field;
a737bd4d 5059
c19d1205
ZW
5060 error:
5061 inst.error = _("flag for {c}psr instruction expected");
5062 return FAIL;
a737bd4d
NC
5063}
5064
c19d1205
ZW
5065/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5066 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5067
c19d1205
ZW
5068static int
5069parse_cps_flags (char **str)
a737bd4d 5070{
c19d1205
ZW
5071 int val = 0;
5072 int saw_a_flag = 0;
5073 char *s = *str;
a737bd4d 5074
c19d1205
ZW
5075 for (;;)
5076 switch (*s++)
5077 {
5078 case '\0': case ',':
5079 goto done;
a737bd4d 5080
c19d1205
ZW
5081 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5082 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5083 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5084
c19d1205
ZW
5085 default:
5086 inst.error = _("unrecognized CPS flag");
5087 return FAIL;
5088 }
a737bd4d 5089
c19d1205
ZW
5090 done:
5091 if (saw_a_flag == 0)
a737bd4d 5092 {
c19d1205
ZW
5093 inst.error = _("missing CPS flags");
5094 return FAIL;
a737bd4d 5095 }
a737bd4d 5096
c19d1205
ZW
5097 *str = s - 1;
5098 return val;
a737bd4d
NC
5099}
5100
c19d1205
ZW
5101/* Parse an endian specifier ("BE" or "LE", case insensitive);
5102 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5103
5104static int
c19d1205 5105parse_endian_specifier (char **str)
a737bd4d 5106{
c19d1205
ZW
5107 int little_endian;
5108 char *s = *str;
a737bd4d 5109
c19d1205
ZW
5110 if (strncasecmp (s, "BE", 2))
5111 little_endian = 0;
5112 else if (strncasecmp (s, "LE", 2))
5113 little_endian = 1;
5114 else
a737bd4d 5115 {
c19d1205 5116 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5117 return FAIL;
5118 }
5119
c19d1205 5120 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5121 {
c19d1205 5122 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5123 return FAIL;
5124 }
5125
c19d1205
ZW
5126 *str = s + 2;
5127 return little_endian;
5128}
a737bd4d 5129
c19d1205
ZW
5130/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5131 value suitable for poking into the rotate field of an sxt or sxta
5132 instruction, or FAIL on error. */
5133
5134static int
5135parse_ror (char **str)
5136{
5137 int rot;
5138 char *s = *str;
5139
5140 if (strncasecmp (s, "ROR", 3) == 0)
5141 s += 3;
5142 else
a737bd4d 5143 {
c19d1205 5144 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5145 return FAIL;
5146 }
c19d1205
ZW
5147
5148 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5149 return FAIL;
5150
5151 switch (rot)
a737bd4d 5152 {
c19d1205
ZW
5153 case 0: *str = s; return 0x0;
5154 case 8: *str = s; return 0x1;
5155 case 16: *str = s; return 0x2;
5156 case 24: *str = s; return 0x3;
5157
5158 default:
5159 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5160 return FAIL;
5161 }
c19d1205 5162}
a737bd4d 5163
c19d1205
ZW
5164/* Parse a conditional code (from conds[] below). The value returned is in the
5165 range 0 .. 14, or FAIL. */
5166static int
5167parse_cond (char **str)
5168{
c462b453 5169 char *q;
c19d1205 5170 const struct asm_cond *c;
c462b453
PB
5171 int n;
5172 /* Condition codes are always 2 characters, so matching up to
5173 3 characters is sufficient. */
5174 char cond[3];
a737bd4d 5175
c462b453
PB
5176 q = *str;
5177 n = 0;
5178 while (ISALPHA (*q) && n < 3)
5179 {
e07e6e58 5180 cond[n] = TOLOWER (*q);
c462b453
PB
5181 q++;
5182 n++;
5183 }
a737bd4d 5184
c462b453 5185 c = hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5186 if (!c)
a737bd4d 5187 {
c19d1205 5188 inst.error = _("condition required");
a737bd4d
NC
5189 return FAIL;
5190 }
5191
c19d1205
ZW
5192 *str = q;
5193 return c->value;
5194}
5195
62b3e311
PB
5196/* Parse an option for a barrier instruction. Returns the encoding for the
5197 option, or FAIL. */
5198static int
5199parse_barrier (char **str)
5200{
5201 char *p, *q;
5202 const struct asm_barrier_opt *o;
5203
5204 p = q = *str;
5205 while (ISALPHA (*q))
5206 q++;
5207
5208 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5209 if (!o)
5210 return FAIL;
5211
5212 *str = q;
5213 return o->value;
5214}
5215
92e90b6e
PB
5216/* Parse the operands of a table branch instruction. Similar to a memory
5217 operand. */
5218static int
5219parse_tb (char **str)
5220{
5221 char * p = *str;
5222 int reg;
5223
5224 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5225 {
5226 inst.error = _("'[' expected");
5227 return FAIL;
5228 }
92e90b6e 5229
dcbf9037 5230 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5231 {
5232 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5233 return FAIL;
5234 }
5235 inst.operands[0].reg = reg;
5236
5237 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5238 {
5239 inst.error = _("',' expected");
5240 return FAIL;
5241 }
5f4273c7 5242
dcbf9037 5243 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5244 {
5245 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5246 return FAIL;
5247 }
5248 inst.operands[0].imm = reg;
5249
5250 if (skip_past_comma (&p) == SUCCESS)
5251 {
5252 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5253 return FAIL;
5254 if (inst.reloc.exp.X_add_number != 1)
5255 {
5256 inst.error = _("invalid shift");
5257 return FAIL;
5258 }
5259 inst.operands[0].shifted = 1;
5260 }
5261
5262 if (skip_past_char (&p, ']') == FAIL)
5263 {
5264 inst.error = _("']' expected");
5265 return FAIL;
5266 }
5267 *str = p;
5268 return SUCCESS;
5269}
5270
5287ad62
JB
5271/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5272 information on the types the operands can take and how they are encoded.
037e8744
JB
5273 Up to four operands may be read; this function handles setting the
5274 ".present" field for each read operand itself.
5287ad62
JB
5275 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5276 else returns FAIL. */
5277
5278static int
5279parse_neon_mov (char **str, int *which_operand)
5280{
5281 int i = *which_operand, val;
5282 enum arm_reg_type rtype;
5283 char *ptr = *str;
dcbf9037 5284 struct neon_type_el optype;
5f4273c7 5285
dcbf9037 5286 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5287 {
5288 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5289 inst.operands[i].reg = val;
5290 inst.operands[i].isscalar = 1;
dcbf9037 5291 inst.operands[i].vectype = optype;
5287ad62
JB
5292 inst.operands[i++].present = 1;
5293
5294 if (skip_past_comma (&ptr) == FAIL)
5295 goto wanted_comma;
5f4273c7 5296
dcbf9037 5297 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5298 goto wanted_arm;
5f4273c7 5299
5287ad62
JB
5300 inst.operands[i].reg = val;
5301 inst.operands[i].isreg = 1;
5302 inst.operands[i].present = 1;
5303 }
037e8744 5304 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5305 != FAIL)
5287ad62
JB
5306 {
5307 /* Cases 0, 1, 2, 3, 5 (D only). */
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5f4273c7 5310
5287ad62
JB
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5315 inst.operands[i].isvec = 1;
dcbf9037 5316 inst.operands[i].vectype = optype;
5287ad62
JB
5317 inst.operands[i++].present = 1;
5318
dcbf9037 5319 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5320 {
037e8744
JB
5321 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5322 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5323 inst.operands[i].reg = val;
5324 inst.operands[i].isreg = 1;
037e8744 5325 inst.operands[i].present = 1;
5287ad62
JB
5326
5327 if (rtype == REG_TYPE_NQ)
5328 {
dcbf9037 5329 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5330 return FAIL;
5331 }
037e8744
JB
5332 else if (rtype != REG_TYPE_VFS)
5333 {
5334 i++;
5335 if (skip_past_comma (&ptr) == FAIL)
5336 goto wanted_comma;
5337 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5338 goto wanted_arm;
5339 inst.operands[i].reg = val;
5340 inst.operands[i].isreg = 1;
5341 inst.operands[i].present = 1;
5342 }
5287ad62 5343 }
037e8744
JB
5344 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5345 &optype)) != FAIL)
5287ad62
JB
5346 {
5347 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5348 Case 1: VMOV<c><q> <Dd>, <Dm>
5349 Case 8: VMOV.F32 <Sd>, <Sm>
5350 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5351
5352 inst.operands[i].reg = val;
5353 inst.operands[i].isreg = 1;
5354 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5355 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5356 inst.operands[i].isvec = 1;
dcbf9037 5357 inst.operands[i].vectype = optype;
5287ad62 5358 inst.operands[i].present = 1;
5f4273c7 5359
037e8744
JB
5360 if (skip_past_comma (&ptr) == SUCCESS)
5361 {
5362 /* Case 15. */
5363 i++;
5364
5365 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5366 goto wanted_arm;
5367
5368 inst.operands[i].reg = val;
5369 inst.operands[i].isreg = 1;
5370 inst.operands[i++].present = 1;
5f4273c7 5371
037e8744
JB
5372 if (skip_past_comma (&ptr) == FAIL)
5373 goto wanted_comma;
5f4273c7 5374
037e8744
JB
5375 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5376 goto wanted_arm;
5f4273c7 5377
037e8744
JB
5378 inst.operands[i].reg = val;
5379 inst.operands[i].isreg = 1;
5380 inst.operands[i++].present = 1;
5381 }
5287ad62 5382 }
4641781c
PB
5383 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5384 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5385 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5386 Case 10: VMOV.F32 <Sd>, #<imm>
5387 Case 11: VMOV.F64 <Dd>, #<imm> */
5388 inst.operands[i].immisfloat = 1;
5389 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5390 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5391 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5392 ;
5287ad62
JB
5393 else
5394 {
dcbf9037 5395 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5396 return FAIL;
5397 }
5398 }
dcbf9037 5399 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5400 {
5401 /* Cases 6, 7. */
5402 inst.operands[i].reg = val;
5403 inst.operands[i].isreg = 1;
5404 inst.operands[i++].present = 1;
5f4273c7 5405
5287ad62
JB
5406 if (skip_past_comma (&ptr) == FAIL)
5407 goto wanted_comma;
5f4273c7 5408
dcbf9037 5409 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5410 {
5411 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5412 inst.operands[i].reg = val;
5413 inst.operands[i].isscalar = 1;
5414 inst.operands[i].present = 1;
dcbf9037 5415 inst.operands[i].vectype = optype;
5287ad62 5416 }
dcbf9037 5417 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5418 {
5419 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5420 inst.operands[i].reg = val;
5421 inst.operands[i].isreg = 1;
5422 inst.operands[i++].present = 1;
5f4273c7 5423
5287ad62
JB
5424 if (skip_past_comma (&ptr) == FAIL)
5425 goto wanted_comma;
5f4273c7 5426
037e8744 5427 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5428 == FAIL)
5287ad62 5429 {
037e8744 5430 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5431 return FAIL;
5432 }
5433
5434 inst.operands[i].reg = val;
5435 inst.operands[i].isreg = 1;
037e8744
JB
5436 inst.operands[i].isvec = 1;
5437 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5438 inst.operands[i].vectype = optype;
5287ad62 5439 inst.operands[i].present = 1;
5f4273c7 5440
037e8744
JB
5441 if (rtype == REG_TYPE_VFS)
5442 {
5443 /* Case 14. */
5444 i++;
5445 if (skip_past_comma (&ptr) == FAIL)
5446 goto wanted_comma;
5447 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5448 &optype)) == FAIL)
5449 {
5450 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5451 return FAIL;
5452 }
5453 inst.operands[i].reg = val;
5454 inst.operands[i].isreg = 1;
5455 inst.operands[i].isvec = 1;
5456 inst.operands[i].issingle = 1;
5457 inst.operands[i].vectype = optype;
5458 inst.operands[i].present = 1;
5459 }
5460 }
5461 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5462 != FAIL)
5463 {
5464 /* Case 13. */
5465 inst.operands[i].reg = val;
5466 inst.operands[i].isreg = 1;
5467 inst.operands[i].isvec = 1;
5468 inst.operands[i].issingle = 1;
5469 inst.operands[i].vectype = optype;
5470 inst.operands[i++].present = 1;
5287ad62
JB
5471 }
5472 }
5473 else
5474 {
dcbf9037 5475 first_error (_("parse error"));
5287ad62
JB
5476 return FAIL;
5477 }
5478
5479 /* Successfully parsed the operands. Update args. */
5480 *which_operand = i;
5481 *str = ptr;
5482 return SUCCESS;
5483
5f4273c7 5484 wanted_comma:
dcbf9037 5485 first_error (_("expected comma"));
5287ad62 5486 return FAIL;
5f4273c7
NC
5487
5488 wanted_arm:
dcbf9037 5489 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5490 return FAIL;
5287ad62
JB
5491}
5492
c19d1205
ZW
5493/* Matcher codes for parse_operands. */
5494enum operand_parse_code
5495{
5496 OP_stop, /* end of line */
5497
5498 OP_RR, /* ARM register */
5499 OP_RRnpc, /* ARM register, not r15 */
5500 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5501 OP_RRw, /* ARM register, not r15, optional trailing ! */
5502 OP_RCP, /* Coprocessor number */
5503 OP_RCN, /* Coprocessor register */
5504 OP_RF, /* FPA register */
5505 OP_RVS, /* VFP single precision register */
5287ad62
JB
5506 OP_RVD, /* VFP double precision register (0..15) */
5507 OP_RND, /* Neon double precision register (0..31) */
5508 OP_RNQ, /* Neon quad precision register */
037e8744 5509 OP_RVSD, /* VFP single or double precision register */
5287ad62 5510 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5511 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5512 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5513 OP_RVC, /* VFP control register */
5514 OP_RMF, /* Maverick F register */
5515 OP_RMD, /* Maverick D register */
5516 OP_RMFX, /* Maverick FX register */
5517 OP_RMDX, /* Maverick DX register */
5518 OP_RMAX, /* Maverick AX register */
5519 OP_RMDS, /* Maverick DSPSC register */
5520 OP_RIWR, /* iWMMXt wR register */
5521 OP_RIWC, /* iWMMXt wC register */
5522 OP_RIWG, /* iWMMXt wCG register */
5523 OP_RXA, /* XScale accumulator register */
5524
5525 OP_REGLST, /* ARM register list */
5526 OP_VRSLST, /* VFP single-precision register list */
5527 OP_VRDLST, /* VFP double-precision register list */
037e8744 5528 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5529 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5530 OP_NSTRLST, /* Neon element/structure list */
5531
5532 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5533 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5534 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5535 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5536 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5537 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5538 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5539 OP_VMOV, /* Neon VMOV operands. */
5540 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5541 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5542 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5543
5544 OP_I0, /* immediate zero */
c19d1205
ZW
5545 OP_I7, /* immediate value 0 .. 7 */
5546 OP_I15, /* 0 .. 15 */
5547 OP_I16, /* 1 .. 16 */
5287ad62 5548 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5549 OP_I31, /* 0 .. 31 */
5550 OP_I31w, /* 0 .. 31, optional trailing ! */
5551 OP_I32, /* 1 .. 32 */
5287ad62
JB
5552 OP_I32z, /* 0 .. 32 */
5553 OP_I63, /* 0 .. 63 */
c19d1205 5554 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5555 OP_I64, /* 1 .. 64 */
5556 OP_I64z, /* 0 .. 64 */
c19d1205 5557 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5558
5559 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5560 OP_I7b, /* 0 .. 7 */
5561 OP_I15b, /* 0 .. 15 */
5562 OP_I31b, /* 0 .. 31 */
5563
5564 OP_SH, /* shifter operand */
4962c51a 5565 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5566 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5567 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5568 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5569 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5570 OP_EXP, /* arbitrary expression */
5571 OP_EXPi, /* same, with optional immediate prefix */
5572 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5573 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5574
5575 OP_CPSF, /* CPS flags */
5576 OP_ENDI, /* Endianness specifier */
5577 OP_PSR, /* CPSR/SPSR mask for msr */
5578 OP_COND, /* conditional code */
92e90b6e 5579 OP_TB, /* Table branch. */
c19d1205 5580
037e8744
JB
5581 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5582 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5583
c19d1205
ZW
5584 OP_RRnpc_I0, /* ARM register or literal 0 */
5585 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5586 OP_RR_EXi, /* ARM register or expression with imm prefix */
5587 OP_RF_IF, /* FPA register or immediate */
5588 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5589 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5590
5591 /* Optional operands. */
5592 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5593 OP_oI31b, /* 0 .. 31 */
5287ad62 5594 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5595 OP_oIffffb, /* 0 .. 65535 */
5596 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5597
5598 OP_oRR, /* ARM register */
5599 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5600 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5601 OP_oRND, /* Optional Neon double precision register */
5602 OP_oRNQ, /* Optional Neon quad precision register */
5603 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5604 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5605 OP_oSHll, /* LSL immediate */
5606 OP_oSHar, /* ASR immediate */
5607 OP_oSHllar, /* LSL or ASR immediate */
5608 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5609 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5610
5611 OP_FIRST_OPTIONAL = OP_oI7b
5612};
a737bd4d 5613
c19d1205
ZW
5614/* Generic instruction operand parser. This does no encoding and no
5615 semantic validation; it merely squirrels values away in the inst
5616 structure. Returns SUCCESS or FAIL depending on whether the
5617 specified grammar matched. */
5618static int
ca3f61f7 5619parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5620{
5621 unsigned const char *upat = pattern;
5622 char *backtrack_pos = 0;
5623 const char *backtrack_error = 0;
5624 int i, val, backtrack_index = 0;
5287ad62 5625 enum arm_reg_type rtype;
4962c51a 5626 parse_operand_result result;
c19d1205 5627
e07e6e58
NC
5628#define po_char_or_fail(chr) \
5629 do \
5630 { \
5631 if (skip_past_char (&str, chr) == FAIL) \
5632 goto bad_args; \
5633 } \
5634 while (0)
c19d1205 5635
e07e6e58
NC
5636#define po_reg_or_fail(regtype) \
5637 do \
dcbf9037 5638 { \
e07e6e58
NC
5639 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5640 & inst.operands[i].vectype); \
5641 if (val == FAIL) \
5642 { \
5643 first_error (_(reg_expected_msgs[regtype])); \
5644 goto failure; \
5645 } \
5646 inst.operands[i].reg = val; \
5647 inst.operands[i].isreg = 1; \
5648 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5649 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5650 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5651 || rtype == REG_TYPE_VFD \
5652 || rtype == REG_TYPE_NQ); \
dcbf9037 5653 } \
e07e6e58
NC
5654 while (0)
5655
5656#define po_reg_or_goto(regtype, label) \
5657 do \
5658 { \
5659 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5660 & inst.operands[i].vectype); \
5661 if (val == FAIL) \
5662 goto label; \
dcbf9037 5663 \
e07e6e58
NC
5664 inst.operands[i].reg = val; \
5665 inst.operands[i].isreg = 1; \
5666 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5667 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5668 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5669 || rtype == REG_TYPE_VFD \
5670 || rtype == REG_TYPE_NQ); \
5671 } \
5672 while (0)
5673
5674#define po_imm_or_fail(min, max, popt) \
5675 do \
5676 { \
5677 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5678 goto failure; \
5679 inst.operands[i].imm = val; \
5680 } \
5681 while (0)
5682
5683#define po_scalar_or_goto(elsz, label) \
5684 do \
5685 { \
5686 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5687 if (val == FAIL) \
5688 goto label; \
5689 inst.operands[i].reg = val; \
5690 inst.operands[i].isscalar = 1; \
5691 } \
5692 while (0)
5693
5694#define po_misc_or_fail(expr) \
5695 do \
5696 { \
5697 if (expr) \
5698 goto failure; \
5699 } \
5700 while (0)
5701
5702#define po_misc_or_fail_no_backtrack(expr) \
5703 do \
5704 { \
5705 result = expr; \
5706 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5707 backtrack_pos = 0; \
5708 if (result != PARSE_OPERAND_SUCCESS) \
5709 goto failure; \
5710 } \
5711 while (0)
4962c51a 5712
c19d1205
ZW
5713 skip_whitespace (str);
5714
5715 for (i = 0; upat[i] != OP_stop; i++)
5716 {
5717 if (upat[i] >= OP_FIRST_OPTIONAL)
5718 {
5719 /* Remember where we are in case we need to backtrack. */
9c2799c2 5720 gas_assert (!backtrack_pos);
c19d1205
ZW
5721 backtrack_pos = str;
5722 backtrack_error = inst.error;
5723 backtrack_index = i;
5724 }
5725
b6702015 5726 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5727 po_char_or_fail (',');
5728
5729 switch (upat[i])
5730 {
5731 /* Registers */
5732 case OP_oRRnpc:
5733 case OP_RRnpc:
5734 case OP_oRR:
5735 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5736 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5737 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5738 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5739 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5740 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5741 case OP_oRND:
5742 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5743 case OP_RVC:
5744 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5745 break;
5746 /* Also accept generic coprocessor regs for unknown registers. */
5747 coproc_reg:
5748 po_reg_or_fail (REG_TYPE_CN);
5749 break;
c19d1205
ZW
5750 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5751 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5752 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5753 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5754 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5755 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5756 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5757 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5758 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5759 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5760 case OP_oRNQ:
5761 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5762 case OP_oRNDQ:
5763 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5764 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5765 case OP_oRNSDQ:
5766 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5767
5768 /* Neon scalar. Using an element size of 8 means that some invalid
5769 scalars are accepted here, so deal with those in later code. */
5770 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5771
5772 /* WARNING: We can expand to two operands here. This has the potential
5773 to totally confuse the backtracking mechanism! It will be OK at
5774 least as long as we don't try to use optional args as well,
5775 though. */
5776 case OP_NILO:
5777 {
5778 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5779 inst.operands[i].present = 1;
5287ad62
JB
5780 i++;
5781 skip_past_comma (&str);
5782 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5783 break;
5784 one_reg_only:
5785 /* Optional register operand was omitted. Unfortunately, it's in
5786 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5787 here (this is a bit grotty). */
5788 inst.operands[i] = inst.operands[i-1];
5789 inst.operands[i-1].present = 0;
5790 break;
5791 try_imm:
036dc3f7
PB
5792 /* There's a possibility of getting a 64-bit immediate here, so
5793 we need special handling. */
5794 if (parse_big_immediate (&str, i) == FAIL)
5795 {
5796 inst.error = _("immediate value is out of range");
5797 goto failure;
5798 }
5287ad62
JB
5799 }
5800 break;
5801
5802 case OP_RNDQ_I0:
5803 {
5804 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5805 break;
5806 try_imm0:
5807 po_imm_or_fail (0, 0, TRUE);
5808 }
5809 break;
5810
037e8744
JB
5811 case OP_RVSD_I0:
5812 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5813 break;
5814
5287ad62
JB
5815 case OP_RR_RNSC:
5816 {
5817 po_scalar_or_goto (8, try_rr);
5818 break;
5819 try_rr:
5820 po_reg_or_fail (REG_TYPE_RN);
5821 }
5822 break;
5823
037e8744
JB
5824 case OP_RNSDQ_RNSC:
5825 {
5826 po_scalar_or_goto (8, try_nsdq);
5827 break;
5828 try_nsdq:
5829 po_reg_or_fail (REG_TYPE_NSDQ);
5830 }
5831 break;
5832
5287ad62
JB
5833 case OP_RNDQ_RNSC:
5834 {
5835 po_scalar_or_goto (8, try_ndq);
5836 break;
5837 try_ndq:
5838 po_reg_or_fail (REG_TYPE_NDQ);
5839 }
5840 break;
5841
5842 case OP_RND_RNSC:
5843 {
5844 po_scalar_or_goto (8, try_vfd);
5845 break;
5846 try_vfd:
5847 po_reg_or_fail (REG_TYPE_VFD);
5848 }
5849 break;
5850
5851 case OP_VMOV:
5852 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5853 not careful then bad things might happen. */
5854 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5855 break;
5856
5857 case OP_RNDQ_IMVNb:
5858 {
5859 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5860 break;
5861 try_mvnimm:
5862 /* There's a possibility of getting a 64-bit immediate here, so
5863 we need special handling. */
5864 if (parse_big_immediate (&str, i) == FAIL)
5865 {
5866 inst.error = _("immediate value is out of range");
5867 goto failure;
5868 }
5869 }
5870 break;
5871
5872 case OP_RNDQ_I63b:
5873 {
5874 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5875 break;
5876 try_shimm:
5877 po_imm_or_fail (0, 63, TRUE);
5878 }
5879 break;
c19d1205
ZW
5880
5881 case OP_RRnpcb:
5882 po_char_or_fail ('[');
5883 po_reg_or_fail (REG_TYPE_RN);
5884 po_char_or_fail (']');
5885 break;
a737bd4d 5886
c19d1205 5887 case OP_RRw:
b6702015 5888 case OP_oRRw:
c19d1205
ZW
5889 po_reg_or_fail (REG_TYPE_RN);
5890 if (skip_past_char (&str, '!') == SUCCESS)
5891 inst.operands[i].writeback = 1;
5892 break;
5893
5894 /* Immediates */
5895 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5896 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5897 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5898 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5899 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5900 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5901 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5902 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5903 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5904 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5905 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5906 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5907
5908 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5909 case OP_oI7b:
5910 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5911 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5912 case OP_oI31b:
5913 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5914 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5915 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5916
5917 /* Immediate variants */
5918 case OP_oI255c:
5919 po_char_or_fail ('{');
5920 po_imm_or_fail (0, 255, TRUE);
5921 po_char_or_fail ('}');
5922 break;
5923
5924 case OP_I31w:
5925 /* The expression parser chokes on a trailing !, so we have
5926 to find it first and zap it. */
5927 {
5928 char *s = str;
5929 while (*s && *s != ',')
5930 s++;
5931 if (s[-1] == '!')
5932 {
5933 s[-1] = '\0';
5934 inst.operands[i].writeback = 1;
5935 }
5936 po_imm_or_fail (0, 31, TRUE);
5937 if (str == s - 1)
5938 str = s;
5939 }
5940 break;
5941
5942 /* Expressions */
5943 case OP_EXPi: EXPi:
5944 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5945 GE_OPT_PREFIX));
5946 break;
5947
5948 case OP_EXP:
5949 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5950 GE_NO_PREFIX));
5951 break;
5952
5953 case OP_EXPr: EXPr:
5954 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5955 GE_NO_PREFIX));
5956 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5957 {
c19d1205
ZW
5958 val = parse_reloc (&str);
5959 if (val == -1)
5960 {
5961 inst.error = _("unrecognized relocation suffix");
5962 goto failure;
5963 }
5964 else if (val != BFD_RELOC_UNUSED)
5965 {
5966 inst.operands[i].imm = val;
5967 inst.operands[i].hasreloc = 1;
5968 }
a737bd4d 5969 }
c19d1205 5970 break;
a737bd4d 5971
b6895b4f
PB
5972 /* Operand for MOVW or MOVT. */
5973 case OP_HALF:
5974 po_misc_or_fail (parse_half (&str));
5975 break;
5976
e07e6e58 5977 /* Register or expression. */
c19d1205
ZW
5978 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5979 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5980
e07e6e58 5981 /* Register or immediate. */
c19d1205
ZW
5982 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5983 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5984
c19d1205
ZW
5985 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5986 IF:
5987 if (!is_immediate_prefix (*str))
5988 goto bad_args;
5989 str++;
5990 val = parse_fpa_immediate (&str);
5991 if (val == FAIL)
5992 goto failure;
5993 /* FPA immediates are encoded as registers 8-15.
5994 parse_fpa_immediate has already applied the offset. */
5995 inst.operands[i].reg = val;
5996 inst.operands[i].isreg = 1;
5997 break;
09d92015 5998
2d447fca
JM
5999 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6000 I32z: po_imm_or_fail (0, 32, FALSE); break;
6001
e07e6e58 6002 /* Two kinds of register. */
c19d1205
ZW
6003 case OP_RIWR_RIWC:
6004 {
6005 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6006 if (!rege
6007 || (rege->type != REG_TYPE_MMXWR
6008 && rege->type != REG_TYPE_MMXWC
6009 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6010 {
6011 inst.error = _("iWMMXt data or control register expected");
6012 goto failure;
6013 }
6014 inst.operands[i].reg = rege->number;
6015 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6016 }
6017 break;
09d92015 6018
41adaa5c
JM
6019 case OP_RIWC_RIWG:
6020 {
6021 struct reg_entry *rege = arm_reg_parse_multi (&str);
6022 if (!rege
6023 || (rege->type != REG_TYPE_MMXWC
6024 && rege->type != REG_TYPE_MMXWCG))
6025 {
6026 inst.error = _("iWMMXt control register expected");
6027 goto failure;
6028 }
6029 inst.operands[i].reg = rege->number;
6030 inst.operands[i].isreg = 1;
6031 }
6032 break;
6033
c19d1205
ZW
6034 /* Misc */
6035 case OP_CPSF: val = parse_cps_flags (&str); break;
6036 case OP_ENDI: val = parse_endian_specifier (&str); break;
6037 case OP_oROR: val = parse_ror (&str); break;
6038 case OP_PSR: val = parse_psr (&str); break;
6039 case OP_COND: val = parse_cond (&str); break;
62b3e311 6040 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6041
037e8744
JB
6042 case OP_RVC_PSR:
6043 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6044 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6045 break;
6046 try_psr:
6047 val = parse_psr (&str);
6048 break;
6049
6050 case OP_APSR_RR:
6051 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6052 break;
6053 try_apsr:
6054 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6055 instruction). */
6056 if (strncasecmp (str, "APSR_", 5) == 0)
6057 {
6058 unsigned found = 0;
6059 str += 5;
6060 while (found < 15)
6061 switch (*str++)
6062 {
6063 case 'c': found = (found & 1) ? 16 : found | 1; break;
6064 case 'n': found = (found & 2) ? 16 : found | 2; break;
6065 case 'z': found = (found & 4) ? 16 : found | 4; break;
6066 case 'v': found = (found & 8) ? 16 : found | 8; break;
6067 default: found = 16;
6068 }
6069 if (found != 15)
6070 goto failure;
6071 inst.operands[i].isvec = 1;
6072 }
6073 else
6074 goto failure;
6075 break;
6076
92e90b6e
PB
6077 case OP_TB:
6078 po_misc_or_fail (parse_tb (&str));
6079 break;
6080
e07e6e58 6081 /* Register lists. */
c19d1205
ZW
6082 case OP_REGLST:
6083 val = parse_reg_list (&str);
6084 if (*str == '^')
6085 {
6086 inst.operands[1].writeback = 1;
6087 str++;
6088 }
6089 break;
09d92015 6090
c19d1205 6091 case OP_VRSLST:
5287ad62 6092 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6093 break;
09d92015 6094
c19d1205 6095 case OP_VRDLST:
5287ad62 6096 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6097 break;
a737bd4d 6098
037e8744
JB
6099 case OP_VRSDLST:
6100 /* Allow Q registers too. */
6101 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6102 REGLIST_NEON_D);
6103 if (val == FAIL)
6104 {
6105 inst.error = NULL;
6106 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6107 REGLIST_VFP_S);
6108 inst.operands[i].issingle = 1;
6109 }
6110 break;
6111
5287ad62
JB
6112 case OP_NRDLST:
6113 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6114 REGLIST_NEON_D);
6115 break;
6116
6117 case OP_NSTRLST:
dcbf9037
JB
6118 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6119 &inst.operands[i].vectype);
5287ad62
JB
6120 break;
6121
c19d1205
ZW
6122 /* Addressing modes */
6123 case OP_ADDR:
6124 po_misc_or_fail (parse_address (&str, i));
6125 break;
09d92015 6126
4962c51a
MS
6127 case OP_ADDRGLDR:
6128 po_misc_or_fail_no_backtrack (
6129 parse_address_group_reloc (&str, i, GROUP_LDR));
6130 break;
6131
6132 case OP_ADDRGLDRS:
6133 po_misc_or_fail_no_backtrack (
6134 parse_address_group_reloc (&str, i, GROUP_LDRS));
6135 break;
6136
6137 case OP_ADDRGLDC:
6138 po_misc_or_fail_no_backtrack (
6139 parse_address_group_reloc (&str, i, GROUP_LDC));
6140 break;
6141
c19d1205
ZW
6142 case OP_SH:
6143 po_misc_or_fail (parse_shifter_operand (&str, i));
6144 break;
09d92015 6145
4962c51a
MS
6146 case OP_SHG:
6147 po_misc_or_fail_no_backtrack (
6148 parse_shifter_operand_group_reloc (&str, i));
6149 break;
6150
c19d1205
ZW
6151 case OP_oSHll:
6152 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6153 break;
09d92015 6154
c19d1205
ZW
6155 case OP_oSHar:
6156 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6157 break;
09d92015 6158
c19d1205
ZW
6159 case OP_oSHllar:
6160 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6161 break;
09d92015 6162
c19d1205 6163 default:
bd3ba5d1 6164 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6165 }
09d92015 6166
c19d1205
ZW
6167 /* Various value-based sanity checks and shared operations. We
6168 do not signal immediate failures for the register constraints;
6169 this allows a syntax error to take precedence. */
6170 switch (upat[i])
6171 {
6172 case OP_oRRnpc:
6173 case OP_RRnpc:
6174 case OP_RRnpcb:
6175 case OP_RRw:
b6702015 6176 case OP_oRRw:
c19d1205
ZW
6177 case OP_RRnpc_I0:
6178 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6179 inst.error = BAD_PC;
6180 break;
09d92015 6181
c19d1205
ZW
6182 case OP_CPSF:
6183 case OP_ENDI:
6184 case OP_oROR:
6185 case OP_PSR:
037e8744 6186 case OP_RVC_PSR:
c19d1205 6187 case OP_COND:
62b3e311 6188 case OP_oBARRIER:
c19d1205
ZW
6189 case OP_REGLST:
6190 case OP_VRSLST:
6191 case OP_VRDLST:
037e8744 6192 case OP_VRSDLST:
5287ad62
JB
6193 case OP_NRDLST:
6194 case OP_NSTRLST:
c19d1205
ZW
6195 if (val == FAIL)
6196 goto failure;
6197 inst.operands[i].imm = val;
6198 break;
a737bd4d 6199
c19d1205
ZW
6200 default:
6201 break;
6202 }
09d92015 6203
c19d1205
ZW
6204 /* If we get here, this operand was successfully parsed. */
6205 inst.operands[i].present = 1;
6206 continue;
09d92015 6207
c19d1205 6208 bad_args:
09d92015 6209 inst.error = BAD_ARGS;
c19d1205
ZW
6210
6211 failure:
6212 if (!backtrack_pos)
d252fdde
PB
6213 {
6214 /* The parse routine should already have set inst.error, but set a
5f4273c7 6215 default here just in case. */
d252fdde
PB
6216 if (!inst.error)
6217 inst.error = _("syntax error");
6218 return FAIL;
6219 }
c19d1205
ZW
6220
6221 /* Do not backtrack over a trailing optional argument that
6222 absorbed some text. We will only fail again, with the
6223 'garbage following instruction' error message, which is
6224 probably less helpful than the current one. */
6225 if (backtrack_index == i && backtrack_pos != str
6226 && upat[i+1] == OP_stop)
d252fdde
PB
6227 {
6228 if (!inst.error)
6229 inst.error = _("syntax error");
6230 return FAIL;
6231 }
c19d1205
ZW
6232
6233 /* Try again, skipping the optional argument at backtrack_pos. */
6234 str = backtrack_pos;
6235 inst.error = backtrack_error;
6236 inst.operands[backtrack_index].present = 0;
6237 i = backtrack_index;
6238 backtrack_pos = 0;
09d92015 6239 }
09d92015 6240
c19d1205
ZW
6241 /* Check that we have parsed all the arguments. */
6242 if (*str != '\0' && !inst.error)
6243 inst.error = _("garbage following instruction");
09d92015 6244
c19d1205 6245 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6246}
6247
c19d1205
ZW
6248#undef po_char_or_fail
6249#undef po_reg_or_fail
6250#undef po_reg_or_goto
6251#undef po_imm_or_fail
5287ad62 6252#undef po_scalar_or_fail
e07e6e58 6253
c19d1205 6254/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6255#define constraint(expr, err) \
6256 do \
c19d1205 6257 { \
e07e6e58
NC
6258 if (expr) \
6259 { \
6260 inst.error = err; \
6261 return; \
6262 } \
c19d1205 6263 } \
e07e6e58 6264 while (0)
c19d1205 6265
fdfde340
JM
6266/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6267 instructions are unpredictable if these registers are used. This
6268 is the BadReg predicate in ARM's Thumb-2 documentation. */
6269#define reject_bad_reg(reg) \
6270 do \
6271 if (reg == REG_SP || reg == REG_PC) \
6272 { \
6273 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6274 return; \
6275 } \
6276 while (0)
6277
94206790
MM
6278/* If REG is R13 (the stack pointer), warn that its use is
6279 deprecated. */
6280#define warn_deprecated_sp(reg) \
6281 do \
6282 if (warn_on_deprecated && reg == REG_SP) \
6283 as_warn (_("use of r13 is deprecated")); \
6284 while (0)
6285
c19d1205
ZW
6286/* Functions for operand encoding. ARM, then Thumb. */
6287
6288#define rotate_left(v, n) (v << n | v >> (32 - n))
6289
6290/* If VAL can be encoded in the immediate field of an ARM instruction,
6291 return the encoded form. Otherwise, return FAIL. */
6292
6293static unsigned int
6294encode_arm_immediate (unsigned int val)
09d92015 6295{
c19d1205
ZW
6296 unsigned int a, i;
6297
6298 for (i = 0; i < 32; i += 2)
6299 if ((a = rotate_left (val, i)) <= 0xff)
6300 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6301
6302 return FAIL;
09d92015
MM
6303}
6304
c19d1205
ZW
6305/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6306 return the encoded form. Otherwise, return FAIL. */
6307static unsigned int
6308encode_thumb32_immediate (unsigned int val)
09d92015 6309{
c19d1205 6310 unsigned int a, i;
09d92015 6311
9c3c69f2 6312 if (val <= 0xff)
c19d1205 6313 return val;
a737bd4d 6314
9c3c69f2 6315 for (i = 1; i <= 24; i++)
09d92015 6316 {
9c3c69f2
PB
6317 a = val >> i;
6318 if ((val & ~(0xff << i)) == 0)
6319 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6320 }
a737bd4d 6321
c19d1205
ZW
6322 a = val & 0xff;
6323 if (val == ((a << 16) | a))
6324 return 0x100 | a;
6325 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6326 return 0x300 | a;
09d92015 6327
c19d1205
ZW
6328 a = val & 0xff00;
6329 if (val == ((a << 16) | a))
6330 return 0x200 | (a >> 8);
a737bd4d 6331
c19d1205 6332 return FAIL;
09d92015 6333}
5287ad62 6334/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6335
6336static void
5287ad62
JB
6337encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6338{
6339 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6340 && reg > 15)
6341 {
b1cc4aeb 6342 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6343 {
6344 if (thumb_mode)
6345 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6346 fpu_vfp_ext_d32);
5287ad62
JB
6347 else
6348 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6349 fpu_vfp_ext_d32);
5287ad62
JB
6350 }
6351 else
6352 {
dcbf9037 6353 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6354 return;
6355 }
6356 }
6357
c19d1205 6358 switch (pos)
09d92015 6359 {
c19d1205
ZW
6360 case VFP_REG_Sd:
6361 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6362 break;
6363
6364 case VFP_REG_Sn:
6365 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6366 break;
6367
6368 case VFP_REG_Sm:
6369 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6370 break;
6371
5287ad62
JB
6372 case VFP_REG_Dd:
6373 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6374 break;
5f4273c7 6375
5287ad62
JB
6376 case VFP_REG_Dn:
6377 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6378 break;
5f4273c7 6379
5287ad62
JB
6380 case VFP_REG_Dm:
6381 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6382 break;
6383
c19d1205
ZW
6384 default:
6385 abort ();
09d92015 6386 }
09d92015
MM
6387}
6388
c19d1205 6389/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6390 if any, is handled by md_apply_fix. */
09d92015 6391static void
c19d1205 6392encode_arm_shift (int i)
09d92015 6393{
c19d1205
ZW
6394 if (inst.operands[i].shift_kind == SHIFT_RRX)
6395 inst.instruction |= SHIFT_ROR << 5;
6396 else
09d92015 6397 {
c19d1205
ZW
6398 inst.instruction |= inst.operands[i].shift_kind << 5;
6399 if (inst.operands[i].immisreg)
6400 {
6401 inst.instruction |= SHIFT_BY_REG;
6402 inst.instruction |= inst.operands[i].imm << 8;
6403 }
6404 else
6405 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6406 }
c19d1205 6407}
09d92015 6408
c19d1205
ZW
6409static void
6410encode_arm_shifter_operand (int i)
6411{
6412 if (inst.operands[i].isreg)
09d92015 6413 {
c19d1205
ZW
6414 inst.instruction |= inst.operands[i].reg;
6415 encode_arm_shift (i);
09d92015 6416 }
c19d1205
ZW
6417 else
6418 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6419}
6420
c19d1205 6421/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6422static void
c19d1205 6423encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6424{
9c2799c2 6425 gas_assert (inst.operands[i].isreg);
c19d1205 6426 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6427
c19d1205 6428 if (inst.operands[i].preind)
09d92015 6429 {
c19d1205
ZW
6430 if (is_t)
6431 {
6432 inst.error = _("instruction does not accept preindexed addressing");
6433 return;
6434 }
6435 inst.instruction |= PRE_INDEX;
6436 if (inst.operands[i].writeback)
6437 inst.instruction |= WRITE_BACK;
09d92015 6438
c19d1205
ZW
6439 }
6440 else if (inst.operands[i].postind)
6441 {
9c2799c2 6442 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6443 if (is_t)
6444 inst.instruction |= WRITE_BACK;
6445 }
6446 else /* unindexed - only for coprocessor */
09d92015 6447 {
c19d1205 6448 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6449 return;
6450 }
6451
c19d1205
ZW
6452 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6453 && (((inst.instruction & 0x000f0000) >> 16)
6454 == ((inst.instruction & 0x0000f000) >> 12)))
6455 as_warn ((inst.instruction & LOAD_BIT)
6456 ? _("destination register same as write-back base")
6457 : _("source register same as write-back base"));
09d92015
MM
6458}
6459
c19d1205
ZW
6460/* inst.operands[i] was set up by parse_address. Encode it into an
6461 ARM-format mode 2 load or store instruction. If is_t is true,
6462 reject forms that cannot be used with a T instruction (i.e. not
6463 post-indexed). */
a737bd4d 6464static void
c19d1205 6465encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6466{
c19d1205 6467 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6468
c19d1205 6469 if (inst.operands[i].immisreg)
09d92015 6470 {
c19d1205
ZW
6471 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6472 inst.instruction |= inst.operands[i].imm;
6473 if (!inst.operands[i].negative)
6474 inst.instruction |= INDEX_UP;
6475 if (inst.operands[i].shifted)
6476 {
6477 if (inst.operands[i].shift_kind == SHIFT_RRX)
6478 inst.instruction |= SHIFT_ROR << 5;
6479 else
6480 {
6481 inst.instruction |= inst.operands[i].shift_kind << 5;
6482 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6483 }
6484 }
09d92015 6485 }
c19d1205 6486 else /* immediate offset in inst.reloc */
09d92015 6487 {
c19d1205
ZW
6488 if (inst.reloc.type == BFD_RELOC_UNUSED)
6489 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6490 }
09d92015
MM
6491}
6492
c19d1205
ZW
6493/* inst.operands[i] was set up by parse_address. Encode it into an
6494 ARM-format mode 3 load or store instruction. Reject forms that
6495 cannot be used with such instructions. If is_t is true, reject
6496 forms that cannot be used with a T instruction (i.e. not
6497 post-indexed). */
6498static void
6499encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6500{
c19d1205 6501 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6502 {
c19d1205
ZW
6503 inst.error = _("instruction does not accept scaled register index");
6504 return;
09d92015 6505 }
a737bd4d 6506
c19d1205 6507 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6508
c19d1205
ZW
6509 if (inst.operands[i].immisreg)
6510 {
6511 inst.instruction |= inst.operands[i].imm;
6512 if (!inst.operands[i].negative)
6513 inst.instruction |= INDEX_UP;
6514 }
6515 else /* immediate offset in inst.reloc */
6516 {
6517 inst.instruction |= HWOFFSET_IMM;
6518 if (inst.reloc.type == BFD_RELOC_UNUSED)
6519 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6520 }
a737bd4d
NC
6521}
6522
c19d1205
ZW
6523/* inst.operands[i] was set up by parse_address. Encode it into an
6524 ARM-format instruction. Reject all forms which cannot be encoded
6525 into a coprocessor load/store instruction. If wb_ok is false,
6526 reject use of writeback; if unind_ok is false, reject use of
6527 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6528 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6529 (in which case it is preserved). */
09d92015 6530
c19d1205
ZW
6531static int
6532encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6533{
c19d1205 6534 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6535
9c2799c2 6536 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6537
c19d1205 6538 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6539 {
9c2799c2 6540 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6541 if (!unind_ok)
6542 {
6543 inst.error = _("instruction does not support unindexed addressing");
6544 return FAIL;
6545 }
6546 inst.instruction |= inst.operands[i].imm;
6547 inst.instruction |= INDEX_UP;
6548 return SUCCESS;
09d92015 6549 }
a737bd4d 6550
c19d1205
ZW
6551 if (inst.operands[i].preind)
6552 inst.instruction |= PRE_INDEX;
a737bd4d 6553
c19d1205 6554 if (inst.operands[i].writeback)
09d92015 6555 {
c19d1205
ZW
6556 if (inst.operands[i].reg == REG_PC)
6557 {
6558 inst.error = _("pc may not be used with write-back");
6559 return FAIL;
6560 }
6561 if (!wb_ok)
6562 {
6563 inst.error = _("instruction does not support writeback");
6564 return FAIL;
6565 }
6566 inst.instruction |= WRITE_BACK;
09d92015 6567 }
a737bd4d 6568
c19d1205
ZW
6569 if (reloc_override)
6570 inst.reloc.type = reloc_override;
4962c51a
MS
6571 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6572 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6573 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6574 {
6575 if (thumb_mode)
6576 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6577 else
6578 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6579 }
6580
c19d1205
ZW
6581 return SUCCESS;
6582}
a737bd4d 6583
c19d1205
ZW
6584/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6585 Determine whether it can be performed with a move instruction; if
6586 it can, convert inst.instruction to that move instruction and
6587 return 1; if it can't, convert inst.instruction to a literal-pool
6588 load and return 0. If this is not a valid thing to do in the
6589 current context, set inst.error and return 1.
a737bd4d 6590
c19d1205
ZW
6591 inst.operands[i] describes the destination register. */
6592
6593static int
6594move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6595{
53365c0d
PB
6596 unsigned long tbit;
6597
6598 if (thumb_p)
6599 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6600 else
6601 tbit = LOAD_BIT;
6602
6603 if ((inst.instruction & tbit) == 0)
09d92015 6604 {
c19d1205
ZW
6605 inst.error = _("invalid pseudo operation");
6606 return 1;
09d92015 6607 }
c19d1205 6608 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6609 {
6610 inst.error = _("constant expression expected");
c19d1205 6611 return 1;
09d92015 6612 }
c19d1205 6613 if (inst.reloc.exp.X_op == O_constant)
09d92015 6614 {
c19d1205
ZW
6615 if (thumb_p)
6616 {
53365c0d 6617 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6618 {
6619 /* This can be done with a mov(1) instruction. */
6620 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6621 inst.instruction |= inst.reloc.exp.X_add_number;
6622 return 1;
6623 }
6624 }
6625 else
6626 {
6627 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6628 if (value != FAIL)
6629 {
6630 /* This can be done with a mov instruction. */
6631 inst.instruction &= LITERAL_MASK;
6632 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6633 inst.instruction |= value & 0xfff;
6634 return 1;
6635 }
09d92015 6636
c19d1205
ZW
6637 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6638 if (value != FAIL)
6639 {
6640 /* This can be done with a mvn instruction. */
6641 inst.instruction &= LITERAL_MASK;
6642 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6643 inst.instruction |= value & 0xfff;
6644 return 1;
6645 }
6646 }
09d92015
MM
6647 }
6648
c19d1205
ZW
6649 if (add_to_lit_pool () == FAIL)
6650 {
6651 inst.error = _("literal pool insertion failed");
6652 return 1;
6653 }
6654 inst.operands[1].reg = REG_PC;
6655 inst.operands[1].isreg = 1;
6656 inst.operands[1].preind = 1;
6657 inst.reloc.pc_rel = 1;
6658 inst.reloc.type = (thumb_p
6659 ? BFD_RELOC_ARM_THUMB_OFFSET
6660 : (mode_3
6661 ? BFD_RELOC_ARM_HWLITERAL
6662 : BFD_RELOC_ARM_LITERAL));
6663 return 0;
09d92015
MM
6664}
6665
5f4273c7 6666/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6667 First some generics; their names are taken from the conventional
6668 bit positions for register arguments in ARM format instructions. */
09d92015 6669
a737bd4d 6670static void
c19d1205 6671do_noargs (void)
09d92015 6672{
c19d1205 6673}
a737bd4d 6674
c19d1205
ZW
6675static void
6676do_rd (void)
6677{
6678 inst.instruction |= inst.operands[0].reg << 12;
6679}
a737bd4d 6680
c19d1205
ZW
6681static void
6682do_rd_rm (void)
6683{
6684 inst.instruction |= inst.operands[0].reg << 12;
6685 inst.instruction |= inst.operands[1].reg;
6686}
09d92015 6687
c19d1205
ZW
6688static void
6689do_rd_rn (void)
6690{
6691 inst.instruction |= inst.operands[0].reg << 12;
6692 inst.instruction |= inst.operands[1].reg << 16;
6693}
a737bd4d 6694
c19d1205
ZW
6695static void
6696do_rn_rd (void)
6697{
6698 inst.instruction |= inst.operands[0].reg << 16;
6699 inst.instruction |= inst.operands[1].reg << 12;
6700}
09d92015 6701
c19d1205
ZW
6702static void
6703do_rd_rm_rn (void)
6704{
9a64e435 6705 unsigned Rn = inst.operands[2].reg;
708587a4 6706 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6707 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6708 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6709 _("Rn must not overlap other operands"));
c19d1205
ZW
6710 inst.instruction |= inst.operands[0].reg << 12;
6711 inst.instruction |= inst.operands[1].reg;
9a64e435 6712 inst.instruction |= Rn << 16;
c19d1205 6713}
09d92015 6714
c19d1205
ZW
6715static void
6716do_rd_rn_rm (void)
6717{
6718 inst.instruction |= inst.operands[0].reg << 12;
6719 inst.instruction |= inst.operands[1].reg << 16;
6720 inst.instruction |= inst.operands[2].reg;
6721}
a737bd4d 6722
c19d1205
ZW
6723static void
6724do_rm_rd_rn (void)
6725{
6726 inst.instruction |= inst.operands[0].reg;
6727 inst.instruction |= inst.operands[1].reg << 12;
6728 inst.instruction |= inst.operands[2].reg << 16;
6729}
09d92015 6730
c19d1205
ZW
6731static void
6732do_imm0 (void)
6733{
6734 inst.instruction |= inst.operands[0].imm;
6735}
09d92015 6736
c19d1205
ZW
6737static void
6738do_rd_cpaddr (void)
6739{
6740 inst.instruction |= inst.operands[0].reg << 12;
6741 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6742}
a737bd4d 6743
c19d1205
ZW
6744/* ARM instructions, in alphabetical order by function name (except
6745 that wrapper functions appear immediately after the function they
6746 wrap). */
09d92015 6747
c19d1205
ZW
6748/* This is a pseudo-op of the form "adr rd, label" to be converted
6749 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6750
6751static void
c19d1205 6752do_adr (void)
09d92015 6753{
c19d1205 6754 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6755
c19d1205
ZW
6756 /* Frag hacking will turn this into a sub instruction if the offset turns
6757 out to be negative. */
6758 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6759 inst.reloc.pc_rel = 1;
2fc8bdac 6760 inst.reloc.exp.X_add_number -= 8;
c19d1205 6761}
b99bd4ef 6762
c19d1205
ZW
6763/* This is a pseudo-op of the form "adrl rd, label" to be converted
6764 into a relative address of the form:
6765 add rd, pc, #low(label-.-8)"
6766 add rd, rd, #high(label-.-8)" */
b99bd4ef 6767
c19d1205
ZW
6768static void
6769do_adrl (void)
6770{
6771 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6772
c19d1205
ZW
6773 /* Frag hacking will turn this into a sub instruction if the offset turns
6774 out to be negative. */
6775 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6776 inst.reloc.pc_rel = 1;
6777 inst.size = INSN_SIZE * 2;
2fc8bdac 6778 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6779}
6780
b99bd4ef 6781static void
c19d1205 6782do_arit (void)
b99bd4ef 6783{
c19d1205
ZW
6784 if (!inst.operands[1].present)
6785 inst.operands[1].reg = inst.operands[0].reg;
6786 inst.instruction |= inst.operands[0].reg << 12;
6787 inst.instruction |= inst.operands[1].reg << 16;
6788 encode_arm_shifter_operand (2);
6789}
b99bd4ef 6790
62b3e311
PB
6791static void
6792do_barrier (void)
6793{
6794 if (inst.operands[0].present)
6795 {
6796 constraint ((inst.instruction & 0xf0) != 0x40
6797 && inst.operands[0].imm != 0xf,
bd3ba5d1 6798 _("bad barrier type"));
62b3e311
PB
6799 inst.instruction |= inst.operands[0].imm;
6800 }
6801 else
6802 inst.instruction |= 0xf;
6803}
6804
c19d1205
ZW
6805static void
6806do_bfc (void)
6807{
6808 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6809 constraint (msb > 32, _("bit-field extends past end of register"));
6810 /* The instruction encoding stores the LSB and MSB,
6811 not the LSB and width. */
6812 inst.instruction |= inst.operands[0].reg << 12;
6813 inst.instruction |= inst.operands[1].imm << 7;
6814 inst.instruction |= (msb - 1) << 16;
6815}
b99bd4ef 6816
c19d1205
ZW
6817static void
6818do_bfi (void)
6819{
6820 unsigned int msb;
b99bd4ef 6821
c19d1205
ZW
6822 /* #0 in second position is alternative syntax for bfc, which is
6823 the same instruction but with REG_PC in the Rm field. */
6824 if (!inst.operands[1].isreg)
6825 inst.operands[1].reg = REG_PC;
b99bd4ef 6826
c19d1205
ZW
6827 msb = inst.operands[2].imm + inst.operands[3].imm;
6828 constraint (msb > 32, _("bit-field extends past end of register"));
6829 /* The instruction encoding stores the LSB and MSB,
6830 not the LSB and width. */
6831 inst.instruction |= inst.operands[0].reg << 12;
6832 inst.instruction |= inst.operands[1].reg;
6833 inst.instruction |= inst.operands[2].imm << 7;
6834 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6835}
6836
b99bd4ef 6837static void
c19d1205 6838do_bfx (void)
b99bd4ef 6839{
c19d1205
ZW
6840 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6841 _("bit-field extends past end of register"));
6842 inst.instruction |= inst.operands[0].reg << 12;
6843 inst.instruction |= inst.operands[1].reg;
6844 inst.instruction |= inst.operands[2].imm << 7;
6845 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6846}
09d92015 6847
c19d1205
ZW
6848/* ARM V5 breakpoint instruction (argument parse)
6849 BKPT <16 bit unsigned immediate>
6850 Instruction is not conditional.
6851 The bit pattern given in insns[] has the COND_ALWAYS condition,
6852 and it is an error if the caller tried to override that. */
b99bd4ef 6853
c19d1205
ZW
6854static void
6855do_bkpt (void)
6856{
6857 /* Top 12 of 16 bits to bits 19:8. */
6858 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6859
c19d1205
ZW
6860 /* Bottom 4 of 16 bits to bits 3:0. */
6861 inst.instruction |= inst.operands[0].imm & 0xf;
6862}
09d92015 6863
c19d1205
ZW
6864static void
6865encode_branch (int default_reloc)
6866{
6867 if (inst.operands[0].hasreloc)
6868 {
6869 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6870 _("the only suffix valid here is '(plt)'"));
267bf995 6871 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6872 }
b99bd4ef 6873 else
c19d1205
ZW
6874 {
6875 inst.reloc.type = default_reloc;
c19d1205 6876 }
2fc8bdac 6877 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6878}
6879
b99bd4ef 6880static void
c19d1205 6881do_branch (void)
b99bd4ef 6882{
39b41c9c
PB
6883#ifdef OBJ_ELF
6884 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6885 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6886 else
6887#endif
6888 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6889}
6890
6891static void
6892do_bl (void)
6893{
6894#ifdef OBJ_ELF
6895 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6896 {
6897 if (inst.cond == COND_ALWAYS)
6898 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6899 else
6900 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6901 }
6902 else
6903#endif
6904 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6905}
b99bd4ef 6906
c19d1205
ZW
6907/* ARM V5 branch-link-exchange instruction (argument parse)
6908 BLX <target_addr> ie BLX(1)
6909 BLX{<condition>} <Rm> ie BLX(2)
6910 Unfortunately, there are two different opcodes for this mnemonic.
6911 So, the insns[].value is not used, and the code here zaps values
6912 into inst.instruction.
6913 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6914
c19d1205
ZW
6915static void
6916do_blx (void)
6917{
6918 if (inst.operands[0].isreg)
b99bd4ef 6919 {
c19d1205
ZW
6920 /* Arg is a register; the opcode provided by insns[] is correct.
6921 It is not illegal to do "blx pc", just useless. */
6922 if (inst.operands[0].reg == REG_PC)
6923 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6924
c19d1205
ZW
6925 inst.instruction |= inst.operands[0].reg;
6926 }
6927 else
b99bd4ef 6928 {
c19d1205 6929 /* Arg is an address; this instruction cannot be executed
267bf995
RR
6930 conditionally, and the opcode must be adjusted.
6931 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
6932 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 6933 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6934 inst.instruction = 0xfa000000;
267bf995 6935 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6936 }
c19d1205
ZW
6937}
6938
6939static void
6940do_bx (void)
6941{
845b51d6
PB
6942 bfd_boolean want_reloc;
6943
c19d1205
ZW
6944 if (inst.operands[0].reg == REG_PC)
6945 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6946
c19d1205 6947 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6948 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6949 it is for ARMv4t or earlier. */
6950 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6951 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6952 want_reloc = TRUE;
6953
5ad34203 6954#ifdef OBJ_ELF
845b51d6 6955 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6956#endif
584206db 6957 want_reloc = FALSE;
845b51d6
PB
6958
6959 if (want_reloc)
6960 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6961}
6962
c19d1205
ZW
6963
6964/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6965
6966static void
c19d1205 6967do_bxj (void)
a737bd4d 6968{
c19d1205
ZW
6969 if (inst.operands[0].reg == REG_PC)
6970 as_tsktsk (_("use of r15 in bxj is not really useful"));
6971
6972 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6973}
6974
c19d1205
ZW
6975/* Co-processor data operation:
6976 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6977 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6978static void
6979do_cdp (void)
6980{
6981 inst.instruction |= inst.operands[0].reg << 8;
6982 inst.instruction |= inst.operands[1].imm << 20;
6983 inst.instruction |= inst.operands[2].reg << 12;
6984 inst.instruction |= inst.operands[3].reg << 16;
6985 inst.instruction |= inst.operands[4].reg;
6986 inst.instruction |= inst.operands[5].imm << 5;
6987}
a737bd4d
NC
6988
6989static void
c19d1205 6990do_cmp (void)
a737bd4d 6991{
c19d1205
ZW
6992 inst.instruction |= inst.operands[0].reg << 16;
6993 encode_arm_shifter_operand (1);
a737bd4d
NC
6994}
6995
c19d1205
ZW
6996/* Transfer between coprocessor and ARM registers.
6997 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6998 MRC2
6999 MCR{cond}
7000 MCR2
7001
7002 No special properties. */
09d92015
MM
7003
7004static void
c19d1205 7005do_co_reg (void)
09d92015 7006{
fdfde340
JM
7007 unsigned Rd;
7008
7009 Rd = inst.operands[2].reg;
7010 if (thumb_mode)
7011 {
7012 if (inst.instruction == 0xee000010
7013 || inst.instruction == 0xfe000010)
7014 /* MCR, MCR2 */
7015 reject_bad_reg (Rd);
7016 else
7017 /* MRC, MRC2 */
7018 constraint (Rd == REG_SP, BAD_SP);
7019 }
7020 else
7021 {
7022 /* MCR */
7023 if (inst.instruction == 0xe000010)
7024 constraint (Rd == REG_PC, BAD_PC);
7025 }
7026
7027
c19d1205
ZW
7028 inst.instruction |= inst.operands[0].reg << 8;
7029 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7030 inst.instruction |= Rd << 12;
c19d1205
ZW
7031 inst.instruction |= inst.operands[3].reg << 16;
7032 inst.instruction |= inst.operands[4].reg;
7033 inst.instruction |= inst.operands[5].imm << 5;
7034}
09d92015 7035
c19d1205
ZW
7036/* Transfer between coprocessor register and pair of ARM registers.
7037 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7038 MCRR2
7039 MRRC{cond}
7040 MRRC2
b99bd4ef 7041
c19d1205 7042 Two XScale instructions are special cases of these:
09d92015 7043
c19d1205
ZW
7044 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7045 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7046
5f4273c7 7047 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7048
c19d1205
ZW
7049static void
7050do_co_reg2c (void)
7051{
fdfde340
JM
7052 unsigned Rd, Rn;
7053
7054 Rd = inst.operands[2].reg;
7055 Rn = inst.operands[3].reg;
7056
7057 if (thumb_mode)
7058 {
7059 reject_bad_reg (Rd);
7060 reject_bad_reg (Rn);
7061 }
7062 else
7063 {
7064 constraint (Rd == REG_PC, BAD_PC);
7065 constraint (Rn == REG_PC, BAD_PC);
7066 }
7067
c19d1205
ZW
7068 inst.instruction |= inst.operands[0].reg << 8;
7069 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7070 inst.instruction |= Rd << 12;
7071 inst.instruction |= Rn << 16;
c19d1205 7072 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7073}
7074
c19d1205
ZW
7075static void
7076do_cpsi (void)
7077{
7078 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7079 if (inst.operands[1].present)
7080 {
7081 inst.instruction |= CPSI_MMOD;
7082 inst.instruction |= inst.operands[1].imm;
7083 }
c19d1205 7084}
b99bd4ef 7085
62b3e311
PB
7086static void
7087do_dbg (void)
7088{
7089 inst.instruction |= inst.operands[0].imm;
7090}
7091
b99bd4ef 7092static void
c19d1205 7093do_it (void)
b99bd4ef 7094{
c19d1205 7095 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7096 process it to do the validation as if in
7097 thumb mode, just in case the code gets
7098 assembled for thumb using the unified syntax. */
7099
c19d1205 7100 inst.size = 0;
e07e6e58
NC
7101 if (unified_syntax)
7102 {
7103 set_it_insn_type (IT_INSN);
7104 now_it.mask = (inst.instruction & 0xf) | 0x10;
7105 now_it.cc = inst.operands[0].imm;
7106 }
09d92015 7107}
b99bd4ef 7108
09d92015 7109static void
c19d1205 7110do_ldmstm (void)
ea6ef066 7111{
c19d1205
ZW
7112 int base_reg = inst.operands[0].reg;
7113 int range = inst.operands[1].imm;
ea6ef066 7114
c19d1205
ZW
7115 inst.instruction |= base_reg << 16;
7116 inst.instruction |= range;
ea6ef066 7117
c19d1205
ZW
7118 if (inst.operands[1].writeback)
7119 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7120
c19d1205 7121 if (inst.operands[0].writeback)
ea6ef066 7122 {
c19d1205
ZW
7123 inst.instruction |= WRITE_BACK;
7124 /* Check for unpredictable uses of writeback. */
7125 if (inst.instruction & LOAD_BIT)
09d92015 7126 {
c19d1205
ZW
7127 /* Not allowed in LDM type 2. */
7128 if ((inst.instruction & LDM_TYPE_2_OR_3)
7129 && ((range & (1 << REG_PC)) == 0))
7130 as_warn (_("writeback of base register is UNPREDICTABLE"));
7131 /* Only allowed if base reg not in list for other types. */
7132 else if (range & (1 << base_reg))
7133 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7134 }
7135 else /* STM. */
7136 {
7137 /* Not allowed for type 2. */
7138 if (inst.instruction & LDM_TYPE_2_OR_3)
7139 as_warn (_("writeback of base register is UNPREDICTABLE"));
7140 /* Only allowed if base reg not in list, or first in list. */
7141 else if ((range & (1 << base_reg))
7142 && (range & ((1 << base_reg) - 1)))
7143 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7144 }
ea6ef066 7145 }
a737bd4d
NC
7146}
7147
c19d1205
ZW
7148/* ARMv5TE load-consecutive (argument parse)
7149 Mode is like LDRH.
7150
7151 LDRccD R, mode
7152 STRccD R, mode. */
7153
a737bd4d 7154static void
c19d1205 7155do_ldrd (void)
a737bd4d 7156{
c19d1205
ZW
7157 constraint (inst.operands[0].reg % 2 != 0,
7158 _("first destination register must be even"));
7159 constraint (inst.operands[1].present
7160 && inst.operands[1].reg != inst.operands[0].reg + 1,
7161 _("can only load two consecutive registers"));
7162 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7163 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7164
c19d1205
ZW
7165 if (!inst.operands[1].present)
7166 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7167
c19d1205 7168 if (inst.instruction & LOAD_BIT)
a737bd4d 7169 {
c19d1205
ZW
7170 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7171 register and the first register written; we have to diagnose
7172 overlap between the base and the second register written here. */
ea6ef066 7173
c19d1205
ZW
7174 if (inst.operands[2].reg == inst.operands[1].reg
7175 && (inst.operands[2].writeback || inst.operands[2].postind))
7176 as_warn (_("base register written back, and overlaps "
7177 "second destination register"));
b05fe5cf 7178
c19d1205
ZW
7179 /* For an index-register load, the index register must not overlap the
7180 destination (even if not write-back). */
7181 else if (inst.operands[2].immisreg
ca3f61f7
NC
7182 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7183 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7184 as_warn (_("index register overlaps destination register"));
b05fe5cf 7185 }
c19d1205
ZW
7186
7187 inst.instruction |= inst.operands[0].reg << 12;
7188 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7189}
7190
7191static void
c19d1205 7192do_ldrex (void)
b05fe5cf 7193{
c19d1205
ZW
7194 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7195 || inst.operands[1].postind || inst.operands[1].writeback
7196 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7197 || inst.operands[1].negative
7198 /* This can arise if the programmer has written
7199 strex rN, rM, foo
7200 or if they have mistakenly used a register name as the last
7201 operand, eg:
7202 strex rN, rM, rX
7203 It is very difficult to distinguish between these two cases
7204 because "rX" might actually be a label. ie the register
7205 name has been occluded by a symbol of the same name. So we
7206 just generate a general 'bad addressing mode' type error
7207 message and leave it up to the programmer to discover the
7208 true cause and fix their mistake. */
7209 || (inst.operands[1].reg == REG_PC),
7210 BAD_ADDR_MODE);
b05fe5cf 7211
c19d1205
ZW
7212 constraint (inst.reloc.exp.X_op != O_constant
7213 || inst.reloc.exp.X_add_number != 0,
7214 _("offset must be zero in ARM encoding"));
b05fe5cf 7215
c19d1205
ZW
7216 inst.instruction |= inst.operands[0].reg << 12;
7217 inst.instruction |= inst.operands[1].reg << 16;
7218 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7219}
7220
7221static void
c19d1205 7222do_ldrexd (void)
b05fe5cf 7223{
c19d1205
ZW
7224 constraint (inst.operands[0].reg % 2 != 0,
7225 _("even register required"));
7226 constraint (inst.operands[1].present
7227 && inst.operands[1].reg != inst.operands[0].reg + 1,
7228 _("can only load two consecutive registers"));
7229 /* If op 1 were present and equal to PC, this function wouldn't
7230 have been called in the first place. */
7231 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7232
c19d1205
ZW
7233 inst.instruction |= inst.operands[0].reg << 12;
7234 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7235}
7236
7237static void
c19d1205 7238do_ldst (void)
b05fe5cf 7239{
c19d1205
ZW
7240 inst.instruction |= inst.operands[0].reg << 12;
7241 if (!inst.operands[1].isreg)
7242 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7243 return;
c19d1205 7244 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7245}
7246
7247static void
c19d1205 7248do_ldstt (void)
b05fe5cf 7249{
c19d1205
ZW
7250 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7251 reject [Rn,...]. */
7252 if (inst.operands[1].preind)
b05fe5cf 7253 {
bd3ba5d1
NC
7254 constraint (inst.reloc.exp.X_op != O_constant
7255 || inst.reloc.exp.X_add_number != 0,
c19d1205 7256 _("this instruction requires a post-indexed address"));
b05fe5cf 7257
c19d1205
ZW
7258 inst.operands[1].preind = 0;
7259 inst.operands[1].postind = 1;
7260 inst.operands[1].writeback = 1;
b05fe5cf 7261 }
c19d1205
ZW
7262 inst.instruction |= inst.operands[0].reg << 12;
7263 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7264}
b05fe5cf 7265
c19d1205 7266/* Halfword and signed-byte load/store operations. */
b05fe5cf 7267
c19d1205
ZW
7268static void
7269do_ldstv4 (void)
7270{
7271 inst.instruction |= inst.operands[0].reg << 12;
7272 if (!inst.operands[1].isreg)
7273 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7274 return;
c19d1205 7275 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7276}
7277
7278static void
c19d1205 7279do_ldsttv4 (void)
b05fe5cf 7280{
c19d1205
ZW
7281 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7282 reject [Rn,...]. */
7283 if (inst.operands[1].preind)
b05fe5cf 7284 {
bd3ba5d1
NC
7285 constraint (inst.reloc.exp.X_op != O_constant
7286 || inst.reloc.exp.X_add_number != 0,
c19d1205 7287 _("this instruction requires a post-indexed address"));
b05fe5cf 7288
c19d1205
ZW
7289 inst.operands[1].preind = 0;
7290 inst.operands[1].postind = 1;
7291 inst.operands[1].writeback = 1;
b05fe5cf 7292 }
c19d1205
ZW
7293 inst.instruction |= inst.operands[0].reg << 12;
7294 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7295}
b05fe5cf 7296
c19d1205
ZW
7297/* Co-processor register load/store.
7298 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7299static void
7300do_lstc (void)
7301{
7302 inst.instruction |= inst.operands[0].reg << 8;
7303 inst.instruction |= inst.operands[1].reg << 12;
7304 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7305}
7306
b05fe5cf 7307static void
c19d1205 7308do_mlas (void)
b05fe5cf 7309{
8fb9d7b9 7310 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7311 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7312 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7313 && !(inst.instruction & 0x00400000))
8fb9d7b9 7314 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7315
c19d1205
ZW
7316 inst.instruction |= inst.operands[0].reg << 16;
7317 inst.instruction |= inst.operands[1].reg;
7318 inst.instruction |= inst.operands[2].reg << 8;
7319 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7320}
b05fe5cf 7321
c19d1205
ZW
7322static void
7323do_mov (void)
7324{
7325 inst.instruction |= inst.operands[0].reg << 12;
7326 encode_arm_shifter_operand (1);
7327}
b05fe5cf 7328
c19d1205
ZW
7329/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7330static void
7331do_mov16 (void)
7332{
b6895b4f
PB
7333 bfd_vma imm;
7334 bfd_boolean top;
7335
7336 top = (inst.instruction & 0x00400000) != 0;
7337 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7338 _(":lower16: not allowed this instruction"));
7339 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7340 _(":upper16: not allowed instruction"));
c19d1205 7341 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7342 if (inst.reloc.type == BFD_RELOC_UNUSED)
7343 {
7344 imm = inst.reloc.exp.X_add_number;
7345 /* The value is in two pieces: 0:11, 16:19. */
7346 inst.instruction |= (imm & 0x00000fff);
7347 inst.instruction |= (imm & 0x0000f000) << 4;
7348 }
b05fe5cf 7349}
b99bd4ef 7350
037e8744
JB
7351static void do_vfp_nsyn_opcode (const char *);
7352
7353static int
7354do_vfp_nsyn_mrs (void)
7355{
7356 if (inst.operands[0].isvec)
7357 {
7358 if (inst.operands[1].reg != 1)
7359 first_error (_("operand 1 must be FPSCR"));
7360 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7361 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7362 do_vfp_nsyn_opcode ("fmstat");
7363 }
7364 else if (inst.operands[1].isvec)
7365 do_vfp_nsyn_opcode ("fmrx");
7366 else
7367 return FAIL;
5f4273c7 7368
037e8744
JB
7369 return SUCCESS;
7370}
7371
7372static int
7373do_vfp_nsyn_msr (void)
7374{
7375 if (inst.operands[0].isvec)
7376 do_vfp_nsyn_opcode ("fmxr");
7377 else
7378 return FAIL;
7379
7380 return SUCCESS;
7381}
7382
b99bd4ef 7383static void
c19d1205 7384do_mrs (void)
b99bd4ef 7385{
037e8744
JB
7386 if (do_vfp_nsyn_mrs () == SUCCESS)
7387 return;
7388
c19d1205
ZW
7389 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7390 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7391 != (PSR_c|PSR_f),
7392 _("'CPSR' or 'SPSR' expected"));
7393 inst.instruction |= inst.operands[0].reg << 12;
7394 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7395}
b99bd4ef 7396
c19d1205
ZW
7397/* Two possible forms:
7398 "{C|S}PSR_<field>, Rm",
7399 "{C|S}PSR_f, #expression". */
b99bd4ef 7400
c19d1205
ZW
7401static void
7402do_msr (void)
7403{
037e8744
JB
7404 if (do_vfp_nsyn_msr () == SUCCESS)
7405 return;
7406
c19d1205
ZW
7407 inst.instruction |= inst.operands[0].imm;
7408 if (inst.operands[1].isreg)
7409 inst.instruction |= inst.operands[1].reg;
7410 else
b99bd4ef 7411 {
c19d1205
ZW
7412 inst.instruction |= INST_IMMEDIATE;
7413 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7414 inst.reloc.pc_rel = 0;
b99bd4ef 7415 }
b99bd4ef
NC
7416}
7417
c19d1205
ZW
7418static void
7419do_mul (void)
a737bd4d 7420{
c19d1205
ZW
7421 if (!inst.operands[2].present)
7422 inst.operands[2].reg = inst.operands[0].reg;
7423 inst.instruction |= inst.operands[0].reg << 16;
7424 inst.instruction |= inst.operands[1].reg;
7425 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7426
8fb9d7b9
MS
7427 if (inst.operands[0].reg == inst.operands[1].reg
7428 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7429 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7430}
7431
c19d1205
ZW
7432/* Long Multiply Parser
7433 UMULL RdLo, RdHi, Rm, Rs
7434 SMULL RdLo, RdHi, Rm, Rs
7435 UMLAL RdLo, RdHi, Rm, Rs
7436 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7437
7438static void
c19d1205 7439do_mull (void)
b99bd4ef 7440{
c19d1205
ZW
7441 inst.instruction |= inst.operands[0].reg << 12;
7442 inst.instruction |= inst.operands[1].reg << 16;
7443 inst.instruction |= inst.operands[2].reg;
7444 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7445
682b27ad
PB
7446 /* rdhi and rdlo must be different. */
7447 if (inst.operands[0].reg == inst.operands[1].reg)
7448 as_tsktsk (_("rdhi and rdlo must be different"));
7449
7450 /* rdhi, rdlo and rm must all be different before armv6. */
7451 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7452 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7453 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7454 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7455}
b99bd4ef 7456
c19d1205
ZW
7457static void
7458do_nop (void)
7459{
e7495e45
NS
7460 if (inst.operands[0].present
7461 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7462 {
7463 /* Architectural NOP hints are CPSR sets with no bits selected. */
7464 inst.instruction &= 0xf0000000;
e7495e45
NS
7465 inst.instruction |= 0x0320f000;
7466 if (inst.operands[0].present)
7467 inst.instruction |= inst.operands[0].imm;
c19d1205 7468 }
b99bd4ef
NC
7469}
7470
c19d1205
ZW
7471/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7472 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7473 Condition defaults to COND_ALWAYS.
7474 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7475
7476static void
c19d1205 7477do_pkhbt (void)
b99bd4ef 7478{
c19d1205
ZW
7479 inst.instruction |= inst.operands[0].reg << 12;
7480 inst.instruction |= inst.operands[1].reg << 16;
7481 inst.instruction |= inst.operands[2].reg;
7482 if (inst.operands[3].present)
7483 encode_arm_shift (3);
7484}
b99bd4ef 7485
c19d1205 7486/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7487
c19d1205
ZW
7488static void
7489do_pkhtb (void)
7490{
7491 if (!inst.operands[3].present)
b99bd4ef 7492 {
c19d1205
ZW
7493 /* If the shift specifier is omitted, turn the instruction
7494 into pkhbt rd, rm, rn. */
7495 inst.instruction &= 0xfff00010;
7496 inst.instruction |= inst.operands[0].reg << 12;
7497 inst.instruction |= inst.operands[1].reg;
7498 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7499 }
7500 else
7501 {
c19d1205
ZW
7502 inst.instruction |= inst.operands[0].reg << 12;
7503 inst.instruction |= inst.operands[1].reg << 16;
7504 inst.instruction |= inst.operands[2].reg;
7505 encode_arm_shift (3);
b99bd4ef
NC
7506 }
7507}
7508
c19d1205
ZW
7509/* ARMv5TE: Preload-Cache
7510
7511 PLD <addr_mode>
7512
7513 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7514
7515static void
c19d1205 7516do_pld (void)
b99bd4ef 7517{
c19d1205
ZW
7518 constraint (!inst.operands[0].isreg,
7519 _("'[' expected after PLD mnemonic"));
7520 constraint (inst.operands[0].postind,
7521 _("post-indexed expression used in preload instruction"));
7522 constraint (inst.operands[0].writeback,
7523 _("writeback used in preload instruction"));
7524 constraint (!inst.operands[0].preind,
7525 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7526 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7527}
b99bd4ef 7528
62b3e311
PB
7529/* ARMv7: PLI <addr_mode> */
7530static void
7531do_pli (void)
7532{
7533 constraint (!inst.operands[0].isreg,
7534 _("'[' expected after PLI mnemonic"));
7535 constraint (inst.operands[0].postind,
7536 _("post-indexed expression used in preload instruction"));
7537 constraint (inst.operands[0].writeback,
7538 _("writeback used in preload instruction"));
7539 constraint (!inst.operands[0].preind,
7540 _("unindexed addressing used in preload instruction"));
7541 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7542 inst.instruction &= ~PRE_INDEX;
7543}
7544
c19d1205
ZW
7545static void
7546do_push_pop (void)
7547{
7548 inst.operands[1] = inst.operands[0];
7549 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7550 inst.operands[0].isreg = 1;
7551 inst.operands[0].writeback = 1;
7552 inst.operands[0].reg = REG_SP;
7553 do_ldmstm ();
7554}
b99bd4ef 7555
c19d1205
ZW
7556/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7557 word at the specified address and the following word
7558 respectively.
7559 Unconditionally executed.
7560 Error if Rn is R15. */
b99bd4ef 7561
c19d1205
ZW
7562static void
7563do_rfe (void)
7564{
7565 inst.instruction |= inst.operands[0].reg << 16;
7566 if (inst.operands[0].writeback)
7567 inst.instruction |= WRITE_BACK;
7568}
b99bd4ef 7569
c19d1205 7570/* ARM V6 ssat (argument parse). */
b99bd4ef 7571
c19d1205
ZW
7572static void
7573do_ssat (void)
7574{
7575 inst.instruction |= inst.operands[0].reg << 12;
7576 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7577 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7578
c19d1205
ZW
7579 if (inst.operands[3].present)
7580 encode_arm_shift (3);
b99bd4ef
NC
7581}
7582
c19d1205 7583/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7584
7585static void
c19d1205 7586do_usat (void)
b99bd4ef 7587{
c19d1205
ZW
7588 inst.instruction |= inst.operands[0].reg << 12;
7589 inst.instruction |= inst.operands[1].imm << 16;
7590 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7591
c19d1205
ZW
7592 if (inst.operands[3].present)
7593 encode_arm_shift (3);
b99bd4ef
NC
7594}
7595
c19d1205 7596/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7597
7598static void
c19d1205 7599do_ssat16 (void)
09d92015 7600{
c19d1205
ZW
7601 inst.instruction |= inst.operands[0].reg << 12;
7602 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7603 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7604}
7605
c19d1205
ZW
7606static void
7607do_usat16 (void)
a737bd4d 7608{
c19d1205
ZW
7609 inst.instruction |= inst.operands[0].reg << 12;
7610 inst.instruction |= inst.operands[1].imm << 16;
7611 inst.instruction |= inst.operands[2].reg;
7612}
a737bd4d 7613
c19d1205
ZW
7614/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7615 preserving the other bits.
a737bd4d 7616
c19d1205
ZW
7617 setend <endian_specifier>, where <endian_specifier> is either
7618 BE or LE. */
a737bd4d 7619
c19d1205
ZW
7620static void
7621do_setend (void)
7622{
7623 if (inst.operands[0].imm)
7624 inst.instruction |= 0x200;
a737bd4d
NC
7625}
7626
7627static void
c19d1205 7628do_shift (void)
a737bd4d 7629{
c19d1205
ZW
7630 unsigned int Rm = (inst.operands[1].present
7631 ? inst.operands[1].reg
7632 : inst.operands[0].reg);
a737bd4d 7633
c19d1205
ZW
7634 inst.instruction |= inst.operands[0].reg << 12;
7635 inst.instruction |= Rm;
7636 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7637 {
c19d1205
ZW
7638 inst.instruction |= inst.operands[2].reg << 8;
7639 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7640 }
7641 else
c19d1205 7642 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7643}
7644
09d92015 7645static void
3eb17e6b 7646do_smc (void)
09d92015 7647{
3eb17e6b 7648 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7649 inst.reloc.pc_rel = 0;
09d92015
MM
7650}
7651
09d92015 7652static void
c19d1205 7653do_swi (void)
09d92015 7654{
c19d1205
ZW
7655 inst.reloc.type = BFD_RELOC_ARM_SWI;
7656 inst.reloc.pc_rel = 0;
09d92015
MM
7657}
7658
c19d1205
ZW
7659/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7660 SMLAxy{cond} Rd,Rm,Rs,Rn
7661 SMLAWy{cond} Rd,Rm,Rs,Rn
7662 Error if any register is R15. */
e16bb312 7663
c19d1205
ZW
7664static void
7665do_smla (void)
e16bb312 7666{
c19d1205
ZW
7667 inst.instruction |= inst.operands[0].reg << 16;
7668 inst.instruction |= inst.operands[1].reg;
7669 inst.instruction |= inst.operands[2].reg << 8;
7670 inst.instruction |= inst.operands[3].reg << 12;
7671}
a737bd4d 7672
c19d1205
ZW
7673/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7674 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7675 Error if any register is R15.
7676 Warning if Rdlo == Rdhi. */
a737bd4d 7677
c19d1205
ZW
7678static void
7679do_smlal (void)
7680{
7681 inst.instruction |= inst.operands[0].reg << 12;
7682 inst.instruction |= inst.operands[1].reg << 16;
7683 inst.instruction |= inst.operands[2].reg;
7684 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7685
c19d1205
ZW
7686 if (inst.operands[0].reg == inst.operands[1].reg)
7687 as_tsktsk (_("rdhi and rdlo must be different"));
7688}
a737bd4d 7689
c19d1205
ZW
7690/* ARM V5E (El Segundo) signed-multiply (argument parse)
7691 SMULxy{cond} Rd,Rm,Rs
7692 Error if any register is R15. */
a737bd4d 7693
c19d1205
ZW
7694static void
7695do_smul (void)
7696{
7697 inst.instruction |= inst.operands[0].reg << 16;
7698 inst.instruction |= inst.operands[1].reg;
7699 inst.instruction |= inst.operands[2].reg << 8;
7700}
a737bd4d 7701
b6702015
PB
7702/* ARM V6 srs (argument parse). The variable fields in the encoding are
7703 the same for both ARM and Thumb-2. */
a737bd4d 7704
c19d1205
ZW
7705static void
7706do_srs (void)
7707{
b6702015
PB
7708 int reg;
7709
7710 if (inst.operands[0].present)
7711 {
7712 reg = inst.operands[0].reg;
fdfde340 7713 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7714 }
7715 else
fdfde340 7716 reg = REG_SP;
b6702015
PB
7717
7718 inst.instruction |= reg << 16;
7719 inst.instruction |= inst.operands[1].imm;
7720 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7721 inst.instruction |= WRITE_BACK;
7722}
a737bd4d 7723
c19d1205 7724/* ARM V6 strex (argument parse). */
a737bd4d 7725
c19d1205
ZW
7726static void
7727do_strex (void)
7728{
7729 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7730 || inst.operands[2].postind || inst.operands[2].writeback
7731 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7732 || inst.operands[2].negative
7733 /* See comment in do_ldrex(). */
7734 || (inst.operands[2].reg == REG_PC),
7735 BAD_ADDR_MODE);
a737bd4d 7736
c19d1205
ZW
7737 constraint (inst.operands[0].reg == inst.operands[1].reg
7738 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7739
c19d1205
ZW
7740 constraint (inst.reloc.exp.X_op != O_constant
7741 || inst.reloc.exp.X_add_number != 0,
7742 _("offset must be zero in ARM encoding"));
a737bd4d 7743
c19d1205
ZW
7744 inst.instruction |= inst.operands[0].reg << 12;
7745 inst.instruction |= inst.operands[1].reg;
7746 inst.instruction |= inst.operands[2].reg << 16;
7747 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7748}
7749
7750static void
c19d1205 7751do_strexd (void)
e16bb312 7752{
c19d1205
ZW
7753 constraint (inst.operands[1].reg % 2 != 0,
7754 _("even register required"));
7755 constraint (inst.operands[2].present
7756 && inst.operands[2].reg != inst.operands[1].reg + 1,
7757 _("can only store two consecutive registers"));
7758 /* If op 2 were present and equal to PC, this function wouldn't
7759 have been called in the first place. */
7760 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7761
c19d1205
ZW
7762 constraint (inst.operands[0].reg == inst.operands[1].reg
7763 || inst.operands[0].reg == inst.operands[1].reg + 1
7764 || inst.operands[0].reg == inst.operands[3].reg,
7765 BAD_OVERLAP);
e16bb312 7766
c19d1205
ZW
7767 inst.instruction |= inst.operands[0].reg << 12;
7768 inst.instruction |= inst.operands[1].reg;
7769 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7770}
7771
c19d1205
ZW
7772/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7773 extends it to 32-bits, and adds the result to a value in another
7774 register. You can specify a rotation by 0, 8, 16, or 24 bits
7775 before extracting the 16-bit value.
7776 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7777 Condition defaults to COND_ALWAYS.
7778 Error if any register uses R15. */
7779
e16bb312 7780static void
c19d1205 7781do_sxtah (void)
e16bb312 7782{
c19d1205
ZW
7783 inst.instruction |= inst.operands[0].reg << 12;
7784 inst.instruction |= inst.operands[1].reg << 16;
7785 inst.instruction |= inst.operands[2].reg;
7786 inst.instruction |= inst.operands[3].imm << 10;
7787}
e16bb312 7788
c19d1205 7789/* ARM V6 SXTH.
e16bb312 7790
c19d1205
ZW
7791 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7792 Condition defaults to COND_ALWAYS.
7793 Error if any register uses R15. */
e16bb312
NC
7794
7795static void
c19d1205 7796do_sxth (void)
e16bb312 7797{
c19d1205
ZW
7798 inst.instruction |= inst.operands[0].reg << 12;
7799 inst.instruction |= inst.operands[1].reg;
7800 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7801}
c19d1205
ZW
7802\f
7803/* VFP instructions. In a logical order: SP variant first, monad
7804 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7805
7806static void
c19d1205 7807do_vfp_sp_monadic (void)
e16bb312 7808{
5287ad62
JB
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7811}
7812
7813static void
c19d1205 7814do_vfp_sp_dyadic (void)
e16bb312 7815{
5287ad62
JB
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7817 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7818 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7819}
7820
7821static void
c19d1205 7822do_vfp_sp_compare_z (void)
e16bb312 7823{
5287ad62 7824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7825}
7826
7827static void
c19d1205 7828do_vfp_dp_sp_cvt (void)
e16bb312 7829{
5287ad62
JB
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7832}
7833
7834static void
c19d1205 7835do_vfp_sp_dp_cvt (void)
e16bb312 7836{
5287ad62
JB
7837 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7838 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7839}
7840
7841static void
c19d1205 7842do_vfp_reg_from_sp (void)
e16bb312 7843{
c19d1205 7844 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7845 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7846}
7847
7848static void
c19d1205 7849do_vfp_reg2_from_sp2 (void)
e16bb312 7850{
c19d1205
ZW
7851 constraint (inst.operands[2].imm != 2,
7852 _("only two consecutive VFP SP registers allowed here"));
7853 inst.instruction |= inst.operands[0].reg << 12;
7854 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7855 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7856}
7857
7858static void
c19d1205 7859do_vfp_sp_from_reg (void)
e16bb312 7860{
5287ad62 7861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7862 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7863}
7864
7865static void
c19d1205 7866do_vfp_sp2_from_reg2 (void)
e16bb312 7867{
c19d1205
ZW
7868 constraint (inst.operands[0].imm != 2,
7869 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7870 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7871 inst.instruction |= inst.operands[1].reg << 12;
7872 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7873}
7874
7875static void
c19d1205 7876do_vfp_sp_ldst (void)
e16bb312 7877{
5287ad62 7878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7879 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7880}
7881
7882static void
c19d1205 7883do_vfp_dp_ldst (void)
e16bb312 7884{
5287ad62 7885 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7886 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7887}
7888
c19d1205 7889
e16bb312 7890static void
c19d1205 7891vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7892{
c19d1205
ZW
7893 if (inst.operands[0].writeback)
7894 inst.instruction |= WRITE_BACK;
7895 else
7896 constraint (ldstm_type != VFP_LDSTMIA,
7897 _("this addressing mode requires base-register writeback"));
7898 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7899 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7900 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7901}
7902
7903static void
c19d1205 7904vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7905{
c19d1205 7906 int count;
e16bb312 7907
c19d1205
ZW
7908 if (inst.operands[0].writeback)
7909 inst.instruction |= WRITE_BACK;
7910 else
7911 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7912 _("this addressing mode requires base-register writeback"));
e16bb312 7913
c19d1205 7914 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7915 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7916
c19d1205
ZW
7917 count = inst.operands[1].imm << 1;
7918 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7919 count += 1;
e16bb312 7920
c19d1205 7921 inst.instruction |= count;
e16bb312
NC
7922}
7923
7924static void
c19d1205 7925do_vfp_sp_ldstmia (void)
e16bb312 7926{
c19d1205 7927 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7928}
7929
7930static void
c19d1205 7931do_vfp_sp_ldstmdb (void)
e16bb312 7932{
c19d1205 7933 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7934}
7935
7936static void
c19d1205 7937do_vfp_dp_ldstmia (void)
e16bb312 7938{
c19d1205 7939 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7940}
7941
7942static void
c19d1205 7943do_vfp_dp_ldstmdb (void)
e16bb312 7944{
c19d1205 7945 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7946}
7947
7948static void
c19d1205 7949do_vfp_xp_ldstmia (void)
e16bb312 7950{
c19d1205
ZW
7951 vfp_dp_ldstm (VFP_LDSTMIAX);
7952}
e16bb312 7953
c19d1205
ZW
7954static void
7955do_vfp_xp_ldstmdb (void)
7956{
7957 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7958}
5287ad62
JB
7959
7960static void
7961do_vfp_dp_rd_rm (void)
7962{
7963 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7964 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7965}
7966
7967static void
7968do_vfp_dp_rn_rd (void)
7969{
7970 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7971 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7972}
7973
7974static void
7975do_vfp_dp_rd_rn (void)
7976{
7977 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7978 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7979}
7980
7981static void
7982do_vfp_dp_rd_rn_rm (void)
7983{
7984 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7985 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7986 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7987}
7988
7989static void
7990do_vfp_dp_rd (void)
7991{
7992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7993}
7994
7995static void
7996do_vfp_dp_rm_rd_rn (void)
7997{
7998 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7999 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8000 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8001}
8002
8003/* VFPv3 instructions. */
8004static void
8005do_vfp_sp_const (void)
8006{
8007 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8008 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8009 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8010}
8011
8012static void
8013do_vfp_dp_const (void)
8014{
8015 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8016 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8017 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8018}
8019
8020static void
8021vfp_conv (int srcsize)
8022{
8023 unsigned immbits = srcsize - inst.operands[1].imm;
8024 inst.instruction |= (immbits & 1) << 5;
8025 inst.instruction |= (immbits >> 1);
8026}
8027
8028static void
8029do_vfp_sp_conv_16 (void)
8030{
8031 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8032 vfp_conv (16);
8033}
8034
8035static void
8036do_vfp_dp_conv_16 (void)
8037{
8038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8039 vfp_conv (16);
8040}
8041
8042static void
8043do_vfp_sp_conv_32 (void)
8044{
8045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8046 vfp_conv (32);
8047}
8048
8049static void
8050do_vfp_dp_conv_32 (void)
8051{
8052 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8053 vfp_conv (32);
8054}
c19d1205
ZW
8055\f
8056/* FPA instructions. Also in a logical order. */
e16bb312 8057
c19d1205
ZW
8058static void
8059do_fpa_cmp (void)
8060{
8061 inst.instruction |= inst.operands[0].reg << 16;
8062 inst.instruction |= inst.operands[1].reg;
8063}
b99bd4ef
NC
8064
8065static void
c19d1205 8066do_fpa_ldmstm (void)
b99bd4ef 8067{
c19d1205
ZW
8068 inst.instruction |= inst.operands[0].reg << 12;
8069 switch (inst.operands[1].imm)
8070 {
8071 case 1: inst.instruction |= CP_T_X; break;
8072 case 2: inst.instruction |= CP_T_Y; break;
8073 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8074 case 4: break;
8075 default: abort ();
8076 }
b99bd4ef 8077
c19d1205
ZW
8078 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8079 {
8080 /* The instruction specified "ea" or "fd", so we can only accept
8081 [Rn]{!}. The instruction does not really support stacking or
8082 unstacking, so we have to emulate these by setting appropriate
8083 bits and offsets. */
8084 constraint (inst.reloc.exp.X_op != O_constant
8085 || inst.reloc.exp.X_add_number != 0,
8086 _("this instruction does not support indexing"));
b99bd4ef 8087
c19d1205
ZW
8088 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8089 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8090
c19d1205
ZW
8091 if (!(inst.instruction & INDEX_UP))
8092 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8093
c19d1205
ZW
8094 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8095 {
8096 inst.operands[2].preind = 0;
8097 inst.operands[2].postind = 1;
8098 }
8099 }
b99bd4ef 8100
c19d1205 8101 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8102}
c19d1205
ZW
8103\f
8104/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8105
c19d1205
ZW
8106static void
8107do_iwmmxt_tandorc (void)
8108{
8109 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8110}
b99bd4ef 8111
c19d1205
ZW
8112static void
8113do_iwmmxt_textrc (void)
8114{
8115 inst.instruction |= inst.operands[0].reg << 12;
8116 inst.instruction |= inst.operands[1].imm;
8117}
b99bd4ef
NC
8118
8119static void
c19d1205 8120do_iwmmxt_textrm (void)
b99bd4ef 8121{
c19d1205
ZW
8122 inst.instruction |= inst.operands[0].reg << 12;
8123 inst.instruction |= inst.operands[1].reg << 16;
8124 inst.instruction |= inst.operands[2].imm;
8125}
b99bd4ef 8126
c19d1205
ZW
8127static void
8128do_iwmmxt_tinsr (void)
8129{
8130 inst.instruction |= inst.operands[0].reg << 16;
8131 inst.instruction |= inst.operands[1].reg << 12;
8132 inst.instruction |= inst.operands[2].imm;
8133}
b99bd4ef 8134
c19d1205
ZW
8135static void
8136do_iwmmxt_tmia (void)
8137{
8138 inst.instruction |= inst.operands[0].reg << 5;
8139 inst.instruction |= inst.operands[1].reg;
8140 inst.instruction |= inst.operands[2].reg << 12;
8141}
b99bd4ef 8142
c19d1205
ZW
8143static void
8144do_iwmmxt_waligni (void)
8145{
8146 inst.instruction |= inst.operands[0].reg << 12;
8147 inst.instruction |= inst.operands[1].reg << 16;
8148 inst.instruction |= inst.operands[2].reg;
8149 inst.instruction |= inst.operands[3].imm << 20;
8150}
b99bd4ef 8151
2d447fca
JM
8152static void
8153do_iwmmxt_wmerge (void)
8154{
8155 inst.instruction |= inst.operands[0].reg << 12;
8156 inst.instruction |= inst.operands[1].reg << 16;
8157 inst.instruction |= inst.operands[2].reg;
8158 inst.instruction |= inst.operands[3].imm << 21;
8159}
8160
c19d1205
ZW
8161static void
8162do_iwmmxt_wmov (void)
8163{
8164 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8165 inst.instruction |= inst.operands[0].reg << 12;
8166 inst.instruction |= inst.operands[1].reg << 16;
8167 inst.instruction |= inst.operands[1].reg;
8168}
b99bd4ef 8169
c19d1205
ZW
8170static void
8171do_iwmmxt_wldstbh (void)
8172{
8f06b2d8 8173 int reloc;
c19d1205 8174 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8175 if (thumb_mode)
8176 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8177 else
8178 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8179 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8180}
8181
c19d1205
ZW
8182static void
8183do_iwmmxt_wldstw (void)
8184{
8185 /* RIWR_RIWC clears .isreg for a control register. */
8186 if (!inst.operands[0].isreg)
8187 {
8188 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8189 inst.instruction |= 0xf0000000;
8190 }
b99bd4ef 8191
c19d1205
ZW
8192 inst.instruction |= inst.operands[0].reg << 12;
8193 encode_arm_cp_address (1, TRUE, TRUE, 0);
8194}
b99bd4ef
NC
8195
8196static void
c19d1205 8197do_iwmmxt_wldstd (void)
b99bd4ef 8198{
c19d1205 8199 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8200 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8201 && inst.operands[1].immisreg)
8202 {
8203 inst.instruction &= ~0x1a000ff;
8204 inst.instruction |= (0xf << 28);
8205 if (inst.operands[1].preind)
8206 inst.instruction |= PRE_INDEX;
8207 if (!inst.operands[1].negative)
8208 inst.instruction |= INDEX_UP;
8209 if (inst.operands[1].writeback)
8210 inst.instruction |= WRITE_BACK;
8211 inst.instruction |= inst.operands[1].reg << 16;
8212 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8213 inst.instruction |= inst.operands[1].imm;
8214 }
8215 else
8216 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8217}
b99bd4ef 8218
c19d1205
ZW
8219static void
8220do_iwmmxt_wshufh (void)
8221{
8222 inst.instruction |= inst.operands[0].reg << 12;
8223 inst.instruction |= inst.operands[1].reg << 16;
8224 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8225 inst.instruction |= (inst.operands[2].imm & 0x0f);
8226}
b99bd4ef 8227
c19d1205
ZW
8228static void
8229do_iwmmxt_wzero (void)
8230{
8231 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8232 inst.instruction |= inst.operands[0].reg;
8233 inst.instruction |= inst.operands[0].reg << 12;
8234 inst.instruction |= inst.operands[0].reg << 16;
8235}
2d447fca
JM
8236
8237static void
8238do_iwmmxt_wrwrwr_or_imm5 (void)
8239{
8240 if (inst.operands[2].isreg)
8241 do_rd_rn_rm ();
8242 else {
8243 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8244 _("immediate operand requires iWMMXt2"));
8245 do_rd_rn ();
8246 if (inst.operands[2].imm == 0)
8247 {
8248 switch ((inst.instruction >> 20) & 0xf)
8249 {
8250 case 4:
8251 case 5:
8252 case 6:
5f4273c7 8253 case 7:
2d447fca
JM
8254 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8255 inst.operands[2].imm = 16;
8256 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8257 break;
8258 case 8:
8259 case 9:
8260 case 10:
8261 case 11:
8262 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8263 inst.operands[2].imm = 32;
8264 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8265 break;
8266 case 12:
8267 case 13:
8268 case 14:
8269 case 15:
8270 {
8271 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8272 unsigned long wrn;
8273 wrn = (inst.instruction >> 16) & 0xf;
8274 inst.instruction &= 0xff0fff0f;
8275 inst.instruction |= wrn;
8276 /* Bail out here; the instruction is now assembled. */
8277 return;
8278 }
8279 }
8280 }
8281 /* Map 32 -> 0, etc. */
8282 inst.operands[2].imm &= 0x1f;
8283 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8284 }
8285}
c19d1205
ZW
8286\f
8287/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8288 operations first, then control, shift, and load/store. */
b99bd4ef 8289
c19d1205 8290/* Insns like "foo X,Y,Z". */
b99bd4ef 8291
c19d1205
ZW
8292static void
8293do_mav_triple (void)
8294{
8295 inst.instruction |= inst.operands[0].reg << 16;
8296 inst.instruction |= inst.operands[1].reg;
8297 inst.instruction |= inst.operands[2].reg << 12;
8298}
b99bd4ef 8299
c19d1205
ZW
8300/* Insns like "foo W,X,Y,Z".
8301 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8302
c19d1205
ZW
8303static void
8304do_mav_quad (void)
8305{
8306 inst.instruction |= inst.operands[0].reg << 5;
8307 inst.instruction |= inst.operands[1].reg << 12;
8308 inst.instruction |= inst.operands[2].reg << 16;
8309 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8310}
8311
c19d1205
ZW
8312/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8313static void
8314do_mav_dspsc (void)
a737bd4d 8315{
c19d1205
ZW
8316 inst.instruction |= inst.operands[1].reg << 12;
8317}
a737bd4d 8318
c19d1205
ZW
8319/* Maverick shift immediate instructions.
8320 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8321 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8322
c19d1205
ZW
8323static void
8324do_mav_shift (void)
8325{
8326 int imm = inst.operands[2].imm;
a737bd4d 8327
c19d1205
ZW
8328 inst.instruction |= inst.operands[0].reg << 12;
8329 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8330
c19d1205
ZW
8331 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8332 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8333 Bit 4 should be 0. */
8334 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8335
c19d1205
ZW
8336 inst.instruction |= imm;
8337}
8338\f
8339/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8340
c19d1205
ZW
8341/* Xscale multiply-accumulate (argument parse)
8342 MIAcc acc0,Rm,Rs
8343 MIAPHcc acc0,Rm,Rs
8344 MIAxycc acc0,Rm,Rs. */
a737bd4d 8345
c19d1205
ZW
8346static void
8347do_xsc_mia (void)
8348{
8349 inst.instruction |= inst.operands[1].reg;
8350 inst.instruction |= inst.operands[2].reg << 12;
8351}
a737bd4d 8352
c19d1205 8353/* Xscale move-accumulator-register (argument parse)
a737bd4d 8354
c19d1205 8355 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8356
c19d1205
ZW
8357static void
8358do_xsc_mar (void)
8359{
8360 inst.instruction |= inst.operands[1].reg << 12;
8361 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8362}
8363
c19d1205 8364/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8365
c19d1205 8366 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8367
8368static void
c19d1205 8369do_xsc_mra (void)
b99bd4ef 8370{
c19d1205
ZW
8371 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8372 inst.instruction |= inst.operands[0].reg << 12;
8373 inst.instruction |= inst.operands[1].reg << 16;
8374}
8375\f
8376/* Encoding functions relevant only to Thumb. */
b99bd4ef 8377
c19d1205
ZW
8378/* inst.operands[i] is a shifted-register operand; encode
8379 it into inst.instruction in the format used by Thumb32. */
8380
8381static void
8382encode_thumb32_shifted_operand (int i)
8383{
8384 unsigned int value = inst.reloc.exp.X_add_number;
8385 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8386
9c3c69f2
PB
8387 constraint (inst.operands[i].immisreg,
8388 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8389 inst.instruction |= inst.operands[i].reg;
8390 if (shift == SHIFT_RRX)
8391 inst.instruction |= SHIFT_ROR << 4;
8392 else
b99bd4ef 8393 {
c19d1205
ZW
8394 constraint (inst.reloc.exp.X_op != O_constant,
8395 _("expression too complex"));
8396
8397 constraint (value > 32
8398 || (value == 32 && (shift == SHIFT_LSL
8399 || shift == SHIFT_ROR)),
8400 _("shift expression is too large"));
8401
8402 if (value == 0)
8403 shift = SHIFT_LSL;
8404 else if (value == 32)
8405 value = 0;
8406
8407 inst.instruction |= shift << 4;
8408 inst.instruction |= (value & 0x1c) << 10;
8409 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8410 }
c19d1205 8411}
b99bd4ef 8412
b99bd4ef 8413
c19d1205
ZW
8414/* inst.operands[i] was set up by parse_address. Encode it into a
8415 Thumb32 format load or store instruction. Reject forms that cannot
8416 be used with such instructions. If is_t is true, reject forms that
8417 cannot be used with a T instruction; if is_d is true, reject forms
8418 that cannot be used with a D instruction. */
b99bd4ef 8419
c19d1205
ZW
8420static void
8421encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8422{
8423 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8424
8425 constraint (!inst.operands[i].isreg,
53365c0d 8426 _("Instruction does not support =N addresses"));
b99bd4ef 8427
c19d1205
ZW
8428 inst.instruction |= inst.operands[i].reg << 16;
8429 if (inst.operands[i].immisreg)
b99bd4ef 8430 {
c19d1205
ZW
8431 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8432 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8433 constraint (inst.operands[i].negative,
8434 _("Thumb does not support negative register indexing"));
8435 constraint (inst.operands[i].postind,
8436 _("Thumb does not support register post-indexing"));
8437 constraint (inst.operands[i].writeback,
8438 _("Thumb does not support register indexing with writeback"));
8439 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8440 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8441
f40d1643 8442 inst.instruction |= inst.operands[i].imm;
c19d1205 8443 if (inst.operands[i].shifted)
b99bd4ef 8444 {
c19d1205
ZW
8445 constraint (inst.reloc.exp.X_op != O_constant,
8446 _("expression too complex"));
9c3c69f2
PB
8447 constraint (inst.reloc.exp.X_add_number < 0
8448 || inst.reloc.exp.X_add_number > 3,
c19d1205 8449 _("shift out of range"));
9c3c69f2 8450 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8451 }
8452 inst.reloc.type = BFD_RELOC_UNUSED;
8453 }
8454 else if (inst.operands[i].preind)
8455 {
8456 constraint (is_pc && inst.operands[i].writeback,
8457 _("cannot use writeback with PC-relative addressing"));
f40d1643 8458 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8459 _("cannot use writeback with this instruction"));
8460
8461 if (is_d)
8462 {
8463 inst.instruction |= 0x01000000;
8464 if (inst.operands[i].writeback)
8465 inst.instruction |= 0x00200000;
b99bd4ef 8466 }
c19d1205 8467 else
b99bd4ef 8468 {
c19d1205
ZW
8469 inst.instruction |= 0x00000c00;
8470 if (inst.operands[i].writeback)
8471 inst.instruction |= 0x00000100;
b99bd4ef 8472 }
c19d1205 8473 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8474 }
c19d1205 8475 else if (inst.operands[i].postind)
b99bd4ef 8476 {
9c2799c2 8477 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8478 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8479 constraint (is_t, _("cannot use post-indexing with this instruction"));
8480
8481 if (is_d)
8482 inst.instruction |= 0x00200000;
8483 else
8484 inst.instruction |= 0x00000900;
8485 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8486 }
8487 else /* unindexed - only for coprocessor */
8488 inst.error = _("instruction does not accept unindexed addressing");
8489}
8490
8491/* Table of Thumb instructions which exist in both 16- and 32-bit
8492 encodings (the latter only in post-V6T2 cores). The index is the
8493 value used in the insns table below. When there is more than one
8494 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8495 holds variant (1).
8496 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8497#define T16_32_TAB \
8498 X(adc, 4140, eb400000), \
8499 X(adcs, 4140, eb500000), \
8500 X(add, 1c00, eb000000), \
8501 X(adds, 1c00, eb100000), \
0110f2b8
PB
8502 X(addi, 0000, f1000000), \
8503 X(addis, 0000, f1100000), \
8504 X(add_pc,000f, f20f0000), \
8505 X(add_sp,000d, f10d0000), \
e9f89963 8506 X(adr, 000f, f20f0000), \
c19d1205
ZW
8507 X(and, 4000, ea000000), \
8508 X(ands, 4000, ea100000), \
8509 X(asr, 1000, fa40f000), \
8510 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8511 X(b, e000, f000b000), \
8512 X(bcond, d000, f0008000), \
c19d1205
ZW
8513 X(bic, 4380, ea200000), \
8514 X(bics, 4380, ea300000), \
8515 X(cmn, 42c0, eb100f00), \
8516 X(cmp, 2800, ebb00f00), \
8517 X(cpsie, b660, f3af8400), \
8518 X(cpsid, b670, f3af8600), \
8519 X(cpy, 4600, ea4f0000), \
155257ea 8520 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8521 X(eor, 4040, ea800000), \
8522 X(eors, 4040, ea900000), \
0110f2b8 8523 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8524 X(ldmia, c800, e8900000), \
8525 X(ldr, 6800, f8500000), \
8526 X(ldrb, 7800, f8100000), \
8527 X(ldrh, 8800, f8300000), \
8528 X(ldrsb, 5600, f9100000), \
8529 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8530 X(ldr_pc,4800, f85f0000), \
8531 X(ldr_pc2,4800, f85f0000), \
8532 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8533 X(lsl, 0000, fa00f000), \
8534 X(lsls, 0000, fa10f000), \
8535 X(lsr, 0800, fa20f000), \
8536 X(lsrs, 0800, fa30f000), \
8537 X(mov, 2000, ea4f0000), \
8538 X(movs, 2000, ea5f0000), \
8539 X(mul, 4340, fb00f000), \
8540 X(muls, 4340, ffffffff), /* no 32b muls */ \
8541 X(mvn, 43c0, ea6f0000), \
8542 X(mvns, 43c0, ea7f0000), \
8543 X(neg, 4240, f1c00000), /* rsb #0 */ \
8544 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8545 X(orr, 4300, ea400000), \
8546 X(orrs, 4300, ea500000), \
e9f89963
PB
8547 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8548 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8549 X(rev, ba00, fa90f080), \
8550 X(rev16, ba40, fa90f090), \
8551 X(revsh, bac0, fa90f0b0), \
8552 X(ror, 41c0, fa60f000), \
8553 X(rors, 41c0, fa70f000), \
8554 X(sbc, 4180, eb600000), \
8555 X(sbcs, 4180, eb700000), \
8556 X(stmia, c000, e8800000), \
8557 X(str, 6000, f8400000), \
8558 X(strb, 7000, f8000000), \
8559 X(strh, 8000, f8200000), \
0110f2b8 8560 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8561 X(sub, 1e00, eba00000), \
8562 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8563 X(subi, 8000, f1a00000), \
8564 X(subis, 8000, f1b00000), \
c19d1205
ZW
8565 X(sxtb, b240, fa4ff080), \
8566 X(sxth, b200, fa0ff080), \
8567 X(tst, 4200, ea100f00), \
8568 X(uxtb, b2c0, fa5ff080), \
8569 X(uxth, b280, fa1ff080), \
8570 X(nop, bf00, f3af8000), \
8571 X(yield, bf10, f3af8001), \
8572 X(wfe, bf20, f3af8002), \
8573 X(wfi, bf30, f3af8003), \
fe2ceba1 8574 X(sev, bf40, f3af8004),
c19d1205
ZW
8575
8576/* To catch errors in encoding functions, the codes are all offset by
8577 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8578 as 16-bit instructions. */
8579#define X(a,b,c) T_MNEM_##a
8580enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8581#undef X
8582
8583#define X(a,b,c) 0x##b
8584static const unsigned short thumb_op16[] = { T16_32_TAB };
8585#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8586#undef X
8587
8588#define X(a,b,c) 0x##c
8589static const unsigned int thumb_op32[] = { T16_32_TAB };
8590#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8591#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8592#undef X
8593#undef T16_32_TAB
8594
8595/* Thumb instruction encoders, in alphabetical order. */
8596
92e90b6e
PB
8597/* ADDW or SUBW. */
8598static void
8599do_t_add_sub_w (void)
8600{
8601 int Rd, Rn;
8602
8603 Rd = inst.operands[0].reg;
8604 Rn = inst.operands[1].reg;
8605
fdfde340
JM
8606 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8607 SP-{plus,minute}-immediate form of the instruction. */
8608 reject_bad_reg (Rd);
8609
92e90b6e
PB
8610 inst.instruction |= (Rn << 16) | (Rd << 8);
8611 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8612}
8613
c19d1205
ZW
8614/* Parse an add or subtract instruction. We get here with inst.instruction
8615 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8616
8617static void
8618do_t_add_sub (void)
8619{
8620 int Rd, Rs, Rn;
8621
8622 Rd = inst.operands[0].reg;
8623 Rs = (inst.operands[1].present
8624 ? inst.operands[1].reg /* Rd, Rs, foo */
8625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8626
e07e6e58
NC
8627 if (Rd == REG_PC)
8628 set_it_insn_type_last ();
8629
c19d1205
ZW
8630 if (unified_syntax)
8631 {
0110f2b8
PB
8632 bfd_boolean flags;
8633 bfd_boolean narrow;
8634 int opcode;
8635
8636 flags = (inst.instruction == T_MNEM_adds
8637 || inst.instruction == T_MNEM_subs);
8638 if (flags)
e07e6e58 8639 narrow = !in_it_block ();
0110f2b8 8640 else
e07e6e58 8641 narrow = in_it_block ();
c19d1205 8642 if (!inst.operands[2].isreg)
b99bd4ef 8643 {
16805f35
PB
8644 int add;
8645
fdfde340
JM
8646 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8647
16805f35
PB
8648 add = (inst.instruction == T_MNEM_add
8649 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8650 opcode = 0;
8651 if (inst.size_req != 4)
8652 {
0110f2b8
PB
8653 /* Attempt to use a narrow opcode, with relaxation if
8654 appropriate. */
8655 if (Rd == REG_SP && Rs == REG_SP && !flags)
8656 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8657 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8658 opcode = T_MNEM_add_sp;
8659 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8660 opcode = T_MNEM_add_pc;
8661 else if (Rd <= 7 && Rs <= 7 && narrow)
8662 {
8663 if (flags)
8664 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8665 else
8666 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8667 }
8668 if (opcode)
8669 {
8670 inst.instruction = THUMB_OP16(opcode);
8671 inst.instruction |= (Rd << 4) | Rs;
8672 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8673 if (inst.size_req != 2)
8674 inst.relax = opcode;
8675 }
8676 else
8677 constraint (inst.size_req == 2, BAD_HIREG);
8678 }
8679 if (inst.size_req == 4
8680 || (inst.size_req != 2 && !opcode))
8681 {
efd81785
PB
8682 if (Rd == REG_PC)
8683 {
fdfde340 8684 constraint (add, BAD_PC);
efd81785
PB
8685 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8686 _("only SUBS PC, LR, #const allowed"));
8687 constraint (inst.reloc.exp.X_op != O_constant,
8688 _("expression too complex"));
8689 constraint (inst.reloc.exp.X_add_number < 0
8690 || inst.reloc.exp.X_add_number > 0xff,
8691 _("immediate value out of range"));
8692 inst.instruction = T2_SUBS_PC_LR
8693 | inst.reloc.exp.X_add_number;
8694 inst.reloc.type = BFD_RELOC_UNUSED;
8695 return;
8696 }
8697 else if (Rs == REG_PC)
16805f35
PB
8698 {
8699 /* Always use addw/subw. */
8700 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8701 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8702 }
8703 else
8704 {
8705 inst.instruction = THUMB_OP32 (inst.instruction);
8706 inst.instruction = (inst.instruction & 0xe1ffffff)
8707 | 0x10000000;
8708 if (flags)
8709 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8710 else
8711 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8712 }
dc4503c6
PB
8713 inst.instruction |= Rd << 8;
8714 inst.instruction |= Rs << 16;
0110f2b8 8715 }
b99bd4ef 8716 }
c19d1205
ZW
8717 else
8718 {
8719 Rn = inst.operands[2].reg;
8720 /* See if we can do this with a 16-bit instruction. */
8721 if (!inst.operands[2].shifted && inst.size_req != 4)
8722 {
e27ec89e
PB
8723 if (Rd > 7 || Rs > 7 || Rn > 7)
8724 narrow = FALSE;
8725
8726 if (narrow)
c19d1205 8727 {
e27ec89e
PB
8728 inst.instruction = ((inst.instruction == T_MNEM_adds
8729 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8730 ? T_OPCODE_ADD_R3
8731 : T_OPCODE_SUB_R3);
8732 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8733 return;
8734 }
b99bd4ef 8735
7e806470 8736 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8737 {
7e806470
PB
8738 /* Thumb-1 cores (except v6-M) require at least one high
8739 register in a narrow non flag setting add. */
8740 if (Rd > 7 || Rn > 7
8741 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8742 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8743 {
7e806470
PB
8744 if (Rd == Rn)
8745 {
8746 Rn = Rs;
8747 Rs = Rd;
8748 }
c19d1205
ZW
8749 inst.instruction = T_OPCODE_ADD_HI;
8750 inst.instruction |= (Rd & 8) << 4;
8751 inst.instruction |= (Rd & 7);
8752 inst.instruction |= Rn << 3;
8753 return;
8754 }
c19d1205
ZW
8755 }
8756 }
fdfde340
JM
8757
8758 constraint (Rd == REG_PC, BAD_PC);
8759 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8760 constraint (Rs == REG_PC, BAD_PC);
8761 reject_bad_reg (Rn);
8762
c19d1205
ZW
8763 /* If we get here, it can't be done in 16 bits. */
8764 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8765 _("shift must be constant"));
8766 inst.instruction = THUMB_OP32 (inst.instruction);
8767 inst.instruction |= Rd << 8;
8768 inst.instruction |= Rs << 16;
8769 encode_thumb32_shifted_operand (2);
8770 }
8771 }
8772 else
8773 {
8774 constraint (inst.instruction == T_MNEM_adds
8775 || inst.instruction == T_MNEM_subs,
8776 BAD_THUMB32);
b99bd4ef 8777
c19d1205 8778 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8779 {
c19d1205
ZW
8780 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8781 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8782 BAD_HIREG);
8783
8784 inst.instruction = (inst.instruction == T_MNEM_add
8785 ? 0x0000 : 0x8000);
8786 inst.instruction |= (Rd << 4) | Rs;
8787 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8788 return;
8789 }
8790
c19d1205
ZW
8791 Rn = inst.operands[2].reg;
8792 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8793
c19d1205
ZW
8794 /* We now have Rd, Rs, and Rn set to registers. */
8795 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8796 {
c19d1205
ZW
8797 /* Can't do this for SUB. */
8798 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8799 inst.instruction = T_OPCODE_ADD_HI;
8800 inst.instruction |= (Rd & 8) << 4;
8801 inst.instruction |= (Rd & 7);
8802 if (Rs == Rd)
8803 inst.instruction |= Rn << 3;
8804 else if (Rn == Rd)
8805 inst.instruction |= Rs << 3;
8806 else
8807 constraint (1, _("dest must overlap one source register"));
8808 }
8809 else
8810 {
8811 inst.instruction = (inst.instruction == T_MNEM_add
8812 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8813 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8814 }
b99bd4ef 8815 }
b99bd4ef
NC
8816}
8817
c19d1205
ZW
8818static void
8819do_t_adr (void)
8820{
fdfde340
JM
8821 unsigned Rd;
8822
8823 Rd = inst.operands[0].reg;
8824 reject_bad_reg (Rd);
8825
8826 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
8827 {
8828 /* Defer to section relaxation. */
8829 inst.relax = inst.instruction;
8830 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 8831 inst.instruction |= Rd << 4;
0110f2b8
PB
8832 }
8833 else if (unified_syntax && inst.size_req != 2)
e9f89963 8834 {
0110f2b8 8835 /* Generate a 32-bit opcode. */
e9f89963 8836 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 8837 inst.instruction |= Rd << 8;
e9f89963
PB
8838 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8839 inst.reloc.pc_rel = 1;
8840 }
8841 else
8842 {
0110f2b8 8843 /* Generate a 16-bit opcode. */
e9f89963
PB
8844 inst.instruction = THUMB_OP16 (inst.instruction);
8845 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8846 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8847 inst.reloc.pc_rel = 1;
b99bd4ef 8848
fdfde340 8849 inst.instruction |= Rd << 4;
e9f89963 8850 }
c19d1205 8851}
b99bd4ef 8852
c19d1205
ZW
8853/* Arithmetic instructions for which there is just one 16-bit
8854 instruction encoding, and it allows only two low registers.
8855 For maximal compatibility with ARM syntax, we allow three register
8856 operands even when Thumb-32 instructions are not available, as long
8857 as the first two are identical. For instance, both "sbc r0,r1" and
8858 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8859static void
c19d1205 8860do_t_arit3 (void)
b99bd4ef 8861{
c19d1205 8862 int Rd, Rs, Rn;
b99bd4ef 8863
c19d1205
ZW
8864 Rd = inst.operands[0].reg;
8865 Rs = (inst.operands[1].present
8866 ? inst.operands[1].reg /* Rd, Rs, foo */
8867 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8868 Rn = inst.operands[2].reg;
b99bd4ef 8869
fdfde340
JM
8870 reject_bad_reg (Rd);
8871 reject_bad_reg (Rs);
8872 if (inst.operands[2].isreg)
8873 reject_bad_reg (Rn);
8874
c19d1205 8875 if (unified_syntax)
b99bd4ef 8876 {
c19d1205
ZW
8877 if (!inst.operands[2].isreg)
8878 {
8879 /* For an immediate, we always generate a 32-bit opcode;
8880 section relaxation will shrink it later if possible. */
8881 inst.instruction = THUMB_OP32 (inst.instruction);
8882 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8883 inst.instruction |= Rd << 8;
8884 inst.instruction |= Rs << 16;
8885 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8886 }
8887 else
8888 {
e27ec89e
PB
8889 bfd_boolean narrow;
8890
c19d1205 8891 /* See if we can do this with a 16-bit instruction. */
e27ec89e 8892 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 8893 narrow = !in_it_block ();
e27ec89e 8894 else
e07e6e58 8895 narrow = in_it_block ();
e27ec89e
PB
8896
8897 if (Rd > 7 || Rn > 7 || Rs > 7)
8898 narrow = FALSE;
8899 if (inst.operands[2].shifted)
8900 narrow = FALSE;
8901 if (inst.size_req == 4)
8902 narrow = FALSE;
8903
8904 if (narrow
c19d1205
ZW
8905 && Rd == Rs)
8906 {
8907 inst.instruction = THUMB_OP16 (inst.instruction);
8908 inst.instruction |= Rd;
8909 inst.instruction |= Rn << 3;
8910 return;
8911 }
b99bd4ef 8912
c19d1205
ZW
8913 /* If we get here, it can't be done in 16 bits. */
8914 constraint (inst.operands[2].shifted
8915 && inst.operands[2].immisreg,
8916 _("shift must be constant"));
8917 inst.instruction = THUMB_OP32 (inst.instruction);
8918 inst.instruction |= Rd << 8;
8919 inst.instruction |= Rs << 16;
8920 encode_thumb32_shifted_operand (2);
8921 }
a737bd4d 8922 }
c19d1205 8923 else
b99bd4ef 8924 {
c19d1205
ZW
8925 /* On its face this is a lie - the instruction does set the
8926 flags. However, the only supported mnemonic in this mode
8927 says it doesn't. */
8928 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8929
c19d1205
ZW
8930 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8931 _("unshifted register required"));
8932 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8933 constraint (Rd != Rs,
8934 _("dest and source1 must be the same register"));
a737bd4d 8935
c19d1205
ZW
8936 inst.instruction = THUMB_OP16 (inst.instruction);
8937 inst.instruction |= Rd;
8938 inst.instruction |= Rn << 3;
b99bd4ef 8939 }
a737bd4d 8940}
b99bd4ef 8941
c19d1205
ZW
8942/* Similarly, but for instructions where the arithmetic operation is
8943 commutative, so we can allow either of them to be different from
8944 the destination operand in a 16-bit instruction. For instance, all
8945 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8946 accepted. */
8947static void
8948do_t_arit3c (void)
a737bd4d 8949{
c19d1205 8950 int Rd, Rs, Rn;
b99bd4ef 8951
c19d1205
ZW
8952 Rd = inst.operands[0].reg;
8953 Rs = (inst.operands[1].present
8954 ? inst.operands[1].reg /* Rd, Rs, foo */
8955 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8956 Rn = inst.operands[2].reg;
fdfde340
JM
8957
8958 reject_bad_reg (Rd);
8959 reject_bad_reg (Rs);
8960 if (inst.operands[2].isreg)
8961 reject_bad_reg (Rn);
a737bd4d 8962
c19d1205 8963 if (unified_syntax)
a737bd4d 8964 {
c19d1205 8965 if (!inst.operands[2].isreg)
b99bd4ef 8966 {
c19d1205
ZW
8967 /* For an immediate, we always generate a 32-bit opcode;
8968 section relaxation will shrink it later if possible. */
8969 inst.instruction = THUMB_OP32 (inst.instruction);
8970 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8971 inst.instruction |= Rd << 8;
8972 inst.instruction |= Rs << 16;
8973 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8974 }
c19d1205 8975 else
a737bd4d 8976 {
e27ec89e
PB
8977 bfd_boolean narrow;
8978
c19d1205 8979 /* See if we can do this with a 16-bit instruction. */
e27ec89e 8980 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 8981 narrow = !in_it_block ();
e27ec89e 8982 else
e07e6e58 8983 narrow = in_it_block ();
e27ec89e
PB
8984
8985 if (Rd > 7 || Rn > 7 || Rs > 7)
8986 narrow = FALSE;
8987 if (inst.operands[2].shifted)
8988 narrow = FALSE;
8989 if (inst.size_req == 4)
8990 narrow = FALSE;
8991
8992 if (narrow)
a737bd4d 8993 {
c19d1205 8994 if (Rd == Rs)
a737bd4d 8995 {
c19d1205
ZW
8996 inst.instruction = THUMB_OP16 (inst.instruction);
8997 inst.instruction |= Rd;
8998 inst.instruction |= Rn << 3;
8999 return;
a737bd4d 9000 }
c19d1205 9001 if (Rd == Rn)
a737bd4d 9002 {
c19d1205
ZW
9003 inst.instruction = THUMB_OP16 (inst.instruction);
9004 inst.instruction |= Rd;
9005 inst.instruction |= Rs << 3;
9006 return;
a737bd4d
NC
9007 }
9008 }
c19d1205
ZW
9009
9010 /* If we get here, it can't be done in 16 bits. */
9011 constraint (inst.operands[2].shifted
9012 && inst.operands[2].immisreg,
9013 _("shift must be constant"));
9014 inst.instruction = THUMB_OP32 (inst.instruction);
9015 inst.instruction |= Rd << 8;
9016 inst.instruction |= Rs << 16;
9017 encode_thumb32_shifted_operand (2);
a737bd4d 9018 }
b99bd4ef 9019 }
c19d1205
ZW
9020 else
9021 {
9022 /* On its face this is a lie - the instruction does set the
9023 flags. However, the only supported mnemonic in this mode
9024 says it doesn't. */
9025 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9026
c19d1205
ZW
9027 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9028 _("unshifted register required"));
9029 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9030
9031 inst.instruction = THUMB_OP16 (inst.instruction);
9032 inst.instruction |= Rd;
9033
9034 if (Rd == Rs)
9035 inst.instruction |= Rn << 3;
9036 else if (Rd == Rn)
9037 inst.instruction |= Rs << 3;
9038 else
9039 constraint (1, _("dest must overlap one source register"));
9040 }
a737bd4d
NC
9041}
9042
62b3e311
PB
9043static void
9044do_t_barrier (void)
9045{
9046 if (inst.operands[0].present)
9047 {
9048 constraint ((inst.instruction & 0xf0) != 0x40
9049 && inst.operands[0].imm != 0xf,
bd3ba5d1 9050 _("bad barrier type"));
62b3e311
PB
9051 inst.instruction |= inst.operands[0].imm;
9052 }
9053 else
9054 inst.instruction |= 0xf;
9055}
9056
c19d1205
ZW
9057static void
9058do_t_bfc (void)
a737bd4d 9059{
fdfde340 9060 unsigned Rd;
c19d1205
ZW
9061 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9062 constraint (msb > 32, _("bit-field extends past end of register"));
9063 /* The instruction encoding stores the LSB and MSB,
9064 not the LSB and width. */
fdfde340
JM
9065 Rd = inst.operands[0].reg;
9066 reject_bad_reg (Rd);
9067 inst.instruction |= Rd << 8;
c19d1205
ZW
9068 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9069 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9070 inst.instruction |= msb - 1;
b99bd4ef
NC
9071}
9072
c19d1205
ZW
9073static void
9074do_t_bfi (void)
b99bd4ef 9075{
fdfde340 9076 int Rd, Rn;
c19d1205 9077 unsigned int msb;
b99bd4ef 9078
fdfde340
JM
9079 Rd = inst.operands[0].reg;
9080 reject_bad_reg (Rd);
9081
c19d1205
ZW
9082 /* #0 in second position is alternative syntax for bfc, which is
9083 the same instruction but with REG_PC in the Rm field. */
9084 if (!inst.operands[1].isreg)
fdfde340
JM
9085 Rn = REG_PC;
9086 else
9087 {
9088 Rn = inst.operands[1].reg;
9089 reject_bad_reg (Rn);
9090 }
b99bd4ef 9091
c19d1205
ZW
9092 msb = inst.operands[2].imm + inst.operands[3].imm;
9093 constraint (msb > 32, _("bit-field extends past end of register"));
9094 /* The instruction encoding stores the LSB and MSB,
9095 not the LSB and width. */
fdfde340
JM
9096 inst.instruction |= Rd << 8;
9097 inst.instruction |= Rn << 16;
c19d1205
ZW
9098 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9099 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9100 inst.instruction |= msb - 1;
b99bd4ef
NC
9101}
9102
c19d1205
ZW
9103static void
9104do_t_bfx (void)
b99bd4ef 9105{
fdfde340
JM
9106 unsigned Rd, Rn;
9107
9108 Rd = inst.operands[0].reg;
9109 Rn = inst.operands[1].reg;
9110
9111 reject_bad_reg (Rd);
9112 reject_bad_reg (Rn);
9113
c19d1205
ZW
9114 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9115 _("bit-field extends past end of register"));
fdfde340
JM
9116 inst.instruction |= Rd << 8;
9117 inst.instruction |= Rn << 16;
c19d1205
ZW
9118 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9119 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9120 inst.instruction |= inst.operands[3].imm - 1;
9121}
b99bd4ef 9122
c19d1205
ZW
9123/* ARM V5 Thumb BLX (argument parse)
9124 BLX <target_addr> which is BLX(1)
9125 BLX <Rm> which is BLX(2)
9126 Unfortunately, there are two different opcodes for this mnemonic.
9127 So, the insns[].value is not used, and the code here zaps values
9128 into inst.instruction.
b99bd4ef 9129
c19d1205
ZW
9130 ??? How to take advantage of the additional two bits of displacement
9131 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9132
c19d1205
ZW
9133static void
9134do_t_blx (void)
9135{
e07e6e58
NC
9136 set_it_insn_type_last ();
9137
c19d1205 9138 if (inst.operands[0].isreg)
fdfde340
JM
9139 {
9140 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9141 /* We have a register, so this is BLX(2). */
9142 inst.instruction |= inst.operands[0].reg << 3;
9143 }
b99bd4ef
NC
9144 else
9145 {
c19d1205 9146 /* No register. This must be BLX(1). */
2fc8bdac 9147 inst.instruction = 0xf000e800;
00adf2d4 9148 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9149 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9150 }
9151}
9152
c19d1205
ZW
9153static void
9154do_t_branch (void)
b99bd4ef 9155{
0110f2b8 9156 int opcode;
dfa9f0d5
PB
9157 int cond;
9158
e07e6e58
NC
9159 cond = inst.cond;
9160 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9161
9162 if (in_it_block ())
dfa9f0d5
PB
9163 {
9164 /* Conditional branches inside IT blocks are encoded as unconditional
9165 branches. */
9166 cond = COND_ALWAYS;
dfa9f0d5
PB
9167 }
9168 else
9169 cond = inst.cond;
9170
9171 if (cond != COND_ALWAYS)
0110f2b8
PB
9172 opcode = T_MNEM_bcond;
9173 else
9174 opcode = inst.instruction;
9175
9176 if (unified_syntax && inst.size_req == 4)
c19d1205 9177 {
0110f2b8 9178 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9179 if (cond == COND_ALWAYS)
0110f2b8 9180 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9181 else
9182 {
9c2799c2 9183 gas_assert (cond != 0xF);
dfa9f0d5 9184 inst.instruction |= cond << 22;
c19d1205
ZW
9185 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9186 }
9187 }
b99bd4ef
NC
9188 else
9189 {
0110f2b8 9190 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9191 if (cond == COND_ALWAYS)
c19d1205
ZW
9192 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9193 else
b99bd4ef 9194 {
dfa9f0d5 9195 inst.instruction |= cond << 8;
c19d1205 9196 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9197 }
0110f2b8
PB
9198 /* Allow section relaxation. */
9199 if (unified_syntax && inst.size_req != 2)
9200 inst.relax = opcode;
b99bd4ef 9201 }
c19d1205
ZW
9202
9203 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9204}
9205
9206static void
c19d1205 9207do_t_bkpt (void)
b99bd4ef 9208{
dfa9f0d5
PB
9209 constraint (inst.cond != COND_ALWAYS,
9210 _("instruction is always unconditional"));
c19d1205 9211 if (inst.operands[0].present)
b99bd4ef 9212 {
c19d1205
ZW
9213 constraint (inst.operands[0].imm > 255,
9214 _("immediate value out of range"));
9215 inst.instruction |= inst.operands[0].imm;
e07e6e58 9216 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9217 }
b99bd4ef
NC
9218}
9219
9220static void
c19d1205 9221do_t_branch23 (void)
b99bd4ef 9222{
e07e6e58 9223 set_it_insn_type_last ();
c19d1205 9224 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9225 inst.reloc.pc_rel = 1;
9226
4343666d 9227#if defined(OBJ_COFF)
c19d1205
ZW
9228 /* If the destination of the branch is a defined symbol which does not have
9229 the THUMB_FUNC attribute, then we must be calling a function which has
9230 the (interfacearm) attribute. We look for the Thumb entry point to that
9231 function and change the branch to refer to that function instead. */
9232 if ( inst.reloc.exp.X_op == O_symbol
9233 && inst.reloc.exp.X_add_symbol != NULL
9234 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9235 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9236 inst.reloc.exp.X_add_symbol =
9237 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9238#endif
90e4755a
RE
9239}
9240
9241static void
c19d1205 9242do_t_bx (void)
90e4755a 9243{
e07e6e58 9244 set_it_insn_type_last ();
c19d1205
ZW
9245 inst.instruction |= inst.operands[0].reg << 3;
9246 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9247 should cause the alignment to be checked once it is known. This is
9248 because BX PC only works if the instruction is word aligned. */
9249}
90e4755a 9250
c19d1205
ZW
9251static void
9252do_t_bxj (void)
9253{
fdfde340 9254 int Rm;
90e4755a 9255
e07e6e58 9256 set_it_insn_type_last ();
fdfde340
JM
9257 Rm = inst.operands[0].reg;
9258 reject_bad_reg (Rm);
9259 inst.instruction |= Rm << 16;
90e4755a
RE
9260}
9261
9262static void
c19d1205 9263do_t_clz (void)
90e4755a 9264{
fdfde340
JM
9265 unsigned Rd;
9266 unsigned Rm;
9267
9268 Rd = inst.operands[0].reg;
9269 Rm = inst.operands[1].reg;
9270
9271 reject_bad_reg (Rd);
9272 reject_bad_reg (Rm);
9273
9274 inst.instruction |= Rd << 8;
9275 inst.instruction |= Rm << 16;
9276 inst.instruction |= Rm;
c19d1205 9277}
90e4755a 9278
dfa9f0d5
PB
9279static void
9280do_t_cps (void)
9281{
e07e6e58 9282 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9283 inst.instruction |= inst.operands[0].imm;
9284}
9285
c19d1205
ZW
9286static void
9287do_t_cpsi (void)
9288{
e07e6e58 9289 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9290 if (unified_syntax
62b3e311
PB
9291 && (inst.operands[1].present || inst.size_req == 4)
9292 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9293 {
c19d1205
ZW
9294 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9295 inst.instruction = 0xf3af8000;
9296 inst.instruction |= imod << 9;
9297 inst.instruction |= inst.operands[0].imm << 5;
9298 if (inst.operands[1].present)
9299 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9300 }
c19d1205 9301 else
90e4755a 9302 {
62b3e311
PB
9303 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9304 && (inst.operands[0].imm & 4),
9305 _("selected processor does not support 'A' form "
9306 "of this instruction"));
9307 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9308 _("Thumb does not support the 2-argument "
9309 "form of this instruction"));
9310 inst.instruction |= inst.operands[0].imm;
90e4755a 9311 }
90e4755a
RE
9312}
9313
c19d1205
ZW
9314/* THUMB CPY instruction (argument parse). */
9315
90e4755a 9316static void
c19d1205 9317do_t_cpy (void)
90e4755a 9318{
c19d1205 9319 if (inst.size_req == 4)
90e4755a 9320 {
c19d1205
ZW
9321 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9322 inst.instruction |= inst.operands[0].reg << 8;
9323 inst.instruction |= inst.operands[1].reg;
90e4755a 9324 }
c19d1205 9325 else
90e4755a 9326 {
c19d1205
ZW
9327 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9328 inst.instruction |= (inst.operands[0].reg & 0x7);
9329 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9330 }
90e4755a
RE
9331}
9332
90e4755a 9333static void
25fe350b 9334do_t_cbz (void)
90e4755a 9335{
e07e6e58 9336 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9337 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9338 inst.instruction |= inst.operands[0].reg;
9339 inst.reloc.pc_rel = 1;
9340 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9341}
90e4755a 9342
62b3e311
PB
9343static void
9344do_t_dbg (void)
9345{
9346 inst.instruction |= inst.operands[0].imm;
9347}
9348
9349static void
9350do_t_div (void)
9351{
fdfde340
JM
9352 unsigned Rd, Rn, Rm;
9353
9354 Rd = inst.operands[0].reg;
9355 Rn = (inst.operands[1].present
9356 ? inst.operands[1].reg : Rd);
9357 Rm = inst.operands[2].reg;
9358
9359 reject_bad_reg (Rd);
9360 reject_bad_reg (Rn);
9361 reject_bad_reg (Rm);
9362
9363 inst.instruction |= Rd << 8;
9364 inst.instruction |= Rn << 16;
9365 inst.instruction |= Rm;
62b3e311
PB
9366}
9367
c19d1205
ZW
9368static void
9369do_t_hint (void)
9370{
9371 if (unified_syntax && inst.size_req == 4)
9372 inst.instruction = THUMB_OP32 (inst.instruction);
9373 else
9374 inst.instruction = THUMB_OP16 (inst.instruction);
9375}
90e4755a 9376
c19d1205
ZW
9377static void
9378do_t_it (void)
9379{
9380 unsigned int cond = inst.operands[0].imm;
e27ec89e 9381
e07e6e58
NC
9382 set_it_insn_type (IT_INSN);
9383 now_it.mask = (inst.instruction & 0xf) | 0x10;
9384 now_it.cc = cond;
e27ec89e
PB
9385
9386 /* If the condition is a negative condition, invert the mask. */
c19d1205 9387 if ((cond & 0x1) == 0x0)
90e4755a 9388 {
c19d1205 9389 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9390
c19d1205
ZW
9391 if ((mask & 0x7) == 0)
9392 /* no conversion needed */;
9393 else if ((mask & 0x3) == 0)
e27ec89e
PB
9394 mask ^= 0x8;
9395 else if ((mask & 0x1) == 0)
9396 mask ^= 0xC;
c19d1205 9397 else
e27ec89e 9398 mask ^= 0xE;
90e4755a 9399
e27ec89e
PB
9400 inst.instruction &= 0xfff0;
9401 inst.instruction |= mask;
c19d1205 9402 }
90e4755a 9403
c19d1205
ZW
9404 inst.instruction |= cond << 4;
9405}
90e4755a 9406
3c707909
PB
9407/* Helper function used for both push/pop and ldm/stm. */
9408static void
9409encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9410{
9411 bfd_boolean load;
9412
9413 load = (inst.instruction & (1 << 20)) != 0;
9414
9415 if (mask & (1 << 13))
9416 inst.error = _("SP not allowed in register list");
9417 if (load)
9418 {
e07e6e58
NC
9419 if (mask & (1 << 15))
9420 {
9421 if (mask & (1 << 14))
9422 inst.error = _("LR and PC should not both be in register list");
9423 else
9424 set_it_insn_type_last ();
9425 }
3c707909
PB
9426
9427 if ((mask & (1 << base)) != 0
9428 && writeback)
9429 as_warn (_("base register should not be in register list "
9430 "when written back"));
9431 }
9432 else
9433 {
9434 if (mask & (1 << 15))
9435 inst.error = _("PC not allowed in register list");
9436
9437 if (mask & (1 << base))
9438 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9439 }
9440
9441 if ((mask & (mask - 1)) == 0)
9442 {
9443 /* Single register transfers implemented as str/ldr. */
9444 if (writeback)
9445 {
9446 if (inst.instruction & (1 << 23))
9447 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9448 else
9449 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9450 }
9451 else
9452 {
9453 if (inst.instruction & (1 << 23))
9454 inst.instruction = 0x00800000; /* ia -> [base] */
9455 else
9456 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9457 }
9458
9459 inst.instruction |= 0xf8400000;
9460 if (load)
9461 inst.instruction |= 0x00100000;
9462
5f4273c7 9463 mask = ffs (mask) - 1;
3c707909
PB
9464 mask <<= 12;
9465 }
9466 else if (writeback)
9467 inst.instruction |= WRITE_BACK;
9468
9469 inst.instruction |= mask;
9470 inst.instruction |= base << 16;
9471}
9472
c19d1205
ZW
9473static void
9474do_t_ldmstm (void)
9475{
9476 /* This really doesn't seem worth it. */
9477 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9478 _("expression too complex"));
9479 constraint (inst.operands[1].writeback,
9480 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9481
c19d1205
ZW
9482 if (unified_syntax)
9483 {
3c707909
PB
9484 bfd_boolean narrow;
9485 unsigned mask;
9486
9487 narrow = FALSE;
c19d1205
ZW
9488 /* See if we can use a 16-bit instruction. */
9489 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9490 && inst.size_req != 4
3c707909 9491 && !(inst.operands[1].imm & ~0xff))
90e4755a 9492 {
3c707909 9493 mask = 1 << inst.operands[0].reg;
90e4755a 9494
3c707909
PB
9495 if (inst.operands[0].reg <= 7
9496 && (inst.instruction == T_MNEM_stmia
9497 ? inst.operands[0].writeback
9498 : (inst.operands[0].writeback
9499 == !(inst.operands[1].imm & mask))))
90e4755a 9500 {
3c707909
PB
9501 if (inst.instruction == T_MNEM_stmia
9502 && (inst.operands[1].imm & mask)
9503 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9504 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9505 inst.operands[0].reg);
3c707909
PB
9506
9507 inst.instruction = THUMB_OP16 (inst.instruction);
9508 inst.instruction |= inst.operands[0].reg << 8;
9509 inst.instruction |= inst.operands[1].imm;
9510 narrow = TRUE;
90e4755a 9511 }
3c707909
PB
9512 else if (inst.operands[0] .reg == REG_SP
9513 && inst.operands[0].writeback)
90e4755a 9514 {
3c707909
PB
9515 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9516 ? T_MNEM_push : T_MNEM_pop);
9517 inst.instruction |= inst.operands[1].imm;
9518 narrow = TRUE;
90e4755a 9519 }
3c707909
PB
9520 }
9521
9522 if (!narrow)
9523 {
c19d1205
ZW
9524 if (inst.instruction < 0xffff)
9525 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9526
5f4273c7
NC
9527 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9528 inst.operands[0].writeback);
90e4755a
RE
9529 }
9530 }
c19d1205 9531 else
90e4755a 9532 {
c19d1205
ZW
9533 constraint (inst.operands[0].reg > 7
9534 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9535 constraint (inst.instruction != T_MNEM_ldmia
9536 && inst.instruction != T_MNEM_stmia,
9537 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9538 if (inst.instruction == T_MNEM_stmia)
f03698e6 9539 {
c19d1205
ZW
9540 if (!inst.operands[0].writeback)
9541 as_warn (_("this instruction will write back the base register"));
9542 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9543 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9544 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9545 inst.operands[0].reg);
f03698e6 9546 }
c19d1205 9547 else
90e4755a 9548 {
c19d1205
ZW
9549 if (!inst.operands[0].writeback
9550 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9551 as_warn (_("this instruction will write back the base register"));
9552 else if (inst.operands[0].writeback
9553 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9554 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9555 }
9556
c19d1205
ZW
9557 inst.instruction = THUMB_OP16 (inst.instruction);
9558 inst.instruction |= inst.operands[0].reg << 8;
9559 inst.instruction |= inst.operands[1].imm;
9560 }
9561}
e28cd48c 9562
c19d1205
ZW
9563static void
9564do_t_ldrex (void)
9565{
9566 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9567 || inst.operands[1].postind || inst.operands[1].writeback
9568 || inst.operands[1].immisreg || inst.operands[1].shifted
9569 || inst.operands[1].negative,
01cfc07f 9570 BAD_ADDR_MODE);
e28cd48c 9571
c19d1205
ZW
9572 inst.instruction |= inst.operands[0].reg << 12;
9573 inst.instruction |= inst.operands[1].reg << 16;
9574 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9575}
e28cd48c 9576
c19d1205
ZW
9577static void
9578do_t_ldrexd (void)
9579{
9580 if (!inst.operands[1].present)
1cac9012 9581 {
c19d1205
ZW
9582 constraint (inst.operands[0].reg == REG_LR,
9583 _("r14 not allowed as first register "
9584 "when second register is omitted"));
9585 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9586 }
c19d1205
ZW
9587 constraint (inst.operands[0].reg == inst.operands[1].reg,
9588 BAD_OVERLAP);
b99bd4ef 9589
c19d1205
ZW
9590 inst.instruction |= inst.operands[0].reg << 12;
9591 inst.instruction |= inst.operands[1].reg << 8;
9592 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9593}
9594
9595static void
c19d1205 9596do_t_ldst (void)
b99bd4ef 9597{
0110f2b8
PB
9598 unsigned long opcode;
9599 int Rn;
9600
e07e6e58
NC
9601 if (inst.operands[0].isreg
9602 && !inst.operands[0].preind
9603 && inst.operands[0].reg == REG_PC)
9604 set_it_insn_type_last ();
9605
0110f2b8 9606 opcode = inst.instruction;
c19d1205 9607 if (unified_syntax)
b99bd4ef 9608 {
53365c0d
PB
9609 if (!inst.operands[1].isreg)
9610 {
9611 if (opcode <= 0xffff)
9612 inst.instruction = THUMB_OP32 (opcode);
9613 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9614 return;
9615 }
0110f2b8
PB
9616 if (inst.operands[1].isreg
9617 && !inst.operands[1].writeback
c19d1205
ZW
9618 && !inst.operands[1].shifted && !inst.operands[1].postind
9619 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9620 && opcode <= 0xffff
9621 && inst.size_req != 4)
c19d1205 9622 {
0110f2b8
PB
9623 /* Insn may have a 16-bit form. */
9624 Rn = inst.operands[1].reg;
9625 if (inst.operands[1].immisreg)
9626 {
9627 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9628 /* [Rn, Rik] */
0110f2b8
PB
9629 if (Rn <= 7 && inst.operands[1].imm <= 7)
9630 goto op16;
9631 }
9632 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9633 && opcode != T_MNEM_ldrsb)
9634 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9635 || (Rn == REG_SP && opcode == T_MNEM_str))
9636 {
9637 /* [Rn, #const] */
9638 if (Rn > 7)
9639 {
9640 if (Rn == REG_PC)
9641 {
9642 if (inst.reloc.pc_rel)
9643 opcode = T_MNEM_ldr_pc2;
9644 else
9645 opcode = T_MNEM_ldr_pc;
9646 }
9647 else
9648 {
9649 if (opcode == T_MNEM_ldr)
9650 opcode = T_MNEM_ldr_sp;
9651 else
9652 opcode = T_MNEM_str_sp;
9653 }
9654 inst.instruction = inst.operands[0].reg << 8;
9655 }
9656 else
9657 {
9658 inst.instruction = inst.operands[0].reg;
9659 inst.instruction |= inst.operands[1].reg << 3;
9660 }
9661 inst.instruction |= THUMB_OP16 (opcode);
9662 if (inst.size_req == 2)
9663 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9664 else
9665 inst.relax = opcode;
9666 return;
9667 }
c19d1205 9668 }
0110f2b8
PB
9669 /* Definitely a 32-bit variant. */
9670 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9671 inst.instruction |= inst.operands[0].reg << 12;
9672 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9673 return;
9674 }
9675
c19d1205
ZW
9676 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9677
9678 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9679 {
c19d1205
ZW
9680 /* Only [Rn,Rm] is acceptable. */
9681 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9682 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9683 || inst.operands[1].postind || inst.operands[1].shifted
9684 || inst.operands[1].negative,
9685 _("Thumb does not support this addressing mode"));
9686 inst.instruction = THUMB_OP16 (inst.instruction);
9687 goto op16;
b99bd4ef 9688 }
5f4273c7 9689
c19d1205
ZW
9690 inst.instruction = THUMB_OP16 (inst.instruction);
9691 if (!inst.operands[1].isreg)
9692 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9693 return;
b99bd4ef 9694
c19d1205
ZW
9695 constraint (!inst.operands[1].preind
9696 || inst.operands[1].shifted
9697 || inst.operands[1].writeback,
9698 _("Thumb does not support this addressing mode"));
9699 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9700 {
c19d1205
ZW
9701 constraint (inst.instruction & 0x0600,
9702 _("byte or halfword not valid for base register"));
9703 constraint (inst.operands[1].reg == REG_PC
9704 && !(inst.instruction & THUMB_LOAD_BIT),
9705 _("r15 based store not allowed"));
9706 constraint (inst.operands[1].immisreg,
9707 _("invalid base register for register offset"));
b99bd4ef 9708
c19d1205
ZW
9709 if (inst.operands[1].reg == REG_PC)
9710 inst.instruction = T_OPCODE_LDR_PC;
9711 else if (inst.instruction & THUMB_LOAD_BIT)
9712 inst.instruction = T_OPCODE_LDR_SP;
9713 else
9714 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9715
c19d1205
ZW
9716 inst.instruction |= inst.operands[0].reg << 8;
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9718 return;
9719 }
90e4755a 9720
c19d1205
ZW
9721 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9722 if (!inst.operands[1].immisreg)
9723 {
9724 /* Immediate offset. */
9725 inst.instruction |= inst.operands[0].reg;
9726 inst.instruction |= inst.operands[1].reg << 3;
9727 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9728 return;
9729 }
90e4755a 9730
c19d1205
ZW
9731 /* Register offset. */
9732 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9733 constraint (inst.operands[1].negative,
9734 _("Thumb does not support this addressing mode"));
90e4755a 9735
c19d1205
ZW
9736 op16:
9737 switch (inst.instruction)
9738 {
9739 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9740 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9741 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9742 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9743 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9744 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9745 case 0x5600 /* ldrsb */:
9746 case 0x5e00 /* ldrsh */: break;
9747 default: abort ();
9748 }
90e4755a 9749
c19d1205
ZW
9750 inst.instruction |= inst.operands[0].reg;
9751 inst.instruction |= inst.operands[1].reg << 3;
9752 inst.instruction |= inst.operands[1].imm << 6;
9753}
90e4755a 9754
c19d1205
ZW
9755static void
9756do_t_ldstd (void)
9757{
9758 if (!inst.operands[1].present)
b99bd4ef 9759 {
c19d1205
ZW
9760 inst.operands[1].reg = inst.operands[0].reg + 1;
9761 constraint (inst.operands[0].reg == REG_LR,
9762 _("r14 not allowed here"));
b99bd4ef 9763 }
c19d1205
ZW
9764 inst.instruction |= inst.operands[0].reg << 12;
9765 inst.instruction |= inst.operands[1].reg << 8;
9766 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9767}
9768
c19d1205
ZW
9769static void
9770do_t_ldstt (void)
9771{
9772 inst.instruction |= inst.operands[0].reg << 12;
9773 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9774}
a737bd4d 9775
b99bd4ef 9776static void
c19d1205 9777do_t_mla (void)
b99bd4ef 9778{
fdfde340
JM
9779 unsigned Rd, Rn, Rm, Ra;
9780
9781 Rd = inst.operands[0].reg;
9782 Rn = inst.operands[1].reg;
9783 Rm = inst.operands[2].reg;
9784 Ra = inst.operands[3].reg;
9785
9786 reject_bad_reg (Rd);
9787 reject_bad_reg (Rn);
9788 reject_bad_reg (Rm);
9789 reject_bad_reg (Ra);
9790
9791 inst.instruction |= Rd << 8;
9792 inst.instruction |= Rn << 16;
9793 inst.instruction |= Rm;
9794 inst.instruction |= Ra << 12;
c19d1205 9795}
b99bd4ef 9796
c19d1205
ZW
9797static void
9798do_t_mlal (void)
9799{
fdfde340
JM
9800 unsigned RdLo, RdHi, Rn, Rm;
9801
9802 RdLo = inst.operands[0].reg;
9803 RdHi = inst.operands[1].reg;
9804 Rn = inst.operands[2].reg;
9805 Rm = inst.operands[3].reg;
9806
9807 reject_bad_reg (RdLo);
9808 reject_bad_reg (RdHi);
9809 reject_bad_reg (Rn);
9810 reject_bad_reg (Rm);
9811
9812 inst.instruction |= RdLo << 12;
9813 inst.instruction |= RdHi << 8;
9814 inst.instruction |= Rn << 16;
9815 inst.instruction |= Rm;
c19d1205 9816}
b99bd4ef 9817
c19d1205
ZW
9818static void
9819do_t_mov_cmp (void)
9820{
fdfde340
JM
9821 unsigned Rn, Rm;
9822
9823 Rn = inst.operands[0].reg;
9824 Rm = inst.operands[1].reg;
9825
e07e6e58
NC
9826 if (Rn == REG_PC)
9827 set_it_insn_type_last ();
9828
c19d1205 9829 if (unified_syntax)
b99bd4ef 9830 {
c19d1205
ZW
9831 int r0off = (inst.instruction == T_MNEM_mov
9832 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9833 unsigned long opcode;
3d388997
PB
9834 bfd_boolean narrow;
9835 bfd_boolean low_regs;
9836
fdfde340 9837 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 9838 opcode = inst.instruction;
e07e6e58 9839 if (in_it_block ())
0110f2b8 9840 narrow = opcode != T_MNEM_movs;
3d388997 9841 else
0110f2b8 9842 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9843 if (inst.size_req == 4
9844 || inst.operands[1].shifted)
9845 narrow = FALSE;
9846
efd81785
PB
9847 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9848 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9849 && !inst.operands[1].shifted
fdfde340
JM
9850 && Rn == REG_PC
9851 && Rm == REG_LR)
efd81785
PB
9852 {
9853 inst.instruction = T2_SUBS_PC_LR;
9854 return;
9855 }
9856
fdfde340
JM
9857 if (opcode == T_MNEM_cmp)
9858 {
9859 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
9860 if (narrow)
9861 {
9862 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9863 but valid. */
9864 warn_deprecated_sp (Rm);
9865 /* R15 was documented as a valid choice for Rm in ARMv6,
9866 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9867 tools reject R15, so we do too. */
9868 constraint (Rm == REG_PC, BAD_PC);
9869 }
9870 else
9871 reject_bad_reg (Rm);
fdfde340
JM
9872 }
9873 else if (opcode == T_MNEM_mov
9874 || opcode == T_MNEM_movs)
9875 {
9876 if (inst.operands[1].isreg)
9877 {
9878 if (opcode == T_MNEM_movs)
9879 {
9880 reject_bad_reg (Rn);
9881 reject_bad_reg (Rm);
9882 }
9883 else if ((Rn == REG_SP || Rn == REG_PC)
9884 && (Rm == REG_SP || Rm == REG_PC))
9885 reject_bad_reg (Rm);
9886 }
9887 else
9888 reject_bad_reg (Rn);
9889 }
9890
c19d1205
ZW
9891 if (!inst.operands[1].isreg)
9892 {
0110f2b8 9893 /* Immediate operand. */
e07e6e58 9894 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
9895 narrow = 0;
9896 if (low_regs && narrow)
9897 {
9898 inst.instruction = THUMB_OP16 (opcode);
fdfde340 9899 inst.instruction |= Rn << 8;
0110f2b8
PB
9900 if (inst.size_req == 2)
9901 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9902 else
9903 inst.relax = opcode;
9904 }
9905 else
9906 {
9907 inst.instruction = THUMB_OP32 (inst.instruction);
9908 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9909 inst.instruction |= Rn << r0off;
0110f2b8
PB
9910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9911 }
c19d1205 9912 }
728ca7c9
PB
9913 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9914 && (inst.instruction == T_MNEM_mov
9915 || inst.instruction == T_MNEM_movs))
9916 {
9917 /* Register shifts are encoded as separate shift instructions. */
9918 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9919
e07e6e58 9920 if (in_it_block ())
728ca7c9
PB
9921 narrow = !flags;
9922 else
9923 narrow = flags;
9924
9925 if (inst.size_req == 4)
9926 narrow = FALSE;
9927
9928 if (!low_regs || inst.operands[1].imm > 7)
9929 narrow = FALSE;
9930
fdfde340 9931 if (Rn != Rm)
728ca7c9
PB
9932 narrow = FALSE;
9933
9934 switch (inst.operands[1].shift_kind)
9935 {
9936 case SHIFT_LSL:
9937 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9938 break;
9939 case SHIFT_ASR:
9940 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9941 break;
9942 case SHIFT_LSR:
9943 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9944 break;
9945 case SHIFT_ROR:
9946 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9947 break;
9948 default:
5f4273c7 9949 abort ();
728ca7c9
PB
9950 }
9951
9952 inst.instruction = opcode;
9953 if (narrow)
9954 {
fdfde340 9955 inst.instruction |= Rn;
728ca7c9
PB
9956 inst.instruction |= inst.operands[1].imm << 3;
9957 }
9958 else
9959 {
9960 if (flags)
9961 inst.instruction |= CONDS_BIT;
9962
fdfde340
JM
9963 inst.instruction |= Rn << 8;
9964 inst.instruction |= Rm << 16;
728ca7c9
PB
9965 inst.instruction |= inst.operands[1].imm;
9966 }
9967 }
3d388997 9968 else if (!narrow)
c19d1205 9969 {
728ca7c9
PB
9970 /* Some mov with immediate shift have narrow variants.
9971 Register shifts are handled above. */
9972 if (low_regs && inst.operands[1].shifted
9973 && (inst.instruction == T_MNEM_mov
9974 || inst.instruction == T_MNEM_movs))
9975 {
e07e6e58 9976 if (in_it_block ())
728ca7c9
PB
9977 narrow = (inst.instruction == T_MNEM_mov);
9978 else
9979 narrow = (inst.instruction == T_MNEM_movs);
9980 }
9981
9982 if (narrow)
9983 {
9984 switch (inst.operands[1].shift_kind)
9985 {
9986 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9987 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9988 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9989 default: narrow = FALSE; break;
9990 }
9991 }
9992
9993 if (narrow)
9994 {
fdfde340
JM
9995 inst.instruction |= Rn;
9996 inst.instruction |= Rm << 3;
728ca7c9
PB
9997 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9998 }
9999 else
10000 {
10001 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10002 inst.instruction |= Rn << r0off;
728ca7c9
PB
10003 encode_thumb32_shifted_operand (1);
10004 }
c19d1205
ZW
10005 }
10006 else
10007 switch (inst.instruction)
10008 {
10009 case T_MNEM_mov:
10010 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10011 inst.instruction |= (Rn & 0x8) << 4;
10012 inst.instruction |= (Rn & 0x7);
10013 inst.instruction |= Rm << 3;
c19d1205 10014 break;
b99bd4ef 10015
c19d1205
ZW
10016 case T_MNEM_movs:
10017 /* We know we have low registers at this point.
10018 Generate ADD Rd, Rs, #0. */
10019 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10020 inst.instruction |= Rn;
10021 inst.instruction |= Rm << 3;
c19d1205
ZW
10022 break;
10023
10024 case T_MNEM_cmp:
3d388997 10025 if (low_regs)
c19d1205
ZW
10026 {
10027 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10028 inst.instruction |= Rn;
10029 inst.instruction |= Rm << 3;
c19d1205
ZW
10030 }
10031 else
10032 {
10033 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10034 inst.instruction |= (Rn & 0x8) << 4;
10035 inst.instruction |= (Rn & 0x7);
10036 inst.instruction |= Rm << 3;
c19d1205
ZW
10037 }
10038 break;
10039 }
b99bd4ef
NC
10040 return;
10041 }
10042
c19d1205
ZW
10043 inst.instruction = THUMB_OP16 (inst.instruction);
10044 if (inst.operands[1].isreg)
b99bd4ef 10045 {
fdfde340 10046 if (Rn < 8 && Rm < 8)
b99bd4ef 10047 {
c19d1205
ZW
10048 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10049 since a MOV instruction produces unpredictable results. */
10050 if (inst.instruction == T_OPCODE_MOV_I8)
10051 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10052 else
c19d1205 10053 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10054
fdfde340
JM
10055 inst.instruction |= Rn;
10056 inst.instruction |= Rm << 3;
b99bd4ef
NC
10057 }
10058 else
10059 {
c19d1205
ZW
10060 if (inst.instruction == T_OPCODE_MOV_I8)
10061 inst.instruction = T_OPCODE_MOV_HR;
10062 else
10063 inst.instruction = T_OPCODE_CMP_HR;
10064 do_t_cpy ();
b99bd4ef
NC
10065 }
10066 }
c19d1205 10067 else
b99bd4ef 10068 {
fdfde340 10069 constraint (Rn > 7,
c19d1205 10070 _("only lo regs allowed with immediate"));
fdfde340 10071 inst.instruction |= Rn << 8;
c19d1205
ZW
10072 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10073 }
10074}
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_t_mov16 (void)
10078{
fdfde340 10079 unsigned Rd;
b6895b4f
PB
10080 bfd_vma imm;
10081 bfd_boolean top;
10082
10083 top = (inst.instruction & 0x00800000) != 0;
10084 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10085 {
10086 constraint (top, _(":lower16: not allowed this instruction"));
10087 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10088 }
10089 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10090 {
10091 constraint (!top, _(":upper16: not allowed this instruction"));
10092 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10093 }
10094
fdfde340
JM
10095 Rd = inst.operands[0].reg;
10096 reject_bad_reg (Rd);
10097
10098 inst.instruction |= Rd << 8;
b6895b4f
PB
10099 if (inst.reloc.type == BFD_RELOC_UNUSED)
10100 {
10101 imm = inst.reloc.exp.X_add_number;
10102 inst.instruction |= (imm & 0xf000) << 4;
10103 inst.instruction |= (imm & 0x0800) << 15;
10104 inst.instruction |= (imm & 0x0700) << 4;
10105 inst.instruction |= (imm & 0x00ff);
10106 }
c19d1205 10107}
b99bd4ef 10108
c19d1205
ZW
10109static void
10110do_t_mvn_tst (void)
10111{
fdfde340
JM
10112 unsigned Rn, Rm;
10113
10114 Rn = inst.operands[0].reg;
10115 Rm = inst.operands[1].reg;
10116
10117 if (inst.instruction == T_MNEM_cmp
10118 || inst.instruction == T_MNEM_cmn)
10119 constraint (Rn == REG_PC, BAD_PC);
10120 else
10121 reject_bad_reg (Rn);
10122 reject_bad_reg (Rm);
10123
c19d1205
ZW
10124 if (unified_syntax)
10125 {
10126 int r0off = (inst.instruction == T_MNEM_mvn
10127 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10128 bfd_boolean narrow;
10129
10130 if (inst.size_req == 4
10131 || inst.instruction > 0xffff
10132 || inst.operands[1].shifted
fdfde340 10133 || Rn > 7 || Rm > 7)
3d388997
PB
10134 narrow = FALSE;
10135 else if (inst.instruction == T_MNEM_cmn)
10136 narrow = TRUE;
10137 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10138 narrow = !in_it_block ();
3d388997 10139 else
e07e6e58 10140 narrow = in_it_block ();
3d388997 10141
c19d1205 10142 if (!inst.operands[1].isreg)
b99bd4ef 10143 {
c19d1205
ZW
10144 /* For an immediate, we always generate a 32-bit opcode;
10145 section relaxation will shrink it later if possible. */
10146 if (inst.instruction < 0xffff)
10147 inst.instruction = THUMB_OP32 (inst.instruction);
10148 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10149 inst.instruction |= Rn << r0off;
c19d1205 10150 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10151 }
c19d1205 10152 else
b99bd4ef 10153 {
c19d1205 10154 /* See if we can do this with a 16-bit instruction. */
3d388997 10155 if (narrow)
b99bd4ef 10156 {
c19d1205 10157 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10158 inst.instruction |= Rn;
10159 inst.instruction |= Rm << 3;
b99bd4ef 10160 }
c19d1205 10161 else
b99bd4ef 10162 {
c19d1205
ZW
10163 constraint (inst.operands[1].shifted
10164 && inst.operands[1].immisreg,
10165 _("shift must be constant"));
10166 if (inst.instruction < 0xffff)
10167 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10168 inst.instruction |= Rn << r0off;
c19d1205 10169 encode_thumb32_shifted_operand (1);
b99bd4ef 10170 }
b99bd4ef
NC
10171 }
10172 }
10173 else
10174 {
c19d1205
ZW
10175 constraint (inst.instruction > 0xffff
10176 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10177 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10178 _("unshifted register required"));
fdfde340 10179 constraint (Rn > 7 || Rm > 7,
c19d1205 10180 BAD_HIREG);
b99bd4ef 10181
c19d1205 10182 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10183 inst.instruction |= Rn;
10184 inst.instruction |= Rm << 3;
b99bd4ef 10185 }
b99bd4ef
NC
10186}
10187
b05fe5cf 10188static void
c19d1205 10189do_t_mrs (void)
b05fe5cf 10190{
fdfde340 10191 unsigned Rd;
62b3e311 10192 int flags;
037e8744
JB
10193
10194 if (do_vfp_nsyn_mrs () == SUCCESS)
10195 return;
10196
62b3e311
PB
10197 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10198 if (flags == 0)
10199 {
7e806470 10200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10201 _("selected processor does not support "
10202 "requested special purpose register"));
10203 }
10204 else
10205 {
10206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10207 _("selected processor does not support "
44bf2362 10208 "requested special purpose register"));
62b3e311
PB
10209 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10210 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10211 _("'CPSR' or 'SPSR' expected"));
10212 }
5f4273c7 10213
fdfde340
JM
10214 Rd = inst.operands[0].reg;
10215 reject_bad_reg (Rd);
10216
10217 inst.instruction |= Rd << 8;
62b3e311
PB
10218 inst.instruction |= (flags & SPSR_BIT) >> 2;
10219 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10220}
b05fe5cf 10221
c19d1205
ZW
10222static void
10223do_t_msr (void)
10224{
62b3e311 10225 int flags;
fdfde340 10226 unsigned Rn;
62b3e311 10227
037e8744
JB
10228 if (do_vfp_nsyn_msr () == SUCCESS)
10229 return;
10230
c19d1205
ZW
10231 constraint (!inst.operands[1].isreg,
10232 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10233 flags = inst.operands[0].imm;
10234 if (flags & ~0xff)
10235 {
10236 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10237 _("selected processor does not support "
10238 "requested special purpose register"));
10239 }
10240 else
10241 {
7e806470 10242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10243 _("selected processor does not support "
10244 "requested special purpose register"));
10245 flags |= PSR_f;
10246 }
fdfde340
JM
10247
10248 Rn = inst.operands[1].reg;
10249 reject_bad_reg (Rn);
10250
62b3e311
PB
10251 inst.instruction |= (flags & SPSR_BIT) >> 2;
10252 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10253 inst.instruction |= (flags & 0xff);
fdfde340 10254 inst.instruction |= Rn << 16;
c19d1205 10255}
b05fe5cf 10256
c19d1205
ZW
10257static void
10258do_t_mul (void)
10259{
17828f45 10260 bfd_boolean narrow;
fdfde340 10261 unsigned Rd, Rn, Rm;
17828f45 10262
c19d1205
ZW
10263 if (!inst.operands[2].present)
10264 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10265
fdfde340
JM
10266 Rd = inst.operands[0].reg;
10267 Rn = inst.operands[1].reg;
10268 Rm = inst.operands[2].reg;
10269
17828f45 10270 if (unified_syntax)
b05fe5cf 10271 {
17828f45 10272 if (inst.size_req == 4
fdfde340
JM
10273 || (Rd != Rn
10274 && Rd != Rm)
10275 || Rn > 7
10276 || Rm > 7)
17828f45
JM
10277 narrow = FALSE;
10278 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10279 narrow = !in_it_block ();
17828f45 10280 else
e07e6e58 10281 narrow = in_it_block ();
b05fe5cf 10282 }
c19d1205 10283 else
b05fe5cf 10284 {
17828f45 10285 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10286 constraint (Rn > 7 || Rm > 7,
c19d1205 10287 BAD_HIREG);
17828f45
JM
10288 narrow = TRUE;
10289 }
b05fe5cf 10290
17828f45
JM
10291 if (narrow)
10292 {
10293 /* 16-bit MULS/Conditional MUL. */
c19d1205 10294 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10295 inst.instruction |= Rd;
b05fe5cf 10296
fdfde340
JM
10297 if (Rd == Rn)
10298 inst.instruction |= Rm << 3;
10299 else if (Rd == Rm)
10300 inst.instruction |= Rn << 3;
c19d1205
ZW
10301 else
10302 constraint (1, _("dest must overlap one source register"));
10303 }
17828f45
JM
10304 else
10305 {
e07e6e58
NC
10306 constraint (inst.instruction != T_MNEM_mul,
10307 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10308 /* 32-bit MUL. */
10309 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10310 inst.instruction |= Rd << 8;
10311 inst.instruction |= Rn << 16;
10312 inst.instruction |= Rm << 0;
10313
10314 reject_bad_reg (Rd);
10315 reject_bad_reg (Rn);
10316 reject_bad_reg (Rm);
17828f45 10317 }
c19d1205 10318}
b05fe5cf 10319
c19d1205
ZW
10320static void
10321do_t_mull (void)
10322{
fdfde340 10323 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10324
fdfde340
JM
10325 RdLo = inst.operands[0].reg;
10326 RdHi = inst.operands[1].reg;
10327 Rn = inst.operands[2].reg;
10328 Rm = inst.operands[3].reg;
10329
10330 reject_bad_reg (RdLo);
10331 reject_bad_reg (RdHi);
10332 reject_bad_reg (Rn);
10333 reject_bad_reg (Rm);
10334
10335 inst.instruction |= RdLo << 12;
10336 inst.instruction |= RdHi << 8;
10337 inst.instruction |= Rn << 16;
10338 inst.instruction |= Rm;
10339
10340 if (RdLo == RdHi)
c19d1205
ZW
10341 as_tsktsk (_("rdhi and rdlo must be different"));
10342}
b05fe5cf 10343
c19d1205
ZW
10344static void
10345do_t_nop (void)
10346{
e07e6e58
NC
10347 set_it_insn_type (NEUTRAL_IT_INSN);
10348
c19d1205
ZW
10349 if (unified_syntax)
10350 {
10351 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10352 {
c19d1205
ZW
10353 inst.instruction = THUMB_OP32 (inst.instruction);
10354 inst.instruction |= inst.operands[0].imm;
10355 }
10356 else
10357 {
bc2d1808
NC
10358 /* PR9722: Check for Thumb2 availability before
10359 generating a thumb2 nop instruction. */
10360 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10361 {
10362 inst.instruction = THUMB_OP16 (inst.instruction);
10363 inst.instruction |= inst.operands[0].imm << 4;
10364 }
10365 else
10366 inst.instruction = 0x46c0;
c19d1205
ZW
10367 }
10368 }
10369 else
10370 {
10371 constraint (inst.operands[0].present,
10372 _("Thumb does not support NOP with hints"));
10373 inst.instruction = 0x46c0;
10374 }
10375}
b05fe5cf 10376
c19d1205
ZW
10377static void
10378do_t_neg (void)
10379{
10380 if (unified_syntax)
10381 {
3d388997
PB
10382 bfd_boolean narrow;
10383
10384 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10385 narrow = !in_it_block ();
3d388997 10386 else
e07e6e58 10387 narrow = in_it_block ();
3d388997
PB
10388 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10389 narrow = FALSE;
10390 if (inst.size_req == 4)
10391 narrow = FALSE;
10392
10393 if (!narrow)
c19d1205
ZW
10394 {
10395 inst.instruction = THUMB_OP32 (inst.instruction);
10396 inst.instruction |= inst.operands[0].reg << 8;
10397 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10398 }
10399 else
10400 {
c19d1205
ZW
10401 inst.instruction = THUMB_OP16 (inst.instruction);
10402 inst.instruction |= inst.operands[0].reg;
10403 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10404 }
10405 }
10406 else
10407 {
c19d1205
ZW
10408 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10409 BAD_HIREG);
10410 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10411
10412 inst.instruction = THUMB_OP16 (inst.instruction);
10413 inst.instruction |= inst.operands[0].reg;
10414 inst.instruction |= inst.operands[1].reg << 3;
10415 }
10416}
10417
1c444d06
JM
10418static void
10419do_t_orn (void)
10420{
10421 unsigned Rd, Rn;
10422
10423 Rd = inst.operands[0].reg;
10424 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10425
fdfde340
JM
10426 reject_bad_reg (Rd);
10427 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10428 reject_bad_reg (Rn);
10429
1c444d06
JM
10430 inst.instruction |= Rd << 8;
10431 inst.instruction |= Rn << 16;
10432
10433 if (!inst.operands[2].isreg)
10434 {
10435 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10436 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10437 }
10438 else
10439 {
10440 unsigned Rm;
10441
10442 Rm = inst.operands[2].reg;
fdfde340 10443 reject_bad_reg (Rm);
1c444d06
JM
10444
10445 constraint (inst.operands[2].shifted
10446 && inst.operands[2].immisreg,
10447 _("shift must be constant"));
10448 encode_thumb32_shifted_operand (2);
10449 }
10450}
10451
c19d1205
ZW
10452static void
10453do_t_pkhbt (void)
10454{
fdfde340
JM
10455 unsigned Rd, Rn, Rm;
10456
10457 Rd = inst.operands[0].reg;
10458 Rn = inst.operands[1].reg;
10459 Rm = inst.operands[2].reg;
10460
10461 reject_bad_reg (Rd);
10462 reject_bad_reg (Rn);
10463 reject_bad_reg (Rm);
10464
10465 inst.instruction |= Rd << 8;
10466 inst.instruction |= Rn << 16;
10467 inst.instruction |= Rm;
c19d1205
ZW
10468 if (inst.operands[3].present)
10469 {
10470 unsigned int val = inst.reloc.exp.X_add_number;
10471 constraint (inst.reloc.exp.X_op != O_constant,
10472 _("expression too complex"));
10473 inst.instruction |= (val & 0x1c) << 10;
10474 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10475 }
c19d1205 10476}
b05fe5cf 10477
c19d1205
ZW
10478static void
10479do_t_pkhtb (void)
10480{
10481 if (!inst.operands[3].present)
10482 inst.instruction &= ~0x00000020;
10483 do_t_pkhbt ();
b05fe5cf
ZW
10484}
10485
c19d1205
ZW
10486static void
10487do_t_pld (void)
10488{
fdfde340
JM
10489 if (inst.operands[0].immisreg)
10490 reject_bad_reg (inst.operands[0].imm);
10491
c19d1205
ZW
10492 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10493}
b05fe5cf 10494
c19d1205
ZW
10495static void
10496do_t_push_pop (void)
b99bd4ef 10497{
e9f89963 10498 unsigned mask;
5f4273c7 10499
c19d1205
ZW
10500 constraint (inst.operands[0].writeback,
10501 _("push/pop do not support {reglist}^"));
10502 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10503 _("expression too complex"));
b99bd4ef 10504
e9f89963
PB
10505 mask = inst.operands[0].imm;
10506 if ((mask & ~0xff) == 0)
3c707909 10507 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10508 else if ((inst.instruction == T_MNEM_push
e9f89963 10509 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10510 || (inst.instruction == T_MNEM_pop
e9f89963 10511 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10512 {
c19d1205
ZW
10513 inst.instruction = THUMB_OP16 (inst.instruction);
10514 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10515 inst.instruction |= mask & 0xff;
c19d1205
ZW
10516 }
10517 else if (unified_syntax)
10518 {
3c707909 10519 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10520 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10521 }
10522 else
10523 {
10524 inst.error = _("invalid register list to push/pop instruction");
10525 return;
10526 }
c19d1205 10527}
b99bd4ef 10528
c19d1205
ZW
10529static void
10530do_t_rbit (void)
10531{
fdfde340
JM
10532 unsigned Rd, Rm;
10533
10534 Rd = inst.operands[0].reg;
10535 Rm = inst.operands[1].reg;
10536
10537 reject_bad_reg (Rd);
10538 reject_bad_reg (Rm);
10539
10540 inst.instruction |= Rd << 8;
10541 inst.instruction |= Rm << 16;
10542 inst.instruction |= Rm;
c19d1205 10543}
b99bd4ef 10544
c19d1205
ZW
10545static void
10546do_t_rev (void)
10547{
fdfde340
JM
10548 unsigned Rd, Rm;
10549
10550 Rd = inst.operands[0].reg;
10551 Rm = inst.operands[1].reg;
10552
10553 reject_bad_reg (Rd);
10554 reject_bad_reg (Rm);
10555
10556 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10557 && inst.size_req != 4)
10558 {
10559 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10560 inst.instruction |= Rd;
10561 inst.instruction |= Rm << 3;
c19d1205
ZW
10562 }
10563 else if (unified_syntax)
10564 {
10565 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10566 inst.instruction |= Rd << 8;
10567 inst.instruction |= Rm << 16;
10568 inst.instruction |= Rm;
c19d1205
ZW
10569 }
10570 else
10571 inst.error = BAD_HIREG;
10572}
b99bd4ef 10573
1c444d06
JM
10574static void
10575do_t_rrx (void)
10576{
10577 unsigned Rd, Rm;
10578
10579 Rd = inst.operands[0].reg;
10580 Rm = inst.operands[1].reg;
10581
fdfde340
JM
10582 reject_bad_reg (Rd);
10583 reject_bad_reg (Rm);
10584
1c444d06
JM
10585 inst.instruction |= Rd << 8;
10586 inst.instruction |= Rm;
10587}
10588
c19d1205
ZW
10589static void
10590do_t_rsb (void)
10591{
fdfde340 10592 unsigned Rd, Rs;
b99bd4ef 10593
c19d1205
ZW
10594 Rd = inst.operands[0].reg;
10595 Rs = (inst.operands[1].present
10596 ? inst.operands[1].reg /* Rd, Rs, foo */
10597 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10598
fdfde340
JM
10599 reject_bad_reg (Rd);
10600 reject_bad_reg (Rs);
10601 if (inst.operands[2].isreg)
10602 reject_bad_reg (inst.operands[2].reg);
10603
c19d1205
ZW
10604 inst.instruction |= Rd << 8;
10605 inst.instruction |= Rs << 16;
10606 if (!inst.operands[2].isreg)
10607 {
026d3abb
PB
10608 bfd_boolean narrow;
10609
10610 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10611 narrow = !in_it_block ();
026d3abb 10612 else
e07e6e58 10613 narrow = in_it_block ();
026d3abb
PB
10614
10615 if (Rd > 7 || Rs > 7)
10616 narrow = FALSE;
10617
10618 if (inst.size_req == 4 || !unified_syntax)
10619 narrow = FALSE;
10620
10621 if (inst.reloc.exp.X_op != O_constant
10622 || inst.reloc.exp.X_add_number != 0)
10623 narrow = FALSE;
10624
10625 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10626 relaxation, but it doesn't seem worth the hassle. */
10627 if (narrow)
10628 {
10629 inst.reloc.type = BFD_RELOC_UNUSED;
10630 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10631 inst.instruction |= Rs << 3;
10632 inst.instruction |= Rd;
10633 }
10634 else
10635 {
10636 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10637 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10638 }
c19d1205
ZW
10639 }
10640 else
10641 encode_thumb32_shifted_operand (2);
10642}
b99bd4ef 10643
c19d1205
ZW
10644static void
10645do_t_setend (void)
10646{
e07e6e58 10647 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10648 if (inst.operands[0].imm)
10649 inst.instruction |= 0x8;
10650}
b99bd4ef 10651
c19d1205
ZW
10652static void
10653do_t_shift (void)
10654{
10655 if (!inst.operands[1].present)
10656 inst.operands[1].reg = inst.operands[0].reg;
10657
10658 if (unified_syntax)
10659 {
3d388997
PB
10660 bfd_boolean narrow;
10661 int shift_kind;
10662
10663 switch (inst.instruction)
10664 {
10665 case T_MNEM_asr:
10666 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10667 case T_MNEM_lsl:
10668 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10669 case T_MNEM_lsr:
10670 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10671 case T_MNEM_ror:
10672 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10673 default: abort ();
10674 }
10675
10676 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10677 narrow = !in_it_block ();
3d388997 10678 else
e07e6e58 10679 narrow = in_it_block ();
3d388997
PB
10680 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10681 narrow = FALSE;
10682 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10683 narrow = FALSE;
10684 if (inst.operands[2].isreg
10685 && (inst.operands[1].reg != inst.operands[0].reg
10686 || inst.operands[2].reg > 7))
10687 narrow = FALSE;
10688 if (inst.size_req == 4)
10689 narrow = FALSE;
10690
fdfde340
JM
10691 reject_bad_reg (inst.operands[0].reg);
10692 reject_bad_reg (inst.operands[1].reg);
10693
3d388997 10694 if (!narrow)
c19d1205
ZW
10695 {
10696 if (inst.operands[2].isreg)
b99bd4ef 10697 {
fdfde340 10698 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10699 inst.instruction = THUMB_OP32 (inst.instruction);
10700 inst.instruction |= inst.operands[0].reg << 8;
10701 inst.instruction |= inst.operands[1].reg << 16;
10702 inst.instruction |= inst.operands[2].reg;
10703 }
10704 else
10705 {
10706 inst.operands[1].shifted = 1;
3d388997 10707 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10708 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10709 ? T_MNEM_movs : T_MNEM_mov);
10710 inst.instruction |= inst.operands[0].reg << 8;
10711 encode_thumb32_shifted_operand (1);
10712 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10713 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10714 }
10715 }
10716 else
10717 {
c19d1205 10718 if (inst.operands[2].isreg)
b99bd4ef 10719 {
3d388997 10720 switch (shift_kind)
b99bd4ef 10721 {
3d388997
PB
10722 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10723 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10724 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10725 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10726 default: abort ();
b99bd4ef 10727 }
5f4273c7 10728
c19d1205
ZW
10729 inst.instruction |= inst.operands[0].reg;
10730 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10731 }
10732 else
10733 {
3d388997 10734 switch (shift_kind)
b99bd4ef 10735 {
3d388997
PB
10736 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10737 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10738 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10739 default: abort ();
b99bd4ef 10740 }
c19d1205
ZW
10741 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10742 inst.instruction |= inst.operands[0].reg;
10743 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10744 }
10745 }
c19d1205
ZW
10746 }
10747 else
10748 {
10749 constraint (inst.operands[0].reg > 7
10750 || inst.operands[1].reg > 7, BAD_HIREG);
10751 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10752
c19d1205
ZW
10753 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10754 {
10755 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10756 constraint (inst.operands[0].reg != inst.operands[1].reg,
10757 _("source1 and dest must be same register"));
b99bd4ef 10758
c19d1205
ZW
10759 switch (inst.instruction)
10760 {
10761 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10762 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10763 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10764 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10765 default: abort ();
10766 }
5f4273c7 10767
c19d1205
ZW
10768 inst.instruction |= inst.operands[0].reg;
10769 inst.instruction |= inst.operands[2].reg << 3;
10770 }
10771 else
b99bd4ef 10772 {
c19d1205
ZW
10773 switch (inst.instruction)
10774 {
10775 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10776 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10777 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10778 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10779 default: abort ();
10780 }
10781 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10782 inst.instruction |= inst.operands[0].reg;
10783 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10784 }
10785 }
b99bd4ef
NC
10786}
10787
10788static void
c19d1205 10789do_t_simd (void)
b99bd4ef 10790{
fdfde340
JM
10791 unsigned Rd, Rn, Rm;
10792
10793 Rd = inst.operands[0].reg;
10794 Rn = inst.operands[1].reg;
10795 Rm = inst.operands[2].reg;
10796
10797 reject_bad_reg (Rd);
10798 reject_bad_reg (Rn);
10799 reject_bad_reg (Rm);
10800
10801 inst.instruction |= Rd << 8;
10802 inst.instruction |= Rn << 16;
10803 inst.instruction |= Rm;
c19d1205 10804}
b99bd4ef 10805
c19d1205 10806static void
3eb17e6b 10807do_t_smc (void)
c19d1205
ZW
10808{
10809 unsigned int value = inst.reloc.exp.X_add_number;
10810 constraint (inst.reloc.exp.X_op != O_constant,
10811 _("expression too complex"));
10812 inst.reloc.type = BFD_RELOC_UNUSED;
10813 inst.instruction |= (value & 0xf000) >> 12;
10814 inst.instruction |= (value & 0x0ff0);
10815 inst.instruction |= (value & 0x000f) << 16;
10816}
b99bd4ef 10817
c19d1205 10818static void
3a21c15a 10819do_t_ssat_usat (int bias)
c19d1205 10820{
fdfde340
JM
10821 unsigned Rd, Rn;
10822
10823 Rd = inst.operands[0].reg;
10824 Rn = inst.operands[2].reg;
10825
10826 reject_bad_reg (Rd);
10827 reject_bad_reg (Rn);
10828
10829 inst.instruction |= Rd << 8;
3a21c15a 10830 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 10831 inst.instruction |= Rn << 16;
b99bd4ef 10832
c19d1205 10833 if (inst.operands[3].present)
b99bd4ef 10834 {
3a21c15a
NC
10835 offsetT shift_amount = inst.reloc.exp.X_add_number;
10836
10837 inst.reloc.type = BFD_RELOC_UNUSED;
10838
c19d1205
ZW
10839 constraint (inst.reloc.exp.X_op != O_constant,
10840 _("expression too complex"));
b99bd4ef 10841
3a21c15a 10842 if (shift_amount != 0)
6189168b 10843 {
3a21c15a
NC
10844 constraint (shift_amount > 31,
10845 _("shift expression is too large"));
10846
c19d1205 10847 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
10848 inst.instruction |= 0x00200000; /* sh bit. */
10849
10850 inst.instruction |= (shift_amount & 0x1c) << 10;
10851 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
10852 }
10853 }
b99bd4ef 10854}
3a21c15a
NC
10855
10856static void
10857do_t_ssat (void)
10858{
10859 do_t_ssat_usat (1);
10860}
b99bd4ef 10861
0dd132b6 10862static void
c19d1205 10863do_t_ssat16 (void)
0dd132b6 10864{
fdfde340
JM
10865 unsigned Rd, Rn;
10866
10867 Rd = inst.operands[0].reg;
10868 Rn = inst.operands[2].reg;
10869
10870 reject_bad_reg (Rd);
10871 reject_bad_reg (Rn);
10872
10873 inst.instruction |= Rd << 8;
c19d1205 10874 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 10875 inst.instruction |= Rn << 16;
c19d1205 10876}
0dd132b6 10877
c19d1205
ZW
10878static void
10879do_t_strex (void)
10880{
10881 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10882 || inst.operands[2].postind || inst.operands[2].writeback
10883 || inst.operands[2].immisreg || inst.operands[2].shifted
10884 || inst.operands[2].negative,
01cfc07f 10885 BAD_ADDR_MODE);
0dd132b6 10886
c19d1205
ZW
10887 inst.instruction |= inst.operands[0].reg << 8;
10888 inst.instruction |= inst.operands[1].reg << 12;
10889 inst.instruction |= inst.operands[2].reg << 16;
10890 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10891}
10892
b99bd4ef 10893static void
c19d1205 10894do_t_strexd (void)
b99bd4ef 10895{
c19d1205
ZW
10896 if (!inst.operands[2].present)
10897 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10898
c19d1205
ZW
10899 constraint (inst.operands[0].reg == inst.operands[1].reg
10900 || inst.operands[0].reg == inst.operands[2].reg
10901 || inst.operands[0].reg == inst.operands[3].reg
10902 || inst.operands[1].reg == inst.operands[2].reg,
10903 BAD_OVERLAP);
b99bd4ef 10904
c19d1205
ZW
10905 inst.instruction |= inst.operands[0].reg;
10906 inst.instruction |= inst.operands[1].reg << 12;
10907 inst.instruction |= inst.operands[2].reg << 8;
10908 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10909}
10910
10911static void
c19d1205 10912do_t_sxtah (void)
b99bd4ef 10913{
fdfde340
JM
10914 unsigned Rd, Rn, Rm;
10915
10916 Rd = inst.operands[0].reg;
10917 Rn = inst.operands[1].reg;
10918 Rm = inst.operands[2].reg;
10919
10920 reject_bad_reg (Rd);
10921 reject_bad_reg (Rn);
10922 reject_bad_reg (Rm);
10923
10924 inst.instruction |= Rd << 8;
10925 inst.instruction |= Rn << 16;
10926 inst.instruction |= Rm;
c19d1205
ZW
10927 inst.instruction |= inst.operands[3].imm << 4;
10928}
b99bd4ef 10929
c19d1205
ZW
10930static void
10931do_t_sxth (void)
10932{
fdfde340
JM
10933 unsigned Rd, Rm;
10934
10935 Rd = inst.operands[0].reg;
10936 Rm = inst.operands[1].reg;
10937
10938 reject_bad_reg (Rd);
10939 reject_bad_reg (Rm);
10940
c19d1205 10941 if (inst.instruction <= 0xffff && inst.size_req != 4
fdfde340 10942 && Rd <= 7 && Rm <= 7
c19d1205 10943 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10944 {
c19d1205 10945 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10946 inst.instruction |= Rd;
10947 inst.instruction |= Rm << 3;
b99bd4ef 10948 }
c19d1205 10949 else if (unified_syntax)
b99bd4ef 10950 {
c19d1205
ZW
10951 if (inst.instruction <= 0xffff)
10952 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10953 inst.instruction |= Rd << 8;
10954 inst.instruction |= Rm;
c19d1205 10955 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10956 }
c19d1205 10957 else
b99bd4ef 10958 {
c19d1205
ZW
10959 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10960 _("Thumb encoding does not support rotation"));
10961 constraint (1, BAD_HIREG);
b99bd4ef 10962 }
c19d1205 10963}
b99bd4ef 10964
c19d1205
ZW
10965static void
10966do_t_swi (void)
10967{
10968 inst.reloc.type = BFD_RELOC_ARM_SWI;
10969}
b99bd4ef 10970
92e90b6e
PB
10971static void
10972do_t_tb (void)
10973{
fdfde340 10974 unsigned Rn, Rm;
92e90b6e
PB
10975 int half;
10976
10977 half = (inst.instruction & 0x10) != 0;
e07e6e58 10978 set_it_insn_type_last ();
dfa9f0d5
PB
10979 constraint (inst.operands[0].immisreg,
10980 _("instruction requires register index"));
fdfde340
JM
10981
10982 Rn = inst.operands[0].reg;
10983 Rm = inst.operands[0].imm;
10984
10985 constraint (Rn == REG_SP, BAD_SP);
10986 reject_bad_reg (Rm);
10987
92e90b6e
PB
10988 constraint (!half && inst.operands[0].shifted,
10989 _("instruction does not allow shifted index"));
fdfde340 10990 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
10991}
10992
c19d1205
ZW
10993static void
10994do_t_usat (void)
10995{
3a21c15a 10996 do_t_ssat_usat (0);
b99bd4ef
NC
10997}
10998
10999static void
c19d1205 11000do_t_usat16 (void)
b99bd4ef 11001{
fdfde340
JM
11002 unsigned Rd, Rn;
11003
11004 Rd = inst.operands[0].reg;
11005 Rn = inst.operands[2].reg;
11006
11007 reject_bad_reg (Rd);
11008 reject_bad_reg (Rn);
11009
11010 inst.instruction |= Rd << 8;
c19d1205 11011 inst.instruction |= inst.operands[1].imm;
fdfde340 11012 inst.instruction |= Rn << 16;
b99bd4ef 11013}
c19d1205 11014
5287ad62 11015/* Neon instruction encoder helpers. */
5f4273c7 11016
5287ad62 11017/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11018
5287ad62
JB
11019/* An "invalid" code for the following tables. */
11020#define N_INV -1u
11021
11022struct neon_tab_entry
b99bd4ef 11023{
5287ad62
JB
11024 unsigned integer;
11025 unsigned float_or_poly;
11026 unsigned scalar_or_imm;
11027};
5f4273c7 11028
5287ad62
JB
11029/* Map overloaded Neon opcodes to their respective encodings. */
11030#define NEON_ENC_TAB \
11031 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11032 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11033 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11034 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11035 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11036 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11037 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11038 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11039 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11040 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11041 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11042 /* Register variants of the following two instructions are encoded as
e07e6e58 11043 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11044 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11045 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
11046 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11047 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11048 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11049 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11050 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11051 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11052 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11053 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11054 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11055 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11056 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11057 X(vshl, 0x0000400, N_INV, 0x0800510), \
11058 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11059 X(vand, 0x0000110, N_INV, 0x0800030), \
11060 X(vbic, 0x0100110, N_INV, 0x0800030), \
11061 X(veor, 0x1000110, N_INV, N_INV), \
11062 X(vorn, 0x0300110, N_INV, 0x0800010), \
11063 X(vorr, 0x0200110, N_INV, 0x0800010), \
11064 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11065 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11066 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11067 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11068 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11069 X(vst1, 0x0000000, 0x0800000, N_INV), \
11070 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11071 X(vst2, 0x0000100, 0x0800100, N_INV), \
11072 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11073 X(vst3, 0x0000200, 0x0800200, N_INV), \
11074 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11075 X(vst4, 0x0000300, 0x0800300, N_INV), \
11076 X(vmovn, 0x1b20200, N_INV, N_INV), \
11077 X(vtrn, 0x1b20080, N_INV, N_INV), \
11078 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11079 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11080 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11081 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
11082 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
11083 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11084 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11085 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11086 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11087
11088enum neon_opc
11089{
11090#define X(OPC,I,F,S) N_MNEM_##OPC
11091NEON_ENC_TAB
11092#undef X
11093};
b99bd4ef 11094
5287ad62
JB
11095static const struct neon_tab_entry neon_enc_tab[] =
11096{
11097#define X(OPC,I,F,S) { (I), (F), (S) }
11098NEON_ENC_TAB
11099#undef X
11100};
b99bd4ef 11101
5287ad62
JB
11102#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11103#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11104#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11105#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11106#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11107#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11108#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11109#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11110#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
11111#define NEON_ENC_SINGLE(X) \
11112 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11113#define NEON_ENC_DOUBLE(X) \
11114 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11115
037e8744
JB
11116/* Define shapes for instruction operands. The following mnemonic characters
11117 are used in this table:
5287ad62 11118
037e8744 11119 F - VFP S<n> register
5287ad62
JB
11120 D - Neon D<n> register
11121 Q - Neon Q<n> register
11122 I - Immediate
11123 S - Scalar
11124 R - ARM register
11125 L - D<n> register list
5f4273c7 11126
037e8744
JB
11127 This table is used to generate various data:
11128 - enumerations of the form NS_DDR to be used as arguments to
11129 neon_select_shape.
11130 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11131 - a table used to drive neon_select_shape. */
b99bd4ef 11132
037e8744
JB
11133#define NEON_SHAPE_DEF \
11134 X(3, (D, D, D), DOUBLE), \
11135 X(3, (Q, Q, Q), QUAD), \
11136 X(3, (D, D, I), DOUBLE), \
11137 X(3, (Q, Q, I), QUAD), \
11138 X(3, (D, D, S), DOUBLE), \
11139 X(3, (Q, Q, S), QUAD), \
11140 X(2, (D, D), DOUBLE), \
11141 X(2, (Q, Q), QUAD), \
11142 X(2, (D, S), DOUBLE), \
11143 X(2, (Q, S), QUAD), \
11144 X(2, (D, R), DOUBLE), \
11145 X(2, (Q, R), QUAD), \
11146 X(2, (D, I), DOUBLE), \
11147 X(2, (Q, I), QUAD), \
11148 X(3, (D, L, D), DOUBLE), \
11149 X(2, (D, Q), MIXED), \
11150 X(2, (Q, D), MIXED), \
11151 X(3, (D, Q, I), MIXED), \
11152 X(3, (Q, D, I), MIXED), \
11153 X(3, (Q, D, D), MIXED), \
11154 X(3, (D, Q, Q), MIXED), \
11155 X(3, (Q, Q, D), MIXED), \
11156 X(3, (Q, D, S), MIXED), \
11157 X(3, (D, Q, S), MIXED), \
11158 X(4, (D, D, D, I), DOUBLE), \
11159 X(4, (Q, Q, Q, I), QUAD), \
11160 X(2, (F, F), SINGLE), \
11161 X(3, (F, F, F), SINGLE), \
11162 X(2, (F, I), SINGLE), \
11163 X(2, (F, D), MIXED), \
11164 X(2, (D, F), MIXED), \
11165 X(3, (F, F, I), MIXED), \
11166 X(4, (R, R, F, F), SINGLE), \
11167 X(4, (F, F, R, R), SINGLE), \
11168 X(3, (D, R, R), DOUBLE), \
11169 X(3, (R, R, D), DOUBLE), \
11170 X(2, (S, R), SINGLE), \
11171 X(2, (R, S), SINGLE), \
11172 X(2, (F, R), SINGLE), \
11173 X(2, (R, F), SINGLE)
11174
11175#define S2(A,B) NS_##A##B
11176#define S3(A,B,C) NS_##A##B##C
11177#define S4(A,B,C,D) NS_##A##B##C##D
11178
11179#define X(N, L, C) S##N L
11180
5287ad62
JB
11181enum neon_shape
11182{
037e8744
JB
11183 NEON_SHAPE_DEF,
11184 NS_NULL
5287ad62 11185};
b99bd4ef 11186
037e8744
JB
11187#undef X
11188#undef S2
11189#undef S3
11190#undef S4
11191
11192enum neon_shape_class
11193{
11194 SC_SINGLE,
11195 SC_DOUBLE,
11196 SC_QUAD,
11197 SC_MIXED
11198};
11199
11200#define X(N, L, C) SC_##C
11201
11202static enum neon_shape_class neon_shape_class[] =
11203{
11204 NEON_SHAPE_DEF
11205};
11206
11207#undef X
11208
11209enum neon_shape_el
11210{
11211 SE_F,
11212 SE_D,
11213 SE_Q,
11214 SE_I,
11215 SE_S,
11216 SE_R,
11217 SE_L
11218};
11219
11220/* Register widths of above. */
11221static unsigned neon_shape_el_size[] =
11222{
11223 32,
11224 64,
11225 128,
11226 0,
11227 32,
11228 32,
11229 0
11230};
11231
11232struct neon_shape_info
11233{
11234 unsigned els;
11235 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11236};
11237
11238#define S2(A,B) { SE_##A, SE_##B }
11239#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11240#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11241
11242#define X(N, L, C) { N, S##N L }
11243
11244static struct neon_shape_info neon_shape_tab[] =
11245{
11246 NEON_SHAPE_DEF
11247};
11248
11249#undef X
11250#undef S2
11251#undef S3
11252#undef S4
11253
5287ad62
JB
11254/* Bit masks used in type checking given instructions.
11255 'N_EQK' means the type must be the same as (or based on in some way) the key
11256 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11257 set, various other bits can be set as well in order to modify the meaning of
11258 the type constraint. */
11259
11260enum neon_type_mask
11261{
8e79c3df
CM
11262 N_S8 = 0x0000001,
11263 N_S16 = 0x0000002,
11264 N_S32 = 0x0000004,
11265 N_S64 = 0x0000008,
11266 N_U8 = 0x0000010,
11267 N_U16 = 0x0000020,
11268 N_U32 = 0x0000040,
11269 N_U64 = 0x0000080,
11270 N_I8 = 0x0000100,
11271 N_I16 = 0x0000200,
11272 N_I32 = 0x0000400,
11273 N_I64 = 0x0000800,
11274 N_8 = 0x0001000,
11275 N_16 = 0x0002000,
11276 N_32 = 0x0004000,
11277 N_64 = 0x0008000,
11278 N_P8 = 0x0010000,
11279 N_P16 = 0x0020000,
11280 N_F16 = 0x0040000,
11281 N_F32 = 0x0080000,
11282 N_F64 = 0x0100000,
11283 N_KEY = 0x1000000, /* key element (main type specifier). */
11284 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11285 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11286 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11287 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11288 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11289 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11290 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11291 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11292 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 11293 N_UTYP = 0,
037e8744 11294 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11295};
11296
dcbf9037
JB
11297#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11298
5287ad62
JB
11299#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11300#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11301#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11302#define N_SUF_32 (N_SU_32 | N_F32)
11303#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11304#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11305
11306/* Pass this as the first type argument to neon_check_type to ignore types
11307 altogether. */
11308#define N_IGNORE_TYPE (N_KEY | N_EQK)
11309
037e8744
JB
11310/* Select a "shape" for the current instruction (describing register types or
11311 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11312 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11313 function of operand parsing, so this function doesn't need to be called.
11314 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11315
11316static enum neon_shape
037e8744 11317neon_select_shape (enum neon_shape shape, ...)
5287ad62 11318{
037e8744
JB
11319 va_list ap;
11320 enum neon_shape first_shape = shape;
5287ad62
JB
11321
11322 /* Fix missing optional operands. FIXME: we don't know at this point how
11323 many arguments we should have, so this makes the assumption that we have
11324 > 1. This is true of all current Neon opcodes, I think, but may not be
11325 true in the future. */
11326 if (!inst.operands[1].present)
11327 inst.operands[1] = inst.operands[0];
11328
037e8744 11329 va_start (ap, shape);
5f4273c7 11330
037e8744
JB
11331 for (; shape != NS_NULL; shape = va_arg (ap, int))
11332 {
11333 unsigned j;
11334 int matches = 1;
11335
11336 for (j = 0; j < neon_shape_tab[shape].els; j++)
11337 {
11338 if (!inst.operands[j].present)
11339 {
11340 matches = 0;
11341 break;
11342 }
11343
11344 switch (neon_shape_tab[shape].el[j])
11345 {
11346 case SE_F:
11347 if (!(inst.operands[j].isreg
11348 && inst.operands[j].isvec
11349 && inst.operands[j].issingle
11350 && !inst.operands[j].isquad))
11351 matches = 0;
11352 break;
11353
11354 case SE_D:
11355 if (!(inst.operands[j].isreg
11356 && inst.operands[j].isvec
11357 && !inst.operands[j].isquad
11358 && !inst.operands[j].issingle))
11359 matches = 0;
11360 break;
11361
11362 case SE_R:
11363 if (!(inst.operands[j].isreg
11364 && !inst.operands[j].isvec))
11365 matches = 0;
11366 break;
11367
11368 case SE_Q:
11369 if (!(inst.operands[j].isreg
11370 && inst.operands[j].isvec
11371 && inst.operands[j].isquad
11372 && !inst.operands[j].issingle))
11373 matches = 0;
11374 break;
11375
11376 case SE_I:
11377 if (!(!inst.operands[j].isreg
11378 && !inst.operands[j].isscalar))
11379 matches = 0;
11380 break;
11381
11382 case SE_S:
11383 if (!(!inst.operands[j].isreg
11384 && inst.operands[j].isscalar))
11385 matches = 0;
11386 break;
11387
11388 case SE_L:
11389 break;
11390 }
11391 }
11392 if (matches)
5287ad62 11393 break;
037e8744 11394 }
5f4273c7 11395
037e8744 11396 va_end (ap);
5287ad62 11397
037e8744
JB
11398 if (shape == NS_NULL && first_shape != NS_NULL)
11399 first_error (_("invalid instruction shape"));
5287ad62 11400
037e8744
JB
11401 return shape;
11402}
5287ad62 11403
037e8744
JB
11404/* True if SHAPE is predominantly a quadword operation (most of the time, this
11405 means the Q bit should be set). */
11406
11407static int
11408neon_quad (enum neon_shape shape)
11409{
11410 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11411}
037e8744 11412
5287ad62
JB
11413static void
11414neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11415 unsigned *g_size)
11416{
11417 /* Allow modification to be made to types which are constrained to be
11418 based on the key element, based on bits set alongside N_EQK. */
11419 if ((typebits & N_EQK) != 0)
11420 {
11421 if ((typebits & N_HLF) != 0)
11422 *g_size /= 2;
11423 else if ((typebits & N_DBL) != 0)
11424 *g_size *= 2;
11425 if ((typebits & N_SGN) != 0)
11426 *g_type = NT_signed;
11427 else if ((typebits & N_UNS) != 0)
11428 *g_type = NT_unsigned;
11429 else if ((typebits & N_INT) != 0)
11430 *g_type = NT_integer;
11431 else if ((typebits & N_FLT) != 0)
11432 *g_type = NT_float;
dcbf9037
JB
11433 else if ((typebits & N_SIZ) != 0)
11434 *g_type = NT_untyped;
5287ad62
JB
11435 }
11436}
5f4273c7 11437
5287ad62
JB
11438/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11439 operand type, i.e. the single type specified in a Neon instruction when it
11440 is the only one given. */
11441
11442static struct neon_type_el
11443neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11444{
11445 struct neon_type_el dest = *key;
5f4273c7 11446
9c2799c2 11447 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11448
5287ad62
JB
11449 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11450
11451 return dest;
11452}
11453
11454/* Convert Neon type and size into compact bitmask representation. */
11455
11456static enum neon_type_mask
11457type_chk_of_el_type (enum neon_el_type type, unsigned size)
11458{
11459 switch (type)
11460 {
11461 case NT_untyped:
11462 switch (size)
11463 {
11464 case 8: return N_8;
11465 case 16: return N_16;
11466 case 32: return N_32;
11467 case 64: return N_64;
11468 default: ;
11469 }
11470 break;
11471
11472 case NT_integer:
11473 switch (size)
11474 {
11475 case 8: return N_I8;
11476 case 16: return N_I16;
11477 case 32: return N_I32;
11478 case 64: return N_I64;
11479 default: ;
11480 }
11481 break;
11482
11483 case NT_float:
037e8744
JB
11484 switch (size)
11485 {
8e79c3df 11486 case 16: return N_F16;
037e8744
JB
11487 case 32: return N_F32;
11488 case 64: return N_F64;
11489 default: ;
11490 }
5287ad62
JB
11491 break;
11492
11493 case NT_poly:
11494 switch (size)
11495 {
11496 case 8: return N_P8;
11497 case 16: return N_P16;
11498 default: ;
11499 }
11500 break;
11501
11502 case NT_signed:
11503 switch (size)
11504 {
11505 case 8: return N_S8;
11506 case 16: return N_S16;
11507 case 32: return N_S32;
11508 case 64: return N_S64;
11509 default: ;
11510 }
11511 break;
11512
11513 case NT_unsigned:
11514 switch (size)
11515 {
11516 case 8: return N_U8;
11517 case 16: return N_U16;
11518 case 32: return N_U32;
11519 case 64: return N_U64;
11520 default: ;
11521 }
11522 break;
11523
11524 default: ;
11525 }
5f4273c7 11526
5287ad62
JB
11527 return N_UTYP;
11528}
11529
11530/* Convert compact Neon bitmask type representation to a type and size. Only
11531 handles the case where a single bit is set in the mask. */
11532
dcbf9037 11533static int
5287ad62
JB
11534el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11535 enum neon_type_mask mask)
11536{
dcbf9037
JB
11537 if ((mask & N_EQK) != 0)
11538 return FAIL;
11539
5287ad62
JB
11540 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11541 *size = 8;
dcbf9037 11542 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11543 *size = 16;
dcbf9037 11544 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11545 *size = 32;
037e8744 11546 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11547 *size = 64;
dcbf9037
JB
11548 else
11549 return FAIL;
11550
5287ad62
JB
11551 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11552 *type = NT_signed;
dcbf9037 11553 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11554 *type = NT_unsigned;
dcbf9037 11555 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11556 *type = NT_integer;
dcbf9037 11557 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11558 *type = NT_untyped;
dcbf9037 11559 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11560 *type = NT_poly;
037e8744 11561 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11562 *type = NT_float;
dcbf9037
JB
11563 else
11564 return FAIL;
5f4273c7 11565
dcbf9037 11566 return SUCCESS;
5287ad62
JB
11567}
11568
11569/* Modify a bitmask of allowed types. This is only needed for type
11570 relaxation. */
11571
11572static unsigned
11573modify_types_allowed (unsigned allowed, unsigned mods)
11574{
11575 unsigned size;
11576 enum neon_el_type type;
11577 unsigned destmask;
11578 int i;
5f4273c7 11579
5287ad62 11580 destmask = 0;
5f4273c7 11581
5287ad62
JB
11582 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11583 {
dcbf9037
JB
11584 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11585 {
11586 neon_modify_type_size (mods, &type, &size);
11587 destmask |= type_chk_of_el_type (type, size);
11588 }
5287ad62 11589 }
5f4273c7 11590
5287ad62
JB
11591 return destmask;
11592}
11593
11594/* Check type and return type classification.
11595 The manual states (paraphrase): If one datatype is given, it indicates the
11596 type given in:
11597 - the second operand, if there is one
11598 - the operand, if there is no second operand
11599 - the result, if there are no operands.
11600 This isn't quite good enough though, so we use a concept of a "key" datatype
11601 which is set on a per-instruction basis, which is the one which matters when
11602 only one data type is written.
11603 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11604 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11605
11606static struct neon_type_el
11607neon_check_type (unsigned els, enum neon_shape ns, ...)
11608{
11609 va_list ap;
11610 unsigned i, pass, key_el = 0;
11611 unsigned types[NEON_MAX_TYPE_ELS];
11612 enum neon_el_type k_type = NT_invtype;
11613 unsigned k_size = -1u;
11614 struct neon_type_el badtype = {NT_invtype, -1};
11615 unsigned key_allowed = 0;
11616
11617 /* Optional registers in Neon instructions are always (not) in operand 1.
11618 Fill in the missing operand here, if it was omitted. */
11619 if (els > 1 && !inst.operands[1].present)
11620 inst.operands[1] = inst.operands[0];
11621
11622 /* Suck up all the varargs. */
11623 va_start (ap, ns);
11624 for (i = 0; i < els; i++)
11625 {
11626 unsigned thisarg = va_arg (ap, unsigned);
11627 if (thisarg == N_IGNORE_TYPE)
11628 {
11629 va_end (ap);
11630 return badtype;
11631 }
11632 types[i] = thisarg;
11633 if ((thisarg & N_KEY) != 0)
11634 key_el = i;
11635 }
11636 va_end (ap);
11637
dcbf9037
JB
11638 if (inst.vectype.elems > 0)
11639 for (i = 0; i < els; i++)
11640 if (inst.operands[i].vectype.type != NT_invtype)
11641 {
11642 first_error (_("types specified in both the mnemonic and operands"));
11643 return badtype;
11644 }
11645
5287ad62
JB
11646 /* Duplicate inst.vectype elements here as necessary.
11647 FIXME: No idea if this is exactly the same as the ARM assembler,
11648 particularly when an insn takes one register and one non-register
11649 operand. */
11650 if (inst.vectype.elems == 1 && els > 1)
11651 {
11652 unsigned j;
11653 inst.vectype.elems = els;
11654 inst.vectype.el[key_el] = inst.vectype.el[0];
11655 for (j = 0; j < els; j++)
dcbf9037
JB
11656 if (j != key_el)
11657 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11658 types[j]);
11659 }
11660 else if (inst.vectype.elems == 0 && els > 0)
11661 {
11662 unsigned j;
11663 /* No types were given after the mnemonic, so look for types specified
11664 after each operand. We allow some flexibility here; as long as the
11665 "key" operand has a type, we can infer the others. */
11666 for (j = 0; j < els; j++)
11667 if (inst.operands[j].vectype.type != NT_invtype)
11668 inst.vectype.el[j] = inst.operands[j].vectype;
11669
11670 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11671 {
dcbf9037
JB
11672 for (j = 0; j < els; j++)
11673 if (inst.operands[j].vectype.type == NT_invtype)
11674 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11675 types[j]);
11676 }
11677 else
11678 {
11679 first_error (_("operand types can't be inferred"));
11680 return badtype;
5287ad62
JB
11681 }
11682 }
11683 else if (inst.vectype.elems != els)
11684 {
dcbf9037 11685 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11686 return badtype;
11687 }
11688
11689 for (pass = 0; pass < 2; pass++)
11690 {
11691 for (i = 0; i < els; i++)
11692 {
11693 unsigned thisarg = types[i];
11694 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11695 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11696 enum neon_el_type g_type = inst.vectype.el[i].type;
11697 unsigned g_size = inst.vectype.el[i].size;
11698
11699 /* Decay more-specific signed & unsigned types to sign-insensitive
11700 integer types if sign-specific variants are unavailable. */
11701 if ((g_type == NT_signed || g_type == NT_unsigned)
11702 && (types_allowed & N_SU_ALL) == 0)
11703 g_type = NT_integer;
11704
11705 /* If only untyped args are allowed, decay any more specific types to
11706 them. Some instructions only care about signs for some element
11707 sizes, so handle that properly. */
11708 if ((g_size == 8 && (types_allowed & N_8) != 0)
11709 || (g_size == 16 && (types_allowed & N_16) != 0)
11710 || (g_size == 32 && (types_allowed & N_32) != 0)
11711 || (g_size == 64 && (types_allowed & N_64) != 0))
11712 g_type = NT_untyped;
11713
11714 if (pass == 0)
11715 {
11716 if ((thisarg & N_KEY) != 0)
11717 {
11718 k_type = g_type;
11719 k_size = g_size;
11720 key_allowed = thisarg & ~N_KEY;
11721 }
11722 }
11723 else
11724 {
037e8744
JB
11725 if ((thisarg & N_VFP) != 0)
11726 {
11727 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11728 unsigned regwidth = neon_shape_el_size[regshape], match;
11729
11730 /* In VFP mode, operands must match register widths. If we
11731 have a key operand, use its width, else use the width of
11732 the current operand. */
11733 if (k_size != -1u)
11734 match = k_size;
11735 else
11736 match = g_size;
11737
11738 if (regwidth != match)
11739 {
11740 first_error (_("operand size must match register width"));
11741 return badtype;
11742 }
11743 }
5f4273c7 11744
5287ad62
JB
11745 if ((thisarg & N_EQK) == 0)
11746 {
11747 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11748
11749 if ((given_type & types_allowed) == 0)
11750 {
dcbf9037 11751 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11752 return badtype;
11753 }
11754 }
11755 else
11756 {
11757 enum neon_el_type mod_k_type = k_type;
11758 unsigned mod_k_size = k_size;
11759 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11760 if (g_type != mod_k_type || g_size != mod_k_size)
11761 {
dcbf9037 11762 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11763 return badtype;
11764 }
11765 }
11766 }
11767 }
11768 }
11769
11770 return inst.vectype.el[key_el];
11771}
11772
037e8744 11773/* Neon-style VFP instruction forwarding. */
5287ad62 11774
037e8744
JB
11775/* Thumb VFP instructions have 0xE in the condition field. */
11776
11777static void
11778do_vfp_cond_or_thumb (void)
5287ad62
JB
11779{
11780 if (thumb_mode)
037e8744 11781 inst.instruction |= 0xe0000000;
5287ad62 11782 else
037e8744 11783 inst.instruction |= inst.cond << 28;
5287ad62
JB
11784}
11785
037e8744
JB
11786/* Look up and encode a simple mnemonic, for use as a helper function for the
11787 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11788 etc. It is assumed that operand parsing has already been done, and that the
11789 operands are in the form expected by the given opcode (this isn't necessarily
11790 the same as the form in which they were parsed, hence some massaging must
11791 take place before this function is called).
11792 Checks current arch version against that in the looked-up opcode. */
5287ad62 11793
037e8744
JB
11794static void
11795do_vfp_nsyn_opcode (const char *opname)
5287ad62 11796{
037e8744 11797 const struct asm_opcode *opcode;
5f4273c7 11798
037e8744 11799 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11800
037e8744
JB
11801 if (!opcode)
11802 abort ();
5287ad62 11803
037e8744
JB
11804 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11805 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11806 _(BAD_FPU));
5287ad62 11807
037e8744
JB
11808 if (thumb_mode)
11809 {
11810 inst.instruction = opcode->tvalue;
11811 opcode->tencode ();
11812 }
11813 else
11814 {
11815 inst.instruction = (inst.cond << 28) | opcode->avalue;
11816 opcode->aencode ();
11817 }
11818}
5287ad62
JB
11819
11820static void
037e8744 11821do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11822{
037e8744
JB
11823 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11824
11825 if (rs == NS_FFF)
11826 {
11827 if (is_add)
11828 do_vfp_nsyn_opcode ("fadds");
11829 else
11830 do_vfp_nsyn_opcode ("fsubs");
11831 }
11832 else
11833 {
11834 if (is_add)
11835 do_vfp_nsyn_opcode ("faddd");
11836 else
11837 do_vfp_nsyn_opcode ("fsubd");
11838 }
11839}
11840
11841/* Check operand types to see if this is a VFP instruction, and if so call
11842 PFN (). */
11843
11844static int
11845try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11846{
11847 enum neon_shape rs;
11848 struct neon_type_el et;
11849
11850 switch (args)
11851 {
11852 case 2:
11853 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11854 et = neon_check_type (2, rs,
11855 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11856 break;
5f4273c7 11857
037e8744
JB
11858 case 3:
11859 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11860 et = neon_check_type (3, rs,
11861 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11862 break;
11863
11864 default:
11865 abort ();
11866 }
11867
11868 if (et.type != NT_invtype)
11869 {
11870 pfn (rs);
11871 return SUCCESS;
11872 }
11873 else
11874 inst.error = NULL;
11875
11876 return FAIL;
11877}
11878
11879static void
11880do_vfp_nsyn_mla_mls (enum neon_shape rs)
11881{
11882 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11883
037e8744
JB
11884 if (rs == NS_FFF)
11885 {
11886 if (is_mla)
11887 do_vfp_nsyn_opcode ("fmacs");
11888 else
11889 do_vfp_nsyn_opcode ("fmscs");
11890 }
11891 else
11892 {
11893 if (is_mla)
11894 do_vfp_nsyn_opcode ("fmacd");
11895 else
11896 do_vfp_nsyn_opcode ("fmscd");
11897 }
11898}
11899
11900static void
11901do_vfp_nsyn_mul (enum neon_shape rs)
11902{
11903 if (rs == NS_FFF)
11904 do_vfp_nsyn_opcode ("fmuls");
11905 else
11906 do_vfp_nsyn_opcode ("fmuld");
11907}
11908
11909static void
11910do_vfp_nsyn_abs_neg (enum neon_shape rs)
11911{
11912 int is_neg = (inst.instruction & 0x80) != 0;
11913 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11914
11915 if (rs == NS_FF)
11916 {
11917 if (is_neg)
11918 do_vfp_nsyn_opcode ("fnegs");
11919 else
11920 do_vfp_nsyn_opcode ("fabss");
11921 }
11922 else
11923 {
11924 if (is_neg)
11925 do_vfp_nsyn_opcode ("fnegd");
11926 else
11927 do_vfp_nsyn_opcode ("fabsd");
11928 }
11929}
11930
11931/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11932 insns belong to Neon, and are handled elsewhere. */
11933
11934static void
11935do_vfp_nsyn_ldm_stm (int is_dbmode)
11936{
11937 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11938 if (is_ldm)
11939 {
11940 if (is_dbmode)
11941 do_vfp_nsyn_opcode ("fldmdbs");
11942 else
11943 do_vfp_nsyn_opcode ("fldmias");
11944 }
11945 else
11946 {
11947 if (is_dbmode)
11948 do_vfp_nsyn_opcode ("fstmdbs");
11949 else
11950 do_vfp_nsyn_opcode ("fstmias");
11951 }
11952}
11953
037e8744
JB
11954static void
11955do_vfp_nsyn_sqrt (void)
11956{
11957 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11958 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11959
037e8744
JB
11960 if (rs == NS_FF)
11961 do_vfp_nsyn_opcode ("fsqrts");
11962 else
11963 do_vfp_nsyn_opcode ("fsqrtd");
11964}
11965
11966static void
11967do_vfp_nsyn_div (void)
11968{
11969 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11970 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11971 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11972
037e8744
JB
11973 if (rs == NS_FFF)
11974 do_vfp_nsyn_opcode ("fdivs");
11975 else
11976 do_vfp_nsyn_opcode ("fdivd");
11977}
11978
11979static void
11980do_vfp_nsyn_nmul (void)
11981{
11982 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11983 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11984 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11985
037e8744
JB
11986 if (rs == NS_FFF)
11987 {
11988 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11989 do_vfp_sp_dyadic ();
11990 }
11991 else
11992 {
11993 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
11994 do_vfp_dp_rd_rn_rm ();
11995 }
11996 do_vfp_cond_or_thumb ();
11997}
11998
11999static void
12000do_vfp_nsyn_cmp (void)
12001{
12002 if (inst.operands[1].isreg)
12003 {
12004 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12005 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12006
037e8744
JB
12007 if (rs == NS_FF)
12008 {
12009 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12010 do_vfp_sp_monadic ();
12011 }
12012 else
12013 {
12014 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12015 do_vfp_dp_rd_rm ();
12016 }
12017 }
12018 else
12019 {
12020 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12021 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12022
12023 switch (inst.instruction & 0x0fffffff)
12024 {
12025 case N_MNEM_vcmp:
12026 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12027 break;
12028 case N_MNEM_vcmpe:
12029 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12030 break;
12031 default:
12032 abort ();
12033 }
5f4273c7 12034
037e8744
JB
12035 if (rs == NS_FI)
12036 {
12037 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12038 do_vfp_sp_compare_z ();
12039 }
12040 else
12041 {
12042 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12043 do_vfp_dp_rd ();
12044 }
12045 }
12046 do_vfp_cond_or_thumb ();
12047}
12048
12049static void
12050nsyn_insert_sp (void)
12051{
12052 inst.operands[1] = inst.operands[0];
12053 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12054 inst.operands[0].reg = REG_SP;
037e8744
JB
12055 inst.operands[0].isreg = 1;
12056 inst.operands[0].writeback = 1;
12057 inst.operands[0].present = 1;
12058}
12059
12060static void
12061do_vfp_nsyn_push (void)
12062{
12063 nsyn_insert_sp ();
12064 if (inst.operands[1].issingle)
12065 do_vfp_nsyn_opcode ("fstmdbs");
12066 else
12067 do_vfp_nsyn_opcode ("fstmdbd");
12068}
12069
12070static void
12071do_vfp_nsyn_pop (void)
12072{
12073 nsyn_insert_sp ();
12074 if (inst.operands[1].issingle)
22b5b651 12075 do_vfp_nsyn_opcode ("fldmias");
037e8744 12076 else
22b5b651 12077 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12078}
12079
12080/* Fix up Neon data-processing instructions, ORing in the correct bits for
12081 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12082
12083static unsigned
12084neon_dp_fixup (unsigned i)
12085{
12086 if (thumb_mode)
12087 {
12088 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12089 if (i & (1 << 24))
12090 i |= 1 << 28;
5f4273c7 12091
037e8744 12092 i &= ~(1 << 24);
5f4273c7 12093
037e8744
JB
12094 i |= 0xef000000;
12095 }
12096 else
12097 i |= 0xf2000000;
5f4273c7 12098
037e8744
JB
12099 return i;
12100}
12101
12102/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12103 (0, 1, 2, 3). */
12104
12105static unsigned
12106neon_logbits (unsigned x)
12107{
12108 return ffs (x) - 4;
12109}
12110
12111#define LOW4(R) ((R) & 0xf)
12112#define HI1(R) (((R) >> 4) & 1)
12113
12114/* Encode insns with bit pattern:
12115
12116 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12117 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12118
037e8744
JB
12119 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12120 different meaning for some instruction. */
12121
12122static void
12123neon_three_same (int isquad, int ubit, int size)
12124{
12125 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12126 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12127 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12128 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12129 inst.instruction |= LOW4 (inst.operands[2].reg);
12130 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12131 inst.instruction |= (isquad != 0) << 6;
12132 inst.instruction |= (ubit != 0) << 24;
12133 if (size != -1)
12134 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12135
037e8744
JB
12136 inst.instruction = neon_dp_fixup (inst.instruction);
12137}
12138
12139/* Encode instructions of the form:
12140
12141 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12142 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12143
12144 Don't write size if SIZE == -1. */
12145
12146static void
12147neon_two_same (int qbit, int ubit, int size)
12148{
12149 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12150 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12151 inst.instruction |= LOW4 (inst.operands[1].reg);
12152 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12153 inst.instruction |= (qbit != 0) << 6;
12154 inst.instruction |= (ubit != 0) << 24;
12155
12156 if (size != -1)
12157 inst.instruction |= neon_logbits (size) << 18;
12158
12159 inst.instruction = neon_dp_fixup (inst.instruction);
12160}
12161
12162/* Neon instruction encoders, in approximate order of appearance. */
12163
12164static void
12165do_neon_dyadic_i_su (void)
12166{
037e8744 12167 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12168 struct neon_type_el et = neon_check_type (3, rs,
12169 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12170 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12171}
12172
12173static void
12174do_neon_dyadic_i64_su (void)
12175{
037e8744 12176 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12177 struct neon_type_el et = neon_check_type (3, rs,
12178 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12179 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12180}
12181
12182static void
12183neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12184 unsigned immbits)
12185{
12186 unsigned size = et.size >> 3;
12187 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12188 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12189 inst.instruction |= LOW4 (inst.operands[1].reg);
12190 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12191 inst.instruction |= (isquad != 0) << 6;
12192 inst.instruction |= immbits << 16;
12193 inst.instruction |= (size >> 3) << 7;
12194 inst.instruction |= (size & 0x7) << 19;
12195 if (write_ubit)
12196 inst.instruction |= (uval != 0) << 24;
12197
12198 inst.instruction = neon_dp_fixup (inst.instruction);
12199}
12200
12201static void
12202do_neon_shl_imm (void)
12203{
12204 if (!inst.operands[2].isreg)
12205 {
037e8744 12206 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12207 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12208 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12209 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12210 }
12211 else
12212 {
037e8744 12213 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12214 struct neon_type_el et = neon_check_type (3, rs,
12215 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12216 unsigned int tmp;
12217
12218 /* VSHL/VQSHL 3-register variants have syntax such as:
12219 vshl.xx Dd, Dm, Dn
12220 whereas other 3-register operations encoded by neon_three_same have
12221 syntax like:
12222 vadd.xx Dd, Dn, Dm
12223 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12224 here. */
12225 tmp = inst.operands[2].reg;
12226 inst.operands[2].reg = inst.operands[1].reg;
12227 inst.operands[1].reg = tmp;
5287ad62 12228 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12229 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12230 }
12231}
12232
12233static void
12234do_neon_qshl_imm (void)
12235{
12236 if (!inst.operands[2].isreg)
12237 {
037e8744 12238 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12239 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12240
5287ad62 12241 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12242 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12243 inst.operands[2].imm);
12244 }
12245 else
12246 {
037e8744 12247 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12248 struct neon_type_el et = neon_check_type (3, rs,
12249 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12250 unsigned int tmp;
12251
12252 /* See note in do_neon_shl_imm. */
12253 tmp = inst.operands[2].reg;
12254 inst.operands[2].reg = inst.operands[1].reg;
12255 inst.operands[1].reg = tmp;
5287ad62 12256 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12257 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12258 }
12259}
12260
627907b7
JB
12261static void
12262do_neon_rshl (void)
12263{
12264 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12265 struct neon_type_el et = neon_check_type (3, rs,
12266 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12267 unsigned int tmp;
12268
12269 tmp = inst.operands[2].reg;
12270 inst.operands[2].reg = inst.operands[1].reg;
12271 inst.operands[1].reg = tmp;
12272 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12273}
12274
5287ad62
JB
12275static int
12276neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12277{
036dc3f7
PB
12278 /* Handle .I8 pseudo-instructions. */
12279 if (size == 8)
5287ad62 12280 {
5287ad62
JB
12281 /* Unfortunately, this will make everything apart from zero out-of-range.
12282 FIXME is this the intended semantics? There doesn't seem much point in
12283 accepting .I8 if so. */
12284 immediate |= immediate << 8;
12285 size = 16;
036dc3f7
PB
12286 }
12287
12288 if (size >= 32)
12289 {
12290 if (immediate == (immediate & 0x000000ff))
12291 {
12292 *immbits = immediate;
12293 return 0x1;
12294 }
12295 else if (immediate == (immediate & 0x0000ff00))
12296 {
12297 *immbits = immediate >> 8;
12298 return 0x3;
12299 }
12300 else if (immediate == (immediate & 0x00ff0000))
12301 {
12302 *immbits = immediate >> 16;
12303 return 0x5;
12304 }
12305 else if (immediate == (immediate & 0xff000000))
12306 {
12307 *immbits = immediate >> 24;
12308 return 0x7;
12309 }
12310 if ((immediate & 0xffff) != (immediate >> 16))
12311 goto bad_immediate;
12312 immediate &= 0xffff;
5287ad62
JB
12313 }
12314
12315 if (immediate == (immediate & 0x000000ff))
12316 {
12317 *immbits = immediate;
036dc3f7 12318 return 0x9;
5287ad62
JB
12319 }
12320 else if (immediate == (immediate & 0x0000ff00))
12321 {
12322 *immbits = immediate >> 8;
036dc3f7 12323 return 0xb;
5287ad62
JB
12324 }
12325
12326 bad_immediate:
dcbf9037 12327 first_error (_("immediate value out of range"));
5287ad62
JB
12328 return FAIL;
12329}
12330
12331/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12332 A, B, C, D. */
12333
12334static int
12335neon_bits_same_in_bytes (unsigned imm)
12336{
12337 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12338 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12339 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12340 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12341}
12342
12343/* For immediate of above form, return 0bABCD. */
12344
12345static unsigned
12346neon_squash_bits (unsigned imm)
12347{
12348 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12349 | ((imm & 0x01000000) >> 21);
12350}
12351
136da414 12352/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12353
12354static unsigned
12355neon_qfloat_bits (unsigned imm)
12356{
136da414 12357 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12358}
12359
12360/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12361 the instruction. *OP is passed as the initial value of the op field, and
12362 may be set to a different value depending on the constant (i.e.
12363 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12364 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12365 try smaller element sizes. */
5287ad62
JB
12366
12367static int
c96612cc
JB
12368neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12369 unsigned *immbits, int *op, int size,
12370 enum neon_el_type type)
5287ad62 12371{
c96612cc
JB
12372 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12373 float. */
12374 if (type == NT_float && !float_p)
12375 return FAIL;
12376
136da414
JB
12377 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12378 {
12379 if (size != 32 || *op == 1)
12380 return FAIL;
12381 *immbits = neon_qfloat_bits (immlo);
12382 return 0xf;
12383 }
036dc3f7
PB
12384
12385 if (size == 64)
5287ad62 12386 {
036dc3f7
PB
12387 if (neon_bits_same_in_bytes (immhi)
12388 && neon_bits_same_in_bytes (immlo))
12389 {
12390 if (*op == 1)
12391 return FAIL;
12392 *immbits = (neon_squash_bits (immhi) << 4)
12393 | neon_squash_bits (immlo);
12394 *op = 1;
12395 return 0xe;
12396 }
12397
12398 if (immhi != immlo)
12399 return FAIL;
5287ad62 12400 }
036dc3f7
PB
12401
12402 if (size >= 32)
5287ad62 12403 {
036dc3f7
PB
12404 if (immlo == (immlo & 0x000000ff))
12405 {
12406 *immbits = immlo;
12407 return 0x0;
12408 }
12409 else if (immlo == (immlo & 0x0000ff00))
12410 {
12411 *immbits = immlo >> 8;
12412 return 0x2;
12413 }
12414 else if (immlo == (immlo & 0x00ff0000))
12415 {
12416 *immbits = immlo >> 16;
12417 return 0x4;
12418 }
12419 else if (immlo == (immlo & 0xff000000))
12420 {
12421 *immbits = immlo >> 24;
12422 return 0x6;
12423 }
12424 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12425 {
12426 *immbits = (immlo >> 8) & 0xff;
12427 return 0xc;
12428 }
12429 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12430 {
12431 *immbits = (immlo >> 16) & 0xff;
12432 return 0xd;
12433 }
12434
12435 if ((immlo & 0xffff) != (immlo >> 16))
12436 return FAIL;
12437 immlo &= 0xffff;
5287ad62 12438 }
036dc3f7
PB
12439
12440 if (size >= 16)
5287ad62 12441 {
036dc3f7
PB
12442 if (immlo == (immlo & 0x000000ff))
12443 {
12444 *immbits = immlo;
12445 return 0x8;
12446 }
12447 else if (immlo == (immlo & 0x0000ff00))
12448 {
12449 *immbits = immlo >> 8;
12450 return 0xa;
12451 }
12452
12453 if ((immlo & 0xff) != (immlo >> 8))
12454 return FAIL;
12455 immlo &= 0xff;
5287ad62 12456 }
036dc3f7
PB
12457
12458 if (immlo == (immlo & 0x000000ff))
5287ad62 12459 {
036dc3f7
PB
12460 /* Don't allow MVN with 8-bit immediate. */
12461 if (*op == 1)
12462 return FAIL;
12463 *immbits = immlo;
12464 return 0xe;
5287ad62 12465 }
5287ad62
JB
12466
12467 return FAIL;
12468}
12469
12470/* Write immediate bits [7:0] to the following locations:
12471
12472 |28/24|23 19|18 16|15 4|3 0|
12473 | 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|
12474
12475 This function is used by VMOV/VMVN/VORR/VBIC. */
12476
12477static void
12478neon_write_immbits (unsigned immbits)
12479{
12480 inst.instruction |= immbits & 0xf;
12481 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12482 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12483}
12484
12485/* Invert low-order SIZE bits of XHI:XLO. */
12486
12487static void
12488neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12489{
12490 unsigned immlo = xlo ? *xlo : 0;
12491 unsigned immhi = xhi ? *xhi : 0;
12492
12493 switch (size)
12494 {
12495 case 8:
12496 immlo = (~immlo) & 0xff;
12497 break;
12498
12499 case 16:
12500 immlo = (~immlo) & 0xffff;
12501 break;
12502
12503 case 64:
12504 immhi = (~immhi) & 0xffffffff;
12505 /* fall through. */
12506
12507 case 32:
12508 immlo = (~immlo) & 0xffffffff;
12509 break;
12510
12511 default:
12512 abort ();
12513 }
12514
12515 if (xlo)
12516 *xlo = immlo;
12517
12518 if (xhi)
12519 *xhi = immhi;
12520}
12521
12522static void
12523do_neon_logic (void)
12524{
12525 if (inst.operands[2].present && inst.operands[2].isreg)
12526 {
037e8744 12527 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12528 neon_check_type (3, rs, N_IGNORE_TYPE);
12529 /* U bit and size field were set as part of the bitmask. */
12530 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12531 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12532 }
12533 else
12534 {
037e8744
JB
12535 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12536 struct neon_type_el et = neon_check_type (2, rs,
12537 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
12538 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12539 unsigned immbits;
12540 int cmode;
5f4273c7 12541
5287ad62
JB
12542 if (et.type == NT_invtype)
12543 return;
5f4273c7 12544
5287ad62
JB
12545 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12546
036dc3f7
PB
12547 immbits = inst.operands[1].imm;
12548 if (et.size == 64)
12549 {
12550 /* .i64 is a pseudo-op, so the immediate must be a repeating
12551 pattern. */
12552 if (immbits != (inst.operands[1].regisimm ?
12553 inst.operands[1].reg : 0))
12554 {
12555 /* Set immbits to an invalid constant. */
12556 immbits = 0xdeadbeef;
12557 }
12558 }
12559
5287ad62
JB
12560 switch (opcode)
12561 {
12562 case N_MNEM_vbic:
036dc3f7 12563 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12564 break;
5f4273c7 12565
5287ad62 12566 case N_MNEM_vorr:
036dc3f7 12567 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12568 break;
5f4273c7 12569
5287ad62
JB
12570 case N_MNEM_vand:
12571 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12572 neon_invert_size (&immbits, 0, et.size);
12573 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12574 break;
5f4273c7 12575
5287ad62
JB
12576 case N_MNEM_vorn:
12577 /* Pseudo-instruction for VORR. */
5287ad62
JB
12578 neon_invert_size (&immbits, 0, et.size);
12579 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12580 break;
5f4273c7 12581
5287ad62
JB
12582 default:
12583 abort ();
12584 }
12585
12586 if (cmode == FAIL)
12587 return;
12588
037e8744 12589 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12590 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12591 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12592 inst.instruction |= cmode << 8;
12593 neon_write_immbits (immbits);
5f4273c7 12594
5287ad62
JB
12595 inst.instruction = neon_dp_fixup (inst.instruction);
12596 }
12597}
12598
12599static void
12600do_neon_bitfield (void)
12601{
037e8744 12602 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12603 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12604 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12605}
12606
12607static void
dcbf9037
JB
12608neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12609 unsigned destbits)
5287ad62 12610{
037e8744 12611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12612 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12613 types | N_KEY);
5287ad62
JB
12614 if (et.type == NT_float)
12615 {
12616 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12617 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12618 }
12619 else
12620 {
12621 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12622 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12623 }
12624}
12625
12626static void
12627do_neon_dyadic_if_su (void)
12628{
dcbf9037 12629 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12630}
12631
12632static void
12633do_neon_dyadic_if_su_d (void)
12634{
12635 /* This version only allow D registers, but that constraint is enforced during
12636 operand parsing so we don't need to do anything extra here. */
dcbf9037 12637 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12638}
12639
5287ad62
JB
12640static void
12641do_neon_dyadic_if_i_d (void)
12642{
428e3f1f
PB
12643 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12644 affected if we specify unsigned args. */
12645 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12646}
12647
037e8744
JB
12648enum vfp_or_neon_is_neon_bits
12649{
12650 NEON_CHECK_CC = 1,
12651 NEON_CHECK_ARCH = 2
12652};
12653
12654/* Call this function if an instruction which may have belonged to the VFP or
12655 Neon instruction sets, but turned out to be a Neon instruction (due to the
12656 operand types involved, etc.). We have to check and/or fix-up a couple of
12657 things:
12658
12659 - Make sure the user hasn't attempted to make a Neon instruction
12660 conditional.
12661 - Alter the value in the condition code field if necessary.
12662 - Make sure that the arch supports Neon instructions.
12663
12664 Which of these operations take place depends on bits from enum
12665 vfp_or_neon_is_neon_bits.
12666
12667 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12668 current instruction's condition is COND_ALWAYS, the condition field is
12669 changed to inst.uncond_value. This is necessary because instructions shared
12670 between VFP and Neon may be conditional for the VFP variants only, and the
12671 unconditional Neon version must have, e.g., 0xF in the condition field. */
12672
12673static int
12674vfp_or_neon_is_neon (unsigned check)
12675{
12676 /* Conditions are always legal in Thumb mode (IT blocks). */
12677 if (!thumb_mode && (check & NEON_CHECK_CC))
12678 {
12679 if (inst.cond != COND_ALWAYS)
12680 {
12681 first_error (_(BAD_COND));
12682 return FAIL;
12683 }
12684 if (inst.uncond_value != -1)
12685 inst.instruction |= inst.uncond_value << 28;
12686 }
5f4273c7 12687
037e8744
JB
12688 if ((check & NEON_CHECK_ARCH)
12689 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12690 {
12691 first_error (_(BAD_FPU));
12692 return FAIL;
12693 }
5f4273c7 12694
037e8744
JB
12695 return SUCCESS;
12696}
12697
5287ad62
JB
12698static void
12699do_neon_addsub_if_i (void)
12700{
037e8744
JB
12701 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12702 return;
12703
12704 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12705 return;
12706
5287ad62
JB
12707 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12708 affected if we specify unsigned args. */
dcbf9037 12709 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12710}
12711
12712/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12713 result to be:
12714 V<op> A,B (A is operand 0, B is operand 2)
12715 to mean:
12716 V<op> A,B,A
12717 not:
12718 V<op> A,B,B
12719 so handle that case specially. */
12720
12721static void
12722neon_exchange_operands (void)
12723{
12724 void *scratch = alloca (sizeof (inst.operands[0]));
12725 if (inst.operands[1].present)
12726 {
12727 /* Swap operands[1] and operands[2]. */
12728 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12729 inst.operands[1] = inst.operands[2];
12730 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12731 }
12732 else
12733 {
12734 inst.operands[1] = inst.operands[2];
12735 inst.operands[2] = inst.operands[0];
12736 }
12737}
12738
12739static void
12740neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12741{
12742 if (inst.operands[2].isreg)
12743 {
12744 if (invert)
12745 neon_exchange_operands ();
dcbf9037 12746 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12747 }
12748 else
12749 {
037e8744 12750 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12751 struct neon_type_el et = neon_check_type (2, rs,
12752 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12753
12754 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12755 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12756 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12757 inst.instruction |= LOW4 (inst.operands[1].reg);
12758 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12759 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12760 inst.instruction |= (et.type == NT_float) << 10;
12761 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12762
5287ad62
JB
12763 inst.instruction = neon_dp_fixup (inst.instruction);
12764 }
12765}
12766
12767static void
12768do_neon_cmp (void)
12769{
12770 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12771}
12772
12773static void
12774do_neon_cmp_inv (void)
12775{
12776 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12777}
12778
12779static void
12780do_neon_ceq (void)
12781{
12782 neon_compare (N_IF_32, N_IF_32, FALSE);
12783}
12784
12785/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12786 scalars, which are encoded in 5 bits, M : Rm.
12787 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12788 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12789 index in M. */
12790
12791static unsigned
12792neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12793{
dcbf9037
JB
12794 unsigned regno = NEON_SCALAR_REG (scalar);
12795 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12796
12797 switch (elsize)
12798 {
12799 case 16:
12800 if (regno > 7 || elno > 3)
12801 goto bad_scalar;
12802 return regno | (elno << 3);
5f4273c7 12803
5287ad62
JB
12804 case 32:
12805 if (regno > 15 || elno > 1)
12806 goto bad_scalar;
12807 return regno | (elno << 4);
12808
12809 default:
12810 bad_scalar:
dcbf9037 12811 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12812 }
12813
12814 return 0;
12815}
12816
12817/* Encode multiply / multiply-accumulate scalar instructions. */
12818
12819static void
12820neon_mul_mac (struct neon_type_el et, int ubit)
12821{
dcbf9037
JB
12822 unsigned scalar;
12823
12824 /* Give a more helpful error message if we have an invalid type. */
12825 if (et.type == NT_invtype)
12826 return;
5f4273c7 12827
dcbf9037 12828 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12829 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12830 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12831 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12832 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12833 inst.instruction |= LOW4 (scalar);
12834 inst.instruction |= HI1 (scalar) << 5;
12835 inst.instruction |= (et.type == NT_float) << 8;
12836 inst.instruction |= neon_logbits (et.size) << 20;
12837 inst.instruction |= (ubit != 0) << 24;
12838
12839 inst.instruction = neon_dp_fixup (inst.instruction);
12840}
12841
12842static void
12843do_neon_mac_maybe_scalar (void)
12844{
037e8744
JB
12845 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12846 return;
12847
12848 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12849 return;
12850
5287ad62
JB
12851 if (inst.operands[2].isscalar)
12852 {
037e8744 12853 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12854 struct neon_type_el et = neon_check_type (3, rs,
12855 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12856 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12857 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12858 }
12859 else
428e3f1f
PB
12860 {
12861 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12862 affected if we specify unsigned args. */
12863 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12864 }
5287ad62
JB
12865}
12866
12867static void
12868do_neon_tst (void)
12869{
037e8744 12870 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12871 struct neon_type_el et = neon_check_type (3, rs,
12872 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12873 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12874}
12875
12876/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12877 same types as the MAC equivalents. The polynomial type for this instruction
12878 is encoded the same as the integer type. */
12879
12880static void
12881do_neon_mul (void)
12882{
037e8744
JB
12883 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12884 return;
12885
12886 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12887 return;
12888
5287ad62
JB
12889 if (inst.operands[2].isscalar)
12890 do_neon_mac_maybe_scalar ();
12891 else
dcbf9037 12892 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12893}
12894
12895static void
12896do_neon_qdmulh (void)
12897{
12898 if (inst.operands[2].isscalar)
12899 {
037e8744 12900 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12901 struct neon_type_el et = neon_check_type (3, rs,
12902 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12903 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12904 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12905 }
12906 else
12907 {
037e8744 12908 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12909 struct neon_type_el et = neon_check_type (3, rs,
12910 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12911 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12912 /* The U bit (rounding) comes from bit mask. */
037e8744 12913 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12914 }
12915}
12916
12917static void
12918do_neon_fcmp_absolute (void)
12919{
037e8744 12920 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12921 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12922 /* Size field comes from bit mask. */
037e8744 12923 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12924}
12925
12926static void
12927do_neon_fcmp_absolute_inv (void)
12928{
12929 neon_exchange_operands ();
12930 do_neon_fcmp_absolute ();
12931}
12932
12933static void
12934do_neon_step (void)
12935{
037e8744 12936 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12937 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12938 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12939}
12940
12941static void
12942do_neon_abs_neg (void)
12943{
037e8744
JB
12944 enum neon_shape rs;
12945 struct neon_type_el et;
5f4273c7 12946
037e8744
JB
12947 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12948 return;
12949
12950 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12951 return;
12952
12953 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12954 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12955
5287ad62
JB
12956 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12957 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12958 inst.instruction |= LOW4 (inst.operands[1].reg);
12959 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12960 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12961 inst.instruction |= (et.type == NT_float) << 10;
12962 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12963
5287ad62
JB
12964 inst.instruction = neon_dp_fixup (inst.instruction);
12965}
12966
12967static void
12968do_neon_sli (void)
12969{
037e8744 12970 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12971 struct neon_type_el et = neon_check_type (2, rs,
12972 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12973 int imm = inst.operands[2].imm;
12974 constraint (imm < 0 || (unsigned)imm >= et.size,
12975 _("immediate out of range for insert"));
037e8744 12976 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12977}
12978
12979static void
12980do_neon_sri (void)
12981{
037e8744 12982 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12983 struct neon_type_el et = neon_check_type (2, rs,
12984 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12985 int imm = inst.operands[2].imm;
12986 constraint (imm < 1 || (unsigned)imm > et.size,
12987 _("immediate out of range for insert"));
037e8744 12988 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12989}
12990
12991static void
12992do_neon_qshlu_imm (void)
12993{
037e8744 12994 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12995 struct neon_type_el et = neon_check_type (2, rs,
12996 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
12997 int imm = inst.operands[2].imm;
12998 constraint (imm < 0 || (unsigned)imm >= et.size,
12999 _("immediate out of range for shift"));
13000 /* Only encodes the 'U present' variant of the instruction.
13001 In this case, signed types have OP (bit 8) set to 0.
13002 Unsigned types have OP set to 1. */
13003 inst.instruction |= (et.type == NT_unsigned) << 8;
13004 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13005 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13006}
13007
13008static void
13009do_neon_qmovn (void)
13010{
13011 struct neon_type_el et = neon_check_type (2, NS_DQ,
13012 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13013 /* Saturating move where operands can be signed or unsigned, and the
13014 destination has the same signedness. */
13015 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13016 if (et.type == NT_unsigned)
13017 inst.instruction |= 0xc0;
13018 else
13019 inst.instruction |= 0x80;
13020 neon_two_same (0, 1, et.size / 2);
13021}
13022
13023static void
13024do_neon_qmovun (void)
13025{
13026 struct neon_type_el et = neon_check_type (2, NS_DQ,
13027 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13028 /* Saturating move with unsigned results. Operands must be signed. */
13029 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13030 neon_two_same (0, 1, et.size / 2);
13031}
13032
13033static void
13034do_neon_rshift_sat_narrow (void)
13035{
13036 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13037 or unsigned. If operands are unsigned, results must also be unsigned. */
13038 struct neon_type_el et = neon_check_type (2, NS_DQI,
13039 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13040 int imm = inst.operands[2].imm;
13041 /* This gets the bounds check, size encoding and immediate bits calculation
13042 right. */
13043 et.size /= 2;
5f4273c7 13044
5287ad62
JB
13045 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13046 VQMOVN.I<size> <Dd>, <Qm>. */
13047 if (imm == 0)
13048 {
13049 inst.operands[2].present = 0;
13050 inst.instruction = N_MNEM_vqmovn;
13051 do_neon_qmovn ();
13052 return;
13053 }
5f4273c7 13054
5287ad62
JB
13055 constraint (imm < 1 || (unsigned)imm > et.size,
13056 _("immediate out of range"));
13057 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13058}
13059
13060static void
13061do_neon_rshift_sat_narrow_u (void)
13062{
13063 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13064 or unsigned. If operands are unsigned, results must also be unsigned. */
13065 struct neon_type_el et = neon_check_type (2, NS_DQI,
13066 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13067 int imm = inst.operands[2].imm;
13068 /* This gets the bounds check, size encoding and immediate bits calculation
13069 right. */
13070 et.size /= 2;
13071
13072 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13073 VQMOVUN.I<size> <Dd>, <Qm>. */
13074 if (imm == 0)
13075 {
13076 inst.operands[2].present = 0;
13077 inst.instruction = N_MNEM_vqmovun;
13078 do_neon_qmovun ();
13079 return;
13080 }
13081
13082 constraint (imm < 1 || (unsigned)imm > et.size,
13083 _("immediate out of range"));
13084 /* FIXME: The manual is kind of unclear about what value U should have in
13085 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13086 must be 1. */
13087 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13088}
13089
13090static void
13091do_neon_movn (void)
13092{
13093 struct neon_type_el et = neon_check_type (2, NS_DQ,
13094 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13095 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13096 neon_two_same (0, 1, et.size / 2);
13097}
13098
13099static void
13100do_neon_rshift_narrow (void)
13101{
13102 struct neon_type_el et = neon_check_type (2, NS_DQI,
13103 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13104 int imm = inst.operands[2].imm;
13105 /* This gets the bounds check, size encoding and immediate bits calculation
13106 right. */
13107 et.size /= 2;
5f4273c7 13108
5287ad62
JB
13109 /* If immediate is zero then we are a pseudo-instruction for
13110 VMOVN.I<size> <Dd>, <Qm> */
13111 if (imm == 0)
13112 {
13113 inst.operands[2].present = 0;
13114 inst.instruction = N_MNEM_vmovn;
13115 do_neon_movn ();
13116 return;
13117 }
5f4273c7 13118
5287ad62
JB
13119 constraint (imm < 1 || (unsigned)imm > et.size,
13120 _("immediate out of range for narrowing operation"));
13121 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13122}
13123
13124static void
13125do_neon_shll (void)
13126{
13127 /* FIXME: Type checking when lengthening. */
13128 struct neon_type_el et = neon_check_type (2, NS_QDI,
13129 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13130 unsigned imm = inst.operands[2].imm;
13131
13132 if (imm == et.size)
13133 {
13134 /* Maximum shift variant. */
13135 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13136 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13137 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13138 inst.instruction |= LOW4 (inst.operands[1].reg);
13139 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13140 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13141
5287ad62
JB
13142 inst.instruction = neon_dp_fixup (inst.instruction);
13143 }
13144 else
13145 {
13146 /* A more-specific type check for non-max versions. */
13147 et = neon_check_type (2, NS_QDI,
13148 N_EQK | N_DBL, N_SU_32 | N_KEY);
13149 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13150 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13151 }
13152}
13153
037e8744 13154/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13155 the current instruction is. */
13156
13157static int
13158neon_cvt_flavour (enum neon_shape rs)
13159{
037e8744
JB
13160#define CVT_VAR(C,X,Y) \
13161 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13162 if (et.type != NT_invtype) \
13163 { \
13164 inst.error = NULL; \
13165 return (C); \
5287ad62
JB
13166 }
13167 struct neon_type_el et;
037e8744
JB
13168 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13169 || rs == NS_FF) ? N_VFP : 0;
13170 /* The instruction versions which take an immediate take one register
13171 argument, which is extended to the width of the full register. Thus the
13172 "source" and "destination" registers must have the same width. Hack that
13173 here by making the size equal to the key (wider, in this case) operand. */
13174 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13175
5287ad62
JB
13176 CVT_VAR (0, N_S32, N_F32);
13177 CVT_VAR (1, N_U32, N_F32);
13178 CVT_VAR (2, N_F32, N_S32);
13179 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13180 /* Half-precision conversions. */
13181 CVT_VAR (4, N_F32, N_F16);
13182 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13183
037e8744 13184 whole_reg = N_VFP;
5f4273c7 13185
037e8744 13186 /* VFP instructions. */
8e79c3df
CM
13187 CVT_VAR (6, N_F32, N_F64);
13188 CVT_VAR (7, N_F64, N_F32);
13189 CVT_VAR (8, N_S32, N_F64 | key);
13190 CVT_VAR (9, N_U32, N_F64 | key);
13191 CVT_VAR (10, N_F64 | key, N_S32);
13192 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13193 /* VFP instructions with bitshift. */
8e79c3df
CM
13194 CVT_VAR (12, N_F32 | key, N_S16);
13195 CVT_VAR (13, N_F32 | key, N_U16);
13196 CVT_VAR (14, N_F64 | key, N_S16);
13197 CVT_VAR (15, N_F64 | key, N_U16);
13198 CVT_VAR (16, N_S16, N_F32 | key);
13199 CVT_VAR (17, N_U16, N_F32 | key);
13200 CVT_VAR (18, N_S16, N_F64 | key);
13201 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13202
5287ad62
JB
13203 return -1;
13204#undef CVT_VAR
13205}
13206
037e8744
JB
13207/* Neon-syntax VFP conversions. */
13208
5287ad62 13209static void
037e8744 13210do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13211{
037e8744 13212 const char *opname = 0;
5f4273c7 13213
037e8744 13214 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13215 {
037e8744
JB
13216 /* Conversions with immediate bitshift. */
13217 const char *enc[] =
13218 {
13219 "ftosls",
13220 "ftouls",
13221 "fsltos",
13222 "fultos",
13223 NULL,
13224 NULL,
8e79c3df
CM
13225 NULL,
13226 NULL,
037e8744
JB
13227 "ftosld",
13228 "ftould",
13229 "fsltod",
13230 "fultod",
13231 "fshtos",
13232 "fuhtos",
13233 "fshtod",
13234 "fuhtod",
13235 "ftoshs",
13236 "ftouhs",
13237 "ftoshd",
13238 "ftouhd"
13239 };
13240
13241 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13242 {
13243 opname = enc[flavour];
13244 constraint (inst.operands[0].reg != inst.operands[1].reg,
13245 _("operands 0 and 1 must be the same register"));
13246 inst.operands[1] = inst.operands[2];
13247 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13248 }
5287ad62
JB
13249 }
13250 else
13251 {
037e8744
JB
13252 /* Conversions without bitshift. */
13253 const char *enc[] =
13254 {
13255 "ftosis",
13256 "ftouis",
13257 "fsitos",
13258 "fuitos",
8e79c3df
CM
13259 "NULL",
13260 "NULL",
037e8744
JB
13261 "fcvtsd",
13262 "fcvtds",
13263 "ftosid",
13264 "ftouid",
13265 "fsitod",
13266 "fuitod"
13267 };
13268
13269 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13270 opname = enc[flavour];
13271 }
13272
13273 if (opname)
13274 do_vfp_nsyn_opcode (opname);
13275}
13276
13277static void
13278do_vfp_nsyn_cvtz (void)
13279{
13280 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13281 int flavour = neon_cvt_flavour (rs);
13282 const char *enc[] =
13283 {
13284 "ftosizs",
13285 "ftouizs",
13286 NULL,
13287 NULL,
13288 NULL,
13289 NULL,
8e79c3df
CM
13290 NULL,
13291 NULL,
037e8744
JB
13292 "ftosizd",
13293 "ftouizd"
13294 };
13295
13296 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13297 do_vfp_nsyn_opcode (enc[flavour]);
13298}
f31fef98 13299
037e8744
JB
13300static void
13301do_neon_cvt (void)
13302{
13303 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13304 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13305 int flavour = neon_cvt_flavour (rs);
13306
13307 /* VFP rather than Neon conversions. */
8e79c3df 13308 if (flavour >= 6)
037e8744
JB
13309 {
13310 do_vfp_nsyn_cvt (rs, flavour);
13311 return;
13312 }
13313
13314 switch (rs)
13315 {
13316 case NS_DDI:
13317 case NS_QQI:
13318 {
35997600
NC
13319 unsigned immbits;
13320 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13321
037e8744
JB
13322 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13323 return;
13324
13325 /* Fixed-point conversion with #0 immediate is encoded as an
13326 integer conversion. */
13327 if (inst.operands[2].present && inst.operands[2].imm == 0)
13328 goto int_encode;
35997600 13329 immbits = 32 - inst.operands[2].imm;
037e8744
JB
13330 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13331 if (flavour != -1)
13332 inst.instruction |= enctab[flavour];
13333 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13334 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13335 inst.instruction |= LOW4 (inst.operands[1].reg);
13336 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13337 inst.instruction |= neon_quad (rs) << 6;
13338 inst.instruction |= 1 << 21;
13339 inst.instruction |= immbits << 16;
13340
13341 inst.instruction = neon_dp_fixup (inst.instruction);
13342 }
13343 break;
13344
13345 case NS_DD:
13346 case NS_QQ:
13347 int_encode:
13348 {
13349 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13350
13351 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13352
13353 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13354 return;
13355
13356 if (flavour != -1)
13357 inst.instruction |= enctab[flavour];
13358
13359 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13360 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13361 inst.instruction |= LOW4 (inst.operands[1].reg);
13362 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13363 inst.instruction |= neon_quad (rs) << 6;
13364 inst.instruction |= 2 << 18;
13365
13366 inst.instruction = neon_dp_fixup (inst.instruction);
13367 }
13368 break;
13369
8e79c3df
CM
13370 /* Half-precision conversions for Advanced SIMD -- neon. */
13371 case NS_QD:
13372 case NS_DQ:
13373
13374 if ((rs == NS_DQ)
13375 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13376 {
13377 as_bad (_("operand size must match register width"));
13378 break;
13379 }
13380
13381 if ((rs == NS_QD)
13382 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13383 {
13384 as_bad (_("operand size must match register width"));
13385 break;
13386 }
13387
13388 if (rs == NS_DQ)
13389 inst.instruction = 0x3b60600;
13390 else
13391 inst.instruction = 0x3b60700;
13392
13393 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13394 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13395 inst.instruction |= LOW4 (inst.operands[1].reg);
13396 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13397 inst.instruction = neon_dp_fixup (inst.instruction);
13398 break;
13399
037e8744
JB
13400 default:
13401 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13402 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13403 }
5287ad62
JB
13404}
13405
8e79c3df
CM
13406static void
13407do_neon_cvtb (void)
13408{
13409 inst.instruction = 0xeb20a40;
13410
13411 /* The sizes are attached to the mnemonic. */
13412 if (inst.vectype.el[0].type != NT_invtype
13413 && inst.vectype.el[0].size == 16)
13414 inst.instruction |= 0x00010000;
13415
13416 /* Programmer's syntax: the sizes are attached to the operands. */
13417 else if (inst.operands[0].vectype.type != NT_invtype
13418 && inst.operands[0].vectype.size == 16)
13419 inst.instruction |= 0x00010000;
13420
13421 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13422 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13423 do_vfp_cond_or_thumb ();
13424}
13425
13426
13427static void
13428do_neon_cvtt (void)
13429{
13430 do_neon_cvtb ();
13431 inst.instruction |= 0x80;
13432}
13433
5287ad62
JB
13434static void
13435neon_move_immediate (void)
13436{
037e8744
JB
13437 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13438 struct neon_type_el et = neon_check_type (2, rs,
13439 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13440 unsigned immlo, immhi = 0, immbits;
c96612cc 13441 int op, cmode, float_p;
5287ad62 13442
037e8744
JB
13443 constraint (et.type == NT_invtype,
13444 _("operand size must be specified for immediate VMOV"));
13445
5287ad62
JB
13446 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13447 op = (inst.instruction & (1 << 5)) != 0;
13448
13449 immlo = inst.operands[1].imm;
13450 if (inst.operands[1].regisimm)
13451 immhi = inst.operands[1].reg;
13452
13453 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13454 _("immediate has bits set outside the operand size"));
13455
c96612cc
JB
13456 float_p = inst.operands[1].immisfloat;
13457
13458 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13459 et.size, et.type)) == FAIL)
5287ad62
JB
13460 {
13461 /* Invert relevant bits only. */
13462 neon_invert_size (&immlo, &immhi, et.size);
13463 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13464 with one or the other; those cases are caught by
13465 neon_cmode_for_move_imm. */
13466 op = !op;
c96612cc
JB
13467 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13468 &op, et.size, et.type)) == FAIL)
5287ad62 13469 {
dcbf9037 13470 first_error (_("immediate out of range"));
5287ad62
JB
13471 return;
13472 }
13473 }
13474
13475 inst.instruction &= ~(1 << 5);
13476 inst.instruction |= op << 5;
13477
13478 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13479 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13480 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13481 inst.instruction |= cmode << 8;
13482
13483 neon_write_immbits (immbits);
13484}
13485
13486static void
13487do_neon_mvn (void)
13488{
13489 if (inst.operands[1].isreg)
13490 {
037e8744 13491 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13492
5287ad62
JB
13493 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13494 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13495 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13496 inst.instruction |= LOW4 (inst.operands[1].reg);
13497 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13498 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13499 }
13500 else
13501 {
13502 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13503 neon_move_immediate ();
13504 }
13505
13506 inst.instruction = neon_dp_fixup (inst.instruction);
13507}
13508
13509/* Encode instructions of form:
13510
13511 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13512 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13513
13514static void
13515neon_mixed_length (struct neon_type_el et, unsigned size)
13516{
13517 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13518 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13519 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13520 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13521 inst.instruction |= LOW4 (inst.operands[2].reg);
13522 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13523 inst.instruction |= (et.type == NT_unsigned) << 24;
13524 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13525
5287ad62
JB
13526 inst.instruction = neon_dp_fixup (inst.instruction);
13527}
13528
13529static void
13530do_neon_dyadic_long (void)
13531{
13532 /* FIXME: Type checking for lengthening op. */
13533 struct neon_type_el et = neon_check_type (3, NS_QDD,
13534 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13535 neon_mixed_length (et, et.size);
13536}
13537
13538static void
13539do_neon_abal (void)
13540{
13541 struct neon_type_el et = neon_check_type (3, NS_QDD,
13542 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13543 neon_mixed_length (et, et.size);
13544}
13545
13546static void
13547neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13548{
13549 if (inst.operands[2].isscalar)
13550 {
dcbf9037
JB
13551 struct neon_type_el et = neon_check_type (3, NS_QDS,
13552 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13553 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13554 neon_mul_mac (et, et.type == NT_unsigned);
13555 }
13556 else
13557 {
13558 struct neon_type_el et = neon_check_type (3, NS_QDD,
13559 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13560 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13561 neon_mixed_length (et, et.size);
13562 }
13563}
13564
13565static void
13566do_neon_mac_maybe_scalar_long (void)
13567{
13568 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13569}
13570
13571static void
13572do_neon_dyadic_wide (void)
13573{
13574 struct neon_type_el et = neon_check_type (3, NS_QQD,
13575 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13576 neon_mixed_length (et, et.size);
13577}
13578
13579static void
13580do_neon_dyadic_narrow (void)
13581{
13582 struct neon_type_el et = neon_check_type (3, NS_QDD,
13583 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13584 /* Operand sign is unimportant, and the U bit is part of the opcode,
13585 so force the operand type to integer. */
13586 et.type = NT_integer;
5287ad62
JB
13587 neon_mixed_length (et, et.size / 2);
13588}
13589
13590static void
13591do_neon_mul_sat_scalar_long (void)
13592{
13593 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13594}
13595
13596static void
13597do_neon_vmull (void)
13598{
13599 if (inst.operands[2].isscalar)
13600 do_neon_mac_maybe_scalar_long ();
13601 else
13602 {
13603 struct neon_type_el et = neon_check_type (3, NS_QDD,
13604 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13605 if (et.type == NT_poly)
13606 inst.instruction = NEON_ENC_POLY (inst.instruction);
13607 else
13608 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13609 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13610 zero. Should be OK as-is. */
13611 neon_mixed_length (et, et.size);
13612 }
13613}
13614
13615static void
13616do_neon_ext (void)
13617{
037e8744 13618 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13619 struct neon_type_el et = neon_check_type (3, rs,
13620 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13621 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13622
13623 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13624 _("shift out of range"));
5287ad62
JB
13625 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13626 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13627 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13628 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13629 inst.instruction |= LOW4 (inst.operands[2].reg);
13630 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13631 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13632 inst.instruction |= imm << 8;
5f4273c7 13633
5287ad62
JB
13634 inst.instruction = neon_dp_fixup (inst.instruction);
13635}
13636
13637static void
13638do_neon_rev (void)
13639{
037e8744 13640 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13641 struct neon_type_el et = neon_check_type (2, rs,
13642 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13643 unsigned op = (inst.instruction >> 7) & 3;
13644 /* N (width of reversed regions) is encoded as part of the bitmask. We
13645 extract it here to check the elements to be reversed are smaller.
13646 Otherwise we'd get a reserved instruction. */
13647 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 13648 gas_assert (elsize != 0);
5287ad62
JB
13649 constraint (et.size >= elsize,
13650 _("elements must be smaller than reversal region"));
037e8744 13651 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13652}
13653
13654static void
13655do_neon_dup (void)
13656{
13657 if (inst.operands[1].isscalar)
13658 {
037e8744 13659 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13660 struct neon_type_el et = neon_check_type (2, rs,
13661 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13662 unsigned sizebits = et.size >> 3;
dcbf9037 13663 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13664 int logsize = neon_logbits (et.size);
dcbf9037 13665 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13666
13667 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13668 return;
13669
5287ad62
JB
13670 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13671 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13672 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13673 inst.instruction |= LOW4 (dm);
13674 inst.instruction |= HI1 (dm) << 5;
037e8744 13675 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13676 inst.instruction |= x << 17;
13677 inst.instruction |= sizebits << 16;
5f4273c7 13678
5287ad62
JB
13679 inst.instruction = neon_dp_fixup (inst.instruction);
13680 }
13681 else
13682 {
037e8744
JB
13683 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13684 struct neon_type_el et = neon_check_type (2, rs,
13685 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13686 /* Duplicate ARM register to lanes of vector. */
13687 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13688 switch (et.size)
13689 {
13690 case 8: inst.instruction |= 0x400000; break;
13691 case 16: inst.instruction |= 0x000020; break;
13692 case 32: inst.instruction |= 0x000000; break;
13693 default: break;
13694 }
13695 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13696 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13697 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13698 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13699 /* The encoding for this instruction is identical for the ARM and Thumb
13700 variants, except for the condition field. */
037e8744 13701 do_vfp_cond_or_thumb ();
5287ad62
JB
13702 }
13703}
13704
13705/* VMOV has particularly many variations. It can be one of:
13706 0. VMOV<c><q> <Qd>, <Qm>
13707 1. VMOV<c><q> <Dd>, <Dm>
13708 (Register operations, which are VORR with Rm = Rn.)
13709 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13710 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13711 (Immediate loads.)
13712 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13713 (ARM register to scalar.)
13714 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13715 (Two ARM registers to vector.)
13716 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13717 (Scalar to ARM register.)
13718 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13719 (Vector to two ARM registers.)
037e8744
JB
13720 8. VMOV.F32 <Sd>, <Sm>
13721 9. VMOV.F64 <Dd>, <Dm>
13722 (VFP register moves.)
13723 10. VMOV.F32 <Sd>, #imm
13724 11. VMOV.F64 <Dd>, #imm
13725 (VFP float immediate load.)
13726 12. VMOV <Rd>, <Sm>
13727 (VFP single to ARM reg.)
13728 13. VMOV <Sd>, <Rm>
13729 (ARM reg to VFP single.)
13730 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13731 (Two ARM regs to two VFP singles.)
13732 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13733 (Two VFP singles to two ARM regs.)
5f4273c7 13734
037e8744
JB
13735 These cases can be disambiguated using neon_select_shape, except cases 1/9
13736 and 3/11 which depend on the operand type too.
5f4273c7 13737
5287ad62 13738 All the encoded bits are hardcoded by this function.
5f4273c7 13739
b7fc2769
JB
13740 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13741 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13742
5287ad62 13743 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13744 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13745
13746static void
13747do_neon_mov (void)
13748{
037e8744
JB
13749 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13750 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13751 NS_NULL);
13752 struct neon_type_el et;
13753 const char *ldconst = 0;
5287ad62 13754
037e8744 13755 switch (rs)
5287ad62 13756 {
037e8744
JB
13757 case NS_DD: /* case 1/9. */
13758 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13759 /* It is not an error here if no type is given. */
13760 inst.error = NULL;
13761 if (et.type == NT_float && et.size == 64)
5287ad62 13762 {
037e8744
JB
13763 do_vfp_nsyn_opcode ("fcpyd");
13764 break;
5287ad62 13765 }
037e8744 13766 /* fall through. */
5287ad62 13767
037e8744
JB
13768 case NS_QQ: /* case 0/1. */
13769 {
13770 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13771 return;
13772 /* The architecture manual I have doesn't explicitly state which
13773 value the U bit should have for register->register moves, but
13774 the equivalent VORR instruction has U = 0, so do that. */
13775 inst.instruction = 0x0200110;
13776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13778 inst.instruction |= LOW4 (inst.operands[1].reg);
13779 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13780 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13781 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13782 inst.instruction |= neon_quad (rs) << 6;
13783
13784 inst.instruction = neon_dp_fixup (inst.instruction);
13785 }
13786 break;
5f4273c7 13787
037e8744
JB
13788 case NS_DI: /* case 3/11. */
13789 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13790 inst.error = NULL;
13791 if (et.type == NT_float && et.size == 64)
5287ad62 13792 {
037e8744
JB
13793 /* case 11 (fconstd). */
13794 ldconst = "fconstd";
13795 goto encode_fconstd;
5287ad62 13796 }
037e8744
JB
13797 /* fall through. */
13798
13799 case NS_QI: /* case 2/3. */
13800 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13801 return;
13802 inst.instruction = 0x0800010;
13803 neon_move_immediate ();
13804 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13805 break;
5f4273c7 13806
037e8744
JB
13807 case NS_SR: /* case 4. */
13808 {
13809 unsigned bcdebits = 0;
13810 struct neon_type_el et = neon_check_type (2, NS_NULL,
13811 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13812 int logsize = neon_logbits (et.size);
13813 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13814 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13815
13816 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13817 _(BAD_FPU));
13818 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13819 && et.size != 32, _(BAD_FPU));
13820 constraint (et.type == NT_invtype, _("bad type for scalar"));
13821 constraint (x >= 64 / et.size, _("scalar index out of range"));
13822
13823 switch (et.size)
13824 {
13825 case 8: bcdebits = 0x8; break;
13826 case 16: bcdebits = 0x1; break;
13827 case 32: bcdebits = 0x0; break;
13828 default: ;
13829 }
13830
13831 bcdebits |= x << logsize;
13832
13833 inst.instruction = 0xe000b10;
13834 do_vfp_cond_or_thumb ();
13835 inst.instruction |= LOW4 (dn) << 16;
13836 inst.instruction |= HI1 (dn) << 7;
13837 inst.instruction |= inst.operands[1].reg << 12;
13838 inst.instruction |= (bcdebits & 3) << 5;
13839 inst.instruction |= (bcdebits >> 2) << 21;
13840 }
13841 break;
5f4273c7 13842
037e8744 13843 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13844 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13845 _(BAD_FPU));
b7fc2769 13846
037e8744
JB
13847 inst.instruction = 0xc400b10;
13848 do_vfp_cond_or_thumb ();
13849 inst.instruction |= LOW4 (inst.operands[0].reg);
13850 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13851 inst.instruction |= inst.operands[1].reg << 12;
13852 inst.instruction |= inst.operands[2].reg << 16;
13853 break;
5f4273c7 13854
037e8744
JB
13855 case NS_RS: /* case 6. */
13856 {
13857 struct neon_type_el et = neon_check_type (2, NS_NULL,
13858 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13859 unsigned logsize = neon_logbits (et.size);
13860 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13861 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13862 unsigned abcdebits = 0;
13863
13864 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13865 _(BAD_FPU));
13866 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13867 && et.size != 32, _(BAD_FPU));
13868 constraint (et.type == NT_invtype, _("bad type for scalar"));
13869 constraint (x >= 64 / et.size, _("scalar index out of range"));
13870
13871 switch (et.size)
13872 {
13873 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13874 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13875 case 32: abcdebits = 0x00; break;
13876 default: ;
13877 }
13878
13879 abcdebits |= x << logsize;
13880 inst.instruction = 0xe100b10;
13881 do_vfp_cond_or_thumb ();
13882 inst.instruction |= LOW4 (dn) << 16;
13883 inst.instruction |= HI1 (dn) << 7;
13884 inst.instruction |= inst.operands[0].reg << 12;
13885 inst.instruction |= (abcdebits & 3) << 5;
13886 inst.instruction |= (abcdebits >> 2) << 21;
13887 }
13888 break;
5f4273c7 13889
037e8744
JB
13890 case NS_RRD: /* case 7 (fmrrd). */
13891 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13892 _(BAD_FPU));
13893
13894 inst.instruction = 0xc500b10;
13895 do_vfp_cond_or_thumb ();
13896 inst.instruction |= inst.operands[0].reg << 12;
13897 inst.instruction |= inst.operands[1].reg << 16;
13898 inst.instruction |= LOW4 (inst.operands[2].reg);
13899 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13900 break;
5f4273c7 13901
037e8744
JB
13902 case NS_FF: /* case 8 (fcpys). */
13903 do_vfp_nsyn_opcode ("fcpys");
13904 break;
5f4273c7 13905
037e8744
JB
13906 case NS_FI: /* case 10 (fconsts). */
13907 ldconst = "fconsts";
13908 encode_fconstd:
13909 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13910 {
037e8744
JB
13911 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13912 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13913 }
13914 else
037e8744
JB
13915 first_error (_("immediate out of range"));
13916 break;
5f4273c7 13917
037e8744
JB
13918 case NS_RF: /* case 12 (fmrs). */
13919 do_vfp_nsyn_opcode ("fmrs");
13920 break;
5f4273c7 13921
037e8744
JB
13922 case NS_FR: /* case 13 (fmsr). */
13923 do_vfp_nsyn_opcode ("fmsr");
13924 break;
5f4273c7 13925
037e8744
JB
13926 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13927 (one of which is a list), but we have parsed four. Do some fiddling to
13928 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13929 expect. */
13930 case NS_RRFF: /* case 14 (fmrrs). */
13931 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13932 _("VFP registers must be adjacent"));
13933 inst.operands[2].imm = 2;
13934 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13935 do_vfp_nsyn_opcode ("fmrrs");
13936 break;
5f4273c7 13937
037e8744
JB
13938 case NS_FFRR: /* case 15 (fmsrr). */
13939 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13940 _("VFP registers must be adjacent"));
13941 inst.operands[1] = inst.operands[2];
13942 inst.operands[2] = inst.operands[3];
13943 inst.operands[0].imm = 2;
13944 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13945 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13946 break;
5f4273c7 13947
5287ad62
JB
13948 default:
13949 abort ();
13950 }
13951}
13952
13953static void
13954do_neon_rshift_round_imm (void)
13955{
037e8744 13956 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13957 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13958 int imm = inst.operands[2].imm;
13959
13960 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13961 if (imm == 0)
13962 {
13963 inst.operands[2].present = 0;
13964 do_neon_mov ();
13965 return;
13966 }
13967
13968 constraint (imm < 1 || (unsigned)imm > et.size,
13969 _("immediate out of range for shift"));
037e8744 13970 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13971 et.size - imm);
13972}
13973
13974static void
13975do_neon_movl (void)
13976{
13977 struct neon_type_el et = neon_check_type (2, NS_QD,
13978 N_EQK | N_DBL, N_SU_32 | N_KEY);
13979 unsigned sizebits = et.size >> 3;
13980 inst.instruction |= sizebits << 19;
13981 neon_two_same (0, et.type == NT_unsigned, -1);
13982}
13983
13984static void
13985do_neon_trn (void)
13986{
037e8744 13987 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13988 struct neon_type_el et = neon_check_type (2, rs,
13989 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13990 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 13991 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13992}
13993
13994static void
13995do_neon_zip_uzp (void)
13996{
037e8744 13997 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13998 struct neon_type_el et = neon_check_type (2, rs,
13999 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14000 if (rs == NS_DD && et.size == 32)
14001 {
14002 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14003 inst.instruction = N_MNEM_vtrn;
14004 do_neon_trn ();
14005 return;
14006 }
037e8744 14007 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14008}
14009
14010static void
14011do_neon_sat_abs_neg (void)
14012{
037e8744 14013 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14014 struct neon_type_el et = neon_check_type (2, rs,
14015 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14016 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14017}
14018
14019static void
14020do_neon_pair_long (void)
14021{
037e8744 14022 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14023 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14024 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14025 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14026 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14027}
14028
14029static void
14030do_neon_recip_est (void)
14031{
037e8744 14032 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14033 struct neon_type_el et = neon_check_type (2, rs,
14034 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14035 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14036 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14037}
14038
14039static void
14040do_neon_cls (void)
14041{
037e8744 14042 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14043 struct neon_type_el et = neon_check_type (2, rs,
14044 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14045 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14046}
14047
14048static void
14049do_neon_clz (void)
14050{
037e8744 14051 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14052 struct neon_type_el et = neon_check_type (2, rs,
14053 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14054 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14055}
14056
14057static void
14058do_neon_cnt (void)
14059{
037e8744 14060 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14061 struct neon_type_el et = neon_check_type (2, rs,
14062 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14063 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14064}
14065
14066static void
14067do_neon_swp (void)
14068{
037e8744
JB
14069 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14070 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14071}
14072
14073static void
14074do_neon_tbl_tbx (void)
14075{
14076 unsigned listlenbits;
dcbf9037 14077 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14078
5287ad62
JB
14079 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14080 {
dcbf9037 14081 first_error (_("bad list length for table lookup"));
5287ad62
JB
14082 return;
14083 }
5f4273c7 14084
5287ad62
JB
14085 listlenbits = inst.operands[1].imm - 1;
14086 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14087 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14088 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14089 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14090 inst.instruction |= LOW4 (inst.operands[2].reg);
14091 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14092 inst.instruction |= listlenbits << 8;
5f4273c7 14093
5287ad62
JB
14094 inst.instruction = neon_dp_fixup (inst.instruction);
14095}
14096
14097static void
14098do_neon_ldm_stm (void)
14099{
14100 /* P, U and L bits are part of bitmask. */
14101 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14102 unsigned offsetbits = inst.operands[1].imm * 2;
14103
037e8744
JB
14104 if (inst.operands[1].issingle)
14105 {
14106 do_vfp_nsyn_ldm_stm (is_dbmode);
14107 return;
14108 }
14109
5287ad62
JB
14110 constraint (is_dbmode && !inst.operands[0].writeback,
14111 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14112
14113 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14114 _("register list must contain at least 1 and at most 16 "
14115 "registers"));
14116
14117 inst.instruction |= inst.operands[0].reg << 16;
14118 inst.instruction |= inst.operands[0].writeback << 21;
14119 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14120 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14121
14122 inst.instruction |= offsetbits;
5f4273c7 14123
037e8744 14124 do_vfp_cond_or_thumb ();
5287ad62
JB
14125}
14126
14127static void
14128do_neon_ldr_str (void)
14129{
5287ad62 14130 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14131
037e8744
JB
14132 if (inst.operands[0].issingle)
14133 {
cd2f129f
JB
14134 if (is_ldr)
14135 do_vfp_nsyn_opcode ("flds");
14136 else
14137 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14138 }
14139 else
5287ad62 14140 {
cd2f129f
JB
14141 if (is_ldr)
14142 do_vfp_nsyn_opcode ("fldd");
5287ad62 14143 else
cd2f129f 14144 do_vfp_nsyn_opcode ("fstd");
5287ad62 14145 }
5287ad62
JB
14146}
14147
14148/* "interleave" version also handles non-interleaving register VLD1/VST1
14149 instructions. */
14150
14151static void
14152do_neon_ld_st_interleave (void)
14153{
037e8744 14154 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14155 N_8 | N_16 | N_32 | N_64);
14156 unsigned alignbits = 0;
14157 unsigned idx;
14158 /* The bits in this table go:
14159 0: register stride of one (0) or two (1)
14160 1,2: register list length, minus one (1, 2, 3, 4).
14161 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14162 We use -1 for invalid entries. */
14163 const int typetable[] =
14164 {
14165 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14166 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14167 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14168 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14169 };
14170 int typebits;
14171
dcbf9037
JB
14172 if (et.type == NT_invtype)
14173 return;
14174
5287ad62
JB
14175 if (inst.operands[1].immisalign)
14176 switch (inst.operands[1].imm >> 8)
14177 {
14178 case 64: alignbits = 1; break;
14179 case 128:
14180 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14181 goto bad_alignment;
14182 alignbits = 2;
14183 break;
14184 case 256:
14185 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14186 goto bad_alignment;
14187 alignbits = 3;
14188 break;
14189 default:
14190 bad_alignment:
dcbf9037 14191 first_error (_("bad alignment"));
5287ad62
JB
14192 return;
14193 }
14194
14195 inst.instruction |= alignbits << 4;
14196 inst.instruction |= neon_logbits (et.size) << 6;
14197
14198 /* Bits [4:6] of the immediate in a list specifier encode register stride
14199 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14200 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14201 up the right value for "type" in a table based on this value and the given
14202 list style, then stick it back. */
14203 idx = ((inst.operands[0].imm >> 4) & 7)
14204 | (((inst.instruction >> 8) & 3) << 3);
14205
14206 typebits = typetable[idx];
5f4273c7 14207
5287ad62
JB
14208 constraint (typebits == -1, _("bad list type for instruction"));
14209
14210 inst.instruction &= ~0xf00;
14211 inst.instruction |= typebits << 8;
14212}
14213
14214/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14215 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14216 otherwise. The variable arguments are a list of pairs of legal (size, align)
14217 values, terminated with -1. */
14218
14219static int
14220neon_alignment_bit (int size, int align, int *do_align, ...)
14221{
14222 va_list ap;
14223 int result = FAIL, thissize, thisalign;
5f4273c7 14224
5287ad62
JB
14225 if (!inst.operands[1].immisalign)
14226 {
14227 *do_align = 0;
14228 return SUCCESS;
14229 }
5f4273c7 14230
5287ad62
JB
14231 va_start (ap, do_align);
14232
14233 do
14234 {
14235 thissize = va_arg (ap, int);
14236 if (thissize == -1)
14237 break;
14238 thisalign = va_arg (ap, int);
14239
14240 if (size == thissize && align == thisalign)
14241 result = SUCCESS;
14242 }
14243 while (result != SUCCESS);
14244
14245 va_end (ap);
14246
14247 if (result == SUCCESS)
14248 *do_align = 1;
14249 else
dcbf9037 14250 first_error (_("unsupported alignment for instruction"));
5f4273c7 14251
5287ad62
JB
14252 return result;
14253}
14254
14255static void
14256do_neon_ld_st_lane (void)
14257{
037e8744 14258 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14259 int align_good, do_align = 0;
14260 int logsize = neon_logbits (et.size);
14261 int align = inst.operands[1].imm >> 8;
14262 int n = (inst.instruction >> 8) & 3;
14263 int max_el = 64 / et.size;
5f4273c7 14264
dcbf9037
JB
14265 if (et.type == NT_invtype)
14266 return;
5f4273c7 14267
5287ad62
JB
14268 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14269 _("bad list length"));
14270 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14271 _("scalar index out of range"));
14272 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14273 && et.size == 8,
14274 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14275
5287ad62
JB
14276 switch (n)
14277 {
14278 case 0: /* VLD1 / VST1. */
14279 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14280 32, 32, -1);
14281 if (align_good == FAIL)
14282 return;
14283 if (do_align)
14284 {
14285 unsigned alignbits = 0;
14286 switch (et.size)
14287 {
14288 case 16: alignbits = 0x1; break;
14289 case 32: alignbits = 0x3; break;
14290 default: ;
14291 }
14292 inst.instruction |= alignbits << 4;
14293 }
14294 break;
14295
14296 case 1: /* VLD2 / VST2. */
14297 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14298 32, 64, -1);
14299 if (align_good == FAIL)
14300 return;
14301 if (do_align)
14302 inst.instruction |= 1 << 4;
14303 break;
14304
14305 case 2: /* VLD3 / VST3. */
14306 constraint (inst.operands[1].immisalign,
14307 _("can't use alignment with this instruction"));
14308 break;
14309
14310 case 3: /* VLD4 / VST4. */
14311 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14312 16, 64, 32, 64, 32, 128, -1);
14313 if (align_good == FAIL)
14314 return;
14315 if (do_align)
14316 {
14317 unsigned alignbits = 0;
14318 switch (et.size)
14319 {
14320 case 8: alignbits = 0x1; break;
14321 case 16: alignbits = 0x1; break;
14322 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14323 default: ;
14324 }
14325 inst.instruction |= alignbits << 4;
14326 }
14327 break;
14328
14329 default: ;
14330 }
14331
14332 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14333 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14334 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14335
5287ad62
JB
14336 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14337 inst.instruction |= logsize << 10;
14338}
14339
14340/* Encode single n-element structure to all lanes VLD<n> instructions. */
14341
14342static void
14343do_neon_ld_dup (void)
14344{
037e8744 14345 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14346 int align_good, do_align = 0;
14347
dcbf9037
JB
14348 if (et.type == NT_invtype)
14349 return;
14350
5287ad62
JB
14351 switch ((inst.instruction >> 8) & 3)
14352 {
14353 case 0: /* VLD1. */
9c2799c2 14354 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14355 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14356 &do_align, 16, 16, 32, 32, -1);
14357 if (align_good == FAIL)
14358 return;
14359 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14360 {
14361 case 1: break;
14362 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14363 default: first_error (_("bad list length")); return;
5287ad62
JB
14364 }
14365 inst.instruction |= neon_logbits (et.size) << 6;
14366 break;
14367
14368 case 1: /* VLD2. */
14369 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14370 &do_align, 8, 16, 16, 32, 32, 64, -1);
14371 if (align_good == FAIL)
14372 return;
14373 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14374 _("bad list length"));
14375 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14376 inst.instruction |= 1 << 5;
14377 inst.instruction |= neon_logbits (et.size) << 6;
14378 break;
14379
14380 case 2: /* VLD3. */
14381 constraint (inst.operands[1].immisalign,
14382 _("can't use alignment with this instruction"));
14383 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14384 _("bad list length"));
14385 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14386 inst.instruction |= 1 << 5;
14387 inst.instruction |= neon_logbits (et.size) << 6;
14388 break;
14389
14390 case 3: /* VLD4. */
14391 {
14392 int align = inst.operands[1].imm >> 8;
14393 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14394 16, 64, 32, 64, 32, 128, -1);
14395 if (align_good == FAIL)
14396 return;
14397 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14398 _("bad list length"));
14399 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14400 inst.instruction |= 1 << 5;
14401 if (et.size == 32 && align == 128)
14402 inst.instruction |= 0x3 << 6;
14403 else
14404 inst.instruction |= neon_logbits (et.size) << 6;
14405 }
14406 break;
14407
14408 default: ;
14409 }
14410
14411 inst.instruction |= do_align << 4;
14412}
14413
14414/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14415 apart from bits [11:4]. */
14416
14417static void
14418do_neon_ldx_stx (void)
14419{
14420 switch (NEON_LANE (inst.operands[0].imm))
14421 {
14422 case NEON_INTERLEAVE_LANES:
14423 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14424 do_neon_ld_st_interleave ();
14425 break;
5f4273c7 14426
5287ad62
JB
14427 case NEON_ALL_LANES:
14428 inst.instruction = NEON_ENC_DUP (inst.instruction);
14429 do_neon_ld_dup ();
14430 break;
5f4273c7 14431
5287ad62
JB
14432 default:
14433 inst.instruction = NEON_ENC_LANE (inst.instruction);
14434 do_neon_ld_st_lane ();
14435 }
14436
14437 /* L bit comes from bit mask. */
14438 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14439 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14440 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14441
5287ad62
JB
14442 if (inst.operands[1].postind)
14443 {
14444 int postreg = inst.operands[1].imm & 0xf;
14445 constraint (!inst.operands[1].immisreg,
14446 _("post-index must be a register"));
14447 constraint (postreg == 0xd || postreg == 0xf,
14448 _("bad register for post-index"));
14449 inst.instruction |= postreg;
14450 }
14451 else if (inst.operands[1].writeback)
14452 {
14453 inst.instruction |= 0xd;
14454 }
14455 else
5f4273c7
NC
14456 inst.instruction |= 0xf;
14457
5287ad62
JB
14458 if (thumb_mode)
14459 inst.instruction |= 0xf9000000;
14460 else
14461 inst.instruction |= 0xf4000000;
14462}
5287ad62
JB
14463\f
14464/* Overall per-instruction processing. */
14465
14466/* We need to be able to fix up arbitrary expressions in some statements.
14467 This is so that we can handle symbols that are an arbitrary distance from
14468 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14469 which returns part of an address in a form which will be valid for
14470 a data instruction. We do this by pushing the expression into a symbol
14471 in the expr_section, and creating a fix for that. */
14472
14473static void
14474fix_new_arm (fragS * frag,
14475 int where,
14476 short int size,
14477 expressionS * exp,
14478 int pc_rel,
14479 int reloc)
14480{
14481 fixS * new_fix;
14482
14483 switch (exp->X_op)
14484 {
14485 case O_constant:
14486 case O_symbol:
14487 case O_add:
14488 case O_subtract:
14489 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14490 break;
14491
14492 default:
14493 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14494 pc_rel, reloc);
14495 break;
14496 }
14497
14498 /* Mark whether the fix is to a THUMB instruction, or an ARM
14499 instruction. */
14500 new_fix->tc_fix_data = thumb_mode;
14501}
14502
14503/* Create a frg for an instruction requiring relaxation. */
14504static void
14505output_relax_insn (void)
14506{
14507 char * to;
14508 symbolS *sym;
0110f2b8
PB
14509 int offset;
14510
6e1cb1a6
PB
14511 /* The size of the instruction is unknown, so tie the debug info to the
14512 start of the instruction. */
14513 dwarf2_emit_insn (0);
6e1cb1a6 14514
0110f2b8
PB
14515 switch (inst.reloc.exp.X_op)
14516 {
14517 case O_symbol:
14518 sym = inst.reloc.exp.X_add_symbol;
14519 offset = inst.reloc.exp.X_add_number;
14520 break;
14521 case O_constant:
14522 sym = NULL;
14523 offset = inst.reloc.exp.X_add_number;
14524 break;
14525 default:
14526 sym = make_expr_symbol (&inst.reloc.exp);
14527 offset = 0;
14528 break;
14529 }
14530 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14531 inst.relax, sym, offset, NULL/*offset, opcode*/);
14532 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14533}
14534
14535/* Write a 32-bit thumb instruction to buf. */
14536static void
14537put_thumb32_insn (char * buf, unsigned long insn)
14538{
14539 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14540 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14541}
14542
b99bd4ef 14543static void
c19d1205 14544output_inst (const char * str)
b99bd4ef 14545{
c19d1205 14546 char * to = NULL;
b99bd4ef 14547
c19d1205 14548 if (inst.error)
b99bd4ef 14549 {
c19d1205 14550 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14551 return;
14552 }
5f4273c7
NC
14553 if (inst.relax)
14554 {
14555 output_relax_insn ();
0110f2b8 14556 return;
5f4273c7 14557 }
c19d1205
ZW
14558 if (inst.size == 0)
14559 return;
b99bd4ef 14560
c19d1205 14561 to = frag_more (inst.size);
8dc2430f
NC
14562 /* PR 9814: Record the thumb mode into the current frag so that we know
14563 what type of NOP padding to use, if necessary. We override any previous
14564 setting so that if the mode has changed then the NOPS that we use will
14565 match the encoding of the last instruction in the frag. */
14566 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14567
14568 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14569 {
9c2799c2 14570 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14571 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14572 }
c19d1205 14573 else if (inst.size > INSN_SIZE)
b99bd4ef 14574 {
9c2799c2 14575 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
14576 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14577 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14578 }
c19d1205
ZW
14579 else
14580 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14581
c19d1205
ZW
14582 if (inst.reloc.type != BFD_RELOC_UNUSED)
14583 fix_new_arm (frag_now, to - frag_now->fr_literal,
14584 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14585 inst.reloc.type);
b99bd4ef 14586
c19d1205 14587 dwarf2_emit_insn (inst.size);
c19d1205 14588}
b99bd4ef 14589
e07e6e58
NC
14590static char *
14591output_it_inst (int cond, int mask, char * to)
14592{
14593 unsigned long instruction = 0xbf00;
14594
14595 mask &= 0xf;
14596 instruction |= mask;
14597 instruction |= cond << 4;
14598
14599 if (to == NULL)
14600 {
14601 to = frag_more (2);
14602#ifdef OBJ_ELF
14603 dwarf2_emit_insn (2);
14604#endif
14605 }
14606
14607 md_number_to_chars (to, instruction, 2);
14608
14609 return to;
14610}
14611
c19d1205
ZW
14612/* Tag values used in struct asm_opcode's tag field. */
14613enum opcode_tag
14614{
14615 OT_unconditional, /* Instruction cannot be conditionalized.
14616 The ARM condition field is still 0xE. */
14617 OT_unconditionalF, /* Instruction cannot be conditionalized
14618 and carries 0xF in its ARM condition field. */
14619 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14620 OT_csuffixF, /* Some forms of the instruction take a conditional
14621 suffix, others place 0xF where the condition field
14622 would be. */
c19d1205
ZW
14623 OT_cinfix3, /* Instruction takes a conditional infix,
14624 beginning at character index 3. (In
14625 unified mode, it becomes a suffix.) */
088fa78e
KH
14626 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14627 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14628 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14629 character index 3, even in unified mode. Used for
14630 legacy instructions where suffix and infix forms
14631 may be ambiguous. */
c19d1205 14632 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14633 suffix or an infix at character index 3. */
c19d1205
ZW
14634 OT_odd_infix_unc, /* This is the unconditional variant of an
14635 instruction that takes a conditional infix
14636 at an unusual position. In unified mode,
14637 this variant will accept a suffix. */
14638 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14639 are the conditional variants of instructions that
14640 take conditional infixes in unusual positions.
14641 The infix appears at character index
14642 (tag - OT_odd_infix_0). These are not accepted
14643 in unified mode. */
14644};
b99bd4ef 14645
c19d1205
ZW
14646/* Subroutine of md_assemble, responsible for looking up the primary
14647 opcode from the mnemonic the user wrote. STR points to the
14648 beginning of the mnemonic.
14649
14650 This is not simply a hash table lookup, because of conditional
14651 variants. Most instructions have conditional variants, which are
14652 expressed with a _conditional affix_ to the mnemonic. If we were
14653 to encode each conditional variant as a literal string in the opcode
14654 table, it would have approximately 20,000 entries.
14655
14656 Most mnemonics take this affix as a suffix, and in unified syntax,
14657 'most' is upgraded to 'all'. However, in the divided syntax, some
14658 instructions take the affix as an infix, notably the s-variants of
14659 the arithmetic instructions. Of those instructions, all but six
14660 have the infix appear after the third character of the mnemonic.
14661
14662 Accordingly, the algorithm for looking up primary opcodes given
14663 an identifier is:
14664
14665 1. Look up the identifier in the opcode table.
14666 If we find a match, go to step U.
14667
14668 2. Look up the last two characters of the identifier in the
14669 conditions table. If we find a match, look up the first N-2
14670 characters of the identifier in the opcode table. If we
14671 find a match, go to step CE.
14672
14673 3. Look up the fourth and fifth characters of the identifier in
14674 the conditions table. If we find a match, extract those
14675 characters from the identifier, and look up the remaining
14676 characters in the opcode table. If we find a match, go
14677 to step CM.
14678
14679 4. Fail.
14680
14681 U. Examine the tag field of the opcode structure, in case this is
14682 one of the six instructions with its conditional infix in an
14683 unusual place. If it is, the tag tells us where to find the
14684 infix; look it up in the conditions table and set inst.cond
14685 accordingly. Otherwise, this is an unconditional instruction.
14686 Again set inst.cond accordingly. Return the opcode structure.
14687
14688 CE. Examine the tag field to make sure this is an instruction that
14689 should receive a conditional suffix. If it is not, fail.
14690 Otherwise, set inst.cond from the suffix we already looked up,
14691 and return the opcode structure.
14692
14693 CM. Examine the tag field to make sure this is an instruction that
14694 should receive a conditional infix after the third character.
14695 If it is not, fail. Otherwise, undo the edits to the current
14696 line of input and proceed as for case CE. */
14697
14698static const struct asm_opcode *
14699opcode_lookup (char **str)
14700{
14701 char *end, *base;
14702 char *affix;
14703 const struct asm_opcode *opcode;
14704 const struct asm_cond *cond;
e3cb604e 14705 char save[2];
267d2029 14706 bfd_boolean neon_supported;
5f4273c7 14707
267d2029 14708 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14709
14710 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14711 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14712 for (base = end = *str; *end != '\0'; end++)
267d2029 14713 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14714 break;
b99bd4ef 14715
c19d1205
ZW
14716 if (end == base)
14717 return 0;
b99bd4ef 14718
5287ad62 14719 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14720 if (end[0] == '.')
b99bd4ef 14721 {
5287ad62 14722 int offset = 2;
5f4273c7 14723
267d2029
JB
14724 /* The .w and .n suffixes are only valid if the unified syntax is in
14725 use. */
14726 if (unified_syntax && end[1] == 'w')
c19d1205 14727 inst.size_req = 4;
267d2029 14728 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14729 inst.size_req = 2;
14730 else
5287ad62
JB
14731 offset = 0;
14732
14733 inst.vectype.elems = 0;
14734
14735 *str = end + offset;
b99bd4ef 14736
5f4273c7 14737 if (end[offset] == '.')
5287ad62 14738 {
267d2029
JB
14739 /* See if we have a Neon type suffix (possible in either unified or
14740 non-unified ARM syntax mode). */
dcbf9037 14741 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14742 return 0;
14743 }
14744 else if (end[offset] != '\0' && end[offset] != ' ')
14745 return 0;
b99bd4ef 14746 }
c19d1205
ZW
14747 else
14748 *str = end;
b99bd4ef 14749
c19d1205
ZW
14750 /* Look for unaffixed or special-case affixed mnemonic. */
14751 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14752 if (opcode)
b99bd4ef 14753 {
c19d1205
ZW
14754 /* step U */
14755 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14756 {
c19d1205
ZW
14757 inst.cond = COND_ALWAYS;
14758 return opcode;
b99bd4ef 14759 }
b99bd4ef 14760
278df34e 14761 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
14762 as_warn (_("conditional infixes are deprecated in unified syntax"));
14763 affix = base + (opcode->tag - OT_odd_infix_0);
14764 cond = hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 14765 gas_assert (cond);
b99bd4ef 14766
c19d1205
ZW
14767 inst.cond = cond->value;
14768 return opcode;
14769 }
b99bd4ef 14770
c19d1205
ZW
14771 /* Cannot have a conditional suffix on a mnemonic of less than two
14772 characters. */
14773 if (end - base < 3)
14774 return 0;
b99bd4ef 14775
c19d1205
ZW
14776 /* Look for suffixed mnemonic. */
14777 affix = end - 2;
14778 cond = hash_find_n (arm_cond_hsh, affix, 2);
14779 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14780 if (opcode && cond)
14781 {
14782 /* step CE */
14783 switch (opcode->tag)
14784 {
e3cb604e
PB
14785 case OT_cinfix3_legacy:
14786 /* Ignore conditional suffixes matched on infix only mnemonics. */
14787 break;
14788
c19d1205 14789 case OT_cinfix3:
088fa78e 14790 case OT_cinfix3_deprecated:
c19d1205
ZW
14791 case OT_odd_infix_unc:
14792 if (!unified_syntax)
e3cb604e 14793 return 0;
c19d1205
ZW
14794 /* else fall through */
14795
14796 case OT_csuffix:
037e8744 14797 case OT_csuffixF:
c19d1205
ZW
14798 case OT_csuf_or_in3:
14799 inst.cond = cond->value;
14800 return opcode;
14801
14802 case OT_unconditional:
14803 case OT_unconditionalF:
dfa9f0d5
PB
14804 if (thumb_mode)
14805 {
14806 inst.cond = cond->value;
14807 }
14808 else
14809 {
14810 /* delayed diagnostic */
14811 inst.error = BAD_COND;
14812 inst.cond = COND_ALWAYS;
14813 }
c19d1205 14814 return opcode;
b99bd4ef 14815
c19d1205
ZW
14816 default:
14817 return 0;
14818 }
14819 }
b99bd4ef 14820
c19d1205
ZW
14821 /* Cannot have a usual-position infix on a mnemonic of less than
14822 six characters (five would be a suffix). */
14823 if (end - base < 6)
14824 return 0;
b99bd4ef 14825
c19d1205
ZW
14826 /* Look for infixed mnemonic in the usual position. */
14827 affix = base + 3;
14828 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14829 if (!cond)
14830 return 0;
14831
14832 memcpy (save, affix, 2);
14833 memmove (affix, affix + 2, (end - affix) - 2);
14834 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14835 memmove (affix + 2, affix, (end - affix) - 2);
14836 memcpy (affix, save, 2);
14837
088fa78e
KH
14838 if (opcode
14839 && (opcode->tag == OT_cinfix3
14840 || opcode->tag == OT_cinfix3_deprecated
14841 || opcode->tag == OT_csuf_or_in3
14842 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14843 {
c19d1205 14844 /* step CM */
278df34e 14845 if (warn_on_deprecated && unified_syntax
088fa78e
KH
14846 && (opcode->tag == OT_cinfix3
14847 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14848 as_warn (_("conditional infixes are deprecated in unified syntax"));
14849
14850 inst.cond = cond->value;
14851 return opcode;
b99bd4ef
NC
14852 }
14853
c19d1205 14854 return 0;
b99bd4ef
NC
14855}
14856
e07e6e58
NC
14857/* This function generates an initial IT instruction, leaving its block
14858 virtually open for the new instructions. Eventually,
14859 the mask will be updated by now_it_add_mask () each time
14860 a new instruction needs to be included in the IT block.
14861 Finally, the block is closed with close_automatic_it_block ().
14862 The block closure can be requested either from md_assemble (),
14863 a tencode (), or due to a label hook. */
14864
14865static void
14866new_automatic_it_block (int cond)
14867{
14868 now_it.state = AUTOMATIC_IT_BLOCK;
14869 now_it.mask = 0x18;
14870 now_it.cc = cond;
14871 now_it.block_length = 1;
14872 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
14873}
14874
14875/* Close an automatic IT block.
14876 See comments in new_automatic_it_block (). */
14877
14878static void
14879close_automatic_it_block (void)
14880{
14881 now_it.mask = 0x10;
14882 now_it.block_length = 0;
14883}
14884
14885/* Update the mask of the current automatically-generated IT
14886 instruction. See comments in new_automatic_it_block (). */
14887
14888static void
14889now_it_add_mask (int cond)
14890{
14891#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
14892#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
14893 | ((bitvalue) << (nbit)))
14894
14895 const int resulting_bit = (cond & 1);
14896 now_it.mask &= 0xf;
14897 now_it.mask = SET_BIT_VALUE (now_it.mask,
14898 resulting_bit,
14899 (5 - now_it.block_length));
14900 now_it.mask = SET_BIT_VALUE (now_it.mask,
14901 1,
14902 ((5 - now_it.block_length) - 1) );
14903 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
14904
14905#undef CLEAR_BIT
14906#undef SET_BIT_VALUE
14907
14908}
14909
14910/* The IT blocks handling machinery is accessed through the these functions:
14911 it_fsm_pre_encode () from md_assemble ()
14912 set_it_insn_type () optional, from the tencode functions
14913 set_it_insn_type_last () ditto
14914 in_it_block () ditto
14915 it_fsm_post_encode () from md_assemble ()
14916 force_automatic_it_block_close () from label habdling functions
14917
14918 Rationale:
14919 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
14920 initializing the IT insn type with a generic initial value depending
14921 on the inst.condition.
14922 2) During the tencode function, two things may happen:
14923 a) The tencode function overrides the IT insn type by
14924 calling either set_it_insn_type (type) or set_it_insn_type_last ().
14925 b) The tencode function queries the IT block state by
14926 calling in_it_block () (i.e. to determine narrow/not narrow mode).
14927
14928 Both set_it_insn_type and in_it_block run the internal FSM state
14929 handling function (handle_it_state), because: a) setting the IT insn
14930 type may incur in an invalid state (exiting the function),
14931 and b) querying the state requires the FSM to be updated.
14932 Specifically we want to avoid creating an IT block for conditional
14933 branches, so it_fsm_pre_encode is actually a guess and we can't
14934 determine whether an IT block is required until the tencode () routine
14935 has decided what type of instruction this actually it.
14936 Because of this, if set_it_insn_type and in_it_block have to be used,
14937 set_it_insn_type has to be called first.
14938
14939 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
14940 determines the insn IT type depending on the inst.cond code.
14941 When a tencode () routine encodes an instruction that can be
14942 either outside an IT block, or, in the case of being inside, has to be
14943 the last one, set_it_insn_type_last () will determine the proper
14944 IT instruction type based on the inst.cond code. Otherwise,
14945 set_it_insn_type can be called for overriding that logic or
14946 for covering other cases.
14947
14948 Calling handle_it_state () may not transition the IT block state to
14949 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
14950 still queried. Instead, if the FSM determines that the state should
14951 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
14952 after the tencode () function: that's what it_fsm_post_encode () does.
14953
14954 Since in_it_block () calls the state handling function to get an
14955 updated state, an error may occur (due to invalid insns combination).
14956 In that case, inst.error is set.
14957 Therefore, inst.error has to be checked after the execution of
14958 the tencode () routine.
14959
14960 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
14961 any pending state change (if any) that didn't take place in
14962 handle_it_state () as explained above. */
14963
14964static void
14965it_fsm_pre_encode (void)
14966{
14967 if (inst.cond != COND_ALWAYS)
14968 inst.it_insn_type = INSIDE_IT_INSN;
14969 else
14970 inst.it_insn_type = OUTSIDE_IT_INSN;
14971
14972 now_it.state_handled = 0;
14973}
14974
14975/* IT state FSM handling function. */
14976
14977static int
14978handle_it_state (void)
14979{
14980 now_it.state_handled = 1;
14981
14982 switch (now_it.state)
14983 {
14984 case OUTSIDE_IT_BLOCK:
14985 switch (inst.it_insn_type)
14986 {
14987 case OUTSIDE_IT_INSN:
14988 break;
14989
14990 case INSIDE_IT_INSN:
14991 case INSIDE_IT_LAST_INSN:
14992 if (thumb_mode == 0)
14993 {
14994 if (unified_syntax
14995 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
14996 as_tsktsk (_("Warning: conditional outside an IT block"\
14997 " for Thumb."));
14998 }
14999 else
15000 {
15001 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15002 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15003 {
15004 /* Automatically generate the IT instruction. */
15005 new_automatic_it_block (inst.cond);
15006 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15007 close_automatic_it_block ();
15008 }
15009 else
15010 {
15011 inst.error = BAD_OUT_IT;
15012 return FAIL;
15013 }
15014 }
15015 break;
15016
15017 case IF_INSIDE_IT_LAST_INSN:
15018 case NEUTRAL_IT_INSN:
15019 break;
15020
15021 case IT_INSN:
15022 now_it.state = MANUAL_IT_BLOCK;
15023 now_it.block_length = 0;
15024 break;
15025 }
15026 break;
15027
15028 case AUTOMATIC_IT_BLOCK:
15029 /* Three things may happen now:
15030 a) We should increment current it block size;
15031 b) We should close current it block (closing insn or 4 insns);
15032 c) We should close current it block and start a new one (due
15033 to incompatible conditions or
15034 4 insns-length block reached). */
15035
15036 switch (inst.it_insn_type)
15037 {
15038 case OUTSIDE_IT_INSN:
15039 /* The closure of the block shall happen immediatelly,
15040 so any in_it_block () call reports the block as closed. */
15041 force_automatic_it_block_close ();
15042 break;
15043
15044 case INSIDE_IT_INSN:
15045 case INSIDE_IT_LAST_INSN:
15046 case IF_INSIDE_IT_LAST_INSN:
15047 now_it.block_length++;
15048
15049 if (now_it.block_length > 4
15050 || !now_it_compatible (inst.cond))
15051 {
15052 force_automatic_it_block_close ();
15053 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15054 new_automatic_it_block (inst.cond);
15055 }
15056 else
15057 {
15058 now_it_add_mask (inst.cond);
15059 }
15060
15061 if (now_it.state == AUTOMATIC_IT_BLOCK
15062 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15063 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15064 close_automatic_it_block ();
15065 break;
15066
15067 case NEUTRAL_IT_INSN:
15068 now_it.block_length++;
15069
15070 if (now_it.block_length > 4)
15071 force_automatic_it_block_close ();
15072 else
15073 now_it_add_mask (now_it.cc & 1);
15074 break;
15075
15076 case IT_INSN:
15077 close_automatic_it_block ();
15078 now_it.state = MANUAL_IT_BLOCK;
15079 break;
15080 }
15081 break;
15082
15083 case MANUAL_IT_BLOCK:
15084 {
15085 /* Check conditional suffixes. */
15086 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15087 int is_last;
15088 now_it.mask <<= 1;
15089 now_it.mask &= 0x1f;
15090 is_last = (now_it.mask == 0x10);
15091
15092 switch (inst.it_insn_type)
15093 {
15094 case OUTSIDE_IT_INSN:
15095 inst.error = BAD_NOT_IT;
15096 return FAIL;
15097
15098 case INSIDE_IT_INSN:
15099 if (cond != inst.cond)
15100 {
15101 inst.error = BAD_IT_COND;
15102 return FAIL;
15103 }
15104 break;
15105
15106 case INSIDE_IT_LAST_INSN:
15107 case IF_INSIDE_IT_LAST_INSN:
15108 if (cond != inst.cond)
15109 {
15110 inst.error = BAD_IT_COND;
15111 return FAIL;
15112 }
15113 if (!is_last)
15114 {
15115 inst.error = BAD_BRANCH;
15116 return FAIL;
15117 }
15118 break;
15119
15120 case NEUTRAL_IT_INSN:
15121 /* The BKPT instruction is unconditional even in an IT block. */
15122 break;
15123
15124 case IT_INSN:
15125 inst.error = BAD_IT_IT;
15126 return FAIL;
15127 }
15128 }
15129 break;
15130 }
15131
15132 return SUCCESS;
15133}
15134
15135static void
15136it_fsm_post_encode (void)
15137{
15138 int is_last;
15139
15140 if (!now_it.state_handled)
15141 handle_it_state ();
15142
15143 is_last = (now_it.mask == 0x10);
15144 if (is_last)
15145 {
15146 now_it.state = OUTSIDE_IT_BLOCK;
15147 now_it.mask = 0;
15148 }
15149}
15150
15151static void
15152force_automatic_it_block_close (void)
15153{
15154 if (now_it.state == AUTOMATIC_IT_BLOCK)
15155 {
15156 close_automatic_it_block ();
15157 now_it.state = OUTSIDE_IT_BLOCK;
15158 now_it.mask = 0;
15159 }
15160}
15161
15162static int
15163in_it_block (void)
15164{
15165 if (!now_it.state_handled)
15166 handle_it_state ();
15167
15168 return now_it.state != OUTSIDE_IT_BLOCK;
15169}
15170
c19d1205
ZW
15171void
15172md_assemble (char *str)
b99bd4ef 15173{
c19d1205
ZW
15174 char *p = str;
15175 const struct asm_opcode * opcode;
b99bd4ef 15176
c19d1205
ZW
15177 /* Align the previous label if needed. */
15178 if (last_label_seen != NULL)
b99bd4ef 15179 {
c19d1205
ZW
15180 symbol_set_frag (last_label_seen, frag_now);
15181 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15182 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15183 }
15184
c19d1205
ZW
15185 memset (&inst, '\0', sizeof (inst));
15186 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15187
c19d1205
ZW
15188 opcode = opcode_lookup (&p);
15189 if (!opcode)
b99bd4ef 15190 {
c19d1205 15191 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
15192 the form alias .req reg, or a Neon .dn/.qn directive. */
15193 if (!create_register_alias (str, p)
15194 && !create_neon_reg_alias (str, p))
c19d1205 15195 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15196
b99bd4ef
NC
15197 return;
15198 }
15199
278df34e 15200 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15201 as_warn (_("s suffix on comparison instruction is deprecated"));
15202
037e8744
JB
15203 /* The value which unconditional instructions should have in place of the
15204 condition field. */
15205 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15206
c19d1205 15207 if (thumb_mode)
b99bd4ef 15208 {
e74cfd16 15209 arm_feature_set variant;
8f06b2d8
PB
15210
15211 variant = cpu_variant;
15212 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15213 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15214 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15215 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15216 if (!opcode->tvariant
15217 || (thumb_mode == 1
15218 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15219 {
c19d1205 15220 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
15221 return;
15222 }
c19d1205
ZW
15223 if (inst.cond != COND_ALWAYS && !unified_syntax
15224 && opcode->tencode != do_t_branch)
b99bd4ef 15225 {
c19d1205 15226 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15227 return;
15228 }
15229
076d447c
PB
15230 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
15231 {
15232 /* Implicit require narrow instructions on Thumb-1. This avoids
15233 relaxation accidentally introducing Thumb-2 instructions. */
7e806470 15234 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
e07e6e58
NC
15235 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15236 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
076d447c
PB
15237 inst.size_req = 2;
15238 }
15239
c19d1205
ZW
15240 mapping_state (MAP_THUMB);
15241 inst.instruction = opcode->tvalue;
15242
15243 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15244 {
15245 /* Prepare the it_insn_type for those encodings that don't set
15246 it. */
15247 it_fsm_pre_encode ();
c19d1205 15248
e07e6e58
NC
15249 opcode->tencode ();
15250
15251 it_fsm_post_encode ();
15252 }
e27ec89e 15253
0110f2b8 15254 if (!(inst.error || inst.relax))
b99bd4ef 15255 {
9c2799c2 15256 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15257 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15258 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15259 {
c19d1205 15260 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15261 return;
15262 }
15263 }
076d447c
PB
15264
15265 /* Something has gone badly wrong if we try to relax a fixed size
15266 instruction. */
9c2799c2 15267 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15268
e74cfd16
PB
15269 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15270 *opcode->tvariant);
ee065d83 15271 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15272 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15273 anything other than bl/blx and v6-M instructions.
ee065d83 15274 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15275 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15276 || inst.relax)
e07e6e58
NC
15277 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15278 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15279 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15280 arm_ext_v6t2);
c19d1205 15281 }
3e9e4fcf 15282 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15283 {
845b51d6
PB
15284 bfd_boolean is_bx;
15285
15286 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15287 is_bx = (opcode->aencode == do_bx);
15288
c19d1205 15289 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15290 if (!(is_bx && fix_v4bx)
15291 && !(opcode->avariant &&
15292 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15293 {
c19d1205
ZW
15294 as_bad (_("selected processor does not support `%s'"), str);
15295 return;
b99bd4ef 15296 }
c19d1205 15297 if (inst.size_req)
b99bd4ef 15298 {
c19d1205
ZW
15299 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15300 return;
b99bd4ef
NC
15301 }
15302
c19d1205
ZW
15303 mapping_state (MAP_ARM);
15304 inst.instruction = opcode->avalue;
15305 if (opcode->tag == OT_unconditionalF)
15306 inst.instruction |= 0xF << 28;
15307 else
15308 inst.instruction |= inst.cond << 28;
15309 inst.size = INSN_SIZE;
15310 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15311 {
15312 it_fsm_pre_encode ();
15313 opcode->aencode ();
15314 it_fsm_post_encode ();
15315 }
ee065d83
PB
15316 /* Arm mode bx is marked as both v4T and v5 because it's still required
15317 on a hypothetical non-thumb v5 core. */
845b51d6 15318 if (is_bx)
e74cfd16 15319 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15320 else
e74cfd16
PB
15321 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15322 *opcode->avariant);
b99bd4ef 15323 }
3e9e4fcf
JB
15324 else
15325 {
15326 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15327 "-- `%s'"), str);
15328 return;
15329 }
c19d1205
ZW
15330 output_inst (str);
15331}
b99bd4ef 15332
e07e6e58
NC
15333static void
15334check_it_blocks_finished (void)
15335{
15336#ifdef OBJ_ELF
15337 asection *sect;
15338
15339 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15340 if (seg_info (sect)->tc_segment_info_data.current_it.state
15341 == MANUAL_IT_BLOCK)
15342 {
15343 as_warn (_("section '%s' finished with an open IT block."),
15344 sect->name);
15345 }
15346#else
15347 if (now_it.state == MANUAL_IT_BLOCK)
15348 as_warn (_("file finished with an open IT block."));
15349#endif
15350}
15351
c19d1205
ZW
15352/* Various frobbings of labels and their addresses. */
15353
15354void
15355arm_start_line_hook (void)
15356{
15357 last_label_seen = NULL;
b99bd4ef
NC
15358}
15359
c19d1205
ZW
15360void
15361arm_frob_label (symbolS * sym)
b99bd4ef 15362{
c19d1205 15363 last_label_seen = sym;
b99bd4ef 15364
c19d1205 15365 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15366
c19d1205
ZW
15367#if defined OBJ_COFF || defined OBJ_ELF
15368 ARM_SET_INTERWORK (sym, support_interwork);
15369#endif
b99bd4ef 15370
e07e6e58
NC
15371 force_automatic_it_block_close ();
15372
5f4273c7 15373 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15374 as Thumb functions. This is because these labels, whilst
15375 they exist inside Thumb code, are not the entry points for
15376 possible ARM->Thumb calls. Also, these labels can be used
15377 as part of a computed goto or switch statement. eg gcc
15378 can generate code that looks like this:
b99bd4ef 15379
c19d1205
ZW
15380 ldr r2, [pc, .Laaa]
15381 lsl r3, r3, #2
15382 ldr r2, [r3, r2]
15383 mov pc, r2
b99bd4ef 15384
c19d1205
ZW
15385 .Lbbb: .word .Lxxx
15386 .Lccc: .word .Lyyy
15387 ..etc...
15388 .Laaa: .word Lbbb
b99bd4ef 15389
c19d1205
ZW
15390 The first instruction loads the address of the jump table.
15391 The second instruction converts a table index into a byte offset.
15392 The third instruction gets the jump address out of the table.
15393 The fourth instruction performs the jump.
b99bd4ef 15394
c19d1205
ZW
15395 If the address stored at .Laaa is that of a symbol which has the
15396 Thumb_Func bit set, then the linker will arrange for this address
15397 to have the bottom bit set, which in turn would mean that the
15398 address computation performed by the third instruction would end
15399 up with the bottom bit set. Since the ARM is capable of unaligned
15400 word loads, the instruction would then load the incorrect address
15401 out of the jump table, and chaos would ensue. */
15402 if (label_is_thumb_function_name
15403 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15404 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15405 {
c19d1205
ZW
15406 /* When the address of a Thumb function is taken the bottom
15407 bit of that address should be set. This will allow
15408 interworking between Arm and Thumb functions to work
15409 correctly. */
b99bd4ef 15410
c19d1205 15411 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15412
c19d1205 15413 label_is_thumb_function_name = FALSE;
b99bd4ef 15414 }
07a53e5c 15415
07a53e5c 15416 dwarf2_emit_label (sym);
b99bd4ef
NC
15417}
15418
c19d1205
ZW
15419int
15420arm_data_in_code (void)
b99bd4ef 15421{
c19d1205 15422 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15423 {
c19d1205
ZW
15424 *input_line_pointer = '/';
15425 input_line_pointer += 5;
15426 *input_line_pointer = 0;
15427 return 1;
b99bd4ef
NC
15428 }
15429
c19d1205 15430 return 0;
b99bd4ef
NC
15431}
15432
c19d1205
ZW
15433char *
15434arm_canonicalize_symbol_name (char * name)
b99bd4ef 15435{
c19d1205 15436 int len;
b99bd4ef 15437
c19d1205
ZW
15438 if (thumb_mode && (len = strlen (name)) > 5
15439 && streq (name + len - 5, "/data"))
15440 *(name + len - 5) = 0;
b99bd4ef 15441
c19d1205 15442 return name;
b99bd4ef 15443}
c19d1205
ZW
15444\f
15445/* Table of all register names defined by default. The user can
15446 define additional names with .req. Note that all register names
15447 should appear in both upper and lowercase variants. Some registers
15448 also have mixed-case names. */
b99bd4ef 15449
dcbf9037 15450#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15451#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15452#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15453#define REGSET(p,t) \
15454 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15455 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15456 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15457 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15458#define REGSETH(p,t) \
15459 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15460 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15461 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15462 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15463#define REGSET2(p,t) \
15464 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15465 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15466 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15467 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15468
c19d1205 15469static const struct reg_entry reg_names[] =
7ed4c4c5 15470{
c19d1205
ZW
15471 /* ARM integer registers. */
15472 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15473
c19d1205
ZW
15474 /* ATPCS synonyms. */
15475 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15476 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15477 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 15478
c19d1205
ZW
15479 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15480 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15481 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 15482
c19d1205
ZW
15483 /* Well-known aliases. */
15484 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15485 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15486
15487 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15488 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15489
15490 /* Coprocessor numbers. */
15491 REGSET(p, CP), REGSET(P, CP),
15492
15493 /* Coprocessor register numbers. The "cr" variants are for backward
15494 compatibility. */
15495 REGSET(c, CN), REGSET(C, CN),
15496 REGSET(cr, CN), REGSET(CR, CN),
15497
15498 /* FPA registers. */
15499 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15500 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15501
15502 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15503 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15504
15505 /* VFP SP registers. */
5287ad62
JB
15506 REGSET(s,VFS), REGSET(S,VFS),
15507 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15508
15509 /* VFP DP Registers. */
5287ad62
JB
15510 REGSET(d,VFD), REGSET(D,VFD),
15511 /* Extra Neon DP registers. */
15512 REGSETH(d,VFD), REGSETH(D,VFD),
15513
15514 /* Neon QP registers. */
15515 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15516
15517 /* VFP control registers. */
15518 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15519 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15520 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15521 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15522 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15523 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15524
15525 /* Maverick DSP coprocessor registers. */
15526 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15527 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15528
15529 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15530 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15531 REGDEF(dspsc,0,DSPSC),
15532
15533 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15534 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15535 REGDEF(DSPSC,0,DSPSC),
15536
15537 /* iWMMXt data registers - p0, c0-15. */
15538 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15539
15540 /* iWMMXt control registers - p1, c0-3. */
15541 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15542 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15543 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15544 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15545
15546 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15547 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15548 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15549 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15550 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15551
15552 /* XScale accumulator registers. */
15553 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15554};
15555#undef REGDEF
15556#undef REGNUM
15557#undef REGSET
7ed4c4c5 15558
c19d1205
ZW
15559/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15560 within psr_required_here. */
15561static const struct asm_psr psrs[] =
15562{
15563 /* Backward compatibility notation. Note that "all" is no longer
15564 truly all possible PSR bits. */
15565 {"all", PSR_c | PSR_f},
15566 {"flg", PSR_f},
15567 {"ctl", PSR_c},
15568
15569 /* Individual flags. */
15570 {"f", PSR_f},
15571 {"c", PSR_c},
15572 {"x", PSR_x},
15573 {"s", PSR_s},
15574 /* Combinations of flags. */
15575 {"fs", PSR_f | PSR_s},
15576 {"fx", PSR_f | PSR_x},
15577 {"fc", PSR_f | PSR_c},
15578 {"sf", PSR_s | PSR_f},
15579 {"sx", PSR_s | PSR_x},
15580 {"sc", PSR_s | PSR_c},
15581 {"xf", PSR_x | PSR_f},
15582 {"xs", PSR_x | PSR_s},
15583 {"xc", PSR_x | PSR_c},
15584 {"cf", PSR_c | PSR_f},
15585 {"cs", PSR_c | PSR_s},
15586 {"cx", PSR_c | PSR_x},
15587 {"fsx", PSR_f | PSR_s | PSR_x},
15588 {"fsc", PSR_f | PSR_s | PSR_c},
15589 {"fxs", PSR_f | PSR_x | PSR_s},
15590 {"fxc", PSR_f | PSR_x | PSR_c},
15591 {"fcs", PSR_f | PSR_c | PSR_s},
15592 {"fcx", PSR_f | PSR_c | PSR_x},
15593 {"sfx", PSR_s | PSR_f | PSR_x},
15594 {"sfc", PSR_s | PSR_f | PSR_c},
15595 {"sxf", PSR_s | PSR_x | PSR_f},
15596 {"sxc", PSR_s | PSR_x | PSR_c},
15597 {"scf", PSR_s | PSR_c | PSR_f},
15598 {"scx", PSR_s | PSR_c | PSR_x},
15599 {"xfs", PSR_x | PSR_f | PSR_s},
15600 {"xfc", PSR_x | PSR_f | PSR_c},
15601 {"xsf", PSR_x | PSR_s | PSR_f},
15602 {"xsc", PSR_x | PSR_s | PSR_c},
15603 {"xcf", PSR_x | PSR_c | PSR_f},
15604 {"xcs", PSR_x | PSR_c | PSR_s},
15605 {"cfs", PSR_c | PSR_f | PSR_s},
15606 {"cfx", PSR_c | PSR_f | PSR_x},
15607 {"csf", PSR_c | PSR_s | PSR_f},
15608 {"csx", PSR_c | PSR_s | PSR_x},
15609 {"cxf", PSR_c | PSR_x | PSR_f},
15610 {"cxs", PSR_c | PSR_x | PSR_s},
15611 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15612 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15613 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15614 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15615 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15616 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15617 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15618 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15619 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15620 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15621 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15622 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15623 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15624 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15625 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15626 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15627 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15628 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15629 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15630 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15631 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15632 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15633 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15634 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15635};
15636
62b3e311
PB
15637/* Table of V7M psr names. */
15638static const struct asm_psr v7m_psrs[] =
15639{
2b744c99
PB
15640 {"apsr", 0 }, {"APSR", 0 },
15641 {"iapsr", 1 }, {"IAPSR", 1 },
15642 {"eapsr", 2 }, {"EAPSR", 2 },
15643 {"psr", 3 }, {"PSR", 3 },
15644 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15645 {"ipsr", 5 }, {"IPSR", 5 },
15646 {"epsr", 6 }, {"EPSR", 6 },
15647 {"iepsr", 7 }, {"IEPSR", 7 },
15648 {"msp", 8 }, {"MSP", 8 },
15649 {"psp", 9 }, {"PSP", 9 },
15650 {"primask", 16}, {"PRIMASK", 16},
15651 {"basepri", 17}, {"BASEPRI", 17},
15652 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15653 {"faultmask", 19}, {"FAULTMASK", 19},
15654 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
15655};
15656
c19d1205
ZW
15657/* Table of all shift-in-operand names. */
15658static const struct asm_shift_name shift_names [] =
b99bd4ef 15659{
c19d1205
ZW
15660 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15661 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15662 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15663 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15664 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15665 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15666};
b99bd4ef 15667
c19d1205
ZW
15668/* Table of all explicit relocation names. */
15669#ifdef OBJ_ELF
15670static struct reloc_entry reloc_names[] =
15671{
15672 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15673 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15674 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15675 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15676 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15677 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15678 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15679 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15680 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15681 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15682 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15683};
15684#endif
b99bd4ef 15685
c19d1205
ZW
15686/* Table of all conditional affixes. 0xF is not defined as a condition code. */
15687static const struct asm_cond conds[] =
15688{
15689 {"eq", 0x0},
15690 {"ne", 0x1},
15691 {"cs", 0x2}, {"hs", 0x2},
15692 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15693 {"mi", 0x4},
15694 {"pl", 0x5},
15695 {"vs", 0x6},
15696 {"vc", 0x7},
15697 {"hi", 0x8},
15698 {"ls", 0x9},
15699 {"ge", 0xa},
15700 {"lt", 0xb},
15701 {"gt", 0xc},
15702 {"le", 0xd},
15703 {"al", 0xe}
15704};
bfae80f2 15705
62b3e311
PB
15706static struct asm_barrier_opt barrier_opt_names[] =
15707{
15708 { "sy", 0xf },
15709 { "un", 0x7 },
15710 { "st", 0xe },
15711 { "unst", 0x6 }
15712};
15713
c19d1205
ZW
15714/* Table of ARM-format instructions. */
15715
15716/* Macros for gluing together operand strings. N.B. In all cases
15717 other than OPS0, the trailing OP_stop comes from default
15718 zero-initialization of the unspecified elements of the array. */
15719#define OPS0() { OP_stop, }
15720#define OPS1(a) { OP_##a, }
15721#define OPS2(a,b) { OP_##a,OP_##b, }
15722#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15723#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15724#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15725#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15726
15727/* These macros abstract out the exact format of the mnemonic table and
15728 save some repeated characters. */
15729
15730/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15731#define TxCE(mnem, op, top, nops, ops, ae, te) \
15732 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 15733 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15734
15735/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15736 a T_MNEM_xyz enumerator. */
15737#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15738 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 15739#define tCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15740 TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15741
15742/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15743 infix after the third character. */
15744#define TxC3(mnem, op, top, nops, ops, ae, te) \
15745 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 15746 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
15747#define TxC3w(mnem, op, top, nops, ops, ae, te) \
15748 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15749 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 15750#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15751 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 15752#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15753 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 15754#define tC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15755 TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e 15756#define tC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15757 TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15758
15759/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15760 appear in the condition table. */
15761#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
e07e6e58 15762 { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
1887dd22 15763 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15764
15765#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
15766 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
15767 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
15768 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
15769 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
15770 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
15771 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
15772 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
15773 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
15774 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
15775 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
15776 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
15777 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
15778 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
15779 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
15780 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
15781 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
15782 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
15783 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
15784 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
15785
15786#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
15787 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
15788#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15789 TxCM (m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15790
15791/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
15792 field is still 0xE. Many of the Thumb variants can be executed
15793 conditionally, so this is checked separately. */
c19d1205
ZW
15794#define TUE(mnem, op, top, nops, ops, ae, te) \
15795 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15796 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15797
15798/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15799 condition code field. */
15800#define TUF(mnem, op, top, nops, ops, ae, te) \
15801 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15802 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15803
15804/* ARM-only variants of all the above. */
6a86118a
NC
15805#define CE(mnem, op, nops, ops, ae) \
15806 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15807
15808#define C3(mnem, op, nops, ops, ae) \
15809 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15810
e3cb604e
PB
15811/* Legacy mnemonics that always have conditional infix after the third
15812 character. */
15813#define CL(mnem, op, nops, ops, ae) \
15814 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15815 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15816
8f06b2d8
PB
15817/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15818#define cCE(mnem, op, nops, ops, ae) \
15819 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15820
e3cb604e
PB
15821/* Legacy coprocessor instructions where conditional infix and conditional
15822 suffix are ambiguous. For consistency this includes all FPA instructions,
15823 not just the potentially ambiguous ones. */
15824#define cCL(mnem, op, nops, ops, ae) \
15825 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15826 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15827
15828/* Coprocessor, takes either a suffix or a position-3 infix
15829 (for an FPA corner case). */
15830#define C3E(mnem, op, nops, ops, ae) \
15831 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15832 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 15833
6a86118a
NC
15834#define xCM_(m1, m2, m3, op, nops, ops, ae) \
15835 { #m1 #m2 #m3, OPS##nops ops, \
e07e6e58 15836 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
6a86118a
NC
15837 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15838
15839#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
15840 xCM_ (m1, , m2, op, nops, ops, ae), \
15841 xCM_ (m1, eq, m2, op, nops, ops, ae), \
15842 xCM_ (m1, ne, m2, op, nops, ops, ae), \
15843 xCM_ (m1, cs, m2, op, nops, ops, ae), \
15844 xCM_ (m1, hs, m2, op, nops, ops, ae), \
15845 xCM_ (m1, cc, m2, op, nops, ops, ae), \
15846 xCM_ (m1, ul, m2, op, nops, ops, ae), \
15847 xCM_ (m1, lo, m2, op, nops, ops, ae), \
15848 xCM_ (m1, mi, m2, op, nops, ops, ae), \
15849 xCM_ (m1, pl, m2, op, nops, ops, ae), \
15850 xCM_ (m1, vs, m2, op, nops, ops, ae), \
15851 xCM_ (m1, vc, m2, op, nops, ops, ae), \
15852 xCM_ (m1, hi, m2, op, nops, ops, ae), \
15853 xCM_ (m1, ls, m2, op, nops, ops, ae), \
15854 xCM_ (m1, ge, m2, op, nops, ops, ae), \
15855 xCM_ (m1, lt, m2, op, nops, ops, ae), \
15856 xCM_ (m1, gt, m2, op, nops, ops, ae), \
15857 xCM_ (m1, le, m2, op, nops, ops, ae), \
15858 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
15859
15860#define UE(mnem, op, nops, ops, ae) \
15861 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15862
15863#define UF(mnem, op, nops, ops, ae) \
15864 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15865
5287ad62
JB
15866/* Neon data-processing. ARM versions are unconditional with cond=0xf.
15867 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15868 use the same encoding function for each. */
15869#define NUF(mnem, op, nops, ops, enc) \
15870 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15871 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15872
15873/* Neon data processing, version which indirects through neon_enc_tab for
15874 the various overloaded versions of opcodes. */
15875#define nUF(mnem, op, nops, ops, enc) \
15876 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15877 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15878
15879/* Neon insn with conditional suffix for the ARM version, non-overloaded
15880 version. */
037e8744
JB
15881#define NCE_tag(mnem, op, nops, ops, enc, tag) \
15882 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
15883 THUMB_VARIANT, do_##enc, do_##enc }
15884
037e8744 15885#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 15886 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
15887
15888#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 15889 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 15890
5287ad62 15891/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
15892#define nCE_tag(mnem, op, nops, ops, enc, tag) \
15893 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
15894 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15895
037e8744 15896#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 15897 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
15898
15899#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 15900 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 15901
c19d1205
ZW
15902#define do_0 0
15903
15904/* Thumb-only, unconditional. */
e07e6e58 15905#define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
c19d1205 15906
c19d1205 15907static const struct asm_opcode insns[] =
bfae80f2 15908{
e74cfd16
PB
15909#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15910#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15911 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15912 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15913 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15914 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15915 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15916 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
15917 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15918 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
15919 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15920 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15921 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15922 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15923 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15924 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15925 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15926 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15927
15928 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15929 for setting PSR flag bits. They are obsolete in V6 and do not
15930 have Thumb equivalents. */
15931 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15932 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15933 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 15934 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 15935 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 15936 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 15937 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15938 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15939 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
15940
15941 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15942 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15943 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15944 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15945
4962c51a
MS
15946 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15947 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15948 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15949 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 15950
f5208ef2 15951 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15952 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15953 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 15954 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15955 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15956 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15957
15958 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 15959 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 15960 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 15961 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 15962
c19d1205 15963 /* Pseudo ops. */
e9f89963 15964 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
15965 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15966 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
15967
15968 /* Thumb-compatibility pseudo ops. */
15969 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15970 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15971 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15972 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15973 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 15974 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
15975 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15976 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15977 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15978 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15979 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15980 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15981
16a4cf17
PB
15982 /* These may simplify to neg. */
15983 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15984 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15985
c19d1205 15986#undef THUMB_VARIANT
e74cfd16 15987#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 15988 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
15989
15990 /* V1 instructions with no Thumb analogue prior to V6T2. */
15991#undef THUMB_VARIANT
e74cfd16 15992#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 15993 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15994 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15995 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
15996
15997 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 15998 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 15999 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 16000 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 16001
9c3c69f2
PB
16002 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16003 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16004
9c3c69f2
PB
16005 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16006 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16007
16008 /* V1 instructions with no Thumb analogue at all. */
16009 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
16010 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16011
16012 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16013 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16014 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16015 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16016 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16017 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16018 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16019 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16020
16021#undef ARM_VARIANT
e74cfd16 16022#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 16023#undef THUMB_VARIANT
e74cfd16 16024#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
16025 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16026 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16027
16028#undef THUMB_VARIANT
e74cfd16 16029#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16030 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16031 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16032
16033 /* Generic coprocessor instructions. */
16034 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
16035 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16036 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16037 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16038 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
16039 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16040 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16041
16042#undef ARM_VARIANT
e74cfd16 16043#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
16044 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16045 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16046
16047#undef ARM_VARIANT
e74cfd16 16048#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
16049#undef THUMB_VARIANT
16050#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
16051 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16052 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
16053
16054#undef ARM_VARIANT
e74cfd16 16055#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
16056#undef THUMB_VARIANT
16057#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16058 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16059 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16060 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16061 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16062 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16063 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16064 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16065 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16066
16067#undef ARM_VARIANT
e74cfd16 16068#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 16069#undef THUMB_VARIANT
e74cfd16 16070#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
16071 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16072 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16073 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16074 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16075 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16076 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
16077
16078#undef ARM_VARIANT
e74cfd16 16079#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
16080 /* ARM Architecture 4T. */
16081 /* Note: bx (and blx) are required on V5, even if the processor does
16082 not support Thumb. */
16083 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
16084
16085#undef ARM_VARIANT
e74cfd16 16086#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 16087#undef THUMB_VARIANT
e74cfd16 16088#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
16089 /* Note: blx has 2 variants; the .value coded here is for
16090 BLX(2). Only this variant has conditional execution. */
16091 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16092 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16093
16094#undef THUMB_VARIANT
e74cfd16 16095#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 16096 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
16097 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16098 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16099 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16100 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
16101 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16102 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16103 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16104
16105#undef ARM_VARIANT
e74cfd16 16106#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
16107 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16108 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16109 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16110 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16111
16112 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16113 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16114
16115 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16116 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16117 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16118 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16119
16120 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16121 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16122 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16123 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16124
16125 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16126 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16127
087b80de
JM
16128 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16129 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16130 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16131 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205
ZW
16132
16133#undef ARM_VARIANT
e74cfd16 16134#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 16135 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
16136 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16137 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
16138
16139 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16140 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16141
16142#undef ARM_VARIANT
e74cfd16 16143#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
16144 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16145
16146#undef ARM_VARIANT
e74cfd16 16147#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 16148#undef THUMB_VARIANT
e74cfd16 16149#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
16150 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16151 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16152 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16153 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16154 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16155 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16156 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16157 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16158 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16159 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
16160
16161#undef THUMB_VARIANT
e74cfd16 16162#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 16163 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 16164 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
16165 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16166 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
16167
16168 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16169 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16170
16171/* ARM V6 not included in V7M (eg. integer SIMD). */
16172#undef THUMB_VARIANT
16173#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 16174 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
16175 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16176 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16177 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16178 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16179 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16180 /* Old name for QASX. */
c19d1205 16181 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16182 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16183 /* Old name for QSAX. */
16184 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16185 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16186 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16187 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16188 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16189 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16190 /* Old name for SASX. */
c19d1205
ZW
16191 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16192 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16193 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16194 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16195 /* Old name for SHASX. */
c19d1205 16196 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16197 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16198 /* Old name for SHSAX. */
16199 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16200 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16201 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16202 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16203 /* Old name for SSAX. */
16204 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16205 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16206 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16207 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16208 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16209 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16210 /* Old name for UASX. */
c19d1205
ZW
16211 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16212 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16213 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16214 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16215 /* Old name for UHASX. */
c19d1205 16216 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16217 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16218 /* Old name for UHSAX. */
16219 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16220 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16221 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16222 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16223 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16224 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16225 /* Old name for UQASX. */
c19d1205 16226 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16227 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16228 /* Old name for UQSAX. */
16229 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16230 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16231 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205 16232 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16233 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16234 /* Old name for USAX. */
c19d1205 16235 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16236 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16237 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
16238 UF(rfeib, 9900a00, 1, (RRw), rfe),
16239 UF(rfeda, 8100a00, 1, (RRw), rfe),
16240 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
16241 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
16242 UF(rfefa, 9900a00, 1, (RRw), rfe),
16243 UF(rfeea, 8100a00, 1, (RRw), rfe),
16244 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
16245 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16246 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16247 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16248 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16249 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16250 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16251 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16252 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 16253 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16254 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16255 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16256 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16257 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16258 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16259 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16260 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16261 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16262 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16263 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16264 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16265 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16266 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16267 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16268 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16269 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16270 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16271 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
16272 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16273 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16274 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16275 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 16276 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
16277 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16278 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16279 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
16280 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16281
16282#undef ARM_VARIANT
e74cfd16 16283#define ARM_VARIANT &arm_ext_v6k
c19d1205 16284#undef THUMB_VARIANT
e74cfd16 16285#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
16286 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
16287 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
16288 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
16289 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
16290
ebdca51a
PB
16291#undef THUMB_VARIANT
16292#define THUMB_VARIANT &arm_ext_v6_notm
16293 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
16294 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
16295
c19d1205 16296#undef THUMB_VARIANT
e74cfd16 16297#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16298 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16299 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
16300 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16301 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
16302 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16303
16304#undef ARM_VARIANT
e74cfd16 16305#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 16306 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
16307
16308#undef ARM_VARIANT
e74cfd16 16309#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
16310 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16311 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16312 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16313 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16314
16315 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
16316 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16317 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 16318 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
16319
16320 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16321 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16322 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16323 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16324
25fe350b
MS
16325 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
16326 UT(cbz, b100, 2, (RR, EXP), t_cbz),
e07e6e58
NC
16327 /* ARM does not really have an IT instruction, so always allow it. The opcode
16328 is copied from Thumb in order to allow warnings
16329 in -mimplicit-it=[never | arm] modes. */
f91e006c
PB
16330#undef ARM_VARIANT
16331#define ARM_VARIANT &arm_ext_v1
e07e6e58
NC
16332 TUE(it, bf08, bf08, 1, (COND), it, t_it),
16333 TUE(itt, bf0c, bf0c, 1, (COND), it, t_it),
16334 TUE(ite, bf04, bf04, 1, (COND), it, t_it),
16335 TUE(ittt, bf0e, bf0e, 1, (COND), it, t_it),
16336 TUE(itet, bf06, bf06, 1, (COND), it, t_it),
16337 TUE(itte, bf0a, bf0a, 1, (COND), it, t_it),
16338 TUE(itee, bf02, bf02, 1, (COND), it, t_it),
16339 TUE(itttt, bf0f, bf0f, 1, (COND), it, t_it),
16340 TUE(itett, bf07, bf07, 1, (COND), it, t_it),
16341 TUE(ittet, bf0b, bf0b, 1, (COND), it, t_it),
16342 TUE(iteet, bf03, bf03, 1, (COND), it, t_it),
16343 TUE(ittte, bf0d, bf0d, 1, (COND), it, t_it),
16344 TUE(itete, bf05, bf05, 1, (COND), it, t_it),
16345 TUE(ittee, bf09, bf09, 1, (COND), it, t_it),
16346 TUE(iteee, bf01, bf01, 1, (COND), it, t_it),
1c444d06
JM
16347 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
16348 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16349 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16350
92e90b6e
PB
16351 /* Thumb2 only instructions. */
16352#undef ARM_VARIANT
e74cfd16 16353#define ARM_VARIANT NULL
92e90b6e
PB
16354
16355 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16356 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
1c444d06
JM
16357 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16358 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
92e90b6e
PB
16359 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
16360 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
16361
62b3e311
PB
16362 /* Thumb-2 hardware division instructions (R and M profiles only). */
16363#undef THUMB_VARIANT
16364#define THUMB_VARIANT &arm_ext_div
16365 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16366 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
16367
7e806470
PB
16368 /* ARM V6M/V7 instructions. */
16369#undef ARM_VARIANT
16370#define ARM_VARIANT &arm_ext_barrier
16371#undef THUMB_VARIANT
16372#define THUMB_VARIANT &arm_ext_barrier
16373 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16374 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16375 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
16376
62b3e311
PB
16377 /* ARM V7 instructions. */
16378#undef ARM_VARIANT
16379#define ARM_VARIANT &arm_ext_v7
16380#undef THUMB_VARIANT
16381#define THUMB_VARIANT &arm_ext_v7
16382 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
16383 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16384
c19d1205 16385#undef ARM_VARIANT
e74cfd16 16386#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
16387 cCE(wfs, e200110, 1, (RR), rd),
16388 cCE(rfs, e300110, 1, (RR), rd),
16389 cCE(wfc, e400110, 1, (RR), rd),
16390 cCE(rfc, e500110, 1, (RR), rd),
16391
4962c51a
MS
16392 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16393 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16394 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16395 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 16396
4962c51a
MS
16397 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16398 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16399 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16400 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
16401
16402 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
16403 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
16404 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
16405 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
16406 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
16407 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
16408 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
16409 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
16410 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
16411 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
16412 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
16413 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
16414
16415 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
16416 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
16417 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
16418 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
16419 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
16420 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
16421 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
16422 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
16423 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
16424 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
16425 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
16426 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
16427
16428 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
16429 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
16430 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
16431 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
16432 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
16433 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
16434 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
16435 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
16436 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
16437 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
16438 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
16439 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
16440
16441 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
16442 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
16443 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
16444 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
16445 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
16446 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
16447 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
16448 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
16449 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
16450 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
16451 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
16452 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
16453
16454 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
16455 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
16456 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
16457 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
16458 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
16459 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
16460 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
16461 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
16462 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
16463 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
16464 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
16465 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
16466
16467 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
16468 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
16469 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
16470 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
16471 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
16472 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
16473 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
16474 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
16475 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
16476 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
16477 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
16478 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
16479
16480 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
16481 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
16482 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
16483 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
16484 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
16485 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
16486 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
16487 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
16488 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
16489 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
16490 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
16491 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
16492
16493 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
16494 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
16495 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
16496 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
16497 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
16498 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
16499 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
16500 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
16501 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
16502 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
16503 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
16504 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
16505
16506 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
16507 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16508 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16509 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16510 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16511 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16512 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16513 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16514 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16515 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16516 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16517 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16518
16519 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16520 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16521 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16522 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16523 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16524 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16525 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16526 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16527 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16528 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16529 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16530 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16531
16532 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16533 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16534 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16535 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16536 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16537 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16538 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16539 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16540 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16541 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16542 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16543 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16544
16545 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16546 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16547 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16548 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16549 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16550 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16551 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16552 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16553 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16554 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16555 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16556 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16557
16558 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16559 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16560 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16561 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16562 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16563 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16564 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16565 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16566 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16567 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16568 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16569 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16570
16571 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16572 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16573 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16574 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16575 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16576 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16577 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16578 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16579 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16580 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16581 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16582 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16583
16584 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16585 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16586 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16587 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16588 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16589 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16590 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16591 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16592 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16593 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16594 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16595 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16596
16597 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16598 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16599 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16600 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16601 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16602 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16603 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16604 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16605 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16606 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16607 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16608 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16609
16610 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16611 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16612 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16613 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16614 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16615 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16616 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16617 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16618 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16619 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16620 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16621 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16622
16623 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16624 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16625 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16626 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16627 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16628 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16629 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16630 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16631 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16632 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16633 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16634 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16635
16636 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16637 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16638 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16639 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16640 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16641 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16642 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16643 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16644 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16645 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16646 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16647 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16648
16649 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16650 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16651 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16652 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16653 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16654 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16655 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16656 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16657 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16658 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16659 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16660 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16661
16662 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16663 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16664 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16665 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16666 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16667 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16668 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16669 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16670 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16671 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16672 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16673 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16674
16675 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16676 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16677 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16678 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16679 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16680 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16681 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16682 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16683 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16684 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16685 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16686 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16687
16688 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16689 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16690 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16691 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16692 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16693 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16694 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16695 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16696 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16697 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16698 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16699 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16700
16701 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16702 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16703 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16704 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16705 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16706 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16707 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16708 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16709 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16710 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16711 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16712 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16713
16714 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16715 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16716 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16717 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16718 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16719 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16720 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16721 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16722 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16723 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16724 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16725 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16726
16727 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16728 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16729 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16730 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16731 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16732 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16733 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16734 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16735 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16736 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16737 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16738 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16739
16740 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16741 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16742 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16743 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16744 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16745 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16746 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16747 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16748 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16749 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16750 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16751 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16752
16753 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16754 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16755 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16756 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16757 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16758 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16759 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16760 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16761 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16762 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16763 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16764 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16765
16766 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16767 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16768 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16769 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16770 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16771 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16772 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16773 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16774 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16775 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16776 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16777 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
16778
16779 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 16780 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 16781 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
16782 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16783
e3cb604e
PB
16784 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16785 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16786 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16787 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16788 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16789 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16790 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16791 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16792 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16793 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16794 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16795 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 16796
c19d1205
ZW
16797 /* The implementation of the FIX instruction is broken on some
16798 assemblers, in that it accepts a precision specifier as well as a
16799 rounding specifier, despite the fact that this is meaningless.
16800 To be more compatible, we accept it as well, though of course it
16801 does not set any bits. */
8f06b2d8 16802 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
16803 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16804 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16805 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16806 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16807 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16808 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16809 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16810 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16811 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16812 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16813 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16814 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 16815
c19d1205
ZW
16816 /* Instructions that were new with the real FPA, call them V2. */
16817#undef ARM_VARIANT
e74cfd16 16818#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 16819 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16820 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16821 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 16822 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16823 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16824 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
16825
16826#undef ARM_VARIANT
e74cfd16 16827#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 16828 /* Moves and type conversions. */
8f06b2d8
PB
16829 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16830 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16831 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16832 cCE(fmstat, ef1fa10, 0, (), noargs),
16833 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16834 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16835 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16836 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16837 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16838 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16839 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16840 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
16841
16842 /* Memory operations. */
4962c51a
MS
16843 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16844 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
16845 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16846 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16847 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16848 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16849 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16850 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16851 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16852 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16853 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16854 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16855 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16856 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16857 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16858 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16859 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16860 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 16861
c19d1205 16862 /* Monadic operations. */
8f06b2d8
PB
16863 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16864 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16865 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
16866
16867 /* Dyadic operations. */
8f06b2d8
PB
16868 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16869 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16870 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16871 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16872 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16873 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16874 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16875 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16876 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 16877
c19d1205 16878 /* Comparisons. */
8f06b2d8
PB
16879 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16880 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16881 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16882 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 16883
c19d1205 16884#undef ARM_VARIANT
e74cfd16 16885#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 16886 /* Moves and type conversions. */
5287ad62 16887 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
16888 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16889 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
16890 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16891 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16892 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16893 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
16894 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16895 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16896 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16897 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16898 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16899 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
16900
16901 /* Memory operations. */
4962c51a
MS
16902 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16903 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
16904 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16905 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16906 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16907 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16908 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16909 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16910 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16911 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 16912
c19d1205 16913 /* Monadic operations. */
5287ad62
JB
16914 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16915 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16916 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
16917
16918 /* Dyadic operations. */
5287ad62
JB
16919 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16920 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16921 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16922 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16923 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16924 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16925 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16926 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16927 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 16928
c19d1205 16929 /* Comparisons. */
5287ad62
JB
16930 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16931 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16932 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16933 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
16934
16935#undef ARM_VARIANT
e74cfd16 16936#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
16937 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16938 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
16939 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16940 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16941
037e8744
JB
16942/* Instructions which may belong to either the Neon or VFP instruction sets.
16943 Individual encoder functions perform additional architecture checks. */
16944#undef ARM_VARIANT
16945#define ARM_VARIANT &fpu_vfp_ext_v1xd
16946#undef THUMB_VARIANT
16947#define THUMB_VARIANT &fpu_vfp_ext_v1xd
16948 /* These mnemonics are unique to VFP. */
16949 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16950 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16951 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16952 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16953 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16954 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16955 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16956 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16957 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16958 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16959
16960 /* Mnemonics shared by Neon and VFP. */
16961 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16962 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16963 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16964
16965 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16966 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16967
16968 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16969 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16970
16971 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16972 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16973 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16974 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16975 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16976 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
16977 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16978 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
16979
16980 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
8e79c3df
CM
16981 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16982 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 16983
037e8744
JB
16984
16985 /* NOTE: All VMOV encoding is special-cased! */
16986 NCE(vmov, 0, 1, (VMOV), neon_mov),
16987 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16988
5287ad62
JB
16989#undef THUMB_VARIANT
16990#define THUMB_VARIANT &fpu_neon_ext_v1
16991#undef ARM_VARIANT
16992#define ARM_VARIANT &fpu_neon_ext_v1
16993 /* Data processing with three registers of the same length. */
16994 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
16995 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
16996 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
16997 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
16998 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
16999 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17000 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17001 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17002 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17003 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17004 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17005 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17006 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17007 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17008 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17009 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17010 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17011 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17012 /* If not immediate, fall back to neon_dyadic_i64_su.
17013 shl_imm should accept I8 I16 I32 I64,
17014 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17015 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17016 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17017 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17018 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17019 /* Logic ops, types optional & ignored. */
17020 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
17021 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
17022 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
17023 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
17024 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
17025 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
17026 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
17027 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
17028 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17029 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17030 /* Bitfield ops, untyped. */
17031 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17032 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17033 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17034 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17035 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17036 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17037 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17038 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17039 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17040 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17041 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17042 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17043 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17044 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17045 back to neon_dyadic_if_su. */
17046 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17047 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17048 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17049 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17050 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17051 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17052 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17053 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17054 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
17055 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17056 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17057 /* As above, D registers only. */
17058 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17059 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17060 /* Int and float variants, signedness unimportant. */
5287ad62 17061 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
17062 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17063 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17064 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 17065 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17066 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17067 /* vtst takes sizes 8, 16, 32. */
17068 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17069 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17070 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 17071 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
17072 /* VQD{R}MULH takes S16 S32. */
17073 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17074 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17075 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17076 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17077 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17078 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17079 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17080 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17081 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17082 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17083 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17084 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17085 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17086 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17087 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17088 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17089
17090 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17091 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17092 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17093
17094 /* Data processing with two registers and a shift amount. */
17095 /* Right shifts, and variants with rounding.
17096 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17097 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17098 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17099 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17100 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17101 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17102 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17103 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17104 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17105 /* Shift and insert. Sizes accepted 8 16 32 64. */
17106 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17107 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17108 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17109 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17110 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17111 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17112 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17113 /* Right shift immediate, saturating & narrowing, with rounding variants.
17114 Types accepted S16 S32 S64 U16 U32 U64. */
17115 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17116 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17117 /* As above, unsigned. Types accepted S16 S32 S64. */
17118 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17119 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17120 /* Right shift narrowing. Types accepted I16 I32 I64. */
17121 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17122 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17123 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17124 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
17125 /* CVT with optional immediate for fixed-point variant. */
037e8744 17126 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17127
5287ad62
JB
17128 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
17129 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
17130
17131 /* Data processing, three registers of different lengths. */
17132 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17133 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17134 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17135 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17136 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17137 /* If not scalar, fall back to neon_dyadic_long.
17138 Vector types as above, scalar types S16 S32 U16 U32. */
17139 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17140 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17141 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17142 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17143 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17144 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17145 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17146 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17147 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17148 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17149 /* Saturating doubling multiplies. Types S16 S32. */
17150 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17151 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17152 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17153 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17154 S16 S32 U16 U32. */
17155 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17156
17157 /* Extract. Size 8. */
3b8d421e
PB
17158 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17159 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17160
17161 /* Two registers, miscellaneous. */
17162 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17163 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17164 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17165 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17166 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17167 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17168 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17169 /* Vector replicate. Sizes 8 16 32. */
17170 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17171 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
17172 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17173 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17174 /* VMOVN. Types I16 I32 I64. */
17175 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
17176 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17177 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
17178 /* VQMOVUN. Types S16 S32 S64. */
17179 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
17180 /* VZIP / VUZP. Sizes 8 16 32. */
17181 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17182 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17183 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17184 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17185 /* VQABS / VQNEG. Types S8 S16 S32. */
17186 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17187 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17188 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17189 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17190 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17191 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17192 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17193 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17194 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17195 /* Reciprocal estimates. Types U32 F32. */
17196 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17197 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17198 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17199 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17200 /* VCLS. Types S8 S16 S32. */
17201 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17202 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17203 /* VCLZ. Types I8 I16 I32. */
17204 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17205 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17206 /* VCNT. Size 8. */
17207 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17208 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17209 /* Two address, untyped. */
17210 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17211 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17212 /* VTRN. Sizes 8 16 32. */
17213 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
17214 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
17215
17216 /* Table lookup. Size 8. */
17217 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17218 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17219
b7fc2769
JB
17220#undef THUMB_VARIANT
17221#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
17222#undef ARM_VARIANT
17223#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
17224 /* Neon element/structure load/store. */
17225 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17226 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17227 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17228 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17229 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17230 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17231 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17232 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17233
17234#undef THUMB_VARIANT
17235#define THUMB_VARIANT &fpu_vfp_ext_v3
17236#undef ARM_VARIANT
17237#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
17238 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
17239 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
17240 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17241 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17242 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17243 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17244 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17245 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17246 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17247 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17248 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17249 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17250 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17251 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17252 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17253 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17254 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17255 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17256
5287ad62 17257#undef THUMB_VARIANT
c19d1205 17258#undef ARM_VARIANT
e74cfd16 17259#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
17260 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17261 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17262 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17263 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17264 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17265 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17266 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17267 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
17268
17269#undef ARM_VARIANT
e74cfd16 17270#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
17271 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
17272 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
17273 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
17274 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
17275 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
17276 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
17277 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
17278 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
17279 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
17280 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17281 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17282 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17283 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17284 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17285 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17286 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17287 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17288 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 17289 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
17290 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17291 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17292 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17293 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17294 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17295 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17296 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17297 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
17298 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
17299 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 17300 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
17301 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17302 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
17303 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
17304 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
17305 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
17306 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
17307 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
17308 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17309 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17310 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17311 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17312 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17313 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17314 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17315 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17316 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17317 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17318 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17319 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17320 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17321 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17322 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17323 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17324 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17325 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17326 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17327 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17328 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17329 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17330 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17331 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17332 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17333 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17334 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17335 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17336 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17337 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17338 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17339 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17340 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17341 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17342 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17343 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17344 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17345 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17346 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17347 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17348 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17349 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17350 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17351 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17352 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17353 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17354 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17355 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17356 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17357 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17358 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17359 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17360 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17361 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17362 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17363 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17364 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17365 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17366 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17367 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17368 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17369 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17370 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 17371 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17372 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17373 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17374 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17375 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
17376 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17377 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17378 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17379 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17380 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17381 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 17382 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17383 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17384 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17385 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17386 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17387 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17388 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17389 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17390 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17391 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17392 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17393 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17394 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17395 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17396 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17397 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17398 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
17399 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17400 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17401 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17402 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17403 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17404 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17405 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17406 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17407 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17408 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17409 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17410 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17411 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17412 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17413 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
17414 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
17415 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
17416 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
17417 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
17418 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
17419 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17420 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17421 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17422 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
17423 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
17424 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
17425 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
17426 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
17427 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
17428 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17429 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17430 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17431 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17432 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 17433
2d447fca
JM
17434#undef ARM_VARIANT
17435#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
17436 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
17437 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
17438 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
17439 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
17440 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
17441 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
17442 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17443 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17444 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17445 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17446 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17447 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17448 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17449 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17450 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17451 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17452 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17453 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17454 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17455 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17456 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
17457 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17458 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17459 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17460 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17461 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17462 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17463 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17464 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17465 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17466 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17467 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17468 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17469 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17470 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17471 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17472 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17473 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17474 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17475 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17476 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17477 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17478 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17479 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17480 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17481 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17482 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17483 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17484 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17485 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17486 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17487 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17488 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17489 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17490 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17491 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17492 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17493
c19d1205 17494#undef ARM_VARIANT
e74cfd16 17495#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
17496 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17497 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17498 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17499 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17500 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17501 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17502 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17503 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
17504 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
17505 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
17506 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
17507 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17508 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17509 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17510 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17511 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17512 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17513 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17514 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17515 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17516 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17517 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17518 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17519 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17520 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17521 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17522 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17523 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17524 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17525 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17526 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17527 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17528 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17529 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17530 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17531 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17532 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17533 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17534 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17535 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17536 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17537 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17538 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17539 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17540 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17541 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17542 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17543 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17544 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17545 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17546 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17547 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17548 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17549 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17550 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17551 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17552 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17553 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17554 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17555 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17556 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17557 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17558 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17559 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17560 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17561 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17562 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17563 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17564 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17565 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17566 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17567 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17568 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17569 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17570 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17571 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
17572};
17573#undef ARM_VARIANT
17574#undef THUMB_VARIANT
17575#undef TCE
17576#undef TCM
17577#undef TUE
17578#undef TUF
17579#undef TCC
8f06b2d8 17580#undef cCE
e3cb604e
PB
17581#undef cCL
17582#undef C3E
c19d1205
ZW
17583#undef CE
17584#undef CM
17585#undef UE
17586#undef UF
17587#undef UT
5287ad62
JB
17588#undef NUF
17589#undef nUF
17590#undef NCE
17591#undef nCE
c19d1205
ZW
17592#undef OPS0
17593#undef OPS1
17594#undef OPS2
17595#undef OPS3
17596#undef OPS4
17597#undef OPS5
17598#undef OPS6
17599#undef do_0
17600\f
17601/* MD interface: bits in the object file. */
bfae80f2 17602
c19d1205
ZW
17603/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17604 for use in the a.out file, and stores them in the array pointed to by buf.
17605 This knows about the endian-ness of the target machine and does
17606 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17607 2 (short) and 4 (long) Floating numbers are put out as a series of
17608 LITTLENUMS (shorts, here at least). */
b99bd4ef 17609
c19d1205
ZW
17610void
17611md_number_to_chars (char * buf, valueT val, int n)
17612{
17613 if (target_big_endian)
17614 number_to_chars_bigendian (buf, val, n);
17615 else
17616 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
17617}
17618
c19d1205
ZW
17619static valueT
17620md_chars_to_number (char * buf, int n)
bfae80f2 17621{
c19d1205
ZW
17622 valueT result = 0;
17623 unsigned char * where = (unsigned char *) buf;
bfae80f2 17624
c19d1205 17625 if (target_big_endian)
b99bd4ef 17626 {
c19d1205
ZW
17627 while (n--)
17628 {
17629 result <<= 8;
17630 result |= (*where++ & 255);
17631 }
b99bd4ef 17632 }
c19d1205 17633 else
b99bd4ef 17634 {
c19d1205
ZW
17635 while (n--)
17636 {
17637 result <<= 8;
17638 result |= (where[n] & 255);
17639 }
bfae80f2 17640 }
b99bd4ef 17641
c19d1205 17642 return result;
bfae80f2 17643}
b99bd4ef 17644
c19d1205 17645/* MD interface: Sections. */
b99bd4ef 17646
0110f2b8
PB
17647/* Estimate the size of a frag before relaxing. Assume everything fits in
17648 2 bytes. */
17649
c19d1205 17650int
0110f2b8 17651md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
17652 segT segtype ATTRIBUTE_UNUSED)
17653{
0110f2b8
PB
17654 fragp->fr_var = 2;
17655 return 2;
17656}
17657
17658/* Convert a machine dependent frag. */
17659
17660void
17661md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17662{
17663 unsigned long insn;
17664 unsigned long old_op;
17665 char *buf;
17666 expressionS exp;
17667 fixS *fixp;
17668 int reloc_type;
17669 int pc_rel;
17670 int opcode;
17671
17672 buf = fragp->fr_literal + fragp->fr_fix;
17673
17674 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
17675 if (fragp->fr_symbol)
17676 {
0110f2b8
PB
17677 exp.X_op = O_symbol;
17678 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
17679 }
17680 else
17681 {
0110f2b8 17682 exp.X_op = O_constant;
5f4273c7 17683 }
0110f2b8
PB
17684 exp.X_add_number = fragp->fr_offset;
17685 opcode = fragp->fr_subtype;
17686 switch (opcode)
17687 {
17688 case T_MNEM_ldr_pc:
17689 case T_MNEM_ldr_pc2:
17690 case T_MNEM_ldr_sp:
17691 case T_MNEM_str_sp:
17692 case T_MNEM_ldr:
17693 case T_MNEM_ldrb:
17694 case T_MNEM_ldrh:
17695 case T_MNEM_str:
17696 case T_MNEM_strb:
17697 case T_MNEM_strh:
17698 if (fragp->fr_var == 4)
17699 {
5f4273c7 17700 insn = THUMB_OP32 (opcode);
0110f2b8
PB
17701 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17702 {
17703 insn |= (old_op & 0x700) << 4;
17704 }
17705 else
17706 {
17707 insn |= (old_op & 7) << 12;
17708 insn |= (old_op & 0x38) << 13;
17709 }
17710 insn |= 0x00000c00;
17711 put_thumb32_insn (buf, insn);
17712 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17713 }
17714 else
17715 {
17716 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17717 }
17718 pc_rel = (opcode == T_MNEM_ldr_pc2);
17719 break;
17720 case T_MNEM_adr:
17721 if (fragp->fr_var == 4)
17722 {
17723 insn = THUMB_OP32 (opcode);
17724 insn |= (old_op & 0xf0) << 4;
17725 put_thumb32_insn (buf, insn);
17726 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17727 }
17728 else
17729 {
17730 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17731 exp.X_add_number -= 4;
17732 }
17733 pc_rel = 1;
17734 break;
17735 case T_MNEM_mov:
17736 case T_MNEM_movs:
17737 case T_MNEM_cmp:
17738 case T_MNEM_cmn:
17739 if (fragp->fr_var == 4)
17740 {
17741 int r0off = (opcode == T_MNEM_mov
17742 || opcode == T_MNEM_movs) ? 0 : 8;
17743 insn = THUMB_OP32 (opcode);
17744 insn = (insn & 0xe1ffffff) | 0x10000000;
17745 insn |= (old_op & 0x700) << r0off;
17746 put_thumb32_insn (buf, insn);
17747 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17748 }
17749 else
17750 {
17751 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17752 }
17753 pc_rel = 0;
17754 break;
17755 case T_MNEM_b:
17756 if (fragp->fr_var == 4)
17757 {
17758 insn = THUMB_OP32(opcode);
17759 put_thumb32_insn (buf, insn);
17760 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17761 }
17762 else
17763 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17764 pc_rel = 1;
17765 break;
17766 case T_MNEM_bcond:
17767 if (fragp->fr_var == 4)
17768 {
17769 insn = THUMB_OP32(opcode);
17770 insn |= (old_op & 0xf00) << 14;
17771 put_thumb32_insn (buf, insn);
17772 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17773 }
17774 else
17775 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17776 pc_rel = 1;
17777 break;
17778 case T_MNEM_add_sp:
17779 case T_MNEM_add_pc:
17780 case T_MNEM_inc_sp:
17781 case T_MNEM_dec_sp:
17782 if (fragp->fr_var == 4)
17783 {
17784 /* ??? Choose between add and addw. */
17785 insn = THUMB_OP32 (opcode);
17786 insn |= (old_op & 0xf0) << 4;
17787 put_thumb32_insn (buf, insn);
16805f35
PB
17788 if (opcode == T_MNEM_add_pc)
17789 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17790 else
17791 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
17792 }
17793 else
17794 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17795 pc_rel = 0;
17796 break;
17797
17798 case T_MNEM_addi:
17799 case T_MNEM_addis:
17800 case T_MNEM_subi:
17801 case T_MNEM_subis:
17802 if (fragp->fr_var == 4)
17803 {
17804 insn = THUMB_OP32 (opcode);
17805 insn |= (old_op & 0xf0) << 4;
17806 insn |= (old_op & 0xf) << 16;
17807 put_thumb32_insn (buf, insn);
16805f35
PB
17808 if (insn & (1 << 20))
17809 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17810 else
17811 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
17812 }
17813 else
17814 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17815 pc_rel = 0;
17816 break;
17817 default:
5f4273c7 17818 abort ();
0110f2b8
PB
17819 }
17820 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17821 reloc_type);
17822 fixp->fx_file = fragp->fr_file;
17823 fixp->fx_line = fragp->fr_line;
17824 fragp->fr_fix += fragp->fr_var;
17825}
17826
17827/* Return the size of a relaxable immediate operand instruction.
17828 SHIFT and SIZE specify the form of the allowable immediate. */
17829static int
17830relax_immediate (fragS *fragp, int size, int shift)
17831{
17832 offsetT offset;
17833 offsetT mask;
17834 offsetT low;
17835
17836 /* ??? Should be able to do better than this. */
17837 if (fragp->fr_symbol)
17838 return 4;
17839
17840 low = (1 << shift) - 1;
17841 mask = (1 << (shift + size)) - (1 << shift);
17842 offset = fragp->fr_offset;
17843 /* Force misaligned offsets to 32-bit variant. */
17844 if (offset & low)
5e77afaa 17845 return 4;
0110f2b8
PB
17846 if (offset & ~mask)
17847 return 4;
17848 return 2;
17849}
17850
5e77afaa
PB
17851/* Get the address of a symbol during relaxation. */
17852static addressT
5f4273c7 17853relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
17854{
17855 fragS *sym_frag;
17856 addressT addr;
17857 symbolS *sym;
17858
17859 sym = fragp->fr_symbol;
17860 sym_frag = symbol_get_frag (sym);
17861 know (S_GET_SEGMENT (sym) != absolute_section
17862 || sym_frag == &zero_address_frag);
17863 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17864
17865 /* If frag has yet to be reached on this pass, assume it will
17866 move by STRETCH just as we did. If this is not so, it will
17867 be because some frag between grows, and that will force
17868 another pass. */
17869
17870 if (stretch != 0
17871 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
17872 {
17873 fragS *f;
17874
17875 /* Adjust stretch for any alignment frag. Note that if have
17876 been expanding the earlier code, the symbol may be
17877 defined in what appears to be an earlier frag. FIXME:
17878 This doesn't handle the fr_subtype field, which specifies
17879 a maximum number of bytes to skip when doing an
17880 alignment. */
17881 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17882 {
17883 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17884 {
17885 if (stretch < 0)
17886 stretch = - ((- stretch)
17887 & ~ ((1 << (int) f->fr_offset) - 1));
17888 else
17889 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17890 if (stretch == 0)
17891 break;
17892 }
17893 }
17894 if (f != NULL)
17895 addr += stretch;
17896 }
5e77afaa
PB
17897
17898 return addr;
17899}
17900
0110f2b8
PB
17901/* Return the size of a relaxable adr pseudo-instruction or PC-relative
17902 load. */
17903static int
5e77afaa 17904relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
17905{
17906 addressT addr;
17907 offsetT val;
17908
17909 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17910 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17911 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17912 return 4;
17913
5f4273c7 17914 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17915 addr = fragp->fr_address + fragp->fr_fix;
17916 addr = (addr + 4) & ~3;
5e77afaa 17917 /* Force misaligned targets to 32-bit variant. */
0110f2b8 17918 if (val & 3)
5e77afaa 17919 return 4;
0110f2b8
PB
17920 val -= addr;
17921 if (val < 0 || val > 1020)
17922 return 4;
17923 return 2;
17924}
17925
17926/* Return the size of a relaxable add/sub immediate instruction. */
17927static int
17928relax_addsub (fragS *fragp, asection *sec)
17929{
17930 char *buf;
17931 int op;
17932
17933 buf = fragp->fr_literal + fragp->fr_fix;
17934 op = bfd_get_16(sec->owner, buf);
17935 if ((op & 0xf) == ((op >> 4) & 0xf))
17936 return relax_immediate (fragp, 8, 0);
17937 else
17938 return relax_immediate (fragp, 3, 0);
17939}
17940
17941
17942/* Return the size of a relaxable branch instruction. BITS is the
17943 size of the offset field in the narrow instruction. */
17944
17945static int
5e77afaa 17946relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
17947{
17948 addressT addr;
17949 offsetT val;
17950 offsetT limit;
17951
17952 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17953 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17954 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17955 return 4;
17956
267bf995
RR
17957#ifdef OBJ_ELF
17958 if (S_IS_DEFINED (fragp->fr_symbol)
17959 && ARM_IS_FUNC (fragp->fr_symbol))
17960 return 4;
17961#endif
17962
5f4273c7 17963 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17964 addr = fragp->fr_address + fragp->fr_fix + 4;
17965 val -= addr;
17966
17967 /* Offset is a signed value *2 */
17968 limit = 1 << bits;
17969 if (val >= limit || val < -limit)
17970 return 4;
17971 return 2;
17972}
17973
17974
17975/* Relax a machine dependent frag. This returns the amount by which
17976 the current size of the frag should change. */
17977
17978int
5e77afaa 17979arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
17980{
17981 int oldsize;
17982 int newsize;
17983
17984 oldsize = fragp->fr_var;
17985 switch (fragp->fr_subtype)
17986 {
17987 case T_MNEM_ldr_pc2:
5f4273c7 17988 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17989 break;
17990 case T_MNEM_ldr_pc:
17991 case T_MNEM_ldr_sp:
17992 case T_MNEM_str_sp:
5f4273c7 17993 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
17994 break;
17995 case T_MNEM_ldr:
17996 case T_MNEM_str:
5f4273c7 17997 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
17998 break;
17999 case T_MNEM_ldrh:
18000 case T_MNEM_strh:
5f4273c7 18001 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18002 break;
18003 case T_MNEM_ldrb:
18004 case T_MNEM_strb:
5f4273c7 18005 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18006 break;
18007 case T_MNEM_adr:
5f4273c7 18008 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18009 break;
18010 case T_MNEM_mov:
18011 case T_MNEM_movs:
18012 case T_MNEM_cmp:
18013 case T_MNEM_cmn:
5f4273c7 18014 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18015 break;
18016 case T_MNEM_b:
5f4273c7 18017 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18018 break;
18019 case T_MNEM_bcond:
5f4273c7 18020 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18021 break;
18022 case T_MNEM_add_sp:
18023 case T_MNEM_add_pc:
18024 newsize = relax_immediate (fragp, 8, 2);
18025 break;
18026 case T_MNEM_inc_sp:
18027 case T_MNEM_dec_sp:
18028 newsize = relax_immediate (fragp, 7, 2);
18029 break;
18030 case T_MNEM_addi:
18031 case T_MNEM_addis:
18032 case T_MNEM_subi:
18033 case T_MNEM_subis:
18034 newsize = relax_addsub (fragp, sec);
18035 break;
18036 default:
5f4273c7 18037 abort ();
0110f2b8 18038 }
5e77afaa
PB
18039
18040 fragp->fr_var = newsize;
18041 /* Freeze wide instructions that are at or before the same location as
18042 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18043 Don't freeze them unconditionally because targets may be artificially
18044 misaligned by the expansion of preceding frags. */
5e77afaa 18045 if (stretch <= 0 && newsize > 2)
0110f2b8 18046 {
0110f2b8 18047 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18048 frag_wane (fragp);
0110f2b8 18049 }
5e77afaa 18050
0110f2b8 18051 return newsize - oldsize;
c19d1205 18052}
b99bd4ef 18053
c19d1205 18054/* Round up a section size to the appropriate boundary. */
b99bd4ef 18055
c19d1205
ZW
18056valueT
18057md_section_align (segT segment ATTRIBUTE_UNUSED,
18058 valueT size)
18059{
f0927246
NC
18060#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18061 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18062 {
18063 /* For a.out, force the section size to be aligned. If we don't do
18064 this, BFD will align it for us, but it will not write out the
18065 final bytes of the section. This may be a bug in BFD, but it is
18066 easier to fix it here since that is how the other a.out targets
18067 work. */
18068 int align;
18069
18070 align = bfd_get_section_alignment (stdoutput, segment);
18071 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18072 }
c19d1205 18073#endif
f0927246
NC
18074
18075 return size;
bfae80f2 18076}
b99bd4ef 18077
c19d1205
ZW
18078/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18079 of an rs_align_code fragment. */
18080
18081void
18082arm_handle_align (fragS * fragP)
bfae80f2 18083{
e7495e45
NS
18084 static char const arm_noop[2][2][4] =
18085 {
18086 { /* ARMv1 */
18087 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18088 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18089 },
18090 { /* ARMv6k */
18091 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18092 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18093 },
18094 };
18095 static char const thumb_noop[2][2][2] =
18096 {
18097 { /* Thumb-1 */
18098 {0xc0, 0x46}, /* LE */
18099 {0x46, 0xc0}, /* BE */
18100 },
18101 { /* Thumb-2 */
18102 {0x00, 0xbf}, /* LE */
18103 {0xbf, 0x00} /* BE */
18104 }
18105 };
18106 static char const wide_thumb_noop[2][4] =
18107 { /* Wide Thumb-2 */
18108 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18109 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18110 };
18111
18112 unsigned bytes, fix, noop_size;
c19d1205
ZW
18113 char * p;
18114 const char * noop;
e7495e45 18115 const char *narrow_noop = NULL;
bfae80f2 18116
c19d1205 18117 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18118 return;
18119
c19d1205
ZW
18120 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18121 p = fragP->fr_literal + fragP->fr_fix;
18122 fix = 0;
bfae80f2 18123
c19d1205
ZW
18124 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18125 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18126
9c2799c2 18127 gas_assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
8dc2430f
NC
18128
18129 if (fragP->tc_frag_data & (~ MODE_RECORDED))
a737bd4d 18130 {
e7495e45
NS
18131 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18132 {
18133 narrow_noop = thumb_noop[1][target_big_endian];
18134 noop = wide_thumb_noop[target_big_endian];
18135 }
c19d1205 18136 else
e7495e45
NS
18137 noop = thumb_noop[0][target_big_endian];
18138 noop_size = 2;
7ed4c4c5
NC
18139 }
18140 else
18141 {
e7495e45
NS
18142 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18143 [target_big_endian];
18144 noop_size = 4;
7ed4c4c5 18145 }
e7495e45
NS
18146
18147 fragP->fr_var = noop_size;
18148
c19d1205 18149 if (bytes & (noop_size - 1))
7ed4c4c5 18150 {
c19d1205
ZW
18151 fix = bytes & (noop_size - 1);
18152 memset (p, 0, fix);
18153 p += fix;
18154 bytes -= fix;
a737bd4d 18155 }
a737bd4d 18156
e7495e45
NS
18157 if (narrow_noop)
18158 {
18159 if (bytes & noop_size)
18160 {
18161 /* Insert a narrow noop. */
18162 memcpy (p, narrow_noop, noop_size);
18163 p += noop_size;
18164 bytes -= noop_size;
18165 fix += noop_size;
18166 }
18167
18168 /* Use wide noops for the remainder */
18169 noop_size = 4;
18170 }
18171
c19d1205 18172 while (bytes >= noop_size)
a737bd4d 18173 {
c19d1205
ZW
18174 memcpy (p, noop, noop_size);
18175 p += noop_size;
18176 bytes -= noop_size;
18177 fix += noop_size;
a737bd4d
NC
18178 }
18179
c19d1205 18180 fragP->fr_fix += fix;
a737bd4d
NC
18181}
18182
c19d1205
ZW
18183/* Called from md_do_align. Used to create an alignment
18184 frag in a code section. */
18185
18186void
18187arm_frag_align_code (int n, int max)
bfae80f2 18188{
c19d1205 18189 char * p;
7ed4c4c5 18190
c19d1205
ZW
18191 /* We assume that there will never be a requirement
18192 to support alignments greater than 32 bytes. */
18193 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18194 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 18195
c19d1205
ZW
18196 p = frag_var (rs_align_code,
18197 MAX_MEM_FOR_RS_ALIGN_CODE,
18198 1,
18199 (relax_substateT) max,
18200 (symbolS *) NULL,
18201 (offsetT) n,
18202 (char *) NULL);
18203 *p = 0;
18204}
bfae80f2 18205
8dc2430f
NC
18206/* Perform target specific initialisation of a frag.
18207 Note - despite the name this initialisation is not done when the frag
18208 is created, but only when its type is assigned. A frag can be created
18209 and used a long time before its type is set, so beware of assuming that
18210 this initialisationis performed first. */
bfae80f2 18211
c19d1205
ZW
18212void
18213arm_init_frag (fragS * fragP)
18214{
8dc2430f
NC
18215 /* If the current ARM vs THUMB mode has not already
18216 been recorded into this frag then do so now. */
18217 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
18218 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
bfae80f2
RE
18219}
18220
c19d1205
ZW
18221#ifdef OBJ_ELF
18222/* When we change sections we need to issue a new mapping symbol. */
18223
18224void
18225arm_elf_change_section (void)
bfae80f2 18226{
c19d1205
ZW
18227 flagword flags;
18228 segment_info_type *seginfo;
bfae80f2 18229
c19d1205
ZW
18230 /* Link an unlinked unwind index table section to the .text section. */
18231 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18232 && elf_linked_to_section (now_seg) == NULL)
18233 elf_linked_to_section (now_seg) = text_section;
18234
18235 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
18236 return;
18237
c19d1205
ZW
18238 flags = bfd_get_section_flags (stdoutput, now_seg);
18239
18240 /* We can ignore sections that only contain debug info. */
18241 if ((flags & SEC_ALLOC) == 0)
18242 return;
bfae80f2 18243
c19d1205
ZW
18244 seginfo = seg_info (now_seg);
18245 mapstate = seginfo->tc_segment_info_data.mapstate;
18246 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
18247}
18248
c19d1205
ZW
18249int
18250arm_elf_section_type (const char * str, size_t len)
e45d0630 18251{
c19d1205
ZW
18252 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18253 return SHT_ARM_EXIDX;
e45d0630 18254
c19d1205
ZW
18255 return -1;
18256}
18257\f
18258/* Code to deal with unwinding tables. */
e45d0630 18259
c19d1205 18260static void add_unwind_adjustsp (offsetT);
e45d0630 18261
5f4273c7 18262/* Generate any deferred unwind frame offset. */
e45d0630 18263
bfae80f2 18264static void
c19d1205 18265flush_pending_unwind (void)
bfae80f2 18266{
c19d1205 18267 offsetT offset;
bfae80f2 18268
c19d1205
ZW
18269 offset = unwind.pending_offset;
18270 unwind.pending_offset = 0;
18271 if (offset != 0)
18272 add_unwind_adjustsp (offset);
bfae80f2
RE
18273}
18274
c19d1205
ZW
18275/* Add an opcode to this list for this function. Two-byte opcodes should
18276 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18277 order. */
18278
bfae80f2 18279static void
c19d1205 18280add_unwind_opcode (valueT op, int length)
bfae80f2 18281{
c19d1205
ZW
18282 /* Add any deferred stack adjustment. */
18283 if (unwind.pending_offset)
18284 flush_pending_unwind ();
bfae80f2 18285
c19d1205 18286 unwind.sp_restored = 0;
bfae80f2 18287
c19d1205 18288 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18289 {
c19d1205
ZW
18290 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18291 if (unwind.opcodes)
18292 unwind.opcodes = xrealloc (unwind.opcodes,
18293 unwind.opcode_alloc);
18294 else
18295 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 18296 }
c19d1205 18297 while (length > 0)
bfae80f2 18298 {
c19d1205
ZW
18299 length--;
18300 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18301 op >>= 8;
18302 unwind.opcode_count++;
bfae80f2 18303 }
bfae80f2
RE
18304}
18305
c19d1205
ZW
18306/* Add unwind opcodes to adjust the stack pointer. */
18307
bfae80f2 18308static void
c19d1205 18309add_unwind_adjustsp (offsetT offset)
bfae80f2 18310{
c19d1205 18311 valueT op;
bfae80f2 18312
c19d1205 18313 if (offset > 0x200)
bfae80f2 18314 {
c19d1205
ZW
18315 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18316 char bytes[5];
18317 int n;
18318 valueT o;
bfae80f2 18319
c19d1205
ZW
18320 /* Long form: 0xb2, uleb128. */
18321 /* This might not fit in a word so add the individual bytes,
18322 remembering the list is built in reverse order. */
18323 o = (valueT) ((offset - 0x204) >> 2);
18324 if (o == 0)
18325 add_unwind_opcode (0, 1);
bfae80f2 18326
c19d1205
ZW
18327 /* Calculate the uleb128 encoding of the offset. */
18328 n = 0;
18329 while (o)
18330 {
18331 bytes[n] = o & 0x7f;
18332 o >>= 7;
18333 if (o)
18334 bytes[n] |= 0x80;
18335 n++;
18336 }
18337 /* Add the insn. */
18338 for (; n; n--)
18339 add_unwind_opcode (bytes[n - 1], 1);
18340 add_unwind_opcode (0xb2, 1);
18341 }
18342 else if (offset > 0x100)
bfae80f2 18343 {
c19d1205
ZW
18344 /* Two short opcodes. */
18345 add_unwind_opcode (0x3f, 1);
18346 op = (offset - 0x104) >> 2;
18347 add_unwind_opcode (op, 1);
bfae80f2 18348 }
c19d1205
ZW
18349 else if (offset > 0)
18350 {
18351 /* Short opcode. */
18352 op = (offset - 4) >> 2;
18353 add_unwind_opcode (op, 1);
18354 }
18355 else if (offset < 0)
bfae80f2 18356 {
c19d1205
ZW
18357 offset = -offset;
18358 while (offset > 0x100)
bfae80f2 18359 {
c19d1205
ZW
18360 add_unwind_opcode (0x7f, 1);
18361 offset -= 0x100;
bfae80f2 18362 }
c19d1205
ZW
18363 op = ((offset - 4) >> 2) | 0x40;
18364 add_unwind_opcode (op, 1);
bfae80f2 18365 }
bfae80f2
RE
18366}
18367
c19d1205
ZW
18368/* Finish the list of unwind opcodes for this function. */
18369static void
18370finish_unwind_opcodes (void)
bfae80f2 18371{
c19d1205 18372 valueT op;
bfae80f2 18373
c19d1205 18374 if (unwind.fp_used)
bfae80f2 18375 {
708587a4 18376 /* Adjust sp as necessary. */
c19d1205
ZW
18377 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18378 flush_pending_unwind ();
bfae80f2 18379
c19d1205
ZW
18380 /* After restoring sp from the frame pointer. */
18381 op = 0x90 | unwind.fp_reg;
18382 add_unwind_opcode (op, 1);
18383 }
18384 else
18385 flush_pending_unwind ();
bfae80f2
RE
18386}
18387
bfae80f2 18388
c19d1205
ZW
18389/* Start an exception table entry. If idx is nonzero this is an index table
18390 entry. */
bfae80f2
RE
18391
18392static void
c19d1205 18393start_unwind_section (const segT text_seg, int idx)
bfae80f2 18394{
c19d1205
ZW
18395 const char * text_name;
18396 const char * prefix;
18397 const char * prefix_once;
18398 const char * group_name;
18399 size_t prefix_len;
18400 size_t text_len;
18401 char * sec_name;
18402 size_t sec_name_len;
18403 int type;
18404 int flags;
18405 int linkonce;
bfae80f2 18406
c19d1205 18407 if (idx)
bfae80f2 18408 {
c19d1205
ZW
18409 prefix = ELF_STRING_ARM_unwind;
18410 prefix_once = ELF_STRING_ARM_unwind_once;
18411 type = SHT_ARM_EXIDX;
bfae80f2 18412 }
c19d1205 18413 else
bfae80f2 18414 {
c19d1205
ZW
18415 prefix = ELF_STRING_ARM_unwind_info;
18416 prefix_once = ELF_STRING_ARM_unwind_info_once;
18417 type = SHT_PROGBITS;
bfae80f2
RE
18418 }
18419
c19d1205
ZW
18420 text_name = segment_name (text_seg);
18421 if (streq (text_name, ".text"))
18422 text_name = "";
18423
18424 if (strncmp (text_name, ".gnu.linkonce.t.",
18425 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 18426 {
c19d1205
ZW
18427 prefix = prefix_once;
18428 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
18429 }
18430
c19d1205
ZW
18431 prefix_len = strlen (prefix);
18432 text_len = strlen (text_name);
18433 sec_name_len = prefix_len + text_len;
18434 sec_name = xmalloc (sec_name_len + 1);
18435 memcpy (sec_name, prefix, prefix_len);
18436 memcpy (sec_name + prefix_len, text_name, text_len);
18437 sec_name[prefix_len + text_len] = '\0';
bfae80f2 18438
c19d1205
ZW
18439 flags = SHF_ALLOC;
18440 linkonce = 0;
18441 group_name = 0;
bfae80f2 18442
c19d1205
ZW
18443 /* Handle COMDAT group. */
18444 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 18445 {
c19d1205
ZW
18446 group_name = elf_group_name (text_seg);
18447 if (group_name == NULL)
18448 {
bd3ba5d1 18449 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
18450 segment_name (text_seg));
18451 ignore_rest_of_line ();
18452 return;
18453 }
18454 flags |= SHF_GROUP;
18455 linkonce = 1;
bfae80f2
RE
18456 }
18457
c19d1205 18458 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 18459
5f4273c7 18460 /* Set the section link for index tables. */
c19d1205
ZW
18461 if (idx)
18462 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
18463}
18464
bfae80f2 18465
c19d1205
ZW
18466/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
18467 personality routine data. Returns zero, or the index table value for
18468 and inline entry. */
18469
18470static valueT
18471create_unwind_entry (int have_data)
bfae80f2 18472{
c19d1205
ZW
18473 int size;
18474 addressT where;
18475 char *ptr;
18476 /* The current word of data. */
18477 valueT data;
18478 /* The number of bytes left in this word. */
18479 int n;
bfae80f2 18480
c19d1205 18481 finish_unwind_opcodes ();
bfae80f2 18482
c19d1205
ZW
18483 /* Remember the current text section. */
18484 unwind.saved_seg = now_seg;
18485 unwind.saved_subseg = now_subseg;
bfae80f2 18486
c19d1205 18487 start_unwind_section (now_seg, 0);
bfae80f2 18488
c19d1205 18489 if (unwind.personality_routine == NULL)
bfae80f2 18490 {
c19d1205
ZW
18491 if (unwind.personality_index == -2)
18492 {
18493 if (have_data)
5f4273c7 18494 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
18495 return 1; /* EXIDX_CANTUNWIND. */
18496 }
bfae80f2 18497
c19d1205
ZW
18498 /* Use a default personality routine if none is specified. */
18499 if (unwind.personality_index == -1)
18500 {
18501 if (unwind.opcode_count > 3)
18502 unwind.personality_index = 1;
18503 else
18504 unwind.personality_index = 0;
18505 }
bfae80f2 18506
c19d1205
ZW
18507 /* Space for the personality routine entry. */
18508 if (unwind.personality_index == 0)
18509 {
18510 if (unwind.opcode_count > 3)
18511 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 18512
c19d1205
ZW
18513 if (!have_data)
18514 {
18515 /* All the data is inline in the index table. */
18516 data = 0x80;
18517 n = 3;
18518 while (unwind.opcode_count > 0)
18519 {
18520 unwind.opcode_count--;
18521 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18522 n--;
18523 }
bfae80f2 18524
c19d1205
ZW
18525 /* Pad with "finish" opcodes. */
18526 while (n--)
18527 data = (data << 8) | 0xb0;
bfae80f2 18528
c19d1205
ZW
18529 return data;
18530 }
18531 size = 0;
18532 }
18533 else
18534 /* We get two opcodes "free" in the first word. */
18535 size = unwind.opcode_count - 2;
18536 }
18537 else
18538 /* An extra byte is required for the opcode count. */
18539 size = unwind.opcode_count + 1;
bfae80f2 18540
c19d1205
ZW
18541 size = (size + 3) >> 2;
18542 if (size > 0xff)
18543 as_bad (_("too many unwind opcodes"));
bfae80f2 18544
c19d1205
ZW
18545 frag_align (2, 0, 0);
18546 record_alignment (now_seg, 2);
18547 unwind.table_entry = expr_build_dot ();
18548
18549 /* Allocate the table entry. */
18550 ptr = frag_more ((size << 2) + 4);
18551 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 18552
c19d1205 18553 switch (unwind.personality_index)
bfae80f2 18554 {
c19d1205
ZW
18555 case -1:
18556 /* ??? Should this be a PLT generating relocation? */
18557 /* Custom personality routine. */
18558 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18559 BFD_RELOC_ARM_PREL31);
bfae80f2 18560
c19d1205
ZW
18561 where += 4;
18562 ptr += 4;
bfae80f2 18563
c19d1205
ZW
18564 /* Set the first byte to the number of additional words. */
18565 data = size - 1;
18566 n = 3;
18567 break;
bfae80f2 18568
c19d1205
ZW
18569 /* ABI defined personality routines. */
18570 case 0:
18571 /* Three opcodes bytes are packed into the first word. */
18572 data = 0x80;
18573 n = 3;
18574 break;
bfae80f2 18575
c19d1205
ZW
18576 case 1:
18577 case 2:
18578 /* The size and first two opcode bytes go in the first word. */
18579 data = ((0x80 + unwind.personality_index) << 8) | size;
18580 n = 2;
18581 break;
bfae80f2 18582
c19d1205
ZW
18583 default:
18584 /* Should never happen. */
18585 abort ();
18586 }
bfae80f2 18587
c19d1205
ZW
18588 /* Pack the opcodes into words (MSB first), reversing the list at the same
18589 time. */
18590 while (unwind.opcode_count > 0)
18591 {
18592 if (n == 0)
18593 {
18594 md_number_to_chars (ptr, data, 4);
18595 ptr += 4;
18596 n = 4;
18597 data = 0;
18598 }
18599 unwind.opcode_count--;
18600 n--;
18601 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18602 }
18603
18604 /* Finish off the last word. */
18605 if (n < 4)
18606 {
18607 /* Pad with "finish" opcodes. */
18608 while (n--)
18609 data = (data << 8) | 0xb0;
18610
18611 md_number_to_chars (ptr, data, 4);
18612 }
18613
18614 if (!have_data)
18615 {
18616 /* Add an empty descriptor if there is no user-specified data. */
18617 ptr = frag_more (4);
18618 md_number_to_chars (ptr, 0, 4);
18619 }
18620
18621 return 0;
bfae80f2
RE
18622}
18623
f0927246
NC
18624
18625/* Initialize the DWARF-2 unwind information for this procedure. */
18626
18627void
18628tc_arm_frame_initial_instructions (void)
18629{
18630 cfi_add_CFA_def_cfa (REG_SP, 0);
18631}
18632#endif /* OBJ_ELF */
18633
c19d1205
ZW
18634/* Convert REGNAME to a DWARF-2 register number. */
18635
18636int
1df69f4f 18637tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 18638{
1df69f4f 18639 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
18640
18641 if (reg == FAIL)
18642 return -1;
18643
18644 return reg;
bfae80f2
RE
18645}
18646
f0927246 18647#ifdef TE_PE
c19d1205 18648void
f0927246 18649tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 18650{
f0927246 18651 expressionS expr;
bfae80f2 18652
f0927246
NC
18653 expr.X_op = O_secrel;
18654 expr.X_add_symbol = symbol;
18655 expr.X_add_number = 0;
18656 emit_expr (&expr, size);
18657}
18658#endif
bfae80f2 18659
c19d1205 18660/* MD interface: Symbol and relocation handling. */
bfae80f2 18661
2fc8bdac
ZW
18662/* Return the address within the segment that a PC-relative fixup is
18663 relative to. For ARM, PC-relative fixups applied to instructions
18664 are generally relative to the location of the fixup plus 8 bytes.
18665 Thumb branches are offset by 4, and Thumb loads relative to PC
18666 require special handling. */
bfae80f2 18667
c19d1205 18668long
2fc8bdac 18669md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 18670{
2fc8bdac
ZW
18671 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18672
18673 /* If this is pc-relative and we are going to emit a relocation
18674 then we just want to put out any pipeline compensation that the linker
53baae48
NC
18675 will need. Otherwise we want to use the calculated base.
18676 For WinCE we skip the bias for externals as well, since this
18677 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 18678 if (fixP->fx_pcrel
2fc8bdac 18679 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
18680 || (arm_force_relocation (fixP)
18681#ifdef TE_WINCE
18682 && !S_IS_EXTERNAL (fixP->fx_addsy)
18683#endif
18684 )))
2fc8bdac 18685 base = 0;
bfae80f2 18686
267bf995 18687
c19d1205 18688 switch (fixP->fx_r_type)
bfae80f2 18689 {
2fc8bdac
ZW
18690 /* PC relative addressing on the Thumb is slightly odd as the
18691 bottom two bits of the PC are forced to zero for the
18692 calculation. This happens *after* application of the
18693 pipeline offset. However, Thumb adrl already adjusts for
18694 this, so we need not do it again. */
c19d1205 18695 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 18696 return base & ~3;
c19d1205
ZW
18697
18698 case BFD_RELOC_ARM_THUMB_OFFSET:
18699 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 18700 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 18701 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 18702 return (base + 4) & ~3;
c19d1205 18703
2fc8bdac
ZW
18704 /* Thumb branches are simply offset by +4. */
18705 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18706 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18707 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18708 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 18709 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 18710 return base + 4;
bfae80f2 18711
267bf995
RR
18712 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18713 if (fixP->fx_addsy
18714 && ARM_IS_FUNC (fixP->fx_addsy)
18715 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18716 base = fixP->fx_where + fixP->fx_frag->fr_address;
18717 return base + 4;
18718
00adf2d4
JB
18719 /* BLX is like branches above, but forces the low two bits of PC to
18720 zero. */
267bf995
RR
18721 case BFD_RELOC_THUMB_PCREL_BLX:
18722 if (fixP->fx_addsy
18723 && THUMB_IS_FUNC (fixP->fx_addsy)
18724 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18725 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
18726 return (base + 4) & ~3;
18727
2fc8bdac
ZW
18728 /* ARM mode branches are offset by +8. However, the Windows CE
18729 loader expects the relocation not to take this into account. */
267bf995
RR
18730 case BFD_RELOC_ARM_PCREL_BLX:
18731 if (fixP->fx_addsy
18732 && ARM_IS_FUNC (fixP->fx_addsy)
18733 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18734 base = fixP->fx_where + fixP->fx_frag->fr_address;
18735 return base + 8;
18736
18737 case BFD_RELOC_ARM_PCREL_CALL:
18738 if (fixP->fx_addsy
18739 && THUMB_IS_FUNC (fixP->fx_addsy)
18740 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18741 base = fixP->fx_where + fixP->fx_frag->fr_address;
18742 return base + 8;
18743
2fc8bdac 18744 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 18745 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18746 case BFD_RELOC_ARM_PLT32:
c19d1205 18747#ifdef TE_WINCE
5f4273c7 18748 /* When handling fixups immediately, because we have already
53baae48
NC
18749 discovered the value of a symbol, or the address of the frag involved
18750 we must account for the offset by +8, as the OS loader will never see the reloc.
18751 see fixup_segment() in write.c
18752 The S_IS_EXTERNAL test handles the case of global symbols.
18753 Those need the calculated base, not just the pipe compensation the linker will need. */
18754 if (fixP->fx_pcrel
18755 && fixP->fx_addsy != NULL
18756 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18757 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18758 return base + 8;
2fc8bdac 18759 return base;
c19d1205 18760#else
2fc8bdac 18761 return base + 8;
c19d1205 18762#endif
2fc8bdac 18763
267bf995 18764
2fc8bdac
ZW
18765 /* ARM mode loads relative to PC are also offset by +8. Unlike
18766 branches, the Windows CE loader *does* expect the relocation
18767 to take this into account. */
18768 case BFD_RELOC_ARM_OFFSET_IMM:
18769 case BFD_RELOC_ARM_OFFSET_IMM8:
18770 case BFD_RELOC_ARM_HWLITERAL:
18771 case BFD_RELOC_ARM_LITERAL:
18772 case BFD_RELOC_ARM_CP_OFF_IMM:
18773 return base + 8;
18774
18775
18776 /* Other PC-relative relocations are un-offset. */
18777 default:
18778 return base;
18779 }
bfae80f2
RE
18780}
18781
c19d1205
ZW
18782/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18783 Otherwise we have no need to default values of symbols. */
18784
18785symbolS *
18786md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 18787{
c19d1205
ZW
18788#ifdef OBJ_ELF
18789 if (name[0] == '_' && name[1] == 'G'
18790 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18791 {
18792 if (!GOT_symbol)
18793 {
18794 if (symbol_find (name))
bd3ba5d1 18795 as_bad (_("GOT already in the symbol table"));
bfae80f2 18796
c19d1205
ZW
18797 GOT_symbol = symbol_new (name, undefined_section,
18798 (valueT) 0, & zero_address_frag);
18799 }
bfae80f2 18800
c19d1205 18801 return GOT_symbol;
bfae80f2 18802 }
c19d1205 18803#endif
bfae80f2 18804
c19d1205 18805 return 0;
bfae80f2
RE
18806}
18807
55cf6793 18808/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
18809 computed as two separate immediate values, added together. We
18810 already know that this value cannot be computed by just one ARM
18811 instruction. */
18812
18813static unsigned int
18814validate_immediate_twopart (unsigned int val,
18815 unsigned int * highpart)
bfae80f2 18816{
c19d1205
ZW
18817 unsigned int a;
18818 unsigned int i;
bfae80f2 18819
c19d1205
ZW
18820 for (i = 0; i < 32; i += 2)
18821 if (((a = rotate_left (val, i)) & 0xff) != 0)
18822 {
18823 if (a & 0xff00)
18824 {
18825 if (a & ~ 0xffff)
18826 continue;
18827 * highpart = (a >> 8) | ((i + 24) << 7);
18828 }
18829 else if (a & 0xff0000)
18830 {
18831 if (a & 0xff000000)
18832 continue;
18833 * highpart = (a >> 16) | ((i + 16) << 7);
18834 }
18835 else
18836 {
9c2799c2 18837 gas_assert (a & 0xff000000);
c19d1205
ZW
18838 * highpart = (a >> 24) | ((i + 8) << 7);
18839 }
bfae80f2 18840
c19d1205
ZW
18841 return (a & 0xff) | (i << 7);
18842 }
bfae80f2 18843
c19d1205 18844 return FAIL;
bfae80f2
RE
18845}
18846
c19d1205
ZW
18847static int
18848validate_offset_imm (unsigned int val, int hwse)
18849{
18850 if ((hwse && val > 255) || val > 4095)
18851 return FAIL;
18852 return val;
18853}
bfae80f2 18854
55cf6793 18855/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
18856 negative immediate constant by altering the instruction. A bit of
18857 a hack really.
18858 MOV <-> MVN
18859 AND <-> BIC
18860 ADC <-> SBC
18861 by inverting the second operand, and
18862 ADD <-> SUB
18863 CMP <-> CMN
18864 by negating the second operand. */
bfae80f2 18865
c19d1205
ZW
18866static int
18867negate_data_op (unsigned long * instruction,
18868 unsigned long value)
bfae80f2 18869{
c19d1205
ZW
18870 int op, new_inst;
18871 unsigned long negated, inverted;
bfae80f2 18872
c19d1205
ZW
18873 negated = encode_arm_immediate (-value);
18874 inverted = encode_arm_immediate (~value);
bfae80f2 18875
c19d1205
ZW
18876 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18877 switch (op)
bfae80f2 18878 {
c19d1205
ZW
18879 /* First negates. */
18880 case OPCODE_SUB: /* ADD <-> SUB */
18881 new_inst = OPCODE_ADD;
18882 value = negated;
18883 break;
bfae80f2 18884
c19d1205
ZW
18885 case OPCODE_ADD:
18886 new_inst = OPCODE_SUB;
18887 value = negated;
18888 break;
bfae80f2 18889
c19d1205
ZW
18890 case OPCODE_CMP: /* CMP <-> CMN */
18891 new_inst = OPCODE_CMN;
18892 value = negated;
18893 break;
bfae80f2 18894
c19d1205
ZW
18895 case OPCODE_CMN:
18896 new_inst = OPCODE_CMP;
18897 value = negated;
18898 break;
bfae80f2 18899
c19d1205
ZW
18900 /* Now Inverted ops. */
18901 case OPCODE_MOV: /* MOV <-> MVN */
18902 new_inst = OPCODE_MVN;
18903 value = inverted;
18904 break;
bfae80f2 18905
c19d1205
ZW
18906 case OPCODE_MVN:
18907 new_inst = OPCODE_MOV;
18908 value = inverted;
18909 break;
bfae80f2 18910
c19d1205
ZW
18911 case OPCODE_AND: /* AND <-> BIC */
18912 new_inst = OPCODE_BIC;
18913 value = inverted;
18914 break;
bfae80f2 18915
c19d1205
ZW
18916 case OPCODE_BIC:
18917 new_inst = OPCODE_AND;
18918 value = inverted;
18919 break;
bfae80f2 18920
c19d1205
ZW
18921 case OPCODE_ADC: /* ADC <-> SBC */
18922 new_inst = OPCODE_SBC;
18923 value = inverted;
18924 break;
bfae80f2 18925
c19d1205
ZW
18926 case OPCODE_SBC:
18927 new_inst = OPCODE_ADC;
18928 value = inverted;
18929 break;
bfae80f2 18930
c19d1205
ZW
18931 /* We cannot do anything. */
18932 default:
18933 return FAIL;
b99bd4ef
NC
18934 }
18935
c19d1205
ZW
18936 if (value == (unsigned) FAIL)
18937 return FAIL;
18938
18939 *instruction &= OPCODE_MASK;
18940 *instruction |= new_inst << DATA_OP_SHIFT;
18941 return value;
b99bd4ef
NC
18942}
18943
ef8d22e6
PB
18944/* Like negate_data_op, but for Thumb-2. */
18945
18946static unsigned int
16dd5e42 18947thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
18948{
18949 int op, new_inst;
18950 int rd;
16dd5e42 18951 unsigned int negated, inverted;
ef8d22e6
PB
18952
18953 negated = encode_thumb32_immediate (-value);
18954 inverted = encode_thumb32_immediate (~value);
18955
18956 rd = (*instruction >> 8) & 0xf;
18957 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18958 switch (op)
18959 {
18960 /* ADD <-> SUB. Includes CMP <-> CMN. */
18961 case T2_OPCODE_SUB:
18962 new_inst = T2_OPCODE_ADD;
18963 value = negated;
18964 break;
18965
18966 case T2_OPCODE_ADD:
18967 new_inst = T2_OPCODE_SUB;
18968 value = negated;
18969 break;
18970
18971 /* ORR <-> ORN. Includes MOV <-> MVN. */
18972 case T2_OPCODE_ORR:
18973 new_inst = T2_OPCODE_ORN;
18974 value = inverted;
18975 break;
18976
18977 case T2_OPCODE_ORN:
18978 new_inst = T2_OPCODE_ORR;
18979 value = inverted;
18980 break;
18981
18982 /* AND <-> BIC. TST has no inverted equivalent. */
18983 case T2_OPCODE_AND:
18984 new_inst = T2_OPCODE_BIC;
18985 if (rd == 15)
18986 value = FAIL;
18987 else
18988 value = inverted;
18989 break;
18990
18991 case T2_OPCODE_BIC:
18992 new_inst = T2_OPCODE_AND;
18993 value = inverted;
18994 break;
18995
18996 /* ADC <-> SBC */
18997 case T2_OPCODE_ADC:
18998 new_inst = T2_OPCODE_SBC;
18999 value = inverted;
19000 break;
19001
19002 case T2_OPCODE_SBC:
19003 new_inst = T2_OPCODE_ADC;
19004 value = inverted;
19005 break;
19006
19007 /* We cannot do anything. */
19008 default:
19009 return FAIL;
19010 }
19011
16dd5e42 19012 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19013 return FAIL;
19014
19015 *instruction &= T2_OPCODE_MASK;
19016 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19017 return value;
19018}
19019
8f06b2d8
PB
19020/* Read a 32-bit thumb instruction from buf. */
19021static unsigned long
19022get_thumb32_insn (char * buf)
19023{
19024 unsigned long insn;
19025 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19026 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19027
19028 return insn;
19029}
19030
a8bc6c78
PB
19031
19032/* We usually want to set the low bit on the address of thumb function
19033 symbols. In particular .word foo - . should have the low bit set.
19034 Generic code tries to fold the difference of two symbols to
19035 a constant. Prevent this and force a relocation when the first symbols
19036 is a thumb function. */
19037int
19038arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19039{
19040 if (op == O_subtract
19041 && l->X_op == O_symbol
19042 && r->X_op == O_symbol
19043 && THUMB_IS_FUNC (l->X_add_symbol))
19044 {
19045 l->X_op = O_subtract;
19046 l->X_op_symbol = r->X_add_symbol;
19047 l->X_add_number -= r->X_add_number;
19048 return 1;
19049 }
19050 /* Process as normal. */
19051 return 0;
19052}
19053
c19d1205 19054void
55cf6793 19055md_apply_fix (fixS * fixP,
c19d1205
ZW
19056 valueT * valP,
19057 segT seg)
19058{
19059 offsetT value = * valP;
19060 offsetT newval;
19061 unsigned int newimm;
19062 unsigned long temp;
19063 int sign;
19064 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19065
9c2799c2 19066 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19067
c19d1205 19068 /* Note whether this will delete the relocation. */
4962c51a 19069
c19d1205
ZW
19070 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19071 fixP->fx_done = 1;
b99bd4ef 19072
adbaf948 19073 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19074 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19075 for emit_reloc. */
19076 value &= 0xffffffff;
19077 value ^= 0x80000000;
5f4273c7 19078 value -= 0x80000000;
adbaf948
ZW
19079
19080 *valP = value;
c19d1205 19081 fixP->fx_addnumber = value;
b99bd4ef 19082
adbaf948
ZW
19083 /* Same treatment for fixP->fx_offset. */
19084 fixP->fx_offset &= 0xffffffff;
19085 fixP->fx_offset ^= 0x80000000;
19086 fixP->fx_offset -= 0x80000000;
19087
c19d1205 19088 switch (fixP->fx_r_type)
b99bd4ef 19089 {
c19d1205
ZW
19090 case BFD_RELOC_NONE:
19091 /* This will need to go in the object file. */
19092 fixP->fx_done = 0;
19093 break;
b99bd4ef 19094
c19d1205
ZW
19095 case BFD_RELOC_ARM_IMMEDIATE:
19096 /* We claim that this fixup has been processed here,
19097 even if in fact we generate an error because we do
19098 not have a reloc for it, so tc_gen_reloc will reject it. */
19099 fixP->fx_done = 1;
b99bd4ef 19100
c19d1205
ZW
19101 if (fixP->fx_addsy
19102 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 19103 {
c19d1205
ZW
19104 as_bad_where (fixP->fx_file, fixP->fx_line,
19105 _("undefined symbol %s used as an immediate value"),
19106 S_GET_NAME (fixP->fx_addsy));
19107 break;
b99bd4ef
NC
19108 }
19109
42e5fcbf
AS
19110 if (fixP->fx_addsy
19111 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19112 {
19113 as_bad_where (fixP->fx_file, fixP->fx_line,
19114 _("symbol %s is in a different section"),
19115 S_GET_NAME (fixP->fx_addsy));
19116 break;
19117 }
19118
c19d1205
ZW
19119 newimm = encode_arm_immediate (value);
19120 temp = md_chars_to_number (buf, INSN_SIZE);
19121
19122 /* If the instruction will fail, see if we can fix things up by
19123 changing the opcode. */
19124 if (newimm == (unsigned int) FAIL
19125 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19126 {
c19d1205
ZW
19127 as_bad_where (fixP->fx_file, fixP->fx_line,
19128 _("invalid constant (%lx) after fixup"),
19129 (unsigned long) value);
19130 break;
b99bd4ef 19131 }
b99bd4ef 19132
c19d1205
ZW
19133 newimm |= (temp & 0xfffff000);
19134 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19135 break;
b99bd4ef 19136
c19d1205
ZW
19137 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19138 {
19139 unsigned int highpart = 0;
19140 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19141
42e5fcbf
AS
19142 if (fixP->fx_addsy
19143 && ! S_IS_DEFINED (fixP->fx_addsy))
19144 {
19145 as_bad_where (fixP->fx_file, fixP->fx_line,
19146 _("undefined symbol %s used as an immediate value"),
19147 S_GET_NAME (fixP->fx_addsy));
19148 break;
19149 }
19150
19151 if (fixP->fx_addsy
19152 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19153 {
19154 as_bad_where (fixP->fx_file, fixP->fx_line,
19155 _("symbol %s is in a different section"),
19156 S_GET_NAME (fixP->fx_addsy));
19157 break;
19158 }
19159
c19d1205
ZW
19160 newimm = encode_arm_immediate (value);
19161 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19162
c19d1205
ZW
19163 /* If the instruction will fail, see if we can fix things up by
19164 changing the opcode. */
19165 if (newimm == (unsigned int) FAIL
19166 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19167 {
19168 /* No ? OK - try using two ADD instructions to generate
19169 the value. */
19170 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19171
c19d1205
ZW
19172 /* Yes - then make sure that the second instruction is
19173 also an add. */
19174 if (newimm != (unsigned int) FAIL)
19175 newinsn = temp;
19176 /* Still No ? Try using a negated value. */
19177 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19178 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19179 /* Otherwise - give up. */
19180 else
19181 {
19182 as_bad_where (fixP->fx_file, fixP->fx_line,
19183 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19184 (long) value);
19185 break;
19186 }
b99bd4ef 19187
c19d1205
ZW
19188 /* Replace the first operand in the 2nd instruction (which
19189 is the PC) with the destination register. We have
19190 already added in the PC in the first instruction and we
19191 do not want to do it again. */
19192 newinsn &= ~ 0xf0000;
19193 newinsn |= ((newinsn & 0x0f000) << 4);
19194 }
b99bd4ef 19195
c19d1205
ZW
19196 newimm |= (temp & 0xfffff000);
19197 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19198
c19d1205
ZW
19199 highpart |= (newinsn & 0xfffff000);
19200 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19201 }
19202 break;
b99bd4ef 19203
c19d1205 19204 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19205 if (!fixP->fx_done && seg->use_rela_p)
19206 value = 0;
19207
c19d1205
ZW
19208 case BFD_RELOC_ARM_LITERAL:
19209 sign = value >= 0;
b99bd4ef 19210
c19d1205
ZW
19211 if (value < 0)
19212 value = - value;
b99bd4ef 19213
c19d1205 19214 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19215 {
c19d1205
ZW
19216 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19217 as_bad_where (fixP->fx_file, fixP->fx_line,
19218 _("invalid literal constant: pool needs to be closer"));
19219 else
19220 as_bad_where (fixP->fx_file, fixP->fx_line,
19221 _("bad immediate value for offset (%ld)"),
19222 (long) value);
19223 break;
f03698e6
RE
19224 }
19225
c19d1205
ZW
19226 newval = md_chars_to_number (buf, INSN_SIZE);
19227 newval &= 0xff7ff000;
19228 newval |= value | (sign ? INDEX_UP : 0);
19229 md_number_to_chars (buf, newval, INSN_SIZE);
19230 break;
b99bd4ef 19231
c19d1205
ZW
19232 case BFD_RELOC_ARM_OFFSET_IMM8:
19233 case BFD_RELOC_ARM_HWLITERAL:
19234 sign = value >= 0;
b99bd4ef 19235
c19d1205
ZW
19236 if (value < 0)
19237 value = - value;
b99bd4ef 19238
c19d1205 19239 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19240 {
c19d1205
ZW
19241 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19242 as_bad_where (fixP->fx_file, fixP->fx_line,
19243 _("invalid literal constant: pool needs to be closer"));
19244 else
f9d4405b 19245 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19246 (long) value);
19247 break;
b99bd4ef
NC
19248 }
19249
c19d1205
ZW
19250 newval = md_chars_to_number (buf, INSN_SIZE);
19251 newval &= 0xff7ff0f0;
19252 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19253 md_number_to_chars (buf, newval, INSN_SIZE);
19254 break;
b99bd4ef 19255
c19d1205
ZW
19256 case BFD_RELOC_ARM_T32_OFFSET_U8:
19257 if (value < 0 || value > 1020 || value % 4 != 0)
19258 as_bad_where (fixP->fx_file, fixP->fx_line,
19259 _("bad immediate value for offset (%ld)"), (long) value);
19260 value /= 4;
b99bd4ef 19261
c19d1205 19262 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19263 newval |= value;
19264 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19265 break;
b99bd4ef 19266
c19d1205
ZW
19267 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19268 /* This is a complicated relocation used for all varieties of Thumb32
19269 load/store instruction with immediate offset:
19270
19271 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19272 *4, optional writeback(W)
19273 (doubleword load/store)
19274
19275 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19276 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19277 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19278 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19279 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19280
19281 Uppercase letters indicate bits that are already encoded at
19282 this point. Lowercase letters are our problem. For the
19283 second block of instructions, the secondary opcode nybble
19284 (bits 8..11) is present, and bit 23 is zero, even if this is
19285 a PC-relative operation. */
19286 newval = md_chars_to_number (buf, THUMB_SIZE);
19287 newval <<= 16;
19288 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19289
c19d1205 19290 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19291 {
c19d1205
ZW
19292 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19293 if (value >= 0)
19294 newval |= (1 << 23);
19295 else
19296 value = -value;
19297 if (value % 4 != 0)
19298 {
19299 as_bad_where (fixP->fx_file, fixP->fx_line,
19300 _("offset not a multiple of 4"));
19301 break;
19302 }
19303 value /= 4;
216d22bc 19304 if (value > 0xff)
c19d1205
ZW
19305 {
19306 as_bad_where (fixP->fx_file, fixP->fx_line,
19307 _("offset out of range"));
19308 break;
19309 }
19310 newval &= ~0xff;
b99bd4ef 19311 }
c19d1205 19312 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 19313 {
c19d1205
ZW
19314 /* PC-relative, 12-bit offset. */
19315 if (value >= 0)
19316 newval |= (1 << 23);
19317 else
19318 value = -value;
216d22bc 19319 if (value > 0xfff)
c19d1205
ZW
19320 {
19321 as_bad_where (fixP->fx_file, fixP->fx_line,
19322 _("offset out of range"));
19323 break;
19324 }
19325 newval &= ~0xfff;
b99bd4ef 19326 }
c19d1205 19327 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 19328 {
c19d1205
ZW
19329 /* Writeback: 8-bit, +/- offset. */
19330 if (value >= 0)
19331 newval |= (1 << 9);
19332 else
19333 value = -value;
216d22bc 19334 if (value > 0xff)
c19d1205
ZW
19335 {
19336 as_bad_where (fixP->fx_file, fixP->fx_line,
19337 _("offset out of range"));
19338 break;
19339 }
19340 newval &= ~0xff;
b99bd4ef 19341 }
c19d1205 19342 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 19343 {
c19d1205 19344 /* T-instruction: positive 8-bit offset. */
216d22bc 19345 if (value < 0 || value > 0xff)
b99bd4ef 19346 {
c19d1205
ZW
19347 as_bad_where (fixP->fx_file, fixP->fx_line,
19348 _("offset out of range"));
19349 break;
b99bd4ef 19350 }
c19d1205
ZW
19351 newval &= ~0xff;
19352 newval |= value;
b99bd4ef
NC
19353 }
19354 else
b99bd4ef 19355 {
c19d1205
ZW
19356 /* Positive 12-bit or negative 8-bit offset. */
19357 int limit;
19358 if (value >= 0)
b99bd4ef 19359 {
c19d1205
ZW
19360 newval |= (1 << 23);
19361 limit = 0xfff;
19362 }
19363 else
19364 {
19365 value = -value;
19366 limit = 0xff;
19367 }
19368 if (value > limit)
19369 {
19370 as_bad_where (fixP->fx_file, fixP->fx_line,
19371 _("offset out of range"));
19372 break;
b99bd4ef 19373 }
c19d1205 19374 newval &= ~limit;
b99bd4ef 19375 }
b99bd4ef 19376
c19d1205
ZW
19377 newval |= value;
19378 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
19379 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
19380 break;
404ff6b5 19381
c19d1205
ZW
19382 case BFD_RELOC_ARM_SHIFT_IMM:
19383 newval = md_chars_to_number (buf, INSN_SIZE);
19384 if (((unsigned long) value) > 32
19385 || (value == 32
19386 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
19387 {
19388 as_bad_where (fixP->fx_file, fixP->fx_line,
19389 _("shift expression is too large"));
19390 break;
19391 }
404ff6b5 19392
c19d1205
ZW
19393 if (value == 0)
19394 /* Shifts of zero must be done as lsl. */
19395 newval &= ~0x60;
19396 else if (value == 32)
19397 value = 0;
19398 newval &= 0xfffff07f;
19399 newval |= (value & 0x1f) << 7;
19400 md_number_to_chars (buf, newval, INSN_SIZE);
19401 break;
404ff6b5 19402
c19d1205 19403 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 19404 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 19405 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 19406 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
19407 /* We claim that this fixup has been processed here,
19408 even if in fact we generate an error because we do
19409 not have a reloc for it, so tc_gen_reloc will reject it. */
19410 fixP->fx_done = 1;
404ff6b5 19411
c19d1205
ZW
19412 if (fixP->fx_addsy
19413 && ! S_IS_DEFINED (fixP->fx_addsy))
19414 {
19415 as_bad_where (fixP->fx_file, fixP->fx_line,
19416 _("undefined symbol %s used as an immediate value"),
19417 S_GET_NAME (fixP->fx_addsy));
19418 break;
19419 }
404ff6b5 19420
c19d1205
ZW
19421 newval = md_chars_to_number (buf, THUMB_SIZE);
19422 newval <<= 16;
19423 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 19424
16805f35
PB
19425 newimm = FAIL;
19426 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19427 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
19428 {
19429 newimm = encode_thumb32_immediate (value);
19430 if (newimm == (unsigned int) FAIL)
19431 newimm = thumb32_negate_data_op (&newval, value);
19432 }
16805f35
PB
19433 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19434 && newimm == (unsigned int) FAIL)
92e90b6e 19435 {
16805f35
PB
19436 /* Turn add/sum into addw/subw. */
19437 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19438 newval = (newval & 0xfeffffff) | 0x02000000;
19439
e9f89963
PB
19440 /* 12 bit immediate for addw/subw. */
19441 if (value < 0)
19442 {
19443 value = -value;
19444 newval ^= 0x00a00000;
19445 }
92e90b6e
PB
19446 if (value > 0xfff)
19447 newimm = (unsigned int) FAIL;
19448 else
19449 newimm = value;
19450 }
cc8a6dd0 19451
c19d1205 19452 if (newimm == (unsigned int)FAIL)
3631a3c8 19453 {
c19d1205
ZW
19454 as_bad_where (fixP->fx_file, fixP->fx_line,
19455 _("invalid constant (%lx) after fixup"),
19456 (unsigned long) value);
19457 break;
3631a3c8
NC
19458 }
19459
c19d1205
ZW
19460 newval |= (newimm & 0x800) << 15;
19461 newval |= (newimm & 0x700) << 4;
19462 newval |= (newimm & 0x0ff);
cc8a6dd0 19463
c19d1205
ZW
19464 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
19465 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
19466 break;
a737bd4d 19467
3eb17e6b 19468 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
19469 if (((unsigned long) value) > 0xffff)
19470 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 19471 _("invalid smc expression"));
2fc8bdac 19472 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19473 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
19474 md_number_to_chars (buf, newval, INSN_SIZE);
19475 break;
a737bd4d 19476
c19d1205 19477 case BFD_RELOC_ARM_SWI:
adbaf948 19478 if (fixP->tc_fix_data != 0)
c19d1205
ZW
19479 {
19480 if (((unsigned long) value) > 0xff)
19481 as_bad_where (fixP->fx_file, fixP->fx_line,
19482 _("invalid swi expression"));
2fc8bdac 19483 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
19484 newval |= value;
19485 md_number_to_chars (buf, newval, THUMB_SIZE);
19486 }
19487 else
19488 {
19489 if (((unsigned long) value) > 0x00ffffff)
19490 as_bad_where (fixP->fx_file, fixP->fx_line,
19491 _("invalid swi expression"));
2fc8bdac 19492 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19493 newval |= value;
19494 md_number_to_chars (buf, newval, INSN_SIZE);
19495 }
19496 break;
a737bd4d 19497
c19d1205
ZW
19498 case BFD_RELOC_ARM_MULTI:
19499 if (((unsigned long) value) > 0xffff)
19500 as_bad_where (fixP->fx_file, fixP->fx_line,
19501 _("invalid expression in load/store multiple"));
19502 newval = value | md_chars_to_number (buf, INSN_SIZE);
19503 md_number_to_chars (buf, newval, INSN_SIZE);
19504 break;
a737bd4d 19505
c19d1205 19506#ifdef OBJ_ELF
39b41c9c 19507 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
19508
19509 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19510 && fixP->fx_addsy
19511 && !S_IS_EXTERNAL (fixP->fx_addsy)
19512 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19513 && THUMB_IS_FUNC (fixP->fx_addsy))
19514 /* Flip the bl to blx. This is a simple flip
19515 bit here because we generate PCREL_CALL for
19516 unconditional bls. */
19517 {
19518 newval = md_chars_to_number (buf, INSN_SIZE);
19519 newval = newval | 0x10000000;
19520 md_number_to_chars (buf, newval, INSN_SIZE);
19521 temp = 1;
19522 fixP->fx_done = 1;
19523 }
39b41c9c
PB
19524 else
19525 temp = 3;
19526 goto arm_branch_common;
19527
19528 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
19529 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19530 && fixP->fx_addsy
19531 && !S_IS_EXTERNAL (fixP->fx_addsy)
19532 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19533 && THUMB_IS_FUNC (fixP->fx_addsy))
19534 {
19535 /* This would map to a bl<cond>, b<cond>,
19536 b<always> to a Thumb function. We
19537 need to force a relocation for this particular
19538 case. */
19539 newval = md_chars_to_number (buf, INSN_SIZE);
19540 fixP->fx_done = 0;
19541 }
19542
2fc8bdac 19543 case BFD_RELOC_ARM_PLT32:
c19d1205 19544#endif
39b41c9c
PB
19545 case BFD_RELOC_ARM_PCREL_BRANCH:
19546 temp = 3;
19547 goto arm_branch_common;
a737bd4d 19548
39b41c9c 19549 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 19550
39b41c9c 19551 temp = 1;
267bf995
RR
19552 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19553 && fixP->fx_addsy
19554 && !S_IS_EXTERNAL (fixP->fx_addsy)
19555 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19556 && ARM_IS_FUNC (fixP->fx_addsy))
19557 {
19558 /* Flip the blx to a bl and warn. */
19559 const char *name = S_GET_NAME (fixP->fx_addsy);
19560 newval = 0xeb000000;
19561 as_warn_where (fixP->fx_file, fixP->fx_line,
19562 _("blx to '%s' an ARM ISA state function changed to bl"),
19563 name);
19564 md_number_to_chars (buf, newval, INSN_SIZE);
19565 temp = 3;
19566 fixP->fx_done = 1;
19567 }
19568
19569#ifdef OBJ_ELF
19570 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
19571 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
19572#endif
19573
39b41c9c 19574 arm_branch_common:
c19d1205 19575 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
19576 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19577 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19578 also be be clear. */
19579 if (value & temp)
c19d1205 19580 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
19581 _("misaligned branch destination"));
19582 if ((value & (offsetT)0xfe000000) != (offsetT)0
19583 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19584 as_bad_where (fixP->fx_file, fixP->fx_line,
19585 _("branch out of range"));
a737bd4d 19586
2fc8bdac 19587 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19588 {
2fc8bdac
ZW
19589 newval = md_chars_to_number (buf, INSN_SIZE);
19590 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
19591 /* Set the H bit on BLX instructions. */
19592 if (temp == 1)
19593 {
19594 if (value & 2)
19595 newval |= 0x01000000;
19596 else
19597 newval &= ~0x01000000;
19598 }
2fc8bdac 19599 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 19600 }
c19d1205 19601 break;
a737bd4d 19602
25fe350b
MS
19603 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19604 /* CBZ can only branch forward. */
a737bd4d 19605
738755b0
MS
19606 /* Attempts to use CBZ to branch to the next instruction
19607 (which, strictly speaking, are prohibited) will be turned into
19608 no-ops.
19609
19610 FIXME: It may be better to remove the instruction completely and
19611 perform relaxation. */
19612 if (value == -2)
2fc8bdac
ZW
19613 {
19614 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 19615 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
19616 md_number_to_chars (buf, newval, THUMB_SIZE);
19617 }
738755b0
MS
19618 else
19619 {
19620 if (value & ~0x7e)
19621 as_bad_where (fixP->fx_file, fixP->fx_line,
19622 _("branch out of range"));
19623
19624 if (fixP->fx_done || !seg->use_rela_p)
19625 {
19626 newval = md_chars_to_number (buf, THUMB_SIZE);
19627 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19628 md_number_to_chars (buf, newval, THUMB_SIZE);
19629 }
19630 }
c19d1205 19631 break;
a737bd4d 19632
c19d1205 19633 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
19634 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19635 as_bad_where (fixP->fx_file, fixP->fx_line,
19636 _("branch out of range"));
a737bd4d 19637
2fc8bdac
ZW
19638 if (fixP->fx_done || !seg->use_rela_p)
19639 {
19640 newval = md_chars_to_number (buf, THUMB_SIZE);
19641 newval |= (value & 0x1ff) >> 1;
19642 md_number_to_chars (buf, newval, THUMB_SIZE);
19643 }
c19d1205 19644 break;
a737bd4d 19645
c19d1205 19646 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
19647 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19648 as_bad_where (fixP->fx_file, fixP->fx_line,
19649 _("branch out of range"));
a737bd4d 19650
2fc8bdac
ZW
19651 if (fixP->fx_done || !seg->use_rela_p)
19652 {
19653 newval = md_chars_to_number (buf, THUMB_SIZE);
19654 newval |= (value & 0xfff) >> 1;
19655 md_number_to_chars (buf, newval, THUMB_SIZE);
19656 }
c19d1205 19657 break;
a737bd4d 19658
c19d1205 19659 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
19660 if (fixP->fx_addsy
19661 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19662 && !S_IS_EXTERNAL (fixP->fx_addsy)
19663 && S_IS_DEFINED (fixP->fx_addsy)
19664 && ARM_IS_FUNC (fixP->fx_addsy)
19665 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19666 {
19667 /* Force a relocation for a branch 20 bits wide. */
19668 fixP->fx_done = 0;
19669 }
2fc8bdac
ZW
19670 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19671 as_bad_where (fixP->fx_file, fixP->fx_line,
19672 _("conditional branch out of range"));
404ff6b5 19673
2fc8bdac
ZW
19674 if (fixP->fx_done || !seg->use_rela_p)
19675 {
19676 offsetT newval2;
19677 addressT S, J1, J2, lo, hi;
404ff6b5 19678
2fc8bdac
ZW
19679 S = (value & 0x00100000) >> 20;
19680 J2 = (value & 0x00080000) >> 19;
19681 J1 = (value & 0x00040000) >> 18;
19682 hi = (value & 0x0003f000) >> 12;
19683 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19684
2fc8bdac
ZW
19685 newval = md_chars_to_number (buf, THUMB_SIZE);
19686 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19687 newval |= (S << 10) | hi;
19688 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19689 md_number_to_chars (buf, newval, THUMB_SIZE);
19690 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19691 }
c19d1205 19692 break;
6c43fab6 19693
c19d1205 19694 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
19695
19696 /* If there is a blx from a thumb state function to
19697 another thumb function flip this to a bl and warn
19698 about it. */
19699
19700 if (fixP->fx_addsy
19701 && S_IS_DEFINED (fixP->fx_addsy)
19702 && !S_IS_EXTERNAL (fixP->fx_addsy)
19703 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19704 && THUMB_IS_FUNC (fixP->fx_addsy))
19705 {
19706 const char *name = S_GET_NAME (fixP->fx_addsy);
19707 as_warn_where (fixP->fx_file, fixP->fx_line,
19708 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
19709 name);
19710 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19711 newval = newval | 0x1000;
19712 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19713 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19714 fixP->fx_done = 1;
19715 }
19716
19717
19718 goto thumb_bl_common;
19719
c19d1205 19720 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
19721
19722 /* A bl from Thumb state ISA to an internal ARM state function
19723 is converted to a blx. */
19724 if (fixP->fx_addsy
19725 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19726 && !S_IS_EXTERNAL (fixP->fx_addsy)
19727 && S_IS_DEFINED (fixP->fx_addsy)
19728 && ARM_IS_FUNC (fixP->fx_addsy)
19729 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19730 {
19731 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19732 newval = newval & ~0x1000;
19733 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19734 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
19735 fixP->fx_done = 1;
19736 }
19737
19738 thumb_bl_common:
19739
19740#ifdef OBJ_ELF
19741 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
19742 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19743 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19744#endif
19745
2fc8bdac
ZW
19746 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19747 as_bad_where (fixP->fx_file, fixP->fx_line,
19748 _("branch out of range"));
404ff6b5 19749
2fc8bdac
ZW
19750 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19751 /* For a BLX instruction, make sure that the relocation is rounded up
19752 to a word boundary. This follows the semantics of the instruction
19753 which specifies that bit 1 of the target address will come from bit
19754 1 of the base address. */
19755 value = (value + 1) & ~ 1;
404ff6b5 19756
2fc8bdac 19757 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19758 {
2fc8bdac
ZW
19759 offsetT newval2;
19760
19761 newval = md_chars_to_number (buf, THUMB_SIZE);
19762 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19763 newval |= (value & 0x7fffff) >> 12;
19764 newval2 |= (value & 0xfff) >> 1;
19765 md_number_to_chars (buf, newval, THUMB_SIZE);
19766 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 19767 }
c19d1205 19768 break;
404ff6b5 19769
c19d1205 19770 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
19771 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19772 as_bad_where (fixP->fx_file, fixP->fx_line,
19773 _("branch out of range"));
6c43fab6 19774
2fc8bdac
ZW
19775 if (fixP->fx_done || !seg->use_rela_p)
19776 {
19777 offsetT newval2;
19778 addressT S, I1, I2, lo, hi;
6c43fab6 19779
2fc8bdac
ZW
19780 S = (value & 0x01000000) >> 24;
19781 I1 = (value & 0x00800000) >> 23;
19782 I2 = (value & 0x00400000) >> 22;
19783 hi = (value & 0x003ff000) >> 12;
19784 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19785
2fc8bdac
ZW
19786 I1 = !(I1 ^ S);
19787 I2 = !(I2 ^ S);
a737bd4d 19788
2fc8bdac
ZW
19789 newval = md_chars_to_number (buf, THUMB_SIZE);
19790 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19791 newval |= (S << 10) | hi;
19792 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19793 md_number_to_chars (buf, newval, THUMB_SIZE);
19794 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19795 }
19796 break;
a737bd4d 19797
2fc8bdac
ZW
19798 case BFD_RELOC_8:
19799 if (fixP->fx_done || !seg->use_rela_p)
19800 md_number_to_chars (buf, value, 1);
c19d1205 19801 break;
a737bd4d 19802
c19d1205 19803 case BFD_RELOC_16:
2fc8bdac 19804 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19805 md_number_to_chars (buf, value, 2);
c19d1205 19806 break;
a737bd4d 19807
c19d1205
ZW
19808#ifdef OBJ_ELF
19809 case BFD_RELOC_ARM_TLS_GD32:
19810 case BFD_RELOC_ARM_TLS_LE32:
19811 case BFD_RELOC_ARM_TLS_IE32:
19812 case BFD_RELOC_ARM_TLS_LDM32:
19813 case BFD_RELOC_ARM_TLS_LDO32:
19814 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19815 /* fall through */
6c43fab6 19816
c19d1205
ZW
19817 case BFD_RELOC_ARM_GOT32:
19818 case BFD_RELOC_ARM_GOTOFF:
19819 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
19820 if (fixP->fx_done || !seg->use_rela_p)
19821 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
19822 break;
19823#endif
6c43fab6 19824
c19d1205
ZW
19825 case BFD_RELOC_RVA:
19826 case BFD_RELOC_32:
19827 case BFD_RELOC_ARM_TARGET1:
19828 case BFD_RELOC_ARM_ROSEGREL32:
19829 case BFD_RELOC_ARM_SBREL32:
19830 case BFD_RELOC_32_PCREL:
f0927246
NC
19831#ifdef TE_PE
19832 case BFD_RELOC_32_SECREL:
19833#endif
2fc8bdac 19834 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
19835#ifdef TE_WINCE
19836 /* For WinCE we only do this for pcrel fixups. */
19837 if (fixP->fx_done || fixP->fx_pcrel)
19838#endif
19839 md_number_to_chars (buf, value, 4);
c19d1205 19840 break;
6c43fab6 19841
c19d1205
ZW
19842#ifdef OBJ_ELF
19843 case BFD_RELOC_ARM_PREL31:
2fc8bdac 19844 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
19845 {
19846 newval = md_chars_to_number (buf, 4) & 0x80000000;
19847 if ((value ^ (value >> 1)) & 0x40000000)
19848 {
19849 as_bad_where (fixP->fx_file, fixP->fx_line,
19850 _("rel31 relocation overflow"));
19851 }
19852 newval |= value & 0x7fffffff;
19853 md_number_to_chars (buf, newval, 4);
19854 }
19855 break;
c19d1205 19856#endif
a737bd4d 19857
c19d1205 19858 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 19859 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
19860 if (value < -1023 || value > 1023 || (value & 3))
19861 as_bad_where (fixP->fx_file, fixP->fx_line,
19862 _("co-processor offset out of range"));
19863 cp_off_common:
19864 sign = value >= 0;
19865 if (value < 0)
19866 value = -value;
8f06b2d8
PB
19867 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19868 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19869 newval = md_chars_to_number (buf, INSN_SIZE);
19870 else
19871 newval = get_thumb32_insn (buf);
19872 newval &= 0xff7fff00;
c19d1205 19873 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
19874 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19875 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19876 md_number_to_chars (buf, newval, INSN_SIZE);
19877 else
19878 put_thumb32_insn (buf, newval);
c19d1205 19879 break;
a737bd4d 19880
c19d1205 19881 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 19882 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
19883 if (value < -255 || value > 255)
19884 as_bad_where (fixP->fx_file, fixP->fx_line,
19885 _("co-processor offset out of range"));
df7849c5 19886 value *= 4;
c19d1205 19887 goto cp_off_common;
6c43fab6 19888
c19d1205
ZW
19889 case BFD_RELOC_ARM_THUMB_OFFSET:
19890 newval = md_chars_to_number (buf, THUMB_SIZE);
19891 /* Exactly what ranges, and where the offset is inserted depends
19892 on the type of instruction, we can establish this from the
19893 top 4 bits. */
19894 switch (newval >> 12)
19895 {
19896 case 4: /* PC load. */
19897 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19898 forced to zero for these loads; md_pcrel_from has already
19899 compensated for this. */
19900 if (value & 3)
19901 as_bad_where (fixP->fx_file, fixP->fx_line,
19902 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
19903 (((unsigned long) fixP->fx_frag->fr_address
19904 + (unsigned long) fixP->fx_where) & ~3)
19905 + (unsigned long) value);
a737bd4d 19906
c19d1205
ZW
19907 if (value & ~0x3fc)
19908 as_bad_where (fixP->fx_file, fixP->fx_line,
19909 _("invalid offset, value too big (0x%08lX)"),
19910 (long) value);
a737bd4d 19911
c19d1205
ZW
19912 newval |= value >> 2;
19913 break;
a737bd4d 19914
c19d1205
ZW
19915 case 9: /* SP load/store. */
19916 if (value & ~0x3fc)
19917 as_bad_where (fixP->fx_file, fixP->fx_line,
19918 _("invalid offset, value too big (0x%08lX)"),
19919 (long) value);
19920 newval |= value >> 2;
19921 break;
6c43fab6 19922
c19d1205
ZW
19923 case 6: /* Word load/store. */
19924 if (value & ~0x7c)
19925 as_bad_where (fixP->fx_file, fixP->fx_line,
19926 _("invalid offset, value too big (0x%08lX)"),
19927 (long) value);
19928 newval |= value << 4; /* 6 - 2. */
19929 break;
a737bd4d 19930
c19d1205
ZW
19931 case 7: /* Byte load/store. */
19932 if (value & ~0x1f)
19933 as_bad_where (fixP->fx_file, fixP->fx_line,
19934 _("invalid offset, value too big (0x%08lX)"),
19935 (long) value);
19936 newval |= value << 6;
19937 break;
a737bd4d 19938
c19d1205
ZW
19939 case 8: /* Halfword load/store. */
19940 if (value & ~0x3e)
19941 as_bad_where (fixP->fx_file, fixP->fx_line,
19942 _("invalid offset, value too big (0x%08lX)"),
19943 (long) value);
19944 newval |= value << 5; /* 6 - 1. */
19945 break;
a737bd4d 19946
c19d1205
ZW
19947 default:
19948 as_bad_where (fixP->fx_file, fixP->fx_line,
19949 "Unable to process relocation for thumb opcode: %lx",
19950 (unsigned long) newval);
19951 break;
19952 }
19953 md_number_to_chars (buf, newval, THUMB_SIZE);
19954 break;
a737bd4d 19955
c19d1205
ZW
19956 case BFD_RELOC_ARM_THUMB_ADD:
19957 /* This is a complicated relocation, since we use it for all of
19958 the following immediate relocations:
a737bd4d 19959
c19d1205
ZW
19960 3bit ADD/SUB
19961 8bit ADD/SUB
19962 9bit ADD/SUB SP word-aligned
19963 10bit ADD PC/SP word-aligned
a737bd4d 19964
c19d1205
ZW
19965 The type of instruction being processed is encoded in the
19966 instruction field:
a737bd4d 19967
c19d1205
ZW
19968 0x8000 SUB
19969 0x00F0 Rd
19970 0x000F Rs
19971 */
19972 newval = md_chars_to_number (buf, THUMB_SIZE);
19973 {
19974 int rd = (newval >> 4) & 0xf;
19975 int rs = newval & 0xf;
19976 int subtract = !!(newval & 0x8000);
a737bd4d 19977
c19d1205
ZW
19978 /* Check for HI regs, only very restricted cases allowed:
19979 Adjusting SP, and using PC or SP to get an address. */
19980 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19981 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19982 as_bad_where (fixP->fx_file, fixP->fx_line,
19983 _("invalid Hi register with immediate"));
a737bd4d 19984
c19d1205
ZW
19985 /* If value is negative, choose the opposite instruction. */
19986 if (value < 0)
19987 {
19988 value = -value;
19989 subtract = !subtract;
19990 if (value < 0)
19991 as_bad_where (fixP->fx_file, fixP->fx_line,
19992 _("immediate value out of range"));
19993 }
a737bd4d 19994
c19d1205
ZW
19995 if (rd == REG_SP)
19996 {
19997 if (value & ~0x1fc)
19998 as_bad_where (fixP->fx_file, fixP->fx_line,
19999 _("invalid immediate for stack address calculation"));
20000 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20001 newval |= value >> 2;
20002 }
20003 else if (rs == REG_PC || rs == REG_SP)
20004 {
20005 if (subtract || value & ~0x3fc)
20006 as_bad_where (fixP->fx_file, fixP->fx_line,
20007 _("invalid immediate for address calculation (value = 0x%08lX)"),
20008 (unsigned long) value);
20009 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20010 newval |= rd << 8;
20011 newval |= value >> 2;
20012 }
20013 else if (rs == rd)
20014 {
20015 if (value & ~0xff)
20016 as_bad_where (fixP->fx_file, fixP->fx_line,
20017 _("immediate value out of range"));
20018 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20019 newval |= (rd << 8) | value;
20020 }
20021 else
20022 {
20023 if (value & ~0x7)
20024 as_bad_where (fixP->fx_file, fixP->fx_line,
20025 _("immediate value out of range"));
20026 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20027 newval |= rd | (rs << 3) | (value << 6);
20028 }
20029 }
20030 md_number_to_chars (buf, newval, THUMB_SIZE);
20031 break;
a737bd4d 20032
c19d1205
ZW
20033 case BFD_RELOC_ARM_THUMB_IMM:
20034 newval = md_chars_to_number (buf, THUMB_SIZE);
20035 if (value < 0 || value > 255)
20036 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20037 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20038 (long) value);
20039 newval |= value;
20040 md_number_to_chars (buf, newval, THUMB_SIZE);
20041 break;
a737bd4d 20042
c19d1205
ZW
20043 case BFD_RELOC_ARM_THUMB_SHIFT:
20044 /* 5bit shift value (0..32). LSL cannot take 32. */
20045 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20046 temp = newval & 0xf800;
20047 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20048 as_bad_where (fixP->fx_file, fixP->fx_line,
20049 _("invalid shift value: %ld"), (long) value);
20050 /* Shifts of zero must be encoded as LSL. */
20051 if (value == 0)
20052 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20053 /* Shifts of 32 are encoded as zero. */
20054 else if (value == 32)
20055 value = 0;
20056 newval |= value << 6;
20057 md_number_to_chars (buf, newval, THUMB_SIZE);
20058 break;
a737bd4d 20059
c19d1205
ZW
20060 case BFD_RELOC_VTABLE_INHERIT:
20061 case BFD_RELOC_VTABLE_ENTRY:
20062 fixP->fx_done = 0;
20063 return;
6c43fab6 20064
b6895b4f
PB
20065 case BFD_RELOC_ARM_MOVW:
20066 case BFD_RELOC_ARM_MOVT:
20067 case BFD_RELOC_ARM_THUMB_MOVW:
20068 case BFD_RELOC_ARM_THUMB_MOVT:
20069 if (fixP->fx_done || !seg->use_rela_p)
20070 {
20071 /* REL format relocations are limited to a 16-bit addend. */
20072 if (!fixP->fx_done)
20073 {
39623e12 20074 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20075 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20076 _("offset out of range"));
b6895b4f
PB
20077 }
20078 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20079 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20080 {
20081 value >>= 16;
20082 }
20083
20084 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20085 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20086 {
20087 newval = get_thumb32_insn (buf);
20088 newval &= 0xfbf08f00;
20089 newval |= (value & 0xf000) << 4;
20090 newval |= (value & 0x0800) << 15;
20091 newval |= (value & 0x0700) << 4;
20092 newval |= (value & 0x00ff);
20093 put_thumb32_insn (buf, newval);
20094 }
20095 else
20096 {
20097 newval = md_chars_to_number (buf, 4);
20098 newval &= 0xfff0f000;
20099 newval |= value & 0x0fff;
20100 newval |= (value & 0xf000) << 4;
20101 md_number_to_chars (buf, newval, 4);
20102 }
20103 }
20104 return;
20105
4962c51a
MS
20106 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20107 case BFD_RELOC_ARM_ALU_PC_G0:
20108 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20109 case BFD_RELOC_ARM_ALU_PC_G1:
20110 case BFD_RELOC_ARM_ALU_PC_G2:
20111 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20112 case BFD_RELOC_ARM_ALU_SB_G0:
20113 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20114 case BFD_RELOC_ARM_ALU_SB_G1:
20115 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20116 gas_assert (!fixP->fx_done);
4962c51a
MS
20117 if (!seg->use_rela_p)
20118 {
20119 bfd_vma insn;
20120 bfd_vma encoded_addend;
20121 bfd_vma addend_abs = abs (value);
20122
20123 /* Check that the absolute value of the addend can be
20124 expressed as an 8-bit constant plus a rotation. */
20125 encoded_addend = encode_arm_immediate (addend_abs);
20126 if (encoded_addend == (unsigned int) FAIL)
20127 as_bad_where (fixP->fx_file, fixP->fx_line,
20128 _("the offset 0x%08lX is not representable"),
495bde8e 20129 (unsigned long) addend_abs);
4962c51a
MS
20130
20131 /* Extract the instruction. */
20132 insn = md_chars_to_number (buf, INSN_SIZE);
20133
20134 /* If the addend is positive, use an ADD instruction.
20135 Otherwise use a SUB. Take care not to destroy the S bit. */
20136 insn &= 0xff1fffff;
20137 if (value < 0)
20138 insn |= 1 << 22;
20139 else
20140 insn |= 1 << 23;
20141
20142 /* Place the encoded addend into the first 12 bits of the
20143 instruction. */
20144 insn &= 0xfffff000;
20145 insn |= encoded_addend;
5f4273c7
NC
20146
20147 /* Update the instruction. */
4962c51a
MS
20148 md_number_to_chars (buf, insn, INSN_SIZE);
20149 }
20150 break;
20151
20152 case BFD_RELOC_ARM_LDR_PC_G0:
20153 case BFD_RELOC_ARM_LDR_PC_G1:
20154 case BFD_RELOC_ARM_LDR_PC_G2:
20155 case BFD_RELOC_ARM_LDR_SB_G0:
20156 case BFD_RELOC_ARM_LDR_SB_G1:
20157 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20158 gas_assert (!fixP->fx_done);
4962c51a
MS
20159 if (!seg->use_rela_p)
20160 {
20161 bfd_vma insn;
20162 bfd_vma addend_abs = abs (value);
20163
20164 /* Check that the absolute value of the addend can be
20165 encoded in 12 bits. */
20166 if (addend_abs >= 0x1000)
20167 as_bad_where (fixP->fx_file, fixP->fx_line,
20168 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20169 (unsigned long) addend_abs);
4962c51a
MS
20170
20171 /* Extract the instruction. */
20172 insn = md_chars_to_number (buf, INSN_SIZE);
20173
20174 /* If the addend is negative, clear bit 23 of the instruction.
20175 Otherwise set it. */
20176 if (value < 0)
20177 insn &= ~(1 << 23);
20178 else
20179 insn |= 1 << 23;
20180
20181 /* Place the absolute value of the addend into the first 12 bits
20182 of the instruction. */
20183 insn &= 0xfffff000;
20184 insn |= addend_abs;
5f4273c7
NC
20185
20186 /* Update the instruction. */
4962c51a
MS
20187 md_number_to_chars (buf, insn, INSN_SIZE);
20188 }
20189 break;
20190
20191 case BFD_RELOC_ARM_LDRS_PC_G0:
20192 case BFD_RELOC_ARM_LDRS_PC_G1:
20193 case BFD_RELOC_ARM_LDRS_PC_G2:
20194 case BFD_RELOC_ARM_LDRS_SB_G0:
20195 case BFD_RELOC_ARM_LDRS_SB_G1:
20196 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20197 gas_assert (!fixP->fx_done);
4962c51a
MS
20198 if (!seg->use_rela_p)
20199 {
20200 bfd_vma insn;
20201 bfd_vma addend_abs = abs (value);
20202
20203 /* Check that the absolute value of the addend can be
20204 encoded in 8 bits. */
20205 if (addend_abs >= 0x100)
20206 as_bad_where (fixP->fx_file, fixP->fx_line,
20207 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20208 (unsigned long) addend_abs);
4962c51a
MS
20209
20210 /* Extract the instruction. */
20211 insn = md_chars_to_number (buf, INSN_SIZE);
20212
20213 /* If the addend is negative, clear bit 23 of the instruction.
20214 Otherwise set it. */
20215 if (value < 0)
20216 insn &= ~(1 << 23);
20217 else
20218 insn |= 1 << 23;
20219
20220 /* Place the first four bits of the absolute value of the addend
20221 into the first 4 bits of the instruction, and the remaining
20222 four into bits 8 .. 11. */
20223 insn &= 0xfffff0f0;
20224 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20225
20226 /* Update the instruction. */
4962c51a
MS
20227 md_number_to_chars (buf, insn, INSN_SIZE);
20228 }
20229 break;
20230
20231 case BFD_RELOC_ARM_LDC_PC_G0:
20232 case BFD_RELOC_ARM_LDC_PC_G1:
20233 case BFD_RELOC_ARM_LDC_PC_G2:
20234 case BFD_RELOC_ARM_LDC_SB_G0:
20235 case BFD_RELOC_ARM_LDC_SB_G1:
20236 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20237 gas_assert (!fixP->fx_done);
4962c51a
MS
20238 if (!seg->use_rela_p)
20239 {
20240 bfd_vma insn;
20241 bfd_vma addend_abs = abs (value);
20242
20243 /* Check that the absolute value of the addend is a multiple of
20244 four and, when divided by four, fits in 8 bits. */
20245 if (addend_abs & 0x3)
20246 as_bad_where (fixP->fx_file, fixP->fx_line,
20247 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20248 (unsigned long) addend_abs);
4962c51a
MS
20249
20250 if ((addend_abs >> 2) > 0xff)
20251 as_bad_where (fixP->fx_file, fixP->fx_line,
20252 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20253 (unsigned long) addend_abs);
4962c51a
MS
20254
20255 /* Extract the instruction. */
20256 insn = md_chars_to_number (buf, INSN_SIZE);
20257
20258 /* If the addend is negative, clear bit 23 of the instruction.
20259 Otherwise set it. */
20260 if (value < 0)
20261 insn &= ~(1 << 23);
20262 else
20263 insn |= 1 << 23;
20264
20265 /* Place the addend (divided by four) into the first eight
20266 bits of the instruction. */
20267 insn &= 0xfffffff0;
20268 insn |= addend_abs >> 2;
5f4273c7
NC
20269
20270 /* Update the instruction. */
4962c51a
MS
20271 md_number_to_chars (buf, insn, INSN_SIZE);
20272 }
20273 break;
20274
845b51d6
PB
20275 case BFD_RELOC_ARM_V4BX:
20276 /* This will need to go in the object file. */
20277 fixP->fx_done = 0;
20278 break;
20279
c19d1205
ZW
20280 case BFD_RELOC_UNUSED:
20281 default:
20282 as_bad_where (fixP->fx_file, fixP->fx_line,
20283 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20284 }
6c43fab6
RE
20285}
20286
c19d1205
ZW
20287/* Translate internal representation of relocation info to BFD target
20288 format. */
a737bd4d 20289
c19d1205 20290arelent *
00a97672 20291tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20292{
c19d1205
ZW
20293 arelent * reloc;
20294 bfd_reloc_code_real_type code;
a737bd4d 20295
c19d1205 20296 reloc = xmalloc (sizeof (arelent));
a737bd4d 20297
c19d1205
ZW
20298 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
20299 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20300 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20301
2fc8bdac 20302 if (fixp->fx_pcrel)
00a97672
RS
20303 {
20304 if (section->use_rela_p)
20305 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20306 else
20307 fixp->fx_offset = reloc->address;
20308 }
c19d1205 20309 reloc->addend = fixp->fx_offset;
a737bd4d 20310
c19d1205 20311 switch (fixp->fx_r_type)
a737bd4d 20312 {
c19d1205
ZW
20313 case BFD_RELOC_8:
20314 if (fixp->fx_pcrel)
20315 {
20316 code = BFD_RELOC_8_PCREL;
20317 break;
20318 }
a737bd4d 20319
c19d1205
ZW
20320 case BFD_RELOC_16:
20321 if (fixp->fx_pcrel)
20322 {
20323 code = BFD_RELOC_16_PCREL;
20324 break;
20325 }
6c43fab6 20326
c19d1205
ZW
20327 case BFD_RELOC_32:
20328 if (fixp->fx_pcrel)
20329 {
20330 code = BFD_RELOC_32_PCREL;
20331 break;
20332 }
a737bd4d 20333
b6895b4f
PB
20334 case BFD_RELOC_ARM_MOVW:
20335 if (fixp->fx_pcrel)
20336 {
20337 code = BFD_RELOC_ARM_MOVW_PCREL;
20338 break;
20339 }
20340
20341 case BFD_RELOC_ARM_MOVT:
20342 if (fixp->fx_pcrel)
20343 {
20344 code = BFD_RELOC_ARM_MOVT_PCREL;
20345 break;
20346 }
20347
20348 case BFD_RELOC_ARM_THUMB_MOVW:
20349 if (fixp->fx_pcrel)
20350 {
20351 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20352 break;
20353 }
20354
20355 case BFD_RELOC_ARM_THUMB_MOVT:
20356 if (fixp->fx_pcrel)
20357 {
20358 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20359 break;
20360 }
20361
c19d1205
ZW
20362 case BFD_RELOC_NONE:
20363 case BFD_RELOC_ARM_PCREL_BRANCH:
20364 case BFD_RELOC_ARM_PCREL_BLX:
20365 case BFD_RELOC_RVA:
20366 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20367 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20368 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20369 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20370 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20371 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
20372 case BFD_RELOC_VTABLE_ENTRY:
20373 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
20374#ifdef TE_PE
20375 case BFD_RELOC_32_SECREL:
20376#endif
c19d1205
ZW
20377 code = fixp->fx_r_type;
20378 break;
a737bd4d 20379
00adf2d4
JB
20380 case BFD_RELOC_THUMB_PCREL_BLX:
20381#ifdef OBJ_ELF
20382 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20383 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
20384 else
20385#endif
20386 code = BFD_RELOC_THUMB_PCREL_BLX;
20387 break;
20388
c19d1205
ZW
20389 case BFD_RELOC_ARM_LITERAL:
20390 case BFD_RELOC_ARM_HWLITERAL:
20391 /* If this is called then the a literal has
20392 been referenced across a section boundary. */
20393 as_bad_where (fixp->fx_file, fixp->fx_line,
20394 _("literal referenced across section boundary"));
20395 return NULL;
a737bd4d 20396
c19d1205
ZW
20397#ifdef OBJ_ELF
20398 case BFD_RELOC_ARM_GOT32:
20399 case BFD_RELOC_ARM_GOTOFF:
20400 case BFD_RELOC_ARM_PLT32:
20401 case BFD_RELOC_ARM_TARGET1:
20402 case BFD_RELOC_ARM_ROSEGREL32:
20403 case BFD_RELOC_ARM_SBREL32:
20404 case BFD_RELOC_ARM_PREL31:
20405 case BFD_RELOC_ARM_TARGET2:
20406 case BFD_RELOC_ARM_TLS_LE32:
20407 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
20408 case BFD_RELOC_ARM_PCREL_CALL:
20409 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
20410 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20411 case BFD_RELOC_ARM_ALU_PC_G0:
20412 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20413 case BFD_RELOC_ARM_ALU_PC_G1:
20414 case BFD_RELOC_ARM_ALU_PC_G2:
20415 case BFD_RELOC_ARM_LDR_PC_G0:
20416 case BFD_RELOC_ARM_LDR_PC_G1:
20417 case BFD_RELOC_ARM_LDR_PC_G2:
20418 case BFD_RELOC_ARM_LDRS_PC_G0:
20419 case BFD_RELOC_ARM_LDRS_PC_G1:
20420 case BFD_RELOC_ARM_LDRS_PC_G2:
20421 case BFD_RELOC_ARM_LDC_PC_G0:
20422 case BFD_RELOC_ARM_LDC_PC_G1:
20423 case BFD_RELOC_ARM_LDC_PC_G2:
20424 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20425 case BFD_RELOC_ARM_ALU_SB_G0:
20426 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20427 case BFD_RELOC_ARM_ALU_SB_G1:
20428 case BFD_RELOC_ARM_ALU_SB_G2:
20429 case BFD_RELOC_ARM_LDR_SB_G0:
20430 case BFD_RELOC_ARM_LDR_SB_G1:
20431 case BFD_RELOC_ARM_LDR_SB_G2:
20432 case BFD_RELOC_ARM_LDRS_SB_G0:
20433 case BFD_RELOC_ARM_LDRS_SB_G1:
20434 case BFD_RELOC_ARM_LDRS_SB_G2:
20435 case BFD_RELOC_ARM_LDC_SB_G0:
20436 case BFD_RELOC_ARM_LDC_SB_G1:
20437 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 20438 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
20439 code = fixp->fx_r_type;
20440 break;
a737bd4d 20441
c19d1205
ZW
20442 case BFD_RELOC_ARM_TLS_GD32:
20443 case BFD_RELOC_ARM_TLS_IE32:
20444 case BFD_RELOC_ARM_TLS_LDM32:
20445 /* BFD will include the symbol's address in the addend.
20446 But we don't want that, so subtract it out again here. */
20447 if (!S_IS_COMMON (fixp->fx_addsy))
20448 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
20449 code = fixp->fx_r_type;
20450 break;
20451#endif
a737bd4d 20452
c19d1205
ZW
20453 case BFD_RELOC_ARM_IMMEDIATE:
20454 as_bad_where (fixp->fx_file, fixp->fx_line,
20455 _("internal relocation (type: IMMEDIATE) not fixed up"));
20456 return NULL;
a737bd4d 20457
c19d1205
ZW
20458 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20459 as_bad_where (fixp->fx_file, fixp->fx_line,
20460 _("ADRL used for a symbol not defined in the same file"));
20461 return NULL;
a737bd4d 20462
c19d1205 20463 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20464 if (section->use_rela_p)
20465 {
20466 code = fixp->fx_r_type;
20467 break;
20468 }
20469
c19d1205
ZW
20470 if (fixp->fx_addsy != NULL
20471 && !S_IS_DEFINED (fixp->fx_addsy)
20472 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 20473 {
c19d1205
ZW
20474 as_bad_where (fixp->fx_file, fixp->fx_line,
20475 _("undefined local label `%s'"),
20476 S_GET_NAME (fixp->fx_addsy));
20477 return NULL;
a737bd4d
NC
20478 }
20479
c19d1205
ZW
20480 as_bad_where (fixp->fx_file, fixp->fx_line,
20481 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
20482 return NULL;
a737bd4d 20483
c19d1205
ZW
20484 default:
20485 {
20486 char * type;
6c43fab6 20487
c19d1205
ZW
20488 switch (fixp->fx_r_type)
20489 {
20490 case BFD_RELOC_NONE: type = "NONE"; break;
20491 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
20492 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 20493 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
20494 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
20495 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
20496 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 20497 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
20498 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
20499 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
20500 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
20501 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
20502 default: type = _("<unknown>"); break;
20503 }
20504 as_bad_where (fixp->fx_file, fixp->fx_line,
20505 _("cannot represent %s relocation in this object file format"),
20506 type);
20507 return NULL;
20508 }
a737bd4d 20509 }
6c43fab6 20510
c19d1205
ZW
20511#ifdef OBJ_ELF
20512 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
20513 && GOT_symbol
20514 && fixp->fx_addsy == GOT_symbol)
20515 {
20516 code = BFD_RELOC_ARM_GOTPC;
20517 reloc->addend = fixp->fx_offset = reloc->address;
20518 }
20519#endif
6c43fab6 20520
c19d1205 20521 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 20522
c19d1205
ZW
20523 if (reloc->howto == NULL)
20524 {
20525 as_bad_where (fixp->fx_file, fixp->fx_line,
20526 _("cannot represent %s relocation in this object file format"),
20527 bfd_get_reloc_code_name (code));
20528 return NULL;
20529 }
6c43fab6 20530
c19d1205
ZW
20531 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
20532 vtable entry to be used in the relocation's section offset. */
20533 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20534 reloc->address = fixp->fx_offset;
6c43fab6 20535
c19d1205 20536 return reloc;
6c43fab6
RE
20537}
20538
c19d1205 20539/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 20540
c19d1205
ZW
20541void
20542cons_fix_new_arm (fragS * frag,
20543 int where,
20544 int size,
20545 expressionS * exp)
6c43fab6 20546{
c19d1205
ZW
20547 bfd_reloc_code_real_type type;
20548 int pcrel = 0;
6c43fab6 20549
c19d1205
ZW
20550 /* Pick a reloc.
20551 FIXME: @@ Should look at CPU word size. */
20552 switch (size)
20553 {
20554 case 1:
20555 type = BFD_RELOC_8;
20556 break;
20557 case 2:
20558 type = BFD_RELOC_16;
20559 break;
20560 case 4:
20561 default:
20562 type = BFD_RELOC_32;
20563 break;
20564 case 8:
20565 type = BFD_RELOC_64;
20566 break;
20567 }
6c43fab6 20568
f0927246
NC
20569#ifdef TE_PE
20570 if (exp->X_op == O_secrel)
20571 {
20572 exp->X_op = O_symbol;
20573 type = BFD_RELOC_32_SECREL;
20574 }
20575#endif
20576
c19d1205
ZW
20577 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
20578}
6c43fab6 20579
4343666d 20580#if defined (OBJ_COFF)
c19d1205
ZW
20581void
20582arm_validate_fix (fixS * fixP)
6c43fab6 20583{
c19d1205
ZW
20584 /* If the destination of the branch is a defined symbol which does not have
20585 the THUMB_FUNC attribute, then we must be calling a function which has
20586 the (interfacearm) attribute. We look for the Thumb entry point to that
20587 function and change the branch to refer to that function instead. */
20588 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
20589 && fixP->fx_addsy != NULL
20590 && S_IS_DEFINED (fixP->fx_addsy)
20591 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 20592 {
c19d1205 20593 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 20594 }
c19d1205
ZW
20595}
20596#endif
6c43fab6 20597
267bf995 20598
c19d1205
ZW
20599int
20600arm_force_relocation (struct fix * fixp)
20601{
20602#if defined (OBJ_COFF) && defined (TE_PE)
20603 if (fixp->fx_r_type == BFD_RELOC_RVA)
20604 return 1;
20605#endif
6c43fab6 20606
267bf995
RR
20607 /* In case we have a call or a branch to a function in ARM ISA mode from
20608 a thumb function or vice-versa force the relocation. These relocations
20609 are cleared off for some cores that might have blx and simple transformations
20610 are possible. */
20611
20612#ifdef OBJ_ELF
20613 switch (fixp->fx_r_type)
20614 {
20615 case BFD_RELOC_ARM_PCREL_JUMP:
20616 case BFD_RELOC_ARM_PCREL_CALL:
20617 case BFD_RELOC_THUMB_PCREL_BLX:
20618 if (THUMB_IS_FUNC (fixp->fx_addsy))
20619 return 1;
20620 break;
20621
20622 case BFD_RELOC_ARM_PCREL_BLX:
20623 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20624 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20625 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20626 if (ARM_IS_FUNC (fixp->fx_addsy))
20627 return 1;
20628 break;
20629
20630 default:
20631 break;
20632 }
20633#endif
20634
c19d1205
ZW
20635 /* Resolve these relocations even if the symbol is extern or weak. */
20636 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
20637 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 20638 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 20639 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
20640 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20641 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
20642 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 20643 return 0;
a737bd4d 20644
4962c51a
MS
20645 /* Always leave these relocations for the linker. */
20646 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20647 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20648 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20649 return 1;
20650
f0291e4c
PB
20651 /* Always generate relocations against function symbols. */
20652 if (fixp->fx_r_type == BFD_RELOC_32
20653 && fixp->fx_addsy
20654 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
20655 return 1;
20656
c19d1205 20657 return generic_force_reloc (fixp);
404ff6b5
AH
20658}
20659
0ffdc86c 20660#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
20661/* Relocations against function names must be left unadjusted,
20662 so that the linker can use this information to generate interworking
20663 stubs. The MIPS version of this function
c19d1205
ZW
20664 also prevents relocations that are mips-16 specific, but I do not
20665 know why it does this.
404ff6b5 20666
c19d1205
ZW
20667 FIXME:
20668 There is one other problem that ought to be addressed here, but
20669 which currently is not: Taking the address of a label (rather
20670 than a function) and then later jumping to that address. Such
20671 addresses also ought to have their bottom bit set (assuming that
20672 they reside in Thumb code), but at the moment they will not. */
404ff6b5 20673
c19d1205
ZW
20674bfd_boolean
20675arm_fix_adjustable (fixS * fixP)
404ff6b5 20676{
c19d1205
ZW
20677 if (fixP->fx_addsy == NULL)
20678 return 1;
404ff6b5 20679
e28387c3
PB
20680 /* Preserve relocations against symbols with function type. */
20681 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20682 return 0;
20683
c19d1205
ZW
20684 if (THUMB_IS_FUNC (fixP->fx_addsy)
20685 && fixP->fx_subsy == NULL)
20686 return 0;
a737bd4d 20687
c19d1205
ZW
20688 /* We need the symbol name for the VTABLE entries. */
20689 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20690 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20691 return 0;
404ff6b5 20692
c19d1205
ZW
20693 /* Don't allow symbols to be discarded on GOT related relocs. */
20694 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20695 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20696 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20697 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20698 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20699 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20700 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20701 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20702 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20703 return 0;
a737bd4d 20704
4962c51a
MS
20705 /* Similarly for group relocations. */
20706 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20707 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20708 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20709 return 0;
20710
79947c54
CD
20711 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20712 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20713 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20714 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20715 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20716 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20717 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20718 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20719 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20720 return 0;
20721
c19d1205 20722 return 1;
a737bd4d 20723}
0ffdc86c
NC
20724#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20725
20726#ifdef OBJ_ELF
404ff6b5 20727
c19d1205
ZW
20728const char *
20729elf32_arm_target_format (void)
404ff6b5 20730{
c19d1205
ZW
20731#ifdef TE_SYMBIAN
20732 return (target_big_endian
20733 ? "elf32-bigarm-symbian"
20734 : "elf32-littlearm-symbian");
20735#elif defined (TE_VXWORKS)
20736 return (target_big_endian
20737 ? "elf32-bigarm-vxworks"
20738 : "elf32-littlearm-vxworks");
20739#else
20740 if (target_big_endian)
20741 return "elf32-bigarm";
20742 else
20743 return "elf32-littlearm";
20744#endif
404ff6b5
AH
20745}
20746
c19d1205
ZW
20747void
20748armelf_frob_symbol (symbolS * symp,
20749 int * puntp)
404ff6b5 20750{
c19d1205
ZW
20751 elf_frob_symbol (symp, puntp);
20752}
20753#endif
404ff6b5 20754
c19d1205 20755/* MD interface: Finalization. */
a737bd4d 20756
c19d1205
ZW
20757void
20758arm_cleanup (void)
20759{
20760 literal_pool * pool;
a737bd4d 20761
e07e6e58
NC
20762 /* Ensure that all the IT blocks are properly closed. */
20763 check_it_blocks_finished ();
20764
c19d1205
ZW
20765 for (pool = list_of_pools; pool; pool = pool->next)
20766 {
5f4273c7 20767 /* Put it at the end of the relevant section. */
c19d1205
ZW
20768 subseg_set (pool->section, pool->sub_section);
20769#ifdef OBJ_ELF
20770 arm_elf_change_section ();
20771#endif
20772 s_ltorg (0);
20773 }
404ff6b5
AH
20774}
20775
c19d1205
ZW
20776/* Adjust the symbol table. This marks Thumb symbols as distinct from
20777 ARM ones. */
404ff6b5 20778
c19d1205
ZW
20779void
20780arm_adjust_symtab (void)
404ff6b5 20781{
c19d1205
ZW
20782#ifdef OBJ_COFF
20783 symbolS * sym;
404ff6b5 20784
c19d1205
ZW
20785 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20786 {
20787 if (ARM_IS_THUMB (sym))
20788 {
20789 if (THUMB_IS_FUNC (sym))
20790 {
20791 /* Mark the symbol as a Thumb function. */
20792 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20793 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20794 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 20795
c19d1205
ZW
20796 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20797 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20798 else
20799 as_bad (_("%s: unexpected function type: %d"),
20800 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20801 }
20802 else switch (S_GET_STORAGE_CLASS (sym))
20803 {
20804 case C_EXT:
20805 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20806 break;
20807 case C_STAT:
20808 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20809 break;
20810 case C_LABEL:
20811 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20812 break;
20813 default:
20814 /* Do nothing. */
20815 break;
20816 }
20817 }
a737bd4d 20818
c19d1205
ZW
20819 if (ARM_IS_INTERWORK (sym))
20820 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 20821 }
c19d1205
ZW
20822#endif
20823#ifdef OBJ_ELF
20824 symbolS * sym;
20825 char bind;
404ff6b5 20826
c19d1205 20827 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 20828 {
c19d1205
ZW
20829 if (ARM_IS_THUMB (sym))
20830 {
20831 elf_symbol_type * elf_sym;
404ff6b5 20832
c19d1205
ZW
20833 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20834 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 20835
b0796911
PB
20836 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20837 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
20838 {
20839 /* If it's a .thumb_func, declare it as so,
20840 otherwise tag label as .code 16. */
20841 if (THUMB_IS_FUNC (sym))
20842 elf_sym->internal_elf_sym.st_info =
20843 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 20844 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
20845 elf_sym->internal_elf_sym.st_info =
20846 ELF_ST_INFO (bind, STT_ARM_16BIT);
20847 }
20848 }
20849 }
20850#endif
404ff6b5
AH
20851}
20852
c19d1205 20853/* MD interface: Initialization. */
404ff6b5 20854
a737bd4d 20855static void
c19d1205 20856set_constant_flonums (void)
a737bd4d 20857{
c19d1205 20858 int i;
404ff6b5 20859
c19d1205
ZW
20860 for (i = 0; i < NUM_FLOAT_VALS; i++)
20861 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20862 abort ();
a737bd4d 20863}
404ff6b5 20864
3e9e4fcf
JB
20865/* Auto-select Thumb mode if it's the only available instruction set for the
20866 given architecture. */
20867
20868static void
20869autoselect_thumb_from_cpu_variant (void)
20870{
20871 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20872 opcode_select (16);
20873}
20874
c19d1205
ZW
20875void
20876md_begin (void)
a737bd4d 20877{
c19d1205
ZW
20878 unsigned mach;
20879 unsigned int i;
404ff6b5 20880
c19d1205
ZW
20881 if ( (arm_ops_hsh = hash_new ()) == NULL
20882 || (arm_cond_hsh = hash_new ()) == NULL
20883 || (arm_shift_hsh = hash_new ()) == NULL
20884 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 20885 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 20886 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
20887 || (arm_reloc_hsh = hash_new ()) == NULL
20888 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
20889 as_fatal (_("virtual memory exhausted"));
20890
20891 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
5a49b8ac 20892 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
c19d1205 20893 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
5a49b8ac 20894 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
c19d1205 20895 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 20896 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 20897 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20898 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
62b3e311 20899 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20900 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
c19d1205 20901 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 20902 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
20903 for (i = 0;
20904 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20905 i++)
20906 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
5a49b8ac 20907 (void *) (barrier_opt_names + i));
c19d1205
ZW
20908#ifdef OBJ_ELF
20909 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 20910 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
20911#endif
20912
20913 set_constant_flonums ();
404ff6b5 20914
c19d1205
ZW
20915 /* Set the cpu variant based on the command-line options. We prefer
20916 -mcpu= over -march= if both are set (as for GCC); and we prefer
20917 -mfpu= over any other way of setting the floating point unit.
20918 Use of legacy options with new options are faulted. */
e74cfd16 20919 if (legacy_cpu)
404ff6b5 20920 {
e74cfd16 20921 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
20922 as_bad (_("use of old and new-style options to set CPU type"));
20923
20924 mcpu_cpu_opt = legacy_cpu;
404ff6b5 20925 }
e74cfd16 20926 else if (!mcpu_cpu_opt)
c19d1205 20927 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 20928
e74cfd16 20929 if (legacy_fpu)
c19d1205 20930 {
e74cfd16 20931 if (mfpu_opt)
c19d1205 20932 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
20933
20934 mfpu_opt = legacy_fpu;
20935 }
e74cfd16 20936 else if (!mfpu_opt)
03b1477f 20937 {
45eb4c1b
NS
20938#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
20939 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
20940 /* Some environments specify a default FPU. If they don't, infer it
20941 from the processor. */
e74cfd16 20942 if (mcpu_fpu_opt)
03b1477f
RE
20943 mfpu_opt = mcpu_fpu_opt;
20944 else
20945 mfpu_opt = march_fpu_opt;
39c2da32 20946#else
e74cfd16 20947 mfpu_opt = &fpu_default;
39c2da32 20948#endif
03b1477f
RE
20949 }
20950
e74cfd16 20951 if (!mfpu_opt)
03b1477f 20952 {
493cb6ef 20953 if (mcpu_cpu_opt != NULL)
e74cfd16 20954 mfpu_opt = &fpu_default;
493cb6ef 20955 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 20956 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 20957 else
e74cfd16 20958 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
20959 }
20960
ee065d83 20961#ifdef CPU_DEFAULT
e74cfd16 20962 if (!mcpu_cpu_opt)
ee065d83 20963 {
e74cfd16
PB
20964 mcpu_cpu_opt = &cpu_default;
20965 selected_cpu = cpu_default;
ee065d83 20966 }
e74cfd16
PB
20967#else
20968 if (mcpu_cpu_opt)
20969 selected_cpu = *mcpu_cpu_opt;
ee065d83 20970 else
e74cfd16 20971 mcpu_cpu_opt = &arm_arch_any;
ee065d83 20972#endif
03b1477f 20973
e74cfd16 20974 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 20975
3e9e4fcf
JB
20976 autoselect_thumb_from_cpu_variant ();
20977
e74cfd16 20978 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 20979
f17c130b 20980#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 20981 {
7cc69913
NC
20982 unsigned int flags = 0;
20983
20984#if defined OBJ_ELF
20985 flags = meabi_flags;
d507cf36
PB
20986
20987 switch (meabi_flags)
33a392fb 20988 {
d507cf36 20989 case EF_ARM_EABI_UNKNOWN:
7cc69913 20990#endif
d507cf36
PB
20991 /* Set the flags in the private structure. */
20992 if (uses_apcs_26) flags |= F_APCS26;
20993 if (support_interwork) flags |= F_INTERWORK;
20994 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 20995 if (pic_code) flags |= F_PIC;
e74cfd16 20996 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
20997 flags |= F_SOFT_FLOAT;
20998
d507cf36
PB
20999 switch (mfloat_abi_opt)
21000 {
21001 case ARM_FLOAT_ABI_SOFT:
21002 case ARM_FLOAT_ABI_SOFTFP:
21003 flags |= F_SOFT_FLOAT;
21004 break;
33a392fb 21005
d507cf36
PB
21006 case ARM_FLOAT_ABI_HARD:
21007 if (flags & F_SOFT_FLOAT)
21008 as_bad (_("hard-float conflicts with specified fpu"));
21009 break;
21010 }
03b1477f 21011
e74cfd16
PB
21012 /* Using pure-endian doubles (even if soft-float). */
21013 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21014 flags |= F_VFP_FLOAT;
f17c130b 21015
fde78edd 21016#if defined OBJ_ELF
e74cfd16 21017 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21018 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21019 break;
21020
8cb51566 21021 case EF_ARM_EABI_VER4:
3a4a14e9 21022 case EF_ARM_EABI_VER5:
c19d1205 21023 /* No additional flags to set. */
d507cf36
PB
21024 break;
21025
21026 default:
21027 abort ();
21028 }
7cc69913 21029#endif
b99bd4ef
NC
21030 bfd_set_private_flags (stdoutput, flags);
21031
21032 /* We have run out flags in the COFF header to encode the
21033 status of ATPCS support, so instead we create a dummy,
c19d1205 21034 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21035 if (atpcs)
21036 {
21037 asection * sec;
21038
21039 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21040
21041 if (sec != NULL)
21042 {
21043 bfd_set_section_flags
21044 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21045 bfd_set_section_size (stdoutput, sec, 0);
21046 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21047 }
21048 }
7cc69913 21049 }
f17c130b 21050#endif
b99bd4ef
NC
21051
21052 /* Record the CPU type as well. */
2d447fca
JM
21053 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21054 mach = bfd_mach_arm_iWMMXt2;
21055 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21056 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21057 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21058 mach = bfd_mach_arm_XScale;
e74cfd16 21059 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21060 mach = bfd_mach_arm_ep9312;
e74cfd16 21061 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21062 mach = bfd_mach_arm_5TE;
e74cfd16 21063 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21064 {
e74cfd16 21065 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21066 mach = bfd_mach_arm_5T;
21067 else
21068 mach = bfd_mach_arm_5;
21069 }
e74cfd16 21070 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21071 {
e74cfd16 21072 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21073 mach = bfd_mach_arm_4T;
21074 else
21075 mach = bfd_mach_arm_4;
21076 }
e74cfd16 21077 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21078 mach = bfd_mach_arm_3M;
e74cfd16
PB
21079 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21080 mach = bfd_mach_arm_3;
21081 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21082 mach = bfd_mach_arm_2a;
21083 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21084 mach = bfd_mach_arm_2;
21085 else
21086 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21087
21088 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21089}
21090
c19d1205 21091/* Command line processing. */
b99bd4ef 21092
c19d1205
ZW
21093/* md_parse_option
21094 Invocation line includes a switch not recognized by the base assembler.
21095 See if it's a processor-specific option.
b99bd4ef 21096
c19d1205
ZW
21097 This routine is somewhat complicated by the need for backwards
21098 compatibility (since older releases of gcc can't be changed).
21099 The new options try to make the interface as compatible as
21100 possible with GCC.
b99bd4ef 21101
c19d1205 21102 New options (supported) are:
b99bd4ef 21103
c19d1205
ZW
21104 -mcpu=<cpu name> Assemble for selected processor
21105 -march=<architecture name> Assemble for selected architecture
21106 -mfpu=<fpu architecture> Assemble for selected FPU.
21107 -EB/-mbig-endian Big-endian
21108 -EL/-mlittle-endian Little-endian
21109 -k Generate PIC code
21110 -mthumb Start in Thumb mode
21111 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21112
278df34e 21113 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21114
c19d1205 21115 For now we will also provide support for:
b99bd4ef 21116
c19d1205
ZW
21117 -mapcs-32 32-bit Program counter
21118 -mapcs-26 26-bit Program counter
21119 -macps-float Floats passed in FP registers
21120 -mapcs-reentrant Reentrant code
21121 -matpcs
21122 (sometime these will probably be replaced with -mapcs=<list of options>
21123 and -matpcs=<list of options>)
b99bd4ef 21124
c19d1205
ZW
21125 The remaining options are only supported for back-wards compatibility.
21126 Cpu variants, the arm part is optional:
21127 -m[arm]1 Currently not supported.
21128 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21129 -m[arm]3 Arm 3 processor
21130 -m[arm]6[xx], Arm 6 processors
21131 -m[arm]7[xx][t][[d]m] Arm 7 processors
21132 -m[arm]8[10] Arm 8 processors
21133 -m[arm]9[20][tdmi] Arm 9 processors
21134 -mstrongarm[110[0]] StrongARM processors
21135 -mxscale XScale processors
21136 -m[arm]v[2345[t[e]]] Arm architectures
21137 -mall All (except the ARM1)
21138 FP variants:
21139 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21140 -mfpe-old (No float load/store multiples)
21141 -mvfpxd VFP Single precision
21142 -mvfp All VFP
21143 -mno-fpu Disable all floating point instructions
b99bd4ef 21144
c19d1205
ZW
21145 The following CPU names are recognized:
21146 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21147 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21148 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21149 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21150 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21151 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21152 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21153
c19d1205 21154 */
b99bd4ef 21155
c19d1205 21156const char * md_shortopts = "m:k";
b99bd4ef 21157
c19d1205
ZW
21158#ifdef ARM_BI_ENDIAN
21159#define OPTION_EB (OPTION_MD_BASE + 0)
21160#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21161#else
c19d1205
ZW
21162#if TARGET_BYTES_BIG_ENDIAN
21163#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21164#else
c19d1205
ZW
21165#define OPTION_EL (OPTION_MD_BASE + 1)
21166#endif
b99bd4ef 21167#endif
845b51d6 21168#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21169
c19d1205 21170struct option md_longopts[] =
b99bd4ef 21171{
c19d1205
ZW
21172#ifdef OPTION_EB
21173 {"EB", no_argument, NULL, OPTION_EB},
21174#endif
21175#ifdef OPTION_EL
21176 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21177#endif
845b51d6 21178 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21179 {NULL, no_argument, NULL, 0}
21180};
b99bd4ef 21181
c19d1205 21182size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21183
c19d1205 21184struct arm_option_table
b99bd4ef 21185{
c19d1205
ZW
21186 char *option; /* Option name to match. */
21187 char *help; /* Help information. */
21188 int *var; /* Variable to change. */
21189 int value; /* What to change it to. */
21190 char *deprecated; /* If non-null, print this message. */
21191};
b99bd4ef 21192
c19d1205
ZW
21193struct arm_option_table arm_opts[] =
21194{
21195 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21196 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21197 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21198 &support_interwork, 1, NULL},
21199 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21200 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21201 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21202 1, NULL},
21203 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21204 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21205 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21206 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21207 NULL},
b99bd4ef 21208
c19d1205
ZW
21209 /* These are recognized by the assembler, but have no affect on code. */
21210 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21211 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21212
21213 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21214 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21215 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21216 {NULL, NULL, NULL, 0, NULL}
21217};
21218
21219struct arm_legacy_option_table
21220{
21221 char *option; /* Option name to match. */
21222 const arm_feature_set **var; /* Variable to change. */
21223 const arm_feature_set value; /* What to change it to. */
21224 char *deprecated; /* If non-null, print this message. */
21225};
b99bd4ef 21226
e74cfd16
PB
21227const struct arm_legacy_option_table arm_legacy_opts[] =
21228{
c19d1205
ZW
21229 /* DON'T add any new processors to this list -- we want the whole list
21230 to go away... Add them to the processors table instead. */
e74cfd16
PB
21231 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21232 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21233 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21234 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21235 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21236 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21237 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21238 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21239 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21240 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21241 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21242 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21243 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21244 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21245 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21246 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21247 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21248 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21249 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21250 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21251 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21252 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21253 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21254 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21255 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21256 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21257 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21258 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21259 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21260 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21261 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21262 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21263 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21264 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21265 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21266 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21267 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21268 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21269 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21270 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21271 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21272 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21273 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21274 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21275 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21276 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21277 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21278 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21279 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21280 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21281 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21282 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21283 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21284 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21285 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21286 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21287 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21288 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21289 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21290 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21291 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21292 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21293 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21294 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21295 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21296 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21297 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21298 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21299 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
21300 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21301 N_("use -mcpu=strongarm110")},
e74cfd16 21302 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21303 N_("use -mcpu=strongarm1100")},
e74cfd16 21304 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21305 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
21306 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
21307 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
21308 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 21309
c19d1205 21310 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
21311 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21312 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21313 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21314 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21315 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21316 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21317 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21318 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21319 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21320 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21321 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21322 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21323 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21324 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21325 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21326 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21327 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21328 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 21329
c19d1205 21330 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
21331 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
21332 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
21333 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
21334 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 21335 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 21336
e74cfd16 21337 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 21338};
7ed4c4c5 21339
c19d1205 21340struct arm_cpu_option_table
7ed4c4c5 21341{
c19d1205 21342 char *name;
e74cfd16 21343 const arm_feature_set value;
c19d1205
ZW
21344 /* For some CPUs we assume an FPU unless the user explicitly sets
21345 -mfpu=... */
e74cfd16 21346 const arm_feature_set default_fpu;
ee065d83
PB
21347 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21348 case. */
21349 const char *canonical_name;
c19d1205 21350};
7ed4c4c5 21351
c19d1205
ZW
21352/* This list should, at a minimum, contain all the cpu names
21353 recognized by GCC. */
e74cfd16 21354static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 21355{
ee065d83
PB
21356 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
21357 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
21358 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
21359 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21360 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21361 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21362 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21363 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21364 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21365 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21366 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21367 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21368 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21369 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21370 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21371 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21372 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21373 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21374 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21375 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21376 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21377 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21378 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21379 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21380 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21381 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21382 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21383 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21384 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21385 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21386 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21387 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21388 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21389 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21390 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21391 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21392 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21393 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21394 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21395 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
21396 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21397 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21398 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21399 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
21400 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21401 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
21402 /* For V5 or later processors we default to using VFP; but the user
21403 should really set the FPU type explicitly. */
ee065d83
PB
21404 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21405 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21406 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21407 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21408 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21409 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21410 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
21411 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21412 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21413 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
21414 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21415 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21416 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21417 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21418 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21419 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
21420 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21421 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21422 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21423 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
21424 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
21425 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
21426 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
21427 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
21428 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
21429 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
21430 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
21431 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
21432 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
21433 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
21434 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
21435 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
21436 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
e07e6e58 21437 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 21438 | FPU_NEON_EXT_V1),
15290f0a 21439 NULL},
e07e6e58 21440 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 21441 | FPU_NEON_EXT_V1),
5287ad62 21442 NULL},
62b3e311
PB
21443 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
21444 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 21445 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 21446 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 21447 /* ??? XSCALE is really an architecture. */
ee065d83 21448 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21449 /* ??? iwmmxt is not a processor. */
ee065d83 21450 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 21451 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 21452 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21453 /* Maverick */
e07e6e58 21454 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 21455 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 21456};
7ed4c4c5 21457
c19d1205 21458struct arm_arch_option_table
7ed4c4c5 21459{
c19d1205 21460 char *name;
e74cfd16
PB
21461 const arm_feature_set value;
21462 const arm_feature_set default_fpu;
c19d1205 21463};
7ed4c4c5 21464
c19d1205
ZW
21465/* This list should, at a minimum, contain all the architecture names
21466 recognized by GCC. */
e74cfd16 21467static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
21468{
21469 {"all", ARM_ANY, FPU_ARCH_FPA},
21470 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
21471 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
21472 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
21473 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
21474 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
21475 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
21476 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
21477 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
21478 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
21479 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
21480 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
21481 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
21482 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
21483 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
21484 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
21485 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
21486 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
21487 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
21488 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
21489 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
21490 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
21491 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
21492 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
21493 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
21494 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 21495 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 21496 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
21497 /* The official spelling of the ARMv7 profile variants is the dashed form.
21498 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
21499 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
21500 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
21501 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
21502 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
21503 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
21504 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
21505 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
21506 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 21507 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 21508 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 21509};
7ed4c4c5 21510
c19d1205 21511/* ISA extensions in the co-processor space. */
e74cfd16 21512struct arm_option_cpu_value_table
c19d1205
ZW
21513{
21514 char *name;
e74cfd16 21515 const arm_feature_set value;
c19d1205 21516};
7ed4c4c5 21517
e74cfd16 21518static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 21519{
e74cfd16
PB
21520 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
21521 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
21522 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 21523 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 21524 {NULL, ARM_ARCH_NONE}
c19d1205 21525};
7ed4c4c5 21526
c19d1205
ZW
21527/* This list should, at a minimum, contain all the fpu names
21528 recognized by GCC. */
e74cfd16 21529static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
21530{
21531 {"softfpa", FPU_NONE},
21532 {"fpe", FPU_ARCH_FPE},
21533 {"fpe2", FPU_ARCH_FPE},
21534 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
21535 {"fpa", FPU_ARCH_FPA},
21536 {"fpa10", FPU_ARCH_FPA},
21537 {"fpa11", FPU_ARCH_FPA},
21538 {"arm7500fe", FPU_ARCH_FPA},
21539 {"softvfp", FPU_ARCH_VFP},
21540 {"softvfp+vfp", FPU_ARCH_VFP_V2},
21541 {"vfp", FPU_ARCH_VFP_V2},
21542 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 21543 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
21544 {"vfp10", FPU_ARCH_VFP_V2},
21545 {"vfp10-r0", FPU_ARCH_VFP_V1},
21546 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
21547 {"vfpv2", FPU_ARCH_VFP_V2},
21548 {"vfpv3", FPU_ARCH_VFP_V3},
21549 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
21550 {"arm1020t", FPU_ARCH_VFP_V1},
21551 {"arm1020e", FPU_ARCH_VFP_V2},
21552 {"arm1136jfs", FPU_ARCH_VFP_V2},
21553 {"arm1136jf-s", FPU_ARCH_VFP_V2},
21554 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 21555 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 21556 {"neon-fp16", FPU_ARCH_NEON_FP16},
e74cfd16
PB
21557 {NULL, ARM_ARCH_NONE}
21558};
21559
21560struct arm_option_value_table
21561{
21562 char *name;
21563 long value;
c19d1205 21564};
7ed4c4c5 21565
e74cfd16 21566static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
21567{
21568 {"hard", ARM_FLOAT_ABI_HARD},
21569 {"softfp", ARM_FLOAT_ABI_SOFTFP},
21570 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 21571 {NULL, 0}
c19d1205 21572};
7ed4c4c5 21573
c19d1205 21574#ifdef OBJ_ELF
3a4a14e9 21575/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 21576static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
21577{
21578 {"gnu", EF_ARM_EABI_UNKNOWN},
21579 {"4", EF_ARM_EABI_VER4},
3a4a14e9 21580 {"5", EF_ARM_EABI_VER5},
e74cfd16 21581 {NULL, 0}
c19d1205
ZW
21582};
21583#endif
7ed4c4c5 21584
c19d1205
ZW
21585struct arm_long_option_table
21586{
21587 char * option; /* Substring to match. */
21588 char * help; /* Help information. */
21589 int (* func) (char * subopt); /* Function to decode sub-option. */
21590 char * deprecated; /* If non-null, print this message. */
21591};
7ed4c4c5
NC
21592
21593static int
e74cfd16 21594arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 21595{
e74cfd16
PB
21596 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
21597
21598 /* Copy the feature set, so that we can modify it. */
21599 *ext_set = **opt_p;
21600 *opt_p = ext_set;
21601
c19d1205 21602 while (str != NULL && *str != 0)
7ed4c4c5 21603 {
e74cfd16 21604 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
21605 char * ext;
21606 int optlen;
7ed4c4c5 21607
c19d1205
ZW
21608 if (*str != '+')
21609 {
21610 as_bad (_("invalid architectural extension"));
21611 return 0;
21612 }
7ed4c4c5 21613
c19d1205
ZW
21614 str++;
21615 ext = strchr (str, '+');
7ed4c4c5 21616
c19d1205
ZW
21617 if (ext != NULL)
21618 optlen = ext - str;
21619 else
21620 optlen = strlen (str);
7ed4c4c5 21621
c19d1205
ZW
21622 if (optlen == 0)
21623 {
21624 as_bad (_("missing architectural extension"));
21625 return 0;
21626 }
7ed4c4c5 21627
c19d1205
ZW
21628 for (opt = arm_extensions; opt->name != NULL; opt++)
21629 if (strncmp (opt->name, str, optlen) == 0)
21630 {
e74cfd16 21631 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
21632 break;
21633 }
7ed4c4c5 21634
c19d1205
ZW
21635 if (opt->name == NULL)
21636 {
5f4273c7 21637 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
21638 return 0;
21639 }
7ed4c4c5 21640
c19d1205
ZW
21641 str = ext;
21642 };
7ed4c4c5 21643
c19d1205
ZW
21644 return 1;
21645}
7ed4c4c5 21646
c19d1205
ZW
21647static int
21648arm_parse_cpu (char * str)
7ed4c4c5 21649{
e74cfd16 21650 const struct arm_cpu_option_table * opt;
c19d1205
ZW
21651 char * ext = strchr (str, '+');
21652 int optlen;
7ed4c4c5 21653
c19d1205
ZW
21654 if (ext != NULL)
21655 optlen = ext - str;
7ed4c4c5 21656 else
c19d1205 21657 optlen = strlen (str);
7ed4c4c5 21658
c19d1205 21659 if (optlen == 0)
7ed4c4c5 21660 {
c19d1205
ZW
21661 as_bad (_("missing cpu name `%s'"), str);
21662 return 0;
7ed4c4c5
NC
21663 }
21664
c19d1205
ZW
21665 for (opt = arm_cpus; opt->name != NULL; opt++)
21666 if (strncmp (opt->name, str, optlen) == 0)
21667 {
e74cfd16
PB
21668 mcpu_cpu_opt = &opt->value;
21669 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 21670 if (opt->canonical_name)
5f4273c7 21671 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21672 else
21673 {
21674 int i;
21675 for (i = 0; i < optlen; i++)
21676 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21677 selected_cpu_name[i] = 0;
21678 }
7ed4c4c5 21679
c19d1205
ZW
21680 if (ext != NULL)
21681 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 21682
c19d1205
ZW
21683 return 1;
21684 }
7ed4c4c5 21685
c19d1205
ZW
21686 as_bad (_("unknown cpu `%s'"), str);
21687 return 0;
7ed4c4c5
NC
21688}
21689
c19d1205
ZW
21690static int
21691arm_parse_arch (char * str)
7ed4c4c5 21692{
e74cfd16 21693 const struct arm_arch_option_table *opt;
c19d1205
ZW
21694 char *ext = strchr (str, '+');
21695 int optlen;
7ed4c4c5 21696
c19d1205
ZW
21697 if (ext != NULL)
21698 optlen = ext - str;
7ed4c4c5 21699 else
c19d1205 21700 optlen = strlen (str);
7ed4c4c5 21701
c19d1205 21702 if (optlen == 0)
7ed4c4c5 21703 {
c19d1205
ZW
21704 as_bad (_("missing architecture name `%s'"), str);
21705 return 0;
7ed4c4c5
NC
21706 }
21707
c19d1205
ZW
21708 for (opt = arm_archs; opt->name != NULL; opt++)
21709 if (streq (opt->name, str))
21710 {
e74cfd16
PB
21711 march_cpu_opt = &opt->value;
21712 march_fpu_opt = &opt->default_fpu;
5f4273c7 21713 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 21714
c19d1205
ZW
21715 if (ext != NULL)
21716 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 21717
c19d1205
ZW
21718 return 1;
21719 }
21720
21721 as_bad (_("unknown architecture `%s'\n"), str);
21722 return 0;
7ed4c4c5 21723}
eb043451 21724
c19d1205
ZW
21725static int
21726arm_parse_fpu (char * str)
21727{
e74cfd16 21728 const struct arm_option_cpu_value_table * opt;
b99bd4ef 21729
c19d1205
ZW
21730 for (opt = arm_fpus; opt->name != NULL; opt++)
21731 if (streq (opt->name, str))
21732 {
e74cfd16 21733 mfpu_opt = &opt->value;
c19d1205
ZW
21734 return 1;
21735 }
b99bd4ef 21736
c19d1205
ZW
21737 as_bad (_("unknown floating point format `%s'\n"), str);
21738 return 0;
21739}
21740
21741static int
21742arm_parse_float_abi (char * str)
b99bd4ef 21743{
e74cfd16 21744 const struct arm_option_value_table * opt;
b99bd4ef 21745
c19d1205
ZW
21746 for (opt = arm_float_abis; opt->name != NULL; opt++)
21747 if (streq (opt->name, str))
21748 {
21749 mfloat_abi_opt = opt->value;
21750 return 1;
21751 }
cc8a6dd0 21752
c19d1205
ZW
21753 as_bad (_("unknown floating point abi `%s'\n"), str);
21754 return 0;
21755}
b99bd4ef 21756
c19d1205
ZW
21757#ifdef OBJ_ELF
21758static int
21759arm_parse_eabi (char * str)
21760{
e74cfd16 21761 const struct arm_option_value_table *opt;
cc8a6dd0 21762
c19d1205
ZW
21763 for (opt = arm_eabis; opt->name != NULL; opt++)
21764 if (streq (opt->name, str))
21765 {
21766 meabi_flags = opt->value;
21767 return 1;
21768 }
21769 as_bad (_("unknown EABI `%s'\n"), str);
21770 return 0;
21771}
21772#endif
cc8a6dd0 21773
e07e6e58
NC
21774static int
21775arm_parse_it_mode (char * str)
21776{
21777 int ret = 1;
21778
21779 if (streq ("arm", str))
21780 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
21781 else if (streq ("thumb", str))
21782 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
21783 else if (streq ("always", str))
21784 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
21785 else if (streq ("never", str))
21786 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
21787 else
21788 {
21789 as_bad (_("unknown implicit IT mode `%s', should be "\
21790 "arm, thumb, always, or never."), str);
21791 ret = 0;
21792 }
21793
21794 return ret;
21795}
21796
c19d1205
ZW
21797struct arm_long_option_table arm_long_opts[] =
21798{
21799 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21800 arm_parse_cpu, NULL},
21801 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21802 arm_parse_arch, NULL},
21803 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21804 arm_parse_fpu, NULL},
21805 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21806 arm_parse_float_abi, NULL},
21807#ifdef OBJ_ELF
7fac0536 21808 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
21809 arm_parse_eabi, NULL},
21810#endif
e07e6e58
NC
21811 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
21812 arm_parse_it_mode, NULL},
c19d1205
ZW
21813 {NULL, NULL, 0, NULL}
21814};
cc8a6dd0 21815
c19d1205
ZW
21816int
21817md_parse_option (int c, char * arg)
21818{
21819 struct arm_option_table *opt;
e74cfd16 21820 const struct arm_legacy_option_table *fopt;
c19d1205 21821 struct arm_long_option_table *lopt;
b99bd4ef 21822
c19d1205 21823 switch (c)
b99bd4ef 21824 {
c19d1205
ZW
21825#ifdef OPTION_EB
21826 case OPTION_EB:
21827 target_big_endian = 1;
21828 break;
21829#endif
cc8a6dd0 21830
c19d1205
ZW
21831#ifdef OPTION_EL
21832 case OPTION_EL:
21833 target_big_endian = 0;
21834 break;
21835#endif
b99bd4ef 21836
845b51d6
PB
21837 case OPTION_FIX_V4BX:
21838 fix_v4bx = TRUE;
21839 break;
21840
c19d1205
ZW
21841 case 'a':
21842 /* Listing option. Just ignore these, we don't support additional
21843 ones. */
21844 return 0;
b99bd4ef 21845
c19d1205
ZW
21846 default:
21847 for (opt = arm_opts; opt->option != NULL; opt++)
21848 {
21849 if (c == opt->option[0]
21850 && ((arg == NULL && opt->option[1] == 0)
21851 || streq (arg, opt->option + 1)))
21852 {
c19d1205 21853 /* If the option is deprecated, tell the user. */
278df34e 21854 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
21855 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21856 arg ? arg : "", _(opt->deprecated));
b99bd4ef 21857
c19d1205
ZW
21858 if (opt->var != NULL)
21859 *opt->var = opt->value;
cc8a6dd0 21860
c19d1205
ZW
21861 return 1;
21862 }
21863 }
b99bd4ef 21864
e74cfd16
PB
21865 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21866 {
21867 if (c == fopt->option[0]
21868 && ((arg == NULL && fopt->option[1] == 0)
21869 || streq (arg, fopt->option + 1)))
21870 {
e74cfd16 21871 /* If the option is deprecated, tell the user. */
278df34e 21872 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
21873 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21874 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
21875
21876 if (fopt->var != NULL)
21877 *fopt->var = &fopt->value;
21878
21879 return 1;
21880 }
21881 }
21882
c19d1205
ZW
21883 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21884 {
21885 /* These options are expected to have an argument. */
21886 if (c == lopt->option[0]
21887 && arg != NULL
21888 && strncmp (arg, lopt->option + 1,
21889 strlen (lopt->option + 1)) == 0)
21890 {
c19d1205 21891 /* If the option is deprecated, tell the user. */
278df34e 21892 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
21893 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21894 _(lopt->deprecated));
b99bd4ef 21895
c19d1205
ZW
21896 /* Call the sup-option parser. */
21897 return lopt->func (arg + strlen (lopt->option) - 1);
21898 }
21899 }
a737bd4d 21900
c19d1205
ZW
21901 return 0;
21902 }
a394c00f 21903
c19d1205
ZW
21904 return 1;
21905}
a394c00f 21906
c19d1205
ZW
21907void
21908md_show_usage (FILE * fp)
a394c00f 21909{
c19d1205
ZW
21910 struct arm_option_table *opt;
21911 struct arm_long_option_table *lopt;
a394c00f 21912
c19d1205 21913 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 21914
c19d1205
ZW
21915 for (opt = arm_opts; opt->option != NULL; opt++)
21916 if (opt->help != NULL)
21917 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 21918
c19d1205
ZW
21919 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21920 if (lopt->help != NULL)
21921 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 21922
c19d1205
ZW
21923#ifdef OPTION_EB
21924 fprintf (fp, _("\
21925 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
21926#endif
21927
c19d1205
ZW
21928#ifdef OPTION_EL
21929 fprintf (fp, _("\
21930 -EL assemble code for a little-endian cpu\n"));
a737bd4d 21931#endif
845b51d6
PB
21932
21933 fprintf (fp, _("\
21934 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 21935}
ee065d83
PB
21936
21937
21938#ifdef OBJ_ELF
62b3e311
PB
21939typedef struct
21940{
21941 int val;
21942 arm_feature_set flags;
21943} cpu_arch_ver_table;
21944
21945/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21946 least features first. */
21947static const cpu_arch_ver_table cpu_arch_ver[] =
21948{
21949 {1, ARM_ARCH_V4},
21950 {2, ARM_ARCH_V4T},
21951 {3, ARM_ARCH_V5},
ee3c0378 21952 {3, ARM_ARCH_V5T},
62b3e311
PB
21953 {4, ARM_ARCH_V5TE},
21954 {5, ARM_ARCH_V5TEJ},
21955 {6, ARM_ARCH_V6},
21956 {7, ARM_ARCH_V6Z},
7e806470 21957 {9, ARM_ARCH_V6K},
91e22acd 21958 {11, ARM_ARCH_V6M},
7e806470 21959 {8, ARM_ARCH_V6T2},
62b3e311
PB
21960 {10, ARM_ARCH_V7A},
21961 {10, ARM_ARCH_V7R},
21962 {10, ARM_ARCH_V7M},
21963 {0, ARM_ARCH_NONE}
21964};
21965
ee3c0378
AS
21966/* Set an attribute if it has not already been set by the user. */
21967static void
21968aeabi_set_attribute_int (int tag, int value)
21969{
21970 if (tag < 1
21971 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21972 || !attributes_set_explicitly[tag])
21973 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21974}
21975
21976static void
21977aeabi_set_attribute_string (int tag, const char *value)
21978{
21979 if (tag < 1
21980 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21981 || !attributes_set_explicitly[tag])
21982 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21983}
21984
ee065d83
PB
21985/* Set the public EABI object attributes. */
21986static void
21987aeabi_set_public_attributes (void)
21988{
21989 int arch;
e74cfd16 21990 arm_feature_set flags;
62b3e311
PB
21991 arm_feature_set tmp;
21992 const cpu_arch_ver_table *p;
ee065d83
PB
21993
21994 /* Choose the architecture based on the capabilities of the requested cpu
21995 (if any) and/or the instructions actually used. */
e74cfd16
PB
21996 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
21997 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
21998 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
21999 /*Allow the user to override the reported architecture. */
22000 if (object_arch)
22001 {
22002 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22003 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22004 }
22005
62b3e311
PB
22006 tmp = flags;
22007 arch = 0;
22008 for (p = cpu_arch_ver; p->val; p++)
22009 {
22010 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22011 {
22012 arch = p->val;
22013 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22014 }
22015 }
ee065d83
PB
22016
22017 /* Tag_CPU_name. */
22018 if (selected_cpu_name[0])
22019 {
22020 char *p;
22021
22022 p = selected_cpu_name;
5f4273c7 22023 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
22024 {
22025 int i;
5f4273c7 22026
ee065d83
PB
22027 p += 4;
22028 for (i = 0; p[i]; i++)
22029 p[i] = TOUPPER (p[i]);
22030 }
ee3c0378 22031 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83
PB
22032 }
22033 /* Tag_CPU_arch. */
ee3c0378 22034 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62b3e311
PB
22035 /* Tag_CPU_arch_profile. */
22036 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22037 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22038 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22039 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22040 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22041 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
ee065d83 22042 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22043 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22044 || arch == 0)
22045 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
ee065d83 22046 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22047 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22048 || arch == 0)
22049 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22050 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
ee065d83 22051 /* Tag_VFP_arch. */
ee3c0378
AS
22052 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22053 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22054 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
22055 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22056 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22057 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22058 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22059 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22060 aeabi_set_attribute_int (Tag_VFP_arch, 1);
ee065d83 22061 /* Tag_WMMX_arch. */
ee3c0378
AS
22062 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22063 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22064 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22065 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22066 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22067 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
ee3c0378
AS
22068 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
22069 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
8e79c3df 22070 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
ee3c0378 22071 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
22072}
22073
104d59d1 22074/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22075void
22076arm_md_end (void)
22077{
ee065d83
PB
22078 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22079 return;
22080
22081 aeabi_set_public_attributes ();
ee065d83 22082}
8463be01 22083#endif /* OBJ_ELF */
ee065d83
PB
22084
22085
22086/* Parse a .cpu directive. */
22087
22088static void
22089s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22090{
e74cfd16 22091 const struct arm_cpu_option_table *opt;
ee065d83
PB
22092 char *name;
22093 char saved_char;
22094
22095 name = input_line_pointer;
5f4273c7 22096 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22097 input_line_pointer++;
22098 saved_char = *input_line_pointer;
22099 *input_line_pointer = 0;
22100
22101 /* Skip the first "all" entry. */
22102 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22103 if (streq (opt->name, name))
22104 {
e74cfd16
PB
22105 mcpu_cpu_opt = &opt->value;
22106 selected_cpu = opt->value;
ee065d83 22107 if (opt->canonical_name)
5f4273c7 22108 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22109 else
22110 {
22111 int i;
22112 for (i = 0; opt->name[i]; i++)
22113 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22114 selected_cpu_name[i] = 0;
22115 }
e74cfd16 22116 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22117 *input_line_pointer = saved_char;
22118 demand_empty_rest_of_line ();
22119 return;
22120 }
22121 as_bad (_("unknown cpu `%s'"), name);
22122 *input_line_pointer = saved_char;
22123 ignore_rest_of_line ();
22124}
22125
22126
22127/* Parse a .arch directive. */
22128
22129static void
22130s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22131{
e74cfd16 22132 const struct arm_arch_option_table *opt;
ee065d83
PB
22133 char saved_char;
22134 char *name;
22135
22136 name = input_line_pointer;
5f4273c7 22137 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22138 input_line_pointer++;
22139 saved_char = *input_line_pointer;
22140 *input_line_pointer = 0;
22141
22142 /* Skip the first "all" entry. */
22143 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22144 if (streq (opt->name, name))
22145 {
e74cfd16
PB
22146 mcpu_cpu_opt = &opt->value;
22147 selected_cpu = opt->value;
5f4273c7 22148 strcpy (selected_cpu_name, opt->name);
e74cfd16 22149 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22150 *input_line_pointer = saved_char;
22151 demand_empty_rest_of_line ();
22152 return;
22153 }
22154
22155 as_bad (_("unknown architecture `%s'\n"), name);
22156 *input_line_pointer = saved_char;
22157 ignore_rest_of_line ();
22158}
22159
22160
7a1d4c38
PB
22161/* Parse a .object_arch directive. */
22162
22163static void
22164s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22165{
22166 const struct arm_arch_option_table *opt;
22167 char saved_char;
22168 char *name;
22169
22170 name = input_line_pointer;
5f4273c7 22171 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22172 input_line_pointer++;
22173 saved_char = *input_line_pointer;
22174 *input_line_pointer = 0;
22175
22176 /* Skip the first "all" entry. */
22177 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22178 if (streq (opt->name, name))
22179 {
22180 object_arch = &opt->value;
22181 *input_line_pointer = saved_char;
22182 demand_empty_rest_of_line ();
22183 return;
22184 }
22185
22186 as_bad (_("unknown architecture `%s'\n"), name);
22187 *input_line_pointer = saved_char;
22188 ignore_rest_of_line ();
22189}
22190
ee065d83
PB
22191/* Parse a .fpu directive. */
22192
22193static void
22194s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22195{
e74cfd16 22196 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
22197 char saved_char;
22198 char *name;
22199
22200 name = input_line_pointer;
5f4273c7 22201 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22202 input_line_pointer++;
22203 saved_char = *input_line_pointer;
22204 *input_line_pointer = 0;
5f4273c7 22205
ee065d83
PB
22206 for (opt = arm_fpus; opt->name != NULL; opt++)
22207 if (streq (opt->name, name))
22208 {
e74cfd16
PB
22209 mfpu_opt = &opt->value;
22210 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22211 *input_line_pointer = saved_char;
22212 demand_empty_rest_of_line ();
22213 return;
22214 }
22215
22216 as_bad (_("unknown floating point format `%s'\n"), name);
22217 *input_line_pointer = saved_char;
22218 ignore_rest_of_line ();
22219}
ee065d83 22220
794ba86a 22221/* Copy symbol information. */
f31fef98 22222
794ba86a
DJ
22223void
22224arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22225{
22226 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22227}
e04befd0 22228
f31fef98 22229#ifdef OBJ_ELF
e04befd0
AS
22230/* Given a symbolic attribute NAME, return the proper integer value.
22231 Returns -1 if the attribute is not known. */
f31fef98 22232
e04befd0
AS
22233int
22234arm_convert_symbolic_attribute (const char *name)
22235{
f31fef98
NC
22236 static const struct
22237 {
22238 const char * name;
22239 const int tag;
22240 }
22241 attribute_table[] =
22242 {
22243 /* When you modify this table you should
22244 also modify the list in doc/c-arm.texi. */
e04befd0 22245#define T(tag) {#tag, tag}
f31fef98
NC
22246 T (Tag_CPU_raw_name),
22247 T (Tag_CPU_name),
22248 T (Tag_CPU_arch),
22249 T (Tag_CPU_arch_profile),
22250 T (Tag_ARM_ISA_use),
22251 T (Tag_THUMB_ISA_use),
22252 T (Tag_VFP_arch),
22253 T (Tag_WMMX_arch),
22254 T (Tag_Advanced_SIMD_arch),
22255 T (Tag_PCS_config),
22256 T (Tag_ABI_PCS_R9_use),
22257 T (Tag_ABI_PCS_RW_data),
22258 T (Tag_ABI_PCS_RO_data),
22259 T (Tag_ABI_PCS_GOT_use),
22260 T (Tag_ABI_PCS_wchar_t),
22261 T (Tag_ABI_FP_rounding),
22262 T (Tag_ABI_FP_denormal),
22263 T (Tag_ABI_FP_exceptions),
22264 T (Tag_ABI_FP_user_exceptions),
22265 T (Tag_ABI_FP_number_model),
22266 T (Tag_ABI_align8_needed),
22267 T (Tag_ABI_align8_preserved),
22268 T (Tag_ABI_enum_size),
22269 T (Tag_ABI_HardFP_use),
22270 T (Tag_ABI_VFP_args),
22271 T (Tag_ABI_WMMX_args),
22272 T (Tag_ABI_optimization_goals),
22273 T (Tag_ABI_FP_optimization_goals),
22274 T (Tag_compatibility),
22275 T (Tag_CPU_unaligned_access),
22276 T (Tag_VFP_HP_extension),
22277 T (Tag_ABI_FP_16bit_format),
22278 T (Tag_nodefaults),
22279 T (Tag_also_compatible_with),
22280 T (Tag_conformance),
22281 T (Tag_T2EE_use),
22282 T (Tag_Virtualization_use),
22283 T (Tag_MPextension_use)
e04befd0 22284#undef T
f31fef98 22285 };
e04befd0
AS
22286 unsigned int i;
22287
22288 if (name == NULL)
22289 return -1;
22290
f31fef98 22291 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
e04befd0
AS
22292 if (strcmp (name, attribute_table[i].name) == 0)
22293 return attribute_table[i].tag;
22294
22295 return -1;
22296}
267bf995
RR
22297
22298
22299/* Apply sym value for relocations only in the case that
22300 they are for local symbols and you have the respective
22301 architectural feature for blx and simple switches. */
22302int
22303arm_apply_sym_value (struct fix * fixP)
22304{
22305 if (fixP->fx_addsy
22306 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22307 && !S_IS_EXTERNAL (fixP->fx_addsy))
22308 {
22309 switch (fixP->fx_r_type)
22310 {
22311 case BFD_RELOC_ARM_PCREL_BLX:
22312 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22313 if (ARM_IS_FUNC (fixP->fx_addsy))
22314 return 1;
22315 break;
22316
22317 case BFD_RELOC_ARM_PCREL_CALL:
22318 case BFD_RELOC_THUMB_PCREL_BLX:
22319 if (THUMB_IS_FUNC (fixP->fx_addsy))
22320 return 1;
22321 break;
22322
22323 default:
22324 break;
22325 }
22326
22327 }
22328 return 0;
22329}
f31fef98 22330#endif /* OBJ_ELF */
This page took 2.374243 seconds and 4 git commands to generate.