]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
gdb/ChangeLog:
[thirdparty/binutils-gdb.git] / gas / config / tc-arm.c
CommitLineData
b99bd4ef 1/* tc-arm.c -- Assemble for the ARM
f17c130b 2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
f31fef98 3 2004, 2005, 2006, 2007, 2008, 2009
b99bd4ef
NC
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
22d9c8c5 7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
34920d91
NC
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
b99bd4ef
NC
10
11 This file is part of GAS, the GNU Assembler.
12
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
ec2655a6 15 the Free Software Foundation; either version 3, or (at your option)
b99bd4ef
NC
16 any later version.
17
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
c19d1205 20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b99bd4ef
NC
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with GAS; see the file COPYING. If not, write to the Free
699d2810
NC
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
b99bd4ef 27
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#endif /* OBJ_ELF */
81
4962c51a
MS
82/* Results from operand parsing worker functions. */
83
84typedef enum
85{
86 PARSE_OPERAND_SUCCESS,
87 PARSE_OPERAND_FAIL,
88 PARSE_OPERAND_FAIL_NO_BACKTRACK
89} parse_operand_result;
90
33a392fb
PB
91enum arm_float_abi
92{
93 ARM_FLOAT_ABI_HARD,
94 ARM_FLOAT_ABI_SOFTFP,
95 ARM_FLOAT_ABI_SOFT
96};
97
c19d1205 98/* Types of processor to assemble for. */
b99bd4ef
NC
99#ifndef CPU_DEFAULT
100#if defined __XSCALE__
e74cfd16 101#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
102#else
103#if defined __thumb__
e74cfd16 104#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
105#endif
106#endif
107#endif
108
109#ifndef FPU_DEFAULT
c820d418
MM
110# ifdef TE_LINUX
111# define FPU_DEFAULT FPU_ARCH_FPA
112# elif defined (TE_NetBSD)
113# ifdef OBJ_ELF
114# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
115# else
116 /* Legacy a.out format. */
117# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
118# endif
4e7fd91e
PB
119# elif defined (TE_VXWORKS)
120# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
121# else
122 /* For backwards compatibility, default to FPA. */
123# define FPU_DEFAULT FPU_ARCH_FPA
124# endif
125#endif /* ifndef FPU_DEFAULT */
b99bd4ef 126
c19d1205 127#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 128
e74cfd16
PB
129static arm_feature_set cpu_variant;
130static arm_feature_set arm_arch_used;
131static arm_feature_set thumb_arch_used;
b99bd4ef 132
b99bd4ef 133/* Flags stored in private area of BFD structure. */
c19d1205
ZW
134static int uses_apcs_26 = FALSE;
135static int atpcs = FALSE;
b34976b6
AM
136static int support_interwork = FALSE;
137static int uses_apcs_float = FALSE;
c19d1205 138static int pic_code = FALSE;
845b51d6 139static int fix_v4bx = FALSE;
278df34e
NS
140/* Warn on using deprecated features. */
141static int warn_on_deprecated = TRUE;
142
03b1477f
RE
143
144/* Variables that we set while parsing command-line options. Once all
145 options have been read we re-process these values to set the real
146 assembly flags. */
e74cfd16
PB
147static const arm_feature_set *legacy_cpu = NULL;
148static const arm_feature_set *legacy_fpu = NULL;
149
150static const arm_feature_set *mcpu_cpu_opt = NULL;
151static const arm_feature_set *mcpu_fpu_opt = NULL;
152static const arm_feature_set *march_cpu_opt = NULL;
153static const arm_feature_set *march_fpu_opt = NULL;
154static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 155static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
156
157/* Constants for known architecture features. */
158static const arm_feature_set fpu_default = FPU_DEFAULT;
159static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
160static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
161static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
162static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
163static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
164static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
165static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
166static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
167
168#ifdef CPU_DEFAULT
169static const arm_feature_set cpu_default = CPU_DEFAULT;
170#endif
171
172static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
173static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
174static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
175static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
176static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
177static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
178static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
179static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
180static const arm_feature_set arm_ext_v4t_5 =
181 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
182static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
183static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
184static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
185static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
186static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
187static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
188static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
189static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 190static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
9e3c6df6 191static const arm_feature_set arm_ext_v6_dsp = ARM_FEATURE (ARM_EXT_V6_DSP, 0);
7e806470
PB
192static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
193static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
194static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
195static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
196static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
197static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
9e3c6df6 198static const arm_feature_set arm_ext_v7m = ARM_FEATURE (ARM_EXT_V7M, 0);
7e806470
PB
199static const arm_feature_set arm_ext_m =
200 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
201
202static const arm_feature_set arm_arch_any = ARM_ANY;
203static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
204static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
205static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
206
2d447fca
JM
207static const arm_feature_set arm_cext_iwmmxt2 =
208 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
209static const arm_feature_set arm_cext_iwmmxt =
210 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
211static const arm_feature_set arm_cext_xscale =
212 ARM_FEATURE (0, ARM_CEXT_XSCALE);
213static const arm_feature_set arm_cext_maverick =
214 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
215static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
216static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
217static const arm_feature_set fpu_vfp_ext_v1xd =
218 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
219static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
220static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
62f3b8c8 221static const arm_feature_set fpu_vfp_ext_v3xd = ARM_FEATURE (0, FPU_VFP_EXT_V3xD);
5287ad62 222static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
223static const arm_feature_set fpu_vfp_ext_d32 =
224 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
225static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
226static const arm_feature_set fpu_vfp_v3_or_neon_ext =
227 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
62f3b8c8
PB
228static const arm_feature_set fpu_vfp_fp16 = ARM_FEATURE (0, FPU_VFP_EXT_FP16);
229static const arm_feature_set fpu_neon_ext_fma = ARM_FEATURE (0, FPU_NEON_EXT_FMA);
230static const arm_feature_set fpu_vfp_ext_fma = ARM_FEATURE (0, FPU_VFP_EXT_FMA);
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{
d3ce72d0 423 const char * template_name;
c921be7d 424 unsigned long value;
b99bd4ef
NC
425};
426
c19d1205 427#define COND_ALWAYS 0xE
b99bd4ef 428
b99bd4ef
NC
429struct asm_psr
430{
d3ce72d0 431 const char * template_name;
c921be7d 432 unsigned long field;
b99bd4ef
NC
433};
434
62b3e311
PB
435struct asm_barrier_opt
436{
d3ce72d0 437 const char * template_name;
c921be7d 438 unsigned long value;
62b3e311
PB
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{
c921be7d
NC
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{
c921be7d
NC
473 unsigned char defined;
474 unsigned char index;
475 struct neon_type_el eltype;
dcbf9037
JB
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{
c921be7d
NC
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 518/* Diagnostics used when we don't get a register of the expected type. */
c921be7d 519const char * const reg_expected_msgs[] =
c19d1205
ZW
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. */
d3ce72d0 556 const char * template_name;
c19d1205
ZW
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. */
c921be7d
NC
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 705
c921be7d
NC
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;
710static struct hash_control * arm_v7m_psr_hsh;
711static struct hash_control * arm_reg_hsh;
712static struct hash_control * arm_reloc_hsh;
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{
c921be7d
NC
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;
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
c921be7d
NC
769static void it_fsm_post_encode (void);
770
e07e6e58
NC
771#define set_it_insn_type(type) \
772 do \
773 { \
774 inst.it_insn_type = type; \
775 if (handle_it_state () == FAIL) \
776 return; \
777 } \
778 while (0)
779
c921be7d
NC
780#define set_it_insn_type_nonvoid(type, failret) \
781 do \
782 { \
783 inst.it_insn_type = type; \
784 if (handle_it_state () == FAIL) \
785 return failret; \
786 } \
787 while(0)
788
e07e6e58
NC
789#define set_it_insn_type_last() \
790 do \
791 { \
792 if (inst.cond == COND_ALWAYS) \
793 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
794 else \
795 set_it_insn_type (INSIDE_IT_LAST_INSN); \
796 } \
797 while (0)
798
c19d1205 799/* Pure syntax. */
b99bd4ef 800
c19d1205
ZW
801/* This array holds the chars that always start a comment. If the
802 pre-processor is disabled, these aren't very useful. */
803const char comment_chars[] = "@";
3d0c9500 804
c19d1205
ZW
805/* This array holds the chars that only start a comment at the beginning of
806 a line. If the line seems to have the form '# 123 filename'
807 .line and .file directives will appear in the pre-processed output. */
808/* Note that input_file.c hand checks for '#' at the beginning of the
809 first line of the input file. This is because the compiler outputs
810 #NO_APP at the beginning of its output. */
811/* Also note that comments like this one will always work. */
812const char line_comment_chars[] = "#";
3d0c9500 813
c19d1205 814const char line_separator_chars[] = ";";
b99bd4ef 815
c19d1205
ZW
816/* Chars that can be used to separate mant
817 from exp in floating point numbers. */
818const char EXP_CHARS[] = "eE";
3d0c9500 819
c19d1205
ZW
820/* Chars that mean this number is a floating point constant. */
821/* As in 0f12.456 */
822/* or 0d1.2345e12 */
b99bd4ef 823
c19d1205 824const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 825
c19d1205
ZW
826/* Prefix characters that indicate the start of an immediate
827 value. */
828#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 829
c19d1205
ZW
830/* Separator character handling. */
831
832#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
833
834static inline int
835skip_past_char (char ** str, char c)
836{
837 if (**str == c)
838 {
839 (*str)++;
840 return SUCCESS;
3d0c9500 841 }
c19d1205
ZW
842 else
843 return FAIL;
844}
c921be7d 845
c19d1205 846#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 847
c19d1205
ZW
848/* Arithmetic expressions (possibly involving symbols). */
849
850/* Return TRUE if anything in the expression is a bignum. */
851
852static int
853walk_no_bignums (symbolS * sp)
854{
855 if (symbol_get_value_expression (sp)->X_op == O_big)
856 return 1;
857
858 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 859 {
c19d1205
ZW
860 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
861 || (symbol_get_value_expression (sp)->X_op_symbol
862 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
863 }
864
c19d1205 865 return 0;
3d0c9500
NC
866}
867
c19d1205
ZW
868static int in_my_get_expression = 0;
869
870/* Third argument to my_get_expression. */
871#define GE_NO_PREFIX 0
872#define GE_IMM_PREFIX 1
873#define GE_OPT_PREFIX 2
5287ad62
JB
874/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
875 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
876#define GE_OPT_PREFIX_BIG 3
a737bd4d 877
b99bd4ef 878static int
c19d1205 879my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 880{
c19d1205
ZW
881 char * save_in;
882 segT seg;
b99bd4ef 883
c19d1205
ZW
884 /* In unified syntax, all prefixes are optional. */
885 if (unified_syntax)
5287ad62
JB
886 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
887 : GE_OPT_PREFIX;
b99bd4ef 888
c19d1205 889 switch (prefix_mode)
b99bd4ef 890 {
c19d1205
ZW
891 case GE_NO_PREFIX: break;
892 case GE_IMM_PREFIX:
893 if (!is_immediate_prefix (**str))
894 {
895 inst.error = _("immediate expression requires a # prefix");
896 return FAIL;
897 }
898 (*str)++;
899 break;
900 case GE_OPT_PREFIX:
5287ad62 901 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
902 if (is_immediate_prefix (**str))
903 (*str)++;
904 break;
905 default: abort ();
906 }
b99bd4ef 907
c19d1205 908 memset (ep, 0, sizeof (expressionS));
b99bd4ef 909
c19d1205
ZW
910 save_in = input_line_pointer;
911 input_line_pointer = *str;
912 in_my_get_expression = 1;
913 seg = expression (ep);
914 in_my_get_expression = 0;
915
f86adc07 916 if (ep->X_op == O_illegal || ep->X_op == O_absent)
b99bd4ef 917 {
f86adc07 918 /* We found a bad or missing expression in md_operand(). */
c19d1205
ZW
919 *str = input_line_pointer;
920 input_line_pointer = save_in;
921 if (inst.error == NULL)
f86adc07
NS
922 inst.error = (ep->X_op == O_absent
923 ? _("missing expression") :_("bad expression"));
c19d1205
ZW
924 return 1;
925 }
b99bd4ef 926
c19d1205
ZW
927#ifdef OBJ_AOUT
928 if (seg != absolute_section
929 && seg != text_section
930 && seg != data_section
931 && seg != bss_section
932 && seg != undefined_section)
933 {
934 inst.error = _("bad segment");
935 *str = input_line_pointer;
936 input_line_pointer = save_in;
937 return 1;
b99bd4ef 938 }
c19d1205 939#endif
b99bd4ef 940
c19d1205
ZW
941 /* Get rid of any bignums now, so that we don't generate an error for which
942 we can't establish a line number later on. Big numbers are never valid
943 in instructions, which is where this routine is always called. */
5287ad62
JB
944 if (prefix_mode != GE_OPT_PREFIX_BIG
945 && (ep->X_op == O_big
946 || (ep->X_add_symbol
947 && (walk_no_bignums (ep->X_add_symbol)
948 || (ep->X_op_symbol
949 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
950 {
951 inst.error = _("invalid constant");
952 *str = input_line_pointer;
953 input_line_pointer = save_in;
954 return 1;
955 }
b99bd4ef 956
c19d1205
ZW
957 *str = input_line_pointer;
958 input_line_pointer = save_in;
959 return 0;
b99bd4ef
NC
960}
961
c19d1205
ZW
962/* Turn a string in input_line_pointer into a floating point constant
963 of type TYPE, and store the appropriate bytes in *LITP. The number
964 of LITTLENUMS emitted is stored in *SIZEP. An error message is
965 returned, or NULL on OK.
b99bd4ef 966
c19d1205
ZW
967 Note that fp constants aren't represent in the normal way on the ARM.
968 In big endian mode, things are as expected. However, in little endian
969 mode fp constants are big-endian word-wise, and little-endian byte-wise
970 within the words. For example, (double) 1.1 in big endian mode is
971 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
972 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 973
c19d1205 974 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 975
c19d1205
ZW
976char *
977md_atof (int type, char * litP, int * sizeP)
978{
979 int prec;
980 LITTLENUM_TYPE words[MAX_LITTLENUMS];
981 char *t;
982 int i;
b99bd4ef 983
c19d1205
ZW
984 switch (type)
985 {
986 case 'f':
987 case 'F':
988 case 's':
989 case 'S':
990 prec = 2;
991 break;
b99bd4ef 992
c19d1205
ZW
993 case 'd':
994 case 'D':
995 case 'r':
996 case 'R':
997 prec = 4;
998 break;
b99bd4ef 999
c19d1205
ZW
1000 case 'x':
1001 case 'X':
499ac353 1002 prec = 5;
c19d1205 1003 break;
b99bd4ef 1004
c19d1205
ZW
1005 case 'p':
1006 case 'P':
499ac353 1007 prec = 5;
c19d1205 1008 break;
a737bd4d 1009
c19d1205
ZW
1010 default:
1011 *sizeP = 0;
499ac353 1012 return _("Unrecognized or unsupported floating point constant");
c19d1205 1013 }
b99bd4ef 1014
c19d1205
ZW
1015 t = atof_ieee (input_line_pointer, type, words);
1016 if (t)
1017 input_line_pointer = t;
499ac353 1018 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1019
c19d1205
ZW
1020 if (target_big_endian)
1021 {
1022 for (i = 0; i < prec; i++)
1023 {
499ac353
NC
1024 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1025 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1026 }
1027 }
1028 else
1029 {
e74cfd16 1030 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1031 for (i = prec - 1; i >= 0; i--)
1032 {
499ac353
NC
1033 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1034 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1035 }
1036 else
1037 /* For a 4 byte float the order of elements in `words' is 1 0.
1038 For an 8 byte float the order is 1 0 3 2. */
1039 for (i = 0; i < prec; i += 2)
1040 {
499ac353
NC
1041 md_number_to_chars (litP, (valueT) words[i + 1],
1042 sizeof (LITTLENUM_TYPE));
1043 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1044 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1045 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1046 }
1047 }
b99bd4ef 1048
499ac353 1049 return NULL;
c19d1205 1050}
b99bd4ef 1051
c19d1205
ZW
1052/* We handle all bad expressions here, so that we can report the faulty
1053 instruction in the error message. */
1054void
1055md_operand (expressionS * expr)
1056{
1057 if (in_my_get_expression)
1058 expr->X_op = O_illegal;
b99bd4ef
NC
1059}
1060
c19d1205 1061/* Immediate values. */
b99bd4ef 1062
c19d1205
ZW
1063/* Generic immediate-value read function for use in directives.
1064 Accepts anything that 'expression' can fold to a constant.
1065 *val receives the number. */
1066#ifdef OBJ_ELF
1067static int
1068immediate_for_directive (int *val)
b99bd4ef 1069{
c19d1205
ZW
1070 expressionS exp;
1071 exp.X_op = O_illegal;
b99bd4ef 1072
c19d1205
ZW
1073 if (is_immediate_prefix (*input_line_pointer))
1074 {
1075 input_line_pointer++;
1076 expression (&exp);
1077 }
b99bd4ef 1078
c19d1205
ZW
1079 if (exp.X_op != O_constant)
1080 {
1081 as_bad (_("expected #constant"));
1082 ignore_rest_of_line ();
1083 return FAIL;
1084 }
1085 *val = exp.X_add_number;
1086 return SUCCESS;
b99bd4ef 1087}
c19d1205 1088#endif
b99bd4ef 1089
c19d1205 1090/* Register parsing. */
b99bd4ef 1091
c19d1205
ZW
1092/* Generic register parser. CCP points to what should be the
1093 beginning of a register name. If it is indeed a valid register
1094 name, advance CCP over it and return the reg_entry structure;
1095 otherwise return NULL. Does not issue diagnostics. */
1096
1097static struct reg_entry *
1098arm_reg_parse_multi (char **ccp)
b99bd4ef 1099{
c19d1205
ZW
1100 char *start = *ccp;
1101 char *p;
1102 struct reg_entry *reg;
b99bd4ef 1103
c19d1205
ZW
1104#ifdef REGISTER_PREFIX
1105 if (*start != REGISTER_PREFIX)
01cfc07f 1106 return NULL;
c19d1205
ZW
1107 start++;
1108#endif
1109#ifdef OPTIONAL_REGISTER_PREFIX
1110 if (*start == OPTIONAL_REGISTER_PREFIX)
1111 start++;
1112#endif
b99bd4ef 1113
c19d1205
ZW
1114 p = start;
1115 if (!ISALPHA (*p) || !is_name_beginner (*p))
1116 return NULL;
b99bd4ef 1117
c19d1205
ZW
1118 do
1119 p++;
1120 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1121
1122 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1123
1124 if (!reg)
1125 return NULL;
1126
1127 *ccp = p;
1128 return reg;
b99bd4ef
NC
1129}
1130
1131static int
dcbf9037
JB
1132arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1133 enum arm_reg_type type)
b99bd4ef 1134{
c19d1205
ZW
1135 /* Alternative syntaxes are accepted for a few register classes. */
1136 switch (type)
1137 {
1138 case REG_TYPE_MVF:
1139 case REG_TYPE_MVD:
1140 case REG_TYPE_MVFX:
1141 case REG_TYPE_MVDX:
1142 /* Generic coprocessor register names are allowed for these. */
79134647 1143 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1144 return reg->number;
1145 break;
69b97547 1146
c19d1205
ZW
1147 case REG_TYPE_CP:
1148 /* For backward compatibility, a bare number is valid here. */
1149 {
1150 unsigned long processor = strtoul (start, ccp, 10);
1151 if (*ccp != start && processor <= 15)
1152 return processor;
1153 }
6057a28f 1154
c19d1205
ZW
1155 case REG_TYPE_MMXWC:
1156 /* WC includes WCG. ??? I'm not sure this is true for all
1157 instructions that take WC registers. */
79134647 1158 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1159 return reg->number;
6057a28f 1160 break;
c19d1205 1161
6057a28f 1162 default:
c19d1205 1163 break;
6057a28f
NC
1164 }
1165
dcbf9037
JB
1166 return FAIL;
1167}
1168
1169/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1170 return value is the register number or FAIL. */
1171
1172static int
1173arm_reg_parse (char **ccp, enum arm_reg_type type)
1174{
1175 char *start = *ccp;
1176 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1177 int ret;
1178
1179 /* Do not allow a scalar (reg+index) to parse as a register. */
1180 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1181 return FAIL;
1182
1183 if (reg && reg->type == type)
1184 return reg->number;
1185
1186 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1187 return ret;
1188
c19d1205
ZW
1189 *ccp = start;
1190 return FAIL;
1191}
69b97547 1192
dcbf9037
JB
1193/* Parse a Neon type specifier. *STR should point at the leading '.'
1194 character. Does no verification at this stage that the type fits the opcode
1195 properly. E.g.,
1196
1197 .i32.i32.s16
1198 .s32.f32
1199 .u16
1200
1201 Can all be legally parsed by this function.
1202
1203 Fills in neon_type struct pointer with parsed information, and updates STR
1204 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1205 type, FAIL if not. */
1206
1207static int
1208parse_neon_type (struct neon_type *type, char **str)
1209{
1210 char *ptr = *str;
1211
1212 if (type)
1213 type->elems = 0;
1214
1215 while (type->elems < NEON_MAX_TYPE_ELS)
1216 {
1217 enum neon_el_type thistype = NT_untyped;
1218 unsigned thissize = -1u;
1219
1220 if (*ptr != '.')
1221 break;
1222
1223 ptr++;
1224
1225 /* Just a size without an explicit type. */
1226 if (ISDIGIT (*ptr))
1227 goto parsesize;
1228
1229 switch (TOLOWER (*ptr))
1230 {
1231 case 'i': thistype = NT_integer; break;
1232 case 'f': thistype = NT_float; break;
1233 case 'p': thistype = NT_poly; break;
1234 case 's': thistype = NT_signed; break;
1235 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1236 case 'd':
1237 thistype = NT_float;
1238 thissize = 64;
1239 ptr++;
1240 goto done;
dcbf9037
JB
1241 default:
1242 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1243 return FAIL;
1244 }
1245
1246 ptr++;
1247
1248 /* .f is an abbreviation for .f32. */
1249 if (thistype == NT_float && !ISDIGIT (*ptr))
1250 thissize = 32;
1251 else
1252 {
1253 parsesize:
1254 thissize = strtoul (ptr, &ptr, 10);
1255
1256 if (thissize != 8 && thissize != 16 && thissize != 32
1257 && thissize != 64)
1258 {
1259 as_bad (_("bad size %d in type specifier"), thissize);
1260 return FAIL;
1261 }
1262 }
1263
037e8744 1264 done:
dcbf9037
JB
1265 if (type)
1266 {
1267 type->el[type->elems].type = thistype;
1268 type->el[type->elems].size = thissize;
1269 type->elems++;
1270 }
1271 }
1272
1273 /* Empty/missing type is not a successful parse. */
1274 if (type->elems == 0)
1275 return FAIL;
1276
1277 *str = ptr;
1278
1279 return SUCCESS;
1280}
1281
1282/* Errors may be set multiple times during parsing or bit encoding
1283 (particularly in the Neon bits), but usually the earliest error which is set
1284 will be the most meaningful. Avoid overwriting it with later (cascading)
1285 errors by calling this function. */
1286
1287static void
1288first_error (const char *err)
1289{
1290 if (!inst.error)
1291 inst.error = err;
1292}
1293
1294/* Parse a single type, e.g. ".s32", leading period included. */
1295static int
1296parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1297{
1298 char *str = *ccp;
1299 struct neon_type optype;
1300
1301 if (*str == '.')
1302 {
1303 if (parse_neon_type (&optype, &str) == SUCCESS)
1304 {
1305 if (optype.elems == 1)
1306 *vectype = optype.el[0];
1307 else
1308 {
1309 first_error (_("only one type should be specified for operand"));
1310 return FAIL;
1311 }
1312 }
1313 else
1314 {
1315 first_error (_("vector type expected"));
1316 return FAIL;
1317 }
1318 }
1319 else
1320 return FAIL;
5f4273c7 1321
dcbf9037 1322 *ccp = str;
5f4273c7 1323
dcbf9037
JB
1324 return SUCCESS;
1325}
1326
1327/* Special meanings for indices (which have a range of 0-7), which will fit into
1328 a 4-bit integer. */
1329
1330#define NEON_ALL_LANES 15
1331#define NEON_INTERLEAVE_LANES 14
1332
1333/* Parse either a register or a scalar, with an optional type. Return the
1334 register number, and optionally fill in the actual type of the register
1335 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1336 type/index information in *TYPEINFO. */
1337
1338static int
1339parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1340 enum arm_reg_type *rtype,
1341 struct neon_typed_alias *typeinfo)
1342{
1343 char *str = *ccp;
1344 struct reg_entry *reg = arm_reg_parse_multi (&str);
1345 struct neon_typed_alias atype;
1346 struct neon_type_el parsetype;
1347
1348 atype.defined = 0;
1349 atype.index = -1;
1350 atype.eltype.type = NT_invtype;
1351 atype.eltype.size = -1;
1352
1353 /* Try alternate syntax for some types of register. Note these are mutually
1354 exclusive with the Neon syntax extensions. */
1355 if (reg == NULL)
1356 {
1357 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1358 if (altreg != FAIL)
1359 *ccp = str;
1360 if (typeinfo)
1361 *typeinfo = atype;
1362 return altreg;
1363 }
1364
037e8744
JB
1365 /* Undo polymorphism when a set of register types may be accepted. */
1366 if ((type == REG_TYPE_NDQ
1367 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1368 || (type == REG_TYPE_VFSD
1369 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1370 || (type == REG_TYPE_NSDQ
1371 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1372 || reg->type == REG_TYPE_NQ))
1373 || (type == REG_TYPE_MMXWC
1374 && (reg->type == REG_TYPE_MMXWCG)))
21d799b5 1375 type = (enum arm_reg_type) reg->type;
dcbf9037
JB
1376
1377 if (type != reg->type)
1378 return FAIL;
1379
1380 if (reg->neon)
1381 atype = *reg->neon;
5f4273c7 1382
dcbf9037
JB
1383 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1384 {
1385 if ((atype.defined & NTA_HASTYPE) != 0)
1386 {
1387 first_error (_("can't redefine type for operand"));
1388 return FAIL;
1389 }
1390 atype.defined |= NTA_HASTYPE;
1391 atype.eltype = parsetype;
1392 }
5f4273c7 1393
dcbf9037
JB
1394 if (skip_past_char (&str, '[') == SUCCESS)
1395 {
1396 if (type != REG_TYPE_VFD)
1397 {
1398 first_error (_("only D registers may be indexed"));
1399 return FAIL;
1400 }
5f4273c7 1401
dcbf9037
JB
1402 if ((atype.defined & NTA_HASINDEX) != 0)
1403 {
1404 first_error (_("can't change index for operand"));
1405 return FAIL;
1406 }
1407
1408 atype.defined |= NTA_HASINDEX;
1409
1410 if (skip_past_char (&str, ']') == SUCCESS)
1411 atype.index = NEON_ALL_LANES;
1412 else
1413 {
1414 expressionS exp;
1415
1416 my_get_expression (&exp, &str, GE_NO_PREFIX);
1417
1418 if (exp.X_op != O_constant)
1419 {
1420 first_error (_("constant expression required"));
1421 return FAIL;
1422 }
1423
1424 if (skip_past_char (&str, ']') == FAIL)
1425 return FAIL;
1426
1427 atype.index = exp.X_add_number;
1428 }
1429 }
5f4273c7 1430
dcbf9037
JB
1431 if (typeinfo)
1432 *typeinfo = atype;
5f4273c7 1433
dcbf9037
JB
1434 if (rtype)
1435 *rtype = type;
5f4273c7 1436
dcbf9037 1437 *ccp = str;
5f4273c7 1438
dcbf9037
JB
1439 return reg->number;
1440}
1441
1442/* Like arm_reg_parse, but allow allow the following extra features:
1443 - If RTYPE is non-zero, return the (possibly restricted) type of the
1444 register (e.g. Neon double or quad reg when either has been requested).
1445 - If this is a Neon vector type with additional type information, fill
1446 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1447 This function will fault on encountering a scalar. */
dcbf9037
JB
1448
1449static int
1450arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1451 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1452{
1453 struct neon_typed_alias atype;
1454 char *str = *ccp;
1455 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1456
1457 if (reg == FAIL)
1458 return FAIL;
1459
1460 /* Do not allow a scalar (reg+index) to parse as a register. */
1461 if ((atype.defined & NTA_HASINDEX) != 0)
1462 {
1463 first_error (_("register operand expected, but got scalar"));
1464 return FAIL;
1465 }
1466
1467 if (vectype)
1468 *vectype = atype.eltype;
1469
1470 *ccp = str;
1471
1472 return reg;
1473}
1474
1475#define NEON_SCALAR_REG(X) ((X) >> 4)
1476#define NEON_SCALAR_INDEX(X) ((X) & 15)
1477
5287ad62
JB
1478/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1479 have enough information to be able to do a good job bounds-checking. So, we
1480 just do easy checks here, and do further checks later. */
1481
1482static int
dcbf9037 1483parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1484{
dcbf9037 1485 int reg;
5287ad62 1486 char *str = *ccp;
dcbf9037 1487 struct neon_typed_alias atype;
5f4273c7 1488
dcbf9037 1489 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1490
dcbf9037 1491 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1492 return FAIL;
5f4273c7 1493
dcbf9037 1494 if (atype.index == NEON_ALL_LANES)
5287ad62 1495 {
dcbf9037 1496 first_error (_("scalar must have an index"));
5287ad62
JB
1497 return FAIL;
1498 }
dcbf9037 1499 else if (atype.index >= 64 / elsize)
5287ad62 1500 {
dcbf9037 1501 first_error (_("scalar index out of range"));
5287ad62
JB
1502 return FAIL;
1503 }
5f4273c7 1504
dcbf9037
JB
1505 if (type)
1506 *type = atype.eltype;
5f4273c7 1507
5287ad62 1508 *ccp = str;
5f4273c7 1509
dcbf9037 1510 return reg * 16 + atype.index;
5287ad62
JB
1511}
1512
c19d1205 1513/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1514
c19d1205
ZW
1515static long
1516parse_reg_list (char ** strp)
1517{
1518 char * str = * strp;
1519 long range = 0;
1520 int another_range;
a737bd4d 1521
c19d1205
ZW
1522 /* We come back here if we get ranges concatenated by '+' or '|'. */
1523 do
6057a28f 1524 {
c19d1205 1525 another_range = 0;
a737bd4d 1526
c19d1205
ZW
1527 if (*str == '{')
1528 {
1529 int in_range = 0;
1530 int cur_reg = -1;
a737bd4d 1531
c19d1205
ZW
1532 str++;
1533 do
1534 {
1535 int reg;
6057a28f 1536
dcbf9037 1537 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1538 {
dcbf9037 1539 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1540 return FAIL;
1541 }
a737bd4d 1542
c19d1205
ZW
1543 if (in_range)
1544 {
1545 int i;
a737bd4d 1546
c19d1205
ZW
1547 if (reg <= cur_reg)
1548 {
dcbf9037 1549 first_error (_("bad range in register list"));
c19d1205
ZW
1550 return FAIL;
1551 }
40a18ebd 1552
c19d1205
ZW
1553 for (i = cur_reg + 1; i < reg; i++)
1554 {
1555 if (range & (1 << i))
1556 as_tsktsk
1557 (_("Warning: duplicated register (r%d) in register list"),
1558 i);
1559 else
1560 range |= 1 << i;
1561 }
1562 in_range = 0;
1563 }
a737bd4d 1564
c19d1205
ZW
1565 if (range & (1 << reg))
1566 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1567 reg);
1568 else if (reg <= cur_reg)
1569 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1570
c19d1205
ZW
1571 range |= 1 << reg;
1572 cur_reg = reg;
1573 }
1574 while (skip_past_comma (&str) != FAIL
1575 || (in_range = 1, *str++ == '-'));
1576 str--;
a737bd4d 1577
c19d1205
ZW
1578 if (*str++ != '}')
1579 {
dcbf9037 1580 first_error (_("missing `}'"));
c19d1205
ZW
1581 return FAIL;
1582 }
1583 }
1584 else
1585 {
1586 expressionS expr;
40a18ebd 1587
c19d1205
ZW
1588 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1589 return FAIL;
40a18ebd 1590
c19d1205
ZW
1591 if (expr.X_op == O_constant)
1592 {
1593 if (expr.X_add_number
1594 != (expr.X_add_number & 0x0000ffff))
1595 {
1596 inst.error = _("invalid register mask");
1597 return FAIL;
1598 }
a737bd4d 1599
c19d1205
ZW
1600 if ((range & expr.X_add_number) != 0)
1601 {
1602 int regno = range & expr.X_add_number;
a737bd4d 1603
c19d1205
ZW
1604 regno &= -regno;
1605 regno = (1 << regno) - 1;
1606 as_tsktsk
1607 (_("Warning: duplicated register (r%d) in register list"),
1608 regno);
1609 }
a737bd4d 1610
c19d1205
ZW
1611 range |= expr.X_add_number;
1612 }
1613 else
1614 {
1615 if (inst.reloc.type != 0)
1616 {
1617 inst.error = _("expression too complex");
1618 return FAIL;
1619 }
a737bd4d 1620
c19d1205
ZW
1621 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1622 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1623 inst.reloc.pc_rel = 0;
1624 }
1625 }
a737bd4d 1626
c19d1205
ZW
1627 if (*str == '|' || *str == '+')
1628 {
1629 str++;
1630 another_range = 1;
1631 }
a737bd4d 1632 }
c19d1205 1633 while (another_range);
a737bd4d 1634
c19d1205
ZW
1635 *strp = str;
1636 return range;
a737bd4d
NC
1637}
1638
5287ad62
JB
1639/* Types of registers in a list. */
1640
1641enum reg_list_els
1642{
1643 REGLIST_VFP_S,
1644 REGLIST_VFP_D,
1645 REGLIST_NEON_D
1646};
1647
c19d1205
ZW
1648/* Parse a VFP register list. If the string is invalid return FAIL.
1649 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1650 register. Parses registers of type ETYPE.
1651 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1652 - Q registers can be used to specify pairs of D registers
1653 - { } can be omitted from around a singleton register list
1654 FIXME: This is not implemented, as it would require backtracking in
1655 some cases, e.g.:
1656 vtbl.8 d3,d4,d5
1657 This could be done (the meaning isn't really ambiguous), but doesn't
1658 fit in well with the current parsing framework.
dcbf9037
JB
1659 - 32 D registers may be used (also true for VFPv3).
1660 FIXME: Types are ignored in these register lists, which is probably a
1661 bug. */
6057a28f 1662
c19d1205 1663static int
037e8744 1664parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1665{
037e8744 1666 char *str = *ccp;
c19d1205
ZW
1667 int base_reg;
1668 int new_base;
21d799b5 1669 enum arm_reg_type regtype = (enum arm_reg_type) 0;
5287ad62 1670 int max_regs = 0;
c19d1205
ZW
1671 int count = 0;
1672 int warned = 0;
1673 unsigned long mask = 0;
a737bd4d 1674 int i;
6057a28f 1675
037e8744 1676 if (*str != '{')
5287ad62
JB
1677 {
1678 inst.error = _("expecting {");
1679 return FAIL;
1680 }
6057a28f 1681
037e8744 1682 str++;
6057a28f 1683
5287ad62 1684 switch (etype)
c19d1205 1685 {
5287ad62 1686 case REGLIST_VFP_S:
c19d1205
ZW
1687 regtype = REG_TYPE_VFS;
1688 max_regs = 32;
5287ad62 1689 break;
5f4273c7 1690
5287ad62
JB
1691 case REGLIST_VFP_D:
1692 regtype = REG_TYPE_VFD;
b7fc2769 1693 break;
5f4273c7 1694
b7fc2769
JB
1695 case REGLIST_NEON_D:
1696 regtype = REG_TYPE_NDQ;
1697 break;
1698 }
1699
1700 if (etype != REGLIST_VFP_S)
1701 {
b1cc4aeb
PB
1702 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1703 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1704 {
1705 max_regs = 32;
1706 if (thumb_mode)
1707 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1708 fpu_vfp_ext_d32);
5287ad62
JB
1709 else
1710 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1711 fpu_vfp_ext_d32);
5287ad62
JB
1712 }
1713 else
1714 max_regs = 16;
c19d1205 1715 }
6057a28f 1716
c19d1205 1717 base_reg = max_regs;
a737bd4d 1718
c19d1205
ZW
1719 do
1720 {
5287ad62 1721 int setmask = 1, addregs = 1;
dcbf9037 1722
037e8744 1723 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1724
c19d1205 1725 if (new_base == FAIL)
a737bd4d 1726 {
dcbf9037 1727 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1728 return FAIL;
1729 }
5f4273c7 1730
b7fc2769
JB
1731 if (new_base >= max_regs)
1732 {
1733 first_error (_("register out of range in list"));
1734 return FAIL;
1735 }
5f4273c7 1736
5287ad62
JB
1737 /* Note: a value of 2 * n is returned for the register Q<n>. */
1738 if (regtype == REG_TYPE_NQ)
1739 {
1740 setmask = 3;
1741 addregs = 2;
1742 }
1743
c19d1205
ZW
1744 if (new_base < base_reg)
1745 base_reg = new_base;
a737bd4d 1746
5287ad62 1747 if (mask & (setmask << new_base))
c19d1205 1748 {
dcbf9037 1749 first_error (_("invalid register list"));
c19d1205 1750 return FAIL;
a737bd4d 1751 }
a737bd4d 1752
c19d1205
ZW
1753 if ((mask >> new_base) != 0 && ! warned)
1754 {
1755 as_tsktsk (_("register list not in ascending order"));
1756 warned = 1;
1757 }
0bbf2aa4 1758
5287ad62
JB
1759 mask |= setmask << new_base;
1760 count += addregs;
0bbf2aa4 1761
037e8744 1762 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1763 {
1764 int high_range;
0bbf2aa4 1765
037e8744 1766 str++;
0bbf2aa4 1767
037e8744 1768 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1769 == FAIL)
c19d1205
ZW
1770 {
1771 inst.error = gettext (reg_expected_msgs[regtype]);
1772 return FAIL;
1773 }
0bbf2aa4 1774
b7fc2769
JB
1775 if (high_range >= max_regs)
1776 {
1777 first_error (_("register out of range in list"));
1778 return FAIL;
1779 }
1780
5287ad62
JB
1781 if (regtype == REG_TYPE_NQ)
1782 high_range = high_range + 1;
1783
c19d1205
ZW
1784 if (high_range <= new_base)
1785 {
1786 inst.error = _("register range not in ascending order");
1787 return FAIL;
1788 }
0bbf2aa4 1789
5287ad62 1790 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1791 {
5287ad62 1792 if (mask & (setmask << new_base))
0bbf2aa4 1793 {
c19d1205
ZW
1794 inst.error = _("invalid register list");
1795 return FAIL;
0bbf2aa4 1796 }
c19d1205 1797
5287ad62
JB
1798 mask |= setmask << new_base;
1799 count += addregs;
0bbf2aa4 1800 }
0bbf2aa4 1801 }
0bbf2aa4 1802 }
037e8744 1803 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1804
037e8744 1805 str++;
0bbf2aa4 1806
c19d1205
ZW
1807 /* Sanity check -- should have raised a parse error above. */
1808 if (count == 0 || count > max_regs)
1809 abort ();
1810
1811 *pbase = base_reg;
1812
1813 /* Final test -- the registers must be consecutive. */
1814 mask >>= base_reg;
1815 for (i = 0; i < count; i++)
1816 {
1817 if ((mask & (1u << i)) == 0)
1818 {
1819 inst.error = _("non-contiguous register range");
1820 return FAIL;
1821 }
1822 }
1823
037e8744
JB
1824 *ccp = str;
1825
c19d1205 1826 return count;
b99bd4ef
NC
1827}
1828
dcbf9037
JB
1829/* True if two alias types are the same. */
1830
c921be7d 1831static bfd_boolean
dcbf9037
JB
1832neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1833{
1834 if (!a && !b)
c921be7d 1835 return TRUE;
5f4273c7 1836
dcbf9037 1837 if (!a || !b)
c921be7d 1838 return FALSE;
dcbf9037
JB
1839
1840 if (a->defined != b->defined)
c921be7d 1841 return FALSE;
5f4273c7 1842
dcbf9037
JB
1843 if ((a->defined & NTA_HASTYPE) != 0
1844 && (a->eltype.type != b->eltype.type
1845 || a->eltype.size != b->eltype.size))
c921be7d 1846 return FALSE;
dcbf9037
JB
1847
1848 if ((a->defined & NTA_HASINDEX) != 0
1849 && (a->index != b->index))
c921be7d 1850 return FALSE;
5f4273c7 1851
c921be7d 1852 return TRUE;
dcbf9037
JB
1853}
1854
5287ad62
JB
1855/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1856 The base register is put in *PBASE.
dcbf9037 1857 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1858 the return value.
1859 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1860 Bits [6:5] encode the list length (minus one).
1861 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1862
5287ad62 1863#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1864#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1865#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1866
1867static int
dcbf9037
JB
1868parse_neon_el_struct_list (char **str, unsigned *pbase,
1869 struct neon_type_el *eltype)
5287ad62
JB
1870{
1871 char *ptr = *str;
1872 int base_reg = -1;
1873 int reg_incr = -1;
1874 int count = 0;
1875 int lane = -1;
1876 int leading_brace = 0;
1877 enum arm_reg_type rtype = REG_TYPE_NDQ;
1878 int addregs = 1;
20203fb9
NC
1879 const char *const incr_error = _("register stride must be 1 or 2");
1880 const char *const type_error = _("mismatched element/structure types in list");
dcbf9037 1881 struct neon_typed_alias firsttype;
5f4273c7 1882
5287ad62
JB
1883 if (skip_past_char (&ptr, '{') == SUCCESS)
1884 leading_brace = 1;
5f4273c7 1885
5287ad62
JB
1886 do
1887 {
dcbf9037
JB
1888 struct neon_typed_alias atype;
1889 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1890
5287ad62
JB
1891 if (getreg == FAIL)
1892 {
dcbf9037 1893 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1894 return FAIL;
1895 }
5f4273c7 1896
5287ad62
JB
1897 if (base_reg == -1)
1898 {
1899 base_reg = getreg;
1900 if (rtype == REG_TYPE_NQ)
1901 {
1902 reg_incr = 1;
1903 addregs = 2;
1904 }
dcbf9037 1905 firsttype = atype;
5287ad62
JB
1906 }
1907 else if (reg_incr == -1)
1908 {
1909 reg_incr = getreg - base_reg;
1910 if (reg_incr < 1 || reg_incr > 2)
1911 {
dcbf9037 1912 first_error (_(incr_error));
5287ad62
JB
1913 return FAIL;
1914 }
1915 }
1916 else if (getreg != base_reg + reg_incr * count)
1917 {
dcbf9037
JB
1918 first_error (_(incr_error));
1919 return FAIL;
1920 }
1921
c921be7d 1922 if (! neon_alias_types_same (&atype, &firsttype))
dcbf9037
JB
1923 {
1924 first_error (_(type_error));
5287ad62
JB
1925 return FAIL;
1926 }
5f4273c7 1927
5287ad62
JB
1928 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1929 modes. */
1930 if (ptr[0] == '-')
1931 {
dcbf9037 1932 struct neon_typed_alias htype;
5287ad62
JB
1933 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1934 if (lane == -1)
1935 lane = NEON_INTERLEAVE_LANES;
1936 else if (lane != NEON_INTERLEAVE_LANES)
1937 {
dcbf9037 1938 first_error (_(type_error));
5287ad62
JB
1939 return FAIL;
1940 }
1941 if (reg_incr == -1)
1942 reg_incr = 1;
1943 else if (reg_incr != 1)
1944 {
dcbf9037 1945 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1946 return FAIL;
1947 }
1948 ptr++;
dcbf9037 1949 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1950 if (hireg == FAIL)
1951 {
dcbf9037
JB
1952 first_error (_(reg_expected_msgs[rtype]));
1953 return FAIL;
1954 }
c921be7d 1955 if (! neon_alias_types_same (&htype, &firsttype))
dcbf9037
JB
1956 {
1957 first_error (_(type_error));
5287ad62
JB
1958 return FAIL;
1959 }
1960 count += hireg + dregs - getreg;
1961 continue;
1962 }
5f4273c7 1963
5287ad62
JB
1964 /* If we're using Q registers, we can't use [] or [n] syntax. */
1965 if (rtype == REG_TYPE_NQ)
1966 {
1967 count += 2;
1968 continue;
1969 }
5f4273c7 1970
dcbf9037 1971 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1972 {
dcbf9037
JB
1973 if (lane == -1)
1974 lane = atype.index;
1975 else if (lane != atype.index)
5287ad62 1976 {
dcbf9037
JB
1977 first_error (_(type_error));
1978 return FAIL;
5287ad62
JB
1979 }
1980 }
1981 else if (lane == -1)
1982 lane = NEON_INTERLEAVE_LANES;
1983 else if (lane != NEON_INTERLEAVE_LANES)
1984 {
dcbf9037 1985 first_error (_(type_error));
5287ad62
JB
1986 return FAIL;
1987 }
1988 count++;
1989 }
1990 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1991
5287ad62
JB
1992 /* No lane set by [x]. We must be interleaving structures. */
1993 if (lane == -1)
1994 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1995
5287ad62
JB
1996 /* Sanity check. */
1997 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1998 || (count > 1 && reg_incr == -1))
1999 {
dcbf9037 2000 first_error (_("error parsing element/structure list"));
5287ad62
JB
2001 return FAIL;
2002 }
2003
2004 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
2005 {
dcbf9037 2006 first_error (_("expected }"));
5287ad62
JB
2007 return FAIL;
2008 }
5f4273c7 2009
5287ad62
JB
2010 if (reg_incr == -1)
2011 reg_incr = 1;
2012
dcbf9037
JB
2013 if (eltype)
2014 *eltype = firsttype.eltype;
2015
5287ad62
JB
2016 *pbase = base_reg;
2017 *str = ptr;
5f4273c7 2018
5287ad62
JB
2019 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2020}
2021
c19d1205
ZW
2022/* Parse an explicit relocation suffix on an expression. This is
2023 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2024 arm_reloc_hsh contains no entries, so this function can only
2025 succeed if there is no () after the word. Returns -1 on error,
2026 BFD_RELOC_UNUSED if there wasn't any suffix. */
2027static int
2028parse_reloc (char **str)
b99bd4ef 2029{
c19d1205
ZW
2030 struct reloc_entry *r;
2031 char *p, *q;
b99bd4ef 2032
c19d1205
ZW
2033 if (**str != '(')
2034 return BFD_RELOC_UNUSED;
b99bd4ef 2035
c19d1205
ZW
2036 p = *str + 1;
2037 q = p;
2038
2039 while (*q && *q != ')' && *q != ',')
2040 q++;
2041 if (*q != ')')
2042 return -1;
2043
21d799b5
NC
2044 if ((r = (struct reloc_entry *)
2045 hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
c19d1205
ZW
2046 return -1;
2047
2048 *str = q + 1;
2049 return r->reloc;
b99bd4ef
NC
2050}
2051
c19d1205
ZW
2052/* Directives: register aliases. */
2053
dcbf9037 2054static struct reg_entry *
c19d1205 2055insert_reg_alias (char *str, int number, int type)
b99bd4ef 2056{
d3ce72d0 2057 struct reg_entry *new_reg;
c19d1205 2058 const char *name;
b99bd4ef 2059
d3ce72d0 2060 if ((new_reg = (struct reg_entry *) hash_find (arm_reg_hsh, str)) != 0)
c19d1205 2061 {
d3ce72d0 2062 if (new_reg->builtin)
c19d1205 2063 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2064
c19d1205
ZW
2065 /* Only warn about a redefinition if it's not defined as the
2066 same register. */
d3ce72d0 2067 else if (new_reg->number != number || new_reg->type != type)
c19d1205 2068 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2069
d929913e 2070 return NULL;
c19d1205 2071 }
b99bd4ef 2072
c19d1205 2073 name = xstrdup (str);
d3ce72d0 2074 new_reg = (struct reg_entry *) xmalloc (sizeof (struct reg_entry));
b99bd4ef 2075
d3ce72d0
NC
2076 new_reg->name = name;
2077 new_reg->number = number;
2078 new_reg->type = type;
2079 new_reg->builtin = FALSE;
2080 new_reg->neon = NULL;
b99bd4ef 2081
d3ce72d0 2082 if (hash_insert (arm_reg_hsh, name, (void *) new_reg))
c19d1205 2083 abort ();
5f4273c7 2084
d3ce72d0 2085 return new_reg;
dcbf9037
JB
2086}
2087
2088static void
2089insert_neon_reg_alias (char *str, int number, int type,
2090 struct neon_typed_alias *atype)
2091{
2092 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2093
dcbf9037
JB
2094 if (!reg)
2095 {
2096 first_error (_("attempt to redefine typed alias"));
2097 return;
2098 }
5f4273c7 2099
dcbf9037
JB
2100 if (atype)
2101 {
21d799b5
NC
2102 reg->neon = (struct neon_typed_alias *)
2103 xmalloc (sizeof (struct neon_typed_alias));
dcbf9037
JB
2104 *reg->neon = *atype;
2105 }
c19d1205 2106}
b99bd4ef 2107
c19d1205 2108/* Look for the .req directive. This is of the form:
b99bd4ef 2109
c19d1205 2110 new_register_name .req existing_register_name
b99bd4ef 2111
c19d1205 2112 If we find one, or if it looks sufficiently like one that we want to
d929913e 2113 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2114
d929913e 2115static bfd_boolean
c19d1205
ZW
2116create_register_alias (char * newname, char *p)
2117{
2118 struct reg_entry *old;
2119 char *oldname, *nbuf;
2120 size_t nlen;
b99bd4ef 2121
c19d1205
ZW
2122 /* The input scrubber ensures that whitespace after the mnemonic is
2123 collapsed to single spaces. */
2124 oldname = p;
2125 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2126 return FALSE;
b99bd4ef 2127
c19d1205
ZW
2128 oldname += 6;
2129 if (*oldname == '\0')
d929913e 2130 return FALSE;
b99bd4ef 2131
21d799b5 2132 old = (struct reg_entry *) hash_find (arm_reg_hsh, oldname);
c19d1205 2133 if (!old)
b99bd4ef 2134 {
c19d1205 2135 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2136 return TRUE;
b99bd4ef
NC
2137 }
2138
c19d1205
ZW
2139 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2140 the desired alias name, and p points to its end. If not, then
2141 the desired alias name is in the global original_case_string. */
2142#ifdef TC_CASE_SENSITIVE
2143 nlen = p - newname;
2144#else
2145 newname = original_case_string;
2146 nlen = strlen (newname);
2147#endif
b99bd4ef 2148
21d799b5 2149 nbuf = (char *) alloca (nlen + 1);
c19d1205
ZW
2150 memcpy (nbuf, newname, nlen);
2151 nbuf[nlen] = '\0';
b99bd4ef 2152
c19d1205
ZW
2153 /* Create aliases under the new name as stated; an all-lowercase
2154 version of the new name; and an all-uppercase version of the new
2155 name. */
d929913e
NC
2156 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2157 {
2158 for (p = nbuf; *p; p++)
2159 *p = TOUPPER (*p);
c19d1205 2160
d929913e
NC
2161 if (strncmp (nbuf, newname, nlen))
2162 {
2163 /* If this attempt to create an additional alias fails, do not bother
2164 trying to create the all-lower case alias. We will fail and issue
2165 a second, duplicate error message. This situation arises when the
2166 programmer does something like:
2167 foo .req r0
2168 Foo .req r1
2169 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2170 the artificial FOO alias because it has already been created by the
d929913e
NC
2171 first .req. */
2172 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2173 return TRUE;
2174 }
c19d1205 2175
d929913e
NC
2176 for (p = nbuf; *p; p++)
2177 *p = TOLOWER (*p);
c19d1205 2178
d929913e
NC
2179 if (strncmp (nbuf, newname, nlen))
2180 insert_reg_alias (nbuf, old->number, old->type);
2181 }
c19d1205 2182
d929913e 2183 return TRUE;
b99bd4ef
NC
2184}
2185
dcbf9037
JB
2186/* Create a Neon typed/indexed register alias using directives, e.g.:
2187 X .dn d5.s32[1]
2188 Y .qn 6.s16
2189 Z .dn d7
2190 T .dn Z[0]
2191 These typed registers can be used instead of the types specified after the
2192 Neon mnemonic, so long as all operands given have types. Types can also be
2193 specified directly, e.g.:
5f4273c7 2194 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037 2195
c921be7d 2196static bfd_boolean
dcbf9037
JB
2197create_neon_reg_alias (char *newname, char *p)
2198{
2199 enum arm_reg_type basetype;
2200 struct reg_entry *basereg;
2201 struct reg_entry mybasereg;
2202 struct neon_type ntype;
2203 struct neon_typed_alias typeinfo;
2204 char *namebuf, *nameend;
2205 int namelen;
5f4273c7 2206
dcbf9037
JB
2207 typeinfo.defined = 0;
2208 typeinfo.eltype.type = NT_invtype;
2209 typeinfo.eltype.size = -1;
2210 typeinfo.index = -1;
5f4273c7 2211
dcbf9037 2212 nameend = p;
5f4273c7 2213
dcbf9037
JB
2214 if (strncmp (p, " .dn ", 5) == 0)
2215 basetype = REG_TYPE_VFD;
2216 else if (strncmp (p, " .qn ", 5) == 0)
2217 basetype = REG_TYPE_NQ;
2218 else
c921be7d 2219 return FALSE;
5f4273c7 2220
dcbf9037 2221 p += 5;
5f4273c7 2222
dcbf9037 2223 if (*p == '\0')
c921be7d 2224 return FALSE;
5f4273c7 2225
dcbf9037
JB
2226 basereg = arm_reg_parse_multi (&p);
2227
2228 if (basereg && basereg->type != basetype)
2229 {
2230 as_bad (_("bad type for register"));
c921be7d 2231 return FALSE;
dcbf9037
JB
2232 }
2233
2234 if (basereg == NULL)
2235 {
2236 expressionS exp;
2237 /* Try parsing as an integer. */
2238 my_get_expression (&exp, &p, GE_NO_PREFIX);
2239 if (exp.X_op != O_constant)
2240 {
2241 as_bad (_("expression must be constant"));
c921be7d 2242 return FALSE;
dcbf9037
JB
2243 }
2244 basereg = &mybasereg;
2245 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2246 : exp.X_add_number;
2247 basereg->neon = 0;
2248 }
2249
2250 if (basereg->neon)
2251 typeinfo = *basereg->neon;
2252
2253 if (parse_neon_type (&ntype, &p) == SUCCESS)
2254 {
2255 /* We got a type. */
2256 if (typeinfo.defined & NTA_HASTYPE)
2257 {
2258 as_bad (_("can't redefine the type of a register alias"));
c921be7d 2259 return FALSE;
dcbf9037 2260 }
5f4273c7 2261
dcbf9037
JB
2262 typeinfo.defined |= NTA_HASTYPE;
2263 if (ntype.elems != 1)
2264 {
2265 as_bad (_("you must specify a single type only"));
c921be7d 2266 return FALSE;
dcbf9037
JB
2267 }
2268 typeinfo.eltype = ntype.el[0];
2269 }
5f4273c7 2270
dcbf9037
JB
2271 if (skip_past_char (&p, '[') == SUCCESS)
2272 {
2273 expressionS exp;
2274 /* We got a scalar index. */
5f4273c7 2275
dcbf9037
JB
2276 if (typeinfo.defined & NTA_HASINDEX)
2277 {
2278 as_bad (_("can't redefine the index of a scalar alias"));
c921be7d 2279 return FALSE;
dcbf9037 2280 }
5f4273c7 2281
dcbf9037 2282 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2283
dcbf9037
JB
2284 if (exp.X_op != O_constant)
2285 {
2286 as_bad (_("scalar index must be constant"));
c921be7d 2287 return FALSE;
dcbf9037 2288 }
5f4273c7 2289
dcbf9037
JB
2290 typeinfo.defined |= NTA_HASINDEX;
2291 typeinfo.index = exp.X_add_number;
5f4273c7 2292
dcbf9037
JB
2293 if (skip_past_char (&p, ']') == FAIL)
2294 {
2295 as_bad (_("expecting ]"));
c921be7d 2296 return FALSE;
dcbf9037
JB
2297 }
2298 }
2299
2300 namelen = nameend - newname;
21d799b5 2301 namebuf = (char *) alloca (namelen + 1);
dcbf9037
JB
2302 strncpy (namebuf, newname, namelen);
2303 namebuf[namelen] = '\0';
5f4273c7 2304
dcbf9037
JB
2305 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2306 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2307
dcbf9037
JB
2308 /* Insert name in all uppercase. */
2309 for (p = namebuf; *p; p++)
2310 *p = TOUPPER (*p);
5f4273c7 2311
dcbf9037
JB
2312 if (strncmp (namebuf, newname, namelen))
2313 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2314 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2315
dcbf9037
JB
2316 /* Insert name in all lowercase. */
2317 for (p = namebuf; *p; p++)
2318 *p = TOLOWER (*p);
5f4273c7 2319
dcbf9037
JB
2320 if (strncmp (namebuf, newname, namelen))
2321 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2322 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2323
c921be7d 2324 return TRUE;
dcbf9037
JB
2325}
2326
c19d1205
ZW
2327/* Should never be called, as .req goes between the alias and the
2328 register name, not at the beginning of the line. */
c921be7d 2329
b99bd4ef 2330static void
c19d1205 2331s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2332{
c19d1205
ZW
2333 as_bad (_("invalid syntax for .req directive"));
2334}
b99bd4ef 2335
dcbf9037
JB
2336static void
2337s_dn (int a ATTRIBUTE_UNUSED)
2338{
2339 as_bad (_("invalid syntax for .dn directive"));
2340}
2341
2342static void
2343s_qn (int a ATTRIBUTE_UNUSED)
2344{
2345 as_bad (_("invalid syntax for .qn directive"));
2346}
2347
c19d1205
ZW
2348/* The .unreq directive deletes an alias which was previously defined
2349 by .req. For example:
b99bd4ef 2350
c19d1205
ZW
2351 my_alias .req r11
2352 .unreq my_alias */
b99bd4ef
NC
2353
2354static void
c19d1205 2355s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2356{
c19d1205
ZW
2357 char * name;
2358 char saved_char;
b99bd4ef 2359
c19d1205
ZW
2360 name = input_line_pointer;
2361
2362 while (*input_line_pointer != 0
2363 && *input_line_pointer != ' '
2364 && *input_line_pointer != '\n')
2365 ++input_line_pointer;
2366
2367 saved_char = *input_line_pointer;
2368 *input_line_pointer = 0;
2369
2370 if (!*name)
2371 as_bad (_("invalid syntax for .unreq directive"));
2372 else
2373 {
21d799b5
NC
2374 struct reg_entry *reg = (struct reg_entry *) hash_find (arm_reg_hsh,
2375 name);
c19d1205
ZW
2376
2377 if (!reg)
2378 as_bad (_("unknown register alias '%s'"), name);
2379 else if (reg->builtin)
2380 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2381 name);
2382 else
2383 {
d929913e
NC
2384 char * p;
2385 char * nbuf;
2386
db0bc284 2387 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2388 free ((char *) reg->name);
dcbf9037
JB
2389 if (reg->neon)
2390 free (reg->neon);
c19d1205 2391 free (reg);
d929913e
NC
2392
2393 /* Also locate the all upper case and all lower case versions.
2394 Do not complain if we cannot find one or the other as it
2395 was probably deleted above. */
5f4273c7 2396
d929913e
NC
2397 nbuf = strdup (name);
2398 for (p = nbuf; *p; p++)
2399 *p = TOUPPER (*p);
21d799b5 2400 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2401 if (reg)
2402 {
db0bc284 2403 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2404 free ((char *) reg->name);
2405 if (reg->neon)
2406 free (reg->neon);
2407 free (reg);
2408 }
2409
2410 for (p = nbuf; *p; p++)
2411 *p = TOLOWER (*p);
21d799b5 2412 reg = (struct reg_entry *) hash_find (arm_reg_hsh, nbuf);
d929913e
NC
2413 if (reg)
2414 {
db0bc284 2415 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2416 free ((char *) reg->name);
2417 if (reg->neon)
2418 free (reg->neon);
2419 free (reg);
2420 }
2421
2422 free (nbuf);
c19d1205
ZW
2423 }
2424 }
b99bd4ef 2425
c19d1205 2426 *input_line_pointer = saved_char;
b99bd4ef
NC
2427 demand_empty_rest_of_line ();
2428}
2429
c19d1205
ZW
2430/* Directives: Instruction set selection. */
2431
2432#ifdef OBJ_ELF
2433/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2434 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2435 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2436 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2437
cd000bff
DJ
2438/* Create a new mapping symbol for the transition to STATE. */
2439
2440static void
2441make_mapping_symbol (enum mstate state, valueT value, fragS *frag)
b99bd4ef 2442{
a737bd4d 2443 symbolS * symbolP;
c19d1205
ZW
2444 const char * symname;
2445 int type;
b99bd4ef 2446
c19d1205 2447 switch (state)
b99bd4ef 2448 {
c19d1205
ZW
2449 case MAP_DATA:
2450 symname = "$d";
2451 type = BSF_NO_FLAGS;
2452 break;
2453 case MAP_ARM:
2454 symname = "$a";
2455 type = BSF_NO_FLAGS;
2456 break;
2457 case MAP_THUMB:
2458 symname = "$t";
2459 type = BSF_NO_FLAGS;
2460 break;
c19d1205
ZW
2461 default:
2462 abort ();
2463 }
2464
cd000bff 2465 symbolP = symbol_new (symname, now_seg, value, frag);
c19d1205
ZW
2466 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2467
2468 switch (state)
2469 {
2470 case MAP_ARM:
2471 THUMB_SET_FUNC (symbolP, 0);
2472 ARM_SET_THUMB (symbolP, 0);
2473 ARM_SET_INTERWORK (symbolP, support_interwork);
2474 break;
2475
2476 case MAP_THUMB:
2477 THUMB_SET_FUNC (symbolP, 1);
2478 ARM_SET_THUMB (symbolP, 1);
2479 ARM_SET_INTERWORK (symbolP, support_interwork);
2480 break;
2481
2482 case MAP_DATA:
2483 default:
cd000bff
DJ
2484 break;
2485 }
2486
2487 /* Save the mapping symbols for future reference. Also check that
2488 we do not place two mapping symbols at the same offset within a
2489 frag. We'll handle overlap between frags in
2490 check_mapping_symbols. */
2491 if (value == 0)
2492 {
2493 know (frag->tc_frag_data.first_map == NULL);
2494 frag->tc_frag_data.first_map = symbolP;
2495 }
2496 if (frag->tc_frag_data.last_map != NULL)
c5ed243b 2497 know (S_GET_VALUE (frag->tc_frag_data.last_map) < S_GET_VALUE (symbolP));
cd000bff
DJ
2498 frag->tc_frag_data.last_map = symbolP;
2499}
2500
2501/* We must sometimes convert a region marked as code to data during
2502 code alignment, if an odd number of bytes have to be padded. The
2503 code mapping symbol is pushed to an aligned address. */
2504
2505static void
2506insert_data_mapping_symbol (enum mstate state,
2507 valueT value, fragS *frag, offsetT bytes)
2508{
2509 /* If there was already a mapping symbol, remove it. */
2510 if (frag->tc_frag_data.last_map != NULL
2511 && S_GET_VALUE (frag->tc_frag_data.last_map) == frag->fr_address + value)
2512 {
2513 symbolS *symp = frag->tc_frag_data.last_map;
2514
2515 if (value == 0)
2516 {
2517 know (frag->tc_frag_data.first_map == symp);
2518 frag->tc_frag_data.first_map = NULL;
2519 }
2520 frag->tc_frag_data.last_map = NULL;
2521 symbol_remove (symp, &symbol_rootP, &symbol_lastP);
c19d1205 2522 }
cd000bff
DJ
2523
2524 make_mapping_symbol (MAP_DATA, value, frag);
2525 make_mapping_symbol (state, value + bytes, frag);
2526}
2527
2528static void mapping_state_2 (enum mstate state, int max_chars);
2529
2530/* Set the mapping state to STATE. Only call this when about to
2531 emit some STATE bytes to the file. */
2532
2533void
2534mapping_state (enum mstate state)
2535{
940b5ce0
DJ
2536 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2537
cd000bff
DJ
2538#define TRANSITION(from, to) (mapstate == (from) && state == (to))
2539
2540 if (mapstate == state)
2541 /* The mapping symbol has already been emitted.
2542 There is nothing else to do. */
2543 return;
2544 else if (TRANSITION (MAP_UNDEFINED, MAP_DATA))
2545 /* This case will be evaluated later in the next else. */
2546 return;
2547 else if (TRANSITION (MAP_UNDEFINED, MAP_ARM)
2548 || TRANSITION (MAP_UNDEFINED, MAP_THUMB))
2549 {
2550 /* Only add the symbol if the offset is > 0:
2551 if we're at the first frag, check it's size > 0;
2552 if we're not at the first frag, then for sure
2553 the offset is > 0. */
2554 struct frag * const frag_first = seg_info (now_seg)->frchainP->frch_root;
2555 const int add_symbol = (frag_now != frag_first) || (frag_now_fix () > 0);
2556
2557 if (add_symbol)
2558 make_mapping_symbol (MAP_DATA, (valueT) 0, frag_first);
2559 }
2560
2561 mapping_state_2 (state, 0);
2562#undef TRANSITION
2563}
2564
2565/* Same as mapping_state, but MAX_CHARS bytes have already been
2566 allocated. Put the mapping symbol that far back. */
2567
2568static void
2569mapping_state_2 (enum mstate state, int max_chars)
2570{
940b5ce0
DJ
2571 enum mstate mapstate = seg_info (now_seg)->tc_segment_info_data.mapstate;
2572
2573 if (!SEG_NORMAL (now_seg))
2574 return;
2575
cd000bff
DJ
2576 if (mapstate == state)
2577 /* The mapping symbol has already been emitted.
2578 There is nothing else to do. */
2579 return;
2580
cd000bff
DJ
2581 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2582 make_mapping_symbol (state, (valueT) frag_now_fix () - max_chars, frag_now);
c19d1205
ZW
2583}
2584#else
d3106081
NS
2585#define mapping_state(x) ((void)0)
2586#define mapping_state_2(x, y) ((void)0)
c19d1205
ZW
2587#endif
2588
2589/* Find the real, Thumb encoded start of a Thumb function. */
2590
4343666d 2591#ifdef OBJ_COFF
c19d1205
ZW
2592static symbolS *
2593find_real_start (symbolS * symbolP)
2594{
2595 char * real_start;
2596 const char * name = S_GET_NAME (symbolP);
2597 symbolS * new_target;
2598
2599 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2600#define STUB_NAME ".real_start_of"
2601
2602 if (name == NULL)
2603 abort ();
2604
37f6032b
ZW
2605 /* The compiler may generate BL instructions to local labels because
2606 it needs to perform a branch to a far away location. These labels
2607 do not have a corresponding ".real_start_of" label. We check
2608 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2609 the ".real_start_of" convention for nonlocal branches. */
2610 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2611 return symbolP;
2612
37f6032b 2613 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2614 new_target = symbol_find (real_start);
2615
2616 if (new_target == NULL)
2617 {
bd3ba5d1 2618 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2619 new_target = symbolP;
2620 }
2621
c19d1205
ZW
2622 return new_target;
2623}
4343666d 2624#endif
c19d1205
ZW
2625
2626static void
2627opcode_select (int width)
2628{
2629 switch (width)
2630 {
2631 case 16:
2632 if (! thumb_mode)
2633 {
e74cfd16 2634 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2635 as_bad (_("selected processor does not support THUMB opcodes"));
2636
2637 thumb_mode = 1;
2638 /* No need to force the alignment, since we will have been
2639 coming from ARM mode, which is word-aligned. */
2640 record_alignment (now_seg, 1);
2641 }
c19d1205
ZW
2642 break;
2643
2644 case 32:
2645 if (thumb_mode)
2646 {
e74cfd16 2647 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2648 as_bad (_("selected processor does not support ARM opcodes"));
2649
2650 thumb_mode = 0;
2651
2652 if (!need_pass_2)
2653 frag_align (2, 0, 0);
2654
2655 record_alignment (now_seg, 1);
2656 }
c19d1205
ZW
2657 break;
2658
2659 default:
2660 as_bad (_("invalid instruction size selected (%d)"), width);
2661 }
2662}
2663
2664static void
2665s_arm (int ignore ATTRIBUTE_UNUSED)
2666{
2667 opcode_select (32);
2668 demand_empty_rest_of_line ();
2669}
2670
2671static void
2672s_thumb (int ignore ATTRIBUTE_UNUSED)
2673{
2674 opcode_select (16);
2675 demand_empty_rest_of_line ();
2676}
2677
2678static void
2679s_code (int unused ATTRIBUTE_UNUSED)
2680{
2681 int temp;
2682
2683 temp = get_absolute_expression ();
2684 switch (temp)
2685 {
2686 case 16:
2687 case 32:
2688 opcode_select (temp);
2689 break;
2690
2691 default:
2692 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2693 }
2694}
2695
2696static void
2697s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2698{
2699 /* If we are not already in thumb mode go into it, EVEN if
2700 the target processor does not support thumb instructions.
2701 This is used by gcc/config/arm/lib1funcs.asm for example
2702 to compile interworking support functions even if the
2703 target processor should not support interworking. */
2704 if (! thumb_mode)
2705 {
2706 thumb_mode = 2;
2707 record_alignment (now_seg, 1);
2708 }
2709
2710 demand_empty_rest_of_line ();
2711}
2712
2713static void
2714s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2715{
2716 s_thumb (0);
2717
2718 /* The following label is the name/address of the start of a Thumb function.
2719 We need to know this for the interworking support. */
2720 label_is_thumb_function_name = TRUE;
2721}
2722
2723/* Perform a .set directive, but also mark the alias as
2724 being a thumb function. */
2725
2726static void
2727s_thumb_set (int equiv)
2728{
2729 /* XXX the following is a duplicate of the code for s_set() in read.c
2730 We cannot just call that code as we need to get at the symbol that
2731 is created. */
2732 char * name;
2733 char delim;
2734 char * end_name;
2735 symbolS * symbolP;
2736
2737 /* Especial apologies for the random logic:
2738 This just grew, and could be parsed much more simply!
2739 Dean - in haste. */
2740 name = input_line_pointer;
2741 delim = get_symbol_end ();
2742 end_name = input_line_pointer;
2743 *end_name = delim;
2744
2745 if (*input_line_pointer != ',')
2746 {
2747 *end_name = 0;
2748 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2749 *end_name = delim;
2750 ignore_rest_of_line ();
2751 return;
2752 }
2753
2754 input_line_pointer++;
2755 *end_name = 0;
2756
2757 if (name[0] == '.' && name[1] == '\0')
2758 {
2759 /* XXX - this should not happen to .thumb_set. */
2760 abort ();
2761 }
2762
2763 if ((symbolP = symbol_find (name)) == NULL
2764 && (symbolP = md_undefined_symbol (name)) == NULL)
2765 {
2766#ifndef NO_LISTING
2767 /* When doing symbol listings, play games with dummy fragments living
2768 outside the normal fragment chain to record the file and line info
c19d1205 2769 for this symbol. */
b99bd4ef
NC
2770 if (listing & LISTING_SYMBOLS)
2771 {
2772 extern struct list_info_struct * listing_tail;
21d799b5 2773 fragS * dummy_frag = (fragS * ) xmalloc (sizeof (fragS));
b99bd4ef
NC
2774
2775 memset (dummy_frag, 0, sizeof (fragS));
2776 dummy_frag->fr_type = rs_fill;
2777 dummy_frag->line = listing_tail;
2778 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2779 dummy_frag->fr_symbol = symbolP;
2780 }
2781 else
2782#endif
2783 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2784
2785#ifdef OBJ_COFF
2786 /* "set" symbols are local unless otherwise specified. */
2787 SF_SET_LOCAL (symbolP);
2788#endif /* OBJ_COFF */
2789 } /* Make a new symbol. */
2790
2791 symbol_table_insert (symbolP);
2792
2793 * end_name = delim;
2794
2795 if (equiv
2796 && S_IS_DEFINED (symbolP)
2797 && S_GET_SEGMENT (symbolP) != reg_section)
2798 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2799
2800 pseudo_set (symbolP);
2801
2802 demand_empty_rest_of_line ();
2803
c19d1205 2804 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2805
2806 THUMB_SET_FUNC (symbolP, 1);
2807 ARM_SET_THUMB (symbolP, 1);
2808#if defined OBJ_ELF || defined OBJ_COFF
2809 ARM_SET_INTERWORK (symbolP, support_interwork);
2810#endif
2811}
2812
c19d1205 2813/* Directives: Mode selection. */
b99bd4ef 2814
c19d1205
ZW
2815/* .syntax [unified|divided] - choose the new unified syntax
2816 (same for Arm and Thumb encoding, modulo slight differences in what
2817 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2818static void
c19d1205 2819s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2820{
c19d1205
ZW
2821 char *name, delim;
2822
2823 name = input_line_pointer;
2824 delim = get_symbol_end ();
2825
2826 if (!strcasecmp (name, "unified"))
2827 unified_syntax = TRUE;
2828 else if (!strcasecmp (name, "divided"))
2829 unified_syntax = FALSE;
2830 else
2831 {
2832 as_bad (_("unrecognized syntax mode \"%s\""), name);
2833 return;
2834 }
2835 *input_line_pointer = delim;
b99bd4ef
NC
2836 demand_empty_rest_of_line ();
2837}
2838
c19d1205
ZW
2839/* Directives: sectioning and alignment. */
2840
2841/* Same as s_align_ptwo but align 0 => align 2. */
2842
b99bd4ef 2843static void
c19d1205 2844s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2845{
a737bd4d 2846 int temp;
dce323d1 2847 bfd_boolean fill_p;
c19d1205
ZW
2848 long temp_fill;
2849 long max_alignment = 15;
b99bd4ef
NC
2850
2851 temp = get_absolute_expression ();
c19d1205
ZW
2852 if (temp > max_alignment)
2853 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2854 else if (temp < 0)
b99bd4ef 2855 {
c19d1205
ZW
2856 as_bad (_("alignment negative. 0 assumed."));
2857 temp = 0;
2858 }
b99bd4ef 2859
c19d1205
ZW
2860 if (*input_line_pointer == ',')
2861 {
2862 input_line_pointer++;
2863 temp_fill = get_absolute_expression ();
dce323d1 2864 fill_p = TRUE;
b99bd4ef 2865 }
c19d1205 2866 else
dce323d1
PB
2867 {
2868 fill_p = FALSE;
2869 temp_fill = 0;
2870 }
b99bd4ef 2871
c19d1205
ZW
2872 if (!temp)
2873 temp = 2;
b99bd4ef 2874
c19d1205
ZW
2875 /* Only make a frag if we HAVE to. */
2876 if (temp && !need_pass_2)
dce323d1
PB
2877 {
2878 if (!fill_p && subseg_text_p (now_seg))
2879 frag_align_code (temp, 0);
2880 else
2881 frag_align (temp, (int) temp_fill, 0);
2882 }
c19d1205
ZW
2883 demand_empty_rest_of_line ();
2884
2885 record_alignment (now_seg, temp);
b99bd4ef
NC
2886}
2887
c19d1205
ZW
2888static void
2889s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2890{
c19d1205
ZW
2891 /* We don't support putting frags in the BSS segment, we fake it by
2892 marking in_bss, then looking at s_skip for clues. */
2893 subseg_set (bss_section, 0);
2894 demand_empty_rest_of_line ();
cd000bff
DJ
2895
2896#ifdef md_elf_section_change_hook
2897 md_elf_section_change_hook ();
2898#endif
c19d1205 2899}
b99bd4ef 2900
c19d1205
ZW
2901static void
2902s_even (int ignore ATTRIBUTE_UNUSED)
2903{
2904 /* Never make frag if expect extra pass. */
2905 if (!need_pass_2)
2906 frag_align (1, 0, 0);
b99bd4ef 2907
c19d1205 2908 record_alignment (now_seg, 1);
b99bd4ef 2909
c19d1205 2910 demand_empty_rest_of_line ();
b99bd4ef
NC
2911}
2912
c19d1205 2913/* Directives: Literal pools. */
a737bd4d 2914
c19d1205
ZW
2915static literal_pool *
2916find_literal_pool (void)
a737bd4d 2917{
c19d1205 2918 literal_pool * pool;
a737bd4d 2919
c19d1205 2920 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2921 {
c19d1205
ZW
2922 if (pool->section == now_seg
2923 && pool->sub_section == now_subseg)
2924 break;
a737bd4d
NC
2925 }
2926
c19d1205 2927 return pool;
a737bd4d
NC
2928}
2929
c19d1205
ZW
2930static literal_pool *
2931find_or_make_literal_pool (void)
a737bd4d 2932{
c19d1205
ZW
2933 /* Next literal pool ID number. */
2934 static unsigned int latest_pool_num = 1;
2935 literal_pool * pool;
a737bd4d 2936
c19d1205 2937 pool = find_literal_pool ();
a737bd4d 2938
c19d1205 2939 if (pool == NULL)
a737bd4d 2940 {
c19d1205 2941 /* Create a new pool. */
21d799b5 2942 pool = (literal_pool *) xmalloc (sizeof (* pool));
c19d1205
ZW
2943 if (! pool)
2944 return NULL;
a737bd4d 2945
c19d1205
ZW
2946 pool->next_free_entry = 0;
2947 pool->section = now_seg;
2948 pool->sub_section = now_subseg;
2949 pool->next = list_of_pools;
2950 pool->symbol = NULL;
2951
2952 /* Add it to the list. */
2953 list_of_pools = pool;
a737bd4d 2954 }
a737bd4d 2955
c19d1205
ZW
2956 /* New pools, and emptied pools, will have a NULL symbol. */
2957 if (pool->symbol == NULL)
a737bd4d 2958 {
c19d1205
ZW
2959 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2960 (valueT) 0, &zero_address_frag);
2961 pool->id = latest_pool_num ++;
a737bd4d
NC
2962 }
2963
c19d1205
ZW
2964 /* Done. */
2965 return pool;
a737bd4d
NC
2966}
2967
c19d1205 2968/* Add the literal in the global 'inst'
5f4273c7 2969 structure to the relevant literal pool. */
b99bd4ef
NC
2970
2971static int
c19d1205 2972add_to_lit_pool (void)
b99bd4ef 2973{
c19d1205
ZW
2974 literal_pool * pool;
2975 unsigned int entry;
b99bd4ef 2976
c19d1205
ZW
2977 pool = find_or_make_literal_pool ();
2978
2979 /* Check if this literal value is already in the pool. */
2980 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2981 {
c19d1205
ZW
2982 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2983 && (inst.reloc.exp.X_op == O_constant)
2984 && (pool->literals[entry].X_add_number
2985 == inst.reloc.exp.X_add_number)
2986 && (pool->literals[entry].X_unsigned
2987 == inst.reloc.exp.X_unsigned))
2988 break;
2989
2990 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2991 && (inst.reloc.exp.X_op == O_symbol)
2992 && (pool->literals[entry].X_add_number
2993 == inst.reloc.exp.X_add_number)
2994 && (pool->literals[entry].X_add_symbol
2995 == inst.reloc.exp.X_add_symbol)
2996 && (pool->literals[entry].X_op_symbol
2997 == inst.reloc.exp.X_op_symbol))
2998 break;
b99bd4ef
NC
2999 }
3000
c19d1205
ZW
3001 /* Do we need to create a new entry? */
3002 if (entry == pool->next_free_entry)
3003 {
3004 if (entry >= MAX_LITERAL_POOL_SIZE)
3005 {
3006 inst.error = _("literal pool overflow");
3007 return FAIL;
3008 }
3009
3010 pool->literals[entry] = inst.reloc.exp;
3011 pool->next_free_entry += 1;
3012 }
b99bd4ef 3013
c19d1205
ZW
3014 inst.reloc.exp.X_op = O_symbol;
3015 inst.reloc.exp.X_add_number = ((int) entry) * 4;
3016 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 3017
c19d1205 3018 return SUCCESS;
b99bd4ef
NC
3019}
3020
c19d1205
ZW
3021/* Can't use symbol_new here, so have to create a symbol and then at
3022 a later date assign it a value. Thats what these functions do. */
e16bb312 3023
c19d1205
ZW
3024static void
3025symbol_locate (symbolS * symbolP,
3026 const char * name, /* It is copied, the caller can modify. */
3027 segT segment, /* Segment identifier (SEG_<something>). */
3028 valueT valu, /* Symbol value. */
3029 fragS * frag) /* Associated fragment. */
3030{
3031 unsigned int name_length;
3032 char * preserved_copy_of_name;
e16bb312 3033
c19d1205
ZW
3034 name_length = strlen (name) + 1; /* +1 for \0. */
3035 obstack_grow (&notes, name, name_length);
21d799b5 3036 preserved_copy_of_name = (char *) obstack_finish (&notes);
e16bb312 3037
c19d1205
ZW
3038#ifdef tc_canonicalize_symbol_name
3039 preserved_copy_of_name =
3040 tc_canonicalize_symbol_name (preserved_copy_of_name);
3041#endif
b99bd4ef 3042
c19d1205 3043 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 3044
c19d1205
ZW
3045 S_SET_SEGMENT (symbolP, segment);
3046 S_SET_VALUE (symbolP, valu);
3047 symbol_clear_list_pointers (symbolP);
b99bd4ef 3048
c19d1205 3049 symbol_set_frag (symbolP, frag);
b99bd4ef 3050
c19d1205
ZW
3051 /* Link to end of symbol chain. */
3052 {
3053 extern int symbol_table_frozen;
b99bd4ef 3054
c19d1205
ZW
3055 if (symbol_table_frozen)
3056 abort ();
3057 }
b99bd4ef 3058
c19d1205 3059 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 3060
c19d1205 3061 obj_symbol_new_hook (symbolP);
b99bd4ef 3062
c19d1205
ZW
3063#ifdef tc_symbol_new_hook
3064 tc_symbol_new_hook (symbolP);
3065#endif
3066
3067#ifdef DEBUG_SYMS
3068 verify_symbol_chain (symbol_rootP, symbol_lastP);
3069#endif /* DEBUG_SYMS */
b99bd4ef
NC
3070}
3071
b99bd4ef 3072
c19d1205
ZW
3073static void
3074s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3075{
c19d1205
ZW
3076 unsigned int entry;
3077 literal_pool * pool;
3078 char sym_name[20];
b99bd4ef 3079
c19d1205
ZW
3080 pool = find_literal_pool ();
3081 if (pool == NULL
3082 || pool->symbol == NULL
3083 || pool->next_free_entry == 0)
3084 return;
b99bd4ef 3085
c19d1205 3086 mapping_state (MAP_DATA);
b99bd4ef 3087
c19d1205
ZW
3088 /* Align pool as you have word accesses.
3089 Only make a frag if we have to. */
3090 if (!need_pass_2)
3091 frag_align (2, 0, 0);
b99bd4ef 3092
c19d1205 3093 record_alignment (now_seg, 2);
b99bd4ef 3094
c19d1205 3095 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 3096
c19d1205
ZW
3097 symbol_locate (pool->symbol, sym_name, now_seg,
3098 (valueT) frag_now_fix (), frag_now);
3099 symbol_table_insert (pool->symbol);
b99bd4ef 3100
c19d1205 3101 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 3102
c19d1205
ZW
3103#if defined OBJ_COFF || defined OBJ_ELF
3104 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3105#endif
6c43fab6 3106
c19d1205
ZW
3107 for (entry = 0; entry < pool->next_free_entry; entry ++)
3108 /* First output the expression in the instruction to the pool. */
3109 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3110
c19d1205
ZW
3111 /* Mark the pool as empty. */
3112 pool->next_free_entry = 0;
3113 pool->symbol = NULL;
b99bd4ef
NC
3114}
3115
c19d1205
ZW
3116#ifdef OBJ_ELF
3117/* Forward declarations for functions below, in the MD interface
3118 section. */
3119static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3120static valueT create_unwind_entry (int);
3121static void start_unwind_section (const segT, int);
3122static void add_unwind_opcode (valueT, int);
3123static void flush_pending_unwind (void);
b99bd4ef 3124
c19d1205 3125/* Directives: Data. */
b99bd4ef 3126
c19d1205
ZW
3127static void
3128s_arm_elf_cons (int nbytes)
3129{
3130 expressionS exp;
b99bd4ef 3131
c19d1205
ZW
3132#ifdef md_flush_pending_output
3133 md_flush_pending_output ();
3134#endif
b99bd4ef 3135
c19d1205 3136 if (is_it_end_of_statement ())
b99bd4ef 3137 {
c19d1205
ZW
3138 demand_empty_rest_of_line ();
3139 return;
b99bd4ef
NC
3140 }
3141
c19d1205
ZW
3142#ifdef md_cons_align
3143 md_cons_align (nbytes);
3144#endif
b99bd4ef 3145
c19d1205
ZW
3146 mapping_state (MAP_DATA);
3147 do
b99bd4ef 3148 {
c19d1205
ZW
3149 int reloc;
3150 char *base = input_line_pointer;
b99bd4ef 3151
c19d1205 3152 expression (& exp);
b99bd4ef 3153
c19d1205
ZW
3154 if (exp.X_op != O_symbol)
3155 emit_expr (&exp, (unsigned int) nbytes);
3156 else
3157 {
3158 char *before_reloc = input_line_pointer;
3159 reloc = parse_reloc (&input_line_pointer);
3160 if (reloc == -1)
3161 {
3162 as_bad (_("unrecognized relocation suffix"));
3163 ignore_rest_of_line ();
3164 return;
3165 }
3166 else if (reloc == BFD_RELOC_UNUSED)
3167 emit_expr (&exp, (unsigned int) nbytes);
3168 else
3169 {
21d799b5
NC
3170 reloc_howto_type *howto = (reloc_howto_type *)
3171 bfd_reloc_type_lookup (stdoutput,
3172 (bfd_reloc_code_real_type) reloc);
c19d1205 3173 int size = bfd_get_reloc_size (howto);
b99bd4ef 3174
2fc8bdac
ZW
3175 if (reloc == BFD_RELOC_ARM_PLT32)
3176 {
3177 as_bad (_("(plt) is only valid on branch targets"));
3178 reloc = BFD_RELOC_UNUSED;
3179 size = 0;
3180 }
3181
c19d1205 3182 if (size > nbytes)
2fc8bdac 3183 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3184 howto->name, nbytes);
3185 else
3186 {
3187 /* We've parsed an expression stopping at O_symbol.
3188 But there may be more expression left now that we
3189 have parsed the relocation marker. Parse it again.
3190 XXX Surely there is a cleaner way to do this. */
3191 char *p = input_line_pointer;
3192 int offset;
21d799b5 3193 char *save_buf = (char *) alloca (input_line_pointer - base);
c19d1205
ZW
3194 memcpy (save_buf, base, input_line_pointer - base);
3195 memmove (base + (input_line_pointer - before_reloc),
3196 base, before_reloc - base);
3197
3198 input_line_pointer = base + (input_line_pointer-before_reloc);
3199 expression (&exp);
3200 memcpy (base, save_buf, p - base);
3201
3202 offset = nbytes - size;
3203 p = frag_more ((int) nbytes);
3204 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
21d799b5 3205 size, &exp, 0, (enum bfd_reloc_code_real) reloc);
c19d1205
ZW
3206 }
3207 }
3208 }
b99bd4ef 3209 }
c19d1205 3210 while (*input_line_pointer++ == ',');
b99bd4ef 3211
c19d1205
ZW
3212 /* Put terminator back into stream. */
3213 input_line_pointer --;
3214 demand_empty_rest_of_line ();
b99bd4ef
NC
3215}
3216
c921be7d
NC
3217/* Emit an expression containing a 32-bit thumb instruction.
3218 Implementation based on put_thumb32_insn. */
3219
3220static void
3221emit_thumb32_expr (expressionS * exp)
3222{
3223 expressionS exp_high = *exp;
3224
3225 exp_high.X_add_number = (unsigned long)exp_high.X_add_number >> 16;
3226 emit_expr (& exp_high, (unsigned int) THUMB_SIZE);
3227 exp->X_add_number &= 0xffff;
3228 emit_expr (exp, (unsigned int) THUMB_SIZE);
3229}
3230
3231/* Guess the instruction size based on the opcode. */
3232
3233static int
3234thumb_insn_size (int opcode)
3235{
3236 if ((unsigned int) opcode < 0xe800u)
3237 return 2;
3238 else if ((unsigned int) opcode >= 0xe8000000u)
3239 return 4;
3240 else
3241 return 0;
3242}
3243
3244static bfd_boolean
3245emit_insn (expressionS *exp, int nbytes)
3246{
3247 int size = 0;
3248
3249 if (exp->X_op == O_constant)
3250 {
3251 size = nbytes;
3252
3253 if (size == 0)
3254 size = thumb_insn_size (exp->X_add_number);
3255
3256 if (size != 0)
3257 {
3258 if (size == 2 && (unsigned int)exp->X_add_number > 0xffffu)
3259 {
3260 as_bad (_(".inst.n operand too big. "\
3261 "Use .inst.w instead"));
3262 size = 0;
3263 }
3264 else
3265 {
3266 if (now_it.state == AUTOMATIC_IT_BLOCK)
3267 set_it_insn_type_nonvoid (OUTSIDE_IT_INSN, 0);
3268 else
3269 set_it_insn_type_nonvoid (NEUTRAL_IT_INSN, 0);
3270
3271 if (thumb_mode && (size > THUMB_SIZE) && !target_big_endian)
3272 emit_thumb32_expr (exp);
3273 else
3274 emit_expr (exp, (unsigned int) size);
3275
3276 it_fsm_post_encode ();
3277 }
3278 }
3279 else
3280 as_bad (_("cannot determine Thumb instruction size. " \
3281 "Use .inst.n/.inst.w instead"));
3282 }
3283 else
3284 as_bad (_("constant expression required"));
3285
3286 return (size != 0);
3287}
3288
3289/* Like s_arm_elf_cons but do not use md_cons_align and
3290 set the mapping state to MAP_ARM/MAP_THUMB. */
3291
3292static void
3293s_arm_elf_inst (int nbytes)
3294{
3295 if (is_it_end_of_statement ())
3296 {
3297 demand_empty_rest_of_line ();
3298 return;
3299 }
3300
3301 /* Calling mapping_state () here will not change ARM/THUMB,
3302 but will ensure not to be in DATA state. */
3303
3304 if (thumb_mode)
3305 mapping_state (MAP_THUMB);
3306 else
3307 {
3308 if (nbytes != 0)
3309 {
3310 as_bad (_("width suffixes are invalid in ARM mode"));
3311 ignore_rest_of_line ();
3312 return;
3313 }
3314
3315 nbytes = 4;
3316
3317 mapping_state (MAP_ARM);
3318 }
3319
3320 do
3321 {
3322 expressionS exp;
3323
3324 expression (& exp);
3325
3326 if (! emit_insn (& exp, nbytes))
3327 {
3328 ignore_rest_of_line ();
3329 return;
3330 }
3331 }
3332 while (*input_line_pointer++ == ',');
3333
3334 /* Put terminator back into stream. */
3335 input_line_pointer --;
3336 demand_empty_rest_of_line ();
3337}
b99bd4ef 3338
c19d1205 3339/* Parse a .rel31 directive. */
b99bd4ef 3340
c19d1205
ZW
3341static void
3342s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3343{
3344 expressionS exp;
3345 char *p;
3346 valueT highbit;
b99bd4ef 3347
c19d1205
ZW
3348 highbit = 0;
3349 if (*input_line_pointer == '1')
3350 highbit = 0x80000000;
3351 else if (*input_line_pointer != '0')
3352 as_bad (_("expected 0 or 1"));
b99bd4ef 3353
c19d1205
ZW
3354 input_line_pointer++;
3355 if (*input_line_pointer != ',')
3356 as_bad (_("missing comma"));
3357 input_line_pointer++;
b99bd4ef 3358
c19d1205
ZW
3359#ifdef md_flush_pending_output
3360 md_flush_pending_output ();
3361#endif
b99bd4ef 3362
c19d1205
ZW
3363#ifdef md_cons_align
3364 md_cons_align (4);
3365#endif
b99bd4ef 3366
c19d1205 3367 mapping_state (MAP_DATA);
b99bd4ef 3368
c19d1205 3369 expression (&exp);
b99bd4ef 3370
c19d1205
ZW
3371 p = frag_more (4);
3372 md_number_to_chars (p, highbit, 4);
3373 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3374 BFD_RELOC_ARM_PREL31);
b99bd4ef 3375
c19d1205 3376 demand_empty_rest_of_line ();
b99bd4ef
NC
3377}
3378
c19d1205 3379/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3380
c19d1205 3381/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3382
c19d1205
ZW
3383static void
3384s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3385{
3386 demand_empty_rest_of_line ();
921e5f0a
PB
3387 if (unwind.proc_start)
3388 {
c921be7d 3389 as_bad (_("duplicate .fnstart directive"));
921e5f0a
PB
3390 return;
3391 }
3392
c19d1205
ZW
3393 /* Mark the start of the function. */
3394 unwind.proc_start = expr_build_dot ();
b99bd4ef 3395
c19d1205
ZW
3396 /* Reset the rest of the unwind info. */
3397 unwind.opcode_count = 0;
3398 unwind.table_entry = NULL;
3399 unwind.personality_routine = NULL;
3400 unwind.personality_index = -1;
3401 unwind.frame_size = 0;
3402 unwind.fp_offset = 0;
fdfde340 3403 unwind.fp_reg = REG_SP;
c19d1205
ZW
3404 unwind.fp_used = 0;
3405 unwind.sp_restored = 0;
3406}
b99bd4ef 3407
b99bd4ef 3408
c19d1205
ZW
3409/* Parse a handlerdata directive. Creates the exception handling table entry
3410 for the function. */
b99bd4ef 3411
c19d1205
ZW
3412static void
3413s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3414{
3415 demand_empty_rest_of_line ();
921e5f0a 3416 if (!unwind.proc_start)
c921be7d 3417 as_bad (MISSING_FNSTART);
921e5f0a 3418
c19d1205 3419 if (unwind.table_entry)
6decc662 3420 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3421
c19d1205
ZW
3422 create_unwind_entry (1);
3423}
a737bd4d 3424
c19d1205 3425/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3426
c19d1205
ZW
3427static void
3428s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3429{
3430 long where;
3431 char *ptr;
3432 valueT val;
940b5ce0 3433 unsigned int marked_pr_dependency;
f02232aa 3434
c19d1205 3435 demand_empty_rest_of_line ();
f02232aa 3436
921e5f0a
PB
3437 if (!unwind.proc_start)
3438 {
c921be7d 3439 as_bad (_(".fnend directive without .fnstart"));
921e5f0a
PB
3440 return;
3441 }
3442
c19d1205
ZW
3443 /* Add eh table entry. */
3444 if (unwind.table_entry == NULL)
3445 val = create_unwind_entry (0);
3446 else
3447 val = 0;
f02232aa 3448
c19d1205
ZW
3449 /* Add index table entry. This is two words. */
3450 start_unwind_section (unwind.saved_seg, 1);
3451 frag_align (2, 0, 0);
3452 record_alignment (now_seg, 2);
b99bd4ef 3453
c19d1205
ZW
3454 ptr = frag_more (8);
3455 where = frag_now_fix () - 8;
f02232aa 3456
c19d1205
ZW
3457 /* Self relative offset of the function start. */
3458 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3459 BFD_RELOC_ARM_PREL31);
f02232aa 3460
c19d1205
ZW
3461 /* Indicate dependency on EHABI-defined personality routines to the
3462 linker, if it hasn't been done already. */
940b5ce0
DJ
3463 marked_pr_dependency
3464 = seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency;
c19d1205
ZW
3465 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3466 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3467 {
5f4273c7
NC
3468 static const char *const name[] =
3469 {
3470 "__aeabi_unwind_cpp_pr0",
3471 "__aeabi_unwind_cpp_pr1",
3472 "__aeabi_unwind_cpp_pr2"
3473 };
c19d1205
ZW
3474 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3475 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
c19d1205 3476 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
940b5ce0 3477 |= 1 << unwind.personality_index;
c19d1205 3478 }
f02232aa 3479
c19d1205
ZW
3480 if (val)
3481 /* Inline exception table entry. */
3482 md_number_to_chars (ptr + 4, val, 4);
3483 else
3484 /* Self relative offset of the table entry. */
3485 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3486 BFD_RELOC_ARM_PREL31);
f02232aa 3487
c19d1205
ZW
3488 /* Restore the original section. */
3489 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3490
3491 unwind.proc_start = NULL;
c19d1205 3492}
f02232aa 3493
f02232aa 3494
c19d1205 3495/* Parse an unwind_cantunwind directive. */
b99bd4ef 3496
c19d1205
ZW
3497static void
3498s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3499{
3500 demand_empty_rest_of_line ();
921e5f0a 3501 if (!unwind.proc_start)
c921be7d 3502 as_bad (MISSING_FNSTART);
921e5f0a 3503
c19d1205
ZW
3504 if (unwind.personality_routine || unwind.personality_index != -1)
3505 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3506
c19d1205
ZW
3507 unwind.personality_index = -2;
3508}
b99bd4ef 3509
b99bd4ef 3510
c19d1205 3511/* Parse a personalityindex directive. */
b99bd4ef 3512
c19d1205
ZW
3513static void
3514s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3515{
3516 expressionS exp;
b99bd4ef 3517
921e5f0a 3518 if (!unwind.proc_start)
c921be7d 3519 as_bad (MISSING_FNSTART);
921e5f0a 3520
c19d1205
ZW
3521 if (unwind.personality_routine || unwind.personality_index != -1)
3522 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3523
c19d1205 3524 expression (&exp);
b99bd4ef 3525
c19d1205
ZW
3526 if (exp.X_op != O_constant
3527 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3528 {
c19d1205
ZW
3529 as_bad (_("bad personality routine number"));
3530 ignore_rest_of_line ();
3531 return;
b99bd4ef
NC
3532 }
3533
c19d1205 3534 unwind.personality_index = exp.X_add_number;
b99bd4ef 3535
c19d1205
ZW
3536 demand_empty_rest_of_line ();
3537}
e16bb312 3538
e16bb312 3539
c19d1205 3540/* Parse a personality directive. */
e16bb312 3541
c19d1205
ZW
3542static void
3543s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3544{
3545 char *name, *p, c;
a737bd4d 3546
921e5f0a 3547 if (!unwind.proc_start)
c921be7d 3548 as_bad (MISSING_FNSTART);
921e5f0a 3549
c19d1205
ZW
3550 if (unwind.personality_routine || unwind.personality_index != -1)
3551 as_bad (_("duplicate .personality directive"));
a737bd4d 3552
c19d1205
ZW
3553 name = input_line_pointer;
3554 c = get_symbol_end ();
3555 p = input_line_pointer;
3556 unwind.personality_routine = symbol_find_or_make (name);
3557 *p = c;
3558 demand_empty_rest_of_line ();
3559}
e16bb312 3560
e16bb312 3561
c19d1205 3562/* Parse a directive saving core registers. */
e16bb312 3563
c19d1205
ZW
3564static void
3565s_arm_unwind_save_core (void)
e16bb312 3566{
c19d1205
ZW
3567 valueT op;
3568 long range;
3569 int n;
e16bb312 3570
c19d1205
ZW
3571 range = parse_reg_list (&input_line_pointer);
3572 if (range == FAIL)
e16bb312 3573 {
c19d1205
ZW
3574 as_bad (_("expected register list"));
3575 ignore_rest_of_line ();
3576 return;
3577 }
e16bb312 3578
c19d1205 3579 demand_empty_rest_of_line ();
e16bb312 3580
c19d1205
ZW
3581 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3582 into .unwind_save {..., sp...}. We aren't bothered about the value of
3583 ip because it is clobbered by calls. */
3584 if (unwind.sp_restored && unwind.fp_reg == 12
3585 && (range & 0x3000) == 0x1000)
3586 {
3587 unwind.opcode_count--;
3588 unwind.sp_restored = 0;
3589 range = (range | 0x2000) & ~0x1000;
3590 unwind.pending_offset = 0;
3591 }
e16bb312 3592
01ae4198
DJ
3593 /* Pop r4-r15. */
3594 if (range & 0xfff0)
c19d1205 3595 {
01ae4198
DJ
3596 /* See if we can use the short opcodes. These pop a block of up to 8
3597 registers starting with r4, plus maybe r14. */
3598 for (n = 0; n < 8; n++)
3599 {
3600 /* Break at the first non-saved register. */
3601 if ((range & (1 << (n + 4))) == 0)
3602 break;
3603 }
3604 /* See if there are any other bits set. */
3605 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3606 {
3607 /* Use the long form. */
3608 op = 0x8000 | ((range >> 4) & 0xfff);
3609 add_unwind_opcode (op, 2);
3610 }
0dd132b6 3611 else
01ae4198
DJ
3612 {
3613 /* Use the short form. */
3614 if (range & 0x4000)
3615 op = 0xa8; /* Pop r14. */
3616 else
3617 op = 0xa0; /* Do not pop r14. */
3618 op |= (n - 1);
3619 add_unwind_opcode (op, 1);
3620 }
c19d1205 3621 }
0dd132b6 3622
c19d1205
ZW
3623 /* Pop r0-r3. */
3624 if (range & 0xf)
3625 {
3626 op = 0xb100 | (range & 0xf);
3627 add_unwind_opcode (op, 2);
0dd132b6
NC
3628 }
3629
c19d1205
ZW
3630 /* Record the number of bytes pushed. */
3631 for (n = 0; n < 16; n++)
3632 {
3633 if (range & (1 << n))
3634 unwind.frame_size += 4;
3635 }
0dd132b6
NC
3636}
3637
c19d1205
ZW
3638
3639/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3640
3641static void
c19d1205 3642s_arm_unwind_save_fpa (int reg)
b99bd4ef 3643{
c19d1205
ZW
3644 expressionS exp;
3645 int num_regs;
3646 valueT op;
b99bd4ef 3647
c19d1205
ZW
3648 /* Get Number of registers to transfer. */
3649 if (skip_past_comma (&input_line_pointer) != FAIL)
3650 expression (&exp);
3651 else
3652 exp.X_op = O_illegal;
b99bd4ef 3653
c19d1205 3654 if (exp.X_op != O_constant)
b99bd4ef 3655 {
c19d1205
ZW
3656 as_bad (_("expected , <constant>"));
3657 ignore_rest_of_line ();
b99bd4ef
NC
3658 return;
3659 }
3660
c19d1205
ZW
3661 num_regs = exp.X_add_number;
3662
3663 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3664 {
c19d1205
ZW
3665 as_bad (_("number of registers must be in the range [1:4]"));
3666 ignore_rest_of_line ();
b99bd4ef
NC
3667 return;
3668 }
3669
c19d1205 3670 demand_empty_rest_of_line ();
b99bd4ef 3671
c19d1205
ZW
3672 if (reg == 4)
3673 {
3674 /* Short form. */
3675 op = 0xb4 | (num_regs - 1);
3676 add_unwind_opcode (op, 1);
3677 }
b99bd4ef
NC
3678 else
3679 {
c19d1205
ZW
3680 /* Long form. */
3681 op = 0xc800 | (reg << 4) | (num_regs - 1);
3682 add_unwind_opcode (op, 2);
b99bd4ef 3683 }
c19d1205 3684 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3685}
3686
c19d1205 3687
fa073d69
MS
3688/* Parse a directive saving VFP registers for ARMv6 and above. */
3689
3690static void
3691s_arm_unwind_save_vfp_armv6 (void)
3692{
3693 int count;
3694 unsigned int start;
3695 valueT op;
3696 int num_vfpv3_regs = 0;
3697 int num_regs_below_16;
3698
3699 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3700 if (count == FAIL)
3701 {
3702 as_bad (_("expected register list"));
3703 ignore_rest_of_line ();
3704 return;
3705 }
3706
3707 demand_empty_rest_of_line ();
3708
3709 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3710 than FSTMX/FLDMX-style ones). */
3711
3712 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3713 if (start >= 16)
3714 num_vfpv3_regs = count;
3715 else if (start + count > 16)
3716 num_vfpv3_regs = start + count - 16;
3717
3718 if (num_vfpv3_regs > 0)
3719 {
3720 int start_offset = start > 16 ? start - 16 : 0;
3721 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3722 add_unwind_opcode (op, 2);
3723 }
3724
3725 /* Generate opcode for registers numbered in the range 0 .. 15. */
3726 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3727 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3728 if (num_regs_below_16 > 0)
3729 {
3730 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3731 add_unwind_opcode (op, 2);
3732 }
3733
3734 unwind.frame_size += count * 8;
3735}
3736
3737
3738/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3739
3740static void
c19d1205 3741s_arm_unwind_save_vfp (void)
b99bd4ef 3742{
c19d1205 3743 int count;
ca3f61f7 3744 unsigned int reg;
c19d1205 3745 valueT op;
b99bd4ef 3746
5287ad62 3747 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3748 if (count == FAIL)
b99bd4ef 3749 {
c19d1205
ZW
3750 as_bad (_("expected register list"));
3751 ignore_rest_of_line ();
b99bd4ef
NC
3752 return;
3753 }
3754
c19d1205 3755 demand_empty_rest_of_line ();
b99bd4ef 3756
c19d1205 3757 if (reg == 8)
b99bd4ef 3758 {
c19d1205
ZW
3759 /* Short form. */
3760 op = 0xb8 | (count - 1);
3761 add_unwind_opcode (op, 1);
b99bd4ef 3762 }
c19d1205 3763 else
b99bd4ef 3764 {
c19d1205
ZW
3765 /* Long form. */
3766 op = 0xb300 | (reg << 4) | (count - 1);
3767 add_unwind_opcode (op, 2);
b99bd4ef 3768 }
c19d1205
ZW
3769 unwind.frame_size += count * 8 + 4;
3770}
b99bd4ef 3771
b99bd4ef 3772
c19d1205
ZW
3773/* Parse a directive saving iWMMXt data registers. */
3774
3775static void
3776s_arm_unwind_save_mmxwr (void)
3777{
3778 int reg;
3779 int hi_reg;
3780 int i;
3781 unsigned mask = 0;
3782 valueT op;
b99bd4ef 3783
c19d1205
ZW
3784 if (*input_line_pointer == '{')
3785 input_line_pointer++;
b99bd4ef 3786
c19d1205 3787 do
b99bd4ef 3788 {
dcbf9037 3789 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3790
c19d1205 3791 if (reg == FAIL)
b99bd4ef 3792 {
9b7132d3 3793 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3794 goto error;
b99bd4ef
NC
3795 }
3796
c19d1205
ZW
3797 if (mask >> reg)
3798 as_tsktsk (_("register list not in ascending order"));
3799 mask |= 1 << reg;
b99bd4ef 3800
c19d1205
ZW
3801 if (*input_line_pointer == '-')
3802 {
3803 input_line_pointer++;
dcbf9037 3804 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3805 if (hi_reg == FAIL)
3806 {
9b7132d3 3807 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3808 goto error;
3809 }
3810 else if (reg >= hi_reg)
3811 {
3812 as_bad (_("bad register range"));
3813 goto error;
3814 }
3815 for (; reg < hi_reg; reg++)
3816 mask |= 1 << reg;
3817 }
3818 }
3819 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3820
c19d1205
ZW
3821 if (*input_line_pointer == '}')
3822 input_line_pointer++;
b99bd4ef 3823
c19d1205 3824 demand_empty_rest_of_line ();
b99bd4ef 3825
708587a4 3826 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3827 the list. */
3828 flush_pending_unwind ();
b99bd4ef 3829
c19d1205 3830 for (i = 0; i < 16; i++)
b99bd4ef 3831 {
c19d1205
ZW
3832 if (mask & (1 << i))
3833 unwind.frame_size += 8;
b99bd4ef
NC
3834 }
3835
c19d1205
ZW
3836 /* Attempt to combine with a previous opcode. We do this because gcc
3837 likes to output separate unwind directives for a single block of
3838 registers. */
3839 if (unwind.opcode_count > 0)
b99bd4ef 3840 {
c19d1205
ZW
3841 i = unwind.opcodes[unwind.opcode_count - 1];
3842 if ((i & 0xf8) == 0xc0)
3843 {
3844 i &= 7;
3845 /* Only merge if the blocks are contiguous. */
3846 if (i < 6)
3847 {
3848 if ((mask & 0xfe00) == (1 << 9))
3849 {
3850 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3851 unwind.opcode_count--;
3852 }
3853 }
3854 else if (i == 6 && unwind.opcode_count >= 2)
3855 {
3856 i = unwind.opcodes[unwind.opcode_count - 2];
3857 reg = i >> 4;
3858 i &= 0xf;
b99bd4ef 3859
c19d1205
ZW
3860 op = 0xffff << (reg - 1);
3861 if (reg > 0
87a1fd79 3862 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3863 {
3864 op = (1 << (reg + i + 1)) - 1;
3865 op &= ~((1 << reg) - 1);
3866 mask |= op;
3867 unwind.opcode_count -= 2;
3868 }
3869 }
3870 }
b99bd4ef
NC
3871 }
3872
c19d1205
ZW
3873 hi_reg = 15;
3874 /* We want to generate opcodes in the order the registers have been
3875 saved, ie. descending order. */
3876 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3877 {
c19d1205
ZW
3878 /* Save registers in blocks. */
3879 if (reg < 0
3880 || !(mask & (1 << reg)))
3881 {
3882 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3883 preceding block. */
c19d1205
ZW
3884 if (reg != hi_reg)
3885 {
3886 if (reg == 9)
3887 {
3888 /* Short form. */
3889 op = 0xc0 | (hi_reg - 10);
3890 add_unwind_opcode (op, 1);
3891 }
3892 else
3893 {
3894 /* Long form. */
3895 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3896 add_unwind_opcode (op, 2);
3897 }
3898 }
3899 hi_reg = reg - 1;
3900 }
b99bd4ef
NC
3901 }
3902
c19d1205
ZW
3903 return;
3904error:
3905 ignore_rest_of_line ();
b99bd4ef
NC
3906}
3907
3908static void
c19d1205 3909s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3910{
c19d1205
ZW
3911 int reg;
3912 int hi_reg;
3913 unsigned mask = 0;
3914 valueT op;
b99bd4ef 3915
c19d1205
ZW
3916 if (*input_line_pointer == '{')
3917 input_line_pointer++;
b99bd4ef 3918
c19d1205 3919 do
b99bd4ef 3920 {
dcbf9037 3921 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3922
c19d1205
ZW
3923 if (reg == FAIL)
3924 {
9b7132d3 3925 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3926 goto error;
3927 }
b99bd4ef 3928
c19d1205
ZW
3929 reg -= 8;
3930 if (mask >> reg)
3931 as_tsktsk (_("register list not in ascending order"));
3932 mask |= 1 << reg;
b99bd4ef 3933
c19d1205
ZW
3934 if (*input_line_pointer == '-')
3935 {
3936 input_line_pointer++;
dcbf9037 3937 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3938 if (hi_reg == FAIL)
3939 {
9b7132d3 3940 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3941 goto error;
3942 }
3943 else if (reg >= hi_reg)
3944 {
3945 as_bad (_("bad register range"));
3946 goto error;
3947 }
3948 for (; reg < hi_reg; reg++)
3949 mask |= 1 << reg;
3950 }
b99bd4ef 3951 }
c19d1205 3952 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3953
c19d1205
ZW
3954 if (*input_line_pointer == '}')
3955 input_line_pointer++;
b99bd4ef 3956
c19d1205
ZW
3957 demand_empty_rest_of_line ();
3958
708587a4 3959 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3960 the list. */
3961 flush_pending_unwind ();
b99bd4ef 3962
c19d1205 3963 for (reg = 0; reg < 16; reg++)
b99bd4ef 3964 {
c19d1205
ZW
3965 if (mask & (1 << reg))
3966 unwind.frame_size += 4;
b99bd4ef 3967 }
c19d1205
ZW
3968 op = 0xc700 | mask;
3969 add_unwind_opcode (op, 2);
3970 return;
3971error:
3972 ignore_rest_of_line ();
b99bd4ef
NC
3973}
3974
c19d1205 3975
fa073d69
MS
3976/* Parse an unwind_save directive.
3977 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3978
b99bd4ef 3979static void
fa073d69 3980s_arm_unwind_save (int arch_v6)
b99bd4ef 3981{
c19d1205
ZW
3982 char *peek;
3983 struct reg_entry *reg;
3984 bfd_boolean had_brace = FALSE;
b99bd4ef 3985
921e5f0a 3986 if (!unwind.proc_start)
c921be7d 3987 as_bad (MISSING_FNSTART);
921e5f0a 3988
c19d1205
ZW
3989 /* Figure out what sort of save we have. */
3990 peek = input_line_pointer;
b99bd4ef 3991
c19d1205 3992 if (*peek == '{')
b99bd4ef 3993 {
c19d1205
ZW
3994 had_brace = TRUE;
3995 peek++;
b99bd4ef
NC
3996 }
3997
c19d1205 3998 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3999
c19d1205 4000 if (!reg)
b99bd4ef 4001 {
c19d1205
ZW
4002 as_bad (_("register expected"));
4003 ignore_rest_of_line ();
b99bd4ef
NC
4004 return;
4005 }
4006
c19d1205 4007 switch (reg->type)
b99bd4ef 4008 {
c19d1205
ZW
4009 case REG_TYPE_FN:
4010 if (had_brace)
4011 {
4012 as_bad (_("FPA .unwind_save does not take a register list"));
4013 ignore_rest_of_line ();
4014 return;
4015 }
93ac2687 4016 input_line_pointer = peek;
c19d1205 4017 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 4018 return;
c19d1205
ZW
4019
4020 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
4021 case REG_TYPE_VFD:
4022 if (arch_v6)
4023 s_arm_unwind_save_vfp_armv6 ();
4024 else
4025 s_arm_unwind_save_vfp ();
4026 return;
c19d1205
ZW
4027 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
4028 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
4029
4030 default:
4031 as_bad (_(".unwind_save does not support this kind of register"));
4032 ignore_rest_of_line ();
b99bd4ef 4033 }
c19d1205 4034}
b99bd4ef 4035
b99bd4ef 4036
c19d1205
ZW
4037/* Parse an unwind_movsp directive. */
4038
4039static void
4040s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
4041{
4042 int reg;
4043 valueT op;
4fa3602b 4044 int offset;
c19d1205 4045
921e5f0a 4046 if (!unwind.proc_start)
c921be7d 4047 as_bad (MISSING_FNSTART);
921e5f0a 4048
dcbf9037 4049 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 4050 if (reg == FAIL)
b99bd4ef 4051 {
9b7132d3 4052 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 4053 ignore_rest_of_line ();
b99bd4ef
NC
4054 return;
4055 }
4fa3602b
PB
4056
4057 /* Optional constant. */
4058 if (skip_past_comma (&input_line_pointer) != FAIL)
4059 {
4060 if (immediate_for_directive (&offset) == FAIL)
4061 return;
4062 }
4063 else
4064 offset = 0;
4065
c19d1205 4066 demand_empty_rest_of_line ();
b99bd4ef 4067
c19d1205 4068 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 4069 {
c19d1205 4070 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
4071 return;
4072 }
4073
c19d1205
ZW
4074 if (unwind.fp_reg != REG_SP)
4075 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 4076
c19d1205
ZW
4077 /* Generate opcode to restore the value. */
4078 op = 0x90 | reg;
4079 add_unwind_opcode (op, 1);
4080
4081 /* Record the information for later. */
4082 unwind.fp_reg = reg;
4fa3602b 4083 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 4084 unwind.sp_restored = 1;
b05fe5cf
ZW
4085}
4086
c19d1205
ZW
4087/* Parse an unwind_pad directive. */
4088
b05fe5cf 4089static void
c19d1205 4090s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 4091{
c19d1205 4092 int offset;
b05fe5cf 4093
921e5f0a 4094 if (!unwind.proc_start)
c921be7d 4095 as_bad (MISSING_FNSTART);
921e5f0a 4096
c19d1205
ZW
4097 if (immediate_for_directive (&offset) == FAIL)
4098 return;
b99bd4ef 4099
c19d1205
ZW
4100 if (offset & 3)
4101 {
4102 as_bad (_("stack increment must be multiple of 4"));
4103 ignore_rest_of_line ();
4104 return;
4105 }
b99bd4ef 4106
c19d1205
ZW
4107 /* Don't generate any opcodes, just record the details for later. */
4108 unwind.frame_size += offset;
4109 unwind.pending_offset += offset;
4110
4111 demand_empty_rest_of_line ();
4112}
4113
4114/* Parse an unwind_setfp directive. */
4115
4116static void
4117s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 4118{
c19d1205
ZW
4119 int sp_reg;
4120 int fp_reg;
4121 int offset;
4122
921e5f0a 4123 if (!unwind.proc_start)
c921be7d 4124 as_bad (MISSING_FNSTART);
921e5f0a 4125
dcbf9037 4126 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
4127 if (skip_past_comma (&input_line_pointer) == FAIL)
4128 sp_reg = FAIL;
4129 else
dcbf9037 4130 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 4131
c19d1205
ZW
4132 if (fp_reg == FAIL || sp_reg == FAIL)
4133 {
4134 as_bad (_("expected <reg>, <reg>"));
4135 ignore_rest_of_line ();
4136 return;
4137 }
b99bd4ef 4138
c19d1205
ZW
4139 /* Optional constant. */
4140 if (skip_past_comma (&input_line_pointer) != FAIL)
4141 {
4142 if (immediate_for_directive (&offset) == FAIL)
4143 return;
4144 }
4145 else
4146 offset = 0;
a737bd4d 4147
c19d1205 4148 demand_empty_rest_of_line ();
a737bd4d 4149
fdfde340 4150 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 4151 {
c19d1205
ZW
4152 as_bad (_("register must be either sp or set by a previous"
4153 "unwind_movsp directive"));
4154 return;
a737bd4d
NC
4155 }
4156
c19d1205
ZW
4157 /* Don't generate any opcodes, just record the information for later. */
4158 unwind.fp_reg = fp_reg;
4159 unwind.fp_used = 1;
fdfde340 4160 if (sp_reg == REG_SP)
c19d1205
ZW
4161 unwind.fp_offset = unwind.frame_size - offset;
4162 else
4163 unwind.fp_offset -= offset;
a737bd4d
NC
4164}
4165
c19d1205
ZW
4166/* Parse an unwind_raw directive. */
4167
4168static void
4169s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 4170{
c19d1205 4171 expressionS exp;
708587a4 4172 /* This is an arbitrary limit. */
c19d1205
ZW
4173 unsigned char op[16];
4174 int count;
a737bd4d 4175
921e5f0a 4176 if (!unwind.proc_start)
c921be7d 4177 as_bad (MISSING_FNSTART);
921e5f0a 4178
c19d1205
ZW
4179 expression (&exp);
4180 if (exp.X_op == O_constant
4181 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 4182 {
c19d1205
ZW
4183 unwind.frame_size += exp.X_add_number;
4184 expression (&exp);
4185 }
4186 else
4187 exp.X_op = O_illegal;
a737bd4d 4188
c19d1205
ZW
4189 if (exp.X_op != O_constant)
4190 {
4191 as_bad (_("expected <offset>, <opcode>"));
4192 ignore_rest_of_line ();
4193 return;
4194 }
a737bd4d 4195
c19d1205 4196 count = 0;
a737bd4d 4197
c19d1205
ZW
4198 /* Parse the opcode. */
4199 for (;;)
4200 {
4201 if (count >= 16)
4202 {
4203 as_bad (_("unwind opcode too long"));
4204 ignore_rest_of_line ();
a737bd4d 4205 }
c19d1205 4206 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 4207 {
c19d1205
ZW
4208 as_bad (_("invalid unwind opcode"));
4209 ignore_rest_of_line ();
4210 return;
a737bd4d 4211 }
c19d1205 4212 op[count++] = exp.X_add_number;
a737bd4d 4213
c19d1205
ZW
4214 /* Parse the next byte. */
4215 if (skip_past_comma (&input_line_pointer) == FAIL)
4216 break;
a737bd4d 4217
c19d1205
ZW
4218 expression (&exp);
4219 }
b99bd4ef 4220
c19d1205
ZW
4221 /* Add the opcode bytes in reverse order. */
4222 while (count--)
4223 add_unwind_opcode (op[count], 1);
b99bd4ef 4224
c19d1205 4225 demand_empty_rest_of_line ();
b99bd4ef 4226}
ee065d83
PB
4227
4228
4229/* Parse a .eabi_attribute directive. */
4230
4231static void
4232s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4233{
ee3c0378
AS
4234 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4235
4236 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4237 attributes_set_explicitly[tag] = 1;
ee065d83 4238}
8463be01 4239#endif /* OBJ_ELF */
ee065d83
PB
4240
4241static void s_arm_arch (int);
7a1d4c38 4242static void s_arm_object_arch (int);
ee065d83
PB
4243static void s_arm_cpu (int);
4244static void s_arm_fpu (int);
b99bd4ef 4245
f0927246
NC
4246#ifdef TE_PE
4247
4248static void
5f4273c7 4249pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4250{
4251 expressionS exp;
4252
4253 do
4254 {
4255 expression (&exp);
4256 if (exp.X_op == O_symbol)
4257 exp.X_op = O_secrel;
4258
4259 emit_expr (&exp, 4);
4260 }
4261 while (*input_line_pointer++ == ',');
4262
4263 input_line_pointer--;
4264 demand_empty_rest_of_line ();
4265}
4266#endif /* TE_PE */
4267
c19d1205
ZW
4268/* This table describes all the machine specific pseudo-ops the assembler
4269 has to support. The fields are:
4270 pseudo-op name without dot
4271 function to call to execute this pseudo-op
4272 Integer arg to pass to the function. */
b99bd4ef 4273
c19d1205 4274const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4275{
c19d1205
ZW
4276 /* Never called because '.req' does not start a line. */
4277 { "req", s_req, 0 },
dcbf9037
JB
4278 /* Following two are likewise never called. */
4279 { "dn", s_dn, 0 },
4280 { "qn", s_qn, 0 },
c19d1205
ZW
4281 { "unreq", s_unreq, 0 },
4282 { "bss", s_bss, 0 },
4283 { "align", s_align, 0 },
4284 { "arm", s_arm, 0 },
4285 { "thumb", s_thumb, 0 },
4286 { "code", s_code, 0 },
4287 { "force_thumb", s_force_thumb, 0 },
4288 { "thumb_func", s_thumb_func, 0 },
4289 { "thumb_set", s_thumb_set, 0 },
4290 { "even", s_even, 0 },
4291 { "ltorg", s_ltorg, 0 },
4292 { "pool", s_ltorg, 0 },
4293 { "syntax", s_syntax, 0 },
8463be01
PB
4294 { "cpu", s_arm_cpu, 0 },
4295 { "arch", s_arm_arch, 0 },
7a1d4c38 4296 { "object_arch", s_arm_object_arch, 0 },
8463be01 4297 { "fpu", s_arm_fpu, 0 },
c19d1205 4298#ifdef OBJ_ELF
c921be7d
NC
4299 { "word", s_arm_elf_cons, 4 },
4300 { "long", s_arm_elf_cons, 4 },
4301 { "inst.n", s_arm_elf_inst, 2 },
4302 { "inst.w", s_arm_elf_inst, 4 },
4303 { "inst", s_arm_elf_inst, 0 },
4304 { "rel31", s_arm_rel31, 0 },
c19d1205
ZW
4305 { "fnstart", s_arm_unwind_fnstart, 0 },
4306 { "fnend", s_arm_unwind_fnend, 0 },
4307 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4308 { "personality", s_arm_unwind_personality, 0 },
4309 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4310 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4311 { "save", s_arm_unwind_save, 0 },
fa073d69 4312 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4313 { "movsp", s_arm_unwind_movsp, 0 },
4314 { "pad", s_arm_unwind_pad, 0 },
4315 { "setfp", s_arm_unwind_setfp, 0 },
4316 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4317 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4318#else
4319 { "word", cons, 4},
f0927246
NC
4320
4321 /* These are used for dwarf. */
4322 {"2byte", cons, 2},
4323 {"4byte", cons, 4},
4324 {"8byte", cons, 8},
4325 /* These are used for dwarf2. */
4326 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4327 { "loc", dwarf2_directive_loc, 0 },
4328 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4329#endif
4330 { "extend", float_cons, 'x' },
4331 { "ldouble", float_cons, 'x' },
4332 { "packed", float_cons, 'p' },
f0927246
NC
4333#ifdef TE_PE
4334 {"secrel32", pe_directive_secrel, 0},
4335#endif
c19d1205
ZW
4336 { 0, 0, 0 }
4337};
4338\f
4339/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4340
c19d1205
ZW
4341/* Generic immediate-value read function for use in insn parsing.
4342 STR points to the beginning of the immediate (the leading #);
4343 VAL receives the value; if the value is outside [MIN, MAX]
4344 issue an error. PREFIX_OPT is true if the immediate prefix is
4345 optional. */
b99bd4ef 4346
c19d1205
ZW
4347static int
4348parse_immediate (char **str, int *val, int min, int max,
4349 bfd_boolean prefix_opt)
4350{
4351 expressionS exp;
4352 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4353 if (exp.X_op != O_constant)
b99bd4ef 4354 {
c19d1205
ZW
4355 inst.error = _("constant expression required");
4356 return FAIL;
4357 }
b99bd4ef 4358
c19d1205
ZW
4359 if (exp.X_add_number < min || exp.X_add_number > max)
4360 {
4361 inst.error = _("immediate value out of range");
4362 return FAIL;
4363 }
b99bd4ef 4364
c19d1205
ZW
4365 *val = exp.X_add_number;
4366 return SUCCESS;
4367}
b99bd4ef 4368
5287ad62 4369/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4370 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4371 instructions. Puts the result directly in inst.operands[i]. */
4372
4373static int
4374parse_big_immediate (char **str, int i)
4375{
4376 expressionS exp;
4377 char *ptr = *str;
4378
4379 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4380
4381 if (exp.X_op == O_constant)
036dc3f7
PB
4382 {
4383 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4384 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4385 O_constant. We have to be careful not to break compilation for
4386 32-bit X_add_number, though. */
4387 if ((exp.X_add_number & ~0xffffffffl) != 0)
4388 {
4389 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4390 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4391 inst.operands[i].regisimm = 1;
4392 }
4393 }
5287ad62
JB
4394 else if (exp.X_op == O_big
4395 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4396 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4397 {
4398 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4399 /* Bignums have their least significant bits in
4400 generic_bignum[0]. Make sure we put 32 bits in imm and
4401 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4402 gas_assert (parts != 0);
5287ad62
JB
4403 inst.operands[i].imm = 0;
4404 for (j = 0; j < parts; j++, idx++)
4405 inst.operands[i].imm |= generic_bignum[idx]
4406 << (LITTLENUM_NUMBER_OF_BITS * j);
4407 inst.operands[i].reg = 0;
4408 for (j = 0; j < parts; j++, idx++)
4409 inst.operands[i].reg |= generic_bignum[idx]
4410 << (LITTLENUM_NUMBER_OF_BITS * j);
4411 inst.operands[i].regisimm = 1;
4412 }
4413 else
4414 return FAIL;
5f4273c7 4415
5287ad62
JB
4416 *str = ptr;
4417
4418 return SUCCESS;
4419}
4420
c19d1205
ZW
4421/* Returns the pseudo-register number of an FPA immediate constant,
4422 or FAIL if there isn't a valid constant here. */
b99bd4ef 4423
c19d1205
ZW
4424static int
4425parse_fpa_immediate (char ** str)
4426{
4427 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4428 char * save_in;
4429 expressionS exp;
4430 int i;
4431 int j;
b99bd4ef 4432
c19d1205
ZW
4433 /* First try and match exact strings, this is to guarantee
4434 that some formats will work even for cross assembly. */
b99bd4ef 4435
c19d1205
ZW
4436 for (i = 0; fp_const[i]; i++)
4437 {
4438 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4439 {
c19d1205 4440 char *start = *str;
b99bd4ef 4441
c19d1205
ZW
4442 *str += strlen (fp_const[i]);
4443 if (is_end_of_line[(unsigned char) **str])
4444 return i + 8;
4445 *str = start;
4446 }
4447 }
b99bd4ef 4448
c19d1205
ZW
4449 /* Just because we didn't get a match doesn't mean that the constant
4450 isn't valid, just that it is in a format that we don't
4451 automatically recognize. Try parsing it with the standard
4452 expression routines. */
b99bd4ef 4453
c19d1205 4454 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4455
c19d1205
ZW
4456 /* Look for a raw floating point number. */
4457 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4458 && is_end_of_line[(unsigned char) *save_in])
4459 {
4460 for (i = 0; i < NUM_FLOAT_VALS; i++)
4461 {
4462 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4463 {
c19d1205
ZW
4464 if (words[j] != fp_values[i][j])
4465 break;
b99bd4ef
NC
4466 }
4467
c19d1205 4468 if (j == MAX_LITTLENUMS)
b99bd4ef 4469 {
c19d1205
ZW
4470 *str = save_in;
4471 return i + 8;
b99bd4ef
NC
4472 }
4473 }
4474 }
b99bd4ef 4475
c19d1205
ZW
4476 /* Try and parse a more complex expression, this will probably fail
4477 unless the code uses a floating point prefix (eg "0f"). */
4478 save_in = input_line_pointer;
4479 input_line_pointer = *str;
4480 if (expression (&exp) == absolute_section
4481 && exp.X_op == O_big
4482 && exp.X_add_number < 0)
4483 {
4484 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4485 Ditto for 15. */
4486 if (gen_to_words (words, 5, (long) 15) == 0)
4487 {
4488 for (i = 0; i < NUM_FLOAT_VALS; i++)
4489 {
4490 for (j = 0; j < MAX_LITTLENUMS; j++)
4491 {
4492 if (words[j] != fp_values[i][j])
4493 break;
4494 }
b99bd4ef 4495
c19d1205
ZW
4496 if (j == MAX_LITTLENUMS)
4497 {
4498 *str = input_line_pointer;
4499 input_line_pointer = save_in;
4500 return i + 8;
4501 }
4502 }
4503 }
b99bd4ef
NC
4504 }
4505
c19d1205
ZW
4506 *str = input_line_pointer;
4507 input_line_pointer = save_in;
4508 inst.error = _("invalid FPA immediate expression");
4509 return FAIL;
b99bd4ef
NC
4510}
4511
136da414
JB
4512/* Returns 1 if a number has "quarter-precision" float format
4513 0baBbbbbbc defgh000 00000000 00000000. */
4514
4515static int
4516is_quarter_float (unsigned imm)
4517{
4518 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4519 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4520}
4521
4522/* Parse an 8-bit "quarter-precision" floating point number of the form:
4523 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4524 The zero and minus-zero cases need special handling, since they can't be
4525 encoded in the "quarter-precision" float format, but can nonetheless be
4526 loaded as integer constants. */
136da414
JB
4527
4528static unsigned
4529parse_qfloat_immediate (char **ccp, int *immed)
4530{
4531 char *str = *ccp;
c96612cc 4532 char *fpnum;
136da414 4533 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4534 int found_fpchar = 0;
5f4273c7 4535
136da414 4536 skip_past_char (&str, '#');
5f4273c7 4537
c96612cc
JB
4538 /* We must not accidentally parse an integer as a floating-point number. Make
4539 sure that the value we parse is not an integer by checking for special
4540 characters '.' or 'e'.
4541 FIXME: This is a horrible hack, but doing better is tricky because type
4542 information isn't in a very usable state at parse time. */
4543 fpnum = str;
4544 skip_whitespace (fpnum);
4545
4546 if (strncmp (fpnum, "0x", 2) == 0)
4547 return FAIL;
4548 else
4549 {
4550 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4551 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4552 {
4553 found_fpchar = 1;
4554 break;
4555 }
4556
4557 if (!found_fpchar)
4558 return FAIL;
4559 }
5f4273c7 4560
136da414
JB
4561 if ((str = atof_ieee (str, 's', words)) != NULL)
4562 {
4563 unsigned fpword = 0;
4564 int i;
5f4273c7 4565
136da414
JB
4566 /* Our FP word must be 32 bits (single-precision FP). */
4567 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4568 {
4569 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4570 fpword |= words[i];
4571 }
5f4273c7 4572
c96612cc 4573 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4574 *immed = fpword;
4575 else
4576 return FAIL;
4577
4578 *ccp = str;
5f4273c7 4579
136da414
JB
4580 return SUCCESS;
4581 }
5f4273c7 4582
136da414
JB
4583 return FAIL;
4584}
4585
c19d1205
ZW
4586/* Shift operands. */
4587enum shift_kind
b99bd4ef 4588{
c19d1205
ZW
4589 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4590};
b99bd4ef 4591
c19d1205
ZW
4592struct asm_shift_name
4593{
4594 const char *name;
4595 enum shift_kind kind;
4596};
b99bd4ef 4597
c19d1205
ZW
4598/* Third argument to parse_shift. */
4599enum parse_shift_mode
4600{
4601 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4602 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4603 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4604 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4605 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4606};
b99bd4ef 4607
c19d1205
ZW
4608/* Parse a <shift> specifier on an ARM data processing instruction.
4609 This has three forms:
b99bd4ef 4610
c19d1205
ZW
4611 (LSL|LSR|ASL|ASR|ROR) Rs
4612 (LSL|LSR|ASL|ASR|ROR) #imm
4613 RRX
b99bd4ef 4614
c19d1205
ZW
4615 Note that ASL is assimilated to LSL in the instruction encoding, and
4616 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4617
c19d1205
ZW
4618static int
4619parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4620{
c19d1205
ZW
4621 const struct asm_shift_name *shift_name;
4622 enum shift_kind shift;
4623 char *s = *str;
4624 char *p = s;
4625 int reg;
b99bd4ef 4626
c19d1205
ZW
4627 for (p = *str; ISALPHA (*p); p++)
4628 ;
b99bd4ef 4629
c19d1205 4630 if (p == *str)
b99bd4ef 4631 {
c19d1205
ZW
4632 inst.error = _("shift expression expected");
4633 return FAIL;
b99bd4ef
NC
4634 }
4635
21d799b5
NC
4636 shift_name = (const struct asm_shift_name *) hash_find_n (arm_shift_hsh, *str,
4637 p - *str);
c19d1205
ZW
4638
4639 if (shift_name == NULL)
b99bd4ef 4640 {
c19d1205
ZW
4641 inst.error = _("shift expression expected");
4642 return FAIL;
b99bd4ef
NC
4643 }
4644
c19d1205 4645 shift = shift_name->kind;
b99bd4ef 4646
c19d1205
ZW
4647 switch (mode)
4648 {
4649 case NO_SHIFT_RESTRICT:
4650 case SHIFT_IMMEDIATE: break;
b99bd4ef 4651
c19d1205
ZW
4652 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4653 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4654 {
4655 inst.error = _("'LSL' or 'ASR' required");
4656 return FAIL;
4657 }
4658 break;
b99bd4ef 4659
c19d1205
ZW
4660 case SHIFT_LSL_IMMEDIATE:
4661 if (shift != SHIFT_LSL)
4662 {
4663 inst.error = _("'LSL' required");
4664 return FAIL;
4665 }
4666 break;
b99bd4ef 4667
c19d1205
ZW
4668 case SHIFT_ASR_IMMEDIATE:
4669 if (shift != SHIFT_ASR)
4670 {
4671 inst.error = _("'ASR' required");
4672 return FAIL;
4673 }
4674 break;
b99bd4ef 4675
c19d1205
ZW
4676 default: abort ();
4677 }
b99bd4ef 4678
c19d1205
ZW
4679 if (shift != SHIFT_RRX)
4680 {
4681 /* Whitespace can appear here if the next thing is a bare digit. */
4682 skip_whitespace (p);
b99bd4ef 4683
c19d1205 4684 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4685 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4686 {
4687 inst.operands[i].imm = reg;
4688 inst.operands[i].immisreg = 1;
4689 }
4690 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4691 return FAIL;
4692 }
4693 inst.operands[i].shift_kind = shift;
4694 inst.operands[i].shifted = 1;
4695 *str = p;
4696 return SUCCESS;
b99bd4ef
NC
4697}
4698
c19d1205 4699/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4700
c19d1205
ZW
4701 #<immediate>
4702 #<immediate>, <rotate>
4703 <Rm>
4704 <Rm>, <shift>
b99bd4ef 4705
c19d1205
ZW
4706 where <shift> is defined by parse_shift above, and <rotate> is a
4707 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4708 is deferred to md_apply_fix. */
b99bd4ef 4709
c19d1205
ZW
4710static int
4711parse_shifter_operand (char **str, int i)
4712{
4713 int value;
4714 expressionS expr;
b99bd4ef 4715
dcbf9037 4716 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4717 {
4718 inst.operands[i].reg = value;
4719 inst.operands[i].isreg = 1;
b99bd4ef 4720
c19d1205
ZW
4721 /* parse_shift will override this if appropriate */
4722 inst.reloc.exp.X_op = O_constant;
4723 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4724
c19d1205
ZW
4725 if (skip_past_comma (str) == FAIL)
4726 return SUCCESS;
b99bd4ef 4727
c19d1205
ZW
4728 /* Shift operation on register. */
4729 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4730 }
4731
c19d1205
ZW
4732 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4733 return FAIL;
b99bd4ef 4734
c19d1205 4735 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4736 {
c19d1205
ZW
4737 /* #x, y -- ie explicit rotation by Y. */
4738 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4739 return FAIL;
b99bd4ef 4740
c19d1205
ZW
4741 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4742 {
4743 inst.error = _("constant expression expected");
4744 return FAIL;
4745 }
b99bd4ef 4746
c19d1205
ZW
4747 value = expr.X_add_number;
4748 if (value < 0 || value > 30 || value % 2 != 0)
4749 {
4750 inst.error = _("invalid rotation");
4751 return FAIL;
4752 }
4753 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4754 {
4755 inst.error = _("invalid constant");
4756 return FAIL;
4757 }
09d92015 4758
55cf6793 4759 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4760 inst.reloc.exp.X_add_number
4761 = (((inst.reloc.exp.X_add_number << (32 - value))
4762 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4763 }
4764
c19d1205
ZW
4765 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4766 inst.reloc.pc_rel = 0;
4767 return SUCCESS;
09d92015
MM
4768}
4769
4962c51a
MS
4770/* Group relocation information. Each entry in the table contains the
4771 textual name of the relocation as may appear in assembler source
4772 and must end with a colon.
4773 Along with this textual name are the relocation codes to be used if
4774 the corresponding instruction is an ALU instruction (ADD or SUB only),
4775 an LDR, an LDRS, or an LDC. */
4776
4777struct group_reloc_table_entry
4778{
4779 const char *name;
4780 int alu_code;
4781 int ldr_code;
4782 int ldrs_code;
4783 int ldc_code;
4784};
4785
4786typedef enum
4787{
4788 /* Varieties of non-ALU group relocation. */
4789
4790 GROUP_LDR,
4791 GROUP_LDRS,
4792 GROUP_LDC
4793} group_reloc_type;
4794
4795static struct group_reloc_table_entry group_reloc_table[] =
4796 { /* Program counter relative: */
4797 { "pc_g0_nc",
4798 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4799 0, /* LDR */
4800 0, /* LDRS */
4801 0 }, /* LDC */
4802 { "pc_g0",
4803 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4804 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4805 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4806 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4807 { "pc_g1_nc",
4808 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4809 0, /* LDR */
4810 0, /* LDRS */
4811 0 }, /* LDC */
4812 { "pc_g1",
4813 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4814 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4815 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4816 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4817 { "pc_g2",
4818 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4819 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4820 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4821 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4822 /* Section base relative */
4823 { "sb_g0_nc",
4824 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4825 0, /* LDR */
4826 0, /* LDRS */
4827 0 }, /* LDC */
4828 { "sb_g0",
4829 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4830 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4831 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4832 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4833 { "sb_g1_nc",
4834 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4835 0, /* LDR */
4836 0, /* LDRS */
4837 0 }, /* LDC */
4838 { "sb_g1",
4839 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4840 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4841 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4842 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4843 { "sb_g2",
4844 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4845 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4846 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4847 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4848
4849/* Given the address of a pointer pointing to the textual name of a group
4850 relocation as may appear in assembler source, attempt to find its details
4851 in group_reloc_table. The pointer will be updated to the character after
4852 the trailing colon. On failure, FAIL will be returned; SUCCESS
4853 otherwise. On success, *entry will be updated to point at the relevant
4854 group_reloc_table entry. */
4855
4856static int
4857find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4858{
4859 unsigned int i;
4860 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4861 {
4862 int length = strlen (group_reloc_table[i].name);
4863
5f4273c7
NC
4864 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4865 && (*str)[length] == ':')
4962c51a
MS
4866 {
4867 *out = &group_reloc_table[i];
4868 *str += (length + 1);
4869 return SUCCESS;
4870 }
4871 }
4872
4873 return FAIL;
4874}
4875
4876/* Parse a <shifter_operand> for an ARM data processing instruction
4877 (as for parse_shifter_operand) where group relocations are allowed:
4878
4879 #<immediate>
4880 #<immediate>, <rotate>
4881 #:<group_reloc>:<expression>
4882 <Rm>
4883 <Rm>, <shift>
4884
4885 where <group_reloc> is one of the strings defined in group_reloc_table.
4886 The hashes are optional.
4887
4888 Everything else is as for parse_shifter_operand. */
4889
4890static parse_operand_result
4891parse_shifter_operand_group_reloc (char **str, int i)
4892{
4893 /* Determine if we have the sequence of characters #: or just :
4894 coming next. If we do, then we check for a group relocation.
4895 If we don't, punt the whole lot to parse_shifter_operand. */
4896
4897 if (((*str)[0] == '#' && (*str)[1] == ':')
4898 || (*str)[0] == ':')
4899 {
4900 struct group_reloc_table_entry *entry;
4901
4902 if ((*str)[0] == '#')
4903 (*str) += 2;
4904 else
4905 (*str)++;
4906
4907 /* Try to parse a group relocation. Anything else is an error. */
4908 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4909 {
4910 inst.error = _("unknown group relocation");
4911 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4912 }
4913
4914 /* We now have the group relocation table entry corresponding to
4915 the name in the assembler source. Next, we parse the expression. */
4916 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4917 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4918
4919 /* Record the relocation type (always the ALU variant here). */
21d799b5 4920 inst.reloc.type = (bfd_reloc_code_real_type) entry->alu_code;
9c2799c2 4921 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4922
4923 return PARSE_OPERAND_SUCCESS;
4924 }
4925 else
4926 return parse_shifter_operand (str, i) == SUCCESS
4927 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4928
4929 /* Never reached. */
4930}
4931
c19d1205
ZW
4932/* Parse all forms of an ARM address expression. Information is written
4933 to inst.operands[i] and/or inst.reloc.
09d92015 4934
c19d1205 4935 Preindexed addressing (.preind=1):
09d92015 4936
c19d1205
ZW
4937 [Rn, #offset] .reg=Rn .reloc.exp=offset
4938 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4939 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4940 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4941
c19d1205 4942 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4943
c19d1205 4944 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4945
c19d1205
ZW
4946 [Rn], #offset .reg=Rn .reloc.exp=offset
4947 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4948 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4949 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4950
c19d1205 4951 Unindexed addressing (.preind=0, .postind=0):
09d92015 4952
c19d1205 4953 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4954
c19d1205 4955 Other:
09d92015 4956
c19d1205
ZW
4957 [Rn]{!} shorthand for [Rn,#0]{!}
4958 =immediate .isreg=0 .reloc.exp=immediate
4959 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4960
c19d1205
ZW
4961 It is the caller's responsibility to check for addressing modes not
4962 supported by the instruction, and to set inst.reloc.type. */
4963
4962c51a
MS
4964static parse_operand_result
4965parse_address_main (char **str, int i, int group_relocations,
4966 group_reloc_type group_type)
09d92015 4967{
c19d1205
ZW
4968 char *p = *str;
4969 int reg;
09d92015 4970
c19d1205 4971 if (skip_past_char (&p, '[') == FAIL)
09d92015 4972 {
c19d1205
ZW
4973 if (skip_past_char (&p, '=') == FAIL)
4974 {
974da60d 4975 /* Bare address - translate to PC-relative offset. */
c19d1205
ZW
4976 inst.reloc.pc_rel = 1;
4977 inst.operands[i].reg = REG_PC;
4978 inst.operands[i].isreg = 1;
4979 inst.operands[i].preind = 1;
4980 }
974da60d 4981 /* Otherwise a load-constant pseudo op, no special treatment needed here. */
09d92015 4982
c19d1205 4983 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4984 return PARSE_OPERAND_FAIL;
09d92015 4985
c19d1205 4986 *str = p;
4962c51a 4987 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4988 }
4989
dcbf9037 4990 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4991 {
c19d1205 4992 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4993 return PARSE_OPERAND_FAIL;
09d92015 4994 }
c19d1205
ZW
4995 inst.operands[i].reg = reg;
4996 inst.operands[i].isreg = 1;
09d92015 4997
c19d1205 4998 if (skip_past_comma (&p) == SUCCESS)
09d92015 4999 {
c19d1205 5000 inst.operands[i].preind = 1;
09d92015 5001
c19d1205
ZW
5002 if (*p == '+') p++;
5003 else if (*p == '-') p++, inst.operands[i].negative = 1;
5004
dcbf9037 5005 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 5006 {
c19d1205
ZW
5007 inst.operands[i].imm = reg;
5008 inst.operands[i].immisreg = 1;
5009
5010 if (skip_past_comma (&p) == SUCCESS)
5011 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5012 return PARSE_OPERAND_FAIL;
c19d1205 5013 }
5287ad62
JB
5014 else if (skip_past_char (&p, ':') == SUCCESS)
5015 {
5016 /* FIXME: '@' should be used here, but it's filtered out by generic
5017 code before we get to see it here. This may be subject to
5018 change. */
5019 expressionS exp;
5020 my_get_expression (&exp, &p, GE_NO_PREFIX);
5021 if (exp.X_op != O_constant)
5022 {
5023 inst.error = _("alignment must be constant");
4962c51a 5024 return PARSE_OPERAND_FAIL;
5287ad62
JB
5025 }
5026 inst.operands[i].imm = exp.X_add_number << 8;
5027 inst.operands[i].immisalign = 1;
5028 /* Alignments are not pre-indexes. */
5029 inst.operands[i].preind = 0;
5030 }
c19d1205
ZW
5031 else
5032 {
5033 if (inst.operands[i].negative)
5034 {
5035 inst.operands[i].negative = 0;
5036 p--;
5037 }
4962c51a 5038
5f4273c7
NC
5039 if (group_relocations
5040 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
5041 {
5042 struct group_reloc_table_entry *entry;
5043
5044 /* Skip over the #: or : sequence. */
5045 if (*p == '#')
5046 p += 2;
5047 else
5048 p++;
5049
5050 /* Try to parse a group relocation. Anything else is an
5051 error. */
5052 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
5053 {
5054 inst.error = _("unknown group relocation");
5055 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5056 }
5057
5058 /* We now have the group relocation table entry corresponding to
5059 the name in the assembler source. Next, we parse the
5060 expression. */
5061 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5062 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5063
5064 /* Record the relocation type. */
5065 switch (group_type)
5066 {
5067 case GROUP_LDR:
21d799b5 5068 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldr_code;
4962c51a
MS
5069 break;
5070
5071 case GROUP_LDRS:
21d799b5 5072 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldrs_code;
4962c51a
MS
5073 break;
5074
5075 case GROUP_LDC:
21d799b5 5076 inst.reloc.type = (bfd_reloc_code_real_type) entry->ldc_code;
4962c51a
MS
5077 break;
5078
5079 default:
9c2799c2 5080 gas_assert (0);
4962c51a
MS
5081 }
5082
5083 if (inst.reloc.type == 0)
5084 {
5085 inst.error = _("this group relocation is not allowed on this instruction");
5086 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
5087 }
5088 }
5089 else
5090 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
5091 return PARSE_OPERAND_FAIL;
09d92015
MM
5092 }
5093 }
5094
c19d1205 5095 if (skip_past_char (&p, ']') == FAIL)
09d92015 5096 {
c19d1205 5097 inst.error = _("']' expected");
4962c51a 5098 return PARSE_OPERAND_FAIL;
09d92015
MM
5099 }
5100
c19d1205
ZW
5101 if (skip_past_char (&p, '!') == SUCCESS)
5102 inst.operands[i].writeback = 1;
09d92015 5103
c19d1205 5104 else if (skip_past_comma (&p) == SUCCESS)
09d92015 5105 {
c19d1205
ZW
5106 if (skip_past_char (&p, '{') == SUCCESS)
5107 {
5108 /* [Rn], {expr} - unindexed, with option */
5109 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 5110 0, 255, TRUE) == FAIL)
4962c51a 5111 return PARSE_OPERAND_FAIL;
09d92015 5112
c19d1205
ZW
5113 if (skip_past_char (&p, '}') == FAIL)
5114 {
5115 inst.error = _("'}' expected at end of 'option' field");
4962c51a 5116 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5117 }
5118 if (inst.operands[i].preind)
5119 {
5120 inst.error = _("cannot combine index with option");
4962c51a 5121 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5122 }
5123 *str = p;
4962c51a 5124 return PARSE_OPERAND_SUCCESS;
09d92015 5125 }
c19d1205
ZW
5126 else
5127 {
5128 inst.operands[i].postind = 1;
5129 inst.operands[i].writeback = 1;
09d92015 5130
c19d1205
ZW
5131 if (inst.operands[i].preind)
5132 {
5133 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 5134 return PARSE_OPERAND_FAIL;
c19d1205 5135 }
09d92015 5136
c19d1205
ZW
5137 if (*p == '+') p++;
5138 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 5139
dcbf9037 5140 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 5141 {
5287ad62
JB
5142 /* We might be using the immediate for alignment already. If we
5143 are, OR the register number into the low-order bits. */
5144 if (inst.operands[i].immisalign)
5145 inst.operands[i].imm |= reg;
5146 else
5147 inst.operands[i].imm = reg;
c19d1205 5148 inst.operands[i].immisreg = 1;
a737bd4d 5149
c19d1205
ZW
5150 if (skip_past_comma (&p) == SUCCESS)
5151 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 5152 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5153 }
5154 else
5155 {
5156 if (inst.operands[i].negative)
5157 {
5158 inst.operands[i].negative = 0;
5159 p--;
5160 }
5161 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 5162 return PARSE_OPERAND_FAIL;
c19d1205
ZW
5163 }
5164 }
a737bd4d
NC
5165 }
5166
c19d1205
ZW
5167 /* If at this point neither .preind nor .postind is set, we have a
5168 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
5169 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
5170 {
5171 inst.operands[i].preind = 1;
5172 inst.reloc.exp.X_op = O_constant;
5173 inst.reloc.exp.X_add_number = 0;
5174 }
5175 *str = p;
4962c51a
MS
5176 return PARSE_OPERAND_SUCCESS;
5177}
5178
5179static int
5180parse_address (char **str, int i)
5181{
21d799b5 5182 return parse_address_main (str, i, 0, GROUP_LDR) == PARSE_OPERAND_SUCCESS
4962c51a
MS
5183 ? SUCCESS : FAIL;
5184}
5185
5186static parse_operand_result
5187parse_address_group_reloc (char **str, int i, group_reloc_type type)
5188{
5189 return parse_address_main (str, i, 1, type);
a737bd4d
NC
5190}
5191
b6895b4f
PB
5192/* Parse an operand for a MOVW or MOVT instruction. */
5193static int
5194parse_half (char **str)
5195{
5196 char * p;
5f4273c7 5197
b6895b4f
PB
5198 p = *str;
5199 skip_past_char (&p, '#');
5f4273c7 5200 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
5201 inst.reloc.type = BFD_RELOC_ARM_MOVW;
5202 else if (strncasecmp (p, ":upper16:", 9) == 0)
5203 inst.reloc.type = BFD_RELOC_ARM_MOVT;
5204
5205 if (inst.reloc.type != BFD_RELOC_UNUSED)
5206 {
5207 p += 9;
5f4273c7 5208 skip_whitespace (p);
b6895b4f
PB
5209 }
5210
5211 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
5212 return FAIL;
5213
5214 if (inst.reloc.type == BFD_RELOC_UNUSED)
5215 {
5216 if (inst.reloc.exp.X_op != O_constant)
5217 {
5218 inst.error = _("constant expression expected");
5219 return FAIL;
5220 }
5221 if (inst.reloc.exp.X_add_number < 0
5222 || inst.reloc.exp.X_add_number > 0xffff)
5223 {
5224 inst.error = _("immediate value out of range");
5225 return FAIL;
5226 }
5227 }
5228 *str = p;
5229 return SUCCESS;
5230}
5231
c19d1205 5232/* Miscellaneous. */
a737bd4d 5233
c19d1205
ZW
5234/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5235 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5236static int
5237parse_psr (char **str)
09d92015 5238{
c19d1205
ZW
5239 char *p;
5240 unsigned long psr_field;
62b3e311
PB
5241 const struct asm_psr *psr;
5242 char *start;
09d92015 5243
c19d1205
ZW
5244 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5245 feature for ease of use and backwards compatibility. */
5246 p = *str;
62b3e311 5247 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5248 psr_field = SPSR_BIT;
62b3e311 5249 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5250 psr_field = 0;
5251 else
62b3e311
PB
5252 {
5253 start = p;
5254 do
5255 p++;
5256 while (ISALNUM (*p) || *p == '_');
5257
21d799b5
NC
5258 psr = (const struct asm_psr *) hash_find_n (arm_v7m_psr_hsh, start,
5259 p - start);
62b3e311
PB
5260 if (!psr)
5261 return FAIL;
09d92015 5262
62b3e311
PB
5263 *str = p;
5264 return psr->field;
5265 }
09d92015 5266
62b3e311 5267 p += 4;
c19d1205
ZW
5268 if (*p == '_')
5269 {
5270 /* A suffix follows. */
c19d1205
ZW
5271 p++;
5272 start = p;
a737bd4d 5273
c19d1205
ZW
5274 do
5275 p++;
5276 while (ISALNUM (*p) || *p == '_');
a737bd4d 5277
21d799b5
NC
5278 psr = (const struct asm_psr *) hash_find_n (arm_psr_hsh, start,
5279 p - start);
c19d1205
ZW
5280 if (!psr)
5281 goto error;
a737bd4d 5282
c19d1205 5283 psr_field |= psr->field;
a737bd4d 5284 }
c19d1205 5285 else
a737bd4d 5286 {
c19d1205
ZW
5287 if (ISALNUM (*p))
5288 goto error; /* Garbage after "[CS]PSR". */
5289
5290 psr_field |= (PSR_c | PSR_f);
a737bd4d 5291 }
c19d1205
ZW
5292 *str = p;
5293 return psr_field;
a737bd4d 5294
c19d1205
ZW
5295 error:
5296 inst.error = _("flag for {c}psr instruction expected");
5297 return FAIL;
a737bd4d
NC
5298}
5299
c19d1205
ZW
5300/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5301 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5302
c19d1205
ZW
5303static int
5304parse_cps_flags (char **str)
a737bd4d 5305{
c19d1205
ZW
5306 int val = 0;
5307 int saw_a_flag = 0;
5308 char *s = *str;
a737bd4d 5309
c19d1205
ZW
5310 for (;;)
5311 switch (*s++)
5312 {
5313 case '\0': case ',':
5314 goto done;
a737bd4d 5315
c19d1205
ZW
5316 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5317 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5318 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5319
c19d1205
ZW
5320 default:
5321 inst.error = _("unrecognized CPS flag");
5322 return FAIL;
5323 }
a737bd4d 5324
c19d1205
ZW
5325 done:
5326 if (saw_a_flag == 0)
a737bd4d 5327 {
c19d1205
ZW
5328 inst.error = _("missing CPS flags");
5329 return FAIL;
a737bd4d 5330 }
a737bd4d 5331
c19d1205
ZW
5332 *str = s - 1;
5333 return val;
a737bd4d
NC
5334}
5335
c19d1205
ZW
5336/* Parse an endian specifier ("BE" or "LE", case insensitive);
5337 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5338
5339static int
c19d1205 5340parse_endian_specifier (char **str)
a737bd4d 5341{
c19d1205
ZW
5342 int little_endian;
5343 char *s = *str;
a737bd4d 5344
c19d1205
ZW
5345 if (strncasecmp (s, "BE", 2))
5346 little_endian = 0;
5347 else if (strncasecmp (s, "LE", 2))
5348 little_endian = 1;
5349 else
a737bd4d 5350 {
c19d1205 5351 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5352 return FAIL;
5353 }
5354
c19d1205 5355 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5356 {
c19d1205 5357 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5358 return FAIL;
5359 }
5360
c19d1205
ZW
5361 *str = s + 2;
5362 return little_endian;
5363}
a737bd4d 5364
c19d1205
ZW
5365/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5366 value suitable for poking into the rotate field of an sxt or sxta
5367 instruction, or FAIL on error. */
5368
5369static int
5370parse_ror (char **str)
5371{
5372 int rot;
5373 char *s = *str;
5374
5375 if (strncasecmp (s, "ROR", 3) == 0)
5376 s += 3;
5377 else
a737bd4d 5378 {
c19d1205 5379 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5380 return FAIL;
5381 }
c19d1205
ZW
5382
5383 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5384 return FAIL;
5385
5386 switch (rot)
a737bd4d 5387 {
c19d1205
ZW
5388 case 0: *str = s; return 0x0;
5389 case 8: *str = s; return 0x1;
5390 case 16: *str = s; return 0x2;
5391 case 24: *str = s; return 0x3;
5392
5393 default:
5394 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5395 return FAIL;
5396 }
c19d1205 5397}
a737bd4d 5398
c19d1205
ZW
5399/* Parse a conditional code (from conds[] below). The value returned is in the
5400 range 0 .. 14, or FAIL. */
5401static int
5402parse_cond (char **str)
5403{
c462b453 5404 char *q;
c19d1205 5405 const struct asm_cond *c;
c462b453
PB
5406 int n;
5407 /* Condition codes are always 2 characters, so matching up to
5408 3 characters is sufficient. */
5409 char cond[3];
a737bd4d 5410
c462b453
PB
5411 q = *str;
5412 n = 0;
5413 while (ISALPHA (*q) && n < 3)
5414 {
e07e6e58 5415 cond[n] = TOLOWER (*q);
c462b453
PB
5416 q++;
5417 n++;
5418 }
a737bd4d 5419
21d799b5 5420 c = (const struct asm_cond *) hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5421 if (!c)
a737bd4d 5422 {
c19d1205 5423 inst.error = _("condition required");
a737bd4d
NC
5424 return FAIL;
5425 }
5426
c19d1205
ZW
5427 *str = q;
5428 return c->value;
5429}
5430
62b3e311
PB
5431/* Parse an option for a barrier instruction. Returns the encoding for the
5432 option, or FAIL. */
5433static int
5434parse_barrier (char **str)
5435{
5436 char *p, *q;
5437 const struct asm_barrier_opt *o;
5438
5439 p = q = *str;
5440 while (ISALPHA (*q))
5441 q++;
5442
21d799b5
NC
5443 o = (const struct asm_barrier_opt *) hash_find_n (arm_barrier_opt_hsh, p,
5444 q - p);
62b3e311
PB
5445 if (!o)
5446 return FAIL;
5447
5448 *str = q;
5449 return o->value;
5450}
5451
92e90b6e
PB
5452/* Parse the operands of a table branch instruction. Similar to a memory
5453 operand. */
5454static int
5455parse_tb (char **str)
5456{
5457 char * p = *str;
5458 int reg;
5459
5460 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5461 {
5462 inst.error = _("'[' expected");
5463 return FAIL;
5464 }
92e90b6e 5465
dcbf9037 5466 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5467 {
5468 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5469 return FAIL;
5470 }
5471 inst.operands[0].reg = reg;
5472
5473 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5474 {
5475 inst.error = _("',' expected");
5476 return FAIL;
5477 }
5f4273c7 5478
dcbf9037 5479 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5480 {
5481 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5482 return FAIL;
5483 }
5484 inst.operands[0].imm = reg;
5485
5486 if (skip_past_comma (&p) == SUCCESS)
5487 {
5488 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5489 return FAIL;
5490 if (inst.reloc.exp.X_add_number != 1)
5491 {
5492 inst.error = _("invalid shift");
5493 return FAIL;
5494 }
5495 inst.operands[0].shifted = 1;
5496 }
5497
5498 if (skip_past_char (&p, ']') == FAIL)
5499 {
5500 inst.error = _("']' expected");
5501 return FAIL;
5502 }
5503 *str = p;
5504 return SUCCESS;
5505}
5506
5287ad62
JB
5507/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5508 information on the types the operands can take and how they are encoded.
037e8744
JB
5509 Up to four operands may be read; this function handles setting the
5510 ".present" field for each read operand itself.
5287ad62
JB
5511 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5512 else returns FAIL. */
5513
5514static int
5515parse_neon_mov (char **str, int *which_operand)
5516{
5517 int i = *which_operand, val;
5518 enum arm_reg_type rtype;
5519 char *ptr = *str;
dcbf9037 5520 struct neon_type_el optype;
5f4273c7 5521
dcbf9037 5522 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5523 {
5524 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5525 inst.operands[i].reg = val;
5526 inst.operands[i].isscalar = 1;
dcbf9037 5527 inst.operands[i].vectype = optype;
5287ad62
JB
5528 inst.operands[i++].present = 1;
5529
5530 if (skip_past_comma (&ptr) == FAIL)
5531 goto wanted_comma;
5f4273c7 5532
dcbf9037 5533 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5534 goto wanted_arm;
5f4273c7 5535
5287ad62
JB
5536 inst.operands[i].reg = val;
5537 inst.operands[i].isreg = 1;
5538 inst.operands[i].present = 1;
5539 }
037e8744 5540 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5541 != FAIL)
5287ad62
JB
5542 {
5543 /* Cases 0, 1, 2, 3, 5 (D only). */
5544 if (skip_past_comma (&ptr) == FAIL)
5545 goto wanted_comma;
5f4273c7 5546
5287ad62
JB
5547 inst.operands[i].reg = val;
5548 inst.operands[i].isreg = 1;
5549 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5550 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5551 inst.operands[i].isvec = 1;
dcbf9037 5552 inst.operands[i].vectype = optype;
5287ad62
JB
5553 inst.operands[i++].present = 1;
5554
dcbf9037 5555 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5556 {
037e8744
JB
5557 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5558 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5559 inst.operands[i].reg = val;
5560 inst.operands[i].isreg = 1;
037e8744 5561 inst.operands[i].present = 1;
5287ad62
JB
5562
5563 if (rtype == REG_TYPE_NQ)
5564 {
dcbf9037 5565 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5566 return FAIL;
5567 }
037e8744
JB
5568 else if (rtype != REG_TYPE_VFS)
5569 {
5570 i++;
5571 if (skip_past_comma (&ptr) == FAIL)
5572 goto wanted_comma;
5573 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5574 goto wanted_arm;
5575 inst.operands[i].reg = val;
5576 inst.operands[i].isreg = 1;
5577 inst.operands[i].present = 1;
5578 }
5287ad62 5579 }
037e8744
JB
5580 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5581 &optype)) != FAIL)
5287ad62
JB
5582 {
5583 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5584 Case 1: VMOV<c><q> <Dd>, <Dm>
5585 Case 8: VMOV.F32 <Sd>, <Sm>
5586 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5587
5588 inst.operands[i].reg = val;
5589 inst.operands[i].isreg = 1;
5590 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5591 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5592 inst.operands[i].isvec = 1;
dcbf9037 5593 inst.operands[i].vectype = optype;
5287ad62 5594 inst.operands[i].present = 1;
5f4273c7 5595
037e8744
JB
5596 if (skip_past_comma (&ptr) == SUCCESS)
5597 {
5598 /* Case 15. */
5599 i++;
5600
5601 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5602 goto wanted_arm;
5603
5604 inst.operands[i].reg = val;
5605 inst.operands[i].isreg = 1;
5606 inst.operands[i++].present = 1;
5f4273c7 5607
037e8744
JB
5608 if (skip_past_comma (&ptr) == FAIL)
5609 goto wanted_comma;
5f4273c7 5610
037e8744
JB
5611 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5612 goto wanted_arm;
5f4273c7 5613
037e8744
JB
5614 inst.operands[i].reg = val;
5615 inst.operands[i].isreg = 1;
5616 inst.operands[i++].present = 1;
5617 }
5287ad62 5618 }
4641781c
PB
5619 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5620 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5621 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5622 Case 10: VMOV.F32 <Sd>, #<imm>
5623 Case 11: VMOV.F64 <Dd>, #<imm> */
5624 inst.operands[i].immisfloat = 1;
5625 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5626 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5627 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5628 ;
5287ad62
JB
5629 else
5630 {
dcbf9037 5631 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5632 return FAIL;
5633 }
5634 }
dcbf9037 5635 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5636 {
5637 /* Cases 6, 7. */
5638 inst.operands[i].reg = val;
5639 inst.operands[i].isreg = 1;
5640 inst.operands[i++].present = 1;
5f4273c7 5641
5287ad62
JB
5642 if (skip_past_comma (&ptr) == FAIL)
5643 goto wanted_comma;
5f4273c7 5644
dcbf9037 5645 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5646 {
5647 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5648 inst.operands[i].reg = val;
5649 inst.operands[i].isscalar = 1;
5650 inst.operands[i].present = 1;
dcbf9037 5651 inst.operands[i].vectype = optype;
5287ad62 5652 }
dcbf9037 5653 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5654 {
5655 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5656 inst.operands[i].reg = val;
5657 inst.operands[i].isreg = 1;
5658 inst.operands[i++].present = 1;
5f4273c7 5659
5287ad62
JB
5660 if (skip_past_comma (&ptr) == FAIL)
5661 goto wanted_comma;
5f4273c7 5662
037e8744 5663 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5664 == FAIL)
5287ad62 5665 {
037e8744 5666 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5667 return FAIL;
5668 }
5669
5670 inst.operands[i].reg = val;
5671 inst.operands[i].isreg = 1;
037e8744
JB
5672 inst.operands[i].isvec = 1;
5673 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5674 inst.operands[i].vectype = optype;
5287ad62 5675 inst.operands[i].present = 1;
5f4273c7 5676
037e8744
JB
5677 if (rtype == REG_TYPE_VFS)
5678 {
5679 /* Case 14. */
5680 i++;
5681 if (skip_past_comma (&ptr) == FAIL)
5682 goto wanted_comma;
5683 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5684 &optype)) == FAIL)
5685 {
5686 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5687 return FAIL;
5688 }
5689 inst.operands[i].reg = val;
5690 inst.operands[i].isreg = 1;
5691 inst.operands[i].isvec = 1;
5692 inst.operands[i].issingle = 1;
5693 inst.operands[i].vectype = optype;
5694 inst.operands[i].present = 1;
5695 }
5696 }
5697 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5698 != FAIL)
5699 {
5700 /* Case 13. */
5701 inst.operands[i].reg = val;
5702 inst.operands[i].isreg = 1;
5703 inst.operands[i].isvec = 1;
5704 inst.operands[i].issingle = 1;
5705 inst.operands[i].vectype = optype;
5706 inst.operands[i++].present = 1;
5287ad62
JB
5707 }
5708 }
5709 else
5710 {
dcbf9037 5711 first_error (_("parse error"));
5287ad62
JB
5712 return FAIL;
5713 }
5714
5715 /* Successfully parsed the operands. Update args. */
5716 *which_operand = i;
5717 *str = ptr;
5718 return SUCCESS;
5719
5f4273c7 5720 wanted_comma:
dcbf9037 5721 first_error (_("expected comma"));
5287ad62 5722 return FAIL;
5f4273c7
NC
5723
5724 wanted_arm:
dcbf9037 5725 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5726 return FAIL;
5287ad62
JB
5727}
5728
c19d1205
ZW
5729/* Matcher codes for parse_operands. */
5730enum operand_parse_code
5731{
5732 OP_stop, /* end of line */
5733
5734 OP_RR, /* ARM register */
5735 OP_RRnpc, /* ARM register, not r15 */
5736 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5737 OP_RRw, /* ARM register, not r15, optional trailing ! */
5738 OP_RCP, /* Coprocessor number */
5739 OP_RCN, /* Coprocessor register */
5740 OP_RF, /* FPA register */
5741 OP_RVS, /* VFP single precision register */
5287ad62
JB
5742 OP_RVD, /* VFP double precision register (0..15) */
5743 OP_RND, /* Neon double precision register (0..31) */
5744 OP_RNQ, /* Neon quad precision register */
037e8744 5745 OP_RVSD, /* VFP single or double precision register */
5287ad62 5746 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5747 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5748 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5749 OP_RVC, /* VFP control register */
5750 OP_RMF, /* Maverick F register */
5751 OP_RMD, /* Maverick D register */
5752 OP_RMFX, /* Maverick FX register */
5753 OP_RMDX, /* Maverick DX register */
5754 OP_RMAX, /* Maverick AX register */
5755 OP_RMDS, /* Maverick DSPSC register */
5756 OP_RIWR, /* iWMMXt wR register */
5757 OP_RIWC, /* iWMMXt wC register */
5758 OP_RIWG, /* iWMMXt wCG register */
5759 OP_RXA, /* XScale accumulator register */
5760
5761 OP_REGLST, /* ARM register list */
5762 OP_VRSLST, /* VFP single-precision register list */
5763 OP_VRDLST, /* VFP double-precision register list */
037e8744 5764 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5765 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5766 OP_NSTRLST, /* Neon element/structure list */
5767
5768 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5769 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5770 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5771 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5772 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5773 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5774 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5775 OP_VMOV, /* Neon VMOV operands. */
5776 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5777 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5778 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5779
5780 OP_I0, /* immediate zero */
c19d1205
ZW
5781 OP_I7, /* immediate value 0 .. 7 */
5782 OP_I15, /* 0 .. 15 */
5783 OP_I16, /* 1 .. 16 */
5287ad62 5784 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5785 OP_I31, /* 0 .. 31 */
5786 OP_I31w, /* 0 .. 31, optional trailing ! */
5787 OP_I32, /* 1 .. 32 */
5287ad62
JB
5788 OP_I32z, /* 0 .. 32 */
5789 OP_I63, /* 0 .. 63 */
c19d1205 5790 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5791 OP_I64, /* 1 .. 64 */
5792 OP_I64z, /* 0 .. 64 */
c19d1205 5793 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5794
5795 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5796 OP_I7b, /* 0 .. 7 */
5797 OP_I15b, /* 0 .. 15 */
5798 OP_I31b, /* 0 .. 31 */
5799
5800 OP_SH, /* shifter operand */
4962c51a 5801 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5802 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5803 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5804 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5805 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5806 OP_EXP, /* arbitrary expression */
5807 OP_EXPi, /* same, with optional immediate prefix */
5808 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5809 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5810
5811 OP_CPSF, /* CPS flags */
5812 OP_ENDI, /* Endianness specifier */
5813 OP_PSR, /* CPSR/SPSR mask for msr */
5814 OP_COND, /* conditional code */
92e90b6e 5815 OP_TB, /* Table branch. */
c19d1205 5816
037e8744
JB
5817 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5818 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5819
c19d1205
ZW
5820 OP_RRnpc_I0, /* ARM register or literal 0 */
5821 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5822 OP_RR_EXi, /* ARM register or expression with imm prefix */
5823 OP_RF_IF, /* FPA register or immediate */
5824 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5825 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5826
5827 /* Optional operands. */
5828 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5829 OP_oI31b, /* 0 .. 31 */
5287ad62 5830 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5831 OP_oIffffb, /* 0 .. 65535 */
5832 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5833
5834 OP_oRR, /* ARM register */
5835 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5836 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5837 OP_oRND, /* Optional Neon double precision register */
5838 OP_oRNQ, /* Optional Neon quad precision register */
5839 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5840 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5841 OP_oSHll, /* LSL immediate */
5842 OP_oSHar, /* ASR immediate */
5843 OP_oSHllar, /* LSL or ASR immediate */
5844 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5845 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5846
5847 OP_FIRST_OPTIONAL = OP_oI7b
5848};
a737bd4d 5849
c19d1205
ZW
5850/* Generic instruction operand parser. This does no encoding and no
5851 semantic validation; it merely squirrels values away in the inst
5852 structure. Returns SUCCESS or FAIL depending on whether the
5853 specified grammar matched. */
5854static int
ca3f61f7 5855parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5856{
5857 unsigned const char *upat = pattern;
5858 char *backtrack_pos = 0;
5859 const char *backtrack_error = 0;
5860 int i, val, backtrack_index = 0;
5287ad62 5861 enum arm_reg_type rtype;
4962c51a 5862 parse_operand_result result;
c19d1205 5863
e07e6e58
NC
5864#define po_char_or_fail(chr) \
5865 do \
5866 { \
5867 if (skip_past_char (&str, chr) == FAIL) \
5868 goto bad_args; \
5869 } \
5870 while (0)
c19d1205 5871
e07e6e58
NC
5872#define po_reg_or_fail(regtype) \
5873 do \
dcbf9037 5874 { \
e07e6e58
NC
5875 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5876 & inst.operands[i].vectype); \
5877 if (val == FAIL) \
5878 { \
5879 first_error (_(reg_expected_msgs[regtype])); \
5880 goto failure; \
5881 } \
5882 inst.operands[i].reg = val; \
5883 inst.operands[i].isreg = 1; \
5884 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5885 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5886 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5887 || rtype == REG_TYPE_VFD \
5888 || rtype == REG_TYPE_NQ); \
dcbf9037 5889 } \
e07e6e58
NC
5890 while (0)
5891
5892#define po_reg_or_goto(regtype, label) \
5893 do \
5894 { \
5895 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5896 & inst.operands[i].vectype); \
5897 if (val == FAIL) \
5898 goto label; \
dcbf9037 5899 \
e07e6e58
NC
5900 inst.operands[i].reg = val; \
5901 inst.operands[i].isreg = 1; \
5902 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5903 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5904 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5905 || rtype == REG_TYPE_VFD \
5906 || rtype == REG_TYPE_NQ); \
5907 } \
5908 while (0)
5909
5910#define po_imm_or_fail(min, max, popt) \
5911 do \
5912 { \
5913 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5914 goto failure; \
5915 inst.operands[i].imm = val; \
5916 } \
5917 while (0)
5918
5919#define po_scalar_or_goto(elsz, label) \
5920 do \
5921 { \
5922 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5923 if (val == FAIL) \
5924 goto label; \
5925 inst.operands[i].reg = val; \
5926 inst.operands[i].isscalar = 1; \
5927 } \
5928 while (0)
5929
5930#define po_misc_or_fail(expr) \
5931 do \
5932 { \
5933 if (expr) \
5934 goto failure; \
5935 } \
5936 while (0)
5937
5938#define po_misc_or_fail_no_backtrack(expr) \
5939 do \
5940 { \
5941 result = expr; \
5942 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5943 backtrack_pos = 0; \
5944 if (result != PARSE_OPERAND_SUCCESS) \
5945 goto failure; \
5946 } \
5947 while (0)
4962c51a 5948
c19d1205
ZW
5949 skip_whitespace (str);
5950
5951 for (i = 0; upat[i] != OP_stop; i++)
5952 {
5953 if (upat[i] >= OP_FIRST_OPTIONAL)
5954 {
5955 /* Remember where we are in case we need to backtrack. */
9c2799c2 5956 gas_assert (!backtrack_pos);
c19d1205
ZW
5957 backtrack_pos = str;
5958 backtrack_error = inst.error;
5959 backtrack_index = i;
5960 }
5961
b6702015 5962 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5963 po_char_or_fail (',');
5964
5965 switch (upat[i])
5966 {
5967 /* Registers */
5968 case OP_oRRnpc:
5969 case OP_RRnpc:
5970 case OP_oRR:
5971 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5972 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5973 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5974 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5975 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5976 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5977 case OP_oRND:
5978 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5979 case OP_RVC:
5980 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5981 break;
5982 /* Also accept generic coprocessor regs for unknown registers. */
5983 coproc_reg:
5984 po_reg_or_fail (REG_TYPE_CN);
5985 break;
c19d1205
ZW
5986 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5987 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5988 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5989 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5990 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5991 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5992 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5993 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5994 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5995 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5996 case OP_oRNQ:
5997 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5998 case OP_oRNDQ:
5999 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
6000 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
6001 case OP_oRNSDQ:
6002 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
6003
6004 /* Neon scalar. Using an element size of 8 means that some invalid
6005 scalars are accepted here, so deal with those in later code. */
6006 case OP_RNSC: po_scalar_or_goto (8, failure); break;
6007
6008 /* WARNING: We can expand to two operands here. This has the potential
6009 to totally confuse the backtracking mechanism! It will be OK at
6010 least as long as we don't try to use optional args as well,
6011 though. */
6012 case OP_NILO:
6013 {
6014 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 6015 inst.operands[i].present = 1;
5287ad62
JB
6016 i++;
6017 skip_past_comma (&str);
6018 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
6019 break;
6020 one_reg_only:
6021 /* Optional register operand was omitted. Unfortunately, it's in
6022 operands[i-1] and we need it to be in inst.operands[i]. Fix that
6023 here (this is a bit grotty). */
6024 inst.operands[i] = inst.operands[i-1];
6025 inst.operands[i-1].present = 0;
6026 break;
6027 try_imm:
036dc3f7
PB
6028 /* There's a possibility of getting a 64-bit immediate here, so
6029 we need special handling. */
6030 if (parse_big_immediate (&str, i) == FAIL)
6031 {
6032 inst.error = _("immediate value is out of range");
6033 goto failure;
6034 }
5287ad62
JB
6035 }
6036 break;
6037
6038 case OP_RNDQ_I0:
6039 {
6040 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
6041 break;
6042 try_imm0:
6043 po_imm_or_fail (0, 0, TRUE);
6044 }
6045 break;
6046
037e8744
JB
6047 case OP_RVSD_I0:
6048 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
6049 break;
6050
5287ad62
JB
6051 case OP_RR_RNSC:
6052 {
6053 po_scalar_or_goto (8, try_rr);
6054 break;
6055 try_rr:
6056 po_reg_or_fail (REG_TYPE_RN);
6057 }
6058 break;
6059
037e8744
JB
6060 case OP_RNSDQ_RNSC:
6061 {
6062 po_scalar_or_goto (8, try_nsdq);
6063 break;
6064 try_nsdq:
6065 po_reg_or_fail (REG_TYPE_NSDQ);
6066 }
6067 break;
6068
5287ad62
JB
6069 case OP_RNDQ_RNSC:
6070 {
6071 po_scalar_or_goto (8, try_ndq);
6072 break;
6073 try_ndq:
6074 po_reg_or_fail (REG_TYPE_NDQ);
6075 }
6076 break;
6077
6078 case OP_RND_RNSC:
6079 {
6080 po_scalar_or_goto (8, try_vfd);
6081 break;
6082 try_vfd:
6083 po_reg_or_fail (REG_TYPE_VFD);
6084 }
6085 break;
6086
6087 case OP_VMOV:
6088 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
6089 not careful then bad things might happen. */
6090 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
6091 break;
6092
6093 case OP_RNDQ_IMVNb:
6094 {
6095 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
6096 break;
6097 try_mvnimm:
6098 /* There's a possibility of getting a 64-bit immediate here, so
6099 we need special handling. */
6100 if (parse_big_immediate (&str, i) == FAIL)
6101 {
6102 inst.error = _("immediate value is out of range");
6103 goto failure;
6104 }
6105 }
6106 break;
6107
6108 case OP_RNDQ_I63b:
6109 {
6110 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
6111 break;
6112 try_shimm:
6113 po_imm_or_fail (0, 63, TRUE);
6114 }
6115 break;
c19d1205
ZW
6116
6117 case OP_RRnpcb:
6118 po_char_or_fail ('[');
6119 po_reg_or_fail (REG_TYPE_RN);
6120 po_char_or_fail (']');
6121 break;
a737bd4d 6122
c19d1205 6123 case OP_RRw:
b6702015 6124 case OP_oRRw:
c19d1205
ZW
6125 po_reg_or_fail (REG_TYPE_RN);
6126 if (skip_past_char (&str, '!') == SUCCESS)
6127 inst.operands[i].writeback = 1;
6128 break;
6129
6130 /* Immediates */
6131 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
6132 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
6133 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 6134 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
6135 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
6136 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 6137 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 6138 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
6139 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
6140 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
6141 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 6142 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
6143
6144 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
6145 case OP_oI7b:
6146 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
6147 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
6148 case OP_oI31b:
6149 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 6150 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
6151 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
6152
6153 /* Immediate variants */
6154 case OP_oI255c:
6155 po_char_or_fail ('{');
6156 po_imm_or_fail (0, 255, TRUE);
6157 po_char_or_fail ('}');
6158 break;
6159
6160 case OP_I31w:
6161 /* The expression parser chokes on a trailing !, so we have
6162 to find it first and zap it. */
6163 {
6164 char *s = str;
6165 while (*s && *s != ',')
6166 s++;
6167 if (s[-1] == '!')
6168 {
6169 s[-1] = '\0';
6170 inst.operands[i].writeback = 1;
6171 }
6172 po_imm_or_fail (0, 31, TRUE);
6173 if (str == s - 1)
6174 str = s;
6175 }
6176 break;
6177
6178 /* Expressions */
6179 case OP_EXPi: EXPi:
6180 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6181 GE_OPT_PREFIX));
6182 break;
6183
6184 case OP_EXP:
6185 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6186 GE_NO_PREFIX));
6187 break;
6188
6189 case OP_EXPr: EXPr:
6190 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
6191 GE_NO_PREFIX));
6192 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 6193 {
c19d1205
ZW
6194 val = parse_reloc (&str);
6195 if (val == -1)
6196 {
6197 inst.error = _("unrecognized relocation suffix");
6198 goto failure;
6199 }
6200 else if (val != BFD_RELOC_UNUSED)
6201 {
6202 inst.operands[i].imm = val;
6203 inst.operands[i].hasreloc = 1;
6204 }
a737bd4d 6205 }
c19d1205 6206 break;
a737bd4d 6207
b6895b4f
PB
6208 /* Operand for MOVW or MOVT. */
6209 case OP_HALF:
6210 po_misc_or_fail (parse_half (&str));
6211 break;
6212
e07e6e58 6213 /* Register or expression. */
c19d1205
ZW
6214 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
6215 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 6216
e07e6e58 6217 /* Register or immediate. */
c19d1205
ZW
6218 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
6219 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 6220
c19d1205
ZW
6221 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
6222 IF:
6223 if (!is_immediate_prefix (*str))
6224 goto bad_args;
6225 str++;
6226 val = parse_fpa_immediate (&str);
6227 if (val == FAIL)
6228 goto failure;
6229 /* FPA immediates are encoded as registers 8-15.
6230 parse_fpa_immediate has already applied the offset. */
6231 inst.operands[i].reg = val;
6232 inst.operands[i].isreg = 1;
6233 break;
09d92015 6234
2d447fca
JM
6235 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6236 I32z: po_imm_or_fail (0, 32, FALSE); break;
6237
e07e6e58 6238 /* Two kinds of register. */
c19d1205
ZW
6239 case OP_RIWR_RIWC:
6240 {
6241 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6242 if (!rege
6243 || (rege->type != REG_TYPE_MMXWR
6244 && rege->type != REG_TYPE_MMXWC
6245 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6246 {
6247 inst.error = _("iWMMXt data or control register expected");
6248 goto failure;
6249 }
6250 inst.operands[i].reg = rege->number;
6251 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6252 }
6253 break;
09d92015 6254
41adaa5c
JM
6255 case OP_RIWC_RIWG:
6256 {
6257 struct reg_entry *rege = arm_reg_parse_multi (&str);
6258 if (!rege
6259 || (rege->type != REG_TYPE_MMXWC
6260 && rege->type != REG_TYPE_MMXWCG))
6261 {
6262 inst.error = _("iWMMXt control register expected");
6263 goto failure;
6264 }
6265 inst.operands[i].reg = rege->number;
6266 inst.operands[i].isreg = 1;
6267 }
6268 break;
6269
c19d1205
ZW
6270 /* Misc */
6271 case OP_CPSF: val = parse_cps_flags (&str); break;
6272 case OP_ENDI: val = parse_endian_specifier (&str); break;
6273 case OP_oROR: val = parse_ror (&str); break;
6274 case OP_PSR: val = parse_psr (&str); break;
6275 case OP_COND: val = parse_cond (&str); break;
62b3e311 6276 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6277
037e8744
JB
6278 case OP_RVC_PSR:
6279 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6280 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6281 break;
6282 try_psr:
6283 val = parse_psr (&str);
6284 break;
6285
6286 case OP_APSR_RR:
6287 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6288 break;
6289 try_apsr:
6290 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6291 instruction). */
6292 if (strncasecmp (str, "APSR_", 5) == 0)
6293 {
6294 unsigned found = 0;
6295 str += 5;
6296 while (found < 15)
6297 switch (*str++)
6298 {
6299 case 'c': found = (found & 1) ? 16 : found | 1; break;
6300 case 'n': found = (found & 2) ? 16 : found | 2; break;
6301 case 'z': found = (found & 4) ? 16 : found | 4; break;
6302 case 'v': found = (found & 8) ? 16 : found | 8; break;
6303 default: found = 16;
6304 }
6305 if (found != 15)
6306 goto failure;
6307 inst.operands[i].isvec = 1;
f7c21dc7
NC
6308 /* APSR_nzcv is encoded in instructions as if it were the REG_PC. */
6309 inst.operands[i].reg = REG_PC;
037e8744
JB
6310 }
6311 else
6312 goto failure;
6313 break;
6314
92e90b6e
PB
6315 case OP_TB:
6316 po_misc_or_fail (parse_tb (&str));
6317 break;
6318
e07e6e58 6319 /* Register lists. */
c19d1205
ZW
6320 case OP_REGLST:
6321 val = parse_reg_list (&str);
6322 if (*str == '^')
6323 {
6324 inst.operands[1].writeback = 1;
6325 str++;
6326 }
6327 break;
09d92015 6328
c19d1205 6329 case OP_VRSLST:
5287ad62 6330 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6331 break;
09d92015 6332
c19d1205 6333 case OP_VRDLST:
5287ad62 6334 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6335 break;
a737bd4d 6336
037e8744
JB
6337 case OP_VRSDLST:
6338 /* Allow Q registers too. */
6339 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6340 REGLIST_NEON_D);
6341 if (val == FAIL)
6342 {
6343 inst.error = NULL;
6344 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6345 REGLIST_VFP_S);
6346 inst.operands[i].issingle = 1;
6347 }
6348 break;
6349
5287ad62
JB
6350 case OP_NRDLST:
6351 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6352 REGLIST_NEON_D);
6353 break;
6354
6355 case OP_NSTRLST:
dcbf9037
JB
6356 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6357 &inst.operands[i].vectype);
5287ad62
JB
6358 break;
6359
c19d1205
ZW
6360 /* Addressing modes */
6361 case OP_ADDR:
6362 po_misc_or_fail (parse_address (&str, i));
6363 break;
09d92015 6364
4962c51a
MS
6365 case OP_ADDRGLDR:
6366 po_misc_or_fail_no_backtrack (
6367 parse_address_group_reloc (&str, i, GROUP_LDR));
6368 break;
6369
6370 case OP_ADDRGLDRS:
6371 po_misc_or_fail_no_backtrack (
6372 parse_address_group_reloc (&str, i, GROUP_LDRS));
6373 break;
6374
6375 case OP_ADDRGLDC:
6376 po_misc_or_fail_no_backtrack (
6377 parse_address_group_reloc (&str, i, GROUP_LDC));
6378 break;
6379
c19d1205
ZW
6380 case OP_SH:
6381 po_misc_or_fail (parse_shifter_operand (&str, i));
6382 break;
09d92015 6383
4962c51a
MS
6384 case OP_SHG:
6385 po_misc_or_fail_no_backtrack (
6386 parse_shifter_operand_group_reloc (&str, i));
6387 break;
6388
c19d1205
ZW
6389 case OP_oSHll:
6390 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6391 break;
09d92015 6392
c19d1205
ZW
6393 case OP_oSHar:
6394 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6395 break;
09d92015 6396
c19d1205
ZW
6397 case OP_oSHllar:
6398 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6399 break;
09d92015 6400
c19d1205 6401 default:
bd3ba5d1 6402 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6403 }
09d92015 6404
c19d1205
ZW
6405 /* Various value-based sanity checks and shared operations. We
6406 do not signal immediate failures for the register constraints;
6407 this allows a syntax error to take precedence. */
6408 switch (upat[i])
6409 {
6410 case OP_oRRnpc:
6411 case OP_RRnpc:
6412 case OP_RRnpcb:
6413 case OP_RRw:
b6702015 6414 case OP_oRRw:
c19d1205
ZW
6415 case OP_RRnpc_I0:
6416 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6417 inst.error = BAD_PC;
6418 break;
09d92015 6419
c19d1205
ZW
6420 case OP_CPSF:
6421 case OP_ENDI:
6422 case OP_oROR:
6423 case OP_PSR:
037e8744 6424 case OP_RVC_PSR:
c19d1205 6425 case OP_COND:
62b3e311 6426 case OP_oBARRIER:
c19d1205
ZW
6427 case OP_REGLST:
6428 case OP_VRSLST:
6429 case OP_VRDLST:
037e8744 6430 case OP_VRSDLST:
5287ad62
JB
6431 case OP_NRDLST:
6432 case OP_NSTRLST:
c19d1205
ZW
6433 if (val == FAIL)
6434 goto failure;
6435 inst.operands[i].imm = val;
6436 break;
a737bd4d 6437
c19d1205
ZW
6438 default:
6439 break;
6440 }
09d92015 6441
c19d1205
ZW
6442 /* If we get here, this operand was successfully parsed. */
6443 inst.operands[i].present = 1;
6444 continue;
09d92015 6445
c19d1205 6446 bad_args:
09d92015 6447 inst.error = BAD_ARGS;
c19d1205
ZW
6448
6449 failure:
6450 if (!backtrack_pos)
d252fdde
PB
6451 {
6452 /* The parse routine should already have set inst.error, but set a
5f4273c7 6453 default here just in case. */
d252fdde
PB
6454 if (!inst.error)
6455 inst.error = _("syntax error");
6456 return FAIL;
6457 }
c19d1205
ZW
6458
6459 /* Do not backtrack over a trailing optional argument that
6460 absorbed some text. We will only fail again, with the
6461 'garbage following instruction' error message, which is
6462 probably less helpful than the current one. */
6463 if (backtrack_index == i && backtrack_pos != str
6464 && upat[i+1] == OP_stop)
d252fdde
PB
6465 {
6466 if (!inst.error)
6467 inst.error = _("syntax error");
6468 return FAIL;
6469 }
c19d1205
ZW
6470
6471 /* Try again, skipping the optional argument at backtrack_pos. */
6472 str = backtrack_pos;
6473 inst.error = backtrack_error;
6474 inst.operands[backtrack_index].present = 0;
6475 i = backtrack_index;
6476 backtrack_pos = 0;
09d92015 6477 }
09d92015 6478
c19d1205
ZW
6479 /* Check that we have parsed all the arguments. */
6480 if (*str != '\0' && !inst.error)
6481 inst.error = _("garbage following instruction");
09d92015 6482
c19d1205 6483 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6484}
6485
c19d1205
ZW
6486#undef po_char_or_fail
6487#undef po_reg_or_fail
6488#undef po_reg_or_goto
6489#undef po_imm_or_fail
5287ad62 6490#undef po_scalar_or_fail
e07e6e58 6491
c19d1205 6492/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6493#define constraint(expr, err) \
6494 do \
c19d1205 6495 { \
e07e6e58
NC
6496 if (expr) \
6497 { \
6498 inst.error = err; \
6499 return; \
6500 } \
c19d1205 6501 } \
e07e6e58 6502 while (0)
c19d1205 6503
fdfde340
JM
6504/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6505 instructions are unpredictable if these registers are used. This
6506 is the BadReg predicate in ARM's Thumb-2 documentation. */
6507#define reject_bad_reg(reg) \
6508 do \
6509 if (reg == REG_SP || reg == REG_PC) \
6510 { \
6511 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6512 return; \
6513 } \
6514 while (0)
6515
94206790
MM
6516/* If REG is R13 (the stack pointer), warn that its use is
6517 deprecated. */
6518#define warn_deprecated_sp(reg) \
6519 do \
6520 if (warn_on_deprecated && reg == REG_SP) \
6521 as_warn (_("use of r13 is deprecated")); \
6522 while (0)
6523
c19d1205
ZW
6524/* Functions for operand encoding. ARM, then Thumb. */
6525
6526#define rotate_left(v, n) (v << n | v >> (32 - n))
6527
6528/* If VAL can be encoded in the immediate field of an ARM instruction,
6529 return the encoded form. Otherwise, return FAIL. */
6530
6531static unsigned int
6532encode_arm_immediate (unsigned int val)
09d92015 6533{
c19d1205
ZW
6534 unsigned int a, i;
6535
6536 for (i = 0; i < 32; i += 2)
6537 if ((a = rotate_left (val, i)) <= 0xff)
6538 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6539
6540 return FAIL;
09d92015
MM
6541}
6542
c19d1205
ZW
6543/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6544 return the encoded form. Otherwise, return FAIL. */
6545static unsigned int
6546encode_thumb32_immediate (unsigned int val)
09d92015 6547{
c19d1205 6548 unsigned int a, i;
09d92015 6549
9c3c69f2 6550 if (val <= 0xff)
c19d1205 6551 return val;
a737bd4d 6552
9c3c69f2 6553 for (i = 1; i <= 24; i++)
09d92015 6554 {
9c3c69f2
PB
6555 a = val >> i;
6556 if ((val & ~(0xff << i)) == 0)
6557 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6558 }
a737bd4d 6559
c19d1205
ZW
6560 a = val & 0xff;
6561 if (val == ((a << 16) | a))
6562 return 0x100 | a;
6563 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6564 return 0x300 | a;
09d92015 6565
c19d1205
ZW
6566 a = val & 0xff00;
6567 if (val == ((a << 16) | a))
6568 return 0x200 | (a >> 8);
a737bd4d 6569
c19d1205 6570 return FAIL;
09d92015 6571}
5287ad62 6572/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6573
6574static void
5287ad62
JB
6575encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6576{
6577 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6578 && reg > 15)
6579 {
b1cc4aeb 6580 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6581 {
6582 if (thumb_mode)
6583 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6584 fpu_vfp_ext_d32);
5287ad62
JB
6585 else
6586 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6587 fpu_vfp_ext_d32);
5287ad62
JB
6588 }
6589 else
6590 {
dcbf9037 6591 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6592 return;
6593 }
6594 }
6595
c19d1205 6596 switch (pos)
09d92015 6597 {
c19d1205
ZW
6598 case VFP_REG_Sd:
6599 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6600 break;
6601
6602 case VFP_REG_Sn:
6603 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6604 break;
6605
6606 case VFP_REG_Sm:
6607 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6608 break;
6609
5287ad62
JB
6610 case VFP_REG_Dd:
6611 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6612 break;
5f4273c7 6613
5287ad62
JB
6614 case VFP_REG_Dn:
6615 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6616 break;
5f4273c7 6617
5287ad62
JB
6618 case VFP_REG_Dm:
6619 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6620 break;
6621
c19d1205
ZW
6622 default:
6623 abort ();
09d92015 6624 }
09d92015
MM
6625}
6626
c19d1205 6627/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6628 if any, is handled by md_apply_fix. */
09d92015 6629static void
c19d1205 6630encode_arm_shift (int i)
09d92015 6631{
c19d1205
ZW
6632 if (inst.operands[i].shift_kind == SHIFT_RRX)
6633 inst.instruction |= SHIFT_ROR << 5;
6634 else
09d92015 6635 {
c19d1205
ZW
6636 inst.instruction |= inst.operands[i].shift_kind << 5;
6637 if (inst.operands[i].immisreg)
6638 {
6639 inst.instruction |= SHIFT_BY_REG;
6640 inst.instruction |= inst.operands[i].imm << 8;
6641 }
6642 else
6643 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6644 }
c19d1205 6645}
09d92015 6646
c19d1205
ZW
6647static void
6648encode_arm_shifter_operand (int i)
6649{
6650 if (inst.operands[i].isreg)
09d92015 6651 {
c19d1205
ZW
6652 inst.instruction |= inst.operands[i].reg;
6653 encode_arm_shift (i);
09d92015 6654 }
c19d1205
ZW
6655 else
6656 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6657}
6658
c19d1205 6659/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6660static void
c19d1205 6661encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6662{
9c2799c2 6663 gas_assert (inst.operands[i].isreg);
c19d1205 6664 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6665
c19d1205 6666 if (inst.operands[i].preind)
09d92015 6667 {
c19d1205
ZW
6668 if (is_t)
6669 {
6670 inst.error = _("instruction does not accept preindexed addressing");
6671 return;
6672 }
6673 inst.instruction |= PRE_INDEX;
6674 if (inst.operands[i].writeback)
6675 inst.instruction |= WRITE_BACK;
09d92015 6676
c19d1205
ZW
6677 }
6678 else if (inst.operands[i].postind)
6679 {
9c2799c2 6680 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6681 if (is_t)
6682 inst.instruction |= WRITE_BACK;
6683 }
6684 else /* unindexed - only for coprocessor */
09d92015 6685 {
c19d1205 6686 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6687 return;
6688 }
6689
c19d1205
ZW
6690 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6691 && (((inst.instruction & 0x000f0000) >> 16)
6692 == ((inst.instruction & 0x0000f000) >> 12)))
6693 as_warn ((inst.instruction & LOAD_BIT)
6694 ? _("destination register same as write-back base")
6695 : _("source register same as write-back base"));
09d92015
MM
6696}
6697
c19d1205
ZW
6698/* inst.operands[i] was set up by parse_address. Encode it into an
6699 ARM-format mode 2 load or store instruction. If is_t is true,
6700 reject forms that cannot be used with a T instruction (i.e. not
6701 post-indexed). */
a737bd4d 6702static void
c19d1205 6703encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6704{
c19d1205 6705 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6706
c19d1205 6707 if (inst.operands[i].immisreg)
09d92015 6708 {
c19d1205
ZW
6709 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6710 inst.instruction |= inst.operands[i].imm;
6711 if (!inst.operands[i].negative)
6712 inst.instruction |= INDEX_UP;
6713 if (inst.operands[i].shifted)
6714 {
6715 if (inst.operands[i].shift_kind == SHIFT_RRX)
6716 inst.instruction |= SHIFT_ROR << 5;
6717 else
6718 {
6719 inst.instruction |= inst.operands[i].shift_kind << 5;
6720 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6721 }
6722 }
09d92015 6723 }
c19d1205 6724 else /* immediate offset in inst.reloc */
09d92015 6725 {
c19d1205
ZW
6726 if (inst.reloc.type == BFD_RELOC_UNUSED)
6727 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6728 }
09d92015
MM
6729}
6730
c19d1205
ZW
6731/* inst.operands[i] was set up by parse_address. Encode it into an
6732 ARM-format mode 3 load or store instruction. Reject forms that
6733 cannot be used with such instructions. If is_t is true, reject
6734 forms that cannot be used with a T instruction (i.e. not
6735 post-indexed). */
6736static void
6737encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6738{
c19d1205 6739 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6740 {
c19d1205
ZW
6741 inst.error = _("instruction does not accept scaled register index");
6742 return;
09d92015 6743 }
a737bd4d 6744
c19d1205 6745 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6746
c19d1205
ZW
6747 if (inst.operands[i].immisreg)
6748 {
6749 inst.instruction |= inst.operands[i].imm;
6750 if (!inst.operands[i].negative)
6751 inst.instruction |= INDEX_UP;
6752 }
6753 else /* immediate offset in inst.reloc */
6754 {
6755 inst.instruction |= HWOFFSET_IMM;
6756 if (inst.reloc.type == BFD_RELOC_UNUSED)
6757 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6758 }
a737bd4d
NC
6759}
6760
c19d1205
ZW
6761/* inst.operands[i] was set up by parse_address. Encode it into an
6762 ARM-format instruction. Reject all forms which cannot be encoded
6763 into a coprocessor load/store instruction. If wb_ok is false,
6764 reject use of writeback; if unind_ok is false, reject use of
6765 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6766 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6767 (in which case it is preserved). */
09d92015 6768
c19d1205
ZW
6769static int
6770encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6771{
c19d1205 6772 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6773
9c2799c2 6774 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6775
c19d1205 6776 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6777 {
9c2799c2 6778 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6779 if (!unind_ok)
6780 {
6781 inst.error = _("instruction does not support unindexed addressing");
6782 return FAIL;
6783 }
6784 inst.instruction |= inst.operands[i].imm;
6785 inst.instruction |= INDEX_UP;
6786 return SUCCESS;
09d92015 6787 }
a737bd4d 6788
c19d1205
ZW
6789 if (inst.operands[i].preind)
6790 inst.instruction |= PRE_INDEX;
a737bd4d 6791
c19d1205 6792 if (inst.operands[i].writeback)
09d92015 6793 {
c19d1205
ZW
6794 if (inst.operands[i].reg == REG_PC)
6795 {
6796 inst.error = _("pc may not be used with write-back");
6797 return FAIL;
6798 }
6799 if (!wb_ok)
6800 {
6801 inst.error = _("instruction does not support writeback");
6802 return FAIL;
6803 }
6804 inst.instruction |= WRITE_BACK;
09d92015 6805 }
a737bd4d 6806
c19d1205 6807 if (reloc_override)
21d799b5 6808 inst.reloc.type = (bfd_reloc_code_real_type) reloc_override;
4962c51a
MS
6809 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6810 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6811 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6812 {
6813 if (thumb_mode)
6814 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6815 else
6816 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6817 }
6818
c19d1205
ZW
6819 return SUCCESS;
6820}
a737bd4d 6821
c19d1205
ZW
6822/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6823 Determine whether it can be performed with a move instruction; if
6824 it can, convert inst.instruction to that move instruction and
c921be7d
NC
6825 return TRUE; if it can't, convert inst.instruction to a literal-pool
6826 load and return FALSE. If this is not a valid thing to do in the
6827 current context, set inst.error and return TRUE.
a737bd4d 6828
c19d1205
ZW
6829 inst.operands[i] describes the destination register. */
6830
c921be7d 6831static bfd_boolean
c19d1205
ZW
6832move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6833{
53365c0d
PB
6834 unsigned long tbit;
6835
6836 if (thumb_p)
6837 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6838 else
6839 tbit = LOAD_BIT;
6840
6841 if ((inst.instruction & tbit) == 0)
09d92015 6842 {
c19d1205 6843 inst.error = _("invalid pseudo operation");
c921be7d 6844 return TRUE;
09d92015 6845 }
c19d1205 6846 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6847 {
6848 inst.error = _("constant expression expected");
c921be7d 6849 return TRUE;
09d92015 6850 }
c19d1205 6851 if (inst.reloc.exp.X_op == O_constant)
09d92015 6852 {
c19d1205
ZW
6853 if (thumb_p)
6854 {
53365c0d 6855 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6856 {
6857 /* This can be done with a mov(1) instruction. */
6858 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6859 inst.instruction |= inst.reloc.exp.X_add_number;
c921be7d 6860 return TRUE;
c19d1205
ZW
6861 }
6862 }
6863 else
6864 {
6865 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6866 if (value != FAIL)
6867 {
6868 /* This can be done with a mov instruction. */
6869 inst.instruction &= LITERAL_MASK;
6870 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6871 inst.instruction |= value & 0xfff;
c921be7d 6872 return TRUE;
c19d1205 6873 }
09d92015 6874
c19d1205
ZW
6875 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6876 if (value != FAIL)
6877 {
6878 /* This can be done with a mvn instruction. */
6879 inst.instruction &= LITERAL_MASK;
6880 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6881 inst.instruction |= value & 0xfff;
c921be7d 6882 return TRUE;
c19d1205
ZW
6883 }
6884 }
09d92015
MM
6885 }
6886
c19d1205
ZW
6887 if (add_to_lit_pool () == FAIL)
6888 {
6889 inst.error = _("literal pool insertion failed");
c921be7d 6890 return TRUE;
c19d1205
ZW
6891 }
6892 inst.operands[1].reg = REG_PC;
6893 inst.operands[1].isreg = 1;
6894 inst.operands[1].preind = 1;
6895 inst.reloc.pc_rel = 1;
6896 inst.reloc.type = (thumb_p
6897 ? BFD_RELOC_ARM_THUMB_OFFSET
6898 : (mode_3
6899 ? BFD_RELOC_ARM_HWLITERAL
6900 : BFD_RELOC_ARM_LITERAL));
c921be7d 6901 return FALSE;
09d92015
MM
6902}
6903
5f4273c7 6904/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6905 First some generics; their names are taken from the conventional
6906 bit positions for register arguments in ARM format instructions. */
09d92015 6907
a737bd4d 6908static void
c19d1205 6909do_noargs (void)
09d92015 6910{
c19d1205 6911}
a737bd4d 6912
c19d1205
ZW
6913static void
6914do_rd (void)
6915{
6916 inst.instruction |= inst.operands[0].reg << 12;
6917}
a737bd4d 6918
c19d1205
ZW
6919static void
6920do_rd_rm (void)
6921{
6922 inst.instruction |= inst.operands[0].reg << 12;
6923 inst.instruction |= inst.operands[1].reg;
6924}
09d92015 6925
c19d1205
ZW
6926static void
6927do_rd_rn (void)
6928{
6929 inst.instruction |= inst.operands[0].reg << 12;
6930 inst.instruction |= inst.operands[1].reg << 16;
6931}
a737bd4d 6932
c19d1205
ZW
6933static void
6934do_rn_rd (void)
6935{
6936 inst.instruction |= inst.operands[0].reg << 16;
6937 inst.instruction |= inst.operands[1].reg << 12;
6938}
09d92015 6939
c19d1205
ZW
6940static void
6941do_rd_rm_rn (void)
6942{
9a64e435 6943 unsigned Rn = inst.operands[2].reg;
708587a4 6944 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6945 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6946 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6947 _("Rn must not overlap other operands"));
c19d1205
ZW
6948 inst.instruction |= inst.operands[0].reg << 12;
6949 inst.instruction |= inst.operands[1].reg;
9a64e435 6950 inst.instruction |= Rn << 16;
c19d1205 6951}
09d92015 6952
c19d1205
ZW
6953static void
6954do_rd_rn_rm (void)
6955{
6956 inst.instruction |= inst.operands[0].reg << 12;
6957 inst.instruction |= inst.operands[1].reg << 16;
6958 inst.instruction |= inst.operands[2].reg;
6959}
a737bd4d 6960
c19d1205
ZW
6961static void
6962do_rm_rd_rn (void)
6963{
6964 inst.instruction |= inst.operands[0].reg;
6965 inst.instruction |= inst.operands[1].reg << 12;
6966 inst.instruction |= inst.operands[2].reg << 16;
6967}
09d92015 6968
c19d1205
ZW
6969static void
6970do_imm0 (void)
6971{
6972 inst.instruction |= inst.operands[0].imm;
6973}
09d92015 6974
c19d1205
ZW
6975static void
6976do_rd_cpaddr (void)
6977{
6978 inst.instruction |= inst.operands[0].reg << 12;
6979 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6980}
a737bd4d 6981
c19d1205
ZW
6982/* ARM instructions, in alphabetical order by function name (except
6983 that wrapper functions appear immediately after the function they
6984 wrap). */
09d92015 6985
c19d1205
ZW
6986/* This is a pseudo-op of the form "adr rd, label" to be converted
6987 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6988
6989static void
c19d1205 6990do_adr (void)
09d92015 6991{
c19d1205 6992 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6993
c19d1205
ZW
6994 /* Frag hacking will turn this into a sub instruction if the offset turns
6995 out to be negative. */
6996 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6997 inst.reloc.pc_rel = 1;
2fc8bdac 6998 inst.reloc.exp.X_add_number -= 8;
c19d1205 6999}
b99bd4ef 7000
c19d1205
ZW
7001/* This is a pseudo-op of the form "adrl rd, label" to be converted
7002 into a relative address of the form:
7003 add rd, pc, #low(label-.-8)"
7004 add rd, rd, #high(label-.-8)" */
b99bd4ef 7005
c19d1205
ZW
7006static void
7007do_adrl (void)
7008{
7009 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 7010
c19d1205
ZW
7011 /* Frag hacking will turn this into a sub instruction if the offset turns
7012 out to be negative. */
7013 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
7014 inst.reloc.pc_rel = 1;
7015 inst.size = INSN_SIZE * 2;
2fc8bdac 7016 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
7017}
7018
b99bd4ef 7019static void
c19d1205 7020do_arit (void)
b99bd4ef 7021{
c19d1205
ZW
7022 if (!inst.operands[1].present)
7023 inst.operands[1].reg = inst.operands[0].reg;
7024 inst.instruction |= inst.operands[0].reg << 12;
7025 inst.instruction |= inst.operands[1].reg << 16;
7026 encode_arm_shifter_operand (2);
7027}
b99bd4ef 7028
62b3e311
PB
7029static void
7030do_barrier (void)
7031{
7032 if (inst.operands[0].present)
7033 {
7034 constraint ((inst.instruction & 0xf0) != 0x40
7035 && inst.operands[0].imm != 0xf,
bd3ba5d1 7036 _("bad barrier type"));
62b3e311
PB
7037 inst.instruction |= inst.operands[0].imm;
7038 }
7039 else
7040 inst.instruction |= 0xf;
7041}
7042
c19d1205
ZW
7043static void
7044do_bfc (void)
7045{
7046 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
7047 constraint (msb > 32, _("bit-field extends past end of register"));
7048 /* The instruction encoding stores the LSB and MSB,
7049 not the LSB and width. */
7050 inst.instruction |= inst.operands[0].reg << 12;
7051 inst.instruction |= inst.operands[1].imm << 7;
7052 inst.instruction |= (msb - 1) << 16;
7053}
b99bd4ef 7054
c19d1205
ZW
7055static void
7056do_bfi (void)
7057{
7058 unsigned int msb;
b99bd4ef 7059
c19d1205
ZW
7060 /* #0 in second position is alternative syntax for bfc, which is
7061 the same instruction but with REG_PC in the Rm field. */
7062 if (!inst.operands[1].isreg)
7063 inst.operands[1].reg = REG_PC;
b99bd4ef 7064
c19d1205
ZW
7065 msb = inst.operands[2].imm + inst.operands[3].imm;
7066 constraint (msb > 32, _("bit-field extends past end of register"));
7067 /* The instruction encoding stores the LSB and MSB,
7068 not the LSB and width. */
7069 inst.instruction |= inst.operands[0].reg << 12;
7070 inst.instruction |= inst.operands[1].reg;
7071 inst.instruction |= inst.operands[2].imm << 7;
7072 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
7073}
7074
b99bd4ef 7075static void
c19d1205 7076do_bfx (void)
b99bd4ef 7077{
c19d1205
ZW
7078 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
7079 _("bit-field extends past end of register"));
7080 inst.instruction |= inst.operands[0].reg << 12;
7081 inst.instruction |= inst.operands[1].reg;
7082 inst.instruction |= inst.operands[2].imm << 7;
7083 inst.instruction |= (inst.operands[3].imm - 1) << 16;
7084}
09d92015 7085
c19d1205
ZW
7086/* ARM V5 breakpoint instruction (argument parse)
7087 BKPT <16 bit unsigned immediate>
7088 Instruction is not conditional.
7089 The bit pattern given in insns[] has the COND_ALWAYS condition,
7090 and it is an error if the caller tried to override that. */
b99bd4ef 7091
c19d1205
ZW
7092static void
7093do_bkpt (void)
7094{
7095 /* Top 12 of 16 bits to bits 19:8. */
7096 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 7097
c19d1205
ZW
7098 /* Bottom 4 of 16 bits to bits 3:0. */
7099 inst.instruction |= inst.operands[0].imm & 0xf;
7100}
09d92015 7101
c19d1205
ZW
7102static void
7103encode_branch (int default_reloc)
7104{
7105 if (inst.operands[0].hasreloc)
7106 {
7107 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
7108 _("the only suffix valid here is '(plt)'"));
267bf995 7109 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 7110 }
b99bd4ef 7111 else
c19d1205 7112 {
21d799b5 7113 inst.reloc.type = (bfd_reloc_code_real_type) default_reloc;
c19d1205 7114 }
2fc8bdac 7115 inst.reloc.pc_rel = 1;
b99bd4ef
NC
7116}
7117
b99bd4ef 7118static void
c19d1205 7119do_branch (void)
b99bd4ef 7120{
39b41c9c
PB
7121#ifdef OBJ_ELF
7122 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7123 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7124 else
7125#endif
7126 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
7127}
7128
7129static void
7130do_bl (void)
7131{
7132#ifdef OBJ_ELF
7133 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
7134 {
7135 if (inst.cond == COND_ALWAYS)
7136 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
7137 else
7138 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
7139 }
7140 else
7141#endif
7142 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 7143}
b99bd4ef 7144
c19d1205
ZW
7145/* ARM V5 branch-link-exchange instruction (argument parse)
7146 BLX <target_addr> ie BLX(1)
7147 BLX{<condition>} <Rm> ie BLX(2)
7148 Unfortunately, there are two different opcodes for this mnemonic.
7149 So, the insns[].value is not used, and the code here zaps values
7150 into inst.instruction.
7151 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 7152
c19d1205
ZW
7153static void
7154do_blx (void)
7155{
7156 if (inst.operands[0].isreg)
b99bd4ef 7157 {
c19d1205
ZW
7158 /* Arg is a register; the opcode provided by insns[] is correct.
7159 It is not illegal to do "blx pc", just useless. */
7160 if (inst.operands[0].reg == REG_PC)
7161 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 7162
c19d1205
ZW
7163 inst.instruction |= inst.operands[0].reg;
7164 }
7165 else
b99bd4ef 7166 {
c19d1205 7167 /* Arg is an address; this instruction cannot be executed
267bf995
RR
7168 conditionally, and the opcode must be adjusted.
7169 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
7170 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 7171 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 7172 inst.instruction = 0xfa000000;
267bf995 7173 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 7174 }
c19d1205
ZW
7175}
7176
7177static void
7178do_bx (void)
7179{
845b51d6
PB
7180 bfd_boolean want_reloc;
7181
c19d1205
ZW
7182 if (inst.operands[0].reg == REG_PC)
7183 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 7184
c19d1205 7185 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
7186 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
7187 it is for ARMv4t or earlier. */
7188 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
7189 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
7190 want_reloc = TRUE;
7191
5ad34203 7192#ifdef OBJ_ELF
845b51d6 7193 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 7194#endif
584206db 7195 want_reloc = FALSE;
845b51d6
PB
7196
7197 if (want_reloc)
7198 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
7199}
7200
c19d1205
ZW
7201
7202/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
7203
7204static void
c19d1205 7205do_bxj (void)
a737bd4d 7206{
c19d1205
ZW
7207 if (inst.operands[0].reg == REG_PC)
7208 as_tsktsk (_("use of r15 in bxj is not really useful"));
7209
7210 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
7211}
7212
c19d1205
ZW
7213/* Co-processor data operation:
7214 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
7215 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
7216static void
7217do_cdp (void)
7218{
7219 inst.instruction |= inst.operands[0].reg << 8;
7220 inst.instruction |= inst.operands[1].imm << 20;
7221 inst.instruction |= inst.operands[2].reg << 12;
7222 inst.instruction |= inst.operands[3].reg << 16;
7223 inst.instruction |= inst.operands[4].reg;
7224 inst.instruction |= inst.operands[5].imm << 5;
7225}
a737bd4d
NC
7226
7227static void
c19d1205 7228do_cmp (void)
a737bd4d 7229{
c19d1205
ZW
7230 inst.instruction |= inst.operands[0].reg << 16;
7231 encode_arm_shifter_operand (1);
a737bd4d
NC
7232}
7233
c19d1205
ZW
7234/* Transfer between coprocessor and ARM registers.
7235 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
7236 MRC2
7237 MCR{cond}
7238 MCR2
7239
7240 No special properties. */
09d92015
MM
7241
7242static void
c19d1205 7243do_co_reg (void)
09d92015 7244{
fdfde340
JM
7245 unsigned Rd;
7246
7247 Rd = inst.operands[2].reg;
7248 if (thumb_mode)
7249 {
7250 if (inst.instruction == 0xee000010
7251 || inst.instruction == 0xfe000010)
7252 /* MCR, MCR2 */
7253 reject_bad_reg (Rd);
7254 else
7255 /* MRC, MRC2 */
7256 constraint (Rd == REG_SP, BAD_SP);
7257 }
7258 else
7259 {
7260 /* MCR */
7261 if (inst.instruction == 0xe000010)
7262 constraint (Rd == REG_PC, BAD_PC);
7263 }
7264
7265
c19d1205
ZW
7266 inst.instruction |= inst.operands[0].reg << 8;
7267 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7268 inst.instruction |= Rd << 12;
c19d1205
ZW
7269 inst.instruction |= inst.operands[3].reg << 16;
7270 inst.instruction |= inst.operands[4].reg;
7271 inst.instruction |= inst.operands[5].imm << 5;
7272}
09d92015 7273
c19d1205
ZW
7274/* Transfer between coprocessor register and pair of ARM registers.
7275 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7276 MCRR2
7277 MRRC{cond}
7278 MRRC2
b99bd4ef 7279
c19d1205 7280 Two XScale instructions are special cases of these:
09d92015 7281
c19d1205
ZW
7282 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7283 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7284
5f4273c7 7285 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7286
c19d1205
ZW
7287static void
7288do_co_reg2c (void)
7289{
fdfde340
JM
7290 unsigned Rd, Rn;
7291
7292 Rd = inst.operands[2].reg;
7293 Rn = inst.operands[3].reg;
7294
7295 if (thumb_mode)
7296 {
7297 reject_bad_reg (Rd);
7298 reject_bad_reg (Rn);
7299 }
7300 else
7301 {
7302 constraint (Rd == REG_PC, BAD_PC);
7303 constraint (Rn == REG_PC, BAD_PC);
7304 }
7305
c19d1205
ZW
7306 inst.instruction |= inst.operands[0].reg << 8;
7307 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7308 inst.instruction |= Rd << 12;
7309 inst.instruction |= Rn << 16;
c19d1205 7310 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7311}
7312
c19d1205
ZW
7313static void
7314do_cpsi (void)
7315{
7316 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7317 if (inst.operands[1].present)
7318 {
7319 inst.instruction |= CPSI_MMOD;
7320 inst.instruction |= inst.operands[1].imm;
7321 }
c19d1205 7322}
b99bd4ef 7323
62b3e311
PB
7324static void
7325do_dbg (void)
7326{
7327 inst.instruction |= inst.operands[0].imm;
7328}
7329
b99bd4ef 7330static void
c19d1205 7331do_it (void)
b99bd4ef 7332{
c19d1205 7333 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7334 process it to do the validation as if in
7335 thumb mode, just in case the code gets
7336 assembled for thumb using the unified syntax. */
7337
c19d1205 7338 inst.size = 0;
e07e6e58
NC
7339 if (unified_syntax)
7340 {
7341 set_it_insn_type (IT_INSN);
7342 now_it.mask = (inst.instruction & 0xf) | 0x10;
7343 now_it.cc = inst.operands[0].imm;
7344 }
09d92015 7345}
b99bd4ef 7346
09d92015 7347static void
c19d1205 7348do_ldmstm (void)
ea6ef066 7349{
c19d1205
ZW
7350 int base_reg = inst.operands[0].reg;
7351 int range = inst.operands[1].imm;
ea6ef066 7352
c19d1205
ZW
7353 inst.instruction |= base_reg << 16;
7354 inst.instruction |= range;
ea6ef066 7355
c19d1205
ZW
7356 if (inst.operands[1].writeback)
7357 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7358
c19d1205 7359 if (inst.operands[0].writeback)
ea6ef066 7360 {
c19d1205
ZW
7361 inst.instruction |= WRITE_BACK;
7362 /* Check for unpredictable uses of writeback. */
7363 if (inst.instruction & LOAD_BIT)
09d92015 7364 {
c19d1205
ZW
7365 /* Not allowed in LDM type 2. */
7366 if ((inst.instruction & LDM_TYPE_2_OR_3)
7367 && ((range & (1 << REG_PC)) == 0))
7368 as_warn (_("writeback of base register is UNPREDICTABLE"));
7369 /* Only allowed if base reg not in list for other types. */
7370 else if (range & (1 << base_reg))
7371 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7372 }
7373 else /* STM. */
7374 {
7375 /* Not allowed for type 2. */
7376 if (inst.instruction & LDM_TYPE_2_OR_3)
7377 as_warn (_("writeback of base register is UNPREDICTABLE"));
7378 /* Only allowed if base reg not in list, or first in list. */
7379 else if ((range & (1 << base_reg))
7380 && (range & ((1 << base_reg) - 1)))
7381 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7382 }
ea6ef066 7383 }
a737bd4d
NC
7384}
7385
c19d1205
ZW
7386/* ARMv5TE load-consecutive (argument parse)
7387 Mode is like LDRH.
7388
7389 LDRccD R, mode
7390 STRccD R, mode. */
7391
a737bd4d 7392static void
c19d1205 7393do_ldrd (void)
a737bd4d 7394{
c19d1205
ZW
7395 constraint (inst.operands[0].reg % 2 != 0,
7396 _("first destination register must be even"));
7397 constraint (inst.operands[1].present
7398 && inst.operands[1].reg != inst.operands[0].reg + 1,
7399 _("can only load two consecutive registers"));
7400 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7401 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7402
c19d1205
ZW
7403 if (!inst.operands[1].present)
7404 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7405
c19d1205 7406 if (inst.instruction & LOAD_BIT)
a737bd4d 7407 {
c19d1205
ZW
7408 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7409 register and the first register written; we have to diagnose
7410 overlap between the base and the second register written here. */
ea6ef066 7411
c19d1205
ZW
7412 if (inst.operands[2].reg == inst.operands[1].reg
7413 && (inst.operands[2].writeback || inst.operands[2].postind))
7414 as_warn (_("base register written back, and overlaps "
7415 "second destination register"));
b05fe5cf 7416
c19d1205
ZW
7417 /* For an index-register load, the index register must not overlap the
7418 destination (even if not write-back). */
7419 else if (inst.operands[2].immisreg
ca3f61f7
NC
7420 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7421 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7422 as_warn (_("index register overlaps destination register"));
b05fe5cf 7423 }
c19d1205
ZW
7424
7425 inst.instruction |= inst.operands[0].reg << 12;
7426 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7427}
7428
7429static void
c19d1205 7430do_ldrex (void)
b05fe5cf 7431{
c19d1205
ZW
7432 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7433 || inst.operands[1].postind || inst.operands[1].writeback
7434 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7435 || inst.operands[1].negative
7436 /* This can arise if the programmer has written
7437 strex rN, rM, foo
7438 or if they have mistakenly used a register name as the last
7439 operand, eg:
7440 strex rN, rM, rX
7441 It is very difficult to distinguish between these two cases
7442 because "rX" might actually be a label. ie the register
7443 name has been occluded by a symbol of the same name. So we
7444 just generate a general 'bad addressing mode' type error
7445 message and leave it up to the programmer to discover the
7446 true cause and fix their mistake. */
7447 || (inst.operands[1].reg == REG_PC),
7448 BAD_ADDR_MODE);
b05fe5cf 7449
c19d1205
ZW
7450 constraint (inst.reloc.exp.X_op != O_constant
7451 || inst.reloc.exp.X_add_number != 0,
7452 _("offset must be zero in ARM encoding"));
b05fe5cf 7453
c19d1205
ZW
7454 inst.instruction |= inst.operands[0].reg << 12;
7455 inst.instruction |= inst.operands[1].reg << 16;
7456 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7457}
7458
7459static void
c19d1205 7460do_ldrexd (void)
b05fe5cf 7461{
c19d1205
ZW
7462 constraint (inst.operands[0].reg % 2 != 0,
7463 _("even register required"));
7464 constraint (inst.operands[1].present
7465 && inst.operands[1].reg != inst.operands[0].reg + 1,
7466 _("can only load two consecutive registers"));
7467 /* If op 1 were present and equal to PC, this function wouldn't
7468 have been called in the first place. */
7469 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7470
c19d1205
ZW
7471 inst.instruction |= inst.operands[0].reg << 12;
7472 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7473}
7474
7475static void
c19d1205 7476do_ldst (void)
b05fe5cf 7477{
c19d1205
ZW
7478 inst.instruction |= inst.operands[0].reg << 12;
7479 if (!inst.operands[1].isreg)
7480 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7481 return;
c19d1205 7482 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7483}
7484
7485static void
c19d1205 7486do_ldstt (void)
b05fe5cf 7487{
c19d1205
ZW
7488 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7489 reject [Rn,...]. */
7490 if (inst.operands[1].preind)
b05fe5cf 7491 {
bd3ba5d1
NC
7492 constraint (inst.reloc.exp.X_op != O_constant
7493 || inst.reloc.exp.X_add_number != 0,
c19d1205 7494 _("this instruction requires a post-indexed address"));
b05fe5cf 7495
c19d1205
ZW
7496 inst.operands[1].preind = 0;
7497 inst.operands[1].postind = 1;
7498 inst.operands[1].writeback = 1;
b05fe5cf 7499 }
c19d1205
ZW
7500 inst.instruction |= inst.operands[0].reg << 12;
7501 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7502}
b05fe5cf 7503
c19d1205 7504/* Halfword and signed-byte load/store operations. */
b05fe5cf 7505
c19d1205
ZW
7506static void
7507do_ldstv4 (void)
7508{
7509 inst.instruction |= inst.operands[0].reg << 12;
7510 if (!inst.operands[1].isreg)
7511 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7512 return;
c19d1205 7513 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7514}
7515
7516static void
c19d1205 7517do_ldsttv4 (void)
b05fe5cf 7518{
c19d1205
ZW
7519 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7520 reject [Rn,...]. */
7521 if (inst.operands[1].preind)
b05fe5cf 7522 {
bd3ba5d1
NC
7523 constraint (inst.reloc.exp.X_op != O_constant
7524 || inst.reloc.exp.X_add_number != 0,
c19d1205 7525 _("this instruction requires a post-indexed address"));
b05fe5cf 7526
c19d1205
ZW
7527 inst.operands[1].preind = 0;
7528 inst.operands[1].postind = 1;
7529 inst.operands[1].writeback = 1;
b05fe5cf 7530 }
c19d1205
ZW
7531 inst.instruction |= inst.operands[0].reg << 12;
7532 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7533}
b05fe5cf 7534
c19d1205
ZW
7535/* Co-processor register load/store.
7536 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7537static void
7538do_lstc (void)
7539{
7540 inst.instruction |= inst.operands[0].reg << 8;
7541 inst.instruction |= inst.operands[1].reg << 12;
7542 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7543}
7544
b05fe5cf 7545static void
c19d1205 7546do_mlas (void)
b05fe5cf 7547{
8fb9d7b9 7548 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7549 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7550 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7551 && !(inst.instruction & 0x00400000))
8fb9d7b9 7552 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7553
c19d1205
ZW
7554 inst.instruction |= inst.operands[0].reg << 16;
7555 inst.instruction |= inst.operands[1].reg;
7556 inst.instruction |= inst.operands[2].reg << 8;
7557 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7558}
b05fe5cf 7559
c19d1205
ZW
7560static void
7561do_mov (void)
7562{
7563 inst.instruction |= inst.operands[0].reg << 12;
7564 encode_arm_shifter_operand (1);
7565}
b05fe5cf 7566
c19d1205
ZW
7567/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7568static void
7569do_mov16 (void)
7570{
b6895b4f
PB
7571 bfd_vma imm;
7572 bfd_boolean top;
7573
7574 top = (inst.instruction & 0x00400000) != 0;
7575 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7576 _(":lower16: not allowed this instruction"));
7577 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7578 _(":upper16: not allowed instruction"));
c19d1205 7579 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7580 if (inst.reloc.type == BFD_RELOC_UNUSED)
7581 {
7582 imm = inst.reloc.exp.X_add_number;
7583 /* The value is in two pieces: 0:11, 16:19. */
7584 inst.instruction |= (imm & 0x00000fff);
7585 inst.instruction |= (imm & 0x0000f000) << 4;
7586 }
b05fe5cf 7587}
b99bd4ef 7588
037e8744
JB
7589static void do_vfp_nsyn_opcode (const char *);
7590
7591static int
7592do_vfp_nsyn_mrs (void)
7593{
7594 if (inst.operands[0].isvec)
7595 {
7596 if (inst.operands[1].reg != 1)
7597 first_error (_("operand 1 must be FPSCR"));
7598 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7599 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7600 do_vfp_nsyn_opcode ("fmstat");
7601 }
7602 else if (inst.operands[1].isvec)
7603 do_vfp_nsyn_opcode ("fmrx");
7604 else
7605 return FAIL;
5f4273c7 7606
037e8744
JB
7607 return SUCCESS;
7608}
7609
7610static int
7611do_vfp_nsyn_msr (void)
7612{
7613 if (inst.operands[0].isvec)
7614 do_vfp_nsyn_opcode ("fmxr");
7615 else
7616 return FAIL;
7617
7618 return SUCCESS;
7619}
7620
f7c21dc7
NC
7621static void
7622do_vmrs (void)
7623{
7624 unsigned Rt = inst.operands[0].reg;
7625
7626 if (thumb_mode && inst.operands[0].reg == REG_SP)
7627 {
7628 inst.error = BAD_SP;
7629 return;
7630 }
7631
7632 /* APSR_ sets isvec. All other refs to PC are illegal. */
7633 if (!inst.operands[0].isvec && inst.operands[0].reg == REG_PC)
7634 {
7635 inst.error = BAD_PC;
7636 return;
7637 }
7638
7639 if (inst.operands[1].reg != 1)
7640 first_error (_("operand 1 must be FPSCR"));
7641
7642 inst.instruction |= (Rt << 12);
7643}
7644
7645static void
7646do_vmsr (void)
7647{
7648 unsigned Rt = inst.operands[1].reg;
7649
7650 if (thumb_mode)
7651 reject_bad_reg (Rt);
7652 else if (Rt == REG_PC)
7653 {
7654 inst.error = BAD_PC;
7655 return;
7656 }
7657
7658 if (inst.operands[0].reg != 1)
7659 first_error (_("operand 0 must be FPSCR"));
7660
7661 inst.instruction |= (Rt << 12);
7662}
7663
b99bd4ef 7664static void
c19d1205 7665do_mrs (void)
b99bd4ef 7666{
037e8744
JB
7667 if (do_vfp_nsyn_mrs () == SUCCESS)
7668 return;
7669
c19d1205
ZW
7670 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7671 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7672 != (PSR_c|PSR_f),
7673 _("'CPSR' or 'SPSR' expected"));
7674 inst.instruction |= inst.operands[0].reg << 12;
7675 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7676}
b99bd4ef 7677
c19d1205
ZW
7678/* Two possible forms:
7679 "{C|S}PSR_<field>, Rm",
7680 "{C|S}PSR_f, #expression". */
b99bd4ef 7681
c19d1205
ZW
7682static void
7683do_msr (void)
7684{
037e8744
JB
7685 if (do_vfp_nsyn_msr () == SUCCESS)
7686 return;
7687
c19d1205
ZW
7688 inst.instruction |= inst.operands[0].imm;
7689 if (inst.operands[1].isreg)
7690 inst.instruction |= inst.operands[1].reg;
7691 else
b99bd4ef 7692 {
c19d1205
ZW
7693 inst.instruction |= INST_IMMEDIATE;
7694 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7695 inst.reloc.pc_rel = 0;
b99bd4ef 7696 }
b99bd4ef
NC
7697}
7698
c19d1205
ZW
7699static void
7700do_mul (void)
a737bd4d 7701{
c19d1205
ZW
7702 if (!inst.operands[2].present)
7703 inst.operands[2].reg = inst.operands[0].reg;
7704 inst.instruction |= inst.operands[0].reg << 16;
7705 inst.instruction |= inst.operands[1].reg;
7706 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7707
8fb9d7b9
MS
7708 if (inst.operands[0].reg == inst.operands[1].reg
7709 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7710 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7711}
7712
c19d1205
ZW
7713/* Long Multiply Parser
7714 UMULL RdLo, RdHi, Rm, Rs
7715 SMULL RdLo, RdHi, Rm, Rs
7716 UMLAL RdLo, RdHi, Rm, Rs
7717 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7718
7719static void
c19d1205 7720do_mull (void)
b99bd4ef 7721{
c19d1205
ZW
7722 inst.instruction |= inst.operands[0].reg << 12;
7723 inst.instruction |= inst.operands[1].reg << 16;
7724 inst.instruction |= inst.operands[2].reg;
7725 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7726
682b27ad
PB
7727 /* rdhi and rdlo must be different. */
7728 if (inst.operands[0].reg == inst.operands[1].reg)
7729 as_tsktsk (_("rdhi and rdlo must be different"));
7730
7731 /* rdhi, rdlo and rm must all be different before armv6. */
7732 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7733 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7734 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7735 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7736}
b99bd4ef 7737
c19d1205
ZW
7738static void
7739do_nop (void)
7740{
e7495e45
NS
7741 if (inst.operands[0].present
7742 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7743 {
7744 /* Architectural NOP hints are CPSR sets with no bits selected. */
7745 inst.instruction &= 0xf0000000;
e7495e45
NS
7746 inst.instruction |= 0x0320f000;
7747 if (inst.operands[0].present)
7748 inst.instruction |= inst.operands[0].imm;
c19d1205 7749 }
b99bd4ef
NC
7750}
7751
c19d1205
ZW
7752/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7753 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7754 Condition defaults to COND_ALWAYS.
7755 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7756
7757static void
c19d1205 7758do_pkhbt (void)
b99bd4ef 7759{
c19d1205
ZW
7760 inst.instruction |= inst.operands[0].reg << 12;
7761 inst.instruction |= inst.operands[1].reg << 16;
7762 inst.instruction |= inst.operands[2].reg;
7763 if (inst.operands[3].present)
7764 encode_arm_shift (3);
7765}
b99bd4ef 7766
c19d1205 7767/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7768
c19d1205
ZW
7769static void
7770do_pkhtb (void)
7771{
7772 if (!inst.operands[3].present)
b99bd4ef 7773 {
c19d1205
ZW
7774 /* If the shift specifier is omitted, turn the instruction
7775 into pkhbt rd, rm, rn. */
7776 inst.instruction &= 0xfff00010;
7777 inst.instruction |= inst.operands[0].reg << 12;
7778 inst.instruction |= inst.operands[1].reg;
7779 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7780 }
7781 else
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 encode_arm_shift (3);
b99bd4ef
NC
7787 }
7788}
7789
c19d1205
ZW
7790/* ARMv5TE: Preload-Cache
7791
7792 PLD <addr_mode>
7793
7794 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7795
7796static void
c19d1205 7797do_pld (void)
b99bd4ef 7798{
c19d1205
ZW
7799 constraint (!inst.operands[0].isreg,
7800 _("'[' expected after PLD mnemonic"));
7801 constraint (inst.operands[0].postind,
7802 _("post-indexed expression used in preload instruction"));
7803 constraint (inst.operands[0].writeback,
7804 _("writeback used in preload instruction"));
7805 constraint (!inst.operands[0].preind,
7806 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7807 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7808}
b99bd4ef 7809
62b3e311
PB
7810/* ARMv7: PLI <addr_mode> */
7811static void
7812do_pli (void)
7813{
7814 constraint (!inst.operands[0].isreg,
7815 _("'[' expected after PLI mnemonic"));
7816 constraint (inst.operands[0].postind,
7817 _("post-indexed expression used in preload instruction"));
7818 constraint (inst.operands[0].writeback,
7819 _("writeback used in preload instruction"));
7820 constraint (!inst.operands[0].preind,
7821 _("unindexed addressing used in preload instruction"));
7822 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7823 inst.instruction &= ~PRE_INDEX;
7824}
7825
c19d1205
ZW
7826static void
7827do_push_pop (void)
7828{
7829 inst.operands[1] = inst.operands[0];
7830 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7831 inst.operands[0].isreg = 1;
7832 inst.operands[0].writeback = 1;
7833 inst.operands[0].reg = REG_SP;
7834 do_ldmstm ();
7835}
b99bd4ef 7836
c19d1205
ZW
7837/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7838 word at the specified address and the following word
7839 respectively.
7840 Unconditionally executed.
7841 Error if Rn is R15. */
b99bd4ef 7842
c19d1205
ZW
7843static void
7844do_rfe (void)
7845{
7846 inst.instruction |= inst.operands[0].reg << 16;
7847 if (inst.operands[0].writeback)
7848 inst.instruction |= WRITE_BACK;
7849}
b99bd4ef 7850
c19d1205 7851/* ARM V6 ssat (argument parse). */
b99bd4ef 7852
c19d1205
ZW
7853static void
7854do_ssat (void)
7855{
7856 inst.instruction |= inst.operands[0].reg << 12;
7857 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7858 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7859
c19d1205
ZW
7860 if (inst.operands[3].present)
7861 encode_arm_shift (3);
b99bd4ef
NC
7862}
7863
c19d1205 7864/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7865
7866static void
c19d1205 7867do_usat (void)
b99bd4ef 7868{
c19d1205
ZW
7869 inst.instruction |= inst.operands[0].reg << 12;
7870 inst.instruction |= inst.operands[1].imm << 16;
7871 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7872
c19d1205
ZW
7873 if (inst.operands[3].present)
7874 encode_arm_shift (3);
b99bd4ef
NC
7875}
7876
c19d1205 7877/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7878
7879static void
c19d1205 7880do_ssat16 (void)
09d92015 7881{
c19d1205
ZW
7882 inst.instruction |= inst.operands[0].reg << 12;
7883 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7884 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7885}
7886
c19d1205
ZW
7887static void
7888do_usat16 (void)
a737bd4d 7889{
c19d1205
ZW
7890 inst.instruction |= inst.operands[0].reg << 12;
7891 inst.instruction |= inst.operands[1].imm << 16;
7892 inst.instruction |= inst.operands[2].reg;
7893}
a737bd4d 7894
c19d1205
ZW
7895/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7896 preserving the other bits.
a737bd4d 7897
c19d1205
ZW
7898 setend <endian_specifier>, where <endian_specifier> is either
7899 BE or LE. */
a737bd4d 7900
c19d1205
ZW
7901static void
7902do_setend (void)
7903{
7904 if (inst.operands[0].imm)
7905 inst.instruction |= 0x200;
a737bd4d
NC
7906}
7907
7908static void
c19d1205 7909do_shift (void)
a737bd4d 7910{
c19d1205
ZW
7911 unsigned int Rm = (inst.operands[1].present
7912 ? inst.operands[1].reg
7913 : inst.operands[0].reg);
a737bd4d 7914
c19d1205
ZW
7915 inst.instruction |= inst.operands[0].reg << 12;
7916 inst.instruction |= Rm;
7917 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7918 {
c19d1205
ZW
7919 inst.instruction |= inst.operands[2].reg << 8;
7920 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7921 }
7922 else
c19d1205 7923 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7924}
7925
09d92015 7926static void
3eb17e6b 7927do_smc (void)
09d92015 7928{
3eb17e6b 7929 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7930 inst.reloc.pc_rel = 0;
09d92015
MM
7931}
7932
09d92015 7933static void
c19d1205 7934do_swi (void)
09d92015 7935{
c19d1205
ZW
7936 inst.reloc.type = BFD_RELOC_ARM_SWI;
7937 inst.reloc.pc_rel = 0;
09d92015
MM
7938}
7939
c19d1205
ZW
7940/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7941 SMLAxy{cond} Rd,Rm,Rs,Rn
7942 SMLAWy{cond} Rd,Rm,Rs,Rn
7943 Error if any register is R15. */
e16bb312 7944
c19d1205
ZW
7945static void
7946do_smla (void)
e16bb312 7947{
c19d1205
ZW
7948 inst.instruction |= inst.operands[0].reg << 16;
7949 inst.instruction |= inst.operands[1].reg;
7950 inst.instruction |= inst.operands[2].reg << 8;
7951 inst.instruction |= inst.operands[3].reg << 12;
7952}
a737bd4d 7953
c19d1205
ZW
7954/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7955 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7956 Error if any register is R15.
7957 Warning if Rdlo == Rdhi. */
a737bd4d 7958
c19d1205
ZW
7959static void
7960do_smlal (void)
7961{
7962 inst.instruction |= inst.operands[0].reg << 12;
7963 inst.instruction |= inst.operands[1].reg << 16;
7964 inst.instruction |= inst.operands[2].reg;
7965 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7966
c19d1205
ZW
7967 if (inst.operands[0].reg == inst.operands[1].reg)
7968 as_tsktsk (_("rdhi and rdlo must be different"));
7969}
a737bd4d 7970
c19d1205
ZW
7971/* ARM V5E (El Segundo) signed-multiply (argument parse)
7972 SMULxy{cond} Rd,Rm,Rs
7973 Error if any register is R15. */
a737bd4d 7974
c19d1205
ZW
7975static void
7976do_smul (void)
7977{
7978 inst.instruction |= inst.operands[0].reg << 16;
7979 inst.instruction |= inst.operands[1].reg;
7980 inst.instruction |= inst.operands[2].reg << 8;
7981}
a737bd4d 7982
b6702015
PB
7983/* ARM V6 srs (argument parse). The variable fields in the encoding are
7984 the same for both ARM and Thumb-2. */
a737bd4d 7985
c19d1205
ZW
7986static void
7987do_srs (void)
7988{
b6702015
PB
7989 int reg;
7990
7991 if (inst.operands[0].present)
7992 {
7993 reg = inst.operands[0].reg;
fdfde340 7994 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7995 }
7996 else
fdfde340 7997 reg = REG_SP;
b6702015
PB
7998
7999 inst.instruction |= reg << 16;
8000 inst.instruction |= inst.operands[1].imm;
8001 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
8002 inst.instruction |= WRITE_BACK;
8003}
a737bd4d 8004
c19d1205 8005/* ARM V6 strex (argument parse). */
a737bd4d 8006
c19d1205
ZW
8007static void
8008do_strex (void)
8009{
8010 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
8011 || inst.operands[2].postind || inst.operands[2].writeback
8012 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
8013 || inst.operands[2].negative
8014 /* See comment in do_ldrex(). */
8015 || (inst.operands[2].reg == REG_PC),
8016 BAD_ADDR_MODE);
a737bd4d 8017
c19d1205
ZW
8018 constraint (inst.operands[0].reg == inst.operands[1].reg
8019 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 8020
c19d1205
ZW
8021 constraint (inst.reloc.exp.X_op != O_constant
8022 || inst.reloc.exp.X_add_number != 0,
8023 _("offset must be zero in ARM encoding"));
a737bd4d 8024
c19d1205
ZW
8025 inst.instruction |= inst.operands[0].reg << 12;
8026 inst.instruction |= inst.operands[1].reg;
8027 inst.instruction |= inst.operands[2].reg << 16;
8028 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
8029}
8030
8031static void
c19d1205 8032do_strexd (void)
e16bb312 8033{
c19d1205
ZW
8034 constraint (inst.operands[1].reg % 2 != 0,
8035 _("even register required"));
8036 constraint (inst.operands[2].present
8037 && inst.operands[2].reg != inst.operands[1].reg + 1,
8038 _("can only store two consecutive registers"));
8039 /* If op 2 were present and equal to PC, this function wouldn't
8040 have been called in the first place. */
8041 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 8042
c19d1205
ZW
8043 constraint (inst.operands[0].reg == inst.operands[1].reg
8044 || inst.operands[0].reg == inst.operands[1].reg + 1
8045 || inst.operands[0].reg == inst.operands[3].reg,
8046 BAD_OVERLAP);
e16bb312 8047
c19d1205
ZW
8048 inst.instruction |= inst.operands[0].reg << 12;
8049 inst.instruction |= inst.operands[1].reg;
8050 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
8051}
8052
c19d1205
ZW
8053/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
8054 extends it to 32-bits, and adds the result to a value in another
8055 register. You can specify a rotation by 0, 8, 16, or 24 bits
8056 before extracting the 16-bit value.
8057 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
8058 Condition defaults to COND_ALWAYS.
8059 Error if any register uses R15. */
8060
e16bb312 8061static void
c19d1205 8062do_sxtah (void)
e16bb312 8063{
c19d1205
ZW
8064 inst.instruction |= inst.operands[0].reg << 12;
8065 inst.instruction |= inst.operands[1].reg << 16;
8066 inst.instruction |= inst.operands[2].reg;
8067 inst.instruction |= inst.operands[3].imm << 10;
8068}
e16bb312 8069
c19d1205 8070/* ARM V6 SXTH.
e16bb312 8071
c19d1205
ZW
8072 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
8073 Condition defaults to COND_ALWAYS.
8074 Error if any register uses R15. */
e16bb312
NC
8075
8076static void
c19d1205 8077do_sxth (void)
e16bb312 8078{
c19d1205
ZW
8079 inst.instruction |= inst.operands[0].reg << 12;
8080 inst.instruction |= inst.operands[1].reg;
8081 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 8082}
c19d1205
ZW
8083\f
8084/* VFP instructions. In a logical order: SP variant first, monad
8085 before dyad, arithmetic then move then load/store. */
e16bb312
NC
8086
8087static void
c19d1205 8088do_vfp_sp_monadic (void)
e16bb312 8089{
5287ad62
JB
8090 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8091 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8092}
8093
8094static void
c19d1205 8095do_vfp_sp_dyadic (void)
e16bb312 8096{
5287ad62
JB
8097 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8098 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
8099 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8100}
8101
8102static void
c19d1205 8103do_vfp_sp_compare_z (void)
e16bb312 8104{
5287ad62 8105 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
8106}
8107
8108static void
c19d1205 8109do_vfp_dp_sp_cvt (void)
e16bb312 8110{
5287ad62
JB
8111 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8112 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
8113}
8114
8115static void
c19d1205 8116do_vfp_sp_dp_cvt (void)
e16bb312 8117{
5287ad62
JB
8118 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8119 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
8120}
8121
8122static void
c19d1205 8123do_vfp_reg_from_sp (void)
e16bb312 8124{
c19d1205 8125 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 8126 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
8127}
8128
8129static void
c19d1205 8130do_vfp_reg2_from_sp2 (void)
e16bb312 8131{
c19d1205
ZW
8132 constraint (inst.operands[2].imm != 2,
8133 _("only two consecutive VFP SP registers allowed here"));
8134 inst.instruction |= inst.operands[0].reg << 12;
8135 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 8136 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
8137}
8138
8139static void
c19d1205 8140do_vfp_sp_from_reg (void)
e16bb312 8141{
5287ad62 8142 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 8143 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
8144}
8145
8146static void
c19d1205 8147do_vfp_sp2_from_reg2 (void)
e16bb312 8148{
c19d1205
ZW
8149 constraint (inst.operands[0].imm != 2,
8150 _("only two consecutive VFP SP registers allowed here"));
5287ad62 8151 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
8152 inst.instruction |= inst.operands[1].reg << 12;
8153 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
8154}
8155
8156static void
c19d1205 8157do_vfp_sp_ldst (void)
e16bb312 8158{
5287ad62 8159 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 8160 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8161}
8162
8163static void
c19d1205 8164do_vfp_dp_ldst (void)
e16bb312 8165{
5287ad62 8166 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 8167 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
8168}
8169
c19d1205 8170
e16bb312 8171static void
c19d1205 8172vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8173{
c19d1205
ZW
8174 if (inst.operands[0].writeback)
8175 inst.instruction |= WRITE_BACK;
8176 else
8177 constraint (ldstm_type != VFP_LDSTMIA,
8178 _("this addressing mode requires base-register writeback"));
8179 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8180 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 8181 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
8182}
8183
8184static void
c19d1205 8185vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 8186{
c19d1205 8187 int count;
e16bb312 8188
c19d1205
ZW
8189 if (inst.operands[0].writeback)
8190 inst.instruction |= WRITE_BACK;
8191 else
8192 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
8193 _("this addressing mode requires base-register writeback"));
e16bb312 8194
c19d1205 8195 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 8196 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 8197
c19d1205
ZW
8198 count = inst.operands[1].imm << 1;
8199 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
8200 count += 1;
e16bb312 8201
c19d1205 8202 inst.instruction |= count;
e16bb312
NC
8203}
8204
8205static void
c19d1205 8206do_vfp_sp_ldstmia (void)
e16bb312 8207{
c19d1205 8208 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8209}
8210
8211static void
c19d1205 8212do_vfp_sp_ldstmdb (void)
e16bb312 8213{
c19d1205 8214 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8215}
8216
8217static void
c19d1205 8218do_vfp_dp_ldstmia (void)
e16bb312 8219{
c19d1205 8220 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
8221}
8222
8223static void
c19d1205 8224do_vfp_dp_ldstmdb (void)
e16bb312 8225{
c19d1205 8226 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
8227}
8228
8229static void
c19d1205 8230do_vfp_xp_ldstmia (void)
e16bb312 8231{
c19d1205
ZW
8232 vfp_dp_ldstm (VFP_LDSTMIAX);
8233}
e16bb312 8234
c19d1205
ZW
8235static void
8236do_vfp_xp_ldstmdb (void)
8237{
8238 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 8239}
5287ad62
JB
8240
8241static void
8242do_vfp_dp_rd_rm (void)
8243{
8244 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8245 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
8246}
8247
8248static void
8249do_vfp_dp_rn_rd (void)
8250{
8251 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
8252 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8253}
8254
8255static void
8256do_vfp_dp_rd_rn (void)
8257{
8258 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8259 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8260}
8261
8262static void
8263do_vfp_dp_rd_rn_rm (void)
8264{
8265 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8266 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
8267 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
8268}
8269
8270static void
8271do_vfp_dp_rd (void)
8272{
8273 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8274}
8275
8276static void
8277do_vfp_dp_rm_rd_rn (void)
8278{
8279 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
8280 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8281 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8282}
8283
8284/* VFPv3 instructions. */
8285static void
8286do_vfp_sp_const (void)
8287{
8288 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8289 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8290 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8291}
8292
8293static void
8294do_vfp_dp_const (void)
8295{
8296 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8297 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8298 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8299}
8300
8301static void
8302vfp_conv (int srcsize)
8303{
8304 unsigned immbits = srcsize - inst.operands[1].imm;
8305 inst.instruction |= (immbits & 1) << 5;
8306 inst.instruction |= (immbits >> 1);
8307}
8308
8309static void
8310do_vfp_sp_conv_16 (void)
8311{
8312 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8313 vfp_conv (16);
8314}
8315
8316static void
8317do_vfp_dp_conv_16 (void)
8318{
8319 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8320 vfp_conv (16);
8321}
8322
8323static void
8324do_vfp_sp_conv_32 (void)
8325{
8326 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8327 vfp_conv (32);
8328}
8329
8330static void
8331do_vfp_dp_conv_32 (void)
8332{
8333 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8334 vfp_conv (32);
8335}
c19d1205
ZW
8336\f
8337/* FPA instructions. Also in a logical order. */
e16bb312 8338
c19d1205
ZW
8339static void
8340do_fpa_cmp (void)
8341{
8342 inst.instruction |= inst.operands[0].reg << 16;
8343 inst.instruction |= inst.operands[1].reg;
8344}
b99bd4ef
NC
8345
8346static void
c19d1205 8347do_fpa_ldmstm (void)
b99bd4ef 8348{
c19d1205
ZW
8349 inst.instruction |= inst.operands[0].reg << 12;
8350 switch (inst.operands[1].imm)
8351 {
8352 case 1: inst.instruction |= CP_T_X; break;
8353 case 2: inst.instruction |= CP_T_Y; break;
8354 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8355 case 4: break;
8356 default: abort ();
8357 }
b99bd4ef 8358
c19d1205
ZW
8359 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8360 {
8361 /* The instruction specified "ea" or "fd", so we can only accept
8362 [Rn]{!}. The instruction does not really support stacking or
8363 unstacking, so we have to emulate these by setting appropriate
8364 bits and offsets. */
8365 constraint (inst.reloc.exp.X_op != O_constant
8366 || inst.reloc.exp.X_add_number != 0,
8367 _("this instruction does not support indexing"));
b99bd4ef 8368
c19d1205
ZW
8369 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8370 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8371
c19d1205
ZW
8372 if (!(inst.instruction & INDEX_UP))
8373 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8374
c19d1205
ZW
8375 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8376 {
8377 inst.operands[2].preind = 0;
8378 inst.operands[2].postind = 1;
8379 }
8380 }
b99bd4ef 8381
c19d1205 8382 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8383}
c19d1205
ZW
8384\f
8385/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8386
c19d1205
ZW
8387static void
8388do_iwmmxt_tandorc (void)
8389{
8390 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8391}
b99bd4ef 8392
c19d1205
ZW
8393static void
8394do_iwmmxt_textrc (void)
8395{
8396 inst.instruction |= inst.operands[0].reg << 12;
8397 inst.instruction |= inst.operands[1].imm;
8398}
b99bd4ef
NC
8399
8400static void
c19d1205 8401do_iwmmxt_textrm (void)
b99bd4ef 8402{
c19d1205
ZW
8403 inst.instruction |= inst.operands[0].reg << 12;
8404 inst.instruction |= inst.operands[1].reg << 16;
8405 inst.instruction |= inst.operands[2].imm;
8406}
b99bd4ef 8407
c19d1205
ZW
8408static void
8409do_iwmmxt_tinsr (void)
8410{
8411 inst.instruction |= inst.operands[0].reg << 16;
8412 inst.instruction |= inst.operands[1].reg << 12;
8413 inst.instruction |= inst.operands[2].imm;
8414}
b99bd4ef 8415
c19d1205
ZW
8416static void
8417do_iwmmxt_tmia (void)
8418{
8419 inst.instruction |= inst.operands[0].reg << 5;
8420 inst.instruction |= inst.operands[1].reg;
8421 inst.instruction |= inst.operands[2].reg << 12;
8422}
b99bd4ef 8423
c19d1205
ZW
8424static void
8425do_iwmmxt_waligni (void)
8426{
8427 inst.instruction |= inst.operands[0].reg << 12;
8428 inst.instruction |= inst.operands[1].reg << 16;
8429 inst.instruction |= inst.operands[2].reg;
8430 inst.instruction |= inst.operands[3].imm << 20;
8431}
b99bd4ef 8432
2d447fca
JM
8433static void
8434do_iwmmxt_wmerge (void)
8435{
8436 inst.instruction |= inst.operands[0].reg << 12;
8437 inst.instruction |= inst.operands[1].reg << 16;
8438 inst.instruction |= inst.operands[2].reg;
8439 inst.instruction |= inst.operands[3].imm << 21;
8440}
8441
c19d1205
ZW
8442static void
8443do_iwmmxt_wmov (void)
8444{
8445 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8446 inst.instruction |= inst.operands[0].reg << 12;
8447 inst.instruction |= inst.operands[1].reg << 16;
8448 inst.instruction |= inst.operands[1].reg;
8449}
b99bd4ef 8450
c19d1205
ZW
8451static void
8452do_iwmmxt_wldstbh (void)
8453{
8f06b2d8 8454 int reloc;
c19d1205 8455 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8456 if (thumb_mode)
8457 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8458 else
8459 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8460 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8461}
8462
c19d1205
ZW
8463static void
8464do_iwmmxt_wldstw (void)
8465{
8466 /* RIWR_RIWC clears .isreg for a control register. */
8467 if (!inst.operands[0].isreg)
8468 {
8469 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8470 inst.instruction |= 0xf0000000;
8471 }
b99bd4ef 8472
c19d1205
ZW
8473 inst.instruction |= inst.operands[0].reg << 12;
8474 encode_arm_cp_address (1, TRUE, TRUE, 0);
8475}
b99bd4ef
NC
8476
8477static void
c19d1205 8478do_iwmmxt_wldstd (void)
b99bd4ef 8479{
c19d1205 8480 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8481 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8482 && inst.operands[1].immisreg)
8483 {
8484 inst.instruction &= ~0x1a000ff;
8485 inst.instruction |= (0xf << 28);
8486 if (inst.operands[1].preind)
8487 inst.instruction |= PRE_INDEX;
8488 if (!inst.operands[1].negative)
8489 inst.instruction |= INDEX_UP;
8490 if (inst.operands[1].writeback)
8491 inst.instruction |= WRITE_BACK;
8492 inst.instruction |= inst.operands[1].reg << 16;
8493 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8494 inst.instruction |= inst.operands[1].imm;
8495 }
8496 else
8497 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8498}
b99bd4ef 8499
c19d1205
ZW
8500static void
8501do_iwmmxt_wshufh (void)
8502{
8503 inst.instruction |= inst.operands[0].reg << 12;
8504 inst.instruction |= inst.operands[1].reg << 16;
8505 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8506 inst.instruction |= (inst.operands[2].imm & 0x0f);
8507}
b99bd4ef 8508
c19d1205
ZW
8509static void
8510do_iwmmxt_wzero (void)
8511{
8512 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8513 inst.instruction |= inst.operands[0].reg;
8514 inst.instruction |= inst.operands[0].reg << 12;
8515 inst.instruction |= inst.operands[0].reg << 16;
8516}
2d447fca
JM
8517
8518static void
8519do_iwmmxt_wrwrwr_or_imm5 (void)
8520{
8521 if (inst.operands[2].isreg)
8522 do_rd_rn_rm ();
8523 else {
8524 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8525 _("immediate operand requires iWMMXt2"));
8526 do_rd_rn ();
8527 if (inst.operands[2].imm == 0)
8528 {
8529 switch ((inst.instruction >> 20) & 0xf)
8530 {
8531 case 4:
8532 case 5:
8533 case 6:
5f4273c7 8534 case 7:
2d447fca
JM
8535 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8536 inst.operands[2].imm = 16;
8537 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8538 break;
8539 case 8:
8540 case 9:
8541 case 10:
8542 case 11:
8543 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8544 inst.operands[2].imm = 32;
8545 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8546 break;
8547 case 12:
8548 case 13:
8549 case 14:
8550 case 15:
8551 {
8552 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8553 unsigned long wrn;
8554 wrn = (inst.instruction >> 16) & 0xf;
8555 inst.instruction &= 0xff0fff0f;
8556 inst.instruction |= wrn;
8557 /* Bail out here; the instruction is now assembled. */
8558 return;
8559 }
8560 }
8561 }
8562 /* Map 32 -> 0, etc. */
8563 inst.operands[2].imm &= 0x1f;
8564 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8565 }
8566}
c19d1205
ZW
8567\f
8568/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8569 operations first, then control, shift, and load/store. */
b99bd4ef 8570
c19d1205 8571/* Insns like "foo X,Y,Z". */
b99bd4ef 8572
c19d1205
ZW
8573static void
8574do_mav_triple (void)
8575{
8576 inst.instruction |= inst.operands[0].reg << 16;
8577 inst.instruction |= inst.operands[1].reg;
8578 inst.instruction |= inst.operands[2].reg << 12;
8579}
b99bd4ef 8580
c19d1205
ZW
8581/* Insns like "foo W,X,Y,Z".
8582 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8583
c19d1205
ZW
8584static void
8585do_mav_quad (void)
8586{
8587 inst.instruction |= inst.operands[0].reg << 5;
8588 inst.instruction |= inst.operands[1].reg << 12;
8589 inst.instruction |= inst.operands[2].reg << 16;
8590 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8591}
8592
c19d1205
ZW
8593/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8594static void
8595do_mav_dspsc (void)
a737bd4d 8596{
c19d1205
ZW
8597 inst.instruction |= inst.operands[1].reg << 12;
8598}
a737bd4d 8599
c19d1205
ZW
8600/* Maverick shift immediate instructions.
8601 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8602 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8603
c19d1205
ZW
8604static void
8605do_mav_shift (void)
8606{
8607 int imm = inst.operands[2].imm;
a737bd4d 8608
c19d1205
ZW
8609 inst.instruction |= inst.operands[0].reg << 12;
8610 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8611
c19d1205
ZW
8612 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8613 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8614 Bit 4 should be 0. */
8615 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8616
c19d1205
ZW
8617 inst.instruction |= imm;
8618}
8619\f
8620/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8621
c19d1205
ZW
8622/* Xscale multiply-accumulate (argument parse)
8623 MIAcc acc0,Rm,Rs
8624 MIAPHcc acc0,Rm,Rs
8625 MIAxycc acc0,Rm,Rs. */
a737bd4d 8626
c19d1205
ZW
8627static void
8628do_xsc_mia (void)
8629{
8630 inst.instruction |= inst.operands[1].reg;
8631 inst.instruction |= inst.operands[2].reg << 12;
8632}
a737bd4d 8633
c19d1205 8634/* Xscale move-accumulator-register (argument parse)
a737bd4d 8635
c19d1205 8636 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8637
c19d1205
ZW
8638static void
8639do_xsc_mar (void)
8640{
8641 inst.instruction |= inst.operands[1].reg << 12;
8642 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8643}
8644
c19d1205 8645/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8646
c19d1205 8647 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8648
8649static void
c19d1205 8650do_xsc_mra (void)
b99bd4ef 8651{
c19d1205
ZW
8652 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8653 inst.instruction |= inst.operands[0].reg << 12;
8654 inst.instruction |= inst.operands[1].reg << 16;
8655}
8656\f
8657/* Encoding functions relevant only to Thumb. */
b99bd4ef 8658
c19d1205
ZW
8659/* inst.operands[i] is a shifted-register operand; encode
8660 it into inst.instruction in the format used by Thumb32. */
8661
8662static void
8663encode_thumb32_shifted_operand (int i)
8664{
8665 unsigned int value = inst.reloc.exp.X_add_number;
8666 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8667
9c3c69f2
PB
8668 constraint (inst.operands[i].immisreg,
8669 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8670 inst.instruction |= inst.operands[i].reg;
8671 if (shift == SHIFT_RRX)
8672 inst.instruction |= SHIFT_ROR << 4;
8673 else
b99bd4ef 8674 {
c19d1205
ZW
8675 constraint (inst.reloc.exp.X_op != O_constant,
8676 _("expression too complex"));
8677
8678 constraint (value > 32
8679 || (value == 32 && (shift == SHIFT_LSL
8680 || shift == SHIFT_ROR)),
8681 _("shift expression is too large"));
8682
8683 if (value == 0)
8684 shift = SHIFT_LSL;
8685 else if (value == 32)
8686 value = 0;
8687
8688 inst.instruction |= shift << 4;
8689 inst.instruction |= (value & 0x1c) << 10;
8690 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8691 }
c19d1205 8692}
b99bd4ef 8693
b99bd4ef 8694
c19d1205
ZW
8695/* inst.operands[i] was set up by parse_address. Encode it into a
8696 Thumb32 format load or store instruction. Reject forms that cannot
8697 be used with such instructions. If is_t is true, reject forms that
8698 cannot be used with a T instruction; if is_d is true, reject forms
8699 that cannot be used with a D instruction. */
b99bd4ef 8700
c19d1205
ZW
8701static void
8702encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8703{
8704 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8705
8706 constraint (!inst.operands[i].isreg,
53365c0d 8707 _("Instruction does not support =N addresses"));
b99bd4ef 8708
c19d1205
ZW
8709 inst.instruction |= inst.operands[i].reg << 16;
8710 if (inst.operands[i].immisreg)
b99bd4ef 8711 {
c19d1205
ZW
8712 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8713 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8714 constraint (inst.operands[i].negative,
8715 _("Thumb does not support negative register indexing"));
8716 constraint (inst.operands[i].postind,
8717 _("Thumb does not support register post-indexing"));
8718 constraint (inst.operands[i].writeback,
8719 _("Thumb does not support register indexing with writeback"));
8720 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8721 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8722
f40d1643 8723 inst.instruction |= inst.operands[i].imm;
c19d1205 8724 if (inst.operands[i].shifted)
b99bd4ef 8725 {
c19d1205
ZW
8726 constraint (inst.reloc.exp.X_op != O_constant,
8727 _("expression too complex"));
9c3c69f2
PB
8728 constraint (inst.reloc.exp.X_add_number < 0
8729 || inst.reloc.exp.X_add_number > 3,
c19d1205 8730 _("shift out of range"));
9c3c69f2 8731 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8732 }
8733 inst.reloc.type = BFD_RELOC_UNUSED;
8734 }
8735 else if (inst.operands[i].preind)
8736 {
8737 constraint (is_pc && inst.operands[i].writeback,
8738 _("cannot use writeback with PC-relative addressing"));
f40d1643 8739 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8740 _("cannot use writeback with this instruction"));
8741
8742 if (is_d)
8743 {
8744 inst.instruction |= 0x01000000;
8745 if (inst.operands[i].writeback)
8746 inst.instruction |= 0x00200000;
b99bd4ef 8747 }
c19d1205 8748 else
b99bd4ef 8749 {
c19d1205
ZW
8750 inst.instruction |= 0x00000c00;
8751 if (inst.operands[i].writeback)
8752 inst.instruction |= 0x00000100;
b99bd4ef 8753 }
c19d1205 8754 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8755 }
c19d1205 8756 else if (inst.operands[i].postind)
b99bd4ef 8757 {
9c2799c2 8758 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8759 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8760 constraint (is_t, _("cannot use post-indexing with this instruction"));
8761
8762 if (is_d)
8763 inst.instruction |= 0x00200000;
8764 else
8765 inst.instruction |= 0x00000900;
8766 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8767 }
8768 else /* unindexed - only for coprocessor */
8769 inst.error = _("instruction does not accept unindexed addressing");
8770}
8771
8772/* Table of Thumb instructions which exist in both 16- and 32-bit
8773 encodings (the latter only in post-V6T2 cores). The index is the
8774 value used in the insns table below. When there is more than one
8775 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8776 holds variant (1).
8777 Also contains several pseudo-instructions used during relaxation. */
c19d1205 8778#define T16_32_TAB \
21d799b5
NC
8779 X(_adc, 4140, eb400000), \
8780 X(_adcs, 4140, eb500000), \
8781 X(_add, 1c00, eb000000), \
8782 X(_adds, 1c00, eb100000), \
8783 X(_addi, 0000, f1000000), \
8784 X(_addis, 0000, f1100000), \
8785 X(_add_pc,000f, f20f0000), \
8786 X(_add_sp,000d, f10d0000), \
8787 X(_adr, 000f, f20f0000), \
8788 X(_and, 4000, ea000000), \
8789 X(_ands, 4000, ea100000), \
8790 X(_asr, 1000, fa40f000), \
8791 X(_asrs, 1000, fa50f000), \
8792 X(_b, e000, f000b000), \
8793 X(_bcond, d000, f0008000), \
8794 X(_bic, 4380, ea200000), \
8795 X(_bics, 4380, ea300000), \
8796 X(_cmn, 42c0, eb100f00), \
8797 X(_cmp, 2800, ebb00f00), \
8798 X(_cpsie, b660, f3af8400), \
8799 X(_cpsid, b670, f3af8600), \
8800 X(_cpy, 4600, ea4f0000), \
8801 X(_dec_sp,80dd, f1ad0d00), \
8802 X(_eor, 4040, ea800000), \
8803 X(_eors, 4040, ea900000), \
8804 X(_inc_sp,00dd, f10d0d00), \
8805 X(_ldmia, c800, e8900000), \
8806 X(_ldr, 6800, f8500000), \
8807 X(_ldrb, 7800, f8100000), \
8808 X(_ldrh, 8800, f8300000), \
8809 X(_ldrsb, 5600, f9100000), \
8810 X(_ldrsh, 5e00, f9300000), \
8811 X(_ldr_pc,4800, f85f0000), \
8812 X(_ldr_pc2,4800, f85f0000), \
8813 X(_ldr_sp,9800, f85d0000), \
8814 X(_lsl, 0000, fa00f000), \
8815 X(_lsls, 0000, fa10f000), \
8816 X(_lsr, 0800, fa20f000), \
8817 X(_lsrs, 0800, fa30f000), \
8818 X(_mov, 2000, ea4f0000), \
8819 X(_movs, 2000, ea5f0000), \
8820 X(_mul, 4340, fb00f000), \
8821 X(_muls, 4340, ffffffff), /* no 32b muls */ \
8822 X(_mvn, 43c0, ea6f0000), \
8823 X(_mvns, 43c0, ea7f0000), \
8824 X(_neg, 4240, f1c00000), /* rsb #0 */ \
8825 X(_negs, 4240, f1d00000), /* rsbs #0 */ \
8826 X(_orr, 4300, ea400000), \
8827 X(_orrs, 4300, ea500000), \
8828 X(_pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8829 X(_push, b400, e92d0000), /* stmdb sp!,... */ \
8830 X(_rev, ba00, fa90f080), \
8831 X(_rev16, ba40, fa90f090), \
8832 X(_revsh, bac0, fa90f0b0), \
8833 X(_ror, 41c0, fa60f000), \
8834 X(_rors, 41c0, fa70f000), \
8835 X(_sbc, 4180, eb600000), \
8836 X(_sbcs, 4180, eb700000), \
8837 X(_stmia, c000, e8800000), \
8838 X(_str, 6000, f8400000), \
8839 X(_strb, 7000, f8000000), \
8840 X(_strh, 8000, f8200000), \
8841 X(_str_sp,9000, f84d0000), \
8842 X(_sub, 1e00, eba00000), \
8843 X(_subs, 1e00, ebb00000), \
8844 X(_subi, 8000, f1a00000), \
8845 X(_subis, 8000, f1b00000), \
8846 X(_sxtb, b240, fa4ff080), \
8847 X(_sxth, b200, fa0ff080), \
8848 X(_tst, 4200, ea100f00), \
8849 X(_uxtb, b2c0, fa5ff080), \
8850 X(_uxth, b280, fa1ff080), \
8851 X(_nop, bf00, f3af8000), \
8852 X(_yield, bf10, f3af8001), \
8853 X(_wfe, bf20, f3af8002), \
8854 X(_wfi, bf30, f3af8003), \
8855 X(_sev, bf40, f3af8004),
c19d1205
ZW
8856
8857/* To catch errors in encoding functions, the codes are all offset by
8858 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8859 as 16-bit instructions. */
21d799b5 8860#define X(a,b,c) T_MNEM##a
c19d1205
ZW
8861enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8862#undef X
8863
8864#define X(a,b,c) 0x##b
8865static const unsigned short thumb_op16[] = { T16_32_TAB };
8866#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8867#undef X
8868
8869#define X(a,b,c) 0x##c
8870static const unsigned int thumb_op32[] = { T16_32_TAB };
c921be7d
NC
8871#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8872#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
c19d1205
ZW
8873#undef X
8874#undef T16_32_TAB
8875
8876/* Thumb instruction encoders, in alphabetical order. */
8877
92e90b6e 8878/* ADDW or SUBW. */
c921be7d 8879
92e90b6e
PB
8880static void
8881do_t_add_sub_w (void)
8882{
8883 int Rd, Rn;
8884
8885 Rd = inst.operands[0].reg;
8886 Rn = inst.operands[1].reg;
8887
539d4391
NC
8888 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this
8889 is the SP-{plus,minus}-immediate form of the instruction. */
8890 if (Rn == REG_SP)
8891 constraint (Rd == REG_PC, BAD_PC);
8892 else
8893 reject_bad_reg (Rd);
fdfde340 8894
92e90b6e
PB
8895 inst.instruction |= (Rn << 16) | (Rd << 8);
8896 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8897}
8898
c19d1205
ZW
8899/* Parse an add or subtract instruction. We get here with inst.instruction
8900 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8901
8902static void
8903do_t_add_sub (void)
8904{
8905 int Rd, Rs, Rn;
8906
8907 Rd = inst.operands[0].reg;
8908 Rs = (inst.operands[1].present
8909 ? inst.operands[1].reg /* Rd, Rs, foo */
8910 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8911
e07e6e58
NC
8912 if (Rd == REG_PC)
8913 set_it_insn_type_last ();
8914
c19d1205
ZW
8915 if (unified_syntax)
8916 {
0110f2b8
PB
8917 bfd_boolean flags;
8918 bfd_boolean narrow;
8919 int opcode;
8920
8921 flags = (inst.instruction == T_MNEM_adds
8922 || inst.instruction == T_MNEM_subs);
8923 if (flags)
e07e6e58 8924 narrow = !in_it_block ();
0110f2b8 8925 else
e07e6e58 8926 narrow = in_it_block ();
c19d1205 8927 if (!inst.operands[2].isreg)
b99bd4ef 8928 {
16805f35
PB
8929 int add;
8930
fdfde340
JM
8931 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8932
16805f35
PB
8933 add = (inst.instruction == T_MNEM_add
8934 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8935 opcode = 0;
8936 if (inst.size_req != 4)
8937 {
0110f2b8
PB
8938 /* Attempt to use a narrow opcode, with relaxation if
8939 appropriate. */
8940 if (Rd == REG_SP && Rs == REG_SP && !flags)
8941 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8942 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8943 opcode = T_MNEM_add_sp;
8944 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8945 opcode = T_MNEM_add_pc;
8946 else if (Rd <= 7 && Rs <= 7 && narrow)
8947 {
8948 if (flags)
8949 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8950 else
8951 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8952 }
8953 if (opcode)
8954 {
8955 inst.instruction = THUMB_OP16(opcode);
8956 inst.instruction |= (Rd << 4) | Rs;
8957 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8958 if (inst.size_req != 2)
8959 inst.relax = opcode;
8960 }
8961 else
8962 constraint (inst.size_req == 2, BAD_HIREG);
8963 }
8964 if (inst.size_req == 4
8965 || (inst.size_req != 2 && !opcode))
8966 {
efd81785
PB
8967 if (Rd == REG_PC)
8968 {
fdfde340 8969 constraint (add, BAD_PC);
efd81785
PB
8970 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8971 _("only SUBS PC, LR, #const allowed"));
8972 constraint (inst.reloc.exp.X_op != O_constant,
8973 _("expression too complex"));
8974 constraint (inst.reloc.exp.X_add_number < 0
8975 || inst.reloc.exp.X_add_number > 0xff,
8976 _("immediate value out of range"));
8977 inst.instruction = T2_SUBS_PC_LR
8978 | inst.reloc.exp.X_add_number;
8979 inst.reloc.type = BFD_RELOC_UNUSED;
8980 return;
8981 }
8982 else if (Rs == REG_PC)
16805f35
PB
8983 {
8984 /* Always use addw/subw. */
8985 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8986 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8987 }
8988 else
8989 {
8990 inst.instruction = THUMB_OP32 (inst.instruction);
8991 inst.instruction = (inst.instruction & 0xe1ffffff)
8992 | 0x10000000;
8993 if (flags)
8994 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8995 else
8996 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8997 }
dc4503c6
PB
8998 inst.instruction |= Rd << 8;
8999 inst.instruction |= Rs << 16;
0110f2b8 9000 }
b99bd4ef 9001 }
c19d1205
ZW
9002 else
9003 {
9004 Rn = inst.operands[2].reg;
9005 /* See if we can do this with a 16-bit instruction. */
9006 if (!inst.operands[2].shifted && inst.size_req != 4)
9007 {
e27ec89e
PB
9008 if (Rd > 7 || Rs > 7 || Rn > 7)
9009 narrow = FALSE;
9010
9011 if (narrow)
c19d1205 9012 {
e27ec89e
PB
9013 inst.instruction = ((inst.instruction == T_MNEM_adds
9014 || inst.instruction == T_MNEM_add)
c19d1205
ZW
9015 ? T_OPCODE_ADD_R3
9016 : T_OPCODE_SUB_R3);
9017 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
9018 return;
9019 }
b99bd4ef 9020
7e806470 9021 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 9022 {
7e806470
PB
9023 /* Thumb-1 cores (except v6-M) require at least one high
9024 register in a narrow non flag setting add. */
9025 if (Rd > 7 || Rn > 7
9026 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
9027 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 9028 {
7e806470
PB
9029 if (Rd == Rn)
9030 {
9031 Rn = Rs;
9032 Rs = Rd;
9033 }
c19d1205
ZW
9034 inst.instruction = T_OPCODE_ADD_HI;
9035 inst.instruction |= (Rd & 8) << 4;
9036 inst.instruction |= (Rd & 7);
9037 inst.instruction |= Rn << 3;
9038 return;
9039 }
c19d1205
ZW
9040 }
9041 }
c921be7d 9042
fdfde340
JM
9043 constraint (Rd == REG_PC, BAD_PC);
9044 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
9045 constraint (Rs == REG_PC, BAD_PC);
9046 reject_bad_reg (Rn);
9047
c19d1205
ZW
9048 /* If we get here, it can't be done in 16 bits. */
9049 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
9050 _("shift must be constant"));
9051 inst.instruction = THUMB_OP32 (inst.instruction);
9052 inst.instruction |= Rd << 8;
9053 inst.instruction |= Rs << 16;
9054 encode_thumb32_shifted_operand (2);
9055 }
9056 }
9057 else
9058 {
9059 constraint (inst.instruction == T_MNEM_adds
9060 || inst.instruction == T_MNEM_subs,
9061 BAD_THUMB32);
b99bd4ef 9062
c19d1205 9063 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 9064 {
c19d1205
ZW
9065 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
9066 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
9067 BAD_HIREG);
9068
9069 inst.instruction = (inst.instruction == T_MNEM_add
9070 ? 0x0000 : 0x8000);
9071 inst.instruction |= (Rd << 4) | Rs;
9072 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
9073 return;
9074 }
9075
c19d1205
ZW
9076 Rn = inst.operands[2].reg;
9077 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 9078
c19d1205
ZW
9079 /* We now have Rd, Rs, and Rn set to registers. */
9080 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 9081 {
c19d1205
ZW
9082 /* Can't do this for SUB. */
9083 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
9084 inst.instruction = T_OPCODE_ADD_HI;
9085 inst.instruction |= (Rd & 8) << 4;
9086 inst.instruction |= (Rd & 7);
9087 if (Rs == Rd)
9088 inst.instruction |= Rn << 3;
9089 else if (Rn == Rd)
9090 inst.instruction |= Rs << 3;
9091 else
9092 constraint (1, _("dest must overlap one source register"));
9093 }
9094 else
9095 {
9096 inst.instruction = (inst.instruction == T_MNEM_add
9097 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
9098 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 9099 }
b99bd4ef 9100 }
b99bd4ef
NC
9101}
9102
c19d1205
ZW
9103static void
9104do_t_adr (void)
9105{
fdfde340
JM
9106 unsigned Rd;
9107
9108 Rd = inst.operands[0].reg;
9109 reject_bad_reg (Rd);
9110
9111 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
9112 {
9113 /* Defer to section relaxation. */
9114 inst.relax = inst.instruction;
9115 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 9116 inst.instruction |= Rd << 4;
0110f2b8
PB
9117 }
9118 else if (unified_syntax && inst.size_req != 2)
e9f89963 9119 {
0110f2b8 9120 /* Generate a 32-bit opcode. */
e9f89963 9121 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 9122 inst.instruction |= Rd << 8;
e9f89963
PB
9123 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
9124 inst.reloc.pc_rel = 1;
9125 }
9126 else
9127 {
0110f2b8 9128 /* Generate a 16-bit opcode. */
e9f89963
PB
9129 inst.instruction = THUMB_OP16 (inst.instruction);
9130 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
9131 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
9132 inst.reloc.pc_rel = 1;
b99bd4ef 9133
fdfde340 9134 inst.instruction |= Rd << 4;
e9f89963 9135 }
c19d1205 9136}
b99bd4ef 9137
c19d1205
ZW
9138/* Arithmetic instructions for which there is just one 16-bit
9139 instruction encoding, and it allows only two low registers.
9140 For maximal compatibility with ARM syntax, we allow three register
9141 operands even when Thumb-32 instructions are not available, as long
9142 as the first two are identical. For instance, both "sbc r0,r1" and
9143 "sbc r0,r0,r1" are allowed. */
b99bd4ef 9144static void
c19d1205 9145do_t_arit3 (void)
b99bd4ef 9146{
c19d1205 9147 int Rd, Rs, Rn;
b99bd4ef 9148
c19d1205
ZW
9149 Rd = inst.operands[0].reg;
9150 Rs = (inst.operands[1].present
9151 ? inst.operands[1].reg /* Rd, Rs, foo */
9152 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9153 Rn = inst.operands[2].reg;
b99bd4ef 9154
fdfde340
JM
9155 reject_bad_reg (Rd);
9156 reject_bad_reg (Rs);
9157 if (inst.operands[2].isreg)
9158 reject_bad_reg (Rn);
9159
c19d1205 9160 if (unified_syntax)
b99bd4ef 9161 {
c19d1205
ZW
9162 if (!inst.operands[2].isreg)
9163 {
9164 /* For an immediate, we always generate a 32-bit opcode;
9165 section relaxation will shrink it later if possible. */
9166 inst.instruction = THUMB_OP32 (inst.instruction);
9167 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9168 inst.instruction |= Rd << 8;
9169 inst.instruction |= Rs << 16;
9170 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9171 }
9172 else
9173 {
e27ec89e
PB
9174 bfd_boolean narrow;
9175
c19d1205 9176 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9177 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9178 narrow = !in_it_block ();
e27ec89e 9179 else
e07e6e58 9180 narrow = in_it_block ();
e27ec89e
PB
9181
9182 if (Rd > 7 || Rn > 7 || Rs > 7)
9183 narrow = FALSE;
9184 if (inst.operands[2].shifted)
9185 narrow = FALSE;
9186 if (inst.size_req == 4)
9187 narrow = FALSE;
9188
9189 if (narrow
c19d1205
ZW
9190 && Rd == Rs)
9191 {
9192 inst.instruction = THUMB_OP16 (inst.instruction);
9193 inst.instruction |= Rd;
9194 inst.instruction |= Rn << 3;
9195 return;
9196 }
b99bd4ef 9197
c19d1205
ZW
9198 /* If we get here, it can't be done in 16 bits. */
9199 constraint (inst.operands[2].shifted
9200 && inst.operands[2].immisreg,
9201 _("shift must be constant"));
9202 inst.instruction = THUMB_OP32 (inst.instruction);
9203 inst.instruction |= Rd << 8;
9204 inst.instruction |= Rs << 16;
9205 encode_thumb32_shifted_operand (2);
9206 }
a737bd4d 9207 }
c19d1205 9208 else
b99bd4ef 9209 {
c19d1205
ZW
9210 /* On its face this is a lie - the instruction does set the
9211 flags. However, the only supported mnemonic in this mode
9212 says it doesn't. */
9213 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9214
c19d1205
ZW
9215 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9216 _("unshifted register required"));
9217 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9218 constraint (Rd != Rs,
9219 _("dest and source1 must be the same register"));
a737bd4d 9220
c19d1205
ZW
9221 inst.instruction = THUMB_OP16 (inst.instruction);
9222 inst.instruction |= Rd;
9223 inst.instruction |= Rn << 3;
b99bd4ef 9224 }
a737bd4d 9225}
b99bd4ef 9226
c19d1205
ZW
9227/* Similarly, but for instructions where the arithmetic operation is
9228 commutative, so we can allow either of them to be different from
9229 the destination operand in a 16-bit instruction. For instance, all
9230 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
9231 accepted. */
9232static void
9233do_t_arit3c (void)
a737bd4d 9234{
c19d1205 9235 int Rd, Rs, Rn;
b99bd4ef 9236
c19d1205
ZW
9237 Rd = inst.operands[0].reg;
9238 Rs = (inst.operands[1].present
9239 ? inst.operands[1].reg /* Rd, Rs, foo */
9240 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
9241 Rn = inst.operands[2].reg;
c921be7d 9242
fdfde340
JM
9243 reject_bad_reg (Rd);
9244 reject_bad_reg (Rs);
9245 if (inst.operands[2].isreg)
9246 reject_bad_reg (Rn);
a737bd4d 9247
c19d1205 9248 if (unified_syntax)
a737bd4d 9249 {
c19d1205 9250 if (!inst.operands[2].isreg)
b99bd4ef 9251 {
c19d1205
ZW
9252 /* For an immediate, we always generate a 32-bit opcode;
9253 section relaxation will shrink it later if possible. */
9254 inst.instruction = THUMB_OP32 (inst.instruction);
9255 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9256 inst.instruction |= Rd << 8;
9257 inst.instruction |= Rs << 16;
9258 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 9259 }
c19d1205 9260 else
a737bd4d 9261 {
e27ec89e
PB
9262 bfd_boolean narrow;
9263
c19d1205 9264 /* See if we can do this with a 16-bit instruction. */
e27ec89e 9265 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 9266 narrow = !in_it_block ();
e27ec89e 9267 else
e07e6e58 9268 narrow = in_it_block ();
e27ec89e
PB
9269
9270 if (Rd > 7 || Rn > 7 || Rs > 7)
9271 narrow = FALSE;
9272 if (inst.operands[2].shifted)
9273 narrow = FALSE;
9274 if (inst.size_req == 4)
9275 narrow = FALSE;
9276
9277 if (narrow)
a737bd4d 9278 {
c19d1205 9279 if (Rd == Rs)
a737bd4d 9280 {
c19d1205
ZW
9281 inst.instruction = THUMB_OP16 (inst.instruction);
9282 inst.instruction |= Rd;
9283 inst.instruction |= Rn << 3;
9284 return;
a737bd4d 9285 }
c19d1205 9286 if (Rd == Rn)
a737bd4d 9287 {
c19d1205
ZW
9288 inst.instruction = THUMB_OP16 (inst.instruction);
9289 inst.instruction |= Rd;
9290 inst.instruction |= Rs << 3;
9291 return;
a737bd4d
NC
9292 }
9293 }
c19d1205
ZW
9294
9295 /* If we get here, it can't be done in 16 bits. */
9296 constraint (inst.operands[2].shifted
9297 && inst.operands[2].immisreg,
9298 _("shift must be constant"));
9299 inst.instruction = THUMB_OP32 (inst.instruction);
9300 inst.instruction |= Rd << 8;
9301 inst.instruction |= Rs << 16;
9302 encode_thumb32_shifted_operand (2);
a737bd4d 9303 }
b99bd4ef 9304 }
c19d1205
ZW
9305 else
9306 {
9307 /* On its face this is a lie - the instruction does set the
9308 flags. However, the only supported mnemonic in this mode
9309 says it doesn't. */
9310 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9311
c19d1205
ZW
9312 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9313 _("unshifted register required"));
9314 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9315
9316 inst.instruction = THUMB_OP16 (inst.instruction);
9317 inst.instruction |= Rd;
9318
9319 if (Rd == Rs)
9320 inst.instruction |= Rn << 3;
9321 else if (Rd == Rn)
9322 inst.instruction |= Rs << 3;
9323 else
9324 constraint (1, _("dest must overlap one source register"));
9325 }
a737bd4d
NC
9326}
9327
62b3e311
PB
9328static void
9329do_t_barrier (void)
9330{
9331 if (inst.operands[0].present)
9332 {
9333 constraint ((inst.instruction & 0xf0) != 0x40
9334 && inst.operands[0].imm != 0xf,
bd3ba5d1 9335 _("bad barrier type"));
62b3e311
PB
9336 inst.instruction |= inst.operands[0].imm;
9337 }
9338 else
9339 inst.instruction |= 0xf;
9340}
9341
c19d1205
ZW
9342static void
9343do_t_bfc (void)
a737bd4d 9344{
fdfde340 9345 unsigned Rd;
c19d1205
ZW
9346 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9347 constraint (msb > 32, _("bit-field extends past end of register"));
9348 /* The instruction encoding stores the LSB and MSB,
9349 not the LSB and width. */
fdfde340
JM
9350 Rd = inst.operands[0].reg;
9351 reject_bad_reg (Rd);
9352 inst.instruction |= Rd << 8;
c19d1205
ZW
9353 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9354 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9355 inst.instruction |= msb - 1;
b99bd4ef
NC
9356}
9357
c19d1205
ZW
9358static void
9359do_t_bfi (void)
b99bd4ef 9360{
fdfde340 9361 int Rd, Rn;
c19d1205 9362 unsigned int msb;
b99bd4ef 9363
fdfde340
JM
9364 Rd = inst.operands[0].reg;
9365 reject_bad_reg (Rd);
9366
c19d1205
ZW
9367 /* #0 in second position is alternative syntax for bfc, which is
9368 the same instruction but with REG_PC in the Rm field. */
9369 if (!inst.operands[1].isreg)
fdfde340
JM
9370 Rn = REG_PC;
9371 else
9372 {
9373 Rn = inst.operands[1].reg;
9374 reject_bad_reg (Rn);
9375 }
b99bd4ef 9376
c19d1205
ZW
9377 msb = inst.operands[2].imm + inst.operands[3].imm;
9378 constraint (msb > 32, _("bit-field extends past end of register"));
9379 /* The instruction encoding stores the LSB and MSB,
9380 not the LSB and width. */
fdfde340
JM
9381 inst.instruction |= Rd << 8;
9382 inst.instruction |= Rn << 16;
c19d1205
ZW
9383 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9384 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9385 inst.instruction |= msb - 1;
b99bd4ef
NC
9386}
9387
c19d1205
ZW
9388static void
9389do_t_bfx (void)
b99bd4ef 9390{
fdfde340
JM
9391 unsigned Rd, Rn;
9392
9393 Rd = inst.operands[0].reg;
9394 Rn = inst.operands[1].reg;
9395
9396 reject_bad_reg (Rd);
9397 reject_bad_reg (Rn);
9398
c19d1205
ZW
9399 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9400 _("bit-field extends past end of register"));
fdfde340
JM
9401 inst.instruction |= Rd << 8;
9402 inst.instruction |= Rn << 16;
c19d1205
ZW
9403 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9404 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9405 inst.instruction |= inst.operands[3].imm - 1;
9406}
b99bd4ef 9407
c19d1205
ZW
9408/* ARM V5 Thumb BLX (argument parse)
9409 BLX <target_addr> which is BLX(1)
9410 BLX <Rm> which is BLX(2)
9411 Unfortunately, there are two different opcodes for this mnemonic.
9412 So, the insns[].value is not used, and the code here zaps values
9413 into inst.instruction.
b99bd4ef 9414
c19d1205
ZW
9415 ??? How to take advantage of the additional two bits of displacement
9416 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9417
c19d1205
ZW
9418static void
9419do_t_blx (void)
9420{
e07e6e58
NC
9421 set_it_insn_type_last ();
9422
c19d1205 9423 if (inst.operands[0].isreg)
fdfde340
JM
9424 {
9425 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9426 /* We have a register, so this is BLX(2). */
9427 inst.instruction |= inst.operands[0].reg << 3;
9428 }
b99bd4ef
NC
9429 else
9430 {
c19d1205 9431 /* No register. This must be BLX(1). */
2fc8bdac 9432 inst.instruction = 0xf000e800;
00adf2d4 9433 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9434 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9435 }
9436}
9437
c19d1205
ZW
9438static void
9439do_t_branch (void)
b99bd4ef 9440{
0110f2b8 9441 int opcode;
dfa9f0d5
PB
9442 int cond;
9443
e07e6e58
NC
9444 cond = inst.cond;
9445 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9446
9447 if (in_it_block ())
dfa9f0d5
PB
9448 {
9449 /* Conditional branches inside IT blocks are encoded as unconditional
9450 branches. */
9451 cond = COND_ALWAYS;
dfa9f0d5
PB
9452 }
9453 else
9454 cond = inst.cond;
9455
9456 if (cond != COND_ALWAYS)
0110f2b8
PB
9457 opcode = T_MNEM_bcond;
9458 else
9459 opcode = inst.instruction;
9460
9461 if (unified_syntax && inst.size_req == 4)
c19d1205 9462 {
0110f2b8 9463 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9464 if (cond == COND_ALWAYS)
0110f2b8 9465 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9466 else
9467 {
9c2799c2 9468 gas_assert (cond != 0xF);
dfa9f0d5 9469 inst.instruction |= cond << 22;
c19d1205
ZW
9470 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9471 }
9472 }
b99bd4ef
NC
9473 else
9474 {
0110f2b8 9475 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9476 if (cond == COND_ALWAYS)
c19d1205
ZW
9477 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9478 else
b99bd4ef 9479 {
dfa9f0d5 9480 inst.instruction |= cond << 8;
c19d1205 9481 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9482 }
0110f2b8
PB
9483 /* Allow section relaxation. */
9484 if (unified_syntax && inst.size_req != 2)
9485 inst.relax = opcode;
b99bd4ef 9486 }
c19d1205
ZW
9487
9488 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9489}
9490
9491static void
c19d1205 9492do_t_bkpt (void)
b99bd4ef 9493{
dfa9f0d5
PB
9494 constraint (inst.cond != COND_ALWAYS,
9495 _("instruction is always unconditional"));
c19d1205 9496 if (inst.operands[0].present)
b99bd4ef 9497 {
c19d1205
ZW
9498 constraint (inst.operands[0].imm > 255,
9499 _("immediate value out of range"));
9500 inst.instruction |= inst.operands[0].imm;
e07e6e58 9501 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9502 }
b99bd4ef
NC
9503}
9504
9505static void
c19d1205 9506do_t_branch23 (void)
b99bd4ef 9507{
e07e6e58 9508 set_it_insn_type_last ();
c19d1205 9509 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9510 inst.reloc.pc_rel = 1;
9511
4343666d 9512#if defined(OBJ_COFF)
c19d1205
ZW
9513 /* If the destination of the branch is a defined symbol which does not have
9514 the THUMB_FUNC attribute, then we must be calling a function which has
9515 the (interfacearm) attribute. We look for the Thumb entry point to that
9516 function and change the branch to refer to that function instead. */
9517 if ( inst.reloc.exp.X_op == O_symbol
9518 && inst.reloc.exp.X_add_symbol != NULL
9519 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9520 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9521 inst.reloc.exp.X_add_symbol =
9522 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9523#endif
90e4755a
RE
9524}
9525
9526static void
c19d1205 9527do_t_bx (void)
90e4755a 9528{
e07e6e58 9529 set_it_insn_type_last ();
c19d1205
ZW
9530 inst.instruction |= inst.operands[0].reg << 3;
9531 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9532 should cause the alignment to be checked once it is known. This is
9533 because BX PC only works if the instruction is word aligned. */
9534}
90e4755a 9535
c19d1205
ZW
9536static void
9537do_t_bxj (void)
9538{
fdfde340 9539 int Rm;
90e4755a 9540
e07e6e58 9541 set_it_insn_type_last ();
fdfde340
JM
9542 Rm = inst.operands[0].reg;
9543 reject_bad_reg (Rm);
9544 inst.instruction |= Rm << 16;
90e4755a
RE
9545}
9546
9547static void
c19d1205 9548do_t_clz (void)
90e4755a 9549{
fdfde340
JM
9550 unsigned Rd;
9551 unsigned Rm;
9552
9553 Rd = inst.operands[0].reg;
9554 Rm = inst.operands[1].reg;
9555
9556 reject_bad_reg (Rd);
9557 reject_bad_reg (Rm);
9558
9559 inst.instruction |= Rd << 8;
9560 inst.instruction |= Rm << 16;
9561 inst.instruction |= Rm;
c19d1205 9562}
90e4755a 9563
dfa9f0d5
PB
9564static void
9565do_t_cps (void)
9566{
e07e6e58 9567 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9568 inst.instruction |= inst.operands[0].imm;
9569}
9570
c19d1205
ZW
9571static void
9572do_t_cpsi (void)
9573{
e07e6e58 9574 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9575 if (unified_syntax
62b3e311
PB
9576 && (inst.operands[1].present || inst.size_req == 4)
9577 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9578 {
c19d1205
ZW
9579 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9580 inst.instruction = 0xf3af8000;
9581 inst.instruction |= imod << 9;
9582 inst.instruction |= inst.operands[0].imm << 5;
9583 if (inst.operands[1].present)
9584 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9585 }
c19d1205 9586 else
90e4755a 9587 {
62b3e311
PB
9588 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9589 && (inst.operands[0].imm & 4),
9590 _("selected processor does not support 'A' form "
9591 "of this instruction"));
9592 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9593 _("Thumb does not support the 2-argument "
9594 "form of this instruction"));
9595 inst.instruction |= inst.operands[0].imm;
90e4755a 9596 }
90e4755a
RE
9597}
9598
c19d1205
ZW
9599/* THUMB CPY instruction (argument parse). */
9600
90e4755a 9601static void
c19d1205 9602do_t_cpy (void)
90e4755a 9603{
c19d1205 9604 if (inst.size_req == 4)
90e4755a 9605 {
c19d1205
ZW
9606 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9607 inst.instruction |= inst.operands[0].reg << 8;
9608 inst.instruction |= inst.operands[1].reg;
90e4755a 9609 }
c19d1205 9610 else
90e4755a 9611 {
c19d1205
ZW
9612 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9613 inst.instruction |= (inst.operands[0].reg & 0x7);
9614 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9615 }
90e4755a
RE
9616}
9617
90e4755a 9618static void
25fe350b 9619do_t_cbz (void)
90e4755a 9620{
e07e6e58 9621 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9622 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9623 inst.instruction |= inst.operands[0].reg;
9624 inst.reloc.pc_rel = 1;
9625 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9626}
90e4755a 9627
62b3e311
PB
9628static void
9629do_t_dbg (void)
9630{
9631 inst.instruction |= inst.operands[0].imm;
9632}
9633
9634static void
9635do_t_div (void)
9636{
fdfde340
JM
9637 unsigned Rd, Rn, Rm;
9638
9639 Rd = inst.operands[0].reg;
9640 Rn = (inst.operands[1].present
9641 ? inst.operands[1].reg : Rd);
9642 Rm = inst.operands[2].reg;
9643
9644 reject_bad_reg (Rd);
9645 reject_bad_reg (Rn);
9646 reject_bad_reg (Rm);
9647
9648 inst.instruction |= Rd << 8;
9649 inst.instruction |= Rn << 16;
9650 inst.instruction |= Rm;
62b3e311
PB
9651}
9652
c19d1205
ZW
9653static void
9654do_t_hint (void)
9655{
9656 if (unified_syntax && inst.size_req == 4)
9657 inst.instruction = THUMB_OP32 (inst.instruction);
9658 else
9659 inst.instruction = THUMB_OP16 (inst.instruction);
9660}
90e4755a 9661
c19d1205
ZW
9662static void
9663do_t_it (void)
9664{
9665 unsigned int cond = inst.operands[0].imm;
e27ec89e 9666
e07e6e58
NC
9667 set_it_insn_type (IT_INSN);
9668 now_it.mask = (inst.instruction & 0xf) | 0x10;
9669 now_it.cc = cond;
e27ec89e
PB
9670
9671 /* If the condition is a negative condition, invert the mask. */
c19d1205 9672 if ((cond & 0x1) == 0x0)
90e4755a 9673 {
c19d1205 9674 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9675
c19d1205
ZW
9676 if ((mask & 0x7) == 0)
9677 /* no conversion needed */;
9678 else if ((mask & 0x3) == 0)
e27ec89e
PB
9679 mask ^= 0x8;
9680 else if ((mask & 0x1) == 0)
9681 mask ^= 0xC;
c19d1205 9682 else
e27ec89e 9683 mask ^= 0xE;
90e4755a 9684
e27ec89e
PB
9685 inst.instruction &= 0xfff0;
9686 inst.instruction |= mask;
c19d1205 9687 }
90e4755a 9688
c19d1205
ZW
9689 inst.instruction |= cond << 4;
9690}
90e4755a 9691
3c707909
PB
9692/* Helper function used for both push/pop and ldm/stm. */
9693static void
9694encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9695{
9696 bfd_boolean load;
9697
9698 load = (inst.instruction & (1 << 20)) != 0;
9699
9700 if (mask & (1 << 13))
9701 inst.error = _("SP not allowed in register list");
9702 if (load)
9703 {
e07e6e58
NC
9704 if (mask & (1 << 15))
9705 {
9706 if (mask & (1 << 14))
9707 inst.error = _("LR and PC should not both be in register list");
9708 else
9709 set_it_insn_type_last ();
9710 }
3c707909
PB
9711
9712 if ((mask & (1 << base)) != 0
9713 && writeback)
9714 as_warn (_("base register should not be in register list "
9715 "when written back"));
9716 }
9717 else
9718 {
9719 if (mask & (1 << 15))
9720 inst.error = _("PC not allowed in register list");
9721
9722 if (mask & (1 << base))
9723 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9724 }
9725
9726 if ((mask & (mask - 1)) == 0)
9727 {
9728 /* Single register transfers implemented as str/ldr. */
9729 if (writeback)
9730 {
9731 if (inst.instruction & (1 << 23))
9732 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9733 else
9734 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9735 }
9736 else
9737 {
9738 if (inst.instruction & (1 << 23))
9739 inst.instruction = 0x00800000; /* ia -> [base] */
9740 else
9741 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9742 }
9743
9744 inst.instruction |= 0xf8400000;
9745 if (load)
9746 inst.instruction |= 0x00100000;
9747
5f4273c7 9748 mask = ffs (mask) - 1;
3c707909
PB
9749 mask <<= 12;
9750 }
9751 else if (writeback)
9752 inst.instruction |= WRITE_BACK;
9753
9754 inst.instruction |= mask;
9755 inst.instruction |= base << 16;
9756}
9757
c19d1205
ZW
9758static void
9759do_t_ldmstm (void)
9760{
9761 /* This really doesn't seem worth it. */
9762 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9763 _("expression too complex"));
9764 constraint (inst.operands[1].writeback,
9765 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9766
c19d1205
ZW
9767 if (unified_syntax)
9768 {
3c707909
PB
9769 bfd_boolean narrow;
9770 unsigned mask;
9771
9772 narrow = FALSE;
c19d1205
ZW
9773 /* See if we can use a 16-bit instruction. */
9774 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9775 && inst.size_req != 4
3c707909 9776 && !(inst.operands[1].imm & ~0xff))
90e4755a 9777 {
3c707909 9778 mask = 1 << inst.operands[0].reg;
90e4755a 9779
3c707909
PB
9780 if (inst.operands[0].reg <= 7
9781 && (inst.instruction == T_MNEM_stmia
9782 ? inst.operands[0].writeback
9783 : (inst.operands[0].writeback
9784 == !(inst.operands[1].imm & mask))))
90e4755a 9785 {
3c707909
PB
9786 if (inst.instruction == T_MNEM_stmia
9787 && (inst.operands[1].imm & mask)
9788 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9789 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9790 inst.operands[0].reg);
3c707909
PB
9791
9792 inst.instruction = THUMB_OP16 (inst.instruction);
9793 inst.instruction |= inst.operands[0].reg << 8;
9794 inst.instruction |= inst.operands[1].imm;
9795 narrow = TRUE;
90e4755a 9796 }
3c707909
PB
9797 else if (inst.operands[0] .reg == REG_SP
9798 && inst.operands[0].writeback)
90e4755a 9799 {
3c707909
PB
9800 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9801 ? T_MNEM_push : T_MNEM_pop);
9802 inst.instruction |= inst.operands[1].imm;
9803 narrow = TRUE;
90e4755a 9804 }
3c707909
PB
9805 }
9806
9807 if (!narrow)
9808 {
c19d1205
ZW
9809 if (inst.instruction < 0xffff)
9810 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9811
5f4273c7
NC
9812 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9813 inst.operands[0].writeback);
90e4755a
RE
9814 }
9815 }
c19d1205 9816 else
90e4755a 9817 {
c19d1205
ZW
9818 constraint (inst.operands[0].reg > 7
9819 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9820 constraint (inst.instruction != T_MNEM_ldmia
9821 && inst.instruction != T_MNEM_stmia,
9822 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9823 if (inst.instruction == T_MNEM_stmia)
f03698e6 9824 {
c19d1205
ZW
9825 if (!inst.operands[0].writeback)
9826 as_warn (_("this instruction will write back the base register"));
9827 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9828 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9829 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9830 inst.operands[0].reg);
f03698e6 9831 }
c19d1205 9832 else
90e4755a 9833 {
c19d1205
ZW
9834 if (!inst.operands[0].writeback
9835 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9836 as_warn (_("this instruction will write back the base register"));
9837 else if (inst.operands[0].writeback
9838 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9839 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9840 }
9841
c19d1205
ZW
9842 inst.instruction = THUMB_OP16 (inst.instruction);
9843 inst.instruction |= inst.operands[0].reg << 8;
9844 inst.instruction |= inst.operands[1].imm;
9845 }
9846}
e28cd48c 9847
c19d1205
ZW
9848static void
9849do_t_ldrex (void)
9850{
9851 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9852 || inst.operands[1].postind || inst.operands[1].writeback
9853 || inst.operands[1].immisreg || inst.operands[1].shifted
9854 || inst.operands[1].negative,
01cfc07f 9855 BAD_ADDR_MODE);
e28cd48c 9856
c19d1205
ZW
9857 inst.instruction |= inst.operands[0].reg << 12;
9858 inst.instruction |= inst.operands[1].reg << 16;
9859 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9860}
e28cd48c 9861
c19d1205
ZW
9862static void
9863do_t_ldrexd (void)
9864{
9865 if (!inst.operands[1].present)
1cac9012 9866 {
c19d1205
ZW
9867 constraint (inst.operands[0].reg == REG_LR,
9868 _("r14 not allowed as first register "
9869 "when second register is omitted"));
9870 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9871 }
c19d1205
ZW
9872 constraint (inst.operands[0].reg == inst.operands[1].reg,
9873 BAD_OVERLAP);
b99bd4ef 9874
c19d1205
ZW
9875 inst.instruction |= inst.operands[0].reg << 12;
9876 inst.instruction |= inst.operands[1].reg << 8;
9877 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9878}
9879
9880static void
c19d1205 9881do_t_ldst (void)
b99bd4ef 9882{
0110f2b8
PB
9883 unsigned long opcode;
9884 int Rn;
9885
e07e6e58
NC
9886 if (inst.operands[0].isreg
9887 && !inst.operands[0].preind
9888 && inst.operands[0].reg == REG_PC)
9889 set_it_insn_type_last ();
9890
0110f2b8 9891 opcode = inst.instruction;
c19d1205 9892 if (unified_syntax)
b99bd4ef 9893 {
53365c0d
PB
9894 if (!inst.operands[1].isreg)
9895 {
9896 if (opcode <= 0xffff)
9897 inst.instruction = THUMB_OP32 (opcode);
9898 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9899 return;
9900 }
0110f2b8
PB
9901 if (inst.operands[1].isreg
9902 && !inst.operands[1].writeback
c19d1205
ZW
9903 && !inst.operands[1].shifted && !inst.operands[1].postind
9904 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9905 && opcode <= 0xffff
9906 && inst.size_req != 4)
c19d1205 9907 {
0110f2b8
PB
9908 /* Insn may have a 16-bit form. */
9909 Rn = inst.operands[1].reg;
9910 if (inst.operands[1].immisreg)
9911 {
9912 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9913 /* [Rn, Rik] */
0110f2b8
PB
9914 if (Rn <= 7 && inst.operands[1].imm <= 7)
9915 goto op16;
9916 }
9917 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9918 && opcode != T_MNEM_ldrsb)
9919 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9920 || (Rn == REG_SP && opcode == T_MNEM_str))
9921 {
9922 /* [Rn, #const] */
9923 if (Rn > 7)
9924 {
9925 if (Rn == REG_PC)
9926 {
9927 if (inst.reloc.pc_rel)
9928 opcode = T_MNEM_ldr_pc2;
9929 else
9930 opcode = T_MNEM_ldr_pc;
9931 }
9932 else
9933 {
9934 if (opcode == T_MNEM_ldr)
9935 opcode = T_MNEM_ldr_sp;
9936 else
9937 opcode = T_MNEM_str_sp;
9938 }
9939 inst.instruction = inst.operands[0].reg << 8;
9940 }
9941 else
9942 {
9943 inst.instruction = inst.operands[0].reg;
9944 inst.instruction |= inst.operands[1].reg << 3;
9945 }
9946 inst.instruction |= THUMB_OP16 (opcode);
9947 if (inst.size_req == 2)
9948 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9949 else
9950 inst.relax = opcode;
9951 return;
9952 }
c19d1205 9953 }
0110f2b8
PB
9954 /* Definitely a 32-bit variant. */
9955 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9956 inst.instruction |= inst.operands[0].reg << 12;
9957 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9958 return;
9959 }
9960
c19d1205
ZW
9961 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9962
9963 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9964 {
c19d1205
ZW
9965 /* Only [Rn,Rm] is acceptable. */
9966 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9967 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9968 || inst.operands[1].postind || inst.operands[1].shifted
9969 || inst.operands[1].negative,
9970 _("Thumb does not support this addressing mode"));
9971 inst.instruction = THUMB_OP16 (inst.instruction);
9972 goto op16;
b99bd4ef 9973 }
5f4273c7 9974
c19d1205
ZW
9975 inst.instruction = THUMB_OP16 (inst.instruction);
9976 if (!inst.operands[1].isreg)
9977 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9978 return;
b99bd4ef 9979
c19d1205
ZW
9980 constraint (!inst.operands[1].preind
9981 || inst.operands[1].shifted
9982 || inst.operands[1].writeback,
9983 _("Thumb does not support this addressing mode"));
9984 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9985 {
c19d1205
ZW
9986 constraint (inst.instruction & 0x0600,
9987 _("byte or halfword not valid for base register"));
9988 constraint (inst.operands[1].reg == REG_PC
9989 && !(inst.instruction & THUMB_LOAD_BIT),
9990 _("r15 based store not allowed"));
9991 constraint (inst.operands[1].immisreg,
9992 _("invalid base register for register offset"));
b99bd4ef 9993
c19d1205
ZW
9994 if (inst.operands[1].reg == REG_PC)
9995 inst.instruction = T_OPCODE_LDR_PC;
9996 else if (inst.instruction & THUMB_LOAD_BIT)
9997 inst.instruction = T_OPCODE_LDR_SP;
9998 else
9999 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 10000
c19d1205
ZW
10001 inst.instruction |= inst.operands[0].reg << 8;
10002 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10003 return;
10004 }
90e4755a 10005
c19d1205
ZW
10006 constraint (inst.operands[1].reg > 7, BAD_HIREG);
10007 if (!inst.operands[1].immisreg)
10008 {
10009 /* Immediate offset. */
10010 inst.instruction |= inst.operands[0].reg;
10011 inst.instruction |= inst.operands[1].reg << 3;
10012 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
10013 return;
10014 }
90e4755a 10015
c19d1205
ZW
10016 /* Register offset. */
10017 constraint (inst.operands[1].imm > 7, BAD_HIREG);
10018 constraint (inst.operands[1].negative,
10019 _("Thumb does not support this addressing mode"));
90e4755a 10020
c19d1205
ZW
10021 op16:
10022 switch (inst.instruction)
10023 {
10024 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
10025 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
10026 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
10027 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
10028 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
10029 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
10030 case 0x5600 /* ldrsb */:
10031 case 0x5e00 /* ldrsh */: break;
10032 default: abort ();
10033 }
90e4755a 10034
c19d1205
ZW
10035 inst.instruction |= inst.operands[0].reg;
10036 inst.instruction |= inst.operands[1].reg << 3;
10037 inst.instruction |= inst.operands[1].imm << 6;
10038}
90e4755a 10039
c19d1205
ZW
10040static void
10041do_t_ldstd (void)
10042{
10043 if (!inst.operands[1].present)
b99bd4ef 10044 {
c19d1205
ZW
10045 inst.operands[1].reg = inst.operands[0].reg + 1;
10046 constraint (inst.operands[0].reg == REG_LR,
10047 _("r14 not allowed here"));
b99bd4ef 10048 }
c19d1205
ZW
10049 inst.instruction |= inst.operands[0].reg << 12;
10050 inst.instruction |= inst.operands[1].reg << 8;
10051 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
10052}
10053
c19d1205
ZW
10054static void
10055do_t_ldstt (void)
10056{
10057 inst.instruction |= inst.operands[0].reg << 12;
10058 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
10059}
a737bd4d 10060
b99bd4ef 10061static void
c19d1205 10062do_t_mla (void)
b99bd4ef 10063{
fdfde340 10064 unsigned Rd, Rn, Rm, Ra;
c921be7d 10065
fdfde340
JM
10066 Rd = inst.operands[0].reg;
10067 Rn = inst.operands[1].reg;
10068 Rm = inst.operands[2].reg;
10069 Ra = inst.operands[3].reg;
10070
10071 reject_bad_reg (Rd);
10072 reject_bad_reg (Rn);
10073 reject_bad_reg (Rm);
10074 reject_bad_reg (Ra);
10075
10076 inst.instruction |= Rd << 8;
10077 inst.instruction |= Rn << 16;
10078 inst.instruction |= Rm;
10079 inst.instruction |= Ra << 12;
c19d1205 10080}
b99bd4ef 10081
c19d1205
ZW
10082static void
10083do_t_mlal (void)
10084{
fdfde340
JM
10085 unsigned RdLo, RdHi, Rn, Rm;
10086
10087 RdLo = inst.operands[0].reg;
10088 RdHi = inst.operands[1].reg;
10089 Rn = inst.operands[2].reg;
10090 Rm = inst.operands[3].reg;
10091
10092 reject_bad_reg (RdLo);
10093 reject_bad_reg (RdHi);
10094 reject_bad_reg (Rn);
10095 reject_bad_reg (Rm);
10096
10097 inst.instruction |= RdLo << 12;
10098 inst.instruction |= RdHi << 8;
10099 inst.instruction |= Rn << 16;
10100 inst.instruction |= Rm;
c19d1205 10101}
b99bd4ef 10102
c19d1205
ZW
10103static void
10104do_t_mov_cmp (void)
10105{
fdfde340
JM
10106 unsigned Rn, Rm;
10107
10108 Rn = inst.operands[0].reg;
10109 Rm = inst.operands[1].reg;
10110
e07e6e58
NC
10111 if (Rn == REG_PC)
10112 set_it_insn_type_last ();
10113
c19d1205 10114 if (unified_syntax)
b99bd4ef 10115 {
c19d1205
ZW
10116 int r0off = (inst.instruction == T_MNEM_mov
10117 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 10118 unsigned long opcode;
3d388997
PB
10119 bfd_boolean narrow;
10120 bfd_boolean low_regs;
10121
fdfde340 10122 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 10123 opcode = inst.instruction;
e07e6e58 10124 if (in_it_block ())
0110f2b8 10125 narrow = opcode != T_MNEM_movs;
3d388997 10126 else
0110f2b8 10127 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
10128 if (inst.size_req == 4
10129 || inst.operands[1].shifted)
10130 narrow = FALSE;
10131
efd81785
PB
10132 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
10133 if (opcode == T_MNEM_movs && inst.operands[1].isreg
10134 && !inst.operands[1].shifted
fdfde340
JM
10135 && Rn == REG_PC
10136 && Rm == REG_LR)
efd81785
PB
10137 {
10138 inst.instruction = T2_SUBS_PC_LR;
10139 return;
10140 }
10141
fdfde340
JM
10142 if (opcode == T_MNEM_cmp)
10143 {
10144 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
10145 if (narrow)
10146 {
10147 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
10148 but valid. */
10149 warn_deprecated_sp (Rm);
10150 /* R15 was documented as a valid choice for Rm in ARMv6,
10151 but as UNPREDICTABLE in ARMv7. ARM's proprietary
10152 tools reject R15, so we do too. */
10153 constraint (Rm == REG_PC, BAD_PC);
10154 }
10155 else
10156 reject_bad_reg (Rm);
fdfde340
JM
10157 }
10158 else if (opcode == T_MNEM_mov
10159 || opcode == T_MNEM_movs)
10160 {
10161 if (inst.operands[1].isreg)
10162 {
10163 if (opcode == T_MNEM_movs)
10164 {
10165 reject_bad_reg (Rn);
10166 reject_bad_reg (Rm);
10167 }
10168 else if ((Rn == REG_SP || Rn == REG_PC)
10169 && (Rm == REG_SP || Rm == REG_PC))
10170 reject_bad_reg (Rm);
10171 }
10172 else
10173 reject_bad_reg (Rn);
10174 }
10175
c19d1205
ZW
10176 if (!inst.operands[1].isreg)
10177 {
0110f2b8 10178 /* Immediate operand. */
e07e6e58 10179 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
10180 narrow = 0;
10181 if (low_regs && narrow)
10182 {
10183 inst.instruction = THUMB_OP16 (opcode);
fdfde340 10184 inst.instruction |= Rn << 8;
0110f2b8
PB
10185 if (inst.size_req == 2)
10186 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10187 else
10188 inst.relax = opcode;
10189 }
10190 else
10191 {
10192 inst.instruction = THUMB_OP32 (inst.instruction);
10193 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10194 inst.instruction |= Rn << r0off;
0110f2b8
PB
10195 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10196 }
c19d1205 10197 }
728ca7c9
PB
10198 else if (inst.operands[1].shifted && inst.operands[1].immisreg
10199 && (inst.instruction == T_MNEM_mov
10200 || inst.instruction == T_MNEM_movs))
10201 {
10202 /* Register shifts are encoded as separate shift instructions. */
10203 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
10204
e07e6e58 10205 if (in_it_block ())
728ca7c9
PB
10206 narrow = !flags;
10207 else
10208 narrow = flags;
10209
10210 if (inst.size_req == 4)
10211 narrow = FALSE;
10212
10213 if (!low_regs || inst.operands[1].imm > 7)
10214 narrow = FALSE;
10215
fdfde340 10216 if (Rn != Rm)
728ca7c9
PB
10217 narrow = FALSE;
10218
10219 switch (inst.operands[1].shift_kind)
10220 {
10221 case SHIFT_LSL:
10222 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
10223 break;
10224 case SHIFT_ASR:
10225 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
10226 break;
10227 case SHIFT_LSR:
10228 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
10229 break;
10230 case SHIFT_ROR:
10231 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
10232 break;
10233 default:
5f4273c7 10234 abort ();
728ca7c9
PB
10235 }
10236
10237 inst.instruction = opcode;
10238 if (narrow)
10239 {
fdfde340 10240 inst.instruction |= Rn;
728ca7c9
PB
10241 inst.instruction |= inst.operands[1].imm << 3;
10242 }
10243 else
10244 {
10245 if (flags)
10246 inst.instruction |= CONDS_BIT;
10247
fdfde340
JM
10248 inst.instruction |= Rn << 8;
10249 inst.instruction |= Rm << 16;
728ca7c9
PB
10250 inst.instruction |= inst.operands[1].imm;
10251 }
10252 }
3d388997 10253 else if (!narrow)
c19d1205 10254 {
728ca7c9
PB
10255 /* Some mov with immediate shift have narrow variants.
10256 Register shifts are handled above. */
10257 if (low_regs && inst.operands[1].shifted
10258 && (inst.instruction == T_MNEM_mov
10259 || inst.instruction == T_MNEM_movs))
10260 {
e07e6e58 10261 if (in_it_block ())
728ca7c9
PB
10262 narrow = (inst.instruction == T_MNEM_mov);
10263 else
10264 narrow = (inst.instruction == T_MNEM_movs);
10265 }
10266
10267 if (narrow)
10268 {
10269 switch (inst.operands[1].shift_kind)
10270 {
10271 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10272 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
10273 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10274 default: narrow = FALSE; break;
10275 }
10276 }
10277
10278 if (narrow)
10279 {
fdfde340
JM
10280 inst.instruction |= Rn;
10281 inst.instruction |= Rm << 3;
728ca7c9
PB
10282 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10283 }
10284 else
10285 {
10286 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10287 inst.instruction |= Rn << r0off;
728ca7c9
PB
10288 encode_thumb32_shifted_operand (1);
10289 }
c19d1205
ZW
10290 }
10291 else
10292 switch (inst.instruction)
10293 {
10294 case T_MNEM_mov:
10295 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10296 inst.instruction |= (Rn & 0x8) << 4;
10297 inst.instruction |= (Rn & 0x7);
10298 inst.instruction |= Rm << 3;
c19d1205 10299 break;
b99bd4ef 10300
c19d1205
ZW
10301 case T_MNEM_movs:
10302 /* We know we have low registers at this point.
10303 Generate ADD Rd, Rs, #0. */
10304 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10305 inst.instruction |= Rn;
10306 inst.instruction |= Rm << 3;
c19d1205
ZW
10307 break;
10308
10309 case T_MNEM_cmp:
3d388997 10310 if (low_regs)
c19d1205
ZW
10311 {
10312 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10313 inst.instruction |= Rn;
10314 inst.instruction |= Rm << 3;
c19d1205
ZW
10315 }
10316 else
10317 {
10318 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10319 inst.instruction |= (Rn & 0x8) << 4;
10320 inst.instruction |= (Rn & 0x7);
10321 inst.instruction |= Rm << 3;
c19d1205
ZW
10322 }
10323 break;
10324 }
b99bd4ef
NC
10325 return;
10326 }
10327
c19d1205 10328 inst.instruction = THUMB_OP16 (inst.instruction);
539d4391
NC
10329
10330 /* PR 10443: Do not silently ignore shifted operands. */
10331 constraint (inst.operands[1].shifted,
10332 _("shifts in CMP/MOV instructions are only supported in unified syntax"));
10333
c19d1205 10334 if (inst.operands[1].isreg)
b99bd4ef 10335 {
fdfde340 10336 if (Rn < 8 && Rm < 8)
b99bd4ef 10337 {
c19d1205
ZW
10338 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10339 since a MOV instruction produces unpredictable results. */
10340 if (inst.instruction == T_OPCODE_MOV_I8)
10341 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10342 else
c19d1205 10343 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10344
fdfde340
JM
10345 inst.instruction |= Rn;
10346 inst.instruction |= Rm << 3;
b99bd4ef
NC
10347 }
10348 else
10349 {
c19d1205
ZW
10350 if (inst.instruction == T_OPCODE_MOV_I8)
10351 inst.instruction = T_OPCODE_MOV_HR;
10352 else
10353 inst.instruction = T_OPCODE_CMP_HR;
10354 do_t_cpy ();
b99bd4ef
NC
10355 }
10356 }
c19d1205 10357 else
b99bd4ef 10358 {
fdfde340 10359 constraint (Rn > 7,
c19d1205 10360 _("only lo regs allowed with immediate"));
fdfde340 10361 inst.instruction |= Rn << 8;
c19d1205
ZW
10362 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10363 }
10364}
b99bd4ef 10365
c19d1205
ZW
10366static void
10367do_t_mov16 (void)
10368{
fdfde340 10369 unsigned Rd;
b6895b4f
PB
10370 bfd_vma imm;
10371 bfd_boolean top;
10372
10373 top = (inst.instruction & 0x00800000) != 0;
10374 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10375 {
10376 constraint (top, _(":lower16: not allowed this instruction"));
10377 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10378 }
10379 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10380 {
10381 constraint (!top, _(":upper16: not allowed this instruction"));
10382 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10383 }
10384
fdfde340
JM
10385 Rd = inst.operands[0].reg;
10386 reject_bad_reg (Rd);
10387
10388 inst.instruction |= Rd << 8;
b6895b4f
PB
10389 if (inst.reloc.type == BFD_RELOC_UNUSED)
10390 {
10391 imm = inst.reloc.exp.X_add_number;
10392 inst.instruction |= (imm & 0xf000) << 4;
10393 inst.instruction |= (imm & 0x0800) << 15;
10394 inst.instruction |= (imm & 0x0700) << 4;
10395 inst.instruction |= (imm & 0x00ff);
10396 }
c19d1205 10397}
b99bd4ef 10398
c19d1205
ZW
10399static void
10400do_t_mvn_tst (void)
10401{
fdfde340 10402 unsigned Rn, Rm;
c921be7d 10403
fdfde340
JM
10404 Rn = inst.operands[0].reg;
10405 Rm = inst.operands[1].reg;
10406
10407 if (inst.instruction == T_MNEM_cmp
10408 || inst.instruction == T_MNEM_cmn)
10409 constraint (Rn == REG_PC, BAD_PC);
10410 else
10411 reject_bad_reg (Rn);
10412 reject_bad_reg (Rm);
10413
c19d1205
ZW
10414 if (unified_syntax)
10415 {
10416 int r0off = (inst.instruction == T_MNEM_mvn
10417 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10418 bfd_boolean narrow;
10419
10420 if (inst.size_req == 4
10421 || inst.instruction > 0xffff
10422 || inst.operands[1].shifted
fdfde340 10423 || Rn > 7 || Rm > 7)
3d388997
PB
10424 narrow = FALSE;
10425 else if (inst.instruction == T_MNEM_cmn)
10426 narrow = TRUE;
10427 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10428 narrow = !in_it_block ();
3d388997 10429 else
e07e6e58 10430 narrow = in_it_block ();
3d388997 10431
c19d1205 10432 if (!inst.operands[1].isreg)
b99bd4ef 10433 {
c19d1205
ZW
10434 /* For an immediate, we always generate a 32-bit opcode;
10435 section relaxation will shrink it later if possible. */
10436 if (inst.instruction < 0xffff)
10437 inst.instruction = THUMB_OP32 (inst.instruction);
10438 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10439 inst.instruction |= Rn << r0off;
c19d1205 10440 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10441 }
c19d1205 10442 else
b99bd4ef 10443 {
c19d1205 10444 /* See if we can do this with a 16-bit instruction. */
3d388997 10445 if (narrow)
b99bd4ef 10446 {
c19d1205 10447 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10448 inst.instruction |= Rn;
10449 inst.instruction |= Rm << 3;
b99bd4ef 10450 }
c19d1205 10451 else
b99bd4ef 10452 {
c19d1205
ZW
10453 constraint (inst.operands[1].shifted
10454 && inst.operands[1].immisreg,
10455 _("shift must be constant"));
10456 if (inst.instruction < 0xffff)
10457 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10458 inst.instruction |= Rn << r0off;
c19d1205 10459 encode_thumb32_shifted_operand (1);
b99bd4ef 10460 }
b99bd4ef
NC
10461 }
10462 }
10463 else
10464 {
c19d1205
ZW
10465 constraint (inst.instruction > 0xffff
10466 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10467 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10468 _("unshifted register required"));
fdfde340 10469 constraint (Rn > 7 || Rm > 7,
c19d1205 10470 BAD_HIREG);
b99bd4ef 10471
c19d1205 10472 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10473 inst.instruction |= Rn;
10474 inst.instruction |= Rm << 3;
b99bd4ef 10475 }
b99bd4ef
NC
10476}
10477
b05fe5cf 10478static void
c19d1205 10479do_t_mrs (void)
b05fe5cf 10480{
fdfde340 10481 unsigned Rd;
62b3e311 10482 int flags;
037e8744
JB
10483
10484 if (do_vfp_nsyn_mrs () == SUCCESS)
10485 return;
10486
62b3e311
PB
10487 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10488 if (flags == 0)
10489 {
7e806470 10490 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10491 _("selected processor does not support "
10492 "requested special purpose register"));
10493 }
10494 else
10495 {
10496 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10497 _("selected processor does not support "
44bf2362 10498 "requested special purpose register"));
62b3e311
PB
10499 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10500 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10501 _("'CPSR' or 'SPSR' expected"));
10502 }
5f4273c7 10503
fdfde340
JM
10504 Rd = inst.operands[0].reg;
10505 reject_bad_reg (Rd);
10506
10507 inst.instruction |= Rd << 8;
62b3e311
PB
10508 inst.instruction |= (flags & SPSR_BIT) >> 2;
10509 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10510}
b05fe5cf 10511
c19d1205
ZW
10512static void
10513do_t_msr (void)
10514{
62b3e311 10515 int flags;
fdfde340 10516 unsigned Rn;
62b3e311 10517
037e8744
JB
10518 if (do_vfp_nsyn_msr () == SUCCESS)
10519 return;
10520
c19d1205
ZW
10521 constraint (!inst.operands[1].isreg,
10522 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10523 flags = inst.operands[0].imm;
10524 if (flags & ~0xff)
10525 {
10526 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10527 _("selected processor does not support "
10528 "requested special purpose register"));
10529 }
10530 else
10531 {
7e806470 10532 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10533 _("selected processor does not support "
10534 "requested special purpose register"));
10535 flags |= PSR_f;
10536 }
c921be7d 10537
fdfde340
JM
10538 Rn = inst.operands[1].reg;
10539 reject_bad_reg (Rn);
10540
62b3e311
PB
10541 inst.instruction |= (flags & SPSR_BIT) >> 2;
10542 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10543 inst.instruction |= (flags & 0xff);
fdfde340 10544 inst.instruction |= Rn << 16;
c19d1205 10545}
b05fe5cf 10546
c19d1205
ZW
10547static void
10548do_t_mul (void)
10549{
17828f45 10550 bfd_boolean narrow;
fdfde340 10551 unsigned Rd, Rn, Rm;
17828f45 10552
c19d1205
ZW
10553 if (!inst.operands[2].present)
10554 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10555
fdfde340
JM
10556 Rd = inst.operands[0].reg;
10557 Rn = inst.operands[1].reg;
10558 Rm = inst.operands[2].reg;
10559
17828f45 10560 if (unified_syntax)
b05fe5cf 10561 {
17828f45 10562 if (inst.size_req == 4
fdfde340
JM
10563 || (Rd != Rn
10564 && Rd != Rm)
10565 || Rn > 7
10566 || Rm > 7)
17828f45
JM
10567 narrow = FALSE;
10568 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10569 narrow = !in_it_block ();
17828f45 10570 else
e07e6e58 10571 narrow = in_it_block ();
b05fe5cf 10572 }
c19d1205 10573 else
b05fe5cf 10574 {
17828f45 10575 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10576 constraint (Rn > 7 || Rm > 7,
c19d1205 10577 BAD_HIREG);
17828f45
JM
10578 narrow = TRUE;
10579 }
b05fe5cf 10580
17828f45
JM
10581 if (narrow)
10582 {
10583 /* 16-bit MULS/Conditional MUL. */
c19d1205 10584 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10585 inst.instruction |= Rd;
b05fe5cf 10586
fdfde340
JM
10587 if (Rd == Rn)
10588 inst.instruction |= Rm << 3;
10589 else if (Rd == Rm)
10590 inst.instruction |= Rn << 3;
c19d1205
ZW
10591 else
10592 constraint (1, _("dest must overlap one source register"));
10593 }
17828f45
JM
10594 else
10595 {
e07e6e58
NC
10596 constraint (inst.instruction != T_MNEM_mul,
10597 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10598 /* 32-bit MUL. */
10599 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10600 inst.instruction |= Rd << 8;
10601 inst.instruction |= Rn << 16;
10602 inst.instruction |= Rm << 0;
10603
10604 reject_bad_reg (Rd);
10605 reject_bad_reg (Rn);
10606 reject_bad_reg (Rm);
17828f45 10607 }
c19d1205 10608}
b05fe5cf 10609
c19d1205
ZW
10610static void
10611do_t_mull (void)
10612{
fdfde340 10613 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10614
fdfde340
JM
10615 RdLo = inst.operands[0].reg;
10616 RdHi = inst.operands[1].reg;
10617 Rn = inst.operands[2].reg;
10618 Rm = inst.operands[3].reg;
10619
10620 reject_bad_reg (RdLo);
10621 reject_bad_reg (RdHi);
10622 reject_bad_reg (Rn);
10623 reject_bad_reg (Rm);
10624
10625 inst.instruction |= RdLo << 12;
10626 inst.instruction |= RdHi << 8;
10627 inst.instruction |= Rn << 16;
10628 inst.instruction |= Rm;
10629
10630 if (RdLo == RdHi)
c19d1205
ZW
10631 as_tsktsk (_("rdhi and rdlo must be different"));
10632}
b05fe5cf 10633
c19d1205
ZW
10634static void
10635do_t_nop (void)
10636{
e07e6e58
NC
10637 set_it_insn_type (NEUTRAL_IT_INSN);
10638
c19d1205
ZW
10639 if (unified_syntax)
10640 {
10641 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10642 {
c19d1205
ZW
10643 inst.instruction = THUMB_OP32 (inst.instruction);
10644 inst.instruction |= inst.operands[0].imm;
10645 }
10646 else
10647 {
bc2d1808
NC
10648 /* PR9722: Check for Thumb2 availability before
10649 generating a thumb2 nop instruction. */
10650 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10651 {
10652 inst.instruction = THUMB_OP16 (inst.instruction);
10653 inst.instruction |= inst.operands[0].imm << 4;
10654 }
10655 else
10656 inst.instruction = 0x46c0;
c19d1205
ZW
10657 }
10658 }
10659 else
10660 {
10661 constraint (inst.operands[0].present,
10662 _("Thumb does not support NOP with hints"));
10663 inst.instruction = 0x46c0;
10664 }
10665}
b05fe5cf 10666
c19d1205
ZW
10667static void
10668do_t_neg (void)
10669{
10670 if (unified_syntax)
10671 {
3d388997
PB
10672 bfd_boolean narrow;
10673
10674 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10675 narrow = !in_it_block ();
3d388997 10676 else
e07e6e58 10677 narrow = in_it_block ();
3d388997
PB
10678 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10679 narrow = FALSE;
10680 if (inst.size_req == 4)
10681 narrow = FALSE;
10682
10683 if (!narrow)
c19d1205
ZW
10684 {
10685 inst.instruction = THUMB_OP32 (inst.instruction);
10686 inst.instruction |= inst.operands[0].reg << 8;
10687 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10688 }
10689 else
10690 {
c19d1205
ZW
10691 inst.instruction = THUMB_OP16 (inst.instruction);
10692 inst.instruction |= inst.operands[0].reg;
10693 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10694 }
10695 }
10696 else
10697 {
c19d1205
ZW
10698 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10699 BAD_HIREG);
10700 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10701
10702 inst.instruction = THUMB_OP16 (inst.instruction);
10703 inst.instruction |= inst.operands[0].reg;
10704 inst.instruction |= inst.operands[1].reg << 3;
10705 }
10706}
10707
1c444d06
JM
10708static void
10709do_t_orn (void)
10710{
10711 unsigned Rd, Rn;
10712
10713 Rd = inst.operands[0].reg;
10714 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10715
fdfde340
JM
10716 reject_bad_reg (Rd);
10717 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10718 reject_bad_reg (Rn);
10719
1c444d06
JM
10720 inst.instruction |= Rd << 8;
10721 inst.instruction |= Rn << 16;
10722
10723 if (!inst.operands[2].isreg)
10724 {
10725 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10726 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10727 }
10728 else
10729 {
10730 unsigned Rm;
10731
10732 Rm = inst.operands[2].reg;
fdfde340 10733 reject_bad_reg (Rm);
1c444d06
JM
10734
10735 constraint (inst.operands[2].shifted
10736 && inst.operands[2].immisreg,
10737 _("shift must be constant"));
10738 encode_thumb32_shifted_operand (2);
10739 }
10740}
10741
c19d1205
ZW
10742static void
10743do_t_pkhbt (void)
10744{
fdfde340
JM
10745 unsigned Rd, Rn, Rm;
10746
10747 Rd = inst.operands[0].reg;
10748 Rn = inst.operands[1].reg;
10749 Rm = inst.operands[2].reg;
10750
10751 reject_bad_reg (Rd);
10752 reject_bad_reg (Rn);
10753 reject_bad_reg (Rm);
10754
10755 inst.instruction |= Rd << 8;
10756 inst.instruction |= Rn << 16;
10757 inst.instruction |= Rm;
c19d1205
ZW
10758 if (inst.operands[3].present)
10759 {
10760 unsigned int val = inst.reloc.exp.X_add_number;
10761 constraint (inst.reloc.exp.X_op != O_constant,
10762 _("expression too complex"));
10763 inst.instruction |= (val & 0x1c) << 10;
10764 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10765 }
c19d1205 10766}
b05fe5cf 10767
c19d1205
ZW
10768static void
10769do_t_pkhtb (void)
10770{
10771 if (!inst.operands[3].present)
1ef52f49
NC
10772 {
10773 unsigned Rtmp;
10774
10775 inst.instruction &= ~0x00000020;
10776
10777 /* PR 10168. Swap the Rm and Rn registers. */
10778 Rtmp = inst.operands[1].reg;
10779 inst.operands[1].reg = inst.operands[2].reg;
10780 inst.operands[2].reg = Rtmp;
10781 }
c19d1205 10782 do_t_pkhbt ();
b05fe5cf
ZW
10783}
10784
c19d1205
ZW
10785static void
10786do_t_pld (void)
10787{
fdfde340
JM
10788 if (inst.operands[0].immisreg)
10789 reject_bad_reg (inst.operands[0].imm);
10790
c19d1205
ZW
10791 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10792}
b05fe5cf 10793
c19d1205
ZW
10794static void
10795do_t_push_pop (void)
b99bd4ef 10796{
e9f89963 10797 unsigned mask;
5f4273c7 10798
c19d1205
ZW
10799 constraint (inst.operands[0].writeback,
10800 _("push/pop do not support {reglist}^"));
10801 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10802 _("expression too complex"));
b99bd4ef 10803
e9f89963
PB
10804 mask = inst.operands[0].imm;
10805 if ((mask & ~0xff) == 0)
3c707909 10806 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10807 else if ((inst.instruction == T_MNEM_push
e9f89963 10808 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10809 || (inst.instruction == T_MNEM_pop
e9f89963 10810 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10811 {
c19d1205
ZW
10812 inst.instruction = THUMB_OP16 (inst.instruction);
10813 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10814 inst.instruction |= mask & 0xff;
c19d1205
ZW
10815 }
10816 else if (unified_syntax)
10817 {
3c707909 10818 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10819 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10820 }
10821 else
10822 {
10823 inst.error = _("invalid register list to push/pop instruction");
10824 return;
10825 }
c19d1205 10826}
b99bd4ef 10827
c19d1205
ZW
10828static void
10829do_t_rbit (void)
10830{
fdfde340
JM
10831 unsigned Rd, Rm;
10832
10833 Rd = inst.operands[0].reg;
10834 Rm = inst.operands[1].reg;
10835
10836 reject_bad_reg (Rd);
10837 reject_bad_reg (Rm);
10838
10839 inst.instruction |= Rd << 8;
10840 inst.instruction |= Rm << 16;
10841 inst.instruction |= Rm;
c19d1205 10842}
b99bd4ef 10843
c19d1205
ZW
10844static void
10845do_t_rev (void)
10846{
fdfde340
JM
10847 unsigned Rd, Rm;
10848
10849 Rd = inst.operands[0].reg;
10850 Rm = inst.operands[1].reg;
10851
10852 reject_bad_reg (Rd);
10853 reject_bad_reg (Rm);
10854
10855 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10856 && inst.size_req != 4)
10857 {
10858 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10859 inst.instruction |= Rd;
10860 inst.instruction |= Rm << 3;
c19d1205
ZW
10861 }
10862 else if (unified_syntax)
10863 {
10864 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10865 inst.instruction |= Rd << 8;
10866 inst.instruction |= Rm << 16;
10867 inst.instruction |= Rm;
c19d1205
ZW
10868 }
10869 else
10870 inst.error = BAD_HIREG;
10871}
b99bd4ef 10872
1c444d06
JM
10873static void
10874do_t_rrx (void)
10875{
10876 unsigned Rd, Rm;
10877
10878 Rd = inst.operands[0].reg;
10879 Rm = inst.operands[1].reg;
10880
fdfde340
JM
10881 reject_bad_reg (Rd);
10882 reject_bad_reg (Rm);
c921be7d 10883
1c444d06
JM
10884 inst.instruction |= Rd << 8;
10885 inst.instruction |= Rm;
10886}
10887
c19d1205
ZW
10888static void
10889do_t_rsb (void)
10890{
fdfde340 10891 unsigned Rd, Rs;
b99bd4ef 10892
c19d1205
ZW
10893 Rd = inst.operands[0].reg;
10894 Rs = (inst.operands[1].present
10895 ? inst.operands[1].reg /* Rd, Rs, foo */
10896 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10897
fdfde340
JM
10898 reject_bad_reg (Rd);
10899 reject_bad_reg (Rs);
10900 if (inst.operands[2].isreg)
10901 reject_bad_reg (inst.operands[2].reg);
10902
c19d1205
ZW
10903 inst.instruction |= Rd << 8;
10904 inst.instruction |= Rs << 16;
10905 if (!inst.operands[2].isreg)
10906 {
026d3abb
PB
10907 bfd_boolean narrow;
10908
10909 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10910 narrow = !in_it_block ();
026d3abb 10911 else
e07e6e58 10912 narrow = in_it_block ();
026d3abb
PB
10913
10914 if (Rd > 7 || Rs > 7)
10915 narrow = FALSE;
10916
10917 if (inst.size_req == 4 || !unified_syntax)
10918 narrow = FALSE;
10919
10920 if (inst.reloc.exp.X_op != O_constant
10921 || inst.reloc.exp.X_add_number != 0)
10922 narrow = FALSE;
10923
10924 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10925 relaxation, but it doesn't seem worth the hassle. */
10926 if (narrow)
10927 {
10928 inst.reloc.type = BFD_RELOC_UNUSED;
10929 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10930 inst.instruction |= Rs << 3;
10931 inst.instruction |= Rd;
10932 }
10933 else
10934 {
10935 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10936 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10937 }
c19d1205
ZW
10938 }
10939 else
10940 encode_thumb32_shifted_operand (2);
10941}
b99bd4ef 10942
c19d1205
ZW
10943static void
10944do_t_setend (void)
10945{
e07e6e58 10946 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10947 if (inst.operands[0].imm)
10948 inst.instruction |= 0x8;
10949}
b99bd4ef 10950
c19d1205
ZW
10951static void
10952do_t_shift (void)
10953{
10954 if (!inst.operands[1].present)
10955 inst.operands[1].reg = inst.operands[0].reg;
10956
10957 if (unified_syntax)
10958 {
3d388997
PB
10959 bfd_boolean narrow;
10960 int shift_kind;
10961
10962 switch (inst.instruction)
10963 {
10964 case T_MNEM_asr:
10965 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10966 case T_MNEM_lsl:
10967 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10968 case T_MNEM_lsr:
10969 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10970 case T_MNEM_ror:
10971 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10972 default: abort ();
10973 }
10974
10975 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10976 narrow = !in_it_block ();
3d388997 10977 else
e07e6e58 10978 narrow = in_it_block ();
3d388997
PB
10979 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10980 narrow = FALSE;
10981 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10982 narrow = FALSE;
10983 if (inst.operands[2].isreg
10984 && (inst.operands[1].reg != inst.operands[0].reg
10985 || inst.operands[2].reg > 7))
10986 narrow = FALSE;
10987 if (inst.size_req == 4)
10988 narrow = FALSE;
10989
fdfde340
JM
10990 reject_bad_reg (inst.operands[0].reg);
10991 reject_bad_reg (inst.operands[1].reg);
c921be7d 10992
3d388997 10993 if (!narrow)
c19d1205
ZW
10994 {
10995 if (inst.operands[2].isreg)
b99bd4ef 10996 {
fdfde340 10997 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10998 inst.instruction = THUMB_OP32 (inst.instruction);
10999 inst.instruction |= inst.operands[0].reg << 8;
11000 inst.instruction |= inst.operands[1].reg << 16;
11001 inst.instruction |= inst.operands[2].reg;
11002 }
11003 else
11004 {
11005 inst.operands[1].shifted = 1;
3d388997 11006 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
11007 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
11008 ? T_MNEM_movs : T_MNEM_mov);
11009 inst.instruction |= inst.operands[0].reg << 8;
11010 encode_thumb32_shifted_operand (1);
11011 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
11012 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
11013 }
11014 }
11015 else
11016 {
c19d1205 11017 if (inst.operands[2].isreg)
b99bd4ef 11018 {
3d388997 11019 switch (shift_kind)
b99bd4ef 11020 {
3d388997
PB
11021 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
11022 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
11023 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
11024 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 11025 default: abort ();
b99bd4ef 11026 }
5f4273c7 11027
c19d1205
ZW
11028 inst.instruction |= inst.operands[0].reg;
11029 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
11030 }
11031 else
11032 {
3d388997 11033 switch (shift_kind)
b99bd4ef 11034 {
3d388997
PB
11035 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
11036 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
11037 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 11038 default: abort ();
b99bd4ef 11039 }
c19d1205
ZW
11040 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11041 inst.instruction |= inst.operands[0].reg;
11042 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11043 }
11044 }
c19d1205
ZW
11045 }
11046 else
11047 {
11048 constraint (inst.operands[0].reg > 7
11049 || inst.operands[1].reg > 7, BAD_HIREG);
11050 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 11051
c19d1205
ZW
11052 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
11053 {
11054 constraint (inst.operands[2].reg > 7, BAD_HIREG);
11055 constraint (inst.operands[0].reg != inst.operands[1].reg,
11056 _("source1 and dest must be same register"));
b99bd4ef 11057
c19d1205
ZW
11058 switch (inst.instruction)
11059 {
11060 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
11061 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
11062 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
11063 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
11064 default: abort ();
11065 }
5f4273c7 11066
c19d1205
ZW
11067 inst.instruction |= inst.operands[0].reg;
11068 inst.instruction |= inst.operands[2].reg << 3;
11069 }
11070 else
b99bd4ef 11071 {
c19d1205
ZW
11072 switch (inst.instruction)
11073 {
11074 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
11075 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
11076 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
11077 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
11078 default: abort ();
11079 }
11080 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
11081 inst.instruction |= inst.operands[0].reg;
11082 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
11083 }
11084 }
b99bd4ef
NC
11085}
11086
11087static void
c19d1205 11088do_t_simd (void)
b99bd4ef 11089{
fdfde340
JM
11090 unsigned Rd, Rn, Rm;
11091
11092 Rd = inst.operands[0].reg;
11093 Rn = inst.operands[1].reg;
11094 Rm = inst.operands[2].reg;
11095
11096 reject_bad_reg (Rd);
11097 reject_bad_reg (Rn);
11098 reject_bad_reg (Rm);
11099
11100 inst.instruction |= Rd << 8;
11101 inst.instruction |= Rn << 16;
11102 inst.instruction |= Rm;
c19d1205 11103}
b99bd4ef 11104
c19d1205 11105static void
3eb17e6b 11106do_t_smc (void)
c19d1205
ZW
11107{
11108 unsigned int value = inst.reloc.exp.X_add_number;
11109 constraint (inst.reloc.exp.X_op != O_constant,
11110 _("expression too complex"));
11111 inst.reloc.type = BFD_RELOC_UNUSED;
11112 inst.instruction |= (value & 0xf000) >> 12;
11113 inst.instruction |= (value & 0x0ff0);
11114 inst.instruction |= (value & 0x000f) << 16;
11115}
b99bd4ef 11116
c19d1205 11117static void
3a21c15a 11118do_t_ssat_usat (int bias)
c19d1205 11119{
fdfde340
JM
11120 unsigned Rd, Rn;
11121
11122 Rd = inst.operands[0].reg;
11123 Rn = inst.operands[2].reg;
11124
11125 reject_bad_reg (Rd);
11126 reject_bad_reg (Rn);
11127
11128 inst.instruction |= Rd << 8;
3a21c15a 11129 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 11130 inst.instruction |= Rn << 16;
b99bd4ef 11131
c19d1205 11132 if (inst.operands[3].present)
b99bd4ef 11133 {
3a21c15a
NC
11134 offsetT shift_amount = inst.reloc.exp.X_add_number;
11135
11136 inst.reloc.type = BFD_RELOC_UNUSED;
11137
c19d1205
ZW
11138 constraint (inst.reloc.exp.X_op != O_constant,
11139 _("expression too complex"));
b99bd4ef 11140
3a21c15a 11141 if (shift_amount != 0)
6189168b 11142 {
3a21c15a
NC
11143 constraint (shift_amount > 31,
11144 _("shift expression is too large"));
11145
c19d1205 11146 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
11147 inst.instruction |= 0x00200000; /* sh bit. */
11148
11149 inst.instruction |= (shift_amount & 0x1c) << 10;
11150 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
11151 }
11152 }
b99bd4ef 11153}
c921be7d 11154
3a21c15a
NC
11155static void
11156do_t_ssat (void)
11157{
11158 do_t_ssat_usat (1);
11159}
b99bd4ef 11160
0dd132b6 11161static void
c19d1205 11162do_t_ssat16 (void)
0dd132b6 11163{
fdfde340
JM
11164 unsigned Rd, Rn;
11165
11166 Rd = inst.operands[0].reg;
11167 Rn = inst.operands[2].reg;
11168
11169 reject_bad_reg (Rd);
11170 reject_bad_reg (Rn);
11171
11172 inst.instruction |= Rd << 8;
c19d1205 11173 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 11174 inst.instruction |= Rn << 16;
c19d1205 11175}
0dd132b6 11176
c19d1205
ZW
11177static void
11178do_t_strex (void)
11179{
11180 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
11181 || inst.operands[2].postind || inst.operands[2].writeback
11182 || inst.operands[2].immisreg || inst.operands[2].shifted
11183 || inst.operands[2].negative,
01cfc07f 11184 BAD_ADDR_MODE);
0dd132b6 11185
c19d1205
ZW
11186 inst.instruction |= inst.operands[0].reg << 8;
11187 inst.instruction |= inst.operands[1].reg << 12;
11188 inst.instruction |= inst.operands[2].reg << 16;
11189 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
11190}
11191
b99bd4ef 11192static void
c19d1205 11193do_t_strexd (void)
b99bd4ef 11194{
c19d1205
ZW
11195 if (!inst.operands[2].present)
11196 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 11197
c19d1205
ZW
11198 constraint (inst.operands[0].reg == inst.operands[1].reg
11199 || inst.operands[0].reg == inst.operands[2].reg
11200 || inst.operands[0].reg == inst.operands[3].reg
11201 || inst.operands[1].reg == inst.operands[2].reg,
11202 BAD_OVERLAP);
b99bd4ef 11203
c19d1205
ZW
11204 inst.instruction |= inst.operands[0].reg;
11205 inst.instruction |= inst.operands[1].reg << 12;
11206 inst.instruction |= inst.operands[2].reg << 8;
11207 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
11208}
11209
11210static void
c19d1205 11211do_t_sxtah (void)
b99bd4ef 11212{
fdfde340
JM
11213 unsigned Rd, Rn, Rm;
11214
11215 Rd = inst.operands[0].reg;
11216 Rn = inst.operands[1].reg;
11217 Rm = inst.operands[2].reg;
11218
11219 reject_bad_reg (Rd);
11220 reject_bad_reg (Rn);
11221 reject_bad_reg (Rm);
11222
11223 inst.instruction |= Rd << 8;
11224 inst.instruction |= Rn << 16;
11225 inst.instruction |= Rm;
c19d1205
ZW
11226 inst.instruction |= inst.operands[3].imm << 4;
11227}
b99bd4ef 11228
c19d1205
ZW
11229static void
11230do_t_sxth (void)
11231{
fdfde340
JM
11232 unsigned Rd, Rm;
11233
11234 Rd = inst.operands[0].reg;
11235 Rm = inst.operands[1].reg;
11236
11237 reject_bad_reg (Rd);
11238 reject_bad_reg (Rm);
c921be7d
NC
11239
11240 if (inst.instruction <= 0xffff
11241 && inst.size_req != 4
fdfde340 11242 && Rd <= 7 && Rm <= 7
c19d1205 11243 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 11244 {
c19d1205 11245 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
11246 inst.instruction |= Rd;
11247 inst.instruction |= Rm << 3;
b99bd4ef 11248 }
c19d1205 11249 else if (unified_syntax)
b99bd4ef 11250 {
c19d1205
ZW
11251 if (inst.instruction <= 0xffff)
11252 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
11253 inst.instruction |= Rd << 8;
11254 inst.instruction |= Rm;
c19d1205 11255 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 11256 }
c19d1205 11257 else
b99bd4ef 11258 {
c19d1205
ZW
11259 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
11260 _("Thumb encoding does not support rotation"));
11261 constraint (1, BAD_HIREG);
b99bd4ef 11262 }
c19d1205 11263}
b99bd4ef 11264
c19d1205
ZW
11265static void
11266do_t_swi (void)
11267{
11268 inst.reloc.type = BFD_RELOC_ARM_SWI;
11269}
b99bd4ef 11270
92e90b6e
PB
11271static void
11272do_t_tb (void)
11273{
fdfde340 11274 unsigned Rn, Rm;
92e90b6e
PB
11275 int half;
11276
11277 half = (inst.instruction & 0x10) != 0;
e07e6e58 11278 set_it_insn_type_last ();
dfa9f0d5
PB
11279 constraint (inst.operands[0].immisreg,
11280 _("instruction requires register index"));
fdfde340
JM
11281
11282 Rn = inst.operands[0].reg;
11283 Rm = inst.operands[0].imm;
c921be7d 11284
fdfde340
JM
11285 constraint (Rn == REG_SP, BAD_SP);
11286 reject_bad_reg (Rm);
11287
92e90b6e
PB
11288 constraint (!half && inst.operands[0].shifted,
11289 _("instruction does not allow shifted index"));
fdfde340 11290 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11291}
11292
c19d1205
ZW
11293static void
11294do_t_usat (void)
11295{
3a21c15a 11296 do_t_ssat_usat (0);
b99bd4ef
NC
11297}
11298
11299static void
c19d1205 11300do_t_usat16 (void)
b99bd4ef 11301{
fdfde340
JM
11302 unsigned Rd, Rn;
11303
11304 Rd = inst.operands[0].reg;
11305 Rn = inst.operands[2].reg;
11306
11307 reject_bad_reg (Rd);
11308 reject_bad_reg (Rn);
11309
11310 inst.instruction |= Rd << 8;
c19d1205 11311 inst.instruction |= inst.operands[1].imm;
fdfde340 11312 inst.instruction |= Rn << 16;
b99bd4ef 11313}
c19d1205 11314
5287ad62 11315/* Neon instruction encoder helpers. */
5f4273c7 11316
5287ad62 11317/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11318
5287ad62
JB
11319/* An "invalid" code for the following tables. */
11320#define N_INV -1u
11321
11322struct neon_tab_entry
b99bd4ef 11323{
5287ad62
JB
11324 unsigned integer;
11325 unsigned float_or_poly;
11326 unsigned scalar_or_imm;
11327};
5f4273c7 11328
5287ad62
JB
11329/* Map overloaded Neon opcodes to their respective encodings. */
11330#define NEON_ENC_TAB \
11331 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11332 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11333 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11334 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11335 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11336 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11337 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11338 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11339 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11340 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11341 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11342 /* Register variants of the following two instructions are encoded as
e07e6e58 11343 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11344 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11345 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
62f3b8c8
PB
11346 X(vfma, N_INV, 0x0000c10, N_INV), \
11347 X(vfms, N_INV, 0x0200c10, N_INV), \
5287ad62
JB
11348 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11349 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11350 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11351 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11352 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11353 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11354 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11355 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11356 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11357 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11358 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11359 X(vshl, 0x0000400, N_INV, 0x0800510), \
11360 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11361 X(vand, 0x0000110, N_INV, 0x0800030), \
11362 X(vbic, 0x0100110, N_INV, 0x0800030), \
11363 X(veor, 0x1000110, N_INV, N_INV), \
11364 X(vorn, 0x0300110, N_INV, 0x0800010), \
11365 X(vorr, 0x0200110, N_INV, 0x0800010), \
11366 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11367 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11368 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11369 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11370 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11371 X(vst1, 0x0000000, 0x0800000, N_INV), \
11372 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11373 X(vst2, 0x0000100, 0x0800100, N_INV), \
11374 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11375 X(vst3, 0x0000200, 0x0800200, N_INV), \
11376 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11377 X(vst4, 0x0000300, 0x0800300, N_INV), \
11378 X(vmovn, 0x1b20200, N_INV, N_INV), \
11379 X(vtrn, 0x1b20080, N_INV, N_INV), \
11380 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11381 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11382 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
e6655fda
PB
11383 X(vnmla, 0xe100a40, 0xe100b40, N_INV), \
11384 X(vnmls, 0xe100a00, 0xe100b00, N_INV), \
62f3b8c8
PB
11385 X(vfnma, 0xe900a40, 0xe900b40, N_INV), \
11386 X(vfnms, 0xe900a00, 0xe900b00, N_INV), \
037e8744
JB
11387 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11388 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11389 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11390 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11391
11392enum neon_opc
11393{
11394#define X(OPC,I,F,S) N_MNEM_##OPC
11395NEON_ENC_TAB
11396#undef X
11397};
b99bd4ef 11398
5287ad62
JB
11399static const struct neon_tab_entry neon_enc_tab[] =
11400{
11401#define X(OPC,I,F,S) { (I), (F), (S) }
11402NEON_ENC_TAB
11403#undef X
11404};
b99bd4ef 11405
5287ad62
JB
11406#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11407#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11408#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11409#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11410#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11411#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11412#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11413#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11414#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
11415#define NEON_ENC_SINGLE(X) \
11416 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11417#define NEON_ENC_DOUBLE(X) \
11418 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11419
037e8744
JB
11420/* Define shapes for instruction operands. The following mnemonic characters
11421 are used in this table:
5287ad62 11422
037e8744 11423 F - VFP S<n> register
5287ad62
JB
11424 D - Neon D<n> register
11425 Q - Neon Q<n> register
11426 I - Immediate
11427 S - Scalar
11428 R - ARM register
11429 L - D<n> register list
5f4273c7 11430
037e8744
JB
11431 This table is used to generate various data:
11432 - enumerations of the form NS_DDR to be used as arguments to
11433 neon_select_shape.
11434 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11435 - a table used to drive neon_select_shape. */
b99bd4ef 11436
037e8744
JB
11437#define NEON_SHAPE_DEF \
11438 X(3, (D, D, D), DOUBLE), \
11439 X(3, (Q, Q, Q), QUAD), \
11440 X(3, (D, D, I), DOUBLE), \
11441 X(3, (Q, Q, I), QUAD), \
11442 X(3, (D, D, S), DOUBLE), \
11443 X(3, (Q, Q, S), QUAD), \
11444 X(2, (D, D), DOUBLE), \
11445 X(2, (Q, Q), QUAD), \
11446 X(2, (D, S), DOUBLE), \
11447 X(2, (Q, S), QUAD), \
11448 X(2, (D, R), DOUBLE), \
11449 X(2, (Q, R), QUAD), \
11450 X(2, (D, I), DOUBLE), \
11451 X(2, (Q, I), QUAD), \
11452 X(3, (D, L, D), DOUBLE), \
11453 X(2, (D, Q), MIXED), \
11454 X(2, (Q, D), MIXED), \
11455 X(3, (D, Q, I), MIXED), \
11456 X(3, (Q, D, I), MIXED), \
11457 X(3, (Q, D, D), MIXED), \
11458 X(3, (D, Q, Q), MIXED), \
11459 X(3, (Q, Q, D), MIXED), \
11460 X(3, (Q, D, S), MIXED), \
11461 X(3, (D, Q, S), MIXED), \
11462 X(4, (D, D, D, I), DOUBLE), \
11463 X(4, (Q, Q, Q, I), QUAD), \
11464 X(2, (F, F), SINGLE), \
11465 X(3, (F, F, F), SINGLE), \
11466 X(2, (F, I), SINGLE), \
11467 X(2, (F, D), MIXED), \
11468 X(2, (D, F), MIXED), \
11469 X(3, (F, F, I), MIXED), \
11470 X(4, (R, R, F, F), SINGLE), \
11471 X(4, (F, F, R, R), SINGLE), \
11472 X(3, (D, R, R), DOUBLE), \
11473 X(3, (R, R, D), DOUBLE), \
11474 X(2, (S, R), SINGLE), \
11475 X(2, (R, S), SINGLE), \
11476 X(2, (F, R), SINGLE), \
11477 X(2, (R, F), SINGLE)
11478
11479#define S2(A,B) NS_##A##B
11480#define S3(A,B,C) NS_##A##B##C
11481#define S4(A,B,C,D) NS_##A##B##C##D
11482
11483#define X(N, L, C) S##N L
11484
5287ad62
JB
11485enum neon_shape
11486{
037e8744
JB
11487 NEON_SHAPE_DEF,
11488 NS_NULL
5287ad62 11489};
b99bd4ef 11490
037e8744
JB
11491#undef X
11492#undef S2
11493#undef S3
11494#undef S4
11495
11496enum neon_shape_class
11497{
11498 SC_SINGLE,
11499 SC_DOUBLE,
11500 SC_QUAD,
11501 SC_MIXED
11502};
11503
11504#define X(N, L, C) SC_##C
11505
11506static enum neon_shape_class neon_shape_class[] =
11507{
11508 NEON_SHAPE_DEF
11509};
11510
11511#undef X
11512
11513enum neon_shape_el
11514{
11515 SE_F,
11516 SE_D,
11517 SE_Q,
11518 SE_I,
11519 SE_S,
11520 SE_R,
11521 SE_L
11522};
11523
11524/* Register widths of above. */
11525static unsigned neon_shape_el_size[] =
11526{
11527 32,
11528 64,
11529 128,
11530 0,
11531 32,
11532 32,
11533 0
11534};
11535
11536struct neon_shape_info
11537{
11538 unsigned els;
11539 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11540};
11541
11542#define S2(A,B) { SE_##A, SE_##B }
11543#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11544#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11545
11546#define X(N, L, C) { N, S##N L }
11547
11548static struct neon_shape_info neon_shape_tab[] =
11549{
11550 NEON_SHAPE_DEF
11551};
11552
11553#undef X
11554#undef S2
11555#undef S3
11556#undef S4
11557
5287ad62
JB
11558/* Bit masks used in type checking given instructions.
11559 'N_EQK' means the type must be the same as (or based on in some way) the key
11560 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11561 set, various other bits can be set as well in order to modify the meaning of
11562 the type constraint. */
11563
11564enum neon_type_mask
11565{
8e79c3df
CM
11566 N_S8 = 0x0000001,
11567 N_S16 = 0x0000002,
11568 N_S32 = 0x0000004,
11569 N_S64 = 0x0000008,
11570 N_U8 = 0x0000010,
11571 N_U16 = 0x0000020,
11572 N_U32 = 0x0000040,
11573 N_U64 = 0x0000080,
11574 N_I8 = 0x0000100,
11575 N_I16 = 0x0000200,
11576 N_I32 = 0x0000400,
11577 N_I64 = 0x0000800,
11578 N_8 = 0x0001000,
11579 N_16 = 0x0002000,
11580 N_32 = 0x0004000,
11581 N_64 = 0x0008000,
11582 N_P8 = 0x0010000,
11583 N_P16 = 0x0020000,
11584 N_F16 = 0x0040000,
11585 N_F32 = 0x0080000,
11586 N_F64 = 0x0100000,
c921be7d
NC
11587 N_KEY = 0x1000000, /* Key element (main type specifier). */
11588 N_EQK = 0x2000000, /* Given operand has the same type & size as the key. */
8e79c3df 11589 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
c921be7d
NC
11590 N_DBL = 0x0000001, /* If N_EQK, this operand is twice the size. */
11591 N_HLF = 0x0000002, /* If N_EQK, this operand is half the size. */
11592 N_SGN = 0x0000004, /* If N_EQK, this operand is forced to be signed. */
11593 N_UNS = 0x0000008, /* If N_EQK, this operand is forced to be unsigned. */
11594 N_INT = 0x0000010, /* If N_EQK, this operand is forced to be integer. */
11595 N_FLT = 0x0000020, /* If N_EQK, this operand is forced to be float. */
11596 N_SIZ = 0x0000040, /* If N_EQK, this operand is forced to be size-only. */
5287ad62 11597 N_UTYP = 0,
037e8744 11598 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11599};
11600
dcbf9037
JB
11601#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11602
5287ad62
JB
11603#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11604#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11605#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11606#define N_SUF_32 (N_SU_32 | N_F32)
11607#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11608#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11609
11610/* Pass this as the first type argument to neon_check_type to ignore types
11611 altogether. */
11612#define N_IGNORE_TYPE (N_KEY | N_EQK)
11613
037e8744
JB
11614/* Select a "shape" for the current instruction (describing register types or
11615 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11616 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11617 function of operand parsing, so this function doesn't need to be called.
11618 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11619
11620static enum neon_shape
037e8744 11621neon_select_shape (enum neon_shape shape, ...)
5287ad62 11622{
037e8744
JB
11623 va_list ap;
11624 enum neon_shape first_shape = shape;
5287ad62
JB
11625
11626 /* Fix missing optional operands. FIXME: we don't know at this point how
11627 many arguments we should have, so this makes the assumption that we have
11628 > 1. This is true of all current Neon opcodes, I think, but may not be
11629 true in the future. */
11630 if (!inst.operands[1].present)
11631 inst.operands[1] = inst.operands[0];
11632
037e8744 11633 va_start (ap, shape);
5f4273c7 11634
21d799b5 11635 for (; shape != NS_NULL; shape = (enum neon_shape) va_arg (ap, int))
037e8744
JB
11636 {
11637 unsigned j;
11638 int matches = 1;
11639
11640 for (j = 0; j < neon_shape_tab[shape].els; j++)
11641 {
11642 if (!inst.operands[j].present)
11643 {
11644 matches = 0;
11645 break;
11646 }
11647
11648 switch (neon_shape_tab[shape].el[j])
11649 {
11650 case SE_F:
11651 if (!(inst.operands[j].isreg
11652 && inst.operands[j].isvec
11653 && inst.operands[j].issingle
11654 && !inst.operands[j].isquad))
11655 matches = 0;
11656 break;
11657
11658 case SE_D:
11659 if (!(inst.operands[j].isreg
11660 && inst.operands[j].isvec
11661 && !inst.operands[j].isquad
11662 && !inst.operands[j].issingle))
11663 matches = 0;
11664 break;
11665
11666 case SE_R:
11667 if (!(inst.operands[j].isreg
11668 && !inst.operands[j].isvec))
11669 matches = 0;
11670 break;
11671
11672 case SE_Q:
11673 if (!(inst.operands[j].isreg
11674 && inst.operands[j].isvec
11675 && inst.operands[j].isquad
11676 && !inst.operands[j].issingle))
11677 matches = 0;
11678 break;
11679
11680 case SE_I:
11681 if (!(!inst.operands[j].isreg
11682 && !inst.operands[j].isscalar))
11683 matches = 0;
11684 break;
11685
11686 case SE_S:
11687 if (!(!inst.operands[j].isreg
11688 && inst.operands[j].isscalar))
11689 matches = 0;
11690 break;
11691
11692 case SE_L:
11693 break;
11694 }
11695 }
11696 if (matches)
5287ad62 11697 break;
037e8744 11698 }
5f4273c7 11699
037e8744 11700 va_end (ap);
5287ad62 11701
037e8744
JB
11702 if (shape == NS_NULL && first_shape != NS_NULL)
11703 first_error (_("invalid instruction shape"));
5287ad62 11704
037e8744
JB
11705 return shape;
11706}
5287ad62 11707
037e8744
JB
11708/* True if SHAPE is predominantly a quadword operation (most of the time, this
11709 means the Q bit should be set). */
11710
11711static int
11712neon_quad (enum neon_shape shape)
11713{
11714 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11715}
037e8744 11716
5287ad62
JB
11717static void
11718neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11719 unsigned *g_size)
11720{
11721 /* Allow modification to be made to types which are constrained to be
11722 based on the key element, based on bits set alongside N_EQK. */
11723 if ((typebits & N_EQK) != 0)
11724 {
11725 if ((typebits & N_HLF) != 0)
11726 *g_size /= 2;
11727 else if ((typebits & N_DBL) != 0)
11728 *g_size *= 2;
11729 if ((typebits & N_SGN) != 0)
11730 *g_type = NT_signed;
11731 else if ((typebits & N_UNS) != 0)
11732 *g_type = NT_unsigned;
11733 else if ((typebits & N_INT) != 0)
11734 *g_type = NT_integer;
11735 else if ((typebits & N_FLT) != 0)
11736 *g_type = NT_float;
dcbf9037
JB
11737 else if ((typebits & N_SIZ) != 0)
11738 *g_type = NT_untyped;
5287ad62
JB
11739 }
11740}
5f4273c7 11741
5287ad62
JB
11742/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11743 operand type, i.e. the single type specified in a Neon instruction when it
11744 is the only one given. */
11745
11746static struct neon_type_el
11747neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11748{
11749 struct neon_type_el dest = *key;
5f4273c7 11750
9c2799c2 11751 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11752
5287ad62
JB
11753 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11754
11755 return dest;
11756}
11757
11758/* Convert Neon type and size into compact bitmask representation. */
11759
11760static enum neon_type_mask
11761type_chk_of_el_type (enum neon_el_type type, unsigned size)
11762{
11763 switch (type)
11764 {
11765 case NT_untyped:
11766 switch (size)
11767 {
11768 case 8: return N_8;
11769 case 16: return N_16;
11770 case 32: return N_32;
11771 case 64: return N_64;
11772 default: ;
11773 }
11774 break;
11775
11776 case NT_integer:
11777 switch (size)
11778 {
11779 case 8: return N_I8;
11780 case 16: return N_I16;
11781 case 32: return N_I32;
11782 case 64: return N_I64;
11783 default: ;
11784 }
11785 break;
11786
11787 case NT_float:
037e8744
JB
11788 switch (size)
11789 {
8e79c3df 11790 case 16: return N_F16;
037e8744
JB
11791 case 32: return N_F32;
11792 case 64: return N_F64;
11793 default: ;
11794 }
5287ad62
JB
11795 break;
11796
11797 case NT_poly:
11798 switch (size)
11799 {
11800 case 8: return N_P8;
11801 case 16: return N_P16;
11802 default: ;
11803 }
11804 break;
11805
11806 case NT_signed:
11807 switch (size)
11808 {
11809 case 8: return N_S8;
11810 case 16: return N_S16;
11811 case 32: return N_S32;
11812 case 64: return N_S64;
11813 default: ;
11814 }
11815 break;
11816
11817 case NT_unsigned:
11818 switch (size)
11819 {
11820 case 8: return N_U8;
11821 case 16: return N_U16;
11822 case 32: return N_U32;
11823 case 64: return N_U64;
11824 default: ;
11825 }
11826 break;
11827
11828 default: ;
11829 }
5f4273c7 11830
5287ad62
JB
11831 return N_UTYP;
11832}
11833
11834/* Convert compact Neon bitmask type representation to a type and size. Only
11835 handles the case where a single bit is set in the mask. */
11836
dcbf9037 11837static int
5287ad62
JB
11838el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11839 enum neon_type_mask mask)
11840{
dcbf9037
JB
11841 if ((mask & N_EQK) != 0)
11842 return FAIL;
11843
5287ad62
JB
11844 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11845 *size = 8;
dcbf9037 11846 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11847 *size = 16;
dcbf9037 11848 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11849 *size = 32;
037e8744 11850 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11851 *size = 64;
dcbf9037
JB
11852 else
11853 return FAIL;
11854
5287ad62
JB
11855 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11856 *type = NT_signed;
dcbf9037 11857 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11858 *type = NT_unsigned;
dcbf9037 11859 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11860 *type = NT_integer;
dcbf9037 11861 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11862 *type = NT_untyped;
dcbf9037 11863 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11864 *type = NT_poly;
037e8744 11865 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11866 *type = NT_float;
dcbf9037
JB
11867 else
11868 return FAIL;
5f4273c7 11869
dcbf9037 11870 return SUCCESS;
5287ad62
JB
11871}
11872
11873/* Modify a bitmask of allowed types. This is only needed for type
11874 relaxation. */
11875
11876static unsigned
11877modify_types_allowed (unsigned allowed, unsigned mods)
11878{
11879 unsigned size;
11880 enum neon_el_type type;
11881 unsigned destmask;
11882 int i;
5f4273c7 11883
5287ad62 11884 destmask = 0;
5f4273c7 11885
5287ad62
JB
11886 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11887 {
21d799b5
NC
11888 if (el_type_of_type_chk (&type, &size,
11889 (enum neon_type_mask) (allowed & i)) == SUCCESS)
dcbf9037
JB
11890 {
11891 neon_modify_type_size (mods, &type, &size);
11892 destmask |= type_chk_of_el_type (type, size);
11893 }
5287ad62 11894 }
5f4273c7 11895
5287ad62
JB
11896 return destmask;
11897}
11898
11899/* Check type and return type classification.
11900 The manual states (paraphrase): If one datatype is given, it indicates the
11901 type given in:
11902 - the second operand, if there is one
11903 - the operand, if there is no second operand
11904 - the result, if there are no operands.
11905 This isn't quite good enough though, so we use a concept of a "key" datatype
11906 which is set on a per-instruction basis, which is the one which matters when
11907 only one data type is written.
11908 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11909 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11910
11911static struct neon_type_el
11912neon_check_type (unsigned els, enum neon_shape ns, ...)
11913{
11914 va_list ap;
11915 unsigned i, pass, key_el = 0;
11916 unsigned types[NEON_MAX_TYPE_ELS];
11917 enum neon_el_type k_type = NT_invtype;
11918 unsigned k_size = -1u;
11919 struct neon_type_el badtype = {NT_invtype, -1};
11920 unsigned key_allowed = 0;
11921
11922 /* Optional registers in Neon instructions are always (not) in operand 1.
11923 Fill in the missing operand here, if it was omitted. */
11924 if (els > 1 && !inst.operands[1].present)
11925 inst.operands[1] = inst.operands[0];
11926
11927 /* Suck up all the varargs. */
11928 va_start (ap, ns);
11929 for (i = 0; i < els; i++)
11930 {
11931 unsigned thisarg = va_arg (ap, unsigned);
11932 if (thisarg == N_IGNORE_TYPE)
11933 {
11934 va_end (ap);
11935 return badtype;
11936 }
11937 types[i] = thisarg;
11938 if ((thisarg & N_KEY) != 0)
11939 key_el = i;
11940 }
11941 va_end (ap);
11942
dcbf9037
JB
11943 if (inst.vectype.elems > 0)
11944 for (i = 0; i < els; i++)
11945 if (inst.operands[i].vectype.type != NT_invtype)
11946 {
11947 first_error (_("types specified in both the mnemonic and operands"));
11948 return badtype;
11949 }
11950
5287ad62
JB
11951 /* Duplicate inst.vectype elements here as necessary.
11952 FIXME: No idea if this is exactly the same as the ARM assembler,
11953 particularly when an insn takes one register and one non-register
11954 operand. */
11955 if (inst.vectype.elems == 1 && els > 1)
11956 {
11957 unsigned j;
11958 inst.vectype.elems = els;
11959 inst.vectype.el[key_el] = inst.vectype.el[0];
11960 for (j = 0; j < els; j++)
dcbf9037
JB
11961 if (j != key_el)
11962 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11963 types[j]);
11964 }
11965 else if (inst.vectype.elems == 0 && els > 0)
11966 {
11967 unsigned j;
11968 /* No types were given after the mnemonic, so look for types specified
11969 after each operand. We allow some flexibility here; as long as the
11970 "key" operand has a type, we can infer the others. */
11971 for (j = 0; j < els; j++)
11972 if (inst.operands[j].vectype.type != NT_invtype)
11973 inst.vectype.el[j] = inst.operands[j].vectype;
11974
11975 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11976 {
dcbf9037
JB
11977 for (j = 0; j < els; j++)
11978 if (inst.operands[j].vectype.type == NT_invtype)
11979 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11980 types[j]);
11981 }
11982 else
11983 {
11984 first_error (_("operand types can't be inferred"));
11985 return badtype;
5287ad62
JB
11986 }
11987 }
11988 else if (inst.vectype.elems != els)
11989 {
dcbf9037 11990 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11991 return badtype;
11992 }
11993
11994 for (pass = 0; pass < 2; pass++)
11995 {
11996 for (i = 0; i < els; i++)
11997 {
11998 unsigned thisarg = types[i];
11999 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
12000 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
12001 enum neon_el_type g_type = inst.vectype.el[i].type;
12002 unsigned g_size = inst.vectype.el[i].size;
12003
12004 /* Decay more-specific signed & unsigned types to sign-insensitive
12005 integer types if sign-specific variants are unavailable. */
12006 if ((g_type == NT_signed || g_type == NT_unsigned)
12007 && (types_allowed & N_SU_ALL) == 0)
12008 g_type = NT_integer;
12009
12010 /* If only untyped args are allowed, decay any more specific types to
12011 them. Some instructions only care about signs for some element
12012 sizes, so handle that properly. */
12013 if ((g_size == 8 && (types_allowed & N_8) != 0)
12014 || (g_size == 16 && (types_allowed & N_16) != 0)
12015 || (g_size == 32 && (types_allowed & N_32) != 0)
12016 || (g_size == 64 && (types_allowed & N_64) != 0))
12017 g_type = NT_untyped;
12018
12019 if (pass == 0)
12020 {
12021 if ((thisarg & N_KEY) != 0)
12022 {
12023 k_type = g_type;
12024 k_size = g_size;
12025 key_allowed = thisarg & ~N_KEY;
12026 }
12027 }
12028 else
12029 {
037e8744
JB
12030 if ((thisarg & N_VFP) != 0)
12031 {
12032 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
12033 unsigned regwidth = neon_shape_el_size[regshape], match;
12034
12035 /* In VFP mode, operands must match register widths. If we
12036 have a key operand, use its width, else use the width of
12037 the current operand. */
12038 if (k_size != -1u)
12039 match = k_size;
12040 else
12041 match = g_size;
12042
12043 if (regwidth != match)
12044 {
12045 first_error (_("operand size must match register width"));
12046 return badtype;
12047 }
12048 }
5f4273c7 12049
5287ad62
JB
12050 if ((thisarg & N_EQK) == 0)
12051 {
12052 unsigned given_type = type_chk_of_el_type (g_type, g_size);
12053
12054 if ((given_type & types_allowed) == 0)
12055 {
dcbf9037 12056 first_error (_("bad type in Neon instruction"));
5287ad62
JB
12057 return badtype;
12058 }
12059 }
12060 else
12061 {
12062 enum neon_el_type mod_k_type = k_type;
12063 unsigned mod_k_size = k_size;
12064 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
12065 if (g_type != mod_k_type || g_size != mod_k_size)
12066 {
dcbf9037 12067 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
12068 return badtype;
12069 }
12070 }
12071 }
12072 }
12073 }
12074
12075 return inst.vectype.el[key_el];
12076}
12077
037e8744 12078/* Neon-style VFP instruction forwarding. */
5287ad62 12079
037e8744
JB
12080/* Thumb VFP instructions have 0xE in the condition field. */
12081
12082static void
12083do_vfp_cond_or_thumb (void)
5287ad62
JB
12084{
12085 if (thumb_mode)
037e8744 12086 inst.instruction |= 0xe0000000;
5287ad62 12087 else
037e8744 12088 inst.instruction |= inst.cond << 28;
5287ad62
JB
12089}
12090
037e8744
JB
12091/* Look up and encode a simple mnemonic, for use as a helper function for the
12092 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
12093 etc. It is assumed that operand parsing has already been done, and that the
12094 operands are in the form expected by the given opcode (this isn't necessarily
12095 the same as the form in which they were parsed, hence some massaging must
12096 take place before this function is called).
12097 Checks current arch version against that in the looked-up opcode. */
5287ad62 12098
037e8744
JB
12099static void
12100do_vfp_nsyn_opcode (const char *opname)
5287ad62 12101{
037e8744 12102 const struct asm_opcode *opcode;
5f4273c7 12103
21d799b5 12104 opcode = (const struct asm_opcode *) hash_find (arm_ops_hsh, opname);
5287ad62 12105
037e8744
JB
12106 if (!opcode)
12107 abort ();
5287ad62 12108
037e8744
JB
12109 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
12110 thumb_mode ? *opcode->tvariant : *opcode->avariant),
12111 _(BAD_FPU));
5287ad62 12112
037e8744
JB
12113 if (thumb_mode)
12114 {
12115 inst.instruction = opcode->tvalue;
12116 opcode->tencode ();
12117 }
12118 else
12119 {
12120 inst.instruction = (inst.cond << 28) | opcode->avalue;
12121 opcode->aencode ();
12122 }
12123}
5287ad62
JB
12124
12125static void
037e8744 12126do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 12127{
037e8744
JB
12128 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
12129
12130 if (rs == NS_FFF)
12131 {
12132 if (is_add)
12133 do_vfp_nsyn_opcode ("fadds");
12134 else
12135 do_vfp_nsyn_opcode ("fsubs");
12136 }
12137 else
12138 {
12139 if (is_add)
12140 do_vfp_nsyn_opcode ("faddd");
12141 else
12142 do_vfp_nsyn_opcode ("fsubd");
12143 }
12144}
12145
12146/* Check operand types to see if this is a VFP instruction, and if so call
12147 PFN (). */
12148
12149static int
12150try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
12151{
12152 enum neon_shape rs;
12153 struct neon_type_el et;
12154
12155 switch (args)
12156 {
12157 case 2:
12158 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12159 et = neon_check_type (2, rs,
12160 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12161 break;
5f4273c7 12162
037e8744
JB
12163 case 3:
12164 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12165 et = neon_check_type (3, rs,
12166 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
12167 break;
12168
12169 default:
12170 abort ();
12171 }
12172
12173 if (et.type != NT_invtype)
12174 {
12175 pfn (rs);
12176 return SUCCESS;
12177 }
12178 else
12179 inst.error = NULL;
12180
12181 return FAIL;
12182}
12183
12184static void
12185do_vfp_nsyn_mla_mls (enum neon_shape rs)
12186{
12187 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 12188
037e8744
JB
12189 if (rs == NS_FFF)
12190 {
12191 if (is_mla)
12192 do_vfp_nsyn_opcode ("fmacs");
12193 else
1ee69515 12194 do_vfp_nsyn_opcode ("fnmacs");
037e8744
JB
12195 }
12196 else
12197 {
12198 if (is_mla)
12199 do_vfp_nsyn_opcode ("fmacd");
12200 else
1ee69515 12201 do_vfp_nsyn_opcode ("fnmacd");
037e8744
JB
12202 }
12203}
12204
62f3b8c8
PB
12205static void
12206do_vfp_nsyn_fma_fms (enum neon_shape rs)
12207{
12208 int is_fma = (inst.instruction & 0x0fffffff) == N_MNEM_vfma;
12209
12210 if (rs == NS_FFF)
12211 {
12212 if (is_fma)
12213 do_vfp_nsyn_opcode ("ffmas");
12214 else
12215 do_vfp_nsyn_opcode ("ffnmas");
12216 }
12217 else
12218 {
12219 if (is_fma)
12220 do_vfp_nsyn_opcode ("ffmad");
12221 else
12222 do_vfp_nsyn_opcode ("ffnmad");
12223 }
12224}
12225
037e8744
JB
12226static void
12227do_vfp_nsyn_mul (enum neon_shape rs)
12228{
12229 if (rs == NS_FFF)
12230 do_vfp_nsyn_opcode ("fmuls");
12231 else
12232 do_vfp_nsyn_opcode ("fmuld");
12233}
12234
12235static void
12236do_vfp_nsyn_abs_neg (enum neon_shape rs)
12237{
12238 int is_neg = (inst.instruction & 0x80) != 0;
12239 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
12240
12241 if (rs == NS_FF)
12242 {
12243 if (is_neg)
12244 do_vfp_nsyn_opcode ("fnegs");
12245 else
12246 do_vfp_nsyn_opcode ("fabss");
12247 }
12248 else
12249 {
12250 if (is_neg)
12251 do_vfp_nsyn_opcode ("fnegd");
12252 else
12253 do_vfp_nsyn_opcode ("fabsd");
12254 }
12255}
12256
12257/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
12258 insns belong to Neon, and are handled elsewhere. */
12259
12260static void
12261do_vfp_nsyn_ldm_stm (int is_dbmode)
12262{
12263 int is_ldm = (inst.instruction & (1 << 20)) != 0;
12264 if (is_ldm)
12265 {
12266 if (is_dbmode)
12267 do_vfp_nsyn_opcode ("fldmdbs");
12268 else
12269 do_vfp_nsyn_opcode ("fldmias");
12270 }
12271 else
12272 {
12273 if (is_dbmode)
12274 do_vfp_nsyn_opcode ("fstmdbs");
12275 else
12276 do_vfp_nsyn_opcode ("fstmias");
12277 }
12278}
12279
037e8744
JB
12280static void
12281do_vfp_nsyn_sqrt (void)
12282{
12283 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12284 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12285
037e8744
JB
12286 if (rs == NS_FF)
12287 do_vfp_nsyn_opcode ("fsqrts");
12288 else
12289 do_vfp_nsyn_opcode ("fsqrtd");
12290}
12291
12292static void
12293do_vfp_nsyn_div (void)
12294{
12295 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12296 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12297 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12298
037e8744
JB
12299 if (rs == NS_FFF)
12300 do_vfp_nsyn_opcode ("fdivs");
12301 else
12302 do_vfp_nsyn_opcode ("fdivd");
12303}
12304
12305static void
12306do_vfp_nsyn_nmul (void)
12307{
12308 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
12309 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
12310 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12311
037e8744
JB
12312 if (rs == NS_FFF)
12313 {
12314 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12315 do_vfp_sp_dyadic ();
12316 }
12317 else
12318 {
12319 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12320 do_vfp_dp_rd_rn_rm ();
12321 }
12322 do_vfp_cond_or_thumb ();
12323}
12324
12325static void
12326do_vfp_nsyn_cmp (void)
12327{
12328 if (inst.operands[1].isreg)
12329 {
12330 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12331 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12332
037e8744
JB
12333 if (rs == NS_FF)
12334 {
12335 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12336 do_vfp_sp_monadic ();
12337 }
12338 else
12339 {
12340 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12341 do_vfp_dp_rd_rm ();
12342 }
12343 }
12344 else
12345 {
12346 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12347 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12348
12349 switch (inst.instruction & 0x0fffffff)
12350 {
12351 case N_MNEM_vcmp:
12352 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12353 break;
12354 case N_MNEM_vcmpe:
12355 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12356 break;
12357 default:
12358 abort ();
12359 }
5f4273c7 12360
037e8744
JB
12361 if (rs == NS_FI)
12362 {
12363 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12364 do_vfp_sp_compare_z ();
12365 }
12366 else
12367 {
12368 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12369 do_vfp_dp_rd ();
12370 }
12371 }
12372 do_vfp_cond_or_thumb ();
12373}
12374
12375static void
12376nsyn_insert_sp (void)
12377{
12378 inst.operands[1] = inst.operands[0];
12379 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12380 inst.operands[0].reg = REG_SP;
037e8744
JB
12381 inst.operands[0].isreg = 1;
12382 inst.operands[0].writeback = 1;
12383 inst.operands[0].present = 1;
12384}
12385
12386static void
12387do_vfp_nsyn_push (void)
12388{
12389 nsyn_insert_sp ();
12390 if (inst.operands[1].issingle)
12391 do_vfp_nsyn_opcode ("fstmdbs");
12392 else
12393 do_vfp_nsyn_opcode ("fstmdbd");
12394}
12395
12396static void
12397do_vfp_nsyn_pop (void)
12398{
12399 nsyn_insert_sp ();
12400 if (inst.operands[1].issingle)
22b5b651 12401 do_vfp_nsyn_opcode ("fldmias");
037e8744 12402 else
22b5b651 12403 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12404}
12405
12406/* Fix up Neon data-processing instructions, ORing in the correct bits for
12407 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12408
12409static unsigned
12410neon_dp_fixup (unsigned i)
12411{
12412 if (thumb_mode)
12413 {
12414 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12415 if (i & (1 << 24))
12416 i |= 1 << 28;
5f4273c7 12417
037e8744 12418 i &= ~(1 << 24);
5f4273c7 12419
037e8744
JB
12420 i |= 0xef000000;
12421 }
12422 else
12423 i |= 0xf2000000;
5f4273c7 12424
037e8744
JB
12425 return i;
12426}
12427
12428/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12429 (0, 1, 2, 3). */
12430
12431static unsigned
12432neon_logbits (unsigned x)
12433{
12434 return ffs (x) - 4;
12435}
12436
12437#define LOW4(R) ((R) & 0xf)
12438#define HI1(R) (((R) >> 4) & 1)
12439
12440/* Encode insns with bit pattern:
12441
12442 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12443 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12444
037e8744
JB
12445 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12446 different meaning for some instruction. */
12447
12448static void
12449neon_three_same (int isquad, int ubit, int size)
12450{
12451 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12452 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12453 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12454 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12455 inst.instruction |= LOW4 (inst.operands[2].reg);
12456 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12457 inst.instruction |= (isquad != 0) << 6;
12458 inst.instruction |= (ubit != 0) << 24;
12459 if (size != -1)
12460 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12461
037e8744
JB
12462 inst.instruction = neon_dp_fixup (inst.instruction);
12463}
12464
12465/* Encode instructions of the form:
12466
12467 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12468 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12469
12470 Don't write size if SIZE == -1. */
12471
12472static void
12473neon_two_same (int qbit, int ubit, int size)
12474{
12475 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12476 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12477 inst.instruction |= LOW4 (inst.operands[1].reg);
12478 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12479 inst.instruction |= (qbit != 0) << 6;
12480 inst.instruction |= (ubit != 0) << 24;
12481
12482 if (size != -1)
12483 inst.instruction |= neon_logbits (size) << 18;
12484
12485 inst.instruction = neon_dp_fixup (inst.instruction);
12486}
12487
12488/* Neon instruction encoders, in approximate order of appearance. */
12489
12490static void
12491do_neon_dyadic_i_su (void)
12492{
037e8744 12493 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12494 struct neon_type_el et = neon_check_type (3, rs,
12495 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12496 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12497}
12498
12499static void
12500do_neon_dyadic_i64_su (void)
12501{
037e8744 12502 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12503 struct neon_type_el et = neon_check_type (3, rs,
12504 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12505 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12506}
12507
12508static void
12509neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12510 unsigned immbits)
12511{
12512 unsigned size = et.size >> 3;
12513 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12514 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12515 inst.instruction |= LOW4 (inst.operands[1].reg);
12516 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12517 inst.instruction |= (isquad != 0) << 6;
12518 inst.instruction |= immbits << 16;
12519 inst.instruction |= (size >> 3) << 7;
12520 inst.instruction |= (size & 0x7) << 19;
12521 if (write_ubit)
12522 inst.instruction |= (uval != 0) << 24;
12523
12524 inst.instruction = neon_dp_fixup (inst.instruction);
12525}
12526
12527static void
12528do_neon_shl_imm (void)
12529{
12530 if (!inst.operands[2].isreg)
12531 {
037e8744 12532 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12533 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12534 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12535 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12536 }
12537 else
12538 {
037e8744 12539 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12540 struct neon_type_el et = neon_check_type (3, rs,
12541 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12542 unsigned int tmp;
12543
12544 /* VSHL/VQSHL 3-register variants have syntax such as:
12545 vshl.xx Dd, Dm, Dn
12546 whereas other 3-register operations encoded by neon_three_same have
12547 syntax like:
12548 vadd.xx Dd, Dn, Dm
12549 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12550 here. */
12551 tmp = inst.operands[2].reg;
12552 inst.operands[2].reg = inst.operands[1].reg;
12553 inst.operands[1].reg = tmp;
5287ad62 12554 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12555 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12556 }
12557}
12558
12559static void
12560do_neon_qshl_imm (void)
12561{
12562 if (!inst.operands[2].isreg)
12563 {
037e8744 12564 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12565 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12566
5287ad62 12567 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12568 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12569 inst.operands[2].imm);
12570 }
12571 else
12572 {
037e8744 12573 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12574 struct neon_type_el et = neon_check_type (3, rs,
12575 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12576 unsigned int tmp;
12577
12578 /* See note in do_neon_shl_imm. */
12579 tmp = inst.operands[2].reg;
12580 inst.operands[2].reg = inst.operands[1].reg;
12581 inst.operands[1].reg = tmp;
5287ad62 12582 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12583 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12584 }
12585}
12586
627907b7
JB
12587static void
12588do_neon_rshl (void)
12589{
12590 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12591 struct neon_type_el et = neon_check_type (3, rs,
12592 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12593 unsigned int tmp;
12594
12595 tmp = inst.operands[2].reg;
12596 inst.operands[2].reg = inst.operands[1].reg;
12597 inst.operands[1].reg = tmp;
12598 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12599}
12600
5287ad62
JB
12601static int
12602neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12603{
036dc3f7
PB
12604 /* Handle .I8 pseudo-instructions. */
12605 if (size == 8)
5287ad62 12606 {
5287ad62
JB
12607 /* Unfortunately, this will make everything apart from zero out-of-range.
12608 FIXME is this the intended semantics? There doesn't seem much point in
12609 accepting .I8 if so. */
12610 immediate |= immediate << 8;
12611 size = 16;
036dc3f7
PB
12612 }
12613
12614 if (size >= 32)
12615 {
12616 if (immediate == (immediate & 0x000000ff))
12617 {
12618 *immbits = immediate;
12619 return 0x1;
12620 }
12621 else if (immediate == (immediate & 0x0000ff00))
12622 {
12623 *immbits = immediate >> 8;
12624 return 0x3;
12625 }
12626 else if (immediate == (immediate & 0x00ff0000))
12627 {
12628 *immbits = immediate >> 16;
12629 return 0x5;
12630 }
12631 else if (immediate == (immediate & 0xff000000))
12632 {
12633 *immbits = immediate >> 24;
12634 return 0x7;
12635 }
12636 if ((immediate & 0xffff) != (immediate >> 16))
12637 goto bad_immediate;
12638 immediate &= 0xffff;
5287ad62
JB
12639 }
12640
12641 if (immediate == (immediate & 0x000000ff))
12642 {
12643 *immbits = immediate;
036dc3f7 12644 return 0x9;
5287ad62
JB
12645 }
12646 else if (immediate == (immediate & 0x0000ff00))
12647 {
12648 *immbits = immediate >> 8;
036dc3f7 12649 return 0xb;
5287ad62
JB
12650 }
12651
12652 bad_immediate:
dcbf9037 12653 first_error (_("immediate value out of range"));
5287ad62
JB
12654 return FAIL;
12655}
12656
12657/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12658 A, B, C, D. */
12659
12660static int
12661neon_bits_same_in_bytes (unsigned imm)
12662{
12663 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12664 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12665 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12666 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12667}
12668
12669/* For immediate of above form, return 0bABCD. */
12670
12671static unsigned
12672neon_squash_bits (unsigned imm)
12673{
12674 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12675 | ((imm & 0x01000000) >> 21);
12676}
12677
136da414 12678/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12679
12680static unsigned
12681neon_qfloat_bits (unsigned imm)
12682{
136da414 12683 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12684}
12685
12686/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12687 the instruction. *OP is passed as the initial value of the op field, and
12688 may be set to a different value depending on the constant (i.e.
12689 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12690 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12691 try smaller element sizes. */
5287ad62
JB
12692
12693static int
c96612cc
JB
12694neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12695 unsigned *immbits, int *op, int size,
12696 enum neon_el_type type)
5287ad62 12697{
c96612cc
JB
12698 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12699 float. */
12700 if (type == NT_float && !float_p)
12701 return FAIL;
12702
136da414
JB
12703 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12704 {
12705 if (size != 32 || *op == 1)
12706 return FAIL;
12707 *immbits = neon_qfloat_bits (immlo);
12708 return 0xf;
12709 }
036dc3f7
PB
12710
12711 if (size == 64)
5287ad62 12712 {
036dc3f7
PB
12713 if (neon_bits_same_in_bytes (immhi)
12714 && neon_bits_same_in_bytes (immlo))
12715 {
12716 if (*op == 1)
12717 return FAIL;
12718 *immbits = (neon_squash_bits (immhi) << 4)
12719 | neon_squash_bits (immlo);
12720 *op = 1;
12721 return 0xe;
12722 }
12723
12724 if (immhi != immlo)
12725 return FAIL;
5287ad62 12726 }
036dc3f7
PB
12727
12728 if (size >= 32)
5287ad62 12729 {
036dc3f7
PB
12730 if (immlo == (immlo & 0x000000ff))
12731 {
12732 *immbits = immlo;
12733 return 0x0;
12734 }
12735 else if (immlo == (immlo & 0x0000ff00))
12736 {
12737 *immbits = immlo >> 8;
12738 return 0x2;
12739 }
12740 else if (immlo == (immlo & 0x00ff0000))
12741 {
12742 *immbits = immlo >> 16;
12743 return 0x4;
12744 }
12745 else if (immlo == (immlo & 0xff000000))
12746 {
12747 *immbits = immlo >> 24;
12748 return 0x6;
12749 }
12750 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12751 {
12752 *immbits = (immlo >> 8) & 0xff;
12753 return 0xc;
12754 }
12755 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12756 {
12757 *immbits = (immlo >> 16) & 0xff;
12758 return 0xd;
12759 }
12760
12761 if ((immlo & 0xffff) != (immlo >> 16))
12762 return FAIL;
12763 immlo &= 0xffff;
5287ad62 12764 }
036dc3f7
PB
12765
12766 if (size >= 16)
5287ad62 12767 {
036dc3f7
PB
12768 if (immlo == (immlo & 0x000000ff))
12769 {
12770 *immbits = immlo;
12771 return 0x8;
12772 }
12773 else if (immlo == (immlo & 0x0000ff00))
12774 {
12775 *immbits = immlo >> 8;
12776 return 0xa;
12777 }
12778
12779 if ((immlo & 0xff) != (immlo >> 8))
12780 return FAIL;
12781 immlo &= 0xff;
5287ad62 12782 }
036dc3f7
PB
12783
12784 if (immlo == (immlo & 0x000000ff))
5287ad62 12785 {
036dc3f7
PB
12786 /* Don't allow MVN with 8-bit immediate. */
12787 if (*op == 1)
12788 return FAIL;
12789 *immbits = immlo;
12790 return 0xe;
5287ad62 12791 }
5287ad62
JB
12792
12793 return FAIL;
12794}
12795
12796/* Write immediate bits [7:0] to the following locations:
12797
12798 |28/24|23 19|18 16|15 4|3 0|
12799 | 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|
12800
12801 This function is used by VMOV/VMVN/VORR/VBIC. */
12802
12803static void
12804neon_write_immbits (unsigned immbits)
12805{
12806 inst.instruction |= immbits & 0xf;
12807 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12808 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12809}
12810
12811/* Invert low-order SIZE bits of XHI:XLO. */
12812
12813static void
12814neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12815{
12816 unsigned immlo = xlo ? *xlo : 0;
12817 unsigned immhi = xhi ? *xhi : 0;
12818
12819 switch (size)
12820 {
12821 case 8:
12822 immlo = (~immlo) & 0xff;
12823 break;
12824
12825 case 16:
12826 immlo = (~immlo) & 0xffff;
12827 break;
12828
12829 case 64:
12830 immhi = (~immhi) & 0xffffffff;
12831 /* fall through. */
12832
12833 case 32:
12834 immlo = (~immlo) & 0xffffffff;
12835 break;
12836
12837 default:
12838 abort ();
12839 }
12840
12841 if (xlo)
12842 *xlo = immlo;
12843
12844 if (xhi)
12845 *xhi = immhi;
12846}
12847
12848static void
12849do_neon_logic (void)
12850{
12851 if (inst.operands[2].present && inst.operands[2].isreg)
12852 {
037e8744 12853 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12854 neon_check_type (3, rs, N_IGNORE_TYPE);
12855 /* U bit and size field were set as part of the bitmask. */
12856 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12857 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12858 }
12859 else
12860 {
037e8744
JB
12861 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12862 struct neon_type_el et = neon_check_type (2, rs,
12863 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
21d799b5 12864 enum neon_opc opcode = (enum neon_opc) inst.instruction & 0x0fffffff;
5287ad62
JB
12865 unsigned immbits;
12866 int cmode;
5f4273c7 12867
5287ad62
JB
12868 if (et.type == NT_invtype)
12869 return;
5f4273c7 12870
5287ad62
JB
12871 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12872
036dc3f7
PB
12873 immbits = inst.operands[1].imm;
12874 if (et.size == 64)
12875 {
12876 /* .i64 is a pseudo-op, so the immediate must be a repeating
12877 pattern. */
12878 if (immbits != (inst.operands[1].regisimm ?
12879 inst.operands[1].reg : 0))
12880 {
12881 /* Set immbits to an invalid constant. */
12882 immbits = 0xdeadbeef;
12883 }
12884 }
12885
5287ad62
JB
12886 switch (opcode)
12887 {
12888 case N_MNEM_vbic:
036dc3f7 12889 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12890 break;
5f4273c7 12891
5287ad62 12892 case N_MNEM_vorr:
036dc3f7 12893 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12894 break;
5f4273c7 12895
5287ad62
JB
12896 case N_MNEM_vand:
12897 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12898 neon_invert_size (&immbits, 0, et.size);
12899 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12900 break;
5f4273c7 12901
5287ad62
JB
12902 case N_MNEM_vorn:
12903 /* Pseudo-instruction for VORR. */
5287ad62
JB
12904 neon_invert_size (&immbits, 0, et.size);
12905 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12906 break;
5f4273c7 12907
5287ad62
JB
12908 default:
12909 abort ();
12910 }
12911
12912 if (cmode == FAIL)
12913 return;
12914
037e8744 12915 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12916 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12917 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12918 inst.instruction |= cmode << 8;
12919 neon_write_immbits (immbits);
5f4273c7 12920
5287ad62
JB
12921 inst.instruction = neon_dp_fixup (inst.instruction);
12922 }
12923}
12924
12925static void
12926do_neon_bitfield (void)
12927{
037e8744 12928 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12929 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12930 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12931}
12932
12933static void
dcbf9037
JB
12934neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12935 unsigned destbits)
5287ad62 12936{
037e8744 12937 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12938 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12939 types | N_KEY);
5287ad62
JB
12940 if (et.type == NT_float)
12941 {
12942 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12943 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12944 }
12945 else
12946 {
12947 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12948 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12949 }
12950}
12951
12952static void
12953do_neon_dyadic_if_su (void)
12954{
dcbf9037 12955 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12956}
12957
12958static void
12959do_neon_dyadic_if_su_d (void)
12960{
12961 /* This version only allow D registers, but that constraint is enforced during
12962 operand parsing so we don't need to do anything extra here. */
dcbf9037 12963 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12964}
12965
5287ad62
JB
12966static void
12967do_neon_dyadic_if_i_d (void)
12968{
428e3f1f
PB
12969 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12970 affected if we specify unsigned args. */
12971 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12972}
12973
037e8744
JB
12974enum vfp_or_neon_is_neon_bits
12975{
12976 NEON_CHECK_CC = 1,
12977 NEON_CHECK_ARCH = 2
12978};
12979
12980/* Call this function if an instruction which may have belonged to the VFP or
12981 Neon instruction sets, but turned out to be a Neon instruction (due to the
12982 operand types involved, etc.). We have to check and/or fix-up a couple of
12983 things:
12984
12985 - Make sure the user hasn't attempted to make a Neon instruction
12986 conditional.
12987 - Alter the value in the condition code field if necessary.
12988 - Make sure that the arch supports Neon instructions.
12989
12990 Which of these operations take place depends on bits from enum
12991 vfp_or_neon_is_neon_bits.
12992
12993 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12994 current instruction's condition is COND_ALWAYS, the condition field is
12995 changed to inst.uncond_value. This is necessary because instructions shared
12996 between VFP and Neon may be conditional for the VFP variants only, and the
12997 unconditional Neon version must have, e.g., 0xF in the condition field. */
12998
12999static int
13000vfp_or_neon_is_neon (unsigned check)
13001{
13002 /* Conditions are always legal in Thumb mode (IT blocks). */
13003 if (!thumb_mode && (check & NEON_CHECK_CC))
13004 {
13005 if (inst.cond != COND_ALWAYS)
13006 {
13007 first_error (_(BAD_COND));
13008 return FAIL;
13009 }
13010 if (inst.uncond_value != -1)
13011 inst.instruction |= inst.uncond_value << 28;
13012 }
5f4273c7 13013
037e8744
JB
13014 if ((check & NEON_CHECK_ARCH)
13015 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
13016 {
13017 first_error (_(BAD_FPU));
13018 return FAIL;
13019 }
5f4273c7 13020
037e8744
JB
13021 return SUCCESS;
13022}
13023
5287ad62
JB
13024static void
13025do_neon_addsub_if_i (void)
13026{
037e8744
JB
13027 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
13028 return;
13029
13030 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13031 return;
13032
5287ad62
JB
13033 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13034 affected if we specify unsigned args. */
dcbf9037 13035 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
13036}
13037
13038/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
13039 result to be:
13040 V<op> A,B (A is operand 0, B is operand 2)
13041 to mean:
13042 V<op> A,B,A
13043 not:
13044 V<op> A,B,B
13045 so handle that case specially. */
13046
13047static void
13048neon_exchange_operands (void)
13049{
13050 void *scratch = alloca (sizeof (inst.operands[0]));
13051 if (inst.operands[1].present)
13052 {
13053 /* Swap operands[1] and operands[2]. */
13054 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
13055 inst.operands[1] = inst.operands[2];
13056 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
13057 }
13058 else
13059 {
13060 inst.operands[1] = inst.operands[2];
13061 inst.operands[2] = inst.operands[0];
13062 }
13063}
13064
13065static void
13066neon_compare (unsigned regtypes, unsigned immtypes, int invert)
13067{
13068 if (inst.operands[2].isreg)
13069 {
13070 if (invert)
13071 neon_exchange_operands ();
dcbf9037 13072 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
13073 }
13074 else
13075 {
037e8744 13076 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
13077 struct neon_type_el et = neon_check_type (2, rs,
13078 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
13079
13080 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13081 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13082 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13083 inst.instruction |= LOW4 (inst.operands[1].reg);
13084 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13085 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13086 inst.instruction |= (et.type == NT_float) << 10;
13087 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13088
5287ad62
JB
13089 inst.instruction = neon_dp_fixup (inst.instruction);
13090 }
13091}
13092
13093static void
13094do_neon_cmp (void)
13095{
13096 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
13097}
13098
13099static void
13100do_neon_cmp_inv (void)
13101{
13102 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
13103}
13104
13105static void
13106do_neon_ceq (void)
13107{
13108 neon_compare (N_IF_32, N_IF_32, FALSE);
13109}
13110
13111/* For multiply instructions, we have the possibility of 16-bit or 32-bit
13112 scalars, which are encoded in 5 bits, M : Rm.
13113 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
13114 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
13115 index in M. */
13116
13117static unsigned
13118neon_scalar_for_mul (unsigned scalar, unsigned elsize)
13119{
dcbf9037
JB
13120 unsigned regno = NEON_SCALAR_REG (scalar);
13121 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
13122
13123 switch (elsize)
13124 {
13125 case 16:
13126 if (regno > 7 || elno > 3)
13127 goto bad_scalar;
13128 return regno | (elno << 3);
5f4273c7 13129
5287ad62
JB
13130 case 32:
13131 if (regno > 15 || elno > 1)
13132 goto bad_scalar;
13133 return regno | (elno << 4);
13134
13135 default:
13136 bad_scalar:
dcbf9037 13137 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
13138 }
13139
13140 return 0;
13141}
13142
13143/* Encode multiply / multiply-accumulate scalar instructions. */
13144
13145static void
13146neon_mul_mac (struct neon_type_el et, int ubit)
13147{
dcbf9037
JB
13148 unsigned scalar;
13149
13150 /* Give a more helpful error message if we have an invalid type. */
13151 if (et.type == NT_invtype)
13152 return;
5f4273c7 13153
dcbf9037 13154 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
13155 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13156 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13157 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13158 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13159 inst.instruction |= LOW4 (scalar);
13160 inst.instruction |= HI1 (scalar) << 5;
13161 inst.instruction |= (et.type == NT_float) << 8;
13162 inst.instruction |= neon_logbits (et.size) << 20;
13163 inst.instruction |= (ubit != 0) << 24;
13164
13165 inst.instruction = neon_dp_fixup (inst.instruction);
13166}
13167
13168static void
13169do_neon_mac_maybe_scalar (void)
13170{
037e8744
JB
13171 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
13172 return;
13173
13174 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13175 return;
13176
5287ad62
JB
13177 if (inst.operands[2].isscalar)
13178 {
037e8744 13179 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13180 struct neon_type_el et = neon_check_type (3, rs,
13181 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
13182 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 13183 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13184 }
13185 else
428e3f1f
PB
13186 {
13187 /* The "untyped" case can't happen. Do this to stop the "U" bit being
13188 affected if we specify unsigned args. */
13189 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13190 }
5287ad62
JB
13191}
13192
62f3b8c8
PB
13193static void
13194do_neon_fmac (void)
13195{
13196 if (try_vfp_nsyn (3, do_vfp_nsyn_fma_fms) == SUCCESS)
13197 return;
13198
13199 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13200 return;
13201
13202 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
13203}
13204
5287ad62
JB
13205static void
13206do_neon_tst (void)
13207{
037e8744 13208 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13209 struct neon_type_el et = neon_check_type (3, rs,
13210 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 13211 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13212}
13213
13214/* VMUL with 3 registers allows the P8 type. The scalar version supports the
13215 same types as the MAC equivalents. The polynomial type for this instruction
13216 is encoded the same as the integer type. */
13217
13218static void
13219do_neon_mul (void)
13220{
037e8744
JB
13221 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
13222 return;
13223
13224 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13225 return;
13226
5287ad62
JB
13227 if (inst.operands[2].isscalar)
13228 do_neon_mac_maybe_scalar ();
13229 else
dcbf9037 13230 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
13231}
13232
13233static void
13234do_neon_qdmulh (void)
13235{
13236 if (inst.operands[2].isscalar)
13237 {
037e8744 13238 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
13239 struct neon_type_el et = neon_check_type (3, rs,
13240 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13241 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 13242 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
13243 }
13244 else
13245 {
037e8744 13246 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13247 struct neon_type_el et = neon_check_type (3, rs,
13248 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
13249 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13250 /* The U bit (rounding) comes from bit mask. */
037e8744 13251 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
13252 }
13253}
13254
13255static void
13256do_neon_fcmp_absolute (void)
13257{
037e8744 13258 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
13259 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
13260 /* Size field comes from bit mask. */
037e8744 13261 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
13262}
13263
13264static void
13265do_neon_fcmp_absolute_inv (void)
13266{
13267 neon_exchange_operands ();
13268 do_neon_fcmp_absolute ();
13269}
13270
13271static void
13272do_neon_step (void)
13273{
037e8744 13274 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 13275 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 13276 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
13277}
13278
13279static void
13280do_neon_abs_neg (void)
13281{
037e8744
JB
13282 enum neon_shape rs;
13283 struct neon_type_el et;
5f4273c7 13284
037e8744
JB
13285 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
13286 return;
13287
13288 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13289 return;
13290
13291 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
13292 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 13293
5287ad62
JB
13294 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13295 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13296 inst.instruction |= LOW4 (inst.operands[1].reg);
13297 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13298 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13299 inst.instruction |= (et.type == NT_float) << 10;
13300 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13301
5287ad62
JB
13302 inst.instruction = neon_dp_fixup (inst.instruction);
13303}
13304
13305static void
13306do_neon_sli (void)
13307{
037e8744 13308 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13309 struct neon_type_el et = neon_check_type (2, rs,
13310 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13311 int imm = inst.operands[2].imm;
13312 constraint (imm < 0 || (unsigned)imm >= et.size,
13313 _("immediate out of range for insert"));
037e8744 13314 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13315}
13316
13317static void
13318do_neon_sri (void)
13319{
037e8744 13320 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13321 struct neon_type_el et = neon_check_type (2, rs,
13322 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13323 int imm = inst.operands[2].imm;
13324 constraint (imm < 1 || (unsigned)imm > et.size,
13325 _("immediate out of range for insert"));
037e8744 13326 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
13327}
13328
13329static void
13330do_neon_qshlu_imm (void)
13331{
037e8744 13332 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13333 struct neon_type_el et = neon_check_type (2, rs,
13334 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13335 int imm = inst.operands[2].imm;
13336 constraint (imm < 0 || (unsigned)imm >= et.size,
13337 _("immediate out of range for shift"));
13338 /* Only encodes the 'U present' variant of the instruction.
13339 In this case, signed types have OP (bit 8) set to 0.
13340 Unsigned types have OP set to 1. */
13341 inst.instruction |= (et.type == NT_unsigned) << 8;
13342 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13343 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13344}
13345
13346static void
13347do_neon_qmovn (void)
13348{
13349 struct neon_type_el et = neon_check_type (2, NS_DQ,
13350 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13351 /* Saturating move where operands can be signed or unsigned, and the
13352 destination has the same signedness. */
13353 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13354 if (et.type == NT_unsigned)
13355 inst.instruction |= 0xc0;
13356 else
13357 inst.instruction |= 0x80;
13358 neon_two_same (0, 1, et.size / 2);
13359}
13360
13361static void
13362do_neon_qmovun (void)
13363{
13364 struct neon_type_el et = neon_check_type (2, NS_DQ,
13365 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13366 /* Saturating move with unsigned results. Operands must be signed. */
13367 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13368 neon_two_same (0, 1, et.size / 2);
13369}
13370
13371static void
13372do_neon_rshift_sat_narrow (void)
13373{
13374 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13375 or unsigned. If operands are unsigned, results must also be unsigned. */
13376 struct neon_type_el et = neon_check_type (2, NS_DQI,
13377 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13378 int imm = inst.operands[2].imm;
13379 /* This gets the bounds check, size encoding and immediate bits calculation
13380 right. */
13381 et.size /= 2;
5f4273c7 13382
5287ad62
JB
13383 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13384 VQMOVN.I<size> <Dd>, <Qm>. */
13385 if (imm == 0)
13386 {
13387 inst.operands[2].present = 0;
13388 inst.instruction = N_MNEM_vqmovn;
13389 do_neon_qmovn ();
13390 return;
13391 }
5f4273c7 13392
5287ad62
JB
13393 constraint (imm < 1 || (unsigned)imm > et.size,
13394 _("immediate out of range"));
13395 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13396}
13397
13398static void
13399do_neon_rshift_sat_narrow_u (void)
13400{
13401 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13402 or unsigned. If operands are unsigned, results must also be unsigned. */
13403 struct neon_type_el et = neon_check_type (2, NS_DQI,
13404 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13405 int imm = inst.operands[2].imm;
13406 /* This gets the bounds check, size encoding and immediate bits calculation
13407 right. */
13408 et.size /= 2;
13409
13410 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13411 VQMOVUN.I<size> <Dd>, <Qm>. */
13412 if (imm == 0)
13413 {
13414 inst.operands[2].present = 0;
13415 inst.instruction = N_MNEM_vqmovun;
13416 do_neon_qmovun ();
13417 return;
13418 }
13419
13420 constraint (imm < 1 || (unsigned)imm > et.size,
13421 _("immediate out of range"));
13422 /* FIXME: The manual is kind of unclear about what value U should have in
13423 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13424 must be 1. */
13425 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13426}
13427
13428static void
13429do_neon_movn (void)
13430{
13431 struct neon_type_el et = neon_check_type (2, NS_DQ,
13432 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13433 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13434 neon_two_same (0, 1, et.size / 2);
13435}
13436
13437static void
13438do_neon_rshift_narrow (void)
13439{
13440 struct neon_type_el et = neon_check_type (2, NS_DQI,
13441 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13442 int imm = inst.operands[2].imm;
13443 /* This gets the bounds check, size encoding and immediate bits calculation
13444 right. */
13445 et.size /= 2;
5f4273c7 13446
5287ad62
JB
13447 /* If immediate is zero then we are a pseudo-instruction for
13448 VMOVN.I<size> <Dd>, <Qm> */
13449 if (imm == 0)
13450 {
13451 inst.operands[2].present = 0;
13452 inst.instruction = N_MNEM_vmovn;
13453 do_neon_movn ();
13454 return;
13455 }
5f4273c7 13456
5287ad62
JB
13457 constraint (imm < 1 || (unsigned)imm > et.size,
13458 _("immediate out of range for narrowing operation"));
13459 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13460}
13461
13462static void
13463do_neon_shll (void)
13464{
13465 /* FIXME: Type checking when lengthening. */
13466 struct neon_type_el et = neon_check_type (2, NS_QDI,
13467 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13468 unsigned imm = inst.operands[2].imm;
13469
13470 if (imm == et.size)
13471 {
13472 /* Maximum shift variant. */
13473 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13474 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13475 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13476 inst.instruction |= LOW4 (inst.operands[1].reg);
13477 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13478 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13479
5287ad62
JB
13480 inst.instruction = neon_dp_fixup (inst.instruction);
13481 }
13482 else
13483 {
13484 /* A more-specific type check for non-max versions. */
13485 et = neon_check_type (2, NS_QDI,
13486 N_EQK | N_DBL, N_SU_32 | N_KEY);
13487 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13488 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13489 }
13490}
13491
037e8744 13492/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13493 the current instruction is. */
13494
13495static int
13496neon_cvt_flavour (enum neon_shape rs)
13497{
037e8744
JB
13498#define CVT_VAR(C,X,Y) \
13499 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13500 if (et.type != NT_invtype) \
13501 { \
13502 inst.error = NULL; \
13503 return (C); \
5287ad62
JB
13504 }
13505 struct neon_type_el et;
037e8744
JB
13506 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13507 || rs == NS_FF) ? N_VFP : 0;
13508 /* The instruction versions which take an immediate take one register
13509 argument, which is extended to the width of the full register. Thus the
13510 "source" and "destination" registers must have the same width. Hack that
13511 here by making the size equal to the key (wider, in this case) operand. */
13512 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13513
5287ad62
JB
13514 CVT_VAR (0, N_S32, N_F32);
13515 CVT_VAR (1, N_U32, N_F32);
13516 CVT_VAR (2, N_F32, N_S32);
13517 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13518 /* Half-precision conversions. */
13519 CVT_VAR (4, N_F32, N_F16);
13520 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13521
037e8744 13522 whole_reg = N_VFP;
5f4273c7 13523
037e8744 13524 /* VFP instructions. */
8e79c3df
CM
13525 CVT_VAR (6, N_F32, N_F64);
13526 CVT_VAR (7, N_F64, N_F32);
13527 CVT_VAR (8, N_S32, N_F64 | key);
13528 CVT_VAR (9, N_U32, N_F64 | key);
13529 CVT_VAR (10, N_F64 | key, N_S32);
13530 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13531 /* VFP instructions with bitshift. */
8e79c3df
CM
13532 CVT_VAR (12, N_F32 | key, N_S16);
13533 CVT_VAR (13, N_F32 | key, N_U16);
13534 CVT_VAR (14, N_F64 | key, N_S16);
13535 CVT_VAR (15, N_F64 | key, N_U16);
13536 CVT_VAR (16, N_S16, N_F32 | key);
13537 CVT_VAR (17, N_U16, N_F32 | key);
13538 CVT_VAR (18, N_S16, N_F64 | key);
13539 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13540
5287ad62
JB
13541 return -1;
13542#undef CVT_VAR
13543}
13544
037e8744
JB
13545/* Neon-syntax VFP conversions. */
13546
5287ad62 13547static void
037e8744 13548do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13549{
037e8744 13550 const char *opname = 0;
5f4273c7 13551
037e8744 13552 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13553 {
037e8744
JB
13554 /* Conversions with immediate bitshift. */
13555 const char *enc[] =
13556 {
13557 "ftosls",
13558 "ftouls",
13559 "fsltos",
13560 "fultos",
13561 NULL,
13562 NULL,
8e79c3df
CM
13563 NULL,
13564 NULL,
037e8744
JB
13565 "ftosld",
13566 "ftould",
13567 "fsltod",
13568 "fultod",
13569 "fshtos",
13570 "fuhtos",
13571 "fshtod",
13572 "fuhtod",
13573 "ftoshs",
13574 "ftouhs",
13575 "ftoshd",
13576 "ftouhd"
13577 };
13578
13579 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13580 {
13581 opname = enc[flavour];
13582 constraint (inst.operands[0].reg != inst.operands[1].reg,
13583 _("operands 0 and 1 must be the same register"));
13584 inst.operands[1] = inst.operands[2];
13585 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13586 }
5287ad62
JB
13587 }
13588 else
13589 {
037e8744
JB
13590 /* Conversions without bitshift. */
13591 const char *enc[] =
13592 {
13593 "ftosis",
13594 "ftouis",
13595 "fsitos",
13596 "fuitos",
8e79c3df
CM
13597 "NULL",
13598 "NULL",
037e8744
JB
13599 "fcvtsd",
13600 "fcvtds",
13601 "ftosid",
13602 "ftouid",
13603 "fsitod",
13604 "fuitod"
13605 };
13606
13607 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13608 opname = enc[flavour];
13609 }
13610
13611 if (opname)
13612 do_vfp_nsyn_opcode (opname);
13613}
13614
13615static void
13616do_vfp_nsyn_cvtz (void)
13617{
13618 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13619 int flavour = neon_cvt_flavour (rs);
13620 const char *enc[] =
13621 {
13622 "ftosizs",
13623 "ftouizs",
13624 NULL,
13625 NULL,
13626 NULL,
13627 NULL,
8e79c3df
CM
13628 NULL,
13629 NULL,
037e8744
JB
13630 "ftosizd",
13631 "ftouizd"
13632 };
13633
13634 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13635 do_vfp_nsyn_opcode (enc[flavour]);
13636}
f31fef98 13637
037e8744
JB
13638static void
13639do_neon_cvt (void)
13640{
13641 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13642 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13643 int flavour = neon_cvt_flavour (rs);
13644
13645 /* VFP rather than Neon conversions. */
8e79c3df 13646 if (flavour >= 6)
037e8744
JB
13647 {
13648 do_vfp_nsyn_cvt (rs, flavour);
13649 return;
13650 }
13651
13652 switch (rs)
13653 {
13654 case NS_DDI:
13655 case NS_QQI:
13656 {
35997600
NC
13657 unsigned immbits;
13658 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13659
037e8744
JB
13660 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13661 return;
13662
13663 /* Fixed-point conversion with #0 immediate is encoded as an
13664 integer conversion. */
13665 if (inst.operands[2].present && inst.operands[2].imm == 0)
13666 goto int_encode;
35997600 13667 immbits = 32 - inst.operands[2].imm;
037e8744
JB
13668 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13669 if (flavour != -1)
13670 inst.instruction |= enctab[flavour];
13671 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13672 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13673 inst.instruction |= LOW4 (inst.operands[1].reg);
13674 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13675 inst.instruction |= neon_quad (rs) << 6;
13676 inst.instruction |= 1 << 21;
13677 inst.instruction |= immbits << 16;
13678
13679 inst.instruction = neon_dp_fixup (inst.instruction);
13680 }
13681 break;
13682
13683 case NS_DD:
13684 case NS_QQ:
13685 int_encode:
13686 {
13687 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13688
13689 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13690
13691 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13692 return;
13693
13694 if (flavour != -1)
13695 inst.instruction |= enctab[flavour];
13696
13697 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13698 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13699 inst.instruction |= LOW4 (inst.operands[1].reg);
13700 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13701 inst.instruction |= neon_quad (rs) << 6;
13702 inst.instruction |= 2 << 18;
13703
13704 inst.instruction = neon_dp_fixup (inst.instruction);
13705 }
13706 break;
13707
8e79c3df
CM
13708 /* Half-precision conversions for Advanced SIMD -- neon. */
13709 case NS_QD:
13710 case NS_DQ:
13711
13712 if ((rs == NS_DQ)
13713 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13714 {
13715 as_bad (_("operand size must match register width"));
13716 break;
13717 }
13718
13719 if ((rs == NS_QD)
13720 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13721 {
13722 as_bad (_("operand size must match register width"));
13723 break;
13724 }
13725
13726 if (rs == NS_DQ)
13727 inst.instruction = 0x3b60600;
13728 else
13729 inst.instruction = 0x3b60700;
13730
13731 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13732 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13733 inst.instruction |= LOW4 (inst.operands[1].reg);
13734 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13735 inst.instruction = neon_dp_fixup (inst.instruction);
13736 break;
13737
037e8744
JB
13738 default:
13739 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13740 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13741 }
5287ad62
JB
13742}
13743
8e79c3df
CM
13744static void
13745do_neon_cvtb (void)
13746{
13747 inst.instruction = 0xeb20a40;
13748
13749 /* The sizes are attached to the mnemonic. */
13750 if (inst.vectype.el[0].type != NT_invtype
13751 && inst.vectype.el[0].size == 16)
13752 inst.instruction |= 0x00010000;
13753
13754 /* Programmer's syntax: the sizes are attached to the operands. */
13755 else if (inst.operands[0].vectype.type != NT_invtype
13756 && inst.operands[0].vectype.size == 16)
13757 inst.instruction |= 0x00010000;
13758
13759 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13760 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13761 do_vfp_cond_or_thumb ();
13762}
13763
13764
13765static void
13766do_neon_cvtt (void)
13767{
13768 do_neon_cvtb ();
13769 inst.instruction |= 0x80;
13770}
13771
5287ad62
JB
13772static void
13773neon_move_immediate (void)
13774{
037e8744
JB
13775 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13776 struct neon_type_el et = neon_check_type (2, rs,
13777 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13778 unsigned immlo, immhi = 0, immbits;
c96612cc 13779 int op, cmode, float_p;
5287ad62 13780
037e8744
JB
13781 constraint (et.type == NT_invtype,
13782 _("operand size must be specified for immediate VMOV"));
13783
5287ad62
JB
13784 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13785 op = (inst.instruction & (1 << 5)) != 0;
13786
13787 immlo = inst.operands[1].imm;
13788 if (inst.operands[1].regisimm)
13789 immhi = inst.operands[1].reg;
13790
13791 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13792 _("immediate has bits set outside the operand size"));
13793
c96612cc
JB
13794 float_p = inst.operands[1].immisfloat;
13795
13796 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13797 et.size, et.type)) == FAIL)
5287ad62
JB
13798 {
13799 /* Invert relevant bits only. */
13800 neon_invert_size (&immlo, &immhi, et.size);
13801 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13802 with one or the other; those cases are caught by
13803 neon_cmode_for_move_imm. */
13804 op = !op;
c96612cc
JB
13805 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13806 &op, et.size, et.type)) == FAIL)
5287ad62 13807 {
dcbf9037 13808 first_error (_("immediate out of range"));
5287ad62
JB
13809 return;
13810 }
13811 }
13812
13813 inst.instruction &= ~(1 << 5);
13814 inst.instruction |= op << 5;
13815
13816 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13817 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13818 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13819 inst.instruction |= cmode << 8;
13820
13821 neon_write_immbits (immbits);
13822}
13823
13824static void
13825do_neon_mvn (void)
13826{
13827 if (inst.operands[1].isreg)
13828 {
037e8744 13829 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13830
5287ad62
JB
13831 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13832 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13833 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13834 inst.instruction |= LOW4 (inst.operands[1].reg);
13835 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13836 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13837 }
13838 else
13839 {
13840 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13841 neon_move_immediate ();
13842 }
13843
13844 inst.instruction = neon_dp_fixup (inst.instruction);
13845}
13846
13847/* Encode instructions of form:
13848
13849 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13850 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13851
13852static void
13853neon_mixed_length (struct neon_type_el et, unsigned size)
13854{
13855 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13856 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13857 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13858 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13859 inst.instruction |= LOW4 (inst.operands[2].reg);
13860 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13861 inst.instruction |= (et.type == NT_unsigned) << 24;
13862 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13863
5287ad62
JB
13864 inst.instruction = neon_dp_fixup (inst.instruction);
13865}
13866
13867static void
13868do_neon_dyadic_long (void)
13869{
13870 /* FIXME: Type checking for lengthening op. */
13871 struct neon_type_el et = neon_check_type (3, NS_QDD,
13872 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13873 neon_mixed_length (et, et.size);
13874}
13875
13876static void
13877do_neon_abal (void)
13878{
13879 struct neon_type_el et = neon_check_type (3, NS_QDD,
13880 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13881 neon_mixed_length (et, et.size);
13882}
13883
13884static void
13885neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13886{
13887 if (inst.operands[2].isscalar)
13888 {
dcbf9037
JB
13889 struct neon_type_el et = neon_check_type (3, NS_QDS,
13890 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13891 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13892 neon_mul_mac (et, et.type == NT_unsigned);
13893 }
13894 else
13895 {
13896 struct neon_type_el et = neon_check_type (3, NS_QDD,
13897 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13898 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13899 neon_mixed_length (et, et.size);
13900 }
13901}
13902
13903static void
13904do_neon_mac_maybe_scalar_long (void)
13905{
13906 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13907}
13908
13909static void
13910do_neon_dyadic_wide (void)
13911{
13912 struct neon_type_el et = neon_check_type (3, NS_QQD,
13913 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13914 neon_mixed_length (et, et.size);
13915}
13916
13917static void
13918do_neon_dyadic_narrow (void)
13919{
13920 struct neon_type_el et = neon_check_type (3, NS_QDD,
13921 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13922 /* Operand sign is unimportant, and the U bit is part of the opcode,
13923 so force the operand type to integer. */
13924 et.type = NT_integer;
5287ad62
JB
13925 neon_mixed_length (et, et.size / 2);
13926}
13927
13928static void
13929do_neon_mul_sat_scalar_long (void)
13930{
13931 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13932}
13933
13934static void
13935do_neon_vmull (void)
13936{
13937 if (inst.operands[2].isscalar)
13938 do_neon_mac_maybe_scalar_long ();
13939 else
13940 {
13941 struct neon_type_el et = neon_check_type (3, NS_QDD,
13942 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13943 if (et.type == NT_poly)
13944 inst.instruction = NEON_ENC_POLY (inst.instruction);
13945 else
13946 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13947 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13948 zero. Should be OK as-is. */
13949 neon_mixed_length (et, et.size);
13950 }
13951}
13952
13953static void
13954do_neon_ext (void)
13955{
037e8744 13956 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13957 struct neon_type_el et = neon_check_type (3, rs,
13958 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13959 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13960
13961 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13962 _("shift out of range"));
5287ad62
JB
13963 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13964 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13965 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13966 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13967 inst.instruction |= LOW4 (inst.operands[2].reg);
13968 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13969 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13970 inst.instruction |= imm << 8;
5f4273c7 13971
5287ad62
JB
13972 inst.instruction = neon_dp_fixup (inst.instruction);
13973}
13974
13975static void
13976do_neon_rev (void)
13977{
037e8744 13978 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13979 struct neon_type_el et = neon_check_type (2, rs,
13980 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13981 unsigned op = (inst.instruction >> 7) & 3;
13982 /* N (width of reversed regions) is encoded as part of the bitmask. We
13983 extract it here to check the elements to be reversed are smaller.
13984 Otherwise we'd get a reserved instruction. */
13985 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 13986 gas_assert (elsize != 0);
5287ad62
JB
13987 constraint (et.size >= elsize,
13988 _("elements must be smaller than reversal region"));
037e8744 13989 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13990}
13991
13992static void
13993do_neon_dup (void)
13994{
13995 if (inst.operands[1].isscalar)
13996 {
037e8744 13997 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13998 struct neon_type_el et = neon_check_type (2, rs,
13999 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 14000 unsigned sizebits = et.size >> 3;
dcbf9037 14001 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 14002 int logsize = neon_logbits (et.size);
dcbf9037 14003 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
14004
14005 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
14006 return;
14007
5287ad62
JB
14008 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
14009 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14010 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14011 inst.instruction |= LOW4 (dm);
14012 inst.instruction |= HI1 (dm) << 5;
037e8744 14013 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
14014 inst.instruction |= x << 17;
14015 inst.instruction |= sizebits << 16;
5f4273c7 14016
5287ad62
JB
14017 inst.instruction = neon_dp_fixup (inst.instruction);
14018 }
14019 else
14020 {
037e8744
JB
14021 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
14022 struct neon_type_el et = neon_check_type (2, rs,
14023 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
14024 /* Duplicate ARM register to lanes of vector. */
14025 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
14026 switch (et.size)
14027 {
14028 case 8: inst.instruction |= 0x400000; break;
14029 case 16: inst.instruction |= 0x000020; break;
14030 case 32: inst.instruction |= 0x000000; break;
14031 default: break;
14032 }
14033 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14034 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
14035 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 14036 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
14037 /* The encoding for this instruction is identical for the ARM and Thumb
14038 variants, except for the condition field. */
037e8744 14039 do_vfp_cond_or_thumb ();
5287ad62
JB
14040 }
14041}
14042
14043/* VMOV has particularly many variations. It can be one of:
14044 0. VMOV<c><q> <Qd>, <Qm>
14045 1. VMOV<c><q> <Dd>, <Dm>
14046 (Register operations, which are VORR with Rm = Rn.)
14047 2. VMOV<c><q>.<dt> <Qd>, #<imm>
14048 3. VMOV<c><q>.<dt> <Dd>, #<imm>
14049 (Immediate loads.)
14050 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
14051 (ARM register to scalar.)
14052 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
14053 (Two ARM registers to vector.)
14054 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
14055 (Scalar to ARM register.)
14056 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
14057 (Vector to two ARM registers.)
037e8744
JB
14058 8. VMOV.F32 <Sd>, <Sm>
14059 9. VMOV.F64 <Dd>, <Dm>
14060 (VFP register moves.)
14061 10. VMOV.F32 <Sd>, #imm
14062 11. VMOV.F64 <Dd>, #imm
14063 (VFP float immediate load.)
14064 12. VMOV <Rd>, <Sm>
14065 (VFP single to ARM reg.)
14066 13. VMOV <Sd>, <Rm>
14067 (ARM reg to VFP single.)
14068 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
14069 (Two ARM regs to two VFP singles.)
14070 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
14071 (Two VFP singles to two ARM regs.)
5f4273c7 14072
037e8744
JB
14073 These cases can be disambiguated using neon_select_shape, except cases 1/9
14074 and 3/11 which depend on the operand type too.
5f4273c7 14075
5287ad62 14076 All the encoded bits are hardcoded by this function.
5f4273c7 14077
b7fc2769
JB
14078 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
14079 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 14080
5287ad62 14081 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 14082 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
14083
14084static void
14085do_neon_mov (void)
14086{
037e8744
JB
14087 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
14088 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
14089 NS_NULL);
14090 struct neon_type_el et;
14091 const char *ldconst = 0;
5287ad62 14092
037e8744 14093 switch (rs)
5287ad62 14094 {
037e8744
JB
14095 case NS_DD: /* case 1/9. */
14096 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14097 /* It is not an error here if no type is given. */
14098 inst.error = NULL;
14099 if (et.type == NT_float && et.size == 64)
5287ad62 14100 {
037e8744
JB
14101 do_vfp_nsyn_opcode ("fcpyd");
14102 break;
5287ad62 14103 }
037e8744 14104 /* fall through. */
5287ad62 14105
037e8744
JB
14106 case NS_QQ: /* case 0/1. */
14107 {
14108 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14109 return;
14110 /* The architecture manual I have doesn't explicitly state which
14111 value the U bit should have for register->register moves, but
14112 the equivalent VORR instruction has U = 0, so do that. */
14113 inst.instruction = 0x0200110;
14114 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14115 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14116 inst.instruction |= LOW4 (inst.operands[1].reg);
14117 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
14118 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14119 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14120 inst.instruction |= neon_quad (rs) << 6;
14121
14122 inst.instruction = neon_dp_fixup (inst.instruction);
14123 }
14124 break;
5f4273c7 14125
037e8744
JB
14126 case NS_DI: /* case 3/11. */
14127 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
14128 inst.error = NULL;
14129 if (et.type == NT_float && et.size == 64)
5287ad62 14130 {
037e8744
JB
14131 /* case 11 (fconstd). */
14132 ldconst = "fconstd";
14133 goto encode_fconstd;
5287ad62 14134 }
037e8744
JB
14135 /* fall through. */
14136
14137 case NS_QI: /* case 2/3. */
14138 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
14139 return;
14140 inst.instruction = 0x0800010;
14141 neon_move_immediate ();
14142 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 14143 break;
5f4273c7 14144
037e8744
JB
14145 case NS_SR: /* case 4. */
14146 {
14147 unsigned bcdebits = 0;
14148 struct neon_type_el et = neon_check_type (2, NS_NULL,
14149 N_8 | N_16 | N_32 | N_KEY, N_EQK);
14150 int logsize = neon_logbits (et.size);
14151 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
14152 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
14153
14154 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14155 _(BAD_FPU));
14156 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14157 && et.size != 32, _(BAD_FPU));
14158 constraint (et.type == NT_invtype, _("bad type for scalar"));
14159 constraint (x >= 64 / et.size, _("scalar index out of range"));
14160
14161 switch (et.size)
14162 {
14163 case 8: bcdebits = 0x8; break;
14164 case 16: bcdebits = 0x1; break;
14165 case 32: bcdebits = 0x0; break;
14166 default: ;
14167 }
14168
14169 bcdebits |= x << logsize;
14170
14171 inst.instruction = 0xe000b10;
14172 do_vfp_cond_or_thumb ();
14173 inst.instruction |= LOW4 (dn) << 16;
14174 inst.instruction |= HI1 (dn) << 7;
14175 inst.instruction |= inst.operands[1].reg << 12;
14176 inst.instruction |= (bcdebits & 3) << 5;
14177 inst.instruction |= (bcdebits >> 2) << 21;
14178 }
14179 break;
5f4273c7 14180
037e8744 14181 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 14182 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 14183 _(BAD_FPU));
b7fc2769 14184
037e8744
JB
14185 inst.instruction = 0xc400b10;
14186 do_vfp_cond_or_thumb ();
14187 inst.instruction |= LOW4 (inst.operands[0].reg);
14188 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
14189 inst.instruction |= inst.operands[1].reg << 12;
14190 inst.instruction |= inst.operands[2].reg << 16;
14191 break;
5f4273c7 14192
037e8744
JB
14193 case NS_RS: /* case 6. */
14194 {
14195 struct neon_type_el et = neon_check_type (2, NS_NULL,
14196 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
14197 unsigned logsize = neon_logbits (et.size);
14198 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
14199 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
14200 unsigned abcdebits = 0;
14201
14202 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
14203 _(BAD_FPU));
14204 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
14205 && et.size != 32, _(BAD_FPU));
14206 constraint (et.type == NT_invtype, _("bad type for scalar"));
14207 constraint (x >= 64 / et.size, _("scalar index out of range"));
14208
14209 switch (et.size)
14210 {
14211 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
14212 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
14213 case 32: abcdebits = 0x00; break;
14214 default: ;
14215 }
14216
14217 abcdebits |= x << logsize;
14218 inst.instruction = 0xe100b10;
14219 do_vfp_cond_or_thumb ();
14220 inst.instruction |= LOW4 (dn) << 16;
14221 inst.instruction |= HI1 (dn) << 7;
14222 inst.instruction |= inst.operands[0].reg << 12;
14223 inst.instruction |= (abcdebits & 3) << 5;
14224 inst.instruction |= (abcdebits >> 2) << 21;
14225 }
14226 break;
5f4273c7 14227
037e8744
JB
14228 case NS_RRD: /* case 7 (fmrrd). */
14229 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
14230 _(BAD_FPU));
14231
14232 inst.instruction = 0xc500b10;
14233 do_vfp_cond_or_thumb ();
14234 inst.instruction |= inst.operands[0].reg << 12;
14235 inst.instruction |= inst.operands[1].reg << 16;
14236 inst.instruction |= LOW4 (inst.operands[2].reg);
14237 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14238 break;
5f4273c7 14239
037e8744
JB
14240 case NS_FF: /* case 8 (fcpys). */
14241 do_vfp_nsyn_opcode ("fcpys");
14242 break;
5f4273c7 14243
037e8744
JB
14244 case NS_FI: /* case 10 (fconsts). */
14245 ldconst = "fconsts";
14246 encode_fconstd:
14247 if (is_quarter_float (inst.operands[1].imm))
5287ad62 14248 {
037e8744
JB
14249 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
14250 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
14251 }
14252 else
037e8744
JB
14253 first_error (_("immediate out of range"));
14254 break;
5f4273c7 14255
037e8744
JB
14256 case NS_RF: /* case 12 (fmrs). */
14257 do_vfp_nsyn_opcode ("fmrs");
14258 break;
5f4273c7 14259
037e8744
JB
14260 case NS_FR: /* case 13 (fmsr). */
14261 do_vfp_nsyn_opcode ("fmsr");
14262 break;
5f4273c7 14263
037e8744
JB
14264 /* The encoders for the fmrrs and fmsrr instructions expect three operands
14265 (one of which is a list), but we have parsed four. Do some fiddling to
14266 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
14267 expect. */
14268 case NS_RRFF: /* case 14 (fmrrs). */
14269 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
14270 _("VFP registers must be adjacent"));
14271 inst.operands[2].imm = 2;
14272 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14273 do_vfp_nsyn_opcode ("fmrrs");
14274 break;
5f4273c7 14275
037e8744
JB
14276 case NS_FFRR: /* case 15 (fmsrr). */
14277 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
14278 _("VFP registers must be adjacent"));
14279 inst.operands[1] = inst.operands[2];
14280 inst.operands[2] = inst.operands[3];
14281 inst.operands[0].imm = 2;
14282 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
14283 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 14284 break;
5f4273c7 14285
5287ad62
JB
14286 default:
14287 abort ();
14288 }
14289}
14290
14291static void
14292do_neon_rshift_round_imm (void)
14293{
037e8744 14294 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
14295 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
14296 int imm = inst.operands[2].imm;
14297
14298 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
14299 if (imm == 0)
14300 {
14301 inst.operands[2].present = 0;
14302 do_neon_mov ();
14303 return;
14304 }
14305
14306 constraint (imm < 1 || (unsigned)imm > et.size,
14307 _("immediate out of range for shift"));
037e8744 14308 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
14309 et.size - imm);
14310}
14311
14312static void
14313do_neon_movl (void)
14314{
14315 struct neon_type_el et = neon_check_type (2, NS_QD,
14316 N_EQK | N_DBL, N_SU_32 | N_KEY);
14317 unsigned sizebits = et.size >> 3;
14318 inst.instruction |= sizebits << 19;
14319 neon_two_same (0, et.type == NT_unsigned, -1);
14320}
14321
14322static void
14323do_neon_trn (void)
14324{
037e8744 14325 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14326 struct neon_type_el et = neon_check_type (2, rs,
14327 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14328 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 14329 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14330}
14331
14332static void
14333do_neon_zip_uzp (void)
14334{
037e8744 14335 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14336 struct neon_type_el et = neon_check_type (2, rs,
14337 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14338 if (rs == NS_DD && et.size == 32)
14339 {
14340 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14341 inst.instruction = N_MNEM_vtrn;
14342 do_neon_trn ();
14343 return;
14344 }
037e8744 14345 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14346}
14347
14348static void
14349do_neon_sat_abs_neg (void)
14350{
037e8744 14351 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14352 struct neon_type_el et = neon_check_type (2, rs,
14353 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14354 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14355}
14356
14357static void
14358do_neon_pair_long (void)
14359{
037e8744 14360 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14361 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14362 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14363 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14364 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14365}
14366
14367static void
14368do_neon_recip_est (void)
14369{
037e8744 14370 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14371 struct neon_type_el et = neon_check_type (2, rs,
14372 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14373 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14374 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14375}
14376
14377static void
14378do_neon_cls (void)
14379{
037e8744 14380 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14381 struct neon_type_el et = neon_check_type (2, rs,
14382 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14383 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14384}
14385
14386static void
14387do_neon_clz (void)
14388{
037e8744 14389 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14390 struct neon_type_el et = neon_check_type (2, rs,
14391 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14392 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14393}
14394
14395static void
14396do_neon_cnt (void)
14397{
037e8744 14398 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14399 struct neon_type_el et = neon_check_type (2, rs,
14400 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14401 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14402}
14403
14404static void
14405do_neon_swp (void)
14406{
037e8744
JB
14407 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14408 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14409}
14410
14411static void
14412do_neon_tbl_tbx (void)
14413{
14414 unsigned listlenbits;
dcbf9037 14415 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14416
5287ad62
JB
14417 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14418 {
dcbf9037 14419 first_error (_("bad list length for table lookup"));
5287ad62
JB
14420 return;
14421 }
5f4273c7 14422
5287ad62
JB
14423 listlenbits = inst.operands[1].imm - 1;
14424 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14425 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14426 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14427 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14428 inst.instruction |= LOW4 (inst.operands[2].reg);
14429 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14430 inst.instruction |= listlenbits << 8;
5f4273c7 14431
5287ad62
JB
14432 inst.instruction = neon_dp_fixup (inst.instruction);
14433}
14434
14435static void
14436do_neon_ldm_stm (void)
14437{
14438 /* P, U and L bits are part of bitmask. */
14439 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14440 unsigned offsetbits = inst.operands[1].imm * 2;
14441
037e8744
JB
14442 if (inst.operands[1].issingle)
14443 {
14444 do_vfp_nsyn_ldm_stm (is_dbmode);
14445 return;
14446 }
14447
5287ad62
JB
14448 constraint (is_dbmode && !inst.operands[0].writeback,
14449 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14450
14451 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14452 _("register list must contain at least 1 and at most 16 "
14453 "registers"));
14454
14455 inst.instruction |= inst.operands[0].reg << 16;
14456 inst.instruction |= inst.operands[0].writeback << 21;
14457 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14458 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14459
14460 inst.instruction |= offsetbits;
5f4273c7 14461
037e8744 14462 do_vfp_cond_or_thumb ();
5287ad62
JB
14463}
14464
14465static void
14466do_neon_ldr_str (void)
14467{
5287ad62 14468 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14469
037e8744
JB
14470 if (inst.operands[0].issingle)
14471 {
cd2f129f
JB
14472 if (is_ldr)
14473 do_vfp_nsyn_opcode ("flds");
14474 else
14475 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14476 }
14477 else
5287ad62 14478 {
cd2f129f
JB
14479 if (is_ldr)
14480 do_vfp_nsyn_opcode ("fldd");
5287ad62 14481 else
cd2f129f 14482 do_vfp_nsyn_opcode ("fstd");
5287ad62 14483 }
5287ad62
JB
14484}
14485
14486/* "interleave" version also handles non-interleaving register VLD1/VST1
14487 instructions. */
14488
14489static void
14490do_neon_ld_st_interleave (void)
14491{
037e8744 14492 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14493 N_8 | N_16 | N_32 | N_64);
14494 unsigned alignbits = 0;
14495 unsigned idx;
14496 /* The bits in this table go:
14497 0: register stride of one (0) or two (1)
14498 1,2: register list length, minus one (1, 2, 3, 4).
14499 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14500 We use -1 for invalid entries. */
14501 const int typetable[] =
14502 {
14503 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14504 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14505 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14506 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14507 };
14508 int typebits;
14509
dcbf9037
JB
14510 if (et.type == NT_invtype)
14511 return;
14512
5287ad62
JB
14513 if (inst.operands[1].immisalign)
14514 switch (inst.operands[1].imm >> 8)
14515 {
14516 case 64: alignbits = 1; break;
14517 case 128:
14518 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14519 goto bad_alignment;
14520 alignbits = 2;
14521 break;
14522 case 256:
14523 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14524 goto bad_alignment;
14525 alignbits = 3;
14526 break;
14527 default:
14528 bad_alignment:
dcbf9037 14529 first_error (_("bad alignment"));
5287ad62
JB
14530 return;
14531 }
14532
14533 inst.instruction |= alignbits << 4;
14534 inst.instruction |= neon_logbits (et.size) << 6;
14535
14536 /* Bits [4:6] of the immediate in a list specifier encode register stride
14537 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14538 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14539 up the right value for "type" in a table based on this value and the given
14540 list style, then stick it back. */
14541 idx = ((inst.operands[0].imm >> 4) & 7)
14542 | (((inst.instruction >> 8) & 3) << 3);
14543
14544 typebits = typetable[idx];
5f4273c7 14545
5287ad62
JB
14546 constraint (typebits == -1, _("bad list type for instruction"));
14547
14548 inst.instruction &= ~0xf00;
14549 inst.instruction |= typebits << 8;
14550}
14551
14552/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14553 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14554 otherwise. The variable arguments are a list of pairs of legal (size, align)
14555 values, terminated with -1. */
14556
14557static int
14558neon_alignment_bit (int size, int align, int *do_align, ...)
14559{
14560 va_list ap;
14561 int result = FAIL, thissize, thisalign;
5f4273c7 14562
5287ad62
JB
14563 if (!inst.operands[1].immisalign)
14564 {
14565 *do_align = 0;
14566 return SUCCESS;
14567 }
5f4273c7 14568
5287ad62
JB
14569 va_start (ap, do_align);
14570
14571 do
14572 {
14573 thissize = va_arg (ap, int);
14574 if (thissize == -1)
14575 break;
14576 thisalign = va_arg (ap, int);
14577
14578 if (size == thissize && align == thisalign)
14579 result = SUCCESS;
14580 }
14581 while (result != SUCCESS);
14582
14583 va_end (ap);
14584
14585 if (result == SUCCESS)
14586 *do_align = 1;
14587 else
dcbf9037 14588 first_error (_("unsupported alignment for instruction"));
5f4273c7 14589
5287ad62
JB
14590 return result;
14591}
14592
14593static void
14594do_neon_ld_st_lane (void)
14595{
037e8744 14596 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14597 int align_good, do_align = 0;
14598 int logsize = neon_logbits (et.size);
14599 int align = inst.operands[1].imm >> 8;
14600 int n = (inst.instruction >> 8) & 3;
14601 int max_el = 64 / et.size;
5f4273c7 14602
dcbf9037
JB
14603 if (et.type == NT_invtype)
14604 return;
5f4273c7 14605
5287ad62
JB
14606 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14607 _("bad list length"));
14608 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14609 _("scalar index out of range"));
14610 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14611 && et.size == 8,
14612 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14613
5287ad62
JB
14614 switch (n)
14615 {
14616 case 0: /* VLD1 / VST1. */
14617 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14618 32, 32, -1);
14619 if (align_good == FAIL)
14620 return;
14621 if (do_align)
14622 {
14623 unsigned alignbits = 0;
14624 switch (et.size)
14625 {
14626 case 16: alignbits = 0x1; break;
14627 case 32: alignbits = 0x3; break;
14628 default: ;
14629 }
14630 inst.instruction |= alignbits << 4;
14631 }
14632 break;
14633
14634 case 1: /* VLD2 / VST2. */
14635 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14636 32, 64, -1);
14637 if (align_good == FAIL)
14638 return;
14639 if (do_align)
14640 inst.instruction |= 1 << 4;
14641 break;
14642
14643 case 2: /* VLD3 / VST3. */
14644 constraint (inst.operands[1].immisalign,
14645 _("can't use alignment with this instruction"));
14646 break;
14647
14648 case 3: /* VLD4 / VST4. */
14649 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14650 16, 64, 32, 64, 32, 128, -1);
14651 if (align_good == FAIL)
14652 return;
14653 if (do_align)
14654 {
14655 unsigned alignbits = 0;
14656 switch (et.size)
14657 {
14658 case 8: alignbits = 0x1; break;
14659 case 16: alignbits = 0x1; break;
14660 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14661 default: ;
14662 }
14663 inst.instruction |= alignbits << 4;
14664 }
14665 break;
14666
14667 default: ;
14668 }
14669
14670 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14671 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14672 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14673
5287ad62
JB
14674 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14675 inst.instruction |= logsize << 10;
14676}
14677
14678/* Encode single n-element structure to all lanes VLD<n> instructions. */
14679
14680static void
14681do_neon_ld_dup (void)
14682{
037e8744 14683 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14684 int align_good, do_align = 0;
14685
dcbf9037
JB
14686 if (et.type == NT_invtype)
14687 return;
14688
5287ad62
JB
14689 switch ((inst.instruction >> 8) & 3)
14690 {
14691 case 0: /* VLD1. */
9c2799c2 14692 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14693 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14694 &do_align, 16, 16, 32, 32, -1);
14695 if (align_good == FAIL)
14696 return;
14697 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14698 {
14699 case 1: break;
14700 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14701 default: first_error (_("bad list length")); return;
5287ad62
JB
14702 }
14703 inst.instruction |= neon_logbits (et.size) << 6;
14704 break;
14705
14706 case 1: /* VLD2. */
14707 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14708 &do_align, 8, 16, 16, 32, 32, 64, -1);
14709 if (align_good == FAIL)
14710 return;
14711 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14712 _("bad list length"));
14713 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14714 inst.instruction |= 1 << 5;
14715 inst.instruction |= neon_logbits (et.size) << 6;
14716 break;
14717
14718 case 2: /* VLD3. */
14719 constraint (inst.operands[1].immisalign,
14720 _("can't use alignment with this instruction"));
14721 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14722 _("bad list length"));
14723 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14724 inst.instruction |= 1 << 5;
14725 inst.instruction |= neon_logbits (et.size) << 6;
14726 break;
14727
14728 case 3: /* VLD4. */
14729 {
14730 int align = inst.operands[1].imm >> 8;
14731 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14732 16, 64, 32, 64, 32, 128, -1);
14733 if (align_good == FAIL)
14734 return;
14735 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14736 _("bad list length"));
14737 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14738 inst.instruction |= 1 << 5;
14739 if (et.size == 32 && align == 128)
14740 inst.instruction |= 0x3 << 6;
14741 else
14742 inst.instruction |= neon_logbits (et.size) << 6;
14743 }
14744 break;
14745
14746 default: ;
14747 }
14748
14749 inst.instruction |= do_align << 4;
14750}
14751
14752/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14753 apart from bits [11:4]. */
14754
14755static void
14756do_neon_ldx_stx (void)
14757{
14758 switch (NEON_LANE (inst.operands[0].imm))
14759 {
14760 case NEON_INTERLEAVE_LANES:
14761 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14762 do_neon_ld_st_interleave ();
14763 break;
5f4273c7 14764
5287ad62
JB
14765 case NEON_ALL_LANES:
14766 inst.instruction = NEON_ENC_DUP (inst.instruction);
14767 do_neon_ld_dup ();
14768 break;
5f4273c7 14769
5287ad62
JB
14770 default:
14771 inst.instruction = NEON_ENC_LANE (inst.instruction);
14772 do_neon_ld_st_lane ();
14773 }
14774
14775 /* L bit comes from bit mask. */
14776 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14777 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14778 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14779
5287ad62
JB
14780 if (inst.operands[1].postind)
14781 {
14782 int postreg = inst.operands[1].imm & 0xf;
14783 constraint (!inst.operands[1].immisreg,
14784 _("post-index must be a register"));
14785 constraint (postreg == 0xd || postreg == 0xf,
14786 _("bad register for post-index"));
14787 inst.instruction |= postreg;
14788 }
14789 else if (inst.operands[1].writeback)
14790 {
14791 inst.instruction |= 0xd;
14792 }
14793 else
5f4273c7
NC
14794 inst.instruction |= 0xf;
14795
5287ad62
JB
14796 if (thumb_mode)
14797 inst.instruction |= 0xf9000000;
14798 else
14799 inst.instruction |= 0xf4000000;
14800}
5287ad62
JB
14801\f
14802/* Overall per-instruction processing. */
14803
14804/* We need to be able to fix up arbitrary expressions in some statements.
14805 This is so that we can handle symbols that are an arbitrary distance from
14806 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14807 which returns part of an address in a form which will be valid for
14808 a data instruction. We do this by pushing the expression into a symbol
14809 in the expr_section, and creating a fix for that. */
14810
14811static void
14812fix_new_arm (fragS * frag,
14813 int where,
14814 short int size,
14815 expressionS * exp,
14816 int pc_rel,
14817 int reloc)
14818{
14819 fixS * new_fix;
14820
14821 switch (exp->X_op)
14822 {
14823 case O_constant:
14824 case O_symbol:
14825 case O_add:
14826 case O_subtract:
21d799b5
NC
14827 new_fix = fix_new_exp (frag, where, size, exp, pc_rel,
14828 (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14829 break;
14830
14831 default:
21d799b5
NC
14832 new_fix = (fixS *) fix_new (frag, where, size, make_expr_symbol (exp), 0,
14833 pc_rel, (enum bfd_reloc_code_real) reloc);
5287ad62
JB
14834 break;
14835 }
14836
14837 /* Mark whether the fix is to a THUMB instruction, or an ARM
14838 instruction. */
14839 new_fix->tc_fix_data = thumb_mode;
14840}
14841
14842/* Create a frg for an instruction requiring relaxation. */
14843static void
14844output_relax_insn (void)
14845{
14846 char * to;
14847 symbolS *sym;
0110f2b8
PB
14848 int offset;
14849
6e1cb1a6
PB
14850 /* The size of the instruction is unknown, so tie the debug info to the
14851 start of the instruction. */
14852 dwarf2_emit_insn (0);
6e1cb1a6 14853
0110f2b8
PB
14854 switch (inst.reloc.exp.X_op)
14855 {
14856 case O_symbol:
14857 sym = inst.reloc.exp.X_add_symbol;
14858 offset = inst.reloc.exp.X_add_number;
14859 break;
14860 case O_constant:
14861 sym = NULL;
14862 offset = inst.reloc.exp.X_add_number;
14863 break;
14864 default:
14865 sym = make_expr_symbol (&inst.reloc.exp);
14866 offset = 0;
14867 break;
14868 }
14869 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14870 inst.relax, sym, offset, NULL/*offset, opcode*/);
14871 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14872}
14873
14874/* Write a 32-bit thumb instruction to buf. */
14875static void
14876put_thumb32_insn (char * buf, unsigned long insn)
14877{
14878 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14879 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14880}
14881
b99bd4ef 14882static void
c19d1205 14883output_inst (const char * str)
b99bd4ef 14884{
c19d1205 14885 char * to = NULL;
b99bd4ef 14886
c19d1205 14887 if (inst.error)
b99bd4ef 14888 {
c19d1205 14889 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14890 return;
14891 }
5f4273c7
NC
14892 if (inst.relax)
14893 {
14894 output_relax_insn ();
0110f2b8 14895 return;
5f4273c7 14896 }
c19d1205
ZW
14897 if (inst.size == 0)
14898 return;
b99bd4ef 14899
c19d1205 14900 to = frag_more (inst.size);
8dc2430f
NC
14901 /* PR 9814: Record the thumb mode into the current frag so that we know
14902 what type of NOP padding to use, if necessary. We override any previous
14903 setting so that if the mode has changed then the NOPS that we use will
14904 match the encoding of the last instruction in the frag. */
cd000bff 14905 frag_now->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14906
14907 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14908 {
9c2799c2 14909 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14910 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14911 }
c19d1205 14912 else if (inst.size > INSN_SIZE)
b99bd4ef 14913 {
9c2799c2 14914 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
14915 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14916 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14917 }
c19d1205
ZW
14918 else
14919 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14920
c19d1205
ZW
14921 if (inst.reloc.type != BFD_RELOC_UNUSED)
14922 fix_new_arm (frag_now, to - frag_now->fr_literal,
14923 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14924 inst.reloc.type);
b99bd4ef 14925
c19d1205 14926 dwarf2_emit_insn (inst.size);
c19d1205 14927}
b99bd4ef 14928
e07e6e58
NC
14929static char *
14930output_it_inst (int cond, int mask, char * to)
14931{
14932 unsigned long instruction = 0xbf00;
14933
14934 mask &= 0xf;
14935 instruction |= mask;
14936 instruction |= cond << 4;
14937
14938 if (to == NULL)
14939 {
14940 to = frag_more (2);
14941#ifdef OBJ_ELF
14942 dwarf2_emit_insn (2);
14943#endif
14944 }
14945
14946 md_number_to_chars (to, instruction, 2);
14947
14948 return to;
14949}
14950
c19d1205
ZW
14951/* Tag values used in struct asm_opcode's tag field. */
14952enum opcode_tag
14953{
14954 OT_unconditional, /* Instruction cannot be conditionalized.
14955 The ARM condition field is still 0xE. */
14956 OT_unconditionalF, /* Instruction cannot be conditionalized
14957 and carries 0xF in its ARM condition field. */
14958 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14959 OT_csuffixF, /* Some forms of the instruction take a conditional
14960 suffix, others place 0xF where the condition field
14961 would be. */
c19d1205
ZW
14962 OT_cinfix3, /* Instruction takes a conditional infix,
14963 beginning at character index 3. (In
14964 unified mode, it becomes a suffix.) */
088fa78e
KH
14965 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14966 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14967 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14968 character index 3, even in unified mode. Used for
14969 legacy instructions where suffix and infix forms
14970 may be ambiguous. */
c19d1205 14971 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14972 suffix or an infix at character index 3. */
c19d1205
ZW
14973 OT_odd_infix_unc, /* This is the unconditional variant of an
14974 instruction that takes a conditional infix
14975 at an unusual position. In unified mode,
14976 this variant will accept a suffix. */
14977 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14978 are the conditional variants of instructions that
14979 take conditional infixes in unusual positions.
14980 The infix appears at character index
14981 (tag - OT_odd_infix_0). These are not accepted
14982 in unified mode. */
14983};
b99bd4ef 14984
c19d1205
ZW
14985/* Subroutine of md_assemble, responsible for looking up the primary
14986 opcode from the mnemonic the user wrote. STR points to the
14987 beginning of the mnemonic.
14988
14989 This is not simply a hash table lookup, because of conditional
14990 variants. Most instructions have conditional variants, which are
14991 expressed with a _conditional affix_ to the mnemonic. If we were
14992 to encode each conditional variant as a literal string in the opcode
14993 table, it would have approximately 20,000 entries.
14994
14995 Most mnemonics take this affix as a suffix, and in unified syntax,
14996 'most' is upgraded to 'all'. However, in the divided syntax, some
14997 instructions take the affix as an infix, notably the s-variants of
14998 the arithmetic instructions. Of those instructions, all but six
14999 have the infix appear after the third character of the mnemonic.
15000
15001 Accordingly, the algorithm for looking up primary opcodes given
15002 an identifier is:
15003
15004 1. Look up the identifier in the opcode table.
15005 If we find a match, go to step U.
15006
15007 2. Look up the last two characters of the identifier in the
15008 conditions table. If we find a match, look up the first N-2
15009 characters of the identifier in the opcode table. If we
15010 find a match, go to step CE.
15011
15012 3. Look up the fourth and fifth characters of the identifier in
15013 the conditions table. If we find a match, extract those
15014 characters from the identifier, and look up the remaining
15015 characters in the opcode table. If we find a match, go
15016 to step CM.
15017
15018 4. Fail.
15019
15020 U. Examine the tag field of the opcode structure, in case this is
15021 one of the six instructions with its conditional infix in an
15022 unusual place. If it is, the tag tells us where to find the
15023 infix; look it up in the conditions table and set inst.cond
15024 accordingly. Otherwise, this is an unconditional instruction.
15025 Again set inst.cond accordingly. Return the opcode structure.
15026
15027 CE. Examine the tag field to make sure this is an instruction that
15028 should receive a conditional suffix. If it is not, fail.
15029 Otherwise, set inst.cond from the suffix we already looked up,
15030 and return the opcode structure.
15031
15032 CM. Examine the tag field to make sure this is an instruction that
15033 should receive a conditional infix after the third character.
15034 If it is not, fail. Otherwise, undo the edits to the current
15035 line of input and proceed as for case CE. */
15036
15037static const struct asm_opcode *
15038opcode_lookup (char **str)
15039{
15040 char *end, *base;
15041 char *affix;
15042 const struct asm_opcode *opcode;
15043 const struct asm_cond *cond;
e3cb604e 15044 char save[2];
c19d1205
ZW
15045
15046 /* Scan up to the end of the mnemonic, which must end in white space,
721a8186 15047 '.' (in unified mode, or for Neon/VFP instructions), or end of string. */
c19d1205 15048 for (base = end = *str; *end != '\0'; end++)
721a8186 15049 if (*end == ' ' || *end == '.')
c19d1205 15050 break;
b99bd4ef 15051
c19d1205 15052 if (end == base)
c921be7d 15053 return NULL;
b99bd4ef 15054
5287ad62 15055 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 15056 if (end[0] == '.')
b99bd4ef 15057 {
5287ad62 15058 int offset = 2;
5f4273c7 15059
267d2029
JB
15060 /* The .w and .n suffixes are only valid if the unified syntax is in
15061 use. */
15062 if (unified_syntax && end[1] == 'w')
c19d1205 15063 inst.size_req = 4;
267d2029 15064 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
15065 inst.size_req = 2;
15066 else
5287ad62
JB
15067 offset = 0;
15068
15069 inst.vectype.elems = 0;
15070
15071 *str = end + offset;
b99bd4ef 15072
5f4273c7 15073 if (end[offset] == '.')
5287ad62 15074 {
267d2029
JB
15075 /* See if we have a Neon type suffix (possible in either unified or
15076 non-unified ARM syntax mode). */
dcbf9037 15077 if (parse_neon_type (&inst.vectype, str) == FAIL)
c921be7d 15078 return NULL;
5287ad62
JB
15079 }
15080 else if (end[offset] != '\0' && end[offset] != ' ')
c921be7d 15081 return NULL;
b99bd4ef 15082 }
c19d1205
ZW
15083 else
15084 *str = end;
b99bd4ef 15085
c19d1205 15086 /* Look for unaffixed or special-case affixed mnemonic. */
21d799b5
NC
15087 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15088 end - base);
c19d1205 15089 if (opcode)
b99bd4ef 15090 {
c19d1205
ZW
15091 /* step U */
15092 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 15093 {
c19d1205
ZW
15094 inst.cond = COND_ALWAYS;
15095 return opcode;
b99bd4ef 15096 }
b99bd4ef 15097
278df34e 15098 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
15099 as_warn (_("conditional infixes are deprecated in unified syntax"));
15100 affix = base + (opcode->tag - OT_odd_infix_0);
21d799b5 15101 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 15102 gas_assert (cond);
b99bd4ef 15103
c19d1205
ZW
15104 inst.cond = cond->value;
15105 return opcode;
15106 }
b99bd4ef 15107
c19d1205
ZW
15108 /* Cannot have a conditional suffix on a mnemonic of less than two
15109 characters. */
15110 if (end - base < 3)
c921be7d 15111 return NULL;
b99bd4ef 15112
c19d1205
ZW
15113 /* Look for suffixed mnemonic. */
15114 affix = end - 2;
21d799b5
NC
15115 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
15116 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15117 affix - base);
c19d1205
ZW
15118 if (opcode && cond)
15119 {
15120 /* step CE */
15121 switch (opcode->tag)
15122 {
e3cb604e
PB
15123 case OT_cinfix3_legacy:
15124 /* Ignore conditional suffixes matched on infix only mnemonics. */
15125 break;
15126
c19d1205 15127 case OT_cinfix3:
088fa78e 15128 case OT_cinfix3_deprecated:
c19d1205
ZW
15129 case OT_odd_infix_unc:
15130 if (!unified_syntax)
e3cb604e 15131 return 0;
c19d1205
ZW
15132 /* else fall through */
15133
15134 case OT_csuffix:
037e8744 15135 case OT_csuffixF:
c19d1205
ZW
15136 case OT_csuf_or_in3:
15137 inst.cond = cond->value;
15138 return opcode;
15139
15140 case OT_unconditional:
15141 case OT_unconditionalF:
dfa9f0d5 15142 if (thumb_mode)
c921be7d 15143 inst.cond = cond->value;
dfa9f0d5
PB
15144 else
15145 {
c921be7d 15146 /* Delayed diagnostic. */
dfa9f0d5
PB
15147 inst.error = BAD_COND;
15148 inst.cond = COND_ALWAYS;
15149 }
c19d1205 15150 return opcode;
b99bd4ef 15151
c19d1205 15152 default:
c921be7d 15153 return NULL;
c19d1205
ZW
15154 }
15155 }
b99bd4ef 15156
c19d1205
ZW
15157 /* Cannot have a usual-position infix on a mnemonic of less than
15158 six characters (five would be a suffix). */
15159 if (end - base < 6)
c921be7d 15160 return NULL;
b99bd4ef 15161
c19d1205
ZW
15162 /* Look for infixed mnemonic in the usual position. */
15163 affix = base + 3;
21d799b5 15164 cond = (const struct asm_cond *) hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e 15165 if (!cond)
c921be7d 15166 return NULL;
e3cb604e
PB
15167
15168 memcpy (save, affix, 2);
15169 memmove (affix, affix + 2, (end - affix) - 2);
21d799b5
NC
15170 opcode = (const struct asm_opcode *) hash_find_n (arm_ops_hsh, base,
15171 (end - base) - 2);
e3cb604e
PB
15172 memmove (affix + 2, affix, (end - affix) - 2);
15173 memcpy (affix, save, 2);
15174
088fa78e
KH
15175 if (opcode
15176 && (opcode->tag == OT_cinfix3
15177 || opcode->tag == OT_cinfix3_deprecated
15178 || opcode->tag == OT_csuf_or_in3
15179 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 15180 {
c921be7d 15181 /* Step CM. */
278df34e 15182 if (warn_on_deprecated && unified_syntax
088fa78e
KH
15183 && (opcode->tag == OT_cinfix3
15184 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
15185 as_warn (_("conditional infixes are deprecated in unified syntax"));
15186
15187 inst.cond = cond->value;
15188 return opcode;
b99bd4ef
NC
15189 }
15190
c921be7d 15191 return NULL;
b99bd4ef
NC
15192}
15193
e07e6e58
NC
15194/* This function generates an initial IT instruction, leaving its block
15195 virtually open for the new instructions. Eventually,
15196 the mask will be updated by now_it_add_mask () each time
15197 a new instruction needs to be included in the IT block.
15198 Finally, the block is closed with close_automatic_it_block ().
15199 The block closure can be requested either from md_assemble (),
15200 a tencode (), or due to a label hook. */
15201
15202static void
15203new_automatic_it_block (int cond)
15204{
15205 now_it.state = AUTOMATIC_IT_BLOCK;
15206 now_it.mask = 0x18;
15207 now_it.cc = cond;
15208 now_it.block_length = 1;
cd000bff 15209 mapping_state (MAP_THUMB);
e07e6e58
NC
15210 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
15211}
15212
15213/* Close an automatic IT block.
15214 See comments in new_automatic_it_block (). */
15215
15216static void
15217close_automatic_it_block (void)
15218{
15219 now_it.mask = 0x10;
15220 now_it.block_length = 0;
15221}
15222
15223/* Update the mask of the current automatically-generated IT
15224 instruction. See comments in new_automatic_it_block (). */
15225
15226static void
15227now_it_add_mask (int cond)
15228{
15229#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
15230#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
15231 | ((bitvalue) << (nbit)))
e07e6e58 15232 const int resulting_bit = (cond & 1);
c921be7d 15233
e07e6e58
NC
15234 now_it.mask &= 0xf;
15235 now_it.mask = SET_BIT_VALUE (now_it.mask,
15236 resulting_bit,
15237 (5 - now_it.block_length));
15238 now_it.mask = SET_BIT_VALUE (now_it.mask,
15239 1,
15240 ((5 - now_it.block_length) - 1) );
15241 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
15242
15243#undef CLEAR_BIT
15244#undef SET_BIT_VALUE
e07e6e58
NC
15245}
15246
15247/* The IT blocks handling machinery is accessed through the these functions:
15248 it_fsm_pre_encode () from md_assemble ()
15249 set_it_insn_type () optional, from the tencode functions
15250 set_it_insn_type_last () ditto
15251 in_it_block () ditto
15252 it_fsm_post_encode () from md_assemble ()
15253 force_automatic_it_block_close () from label habdling functions
15254
15255 Rationale:
15256 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
15257 initializing the IT insn type with a generic initial value depending
15258 on the inst.condition.
15259 2) During the tencode function, two things may happen:
15260 a) The tencode function overrides the IT insn type by
15261 calling either set_it_insn_type (type) or set_it_insn_type_last ().
15262 b) The tencode function queries the IT block state by
15263 calling in_it_block () (i.e. to determine narrow/not narrow mode).
15264
15265 Both set_it_insn_type and in_it_block run the internal FSM state
15266 handling function (handle_it_state), because: a) setting the IT insn
15267 type may incur in an invalid state (exiting the function),
15268 and b) querying the state requires the FSM to be updated.
15269 Specifically we want to avoid creating an IT block for conditional
15270 branches, so it_fsm_pre_encode is actually a guess and we can't
15271 determine whether an IT block is required until the tencode () routine
15272 has decided what type of instruction this actually it.
15273 Because of this, if set_it_insn_type and in_it_block have to be used,
15274 set_it_insn_type has to be called first.
15275
15276 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
15277 determines the insn IT type depending on the inst.cond code.
15278 When a tencode () routine encodes an instruction that can be
15279 either outside an IT block, or, in the case of being inside, has to be
15280 the last one, set_it_insn_type_last () will determine the proper
15281 IT instruction type based on the inst.cond code. Otherwise,
15282 set_it_insn_type can be called for overriding that logic or
15283 for covering other cases.
15284
15285 Calling handle_it_state () may not transition the IT block state to
15286 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
15287 still queried. Instead, if the FSM determines that the state should
15288 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
15289 after the tencode () function: that's what it_fsm_post_encode () does.
15290
15291 Since in_it_block () calls the state handling function to get an
15292 updated state, an error may occur (due to invalid insns combination).
15293 In that case, inst.error is set.
15294 Therefore, inst.error has to be checked after the execution of
15295 the tencode () routine.
15296
15297 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
15298 any pending state change (if any) that didn't take place in
15299 handle_it_state () as explained above. */
15300
15301static void
15302it_fsm_pre_encode (void)
15303{
15304 if (inst.cond != COND_ALWAYS)
15305 inst.it_insn_type = INSIDE_IT_INSN;
15306 else
15307 inst.it_insn_type = OUTSIDE_IT_INSN;
15308
15309 now_it.state_handled = 0;
15310}
15311
15312/* IT state FSM handling function. */
15313
15314static int
15315handle_it_state (void)
15316{
15317 now_it.state_handled = 1;
15318
15319 switch (now_it.state)
15320 {
15321 case OUTSIDE_IT_BLOCK:
15322 switch (inst.it_insn_type)
15323 {
15324 case OUTSIDE_IT_INSN:
15325 break;
15326
15327 case INSIDE_IT_INSN:
15328 case INSIDE_IT_LAST_INSN:
15329 if (thumb_mode == 0)
15330 {
c921be7d 15331 if (unified_syntax
e07e6e58
NC
15332 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15333 as_tsktsk (_("Warning: conditional outside an IT block"\
15334 " for Thumb."));
15335 }
15336 else
15337 {
15338 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15339 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15340 {
15341 /* Automatically generate the IT instruction. */
15342 new_automatic_it_block (inst.cond);
15343 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15344 close_automatic_it_block ();
15345 }
15346 else
15347 {
15348 inst.error = BAD_OUT_IT;
15349 return FAIL;
15350 }
15351 }
15352 break;
15353
15354 case IF_INSIDE_IT_LAST_INSN:
15355 case NEUTRAL_IT_INSN:
15356 break;
15357
15358 case IT_INSN:
15359 now_it.state = MANUAL_IT_BLOCK;
15360 now_it.block_length = 0;
15361 break;
15362 }
15363 break;
15364
15365 case AUTOMATIC_IT_BLOCK:
15366 /* Three things may happen now:
15367 a) We should increment current it block size;
15368 b) We should close current it block (closing insn or 4 insns);
15369 c) We should close current it block and start a new one (due
15370 to incompatible conditions or
15371 4 insns-length block reached). */
15372
15373 switch (inst.it_insn_type)
15374 {
15375 case OUTSIDE_IT_INSN:
15376 /* The closure of the block shall happen immediatelly,
15377 so any in_it_block () call reports the block as closed. */
15378 force_automatic_it_block_close ();
15379 break;
15380
15381 case INSIDE_IT_INSN:
15382 case INSIDE_IT_LAST_INSN:
15383 case IF_INSIDE_IT_LAST_INSN:
15384 now_it.block_length++;
15385
15386 if (now_it.block_length > 4
15387 || !now_it_compatible (inst.cond))
15388 {
15389 force_automatic_it_block_close ();
15390 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15391 new_automatic_it_block (inst.cond);
15392 }
15393 else
15394 {
15395 now_it_add_mask (inst.cond);
15396 }
15397
15398 if (now_it.state == AUTOMATIC_IT_BLOCK
15399 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15400 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15401 close_automatic_it_block ();
15402 break;
15403
15404 case NEUTRAL_IT_INSN:
15405 now_it.block_length++;
15406
15407 if (now_it.block_length > 4)
15408 force_automatic_it_block_close ();
15409 else
15410 now_it_add_mask (now_it.cc & 1);
15411 break;
15412
15413 case IT_INSN:
15414 close_automatic_it_block ();
15415 now_it.state = MANUAL_IT_BLOCK;
15416 break;
15417 }
15418 break;
15419
15420 case MANUAL_IT_BLOCK:
15421 {
15422 /* Check conditional suffixes. */
15423 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15424 int is_last;
15425 now_it.mask <<= 1;
15426 now_it.mask &= 0x1f;
15427 is_last = (now_it.mask == 0x10);
15428
15429 switch (inst.it_insn_type)
15430 {
15431 case OUTSIDE_IT_INSN:
15432 inst.error = BAD_NOT_IT;
15433 return FAIL;
15434
15435 case INSIDE_IT_INSN:
15436 if (cond != inst.cond)
15437 {
15438 inst.error = BAD_IT_COND;
15439 return FAIL;
15440 }
15441 break;
15442
15443 case INSIDE_IT_LAST_INSN:
15444 case IF_INSIDE_IT_LAST_INSN:
15445 if (cond != inst.cond)
15446 {
15447 inst.error = BAD_IT_COND;
15448 return FAIL;
15449 }
15450 if (!is_last)
15451 {
15452 inst.error = BAD_BRANCH;
15453 return FAIL;
15454 }
15455 break;
15456
15457 case NEUTRAL_IT_INSN:
15458 /* The BKPT instruction is unconditional even in an IT block. */
15459 break;
15460
15461 case IT_INSN:
15462 inst.error = BAD_IT_IT;
15463 return FAIL;
15464 }
15465 }
15466 break;
15467 }
15468
15469 return SUCCESS;
15470}
15471
15472static void
15473it_fsm_post_encode (void)
15474{
15475 int is_last;
15476
15477 if (!now_it.state_handled)
15478 handle_it_state ();
15479
15480 is_last = (now_it.mask == 0x10);
15481 if (is_last)
15482 {
15483 now_it.state = OUTSIDE_IT_BLOCK;
15484 now_it.mask = 0;
15485 }
15486}
15487
15488static void
15489force_automatic_it_block_close (void)
15490{
15491 if (now_it.state == AUTOMATIC_IT_BLOCK)
15492 {
15493 close_automatic_it_block ();
15494 now_it.state = OUTSIDE_IT_BLOCK;
15495 now_it.mask = 0;
15496 }
15497}
15498
15499static int
15500in_it_block (void)
15501{
15502 if (!now_it.state_handled)
15503 handle_it_state ();
15504
15505 return now_it.state != OUTSIDE_IT_BLOCK;
15506}
15507
c19d1205
ZW
15508void
15509md_assemble (char *str)
b99bd4ef 15510{
c19d1205
ZW
15511 char *p = str;
15512 const struct asm_opcode * opcode;
b99bd4ef 15513
c19d1205
ZW
15514 /* Align the previous label if needed. */
15515 if (last_label_seen != NULL)
b99bd4ef 15516 {
c19d1205
ZW
15517 symbol_set_frag (last_label_seen, frag_now);
15518 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15519 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15520 }
15521
c19d1205
ZW
15522 memset (&inst, '\0', sizeof (inst));
15523 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15524
c19d1205
ZW
15525 opcode = opcode_lookup (&p);
15526 if (!opcode)
b99bd4ef 15527 {
c19d1205 15528 /* It wasn't an instruction, but it might be a register alias of
dcbf9037 15529 the form alias .req reg, or a Neon .dn/.qn directive. */
c921be7d
NC
15530 if (! create_register_alias (str, p)
15531 && ! create_neon_reg_alias (str, p))
c19d1205 15532 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15533
b99bd4ef
NC
15534 return;
15535 }
15536
278df34e 15537 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15538 as_warn (_("s suffix on comparison instruction is deprecated"));
15539
037e8744
JB
15540 /* The value which unconditional instructions should have in place of the
15541 condition field. */
15542 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15543
c19d1205 15544 if (thumb_mode)
b99bd4ef 15545 {
e74cfd16 15546 arm_feature_set variant;
8f06b2d8
PB
15547
15548 variant = cpu_variant;
15549 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15550 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15551 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15552 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15553 if (!opcode->tvariant
15554 || (thumb_mode == 1
15555 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15556 {
c19d1205 15557 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
15558 return;
15559 }
c19d1205
ZW
15560 if (inst.cond != COND_ALWAYS && !unified_syntax
15561 && opcode->tencode != do_t_branch)
b99bd4ef 15562 {
c19d1205 15563 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15564 return;
15565 }
15566
752d5da4 15567 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2))
076d447c 15568 {
7e806470 15569 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
752d5da4
NC
15570 && !(ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_msr)
15571 || ARM_CPU_HAS_FEATURE(*opcode->tvariant, arm_ext_barrier)))
15572 {
15573 /* Two things are addressed here.
15574 1) Implicit require narrow instructions on Thumb-1.
15575 This avoids relaxation accidentally introducing Thumb-2
15576 instructions.
15577 2) Reject wide instructions in non Thumb-2 cores. */
15578 if (inst.size_req == 0)
15579 inst.size_req = 2;
15580 else if (inst.size_req == 4)
15581 {
15582 as_bad (_("selected processor does not support `%s'"), str);
15583 return;
15584 }
15585 }
076d447c
PB
15586 }
15587
c19d1205
ZW
15588 inst.instruction = opcode->tvalue;
15589
15590 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15591 {
15592 /* Prepare the it_insn_type for those encodings that don't set
15593 it. */
15594 it_fsm_pre_encode ();
c19d1205 15595
e07e6e58
NC
15596 opcode->tencode ();
15597
15598 it_fsm_post_encode ();
15599 }
e27ec89e 15600
0110f2b8 15601 if (!(inst.error || inst.relax))
b99bd4ef 15602 {
9c2799c2 15603 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15604 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15605 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15606 {
c19d1205 15607 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15608 return;
15609 }
15610 }
076d447c
PB
15611
15612 /* Something has gone badly wrong if we try to relax a fixed size
15613 instruction. */
9c2799c2 15614 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15615
e74cfd16
PB
15616 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15617 *opcode->tvariant);
ee065d83 15618 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15619 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15620 anything other than bl/blx and v6-M instructions.
ee065d83 15621 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15622 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15623 || inst.relax)
e07e6e58
NC
15624 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15625 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15626 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15627 arm_ext_v6t2);
cd000bff
DJ
15628
15629 if (!inst.error)
c877a2f2
NC
15630 {
15631 mapping_state (MAP_THUMB);
15632 }
c19d1205 15633 }
3e9e4fcf 15634 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15635 {
845b51d6
PB
15636 bfd_boolean is_bx;
15637
15638 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15639 is_bx = (opcode->aencode == do_bx);
15640
c19d1205 15641 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15642 if (!(is_bx && fix_v4bx)
15643 && !(opcode->avariant &&
15644 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15645 {
c19d1205
ZW
15646 as_bad (_("selected processor does not support `%s'"), str);
15647 return;
b99bd4ef 15648 }
c19d1205 15649 if (inst.size_req)
b99bd4ef 15650 {
c19d1205
ZW
15651 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15652 return;
b99bd4ef
NC
15653 }
15654
c19d1205
ZW
15655 inst.instruction = opcode->avalue;
15656 if (opcode->tag == OT_unconditionalF)
15657 inst.instruction |= 0xF << 28;
15658 else
15659 inst.instruction |= inst.cond << 28;
15660 inst.size = INSN_SIZE;
15661 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15662 {
15663 it_fsm_pre_encode ();
15664 opcode->aencode ();
15665 it_fsm_post_encode ();
15666 }
ee065d83
PB
15667 /* Arm mode bx is marked as both v4T and v5 because it's still required
15668 on a hypothetical non-thumb v5 core. */
845b51d6 15669 if (is_bx)
e74cfd16 15670 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15671 else
e74cfd16
PB
15672 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15673 *opcode->avariant);
cd000bff 15674 if (!inst.error)
c877a2f2
NC
15675 {
15676 mapping_state (MAP_ARM);
15677 }
b99bd4ef 15678 }
3e9e4fcf
JB
15679 else
15680 {
15681 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15682 "-- `%s'"), str);
15683 return;
15684 }
c19d1205
ZW
15685 output_inst (str);
15686}
b99bd4ef 15687
e07e6e58
NC
15688static void
15689check_it_blocks_finished (void)
15690{
15691#ifdef OBJ_ELF
15692 asection *sect;
15693
15694 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15695 if (seg_info (sect)->tc_segment_info_data.current_it.state
15696 == MANUAL_IT_BLOCK)
15697 {
15698 as_warn (_("section '%s' finished with an open IT block."),
15699 sect->name);
15700 }
15701#else
15702 if (now_it.state == MANUAL_IT_BLOCK)
15703 as_warn (_("file finished with an open IT block."));
15704#endif
15705}
15706
c19d1205
ZW
15707/* Various frobbings of labels and their addresses. */
15708
15709void
15710arm_start_line_hook (void)
15711{
15712 last_label_seen = NULL;
b99bd4ef
NC
15713}
15714
c19d1205
ZW
15715void
15716arm_frob_label (symbolS * sym)
b99bd4ef 15717{
c19d1205 15718 last_label_seen = sym;
b99bd4ef 15719
c19d1205 15720 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15721
c19d1205
ZW
15722#if defined OBJ_COFF || defined OBJ_ELF
15723 ARM_SET_INTERWORK (sym, support_interwork);
15724#endif
b99bd4ef 15725
e07e6e58
NC
15726 force_automatic_it_block_close ();
15727
5f4273c7 15728 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15729 as Thumb functions. This is because these labels, whilst
15730 they exist inside Thumb code, are not the entry points for
15731 possible ARM->Thumb calls. Also, these labels can be used
15732 as part of a computed goto or switch statement. eg gcc
15733 can generate code that looks like this:
b99bd4ef 15734
c19d1205
ZW
15735 ldr r2, [pc, .Laaa]
15736 lsl r3, r3, #2
15737 ldr r2, [r3, r2]
15738 mov pc, r2
b99bd4ef 15739
c19d1205
ZW
15740 .Lbbb: .word .Lxxx
15741 .Lccc: .word .Lyyy
15742 ..etc...
15743 .Laaa: .word Lbbb
b99bd4ef 15744
c19d1205
ZW
15745 The first instruction loads the address of the jump table.
15746 The second instruction converts a table index into a byte offset.
15747 The third instruction gets the jump address out of the table.
15748 The fourth instruction performs the jump.
b99bd4ef 15749
c19d1205
ZW
15750 If the address stored at .Laaa is that of a symbol which has the
15751 Thumb_Func bit set, then the linker will arrange for this address
15752 to have the bottom bit set, which in turn would mean that the
15753 address computation performed by the third instruction would end
15754 up with the bottom bit set. Since the ARM is capable of unaligned
15755 word loads, the instruction would then load the incorrect address
15756 out of the jump table, and chaos would ensue. */
15757 if (label_is_thumb_function_name
15758 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15759 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15760 {
c19d1205
ZW
15761 /* When the address of a Thumb function is taken the bottom
15762 bit of that address should be set. This will allow
15763 interworking between Arm and Thumb functions to work
15764 correctly. */
b99bd4ef 15765
c19d1205 15766 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15767
c19d1205 15768 label_is_thumb_function_name = FALSE;
b99bd4ef 15769 }
07a53e5c 15770
07a53e5c 15771 dwarf2_emit_label (sym);
b99bd4ef
NC
15772}
15773
c921be7d 15774bfd_boolean
c19d1205 15775arm_data_in_code (void)
b99bd4ef 15776{
c19d1205 15777 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15778 {
c19d1205
ZW
15779 *input_line_pointer = '/';
15780 input_line_pointer += 5;
15781 *input_line_pointer = 0;
c921be7d 15782 return TRUE;
b99bd4ef
NC
15783 }
15784
c921be7d 15785 return FALSE;
b99bd4ef
NC
15786}
15787
c19d1205
ZW
15788char *
15789arm_canonicalize_symbol_name (char * name)
b99bd4ef 15790{
c19d1205 15791 int len;
b99bd4ef 15792
c19d1205
ZW
15793 if (thumb_mode && (len = strlen (name)) > 5
15794 && streq (name + len - 5, "/data"))
15795 *(name + len - 5) = 0;
b99bd4ef 15796
c19d1205 15797 return name;
b99bd4ef 15798}
c19d1205
ZW
15799\f
15800/* Table of all register names defined by default. The user can
15801 define additional names with .req. Note that all register names
15802 should appear in both upper and lowercase variants. Some registers
15803 also have mixed-case names. */
b99bd4ef 15804
dcbf9037 15805#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15806#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15807#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15808#define REGSET(p,t) \
15809 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15810 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15811 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15812 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15813#define REGSETH(p,t) \
15814 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15815 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15816 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15817 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15818#define REGSET2(p,t) \
15819 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15820 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15821 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15822 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15823
c19d1205 15824static const struct reg_entry reg_names[] =
7ed4c4c5 15825{
c19d1205
ZW
15826 /* ARM integer registers. */
15827 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15828
c19d1205
ZW
15829 /* ATPCS synonyms. */
15830 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15831 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15832 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 15833
c19d1205
ZW
15834 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15835 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15836 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 15837
c19d1205
ZW
15838 /* Well-known aliases. */
15839 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15840 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15841
15842 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15843 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15844
15845 /* Coprocessor numbers. */
15846 REGSET(p, CP), REGSET(P, CP),
15847
15848 /* Coprocessor register numbers. The "cr" variants are for backward
15849 compatibility. */
15850 REGSET(c, CN), REGSET(C, CN),
15851 REGSET(cr, CN), REGSET(CR, CN),
15852
15853 /* FPA registers. */
15854 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15855 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15856
15857 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15858 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15859
15860 /* VFP SP registers. */
5287ad62
JB
15861 REGSET(s,VFS), REGSET(S,VFS),
15862 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15863
15864 /* VFP DP Registers. */
5287ad62
JB
15865 REGSET(d,VFD), REGSET(D,VFD),
15866 /* Extra Neon DP registers. */
15867 REGSETH(d,VFD), REGSETH(D,VFD),
15868
15869 /* Neon QP registers. */
15870 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15871
15872 /* VFP control registers. */
15873 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15874 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15875 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15876 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15877 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15878 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15879
15880 /* Maverick DSP coprocessor registers. */
15881 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15882 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15883
15884 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15885 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15886 REGDEF(dspsc,0,DSPSC),
15887
15888 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15889 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15890 REGDEF(DSPSC,0,DSPSC),
15891
15892 /* iWMMXt data registers - p0, c0-15. */
15893 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15894
15895 /* iWMMXt control registers - p1, c0-3. */
15896 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15897 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15898 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15899 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15900
15901 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15902 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15903 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15904 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15905 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15906
15907 /* XScale accumulator registers. */
15908 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15909};
15910#undef REGDEF
15911#undef REGNUM
15912#undef REGSET
7ed4c4c5 15913
c19d1205
ZW
15914/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15915 within psr_required_here. */
15916static const struct asm_psr psrs[] =
15917{
15918 /* Backward compatibility notation. Note that "all" is no longer
15919 truly all possible PSR bits. */
15920 {"all", PSR_c | PSR_f},
15921 {"flg", PSR_f},
15922 {"ctl", PSR_c},
15923
15924 /* Individual flags. */
15925 {"f", PSR_f},
15926 {"c", PSR_c},
15927 {"x", PSR_x},
15928 {"s", PSR_s},
15929 /* Combinations of flags. */
15930 {"fs", PSR_f | PSR_s},
15931 {"fx", PSR_f | PSR_x},
15932 {"fc", PSR_f | PSR_c},
15933 {"sf", PSR_s | PSR_f},
15934 {"sx", PSR_s | PSR_x},
15935 {"sc", PSR_s | PSR_c},
15936 {"xf", PSR_x | PSR_f},
15937 {"xs", PSR_x | PSR_s},
15938 {"xc", PSR_x | PSR_c},
15939 {"cf", PSR_c | PSR_f},
15940 {"cs", PSR_c | PSR_s},
15941 {"cx", PSR_c | PSR_x},
15942 {"fsx", PSR_f | PSR_s | PSR_x},
15943 {"fsc", PSR_f | PSR_s | PSR_c},
15944 {"fxs", PSR_f | PSR_x | PSR_s},
15945 {"fxc", PSR_f | PSR_x | PSR_c},
15946 {"fcs", PSR_f | PSR_c | PSR_s},
15947 {"fcx", PSR_f | PSR_c | PSR_x},
15948 {"sfx", PSR_s | PSR_f | PSR_x},
15949 {"sfc", PSR_s | PSR_f | PSR_c},
15950 {"sxf", PSR_s | PSR_x | PSR_f},
15951 {"sxc", PSR_s | PSR_x | PSR_c},
15952 {"scf", PSR_s | PSR_c | PSR_f},
15953 {"scx", PSR_s | PSR_c | PSR_x},
15954 {"xfs", PSR_x | PSR_f | PSR_s},
15955 {"xfc", PSR_x | PSR_f | PSR_c},
15956 {"xsf", PSR_x | PSR_s | PSR_f},
15957 {"xsc", PSR_x | PSR_s | PSR_c},
15958 {"xcf", PSR_x | PSR_c | PSR_f},
15959 {"xcs", PSR_x | PSR_c | PSR_s},
15960 {"cfs", PSR_c | PSR_f | PSR_s},
15961 {"cfx", PSR_c | PSR_f | PSR_x},
15962 {"csf", PSR_c | PSR_s | PSR_f},
15963 {"csx", PSR_c | PSR_s | PSR_x},
15964 {"cxf", PSR_c | PSR_x | PSR_f},
15965 {"cxs", PSR_c | PSR_x | PSR_s},
15966 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15967 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15968 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15969 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15970 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15971 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15972 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15973 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15974 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15975 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15976 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15977 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15978 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15979 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15980 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15981 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15982 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15983 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15984 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15985 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15986 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15987 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15988 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15989 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15990};
15991
62b3e311
PB
15992/* Table of V7M psr names. */
15993static const struct asm_psr v7m_psrs[] =
15994{
2b744c99
PB
15995 {"apsr", 0 }, {"APSR", 0 },
15996 {"iapsr", 1 }, {"IAPSR", 1 },
15997 {"eapsr", 2 }, {"EAPSR", 2 },
15998 {"psr", 3 }, {"PSR", 3 },
15999 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
16000 {"ipsr", 5 }, {"IPSR", 5 },
16001 {"epsr", 6 }, {"EPSR", 6 },
16002 {"iepsr", 7 }, {"IEPSR", 7 },
16003 {"msp", 8 }, {"MSP", 8 },
16004 {"psp", 9 }, {"PSP", 9 },
16005 {"primask", 16}, {"PRIMASK", 16},
16006 {"basepri", 17}, {"BASEPRI", 17},
16007 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
16008 {"faultmask", 19}, {"FAULTMASK", 19},
16009 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
16010};
16011
c19d1205
ZW
16012/* Table of all shift-in-operand names. */
16013static const struct asm_shift_name shift_names [] =
b99bd4ef 16014{
c19d1205
ZW
16015 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
16016 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
16017 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
16018 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
16019 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
16020 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
16021};
b99bd4ef 16022
c19d1205
ZW
16023/* Table of all explicit relocation names. */
16024#ifdef OBJ_ELF
16025static struct reloc_entry reloc_names[] =
16026{
16027 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
16028 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
16029 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
16030 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
16031 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
16032 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
16033 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
16034 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
16035 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
16036 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
16037 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
16038};
16039#endif
b99bd4ef 16040
c19d1205
ZW
16041/* Table of all conditional affixes. 0xF is not defined as a condition code. */
16042static const struct asm_cond conds[] =
16043{
16044 {"eq", 0x0},
16045 {"ne", 0x1},
16046 {"cs", 0x2}, {"hs", 0x2},
16047 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
16048 {"mi", 0x4},
16049 {"pl", 0x5},
16050 {"vs", 0x6},
16051 {"vc", 0x7},
16052 {"hi", 0x8},
16053 {"ls", 0x9},
16054 {"ge", 0xa},
16055 {"lt", 0xb},
16056 {"gt", 0xc},
16057 {"le", 0xd},
16058 {"al", 0xe}
16059};
bfae80f2 16060
62b3e311
PB
16061static struct asm_barrier_opt barrier_opt_names[] =
16062{
16063 { "sy", 0xf },
16064 { "un", 0x7 },
16065 { "st", 0xe },
16066 { "unst", 0x6 }
16067};
16068
c19d1205
ZW
16069/* Table of ARM-format instructions. */
16070
16071/* Macros for gluing together operand strings. N.B. In all cases
16072 other than OPS0, the trailing OP_stop comes from default
16073 zero-initialization of the unspecified elements of the array. */
16074#define OPS0() { OP_stop, }
16075#define OPS1(a) { OP_##a, }
16076#define OPS2(a,b) { OP_##a,OP_##b, }
16077#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
16078#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
16079#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
16080#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
16081
16082/* These macros abstract out the exact format of the mnemonic table and
16083 save some repeated characters. */
16084
16085/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
16086#define TxCE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16087 { mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 16088 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16089
16090/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
16091 a T_MNEM_xyz enumerator. */
16092#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16093 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16094#define tCE(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16095 TxCE (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16096
16097/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
16098 infix after the third character. */
16099#define TxC3(mnem, op, top, nops, ops, ae, te) \
21d799b5 16100 { mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 16101 THUMB_VARIANT, do_##ae, do_##te }
088fa78e 16102#define TxC3w(mnem, op, top, nops, ops, ae, te) \
21d799b5 16103 { mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
088fa78e 16104 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 16105#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16106 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 16107#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 16108 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 16109#define tC3(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16110 TxC3 (mnem, aop, T_MNEM##top, nops, ops, ae, te)
088fa78e 16111#define tC3w(mnem, aop, top, nops, ops, ae, te) \
21d799b5 16112 TxC3w (mnem, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16113
16114/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
16115 appear in the condition table. */
16116#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
21d799b5 16117 { m1 #m2 m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
1887dd22 16118 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16119
16120#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
16121 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
16122 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
16123 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
16124 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
16125 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
16126 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
16127 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
16128 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
16129 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
16130 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
16131 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
16132 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
16133 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
16134 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
16135 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
16136 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
16137 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
16138 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
16139 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
16140
16141#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
16142 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
16143#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
21d799b5 16144 TxCM (m1,m2, aop, T_MNEM##top, nops, ops, ae, te)
c19d1205
ZW
16145
16146/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
16147 field is still 0xE. Many of the Thumb variants can be executed
16148 conditionally, so this is checked separately. */
c19d1205 16149#define TUE(mnem, op, top, nops, ops, ae, te) \
21d799b5 16150 { mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16151 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16152
16153/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
16154 condition code field. */
16155#define TUF(mnem, op, top, nops, ops, ae, te) \
21d799b5 16156 { mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 16157 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
16158
16159/* ARM-only variants of all the above. */
6a86118a 16160#define CE(mnem, op, nops, ops, ae) \
21d799b5 16161 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
6a86118a
NC
16162
16163#define C3(mnem, op, nops, ops, ae) \
16164 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16165
e3cb604e
PB
16166/* Legacy mnemonics that always have conditional infix after the third
16167 character. */
16168#define CL(mnem, op, nops, ops, ae) \
21d799b5 16169 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16170 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16171
8f06b2d8
PB
16172/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
16173#define cCE(mnem, op, nops, ops, ae) \
21d799b5 16174 { mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16175
e3cb604e
PB
16176/* Legacy coprocessor instructions where conditional infix and conditional
16177 suffix are ambiguous. For consistency this includes all FPA instructions,
16178 not just the potentially ambiguous ones. */
16179#define cCL(mnem, op, nops, ops, ae) \
21d799b5 16180 { mnem, OPS##nops ops, OT_cinfix3_legacy, \
e3cb604e
PB
16181 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
16182
16183/* Coprocessor, takes either a suffix or a position-3 infix
16184 (for an FPA corner case). */
16185#define C3E(mnem, op, nops, ops, ae) \
21d799b5 16186 { mnem, OPS##nops ops, OT_csuf_or_in3, \
e3cb604e 16187 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 16188
6a86118a 16189#define xCM_(m1, m2, m3, op, nops, ops, ae) \
21d799b5
NC
16190 { m1 #m2 m3, OPS##nops ops, \
16191 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (m1) - 1, \
6a86118a
NC
16192 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
16193
16194#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
16195 xCM_ (m1, , m2, op, nops, ops, ae), \
16196 xCM_ (m1, eq, m2, op, nops, ops, ae), \
16197 xCM_ (m1, ne, m2, op, nops, ops, ae), \
16198 xCM_ (m1, cs, m2, op, nops, ops, ae), \
16199 xCM_ (m1, hs, m2, op, nops, ops, ae), \
16200 xCM_ (m1, cc, m2, op, nops, ops, ae), \
16201 xCM_ (m1, ul, m2, op, nops, ops, ae), \
16202 xCM_ (m1, lo, m2, op, nops, ops, ae), \
16203 xCM_ (m1, mi, m2, op, nops, ops, ae), \
16204 xCM_ (m1, pl, m2, op, nops, ops, ae), \
16205 xCM_ (m1, vs, m2, op, nops, ops, ae), \
16206 xCM_ (m1, vc, m2, op, nops, ops, ae), \
16207 xCM_ (m1, hi, m2, op, nops, ops, ae), \
16208 xCM_ (m1, ls, m2, op, nops, ops, ae), \
16209 xCM_ (m1, ge, m2, op, nops, ops, ae), \
16210 xCM_ (m1, lt, m2, op, nops, ops, ae), \
16211 xCM_ (m1, gt, m2, op, nops, ops, ae), \
16212 xCM_ (m1, le, m2, op, nops, ops, ae), \
16213 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
16214
16215#define UE(mnem, op, nops, ops, ae) \
16216 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16217
16218#define UF(mnem, op, nops, ops, ae) \
16219 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
16220
5287ad62
JB
16221/* Neon data-processing. ARM versions are unconditional with cond=0xf.
16222 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
16223 use the same encoding function for each. */
16224#define NUF(mnem, op, nops, ops, enc) \
16225 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
16226 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16227
16228/* Neon data processing, version which indirects through neon_enc_tab for
16229 the various overloaded versions of opcodes. */
16230#define nUF(mnem, op, nops, ops, enc) \
21d799b5 16231 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16232 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16233
16234/* Neon insn with conditional suffix for the ARM version, non-overloaded
16235 version. */
037e8744
JB
16236#define NCE_tag(mnem, op, nops, ops, enc, tag) \
16237 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
16238 THUMB_VARIANT, do_##enc, do_##enc }
16239
037e8744 16240#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 16241 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16242
16243#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 16244 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16245
5287ad62 16246/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744 16247#define nCE_tag(mnem, op, nops, ops, enc, tag) \
21d799b5 16248 { #mnem, OPS##nops ops, tag, N_MNEM##op, N_MNEM##op, \
5287ad62
JB
16249 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
16250
037e8744 16251#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 16252 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
16253
16254#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 16255 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 16256
c19d1205
ZW
16257#define do_0 0
16258
16259/* Thumb-only, unconditional. */
e07e6e58 16260#define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
c19d1205 16261
c19d1205 16262static const struct asm_opcode insns[] =
bfae80f2 16263{
e74cfd16
PB
16264#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
16265#define THUMB_VARIANT &arm_ext_v4t
21d799b5
NC
16266 tCE("and", 0000000, _and, 3, (RR, oRR, SH), arit, t_arit3c),
16267 tC3("ands", 0100000, _ands, 3, (RR, oRR, SH), arit, t_arit3c),
16268 tCE("eor", 0200000, _eor, 3, (RR, oRR, SH), arit, t_arit3c),
16269 tC3("eors", 0300000, _eors, 3, (RR, oRR, SH), arit, t_arit3c),
16270 tCE("sub", 0400000, _sub, 3, (RR, oRR, SH), arit, t_add_sub),
16271 tC3("subs", 0500000, _subs, 3, (RR, oRR, SH), arit, t_add_sub),
16272 tCE("add", 0800000, _add, 3, (RR, oRR, SHG), arit, t_add_sub),
16273 tC3("adds", 0900000, _adds, 3, (RR, oRR, SHG), arit, t_add_sub),
16274 tCE("adc", 0a00000, _adc, 3, (RR, oRR, SH), arit, t_arit3c),
16275 tC3("adcs", 0b00000, _adcs, 3, (RR, oRR, SH), arit, t_arit3c),
16276 tCE("sbc", 0c00000, _sbc, 3, (RR, oRR, SH), arit, t_arit3),
16277 tC3("sbcs", 0d00000, _sbcs, 3, (RR, oRR, SH), arit, t_arit3),
16278 tCE("orr", 1800000, _orr, 3, (RR, oRR, SH), arit, t_arit3c),
16279 tC3("orrs", 1900000, _orrs, 3, (RR, oRR, SH), arit, t_arit3c),
16280 tCE("bic", 1c00000, _bic, 3, (RR, oRR, SH), arit, t_arit3),
16281 tC3("bics", 1d00000, _bics, 3, (RR, oRR, SH), arit, t_arit3),
c19d1205
ZW
16282
16283 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
16284 for setting PSR flag bits. They are obsolete in V6 and do not
16285 have Thumb equivalents. */
21d799b5
NC
16286 tCE("tst", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16287 tC3w("tsts", 1100000, _tst, 2, (RR, SH), cmp, t_mvn_tst),
16288 CL("tstp", 110f000, 2, (RR, SH), cmp),
16289 tCE("cmp", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16290 tC3w("cmps", 1500000, _cmp, 2, (RR, SH), cmp, t_mov_cmp),
16291 CL("cmpp", 150f000, 2, (RR, SH), cmp),
16292 tCE("cmn", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16293 tC3w("cmns", 1700000, _cmn, 2, (RR, SH), cmp, t_mvn_tst),
16294 CL("cmnp", 170f000, 2, (RR, SH), cmp),
16295
16296 tCE("mov", 1a00000, _mov, 2, (RR, SH), mov, t_mov_cmp),
16297 tC3("movs", 1b00000, _movs, 2, (RR, SH), mov, t_mov_cmp),
16298 tCE("mvn", 1e00000, _mvn, 2, (RR, SH), mov, t_mvn_tst),
16299 tC3("mvns", 1f00000, _mvns, 2, (RR, SH), mov, t_mvn_tst),
16300
16301 tCE("ldr", 4100000, _ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
16302 tC3("ldrb", 4500000, _ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16303 tCE("str", 4000000, _str, 2, (RR, ADDRGLDR),ldst, t_ldst),
16304 tC3("strb", 4400000, _strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
16305
16306 tCE("stm", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16307 tC3("stmia", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16308 tC3("stmea", 8800000, _stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16309 tCE("ldm", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16310 tC3("ldmia", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16311 tC3("ldmfd", 8900000, _ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16312
16313 TCE("swi", f000000, df00, 1, (EXPi), swi, t_swi),
16314 TCE("svc", f000000, df00, 1, (EXPi), swi, t_swi),
16315 tCE("b", a000000, _b, 1, (EXPr), branch, t_branch),
16316 TCE("bl", b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 16317
c19d1205 16318 /* Pseudo ops. */
21d799b5 16319 tCE("adr", 28f0000, _adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac 16320 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
21d799b5 16321 tCE("nop", 1a00000, _nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
16322
16323 /* Thumb-compatibility pseudo ops. */
21d799b5
NC
16324 tCE("lsl", 1a00000, _lsl, 3, (RR, oRR, SH), shift, t_shift),
16325 tC3("lsls", 1b00000, _lsls, 3, (RR, oRR, SH), shift, t_shift),
16326 tCE("lsr", 1a00020, _lsr, 3, (RR, oRR, SH), shift, t_shift),
16327 tC3("lsrs", 1b00020, _lsrs, 3, (RR, oRR, SH), shift, t_shift),
16328 tCE("asr", 1a00040, _asr, 3, (RR, oRR, SH), shift, t_shift),
16329 tC3("asrs", 1b00040, _asrs, 3, (RR, oRR, SH), shift, t_shift),
16330 tCE("ror", 1a00060, _ror, 3, (RR, oRR, SH), shift, t_shift),
16331 tC3("rors", 1b00060, _rors, 3, (RR, oRR, SH), shift, t_shift),
16332 tCE("neg", 2600000, _neg, 2, (RR, RR), rd_rn, t_neg),
16333 tC3("negs", 2700000, _negs, 2, (RR, RR), rd_rn, t_neg),
16334 tCE("push", 92d0000, _push, 1, (REGLST), push_pop, t_push_pop),
16335 tCE("pop", 8bd0000, _pop, 1, (REGLST), push_pop, t_push_pop),
c19d1205 16336
16a4cf17 16337 /* These may simplify to neg. */
21d799b5
NC
16338 TCE("rsb", 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
16339 TC3("rsbs", 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
16a4cf17 16340
c921be7d
NC
16341#undef THUMB_VARIANT
16342#define THUMB_VARIANT & arm_ext_v6
16343
21d799b5 16344 TCE("cpy", 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
16345
16346 /* V1 instructions with no Thumb analogue prior to V6T2. */
c921be7d
NC
16347#undef THUMB_VARIANT
16348#define THUMB_VARIANT & arm_ext_v6t2
16349
21d799b5
NC
16350 TCE("teq", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16351 TC3w("teqs", 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16352 CL("teqp", 130f000, 2, (RR, SH), cmp),
c19d1205 16353
21d799b5
NC
16354 TC3("ldrt", 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
16355 TC3("ldrbt", 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
16356 TC3("strt", 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
16357 TC3("strbt", 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 16358
21d799b5
NC
16359 TC3("stmdb", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16360 TC3("stmfd", 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16361
21d799b5
NC
16362 TC3("ldmdb", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16363 TC3("ldmea", 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16364
16365 /* V1 instructions with no Thumb analogue at all. */
21d799b5 16366 CE("rsc", 0e00000, 3, (RR, oRR, SH), arit),
c19d1205
ZW
16367 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16368
16369 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16370 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16371 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16372 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16373 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16374 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16375 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16376 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16377
c921be7d
NC
16378#undef ARM_VARIANT
16379#define ARM_VARIANT & arm_ext_v2 /* ARM 2 - multiplies. */
16380#undef THUMB_VARIANT
16381#define THUMB_VARIANT & arm_ext_v4t
16382
21d799b5
NC
16383 tCE("mul", 0000090, _mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16384 tC3("muls", 0100090, _muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
c19d1205 16385
c921be7d
NC
16386#undef THUMB_VARIANT
16387#define THUMB_VARIANT & arm_ext_v6t2
16388
21d799b5 16389 TCE("mla", 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
c19d1205
ZW
16390 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16391
16392 /* Generic coprocessor instructions. */
21d799b5
NC
16393 TCE("cdp", e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16394 TCE("ldc", c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16395 TC3("ldcl", c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16396 TCE("stc", c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16397 TC3("stcl", c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16398 TCE("mcr", e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16399 TCE("mrc", e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16400
c921be7d
NC
16401#undef ARM_VARIANT
16402#define ARM_VARIANT & arm_ext_v2s /* ARM 3 - swp instructions. */
16403
21d799b5 16404 CE("swp", 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
c19d1205
ZW
16405 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16406
c921be7d
NC
16407#undef ARM_VARIANT
16408#define ARM_VARIANT & arm_ext_v3 /* ARM 6 Status register instructions. */
16409#undef THUMB_VARIANT
16410#define THUMB_VARIANT & arm_ext_msr
16411
21d799b5
NC
16412 TCE("mrs", 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16413 TCE("msr", 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205 16414
c921be7d
NC
16415#undef ARM_VARIANT
16416#define ARM_VARIANT & arm_ext_v3m /* ARM 7M long multiplies. */
16417#undef THUMB_VARIANT
16418#define THUMB_VARIANT & arm_ext_v6t2
16419
21d799b5
NC
16420 TCE("smull", 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16421 CM("smull","s", 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16422 TCE("umull", 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16423 CM("umull","s", 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16424 TCE("smlal", 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16425 CM("smlal","s", 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16426 TCE("umlal", 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16427 CM("umlal","s", 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
c19d1205 16428
c921be7d
NC
16429#undef ARM_VARIANT
16430#define ARM_VARIANT & arm_ext_v4 /* ARM Architecture 4. */
16431#undef THUMB_VARIANT
16432#define THUMB_VARIANT & arm_ext_v4t
16433
21d799b5
NC
16434 tC3("ldrh", 01000b0, _ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16435 tC3("strh", 00000b0, _strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16436 tC3("ldrsh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16437 tC3("ldrsb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16438 tCM("ld","sh", 01000f0, _ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16439 tCM("ld","sb", 01000d0, _ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205 16440
c921be7d
NC
16441#undef ARM_VARIANT
16442#define ARM_VARIANT & arm_ext_v4t_5
16443
c19d1205
ZW
16444 /* ARM Architecture 4T. */
16445 /* Note: bx (and blx) are required on V5, even if the processor does
16446 not support Thumb. */
21d799b5 16447 TCE("bx", 12fff10, 4700, 1, (RR), bx, t_bx),
c19d1205 16448
c921be7d
NC
16449#undef ARM_VARIANT
16450#define ARM_VARIANT & arm_ext_v5 /* ARM Architecture 5T. */
16451#undef THUMB_VARIANT
16452#define THUMB_VARIANT & arm_ext_v5t
16453
c19d1205
ZW
16454 /* Note: blx has 2 variants; the .value coded here is for
16455 BLX(2). Only this variant has conditional execution. */
21d799b5
NC
16456 TCE("blx", 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16457 TUE("bkpt", 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
c19d1205 16458
c921be7d
NC
16459#undef THUMB_VARIANT
16460#define THUMB_VARIANT & arm_ext_v6t2
16461
21d799b5
NC
16462 TCE("clz", 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
16463 TUF("ldc2", c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16464 TUF("ldc2l", c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16465 TUF("stc2", c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16466 TUF("stc2l", c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16467 TUF("cdp2", e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16468 TUF("mcr2", e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16469 TUF("mrc2", e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
c19d1205 16470
c921be7d
NC
16471#undef ARM_VARIANT
16472#define ARM_VARIANT & arm_ext_v5exp /* ARM Architecture 5TExP. */
9e3c6df6
PB
16473#undef THUMB_VARIANT
16474#define THUMB_VARIANT &arm_ext_v5exp
c921be7d 16475
21d799b5
NC
16476 TCE("smlabb", 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16477 TCE("smlatb", 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16478 TCE("smlabt", 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16479 TCE("smlatt", 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16480
21d799b5
NC
16481 TCE("smlawb", 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16482 TCE("smlawt", 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
c19d1205 16483
21d799b5
NC
16484 TCE("smlalbb", 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16485 TCE("smlaltb", 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16486 TCE("smlalbt", 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16487 TCE("smlaltt", 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
c19d1205 16488
21d799b5
NC
16489 TCE("smulbb", 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16490 TCE("smultb", 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16491 TCE("smulbt", 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16492 TCE("smultt", 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16493
21d799b5
NC
16494 TCE("smulwb", 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16495 TCE("smulwt", 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
c19d1205 16496
21d799b5
NC
16497 TCE("qadd", 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16498 TCE("qdadd", 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16499 TCE("qsub", 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16500 TCE("qdsub", 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205 16501
c921be7d
NC
16502#undef ARM_VARIANT
16503#define ARM_VARIANT & arm_ext_v5e /* ARM Architecture 5TE. */
9e3c6df6
PB
16504#undef THUMB_VARIANT
16505#define THUMB_VARIANT &arm_ext_v6t2
c921be7d 16506
21d799b5
NC
16507 TUF("pld", 450f000, f810f000, 1, (ADDR), pld, t_pld),
16508 TC3("ldrd", 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16509 TC3("strd", 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205 16510
21d799b5
NC
16511 TCE("mcrr", c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16512 TCE("mrrc", c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
c19d1205 16513
c921be7d
NC
16514#undef ARM_VARIANT
16515#define ARM_VARIANT & arm_ext_v5j /* ARM Architecture 5TEJ. */
16516
21d799b5 16517 TCE("bxj", 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
c19d1205 16518
c921be7d
NC
16519#undef ARM_VARIANT
16520#define ARM_VARIANT & arm_ext_v6 /* ARM V6. */
16521#undef THUMB_VARIANT
16522#define THUMB_VARIANT & arm_ext_v6
16523
21d799b5
NC
16524 TUF("cpsie", 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16525 TUF("cpsid", 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16526 tCE("rev", 6bf0f30, _rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16527 tCE("rev16", 6bf0fb0, _rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16528 tCE("revsh", 6ff0fb0, _revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16529 tCE("sxth", 6bf0070, _sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16530 tCE("uxth", 6ff0070, _uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16531 tCE("sxtb", 6af0070, _sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16532 tCE("uxtb", 6ef0070, _uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16533 TUF("setend", 1010000, b650, 1, (ENDI), setend, t_setend),
c19d1205 16534
c921be7d
NC
16535#undef THUMB_VARIANT
16536#define THUMB_VARIANT & arm_ext_v6t2
16537
21d799b5
NC
16538 TCE("ldrex", 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
16539 TCE("strex", 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
16540 TUF("mcrr2", c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16541 TUF("mrrc2", c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311 16542
21d799b5
NC
16543 TCE("ssat", 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16544 TCE("usat", 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
62b3e311 16545
9e3c6df6 16546/* ARM V6 not included in V7M. */
c921be7d
NC
16547#undef THUMB_VARIANT
16548#define THUMB_VARIANT & arm_ext_v6_notm
9e3c6df6
PB
16549 TUF("rfeia", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16550 UF(rfeib, 9900a00, 1, (RRw), rfe),
16551 UF(rfeda, 8100a00, 1, (RRw), rfe),
16552 TUF("rfedb", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16553 TUF("rfefd", 8900a00, e990c000, 1, (RRw), rfe, rfe),
16554 UF(rfefa, 9900a00, 1, (RRw), rfe),
16555 UF(rfeea, 8100a00, 1, (RRw), rfe),
16556 TUF("rfeed", 9100a00, e810c000, 1, (RRw), rfe, rfe),
16557 TUF("srsia", 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16558 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16559 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16560 TUF("srsdb", 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c921be7d 16561
9e3c6df6
PB
16562/* ARM V6 not included in V7M (eg. integer SIMD). */
16563#undef THUMB_VARIANT
16564#define THUMB_VARIANT & arm_ext_v6_dsp
21d799b5
NC
16565 TUF("cps", 1020000, f3af8100, 1, (I31b), imm0, t_cps),
16566 TCE("pkhbt", 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16567 TCE("pkhtb", 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16568 TCE("qadd16", 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16569 TCE("qadd8", 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16570 TCE("qasx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16571 /* Old name for QASX. */
21d799b5
NC
16572 TCE("qaddsubx", 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16573 TCE("qsax", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16574 /* Old name for QSAX. */
21d799b5
NC
16575 TCE("qsubaddx", 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16576 TCE("qsub16", 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16577 TCE("qsub8", 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16578 TCE("sadd16", 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16579 TCE("sadd8", 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16580 TCE("sasx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16581 /* Old name for SASX. */
21d799b5
NC
16582 TCE("saddsubx", 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16583 TCE("shadd16", 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16584 TCE("shadd8", 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16585 TCE("shasx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16586 /* Old name for SHASX. */
21d799b5
NC
16587 TCE("shaddsubx", 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16588 TCE("shsax", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16589 /* Old name for SHSAX. */
21d799b5
NC
16590 TCE("shsubaddx", 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16591 TCE("shsub16", 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16592 TCE("shsub8", 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16593 TCE("ssax", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16594 /* Old name for SSAX. */
21d799b5
NC
16595 TCE("ssubaddx", 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16596 TCE("ssub16", 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16597 TCE("ssub8", 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16598 TCE("uadd16", 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16599 TCE("uadd8", 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16600 TCE("uasx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16601 /* Old name for UASX. */
21d799b5
NC
16602 TCE("uaddsubx", 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16603 TCE("uhadd16", 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16604 TCE("uhadd8", 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16605 TCE("uhasx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16606 /* Old name for UHASX. */
21d799b5
NC
16607 TCE("uhaddsubx", 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16608 TCE("uhsax", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16609 /* Old name for UHSAX. */
21d799b5
NC
16610 TCE("uhsubaddx", 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16611 TCE("uhsub16", 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16612 TCE("uhsub8", 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16613 TCE("uqadd16", 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16614 TCE("uqadd8", 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16615 TCE("uqasx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16616 /* Old name for UQASX. */
21d799b5
NC
16617 TCE("uqaddsubx", 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16618 TCE("uqsax", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16619 /* Old name for UQSAX. */
21d799b5
NC
16620 TCE("uqsubaddx", 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16621 TCE("uqsub16", 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16622 TCE("uqsub8", 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16623 TCE("usub16", 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16624 TCE("usax", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16625 /* Old name for USAX. */
21d799b5
NC
16626 TCE("usubaddx", 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16627 TCE("usub8", 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
21d799b5
NC
16628 TCE("sxtah", 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16629 TCE("sxtab16", 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16630 TCE("sxtab", 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16631 TCE("sxtb16", 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16632 TCE("uxtah", 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16633 TCE("uxtab16", 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16634 TCE("uxtab", 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16635 TCE("uxtb16", 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16636 TCE("sel", 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16637 TCE("smlad", 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16638 TCE("smladx", 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16639 TCE("smlald", 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16640 TCE("smlaldx", 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16641 TCE("smlsd", 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16642 TCE("smlsdx", 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16643 TCE("smlsld", 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16644 TCE("smlsldx", 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16645 TCE("smmla", 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16646 TCE("smmlar", 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16647 TCE("smmls", 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16648 TCE("smmlsr", 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16649 TCE("smmul", 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16650 TCE("smmulr", 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16651 TCE("smuad", 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16652 TCE("smuadx", 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16653 TCE("smusd", 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16654 TCE("smusdx", 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
21d799b5
NC
16655 TCE("ssat16", 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
16656 TCE("umaal", 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16657 TCE("usad8", 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16658 TCE("usada8", 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16659 TCE("usat16", 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
c19d1205 16660
c921be7d
NC
16661#undef ARM_VARIANT
16662#define ARM_VARIANT & arm_ext_v6k
16663#undef THUMB_VARIANT
16664#define THUMB_VARIANT & arm_ext_v6k
16665
21d799b5
NC
16666 tCE("yield", 320f001, _yield, 0, (), noargs, t_hint),
16667 tCE("wfe", 320f002, _wfe, 0, (), noargs, t_hint),
16668 tCE("wfi", 320f003, _wfi, 0, (), noargs, t_hint),
16669 tCE("sev", 320f004, _sev, 0, (), noargs, t_hint),
c19d1205 16670
c921be7d
NC
16671#undef THUMB_VARIANT
16672#define THUMB_VARIANT & arm_ext_v6_notm
16673
21d799b5
NC
16674 TCE("ldrexd", 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
16675 TCE("strexd", 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
ebdca51a 16676
c921be7d
NC
16677#undef THUMB_VARIANT
16678#define THUMB_VARIANT & arm_ext_v6t2
16679
21d799b5
NC
16680 TCE("ldrexb", 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16681 TCE("ldrexh", 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16682 TCE("strexb", 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16683 TCE("strexh", 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16684 TUF("clrex", 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
c19d1205 16685
c921be7d
NC
16686#undef ARM_VARIANT
16687#define ARM_VARIANT & arm_ext_v6z
16688
21d799b5 16689 TCE("smc", 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205 16690
c921be7d
NC
16691#undef ARM_VARIANT
16692#define ARM_VARIANT & arm_ext_v6t2
16693
21d799b5
NC
16694 TCE("bfc", 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16695 TCE("bfi", 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16696 TCE("sbfx", 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16697 TCE("ubfx", 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
c19d1205 16698
21d799b5
NC
16699 TCE("mls", 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16700 TCE("movw", 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16701 TCE("movt", 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16702 TCE("rbit", 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205 16703
21d799b5
NC
16704 TC3("ldrht", 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16705 TC3("ldrsht", 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16706 TC3("ldrsbt", 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16707 TC3("strht", 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
c19d1205 16708
21d799b5
NC
16709 UT("cbnz", b900, 2, (RR, EXP), t_cbz),
16710 UT("cbz", b100, 2, (RR, EXP), t_cbz),
c921be7d
NC
16711
16712 /* ARM does not really have an IT instruction, so always allow it.
16713 The opcode is copied from Thumb in order to allow warnings in
16714 -mimplicit-it=[never | arm] modes. */
16715#undef ARM_VARIANT
16716#define ARM_VARIANT & arm_ext_v1
16717
21d799b5
NC
16718 TUE("it", bf08, bf08, 1, (COND), it, t_it),
16719 TUE("itt", bf0c, bf0c, 1, (COND), it, t_it),
16720 TUE("ite", bf04, bf04, 1, (COND), it, t_it),
16721 TUE("ittt", bf0e, bf0e, 1, (COND), it, t_it),
16722 TUE("itet", bf06, bf06, 1, (COND), it, t_it),
16723 TUE("itte", bf0a, bf0a, 1, (COND), it, t_it),
16724 TUE("itee", bf02, bf02, 1, (COND), it, t_it),
16725 TUE("itttt", bf0f, bf0f, 1, (COND), it, t_it),
16726 TUE("itett", bf07, bf07, 1, (COND), it, t_it),
16727 TUE("ittet", bf0b, bf0b, 1, (COND), it, t_it),
16728 TUE("iteet", bf03, bf03, 1, (COND), it, t_it),
16729 TUE("ittte", bf0d, bf0d, 1, (COND), it, t_it),
16730 TUE("itete", bf05, bf05, 1, (COND), it, t_it),
16731 TUE("ittee", bf09, bf09, 1, (COND), it, t_it),
16732 TUE("iteee", bf01, bf01, 1, (COND), it, t_it),
1c444d06 16733 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
21d799b5
NC
16734 TC3("rrx", 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16735 TC3("rrxs", 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16736
92e90b6e 16737 /* Thumb2 only instructions. */
c921be7d
NC
16738#undef ARM_VARIANT
16739#define ARM_VARIANT NULL
92e90b6e 16740
21d799b5
NC
16741 TCE("addw", 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16742 TCE("subw", 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16743 TCE("orn", 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16744 TCE("orns", 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16745 TCE("tbb", 0, e8d0f000, 1, (TB), 0, t_tb),
16746 TCE("tbh", 0, e8d0f010, 1, (TB), 0, t_tb),
92e90b6e 16747
62b3e311 16748 /* Thumb-2 hardware division instructions (R and M profiles only). */
c921be7d
NC
16749#undef THUMB_VARIANT
16750#define THUMB_VARIANT & arm_ext_div
16751
21d799b5
NC
16752 TCE("sdiv", 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16753 TCE("udiv", 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
62b3e311 16754
7e806470 16755 /* ARM V6M/V7 instructions. */
c921be7d
NC
16756#undef ARM_VARIANT
16757#define ARM_VARIANT & arm_ext_barrier
16758#undef THUMB_VARIANT
16759#define THUMB_VARIANT & arm_ext_barrier
16760
21d799b5
NC
16761 TUF("dmb", 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16762 TUF("dsb", 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16763 TUF("isb", 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
7e806470 16764
62b3e311 16765 /* ARM V7 instructions. */
c921be7d
NC
16766#undef ARM_VARIANT
16767#define ARM_VARIANT & arm_ext_v7
16768#undef THUMB_VARIANT
16769#define THUMB_VARIANT & arm_ext_v7
16770
21d799b5
NC
16771 TUF("pli", 450f000, f910f000, 1, (ADDR), pli, t_pld),
16772 TCE("dbg", 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16773
c921be7d
NC
16774#undef ARM_VARIANT
16775#define ARM_VARIANT & fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
16776
21d799b5
NC
16777 cCE("wfs", e200110, 1, (RR), rd),
16778 cCE("rfs", e300110, 1, (RR), rd),
16779 cCE("wfc", e400110, 1, (RR), rd),
16780 cCE("rfc", e500110, 1, (RR), rd),
16781
16782 cCL("ldfs", c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16783 cCL("ldfd", c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16784 cCL("ldfe", c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16785 cCL("ldfp", c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
16786
16787 cCL("stfs", c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16788 cCL("stfd", c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16789 cCL("stfe", c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16790 cCL("stfp", c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
16791
16792 cCL("mvfs", e008100, 2, (RF, RF_IF), rd_rm),
16793 cCL("mvfsp", e008120, 2, (RF, RF_IF), rd_rm),
16794 cCL("mvfsm", e008140, 2, (RF, RF_IF), rd_rm),
16795 cCL("mvfsz", e008160, 2, (RF, RF_IF), rd_rm),
16796 cCL("mvfd", e008180, 2, (RF, RF_IF), rd_rm),
16797 cCL("mvfdp", e0081a0, 2, (RF, RF_IF), rd_rm),
16798 cCL("mvfdm", e0081c0, 2, (RF, RF_IF), rd_rm),
16799 cCL("mvfdz", e0081e0, 2, (RF, RF_IF), rd_rm),
16800 cCL("mvfe", e088100, 2, (RF, RF_IF), rd_rm),
16801 cCL("mvfep", e088120, 2, (RF, RF_IF), rd_rm),
16802 cCL("mvfem", e088140, 2, (RF, RF_IF), rd_rm),
16803 cCL("mvfez", e088160, 2, (RF, RF_IF), rd_rm),
16804
16805 cCL("mnfs", e108100, 2, (RF, RF_IF), rd_rm),
16806 cCL("mnfsp", e108120, 2, (RF, RF_IF), rd_rm),
16807 cCL("mnfsm", e108140, 2, (RF, RF_IF), rd_rm),
16808 cCL("mnfsz", e108160, 2, (RF, RF_IF), rd_rm),
16809 cCL("mnfd", e108180, 2, (RF, RF_IF), rd_rm),
16810 cCL("mnfdp", e1081a0, 2, (RF, RF_IF), rd_rm),
16811 cCL("mnfdm", e1081c0, 2, (RF, RF_IF), rd_rm),
16812 cCL("mnfdz", e1081e0, 2, (RF, RF_IF), rd_rm),
16813 cCL("mnfe", e188100, 2, (RF, RF_IF), rd_rm),
16814 cCL("mnfep", e188120, 2, (RF, RF_IF), rd_rm),
16815 cCL("mnfem", e188140, 2, (RF, RF_IF), rd_rm),
16816 cCL("mnfez", e188160, 2, (RF, RF_IF), rd_rm),
16817
16818 cCL("abss", e208100, 2, (RF, RF_IF), rd_rm),
16819 cCL("abssp", e208120, 2, (RF, RF_IF), rd_rm),
16820 cCL("abssm", e208140, 2, (RF, RF_IF), rd_rm),
16821 cCL("abssz", e208160, 2, (RF, RF_IF), rd_rm),
16822 cCL("absd", e208180, 2, (RF, RF_IF), rd_rm),
16823 cCL("absdp", e2081a0, 2, (RF, RF_IF), rd_rm),
16824 cCL("absdm", e2081c0, 2, (RF, RF_IF), rd_rm),
16825 cCL("absdz", e2081e0, 2, (RF, RF_IF), rd_rm),
16826 cCL("abse", e288100, 2, (RF, RF_IF), rd_rm),
16827 cCL("absep", e288120, 2, (RF, RF_IF), rd_rm),
16828 cCL("absem", e288140, 2, (RF, RF_IF), rd_rm),
16829 cCL("absez", e288160, 2, (RF, RF_IF), rd_rm),
16830
16831 cCL("rnds", e308100, 2, (RF, RF_IF), rd_rm),
16832 cCL("rndsp", e308120, 2, (RF, RF_IF), rd_rm),
16833 cCL("rndsm", e308140, 2, (RF, RF_IF), rd_rm),
16834 cCL("rndsz", e308160, 2, (RF, RF_IF), rd_rm),
16835 cCL("rndd", e308180, 2, (RF, RF_IF), rd_rm),
16836 cCL("rnddp", e3081a0, 2, (RF, RF_IF), rd_rm),
16837 cCL("rnddm", e3081c0, 2, (RF, RF_IF), rd_rm),
16838 cCL("rnddz", e3081e0, 2, (RF, RF_IF), rd_rm),
16839 cCL("rnde", e388100, 2, (RF, RF_IF), rd_rm),
16840 cCL("rndep", e388120, 2, (RF, RF_IF), rd_rm),
16841 cCL("rndem", e388140, 2, (RF, RF_IF), rd_rm),
16842 cCL("rndez", e388160, 2, (RF, RF_IF), rd_rm),
16843
16844 cCL("sqts", e408100, 2, (RF, RF_IF), rd_rm),
16845 cCL("sqtsp", e408120, 2, (RF, RF_IF), rd_rm),
16846 cCL("sqtsm", e408140, 2, (RF, RF_IF), rd_rm),
16847 cCL("sqtsz", e408160, 2, (RF, RF_IF), rd_rm),
16848 cCL("sqtd", e408180, 2, (RF, RF_IF), rd_rm),
16849 cCL("sqtdp", e4081a0, 2, (RF, RF_IF), rd_rm),
16850 cCL("sqtdm", e4081c0, 2, (RF, RF_IF), rd_rm),
16851 cCL("sqtdz", e4081e0, 2, (RF, RF_IF), rd_rm),
16852 cCL("sqte", e488100, 2, (RF, RF_IF), rd_rm),
16853 cCL("sqtep", e488120, 2, (RF, RF_IF), rd_rm),
16854 cCL("sqtem", e488140, 2, (RF, RF_IF), rd_rm),
16855 cCL("sqtez", e488160, 2, (RF, RF_IF), rd_rm),
16856
16857 cCL("logs", e508100, 2, (RF, RF_IF), rd_rm),
16858 cCL("logsp", e508120, 2, (RF, RF_IF), rd_rm),
16859 cCL("logsm", e508140, 2, (RF, RF_IF), rd_rm),
16860 cCL("logsz", e508160, 2, (RF, RF_IF), rd_rm),
16861 cCL("logd", e508180, 2, (RF, RF_IF), rd_rm),
16862 cCL("logdp", e5081a0, 2, (RF, RF_IF), rd_rm),
16863 cCL("logdm", e5081c0, 2, (RF, RF_IF), rd_rm),
16864 cCL("logdz", e5081e0, 2, (RF, RF_IF), rd_rm),
16865 cCL("loge", e588100, 2, (RF, RF_IF), rd_rm),
16866 cCL("logep", e588120, 2, (RF, RF_IF), rd_rm),
16867 cCL("logem", e588140, 2, (RF, RF_IF), rd_rm),
16868 cCL("logez", e588160, 2, (RF, RF_IF), rd_rm),
16869
16870 cCL("lgns", e608100, 2, (RF, RF_IF), rd_rm),
16871 cCL("lgnsp", e608120, 2, (RF, RF_IF), rd_rm),
16872 cCL("lgnsm", e608140, 2, (RF, RF_IF), rd_rm),
16873 cCL("lgnsz", e608160, 2, (RF, RF_IF), rd_rm),
16874 cCL("lgnd", e608180, 2, (RF, RF_IF), rd_rm),
16875 cCL("lgndp", e6081a0, 2, (RF, RF_IF), rd_rm),
16876 cCL("lgndm", e6081c0, 2, (RF, RF_IF), rd_rm),
16877 cCL("lgndz", e6081e0, 2, (RF, RF_IF), rd_rm),
16878 cCL("lgne", e688100, 2, (RF, RF_IF), rd_rm),
16879 cCL("lgnep", e688120, 2, (RF, RF_IF), rd_rm),
16880 cCL("lgnem", e688140, 2, (RF, RF_IF), rd_rm),
16881 cCL("lgnez", e688160, 2, (RF, RF_IF), rd_rm),
16882
16883 cCL("exps", e708100, 2, (RF, RF_IF), rd_rm),
16884 cCL("expsp", e708120, 2, (RF, RF_IF), rd_rm),
16885 cCL("expsm", e708140, 2, (RF, RF_IF), rd_rm),
16886 cCL("expsz", e708160, 2, (RF, RF_IF), rd_rm),
16887 cCL("expd", e708180, 2, (RF, RF_IF), rd_rm),
16888 cCL("expdp", e7081a0, 2, (RF, RF_IF), rd_rm),
16889 cCL("expdm", e7081c0, 2, (RF, RF_IF), rd_rm),
16890 cCL("expdz", e7081e0, 2, (RF, RF_IF), rd_rm),
16891 cCL("expe", e788100, 2, (RF, RF_IF), rd_rm),
16892 cCL("expep", e788120, 2, (RF, RF_IF), rd_rm),
16893 cCL("expem", e788140, 2, (RF, RF_IF), rd_rm),
16894 cCL("expdz", e788160, 2, (RF, RF_IF), rd_rm),
16895
16896 cCL("sins", e808100, 2, (RF, RF_IF), rd_rm),
16897 cCL("sinsp", e808120, 2, (RF, RF_IF), rd_rm),
16898 cCL("sinsm", e808140, 2, (RF, RF_IF), rd_rm),
16899 cCL("sinsz", e808160, 2, (RF, RF_IF), rd_rm),
16900 cCL("sind", e808180, 2, (RF, RF_IF), rd_rm),
16901 cCL("sindp", e8081a0, 2, (RF, RF_IF), rd_rm),
16902 cCL("sindm", e8081c0, 2, (RF, RF_IF), rd_rm),
16903 cCL("sindz", e8081e0, 2, (RF, RF_IF), rd_rm),
16904 cCL("sine", e888100, 2, (RF, RF_IF), rd_rm),
16905 cCL("sinep", e888120, 2, (RF, RF_IF), rd_rm),
16906 cCL("sinem", e888140, 2, (RF, RF_IF), rd_rm),
16907 cCL("sinez", e888160, 2, (RF, RF_IF), rd_rm),
16908
16909 cCL("coss", e908100, 2, (RF, RF_IF), rd_rm),
16910 cCL("cossp", e908120, 2, (RF, RF_IF), rd_rm),
16911 cCL("cossm", e908140, 2, (RF, RF_IF), rd_rm),
16912 cCL("cossz", e908160, 2, (RF, RF_IF), rd_rm),
16913 cCL("cosd", e908180, 2, (RF, RF_IF), rd_rm),
16914 cCL("cosdp", e9081a0, 2, (RF, RF_IF), rd_rm),
16915 cCL("cosdm", e9081c0, 2, (RF, RF_IF), rd_rm),
16916 cCL("cosdz", e9081e0, 2, (RF, RF_IF), rd_rm),
16917 cCL("cose", e988100, 2, (RF, RF_IF), rd_rm),
16918 cCL("cosep", e988120, 2, (RF, RF_IF), rd_rm),
16919 cCL("cosem", e988140, 2, (RF, RF_IF), rd_rm),
16920 cCL("cosez", e988160, 2, (RF, RF_IF), rd_rm),
16921
16922 cCL("tans", ea08100, 2, (RF, RF_IF), rd_rm),
16923 cCL("tansp", ea08120, 2, (RF, RF_IF), rd_rm),
16924 cCL("tansm", ea08140, 2, (RF, RF_IF), rd_rm),
16925 cCL("tansz", ea08160, 2, (RF, RF_IF), rd_rm),
16926 cCL("tand", ea08180, 2, (RF, RF_IF), rd_rm),
16927 cCL("tandp", ea081a0, 2, (RF, RF_IF), rd_rm),
16928 cCL("tandm", ea081c0, 2, (RF, RF_IF), rd_rm),
16929 cCL("tandz", ea081e0, 2, (RF, RF_IF), rd_rm),
16930 cCL("tane", ea88100, 2, (RF, RF_IF), rd_rm),
16931 cCL("tanep", ea88120, 2, (RF, RF_IF), rd_rm),
16932 cCL("tanem", ea88140, 2, (RF, RF_IF), rd_rm),
16933 cCL("tanez", ea88160, 2, (RF, RF_IF), rd_rm),
16934
16935 cCL("asns", eb08100, 2, (RF, RF_IF), rd_rm),
16936 cCL("asnsp", eb08120, 2, (RF, RF_IF), rd_rm),
16937 cCL("asnsm", eb08140, 2, (RF, RF_IF), rd_rm),
16938 cCL("asnsz", eb08160, 2, (RF, RF_IF), rd_rm),
16939 cCL("asnd", eb08180, 2, (RF, RF_IF), rd_rm),
16940 cCL("asndp", eb081a0, 2, (RF, RF_IF), rd_rm),
16941 cCL("asndm", eb081c0, 2, (RF, RF_IF), rd_rm),
16942 cCL("asndz", eb081e0, 2, (RF, RF_IF), rd_rm),
16943 cCL("asne", eb88100, 2, (RF, RF_IF), rd_rm),
16944 cCL("asnep", eb88120, 2, (RF, RF_IF), rd_rm),
16945 cCL("asnem", eb88140, 2, (RF, RF_IF), rd_rm),
16946 cCL("asnez", eb88160, 2, (RF, RF_IF), rd_rm),
16947
16948 cCL("acss", ec08100, 2, (RF, RF_IF), rd_rm),
16949 cCL("acssp", ec08120, 2, (RF, RF_IF), rd_rm),
16950 cCL("acssm", ec08140, 2, (RF, RF_IF), rd_rm),
16951 cCL("acssz", ec08160, 2, (RF, RF_IF), rd_rm),
16952 cCL("acsd", ec08180, 2, (RF, RF_IF), rd_rm),
16953 cCL("acsdp", ec081a0, 2, (RF, RF_IF), rd_rm),
16954 cCL("acsdm", ec081c0, 2, (RF, RF_IF), rd_rm),
16955 cCL("acsdz", ec081e0, 2, (RF, RF_IF), rd_rm),
16956 cCL("acse", ec88100, 2, (RF, RF_IF), rd_rm),
16957 cCL("acsep", ec88120, 2, (RF, RF_IF), rd_rm),
16958 cCL("acsem", ec88140, 2, (RF, RF_IF), rd_rm),
16959 cCL("acsez", ec88160, 2, (RF, RF_IF), rd_rm),
16960
16961 cCL("atns", ed08100, 2, (RF, RF_IF), rd_rm),
16962 cCL("atnsp", ed08120, 2, (RF, RF_IF), rd_rm),
16963 cCL("atnsm", ed08140, 2, (RF, RF_IF), rd_rm),
16964 cCL("atnsz", ed08160, 2, (RF, RF_IF), rd_rm),
16965 cCL("atnd", ed08180, 2, (RF, RF_IF), rd_rm),
16966 cCL("atndp", ed081a0, 2, (RF, RF_IF), rd_rm),
16967 cCL("atndm", ed081c0, 2, (RF, RF_IF), rd_rm),
16968 cCL("atndz", ed081e0, 2, (RF, RF_IF), rd_rm),
16969 cCL("atne", ed88100, 2, (RF, RF_IF), rd_rm),
16970 cCL("atnep", ed88120, 2, (RF, RF_IF), rd_rm),
16971 cCL("atnem", ed88140, 2, (RF, RF_IF), rd_rm),
16972 cCL("atnez", ed88160, 2, (RF, RF_IF), rd_rm),
16973
16974 cCL("urds", ee08100, 2, (RF, RF_IF), rd_rm),
16975 cCL("urdsp", ee08120, 2, (RF, RF_IF), rd_rm),
16976 cCL("urdsm", ee08140, 2, (RF, RF_IF), rd_rm),
16977 cCL("urdsz", ee08160, 2, (RF, RF_IF), rd_rm),
16978 cCL("urdd", ee08180, 2, (RF, RF_IF), rd_rm),
16979 cCL("urddp", ee081a0, 2, (RF, RF_IF), rd_rm),
16980 cCL("urddm", ee081c0, 2, (RF, RF_IF), rd_rm),
16981 cCL("urddz", ee081e0, 2, (RF, RF_IF), rd_rm),
16982 cCL("urde", ee88100, 2, (RF, RF_IF), rd_rm),
16983 cCL("urdep", ee88120, 2, (RF, RF_IF), rd_rm),
16984 cCL("urdem", ee88140, 2, (RF, RF_IF), rd_rm),
16985 cCL("urdez", ee88160, 2, (RF, RF_IF), rd_rm),
16986
16987 cCL("nrms", ef08100, 2, (RF, RF_IF), rd_rm),
16988 cCL("nrmsp", ef08120, 2, (RF, RF_IF), rd_rm),
16989 cCL("nrmsm", ef08140, 2, (RF, RF_IF), rd_rm),
16990 cCL("nrmsz", ef08160, 2, (RF, RF_IF), rd_rm),
16991 cCL("nrmd", ef08180, 2, (RF, RF_IF), rd_rm),
16992 cCL("nrmdp", ef081a0, 2, (RF, RF_IF), rd_rm),
16993 cCL("nrmdm", ef081c0, 2, (RF, RF_IF), rd_rm),
16994 cCL("nrmdz", ef081e0, 2, (RF, RF_IF), rd_rm),
16995 cCL("nrme", ef88100, 2, (RF, RF_IF), rd_rm),
16996 cCL("nrmep", ef88120, 2, (RF, RF_IF), rd_rm),
16997 cCL("nrmem", ef88140, 2, (RF, RF_IF), rd_rm),
16998 cCL("nrmez", ef88160, 2, (RF, RF_IF), rd_rm),
16999
17000 cCL("adfs", e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
17001 cCL("adfsp", e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
17002 cCL("adfsm", e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
17003 cCL("adfsz", e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
17004 cCL("adfd", e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
17005 cCL("adfdp", e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17006 cCL("adfdm", e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17007 cCL("adfdz", e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17008 cCL("adfe", e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
17009 cCL("adfep", e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
17010 cCL("adfem", e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
17011 cCL("adfez", e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
17012
17013 cCL("sufs", e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
17014 cCL("sufsp", e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
17015 cCL("sufsm", e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
17016 cCL("sufsz", e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
17017 cCL("sufd", e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
17018 cCL("sufdp", e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17019 cCL("sufdm", e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17020 cCL("sufdz", e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17021 cCL("sufe", e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
17022 cCL("sufep", e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
17023 cCL("sufem", e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
17024 cCL("sufez", e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
17025
17026 cCL("rsfs", e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
17027 cCL("rsfsp", e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
17028 cCL("rsfsm", e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
17029 cCL("rsfsz", e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
17030 cCL("rsfd", e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
17031 cCL("rsfdp", e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17032 cCL("rsfdm", e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17033 cCL("rsfdz", e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17034 cCL("rsfe", e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
17035 cCL("rsfep", e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
17036 cCL("rsfem", e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
17037 cCL("rsfez", e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
17038
17039 cCL("mufs", e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
17040 cCL("mufsp", e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
17041 cCL("mufsm", e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
17042 cCL("mufsz", e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
17043 cCL("mufd", e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
17044 cCL("mufdp", e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17045 cCL("mufdm", e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17046 cCL("mufdz", e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17047 cCL("mufe", e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
17048 cCL("mufep", e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
17049 cCL("mufem", e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
17050 cCL("mufez", e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
17051
17052 cCL("dvfs", e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
17053 cCL("dvfsp", e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
17054 cCL("dvfsm", e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
17055 cCL("dvfsz", e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
17056 cCL("dvfd", e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
17057 cCL("dvfdp", e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17058 cCL("dvfdm", e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17059 cCL("dvfdz", e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17060 cCL("dvfe", e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
17061 cCL("dvfep", e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
17062 cCL("dvfem", e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
17063 cCL("dvfez", e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
17064
17065 cCL("rdfs", e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
17066 cCL("rdfsp", e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
17067 cCL("rdfsm", e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
17068 cCL("rdfsz", e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
17069 cCL("rdfd", e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
17070 cCL("rdfdp", e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17071 cCL("rdfdm", e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17072 cCL("rdfdz", e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17073 cCL("rdfe", e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
17074 cCL("rdfep", e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
17075 cCL("rdfem", e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
17076 cCL("rdfez", e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
17077
17078 cCL("pows", e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
17079 cCL("powsp", e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
17080 cCL("powsm", e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
17081 cCL("powsz", e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
17082 cCL("powd", e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
17083 cCL("powdp", e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17084 cCL("powdm", e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17085 cCL("powdz", e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17086 cCL("powe", e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
17087 cCL("powep", e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
17088 cCL("powem", e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
17089 cCL("powez", e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
17090
17091 cCL("rpws", e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
17092 cCL("rpwsp", e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
17093 cCL("rpwsm", e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
17094 cCL("rpwsz", e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
17095 cCL("rpwd", e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
17096 cCL("rpwdp", e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17097 cCL("rpwdm", e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17098 cCL("rpwdz", e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17099 cCL("rpwe", e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
17100 cCL("rpwep", e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
17101 cCL("rpwem", e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
17102 cCL("rpwez", e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
17103
17104 cCL("rmfs", e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
17105 cCL("rmfsp", e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
17106 cCL("rmfsm", e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
17107 cCL("rmfsz", e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
17108 cCL("rmfd", e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
17109 cCL("rmfdp", e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17110 cCL("rmfdm", e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17111 cCL("rmfdz", e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17112 cCL("rmfe", e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
17113 cCL("rmfep", e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
17114 cCL("rmfem", e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
17115 cCL("rmfez", e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
17116
17117 cCL("fmls", e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
17118 cCL("fmlsp", e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
17119 cCL("fmlsm", e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
17120 cCL("fmlsz", e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
17121 cCL("fmld", e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
17122 cCL("fmldp", e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17123 cCL("fmldm", e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17124 cCL("fmldz", e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17125 cCL("fmle", e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
17126 cCL("fmlep", e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
17127 cCL("fmlem", e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
17128 cCL("fmlez", e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
17129
17130 cCL("fdvs", ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17131 cCL("fdvsp", ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17132 cCL("fdvsm", ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17133 cCL("fdvsz", ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17134 cCL("fdvd", ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17135 cCL("fdvdp", ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17136 cCL("fdvdm", ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17137 cCL("fdvdz", ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17138 cCL("fdve", ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17139 cCL("fdvep", ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17140 cCL("fdvem", ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17141 cCL("fdvez", ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17142
17143 cCL("frds", eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17144 cCL("frdsp", eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17145 cCL("frdsm", eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17146 cCL("frdsz", eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17147 cCL("frdd", eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17148 cCL("frddp", eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17149 cCL("frddm", eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17150 cCL("frddz", eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17151 cCL("frde", eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17152 cCL("frdep", eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17153 cCL("frdem", eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17154 cCL("frdez", eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17155
17156 cCL("pols", ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
17157 cCL("polsp", ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
17158 cCL("polsm", ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
17159 cCL("polsz", ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
17160 cCL("pold", ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
17161 cCL("poldp", ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
17162 cCL("poldm", ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
17163 cCL("poldz", ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
17164 cCL("pole", ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
17165 cCL("polep", ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
17166 cCL("polem", ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
17167 cCL("polez", ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
17168
17169 cCE("cmf", e90f110, 2, (RF, RF_IF), fpa_cmp),
17170 C3E("cmfe", ed0f110, 2, (RF, RF_IF), fpa_cmp),
17171 cCE("cnf", eb0f110, 2, (RF, RF_IF), fpa_cmp),
17172 C3E("cnfe", ef0f110, 2, (RF, RF_IF), fpa_cmp),
17173
17174 cCL("flts", e000110, 2, (RF, RR), rn_rd),
17175 cCL("fltsp", e000130, 2, (RF, RR), rn_rd),
17176 cCL("fltsm", e000150, 2, (RF, RR), rn_rd),
17177 cCL("fltsz", e000170, 2, (RF, RR), rn_rd),
17178 cCL("fltd", e000190, 2, (RF, RR), rn_rd),
17179 cCL("fltdp", e0001b0, 2, (RF, RR), rn_rd),
17180 cCL("fltdm", e0001d0, 2, (RF, RR), rn_rd),
17181 cCL("fltdz", e0001f0, 2, (RF, RR), rn_rd),
17182 cCL("flte", e080110, 2, (RF, RR), rn_rd),
17183 cCL("fltep", e080130, 2, (RF, RR), rn_rd),
17184 cCL("fltem", e080150, 2, (RF, RR), rn_rd),
17185 cCL("fltez", e080170, 2, (RF, RR), rn_rd),
b99bd4ef 17186
c19d1205
ZW
17187 /* The implementation of the FIX instruction is broken on some
17188 assemblers, in that it accepts a precision specifier as well as a
17189 rounding specifier, despite the fact that this is meaningless.
17190 To be more compatible, we accept it as well, though of course it
17191 does not set any bits. */
21d799b5
NC
17192 cCE("fix", e100110, 2, (RR, RF), rd_rm),
17193 cCL("fixp", e100130, 2, (RR, RF), rd_rm),
17194 cCL("fixm", e100150, 2, (RR, RF), rd_rm),
17195 cCL("fixz", e100170, 2, (RR, RF), rd_rm),
17196 cCL("fixsp", e100130, 2, (RR, RF), rd_rm),
17197 cCL("fixsm", e100150, 2, (RR, RF), rd_rm),
17198 cCL("fixsz", e100170, 2, (RR, RF), rd_rm),
17199 cCL("fixdp", e100130, 2, (RR, RF), rd_rm),
17200 cCL("fixdm", e100150, 2, (RR, RF), rd_rm),
17201 cCL("fixdz", e100170, 2, (RR, RF), rd_rm),
17202 cCL("fixep", e100130, 2, (RR, RF), rd_rm),
17203 cCL("fixem", e100150, 2, (RR, RF), rd_rm),
17204 cCL("fixez", e100170, 2, (RR, RF), rd_rm),
bfae80f2 17205
c19d1205 17206 /* Instructions that were new with the real FPA, call them V2. */
c921be7d
NC
17207#undef ARM_VARIANT
17208#define ARM_VARIANT & fpu_fpa_ext_v2
17209
21d799b5
NC
17210 cCE("lfm", c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17211 cCL("lfmfd", c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17212 cCL("lfmea", d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17213 cCE("sfm", c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17214 cCL("sfmfd", d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
17215 cCL("sfmea", c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205 17216
c921be7d
NC
17217#undef ARM_VARIANT
17218#define ARM_VARIANT & fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
17219
c19d1205 17220 /* Moves and type conversions. */
21d799b5
NC
17221 cCE("fcpys", eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
17222 cCE("fmrs", e100a10, 2, (RR, RVS), vfp_reg_from_sp),
17223 cCE("fmsr", e000a10, 2, (RVS, RR), vfp_sp_from_reg),
17224 cCE("fmstat", ef1fa10, 0, (), noargs),
f7c21dc7
NC
17225 cCE("vmrs", ef10a10, 2, (APSR_RR, RVC), vmrs),
17226 cCE("vmsr", ee10a10, 2, (RVC, RR), vmsr),
21d799b5
NC
17227 cCE("fsitos", eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
17228 cCE("fuitos", eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
17229 cCE("ftosis", ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
17230 cCE("ftosizs", ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17231 cCE("ftouis", ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
17232 cCE("ftouizs", ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
17233 cCE("fmrx", ef00a10, 2, (RR, RVC), rd_rn),
17234 cCE("fmxr", ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
17235
17236 /* Memory operations. */
21d799b5
NC
17237 cCE("flds", d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17238 cCE("fsts", d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
17239 cCE("fldmias", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17240 cCE("fldmfds", c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17241 cCE("fldmdbs", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17242 cCE("fldmeas", d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17243 cCE("fldmiax", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17244 cCE("fldmfdx", c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17245 cCE("fldmdbx", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17246 cCE("fldmeax", d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17247 cCE("fstmias", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17248 cCE("fstmeas", c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
17249 cCE("fstmdbs", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17250 cCE("fstmfds", d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
17251 cCE("fstmiax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17252 cCE("fstmeax", c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
17253 cCE("fstmdbx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
17254 cCE("fstmfdx", d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 17255
c19d1205 17256 /* Monadic operations. */
21d799b5
NC
17257 cCE("fabss", eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
17258 cCE("fnegs", eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
17259 cCE("fsqrts", eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
17260
17261 /* Dyadic operations. */
21d799b5
NC
17262 cCE("fadds", e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17263 cCE("fsubs", e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17264 cCE("fmuls", e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17265 cCE("fdivs", e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17266 cCE("fmacs", e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17267 cCE("fmscs", e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17268 cCE("fnmuls", e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17269 cCE("fnmacs", e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17270 cCE("fnmscs", e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 17271
c19d1205 17272 /* Comparisons. */
21d799b5
NC
17273 cCE("fcmps", eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
17274 cCE("fcmpzs", eb50a40, 1, (RVS), vfp_sp_compare_z),
17275 cCE("fcmpes", eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
17276 cCE("fcmpezs", eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 17277
62f3b8c8
PB
17278 /* Double precision load/store are still present on single precision
17279 implementations. */
17280 cCE("fldd", d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17281 cCE("fstd", d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
17282 cCE("fldmiad", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17283 cCE("fldmfdd", c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17284 cCE("fldmdbd", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17285 cCE("fldmead", d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17286 cCE("fstmiad", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17287 cCE("fstmead", c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
17288 cCE("fstmdbd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17289 cCE("fstmfdd", d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
17290
c921be7d
NC
17291#undef ARM_VARIANT
17292#define ARM_VARIANT & fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
17293
c19d1205 17294 /* Moves and type conversions. */
21d799b5
NC
17295 cCE("fcpyd", eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17296 cCE("fcvtds", eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17297 cCE("fcvtsd", eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17298 cCE("fmdhr", e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
17299 cCE("fmdlr", e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
17300 cCE("fmrdh", e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
17301 cCE("fmrdl", e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
17302 cCE("fsitod", eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
17303 cCE("fuitod", eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
17304 cCE("ftosid", ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17305 cCE("ftosizd", ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
17306 cCE("ftouid", ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
17307 cCE("ftouizd", ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205 17308
c19d1205 17309 /* Monadic operations. */
21d799b5
NC
17310 cCE("fabsd", eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17311 cCE("fnegd", eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17312 cCE("fsqrtd", eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
17313
17314 /* Dyadic operations. */
21d799b5
NC
17315 cCE("faddd", e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17316 cCE("fsubd", e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17317 cCE("fmuld", e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17318 cCE("fdivd", e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17319 cCE("fmacd", e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17320 cCE("fmscd", e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17321 cCE("fnmuld", e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17322 cCE("fnmacd", e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17323 cCE("fnmscd", e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 17324
c19d1205 17325 /* Comparisons. */
21d799b5
NC
17326 cCE("fcmpd", eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
17327 cCE("fcmpzd", eb50b40, 1, (RVD), vfp_dp_rd),
17328 cCE("fcmped", eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
17329 cCE("fcmpezd", eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205 17330
c921be7d
NC
17331#undef ARM_VARIANT
17332#define ARM_VARIANT & fpu_vfp_ext_v2
17333
21d799b5
NC
17334 cCE("fmsrr", c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
17335 cCE("fmrrs", c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
17336 cCE("fmdrr", c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
17337 cCE("fmrrd", c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
5287ad62 17338
037e8744
JB
17339/* Instructions which may belong to either the Neon or VFP instruction sets.
17340 Individual encoder functions perform additional architecture checks. */
c921be7d
NC
17341#undef ARM_VARIANT
17342#define ARM_VARIANT & fpu_vfp_ext_v1xd
17343#undef THUMB_VARIANT
17344#define THUMB_VARIANT & fpu_vfp_ext_v1xd
17345
037e8744
JB
17346 /* These mnemonics are unique to VFP. */
17347 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
17348 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
21d799b5
NC
17349 nCE(vnmul, _vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17350 nCE(vnmla, _vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17351 nCE(vnmls, _vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17352 nCE(vcmp, _vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
17353 nCE(vcmpe, _vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
037e8744
JB
17354 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
17355 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
17356 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
17357
17358 /* Mnemonics shared by Neon and VFP. */
21d799b5
NC
17359 nCEF(vmul, _vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
17360 nCEF(vmla, _vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
17361 nCEF(vmls, _vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
037e8744 17362
21d799b5
NC
17363 nCEF(vadd, _vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
17364 nCEF(vsub, _vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
037e8744
JB
17365
17366 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17367 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
17368
17369 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17370 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17371 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17372 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17373 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
17374 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
17375 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
17376 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744 17377
21d799b5
NC
17378 nCEF(vcvt, _vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
17379 nCEF(vcvtb, _vcvt, 2, (RVS, RVS), neon_cvtb),
17380 nCEF(vcvtt, _vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 17381
037e8744
JB
17382
17383 /* NOTE: All VMOV encoding is special-cased! */
17384 NCE(vmov, 0, 1, (VMOV), neon_mov),
17385 NCE(vmovq, 0, 1, (VMOV), neon_mov),
17386
c921be7d
NC
17387#undef THUMB_VARIANT
17388#define THUMB_VARIANT & fpu_neon_ext_v1
17389#undef ARM_VARIANT
17390#define ARM_VARIANT & fpu_neon_ext_v1
17391
5287ad62
JB
17392 /* Data processing with three registers of the same length. */
17393 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17394 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17395 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17396 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17397 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17398 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17399 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17400 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17401 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17402 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17403 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17404 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17405 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17406 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17407 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17408 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17409 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17410 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17411 /* If not immediate, fall back to neon_dyadic_i64_su.
17412 shl_imm should accept I8 I16 I32 I64,
17413 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
21d799b5
NC
17414 nUF(vshl, _vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17415 nUF(vshlq, _vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17416 nUF(vqshl, _vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17417 nUF(vqshlq, _vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
5287ad62 17418 /* Logic ops, types optional & ignored. */
21d799b5
NC
17419 nUF(vand, _vand, 2, (RNDQ, NILO), neon_logic),
17420 nUF(vandq, _vand, 2, (RNQ, NILO), neon_logic),
17421 nUF(vbic, _vbic, 2, (RNDQ, NILO), neon_logic),
17422 nUF(vbicq, _vbic, 2, (RNQ, NILO), neon_logic),
17423 nUF(vorr, _vorr, 2, (RNDQ, NILO), neon_logic),
17424 nUF(vorrq, _vorr, 2, (RNQ, NILO), neon_logic),
17425 nUF(vorn, _vorn, 2, (RNDQ, NILO), neon_logic),
17426 nUF(vornq, _vorn, 2, (RNQ, NILO), neon_logic),
17427 nUF(veor, _veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17428 nUF(veorq, _veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
5287ad62
JB
17429 /* Bitfield ops, untyped. */
17430 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17431 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17432 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17433 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17434 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17435 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17436 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
21d799b5
NC
17437 nUF(vabd, _vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17438 nUF(vabdq, _vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17439 nUF(vmax, _vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17440 nUF(vmaxq, _vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17441 nUF(vmin, _vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17442 nUF(vminq, _vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
5287ad62
JB
17443 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17444 back to neon_dyadic_if_su. */
21d799b5
NC
17445 nUF(vcge, _vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17446 nUF(vcgeq, _vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17447 nUF(vcgt, _vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17448 nUF(vcgtq, _vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17449 nUF(vclt, _vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17450 nUF(vcltq, _vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17451 nUF(vcle, _vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17452 nUF(vcleq, _vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17453 /* Comparison. Type I8 I16 I32 F32. */
21d799b5
NC
17454 nUF(vceq, _vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17455 nUF(vceqq, _vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
5287ad62 17456 /* As above, D registers only. */
21d799b5
NC
17457 nUF(vpmax, _vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17458 nUF(vpmin, _vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
5287ad62 17459 /* Int and float variants, signedness unimportant. */
21d799b5
NC
17460 nUF(vmlaq, _vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17461 nUF(vmlsq, _vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17462 nUF(vpadd, _vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
5287ad62 17463 /* Add/sub take types I8 I16 I32 I64 F32. */
21d799b5
NC
17464 nUF(vaddq, _vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17465 nUF(vsubq, _vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17466 /* vtst takes sizes 8, 16, 32. */
17467 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17468 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17469 /* VMUL takes I8 I16 I32 F32 P8. */
21d799b5 17470 nUF(vmulq, _vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62 17471 /* VQD{R}MULH takes S16 S32. */
21d799b5
NC
17472 nUF(vqdmulh, _vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17473 nUF(vqdmulhq, _vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17474 nUF(vqrdmulh, _vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17475 nUF(vqrdmulhq, _vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
5287ad62
JB
17476 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17477 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17478 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17479 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17480 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17481 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17482 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17483 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17484 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17485 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17486 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17487 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17488
17489 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17490 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17491 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17492
17493 /* Data processing with two registers and a shift amount. */
17494 /* Right shifts, and variants with rounding.
17495 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17496 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17497 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17498 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17499 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17500 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17501 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17502 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17503 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17504 /* Shift and insert. Sizes accepted 8 16 32 64. */
17505 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17506 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17507 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17508 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17509 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17510 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17511 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17512 /* Right shift immediate, saturating & narrowing, with rounding variants.
17513 Types accepted S16 S32 S64 U16 U32 U64. */
17514 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17515 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17516 /* As above, unsigned. Types accepted S16 S32 S64. */
17517 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17518 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17519 /* Right shift narrowing. Types accepted I16 I32 I64. */
17520 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17521 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17522 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
21d799b5 17523 nUF(vshll, _vshll, 3, (RNQ, RND, I32), neon_shll),
5287ad62 17524 /* CVT with optional immediate for fixed-point variant. */
21d799b5 17525 nUF(vcvtq, _vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17526
21d799b5
NC
17527 nUF(vmvn, _vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
17528 nUF(vmvnq, _vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
5287ad62
JB
17529
17530 /* Data processing, three registers of different lengths. */
17531 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17532 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17533 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17534 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17535 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17536 /* If not scalar, fall back to neon_dyadic_long.
17537 Vector types as above, scalar types S16 S32 U16 U32. */
21d799b5
NC
17538 nUF(vmlal, _vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17539 nUF(vmlsl, _vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
5287ad62
JB
17540 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17541 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17542 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17543 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17544 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17545 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17546 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17547 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17548 /* Saturating doubling multiplies. Types S16 S32. */
21d799b5
NC
17549 nUF(vqdmlal, _vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17550 nUF(vqdmlsl, _vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17551 nUF(vqdmull, _vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
5287ad62
JB
17552 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17553 S16 S32 U16 U32. */
21d799b5 17554 nUF(vmull, _vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
5287ad62
JB
17555
17556 /* Extract. Size 8. */
3b8d421e
PB
17557 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17558 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17559
17560 /* Two registers, miscellaneous. */
17561 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17562 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17563 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17564 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17565 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17566 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17567 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17568 /* Vector replicate. Sizes 8 16 32. */
21d799b5
NC
17569 nCE(vdup, _vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17570 nCE(vdupq, _vdup, 2, (RNQ, RR_RNSC), neon_dup),
5287ad62
JB
17571 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17572 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17573 /* VMOVN. Types I16 I32 I64. */
21d799b5 17574 nUF(vmovn, _vmovn, 2, (RND, RNQ), neon_movn),
5287ad62 17575 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
21d799b5 17576 nUF(vqmovn, _vqmovn, 2, (RND, RNQ), neon_qmovn),
5287ad62 17577 /* VQMOVUN. Types S16 S32 S64. */
21d799b5 17578 nUF(vqmovun, _vqmovun, 2, (RND, RNQ), neon_qmovun),
5287ad62
JB
17579 /* VZIP / VUZP. Sizes 8 16 32. */
17580 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17581 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17582 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17583 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17584 /* VQABS / VQNEG. Types S8 S16 S32. */
17585 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17586 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17587 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17588 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17589 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17590 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17591 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17592 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17593 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17594 /* Reciprocal estimates. Types U32 F32. */
17595 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17596 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17597 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17598 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17599 /* VCLS. Types S8 S16 S32. */
17600 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17601 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17602 /* VCLZ. Types I8 I16 I32. */
17603 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17604 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17605 /* VCNT. Size 8. */
17606 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17607 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17608 /* Two address, untyped. */
17609 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17610 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17611 /* VTRN. Sizes 8 16 32. */
21d799b5
NC
17612 nUF(vtrn, _vtrn, 2, (RNDQ, RNDQ), neon_trn),
17613 nUF(vtrnq, _vtrn, 2, (RNQ, RNQ), neon_trn),
5287ad62
JB
17614
17615 /* Table lookup. Size 8. */
17616 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17617 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17618
c921be7d
NC
17619#undef THUMB_VARIANT
17620#define THUMB_VARIANT & fpu_vfp_v3_or_neon_ext
17621#undef ARM_VARIANT
17622#define ARM_VARIANT & fpu_vfp_v3_or_neon_ext
17623
5287ad62 17624 /* Neon element/structure load/store. */
21d799b5
NC
17625 nUF(vld1, _vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17626 nUF(vst1, _vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17627 nUF(vld2, _vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17628 nUF(vst2, _vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17629 nUF(vld3, _vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17630 nUF(vst3, _vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17631 nUF(vld4, _vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17632 nUF(vst4, _vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
5287ad62 17633
c921be7d 17634#undef THUMB_VARIANT
62f3b8c8
PB
17635#define THUMB_VARIANT &fpu_vfp_ext_v3xd
17636#undef ARM_VARIANT
17637#define ARM_VARIANT &fpu_vfp_ext_v3xd
17638 cCE("fconsts", eb00a00, 2, (RVS, I255), vfp_sp_const),
17639 cCE("fshtos", eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17640 cCE("fsltos", eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17641 cCE("fuhtos", ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17642 cCE("fultos", ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17643 cCE("ftoshs", ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17644 cCE("ftosls", ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17645 cCE("ftouhs", ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17646 cCE("ftouls", ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17647
17648#undef THUMB_VARIANT
c921be7d
NC
17649#define THUMB_VARIANT & fpu_vfp_ext_v3
17650#undef ARM_VARIANT
17651#define ARM_VARIANT & fpu_vfp_ext_v3
17652
21d799b5 17653 cCE("fconstd", eb00b00, 2, (RVD, I255), vfp_dp_const),
21d799b5 17654 cCE("fshtod", eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17655 cCE("fsltod", eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17656 cCE("fuhtod", ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17657 cCE("fultod", ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17658 cCE("ftoshd", ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17659 cCE("ftosld", ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
21d799b5 17660 cCE("ftouhd", ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
21d799b5 17661 cCE("ftould", ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17662
62f3b8c8
PB
17663#undef ARM_VARIANT
17664#define ARM_VARIANT &fpu_vfp_ext_fma
17665#undef THUMB_VARIANT
17666#define THUMB_VARIANT &fpu_vfp_ext_fma
17667 /* Mnemonics shared by Neon and VFP. These are included in the
17668 VFP FMA variant; NEON and VFP FMA always includes the NEON
17669 FMA instructions. */
17670 nCEF(vfma, _vfma, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17671 nCEF(vfms, _vfms, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_fmac),
17672 /* ffmas/ffmad/ffmss/ffmsd are dummy mnemonics to satisfy gas;
17673 the v form should always be used. */
17674 cCE("ffmas", ea00a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17675 cCE("ffnmas", ea00a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
17676 cCE("ffmad", ea00b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17677 cCE("ffnmad", ea00b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
17678 nCE(vfnma, _vfnma, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17679 nCE(vfnms, _vfnms, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
17680
5287ad62 17681#undef THUMB_VARIANT
c921be7d
NC
17682#undef ARM_VARIANT
17683#define ARM_VARIANT & arm_cext_xscale /* Intel XScale extensions. */
17684
21d799b5
NC
17685 cCE("mia", e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17686 cCE("miaph", e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17687 cCE("miabb", e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17688 cCE("miabt", e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17689 cCE("miatb", e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17690 cCE("miatt", e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17691 cCE("mar", c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17692 cCE("mra", c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205 17693
c921be7d
NC
17694#undef ARM_VARIANT
17695#define ARM_VARIANT & arm_cext_iwmmxt /* Intel Wireless MMX technology. */
17696
21d799b5
NC
17697 cCE("tandcb", e13f130, 1, (RR), iwmmxt_tandorc),
17698 cCE("tandch", e53f130, 1, (RR), iwmmxt_tandorc),
17699 cCE("tandcw", e93f130, 1, (RR), iwmmxt_tandorc),
17700 cCE("tbcstb", e400010, 2, (RIWR, RR), rn_rd),
17701 cCE("tbcsth", e400050, 2, (RIWR, RR), rn_rd),
17702 cCE("tbcstw", e400090, 2, (RIWR, RR), rn_rd),
17703 cCE("textrcb", e130170, 2, (RR, I7), iwmmxt_textrc),
17704 cCE("textrch", e530170, 2, (RR, I7), iwmmxt_textrc),
17705 cCE("textrcw", e930170, 2, (RR, I7), iwmmxt_textrc),
17706 cCE("textrmub", e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17707 cCE("textrmuh", e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17708 cCE("textrmuw", e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17709 cCE("textrmsb", e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17710 cCE("textrmsh", e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17711 cCE("textrmsw", e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17712 cCE("tinsrb", e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17713 cCE("tinsrh", e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17714 cCE("tinsrw", e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17715 cCE("tmcr", e000110, 2, (RIWC_RIWG, RR), rn_rd),
17716 cCE("tmcrr", c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17717 cCE("tmia", e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17718 cCE("tmiaph", e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17719 cCE("tmiabb", e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17720 cCE("tmiabt", e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17721 cCE("tmiatb", e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17722 cCE("tmiatt", e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17723 cCE("tmovmskb", e100030, 2, (RR, RIWR), rd_rn),
17724 cCE("tmovmskh", e500030, 2, (RR, RIWR), rd_rn),
17725 cCE("tmovmskw", e900030, 2, (RR, RIWR), rd_rn),
17726 cCE("tmrc", e100110, 2, (RR, RIWC_RIWG), rd_rn),
17727 cCE("tmrrc", c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17728 cCE("torcb", e13f150, 1, (RR), iwmmxt_tandorc),
17729 cCE("torch", e53f150, 1, (RR), iwmmxt_tandorc),
17730 cCE("torcw", e93f150, 1, (RR), iwmmxt_tandorc),
17731 cCE("waccb", e0001c0, 2, (RIWR, RIWR), rd_rn),
17732 cCE("wacch", e4001c0, 2, (RIWR, RIWR), rd_rn),
17733 cCE("waccw", e8001c0, 2, (RIWR, RIWR), rd_rn),
17734 cCE("waddbss", e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17735 cCE("waddb", e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17736 cCE("waddbus", e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17737 cCE("waddhss", e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17738 cCE("waddh", e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17739 cCE("waddhus", e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17740 cCE("waddwss", eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17741 cCE("waddw", e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17742 cCE("waddwus", e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17743 cCE("waligni", e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17744 cCE("walignr0", e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17745 cCE("walignr1", e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17746 cCE("walignr2", ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17747 cCE("walignr3", eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17748 cCE("wand", e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17749 cCE("wandn", e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17750 cCE("wavg2b", e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17751 cCE("wavg2br", e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17752 cCE("wavg2h", ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17753 cCE("wavg2hr", ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17754 cCE("wcmpeqb", e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17755 cCE("wcmpeqh", e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17756 cCE("wcmpeqw", e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17757 cCE("wcmpgtub", e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17758 cCE("wcmpgtuh", e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17759 cCE("wcmpgtuw", e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17760 cCE("wcmpgtsb", e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17761 cCE("wcmpgtsh", e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17762 cCE("wcmpgtsw", eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17763 cCE("wldrb", c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17764 cCE("wldrh", c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17765 cCE("wldrw", c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17766 cCE("wldrd", c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17767 cCE("wmacs", e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17768 cCE("wmacsz", e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17769 cCE("wmacu", e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17770 cCE("wmacuz", e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17771 cCE("wmadds", ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17772 cCE("wmaddu", e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17773 cCE("wmaxsb", e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17774 cCE("wmaxsh", e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17775 cCE("wmaxsw", ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17776 cCE("wmaxub", e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17777 cCE("wmaxuh", e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17778 cCE("wmaxuw", e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17779 cCE("wminsb", e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17780 cCE("wminsh", e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17781 cCE("wminsw", eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17782 cCE("wminub", e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17783 cCE("wminuh", e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17784 cCE("wminuw", e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17785 cCE("wmov", e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17786 cCE("wmulsm", e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17787 cCE("wmulsl", e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17788 cCE("wmulum", e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17789 cCE("wmulul", e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17790 cCE("wor", e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17791 cCE("wpackhss", e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17792 cCE("wpackhus", e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17793 cCE("wpackwss", eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17794 cCE("wpackwus", e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17795 cCE("wpackdss", ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17796 cCE("wpackdus", ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17797 cCE("wrorh", e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17798 cCE("wrorhg", e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17799 cCE("wrorw", eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17800 cCE("wrorwg", eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17801 cCE("wrord", ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17802 cCE("wrordg", ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17803 cCE("wsadb", e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17804 cCE("wsadbz", e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17805 cCE("wsadh", e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17806 cCE("wsadhz", e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17807 cCE("wshufh", e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
17808 cCE("wsllh", e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17809 cCE("wsllhg", e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17810 cCE("wsllw", e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17811 cCE("wsllwg", e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17812 cCE("wslld", ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17813 cCE("wslldg", ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17814 cCE("wsrah", e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17815 cCE("wsrahg", e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17816 cCE("wsraw", e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17817 cCE("wsrawg", e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17818 cCE("wsrad", ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17819 cCE("wsradg", ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17820 cCE("wsrlh", e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17821 cCE("wsrlhg", e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17822 cCE("wsrlw", ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17823 cCE("wsrlwg", ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17824 cCE("wsrld", ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17825 cCE("wsrldg", ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17826 cCE("wstrb", c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17827 cCE("wstrh", c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17828 cCE("wstrw", c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17829 cCE("wstrd", c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17830 cCE("wsubbss", e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17831 cCE("wsubb", e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17832 cCE("wsubbus", e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17833 cCE("wsubhss", e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17834 cCE("wsubh", e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17835 cCE("wsubhus", e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17836 cCE("wsubwss", eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17837 cCE("wsubw", e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17838 cCE("wsubwus", e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17839 cCE("wunpckehub",e0000c0, 2, (RIWR, RIWR), rd_rn),
17840 cCE("wunpckehuh",e4000c0, 2, (RIWR, RIWR), rd_rn),
17841 cCE("wunpckehuw",e8000c0, 2, (RIWR, RIWR), rd_rn),
17842 cCE("wunpckehsb",e2000c0, 2, (RIWR, RIWR), rd_rn),
17843 cCE("wunpckehsh",e6000c0, 2, (RIWR, RIWR), rd_rn),
17844 cCE("wunpckehsw",ea000c0, 2, (RIWR, RIWR), rd_rn),
17845 cCE("wunpckihb", e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17846 cCE("wunpckihh", e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17847 cCE("wunpckihw", e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17848 cCE("wunpckelub",e0000e0, 2, (RIWR, RIWR), rd_rn),
17849 cCE("wunpckeluh",e4000e0, 2, (RIWR, RIWR), rd_rn),
17850 cCE("wunpckeluw",e8000e0, 2, (RIWR, RIWR), rd_rn),
17851 cCE("wunpckelsb",e2000e0, 2, (RIWR, RIWR), rd_rn),
17852 cCE("wunpckelsh",e6000e0, 2, (RIWR, RIWR), rd_rn),
17853 cCE("wunpckelsw",ea000e0, 2, (RIWR, RIWR), rd_rn),
17854 cCE("wunpckilb", e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17855 cCE("wunpckilh", e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17856 cCE("wunpckilw", e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17857 cCE("wxor", e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17858 cCE("wzero", e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 17859
c921be7d
NC
17860#undef ARM_VARIANT
17861#define ARM_VARIANT & arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
17862
21d799b5
NC
17863 cCE("torvscb", e12f190, 1, (RR), iwmmxt_tandorc),
17864 cCE("torvsch", e52f190, 1, (RR), iwmmxt_tandorc),
17865 cCE("torvscw", e92f190, 1, (RR), iwmmxt_tandorc),
17866 cCE("wabsb", e2001c0, 2, (RIWR, RIWR), rd_rn),
17867 cCE("wabsh", e6001c0, 2, (RIWR, RIWR), rd_rn),
17868 cCE("wabsw", ea001c0, 2, (RIWR, RIWR), rd_rn),
17869 cCE("wabsdiffb", e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17870 cCE("wabsdiffh", e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17871 cCE("wabsdiffw", e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17872 cCE("waddbhusl", e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17873 cCE("waddbhusm", e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17874 cCE("waddhc", e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17875 cCE("waddwc", ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17876 cCE("waddsubhx", ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17877 cCE("wavg4", e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17878 cCE("wavg4r", e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17879 cCE("wmaddsn", ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17880 cCE("wmaddsx", eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17881 cCE("wmaddun", ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17882 cCE("wmaddux", e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17883 cCE("wmerge", e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
17884 cCE("wmiabb", e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17885 cCE("wmiabt", e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17886 cCE("wmiatb", e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17887 cCE("wmiatt", e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17888 cCE("wmiabbn", e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17889 cCE("wmiabtn", e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17890 cCE("wmiatbn", e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17891 cCE("wmiattn", e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17892 cCE("wmiawbb", e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17893 cCE("wmiawbt", e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17894 cCE("wmiawtb", ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17895 cCE("wmiawtt", eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17896 cCE("wmiawbbn", ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17897 cCE("wmiawbtn", ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17898 cCE("wmiawtbn", ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17899 cCE("wmiawttn", ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17900 cCE("wmulsmr", ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17901 cCE("wmulumr", ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17902 cCE("wmulwumr", ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17903 cCE("wmulwsmr", ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17904 cCE("wmulwum", ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17905 cCE("wmulwsm", ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17906 cCE("wmulwl", eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17907 cCE("wqmiabb", e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17908 cCE("wqmiabt", e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17909 cCE("wqmiatb", ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17910 cCE("wqmiatt", eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17911 cCE("wqmiabbn", ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17912 cCE("wqmiabtn", ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17913 cCE("wqmiatbn", ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17914 cCE("wqmiattn", ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17915 cCE("wqmulm", e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17916 cCE("wqmulmr", e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17917 cCE("wqmulwm", ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17918 cCE("wqmulwmr", ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17919 cCE("wsubaddhx", ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 17920
c921be7d
NC
17921#undef ARM_VARIANT
17922#define ARM_VARIANT & arm_cext_maverick /* Cirrus Maverick instructions. */
17923
21d799b5
NC
17924 cCE("cfldrs", c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17925 cCE("cfldrd", c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17926 cCE("cfldr32", c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17927 cCE("cfldr64", c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17928 cCE("cfstrs", c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17929 cCE("cfstrd", c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17930 cCE("cfstr32", c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17931 cCE("cfstr64", c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17932 cCE("cfmvsr", e000450, 2, (RMF, RR), rn_rd),
17933 cCE("cfmvrs", e100450, 2, (RR, RMF), rd_rn),
17934 cCE("cfmvdlr", e000410, 2, (RMD, RR), rn_rd),
17935 cCE("cfmvrdl", e100410, 2, (RR, RMD), rd_rn),
17936 cCE("cfmvdhr", e000430, 2, (RMD, RR), rn_rd),
17937 cCE("cfmvrdh", e100430, 2, (RR, RMD), rd_rn),
17938 cCE("cfmv64lr", e000510, 2, (RMDX, RR), rn_rd),
17939 cCE("cfmvr64l", e100510, 2, (RR, RMDX), rd_rn),
17940 cCE("cfmv64hr", e000530, 2, (RMDX, RR), rn_rd),
17941 cCE("cfmvr64h", e100530, 2, (RR, RMDX), rd_rn),
17942 cCE("cfmval32", e200440, 2, (RMAX, RMFX), rd_rn),
17943 cCE("cfmv32al", e100440, 2, (RMFX, RMAX), rd_rn),
17944 cCE("cfmvam32", e200460, 2, (RMAX, RMFX), rd_rn),
17945 cCE("cfmv32am", e100460, 2, (RMFX, RMAX), rd_rn),
17946 cCE("cfmvah32", e200480, 2, (RMAX, RMFX), rd_rn),
17947 cCE("cfmv32ah", e100480, 2, (RMFX, RMAX), rd_rn),
17948 cCE("cfmva32", e2004a0, 2, (RMAX, RMFX), rd_rn),
17949 cCE("cfmv32a", e1004a0, 2, (RMFX, RMAX), rd_rn),
17950 cCE("cfmva64", e2004c0, 2, (RMAX, RMDX), rd_rn),
17951 cCE("cfmv64a", e1004c0, 2, (RMDX, RMAX), rd_rn),
17952 cCE("cfmvsc32", e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17953 cCE("cfmv32sc", e1004e0, 2, (RMDX, RMDS), rd),
17954 cCE("cfcpys", e000400, 2, (RMF, RMF), rd_rn),
17955 cCE("cfcpyd", e000420, 2, (RMD, RMD), rd_rn),
17956 cCE("cfcvtsd", e000460, 2, (RMD, RMF), rd_rn),
17957 cCE("cfcvtds", e000440, 2, (RMF, RMD), rd_rn),
17958 cCE("cfcvt32s", e000480, 2, (RMF, RMFX), rd_rn),
17959 cCE("cfcvt32d", e0004a0, 2, (RMD, RMFX), rd_rn),
17960 cCE("cfcvt64s", e0004c0, 2, (RMF, RMDX), rd_rn),
17961 cCE("cfcvt64d", e0004e0, 2, (RMD, RMDX), rd_rn),
17962 cCE("cfcvts32", e100580, 2, (RMFX, RMF), rd_rn),
17963 cCE("cfcvtd32", e1005a0, 2, (RMFX, RMD), rd_rn),
17964 cCE("cftruncs32",e1005c0, 2, (RMFX, RMF), rd_rn),
17965 cCE("cftruncd32",e1005e0, 2, (RMFX, RMD), rd_rn),
17966 cCE("cfrshl32", e000550, 3, (RMFX, RMFX, RR), mav_triple),
17967 cCE("cfrshl64", e000570, 3, (RMDX, RMDX, RR), mav_triple),
17968 cCE("cfsh32", e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17969 cCE("cfsh64", e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17970 cCE("cfcmps", e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17971 cCE("cfcmpd", e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17972 cCE("cfcmp32", e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17973 cCE("cfcmp64", e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17974 cCE("cfabss", e300400, 2, (RMF, RMF), rd_rn),
17975 cCE("cfabsd", e300420, 2, (RMD, RMD), rd_rn),
17976 cCE("cfnegs", e300440, 2, (RMF, RMF), rd_rn),
17977 cCE("cfnegd", e300460, 2, (RMD, RMD), rd_rn),
17978 cCE("cfadds", e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17979 cCE("cfaddd", e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17980 cCE("cfsubs", e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17981 cCE("cfsubd", e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17982 cCE("cfmuls", e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17983 cCE("cfmuld", e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17984 cCE("cfabs32", e300500, 2, (RMFX, RMFX), rd_rn),
17985 cCE("cfabs64", e300520, 2, (RMDX, RMDX), rd_rn),
17986 cCE("cfneg32", e300540, 2, (RMFX, RMFX), rd_rn),
17987 cCE("cfneg64", e300560, 2, (RMDX, RMDX), rd_rn),
17988 cCE("cfadd32", e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17989 cCE("cfadd64", e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17990 cCE("cfsub32", e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17991 cCE("cfsub64", e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17992 cCE("cfmul32", e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17993 cCE("cfmul64", e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17994 cCE("cfmac32", e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17995 cCE("cfmsc32", e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17996 cCE("cfmadd32", e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17997 cCE("cfmsub32", e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17998 cCE("cfmadda32", e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17999 cCE("cfmsuba32", e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
18000};
18001#undef ARM_VARIANT
18002#undef THUMB_VARIANT
18003#undef TCE
18004#undef TCM
18005#undef TUE
18006#undef TUF
18007#undef TCC
8f06b2d8 18008#undef cCE
e3cb604e
PB
18009#undef cCL
18010#undef C3E
c19d1205
ZW
18011#undef CE
18012#undef CM
18013#undef UE
18014#undef UF
18015#undef UT
5287ad62
JB
18016#undef NUF
18017#undef nUF
18018#undef NCE
18019#undef nCE
c19d1205
ZW
18020#undef OPS0
18021#undef OPS1
18022#undef OPS2
18023#undef OPS3
18024#undef OPS4
18025#undef OPS5
18026#undef OPS6
18027#undef do_0
18028\f
18029/* MD interface: bits in the object file. */
bfae80f2 18030
c19d1205
ZW
18031/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
18032 for use in the a.out file, and stores them in the array pointed to by buf.
18033 This knows about the endian-ness of the target machine and does
18034 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
18035 2 (short) and 4 (long) Floating numbers are put out as a series of
18036 LITTLENUMS (shorts, here at least). */
b99bd4ef 18037
c19d1205
ZW
18038void
18039md_number_to_chars (char * buf, valueT val, int n)
18040{
18041 if (target_big_endian)
18042 number_to_chars_bigendian (buf, val, n);
18043 else
18044 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
18045}
18046
c19d1205
ZW
18047static valueT
18048md_chars_to_number (char * buf, int n)
bfae80f2 18049{
c19d1205
ZW
18050 valueT result = 0;
18051 unsigned char * where = (unsigned char *) buf;
bfae80f2 18052
c19d1205 18053 if (target_big_endian)
b99bd4ef 18054 {
c19d1205
ZW
18055 while (n--)
18056 {
18057 result <<= 8;
18058 result |= (*where++ & 255);
18059 }
b99bd4ef 18060 }
c19d1205 18061 else
b99bd4ef 18062 {
c19d1205
ZW
18063 while (n--)
18064 {
18065 result <<= 8;
18066 result |= (where[n] & 255);
18067 }
bfae80f2 18068 }
b99bd4ef 18069
c19d1205 18070 return result;
bfae80f2 18071}
b99bd4ef 18072
c19d1205 18073/* MD interface: Sections. */
b99bd4ef 18074
0110f2b8
PB
18075/* Estimate the size of a frag before relaxing. Assume everything fits in
18076 2 bytes. */
18077
c19d1205 18078int
0110f2b8 18079md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
18080 segT segtype ATTRIBUTE_UNUSED)
18081{
0110f2b8
PB
18082 fragp->fr_var = 2;
18083 return 2;
18084}
18085
18086/* Convert a machine dependent frag. */
18087
18088void
18089md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
18090{
18091 unsigned long insn;
18092 unsigned long old_op;
18093 char *buf;
18094 expressionS exp;
18095 fixS *fixp;
18096 int reloc_type;
18097 int pc_rel;
18098 int opcode;
18099
18100 buf = fragp->fr_literal + fragp->fr_fix;
18101
18102 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
18103 if (fragp->fr_symbol)
18104 {
0110f2b8
PB
18105 exp.X_op = O_symbol;
18106 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
18107 }
18108 else
18109 {
0110f2b8 18110 exp.X_op = O_constant;
5f4273c7 18111 }
0110f2b8
PB
18112 exp.X_add_number = fragp->fr_offset;
18113 opcode = fragp->fr_subtype;
18114 switch (opcode)
18115 {
18116 case T_MNEM_ldr_pc:
18117 case T_MNEM_ldr_pc2:
18118 case T_MNEM_ldr_sp:
18119 case T_MNEM_str_sp:
18120 case T_MNEM_ldr:
18121 case T_MNEM_ldrb:
18122 case T_MNEM_ldrh:
18123 case T_MNEM_str:
18124 case T_MNEM_strb:
18125 case T_MNEM_strh:
18126 if (fragp->fr_var == 4)
18127 {
5f4273c7 18128 insn = THUMB_OP32 (opcode);
0110f2b8
PB
18129 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
18130 {
18131 insn |= (old_op & 0x700) << 4;
18132 }
18133 else
18134 {
18135 insn |= (old_op & 7) << 12;
18136 insn |= (old_op & 0x38) << 13;
18137 }
18138 insn |= 0x00000c00;
18139 put_thumb32_insn (buf, insn);
18140 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
18141 }
18142 else
18143 {
18144 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
18145 }
18146 pc_rel = (opcode == T_MNEM_ldr_pc2);
18147 break;
18148 case T_MNEM_adr:
18149 if (fragp->fr_var == 4)
18150 {
18151 insn = THUMB_OP32 (opcode);
18152 insn |= (old_op & 0xf0) << 4;
18153 put_thumb32_insn (buf, insn);
18154 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
18155 }
18156 else
18157 {
18158 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18159 exp.X_add_number -= 4;
18160 }
18161 pc_rel = 1;
18162 break;
18163 case T_MNEM_mov:
18164 case T_MNEM_movs:
18165 case T_MNEM_cmp:
18166 case T_MNEM_cmn:
18167 if (fragp->fr_var == 4)
18168 {
18169 int r0off = (opcode == T_MNEM_mov
18170 || opcode == T_MNEM_movs) ? 0 : 8;
18171 insn = THUMB_OP32 (opcode);
18172 insn = (insn & 0xe1ffffff) | 0x10000000;
18173 insn |= (old_op & 0x700) << r0off;
18174 put_thumb32_insn (buf, insn);
18175 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
18176 }
18177 else
18178 {
18179 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
18180 }
18181 pc_rel = 0;
18182 break;
18183 case T_MNEM_b:
18184 if (fragp->fr_var == 4)
18185 {
18186 insn = THUMB_OP32(opcode);
18187 put_thumb32_insn (buf, insn);
18188 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
18189 }
18190 else
18191 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
18192 pc_rel = 1;
18193 break;
18194 case T_MNEM_bcond:
18195 if (fragp->fr_var == 4)
18196 {
18197 insn = THUMB_OP32(opcode);
18198 insn |= (old_op & 0xf00) << 14;
18199 put_thumb32_insn (buf, insn);
18200 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
18201 }
18202 else
18203 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
18204 pc_rel = 1;
18205 break;
18206 case T_MNEM_add_sp:
18207 case T_MNEM_add_pc:
18208 case T_MNEM_inc_sp:
18209 case T_MNEM_dec_sp:
18210 if (fragp->fr_var == 4)
18211 {
18212 /* ??? Choose between add and addw. */
18213 insn = THUMB_OP32 (opcode);
18214 insn |= (old_op & 0xf0) << 4;
18215 put_thumb32_insn (buf, insn);
16805f35
PB
18216 if (opcode == T_MNEM_add_pc)
18217 reloc_type = BFD_RELOC_ARM_T32_IMM12;
18218 else
18219 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
18220 }
18221 else
18222 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18223 pc_rel = 0;
18224 break;
18225
18226 case T_MNEM_addi:
18227 case T_MNEM_addis:
18228 case T_MNEM_subi:
18229 case T_MNEM_subis:
18230 if (fragp->fr_var == 4)
18231 {
18232 insn = THUMB_OP32 (opcode);
18233 insn |= (old_op & 0xf0) << 4;
18234 insn |= (old_op & 0xf) << 16;
18235 put_thumb32_insn (buf, insn);
16805f35
PB
18236 if (insn & (1 << 20))
18237 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
18238 else
18239 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
18240 }
18241 else
18242 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
18243 pc_rel = 0;
18244 break;
18245 default:
5f4273c7 18246 abort ();
0110f2b8
PB
18247 }
18248 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
21d799b5 18249 (enum bfd_reloc_code_real) reloc_type);
0110f2b8
PB
18250 fixp->fx_file = fragp->fr_file;
18251 fixp->fx_line = fragp->fr_line;
18252 fragp->fr_fix += fragp->fr_var;
18253}
18254
18255/* Return the size of a relaxable immediate operand instruction.
18256 SHIFT and SIZE specify the form of the allowable immediate. */
18257static int
18258relax_immediate (fragS *fragp, int size, int shift)
18259{
18260 offsetT offset;
18261 offsetT mask;
18262 offsetT low;
18263
18264 /* ??? Should be able to do better than this. */
18265 if (fragp->fr_symbol)
18266 return 4;
18267
18268 low = (1 << shift) - 1;
18269 mask = (1 << (shift + size)) - (1 << shift);
18270 offset = fragp->fr_offset;
18271 /* Force misaligned offsets to 32-bit variant. */
18272 if (offset & low)
5e77afaa 18273 return 4;
0110f2b8
PB
18274 if (offset & ~mask)
18275 return 4;
18276 return 2;
18277}
18278
5e77afaa
PB
18279/* Get the address of a symbol during relaxation. */
18280static addressT
5f4273c7 18281relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
18282{
18283 fragS *sym_frag;
18284 addressT addr;
18285 symbolS *sym;
18286
18287 sym = fragp->fr_symbol;
18288 sym_frag = symbol_get_frag (sym);
18289 know (S_GET_SEGMENT (sym) != absolute_section
18290 || sym_frag == &zero_address_frag);
18291 addr = S_GET_VALUE (sym) + fragp->fr_offset;
18292
18293 /* If frag has yet to be reached on this pass, assume it will
18294 move by STRETCH just as we did. If this is not so, it will
18295 be because some frag between grows, and that will force
18296 another pass. */
18297
18298 if (stretch != 0
18299 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
18300 {
18301 fragS *f;
18302
18303 /* Adjust stretch for any alignment frag. Note that if have
18304 been expanding the earlier code, the symbol may be
18305 defined in what appears to be an earlier frag. FIXME:
18306 This doesn't handle the fr_subtype field, which specifies
18307 a maximum number of bytes to skip when doing an
18308 alignment. */
18309 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
18310 {
18311 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
18312 {
18313 if (stretch < 0)
18314 stretch = - ((- stretch)
18315 & ~ ((1 << (int) f->fr_offset) - 1));
18316 else
18317 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
18318 if (stretch == 0)
18319 break;
18320 }
18321 }
18322 if (f != NULL)
18323 addr += stretch;
18324 }
5e77afaa
PB
18325
18326 return addr;
18327}
18328
0110f2b8
PB
18329/* Return the size of a relaxable adr pseudo-instruction or PC-relative
18330 load. */
18331static int
5e77afaa 18332relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
18333{
18334 addressT addr;
18335 offsetT val;
18336
18337 /* Assume worst case for symbols not known to be in the same section. */
974da60d
NC
18338 if (fragp->fr_symbol == NULL
18339 || !S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18340 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18341 return 4;
18342
5f4273c7 18343 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18344 addr = fragp->fr_address + fragp->fr_fix;
18345 addr = (addr + 4) & ~3;
5e77afaa 18346 /* Force misaligned targets to 32-bit variant. */
0110f2b8 18347 if (val & 3)
5e77afaa 18348 return 4;
0110f2b8
PB
18349 val -= addr;
18350 if (val < 0 || val > 1020)
18351 return 4;
18352 return 2;
18353}
18354
18355/* Return the size of a relaxable add/sub immediate instruction. */
18356static int
18357relax_addsub (fragS *fragp, asection *sec)
18358{
18359 char *buf;
18360 int op;
18361
18362 buf = fragp->fr_literal + fragp->fr_fix;
18363 op = bfd_get_16(sec->owner, buf);
18364 if ((op & 0xf) == ((op >> 4) & 0xf))
18365 return relax_immediate (fragp, 8, 0);
18366 else
18367 return relax_immediate (fragp, 3, 0);
18368}
18369
18370
18371/* Return the size of a relaxable branch instruction. BITS is the
18372 size of the offset field in the narrow instruction. */
18373
18374static int
5e77afaa 18375relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
18376{
18377 addressT addr;
18378 offsetT val;
18379 offsetT limit;
18380
18381 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 18382 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
18383 || sec != S_GET_SEGMENT (fragp->fr_symbol))
18384 return 4;
18385
267bf995
RR
18386#ifdef OBJ_ELF
18387 if (S_IS_DEFINED (fragp->fr_symbol)
18388 && ARM_IS_FUNC (fragp->fr_symbol))
18389 return 4;
18390#endif
18391
5f4273c7 18392 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
18393 addr = fragp->fr_address + fragp->fr_fix + 4;
18394 val -= addr;
18395
18396 /* Offset is a signed value *2 */
18397 limit = 1 << bits;
18398 if (val >= limit || val < -limit)
18399 return 4;
18400 return 2;
18401}
18402
18403
18404/* Relax a machine dependent frag. This returns the amount by which
18405 the current size of the frag should change. */
18406
18407int
5e77afaa 18408arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
18409{
18410 int oldsize;
18411 int newsize;
18412
18413 oldsize = fragp->fr_var;
18414 switch (fragp->fr_subtype)
18415 {
18416 case T_MNEM_ldr_pc2:
5f4273c7 18417 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18418 break;
18419 case T_MNEM_ldr_pc:
18420 case T_MNEM_ldr_sp:
18421 case T_MNEM_str_sp:
5f4273c7 18422 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18423 break;
18424 case T_MNEM_ldr:
18425 case T_MNEM_str:
5f4273c7 18426 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18427 break;
18428 case T_MNEM_ldrh:
18429 case T_MNEM_strh:
5f4273c7 18430 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18431 break;
18432 case T_MNEM_ldrb:
18433 case T_MNEM_strb:
5f4273c7 18434 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18435 break;
18436 case T_MNEM_adr:
5f4273c7 18437 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18438 break;
18439 case T_MNEM_mov:
18440 case T_MNEM_movs:
18441 case T_MNEM_cmp:
18442 case T_MNEM_cmn:
5f4273c7 18443 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18444 break;
18445 case T_MNEM_b:
5f4273c7 18446 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18447 break;
18448 case T_MNEM_bcond:
5f4273c7 18449 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18450 break;
18451 case T_MNEM_add_sp:
18452 case T_MNEM_add_pc:
18453 newsize = relax_immediate (fragp, 8, 2);
18454 break;
18455 case T_MNEM_inc_sp:
18456 case T_MNEM_dec_sp:
18457 newsize = relax_immediate (fragp, 7, 2);
18458 break;
18459 case T_MNEM_addi:
18460 case T_MNEM_addis:
18461 case T_MNEM_subi:
18462 case T_MNEM_subis:
18463 newsize = relax_addsub (fragp, sec);
18464 break;
18465 default:
5f4273c7 18466 abort ();
0110f2b8 18467 }
5e77afaa
PB
18468
18469 fragp->fr_var = newsize;
18470 /* Freeze wide instructions that are at or before the same location as
18471 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18472 Don't freeze them unconditionally because targets may be artificially
18473 misaligned by the expansion of preceding frags. */
5e77afaa 18474 if (stretch <= 0 && newsize > 2)
0110f2b8 18475 {
0110f2b8 18476 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18477 frag_wane (fragp);
0110f2b8 18478 }
5e77afaa 18479
0110f2b8 18480 return newsize - oldsize;
c19d1205 18481}
b99bd4ef 18482
c19d1205 18483/* Round up a section size to the appropriate boundary. */
b99bd4ef 18484
c19d1205
ZW
18485valueT
18486md_section_align (segT segment ATTRIBUTE_UNUSED,
18487 valueT size)
18488{
f0927246
NC
18489#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18490 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18491 {
18492 /* For a.out, force the section size to be aligned. If we don't do
18493 this, BFD will align it for us, but it will not write out the
18494 final bytes of the section. This may be a bug in BFD, but it is
18495 easier to fix it here since that is how the other a.out targets
18496 work. */
18497 int align;
18498
18499 align = bfd_get_section_alignment (stdoutput, segment);
18500 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18501 }
c19d1205 18502#endif
f0927246
NC
18503
18504 return size;
bfae80f2 18505}
b99bd4ef 18506
c19d1205
ZW
18507/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18508 of an rs_align_code fragment. */
18509
18510void
18511arm_handle_align (fragS * fragP)
bfae80f2 18512{
e7495e45
NS
18513 static char const arm_noop[2][2][4] =
18514 {
18515 { /* ARMv1 */
18516 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18517 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18518 },
18519 { /* ARMv6k */
18520 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18521 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18522 },
18523 };
18524 static char const thumb_noop[2][2][2] =
18525 {
18526 { /* Thumb-1 */
18527 {0xc0, 0x46}, /* LE */
18528 {0x46, 0xc0}, /* BE */
18529 },
18530 { /* Thumb-2 */
18531 {0x00, 0xbf}, /* LE */
18532 {0xbf, 0x00} /* BE */
18533 }
18534 };
18535 static char const wide_thumb_noop[2][4] =
18536 { /* Wide Thumb-2 */
18537 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18538 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18539 };
c921be7d 18540
e7495e45 18541 unsigned bytes, fix, noop_size;
c19d1205
ZW
18542 char * p;
18543 const char * noop;
e7495e45 18544 const char *narrow_noop = NULL;
cd000bff
DJ
18545#ifdef OBJ_ELF
18546 enum mstate state;
18547#endif
bfae80f2 18548
c19d1205 18549 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18550 return;
18551
c19d1205
ZW
18552 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18553 p = fragP->fr_literal + fragP->fr_fix;
18554 fix = 0;
bfae80f2 18555
c19d1205
ZW
18556 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18557 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18558
539d4391 18559#ifdef OBJ_ELF
cd000bff 18560 gas_assert ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) != 0);
539d4391 18561#endif
8dc2430f 18562
cd000bff 18563 if (fragP->tc_frag_data.thumb_mode & (~ MODE_RECORDED))
a737bd4d 18564 {
e7495e45
NS
18565 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18566 {
18567 narrow_noop = thumb_noop[1][target_big_endian];
18568 noop = wide_thumb_noop[target_big_endian];
18569 }
c19d1205 18570 else
e7495e45
NS
18571 noop = thumb_noop[0][target_big_endian];
18572 noop_size = 2;
cd000bff
DJ
18573#ifdef OBJ_ELF
18574 state = MAP_THUMB;
18575#endif
7ed4c4c5
NC
18576 }
18577 else
18578 {
e7495e45
NS
18579 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18580 [target_big_endian];
18581 noop_size = 4;
cd000bff
DJ
18582#ifdef OBJ_ELF
18583 state = MAP_ARM;
18584#endif
7ed4c4c5 18585 }
c921be7d 18586
e7495e45 18587 fragP->fr_var = noop_size;
c921be7d 18588
c19d1205 18589 if (bytes & (noop_size - 1))
7ed4c4c5 18590 {
c19d1205 18591 fix = bytes & (noop_size - 1);
cd000bff
DJ
18592#ifdef OBJ_ELF
18593 insert_data_mapping_symbol (state, fragP->fr_fix, fragP, fix);
18594#endif
c19d1205
ZW
18595 memset (p, 0, fix);
18596 p += fix;
18597 bytes -= fix;
a737bd4d 18598 }
a737bd4d 18599
e7495e45
NS
18600 if (narrow_noop)
18601 {
18602 if (bytes & noop_size)
18603 {
18604 /* Insert a narrow noop. */
18605 memcpy (p, narrow_noop, noop_size);
18606 p += noop_size;
18607 bytes -= noop_size;
18608 fix += noop_size;
18609 }
18610
18611 /* Use wide noops for the remainder */
18612 noop_size = 4;
18613 }
18614
c19d1205 18615 while (bytes >= noop_size)
a737bd4d 18616 {
c19d1205
ZW
18617 memcpy (p, noop, noop_size);
18618 p += noop_size;
18619 bytes -= noop_size;
18620 fix += noop_size;
a737bd4d
NC
18621 }
18622
c19d1205 18623 fragP->fr_fix += fix;
a737bd4d
NC
18624}
18625
c19d1205
ZW
18626/* Called from md_do_align. Used to create an alignment
18627 frag in a code section. */
18628
18629void
18630arm_frag_align_code (int n, int max)
bfae80f2 18631{
c19d1205 18632 char * p;
7ed4c4c5 18633
c19d1205 18634 /* We assume that there will never be a requirement
6ec8e702 18635 to support alignments greater than MAX_MEM_FOR_RS_ALIGN_CODE bytes. */
c19d1205 18636 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
6ec8e702
NC
18637 {
18638 char err_msg[128];
18639
18640 sprintf (err_msg,
18641 _("alignments greater than %d bytes not supported in .text sections."),
18642 MAX_MEM_FOR_RS_ALIGN_CODE + 1);
20203fb9 18643 as_fatal ("%s", err_msg);
6ec8e702 18644 }
bfae80f2 18645
c19d1205
ZW
18646 p = frag_var (rs_align_code,
18647 MAX_MEM_FOR_RS_ALIGN_CODE,
18648 1,
18649 (relax_substateT) max,
18650 (symbolS *) NULL,
18651 (offsetT) n,
18652 (char *) NULL);
18653 *p = 0;
18654}
bfae80f2 18655
8dc2430f
NC
18656/* Perform target specific initialisation of a frag.
18657 Note - despite the name this initialisation is not done when the frag
18658 is created, but only when its type is assigned. A frag can be created
18659 and used a long time before its type is set, so beware of assuming that
18660 this initialisationis performed first. */
bfae80f2 18661
cd000bff
DJ
18662#ifndef OBJ_ELF
18663void
18664arm_init_frag (fragS * fragP, int max_chars ATTRIBUTE_UNUSED)
18665{
18666 /* Record whether this frag is in an ARM or a THUMB area. */
18667 fragP->tc_frag_data.thumb_mode = thumb_mode;
18668}
18669
18670#else /* OBJ_ELF is defined. */
c19d1205 18671void
cd000bff 18672arm_init_frag (fragS * fragP, int max_chars)
c19d1205 18673{
8dc2430f
NC
18674 /* If the current ARM vs THUMB mode has not already
18675 been recorded into this frag then do so now. */
cd000bff
DJ
18676 if ((fragP->tc_frag_data.thumb_mode & MODE_RECORDED) == 0)
18677 {
18678 fragP->tc_frag_data.thumb_mode = thumb_mode | MODE_RECORDED;
18679
18680 /* Record a mapping symbol for alignment frags. We will delete this
18681 later if the alignment ends up empty. */
18682 switch (fragP->fr_type)
18683 {
18684 case rs_align:
18685 case rs_align_test:
18686 case rs_fill:
18687 mapping_state_2 (MAP_DATA, max_chars);
18688 break;
18689 case rs_align_code:
18690 mapping_state_2 (thumb_mode ? MAP_THUMB : MAP_ARM, max_chars);
18691 break;
18692 default:
18693 break;
18694 }
18695 }
bfae80f2
RE
18696}
18697
c19d1205
ZW
18698/* When we change sections we need to issue a new mapping symbol. */
18699
18700void
18701arm_elf_change_section (void)
bfae80f2 18702{
c19d1205
ZW
18703 /* Link an unlinked unwind index table section to the .text section. */
18704 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18705 && elf_linked_to_section (now_seg) == NULL)
18706 elf_linked_to_section (now_seg) = text_section;
bfae80f2
RE
18707}
18708
c19d1205
ZW
18709int
18710arm_elf_section_type (const char * str, size_t len)
e45d0630 18711{
c19d1205
ZW
18712 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18713 return SHT_ARM_EXIDX;
e45d0630 18714
c19d1205
ZW
18715 return -1;
18716}
18717\f
18718/* Code to deal with unwinding tables. */
e45d0630 18719
c19d1205 18720static void add_unwind_adjustsp (offsetT);
e45d0630 18721
5f4273c7 18722/* Generate any deferred unwind frame offset. */
e45d0630 18723
bfae80f2 18724static void
c19d1205 18725flush_pending_unwind (void)
bfae80f2 18726{
c19d1205 18727 offsetT offset;
bfae80f2 18728
c19d1205
ZW
18729 offset = unwind.pending_offset;
18730 unwind.pending_offset = 0;
18731 if (offset != 0)
18732 add_unwind_adjustsp (offset);
bfae80f2
RE
18733}
18734
c19d1205
ZW
18735/* Add an opcode to this list for this function. Two-byte opcodes should
18736 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18737 order. */
18738
bfae80f2 18739static void
c19d1205 18740add_unwind_opcode (valueT op, int length)
bfae80f2 18741{
c19d1205
ZW
18742 /* Add any deferred stack adjustment. */
18743 if (unwind.pending_offset)
18744 flush_pending_unwind ();
bfae80f2 18745
c19d1205 18746 unwind.sp_restored = 0;
bfae80f2 18747
c19d1205 18748 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18749 {
c19d1205
ZW
18750 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18751 if (unwind.opcodes)
21d799b5
NC
18752 unwind.opcodes = (unsigned char *) xrealloc (unwind.opcodes,
18753 unwind.opcode_alloc);
c19d1205 18754 else
21d799b5 18755 unwind.opcodes = (unsigned char *) xmalloc (unwind.opcode_alloc);
bfae80f2 18756 }
c19d1205 18757 while (length > 0)
bfae80f2 18758 {
c19d1205
ZW
18759 length--;
18760 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18761 op >>= 8;
18762 unwind.opcode_count++;
bfae80f2 18763 }
bfae80f2
RE
18764}
18765
c19d1205
ZW
18766/* Add unwind opcodes to adjust the stack pointer. */
18767
bfae80f2 18768static void
c19d1205 18769add_unwind_adjustsp (offsetT offset)
bfae80f2 18770{
c19d1205 18771 valueT op;
bfae80f2 18772
c19d1205 18773 if (offset > 0x200)
bfae80f2 18774 {
c19d1205
ZW
18775 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18776 char bytes[5];
18777 int n;
18778 valueT o;
bfae80f2 18779
c19d1205
ZW
18780 /* Long form: 0xb2, uleb128. */
18781 /* This might not fit in a word so add the individual bytes,
18782 remembering the list is built in reverse order. */
18783 o = (valueT) ((offset - 0x204) >> 2);
18784 if (o == 0)
18785 add_unwind_opcode (0, 1);
bfae80f2 18786
c19d1205
ZW
18787 /* Calculate the uleb128 encoding of the offset. */
18788 n = 0;
18789 while (o)
18790 {
18791 bytes[n] = o & 0x7f;
18792 o >>= 7;
18793 if (o)
18794 bytes[n] |= 0x80;
18795 n++;
18796 }
18797 /* Add the insn. */
18798 for (; n; n--)
18799 add_unwind_opcode (bytes[n - 1], 1);
18800 add_unwind_opcode (0xb2, 1);
18801 }
18802 else if (offset > 0x100)
bfae80f2 18803 {
c19d1205
ZW
18804 /* Two short opcodes. */
18805 add_unwind_opcode (0x3f, 1);
18806 op = (offset - 0x104) >> 2;
18807 add_unwind_opcode (op, 1);
bfae80f2 18808 }
c19d1205
ZW
18809 else if (offset > 0)
18810 {
18811 /* Short opcode. */
18812 op = (offset - 4) >> 2;
18813 add_unwind_opcode (op, 1);
18814 }
18815 else if (offset < 0)
bfae80f2 18816 {
c19d1205
ZW
18817 offset = -offset;
18818 while (offset > 0x100)
bfae80f2 18819 {
c19d1205
ZW
18820 add_unwind_opcode (0x7f, 1);
18821 offset -= 0x100;
bfae80f2 18822 }
c19d1205
ZW
18823 op = ((offset - 4) >> 2) | 0x40;
18824 add_unwind_opcode (op, 1);
bfae80f2 18825 }
bfae80f2
RE
18826}
18827
c19d1205
ZW
18828/* Finish the list of unwind opcodes for this function. */
18829static void
18830finish_unwind_opcodes (void)
bfae80f2 18831{
c19d1205 18832 valueT op;
bfae80f2 18833
c19d1205 18834 if (unwind.fp_used)
bfae80f2 18835 {
708587a4 18836 /* Adjust sp as necessary. */
c19d1205
ZW
18837 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18838 flush_pending_unwind ();
bfae80f2 18839
c19d1205
ZW
18840 /* After restoring sp from the frame pointer. */
18841 op = 0x90 | unwind.fp_reg;
18842 add_unwind_opcode (op, 1);
18843 }
18844 else
18845 flush_pending_unwind ();
bfae80f2
RE
18846}
18847
bfae80f2 18848
c19d1205
ZW
18849/* Start an exception table entry. If idx is nonzero this is an index table
18850 entry. */
bfae80f2
RE
18851
18852static void
c19d1205 18853start_unwind_section (const segT text_seg, int idx)
bfae80f2 18854{
c19d1205
ZW
18855 const char * text_name;
18856 const char * prefix;
18857 const char * prefix_once;
18858 const char * group_name;
18859 size_t prefix_len;
18860 size_t text_len;
18861 char * sec_name;
18862 size_t sec_name_len;
18863 int type;
18864 int flags;
18865 int linkonce;
bfae80f2 18866
c19d1205 18867 if (idx)
bfae80f2 18868 {
c19d1205
ZW
18869 prefix = ELF_STRING_ARM_unwind;
18870 prefix_once = ELF_STRING_ARM_unwind_once;
18871 type = SHT_ARM_EXIDX;
bfae80f2 18872 }
c19d1205 18873 else
bfae80f2 18874 {
c19d1205
ZW
18875 prefix = ELF_STRING_ARM_unwind_info;
18876 prefix_once = ELF_STRING_ARM_unwind_info_once;
18877 type = SHT_PROGBITS;
bfae80f2
RE
18878 }
18879
c19d1205
ZW
18880 text_name = segment_name (text_seg);
18881 if (streq (text_name, ".text"))
18882 text_name = "";
18883
18884 if (strncmp (text_name, ".gnu.linkonce.t.",
18885 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 18886 {
c19d1205
ZW
18887 prefix = prefix_once;
18888 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
18889 }
18890
c19d1205
ZW
18891 prefix_len = strlen (prefix);
18892 text_len = strlen (text_name);
18893 sec_name_len = prefix_len + text_len;
21d799b5 18894 sec_name = (char *) xmalloc (sec_name_len + 1);
c19d1205
ZW
18895 memcpy (sec_name, prefix, prefix_len);
18896 memcpy (sec_name + prefix_len, text_name, text_len);
18897 sec_name[prefix_len + text_len] = '\0';
bfae80f2 18898
c19d1205
ZW
18899 flags = SHF_ALLOC;
18900 linkonce = 0;
18901 group_name = 0;
bfae80f2 18902
c19d1205
ZW
18903 /* Handle COMDAT group. */
18904 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 18905 {
c19d1205
ZW
18906 group_name = elf_group_name (text_seg);
18907 if (group_name == NULL)
18908 {
bd3ba5d1 18909 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
18910 segment_name (text_seg));
18911 ignore_rest_of_line ();
18912 return;
18913 }
18914 flags |= SHF_GROUP;
18915 linkonce = 1;
bfae80f2
RE
18916 }
18917
c19d1205 18918 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 18919
5f4273c7 18920 /* Set the section link for index tables. */
c19d1205
ZW
18921 if (idx)
18922 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
18923}
18924
bfae80f2 18925
c19d1205
ZW
18926/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
18927 personality routine data. Returns zero, or the index table value for
18928 and inline entry. */
18929
18930static valueT
18931create_unwind_entry (int have_data)
bfae80f2 18932{
c19d1205
ZW
18933 int size;
18934 addressT where;
18935 char *ptr;
18936 /* The current word of data. */
18937 valueT data;
18938 /* The number of bytes left in this word. */
18939 int n;
bfae80f2 18940
c19d1205 18941 finish_unwind_opcodes ();
bfae80f2 18942
c19d1205
ZW
18943 /* Remember the current text section. */
18944 unwind.saved_seg = now_seg;
18945 unwind.saved_subseg = now_subseg;
bfae80f2 18946
c19d1205 18947 start_unwind_section (now_seg, 0);
bfae80f2 18948
c19d1205 18949 if (unwind.personality_routine == NULL)
bfae80f2 18950 {
c19d1205
ZW
18951 if (unwind.personality_index == -2)
18952 {
18953 if (have_data)
5f4273c7 18954 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
18955 return 1; /* EXIDX_CANTUNWIND. */
18956 }
bfae80f2 18957
c19d1205
ZW
18958 /* Use a default personality routine if none is specified. */
18959 if (unwind.personality_index == -1)
18960 {
18961 if (unwind.opcode_count > 3)
18962 unwind.personality_index = 1;
18963 else
18964 unwind.personality_index = 0;
18965 }
bfae80f2 18966
c19d1205
ZW
18967 /* Space for the personality routine entry. */
18968 if (unwind.personality_index == 0)
18969 {
18970 if (unwind.opcode_count > 3)
18971 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 18972
c19d1205
ZW
18973 if (!have_data)
18974 {
18975 /* All the data is inline in the index table. */
18976 data = 0x80;
18977 n = 3;
18978 while (unwind.opcode_count > 0)
18979 {
18980 unwind.opcode_count--;
18981 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18982 n--;
18983 }
bfae80f2 18984
c19d1205
ZW
18985 /* Pad with "finish" opcodes. */
18986 while (n--)
18987 data = (data << 8) | 0xb0;
bfae80f2 18988
c19d1205
ZW
18989 return data;
18990 }
18991 size = 0;
18992 }
18993 else
18994 /* We get two opcodes "free" in the first word. */
18995 size = unwind.opcode_count - 2;
18996 }
18997 else
18998 /* An extra byte is required for the opcode count. */
18999 size = unwind.opcode_count + 1;
bfae80f2 19000
c19d1205
ZW
19001 size = (size + 3) >> 2;
19002 if (size > 0xff)
19003 as_bad (_("too many unwind opcodes"));
bfae80f2 19004
c19d1205
ZW
19005 frag_align (2, 0, 0);
19006 record_alignment (now_seg, 2);
19007 unwind.table_entry = expr_build_dot ();
19008
19009 /* Allocate the table entry. */
19010 ptr = frag_more ((size << 2) + 4);
19011 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 19012
c19d1205 19013 switch (unwind.personality_index)
bfae80f2 19014 {
c19d1205
ZW
19015 case -1:
19016 /* ??? Should this be a PLT generating relocation? */
19017 /* Custom personality routine. */
19018 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
19019 BFD_RELOC_ARM_PREL31);
bfae80f2 19020
c19d1205
ZW
19021 where += 4;
19022 ptr += 4;
bfae80f2 19023
c19d1205
ZW
19024 /* Set the first byte to the number of additional words. */
19025 data = size - 1;
19026 n = 3;
19027 break;
bfae80f2 19028
c19d1205
ZW
19029 /* ABI defined personality routines. */
19030 case 0:
19031 /* Three opcodes bytes are packed into the first word. */
19032 data = 0x80;
19033 n = 3;
19034 break;
bfae80f2 19035
c19d1205
ZW
19036 case 1:
19037 case 2:
19038 /* The size and first two opcode bytes go in the first word. */
19039 data = ((0x80 + unwind.personality_index) << 8) | size;
19040 n = 2;
19041 break;
bfae80f2 19042
c19d1205
ZW
19043 default:
19044 /* Should never happen. */
19045 abort ();
19046 }
bfae80f2 19047
c19d1205
ZW
19048 /* Pack the opcodes into words (MSB first), reversing the list at the same
19049 time. */
19050 while (unwind.opcode_count > 0)
19051 {
19052 if (n == 0)
19053 {
19054 md_number_to_chars (ptr, data, 4);
19055 ptr += 4;
19056 n = 4;
19057 data = 0;
19058 }
19059 unwind.opcode_count--;
19060 n--;
19061 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
19062 }
19063
19064 /* Finish off the last word. */
19065 if (n < 4)
19066 {
19067 /* Pad with "finish" opcodes. */
19068 while (n--)
19069 data = (data << 8) | 0xb0;
19070
19071 md_number_to_chars (ptr, data, 4);
19072 }
19073
19074 if (!have_data)
19075 {
19076 /* Add an empty descriptor if there is no user-specified data. */
19077 ptr = frag_more (4);
19078 md_number_to_chars (ptr, 0, 4);
19079 }
19080
19081 return 0;
bfae80f2
RE
19082}
19083
f0927246
NC
19084
19085/* Initialize the DWARF-2 unwind information for this procedure. */
19086
19087void
19088tc_arm_frame_initial_instructions (void)
19089{
19090 cfi_add_CFA_def_cfa (REG_SP, 0);
19091}
19092#endif /* OBJ_ELF */
19093
c19d1205
ZW
19094/* Convert REGNAME to a DWARF-2 register number. */
19095
19096int
1df69f4f 19097tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 19098{
1df69f4f 19099 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
19100
19101 if (reg == FAIL)
19102 return -1;
19103
19104 return reg;
bfae80f2
RE
19105}
19106
f0927246 19107#ifdef TE_PE
c19d1205 19108void
f0927246 19109tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 19110{
f0927246 19111 expressionS expr;
bfae80f2 19112
f0927246
NC
19113 expr.X_op = O_secrel;
19114 expr.X_add_symbol = symbol;
19115 expr.X_add_number = 0;
19116 emit_expr (&expr, size);
19117}
19118#endif
bfae80f2 19119
c19d1205 19120/* MD interface: Symbol and relocation handling. */
bfae80f2 19121
2fc8bdac
ZW
19122/* Return the address within the segment that a PC-relative fixup is
19123 relative to. For ARM, PC-relative fixups applied to instructions
19124 are generally relative to the location of the fixup plus 8 bytes.
19125 Thumb branches are offset by 4, and Thumb loads relative to PC
19126 require special handling. */
bfae80f2 19127
c19d1205 19128long
2fc8bdac 19129md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 19130{
2fc8bdac
ZW
19131 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
19132
19133 /* If this is pc-relative and we are going to emit a relocation
19134 then we just want to put out any pipeline compensation that the linker
53baae48
NC
19135 will need. Otherwise we want to use the calculated base.
19136 For WinCE we skip the bias for externals as well, since this
19137 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 19138 if (fixP->fx_pcrel
2fc8bdac 19139 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
19140 || (arm_force_relocation (fixP)
19141#ifdef TE_WINCE
19142 && !S_IS_EXTERNAL (fixP->fx_addsy)
19143#endif
19144 )))
2fc8bdac 19145 base = 0;
bfae80f2 19146
267bf995 19147
c19d1205 19148 switch (fixP->fx_r_type)
bfae80f2 19149 {
2fc8bdac
ZW
19150 /* PC relative addressing on the Thumb is slightly odd as the
19151 bottom two bits of the PC are forced to zero for the
19152 calculation. This happens *after* application of the
19153 pipeline offset. However, Thumb adrl already adjusts for
19154 this, so we need not do it again. */
c19d1205 19155 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 19156 return base & ~3;
c19d1205
ZW
19157
19158 case BFD_RELOC_ARM_THUMB_OFFSET:
19159 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 19160 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 19161 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 19162 return (base + 4) & ~3;
c19d1205 19163
2fc8bdac
ZW
19164 /* Thumb branches are simply offset by +4. */
19165 case BFD_RELOC_THUMB_PCREL_BRANCH7:
19166 case BFD_RELOC_THUMB_PCREL_BRANCH9:
19167 case BFD_RELOC_THUMB_PCREL_BRANCH12:
19168 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 19169 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 19170 return base + 4;
bfae80f2 19171
267bf995
RR
19172 case BFD_RELOC_THUMB_PCREL_BRANCH23:
19173 if (fixP->fx_addsy
19174 && ARM_IS_FUNC (fixP->fx_addsy)
19175 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19176 base = fixP->fx_where + fixP->fx_frag->fr_address;
19177 return base + 4;
19178
00adf2d4
JB
19179 /* BLX is like branches above, but forces the low two bits of PC to
19180 zero. */
267bf995
RR
19181 case BFD_RELOC_THUMB_PCREL_BLX:
19182 if (fixP->fx_addsy
19183 && THUMB_IS_FUNC (fixP->fx_addsy)
19184 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19185 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
19186 return (base + 4) & ~3;
19187
2fc8bdac
ZW
19188 /* ARM mode branches are offset by +8. However, the Windows CE
19189 loader expects the relocation not to take this into account. */
267bf995
RR
19190 case BFD_RELOC_ARM_PCREL_BLX:
19191 if (fixP->fx_addsy
19192 && ARM_IS_FUNC (fixP->fx_addsy)
19193 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19194 base = fixP->fx_where + fixP->fx_frag->fr_address;
19195 return base + 8;
19196
19197 case BFD_RELOC_ARM_PCREL_CALL:
19198 if (fixP->fx_addsy
19199 && THUMB_IS_FUNC (fixP->fx_addsy)
19200 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19201 base = fixP->fx_where + fixP->fx_frag->fr_address;
19202 return base + 8;
19203
2fc8bdac 19204 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 19205 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 19206 case BFD_RELOC_ARM_PLT32:
c19d1205 19207#ifdef TE_WINCE
5f4273c7 19208 /* When handling fixups immediately, because we have already
53baae48
NC
19209 discovered the value of a symbol, or the address of the frag involved
19210 we must account for the offset by +8, as the OS loader will never see the reloc.
19211 see fixup_segment() in write.c
19212 The S_IS_EXTERNAL test handles the case of global symbols.
19213 Those need the calculated base, not just the pipe compensation the linker will need. */
19214 if (fixP->fx_pcrel
19215 && fixP->fx_addsy != NULL
19216 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19217 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
19218 return base + 8;
2fc8bdac 19219 return base;
c19d1205 19220#else
2fc8bdac 19221 return base + 8;
c19d1205 19222#endif
2fc8bdac 19223
267bf995 19224
2fc8bdac
ZW
19225 /* ARM mode loads relative to PC are also offset by +8. Unlike
19226 branches, the Windows CE loader *does* expect the relocation
19227 to take this into account. */
19228 case BFD_RELOC_ARM_OFFSET_IMM:
19229 case BFD_RELOC_ARM_OFFSET_IMM8:
19230 case BFD_RELOC_ARM_HWLITERAL:
19231 case BFD_RELOC_ARM_LITERAL:
19232 case BFD_RELOC_ARM_CP_OFF_IMM:
19233 return base + 8;
19234
19235
19236 /* Other PC-relative relocations are un-offset. */
19237 default:
19238 return base;
19239 }
bfae80f2
RE
19240}
19241
c19d1205
ZW
19242/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
19243 Otherwise we have no need to default values of symbols. */
19244
19245symbolS *
19246md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 19247{
c19d1205
ZW
19248#ifdef OBJ_ELF
19249 if (name[0] == '_' && name[1] == 'G'
19250 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
19251 {
19252 if (!GOT_symbol)
19253 {
19254 if (symbol_find (name))
bd3ba5d1 19255 as_bad (_("GOT already in the symbol table"));
bfae80f2 19256
c19d1205
ZW
19257 GOT_symbol = symbol_new (name, undefined_section,
19258 (valueT) 0, & zero_address_frag);
19259 }
bfae80f2 19260
c19d1205 19261 return GOT_symbol;
bfae80f2 19262 }
c19d1205 19263#endif
bfae80f2 19264
c921be7d 19265 return NULL;
bfae80f2
RE
19266}
19267
55cf6793 19268/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
19269 computed as two separate immediate values, added together. We
19270 already know that this value cannot be computed by just one ARM
19271 instruction. */
19272
19273static unsigned int
19274validate_immediate_twopart (unsigned int val,
19275 unsigned int * highpart)
bfae80f2 19276{
c19d1205
ZW
19277 unsigned int a;
19278 unsigned int i;
bfae80f2 19279
c19d1205
ZW
19280 for (i = 0; i < 32; i += 2)
19281 if (((a = rotate_left (val, i)) & 0xff) != 0)
19282 {
19283 if (a & 0xff00)
19284 {
19285 if (a & ~ 0xffff)
19286 continue;
19287 * highpart = (a >> 8) | ((i + 24) << 7);
19288 }
19289 else if (a & 0xff0000)
19290 {
19291 if (a & 0xff000000)
19292 continue;
19293 * highpart = (a >> 16) | ((i + 16) << 7);
19294 }
19295 else
19296 {
9c2799c2 19297 gas_assert (a & 0xff000000);
c19d1205
ZW
19298 * highpart = (a >> 24) | ((i + 8) << 7);
19299 }
bfae80f2 19300
c19d1205
ZW
19301 return (a & 0xff) | (i << 7);
19302 }
bfae80f2 19303
c19d1205 19304 return FAIL;
bfae80f2
RE
19305}
19306
c19d1205
ZW
19307static int
19308validate_offset_imm (unsigned int val, int hwse)
19309{
19310 if ((hwse && val > 255) || val > 4095)
19311 return FAIL;
19312 return val;
19313}
bfae80f2 19314
55cf6793 19315/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
19316 negative immediate constant by altering the instruction. A bit of
19317 a hack really.
19318 MOV <-> MVN
19319 AND <-> BIC
19320 ADC <-> SBC
19321 by inverting the second operand, and
19322 ADD <-> SUB
19323 CMP <-> CMN
19324 by negating the second operand. */
bfae80f2 19325
c19d1205
ZW
19326static int
19327negate_data_op (unsigned long * instruction,
19328 unsigned long value)
bfae80f2 19329{
c19d1205
ZW
19330 int op, new_inst;
19331 unsigned long negated, inverted;
bfae80f2 19332
c19d1205
ZW
19333 negated = encode_arm_immediate (-value);
19334 inverted = encode_arm_immediate (~value);
bfae80f2 19335
c19d1205
ZW
19336 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
19337 switch (op)
bfae80f2 19338 {
c19d1205
ZW
19339 /* First negates. */
19340 case OPCODE_SUB: /* ADD <-> SUB */
19341 new_inst = OPCODE_ADD;
19342 value = negated;
19343 break;
bfae80f2 19344
c19d1205
ZW
19345 case OPCODE_ADD:
19346 new_inst = OPCODE_SUB;
19347 value = negated;
19348 break;
bfae80f2 19349
c19d1205
ZW
19350 case OPCODE_CMP: /* CMP <-> CMN */
19351 new_inst = OPCODE_CMN;
19352 value = negated;
19353 break;
bfae80f2 19354
c19d1205
ZW
19355 case OPCODE_CMN:
19356 new_inst = OPCODE_CMP;
19357 value = negated;
19358 break;
bfae80f2 19359
c19d1205
ZW
19360 /* Now Inverted ops. */
19361 case OPCODE_MOV: /* MOV <-> MVN */
19362 new_inst = OPCODE_MVN;
19363 value = inverted;
19364 break;
bfae80f2 19365
c19d1205
ZW
19366 case OPCODE_MVN:
19367 new_inst = OPCODE_MOV;
19368 value = inverted;
19369 break;
bfae80f2 19370
c19d1205
ZW
19371 case OPCODE_AND: /* AND <-> BIC */
19372 new_inst = OPCODE_BIC;
19373 value = inverted;
19374 break;
bfae80f2 19375
c19d1205
ZW
19376 case OPCODE_BIC:
19377 new_inst = OPCODE_AND;
19378 value = inverted;
19379 break;
bfae80f2 19380
c19d1205
ZW
19381 case OPCODE_ADC: /* ADC <-> SBC */
19382 new_inst = OPCODE_SBC;
19383 value = inverted;
19384 break;
bfae80f2 19385
c19d1205
ZW
19386 case OPCODE_SBC:
19387 new_inst = OPCODE_ADC;
19388 value = inverted;
19389 break;
bfae80f2 19390
c19d1205
ZW
19391 /* We cannot do anything. */
19392 default:
19393 return FAIL;
b99bd4ef
NC
19394 }
19395
c19d1205
ZW
19396 if (value == (unsigned) FAIL)
19397 return FAIL;
19398
19399 *instruction &= OPCODE_MASK;
19400 *instruction |= new_inst << DATA_OP_SHIFT;
19401 return value;
b99bd4ef
NC
19402}
19403
ef8d22e6
PB
19404/* Like negate_data_op, but for Thumb-2. */
19405
19406static unsigned int
16dd5e42 19407thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
19408{
19409 int op, new_inst;
19410 int rd;
16dd5e42 19411 unsigned int negated, inverted;
ef8d22e6
PB
19412
19413 negated = encode_thumb32_immediate (-value);
19414 inverted = encode_thumb32_immediate (~value);
19415
19416 rd = (*instruction >> 8) & 0xf;
19417 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
19418 switch (op)
19419 {
19420 /* ADD <-> SUB. Includes CMP <-> CMN. */
19421 case T2_OPCODE_SUB:
19422 new_inst = T2_OPCODE_ADD;
19423 value = negated;
19424 break;
19425
19426 case T2_OPCODE_ADD:
19427 new_inst = T2_OPCODE_SUB;
19428 value = negated;
19429 break;
19430
19431 /* ORR <-> ORN. Includes MOV <-> MVN. */
19432 case T2_OPCODE_ORR:
19433 new_inst = T2_OPCODE_ORN;
19434 value = inverted;
19435 break;
19436
19437 case T2_OPCODE_ORN:
19438 new_inst = T2_OPCODE_ORR;
19439 value = inverted;
19440 break;
19441
19442 /* AND <-> BIC. TST has no inverted equivalent. */
19443 case T2_OPCODE_AND:
19444 new_inst = T2_OPCODE_BIC;
19445 if (rd == 15)
19446 value = FAIL;
19447 else
19448 value = inverted;
19449 break;
19450
19451 case T2_OPCODE_BIC:
19452 new_inst = T2_OPCODE_AND;
19453 value = inverted;
19454 break;
19455
19456 /* ADC <-> SBC */
19457 case T2_OPCODE_ADC:
19458 new_inst = T2_OPCODE_SBC;
19459 value = inverted;
19460 break;
19461
19462 case T2_OPCODE_SBC:
19463 new_inst = T2_OPCODE_ADC;
19464 value = inverted;
19465 break;
19466
19467 /* We cannot do anything. */
19468 default:
19469 return FAIL;
19470 }
19471
16dd5e42 19472 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19473 return FAIL;
19474
19475 *instruction &= T2_OPCODE_MASK;
19476 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19477 return value;
19478}
19479
8f06b2d8
PB
19480/* Read a 32-bit thumb instruction from buf. */
19481static unsigned long
19482get_thumb32_insn (char * buf)
19483{
19484 unsigned long insn;
19485 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19486 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19487
19488 return insn;
19489}
19490
a8bc6c78
PB
19491
19492/* We usually want to set the low bit on the address of thumb function
19493 symbols. In particular .word foo - . should have the low bit set.
19494 Generic code tries to fold the difference of two symbols to
19495 a constant. Prevent this and force a relocation when the first symbols
19496 is a thumb function. */
c921be7d
NC
19497
19498bfd_boolean
a8bc6c78
PB
19499arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19500{
19501 if (op == O_subtract
19502 && l->X_op == O_symbol
19503 && r->X_op == O_symbol
19504 && THUMB_IS_FUNC (l->X_add_symbol))
19505 {
19506 l->X_op = O_subtract;
19507 l->X_op_symbol = r->X_add_symbol;
19508 l->X_add_number -= r->X_add_number;
c921be7d 19509 return TRUE;
a8bc6c78 19510 }
c921be7d 19511
a8bc6c78 19512 /* Process as normal. */
c921be7d 19513 return FALSE;
a8bc6c78
PB
19514}
19515
c19d1205 19516void
55cf6793 19517md_apply_fix (fixS * fixP,
c19d1205
ZW
19518 valueT * valP,
19519 segT seg)
19520{
19521 offsetT value = * valP;
19522 offsetT newval;
19523 unsigned int newimm;
19524 unsigned long temp;
19525 int sign;
19526 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19527
9c2799c2 19528 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19529
c19d1205 19530 /* Note whether this will delete the relocation. */
4962c51a 19531
c19d1205
ZW
19532 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19533 fixP->fx_done = 1;
b99bd4ef 19534
adbaf948 19535 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19536 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19537 for emit_reloc. */
19538 value &= 0xffffffff;
19539 value ^= 0x80000000;
5f4273c7 19540 value -= 0x80000000;
adbaf948
ZW
19541
19542 *valP = value;
c19d1205 19543 fixP->fx_addnumber = value;
b99bd4ef 19544
adbaf948
ZW
19545 /* Same treatment for fixP->fx_offset. */
19546 fixP->fx_offset &= 0xffffffff;
19547 fixP->fx_offset ^= 0x80000000;
19548 fixP->fx_offset -= 0x80000000;
19549
c19d1205 19550 switch (fixP->fx_r_type)
b99bd4ef 19551 {
c19d1205
ZW
19552 case BFD_RELOC_NONE:
19553 /* This will need to go in the object file. */
19554 fixP->fx_done = 0;
19555 break;
b99bd4ef 19556
c19d1205
ZW
19557 case BFD_RELOC_ARM_IMMEDIATE:
19558 /* We claim that this fixup has been processed here,
19559 even if in fact we generate an error because we do
19560 not have a reloc for it, so tc_gen_reloc will reject it. */
19561 fixP->fx_done = 1;
b99bd4ef 19562
c19d1205
ZW
19563 if (fixP->fx_addsy
19564 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 19565 {
c19d1205
ZW
19566 as_bad_where (fixP->fx_file, fixP->fx_line,
19567 _("undefined symbol %s used as an immediate value"),
19568 S_GET_NAME (fixP->fx_addsy));
19569 break;
b99bd4ef
NC
19570 }
19571
42e5fcbf
AS
19572 if (fixP->fx_addsy
19573 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19574 {
19575 as_bad_where (fixP->fx_file, fixP->fx_line,
19576 _("symbol %s is in a different section"),
19577 S_GET_NAME (fixP->fx_addsy));
19578 break;
19579 }
19580
c19d1205
ZW
19581 newimm = encode_arm_immediate (value);
19582 temp = md_chars_to_number (buf, INSN_SIZE);
19583
19584 /* If the instruction will fail, see if we can fix things up by
19585 changing the opcode. */
19586 if (newimm == (unsigned int) FAIL
19587 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19588 {
c19d1205
ZW
19589 as_bad_where (fixP->fx_file, fixP->fx_line,
19590 _("invalid constant (%lx) after fixup"),
19591 (unsigned long) value);
19592 break;
b99bd4ef 19593 }
b99bd4ef 19594
c19d1205
ZW
19595 newimm |= (temp & 0xfffff000);
19596 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19597 break;
b99bd4ef 19598
c19d1205
ZW
19599 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19600 {
19601 unsigned int highpart = 0;
19602 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19603
42e5fcbf
AS
19604 if (fixP->fx_addsy
19605 && ! S_IS_DEFINED (fixP->fx_addsy))
19606 {
19607 as_bad_where (fixP->fx_file, fixP->fx_line,
19608 _("undefined symbol %s used as an immediate value"),
19609 S_GET_NAME (fixP->fx_addsy));
19610 break;
19611 }
19612
19613 if (fixP->fx_addsy
19614 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19615 {
19616 as_bad_where (fixP->fx_file, fixP->fx_line,
19617 _("symbol %s is in a different section"),
19618 S_GET_NAME (fixP->fx_addsy));
19619 break;
19620 }
19621
c19d1205
ZW
19622 newimm = encode_arm_immediate (value);
19623 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19624
c19d1205
ZW
19625 /* If the instruction will fail, see if we can fix things up by
19626 changing the opcode. */
19627 if (newimm == (unsigned int) FAIL
19628 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19629 {
19630 /* No ? OK - try using two ADD instructions to generate
19631 the value. */
19632 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19633
c19d1205
ZW
19634 /* Yes - then make sure that the second instruction is
19635 also an add. */
19636 if (newimm != (unsigned int) FAIL)
19637 newinsn = temp;
19638 /* Still No ? Try using a negated value. */
19639 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19640 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19641 /* Otherwise - give up. */
19642 else
19643 {
19644 as_bad_where (fixP->fx_file, fixP->fx_line,
19645 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19646 (long) value);
19647 break;
19648 }
b99bd4ef 19649
c19d1205
ZW
19650 /* Replace the first operand in the 2nd instruction (which
19651 is the PC) with the destination register. We have
19652 already added in the PC in the first instruction and we
19653 do not want to do it again. */
19654 newinsn &= ~ 0xf0000;
19655 newinsn |= ((newinsn & 0x0f000) << 4);
19656 }
b99bd4ef 19657
c19d1205
ZW
19658 newimm |= (temp & 0xfffff000);
19659 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19660
c19d1205
ZW
19661 highpart |= (newinsn & 0xfffff000);
19662 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19663 }
19664 break;
b99bd4ef 19665
c19d1205 19666 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19667 if (!fixP->fx_done && seg->use_rela_p)
19668 value = 0;
19669
c19d1205
ZW
19670 case BFD_RELOC_ARM_LITERAL:
19671 sign = value >= 0;
b99bd4ef 19672
c19d1205
ZW
19673 if (value < 0)
19674 value = - value;
b99bd4ef 19675
c19d1205 19676 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19677 {
c19d1205
ZW
19678 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19679 as_bad_where (fixP->fx_file, fixP->fx_line,
19680 _("invalid literal constant: pool needs to be closer"));
19681 else
19682 as_bad_where (fixP->fx_file, fixP->fx_line,
19683 _("bad immediate value for offset (%ld)"),
19684 (long) value);
19685 break;
f03698e6
RE
19686 }
19687
c19d1205
ZW
19688 newval = md_chars_to_number (buf, INSN_SIZE);
19689 newval &= 0xff7ff000;
19690 newval |= value | (sign ? INDEX_UP : 0);
19691 md_number_to_chars (buf, newval, INSN_SIZE);
19692 break;
b99bd4ef 19693
c19d1205
ZW
19694 case BFD_RELOC_ARM_OFFSET_IMM8:
19695 case BFD_RELOC_ARM_HWLITERAL:
19696 sign = value >= 0;
b99bd4ef 19697
c19d1205
ZW
19698 if (value < 0)
19699 value = - value;
b99bd4ef 19700
c19d1205 19701 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19702 {
c19d1205
ZW
19703 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19704 as_bad_where (fixP->fx_file, fixP->fx_line,
19705 _("invalid literal constant: pool needs to be closer"));
19706 else
f9d4405b 19707 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19708 (long) value);
19709 break;
b99bd4ef
NC
19710 }
19711
c19d1205
ZW
19712 newval = md_chars_to_number (buf, INSN_SIZE);
19713 newval &= 0xff7ff0f0;
19714 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19715 md_number_to_chars (buf, newval, INSN_SIZE);
19716 break;
b99bd4ef 19717
c19d1205
ZW
19718 case BFD_RELOC_ARM_T32_OFFSET_U8:
19719 if (value < 0 || value > 1020 || value % 4 != 0)
19720 as_bad_where (fixP->fx_file, fixP->fx_line,
19721 _("bad immediate value for offset (%ld)"), (long) value);
19722 value /= 4;
b99bd4ef 19723
c19d1205 19724 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19725 newval |= value;
19726 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19727 break;
b99bd4ef 19728
c19d1205
ZW
19729 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19730 /* This is a complicated relocation used for all varieties of Thumb32
19731 load/store instruction with immediate offset:
19732
19733 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19734 *4, optional writeback(W)
19735 (doubleword load/store)
19736
19737 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19738 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19739 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19740 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19741 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19742
19743 Uppercase letters indicate bits that are already encoded at
19744 this point. Lowercase letters are our problem. For the
19745 second block of instructions, the secondary opcode nybble
19746 (bits 8..11) is present, and bit 23 is zero, even if this is
19747 a PC-relative operation. */
19748 newval = md_chars_to_number (buf, THUMB_SIZE);
19749 newval <<= 16;
19750 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19751
c19d1205 19752 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19753 {
c19d1205
ZW
19754 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19755 if (value >= 0)
19756 newval |= (1 << 23);
19757 else
19758 value = -value;
19759 if (value % 4 != 0)
19760 {
19761 as_bad_where (fixP->fx_file, fixP->fx_line,
19762 _("offset not a multiple of 4"));
19763 break;
19764 }
19765 value /= 4;
216d22bc 19766 if (value > 0xff)
c19d1205
ZW
19767 {
19768 as_bad_where (fixP->fx_file, fixP->fx_line,
19769 _("offset out of range"));
19770 break;
19771 }
19772 newval &= ~0xff;
b99bd4ef 19773 }
c19d1205 19774 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 19775 {
c19d1205
ZW
19776 /* PC-relative, 12-bit offset. */
19777 if (value >= 0)
19778 newval |= (1 << 23);
19779 else
19780 value = -value;
216d22bc 19781 if (value > 0xfff)
c19d1205
ZW
19782 {
19783 as_bad_where (fixP->fx_file, fixP->fx_line,
19784 _("offset out of range"));
19785 break;
19786 }
19787 newval &= ~0xfff;
b99bd4ef 19788 }
c19d1205 19789 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 19790 {
c19d1205
ZW
19791 /* Writeback: 8-bit, +/- offset. */
19792 if (value >= 0)
19793 newval |= (1 << 9);
19794 else
19795 value = -value;
216d22bc 19796 if (value > 0xff)
c19d1205
ZW
19797 {
19798 as_bad_where (fixP->fx_file, fixP->fx_line,
19799 _("offset out of range"));
19800 break;
19801 }
19802 newval &= ~0xff;
b99bd4ef 19803 }
c19d1205 19804 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 19805 {
c19d1205 19806 /* T-instruction: positive 8-bit offset. */
216d22bc 19807 if (value < 0 || value > 0xff)
b99bd4ef 19808 {
c19d1205
ZW
19809 as_bad_where (fixP->fx_file, fixP->fx_line,
19810 _("offset out of range"));
19811 break;
b99bd4ef 19812 }
c19d1205
ZW
19813 newval &= ~0xff;
19814 newval |= value;
b99bd4ef
NC
19815 }
19816 else
b99bd4ef 19817 {
c19d1205
ZW
19818 /* Positive 12-bit or negative 8-bit offset. */
19819 int limit;
19820 if (value >= 0)
b99bd4ef 19821 {
c19d1205
ZW
19822 newval |= (1 << 23);
19823 limit = 0xfff;
19824 }
19825 else
19826 {
19827 value = -value;
19828 limit = 0xff;
19829 }
19830 if (value > limit)
19831 {
19832 as_bad_where (fixP->fx_file, fixP->fx_line,
19833 _("offset out of range"));
19834 break;
b99bd4ef 19835 }
c19d1205 19836 newval &= ~limit;
b99bd4ef 19837 }
b99bd4ef 19838
c19d1205
ZW
19839 newval |= value;
19840 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
19841 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
19842 break;
404ff6b5 19843
c19d1205
ZW
19844 case BFD_RELOC_ARM_SHIFT_IMM:
19845 newval = md_chars_to_number (buf, INSN_SIZE);
19846 if (((unsigned long) value) > 32
19847 || (value == 32
19848 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
19849 {
19850 as_bad_where (fixP->fx_file, fixP->fx_line,
19851 _("shift expression is too large"));
19852 break;
19853 }
404ff6b5 19854
c19d1205
ZW
19855 if (value == 0)
19856 /* Shifts of zero must be done as lsl. */
19857 newval &= ~0x60;
19858 else if (value == 32)
19859 value = 0;
19860 newval &= 0xfffff07f;
19861 newval |= (value & 0x1f) << 7;
19862 md_number_to_chars (buf, newval, INSN_SIZE);
19863 break;
404ff6b5 19864
c19d1205 19865 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 19866 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 19867 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 19868 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
19869 /* We claim that this fixup has been processed here,
19870 even if in fact we generate an error because we do
19871 not have a reloc for it, so tc_gen_reloc will reject it. */
19872 fixP->fx_done = 1;
404ff6b5 19873
c19d1205
ZW
19874 if (fixP->fx_addsy
19875 && ! S_IS_DEFINED (fixP->fx_addsy))
19876 {
19877 as_bad_where (fixP->fx_file, fixP->fx_line,
19878 _("undefined symbol %s used as an immediate value"),
19879 S_GET_NAME (fixP->fx_addsy));
19880 break;
19881 }
404ff6b5 19882
c19d1205
ZW
19883 newval = md_chars_to_number (buf, THUMB_SIZE);
19884 newval <<= 16;
19885 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 19886
16805f35
PB
19887 newimm = FAIL;
19888 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19889 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
19890 {
19891 newimm = encode_thumb32_immediate (value);
19892 if (newimm == (unsigned int) FAIL)
19893 newimm = thumb32_negate_data_op (&newval, value);
19894 }
16805f35
PB
19895 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19896 && newimm == (unsigned int) FAIL)
92e90b6e 19897 {
16805f35
PB
19898 /* Turn add/sum into addw/subw. */
19899 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19900 newval = (newval & 0xfeffffff) | 0x02000000;
19901
e9f89963
PB
19902 /* 12 bit immediate for addw/subw. */
19903 if (value < 0)
19904 {
19905 value = -value;
19906 newval ^= 0x00a00000;
19907 }
92e90b6e
PB
19908 if (value > 0xfff)
19909 newimm = (unsigned int) FAIL;
19910 else
19911 newimm = value;
19912 }
cc8a6dd0 19913
c19d1205 19914 if (newimm == (unsigned int)FAIL)
3631a3c8 19915 {
c19d1205
ZW
19916 as_bad_where (fixP->fx_file, fixP->fx_line,
19917 _("invalid constant (%lx) after fixup"),
19918 (unsigned long) value);
19919 break;
3631a3c8
NC
19920 }
19921
c19d1205
ZW
19922 newval |= (newimm & 0x800) << 15;
19923 newval |= (newimm & 0x700) << 4;
19924 newval |= (newimm & 0x0ff);
cc8a6dd0 19925
c19d1205
ZW
19926 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
19927 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
19928 break;
a737bd4d 19929
3eb17e6b 19930 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
19931 if (((unsigned long) value) > 0xffff)
19932 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 19933 _("invalid smc expression"));
2fc8bdac 19934 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19935 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
19936 md_number_to_chars (buf, newval, INSN_SIZE);
19937 break;
a737bd4d 19938
c19d1205 19939 case BFD_RELOC_ARM_SWI:
adbaf948 19940 if (fixP->tc_fix_data != 0)
c19d1205
ZW
19941 {
19942 if (((unsigned long) value) > 0xff)
19943 as_bad_where (fixP->fx_file, fixP->fx_line,
19944 _("invalid swi expression"));
2fc8bdac 19945 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
19946 newval |= value;
19947 md_number_to_chars (buf, newval, THUMB_SIZE);
19948 }
19949 else
19950 {
19951 if (((unsigned long) value) > 0x00ffffff)
19952 as_bad_where (fixP->fx_file, fixP->fx_line,
19953 _("invalid swi expression"));
2fc8bdac 19954 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19955 newval |= value;
19956 md_number_to_chars (buf, newval, INSN_SIZE);
19957 }
19958 break;
a737bd4d 19959
c19d1205
ZW
19960 case BFD_RELOC_ARM_MULTI:
19961 if (((unsigned long) value) > 0xffff)
19962 as_bad_where (fixP->fx_file, fixP->fx_line,
19963 _("invalid expression in load/store multiple"));
19964 newval = value | md_chars_to_number (buf, INSN_SIZE);
19965 md_number_to_chars (buf, newval, INSN_SIZE);
19966 break;
a737bd4d 19967
c19d1205 19968#ifdef OBJ_ELF
39b41c9c 19969 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
19970
19971 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19972 && fixP->fx_addsy
19973 && !S_IS_EXTERNAL (fixP->fx_addsy)
19974 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19975 && THUMB_IS_FUNC (fixP->fx_addsy))
19976 /* Flip the bl to blx. This is a simple flip
19977 bit here because we generate PCREL_CALL for
19978 unconditional bls. */
19979 {
19980 newval = md_chars_to_number (buf, INSN_SIZE);
19981 newval = newval | 0x10000000;
19982 md_number_to_chars (buf, newval, INSN_SIZE);
19983 temp = 1;
19984 fixP->fx_done = 1;
19985 }
39b41c9c
PB
19986 else
19987 temp = 3;
19988 goto arm_branch_common;
19989
19990 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
19991 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19992 && fixP->fx_addsy
19993 && !S_IS_EXTERNAL (fixP->fx_addsy)
19994 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19995 && THUMB_IS_FUNC (fixP->fx_addsy))
19996 {
19997 /* This would map to a bl<cond>, b<cond>,
19998 b<always> to a Thumb function. We
19999 need to force a relocation for this particular
20000 case. */
20001 newval = md_chars_to_number (buf, INSN_SIZE);
20002 fixP->fx_done = 0;
20003 }
20004
2fc8bdac 20005 case BFD_RELOC_ARM_PLT32:
c19d1205 20006#endif
39b41c9c
PB
20007 case BFD_RELOC_ARM_PCREL_BRANCH:
20008 temp = 3;
20009 goto arm_branch_common;
a737bd4d 20010
39b41c9c 20011 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 20012
39b41c9c 20013 temp = 1;
267bf995
RR
20014 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
20015 && fixP->fx_addsy
20016 && !S_IS_EXTERNAL (fixP->fx_addsy)
20017 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20018 && ARM_IS_FUNC (fixP->fx_addsy))
20019 {
20020 /* Flip the blx to a bl and warn. */
20021 const char *name = S_GET_NAME (fixP->fx_addsy);
20022 newval = 0xeb000000;
20023 as_warn_where (fixP->fx_file, fixP->fx_line,
20024 _("blx to '%s' an ARM ISA state function changed to bl"),
20025 name);
20026 md_number_to_chars (buf, newval, INSN_SIZE);
20027 temp = 3;
20028 fixP->fx_done = 1;
20029 }
20030
20031#ifdef OBJ_ELF
20032 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20033 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
20034#endif
20035
39b41c9c 20036 arm_branch_common:
c19d1205 20037 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
20038 instruction, in a 24 bit, signed field. Bits 26 through 32 either
20039 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
20040 also be be clear. */
20041 if (value & temp)
c19d1205 20042 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
20043 _("misaligned branch destination"));
20044 if ((value & (offsetT)0xfe000000) != (offsetT)0
20045 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
20046 as_bad_where (fixP->fx_file, fixP->fx_line,
20047 _("branch out of range"));
a737bd4d 20048
2fc8bdac 20049 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20050 {
2fc8bdac
ZW
20051 newval = md_chars_to_number (buf, INSN_SIZE);
20052 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
20053 /* Set the H bit on BLX instructions. */
20054 if (temp == 1)
20055 {
20056 if (value & 2)
20057 newval |= 0x01000000;
20058 else
20059 newval &= ~0x01000000;
20060 }
2fc8bdac 20061 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 20062 }
c19d1205 20063 break;
a737bd4d 20064
25fe350b
MS
20065 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
20066 /* CBZ can only branch forward. */
a737bd4d 20067
738755b0
MS
20068 /* Attempts to use CBZ to branch to the next instruction
20069 (which, strictly speaking, are prohibited) will be turned into
20070 no-ops.
20071
20072 FIXME: It may be better to remove the instruction completely and
20073 perform relaxation. */
20074 if (value == -2)
2fc8bdac
ZW
20075 {
20076 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 20077 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
20078 md_number_to_chars (buf, newval, THUMB_SIZE);
20079 }
738755b0
MS
20080 else
20081 {
20082 if (value & ~0x7e)
20083 as_bad_where (fixP->fx_file, fixP->fx_line,
20084 _("branch out of range"));
20085
20086 if (fixP->fx_done || !seg->use_rela_p)
20087 {
20088 newval = md_chars_to_number (buf, THUMB_SIZE);
20089 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
20090 md_number_to_chars (buf, newval, THUMB_SIZE);
20091 }
20092 }
c19d1205 20093 break;
a737bd4d 20094
c19d1205 20095 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
20096 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
20097 as_bad_where (fixP->fx_file, fixP->fx_line,
20098 _("branch out of range"));
a737bd4d 20099
2fc8bdac
ZW
20100 if (fixP->fx_done || !seg->use_rela_p)
20101 {
20102 newval = md_chars_to_number (buf, THUMB_SIZE);
20103 newval |= (value & 0x1ff) >> 1;
20104 md_number_to_chars (buf, newval, THUMB_SIZE);
20105 }
c19d1205 20106 break;
a737bd4d 20107
c19d1205 20108 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
20109 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
20110 as_bad_where (fixP->fx_file, fixP->fx_line,
20111 _("branch out of range"));
a737bd4d 20112
2fc8bdac
ZW
20113 if (fixP->fx_done || !seg->use_rela_p)
20114 {
20115 newval = md_chars_to_number (buf, THUMB_SIZE);
20116 newval |= (value & 0xfff) >> 1;
20117 md_number_to_chars (buf, newval, THUMB_SIZE);
20118 }
c19d1205 20119 break;
a737bd4d 20120
c19d1205 20121 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
20122 if (fixP->fx_addsy
20123 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20124 && !S_IS_EXTERNAL (fixP->fx_addsy)
20125 && S_IS_DEFINED (fixP->fx_addsy)
20126 && ARM_IS_FUNC (fixP->fx_addsy)
20127 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20128 {
20129 /* Force a relocation for a branch 20 bits wide. */
20130 fixP->fx_done = 0;
20131 }
2fc8bdac
ZW
20132 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
20133 as_bad_where (fixP->fx_file, fixP->fx_line,
20134 _("conditional branch out of range"));
404ff6b5 20135
2fc8bdac
ZW
20136 if (fixP->fx_done || !seg->use_rela_p)
20137 {
20138 offsetT newval2;
20139 addressT S, J1, J2, lo, hi;
404ff6b5 20140
2fc8bdac
ZW
20141 S = (value & 0x00100000) >> 20;
20142 J2 = (value & 0x00080000) >> 19;
20143 J1 = (value & 0x00040000) >> 18;
20144 hi = (value & 0x0003f000) >> 12;
20145 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20146
2fc8bdac
ZW
20147 newval = md_chars_to_number (buf, THUMB_SIZE);
20148 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20149 newval |= (S << 10) | hi;
20150 newval2 |= (J1 << 13) | (J2 << 11) | lo;
20151 md_number_to_chars (buf, newval, THUMB_SIZE);
20152 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20153 }
c19d1205 20154 break;
6c43fab6 20155
c19d1205 20156 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
20157
20158 /* If there is a blx from a thumb state function to
20159 another thumb function flip this to a bl and warn
20160 about it. */
20161
20162 if (fixP->fx_addsy
20163 && S_IS_DEFINED (fixP->fx_addsy)
20164 && !S_IS_EXTERNAL (fixP->fx_addsy)
20165 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20166 && THUMB_IS_FUNC (fixP->fx_addsy))
20167 {
20168 const char *name = S_GET_NAME (fixP->fx_addsy);
20169 as_warn_where (fixP->fx_file, fixP->fx_line,
20170 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
20171 name);
20172 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20173 newval = newval | 0x1000;
20174 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20175 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20176 fixP->fx_done = 1;
20177 }
20178
20179
20180 goto thumb_bl_common;
20181
c19d1205 20182 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
20183
20184 /* A bl from Thumb state ISA to an internal ARM state function
20185 is converted to a blx. */
20186 if (fixP->fx_addsy
20187 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
20188 && !S_IS_EXTERNAL (fixP->fx_addsy)
20189 && S_IS_DEFINED (fixP->fx_addsy)
20190 && ARM_IS_FUNC (fixP->fx_addsy)
20191 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
20192 {
20193 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20194 newval = newval & ~0x1000;
20195 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
20196 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
20197 fixP->fx_done = 1;
20198 }
20199
20200 thumb_bl_common:
20201
20202#ifdef OBJ_ELF
20203 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
20204 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20205 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
20206#endif
20207
2fc8bdac
ZW
20208 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
20209 as_bad_where (fixP->fx_file, fixP->fx_line,
20210 _("branch out of range"));
404ff6b5 20211
2fc8bdac
ZW
20212 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
20213 /* For a BLX instruction, make sure that the relocation is rounded up
20214 to a word boundary. This follows the semantics of the instruction
20215 which specifies that bit 1 of the target address will come from bit
20216 1 of the base address. */
20217 value = (value + 1) & ~ 1;
404ff6b5 20218
2fc8bdac 20219 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20220 {
2fc8bdac
ZW
20221 offsetT newval2;
20222
20223 newval = md_chars_to_number (buf, THUMB_SIZE);
20224 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20225 newval |= (value & 0x7fffff) >> 12;
20226 newval2 |= (value & 0xfff) >> 1;
20227 md_number_to_chars (buf, newval, THUMB_SIZE);
20228 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 20229 }
c19d1205 20230 break;
404ff6b5 20231
c19d1205 20232 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
20233 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
20234 as_bad_where (fixP->fx_file, fixP->fx_line,
20235 _("branch out of range"));
6c43fab6 20236
2fc8bdac
ZW
20237 if (fixP->fx_done || !seg->use_rela_p)
20238 {
20239 offsetT newval2;
20240 addressT S, I1, I2, lo, hi;
6c43fab6 20241
2fc8bdac
ZW
20242 S = (value & 0x01000000) >> 24;
20243 I1 = (value & 0x00800000) >> 23;
20244 I2 = (value & 0x00400000) >> 22;
20245 hi = (value & 0x003ff000) >> 12;
20246 lo = (value & 0x00000ffe) >> 1;
6c43fab6 20247
2fc8bdac
ZW
20248 I1 = !(I1 ^ S);
20249 I2 = !(I2 ^ S);
a737bd4d 20250
2fc8bdac
ZW
20251 newval = md_chars_to_number (buf, THUMB_SIZE);
20252 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
20253 newval |= (S << 10) | hi;
20254 newval2 |= (I1 << 13) | (I2 << 11) | lo;
20255 md_number_to_chars (buf, newval, THUMB_SIZE);
20256 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
20257 }
20258 break;
a737bd4d 20259
2fc8bdac
ZW
20260 case BFD_RELOC_8:
20261 if (fixP->fx_done || !seg->use_rela_p)
20262 md_number_to_chars (buf, value, 1);
c19d1205 20263 break;
a737bd4d 20264
c19d1205 20265 case BFD_RELOC_16:
2fc8bdac 20266 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 20267 md_number_to_chars (buf, value, 2);
c19d1205 20268 break;
a737bd4d 20269
c19d1205
ZW
20270#ifdef OBJ_ELF
20271 case BFD_RELOC_ARM_TLS_GD32:
20272 case BFD_RELOC_ARM_TLS_LE32:
20273 case BFD_RELOC_ARM_TLS_IE32:
20274 case BFD_RELOC_ARM_TLS_LDM32:
20275 case BFD_RELOC_ARM_TLS_LDO32:
20276 S_SET_THREAD_LOCAL (fixP->fx_addsy);
20277 /* fall through */
6c43fab6 20278
c19d1205
ZW
20279 case BFD_RELOC_ARM_GOT32:
20280 case BFD_RELOC_ARM_GOTOFF:
2fc8bdac
ZW
20281 if (fixP->fx_done || !seg->use_rela_p)
20282 md_number_to_chars (buf, 0, 4);
c19d1205 20283 break;
9a6f4e97
NS
20284
20285 case BFD_RELOC_ARM_TARGET2:
20286 /* TARGET2 is not partial-inplace, so we need to write the
20287 addend here for REL targets, because it won't be written out
20288 during reloc processing later. */
20289 if (fixP->fx_done || !seg->use_rela_p)
20290 md_number_to_chars (buf, fixP->fx_offset, 4);
20291 break;
c19d1205 20292#endif
6c43fab6 20293
c19d1205
ZW
20294 case BFD_RELOC_RVA:
20295 case BFD_RELOC_32:
20296 case BFD_RELOC_ARM_TARGET1:
20297 case BFD_RELOC_ARM_ROSEGREL32:
20298 case BFD_RELOC_ARM_SBREL32:
20299 case BFD_RELOC_32_PCREL:
f0927246
NC
20300#ifdef TE_PE
20301 case BFD_RELOC_32_SECREL:
20302#endif
2fc8bdac 20303 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
20304#ifdef TE_WINCE
20305 /* For WinCE we only do this for pcrel fixups. */
20306 if (fixP->fx_done || fixP->fx_pcrel)
20307#endif
20308 md_number_to_chars (buf, value, 4);
c19d1205 20309 break;
6c43fab6 20310
c19d1205
ZW
20311#ifdef OBJ_ELF
20312 case BFD_RELOC_ARM_PREL31:
2fc8bdac 20313 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
20314 {
20315 newval = md_chars_to_number (buf, 4) & 0x80000000;
20316 if ((value ^ (value >> 1)) & 0x40000000)
20317 {
20318 as_bad_where (fixP->fx_file, fixP->fx_line,
20319 _("rel31 relocation overflow"));
20320 }
20321 newval |= value & 0x7fffffff;
20322 md_number_to_chars (buf, newval, 4);
20323 }
20324 break;
c19d1205 20325#endif
a737bd4d 20326
c19d1205 20327 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 20328 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
20329 if (value < -1023 || value > 1023 || (value & 3))
20330 as_bad_where (fixP->fx_file, fixP->fx_line,
20331 _("co-processor offset out of range"));
20332 cp_off_common:
20333 sign = value >= 0;
20334 if (value < 0)
20335 value = -value;
8f06b2d8
PB
20336 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20337 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20338 newval = md_chars_to_number (buf, INSN_SIZE);
20339 else
20340 newval = get_thumb32_insn (buf);
20341 newval &= 0xff7fff00;
c19d1205 20342 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
20343 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
20344 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
20345 md_number_to_chars (buf, newval, INSN_SIZE);
20346 else
20347 put_thumb32_insn (buf, newval);
c19d1205 20348 break;
a737bd4d 20349
c19d1205 20350 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 20351 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
20352 if (value < -255 || value > 255)
20353 as_bad_where (fixP->fx_file, fixP->fx_line,
20354 _("co-processor offset out of range"));
df7849c5 20355 value *= 4;
c19d1205 20356 goto cp_off_common;
6c43fab6 20357
c19d1205
ZW
20358 case BFD_RELOC_ARM_THUMB_OFFSET:
20359 newval = md_chars_to_number (buf, THUMB_SIZE);
20360 /* Exactly what ranges, and where the offset is inserted depends
20361 on the type of instruction, we can establish this from the
20362 top 4 bits. */
20363 switch (newval >> 12)
20364 {
20365 case 4: /* PC load. */
20366 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
20367 forced to zero for these loads; md_pcrel_from has already
20368 compensated for this. */
20369 if (value & 3)
20370 as_bad_where (fixP->fx_file, fixP->fx_line,
20371 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
20372 (((unsigned long) fixP->fx_frag->fr_address
20373 + (unsigned long) fixP->fx_where) & ~3)
20374 + (unsigned long) value);
a737bd4d 20375
c19d1205
ZW
20376 if (value & ~0x3fc)
20377 as_bad_where (fixP->fx_file, fixP->fx_line,
20378 _("invalid offset, value too big (0x%08lX)"),
20379 (long) value);
a737bd4d 20380
c19d1205
ZW
20381 newval |= value >> 2;
20382 break;
a737bd4d 20383
c19d1205
ZW
20384 case 9: /* SP load/store. */
20385 if (value & ~0x3fc)
20386 as_bad_where (fixP->fx_file, fixP->fx_line,
20387 _("invalid offset, value too big (0x%08lX)"),
20388 (long) value);
20389 newval |= value >> 2;
20390 break;
6c43fab6 20391
c19d1205
ZW
20392 case 6: /* Word load/store. */
20393 if (value & ~0x7c)
20394 as_bad_where (fixP->fx_file, fixP->fx_line,
20395 _("invalid offset, value too big (0x%08lX)"),
20396 (long) value);
20397 newval |= value << 4; /* 6 - 2. */
20398 break;
a737bd4d 20399
c19d1205
ZW
20400 case 7: /* Byte load/store. */
20401 if (value & ~0x1f)
20402 as_bad_where (fixP->fx_file, fixP->fx_line,
20403 _("invalid offset, value too big (0x%08lX)"),
20404 (long) value);
20405 newval |= value << 6;
20406 break;
a737bd4d 20407
c19d1205
ZW
20408 case 8: /* Halfword load/store. */
20409 if (value & ~0x3e)
20410 as_bad_where (fixP->fx_file, fixP->fx_line,
20411 _("invalid offset, value too big (0x%08lX)"),
20412 (long) value);
20413 newval |= value << 5; /* 6 - 1. */
20414 break;
a737bd4d 20415
c19d1205
ZW
20416 default:
20417 as_bad_where (fixP->fx_file, fixP->fx_line,
20418 "Unable to process relocation for thumb opcode: %lx",
20419 (unsigned long) newval);
20420 break;
20421 }
20422 md_number_to_chars (buf, newval, THUMB_SIZE);
20423 break;
a737bd4d 20424
c19d1205
ZW
20425 case BFD_RELOC_ARM_THUMB_ADD:
20426 /* This is a complicated relocation, since we use it for all of
20427 the following immediate relocations:
a737bd4d 20428
c19d1205
ZW
20429 3bit ADD/SUB
20430 8bit ADD/SUB
20431 9bit ADD/SUB SP word-aligned
20432 10bit ADD PC/SP word-aligned
a737bd4d 20433
c19d1205
ZW
20434 The type of instruction being processed is encoded in the
20435 instruction field:
a737bd4d 20436
c19d1205
ZW
20437 0x8000 SUB
20438 0x00F0 Rd
20439 0x000F Rs
20440 */
20441 newval = md_chars_to_number (buf, THUMB_SIZE);
20442 {
20443 int rd = (newval >> 4) & 0xf;
20444 int rs = newval & 0xf;
20445 int subtract = !!(newval & 0x8000);
a737bd4d 20446
c19d1205
ZW
20447 /* Check for HI regs, only very restricted cases allowed:
20448 Adjusting SP, and using PC or SP to get an address. */
20449 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
20450 || (rs > 7 && rs != REG_SP && rs != REG_PC))
20451 as_bad_where (fixP->fx_file, fixP->fx_line,
20452 _("invalid Hi register with immediate"));
a737bd4d 20453
c19d1205
ZW
20454 /* If value is negative, choose the opposite instruction. */
20455 if (value < 0)
20456 {
20457 value = -value;
20458 subtract = !subtract;
20459 if (value < 0)
20460 as_bad_where (fixP->fx_file, fixP->fx_line,
20461 _("immediate value out of range"));
20462 }
a737bd4d 20463
c19d1205
ZW
20464 if (rd == REG_SP)
20465 {
20466 if (value & ~0x1fc)
20467 as_bad_where (fixP->fx_file, fixP->fx_line,
20468 _("invalid immediate for stack address calculation"));
20469 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20470 newval |= value >> 2;
20471 }
20472 else if (rs == REG_PC || rs == REG_SP)
20473 {
20474 if (subtract || value & ~0x3fc)
20475 as_bad_where (fixP->fx_file, fixP->fx_line,
20476 _("invalid immediate for address calculation (value = 0x%08lX)"),
20477 (unsigned long) value);
20478 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20479 newval |= rd << 8;
20480 newval |= value >> 2;
20481 }
20482 else if (rs == rd)
20483 {
20484 if (value & ~0xff)
20485 as_bad_where (fixP->fx_file, fixP->fx_line,
20486 _("immediate value out of range"));
20487 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20488 newval |= (rd << 8) | value;
20489 }
20490 else
20491 {
20492 if (value & ~0x7)
20493 as_bad_where (fixP->fx_file, fixP->fx_line,
20494 _("immediate value out of range"));
20495 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20496 newval |= rd | (rs << 3) | (value << 6);
20497 }
20498 }
20499 md_number_to_chars (buf, newval, THUMB_SIZE);
20500 break;
a737bd4d 20501
c19d1205
ZW
20502 case BFD_RELOC_ARM_THUMB_IMM:
20503 newval = md_chars_to_number (buf, THUMB_SIZE);
20504 if (value < 0 || value > 255)
20505 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20506 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20507 (long) value);
20508 newval |= value;
20509 md_number_to_chars (buf, newval, THUMB_SIZE);
20510 break;
a737bd4d 20511
c19d1205
ZW
20512 case BFD_RELOC_ARM_THUMB_SHIFT:
20513 /* 5bit shift value (0..32). LSL cannot take 32. */
20514 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20515 temp = newval & 0xf800;
20516 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20517 as_bad_where (fixP->fx_file, fixP->fx_line,
20518 _("invalid shift value: %ld"), (long) value);
20519 /* Shifts of zero must be encoded as LSL. */
20520 if (value == 0)
20521 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20522 /* Shifts of 32 are encoded as zero. */
20523 else if (value == 32)
20524 value = 0;
20525 newval |= value << 6;
20526 md_number_to_chars (buf, newval, THUMB_SIZE);
20527 break;
a737bd4d 20528
c19d1205
ZW
20529 case BFD_RELOC_VTABLE_INHERIT:
20530 case BFD_RELOC_VTABLE_ENTRY:
20531 fixP->fx_done = 0;
20532 return;
6c43fab6 20533
b6895b4f
PB
20534 case BFD_RELOC_ARM_MOVW:
20535 case BFD_RELOC_ARM_MOVT:
20536 case BFD_RELOC_ARM_THUMB_MOVW:
20537 case BFD_RELOC_ARM_THUMB_MOVT:
20538 if (fixP->fx_done || !seg->use_rela_p)
20539 {
20540 /* REL format relocations are limited to a 16-bit addend. */
20541 if (!fixP->fx_done)
20542 {
39623e12 20543 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20544 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20545 _("offset out of range"));
b6895b4f
PB
20546 }
20547 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20548 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20549 {
20550 value >>= 16;
20551 }
20552
20553 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20554 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20555 {
20556 newval = get_thumb32_insn (buf);
20557 newval &= 0xfbf08f00;
20558 newval |= (value & 0xf000) << 4;
20559 newval |= (value & 0x0800) << 15;
20560 newval |= (value & 0x0700) << 4;
20561 newval |= (value & 0x00ff);
20562 put_thumb32_insn (buf, newval);
20563 }
20564 else
20565 {
20566 newval = md_chars_to_number (buf, 4);
20567 newval &= 0xfff0f000;
20568 newval |= value & 0x0fff;
20569 newval |= (value & 0xf000) << 4;
20570 md_number_to_chars (buf, newval, 4);
20571 }
20572 }
20573 return;
20574
4962c51a
MS
20575 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20576 case BFD_RELOC_ARM_ALU_PC_G0:
20577 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20578 case BFD_RELOC_ARM_ALU_PC_G1:
20579 case BFD_RELOC_ARM_ALU_PC_G2:
20580 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20581 case BFD_RELOC_ARM_ALU_SB_G0:
20582 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20583 case BFD_RELOC_ARM_ALU_SB_G1:
20584 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20585 gas_assert (!fixP->fx_done);
4962c51a
MS
20586 if (!seg->use_rela_p)
20587 {
20588 bfd_vma insn;
20589 bfd_vma encoded_addend;
20590 bfd_vma addend_abs = abs (value);
20591
20592 /* Check that the absolute value of the addend can be
20593 expressed as an 8-bit constant plus a rotation. */
20594 encoded_addend = encode_arm_immediate (addend_abs);
20595 if (encoded_addend == (unsigned int) FAIL)
20596 as_bad_where (fixP->fx_file, fixP->fx_line,
20597 _("the offset 0x%08lX is not representable"),
495bde8e 20598 (unsigned long) addend_abs);
4962c51a
MS
20599
20600 /* Extract the instruction. */
20601 insn = md_chars_to_number (buf, INSN_SIZE);
20602
20603 /* If the addend is positive, use an ADD instruction.
20604 Otherwise use a SUB. Take care not to destroy the S bit. */
20605 insn &= 0xff1fffff;
20606 if (value < 0)
20607 insn |= 1 << 22;
20608 else
20609 insn |= 1 << 23;
20610
20611 /* Place the encoded addend into the first 12 bits of the
20612 instruction. */
20613 insn &= 0xfffff000;
20614 insn |= encoded_addend;
5f4273c7
NC
20615
20616 /* Update the instruction. */
4962c51a
MS
20617 md_number_to_chars (buf, insn, INSN_SIZE);
20618 }
20619 break;
20620
20621 case BFD_RELOC_ARM_LDR_PC_G0:
20622 case BFD_RELOC_ARM_LDR_PC_G1:
20623 case BFD_RELOC_ARM_LDR_PC_G2:
20624 case BFD_RELOC_ARM_LDR_SB_G0:
20625 case BFD_RELOC_ARM_LDR_SB_G1:
20626 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20627 gas_assert (!fixP->fx_done);
4962c51a
MS
20628 if (!seg->use_rela_p)
20629 {
20630 bfd_vma insn;
20631 bfd_vma addend_abs = abs (value);
20632
20633 /* Check that the absolute value of the addend can be
20634 encoded in 12 bits. */
20635 if (addend_abs >= 0x1000)
20636 as_bad_where (fixP->fx_file, fixP->fx_line,
20637 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20638 (unsigned long) addend_abs);
4962c51a
MS
20639
20640 /* Extract the instruction. */
20641 insn = md_chars_to_number (buf, INSN_SIZE);
20642
20643 /* If the addend is negative, clear bit 23 of the instruction.
20644 Otherwise set it. */
20645 if (value < 0)
20646 insn &= ~(1 << 23);
20647 else
20648 insn |= 1 << 23;
20649
20650 /* Place the absolute value of the addend into the first 12 bits
20651 of the instruction. */
20652 insn &= 0xfffff000;
20653 insn |= addend_abs;
5f4273c7
NC
20654
20655 /* Update the instruction. */
4962c51a
MS
20656 md_number_to_chars (buf, insn, INSN_SIZE);
20657 }
20658 break;
20659
20660 case BFD_RELOC_ARM_LDRS_PC_G0:
20661 case BFD_RELOC_ARM_LDRS_PC_G1:
20662 case BFD_RELOC_ARM_LDRS_PC_G2:
20663 case BFD_RELOC_ARM_LDRS_SB_G0:
20664 case BFD_RELOC_ARM_LDRS_SB_G1:
20665 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20666 gas_assert (!fixP->fx_done);
4962c51a
MS
20667 if (!seg->use_rela_p)
20668 {
20669 bfd_vma insn;
20670 bfd_vma addend_abs = abs (value);
20671
20672 /* Check that the absolute value of the addend can be
20673 encoded in 8 bits. */
20674 if (addend_abs >= 0x100)
20675 as_bad_where (fixP->fx_file, fixP->fx_line,
20676 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20677 (unsigned long) addend_abs);
4962c51a
MS
20678
20679 /* Extract the instruction. */
20680 insn = md_chars_to_number (buf, INSN_SIZE);
20681
20682 /* If the addend is negative, clear bit 23 of the instruction.
20683 Otherwise set it. */
20684 if (value < 0)
20685 insn &= ~(1 << 23);
20686 else
20687 insn |= 1 << 23;
20688
20689 /* Place the first four bits of the absolute value of the addend
20690 into the first 4 bits of the instruction, and the remaining
20691 four into bits 8 .. 11. */
20692 insn &= 0xfffff0f0;
20693 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20694
20695 /* Update the instruction. */
4962c51a
MS
20696 md_number_to_chars (buf, insn, INSN_SIZE);
20697 }
20698 break;
20699
20700 case BFD_RELOC_ARM_LDC_PC_G0:
20701 case BFD_RELOC_ARM_LDC_PC_G1:
20702 case BFD_RELOC_ARM_LDC_PC_G2:
20703 case BFD_RELOC_ARM_LDC_SB_G0:
20704 case BFD_RELOC_ARM_LDC_SB_G1:
20705 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20706 gas_assert (!fixP->fx_done);
4962c51a
MS
20707 if (!seg->use_rela_p)
20708 {
20709 bfd_vma insn;
20710 bfd_vma addend_abs = abs (value);
20711
20712 /* Check that the absolute value of the addend is a multiple of
20713 four and, when divided by four, fits in 8 bits. */
20714 if (addend_abs & 0x3)
20715 as_bad_where (fixP->fx_file, fixP->fx_line,
20716 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20717 (unsigned long) addend_abs);
4962c51a
MS
20718
20719 if ((addend_abs >> 2) > 0xff)
20720 as_bad_where (fixP->fx_file, fixP->fx_line,
20721 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20722 (unsigned long) addend_abs);
4962c51a
MS
20723
20724 /* Extract the instruction. */
20725 insn = md_chars_to_number (buf, INSN_SIZE);
20726
20727 /* If the addend is negative, clear bit 23 of the instruction.
20728 Otherwise set it. */
20729 if (value < 0)
20730 insn &= ~(1 << 23);
20731 else
20732 insn |= 1 << 23;
20733
20734 /* Place the addend (divided by four) into the first eight
20735 bits of the instruction. */
20736 insn &= 0xfffffff0;
20737 insn |= addend_abs >> 2;
5f4273c7
NC
20738
20739 /* Update the instruction. */
4962c51a
MS
20740 md_number_to_chars (buf, insn, INSN_SIZE);
20741 }
20742 break;
20743
845b51d6
PB
20744 case BFD_RELOC_ARM_V4BX:
20745 /* This will need to go in the object file. */
20746 fixP->fx_done = 0;
20747 break;
20748
c19d1205
ZW
20749 case BFD_RELOC_UNUSED:
20750 default:
20751 as_bad_where (fixP->fx_file, fixP->fx_line,
20752 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20753 }
6c43fab6
RE
20754}
20755
c19d1205
ZW
20756/* Translate internal representation of relocation info to BFD target
20757 format. */
a737bd4d 20758
c19d1205 20759arelent *
00a97672 20760tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20761{
c19d1205
ZW
20762 arelent * reloc;
20763 bfd_reloc_code_real_type code;
a737bd4d 20764
21d799b5 20765 reloc = (arelent *) xmalloc (sizeof (arelent));
a737bd4d 20766
21d799b5 20767 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
c19d1205
ZW
20768 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20769 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20770
2fc8bdac 20771 if (fixp->fx_pcrel)
00a97672
RS
20772 {
20773 if (section->use_rela_p)
20774 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20775 else
20776 fixp->fx_offset = reloc->address;
20777 }
c19d1205 20778 reloc->addend = fixp->fx_offset;
a737bd4d 20779
c19d1205 20780 switch (fixp->fx_r_type)
a737bd4d 20781 {
c19d1205
ZW
20782 case BFD_RELOC_8:
20783 if (fixp->fx_pcrel)
20784 {
20785 code = BFD_RELOC_8_PCREL;
20786 break;
20787 }
a737bd4d 20788
c19d1205
ZW
20789 case BFD_RELOC_16:
20790 if (fixp->fx_pcrel)
20791 {
20792 code = BFD_RELOC_16_PCREL;
20793 break;
20794 }
6c43fab6 20795
c19d1205
ZW
20796 case BFD_RELOC_32:
20797 if (fixp->fx_pcrel)
20798 {
20799 code = BFD_RELOC_32_PCREL;
20800 break;
20801 }
a737bd4d 20802
b6895b4f
PB
20803 case BFD_RELOC_ARM_MOVW:
20804 if (fixp->fx_pcrel)
20805 {
20806 code = BFD_RELOC_ARM_MOVW_PCREL;
20807 break;
20808 }
20809
20810 case BFD_RELOC_ARM_MOVT:
20811 if (fixp->fx_pcrel)
20812 {
20813 code = BFD_RELOC_ARM_MOVT_PCREL;
20814 break;
20815 }
20816
20817 case BFD_RELOC_ARM_THUMB_MOVW:
20818 if (fixp->fx_pcrel)
20819 {
20820 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20821 break;
20822 }
20823
20824 case BFD_RELOC_ARM_THUMB_MOVT:
20825 if (fixp->fx_pcrel)
20826 {
20827 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20828 break;
20829 }
20830
c19d1205
ZW
20831 case BFD_RELOC_NONE:
20832 case BFD_RELOC_ARM_PCREL_BRANCH:
20833 case BFD_RELOC_ARM_PCREL_BLX:
20834 case BFD_RELOC_RVA:
20835 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20836 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20837 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20838 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20839 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20840 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
20841 case BFD_RELOC_VTABLE_ENTRY:
20842 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
20843#ifdef TE_PE
20844 case BFD_RELOC_32_SECREL:
20845#endif
c19d1205
ZW
20846 code = fixp->fx_r_type;
20847 break;
a737bd4d 20848
00adf2d4
JB
20849 case BFD_RELOC_THUMB_PCREL_BLX:
20850#ifdef OBJ_ELF
20851 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20852 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
20853 else
20854#endif
20855 code = BFD_RELOC_THUMB_PCREL_BLX;
20856 break;
20857
c19d1205
ZW
20858 case BFD_RELOC_ARM_LITERAL:
20859 case BFD_RELOC_ARM_HWLITERAL:
20860 /* If this is called then the a literal has
20861 been referenced across a section boundary. */
20862 as_bad_where (fixp->fx_file, fixp->fx_line,
20863 _("literal referenced across section boundary"));
20864 return NULL;
a737bd4d 20865
c19d1205
ZW
20866#ifdef OBJ_ELF
20867 case BFD_RELOC_ARM_GOT32:
20868 case BFD_RELOC_ARM_GOTOFF:
20869 case BFD_RELOC_ARM_PLT32:
20870 case BFD_RELOC_ARM_TARGET1:
20871 case BFD_RELOC_ARM_ROSEGREL32:
20872 case BFD_RELOC_ARM_SBREL32:
20873 case BFD_RELOC_ARM_PREL31:
20874 case BFD_RELOC_ARM_TARGET2:
20875 case BFD_RELOC_ARM_TLS_LE32:
20876 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
20877 case BFD_RELOC_ARM_PCREL_CALL:
20878 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
20879 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20880 case BFD_RELOC_ARM_ALU_PC_G0:
20881 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20882 case BFD_RELOC_ARM_ALU_PC_G1:
20883 case BFD_RELOC_ARM_ALU_PC_G2:
20884 case BFD_RELOC_ARM_LDR_PC_G0:
20885 case BFD_RELOC_ARM_LDR_PC_G1:
20886 case BFD_RELOC_ARM_LDR_PC_G2:
20887 case BFD_RELOC_ARM_LDRS_PC_G0:
20888 case BFD_RELOC_ARM_LDRS_PC_G1:
20889 case BFD_RELOC_ARM_LDRS_PC_G2:
20890 case BFD_RELOC_ARM_LDC_PC_G0:
20891 case BFD_RELOC_ARM_LDC_PC_G1:
20892 case BFD_RELOC_ARM_LDC_PC_G2:
20893 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20894 case BFD_RELOC_ARM_ALU_SB_G0:
20895 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20896 case BFD_RELOC_ARM_ALU_SB_G1:
20897 case BFD_RELOC_ARM_ALU_SB_G2:
20898 case BFD_RELOC_ARM_LDR_SB_G0:
20899 case BFD_RELOC_ARM_LDR_SB_G1:
20900 case BFD_RELOC_ARM_LDR_SB_G2:
20901 case BFD_RELOC_ARM_LDRS_SB_G0:
20902 case BFD_RELOC_ARM_LDRS_SB_G1:
20903 case BFD_RELOC_ARM_LDRS_SB_G2:
20904 case BFD_RELOC_ARM_LDC_SB_G0:
20905 case BFD_RELOC_ARM_LDC_SB_G1:
20906 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 20907 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
20908 code = fixp->fx_r_type;
20909 break;
a737bd4d 20910
c19d1205
ZW
20911 case BFD_RELOC_ARM_TLS_GD32:
20912 case BFD_RELOC_ARM_TLS_IE32:
20913 case BFD_RELOC_ARM_TLS_LDM32:
20914 /* BFD will include the symbol's address in the addend.
20915 But we don't want that, so subtract it out again here. */
20916 if (!S_IS_COMMON (fixp->fx_addsy))
20917 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
20918 code = fixp->fx_r_type;
20919 break;
20920#endif
a737bd4d 20921
c19d1205
ZW
20922 case BFD_RELOC_ARM_IMMEDIATE:
20923 as_bad_where (fixp->fx_file, fixp->fx_line,
20924 _("internal relocation (type: IMMEDIATE) not fixed up"));
20925 return NULL;
a737bd4d 20926
c19d1205
ZW
20927 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20928 as_bad_where (fixp->fx_file, fixp->fx_line,
20929 _("ADRL used for a symbol not defined in the same file"));
20930 return NULL;
a737bd4d 20931
c19d1205 20932 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20933 if (section->use_rela_p)
20934 {
20935 code = fixp->fx_r_type;
20936 break;
20937 }
20938
c19d1205
ZW
20939 if (fixp->fx_addsy != NULL
20940 && !S_IS_DEFINED (fixp->fx_addsy)
20941 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 20942 {
c19d1205
ZW
20943 as_bad_where (fixp->fx_file, fixp->fx_line,
20944 _("undefined local label `%s'"),
20945 S_GET_NAME (fixp->fx_addsy));
20946 return NULL;
a737bd4d
NC
20947 }
20948
c19d1205
ZW
20949 as_bad_where (fixp->fx_file, fixp->fx_line,
20950 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
20951 return NULL;
a737bd4d 20952
c19d1205
ZW
20953 default:
20954 {
20955 char * type;
6c43fab6 20956
c19d1205
ZW
20957 switch (fixp->fx_r_type)
20958 {
20959 case BFD_RELOC_NONE: type = "NONE"; break;
20960 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
20961 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 20962 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
20963 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
20964 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
20965 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 20966 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
20967 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
20968 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
20969 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
20970 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
20971 default: type = _("<unknown>"); break;
20972 }
20973 as_bad_where (fixp->fx_file, fixp->fx_line,
20974 _("cannot represent %s relocation in this object file format"),
20975 type);
20976 return NULL;
20977 }
a737bd4d 20978 }
6c43fab6 20979
c19d1205
ZW
20980#ifdef OBJ_ELF
20981 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
20982 && GOT_symbol
20983 && fixp->fx_addsy == GOT_symbol)
20984 {
20985 code = BFD_RELOC_ARM_GOTPC;
20986 reloc->addend = fixp->fx_offset = reloc->address;
20987 }
20988#endif
6c43fab6 20989
c19d1205 20990 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 20991
c19d1205
ZW
20992 if (reloc->howto == NULL)
20993 {
20994 as_bad_where (fixp->fx_file, fixp->fx_line,
20995 _("cannot represent %s relocation in this object file format"),
20996 bfd_get_reloc_code_name (code));
20997 return NULL;
20998 }
6c43fab6 20999
c19d1205
ZW
21000 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
21001 vtable entry to be used in the relocation's section offset. */
21002 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
21003 reloc->address = fixp->fx_offset;
6c43fab6 21004
c19d1205 21005 return reloc;
6c43fab6
RE
21006}
21007
c19d1205 21008/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 21009
c19d1205
ZW
21010void
21011cons_fix_new_arm (fragS * frag,
21012 int where,
21013 int size,
21014 expressionS * exp)
6c43fab6 21015{
c19d1205
ZW
21016 bfd_reloc_code_real_type type;
21017 int pcrel = 0;
6c43fab6 21018
c19d1205
ZW
21019 /* Pick a reloc.
21020 FIXME: @@ Should look at CPU word size. */
21021 switch (size)
21022 {
21023 case 1:
21024 type = BFD_RELOC_8;
21025 break;
21026 case 2:
21027 type = BFD_RELOC_16;
21028 break;
21029 case 4:
21030 default:
21031 type = BFD_RELOC_32;
21032 break;
21033 case 8:
21034 type = BFD_RELOC_64;
21035 break;
21036 }
6c43fab6 21037
f0927246
NC
21038#ifdef TE_PE
21039 if (exp->X_op == O_secrel)
21040 {
21041 exp->X_op = O_symbol;
21042 type = BFD_RELOC_32_SECREL;
21043 }
21044#endif
21045
c19d1205
ZW
21046 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
21047}
6c43fab6 21048
4343666d 21049#if defined (OBJ_COFF)
c19d1205
ZW
21050void
21051arm_validate_fix (fixS * fixP)
6c43fab6 21052{
c19d1205
ZW
21053 /* If the destination of the branch is a defined symbol which does not have
21054 the THUMB_FUNC attribute, then we must be calling a function which has
21055 the (interfacearm) attribute. We look for the Thumb entry point to that
21056 function and change the branch to refer to that function instead. */
21057 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
21058 && fixP->fx_addsy != NULL
21059 && S_IS_DEFINED (fixP->fx_addsy)
21060 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 21061 {
c19d1205 21062 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 21063 }
c19d1205
ZW
21064}
21065#endif
6c43fab6 21066
267bf995 21067
c19d1205
ZW
21068int
21069arm_force_relocation (struct fix * fixp)
21070{
21071#if defined (OBJ_COFF) && defined (TE_PE)
21072 if (fixp->fx_r_type == BFD_RELOC_RVA)
21073 return 1;
21074#endif
6c43fab6 21075
267bf995
RR
21076 /* In case we have a call or a branch to a function in ARM ISA mode from
21077 a thumb function or vice-versa force the relocation. These relocations
21078 are cleared off for some cores that might have blx and simple transformations
21079 are possible. */
21080
21081#ifdef OBJ_ELF
21082 switch (fixp->fx_r_type)
21083 {
21084 case BFD_RELOC_ARM_PCREL_JUMP:
21085 case BFD_RELOC_ARM_PCREL_CALL:
21086 case BFD_RELOC_THUMB_PCREL_BLX:
21087 if (THUMB_IS_FUNC (fixp->fx_addsy))
21088 return 1;
21089 break;
21090
21091 case BFD_RELOC_ARM_PCREL_BLX:
21092 case BFD_RELOC_THUMB_PCREL_BRANCH25:
21093 case BFD_RELOC_THUMB_PCREL_BRANCH20:
21094 case BFD_RELOC_THUMB_PCREL_BRANCH23:
21095 if (ARM_IS_FUNC (fixp->fx_addsy))
21096 return 1;
21097 break;
21098
21099 default:
21100 break;
21101 }
21102#endif
21103
c19d1205
ZW
21104 /* Resolve these relocations even if the symbol is extern or weak. */
21105 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
21106 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 21107 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 21108 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
21109 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
21110 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
21111 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 21112 return 0;
a737bd4d 21113
4962c51a
MS
21114 /* Always leave these relocations for the linker. */
21115 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21116 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21117 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
21118 return 1;
21119
f0291e4c
PB
21120 /* Always generate relocations against function symbols. */
21121 if (fixp->fx_r_type == BFD_RELOC_32
21122 && fixp->fx_addsy
21123 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
21124 return 1;
21125
c19d1205 21126 return generic_force_reloc (fixp);
404ff6b5
AH
21127}
21128
0ffdc86c 21129#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
21130/* Relocations against function names must be left unadjusted,
21131 so that the linker can use this information to generate interworking
21132 stubs. The MIPS version of this function
c19d1205
ZW
21133 also prevents relocations that are mips-16 specific, but I do not
21134 know why it does this.
404ff6b5 21135
c19d1205
ZW
21136 FIXME:
21137 There is one other problem that ought to be addressed here, but
21138 which currently is not: Taking the address of a label (rather
21139 than a function) and then later jumping to that address. Such
21140 addresses also ought to have their bottom bit set (assuming that
21141 they reside in Thumb code), but at the moment they will not. */
404ff6b5 21142
c19d1205
ZW
21143bfd_boolean
21144arm_fix_adjustable (fixS * fixP)
404ff6b5 21145{
c19d1205
ZW
21146 if (fixP->fx_addsy == NULL)
21147 return 1;
404ff6b5 21148
e28387c3
PB
21149 /* Preserve relocations against symbols with function type. */
21150 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
c921be7d 21151 return FALSE;
e28387c3 21152
c19d1205
ZW
21153 if (THUMB_IS_FUNC (fixP->fx_addsy)
21154 && fixP->fx_subsy == NULL)
c921be7d 21155 return FALSE;
a737bd4d 21156
c19d1205
ZW
21157 /* We need the symbol name for the VTABLE entries. */
21158 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
21159 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
c921be7d 21160 return FALSE;
404ff6b5 21161
c19d1205
ZW
21162 /* Don't allow symbols to be discarded on GOT related relocs. */
21163 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
21164 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
21165 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
21166 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
21167 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
21168 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
21169 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
21170 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
21171 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
c921be7d 21172 return FALSE;
a737bd4d 21173
4962c51a
MS
21174 /* Similarly for group relocations. */
21175 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
21176 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
21177 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
c921be7d 21178 return FALSE;
4962c51a 21179
79947c54
CD
21180 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
21181 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
21182 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
21183 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
21184 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
21185 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
21186 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
21187 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
21188 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
c921be7d 21189 return FALSE;
79947c54 21190
c921be7d 21191 return TRUE;
a737bd4d 21192}
0ffdc86c
NC
21193#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
21194
21195#ifdef OBJ_ELF
404ff6b5 21196
c19d1205
ZW
21197const char *
21198elf32_arm_target_format (void)
404ff6b5 21199{
c19d1205
ZW
21200#ifdef TE_SYMBIAN
21201 return (target_big_endian
21202 ? "elf32-bigarm-symbian"
21203 : "elf32-littlearm-symbian");
21204#elif defined (TE_VXWORKS)
21205 return (target_big_endian
21206 ? "elf32-bigarm-vxworks"
21207 : "elf32-littlearm-vxworks");
21208#else
21209 if (target_big_endian)
21210 return "elf32-bigarm";
21211 else
21212 return "elf32-littlearm";
21213#endif
404ff6b5
AH
21214}
21215
c19d1205
ZW
21216void
21217armelf_frob_symbol (symbolS * symp,
21218 int * puntp)
404ff6b5 21219{
c19d1205
ZW
21220 elf_frob_symbol (symp, puntp);
21221}
21222#endif
404ff6b5 21223
c19d1205 21224/* MD interface: Finalization. */
a737bd4d 21225
c19d1205
ZW
21226void
21227arm_cleanup (void)
21228{
21229 literal_pool * pool;
a737bd4d 21230
e07e6e58
NC
21231 /* Ensure that all the IT blocks are properly closed. */
21232 check_it_blocks_finished ();
21233
c19d1205
ZW
21234 for (pool = list_of_pools; pool; pool = pool->next)
21235 {
5f4273c7 21236 /* Put it at the end of the relevant section. */
c19d1205
ZW
21237 subseg_set (pool->section, pool->sub_section);
21238#ifdef OBJ_ELF
21239 arm_elf_change_section ();
21240#endif
21241 s_ltorg (0);
21242 }
404ff6b5
AH
21243}
21244
cd000bff
DJ
21245#ifdef OBJ_ELF
21246/* Remove any excess mapping symbols generated for alignment frags in
21247 SEC. We may have created a mapping symbol before a zero byte
21248 alignment; remove it if there's a mapping symbol after the
21249 alignment. */
21250static void
21251check_mapping_symbols (bfd *abfd ATTRIBUTE_UNUSED, asection *sec,
21252 void *dummy ATTRIBUTE_UNUSED)
21253{
21254 segment_info_type *seginfo = seg_info (sec);
21255 fragS *fragp;
21256
21257 if (seginfo == NULL || seginfo->frchainP == NULL)
21258 return;
21259
21260 for (fragp = seginfo->frchainP->frch_root;
21261 fragp != NULL;
21262 fragp = fragp->fr_next)
21263 {
21264 symbolS *sym = fragp->tc_frag_data.last_map;
21265 fragS *next = fragp->fr_next;
21266
21267 /* Variable-sized frags have been converted to fixed size by
21268 this point. But if this was variable-sized to start with,
21269 there will be a fixed-size frag after it. So don't handle
21270 next == NULL. */
21271 if (sym == NULL || next == NULL)
21272 continue;
21273
21274 if (S_GET_VALUE (sym) < next->fr_address)
21275 /* Not at the end of this frag. */
21276 continue;
21277 know (S_GET_VALUE (sym) == next->fr_address);
21278
21279 do
21280 {
21281 if (next->tc_frag_data.first_map != NULL)
21282 {
21283 /* Next frag starts with a mapping symbol. Discard this
21284 one. */
21285 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21286 break;
21287 }
21288
21289 if (next->fr_next == NULL)
21290 {
21291 /* This mapping symbol is at the end of the section. Discard
21292 it. */
21293 know (next->fr_fix == 0 && next->fr_var == 0);
21294 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
21295 break;
21296 }
21297
21298 /* As long as we have empty frags without any mapping symbols,
21299 keep looking. */
21300 /* If the next frag is non-empty and does not start with a
21301 mapping symbol, then this mapping symbol is required. */
21302 if (next->fr_address != next->fr_next->fr_address)
21303 break;
21304
21305 next = next->fr_next;
21306 }
21307 while (next != NULL);
21308 }
21309}
21310#endif
21311
c19d1205
ZW
21312/* Adjust the symbol table. This marks Thumb symbols as distinct from
21313 ARM ones. */
404ff6b5 21314
c19d1205
ZW
21315void
21316arm_adjust_symtab (void)
404ff6b5 21317{
c19d1205
ZW
21318#ifdef OBJ_COFF
21319 symbolS * sym;
404ff6b5 21320
c19d1205
ZW
21321 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
21322 {
21323 if (ARM_IS_THUMB (sym))
21324 {
21325 if (THUMB_IS_FUNC (sym))
21326 {
21327 /* Mark the symbol as a Thumb function. */
21328 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
21329 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
21330 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 21331
c19d1205
ZW
21332 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
21333 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
21334 else
21335 as_bad (_("%s: unexpected function type: %d"),
21336 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
21337 }
21338 else switch (S_GET_STORAGE_CLASS (sym))
21339 {
21340 case C_EXT:
21341 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
21342 break;
21343 case C_STAT:
21344 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
21345 break;
21346 case C_LABEL:
21347 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
21348 break;
21349 default:
21350 /* Do nothing. */
21351 break;
21352 }
21353 }
a737bd4d 21354
c19d1205
ZW
21355 if (ARM_IS_INTERWORK (sym))
21356 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 21357 }
c19d1205
ZW
21358#endif
21359#ifdef OBJ_ELF
21360 symbolS * sym;
21361 char bind;
404ff6b5 21362
c19d1205 21363 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 21364 {
c19d1205
ZW
21365 if (ARM_IS_THUMB (sym))
21366 {
21367 elf_symbol_type * elf_sym;
404ff6b5 21368
c19d1205
ZW
21369 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
21370 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 21371
b0796911
PB
21372 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
21373 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
21374 {
21375 /* If it's a .thumb_func, declare it as so,
21376 otherwise tag label as .code 16. */
21377 if (THUMB_IS_FUNC (sym))
21378 elf_sym->internal_elf_sym.st_info =
21379 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 21380 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
21381 elf_sym->internal_elf_sym.st_info =
21382 ELF_ST_INFO (bind, STT_ARM_16BIT);
21383 }
21384 }
21385 }
cd000bff
DJ
21386
21387 /* Remove any overlapping mapping symbols generated by alignment frags. */
21388 bfd_map_over_sections (stdoutput, check_mapping_symbols, (char *) 0);
c19d1205 21389#endif
404ff6b5
AH
21390}
21391
c19d1205 21392/* MD interface: Initialization. */
404ff6b5 21393
a737bd4d 21394static void
c19d1205 21395set_constant_flonums (void)
a737bd4d 21396{
c19d1205 21397 int i;
404ff6b5 21398
c19d1205
ZW
21399 for (i = 0; i < NUM_FLOAT_VALS; i++)
21400 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
21401 abort ();
a737bd4d 21402}
404ff6b5 21403
3e9e4fcf
JB
21404/* Auto-select Thumb mode if it's the only available instruction set for the
21405 given architecture. */
21406
21407static void
21408autoselect_thumb_from_cpu_variant (void)
21409{
21410 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
21411 opcode_select (16);
21412}
21413
c19d1205
ZW
21414void
21415md_begin (void)
a737bd4d 21416{
c19d1205
ZW
21417 unsigned mach;
21418 unsigned int i;
404ff6b5 21419
c19d1205
ZW
21420 if ( (arm_ops_hsh = hash_new ()) == NULL
21421 || (arm_cond_hsh = hash_new ()) == NULL
21422 || (arm_shift_hsh = hash_new ()) == NULL
21423 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 21424 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 21425 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
21426 || (arm_reloc_hsh = hash_new ()) == NULL
21427 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
21428 as_fatal (_("virtual memory exhausted"));
21429
21430 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
d3ce72d0 21431 hash_insert (arm_ops_hsh, insns[i].template_name, (void *) (insns + i));
c19d1205 21432 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
d3ce72d0 21433 hash_insert (arm_cond_hsh, conds[i].template_name, (void *) (conds + i));
c19d1205 21434 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 21435 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 21436 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
d3ce72d0 21437 hash_insert (arm_psr_hsh, psrs[i].template_name, (void *) (psrs + i));
62b3e311 21438 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
d3ce72d0
NC
21439 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template_name,
21440 (void *) (v7m_psrs + i));
c19d1205 21441 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 21442 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
21443 for (i = 0;
21444 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
21445 i++)
d3ce72d0 21446 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template_name,
5a49b8ac 21447 (void *) (barrier_opt_names + i));
c19d1205
ZW
21448#ifdef OBJ_ELF
21449 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 21450 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
21451#endif
21452
21453 set_constant_flonums ();
404ff6b5 21454
c19d1205
ZW
21455 /* Set the cpu variant based on the command-line options. We prefer
21456 -mcpu= over -march= if both are set (as for GCC); and we prefer
21457 -mfpu= over any other way of setting the floating point unit.
21458 Use of legacy options with new options are faulted. */
e74cfd16 21459 if (legacy_cpu)
404ff6b5 21460 {
e74cfd16 21461 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
21462 as_bad (_("use of old and new-style options to set CPU type"));
21463
21464 mcpu_cpu_opt = legacy_cpu;
404ff6b5 21465 }
e74cfd16 21466 else if (!mcpu_cpu_opt)
c19d1205 21467 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 21468
e74cfd16 21469 if (legacy_fpu)
c19d1205 21470 {
e74cfd16 21471 if (mfpu_opt)
c19d1205 21472 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
21473
21474 mfpu_opt = legacy_fpu;
21475 }
e74cfd16 21476 else if (!mfpu_opt)
03b1477f 21477 {
45eb4c1b
NS
21478#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
21479 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
21480 /* Some environments specify a default FPU. If they don't, infer it
21481 from the processor. */
e74cfd16 21482 if (mcpu_fpu_opt)
03b1477f
RE
21483 mfpu_opt = mcpu_fpu_opt;
21484 else
21485 mfpu_opt = march_fpu_opt;
39c2da32 21486#else
e74cfd16 21487 mfpu_opt = &fpu_default;
39c2da32 21488#endif
03b1477f
RE
21489 }
21490
e74cfd16 21491 if (!mfpu_opt)
03b1477f 21492 {
493cb6ef 21493 if (mcpu_cpu_opt != NULL)
e74cfd16 21494 mfpu_opt = &fpu_default;
493cb6ef 21495 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 21496 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 21497 else
e74cfd16 21498 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
21499 }
21500
ee065d83 21501#ifdef CPU_DEFAULT
e74cfd16 21502 if (!mcpu_cpu_opt)
ee065d83 21503 {
e74cfd16
PB
21504 mcpu_cpu_opt = &cpu_default;
21505 selected_cpu = cpu_default;
ee065d83 21506 }
e74cfd16
PB
21507#else
21508 if (mcpu_cpu_opt)
21509 selected_cpu = *mcpu_cpu_opt;
ee065d83 21510 else
e74cfd16 21511 mcpu_cpu_opt = &arm_arch_any;
ee065d83 21512#endif
03b1477f 21513
e74cfd16 21514 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 21515
3e9e4fcf
JB
21516 autoselect_thumb_from_cpu_variant ();
21517
e74cfd16 21518 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 21519
f17c130b 21520#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 21521 {
7cc69913
NC
21522 unsigned int flags = 0;
21523
21524#if defined OBJ_ELF
21525 flags = meabi_flags;
d507cf36
PB
21526
21527 switch (meabi_flags)
33a392fb 21528 {
d507cf36 21529 case EF_ARM_EABI_UNKNOWN:
7cc69913 21530#endif
d507cf36
PB
21531 /* Set the flags in the private structure. */
21532 if (uses_apcs_26) flags |= F_APCS26;
21533 if (support_interwork) flags |= F_INTERWORK;
21534 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21535 if (pic_code) flags |= F_PIC;
e74cfd16 21536 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21537 flags |= F_SOFT_FLOAT;
21538
d507cf36
PB
21539 switch (mfloat_abi_opt)
21540 {
21541 case ARM_FLOAT_ABI_SOFT:
21542 case ARM_FLOAT_ABI_SOFTFP:
21543 flags |= F_SOFT_FLOAT;
21544 break;
33a392fb 21545
d507cf36
PB
21546 case ARM_FLOAT_ABI_HARD:
21547 if (flags & F_SOFT_FLOAT)
21548 as_bad (_("hard-float conflicts with specified fpu"));
21549 break;
21550 }
03b1477f 21551
e74cfd16
PB
21552 /* Using pure-endian doubles (even if soft-float). */
21553 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21554 flags |= F_VFP_FLOAT;
f17c130b 21555
fde78edd 21556#if defined OBJ_ELF
e74cfd16 21557 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21558 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21559 break;
21560
8cb51566 21561 case EF_ARM_EABI_VER4:
3a4a14e9 21562 case EF_ARM_EABI_VER5:
c19d1205 21563 /* No additional flags to set. */
d507cf36
PB
21564 break;
21565
21566 default:
21567 abort ();
21568 }
7cc69913 21569#endif
b99bd4ef
NC
21570 bfd_set_private_flags (stdoutput, flags);
21571
21572 /* We have run out flags in the COFF header to encode the
21573 status of ATPCS support, so instead we create a dummy,
c19d1205 21574 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21575 if (atpcs)
21576 {
21577 asection * sec;
21578
21579 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21580
21581 if (sec != NULL)
21582 {
21583 bfd_set_section_flags
21584 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21585 bfd_set_section_size (stdoutput, sec, 0);
21586 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21587 }
21588 }
7cc69913 21589 }
f17c130b 21590#endif
b99bd4ef
NC
21591
21592 /* Record the CPU type as well. */
2d447fca
JM
21593 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21594 mach = bfd_mach_arm_iWMMXt2;
21595 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21596 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21597 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21598 mach = bfd_mach_arm_XScale;
e74cfd16 21599 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21600 mach = bfd_mach_arm_ep9312;
e74cfd16 21601 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21602 mach = bfd_mach_arm_5TE;
e74cfd16 21603 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21604 {
e74cfd16 21605 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21606 mach = bfd_mach_arm_5T;
21607 else
21608 mach = bfd_mach_arm_5;
21609 }
e74cfd16 21610 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21611 {
e74cfd16 21612 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21613 mach = bfd_mach_arm_4T;
21614 else
21615 mach = bfd_mach_arm_4;
21616 }
e74cfd16 21617 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21618 mach = bfd_mach_arm_3M;
e74cfd16
PB
21619 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21620 mach = bfd_mach_arm_3;
21621 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21622 mach = bfd_mach_arm_2a;
21623 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21624 mach = bfd_mach_arm_2;
21625 else
21626 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21627
21628 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21629}
21630
c19d1205 21631/* Command line processing. */
b99bd4ef 21632
c19d1205
ZW
21633/* md_parse_option
21634 Invocation line includes a switch not recognized by the base assembler.
21635 See if it's a processor-specific option.
b99bd4ef 21636
c19d1205
ZW
21637 This routine is somewhat complicated by the need for backwards
21638 compatibility (since older releases of gcc can't be changed).
21639 The new options try to make the interface as compatible as
21640 possible with GCC.
b99bd4ef 21641
c19d1205 21642 New options (supported) are:
b99bd4ef 21643
c19d1205
ZW
21644 -mcpu=<cpu name> Assemble for selected processor
21645 -march=<architecture name> Assemble for selected architecture
21646 -mfpu=<fpu architecture> Assemble for selected FPU.
21647 -EB/-mbig-endian Big-endian
21648 -EL/-mlittle-endian Little-endian
21649 -k Generate PIC code
21650 -mthumb Start in Thumb mode
21651 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21652
278df34e 21653 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21654
c19d1205 21655 For now we will also provide support for:
b99bd4ef 21656
c19d1205
ZW
21657 -mapcs-32 32-bit Program counter
21658 -mapcs-26 26-bit Program counter
21659 -macps-float Floats passed in FP registers
21660 -mapcs-reentrant Reentrant code
21661 -matpcs
21662 (sometime these will probably be replaced with -mapcs=<list of options>
21663 and -matpcs=<list of options>)
b99bd4ef 21664
c19d1205
ZW
21665 The remaining options are only supported for back-wards compatibility.
21666 Cpu variants, the arm part is optional:
21667 -m[arm]1 Currently not supported.
21668 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21669 -m[arm]3 Arm 3 processor
21670 -m[arm]6[xx], Arm 6 processors
21671 -m[arm]7[xx][t][[d]m] Arm 7 processors
21672 -m[arm]8[10] Arm 8 processors
21673 -m[arm]9[20][tdmi] Arm 9 processors
21674 -mstrongarm[110[0]] StrongARM processors
21675 -mxscale XScale processors
21676 -m[arm]v[2345[t[e]]] Arm architectures
21677 -mall All (except the ARM1)
21678 FP variants:
21679 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21680 -mfpe-old (No float load/store multiples)
21681 -mvfpxd VFP Single precision
21682 -mvfp All VFP
21683 -mno-fpu Disable all floating point instructions
b99bd4ef 21684
c19d1205
ZW
21685 The following CPU names are recognized:
21686 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21687 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21688 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21689 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21690 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21691 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21692 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21693
c19d1205 21694 */
b99bd4ef 21695
c19d1205 21696const char * md_shortopts = "m:k";
b99bd4ef 21697
c19d1205
ZW
21698#ifdef ARM_BI_ENDIAN
21699#define OPTION_EB (OPTION_MD_BASE + 0)
21700#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21701#else
c19d1205
ZW
21702#if TARGET_BYTES_BIG_ENDIAN
21703#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21704#else
c19d1205
ZW
21705#define OPTION_EL (OPTION_MD_BASE + 1)
21706#endif
b99bd4ef 21707#endif
845b51d6 21708#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21709
c19d1205 21710struct option md_longopts[] =
b99bd4ef 21711{
c19d1205
ZW
21712#ifdef OPTION_EB
21713 {"EB", no_argument, NULL, OPTION_EB},
21714#endif
21715#ifdef OPTION_EL
21716 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21717#endif
845b51d6 21718 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21719 {NULL, no_argument, NULL, 0}
21720};
b99bd4ef 21721
c19d1205 21722size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21723
c19d1205 21724struct arm_option_table
b99bd4ef 21725{
c19d1205
ZW
21726 char *option; /* Option name to match. */
21727 char *help; /* Help information. */
21728 int *var; /* Variable to change. */
21729 int value; /* What to change it to. */
21730 char *deprecated; /* If non-null, print this message. */
21731};
b99bd4ef 21732
c19d1205
ZW
21733struct arm_option_table arm_opts[] =
21734{
21735 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21736 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21737 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21738 &support_interwork, 1, NULL},
21739 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21740 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21741 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21742 1, NULL},
21743 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21744 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21745 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21746 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21747 NULL},
b99bd4ef 21748
c19d1205
ZW
21749 /* These are recognized by the assembler, but have no affect on code. */
21750 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21751 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21752
21753 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21754 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21755 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21756 {NULL, NULL, NULL, 0, NULL}
21757};
21758
21759struct arm_legacy_option_table
21760{
21761 char *option; /* Option name to match. */
21762 const arm_feature_set **var; /* Variable to change. */
21763 const arm_feature_set value; /* What to change it to. */
21764 char *deprecated; /* If non-null, print this message. */
21765};
b99bd4ef 21766
e74cfd16
PB
21767const struct arm_legacy_option_table arm_legacy_opts[] =
21768{
c19d1205
ZW
21769 /* DON'T add any new processors to this list -- we want the whole list
21770 to go away... Add them to the processors table instead. */
e74cfd16
PB
21771 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21772 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21773 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21774 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21775 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21776 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21777 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21778 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21779 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21780 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21781 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21782 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21783 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21784 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21785 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21786 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21787 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21788 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21789 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21790 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21791 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21792 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21793 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21794 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21795 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21796 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21797 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21798 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21799 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21800 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21801 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21802 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21803 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21804 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21805 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21806 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21807 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21808 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21809 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21810 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21811 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21812 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21813 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21814 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21815 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21816 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21817 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21818 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21819 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21820 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21821 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21822 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21823 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21824 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21825 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21826 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21827 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21828 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21829 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21830 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21831 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21832 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21833 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21834 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21835 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21836 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21837 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21838 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21839 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
21840 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21841 N_("use -mcpu=strongarm110")},
e74cfd16 21842 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21843 N_("use -mcpu=strongarm1100")},
e74cfd16 21844 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21845 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
21846 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
21847 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
21848 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 21849
c19d1205 21850 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
21851 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21852 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21853 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21854 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21855 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21856 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21857 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21858 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21859 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21860 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21861 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21862 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21863 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21864 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21865 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21866 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21867 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21868 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 21869
c19d1205 21870 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
21871 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
21872 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
21873 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
21874 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 21875 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 21876
e74cfd16 21877 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 21878};
7ed4c4c5 21879
c19d1205 21880struct arm_cpu_option_table
7ed4c4c5 21881{
c19d1205 21882 char *name;
e74cfd16 21883 const arm_feature_set value;
c19d1205
ZW
21884 /* For some CPUs we assume an FPU unless the user explicitly sets
21885 -mfpu=... */
e74cfd16 21886 const arm_feature_set default_fpu;
ee065d83
PB
21887 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21888 case. */
21889 const char *canonical_name;
c19d1205 21890};
7ed4c4c5 21891
c19d1205
ZW
21892/* This list should, at a minimum, contain all the cpu names
21893 recognized by GCC. */
e74cfd16 21894static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 21895{
ee065d83
PB
21896 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
21897 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
21898 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
21899 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21900 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21901 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21902 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21903 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21904 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21905 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21906 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21907 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21908 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21909 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21910 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21911 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21912 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21913 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21914 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21915 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21916 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21917 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21918 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21919 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21920 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21921 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21922 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21923 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21924 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21925 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21926 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21927 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21928 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21929 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21930 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21931 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21932 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21933 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21934 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21935 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
21936 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21937 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21938 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21939 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
21940 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21941 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
21942 /* For V5 or later processors we default to using VFP; but the user
21943 should really set the FPU type explicitly. */
ee065d83
PB
21944 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21945 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21946 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21947 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21948 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21949 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21950 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
21951 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21952 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21953 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
21954 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21955 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21956 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21957 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21958 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21959 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
21960 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21961 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21962 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21963 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
21964 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
21965 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
21966 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
21967 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
21968 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
21969 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
21970 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
21971 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
21972 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
21973 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
21974 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
21975 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
21976 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
b38f9f31 21977 {"cortex-a5", ARM_ARCH_V7A, FPU_NONE, NULL},
e07e6e58 21978 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 21979 | FPU_NEON_EXT_V1),
15290f0a 21980 NULL},
e07e6e58 21981 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 21982 | FPU_NEON_EXT_V1),
5287ad62 21983 NULL},
62b3e311 21984 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
307c948d 21985 {"cortex-r4f", ARM_ARCH_V7R, FPU_ARCH_VFP_V3D16, NULL},
62b3e311 21986 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 21987 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 21988 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 21989 /* ??? XSCALE is really an architecture. */
ee065d83 21990 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21991 /* ??? iwmmxt is not a processor. */
ee065d83 21992 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 21993 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 21994 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21995 /* Maverick */
e07e6e58 21996 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 21997 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 21998};
7ed4c4c5 21999
c19d1205 22000struct arm_arch_option_table
7ed4c4c5 22001{
c19d1205 22002 char *name;
e74cfd16
PB
22003 const arm_feature_set value;
22004 const arm_feature_set default_fpu;
c19d1205 22005};
7ed4c4c5 22006
c19d1205
ZW
22007/* This list should, at a minimum, contain all the architecture names
22008 recognized by GCC. */
e74cfd16 22009static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
22010{
22011 {"all", ARM_ANY, FPU_ARCH_FPA},
22012 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
22013 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
22014 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
22015 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
22016 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
22017 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
22018 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
22019 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
22020 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
22021 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
22022 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
22023 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
22024 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
22025 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
22026 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
22027 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
22028 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
22029 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
22030 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
22031 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
22032 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
22033 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
22034 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
22035 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
22036 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 22037 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 22038 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
22039 /* The official spelling of the ARMv7 profile variants is the dashed form.
22040 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
22041 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22042 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22043 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
22044 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
22045 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
22046 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
9e3c6df6 22047 {"armv7e-m", ARM_ARCH_V7EM, FPU_ARCH_VFP},
c19d1205
ZW
22048 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
22049 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 22050 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 22051 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 22052};
7ed4c4c5 22053
c19d1205 22054/* ISA extensions in the co-processor space. */
e74cfd16 22055struct arm_option_cpu_value_table
c19d1205
ZW
22056{
22057 char *name;
e74cfd16 22058 const arm_feature_set value;
c19d1205 22059};
7ed4c4c5 22060
e74cfd16 22061static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 22062{
e74cfd16
PB
22063 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
22064 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
22065 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 22066 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 22067 {NULL, ARM_ARCH_NONE}
c19d1205 22068};
7ed4c4c5 22069
c19d1205
ZW
22070/* This list should, at a minimum, contain all the fpu names
22071 recognized by GCC. */
e74cfd16 22072static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
22073{
22074 {"softfpa", FPU_NONE},
22075 {"fpe", FPU_ARCH_FPE},
22076 {"fpe2", FPU_ARCH_FPE},
22077 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
22078 {"fpa", FPU_ARCH_FPA},
22079 {"fpa10", FPU_ARCH_FPA},
22080 {"fpa11", FPU_ARCH_FPA},
22081 {"arm7500fe", FPU_ARCH_FPA},
22082 {"softvfp", FPU_ARCH_VFP},
22083 {"softvfp+vfp", FPU_ARCH_VFP_V2},
22084 {"vfp", FPU_ARCH_VFP_V2},
22085 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 22086 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
22087 {"vfp10", FPU_ARCH_VFP_V2},
22088 {"vfp10-r0", FPU_ARCH_VFP_V1},
22089 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
22090 {"vfpv2", FPU_ARCH_VFP_V2},
22091 {"vfpv3", FPU_ARCH_VFP_V3},
62f3b8c8 22092 {"vfpv3-fp16", FPU_ARCH_VFP_V3_FP16},
b1cc4aeb 22093 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
62f3b8c8
PB
22094 {"vfpv3-d16-fp16", FPU_ARCH_VFP_V3D16_FP16},
22095 {"vfpv3xd", FPU_ARCH_VFP_V3xD},
22096 {"vfpv3xd-fp16", FPU_ARCH_VFP_V3xD_FP16},
c19d1205
ZW
22097 {"arm1020t", FPU_ARCH_VFP_V1},
22098 {"arm1020e", FPU_ARCH_VFP_V2},
22099 {"arm1136jfs", FPU_ARCH_VFP_V2},
22100 {"arm1136jf-s", FPU_ARCH_VFP_V2},
22101 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 22102 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 22103 {"neon-fp16", FPU_ARCH_NEON_FP16},
62f3b8c8
PB
22104 {"vfpv4", FPU_ARCH_VFP_V4},
22105 {"vfpv4-d16", FPU_ARCH_VFP_V4D16},
ada65aa3 22106 {"fpv4-sp-d16", FPU_ARCH_VFP_V4_SP_D16},
62f3b8c8 22107 {"neon-vfpv4", FPU_ARCH_NEON_VFP_V4},
e74cfd16
PB
22108 {NULL, ARM_ARCH_NONE}
22109};
22110
22111struct arm_option_value_table
22112{
22113 char *name;
22114 long value;
c19d1205 22115};
7ed4c4c5 22116
e74cfd16 22117static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
22118{
22119 {"hard", ARM_FLOAT_ABI_HARD},
22120 {"softfp", ARM_FLOAT_ABI_SOFTFP},
22121 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 22122 {NULL, 0}
c19d1205 22123};
7ed4c4c5 22124
c19d1205 22125#ifdef OBJ_ELF
3a4a14e9 22126/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 22127static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
22128{
22129 {"gnu", EF_ARM_EABI_UNKNOWN},
22130 {"4", EF_ARM_EABI_VER4},
3a4a14e9 22131 {"5", EF_ARM_EABI_VER5},
e74cfd16 22132 {NULL, 0}
c19d1205
ZW
22133};
22134#endif
7ed4c4c5 22135
c19d1205
ZW
22136struct arm_long_option_table
22137{
22138 char * option; /* Substring to match. */
22139 char * help; /* Help information. */
22140 int (* func) (char * subopt); /* Function to decode sub-option. */
22141 char * deprecated; /* If non-null, print this message. */
22142};
7ed4c4c5 22143
c921be7d 22144static bfd_boolean
e74cfd16 22145arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 22146{
21d799b5
NC
22147 arm_feature_set *ext_set = (arm_feature_set *)
22148 xmalloc (sizeof (arm_feature_set));
e74cfd16
PB
22149
22150 /* Copy the feature set, so that we can modify it. */
22151 *ext_set = **opt_p;
22152 *opt_p = ext_set;
22153
c19d1205 22154 while (str != NULL && *str != 0)
7ed4c4c5 22155 {
e74cfd16 22156 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
22157 char * ext;
22158 int optlen;
7ed4c4c5 22159
c19d1205
ZW
22160 if (*str != '+')
22161 {
22162 as_bad (_("invalid architectural extension"));
c921be7d 22163 return FALSE;
c19d1205 22164 }
7ed4c4c5 22165
c19d1205
ZW
22166 str++;
22167 ext = strchr (str, '+');
7ed4c4c5 22168
c19d1205
ZW
22169 if (ext != NULL)
22170 optlen = ext - str;
22171 else
22172 optlen = strlen (str);
7ed4c4c5 22173
c19d1205
ZW
22174 if (optlen == 0)
22175 {
22176 as_bad (_("missing architectural extension"));
c921be7d 22177 return FALSE;
c19d1205 22178 }
7ed4c4c5 22179
c19d1205
ZW
22180 for (opt = arm_extensions; opt->name != NULL; opt++)
22181 if (strncmp (opt->name, str, optlen) == 0)
22182 {
e74cfd16 22183 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
22184 break;
22185 }
7ed4c4c5 22186
c19d1205
ZW
22187 if (opt->name == NULL)
22188 {
5f4273c7 22189 as_bad (_("unknown architectural extension `%s'"), str);
c921be7d 22190 return FALSE;
c19d1205 22191 }
7ed4c4c5 22192
c19d1205
ZW
22193 str = ext;
22194 };
7ed4c4c5 22195
c921be7d 22196 return TRUE;
c19d1205 22197}
7ed4c4c5 22198
c921be7d 22199static bfd_boolean
c19d1205 22200arm_parse_cpu (char * str)
7ed4c4c5 22201{
e74cfd16 22202 const struct arm_cpu_option_table * opt;
c19d1205
ZW
22203 char * ext = strchr (str, '+');
22204 int optlen;
7ed4c4c5 22205
c19d1205
ZW
22206 if (ext != NULL)
22207 optlen = ext - str;
7ed4c4c5 22208 else
c19d1205 22209 optlen = strlen (str);
7ed4c4c5 22210
c19d1205 22211 if (optlen == 0)
7ed4c4c5 22212 {
c19d1205 22213 as_bad (_("missing cpu name `%s'"), str);
c921be7d 22214 return FALSE;
7ed4c4c5
NC
22215 }
22216
c19d1205
ZW
22217 for (opt = arm_cpus; opt->name != NULL; opt++)
22218 if (strncmp (opt->name, str, optlen) == 0)
22219 {
e74cfd16
PB
22220 mcpu_cpu_opt = &opt->value;
22221 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 22222 if (opt->canonical_name)
5f4273c7 22223 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22224 else
22225 {
22226 int i;
c921be7d 22227
ee065d83
PB
22228 for (i = 0; i < optlen; i++)
22229 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22230 selected_cpu_name[i] = 0;
22231 }
7ed4c4c5 22232
c19d1205
ZW
22233 if (ext != NULL)
22234 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 22235
c921be7d 22236 return TRUE;
c19d1205 22237 }
7ed4c4c5 22238
c19d1205 22239 as_bad (_("unknown cpu `%s'"), str);
c921be7d 22240 return FALSE;
7ed4c4c5
NC
22241}
22242
c921be7d 22243static bfd_boolean
c19d1205 22244arm_parse_arch (char * str)
7ed4c4c5 22245{
e74cfd16 22246 const struct arm_arch_option_table *opt;
c19d1205
ZW
22247 char *ext = strchr (str, '+');
22248 int optlen;
7ed4c4c5 22249
c19d1205
ZW
22250 if (ext != NULL)
22251 optlen = ext - str;
7ed4c4c5 22252 else
c19d1205 22253 optlen = strlen (str);
7ed4c4c5 22254
c19d1205 22255 if (optlen == 0)
7ed4c4c5 22256 {
c19d1205 22257 as_bad (_("missing architecture name `%s'"), str);
c921be7d 22258 return FALSE;
7ed4c4c5
NC
22259 }
22260
c19d1205
ZW
22261 for (opt = arm_archs; opt->name != NULL; opt++)
22262 if (streq (opt->name, str))
22263 {
e74cfd16
PB
22264 march_cpu_opt = &opt->value;
22265 march_fpu_opt = &opt->default_fpu;
5f4273c7 22266 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 22267
c19d1205
ZW
22268 if (ext != NULL)
22269 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 22270
c921be7d 22271 return TRUE;
c19d1205
ZW
22272 }
22273
22274 as_bad (_("unknown architecture `%s'\n"), str);
c921be7d 22275 return FALSE;
7ed4c4c5 22276}
eb043451 22277
c921be7d 22278static bfd_boolean
c19d1205
ZW
22279arm_parse_fpu (char * str)
22280{
e74cfd16 22281 const struct arm_option_cpu_value_table * opt;
b99bd4ef 22282
c19d1205
ZW
22283 for (opt = arm_fpus; opt->name != NULL; opt++)
22284 if (streq (opt->name, str))
22285 {
e74cfd16 22286 mfpu_opt = &opt->value;
c921be7d 22287 return TRUE;
c19d1205 22288 }
b99bd4ef 22289
c19d1205 22290 as_bad (_("unknown floating point format `%s'\n"), str);
c921be7d 22291 return FALSE;
c19d1205
ZW
22292}
22293
c921be7d 22294static bfd_boolean
c19d1205 22295arm_parse_float_abi (char * str)
b99bd4ef 22296{
e74cfd16 22297 const struct arm_option_value_table * opt;
b99bd4ef 22298
c19d1205
ZW
22299 for (opt = arm_float_abis; opt->name != NULL; opt++)
22300 if (streq (opt->name, str))
22301 {
22302 mfloat_abi_opt = opt->value;
c921be7d 22303 return TRUE;
c19d1205 22304 }
cc8a6dd0 22305
c19d1205 22306 as_bad (_("unknown floating point abi `%s'\n"), str);
c921be7d 22307 return FALSE;
c19d1205 22308}
b99bd4ef 22309
c19d1205 22310#ifdef OBJ_ELF
c921be7d 22311static bfd_boolean
c19d1205
ZW
22312arm_parse_eabi (char * str)
22313{
e74cfd16 22314 const struct arm_option_value_table *opt;
cc8a6dd0 22315
c19d1205
ZW
22316 for (opt = arm_eabis; opt->name != NULL; opt++)
22317 if (streq (opt->name, str))
22318 {
22319 meabi_flags = opt->value;
c921be7d 22320 return TRUE;
c19d1205
ZW
22321 }
22322 as_bad (_("unknown EABI `%s'\n"), str);
c921be7d 22323 return FALSE;
c19d1205
ZW
22324}
22325#endif
cc8a6dd0 22326
c921be7d 22327static bfd_boolean
e07e6e58
NC
22328arm_parse_it_mode (char * str)
22329{
c921be7d 22330 bfd_boolean ret = TRUE;
e07e6e58
NC
22331
22332 if (streq ("arm", str))
22333 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
22334 else if (streq ("thumb", str))
22335 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
22336 else if (streq ("always", str))
22337 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
22338 else if (streq ("never", str))
22339 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
22340 else
22341 {
22342 as_bad (_("unknown implicit IT mode `%s', should be "\
22343 "arm, thumb, always, or never."), str);
c921be7d 22344 ret = FALSE;
e07e6e58
NC
22345 }
22346
22347 return ret;
22348}
22349
c19d1205
ZW
22350struct arm_long_option_table arm_long_opts[] =
22351{
22352 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
22353 arm_parse_cpu, NULL},
22354 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
22355 arm_parse_arch, NULL},
22356 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
22357 arm_parse_fpu, NULL},
22358 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
22359 arm_parse_float_abi, NULL},
22360#ifdef OBJ_ELF
7fac0536 22361 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
22362 arm_parse_eabi, NULL},
22363#endif
e07e6e58
NC
22364 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
22365 arm_parse_it_mode, NULL},
c19d1205
ZW
22366 {NULL, NULL, 0, NULL}
22367};
cc8a6dd0 22368
c19d1205
ZW
22369int
22370md_parse_option (int c, char * arg)
22371{
22372 struct arm_option_table *opt;
e74cfd16 22373 const struct arm_legacy_option_table *fopt;
c19d1205 22374 struct arm_long_option_table *lopt;
b99bd4ef 22375
c19d1205 22376 switch (c)
b99bd4ef 22377 {
c19d1205
ZW
22378#ifdef OPTION_EB
22379 case OPTION_EB:
22380 target_big_endian = 1;
22381 break;
22382#endif
cc8a6dd0 22383
c19d1205
ZW
22384#ifdef OPTION_EL
22385 case OPTION_EL:
22386 target_big_endian = 0;
22387 break;
22388#endif
b99bd4ef 22389
845b51d6
PB
22390 case OPTION_FIX_V4BX:
22391 fix_v4bx = TRUE;
22392 break;
22393
c19d1205
ZW
22394 case 'a':
22395 /* Listing option. Just ignore these, we don't support additional
22396 ones. */
22397 return 0;
b99bd4ef 22398
c19d1205
ZW
22399 default:
22400 for (opt = arm_opts; opt->option != NULL; opt++)
22401 {
22402 if (c == opt->option[0]
22403 && ((arg == NULL && opt->option[1] == 0)
22404 || streq (arg, opt->option + 1)))
22405 {
c19d1205 22406 /* If the option is deprecated, tell the user. */
278df34e 22407 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
22408 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22409 arg ? arg : "", _(opt->deprecated));
b99bd4ef 22410
c19d1205
ZW
22411 if (opt->var != NULL)
22412 *opt->var = opt->value;
cc8a6dd0 22413
c19d1205
ZW
22414 return 1;
22415 }
22416 }
b99bd4ef 22417
e74cfd16
PB
22418 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
22419 {
22420 if (c == fopt->option[0]
22421 && ((arg == NULL && fopt->option[1] == 0)
22422 || streq (arg, fopt->option + 1)))
22423 {
e74cfd16 22424 /* If the option is deprecated, tell the user. */
278df34e 22425 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
22426 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
22427 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
22428
22429 if (fopt->var != NULL)
22430 *fopt->var = &fopt->value;
22431
22432 return 1;
22433 }
22434 }
22435
c19d1205
ZW
22436 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22437 {
22438 /* These options are expected to have an argument. */
22439 if (c == lopt->option[0]
22440 && arg != NULL
22441 && strncmp (arg, lopt->option + 1,
22442 strlen (lopt->option + 1)) == 0)
22443 {
c19d1205 22444 /* If the option is deprecated, tell the user. */
278df34e 22445 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
22446 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
22447 _(lopt->deprecated));
b99bd4ef 22448
c19d1205
ZW
22449 /* Call the sup-option parser. */
22450 return lopt->func (arg + strlen (lopt->option) - 1);
22451 }
22452 }
a737bd4d 22453
c19d1205
ZW
22454 return 0;
22455 }
a394c00f 22456
c19d1205
ZW
22457 return 1;
22458}
a394c00f 22459
c19d1205
ZW
22460void
22461md_show_usage (FILE * fp)
a394c00f 22462{
c19d1205
ZW
22463 struct arm_option_table *opt;
22464 struct arm_long_option_table *lopt;
a394c00f 22465
c19d1205 22466 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 22467
c19d1205
ZW
22468 for (opt = arm_opts; opt->option != NULL; opt++)
22469 if (opt->help != NULL)
22470 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 22471
c19d1205
ZW
22472 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
22473 if (lopt->help != NULL)
22474 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 22475
c19d1205
ZW
22476#ifdef OPTION_EB
22477 fprintf (fp, _("\
22478 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
22479#endif
22480
c19d1205
ZW
22481#ifdef OPTION_EL
22482 fprintf (fp, _("\
22483 -EL assemble code for a little-endian cpu\n"));
a737bd4d 22484#endif
845b51d6
PB
22485
22486 fprintf (fp, _("\
22487 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 22488}
ee065d83
PB
22489
22490
22491#ifdef OBJ_ELF
62b3e311
PB
22492typedef struct
22493{
22494 int val;
22495 arm_feature_set flags;
22496} cpu_arch_ver_table;
22497
22498/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
22499 least features first. */
22500static const cpu_arch_ver_table cpu_arch_ver[] =
22501{
22502 {1, ARM_ARCH_V4},
22503 {2, ARM_ARCH_V4T},
22504 {3, ARM_ARCH_V5},
ee3c0378 22505 {3, ARM_ARCH_V5T},
62b3e311
PB
22506 {4, ARM_ARCH_V5TE},
22507 {5, ARM_ARCH_V5TEJ},
22508 {6, ARM_ARCH_V6},
22509 {7, ARM_ARCH_V6Z},
7e806470 22510 {9, ARM_ARCH_V6K},
91e22acd 22511 {11, ARM_ARCH_V6M},
7e806470 22512 {8, ARM_ARCH_V6T2},
62b3e311
PB
22513 {10, ARM_ARCH_V7A},
22514 {10, ARM_ARCH_V7R},
22515 {10, ARM_ARCH_V7M},
22516 {0, ARM_ARCH_NONE}
22517};
22518
ee3c0378
AS
22519/* Set an attribute if it has not already been set by the user. */
22520static void
22521aeabi_set_attribute_int (int tag, int value)
22522{
22523 if (tag < 1
22524 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22525 || !attributes_set_explicitly[tag])
22526 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
22527}
22528
22529static void
22530aeabi_set_attribute_string (int tag, const char *value)
22531{
22532 if (tag < 1
22533 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
22534 || !attributes_set_explicitly[tag])
22535 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
22536}
22537
ee065d83
PB
22538/* Set the public EABI object attributes. */
22539static void
22540aeabi_set_public_attributes (void)
22541{
22542 int arch;
e74cfd16 22543 arm_feature_set flags;
62b3e311
PB
22544 arm_feature_set tmp;
22545 const cpu_arch_ver_table *p;
ee065d83
PB
22546
22547 /* Choose the architecture based on the capabilities of the requested cpu
22548 (if any) and/or the instructions actually used. */
e74cfd16
PB
22549 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22550 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22551 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22552 /*Allow the user to override the reported architecture. */
22553 if (object_arch)
22554 {
22555 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22556 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22557 }
22558
62b3e311
PB
22559 tmp = flags;
22560 arch = 0;
22561 for (p = cpu_arch_ver; p->val; p++)
22562 {
22563 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22564 {
22565 arch = p->val;
22566 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22567 }
22568 }
ee065d83 22569
9e3c6df6
PB
22570 /* The table lookup above finds the last architecture to contribute
22571 a new feature. Unfortunately, Tag13 is a subset of the union of
22572 v6T2 and v7-M, so it is never seen as contributing a new feature.
22573 We can not search for the last entry which is entirely used,
22574 because if no CPU is specified we build up only those flags
22575 actually used. Perhaps we should separate out the specified
22576 and implicit cases. Avoid taking this path for -march=all by
22577 checking for contradictory v7-A / v7-M features. */
22578 if (arch == 10
22579 && !ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a)
22580 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v7m)
22581 && ARM_CPU_HAS_FEATURE (flags, arm_ext_v6_dsp))
22582 arch = 13;
22583
ee065d83
PB
22584 /* Tag_CPU_name. */
22585 if (selected_cpu_name[0])
22586 {
22587 char *p;
22588
22589 p = selected_cpu_name;
5f4273c7 22590 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
22591 {
22592 int i;
5f4273c7 22593
ee065d83
PB
22594 p += 4;
22595 for (i = 0; p[i]; i++)
22596 p[i] = TOUPPER (p[i]);
22597 }
ee3c0378 22598 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83 22599 }
62f3b8c8 22600
ee065d83 22601 /* Tag_CPU_arch. */
ee3c0378 22602 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62f3b8c8 22603
62b3e311
PB
22604 /* Tag_CPU_arch_profile. */
22605 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22606 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22607 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22608 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22609 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22610 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
62f3b8c8 22611
ee065d83 22612 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22613 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22614 || arch == 0)
22615 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
62f3b8c8 22616
ee065d83 22617 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22618 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22619 || arch == 0)
22620 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22621 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
62f3b8c8 22622
ee065d83 22623 /* Tag_VFP_arch. */
62f3b8c8
PB
22624 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_fma))
22625 aeabi_set_attribute_int (Tag_VFP_arch,
22626 ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32)
22627 ? 5 : 6);
22628 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
ee3c0378 22629 aeabi_set_attribute_int (Tag_VFP_arch, 3);
ada65aa3 22630 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3xd))
ee3c0378
AS
22631 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22632 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22633 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22634 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22635 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22636 aeabi_set_attribute_int (Tag_VFP_arch, 1);
62f3b8c8 22637
ee065d83 22638 /* Tag_WMMX_arch. */
ee3c0378
AS
22639 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22640 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22641 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22642 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
62f3b8c8 22643
ee3c0378 22644 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22645 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
62f3b8c8
PB
22646 aeabi_set_attribute_int
22647 (Tag_Advanced_SIMD_arch, (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_fma)
22648 ? 2 : 1));
22649
ee3c0378 22650 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
62f3b8c8 22651 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_fp16))
ee3c0378 22652 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
22653}
22654
104d59d1 22655/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22656void
22657arm_md_end (void)
22658{
ee065d83
PB
22659 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22660 return;
22661
22662 aeabi_set_public_attributes ();
ee065d83 22663}
8463be01 22664#endif /* OBJ_ELF */
ee065d83
PB
22665
22666
22667/* Parse a .cpu directive. */
22668
22669static void
22670s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22671{
e74cfd16 22672 const struct arm_cpu_option_table *opt;
ee065d83
PB
22673 char *name;
22674 char saved_char;
22675
22676 name = input_line_pointer;
5f4273c7 22677 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22678 input_line_pointer++;
22679 saved_char = *input_line_pointer;
22680 *input_line_pointer = 0;
22681
22682 /* Skip the first "all" entry. */
22683 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22684 if (streq (opt->name, name))
22685 {
e74cfd16
PB
22686 mcpu_cpu_opt = &opt->value;
22687 selected_cpu = opt->value;
ee065d83 22688 if (opt->canonical_name)
5f4273c7 22689 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22690 else
22691 {
22692 int i;
22693 for (i = 0; opt->name[i]; i++)
22694 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22695 selected_cpu_name[i] = 0;
22696 }
e74cfd16 22697 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22698 *input_line_pointer = saved_char;
22699 demand_empty_rest_of_line ();
22700 return;
22701 }
22702 as_bad (_("unknown cpu `%s'"), name);
22703 *input_line_pointer = saved_char;
22704 ignore_rest_of_line ();
22705}
22706
22707
22708/* Parse a .arch directive. */
22709
22710static void
22711s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22712{
e74cfd16 22713 const struct arm_arch_option_table *opt;
ee065d83
PB
22714 char saved_char;
22715 char *name;
22716
22717 name = input_line_pointer;
5f4273c7 22718 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22719 input_line_pointer++;
22720 saved_char = *input_line_pointer;
22721 *input_line_pointer = 0;
22722
22723 /* Skip the first "all" entry. */
22724 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22725 if (streq (opt->name, name))
22726 {
e74cfd16
PB
22727 mcpu_cpu_opt = &opt->value;
22728 selected_cpu = opt->value;
5f4273c7 22729 strcpy (selected_cpu_name, opt->name);
e74cfd16 22730 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22731 *input_line_pointer = saved_char;
22732 demand_empty_rest_of_line ();
22733 return;
22734 }
22735
22736 as_bad (_("unknown architecture `%s'\n"), name);
22737 *input_line_pointer = saved_char;
22738 ignore_rest_of_line ();
22739}
22740
22741
7a1d4c38
PB
22742/* Parse a .object_arch directive. */
22743
22744static void
22745s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22746{
22747 const struct arm_arch_option_table *opt;
22748 char saved_char;
22749 char *name;
22750
22751 name = input_line_pointer;
5f4273c7 22752 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22753 input_line_pointer++;
22754 saved_char = *input_line_pointer;
22755 *input_line_pointer = 0;
22756
22757 /* Skip the first "all" entry. */
22758 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22759 if (streq (opt->name, name))
22760 {
22761 object_arch = &opt->value;
22762 *input_line_pointer = saved_char;
22763 demand_empty_rest_of_line ();
22764 return;
22765 }
22766
22767 as_bad (_("unknown architecture `%s'\n"), name);
22768 *input_line_pointer = saved_char;
22769 ignore_rest_of_line ();
22770}
22771
ee065d83
PB
22772/* Parse a .fpu directive. */
22773
22774static void
22775s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22776{
e74cfd16 22777 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
22778 char saved_char;
22779 char *name;
22780
22781 name = input_line_pointer;
5f4273c7 22782 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22783 input_line_pointer++;
22784 saved_char = *input_line_pointer;
22785 *input_line_pointer = 0;
5f4273c7 22786
ee065d83
PB
22787 for (opt = arm_fpus; opt->name != NULL; opt++)
22788 if (streq (opt->name, name))
22789 {
e74cfd16
PB
22790 mfpu_opt = &opt->value;
22791 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22792 *input_line_pointer = saved_char;
22793 demand_empty_rest_of_line ();
22794 return;
22795 }
22796
22797 as_bad (_("unknown floating point format `%s'\n"), name);
22798 *input_line_pointer = saved_char;
22799 ignore_rest_of_line ();
22800}
ee065d83 22801
794ba86a 22802/* Copy symbol information. */
f31fef98 22803
794ba86a
DJ
22804void
22805arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22806{
22807 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22808}
e04befd0 22809
f31fef98 22810#ifdef OBJ_ELF
e04befd0
AS
22811/* Given a symbolic attribute NAME, return the proper integer value.
22812 Returns -1 if the attribute is not known. */
f31fef98 22813
e04befd0
AS
22814int
22815arm_convert_symbolic_attribute (const char *name)
22816{
f31fef98
NC
22817 static const struct
22818 {
22819 const char * name;
22820 const int tag;
22821 }
22822 attribute_table[] =
22823 {
22824 /* When you modify this table you should
22825 also modify the list in doc/c-arm.texi. */
e04befd0 22826#define T(tag) {#tag, tag}
f31fef98
NC
22827 T (Tag_CPU_raw_name),
22828 T (Tag_CPU_name),
22829 T (Tag_CPU_arch),
22830 T (Tag_CPU_arch_profile),
22831 T (Tag_ARM_ISA_use),
22832 T (Tag_THUMB_ISA_use),
22833 T (Tag_VFP_arch),
22834 T (Tag_WMMX_arch),
22835 T (Tag_Advanced_SIMD_arch),
22836 T (Tag_PCS_config),
22837 T (Tag_ABI_PCS_R9_use),
22838 T (Tag_ABI_PCS_RW_data),
22839 T (Tag_ABI_PCS_RO_data),
22840 T (Tag_ABI_PCS_GOT_use),
22841 T (Tag_ABI_PCS_wchar_t),
22842 T (Tag_ABI_FP_rounding),
22843 T (Tag_ABI_FP_denormal),
22844 T (Tag_ABI_FP_exceptions),
22845 T (Tag_ABI_FP_user_exceptions),
22846 T (Tag_ABI_FP_number_model),
22847 T (Tag_ABI_align8_needed),
22848 T (Tag_ABI_align8_preserved),
22849 T (Tag_ABI_enum_size),
22850 T (Tag_ABI_HardFP_use),
22851 T (Tag_ABI_VFP_args),
22852 T (Tag_ABI_WMMX_args),
22853 T (Tag_ABI_optimization_goals),
22854 T (Tag_ABI_FP_optimization_goals),
22855 T (Tag_compatibility),
22856 T (Tag_CPU_unaligned_access),
22857 T (Tag_VFP_HP_extension),
22858 T (Tag_ABI_FP_16bit_format),
22859 T (Tag_nodefaults),
22860 T (Tag_also_compatible_with),
22861 T (Tag_conformance),
22862 T (Tag_T2EE_use),
22863 T (Tag_Virtualization_use),
22864 T (Tag_MPextension_use)
e04befd0 22865#undef T
f31fef98 22866 };
e04befd0
AS
22867 unsigned int i;
22868
22869 if (name == NULL)
22870 return -1;
22871
f31fef98 22872 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
c921be7d 22873 if (streq (name, attribute_table[i].name))
e04befd0
AS
22874 return attribute_table[i].tag;
22875
22876 return -1;
22877}
267bf995
RR
22878
22879
22880/* Apply sym value for relocations only in the case that
22881 they are for local symbols and you have the respective
22882 architectural feature for blx and simple switches. */
22883int
22884arm_apply_sym_value (struct fix * fixP)
22885{
22886 if (fixP->fx_addsy
22887 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22888 && !S_IS_EXTERNAL (fixP->fx_addsy))
22889 {
22890 switch (fixP->fx_r_type)
22891 {
22892 case BFD_RELOC_ARM_PCREL_BLX:
22893 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22894 if (ARM_IS_FUNC (fixP->fx_addsy))
22895 return 1;
22896 break;
22897
22898 case BFD_RELOC_ARM_PCREL_CALL:
22899 case BFD_RELOC_THUMB_PCREL_BLX:
22900 if (THUMB_IS_FUNC (fixP->fx_addsy))
22901 return 1;
22902 break;
22903
22904 default:
22905 break;
22906 }
22907
22908 }
22909 return 0;
22910}
f31fef98 22911#endif /* OBJ_ELF */