]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gas/config/tc-arm.c
* cli/cli-cmds.c (init_cli_cmds): Add "inf" alias for "info" command.
[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/* Bit N indicates that an R_ARM_NONE relocation has been output for
81 __aeabi_unwind_cpp_prN already if set. This enables dependencies to be
82 emitted only once per section, to save unnecessary bloat. */
83static unsigned int marked_pr_dependency = 0;
84
85#endif /* OBJ_ELF */
86
4962c51a
MS
87/* Results from operand parsing worker functions. */
88
89typedef enum
90{
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94} parse_operand_result;
95
33a392fb
PB
96enum arm_float_abi
97{
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
101};
102
c19d1205 103/* Types of processor to assemble for. */
b99bd4ef
NC
104#ifndef CPU_DEFAULT
105#if defined __XSCALE__
e74cfd16 106#define CPU_DEFAULT ARM_ARCH_XSCALE
b99bd4ef
NC
107#else
108#if defined __thumb__
e74cfd16 109#define CPU_DEFAULT ARM_ARCH_V5T
b99bd4ef
NC
110#endif
111#endif
112#endif
113
114#ifndef FPU_DEFAULT
c820d418
MM
115# ifdef TE_LINUX
116# define FPU_DEFAULT FPU_ARCH_FPA
117# elif defined (TE_NetBSD)
118# ifdef OBJ_ELF
119# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, but VFP order. */
120# else
121 /* Legacy a.out format. */
122# define FPU_DEFAULT FPU_ARCH_FPA /* Soft-float, but FPA order. */
123# endif
4e7fd91e
PB
124# elif defined (TE_VXWORKS)
125# define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
c820d418
MM
126# else
127 /* For backwards compatibility, default to FPA. */
128# define FPU_DEFAULT FPU_ARCH_FPA
129# endif
130#endif /* ifndef FPU_DEFAULT */
b99bd4ef 131
c19d1205 132#define streq(a, b) (strcmp (a, b) == 0)
b99bd4ef 133
e74cfd16
PB
134static arm_feature_set cpu_variant;
135static arm_feature_set arm_arch_used;
136static arm_feature_set thumb_arch_used;
b99bd4ef 137
b99bd4ef 138/* Flags stored in private area of BFD structure. */
c19d1205
ZW
139static int uses_apcs_26 = FALSE;
140static int atpcs = FALSE;
b34976b6
AM
141static int support_interwork = FALSE;
142static int uses_apcs_float = FALSE;
c19d1205 143static int pic_code = FALSE;
845b51d6 144static int fix_v4bx = FALSE;
278df34e
NS
145/* Warn on using deprecated features. */
146static int warn_on_deprecated = TRUE;
147
03b1477f
RE
148
149/* Variables that we set while parsing command-line options. Once all
150 options have been read we re-process these values to set the real
151 assembly flags. */
e74cfd16
PB
152static const arm_feature_set *legacy_cpu = NULL;
153static const arm_feature_set *legacy_fpu = NULL;
154
155static const arm_feature_set *mcpu_cpu_opt = NULL;
156static const arm_feature_set *mcpu_fpu_opt = NULL;
157static const arm_feature_set *march_cpu_opt = NULL;
158static const arm_feature_set *march_fpu_opt = NULL;
159static const arm_feature_set *mfpu_opt = NULL;
7a1d4c38 160static const arm_feature_set *object_arch = NULL;
e74cfd16
PB
161
162/* Constants for known architecture features. */
163static const arm_feature_set fpu_default = FPU_DEFAULT;
164static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
5287ad62
JB
166static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
e74cfd16
PB
168static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
172
173#ifdef CPU_DEFAULT
174static const arm_feature_set cpu_default = CPU_DEFAULT;
175#endif
176
177static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
62b3e311 195static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
7e806470
PB
196static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
62b3e311
PB
198static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
7e806470
PB
202static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
e74cfd16
PB
204
205static const arm_feature_set arm_arch_any = ARM_ANY;
206static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
209
2d447fca
JM
210static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
e74cfd16
PB
212static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
5287ad62 224static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
b1cc4aeb
PB
225static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
5287ad62
JB
227static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
8e79c3df 230static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
e74cfd16 231
33a392fb 232static int mfloat_abi_opt = -1;
e74cfd16
PB
233/* Record user cpu selection for object attributes. */
234static arm_feature_set selected_cpu = ARM_ARCH_NONE;
ee065d83
PB
235/* Must be long enough to hold any of the names in arm_cpus. */
236static char selected_cpu_name[16];
7cc69913 237#ifdef OBJ_ELF
deeaaff8
DJ
238# ifdef EABI_DEFAULT
239static int meabi_flags = EABI_DEFAULT;
240# else
d507cf36 241static int meabi_flags = EF_ARM_EABI_UNKNOWN;
deeaaff8 242# endif
e1da3f5b 243
ee3c0378
AS
244static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
245
e1da3f5b 246bfd_boolean
5f4273c7 247arm_is_eabi (void)
e1da3f5b
PB
248{
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
250}
7cc69913 251#endif
b99bd4ef 252
b99bd4ef 253#ifdef OBJ_ELF
c19d1205 254/* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
b99bd4ef
NC
255symbolS * GOT_symbol;
256#endif
257
b99bd4ef
NC
258/* 0: assemble for ARM,
259 1: assemble for Thumb,
260 2: assemble for Thumb even though target CPU does not support thumb
261 instructions. */
262static int thumb_mode = 0;
8dc2430f
NC
263/* A value distinct from the possible values for thumb_mode that we
264 can use to record whether thumb_mode has been copied into the
265 tc_frag_data field of a frag. */
266#define MODE_RECORDED (1 << 4)
b99bd4ef 267
e07e6e58
NC
268/* Specifies the intrinsic IT insn behavior mode. */
269enum implicit_it_mode
270{
271 IMPLICIT_IT_MODE_NEVER = 0x00,
272 IMPLICIT_IT_MODE_ARM = 0x01,
273 IMPLICIT_IT_MODE_THUMB = 0x02,
274 IMPLICIT_IT_MODE_ALWAYS = (IMPLICIT_IT_MODE_ARM | IMPLICIT_IT_MODE_THUMB)
275};
276static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
277
c19d1205
ZW
278/* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
280
281 - Immediate operands do not require a # prefix.
282 - Conditional affixes always appear at the end of the
283 instruction. (For backward compatibility, those instructions
284 that formerly had them in the middle, continue to accept them
285 there.)
286 - The IT instruction may appear, and if it does is validated
287 against subsequent conditional affixes. It does not generate
288 machine code.
289
290 Important differences from the old Thumb mode:
291
292 - Immediate operands do not require a # prefix.
293 - Most of the V6T2 instructions are only available in unified mode.
294 - The .N and .W suffixes are recognized and honored (it is an error
295 if they cannot be honored).
296 - All instructions set the flags if and only if they have an 's' affix.
297 - Conditional affixes may be used. They are validated against
298 preceding IT instructions. Unlike ARM mode, you cannot use a
299 conditional affix except in the scope of an IT instruction. */
300
301static bfd_boolean unified_syntax = FALSE;
b99bd4ef 302
5287ad62
JB
303enum neon_el_type
304{
dcbf9037 305 NT_invtype,
5287ad62
JB
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
dcbf9037 311 NT_unsigned
5287ad62
JB
312};
313
314struct neon_type_el
315{
316 enum neon_el_type type;
317 unsigned size;
318};
319
320#define NEON_MAX_TYPE_ELS 4
321
322struct neon_type
323{
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
326};
327
e07e6e58
NC
328enum it_instruction_type
329{
330 OUTSIDE_IT_INSN,
331 INSIDE_IT_INSN,
332 INSIDE_IT_LAST_INSN,
333 IF_INSIDE_IT_LAST_INSN, /* Either outside or inside;
334 if inside, should be the last one. */
335 NEUTRAL_IT_INSN, /* This could be either inside or outside,
336 i.e. BKPT and NOP. */
337 IT_INSN /* The IT insn has been parsed. */
338};
339
b99bd4ef
NC
340struct arm_it
341{
c19d1205 342 const char * error;
b99bd4ef 343 unsigned long instruction;
c19d1205
ZW
344 int size;
345 int size_req;
346 int cond;
037e8744
JB
347 /* "uncond_value" is set to the value in place of the conditional field in
348 unconditional versions of the instruction, or -1 if nothing is
349 appropriate. */
350 int uncond_value;
5287ad62 351 struct neon_type vectype;
0110f2b8
PB
352 /* Set to the opcode if the instruction needs relaxation.
353 Zero if the instruction is not relaxed. */
354 unsigned long relax;
b99bd4ef
NC
355 struct
356 {
357 bfd_reloc_code_real_type type;
c19d1205
ZW
358 expressionS exp;
359 int pc_rel;
b99bd4ef 360 } reloc;
b99bd4ef 361
e07e6e58
NC
362 enum it_instruction_type it_insn_type;
363
c19d1205
ZW
364 struct
365 {
366 unsigned reg;
ca3f61f7 367 signed int imm;
dcbf9037 368 struct neon_type_el vectype;
ca3f61f7
NC
369 unsigned present : 1; /* Operand present. */
370 unsigned isreg : 1; /* Operand was a register. */
371 unsigned immisreg : 1; /* .imm field is a second register. */
5287ad62
JB
372 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
373 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
c96612cc 374 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
5287ad62
JB
375 /* Note: we abuse "regisimm" to mean "is Neon register" in VMOV
376 instructions. This allows us to disambiguate ARM <-> vector insns. */
377 unsigned regisimm : 1; /* 64-bit immediate, reg forms high 32 bits. */
037e8744 378 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
5287ad62 379 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
037e8744 380 unsigned issingle : 1; /* Operand is VFP single-precision register. */
ca3f61f7
NC
381 unsigned hasreloc : 1; /* Operand has relocation suffix. */
382 unsigned writeback : 1; /* Operand has trailing ! */
383 unsigned preind : 1; /* Preindexed address. */
384 unsigned postind : 1; /* Postindexed address. */
385 unsigned negative : 1; /* Index register was negated. */
386 unsigned shifted : 1; /* Shift applied to operation. */
387 unsigned shift_kind : 3; /* Shift operation (enum shift_kind). */
c19d1205 388 } operands[6];
b99bd4ef
NC
389};
390
c19d1205 391static struct arm_it inst;
b99bd4ef
NC
392
393#define NUM_FLOAT_VALS 8
394
05d2d07e 395const char * fp_const[] =
b99bd4ef
NC
396{
397 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
398};
399
c19d1205 400/* Number of littlenums required to hold an extended precision number. */
b99bd4ef
NC
401#define MAX_LITTLENUMS 6
402
403LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
404
405#define FAIL (-1)
406#define SUCCESS (0)
407
408#define SUFF_S 1
409#define SUFF_D 2
410#define SUFF_E 3
411#define SUFF_P 4
412
c19d1205
ZW
413#define CP_T_X 0x00008000
414#define CP_T_Y 0x00400000
b99bd4ef 415
c19d1205
ZW
416#define CONDS_BIT 0x00100000
417#define LOAD_BIT 0x00100000
b99bd4ef
NC
418
419#define DOUBLE_LOAD_FLAG 0x00000001
420
421struct asm_cond
422{
c19d1205 423 const char * template;
b99bd4ef
NC
424 unsigned long value;
425};
426
c19d1205 427#define COND_ALWAYS 0xE
b99bd4ef 428
b99bd4ef
NC
429struct asm_psr
430{
b34976b6 431 const char *template;
b99bd4ef
NC
432 unsigned long field;
433};
434
62b3e311
PB
435struct asm_barrier_opt
436{
437 const char *template;
438 unsigned long value;
439};
440
2d2255b5 441/* The bit that distinguishes CPSR and SPSR. */
b99bd4ef
NC
442#define SPSR_BIT (1 << 22)
443
c19d1205
ZW
444/* The individual PSR flag bits. */
445#define PSR_c (1 << 16)
446#define PSR_x (1 << 17)
447#define PSR_s (1 << 18)
448#define PSR_f (1 << 19)
b99bd4ef 449
c19d1205 450struct reloc_entry
bfae80f2 451{
c19d1205
ZW
452 char *name;
453 bfd_reloc_code_real_type reloc;
bfae80f2
RE
454};
455
5287ad62 456enum vfp_reg_pos
bfae80f2 457{
5287ad62
JB
458 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
459 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
bfae80f2
RE
460};
461
462enum vfp_ldstm_type
463{
464 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
465};
466
dcbf9037
JB
467/* Bits for DEFINED field in neon_typed_alias. */
468#define NTA_HASTYPE 1
469#define NTA_HASINDEX 2
470
471struct neon_typed_alias
472{
473 unsigned char defined;
474 unsigned char index;
475 struct neon_type_el eltype;
476};
477
c19d1205
ZW
478/* ARM register categories. This includes coprocessor numbers and various
479 architecture extensions' registers. */
480enum arm_reg_type
bfae80f2 481{
c19d1205
ZW
482 REG_TYPE_RN,
483 REG_TYPE_CP,
484 REG_TYPE_CN,
485 REG_TYPE_FN,
486 REG_TYPE_VFS,
487 REG_TYPE_VFD,
5287ad62 488 REG_TYPE_NQ,
037e8744 489 REG_TYPE_VFSD,
5287ad62 490 REG_TYPE_NDQ,
037e8744 491 REG_TYPE_NSDQ,
c19d1205
ZW
492 REG_TYPE_VFC,
493 REG_TYPE_MVF,
494 REG_TYPE_MVD,
495 REG_TYPE_MVFX,
496 REG_TYPE_MVDX,
497 REG_TYPE_MVAX,
498 REG_TYPE_DSPSC,
499 REG_TYPE_MMXWR,
500 REG_TYPE_MMXWC,
501 REG_TYPE_MMXWCG,
502 REG_TYPE_XSCALE,
bfae80f2
RE
503};
504
dcbf9037
JB
505/* Structure for a hash table entry for a register.
506 If TYPE is REG_TYPE_VFD or REG_TYPE_NQ, the NEON field can point to extra
507 information which states whether a vector type or index is specified (for a
508 register alias created with .dn or .qn). Otherwise NEON should be NULL. */
6c43fab6
RE
509struct reg_entry
510{
dcbf9037
JB
511 const char *name;
512 unsigned char number;
513 unsigned char type;
514 unsigned char builtin;
515 struct neon_typed_alias *neon;
6c43fab6
RE
516};
517
c19d1205
ZW
518/* Diagnostics used when we don't get a register of the expected type. */
519const char *const reg_expected_msgs[] =
520{
521 N_("ARM register expected"),
522 N_("bad or missing co-processor number"),
523 N_("co-processor register expected"),
524 N_("FPA register expected"),
525 N_("VFP single precision register expected"),
5287ad62
JB
526 N_("VFP/Neon double precision register expected"),
527 N_("Neon quad precision register expected"),
037e8744 528 N_("VFP single or double precision register expected"),
5287ad62 529 N_("Neon double or quad precision register expected"),
037e8744 530 N_("VFP single, double or Neon quad precision register expected"),
c19d1205
ZW
531 N_("VFP system register expected"),
532 N_("Maverick MVF register expected"),
533 N_("Maverick MVD register expected"),
534 N_("Maverick MVFX register expected"),
535 N_("Maverick MVDX register expected"),
536 N_("Maverick MVAX register expected"),
537 N_("Maverick DSPSC register expected"),
538 N_("iWMMXt data register expected"),
539 N_("iWMMXt control register expected"),
540 N_("iWMMXt scalar register expected"),
541 N_("XScale accumulator register expected"),
6c43fab6
RE
542};
543
c19d1205
ZW
544/* Some well known registers that we refer to directly elsewhere. */
545#define REG_SP 13
546#define REG_LR 14
547#define REG_PC 15
404ff6b5 548
b99bd4ef
NC
549/* ARM instructions take 4bytes in the object file, Thumb instructions
550 take 2: */
c19d1205 551#define INSN_SIZE 4
b99bd4ef
NC
552
553struct asm_opcode
554{
555 /* Basic string to match. */
c19d1205
ZW
556 const char *template;
557
558 /* Parameters to instruction. */
559 unsigned char operands[8];
560
561 /* Conditional tag - see opcode_lookup. */
562 unsigned int tag : 4;
b99bd4ef
NC
563
564 /* Basic instruction code. */
c19d1205 565 unsigned int avalue : 28;
b99bd4ef 566
c19d1205
ZW
567 /* Thumb-format instruction code. */
568 unsigned int tvalue;
b99bd4ef 569
90e4755a 570 /* Which architecture variant provides this instruction. */
e74cfd16
PB
571 const arm_feature_set *avariant;
572 const arm_feature_set *tvariant;
c19d1205
ZW
573
574 /* Function to call to encode instruction in ARM format. */
575 void (* aencode) (void);
b99bd4ef 576
c19d1205
ZW
577 /* Function to call to encode instruction in Thumb format. */
578 void (* tencode) (void);
b99bd4ef
NC
579};
580
a737bd4d
NC
581/* Defines for various bits that we will want to toggle. */
582#define INST_IMMEDIATE 0x02000000
583#define OFFSET_REG 0x02000000
c19d1205 584#define HWOFFSET_IMM 0x00400000
a737bd4d
NC
585#define SHIFT_BY_REG 0x00000010
586#define PRE_INDEX 0x01000000
587#define INDEX_UP 0x00800000
588#define WRITE_BACK 0x00200000
589#define LDM_TYPE_2_OR_3 0x00400000
a028a6f5 590#define CPSI_MMOD 0x00020000
90e4755a 591
a737bd4d
NC
592#define LITERAL_MASK 0xf000f000
593#define OPCODE_MASK 0xfe1fffff
594#define V4_STR_BIT 0x00000020
90e4755a 595
efd81785
PB
596#define T2_SUBS_PC_LR 0xf3de8f00
597
a737bd4d 598#define DATA_OP_SHIFT 21
90e4755a 599
ef8d22e6
PB
600#define T2_OPCODE_MASK 0xfe1fffff
601#define T2_DATA_OP_SHIFT 21
602
a737bd4d
NC
603/* Codes to distinguish the arithmetic instructions. */
604#define OPCODE_AND 0
605#define OPCODE_EOR 1
606#define OPCODE_SUB 2
607#define OPCODE_RSB 3
608#define OPCODE_ADD 4
609#define OPCODE_ADC 5
610#define OPCODE_SBC 6
611#define OPCODE_RSC 7
612#define OPCODE_TST 8
613#define OPCODE_TEQ 9
614#define OPCODE_CMP 10
615#define OPCODE_CMN 11
616#define OPCODE_ORR 12
617#define OPCODE_MOV 13
618#define OPCODE_BIC 14
619#define OPCODE_MVN 15
90e4755a 620
ef8d22e6
PB
621#define T2_OPCODE_AND 0
622#define T2_OPCODE_BIC 1
623#define T2_OPCODE_ORR 2
624#define T2_OPCODE_ORN 3
625#define T2_OPCODE_EOR 4
626#define T2_OPCODE_ADD 8
627#define T2_OPCODE_ADC 10
628#define T2_OPCODE_SBC 11
629#define T2_OPCODE_SUB 13
630#define T2_OPCODE_RSB 14
631
a737bd4d
NC
632#define T_OPCODE_MUL 0x4340
633#define T_OPCODE_TST 0x4200
634#define T_OPCODE_CMN 0x42c0
635#define T_OPCODE_NEG 0x4240
636#define T_OPCODE_MVN 0x43c0
90e4755a 637
a737bd4d
NC
638#define T_OPCODE_ADD_R3 0x1800
639#define T_OPCODE_SUB_R3 0x1a00
640#define T_OPCODE_ADD_HI 0x4400
641#define T_OPCODE_ADD_ST 0xb000
642#define T_OPCODE_SUB_ST 0xb080
643#define T_OPCODE_ADD_SP 0xa800
644#define T_OPCODE_ADD_PC 0xa000
645#define T_OPCODE_ADD_I8 0x3000
646#define T_OPCODE_SUB_I8 0x3800
647#define T_OPCODE_ADD_I3 0x1c00
648#define T_OPCODE_SUB_I3 0x1e00
b99bd4ef 649
a737bd4d
NC
650#define T_OPCODE_ASR_R 0x4100
651#define T_OPCODE_LSL_R 0x4080
c19d1205
ZW
652#define T_OPCODE_LSR_R 0x40c0
653#define T_OPCODE_ROR_R 0x41c0
a737bd4d
NC
654#define T_OPCODE_ASR_I 0x1000
655#define T_OPCODE_LSL_I 0x0000
656#define T_OPCODE_LSR_I 0x0800
b99bd4ef 657
a737bd4d
NC
658#define T_OPCODE_MOV_I8 0x2000
659#define T_OPCODE_CMP_I8 0x2800
660#define T_OPCODE_CMP_LR 0x4280
661#define T_OPCODE_MOV_HR 0x4600
662#define T_OPCODE_CMP_HR 0x4500
b99bd4ef 663
a737bd4d
NC
664#define T_OPCODE_LDR_PC 0x4800
665#define T_OPCODE_LDR_SP 0x9800
666#define T_OPCODE_STR_SP 0x9000
667#define T_OPCODE_LDR_IW 0x6800
668#define T_OPCODE_STR_IW 0x6000
669#define T_OPCODE_LDR_IH 0x8800
670#define T_OPCODE_STR_IH 0x8000
671#define T_OPCODE_LDR_IB 0x7800
672#define T_OPCODE_STR_IB 0x7000
673#define T_OPCODE_LDR_RW 0x5800
674#define T_OPCODE_STR_RW 0x5000
675#define T_OPCODE_LDR_RH 0x5a00
676#define T_OPCODE_STR_RH 0x5200
677#define T_OPCODE_LDR_RB 0x5c00
678#define T_OPCODE_STR_RB 0x5400
c9b604bd 679
a737bd4d
NC
680#define T_OPCODE_PUSH 0xb400
681#define T_OPCODE_POP 0xbc00
b99bd4ef 682
2fc8bdac 683#define T_OPCODE_BRANCH 0xe000
b99bd4ef 684
a737bd4d 685#define THUMB_SIZE 2 /* Size of thumb instruction. */
a737bd4d 686#define THUMB_PP_PC_LR 0x0100
c19d1205 687#define THUMB_LOAD_BIT 0x0800
53365c0d 688#define THUMB2_LOAD_BIT 0x00100000
c19d1205
ZW
689
690#define BAD_ARGS _("bad arguments to instruction")
fdfde340 691#define BAD_SP _("r13 not allowed here")
c19d1205
ZW
692#define BAD_PC _("r15 not allowed here")
693#define BAD_COND _("instruction cannot be conditional")
694#define BAD_OVERLAP _("registers may not be the same")
695#define BAD_HIREG _("lo register required")
696#define BAD_THUMB32 _("instruction not supported in Thumb16 mode")
01cfc07f 697#define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
dfa9f0d5
PB
698#define BAD_BRANCH _("branch must be last instruction in IT block")
699#define BAD_NOT_IT _("instruction not allowed in IT block")
037e8744 700#define BAD_FPU _("selected FPU does not support instruction")
e07e6e58
NC
701#define BAD_OUT_IT _("thumb conditional instruction should be in IT block")
702#define BAD_IT_COND _("incorrect condition in IT block")
703#define BAD_IT_IT _("IT falling in the range of a previous IT block")
921e5f0a 704#define MISSING_FNSTART _("missing .fnstart before unwinding directive")
c19d1205
ZW
705
706static struct hash_control *arm_ops_hsh;
707static struct hash_control *arm_cond_hsh;
708static struct hash_control *arm_shift_hsh;
709static struct hash_control *arm_psr_hsh;
62b3e311 710static struct hash_control *arm_v7m_psr_hsh;
c19d1205
ZW
711static struct hash_control *arm_reg_hsh;
712static struct hash_control *arm_reloc_hsh;
62b3e311 713static struct hash_control *arm_barrier_opt_hsh;
b99bd4ef 714
b99bd4ef
NC
715/* Stuff needed to resolve the label ambiguity
716 As:
717 ...
718 label: <insn>
719 may differ from:
720 ...
721 label:
5f4273c7 722 <insn> */
b99bd4ef
NC
723
724symbolS * last_label_seen;
b34976b6 725static int label_is_thumb_function_name = FALSE;
e07e6e58 726
3d0c9500
NC
727/* Literal pool structure. Held on a per-section
728 and per-sub-section basis. */
a737bd4d 729
c19d1205 730#define MAX_LITERAL_POOL_SIZE 1024
3d0c9500 731typedef struct literal_pool
b99bd4ef 732{
c19d1205
ZW
733 expressionS literals [MAX_LITERAL_POOL_SIZE];
734 unsigned int next_free_entry;
735 unsigned int id;
736 symbolS * symbol;
737 segT section;
738 subsegT sub_section;
61b5f74b 739 struct literal_pool * next;
3d0c9500 740} literal_pool;
b99bd4ef 741
3d0c9500
NC
742/* Pointer to a linked list of literal pools. */
743literal_pool * list_of_pools = NULL;
e27ec89e 744
e07e6e58
NC
745#ifdef OBJ_ELF
746# define now_it seg_info (now_seg)->tc_segment_info_data.current_it
747#else
748static struct current_it now_it;
749#endif
750
751static inline int
752now_it_compatible (int cond)
753{
754 return (cond & ~1) == (now_it.cc & ~1);
755}
756
757static inline int
758conditional_insn (void)
759{
760 return inst.cond != COND_ALWAYS;
761}
762
763static int in_it_block (void);
764
765static int handle_it_state (void);
766
767static void force_automatic_it_block_close (void);
768
769#define set_it_insn_type(type) \
770 do \
771 { \
772 inst.it_insn_type = type; \
773 if (handle_it_state () == FAIL) \
774 return; \
775 } \
776 while (0)
777
778#define set_it_insn_type_last() \
779 do \
780 { \
781 if (inst.cond == COND_ALWAYS) \
782 set_it_insn_type (IF_INSIDE_IT_LAST_INSN); \
783 else \
784 set_it_insn_type (INSIDE_IT_LAST_INSN); \
785 } \
786 while (0)
787
c19d1205 788/* Pure syntax. */
b99bd4ef 789
c19d1205
ZW
790/* This array holds the chars that always start a comment. If the
791 pre-processor is disabled, these aren't very useful. */
792const char comment_chars[] = "@";
3d0c9500 793
c19d1205
ZW
794/* This array holds the chars that only start a comment at the beginning of
795 a line. If the line seems to have the form '# 123 filename'
796 .line and .file directives will appear in the pre-processed output. */
797/* Note that input_file.c hand checks for '#' at the beginning of the
798 first line of the input file. This is because the compiler outputs
799 #NO_APP at the beginning of its output. */
800/* Also note that comments like this one will always work. */
801const char line_comment_chars[] = "#";
3d0c9500 802
c19d1205 803const char line_separator_chars[] = ";";
b99bd4ef 804
c19d1205
ZW
805/* Chars that can be used to separate mant
806 from exp in floating point numbers. */
807const char EXP_CHARS[] = "eE";
3d0c9500 808
c19d1205
ZW
809/* Chars that mean this number is a floating point constant. */
810/* As in 0f12.456 */
811/* or 0d1.2345e12 */
b99bd4ef 812
c19d1205 813const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
3d0c9500 814
c19d1205
ZW
815/* Prefix characters that indicate the start of an immediate
816 value. */
817#define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
3d0c9500 818
c19d1205
ZW
819/* Separator character handling. */
820
821#define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
822
823static inline int
824skip_past_char (char ** str, char c)
825{
826 if (**str == c)
827 {
828 (*str)++;
829 return SUCCESS;
3d0c9500 830 }
c19d1205
ZW
831 else
832 return FAIL;
833}
834#define skip_past_comma(str) skip_past_char (str, ',')
3d0c9500 835
c19d1205
ZW
836/* Arithmetic expressions (possibly involving symbols). */
837
838/* Return TRUE if anything in the expression is a bignum. */
839
840static int
841walk_no_bignums (symbolS * sp)
842{
843 if (symbol_get_value_expression (sp)->X_op == O_big)
844 return 1;
845
846 if (symbol_get_value_expression (sp)->X_add_symbol)
3d0c9500 847 {
c19d1205
ZW
848 return (walk_no_bignums (symbol_get_value_expression (sp)->X_add_symbol)
849 || (symbol_get_value_expression (sp)->X_op_symbol
850 && walk_no_bignums (symbol_get_value_expression (sp)->X_op_symbol)));
3d0c9500
NC
851 }
852
c19d1205 853 return 0;
3d0c9500
NC
854}
855
c19d1205
ZW
856static int in_my_get_expression = 0;
857
858/* Third argument to my_get_expression. */
859#define GE_NO_PREFIX 0
860#define GE_IMM_PREFIX 1
861#define GE_OPT_PREFIX 2
5287ad62
JB
862/* This is a bit of a hack. Use an optional prefix, and also allow big (64-bit)
863 immediates, as can be used in Neon VMVN and VMOV immediate instructions. */
864#define GE_OPT_PREFIX_BIG 3
a737bd4d 865
b99bd4ef 866static int
c19d1205 867my_get_expression (expressionS * ep, char ** str, int prefix_mode)
b99bd4ef 868{
c19d1205
ZW
869 char * save_in;
870 segT seg;
b99bd4ef 871
c19d1205
ZW
872 /* In unified syntax, all prefixes are optional. */
873 if (unified_syntax)
5287ad62
JB
874 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
875 : GE_OPT_PREFIX;
b99bd4ef 876
c19d1205 877 switch (prefix_mode)
b99bd4ef 878 {
c19d1205
ZW
879 case GE_NO_PREFIX: break;
880 case GE_IMM_PREFIX:
881 if (!is_immediate_prefix (**str))
882 {
883 inst.error = _("immediate expression requires a # prefix");
884 return FAIL;
885 }
886 (*str)++;
887 break;
888 case GE_OPT_PREFIX:
5287ad62 889 case GE_OPT_PREFIX_BIG:
c19d1205
ZW
890 if (is_immediate_prefix (**str))
891 (*str)++;
892 break;
893 default: abort ();
894 }
b99bd4ef 895
c19d1205 896 memset (ep, 0, sizeof (expressionS));
b99bd4ef 897
c19d1205
ZW
898 save_in = input_line_pointer;
899 input_line_pointer = *str;
900 in_my_get_expression = 1;
901 seg = expression (ep);
902 in_my_get_expression = 0;
903
904 if (ep->X_op == O_illegal)
b99bd4ef 905 {
c19d1205
ZW
906 /* We found a bad expression in md_operand(). */
907 *str = input_line_pointer;
908 input_line_pointer = save_in;
909 if (inst.error == NULL)
910 inst.error = _("bad expression");
911 return 1;
912 }
b99bd4ef 913
c19d1205
ZW
914#ifdef OBJ_AOUT
915 if (seg != absolute_section
916 && seg != text_section
917 && seg != data_section
918 && seg != bss_section
919 && seg != undefined_section)
920 {
921 inst.error = _("bad segment");
922 *str = input_line_pointer;
923 input_line_pointer = save_in;
924 return 1;
b99bd4ef 925 }
c19d1205 926#endif
b99bd4ef 927
c19d1205
ZW
928 /* Get rid of any bignums now, so that we don't generate an error for which
929 we can't establish a line number later on. Big numbers are never valid
930 in instructions, which is where this routine is always called. */
5287ad62
JB
931 if (prefix_mode != GE_OPT_PREFIX_BIG
932 && (ep->X_op == O_big
933 || (ep->X_add_symbol
934 && (walk_no_bignums (ep->X_add_symbol)
935 || (ep->X_op_symbol
936 && walk_no_bignums (ep->X_op_symbol))))))
c19d1205
ZW
937 {
938 inst.error = _("invalid constant");
939 *str = input_line_pointer;
940 input_line_pointer = save_in;
941 return 1;
942 }
b99bd4ef 943
c19d1205
ZW
944 *str = input_line_pointer;
945 input_line_pointer = save_in;
946 return 0;
b99bd4ef
NC
947}
948
c19d1205
ZW
949/* Turn a string in input_line_pointer into a floating point constant
950 of type TYPE, and store the appropriate bytes in *LITP. The number
951 of LITTLENUMS emitted is stored in *SIZEP. An error message is
952 returned, or NULL on OK.
b99bd4ef 953
c19d1205
ZW
954 Note that fp constants aren't represent in the normal way on the ARM.
955 In big endian mode, things are as expected. However, in little endian
956 mode fp constants are big-endian word-wise, and little-endian byte-wise
957 within the words. For example, (double) 1.1 in big endian mode is
958 the byte sequence 3f f1 99 99 99 99 99 9a, and in little endian mode is
959 the byte sequence 99 99 f1 3f 9a 99 99 99.
b99bd4ef 960
c19d1205 961 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
b99bd4ef 962
c19d1205
ZW
963char *
964md_atof (int type, char * litP, int * sizeP)
965{
966 int prec;
967 LITTLENUM_TYPE words[MAX_LITTLENUMS];
968 char *t;
969 int i;
b99bd4ef 970
c19d1205
ZW
971 switch (type)
972 {
973 case 'f':
974 case 'F':
975 case 's':
976 case 'S':
977 prec = 2;
978 break;
b99bd4ef 979
c19d1205
ZW
980 case 'd':
981 case 'D':
982 case 'r':
983 case 'R':
984 prec = 4;
985 break;
b99bd4ef 986
c19d1205
ZW
987 case 'x':
988 case 'X':
499ac353 989 prec = 5;
c19d1205 990 break;
b99bd4ef 991
c19d1205
ZW
992 case 'p':
993 case 'P':
499ac353 994 prec = 5;
c19d1205 995 break;
a737bd4d 996
c19d1205
ZW
997 default:
998 *sizeP = 0;
499ac353 999 return _("Unrecognized or unsupported floating point constant");
c19d1205 1000 }
b99bd4ef 1001
c19d1205
ZW
1002 t = atof_ieee (input_line_pointer, type, words);
1003 if (t)
1004 input_line_pointer = t;
499ac353 1005 *sizeP = prec * sizeof (LITTLENUM_TYPE);
b99bd4ef 1006
c19d1205
ZW
1007 if (target_big_endian)
1008 {
1009 for (i = 0; i < prec; i++)
1010 {
499ac353
NC
1011 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1012 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1013 }
1014 }
1015 else
1016 {
e74cfd16 1017 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
c19d1205
ZW
1018 for (i = prec - 1; i >= 0; i--)
1019 {
499ac353
NC
1020 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1021 litP += sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1022 }
1023 else
1024 /* For a 4 byte float the order of elements in `words' is 1 0.
1025 For an 8 byte float the order is 1 0 3 2. */
1026 for (i = 0; i < prec; i += 2)
1027 {
499ac353
NC
1028 md_number_to_chars (litP, (valueT) words[i + 1],
1029 sizeof (LITTLENUM_TYPE));
1030 md_number_to_chars (litP + sizeof (LITTLENUM_TYPE),
1031 (valueT) words[i], sizeof (LITTLENUM_TYPE));
1032 litP += 2 * sizeof (LITTLENUM_TYPE);
c19d1205
ZW
1033 }
1034 }
b99bd4ef 1035
499ac353 1036 return NULL;
c19d1205 1037}
b99bd4ef 1038
c19d1205
ZW
1039/* We handle all bad expressions here, so that we can report the faulty
1040 instruction in the error message. */
1041void
1042md_operand (expressionS * expr)
1043{
1044 if (in_my_get_expression)
1045 expr->X_op = O_illegal;
b99bd4ef
NC
1046}
1047
c19d1205 1048/* Immediate values. */
b99bd4ef 1049
c19d1205
ZW
1050/* Generic immediate-value read function for use in directives.
1051 Accepts anything that 'expression' can fold to a constant.
1052 *val receives the number. */
1053#ifdef OBJ_ELF
1054static int
1055immediate_for_directive (int *val)
b99bd4ef 1056{
c19d1205
ZW
1057 expressionS exp;
1058 exp.X_op = O_illegal;
b99bd4ef 1059
c19d1205
ZW
1060 if (is_immediate_prefix (*input_line_pointer))
1061 {
1062 input_line_pointer++;
1063 expression (&exp);
1064 }
b99bd4ef 1065
c19d1205
ZW
1066 if (exp.X_op != O_constant)
1067 {
1068 as_bad (_("expected #constant"));
1069 ignore_rest_of_line ();
1070 return FAIL;
1071 }
1072 *val = exp.X_add_number;
1073 return SUCCESS;
b99bd4ef 1074}
c19d1205 1075#endif
b99bd4ef 1076
c19d1205 1077/* Register parsing. */
b99bd4ef 1078
c19d1205
ZW
1079/* Generic register parser. CCP points to what should be the
1080 beginning of a register name. If it is indeed a valid register
1081 name, advance CCP over it and return the reg_entry structure;
1082 otherwise return NULL. Does not issue diagnostics. */
1083
1084static struct reg_entry *
1085arm_reg_parse_multi (char **ccp)
b99bd4ef 1086{
c19d1205
ZW
1087 char *start = *ccp;
1088 char *p;
1089 struct reg_entry *reg;
b99bd4ef 1090
c19d1205
ZW
1091#ifdef REGISTER_PREFIX
1092 if (*start != REGISTER_PREFIX)
01cfc07f 1093 return NULL;
c19d1205
ZW
1094 start++;
1095#endif
1096#ifdef OPTIONAL_REGISTER_PREFIX
1097 if (*start == OPTIONAL_REGISTER_PREFIX)
1098 start++;
1099#endif
b99bd4ef 1100
c19d1205
ZW
1101 p = start;
1102 if (!ISALPHA (*p) || !is_name_beginner (*p))
1103 return NULL;
b99bd4ef 1104
c19d1205
ZW
1105 do
1106 p++;
1107 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1108
1109 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1110
1111 if (!reg)
1112 return NULL;
1113
1114 *ccp = p;
1115 return reg;
b99bd4ef
NC
1116}
1117
1118static int
dcbf9037
JB
1119arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1120 enum arm_reg_type type)
b99bd4ef 1121{
c19d1205
ZW
1122 /* Alternative syntaxes are accepted for a few register classes. */
1123 switch (type)
1124 {
1125 case REG_TYPE_MVF:
1126 case REG_TYPE_MVD:
1127 case REG_TYPE_MVFX:
1128 case REG_TYPE_MVDX:
1129 /* Generic coprocessor register names are allowed for these. */
79134647 1130 if (reg && reg->type == REG_TYPE_CN)
c19d1205
ZW
1131 return reg->number;
1132 break;
69b97547 1133
c19d1205
ZW
1134 case REG_TYPE_CP:
1135 /* For backward compatibility, a bare number is valid here. */
1136 {
1137 unsigned long processor = strtoul (start, ccp, 10);
1138 if (*ccp != start && processor <= 15)
1139 return processor;
1140 }
6057a28f 1141
c19d1205
ZW
1142 case REG_TYPE_MMXWC:
1143 /* WC includes WCG. ??? I'm not sure this is true for all
1144 instructions that take WC registers. */
79134647 1145 if (reg && reg->type == REG_TYPE_MMXWCG)
c19d1205 1146 return reg->number;
6057a28f 1147 break;
c19d1205 1148
6057a28f 1149 default:
c19d1205 1150 break;
6057a28f
NC
1151 }
1152
dcbf9037
JB
1153 return FAIL;
1154}
1155
1156/* As arm_reg_parse_multi, but the register must be of type TYPE, and the
1157 return value is the register number or FAIL. */
1158
1159static int
1160arm_reg_parse (char **ccp, enum arm_reg_type type)
1161{
1162 char *start = *ccp;
1163 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1164 int ret;
1165
1166 /* Do not allow a scalar (reg+index) to parse as a register. */
1167 if (reg && reg->neon && (reg->neon->defined & NTA_HASINDEX))
1168 return FAIL;
1169
1170 if (reg && reg->type == type)
1171 return reg->number;
1172
1173 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1174 return ret;
1175
c19d1205
ZW
1176 *ccp = start;
1177 return FAIL;
1178}
69b97547 1179
dcbf9037
JB
1180/* Parse a Neon type specifier. *STR should point at the leading '.'
1181 character. Does no verification at this stage that the type fits the opcode
1182 properly. E.g.,
1183
1184 .i32.i32.s16
1185 .s32.f32
1186 .u16
1187
1188 Can all be legally parsed by this function.
1189
1190 Fills in neon_type struct pointer with parsed information, and updates STR
1191 to point after the parsed type specifier. Returns SUCCESS if this was a legal
1192 type, FAIL if not. */
1193
1194static int
1195parse_neon_type (struct neon_type *type, char **str)
1196{
1197 char *ptr = *str;
1198
1199 if (type)
1200 type->elems = 0;
1201
1202 while (type->elems < NEON_MAX_TYPE_ELS)
1203 {
1204 enum neon_el_type thistype = NT_untyped;
1205 unsigned thissize = -1u;
1206
1207 if (*ptr != '.')
1208 break;
1209
1210 ptr++;
1211
1212 /* Just a size without an explicit type. */
1213 if (ISDIGIT (*ptr))
1214 goto parsesize;
1215
1216 switch (TOLOWER (*ptr))
1217 {
1218 case 'i': thistype = NT_integer; break;
1219 case 'f': thistype = NT_float; break;
1220 case 'p': thistype = NT_poly; break;
1221 case 's': thistype = NT_signed; break;
1222 case 'u': thistype = NT_unsigned; break;
037e8744
JB
1223 case 'd':
1224 thistype = NT_float;
1225 thissize = 64;
1226 ptr++;
1227 goto done;
dcbf9037
JB
1228 default:
1229 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1230 return FAIL;
1231 }
1232
1233 ptr++;
1234
1235 /* .f is an abbreviation for .f32. */
1236 if (thistype == NT_float && !ISDIGIT (*ptr))
1237 thissize = 32;
1238 else
1239 {
1240 parsesize:
1241 thissize = strtoul (ptr, &ptr, 10);
1242
1243 if (thissize != 8 && thissize != 16 && thissize != 32
1244 && thissize != 64)
1245 {
1246 as_bad (_("bad size %d in type specifier"), thissize);
1247 return FAIL;
1248 }
1249 }
1250
037e8744 1251 done:
dcbf9037
JB
1252 if (type)
1253 {
1254 type->el[type->elems].type = thistype;
1255 type->el[type->elems].size = thissize;
1256 type->elems++;
1257 }
1258 }
1259
1260 /* Empty/missing type is not a successful parse. */
1261 if (type->elems == 0)
1262 return FAIL;
1263
1264 *str = ptr;
1265
1266 return SUCCESS;
1267}
1268
1269/* Errors may be set multiple times during parsing or bit encoding
1270 (particularly in the Neon bits), but usually the earliest error which is set
1271 will be the most meaningful. Avoid overwriting it with later (cascading)
1272 errors by calling this function. */
1273
1274static void
1275first_error (const char *err)
1276{
1277 if (!inst.error)
1278 inst.error = err;
1279}
1280
1281/* Parse a single type, e.g. ".s32", leading period included. */
1282static int
1283parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1284{
1285 char *str = *ccp;
1286 struct neon_type optype;
1287
1288 if (*str == '.')
1289 {
1290 if (parse_neon_type (&optype, &str) == SUCCESS)
1291 {
1292 if (optype.elems == 1)
1293 *vectype = optype.el[0];
1294 else
1295 {
1296 first_error (_("only one type should be specified for operand"));
1297 return FAIL;
1298 }
1299 }
1300 else
1301 {
1302 first_error (_("vector type expected"));
1303 return FAIL;
1304 }
1305 }
1306 else
1307 return FAIL;
5f4273c7 1308
dcbf9037 1309 *ccp = str;
5f4273c7 1310
dcbf9037
JB
1311 return SUCCESS;
1312}
1313
1314/* Special meanings for indices (which have a range of 0-7), which will fit into
1315 a 4-bit integer. */
1316
1317#define NEON_ALL_LANES 15
1318#define NEON_INTERLEAVE_LANES 14
1319
1320/* Parse either a register or a scalar, with an optional type. Return the
1321 register number, and optionally fill in the actual type of the register
1322 when multiple alternatives were given (NEON_TYPE_NDQ) in *RTYPE, and
1323 type/index information in *TYPEINFO. */
1324
1325static int
1326parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1327 enum arm_reg_type *rtype,
1328 struct neon_typed_alias *typeinfo)
1329{
1330 char *str = *ccp;
1331 struct reg_entry *reg = arm_reg_parse_multi (&str);
1332 struct neon_typed_alias atype;
1333 struct neon_type_el parsetype;
1334
1335 atype.defined = 0;
1336 atype.index = -1;
1337 atype.eltype.type = NT_invtype;
1338 atype.eltype.size = -1;
1339
1340 /* Try alternate syntax for some types of register. Note these are mutually
1341 exclusive with the Neon syntax extensions. */
1342 if (reg == NULL)
1343 {
1344 int altreg = arm_reg_alt_syntax (&str, *ccp, reg, type);
1345 if (altreg != FAIL)
1346 *ccp = str;
1347 if (typeinfo)
1348 *typeinfo = atype;
1349 return altreg;
1350 }
1351
037e8744
JB
1352 /* Undo polymorphism when a set of register types may be accepted. */
1353 if ((type == REG_TYPE_NDQ
1354 && (reg->type == REG_TYPE_NQ || reg->type == REG_TYPE_VFD))
1355 || (type == REG_TYPE_VFSD
1356 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD))
1357 || (type == REG_TYPE_NSDQ
1358 && (reg->type == REG_TYPE_VFS || reg->type == REG_TYPE_VFD
f512f76f
NC
1359 || reg->type == REG_TYPE_NQ))
1360 || (type == REG_TYPE_MMXWC
1361 && (reg->type == REG_TYPE_MMXWCG)))
dcbf9037
JB
1362 type = reg->type;
1363
1364 if (type != reg->type)
1365 return FAIL;
1366
1367 if (reg->neon)
1368 atype = *reg->neon;
5f4273c7 1369
dcbf9037
JB
1370 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1371 {
1372 if ((atype.defined & NTA_HASTYPE) != 0)
1373 {
1374 first_error (_("can't redefine type for operand"));
1375 return FAIL;
1376 }
1377 atype.defined |= NTA_HASTYPE;
1378 atype.eltype = parsetype;
1379 }
5f4273c7 1380
dcbf9037
JB
1381 if (skip_past_char (&str, '[') == SUCCESS)
1382 {
1383 if (type != REG_TYPE_VFD)
1384 {
1385 first_error (_("only D registers may be indexed"));
1386 return FAIL;
1387 }
5f4273c7 1388
dcbf9037
JB
1389 if ((atype.defined & NTA_HASINDEX) != 0)
1390 {
1391 first_error (_("can't change index for operand"));
1392 return FAIL;
1393 }
1394
1395 atype.defined |= NTA_HASINDEX;
1396
1397 if (skip_past_char (&str, ']') == SUCCESS)
1398 atype.index = NEON_ALL_LANES;
1399 else
1400 {
1401 expressionS exp;
1402
1403 my_get_expression (&exp, &str, GE_NO_PREFIX);
1404
1405 if (exp.X_op != O_constant)
1406 {
1407 first_error (_("constant expression required"));
1408 return FAIL;
1409 }
1410
1411 if (skip_past_char (&str, ']') == FAIL)
1412 return FAIL;
1413
1414 atype.index = exp.X_add_number;
1415 }
1416 }
5f4273c7 1417
dcbf9037
JB
1418 if (typeinfo)
1419 *typeinfo = atype;
5f4273c7 1420
dcbf9037
JB
1421 if (rtype)
1422 *rtype = type;
5f4273c7 1423
dcbf9037 1424 *ccp = str;
5f4273c7 1425
dcbf9037
JB
1426 return reg->number;
1427}
1428
1429/* Like arm_reg_parse, but allow allow the following extra features:
1430 - If RTYPE is non-zero, return the (possibly restricted) type of the
1431 register (e.g. Neon double or quad reg when either has been requested).
1432 - If this is a Neon vector type with additional type information, fill
1433 in the struct pointed to by VECTYPE (if non-NULL).
5f4273c7 1434 This function will fault on encountering a scalar. */
dcbf9037
JB
1435
1436static int
1437arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1438 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1439{
1440 struct neon_typed_alias atype;
1441 char *str = *ccp;
1442 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1443
1444 if (reg == FAIL)
1445 return FAIL;
1446
1447 /* Do not allow a scalar (reg+index) to parse as a register. */
1448 if ((atype.defined & NTA_HASINDEX) != 0)
1449 {
1450 first_error (_("register operand expected, but got scalar"));
1451 return FAIL;
1452 }
1453
1454 if (vectype)
1455 *vectype = atype.eltype;
1456
1457 *ccp = str;
1458
1459 return reg;
1460}
1461
1462#define NEON_SCALAR_REG(X) ((X) >> 4)
1463#define NEON_SCALAR_INDEX(X) ((X) & 15)
1464
5287ad62
JB
1465/* Parse a Neon scalar. Most of the time when we're parsing a scalar, we don't
1466 have enough information to be able to do a good job bounds-checking. So, we
1467 just do easy checks here, and do further checks later. */
1468
1469static int
dcbf9037 1470parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
5287ad62 1471{
dcbf9037 1472 int reg;
5287ad62 1473 char *str = *ccp;
dcbf9037 1474 struct neon_typed_alias atype;
5f4273c7 1475
dcbf9037 1476 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
5f4273c7 1477
dcbf9037 1478 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
5287ad62 1479 return FAIL;
5f4273c7 1480
dcbf9037 1481 if (atype.index == NEON_ALL_LANES)
5287ad62 1482 {
dcbf9037 1483 first_error (_("scalar must have an index"));
5287ad62
JB
1484 return FAIL;
1485 }
dcbf9037 1486 else if (atype.index >= 64 / elsize)
5287ad62 1487 {
dcbf9037 1488 first_error (_("scalar index out of range"));
5287ad62
JB
1489 return FAIL;
1490 }
5f4273c7 1491
dcbf9037
JB
1492 if (type)
1493 *type = atype.eltype;
5f4273c7 1494
5287ad62 1495 *ccp = str;
5f4273c7 1496
dcbf9037 1497 return reg * 16 + atype.index;
5287ad62
JB
1498}
1499
c19d1205 1500/* Parse an ARM register list. Returns the bitmask, or FAIL. */
e07e6e58 1501
c19d1205
ZW
1502static long
1503parse_reg_list (char ** strp)
1504{
1505 char * str = * strp;
1506 long range = 0;
1507 int another_range;
a737bd4d 1508
c19d1205
ZW
1509 /* We come back here if we get ranges concatenated by '+' or '|'. */
1510 do
6057a28f 1511 {
c19d1205 1512 another_range = 0;
a737bd4d 1513
c19d1205
ZW
1514 if (*str == '{')
1515 {
1516 int in_range = 0;
1517 int cur_reg = -1;
a737bd4d 1518
c19d1205
ZW
1519 str++;
1520 do
1521 {
1522 int reg;
6057a28f 1523
dcbf9037 1524 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
c19d1205 1525 {
dcbf9037 1526 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
c19d1205
ZW
1527 return FAIL;
1528 }
a737bd4d 1529
c19d1205
ZW
1530 if (in_range)
1531 {
1532 int i;
a737bd4d 1533
c19d1205
ZW
1534 if (reg <= cur_reg)
1535 {
dcbf9037 1536 first_error (_("bad range in register list"));
c19d1205
ZW
1537 return FAIL;
1538 }
40a18ebd 1539
c19d1205
ZW
1540 for (i = cur_reg + 1; i < reg; i++)
1541 {
1542 if (range & (1 << i))
1543 as_tsktsk
1544 (_("Warning: duplicated register (r%d) in register list"),
1545 i);
1546 else
1547 range |= 1 << i;
1548 }
1549 in_range = 0;
1550 }
a737bd4d 1551
c19d1205
ZW
1552 if (range & (1 << reg))
1553 as_tsktsk (_("Warning: duplicated register (r%d) in register list"),
1554 reg);
1555 else if (reg <= cur_reg)
1556 as_tsktsk (_("Warning: register range not in ascending order"));
a737bd4d 1557
c19d1205
ZW
1558 range |= 1 << reg;
1559 cur_reg = reg;
1560 }
1561 while (skip_past_comma (&str) != FAIL
1562 || (in_range = 1, *str++ == '-'));
1563 str--;
a737bd4d 1564
c19d1205
ZW
1565 if (*str++ != '}')
1566 {
dcbf9037 1567 first_error (_("missing `}'"));
c19d1205
ZW
1568 return FAIL;
1569 }
1570 }
1571 else
1572 {
1573 expressionS expr;
40a18ebd 1574
c19d1205
ZW
1575 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1576 return FAIL;
40a18ebd 1577
c19d1205
ZW
1578 if (expr.X_op == O_constant)
1579 {
1580 if (expr.X_add_number
1581 != (expr.X_add_number & 0x0000ffff))
1582 {
1583 inst.error = _("invalid register mask");
1584 return FAIL;
1585 }
a737bd4d 1586
c19d1205
ZW
1587 if ((range & expr.X_add_number) != 0)
1588 {
1589 int regno = range & expr.X_add_number;
a737bd4d 1590
c19d1205
ZW
1591 regno &= -regno;
1592 regno = (1 << regno) - 1;
1593 as_tsktsk
1594 (_("Warning: duplicated register (r%d) in register list"),
1595 regno);
1596 }
a737bd4d 1597
c19d1205
ZW
1598 range |= expr.X_add_number;
1599 }
1600 else
1601 {
1602 if (inst.reloc.type != 0)
1603 {
1604 inst.error = _("expression too complex");
1605 return FAIL;
1606 }
a737bd4d 1607
c19d1205
ZW
1608 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1609 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1610 inst.reloc.pc_rel = 0;
1611 }
1612 }
a737bd4d 1613
c19d1205
ZW
1614 if (*str == '|' || *str == '+')
1615 {
1616 str++;
1617 another_range = 1;
1618 }
a737bd4d 1619 }
c19d1205 1620 while (another_range);
a737bd4d 1621
c19d1205
ZW
1622 *strp = str;
1623 return range;
a737bd4d
NC
1624}
1625
5287ad62
JB
1626/* Types of registers in a list. */
1627
1628enum reg_list_els
1629{
1630 REGLIST_VFP_S,
1631 REGLIST_VFP_D,
1632 REGLIST_NEON_D
1633};
1634
c19d1205
ZW
1635/* Parse a VFP register list. If the string is invalid return FAIL.
1636 Otherwise return the number of registers, and set PBASE to the first
5287ad62
JB
1637 register. Parses registers of type ETYPE.
1638 If REGLIST_NEON_D is used, several syntax enhancements are enabled:
1639 - Q registers can be used to specify pairs of D registers
1640 - { } can be omitted from around a singleton register list
1641 FIXME: This is not implemented, as it would require backtracking in
1642 some cases, e.g.:
1643 vtbl.8 d3,d4,d5
1644 This could be done (the meaning isn't really ambiguous), but doesn't
1645 fit in well with the current parsing framework.
dcbf9037
JB
1646 - 32 D registers may be used (also true for VFPv3).
1647 FIXME: Types are ignored in these register lists, which is probably a
1648 bug. */
6057a28f 1649
c19d1205 1650static int
037e8744 1651parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
6057a28f 1652{
037e8744 1653 char *str = *ccp;
c19d1205
ZW
1654 int base_reg;
1655 int new_base;
5287ad62
JB
1656 enum arm_reg_type regtype = 0;
1657 int max_regs = 0;
c19d1205
ZW
1658 int count = 0;
1659 int warned = 0;
1660 unsigned long mask = 0;
a737bd4d 1661 int i;
6057a28f 1662
037e8744 1663 if (*str != '{')
5287ad62
JB
1664 {
1665 inst.error = _("expecting {");
1666 return FAIL;
1667 }
6057a28f 1668
037e8744 1669 str++;
6057a28f 1670
5287ad62 1671 switch (etype)
c19d1205 1672 {
5287ad62 1673 case REGLIST_VFP_S:
c19d1205
ZW
1674 regtype = REG_TYPE_VFS;
1675 max_regs = 32;
5287ad62 1676 break;
5f4273c7 1677
5287ad62
JB
1678 case REGLIST_VFP_D:
1679 regtype = REG_TYPE_VFD;
b7fc2769 1680 break;
5f4273c7 1681
b7fc2769
JB
1682 case REGLIST_NEON_D:
1683 regtype = REG_TYPE_NDQ;
1684 break;
1685 }
1686
1687 if (etype != REGLIST_VFP_S)
1688 {
b1cc4aeb
PB
1689 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1690 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
1691 {
1692 max_regs = 32;
1693 if (thumb_mode)
1694 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 1695 fpu_vfp_ext_d32);
5287ad62
JB
1696 else
1697 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 1698 fpu_vfp_ext_d32);
5287ad62
JB
1699 }
1700 else
1701 max_regs = 16;
c19d1205 1702 }
6057a28f 1703
c19d1205 1704 base_reg = max_regs;
a737bd4d 1705
c19d1205
ZW
1706 do
1707 {
5287ad62 1708 int setmask = 1, addregs = 1;
dcbf9037 1709
037e8744 1710 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
dcbf9037 1711
c19d1205 1712 if (new_base == FAIL)
a737bd4d 1713 {
dcbf9037 1714 first_error (_(reg_expected_msgs[regtype]));
c19d1205
ZW
1715 return FAIL;
1716 }
5f4273c7 1717
b7fc2769
JB
1718 if (new_base >= max_regs)
1719 {
1720 first_error (_("register out of range in list"));
1721 return FAIL;
1722 }
5f4273c7 1723
5287ad62
JB
1724 /* Note: a value of 2 * n is returned for the register Q<n>. */
1725 if (regtype == REG_TYPE_NQ)
1726 {
1727 setmask = 3;
1728 addregs = 2;
1729 }
1730
c19d1205
ZW
1731 if (new_base < base_reg)
1732 base_reg = new_base;
a737bd4d 1733
5287ad62 1734 if (mask & (setmask << new_base))
c19d1205 1735 {
dcbf9037 1736 first_error (_("invalid register list"));
c19d1205 1737 return FAIL;
a737bd4d 1738 }
a737bd4d 1739
c19d1205
ZW
1740 if ((mask >> new_base) != 0 && ! warned)
1741 {
1742 as_tsktsk (_("register list not in ascending order"));
1743 warned = 1;
1744 }
0bbf2aa4 1745
5287ad62
JB
1746 mask |= setmask << new_base;
1747 count += addregs;
0bbf2aa4 1748
037e8744 1749 if (*str == '-') /* We have the start of a range expression */
c19d1205
ZW
1750 {
1751 int high_range;
0bbf2aa4 1752
037e8744 1753 str++;
0bbf2aa4 1754
037e8744 1755 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
dcbf9037 1756 == FAIL)
c19d1205
ZW
1757 {
1758 inst.error = gettext (reg_expected_msgs[regtype]);
1759 return FAIL;
1760 }
0bbf2aa4 1761
b7fc2769
JB
1762 if (high_range >= max_regs)
1763 {
1764 first_error (_("register out of range in list"));
1765 return FAIL;
1766 }
1767
5287ad62
JB
1768 if (regtype == REG_TYPE_NQ)
1769 high_range = high_range + 1;
1770
c19d1205
ZW
1771 if (high_range <= new_base)
1772 {
1773 inst.error = _("register range not in ascending order");
1774 return FAIL;
1775 }
0bbf2aa4 1776
5287ad62 1777 for (new_base += addregs; new_base <= high_range; new_base += addregs)
0bbf2aa4 1778 {
5287ad62 1779 if (mask & (setmask << new_base))
0bbf2aa4 1780 {
c19d1205
ZW
1781 inst.error = _("invalid register list");
1782 return FAIL;
0bbf2aa4 1783 }
c19d1205 1784
5287ad62
JB
1785 mask |= setmask << new_base;
1786 count += addregs;
0bbf2aa4 1787 }
0bbf2aa4 1788 }
0bbf2aa4 1789 }
037e8744 1790 while (skip_past_comma (&str) != FAIL);
0bbf2aa4 1791
037e8744 1792 str++;
0bbf2aa4 1793
c19d1205
ZW
1794 /* Sanity check -- should have raised a parse error above. */
1795 if (count == 0 || count > max_regs)
1796 abort ();
1797
1798 *pbase = base_reg;
1799
1800 /* Final test -- the registers must be consecutive. */
1801 mask >>= base_reg;
1802 for (i = 0; i < count; i++)
1803 {
1804 if ((mask & (1u << i)) == 0)
1805 {
1806 inst.error = _("non-contiguous register range");
1807 return FAIL;
1808 }
1809 }
1810
037e8744
JB
1811 *ccp = str;
1812
c19d1205 1813 return count;
b99bd4ef
NC
1814}
1815
dcbf9037
JB
1816/* True if two alias types are the same. */
1817
1818static int
1819neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1820{
1821 if (!a && !b)
1822 return 1;
5f4273c7 1823
dcbf9037
JB
1824 if (!a || !b)
1825 return 0;
1826
1827 if (a->defined != b->defined)
1828 return 0;
5f4273c7 1829
dcbf9037
JB
1830 if ((a->defined & NTA_HASTYPE) != 0
1831 && (a->eltype.type != b->eltype.type
1832 || a->eltype.size != b->eltype.size))
1833 return 0;
1834
1835 if ((a->defined & NTA_HASINDEX) != 0
1836 && (a->index != b->index))
1837 return 0;
5f4273c7 1838
dcbf9037
JB
1839 return 1;
1840}
1841
5287ad62
JB
1842/* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1843 The base register is put in *PBASE.
dcbf9037 1844 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
5287ad62
JB
1845 the return value.
1846 The register stride (minus one) is put in bit 4 of the return value.
dcbf9037
JB
1847 Bits [6:5] encode the list length (minus one).
1848 The type of the list elements is put in *ELTYPE, if non-NULL. */
5287ad62 1849
5287ad62 1850#define NEON_LANE(X) ((X) & 0xf)
dcbf9037 1851#define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
5287ad62
JB
1852#define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1853
1854static int
dcbf9037
JB
1855parse_neon_el_struct_list (char **str, unsigned *pbase,
1856 struct neon_type_el *eltype)
5287ad62
JB
1857{
1858 char *ptr = *str;
1859 int base_reg = -1;
1860 int reg_incr = -1;
1861 int count = 0;
1862 int lane = -1;
1863 int leading_brace = 0;
1864 enum arm_reg_type rtype = REG_TYPE_NDQ;
1865 int addregs = 1;
1866 const char *const incr_error = "register stride must be 1 or 2";
1867 const char *const type_error = "mismatched element/structure types in list";
dcbf9037 1868 struct neon_typed_alias firsttype;
5f4273c7 1869
5287ad62
JB
1870 if (skip_past_char (&ptr, '{') == SUCCESS)
1871 leading_brace = 1;
5f4273c7 1872
5287ad62
JB
1873 do
1874 {
dcbf9037
JB
1875 struct neon_typed_alias atype;
1876 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1877
5287ad62
JB
1878 if (getreg == FAIL)
1879 {
dcbf9037 1880 first_error (_(reg_expected_msgs[rtype]));
5287ad62
JB
1881 return FAIL;
1882 }
5f4273c7 1883
5287ad62
JB
1884 if (base_reg == -1)
1885 {
1886 base_reg = getreg;
1887 if (rtype == REG_TYPE_NQ)
1888 {
1889 reg_incr = 1;
1890 addregs = 2;
1891 }
dcbf9037 1892 firsttype = atype;
5287ad62
JB
1893 }
1894 else if (reg_incr == -1)
1895 {
1896 reg_incr = getreg - base_reg;
1897 if (reg_incr < 1 || reg_incr > 2)
1898 {
dcbf9037 1899 first_error (_(incr_error));
5287ad62
JB
1900 return FAIL;
1901 }
1902 }
1903 else if (getreg != base_reg + reg_incr * count)
1904 {
dcbf9037
JB
1905 first_error (_(incr_error));
1906 return FAIL;
1907 }
1908
1909 if (!neon_alias_types_same (&atype, &firsttype))
1910 {
1911 first_error (_(type_error));
5287ad62
JB
1912 return FAIL;
1913 }
5f4273c7 1914
5287ad62
JB
1915 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1916 modes. */
1917 if (ptr[0] == '-')
1918 {
dcbf9037 1919 struct neon_typed_alias htype;
5287ad62
JB
1920 int hireg, dregs = (rtype == REG_TYPE_NQ) ? 2 : 1;
1921 if (lane == -1)
1922 lane = NEON_INTERLEAVE_LANES;
1923 else if (lane != NEON_INTERLEAVE_LANES)
1924 {
dcbf9037 1925 first_error (_(type_error));
5287ad62
JB
1926 return FAIL;
1927 }
1928 if (reg_incr == -1)
1929 reg_incr = 1;
1930 else if (reg_incr != 1)
1931 {
dcbf9037 1932 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
5287ad62
JB
1933 return FAIL;
1934 }
1935 ptr++;
dcbf9037 1936 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
5287ad62
JB
1937 if (hireg == FAIL)
1938 {
dcbf9037
JB
1939 first_error (_(reg_expected_msgs[rtype]));
1940 return FAIL;
1941 }
1942 if (!neon_alias_types_same (&htype, &firsttype))
1943 {
1944 first_error (_(type_error));
5287ad62
JB
1945 return FAIL;
1946 }
1947 count += hireg + dregs - getreg;
1948 continue;
1949 }
5f4273c7 1950
5287ad62
JB
1951 /* If we're using Q registers, we can't use [] or [n] syntax. */
1952 if (rtype == REG_TYPE_NQ)
1953 {
1954 count += 2;
1955 continue;
1956 }
5f4273c7 1957
dcbf9037 1958 if ((atype.defined & NTA_HASINDEX) != 0)
5287ad62 1959 {
dcbf9037
JB
1960 if (lane == -1)
1961 lane = atype.index;
1962 else if (lane != atype.index)
5287ad62 1963 {
dcbf9037
JB
1964 first_error (_(type_error));
1965 return FAIL;
5287ad62
JB
1966 }
1967 }
1968 else if (lane == -1)
1969 lane = NEON_INTERLEAVE_LANES;
1970 else if (lane != NEON_INTERLEAVE_LANES)
1971 {
dcbf9037 1972 first_error (_(type_error));
5287ad62
JB
1973 return FAIL;
1974 }
1975 count++;
1976 }
1977 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
5f4273c7 1978
5287ad62
JB
1979 /* No lane set by [x]. We must be interleaving structures. */
1980 if (lane == -1)
1981 lane = NEON_INTERLEAVE_LANES;
5f4273c7 1982
5287ad62
JB
1983 /* Sanity check. */
1984 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1985 || (count > 1 && reg_incr == -1))
1986 {
dcbf9037 1987 first_error (_("error parsing element/structure list"));
5287ad62
JB
1988 return FAIL;
1989 }
1990
1991 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1992 {
dcbf9037 1993 first_error (_("expected }"));
5287ad62
JB
1994 return FAIL;
1995 }
5f4273c7 1996
5287ad62
JB
1997 if (reg_incr == -1)
1998 reg_incr = 1;
1999
dcbf9037
JB
2000 if (eltype)
2001 *eltype = firsttype.eltype;
2002
5287ad62
JB
2003 *pbase = base_reg;
2004 *str = ptr;
5f4273c7 2005
5287ad62
JB
2006 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
2007}
2008
c19d1205
ZW
2009/* Parse an explicit relocation suffix on an expression. This is
2010 either nothing, or a word in parentheses. Note that if !OBJ_ELF,
2011 arm_reloc_hsh contains no entries, so this function can only
2012 succeed if there is no () after the word. Returns -1 on error,
2013 BFD_RELOC_UNUSED if there wasn't any suffix. */
2014static int
2015parse_reloc (char **str)
b99bd4ef 2016{
c19d1205
ZW
2017 struct reloc_entry *r;
2018 char *p, *q;
b99bd4ef 2019
c19d1205
ZW
2020 if (**str != '(')
2021 return BFD_RELOC_UNUSED;
b99bd4ef 2022
c19d1205
ZW
2023 p = *str + 1;
2024 q = p;
2025
2026 while (*q && *q != ')' && *q != ',')
2027 q++;
2028 if (*q != ')')
2029 return -1;
2030
2031 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2032 return -1;
2033
2034 *str = q + 1;
2035 return r->reloc;
b99bd4ef
NC
2036}
2037
c19d1205
ZW
2038/* Directives: register aliases. */
2039
dcbf9037 2040static struct reg_entry *
c19d1205 2041insert_reg_alias (char *str, int number, int type)
b99bd4ef 2042{
c19d1205
ZW
2043 struct reg_entry *new;
2044 const char *name;
b99bd4ef 2045
c19d1205
ZW
2046 if ((new = hash_find (arm_reg_hsh, str)) != 0)
2047 {
2048 if (new->builtin)
2049 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
b99bd4ef 2050
c19d1205
ZW
2051 /* Only warn about a redefinition if it's not defined as the
2052 same register. */
2053 else if (new->number != number || new->type != type)
2054 as_warn (_("ignoring redefinition of register alias '%s'"), str);
69b97547 2055
d929913e 2056 return NULL;
c19d1205 2057 }
b99bd4ef 2058
c19d1205
ZW
2059 name = xstrdup (str);
2060 new = xmalloc (sizeof (struct reg_entry));
b99bd4ef 2061
c19d1205
ZW
2062 new->name = name;
2063 new->number = number;
2064 new->type = type;
2065 new->builtin = FALSE;
dcbf9037 2066 new->neon = NULL;
b99bd4ef 2067
5a49b8ac 2068 if (hash_insert (arm_reg_hsh, name, (void *) new))
c19d1205 2069 abort ();
5f4273c7 2070
dcbf9037
JB
2071 return new;
2072}
2073
2074static void
2075insert_neon_reg_alias (char *str, int number, int type,
2076 struct neon_typed_alias *atype)
2077{
2078 struct reg_entry *reg = insert_reg_alias (str, number, type);
5f4273c7 2079
dcbf9037
JB
2080 if (!reg)
2081 {
2082 first_error (_("attempt to redefine typed alias"));
2083 return;
2084 }
5f4273c7 2085
dcbf9037
JB
2086 if (atype)
2087 {
2088 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2089 *reg->neon = *atype;
2090 }
c19d1205 2091}
b99bd4ef 2092
c19d1205 2093/* Look for the .req directive. This is of the form:
b99bd4ef 2094
c19d1205 2095 new_register_name .req existing_register_name
b99bd4ef 2096
c19d1205 2097 If we find one, or if it looks sufficiently like one that we want to
d929913e 2098 handle any error here, return TRUE. Otherwise return FALSE. */
b99bd4ef 2099
d929913e 2100static bfd_boolean
c19d1205
ZW
2101create_register_alias (char * newname, char *p)
2102{
2103 struct reg_entry *old;
2104 char *oldname, *nbuf;
2105 size_t nlen;
b99bd4ef 2106
c19d1205
ZW
2107 /* The input scrubber ensures that whitespace after the mnemonic is
2108 collapsed to single spaces. */
2109 oldname = p;
2110 if (strncmp (oldname, " .req ", 6) != 0)
d929913e 2111 return FALSE;
b99bd4ef 2112
c19d1205
ZW
2113 oldname += 6;
2114 if (*oldname == '\0')
d929913e 2115 return FALSE;
b99bd4ef 2116
c19d1205
ZW
2117 old = hash_find (arm_reg_hsh, oldname);
2118 if (!old)
b99bd4ef 2119 {
c19d1205 2120 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
d929913e 2121 return TRUE;
b99bd4ef
NC
2122 }
2123
c19d1205
ZW
2124 /* If TC_CASE_SENSITIVE is defined, then newname already points to
2125 the desired alias name, and p points to its end. If not, then
2126 the desired alias name is in the global original_case_string. */
2127#ifdef TC_CASE_SENSITIVE
2128 nlen = p - newname;
2129#else
2130 newname = original_case_string;
2131 nlen = strlen (newname);
2132#endif
b99bd4ef 2133
c19d1205
ZW
2134 nbuf = alloca (nlen + 1);
2135 memcpy (nbuf, newname, nlen);
2136 nbuf[nlen] = '\0';
b99bd4ef 2137
c19d1205
ZW
2138 /* Create aliases under the new name as stated; an all-lowercase
2139 version of the new name; and an all-uppercase version of the new
2140 name. */
d929913e
NC
2141 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2142 {
2143 for (p = nbuf; *p; p++)
2144 *p = TOUPPER (*p);
c19d1205 2145
d929913e
NC
2146 if (strncmp (nbuf, newname, nlen))
2147 {
2148 /* If this attempt to create an additional alias fails, do not bother
2149 trying to create the all-lower case alias. We will fail and issue
2150 a second, duplicate error message. This situation arises when the
2151 programmer does something like:
2152 foo .req r0
2153 Foo .req r1
2154 The second .req creates the "Foo" alias but then fails to create
5f4273c7 2155 the artificial FOO alias because it has already been created by the
d929913e
NC
2156 first .req. */
2157 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2158 return TRUE;
2159 }
c19d1205 2160
d929913e
NC
2161 for (p = nbuf; *p; p++)
2162 *p = TOLOWER (*p);
c19d1205 2163
d929913e
NC
2164 if (strncmp (nbuf, newname, nlen))
2165 insert_reg_alias (nbuf, old->number, old->type);
2166 }
c19d1205 2167
d929913e 2168 return TRUE;
b99bd4ef
NC
2169}
2170
dcbf9037
JB
2171/* Create a Neon typed/indexed register alias using directives, e.g.:
2172 X .dn d5.s32[1]
2173 Y .qn 6.s16
2174 Z .dn d7
2175 T .dn Z[0]
2176 These typed registers can be used instead of the types specified after the
2177 Neon mnemonic, so long as all operands given have types. Types can also be
2178 specified directly, e.g.:
5f4273c7 2179 vadd d0.s32, d1.s32, d2.s32 */
dcbf9037
JB
2180
2181static int
2182create_neon_reg_alias (char *newname, char *p)
2183{
2184 enum arm_reg_type basetype;
2185 struct reg_entry *basereg;
2186 struct reg_entry mybasereg;
2187 struct neon_type ntype;
2188 struct neon_typed_alias typeinfo;
2189 char *namebuf, *nameend;
2190 int namelen;
5f4273c7 2191
dcbf9037
JB
2192 typeinfo.defined = 0;
2193 typeinfo.eltype.type = NT_invtype;
2194 typeinfo.eltype.size = -1;
2195 typeinfo.index = -1;
5f4273c7 2196
dcbf9037 2197 nameend = p;
5f4273c7 2198
dcbf9037
JB
2199 if (strncmp (p, " .dn ", 5) == 0)
2200 basetype = REG_TYPE_VFD;
2201 else if (strncmp (p, " .qn ", 5) == 0)
2202 basetype = REG_TYPE_NQ;
2203 else
2204 return 0;
5f4273c7 2205
dcbf9037 2206 p += 5;
5f4273c7 2207
dcbf9037
JB
2208 if (*p == '\0')
2209 return 0;
5f4273c7 2210
dcbf9037
JB
2211 basereg = arm_reg_parse_multi (&p);
2212
2213 if (basereg && basereg->type != basetype)
2214 {
2215 as_bad (_("bad type for register"));
2216 return 0;
2217 }
2218
2219 if (basereg == NULL)
2220 {
2221 expressionS exp;
2222 /* Try parsing as an integer. */
2223 my_get_expression (&exp, &p, GE_NO_PREFIX);
2224 if (exp.X_op != O_constant)
2225 {
2226 as_bad (_("expression must be constant"));
2227 return 0;
2228 }
2229 basereg = &mybasereg;
2230 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2231 : exp.X_add_number;
2232 basereg->neon = 0;
2233 }
2234
2235 if (basereg->neon)
2236 typeinfo = *basereg->neon;
2237
2238 if (parse_neon_type (&ntype, &p) == SUCCESS)
2239 {
2240 /* We got a type. */
2241 if (typeinfo.defined & NTA_HASTYPE)
2242 {
2243 as_bad (_("can't redefine the type of a register alias"));
2244 return 0;
2245 }
5f4273c7 2246
dcbf9037
JB
2247 typeinfo.defined |= NTA_HASTYPE;
2248 if (ntype.elems != 1)
2249 {
2250 as_bad (_("you must specify a single type only"));
2251 return 0;
2252 }
2253 typeinfo.eltype = ntype.el[0];
2254 }
5f4273c7 2255
dcbf9037
JB
2256 if (skip_past_char (&p, '[') == SUCCESS)
2257 {
2258 expressionS exp;
2259 /* We got a scalar index. */
5f4273c7 2260
dcbf9037
JB
2261 if (typeinfo.defined & NTA_HASINDEX)
2262 {
2263 as_bad (_("can't redefine the index of a scalar alias"));
2264 return 0;
2265 }
5f4273c7 2266
dcbf9037 2267 my_get_expression (&exp, &p, GE_NO_PREFIX);
5f4273c7 2268
dcbf9037
JB
2269 if (exp.X_op != O_constant)
2270 {
2271 as_bad (_("scalar index must be constant"));
2272 return 0;
2273 }
5f4273c7 2274
dcbf9037
JB
2275 typeinfo.defined |= NTA_HASINDEX;
2276 typeinfo.index = exp.X_add_number;
5f4273c7 2277
dcbf9037
JB
2278 if (skip_past_char (&p, ']') == FAIL)
2279 {
2280 as_bad (_("expecting ]"));
2281 return 0;
2282 }
2283 }
2284
2285 namelen = nameend - newname;
2286 namebuf = alloca (namelen + 1);
2287 strncpy (namebuf, newname, namelen);
2288 namebuf[namelen] = '\0';
5f4273c7 2289
dcbf9037
JB
2290 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2291 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2292
dcbf9037
JB
2293 /* Insert name in all uppercase. */
2294 for (p = namebuf; *p; p++)
2295 *p = TOUPPER (*p);
5f4273c7 2296
dcbf9037
JB
2297 if (strncmp (namebuf, newname, namelen))
2298 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2299 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2300
dcbf9037
JB
2301 /* Insert name in all lowercase. */
2302 for (p = namebuf; *p; p++)
2303 *p = TOLOWER (*p);
5f4273c7 2304
dcbf9037
JB
2305 if (strncmp (namebuf, newname, namelen))
2306 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2307 typeinfo.defined != 0 ? &typeinfo : NULL);
5f4273c7 2308
dcbf9037
JB
2309 return 1;
2310}
2311
c19d1205
ZW
2312/* Should never be called, as .req goes between the alias and the
2313 register name, not at the beginning of the line. */
b99bd4ef 2314static void
c19d1205 2315s_req (int a ATTRIBUTE_UNUSED)
b99bd4ef 2316{
c19d1205
ZW
2317 as_bad (_("invalid syntax for .req directive"));
2318}
b99bd4ef 2319
dcbf9037
JB
2320static void
2321s_dn (int a ATTRIBUTE_UNUSED)
2322{
2323 as_bad (_("invalid syntax for .dn directive"));
2324}
2325
2326static void
2327s_qn (int a ATTRIBUTE_UNUSED)
2328{
2329 as_bad (_("invalid syntax for .qn directive"));
2330}
2331
c19d1205
ZW
2332/* The .unreq directive deletes an alias which was previously defined
2333 by .req. For example:
b99bd4ef 2334
c19d1205
ZW
2335 my_alias .req r11
2336 .unreq my_alias */
b99bd4ef
NC
2337
2338static void
c19d1205 2339s_unreq (int a ATTRIBUTE_UNUSED)
b99bd4ef 2340{
c19d1205
ZW
2341 char * name;
2342 char saved_char;
b99bd4ef 2343
c19d1205
ZW
2344 name = input_line_pointer;
2345
2346 while (*input_line_pointer != 0
2347 && *input_line_pointer != ' '
2348 && *input_line_pointer != '\n')
2349 ++input_line_pointer;
2350
2351 saved_char = *input_line_pointer;
2352 *input_line_pointer = 0;
2353
2354 if (!*name)
2355 as_bad (_("invalid syntax for .unreq directive"));
2356 else
2357 {
2358 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
2359
2360 if (!reg)
2361 as_bad (_("unknown register alias '%s'"), name);
2362 else if (reg->builtin)
2363 as_warn (_("ignoring attempt to undefine built-in register '%s'"),
2364 name);
2365 else
2366 {
d929913e
NC
2367 char * p;
2368 char * nbuf;
2369
db0bc284 2370 hash_delete (arm_reg_hsh, name, FALSE);
c19d1205 2371 free ((char *) reg->name);
dcbf9037
JB
2372 if (reg->neon)
2373 free (reg->neon);
c19d1205 2374 free (reg);
d929913e
NC
2375
2376 /* Also locate the all upper case and all lower case versions.
2377 Do not complain if we cannot find one or the other as it
2378 was probably deleted above. */
5f4273c7 2379
d929913e
NC
2380 nbuf = strdup (name);
2381 for (p = nbuf; *p; p++)
2382 *p = TOUPPER (*p);
2383 reg = hash_find (arm_reg_hsh, nbuf);
2384 if (reg)
2385 {
db0bc284 2386 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2387 free ((char *) reg->name);
2388 if (reg->neon)
2389 free (reg->neon);
2390 free (reg);
2391 }
2392
2393 for (p = nbuf; *p; p++)
2394 *p = TOLOWER (*p);
2395 reg = hash_find (arm_reg_hsh, nbuf);
2396 if (reg)
2397 {
db0bc284 2398 hash_delete (arm_reg_hsh, nbuf, FALSE);
d929913e
NC
2399 free ((char *) reg->name);
2400 if (reg->neon)
2401 free (reg->neon);
2402 free (reg);
2403 }
2404
2405 free (nbuf);
c19d1205
ZW
2406 }
2407 }
b99bd4ef 2408
c19d1205 2409 *input_line_pointer = saved_char;
b99bd4ef
NC
2410 demand_empty_rest_of_line ();
2411}
2412
c19d1205
ZW
2413/* Directives: Instruction set selection. */
2414
2415#ifdef OBJ_ELF
2416/* This code is to handle mapping symbols as defined in the ARM ELF spec.
2417 (See "Mapping symbols", section 4.5.5, ARM AAELF version 1.0).
2418 Note that previously, $a and $t has type STT_FUNC (BSF_OBJECT flag),
2419 and $d has type STT_OBJECT (BSF_OBJECT flag). Now all three are untyped. */
2420
2421static enum mstate mapstate = MAP_UNDEFINED;
b99bd4ef 2422
e821645d 2423void
c19d1205 2424mapping_state (enum mstate state)
b99bd4ef 2425{
a737bd4d 2426 symbolS * symbolP;
c19d1205
ZW
2427 const char * symname;
2428 int type;
b99bd4ef 2429
c19d1205
ZW
2430 if (mapstate == state)
2431 /* The mapping symbol has already been emitted.
2432 There is nothing else to do. */
2433 return;
b99bd4ef 2434
c19d1205 2435 mapstate = state;
b99bd4ef 2436
c19d1205 2437 switch (state)
b99bd4ef 2438 {
c19d1205
ZW
2439 case MAP_DATA:
2440 symname = "$d";
2441 type = BSF_NO_FLAGS;
2442 break;
2443 case MAP_ARM:
2444 symname = "$a";
2445 type = BSF_NO_FLAGS;
2446 break;
2447 case MAP_THUMB:
2448 symname = "$t";
2449 type = BSF_NO_FLAGS;
2450 break;
2451 case MAP_UNDEFINED:
2452 return;
2453 default:
2454 abort ();
2455 }
2456
2457 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
2458
2459 symbolP = symbol_new (symname, now_seg, (valueT) frag_now_fix (), frag_now);
2460 symbol_table_insert (symbolP);
2461 symbol_get_bfdsym (symbolP)->flags |= type | BSF_LOCAL;
2462
2463 switch (state)
2464 {
2465 case MAP_ARM:
2466 THUMB_SET_FUNC (symbolP, 0);
2467 ARM_SET_THUMB (symbolP, 0);
2468 ARM_SET_INTERWORK (symbolP, support_interwork);
2469 break;
2470
2471 case MAP_THUMB:
2472 THUMB_SET_FUNC (symbolP, 1);
2473 ARM_SET_THUMB (symbolP, 1);
2474 ARM_SET_INTERWORK (symbolP, support_interwork);
2475 break;
2476
2477 case MAP_DATA:
2478 default:
2479 return;
2480 }
2481}
2482#else
2483#define mapping_state(x) /* nothing */
2484#endif
2485
2486/* Find the real, Thumb encoded start of a Thumb function. */
2487
4343666d 2488#ifdef OBJ_COFF
c19d1205
ZW
2489static symbolS *
2490find_real_start (symbolS * symbolP)
2491{
2492 char * real_start;
2493 const char * name = S_GET_NAME (symbolP);
2494 symbolS * new_target;
2495
2496 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2497#define STUB_NAME ".real_start_of"
2498
2499 if (name == NULL)
2500 abort ();
2501
37f6032b
ZW
2502 /* The compiler may generate BL instructions to local labels because
2503 it needs to perform a branch to a far away location. These labels
2504 do not have a corresponding ".real_start_of" label. We check
2505 both for S_IS_LOCAL and for a leading dot, to give a way to bypass
2506 the ".real_start_of" convention for nonlocal branches. */
2507 if (S_IS_LOCAL (symbolP) || name[0] == '.')
c19d1205
ZW
2508 return symbolP;
2509
37f6032b 2510 real_start = ACONCAT ((STUB_NAME, name, NULL));
c19d1205
ZW
2511 new_target = symbol_find (real_start);
2512
2513 if (new_target == NULL)
2514 {
bd3ba5d1 2515 as_warn (_("Failed to find real start of function: %s\n"), name);
c19d1205
ZW
2516 new_target = symbolP;
2517 }
2518
c19d1205
ZW
2519 return new_target;
2520}
4343666d 2521#endif
c19d1205
ZW
2522
2523static void
2524opcode_select (int width)
2525{
2526 switch (width)
2527 {
2528 case 16:
2529 if (! thumb_mode)
2530 {
e74cfd16 2531 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
c19d1205
ZW
2532 as_bad (_("selected processor does not support THUMB opcodes"));
2533
2534 thumb_mode = 1;
2535 /* No need to force the alignment, since we will have been
2536 coming from ARM mode, which is word-aligned. */
2537 record_alignment (now_seg, 1);
2538 }
2539 mapping_state (MAP_THUMB);
2540 break;
2541
2542 case 32:
2543 if (thumb_mode)
2544 {
e74cfd16 2545 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205
ZW
2546 as_bad (_("selected processor does not support ARM opcodes"));
2547
2548 thumb_mode = 0;
2549
2550 if (!need_pass_2)
2551 frag_align (2, 0, 0);
2552
2553 record_alignment (now_seg, 1);
2554 }
2555 mapping_state (MAP_ARM);
2556 break;
2557
2558 default:
2559 as_bad (_("invalid instruction size selected (%d)"), width);
2560 }
2561}
2562
2563static void
2564s_arm (int ignore ATTRIBUTE_UNUSED)
2565{
2566 opcode_select (32);
2567 demand_empty_rest_of_line ();
2568}
2569
2570static void
2571s_thumb (int ignore ATTRIBUTE_UNUSED)
2572{
2573 opcode_select (16);
2574 demand_empty_rest_of_line ();
2575}
2576
2577static void
2578s_code (int unused ATTRIBUTE_UNUSED)
2579{
2580 int temp;
2581
2582 temp = get_absolute_expression ();
2583 switch (temp)
2584 {
2585 case 16:
2586 case 32:
2587 opcode_select (temp);
2588 break;
2589
2590 default:
2591 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2592 }
2593}
2594
2595static void
2596s_force_thumb (int ignore ATTRIBUTE_UNUSED)
2597{
2598 /* If we are not already in thumb mode go into it, EVEN if
2599 the target processor does not support thumb instructions.
2600 This is used by gcc/config/arm/lib1funcs.asm for example
2601 to compile interworking support functions even if the
2602 target processor should not support interworking. */
2603 if (! thumb_mode)
2604 {
2605 thumb_mode = 2;
2606 record_alignment (now_seg, 1);
2607 }
2608
2609 demand_empty_rest_of_line ();
2610}
2611
2612static void
2613s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2614{
2615 s_thumb (0);
2616
2617 /* The following label is the name/address of the start of a Thumb function.
2618 We need to know this for the interworking support. */
2619 label_is_thumb_function_name = TRUE;
2620}
2621
2622/* Perform a .set directive, but also mark the alias as
2623 being a thumb function. */
2624
2625static void
2626s_thumb_set (int equiv)
2627{
2628 /* XXX the following is a duplicate of the code for s_set() in read.c
2629 We cannot just call that code as we need to get at the symbol that
2630 is created. */
2631 char * name;
2632 char delim;
2633 char * end_name;
2634 symbolS * symbolP;
2635
2636 /* Especial apologies for the random logic:
2637 This just grew, and could be parsed much more simply!
2638 Dean - in haste. */
2639 name = input_line_pointer;
2640 delim = get_symbol_end ();
2641 end_name = input_line_pointer;
2642 *end_name = delim;
2643
2644 if (*input_line_pointer != ',')
2645 {
2646 *end_name = 0;
2647 as_bad (_("expected comma after name \"%s\""), name);
b99bd4ef
NC
2648 *end_name = delim;
2649 ignore_rest_of_line ();
2650 return;
2651 }
2652
2653 input_line_pointer++;
2654 *end_name = 0;
2655
2656 if (name[0] == '.' && name[1] == '\0')
2657 {
2658 /* XXX - this should not happen to .thumb_set. */
2659 abort ();
2660 }
2661
2662 if ((symbolP = symbol_find (name)) == NULL
2663 && (symbolP = md_undefined_symbol (name)) == NULL)
2664 {
2665#ifndef NO_LISTING
2666 /* When doing symbol listings, play games with dummy fragments living
2667 outside the normal fragment chain to record the file and line info
c19d1205 2668 for this symbol. */
b99bd4ef
NC
2669 if (listing & LISTING_SYMBOLS)
2670 {
2671 extern struct list_info_struct * listing_tail;
a737bd4d 2672 fragS * dummy_frag = xmalloc (sizeof (fragS));
b99bd4ef
NC
2673
2674 memset (dummy_frag, 0, sizeof (fragS));
2675 dummy_frag->fr_type = rs_fill;
2676 dummy_frag->line = listing_tail;
2677 symbolP = symbol_new (name, undefined_section, 0, dummy_frag);
2678 dummy_frag->fr_symbol = symbolP;
2679 }
2680 else
2681#endif
2682 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
2683
2684#ifdef OBJ_COFF
2685 /* "set" symbols are local unless otherwise specified. */
2686 SF_SET_LOCAL (symbolP);
2687#endif /* OBJ_COFF */
2688 } /* Make a new symbol. */
2689
2690 symbol_table_insert (symbolP);
2691
2692 * end_name = delim;
2693
2694 if (equiv
2695 && S_IS_DEFINED (symbolP)
2696 && S_GET_SEGMENT (symbolP) != reg_section)
2697 as_bad (_("symbol `%s' already defined"), S_GET_NAME (symbolP));
2698
2699 pseudo_set (symbolP);
2700
2701 demand_empty_rest_of_line ();
2702
c19d1205 2703 /* XXX Now we come to the Thumb specific bit of code. */
b99bd4ef
NC
2704
2705 THUMB_SET_FUNC (symbolP, 1);
2706 ARM_SET_THUMB (symbolP, 1);
2707#if defined OBJ_ELF || defined OBJ_COFF
2708 ARM_SET_INTERWORK (symbolP, support_interwork);
2709#endif
2710}
2711
c19d1205 2712/* Directives: Mode selection. */
b99bd4ef 2713
c19d1205
ZW
2714/* .syntax [unified|divided] - choose the new unified syntax
2715 (same for Arm and Thumb encoding, modulo slight differences in what
2716 can be represented) or the old divergent syntax for each mode. */
b99bd4ef 2717static void
c19d1205 2718s_syntax (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2719{
c19d1205
ZW
2720 char *name, delim;
2721
2722 name = input_line_pointer;
2723 delim = get_symbol_end ();
2724
2725 if (!strcasecmp (name, "unified"))
2726 unified_syntax = TRUE;
2727 else if (!strcasecmp (name, "divided"))
2728 unified_syntax = FALSE;
2729 else
2730 {
2731 as_bad (_("unrecognized syntax mode \"%s\""), name);
2732 return;
2733 }
2734 *input_line_pointer = delim;
b99bd4ef
NC
2735 demand_empty_rest_of_line ();
2736}
2737
c19d1205
ZW
2738/* Directives: sectioning and alignment. */
2739
2740/* Same as s_align_ptwo but align 0 => align 2. */
2741
b99bd4ef 2742static void
c19d1205 2743s_align (int unused ATTRIBUTE_UNUSED)
b99bd4ef 2744{
a737bd4d 2745 int temp;
dce323d1 2746 bfd_boolean fill_p;
c19d1205
ZW
2747 long temp_fill;
2748 long max_alignment = 15;
b99bd4ef
NC
2749
2750 temp = get_absolute_expression ();
c19d1205
ZW
2751 if (temp > max_alignment)
2752 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2753 else if (temp < 0)
b99bd4ef 2754 {
c19d1205
ZW
2755 as_bad (_("alignment negative. 0 assumed."));
2756 temp = 0;
2757 }
b99bd4ef 2758
c19d1205
ZW
2759 if (*input_line_pointer == ',')
2760 {
2761 input_line_pointer++;
2762 temp_fill = get_absolute_expression ();
dce323d1 2763 fill_p = TRUE;
b99bd4ef 2764 }
c19d1205 2765 else
dce323d1
PB
2766 {
2767 fill_p = FALSE;
2768 temp_fill = 0;
2769 }
b99bd4ef 2770
c19d1205
ZW
2771 if (!temp)
2772 temp = 2;
b99bd4ef 2773
c19d1205
ZW
2774 /* Only make a frag if we HAVE to. */
2775 if (temp && !need_pass_2)
dce323d1
PB
2776 {
2777 if (!fill_p && subseg_text_p (now_seg))
2778 frag_align_code (temp, 0);
2779 else
2780 frag_align (temp, (int) temp_fill, 0);
2781 }
c19d1205
ZW
2782 demand_empty_rest_of_line ();
2783
2784 record_alignment (now_seg, temp);
b99bd4ef
NC
2785}
2786
c19d1205
ZW
2787static void
2788s_bss (int ignore ATTRIBUTE_UNUSED)
b99bd4ef 2789{
c19d1205
ZW
2790 /* We don't support putting frags in the BSS segment, we fake it by
2791 marking in_bss, then looking at s_skip for clues. */
2792 subseg_set (bss_section, 0);
2793 demand_empty_rest_of_line ();
2794 mapping_state (MAP_DATA);
2795}
b99bd4ef 2796
c19d1205
ZW
2797static void
2798s_even (int ignore ATTRIBUTE_UNUSED)
2799{
2800 /* Never make frag if expect extra pass. */
2801 if (!need_pass_2)
2802 frag_align (1, 0, 0);
b99bd4ef 2803
c19d1205 2804 record_alignment (now_seg, 1);
b99bd4ef 2805
c19d1205 2806 demand_empty_rest_of_line ();
b99bd4ef
NC
2807}
2808
c19d1205 2809/* Directives: Literal pools. */
a737bd4d 2810
c19d1205
ZW
2811static literal_pool *
2812find_literal_pool (void)
a737bd4d 2813{
c19d1205 2814 literal_pool * pool;
a737bd4d 2815
c19d1205 2816 for (pool = list_of_pools; pool != NULL; pool = pool->next)
a737bd4d 2817 {
c19d1205
ZW
2818 if (pool->section == now_seg
2819 && pool->sub_section == now_subseg)
2820 break;
a737bd4d
NC
2821 }
2822
c19d1205 2823 return pool;
a737bd4d
NC
2824}
2825
c19d1205
ZW
2826static literal_pool *
2827find_or_make_literal_pool (void)
a737bd4d 2828{
c19d1205
ZW
2829 /* Next literal pool ID number. */
2830 static unsigned int latest_pool_num = 1;
2831 literal_pool * pool;
a737bd4d 2832
c19d1205 2833 pool = find_literal_pool ();
a737bd4d 2834
c19d1205 2835 if (pool == NULL)
a737bd4d 2836 {
c19d1205
ZW
2837 /* Create a new pool. */
2838 pool = xmalloc (sizeof (* pool));
2839 if (! pool)
2840 return NULL;
a737bd4d 2841
c19d1205
ZW
2842 pool->next_free_entry = 0;
2843 pool->section = now_seg;
2844 pool->sub_section = now_subseg;
2845 pool->next = list_of_pools;
2846 pool->symbol = NULL;
2847
2848 /* Add it to the list. */
2849 list_of_pools = pool;
a737bd4d 2850 }
a737bd4d 2851
c19d1205
ZW
2852 /* New pools, and emptied pools, will have a NULL symbol. */
2853 if (pool->symbol == NULL)
a737bd4d 2854 {
c19d1205
ZW
2855 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2856 (valueT) 0, &zero_address_frag);
2857 pool->id = latest_pool_num ++;
a737bd4d
NC
2858 }
2859
c19d1205
ZW
2860 /* Done. */
2861 return pool;
a737bd4d
NC
2862}
2863
c19d1205 2864/* Add the literal in the global 'inst'
5f4273c7 2865 structure to the relevant literal pool. */
b99bd4ef
NC
2866
2867static int
c19d1205 2868add_to_lit_pool (void)
b99bd4ef 2869{
c19d1205
ZW
2870 literal_pool * pool;
2871 unsigned int entry;
b99bd4ef 2872
c19d1205
ZW
2873 pool = find_or_make_literal_pool ();
2874
2875 /* Check if this literal value is already in the pool. */
2876 for (entry = 0; entry < pool->next_free_entry; entry ++)
b99bd4ef 2877 {
c19d1205
ZW
2878 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2879 && (inst.reloc.exp.X_op == O_constant)
2880 && (pool->literals[entry].X_add_number
2881 == inst.reloc.exp.X_add_number)
2882 && (pool->literals[entry].X_unsigned
2883 == inst.reloc.exp.X_unsigned))
2884 break;
2885
2886 if ((pool->literals[entry].X_op == inst.reloc.exp.X_op)
2887 && (inst.reloc.exp.X_op == O_symbol)
2888 && (pool->literals[entry].X_add_number
2889 == inst.reloc.exp.X_add_number)
2890 && (pool->literals[entry].X_add_symbol
2891 == inst.reloc.exp.X_add_symbol)
2892 && (pool->literals[entry].X_op_symbol
2893 == inst.reloc.exp.X_op_symbol))
2894 break;
b99bd4ef
NC
2895 }
2896
c19d1205
ZW
2897 /* Do we need to create a new entry? */
2898 if (entry == pool->next_free_entry)
2899 {
2900 if (entry >= MAX_LITERAL_POOL_SIZE)
2901 {
2902 inst.error = _("literal pool overflow");
2903 return FAIL;
2904 }
2905
2906 pool->literals[entry] = inst.reloc.exp;
2907 pool->next_free_entry += 1;
2908 }
b99bd4ef 2909
c19d1205
ZW
2910 inst.reloc.exp.X_op = O_symbol;
2911 inst.reloc.exp.X_add_number = ((int) entry) * 4;
2912 inst.reloc.exp.X_add_symbol = pool->symbol;
b99bd4ef 2913
c19d1205 2914 return SUCCESS;
b99bd4ef
NC
2915}
2916
c19d1205
ZW
2917/* Can't use symbol_new here, so have to create a symbol and then at
2918 a later date assign it a value. Thats what these functions do. */
e16bb312 2919
c19d1205
ZW
2920static void
2921symbol_locate (symbolS * symbolP,
2922 const char * name, /* It is copied, the caller can modify. */
2923 segT segment, /* Segment identifier (SEG_<something>). */
2924 valueT valu, /* Symbol value. */
2925 fragS * frag) /* Associated fragment. */
2926{
2927 unsigned int name_length;
2928 char * preserved_copy_of_name;
e16bb312 2929
c19d1205
ZW
2930 name_length = strlen (name) + 1; /* +1 for \0. */
2931 obstack_grow (&notes, name, name_length);
2932 preserved_copy_of_name = obstack_finish (&notes);
e16bb312 2933
c19d1205
ZW
2934#ifdef tc_canonicalize_symbol_name
2935 preserved_copy_of_name =
2936 tc_canonicalize_symbol_name (preserved_copy_of_name);
2937#endif
b99bd4ef 2938
c19d1205 2939 S_SET_NAME (symbolP, preserved_copy_of_name);
b99bd4ef 2940
c19d1205
ZW
2941 S_SET_SEGMENT (symbolP, segment);
2942 S_SET_VALUE (symbolP, valu);
2943 symbol_clear_list_pointers (symbolP);
b99bd4ef 2944
c19d1205 2945 symbol_set_frag (symbolP, frag);
b99bd4ef 2946
c19d1205
ZW
2947 /* Link to end of symbol chain. */
2948 {
2949 extern int symbol_table_frozen;
b99bd4ef 2950
c19d1205
ZW
2951 if (symbol_table_frozen)
2952 abort ();
2953 }
b99bd4ef 2954
c19d1205 2955 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
b99bd4ef 2956
c19d1205 2957 obj_symbol_new_hook (symbolP);
b99bd4ef 2958
c19d1205
ZW
2959#ifdef tc_symbol_new_hook
2960 tc_symbol_new_hook (symbolP);
2961#endif
2962
2963#ifdef DEBUG_SYMS
2964 verify_symbol_chain (symbol_rootP, symbol_lastP);
2965#endif /* DEBUG_SYMS */
b99bd4ef
NC
2966}
2967
b99bd4ef 2968
c19d1205
ZW
2969static void
2970s_ltorg (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 2971{
c19d1205
ZW
2972 unsigned int entry;
2973 literal_pool * pool;
2974 char sym_name[20];
b99bd4ef 2975
c19d1205
ZW
2976 pool = find_literal_pool ();
2977 if (pool == NULL
2978 || pool->symbol == NULL
2979 || pool->next_free_entry == 0)
2980 return;
b99bd4ef 2981
c19d1205 2982 mapping_state (MAP_DATA);
b99bd4ef 2983
c19d1205
ZW
2984 /* Align pool as you have word accesses.
2985 Only make a frag if we have to. */
2986 if (!need_pass_2)
2987 frag_align (2, 0, 0);
b99bd4ef 2988
c19d1205 2989 record_alignment (now_seg, 2);
b99bd4ef 2990
c19d1205 2991 sprintf (sym_name, "$$lit_\002%x", pool->id);
b99bd4ef 2992
c19d1205
ZW
2993 symbol_locate (pool->symbol, sym_name, now_seg,
2994 (valueT) frag_now_fix (), frag_now);
2995 symbol_table_insert (pool->symbol);
b99bd4ef 2996
c19d1205 2997 ARM_SET_THUMB (pool->symbol, thumb_mode);
b99bd4ef 2998
c19d1205
ZW
2999#if defined OBJ_COFF || defined OBJ_ELF
3000 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3001#endif
6c43fab6 3002
c19d1205
ZW
3003 for (entry = 0; entry < pool->next_free_entry; entry ++)
3004 /* First output the expression in the instruction to the pool. */
3005 emit_expr (&(pool->literals[entry]), 4); /* .word */
b99bd4ef 3006
c19d1205
ZW
3007 /* Mark the pool as empty. */
3008 pool->next_free_entry = 0;
3009 pool->symbol = NULL;
b99bd4ef
NC
3010}
3011
c19d1205
ZW
3012#ifdef OBJ_ELF
3013/* Forward declarations for functions below, in the MD interface
3014 section. */
3015static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3016static valueT create_unwind_entry (int);
3017static void start_unwind_section (const segT, int);
3018static void add_unwind_opcode (valueT, int);
3019static void flush_pending_unwind (void);
b99bd4ef 3020
c19d1205 3021/* Directives: Data. */
b99bd4ef 3022
c19d1205
ZW
3023static void
3024s_arm_elf_cons (int nbytes)
3025{
3026 expressionS exp;
b99bd4ef 3027
c19d1205
ZW
3028#ifdef md_flush_pending_output
3029 md_flush_pending_output ();
3030#endif
b99bd4ef 3031
c19d1205 3032 if (is_it_end_of_statement ())
b99bd4ef 3033 {
c19d1205
ZW
3034 demand_empty_rest_of_line ();
3035 return;
b99bd4ef
NC
3036 }
3037
c19d1205
ZW
3038#ifdef md_cons_align
3039 md_cons_align (nbytes);
3040#endif
b99bd4ef 3041
c19d1205
ZW
3042 mapping_state (MAP_DATA);
3043 do
b99bd4ef 3044 {
c19d1205
ZW
3045 int reloc;
3046 char *base = input_line_pointer;
b99bd4ef 3047
c19d1205 3048 expression (& exp);
b99bd4ef 3049
c19d1205
ZW
3050 if (exp.X_op != O_symbol)
3051 emit_expr (&exp, (unsigned int) nbytes);
3052 else
3053 {
3054 char *before_reloc = input_line_pointer;
3055 reloc = parse_reloc (&input_line_pointer);
3056 if (reloc == -1)
3057 {
3058 as_bad (_("unrecognized relocation suffix"));
3059 ignore_rest_of_line ();
3060 return;
3061 }
3062 else if (reloc == BFD_RELOC_UNUSED)
3063 emit_expr (&exp, (unsigned int) nbytes);
3064 else
3065 {
3066 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
3067 int size = bfd_get_reloc_size (howto);
b99bd4ef 3068
2fc8bdac
ZW
3069 if (reloc == BFD_RELOC_ARM_PLT32)
3070 {
3071 as_bad (_("(plt) is only valid on branch targets"));
3072 reloc = BFD_RELOC_UNUSED;
3073 size = 0;
3074 }
3075
c19d1205 3076 if (size > nbytes)
2fc8bdac 3077 as_bad (_("%s relocations do not fit in %d bytes"),
c19d1205
ZW
3078 howto->name, nbytes);
3079 else
3080 {
3081 /* We've parsed an expression stopping at O_symbol.
3082 But there may be more expression left now that we
3083 have parsed the relocation marker. Parse it again.
3084 XXX Surely there is a cleaner way to do this. */
3085 char *p = input_line_pointer;
3086 int offset;
3087 char *save_buf = alloca (input_line_pointer - base);
3088 memcpy (save_buf, base, input_line_pointer - base);
3089 memmove (base + (input_line_pointer - before_reloc),
3090 base, before_reloc - base);
3091
3092 input_line_pointer = base + (input_line_pointer-before_reloc);
3093 expression (&exp);
3094 memcpy (base, save_buf, p - base);
3095
3096 offset = nbytes - size;
3097 p = frag_more ((int) nbytes);
3098 fix_new_exp (frag_now, p - frag_now->fr_literal + offset,
3099 size, &exp, 0, reloc);
3100 }
3101 }
3102 }
b99bd4ef 3103 }
c19d1205 3104 while (*input_line_pointer++ == ',');
b99bd4ef 3105
c19d1205
ZW
3106 /* Put terminator back into stream. */
3107 input_line_pointer --;
3108 demand_empty_rest_of_line ();
b99bd4ef
NC
3109}
3110
b99bd4ef 3111
c19d1205 3112/* Parse a .rel31 directive. */
b99bd4ef 3113
c19d1205
ZW
3114static void
3115s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3116{
3117 expressionS exp;
3118 char *p;
3119 valueT highbit;
b99bd4ef 3120
c19d1205
ZW
3121 highbit = 0;
3122 if (*input_line_pointer == '1')
3123 highbit = 0x80000000;
3124 else if (*input_line_pointer != '0')
3125 as_bad (_("expected 0 or 1"));
b99bd4ef 3126
c19d1205
ZW
3127 input_line_pointer++;
3128 if (*input_line_pointer != ',')
3129 as_bad (_("missing comma"));
3130 input_line_pointer++;
b99bd4ef 3131
c19d1205
ZW
3132#ifdef md_flush_pending_output
3133 md_flush_pending_output ();
3134#endif
b99bd4ef 3135
c19d1205
ZW
3136#ifdef md_cons_align
3137 md_cons_align (4);
3138#endif
b99bd4ef 3139
c19d1205 3140 mapping_state (MAP_DATA);
b99bd4ef 3141
c19d1205 3142 expression (&exp);
b99bd4ef 3143
c19d1205
ZW
3144 p = frag_more (4);
3145 md_number_to_chars (p, highbit, 4);
3146 fix_new_arm (frag_now, p - frag_now->fr_literal, 4, &exp, 1,
3147 BFD_RELOC_ARM_PREL31);
b99bd4ef 3148
c19d1205 3149 demand_empty_rest_of_line ();
b99bd4ef
NC
3150}
3151
c19d1205 3152/* Directives: AEABI stack-unwind tables. */
b99bd4ef 3153
c19d1205 3154/* Parse an unwind_fnstart directive. Simply records the current location. */
b99bd4ef 3155
c19d1205
ZW
3156static void
3157s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3158{
3159 demand_empty_rest_of_line ();
921e5f0a
PB
3160 if (unwind.proc_start)
3161 {
3162 as_bad(_("duplicate .fnstart directive"));
3163 return;
3164 }
3165
c19d1205
ZW
3166 /* Mark the start of the function. */
3167 unwind.proc_start = expr_build_dot ();
b99bd4ef 3168
c19d1205
ZW
3169 /* Reset the rest of the unwind info. */
3170 unwind.opcode_count = 0;
3171 unwind.table_entry = NULL;
3172 unwind.personality_routine = NULL;
3173 unwind.personality_index = -1;
3174 unwind.frame_size = 0;
3175 unwind.fp_offset = 0;
fdfde340 3176 unwind.fp_reg = REG_SP;
c19d1205
ZW
3177 unwind.fp_used = 0;
3178 unwind.sp_restored = 0;
3179}
b99bd4ef 3180
b99bd4ef 3181
c19d1205
ZW
3182/* Parse a handlerdata directive. Creates the exception handling table entry
3183 for the function. */
b99bd4ef 3184
c19d1205
ZW
3185static void
3186s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3187{
3188 demand_empty_rest_of_line ();
921e5f0a
PB
3189 if (!unwind.proc_start)
3190 as_bad(MISSING_FNSTART);
3191
c19d1205 3192 if (unwind.table_entry)
6decc662 3193 as_bad (_("duplicate .handlerdata directive"));
f02232aa 3194
c19d1205
ZW
3195 create_unwind_entry (1);
3196}
a737bd4d 3197
c19d1205 3198/* Parse an unwind_fnend directive. Generates the index table entry. */
b99bd4ef 3199
c19d1205
ZW
3200static void
3201s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3202{
3203 long where;
3204 char *ptr;
3205 valueT val;
f02232aa 3206
c19d1205 3207 demand_empty_rest_of_line ();
f02232aa 3208
921e5f0a
PB
3209 if (!unwind.proc_start)
3210 {
3211 as_bad(_(".fnend directive without .fnstart"));
3212 return;
3213 }
3214
c19d1205
ZW
3215 /* Add eh table entry. */
3216 if (unwind.table_entry == NULL)
3217 val = create_unwind_entry (0);
3218 else
3219 val = 0;
f02232aa 3220
c19d1205
ZW
3221 /* Add index table entry. This is two words. */
3222 start_unwind_section (unwind.saved_seg, 1);
3223 frag_align (2, 0, 0);
3224 record_alignment (now_seg, 2);
b99bd4ef 3225
c19d1205
ZW
3226 ptr = frag_more (8);
3227 where = frag_now_fix () - 8;
f02232aa 3228
c19d1205
ZW
3229 /* Self relative offset of the function start. */
3230 fix_new (frag_now, where, 4, unwind.proc_start, 0, 1,
3231 BFD_RELOC_ARM_PREL31);
f02232aa 3232
c19d1205
ZW
3233 /* Indicate dependency on EHABI-defined personality routines to the
3234 linker, if it hasn't been done already. */
3235 if (unwind.personality_index >= 0 && unwind.personality_index < 3
3236 && !(marked_pr_dependency & (1 << unwind.personality_index)))
3237 {
5f4273c7
NC
3238 static const char *const name[] =
3239 {
3240 "__aeabi_unwind_cpp_pr0",
3241 "__aeabi_unwind_cpp_pr1",
3242 "__aeabi_unwind_cpp_pr2"
3243 };
c19d1205
ZW
3244 symbolS *pr = symbol_find_or_make (name[unwind.personality_index]);
3245 fix_new (frag_now, where, 0, pr, 0, 1, BFD_RELOC_NONE);
3246 marked_pr_dependency |= 1 << unwind.personality_index;
3247 seg_info (now_seg)->tc_segment_info_data.marked_pr_dependency
3248 = marked_pr_dependency;
3249 }
f02232aa 3250
c19d1205
ZW
3251 if (val)
3252 /* Inline exception table entry. */
3253 md_number_to_chars (ptr + 4, val, 4);
3254 else
3255 /* Self relative offset of the table entry. */
3256 fix_new (frag_now, where + 4, 4, unwind.table_entry, 0, 1,
3257 BFD_RELOC_ARM_PREL31);
f02232aa 3258
c19d1205
ZW
3259 /* Restore the original section. */
3260 subseg_set (unwind.saved_seg, unwind.saved_subseg);
921e5f0a
PB
3261
3262 unwind.proc_start = NULL;
c19d1205 3263}
f02232aa 3264
f02232aa 3265
c19d1205 3266/* Parse an unwind_cantunwind directive. */
b99bd4ef 3267
c19d1205
ZW
3268static void
3269s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3270{
3271 demand_empty_rest_of_line ();
921e5f0a
PB
3272 if (!unwind.proc_start)
3273 as_bad(MISSING_FNSTART);
3274
c19d1205
ZW
3275 if (unwind.personality_routine || unwind.personality_index != -1)
3276 as_bad (_("personality routine specified for cantunwind frame"));
b99bd4ef 3277
c19d1205
ZW
3278 unwind.personality_index = -2;
3279}
b99bd4ef 3280
b99bd4ef 3281
c19d1205 3282/* Parse a personalityindex directive. */
b99bd4ef 3283
c19d1205
ZW
3284static void
3285s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3286{
3287 expressionS exp;
b99bd4ef 3288
921e5f0a
PB
3289 if (!unwind.proc_start)
3290 as_bad(MISSING_FNSTART);
3291
c19d1205
ZW
3292 if (unwind.personality_routine || unwind.personality_index != -1)
3293 as_bad (_("duplicate .personalityindex directive"));
b99bd4ef 3294
c19d1205 3295 expression (&exp);
b99bd4ef 3296
c19d1205
ZW
3297 if (exp.X_op != O_constant
3298 || exp.X_add_number < 0 || exp.X_add_number > 15)
b99bd4ef 3299 {
c19d1205
ZW
3300 as_bad (_("bad personality routine number"));
3301 ignore_rest_of_line ();
3302 return;
b99bd4ef
NC
3303 }
3304
c19d1205 3305 unwind.personality_index = exp.X_add_number;
b99bd4ef 3306
c19d1205
ZW
3307 demand_empty_rest_of_line ();
3308}
e16bb312 3309
e16bb312 3310
c19d1205 3311/* Parse a personality directive. */
e16bb312 3312
c19d1205
ZW
3313static void
3314s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3315{
3316 char *name, *p, c;
a737bd4d 3317
921e5f0a
PB
3318 if (!unwind.proc_start)
3319 as_bad(MISSING_FNSTART);
3320
c19d1205
ZW
3321 if (unwind.personality_routine || unwind.personality_index != -1)
3322 as_bad (_("duplicate .personality directive"));
a737bd4d 3323
c19d1205
ZW
3324 name = input_line_pointer;
3325 c = get_symbol_end ();
3326 p = input_line_pointer;
3327 unwind.personality_routine = symbol_find_or_make (name);
3328 *p = c;
3329 demand_empty_rest_of_line ();
3330}
e16bb312 3331
e16bb312 3332
c19d1205 3333/* Parse a directive saving core registers. */
e16bb312 3334
c19d1205
ZW
3335static void
3336s_arm_unwind_save_core (void)
e16bb312 3337{
c19d1205
ZW
3338 valueT op;
3339 long range;
3340 int n;
e16bb312 3341
c19d1205
ZW
3342 range = parse_reg_list (&input_line_pointer);
3343 if (range == FAIL)
e16bb312 3344 {
c19d1205
ZW
3345 as_bad (_("expected register list"));
3346 ignore_rest_of_line ();
3347 return;
3348 }
e16bb312 3349
c19d1205 3350 demand_empty_rest_of_line ();
e16bb312 3351
c19d1205
ZW
3352 /* Turn .unwind_movsp ip followed by .unwind_save {..., ip, ...}
3353 into .unwind_save {..., sp...}. We aren't bothered about the value of
3354 ip because it is clobbered by calls. */
3355 if (unwind.sp_restored && unwind.fp_reg == 12
3356 && (range & 0x3000) == 0x1000)
3357 {
3358 unwind.opcode_count--;
3359 unwind.sp_restored = 0;
3360 range = (range | 0x2000) & ~0x1000;
3361 unwind.pending_offset = 0;
3362 }
e16bb312 3363
01ae4198
DJ
3364 /* Pop r4-r15. */
3365 if (range & 0xfff0)
c19d1205 3366 {
01ae4198
DJ
3367 /* See if we can use the short opcodes. These pop a block of up to 8
3368 registers starting with r4, plus maybe r14. */
3369 for (n = 0; n < 8; n++)
3370 {
3371 /* Break at the first non-saved register. */
3372 if ((range & (1 << (n + 4))) == 0)
3373 break;
3374 }
3375 /* See if there are any other bits set. */
3376 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3377 {
3378 /* Use the long form. */
3379 op = 0x8000 | ((range >> 4) & 0xfff);
3380 add_unwind_opcode (op, 2);
3381 }
0dd132b6 3382 else
01ae4198
DJ
3383 {
3384 /* Use the short form. */
3385 if (range & 0x4000)
3386 op = 0xa8; /* Pop r14. */
3387 else
3388 op = 0xa0; /* Do not pop r14. */
3389 op |= (n - 1);
3390 add_unwind_opcode (op, 1);
3391 }
c19d1205 3392 }
0dd132b6 3393
c19d1205
ZW
3394 /* Pop r0-r3. */
3395 if (range & 0xf)
3396 {
3397 op = 0xb100 | (range & 0xf);
3398 add_unwind_opcode (op, 2);
0dd132b6
NC
3399 }
3400
c19d1205
ZW
3401 /* Record the number of bytes pushed. */
3402 for (n = 0; n < 16; n++)
3403 {
3404 if (range & (1 << n))
3405 unwind.frame_size += 4;
3406 }
0dd132b6
NC
3407}
3408
c19d1205
ZW
3409
3410/* Parse a directive saving FPA registers. */
b99bd4ef
NC
3411
3412static void
c19d1205 3413s_arm_unwind_save_fpa (int reg)
b99bd4ef 3414{
c19d1205
ZW
3415 expressionS exp;
3416 int num_regs;
3417 valueT op;
b99bd4ef 3418
c19d1205
ZW
3419 /* Get Number of registers to transfer. */
3420 if (skip_past_comma (&input_line_pointer) != FAIL)
3421 expression (&exp);
3422 else
3423 exp.X_op = O_illegal;
b99bd4ef 3424
c19d1205 3425 if (exp.X_op != O_constant)
b99bd4ef 3426 {
c19d1205
ZW
3427 as_bad (_("expected , <constant>"));
3428 ignore_rest_of_line ();
b99bd4ef
NC
3429 return;
3430 }
3431
c19d1205
ZW
3432 num_regs = exp.X_add_number;
3433
3434 if (num_regs < 1 || num_regs > 4)
b99bd4ef 3435 {
c19d1205
ZW
3436 as_bad (_("number of registers must be in the range [1:4]"));
3437 ignore_rest_of_line ();
b99bd4ef
NC
3438 return;
3439 }
3440
c19d1205 3441 demand_empty_rest_of_line ();
b99bd4ef 3442
c19d1205
ZW
3443 if (reg == 4)
3444 {
3445 /* Short form. */
3446 op = 0xb4 | (num_regs - 1);
3447 add_unwind_opcode (op, 1);
3448 }
b99bd4ef
NC
3449 else
3450 {
c19d1205
ZW
3451 /* Long form. */
3452 op = 0xc800 | (reg << 4) | (num_regs - 1);
3453 add_unwind_opcode (op, 2);
b99bd4ef 3454 }
c19d1205 3455 unwind.frame_size += num_regs * 12;
b99bd4ef
NC
3456}
3457
c19d1205 3458
fa073d69
MS
3459/* Parse a directive saving VFP registers for ARMv6 and above. */
3460
3461static void
3462s_arm_unwind_save_vfp_armv6 (void)
3463{
3464 int count;
3465 unsigned int start;
3466 valueT op;
3467 int num_vfpv3_regs = 0;
3468 int num_regs_below_16;
3469
3470 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3471 if (count == FAIL)
3472 {
3473 as_bad (_("expected register list"));
3474 ignore_rest_of_line ();
3475 return;
3476 }
3477
3478 demand_empty_rest_of_line ();
3479
3480 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3481 than FSTMX/FLDMX-style ones). */
3482
3483 /* Generate opcode for (VFPv3) registers numbered in the range 16 .. 31. */
3484 if (start >= 16)
3485 num_vfpv3_regs = count;
3486 else if (start + count > 16)
3487 num_vfpv3_regs = start + count - 16;
3488
3489 if (num_vfpv3_regs > 0)
3490 {
3491 int start_offset = start > 16 ? start - 16 : 0;
3492 op = 0xc800 | (start_offset << 4) | (num_vfpv3_regs - 1);
3493 add_unwind_opcode (op, 2);
3494 }
3495
3496 /* Generate opcode for registers numbered in the range 0 .. 15. */
3497 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
9c2799c2 3498 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
fa073d69
MS
3499 if (num_regs_below_16 > 0)
3500 {
3501 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3502 add_unwind_opcode (op, 2);
3503 }
3504
3505 unwind.frame_size += count * 8;
3506}
3507
3508
3509/* Parse a directive saving VFP registers for pre-ARMv6. */
b99bd4ef
NC
3510
3511static void
c19d1205 3512s_arm_unwind_save_vfp (void)
b99bd4ef 3513{
c19d1205 3514 int count;
ca3f61f7 3515 unsigned int reg;
c19d1205 3516 valueT op;
b99bd4ef 3517
5287ad62 3518 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
c19d1205 3519 if (count == FAIL)
b99bd4ef 3520 {
c19d1205
ZW
3521 as_bad (_("expected register list"));
3522 ignore_rest_of_line ();
b99bd4ef
NC
3523 return;
3524 }
3525
c19d1205 3526 demand_empty_rest_of_line ();
b99bd4ef 3527
c19d1205 3528 if (reg == 8)
b99bd4ef 3529 {
c19d1205
ZW
3530 /* Short form. */
3531 op = 0xb8 | (count - 1);
3532 add_unwind_opcode (op, 1);
b99bd4ef 3533 }
c19d1205 3534 else
b99bd4ef 3535 {
c19d1205
ZW
3536 /* Long form. */
3537 op = 0xb300 | (reg << 4) | (count - 1);
3538 add_unwind_opcode (op, 2);
b99bd4ef 3539 }
c19d1205
ZW
3540 unwind.frame_size += count * 8 + 4;
3541}
b99bd4ef 3542
b99bd4ef 3543
c19d1205
ZW
3544/* Parse a directive saving iWMMXt data registers. */
3545
3546static void
3547s_arm_unwind_save_mmxwr (void)
3548{
3549 int reg;
3550 int hi_reg;
3551 int i;
3552 unsigned mask = 0;
3553 valueT op;
b99bd4ef 3554
c19d1205
ZW
3555 if (*input_line_pointer == '{')
3556 input_line_pointer++;
b99bd4ef 3557
c19d1205 3558 do
b99bd4ef 3559 {
dcbf9037 3560 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
b99bd4ef 3561
c19d1205 3562 if (reg == FAIL)
b99bd4ef 3563 {
9b7132d3 3564 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205 3565 goto error;
b99bd4ef
NC
3566 }
3567
c19d1205
ZW
3568 if (mask >> reg)
3569 as_tsktsk (_("register list not in ascending order"));
3570 mask |= 1 << reg;
b99bd4ef 3571
c19d1205
ZW
3572 if (*input_line_pointer == '-')
3573 {
3574 input_line_pointer++;
dcbf9037 3575 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
c19d1205
ZW
3576 if (hi_reg == FAIL)
3577 {
9b7132d3 3578 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
c19d1205
ZW
3579 goto error;
3580 }
3581 else if (reg >= hi_reg)
3582 {
3583 as_bad (_("bad register range"));
3584 goto error;
3585 }
3586 for (; reg < hi_reg; reg++)
3587 mask |= 1 << reg;
3588 }
3589 }
3590 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3591
c19d1205
ZW
3592 if (*input_line_pointer == '}')
3593 input_line_pointer++;
b99bd4ef 3594
c19d1205 3595 demand_empty_rest_of_line ();
b99bd4ef 3596
708587a4 3597 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3598 the list. */
3599 flush_pending_unwind ();
b99bd4ef 3600
c19d1205 3601 for (i = 0; i < 16; i++)
b99bd4ef 3602 {
c19d1205
ZW
3603 if (mask & (1 << i))
3604 unwind.frame_size += 8;
b99bd4ef
NC
3605 }
3606
c19d1205
ZW
3607 /* Attempt to combine with a previous opcode. We do this because gcc
3608 likes to output separate unwind directives for a single block of
3609 registers. */
3610 if (unwind.opcode_count > 0)
b99bd4ef 3611 {
c19d1205
ZW
3612 i = unwind.opcodes[unwind.opcode_count - 1];
3613 if ((i & 0xf8) == 0xc0)
3614 {
3615 i &= 7;
3616 /* Only merge if the blocks are contiguous. */
3617 if (i < 6)
3618 {
3619 if ((mask & 0xfe00) == (1 << 9))
3620 {
3621 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3622 unwind.opcode_count--;
3623 }
3624 }
3625 else if (i == 6 && unwind.opcode_count >= 2)
3626 {
3627 i = unwind.opcodes[unwind.opcode_count - 2];
3628 reg = i >> 4;
3629 i &= 0xf;
b99bd4ef 3630
c19d1205
ZW
3631 op = 0xffff << (reg - 1);
3632 if (reg > 0
87a1fd79 3633 && ((mask & op) == (1u << (reg - 1))))
c19d1205
ZW
3634 {
3635 op = (1 << (reg + i + 1)) - 1;
3636 op &= ~((1 << reg) - 1);
3637 mask |= op;
3638 unwind.opcode_count -= 2;
3639 }
3640 }
3641 }
b99bd4ef
NC
3642 }
3643
c19d1205
ZW
3644 hi_reg = 15;
3645 /* We want to generate opcodes in the order the registers have been
3646 saved, ie. descending order. */
3647 for (reg = 15; reg >= -1; reg--)
b99bd4ef 3648 {
c19d1205
ZW
3649 /* Save registers in blocks. */
3650 if (reg < 0
3651 || !(mask & (1 << reg)))
3652 {
3653 /* We found an unsaved reg. Generate opcodes to save the
5f4273c7 3654 preceding block. */
c19d1205
ZW
3655 if (reg != hi_reg)
3656 {
3657 if (reg == 9)
3658 {
3659 /* Short form. */
3660 op = 0xc0 | (hi_reg - 10);
3661 add_unwind_opcode (op, 1);
3662 }
3663 else
3664 {
3665 /* Long form. */
3666 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3667 add_unwind_opcode (op, 2);
3668 }
3669 }
3670 hi_reg = reg - 1;
3671 }
b99bd4ef
NC
3672 }
3673
c19d1205
ZW
3674 return;
3675error:
3676 ignore_rest_of_line ();
b99bd4ef
NC
3677}
3678
3679static void
c19d1205 3680s_arm_unwind_save_mmxwcg (void)
b99bd4ef 3681{
c19d1205
ZW
3682 int reg;
3683 int hi_reg;
3684 unsigned mask = 0;
3685 valueT op;
b99bd4ef 3686
c19d1205
ZW
3687 if (*input_line_pointer == '{')
3688 input_line_pointer++;
b99bd4ef 3689
c19d1205 3690 do
b99bd4ef 3691 {
dcbf9037 3692 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
b99bd4ef 3693
c19d1205
ZW
3694 if (reg == FAIL)
3695 {
9b7132d3 3696 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3697 goto error;
3698 }
b99bd4ef 3699
c19d1205
ZW
3700 reg -= 8;
3701 if (mask >> reg)
3702 as_tsktsk (_("register list not in ascending order"));
3703 mask |= 1 << reg;
b99bd4ef 3704
c19d1205
ZW
3705 if (*input_line_pointer == '-')
3706 {
3707 input_line_pointer++;
dcbf9037 3708 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
c19d1205
ZW
3709 if (hi_reg == FAIL)
3710 {
9b7132d3 3711 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
c19d1205
ZW
3712 goto error;
3713 }
3714 else if (reg >= hi_reg)
3715 {
3716 as_bad (_("bad register range"));
3717 goto error;
3718 }
3719 for (; reg < hi_reg; reg++)
3720 mask |= 1 << reg;
3721 }
b99bd4ef 3722 }
c19d1205 3723 while (skip_past_comma (&input_line_pointer) != FAIL);
b99bd4ef 3724
c19d1205
ZW
3725 if (*input_line_pointer == '}')
3726 input_line_pointer++;
b99bd4ef 3727
c19d1205
ZW
3728 demand_empty_rest_of_line ();
3729
708587a4 3730 /* Generate any deferred opcodes because we're going to be looking at
c19d1205
ZW
3731 the list. */
3732 flush_pending_unwind ();
b99bd4ef 3733
c19d1205 3734 for (reg = 0; reg < 16; reg++)
b99bd4ef 3735 {
c19d1205
ZW
3736 if (mask & (1 << reg))
3737 unwind.frame_size += 4;
b99bd4ef 3738 }
c19d1205
ZW
3739 op = 0xc700 | mask;
3740 add_unwind_opcode (op, 2);
3741 return;
3742error:
3743 ignore_rest_of_line ();
b99bd4ef
NC
3744}
3745
c19d1205 3746
fa073d69
MS
3747/* Parse an unwind_save directive.
3748 If the argument is non-zero, this is a .vsave directive. */
c19d1205 3749
b99bd4ef 3750static void
fa073d69 3751s_arm_unwind_save (int arch_v6)
b99bd4ef 3752{
c19d1205
ZW
3753 char *peek;
3754 struct reg_entry *reg;
3755 bfd_boolean had_brace = FALSE;
b99bd4ef 3756
921e5f0a
PB
3757 if (!unwind.proc_start)
3758 as_bad(MISSING_FNSTART);
3759
c19d1205
ZW
3760 /* Figure out what sort of save we have. */
3761 peek = input_line_pointer;
b99bd4ef 3762
c19d1205 3763 if (*peek == '{')
b99bd4ef 3764 {
c19d1205
ZW
3765 had_brace = TRUE;
3766 peek++;
b99bd4ef
NC
3767 }
3768
c19d1205 3769 reg = arm_reg_parse_multi (&peek);
b99bd4ef 3770
c19d1205 3771 if (!reg)
b99bd4ef 3772 {
c19d1205
ZW
3773 as_bad (_("register expected"));
3774 ignore_rest_of_line ();
b99bd4ef
NC
3775 return;
3776 }
3777
c19d1205 3778 switch (reg->type)
b99bd4ef 3779 {
c19d1205
ZW
3780 case REG_TYPE_FN:
3781 if (had_brace)
3782 {
3783 as_bad (_("FPA .unwind_save does not take a register list"));
3784 ignore_rest_of_line ();
3785 return;
3786 }
93ac2687 3787 input_line_pointer = peek;
c19d1205 3788 s_arm_unwind_save_fpa (reg->number);
b99bd4ef 3789 return;
c19d1205
ZW
3790
3791 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
fa073d69
MS
3792 case REG_TYPE_VFD:
3793 if (arch_v6)
3794 s_arm_unwind_save_vfp_armv6 ();
3795 else
3796 s_arm_unwind_save_vfp ();
3797 return;
c19d1205
ZW
3798 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3799 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3800
3801 default:
3802 as_bad (_(".unwind_save does not support this kind of register"));
3803 ignore_rest_of_line ();
b99bd4ef 3804 }
c19d1205 3805}
b99bd4ef 3806
b99bd4ef 3807
c19d1205
ZW
3808/* Parse an unwind_movsp directive. */
3809
3810static void
3811s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3812{
3813 int reg;
3814 valueT op;
4fa3602b 3815 int offset;
c19d1205 3816
921e5f0a
PB
3817 if (!unwind.proc_start)
3818 as_bad(MISSING_FNSTART);
3819
dcbf9037 3820 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205 3821 if (reg == FAIL)
b99bd4ef 3822 {
9b7132d3 3823 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
c19d1205 3824 ignore_rest_of_line ();
b99bd4ef
NC
3825 return;
3826 }
4fa3602b
PB
3827
3828 /* Optional constant. */
3829 if (skip_past_comma (&input_line_pointer) != FAIL)
3830 {
3831 if (immediate_for_directive (&offset) == FAIL)
3832 return;
3833 }
3834 else
3835 offset = 0;
3836
c19d1205 3837 demand_empty_rest_of_line ();
b99bd4ef 3838
c19d1205 3839 if (reg == REG_SP || reg == REG_PC)
b99bd4ef 3840 {
c19d1205 3841 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
b99bd4ef
NC
3842 return;
3843 }
3844
c19d1205
ZW
3845 if (unwind.fp_reg != REG_SP)
3846 as_bad (_("unexpected .unwind_movsp directive"));
b99bd4ef 3847
c19d1205
ZW
3848 /* Generate opcode to restore the value. */
3849 op = 0x90 | reg;
3850 add_unwind_opcode (op, 1);
3851
3852 /* Record the information for later. */
3853 unwind.fp_reg = reg;
4fa3602b 3854 unwind.fp_offset = unwind.frame_size - offset;
c19d1205 3855 unwind.sp_restored = 1;
b05fe5cf
ZW
3856}
3857
c19d1205
ZW
3858/* Parse an unwind_pad directive. */
3859
b05fe5cf 3860static void
c19d1205 3861s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
b05fe5cf 3862{
c19d1205 3863 int offset;
b05fe5cf 3864
921e5f0a
PB
3865 if (!unwind.proc_start)
3866 as_bad(MISSING_FNSTART);
3867
c19d1205
ZW
3868 if (immediate_for_directive (&offset) == FAIL)
3869 return;
b99bd4ef 3870
c19d1205
ZW
3871 if (offset & 3)
3872 {
3873 as_bad (_("stack increment must be multiple of 4"));
3874 ignore_rest_of_line ();
3875 return;
3876 }
b99bd4ef 3877
c19d1205
ZW
3878 /* Don't generate any opcodes, just record the details for later. */
3879 unwind.frame_size += offset;
3880 unwind.pending_offset += offset;
3881
3882 demand_empty_rest_of_line ();
3883}
3884
3885/* Parse an unwind_setfp directive. */
3886
3887static void
3888s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
b99bd4ef 3889{
c19d1205
ZW
3890 int sp_reg;
3891 int fp_reg;
3892 int offset;
3893
921e5f0a
PB
3894 if (!unwind.proc_start)
3895 as_bad(MISSING_FNSTART);
3896
dcbf9037 3897 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
c19d1205
ZW
3898 if (skip_past_comma (&input_line_pointer) == FAIL)
3899 sp_reg = FAIL;
3900 else
dcbf9037 3901 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
b99bd4ef 3902
c19d1205
ZW
3903 if (fp_reg == FAIL || sp_reg == FAIL)
3904 {
3905 as_bad (_("expected <reg>, <reg>"));
3906 ignore_rest_of_line ();
3907 return;
3908 }
b99bd4ef 3909
c19d1205
ZW
3910 /* Optional constant. */
3911 if (skip_past_comma (&input_line_pointer) != FAIL)
3912 {
3913 if (immediate_for_directive (&offset) == FAIL)
3914 return;
3915 }
3916 else
3917 offset = 0;
a737bd4d 3918
c19d1205 3919 demand_empty_rest_of_line ();
a737bd4d 3920
fdfde340 3921 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
a737bd4d 3922 {
c19d1205
ZW
3923 as_bad (_("register must be either sp or set by a previous"
3924 "unwind_movsp directive"));
3925 return;
a737bd4d
NC
3926 }
3927
c19d1205
ZW
3928 /* Don't generate any opcodes, just record the information for later. */
3929 unwind.fp_reg = fp_reg;
3930 unwind.fp_used = 1;
fdfde340 3931 if (sp_reg == REG_SP)
c19d1205
ZW
3932 unwind.fp_offset = unwind.frame_size - offset;
3933 else
3934 unwind.fp_offset -= offset;
a737bd4d
NC
3935}
3936
c19d1205
ZW
3937/* Parse an unwind_raw directive. */
3938
3939static void
3940s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
a737bd4d 3941{
c19d1205 3942 expressionS exp;
708587a4 3943 /* This is an arbitrary limit. */
c19d1205
ZW
3944 unsigned char op[16];
3945 int count;
a737bd4d 3946
921e5f0a
PB
3947 if (!unwind.proc_start)
3948 as_bad(MISSING_FNSTART);
3949
c19d1205
ZW
3950 expression (&exp);
3951 if (exp.X_op == O_constant
3952 && skip_past_comma (&input_line_pointer) != FAIL)
a737bd4d 3953 {
c19d1205
ZW
3954 unwind.frame_size += exp.X_add_number;
3955 expression (&exp);
3956 }
3957 else
3958 exp.X_op = O_illegal;
a737bd4d 3959
c19d1205
ZW
3960 if (exp.X_op != O_constant)
3961 {
3962 as_bad (_("expected <offset>, <opcode>"));
3963 ignore_rest_of_line ();
3964 return;
3965 }
a737bd4d 3966
c19d1205 3967 count = 0;
a737bd4d 3968
c19d1205
ZW
3969 /* Parse the opcode. */
3970 for (;;)
3971 {
3972 if (count >= 16)
3973 {
3974 as_bad (_("unwind opcode too long"));
3975 ignore_rest_of_line ();
a737bd4d 3976 }
c19d1205 3977 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
a737bd4d 3978 {
c19d1205
ZW
3979 as_bad (_("invalid unwind opcode"));
3980 ignore_rest_of_line ();
3981 return;
a737bd4d 3982 }
c19d1205 3983 op[count++] = exp.X_add_number;
a737bd4d 3984
c19d1205
ZW
3985 /* Parse the next byte. */
3986 if (skip_past_comma (&input_line_pointer) == FAIL)
3987 break;
a737bd4d 3988
c19d1205
ZW
3989 expression (&exp);
3990 }
b99bd4ef 3991
c19d1205
ZW
3992 /* Add the opcode bytes in reverse order. */
3993 while (count--)
3994 add_unwind_opcode (op[count], 1);
b99bd4ef 3995
c19d1205 3996 demand_empty_rest_of_line ();
b99bd4ef 3997}
ee065d83
PB
3998
3999
4000/* Parse a .eabi_attribute directive. */
4001
4002static void
4003s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4004{
ee3c0378
AS
4005 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4006
4007 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4008 attributes_set_explicitly[tag] = 1;
ee065d83 4009}
8463be01 4010#endif /* OBJ_ELF */
ee065d83
PB
4011
4012static void s_arm_arch (int);
7a1d4c38 4013static void s_arm_object_arch (int);
ee065d83
PB
4014static void s_arm_cpu (int);
4015static void s_arm_fpu (int);
b99bd4ef 4016
f0927246
NC
4017#ifdef TE_PE
4018
4019static void
5f4273c7 4020pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
f0927246
NC
4021{
4022 expressionS exp;
4023
4024 do
4025 {
4026 expression (&exp);
4027 if (exp.X_op == O_symbol)
4028 exp.X_op = O_secrel;
4029
4030 emit_expr (&exp, 4);
4031 }
4032 while (*input_line_pointer++ == ',');
4033
4034 input_line_pointer--;
4035 demand_empty_rest_of_line ();
4036}
4037#endif /* TE_PE */
4038
c19d1205
ZW
4039/* This table describes all the machine specific pseudo-ops the assembler
4040 has to support. The fields are:
4041 pseudo-op name without dot
4042 function to call to execute this pseudo-op
4043 Integer arg to pass to the function. */
b99bd4ef 4044
c19d1205 4045const pseudo_typeS md_pseudo_table[] =
b99bd4ef 4046{
c19d1205
ZW
4047 /* Never called because '.req' does not start a line. */
4048 { "req", s_req, 0 },
dcbf9037
JB
4049 /* Following two are likewise never called. */
4050 { "dn", s_dn, 0 },
4051 { "qn", s_qn, 0 },
c19d1205
ZW
4052 { "unreq", s_unreq, 0 },
4053 { "bss", s_bss, 0 },
4054 { "align", s_align, 0 },
4055 { "arm", s_arm, 0 },
4056 { "thumb", s_thumb, 0 },
4057 { "code", s_code, 0 },
4058 { "force_thumb", s_force_thumb, 0 },
4059 { "thumb_func", s_thumb_func, 0 },
4060 { "thumb_set", s_thumb_set, 0 },
4061 { "even", s_even, 0 },
4062 { "ltorg", s_ltorg, 0 },
4063 { "pool", s_ltorg, 0 },
4064 { "syntax", s_syntax, 0 },
8463be01
PB
4065 { "cpu", s_arm_cpu, 0 },
4066 { "arch", s_arm_arch, 0 },
7a1d4c38 4067 { "object_arch", s_arm_object_arch, 0 },
8463be01 4068 { "fpu", s_arm_fpu, 0 },
c19d1205
ZW
4069#ifdef OBJ_ELF
4070 { "word", s_arm_elf_cons, 4 },
4071 { "long", s_arm_elf_cons, 4 },
4072 { "rel31", s_arm_rel31, 0 },
4073 { "fnstart", s_arm_unwind_fnstart, 0 },
4074 { "fnend", s_arm_unwind_fnend, 0 },
4075 { "cantunwind", s_arm_unwind_cantunwind, 0 },
4076 { "personality", s_arm_unwind_personality, 0 },
4077 { "personalityindex", s_arm_unwind_personalityindex, 0 },
4078 { "handlerdata", s_arm_unwind_handlerdata, 0 },
4079 { "save", s_arm_unwind_save, 0 },
fa073d69 4080 { "vsave", s_arm_unwind_save, 1 },
c19d1205
ZW
4081 { "movsp", s_arm_unwind_movsp, 0 },
4082 { "pad", s_arm_unwind_pad, 0 },
4083 { "setfp", s_arm_unwind_setfp, 0 },
4084 { "unwind_raw", s_arm_unwind_raw, 0 },
ee065d83 4085 { "eabi_attribute", s_arm_eabi_attribute, 0 },
c19d1205
ZW
4086#else
4087 { "word", cons, 4},
f0927246
NC
4088
4089 /* These are used for dwarf. */
4090 {"2byte", cons, 2},
4091 {"4byte", cons, 4},
4092 {"8byte", cons, 8},
4093 /* These are used for dwarf2. */
4094 { "file", (void (*) (int)) dwarf2_directive_file, 0 },
4095 { "loc", dwarf2_directive_loc, 0 },
4096 { "loc_mark_labels", dwarf2_directive_loc_mark_labels, 0 },
c19d1205
ZW
4097#endif
4098 { "extend", float_cons, 'x' },
4099 { "ldouble", float_cons, 'x' },
4100 { "packed", float_cons, 'p' },
f0927246
NC
4101#ifdef TE_PE
4102 {"secrel32", pe_directive_secrel, 0},
4103#endif
c19d1205
ZW
4104 { 0, 0, 0 }
4105};
4106\f
4107/* Parser functions used exclusively in instruction operands. */
b99bd4ef 4108
c19d1205
ZW
4109/* Generic immediate-value read function for use in insn parsing.
4110 STR points to the beginning of the immediate (the leading #);
4111 VAL receives the value; if the value is outside [MIN, MAX]
4112 issue an error. PREFIX_OPT is true if the immediate prefix is
4113 optional. */
b99bd4ef 4114
c19d1205
ZW
4115static int
4116parse_immediate (char **str, int *val, int min, int max,
4117 bfd_boolean prefix_opt)
4118{
4119 expressionS exp;
4120 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4121 if (exp.X_op != O_constant)
b99bd4ef 4122 {
c19d1205
ZW
4123 inst.error = _("constant expression required");
4124 return FAIL;
4125 }
b99bd4ef 4126
c19d1205
ZW
4127 if (exp.X_add_number < min || exp.X_add_number > max)
4128 {
4129 inst.error = _("immediate value out of range");
4130 return FAIL;
4131 }
b99bd4ef 4132
c19d1205
ZW
4133 *val = exp.X_add_number;
4134 return SUCCESS;
4135}
b99bd4ef 4136
5287ad62 4137/* Less-generic immediate-value read function with the possibility of loading a
036dc3f7 4138 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
5287ad62
JB
4139 instructions. Puts the result directly in inst.operands[i]. */
4140
4141static int
4142parse_big_immediate (char **str, int i)
4143{
4144 expressionS exp;
4145 char *ptr = *str;
4146
4147 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4148
4149 if (exp.X_op == O_constant)
036dc3f7
PB
4150 {
4151 inst.operands[i].imm = exp.X_add_number & 0xffffffff;
4152 /* If we're on a 64-bit host, then a 64-bit number can be returned using
4153 O_constant. We have to be careful not to break compilation for
4154 32-bit X_add_number, though. */
4155 if ((exp.X_add_number & ~0xffffffffl) != 0)
4156 {
4157 /* X >> 32 is illegal if sizeof (exp.X_add_number) == 4. */
4158 inst.operands[i].reg = ((exp.X_add_number >> 16) >> 16) & 0xffffffff;
4159 inst.operands[i].regisimm = 1;
4160 }
4161 }
5287ad62
JB
4162 else if (exp.X_op == O_big
4163 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number > 32
4164 && LITTLENUM_NUMBER_OF_BITS * exp.X_add_number <= 64)
4165 {
4166 unsigned parts = 32 / LITTLENUM_NUMBER_OF_BITS, j, idx = 0;
4167 /* Bignums have their least significant bits in
4168 generic_bignum[0]. Make sure we put 32 bits in imm and
4169 32 bits in reg, in a (hopefully) portable way. */
9c2799c2 4170 gas_assert (parts != 0);
5287ad62
JB
4171 inst.operands[i].imm = 0;
4172 for (j = 0; j < parts; j++, idx++)
4173 inst.operands[i].imm |= generic_bignum[idx]
4174 << (LITTLENUM_NUMBER_OF_BITS * j);
4175 inst.operands[i].reg = 0;
4176 for (j = 0; j < parts; j++, idx++)
4177 inst.operands[i].reg |= generic_bignum[idx]
4178 << (LITTLENUM_NUMBER_OF_BITS * j);
4179 inst.operands[i].regisimm = 1;
4180 }
4181 else
4182 return FAIL;
5f4273c7 4183
5287ad62
JB
4184 *str = ptr;
4185
4186 return SUCCESS;
4187}
4188
c19d1205
ZW
4189/* Returns the pseudo-register number of an FPA immediate constant,
4190 or FAIL if there isn't a valid constant here. */
b99bd4ef 4191
c19d1205
ZW
4192static int
4193parse_fpa_immediate (char ** str)
4194{
4195 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4196 char * save_in;
4197 expressionS exp;
4198 int i;
4199 int j;
b99bd4ef 4200
c19d1205
ZW
4201 /* First try and match exact strings, this is to guarantee
4202 that some formats will work even for cross assembly. */
b99bd4ef 4203
c19d1205
ZW
4204 for (i = 0; fp_const[i]; i++)
4205 {
4206 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
b99bd4ef 4207 {
c19d1205 4208 char *start = *str;
b99bd4ef 4209
c19d1205
ZW
4210 *str += strlen (fp_const[i]);
4211 if (is_end_of_line[(unsigned char) **str])
4212 return i + 8;
4213 *str = start;
4214 }
4215 }
b99bd4ef 4216
c19d1205
ZW
4217 /* Just because we didn't get a match doesn't mean that the constant
4218 isn't valid, just that it is in a format that we don't
4219 automatically recognize. Try parsing it with the standard
4220 expression routines. */
b99bd4ef 4221
c19d1205 4222 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
b99bd4ef 4223
c19d1205
ZW
4224 /* Look for a raw floating point number. */
4225 if ((save_in = atof_ieee (*str, 'x', words)) != NULL
4226 && is_end_of_line[(unsigned char) *save_in])
4227 {
4228 for (i = 0; i < NUM_FLOAT_VALS; i++)
4229 {
4230 for (j = 0; j < MAX_LITTLENUMS; j++)
b99bd4ef 4231 {
c19d1205
ZW
4232 if (words[j] != fp_values[i][j])
4233 break;
b99bd4ef
NC
4234 }
4235
c19d1205 4236 if (j == MAX_LITTLENUMS)
b99bd4ef 4237 {
c19d1205
ZW
4238 *str = save_in;
4239 return i + 8;
b99bd4ef
NC
4240 }
4241 }
4242 }
b99bd4ef 4243
c19d1205
ZW
4244 /* Try and parse a more complex expression, this will probably fail
4245 unless the code uses a floating point prefix (eg "0f"). */
4246 save_in = input_line_pointer;
4247 input_line_pointer = *str;
4248 if (expression (&exp) == absolute_section
4249 && exp.X_op == O_big
4250 && exp.X_add_number < 0)
4251 {
4252 /* FIXME: 5 = X_PRECISION, should be #define'd where we can use it.
4253 Ditto for 15. */
4254 if (gen_to_words (words, 5, (long) 15) == 0)
4255 {
4256 for (i = 0; i < NUM_FLOAT_VALS; i++)
4257 {
4258 for (j = 0; j < MAX_LITTLENUMS; j++)
4259 {
4260 if (words[j] != fp_values[i][j])
4261 break;
4262 }
b99bd4ef 4263
c19d1205
ZW
4264 if (j == MAX_LITTLENUMS)
4265 {
4266 *str = input_line_pointer;
4267 input_line_pointer = save_in;
4268 return i + 8;
4269 }
4270 }
4271 }
b99bd4ef
NC
4272 }
4273
c19d1205
ZW
4274 *str = input_line_pointer;
4275 input_line_pointer = save_in;
4276 inst.error = _("invalid FPA immediate expression");
4277 return FAIL;
b99bd4ef
NC
4278}
4279
136da414
JB
4280/* Returns 1 if a number has "quarter-precision" float format
4281 0baBbbbbbc defgh000 00000000 00000000. */
4282
4283static int
4284is_quarter_float (unsigned imm)
4285{
4286 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4287 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4288}
4289
4290/* Parse an 8-bit "quarter-precision" floating point number of the form:
4291 0baBbbbbbc defgh000 00000000 00000000.
c96612cc
JB
4292 The zero and minus-zero cases need special handling, since they can't be
4293 encoded in the "quarter-precision" float format, but can nonetheless be
4294 loaded as integer constants. */
136da414
JB
4295
4296static unsigned
4297parse_qfloat_immediate (char **ccp, int *immed)
4298{
4299 char *str = *ccp;
c96612cc 4300 char *fpnum;
136da414 4301 LITTLENUM_TYPE words[MAX_LITTLENUMS];
c96612cc 4302 int found_fpchar = 0;
5f4273c7 4303
136da414 4304 skip_past_char (&str, '#');
5f4273c7 4305
c96612cc
JB
4306 /* We must not accidentally parse an integer as a floating-point number. Make
4307 sure that the value we parse is not an integer by checking for special
4308 characters '.' or 'e'.
4309 FIXME: This is a horrible hack, but doing better is tricky because type
4310 information isn't in a very usable state at parse time. */
4311 fpnum = str;
4312 skip_whitespace (fpnum);
4313
4314 if (strncmp (fpnum, "0x", 2) == 0)
4315 return FAIL;
4316 else
4317 {
4318 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4319 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4320 {
4321 found_fpchar = 1;
4322 break;
4323 }
4324
4325 if (!found_fpchar)
4326 return FAIL;
4327 }
5f4273c7 4328
136da414
JB
4329 if ((str = atof_ieee (str, 's', words)) != NULL)
4330 {
4331 unsigned fpword = 0;
4332 int i;
5f4273c7 4333
136da414
JB
4334 /* Our FP word must be 32 bits (single-precision FP). */
4335 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4336 {
4337 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4338 fpword |= words[i];
4339 }
5f4273c7 4340
c96612cc 4341 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
136da414
JB
4342 *immed = fpword;
4343 else
4344 return FAIL;
4345
4346 *ccp = str;
5f4273c7 4347
136da414
JB
4348 return SUCCESS;
4349 }
5f4273c7 4350
136da414
JB
4351 return FAIL;
4352}
4353
c19d1205
ZW
4354/* Shift operands. */
4355enum shift_kind
b99bd4ef 4356{
c19d1205
ZW
4357 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4358};
b99bd4ef 4359
c19d1205
ZW
4360struct asm_shift_name
4361{
4362 const char *name;
4363 enum shift_kind kind;
4364};
b99bd4ef 4365
c19d1205
ZW
4366/* Third argument to parse_shift. */
4367enum parse_shift_mode
4368{
4369 NO_SHIFT_RESTRICT, /* Any kind of shift is accepted. */
4370 SHIFT_IMMEDIATE, /* Shift operand must be an immediate. */
4371 SHIFT_LSL_OR_ASR_IMMEDIATE, /* Shift must be LSL or ASR immediate. */
4372 SHIFT_ASR_IMMEDIATE, /* Shift must be ASR immediate. */
4373 SHIFT_LSL_IMMEDIATE, /* Shift must be LSL immediate. */
4374};
b99bd4ef 4375
c19d1205
ZW
4376/* Parse a <shift> specifier on an ARM data processing instruction.
4377 This has three forms:
b99bd4ef 4378
c19d1205
ZW
4379 (LSL|LSR|ASL|ASR|ROR) Rs
4380 (LSL|LSR|ASL|ASR|ROR) #imm
4381 RRX
b99bd4ef 4382
c19d1205
ZW
4383 Note that ASL is assimilated to LSL in the instruction encoding, and
4384 RRX to ROR #0 (which cannot be written as such). */
b99bd4ef 4385
c19d1205
ZW
4386static int
4387parse_shift (char **str, int i, enum parse_shift_mode mode)
b99bd4ef 4388{
c19d1205
ZW
4389 const struct asm_shift_name *shift_name;
4390 enum shift_kind shift;
4391 char *s = *str;
4392 char *p = s;
4393 int reg;
b99bd4ef 4394
c19d1205
ZW
4395 for (p = *str; ISALPHA (*p); p++)
4396 ;
b99bd4ef 4397
c19d1205 4398 if (p == *str)
b99bd4ef 4399 {
c19d1205
ZW
4400 inst.error = _("shift expression expected");
4401 return FAIL;
b99bd4ef
NC
4402 }
4403
c19d1205
ZW
4404 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4405
4406 if (shift_name == NULL)
b99bd4ef 4407 {
c19d1205
ZW
4408 inst.error = _("shift expression expected");
4409 return FAIL;
b99bd4ef
NC
4410 }
4411
c19d1205 4412 shift = shift_name->kind;
b99bd4ef 4413
c19d1205
ZW
4414 switch (mode)
4415 {
4416 case NO_SHIFT_RESTRICT:
4417 case SHIFT_IMMEDIATE: break;
b99bd4ef 4418
c19d1205
ZW
4419 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4420 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4421 {
4422 inst.error = _("'LSL' or 'ASR' required");
4423 return FAIL;
4424 }
4425 break;
b99bd4ef 4426
c19d1205
ZW
4427 case SHIFT_LSL_IMMEDIATE:
4428 if (shift != SHIFT_LSL)
4429 {
4430 inst.error = _("'LSL' required");
4431 return FAIL;
4432 }
4433 break;
b99bd4ef 4434
c19d1205
ZW
4435 case SHIFT_ASR_IMMEDIATE:
4436 if (shift != SHIFT_ASR)
4437 {
4438 inst.error = _("'ASR' required");
4439 return FAIL;
4440 }
4441 break;
b99bd4ef 4442
c19d1205
ZW
4443 default: abort ();
4444 }
b99bd4ef 4445
c19d1205
ZW
4446 if (shift != SHIFT_RRX)
4447 {
4448 /* Whitespace can appear here if the next thing is a bare digit. */
4449 skip_whitespace (p);
b99bd4ef 4450
c19d1205 4451 if (mode == NO_SHIFT_RESTRICT
dcbf9037 4452 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4453 {
4454 inst.operands[i].imm = reg;
4455 inst.operands[i].immisreg = 1;
4456 }
4457 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4458 return FAIL;
4459 }
4460 inst.operands[i].shift_kind = shift;
4461 inst.operands[i].shifted = 1;
4462 *str = p;
4463 return SUCCESS;
b99bd4ef
NC
4464}
4465
c19d1205 4466/* Parse a <shifter_operand> for an ARM data processing instruction:
b99bd4ef 4467
c19d1205
ZW
4468 #<immediate>
4469 #<immediate>, <rotate>
4470 <Rm>
4471 <Rm>, <shift>
b99bd4ef 4472
c19d1205
ZW
4473 where <shift> is defined by parse_shift above, and <rotate> is a
4474 multiple of 2 between 0 and 30. Validation of immediate operands
55cf6793 4475 is deferred to md_apply_fix. */
b99bd4ef 4476
c19d1205
ZW
4477static int
4478parse_shifter_operand (char **str, int i)
4479{
4480 int value;
4481 expressionS expr;
b99bd4ef 4482
dcbf9037 4483 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
c19d1205
ZW
4484 {
4485 inst.operands[i].reg = value;
4486 inst.operands[i].isreg = 1;
b99bd4ef 4487
c19d1205
ZW
4488 /* parse_shift will override this if appropriate */
4489 inst.reloc.exp.X_op = O_constant;
4490 inst.reloc.exp.X_add_number = 0;
b99bd4ef 4491
c19d1205
ZW
4492 if (skip_past_comma (str) == FAIL)
4493 return SUCCESS;
b99bd4ef 4494
c19d1205
ZW
4495 /* Shift operation on register. */
4496 return parse_shift (str, i, NO_SHIFT_RESTRICT);
b99bd4ef
NC
4497 }
4498
c19d1205
ZW
4499 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4500 return FAIL;
b99bd4ef 4501
c19d1205 4502 if (skip_past_comma (str) == SUCCESS)
b99bd4ef 4503 {
c19d1205
ZW
4504 /* #x, y -- ie explicit rotation by Y. */
4505 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4506 return FAIL;
b99bd4ef 4507
c19d1205
ZW
4508 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4509 {
4510 inst.error = _("constant expression expected");
4511 return FAIL;
4512 }
b99bd4ef 4513
c19d1205
ZW
4514 value = expr.X_add_number;
4515 if (value < 0 || value > 30 || value % 2 != 0)
4516 {
4517 inst.error = _("invalid rotation");
4518 return FAIL;
4519 }
4520 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4521 {
4522 inst.error = _("invalid constant");
4523 return FAIL;
4524 }
09d92015 4525
55cf6793 4526 /* Convert to decoded value. md_apply_fix will put it back. */
c19d1205
ZW
4527 inst.reloc.exp.X_add_number
4528 = (((inst.reloc.exp.X_add_number << (32 - value))
4529 | (inst.reloc.exp.X_add_number >> value)) & 0xffffffff);
09d92015
MM
4530 }
4531
c19d1205
ZW
4532 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4533 inst.reloc.pc_rel = 0;
4534 return SUCCESS;
09d92015
MM
4535}
4536
4962c51a
MS
4537/* Group relocation information. Each entry in the table contains the
4538 textual name of the relocation as may appear in assembler source
4539 and must end with a colon.
4540 Along with this textual name are the relocation codes to be used if
4541 the corresponding instruction is an ALU instruction (ADD or SUB only),
4542 an LDR, an LDRS, or an LDC. */
4543
4544struct group_reloc_table_entry
4545{
4546 const char *name;
4547 int alu_code;
4548 int ldr_code;
4549 int ldrs_code;
4550 int ldc_code;
4551};
4552
4553typedef enum
4554{
4555 /* Varieties of non-ALU group relocation. */
4556
4557 GROUP_LDR,
4558 GROUP_LDRS,
4559 GROUP_LDC
4560} group_reloc_type;
4561
4562static struct group_reloc_table_entry group_reloc_table[] =
4563 { /* Program counter relative: */
4564 { "pc_g0_nc",
4565 BFD_RELOC_ARM_ALU_PC_G0_NC, /* ALU */
4566 0, /* LDR */
4567 0, /* LDRS */
4568 0 }, /* LDC */
4569 { "pc_g0",
4570 BFD_RELOC_ARM_ALU_PC_G0, /* ALU */
4571 BFD_RELOC_ARM_LDR_PC_G0, /* LDR */
4572 BFD_RELOC_ARM_LDRS_PC_G0, /* LDRS */
4573 BFD_RELOC_ARM_LDC_PC_G0 }, /* LDC */
4574 { "pc_g1_nc",
4575 BFD_RELOC_ARM_ALU_PC_G1_NC, /* ALU */
4576 0, /* LDR */
4577 0, /* LDRS */
4578 0 }, /* LDC */
4579 { "pc_g1",
4580 BFD_RELOC_ARM_ALU_PC_G1, /* ALU */
4581 BFD_RELOC_ARM_LDR_PC_G1, /* LDR */
4582 BFD_RELOC_ARM_LDRS_PC_G1, /* LDRS */
4583 BFD_RELOC_ARM_LDC_PC_G1 }, /* LDC */
4584 { "pc_g2",
4585 BFD_RELOC_ARM_ALU_PC_G2, /* ALU */
4586 BFD_RELOC_ARM_LDR_PC_G2, /* LDR */
4587 BFD_RELOC_ARM_LDRS_PC_G2, /* LDRS */
4588 BFD_RELOC_ARM_LDC_PC_G2 }, /* LDC */
4589 /* Section base relative */
4590 { "sb_g0_nc",
4591 BFD_RELOC_ARM_ALU_SB_G0_NC, /* ALU */
4592 0, /* LDR */
4593 0, /* LDRS */
4594 0 }, /* LDC */
4595 { "sb_g0",
4596 BFD_RELOC_ARM_ALU_SB_G0, /* ALU */
4597 BFD_RELOC_ARM_LDR_SB_G0, /* LDR */
4598 BFD_RELOC_ARM_LDRS_SB_G0, /* LDRS */
4599 BFD_RELOC_ARM_LDC_SB_G0 }, /* LDC */
4600 { "sb_g1_nc",
4601 BFD_RELOC_ARM_ALU_SB_G1_NC, /* ALU */
4602 0, /* LDR */
4603 0, /* LDRS */
4604 0 }, /* LDC */
4605 { "sb_g1",
4606 BFD_RELOC_ARM_ALU_SB_G1, /* ALU */
4607 BFD_RELOC_ARM_LDR_SB_G1, /* LDR */
4608 BFD_RELOC_ARM_LDRS_SB_G1, /* LDRS */
4609 BFD_RELOC_ARM_LDC_SB_G1 }, /* LDC */
4610 { "sb_g2",
4611 BFD_RELOC_ARM_ALU_SB_G2, /* ALU */
4612 BFD_RELOC_ARM_LDR_SB_G2, /* LDR */
4613 BFD_RELOC_ARM_LDRS_SB_G2, /* LDRS */
4614 BFD_RELOC_ARM_LDC_SB_G2 } }; /* LDC */
4615
4616/* Given the address of a pointer pointing to the textual name of a group
4617 relocation as may appear in assembler source, attempt to find its details
4618 in group_reloc_table. The pointer will be updated to the character after
4619 the trailing colon. On failure, FAIL will be returned; SUCCESS
4620 otherwise. On success, *entry will be updated to point at the relevant
4621 group_reloc_table entry. */
4622
4623static int
4624find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4625{
4626 unsigned int i;
4627 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4628 {
4629 int length = strlen (group_reloc_table[i].name);
4630
5f4273c7
NC
4631 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4632 && (*str)[length] == ':')
4962c51a
MS
4633 {
4634 *out = &group_reloc_table[i];
4635 *str += (length + 1);
4636 return SUCCESS;
4637 }
4638 }
4639
4640 return FAIL;
4641}
4642
4643/* Parse a <shifter_operand> for an ARM data processing instruction
4644 (as for parse_shifter_operand) where group relocations are allowed:
4645
4646 #<immediate>
4647 #<immediate>, <rotate>
4648 #:<group_reloc>:<expression>
4649 <Rm>
4650 <Rm>, <shift>
4651
4652 where <group_reloc> is one of the strings defined in group_reloc_table.
4653 The hashes are optional.
4654
4655 Everything else is as for parse_shifter_operand. */
4656
4657static parse_operand_result
4658parse_shifter_operand_group_reloc (char **str, int i)
4659{
4660 /* Determine if we have the sequence of characters #: or just :
4661 coming next. If we do, then we check for a group relocation.
4662 If we don't, punt the whole lot to parse_shifter_operand. */
4663
4664 if (((*str)[0] == '#' && (*str)[1] == ':')
4665 || (*str)[0] == ':')
4666 {
4667 struct group_reloc_table_entry *entry;
4668
4669 if ((*str)[0] == '#')
4670 (*str) += 2;
4671 else
4672 (*str)++;
4673
4674 /* Try to parse a group relocation. Anything else is an error. */
4675 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4676 {
4677 inst.error = _("unknown group relocation");
4678 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4679 }
4680
4681 /* We now have the group relocation table entry corresponding to
4682 the name in the assembler source. Next, we parse the expression. */
4683 if (my_get_expression (&inst.reloc.exp, str, GE_NO_PREFIX))
4684 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4685
4686 /* Record the relocation type (always the ALU variant here). */
4687 inst.reloc.type = entry->alu_code;
9c2799c2 4688 gas_assert (inst.reloc.type != 0);
4962c51a
MS
4689
4690 return PARSE_OPERAND_SUCCESS;
4691 }
4692 else
4693 return parse_shifter_operand (str, i) == SUCCESS
4694 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4695
4696 /* Never reached. */
4697}
4698
c19d1205
ZW
4699/* Parse all forms of an ARM address expression. Information is written
4700 to inst.operands[i] and/or inst.reloc.
09d92015 4701
c19d1205 4702 Preindexed addressing (.preind=1):
09d92015 4703
c19d1205
ZW
4704 [Rn, #offset] .reg=Rn .reloc.exp=offset
4705 [Rn, +/-Rm] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4706 [Rn, +/-Rm, shift] .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4707 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4708
c19d1205 4709 These three may have a trailing ! which causes .writeback to be set also.
09d92015 4710
c19d1205 4711 Postindexed addressing (.postind=1, .writeback=1):
09d92015 4712
c19d1205
ZW
4713 [Rn], #offset .reg=Rn .reloc.exp=offset
4714 [Rn], +/-Rm .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4715 [Rn], +/-Rm, shift .reg=Rn .imm=Rm .immisreg=1 .negative=0/1
4716 .shift_kind=shift .reloc.exp=shift_imm
09d92015 4717
c19d1205 4718 Unindexed addressing (.preind=0, .postind=0):
09d92015 4719
c19d1205 4720 [Rn], {option} .reg=Rn .imm=option .immisreg=0
09d92015 4721
c19d1205 4722 Other:
09d92015 4723
c19d1205
ZW
4724 [Rn]{!} shorthand for [Rn,#0]{!}
4725 =immediate .isreg=0 .reloc.exp=immediate
4726 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
09d92015 4727
c19d1205
ZW
4728 It is the caller's responsibility to check for addressing modes not
4729 supported by the instruction, and to set inst.reloc.type. */
4730
4962c51a
MS
4731static parse_operand_result
4732parse_address_main (char **str, int i, int group_relocations,
4733 group_reloc_type group_type)
09d92015 4734{
c19d1205
ZW
4735 char *p = *str;
4736 int reg;
09d92015 4737
c19d1205 4738 if (skip_past_char (&p, '[') == FAIL)
09d92015 4739 {
c19d1205
ZW
4740 if (skip_past_char (&p, '=') == FAIL)
4741 {
4742 /* bare address - translate to PC-relative offset */
4743 inst.reloc.pc_rel = 1;
4744 inst.operands[i].reg = REG_PC;
4745 inst.operands[i].isreg = 1;
4746 inst.operands[i].preind = 1;
4747 }
4748 /* else a load-constant pseudo op, no special treatment needed here */
09d92015 4749
c19d1205 4750 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4962c51a 4751 return PARSE_OPERAND_FAIL;
09d92015 4752
c19d1205 4753 *str = p;
4962c51a 4754 return PARSE_OPERAND_SUCCESS;
09d92015
MM
4755 }
4756
dcbf9037 4757 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
09d92015 4758 {
c19d1205 4759 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4962c51a 4760 return PARSE_OPERAND_FAIL;
09d92015 4761 }
c19d1205
ZW
4762 inst.operands[i].reg = reg;
4763 inst.operands[i].isreg = 1;
09d92015 4764
c19d1205 4765 if (skip_past_comma (&p) == SUCCESS)
09d92015 4766 {
c19d1205 4767 inst.operands[i].preind = 1;
09d92015 4768
c19d1205
ZW
4769 if (*p == '+') p++;
4770 else if (*p == '-') p++, inst.operands[i].negative = 1;
4771
dcbf9037 4772 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
09d92015 4773 {
c19d1205
ZW
4774 inst.operands[i].imm = reg;
4775 inst.operands[i].immisreg = 1;
4776
4777 if (skip_past_comma (&p) == SUCCESS)
4778 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4779 return PARSE_OPERAND_FAIL;
c19d1205 4780 }
5287ad62
JB
4781 else if (skip_past_char (&p, ':') == SUCCESS)
4782 {
4783 /* FIXME: '@' should be used here, but it's filtered out by generic
4784 code before we get to see it here. This may be subject to
4785 change. */
4786 expressionS exp;
4787 my_get_expression (&exp, &p, GE_NO_PREFIX);
4788 if (exp.X_op != O_constant)
4789 {
4790 inst.error = _("alignment must be constant");
4962c51a 4791 return PARSE_OPERAND_FAIL;
5287ad62
JB
4792 }
4793 inst.operands[i].imm = exp.X_add_number << 8;
4794 inst.operands[i].immisalign = 1;
4795 /* Alignments are not pre-indexes. */
4796 inst.operands[i].preind = 0;
4797 }
c19d1205
ZW
4798 else
4799 {
4800 if (inst.operands[i].negative)
4801 {
4802 inst.operands[i].negative = 0;
4803 p--;
4804 }
4962c51a 4805
5f4273c7
NC
4806 if (group_relocations
4807 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4962c51a
MS
4808 {
4809 struct group_reloc_table_entry *entry;
4810
4811 /* Skip over the #: or : sequence. */
4812 if (*p == '#')
4813 p += 2;
4814 else
4815 p++;
4816
4817 /* Try to parse a group relocation. Anything else is an
4818 error. */
4819 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4820 {
4821 inst.error = _("unknown group relocation");
4822 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4823 }
4824
4825 /* We now have the group relocation table entry corresponding to
4826 the name in the assembler source. Next, we parse the
4827 expression. */
4828 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4829 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4830
4831 /* Record the relocation type. */
4832 switch (group_type)
4833 {
4834 case GROUP_LDR:
4835 inst.reloc.type = entry->ldr_code;
4836 break;
4837
4838 case GROUP_LDRS:
4839 inst.reloc.type = entry->ldrs_code;
4840 break;
4841
4842 case GROUP_LDC:
4843 inst.reloc.type = entry->ldc_code;
4844 break;
4845
4846 default:
9c2799c2 4847 gas_assert (0);
4962c51a
MS
4848 }
4849
4850 if (inst.reloc.type == 0)
4851 {
4852 inst.error = _("this group relocation is not allowed on this instruction");
4853 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4854 }
4855 }
4856 else
4857 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4858 return PARSE_OPERAND_FAIL;
09d92015
MM
4859 }
4860 }
4861
c19d1205 4862 if (skip_past_char (&p, ']') == FAIL)
09d92015 4863 {
c19d1205 4864 inst.error = _("']' expected");
4962c51a 4865 return PARSE_OPERAND_FAIL;
09d92015
MM
4866 }
4867
c19d1205
ZW
4868 if (skip_past_char (&p, '!') == SUCCESS)
4869 inst.operands[i].writeback = 1;
09d92015 4870
c19d1205 4871 else if (skip_past_comma (&p) == SUCCESS)
09d92015 4872 {
c19d1205
ZW
4873 if (skip_past_char (&p, '{') == SUCCESS)
4874 {
4875 /* [Rn], {expr} - unindexed, with option */
4876 if (parse_immediate (&p, &inst.operands[i].imm,
ca3f61f7 4877 0, 255, TRUE) == FAIL)
4962c51a 4878 return PARSE_OPERAND_FAIL;
09d92015 4879
c19d1205
ZW
4880 if (skip_past_char (&p, '}') == FAIL)
4881 {
4882 inst.error = _("'}' expected at end of 'option' field");
4962c51a 4883 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4884 }
4885 if (inst.operands[i].preind)
4886 {
4887 inst.error = _("cannot combine index with option");
4962c51a 4888 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4889 }
4890 *str = p;
4962c51a 4891 return PARSE_OPERAND_SUCCESS;
09d92015 4892 }
c19d1205
ZW
4893 else
4894 {
4895 inst.operands[i].postind = 1;
4896 inst.operands[i].writeback = 1;
09d92015 4897
c19d1205
ZW
4898 if (inst.operands[i].preind)
4899 {
4900 inst.error = _("cannot combine pre- and post-indexing");
4962c51a 4901 return PARSE_OPERAND_FAIL;
c19d1205 4902 }
09d92015 4903
c19d1205
ZW
4904 if (*p == '+') p++;
4905 else if (*p == '-') p++, inst.operands[i].negative = 1;
a737bd4d 4906
dcbf9037 4907 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
c19d1205 4908 {
5287ad62
JB
4909 /* We might be using the immediate for alignment already. If we
4910 are, OR the register number into the low-order bits. */
4911 if (inst.operands[i].immisalign)
4912 inst.operands[i].imm |= reg;
4913 else
4914 inst.operands[i].imm = reg;
c19d1205 4915 inst.operands[i].immisreg = 1;
a737bd4d 4916
c19d1205
ZW
4917 if (skip_past_comma (&p) == SUCCESS)
4918 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4962c51a 4919 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4920 }
4921 else
4922 {
4923 if (inst.operands[i].negative)
4924 {
4925 inst.operands[i].negative = 0;
4926 p--;
4927 }
4928 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4962c51a 4929 return PARSE_OPERAND_FAIL;
c19d1205
ZW
4930 }
4931 }
a737bd4d
NC
4932 }
4933
c19d1205
ZW
4934 /* If at this point neither .preind nor .postind is set, we have a
4935 bare [Rn]{!}, which is shorthand for [Rn,#0]{!}. */
4936 if (inst.operands[i].preind == 0 && inst.operands[i].postind == 0)
4937 {
4938 inst.operands[i].preind = 1;
4939 inst.reloc.exp.X_op = O_constant;
4940 inst.reloc.exp.X_add_number = 0;
4941 }
4942 *str = p;
4962c51a
MS
4943 return PARSE_OPERAND_SUCCESS;
4944}
4945
4946static int
4947parse_address (char **str, int i)
4948{
4949 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4950 ? SUCCESS : FAIL;
4951}
4952
4953static parse_operand_result
4954parse_address_group_reloc (char **str, int i, group_reloc_type type)
4955{
4956 return parse_address_main (str, i, 1, type);
a737bd4d
NC
4957}
4958
b6895b4f
PB
4959/* Parse an operand for a MOVW or MOVT instruction. */
4960static int
4961parse_half (char **str)
4962{
4963 char * p;
5f4273c7 4964
b6895b4f
PB
4965 p = *str;
4966 skip_past_char (&p, '#');
5f4273c7 4967 if (strncasecmp (p, ":lower16:", 9) == 0)
b6895b4f
PB
4968 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4969 else if (strncasecmp (p, ":upper16:", 9) == 0)
4970 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4971
4972 if (inst.reloc.type != BFD_RELOC_UNUSED)
4973 {
4974 p += 9;
5f4273c7 4975 skip_whitespace (p);
b6895b4f
PB
4976 }
4977
4978 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4979 return FAIL;
4980
4981 if (inst.reloc.type == BFD_RELOC_UNUSED)
4982 {
4983 if (inst.reloc.exp.X_op != O_constant)
4984 {
4985 inst.error = _("constant expression expected");
4986 return FAIL;
4987 }
4988 if (inst.reloc.exp.X_add_number < 0
4989 || inst.reloc.exp.X_add_number > 0xffff)
4990 {
4991 inst.error = _("immediate value out of range");
4992 return FAIL;
4993 }
4994 }
4995 *str = p;
4996 return SUCCESS;
4997}
4998
c19d1205 4999/* Miscellaneous. */
a737bd4d 5000
c19d1205
ZW
5001/* Parse a PSR flag operand. The value returned is FAIL on syntax error,
5002 or a bitmask suitable to be or-ed into the ARM msr instruction. */
5003static int
5004parse_psr (char **str)
09d92015 5005{
c19d1205
ZW
5006 char *p;
5007 unsigned long psr_field;
62b3e311
PB
5008 const struct asm_psr *psr;
5009 char *start;
09d92015 5010
c19d1205
ZW
5011 /* CPSR's and SPSR's can now be lowercase. This is just a convenience
5012 feature for ease of use and backwards compatibility. */
5013 p = *str;
62b3e311 5014 if (strncasecmp (p, "SPSR", 4) == 0)
c19d1205 5015 psr_field = SPSR_BIT;
62b3e311 5016 else if (strncasecmp (p, "CPSR", 4) == 0)
c19d1205
ZW
5017 psr_field = 0;
5018 else
62b3e311
PB
5019 {
5020 start = p;
5021 do
5022 p++;
5023 while (ISALNUM (*p) || *p == '_');
5024
5025 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
5026 if (!psr)
5027 return FAIL;
09d92015 5028
62b3e311
PB
5029 *str = p;
5030 return psr->field;
5031 }
09d92015 5032
62b3e311 5033 p += 4;
c19d1205
ZW
5034 if (*p == '_')
5035 {
5036 /* A suffix follows. */
c19d1205
ZW
5037 p++;
5038 start = p;
a737bd4d 5039
c19d1205
ZW
5040 do
5041 p++;
5042 while (ISALNUM (*p) || *p == '_');
a737bd4d 5043
c19d1205
ZW
5044 psr = hash_find_n (arm_psr_hsh, start, p - start);
5045 if (!psr)
5046 goto error;
a737bd4d 5047
c19d1205 5048 psr_field |= psr->field;
a737bd4d 5049 }
c19d1205 5050 else
a737bd4d 5051 {
c19d1205
ZW
5052 if (ISALNUM (*p))
5053 goto error; /* Garbage after "[CS]PSR". */
5054
5055 psr_field |= (PSR_c | PSR_f);
a737bd4d 5056 }
c19d1205
ZW
5057 *str = p;
5058 return psr_field;
a737bd4d 5059
c19d1205
ZW
5060 error:
5061 inst.error = _("flag for {c}psr instruction expected");
5062 return FAIL;
a737bd4d
NC
5063}
5064
c19d1205
ZW
5065/* Parse the flags argument to CPSI[ED]. Returns FAIL on error, or a
5066 value suitable for splatting into the AIF field of the instruction. */
a737bd4d 5067
c19d1205
ZW
5068static int
5069parse_cps_flags (char **str)
a737bd4d 5070{
c19d1205
ZW
5071 int val = 0;
5072 int saw_a_flag = 0;
5073 char *s = *str;
a737bd4d 5074
c19d1205
ZW
5075 for (;;)
5076 switch (*s++)
5077 {
5078 case '\0': case ',':
5079 goto done;
a737bd4d 5080
c19d1205
ZW
5081 case 'a': case 'A': saw_a_flag = 1; val |= 0x4; break;
5082 case 'i': case 'I': saw_a_flag = 1; val |= 0x2; break;
5083 case 'f': case 'F': saw_a_flag = 1; val |= 0x1; break;
a737bd4d 5084
c19d1205
ZW
5085 default:
5086 inst.error = _("unrecognized CPS flag");
5087 return FAIL;
5088 }
a737bd4d 5089
c19d1205
ZW
5090 done:
5091 if (saw_a_flag == 0)
a737bd4d 5092 {
c19d1205
ZW
5093 inst.error = _("missing CPS flags");
5094 return FAIL;
a737bd4d 5095 }
a737bd4d 5096
c19d1205
ZW
5097 *str = s - 1;
5098 return val;
a737bd4d
NC
5099}
5100
c19d1205
ZW
5101/* Parse an endian specifier ("BE" or "LE", case insensitive);
5102 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
a737bd4d
NC
5103
5104static int
c19d1205 5105parse_endian_specifier (char **str)
a737bd4d 5106{
c19d1205
ZW
5107 int little_endian;
5108 char *s = *str;
a737bd4d 5109
c19d1205
ZW
5110 if (strncasecmp (s, "BE", 2))
5111 little_endian = 0;
5112 else if (strncasecmp (s, "LE", 2))
5113 little_endian = 1;
5114 else
a737bd4d 5115 {
c19d1205 5116 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5117 return FAIL;
5118 }
5119
c19d1205 5120 if (ISALNUM (s[2]) || s[2] == '_')
a737bd4d 5121 {
c19d1205 5122 inst.error = _("valid endian specifiers are be or le");
a737bd4d
NC
5123 return FAIL;
5124 }
5125
c19d1205
ZW
5126 *str = s + 2;
5127 return little_endian;
5128}
a737bd4d 5129
c19d1205
ZW
5130/* Parse a rotation specifier: ROR #0, #8, #16, #24. *val receives a
5131 value suitable for poking into the rotate field of an sxt or sxta
5132 instruction, or FAIL on error. */
5133
5134static int
5135parse_ror (char **str)
5136{
5137 int rot;
5138 char *s = *str;
5139
5140 if (strncasecmp (s, "ROR", 3) == 0)
5141 s += 3;
5142 else
a737bd4d 5143 {
c19d1205 5144 inst.error = _("missing rotation field after comma");
a737bd4d
NC
5145 return FAIL;
5146 }
c19d1205
ZW
5147
5148 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5149 return FAIL;
5150
5151 switch (rot)
a737bd4d 5152 {
c19d1205
ZW
5153 case 0: *str = s; return 0x0;
5154 case 8: *str = s; return 0x1;
5155 case 16: *str = s; return 0x2;
5156 case 24: *str = s; return 0x3;
5157
5158 default:
5159 inst.error = _("rotation can only be 0, 8, 16, or 24");
a737bd4d
NC
5160 return FAIL;
5161 }
c19d1205 5162}
a737bd4d 5163
c19d1205
ZW
5164/* Parse a conditional code (from conds[] below). The value returned is in the
5165 range 0 .. 14, or FAIL. */
5166static int
5167parse_cond (char **str)
5168{
c462b453 5169 char *q;
c19d1205 5170 const struct asm_cond *c;
c462b453
PB
5171 int n;
5172 /* Condition codes are always 2 characters, so matching up to
5173 3 characters is sufficient. */
5174 char cond[3];
a737bd4d 5175
c462b453
PB
5176 q = *str;
5177 n = 0;
5178 while (ISALPHA (*q) && n < 3)
5179 {
e07e6e58 5180 cond[n] = TOLOWER (*q);
c462b453
PB
5181 q++;
5182 n++;
5183 }
a737bd4d 5184
c462b453 5185 c = hash_find_n (arm_cond_hsh, cond, n);
c19d1205 5186 if (!c)
a737bd4d 5187 {
c19d1205 5188 inst.error = _("condition required");
a737bd4d
NC
5189 return FAIL;
5190 }
5191
c19d1205
ZW
5192 *str = q;
5193 return c->value;
5194}
5195
62b3e311
PB
5196/* Parse an option for a barrier instruction. Returns the encoding for the
5197 option, or FAIL. */
5198static int
5199parse_barrier (char **str)
5200{
5201 char *p, *q;
5202 const struct asm_barrier_opt *o;
5203
5204 p = q = *str;
5205 while (ISALPHA (*q))
5206 q++;
5207
5208 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5209 if (!o)
5210 return FAIL;
5211
5212 *str = q;
5213 return o->value;
5214}
5215
92e90b6e
PB
5216/* Parse the operands of a table branch instruction. Similar to a memory
5217 operand. */
5218static int
5219parse_tb (char **str)
5220{
5221 char * p = *str;
5222 int reg;
5223
5224 if (skip_past_char (&p, '[') == FAIL)
ab1eb5fe
PB
5225 {
5226 inst.error = _("'[' expected");
5227 return FAIL;
5228 }
92e90b6e 5229
dcbf9037 5230 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5231 {
5232 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5233 return FAIL;
5234 }
5235 inst.operands[0].reg = reg;
5236
5237 if (skip_past_comma (&p) == FAIL)
ab1eb5fe
PB
5238 {
5239 inst.error = _("',' expected");
5240 return FAIL;
5241 }
5f4273c7 5242
dcbf9037 5243 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
92e90b6e
PB
5244 {
5245 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5246 return FAIL;
5247 }
5248 inst.operands[0].imm = reg;
5249
5250 if (skip_past_comma (&p) == SUCCESS)
5251 {
5252 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5253 return FAIL;
5254 if (inst.reloc.exp.X_add_number != 1)
5255 {
5256 inst.error = _("invalid shift");
5257 return FAIL;
5258 }
5259 inst.operands[0].shifted = 1;
5260 }
5261
5262 if (skip_past_char (&p, ']') == FAIL)
5263 {
5264 inst.error = _("']' expected");
5265 return FAIL;
5266 }
5267 *str = p;
5268 return SUCCESS;
5269}
5270
5287ad62
JB
5271/* Parse the operands of a Neon VMOV instruction. See do_neon_mov for more
5272 information on the types the operands can take and how they are encoded.
037e8744
JB
5273 Up to four operands may be read; this function handles setting the
5274 ".present" field for each read operand itself.
5287ad62
JB
5275 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5276 else returns FAIL. */
5277
5278static int
5279parse_neon_mov (char **str, int *which_operand)
5280{
5281 int i = *which_operand, val;
5282 enum arm_reg_type rtype;
5283 char *ptr = *str;
dcbf9037 5284 struct neon_type_el optype;
5f4273c7 5285
dcbf9037 5286 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5287 {
5288 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5289 inst.operands[i].reg = val;
5290 inst.operands[i].isscalar = 1;
dcbf9037 5291 inst.operands[i].vectype = optype;
5287ad62
JB
5292 inst.operands[i++].present = 1;
5293
5294 if (skip_past_comma (&ptr) == FAIL)
5295 goto wanted_comma;
5f4273c7 5296
dcbf9037 5297 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5287ad62 5298 goto wanted_arm;
5f4273c7 5299
5287ad62
JB
5300 inst.operands[i].reg = val;
5301 inst.operands[i].isreg = 1;
5302 inst.operands[i].present = 1;
5303 }
037e8744 5304 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
dcbf9037 5305 != FAIL)
5287ad62
JB
5306 {
5307 /* Cases 0, 1, 2, 3, 5 (D only). */
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5f4273c7 5310
5287ad62
JB
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5315 inst.operands[i].isvec = 1;
dcbf9037 5316 inst.operands[i].vectype = optype;
5287ad62
JB
5317 inst.operands[i++].present = 1;
5318
dcbf9037 5319 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62 5320 {
037e8744
JB
5321 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5322 Case 13: VMOV <Sd>, <Rm> */
5287ad62
JB
5323 inst.operands[i].reg = val;
5324 inst.operands[i].isreg = 1;
037e8744 5325 inst.operands[i].present = 1;
5287ad62
JB
5326
5327 if (rtype == REG_TYPE_NQ)
5328 {
dcbf9037 5329 first_error (_("can't use Neon quad register here"));
5287ad62
JB
5330 return FAIL;
5331 }
037e8744
JB
5332 else if (rtype != REG_TYPE_VFS)
5333 {
5334 i++;
5335 if (skip_past_comma (&ptr) == FAIL)
5336 goto wanted_comma;
5337 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5338 goto wanted_arm;
5339 inst.operands[i].reg = val;
5340 inst.operands[i].isreg = 1;
5341 inst.operands[i].present = 1;
5342 }
5287ad62 5343 }
037e8744
JB
5344 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5345 &optype)) != FAIL)
5287ad62
JB
5346 {
5347 /* Case 0: VMOV<c><q> <Qd>, <Qm>
037e8744
JB
5348 Case 1: VMOV<c><q> <Dd>, <Dm>
5349 Case 8: VMOV.F32 <Sd>, <Sm>
5350 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5287ad62
JB
5351
5352 inst.operands[i].reg = val;
5353 inst.operands[i].isreg = 1;
5354 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
037e8744
JB
5355 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5356 inst.operands[i].isvec = 1;
dcbf9037 5357 inst.operands[i].vectype = optype;
5287ad62 5358 inst.operands[i].present = 1;
5f4273c7 5359
037e8744
JB
5360 if (skip_past_comma (&ptr) == SUCCESS)
5361 {
5362 /* Case 15. */
5363 i++;
5364
5365 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5366 goto wanted_arm;
5367
5368 inst.operands[i].reg = val;
5369 inst.operands[i].isreg = 1;
5370 inst.operands[i++].present = 1;
5f4273c7 5371
037e8744
JB
5372 if (skip_past_comma (&ptr) == FAIL)
5373 goto wanted_comma;
5f4273c7 5374
037e8744
JB
5375 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5376 goto wanted_arm;
5f4273c7 5377
037e8744
JB
5378 inst.operands[i].reg = val;
5379 inst.operands[i].isreg = 1;
5380 inst.operands[i++].present = 1;
5381 }
5287ad62 5382 }
4641781c
PB
5383 else if (parse_qfloat_immediate (&ptr, &inst.operands[i].imm) == SUCCESS)
5384 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<float-imm>
5385 Case 3: VMOV<c><q>.<dt> <Dd>, #<float-imm>
5386 Case 10: VMOV.F32 <Sd>, #<imm>
5387 Case 11: VMOV.F64 <Dd>, #<imm> */
5388 inst.operands[i].immisfloat = 1;
5389 else if (parse_big_immediate (&ptr, i) == SUCCESS)
5390 /* Case 2: VMOV<c><q>.<dt> <Qd>, #<imm>
5391 Case 3: VMOV<c><q>.<dt> <Dd>, #<imm> */
5392 ;
5287ad62
JB
5393 else
5394 {
dcbf9037 5395 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5287ad62
JB
5396 return FAIL;
5397 }
5398 }
dcbf9037 5399 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5400 {
5401 /* Cases 6, 7. */
5402 inst.operands[i].reg = val;
5403 inst.operands[i].isreg = 1;
5404 inst.operands[i++].present = 1;
5f4273c7 5405
5287ad62
JB
5406 if (skip_past_comma (&ptr) == FAIL)
5407 goto wanted_comma;
5f4273c7 5408
dcbf9037 5409 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5287ad62
JB
5410 {
5411 /* Case 6: VMOV<c><q>.<dt> <Rd>, <Dn[x]> */
5412 inst.operands[i].reg = val;
5413 inst.operands[i].isscalar = 1;
5414 inst.operands[i].present = 1;
dcbf9037 5415 inst.operands[i].vectype = optype;
5287ad62 5416 }
dcbf9037 5417 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5287ad62
JB
5418 {
5419 /* Case 7: VMOV<c><q> <Rd>, <Rn>, <Dm> */
5420 inst.operands[i].reg = val;
5421 inst.operands[i].isreg = 1;
5422 inst.operands[i++].present = 1;
5f4273c7 5423
5287ad62
JB
5424 if (skip_past_comma (&ptr) == FAIL)
5425 goto wanted_comma;
5f4273c7 5426
037e8744 5427 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
dcbf9037 5428 == FAIL)
5287ad62 5429 {
037e8744 5430 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5287ad62
JB
5431 return FAIL;
5432 }
5433
5434 inst.operands[i].reg = val;
5435 inst.operands[i].isreg = 1;
037e8744
JB
5436 inst.operands[i].isvec = 1;
5437 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
dcbf9037 5438 inst.operands[i].vectype = optype;
5287ad62 5439 inst.operands[i].present = 1;
5f4273c7 5440
037e8744
JB
5441 if (rtype == REG_TYPE_VFS)
5442 {
5443 /* Case 14. */
5444 i++;
5445 if (skip_past_comma (&ptr) == FAIL)
5446 goto wanted_comma;
5447 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL,
5448 &optype)) == FAIL)
5449 {
5450 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5451 return FAIL;
5452 }
5453 inst.operands[i].reg = val;
5454 inst.operands[i].isreg = 1;
5455 inst.operands[i].isvec = 1;
5456 inst.operands[i].issingle = 1;
5457 inst.operands[i].vectype = optype;
5458 inst.operands[i].present = 1;
5459 }
5460 }
5461 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5462 != FAIL)
5463 {
5464 /* Case 13. */
5465 inst.operands[i].reg = val;
5466 inst.operands[i].isreg = 1;
5467 inst.operands[i].isvec = 1;
5468 inst.operands[i].issingle = 1;
5469 inst.operands[i].vectype = optype;
5470 inst.operands[i++].present = 1;
5287ad62
JB
5471 }
5472 }
5473 else
5474 {
dcbf9037 5475 first_error (_("parse error"));
5287ad62
JB
5476 return FAIL;
5477 }
5478
5479 /* Successfully parsed the operands. Update args. */
5480 *which_operand = i;
5481 *str = ptr;
5482 return SUCCESS;
5483
5f4273c7 5484 wanted_comma:
dcbf9037 5485 first_error (_("expected comma"));
5287ad62 5486 return FAIL;
5f4273c7
NC
5487
5488 wanted_arm:
dcbf9037 5489 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5287ad62 5490 return FAIL;
5287ad62
JB
5491}
5492
c19d1205
ZW
5493/* Matcher codes for parse_operands. */
5494enum operand_parse_code
5495{
5496 OP_stop, /* end of line */
5497
5498 OP_RR, /* ARM register */
5499 OP_RRnpc, /* ARM register, not r15 */
5500 OP_RRnpcb, /* ARM register, not r15, in square brackets */
5501 OP_RRw, /* ARM register, not r15, optional trailing ! */
5502 OP_RCP, /* Coprocessor number */
5503 OP_RCN, /* Coprocessor register */
5504 OP_RF, /* FPA register */
5505 OP_RVS, /* VFP single precision register */
5287ad62
JB
5506 OP_RVD, /* VFP double precision register (0..15) */
5507 OP_RND, /* Neon double precision register (0..31) */
5508 OP_RNQ, /* Neon quad precision register */
037e8744 5509 OP_RVSD, /* VFP single or double precision register */
5287ad62 5510 OP_RNDQ, /* Neon double or quad precision register */
037e8744 5511 OP_RNSDQ, /* Neon single, double or quad precision register */
5287ad62 5512 OP_RNSC, /* Neon scalar D[X] */
c19d1205
ZW
5513 OP_RVC, /* VFP control register */
5514 OP_RMF, /* Maverick F register */
5515 OP_RMD, /* Maverick D register */
5516 OP_RMFX, /* Maverick FX register */
5517 OP_RMDX, /* Maverick DX register */
5518 OP_RMAX, /* Maverick AX register */
5519 OP_RMDS, /* Maverick DSPSC register */
5520 OP_RIWR, /* iWMMXt wR register */
5521 OP_RIWC, /* iWMMXt wC register */
5522 OP_RIWG, /* iWMMXt wCG register */
5523 OP_RXA, /* XScale accumulator register */
5524
5525 OP_REGLST, /* ARM register list */
5526 OP_VRSLST, /* VFP single-precision register list */
5527 OP_VRDLST, /* VFP double-precision register list */
037e8744 5528 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5287ad62
JB
5529 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5530 OP_NSTRLST, /* Neon element/structure list */
5531
5532 OP_NILO, /* Neon immediate/logic operands 2 or 2+3. (VBIC, VORR...) */
5533 OP_RNDQ_I0, /* Neon D or Q reg, or immediate zero. */
037e8744 5534 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5287ad62 5535 OP_RR_RNSC, /* ARM reg or Neon scalar. */
037e8744 5536 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
5287ad62
JB
5537 OP_RNDQ_RNSC, /* Neon D or Q reg, or Neon scalar. */
5538 OP_RND_RNSC, /* Neon D reg, or Neon scalar. */
5539 OP_VMOV, /* Neon VMOV operands. */
5540 OP_RNDQ_IMVNb,/* Neon D or Q reg, or immediate good for VMVN. */
5541 OP_RNDQ_I63b, /* Neon D or Q reg, or immediate for shift. */
2d447fca 5542 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5287ad62
JB
5543
5544 OP_I0, /* immediate zero */
c19d1205
ZW
5545 OP_I7, /* immediate value 0 .. 7 */
5546 OP_I15, /* 0 .. 15 */
5547 OP_I16, /* 1 .. 16 */
5287ad62 5548 OP_I16z, /* 0 .. 16 */
c19d1205
ZW
5549 OP_I31, /* 0 .. 31 */
5550 OP_I31w, /* 0 .. 31, optional trailing ! */
5551 OP_I32, /* 1 .. 32 */
5287ad62
JB
5552 OP_I32z, /* 0 .. 32 */
5553 OP_I63, /* 0 .. 63 */
c19d1205 5554 OP_I63s, /* -64 .. 63 */
5287ad62
JB
5555 OP_I64, /* 1 .. 64 */
5556 OP_I64z, /* 0 .. 64 */
c19d1205 5557 OP_I255, /* 0 .. 255 */
c19d1205
ZW
5558
5559 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5560 OP_I7b, /* 0 .. 7 */
5561 OP_I15b, /* 0 .. 15 */
5562 OP_I31b, /* 0 .. 31 */
5563
5564 OP_SH, /* shifter operand */
4962c51a 5565 OP_SHG, /* shifter operand with possible group relocation */
c19d1205 5566 OP_ADDR, /* Memory address expression (any mode) */
4962c51a
MS
5567 OP_ADDRGLDR, /* Mem addr expr (any mode) with possible LDR group reloc */
5568 OP_ADDRGLDRS, /* Mem addr expr (any mode) with possible LDRS group reloc */
5569 OP_ADDRGLDC, /* Mem addr expr (any mode) with possible LDC group reloc */
c19d1205
ZW
5570 OP_EXP, /* arbitrary expression */
5571 OP_EXPi, /* same, with optional immediate prefix */
5572 OP_EXPr, /* same, with optional relocation suffix */
b6895b4f 5573 OP_HALF, /* 0 .. 65535 or low/high reloc. */
c19d1205
ZW
5574
5575 OP_CPSF, /* CPS flags */
5576 OP_ENDI, /* Endianness specifier */
5577 OP_PSR, /* CPSR/SPSR mask for msr */
5578 OP_COND, /* conditional code */
92e90b6e 5579 OP_TB, /* Table branch. */
c19d1205 5580
037e8744
JB
5581 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5582 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
5583
c19d1205
ZW
5584 OP_RRnpc_I0, /* ARM register or literal 0 */
5585 OP_RR_EXr, /* ARM register or expression with opt. reloc suff. */
5586 OP_RR_EXi, /* ARM register or expression with imm prefix */
5587 OP_RF_IF, /* FPA register or immediate */
5588 OP_RIWR_RIWC, /* iWMMXt R or C reg */
41adaa5c 5589 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
c19d1205
ZW
5590
5591 /* Optional operands. */
5592 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5593 OP_oI31b, /* 0 .. 31 */
5287ad62 5594 OP_oI32b, /* 1 .. 32 */
c19d1205
ZW
5595 OP_oIffffb, /* 0 .. 65535 */
5596 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5597
5598 OP_oRR, /* ARM register */
5599 OP_oRRnpc, /* ARM register, not the PC */
b6702015 5600 OP_oRRw, /* ARM register, not r15, optional trailing ! */
5287ad62
JB
5601 OP_oRND, /* Optional Neon double precision register */
5602 OP_oRNQ, /* Optional Neon quad precision register */
5603 OP_oRNDQ, /* Optional Neon double or quad precision register */
037e8744 5604 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
c19d1205
ZW
5605 OP_oSHll, /* LSL immediate */
5606 OP_oSHar, /* ASR immediate */
5607 OP_oSHllar, /* LSL or ASR immediate */
5608 OP_oROR, /* ROR 0/8/16/24 */
62b3e311 5609 OP_oBARRIER, /* Option argument for a barrier instruction. */
c19d1205
ZW
5610
5611 OP_FIRST_OPTIONAL = OP_oI7b
5612};
a737bd4d 5613
c19d1205
ZW
5614/* Generic instruction operand parser. This does no encoding and no
5615 semantic validation; it merely squirrels values away in the inst
5616 structure. Returns SUCCESS or FAIL depending on whether the
5617 specified grammar matched. */
5618static int
ca3f61f7 5619parse_operands (char *str, const unsigned char *pattern)
c19d1205
ZW
5620{
5621 unsigned const char *upat = pattern;
5622 char *backtrack_pos = 0;
5623 const char *backtrack_error = 0;
5624 int i, val, backtrack_index = 0;
5287ad62 5625 enum arm_reg_type rtype;
4962c51a 5626 parse_operand_result result;
c19d1205 5627
e07e6e58
NC
5628#define po_char_or_fail(chr) \
5629 do \
5630 { \
5631 if (skip_past_char (&str, chr) == FAIL) \
5632 goto bad_args; \
5633 } \
5634 while (0)
c19d1205 5635
e07e6e58
NC
5636#define po_reg_or_fail(regtype) \
5637 do \
dcbf9037 5638 { \
e07e6e58
NC
5639 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5640 & inst.operands[i].vectype); \
5641 if (val == FAIL) \
5642 { \
5643 first_error (_(reg_expected_msgs[regtype])); \
5644 goto failure; \
5645 } \
5646 inst.operands[i].reg = val; \
5647 inst.operands[i].isreg = 1; \
5648 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5649 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5650 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5651 || rtype == REG_TYPE_VFD \
5652 || rtype == REG_TYPE_NQ); \
dcbf9037 5653 } \
e07e6e58
NC
5654 while (0)
5655
5656#define po_reg_or_goto(regtype, label) \
5657 do \
5658 { \
5659 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5660 & inst.operands[i].vectype); \
5661 if (val == FAIL) \
5662 goto label; \
dcbf9037 5663 \
e07e6e58
NC
5664 inst.operands[i].reg = val; \
5665 inst.operands[i].isreg = 1; \
5666 inst.operands[i].isquad = (rtype == REG_TYPE_NQ); \
5667 inst.operands[i].issingle = (rtype == REG_TYPE_VFS); \
5668 inst.operands[i].isvec = (rtype == REG_TYPE_VFS \
5669 || rtype == REG_TYPE_VFD \
5670 || rtype == REG_TYPE_NQ); \
5671 } \
5672 while (0)
5673
5674#define po_imm_or_fail(min, max, popt) \
5675 do \
5676 { \
5677 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5678 goto failure; \
5679 inst.operands[i].imm = val; \
5680 } \
5681 while (0)
5682
5683#define po_scalar_or_goto(elsz, label) \
5684 do \
5685 { \
5686 val = parse_scalar (& str, elsz, & inst.operands[i].vectype); \
5687 if (val == FAIL) \
5688 goto label; \
5689 inst.operands[i].reg = val; \
5690 inst.operands[i].isscalar = 1; \
5691 } \
5692 while (0)
5693
5694#define po_misc_or_fail(expr) \
5695 do \
5696 { \
5697 if (expr) \
5698 goto failure; \
5699 } \
5700 while (0)
5701
5702#define po_misc_or_fail_no_backtrack(expr) \
5703 do \
5704 { \
5705 result = expr; \
5706 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5707 backtrack_pos = 0; \
5708 if (result != PARSE_OPERAND_SUCCESS) \
5709 goto failure; \
5710 } \
5711 while (0)
4962c51a 5712
c19d1205
ZW
5713 skip_whitespace (str);
5714
5715 for (i = 0; upat[i] != OP_stop; i++)
5716 {
5717 if (upat[i] >= OP_FIRST_OPTIONAL)
5718 {
5719 /* Remember where we are in case we need to backtrack. */
9c2799c2 5720 gas_assert (!backtrack_pos);
c19d1205
ZW
5721 backtrack_pos = str;
5722 backtrack_error = inst.error;
5723 backtrack_index = i;
5724 }
5725
b6702015 5726 if (i > 0 && (i > 1 || inst.operands[0].present))
c19d1205
ZW
5727 po_char_or_fail (',');
5728
5729 switch (upat[i])
5730 {
5731 /* Registers */
5732 case OP_oRRnpc:
5733 case OP_RRnpc:
5734 case OP_oRR:
5735 case OP_RR: po_reg_or_fail (REG_TYPE_RN); break;
5736 case OP_RCP: po_reg_or_fail (REG_TYPE_CP); break;
5737 case OP_RCN: po_reg_or_fail (REG_TYPE_CN); break;
5738 case OP_RF: po_reg_or_fail (REG_TYPE_FN); break;
5739 case OP_RVS: po_reg_or_fail (REG_TYPE_VFS); break;
5740 case OP_RVD: po_reg_or_fail (REG_TYPE_VFD); break;
5287ad62
JB
5741 case OP_oRND:
5742 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
cd2cf30b
PB
5743 case OP_RVC:
5744 po_reg_or_goto (REG_TYPE_VFC, coproc_reg);
5745 break;
5746 /* Also accept generic coprocessor regs for unknown registers. */
5747 coproc_reg:
5748 po_reg_or_fail (REG_TYPE_CN);
5749 break;
c19d1205
ZW
5750 case OP_RMF: po_reg_or_fail (REG_TYPE_MVF); break;
5751 case OP_RMD: po_reg_or_fail (REG_TYPE_MVD); break;
5752 case OP_RMFX: po_reg_or_fail (REG_TYPE_MVFX); break;
5753 case OP_RMDX: po_reg_or_fail (REG_TYPE_MVDX); break;
5754 case OP_RMAX: po_reg_or_fail (REG_TYPE_MVAX); break;
5755 case OP_RMDS: po_reg_or_fail (REG_TYPE_DSPSC); break;
5756 case OP_RIWR: po_reg_or_fail (REG_TYPE_MMXWR); break;
5757 case OP_RIWC: po_reg_or_fail (REG_TYPE_MMXWC); break;
5758 case OP_RIWG: po_reg_or_fail (REG_TYPE_MMXWCG); break;
5759 case OP_RXA: po_reg_or_fail (REG_TYPE_XSCALE); break;
5287ad62
JB
5760 case OP_oRNQ:
5761 case OP_RNQ: po_reg_or_fail (REG_TYPE_NQ); break;
5762 case OP_oRNDQ:
5763 case OP_RNDQ: po_reg_or_fail (REG_TYPE_NDQ); break;
037e8744
JB
5764 case OP_RVSD: po_reg_or_fail (REG_TYPE_VFSD); break;
5765 case OP_oRNSDQ:
5766 case OP_RNSDQ: po_reg_or_fail (REG_TYPE_NSDQ); break;
5287ad62
JB
5767
5768 /* Neon scalar. Using an element size of 8 means that some invalid
5769 scalars are accepted here, so deal with those in later code. */
5770 case OP_RNSC: po_scalar_or_goto (8, failure); break;
5771
5772 /* WARNING: We can expand to two operands here. This has the potential
5773 to totally confuse the backtracking mechanism! It will be OK at
5774 least as long as we don't try to use optional args as well,
5775 though. */
5776 case OP_NILO:
5777 {
5778 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
466bbf93 5779 inst.operands[i].present = 1;
5287ad62
JB
5780 i++;
5781 skip_past_comma (&str);
5782 po_reg_or_goto (REG_TYPE_NDQ, one_reg_only);
5783 break;
5784 one_reg_only:
5785 /* Optional register operand was omitted. Unfortunately, it's in
5786 operands[i-1] and we need it to be in inst.operands[i]. Fix that
5787 here (this is a bit grotty). */
5788 inst.operands[i] = inst.operands[i-1];
5789 inst.operands[i-1].present = 0;
5790 break;
5791 try_imm:
036dc3f7
PB
5792 /* There's a possibility of getting a 64-bit immediate here, so
5793 we need special handling. */
5794 if (parse_big_immediate (&str, i) == FAIL)
5795 {
5796 inst.error = _("immediate value is out of range");
5797 goto failure;
5798 }
5287ad62
JB
5799 }
5800 break;
5801
5802 case OP_RNDQ_I0:
5803 {
5804 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5805 break;
5806 try_imm0:
5807 po_imm_or_fail (0, 0, TRUE);
5808 }
5809 break;
5810
037e8744
JB
5811 case OP_RVSD_I0:
5812 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5813 break;
5814
5287ad62
JB
5815 case OP_RR_RNSC:
5816 {
5817 po_scalar_or_goto (8, try_rr);
5818 break;
5819 try_rr:
5820 po_reg_or_fail (REG_TYPE_RN);
5821 }
5822 break;
5823
037e8744
JB
5824 case OP_RNSDQ_RNSC:
5825 {
5826 po_scalar_or_goto (8, try_nsdq);
5827 break;
5828 try_nsdq:
5829 po_reg_or_fail (REG_TYPE_NSDQ);
5830 }
5831 break;
5832
5287ad62
JB
5833 case OP_RNDQ_RNSC:
5834 {
5835 po_scalar_or_goto (8, try_ndq);
5836 break;
5837 try_ndq:
5838 po_reg_or_fail (REG_TYPE_NDQ);
5839 }
5840 break;
5841
5842 case OP_RND_RNSC:
5843 {
5844 po_scalar_or_goto (8, try_vfd);
5845 break;
5846 try_vfd:
5847 po_reg_or_fail (REG_TYPE_VFD);
5848 }
5849 break;
5850
5851 case OP_VMOV:
5852 /* WARNING: parse_neon_mov can move the operand counter, i. If we're
5853 not careful then bad things might happen. */
5854 po_misc_or_fail (parse_neon_mov (&str, &i) == FAIL);
5855 break;
5856
5857 case OP_RNDQ_IMVNb:
5858 {
5859 po_reg_or_goto (REG_TYPE_NDQ, try_mvnimm);
5860 break;
5861 try_mvnimm:
5862 /* There's a possibility of getting a 64-bit immediate here, so
5863 we need special handling. */
5864 if (parse_big_immediate (&str, i) == FAIL)
5865 {
5866 inst.error = _("immediate value is out of range");
5867 goto failure;
5868 }
5869 }
5870 break;
5871
5872 case OP_RNDQ_I63b:
5873 {
5874 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5875 break;
5876 try_shimm:
5877 po_imm_or_fail (0, 63, TRUE);
5878 }
5879 break;
c19d1205
ZW
5880
5881 case OP_RRnpcb:
5882 po_char_or_fail ('[');
5883 po_reg_or_fail (REG_TYPE_RN);
5884 po_char_or_fail (']');
5885 break;
a737bd4d 5886
c19d1205 5887 case OP_RRw:
b6702015 5888 case OP_oRRw:
c19d1205
ZW
5889 po_reg_or_fail (REG_TYPE_RN);
5890 if (skip_past_char (&str, '!') == SUCCESS)
5891 inst.operands[i].writeback = 1;
5892 break;
5893
5894 /* Immediates */
5895 case OP_I7: po_imm_or_fail ( 0, 7, FALSE); break;
5896 case OP_I15: po_imm_or_fail ( 0, 15, FALSE); break;
5897 case OP_I16: po_imm_or_fail ( 1, 16, FALSE); break;
5287ad62 5898 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
c19d1205
ZW
5899 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5900 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5287ad62 5901 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
c19d1205 5902 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
5287ad62
JB
5903 case OP_I63: po_imm_or_fail ( 0, 63, FALSE); break;
5904 case OP_I64: po_imm_or_fail ( 1, 64, FALSE); break;
5905 case OP_I64z: po_imm_or_fail ( 0, 64, FALSE); break;
c19d1205 5906 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
c19d1205
ZW
5907
5908 case OP_I4b: po_imm_or_fail ( 1, 4, TRUE); break;
5909 case OP_oI7b:
5910 case OP_I7b: po_imm_or_fail ( 0, 7, TRUE); break;
5911 case OP_I15b: po_imm_or_fail ( 0, 15, TRUE); break;
5912 case OP_oI31b:
5913 case OP_I31b: po_imm_or_fail ( 0, 31, TRUE); break;
5287ad62 5914 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
c19d1205
ZW
5915 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
5916
5917 /* Immediate variants */
5918 case OP_oI255c:
5919 po_char_or_fail ('{');
5920 po_imm_or_fail (0, 255, TRUE);
5921 po_char_or_fail ('}');
5922 break;
5923
5924 case OP_I31w:
5925 /* The expression parser chokes on a trailing !, so we have
5926 to find it first and zap it. */
5927 {
5928 char *s = str;
5929 while (*s && *s != ',')
5930 s++;
5931 if (s[-1] == '!')
5932 {
5933 s[-1] = '\0';
5934 inst.operands[i].writeback = 1;
5935 }
5936 po_imm_or_fail (0, 31, TRUE);
5937 if (str == s - 1)
5938 str = s;
5939 }
5940 break;
5941
5942 /* Expressions */
5943 case OP_EXPi: EXPi:
5944 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5945 GE_OPT_PREFIX));
5946 break;
5947
5948 case OP_EXP:
5949 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5950 GE_NO_PREFIX));
5951 break;
5952
5953 case OP_EXPr: EXPr:
5954 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5955 GE_NO_PREFIX));
5956 if (inst.reloc.exp.X_op == O_symbol)
a737bd4d 5957 {
c19d1205
ZW
5958 val = parse_reloc (&str);
5959 if (val == -1)
5960 {
5961 inst.error = _("unrecognized relocation suffix");
5962 goto failure;
5963 }
5964 else if (val != BFD_RELOC_UNUSED)
5965 {
5966 inst.operands[i].imm = val;
5967 inst.operands[i].hasreloc = 1;
5968 }
a737bd4d 5969 }
c19d1205 5970 break;
a737bd4d 5971
b6895b4f
PB
5972 /* Operand for MOVW or MOVT. */
5973 case OP_HALF:
5974 po_misc_or_fail (parse_half (&str));
5975 break;
5976
e07e6e58 5977 /* Register or expression. */
c19d1205
ZW
5978 case OP_RR_EXr: po_reg_or_goto (REG_TYPE_RN, EXPr); break;
5979 case OP_RR_EXi: po_reg_or_goto (REG_TYPE_RN, EXPi); break;
a737bd4d 5980
e07e6e58 5981 /* Register or immediate. */
c19d1205
ZW
5982 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5983 I0: po_imm_or_fail (0, 0, FALSE); break;
a737bd4d 5984
c19d1205
ZW
5985 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
5986 IF:
5987 if (!is_immediate_prefix (*str))
5988 goto bad_args;
5989 str++;
5990 val = parse_fpa_immediate (&str);
5991 if (val == FAIL)
5992 goto failure;
5993 /* FPA immediates are encoded as registers 8-15.
5994 parse_fpa_immediate has already applied the offset. */
5995 inst.operands[i].reg = val;
5996 inst.operands[i].isreg = 1;
5997 break;
09d92015 5998
2d447fca
JM
5999 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6000 I32z: po_imm_or_fail (0, 32, FALSE); break;
6001
e07e6e58 6002 /* Two kinds of register. */
c19d1205
ZW
6003 case OP_RIWR_RIWC:
6004 {
6005 struct reg_entry *rege = arm_reg_parse_multi (&str);
97f87066
JM
6006 if (!rege
6007 || (rege->type != REG_TYPE_MMXWR
6008 && rege->type != REG_TYPE_MMXWC
6009 && rege->type != REG_TYPE_MMXWCG))
c19d1205
ZW
6010 {
6011 inst.error = _("iWMMXt data or control register expected");
6012 goto failure;
6013 }
6014 inst.operands[i].reg = rege->number;
6015 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6016 }
6017 break;
09d92015 6018
41adaa5c
JM
6019 case OP_RIWC_RIWG:
6020 {
6021 struct reg_entry *rege = arm_reg_parse_multi (&str);
6022 if (!rege
6023 || (rege->type != REG_TYPE_MMXWC
6024 && rege->type != REG_TYPE_MMXWCG))
6025 {
6026 inst.error = _("iWMMXt control register expected");
6027 goto failure;
6028 }
6029 inst.operands[i].reg = rege->number;
6030 inst.operands[i].isreg = 1;
6031 }
6032 break;
6033
c19d1205
ZW
6034 /* Misc */
6035 case OP_CPSF: val = parse_cps_flags (&str); break;
6036 case OP_ENDI: val = parse_endian_specifier (&str); break;
6037 case OP_oROR: val = parse_ror (&str); break;
6038 case OP_PSR: val = parse_psr (&str); break;
6039 case OP_COND: val = parse_cond (&str); break;
62b3e311 6040 case OP_oBARRIER:val = parse_barrier (&str); break;
c19d1205 6041
037e8744
JB
6042 case OP_RVC_PSR:
6043 po_reg_or_goto (REG_TYPE_VFC, try_psr);
6044 inst.operands[i].isvec = 1; /* Mark VFP control reg as vector. */
6045 break;
6046 try_psr:
6047 val = parse_psr (&str);
6048 break;
6049
6050 case OP_APSR_RR:
6051 po_reg_or_goto (REG_TYPE_RN, try_apsr);
6052 break;
6053 try_apsr:
6054 /* Parse "APSR_nvzc" operand (for FMSTAT-equivalent MRS
6055 instruction). */
6056 if (strncasecmp (str, "APSR_", 5) == 0)
6057 {
6058 unsigned found = 0;
6059 str += 5;
6060 while (found < 15)
6061 switch (*str++)
6062 {
6063 case 'c': found = (found & 1) ? 16 : found | 1; break;
6064 case 'n': found = (found & 2) ? 16 : found | 2; break;
6065 case 'z': found = (found & 4) ? 16 : found | 4; break;
6066 case 'v': found = (found & 8) ? 16 : found | 8; break;
6067 default: found = 16;
6068 }
6069 if (found != 15)
6070 goto failure;
6071 inst.operands[i].isvec = 1;
6072 }
6073 else
6074 goto failure;
6075 break;
6076
92e90b6e
PB
6077 case OP_TB:
6078 po_misc_or_fail (parse_tb (&str));
6079 break;
6080
e07e6e58 6081 /* Register lists. */
c19d1205
ZW
6082 case OP_REGLST:
6083 val = parse_reg_list (&str);
6084 if (*str == '^')
6085 {
6086 inst.operands[1].writeback = 1;
6087 str++;
6088 }
6089 break;
09d92015 6090
c19d1205 6091 case OP_VRSLST:
5287ad62 6092 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
c19d1205 6093 break;
09d92015 6094
c19d1205 6095 case OP_VRDLST:
5287ad62 6096 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
c19d1205 6097 break;
a737bd4d 6098
037e8744
JB
6099 case OP_VRSDLST:
6100 /* Allow Q registers too. */
6101 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6102 REGLIST_NEON_D);
6103 if (val == FAIL)
6104 {
6105 inst.error = NULL;
6106 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6107 REGLIST_VFP_S);
6108 inst.operands[i].issingle = 1;
6109 }
6110 break;
6111
5287ad62
JB
6112 case OP_NRDLST:
6113 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6114 REGLIST_NEON_D);
6115 break;
6116
6117 case OP_NSTRLST:
dcbf9037
JB
6118 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6119 &inst.operands[i].vectype);
5287ad62
JB
6120 break;
6121
c19d1205
ZW
6122 /* Addressing modes */
6123 case OP_ADDR:
6124 po_misc_or_fail (parse_address (&str, i));
6125 break;
09d92015 6126
4962c51a
MS
6127 case OP_ADDRGLDR:
6128 po_misc_or_fail_no_backtrack (
6129 parse_address_group_reloc (&str, i, GROUP_LDR));
6130 break;
6131
6132 case OP_ADDRGLDRS:
6133 po_misc_or_fail_no_backtrack (
6134 parse_address_group_reloc (&str, i, GROUP_LDRS));
6135 break;
6136
6137 case OP_ADDRGLDC:
6138 po_misc_or_fail_no_backtrack (
6139 parse_address_group_reloc (&str, i, GROUP_LDC));
6140 break;
6141
c19d1205
ZW
6142 case OP_SH:
6143 po_misc_or_fail (parse_shifter_operand (&str, i));
6144 break;
09d92015 6145
4962c51a
MS
6146 case OP_SHG:
6147 po_misc_or_fail_no_backtrack (
6148 parse_shifter_operand_group_reloc (&str, i));
6149 break;
6150
c19d1205
ZW
6151 case OP_oSHll:
6152 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6153 break;
09d92015 6154
c19d1205
ZW
6155 case OP_oSHar:
6156 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6157 break;
09d92015 6158
c19d1205
ZW
6159 case OP_oSHllar:
6160 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6161 break;
09d92015 6162
c19d1205 6163 default:
bd3ba5d1 6164 as_fatal (_("unhandled operand code %d"), upat[i]);
c19d1205 6165 }
09d92015 6166
c19d1205
ZW
6167 /* Various value-based sanity checks and shared operations. We
6168 do not signal immediate failures for the register constraints;
6169 this allows a syntax error to take precedence. */
6170 switch (upat[i])
6171 {
6172 case OP_oRRnpc:
6173 case OP_RRnpc:
6174 case OP_RRnpcb:
6175 case OP_RRw:
b6702015 6176 case OP_oRRw:
c19d1205
ZW
6177 case OP_RRnpc_I0:
6178 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6179 inst.error = BAD_PC;
6180 break;
09d92015 6181
c19d1205
ZW
6182 case OP_CPSF:
6183 case OP_ENDI:
6184 case OP_oROR:
6185 case OP_PSR:
037e8744 6186 case OP_RVC_PSR:
c19d1205 6187 case OP_COND:
62b3e311 6188 case OP_oBARRIER:
c19d1205
ZW
6189 case OP_REGLST:
6190 case OP_VRSLST:
6191 case OP_VRDLST:
037e8744 6192 case OP_VRSDLST:
5287ad62
JB
6193 case OP_NRDLST:
6194 case OP_NSTRLST:
c19d1205
ZW
6195 if (val == FAIL)
6196 goto failure;
6197 inst.operands[i].imm = val;
6198 break;
a737bd4d 6199
c19d1205
ZW
6200 default:
6201 break;
6202 }
09d92015 6203
c19d1205
ZW
6204 /* If we get here, this operand was successfully parsed. */
6205 inst.operands[i].present = 1;
6206 continue;
09d92015 6207
c19d1205 6208 bad_args:
09d92015 6209 inst.error = BAD_ARGS;
c19d1205
ZW
6210
6211 failure:
6212 if (!backtrack_pos)
d252fdde
PB
6213 {
6214 /* The parse routine should already have set inst.error, but set a
5f4273c7 6215 default here just in case. */
d252fdde
PB
6216 if (!inst.error)
6217 inst.error = _("syntax error");
6218 return FAIL;
6219 }
c19d1205
ZW
6220
6221 /* Do not backtrack over a trailing optional argument that
6222 absorbed some text. We will only fail again, with the
6223 'garbage following instruction' error message, which is
6224 probably less helpful than the current one. */
6225 if (backtrack_index == i && backtrack_pos != str
6226 && upat[i+1] == OP_stop)
d252fdde
PB
6227 {
6228 if (!inst.error)
6229 inst.error = _("syntax error");
6230 return FAIL;
6231 }
c19d1205
ZW
6232
6233 /* Try again, skipping the optional argument at backtrack_pos. */
6234 str = backtrack_pos;
6235 inst.error = backtrack_error;
6236 inst.operands[backtrack_index].present = 0;
6237 i = backtrack_index;
6238 backtrack_pos = 0;
09d92015 6239 }
09d92015 6240
c19d1205
ZW
6241 /* Check that we have parsed all the arguments. */
6242 if (*str != '\0' && !inst.error)
6243 inst.error = _("garbage following instruction");
09d92015 6244
c19d1205 6245 return inst.error ? FAIL : SUCCESS;
09d92015
MM
6246}
6247
c19d1205
ZW
6248#undef po_char_or_fail
6249#undef po_reg_or_fail
6250#undef po_reg_or_goto
6251#undef po_imm_or_fail
5287ad62 6252#undef po_scalar_or_fail
e07e6e58 6253
c19d1205 6254/* Shorthand macro for instruction encoding functions issuing errors. */
e07e6e58
NC
6255#define constraint(expr, err) \
6256 do \
c19d1205 6257 { \
e07e6e58
NC
6258 if (expr) \
6259 { \
6260 inst.error = err; \
6261 return; \
6262 } \
c19d1205 6263 } \
e07e6e58 6264 while (0)
c19d1205 6265
fdfde340
JM
6266/* Reject "bad registers" for Thumb-2 instructions. Many Thumb-2
6267 instructions are unpredictable if these registers are used. This
6268 is the BadReg predicate in ARM's Thumb-2 documentation. */
6269#define reject_bad_reg(reg) \
6270 do \
6271 if (reg == REG_SP || reg == REG_PC) \
6272 { \
6273 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6274 return; \
6275 } \
6276 while (0)
6277
94206790
MM
6278/* If REG is R13 (the stack pointer), warn that its use is
6279 deprecated. */
6280#define warn_deprecated_sp(reg) \
6281 do \
6282 if (warn_on_deprecated && reg == REG_SP) \
6283 as_warn (_("use of r13 is deprecated")); \
6284 while (0)
6285
c19d1205
ZW
6286/* Functions for operand encoding. ARM, then Thumb. */
6287
6288#define rotate_left(v, n) (v << n | v >> (32 - n))
6289
6290/* If VAL can be encoded in the immediate field of an ARM instruction,
6291 return the encoded form. Otherwise, return FAIL. */
6292
6293static unsigned int
6294encode_arm_immediate (unsigned int val)
09d92015 6295{
c19d1205
ZW
6296 unsigned int a, i;
6297
6298 for (i = 0; i < 32; i += 2)
6299 if ((a = rotate_left (val, i)) <= 0xff)
6300 return a | (i << 7); /* 12-bit pack: [shift-cnt,const]. */
6301
6302 return FAIL;
09d92015
MM
6303}
6304
c19d1205
ZW
6305/* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6306 return the encoded form. Otherwise, return FAIL. */
6307static unsigned int
6308encode_thumb32_immediate (unsigned int val)
09d92015 6309{
c19d1205 6310 unsigned int a, i;
09d92015 6311
9c3c69f2 6312 if (val <= 0xff)
c19d1205 6313 return val;
a737bd4d 6314
9c3c69f2 6315 for (i = 1; i <= 24; i++)
09d92015 6316 {
9c3c69f2
PB
6317 a = val >> i;
6318 if ((val & ~(0xff << i)) == 0)
6319 return ((val >> i) & 0x7f) | ((32 - i) << 7);
09d92015 6320 }
a737bd4d 6321
c19d1205
ZW
6322 a = val & 0xff;
6323 if (val == ((a << 16) | a))
6324 return 0x100 | a;
6325 if (val == ((a << 24) | (a << 16) | (a << 8) | a))
6326 return 0x300 | a;
09d92015 6327
c19d1205
ZW
6328 a = val & 0xff00;
6329 if (val == ((a << 16) | a))
6330 return 0x200 | (a >> 8);
a737bd4d 6331
c19d1205 6332 return FAIL;
09d92015 6333}
5287ad62 6334/* Encode a VFP SP or DP register number into inst.instruction. */
09d92015
MM
6335
6336static void
5287ad62
JB
6337encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6338{
6339 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6340 && reg > 15)
6341 {
b1cc4aeb 6342 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
5287ad62
JB
6343 {
6344 if (thumb_mode)
6345 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
b1cc4aeb 6346 fpu_vfp_ext_d32);
5287ad62
JB
6347 else
6348 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
b1cc4aeb 6349 fpu_vfp_ext_d32);
5287ad62
JB
6350 }
6351 else
6352 {
dcbf9037 6353 first_error (_("D register out of range for selected VFP version"));
5287ad62
JB
6354 return;
6355 }
6356 }
6357
c19d1205 6358 switch (pos)
09d92015 6359 {
c19d1205
ZW
6360 case VFP_REG_Sd:
6361 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6362 break;
6363
6364 case VFP_REG_Sn:
6365 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6366 break;
6367
6368 case VFP_REG_Sm:
6369 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6370 break;
6371
5287ad62
JB
6372 case VFP_REG_Dd:
6373 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6374 break;
5f4273c7 6375
5287ad62
JB
6376 case VFP_REG_Dn:
6377 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6378 break;
5f4273c7 6379
5287ad62
JB
6380 case VFP_REG_Dm:
6381 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6382 break;
6383
c19d1205
ZW
6384 default:
6385 abort ();
09d92015 6386 }
09d92015
MM
6387}
6388
c19d1205 6389/* Encode a <shift> in an ARM-format instruction. The immediate,
55cf6793 6390 if any, is handled by md_apply_fix. */
09d92015 6391static void
c19d1205 6392encode_arm_shift (int i)
09d92015 6393{
c19d1205
ZW
6394 if (inst.operands[i].shift_kind == SHIFT_RRX)
6395 inst.instruction |= SHIFT_ROR << 5;
6396 else
09d92015 6397 {
c19d1205
ZW
6398 inst.instruction |= inst.operands[i].shift_kind << 5;
6399 if (inst.operands[i].immisreg)
6400 {
6401 inst.instruction |= SHIFT_BY_REG;
6402 inst.instruction |= inst.operands[i].imm << 8;
6403 }
6404 else
6405 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
09d92015 6406 }
c19d1205 6407}
09d92015 6408
c19d1205
ZW
6409static void
6410encode_arm_shifter_operand (int i)
6411{
6412 if (inst.operands[i].isreg)
09d92015 6413 {
c19d1205
ZW
6414 inst.instruction |= inst.operands[i].reg;
6415 encode_arm_shift (i);
09d92015 6416 }
c19d1205
ZW
6417 else
6418 inst.instruction |= INST_IMMEDIATE;
09d92015
MM
6419}
6420
c19d1205 6421/* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
09d92015 6422static void
c19d1205 6423encode_arm_addr_mode_common (int i, bfd_boolean is_t)
09d92015 6424{
9c2799c2 6425 gas_assert (inst.operands[i].isreg);
c19d1205 6426 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6427
c19d1205 6428 if (inst.operands[i].preind)
09d92015 6429 {
c19d1205
ZW
6430 if (is_t)
6431 {
6432 inst.error = _("instruction does not accept preindexed addressing");
6433 return;
6434 }
6435 inst.instruction |= PRE_INDEX;
6436 if (inst.operands[i].writeback)
6437 inst.instruction |= WRITE_BACK;
09d92015 6438
c19d1205
ZW
6439 }
6440 else if (inst.operands[i].postind)
6441 {
9c2799c2 6442 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
6443 if (is_t)
6444 inst.instruction |= WRITE_BACK;
6445 }
6446 else /* unindexed - only for coprocessor */
09d92015 6447 {
c19d1205 6448 inst.error = _("instruction does not accept unindexed addressing");
09d92015
MM
6449 return;
6450 }
6451
c19d1205
ZW
6452 if (((inst.instruction & WRITE_BACK) || !(inst.instruction & PRE_INDEX))
6453 && (((inst.instruction & 0x000f0000) >> 16)
6454 == ((inst.instruction & 0x0000f000) >> 12)))
6455 as_warn ((inst.instruction & LOAD_BIT)
6456 ? _("destination register same as write-back base")
6457 : _("source register same as write-back base"));
09d92015
MM
6458}
6459
c19d1205
ZW
6460/* inst.operands[i] was set up by parse_address. Encode it into an
6461 ARM-format mode 2 load or store instruction. If is_t is true,
6462 reject forms that cannot be used with a T instruction (i.e. not
6463 post-indexed). */
a737bd4d 6464static void
c19d1205 6465encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
09d92015 6466{
c19d1205 6467 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6468
c19d1205 6469 if (inst.operands[i].immisreg)
09d92015 6470 {
c19d1205
ZW
6471 inst.instruction |= INST_IMMEDIATE; /* yes, this is backwards */
6472 inst.instruction |= inst.operands[i].imm;
6473 if (!inst.operands[i].negative)
6474 inst.instruction |= INDEX_UP;
6475 if (inst.operands[i].shifted)
6476 {
6477 if (inst.operands[i].shift_kind == SHIFT_RRX)
6478 inst.instruction |= SHIFT_ROR << 5;
6479 else
6480 {
6481 inst.instruction |= inst.operands[i].shift_kind << 5;
6482 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6483 }
6484 }
09d92015 6485 }
c19d1205 6486 else /* immediate offset in inst.reloc */
09d92015 6487 {
c19d1205
ZW
6488 if (inst.reloc.type == BFD_RELOC_UNUSED)
6489 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
09d92015 6490 }
09d92015
MM
6491}
6492
c19d1205
ZW
6493/* inst.operands[i] was set up by parse_address. Encode it into an
6494 ARM-format mode 3 load or store instruction. Reject forms that
6495 cannot be used with such instructions. If is_t is true, reject
6496 forms that cannot be used with a T instruction (i.e. not
6497 post-indexed). */
6498static void
6499encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
09d92015 6500{
c19d1205 6501 if (inst.operands[i].immisreg && inst.operands[i].shifted)
09d92015 6502 {
c19d1205
ZW
6503 inst.error = _("instruction does not accept scaled register index");
6504 return;
09d92015 6505 }
a737bd4d 6506
c19d1205 6507 encode_arm_addr_mode_common (i, is_t);
a737bd4d 6508
c19d1205
ZW
6509 if (inst.operands[i].immisreg)
6510 {
6511 inst.instruction |= inst.operands[i].imm;
6512 if (!inst.operands[i].negative)
6513 inst.instruction |= INDEX_UP;
6514 }
6515 else /* immediate offset in inst.reloc */
6516 {
6517 inst.instruction |= HWOFFSET_IMM;
6518 if (inst.reloc.type == BFD_RELOC_UNUSED)
6519 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
c19d1205 6520 }
a737bd4d
NC
6521}
6522
c19d1205
ZW
6523/* inst.operands[i] was set up by parse_address. Encode it into an
6524 ARM-format instruction. Reject all forms which cannot be encoded
6525 into a coprocessor load/store instruction. If wb_ok is false,
6526 reject use of writeback; if unind_ok is false, reject use of
6527 unindexed addressing. If reloc_override is not 0, use it instead
4962c51a
MS
6528 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6529 (in which case it is preserved). */
09d92015 6530
c19d1205
ZW
6531static int
6532encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
09d92015 6533{
c19d1205 6534 inst.instruction |= inst.operands[i].reg << 16;
a737bd4d 6535
9c2799c2 6536 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
09d92015 6537
c19d1205 6538 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
09d92015 6539 {
9c2799c2 6540 gas_assert (!inst.operands[i].writeback);
c19d1205
ZW
6541 if (!unind_ok)
6542 {
6543 inst.error = _("instruction does not support unindexed addressing");
6544 return FAIL;
6545 }
6546 inst.instruction |= inst.operands[i].imm;
6547 inst.instruction |= INDEX_UP;
6548 return SUCCESS;
09d92015 6549 }
a737bd4d 6550
c19d1205
ZW
6551 if (inst.operands[i].preind)
6552 inst.instruction |= PRE_INDEX;
a737bd4d 6553
c19d1205 6554 if (inst.operands[i].writeback)
09d92015 6555 {
c19d1205
ZW
6556 if (inst.operands[i].reg == REG_PC)
6557 {
6558 inst.error = _("pc may not be used with write-back");
6559 return FAIL;
6560 }
6561 if (!wb_ok)
6562 {
6563 inst.error = _("instruction does not support writeback");
6564 return FAIL;
6565 }
6566 inst.instruction |= WRITE_BACK;
09d92015 6567 }
a737bd4d 6568
c19d1205
ZW
6569 if (reloc_override)
6570 inst.reloc.type = reloc_override;
4962c51a
MS
6571 else if ((inst.reloc.type < BFD_RELOC_ARM_ALU_PC_G0_NC
6572 || inst.reloc.type > BFD_RELOC_ARM_LDC_SB_G2)
6573 && inst.reloc.type != BFD_RELOC_ARM_LDR_PC_G0)
6574 {
6575 if (thumb_mode)
6576 inst.reloc.type = BFD_RELOC_ARM_T32_CP_OFF_IMM;
6577 else
6578 inst.reloc.type = BFD_RELOC_ARM_CP_OFF_IMM;
6579 }
6580
c19d1205
ZW
6581 return SUCCESS;
6582}
a737bd4d 6583
c19d1205
ZW
6584/* inst.reloc.exp describes an "=expr" load pseudo-operation.
6585 Determine whether it can be performed with a move instruction; if
6586 it can, convert inst.instruction to that move instruction and
6587 return 1; if it can't, convert inst.instruction to a literal-pool
6588 load and return 0. If this is not a valid thing to do in the
6589 current context, set inst.error and return 1.
a737bd4d 6590
c19d1205
ZW
6591 inst.operands[i] describes the destination register. */
6592
6593static int
6594move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6595{
53365c0d
PB
6596 unsigned long tbit;
6597
6598 if (thumb_p)
6599 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6600 else
6601 tbit = LOAD_BIT;
6602
6603 if ((inst.instruction & tbit) == 0)
09d92015 6604 {
c19d1205
ZW
6605 inst.error = _("invalid pseudo operation");
6606 return 1;
09d92015 6607 }
c19d1205 6608 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
09d92015
MM
6609 {
6610 inst.error = _("constant expression expected");
c19d1205 6611 return 1;
09d92015 6612 }
c19d1205 6613 if (inst.reloc.exp.X_op == O_constant)
09d92015 6614 {
c19d1205
ZW
6615 if (thumb_p)
6616 {
53365c0d 6617 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
c19d1205
ZW
6618 {
6619 /* This can be done with a mov(1) instruction. */
6620 inst.instruction = T_OPCODE_MOV_I8 | (inst.operands[i].reg << 8);
6621 inst.instruction |= inst.reloc.exp.X_add_number;
6622 return 1;
6623 }
6624 }
6625 else
6626 {
6627 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6628 if (value != FAIL)
6629 {
6630 /* This can be done with a mov instruction. */
6631 inst.instruction &= LITERAL_MASK;
6632 inst.instruction |= INST_IMMEDIATE | (OPCODE_MOV << DATA_OP_SHIFT);
6633 inst.instruction |= value & 0xfff;
6634 return 1;
6635 }
09d92015 6636
c19d1205
ZW
6637 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6638 if (value != FAIL)
6639 {
6640 /* This can be done with a mvn instruction. */
6641 inst.instruction &= LITERAL_MASK;
6642 inst.instruction |= INST_IMMEDIATE | (OPCODE_MVN << DATA_OP_SHIFT);
6643 inst.instruction |= value & 0xfff;
6644 return 1;
6645 }
6646 }
09d92015
MM
6647 }
6648
c19d1205
ZW
6649 if (add_to_lit_pool () == FAIL)
6650 {
6651 inst.error = _("literal pool insertion failed");
6652 return 1;
6653 }
6654 inst.operands[1].reg = REG_PC;
6655 inst.operands[1].isreg = 1;
6656 inst.operands[1].preind = 1;
6657 inst.reloc.pc_rel = 1;
6658 inst.reloc.type = (thumb_p
6659 ? BFD_RELOC_ARM_THUMB_OFFSET
6660 : (mode_3
6661 ? BFD_RELOC_ARM_HWLITERAL
6662 : BFD_RELOC_ARM_LITERAL));
6663 return 0;
09d92015
MM
6664}
6665
5f4273c7 6666/* Functions for instruction encoding, sorted by sub-architecture.
c19d1205
ZW
6667 First some generics; their names are taken from the conventional
6668 bit positions for register arguments in ARM format instructions. */
09d92015 6669
a737bd4d 6670static void
c19d1205 6671do_noargs (void)
09d92015 6672{
c19d1205 6673}
a737bd4d 6674
c19d1205
ZW
6675static void
6676do_rd (void)
6677{
6678 inst.instruction |= inst.operands[0].reg << 12;
6679}
a737bd4d 6680
c19d1205
ZW
6681static void
6682do_rd_rm (void)
6683{
6684 inst.instruction |= inst.operands[0].reg << 12;
6685 inst.instruction |= inst.operands[1].reg;
6686}
09d92015 6687
c19d1205
ZW
6688static void
6689do_rd_rn (void)
6690{
6691 inst.instruction |= inst.operands[0].reg << 12;
6692 inst.instruction |= inst.operands[1].reg << 16;
6693}
a737bd4d 6694
c19d1205
ZW
6695static void
6696do_rn_rd (void)
6697{
6698 inst.instruction |= inst.operands[0].reg << 16;
6699 inst.instruction |= inst.operands[1].reg << 12;
6700}
09d92015 6701
c19d1205
ZW
6702static void
6703do_rd_rm_rn (void)
6704{
9a64e435 6705 unsigned Rn = inst.operands[2].reg;
708587a4 6706 /* Enforce restrictions on SWP instruction. */
9a64e435
PB
6707 if ((inst.instruction & 0x0fbfffff) == 0x01000090)
6708 constraint (Rn == inst.operands[0].reg || Rn == inst.operands[1].reg,
6709 _("Rn must not overlap other operands"));
c19d1205
ZW
6710 inst.instruction |= inst.operands[0].reg << 12;
6711 inst.instruction |= inst.operands[1].reg;
9a64e435 6712 inst.instruction |= Rn << 16;
c19d1205 6713}
09d92015 6714
c19d1205
ZW
6715static void
6716do_rd_rn_rm (void)
6717{
6718 inst.instruction |= inst.operands[0].reg << 12;
6719 inst.instruction |= inst.operands[1].reg << 16;
6720 inst.instruction |= inst.operands[2].reg;
6721}
a737bd4d 6722
c19d1205
ZW
6723static void
6724do_rm_rd_rn (void)
6725{
6726 inst.instruction |= inst.operands[0].reg;
6727 inst.instruction |= inst.operands[1].reg << 12;
6728 inst.instruction |= inst.operands[2].reg << 16;
6729}
09d92015 6730
c19d1205
ZW
6731static void
6732do_imm0 (void)
6733{
6734 inst.instruction |= inst.operands[0].imm;
6735}
09d92015 6736
c19d1205
ZW
6737static void
6738do_rd_cpaddr (void)
6739{
6740 inst.instruction |= inst.operands[0].reg << 12;
6741 encode_arm_cp_address (1, TRUE, TRUE, 0);
09d92015 6742}
a737bd4d 6743
c19d1205
ZW
6744/* ARM instructions, in alphabetical order by function name (except
6745 that wrapper functions appear immediately after the function they
6746 wrap). */
09d92015 6747
c19d1205
ZW
6748/* This is a pseudo-op of the form "adr rd, label" to be converted
6749 into a relative address of the form "add rd, pc, #label-.-8". */
09d92015
MM
6750
6751static void
c19d1205 6752do_adr (void)
09d92015 6753{
c19d1205 6754 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6755
c19d1205
ZW
6756 /* Frag hacking will turn this into a sub instruction if the offset turns
6757 out to be negative. */
6758 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
c19d1205 6759 inst.reloc.pc_rel = 1;
2fc8bdac 6760 inst.reloc.exp.X_add_number -= 8;
c19d1205 6761}
b99bd4ef 6762
c19d1205
ZW
6763/* This is a pseudo-op of the form "adrl rd, label" to be converted
6764 into a relative address of the form:
6765 add rd, pc, #low(label-.-8)"
6766 add rd, rd, #high(label-.-8)" */
b99bd4ef 6767
c19d1205
ZW
6768static void
6769do_adrl (void)
6770{
6771 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
a737bd4d 6772
c19d1205
ZW
6773 /* Frag hacking will turn this into a sub instruction if the offset turns
6774 out to be negative. */
6775 inst.reloc.type = BFD_RELOC_ARM_ADRL_IMMEDIATE;
c19d1205
ZW
6776 inst.reloc.pc_rel = 1;
6777 inst.size = INSN_SIZE * 2;
2fc8bdac 6778 inst.reloc.exp.X_add_number -= 8;
b99bd4ef
NC
6779}
6780
b99bd4ef 6781static void
c19d1205 6782do_arit (void)
b99bd4ef 6783{
c19d1205
ZW
6784 if (!inst.operands[1].present)
6785 inst.operands[1].reg = inst.operands[0].reg;
6786 inst.instruction |= inst.operands[0].reg << 12;
6787 inst.instruction |= inst.operands[1].reg << 16;
6788 encode_arm_shifter_operand (2);
6789}
b99bd4ef 6790
62b3e311
PB
6791static void
6792do_barrier (void)
6793{
6794 if (inst.operands[0].present)
6795 {
6796 constraint ((inst.instruction & 0xf0) != 0x40
6797 && inst.operands[0].imm != 0xf,
bd3ba5d1 6798 _("bad barrier type"));
62b3e311
PB
6799 inst.instruction |= inst.operands[0].imm;
6800 }
6801 else
6802 inst.instruction |= 0xf;
6803}
6804
c19d1205
ZW
6805static void
6806do_bfc (void)
6807{
6808 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
6809 constraint (msb > 32, _("bit-field extends past end of register"));
6810 /* The instruction encoding stores the LSB and MSB,
6811 not the LSB and width. */
6812 inst.instruction |= inst.operands[0].reg << 12;
6813 inst.instruction |= inst.operands[1].imm << 7;
6814 inst.instruction |= (msb - 1) << 16;
6815}
b99bd4ef 6816
c19d1205
ZW
6817static void
6818do_bfi (void)
6819{
6820 unsigned int msb;
b99bd4ef 6821
c19d1205
ZW
6822 /* #0 in second position is alternative syntax for bfc, which is
6823 the same instruction but with REG_PC in the Rm field. */
6824 if (!inst.operands[1].isreg)
6825 inst.operands[1].reg = REG_PC;
b99bd4ef 6826
c19d1205
ZW
6827 msb = inst.operands[2].imm + inst.operands[3].imm;
6828 constraint (msb > 32, _("bit-field extends past end of register"));
6829 /* The instruction encoding stores the LSB and MSB,
6830 not the LSB and width. */
6831 inst.instruction |= inst.operands[0].reg << 12;
6832 inst.instruction |= inst.operands[1].reg;
6833 inst.instruction |= inst.operands[2].imm << 7;
6834 inst.instruction |= (msb - 1) << 16;
b99bd4ef
NC
6835}
6836
b99bd4ef 6837static void
c19d1205 6838do_bfx (void)
b99bd4ef 6839{
c19d1205
ZW
6840 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
6841 _("bit-field extends past end of register"));
6842 inst.instruction |= inst.operands[0].reg << 12;
6843 inst.instruction |= inst.operands[1].reg;
6844 inst.instruction |= inst.operands[2].imm << 7;
6845 inst.instruction |= (inst.operands[3].imm - 1) << 16;
6846}
09d92015 6847
c19d1205
ZW
6848/* ARM V5 breakpoint instruction (argument parse)
6849 BKPT <16 bit unsigned immediate>
6850 Instruction is not conditional.
6851 The bit pattern given in insns[] has the COND_ALWAYS condition,
6852 and it is an error if the caller tried to override that. */
b99bd4ef 6853
c19d1205
ZW
6854static void
6855do_bkpt (void)
6856{
6857 /* Top 12 of 16 bits to bits 19:8. */
6858 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
09d92015 6859
c19d1205
ZW
6860 /* Bottom 4 of 16 bits to bits 3:0. */
6861 inst.instruction |= inst.operands[0].imm & 0xf;
6862}
09d92015 6863
c19d1205
ZW
6864static void
6865encode_branch (int default_reloc)
6866{
6867 if (inst.operands[0].hasreloc)
6868 {
6869 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6870 _("the only suffix valid here is '(plt)'"));
267bf995 6871 inst.reloc.type = BFD_RELOC_ARM_PLT32;
c19d1205 6872 }
b99bd4ef 6873 else
c19d1205
ZW
6874 {
6875 inst.reloc.type = default_reloc;
c19d1205 6876 }
2fc8bdac 6877 inst.reloc.pc_rel = 1;
b99bd4ef
NC
6878}
6879
b99bd4ef 6880static void
c19d1205 6881do_branch (void)
b99bd4ef 6882{
39b41c9c
PB
6883#ifdef OBJ_ELF
6884 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6885 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6886 else
6887#endif
6888 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
6889}
6890
6891static void
6892do_bl (void)
6893{
6894#ifdef OBJ_ELF
6895 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6896 {
6897 if (inst.cond == COND_ALWAYS)
6898 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6899 else
6900 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6901 }
6902 else
6903#endif
6904 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
c19d1205 6905}
b99bd4ef 6906
c19d1205
ZW
6907/* ARM V5 branch-link-exchange instruction (argument parse)
6908 BLX <target_addr> ie BLX(1)
6909 BLX{<condition>} <Rm> ie BLX(2)
6910 Unfortunately, there are two different opcodes for this mnemonic.
6911 So, the insns[].value is not used, and the code here zaps values
6912 into inst.instruction.
6913 Also, the <target_addr> can be 25 bits, hence has its own reloc. */
b99bd4ef 6914
c19d1205
ZW
6915static void
6916do_blx (void)
6917{
6918 if (inst.operands[0].isreg)
b99bd4ef 6919 {
c19d1205
ZW
6920 /* Arg is a register; the opcode provided by insns[] is correct.
6921 It is not illegal to do "blx pc", just useless. */
6922 if (inst.operands[0].reg == REG_PC)
6923 as_tsktsk (_("use of r15 in blx in ARM mode is not really useful"));
b99bd4ef 6924
c19d1205
ZW
6925 inst.instruction |= inst.operands[0].reg;
6926 }
6927 else
b99bd4ef 6928 {
c19d1205 6929 /* Arg is an address; this instruction cannot be executed
267bf995
RR
6930 conditionally, and the opcode must be adjusted.
6931 We retain the BFD_RELOC_ARM_PCREL_BLX till the very end
6932 where we generate out a BFD_RELOC_ARM_PCREL_CALL instead. */
c19d1205 6933 constraint (inst.cond != COND_ALWAYS, BAD_COND);
2fc8bdac 6934 inst.instruction = 0xfa000000;
267bf995 6935 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
b99bd4ef 6936 }
c19d1205
ZW
6937}
6938
6939static void
6940do_bx (void)
6941{
845b51d6
PB
6942 bfd_boolean want_reloc;
6943
c19d1205
ZW
6944 if (inst.operands[0].reg == REG_PC)
6945 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
b99bd4ef 6946
c19d1205 6947 inst.instruction |= inst.operands[0].reg;
845b51d6
PB
6948 /* Output R_ARM_V4BX relocations if is an EABI object that looks like
6949 it is for ARMv4t or earlier. */
6950 want_reloc = !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5);
6951 if (object_arch && !ARM_CPU_HAS_FEATURE (*object_arch, arm_ext_v5))
6952 want_reloc = TRUE;
6953
5ad34203 6954#ifdef OBJ_ELF
845b51d6 6955 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
5ad34203 6956#endif
584206db 6957 want_reloc = FALSE;
845b51d6
PB
6958
6959 if (want_reloc)
6960 inst.reloc.type = BFD_RELOC_ARM_V4BX;
09d92015
MM
6961}
6962
c19d1205
ZW
6963
6964/* ARM v5TEJ. Jump to Jazelle code. */
a737bd4d
NC
6965
6966static void
c19d1205 6967do_bxj (void)
a737bd4d 6968{
c19d1205
ZW
6969 if (inst.operands[0].reg == REG_PC)
6970 as_tsktsk (_("use of r15 in bxj is not really useful"));
6971
6972 inst.instruction |= inst.operands[0].reg;
a737bd4d
NC
6973}
6974
c19d1205
ZW
6975/* Co-processor data operation:
6976 CDP{cond} <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>}
6977 CDP2 <coproc>, <opcode_1>, <CRd>, <CRn>, <CRm>{, <opcode_2>} */
6978static void
6979do_cdp (void)
6980{
6981 inst.instruction |= inst.operands[0].reg << 8;
6982 inst.instruction |= inst.operands[1].imm << 20;
6983 inst.instruction |= inst.operands[2].reg << 12;
6984 inst.instruction |= inst.operands[3].reg << 16;
6985 inst.instruction |= inst.operands[4].reg;
6986 inst.instruction |= inst.operands[5].imm << 5;
6987}
a737bd4d
NC
6988
6989static void
c19d1205 6990do_cmp (void)
a737bd4d 6991{
c19d1205
ZW
6992 inst.instruction |= inst.operands[0].reg << 16;
6993 encode_arm_shifter_operand (1);
a737bd4d
NC
6994}
6995
c19d1205
ZW
6996/* Transfer between coprocessor and ARM registers.
6997 MRC{cond} <coproc>, <opcode_1>, <Rd>, <CRn>, <CRm>{, <opcode_2>}
6998 MRC2
6999 MCR{cond}
7000 MCR2
7001
7002 No special properties. */
09d92015
MM
7003
7004static void
c19d1205 7005do_co_reg (void)
09d92015 7006{
fdfde340
JM
7007 unsigned Rd;
7008
7009 Rd = inst.operands[2].reg;
7010 if (thumb_mode)
7011 {
7012 if (inst.instruction == 0xee000010
7013 || inst.instruction == 0xfe000010)
7014 /* MCR, MCR2 */
7015 reject_bad_reg (Rd);
7016 else
7017 /* MRC, MRC2 */
7018 constraint (Rd == REG_SP, BAD_SP);
7019 }
7020 else
7021 {
7022 /* MCR */
7023 if (inst.instruction == 0xe000010)
7024 constraint (Rd == REG_PC, BAD_PC);
7025 }
7026
7027
c19d1205
ZW
7028 inst.instruction |= inst.operands[0].reg << 8;
7029 inst.instruction |= inst.operands[1].imm << 21;
fdfde340 7030 inst.instruction |= Rd << 12;
c19d1205
ZW
7031 inst.instruction |= inst.operands[3].reg << 16;
7032 inst.instruction |= inst.operands[4].reg;
7033 inst.instruction |= inst.operands[5].imm << 5;
7034}
09d92015 7035
c19d1205
ZW
7036/* Transfer between coprocessor register and pair of ARM registers.
7037 MCRR{cond} <coproc>, <opcode>, <Rd>, <Rn>, <CRm>.
7038 MCRR2
7039 MRRC{cond}
7040 MRRC2
b99bd4ef 7041
c19d1205 7042 Two XScale instructions are special cases of these:
09d92015 7043
c19d1205
ZW
7044 MAR{cond} acc0, <RdLo>, <RdHi> == MCRR{cond} p0, #0, <RdLo>, <RdHi>, c0
7045 MRA{cond} acc0, <RdLo>, <RdHi> == MRRC{cond} p0, #0, <RdLo>, <RdHi>, c0
b99bd4ef 7046
5f4273c7 7047 Result unpredictable if Rd or Rn is R15. */
a737bd4d 7048
c19d1205
ZW
7049static void
7050do_co_reg2c (void)
7051{
fdfde340
JM
7052 unsigned Rd, Rn;
7053
7054 Rd = inst.operands[2].reg;
7055 Rn = inst.operands[3].reg;
7056
7057 if (thumb_mode)
7058 {
7059 reject_bad_reg (Rd);
7060 reject_bad_reg (Rn);
7061 }
7062 else
7063 {
7064 constraint (Rd == REG_PC, BAD_PC);
7065 constraint (Rn == REG_PC, BAD_PC);
7066 }
7067
c19d1205
ZW
7068 inst.instruction |= inst.operands[0].reg << 8;
7069 inst.instruction |= inst.operands[1].imm << 4;
fdfde340
JM
7070 inst.instruction |= Rd << 12;
7071 inst.instruction |= Rn << 16;
c19d1205 7072 inst.instruction |= inst.operands[4].reg;
b99bd4ef
NC
7073}
7074
c19d1205
ZW
7075static void
7076do_cpsi (void)
7077{
7078 inst.instruction |= inst.operands[0].imm << 6;
a028a6f5
PB
7079 if (inst.operands[1].present)
7080 {
7081 inst.instruction |= CPSI_MMOD;
7082 inst.instruction |= inst.operands[1].imm;
7083 }
c19d1205 7084}
b99bd4ef 7085
62b3e311
PB
7086static void
7087do_dbg (void)
7088{
7089 inst.instruction |= inst.operands[0].imm;
7090}
7091
b99bd4ef 7092static void
c19d1205 7093do_it (void)
b99bd4ef 7094{
c19d1205 7095 /* There is no IT instruction in ARM mode. We
e07e6e58
NC
7096 process it to do the validation as if in
7097 thumb mode, just in case the code gets
7098 assembled for thumb using the unified syntax. */
7099
c19d1205 7100 inst.size = 0;
e07e6e58
NC
7101 if (unified_syntax)
7102 {
7103 set_it_insn_type (IT_INSN);
7104 now_it.mask = (inst.instruction & 0xf) | 0x10;
7105 now_it.cc = inst.operands[0].imm;
7106 }
09d92015 7107}
b99bd4ef 7108
09d92015 7109static void
c19d1205 7110do_ldmstm (void)
ea6ef066 7111{
c19d1205
ZW
7112 int base_reg = inst.operands[0].reg;
7113 int range = inst.operands[1].imm;
ea6ef066 7114
c19d1205
ZW
7115 inst.instruction |= base_reg << 16;
7116 inst.instruction |= range;
ea6ef066 7117
c19d1205
ZW
7118 if (inst.operands[1].writeback)
7119 inst.instruction |= LDM_TYPE_2_OR_3;
09d92015 7120
c19d1205 7121 if (inst.operands[0].writeback)
ea6ef066 7122 {
c19d1205
ZW
7123 inst.instruction |= WRITE_BACK;
7124 /* Check for unpredictable uses of writeback. */
7125 if (inst.instruction & LOAD_BIT)
09d92015 7126 {
c19d1205
ZW
7127 /* Not allowed in LDM type 2. */
7128 if ((inst.instruction & LDM_TYPE_2_OR_3)
7129 && ((range & (1 << REG_PC)) == 0))
7130 as_warn (_("writeback of base register is UNPREDICTABLE"));
7131 /* Only allowed if base reg not in list for other types. */
7132 else if (range & (1 << base_reg))
7133 as_warn (_("writeback of base register when in register list is UNPREDICTABLE"));
7134 }
7135 else /* STM. */
7136 {
7137 /* Not allowed for type 2. */
7138 if (inst.instruction & LDM_TYPE_2_OR_3)
7139 as_warn (_("writeback of base register is UNPREDICTABLE"));
7140 /* Only allowed if base reg not in list, or first in list. */
7141 else if ((range & (1 << base_reg))
7142 && (range & ((1 << base_reg) - 1)))
7143 as_warn (_("if writeback register is in list, it must be the lowest reg in the list"));
09d92015 7144 }
ea6ef066 7145 }
a737bd4d
NC
7146}
7147
c19d1205
ZW
7148/* ARMv5TE load-consecutive (argument parse)
7149 Mode is like LDRH.
7150
7151 LDRccD R, mode
7152 STRccD R, mode. */
7153
a737bd4d 7154static void
c19d1205 7155do_ldrd (void)
a737bd4d 7156{
c19d1205
ZW
7157 constraint (inst.operands[0].reg % 2 != 0,
7158 _("first destination register must be even"));
7159 constraint (inst.operands[1].present
7160 && inst.operands[1].reg != inst.operands[0].reg + 1,
7161 _("can only load two consecutive registers"));
7162 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
7163 constraint (!inst.operands[2].isreg, _("'[' expected"));
a737bd4d 7164
c19d1205
ZW
7165 if (!inst.operands[1].present)
7166 inst.operands[1].reg = inst.operands[0].reg + 1;
5f4273c7 7167
c19d1205 7168 if (inst.instruction & LOAD_BIT)
a737bd4d 7169 {
c19d1205
ZW
7170 /* encode_arm_addr_mode_3 will diagnose overlap between the base
7171 register and the first register written; we have to diagnose
7172 overlap between the base and the second register written here. */
ea6ef066 7173
c19d1205
ZW
7174 if (inst.operands[2].reg == inst.operands[1].reg
7175 && (inst.operands[2].writeback || inst.operands[2].postind))
7176 as_warn (_("base register written back, and overlaps "
7177 "second destination register"));
b05fe5cf 7178
c19d1205
ZW
7179 /* For an index-register load, the index register must not overlap the
7180 destination (even if not write-back). */
7181 else if (inst.operands[2].immisreg
ca3f61f7
NC
7182 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7183 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
c19d1205 7184 as_warn (_("index register overlaps destination register"));
b05fe5cf 7185 }
c19d1205
ZW
7186
7187 inst.instruction |= inst.operands[0].reg << 12;
7188 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
b05fe5cf
ZW
7189}
7190
7191static void
c19d1205 7192do_ldrex (void)
b05fe5cf 7193{
c19d1205
ZW
7194 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
7195 || inst.operands[1].postind || inst.operands[1].writeback
7196 || inst.operands[1].immisreg || inst.operands[1].shifted
01cfc07f
NC
7197 || inst.operands[1].negative
7198 /* This can arise if the programmer has written
7199 strex rN, rM, foo
7200 or if they have mistakenly used a register name as the last
7201 operand, eg:
7202 strex rN, rM, rX
7203 It is very difficult to distinguish between these two cases
7204 because "rX" might actually be a label. ie the register
7205 name has been occluded by a symbol of the same name. So we
7206 just generate a general 'bad addressing mode' type error
7207 message and leave it up to the programmer to discover the
7208 true cause and fix their mistake. */
7209 || (inst.operands[1].reg == REG_PC),
7210 BAD_ADDR_MODE);
b05fe5cf 7211
c19d1205
ZW
7212 constraint (inst.reloc.exp.X_op != O_constant
7213 || inst.reloc.exp.X_add_number != 0,
7214 _("offset must be zero in ARM encoding"));
b05fe5cf 7215
c19d1205
ZW
7216 inst.instruction |= inst.operands[0].reg << 12;
7217 inst.instruction |= inst.operands[1].reg << 16;
7218 inst.reloc.type = BFD_RELOC_UNUSED;
b05fe5cf
ZW
7219}
7220
7221static void
c19d1205 7222do_ldrexd (void)
b05fe5cf 7223{
c19d1205
ZW
7224 constraint (inst.operands[0].reg % 2 != 0,
7225 _("even register required"));
7226 constraint (inst.operands[1].present
7227 && inst.operands[1].reg != inst.operands[0].reg + 1,
7228 _("can only load two consecutive registers"));
7229 /* If op 1 were present and equal to PC, this function wouldn't
7230 have been called in the first place. */
7231 constraint (inst.operands[0].reg == REG_LR, _("r14 not allowed here"));
b05fe5cf 7232
c19d1205
ZW
7233 inst.instruction |= inst.operands[0].reg << 12;
7234 inst.instruction |= inst.operands[2].reg << 16;
b05fe5cf
ZW
7235}
7236
7237static void
c19d1205 7238do_ldst (void)
b05fe5cf 7239{
c19d1205
ZW
7240 inst.instruction |= inst.operands[0].reg << 12;
7241 if (!inst.operands[1].isreg)
7242 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/FALSE))
b05fe5cf 7243 return;
c19d1205 7244 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7245}
7246
7247static void
c19d1205 7248do_ldstt (void)
b05fe5cf 7249{
c19d1205
ZW
7250 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7251 reject [Rn,...]. */
7252 if (inst.operands[1].preind)
b05fe5cf 7253 {
bd3ba5d1
NC
7254 constraint (inst.reloc.exp.X_op != O_constant
7255 || inst.reloc.exp.X_add_number != 0,
c19d1205 7256 _("this instruction requires a post-indexed address"));
b05fe5cf 7257
c19d1205
ZW
7258 inst.operands[1].preind = 0;
7259 inst.operands[1].postind = 1;
7260 inst.operands[1].writeback = 1;
b05fe5cf 7261 }
c19d1205
ZW
7262 inst.instruction |= inst.operands[0].reg << 12;
7263 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7264}
b05fe5cf 7265
c19d1205 7266/* Halfword and signed-byte load/store operations. */
b05fe5cf 7267
c19d1205
ZW
7268static void
7269do_ldstv4 (void)
7270{
7271 inst.instruction |= inst.operands[0].reg << 12;
7272 if (!inst.operands[1].isreg)
7273 if (move_or_literal_pool (0, /*thumb_p=*/FALSE, /*mode_3=*/TRUE))
b05fe5cf 7274 return;
c19d1205 7275 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
b05fe5cf
ZW
7276}
7277
7278static void
c19d1205 7279do_ldsttv4 (void)
b05fe5cf 7280{
c19d1205
ZW
7281 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7282 reject [Rn,...]. */
7283 if (inst.operands[1].preind)
b05fe5cf 7284 {
bd3ba5d1
NC
7285 constraint (inst.reloc.exp.X_op != O_constant
7286 || inst.reloc.exp.X_add_number != 0,
c19d1205 7287 _("this instruction requires a post-indexed address"));
b05fe5cf 7288
c19d1205
ZW
7289 inst.operands[1].preind = 0;
7290 inst.operands[1].postind = 1;
7291 inst.operands[1].writeback = 1;
b05fe5cf 7292 }
c19d1205
ZW
7293 inst.instruction |= inst.operands[0].reg << 12;
7294 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7295}
b05fe5cf 7296
c19d1205
ZW
7297/* Co-processor register load/store.
7298 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7299static void
7300do_lstc (void)
7301{
7302 inst.instruction |= inst.operands[0].reg << 8;
7303 inst.instruction |= inst.operands[1].reg << 12;
7304 encode_arm_cp_address (2, TRUE, TRUE, 0);
b05fe5cf
ZW
7305}
7306
b05fe5cf 7307static void
c19d1205 7308do_mlas (void)
b05fe5cf 7309{
8fb9d7b9 7310 /* This restriction does not apply to mls (nor to mla in v6 or later). */
c19d1205 7311 if (inst.operands[0].reg == inst.operands[1].reg
8fb9d7b9 7312 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
c19d1205 7313 && !(inst.instruction & 0x00400000))
8fb9d7b9 7314 as_tsktsk (_("Rd and Rm should be different in mla"));
b05fe5cf 7315
c19d1205
ZW
7316 inst.instruction |= inst.operands[0].reg << 16;
7317 inst.instruction |= inst.operands[1].reg;
7318 inst.instruction |= inst.operands[2].reg << 8;
7319 inst.instruction |= inst.operands[3].reg << 12;
c19d1205 7320}
b05fe5cf 7321
c19d1205
ZW
7322static void
7323do_mov (void)
7324{
7325 inst.instruction |= inst.operands[0].reg << 12;
7326 encode_arm_shifter_operand (1);
7327}
b05fe5cf 7328
c19d1205
ZW
7329/* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7330static void
7331do_mov16 (void)
7332{
b6895b4f
PB
7333 bfd_vma imm;
7334 bfd_boolean top;
7335
7336 top = (inst.instruction & 0x00400000) != 0;
7337 constraint (top && inst.reloc.type == BFD_RELOC_ARM_MOVW,
7338 _(":lower16: not allowed this instruction"));
7339 constraint (!top && inst.reloc.type == BFD_RELOC_ARM_MOVT,
7340 _(":upper16: not allowed instruction"));
c19d1205 7341 inst.instruction |= inst.operands[0].reg << 12;
b6895b4f
PB
7342 if (inst.reloc.type == BFD_RELOC_UNUSED)
7343 {
7344 imm = inst.reloc.exp.X_add_number;
7345 /* The value is in two pieces: 0:11, 16:19. */
7346 inst.instruction |= (imm & 0x00000fff);
7347 inst.instruction |= (imm & 0x0000f000) << 4;
7348 }
b05fe5cf 7349}
b99bd4ef 7350
037e8744
JB
7351static void do_vfp_nsyn_opcode (const char *);
7352
7353static int
7354do_vfp_nsyn_mrs (void)
7355{
7356 if (inst.operands[0].isvec)
7357 {
7358 if (inst.operands[1].reg != 1)
7359 first_error (_("operand 1 must be FPSCR"));
7360 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
7361 memset (&inst.operands[1], '\0', sizeof (inst.operands[1]));
7362 do_vfp_nsyn_opcode ("fmstat");
7363 }
7364 else if (inst.operands[1].isvec)
7365 do_vfp_nsyn_opcode ("fmrx");
7366 else
7367 return FAIL;
5f4273c7 7368
037e8744
JB
7369 return SUCCESS;
7370}
7371
7372static int
7373do_vfp_nsyn_msr (void)
7374{
7375 if (inst.operands[0].isvec)
7376 do_vfp_nsyn_opcode ("fmxr");
7377 else
7378 return FAIL;
7379
7380 return SUCCESS;
7381}
7382
b99bd4ef 7383static void
c19d1205 7384do_mrs (void)
b99bd4ef 7385{
037e8744
JB
7386 if (do_vfp_nsyn_mrs () == SUCCESS)
7387 return;
7388
c19d1205
ZW
7389 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
7390 constraint ((inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f))
7391 != (PSR_c|PSR_f),
7392 _("'CPSR' or 'SPSR' expected"));
7393 inst.instruction |= inst.operands[0].reg << 12;
7394 inst.instruction |= (inst.operands[1].imm & SPSR_BIT);
7395}
b99bd4ef 7396
c19d1205
ZW
7397/* Two possible forms:
7398 "{C|S}PSR_<field>, Rm",
7399 "{C|S}PSR_f, #expression". */
b99bd4ef 7400
c19d1205
ZW
7401static void
7402do_msr (void)
7403{
037e8744
JB
7404 if (do_vfp_nsyn_msr () == SUCCESS)
7405 return;
7406
c19d1205
ZW
7407 inst.instruction |= inst.operands[0].imm;
7408 if (inst.operands[1].isreg)
7409 inst.instruction |= inst.operands[1].reg;
7410 else
b99bd4ef 7411 {
c19d1205
ZW
7412 inst.instruction |= INST_IMMEDIATE;
7413 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7414 inst.reloc.pc_rel = 0;
b99bd4ef 7415 }
b99bd4ef
NC
7416}
7417
c19d1205
ZW
7418static void
7419do_mul (void)
a737bd4d 7420{
c19d1205
ZW
7421 if (!inst.operands[2].present)
7422 inst.operands[2].reg = inst.operands[0].reg;
7423 inst.instruction |= inst.operands[0].reg << 16;
7424 inst.instruction |= inst.operands[1].reg;
7425 inst.instruction |= inst.operands[2].reg << 8;
a737bd4d 7426
8fb9d7b9
MS
7427 if (inst.operands[0].reg == inst.operands[1].reg
7428 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7429 as_tsktsk (_("Rd and Rm should be different in mul"));
a737bd4d
NC
7430}
7431
c19d1205
ZW
7432/* Long Multiply Parser
7433 UMULL RdLo, RdHi, Rm, Rs
7434 SMULL RdLo, RdHi, Rm, Rs
7435 UMLAL RdLo, RdHi, Rm, Rs
7436 SMLAL RdLo, RdHi, Rm, Rs. */
b99bd4ef
NC
7437
7438static void
c19d1205 7439do_mull (void)
b99bd4ef 7440{
c19d1205
ZW
7441 inst.instruction |= inst.operands[0].reg << 12;
7442 inst.instruction |= inst.operands[1].reg << 16;
7443 inst.instruction |= inst.operands[2].reg;
7444 inst.instruction |= inst.operands[3].reg << 8;
b99bd4ef 7445
682b27ad
PB
7446 /* rdhi and rdlo must be different. */
7447 if (inst.operands[0].reg == inst.operands[1].reg)
7448 as_tsktsk (_("rdhi and rdlo must be different"));
7449
7450 /* rdhi, rdlo and rm must all be different before armv6. */
7451 if ((inst.operands[0].reg == inst.operands[2].reg
c19d1205 7452 || inst.operands[1].reg == inst.operands[2].reg)
682b27ad 7453 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
c19d1205
ZW
7454 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7455}
b99bd4ef 7456
c19d1205
ZW
7457static void
7458do_nop (void)
7459{
e7495e45
NS
7460 if (inst.operands[0].present
7461 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
c19d1205
ZW
7462 {
7463 /* Architectural NOP hints are CPSR sets with no bits selected. */
7464 inst.instruction &= 0xf0000000;
e7495e45
NS
7465 inst.instruction |= 0x0320f000;
7466 if (inst.operands[0].present)
7467 inst.instruction |= inst.operands[0].imm;
c19d1205 7468 }
b99bd4ef
NC
7469}
7470
c19d1205
ZW
7471/* ARM V6 Pack Halfword Bottom Top instruction (argument parse).
7472 PKHBT {<cond>} <Rd>, <Rn>, <Rm> {, LSL #<shift_imm>}
7473 Condition defaults to COND_ALWAYS.
7474 Error if Rd, Rn or Rm are R15. */
b99bd4ef
NC
7475
7476static void
c19d1205 7477do_pkhbt (void)
b99bd4ef 7478{
c19d1205
ZW
7479 inst.instruction |= inst.operands[0].reg << 12;
7480 inst.instruction |= inst.operands[1].reg << 16;
7481 inst.instruction |= inst.operands[2].reg;
7482 if (inst.operands[3].present)
7483 encode_arm_shift (3);
7484}
b99bd4ef 7485
c19d1205 7486/* ARM V6 PKHTB (Argument Parse). */
b99bd4ef 7487
c19d1205
ZW
7488static void
7489do_pkhtb (void)
7490{
7491 if (!inst.operands[3].present)
b99bd4ef 7492 {
c19d1205
ZW
7493 /* If the shift specifier is omitted, turn the instruction
7494 into pkhbt rd, rm, rn. */
7495 inst.instruction &= 0xfff00010;
7496 inst.instruction |= inst.operands[0].reg << 12;
7497 inst.instruction |= inst.operands[1].reg;
7498 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
7499 }
7500 else
7501 {
c19d1205
ZW
7502 inst.instruction |= inst.operands[0].reg << 12;
7503 inst.instruction |= inst.operands[1].reg << 16;
7504 inst.instruction |= inst.operands[2].reg;
7505 encode_arm_shift (3);
b99bd4ef
NC
7506 }
7507}
7508
c19d1205
ZW
7509/* ARMv5TE: Preload-Cache
7510
7511 PLD <addr_mode>
7512
7513 Syntactically, like LDR with B=1, W=0, L=1. */
b99bd4ef
NC
7514
7515static void
c19d1205 7516do_pld (void)
b99bd4ef 7517{
c19d1205
ZW
7518 constraint (!inst.operands[0].isreg,
7519 _("'[' expected after PLD mnemonic"));
7520 constraint (inst.operands[0].postind,
7521 _("post-indexed expression used in preload instruction"));
7522 constraint (inst.operands[0].writeback,
7523 _("writeback used in preload instruction"));
7524 constraint (!inst.operands[0].preind,
7525 _("unindexed addressing used in preload instruction"));
c19d1205
ZW
7526 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7527}
b99bd4ef 7528
62b3e311
PB
7529/* ARMv7: PLI <addr_mode> */
7530static void
7531do_pli (void)
7532{
7533 constraint (!inst.operands[0].isreg,
7534 _("'[' expected after PLI mnemonic"));
7535 constraint (inst.operands[0].postind,
7536 _("post-indexed expression used in preload instruction"));
7537 constraint (inst.operands[0].writeback,
7538 _("writeback used in preload instruction"));
7539 constraint (!inst.operands[0].preind,
7540 _("unindexed addressing used in preload instruction"));
7541 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7542 inst.instruction &= ~PRE_INDEX;
7543}
7544
c19d1205
ZW
7545static void
7546do_push_pop (void)
7547{
7548 inst.operands[1] = inst.operands[0];
7549 memset (&inst.operands[0], 0, sizeof inst.operands[0]);
7550 inst.operands[0].isreg = 1;
7551 inst.operands[0].writeback = 1;
7552 inst.operands[0].reg = REG_SP;
7553 do_ldmstm ();
7554}
b99bd4ef 7555
c19d1205
ZW
7556/* ARM V6 RFE (Return from Exception) loads the PC and CPSR from the
7557 word at the specified address and the following word
7558 respectively.
7559 Unconditionally executed.
7560 Error if Rn is R15. */
b99bd4ef 7561
c19d1205
ZW
7562static void
7563do_rfe (void)
7564{
7565 inst.instruction |= inst.operands[0].reg << 16;
7566 if (inst.operands[0].writeback)
7567 inst.instruction |= WRITE_BACK;
7568}
b99bd4ef 7569
c19d1205 7570/* ARM V6 ssat (argument parse). */
b99bd4ef 7571
c19d1205
ZW
7572static void
7573do_ssat (void)
7574{
7575 inst.instruction |= inst.operands[0].reg << 12;
7576 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7577 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7578
c19d1205
ZW
7579 if (inst.operands[3].present)
7580 encode_arm_shift (3);
b99bd4ef
NC
7581}
7582
c19d1205 7583/* ARM V6 usat (argument parse). */
b99bd4ef
NC
7584
7585static void
c19d1205 7586do_usat (void)
b99bd4ef 7587{
c19d1205
ZW
7588 inst.instruction |= inst.operands[0].reg << 12;
7589 inst.instruction |= inst.operands[1].imm << 16;
7590 inst.instruction |= inst.operands[2].reg;
b99bd4ef 7591
c19d1205
ZW
7592 if (inst.operands[3].present)
7593 encode_arm_shift (3);
b99bd4ef
NC
7594}
7595
c19d1205 7596/* ARM V6 ssat16 (argument parse). */
09d92015
MM
7597
7598static void
c19d1205 7599do_ssat16 (void)
09d92015 7600{
c19d1205
ZW
7601 inst.instruction |= inst.operands[0].reg << 12;
7602 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7603 inst.instruction |= inst.operands[2].reg;
09d92015
MM
7604}
7605
c19d1205
ZW
7606static void
7607do_usat16 (void)
a737bd4d 7608{
c19d1205
ZW
7609 inst.instruction |= inst.operands[0].reg << 12;
7610 inst.instruction |= inst.operands[1].imm << 16;
7611 inst.instruction |= inst.operands[2].reg;
7612}
a737bd4d 7613
c19d1205
ZW
7614/* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7615 preserving the other bits.
a737bd4d 7616
c19d1205
ZW
7617 setend <endian_specifier>, where <endian_specifier> is either
7618 BE or LE. */
a737bd4d 7619
c19d1205
ZW
7620static void
7621do_setend (void)
7622{
7623 if (inst.operands[0].imm)
7624 inst.instruction |= 0x200;
a737bd4d
NC
7625}
7626
7627static void
c19d1205 7628do_shift (void)
a737bd4d 7629{
c19d1205
ZW
7630 unsigned int Rm = (inst.operands[1].present
7631 ? inst.operands[1].reg
7632 : inst.operands[0].reg);
a737bd4d 7633
c19d1205
ZW
7634 inst.instruction |= inst.operands[0].reg << 12;
7635 inst.instruction |= Rm;
7636 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
a737bd4d 7637 {
c19d1205
ZW
7638 inst.instruction |= inst.operands[2].reg << 8;
7639 inst.instruction |= SHIFT_BY_REG;
a737bd4d
NC
7640 }
7641 else
c19d1205 7642 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
a737bd4d
NC
7643}
7644
09d92015 7645static void
3eb17e6b 7646do_smc (void)
09d92015 7647{
3eb17e6b 7648 inst.reloc.type = BFD_RELOC_ARM_SMC;
c19d1205 7649 inst.reloc.pc_rel = 0;
09d92015
MM
7650}
7651
09d92015 7652static void
c19d1205 7653do_swi (void)
09d92015 7654{
c19d1205
ZW
7655 inst.reloc.type = BFD_RELOC_ARM_SWI;
7656 inst.reloc.pc_rel = 0;
09d92015
MM
7657}
7658
c19d1205
ZW
7659/* ARM V5E (El Segundo) signed-multiply-accumulate (argument parse)
7660 SMLAxy{cond} Rd,Rm,Rs,Rn
7661 SMLAWy{cond} Rd,Rm,Rs,Rn
7662 Error if any register is R15. */
e16bb312 7663
c19d1205
ZW
7664static void
7665do_smla (void)
e16bb312 7666{
c19d1205
ZW
7667 inst.instruction |= inst.operands[0].reg << 16;
7668 inst.instruction |= inst.operands[1].reg;
7669 inst.instruction |= inst.operands[2].reg << 8;
7670 inst.instruction |= inst.operands[3].reg << 12;
7671}
a737bd4d 7672
c19d1205
ZW
7673/* ARM V5E (El Segundo) signed-multiply-accumulate-long (argument parse)
7674 SMLALxy{cond} Rdlo,Rdhi,Rm,Rs
7675 Error if any register is R15.
7676 Warning if Rdlo == Rdhi. */
a737bd4d 7677
c19d1205
ZW
7678static void
7679do_smlal (void)
7680{
7681 inst.instruction |= inst.operands[0].reg << 12;
7682 inst.instruction |= inst.operands[1].reg << 16;
7683 inst.instruction |= inst.operands[2].reg;
7684 inst.instruction |= inst.operands[3].reg << 8;
a737bd4d 7685
c19d1205
ZW
7686 if (inst.operands[0].reg == inst.operands[1].reg)
7687 as_tsktsk (_("rdhi and rdlo must be different"));
7688}
a737bd4d 7689
c19d1205
ZW
7690/* ARM V5E (El Segundo) signed-multiply (argument parse)
7691 SMULxy{cond} Rd,Rm,Rs
7692 Error if any register is R15. */
a737bd4d 7693
c19d1205
ZW
7694static void
7695do_smul (void)
7696{
7697 inst.instruction |= inst.operands[0].reg << 16;
7698 inst.instruction |= inst.operands[1].reg;
7699 inst.instruction |= inst.operands[2].reg << 8;
7700}
a737bd4d 7701
b6702015
PB
7702/* ARM V6 srs (argument parse). The variable fields in the encoding are
7703 the same for both ARM and Thumb-2. */
a737bd4d 7704
c19d1205
ZW
7705static void
7706do_srs (void)
7707{
b6702015
PB
7708 int reg;
7709
7710 if (inst.operands[0].present)
7711 {
7712 reg = inst.operands[0].reg;
fdfde340 7713 constraint (reg != REG_SP, _("SRS base register must be r13"));
b6702015
PB
7714 }
7715 else
fdfde340 7716 reg = REG_SP;
b6702015
PB
7717
7718 inst.instruction |= reg << 16;
7719 inst.instruction |= inst.operands[1].imm;
7720 if (inst.operands[0].writeback || inst.operands[1].writeback)
c19d1205
ZW
7721 inst.instruction |= WRITE_BACK;
7722}
a737bd4d 7723
c19d1205 7724/* ARM V6 strex (argument parse). */
a737bd4d 7725
c19d1205
ZW
7726static void
7727do_strex (void)
7728{
7729 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
7730 || inst.operands[2].postind || inst.operands[2].writeback
7731 || inst.operands[2].immisreg || inst.operands[2].shifted
01cfc07f
NC
7732 || inst.operands[2].negative
7733 /* See comment in do_ldrex(). */
7734 || (inst.operands[2].reg == REG_PC),
7735 BAD_ADDR_MODE);
a737bd4d 7736
c19d1205
ZW
7737 constraint (inst.operands[0].reg == inst.operands[1].reg
7738 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
a737bd4d 7739
c19d1205
ZW
7740 constraint (inst.reloc.exp.X_op != O_constant
7741 || inst.reloc.exp.X_add_number != 0,
7742 _("offset must be zero in ARM encoding"));
a737bd4d 7743
c19d1205
ZW
7744 inst.instruction |= inst.operands[0].reg << 12;
7745 inst.instruction |= inst.operands[1].reg;
7746 inst.instruction |= inst.operands[2].reg << 16;
7747 inst.reloc.type = BFD_RELOC_UNUSED;
e16bb312
NC
7748}
7749
7750static void
c19d1205 7751do_strexd (void)
e16bb312 7752{
c19d1205
ZW
7753 constraint (inst.operands[1].reg % 2 != 0,
7754 _("even register required"));
7755 constraint (inst.operands[2].present
7756 && inst.operands[2].reg != inst.operands[1].reg + 1,
7757 _("can only store two consecutive registers"));
7758 /* If op 2 were present and equal to PC, this function wouldn't
7759 have been called in the first place. */
7760 constraint (inst.operands[1].reg == REG_LR, _("r14 not allowed here"));
e16bb312 7761
c19d1205
ZW
7762 constraint (inst.operands[0].reg == inst.operands[1].reg
7763 || inst.operands[0].reg == inst.operands[1].reg + 1
7764 || inst.operands[0].reg == inst.operands[3].reg,
7765 BAD_OVERLAP);
e16bb312 7766
c19d1205
ZW
7767 inst.instruction |= inst.operands[0].reg << 12;
7768 inst.instruction |= inst.operands[1].reg;
7769 inst.instruction |= inst.operands[3].reg << 16;
e16bb312
NC
7770}
7771
c19d1205
ZW
7772/* ARM V6 SXTAH extracts a 16-bit value from a register, sign
7773 extends it to 32-bits, and adds the result to a value in another
7774 register. You can specify a rotation by 0, 8, 16, or 24 bits
7775 before extracting the 16-bit value.
7776 SXTAH{<cond>} <Rd>, <Rn>, <Rm>{, <rotation>}
7777 Condition defaults to COND_ALWAYS.
7778 Error if any register uses R15. */
7779
e16bb312 7780static void
c19d1205 7781do_sxtah (void)
e16bb312 7782{
c19d1205
ZW
7783 inst.instruction |= inst.operands[0].reg << 12;
7784 inst.instruction |= inst.operands[1].reg << 16;
7785 inst.instruction |= inst.operands[2].reg;
7786 inst.instruction |= inst.operands[3].imm << 10;
7787}
e16bb312 7788
c19d1205 7789/* ARM V6 SXTH.
e16bb312 7790
c19d1205
ZW
7791 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7792 Condition defaults to COND_ALWAYS.
7793 Error if any register uses R15. */
e16bb312
NC
7794
7795static void
c19d1205 7796do_sxth (void)
e16bb312 7797{
c19d1205
ZW
7798 inst.instruction |= inst.operands[0].reg << 12;
7799 inst.instruction |= inst.operands[1].reg;
7800 inst.instruction |= inst.operands[2].imm << 10;
e16bb312 7801}
c19d1205
ZW
7802\f
7803/* VFP instructions. In a logical order: SP variant first, monad
7804 before dyad, arithmetic then move then load/store. */
e16bb312
NC
7805
7806static void
c19d1205 7807do_vfp_sp_monadic (void)
e16bb312 7808{
5287ad62
JB
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7811}
7812
7813static void
c19d1205 7814do_vfp_sp_dyadic (void)
e16bb312 7815{
5287ad62
JB
7816 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7817 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7818 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7819}
7820
7821static void
c19d1205 7822do_vfp_sp_compare_z (void)
e16bb312 7823{
5287ad62 7824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
e16bb312
NC
7825}
7826
7827static void
c19d1205 7828do_vfp_dp_sp_cvt (void)
e16bb312 7829{
5287ad62
JB
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
e16bb312
NC
7832}
7833
7834static void
c19d1205 7835do_vfp_sp_dp_cvt (void)
e16bb312 7836{
5287ad62
JB
7837 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7838 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
e16bb312
NC
7839}
7840
7841static void
c19d1205 7842do_vfp_reg_from_sp (void)
e16bb312 7843{
c19d1205 7844 inst.instruction |= inst.operands[0].reg << 12;
5287ad62 7845 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
e16bb312
NC
7846}
7847
7848static void
c19d1205 7849do_vfp_reg2_from_sp2 (void)
e16bb312 7850{
c19d1205
ZW
7851 constraint (inst.operands[2].imm != 2,
7852 _("only two consecutive VFP SP registers allowed here"));
7853 inst.instruction |= inst.operands[0].reg << 12;
7854 inst.instruction |= inst.operands[1].reg << 16;
5287ad62 7855 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
e16bb312
NC
7856}
7857
7858static void
c19d1205 7859do_vfp_sp_from_reg (void)
e16bb312 7860{
5287ad62 7861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
c19d1205 7862 inst.instruction |= inst.operands[1].reg << 12;
e16bb312
NC
7863}
7864
7865static void
c19d1205 7866do_vfp_sp2_from_reg2 (void)
e16bb312 7867{
c19d1205
ZW
7868 constraint (inst.operands[0].imm != 2,
7869 _("only two consecutive VFP SP registers allowed here"));
5287ad62 7870 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
c19d1205
ZW
7871 inst.instruction |= inst.operands[1].reg << 12;
7872 inst.instruction |= inst.operands[2].reg << 16;
e16bb312
NC
7873}
7874
7875static void
c19d1205 7876do_vfp_sp_ldst (void)
e16bb312 7877{
5287ad62 7878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
c19d1205 7879 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7880}
7881
7882static void
c19d1205 7883do_vfp_dp_ldst (void)
e16bb312 7884{
5287ad62 7885 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
c19d1205 7886 encode_arm_cp_address (1, FALSE, TRUE, 0);
e16bb312
NC
7887}
7888
c19d1205 7889
e16bb312 7890static void
c19d1205 7891vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7892{
c19d1205
ZW
7893 if (inst.operands[0].writeback)
7894 inst.instruction |= WRITE_BACK;
7895 else
7896 constraint (ldstm_type != VFP_LDSTMIA,
7897 _("this addressing mode requires base-register writeback"));
7898 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7899 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
c19d1205 7900 inst.instruction |= inst.operands[1].imm;
e16bb312
NC
7901}
7902
7903static void
c19d1205 7904vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
e16bb312 7905{
c19d1205 7906 int count;
e16bb312 7907
c19d1205
ZW
7908 if (inst.operands[0].writeback)
7909 inst.instruction |= WRITE_BACK;
7910 else
7911 constraint (ldstm_type != VFP_LDSTMIA && ldstm_type != VFP_LDSTMIAX,
7912 _("this addressing mode requires base-register writeback"));
e16bb312 7913
c19d1205 7914 inst.instruction |= inst.operands[0].reg << 16;
5287ad62 7915 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
e16bb312 7916
c19d1205
ZW
7917 count = inst.operands[1].imm << 1;
7918 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7919 count += 1;
e16bb312 7920
c19d1205 7921 inst.instruction |= count;
e16bb312
NC
7922}
7923
7924static void
c19d1205 7925do_vfp_sp_ldstmia (void)
e16bb312 7926{
c19d1205 7927 vfp_sp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7928}
7929
7930static void
c19d1205 7931do_vfp_sp_ldstmdb (void)
e16bb312 7932{
c19d1205 7933 vfp_sp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7934}
7935
7936static void
c19d1205 7937do_vfp_dp_ldstmia (void)
e16bb312 7938{
c19d1205 7939 vfp_dp_ldstm (VFP_LDSTMIA);
e16bb312
NC
7940}
7941
7942static void
c19d1205 7943do_vfp_dp_ldstmdb (void)
e16bb312 7944{
c19d1205 7945 vfp_dp_ldstm (VFP_LDSTMDB);
e16bb312
NC
7946}
7947
7948static void
c19d1205 7949do_vfp_xp_ldstmia (void)
e16bb312 7950{
c19d1205
ZW
7951 vfp_dp_ldstm (VFP_LDSTMIAX);
7952}
e16bb312 7953
c19d1205
ZW
7954static void
7955do_vfp_xp_ldstmdb (void)
7956{
7957 vfp_dp_ldstm (VFP_LDSTMDBX);
e16bb312 7958}
5287ad62
JB
7959
7960static void
7961do_vfp_dp_rd_rm (void)
7962{
7963 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7964 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7965}
7966
7967static void
7968do_vfp_dp_rn_rd (void)
7969{
7970 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7971 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7972}
7973
7974static void
7975do_vfp_dp_rd_rn (void)
7976{
7977 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7978 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7979}
7980
7981static void
7982do_vfp_dp_rd_rn_rm (void)
7983{
7984 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7985 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7986 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dm);
7987}
7988
7989static void
7990do_vfp_dp_rd (void)
7991{
7992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7993}
7994
7995static void
7996do_vfp_dp_rm_rd_rn (void)
7997{
7998 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dm);
7999 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
8000 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Dn);
8001}
8002
8003/* VFPv3 instructions. */
8004static void
8005do_vfp_sp_const (void)
8006{
8007 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
00249aaa
PB
8008 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8009 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8010}
8011
8012static void
8013do_vfp_dp_const (void)
8014{
8015 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
00249aaa
PB
8016 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8017 inst.instruction |= (inst.operands[1].imm & 0x0f);
5287ad62
JB
8018}
8019
8020static void
8021vfp_conv (int srcsize)
8022{
8023 unsigned immbits = srcsize - inst.operands[1].imm;
8024 inst.instruction |= (immbits & 1) << 5;
8025 inst.instruction |= (immbits >> 1);
8026}
8027
8028static void
8029do_vfp_sp_conv_16 (void)
8030{
8031 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8032 vfp_conv (16);
8033}
8034
8035static void
8036do_vfp_dp_conv_16 (void)
8037{
8038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8039 vfp_conv (16);
8040}
8041
8042static void
8043do_vfp_sp_conv_32 (void)
8044{
8045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8046 vfp_conv (32);
8047}
8048
8049static void
8050do_vfp_dp_conv_32 (void)
8051{
8052 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8053 vfp_conv (32);
8054}
c19d1205
ZW
8055\f
8056/* FPA instructions. Also in a logical order. */
e16bb312 8057
c19d1205
ZW
8058static void
8059do_fpa_cmp (void)
8060{
8061 inst.instruction |= inst.operands[0].reg << 16;
8062 inst.instruction |= inst.operands[1].reg;
8063}
b99bd4ef
NC
8064
8065static void
c19d1205 8066do_fpa_ldmstm (void)
b99bd4ef 8067{
c19d1205
ZW
8068 inst.instruction |= inst.operands[0].reg << 12;
8069 switch (inst.operands[1].imm)
8070 {
8071 case 1: inst.instruction |= CP_T_X; break;
8072 case 2: inst.instruction |= CP_T_Y; break;
8073 case 3: inst.instruction |= CP_T_Y | CP_T_X; break;
8074 case 4: break;
8075 default: abort ();
8076 }
b99bd4ef 8077
c19d1205
ZW
8078 if (inst.instruction & (PRE_INDEX | INDEX_UP))
8079 {
8080 /* The instruction specified "ea" or "fd", so we can only accept
8081 [Rn]{!}. The instruction does not really support stacking or
8082 unstacking, so we have to emulate these by setting appropriate
8083 bits and offsets. */
8084 constraint (inst.reloc.exp.X_op != O_constant
8085 || inst.reloc.exp.X_add_number != 0,
8086 _("this instruction does not support indexing"));
b99bd4ef 8087
c19d1205
ZW
8088 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8089 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
b99bd4ef 8090
c19d1205
ZW
8091 if (!(inst.instruction & INDEX_UP))
8092 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
b99bd4ef 8093
c19d1205
ZW
8094 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8095 {
8096 inst.operands[2].preind = 0;
8097 inst.operands[2].postind = 1;
8098 }
8099 }
b99bd4ef 8100
c19d1205 8101 encode_arm_cp_address (2, TRUE, TRUE, 0);
b99bd4ef 8102}
c19d1205
ZW
8103\f
8104/* iWMMXt instructions: strictly in alphabetical order. */
b99bd4ef 8105
c19d1205
ZW
8106static void
8107do_iwmmxt_tandorc (void)
8108{
8109 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8110}
b99bd4ef 8111
c19d1205
ZW
8112static void
8113do_iwmmxt_textrc (void)
8114{
8115 inst.instruction |= inst.operands[0].reg << 12;
8116 inst.instruction |= inst.operands[1].imm;
8117}
b99bd4ef
NC
8118
8119static void
c19d1205 8120do_iwmmxt_textrm (void)
b99bd4ef 8121{
c19d1205
ZW
8122 inst.instruction |= inst.operands[0].reg << 12;
8123 inst.instruction |= inst.operands[1].reg << 16;
8124 inst.instruction |= inst.operands[2].imm;
8125}
b99bd4ef 8126
c19d1205
ZW
8127static void
8128do_iwmmxt_tinsr (void)
8129{
8130 inst.instruction |= inst.operands[0].reg << 16;
8131 inst.instruction |= inst.operands[1].reg << 12;
8132 inst.instruction |= inst.operands[2].imm;
8133}
b99bd4ef 8134
c19d1205
ZW
8135static void
8136do_iwmmxt_tmia (void)
8137{
8138 inst.instruction |= inst.operands[0].reg << 5;
8139 inst.instruction |= inst.operands[1].reg;
8140 inst.instruction |= inst.operands[2].reg << 12;
8141}
b99bd4ef 8142
c19d1205
ZW
8143static void
8144do_iwmmxt_waligni (void)
8145{
8146 inst.instruction |= inst.operands[0].reg << 12;
8147 inst.instruction |= inst.operands[1].reg << 16;
8148 inst.instruction |= inst.operands[2].reg;
8149 inst.instruction |= inst.operands[3].imm << 20;
8150}
b99bd4ef 8151
2d447fca
JM
8152static void
8153do_iwmmxt_wmerge (void)
8154{
8155 inst.instruction |= inst.operands[0].reg << 12;
8156 inst.instruction |= inst.operands[1].reg << 16;
8157 inst.instruction |= inst.operands[2].reg;
8158 inst.instruction |= inst.operands[3].imm << 21;
8159}
8160
c19d1205
ZW
8161static void
8162do_iwmmxt_wmov (void)
8163{
8164 /* WMOV rD, rN is an alias for WOR rD, rN, rN. */
8165 inst.instruction |= inst.operands[0].reg << 12;
8166 inst.instruction |= inst.operands[1].reg << 16;
8167 inst.instruction |= inst.operands[1].reg;
8168}
b99bd4ef 8169
c19d1205
ZW
8170static void
8171do_iwmmxt_wldstbh (void)
8172{
8f06b2d8 8173 int reloc;
c19d1205 8174 inst.instruction |= inst.operands[0].reg << 12;
8f06b2d8
PB
8175 if (thumb_mode)
8176 reloc = BFD_RELOC_ARM_T32_CP_OFF_IMM_S2;
8177 else
8178 reloc = BFD_RELOC_ARM_CP_OFF_IMM_S2;
8179 encode_arm_cp_address (1, TRUE, FALSE, reloc);
b99bd4ef
NC
8180}
8181
c19d1205
ZW
8182static void
8183do_iwmmxt_wldstw (void)
8184{
8185 /* RIWR_RIWC clears .isreg for a control register. */
8186 if (!inst.operands[0].isreg)
8187 {
8188 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8189 inst.instruction |= 0xf0000000;
8190 }
b99bd4ef 8191
c19d1205
ZW
8192 inst.instruction |= inst.operands[0].reg << 12;
8193 encode_arm_cp_address (1, TRUE, TRUE, 0);
8194}
b99bd4ef
NC
8195
8196static void
c19d1205 8197do_iwmmxt_wldstd (void)
b99bd4ef 8198{
c19d1205 8199 inst.instruction |= inst.operands[0].reg << 12;
2d447fca
JM
8200 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8201 && inst.operands[1].immisreg)
8202 {
8203 inst.instruction &= ~0x1a000ff;
8204 inst.instruction |= (0xf << 28);
8205 if (inst.operands[1].preind)
8206 inst.instruction |= PRE_INDEX;
8207 if (!inst.operands[1].negative)
8208 inst.instruction |= INDEX_UP;
8209 if (inst.operands[1].writeback)
8210 inst.instruction |= WRITE_BACK;
8211 inst.instruction |= inst.operands[1].reg << 16;
8212 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8213 inst.instruction |= inst.operands[1].imm;
8214 }
8215 else
8216 encode_arm_cp_address (1, TRUE, FALSE, 0);
c19d1205 8217}
b99bd4ef 8218
c19d1205
ZW
8219static void
8220do_iwmmxt_wshufh (void)
8221{
8222 inst.instruction |= inst.operands[0].reg << 12;
8223 inst.instruction |= inst.operands[1].reg << 16;
8224 inst.instruction |= ((inst.operands[2].imm & 0xf0) << 16);
8225 inst.instruction |= (inst.operands[2].imm & 0x0f);
8226}
b99bd4ef 8227
c19d1205
ZW
8228static void
8229do_iwmmxt_wzero (void)
8230{
8231 /* WZERO reg is an alias for WANDN reg, reg, reg. */
8232 inst.instruction |= inst.operands[0].reg;
8233 inst.instruction |= inst.operands[0].reg << 12;
8234 inst.instruction |= inst.operands[0].reg << 16;
8235}
2d447fca
JM
8236
8237static void
8238do_iwmmxt_wrwrwr_or_imm5 (void)
8239{
8240 if (inst.operands[2].isreg)
8241 do_rd_rn_rm ();
8242 else {
8243 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2),
8244 _("immediate operand requires iWMMXt2"));
8245 do_rd_rn ();
8246 if (inst.operands[2].imm == 0)
8247 {
8248 switch ((inst.instruction >> 20) & 0xf)
8249 {
8250 case 4:
8251 case 5:
8252 case 6:
5f4273c7 8253 case 7:
2d447fca
JM
8254 /* w...h wrd, wrn, #0 -> wrorh wrd, wrn, #16. */
8255 inst.operands[2].imm = 16;
8256 inst.instruction = (inst.instruction & 0xff0fffff) | (0x7 << 20);
8257 break;
8258 case 8:
8259 case 9:
8260 case 10:
8261 case 11:
8262 /* w...w wrd, wrn, #0 -> wrorw wrd, wrn, #32. */
8263 inst.operands[2].imm = 32;
8264 inst.instruction = (inst.instruction & 0xff0fffff) | (0xb << 20);
8265 break;
8266 case 12:
8267 case 13:
8268 case 14:
8269 case 15:
8270 {
8271 /* w...d wrd, wrn, #0 -> wor wrd, wrn, wrn. */
8272 unsigned long wrn;
8273 wrn = (inst.instruction >> 16) & 0xf;
8274 inst.instruction &= 0xff0fff0f;
8275 inst.instruction |= wrn;
8276 /* Bail out here; the instruction is now assembled. */
8277 return;
8278 }
8279 }
8280 }
8281 /* Map 32 -> 0, etc. */
8282 inst.operands[2].imm &= 0x1f;
8283 inst.instruction |= (0xf << 28) | ((inst.operands[2].imm & 0x10) << 4) | (inst.operands[2].imm & 0xf);
8284 }
8285}
c19d1205
ZW
8286\f
8287/* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8288 operations first, then control, shift, and load/store. */
b99bd4ef 8289
c19d1205 8290/* Insns like "foo X,Y,Z". */
b99bd4ef 8291
c19d1205
ZW
8292static void
8293do_mav_triple (void)
8294{
8295 inst.instruction |= inst.operands[0].reg << 16;
8296 inst.instruction |= inst.operands[1].reg;
8297 inst.instruction |= inst.operands[2].reg << 12;
8298}
b99bd4ef 8299
c19d1205
ZW
8300/* Insns like "foo W,X,Y,Z".
8301 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
a737bd4d 8302
c19d1205
ZW
8303static void
8304do_mav_quad (void)
8305{
8306 inst.instruction |= inst.operands[0].reg << 5;
8307 inst.instruction |= inst.operands[1].reg << 12;
8308 inst.instruction |= inst.operands[2].reg << 16;
8309 inst.instruction |= inst.operands[3].reg;
a737bd4d
NC
8310}
8311
c19d1205
ZW
8312/* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8313static void
8314do_mav_dspsc (void)
a737bd4d 8315{
c19d1205
ZW
8316 inst.instruction |= inst.operands[1].reg << 12;
8317}
a737bd4d 8318
c19d1205
ZW
8319/* Maverick shift immediate instructions.
8320 cfsh32<cond> MVFX[15:0],MVFX[15:0],Shift[6:0].
8321 cfsh64<cond> MVDX[15:0],MVDX[15:0],Shift[6:0]. */
a737bd4d 8322
c19d1205
ZW
8323static void
8324do_mav_shift (void)
8325{
8326 int imm = inst.operands[2].imm;
a737bd4d 8327
c19d1205
ZW
8328 inst.instruction |= inst.operands[0].reg << 12;
8329 inst.instruction |= inst.operands[1].reg << 16;
a737bd4d 8330
c19d1205
ZW
8331 /* Bits 0-3 of the insn should have bits 0-3 of the immediate.
8332 Bits 5-7 of the insn should have bits 4-6 of the immediate.
8333 Bit 4 should be 0. */
8334 imm = (imm & 0xf) | ((imm & 0x70) << 1);
a737bd4d 8335
c19d1205
ZW
8336 inst.instruction |= imm;
8337}
8338\f
8339/* XScale instructions. Also sorted arithmetic before move. */
a737bd4d 8340
c19d1205
ZW
8341/* Xscale multiply-accumulate (argument parse)
8342 MIAcc acc0,Rm,Rs
8343 MIAPHcc acc0,Rm,Rs
8344 MIAxycc acc0,Rm,Rs. */
a737bd4d 8345
c19d1205
ZW
8346static void
8347do_xsc_mia (void)
8348{
8349 inst.instruction |= inst.operands[1].reg;
8350 inst.instruction |= inst.operands[2].reg << 12;
8351}
a737bd4d 8352
c19d1205 8353/* Xscale move-accumulator-register (argument parse)
a737bd4d 8354
c19d1205 8355 MARcc acc0,RdLo,RdHi. */
b99bd4ef 8356
c19d1205
ZW
8357static void
8358do_xsc_mar (void)
8359{
8360 inst.instruction |= inst.operands[1].reg << 12;
8361 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
8362}
8363
c19d1205 8364/* Xscale move-register-accumulator (argument parse)
b99bd4ef 8365
c19d1205 8366 MRAcc RdLo,RdHi,acc0. */
b99bd4ef
NC
8367
8368static void
c19d1205 8369do_xsc_mra (void)
b99bd4ef 8370{
c19d1205
ZW
8371 constraint (inst.operands[0].reg == inst.operands[1].reg, BAD_OVERLAP);
8372 inst.instruction |= inst.operands[0].reg << 12;
8373 inst.instruction |= inst.operands[1].reg << 16;
8374}
8375\f
8376/* Encoding functions relevant only to Thumb. */
b99bd4ef 8377
c19d1205
ZW
8378/* inst.operands[i] is a shifted-register operand; encode
8379 it into inst.instruction in the format used by Thumb32. */
8380
8381static void
8382encode_thumb32_shifted_operand (int i)
8383{
8384 unsigned int value = inst.reloc.exp.X_add_number;
8385 unsigned int shift = inst.operands[i].shift_kind;
b99bd4ef 8386
9c3c69f2
PB
8387 constraint (inst.operands[i].immisreg,
8388 _("shift by register not allowed in thumb mode"));
c19d1205
ZW
8389 inst.instruction |= inst.operands[i].reg;
8390 if (shift == SHIFT_RRX)
8391 inst.instruction |= SHIFT_ROR << 4;
8392 else
b99bd4ef 8393 {
c19d1205
ZW
8394 constraint (inst.reloc.exp.X_op != O_constant,
8395 _("expression too complex"));
8396
8397 constraint (value > 32
8398 || (value == 32 && (shift == SHIFT_LSL
8399 || shift == SHIFT_ROR)),
8400 _("shift expression is too large"));
8401
8402 if (value == 0)
8403 shift = SHIFT_LSL;
8404 else if (value == 32)
8405 value = 0;
8406
8407 inst.instruction |= shift << 4;
8408 inst.instruction |= (value & 0x1c) << 10;
8409 inst.instruction |= (value & 0x03) << 6;
b99bd4ef 8410 }
c19d1205 8411}
b99bd4ef 8412
b99bd4ef 8413
c19d1205
ZW
8414/* inst.operands[i] was set up by parse_address. Encode it into a
8415 Thumb32 format load or store instruction. Reject forms that cannot
8416 be used with such instructions. If is_t is true, reject forms that
8417 cannot be used with a T instruction; if is_d is true, reject forms
8418 that cannot be used with a D instruction. */
b99bd4ef 8419
c19d1205
ZW
8420static void
8421encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8422{
8423 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8424
8425 constraint (!inst.operands[i].isreg,
53365c0d 8426 _("Instruction does not support =N addresses"));
b99bd4ef 8427
c19d1205
ZW
8428 inst.instruction |= inst.operands[i].reg << 16;
8429 if (inst.operands[i].immisreg)
b99bd4ef 8430 {
c19d1205
ZW
8431 constraint (is_pc, _("cannot use register index with PC-relative addressing"));
8432 constraint (is_t || is_d, _("cannot use register index with this instruction"));
8433 constraint (inst.operands[i].negative,
8434 _("Thumb does not support negative register indexing"));
8435 constraint (inst.operands[i].postind,
8436 _("Thumb does not support register post-indexing"));
8437 constraint (inst.operands[i].writeback,
8438 _("Thumb does not support register indexing with writeback"));
8439 constraint (inst.operands[i].shifted && inst.operands[i].shift_kind != SHIFT_LSL,
8440 _("Thumb supports only LSL in shifted register indexing"));
b99bd4ef 8441
f40d1643 8442 inst.instruction |= inst.operands[i].imm;
c19d1205 8443 if (inst.operands[i].shifted)
b99bd4ef 8444 {
c19d1205
ZW
8445 constraint (inst.reloc.exp.X_op != O_constant,
8446 _("expression too complex"));
9c3c69f2
PB
8447 constraint (inst.reloc.exp.X_add_number < 0
8448 || inst.reloc.exp.X_add_number > 3,
c19d1205 8449 _("shift out of range"));
9c3c69f2 8450 inst.instruction |= inst.reloc.exp.X_add_number << 4;
c19d1205
ZW
8451 }
8452 inst.reloc.type = BFD_RELOC_UNUSED;
8453 }
8454 else if (inst.operands[i].preind)
8455 {
8456 constraint (is_pc && inst.operands[i].writeback,
8457 _("cannot use writeback with PC-relative addressing"));
f40d1643 8458 constraint (is_t && inst.operands[i].writeback,
c19d1205
ZW
8459 _("cannot use writeback with this instruction"));
8460
8461 if (is_d)
8462 {
8463 inst.instruction |= 0x01000000;
8464 if (inst.operands[i].writeback)
8465 inst.instruction |= 0x00200000;
b99bd4ef 8466 }
c19d1205 8467 else
b99bd4ef 8468 {
c19d1205
ZW
8469 inst.instruction |= 0x00000c00;
8470 if (inst.operands[i].writeback)
8471 inst.instruction |= 0x00000100;
b99bd4ef 8472 }
c19d1205 8473 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
b99bd4ef 8474 }
c19d1205 8475 else if (inst.operands[i].postind)
b99bd4ef 8476 {
9c2799c2 8477 gas_assert (inst.operands[i].writeback);
c19d1205
ZW
8478 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8479 constraint (is_t, _("cannot use post-indexing with this instruction"));
8480
8481 if (is_d)
8482 inst.instruction |= 0x00200000;
8483 else
8484 inst.instruction |= 0x00000900;
8485 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8486 }
8487 else /* unindexed - only for coprocessor */
8488 inst.error = _("instruction does not accept unindexed addressing");
8489}
8490
8491/* Table of Thumb instructions which exist in both 16- and 32-bit
8492 encodings (the latter only in post-V6T2 cores). The index is the
8493 value used in the insns table below. When there is more than one
8494 possible 16-bit encoding for the instruction, this table always
0110f2b8
PB
8495 holds variant (1).
8496 Also contains several pseudo-instructions used during relaxation. */
c19d1205
ZW
8497#define T16_32_TAB \
8498 X(adc, 4140, eb400000), \
8499 X(adcs, 4140, eb500000), \
8500 X(add, 1c00, eb000000), \
8501 X(adds, 1c00, eb100000), \
0110f2b8
PB
8502 X(addi, 0000, f1000000), \
8503 X(addis, 0000, f1100000), \
8504 X(add_pc,000f, f20f0000), \
8505 X(add_sp,000d, f10d0000), \
e9f89963 8506 X(adr, 000f, f20f0000), \
c19d1205
ZW
8507 X(and, 4000, ea000000), \
8508 X(ands, 4000, ea100000), \
8509 X(asr, 1000, fa40f000), \
8510 X(asrs, 1000, fa50f000), \
0110f2b8
PB
8511 X(b, e000, f000b000), \
8512 X(bcond, d000, f0008000), \
c19d1205
ZW
8513 X(bic, 4380, ea200000), \
8514 X(bics, 4380, ea300000), \
8515 X(cmn, 42c0, eb100f00), \
8516 X(cmp, 2800, ebb00f00), \
8517 X(cpsie, b660, f3af8400), \
8518 X(cpsid, b670, f3af8600), \
8519 X(cpy, 4600, ea4f0000), \
155257ea 8520 X(dec_sp,80dd, f1ad0d00), \
c19d1205
ZW
8521 X(eor, 4040, ea800000), \
8522 X(eors, 4040, ea900000), \
0110f2b8 8523 X(inc_sp,00dd, f10d0d00), \
c19d1205
ZW
8524 X(ldmia, c800, e8900000), \
8525 X(ldr, 6800, f8500000), \
8526 X(ldrb, 7800, f8100000), \
8527 X(ldrh, 8800, f8300000), \
8528 X(ldrsb, 5600, f9100000), \
8529 X(ldrsh, 5e00, f9300000), \
0110f2b8
PB
8530 X(ldr_pc,4800, f85f0000), \
8531 X(ldr_pc2,4800, f85f0000), \
8532 X(ldr_sp,9800, f85d0000), \
c19d1205
ZW
8533 X(lsl, 0000, fa00f000), \
8534 X(lsls, 0000, fa10f000), \
8535 X(lsr, 0800, fa20f000), \
8536 X(lsrs, 0800, fa30f000), \
8537 X(mov, 2000, ea4f0000), \
8538 X(movs, 2000, ea5f0000), \
8539 X(mul, 4340, fb00f000), \
8540 X(muls, 4340, ffffffff), /* no 32b muls */ \
8541 X(mvn, 43c0, ea6f0000), \
8542 X(mvns, 43c0, ea7f0000), \
8543 X(neg, 4240, f1c00000), /* rsb #0 */ \
8544 X(negs, 4240, f1d00000), /* rsbs #0 */ \
8545 X(orr, 4300, ea400000), \
8546 X(orrs, 4300, ea500000), \
e9f89963
PB
8547 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8548 X(push, b400, e92d0000), /* stmdb sp!,... */ \
c19d1205
ZW
8549 X(rev, ba00, fa90f080), \
8550 X(rev16, ba40, fa90f090), \
8551 X(revsh, bac0, fa90f0b0), \
8552 X(ror, 41c0, fa60f000), \
8553 X(rors, 41c0, fa70f000), \
8554 X(sbc, 4180, eb600000), \
8555 X(sbcs, 4180, eb700000), \
8556 X(stmia, c000, e8800000), \
8557 X(str, 6000, f8400000), \
8558 X(strb, 7000, f8000000), \
8559 X(strh, 8000, f8200000), \
0110f2b8 8560 X(str_sp,9000, f84d0000), \
c19d1205
ZW
8561 X(sub, 1e00, eba00000), \
8562 X(subs, 1e00, ebb00000), \
0110f2b8
PB
8563 X(subi, 8000, f1a00000), \
8564 X(subis, 8000, f1b00000), \
c19d1205
ZW
8565 X(sxtb, b240, fa4ff080), \
8566 X(sxth, b200, fa0ff080), \
8567 X(tst, 4200, ea100f00), \
8568 X(uxtb, b2c0, fa5ff080), \
8569 X(uxth, b280, fa1ff080), \
8570 X(nop, bf00, f3af8000), \
8571 X(yield, bf10, f3af8001), \
8572 X(wfe, bf20, f3af8002), \
8573 X(wfi, bf30, f3af8003), \
fe2ceba1 8574 X(sev, bf40, f3af8004),
c19d1205
ZW
8575
8576/* To catch errors in encoding functions, the codes are all offset by
8577 0xF800, putting them in one of the 32-bit prefix ranges, ergo undefined
8578 as 16-bit instructions. */
8579#define X(a,b,c) T_MNEM_##a
8580enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8581#undef X
8582
8583#define X(a,b,c) 0x##b
8584static const unsigned short thumb_op16[] = { T16_32_TAB };
8585#define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8586#undef X
8587
8588#define X(a,b,c) 0x##c
8589static const unsigned int thumb_op32[] = { T16_32_TAB };
8590#define THUMB_OP32(n) (thumb_op32[(n) - (T16_32_OFFSET + 1)])
8591#define THUMB_SETS_FLAGS(n) (THUMB_OP32 (n) & 0x00100000)
8592#undef X
8593#undef T16_32_TAB
8594
8595/* Thumb instruction encoders, in alphabetical order. */
8596
92e90b6e
PB
8597/* ADDW or SUBW. */
8598static void
8599do_t_add_sub_w (void)
8600{
8601 int Rd, Rn;
8602
8603 Rd = inst.operands[0].reg;
8604 Rn = inst.operands[1].reg;
8605
fdfde340
JM
8606 /* If Rn is REG_PC, this is ADR; if Rn is REG_SP, then this is the
8607 SP-{plus,minute}-immediate form of the instruction. */
8608 reject_bad_reg (Rd);
8609
92e90b6e
PB
8610 inst.instruction |= (Rn << 16) | (Rd << 8);
8611 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8612}
8613
c19d1205
ZW
8614/* Parse an add or subtract instruction. We get here with inst.instruction
8615 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8616
8617static void
8618do_t_add_sub (void)
8619{
8620 int Rd, Rs, Rn;
8621
8622 Rd = inst.operands[0].reg;
8623 Rs = (inst.operands[1].present
8624 ? inst.operands[1].reg /* Rd, Rs, foo */
8625 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8626
e07e6e58
NC
8627 if (Rd == REG_PC)
8628 set_it_insn_type_last ();
8629
c19d1205
ZW
8630 if (unified_syntax)
8631 {
0110f2b8
PB
8632 bfd_boolean flags;
8633 bfd_boolean narrow;
8634 int opcode;
8635
8636 flags = (inst.instruction == T_MNEM_adds
8637 || inst.instruction == T_MNEM_subs);
8638 if (flags)
e07e6e58 8639 narrow = !in_it_block ();
0110f2b8 8640 else
e07e6e58 8641 narrow = in_it_block ();
c19d1205 8642 if (!inst.operands[2].isreg)
b99bd4ef 8643 {
16805f35
PB
8644 int add;
8645
fdfde340
JM
8646 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8647
16805f35
PB
8648 add = (inst.instruction == T_MNEM_add
8649 || inst.instruction == T_MNEM_adds);
0110f2b8
PB
8650 opcode = 0;
8651 if (inst.size_req != 4)
8652 {
0110f2b8
PB
8653 /* Attempt to use a narrow opcode, with relaxation if
8654 appropriate. */
8655 if (Rd == REG_SP && Rs == REG_SP && !flags)
8656 opcode = add ? T_MNEM_inc_sp : T_MNEM_dec_sp;
8657 else if (Rd <= 7 && Rs == REG_SP && add && !flags)
8658 opcode = T_MNEM_add_sp;
8659 else if (Rd <= 7 && Rs == REG_PC && add && !flags)
8660 opcode = T_MNEM_add_pc;
8661 else if (Rd <= 7 && Rs <= 7 && narrow)
8662 {
8663 if (flags)
8664 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8665 else
8666 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8667 }
8668 if (opcode)
8669 {
8670 inst.instruction = THUMB_OP16(opcode);
8671 inst.instruction |= (Rd << 4) | Rs;
8672 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8673 if (inst.size_req != 2)
8674 inst.relax = opcode;
8675 }
8676 else
8677 constraint (inst.size_req == 2, BAD_HIREG);
8678 }
8679 if (inst.size_req == 4
8680 || (inst.size_req != 2 && !opcode))
8681 {
efd81785
PB
8682 if (Rd == REG_PC)
8683 {
fdfde340 8684 constraint (add, BAD_PC);
efd81785
PB
8685 constraint (Rs != REG_LR || inst.instruction != T_MNEM_subs,
8686 _("only SUBS PC, LR, #const allowed"));
8687 constraint (inst.reloc.exp.X_op != O_constant,
8688 _("expression too complex"));
8689 constraint (inst.reloc.exp.X_add_number < 0
8690 || inst.reloc.exp.X_add_number > 0xff,
8691 _("immediate value out of range"));
8692 inst.instruction = T2_SUBS_PC_LR
8693 | inst.reloc.exp.X_add_number;
8694 inst.reloc.type = BFD_RELOC_UNUSED;
8695 return;
8696 }
8697 else if (Rs == REG_PC)
16805f35
PB
8698 {
8699 /* Always use addw/subw. */
8700 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8701 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8702 }
8703 else
8704 {
8705 inst.instruction = THUMB_OP32 (inst.instruction);
8706 inst.instruction = (inst.instruction & 0xe1ffffff)
8707 | 0x10000000;
8708 if (flags)
8709 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8710 else
8711 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_IMM;
8712 }
dc4503c6
PB
8713 inst.instruction |= Rd << 8;
8714 inst.instruction |= Rs << 16;
0110f2b8 8715 }
b99bd4ef 8716 }
c19d1205
ZW
8717 else
8718 {
8719 Rn = inst.operands[2].reg;
8720 /* See if we can do this with a 16-bit instruction. */
8721 if (!inst.operands[2].shifted && inst.size_req != 4)
8722 {
e27ec89e
PB
8723 if (Rd > 7 || Rs > 7 || Rn > 7)
8724 narrow = FALSE;
8725
8726 if (narrow)
c19d1205 8727 {
e27ec89e
PB
8728 inst.instruction = ((inst.instruction == T_MNEM_adds
8729 || inst.instruction == T_MNEM_add)
c19d1205
ZW
8730 ? T_OPCODE_ADD_R3
8731 : T_OPCODE_SUB_R3);
8732 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8733 return;
8734 }
b99bd4ef 8735
7e806470 8736 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
c19d1205 8737 {
7e806470
PB
8738 /* Thumb-1 cores (except v6-M) require at least one high
8739 register in a narrow non flag setting add. */
8740 if (Rd > 7 || Rn > 7
8741 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2)
8742 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_msr))
c19d1205 8743 {
7e806470
PB
8744 if (Rd == Rn)
8745 {
8746 Rn = Rs;
8747 Rs = Rd;
8748 }
c19d1205
ZW
8749 inst.instruction = T_OPCODE_ADD_HI;
8750 inst.instruction |= (Rd & 8) << 4;
8751 inst.instruction |= (Rd & 7);
8752 inst.instruction |= Rn << 3;
8753 return;
8754 }
c19d1205
ZW
8755 }
8756 }
fdfde340
JM
8757
8758 constraint (Rd == REG_PC, BAD_PC);
8759 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8760 constraint (Rs == REG_PC, BAD_PC);
8761 reject_bad_reg (Rn);
8762
c19d1205
ZW
8763 /* If we get here, it can't be done in 16 bits. */
8764 constraint (inst.operands[2].shifted && inst.operands[2].immisreg,
8765 _("shift must be constant"));
8766 inst.instruction = THUMB_OP32 (inst.instruction);
8767 inst.instruction |= Rd << 8;
8768 inst.instruction |= Rs << 16;
8769 encode_thumb32_shifted_operand (2);
8770 }
8771 }
8772 else
8773 {
8774 constraint (inst.instruction == T_MNEM_adds
8775 || inst.instruction == T_MNEM_subs,
8776 BAD_THUMB32);
b99bd4ef 8777
c19d1205 8778 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
b99bd4ef 8779 {
c19d1205
ZW
8780 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8781 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8782 BAD_HIREG);
8783
8784 inst.instruction = (inst.instruction == T_MNEM_add
8785 ? 0x0000 : 0x8000);
8786 inst.instruction |= (Rd << 4) | Rs;
8787 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
b99bd4ef
NC
8788 return;
8789 }
8790
c19d1205
ZW
8791 Rn = inst.operands[2].reg;
8792 constraint (inst.operands[2].shifted, _("unshifted register required"));
b99bd4ef 8793
c19d1205
ZW
8794 /* We now have Rd, Rs, and Rn set to registers. */
8795 if (Rd > 7 || Rs > 7 || Rn > 7)
b99bd4ef 8796 {
c19d1205
ZW
8797 /* Can't do this for SUB. */
8798 constraint (inst.instruction == T_MNEM_sub, BAD_HIREG);
8799 inst.instruction = T_OPCODE_ADD_HI;
8800 inst.instruction |= (Rd & 8) << 4;
8801 inst.instruction |= (Rd & 7);
8802 if (Rs == Rd)
8803 inst.instruction |= Rn << 3;
8804 else if (Rn == Rd)
8805 inst.instruction |= Rs << 3;
8806 else
8807 constraint (1, _("dest must overlap one source register"));
8808 }
8809 else
8810 {
8811 inst.instruction = (inst.instruction == T_MNEM_add
8812 ? T_OPCODE_ADD_R3 : T_OPCODE_SUB_R3);
8813 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
b99bd4ef 8814 }
b99bd4ef 8815 }
b99bd4ef
NC
8816}
8817
c19d1205
ZW
8818static void
8819do_t_adr (void)
8820{
fdfde340
JM
8821 unsigned Rd;
8822
8823 Rd = inst.operands[0].reg;
8824 reject_bad_reg (Rd);
8825
8826 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
0110f2b8
PB
8827 {
8828 /* Defer to section relaxation. */
8829 inst.relax = inst.instruction;
8830 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 8831 inst.instruction |= Rd << 4;
0110f2b8
PB
8832 }
8833 else if (unified_syntax && inst.size_req != 2)
e9f89963 8834 {
0110f2b8 8835 /* Generate a 32-bit opcode. */
e9f89963 8836 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 8837 inst.instruction |= Rd << 8;
e9f89963
PB
8838 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8839 inst.reloc.pc_rel = 1;
8840 }
8841 else
8842 {
0110f2b8 8843 /* Generate a 16-bit opcode. */
e9f89963
PB
8844 inst.instruction = THUMB_OP16 (inst.instruction);
8845 inst.reloc.type = BFD_RELOC_ARM_THUMB_ADD;
8846 inst.reloc.exp.X_add_number -= 4; /* PC relative adjust. */
8847 inst.reloc.pc_rel = 1;
b99bd4ef 8848
fdfde340 8849 inst.instruction |= Rd << 4;
e9f89963 8850 }
c19d1205 8851}
b99bd4ef 8852
c19d1205
ZW
8853/* Arithmetic instructions for which there is just one 16-bit
8854 instruction encoding, and it allows only two low registers.
8855 For maximal compatibility with ARM syntax, we allow three register
8856 operands even when Thumb-32 instructions are not available, as long
8857 as the first two are identical. For instance, both "sbc r0,r1" and
8858 "sbc r0,r0,r1" are allowed. */
b99bd4ef 8859static void
c19d1205 8860do_t_arit3 (void)
b99bd4ef 8861{
c19d1205 8862 int Rd, Rs, Rn;
b99bd4ef 8863
c19d1205
ZW
8864 Rd = inst.operands[0].reg;
8865 Rs = (inst.operands[1].present
8866 ? inst.operands[1].reg /* Rd, Rs, foo */
8867 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8868 Rn = inst.operands[2].reg;
b99bd4ef 8869
fdfde340
JM
8870 reject_bad_reg (Rd);
8871 reject_bad_reg (Rs);
8872 if (inst.operands[2].isreg)
8873 reject_bad_reg (Rn);
8874
c19d1205 8875 if (unified_syntax)
b99bd4ef 8876 {
c19d1205
ZW
8877 if (!inst.operands[2].isreg)
8878 {
8879 /* For an immediate, we always generate a 32-bit opcode;
8880 section relaxation will shrink it later if possible. */
8881 inst.instruction = THUMB_OP32 (inst.instruction);
8882 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8883 inst.instruction |= Rd << 8;
8884 inst.instruction |= Rs << 16;
8885 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
8886 }
8887 else
8888 {
e27ec89e
PB
8889 bfd_boolean narrow;
8890
c19d1205 8891 /* See if we can do this with a 16-bit instruction. */
e27ec89e 8892 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 8893 narrow = !in_it_block ();
e27ec89e 8894 else
e07e6e58 8895 narrow = in_it_block ();
e27ec89e
PB
8896
8897 if (Rd > 7 || Rn > 7 || Rs > 7)
8898 narrow = FALSE;
8899 if (inst.operands[2].shifted)
8900 narrow = FALSE;
8901 if (inst.size_req == 4)
8902 narrow = FALSE;
8903
8904 if (narrow
c19d1205
ZW
8905 && Rd == Rs)
8906 {
8907 inst.instruction = THUMB_OP16 (inst.instruction);
8908 inst.instruction |= Rd;
8909 inst.instruction |= Rn << 3;
8910 return;
8911 }
b99bd4ef 8912
c19d1205
ZW
8913 /* If we get here, it can't be done in 16 bits. */
8914 constraint (inst.operands[2].shifted
8915 && inst.operands[2].immisreg,
8916 _("shift must be constant"));
8917 inst.instruction = THUMB_OP32 (inst.instruction);
8918 inst.instruction |= Rd << 8;
8919 inst.instruction |= Rs << 16;
8920 encode_thumb32_shifted_operand (2);
8921 }
a737bd4d 8922 }
c19d1205 8923 else
b99bd4ef 8924 {
c19d1205
ZW
8925 /* On its face this is a lie - the instruction does set the
8926 flags. However, the only supported mnemonic in this mode
8927 says it doesn't. */
8928 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 8929
c19d1205
ZW
8930 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
8931 _("unshifted register required"));
8932 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
8933 constraint (Rd != Rs,
8934 _("dest and source1 must be the same register"));
a737bd4d 8935
c19d1205
ZW
8936 inst.instruction = THUMB_OP16 (inst.instruction);
8937 inst.instruction |= Rd;
8938 inst.instruction |= Rn << 3;
b99bd4ef 8939 }
a737bd4d 8940}
b99bd4ef 8941
c19d1205
ZW
8942/* Similarly, but for instructions where the arithmetic operation is
8943 commutative, so we can allow either of them to be different from
8944 the destination operand in a 16-bit instruction. For instance, all
8945 three of "adc r0,r1", "adc r0,r0,r1", and "adc r0,r1,r0" are
8946 accepted. */
8947static void
8948do_t_arit3c (void)
a737bd4d 8949{
c19d1205 8950 int Rd, Rs, Rn;
b99bd4ef 8951
c19d1205
ZW
8952 Rd = inst.operands[0].reg;
8953 Rs = (inst.operands[1].present
8954 ? inst.operands[1].reg /* Rd, Rs, foo */
8955 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
8956 Rn = inst.operands[2].reg;
fdfde340
JM
8957
8958 reject_bad_reg (Rd);
8959 reject_bad_reg (Rs);
8960 if (inst.operands[2].isreg)
8961 reject_bad_reg (Rn);
a737bd4d 8962
c19d1205 8963 if (unified_syntax)
a737bd4d 8964 {
c19d1205 8965 if (!inst.operands[2].isreg)
b99bd4ef 8966 {
c19d1205
ZW
8967 /* For an immediate, we always generate a 32-bit opcode;
8968 section relaxation will shrink it later if possible. */
8969 inst.instruction = THUMB_OP32 (inst.instruction);
8970 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
8971 inst.instruction |= Rd << 8;
8972 inst.instruction |= Rs << 16;
8973 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 8974 }
c19d1205 8975 else
a737bd4d 8976 {
e27ec89e
PB
8977 bfd_boolean narrow;
8978
c19d1205 8979 /* See if we can do this with a 16-bit instruction. */
e27ec89e 8980 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 8981 narrow = !in_it_block ();
e27ec89e 8982 else
e07e6e58 8983 narrow = in_it_block ();
e27ec89e
PB
8984
8985 if (Rd > 7 || Rn > 7 || Rs > 7)
8986 narrow = FALSE;
8987 if (inst.operands[2].shifted)
8988 narrow = FALSE;
8989 if (inst.size_req == 4)
8990 narrow = FALSE;
8991
8992 if (narrow)
a737bd4d 8993 {
c19d1205 8994 if (Rd == Rs)
a737bd4d 8995 {
c19d1205
ZW
8996 inst.instruction = THUMB_OP16 (inst.instruction);
8997 inst.instruction |= Rd;
8998 inst.instruction |= Rn << 3;
8999 return;
a737bd4d 9000 }
c19d1205 9001 if (Rd == Rn)
a737bd4d 9002 {
c19d1205
ZW
9003 inst.instruction = THUMB_OP16 (inst.instruction);
9004 inst.instruction |= Rd;
9005 inst.instruction |= Rs << 3;
9006 return;
a737bd4d
NC
9007 }
9008 }
c19d1205
ZW
9009
9010 /* If we get here, it can't be done in 16 bits. */
9011 constraint (inst.operands[2].shifted
9012 && inst.operands[2].immisreg,
9013 _("shift must be constant"));
9014 inst.instruction = THUMB_OP32 (inst.instruction);
9015 inst.instruction |= Rd << 8;
9016 inst.instruction |= Rs << 16;
9017 encode_thumb32_shifted_operand (2);
a737bd4d 9018 }
b99bd4ef 9019 }
c19d1205
ZW
9020 else
9021 {
9022 /* On its face this is a lie - the instruction does set the
9023 flags. However, the only supported mnemonic in this mode
9024 says it doesn't. */
9025 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
a737bd4d 9026
c19d1205
ZW
9027 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9028 _("unshifted register required"));
9029 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9030
9031 inst.instruction = THUMB_OP16 (inst.instruction);
9032 inst.instruction |= Rd;
9033
9034 if (Rd == Rs)
9035 inst.instruction |= Rn << 3;
9036 else if (Rd == Rn)
9037 inst.instruction |= Rs << 3;
9038 else
9039 constraint (1, _("dest must overlap one source register"));
9040 }
a737bd4d
NC
9041}
9042
62b3e311
PB
9043static void
9044do_t_barrier (void)
9045{
9046 if (inst.operands[0].present)
9047 {
9048 constraint ((inst.instruction & 0xf0) != 0x40
9049 && inst.operands[0].imm != 0xf,
bd3ba5d1 9050 _("bad barrier type"));
62b3e311
PB
9051 inst.instruction |= inst.operands[0].imm;
9052 }
9053 else
9054 inst.instruction |= 0xf;
9055}
9056
c19d1205
ZW
9057static void
9058do_t_bfc (void)
a737bd4d 9059{
fdfde340 9060 unsigned Rd;
c19d1205
ZW
9061 unsigned int msb = inst.operands[1].imm + inst.operands[2].imm;
9062 constraint (msb > 32, _("bit-field extends past end of register"));
9063 /* The instruction encoding stores the LSB and MSB,
9064 not the LSB and width. */
fdfde340
JM
9065 Rd = inst.operands[0].reg;
9066 reject_bad_reg (Rd);
9067 inst.instruction |= Rd << 8;
c19d1205
ZW
9068 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9069 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9070 inst.instruction |= msb - 1;
b99bd4ef
NC
9071}
9072
c19d1205
ZW
9073static void
9074do_t_bfi (void)
b99bd4ef 9075{
fdfde340 9076 int Rd, Rn;
c19d1205 9077 unsigned int msb;
b99bd4ef 9078
fdfde340
JM
9079 Rd = inst.operands[0].reg;
9080 reject_bad_reg (Rd);
9081
c19d1205
ZW
9082 /* #0 in second position is alternative syntax for bfc, which is
9083 the same instruction but with REG_PC in the Rm field. */
9084 if (!inst.operands[1].isreg)
fdfde340
JM
9085 Rn = REG_PC;
9086 else
9087 {
9088 Rn = inst.operands[1].reg;
9089 reject_bad_reg (Rn);
9090 }
b99bd4ef 9091
c19d1205
ZW
9092 msb = inst.operands[2].imm + inst.operands[3].imm;
9093 constraint (msb > 32, _("bit-field extends past end of register"));
9094 /* The instruction encoding stores the LSB and MSB,
9095 not the LSB and width. */
fdfde340
JM
9096 inst.instruction |= Rd << 8;
9097 inst.instruction |= Rn << 16;
c19d1205
ZW
9098 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9099 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9100 inst.instruction |= msb - 1;
b99bd4ef
NC
9101}
9102
c19d1205
ZW
9103static void
9104do_t_bfx (void)
b99bd4ef 9105{
fdfde340
JM
9106 unsigned Rd, Rn;
9107
9108 Rd = inst.operands[0].reg;
9109 Rn = inst.operands[1].reg;
9110
9111 reject_bad_reg (Rd);
9112 reject_bad_reg (Rn);
9113
c19d1205
ZW
9114 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9115 _("bit-field extends past end of register"));
fdfde340
JM
9116 inst.instruction |= Rd << 8;
9117 inst.instruction |= Rn << 16;
c19d1205
ZW
9118 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9119 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9120 inst.instruction |= inst.operands[3].imm - 1;
9121}
b99bd4ef 9122
c19d1205
ZW
9123/* ARM V5 Thumb BLX (argument parse)
9124 BLX <target_addr> which is BLX(1)
9125 BLX <Rm> which is BLX(2)
9126 Unfortunately, there are two different opcodes for this mnemonic.
9127 So, the insns[].value is not used, and the code here zaps values
9128 into inst.instruction.
b99bd4ef 9129
c19d1205
ZW
9130 ??? How to take advantage of the additional two bits of displacement
9131 available in Thumb32 mode? Need new relocation? */
b99bd4ef 9132
c19d1205
ZW
9133static void
9134do_t_blx (void)
9135{
e07e6e58
NC
9136 set_it_insn_type_last ();
9137
c19d1205 9138 if (inst.operands[0].isreg)
fdfde340
JM
9139 {
9140 constraint (inst.operands[0].reg == REG_PC, BAD_PC);
9141 /* We have a register, so this is BLX(2). */
9142 inst.instruction |= inst.operands[0].reg << 3;
9143 }
b99bd4ef
NC
9144 else
9145 {
c19d1205 9146 /* No register. This must be BLX(1). */
2fc8bdac 9147 inst.instruction = 0xf000e800;
00adf2d4 9148 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
c19d1205 9149 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9150 }
9151}
9152
c19d1205
ZW
9153static void
9154do_t_branch (void)
b99bd4ef 9155{
0110f2b8 9156 int opcode;
dfa9f0d5
PB
9157 int cond;
9158
e07e6e58
NC
9159 cond = inst.cond;
9160 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9161
9162 if (in_it_block ())
dfa9f0d5
PB
9163 {
9164 /* Conditional branches inside IT blocks are encoded as unconditional
9165 branches. */
9166 cond = COND_ALWAYS;
dfa9f0d5
PB
9167 }
9168 else
9169 cond = inst.cond;
9170
9171 if (cond != COND_ALWAYS)
0110f2b8
PB
9172 opcode = T_MNEM_bcond;
9173 else
9174 opcode = inst.instruction;
9175
9176 if (unified_syntax && inst.size_req == 4)
c19d1205 9177 {
0110f2b8 9178 inst.instruction = THUMB_OP32(opcode);
dfa9f0d5 9179 if (cond == COND_ALWAYS)
0110f2b8 9180 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
c19d1205
ZW
9181 else
9182 {
9c2799c2 9183 gas_assert (cond != 0xF);
dfa9f0d5 9184 inst.instruction |= cond << 22;
c19d1205
ZW
9185 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9186 }
9187 }
b99bd4ef
NC
9188 else
9189 {
0110f2b8 9190 inst.instruction = THUMB_OP16(opcode);
dfa9f0d5 9191 if (cond == COND_ALWAYS)
c19d1205
ZW
9192 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9193 else
b99bd4ef 9194 {
dfa9f0d5 9195 inst.instruction |= cond << 8;
c19d1205 9196 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
b99bd4ef 9197 }
0110f2b8
PB
9198 /* Allow section relaxation. */
9199 if (unified_syntax && inst.size_req != 2)
9200 inst.relax = opcode;
b99bd4ef 9201 }
c19d1205
ZW
9202
9203 inst.reloc.pc_rel = 1;
b99bd4ef
NC
9204}
9205
9206static void
c19d1205 9207do_t_bkpt (void)
b99bd4ef 9208{
dfa9f0d5
PB
9209 constraint (inst.cond != COND_ALWAYS,
9210 _("instruction is always unconditional"));
c19d1205 9211 if (inst.operands[0].present)
b99bd4ef 9212 {
c19d1205
ZW
9213 constraint (inst.operands[0].imm > 255,
9214 _("immediate value out of range"));
9215 inst.instruction |= inst.operands[0].imm;
e07e6e58 9216 set_it_insn_type (NEUTRAL_IT_INSN);
b99bd4ef 9217 }
b99bd4ef
NC
9218}
9219
9220static void
c19d1205 9221do_t_branch23 (void)
b99bd4ef 9222{
e07e6e58 9223 set_it_insn_type_last ();
c19d1205 9224 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
90e4755a
RE
9225 inst.reloc.pc_rel = 1;
9226
4343666d 9227#if defined(OBJ_COFF)
c19d1205
ZW
9228 /* If the destination of the branch is a defined symbol which does not have
9229 the THUMB_FUNC attribute, then we must be calling a function which has
9230 the (interfacearm) attribute. We look for the Thumb entry point to that
9231 function and change the branch to refer to that function instead. */
9232 if ( inst.reloc.exp.X_op == O_symbol
9233 && inst.reloc.exp.X_add_symbol != NULL
9234 && S_IS_DEFINED (inst.reloc.exp.X_add_symbol)
9235 && ! THUMB_IS_FUNC (inst.reloc.exp.X_add_symbol))
9236 inst.reloc.exp.X_add_symbol =
9237 find_real_start (inst.reloc.exp.X_add_symbol);
4343666d 9238#endif
90e4755a
RE
9239}
9240
9241static void
c19d1205 9242do_t_bx (void)
90e4755a 9243{
e07e6e58 9244 set_it_insn_type_last ();
c19d1205
ZW
9245 inst.instruction |= inst.operands[0].reg << 3;
9246 /* ??? FIXME: Should add a hacky reloc here if reg is REG_PC. The reloc
9247 should cause the alignment to be checked once it is known. This is
9248 because BX PC only works if the instruction is word aligned. */
9249}
90e4755a 9250
c19d1205
ZW
9251static void
9252do_t_bxj (void)
9253{
fdfde340 9254 int Rm;
90e4755a 9255
e07e6e58 9256 set_it_insn_type_last ();
fdfde340
JM
9257 Rm = inst.operands[0].reg;
9258 reject_bad_reg (Rm);
9259 inst.instruction |= Rm << 16;
90e4755a
RE
9260}
9261
9262static void
c19d1205 9263do_t_clz (void)
90e4755a 9264{
fdfde340
JM
9265 unsigned Rd;
9266 unsigned Rm;
9267
9268 Rd = inst.operands[0].reg;
9269 Rm = inst.operands[1].reg;
9270
9271 reject_bad_reg (Rd);
9272 reject_bad_reg (Rm);
9273
9274 inst.instruction |= Rd << 8;
9275 inst.instruction |= Rm << 16;
9276 inst.instruction |= Rm;
c19d1205 9277}
90e4755a 9278
dfa9f0d5
PB
9279static void
9280do_t_cps (void)
9281{
e07e6e58 9282 set_it_insn_type (OUTSIDE_IT_INSN);
dfa9f0d5
PB
9283 inst.instruction |= inst.operands[0].imm;
9284}
9285
c19d1205
ZW
9286static void
9287do_t_cpsi (void)
9288{
e07e6e58 9289 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205 9290 if (unified_syntax
62b3e311
PB
9291 && (inst.operands[1].present || inst.size_req == 4)
9292 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
90e4755a 9293 {
c19d1205
ZW
9294 unsigned int imod = (inst.instruction & 0x0030) >> 4;
9295 inst.instruction = 0xf3af8000;
9296 inst.instruction |= imod << 9;
9297 inst.instruction |= inst.operands[0].imm << 5;
9298 if (inst.operands[1].present)
9299 inst.instruction |= 0x100 | inst.operands[1].imm;
90e4755a 9300 }
c19d1205 9301 else
90e4755a 9302 {
62b3e311
PB
9303 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1)
9304 && (inst.operands[0].imm & 4),
9305 _("selected processor does not support 'A' form "
9306 "of this instruction"));
9307 constraint (inst.operands[1].present || inst.size_req == 4,
c19d1205
ZW
9308 _("Thumb does not support the 2-argument "
9309 "form of this instruction"));
9310 inst.instruction |= inst.operands[0].imm;
90e4755a 9311 }
90e4755a
RE
9312}
9313
c19d1205
ZW
9314/* THUMB CPY instruction (argument parse). */
9315
90e4755a 9316static void
c19d1205 9317do_t_cpy (void)
90e4755a 9318{
c19d1205 9319 if (inst.size_req == 4)
90e4755a 9320 {
c19d1205
ZW
9321 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9322 inst.instruction |= inst.operands[0].reg << 8;
9323 inst.instruction |= inst.operands[1].reg;
90e4755a 9324 }
c19d1205 9325 else
90e4755a 9326 {
c19d1205
ZW
9327 inst.instruction |= (inst.operands[0].reg & 0x8) << 4;
9328 inst.instruction |= (inst.operands[0].reg & 0x7);
9329 inst.instruction |= inst.operands[1].reg << 3;
90e4755a 9330 }
90e4755a
RE
9331}
9332
90e4755a 9333static void
25fe350b 9334do_t_cbz (void)
90e4755a 9335{
e07e6e58 9336 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
9337 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9338 inst.instruction |= inst.operands[0].reg;
9339 inst.reloc.pc_rel = 1;
9340 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH7;
9341}
90e4755a 9342
62b3e311
PB
9343static void
9344do_t_dbg (void)
9345{
9346 inst.instruction |= inst.operands[0].imm;
9347}
9348
9349static void
9350do_t_div (void)
9351{
fdfde340
JM
9352 unsigned Rd, Rn, Rm;
9353
9354 Rd = inst.operands[0].reg;
9355 Rn = (inst.operands[1].present
9356 ? inst.operands[1].reg : Rd);
9357 Rm = inst.operands[2].reg;
9358
9359 reject_bad_reg (Rd);
9360 reject_bad_reg (Rn);
9361 reject_bad_reg (Rm);
9362
9363 inst.instruction |= Rd << 8;
9364 inst.instruction |= Rn << 16;
9365 inst.instruction |= Rm;
62b3e311
PB
9366}
9367
c19d1205
ZW
9368static void
9369do_t_hint (void)
9370{
9371 if (unified_syntax && inst.size_req == 4)
9372 inst.instruction = THUMB_OP32 (inst.instruction);
9373 else
9374 inst.instruction = THUMB_OP16 (inst.instruction);
9375}
90e4755a 9376
c19d1205
ZW
9377static void
9378do_t_it (void)
9379{
9380 unsigned int cond = inst.operands[0].imm;
e27ec89e 9381
e07e6e58
NC
9382 set_it_insn_type (IT_INSN);
9383 now_it.mask = (inst.instruction & 0xf) | 0x10;
9384 now_it.cc = cond;
e27ec89e
PB
9385
9386 /* If the condition is a negative condition, invert the mask. */
c19d1205 9387 if ((cond & 0x1) == 0x0)
90e4755a 9388 {
c19d1205 9389 unsigned int mask = inst.instruction & 0x000f;
90e4755a 9390
c19d1205
ZW
9391 if ((mask & 0x7) == 0)
9392 /* no conversion needed */;
9393 else if ((mask & 0x3) == 0)
e27ec89e
PB
9394 mask ^= 0x8;
9395 else if ((mask & 0x1) == 0)
9396 mask ^= 0xC;
c19d1205 9397 else
e27ec89e 9398 mask ^= 0xE;
90e4755a 9399
e27ec89e
PB
9400 inst.instruction &= 0xfff0;
9401 inst.instruction |= mask;
c19d1205 9402 }
90e4755a 9403
c19d1205
ZW
9404 inst.instruction |= cond << 4;
9405}
90e4755a 9406
3c707909
PB
9407/* Helper function used for both push/pop and ldm/stm. */
9408static void
9409encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9410{
9411 bfd_boolean load;
9412
9413 load = (inst.instruction & (1 << 20)) != 0;
9414
9415 if (mask & (1 << 13))
9416 inst.error = _("SP not allowed in register list");
9417 if (load)
9418 {
e07e6e58
NC
9419 if (mask & (1 << 15))
9420 {
9421 if (mask & (1 << 14))
9422 inst.error = _("LR and PC should not both be in register list");
9423 else
9424 set_it_insn_type_last ();
9425 }
3c707909
PB
9426
9427 if ((mask & (1 << base)) != 0
9428 && writeback)
9429 as_warn (_("base register should not be in register list "
9430 "when written back"));
9431 }
9432 else
9433 {
9434 if (mask & (1 << 15))
9435 inst.error = _("PC not allowed in register list");
9436
9437 if (mask & (1 << base))
9438 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9439 }
9440
9441 if ((mask & (mask - 1)) == 0)
9442 {
9443 /* Single register transfers implemented as str/ldr. */
9444 if (writeback)
9445 {
9446 if (inst.instruction & (1 << 23))
9447 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9448 else
9449 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9450 }
9451 else
9452 {
9453 if (inst.instruction & (1 << 23))
9454 inst.instruction = 0x00800000; /* ia -> [base] */
9455 else
9456 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9457 }
9458
9459 inst.instruction |= 0xf8400000;
9460 if (load)
9461 inst.instruction |= 0x00100000;
9462
5f4273c7 9463 mask = ffs (mask) - 1;
3c707909
PB
9464 mask <<= 12;
9465 }
9466 else if (writeback)
9467 inst.instruction |= WRITE_BACK;
9468
9469 inst.instruction |= mask;
9470 inst.instruction |= base << 16;
9471}
9472
c19d1205
ZW
9473static void
9474do_t_ldmstm (void)
9475{
9476 /* This really doesn't seem worth it. */
9477 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
9478 _("expression too complex"));
9479 constraint (inst.operands[1].writeback,
9480 _("Thumb load/store multiple does not support {reglist}^"));
90e4755a 9481
c19d1205
ZW
9482 if (unified_syntax)
9483 {
3c707909
PB
9484 bfd_boolean narrow;
9485 unsigned mask;
9486
9487 narrow = FALSE;
c19d1205
ZW
9488 /* See if we can use a 16-bit instruction. */
9489 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9490 && inst.size_req != 4
3c707909 9491 && !(inst.operands[1].imm & ~0xff))
90e4755a 9492 {
3c707909 9493 mask = 1 << inst.operands[0].reg;
90e4755a 9494
3c707909
PB
9495 if (inst.operands[0].reg <= 7
9496 && (inst.instruction == T_MNEM_stmia
9497 ? inst.operands[0].writeback
9498 : (inst.operands[0].writeback
9499 == !(inst.operands[1].imm & mask))))
90e4755a 9500 {
3c707909
PB
9501 if (inst.instruction == T_MNEM_stmia
9502 && (inst.operands[1].imm & mask)
9503 && (inst.operands[1].imm & (mask - 1)))
c19d1205
ZW
9504 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9505 inst.operands[0].reg);
3c707909
PB
9506
9507 inst.instruction = THUMB_OP16 (inst.instruction);
9508 inst.instruction |= inst.operands[0].reg << 8;
9509 inst.instruction |= inst.operands[1].imm;
9510 narrow = TRUE;
90e4755a 9511 }
3c707909
PB
9512 else if (inst.operands[0] .reg == REG_SP
9513 && inst.operands[0].writeback)
90e4755a 9514 {
3c707909
PB
9515 inst.instruction = THUMB_OP16 (inst.instruction == T_MNEM_stmia
9516 ? T_MNEM_push : T_MNEM_pop);
9517 inst.instruction |= inst.operands[1].imm;
9518 narrow = TRUE;
90e4755a 9519 }
3c707909
PB
9520 }
9521
9522 if (!narrow)
9523 {
c19d1205
ZW
9524 if (inst.instruction < 0xffff)
9525 inst.instruction = THUMB_OP32 (inst.instruction);
3c707909 9526
5f4273c7
NC
9527 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9528 inst.operands[0].writeback);
90e4755a
RE
9529 }
9530 }
c19d1205 9531 else
90e4755a 9532 {
c19d1205
ZW
9533 constraint (inst.operands[0].reg > 7
9534 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
1198ca51
PB
9535 constraint (inst.instruction != T_MNEM_ldmia
9536 && inst.instruction != T_MNEM_stmia,
9537 _("Thumb-2 instruction only valid in unified syntax"));
c19d1205 9538 if (inst.instruction == T_MNEM_stmia)
f03698e6 9539 {
c19d1205
ZW
9540 if (!inst.operands[0].writeback)
9541 as_warn (_("this instruction will write back the base register"));
9542 if ((inst.operands[1].imm & (1 << inst.operands[0].reg))
9543 && (inst.operands[1].imm & ((1 << inst.operands[0].reg) - 1)))
9544 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9545 inst.operands[0].reg);
f03698e6 9546 }
c19d1205 9547 else
90e4755a 9548 {
c19d1205
ZW
9549 if (!inst.operands[0].writeback
9550 && !(inst.operands[1].imm & (1 << inst.operands[0].reg)))
9551 as_warn (_("this instruction will write back the base register"));
9552 else if (inst.operands[0].writeback
9553 && (inst.operands[1].imm & (1 << inst.operands[0].reg)))
9554 as_warn (_("this instruction will not write back the base register"));
90e4755a
RE
9555 }
9556
c19d1205
ZW
9557 inst.instruction = THUMB_OP16 (inst.instruction);
9558 inst.instruction |= inst.operands[0].reg << 8;
9559 inst.instruction |= inst.operands[1].imm;
9560 }
9561}
e28cd48c 9562
c19d1205
ZW
9563static void
9564do_t_ldrex (void)
9565{
9566 constraint (!inst.operands[1].isreg || !inst.operands[1].preind
9567 || inst.operands[1].postind || inst.operands[1].writeback
9568 || inst.operands[1].immisreg || inst.operands[1].shifted
9569 || inst.operands[1].negative,
01cfc07f 9570 BAD_ADDR_MODE);
e28cd48c 9571
c19d1205
ZW
9572 inst.instruction |= inst.operands[0].reg << 12;
9573 inst.instruction |= inst.operands[1].reg << 16;
9574 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
9575}
e28cd48c 9576
c19d1205
ZW
9577static void
9578do_t_ldrexd (void)
9579{
9580 if (!inst.operands[1].present)
1cac9012 9581 {
c19d1205
ZW
9582 constraint (inst.operands[0].reg == REG_LR,
9583 _("r14 not allowed as first register "
9584 "when second register is omitted"));
9585 inst.operands[1].reg = inst.operands[0].reg + 1;
b99bd4ef 9586 }
c19d1205
ZW
9587 constraint (inst.operands[0].reg == inst.operands[1].reg,
9588 BAD_OVERLAP);
b99bd4ef 9589
c19d1205
ZW
9590 inst.instruction |= inst.operands[0].reg << 12;
9591 inst.instruction |= inst.operands[1].reg << 8;
9592 inst.instruction |= inst.operands[2].reg << 16;
b99bd4ef
NC
9593}
9594
9595static void
c19d1205 9596do_t_ldst (void)
b99bd4ef 9597{
0110f2b8
PB
9598 unsigned long opcode;
9599 int Rn;
9600
e07e6e58
NC
9601 if (inst.operands[0].isreg
9602 && !inst.operands[0].preind
9603 && inst.operands[0].reg == REG_PC)
9604 set_it_insn_type_last ();
9605
0110f2b8 9606 opcode = inst.instruction;
c19d1205 9607 if (unified_syntax)
b99bd4ef 9608 {
53365c0d
PB
9609 if (!inst.operands[1].isreg)
9610 {
9611 if (opcode <= 0xffff)
9612 inst.instruction = THUMB_OP32 (opcode);
9613 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9614 return;
9615 }
0110f2b8
PB
9616 if (inst.operands[1].isreg
9617 && !inst.operands[1].writeback
c19d1205
ZW
9618 && !inst.operands[1].shifted && !inst.operands[1].postind
9619 && !inst.operands[1].negative && inst.operands[0].reg <= 7
0110f2b8
PB
9620 && opcode <= 0xffff
9621 && inst.size_req != 4)
c19d1205 9622 {
0110f2b8
PB
9623 /* Insn may have a 16-bit form. */
9624 Rn = inst.operands[1].reg;
9625 if (inst.operands[1].immisreg)
9626 {
9627 inst.instruction = THUMB_OP16 (opcode);
5f4273c7 9628 /* [Rn, Rik] */
0110f2b8
PB
9629 if (Rn <= 7 && inst.operands[1].imm <= 7)
9630 goto op16;
9631 }
9632 else if ((Rn <= 7 && opcode != T_MNEM_ldrsh
9633 && opcode != T_MNEM_ldrsb)
9634 || ((Rn == REG_PC || Rn == REG_SP) && opcode == T_MNEM_ldr)
9635 || (Rn == REG_SP && opcode == T_MNEM_str))
9636 {
9637 /* [Rn, #const] */
9638 if (Rn > 7)
9639 {
9640 if (Rn == REG_PC)
9641 {
9642 if (inst.reloc.pc_rel)
9643 opcode = T_MNEM_ldr_pc2;
9644 else
9645 opcode = T_MNEM_ldr_pc;
9646 }
9647 else
9648 {
9649 if (opcode == T_MNEM_ldr)
9650 opcode = T_MNEM_ldr_sp;
9651 else
9652 opcode = T_MNEM_str_sp;
9653 }
9654 inst.instruction = inst.operands[0].reg << 8;
9655 }
9656 else
9657 {
9658 inst.instruction = inst.operands[0].reg;
9659 inst.instruction |= inst.operands[1].reg << 3;
9660 }
9661 inst.instruction |= THUMB_OP16 (opcode);
9662 if (inst.size_req == 2)
9663 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9664 else
9665 inst.relax = opcode;
9666 return;
9667 }
c19d1205 9668 }
0110f2b8
PB
9669 /* Definitely a 32-bit variant. */
9670 inst.instruction = THUMB_OP32 (opcode);
c19d1205
ZW
9671 inst.instruction |= inst.operands[0].reg << 12;
9672 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
b99bd4ef
NC
9673 return;
9674 }
9675
c19d1205
ZW
9676 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9677
9678 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
b99bd4ef 9679 {
c19d1205
ZW
9680 /* Only [Rn,Rm] is acceptable. */
9681 constraint (inst.operands[1].reg > 7 || inst.operands[1].imm > 7, BAD_HIREG);
9682 constraint (!inst.operands[1].isreg || !inst.operands[1].immisreg
9683 || inst.operands[1].postind || inst.operands[1].shifted
9684 || inst.operands[1].negative,
9685 _("Thumb does not support this addressing mode"));
9686 inst.instruction = THUMB_OP16 (inst.instruction);
9687 goto op16;
b99bd4ef 9688 }
5f4273c7 9689
c19d1205
ZW
9690 inst.instruction = THUMB_OP16 (inst.instruction);
9691 if (!inst.operands[1].isreg)
9692 if (move_or_literal_pool (0, /*thumb_p=*/TRUE, /*mode_3=*/FALSE))
9693 return;
b99bd4ef 9694
c19d1205
ZW
9695 constraint (!inst.operands[1].preind
9696 || inst.operands[1].shifted
9697 || inst.operands[1].writeback,
9698 _("Thumb does not support this addressing mode"));
9699 if (inst.operands[1].reg == REG_PC || inst.operands[1].reg == REG_SP)
90e4755a 9700 {
c19d1205
ZW
9701 constraint (inst.instruction & 0x0600,
9702 _("byte or halfword not valid for base register"));
9703 constraint (inst.operands[1].reg == REG_PC
9704 && !(inst.instruction & THUMB_LOAD_BIT),
9705 _("r15 based store not allowed"));
9706 constraint (inst.operands[1].immisreg,
9707 _("invalid base register for register offset"));
b99bd4ef 9708
c19d1205
ZW
9709 if (inst.operands[1].reg == REG_PC)
9710 inst.instruction = T_OPCODE_LDR_PC;
9711 else if (inst.instruction & THUMB_LOAD_BIT)
9712 inst.instruction = T_OPCODE_LDR_SP;
9713 else
9714 inst.instruction = T_OPCODE_STR_SP;
b99bd4ef 9715
c19d1205
ZW
9716 inst.instruction |= inst.operands[0].reg << 8;
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9718 return;
9719 }
90e4755a 9720
c19d1205
ZW
9721 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9722 if (!inst.operands[1].immisreg)
9723 {
9724 /* Immediate offset. */
9725 inst.instruction |= inst.operands[0].reg;
9726 inst.instruction |= inst.operands[1].reg << 3;
9727 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9728 return;
9729 }
90e4755a 9730
c19d1205
ZW
9731 /* Register offset. */
9732 constraint (inst.operands[1].imm > 7, BAD_HIREG);
9733 constraint (inst.operands[1].negative,
9734 _("Thumb does not support this addressing mode"));
90e4755a 9735
c19d1205
ZW
9736 op16:
9737 switch (inst.instruction)
9738 {
9739 case T_OPCODE_STR_IW: inst.instruction = T_OPCODE_STR_RW; break;
9740 case T_OPCODE_STR_IH: inst.instruction = T_OPCODE_STR_RH; break;
9741 case T_OPCODE_STR_IB: inst.instruction = T_OPCODE_STR_RB; break;
9742 case T_OPCODE_LDR_IW: inst.instruction = T_OPCODE_LDR_RW; break;
9743 case T_OPCODE_LDR_IH: inst.instruction = T_OPCODE_LDR_RH; break;
9744 case T_OPCODE_LDR_IB: inst.instruction = T_OPCODE_LDR_RB; break;
9745 case 0x5600 /* ldrsb */:
9746 case 0x5e00 /* ldrsh */: break;
9747 default: abort ();
9748 }
90e4755a 9749
c19d1205
ZW
9750 inst.instruction |= inst.operands[0].reg;
9751 inst.instruction |= inst.operands[1].reg << 3;
9752 inst.instruction |= inst.operands[1].imm << 6;
9753}
90e4755a 9754
c19d1205
ZW
9755static void
9756do_t_ldstd (void)
9757{
9758 if (!inst.operands[1].present)
b99bd4ef 9759 {
c19d1205
ZW
9760 inst.operands[1].reg = inst.operands[0].reg + 1;
9761 constraint (inst.operands[0].reg == REG_LR,
9762 _("r14 not allowed here"));
b99bd4ef 9763 }
c19d1205
ZW
9764 inst.instruction |= inst.operands[0].reg << 12;
9765 inst.instruction |= inst.operands[1].reg << 8;
9766 encode_thumb32_addr_mode (2, /*is_t=*/FALSE, /*is_d=*/TRUE);
b99bd4ef
NC
9767}
9768
c19d1205
ZW
9769static void
9770do_t_ldstt (void)
9771{
9772 inst.instruction |= inst.operands[0].reg << 12;
9773 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9774}
a737bd4d 9775
b99bd4ef 9776static void
c19d1205 9777do_t_mla (void)
b99bd4ef 9778{
fdfde340
JM
9779 unsigned Rd, Rn, Rm, Ra;
9780
9781 Rd = inst.operands[0].reg;
9782 Rn = inst.operands[1].reg;
9783 Rm = inst.operands[2].reg;
9784 Ra = inst.operands[3].reg;
9785
9786 reject_bad_reg (Rd);
9787 reject_bad_reg (Rn);
9788 reject_bad_reg (Rm);
9789 reject_bad_reg (Ra);
9790
9791 inst.instruction |= Rd << 8;
9792 inst.instruction |= Rn << 16;
9793 inst.instruction |= Rm;
9794 inst.instruction |= Ra << 12;
c19d1205 9795}
b99bd4ef 9796
c19d1205
ZW
9797static void
9798do_t_mlal (void)
9799{
fdfde340
JM
9800 unsigned RdLo, RdHi, Rn, Rm;
9801
9802 RdLo = inst.operands[0].reg;
9803 RdHi = inst.operands[1].reg;
9804 Rn = inst.operands[2].reg;
9805 Rm = inst.operands[3].reg;
9806
9807 reject_bad_reg (RdLo);
9808 reject_bad_reg (RdHi);
9809 reject_bad_reg (Rn);
9810 reject_bad_reg (Rm);
9811
9812 inst.instruction |= RdLo << 12;
9813 inst.instruction |= RdHi << 8;
9814 inst.instruction |= Rn << 16;
9815 inst.instruction |= Rm;
c19d1205 9816}
b99bd4ef 9817
c19d1205
ZW
9818static void
9819do_t_mov_cmp (void)
9820{
fdfde340
JM
9821 unsigned Rn, Rm;
9822
9823 Rn = inst.operands[0].reg;
9824 Rm = inst.operands[1].reg;
9825
e07e6e58
NC
9826 if (Rn == REG_PC)
9827 set_it_insn_type_last ();
9828
c19d1205 9829 if (unified_syntax)
b99bd4ef 9830 {
c19d1205
ZW
9831 int r0off = (inst.instruction == T_MNEM_mov
9832 || inst.instruction == T_MNEM_movs) ? 8 : 16;
0110f2b8 9833 unsigned long opcode;
3d388997
PB
9834 bfd_boolean narrow;
9835 bfd_boolean low_regs;
9836
fdfde340 9837 low_regs = (Rn <= 7 && Rm <= 7);
0110f2b8 9838 opcode = inst.instruction;
e07e6e58 9839 if (in_it_block ())
0110f2b8 9840 narrow = opcode != T_MNEM_movs;
3d388997 9841 else
0110f2b8 9842 narrow = opcode != T_MNEM_movs || low_regs;
3d388997
PB
9843 if (inst.size_req == 4
9844 || inst.operands[1].shifted)
9845 narrow = FALSE;
9846
efd81785
PB
9847 /* MOVS PC, LR is encoded as SUBS PC, LR, #0. */
9848 if (opcode == T_MNEM_movs && inst.operands[1].isreg
9849 && !inst.operands[1].shifted
fdfde340
JM
9850 && Rn == REG_PC
9851 && Rm == REG_LR)
efd81785
PB
9852 {
9853 inst.instruction = T2_SUBS_PC_LR;
9854 return;
9855 }
9856
fdfde340
JM
9857 if (opcode == T_MNEM_cmp)
9858 {
9859 constraint (Rn == REG_PC, BAD_PC);
94206790
MM
9860 if (narrow)
9861 {
9862 /* In the Thumb-2 ISA, use of R13 as Rm is deprecated,
9863 but valid. */
9864 warn_deprecated_sp (Rm);
9865 /* R15 was documented as a valid choice for Rm in ARMv6,
9866 but as UNPREDICTABLE in ARMv7. ARM's proprietary
9867 tools reject R15, so we do too. */
9868 constraint (Rm == REG_PC, BAD_PC);
9869 }
9870 else
9871 reject_bad_reg (Rm);
fdfde340
JM
9872 }
9873 else if (opcode == T_MNEM_mov
9874 || opcode == T_MNEM_movs)
9875 {
9876 if (inst.operands[1].isreg)
9877 {
9878 if (opcode == T_MNEM_movs)
9879 {
9880 reject_bad_reg (Rn);
9881 reject_bad_reg (Rm);
9882 }
9883 else if ((Rn == REG_SP || Rn == REG_PC)
9884 && (Rm == REG_SP || Rm == REG_PC))
9885 reject_bad_reg (Rm);
9886 }
9887 else
9888 reject_bad_reg (Rn);
9889 }
9890
c19d1205
ZW
9891 if (!inst.operands[1].isreg)
9892 {
0110f2b8 9893 /* Immediate operand. */
e07e6e58 9894 if (!in_it_block () && opcode == T_MNEM_mov)
0110f2b8
PB
9895 narrow = 0;
9896 if (low_regs && narrow)
9897 {
9898 inst.instruction = THUMB_OP16 (opcode);
fdfde340 9899 inst.instruction |= Rn << 8;
0110f2b8
PB
9900 if (inst.size_req == 2)
9901 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9902 else
9903 inst.relax = opcode;
9904 }
9905 else
9906 {
9907 inst.instruction = THUMB_OP32 (inst.instruction);
9908 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 9909 inst.instruction |= Rn << r0off;
0110f2b8
PB
9910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9911 }
c19d1205 9912 }
728ca7c9
PB
9913 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9914 && (inst.instruction == T_MNEM_mov
9915 || inst.instruction == T_MNEM_movs))
9916 {
9917 /* Register shifts are encoded as separate shift instructions. */
9918 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9919
e07e6e58 9920 if (in_it_block ())
728ca7c9
PB
9921 narrow = !flags;
9922 else
9923 narrow = flags;
9924
9925 if (inst.size_req == 4)
9926 narrow = FALSE;
9927
9928 if (!low_regs || inst.operands[1].imm > 7)
9929 narrow = FALSE;
9930
fdfde340 9931 if (Rn != Rm)
728ca7c9
PB
9932 narrow = FALSE;
9933
9934 switch (inst.operands[1].shift_kind)
9935 {
9936 case SHIFT_LSL:
9937 opcode = narrow ? T_OPCODE_LSL_R : THUMB_OP32 (T_MNEM_lsl);
9938 break;
9939 case SHIFT_ASR:
9940 opcode = narrow ? T_OPCODE_ASR_R : THUMB_OP32 (T_MNEM_asr);
9941 break;
9942 case SHIFT_LSR:
9943 opcode = narrow ? T_OPCODE_LSR_R : THUMB_OP32 (T_MNEM_lsr);
9944 break;
9945 case SHIFT_ROR:
9946 opcode = narrow ? T_OPCODE_ROR_R : THUMB_OP32 (T_MNEM_ror);
9947 break;
9948 default:
5f4273c7 9949 abort ();
728ca7c9
PB
9950 }
9951
9952 inst.instruction = opcode;
9953 if (narrow)
9954 {
fdfde340 9955 inst.instruction |= Rn;
728ca7c9
PB
9956 inst.instruction |= inst.operands[1].imm << 3;
9957 }
9958 else
9959 {
9960 if (flags)
9961 inst.instruction |= CONDS_BIT;
9962
fdfde340
JM
9963 inst.instruction |= Rn << 8;
9964 inst.instruction |= Rm << 16;
728ca7c9
PB
9965 inst.instruction |= inst.operands[1].imm;
9966 }
9967 }
3d388997 9968 else if (!narrow)
c19d1205 9969 {
728ca7c9
PB
9970 /* Some mov with immediate shift have narrow variants.
9971 Register shifts are handled above. */
9972 if (low_regs && inst.operands[1].shifted
9973 && (inst.instruction == T_MNEM_mov
9974 || inst.instruction == T_MNEM_movs))
9975 {
e07e6e58 9976 if (in_it_block ())
728ca7c9
PB
9977 narrow = (inst.instruction == T_MNEM_mov);
9978 else
9979 narrow = (inst.instruction == T_MNEM_movs);
9980 }
9981
9982 if (narrow)
9983 {
9984 switch (inst.operands[1].shift_kind)
9985 {
9986 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
9987 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
9988 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
9989 default: narrow = FALSE; break;
9990 }
9991 }
9992
9993 if (narrow)
9994 {
fdfde340
JM
9995 inst.instruction |= Rn;
9996 inst.instruction |= Rm << 3;
728ca7c9
PB
9997 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9998 }
9999 else
10000 {
10001 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10002 inst.instruction |= Rn << r0off;
728ca7c9
PB
10003 encode_thumb32_shifted_operand (1);
10004 }
c19d1205
ZW
10005 }
10006 else
10007 switch (inst.instruction)
10008 {
10009 case T_MNEM_mov:
10010 inst.instruction = T_OPCODE_MOV_HR;
fdfde340
JM
10011 inst.instruction |= (Rn & 0x8) << 4;
10012 inst.instruction |= (Rn & 0x7);
10013 inst.instruction |= Rm << 3;
c19d1205 10014 break;
b99bd4ef 10015
c19d1205
ZW
10016 case T_MNEM_movs:
10017 /* We know we have low registers at this point.
10018 Generate ADD Rd, Rs, #0. */
10019 inst.instruction = T_OPCODE_ADD_I3;
fdfde340
JM
10020 inst.instruction |= Rn;
10021 inst.instruction |= Rm << 3;
c19d1205
ZW
10022 break;
10023
10024 case T_MNEM_cmp:
3d388997 10025 if (low_regs)
c19d1205
ZW
10026 {
10027 inst.instruction = T_OPCODE_CMP_LR;
fdfde340
JM
10028 inst.instruction |= Rn;
10029 inst.instruction |= Rm << 3;
c19d1205
ZW
10030 }
10031 else
10032 {
10033 inst.instruction = T_OPCODE_CMP_HR;
fdfde340
JM
10034 inst.instruction |= (Rn & 0x8) << 4;
10035 inst.instruction |= (Rn & 0x7);
10036 inst.instruction |= Rm << 3;
c19d1205
ZW
10037 }
10038 break;
10039 }
b99bd4ef
NC
10040 return;
10041 }
10042
c19d1205
ZW
10043 inst.instruction = THUMB_OP16 (inst.instruction);
10044 if (inst.operands[1].isreg)
b99bd4ef 10045 {
fdfde340 10046 if (Rn < 8 && Rm < 8)
b99bd4ef 10047 {
c19d1205
ZW
10048 /* A move of two lowregs is encoded as ADD Rd, Rs, #0
10049 since a MOV instruction produces unpredictable results. */
10050 if (inst.instruction == T_OPCODE_MOV_I8)
10051 inst.instruction = T_OPCODE_ADD_I3;
b99bd4ef 10052 else
c19d1205 10053 inst.instruction = T_OPCODE_CMP_LR;
b99bd4ef 10054
fdfde340
JM
10055 inst.instruction |= Rn;
10056 inst.instruction |= Rm << 3;
b99bd4ef
NC
10057 }
10058 else
10059 {
c19d1205
ZW
10060 if (inst.instruction == T_OPCODE_MOV_I8)
10061 inst.instruction = T_OPCODE_MOV_HR;
10062 else
10063 inst.instruction = T_OPCODE_CMP_HR;
10064 do_t_cpy ();
b99bd4ef
NC
10065 }
10066 }
c19d1205 10067 else
b99bd4ef 10068 {
fdfde340 10069 constraint (Rn > 7,
c19d1205 10070 _("only lo regs allowed with immediate"));
fdfde340 10071 inst.instruction |= Rn << 8;
c19d1205
ZW
10072 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10073 }
10074}
b99bd4ef 10075
c19d1205
ZW
10076static void
10077do_t_mov16 (void)
10078{
fdfde340 10079 unsigned Rd;
b6895b4f
PB
10080 bfd_vma imm;
10081 bfd_boolean top;
10082
10083 top = (inst.instruction & 0x00800000) != 0;
10084 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10085 {
10086 constraint (top, _(":lower16: not allowed this instruction"));
10087 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10088 }
10089 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10090 {
10091 constraint (!top, _(":upper16: not allowed this instruction"));
10092 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10093 }
10094
fdfde340
JM
10095 Rd = inst.operands[0].reg;
10096 reject_bad_reg (Rd);
10097
10098 inst.instruction |= Rd << 8;
b6895b4f
PB
10099 if (inst.reloc.type == BFD_RELOC_UNUSED)
10100 {
10101 imm = inst.reloc.exp.X_add_number;
10102 inst.instruction |= (imm & 0xf000) << 4;
10103 inst.instruction |= (imm & 0x0800) << 15;
10104 inst.instruction |= (imm & 0x0700) << 4;
10105 inst.instruction |= (imm & 0x00ff);
10106 }
c19d1205 10107}
b99bd4ef 10108
c19d1205
ZW
10109static void
10110do_t_mvn_tst (void)
10111{
fdfde340
JM
10112 unsigned Rn, Rm;
10113
10114 Rn = inst.operands[0].reg;
10115 Rm = inst.operands[1].reg;
10116
10117 if (inst.instruction == T_MNEM_cmp
10118 || inst.instruction == T_MNEM_cmn)
10119 constraint (Rn == REG_PC, BAD_PC);
10120 else
10121 reject_bad_reg (Rn);
10122 reject_bad_reg (Rm);
10123
c19d1205
ZW
10124 if (unified_syntax)
10125 {
10126 int r0off = (inst.instruction == T_MNEM_mvn
10127 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
3d388997
PB
10128 bfd_boolean narrow;
10129
10130 if (inst.size_req == 4
10131 || inst.instruction > 0xffff
10132 || inst.operands[1].shifted
fdfde340 10133 || Rn > 7 || Rm > 7)
3d388997
PB
10134 narrow = FALSE;
10135 else if (inst.instruction == T_MNEM_cmn)
10136 narrow = TRUE;
10137 else if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10138 narrow = !in_it_block ();
3d388997 10139 else
e07e6e58 10140 narrow = in_it_block ();
3d388997 10141
c19d1205 10142 if (!inst.operands[1].isreg)
b99bd4ef 10143 {
c19d1205
ZW
10144 /* For an immediate, we always generate a 32-bit opcode;
10145 section relaxation will shrink it later if possible. */
10146 if (inst.instruction < 0xffff)
10147 inst.instruction = THUMB_OP32 (inst.instruction);
10148 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
fdfde340 10149 inst.instruction |= Rn << r0off;
c19d1205 10150 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
b99bd4ef 10151 }
c19d1205 10152 else
b99bd4ef 10153 {
c19d1205 10154 /* See if we can do this with a 16-bit instruction. */
3d388997 10155 if (narrow)
b99bd4ef 10156 {
c19d1205 10157 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10158 inst.instruction |= Rn;
10159 inst.instruction |= Rm << 3;
b99bd4ef 10160 }
c19d1205 10161 else
b99bd4ef 10162 {
c19d1205
ZW
10163 constraint (inst.operands[1].shifted
10164 && inst.operands[1].immisreg,
10165 _("shift must be constant"));
10166 if (inst.instruction < 0xffff)
10167 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340 10168 inst.instruction |= Rn << r0off;
c19d1205 10169 encode_thumb32_shifted_operand (1);
b99bd4ef 10170 }
b99bd4ef
NC
10171 }
10172 }
10173 else
10174 {
c19d1205
ZW
10175 constraint (inst.instruction > 0xffff
10176 || inst.instruction == T_MNEM_mvns, BAD_THUMB32);
10177 constraint (!inst.operands[1].isreg || inst.operands[1].shifted,
10178 _("unshifted register required"));
fdfde340 10179 constraint (Rn > 7 || Rm > 7,
c19d1205 10180 BAD_HIREG);
b99bd4ef 10181
c19d1205 10182 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10183 inst.instruction |= Rn;
10184 inst.instruction |= Rm << 3;
b99bd4ef 10185 }
b99bd4ef
NC
10186}
10187
b05fe5cf 10188static void
c19d1205 10189do_t_mrs (void)
b05fe5cf 10190{
fdfde340 10191 unsigned Rd;
62b3e311 10192 int flags;
037e8744
JB
10193
10194 if (do_vfp_nsyn_mrs () == SUCCESS)
10195 return;
10196
62b3e311
PB
10197 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10198 if (flags == 0)
10199 {
7e806470 10200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10201 _("selected processor does not support "
10202 "requested special purpose register"));
10203 }
10204 else
10205 {
10206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10207 _("selected processor does not support "
44bf2362 10208 "requested special purpose register"));
62b3e311
PB
10209 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10210 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10211 _("'CPSR' or 'SPSR' expected"));
10212 }
5f4273c7 10213
fdfde340
JM
10214 Rd = inst.operands[0].reg;
10215 reject_bad_reg (Rd);
10216
10217 inst.instruction |= Rd << 8;
62b3e311
PB
10218 inst.instruction |= (flags & SPSR_BIT) >> 2;
10219 inst.instruction |= inst.operands[1].imm & 0xff;
c19d1205 10220}
b05fe5cf 10221
c19d1205
ZW
10222static void
10223do_t_msr (void)
10224{
62b3e311 10225 int flags;
fdfde340 10226 unsigned Rn;
62b3e311 10227
037e8744
JB
10228 if (do_vfp_nsyn_msr () == SUCCESS)
10229 return;
10230
c19d1205
ZW
10231 constraint (!inst.operands[1].isreg,
10232 _("Thumb encoding does not support an immediate here"));
62b3e311
PB
10233 flags = inst.operands[0].imm;
10234 if (flags & ~0xff)
10235 {
10236 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10237 _("selected processor does not support "
10238 "requested special purpose register"));
10239 }
10240 else
10241 {
7e806470 10242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
62b3e311
PB
10243 _("selected processor does not support "
10244 "requested special purpose register"));
10245 flags |= PSR_f;
10246 }
fdfde340
JM
10247
10248 Rn = inst.operands[1].reg;
10249 reject_bad_reg (Rn);
10250
62b3e311
PB
10251 inst.instruction |= (flags & SPSR_BIT) >> 2;
10252 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10253 inst.instruction |= (flags & 0xff);
fdfde340 10254 inst.instruction |= Rn << 16;
c19d1205 10255}
b05fe5cf 10256
c19d1205
ZW
10257static void
10258do_t_mul (void)
10259{
17828f45 10260 bfd_boolean narrow;
fdfde340 10261 unsigned Rd, Rn, Rm;
17828f45 10262
c19d1205
ZW
10263 if (!inst.operands[2].present)
10264 inst.operands[2].reg = inst.operands[0].reg;
b05fe5cf 10265
fdfde340
JM
10266 Rd = inst.operands[0].reg;
10267 Rn = inst.operands[1].reg;
10268 Rm = inst.operands[2].reg;
10269
17828f45 10270 if (unified_syntax)
b05fe5cf 10271 {
17828f45 10272 if (inst.size_req == 4
fdfde340
JM
10273 || (Rd != Rn
10274 && Rd != Rm)
10275 || Rn > 7
10276 || Rm > 7)
17828f45
JM
10277 narrow = FALSE;
10278 else if (inst.instruction == T_MNEM_muls)
e07e6e58 10279 narrow = !in_it_block ();
17828f45 10280 else
e07e6e58 10281 narrow = in_it_block ();
b05fe5cf 10282 }
c19d1205 10283 else
b05fe5cf 10284 {
17828f45 10285 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
fdfde340 10286 constraint (Rn > 7 || Rm > 7,
c19d1205 10287 BAD_HIREG);
17828f45
JM
10288 narrow = TRUE;
10289 }
b05fe5cf 10290
17828f45
JM
10291 if (narrow)
10292 {
10293 /* 16-bit MULS/Conditional MUL. */
c19d1205 10294 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340 10295 inst.instruction |= Rd;
b05fe5cf 10296
fdfde340
JM
10297 if (Rd == Rn)
10298 inst.instruction |= Rm << 3;
10299 else if (Rd == Rm)
10300 inst.instruction |= Rn << 3;
c19d1205
ZW
10301 else
10302 constraint (1, _("dest must overlap one source register"));
10303 }
17828f45
JM
10304 else
10305 {
e07e6e58
NC
10306 constraint (inst.instruction != T_MNEM_mul,
10307 _("Thumb-2 MUL must not set flags"));
17828f45
JM
10308 /* 32-bit MUL. */
10309 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10310 inst.instruction |= Rd << 8;
10311 inst.instruction |= Rn << 16;
10312 inst.instruction |= Rm << 0;
10313
10314 reject_bad_reg (Rd);
10315 reject_bad_reg (Rn);
10316 reject_bad_reg (Rm);
17828f45 10317 }
c19d1205 10318}
b05fe5cf 10319
c19d1205
ZW
10320static void
10321do_t_mull (void)
10322{
fdfde340 10323 unsigned RdLo, RdHi, Rn, Rm;
b05fe5cf 10324
fdfde340
JM
10325 RdLo = inst.operands[0].reg;
10326 RdHi = inst.operands[1].reg;
10327 Rn = inst.operands[2].reg;
10328 Rm = inst.operands[3].reg;
10329
10330 reject_bad_reg (RdLo);
10331 reject_bad_reg (RdHi);
10332 reject_bad_reg (Rn);
10333 reject_bad_reg (Rm);
10334
10335 inst.instruction |= RdLo << 12;
10336 inst.instruction |= RdHi << 8;
10337 inst.instruction |= Rn << 16;
10338 inst.instruction |= Rm;
10339
10340 if (RdLo == RdHi)
c19d1205
ZW
10341 as_tsktsk (_("rdhi and rdlo must be different"));
10342}
b05fe5cf 10343
c19d1205
ZW
10344static void
10345do_t_nop (void)
10346{
e07e6e58
NC
10347 set_it_insn_type (NEUTRAL_IT_INSN);
10348
c19d1205
ZW
10349 if (unified_syntax)
10350 {
10351 if (inst.size_req == 4 || inst.operands[0].imm > 15)
b05fe5cf 10352 {
c19d1205
ZW
10353 inst.instruction = THUMB_OP32 (inst.instruction);
10354 inst.instruction |= inst.operands[0].imm;
10355 }
10356 else
10357 {
bc2d1808
NC
10358 /* PR9722: Check for Thumb2 availability before
10359 generating a thumb2 nop instruction. */
10360 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10361 {
10362 inst.instruction = THUMB_OP16 (inst.instruction);
10363 inst.instruction |= inst.operands[0].imm << 4;
10364 }
10365 else
10366 inst.instruction = 0x46c0;
c19d1205
ZW
10367 }
10368 }
10369 else
10370 {
10371 constraint (inst.operands[0].present,
10372 _("Thumb does not support NOP with hints"));
10373 inst.instruction = 0x46c0;
10374 }
10375}
b05fe5cf 10376
c19d1205
ZW
10377static void
10378do_t_neg (void)
10379{
10380 if (unified_syntax)
10381 {
3d388997
PB
10382 bfd_boolean narrow;
10383
10384 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10385 narrow = !in_it_block ();
3d388997 10386 else
e07e6e58 10387 narrow = in_it_block ();
3d388997
PB
10388 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10389 narrow = FALSE;
10390 if (inst.size_req == 4)
10391 narrow = FALSE;
10392
10393 if (!narrow)
c19d1205
ZW
10394 {
10395 inst.instruction = THUMB_OP32 (inst.instruction);
10396 inst.instruction |= inst.operands[0].reg << 8;
10397 inst.instruction |= inst.operands[1].reg << 16;
b05fe5cf
ZW
10398 }
10399 else
10400 {
c19d1205
ZW
10401 inst.instruction = THUMB_OP16 (inst.instruction);
10402 inst.instruction |= inst.operands[0].reg;
10403 inst.instruction |= inst.operands[1].reg << 3;
b05fe5cf
ZW
10404 }
10405 }
10406 else
10407 {
c19d1205
ZW
10408 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10409 BAD_HIREG);
10410 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10411
10412 inst.instruction = THUMB_OP16 (inst.instruction);
10413 inst.instruction |= inst.operands[0].reg;
10414 inst.instruction |= inst.operands[1].reg << 3;
10415 }
10416}
10417
1c444d06
JM
10418static void
10419do_t_orn (void)
10420{
10421 unsigned Rd, Rn;
10422
10423 Rd = inst.operands[0].reg;
10424 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10425
fdfde340
JM
10426 reject_bad_reg (Rd);
10427 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10428 reject_bad_reg (Rn);
10429
1c444d06
JM
10430 inst.instruction |= Rd << 8;
10431 inst.instruction |= Rn << 16;
10432
10433 if (!inst.operands[2].isreg)
10434 {
10435 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10436 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10437 }
10438 else
10439 {
10440 unsigned Rm;
10441
10442 Rm = inst.operands[2].reg;
fdfde340 10443 reject_bad_reg (Rm);
1c444d06
JM
10444
10445 constraint (inst.operands[2].shifted
10446 && inst.operands[2].immisreg,
10447 _("shift must be constant"));
10448 encode_thumb32_shifted_operand (2);
10449 }
10450}
10451
c19d1205
ZW
10452static void
10453do_t_pkhbt (void)
10454{
fdfde340
JM
10455 unsigned Rd, Rn, Rm;
10456
10457 Rd = inst.operands[0].reg;
10458 Rn = inst.operands[1].reg;
10459 Rm = inst.operands[2].reg;
10460
10461 reject_bad_reg (Rd);
10462 reject_bad_reg (Rn);
10463 reject_bad_reg (Rm);
10464
10465 inst.instruction |= Rd << 8;
10466 inst.instruction |= Rn << 16;
10467 inst.instruction |= Rm;
c19d1205
ZW
10468 if (inst.operands[3].present)
10469 {
10470 unsigned int val = inst.reloc.exp.X_add_number;
10471 constraint (inst.reloc.exp.X_op != O_constant,
10472 _("expression too complex"));
10473 inst.instruction |= (val & 0x1c) << 10;
10474 inst.instruction |= (val & 0x03) << 6;
b05fe5cf 10475 }
c19d1205 10476}
b05fe5cf 10477
c19d1205
ZW
10478static void
10479do_t_pkhtb (void)
10480{
10481 if (!inst.operands[3].present)
1ef52f49
NC
10482 {
10483 unsigned Rtmp;
10484
10485 inst.instruction &= ~0x00000020;
10486
10487 /* PR 10168. Swap the Rm and Rn registers. */
10488 Rtmp = inst.operands[1].reg;
10489 inst.operands[1].reg = inst.operands[2].reg;
10490 inst.operands[2].reg = Rtmp;
10491 }
c19d1205 10492 do_t_pkhbt ();
b05fe5cf
ZW
10493}
10494
c19d1205
ZW
10495static void
10496do_t_pld (void)
10497{
fdfde340
JM
10498 if (inst.operands[0].immisreg)
10499 reject_bad_reg (inst.operands[0].imm);
10500
c19d1205
ZW
10501 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10502}
b05fe5cf 10503
c19d1205
ZW
10504static void
10505do_t_push_pop (void)
b99bd4ef 10506{
e9f89963 10507 unsigned mask;
5f4273c7 10508
c19d1205
ZW
10509 constraint (inst.operands[0].writeback,
10510 _("push/pop do not support {reglist}^"));
10511 constraint (inst.reloc.type != BFD_RELOC_UNUSED,
10512 _("expression too complex"));
b99bd4ef 10513
e9f89963
PB
10514 mask = inst.operands[0].imm;
10515 if ((mask & ~0xff) == 0)
3c707909 10516 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
c19d1205 10517 else if ((inst.instruction == T_MNEM_push
e9f89963 10518 && (mask & ~0xff) == 1 << REG_LR)
c19d1205 10519 || (inst.instruction == T_MNEM_pop
e9f89963 10520 && (mask & ~0xff) == 1 << REG_PC))
b99bd4ef 10521 {
c19d1205
ZW
10522 inst.instruction = THUMB_OP16 (inst.instruction);
10523 inst.instruction |= THUMB_PP_PC_LR;
3c707909 10524 inst.instruction |= mask & 0xff;
c19d1205
ZW
10525 }
10526 else if (unified_syntax)
10527 {
3c707909 10528 inst.instruction = THUMB_OP32 (inst.instruction);
5f4273c7 10529 encode_thumb2_ldmstm (13, mask, TRUE);
c19d1205
ZW
10530 }
10531 else
10532 {
10533 inst.error = _("invalid register list to push/pop instruction");
10534 return;
10535 }
c19d1205 10536}
b99bd4ef 10537
c19d1205
ZW
10538static void
10539do_t_rbit (void)
10540{
fdfde340
JM
10541 unsigned Rd, Rm;
10542
10543 Rd = inst.operands[0].reg;
10544 Rm = inst.operands[1].reg;
10545
10546 reject_bad_reg (Rd);
10547 reject_bad_reg (Rm);
10548
10549 inst.instruction |= Rd << 8;
10550 inst.instruction |= Rm << 16;
10551 inst.instruction |= Rm;
c19d1205 10552}
b99bd4ef 10553
c19d1205
ZW
10554static void
10555do_t_rev (void)
10556{
fdfde340
JM
10557 unsigned Rd, Rm;
10558
10559 Rd = inst.operands[0].reg;
10560 Rm = inst.operands[1].reg;
10561
10562 reject_bad_reg (Rd);
10563 reject_bad_reg (Rm);
10564
10565 if (Rd <= 7 && Rm <= 7
c19d1205
ZW
10566 && inst.size_req != 4)
10567 {
10568 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10569 inst.instruction |= Rd;
10570 inst.instruction |= Rm << 3;
c19d1205
ZW
10571 }
10572 else if (unified_syntax)
10573 {
10574 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10575 inst.instruction |= Rd << 8;
10576 inst.instruction |= Rm << 16;
10577 inst.instruction |= Rm;
c19d1205
ZW
10578 }
10579 else
10580 inst.error = BAD_HIREG;
10581}
b99bd4ef 10582
1c444d06
JM
10583static void
10584do_t_rrx (void)
10585{
10586 unsigned Rd, Rm;
10587
10588 Rd = inst.operands[0].reg;
10589 Rm = inst.operands[1].reg;
10590
fdfde340
JM
10591 reject_bad_reg (Rd);
10592 reject_bad_reg (Rm);
10593
1c444d06
JM
10594 inst.instruction |= Rd << 8;
10595 inst.instruction |= Rm;
10596}
10597
c19d1205
ZW
10598static void
10599do_t_rsb (void)
10600{
fdfde340 10601 unsigned Rd, Rs;
b99bd4ef 10602
c19d1205
ZW
10603 Rd = inst.operands[0].reg;
10604 Rs = (inst.operands[1].present
10605 ? inst.operands[1].reg /* Rd, Rs, foo */
10606 : inst.operands[0].reg); /* Rd, foo -> Rd, Rd, foo */
b99bd4ef 10607
fdfde340
JM
10608 reject_bad_reg (Rd);
10609 reject_bad_reg (Rs);
10610 if (inst.operands[2].isreg)
10611 reject_bad_reg (inst.operands[2].reg);
10612
c19d1205
ZW
10613 inst.instruction |= Rd << 8;
10614 inst.instruction |= Rs << 16;
10615 if (!inst.operands[2].isreg)
10616 {
026d3abb
PB
10617 bfd_boolean narrow;
10618
10619 if ((inst.instruction & 0x00100000) != 0)
e07e6e58 10620 narrow = !in_it_block ();
026d3abb 10621 else
e07e6e58 10622 narrow = in_it_block ();
026d3abb
PB
10623
10624 if (Rd > 7 || Rs > 7)
10625 narrow = FALSE;
10626
10627 if (inst.size_req == 4 || !unified_syntax)
10628 narrow = FALSE;
10629
10630 if (inst.reloc.exp.X_op != O_constant
10631 || inst.reloc.exp.X_add_number != 0)
10632 narrow = FALSE;
10633
10634 /* Turn rsb #0 into 16-bit neg. We should probably do this via
10635 relaxation, but it doesn't seem worth the hassle. */
10636 if (narrow)
10637 {
10638 inst.reloc.type = BFD_RELOC_UNUSED;
10639 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10640 inst.instruction |= Rs << 3;
10641 inst.instruction |= Rd;
10642 }
10643 else
10644 {
10645 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10646 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10647 }
c19d1205
ZW
10648 }
10649 else
10650 encode_thumb32_shifted_operand (2);
10651}
b99bd4ef 10652
c19d1205
ZW
10653static void
10654do_t_setend (void)
10655{
e07e6e58 10656 set_it_insn_type (OUTSIDE_IT_INSN);
c19d1205
ZW
10657 if (inst.operands[0].imm)
10658 inst.instruction |= 0x8;
10659}
b99bd4ef 10660
c19d1205
ZW
10661static void
10662do_t_shift (void)
10663{
10664 if (!inst.operands[1].present)
10665 inst.operands[1].reg = inst.operands[0].reg;
10666
10667 if (unified_syntax)
10668 {
3d388997
PB
10669 bfd_boolean narrow;
10670 int shift_kind;
10671
10672 switch (inst.instruction)
10673 {
10674 case T_MNEM_asr:
10675 case T_MNEM_asrs: shift_kind = SHIFT_ASR; break;
10676 case T_MNEM_lsl:
10677 case T_MNEM_lsls: shift_kind = SHIFT_LSL; break;
10678 case T_MNEM_lsr:
10679 case T_MNEM_lsrs: shift_kind = SHIFT_LSR; break;
10680 case T_MNEM_ror:
10681 case T_MNEM_rors: shift_kind = SHIFT_ROR; break;
10682 default: abort ();
10683 }
10684
10685 if (THUMB_SETS_FLAGS (inst.instruction))
e07e6e58 10686 narrow = !in_it_block ();
3d388997 10687 else
e07e6e58 10688 narrow = in_it_block ();
3d388997
PB
10689 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10690 narrow = FALSE;
10691 if (!inst.operands[2].isreg && shift_kind == SHIFT_ROR)
10692 narrow = FALSE;
10693 if (inst.operands[2].isreg
10694 && (inst.operands[1].reg != inst.operands[0].reg
10695 || inst.operands[2].reg > 7))
10696 narrow = FALSE;
10697 if (inst.size_req == 4)
10698 narrow = FALSE;
10699
fdfde340
JM
10700 reject_bad_reg (inst.operands[0].reg);
10701 reject_bad_reg (inst.operands[1].reg);
10702
3d388997 10703 if (!narrow)
c19d1205
ZW
10704 {
10705 if (inst.operands[2].isreg)
b99bd4ef 10706 {
fdfde340 10707 reject_bad_reg (inst.operands[2].reg);
c19d1205
ZW
10708 inst.instruction = THUMB_OP32 (inst.instruction);
10709 inst.instruction |= inst.operands[0].reg << 8;
10710 inst.instruction |= inst.operands[1].reg << 16;
10711 inst.instruction |= inst.operands[2].reg;
10712 }
10713 else
10714 {
10715 inst.operands[1].shifted = 1;
3d388997 10716 inst.operands[1].shift_kind = shift_kind;
c19d1205
ZW
10717 inst.instruction = THUMB_OP32 (THUMB_SETS_FLAGS (inst.instruction)
10718 ? T_MNEM_movs : T_MNEM_mov);
10719 inst.instruction |= inst.operands[0].reg << 8;
10720 encode_thumb32_shifted_operand (1);
10721 /* Prevent the incorrect generation of an ARM_IMMEDIATE fixup. */
10722 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef
NC
10723 }
10724 }
10725 else
10726 {
c19d1205 10727 if (inst.operands[2].isreg)
b99bd4ef 10728 {
3d388997 10729 switch (shift_kind)
b99bd4ef 10730 {
3d388997
PB
10731 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_R; break;
10732 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_R; break;
10733 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_R; break;
10734 case SHIFT_ROR: inst.instruction = T_OPCODE_ROR_R; break;
c19d1205 10735 default: abort ();
b99bd4ef 10736 }
5f4273c7 10737
c19d1205
ZW
10738 inst.instruction |= inst.operands[0].reg;
10739 inst.instruction |= inst.operands[2].reg << 3;
b99bd4ef
NC
10740 }
10741 else
10742 {
3d388997 10743 switch (shift_kind)
b99bd4ef 10744 {
3d388997
PB
10745 case SHIFT_ASR: inst.instruction = T_OPCODE_ASR_I; break;
10746 case SHIFT_LSL: inst.instruction = T_OPCODE_LSL_I; break;
10747 case SHIFT_LSR: inst.instruction = T_OPCODE_LSR_I; break;
c19d1205 10748 default: abort ();
b99bd4ef 10749 }
c19d1205
ZW
10750 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10751 inst.instruction |= inst.operands[0].reg;
10752 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10753 }
10754 }
c19d1205
ZW
10755 }
10756 else
10757 {
10758 constraint (inst.operands[0].reg > 7
10759 || inst.operands[1].reg > 7, BAD_HIREG);
10760 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
b99bd4ef 10761
c19d1205
ZW
10762 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
10763 {
10764 constraint (inst.operands[2].reg > 7, BAD_HIREG);
10765 constraint (inst.operands[0].reg != inst.operands[1].reg,
10766 _("source1 and dest must be same register"));
b99bd4ef 10767
c19d1205
ZW
10768 switch (inst.instruction)
10769 {
10770 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_R; break;
10771 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_R; break;
10772 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_R; break;
10773 case T_MNEM_ror: inst.instruction = T_OPCODE_ROR_R; break;
10774 default: abort ();
10775 }
5f4273c7 10776
c19d1205
ZW
10777 inst.instruction |= inst.operands[0].reg;
10778 inst.instruction |= inst.operands[2].reg << 3;
10779 }
10780 else
b99bd4ef 10781 {
c19d1205
ZW
10782 switch (inst.instruction)
10783 {
10784 case T_MNEM_asr: inst.instruction = T_OPCODE_ASR_I; break;
10785 case T_MNEM_lsl: inst.instruction = T_OPCODE_LSL_I; break;
10786 case T_MNEM_lsr: inst.instruction = T_OPCODE_LSR_I; break;
10787 case T_MNEM_ror: inst.error = _("ror #imm not supported"); return;
10788 default: abort ();
10789 }
10790 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10791 inst.instruction |= inst.operands[0].reg;
10792 inst.instruction |= inst.operands[1].reg << 3;
b99bd4ef
NC
10793 }
10794 }
b99bd4ef
NC
10795}
10796
10797static void
c19d1205 10798do_t_simd (void)
b99bd4ef 10799{
fdfde340
JM
10800 unsigned Rd, Rn, Rm;
10801
10802 Rd = inst.operands[0].reg;
10803 Rn = inst.operands[1].reg;
10804 Rm = inst.operands[2].reg;
10805
10806 reject_bad_reg (Rd);
10807 reject_bad_reg (Rn);
10808 reject_bad_reg (Rm);
10809
10810 inst.instruction |= Rd << 8;
10811 inst.instruction |= Rn << 16;
10812 inst.instruction |= Rm;
c19d1205 10813}
b99bd4ef 10814
c19d1205 10815static void
3eb17e6b 10816do_t_smc (void)
c19d1205
ZW
10817{
10818 unsigned int value = inst.reloc.exp.X_add_number;
10819 constraint (inst.reloc.exp.X_op != O_constant,
10820 _("expression too complex"));
10821 inst.reloc.type = BFD_RELOC_UNUSED;
10822 inst.instruction |= (value & 0xf000) >> 12;
10823 inst.instruction |= (value & 0x0ff0);
10824 inst.instruction |= (value & 0x000f) << 16;
10825}
b99bd4ef 10826
c19d1205 10827static void
3a21c15a 10828do_t_ssat_usat (int bias)
c19d1205 10829{
fdfde340
JM
10830 unsigned Rd, Rn;
10831
10832 Rd = inst.operands[0].reg;
10833 Rn = inst.operands[2].reg;
10834
10835 reject_bad_reg (Rd);
10836 reject_bad_reg (Rn);
10837
10838 inst.instruction |= Rd << 8;
3a21c15a 10839 inst.instruction |= inst.operands[1].imm - bias;
fdfde340 10840 inst.instruction |= Rn << 16;
b99bd4ef 10841
c19d1205 10842 if (inst.operands[3].present)
b99bd4ef 10843 {
3a21c15a
NC
10844 offsetT shift_amount = inst.reloc.exp.X_add_number;
10845
10846 inst.reloc.type = BFD_RELOC_UNUSED;
10847
c19d1205
ZW
10848 constraint (inst.reloc.exp.X_op != O_constant,
10849 _("expression too complex"));
b99bd4ef 10850
3a21c15a 10851 if (shift_amount != 0)
6189168b 10852 {
3a21c15a
NC
10853 constraint (shift_amount > 31,
10854 _("shift expression is too large"));
10855
c19d1205 10856 if (inst.operands[3].shift_kind == SHIFT_ASR)
3a21c15a
NC
10857 inst.instruction |= 0x00200000; /* sh bit. */
10858
10859 inst.instruction |= (shift_amount & 0x1c) << 10;
10860 inst.instruction |= (shift_amount & 0x03) << 6;
6189168b
NC
10861 }
10862 }
b99bd4ef 10863}
3a21c15a
NC
10864
10865static void
10866do_t_ssat (void)
10867{
10868 do_t_ssat_usat (1);
10869}
b99bd4ef 10870
0dd132b6 10871static void
c19d1205 10872do_t_ssat16 (void)
0dd132b6 10873{
fdfde340
JM
10874 unsigned Rd, Rn;
10875
10876 Rd = inst.operands[0].reg;
10877 Rn = inst.operands[2].reg;
10878
10879 reject_bad_reg (Rd);
10880 reject_bad_reg (Rn);
10881
10882 inst.instruction |= Rd << 8;
c19d1205 10883 inst.instruction |= inst.operands[1].imm - 1;
fdfde340 10884 inst.instruction |= Rn << 16;
c19d1205 10885}
0dd132b6 10886
c19d1205
ZW
10887static void
10888do_t_strex (void)
10889{
10890 constraint (!inst.operands[2].isreg || !inst.operands[2].preind
10891 || inst.operands[2].postind || inst.operands[2].writeback
10892 || inst.operands[2].immisreg || inst.operands[2].shifted
10893 || inst.operands[2].negative,
01cfc07f 10894 BAD_ADDR_MODE);
0dd132b6 10895
c19d1205
ZW
10896 inst.instruction |= inst.operands[0].reg << 8;
10897 inst.instruction |= inst.operands[1].reg << 12;
10898 inst.instruction |= inst.operands[2].reg << 16;
10899 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_U8;
0dd132b6
NC
10900}
10901
b99bd4ef 10902static void
c19d1205 10903do_t_strexd (void)
b99bd4ef 10904{
c19d1205
ZW
10905 if (!inst.operands[2].present)
10906 inst.operands[2].reg = inst.operands[1].reg + 1;
b99bd4ef 10907
c19d1205
ZW
10908 constraint (inst.operands[0].reg == inst.operands[1].reg
10909 || inst.operands[0].reg == inst.operands[2].reg
10910 || inst.operands[0].reg == inst.operands[3].reg
10911 || inst.operands[1].reg == inst.operands[2].reg,
10912 BAD_OVERLAP);
b99bd4ef 10913
c19d1205
ZW
10914 inst.instruction |= inst.operands[0].reg;
10915 inst.instruction |= inst.operands[1].reg << 12;
10916 inst.instruction |= inst.operands[2].reg << 8;
10917 inst.instruction |= inst.operands[3].reg << 16;
b99bd4ef
NC
10918}
10919
10920static void
c19d1205 10921do_t_sxtah (void)
b99bd4ef 10922{
fdfde340
JM
10923 unsigned Rd, Rn, Rm;
10924
10925 Rd = inst.operands[0].reg;
10926 Rn = inst.operands[1].reg;
10927 Rm = inst.operands[2].reg;
10928
10929 reject_bad_reg (Rd);
10930 reject_bad_reg (Rn);
10931 reject_bad_reg (Rm);
10932
10933 inst.instruction |= Rd << 8;
10934 inst.instruction |= Rn << 16;
10935 inst.instruction |= Rm;
c19d1205
ZW
10936 inst.instruction |= inst.operands[3].imm << 4;
10937}
b99bd4ef 10938
c19d1205
ZW
10939static void
10940do_t_sxth (void)
10941{
fdfde340
JM
10942 unsigned Rd, Rm;
10943
10944 Rd = inst.operands[0].reg;
10945 Rm = inst.operands[1].reg;
10946
10947 reject_bad_reg (Rd);
10948 reject_bad_reg (Rm);
10949
c19d1205 10950 if (inst.instruction <= 0xffff && inst.size_req != 4
fdfde340 10951 && Rd <= 7 && Rm <= 7
c19d1205 10952 && (!inst.operands[2].present || inst.operands[2].imm == 0))
b99bd4ef 10953 {
c19d1205 10954 inst.instruction = THUMB_OP16 (inst.instruction);
fdfde340
JM
10955 inst.instruction |= Rd;
10956 inst.instruction |= Rm << 3;
b99bd4ef 10957 }
c19d1205 10958 else if (unified_syntax)
b99bd4ef 10959 {
c19d1205
ZW
10960 if (inst.instruction <= 0xffff)
10961 inst.instruction = THUMB_OP32 (inst.instruction);
fdfde340
JM
10962 inst.instruction |= Rd << 8;
10963 inst.instruction |= Rm;
c19d1205 10964 inst.instruction |= inst.operands[2].imm << 4;
b99bd4ef 10965 }
c19d1205 10966 else
b99bd4ef 10967 {
c19d1205
ZW
10968 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10969 _("Thumb encoding does not support rotation"));
10970 constraint (1, BAD_HIREG);
b99bd4ef 10971 }
c19d1205 10972}
b99bd4ef 10973
c19d1205
ZW
10974static void
10975do_t_swi (void)
10976{
10977 inst.reloc.type = BFD_RELOC_ARM_SWI;
10978}
b99bd4ef 10979
92e90b6e
PB
10980static void
10981do_t_tb (void)
10982{
fdfde340 10983 unsigned Rn, Rm;
92e90b6e
PB
10984 int half;
10985
10986 half = (inst.instruction & 0x10) != 0;
e07e6e58 10987 set_it_insn_type_last ();
dfa9f0d5
PB
10988 constraint (inst.operands[0].immisreg,
10989 _("instruction requires register index"));
fdfde340
JM
10990
10991 Rn = inst.operands[0].reg;
10992 Rm = inst.operands[0].imm;
10993
10994 constraint (Rn == REG_SP, BAD_SP);
10995 reject_bad_reg (Rm);
10996
92e90b6e
PB
10997 constraint (!half && inst.operands[0].shifted,
10998 _("instruction does not allow shifted index"));
fdfde340 10999 inst.instruction |= (Rn << 16) | Rm;
92e90b6e
PB
11000}
11001
c19d1205
ZW
11002static void
11003do_t_usat (void)
11004{
3a21c15a 11005 do_t_ssat_usat (0);
b99bd4ef
NC
11006}
11007
11008static void
c19d1205 11009do_t_usat16 (void)
b99bd4ef 11010{
fdfde340
JM
11011 unsigned Rd, Rn;
11012
11013 Rd = inst.operands[0].reg;
11014 Rn = inst.operands[2].reg;
11015
11016 reject_bad_reg (Rd);
11017 reject_bad_reg (Rn);
11018
11019 inst.instruction |= Rd << 8;
c19d1205 11020 inst.instruction |= inst.operands[1].imm;
fdfde340 11021 inst.instruction |= Rn << 16;
b99bd4ef 11022}
c19d1205 11023
5287ad62 11024/* Neon instruction encoder helpers. */
5f4273c7 11025
5287ad62 11026/* Encodings for the different types for various Neon opcodes. */
b99bd4ef 11027
5287ad62
JB
11028/* An "invalid" code for the following tables. */
11029#define N_INV -1u
11030
11031struct neon_tab_entry
b99bd4ef 11032{
5287ad62
JB
11033 unsigned integer;
11034 unsigned float_or_poly;
11035 unsigned scalar_or_imm;
11036};
5f4273c7 11037
5287ad62
JB
11038/* Map overloaded Neon opcodes to their respective encodings. */
11039#define NEON_ENC_TAB \
11040 X(vabd, 0x0000700, 0x1200d00, N_INV), \
11041 X(vmax, 0x0000600, 0x0000f00, N_INV), \
11042 X(vmin, 0x0000610, 0x0200f00, N_INV), \
11043 X(vpadd, 0x0000b10, 0x1000d00, N_INV), \
11044 X(vpmax, 0x0000a00, 0x1000f00, N_INV), \
11045 X(vpmin, 0x0000a10, 0x1200f00, N_INV), \
11046 X(vadd, 0x0000800, 0x0000d00, N_INV), \
11047 X(vsub, 0x1000800, 0x0200d00, N_INV), \
11048 X(vceq, 0x1000810, 0x0000e00, 0x1b10100), \
11049 X(vcge, 0x0000310, 0x1000e00, 0x1b10080), \
11050 X(vcgt, 0x0000300, 0x1200e00, 0x1b10000), \
11051 /* Register variants of the following two instructions are encoded as
e07e6e58 11052 vcge / vcgt with the operands reversed. */ \
92559b5b
PB
11053 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11054 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
5287ad62
JB
11055 X(vmla, 0x0000900, 0x0000d10, 0x0800040), \
11056 X(vmls, 0x1000900, 0x0200d10, 0x0800440), \
11057 X(vmul, 0x0000910, 0x1000d10, 0x0800840), \
11058 X(vmull, 0x0800c00, 0x0800e00, 0x0800a40), /* polynomial not float. */ \
11059 X(vmlal, 0x0800800, N_INV, 0x0800240), \
11060 X(vmlsl, 0x0800a00, N_INV, 0x0800640), \
11061 X(vqdmlal, 0x0800900, N_INV, 0x0800340), \
11062 X(vqdmlsl, 0x0800b00, N_INV, 0x0800740), \
11063 X(vqdmull, 0x0800d00, N_INV, 0x0800b40), \
11064 X(vqdmulh, 0x0000b00, N_INV, 0x0800c40), \
11065 X(vqrdmulh, 0x1000b00, N_INV, 0x0800d40), \
11066 X(vshl, 0x0000400, N_INV, 0x0800510), \
11067 X(vqshl, 0x0000410, N_INV, 0x0800710), \
11068 X(vand, 0x0000110, N_INV, 0x0800030), \
11069 X(vbic, 0x0100110, N_INV, 0x0800030), \
11070 X(veor, 0x1000110, N_INV, N_INV), \
11071 X(vorn, 0x0300110, N_INV, 0x0800010), \
11072 X(vorr, 0x0200110, N_INV, 0x0800010), \
11073 X(vmvn, 0x1b00580, N_INV, 0x0800030), \
11074 X(vshll, 0x1b20300, N_INV, 0x0800a10), /* max shift, immediate. */ \
11075 X(vcvt, 0x1b30600, N_INV, 0x0800e10), /* integer, fixed-point. */ \
11076 X(vdup, 0xe800b10, N_INV, 0x1b00c00), /* arm, scalar. */ \
11077 X(vld1, 0x0200000, 0x0a00000, 0x0a00c00), /* interlv, lane, dup. */ \
11078 X(vst1, 0x0000000, 0x0800000, N_INV), \
11079 X(vld2, 0x0200100, 0x0a00100, 0x0a00d00), \
11080 X(vst2, 0x0000100, 0x0800100, N_INV), \
11081 X(vld3, 0x0200200, 0x0a00200, 0x0a00e00), \
11082 X(vst3, 0x0000200, 0x0800200, N_INV), \
11083 X(vld4, 0x0200300, 0x0a00300, 0x0a00f00), \
11084 X(vst4, 0x0000300, 0x0800300, N_INV), \
11085 X(vmovn, 0x1b20200, N_INV, N_INV), \
11086 X(vtrn, 0x1b20080, N_INV, N_INV), \
11087 X(vqmovn, 0x1b20200, N_INV, N_INV), \
037e8744
JB
11088 X(vqmovun, 0x1b20240, N_INV, N_INV), \
11089 X(vnmul, 0xe200a40, 0xe200b40, N_INV), \
11090 X(vnmla, 0xe000a40, 0xe000b40, N_INV), \
11091 X(vnmls, 0xe100a40, 0xe100b40, N_INV), \
11092 X(vcmp, 0xeb40a40, 0xeb40b40, N_INV), \
11093 X(vcmpz, 0xeb50a40, 0xeb50b40, N_INV), \
11094 X(vcmpe, 0xeb40ac0, 0xeb40bc0, N_INV), \
11095 X(vcmpez, 0xeb50ac0, 0xeb50bc0, N_INV)
5287ad62
JB
11096
11097enum neon_opc
11098{
11099#define X(OPC,I,F,S) N_MNEM_##OPC
11100NEON_ENC_TAB
11101#undef X
11102};
b99bd4ef 11103
5287ad62
JB
11104static const struct neon_tab_entry neon_enc_tab[] =
11105{
11106#define X(OPC,I,F,S) { (I), (F), (S) }
11107NEON_ENC_TAB
11108#undef X
11109};
b99bd4ef 11110
5287ad62
JB
11111#define NEON_ENC_INTEGER(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11112#define NEON_ENC_ARMREG(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11113#define NEON_ENC_POLY(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11114#define NEON_ENC_FLOAT(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11115#define NEON_ENC_SCALAR(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11116#define NEON_ENC_IMMED(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
11117#define NEON_ENC_INTERLV(X) (neon_enc_tab[(X) & 0x0fffffff].integer)
11118#define NEON_ENC_LANE(X) (neon_enc_tab[(X) & 0x0fffffff].float_or_poly)
11119#define NEON_ENC_DUP(X) (neon_enc_tab[(X) & 0x0fffffff].scalar_or_imm)
037e8744
JB
11120#define NEON_ENC_SINGLE(X) \
11121 ((neon_enc_tab[(X) & 0x0fffffff].integer) | ((X) & 0xf0000000))
11122#define NEON_ENC_DOUBLE(X) \
11123 ((neon_enc_tab[(X) & 0x0fffffff].float_or_poly) | ((X) & 0xf0000000))
5287ad62 11124
037e8744
JB
11125/* Define shapes for instruction operands. The following mnemonic characters
11126 are used in this table:
5287ad62 11127
037e8744 11128 F - VFP S<n> register
5287ad62
JB
11129 D - Neon D<n> register
11130 Q - Neon Q<n> register
11131 I - Immediate
11132 S - Scalar
11133 R - ARM register
11134 L - D<n> register list
5f4273c7 11135
037e8744
JB
11136 This table is used to generate various data:
11137 - enumerations of the form NS_DDR to be used as arguments to
11138 neon_select_shape.
11139 - a table classifying shapes into single, double, quad, mixed.
5f4273c7 11140 - a table used to drive neon_select_shape. */
b99bd4ef 11141
037e8744
JB
11142#define NEON_SHAPE_DEF \
11143 X(3, (D, D, D), DOUBLE), \
11144 X(3, (Q, Q, Q), QUAD), \
11145 X(3, (D, D, I), DOUBLE), \
11146 X(3, (Q, Q, I), QUAD), \
11147 X(3, (D, D, S), DOUBLE), \
11148 X(3, (Q, Q, S), QUAD), \
11149 X(2, (D, D), DOUBLE), \
11150 X(2, (Q, Q), QUAD), \
11151 X(2, (D, S), DOUBLE), \
11152 X(2, (Q, S), QUAD), \
11153 X(2, (D, R), DOUBLE), \
11154 X(2, (Q, R), QUAD), \
11155 X(2, (D, I), DOUBLE), \
11156 X(2, (Q, I), QUAD), \
11157 X(3, (D, L, D), DOUBLE), \
11158 X(2, (D, Q), MIXED), \
11159 X(2, (Q, D), MIXED), \
11160 X(3, (D, Q, I), MIXED), \
11161 X(3, (Q, D, I), MIXED), \
11162 X(3, (Q, D, D), MIXED), \
11163 X(3, (D, Q, Q), MIXED), \
11164 X(3, (Q, Q, D), MIXED), \
11165 X(3, (Q, D, S), MIXED), \
11166 X(3, (D, Q, S), MIXED), \
11167 X(4, (D, D, D, I), DOUBLE), \
11168 X(4, (Q, Q, Q, I), QUAD), \
11169 X(2, (F, F), SINGLE), \
11170 X(3, (F, F, F), SINGLE), \
11171 X(2, (F, I), SINGLE), \
11172 X(2, (F, D), MIXED), \
11173 X(2, (D, F), MIXED), \
11174 X(3, (F, F, I), MIXED), \
11175 X(4, (R, R, F, F), SINGLE), \
11176 X(4, (F, F, R, R), SINGLE), \
11177 X(3, (D, R, R), DOUBLE), \
11178 X(3, (R, R, D), DOUBLE), \
11179 X(2, (S, R), SINGLE), \
11180 X(2, (R, S), SINGLE), \
11181 X(2, (F, R), SINGLE), \
11182 X(2, (R, F), SINGLE)
11183
11184#define S2(A,B) NS_##A##B
11185#define S3(A,B,C) NS_##A##B##C
11186#define S4(A,B,C,D) NS_##A##B##C##D
11187
11188#define X(N, L, C) S##N L
11189
5287ad62
JB
11190enum neon_shape
11191{
037e8744
JB
11192 NEON_SHAPE_DEF,
11193 NS_NULL
5287ad62 11194};
b99bd4ef 11195
037e8744
JB
11196#undef X
11197#undef S2
11198#undef S3
11199#undef S4
11200
11201enum neon_shape_class
11202{
11203 SC_SINGLE,
11204 SC_DOUBLE,
11205 SC_QUAD,
11206 SC_MIXED
11207};
11208
11209#define X(N, L, C) SC_##C
11210
11211static enum neon_shape_class neon_shape_class[] =
11212{
11213 NEON_SHAPE_DEF
11214};
11215
11216#undef X
11217
11218enum neon_shape_el
11219{
11220 SE_F,
11221 SE_D,
11222 SE_Q,
11223 SE_I,
11224 SE_S,
11225 SE_R,
11226 SE_L
11227};
11228
11229/* Register widths of above. */
11230static unsigned neon_shape_el_size[] =
11231{
11232 32,
11233 64,
11234 128,
11235 0,
11236 32,
11237 32,
11238 0
11239};
11240
11241struct neon_shape_info
11242{
11243 unsigned els;
11244 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
11245};
11246
11247#define S2(A,B) { SE_##A, SE_##B }
11248#define S3(A,B,C) { SE_##A, SE_##B, SE_##C }
11249#define S4(A,B,C,D) { SE_##A, SE_##B, SE_##C, SE_##D }
11250
11251#define X(N, L, C) { N, S##N L }
11252
11253static struct neon_shape_info neon_shape_tab[] =
11254{
11255 NEON_SHAPE_DEF
11256};
11257
11258#undef X
11259#undef S2
11260#undef S3
11261#undef S4
11262
5287ad62
JB
11263/* Bit masks used in type checking given instructions.
11264 'N_EQK' means the type must be the same as (or based on in some way) the key
11265 type, which itself is marked with the 'N_KEY' bit. If the 'N_EQK' bit is
11266 set, various other bits can be set as well in order to modify the meaning of
11267 the type constraint. */
11268
11269enum neon_type_mask
11270{
8e79c3df
CM
11271 N_S8 = 0x0000001,
11272 N_S16 = 0x0000002,
11273 N_S32 = 0x0000004,
11274 N_S64 = 0x0000008,
11275 N_U8 = 0x0000010,
11276 N_U16 = 0x0000020,
11277 N_U32 = 0x0000040,
11278 N_U64 = 0x0000080,
11279 N_I8 = 0x0000100,
11280 N_I16 = 0x0000200,
11281 N_I32 = 0x0000400,
11282 N_I64 = 0x0000800,
11283 N_8 = 0x0001000,
11284 N_16 = 0x0002000,
11285 N_32 = 0x0004000,
11286 N_64 = 0x0008000,
11287 N_P8 = 0x0010000,
11288 N_P16 = 0x0020000,
11289 N_F16 = 0x0040000,
11290 N_F32 = 0x0080000,
11291 N_F64 = 0x0100000,
11292 N_KEY = 0x1000000, /* key element (main type specifier). */
11293 N_EQK = 0x2000000, /* given operand has the same type & size as the key. */
11294 N_VFP = 0x4000000, /* VFP mode: operand size must match register width. */
11295 N_DBL = 0x0000001, /* if N_EQK, this operand is twice the size. */
11296 N_HLF = 0x0000002, /* if N_EQK, this operand is half the size. */
11297 N_SGN = 0x0000004, /* if N_EQK, this operand is forced to be signed. */
11298 N_UNS = 0x0000008, /* if N_EQK, this operand is forced to be unsigned. */
11299 N_INT = 0x0000010, /* if N_EQK, this operand is forced to be integer. */
11300 N_FLT = 0x0000020, /* if N_EQK, this operand is forced to be float. */
11301 N_SIZ = 0x0000040, /* if N_EQK, this operand is forced to be size-only. */
5287ad62 11302 N_UTYP = 0,
037e8744 11303 N_MAX_NONSPECIAL = N_F64
5287ad62
JB
11304};
11305
dcbf9037
JB
11306#define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
11307
5287ad62
JB
11308#define N_SU_ALL (N_S8 | N_S16 | N_S32 | N_S64 | N_U8 | N_U16 | N_U32 | N_U64)
11309#define N_SU_32 (N_S8 | N_S16 | N_S32 | N_U8 | N_U16 | N_U32)
11310#define N_SU_16_64 (N_S16 | N_S32 | N_S64 | N_U16 | N_U32 | N_U64)
11311#define N_SUF_32 (N_SU_32 | N_F32)
11312#define N_I_ALL (N_I8 | N_I16 | N_I32 | N_I64)
11313#define N_IF_32 (N_I8 | N_I16 | N_I32 | N_F32)
11314
11315/* Pass this as the first type argument to neon_check_type to ignore types
11316 altogether. */
11317#define N_IGNORE_TYPE (N_KEY | N_EQK)
11318
037e8744
JB
11319/* Select a "shape" for the current instruction (describing register types or
11320 sizes) from a list of alternatives. Return NS_NULL if the current instruction
11321 doesn't fit. For non-polymorphic shapes, checking is usually done as a
11322 function of operand parsing, so this function doesn't need to be called.
11323 Shapes should be listed in order of decreasing length. */
5287ad62
JB
11324
11325static enum neon_shape
037e8744 11326neon_select_shape (enum neon_shape shape, ...)
5287ad62 11327{
037e8744
JB
11328 va_list ap;
11329 enum neon_shape first_shape = shape;
5287ad62
JB
11330
11331 /* Fix missing optional operands. FIXME: we don't know at this point how
11332 many arguments we should have, so this makes the assumption that we have
11333 > 1. This is true of all current Neon opcodes, I think, but may not be
11334 true in the future. */
11335 if (!inst.operands[1].present)
11336 inst.operands[1] = inst.operands[0];
11337
037e8744 11338 va_start (ap, shape);
5f4273c7 11339
037e8744
JB
11340 for (; shape != NS_NULL; shape = va_arg (ap, int))
11341 {
11342 unsigned j;
11343 int matches = 1;
11344
11345 for (j = 0; j < neon_shape_tab[shape].els; j++)
11346 {
11347 if (!inst.operands[j].present)
11348 {
11349 matches = 0;
11350 break;
11351 }
11352
11353 switch (neon_shape_tab[shape].el[j])
11354 {
11355 case SE_F:
11356 if (!(inst.operands[j].isreg
11357 && inst.operands[j].isvec
11358 && inst.operands[j].issingle
11359 && !inst.operands[j].isquad))
11360 matches = 0;
11361 break;
11362
11363 case SE_D:
11364 if (!(inst.operands[j].isreg
11365 && inst.operands[j].isvec
11366 && !inst.operands[j].isquad
11367 && !inst.operands[j].issingle))
11368 matches = 0;
11369 break;
11370
11371 case SE_R:
11372 if (!(inst.operands[j].isreg
11373 && !inst.operands[j].isvec))
11374 matches = 0;
11375 break;
11376
11377 case SE_Q:
11378 if (!(inst.operands[j].isreg
11379 && inst.operands[j].isvec
11380 && inst.operands[j].isquad
11381 && !inst.operands[j].issingle))
11382 matches = 0;
11383 break;
11384
11385 case SE_I:
11386 if (!(!inst.operands[j].isreg
11387 && !inst.operands[j].isscalar))
11388 matches = 0;
11389 break;
11390
11391 case SE_S:
11392 if (!(!inst.operands[j].isreg
11393 && inst.operands[j].isscalar))
11394 matches = 0;
11395 break;
11396
11397 case SE_L:
11398 break;
11399 }
11400 }
11401 if (matches)
5287ad62 11402 break;
037e8744 11403 }
5f4273c7 11404
037e8744 11405 va_end (ap);
5287ad62 11406
037e8744
JB
11407 if (shape == NS_NULL && first_shape != NS_NULL)
11408 first_error (_("invalid instruction shape"));
5287ad62 11409
037e8744
JB
11410 return shape;
11411}
5287ad62 11412
037e8744
JB
11413/* True if SHAPE is predominantly a quadword operation (most of the time, this
11414 means the Q bit should be set). */
11415
11416static int
11417neon_quad (enum neon_shape shape)
11418{
11419 return neon_shape_class[shape] == SC_QUAD;
5287ad62 11420}
037e8744 11421
5287ad62
JB
11422static void
11423neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11424 unsigned *g_size)
11425{
11426 /* Allow modification to be made to types which are constrained to be
11427 based on the key element, based on bits set alongside N_EQK. */
11428 if ((typebits & N_EQK) != 0)
11429 {
11430 if ((typebits & N_HLF) != 0)
11431 *g_size /= 2;
11432 else if ((typebits & N_DBL) != 0)
11433 *g_size *= 2;
11434 if ((typebits & N_SGN) != 0)
11435 *g_type = NT_signed;
11436 else if ((typebits & N_UNS) != 0)
11437 *g_type = NT_unsigned;
11438 else if ((typebits & N_INT) != 0)
11439 *g_type = NT_integer;
11440 else if ((typebits & N_FLT) != 0)
11441 *g_type = NT_float;
dcbf9037
JB
11442 else if ((typebits & N_SIZ) != 0)
11443 *g_type = NT_untyped;
5287ad62
JB
11444 }
11445}
5f4273c7 11446
5287ad62
JB
11447/* Return operand OPNO promoted by bits set in THISARG. KEY should be the "key"
11448 operand type, i.e. the single type specified in a Neon instruction when it
11449 is the only one given. */
11450
11451static struct neon_type_el
11452neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11453{
11454 struct neon_type_el dest = *key;
5f4273c7 11455
9c2799c2 11456 gas_assert ((thisarg & N_EQK) != 0);
5f4273c7 11457
5287ad62
JB
11458 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11459
11460 return dest;
11461}
11462
11463/* Convert Neon type and size into compact bitmask representation. */
11464
11465static enum neon_type_mask
11466type_chk_of_el_type (enum neon_el_type type, unsigned size)
11467{
11468 switch (type)
11469 {
11470 case NT_untyped:
11471 switch (size)
11472 {
11473 case 8: return N_8;
11474 case 16: return N_16;
11475 case 32: return N_32;
11476 case 64: return N_64;
11477 default: ;
11478 }
11479 break;
11480
11481 case NT_integer:
11482 switch (size)
11483 {
11484 case 8: return N_I8;
11485 case 16: return N_I16;
11486 case 32: return N_I32;
11487 case 64: return N_I64;
11488 default: ;
11489 }
11490 break;
11491
11492 case NT_float:
037e8744
JB
11493 switch (size)
11494 {
8e79c3df 11495 case 16: return N_F16;
037e8744
JB
11496 case 32: return N_F32;
11497 case 64: return N_F64;
11498 default: ;
11499 }
5287ad62
JB
11500 break;
11501
11502 case NT_poly:
11503 switch (size)
11504 {
11505 case 8: return N_P8;
11506 case 16: return N_P16;
11507 default: ;
11508 }
11509 break;
11510
11511 case NT_signed:
11512 switch (size)
11513 {
11514 case 8: return N_S8;
11515 case 16: return N_S16;
11516 case 32: return N_S32;
11517 case 64: return N_S64;
11518 default: ;
11519 }
11520 break;
11521
11522 case NT_unsigned:
11523 switch (size)
11524 {
11525 case 8: return N_U8;
11526 case 16: return N_U16;
11527 case 32: return N_U32;
11528 case 64: return N_U64;
11529 default: ;
11530 }
11531 break;
11532
11533 default: ;
11534 }
5f4273c7 11535
5287ad62
JB
11536 return N_UTYP;
11537}
11538
11539/* Convert compact Neon bitmask type representation to a type and size. Only
11540 handles the case where a single bit is set in the mask. */
11541
dcbf9037 11542static int
5287ad62
JB
11543el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11544 enum neon_type_mask mask)
11545{
dcbf9037
JB
11546 if ((mask & N_EQK) != 0)
11547 return FAIL;
11548
5287ad62
JB
11549 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11550 *size = 8;
dcbf9037 11551 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
5287ad62 11552 *size = 16;
dcbf9037 11553 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
5287ad62 11554 *size = 32;
037e8744 11555 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
5287ad62 11556 *size = 64;
dcbf9037
JB
11557 else
11558 return FAIL;
11559
5287ad62
JB
11560 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11561 *type = NT_signed;
dcbf9037 11562 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
5287ad62 11563 *type = NT_unsigned;
dcbf9037 11564 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
5287ad62 11565 *type = NT_integer;
dcbf9037 11566 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
5287ad62 11567 *type = NT_untyped;
dcbf9037 11568 else if ((mask & (N_P8 | N_P16)) != 0)
5287ad62 11569 *type = NT_poly;
037e8744 11570 else if ((mask & (N_F32 | N_F64)) != 0)
5287ad62 11571 *type = NT_float;
dcbf9037
JB
11572 else
11573 return FAIL;
5f4273c7 11574
dcbf9037 11575 return SUCCESS;
5287ad62
JB
11576}
11577
11578/* Modify a bitmask of allowed types. This is only needed for type
11579 relaxation. */
11580
11581static unsigned
11582modify_types_allowed (unsigned allowed, unsigned mods)
11583{
11584 unsigned size;
11585 enum neon_el_type type;
11586 unsigned destmask;
11587 int i;
5f4273c7 11588
5287ad62 11589 destmask = 0;
5f4273c7 11590
5287ad62
JB
11591 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11592 {
dcbf9037
JB
11593 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11594 {
11595 neon_modify_type_size (mods, &type, &size);
11596 destmask |= type_chk_of_el_type (type, size);
11597 }
5287ad62 11598 }
5f4273c7 11599
5287ad62
JB
11600 return destmask;
11601}
11602
11603/* Check type and return type classification.
11604 The manual states (paraphrase): If one datatype is given, it indicates the
11605 type given in:
11606 - the second operand, if there is one
11607 - the operand, if there is no second operand
11608 - the result, if there are no operands.
11609 This isn't quite good enough though, so we use a concept of a "key" datatype
11610 which is set on a per-instruction basis, which is the one which matters when
11611 only one data type is written.
11612 Note: this function has side-effects (e.g. filling in missing operands). All
037e8744 11613 Neon instructions should call it before performing bit encoding. */
5287ad62
JB
11614
11615static struct neon_type_el
11616neon_check_type (unsigned els, enum neon_shape ns, ...)
11617{
11618 va_list ap;
11619 unsigned i, pass, key_el = 0;
11620 unsigned types[NEON_MAX_TYPE_ELS];
11621 enum neon_el_type k_type = NT_invtype;
11622 unsigned k_size = -1u;
11623 struct neon_type_el badtype = {NT_invtype, -1};
11624 unsigned key_allowed = 0;
11625
11626 /* Optional registers in Neon instructions are always (not) in operand 1.
11627 Fill in the missing operand here, if it was omitted. */
11628 if (els > 1 && !inst.operands[1].present)
11629 inst.operands[1] = inst.operands[0];
11630
11631 /* Suck up all the varargs. */
11632 va_start (ap, ns);
11633 for (i = 0; i < els; i++)
11634 {
11635 unsigned thisarg = va_arg (ap, unsigned);
11636 if (thisarg == N_IGNORE_TYPE)
11637 {
11638 va_end (ap);
11639 return badtype;
11640 }
11641 types[i] = thisarg;
11642 if ((thisarg & N_KEY) != 0)
11643 key_el = i;
11644 }
11645 va_end (ap);
11646
dcbf9037
JB
11647 if (inst.vectype.elems > 0)
11648 for (i = 0; i < els; i++)
11649 if (inst.operands[i].vectype.type != NT_invtype)
11650 {
11651 first_error (_("types specified in both the mnemonic and operands"));
11652 return badtype;
11653 }
11654
5287ad62
JB
11655 /* Duplicate inst.vectype elements here as necessary.
11656 FIXME: No idea if this is exactly the same as the ARM assembler,
11657 particularly when an insn takes one register and one non-register
11658 operand. */
11659 if (inst.vectype.elems == 1 && els > 1)
11660 {
11661 unsigned j;
11662 inst.vectype.elems = els;
11663 inst.vectype.el[key_el] = inst.vectype.el[0];
11664 for (j = 0; j < els; j++)
dcbf9037
JB
11665 if (j != key_el)
11666 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11667 types[j]);
11668 }
11669 else if (inst.vectype.elems == 0 && els > 0)
11670 {
11671 unsigned j;
11672 /* No types were given after the mnemonic, so look for types specified
11673 after each operand. We allow some flexibility here; as long as the
11674 "key" operand has a type, we can infer the others. */
11675 for (j = 0; j < els; j++)
11676 if (inst.operands[j].vectype.type != NT_invtype)
11677 inst.vectype.el[j] = inst.operands[j].vectype;
11678
11679 if (inst.operands[key_el].vectype.type != NT_invtype)
5287ad62 11680 {
dcbf9037
JB
11681 for (j = 0; j < els; j++)
11682 if (inst.operands[j].vectype.type == NT_invtype)
11683 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11684 types[j]);
11685 }
11686 else
11687 {
11688 first_error (_("operand types can't be inferred"));
11689 return badtype;
5287ad62
JB
11690 }
11691 }
11692 else if (inst.vectype.elems != els)
11693 {
dcbf9037 11694 first_error (_("type specifier has the wrong number of parts"));
5287ad62
JB
11695 return badtype;
11696 }
11697
11698 for (pass = 0; pass < 2; pass++)
11699 {
11700 for (i = 0; i < els; i++)
11701 {
11702 unsigned thisarg = types[i];
11703 unsigned types_allowed = ((thisarg & N_EQK) != 0 && pass != 0)
11704 ? modify_types_allowed (key_allowed, thisarg) : thisarg;
11705 enum neon_el_type g_type = inst.vectype.el[i].type;
11706 unsigned g_size = inst.vectype.el[i].size;
11707
11708 /* Decay more-specific signed & unsigned types to sign-insensitive
11709 integer types if sign-specific variants are unavailable. */
11710 if ((g_type == NT_signed || g_type == NT_unsigned)
11711 && (types_allowed & N_SU_ALL) == 0)
11712 g_type = NT_integer;
11713
11714 /* If only untyped args are allowed, decay any more specific types to
11715 them. Some instructions only care about signs for some element
11716 sizes, so handle that properly. */
11717 if ((g_size == 8 && (types_allowed & N_8) != 0)
11718 || (g_size == 16 && (types_allowed & N_16) != 0)
11719 || (g_size == 32 && (types_allowed & N_32) != 0)
11720 || (g_size == 64 && (types_allowed & N_64) != 0))
11721 g_type = NT_untyped;
11722
11723 if (pass == 0)
11724 {
11725 if ((thisarg & N_KEY) != 0)
11726 {
11727 k_type = g_type;
11728 k_size = g_size;
11729 key_allowed = thisarg & ~N_KEY;
11730 }
11731 }
11732 else
11733 {
037e8744
JB
11734 if ((thisarg & N_VFP) != 0)
11735 {
11736 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11737 unsigned regwidth = neon_shape_el_size[regshape], match;
11738
11739 /* In VFP mode, operands must match register widths. If we
11740 have a key operand, use its width, else use the width of
11741 the current operand. */
11742 if (k_size != -1u)
11743 match = k_size;
11744 else
11745 match = g_size;
11746
11747 if (regwidth != match)
11748 {
11749 first_error (_("operand size must match register width"));
11750 return badtype;
11751 }
11752 }
5f4273c7 11753
5287ad62
JB
11754 if ((thisarg & N_EQK) == 0)
11755 {
11756 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11757
11758 if ((given_type & types_allowed) == 0)
11759 {
dcbf9037 11760 first_error (_("bad type in Neon instruction"));
5287ad62
JB
11761 return badtype;
11762 }
11763 }
11764 else
11765 {
11766 enum neon_el_type mod_k_type = k_type;
11767 unsigned mod_k_size = k_size;
11768 neon_modify_type_size (thisarg, &mod_k_type, &mod_k_size);
11769 if (g_type != mod_k_type || g_size != mod_k_size)
11770 {
dcbf9037 11771 first_error (_("inconsistent types in Neon instruction"));
5287ad62
JB
11772 return badtype;
11773 }
11774 }
11775 }
11776 }
11777 }
11778
11779 return inst.vectype.el[key_el];
11780}
11781
037e8744 11782/* Neon-style VFP instruction forwarding. */
5287ad62 11783
037e8744
JB
11784/* Thumb VFP instructions have 0xE in the condition field. */
11785
11786static void
11787do_vfp_cond_or_thumb (void)
5287ad62
JB
11788{
11789 if (thumb_mode)
037e8744 11790 inst.instruction |= 0xe0000000;
5287ad62 11791 else
037e8744 11792 inst.instruction |= inst.cond << 28;
5287ad62
JB
11793}
11794
037e8744
JB
11795/* Look up and encode a simple mnemonic, for use as a helper function for the
11796 Neon-style VFP syntax. This avoids duplication of bits of the insns table,
11797 etc. It is assumed that operand parsing has already been done, and that the
11798 operands are in the form expected by the given opcode (this isn't necessarily
11799 the same as the form in which they were parsed, hence some massaging must
11800 take place before this function is called).
11801 Checks current arch version against that in the looked-up opcode. */
5287ad62 11802
037e8744
JB
11803static void
11804do_vfp_nsyn_opcode (const char *opname)
5287ad62 11805{
037e8744 11806 const struct asm_opcode *opcode;
5f4273c7 11807
037e8744 11808 opcode = hash_find (arm_ops_hsh, opname);
5287ad62 11809
037e8744
JB
11810 if (!opcode)
11811 abort ();
5287ad62 11812
037e8744
JB
11813 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11814 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11815 _(BAD_FPU));
5287ad62 11816
037e8744
JB
11817 if (thumb_mode)
11818 {
11819 inst.instruction = opcode->tvalue;
11820 opcode->tencode ();
11821 }
11822 else
11823 {
11824 inst.instruction = (inst.cond << 28) | opcode->avalue;
11825 opcode->aencode ();
11826 }
11827}
5287ad62
JB
11828
11829static void
037e8744 11830do_vfp_nsyn_add_sub (enum neon_shape rs)
5287ad62 11831{
037e8744
JB
11832 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11833
11834 if (rs == NS_FFF)
11835 {
11836 if (is_add)
11837 do_vfp_nsyn_opcode ("fadds");
11838 else
11839 do_vfp_nsyn_opcode ("fsubs");
11840 }
11841 else
11842 {
11843 if (is_add)
11844 do_vfp_nsyn_opcode ("faddd");
11845 else
11846 do_vfp_nsyn_opcode ("fsubd");
11847 }
11848}
11849
11850/* Check operand types to see if this is a VFP instruction, and if so call
11851 PFN (). */
11852
11853static int
11854try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11855{
11856 enum neon_shape rs;
11857 struct neon_type_el et;
11858
11859 switch (args)
11860 {
11861 case 2:
11862 rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11863 et = neon_check_type (2, rs,
11864 N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11865 break;
5f4273c7 11866
037e8744
JB
11867 case 3:
11868 rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11869 et = neon_check_type (3, rs,
11870 N_EQK | N_VFP, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
11871 break;
11872
11873 default:
11874 abort ();
11875 }
11876
11877 if (et.type != NT_invtype)
11878 {
11879 pfn (rs);
11880 return SUCCESS;
11881 }
11882 else
11883 inst.error = NULL;
11884
11885 return FAIL;
11886}
11887
11888static void
11889do_vfp_nsyn_mla_mls (enum neon_shape rs)
11890{
11891 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
5f4273c7 11892
037e8744
JB
11893 if (rs == NS_FFF)
11894 {
11895 if (is_mla)
11896 do_vfp_nsyn_opcode ("fmacs");
11897 else
11898 do_vfp_nsyn_opcode ("fmscs");
11899 }
11900 else
11901 {
11902 if (is_mla)
11903 do_vfp_nsyn_opcode ("fmacd");
11904 else
11905 do_vfp_nsyn_opcode ("fmscd");
11906 }
11907}
11908
11909static void
11910do_vfp_nsyn_mul (enum neon_shape rs)
11911{
11912 if (rs == NS_FFF)
11913 do_vfp_nsyn_opcode ("fmuls");
11914 else
11915 do_vfp_nsyn_opcode ("fmuld");
11916}
11917
11918static void
11919do_vfp_nsyn_abs_neg (enum neon_shape rs)
11920{
11921 int is_neg = (inst.instruction & 0x80) != 0;
11922 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_VFP | N_KEY);
11923
11924 if (rs == NS_FF)
11925 {
11926 if (is_neg)
11927 do_vfp_nsyn_opcode ("fnegs");
11928 else
11929 do_vfp_nsyn_opcode ("fabss");
11930 }
11931 else
11932 {
11933 if (is_neg)
11934 do_vfp_nsyn_opcode ("fnegd");
11935 else
11936 do_vfp_nsyn_opcode ("fabsd");
11937 }
11938}
11939
11940/* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11941 insns belong to Neon, and are handled elsewhere. */
11942
11943static void
11944do_vfp_nsyn_ldm_stm (int is_dbmode)
11945{
11946 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11947 if (is_ldm)
11948 {
11949 if (is_dbmode)
11950 do_vfp_nsyn_opcode ("fldmdbs");
11951 else
11952 do_vfp_nsyn_opcode ("fldmias");
11953 }
11954 else
11955 {
11956 if (is_dbmode)
11957 do_vfp_nsyn_opcode ("fstmdbs");
11958 else
11959 do_vfp_nsyn_opcode ("fstmias");
11960 }
11961}
11962
037e8744
JB
11963static void
11964do_vfp_nsyn_sqrt (void)
11965{
11966 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
11967 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11968
037e8744
JB
11969 if (rs == NS_FF)
11970 do_vfp_nsyn_opcode ("fsqrts");
11971 else
11972 do_vfp_nsyn_opcode ("fsqrtd");
11973}
11974
11975static void
11976do_vfp_nsyn_div (void)
11977{
11978 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11979 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11980 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11981
037e8744
JB
11982 if (rs == NS_FFF)
11983 do_vfp_nsyn_opcode ("fdivs");
11984 else
11985 do_vfp_nsyn_opcode ("fdivd");
11986}
11987
11988static void
11989do_vfp_nsyn_nmul (void)
11990{
11991 enum neon_shape rs = neon_select_shape (NS_FFF, NS_DDD, NS_NULL);
11992 neon_check_type (3, rs, N_EQK | N_VFP, N_EQK | N_VFP,
11993 N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 11994
037e8744
JB
11995 if (rs == NS_FFF)
11996 {
11997 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11998 do_vfp_sp_dyadic ();
11999 }
12000 else
12001 {
12002 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12003 do_vfp_dp_rd_rn_rm ();
12004 }
12005 do_vfp_cond_or_thumb ();
12006}
12007
12008static void
12009do_vfp_nsyn_cmp (void)
12010{
12011 if (inst.operands[1].isreg)
12012 {
12013 enum neon_shape rs = neon_select_shape (NS_FF, NS_DD, NS_NULL);
12014 neon_check_type (2, rs, N_EQK | N_VFP, N_F32 | N_F64 | N_KEY | N_VFP);
5f4273c7 12015
037e8744
JB
12016 if (rs == NS_FF)
12017 {
12018 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12019 do_vfp_sp_monadic ();
12020 }
12021 else
12022 {
12023 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12024 do_vfp_dp_rd_rm ();
12025 }
12026 }
12027 else
12028 {
12029 enum neon_shape rs = neon_select_shape (NS_FI, NS_DI, NS_NULL);
12030 neon_check_type (2, rs, N_F32 | N_F64 | N_KEY | N_VFP, N_EQK);
12031
12032 switch (inst.instruction & 0x0fffffff)
12033 {
12034 case N_MNEM_vcmp:
12035 inst.instruction += N_MNEM_vcmpz - N_MNEM_vcmp;
12036 break;
12037 case N_MNEM_vcmpe:
12038 inst.instruction += N_MNEM_vcmpez - N_MNEM_vcmpe;
12039 break;
12040 default:
12041 abort ();
12042 }
5f4273c7 12043
037e8744
JB
12044 if (rs == NS_FI)
12045 {
12046 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12047 do_vfp_sp_compare_z ();
12048 }
12049 else
12050 {
12051 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12052 do_vfp_dp_rd ();
12053 }
12054 }
12055 do_vfp_cond_or_thumb ();
12056}
12057
12058static void
12059nsyn_insert_sp (void)
12060{
12061 inst.operands[1] = inst.operands[0];
12062 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
fdfde340 12063 inst.operands[0].reg = REG_SP;
037e8744
JB
12064 inst.operands[0].isreg = 1;
12065 inst.operands[0].writeback = 1;
12066 inst.operands[0].present = 1;
12067}
12068
12069static void
12070do_vfp_nsyn_push (void)
12071{
12072 nsyn_insert_sp ();
12073 if (inst.operands[1].issingle)
12074 do_vfp_nsyn_opcode ("fstmdbs");
12075 else
12076 do_vfp_nsyn_opcode ("fstmdbd");
12077}
12078
12079static void
12080do_vfp_nsyn_pop (void)
12081{
12082 nsyn_insert_sp ();
12083 if (inst.operands[1].issingle)
22b5b651 12084 do_vfp_nsyn_opcode ("fldmias");
037e8744 12085 else
22b5b651 12086 do_vfp_nsyn_opcode ("fldmiad");
037e8744
JB
12087}
12088
12089/* Fix up Neon data-processing instructions, ORing in the correct bits for
12090 ARM mode or Thumb mode and moving the encoded bit 24 to bit 28. */
12091
12092static unsigned
12093neon_dp_fixup (unsigned i)
12094{
12095 if (thumb_mode)
12096 {
12097 /* The U bit is at bit 24 by default. Move to bit 28 in Thumb mode. */
12098 if (i & (1 << 24))
12099 i |= 1 << 28;
5f4273c7 12100
037e8744 12101 i &= ~(1 << 24);
5f4273c7 12102
037e8744
JB
12103 i |= 0xef000000;
12104 }
12105 else
12106 i |= 0xf2000000;
5f4273c7 12107
037e8744
JB
12108 return i;
12109}
12110
12111/* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12112 (0, 1, 2, 3). */
12113
12114static unsigned
12115neon_logbits (unsigned x)
12116{
12117 return ffs (x) - 4;
12118}
12119
12120#define LOW4(R) ((R) & 0xf)
12121#define HI1(R) (((R) >> 4) & 1)
12122
12123/* Encode insns with bit pattern:
12124
12125 |28/24|23|22 |21 20|19 16|15 12|11 8|7|6|5|4|3 0|
12126 | U |x |D |size | Rn | Rd |x x x x|N|Q|M|x| Rm |
5f4273c7 12127
037e8744
JB
12128 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12129 different meaning for some instruction. */
12130
12131static void
12132neon_three_same (int isquad, int ubit, int size)
12133{
12134 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12135 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12136 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12137 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12138 inst.instruction |= LOW4 (inst.operands[2].reg);
12139 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
12140 inst.instruction |= (isquad != 0) << 6;
12141 inst.instruction |= (ubit != 0) << 24;
12142 if (size != -1)
12143 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 12144
037e8744
JB
12145 inst.instruction = neon_dp_fixup (inst.instruction);
12146}
12147
12148/* Encode instructions of the form:
12149
12150 |28/24|23|22|21 20|19 18|17 16|15 12|11 7|6|5|4|3 0|
12151 | U |x |D |x x |size |x x | Rd |x x x x x|Q|M|x| Rm |
5287ad62
JB
12152
12153 Don't write size if SIZE == -1. */
12154
12155static void
12156neon_two_same (int qbit, int ubit, int size)
12157{
12158 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12159 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12160 inst.instruction |= LOW4 (inst.operands[1].reg);
12161 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12162 inst.instruction |= (qbit != 0) << 6;
12163 inst.instruction |= (ubit != 0) << 24;
12164
12165 if (size != -1)
12166 inst.instruction |= neon_logbits (size) << 18;
12167
12168 inst.instruction = neon_dp_fixup (inst.instruction);
12169}
12170
12171/* Neon instruction encoders, in approximate order of appearance. */
12172
12173static void
12174do_neon_dyadic_i_su (void)
12175{
037e8744 12176 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12177 struct neon_type_el et = neon_check_type (3, rs,
12178 N_EQK, N_EQK, N_SU_32 | N_KEY);
037e8744 12179 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12180}
12181
12182static void
12183do_neon_dyadic_i64_su (void)
12184{
037e8744 12185 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12186 struct neon_type_el et = neon_check_type (3, rs,
12187 N_EQK, N_EQK, N_SU_ALL | N_KEY);
037e8744 12188 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12189}
12190
12191static void
12192neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12193 unsigned immbits)
12194{
12195 unsigned size = et.size >> 3;
12196 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12197 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12198 inst.instruction |= LOW4 (inst.operands[1].reg);
12199 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
12200 inst.instruction |= (isquad != 0) << 6;
12201 inst.instruction |= immbits << 16;
12202 inst.instruction |= (size >> 3) << 7;
12203 inst.instruction |= (size & 0x7) << 19;
12204 if (write_ubit)
12205 inst.instruction |= (uval != 0) << 24;
12206
12207 inst.instruction = neon_dp_fixup (inst.instruction);
12208}
12209
12210static void
12211do_neon_shl_imm (void)
12212{
12213 if (!inst.operands[2].isreg)
12214 {
037e8744 12215 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12216 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_KEY | N_I_ALL);
12217 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12218 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
5287ad62
JB
12219 }
12220 else
12221 {
037e8744 12222 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12223 struct neon_type_el et = neon_check_type (3, rs,
12224 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12225 unsigned int tmp;
12226
12227 /* VSHL/VQSHL 3-register variants have syntax such as:
12228 vshl.xx Dd, Dm, Dn
12229 whereas other 3-register operations encoded by neon_three_same have
12230 syntax like:
12231 vadd.xx Dd, Dn, Dm
12232 (i.e. with Dn & Dm reversed). Swap operands[1].reg and operands[2].reg
12233 here. */
12234 tmp = inst.operands[2].reg;
12235 inst.operands[2].reg = inst.operands[1].reg;
12236 inst.operands[1].reg = tmp;
5287ad62 12237 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12238 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12239 }
12240}
12241
12242static void
12243do_neon_qshl_imm (void)
12244{
12245 if (!inst.operands[2].isreg)
12246 {
037e8744 12247 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62 12248 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
627907b7 12249
5287ad62 12250 inst.instruction = NEON_ENC_IMMED (inst.instruction);
037e8744 12251 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
12252 inst.operands[2].imm);
12253 }
12254 else
12255 {
037e8744 12256 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12257 struct neon_type_el et = neon_check_type (3, rs,
12258 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
627907b7
JB
12259 unsigned int tmp;
12260
12261 /* See note in do_neon_shl_imm. */
12262 tmp = inst.operands[2].reg;
12263 inst.operands[2].reg = inst.operands[1].reg;
12264 inst.operands[1].reg = tmp;
5287ad62 12265 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12266 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
5287ad62
JB
12267 }
12268}
12269
627907b7
JB
12270static void
12271do_neon_rshl (void)
12272{
12273 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12274 struct neon_type_el et = neon_check_type (3, rs,
12275 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12276 unsigned int tmp;
12277
12278 tmp = inst.operands[2].reg;
12279 inst.operands[2].reg = inst.operands[1].reg;
12280 inst.operands[1].reg = tmp;
12281 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12282}
12283
5287ad62
JB
12284static int
12285neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12286{
036dc3f7
PB
12287 /* Handle .I8 pseudo-instructions. */
12288 if (size == 8)
5287ad62 12289 {
5287ad62
JB
12290 /* Unfortunately, this will make everything apart from zero out-of-range.
12291 FIXME is this the intended semantics? There doesn't seem much point in
12292 accepting .I8 if so. */
12293 immediate |= immediate << 8;
12294 size = 16;
036dc3f7
PB
12295 }
12296
12297 if (size >= 32)
12298 {
12299 if (immediate == (immediate & 0x000000ff))
12300 {
12301 *immbits = immediate;
12302 return 0x1;
12303 }
12304 else if (immediate == (immediate & 0x0000ff00))
12305 {
12306 *immbits = immediate >> 8;
12307 return 0x3;
12308 }
12309 else if (immediate == (immediate & 0x00ff0000))
12310 {
12311 *immbits = immediate >> 16;
12312 return 0x5;
12313 }
12314 else if (immediate == (immediate & 0xff000000))
12315 {
12316 *immbits = immediate >> 24;
12317 return 0x7;
12318 }
12319 if ((immediate & 0xffff) != (immediate >> 16))
12320 goto bad_immediate;
12321 immediate &= 0xffff;
5287ad62
JB
12322 }
12323
12324 if (immediate == (immediate & 0x000000ff))
12325 {
12326 *immbits = immediate;
036dc3f7 12327 return 0x9;
5287ad62
JB
12328 }
12329 else if (immediate == (immediate & 0x0000ff00))
12330 {
12331 *immbits = immediate >> 8;
036dc3f7 12332 return 0xb;
5287ad62
JB
12333 }
12334
12335 bad_immediate:
dcbf9037 12336 first_error (_("immediate value out of range"));
5287ad62
JB
12337 return FAIL;
12338}
12339
12340/* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12341 A, B, C, D. */
12342
12343static int
12344neon_bits_same_in_bytes (unsigned imm)
12345{
12346 return ((imm & 0x000000ff) == 0 || (imm & 0x000000ff) == 0x000000ff)
12347 && ((imm & 0x0000ff00) == 0 || (imm & 0x0000ff00) == 0x0000ff00)
12348 && ((imm & 0x00ff0000) == 0 || (imm & 0x00ff0000) == 0x00ff0000)
12349 && ((imm & 0xff000000) == 0 || (imm & 0xff000000) == 0xff000000);
12350}
12351
12352/* For immediate of above form, return 0bABCD. */
12353
12354static unsigned
12355neon_squash_bits (unsigned imm)
12356{
12357 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12358 | ((imm & 0x01000000) >> 21);
12359}
12360
136da414 12361/* Compress quarter-float representation to 0b...000 abcdefgh. */
5287ad62
JB
12362
12363static unsigned
12364neon_qfloat_bits (unsigned imm)
12365{
136da414 12366 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
5287ad62
JB
12367}
12368
12369/* Returns CMODE. IMMBITS [7:0] is set to bits suitable for inserting into
12370 the instruction. *OP is passed as the initial value of the op field, and
12371 may be set to a different value depending on the constant (i.e.
12372 "MOV I64, 0bAAAAAAAABBBB..." which uses OP = 1 despite being MOV not
5f4273c7 12373 MVN). If the immediate looks like a repeated pattern then also
036dc3f7 12374 try smaller element sizes. */
5287ad62
JB
12375
12376static int
c96612cc
JB
12377neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12378 unsigned *immbits, int *op, int size,
12379 enum neon_el_type type)
5287ad62 12380{
c96612cc
JB
12381 /* Only permit float immediates (including 0.0/-0.0) if the operand type is
12382 float. */
12383 if (type == NT_float && !float_p)
12384 return FAIL;
12385
136da414
JB
12386 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12387 {
12388 if (size != 32 || *op == 1)
12389 return FAIL;
12390 *immbits = neon_qfloat_bits (immlo);
12391 return 0xf;
12392 }
036dc3f7
PB
12393
12394 if (size == 64)
5287ad62 12395 {
036dc3f7
PB
12396 if (neon_bits_same_in_bytes (immhi)
12397 && neon_bits_same_in_bytes (immlo))
12398 {
12399 if (*op == 1)
12400 return FAIL;
12401 *immbits = (neon_squash_bits (immhi) << 4)
12402 | neon_squash_bits (immlo);
12403 *op = 1;
12404 return 0xe;
12405 }
12406
12407 if (immhi != immlo)
12408 return FAIL;
5287ad62 12409 }
036dc3f7
PB
12410
12411 if (size >= 32)
5287ad62 12412 {
036dc3f7
PB
12413 if (immlo == (immlo & 0x000000ff))
12414 {
12415 *immbits = immlo;
12416 return 0x0;
12417 }
12418 else if (immlo == (immlo & 0x0000ff00))
12419 {
12420 *immbits = immlo >> 8;
12421 return 0x2;
12422 }
12423 else if (immlo == (immlo & 0x00ff0000))
12424 {
12425 *immbits = immlo >> 16;
12426 return 0x4;
12427 }
12428 else if (immlo == (immlo & 0xff000000))
12429 {
12430 *immbits = immlo >> 24;
12431 return 0x6;
12432 }
12433 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12434 {
12435 *immbits = (immlo >> 8) & 0xff;
12436 return 0xc;
12437 }
12438 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12439 {
12440 *immbits = (immlo >> 16) & 0xff;
12441 return 0xd;
12442 }
12443
12444 if ((immlo & 0xffff) != (immlo >> 16))
12445 return FAIL;
12446 immlo &= 0xffff;
5287ad62 12447 }
036dc3f7
PB
12448
12449 if (size >= 16)
5287ad62 12450 {
036dc3f7
PB
12451 if (immlo == (immlo & 0x000000ff))
12452 {
12453 *immbits = immlo;
12454 return 0x8;
12455 }
12456 else if (immlo == (immlo & 0x0000ff00))
12457 {
12458 *immbits = immlo >> 8;
12459 return 0xa;
12460 }
12461
12462 if ((immlo & 0xff) != (immlo >> 8))
12463 return FAIL;
12464 immlo &= 0xff;
5287ad62 12465 }
036dc3f7
PB
12466
12467 if (immlo == (immlo & 0x000000ff))
5287ad62 12468 {
036dc3f7
PB
12469 /* Don't allow MVN with 8-bit immediate. */
12470 if (*op == 1)
12471 return FAIL;
12472 *immbits = immlo;
12473 return 0xe;
5287ad62 12474 }
5287ad62
JB
12475
12476 return FAIL;
12477}
12478
12479/* Write immediate bits [7:0] to the following locations:
12480
12481 |28/24|23 19|18 16|15 4|3 0|
12482 | 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|
12483
12484 This function is used by VMOV/VMVN/VORR/VBIC. */
12485
12486static void
12487neon_write_immbits (unsigned immbits)
12488{
12489 inst.instruction |= immbits & 0xf;
12490 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12491 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12492}
12493
12494/* Invert low-order SIZE bits of XHI:XLO. */
12495
12496static void
12497neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12498{
12499 unsigned immlo = xlo ? *xlo : 0;
12500 unsigned immhi = xhi ? *xhi : 0;
12501
12502 switch (size)
12503 {
12504 case 8:
12505 immlo = (~immlo) & 0xff;
12506 break;
12507
12508 case 16:
12509 immlo = (~immlo) & 0xffff;
12510 break;
12511
12512 case 64:
12513 immhi = (~immhi) & 0xffffffff;
12514 /* fall through. */
12515
12516 case 32:
12517 immlo = (~immlo) & 0xffffffff;
12518 break;
12519
12520 default:
12521 abort ();
12522 }
12523
12524 if (xlo)
12525 *xlo = immlo;
12526
12527 if (xhi)
12528 *xhi = immhi;
12529}
12530
12531static void
12532do_neon_logic (void)
12533{
12534 if (inst.operands[2].present && inst.operands[2].isreg)
12535 {
037e8744 12536 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12537 neon_check_type (3, rs, N_IGNORE_TYPE);
12538 /* U bit and size field were set as part of the bitmask. */
12539 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12540 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12541 }
12542 else
12543 {
037e8744
JB
12544 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
12545 struct neon_type_el et = neon_check_type (2, rs,
12546 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62
JB
12547 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12548 unsigned immbits;
12549 int cmode;
5f4273c7 12550
5287ad62
JB
12551 if (et.type == NT_invtype)
12552 return;
5f4273c7 12553
5287ad62
JB
12554 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12555
036dc3f7
PB
12556 immbits = inst.operands[1].imm;
12557 if (et.size == 64)
12558 {
12559 /* .i64 is a pseudo-op, so the immediate must be a repeating
12560 pattern. */
12561 if (immbits != (inst.operands[1].regisimm ?
12562 inst.operands[1].reg : 0))
12563 {
12564 /* Set immbits to an invalid constant. */
12565 immbits = 0xdeadbeef;
12566 }
12567 }
12568
5287ad62
JB
12569 switch (opcode)
12570 {
12571 case N_MNEM_vbic:
036dc3f7 12572 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12573 break;
5f4273c7 12574
5287ad62 12575 case N_MNEM_vorr:
036dc3f7 12576 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
5287ad62 12577 break;
5f4273c7 12578
5287ad62
JB
12579 case N_MNEM_vand:
12580 /* Pseudo-instruction for VBIC. */
5287ad62
JB
12581 neon_invert_size (&immbits, 0, et.size);
12582 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12583 break;
5f4273c7 12584
5287ad62
JB
12585 case N_MNEM_vorn:
12586 /* Pseudo-instruction for VORR. */
5287ad62
JB
12587 neon_invert_size (&immbits, 0, et.size);
12588 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12589 break;
5f4273c7 12590
5287ad62
JB
12591 default:
12592 abort ();
12593 }
12594
12595 if (cmode == FAIL)
12596 return;
12597
037e8744 12598 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12599 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12600 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12601 inst.instruction |= cmode << 8;
12602 neon_write_immbits (immbits);
5f4273c7 12603
5287ad62
JB
12604 inst.instruction = neon_dp_fixup (inst.instruction);
12605 }
12606}
12607
12608static void
12609do_neon_bitfield (void)
12610{
037e8744 12611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037 12612 neon_check_type (3, rs, N_IGNORE_TYPE);
037e8744 12613 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12614}
12615
12616static void
dcbf9037
JB
12617neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12618 unsigned destbits)
5287ad62 12619{
037e8744 12620 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
dcbf9037
JB
12621 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12622 types | N_KEY);
5287ad62
JB
12623 if (et.type == NT_float)
12624 {
12625 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
037e8744 12626 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12627 }
12628 else
12629 {
12630 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 12631 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
5287ad62
JB
12632 }
12633}
12634
12635static void
12636do_neon_dyadic_if_su (void)
12637{
dcbf9037 12638 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12639}
12640
12641static void
12642do_neon_dyadic_if_su_d (void)
12643{
12644 /* This version only allow D registers, but that constraint is enforced during
12645 operand parsing so we don't need to do anything extra here. */
dcbf9037 12646 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
5287ad62
JB
12647}
12648
5287ad62
JB
12649static void
12650do_neon_dyadic_if_i_d (void)
12651{
428e3f1f
PB
12652 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12653 affected if we specify unsigned args. */
12654 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
5287ad62
JB
12655}
12656
037e8744
JB
12657enum vfp_or_neon_is_neon_bits
12658{
12659 NEON_CHECK_CC = 1,
12660 NEON_CHECK_ARCH = 2
12661};
12662
12663/* Call this function if an instruction which may have belonged to the VFP or
12664 Neon instruction sets, but turned out to be a Neon instruction (due to the
12665 operand types involved, etc.). We have to check and/or fix-up a couple of
12666 things:
12667
12668 - Make sure the user hasn't attempted to make a Neon instruction
12669 conditional.
12670 - Alter the value in the condition code field if necessary.
12671 - Make sure that the arch supports Neon instructions.
12672
12673 Which of these operations take place depends on bits from enum
12674 vfp_or_neon_is_neon_bits.
12675
12676 WARNING: This function has side effects! If NEON_CHECK_CC is used and the
12677 current instruction's condition is COND_ALWAYS, the condition field is
12678 changed to inst.uncond_value. This is necessary because instructions shared
12679 between VFP and Neon may be conditional for the VFP variants only, and the
12680 unconditional Neon version must have, e.g., 0xF in the condition field. */
12681
12682static int
12683vfp_or_neon_is_neon (unsigned check)
12684{
12685 /* Conditions are always legal in Thumb mode (IT blocks). */
12686 if (!thumb_mode && (check & NEON_CHECK_CC))
12687 {
12688 if (inst.cond != COND_ALWAYS)
12689 {
12690 first_error (_(BAD_COND));
12691 return FAIL;
12692 }
12693 if (inst.uncond_value != -1)
12694 inst.instruction |= inst.uncond_value << 28;
12695 }
5f4273c7 12696
037e8744
JB
12697 if ((check & NEON_CHECK_ARCH)
12698 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12699 {
12700 first_error (_(BAD_FPU));
12701 return FAIL;
12702 }
5f4273c7 12703
037e8744
JB
12704 return SUCCESS;
12705}
12706
5287ad62
JB
12707static void
12708do_neon_addsub_if_i (void)
12709{
037e8744
JB
12710 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12711 return;
12712
12713 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12714 return;
12715
5287ad62
JB
12716 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12717 affected if we specify unsigned args. */
dcbf9037 12718 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
5287ad62
JB
12719}
12720
12721/* Swaps operands 1 and 2. If operand 1 (optional arg) was omitted, we want the
12722 result to be:
12723 V<op> A,B (A is operand 0, B is operand 2)
12724 to mean:
12725 V<op> A,B,A
12726 not:
12727 V<op> A,B,B
12728 so handle that case specially. */
12729
12730static void
12731neon_exchange_operands (void)
12732{
12733 void *scratch = alloca (sizeof (inst.operands[0]));
12734 if (inst.operands[1].present)
12735 {
12736 /* Swap operands[1] and operands[2]. */
12737 memcpy (scratch, &inst.operands[1], sizeof (inst.operands[0]));
12738 inst.operands[1] = inst.operands[2];
12739 memcpy (&inst.operands[2], scratch, sizeof (inst.operands[0]));
12740 }
12741 else
12742 {
12743 inst.operands[1] = inst.operands[2];
12744 inst.operands[2] = inst.operands[0];
12745 }
12746}
12747
12748static void
12749neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12750{
12751 if (inst.operands[2].isreg)
12752 {
12753 if (invert)
12754 neon_exchange_operands ();
dcbf9037 12755 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
5287ad62
JB
12756 }
12757 else
12758 {
037e8744 12759 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
dcbf9037
JB
12760 struct neon_type_el et = neon_check_type (2, rs,
12761 N_EQK | N_SIZ, immtypes | N_KEY);
5287ad62
JB
12762
12763 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12764 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12765 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12766 inst.instruction |= LOW4 (inst.operands[1].reg);
12767 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12768 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12769 inst.instruction |= (et.type == NT_float) << 10;
12770 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12771
5287ad62
JB
12772 inst.instruction = neon_dp_fixup (inst.instruction);
12773 }
12774}
12775
12776static void
12777do_neon_cmp (void)
12778{
12779 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12780}
12781
12782static void
12783do_neon_cmp_inv (void)
12784{
12785 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12786}
12787
12788static void
12789do_neon_ceq (void)
12790{
12791 neon_compare (N_IF_32, N_IF_32, FALSE);
12792}
12793
12794/* For multiply instructions, we have the possibility of 16-bit or 32-bit
12795 scalars, which are encoded in 5 bits, M : Rm.
12796 For 16-bit scalars, the register is encoded in Rm[2:0] and the index in
12797 M:Rm[3], and for 32-bit scalars, the register is encoded in Rm[3:0] and the
12798 index in M. */
12799
12800static unsigned
12801neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12802{
dcbf9037
JB
12803 unsigned regno = NEON_SCALAR_REG (scalar);
12804 unsigned elno = NEON_SCALAR_INDEX (scalar);
5287ad62
JB
12805
12806 switch (elsize)
12807 {
12808 case 16:
12809 if (regno > 7 || elno > 3)
12810 goto bad_scalar;
12811 return regno | (elno << 3);
5f4273c7 12812
5287ad62
JB
12813 case 32:
12814 if (regno > 15 || elno > 1)
12815 goto bad_scalar;
12816 return regno | (elno << 4);
12817
12818 default:
12819 bad_scalar:
dcbf9037 12820 first_error (_("scalar out of range for multiply instruction"));
5287ad62
JB
12821 }
12822
12823 return 0;
12824}
12825
12826/* Encode multiply / multiply-accumulate scalar instructions. */
12827
12828static void
12829neon_mul_mac (struct neon_type_el et, int ubit)
12830{
dcbf9037
JB
12831 unsigned scalar;
12832
12833 /* Give a more helpful error message if we have an invalid type. */
12834 if (et.type == NT_invtype)
12835 return;
5f4273c7 12836
dcbf9037 12837 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
5287ad62
JB
12838 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12839 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12840 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
12841 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
12842 inst.instruction |= LOW4 (scalar);
12843 inst.instruction |= HI1 (scalar) << 5;
12844 inst.instruction |= (et.type == NT_float) << 8;
12845 inst.instruction |= neon_logbits (et.size) << 20;
12846 inst.instruction |= (ubit != 0) << 24;
12847
12848 inst.instruction = neon_dp_fixup (inst.instruction);
12849}
12850
12851static void
12852do_neon_mac_maybe_scalar (void)
12853{
037e8744
JB
12854 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12855 return;
12856
12857 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12858 return;
12859
5287ad62
JB
12860 if (inst.operands[2].isscalar)
12861 {
037e8744 12862 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12863 struct neon_type_el et = neon_check_type (3, rs,
12864 N_EQK, N_EQK, N_I16 | N_I32 | N_F32 | N_KEY);
12865 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12866 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12867 }
12868 else
428e3f1f
PB
12869 {
12870 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12871 affected if we specify unsigned args. */
12872 neon_dyadic_misc (NT_untyped, N_IF_32, 0);
12873 }
5287ad62
JB
12874}
12875
12876static void
12877do_neon_tst (void)
12878{
037e8744 12879 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12880 struct neon_type_el et = neon_check_type (3, rs,
12881 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
037e8744 12882 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12883}
12884
12885/* VMUL with 3 registers allows the P8 type. The scalar version supports the
12886 same types as the MAC equivalents. The polynomial type for this instruction
12887 is encoded the same as the integer type. */
12888
12889static void
12890do_neon_mul (void)
12891{
037e8744
JB
12892 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12893 return;
12894
12895 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12896 return;
12897
5287ad62
JB
12898 if (inst.operands[2].isscalar)
12899 do_neon_mac_maybe_scalar ();
12900 else
dcbf9037 12901 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
5287ad62
JB
12902}
12903
12904static void
12905do_neon_qdmulh (void)
12906{
12907 if (inst.operands[2].isscalar)
12908 {
037e8744 12909 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
5287ad62
JB
12910 struct neon_type_el et = neon_check_type (3, rs,
12911 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12912 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
037e8744 12913 neon_mul_mac (et, neon_quad (rs));
5287ad62
JB
12914 }
12915 else
12916 {
037e8744 12917 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12918 struct neon_type_el et = neon_check_type (3, rs,
12919 N_EQK, N_EQK, N_S16 | N_S32 | N_KEY);
12920 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12921 /* The U bit (rounding) comes from bit mask. */
037e8744 12922 neon_three_same (neon_quad (rs), 0, et.size);
5287ad62
JB
12923 }
12924}
12925
12926static void
12927do_neon_fcmp_absolute (void)
12928{
037e8744 12929 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62
JB
12930 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12931 /* Size field comes from bit mask. */
037e8744 12932 neon_three_same (neon_quad (rs), 1, -1);
5287ad62
JB
12933}
12934
12935static void
12936do_neon_fcmp_absolute_inv (void)
12937{
12938 neon_exchange_operands ();
12939 do_neon_fcmp_absolute ();
12940}
12941
12942static void
12943do_neon_step (void)
12944{
037e8744 12945 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
5287ad62 12946 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
037e8744 12947 neon_three_same (neon_quad (rs), 0, -1);
5287ad62
JB
12948}
12949
12950static void
12951do_neon_abs_neg (void)
12952{
037e8744
JB
12953 enum neon_shape rs;
12954 struct neon_type_el et;
5f4273c7 12955
037e8744
JB
12956 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12957 return;
12958
12959 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12960 return;
12961
12962 rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
12963 et = neon_check_type (2, rs, N_EQK, N_S8 | N_S16 | N_S32 | N_F32 | N_KEY);
5f4273c7 12964
5287ad62
JB
12965 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
12966 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
12967 inst.instruction |= LOW4 (inst.operands[1].reg);
12968 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 12969 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
12970 inst.instruction |= (et.type == NT_float) << 10;
12971 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 12972
5287ad62
JB
12973 inst.instruction = neon_dp_fixup (inst.instruction);
12974}
12975
12976static void
12977do_neon_sli (void)
12978{
037e8744 12979 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12980 struct neon_type_el et = neon_check_type (2, rs,
12981 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12982 int imm = inst.operands[2].imm;
12983 constraint (imm < 0 || (unsigned)imm >= et.size,
12984 _("immediate out of range for insert"));
037e8744 12985 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
12986}
12987
12988static void
12989do_neon_sri (void)
12990{
037e8744 12991 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
12992 struct neon_type_el et = neon_check_type (2, rs,
12993 N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
12994 int imm = inst.operands[2].imm;
12995 constraint (imm < 1 || (unsigned)imm > et.size,
12996 _("immediate out of range for insert"));
037e8744 12997 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
5287ad62
JB
12998}
12999
13000static void
13001do_neon_qshlu_imm (void)
13002{
037e8744 13003 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13004 struct neon_type_el et = neon_check_type (2, rs,
13005 N_EQK | N_UNS, N_S8 | N_S16 | N_S32 | N_S64 | N_KEY);
13006 int imm = inst.operands[2].imm;
13007 constraint (imm < 0 || (unsigned)imm >= et.size,
13008 _("immediate out of range for shift"));
13009 /* Only encodes the 'U present' variant of the instruction.
13010 In this case, signed types have OP (bit 8) set to 0.
13011 Unsigned types have OP set to 1. */
13012 inst.instruction |= (et.type == NT_unsigned) << 8;
13013 /* The rest of the bits are the same as other immediate shifts. */
037e8744 13014 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
5287ad62
JB
13015}
13016
13017static void
13018do_neon_qmovn (void)
13019{
13020 struct neon_type_el et = neon_check_type (2, NS_DQ,
13021 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13022 /* Saturating move where operands can be signed or unsigned, and the
13023 destination has the same signedness. */
13024 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13025 if (et.type == NT_unsigned)
13026 inst.instruction |= 0xc0;
13027 else
13028 inst.instruction |= 0x80;
13029 neon_two_same (0, 1, et.size / 2);
13030}
13031
13032static void
13033do_neon_qmovun (void)
13034{
13035 struct neon_type_el et = neon_check_type (2, NS_DQ,
13036 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13037 /* Saturating move with unsigned results. Operands must be signed. */
13038 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13039 neon_two_same (0, 1, et.size / 2);
13040}
13041
13042static void
13043do_neon_rshift_sat_narrow (void)
13044{
13045 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13046 or unsigned. If operands are unsigned, results must also be unsigned. */
13047 struct neon_type_el et = neon_check_type (2, NS_DQI,
13048 N_EQK | N_HLF, N_SU_16_64 | N_KEY);
13049 int imm = inst.operands[2].imm;
13050 /* This gets the bounds check, size encoding and immediate bits calculation
13051 right. */
13052 et.size /= 2;
5f4273c7 13053
5287ad62
JB
13054 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13055 VQMOVN.I<size> <Dd>, <Qm>. */
13056 if (imm == 0)
13057 {
13058 inst.operands[2].present = 0;
13059 inst.instruction = N_MNEM_vqmovn;
13060 do_neon_qmovn ();
13061 return;
13062 }
5f4273c7 13063
5287ad62
JB
13064 constraint (imm < 1 || (unsigned)imm > et.size,
13065 _("immediate out of range"));
13066 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, et.size - imm);
13067}
13068
13069static void
13070do_neon_rshift_sat_narrow_u (void)
13071{
13072 /* FIXME: Types for narrowing. If operands are signed, results can be signed
13073 or unsigned. If operands are unsigned, results must also be unsigned. */
13074 struct neon_type_el et = neon_check_type (2, NS_DQI,
13075 N_EQK | N_HLF | N_UNS, N_S16 | N_S32 | N_S64 | N_KEY);
13076 int imm = inst.operands[2].imm;
13077 /* This gets the bounds check, size encoding and immediate bits calculation
13078 right. */
13079 et.size /= 2;
13080
13081 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13082 VQMOVUN.I<size> <Dd>, <Qm>. */
13083 if (imm == 0)
13084 {
13085 inst.operands[2].present = 0;
13086 inst.instruction = N_MNEM_vqmovun;
13087 do_neon_qmovun ();
13088 return;
13089 }
13090
13091 constraint (imm < 1 || (unsigned)imm > et.size,
13092 _("immediate out of range"));
13093 /* FIXME: The manual is kind of unclear about what value U should have in
13094 VQ{R}SHRUN instructions, but U=0, op=0 definitely encodes VRSHR, so it
13095 must be 1. */
13096 neon_imm_shift (TRUE, 1, 0, et, et.size - imm);
13097}
13098
13099static void
13100do_neon_movn (void)
13101{
13102 struct neon_type_el et = neon_check_type (2, NS_DQ,
13103 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13104 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13105 neon_two_same (0, 1, et.size / 2);
13106}
13107
13108static void
13109do_neon_rshift_narrow (void)
13110{
13111 struct neon_type_el et = neon_check_type (2, NS_DQI,
13112 N_EQK | N_HLF, N_I16 | N_I32 | N_I64 | N_KEY);
13113 int imm = inst.operands[2].imm;
13114 /* This gets the bounds check, size encoding and immediate bits calculation
13115 right. */
13116 et.size /= 2;
5f4273c7 13117
5287ad62
JB
13118 /* If immediate is zero then we are a pseudo-instruction for
13119 VMOVN.I<size> <Dd>, <Qm> */
13120 if (imm == 0)
13121 {
13122 inst.operands[2].present = 0;
13123 inst.instruction = N_MNEM_vmovn;
13124 do_neon_movn ();
13125 return;
13126 }
5f4273c7 13127
5287ad62
JB
13128 constraint (imm < 1 || (unsigned)imm > et.size,
13129 _("immediate out of range for narrowing operation"));
13130 neon_imm_shift (FALSE, 0, 0, et, et.size - imm);
13131}
13132
13133static void
13134do_neon_shll (void)
13135{
13136 /* FIXME: Type checking when lengthening. */
13137 struct neon_type_el et = neon_check_type (2, NS_QDI,
13138 N_EQK | N_DBL, N_I8 | N_I16 | N_I32 | N_KEY);
13139 unsigned imm = inst.operands[2].imm;
13140
13141 if (imm == et.size)
13142 {
13143 /* Maximum shift variant. */
13144 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13145 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13146 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13147 inst.instruction |= LOW4 (inst.operands[1].reg);
13148 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13149 inst.instruction |= neon_logbits (et.size) << 18;
5f4273c7 13150
5287ad62
JB
13151 inst.instruction = neon_dp_fixup (inst.instruction);
13152 }
13153 else
13154 {
13155 /* A more-specific type check for non-max versions. */
13156 et = neon_check_type (2, NS_QDI,
13157 N_EQK | N_DBL, N_SU_32 | N_KEY);
13158 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13159 neon_imm_shift (TRUE, et.type == NT_unsigned, 0, et, imm);
13160 }
13161}
13162
037e8744 13163/* Check the various types for the VCVT instruction, and return which version
5287ad62
JB
13164 the current instruction is. */
13165
13166static int
13167neon_cvt_flavour (enum neon_shape rs)
13168{
037e8744
JB
13169#define CVT_VAR(C,X,Y) \
13170 et = neon_check_type (2, rs, whole_reg | (X), whole_reg | (Y)); \
13171 if (et.type != NT_invtype) \
13172 { \
13173 inst.error = NULL; \
13174 return (C); \
5287ad62
JB
13175 }
13176 struct neon_type_el et;
037e8744
JB
13177 unsigned whole_reg = (rs == NS_FFI || rs == NS_FD || rs == NS_DF
13178 || rs == NS_FF) ? N_VFP : 0;
13179 /* The instruction versions which take an immediate take one register
13180 argument, which is extended to the width of the full register. Thus the
13181 "source" and "destination" registers must have the same width. Hack that
13182 here by making the size equal to the key (wider, in this case) operand. */
13183 unsigned key = (rs == NS_QQI || rs == NS_DDI || rs == NS_FFI) ? N_KEY : 0;
5f4273c7 13184
5287ad62
JB
13185 CVT_VAR (0, N_S32, N_F32);
13186 CVT_VAR (1, N_U32, N_F32);
13187 CVT_VAR (2, N_F32, N_S32);
13188 CVT_VAR (3, N_F32, N_U32);
8e79c3df
CM
13189 /* Half-precision conversions. */
13190 CVT_VAR (4, N_F32, N_F16);
13191 CVT_VAR (5, N_F16, N_F32);
5f4273c7 13192
037e8744 13193 whole_reg = N_VFP;
5f4273c7 13194
037e8744 13195 /* VFP instructions. */
8e79c3df
CM
13196 CVT_VAR (6, N_F32, N_F64);
13197 CVT_VAR (7, N_F64, N_F32);
13198 CVT_VAR (8, N_S32, N_F64 | key);
13199 CVT_VAR (9, N_U32, N_F64 | key);
13200 CVT_VAR (10, N_F64 | key, N_S32);
13201 CVT_VAR (11, N_F64 | key, N_U32);
037e8744 13202 /* VFP instructions with bitshift. */
8e79c3df
CM
13203 CVT_VAR (12, N_F32 | key, N_S16);
13204 CVT_VAR (13, N_F32 | key, N_U16);
13205 CVT_VAR (14, N_F64 | key, N_S16);
13206 CVT_VAR (15, N_F64 | key, N_U16);
13207 CVT_VAR (16, N_S16, N_F32 | key);
13208 CVT_VAR (17, N_U16, N_F32 | key);
13209 CVT_VAR (18, N_S16, N_F64 | key);
13210 CVT_VAR (19, N_U16, N_F64 | key);
5f4273c7 13211
5287ad62
JB
13212 return -1;
13213#undef CVT_VAR
13214}
13215
037e8744
JB
13216/* Neon-syntax VFP conversions. */
13217
5287ad62 13218static void
037e8744 13219do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
5287ad62 13220{
037e8744 13221 const char *opname = 0;
5f4273c7 13222
037e8744 13223 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
5287ad62 13224 {
037e8744
JB
13225 /* Conversions with immediate bitshift. */
13226 const char *enc[] =
13227 {
13228 "ftosls",
13229 "ftouls",
13230 "fsltos",
13231 "fultos",
13232 NULL,
13233 NULL,
8e79c3df
CM
13234 NULL,
13235 NULL,
037e8744
JB
13236 "ftosld",
13237 "ftould",
13238 "fsltod",
13239 "fultod",
13240 "fshtos",
13241 "fuhtos",
13242 "fshtod",
13243 "fuhtod",
13244 "ftoshs",
13245 "ftouhs",
13246 "ftoshd",
13247 "ftouhd"
13248 };
13249
13250 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13251 {
13252 opname = enc[flavour];
13253 constraint (inst.operands[0].reg != inst.operands[1].reg,
13254 _("operands 0 and 1 must be the same register"));
13255 inst.operands[1] = inst.operands[2];
13256 memset (&inst.operands[2], '\0', sizeof (inst.operands[2]));
13257 }
5287ad62
JB
13258 }
13259 else
13260 {
037e8744
JB
13261 /* Conversions without bitshift. */
13262 const char *enc[] =
13263 {
13264 "ftosis",
13265 "ftouis",
13266 "fsitos",
13267 "fuitos",
8e79c3df
CM
13268 "NULL",
13269 "NULL",
037e8744
JB
13270 "fcvtsd",
13271 "fcvtds",
13272 "ftosid",
13273 "ftouid",
13274 "fsitod",
13275 "fuitod"
13276 };
13277
13278 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13279 opname = enc[flavour];
13280 }
13281
13282 if (opname)
13283 do_vfp_nsyn_opcode (opname);
13284}
13285
13286static void
13287do_vfp_nsyn_cvtz (void)
13288{
13289 enum neon_shape rs = neon_select_shape (NS_FF, NS_FD, NS_NULL);
13290 int flavour = neon_cvt_flavour (rs);
13291 const char *enc[] =
13292 {
13293 "ftosizs",
13294 "ftouizs",
13295 NULL,
13296 NULL,
13297 NULL,
13298 NULL,
8e79c3df
CM
13299 NULL,
13300 NULL,
037e8744
JB
13301 "ftosizd",
13302 "ftouizd"
13303 };
13304
13305 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13306 do_vfp_nsyn_opcode (enc[flavour]);
13307}
f31fef98 13308
037e8744
JB
13309static void
13310do_neon_cvt (void)
13311{
13312 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
8e79c3df 13313 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
037e8744
JB
13314 int flavour = neon_cvt_flavour (rs);
13315
13316 /* VFP rather than Neon conversions. */
8e79c3df 13317 if (flavour >= 6)
037e8744
JB
13318 {
13319 do_vfp_nsyn_cvt (rs, flavour);
13320 return;
13321 }
13322
13323 switch (rs)
13324 {
13325 case NS_DDI:
13326 case NS_QQI:
13327 {
35997600
NC
13328 unsigned immbits;
13329 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13330
037e8744
JB
13331 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13332 return;
13333
13334 /* Fixed-point conversion with #0 immediate is encoded as an
13335 integer conversion. */
13336 if (inst.operands[2].present && inst.operands[2].imm == 0)
13337 goto int_encode;
35997600 13338 immbits = 32 - inst.operands[2].imm;
037e8744
JB
13339 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13340 if (flavour != -1)
13341 inst.instruction |= enctab[flavour];
13342 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13343 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13344 inst.instruction |= LOW4 (inst.operands[1].reg);
13345 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13346 inst.instruction |= neon_quad (rs) << 6;
13347 inst.instruction |= 1 << 21;
13348 inst.instruction |= immbits << 16;
13349
13350 inst.instruction = neon_dp_fixup (inst.instruction);
13351 }
13352 break;
13353
13354 case NS_DD:
13355 case NS_QQ:
13356 int_encode:
13357 {
13358 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13359
13360 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13361
13362 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13363 return;
13364
13365 if (flavour != -1)
13366 inst.instruction |= enctab[flavour];
13367
13368 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13369 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13370 inst.instruction |= LOW4 (inst.operands[1].reg);
13371 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13372 inst.instruction |= neon_quad (rs) << 6;
13373 inst.instruction |= 2 << 18;
13374
13375 inst.instruction = neon_dp_fixup (inst.instruction);
13376 }
13377 break;
13378
8e79c3df
CM
13379 /* Half-precision conversions for Advanced SIMD -- neon. */
13380 case NS_QD:
13381 case NS_DQ:
13382
13383 if ((rs == NS_DQ)
13384 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13385 {
13386 as_bad (_("operand size must match register width"));
13387 break;
13388 }
13389
13390 if ((rs == NS_QD)
13391 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13392 {
13393 as_bad (_("operand size must match register width"));
13394 break;
13395 }
13396
13397 if (rs == NS_DQ)
13398 inst.instruction = 0x3b60600;
13399 else
13400 inst.instruction = 0x3b60700;
13401
13402 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13403 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13404 inst.instruction |= LOW4 (inst.operands[1].reg);
13405 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13406 inst.instruction = neon_dp_fixup (inst.instruction);
13407 break;
13408
037e8744
JB
13409 default:
13410 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13411 do_vfp_nsyn_cvt (rs, flavour);
5287ad62 13412 }
5287ad62
JB
13413}
13414
8e79c3df
CM
13415static void
13416do_neon_cvtb (void)
13417{
13418 inst.instruction = 0xeb20a40;
13419
13420 /* The sizes are attached to the mnemonic. */
13421 if (inst.vectype.el[0].type != NT_invtype
13422 && inst.vectype.el[0].size == 16)
13423 inst.instruction |= 0x00010000;
13424
13425 /* Programmer's syntax: the sizes are attached to the operands. */
13426 else if (inst.operands[0].vectype.type != NT_invtype
13427 && inst.operands[0].vectype.size == 16)
13428 inst.instruction |= 0x00010000;
13429
13430 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
13431 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
13432 do_vfp_cond_or_thumb ();
13433}
13434
13435
13436static void
13437do_neon_cvtt (void)
13438{
13439 do_neon_cvtb ();
13440 inst.instruction |= 0x80;
13441}
13442
5287ad62
JB
13443static void
13444neon_move_immediate (void)
13445{
037e8744
JB
13446 enum neon_shape rs = neon_select_shape (NS_DI, NS_QI, NS_NULL);
13447 struct neon_type_el et = neon_check_type (2, rs,
13448 N_I8 | N_I16 | N_I32 | N_I64 | N_F32 | N_KEY, N_EQK);
5287ad62 13449 unsigned immlo, immhi = 0, immbits;
c96612cc 13450 int op, cmode, float_p;
5287ad62 13451
037e8744
JB
13452 constraint (et.type == NT_invtype,
13453 _("operand size must be specified for immediate VMOV"));
13454
5287ad62
JB
13455 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13456 op = (inst.instruction & (1 << 5)) != 0;
13457
13458 immlo = inst.operands[1].imm;
13459 if (inst.operands[1].regisimm)
13460 immhi = inst.operands[1].reg;
13461
13462 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13463 _("immediate has bits set outside the operand size"));
13464
c96612cc
JB
13465 float_p = inst.operands[1].immisfloat;
13466
13467 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
136da414 13468 et.size, et.type)) == FAIL)
5287ad62
JB
13469 {
13470 /* Invert relevant bits only. */
13471 neon_invert_size (&immlo, &immhi, et.size);
13472 /* Flip from VMOV/VMVN to VMVN/VMOV. Some immediate types are unavailable
13473 with one or the other; those cases are caught by
13474 neon_cmode_for_move_imm. */
13475 op = !op;
c96612cc
JB
13476 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13477 &op, et.size, et.type)) == FAIL)
5287ad62 13478 {
dcbf9037 13479 first_error (_("immediate out of range"));
5287ad62
JB
13480 return;
13481 }
13482 }
13483
13484 inst.instruction &= ~(1 << 5);
13485 inst.instruction |= op << 5;
13486
13487 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13488 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
037e8744 13489 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13490 inst.instruction |= cmode << 8;
13491
13492 neon_write_immbits (immbits);
13493}
13494
13495static void
13496do_neon_mvn (void)
13497{
13498 if (inst.operands[1].isreg)
13499 {
037e8744 13500 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5f4273c7 13501
5287ad62
JB
13502 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13503 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13504 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13505 inst.instruction |= LOW4 (inst.operands[1].reg);
13506 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
037e8744 13507 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13508 }
13509 else
13510 {
13511 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13512 neon_move_immediate ();
13513 }
13514
13515 inst.instruction = neon_dp_fixup (inst.instruction);
13516}
13517
13518/* Encode instructions of form:
13519
13520 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
5f4273c7 13521 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
5287ad62
JB
13522
13523static void
13524neon_mixed_length (struct neon_type_el et, unsigned size)
13525{
13526 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13527 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13528 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13529 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13530 inst.instruction |= LOW4 (inst.operands[2].reg);
13531 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13532 inst.instruction |= (et.type == NT_unsigned) << 24;
13533 inst.instruction |= neon_logbits (size) << 20;
5f4273c7 13534
5287ad62
JB
13535 inst.instruction = neon_dp_fixup (inst.instruction);
13536}
13537
13538static void
13539do_neon_dyadic_long (void)
13540{
13541 /* FIXME: Type checking for lengthening op. */
13542 struct neon_type_el et = neon_check_type (3, NS_QDD,
13543 N_EQK | N_DBL, N_EQK, N_SU_32 | N_KEY);
13544 neon_mixed_length (et, et.size);
13545}
13546
13547static void
13548do_neon_abal (void)
13549{
13550 struct neon_type_el et = neon_check_type (3, NS_QDD,
13551 N_EQK | N_INT | N_DBL, N_EQK, N_SU_32 | N_KEY);
13552 neon_mixed_length (et, et.size);
13553}
13554
13555static void
13556neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13557{
13558 if (inst.operands[2].isscalar)
13559 {
dcbf9037
JB
13560 struct neon_type_el et = neon_check_type (3, NS_QDS,
13561 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
5287ad62
JB
13562 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13563 neon_mul_mac (et, et.type == NT_unsigned);
13564 }
13565 else
13566 {
13567 struct neon_type_el et = neon_check_type (3, NS_QDD,
13568 N_EQK | N_DBL, N_EQK, scalartypes | N_KEY);
13569 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13570 neon_mixed_length (et, et.size);
13571 }
13572}
13573
13574static void
13575do_neon_mac_maybe_scalar_long (void)
13576{
13577 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13578}
13579
13580static void
13581do_neon_dyadic_wide (void)
13582{
13583 struct neon_type_el et = neon_check_type (3, NS_QQD,
13584 N_EQK | N_DBL, N_EQK | N_DBL, N_SU_32 | N_KEY);
13585 neon_mixed_length (et, et.size);
13586}
13587
13588static void
13589do_neon_dyadic_narrow (void)
13590{
13591 struct neon_type_el et = neon_check_type (3, NS_QDD,
13592 N_EQK | N_DBL, N_EQK, N_I16 | N_I32 | N_I64 | N_KEY);
428e3f1f
PB
13593 /* Operand sign is unimportant, and the U bit is part of the opcode,
13594 so force the operand type to integer. */
13595 et.type = NT_integer;
5287ad62
JB
13596 neon_mixed_length (et, et.size / 2);
13597}
13598
13599static void
13600do_neon_mul_sat_scalar_long (void)
13601{
13602 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13603}
13604
13605static void
13606do_neon_vmull (void)
13607{
13608 if (inst.operands[2].isscalar)
13609 do_neon_mac_maybe_scalar_long ();
13610 else
13611 {
13612 struct neon_type_el et = neon_check_type (3, NS_QDD,
13613 N_EQK | N_DBL, N_EQK, N_SU_32 | N_P8 | N_KEY);
13614 if (et.type == NT_poly)
13615 inst.instruction = NEON_ENC_POLY (inst.instruction);
13616 else
13617 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13618 /* For polynomial encoding, size field must be 0b00 and the U bit must be
13619 zero. Should be OK as-is. */
13620 neon_mixed_length (et, et.size);
13621 }
13622}
13623
13624static void
13625do_neon_ext (void)
13626{
037e8744 13627 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
5287ad62
JB
13628 struct neon_type_el et = neon_check_type (3, rs,
13629 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_64 | N_KEY);
13630 unsigned imm = (inst.operands[3].imm * et.size) / 8;
35997600
NC
13631
13632 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13633 _("shift out of range"));
5287ad62
JB
13634 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13635 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13636 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13637 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13638 inst.instruction |= LOW4 (inst.operands[2].reg);
13639 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
037e8744 13640 inst.instruction |= neon_quad (rs) << 6;
5287ad62 13641 inst.instruction |= imm << 8;
5f4273c7 13642
5287ad62
JB
13643 inst.instruction = neon_dp_fixup (inst.instruction);
13644}
13645
13646static void
13647do_neon_rev (void)
13648{
037e8744 13649 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13650 struct neon_type_el et = neon_check_type (2, rs,
13651 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13652 unsigned op = (inst.instruction >> 7) & 3;
13653 /* N (width of reversed regions) is encoded as part of the bitmask. We
13654 extract it here to check the elements to be reversed are smaller.
13655 Otherwise we'd get a reserved instruction. */
13656 unsigned elsize = (op == 2) ? 16 : (op == 1) ? 32 : (op == 0) ? 64 : 0;
9c2799c2 13657 gas_assert (elsize != 0);
5287ad62
JB
13658 constraint (et.size >= elsize,
13659 _("elements must be smaller than reversal region"));
037e8744 13660 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
13661}
13662
13663static void
13664do_neon_dup (void)
13665{
13666 if (inst.operands[1].isscalar)
13667 {
037e8744 13668 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
dcbf9037
JB
13669 struct neon_type_el et = neon_check_type (2, rs,
13670 N_EQK, N_8 | N_16 | N_32 | N_KEY);
5287ad62 13671 unsigned sizebits = et.size >> 3;
dcbf9037 13672 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
5287ad62 13673 int logsize = neon_logbits (et.size);
dcbf9037 13674 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
037e8744
JB
13675
13676 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13677 return;
13678
5287ad62
JB
13679 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13680 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13681 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13682 inst.instruction |= LOW4 (dm);
13683 inst.instruction |= HI1 (dm) << 5;
037e8744 13684 inst.instruction |= neon_quad (rs) << 6;
5287ad62
JB
13685 inst.instruction |= x << 17;
13686 inst.instruction |= sizebits << 16;
5f4273c7 13687
5287ad62
JB
13688 inst.instruction = neon_dp_fixup (inst.instruction);
13689 }
13690 else
13691 {
037e8744
JB
13692 enum neon_shape rs = neon_select_shape (NS_DR, NS_QR, NS_NULL);
13693 struct neon_type_el et = neon_check_type (2, rs,
13694 N_8 | N_16 | N_32 | N_KEY, N_EQK);
5287ad62
JB
13695 /* Duplicate ARM register to lanes of vector. */
13696 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13697 switch (et.size)
13698 {
13699 case 8: inst.instruction |= 0x400000; break;
13700 case 16: inst.instruction |= 0x000020; break;
13701 case 32: inst.instruction |= 0x000000; break;
13702 default: break;
13703 }
13704 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
13705 inst.instruction |= LOW4 (inst.operands[0].reg) << 16;
13706 inst.instruction |= HI1 (inst.operands[0].reg) << 7;
037e8744 13707 inst.instruction |= neon_quad (rs) << 21;
5287ad62
JB
13708 /* The encoding for this instruction is identical for the ARM and Thumb
13709 variants, except for the condition field. */
037e8744 13710 do_vfp_cond_or_thumb ();
5287ad62
JB
13711 }
13712}
13713
13714/* VMOV has particularly many variations. It can be one of:
13715 0. VMOV<c><q> <Qd>, <Qm>
13716 1. VMOV<c><q> <Dd>, <Dm>
13717 (Register operations, which are VORR with Rm = Rn.)
13718 2. VMOV<c><q>.<dt> <Qd>, #<imm>
13719 3. VMOV<c><q>.<dt> <Dd>, #<imm>
13720 (Immediate loads.)
13721 4. VMOV<c><q>.<size> <Dn[x]>, <Rd>
13722 (ARM register to scalar.)
13723 5. VMOV<c><q> <Dm>, <Rd>, <Rn>
13724 (Two ARM registers to vector.)
13725 6. VMOV<c><q>.<dt> <Rd>, <Dn[x]>
13726 (Scalar to ARM register.)
13727 7. VMOV<c><q> <Rd>, <Rn>, <Dm>
13728 (Vector to two ARM registers.)
037e8744
JB
13729 8. VMOV.F32 <Sd>, <Sm>
13730 9. VMOV.F64 <Dd>, <Dm>
13731 (VFP register moves.)
13732 10. VMOV.F32 <Sd>, #imm
13733 11. VMOV.F64 <Dd>, #imm
13734 (VFP float immediate load.)
13735 12. VMOV <Rd>, <Sm>
13736 (VFP single to ARM reg.)
13737 13. VMOV <Sd>, <Rm>
13738 (ARM reg to VFP single.)
13739 14. VMOV <Rd>, <Re>, <Sn>, <Sm>
13740 (Two ARM regs to two VFP singles.)
13741 15. VMOV <Sd>, <Se>, <Rn>, <Rm>
13742 (Two VFP singles to two ARM regs.)
5f4273c7 13743
037e8744
JB
13744 These cases can be disambiguated using neon_select_shape, except cases 1/9
13745 and 3/11 which depend on the operand type too.
5f4273c7 13746
5287ad62 13747 All the encoded bits are hardcoded by this function.
5f4273c7 13748
b7fc2769
JB
13749 Cases 4, 6 may be used with VFPv1 and above (only 32-bit transfers!).
13750 Cases 5, 7 may be used with VFPv2 and above.
5f4273c7 13751
5287ad62 13752 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
5f4273c7 13753 can specify a type where it doesn't make sense to, and is ignored). */
5287ad62
JB
13754
13755static void
13756do_neon_mov (void)
13757{
037e8744
JB
13758 enum neon_shape rs = neon_select_shape (NS_RRFF, NS_FFRR, NS_DRR, NS_RRD,
13759 NS_QQ, NS_DD, NS_QI, NS_DI, NS_SR, NS_RS, NS_FF, NS_FI, NS_RF, NS_FR,
13760 NS_NULL);
13761 struct neon_type_el et;
13762 const char *ldconst = 0;
5287ad62 13763
037e8744 13764 switch (rs)
5287ad62 13765 {
037e8744
JB
13766 case NS_DD: /* case 1/9. */
13767 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13768 /* It is not an error here if no type is given. */
13769 inst.error = NULL;
13770 if (et.type == NT_float && et.size == 64)
5287ad62 13771 {
037e8744
JB
13772 do_vfp_nsyn_opcode ("fcpyd");
13773 break;
5287ad62 13774 }
037e8744 13775 /* fall through. */
5287ad62 13776
037e8744
JB
13777 case NS_QQ: /* case 0/1. */
13778 {
13779 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13780 return;
13781 /* The architecture manual I have doesn't explicitly state which
13782 value the U bit should have for register->register moves, but
13783 the equivalent VORR instruction has U = 0, so do that. */
13784 inst.instruction = 0x0200110;
13785 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13786 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13787 inst.instruction |= LOW4 (inst.operands[1].reg);
13788 inst.instruction |= HI1 (inst.operands[1].reg) << 5;
13789 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
13790 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
13791 inst.instruction |= neon_quad (rs) << 6;
13792
13793 inst.instruction = neon_dp_fixup (inst.instruction);
13794 }
13795 break;
5f4273c7 13796
037e8744
JB
13797 case NS_DI: /* case 3/11. */
13798 et = neon_check_type (2, rs, N_EQK, N_F64 | N_KEY);
13799 inst.error = NULL;
13800 if (et.type == NT_float && et.size == 64)
5287ad62 13801 {
037e8744
JB
13802 /* case 11 (fconstd). */
13803 ldconst = "fconstd";
13804 goto encode_fconstd;
5287ad62 13805 }
037e8744
JB
13806 /* fall through. */
13807
13808 case NS_QI: /* case 2/3. */
13809 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13810 return;
13811 inst.instruction = 0x0800010;
13812 neon_move_immediate ();
13813 inst.instruction = neon_dp_fixup (inst.instruction);
5287ad62 13814 break;
5f4273c7 13815
037e8744
JB
13816 case NS_SR: /* case 4. */
13817 {
13818 unsigned bcdebits = 0;
13819 struct neon_type_el et = neon_check_type (2, NS_NULL,
13820 N_8 | N_16 | N_32 | N_KEY, N_EQK);
13821 int logsize = neon_logbits (et.size);
13822 unsigned dn = NEON_SCALAR_REG (inst.operands[0].reg);
13823 unsigned x = NEON_SCALAR_INDEX (inst.operands[0].reg);
13824
13825 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13826 _(BAD_FPU));
13827 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13828 && et.size != 32, _(BAD_FPU));
13829 constraint (et.type == NT_invtype, _("bad type for scalar"));
13830 constraint (x >= 64 / et.size, _("scalar index out of range"));
13831
13832 switch (et.size)
13833 {
13834 case 8: bcdebits = 0x8; break;
13835 case 16: bcdebits = 0x1; break;
13836 case 32: bcdebits = 0x0; break;
13837 default: ;
13838 }
13839
13840 bcdebits |= x << logsize;
13841
13842 inst.instruction = 0xe000b10;
13843 do_vfp_cond_or_thumb ();
13844 inst.instruction |= LOW4 (dn) << 16;
13845 inst.instruction |= HI1 (dn) << 7;
13846 inst.instruction |= inst.operands[1].reg << 12;
13847 inst.instruction |= (bcdebits & 3) << 5;
13848 inst.instruction |= (bcdebits >> 2) << 21;
13849 }
13850 break;
5f4273c7 13851
037e8744 13852 case NS_DRR: /* case 5 (fmdrr). */
b7fc2769 13853 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
037e8744 13854 _(BAD_FPU));
b7fc2769 13855
037e8744
JB
13856 inst.instruction = 0xc400b10;
13857 do_vfp_cond_or_thumb ();
13858 inst.instruction |= LOW4 (inst.operands[0].reg);
13859 inst.instruction |= HI1 (inst.operands[0].reg) << 5;
13860 inst.instruction |= inst.operands[1].reg << 12;
13861 inst.instruction |= inst.operands[2].reg << 16;
13862 break;
5f4273c7 13863
037e8744
JB
13864 case NS_RS: /* case 6. */
13865 {
13866 struct neon_type_el et = neon_check_type (2, NS_NULL,
13867 N_EQK, N_S8 | N_S16 | N_U8 | N_U16 | N_32 | N_KEY);
13868 unsigned logsize = neon_logbits (et.size);
13869 unsigned dn = NEON_SCALAR_REG (inst.operands[1].reg);
13870 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg);
13871 unsigned abcdebits = 0;
13872
13873 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v1),
13874 _(BAD_FPU));
13875 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1)
13876 && et.size != 32, _(BAD_FPU));
13877 constraint (et.type == NT_invtype, _("bad type for scalar"));
13878 constraint (x >= 64 / et.size, _("scalar index out of range"));
13879
13880 switch (et.size)
13881 {
13882 case 8: abcdebits = (et.type == NT_signed) ? 0x08 : 0x18; break;
13883 case 16: abcdebits = (et.type == NT_signed) ? 0x01 : 0x11; break;
13884 case 32: abcdebits = 0x00; break;
13885 default: ;
13886 }
13887
13888 abcdebits |= x << logsize;
13889 inst.instruction = 0xe100b10;
13890 do_vfp_cond_or_thumb ();
13891 inst.instruction |= LOW4 (dn) << 16;
13892 inst.instruction |= HI1 (dn) << 7;
13893 inst.instruction |= inst.operands[0].reg << 12;
13894 inst.instruction |= (abcdebits & 3) << 5;
13895 inst.instruction |= (abcdebits >> 2) << 21;
13896 }
13897 break;
5f4273c7 13898
037e8744
JB
13899 case NS_RRD: /* case 7 (fmrrd). */
13900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13901 _(BAD_FPU));
13902
13903 inst.instruction = 0xc500b10;
13904 do_vfp_cond_or_thumb ();
13905 inst.instruction |= inst.operands[0].reg << 12;
13906 inst.instruction |= inst.operands[1].reg << 16;
13907 inst.instruction |= LOW4 (inst.operands[2].reg);
13908 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
13909 break;
5f4273c7 13910
037e8744
JB
13911 case NS_FF: /* case 8 (fcpys). */
13912 do_vfp_nsyn_opcode ("fcpys");
13913 break;
5f4273c7 13914
037e8744
JB
13915 case NS_FI: /* case 10 (fconsts). */
13916 ldconst = "fconsts";
13917 encode_fconstd:
13918 if (is_quarter_float (inst.operands[1].imm))
5287ad62 13919 {
037e8744
JB
13920 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13921 do_vfp_nsyn_opcode (ldconst);
5287ad62
JB
13922 }
13923 else
037e8744
JB
13924 first_error (_("immediate out of range"));
13925 break;
5f4273c7 13926
037e8744
JB
13927 case NS_RF: /* case 12 (fmrs). */
13928 do_vfp_nsyn_opcode ("fmrs");
13929 break;
5f4273c7 13930
037e8744
JB
13931 case NS_FR: /* case 13 (fmsr). */
13932 do_vfp_nsyn_opcode ("fmsr");
13933 break;
5f4273c7 13934
037e8744
JB
13935 /* The encoders for the fmrrs and fmsrr instructions expect three operands
13936 (one of which is a list), but we have parsed four. Do some fiddling to
13937 make the operands what do_vfp_reg2_from_sp2 and do_vfp_sp2_from_reg2
13938 expect. */
13939 case NS_RRFF: /* case 14 (fmrrs). */
13940 constraint (inst.operands[3].reg != inst.operands[2].reg + 1,
13941 _("VFP registers must be adjacent"));
13942 inst.operands[2].imm = 2;
13943 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13944 do_vfp_nsyn_opcode ("fmrrs");
13945 break;
5f4273c7 13946
037e8744
JB
13947 case NS_FFRR: /* case 15 (fmsrr). */
13948 constraint (inst.operands[1].reg != inst.operands[0].reg + 1,
13949 _("VFP registers must be adjacent"));
13950 inst.operands[1] = inst.operands[2];
13951 inst.operands[2] = inst.operands[3];
13952 inst.operands[0].imm = 2;
13953 memset (&inst.operands[3], '\0', sizeof (inst.operands[3]));
13954 do_vfp_nsyn_opcode ("fmsrr");
5287ad62 13955 break;
5f4273c7 13956
5287ad62
JB
13957 default:
13958 abort ();
13959 }
13960}
13961
13962static void
13963do_neon_rshift_round_imm (void)
13964{
037e8744 13965 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
5287ad62
JB
13966 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
13967 int imm = inst.operands[2].imm;
13968
13969 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13970 if (imm == 0)
13971 {
13972 inst.operands[2].present = 0;
13973 do_neon_mov ();
13974 return;
13975 }
13976
13977 constraint (imm < 1 || (unsigned)imm > et.size,
13978 _("immediate out of range for shift"));
037e8744 13979 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
5287ad62
JB
13980 et.size - imm);
13981}
13982
13983static void
13984do_neon_movl (void)
13985{
13986 struct neon_type_el et = neon_check_type (2, NS_QD,
13987 N_EQK | N_DBL, N_SU_32 | N_KEY);
13988 unsigned sizebits = et.size >> 3;
13989 inst.instruction |= sizebits << 19;
13990 neon_two_same (0, et.type == NT_unsigned, -1);
13991}
13992
13993static void
13994do_neon_trn (void)
13995{
037e8744 13996 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
13997 struct neon_type_el et = neon_check_type (2, rs,
13998 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13999 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
037e8744 14000 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14001}
14002
14003static void
14004do_neon_zip_uzp (void)
14005{
037e8744 14006 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14007 struct neon_type_el et = neon_check_type (2, rs,
14008 N_EQK, N_8 | N_16 | N_32 | N_KEY);
14009 if (rs == NS_DD && et.size == 32)
14010 {
14011 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14012 inst.instruction = N_MNEM_vtrn;
14013 do_neon_trn ();
14014 return;
14015 }
037e8744 14016 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14017}
14018
14019static void
14020do_neon_sat_abs_neg (void)
14021{
037e8744 14022 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14023 struct neon_type_el et = neon_check_type (2, rs,
14024 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14025 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14026}
14027
14028static void
14029do_neon_pair_long (void)
14030{
037e8744 14031 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14032 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_32 | N_KEY);
14033 /* Unsigned is encoded in OP field (bit 7) for these instruction. */
14034 inst.instruction |= (et.type == NT_unsigned) << 7;
037e8744 14035 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14036}
14037
14038static void
14039do_neon_recip_est (void)
14040{
037e8744 14041 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14042 struct neon_type_el et = neon_check_type (2, rs,
14043 N_EQK | N_FLT, N_F32 | N_U32 | N_KEY);
14044 inst.instruction |= (et.type == NT_float) << 8;
037e8744 14045 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14046}
14047
14048static void
14049do_neon_cls (void)
14050{
037e8744 14051 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14052 struct neon_type_el et = neon_check_type (2, rs,
14053 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
037e8744 14054 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14055}
14056
14057static void
14058do_neon_clz (void)
14059{
037e8744 14060 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14061 struct neon_type_el et = neon_check_type (2, rs,
14062 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
037e8744 14063 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14064}
14065
14066static void
14067do_neon_cnt (void)
14068{
037e8744 14069 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
5287ad62
JB
14070 struct neon_type_el et = neon_check_type (2, rs,
14071 N_EQK | N_INT, N_8 | N_KEY);
037e8744 14072 neon_two_same (neon_quad (rs), 1, et.size);
5287ad62
JB
14073}
14074
14075static void
14076do_neon_swp (void)
14077{
037e8744
JB
14078 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14079 neon_two_same (neon_quad (rs), 1, -1);
5287ad62
JB
14080}
14081
14082static void
14083do_neon_tbl_tbx (void)
14084{
14085 unsigned listlenbits;
dcbf9037 14086 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
5f4273c7 14087
5287ad62
JB
14088 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14089 {
dcbf9037 14090 first_error (_("bad list length for table lookup"));
5287ad62
JB
14091 return;
14092 }
5f4273c7 14093
5287ad62
JB
14094 listlenbits = inst.operands[1].imm - 1;
14095 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14096 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14097 inst.instruction |= LOW4 (inst.operands[1].reg) << 16;
14098 inst.instruction |= HI1 (inst.operands[1].reg) << 7;
14099 inst.instruction |= LOW4 (inst.operands[2].reg);
14100 inst.instruction |= HI1 (inst.operands[2].reg) << 5;
14101 inst.instruction |= listlenbits << 8;
5f4273c7 14102
5287ad62
JB
14103 inst.instruction = neon_dp_fixup (inst.instruction);
14104}
14105
14106static void
14107do_neon_ldm_stm (void)
14108{
14109 /* P, U and L bits are part of bitmask. */
14110 int is_dbmode = (inst.instruction & (1 << 24)) != 0;
14111 unsigned offsetbits = inst.operands[1].imm * 2;
14112
037e8744
JB
14113 if (inst.operands[1].issingle)
14114 {
14115 do_vfp_nsyn_ldm_stm (is_dbmode);
14116 return;
14117 }
14118
5287ad62
JB
14119 constraint (is_dbmode && !inst.operands[0].writeback,
14120 _("writeback (!) must be used for VLDMDB and VSTMDB"));
14121
14122 constraint (inst.operands[1].imm < 1 || inst.operands[1].imm > 16,
14123 _("register list must contain at least 1 and at most 16 "
14124 "registers"));
14125
14126 inst.instruction |= inst.operands[0].reg << 16;
14127 inst.instruction |= inst.operands[0].writeback << 21;
14128 inst.instruction |= LOW4 (inst.operands[1].reg) << 12;
14129 inst.instruction |= HI1 (inst.operands[1].reg) << 22;
14130
14131 inst.instruction |= offsetbits;
5f4273c7 14132
037e8744 14133 do_vfp_cond_or_thumb ();
5287ad62
JB
14134}
14135
14136static void
14137do_neon_ldr_str (void)
14138{
5287ad62 14139 int is_ldr = (inst.instruction & (1 << 20)) != 0;
5f4273c7 14140
037e8744
JB
14141 if (inst.operands[0].issingle)
14142 {
cd2f129f
JB
14143 if (is_ldr)
14144 do_vfp_nsyn_opcode ("flds");
14145 else
14146 do_vfp_nsyn_opcode ("fsts");
5287ad62
JB
14147 }
14148 else
5287ad62 14149 {
cd2f129f
JB
14150 if (is_ldr)
14151 do_vfp_nsyn_opcode ("fldd");
5287ad62 14152 else
cd2f129f 14153 do_vfp_nsyn_opcode ("fstd");
5287ad62 14154 }
5287ad62
JB
14155}
14156
14157/* "interleave" version also handles non-interleaving register VLD1/VST1
14158 instructions. */
14159
14160static void
14161do_neon_ld_st_interleave (void)
14162{
037e8744 14163 struct neon_type_el et = neon_check_type (1, NS_NULL,
5287ad62
JB
14164 N_8 | N_16 | N_32 | N_64);
14165 unsigned alignbits = 0;
14166 unsigned idx;
14167 /* The bits in this table go:
14168 0: register stride of one (0) or two (1)
14169 1,2: register list length, minus one (1, 2, 3, 4).
14170 3,4: <n> in instruction type, minus one (VLD<n> / VST<n>).
14171 We use -1 for invalid entries. */
14172 const int typetable[] =
14173 {
14174 0x7, -1, 0xa, -1, 0x6, -1, 0x2, -1, /* VLD1 / VST1. */
14175 -1, -1, 0x8, 0x9, -1, -1, 0x3, -1, /* VLD2 / VST2. */
14176 -1, -1, -1, -1, 0x4, 0x5, -1, -1, /* VLD3 / VST3. */
14177 -1, -1, -1, -1, -1, -1, 0x0, 0x1 /* VLD4 / VST4. */
14178 };
14179 int typebits;
14180
dcbf9037
JB
14181 if (et.type == NT_invtype)
14182 return;
14183
5287ad62
JB
14184 if (inst.operands[1].immisalign)
14185 switch (inst.operands[1].imm >> 8)
14186 {
14187 case 64: alignbits = 1; break;
14188 case 128:
14189 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14190 goto bad_alignment;
14191 alignbits = 2;
14192 break;
14193 case 256:
14194 if (NEON_REGLIST_LENGTH (inst.operands[0].imm) == 3)
14195 goto bad_alignment;
14196 alignbits = 3;
14197 break;
14198 default:
14199 bad_alignment:
dcbf9037 14200 first_error (_("bad alignment"));
5287ad62
JB
14201 return;
14202 }
14203
14204 inst.instruction |= alignbits << 4;
14205 inst.instruction |= neon_logbits (et.size) << 6;
14206
14207 /* Bits [4:6] of the immediate in a list specifier encode register stride
14208 (minus 1) in bit 4, and list length in bits [5:6]. We put the <n> of
14209 VLD<n>/VST<n> in bits [9:8] of the initial bitmask. Suck it out here, look
14210 up the right value for "type" in a table based on this value and the given
14211 list style, then stick it back. */
14212 idx = ((inst.operands[0].imm >> 4) & 7)
14213 | (((inst.instruction >> 8) & 3) << 3);
14214
14215 typebits = typetable[idx];
5f4273c7 14216
5287ad62
JB
14217 constraint (typebits == -1, _("bad list type for instruction"));
14218
14219 inst.instruction &= ~0xf00;
14220 inst.instruction |= typebits << 8;
14221}
14222
14223/* Check alignment is valid for do_neon_ld_st_lane and do_neon_ld_dup.
14224 *DO_ALIGN is set to 1 if the relevant alignment bit should be set, 0
14225 otherwise. The variable arguments are a list of pairs of legal (size, align)
14226 values, terminated with -1. */
14227
14228static int
14229neon_alignment_bit (int size, int align, int *do_align, ...)
14230{
14231 va_list ap;
14232 int result = FAIL, thissize, thisalign;
5f4273c7 14233
5287ad62
JB
14234 if (!inst.operands[1].immisalign)
14235 {
14236 *do_align = 0;
14237 return SUCCESS;
14238 }
5f4273c7 14239
5287ad62
JB
14240 va_start (ap, do_align);
14241
14242 do
14243 {
14244 thissize = va_arg (ap, int);
14245 if (thissize == -1)
14246 break;
14247 thisalign = va_arg (ap, int);
14248
14249 if (size == thissize && align == thisalign)
14250 result = SUCCESS;
14251 }
14252 while (result != SUCCESS);
14253
14254 va_end (ap);
14255
14256 if (result == SUCCESS)
14257 *do_align = 1;
14258 else
dcbf9037 14259 first_error (_("unsupported alignment for instruction"));
5f4273c7 14260
5287ad62
JB
14261 return result;
14262}
14263
14264static void
14265do_neon_ld_st_lane (void)
14266{
037e8744 14267 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14268 int align_good, do_align = 0;
14269 int logsize = neon_logbits (et.size);
14270 int align = inst.operands[1].imm >> 8;
14271 int n = (inst.instruction >> 8) & 3;
14272 int max_el = 64 / et.size;
5f4273c7 14273
dcbf9037
JB
14274 if (et.type == NT_invtype)
14275 return;
5f4273c7 14276
5287ad62
JB
14277 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != n + 1,
14278 _("bad list length"));
14279 constraint (NEON_LANE (inst.operands[0].imm) >= max_el,
14280 _("scalar index out of range"));
14281 constraint (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2
14282 && et.size == 8,
14283 _("stride of 2 unavailable when element size is 8"));
5f4273c7 14284
5287ad62
JB
14285 switch (n)
14286 {
14287 case 0: /* VLD1 / VST1. */
14288 align_good = neon_alignment_bit (et.size, align, &do_align, 16, 16,
14289 32, 32, -1);
14290 if (align_good == FAIL)
14291 return;
14292 if (do_align)
14293 {
14294 unsigned alignbits = 0;
14295 switch (et.size)
14296 {
14297 case 16: alignbits = 0x1; break;
14298 case 32: alignbits = 0x3; break;
14299 default: ;
14300 }
14301 inst.instruction |= alignbits << 4;
14302 }
14303 break;
14304
14305 case 1: /* VLD2 / VST2. */
14306 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 16, 16, 32,
14307 32, 64, -1);
14308 if (align_good == FAIL)
14309 return;
14310 if (do_align)
14311 inst.instruction |= 1 << 4;
14312 break;
14313
14314 case 2: /* VLD3 / VST3. */
14315 constraint (inst.operands[1].immisalign,
14316 _("can't use alignment with this instruction"));
14317 break;
14318
14319 case 3: /* VLD4 / VST4. */
14320 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14321 16, 64, 32, 64, 32, 128, -1);
14322 if (align_good == FAIL)
14323 return;
14324 if (do_align)
14325 {
14326 unsigned alignbits = 0;
14327 switch (et.size)
14328 {
14329 case 8: alignbits = 0x1; break;
14330 case 16: alignbits = 0x1; break;
14331 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14332 default: ;
14333 }
14334 inst.instruction |= alignbits << 4;
14335 }
14336 break;
14337
14338 default: ;
14339 }
14340
14341 /* Reg stride of 2 is encoded in bit 5 when size==16, bit 6 when size==32. */
14342 if (n != 0 && NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14343 inst.instruction |= 1 << (4 + logsize);
5f4273c7 14344
5287ad62
JB
14345 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14346 inst.instruction |= logsize << 10;
14347}
14348
14349/* Encode single n-element structure to all lanes VLD<n> instructions. */
14350
14351static void
14352do_neon_ld_dup (void)
14353{
037e8744 14354 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
5287ad62
JB
14355 int align_good, do_align = 0;
14356
dcbf9037
JB
14357 if (et.type == NT_invtype)
14358 return;
14359
5287ad62
JB
14360 switch ((inst.instruction >> 8) & 3)
14361 {
14362 case 0: /* VLD1. */
9c2799c2 14363 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
5287ad62
JB
14364 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14365 &do_align, 16, 16, 32, 32, -1);
14366 if (align_good == FAIL)
14367 return;
14368 switch (NEON_REGLIST_LENGTH (inst.operands[0].imm))
14369 {
14370 case 1: break;
14371 case 2: inst.instruction |= 1 << 5; break;
dcbf9037 14372 default: first_error (_("bad list length")); return;
5287ad62
JB
14373 }
14374 inst.instruction |= neon_logbits (et.size) << 6;
14375 break;
14376
14377 case 1: /* VLD2. */
14378 align_good = neon_alignment_bit (et.size, inst.operands[1].imm >> 8,
14379 &do_align, 8, 16, 16, 32, 32, 64, -1);
14380 if (align_good == FAIL)
14381 return;
14382 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 2,
14383 _("bad list length"));
14384 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14385 inst.instruction |= 1 << 5;
14386 inst.instruction |= neon_logbits (et.size) << 6;
14387 break;
14388
14389 case 2: /* VLD3. */
14390 constraint (inst.operands[1].immisalign,
14391 _("can't use alignment with this instruction"));
14392 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 3,
14393 _("bad list length"));
14394 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14395 inst.instruction |= 1 << 5;
14396 inst.instruction |= neon_logbits (et.size) << 6;
14397 break;
14398
14399 case 3: /* VLD4. */
14400 {
14401 int align = inst.operands[1].imm >> 8;
14402 align_good = neon_alignment_bit (et.size, align, &do_align, 8, 32,
14403 16, 64, 32, 64, 32, 128, -1);
14404 if (align_good == FAIL)
14405 return;
14406 constraint (NEON_REGLIST_LENGTH (inst.operands[0].imm) != 4,
14407 _("bad list length"));
14408 if (NEON_REG_STRIDE (inst.operands[0].imm) == 2)
14409 inst.instruction |= 1 << 5;
14410 if (et.size == 32 && align == 128)
14411 inst.instruction |= 0x3 << 6;
14412 else
14413 inst.instruction |= neon_logbits (et.size) << 6;
14414 }
14415 break;
14416
14417 default: ;
14418 }
14419
14420 inst.instruction |= do_align << 4;
14421}
14422
14423/* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14424 apart from bits [11:4]. */
14425
14426static void
14427do_neon_ldx_stx (void)
14428{
14429 switch (NEON_LANE (inst.operands[0].imm))
14430 {
14431 case NEON_INTERLEAVE_LANES:
14432 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14433 do_neon_ld_st_interleave ();
14434 break;
5f4273c7 14435
5287ad62
JB
14436 case NEON_ALL_LANES:
14437 inst.instruction = NEON_ENC_DUP (inst.instruction);
14438 do_neon_ld_dup ();
14439 break;
5f4273c7 14440
5287ad62
JB
14441 default:
14442 inst.instruction = NEON_ENC_LANE (inst.instruction);
14443 do_neon_ld_st_lane ();
14444 }
14445
14446 /* L bit comes from bit mask. */
14447 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
14448 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
14449 inst.instruction |= inst.operands[1].reg << 16;
5f4273c7 14450
5287ad62
JB
14451 if (inst.operands[1].postind)
14452 {
14453 int postreg = inst.operands[1].imm & 0xf;
14454 constraint (!inst.operands[1].immisreg,
14455 _("post-index must be a register"));
14456 constraint (postreg == 0xd || postreg == 0xf,
14457 _("bad register for post-index"));
14458 inst.instruction |= postreg;
14459 }
14460 else if (inst.operands[1].writeback)
14461 {
14462 inst.instruction |= 0xd;
14463 }
14464 else
5f4273c7
NC
14465 inst.instruction |= 0xf;
14466
5287ad62
JB
14467 if (thumb_mode)
14468 inst.instruction |= 0xf9000000;
14469 else
14470 inst.instruction |= 0xf4000000;
14471}
5287ad62
JB
14472\f
14473/* Overall per-instruction processing. */
14474
14475/* We need to be able to fix up arbitrary expressions in some statements.
14476 This is so that we can handle symbols that are an arbitrary distance from
14477 the pc. The most common cases are of the form ((+/-sym -/+ . - 8) & mask),
14478 which returns part of an address in a form which will be valid for
14479 a data instruction. We do this by pushing the expression into a symbol
14480 in the expr_section, and creating a fix for that. */
14481
14482static void
14483fix_new_arm (fragS * frag,
14484 int where,
14485 short int size,
14486 expressionS * exp,
14487 int pc_rel,
14488 int reloc)
14489{
14490 fixS * new_fix;
14491
14492 switch (exp->X_op)
14493 {
14494 case O_constant:
14495 case O_symbol:
14496 case O_add:
14497 case O_subtract:
14498 new_fix = fix_new_exp (frag, where, size, exp, pc_rel, reloc);
14499 break;
14500
14501 default:
14502 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14503 pc_rel, reloc);
14504 break;
14505 }
14506
14507 /* Mark whether the fix is to a THUMB instruction, or an ARM
14508 instruction. */
14509 new_fix->tc_fix_data = thumb_mode;
14510}
14511
14512/* Create a frg for an instruction requiring relaxation. */
14513static void
14514output_relax_insn (void)
14515{
14516 char * to;
14517 symbolS *sym;
0110f2b8
PB
14518 int offset;
14519
6e1cb1a6
PB
14520 /* The size of the instruction is unknown, so tie the debug info to the
14521 start of the instruction. */
14522 dwarf2_emit_insn (0);
6e1cb1a6 14523
0110f2b8
PB
14524 switch (inst.reloc.exp.X_op)
14525 {
14526 case O_symbol:
14527 sym = inst.reloc.exp.X_add_symbol;
14528 offset = inst.reloc.exp.X_add_number;
14529 break;
14530 case O_constant:
14531 sym = NULL;
14532 offset = inst.reloc.exp.X_add_number;
14533 break;
14534 default:
14535 sym = make_expr_symbol (&inst.reloc.exp);
14536 offset = 0;
14537 break;
14538 }
14539 to = frag_var (rs_machine_dependent, INSN_SIZE, THUMB_SIZE,
14540 inst.relax, sym, offset, NULL/*offset, opcode*/);
14541 md_number_to_chars (to, inst.instruction, THUMB_SIZE);
0110f2b8
PB
14542}
14543
14544/* Write a 32-bit thumb instruction to buf. */
14545static void
14546put_thumb32_insn (char * buf, unsigned long insn)
14547{
14548 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14549 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14550}
14551
b99bd4ef 14552static void
c19d1205 14553output_inst (const char * str)
b99bd4ef 14554{
c19d1205 14555 char * to = NULL;
b99bd4ef 14556
c19d1205 14557 if (inst.error)
b99bd4ef 14558 {
c19d1205 14559 as_bad ("%s -- `%s'", inst.error, str);
b99bd4ef
NC
14560 return;
14561 }
5f4273c7
NC
14562 if (inst.relax)
14563 {
14564 output_relax_insn ();
0110f2b8 14565 return;
5f4273c7 14566 }
c19d1205
ZW
14567 if (inst.size == 0)
14568 return;
b99bd4ef 14569
c19d1205 14570 to = frag_more (inst.size);
8dc2430f
NC
14571 /* PR 9814: Record the thumb mode into the current frag so that we know
14572 what type of NOP padding to use, if necessary. We override any previous
14573 setting so that if the mode has changed then the NOPS that we use will
14574 match the encoding of the last instruction in the frag. */
14575 frag_now->tc_frag_data = thumb_mode | MODE_RECORDED;
c19d1205
ZW
14576
14577 if (thumb_mode && (inst.size > THUMB_SIZE))
b99bd4ef 14578 {
9c2799c2 14579 gas_assert (inst.size == (2 * THUMB_SIZE));
0110f2b8 14580 put_thumb32_insn (to, inst.instruction);
b99bd4ef 14581 }
c19d1205 14582 else if (inst.size > INSN_SIZE)
b99bd4ef 14583 {
9c2799c2 14584 gas_assert (inst.size == (2 * INSN_SIZE));
c19d1205
ZW
14585 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14586 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
b99bd4ef 14587 }
c19d1205
ZW
14588 else
14589 md_number_to_chars (to, inst.instruction, inst.size);
b99bd4ef 14590
c19d1205
ZW
14591 if (inst.reloc.type != BFD_RELOC_UNUSED)
14592 fix_new_arm (frag_now, to - frag_now->fr_literal,
14593 inst.size, & inst.reloc.exp, inst.reloc.pc_rel,
14594 inst.reloc.type);
b99bd4ef 14595
c19d1205 14596 dwarf2_emit_insn (inst.size);
c19d1205 14597}
b99bd4ef 14598
e07e6e58
NC
14599static char *
14600output_it_inst (int cond, int mask, char * to)
14601{
14602 unsigned long instruction = 0xbf00;
14603
14604 mask &= 0xf;
14605 instruction |= mask;
14606 instruction |= cond << 4;
14607
14608 if (to == NULL)
14609 {
14610 to = frag_more (2);
14611#ifdef OBJ_ELF
14612 dwarf2_emit_insn (2);
14613#endif
14614 }
14615
14616 md_number_to_chars (to, instruction, 2);
14617
14618 return to;
14619}
14620
c19d1205
ZW
14621/* Tag values used in struct asm_opcode's tag field. */
14622enum opcode_tag
14623{
14624 OT_unconditional, /* Instruction cannot be conditionalized.
14625 The ARM condition field is still 0xE. */
14626 OT_unconditionalF, /* Instruction cannot be conditionalized
14627 and carries 0xF in its ARM condition field. */
14628 OT_csuffix, /* Instruction takes a conditional suffix. */
037e8744
JB
14629 OT_csuffixF, /* Some forms of the instruction take a conditional
14630 suffix, others place 0xF where the condition field
14631 would be. */
c19d1205
ZW
14632 OT_cinfix3, /* Instruction takes a conditional infix,
14633 beginning at character index 3. (In
14634 unified mode, it becomes a suffix.) */
088fa78e
KH
14635 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14636 tsts, cmps, cmns, and teqs. */
e3cb604e
PB
14637 OT_cinfix3_legacy, /* Legacy instruction takes a conditional infix at
14638 character index 3, even in unified mode. Used for
14639 legacy instructions where suffix and infix forms
14640 may be ambiguous. */
c19d1205 14641 OT_csuf_or_in3, /* Instruction takes either a conditional
e3cb604e 14642 suffix or an infix at character index 3. */
c19d1205
ZW
14643 OT_odd_infix_unc, /* This is the unconditional variant of an
14644 instruction that takes a conditional infix
14645 at an unusual position. In unified mode,
14646 this variant will accept a suffix. */
14647 OT_odd_infix_0 /* Values greater than or equal to OT_odd_infix_0
14648 are the conditional variants of instructions that
14649 take conditional infixes in unusual positions.
14650 The infix appears at character index
14651 (tag - OT_odd_infix_0). These are not accepted
14652 in unified mode. */
14653};
b99bd4ef 14654
c19d1205
ZW
14655/* Subroutine of md_assemble, responsible for looking up the primary
14656 opcode from the mnemonic the user wrote. STR points to the
14657 beginning of the mnemonic.
14658
14659 This is not simply a hash table lookup, because of conditional
14660 variants. Most instructions have conditional variants, which are
14661 expressed with a _conditional affix_ to the mnemonic. If we were
14662 to encode each conditional variant as a literal string in the opcode
14663 table, it would have approximately 20,000 entries.
14664
14665 Most mnemonics take this affix as a suffix, and in unified syntax,
14666 'most' is upgraded to 'all'. However, in the divided syntax, some
14667 instructions take the affix as an infix, notably the s-variants of
14668 the arithmetic instructions. Of those instructions, all but six
14669 have the infix appear after the third character of the mnemonic.
14670
14671 Accordingly, the algorithm for looking up primary opcodes given
14672 an identifier is:
14673
14674 1. Look up the identifier in the opcode table.
14675 If we find a match, go to step U.
14676
14677 2. Look up the last two characters of the identifier in the
14678 conditions table. If we find a match, look up the first N-2
14679 characters of the identifier in the opcode table. If we
14680 find a match, go to step CE.
14681
14682 3. Look up the fourth and fifth characters of the identifier in
14683 the conditions table. If we find a match, extract those
14684 characters from the identifier, and look up the remaining
14685 characters in the opcode table. If we find a match, go
14686 to step CM.
14687
14688 4. Fail.
14689
14690 U. Examine the tag field of the opcode structure, in case this is
14691 one of the six instructions with its conditional infix in an
14692 unusual place. If it is, the tag tells us where to find the
14693 infix; look it up in the conditions table and set inst.cond
14694 accordingly. Otherwise, this is an unconditional instruction.
14695 Again set inst.cond accordingly. Return the opcode structure.
14696
14697 CE. Examine the tag field to make sure this is an instruction that
14698 should receive a conditional suffix. If it is not, fail.
14699 Otherwise, set inst.cond from the suffix we already looked up,
14700 and return the opcode structure.
14701
14702 CM. Examine the tag field to make sure this is an instruction that
14703 should receive a conditional infix after the third character.
14704 If it is not, fail. Otherwise, undo the edits to the current
14705 line of input and proceed as for case CE. */
14706
14707static const struct asm_opcode *
14708opcode_lookup (char **str)
14709{
14710 char *end, *base;
14711 char *affix;
14712 const struct asm_opcode *opcode;
14713 const struct asm_cond *cond;
e3cb604e 14714 char save[2];
267d2029 14715 bfd_boolean neon_supported;
5f4273c7 14716
267d2029 14717 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
c19d1205
ZW
14718
14719 /* Scan up to the end of the mnemonic, which must end in white space,
267d2029 14720 '.' (in unified mode, or for Neon instructions), or end of string. */
c19d1205 14721 for (base = end = *str; *end != '\0'; end++)
267d2029 14722 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
c19d1205 14723 break;
b99bd4ef 14724
c19d1205
ZW
14725 if (end == base)
14726 return 0;
b99bd4ef 14727
5287ad62 14728 /* Handle a possible width suffix and/or Neon type suffix. */
c19d1205 14729 if (end[0] == '.')
b99bd4ef 14730 {
5287ad62 14731 int offset = 2;
5f4273c7 14732
267d2029
JB
14733 /* The .w and .n suffixes are only valid if the unified syntax is in
14734 use. */
14735 if (unified_syntax && end[1] == 'w')
c19d1205 14736 inst.size_req = 4;
267d2029 14737 else if (unified_syntax && end[1] == 'n')
c19d1205
ZW
14738 inst.size_req = 2;
14739 else
5287ad62
JB
14740 offset = 0;
14741
14742 inst.vectype.elems = 0;
14743
14744 *str = end + offset;
b99bd4ef 14745
5f4273c7 14746 if (end[offset] == '.')
5287ad62 14747 {
267d2029
JB
14748 /* See if we have a Neon type suffix (possible in either unified or
14749 non-unified ARM syntax mode). */
dcbf9037 14750 if (parse_neon_type (&inst.vectype, str) == FAIL)
5287ad62
JB
14751 return 0;
14752 }
14753 else if (end[offset] != '\0' && end[offset] != ' ')
14754 return 0;
b99bd4ef 14755 }
c19d1205
ZW
14756 else
14757 *str = end;
b99bd4ef 14758
c19d1205
ZW
14759 /* Look for unaffixed or special-case affixed mnemonic. */
14760 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14761 if (opcode)
b99bd4ef 14762 {
c19d1205
ZW
14763 /* step U */
14764 if (opcode->tag < OT_odd_infix_0)
b99bd4ef 14765 {
c19d1205
ZW
14766 inst.cond = COND_ALWAYS;
14767 return opcode;
b99bd4ef 14768 }
b99bd4ef 14769
278df34e 14770 if (warn_on_deprecated && unified_syntax)
c19d1205
ZW
14771 as_warn (_("conditional infixes are deprecated in unified syntax"));
14772 affix = base + (opcode->tag - OT_odd_infix_0);
14773 cond = hash_find_n (arm_cond_hsh, affix, 2);
9c2799c2 14774 gas_assert (cond);
b99bd4ef 14775
c19d1205
ZW
14776 inst.cond = cond->value;
14777 return opcode;
14778 }
b99bd4ef 14779
c19d1205
ZW
14780 /* Cannot have a conditional suffix on a mnemonic of less than two
14781 characters. */
14782 if (end - base < 3)
14783 return 0;
b99bd4ef 14784
c19d1205
ZW
14785 /* Look for suffixed mnemonic. */
14786 affix = end - 2;
14787 cond = hash_find_n (arm_cond_hsh, affix, 2);
14788 opcode = hash_find_n (arm_ops_hsh, base, affix - base);
14789 if (opcode && cond)
14790 {
14791 /* step CE */
14792 switch (opcode->tag)
14793 {
e3cb604e
PB
14794 case OT_cinfix3_legacy:
14795 /* Ignore conditional suffixes matched on infix only mnemonics. */
14796 break;
14797
c19d1205 14798 case OT_cinfix3:
088fa78e 14799 case OT_cinfix3_deprecated:
c19d1205
ZW
14800 case OT_odd_infix_unc:
14801 if (!unified_syntax)
e3cb604e 14802 return 0;
c19d1205
ZW
14803 /* else fall through */
14804
14805 case OT_csuffix:
037e8744 14806 case OT_csuffixF:
c19d1205
ZW
14807 case OT_csuf_or_in3:
14808 inst.cond = cond->value;
14809 return opcode;
14810
14811 case OT_unconditional:
14812 case OT_unconditionalF:
dfa9f0d5
PB
14813 if (thumb_mode)
14814 {
14815 inst.cond = cond->value;
14816 }
14817 else
14818 {
14819 /* delayed diagnostic */
14820 inst.error = BAD_COND;
14821 inst.cond = COND_ALWAYS;
14822 }
c19d1205 14823 return opcode;
b99bd4ef 14824
c19d1205
ZW
14825 default:
14826 return 0;
14827 }
14828 }
b99bd4ef 14829
c19d1205
ZW
14830 /* Cannot have a usual-position infix on a mnemonic of less than
14831 six characters (five would be a suffix). */
14832 if (end - base < 6)
14833 return 0;
b99bd4ef 14834
c19d1205
ZW
14835 /* Look for infixed mnemonic in the usual position. */
14836 affix = base + 3;
14837 cond = hash_find_n (arm_cond_hsh, affix, 2);
e3cb604e
PB
14838 if (!cond)
14839 return 0;
14840
14841 memcpy (save, affix, 2);
14842 memmove (affix, affix + 2, (end - affix) - 2);
14843 opcode = hash_find_n (arm_ops_hsh, base, (end - base) - 2);
14844 memmove (affix + 2, affix, (end - affix) - 2);
14845 memcpy (affix, save, 2);
14846
088fa78e
KH
14847 if (opcode
14848 && (opcode->tag == OT_cinfix3
14849 || opcode->tag == OT_cinfix3_deprecated
14850 || opcode->tag == OT_csuf_or_in3
14851 || opcode->tag == OT_cinfix3_legacy))
b99bd4ef 14852 {
c19d1205 14853 /* step CM */
278df34e 14854 if (warn_on_deprecated && unified_syntax
088fa78e
KH
14855 && (opcode->tag == OT_cinfix3
14856 || opcode->tag == OT_cinfix3_deprecated))
c19d1205
ZW
14857 as_warn (_("conditional infixes are deprecated in unified syntax"));
14858
14859 inst.cond = cond->value;
14860 return opcode;
b99bd4ef
NC
14861 }
14862
c19d1205 14863 return 0;
b99bd4ef
NC
14864}
14865
e07e6e58
NC
14866/* This function generates an initial IT instruction, leaving its block
14867 virtually open for the new instructions. Eventually,
14868 the mask will be updated by now_it_add_mask () each time
14869 a new instruction needs to be included in the IT block.
14870 Finally, the block is closed with close_automatic_it_block ().
14871 The block closure can be requested either from md_assemble (),
14872 a tencode (), or due to a label hook. */
14873
14874static void
14875new_automatic_it_block (int cond)
14876{
14877 now_it.state = AUTOMATIC_IT_BLOCK;
14878 now_it.mask = 0x18;
14879 now_it.cc = cond;
14880 now_it.block_length = 1;
14881 now_it.insn = output_it_inst (cond, now_it.mask, NULL);
14882}
14883
14884/* Close an automatic IT block.
14885 See comments in new_automatic_it_block (). */
14886
14887static void
14888close_automatic_it_block (void)
14889{
14890 now_it.mask = 0x10;
14891 now_it.block_length = 0;
14892}
14893
14894/* Update the mask of the current automatically-generated IT
14895 instruction. See comments in new_automatic_it_block (). */
14896
14897static void
14898now_it_add_mask (int cond)
14899{
14900#define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
14901#define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
14902 | ((bitvalue) << (nbit)))
14903
14904 const int resulting_bit = (cond & 1);
14905 now_it.mask &= 0xf;
14906 now_it.mask = SET_BIT_VALUE (now_it.mask,
14907 resulting_bit,
14908 (5 - now_it.block_length));
14909 now_it.mask = SET_BIT_VALUE (now_it.mask,
14910 1,
14911 ((5 - now_it.block_length) - 1) );
14912 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
14913
14914#undef CLEAR_BIT
14915#undef SET_BIT_VALUE
14916
14917}
14918
14919/* The IT blocks handling machinery is accessed through the these functions:
14920 it_fsm_pre_encode () from md_assemble ()
14921 set_it_insn_type () optional, from the tencode functions
14922 set_it_insn_type_last () ditto
14923 in_it_block () ditto
14924 it_fsm_post_encode () from md_assemble ()
14925 force_automatic_it_block_close () from label habdling functions
14926
14927 Rationale:
14928 1) md_assemble () calls it_fsm_pre_encode () before calling tencode (),
14929 initializing the IT insn type with a generic initial value depending
14930 on the inst.condition.
14931 2) During the tencode function, two things may happen:
14932 a) The tencode function overrides the IT insn type by
14933 calling either set_it_insn_type (type) or set_it_insn_type_last ().
14934 b) The tencode function queries the IT block state by
14935 calling in_it_block () (i.e. to determine narrow/not narrow mode).
14936
14937 Both set_it_insn_type and in_it_block run the internal FSM state
14938 handling function (handle_it_state), because: a) setting the IT insn
14939 type may incur in an invalid state (exiting the function),
14940 and b) querying the state requires the FSM to be updated.
14941 Specifically we want to avoid creating an IT block for conditional
14942 branches, so it_fsm_pre_encode is actually a guess and we can't
14943 determine whether an IT block is required until the tencode () routine
14944 has decided what type of instruction this actually it.
14945 Because of this, if set_it_insn_type and in_it_block have to be used,
14946 set_it_insn_type has to be called first.
14947
14948 set_it_insn_type_last () is a wrapper of set_it_insn_type (type), that
14949 determines the insn IT type depending on the inst.cond code.
14950 When a tencode () routine encodes an instruction that can be
14951 either outside an IT block, or, in the case of being inside, has to be
14952 the last one, set_it_insn_type_last () will determine the proper
14953 IT instruction type based on the inst.cond code. Otherwise,
14954 set_it_insn_type can be called for overriding that logic or
14955 for covering other cases.
14956
14957 Calling handle_it_state () may not transition the IT block state to
14958 OUTSIDE_IT_BLOCK immediatelly, since the (current) state could be
14959 still queried. Instead, if the FSM determines that the state should
14960 be transitioned to OUTSIDE_IT_BLOCK, a flag is marked to be closed
14961 after the tencode () function: that's what it_fsm_post_encode () does.
14962
14963 Since in_it_block () calls the state handling function to get an
14964 updated state, an error may occur (due to invalid insns combination).
14965 In that case, inst.error is set.
14966 Therefore, inst.error has to be checked after the execution of
14967 the tencode () routine.
14968
14969 3) Back in md_assemble(), it_fsm_post_encode () is called to commit
14970 any pending state change (if any) that didn't take place in
14971 handle_it_state () as explained above. */
14972
14973static void
14974it_fsm_pre_encode (void)
14975{
14976 if (inst.cond != COND_ALWAYS)
14977 inst.it_insn_type = INSIDE_IT_INSN;
14978 else
14979 inst.it_insn_type = OUTSIDE_IT_INSN;
14980
14981 now_it.state_handled = 0;
14982}
14983
14984/* IT state FSM handling function. */
14985
14986static int
14987handle_it_state (void)
14988{
14989 now_it.state_handled = 1;
14990
14991 switch (now_it.state)
14992 {
14993 case OUTSIDE_IT_BLOCK:
14994 switch (inst.it_insn_type)
14995 {
14996 case OUTSIDE_IT_INSN:
14997 break;
14998
14999 case INSIDE_IT_INSN:
15000 case INSIDE_IT_LAST_INSN:
15001 if (thumb_mode == 0)
15002 {
15003 if (unified_syntax
15004 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15005 as_tsktsk (_("Warning: conditional outside an IT block"\
15006 " for Thumb."));
15007 }
15008 else
15009 {
15010 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15011 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
15012 {
15013 /* Automatically generate the IT instruction. */
15014 new_automatic_it_block (inst.cond);
15015 if (inst.it_insn_type == INSIDE_IT_LAST_INSN)
15016 close_automatic_it_block ();
15017 }
15018 else
15019 {
15020 inst.error = BAD_OUT_IT;
15021 return FAIL;
15022 }
15023 }
15024 break;
15025
15026 case IF_INSIDE_IT_LAST_INSN:
15027 case NEUTRAL_IT_INSN:
15028 break;
15029
15030 case IT_INSN:
15031 now_it.state = MANUAL_IT_BLOCK;
15032 now_it.block_length = 0;
15033 break;
15034 }
15035 break;
15036
15037 case AUTOMATIC_IT_BLOCK:
15038 /* Three things may happen now:
15039 a) We should increment current it block size;
15040 b) We should close current it block (closing insn or 4 insns);
15041 c) We should close current it block and start a new one (due
15042 to incompatible conditions or
15043 4 insns-length block reached). */
15044
15045 switch (inst.it_insn_type)
15046 {
15047 case OUTSIDE_IT_INSN:
15048 /* The closure of the block shall happen immediatelly,
15049 so any in_it_block () call reports the block as closed. */
15050 force_automatic_it_block_close ();
15051 break;
15052
15053 case INSIDE_IT_INSN:
15054 case INSIDE_IT_LAST_INSN:
15055 case IF_INSIDE_IT_LAST_INSN:
15056 now_it.block_length++;
15057
15058 if (now_it.block_length > 4
15059 || !now_it_compatible (inst.cond))
15060 {
15061 force_automatic_it_block_close ();
15062 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15063 new_automatic_it_block (inst.cond);
15064 }
15065 else
15066 {
15067 now_it_add_mask (inst.cond);
15068 }
15069
15070 if (now_it.state == AUTOMATIC_IT_BLOCK
15071 && (inst.it_insn_type == INSIDE_IT_LAST_INSN
15072 || inst.it_insn_type == IF_INSIDE_IT_LAST_INSN))
15073 close_automatic_it_block ();
15074 break;
15075
15076 case NEUTRAL_IT_INSN:
15077 now_it.block_length++;
15078
15079 if (now_it.block_length > 4)
15080 force_automatic_it_block_close ();
15081 else
15082 now_it_add_mask (now_it.cc & 1);
15083 break;
15084
15085 case IT_INSN:
15086 close_automatic_it_block ();
15087 now_it.state = MANUAL_IT_BLOCK;
15088 break;
15089 }
15090 break;
15091
15092 case MANUAL_IT_BLOCK:
15093 {
15094 /* Check conditional suffixes. */
15095 const int cond = now_it.cc ^ ((now_it.mask >> 4) & 1) ^ 1;
15096 int is_last;
15097 now_it.mask <<= 1;
15098 now_it.mask &= 0x1f;
15099 is_last = (now_it.mask == 0x10);
15100
15101 switch (inst.it_insn_type)
15102 {
15103 case OUTSIDE_IT_INSN:
15104 inst.error = BAD_NOT_IT;
15105 return FAIL;
15106
15107 case INSIDE_IT_INSN:
15108 if (cond != inst.cond)
15109 {
15110 inst.error = BAD_IT_COND;
15111 return FAIL;
15112 }
15113 break;
15114
15115 case INSIDE_IT_LAST_INSN:
15116 case IF_INSIDE_IT_LAST_INSN:
15117 if (cond != inst.cond)
15118 {
15119 inst.error = BAD_IT_COND;
15120 return FAIL;
15121 }
15122 if (!is_last)
15123 {
15124 inst.error = BAD_BRANCH;
15125 return FAIL;
15126 }
15127 break;
15128
15129 case NEUTRAL_IT_INSN:
15130 /* The BKPT instruction is unconditional even in an IT block. */
15131 break;
15132
15133 case IT_INSN:
15134 inst.error = BAD_IT_IT;
15135 return FAIL;
15136 }
15137 }
15138 break;
15139 }
15140
15141 return SUCCESS;
15142}
15143
15144static void
15145it_fsm_post_encode (void)
15146{
15147 int is_last;
15148
15149 if (!now_it.state_handled)
15150 handle_it_state ();
15151
15152 is_last = (now_it.mask == 0x10);
15153 if (is_last)
15154 {
15155 now_it.state = OUTSIDE_IT_BLOCK;
15156 now_it.mask = 0;
15157 }
15158}
15159
15160static void
15161force_automatic_it_block_close (void)
15162{
15163 if (now_it.state == AUTOMATIC_IT_BLOCK)
15164 {
15165 close_automatic_it_block ();
15166 now_it.state = OUTSIDE_IT_BLOCK;
15167 now_it.mask = 0;
15168 }
15169}
15170
15171static int
15172in_it_block (void)
15173{
15174 if (!now_it.state_handled)
15175 handle_it_state ();
15176
15177 return now_it.state != OUTSIDE_IT_BLOCK;
15178}
15179
c19d1205
ZW
15180void
15181md_assemble (char *str)
b99bd4ef 15182{
c19d1205
ZW
15183 char *p = str;
15184 const struct asm_opcode * opcode;
b99bd4ef 15185
c19d1205
ZW
15186 /* Align the previous label if needed. */
15187 if (last_label_seen != NULL)
b99bd4ef 15188 {
c19d1205
ZW
15189 symbol_set_frag (last_label_seen, frag_now);
15190 S_SET_VALUE (last_label_seen, (valueT) frag_now_fix ());
15191 S_SET_SEGMENT (last_label_seen, now_seg);
b99bd4ef
NC
15192 }
15193
c19d1205
ZW
15194 memset (&inst, '\0', sizeof (inst));
15195 inst.reloc.type = BFD_RELOC_UNUSED;
b99bd4ef 15196
c19d1205
ZW
15197 opcode = opcode_lookup (&p);
15198 if (!opcode)
b99bd4ef 15199 {
c19d1205 15200 /* It wasn't an instruction, but it might be a register alias of
dcbf9037
JB
15201 the form alias .req reg, or a Neon .dn/.qn directive. */
15202 if (!create_register_alias (str, p)
15203 && !create_neon_reg_alias (str, p))
c19d1205 15204 as_bad (_("bad instruction `%s'"), str);
b99bd4ef 15205
b99bd4ef
NC
15206 return;
15207 }
15208
278df34e 15209 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
088fa78e
KH
15210 as_warn (_("s suffix on comparison instruction is deprecated"));
15211
037e8744
JB
15212 /* The value which unconditional instructions should have in place of the
15213 condition field. */
15214 inst.uncond_value = (opcode->tag == OT_csuffixF) ? 0xf : -1;
15215
c19d1205 15216 if (thumb_mode)
b99bd4ef 15217 {
e74cfd16 15218 arm_feature_set variant;
8f06b2d8
PB
15219
15220 variant = cpu_variant;
15221 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
e74cfd16
PB
15222 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15223 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
c19d1205 15224 /* Check that this instruction is supported for this CPU. */
62b3e311
PB
15225 if (!opcode->tvariant
15226 || (thumb_mode == 1
15227 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
b99bd4ef 15228 {
c19d1205 15229 as_bad (_("selected processor does not support `%s'"), str);
b99bd4ef
NC
15230 return;
15231 }
c19d1205
ZW
15232 if (inst.cond != COND_ALWAYS && !unified_syntax
15233 && opcode->tencode != do_t_branch)
b99bd4ef 15234 {
c19d1205 15235 as_bad (_("Thumb does not support conditional execution"));
b99bd4ef
NC
15236 return;
15237 }
15238
076d447c
PB
15239 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
15240 {
15241 /* Implicit require narrow instructions on Thumb-1. This avoids
15242 relaxation accidentally introducing Thumb-2 instructions. */
7e806470 15243 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
e07e6e58
NC
15244 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15245 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
076d447c
PB
15246 inst.size_req = 2;
15247 }
15248
c19d1205
ZW
15249 mapping_state (MAP_THUMB);
15250 inst.instruction = opcode->tvalue;
15251
15252 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15253 {
15254 /* Prepare the it_insn_type for those encodings that don't set
15255 it. */
15256 it_fsm_pre_encode ();
c19d1205 15257
e07e6e58
NC
15258 opcode->tencode ();
15259
15260 it_fsm_post_encode ();
15261 }
e27ec89e 15262
0110f2b8 15263 if (!(inst.error || inst.relax))
b99bd4ef 15264 {
9c2799c2 15265 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
c19d1205
ZW
15266 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15267 if (inst.size_req && inst.size_req != inst.size)
b99bd4ef 15268 {
c19d1205 15269 as_bad (_("cannot honor width suffix -- `%s'"), str);
b99bd4ef
NC
15270 return;
15271 }
15272 }
076d447c
PB
15273
15274 /* Something has gone badly wrong if we try to relax a fixed size
15275 instruction. */
9c2799c2 15276 gas_assert (inst.size_req == 0 || !inst.relax);
076d447c 15277
e74cfd16
PB
15278 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15279 *opcode->tvariant);
ee065d83 15280 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
708587a4 15281 set those bits when Thumb-2 32-bit instructions are seen. ie.
7e806470 15282 anything other than bl/blx and v6-M instructions.
ee065d83 15283 This is overly pessimistic for relaxable instructions. */
7e806470
PB
15284 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15285 || inst.relax)
e07e6e58
NC
15286 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15287 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
e74cfd16
PB
15288 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15289 arm_ext_v6t2);
c19d1205 15290 }
3e9e4fcf 15291 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
c19d1205 15292 {
845b51d6
PB
15293 bfd_boolean is_bx;
15294
15295 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15296 is_bx = (opcode->aencode == do_bx);
15297
c19d1205 15298 /* Check that this instruction is supported for this CPU. */
845b51d6
PB
15299 if (!(is_bx && fix_v4bx)
15300 && !(opcode->avariant &&
15301 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
b99bd4ef 15302 {
c19d1205
ZW
15303 as_bad (_("selected processor does not support `%s'"), str);
15304 return;
b99bd4ef 15305 }
c19d1205 15306 if (inst.size_req)
b99bd4ef 15307 {
c19d1205
ZW
15308 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15309 return;
b99bd4ef
NC
15310 }
15311
c19d1205
ZW
15312 mapping_state (MAP_ARM);
15313 inst.instruction = opcode->avalue;
15314 if (opcode->tag == OT_unconditionalF)
15315 inst.instruction |= 0xF << 28;
15316 else
15317 inst.instruction |= inst.cond << 28;
15318 inst.size = INSN_SIZE;
15319 if (!parse_operands (p, opcode->operands))
e07e6e58
NC
15320 {
15321 it_fsm_pre_encode ();
15322 opcode->aencode ();
15323 it_fsm_post_encode ();
15324 }
ee065d83
PB
15325 /* Arm mode bx is marked as both v4T and v5 because it's still required
15326 on a hypothetical non-thumb v5 core. */
845b51d6 15327 if (is_bx)
e74cfd16 15328 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
ee065d83 15329 else
e74cfd16
PB
15330 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15331 *opcode->avariant);
b99bd4ef 15332 }
3e9e4fcf
JB
15333 else
15334 {
15335 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15336 "-- `%s'"), str);
15337 return;
15338 }
c19d1205
ZW
15339 output_inst (str);
15340}
b99bd4ef 15341
e07e6e58
NC
15342static void
15343check_it_blocks_finished (void)
15344{
15345#ifdef OBJ_ELF
15346 asection *sect;
15347
15348 for (sect = stdoutput->sections; sect != NULL; sect = sect->next)
15349 if (seg_info (sect)->tc_segment_info_data.current_it.state
15350 == MANUAL_IT_BLOCK)
15351 {
15352 as_warn (_("section '%s' finished with an open IT block."),
15353 sect->name);
15354 }
15355#else
15356 if (now_it.state == MANUAL_IT_BLOCK)
15357 as_warn (_("file finished with an open IT block."));
15358#endif
15359}
15360
c19d1205
ZW
15361/* Various frobbings of labels and their addresses. */
15362
15363void
15364arm_start_line_hook (void)
15365{
15366 last_label_seen = NULL;
b99bd4ef
NC
15367}
15368
c19d1205
ZW
15369void
15370arm_frob_label (symbolS * sym)
b99bd4ef 15371{
c19d1205 15372 last_label_seen = sym;
b99bd4ef 15373
c19d1205 15374 ARM_SET_THUMB (sym, thumb_mode);
b99bd4ef 15375
c19d1205
ZW
15376#if defined OBJ_COFF || defined OBJ_ELF
15377 ARM_SET_INTERWORK (sym, support_interwork);
15378#endif
b99bd4ef 15379
e07e6e58
NC
15380 force_automatic_it_block_close ();
15381
5f4273c7 15382 /* Note - do not allow local symbols (.Lxxx) to be labelled
c19d1205
ZW
15383 as Thumb functions. This is because these labels, whilst
15384 they exist inside Thumb code, are not the entry points for
15385 possible ARM->Thumb calls. Also, these labels can be used
15386 as part of a computed goto or switch statement. eg gcc
15387 can generate code that looks like this:
b99bd4ef 15388
c19d1205
ZW
15389 ldr r2, [pc, .Laaa]
15390 lsl r3, r3, #2
15391 ldr r2, [r3, r2]
15392 mov pc, r2
b99bd4ef 15393
c19d1205
ZW
15394 .Lbbb: .word .Lxxx
15395 .Lccc: .word .Lyyy
15396 ..etc...
15397 .Laaa: .word Lbbb
b99bd4ef 15398
c19d1205
ZW
15399 The first instruction loads the address of the jump table.
15400 The second instruction converts a table index into a byte offset.
15401 The third instruction gets the jump address out of the table.
15402 The fourth instruction performs the jump.
b99bd4ef 15403
c19d1205
ZW
15404 If the address stored at .Laaa is that of a symbol which has the
15405 Thumb_Func bit set, then the linker will arrange for this address
15406 to have the bottom bit set, which in turn would mean that the
15407 address computation performed by the third instruction would end
15408 up with the bottom bit set. Since the ARM is capable of unaligned
15409 word loads, the instruction would then load the incorrect address
15410 out of the jump table, and chaos would ensue. */
15411 if (label_is_thumb_function_name
15412 && (S_GET_NAME (sym)[0] != '.' || S_GET_NAME (sym)[1] != 'L')
15413 && (bfd_get_section_flags (stdoutput, now_seg) & SEC_CODE) != 0)
b99bd4ef 15414 {
c19d1205
ZW
15415 /* When the address of a Thumb function is taken the bottom
15416 bit of that address should be set. This will allow
15417 interworking between Arm and Thumb functions to work
15418 correctly. */
b99bd4ef 15419
c19d1205 15420 THUMB_SET_FUNC (sym, 1);
b99bd4ef 15421
c19d1205 15422 label_is_thumb_function_name = FALSE;
b99bd4ef 15423 }
07a53e5c 15424
07a53e5c 15425 dwarf2_emit_label (sym);
b99bd4ef
NC
15426}
15427
c19d1205
ZW
15428int
15429arm_data_in_code (void)
b99bd4ef 15430{
c19d1205 15431 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
b99bd4ef 15432 {
c19d1205
ZW
15433 *input_line_pointer = '/';
15434 input_line_pointer += 5;
15435 *input_line_pointer = 0;
15436 return 1;
b99bd4ef
NC
15437 }
15438
c19d1205 15439 return 0;
b99bd4ef
NC
15440}
15441
c19d1205
ZW
15442char *
15443arm_canonicalize_symbol_name (char * name)
b99bd4ef 15444{
c19d1205 15445 int len;
b99bd4ef 15446
c19d1205
ZW
15447 if (thumb_mode && (len = strlen (name)) > 5
15448 && streq (name + len - 5, "/data"))
15449 *(name + len - 5) = 0;
b99bd4ef 15450
c19d1205 15451 return name;
b99bd4ef 15452}
c19d1205
ZW
15453\f
15454/* Table of all register names defined by default. The user can
15455 define additional names with .req. Note that all register names
15456 should appear in both upper and lowercase variants. Some registers
15457 also have mixed-case names. */
b99bd4ef 15458
dcbf9037 15459#define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
c19d1205 15460#define REGNUM(p,n,t) REGDEF(p##n, n, t)
5287ad62 15461#define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
c19d1205
ZW
15462#define REGSET(p,t) \
15463 REGNUM(p, 0,t), REGNUM(p, 1,t), REGNUM(p, 2,t), REGNUM(p, 3,t), \
15464 REGNUM(p, 4,t), REGNUM(p, 5,t), REGNUM(p, 6,t), REGNUM(p, 7,t), \
15465 REGNUM(p, 8,t), REGNUM(p, 9,t), REGNUM(p,10,t), REGNUM(p,11,t), \
15466 REGNUM(p,12,t), REGNUM(p,13,t), REGNUM(p,14,t), REGNUM(p,15,t)
5287ad62
JB
15467#define REGSETH(p,t) \
15468 REGNUM(p,16,t), REGNUM(p,17,t), REGNUM(p,18,t), REGNUM(p,19,t), \
15469 REGNUM(p,20,t), REGNUM(p,21,t), REGNUM(p,22,t), REGNUM(p,23,t), \
15470 REGNUM(p,24,t), REGNUM(p,25,t), REGNUM(p,26,t), REGNUM(p,27,t), \
15471 REGNUM(p,28,t), REGNUM(p,29,t), REGNUM(p,30,t), REGNUM(p,31,t)
15472#define REGSET2(p,t) \
15473 REGNUM2(p, 0,t), REGNUM2(p, 1,t), REGNUM2(p, 2,t), REGNUM2(p, 3,t), \
15474 REGNUM2(p, 4,t), REGNUM2(p, 5,t), REGNUM2(p, 6,t), REGNUM2(p, 7,t), \
15475 REGNUM2(p, 8,t), REGNUM2(p, 9,t), REGNUM2(p,10,t), REGNUM2(p,11,t), \
15476 REGNUM2(p,12,t), REGNUM2(p,13,t), REGNUM2(p,14,t), REGNUM2(p,15,t)
7ed4c4c5 15477
c19d1205 15478static const struct reg_entry reg_names[] =
7ed4c4c5 15479{
c19d1205
ZW
15480 /* ARM integer registers. */
15481 REGSET(r, RN), REGSET(R, RN),
7ed4c4c5 15482
c19d1205
ZW
15483 /* ATPCS synonyms. */
15484 REGDEF(a1,0,RN), REGDEF(a2,1,RN), REGDEF(a3, 2,RN), REGDEF(a4, 3,RN),
15485 REGDEF(v1,4,RN), REGDEF(v2,5,RN), REGDEF(v3, 6,RN), REGDEF(v4, 7,RN),
15486 REGDEF(v5,8,RN), REGDEF(v6,9,RN), REGDEF(v7,10,RN), REGDEF(v8,11,RN),
7ed4c4c5 15487
c19d1205
ZW
15488 REGDEF(A1,0,RN), REGDEF(A2,1,RN), REGDEF(A3, 2,RN), REGDEF(A4, 3,RN),
15489 REGDEF(V1,4,RN), REGDEF(V2,5,RN), REGDEF(V3, 6,RN), REGDEF(V4, 7,RN),
15490 REGDEF(V5,8,RN), REGDEF(V6,9,RN), REGDEF(V7,10,RN), REGDEF(V8,11,RN),
7ed4c4c5 15491
c19d1205
ZW
15492 /* Well-known aliases. */
15493 REGDEF(wr, 7,RN), REGDEF(sb, 9,RN), REGDEF(sl,10,RN), REGDEF(fp,11,RN),
15494 REGDEF(ip,12,RN), REGDEF(sp,13,RN), REGDEF(lr,14,RN), REGDEF(pc,15,RN),
15495
15496 REGDEF(WR, 7,RN), REGDEF(SB, 9,RN), REGDEF(SL,10,RN), REGDEF(FP,11,RN),
15497 REGDEF(IP,12,RN), REGDEF(SP,13,RN), REGDEF(LR,14,RN), REGDEF(PC,15,RN),
15498
15499 /* Coprocessor numbers. */
15500 REGSET(p, CP), REGSET(P, CP),
15501
15502 /* Coprocessor register numbers. The "cr" variants are for backward
15503 compatibility. */
15504 REGSET(c, CN), REGSET(C, CN),
15505 REGSET(cr, CN), REGSET(CR, CN),
15506
15507 /* FPA registers. */
15508 REGNUM(f,0,FN), REGNUM(f,1,FN), REGNUM(f,2,FN), REGNUM(f,3,FN),
15509 REGNUM(f,4,FN), REGNUM(f,5,FN), REGNUM(f,6,FN), REGNUM(f,7, FN),
15510
15511 REGNUM(F,0,FN), REGNUM(F,1,FN), REGNUM(F,2,FN), REGNUM(F,3,FN),
15512 REGNUM(F,4,FN), REGNUM(F,5,FN), REGNUM(F,6,FN), REGNUM(F,7, FN),
15513
15514 /* VFP SP registers. */
5287ad62
JB
15515 REGSET(s,VFS), REGSET(S,VFS),
15516 REGSETH(s,VFS), REGSETH(S,VFS),
c19d1205
ZW
15517
15518 /* VFP DP Registers. */
5287ad62
JB
15519 REGSET(d,VFD), REGSET(D,VFD),
15520 /* Extra Neon DP registers. */
15521 REGSETH(d,VFD), REGSETH(D,VFD),
15522
15523 /* Neon QP registers. */
15524 REGSET2(q,NQ), REGSET2(Q,NQ),
c19d1205
ZW
15525
15526 /* VFP control registers. */
15527 REGDEF(fpsid,0,VFC), REGDEF(fpscr,1,VFC), REGDEF(fpexc,8,VFC),
15528 REGDEF(FPSID,0,VFC), REGDEF(FPSCR,1,VFC), REGDEF(FPEXC,8,VFC),
cd2cf30b
PB
15529 REGDEF(fpinst,9,VFC), REGDEF(fpinst2,10,VFC),
15530 REGDEF(FPINST,9,VFC), REGDEF(FPINST2,10,VFC),
15531 REGDEF(mvfr0,7,VFC), REGDEF(mvfr1,6,VFC),
15532 REGDEF(MVFR0,7,VFC), REGDEF(MVFR1,6,VFC),
c19d1205
ZW
15533
15534 /* Maverick DSP coprocessor registers. */
15535 REGSET(mvf,MVF), REGSET(mvd,MVD), REGSET(mvfx,MVFX), REGSET(mvdx,MVDX),
15536 REGSET(MVF,MVF), REGSET(MVD,MVD), REGSET(MVFX,MVFX), REGSET(MVDX,MVDX),
15537
15538 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15539 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15540 REGDEF(dspsc,0,DSPSC),
15541
15542 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15543 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15544 REGDEF(DSPSC,0,DSPSC),
15545
15546 /* iWMMXt data registers - p0, c0-15. */
15547 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
15548
15549 /* iWMMXt control registers - p1, c0-3. */
15550 REGDEF(wcid, 0,MMXWC), REGDEF(wCID, 0,MMXWC), REGDEF(WCID, 0,MMXWC),
15551 REGDEF(wcon, 1,MMXWC), REGDEF(wCon, 1,MMXWC), REGDEF(WCON, 1,MMXWC),
15552 REGDEF(wcssf, 2,MMXWC), REGDEF(wCSSF, 2,MMXWC), REGDEF(WCSSF, 2,MMXWC),
15553 REGDEF(wcasf, 3,MMXWC), REGDEF(wCASF, 3,MMXWC), REGDEF(WCASF, 3,MMXWC),
15554
15555 /* iWMMXt scalar (constant/offset) registers - p1, c8-11. */
15556 REGDEF(wcgr0, 8,MMXWCG), REGDEF(wCGR0, 8,MMXWCG), REGDEF(WCGR0, 8,MMXWCG),
15557 REGDEF(wcgr1, 9,MMXWCG), REGDEF(wCGR1, 9,MMXWCG), REGDEF(WCGR1, 9,MMXWCG),
15558 REGDEF(wcgr2,10,MMXWCG), REGDEF(wCGR2,10,MMXWCG), REGDEF(WCGR2,10,MMXWCG),
15559 REGDEF(wcgr3,11,MMXWCG), REGDEF(wCGR3,11,MMXWCG), REGDEF(WCGR3,11,MMXWCG),
15560
15561 /* XScale accumulator registers. */
15562 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15563};
15564#undef REGDEF
15565#undef REGNUM
15566#undef REGSET
7ed4c4c5 15567
c19d1205
ZW
15568/* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15569 within psr_required_here. */
15570static const struct asm_psr psrs[] =
15571{
15572 /* Backward compatibility notation. Note that "all" is no longer
15573 truly all possible PSR bits. */
15574 {"all", PSR_c | PSR_f},
15575 {"flg", PSR_f},
15576 {"ctl", PSR_c},
15577
15578 /* Individual flags. */
15579 {"f", PSR_f},
15580 {"c", PSR_c},
15581 {"x", PSR_x},
15582 {"s", PSR_s},
15583 /* Combinations of flags. */
15584 {"fs", PSR_f | PSR_s},
15585 {"fx", PSR_f | PSR_x},
15586 {"fc", PSR_f | PSR_c},
15587 {"sf", PSR_s | PSR_f},
15588 {"sx", PSR_s | PSR_x},
15589 {"sc", PSR_s | PSR_c},
15590 {"xf", PSR_x | PSR_f},
15591 {"xs", PSR_x | PSR_s},
15592 {"xc", PSR_x | PSR_c},
15593 {"cf", PSR_c | PSR_f},
15594 {"cs", PSR_c | PSR_s},
15595 {"cx", PSR_c | PSR_x},
15596 {"fsx", PSR_f | PSR_s | PSR_x},
15597 {"fsc", PSR_f | PSR_s | PSR_c},
15598 {"fxs", PSR_f | PSR_x | PSR_s},
15599 {"fxc", PSR_f | PSR_x | PSR_c},
15600 {"fcs", PSR_f | PSR_c | PSR_s},
15601 {"fcx", PSR_f | PSR_c | PSR_x},
15602 {"sfx", PSR_s | PSR_f | PSR_x},
15603 {"sfc", PSR_s | PSR_f | PSR_c},
15604 {"sxf", PSR_s | PSR_x | PSR_f},
15605 {"sxc", PSR_s | PSR_x | PSR_c},
15606 {"scf", PSR_s | PSR_c | PSR_f},
15607 {"scx", PSR_s | PSR_c | PSR_x},
15608 {"xfs", PSR_x | PSR_f | PSR_s},
15609 {"xfc", PSR_x | PSR_f | PSR_c},
15610 {"xsf", PSR_x | PSR_s | PSR_f},
15611 {"xsc", PSR_x | PSR_s | PSR_c},
15612 {"xcf", PSR_x | PSR_c | PSR_f},
15613 {"xcs", PSR_x | PSR_c | PSR_s},
15614 {"cfs", PSR_c | PSR_f | PSR_s},
15615 {"cfx", PSR_c | PSR_f | PSR_x},
15616 {"csf", PSR_c | PSR_s | PSR_f},
15617 {"csx", PSR_c | PSR_s | PSR_x},
15618 {"cxf", PSR_c | PSR_x | PSR_f},
15619 {"cxs", PSR_c | PSR_x | PSR_s},
15620 {"fsxc", PSR_f | PSR_s | PSR_x | PSR_c},
15621 {"fscx", PSR_f | PSR_s | PSR_c | PSR_x},
15622 {"fxsc", PSR_f | PSR_x | PSR_s | PSR_c},
15623 {"fxcs", PSR_f | PSR_x | PSR_c | PSR_s},
15624 {"fcsx", PSR_f | PSR_c | PSR_s | PSR_x},
15625 {"fcxs", PSR_f | PSR_c | PSR_x | PSR_s},
15626 {"sfxc", PSR_s | PSR_f | PSR_x | PSR_c},
15627 {"sfcx", PSR_s | PSR_f | PSR_c | PSR_x},
15628 {"sxfc", PSR_s | PSR_x | PSR_f | PSR_c},
15629 {"sxcf", PSR_s | PSR_x | PSR_c | PSR_f},
15630 {"scfx", PSR_s | PSR_c | PSR_f | PSR_x},
15631 {"scxf", PSR_s | PSR_c | PSR_x | PSR_f},
15632 {"xfsc", PSR_x | PSR_f | PSR_s | PSR_c},
15633 {"xfcs", PSR_x | PSR_f | PSR_c | PSR_s},
15634 {"xsfc", PSR_x | PSR_s | PSR_f | PSR_c},
15635 {"xscf", PSR_x | PSR_s | PSR_c | PSR_f},
15636 {"xcfs", PSR_x | PSR_c | PSR_f | PSR_s},
15637 {"xcsf", PSR_x | PSR_c | PSR_s | PSR_f},
15638 {"cfsx", PSR_c | PSR_f | PSR_s | PSR_x},
15639 {"cfxs", PSR_c | PSR_f | PSR_x | PSR_s},
15640 {"csfx", PSR_c | PSR_s | PSR_f | PSR_x},
15641 {"csxf", PSR_c | PSR_s | PSR_x | PSR_f},
15642 {"cxfs", PSR_c | PSR_x | PSR_f | PSR_s},
15643 {"cxsf", PSR_c | PSR_x | PSR_s | PSR_f},
15644};
15645
62b3e311
PB
15646/* Table of V7M psr names. */
15647static const struct asm_psr v7m_psrs[] =
15648{
2b744c99
PB
15649 {"apsr", 0 }, {"APSR", 0 },
15650 {"iapsr", 1 }, {"IAPSR", 1 },
15651 {"eapsr", 2 }, {"EAPSR", 2 },
15652 {"psr", 3 }, {"PSR", 3 },
15653 {"xpsr", 3 }, {"XPSR", 3 }, {"xPSR", 3 },
15654 {"ipsr", 5 }, {"IPSR", 5 },
15655 {"epsr", 6 }, {"EPSR", 6 },
15656 {"iepsr", 7 }, {"IEPSR", 7 },
15657 {"msp", 8 }, {"MSP", 8 },
15658 {"psp", 9 }, {"PSP", 9 },
15659 {"primask", 16}, {"PRIMASK", 16},
15660 {"basepri", 17}, {"BASEPRI", 17},
15661 {"basepri_max", 18}, {"BASEPRI_MAX", 18},
15662 {"faultmask", 19}, {"FAULTMASK", 19},
15663 {"control", 20}, {"CONTROL", 20}
62b3e311
PB
15664};
15665
c19d1205
ZW
15666/* Table of all shift-in-operand names. */
15667static const struct asm_shift_name shift_names [] =
b99bd4ef 15668{
c19d1205
ZW
15669 { "asl", SHIFT_LSL }, { "ASL", SHIFT_LSL },
15670 { "lsl", SHIFT_LSL }, { "LSL", SHIFT_LSL },
15671 { "lsr", SHIFT_LSR }, { "LSR", SHIFT_LSR },
15672 { "asr", SHIFT_ASR }, { "ASR", SHIFT_ASR },
15673 { "ror", SHIFT_ROR }, { "ROR", SHIFT_ROR },
15674 { "rrx", SHIFT_RRX }, { "RRX", SHIFT_RRX }
15675};
b99bd4ef 15676
c19d1205
ZW
15677/* Table of all explicit relocation names. */
15678#ifdef OBJ_ELF
15679static struct reloc_entry reloc_names[] =
15680{
15681 { "got", BFD_RELOC_ARM_GOT32 }, { "GOT", BFD_RELOC_ARM_GOT32 },
15682 { "gotoff", BFD_RELOC_ARM_GOTOFF }, { "GOTOFF", BFD_RELOC_ARM_GOTOFF },
15683 { "plt", BFD_RELOC_ARM_PLT32 }, { "PLT", BFD_RELOC_ARM_PLT32 },
15684 { "target1", BFD_RELOC_ARM_TARGET1 }, { "TARGET1", BFD_RELOC_ARM_TARGET1 },
15685 { "target2", BFD_RELOC_ARM_TARGET2 }, { "TARGET2", BFD_RELOC_ARM_TARGET2 },
15686 { "sbrel", BFD_RELOC_ARM_SBREL32 }, { "SBREL", BFD_RELOC_ARM_SBREL32 },
15687 { "tlsgd", BFD_RELOC_ARM_TLS_GD32}, { "TLSGD", BFD_RELOC_ARM_TLS_GD32},
15688 { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
15689 { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
15690 { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
15691 { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
15692};
15693#endif
b99bd4ef 15694
c19d1205
ZW
15695/* Table of all conditional affixes. 0xF is not defined as a condition code. */
15696static const struct asm_cond conds[] =
15697{
15698 {"eq", 0x0},
15699 {"ne", 0x1},
15700 {"cs", 0x2}, {"hs", 0x2},
15701 {"cc", 0x3}, {"ul", 0x3}, {"lo", 0x3},
15702 {"mi", 0x4},
15703 {"pl", 0x5},
15704 {"vs", 0x6},
15705 {"vc", 0x7},
15706 {"hi", 0x8},
15707 {"ls", 0x9},
15708 {"ge", 0xa},
15709 {"lt", 0xb},
15710 {"gt", 0xc},
15711 {"le", 0xd},
15712 {"al", 0xe}
15713};
bfae80f2 15714
62b3e311
PB
15715static struct asm_barrier_opt barrier_opt_names[] =
15716{
15717 { "sy", 0xf },
15718 { "un", 0x7 },
15719 { "st", 0xe },
15720 { "unst", 0x6 }
15721};
15722
c19d1205
ZW
15723/* Table of ARM-format instructions. */
15724
15725/* Macros for gluing together operand strings. N.B. In all cases
15726 other than OPS0, the trailing OP_stop comes from default
15727 zero-initialization of the unspecified elements of the array. */
15728#define OPS0() { OP_stop, }
15729#define OPS1(a) { OP_##a, }
15730#define OPS2(a,b) { OP_##a,OP_##b, }
15731#define OPS3(a,b,c) { OP_##a,OP_##b,OP_##c, }
15732#define OPS4(a,b,c,d) { OP_##a,OP_##b,OP_##c,OP_##d, }
15733#define OPS5(a,b,c,d,e) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e, }
15734#define OPS6(a,b,c,d,e,f) { OP_##a,OP_##b,OP_##c,OP_##d,OP_##e,OP_##f, }
15735
15736/* These macros abstract out the exact format of the mnemonic table and
15737 save some repeated characters. */
15738
15739/* The normal sort of mnemonic; has a Thumb variant; takes a conditional suffix. */
15740#define TxCE(mnem, op, top, nops, ops, ae, te) \
15741 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, top, ARM_VARIANT, \
1887dd22 15742 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15743
15744/* Two variants of the above - TCE for a numeric Thumb opcode, tCE for
15745 a T_MNEM_xyz enumerator. */
15746#define TCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15747 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 15748#define tCE(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15749 TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15750
15751/* Second most common sort of mnemonic: has a Thumb variant, takes a conditional
15752 infix after the third character. */
15753#define TxC3(mnem, op, top, nops, ops, ae, te) \
15754 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, top, ARM_VARIANT, \
1887dd22 15755 THUMB_VARIANT, do_##ae, do_##te }
088fa78e
KH
15756#define TxC3w(mnem, op, top, nops, ops, ae, te) \
15757 { #mnem, OPS##nops ops, OT_cinfix3_deprecated, 0x##op, top, ARM_VARIANT, \
15758 THUMB_VARIANT, do_##ae, do_##te }
c19d1205 15759#define TC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15760 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
088fa78e 15761#define TC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15762 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
c19d1205 15763#define tC3(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15764 TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
088fa78e 15765#define tC3w(mnem, aop, top, nops, ops, ae, te) \
e07e6e58 15766 TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15767
15768/* Mnemonic with a conditional infix in an unusual place. Each and every variant has to
15769 appear in the condition table. */
15770#define TxCM_(m1, m2, m3, op, top, nops, ops, ae, te) \
e07e6e58 15771 { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
1887dd22 15772 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15773
15774#define TxCM(m1, m2, op, top, nops, ops, ae, te) \
e07e6e58
NC
15775 TxCM_ (m1, , m2, op, top, nops, ops, ae, te), \
15776 TxCM_ (m1, eq, m2, op, top, nops, ops, ae, te), \
15777 TxCM_ (m1, ne, m2, op, top, nops, ops, ae, te), \
15778 TxCM_ (m1, cs, m2, op, top, nops, ops, ae, te), \
15779 TxCM_ (m1, hs, m2, op, top, nops, ops, ae, te), \
15780 TxCM_ (m1, cc, m2, op, top, nops, ops, ae, te), \
15781 TxCM_ (m1, ul, m2, op, top, nops, ops, ae, te), \
15782 TxCM_ (m1, lo, m2, op, top, nops, ops, ae, te), \
15783 TxCM_ (m1, mi, m2, op, top, nops, ops, ae, te), \
15784 TxCM_ (m1, pl, m2, op, top, nops, ops, ae, te), \
15785 TxCM_ (m1, vs, m2, op, top, nops, ops, ae, te), \
15786 TxCM_ (m1, vc, m2, op, top, nops, ops, ae, te), \
15787 TxCM_ (m1, hi, m2, op, top, nops, ops, ae, te), \
15788 TxCM_ (m1, ls, m2, op, top, nops, ops, ae, te), \
15789 TxCM_ (m1, ge, m2, op, top, nops, ops, ae, te), \
15790 TxCM_ (m1, lt, m2, op, top, nops, ops, ae, te), \
15791 TxCM_ (m1, gt, m2, op, top, nops, ops, ae, te), \
15792 TxCM_ (m1, le, m2, op, top, nops, ops, ae, te), \
15793 TxCM_ (m1, al, m2, op, top, nops, ops, ae, te)
c19d1205
ZW
15794
15795#define TCM(m1,m2, aop, top, nops, ops, ae, te) \
e07e6e58
NC
15796 TxCM (m1,m2, aop, 0x##top, nops, ops, ae, te)
15797#define tCM(m1,m2, aop, top, nops, ops, ae, te) \
15798 TxCM (m1,m2, aop, T_MNEM_##top, nops, ops, ae, te)
c19d1205
ZW
15799
15800/* Mnemonic that cannot be conditionalized. The ARM condition-code
dfa9f0d5
PB
15801 field is still 0xE. Many of the Thumb variants can be executed
15802 conditionally, so this is checked separately. */
c19d1205
ZW
15803#define TUE(mnem, op, top, nops, ops, ae, te) \
15804 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15805 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15806
15807/* Mnemonic that cannot be conditionalized, and bears 0xF in its ARM
15808 condition code field. */
15809#define TUF(mnem, op, top, nops, ops, ae, te) \
15810 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##top, ARM_VARIANT, \
1887dd22 15811 THUMB_VARIANT, do_##ae, do_##te }
c19d1205
ZW
15812
15813/* ARM-only variants of all the above. */
6a86118a
NC
15814#define CE(mnem, op, nops, ops, ae) \
15815 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15816
15817#define C3(mnem, op, nops, ops, ae) \
15818 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15819
e3cb604e
PB
15820/* Legacy mnemonics that always have conditional infix after the third
15821 character. */
15822#define CL(mnem, op, nops, ops, ae) \
15823 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15824 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15825
8f06b2d8
PB
15826/* Coprocessor instructions. Isomorphic between Arm and Thumb-2. */
15827#define cCE(mnem, op, nops, ops, ae) \
15828 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15829
e3cb604e
PB
15830/* Legacy coprocessor instructions where conditional infix and conditional
15831 suffix are ambiguous. For consistency this includes all FPA instructions,
15832 not just the potentially ambiguous ones. */
15833#define cCL(mnem, op, nops, ops, ae) \
15834 { #mnem, OPS##nops ops, OT_cinfix3_legacy, \
15835 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
15836
15837/* Coprocessor, takes either a suffix or a position-3 infix
15838 (for an FPA corner case). */
15839#define C3E(mnem, op, nops, ops, ae) \
15840 { #mnem, OPS##nops ops, OT_csuf_or_in3, \
15841 0x##op, 0xe##op, ARM_VARIANT, ARM_VARIANT, do_##ae, do_##ae }
8f06b2d8 15842
6a86118a
NC
15843#define xCM_(m1, m2, m3, op, nops, ops, ae) \
15844 { #m1 #m2 #m3, OPS##nops ops, \
e07e6e58 15845 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
6a86118a
NC
15846 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15847
15848#define CM(m1, m2, op, nops, ops, ae) \
e07e6e58
NC
15849 xCM_ (m1, , m2, op, nops, ops, ae), \
15850 xCM_ (m1, eq, m2, op, nops, ops, ae), \
15851 xCM_ (m1, ne, m2, op, nops, ops, ae), \
15852 xCM_ (m1, cs, m2, op, nops, ops, ae), \
15853 xCM_ (m1, hs, m2, op, nops, ops, ae), \
15854 xCM_ (m1, cc, m2, op, nops, ops, ae), \
15855 xCM_ (m1, ul, m2, op, nops, ops, ae), \
15856 xCM_ (m1, lo, m2, op, nops, ops, ae), \
15857 xCM_ (m1, mi, m2, op, nops, ops, ae), \
15858 xCM_ (m1, pl, m2, op, nops, ops, ae), \
15859 xCM_ (m1, vs, m2, op, nops, ops, ae), \
15860 xCM_ (m1, vc, m2, op, nops, ops, ae), \
15861 xCM_ (m1, hi, m2, op, nops, ops, ae), \
15862 xCM_ (m1, ls, m2, op, nops, ops, ae), \
15863 xCM_ (m1, ge, m2, op, nops, ops, ae), \
15864 xCM_ (m1, lt, m2, op, nops, ops, ae), \
15865 xCM_ (m1, gt, m2, op, nops, ops, ae), \
15866 xCM_ (m1, le, m2, op, nops, ops, ae), \
15867 xCM_ (m1, al, m2, op, nops, ops, ae)
6a86118a
NC
15868
15869#define UE(mnem, op, nops, ops, ae) \
15870 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15871
15872#define UF(mnem, op, nops, ops, ae) \
15873 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15874
5287ad62
JB
15875/* Neon data-processing. ARM versions are unconditional with cond=0xf.
15876 The Thumb and ARM variants are mostly the same (bits 0-23 and 24/28), so we
15877 use the same encoding function for each. */
15878#define NUF(mnem, op, nops, ops, enc) \
15879 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0x##op, \
15880 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15881
15882/* Neon data processing, version which indirects through neon_enc_tab for
15883 the various overloaded versions of opcodes. */
15884#define nUF(mnem, op, nops, ops, enc) \
15885 { #mnem, OPS##nops ops, OT_unconditionalF, N_MNEM_##op, N_MNEM_##op, \
15886 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15887
15888/* Neon insn with conditional suffix for the ARM version, non-overloaded
15889 version. */
037e8744
JB
15890#define NCE_tag(mnem, op, nops, ops, enc, tag) \
15891 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
5287ad62
JB
15892 THUMB_VARIANT, do_##enc, do_##enc }
15893
037e8744 15894#define NCE(mnem, op, nops, ops, enc) \
e07e6e58 15895 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
15896
15897#define NCEF(mnem, op, nops, ops, enc) \
e07e6e58 15898 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 15899
5287ad62 15900/* Neon insn with conditional suffix for the ARM version, overloaded types. */
037e8744
JB
15901#define nCE_tag(mnem, op, nops, ops, enc, tag) \
15902 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
5287ad62
JB
15903 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15904
037e8744 15905#define nCE(mnem, op, nops, ops, enc) \
e07e6e58 15906 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
037e8744
JB
15907
15908#define nCEF(mnem, op, nops, ops, enc) \
e07e6e58 15909 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
037e8744 15910
c19d1205
ZW
15911#define do_0 0
15912
15913/* Thumb-only, unconditional. */
e07e6e58 15914#define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
c19d1205 15915
c19d1205 15916static const struct asm_opcode insns[] =
bfae80f2 15917{
e74cfd16
PB
15918#define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15919#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
15920 tCE(and, 0000000, and, 3, (RR, oRR, SH), arit, t_arit3c),
15921 tC3(ands, 0100000, ands, 3, (RR, oRR, SH), arit, t_arit3c),
15922 tCE(eor, 0200000, eor, 3, (RR, oRR, SH), arit, t_arit3c),
15923 tC3(eors, 0300000, eors, 3, (RR, oRR, SH), arit, t_arit3c),
15924 tCE(sub, 0400000, sub, 3, (RR, oRR, SH), arit, t_add_sub),
15925 tC3(subs, 0500000, subs, 3, (RR, oRR, SH), arit, t_add_sub),
4962c51a
MS
15926 tCE(add, 0800000, add, 3, (RR, oRR, SHG), arit, t_add_sub),
15927 tC3(adds, 0900000, adds, 3, (RR, oRR, SHG), arit, t_add_sub),
c19d1205
ZW
15928 tCE(adc, 0a00000, adc, 3, (RR, oRR, SH), arit, t_arit3c),
15929 tC3(adcs, 0b00000, adcs, 3, (RR, oRR, SH), arit, t_arit3c),
15930 tCE(sbc, 0c00000, sbc, 3, (RR, oRR, SH), arit, t_arit3),
15931 tC3(sbcs, 0d00000, sbcs, 3, (RR, oRR, SH), arit, t_arit3),
15932 tCE(orr, 1800000, orr, 3, (RR, oRR, SH), arit, t_arit3c),
15933 tC3(orrs, 1900000, orrs, 3, (RR, oRR, SH), arit, t_arit3c),
15934 tCE(bic, 1c00000, bic, 3, (RR, oRR, SH), arit, t_arit3),
15935 tC3(bics, 1d00000, bics, 3, (RR, oRR, SH), arit, t_arit3),
15936
15937 /* The p-variants of tst/cmp/cmn/teq (below) are the pre-V6 mechanism
15938 for setting PSR flag bits. They are obsolete in V6 and do not
15939 have Thumb equivalents. */
15940 tCE(tst, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15941 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15942 CL(tstp, 110f000, 2, (RR, SH), cmp),
c19d1205 15943 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
088fa78e 15944 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
e3cb604e 15945 CL(cmpp, 150f000, 2, (RR, SH), cmp),
c19d1205 15946 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 15947 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 15948 CL(cmnp, 170f000, 2, (RR, SH), cmp),
c19d1205
ZW
15949
15950 tCE(mov, 1a00000, mov, 2, (RR, SH), mov, t_mov_cmp),
15951 tC3(movs, 1b00000, movs, 2, (RR, SH), mov, t_mov_cmp),
15952 tCE(mvn, 1e00000, mvn, 2, (RR, SH), mov, t_mvn_tst),
15953 tC3(mvns, 1f00000, mvns, 2, (RR, SH), mov, t_mvn_tst),
15954
4962c51a
MS
15955 tCE(ldr, 4100000, ldr, 2, (RR, ADDRGLDR),ldst, t_ldst),
15956 tC3(ldrb, 4500000, ldrb, 2, (RR, ADDRGLDR),ldst, t_ldst),
15957 tCE(str, 4000000, str, 2, (RR, ADDRGLDR),ldst, t_ldst),
15958 tC3(strb, 4400000, strb, 2, (RR, ADDRGLDR),ldst, t_ldst),
c19d1205 15959
f5208ef2 15960 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15961 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15962 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
f5208ef2 15963 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
15964 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15965 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15966
15967 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
c16d2bf0 15968 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
0110f2b8 15969 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
39b41c9c 15970 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
bfae80f2 15971
c19d1205 15972 /* Pseudo ops. */
e9f89963 15973 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
2fc8bdac
ZW
15974 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15975 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
c19d1205
ZW
15976
15977 /* Thumb-compatibility pseudo ops. */
15978 tCE(lsl, 1a00000, lsl, 3, (RR, oRR, SH), shift, t_shift),
15979 tC3(lsls, 1b00000, lsls, 3, (RR, oRR, SH), shift, t_shift),
15980 tCE(lsr, 1a00020, lsr, 3, (RR, oRR, SH), shift, t_shift),
15981 tC3(lsrs, 1b00020, lsrs, 3, (RR, oRR, SH), shift, t_shift),
15982 tCE(asr, 1a00040, asr, 3, (RR, oRR, SH), shift, t_shift),
2fc8bdac 15983 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
c19d1205
ZW
15984 tCE(ror, 1a00060, ror, 3, (RR, oRR, SH), shift, t_shift),
15985 tC3(rors, 1b00060, rors, 3, (RR, oRR, SH), shift, t_shift),
15986 tCE(neg, 2600000, neg, 2, (RR, RR), rd_rn, t_neg),
15987 tC3(negs, 2700000, negs, 2, (RR, RR), rd_rn, t_neg),
15988 tCE(push, 92d0000, push, 1, (REGLST), push_pop, t_push_pop),
15989 tCE(pop, 8bd0000, pop, 1, (REGLST), push_pop, t_push_pop),
15990
16a4cf17
PB
15991 /* These may simplify to neg. */
15992 TCE(rsb, 0600000, ebc00000, 3, (RR, oRR, SH), arit, t_rsb),
15993 TC3(rsbs, 0700000, ebd00000, 3, (RR, oRR, SH), arit, t_rsb),
15994
c19d1205 15995#undef THUMB_VARIANT
e74cfd16 15996#define THUMB_VARIANT &arm_ext_v6
2fc8bdac 15997 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
c19d1205
ZW
15998
15999 /* V1 instructions with no Thumb analogue prior to V6T2. */
16000#undef THUMB_VARIANT
e74cfd16 16001#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 16002 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
088fa78e 16003 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
e3cb604e 16004 CL(teqp, 130f000, 2, (RR, SH), cmp),
c19d1205
ZW
16005
16006 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 16007 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 16008 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
3e94bf1a 16009 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
c19d1205 16010
9c3c69f2
PB
16011 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16012 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205 16013
9c3c69f2
PB
16014 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16015 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
c19d1205
ZW
16016
16017 /* V1 instructions with no Thumb analogue at all. */
16018 CE(rsc, 0e00000, 3, (RR, oRR, SH), arit),
16019 C3(rscs, 0f00000, 3, (RR, oRR, SH), arit),
16020
16021 C3(stmib, 9800000, 2, (RRw, REGLST), ldmstm),
16022 C3(stmfa, 9800000, 2, (RRw, REGLST), ldmstm),
16023 C3(stmda, 8000000, 2, (RRw, REGLST), ldmstm),
16024 C3(stmed, 8000000, 2, (RRw, REGLST), ldmstm),
16025 C3(ldmib, 9900000, 2, (RRw, REGLST), ldmstm),
16026 C3(ldmed, 9900000, 2, (RRw, REGLST), ldmstm),
16027 C3(ldmda, 8100000, 2, (RRw, REGLST), ldmstm),
16028 C3(ldmfa, 8100000, 2, (RRw, REGLST), ldmstm),
16029
16030#undef ARM_VARIANT
e74cfd16 16031#define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
c19d1205 16032#undef THUMB_VARIANT
e74cfd16 16033#define THUMB_VARIANT &arm_ext_v4t
c19d1205
ZW
16034 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16035 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16036
16037#undef THUMB_VARIANT
e74cfd16 16038#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16039 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16040 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16041
16042 /* Generic coprocessor instructions. */
16043 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
4962c51a
MS
16044 TCE(ldc, c100000, ec100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16045 TC3(ldcl, c500000, ec500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16046 TCE(stc, c000000, ec000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16047 TC3(stcl, c400000, ec400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
16048 TCE(mcr, e000010, ee000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16049 TCE(mrc, e100010, ee100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16050
16051#undef ARM_VARIANT
e74cfd16 16052#define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
c19d1205
ZW
16053 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16054 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16055
16056#undef ARM_VARIANT
e74cfd16 16057#define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
7e806470
PB
16058#undef THUMB_VARIANT
16059#define THUMB_VARIANT &arm_ext_msr
037e8744
JB
16060 TCE(mrs, 10f0000, f3ef8000, 2, (APSR_RR, RVC_PSR), mrs, t_mrs),
16061 TCE(msr, 120f000, f3808000, 2, (RVC_PSR, RR_EXi), msr, t_msr),
c19d1205
ZW
16062
16063#undef ARM_VARIANT
e74cfd16 16064#define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
7e806470
PB
16065#undef THUMB_VARIANT
16066#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16067 TCE(smull, 0c00090, fb800000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16068 CM(smull,s, 0d00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16069 TCE(umull, 0800090, fba00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16070 CM(umull,s, 0900090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16071 TCE(smlal, 0e00090, fbc00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16072 CM(smlal,s, 0f00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16073 TCE(umlal, 0a00090, fbe00000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull, t_mull),
16074 CM(umlal,s, 0b00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mull),
16075
16076#undef ARM_VARIANT
e74cfd16 16077#define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
c19d1205 16078#undef THUMB_VARIANT
e74cfd16 16079#define THUMB_VARIANT &arm_ext_v4t
4962c51a
MS
16080 tC3(ldrh, 01000b0, ldrh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16081 tC3(strh, 00000b0, strh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16082 tC3(ldrsh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16083 tC3(ldrsb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16084 tCM(ld,sh, 01000f0, ldrsh, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
16085 tCM(ld,sb, 01000d0, ldrsb, 2, (RR, ADDRGLDRS), ldstv4, t_ldst),
c19d1205
ZW
16086
16087#undef ARM_VARIANT
e74cfd16 16088#define ARM_VARIANT &arm_ext_v4t_5
c19d1205
ZW
16089 /* ARM Architecture 4T. */
16090 /* Note: bx (and blx) are required on V5, even if the processor does
16091 not support Thumb. */
16092 TCE(bx, 12fff10, 4700, 1, (RR), bx, t_bx),
16093
16094#undef ARM_VARIANT
e74cfd16 16095#define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
c19d1205 16096#undef THUMB_VARIANT
e74cfd16 16097#define THUMB_VARIANT &arm_ext_v5t
c19d1205
ZW
16098 /* Note: blx has 2 variants; the .value coded here is for
16099 BLX(2). Only this variant has conditional execution. */
16100 TCE(blx, 12fff30, 4780, 1, (RR_EXr), blx, t_blx),
16101 TUE(bkpt, 1200070, be00, 1, (oIffffb), bkpt, t_bkpt),
16102
16103#undef THUMB_VARIANT
e74cfd16 16104#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 16105 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
4962c51a
MS
16106 TUF(ldc2, c100000, fc100000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16107 TUF(ldc2l, c500000, fc500000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16108 TUF(stc2, c000000, fc000000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
16109 TUF(stc2l, c400000, fc400000, 3, (RCP, RCN, ADDRGLDC), lstc, lstc),
c19d1205
ZW
16110 TUF(cdp2, e000000, fe000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
16111 TUF(mcr2, e000010, fe000010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16112 TUF(mrc2, e100010, fe100010, 6, (RCP, I7b, RR, RCN, RCN, oI7b), co_reg, co_reg),
16113
16114#undef ARM_VARIANT
e74cfd16 16115#define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
c19d1205
ZW
16116 TCE(smlabb, 1000080, fb100000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16117 TCE(smlatb, 10000a0, fb100020, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16118 TCE(smlabt, 10000c0, fb100010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16119 TCE(smlatt, 10000e0, fb100030, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16120
16121 TCE(smlawb, 1200080, fb300000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16122 TCE(smlawt, 12000c0, fb300010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smla, t_mla),
16123
16124 TCE(smlalbb, 1400080, fbc00080, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16125 TCE(smlaltb, 14000a0, fbc000a0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16126 TCE(smlalbt, 14000c0, fbc00090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16127 TCE(smlaltt, 14000e0, fbc000b0, 4, (RRnpc, RRnpc, RRnpc, RRnpc), smlal, t_mlal),
16128
16129 TCE(smulbb, 1600080, fb10f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16130 TCE(smultb, 16000a0, fb10f020, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16131 TCE(smulbt, 16000c0, fb10f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16132 TCE(smultt, 16000e0, fb10f030, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16133
16134 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16135 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16136
087b80de
JM
16137 TCE(qadd, 1000050, fa80f080, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16138 TCE(qdadd, 1400050, fa80f090, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16139 TCE(qsub, 1200050, fa80f0a0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
16140 TCE(qdsub, 1600050, fa80f0b0, 3, (RRnpc, RRnpc, RRnpc), rd_rm_rn, t_simd),
c19d1205
ZW
16141
16142#undef ARM_VARIANT
e74cfd16 16143#define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
c19d1205 16144 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
79d49516
PB
16145 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16146 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
c19d1205
ZW
16147
16148 TCE(mcrr, c400000, ec400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16149 TCE(mrrc, c500000, ec500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16150
16151#undef ARM_VARIANT
e74cfd16 16152#define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
c19d1205
ZW
16153 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16154
16155#undef ARM_VARIANT
e74cfd16 16156#define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
c19d1205 16157#undef THUMB_VARIANT
e74cfd16 16158#define THUMB_VARIANT &arm_ext_v6
c19d1205
ZW
16159 TUF(cpsie, 1080000, b660, 2, (CPSF, oI31b), cpsi, t_cpsi),
16160 TUF(cpsid, 10c0000, b670, 2, (CPSF, oI31b), cpsi, t_cpsi),
16161 tCE(rev, 6bf0f30, rev, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16162 tCE(rev16, 6bf0fb0, rev16, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16163 tCE(revsh, 6ff0fb0, revsh, 2, (RRnpc, RRnpc), rd_rm, t_rev),
16164 tCE(sxth, 6bf0070, sxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16165 tCE(uxth, 6ff0070, uxth, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16166 tCE(sxtb, 6af0070, sxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16167 tCE(uxtb, 6ef0070, uxtb, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16168 TUF(setend, 1010000, b650, 1, (ENDI), setend, t_setend),
16169
16170#undef THUMB_VARIANT
e74cfd16 16171#define THUMB_VARIANT &arm_ext_v6t2
c19d1205 16172 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
91568d08 16173 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
c19d1205
ZW
16174 TUF(mcrr2, c400000, fc400000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
16175 TUF(mrrc2, c500000, fc500000, 5, (RCP, I15b, RRnpc, RRnpc, RCN), co_reg2c, co_reg2c),
62b3e311
PB
16176
16177 TCE(ssat, 6a00010, f3000000, 4, (RRnpc, I32, RRnpc, oSHllar),ssat, t_ssat),
16178 TCE(usat, 6e00010, f3800000, 4, (RRnpc, I31, RRnpc, oSHllar),usat, t_usat),
16179
16180/* ARM V6 not included in V7M (eg. integer SIMD). */
16181#undef THUMB_VARIANT
16182#define THUMB_VARIANT &arm_ext_v6_notm
dfa9f0d5 16183 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
c19d1205
ZW
16184 TCE(pkhbt, 6800010, eac00000, 4, (RRnpc, RRnpc, RRnpc, oSHll), pkhbt, t_pkhbt),
16185 TCE(pkhtb, 6800050, eac00020, 4, (RRnpc, RRnpc, RRnpc, oSHar), pkhtb, t_pkhtb),
16186 TCE(qadd16, 6200f10, fa90f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16187 TCE(qadd8, 6200f90, fa80f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16188 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16189 /* Old name for QASX. */
c19d1205 16190 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16191 TCE(qsax, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16192 /* Old name for QSAX. */
16193 TCE(qsubaddx, 6200f50, fae0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16194 TCE(qsub16, 6200f70, fad0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16195 TCE(qsub8, 6200ff0, fac0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16196 TCE(sadd16, 6100f10, fa90f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16197 TCE(sadd8, 6100f90, fa80f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16198 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16199 /* Old name for SASX. */
c19d1205
ZW
16200 TCE(saddsubx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16201 TCE(shadd16, 6300f10, fa90f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16202 TCE(shadd8, 6300f90, fa80f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16203 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16204 /* Old name for SHASX. */
c19d1205 16205 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16206 TCE(shsax, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16207 /* Old name for SHSAX. */
16208 TCE(shsubaddx, 6300f50, fae0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16209 TCE(shsub16, 6300f70, fad0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16210 TCE(shsub8, 6300ff0, fac0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16211 TCE(ssax, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16212 /* Old name for SSAX. */
16213 TCE(ssubaddx, 6100f50, fae0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16214 TCE(ssub16, 6100f70, fad0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16215 TCE(ssub8, 6100ff0, fac0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16216 TCE(uadd16, 6500f10, fa90f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16217 TCE(uadd8, 6500f90, fa80f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16218 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16219 /* Old name for UASX. */
c19d1205
ZW
16220 TCE(uaddsubx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16221 TCE(uhadd16, 6700f10, fa90f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16222 TCE(uhadd8, 6700f90, fa80f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16223 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16224 /* Old name for UHASX. */
c19d1205 16225 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16226 TCE(uhsax, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16227 /* Old name for UHSAX. */
16228 TCE(uhsubaddx, 6700f50, fae0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16229 TCE(uhsub16, 6700f70, fad0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16230 TCE(uhsub8, 6700ff0, fac0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16231 TCE(uqadd16, 6600f10, fa90f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16232 TCE(uqadd8, 6600f90, fa80f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16233 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16234 /* Old name for UQASX. */
c19d1205 16235 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16236 TCE(uqsax, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16237 /* Old name for UQSAX. */
16238 TCE(uqsubaddx, 6600f50, fae0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16239 TCE(uqsub16, 6600f70, fad0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16240 TCE(uqsub8, 6600ff0, fac0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205 16241 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e
JM
16242 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16243 /* Old name for USAX. */
c19d1205 16244 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
4f80ef3e 16245 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16246 TUF(rfeia, 8900a00, e990c000, 1, (RRw), rfe, rfe),
16247 UF(rfeib, 9900a00, 1, (RRw), rfe),
16248 UF(rfeda, 8100a00, 1, (RRw), rfe),
16249 TUF(rfedb, 9100a00, e810c000, 1, (RRw), rfe, rfe),
16250 TUF(rfefd, 8900a00, e990c000, 1, (RRw), rfe, rfe),
16251 UF(rfefa, 9900a00, 1, (RRw), rfe),
16252 UF(rfeea, 8100a00, 1, (RRw), rfe),
16253 TUF(rfeed, 9100a00, e810c000, 1, (RRw), rfe, rfe),
16254 TCE(sxtah, 6b00070, fa00f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16255 TCE(sxtab16, 6800070, fa20f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16256 TCE(sxtab, 6a00070, fa40f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16257 TCE(sxtb16, 68f0070, fa2ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
16258 TCE(uxtah, 6f00070, fa10f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16259 TCE(uxtab16, 6c00070, fa30f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16260 TCE(uxtab, 6e00070, fa50f080, 4, (RRnpc, RRnpc, RRnpc, oROR), sxtah, t_sxtah),
16261 TCE(uxtb16, 6cf0070, fa3ff080, 3, (RRnpc, RRnpc, oROR), sxth, t_sxth),
f1022c90 16262 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
c19d1205
ZW
16263 TCE(smlad, 7000010, fb200000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16264 TCE(smladx, 7000030, fb200010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16265 TCE(smlald, 7400010, fbc000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16266 TCE(smlaldx, 7400030, fbc000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16267 TCE(smlsd, 7000050, fb400000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16268 TCE(smlsdx, 7000070, fb400010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16269 TCE(smlsld, 7400050, fbd000c0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16270 TCE(smlsldx, 7400070, fbd000d0, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal,t_mlal),
16271 TCE(smmla, 7500010, fb500000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16272 TCE(smmlar, 7500030, fb500010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16273 TCE(smmls, 75000d0, fb600000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16274 TCE(smmlsr, 75000f0, fb600010, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
16275 TCE(smmul, 750f010, fb50f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16276 TCE(smmulr, 750f030, fb50f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16277 TCE(smuad, 700f010, fb20f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16278 TCE(smuadx, 700f030, fb20f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16279 TCE(smusd, 700f050, fb40f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16280 TCE(smusdx, 700f070, fb40f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
b6702015
PB
16281 TUF(srsia, 8c00500, e980c000, 2, (oRRw, I31w), srs, srs),
16282 UF(srsib, 9c00500, 2, (oRRw, I31w), srs),
16283 UF(srsda, 8400500, 2, (oRRw, I31w), srs),
16284 TUF(srsdb, 9400500, e800c000, 2, (oRRw, I31w), srs, srs),
c19d1205 16285 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
c19d1205
ZW
16286 TCE(umaal, 0400090, fbe00060, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smlal, t_mlal),
16287 TCE(usad8, 780f010, fb70f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16288 TCE(usada8, 7800010, fb700000, 4, (RRnpc, RRnpc, RRnpc, RRnpc),smla, t_mla),
c19d1205
ZW
16289 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16290
16291#undef ARM_VARIANT
e74cfd16 16292#define ARM_VARIANT &arm_ext_v6k
c19d1205 16293#undef THUMB_VARIANT
e74cfd16 16294#define THUMB_VARIANT &arm_ext_v6k
c19d1205
ZW
16295 tCE(yield, 320f001, yield, 0, (), noargs, t_hint),
16296 tCE(wfe, 320f002, wfe, 0, (), noargs, t_hint),
16297 tCE(wfi, 320f003, wfi, 0, (), noargs, t_hint),
16298 tCE(sev, 320f004, sev, 0, (), noargs, t_hint),
16299
ebdca51a
PB
16300#undef THUMB_VARIANT
16301#define THUMB_VARIANT &arm_ext_v6_notm
16302 TCE(ldrexd, 1b00f9f, e8d0007f, 3, (RRnpc, oRRnpc, RRnpcb), ldrexd, t_ldrexd),
16303 TCE(strexd, 1a00f90, e8c00070, 4, (RRnpc, RRnpc, oRRnpc, RRnpcb), strexd, t_strexd),
16304
c19d1205 16305#undef THUMB_VARIANT
e74cfd16 16306#define THUMB_VARIANT &arm_ext_v6t2
c19d1205
ZW
16307 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16308 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
c19d1205
ZW
16309 TCE(strexb, 1c00f90, e8c00f40, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
16310 TCE(strexh, 1e00f90, e8c00f50, 3, (RRnpc, RRnpc, ADDR), strex, rm_rd_rn),
c19d1205
ZW
16311 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16312
16313#undef ARM_VARIANT
e74cfd16 16314#define ARM_VARIANT &arm_ext_v6z
3eb17e6b 16315 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
c19d1205
ZW
16316
16317#undef ARM_VARIANT
e74cfd16 16318#define ARM_VARIANT &arm_ext_v6t2
c19d1205
ZW
16319 TCE(bfc, 7c0001f, f36f0000, 3, (RRnpc, I31, I32), bfc, t_bfc),
16320 TCE(bfi, 7c00010, f3600000, 4, (RRnpc, RRnpc_I0, I31, I32), bfi, t_bfi),
16321 TCE(sbfx, 7a00050, f3400000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16322 TCE(ubfx, 7e00050, f3c00000, 4, (RR, RR, I31, I32), bfx, t_bfx),
16323
16324 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
b6895b4f
PB
16325 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16326 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
401a54cf 16327 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
c19d1205
ZW
16328
16329 TC3(ldrht, 03000b0, f8300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16330 TC3(ldrsht, 03000f0, f9300e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16331 TC3(ldrsbt, 03000d0, f9100e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16332 TC3(strht, 02000b0, f8200e00, 2, (RR, ADDR), ldsttv4, t_ldstt),
16333
25fe350b
MS
16334 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
16335 UT(cbz, b100, 2, (RR, EXP), t_cbz),
e07e6e58
NC
16336 /* ARM does not really have an IT instruction, so always allow it. The opcode
16337 is copied from Thumb in order to allow warnings
16338 in -mimplicit-it=[never | arm] modes. */
f91e006c
PB
16339#undef ARM_VARIANT
16340#define ARM_VARIANT &arm_ext_v1
e07e6e58
NC
16341 TUE(it, bf08, bf08, 1, (COND), it, t_it),
16342 TUE(itt, bf0c, bf0c, 1, (COND), it, t_it),
16343 TUE(ite, bf04, bf04, 1, (COND), it, t_it),
16344 TUE(ittt, bf0e, bf0e, 1, (COND), it, t_it),
16345 TUE(itet, bf06, bf06, 1, (COND), it, t_it),
16346 TUE(itte, bf0a, bf0a, 1, (COND), it, t_it),
16347 TUE(itee, bf02, bf02, 1, (COND), it, t_it),
16348 TUE(itttt, bf0f, bf0f, 1, (COND), it, t_it),
16349 TUE(itett, bf07, bf07, 1, (COND), it, t_it),
16350 TUE(ittet, bf0b, bf0b, 1, (COND), it, t_it),
16351 TUE(iteet, bf03, bf03, 1, (COND), it, t_it),
16352 TUE(ittte, bf0d, bf0d, 1, (COND), it, t_it),
16353 TUE(itete, bf05, bf05, 1, (COND), it, t_it),
16354 TUE(ittee, bf09, bf09, 1, (COND), it, t_it),
16355 TUE(iteee, bf01, bf01, 1, (COND), it, t_it),
1c444d06
JM
16356 /* ARM/Thumb-2 instructions with no Thumb-1 equivalent. */
16357 TC3(rrx, 01a00060, ea4f0030, 2, (RR, RR), rd_rm, t_rrx),
16358 TC3(rrxs, 01b00060, ea5f0030, 2, (RR, RR), rd_rm, t_rrx),
c19d1205 16359
92e90b6e
PB
16360 /* Thumb2 only instructions. */
16361#undef ARM_VARIANT
e74cfd16 16362#define ARM_VARIANT NULL
92e90b6e
PB
16363
16364 TCE(addw, 0, f2000000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
16365 TCE(subw, 0, f2a00000, 3, (RR, RR, EXPi), 0, t_add_sub_w),
1c444d06
JM
16366 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16367 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
92e90b6e
PB
16368 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
16369 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
16370
62b3e311
PB
16371 /* Thumb-2 hardware division instructions (R and M profiles only). */
16372#undef THUMB_VARIANT
16373#define THUMB_VARIANT &arm_ext_div
16374 TCE(sdiv, 0, fb90f0f0, 3, (RR, oRR, RR), 0, t_div),
16375 TCE(udiv, 0, fbb0f0f0, 3, (RR, oRR, RR), 0, t_div),
16376
7e806470
PB
16377 /* ARM V6M/V7 instructions. */
16378#undef ARM_VARIANT
16379#define ARM_VARIANT &arm_ext_barrier
16380#undef THUMB_VARIANT
16381#define THUMB_VARIANT &arm_ext_barrier
16382 TUF(dmb, 57ff050, f3bf8f50, 1, (oBARRIER), barrier, t_barrier),
16383 TUF(dsb, 57ff040, f3bf8f40, 1, (oBARRIER), barrier, t_barrier),
16384 TUF(isb, 57ff060, f3bf8f60, 1, (oBARRIER), barrier, t_barrier),
16385
62b3e311
PB
16386 /* ARM V7 instructions. */
16387#undef ARM_VARIANT
16388#define ARM_VARIANT &arm_ext_v7
16389#undef THUMB_VARIANT
16390#define THUMB_VARIANT &arm_ext_v7
16391 TUF(pli, 450f000, f910f000, 1, (ADDR), pli, t_pld),
16392 TCE(dbg, 320f0f0, f3af80f0, 1, (I15), dbg, t_dbg),
62b3e311 16393
c19d1205 16394#undef ARM_VARIANT
e74cfd16 16395#define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
8f06b2d8
PB
16396 cCE(wfs, e200110, 1, (RR), rd),
16397 cCE(rfs, e300110, 1, (RR), rd),
16398 cCE(wfc, e400110, 1, (RR), rd),
16399 cCE(rfc, e500110, 1, (RR), rd),
16400
4962c51a
MS
16401 cCL(ldfs, c100100, 2, (RF, ADDRGLDC), rd_cpaddr),
16402 cCL(ldfd, c108100, 2, (RF, ADDRGLDC), rd_cpaddr),
16403 cCL(ldfe, c500100, 2, (RF, ADDRGLDC), rd_cpaddr),
16404 cCL(ldfp, c508100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e 16405
4962c51a
MS
16406 cCL(stfs, c000100, 2, (RF, ADDRGLDC), rd_cpaddr),
16407 cCL(stfd, c008100, 2, (RF, ADDRGLDC), rd_cpaddr),
16408 cCL(stfe, c400100, 2, (RF, ADDRGLDC), rd_cpaddr),
16409 cCL(stfp, c408100, 2, (RF, ADDRGLDC), rd_cpaddr),
e3cb604e
PB
16410
16411 cCL(mvfs, e008100, 2, (RF, RF_IF), rd_rm),
16412 cCL(mvfsp, e008120, 2, (RF, RF_IF), rd_rm),
16413 cCL(mvfsm, e008140, 2, (RF, RF_IF), rd_rm),
16414 cCL(mvfsz, e008160, 2, (RF, RF_IF), rd_rm),
16415 cCL(mvfd, e008180, 2, (RF, RF_IF), rd_rm),
16416 cCL(mvfdp, e0081a0, 2, (RF, RF_IF), rd_rm),
16417 cCL(mvfdm, e0081c0, 2, (RF, RF_IF), rd_rm),
16418 cCL(mvfdz, e0081e0, 2, (RF, RF_IF), rd_rm),
16419 cCL(mvfe, e088100, 2, (RF, RF_IF), rd_rm),
16420 cCL(mvfep, e088120, 2, (RF, RF_IF), rd_rm),
16421 cCL(mvfem, e088140, 2, (RF, RF_IF), rd_rm),
16422 cCL(mvfez, e088160, 2, (RF, RF_IF), rd_rm),
16423
16424 cCL(mnfs, e108100, 2, (RF, RF_IF), rd_rm),
16425 cCL(mnfsp, e108120, 2, (RF, RF_IF), rd_rm),
16426 cCL(mnfsm, e108140, 2, (RF, RF_IF), rd_rm),
16427 cCL(mnfsz, e108160, 2, (RF, RF_IF), rd_rm),
16428 cCL(mnfd, e108180, 2, (RF, RF_IF), rd_rm),
16429 cCL(mnfdp, e1081a0, 2, (RF, RF_IF), rd_rm),
16430 cCL(mnfdm, e1081c0, 2, (RF, RF_IF), rd_rm),
16431 cCL(mnfdz, e1081e0, 2, (RF, RF_IF), rd_rm),
16432 cCL(mnfe, e188100, 2, (RF, RF_IF), rd_rm),
16433 cCL(mnfep, e188120, 2, (RF, RF_IF), rd_rm),
16434 cCL(mnfem, e188140, 2, (RF, RF_IF), rd_rm),
16435 cCL(mnfez, e188160, 2, (RF, RF_IF), rd_rm),
16436
16437 cCL(abss, e208100, 2, (RF, RF_IF), rd_rm),
16438 cCL(abssp, e208120, 2, (RF, RF_IF), rd_rm),
16439 cCL(abssm, e208140, 2, (RF, RF_IF), rd_rm),
16440 cCL(abssz, e208160, 2, (RF, RF_IF), rd_rm),
16441 cCL(absd, e208180, 2, (RF, RF_IF), rd_rm),
16442 cCL(absdp, e2081a0, 2, (RF, RF_IF), rd_rm),
16443 cCL(absdm, e2081c0, 2, (RF, RF_IF), rd_rm),
16444 cCL(absdz, e2081e0, 2, (RF, RF_IF), rd_rm),
16445 cCL(abse, e288100, 2, (RF, RF_IF), rd_rm),
16446 cCL(absep, e288120, 2, (RF, RF_IF), rd_rm),
16447 cCL(absem, e288140, 2, (RF, RF_IF), rd_rm),
16448 cCL(absez, e288160, 2, (RF, RF_IF), rd_rm),
16449
16450 cCL(rnds, e308100, 2, (RF, RF_IF), rd_rm),
16451 cCL(rndsp, e308120, 2, (RF, RF_IF), rd_rm),
16452 cCL(rndsm, e308140, 2, (RF, RF_IF), rd_rm),
16453 cCL(rndsz, e308160, 2, (RF, RF_IF), rd_rm),
16454 cCL(rndd, e308180, 2, (RF, RF_IF), rd_rm),
16455 cCL(rnddp, e3081a0, 2, (RF, RF_IF), rd_rm),
16456 cCL(rnddm, e3081c0, 2, (RF, RF_IF), rd_rm),
16457 cCL(rnddz, e3081e0, 2, (RF, RF_IF), rd_rm),
16458 cCL(rnde, e388100, 2, (RF, RF_IF), rd_rm),
16459 cCL(rndep, e388120, 2, (RF, RF_IF), rd_rm),
16460 cCL(rndem, e388140, 2, (RF, RF_IF), rd_rm),
16461 cCL(rndez, e388160, 2, (RF, RF_IF), rd_rm),
16462
16463 cCL(sqts, e408100, 2, (RF, RF_IF), rd_rm),
16464 cCL(sqtsp, e408120, 2, (RF, RF_IF), rd_rm),
16465 cCL(sqtsm, e408140, 2, (RF, RF_IF), rd_rm),
16466 cCL(sqtsz, e408160, 2, (RF, RF_IF), rd_rm),
16467 cCL(sqtd, e408180, 2, (RF, RF_IF), rd_rm),
16468 cCL(sqtdp, e4081a0, 2, (RF, RF_IF), rd_rm),
16469 cCL(sqtdm, e4081c0, 2, (RF, RF_IF), rd_rm),
16470 cCL(sqtdz, e4081e0, 2, (RF, RF_IF), rd_rm),
16471 cCL(sqte, e488100, 2, (RF, RF_IF), rd_rm),
16472 cCL(sqtep, e488120, 2, (RF, RF_IF), rd_rm),
16473 cCL(sqtem, e488140, 2, (RF, RF_IF), rd_rm),
16474 cCL(sqtez, e488160, 2, (RF, RF_IF), rd_rm),
16475
16476 cCL(logs, e508100, 2, (RF, RF_IF), rd_rm),
16477 cCL(logsp, e508120, 2, (RF, RF_IF), rd_rm),
16478 cCL(logsm, e508140, 2, (RF, RF_IF), rd_rm),
16479 cCL(logsz, e508160, 2, (RF, RF_IF), rd_rm),
16480 cCL(logd, e508180, 2, (RF, RF_IF), rd_rm),
16481 cCL(logdp, e5081a0, 2, (RF, RF_IF), rd_rm),
16482 cCL(logdm, e5081c0, 2, (RF, RF_IF), rd_rm),
16483 cCL(logdz, e5081e0, 2, (RF, RF_IF), rd_rm),
16484 cCL(loge, e588100, 2, (RF, RF_IF), rd_rm),
16485 cCL(logep, e588120, 2, (RF, RF_IF), rd_rm),
16486 cCL(logem, e588140, 2, (RF, RF_IF), rd_rm),
16487 cCL(logez, e588160, 2, (RF, RF_IF), rd_rm),
16488
16489 cCL(lgns, e608100, 2, (RF, RF_IF), rd_rm),
16490 cCL(lgnsp, e608120, 2, (RF, RF_IF), rd_rm),
16491 cCL(lgnsm, e608140, 2, (RF, RF_IF), rd_rm),
16492 cCL(lgnsz, e608160, 2, (RF, RF_IF), rd_rm),
16493 cCL(lgnd, e608180, 2, (RF, RF_IF), rd_rm),
16494 cCL(lgndp, e6081a0, 2, (RF, RF_IF), rd_rm),
16495 cCL(lgndm, e6081c0, 2, (RF, RF_IF), rd_rm),
16496 cCL(lgndz, e6081e0, 2, (RF, RF_IF), rd_rm),
16497 cCL(lgne, e688100, 2, (RF, RF_IF), rd_rm),
16498 cCL(lgnep, e688120, 2, (RF, RF_IF), rd_rm),
16499 cCL(lgnem, e688140, 2, (RF, RF_IF), rd_rm),
16500 cCL(lgnez, e688160, 2, (RF, RF_IF), rd_rm),
16501
16502 cCL(exps, e708100, 2, (RF, RF_IF), rd_rm),
16503 cCL(expsp, e708120, 2, (RF, RF_IF), rd_rm),
16504 cCL(expsm, e708140, 2, (RF, RF_IF), rd_rm),
16505 cCL(expsz, e708160, 2, (RF, RF_IF), rd_rm),
16506 cCL(expd, e708180, 2, (RF, RF_IF), rd_rm),
16507 cCL(expdp, e7081a0, 2, (RF, RF_IF), rd_rm),
16508 cCL(expdm, e7081c0, 2, (RF, RF_IF), rd_rm),
16509 cCL(expdz, e7081e0, 2, (RF, RF_IF), rd_rm),
16510 cCL(expe, e788100, 2, (RF, RF_IF), rd_rm),
16511 cCL(expep, e788120, 2, (RF, RF_IF), rd_rm),
16512 cCL(expem, e788140, 2, (RF, RF_IF), rd_rm),
16513 cCL(expdz, e788160, 2, (RF, RF_IF), rd_rm),
16514
16515 cCL(sins, e808100, 2, (RF, RF_IF), rd_rm),
16516 cCL(sinsp, e808120, 2, (RF, RF_IF), rd_rm),
16517 cCL(sinsm, e808140, 2, (RF, RF_IF), rd_rm),
16518 cCL(sinsz, e808160, 2, (RF, RF_IF), rd_rm),
16519 cCL(sind, e808180, 2, (RF, RF_IF), rd_rm),
16520 cCL(sindp, e8081a0, 2, (RF, RF_IF), rd_rm),
16521 cCL(sindm, e8081c0, 2, (RF, RF_IF), rd_rm),
16522 cCL(sindz, e8081e0, 2, (RF, RF_IF), rd_rm),
16523 cCL(sine, e888100, 2, (RF, RF_IF), rd_rm),
16524 cCL(sinep, e888120, 2, (RF, RF_IF), rd_rm),
16525 cCL(sinem, e888140, 2, (RF, RF_IF), rd_rm),
16526 cCL(sinez, e888160, 2, (RF, RF_IF), rd_rm),
16527
16528 cCL(coss, e908100, 2, (RF, RF_IF), rd_rm),
16529 cCL(cossp, e908120, 2, (RF, RF_IF), rd_rm),
16530 cCL(cossm, e908140, 2, (RF, RF_IF), rd_rm),
16531 cCL(cossz, e908160, 2, (RF, RF_IF), rd_rm),
16532 cCL(cosd, e908180, 2, (RF, RF_IF), rd_rm),
16533 cCL(cosdp, e9081a0, 2, (RF, RF_IF), rd_rm),
16534 cCL(cosdm, e9081c0, 2, (RF, RF_IF), rd_rm),
16535 cCL(cosdz, e9081e0, 2, (RF, RF_IF), rd_rm),
16536 cCL(cose, e988100, 2, (RF, RF_IF), rd_rm),
16537 cCL(cosep, e988120, 2, (RF, RF_IF), rd_rm),
16538 cCL(cosem, e988140, 2, (RF, RF_IF), rd_rm),
16539 cCL(cosez, e988160, 2, (RF, RF_IF), rd_rm),
16540
16541 cCL(tans, ea08100, 2, (RF, RF_IF), rd_rm),
16542 cCL(tansp, ea08120, 2, (RF, RF_IF), rd_rm),
16543 cCL(tansm, ea08140, 2, (RF, RF_IF), rd_rm),
16544 cCL(tansz, ea08160, 2, (RF, RF_IF), rd_rm),
16545 cCL(tand, ea08180, 2, (RF, RF_IF), rd_rm),
16546 cCL(tandp, ea081a0, 2, (RF, RF_IF), rd_rm),
16547 cCL(tandm, ea081c0, 2, (RF, RF_IF), rd_rm),
16548 cCL(tandz, ea081e0, 2, (RF, RF_IF), rd_rm),
16549 cCL(tane, ea88100, 2, (RF, RF_IF), rd_rm),
16550 cCL(tanep, ea88120, 2, (RF, RF_IF), rd_rm),
16551 cCL(tanem, ea88140, 2, (RF, RF_IF), rd_rm),
16552 cCL(tanez, ea88160, 2, (RF, RF_IF), rd_rm),
16553
16554 cCL(asns, eb08100, 2, (RF, RF_IF), rd_rm),
16555 cCL(asnsp, eb08120, 2, (RF, RF_IF), rd_rm),
16556 cCL(asnsm, eb08140, 2, (RF, RF_IF), rd_rm),
16557 cCL(asnsz, eb08160, 2, (RF, RF_IF), rd_rm),
16558 cCL(asnd, eb08180, 2, (RF, RF_IF), rd_rm),
16559 cCL(asndp, eb081a0, 2, (RF, RF_IF), rd_rm),
16560 cCL(asndm, eb081c0, 2, (RF, RF_IF), rd_rm),
16561 cCL(asndz, eb081e0, 2, (RF, RF_IF), rd_rm),
16562 cCL(asne, eb88100, 2, (RF, RF_IF), rd_rm),
16563 cCL(asnep, eb88120, 2, (RF, RF_IF), rd_rm),
16564 cCL(asnem, eb88140, 2, (RF, RF_IF), rd_rm),
16565 cCL(asnez, eb88160, 2, (RF, RF_IF), rd_rm),
16566
16567 cCL(acss, ec08100, 2, (RF, RF_IF), rd_rm),
16568 cCL(acssp, ec08120, 2, (RF, RF_IF), rd_rm),
16569 cCL(acssm, ec08140, 2, (RF, RF_IF), rd_rm),
16570 cCL(acssz, ec08160, 2, (RF, RF_IF), rd_rm),
16571 cCL(acsd, ec08180, 2, (RF, RF_IF), rd_rm),
16572 cCL(acsdp, ec081a0, 2, (RF, RF_IF), rd_rm),
16573 cCL(acsdm, ec081c0, 2, (RF, RF_IF), rd_rm),
16574 cCL(acsdz, ec081e0, 2, (RF, RF_IF), rd_rm),
16575 cCL(acse, ec88100, 2, (RF, RF_IF), rd_rm),
16576 cCL(acsep, ec88120, 2, (RF, RF_IF), rd_rm),
16577 cCL(acsem, ec88140, 2, (RF, RF_IF), rd_rm),
16578 cCL(acsez, ec88160, 2, (RF, RF_IF), rd_rm),
16579
16580 cCL(atns, ed08100, 2, (RF, RF_IF), rd_rm),
16581 cCL(atnsp, ed08120, 2, (RF, RF_IF), rd_rm),
16582 cCL(atnsm, ed08140, 2, (RF, RF_IF), rd_rm),
16583 cCL(atnsz, ed08160, 2, (RF, RF_IF), rd_rm),
16584 cCL(atnd, ed08180, 2, (RF, RF_IF), rd_rm),
16585 cCL(atndp, ed081a0, 2, (RF, RF_IF), rd_rm),
16586 cCL(atndm, ed081c0, 2, (RF, RF_IF), rd_rm),
16587 cCL(atndz, ed081e0, 2, (RF, RF_IF), rd_rm),
16588 cCL(atne, ed88100, 2, (RF, RF_IF), rd_rm),
16589 cCL(atnep, ed88120, 2, (RF, RF_IF), rd_rm),
16590 cCL(atnem, ed88140, 2, (RF, RF_IF), rd_rm),
16591 cCL(atnez, ed88160, 2, (RF, RF_IF), rd_rm),
16592
16593 cCL(urds, ee08100, 2, (RF, RF_IF), rd_rm),
16594 cCL(urdsp, ee08120, 2, (RF, RF_IF), rd_rm),
16595 cCL(urdsm, ee08140, 2, (RF, RF_IF), rd_rm),
16596 cCL(urdsz, ee08160, 2, (RF, RF_IF), rd_rm),
16597 cCL(urdd, ee08180, 2, (RF, RF_IF), rd_rm),
16598 cCL(urddp, ee081a0, 2, (RF, RF_IF), rd_rm),
16599 cCL(urddm, ee081c0, 2, (RF, RF_IF), rd_rm),
16600 cCL(urddz, ee081e0, 2, (RF, RF_IF), rd_rm),
16601 cCL(urde, ee88100, 2, (RF, RF_IF), rd_rm),
16602 cCL(urdep, ee88120, 2, (RF, RF_IF), rd_rm),
16603 cCL(urdem, ee88140, 2, (RF, RF_IF), rd_rm),
16604 cCL(urdez, ee88160, 2, (RF, RF_IF), rd_rm),
16605
16606 cCL(nrms, ef08100, 2, (RF, RF_IF), rd_rm),
16607 cCL(nrmsp, ef08120, 2, (RF, RF_IF), rd_rm),
16608 cCL(nrmsm, ef08140, 2, (RF, RF_IF), rd_rm),
16609 cCL(nrmsz, ef08160, 2, (RF, RF_IF), rd_rm),
16610 cCL(nrmd, ef08180, 2, (RF, RF_IF), rd_rm),
16611 cCL(nrmdp, ef081a0, 2, (RF, RF_IF), rd_rm),
16612 cCL(nrmdm, ef081c0, 2, (RF, RF_IF), rd_rm),
16613 cCL(nrmdz, ef081e0, 2, (RF, RF_IF), rd_rm),
16614 cCL(nrme, ef88100, 2, (RF, RF_IF), rd_rm),
16615 cCL(nrmep, ef88120, 2, (RF, RF_IF), rd_rm),
16616 cCL(nrmem, ef88140, 2, (RF, RF_IF), rd_rm),
16617 cCL(nrmez, ef88160, 2, (RF, RF_IF), rd_rm),
16618
16619 cCL(adfs, e000100, 3, (RF, RF, RF_IF), rd_rn_rm),
16620 cCL(adfsp, e000120, 3, (RF, RF, RF_IF), rd_rn_rm),
16621 cCL(adfsm, e000140, 3, (RF, RF, RF_IF), rd_rn_rm),
16622 cCL(adfsz, e000160, 3, (RF, RF, RF_IF), rd_rn_rm),
16623 cCL(adfd, e000180, 3, (RF, RF, RF_IF), rd_rn_rm),
16624 cCL(adfdp, e0001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16625 cCL(adfdm, e0001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16626 cCL(adfdz, e0001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16627 cCL(adfe, e080100, 3, (RF, RF, RF_IF), rd_rn_rm),
16628 cCL(adfep, e080120, 3, (RF, RF, RF_IF), rd_rn_rm),
16629 cCL(adfem, e080140, 3, (RF, RF, RF_IF), rd_rn_rm),
16630 cCL(adfez, e080160, 3, (RF, RF, RF_IF), rd_rn_rm),
16631
16632 cCL(sufs, e200100, 3, (RF, RF, RF_IF), rd_rn_rm),
16633 cCL(sufsp, e200120, 3, (RF, RF, RF_IF), rd_rn_rm),
16634 cCL(sufsm, e200140, 3, (RF, RF, RF_IF), rd_rn_rm),
16635 cCL(sufsz, e200160, 3, (RF, RF, RF_IF), rd_rn_rm),
16636 cCL(sufd, e200180, 3, (RF, RF, RF_IF), rd_rn_rm),
16637 cCL(sufdp, e2001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16638 cCL(sufdm, e2001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16639 cCL(sufdz, e2001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16640 cCL(sufe, e280100, 3, (RF, RF, RF_IF), rd_rn_rm),
16641 cCL(sufep, e280120, 3, (RF, RF, RF_IF), rd_rn_rm),
16642 cCL(sufem, e280140, 3, (RF, RF, RF_IF), rd_rn_rm),
16643 cCL(sufez, e280160, 3, (RF, RF, RF_IF), rd_rn_rm),
16644
16645 cCL(rsfs, e300100, 3, (RF, RF, RF_IF), rd_rn_rm),
16646 cCL(rsfsp, e300120, 3, (RF, RF, RF_IF), rd_rn_rm),
16647 cCL(rsfsm, e300140, 3, (RF, RF, RF_IF), rd_rn_rm),
16648 cCL(rsfsz, e300160, 3, (RF, RF, RF_IF), rd_rn_rm),
16649 cCL(rsfd, e300180, 3, (RF, RF, RF_IF), rd_rn_rm),
16650 cCL(rsfdp, e3001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16651 cCL(rsfdm, e3001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16652 cCL(rsfdz, e3001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16653 cCL(rsfe, e380100, 3, (RF, RF, RF_IF), rd_rn_rm),
16654 cCL(rsfep, e380120, 3, (RF, RF, RF_IF), rd_rn_rm),
16655 cCL(rsfem, e380140, 3, (RF, RF, RF_IF), rd_rn_rm),
16656 cCL(rsfez, e380160, 3, (RF, RF, RF_IF), rd_rn_rm),
16657
16658 cCL(mufs, e100100, 3, (RF, RF, RF_IF), rd_rn_rm),
16659 cCL(mufsp, e100120, 3, (RF, RF, RF_IF), rd_rn_rm),
16660 cCL(mufsm, e100140, 3, (RF, RF, RF_IF), rd_rn_rm),
16661 cCL(mufsz, e100160, 3, (RF, RF, RF_IF), rd_rn_rm),
16662 cCL(mufd, e100180, 3, (RF, RF, RF_IF), rd_rn_rm),
16663 cCL(mufdp, e1001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16664 cCL(mufdm, e1001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16665 cCL(mufdz, e1001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16666 cCL(mufe, e180100, 3, (RF, RF, RF_IF), rd_rn_rm),
16667 cCL(mufep, e180120, 3, (RF, RF, RF_IF), rd_rn_rm),
16668 cCL(mufem, e180140, 3, (RF, RF, RF_IF), rd_rn_rm),
16669 cCL(mufez, e180160, 3, (RF, RF, RF_IF), rd_rn_rm),
16670
16671 cCL(dvfs, e400100, 3, (RF, RF, RF_IF), rd_rn_rm),
16672 cCL(dvfsp, e400120, 3, (RF, RF, RF_IF), rd_rn_rm),
16673 cCL(dvfsm, e400140, 3, (RF, RF, RF_IF), rd_rn_rm),
16674 cCL(dvfsz, e400160, 3, (RF, RF, RF_IF), rd_rn_rm),
16675 cCL(dvfd, e400180, 3, (RF, RF, RF_IF), rd_rn_rm),
16676 cCL(dvfdp, e4001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16677 cCL(dvfdm, e4001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16678 cCL(dvfdz, e4001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16679 cCL(dvfe, e480100, 3, (RF, RF, RF_IF), rd_rn_rm),
16680 cCL(dvfep, e480120, 3, (RF, RF, RF_IF), rd_rn_rm),
16681 cCL(dvfem, e480140, 3, (RF, RF, RF_IF), rd_rn_rm),
16682 cCL(dvfez, e480160, 3, (RF, RF, RF_IF), rd_rn_rm),
16683
16684 cCL(rdfs, e500100, 3, (RF, RF, RF_IF), rd_rn_rm),
16685 cCL(rdfsp, e500120, 3, (RF, RF, RF_IF), rd_rn_rm),
16686 cCL(rdfsm, e500140, 3, (RF, RF, RF_IF), rd_rn_rm),
16687 cCL(rdfsz, e500160, 3, (RF, RF, RF_IF), rd_rn_rm),
16688 cCL(rdfd, e500180, 3, (RF, RF, RF_IF), rd_rn_rm),
16689 cCL(rdfdp, e5001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16690 cCL(rdfdm, e5001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16691 cCL(rdfdz, e5001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16692 cCL(rdfe, e580100, 3, (RF, RF, RF_IF), rd_rn_rm),
16693 cCL(rdfep, e580120, 3, (RF, RF, RF_IF), rd_rn_rm),
16694 cCL(rdfem, e580140, 3, (RF, RF, RF_IF), rd_rn_rm),
16695 cCL(rdfez, e580160, 3, (RF, RF, RF_IF), rd_rn_rm),
16696
16697 cCL(pows, e600100, 3, (RF, RF, RF_IF), rd_rn_rm),
16698 cCL(powsp, e600120, 3, (RF, RF, RF_IF), rd_rn_rm),
16699 cCL(powsm, e600140, 3, (RF, RF, RF_IF), rd_rn_rm),
16700 cCL(powsz, e600160, 3, (RF, RF, RF_IF), rd_rn_rm),
16701 cCL(powd, e600180, 3, (RF, RF, RF_IF), rd_rn_rm),
16702 cCL(powdp, e6001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16703 cCL(powdm, e6001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16704 cCL(powdz, e6001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16705 cCL(powe, e680100, 3, (RF, RF, RF_IF), rd_rn_rm),
16706 cCL(powep, e680120, 3, (RF, RF, RF_IF), rd_rn_rm),
16707 cCL(powem, e680140, 3, (RF, RF, RF_IF), rd_rn_rm),
16708 cCL(powez, e680160, 3, (RF, RF, RF_IF), rd_rn_rm),
16709
16710 cCL(rpws, e700100, 3, (RF, RF, RF_IF), rd_rn_rm),
16711 cCL(rpwsp, e700120, 3, (RF, RF, RF_IF), rd_rn_rm),
16712 cCL(rpwsm, e700140, 3, (RF, RF, RF_IF), rd_rn_rm),
16713 cCL(rpwsz, e700160, 3, (RF, RF, RF_IF), rd_rn_rm),
16714 cCL(rpwd, e700180, 3, (RF, RF, RF_IF), rd_rn_rm),
16715 cCL(rpwdp, e7001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16716 cCL(rpwdm, e7001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16717 cCL(rpwdz, e7001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16718 cCL(rpwe, e780100, 3, (RF, RF, RF_IF), rd_rn_rm),
16719 cCL(rpwep, e780120, 3, (RF, RF, RF_IF), rd_rn_rm),
16720 cCL(rpwem, e780140, 3, (RF, RF, RF_IF), rd_rn_rm),
16721 cCL(rpwez, e780160, 3, (RF, RF, RF_IF), rd_rn_rm),
16722
16723 cCL(rmfs, e800100, 3, (RF, RF, RF_IF), rd_rn_rm),
16724 cCL(rmfsp, e800120, 3, (RF, RF, RF_IF), rd_rn_rm),
16725 cCL(rmfsm, e800140, 3, (RF, RF, RF_IF), rd_rn_rm),
16726 cCL(rmfsz, e800160, 3, (RF, RF, RF_IF), rd_rn_rm),
16727 cCL(rmfd, e800180, 3, (RF, RF, RF_IF), rd_rn_rm),
16728 cCL(rmfdp, e8001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16729 cCL(rmfdm, e8001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16730 cCL(rmfdz, e8001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16731 cCL(rmfe, e880100, 3, (RF, RF, RF_IF), rd_rn_rm),
16732 cCL(rmfep, e880120, 3, (RF, RF, RF_IF), rd_rn_rm),
16733 cCL(rmfem, e880140, 3, (RF, RF, RF_IF), rd_rn_rm),
16734 cCL(rmfez, e880160, 3, (RF, RF, RF_IF), rd_rn_rm),
16735
16736 cCL(fmls, e900100, 3, (RF, RF, RF_IF), rd_rn_rm),
16737 cCL(fmlsp, e900120, 3, (RF, RF, RF_IF), rd_rn_rm),
16738 cCL(fmlsm, e900140, 3, (RF, RF, RF_IF), rd_rn_rm),
16739 cCL(fmlsz, e900160, 3, (RF, RF, RF_IF), rd_rn_rm),
16740 cCL(fmld, e900180, 3, (RF, RF, RF_IF), rd_rn_rm),
16741 cCL(fmldp, e9001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16742 cCL(fmldm, e9001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16743 cCL(fmldz, e9001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16744 cCL(fmle, e980100, 3, (RF, RF, RF_IF), rd_rn_rm),
16745 cCL(fmlep, e980120, 3, (RF, RF, RF_IF), rd_rn_rm),
16746 cCL(fmlem, e980140, 3, (RF, RF, RF_IF), rd_rn_rm),
16747 cCL(fmlez, e980160, 3, (RF, RF, RF_IF), rd_rn_rm),
16748
16749 cCL(fdvs, ea00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16750 cCL(fdvsp, ea00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16751 cCL(fdvsm, ea00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16752 cCL(fdvsz, ea00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16753 cCL(fdvd, ea00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16754 cCL(fdvdp, ea001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16755 cCL(fdvdm, ea001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16756 cCL(fdvdz, ea001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16757 cCL(fdve, ea80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16758 cCL(fdvep, ea80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16759 cCL(fdvem, ea80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16760 cCL(fdvez, ea80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16761
16762 cCL(frds, eb00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16763 cCL(frdsp, eb00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16764 cCL(frdsm, eb00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16765 cCL(frdsz, eb00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16766 cCL(frdd, eb00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16767 cCL(frddp, eb001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16768 cCL(frddm, eb001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16769 cCL(frddz, eb001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16770 cCL(frde, eb80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16771 cCL(frdep, eb80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16772 cCL(frdem, eb80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16773 cCL(frdez, eb80160, 3, (RF, RF, RF_IF), rd_rn_rm),
16774
16775 cCL(pols, ec00100, 3, (RF, RF, RF_IF), rd_rn_rm),
16776 cCL(polsp, ec00120, 3, (RF, RF, RF_IF), rd_rn_rm),
16777 cCL(polsm, ec00140, 3, (RF, RF, RF_IF), rd_rn_rm),
16778 cCL(polsz, ec00160, 3, (RF, RF, RF_IF), rd_rn_rm),
16779 cCL(pold, ec00180, 3, (RF, RF, RF_IF), rd_rn_rm),
16780 cCL(poldp, ec001a0, 3, (RF, RF, RF_IF), rd_rn_rm),
16781 cCL(poldm, ec001c0, 3, (RF, RF, RF_IF), rd_rn_rm),
16782 cCL(poldz, ec001e0, 3, (RF, RF, RF_IF), rd_rn_rm),
16783 cCL(pole, ec80100, 3, (RF, RF, RF_IF), rd_rn_rm),
16784 cCL(polep, ec80120, 3, (RF, RF, RF_IF), rd_rn_rm),
16785 cCL(polem, ec80140, 3, (RF, RF, RF_IF), rd_rn_rm),
16786 cCL(polez, ec80160, 3, (RF, RF, RF_IF), rd_rn_rm),
8f06b2d8
PB
16787
16788 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205 16789 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
8f06b2d8 16790 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
c19d1205
ZW
16791 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
16792
e3cb604e
PB
16793 cCL(flts, e000110, 2, (RF, RR), rn_rd),
16794 cCL(fltsp, e000130, 2, (RF, RR), rn_rd),
16795 cCL(fltsm, e000150, 2, (RF, RR), rn_rd),
16796 cCL(fltsz, e000170, 2, (RF, RR), rn_rd),
16797 cCL(fltd, e000190, 2, (RF, RR), rn_rd),
16798 cCL(fltdp, e0001b0, 2, (RF, RR), rn_rd),
16799 cCL(fltdm, e0001d0, 2, (RF, RR), rn_rd),
16800 cCL(fltdz, e0001f0, 2, (RF, RR), rn_rd),
16801 cCL(flte, e080110, 2, (RF, RR), rn_rd),
16802 cCL(fltep, e080130, 2, (RF, RR), rn_rd),
16803 cCL(fltem, e080150, 2, (RF, RR), rn_rd),
16804 cCL(fltez, e080170, 2, (RF, RR), rn_rd),
b99bd4ef 16805
c19d1205
ZW
16806 /* The implementation of the FIX instruction is broken on some
16807 assemblers, in that it accepts a precision specifier as well as a
16808 rounding specifier, despite the fact that this is meaningless.
16809 To be more compatible, we accept it as well, though of course it
16810 does not set any bits. */
8f06b2d8 16811 cCE(fix, e100110, 2, (RR, RF), rd_rm),
e3cb604e
PB
16812 cCL(fixp, e100130, 2, (RR, RF), rd_rm),
16813 cCL(fixm, e100150, 2, (RR, RF), rd_rm),
16814 cCL(fixz, e100170, 2, (RR, RF), rd_rm),
16815 cCL(fixsp, e100130, 2, (RR, RF), rd_rm),
16816 cCL(fixsm, e100150, 2, (RR, RF), rd_rm),
16817 cCL(fixsz, e100170, 2, (RR, RF), rd_rm),
16818 cCL(fixdp, e100130, 2, (RR, RF), rd_rm),
16819 cCL(fixdm, e100150, 2, (RR, RF), rd_rm),
16820 cCL(fixdz, e100170, 2, (RR, RF), rd_rm),
16821 cCL(fixep, e100130, 2, (RR, RF), rd_rm),
16822 cCL(fixem, e100150, 2, (RR, RF), rd_rm),
16823 cCL(fixez, e100170, 2, (RR, RF), rd_rm),
bfae80f2 16824
c19d1205
ZW
16825 /* Instructions that were new with the real FPA, call them V2. */
16826#undef ARM_VARIANT
e74cfd16 16827#define ARM_VARIANT &fpu_fpa_ext_v2
8f06b2d8 16828 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16829 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16830 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
8f06b2d8 16831 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
e3cb604e
PB
16832 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16833 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
c19d1205
ZW
16834
16835#undef ARM_VARIANT
e74cfd16 16836#define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
c19d1205 16837 /* Moves and type conversions. */
8f06b2d8
PB
16838 cCE(fcpys, eb00a40, 2, (RVS, RVS), vfp_sp_monadic),
16839 cCE(fmrs, e100a10, 2, (RR, RVS), vfp_reg_from_sp),
16840 cCE(fmsr, e000a10, 2, (RVS, RR), vfp_sp_from_reg),
16841 cCE(fmstat, ef1fa10, 0, (), noargs),
16842 cCE(fsitos, eb80ac0, 2, (RVS, RVS), vfp_sp_monadic),
16843 cCE(fuitos, eb80a40, 2, (RVS, RVS), vfp_sp_monadic),
16844 cCE(ftosis, ebd0a40, 2, (RVS, RVS), vfp_sp_monadic),
16845 cCE(ftosizs, ebd0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16846 cCE(ftouis, ebc0a40, 2, (RVS, RVS), vfp_sp_monadic),
16847 cCE(ftouizs, ebc0ac0, 2, (RVS, RVS), vfp_sp_monadic),
16848 cCE(fmrx, ef00a10, 2, (RR, RVC), rd_rn),
16849 cCE(fmxr, ee00a10, 2, (RVC, RR), rn_rd),
c19d1205
ZW
16850
16851 /* Memory operations. */
4962c51a
MS
16852 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16853 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
8f06b2d8
PB
16854 cCE(fldmias, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16855 cCE(fldmfds, c900a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16856 cCE(fldmdbs, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16857 cCE(fldmeas, d300a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16858 cCE(fldmiax, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16859 cCE(fldmfdx, c900b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16860 cCE(fldmdbx, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16861 cCE(fldmeax, d300b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16862 cCE(fstmias, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16863 cCE(fstmeas, c800a00, 2, (RRw, VRSLST), vfp_sp_ldstmia),
16864 cCE(fstmdbs, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16865 cCE(fstmfds, d200a00, 2, (RRw, VRSLST), vfp_sp_ldstmdb),
16866 cCE(fstmiax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16867 cCE(fstmeax, c800b00, 2, (RRw, VRDLST), vfp_xp_ldstmia),
16868 cCE(fstmdbx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
16869 cCE(fstmfdx, d200b00, 2, (RRw, VRDLST), vfp_xp_ldstmdb),
bfae80f2 16870
c19d1205 16871 /* Monadic operations. */
8f06b2d8
PB
16872 cCE(fabss, eb00ac0, 2, (RVS, RVS), vfp_sp_monadic),
16873 cCE(fnegs, eb10a40, 2, (RVS, RVS), vfp_sp_monadic),
16874 cCE(fsqrts, eb10ac0, 2, (RVS, RVS), vfp_sp_monadic),
c19d1205
ZW
16875
16876 /* Dyadic operations. */
8f06b2d8
PB
16877 cCE(fadds, e300a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16878 cCE(fsubs, e300a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16879 cCE(fmuls, e200a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16880 cCE(fdivs, e800a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16881 cCE(fmacs, e000a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16882 cCE(fmscs, e100a00, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16883 cCE(fnmuls, e200a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16884 cCE(fnmacs, e000a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
16885 cCE(fnmscs, e100a40, 3, (RVS, RVS, RVS), vfp_sp_dyadic),
b99bd4ef 16886
c19d1205 16887 /* Comparisons. */
8f06b2d8
PB
16888 cCE(fcmps, eb40a40, 2, (RVS, RVS), vfp_sp_monadic),
16889 cCE(fcmpzs, eb50a40, 1, (RVS), vfp_sp_compare_z),
16890 cCE(fcmpes, eb40ac0, 2, (RVS, RVS), vfp_sp_monadic),
16891 cCE(fcmpezs, eb50ac0, 1, (RVS), vfp_sp_compare_z),
b99bd4ef 16892
c19d1205 16893#undef ARM_VARIANT
e74cfd16 16894#define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
c19d1205 16895 /* Moves and type conversions. */
5287ad62 16896 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
8f06b2d8
PB
16897 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16898 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
5287ad62
JB
16899 cCE(fmdhr, e200b10, 2, (RVD, RR), vfp_dp_rn_rd),
16900 cCE(fmdlr, e000b10, 2, (RVD, RR), vfp_dp_rn_rd),
16901 cCE(fmrdh, e300b10, 2, (RR, RVD), vfp_dp_rd_rn),
16902 cCE(fmrdl, e100b10, 2, (RR, RVD), vfp_dp_rd_rn),
8f06b2d8
PB
16903 cCE(fsitod, eb80bc0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16904 cCE(fuitod, eb80b40, 2, (RVD, RVS), vfp_dp_sp_cvt),
16905 cCE(ftosid, ebd0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16906 cCE(ftosizd, ebd0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
16907 cCE(ftouid, ebc0b40, 2, (RVS, RVD), vfp_sp_dp_cvt),
16908 cCE(ftouizd, ebc0bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
c19d1205
ZW
16909
16910 /* Memory operations. */
4962c51a
MS
16911 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16912 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
8f06b2d8
PB
16913 cCE(fldmiad, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16914 cCE(fldmfdd, c900b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16915 cCE(fldmdbd, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16916 cCE(fldmead, d300b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16917 cCE(fstmiad, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16918 cCE(fstmead, c800b00, 2, (RRw, VRDLST), vfp_dp_ldstmia),
16919 cCE(fstmdbd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
16920 cCE(fstmfdd, d200b00, 2, (RRw, VRDLST), vfp_dp_ldstmdb),
b99bd4ef 16921
c19d1205 16922 /* Monadic operations. */
5287ad62
JB
16923 cCE(fabsd, eb00bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16924 cCE(fnegd, eb10b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16925 cCE(fsqrtd, eb10bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
c19d1205
ZW
16926
16927 /* Dyadic operations. */
5287ad62
JB
16928 cCE(faddd, e300b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16929 cCE(fsubd, e300b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16930 cCE(fmuld, e200b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16931 cCE(fdivd, e800b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16932 cCE(fmacd, e000b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16933 cCE(fmscd, e100b00, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16934 cCE(fnmuld, e200b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16935 cCE(fnmacd, e000b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
16936 cCE(fnmscd, e100b40, 3, (RVD, RVD, RVD), vfp_dp_rd_rn_rm),
b99bd4ef 16937
c19d1205 16938 /* Comparisons. */
5287ad62
JB
16939 cCE(fcmpd, eb40b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16940 cCE(fcmpzd, eb50b40, 1, (RVD), vfp_dp_rd),
16941 cCE(fcmped, eb40bc0, 2, (RVD, RVD), vfp_dp_rd_rm),
16942 cCE(fcmpezd, eb50bc0, 1, (RVD), vfp_dp_rd),
c19d1205
ZW
16943
16944#undef ARM_VARIANT
e74cfd16 16945#define ARM_VARIANT &fpu_vfp_ext_v2
8f06b2d8
PB
16946 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16947 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
5287ad62
JB
16948 cCE(fmdrr, c400b10, 3, (RVD, RR, RR), vfp_dp_rm_rd_rn),
16949 cCE(fmrrd, c500b10, 3, (RR, RR, RVD), vfp_dp_rd_rn_rm),
16950
037e8744
JB
16951/* Instructions which may belong to either the Neon or VFP instruction sets.
16952 Individual encoder functions perform additional architecture checks. */
16953#undef ARM_VARIANT
16954#define ARM_VARIANT &fpu_vfp_ext_v1xd
16955#undef THUMB_VARIANT
16956#define THUMB_VARIANT &fpu_vfp_ext_v1xd
16957 /* These mnemonics are unique to VFP. */
16958 NCE(vsqrt, 0, 2, (RVSD, RVSD), vfp_nsyn_sqrt),
16959 NCE(vdiv, 0, 3, (RVSD, RVSD, RVSD), vfp_nsyn_div),
16960 nCE(vnmul, vnmul, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16961 nCE(vnmla, vnmla, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16962 nCE(vnmls, vnmls, 3, (RVSD, RVSD, RVSD), vfp_nsyn_nmul),
16963 nCE(vcmp, vcmp, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16964 nCE(vcmpe, vcmpe, 2, (RVSD, RVSD_I0), vfp_nsyn_cmp),
16965 NCE(vpush, 0, 1, (VRSDLST), vfp_nsyn_push),
16966 NCE(vpop, 0, 1, (VRSDLST), vfp_nsyn_pop),
16967 NCE(vcvtz, 0, 2, (RVSD, RVSD), vfp_nsyn_cvtz),
16968
16969 /* Mnemonics shared by Neon and VFP. */
16970 nCEF(vmul, vmul, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mul),
16971 nCEF(vmla, vmla, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16972 nCEF(vmls, vmls, 3, (RNSDQ, oRNSDQ, RNSDQ_RNSC), neon_mac_maybe_scalar),
16973
16974 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16975 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16976
16977 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16978 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16979
16980 NCE(vldm, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16981 NCE(vldmia, c900b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16982 NCE(vldmdb, d100b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16983 NCE(vstm, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16984 NCE(vstmia, c800b00, 2, (RRw, VRSDLST), neon_ldm_stm),
16985 NCE(vstmdb, d000b00, 2, (RRw, VRSDLST), neon_ldm_stm),
4962c51a
MS
16986 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16987 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
037e8744
JB
16988
16989 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
8e79c3df
CM
16990 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16991 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
f31fef98 16992
037e8744
JB
16993
16994 /* NOTE: All VMOV encoding is special-cased! */
16995 NCE(vmov, 0, 1, (VMOV), neon_mov),
16996 NCE(vmovq, 0, 1, (VMOV), neon_mov),
16997
5287ad62
JB
16998#undef THUMB_VARIANT
16999#define THUMB_VARIANT &fpu_neon_ext_v1
17000#undef ARM_VARIANT
17001#define ARM_VARIANT &fpu_neon_ext_v1
17002 /* Data processing with three registers of the same length. */
17003 /* integer ops, valid types S8 S16 S32 U8 U16 U32. */
17004 NUF(vaba, 0000710, 3, (RNDQ, RNDQ, RNDQ), neon_dyadic_i_su),
17005 NUF(vabaq, 0000710, 3, (RNQ, RNQ, RNQ), neon_dyadic_i_su),
17006 NUF(vhadd, 0000000, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17007 NUF(vhaddq, 0000000, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17008 NUF(vrhadd, 0000100, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17009 NUF(vrhaddq, 0000100, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17010 NUF(vhsub, 0000200, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i_su),
17011 NUF(vhsubq, 0000200, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i_su),
17012 /* integer ops, valid types S8 S16 S32 S64 U8 U16 U32 U64. */
17013 NUF(vqadd, 0000010, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17014 NUF(vqaddq, 0000010, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
17015 NUF(vqsub, 0000210, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_i64_su),
17016 NUF(vqsubq, 0000210, 3, (RNQ, oRNQ, RNQ), neon_dyadic_i64_su),
627907b7
JB
17017 NUF(vrshl, 0000500, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17018 NUF(vrshlq, 0000500, 3, (RNQ, oRNQ, RNQ), neon_rshl),
17019 NUF(vqrshl, 0000510, 3, (RNDQ, oRNDQ, RNDQ), neon_rshl),
17020 NUF(vqrshlq, 0000510, 3, (RNQ, oRNQ, RNQ), neon_rshl),
5287ad62
JB
17021 /* If not immediate, fall back to neon_dyadic_i64_su.
17022 shl_imm should accept I8 I16 I32 I64,
17023 qshl_imm should accept S8 S16 S32 S64 U8 U16 U32 U64. */
17024 nUF(vshl, vshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_shl_imm),
17025 nUF(vshlq, vshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_shl_imm),
17026 nUF(vqshl, vqshl, 3, (RNDQ, oRNDQ, RNDQ_I63b), neon_qshl_imm),
17027 nUF(vqshlq, vqshl, 3, (RNQ, oRNQ, RNDQ_I63b), neon_qshl_imm),
17028 /* Logic ops, types optional & ignored. */
17029 nUF(vand, vand, 2, (RNDQ, NILO), neon_logic),
17030 nUF(vandq, vand, 2, (RNQ, NILO), neon_logic),
17031 nUF(vbic, vbic, 2, (RNDQ, NILO), neon_logic),
17032 nUF(vbicq, vbic, 2, (RNQ, NILO), neon_logic),
17033 nUF(vorr, vorr, 2, (RNDQ, NILO), neon_logic),
17034 nUF(vorrq, vorr, 2, (RNQ, NILO), neon_logic),
17035 nUF(vorn, vorn, 2, (RNDQ, NILO), neon_logic),
17036 nUF(vornq, vorn, 2, (RNQ, NILO), neon_logic),
17037 nUF(veor, veor, 3, (RNDQ, oRNDQ, RNDQ), neon_logic),
17038 nUF(veorq, veor, 3, (RNQ, oRNQ, RNQ), neon_logic),
17039 /* Bitfield ops, untyped. */
17040 NUF(vbsl, 1100110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17041 NUF(vbslq, 1100110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17042 NUF(vbit, 1200110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17043 NUF(vbitq, 1200110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17044 NUF(vbif, 1300110, 3, (RNDQ, RNDQ, RNDQ), neon_bitfield),
17045 NUF(vbifq, 1300110, 3, (RNQ, RNQ, RNQ), neon_bitfield),
17046 /* Int and float variants, types S8 S16 S32 U8 U16 U32 F32. */
17047 nUF(vabd, vabd, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17048 nUF(vabdq, vabd, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17049 nUF(vmax, vmax, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17050 nUF(vmaxq, vmax, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17051 nUF(vmin, vmin, 3, (RNDQ, oRNDQ, RNDQ), neon_dyadic_if_su),
17052 nUF(vminq, vmin, 3, (RNQ, oRNQ, RNQ), neon_dyadic_if_su),
17053 /* Comparisons. Types S8 S16 S32 U8 U16 U32 F32. Non-immediate versions fall
17054 back to neon_dyadic_if_su. */
17055 nUF(vcge, vcge, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17056 nUF(vcgeq, vcge, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17057 nUF(vcgt, vcgt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp),
17058 nUF(vcgtq, vcgt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp),
17059 nUF(vclt, vclt, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17060 nUF(vcltq, vclt, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
17061 nUF(vcle, vcle, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_cmp_inv),
17062 nUF(vcleq, vcle, 3, (RNQ, oRNQ, RNDQ_I0), neon_cmp_inv),
428e3f1f 17063 /* Comparison. Type I8 I16 I32 F32. */
5287ad62
JB
17064 nUF(vceq, vceq, 3, (RNDQ, oRNDQ, RNDQ_I0), neon_ceq),
17065 nUF(vceqq, vceq, 3, (RNQ, oRNQ, RNDQ_I0), neon_ceq),
17066 /* As above, D registers only. */
17067 nUF(vpmax, vpmax, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17068 nUF(vpmin, vpmin, 3, (RND, oRND, RND), neon_dyadic_if_su_d),
17069 /* Int and float variants, signedness unimportant. */
5287ad62 17070 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
5287ad62
JB
17071 nUF(vmlsq, vmls, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
17072 nUF(vpadd, vpadd, 3, (RND, oRND, RND), neon_dyadic_if_i_d),
17073 /* Add/sub take types I8 I16 I32 I64 F32. */
5287ad62 17074 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
5287ad62
JB
17075 nUF(vsubq, vsub, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
17076 /* vtst takes sizes 8, 16, 32. */
17077 NUF(vtst, 0000810, 3, (RNDQ, oRNDQ, RNDQ), neon_tst),
17078 NUF(vtstq, 0000810, 3, (RNQ, oRNQ, RNQ), neon_tst),
17079 /* VMUL takes I8 I16 I32 F32 P8. */
037e8744 17080 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
5287ad62
JB
17081 /* VQD{R}MULH takes S16 S32. */
17082 nUF(vqdmulh, vqdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17083 nUF(vqdmulhq, vqdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17084 nUF(vqrdmulh, vqrdmulh, 3, (RNDQ, oRNDQ, RNDQ_RNSC), neon_qdmulh),
17085 nUF(vqrdmulhq, vqrdmulh, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_qdmulh),
17086 NUF(vacge, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17087 NUF(vacgeq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
17088 NUF(vacgt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute),
17089 NUF(vacgtq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute),
92559b5b
PB
17090 NUF(vaclt, 0200e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17091 NUF(vacltq, 0200e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
17092 NUF(vacle, 0000e10, 3, (RNDQ, oRNDQ, RNDQ), neon_fcmp_absolute_inv),
17093 NUF(vacleq, 0000e10, 3, (RNQ, oRNQ, RNQ), neon_fcmp_absolute_inv),
5287ad62
JB
17094 NUF(vrecps, 0000f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17095 NUF(vrecpsq, 0000f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17096 NUF(vrsqrts, 0200f10, 3, (RNDQ, oRNDQ, RNDQ), neon_step),
17097 NUF(vrsqrtsq, 0200f10, 3, (RNQ, oRNQ, RNQ), neon_step),
17098
17099 /* Two address, int/float. Types S8 S16 S32 F32. */
5287ad62 17100 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
5287ad62
JB
17101 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
17102
17103 /* Data processing with two registers and a shift amount. */
17104 /* Right shifts, and variants with rounding.
17105 Types accepted S8 S16 S32 S64 U8 U16 U32 U64. */
17106 NUF(vshr, 0800010, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17107 NUF(vshrq, 0800010, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17108 NUF(vrshr, 0800210, 3, (RNDQ, oRNDQ, I64z), neon_rshift_round_imm),
17109 NUF(vrshrq, 0800210, 3, (RNQ, oRNQ, I64z), neon_rshift_round_imm),
17110 NUF(vsra, 0800110, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17111 NUF(vsraq, 0800110, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17112 NUF(vrsra, 0800310, 3, (RNDQ, oRNDQ, I64), neon_rshift_round_imm),
17113 NUF(vrsraq, 0800310, 3, (RNQ, oRNQ, I64), neon_rshift_round_imm),
17114 /* Shift and insert. Sizes accepted 8 16 32 64. */
17115 NUF(vsli, 1800510, 3, (RNDQ, oRNDQ, I63), neon_sli),
17116 NUF(vsliq, 1800510, 3, (RNQ, oRNQ, I63), neon_sli),
17117 NUF(vsri, 1800410, 3, (RNDQ, oRNDQ, I64), neon_sri),
17118 NUF(vsriq, 1800410, 3, (RNQ, oRNQ, I64), neon_sri),
17119 /* QSHL{U} immediate accepts S8 S16 S32 S64 U8 U16 U32 U64. */
17120 NUF(vqshlu, 1800610, 3, (RNDQ, oRNDQ, I63), neon_qshlu_imm),
17121 NUF(vqshluq, 1800610, 3, (RNQ, oRNQ, I63), neon_qshlu_imm),
17122 /* Right shift immediate, saturating & narrowing, with rounding variants.
17123 Types accepted S16 S32 S64 U16 U32 U64. */
17124 NUF(vqshrn, 0800910, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17125 NUF(vqrshrn, 0800950, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow),
17126 /* As above, unsigned. Types accepted S16 S32 S64. */
17127 NUF(vqshrun, 0800810, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17128 NUF(vqrshrun, 0800850, 3, (RND, RNQ, I32z), neon_rshift_sat_narrow_u),
17129 /* Right shift narrowing. Types accepted I16 I32 I64. */
17130 NUF(vshrn, 0800810, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17131 NUF(vrshrn, 0800850, 3, (RND, RNQ, I32z), neon_rshift_narrow),
17132 /* Special case. Types S8 S16 S32 U8 U16 U32. Handles max shift variant. */
17133 nUF(vshll, vshll, 3, (RNQ, RND, I32), neon_shll),
17134 /* CVT with optional immediate for fixed-point variant. */
037e8744 17135 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
b7fc2769 17136
5287ad62
JB
17137 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
17138 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
17139
17140 /* Data processing, three registers of different lengths. */
17141 /* Dyadic, long insns. Types S8 S16 S32 U8 U16 U32. */
17142 NUF(vabal, 0800500, 3, (RNQ, RND, RND), neon_abal),
17143 NUF(vabdl, 0800700, 3, (RNQ, RND, RND), neon_dyadic_long),
17144 NUF(vaddl, 0800000, 3, (RNQ, RND, RND), neon_dyadic_long),
17145 NUF(vsubl, 0800200, 3, (RNQ, RND, RND), neon_dyadic_long),
17146 /* If not scalar, fall back to neon_dyadic_long.
17147 Vector types as above, scalar types S16 S32 U16 U32. */
17148 nUF(vmlal, vmlal, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17149 nUF(vmlsl, vmlsl, 3, (RNQ, RND, RND_RNSC), neon_mac_maybe_scalar_long),
17150 /* Dyadic, widening insns. Types S8 S16 S32 U8 U16 U32. */
17151 NUF(vaddw, 0800100, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17152 NUF(vsubw, 0800300, 3, (RNQ, oRNQ, RND), neon_dyadic_wide),
17153 /* Dyadic, narrowing insns. Types I16 I32 I64. */
17154 NUF(vaddhn, 0800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17155 NUF(vraddhn, 1800400, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17156 NUF(vsubhn, 0800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17157 NUF(vrsubhn, 1800600, 3, (RND, RNQ, RNQ), neon_dyadic_narrow),
17158 /* Saturating doubling multiplies. Types S16 S32. */
17159 nUF(vqdmlal, vqdmlal, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17160 nUF(vqdmlsl, vqdmlsl, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17161 nUF(vqdmull, vqdmull, 3, (RNQ, RND, RND_RNSC), neon_mul_sat_scalar_long),
17162 /* VMULL. Vector types S8 S16 S32 U8 U16 U32 P8, scalar types
17163 S16 S32 U16 U32. */
17164 nUF(vmull, vmull, 3, (RNQ, RND, RND_RNSC), neon_vmull),
17165
17166 /* Extract. Size 8. */
3b8d421e
PB
17167 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17168 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
5287ad62
JB
17169
17170 /* Two registers, miscellaneous. */
17171 /* Reverse. Sizes 8 16 32 (must be < size in opcode). */
17172 NUF(vrev64, 1b00000, 2, (RNDQ, RNDQ), neon_rev),
17173 NUF(vrev64q, 1b00000, 2, (RNQ, RNQ), neon_rev),
17174 NUF(vrev32, 1b00080, 2, (RNDQ, RNDQ), neon_rev),
17175 NUF(vrev32q, 1b00080, 2, (RNQ, RNQ), neon_rev),
17176 NUF(vrev16, 1b00100, 2, (RNDQ, RNDQ), neon_rev),
17177 NUF(vrev16q, 1b00100, 2, (RNQ, RNQ), neon_rev),
17178 /* Vector replicate. Sizes 8 16 32. */
17179 nCE(vdup, vdup, 2, (RNDQ, RR_RNSC), neon_dup),
17180 nCE(vdupq, vdup, 2, (RNQ, RR_RNSC), neon_dup),
17181 /* VMOVL. Types S8 S16 S32 U8 U16 U32. */
17182 NUF(vmovl, 0800a10, 2, (RNQ, RND), neon_movl),
17183 /* VMOVN. Types I16 I32 I64. */
17184 nUF(vmovn, vmovn, 2, (RND, RNQ), neon_movn),
17185 /* VQMOVN. Types S16 S32 S64 U16 U32 U64. */
17186 nUF(vqmovn, vqmovn, 2, (RND, RNQ), neon_qmovn),
17187 /* VQMOVUN. Types S16 S32 S64. */
17188 nUF(vqmovun, vqmovun, 2, (RND, RNQ), neon_qmovun),
17189 /* VZIP / VUZP. Sizes 8 16 32. */
17190 NUF(vzip, 1b20180, 2, (RNDQ, RNDQ), neon_zip_uzp),
17191 NUF(vzipq, 1b20180, 2, (RNQ, RNQ), neon_zip_uzp),
17192 NUF(vuzp, 1b20100, 2, (RNDQ, RNDQ), neon_zip_uzp),
17193 NUF(vuzpq, 1b20100, 2, (RNQ, RNQ), neon_zip_uzp),
17194 /* VQABS / VQNEG. Types S8 S16 S32. */
17195 NUF(vqabs, 1b00700, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17196 NUF(vqabsq, 1b00700, 2, (RNQ, RNQ), neon_sat_abs_neg),
17197 NUF(vqneg, 1b00780, 2, (RNDQ, RNDQ), neon_sat_abs_neg),
17198 NUF(vqnegq, 1b00780, 2, (RNQ, RNQ), neon_sat_abs_neg),
17199 /* Pairwise, lengthening. Types S8 S16 S32 U8 U16 U32. */
17200 NUF(vpadal, 1b00600, 2, (RNDQ, RNDQ), neon_pair_long),
17201 NUF(vpadalq, 1b00600, 2, (RNQ, RNQ), neon_pair_long),
17202 NUF(vpaddl, 1b00200, 2, (RNDQ, RNDQ), neon_pair_long),
17203 NUF(vpaddlq, 1b00200, 2, (RNQ, RNQ), neon_pair_long),
17204 /* Reciprocal estimates. Types U32 F32. */
17205 NUF(vrecpe, 1b30400, 2, (RNDQ, RNDQ), neon_recip_est),
17206 NUF(vrecpeq, 1b30400, 2, (RNQ, RNQ), neon_recip_est),
17207 NUF(vrsqrte, 1b30480, 2, (RNDQ, RNDQ), neon_recip_est),
17208 NUF(vrsqrteq, 1b30480, 2, (RNQ, RNQ), neon_recip_est),
17209 /* VCLS. Types S8 S16 S32. */
17210 NUF(vcls, 1b00400, 2, (RNDQ, RNDQ), neon_cls),
17211 NUF(vclsq, 1b00400, 2, (RNQ, RNQ), neon_cls),
17212 /* VCLZ. Types I8 I16 I32. */
17213 NUF(vclz, 1b00480, 2, (RNDQ, RNDQ), neon_clz),
17214 NUF(vclzq, 1b00480, 2, (RNQ, RNQ), neon_clz),
17215 /* VCNT. Size 8. */
17216 NUF(vcnt, 1b00500, 2, (RNDQ, RNDQ), neon_cnt),
17217 NUF(vcntq, 1b00500, 2, (RNQ, RNQ), neon_cnt),
17218 /* Two address, untyped. */
17219 NUF(vswp, 1b20000, 2, (RNDQ, RNDQ), neon_swp),
17220 NUF(vswpq, 1b20000, 2, (RNQ, RNQ), neon_swp),
17221 /* VTRN. Sizes 8 16 32. */
17222 nUF(vtrn, vtrn, 2, (RNDQ, RNDQ), neon_trn),
17223 nUF(vtrnq, vtrn, 2, (RNQ, RNQ), neon_trn),
17224
17225 /* Table lookup. Size 8. */
17226 NUF(vtbl, 1b00800, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17227 NUF(vtbx, 1b00840, 3, (RND, NRDLST, RND), neon_tbl_tbx),
17228
b7fc2769
JB
17229#undef THUMB_VARIANT
17230#define THUMB_VARIANT &fpu_vfp_v3_or_neon_ext
17231#undef ARM_VARIANT
17232#define ARM_VARIANT &fpu_vfp_v3_or_neon_ext
5287ad62
JB
17233 /* Neon element/structure load/store. */
17234 nUF(vld1, vld1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17235 nUF(vst1, vst1, 2, (NSTRLST, ADDR), neon_ldx_stx),
17236 nUF(vld2, vld2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17237 nUF(vst2, vst2, 2, (NSTRLST, ADDR), neon_ldx_stx),
17238 nUF(vld3, vld3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17239 nUF(vst3, vst3, 2, (NSTRLST, ADDR), neon_ldx_stx),
17240 nUF(vld4, vld4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17241 nUF(vst4, vst4, 2, (NSTRLST, ADDR), neon_ldx_stx),
17242
17243#undef THUMB_VARIANT
17244#define THUMB_VARIANT &fpu_vfp_ext_v3
17245#undef ARM_VARIANT
17246#define ARM_VARIANT &fpu_vfp_ext_v3
5287ad62
JB
17247 cCE(fconsts, eb00a00, 2, (RVS, I255), vfp_sp_const),
17248 cCE(fconstd, eb00b00, 2, (RVD, I255), vfp_dp_const),
17249 cCE(fshtos, eba0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17250 cCE(fshtod, eba0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17251 cCE(fsltos, eba0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17252 cCE(fsltod, eba0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17253 cCE(fuhtos, ebb0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17254 cCE(fuhtod, ebb0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17255 cCE(fultos, ebb0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17256 cCE(fultod, ebb0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17257 cCE(ftoshs, ebe0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17258 cCE(ftoshd, ebe0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17259 cCE(ftosls, ebe0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17260 cCE(ftosld, ebe0bc0, 2, (RVD, I32), vfp_dp_conv_32),
17261 cCE(ftouhs, ebf0a40, 2, (RVS, I16z), vfp_sp_conv_16),
17262 cCE(ftouhd, ebf0b40, 2, (RVD, I16z), vfp_dp_conv_16),
17263 cCE(ftouls, ebf0ac0, 2, (RVS, I32), vfp_sp_conv_32),
17264 cCE(ftould, ebf0bc0, 2, (RVD, I32), vfp_dp_conv_32),
c19d1205 17265
5287ad62 17266#undef THUMB_VARIANT
c19d1205 17267#undef ARM_VARIANT
e74cfd16 17268#define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
8f06b2d8
PB
17269 cCE(mia, e200010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17270 cCE(miaph, e280010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17271 cCE(miabb, e2c0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17272 cCE(miabt, e2d0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17273 cCE(miatb, e2e0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17274 cCE(miatt, e2f0010, 3, (RXA, RRnpc, RRnpc), xsc_mia),
17275 cCE(mar, c400000, 3, (RXA, RRnpc, RRnpc), xsc_mar),
17276 cCE(mra, c500000, 3, (RRnpc, RRnpc, RXA), xsc_mra),
c19d1205
ZW
17277
17278#undef ARM_VARIANT
e74cfd16 17279#define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
8f06b2d8
PB
17280 cCE(tandcb, e13f130, 1, (RR), iwmmxt_tandorc),
17281 cCE(tandch, e53f130, 1, (RR), iwmmxt_tandorc),
17282 cCE(tandcw, e93f130, 1, (RR), iwmmxt_tandorc),
17283 cCE(tbcstb, e400010, 2, (RIWR, RR), rn_rd),
17284 cCE(tbcsth, e400050, 2, (RIWR, RR), rn_rd),
17285 cCE(tbcstw, e400090, 2, (RIWR, RR), rn_rd),
17286 cCE(textrcb, e130170, 2, (RR, I7), iwmmxt_textrc),
17287 cCE(textrch, e530170, 2, (RR, I7), iwmmxt_textrc),
17288 cCE(textrcw, e930170, 2, (RR, I7), iwmmxt_textrc),
17289 cCE(textrmub, e100070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17290 cCE(textrmuh, e500070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17291 cCE(textrmuw, e900070, 3, (RR, RIWR, I7), iwmmxt_textrm),
17292 cCE(textrmsb, e100078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17293 cCE(textrmsh, e500078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17294 cCE(textrmsw, e900078, 3, (RR, RIWR, I7), iwmmxt_textrm),
17295 cCE(tinsrb, e600010, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17296 cCE(tinsrh, e600050, 3, (RIWR, RR, I7), iwmmxt_tinsr),
17297 cCE(tinsrw, e600090, 3, (RIWR, RR, I7), iwmmxt_tinsr),
41adaa5c 17298 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
8f06b2d8
PB
17299 cCE(tmcrr, c400000, 3, (RIWR, RR, RR), rm_rd_rn),
17300 cCE(tmia, e200010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17301 cCE(tmiaph, e280010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17302 cCE(tmiabb, e2c0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17303 cCE(tmiabt, e2d0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17304 cCE(tmiatb, e2e0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17305 cCE(tmiatt, e2f0010, 3, (RIWR, RR, RR), iwmmxt_tmia),
17306 cCE(tmovmskb, e100030, 2, (RR, RIWR), rd_rn),
17307 cCE(tmovmskh, e500030, 2, (RR, RIWR), rd_rn),
17308 cCE(tmovmskw, e900030, 2, (RR, RIWR), rd_rn),
41adaa5c 17309 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
8f06b2d8
PB
17310 cCE(tmrrc, c500000, 3, (RR, RR, RIWR), rd_rn_rm),
17311 cCE(torcb, e13f150, 1, (RR), iwmmxt_tandorc),
17312 cCE(torch, e53f150, 1, (RR), iwmmxt_tandorc),
17313 cCE(torcw, e93f150, 1, (RR), iwmmxt_tandorc),
17314 cCE(waccb, e0001c0, 2, (RIWR, RIWR), rd_rn),
17315 cCE(wacch, e4001c0, 2, (RIWR, RIWR), rd_rn),
17316 cCE(waccw, e8001c0, 2, (RIWR, RIWR), rd_rn),
17317 cCE(waddbss, e300180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17318 cCE(waddb, e000180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17319 cCE(waddbus, e100180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17320 cCE(waddhss, e700180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17321 cCE(waddh, e400180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17322 cCE(waddhus, e500180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17323 cCE(waddwss, eb00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17324 cCE(waddw, e800180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17325 cCE(waddwus, e900180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17326 cCE(waligni, e000020, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_waligni),
17327 cCE(walignr0, e800020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17328 cCE(walignr1, e900020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17329 cCE(walignr2, ea00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17330 cCE(walignr3, eb00020, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17331 cCE(wand, e200000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17332 cCE(wandn, e300000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17333 cCE(wavg2b, e800000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17334 cCE(wavg2br, e900000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17335 cCE(wavg2h, ec00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17336 cCE(wavg2hr, ed00000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17337 cCE(wcmpeqb, e000060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17338 cCE(wcmpeqh, e400060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17339 cCE(wcmpeqw, e800060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17340 cCE(wcmpgtub, e100060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17341 cCE(wcmpgtuh, e500060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17342 cCE(wcmpgtuw, e900060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17343 cCE(wcmpgtsb, e300060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17344 cCE(wcmpgtsh, e700060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17345 cCE(wcmpgtsw, eb00060, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17346 cCE(wldrb, c100000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17347 cCE(wldrh, c500000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17348 cCE(wldrw, c100100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17349 cCE(wldrd, c500100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17350 cCE(wmacs, e600100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17351 cCE(wmacsz, e700100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17352 cCE(wmacu, e400100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17353 cCE(wmacuz, e500100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17354 cCE(wmadds, ea00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17355 cCE(wmaddu, e800100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17356 cCE(wmaxsb, e200160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17357 cCE(wmaxsh, e600160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17358 cCE(wmaxsw, ea00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17359 cCE(wmaxub, e000160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17360 cCE(wmaxuh, e400160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17361 cCE(wmaxuw, e800160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17362 cCE(wminsb, e300160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17363 cCE(wminsh, e700160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17364 cCE(wminsw, eb00160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17365 cCE(wminub, e100160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17366 cCE(wminuh, e500160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17367 cCE(wminuw, e900160, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17368 cCE(wmov, e000000, 2, (RIWR, RIWR), iwmmxt_wmov),
17369 cCE(wmulsm, e300100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17370 cCE(wmulsl, e200100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17371 cCE(wmulum, e100100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17372 cCE(wmulul, e000100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17373 cCE(wor, e000000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17374 cCE(wpackhss, e700080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17375 cCE(wpackhus, e500080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17376 cCE(wpackwss, eb00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17377 cCE(wpackwus, e900080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17378 cCE(wpackdss, ef00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17379 cCE(wpackdus, ed00080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
2d447fca 17380 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17381 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17382 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17383 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17384 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
17385 cCE(wrordg, ef00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17386 cCE(wsadb, e000120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17387 cCE(wsadbz, e100120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17388 cCE(wsadh, e400120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17389 cCE(wsadhz, e500120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17390 cCE(wshufh, e0001e0, 3, (RIWR, RIWR, I255), iwmmxt_wshufh),
2d447fca 17391 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17392 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17393 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17394 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17395 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17396 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17397 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17398 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17399 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17400 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17401 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17402 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17403 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17404 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17405 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8 17406 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
2d447fca 17407 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
8f06b2d8
PB
17408 cCE(wsrldg, ee00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17409 cCE(wstrb, c000000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17410 cCE(wstrh, c400000, 2, (RIWR, ADDR), iwmmxt_wldstbh),
17411 cCE(wstrw, c000100, 2, (RIWR_RIWC, ADDR), iwmmxt_wldstw),
17412 cCE(wstrd, c400100, 2, (RIWR, ADDR), iwmmxt_wldstd),
17413 cCE(wsubbss, e3001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17414 cCE(wsubb, e0001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17415 cCE(wsubbus, e1001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17416 cCE(wsubhss, e7001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17417 cCE(wsubh, e4001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17418 cCE(wsubhus, e5001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17419 cCE(wsubwss, eb001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17420 cCE(wsubw, e8001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17421 cCE(wsubwus, e9001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17422 cCE(wunpckehub,e0000c0, 2, (RIWR, RIWR), rd_rn),
17423 cCE(wunpckehuh,e4000c0, 2, (RIWR, RIWR), rd_rn),
17424 cCE(wunpckehuw,e8000c0, 2, (RIWR, RIWR), rd_rn),
17425 cCE(wunpckehsb,e2000c0, 2, (RIWR, RIWR), rd_rn),
17426 cCE(wunpckehsh,e6000c0, 2, (RIWR, RIWR), rd_rn),
17427 cCE(wunpckehsw,ea000c0, 2, (RIWR, RIWR), rd_rn),
17428 cCE(wunpckihb, e1000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17429 cCE(wunpckihh, e5000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17430 cCE(wunpckihw, e9000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17431 cCE(wunpckelub,e0000e0, 2, (RIWR, RIWR), rd_rn),
17432 cCE(wunpckeluh,e4000e0, 2, (RIWR, RIWR), rd_rn),
17433 cCE(wunpckeluw,e8000e0, 2, (RIWR, RIWR), rd_rn),
17434 cCE(wunpckelsb,e2000e0, 2, (RIWR, RIWR), rd_rn),
17435 cCE(wunpckelsh,e6000e0, 2, (RIWR, RIWR), rd_rn),
17436 cCE(wunpckelsw,ea000e0, 2, (RIWR, RIWR), rd_rn),
17437 cCE(wunpckilb, e1000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17438 cCE(wunpckilh, e5000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17439 cCE(wunpckilw, e9000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17440 cCE(wxor, e100000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17441 cCE(wzero, e300000, 1, (RIWR), iwmmxt_wzero),
c19d1205 17442
2d447fca
JM
17443#undef ARM_VARIANT
17444#define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
1103f72c
NC
17445 cCE(torvscb, e12f190, 1, (RR), iwmmxt_tandorc),
17446 cCE(torvsch, e52f190, 1, (RR), iwmmxt_tandorc),
17447 cCE(torvscw, e92f190, 1, (RR), iwmmxt_tandorc),
2d447fca
JM
17448 cCE(wabsb, e2001c0, 2, (RIWR, RIWR), rd_rn),
17449 cCE(wabsh, e6001c0, 2, (RIWR, RIWR), rd_rn),
17450 cCE(wabsw, ea001c0, 2, (RIWR, RIWR), rd_rn),
17451 cCE(wabsdiffb, e1001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17452 cCE(wabsdiffh, e5001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17453 cCE(wabsdiffw, e9001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17454 cCE(waddbhusl, e2001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17455 cCE(waddbhusm, e6001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17456 cCE(waddhc, e600180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17457 cCE(waddwc, ea00180, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17458 cCE(waddsubhx, ea001a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17459 cCE(wavg4, e400000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17460 cCE(wavg4r, e500000, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17461 cCE(wmaddsn, ee00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17462 cCE(wmaddsx, eb00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17463 cCE(wmaddun, ec00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17464 cCE(wmaddux, e900100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17465 cCE(wmerge, e000080, 4, (RIWR, RIWR, RIWR, I7), iwmmxt_wmerge),
17466 cCE(wmiabb, e0000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17467 cCE(wmiabt, e1000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17468 cCE(wmiatb, e2000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17469 cCE(wmiatt, e3000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17470 cCE(wmiabbn, e4000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17471 cCE(wmiabtn, e5000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17472 cCE(wmiatbn, e6000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17473 cCE(wmiattn, e7000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17474 cCE(wmiawbb, e800120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17475 cCE(wmiawbt, e900120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17476 cCE(wmiawtb, ea00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17477 cCE(wmiawtt, eb00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17478 cCE(wmiawbbn, ec00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17479 cCE(wmiawbtn, ed00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17480 cCE(wmiawtbn, ee00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17481 cCE(wmiawttn, ef00120, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17482 cCE(wmulsmr, ef00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17483 cCE(wmulumr, ed00100, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17484 cCE(wmulwumr, ec000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17485 cCE(wmulwsmr, ee000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17486 cCE(wmulwum, ed000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17487 cCE(wmulwsm, ef000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17488 cCE(wmulwl, eb000c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17489 cCE(wqmiabb, e8000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17490 cCE(wqmiabt, e9000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17491 cCE(wqmiatb, ea000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17492 cCE(wqmiatt, eb000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17493 cCE(wqmiabbn, ec000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17494 cCE(wqmiabtn, ed000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17495 cCE(wqmiatbn, ee000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17496 cCE(wqmiattn, ef000a0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17497 cCE(wqmulm, e100080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17498 cCE(wqmulmr, e300080, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17499 cCE(wqmulwm, ec000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17500 cCE(wqmulwmr, ee000e0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17501 cCE(wsubaddhx, ed001c0, 3, (RIWR, RIWR, RIWR), rd_rn_rm),
17502
c19d1205 17503#undef ARM_VARIANT
e74cfd16 17504#define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
4962c51a
MS
17505 cCE(cfldrs, c100400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17506 cCE(cfldrd, c500400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17507 cCE(cfldr32, c100500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17508 cCE(cfldr64, c500500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
17509 cCE(cfstrs, c000400, 2, (RMF, ADDRGLDC), rd_cpaddr),
17510 cCE(cfstrd, c400400, 2, (RMD, ADDRGLDC), rd_cpaddr),
17511 cCE(cfstr32, c000500, 2, (RMFX, ADDRGLDC), rd_cpaddr),
17512 cCE(cfstr64, c400500, 2, (RMDX, ADDRGLDC), rd_cpaddr),
8f06b2d8
PB
17513 cCE(cfmvsr, e000450, 2, (RMF, RR), rn_rd),
17514 cCE(cfmvrs, e100450, 2, (RR, RMF), rd_rn),
17515 cCE(cfmvdlr, e000410, 2, (RMD, RR), rn_rd),
17516 cCE(cfmvrdl, e100410, 2, (RR, RMD), rd_rn),
17517 cCE(cfmvdhr, e000430, 2, (RMD, RR), rn_rd),
17518 cCE(cfmvrdh, e100430, 2, (RR, RMD), rd_rn),
17519 cCE(cfmv64lr, e000510, 2, (RMDX, RR), rn_rd),
17520 cCE(cfmvr64l, e100510, 2, (RR, RMDX), rd_rn),
17521 cCE(cfmv64hr, e000530, 2, (RMDX, RR), rn_rd),
17522 cCE(cfmvr64h, e100530, 2, (RR, RMDX), rd_rn),
17523 cCE(cfmval32, e200440, 2, (RMAX, RMFX), rd_rn),
17524 cCE(cfmv32al, e100440, 2, (RMFX, RMAX), rd_rn),
17525 cCE(cfmvam32, e200460, 2, (RMAX, RMFX), rd_rn),
17526 cCE(cfmv32am, e100460, 2, (RMFX, RMAX), rd_rn),
17527 cCE(cfmvah32, e200480, 2, (RMAX, RMFX), rd_rn),
17528 cCE(cfmv32ah, e100480, 2, (RMFX, RMAX), rd_rn),
17529 cCE(cfmva32, e2004a0, 2, (RMAX, RMFX), rd_rn),
17530 cCE(cfmv32a, e1004a0, 2, (RMFX, RMAX), rd_rn),
17531 cCE(cfmva64, e2004c0, 2, (RMAX, RMDX), rd_rn),
17532 cCE(cfmv64a, e1004c0, 2, (RMDX, RMAX), rd_rn),
17533 cCE(cfmvsc32, e2004e0, 2, (RMDS, RMDX), mav_dspsc),
17534 cCE(cfmv32sc, e1004e0, 2, (RMDX, RMDS), rd),
17535 cCE(cfcpys, e000400, 2, (RMF, RMF), rd_rn),
17536 cCE(cfcpyd, e000420, 2, (RMD, RMD), rd_rn),
17537 cCE(cfcvtsd, e000460, 2, (RMD, RMF), rd_rn),
17538 cCE(cfcvtds, e000440, 2, (RMF, RMD), rd_rn),
17539 cCE(cfcvt32s, e000480, 2, (RMF, RMFX), rd_rn),
17540 cCE(cfcvt32d, e0004a0, 2, (RMD, RMFX), rd_rn),
17541 cCE(cfcvt64s, e0004c0, 2, (RMF, RMDX), rd_rn),
17542 cCE(cfcvt64d, e0004e0, 2, (RMD, RMDX), rd_rn),
17543 cCE(cfcvts32, e100580, 2, (RMFX, RMF), rd_rn),
17544 cCE(cfcvtd32, e1005a0, 2, (RMFX, RMD), rd_rn),
17545 cCE(cftruncs32,e1005c0, 2, (RMFX, RMF), rd_rn),
17546 cCE(cftruncd32,e1005e0, 2, (RMFX, RMD), rd_rn),
17547 cCE(cfrshl32, e000550, 3, (RMFX, RMFX, RR), mav_triple),
17548 cCE(cfrshl64, e000570, 3, (RMDX, RMDX, RR), mav_triple),
17549 cCE(cfsh32, e000500, 3, (RMFX, RMFX, I63s), mav_shift),
17550 cCE(cfsh64, e200500, 3, (RMDX, RMDX, I63s), mav_shift),
17551 cCE(cfcmps, e100490, 3, (RR, RMF, RMF), rd_rn_rm),
17552 cCE(cfcmpd, e1004b0, 3, (RR, RMD, RMD), rd_rn_rm),
17553 cCE(cfcmp32, e100590, 3, (RR, RMFX, RMFX), rd_rn_rm),
17554 cCE(cfcmp64, e1005b0, 3, (RR, RMDX, RMDX), rd_rn_rm),
17555 cCE(cfabss, e300400, 2, (RMF, RMF), rd_rn),
17556 cCE(cfabsd, e300420, 2, (RMD, RMD), rd_rn),
17557 cCE(cfnegs, e300440, 2, (RMF, RMF), rd_rn),
17558 cCE(cfnegd, e300460, 2, (RMD, RMD), rd_rn),
17559 cCE(cfadds, e300480, 3, (RMF, RMF, RMF), rd_rn_rm),
17560 cCE(cfaddd, e3004a0, 3, (RMD, RMD, RMD), rd_rn_rm),
17561 cCE(cfsubs, e3004c0, 3, (RMF, RMF, RMF), rd_rn_rm),
17562 cCE(cfsubd, e3004e0, 3, (RMD, RMD, RMD), rd_rn_rm),
17563 cCE(cfmuls, e100400, 3, (RMF, RMF, RMF), rd_rn_rm),
17564 cCE(cfmuld, e100420, 3, (RMD, RMD, RMD), rd_rn_rm),
17565 cCE(cfabs32, e300500, 2, (RMFX, RMFX), rd_rn),
17566 cCE(cfabs64, e300520, 2, (RMDX, RMDX), rd_rn),
17567 cCE(cfneg32, e300540, 2, (RMFX, RMFX), rd_rn),
17568 cCE(cfneg64, e300560, 2, (RMDX, RMDX), rd_rn),
17569 cCE(cfadd32, e300580, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17570 cCE(cfadd64, e3005a0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17571 cCE(cfsub32, e3005c0, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17572 cCE(cfsub64, e3005e0, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17573 cCE(cfmul32, e100500, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17574 cCE(cfmul64, e100520, 3, (RMDX, RMDX, RMDX), rd_rn_rm),
17575 cCE(cfmac32, e100540, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17576 cCE(cfmsc32, e100560, 3, (RMFX, RMFX, RMFX), rd_rn_rm),
17577 cCE(cfmadd32, e000600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17578 cCE(cfmsub32, e100600, 4, (RMAX, RMFX, RMFX, RMFX), mav_quad),
17579 cCE(cfmadda32, e200600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
17580 cCE(cfmsuba32, e300600, 4, (RMAX, RMAX, RMFX, RMFX), mav_quad),
c19d1205
ZW
17581};
17582#undef ARM_VARIANT
17583#undef THUMB_VARIANT
17584#undef TCE
17585#undef TCM
17586#undef TUE
17587#undef TUF
17588#undef TCC
8f06b2d8 17589#undef cCE
e3cb604e
PB
17590#undef cCL
17591#undef C3E
c19d1205
ZW
17592#undef CE
17593#undef CM
17594#undef UE
17595#undef UF
17596#undef UT
5287ad62
JB
17597#undef NUF
17598#undef nUF
17599#undef NCE
17600#undef nCE
c19d1205
ZW
17601#undef OPS0
17602#undef OPS1
17603#undef OPS2
17604#undef OPS3
17605#undef OPS4
17606#undef OPS5
17607#undef OPS6
17608#undef do_0
17609\f
17610/* MD interface: bits in the object file. */
bfae80f2 17611
c19d1205
ZW
17612/* Turn an integer of n bytes (in val) into a stream of bytes appropriate
17613 for use in the a.out file, and stores them in the array pointed to by buf.
17614 This knows about the endian-ness of the target machine and does
17615 THE RIGHT THING, whatever it is. Possible values for n are 1 (byte)
17616 2 (short) and 4 (long) Floating numbers are put out as a series of
17617 LITTLENUMS (shorts, here at least). */
b99bd4ef 17618
c19d1205
ZW
17619void
17620md_number_to_chars (char * buf, valueT val, int n)
17621{
17622 if (target_big_endian)
17623 number_to_chars_bigendian (buf, val, n);
17624 else
17625 number_to_chars_littleendian (buf, val, n);
bfae80f2
RE
17626}
17627
c19d1205
ZW
17628static valueT
17629md_chars_to_number (char * buf, int n)
bfae80f2 17630{
c19d1205
ZW
17631 valueT result = 0;
17632 unsigned char * where = (unsigned char *) buf;
bfae80f2 17633
c19d1205 17634 if (target_big_endian)
b99bd4ef 17635 {
c19d1205
ZW
17636 while (n--)
17637 {
17638 result <<= 8;
17639 result |= (*where++ & 255);
17640 }
b99bd4ef 17641 }
c19d1205 17642 else
b99bd4ef 17643 {
c19d1205
ZW
17644 while (n--)
17645 {
17646 result <<= 8;
17647 result |= (where[n] & 255);
17648 }
bfae80f2 17649 }
b99bd4ef 17650
c19d1205 17651 return result;
bfae80f2 17652}
b99bd4ef 17653
c19d1205 17654/* MD interface: Sections. */
b99bd4ef 17655
0110f2b8
PB
17656/* Estimate the size of a frag before relaxing. Assume everything fits in
17657 2 bytes. */
17658
c19d1205 17659int
0110f2b8 17660md_estimate_size_before_relax (fragS * fragp,
c19d1205
ZW
17661 segT segtype ATTRIBUTE_UNUSED)
17662{
0110f2b8
PB
17663 fragp->fr_var = 2;
17664 return 2;
17665}
17666
17667/* Convert a machine dependent frag. */
17668
17669void
17670md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
17671{
17672 unsigned long insn;
17673 unsigned long old_op;
17674 char *buf;
17675 expressionS exp;
17676 fixS *fixp;
17677 int reloc_type;
17678 int pc_rel;
17679 int opcode;
17680
17681 buf = fragp->fr_literal + fragp->fr_fix;
17682
17683 old_op = bfd_get_16(abfd, buf);
5f4273c7
NC
17684 if (fragp->fr_symbol)
17685 {
0110f2b8
PB
17686 exp.X_op = O_symbol;
17687 exp.X_add_symbol = fragp->fr_symbol;
5f4273c7
NC
17688 }
17689 else
17690 {
0110f2b8 17691 exp.X_op = O_constant;
5f4273c7 17692 }
0110f2b8
PB
17693 exp.X_add_number = fragp->fr_offset;
17694 opcode = fragp->fr_subtype;
17695 switch (opcode)
17696 {
17697 case T_MNEM_ldr_pc:
17698 case T_MNEM_ldr_pc2:
17699 case T_MNEM_ldr_sp:
17700 case T_MNEM_str_sp:
17701 case T_MNEM_ldr:
17702 case T_MNEM_ldrb:
17703 case T_MNEM_ldrh:
17704 case T_MNEM_str:
17705 case T_MNEM_strb:
17706 case T_MNEM_strh:
17707 if (fragp->fr_var == 4)
17708 {
5f4273c7 17709 insn = THUMB_OP32 (opcode);
0110f2b8
PB
17710 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17711 {
17712 insn |= (old_op & 0x700) << 4;
17713 }
17714 else
17715 {
17716 insn |= (old_op & 7) << 12;
17717 insn |= (old_op & 0x38) << 13;
17718 }
17719 insn |= 0x00000c00;
17720 put_thumb32_insn (buf, insn);
17721 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17722 }
17723 else
17724 {
17725 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17726 }
17727 pc_rel = (opcode == T_MNEM_ldr_pc2);
17728 break;
17729 case T_MNEM_adr:
17730 if (fragp->fr_var == 4)
17731 {
17732 insn = THUMB_OP32 (opcode);
17733 insn |= (old_op & 0xf0) << 4;
17734 put_thumb32_insn (buf, insn);
17735 reloc_type = BFD_RELOC_ARM_T32_ADD_PC12;
17736 }
17737 else
17738 {
17739 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17740 exp.X_add_number -= 4;
17741 }
17742 pc_rel = 1;
17743 break;
17744 case T_MNEM_mov:
17745 case T_MNEM_movs:
17746 case T_MNEM_cmp:
17747 case T_MNEM_cmn:
17748 if (fragp->fr_var == 4)
17749 {
17750 int r0off = (opcode == T_MNEM_mov
17751 || opcode == T_MNEM_movs) ? 0 : 8;
17752 insn = THUMB_OP32 (opcode);
17753 insn = (insn & 0xe1ffffff) | 0x10000000;
17754 insn |= (old_op & 0x700) << r0off;
17755 put_thumb32_insn (buf, insn);
17756 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17757 }
17758 else
17759 {
17760 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17761 }
17762 pc_rel = 0;
17763 break;
17764 case T_MNEM_b:
17765 if (fragp->fr_var == 4)
17766 {
17767 insn = THUMB_OP32(opcode);
17768 put_thumb32_insn (buf, insn);
17769 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
17770 }
17771 else
17772 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH12;
17773 pc_rel = 1;
17774 break;
17775 case T_MNEM_bcond:
17776 if (fragp->fr_var == 4)
17777 {
17778 insn = THUMB_OP32(opcode);
17779 insn |= (old_op & 0xf00) << 14;
17780 put_thumb32_insn (buf, insn);
17781 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH20;
17782 }
17783 else
17784 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH9;
17785 pc_rel = 1;
17786 break;
17787 case T_MNEM_add_sp:
17788 case T_MNEM_add_pc:
17789 case T_MNEM_inc_sp:
17790 case T_MNEM_dec_sp:
17791 if (fragp->fr_var == 4)
17792 {
17793 /* ??? Choose between add and addw. */
17794 insn = THUMB_OP32 (opcode);
17795 insn |= (old_op & 0xf0) << 4;
17796 put_thumb32_insn (buf, insn);
16805f35
PB
17797 if (opcode == T_MNEM_add_pc)
17798 reloc_type = BFD_RELOC_ARM_T32_IMM12;
17799 else
17800 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
0110f2b8
PB
17801 }
17802 else
17803 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17804 pc_rel = 0;
17805 break;
17806
17807 case T_MNEM_addi:
17808 case T_MNEM_addis:
17809 case T_MNEM_subi:
17810 case T_MNEM_subis:
17811 if (fragp->fr_var == 4)
17812 {
17813 insn = THUMB_OP32 (opcode);
17814 insn |= (old_op & 0xf0) << 4;
17815 insn |= (old_op & 0xf) << 16;
17816 put_thumb32_insn (buf, insn);
16805f35
PB
17817 if (insn & (1 << 20))
17818 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17819 else
17820 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
0110f2b8
PB
17821 }
17822 else
17823 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17824 pc_rel = 0;
17825 break;
17826 default:
5f4273c7 17827 abort ();
0110f2b8
PB
17828 }
17829 fixp = fix_new_exp (fragp, fragp->fr_fix, fragp->fr_var, &exp, pc_rel,
17830 reloc_type);
17831 fixp->fx_file = fragp->fr_file;
17832 fixp->fx_line = fragp->fr_line;
17833 fragp->fr_fix += fragp->fr_var;
17834}
17835
17836/* Return the size of a relaxable immediate operand instruction.
17837 SHIFT and SIZE specify the form of the allowable immediate. */
17838static int
17839relax_immediate (fragS *fragp, int size, int shift)
17840{
17841 offsetT offset;
17842 offsetT mask;
17843 offsetT low;
17844
17845 /* ??? Should be able to do better than this. */
17846 if (fragp->fr_symbol)
17847 return 4;
17848
17849 low = (1 << shift) - 1;
17850 mask = (1 << (shift + size)) - (1 << shift);
17851 offset = fragp->fr_offset;
17852 /* Force misaligned offsets to 32-bit variant. */
17853 if (offset & low)
5e77afaa 17854 return 4;
0110f2b8
PB
17855 if (offset & ~mask)
17856 return 4;
17857 return 2;
17858}
17859
5e77afaa
PB
17860/* Get the address of a symbol during relaxation. */
17861static addressT
5f4273c7 17862relaxed_symbol_addr (fragS *fragp, long stretch)
5e77afaa
PB
17863{
17864 fragS *sym_frag;
17865 addressT addr;
17866 symbolS *sym;
17867
17868 sym = fragp->fr_symbol;
17869 sym_frag = symbol_get_frag (sym);
17870 know (S_GET_SEGMENT (sym) != absolute_section
17871 || sym_frag == &zero_address_frag);
17872 addr = S_GET_VALUE (sym) + fragp->fr_offset;
17873
17874 /* If frag has yet to be reached on this pass, assume it will
17875 move by STRETCH just as we did. If this is not so, it will
17876 be because some frag between grows, and that will force
17877 another pass. */
17878
17879 if (stretch != 0
17880 && sym_frag->relax_marker != fragp->relax_marker)
4396b686
PB
17881 {
17882 fragS *f;
17883
17884 /* Adjust stretch for any alignment frag. Note that if have
17885 been expanding the earlier code, the symbol may be
17886 defined in what appears to be an earlier frag. FIXME:
17887 This doesn't handle the fr_subtype field, which specifies
17888 a maximum number of bytes to skip when doing an
17889 alignment. */
17890 for (f = fragp; f != NULL && f != sym_frag; f = f->fr_next)
17891 {
17892 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
17893 {
17894 if (stretch < 0)
17895 stretch = - ((- stretch)
17896 & ~ ((1 << (int) f->fr_offset) - 1));
17897 else
17898 stretch &= ~ ((1 << (int) f->fr_offset) - 1);
17899 if (stretch == 0)
17900 break;
17901 }
17902 }
17903 if (f != NULL)
17904 addr += stretch;
17905 }
5e77afaa
PB
17906
17907 return addr;
17908}
17909
0110f2b8
PB
17910/* Return the size of a relaxable adr pseudo-instruction or PC-relative
17911 load. */
17912static int
5e77afaa 17913relax_adr (fragS *fragp, asection *sec, long stretch)
0110f2b8
PB
17914{
17915 addressT addr;
17916 offsetT val;
17917
17918 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17919 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17920 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17921 return 4;
17922
5f4273c7 17923 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17924 addr = fragp->fr_address + fragp->fr_fix;
17925 addr = (addr + 4) & ~3;
5e77afaa 17926 /* Force misaligned targets to 32-bit variant. */
0110f2b8 17927 if (val & 3)
5e77afaa 17928 return 4;
0110f2b8
PB
17929 val -= addr;
17930 if (val < 0 || val > 1020)
17931 return 4;
17932 return 2;
17933}
17934
17935/* Return the size of a relaxable add/sub immediate instruction. */
17936static int
17937relax_addsub (fragS *fragp, asection *sec)
17938{
17939 char *buf;
17940 int op;
17941
17942 buf = fragp->fr_literal + fragp->fr_fix;
17943 op = bfd_get_16(sec->owner, buf);
17944 if ((op & 0xf) == ((op >> 4) & 0xf))
17945 return relax_immediate (fragp, 8, 0);
17946 else
17947 return relax_immediate (fragp, 3, 0);
17948}
17949
17950
17951/* Return the size of a relaxable branch instruction. BITS is the
17952 size of the offset field in the narrow instruction. */
17953
17954static int
5e77afaa 17955relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
0110f2b8
PB
17956{
17957 addressT addr;
17958 offsetT val;
17959 offsetT limit;
17960
17961 /* Assume worst case for symbols not known to be in the same section. */
5f4273c7 17962 if (!S_IS_DEFINED (fragp->fr_symbol)
0110f2b8
PB
17963 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17964 return 4;
17965
267bf995
RR
17966#ifdef OBJ_ELF
17967 if (S_IS_DEFINED (fragp->fr_symbol)
17968 && ARM_IS_FUNC (fragp->fr_symbol))
17969 return 4;
17970#endif
17971
5f4273c7 17972 val = relaxed_symbol_addr (fragp, stretch);
0110f2b8
PB
17973 addr = fragp->fr_address + fragp->fr_fix + 4;
17974 val -= addr;
17975
17976 /* Offset is a signed value *2 */
17977 limit = 1 << bits;
17978 if (val >= limit || val < -limit)
17979 return 4;
17980 return 2;
17981}
17982
17983
17984/* Relax a machine dependent frag. This returns the amount by which
17985 the current size of the frag should change. */
17986
17987int
5e77afaa 17988arm_relax_frag (asection *sec, fragS *fragp, long stretch)
0110f2b8
PB
17989{
17990 int oldsize;
17991 int newsize;
17992
17993 oldsize = fragp->fr_var;
17994 switch (fragp->fr_subtype)
17995 {
17996 case T_MNEM_ldr_pc2:
5f4273c7 17997 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
17998 break;
17999 case T_MNEM_ldr_pc:
18000 case T_MNEM_ldr_sp:
18001 case T_MNEM_str_sp:
5f4273c7 18002 newsize = relax_immediate (fragp, 8, 2);
0110f2b8
PB
18003 break;
18004 case T_MNEM_ldr:
18005 case T_MNEM_str:
5f4273c7 18006 newsize = relax_immediate (fragp, 5, 2);
0110f2b8
PB
18007 break;
18008 case T_MNEM_ldrh:
18009 case T_MNEM_strh:
5f4273c7 18010 newsize = relax_immediate (fragp, 5, 1);
0110f2b8
PB
18011 break;
18012 case T_MNEM_ldrb:
18013 case T_MNEM_strb:
5f4273c7 18014 newsize = relax_immediate (fragp, 5, 0);
0110f2b8
PB
18015 break;
18016 case T_MNEM_adr:
5f4273c7 18017 newsize = relax_adr (fragp, sec, stretch);
0110f2b8
PB
18018 break;
18019 case T_MNEM_mov:
18020 case T_MNEM_movs:
18021 case T_MNEM_cmp:
18022 case T_MNEM_cmn:
5f4273c7 18023 newsize = relax_immediate (fragp, 8, 0);
0110f2b8
PB
18024 break;
18025 case T_MNEM_b:
5f4273c7 18026 newsize = relax_branch (fragp, sec, 11, stretch);
0110f2b8
PB
18027 break;
18028 case T_MNEM_bcond:
5f4273c7 18029 newsize = relax_branch (fragp, sec, 8, stretch);
0110f2b8
PB
18030 break;
18031 case T_MNEM_add_sp:
18032 case T_MNEM_add_pc:
18033 newsize = relax_immediate (fragp, 8, 2);
18034 break;
18035 case T_MNEM_inc_sp:
18036 case T_MNEM_dec_sp:
18037 newsize = relax_immediate (fragp, 7, 2);
18038 break;
18039 case T_MNEM_addi:
18040 case T_MNEM_addis:
18041 case T_MNEM_subi:
18042 case T_MNEM_subis:
18043 newsize = relax_addsub (fragp, sec);
18044 break;
18045 default:
5f4273c7 18046 abort ();
0110f2b8 18047 }
5e77afaa
PB
18048
18049 fragp->fr_var = newsize;
18050 /* Freeze wide instructions that are at or before the same location as
18051 in the previous pass. This avoids infinite loops.
5f4273c7
NC
18052 Don't freeze them unconditionally because targets may be artificially
18053 misaligned by the expansion of preceding frags. */
5e77afaa 18054 if (stretch <= 0 && newsize > 2)
0110f2b8 18055 {
0110f2b8 18056 md_convert_frag (sec->owner, sec, fragp);
5f4273c7 18057 frag_wane (fragp);
0110f2b8 18058 }
5e77afaa 18059
0110f2b8 18060 return newsize - oldsize;
c19d1205 18061}
b99bd4ef 18062
c19d1205 18063/* Round up a section size to the appropriate boundary. */
b99bd4ef 18064
c19d1205
ZW
18065valueT
18066md_section_align (segT segment ATTRIBUTE_UNUSED,
18067 valueT size)
18068{
f0927246
NC
18069#if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18070 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
18071 {
18072 /* For a.out, force the section size to be aligned. If we don't do
18073 this, BFD will align it for us, but it will not write out the
18074 final bytes of the section. This may be a bug in BFD, but it is
18075 easier to fix it here since that is how the other a.out targets
18076 work. */
18077 int align;
18078
18079 align = bfd_get_section_alignment (stdoutput, segment);
18080 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18081 }
c19d1205 18082#endif
f0927246
NC
18083
18084 return size;
bfae80f2 18085}
b99bd4ef 18086
c19d1205
ZW
18087/* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18088 of an rs_align_code fragment. */
18089
18090void
18091arm_handle_align (fragS * fragP)
bfae80f2 18092{
e7495e45
NS
18093 static char const arm_noop[2][2][4] =
18094 {
18095 { /* ARMv1 */
18096 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18097 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18098 },
18099 { /* ARMv6k */
18100 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18101 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18102 },
18103 };
18104 static char const thumb_noop[2][2][2] =
18105 {
18106 { /* Thumb-1 */
18107 {0xc0, 0x46}, /* LE */
18108 {0x46, 0xc0}, /* BE */
18109 },
18110 { /* Thumb-2 */
18111 {0x00, 0xbf}, /* LE */
18112 {0xbf, 0x00} /* BE */
18113 }
18114 };
18115 static char const wide_thumb_noop[2][4] =
18116 { /* Wide Thumb-2 */
18117 {0xaf, 0xf3, 0x00, 0x80}, /* LE */
18118 {0xf3, 0xaf, 0x80, 0x00}, /* BE */
18119 };
18120
18121 unsigned bytes, fix, noop_size;
c19d1205
ZW
18122 char * p;
18123 const char * noop;
e7495e45 18124 const char *narrow_noop = NULL;
bfae80f2 18125
c19d1205 18126 if (fragP->fr_type != rs_align_code)
bfae80f2
RE
18127 return;
18128
c19d1205
ZW
18129 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18130 p = fragP->fr_literal + fragP->fr_fix;
18131 fix = 0;
bfae80f2 18132
c19d1205
ZW
18133 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18134 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
bfae80f2 18135
9c2799c2 18136 gas_assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
8dc2430f
NC
18137
18138 if (fragP->tc_frag_data & (~ MODE_RECORDED))
a737bd4d 18139 {
e7495e45
NS
18140 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18141 {
18142 narrow_noop = thumb_noop[1][target_big_endian];
18143 noop = wide_thumb_noop[target_big_endian];
18144 }
c19d1205 18145 else
e7495e45
NS
18146 noop = thumb_noop[0][target_big_endian];
18147 noop_size = 2;
7ed4c4c5
NC
18148 }
18149 else
18150 {
e7495e45
NS
18151 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18152 [target_big_endian];
18153 noop_size = 4;
7ed4c4c5 18154 }
e7495e45
NS
18155
18156 fragP->fr_var = noop_size;
18157
c19d1205 18158 if (bytes & (noop_size - 1))
7ed4c4c5 18159 {
c19d1205
ZW
18160 fix = bytes & (noop_size - 1);
18161 memset (p, 0, fix);
18162 p += fix;
18163 bytes -= fix;
a737bd4d 18164 }
a737bd4d 18165
e7495e45
NS
18166 if (narrow_noop)
18167 {
18168 if (bytes & noop_size)
18169 {
18170 /* Insert a narrow noop. */
18171 memcpy (p, narrow_noop, noop_size);
18172 p += noop_size;
18173 bytes -= noop_size;
18174 fix += noop_size;
18175 }
18176
18177 /* Use wide noops for the remainder */
18178 noop_size = 4;
18179 }
18180
c19d1205 18181 while (bytes >= noop_size)
a737bd4d 18182 {
c19d1205
ZW
18183 memcpy (p, noop, noop_size);
18184 p += noop_size;
18185 bytes -= noop_size;
18186 fix += noop_size;
a737bd4d
NC
18187 }
18188
c19d1205 18189 fragP->fr_fix += fix;
a737bd4d
NC
18190}
18191
c19d1205
ZW
18192/* Called from md_do_align. Used to create an alignment
18193 frag in a code section. */
18194
18195void
18196arm_frag_align_code (int n, int max)
bfae80f2 18197{
c19d1205 18198 char * p;
7ed4c4c5 18199
c19d1205
ZW
18200 /* We assume that there will never be a requirement
18201 to support alignments greater than 32 bytes. */
18202 if (max > MAX_MEM_FOR_RS_ALIGN_CODE)
18203 as_fatal (_("alignments greater than 32 bytes not supported in .text sections."));
bfae80f2 18204
c19d1205
ZW
18205 p = frag_var (rs_align_code,
18206 MAX_MEM_FOR_RS_ALIGN_CODE,
18207 1,
18208 (relax_substateT) max,
18209 (symbolS *) NULL,
18210 (offsetT) n,
18211 (char *) NULL);
18212 *p = 0;
18213}
bfae80f2 18214
8dc2430f
NC
18215/* Perform target specific initialisation of a frag.
18216 Note - despite the name this initialisation is not done when the frag
18217 is created, but only when its type is assigned. A frag can be created
18218 and used a long time before its type is set, so beware of assuming that
18219 this initialisationis performed first. */
bfae80f2 18220
c19d1205
ZW
18221void
18222arm_init_frag (fragS * fragP)
18223{
8dc2430f
NC
18224 /* If the current ARM vs THUMB mode has not already
18225 been recorded into this frag then do so now. */
18226 if ((fragP->tc_frag_data & MODE_RECORDED) == 0)
18227 fragP->tc_frag_data = thumb_mode | MODE_RECORDED;
bfae80f2
RE
18228}
18229
c19d1205
ZW
18230#ifdef OBJ_ELF
18231/* When we change sections we need to issue a new mapping symbol. */
18232
18233void
18234arm_elf_change_section (void)
bfae80f2 18235{
c19d1205
ZW
18236 flagword flags;
18237 segment_info_type *seginfo;
bfae80f2 18238
c19d1205
ZW
18239 /* Link an unlinked unwind index table section to the .text section. */
18240 if (elf_section_type (now_seg) == SHT_ARM_EXIDX
18241 && elf_linked_to_section (now_seg) == NULL)
18242 elf_linked_to_section (now_seg) = text_section;
18243
18244 if (!SEG_NORMAL (now_seg))
bfae80f2
RE
18245 return;
18246
c19d1205
ZW
18247 flags = bfd_get_section_flags (stdoutput, now_seg);
18248
18249 /* We can ignore sections that only contain debug info. */
18250 if ((flags & SEC_ALLOC) == 0)
18251 return;
bfae80f2 18252
c19d1205
ZW
18253 seginfo = seg_info (now_seg);
18254 mapstate = seginfo->tc_segment_info_data.mapstate;
18255 marked_pr_dependency = seginfo->tc_segment_info_data.marked_pr_dependency;
bfae80f2
RE
18256}
18257
c19d1205
ZW
18258int
18259arm_elf_section_type (const char * str, size_t len)
e45d0630 18260{
c19d1205
ZW
18261 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18262 return SHT_ARM_EXIDX;
e45d0630 18263
c19d1205
ZW
18264 return -1;
18265}
18266\f
18267/* Code to deal with unwinding tables. */
e45d0630 18268
c19d1205 18269static void add_unwind_adjustsp (offsetT);
e45d0630 18270
5f4273c7 18271/* Generate any deferred unwind frame offset. */
e45d0630 18272
bfae80f2 18273static void
c19d1205 18274flush_pending_unwind (void)
bfae80f2 18275{
c19d1205 18276 offsetT offset;
bfae80f2 18277
c19d1205
ZW
18278 offset = unwind.pending_offset;
18279 unwind.pending_offset = 0;
18280 if (offset != 0)
18281 add_unwind_adjustsp (offset);
bfae80f2
RE
18282}
18283
c19d1205
ZW
18284/* Add an opcode to this list for this function. Two-byte opcodes should
18285 be passed as op[0] << 8 | op[1]. The list of opcodes is built in reverse
18286 order. */
18287
bfae80f2 18288static void
c19d1205 18289add_unwind_opcode (valueT op, int length)
bfae80f2 18290{
c19d1205
ZW
18291 /* Add any deferred stack adjustment. */
18292 if (unwind.pending_offset)
18293 flush_pending_unwind ();
bfae80f2 18294
c19d1205 18295 unwind.sp_restored = 0;
bfae80f2 18296
c19d1205 18297 if (unwind.opcode_count + length > unwind.opcode_alloc)
bfae80f2 18298 {
c19d1205
ZW
18299 unwind.opcode_alloc += ARM_OPCODE_CHUNK_SIZE;
18300 if (unwind.opcodes)
18301 unwind.opcodes = xrealloc (unwind.opcodes,
18302 unwind.opcode_alloc);
18303 else
18304 unwind.opcodes = xmalloc (unwind.opcode_alloc);
bfae80f2 18305 }
c19d1205 18306 while (length > 0)
bfae80f2 18307 {
c19d1205
ZW
18308 length--;
18309 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18310 op >>= 8;
18311 unwind.opcode_count++;
bfae80f2 18312 }
bfae80f2
RE
18313}
18314
c19d1205
ZW
18315/* Add unwind opcodes to adjust the stack pointer. */
18316
bfae80f2 18317static void
c19d1205 18318add_unwind_adjustsp (offsetT offset)
bfae80f2 18319{
c19d1205 18320 valueT op;
bfae80f2 18321
c19d1205 18322 if (offset > 0x200)
bfae80f2 18323 {
c19d1205
ZW
18324 /* We need at most 5 bytes to hold a 32-bit value in a uleb128. */
18325 char bytes[5];
18326 int n;
18327 valueT o;
bfae80f2 18328
c19d1205
ZW
18329 /* Long form: 0xb2, uleb128. */
18330 /* This might not fit in a word so add the individual bytes,
18331 remembering the list is built in reverse order. */
18332 o = (valueT) ((offset - 0x204) >> 2);
18333 if (o == 0)
18334 add_unwind_opcode (0, 1);
bfae80f2 18335
c19d1205
ZW
18336 /* Calculate the uleb128 encoding of the offset. */
18337 n = 0;
18338 while (o)
18339 {
18340 bytes[n] = o & 0x7f;
18341 o >>= 7;
18342 if (o)
18343 bytes[n] |= 0x80;
18344 n++;
18345 }
18346 /* Add the insn. */
18347 for (; n; n--)
18348 add_unwind_opcode (bytes[n - 1], 1);
18349 add_unwind_opcode (0xb2, 1);
18350 }
18351 else if (offset > 0x100)
bfae80f2 18352 {
c19d1205
ZW
18353 /* Two short opcodes. */
18354 add_unwind_opcode (0x3f, 1);
18355 op = (offset - 0x104) >> 2;
18356 add_unwind_opcode (op, 1);
bfae80f2 18357 }
c19d1205
ZW
18358 else if (offset > 0)
18359 {
18360 /* Short opcode. */
18361 op = (offset - 4) >> 2;
18362 add_unwind_opcode (op, 1);
18363 }
18364 else if (offset < 0)
bfae80f2 18365 {
c19d1205
ZW
18366 offset = -offset;
18367 while (offset > 0x100)
bfae80f2 18368 {
c19d1205
ZW
18369 add_unwind_opcode (0x7f, 1);
18370 offset -= 0x100;
bfae80f2 18371 }
c19d1205
ZW
18372 op = ((offset - 4) >> 2) | 0x40;
18373 add_unwind_opcode (op, 1);
bfae80f2 18374 }
bfae80f2
RE
18375}
18376
c19d1205
ZW
18377/* Finish the list of unwind opcodes for this function. */
18378static void
18379finish_unwind_opcodes (void)
bfae80f2 18380{
c19d1205 18381 valueT op;
bfae80f2 18382
c19d1205 18383 if (unwind.fp_used)
bfae80f2 18384 {
708587a4 18385 /* Adjust sp as necessary. */
c19d1205
ZW
18386 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18387 flush_pending_unwind ();
bfae80f2 18388
c19d1205
ZW
18389 /* After restoring sp from the frame pointer. */
18390 op = 0x90 | unwind.fp_reg;
18391 add_unwind_opcode (op, 1);
18392 }
18393 else
18394 flush_pending_unwind ();
bfae80f2
RE
18395}
18396
bfae80f2 18397
c19d1205
ZW
18398/* Start an exception table entry. If idx is nonzero this is an index table
18399 entry. */
bfae80f2
RE
18400
18401static void
c19d1205 18402start_unwind_section (const segT text_seg, int idx)
bfae80f2 18403{
c19d1205
ZW
18404 const char * text_name;
18405 const char * prefix;
18406 const char * prefix_once;
18407 const char * group_name;
18408 size_t prefix_len;
18409 size_t text_len;
18410 char * sec_name;
18411 size_t sec_name_len;
18412 int type;
18413 int flags;
18414 int linkonce;
bfae80f2 18415
c19d1205 18416 if (idx)
bfae80f2 18417 {
c19d1205
ZW
18418 prefix = ELF_STRING_ARM_unwind;
18419 prefix_once = ELF_STRING_ARM_unwind_once;
18420 type = SHT_ARM_EXIDX;
bfae80f2 18421 }
c19d1205 18422 else
bfae80f2 18423 {
c19d1205
ZW
18424 prefix = ELF_STRING_ARM_unwind_info;
18425 prefix_once = ELF_STRING_ARM_unwind_info_once;
18426 type = SHT_PROGBITS;
bfae80f2
RE
18427 }
18428
c19d1205
ZW
18429 text_name = segment_name (text_seg);
18430 if (streq (text_name, ".text"))
18431 text_name = "";
18432
18433 if (strncmp (text_name, ".gnu.linkonce.t.",
18434 strlen (".gnu.linkonce.t.")) == 0)
bfae80f2 18435 {
c19d1205
ZW
18436 prefix = prefix_once;
18437 text_name += strlen (".gnu.linkonce.t.");
bfae80f2
RE
18438 }
18439
c19d1205
ZW
18440 prefix_len = strlen (prefix);
18441 text_len = strlen (text_name);
18442 sec_name_len = prefix_len + text_len;
18443 sec_name = xmalloc (sec_name_len + 1);
18444 memcpy (sec_name, prefix, prefix_len);
18445 memcpy (sec_name + prefix_len, text_name, text_len);
18446 sec_name[prefix_len + text_len] = '\0';
bfae80f2 18447
c19d1205
ZW
18448 flags = SHF_ALLOC;
18449 linkonce = 0;
18450 group_name = 0;
bfae80f2 18451
c19d1205
ZW
18452 /* Handle COMDAT group. */
18453 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
bfae80f2 18454 {
c19d1205
ZW
18455 group_name = elf_group_name (text_seg);
18456 if (group_name == NULL)
18457 {
bd3ba5d1 18458 as_bad (_("Group section `%s' has no group signature"),
c19d1205
ZW
18459 segment_name (text_seg));
18460 ignore_rest_of_line ();
18461 return;
18462 }
18463 flags |= SHF_GROUP;
18464 linkonce = 1;
bfae80f2
RE
18465 }
18466
c19d1205 18467 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
bfae80f2 18468
5f4273c7 18469 /* Set the section link for index tables. */
c19d1205
ZW
18470 if (idx)
18471 elf_linked_to_section (now_seg) = text_seg;
bfae80f2
RE
18472}
18473
bfae80f2 18474
c19d1205
ZW
18475/* Start an unwind table entry. HAVE_DATA is nonzero if we have additional
18476 personality routine data. Returns zero, or the index table value for
18477 and inline entry. */
18478
18479static valueT
18480create_unwind_entry (int have_data)
bfae80f2 18481{
c19d1205
ZW
18482 int size;
18483 addressT where;
18484 char *ptr;
18485 /* The current word of data. */
18486 valueT data;
18487 /* The number of bytes left in this word. */
18488 int n;
bfae80f2 18489
c19d1205 18490 finish_unwind_opcodes ();
bfae80f2 18491
c19d1205
ZW
18492 /* Remember the current text section. */
18493 unwind.saved_seg = now_seg;
18494 unwind.saved_subseg = now_subseg;
bfae80f2 18495
c19d1205 18496 start_unwind_section (now_seg, 0);
bfae80f2 18497
c19d1205 18498 if (unwind.personality_routine == NULL)
bfae80f2 18499 {
c19d1205
ZW
18500 if (unwind.personality_index == -2)
18501 {
18502 if (have_data)
5f4273c7 18503 as_bad (_("handlerdata in cantunwind frame"));
c19d1205
ZW
18504 return 1; /* EXIDX_CANTUNWIND. */
18505 }
bfae80f2 18506
c19d1205
ZW
18507 /* Use a default personality routine if none is specified. */
18508 if (unwind.personality_index == -1)
18509 {
18510 if (unwind.opcode_count > 3)
18511 unwind.personality_index = 1;
18512 else
18513 unwind.personality_index = 0;
18514 }
bfae80f2 18515
c19d1205
ZW
18516 /* Space for the personality routine entry. */
18517 if (unwind.personality_index == 0)
18518 {
18519 if (unwind.opcode_count > 3)
18520 as_bad (_("too many unwind opcodes for personality routine 0"));
bfae80f2 18521
c19d1205
ZW
18522 if (!have_data)
18523 {
18524 /* All the data is inline in the index table. */
18525 data = 0x80;
18526 n = 3;
18527 while (unwind.opcode_count > 0)
18528 {
18529 unwind.opcode_count--;
18530 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18531 n--;
18532 }
bfae80f2 18533
c19d1205
ZW
18534 /* Pad with "finish" opcodes. */
18535 while (n--)
18536 data = (data << 8) | 0xb0;
bfae80f2 18537
c19d1205
ZW
18538 return data;
18539 }
18540 size = 0;
18541 }
18542 else
18543 /* We get two opcodes "free" in the first word. */
18544 size = unwind.opcode_count - 2;
18545 }
18546 else
18547 /* An extra byte is required for the opcode count. */
18548 size = unwind.opcode_count + 1;
bfae80f2 18549
c19d1205
ZW
18550 size = (size + 3) >> 2;
18551 if (size > 0xff)
18552 as_bad (_("too many unwind opcodes"));
bfae80f2 18553
c19d1205
ZW
18554 frag_align (2, 0, 0);
18555 record_alignment (now_seg, 2);
18556 unwind.table_entry = expr_build_dot ();
18557
18558 /* Allocate the table entry. */
18559 ptr = frag_more ((size << 2) + 4);
18560 where = frag_now_fix () - ((size << 2) + 4);
bfae80f2 18561
c19d1205 18562 switch (unwind.personality_index)
bfae80f2 18563 {
c19d1205
ZW
18564 case -1:
18565 /* ??? Should this be a PLT generating relocation? */
18566 /* Custom personality routine. */
18567 fix_new (frag_now, where, 4, unwind.personality_routine, 0, 1,
18568 BFD_RELOC_ARM_PREL31);
bfae80f2 18569
c19d1205
ZW
18570 where += 4;
18571 ptr += 4;
bfae80f2 18572
c19d1205
ZW
18573 /* Set the first byte to the number of additional words. */
18574 data = size - 1;
18575 n = 3;
18576 break;
bfae80f2 18577
c19d1205
ZW
18578 /* ABI defined personality routines. */
18579 case 0:
18580 /* Three opcodes bytes are packed into the first word. */
18581 data = 0x80;
18582 n = 3;
18583 break;
bfae80f2 18584
c19d1205
ZW
18585 case 1:
18586 case 2:
18587 /* The size and first two opcode bytes go in the first word. */
18588 data = ((0x80 + unwind.personality_index) << 8) | size;
18589 n = 2;
18590 break;
bfae80f2 18591
c19d1205
ZW
18592 default:
18593 /* Should never happen. */
18594 abort ();
18595 }
bfae80f2 18596
c19d1205
ZW
18597 /* Pack the opcodes into words (MSB first), reversing the list at the same
18598 time. */
18599 while (unwind.opcode_count > 0)
18600 {
18601 if (n == 0)
18602 {
18603 md_number_to_chars (ptr, data, 4);
18604 ptr += 4;
18605 n = 4;
18606 data = 0;
18607 }
18608 unwind.opcode_count--;
18609 n--;
18610 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18611 }
18612
18613 /* Finish off the last word. */
18614 if (n < 4)
18615 {
18616 /* Pad with "finish" opcodes. */
18617 while (n--)
18618 data = (data << 8) | 0xb0;
18619
18620 md_number_to_chars (ptr, data, 4);
18621 }
18622
18623 if (!have_data)
18624 {
18625 /* Add an empty descriptor if there is no user-specified data. */
18626 ptr = frag_more (4);
18627 md_number_to_chars (ptr, 0, 4);
18628 }
18629
18630 return 0;
bfae80f2
RE
18631}
18632
f0927246
NC
18633
18634/* Initialize the DWARF-2 unwind information for this procedure. */
18635
18636void
18637tc_arm_frame_initial_instructions (void)
18638{
18639 cfi_add_CFA_def_cfa (REG_SP, 0);
18640}
18641#endif /* OBJ_ELF */
18642
c19d1205
ZW
18643/* Convert REGNAME to a DWARF-2 register number. */
18644
18645int
1df69f4f 18646tc_arm_regname_to_dw2regnum (char *regname)
bfae80f2 18647{
1df69f4f 18648 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
c19d1205
ZW
18649
18650 if (reg == FAIL)
18651 return -1;
18652
18653 return reg;
bfae80f2
RE
18654}
18655
f0927246 18656#ifdef TE_PE
c19d1205 18657void
f0927246 18658tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
bfae80f2 18659{
f0927246 18660 expressionS expr;
bfae80f2 18661
f0927246
NC
18662 expr.X_op = O_secrel;
18663 expr.X_add_symbol = symbol;
18664 expr.X_add_number = 0;
18665 emit_expr (&expr, size);
18666}
18667#endif
bfae80f2 18668
c19d1205 18669/* MD interface: Symbol and relocation handling. */
bfae80f2 18670
2fc8bdac
ZW
18671/* Return the address within the segment that a PC-relative fixup is
18672 relative to. For ARM, PC-relative fixups applied to instructions
18673 are generally relative to the location of the fixup plus 8 bytes.
18674 Thumb branches are offset by 4, and Thumb loads relative to PC
18675 require special handling. */
bfae80f2 18676
c19d1205 18677long
2fc8bdac 18678md_pcrel_from_section (fixS * fixP, segT seg)
bfae80f2 18679{
2fc8bdac
ZW
18680 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
18681
18682 /* If this is pc-relative and we are going to emit a relocation
18683 then we just want to put out any pipeline compensation that the linker
53baae48
NC
18684 will need. Otherwise we want to use the calculated base.
18685 For WinCE we skip the bias for externals as well, since this
18686 is how the MS ARM-CE assembler behaves and we want to be compatible. */
5f4273c7 18687 if (fixP->fx_pcrel
2fc8bdac 18688 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
53baae48
NC
18689 || (arm_force_relocation (fixP)
18690#ifdef TE_WINCE
18691 && !S_IS_EXTERNAL (fixP->fx_addsy)
18692#endif
18693 )))
2fc8bdac 18694 base = 0;
bfae80f2 18695
267bf995 18696
c19d1205 18697 switch (fixP->fx_r_type)
bfae80f2 18698 {
2fc8bdac
ZW
18699 /* PC relative addressing on the Thumb is slightly odd as the
18700 bottom two bits of the PC are forced to zero for the
18701 calculation. This happens *after* application of the
18702 pipeline offset. However, Thumb adrl already adjusts for
18703 this, so we need not do it again. */
c19d1205 18704 case BFD_RELOC_ARM_THUMB_ADD:
2fc8bdac 18705 return base & ~3;
c19d1205
ZW
18706
18707 case BFD_RELOC_ARM_THUMB_OFFSET:
18708 case BFD_RELOC_ARM_T32_OFFSET_IMM:
e9f89963 18709 case BFD_RELOC_ARM_T32_ADD_PC12:
8f06b2d8 18710 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
2fc8bdac 18711 return (base + 4) & ~3;
c19d1205 18712
2fc8bdac
ZW
18713 /* Thumb branches are simply offset by +4. */
18714 case BFD_RELOC_THUMB_PCREL_BRANCH7:
18715 case BFD_RELOC_THUMB_PCREL_BRANCH9:
18716 case BFD_RELOC_THUMB_PCREL_BRANCH12:
18717 case BFD_RELOC_THUMB_PCREL_BRANCH20:
2fc8bdac 18718 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac 18719 return base + 4;
bfae80f2 18720
267bf995
RR
18721 case BFD_RELOC_THUMB_PCREL_BRANCH23:
18722 if (fixP->fx_addsy
18723 && ARM_IS_FUNC (fixP->fx_addsy)
18724 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18725 base = fixP->fx_where + fixP->fx_frag->fr_address;
18726 return base + 4;
18727
00adf2d4
JB
18728 /* BLX is like branches above, but forces the low two bits of PC to
18729 zero. */
267bf995
RR
18730 case BFD_RELOC_THUMB_PCREL_BLX:
18731 if (fixP->fx_addsy
18732 && THUMB_IS_FUNC (fixP->fx_addsy)
18733 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18734 base = fixP->fx_where + fixP->fx_frag->fr_address;
00adf2d4
JB
18735 return (base + 4) & ~3;
18736
2fc8bdac
ZW
18737 /* ARM mode branches are offset by +8. However, the Windows CE
18738 loader expects the relocation not to take this into account. */
267bf995
RR
18739 case BFD_RELOC_ARM_PCREL_BLX:
18740 if (fixP->fx_addsy
18741 && ARM_IS_FUNC (fixP->fx_addsy)
18742 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18743 base = fixP->fx_where + fixP->fx_frag->fr_address;
18744 return base + 8;
18745
18746 case BFD_RELOC_ARM_PCREL_CALL:
18747 if (fixP->fx_addsy
18748 && THUMB_IS_FUNC (fixP->fx_addsy)
18749 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
18750 base = fixP->fx_where + fixP->fx_frag->fr_address;
18751 return base + 8;
18752
2fc8bdac 18753 case BFD_RELOC_ARM_PCREL_BRANCH:
39b41c9c 18754 case BFD_RELOC_ARM_PCREL_JUMP:
2fc8bdac 18755 case BFD_RELOC_ARM_PLT32:
c19d1205 18756#ifdef TE_WINCE
5f4273c7 18757 /* When handling fixups immediately, because we have already
53baae48
NC
18758 discovered the value of a symbol, or the address of the frag involved
18759 we must account for the offset by +8, as the OS loader will never see the reloc.
18760 see fixup_segment() in write.c
18761 The S_IS_EXTERNAL test handles the case of global symbols.
18762 Those need the calculated base, not just the pipe compensation the linker will need. */
18763 if (fixP->fx_pcrel
18764 && fixP->fx_addsy != NULL
18765 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
18766 && (S_IS_EXTERNAL (fixP->fx_addsy) || !arm_force_relocation (fixP)))
18767 return base + 8;
2fc8bdac 18768 return base;
c19d1205 18769#else
2fc8bdac 18770 return base + 8;
c19d1205 18771#endif
2fc8bdac 18772
267bf995 18773
2fc8bdac
ZW
18774 /* ARM mode loads relative to PC are also offset by +8. Unlike
18775 branches, the Windows CE loader *does* expect the relocation
18776 to take this into account. */
18777 case BFD_RELOC_ARM_OFFSET_IMM:
18778 case BFD_RELOC_ARM_OFFSET_IMM8:
18779 case BFD_RELOC_ARM_HWLITERAL:
18780 case BFD_RELOC_ARM_LITERAL:
18781 case BFD_RELOC_ARM_CP_OFF_IMM:
18782 return base + 8;
18783
18784
18785 /* Other PC-relative relocations are un-offset. */
18786 default:
18787 return base;
18788 }
bfae80f2
RE
18789}
18790
c19d1205
ZW
18791/* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18792 Otherwise we have no need to default values of symbols. */
18793
18794symbolS *
18795md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
bfae80f2 18796{
c19d1205
ZW
18797#ifdef OBJ_ELF
18798 if (name[0] == '_' && name[1] == 'G'
18799 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18800 {
18801 if (!GOT_symbol)
18802 {
18803 if (symbol_find (name))
bd3ba5d1 18804 as_bad (_("GOT already in the symbol table"));
bfae80f2 18805
c19d1205
ZW
18806 GOT_symbol = symbol_new (name, undefined_section,
18807 (valueT) 0, & zero_address_frag);
18808 }
bfae80f2 18809
c19d1205 18810 return GOT_symbol;
bfae80f2 18811 }
c19d1205 18812#endif
bfae80f2 18813
c19d1205 18814 return 0;
bfae80f2
RE
18815}
18816
55cf6793 18817/* Subroutine of md_apply_fix. Check to see if an immediate can be
c19d1205
ZW
18818 computed as two separate immediate values, added together. We
18819 already know that this value cannot be computed by just one ARM
18820 instruction. */
18821
18822static unsigned int
18823validate_immediate_twopart (unsigned int val,
18824 unsigned int * highpart)
bfae80f2 18825{
c19d1205
ZW
18826 unsigned int a;
18827 unsigned int i;
bfae80f2 18828
c19d1205
ZW
18829 for (i = 0; i < 32; i += 2)
18830 if (((a = rotate_left (val, i)) & 0xff) != 0)
18831 {
18832 if (a & 0xff00)
18833 {
18834 if (a & ~ 0xffff)
18835 continue;
18836 * highpart = (a >> 8) | ((i + 24) << 7);
18837 }
18838 else if (a & 0xff0000)
18839 {
18840 if (a & 0xff000000)
18841 continue;
18842 * highpart = (a >> 16) | ((i + 16) << 7);
18843 }
18844 else
18845 {
9c2799c2 18846 gas_assert (a & 0xff000000);
c19d1205
ZW
18847 * highpart = (a >> 24) | ((i + 8) << 7);
18848 }
bfae80f2 18849
c19d1205
ZW
18850 return (a & 0xff) | (i << 7);
18851 }
bfae80f2 18852
c19d1205 18853 return FAIL;
bfae80f2
RE
18854}
18855
c19d1205
ZW
18856static int
18857validate_offset_imm (unsigned int val, int hwse)
18858{
18859 if ((hwse && val > 255) || val > 4095)
18860 return FAIL;
18861 return val;
18862}
bfae80f2 18863
55cf6793 18864/* Subroutine of md_apply_fix. Do those data_ops which can take a
c19d1205
ZW
18865 negative immediate constant by altering the instruction. A bit of
18866 a hack really.
18867 MOV <-> MVN
18868 AND <-> BIC
18869 ADC <-> SBC
18870 by inverting the second operand, and
18871 ADD <-> SUB
18872 CMP <-> CMN
18873 by negating the second operand. */
bfae80f2 18874
c19d1205
ZW
18875static int
18876negate_data_op (unsigned long * instruction,
18877 unsigned long value)
bfae80f2 18878{
c19d1205
ZW
18879 int op, new_inst;
18880 unsigned long negated, inverted;
bfae80f2 18881
c19d1205
ZW
18882 negated = encode_arm_immediate (-value);
18883 inverted = encode_arm_immediate (~value);
bfae80f2 18884
c19d1205
ZW
18885 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18886 switch (op)
bfae80f2 18887 {
c19d1205
ZW
18888 /* First negates. */
18889 case OPCODE_SUB: /* ADD <-> SUB */
18890 new_inst = OPCODE_ADD;
18891 value = negated;
18892 break;
bfae80f2 18893
c19d1205
ZW
18894 case OPCODE_ADD:
18895 new_inst = OPCODE_SUB;
18896 value = negated;
18897 break;
bfae80f2 18898
c19d1205
ZW
18899 case OPCODE_CMP: /* CMP <-> CMN */
18900 new_inst = OPCODE_CMN;
18901 value = negated;
18902 break;
bfae80f2 18903
c19d1205
ZW
18904 case OPCODE_CMN:
18905 new_inst = OPCODE_CMP;
18906 value = negated;
18907 break;
bfae80f2 18908
c19d1205
ZW
18909 /* Now Inverted ops. */
18910 case OPCODE_MOV: /* MOV <-> MVN */
18911 new_inst = OPCODE_MVN;
18912 value = inverted;
18913 break;
bfae80f2 18914
c19d1205
ZW
18915 case OPCODE_MVN:
18916 new_inst = OPCODE_MOV;
18917 value = inverted;
18918 break;
bfae80f2 18919
c19d1205
ZW
18920 case OPCODE_AND: /* AND <-> BIC */
18921 new_inst = OPCODE_BIC;
18922 value = inverted;
18923 break;
bfae80f2 18924
c19d1205
ZW
18925 case OPCODE_BIC:
18926 new_inst = OPCODE_AND;
18927 value = inverted;
18928 break;
bfae80f2 18929
c19d1205
ZW
18930 case OPCODE_ADC: /* ADC <-> SBC */
18931 new_inst = OPCODE_SBC;
18932 value = inverted;
18933 break;
bfae80f2 18934
c19d1205
ZW
18935 case OPCODE_SBC:
18936 new_inst = OPCODE_ADC;
18937 value = inverted;
18938 break;
bfae80f2 18939
c19d1205
ZW
18940 /* We cannot do anything. */
18941 default:
18942 return FAIL;
b99bd4ef
NC
18943 }
18944
c19d1205
ZW
18945 if (value == (unsigned) FAIL)
18946 return FAIL;
18947
18948 *instruction &= OPCODE_MASK;
18949 *instruction |= new_inst << DATA_OP_SHIFT;
18950 return value;
b99bd4ef
NC
18951}
18952
ef8d22e6
PB
18953/* Like negate_data_op, but for Thumb-2. */
18954
18955static unsigned int
16dd5e42 18956thumb32_negate_data_op (offsetT *instruction, unsigned int value)
ef8d22e6
PB
18957{
18958 int op, new_inst;
18959 int rd;
16dd5e42 18960 unsigned int negated, inverted;
ef8d22e6
PB
18961
18962 negated = encode_thumb32_immediate (-value);
18963 inverted = encode_thumb32_immediate (~value);
18964
18965 rd = (*instruction >> 8) & 0xf;
18966 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18967 switch (op)
18968 {
18969 /* ADD <-> SUB. Includes CMP <-> CMN. */
18970 case T2_OPCODE_SUB:
18971 new_inst = T2_OPCODE_ADD;
18972 value = negated;
18973 break;
18974
18975 case T2_OPCODE_ADD:
18976 new_inst = T2_OPCODE_SUB;
18977 value = negated;
18978 break;
18979
18980 /* ORR <-> ORN. Includes MOV <-> MVN. */
18981 case T2_OPCODE_ORR:
18982 new_inst = T2_OPCODE_ORN;
18983 value = inverted;
18984 break;
18985
18986 case T2_OPCODE_ORN:
18987 new_inst = T2_OPCODE_ORR;
18988 value = inverted;
18989 break;
18990
18991 /* AND <-> BIC. TST has no inverted equivalent. */
18992 case T2_OPCODE_AND:
18993 new_inst = T2_OPCODE_BIC;
18994 if (rd == 15)
18995 value = FAIL;
18996 else
18997 value = inverted;
18998 break;
18999
19000 case T2_OPCODE_BIC:
19001 new_inst = T2_OPCODE_AND;
19002 value = inverted;
19003 break;
19004
19005 /* ADC <-> SBC */
19006 case T2_OPCODE_ADC:
19007 new_inst = T2_OPCODE_SBC;
19008 value = inverted;
19009 break;
19010
19011 case T2_OPCODE_SBC:
19012 new_inst = T2_OPCODE_ADC;
19013 value = inverted;
19014 break;
19015
19016 /* We cannot do anything. */
19017 default:
19018 return FAIL;
19019 }
19020
16dd5e42 19021 if (value == (unsigned int)FAIL)
ef8d22e6
PB
19022 return FAIL;
19023
19024 *instruction &= T2_OPCODE_MASK;
19025 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19026 return value;
19027}
19028
8f06b2d8
PB
19029/* Read a 32-bit thumb instruction from buf. */
19030static unsigned long
19031get_thumb32_insn (char * buf)
19032{
19033 unsigned long insn;
19034 insn = md_chars_to_number (buf, THUMB_SIZE) << 16;
19035 insn |= md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19036
19037 return insn;
19038}
19039
a8bc6c78
PB
19040
19041/* We usually want to set the low bit on the address of thumb function
19042 symbols. In particular .word foo - . should have the low bit set.
19043 Generic code tries to fold the difference of two symbols to
19044 a constant. Prevent this and force a relocation when the first symbols
19045 is a thumb function. */
19046int
19047arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
19048{
19049 if (op == O_subtract
19050 && l->X_op == O_symbol
19051 && r->X_op == O_symbol
19052 && THUMB_IS_FUNC (l->X_add_symbol))
19053 {
19054 l->X_op = O_subtract;
19055 l->X_op_symbol = r->X_add_symbol;
19056 l->X_add_number -= r->X_add_number;
19057 return 1;
19058 }
19059 /* Process as normal. */
19060 return 0;
19061}
19062
c19d1205 19063void
55cf6793 19064md_apply_fix (fixS * fixP,
c19d1205
ZW
19065 valueT * valP,
19066 segT seg)
19067{
19068 offsetT value = * valP;
19069 offsetT newval;
19070 unsigned int newimm;
19071 unsigned long temp;
19072 int sign;
19073 char * buf = fixP->fx_where + fixP->fx_frag->fr_literal;
b99bd4ef 19074
9c2799c2 19075 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
b99bd4ef 19076
c19d1205 19077 /* Note whether this will delete the relocation. */
4962c51a 19078
c19d1205
ZW
19079 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19080 fixP->fx_done = 1;
b99bd4ef 19081
adbaf948 19082 /* On a 64-bit host, silently truncate 'value' to 32 bits for
5f4273c7 19083 consistency with the behaviour on 32-bit hosts. Remember value
adbaf948
ZW
19084 for emit_reloc. */
19085 value &= 0xffffffff;
19086 value ^= 0x80000000;
5f4273c7 19087 value -= 0x80000000;
adbaf948
ZW
19088
19089 *valP = value;
c19d1205 19090 fixP->fx_addnumber = value;
b99bd4ef 19091
adbaf948
ZW
19092 /* Same treatment for fixP->fx_offset. */
19093 fixP->fx_offset &= 0xffffffff;
19094 fixP->fx_offset ^= 0x80000000;
19095 fixP->fx_offset -= 0x80000000;
19096
c19d1205 19097 switch (fixP->fx_r_type)
b99bd4ef 19098 {
c19d1205
ZW
19099 case BFD_RELOC_NONE:
19100 /* This will need to go in the object file. */
19101 fixP->fx_done = 0;
19102 break;
b99bd4ef 19103
c19d1205
ZW
19104 case BFD_RELOC_ARM_IMMEDIATE:
19105 /* We claim that this fixup has been processed here,
19106 even if in fact we generate an error because we do
19107 not have a reloc for it, so tc_gen_reloc will reject it. */
19108 fixP->fx_done = 1;
b99bd4ef 19109
c19d1205
ZW
19110 if (fixP->fx_addsy
19111 && ! S_IS_DEFINED (fixP->fx_addsy))
b99bd4ef 19112 {
c19d1205
ZW
19113 as_bad_where (fixP->fx_file, fixP->fx_line,
19114 _("undefined symbol %s used as an immediate value"),
19115 S_GET_NAME (fixP->fx_addsy));
19116 break;
b99bd4ef
NC
19117 }
19118
42e5fcbf
AS
19119 if (fixP->fx_addsy
19120 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19121 {
19122 as_bad_where (fixP->fx_file, fixP->fx_line,
19123 _("symbol %s is in a different section"),
19124 S_GET_NAME (fixP->fx_addsy));
19125 break;
19126 }
19127
c19d1205
ZW
19128 newimm = encode_arm_immediate (value);
19129 temp = md_chars_to_number (buf, INSN_SIZE);
19130
19131 /* If the instruction will fail, see if we can fix things up by
19132 changing the opcode. */
19133 if (newimm == (unsigned int) FAIL
19134 && (newimm = negate_data_op (&temp, value)) == (unsigned int) FAIL)
b99bd4ef 19135 {
c19d1205
ZW
19136 as_bad_where (fixP->fx_file, fixP->fx_line,
19137 _("invalid constant (%lx) after fixup"),
19138 (unsigned long) value);
19139 break;
b99bd4ef 19140 }
b99bd4ef 19141
c19d1205
ZW
19142 newimm |= (temp & 0xfffff000);
19143 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19144 break;
b99bd4ef 19145
c19d1205
ZW
19146 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19147 {
19148 unsigned int highpart = 0;
19149 unsigned int newinsn = 0xe1a00000; /* nop. */
b99bd4ef 19150
42e5fcbf
AS
19151 if (fixP->fx_addsy
19152 && ! S_IS_DEFINED (fixP->fx_addsy))
19153 {
19154 as_bad_where (fixP->fx_file, fixP->fx_line,
19155 _("undefined symbol %s used as an immediate value"),
19156 S_GET_NAME (fixP->fx_addsy));
19157 break;
19158 }
19159
19160 if (fixP->fx_addsy
19161 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
19162 {
19163 as_bad_where (fixP->fx_file, fixP->fx_line,
19164 _("symbol %s is in a different section"),
19165 S_GET_NAME (fixP->fx_addsy));
19166 break;
19167 }
19168
c19d1205
ZW
19169 newimm = encode_arm_immediate (value);
19170 temp = md_chars_to_number (buf, INSN_SIZE);
b99bd4ef 19171
c19d1205
ZW
19172 /* If the instruction will fail, see if we can fix things up by
19173 changing the opcode. */
19174 if (newimm == (unsigned int) FAIL
19175 && (newimm = negate_data_op (& temp, value)) == (unsigned int) FAIL)
19176 {
19177 /* No ? OK - try using two ADD instructions to generate
19178 the value. */
19179 newimm = validate_immediate_twopart (value, & highpart);
b99bd4ef 19180
c19d1205
ZW
19181 /* Yes - then make sure that the second instruction is
19182 also an add. */
19183 if (newimm != (unsigned int) FAIL)
19184 newinsn = temp;
19185 /* Still No ? Try using a negated value. */
19186 else if ((newimm = validate_immediate_twopart (- value, & highpart)) != (unsigned int) FAIL)
19187 temp = newinsn = (temp & OPCODE_MASK) | OPCODE_SUB << DATA_OP_SHIFT;
19188 /* Otherwise - give up. */
19189 else
19190 {
19191 as_bad_where (fixP->fx_file, fixP->fx_line,
19192 _("unable to compute ADRL instructions for PC offset of 0x%lx"),
19193 (long) value);
19194 break;
19195 }
b99bd4ef 19196
c19d1205
ZW
19197 /* Replace the first operand in the 2nd instruction (which
19198 is the PC) with the destination register. We have
19199 already added in the PC in the first instruction and we
19200 do not want to do it again. */
19201 newinsn &= ~ 0xf0000;
19202 newinsn |= ((newinsn & 0x0f000) << 4);
19203 }
b99bd4ef 19204
c19d1205
ZW
19205 newimm |= (temp & 0xfffff000);
19206 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
b99bd4ef 19207
c19d1205
ZW
19208 highpart |= (newinsn & 0xfffff000);
19209 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19210 }
19211 break;
b99bd4ef 19212
c19d1205 19213 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
19214 if (!fixP->fx_done && seg->use_rela_p)
19215 value = 0;
19216
c19d1205
ZW
19217 case BFD_RELOC_ARM_LITERAL:
19218 sign = value >= 0;
b99bd4ef 19219
c19d1205
ZW
19220 if (value < 0)
19221 value = - value;
b99bd4ef 19222
c19d1205 19223 if (validate_offset_imm (value, 0) == FAIL)
f03698e6 19224 {
c19d1205
ZW
19225 if (fixP->fx_r_type == BFD_RELOC_ARM_LITERAL)
19226 as_bad_where (fixP->fx_file, fixP->fx_line,
19227 _("invalid literal constant: pool needs to be closer"));
19228 else
19229 as_bad_where (fixP->fx_file, fixP->fx_line,
19230 _("bad immediate value for offset (%ld)"),
19231 (long) value);
19232 break;
f03698e6
RE
19233 }
19234
c19d1205
ZW
19235 newval = md_chars_to_number (buf, INSN_SIZE);
19236 newval &= 0xff7ff000;
19237 newval |= value | (sign ? INDEX_UP : 0);
19238 md_number_to_chars (buf, newval, INSN_SIZE);
19239 break;
b99bd4ef 19240
c19d1205
ZW
19241 case BFD_RELOC_ARM_OFFSET_IMM8:
19242 case BFD_RELOC_ARM_HWLITERAL:
19243 sign = value >= 0;
b99bd4ef 19244
c19d1205
ZW
19245 if (value < 0)
19246 value = - value;
b99bd4ef 19247
c19d1205 19248 if (validate_offset_imm (value, 1) == FAIL)
b99bd4ef 19249 {
c19d1205
ZW
19250 if (fixP->fx_r_type == BFD_RELOC_ARM_HWLITERAL)
19251 as_bad_where (fixP->fx_file, fixP->fx_line,
19252 _("invalid literal constant: pool needs to be closer"));
19253 else
f9d4405b 19254 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
c19d1205
ZW
19255 (long) value);
19256 break;
b99bd4ef
NC
19257 }
19258
c19d1205
ZW
19259 newval = md_chars_to_number (buf, INSN_SIZE);
19260 newval &= 0xff7ff0f0;
19261 newval |= ((value >> 4) << 8) | (value & 0xf) | (sign ? INDEX_UP : 0);
19262 md_number_to_chars (buf, newval, INSN_SIZE);
19263 break;
b99bd4ef 19264
c19d1205
ZW
19265 case BFD_RELOC_ARM_T32_OFFSET_U8:
19266 if (value < 0 || value > 1020 || value % 4 != 0)
19267 as_bad_where (fixP->fx_file, fixP->fx_line,
19268 _("bad immediate value for offset (%ld)"), (long) value);
19269 value /= 4;
b99bd4ef 19270
c19d1205 19271 newval = md_chars_to_number (buf+2, THUMB_SIZE);
c19d1205
ZW
19272 newval |= value;
19273 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19274 break;
b99bd4ef 19275
c19d1205
ZW
19276 case BFD_RELOC_ARM_T32_OFFSET_IMM:
19277 /* This is a complicated relocation used for all varieties of Thumb32
19278 load/store instruction with immediate offset:
19279
19280 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19281 *4, optional writeback(W)
19282 (doubleword load/store)
19283
19284 1111 100S uTTL 1111 XXXX iiii iiii iiii - +/-(U) 12-bit PC-rel
19285 1111 100S 0TTL NNNN XXXX 1Pu1 iiii iiii - +/-(U) pre/post(P) 8-bit
19286 1111 100S 0TTL NNNN XXXX 1110 iiii iiii - positive 8-bit (T instruction)
19287 1111 100S 1TTL NNNN XXXX iiii iiii iiii - positive 12-bit
19288 1111 100S 0TTL NNNN XXXX 1100 iiii iiii - negative 8-bit
19289
19290 Uppercase letters indicate bits that are already encoded at
19291 this point. Lowercase letters are our problem. For the
19292 second block of instructions, the secondary opcode nybble
19293 (bits 8..11) is present, and bit 23 is zero, even if this is
19294 a PC-relative operation. */
19295 newval = md_chars_to_number (buf, THUMB_SIZE);
19296 newval <<= 16;
19297 newval |= md_chars_to_number (buf+THUMB_SIZE, THUMB_SIZE);
b99bd4ef 19298
c19d1205 19299 if ((newval & 0xf0000000) == 0xe0000000)
b99bd4ef 19300 {
c19d1205
ZW
19301 /* Doubleword load/store: 8-bit offset, scaled by 4. */
19302 if (value >= 0)
19303 newval |= (1 << 23);
19304 else
19305 value = -value;
19306 if (value % 4 != 0)
19307 {
19308 as_bad_where (fixP->fx_file, fixP->fx_line,
19309 _("offset not a multiple of 4"));
19310 break;
19311 }
19312 value /= 4;
216d22bc 19313 if (value > 0xff)
c19d1205
ZW
19314 {
19315 as_bad_where (fixP->fx_file, fixP->fx_line,
19316 _("offset out of range"));
19317 break;
19318 }
19319 newval &= ~0xff;
b99bd4ef 19320 }
c19d1205 19321 else if ((newval & 0x000f0000) == 0x000f0000)
b99bd4ef 19322 {
c19d1205
ZW
19323 /* PC-relative, 12-bit offset. */
19324 if (value >= 0)
19325 newval |= (1 << 23);
19326 else
19327 value = -value;
216d22bc 19328 if (value > 0xfff)
c19d1205
ZW
19329 {
19330 as_bad_where (fixP->fx_file, fixP->fx_line,
19331 _("offset out of range"));
19332 break;
19333 }
19334 newval &= ~0xfff;
b99bd4ef 19335 }
c19d1205 19336 else if ((newval & 0x00000100) == 0x00000100)
b99bd4ef 19337 {
c19d1205
ZW
19338 /* Writeback: 8-bit, +/- offset. */
19339 if (value >= 0)
19340 newval |= (1 << 9);
19341 else
19342 value = -value;
216d22bc 19343 if (value > 0xff)
c19d1205
ZW
19344 {
19345 as_bad_where (fixP->fx_file, fixP->fx_line,
19346 _("offset out of range"));
19347 break;
19348 }
19349 newval &= ~0xff;
b99bd4ef 19350 }
c19d1205 19351 else if ((newval & 0x00000f00) == 0x00000e00)
b99bd4ef 19352 {
c19d1205 19353 /* T-instruction: positive 8-bit offset. */
216d22bc 19354 if (value < 0 || value > 0xff)
b99bd4ef 19355 {
c19d1205
ZW
19356 as_bad_where (fixP->fx_file, fixP->fx_line,
19357 _("offset out of range"));
19358 break;
b99bd4ef 19359 }
c19d1205
ZW
19360 newval &= ~0xff;
19361 newval |= value;
b99bd4ef
NC
19362 }
19363 else
b99bd4ef 19364 {
c19d1205
ZW
19365 /* Positive 12-bit or negative 8-bit offset. */
19366 int limit;
19367 if (value >= 0)
b99bd4ef 19368 {
c19d1205
ZW
19369 newval |= (1 << 23);
19370 limit = 0xfff;
19371 }
19372 else
19373 {
19374 value = -value;
19375 limit = 0xff;
19376 }
19377 if (value > limit)
19378 {
19379 as_bad_where (fixP->fx_file, fixP->fx_line,
19380 _("offset out of range"));
19381 break;
b99bd4ef 19382 }
c19d1205 19383 newval &= ~limit;
b99bd4ef 19384 }
b99bd4ef 19385
c19d1205
ZW
19386 newval |= value;
19387 md_number_to_chars (buf, (newval >> 16) & 0xffff, THUMB_SIZE);
19388 md_number_to_chars (buf + THUMB_SIZE, newval & 0xffff, THUMB_SIZE);
19389 break;
404ff6b5 19390
c19d1205
ZW
19391 case BFD_RELOC_ARM_SHIFT_IMM:
19392 newval = md_chars_to_number (buf, INSN_SIZE);
19393 if (((unsigned long) value) > 32
19394 || (value == 32
19395 && (((newval & 0x60) == 0) || (newval & 0x60) == 0x60)))
19396 {
19397 as_bad_where (fixP->fx_file, fixP->fx_line,
19398 _("shift expression is too large"));
19399 break;
19400 }
404ff6b5 19401
c19d1205
ZW
19402 if (value == 0)
19403 /* Shifts of zero must be done as lsl. */
19404 newval &= ~0x60;
19405 else if (value == 32)
19406 value = 0;
19407 newval &= 0xfffff07f;
19408 newval |= (value & 0x1f) << 7;
19409 md_number_to_chars (buf, newval, INSN_SIZE);
19410 break;
404ff6b5 19411
c19d1205 19412 case BFD_RELOC_ARM_T32_IMMEDIATE:
16805f35 19413 case BFD_RELOC_ARM_T32_ADD_IMM:
92e90b6e 19414 case BFD_RELOC_ARM_T32_IMM12:
e9f89963 19415 case BFD_RELOC_ARM_T32_ADD_PC12:
c19d1205
ZW
19416 /* We claim that this fixup has been processed here,
19417 even if in fact we generate an error because we do
19418 not have a reloc for it, so tc_gen_reloc will reject it. */
19419 fixP->fx_done = 1;
404ff6b5 19420
c19d1205
ZW
19421 if (fixP->fx_addsy
19422 && ! S_IS_DEFINED (fixP->fx_addsy))
19423 {
19424 as_bad_where (fixP->fx_file, fixP->fx_line,
19425 _("undefined symbol %s used as an immediate value"),
19426 S_GET_NAME (fixP->fx_addsy));
19427 break;
19428 }
404ff6b5 19429
c19d1205
ZW
19430 newval = md_chars_to_number (buf, THUMB_SIZE);
19431 newval <<= 16;
19432 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
404ff6b5 19433
16805f35
PB
19434 newimm = FAIL;
19435 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
19436 || fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
ef8d22e6
PB
19437 {
19438 newimm = encode_thumb32_immediate (value);
19439 if (newimm == (unsigned int) FAIL)
19440 newimm = thumb32_negate_data_op (&newval, value);
19441 }
16805f35
PB
19442 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19443 && newimm == (unsigned int) FAIL)
92e90b6e 19444 {
16805f35
PB
19445 /* Turn add/sum into addw/subw. */
19446 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19447 newval = (newval & 0xfeffffff) | 0x02000000;
19448
e9f89963
PB
19449 /* 12 bit immediate for addw/subw. */
19450 if (value < 0)
19451 {
19452 value = -value;
19453 newval ^= 0x00a00000;
19454 }
92e90b6e
PB
19455 if (value > 0xfff)
19456 newimm = (unsigned int) FAIL;
19457 else
19458 newimm = value;
19459 }
cc8a6dd0 19460
c19d1205 19461 if (newimm == (unsigned int)FAIL)
3631a3c8 19462 {
c19d1205
ZW
19463 as_bad_where (fixP->fx_file, fixP->fx_line,
19464 _("invalid constant (%lx) after fixup"),
19465 (unsigned long) value);
19466 break;
3631a3c8
NC
19467 }
19468
c19d1205
ZW
19469 newval |= (newimm & 0x800) << 15;
19470 newval |= (newimm & 0x700) << 4;
19471 newval |= (newimm & 0x0ff);
cc8a6dd0 19472
c19d1205
ZW
19473 md_number_to_chars (buf, (valueT) ((newval >> 16) & 0xffff), THUMB_SIZE);
19474 md_number_to_chars (buf+2, (valueT) (newval & 0xffff), THUMB_SIZE);
19475 break;
a737bd4d 19476
3eb17e6b 19477 case BFD_RELOC_ARM_SMC:
c19d1205
ZW
19478 if (((unsigned long) value) > 0xffff)
19479 as_bad_where (fixP->fx_file, fixP->fx_line,
3eb17e6b 19480 _("invalid smc expression"));
2fc8bdac 19481 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19482 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
19483 md_number_to_chars (buf, newval, INSN_SIZE);
19484 break;
a737bd4d 19485
c19d1205 19486 case BFD_RELOC_ARM_SWI:
adbaf948 19487 if (fixP->tc_fix_data != 0)
c19d1205
ZW
19488 {
19489 if (((unsigned long) value) > 0xff)
19490 as_bad_where (fixP->fx_file, fixP->fx_line,
19491 _("invalid swi expression"));
2fc8bdac 19492 newval = md_chars_to_number (buf, THUMB_SIZE);
c19d1205
ZW
19493 newval |= value;
19494 md_number_to_chars (buf, newval, THUMB_SIZE);
19495 }
19496 else
19497 {
19498 if (((unsigned long) value) > 0x00ffffff)
19499 as_bad_where (fixP->fx_file, fixP->fx_line,
19500 _("invalid swi expression"));
2fc8bdac 19501 newval = md_chars_to_number (buf, INSN_SIZE);
c19d1205
ZW
19502 newval |= value;
19503 md_number_to_chars (buf, newval, INSN_SIZE);
19504 }
19505 break;
a737bd4d 19506
c19d1205
ZW
19507 case BFD_RELOC_ARM_MULTI:
19508 if (((unsigned long) value) > 0xffff)
19509 as_bad_where (fixP->fx_file, fixP->fx_line,
19510 _("invalid expression in load/store multiple"));
19511 newval = value | md_chars_to_number (buf, INSN_SIZE);
19512 md_number_to_chars (buf, newval, INSN_SIZE);
19513 break;
a737bd4d 19514
c19d1205 19515#ifdef OBJ_ELF
39b41c9c 19516 case BFD_RELOC_ARM_PCREL_CALL:
267bf995
RR
19517
19518 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19519 && fixP->fx_addsy
19520 && !S_IS_EXTERNAL (fixP->fx_addsy)
19521 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19522 && THUMB_IS_FUNC (fixP->fx_addsy))
19523 /* Flip the bl to blx. This is a simple flip
19524 bit here because we generate PCREL_CALL for
19525 unconditional bls. */
19526 {
19527 newval = md_chars_to_number (buf, INSN_SIZE);
19528 newval = newval | 0x10000000;
19529 md_number_to_chars (buf, newval, INSN_SIZE);
19530 temp = 1;
19531 fixP->fx_done = 1;
19532 }
39b41c9c
PB
19533 else
19534 temp = 3;
19535 goto arm_branch_common;
19536
19537 case BFD_RELOC_ARM_PCREL_JUMP:
267bf995
RR
19538 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19539 && fixP->fx_addsy
19540 && !S_IS_EXTERNAL (fixP->fx_addsy)
19541 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19542 && THUMB_IS_FUNC (fixP->fx_addsy))
19543 {
19544 /* This would map to a bl<cond>, b<cond>,
19545 b<always> to a Thumb function. We
19546 need to force a relocation for this particular
19547 case. */
19548 newval = md_chars_to_number (buf, INSN_SIZE);
19549 fixP->fx_done = 0;
19550 }
19551
2fc8bdac 19552 case BFD_RELOC_ARM_PLT32:
c19d1205 19553#endif
39b41c9c
PB
19554 case BFD_RELOC_ARM_PCREL_BRANCH:
19555 temp = 3;
19556 goto arm_branch_common;
a737bd4d 19557
39b41c9c 19558 case BFD_RELOC_ARM_PCREL_BLX:
267bf995 19559
39b41c9c 19560 temp = 1;
267bf995
RR
19561 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
19562 && fixP->fx_addsy
19563 && !S_IS_EXTERNAL (fixP->fx_addsy)
19564 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19565 && ARM_IS_FUNC (fixP->fx_addsy))
19566 {
19567 /* Flip the blx to a bl and warn. */
19568 const char *name = S_GET_NAME (fixP->fx_addsy);
19569 newval = 0xeb000000;
19570 as_warn_where (fixP->fx_file, fixP->fx_line,
19571 _("blx to '%s' an ARM ISA state function changed to bl"),
19572 name);
19573 md_number_to_chars (buf, newval, INSN_SIZE);
19574 temp = 3;
19575 fixP->fx_done = 1;
19576 }
19577
19578#ifdef OBJ_ELF
19579 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
19580 fixP->fx_r_type = BFD_RELOC_ARM_PCREL_CALL;
19581#endif
19582
39b41c9c 19583 arm_branch_common:
c19d1205 19584 /* We are going to store value (shifted right by two) in the
39b41c9c
PB
19585 instruction, in a 24 bit, signed field. Bits 26 through 32 either
19586 all clear or all set and bit 0 must be clear. For B/BL bit 1 must
19587 also be be clear. */
19588 if (value & temp)
c19d1205 19589 as_bad_where (fixP->fx_file, fixP->fx_line,
2fc8bdac
ZW
19590 _("misaligned branch destination"));
19591 if ((value & (offsetT)0xfe000000) != (offsetT)0
19592 && (value & (offsetT)0xfe000000) != (offsetT)0xfe000000)
19593 as_bad_where (fixP->fx_file, fixP->fx_line,
19594 _("branch out of range"));
a737bd4d 19595
2fc8bdac 19596 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19597 {
2fc8bdac
ZW
19598 newval = md_chars_to_number (buf, INSN_SIZE);
19599 newval |= (value >> 2) & 0x00ffffff;
7ae2971b
PB
19600 /* Set the H bit on BLX instructions. */
19601 if (temp == 1)
19602 {
19603 if (value & 2)
19604 newval |= 0x01000000;
19605 else
19606 newval &= ~0x01000000;
19607 }
2fc8bdac 19608 md_number_to_chars (buf, newval, INSN_SIZE);
c19d1205 19609 }
c19d1205 19610 break;
a737bd4d 19611
25fe350b
MS
19612 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19613 /* CBZ can only branch forward. */
a737bd4d 19614
738755b0
MS
19615 /* Attempts to use CBZ to branch to the next instruction
19616 (which, strictly speaking, are prohibited) will be turned into
19617 no-ops.
19618
19619 FIXME: It may be better to remove the instruction completely and
19620 perform relaxation. */
19621 if (value == -2)
2fc8bdac
ZW
19622 {
19623 newval = md_chars_to_number (buf, THUMB_SIZE);
738755b0 19624 newval = 0xbf00; /* NOP encoding T1 */
2fc8bdac
ZW
19625 md_number_to_chars (buf, newval, THUMB_SIZE);
19626 }
738755b0
MS
19627 else
19628 {
19629 if (value & ~0x7e)
19630 as_bad_where (fixP->fx_file, fixP->fx_line,
19631 _("branch out of range"));
19632
19633 if (fixP->fx_done || !seg->use_rela_p)
19634 {
19635 newval = md_chars_to_number (buf, THUMB_SIZE);
19636 newval |= ((value & 0x3e) << 2) | ((value & 0x40) << 3);
19637 md_number_to_chars (buf, newval, THUMB_SIZE);
19638 }
19639 }
c19d1205 19640 break;
a737bd4d 19641
c19d1205 19642 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
2fc8bdac
ZW
19643 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19644 as_bad_where (fixP->fx_file, fixP->fx_line,
19645 _("branch out of range"));
a737bd4d 19646
2fc8bdac
ZW
19647 if (fixP->fx_done || !seg->use_rela_p)
19648 {
19649 newval = md_chars_to_number (buf, THUMB_SIZE);
19650 newval |= (value & 0x1ff) >> 1;
19651 md_number_to_chars (buf, newval, THUMB_SIZE);
19652 }
c19d1205 19653 break;
a737bd4d 19654
c19d1205 19655 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
2fc8bdac
ZW
19656 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19657 as_bad_where (fixP->fx_file, fixP->fx_line,
19658 _("branch out of range"));
a737bd4d 19659
2fc8bdac
ZW
19660 if (fixP->fx_done || !seg->use_rela_p)
19661 {
19662 newval = md_chars_to_number (buf, THUMB_SIZE);
19663 newval |= (value & 0xfff) >> 1;
19664 md_number_to_chars (buf, newval, THUMB_SIZE);
19665 }
c19d1205 19666 break;
a737bd4d 19667
c19d1205 19668 case BFD_RELOC_THUMB_PCREL_BRANCH20:
267bf995
RR
19669 if (fixP->fx_addsy
19670 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19671 && !S_IS_EXTERNAL (fixP->fx_addsy)
19672 && S_IS_DEFINED (fixP->fx_addsy)
19673 && ARM_IS_FUNC (fixP->fx_addsy)
19674 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19675 {
19676 /* Force a relocation for a branch 20 bits wide. */
19677 fixP->fx_done = 0;
19678 }
2fc8bdac
ZW
19679 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19680 as_bad_where (fixP->fx_file, fixP->fx_line,
19681 _("conditional branch out of range"));
404ff6b5 19682
2fc8bdac
ZW
19683 if (fixP->fx_done || !seg->use_rela_p)
19684 {
19685 offsetT newval2;
19686 addressT S, J1, J2, lo, hi;
404ff6b5 19687
2fc8bdac
ZW
19688 S = (value & 0x00100000) >> 20;
19689 J2 = (value & 0x00080000) >> 19;
19690 J1 = (value & 0x00040000) >> 18;
19691 hi = (value & 0x0003f000) >> 12;
19692 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19693
2fc8bdac
ZW
19694 newval = md_chars_to_number (buf, THUMB_SIZE);
19695 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19696 newval |= (S << 10) | hi;
19697 newval2 |= (J1 << 13) | (J2 << 11) | lo;
19698 md_number_to_chars (buf, newval, THUMB_SIZE);
19699 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19700 }
c19d1205 19701 break;
6c43fab6 19702
c19d1205 19703 case BFD_RELOC_THUMB_PCREL_BLX:
267bf995
RR
19704
19705 /* If there is a blx from a thumb state function to
19706 another thumb function flip this to a bl and warn
19707 about it. */
19708
19709 if (fixP->fx_addsy
19710 && S_IS_DEFINED (fixP->fx_addsy)
19711 && !S_IS_EXTERNAL (fixP->fx_addsy)
19712 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19713 && THUMB_IS_FUNC (fixP->fx_addsy))
19714 {
19715 const char *name = S_GET_NAME (fixP->fx_addsy);
19716 as_warn_where (fixP->fx_file, fixP->fx_line,
19717 _("blx to Thumb func '%s' from Thumb ISA state changed to bl"),
19718 name);
19719 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19720 newval = newval | 0x1000;
19721 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19722 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19723 fixP->fx_done = 1;
19724 }
19725
19726
19727 goto thumb_bl_common;
19728
c19d1205 19729 case BFD_RELOC_THUMB_PCREL_BRANCH23:
267bf995
RR
19730
19731 /* A bl from Thumb state ISA to an internal ARM state function
19732 is converted to a blx. */
19733 if (fixP->fx_addsy
19734 && (S_GET_SEGMENT (fixP->fx_addsy) == seg)
19735 && !S_IS_EXTERNAL (fixP->fx_addsy)
19736 && S_IS_DEFINED (fixP->fx_addsy)
19737 && ARM_IS_FUNC (fixP->fx_addsy)
19738 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t))
19739 {
19740 newval = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19741 newval = newval & ~0x1000;
19742 md_number_to_chars (buf+THUMB_SIZE, newval, THUMB_SIZE);
19743 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BLX;
19744 fixP->fx_done = 1;
19745 }
19746
19747 thumb_bl_common:
19748
19749#ifdef OBJ_ELF
19750 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4 &&
19751 fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19752 fixP->fx_r_type = BFD_RELOC_THUMB_PCREL_BRANCH23;
19753#endif
19754
2fc8bdac
ZW
19755 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19756 as_bad_where (fixP->fx_file, fixP->fx_line,
19757 _("branch out of range"));
404ff6b5 19758
2fc8bdac
ZW
19759 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BLX)
19760 /* For a BLX instruction, make sure that the relocation is rounded up
19761 to a word boundary. This follows the semantics of the instruction
19762 which specifies that bit 1 of the target address will come from bit
19763 1 of the base address. */
19764 value = (value + 1) & ~ 1;
404ff6b5 19765
2fc8bdac 19766 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19767 {
2fc8bdac
ZW
19768 offsetT newval2;
19769
19770 newval = md_chars_to_number (buf, THUMB_SIZE);
19771 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19772 newval |= (value & 0x7fffff) >> 12;
19773 newval2 |= (value & 0xfff) >> 1;
19774 md_number_to_chars (buf, newval, THUMB_SIZE);
19775 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
c19d1205 19776 }
c19d1205 19777 break;
404ff6b5 19778
c19d1205 19779 case BFD_RELOC_THUMB_PCREL_BRANCH25:
2fc8bdac
ZW
19780 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19781 as_bad_where (fixP->fx_file, fixP->fx_line,
19782 _("branch out of range"));
6c43fab6 19783
2fc8bdac
ZW
19784 if (fixP->fx_done || !seg->use_rela_p)
19785 {
19786 offsetT newval2;
19787 addressT S, I1, I2, lo, hi;
6c43fab6 19788
2fc8bdac
ZW
19789 S = (value & 0x01000000) >> 24;
19790 I1 = (value & 0x00800000) >> 23;
19791 I2 = (value & 0x00400000) >> 22;
19792 hi = (value & 0x003ff000) >> 12;
19793 lo = (value & 0x00000ffe) >> 1;
6c43fab6 19794
2fc8bdac
ZW
19795 I1 = !(I1 ^ S);
19796 I2 = !(I2 ^ S);
a737bd4d 19797
2fc8bdac
ZW
19798 newval = md_chars_to_number (buf, THUMB_SIZE);
19799 newval2 = md_chars_to_number (buf + THUMB_SIZE, THUMB_SIZE);
19800 newval |= (S << 10) | hi;
19801 newval2 |= (I1 << 13) | (I2 << 11) | lo;
19802 md_number_to_chars (buf, newval, THUMB_SIZE);
19803 md_number_to_chars (buf + THUMB_SIZE, newval2, THUMB_SIZE);
19804 }
19805 break;
a737bd4d 19806
2fc8bdac
ZW
19807 case BFD_RELOC_8:
19808 if (fixP->fx_done || !seg->use_rela_p)
19809 md_number_to_chars (buf, value, 1);
c19d1205 19810 break;
a737bd4d 19811
c19d1205 19812 case BFD_RELOC_16:
2fc8bdac 19813 if (fixP->fx_done || !seg->use_rela_p)
c19d1205 19814 md_number_to_chars (buf, value, 2);
c19d1205 19815 break;
a737bd4d 19816
c19d1205
ZW
19817#ifdef OBJ_ELF
19818 case BFD_RELOC_ARM_TLS_GD32:
19819 case BFD_RELOC_ARM_TLS_LE32:
19820 case BFD_RELOC_ARM_TLS_IE32:
19821 case BFD_RELOC_ARM_TLS_LDM32:
19822 case BFD_RELOC_ARM_TLS_LDO32:
19823 S_SET_THREAD_LOCAL (fixP->fx_addsy);
19824 /* fall through */
6c43fab6 19825
c19d1205
ZW
19826 case BFD_RELOC_ARM_GOT32:
19827 case BFD_RELOC_ARM_GOTOFF:
19828 case BFD_RELOC_ARM_TARGET2:
2fc8bdac
ZW
19829 if (fixP->fx_done || !seg->use_rela_p)
19830 md_number_to_chars (buf, 0, 4);
c19d1205
ZW
19831 break;
19832#endif
6c43fab6 19833
c19d1205
ZW
19834 case BFD_RELOC_RVA:
19835 case BFD_RELOC_32:
19836 case BFD_RELOC_ARM_TARGET1:
19837 case BFD_RELOC_ARM_ROSEGREL32:
19838 case BFD_RELOC_ARM_SBREL32:
19839 case BFD_RELOC_32_PCREL:
f0927246
NC
19840#ifdef TE_PE
19841 case BFD_RELOC_32_SECREL:
19842#endif
2fc8bdac 19843 if (fixP->fx_done || !seg->use_rela_p)
53baae48
NC
19844#ifdef TE_WINCE
19845 /* For WinCE we only do this for pcrel fixups. */
19846 if (fixP->fx_done || fixP->fx_pcrel)
19847#endif
19848 md_number_to_chars (buf, value, 4);
c19d1205 19849 break;
6c43fab6 19850
c19d1205
ZW
19851#ifdef OBJ_ELF
19852 case BFD_RELOC_ARM_PREL31:
2fc8bdac 19853 if (fixP->fx_done || !seg->use_rela_p)
c19d1205
ZW
19854 {
19855 newval = md_chars_to_number (buf, 4) & 0x80000000;
19856 if ((value ^ (value >> 1)) & 0x40000000)
19857 {
19858 as_bad_where (fixP->fx_file, fixP->fx_line,
19859 _("rel31 relocation overflow"));
19860 }
19861 newval |= value & 0x7fffffff;
19862 md_number_to_chars (buf, newval, 4);
19863 }
19864 break;
c19d1205 19865#endif
a737bd4d 19866
c19d1205 19867 case BFD_RELOC_ARM_CP_OFF_IMM:
8f06b2d8 19868 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
c19d1205
ZW
19869 if (value < -1023 || value > 1023 || (value & 3))
19870 as_bad_where (fixP->fx_file, fixP->fx_line,
19871 _("co-processor offset out of range"));
19872 cp_off_common:
19873 sign = value >= 0;
19874 if (value < 0)
19875 value = -value;
8f06b2d8
PB
19876 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19877 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19878 newval = md_chars_to_number (buf, INSN_SIZE);
19879 else
19880 newval = get_thumb32_insn (buf);
19881 newval &= 0xff7fff00;
c19d1205 19882 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
8f06b2d8
PB
19883 if (fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM
19884 || fixP->fx_r_type == BFD_RELOC_ARM_CP_OFF_IMM_S2)
19885 md_number_to_chars (buf, newval, INSN_SIZE);
19886 else
19887 put_thumb32_insn (buf, newval);
c19d1205 19888 break;
a737bd4d 19889
c19d1205 19890 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
8f06b2d8 19891 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
c19d1205
ZW
19892 if (value < -255 || value > 255)
19893 as_bad_where (fixP->fx_file, fixP->fx_line,
19894 _("co-processor offset out of range"));
df7849c5 19895 value *= 4;
c19d1205 19896 goto cp_off_common;
6c43fab6 19897
c19d1205
ZW
19898 case BFD_RELOC_ARM_THUMB_OFFSET:
19899 newval = md_chars_to_number (buf, THUMB_SIZE);
19900 /* Exactly what ranges, and where the offset is inserted depends
19901 on the type of instruction, we can establish this from the
19902 top 4 bits. */
19903 switch (newval >> 12)
19904 {
19905 case 4: /* PC load. */
19906 /* Thumb PC loads are somewhat odd, bit 1 of the PC is
19907 forced to zero for these loads; md_pcrel_from has already
19908 compensated for this. */
19909 if (value & 3)
19910 as_bad_where (fixP->fx_file, fixP->fx_line,
19911 _("invalid offset, target not word aligned (0x%08lX)"),
0359e808
NC
19912 (((unsigned long) fixP->fx_frag->fr_address
19913 + (unsigned long) fixP->fx_where) & ~3)
19914 + (unsigned long) value);
a737bd4d 19915
c19d1205
ZW
19916 if (value & ~0x3fc)
19917 as_bad_where (fixP->fx_file, fixP->fx_line,
19918 _("invalid offset, value too big (0x%08lX)"),
19919 (long) value);
a737bd4d 19920
c19d1205
ZW
19921 newval |= value >> 2;
19922 break;
a737bd4d 19923
c19d1205
ZW
19924 case 9: /* SP load/store. */
19925 if (value & ~0x3fc)
19926 as_bad_where (fixP->fx_file, fixP->fx_line,
19927 _("invalid offset, value too big (0x%08lX)"),
19928 (long) value);
19929 newval |= value >> 2;
19930 break;
6c43fab6 19931
c19d1205
ZW
19932 case 6: /* Word load/store. */
19933 if (value & ~0x7c)
19934 as_bad_where (fixP->fx_file, fixP->fx_line,
19935 _("invalid offset, value too big (0x%08lX)"),
19936 (long) value);
19937 newval |= value << 4; /* 6 - 2. */
19938 break;
a737bd4d 19939
c19d1205
ZW
19940 case 7: /* Byte load/store. */
19941 if (value & ~0x1f)
19942 as_bad_where (fixP->fx_file, fixP->fx_line,
19943 _("invalid offset, value too big (0x%08lX)"),
19944 (long) value);
19945 newval |= value << 6;
19946 break;
a737bd4d 19947
c19d1205
ZW
19948 case 8: /* Halfword load/store. */
19949 if (value & ~0x3e)
19950 as_bad_where (fixP->fx_file, fixP->fx_line,
19951 _("invalid offset, value too big (0x%08lX)"),
19952 (long) value);
19953 newval |= value << 5; /* 6 - 1. */
19954 break;
a737bd4d 19955
c19d1205
ZW
19956 default:
19957 as_bad_where (fixP->fx_file, fixP->fx_line,
19958 "Unable to process relocation for thumb opcode: %lx",
19959 (unsigned long) newval);
19960 break;
19961 }
19962 md_number_to_chars (buf, newval, THUMB_SIZE);
19963 break;
a737bd4d 19964
c19d1205
ZW
19965 case BFD_RELOC_ARM_THUMB_ADD:
19966 /* This is a complicated relocation, since we use it for all of
19967 the following immediate relocations:
a737bd4d 19968
c19d1205
ZW
19969 3bit ADD/SUB
19970 8bit ADD/SUB
19971 9bit ADD/SUB SP word-aligned
19972 10bit ADD PC/SP word-aligned
a737bd4d 19973
c19d1205
ZW
19974 The type of instruction being processed is encoded in the
19975 instruction field:
a737bd4d 19976
c19d1205
ZW
19977 0x8000 SUB
19978 0x00F0 Rd
19979 0x000F Rs
19980 */
19981 newval = md_chars_to_number (buf, THUMB_SIZE);
19982 {
19983 int rd = (newval >> 4) & 0xf;
19984 int rs = newval & 0xf;
19985 int subtract = !!(newval & 0x8000);
a737bd4d 19986
c19d1205
ZW
19987 /* Check for HI regs, only very restricted cases allowed:
19988 Adjusting SP, and using PC or SP to get an address. */
19989 if ((rd > 7 && (rd != REG_SP || rs != REG_SP))
19990 || (rs > 7 && rs != REG_SP && rs != REG_PC))
19991 as_bad_where (fixP->fx_file, fixP->fx_line,
19992 _("invalid Hi register with immediate"));
a737bd4d 19993
c19d1205
ZW
19994 /* If value is negative, choose the opposite instruction. */
19995 if (value < 0)
19996 {
19997 value = -value;
19998 subtract = !subtract;
19999 if (value < 0)
20000 as_bad_where (fixP->fx_file, fixP->fx_line,
20001 _("immediate value out of range"));
20002 }
a737bd4d 20003
c19d1205
ZW
20004 if (rd == REG_SP)
20005 {
20006 if (value & ~0x1fc)
20007 as_bad_where (fixP->fx_file, fixP->fx_line,
20008 _("invalid immediate for stack address calculation"));
20009 newval = subtract ? T_OPCODE_SUB_ST : T_OPCODE_ADD_ST;
20010 newval |= value >> 2;
20011 }
20012 else if (rs == REG_PC || rs == REG_SP)
20013 {
20014 if (subtract || value & ~0x3fc)
20015 as_bad_where (fixP->fx_file, fixP->fx_line,
20016 _("invalid immediate for address calculation (value = 0x%08lX)"),
20017 (unsigned long) value);
20018 newval = (rs == REG_PC ? T_OPCODE_ADD_PC : T_OPCODE_ADD_SP);
20019 newval |= rd << 8;
20020 newval |= value >> 2;
20021 }
20022 else if (rs == rd)
20023 {
20024 if (value & ~0xff)
20025 as_bad_where (fixP->fx_file, fixP->fx_line,
20026 _("immediate value out of range"));
20027 newval = subtract ? T_OPCODE_SUB_I8 : T_OPCODE_ADD_I8;
20028 newval |= (rd << 8) | value;
20029 }
20030 else
20031 {
20032 if (value & ~0x7)
20033 as_bad_where (fixP->fx_file, fixP->fx_line,
20034 _("immediate value out of range"));
20035 newval = subtract ? T_OPCODE_SUB_I3 : T_OPCODE_ADD_I3;
20036 newval |= rd | (rs << 3) | (value << 6);
20037 }
20038 }
20039 md_number_to_chars (buf, newval, THUMB_SIZE);
20040 break;
a737bd4d 20041
c19d1205
ZW
20042 case BFD_RELOC_ARM_THUMB_IMM:
20043 newval = md_chars_to_number (buf, THUMB_SIZE);
20044 if (value < 0 || value > 255)
20045 as_bad_where (fixP->fx_file, fixP->fx_line,
4e6e072b 20046 _("invalid immediate: %ld is out of range"),
c19d1205
ZW
20047 (long) value);
20048 newval |= value;
20049 md_number_to_chars (buf, newval, THUMB_SIZE);
20050 break;
a737bd4d 20051
c19d1205
ZW
20052 case BFD_RELOC_ARM_THUMB_SHIFT:
20053 /* 5bit shift value (0..32). LSL cannot take 32. */
20054 newval = md_chars_to_number (buf, THUMB_SIZE) & 0xf83f;
20055 temp = newval & 0xf800;
20056 if (value < 0 || value > 32 || (value == 32 && temp == T_OPCODE_LSL_I))
20057 as_bad_where (fixP->fx_file, fixP->fx_line,
20058 _("invalid shift value: %ld"), (long) value);
20059 /* Shifts of zero must be encoded as LSL. */
20060 if (value == 0)
20061 newval = (newval & 0x003f) | T_OPCODE_LSL_I;
20062 /* Shifts of 32 are encoded as zero. */
20063 else if (value == 32)
20064 value = 0;
20065 newval |= value << 6;
20066 md_number_to_chars (buf, newval, THUMB_SIZE);
20067 break;
a737bd4d 20068
c19d1205
ZW
20069 case BFD_RELOC_VTABLE_INHERIT:
20070 case BFD_RELOC_VTABLE_ENTRY:
20071 fixP->fx_done = 0;
20072 return;
6c43fab6 20073
b6895b4f
PB
20074 case BFD_RELOC_ARM_MOVW:
20075 case BFD_RELOC_ARM_MOVT:
20076 case BFD_RELOC_ARM_THUMB_MOVW:
20077 case BFD_RELOC_ARM_THUMB_MOVT:
20078 if (fixP->fx_done || !seg->use_rela_p)
20079 {
20080 /* REL format relocations are limited to a 16-bit addend. */
20081 if (!fixP->fx_done)
20082 {
39623e12 20083 if (value < -0x8000 || value > 0x7fff)
b6895b4f 20084 as_bad_where (fixP->fx_file, fixP->fx_line,
ff5075ca 20085 _("offset out of range"));
b6895b4f
PB
20086 }
20087 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20088 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20089 {
20090 value >>= 16;
20091 }
20092
20093 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20094 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20095 {
20096 newval = get_thumb32_insn (buf);
20097 newval &= 0xfbf08f00;
20098 newval |= (value & 0xf000) << 4;
20099 newval |= (value & 0x0800) << 15;
20100 newval |= (value & 0x0700) << 4;
20101 newval |= (value & 0x00ff);
20102 put_thumb32_insn (buf, newval);
20103 }
20104 else
20105 {
20106 newval = md_chars_to_number (buf, 4);
20107 newval &= 0xfff0f000;
20108 newval |= value & 0x0fff;
20109 newval |= (value & 0xf000) << 4;
20110 md_number_to_chars (buf, newval, 4);
20111 }
20112 }
20113 return;
20114
4962c51a
MS
20115 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20116 case BFD_RELOC_ARM_ALU_PC_G0:
20117 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20118 case BFD_RELOC_ARM_ALU_PC_G1:
20119 case BFD_RELOC_ARM_ALU_PC_G2:
20120 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20121 case BFD_RELOC_ARM_ALU_SB_G0:
20122 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20123 case BFD_RELOC_ARM_ALU_SB_G1:
20124 case BFD_RELOC_ARM_ALU_SB_G2:
9c2799c2 20125 gas_assert (!fixP->fx_done);
4962c51a
MS
20126 if (!seg->use_rela_p)
20127 {
20128 bfd_vma insn;
20129 bfd_vma encoded_addend;
20130 bfd_vma addend_abs = abs (value);
20131
20132 /* Check that the absolute value of the addend can be
20133 expressed as an 8-bit constant plus a rotation. */
20134 encoded_addend = encode_arm_immediate (addend_abs);
20135 if (encoded_addend == (unsigned int) FAIL)
20136 as_bad_where (fixP->fx_file, fixP->fx_line,
20137 _("the offset 0x%08lX is not representable"),
495bde8e 20138 (unsigned long) addend_abs);
4962c51a
MS
20139
20140 /* Extract the instruction. */
20141 insn = md_chars_to_number (buf, INSN_SIZE);
20142
20143 /* If the addend is positive, use an ADD instruction.
20144 Otherwise use a SUB. Take care not to destroy the S bit. */
20145 insn &= 0xff1fffff;
20146 if (value < 0)
20147 insn |= 1 << 22;
20148 else
20149 insn |= 1 << 23;
20150
20151 /* Place the encoded addend into the first 12 bits of the
20152 instruction. */
20153 insn &= 0xfffff000;
20154 insn |= encoded_addend;
5f4273c7
NC
20155
20156 /* Update the instruction. */
4962c51a
MS
20157 md_number_to_chars (buf, insn, INSN_SIZE);
20158 }
20159 break;
20160
20161 case BFD_RELOC_ARM_LDR_PC_G0:
20162 case BFD_RELOC_ARM_LDR_PC_G1:
20163 case BFD_RELOC_ARM_LDR_PC_G2:
20164 case BFD_RELOC_ARM_LDR_SB_G0:
20165 case BFD_RELOC_ARM_LDR_SB_G1:
20166 case BFD_RELOC_ARM_LDR_SB_G2:
9c2799c2 20167 gas_assert (!fixP->fx_done);
4962c51a
MS
20168 if (!seg->use_rela_p)
20169 {
20170 bfd_vma insn;
20171 bfd_vma addend_abs = abs (value);
20172
20173 /* Check that the absolute value of the addend can be
20174 encoded in 12 bits. */
20175 if (addend_abs >= 0x1000)
20176 as_bad_where (fixP->fx_file, fixP->fx_line,
20177 _("bad offset 0x%08lX (only 12 bits available for the magnitude)"),
495bde8e 20178 (unsigned long) addend_abs);
4962c51a
MS
20179
20180 /* Extract the instruction. */
20181 insn = md_chars_to_number (buf, INSN_SIZE);
20182
20183 /* If the addend is negative, clear bit 23 of the instruction.
20184 Otherwise set it. */
20185 if (value < 0)
20186 insn &= ~(1 << 23);
20187 else
20188 insn |= 1 << 23;
20189
20190 /* Place the absolute value of the addend into the first 12 bits
20191 of the instruction. */
20192 insn &= 0xfffff000;
20193 insn |= addend_abs;
5f4273c7
NC
20194
20195 /* Update the instruction. */
4962c51a
MS
20196 md_number_to_chars (buf, insn, INSN_SIZE);
20197 }
20198 break;
20199
20200 case BFD_RELOC_ARM_LDRS_PC_G0:
20201 case BFD_RELOC_ARM_LDRS_PC_G1:
20202 case BFD_RELOC_ARM_LDRS_PC_G2:
20203 case BFD_RELOC_ARM_LDRS_SB_G0:
20204 case BFD_RELOC_ARM_LDRS_SB_G1:
20205 case BFD_RELOC_ARM_LDRS_SB_G2:
9c2799c2 20206 gas_assert (!fixP->fx_done);
4962c51a
MS
20207 if (!seg->use_rela_p)
20208 {
20209 bfd_vma insn;
20210 bfd_vma addend_abs = abs (value);
20211
20212 /* Check that the absolute value of the addend can be
20213 encoded in 8 bits. */
20214 if (addend_abs >= 0x100)
20215 as_bad_where (fixP->fx_file, fixP->fx_line,
20216 _("bad offset 0x%08lX (only 8 bits available for the magnitude)"),
495bde8e 20217 (unsigned long) addend_abs);
4962c51a
MS
20218
20219 /* Extract the instruction. */
20220 insn = md_chars_to_number (buf, INSN_SIZE);
20221
20222 /* If the addend is negative, clear bit 23 of the instruction.
20223 Otherwise set it. */
20224 if (value < 0)
20225 insn &= ~(1 << 23);
20226 else
20227 insn |= 1 << 23;
20228
20229 /* Place the first four bits of the absolute value of the addend
20230 into the first 4 bits of the instruction, and the remaining
20231 four into bits 8 .. 11. */
20232 insn &= 0xfffff0f0;
20233 insn |= (addend_abs & 0xf) | ((addend_abs & 0xf0) << 4);
5f4273c7
NC
20234
20235 /* Update the instruction. */
4962c51a
MS
20236 md_number_to_chars (buf, insn, INSN_SIZE);
20237 }
20238 break;
20239
20240 case BFD_RELOC_ARM_LDC_PC_G0:
20241 case BFD_RELOC_ARM_LDC_PC_G1:
20242 case BFD_RELOC_ARM_LDC_PC_G2:
20243 case BFD_RELOC_ARM_LDC_SB_G0:
20244 case BFD_RELOC_ARM_LDC_SB_G1:
20245 case BFD_RELOC_ARM_LDC_SB_G2:
9c2799c2 20246 gas_assert (!fixP->fx_done);
4962c51a
MS
20247 if (!seg->use_rela_p)
20248 {
20249 bfd_vma insn;
20250 bfd_vma addend_abs = abs (value);
20251
20252 /* Check that the absolute value of the addend is a multiple of
20253 four and, when divided by four, fits in 8 bits. */
20254 if (addend_abs & 0x3)
20255 as_bad_where (fixP->fx_file, fixP->fx_line,
20256 _("bad offset 0x%08lX (must be word-aligned)"),
495bde8e 20257 (unsigned long) addend_abs);
4962c51a
MS
20258
20259 if ((addend_abs >> 2) > 0xff)
20260 as_bad_where (fixP->fx_file, fixP->fx_line,
20261 _("bad offset 0x%08lX (must be an 8-bit number of words)"),
495bde8e 20262 (unsigned long) addend_abs);
4962c51a
MS
20263
20264 /* Extract the instruction. */
20265 insn = md_chars_to_number (buf, INSN_SIZE);
20266
20267 /* If the addend is negative, clear bit 23 of the instruction.
20268 Otherwise set it. */
20269 if (value < 0)
20270 insn &= ~(1 << 23);
20271 else
20272 insn |= 1 << 23;
20273
20274 /* Place the addend (divided by four) into the first eight
20275 bits of the instruction. */
20276 insn &= 0xfffffff0;
20277 insn |= addend_abs >> 2;
5f4273c7
NC
20278
20279 /* Update the instruction. */
4962c51a
MS
20280 md_number_to_chars (buf, insn, INSN_SIZE);
20281 }
20282 break;
20283
845b51d6
PB
20284 case BFD_RELOC_ARM_V4BX:
20285 /* This will need to go in the object file. */
20286 fixP->fx_done = 0;
20287 break;
20288
c19d1205
ZW
20289 case BFD_RELOC_UNUSED:
20290 default:
20291 as_bad_where (fixP->fx_file, fixP->fx_line,
20292 _("bad relocation fixup type (%d)"), fixP->fx_r_type);
20293 }
6c43fab6
RE
20294}
20295
c19d1205
ZW
20296/* Translate internal representation of relocation info to BFD target
20297 format. */
a737bd4d 20298
c19d1205 20299arelent *
00a97672 20300tc_gen_reloc (asection *section, fixS *fixp)
a737bd4d 20301{
c19d1205
ZW
20302 arelent * reloc;
20303 bfd_reloc_code_real_type code;
a737bd4d 20304
c19d1205 20305 reloc = xmalloc (sizeof (arelent));
a737bd4d 20306
c19d1205
ZW
20307 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
20308 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
20309 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
a737bd4d 20310
2fc8bdac 20311 if (fixp->fx_pcrel)
00a97672
RS
20312 {
20313 if (section->use_rela_p)
20314 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20315 else
20316 fixp->fx_offset = reloc->address;
20317 }
c19d1205 20318 reloc->addend = fixp->fx_offset;
a737bd4d 20319
c19d1205 20320 switch (fixp->fx_r_type)
a737bd4d 20321 {
c19d1205
ZW
20322 case BFD_RELOC_8:
20323 if (fixp->fx_pcrel)
20324 {
20325 code = BFD_RELOC_8_PCREL;
20326 break;
20327 }
a737bd4d 20328
c19d1205
ZW
20329 case BFD_RELOC_16:
20330 if (fixp->fx_pcrel)
20331 {
20332 code = BFD_RELOC_16_PCREL;
20333 break;
20334 }
6c43fab6 20335
c19d1205
ZW
20336 case BFD_RELOC_32:
20337 if (fixp->fx_pcrel)
20338 {
20339 code = BFD_RELOC_32_PCREL;
20340 break;
20341 }
a737bd4d 20342
b6895b4f
PB
20343 case BFD_RELOC_ARM_MOVW:
20344 if (fixp->fx_pcrel)
20345 {
20346 code = BFD_RELOC_ARM_MOVW_PCREL;
20347 break;
20348 }
20349
20350 case BFD_RELOC_ARM_MOVT:
20351 if (fixp->fx_pcrel)
20352 {
20353 code = BFD_RELOC_ARM_MOVT_PCREL;
20354 break;
20355 }
20356
20357 case BFD_RELOC_ARM_THUMB_MOVW:
20358 if (fixp->fx_pcrel)
20359 {
20360 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20361 break;
20362 }
20363
20364 case BFD_RELOC_ARM_THUMB_MOVT:
20365 if (fixp->fx_pcrel)
20366 {
20367 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20368 break;
20369 }
20370
c19d1205
ZW
20371 case BFD_RELOC_NONE:
20372 case BFD_RELOC_ARM_PCREL_BRANCH:
20373 case BFD_RELOC_ARM_PCREL_BLX:
20374 case BFD_RELOC_RVA:
20375 case BFD_RELOC_THUMB_PCREL_BRANCH7:
20376 case BFD_RELOC_THUMB_PCREL_BRANCH9:
20377 case BFD_RELOC_THUMB_PCREL_BRANCH12:
20378 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20379 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20380 case BFD_RELOC_THUMB_PCREL_BRANCH25:
c19d1205
ZW
20381 case BFD_RELOC_VTABLE_ENTRY:
20382 case BFD_RELOC_VTABLE_INHERIT:
f0927246
NC
20383#ifdef TE_PE
20384 case BFD_RELOC_32_SECREL:
20385#endif
c19d1205
ZW
20386 code = fixp->fx_r_type;
20387 break;
a737bd4d 20388
00adf2d4
JB
20389 case BFD_RELOC_THUMB_PCREL_BLX:
20390#ifdef OBJ_ELF
20391 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
20392 code = BFD_RELOC_THUMB_PCREL_BRANCH23;
20393 else
20394#endif
20395 code = BFD_RELOC_THUMB_PCREL_BLX;
20396 break;
20397
c19d1205
ZW
20398 case BFD_RELOC_ARM_LITERAL:
20399 case BFD_RELOC_ARM_HWLITERAL:
20400 /* If this is called then the a literal has
20401 been referenced across a section boundary. */
20402 as_bad_where (fixp->fx_file, fixp->fx_line,
20403 _("literal referenced across section boundary"));
20404 return NULL;
a737bd4d 20405
c19d1205
ZW
20406#ifdef OBJ_ELF
20407 case BFD_RELOC_ARM_GOT32:
20408 case BFD_RELOC_ARM_GOTOFF:
20409 case BFD_RELOC_ARM_PLT32:
20410 case BFD_RELOC_ARM_TARGET1:
20411 case BFD_RELOC_ARM_ROSEGREL32:
20412 case BFD_RELOC_ARM_SBREL32:
20413 case BFD_RELOC_ARM_PREL31:
20414 case BFD_RELOC_ARM_TARGET2:
20415 case BFD_RELOC_ARM_TLS_LE32:
20416 case BFD_RELOC_ARM_TLS_LDO32:
39b41c9c
PB
20417 case BFD_RELOC_ARM_PCREL_CALL:
20418 case BFD_RELOC_ARM_PCREL_JUMP:
4962c51a
MS
20419 case BFD_RELOC_ARM_ALU_PC_G0_NC:
20420 case BFD_RELOC_ARM_ALU_PC_G0:
20421 case BFD_RELOC_ARM_ALU_PC_G1_NC:
20422 case BFD_RELOC_ARM_ALU_PC_G1:
20423 case BFD_RELOC_ARM_ALU_PC_G2:
20424 case BFD_RELOC_ARM_LDR_PC_G0:
20425 case BFD_RELOC_ARM_LDR_PC_G1:
20426 case BFD_RELOC_ARM_LDR_PC_G2:
20427 case BFD_RELOC_ARM_LDRS_PC_G0:
20428 case BFD_RELOC_ARM_LDRS_PC_G1:
20429 case BFD_RELOC_ARM_LDRS_PC_G2:
20430 case BFD_RELOC_ARM_LDC_PC_G0:
20431 case BFD_RELOC_ARM_LDC_PC_G1:
20432 case BFD_RELOC_ARM_LDC_PC_G2:
20433 case BFD_RELOC_ARM_ALU_SB_G0_NC:
20434 case BFD_RELOC_ARM_ALU_SB_G0:
20435 case BFD_RELOC_ARM_ALU_SB_G1_NC:
20436 case BFD_RELOC_ARM_ALU_SB_G1:
20437 case BFD_RELOC_ARM_ALU_SB_G2:
20438 case BFD_RELOC_ARM_LDR_SB_G0:
20439 case BFD_RELOC_ARM_LDR_SB_G1:
20440 case BFD_RELOC_ARM_LDR_SB_G2:
20441 case BFD_RELOC_ARM_LDRS_SB_G0:
20442 case BFD_RELOC_ARM_LDRS_SB_G1:
20443 case BFD_RELOC_ARM_LDRS_SB_G2:
20444 case BFD_RELOC_ARM_LDC_SB_G0:
20445 case BFD_RELOC_ARM_LDC_SB_G1:
20446 case BFD_RELOC_ARM_LDC_SB_G2:
845b51d6 20447 case BFD_RELOC_ARM_V4BX:
c19d1205
ZW
20448 code = fixp->fx_r_type;
20449 break;
a737bd4d 20450
c19d1205
ZW
20451 case BFD_RELOC_ARM_TLS_GD32:
20452 case BFD_RELOC_ARM_TLS_IE32:
20453 case BFD_RELOC_ARM_TLS_LDM32:
20454 /* BFD will include the symbol's address in the addend.
20455 But we don't want that, so subtract it out again here. */
20456 if (!S_IS_COMMON (fixp->fx_addsy))
20457 reloc->addend -= (*reloc->sym_ptr_ptr)->value;
20458 code = fixp->fx_r_type;
20459 break;
20460#endif
a737bd4d 20461
c19d1205
ZW
20462 case BFD_RELOC_ARM_IMMEDIATE:
20463 as_bad_where (fixp->fx_file, fixp->fx_line,
20464 _("internal relocation (type: IMMEDIATE) not fixed up"));
20465 return NULL;
a737bd4d 20466
c19d1205
ZW
20467 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
20468 as_bad_where (fixp->fx_file, fixp->fx_line,
20469 _("ADRL used for a symbol not defined in the same file"));
20470 return NULL;
a737bd4d 20471
c19d1205 20472 case BFD_RELOC_ARM_OFFSET_IMM:
00a97672
RS
20473 if (section->use_rela_p)
20474 {
20475 code = fixp->fx_r_type;
20476 break;
20477 }
20478
c19d1205
ZW
20479 if (fixp->fx_addsy != NULL
20480 && !S_IS_DEFINED (fixp->fx_addsy)
20481 && S_IS_LOCAL (fixp->fx_addsy))
a737bd4d 20482 {
c19d1205
ZW
20483 as_bad_where (fixp->fx_file, fixp->fx_line,
20484 _("undefined local label `%s'"),
20485 S_GET_NAME (fixp->fx_addsy));
20486 return NULL;
a737bd4d
NC
20487 }
20488
c19d1205
ZW
20489 as_bad_where (fixp->fx_file, fixp->fx_line,
20490 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
20491 return NULL;
a737bd4d 20492
c19d1205
ZW
20493 default:
20494 {
20495 char * type;
6c43fab6 20496
c19d1205
ZW
20497 switch (fixp->fx_r_type)
20498 {
20499 case BFD_RELOC_NONE: type = "NONE"; break;
20500 case BFD_RELOC_ARM_OFFSET_IMM8: type = "OFFSET_IMM8"; break;
20501 case BFD_RELOC_ARM_SHIFT_IMM: type = "SHIFT_IMM"; break;
3eb17e6b 20502 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
c19d1205
ZW
20503 case BFD_RELOC_ARM_SWI: type = "SWI"; break;
20504 case BFD_RELOC_ARM_MULTI: type = "MULTI"; break;
20505 case BFD_RELOC_ARM_CP_OFF_IMM: type = "CP_OFF_IMM"; break;
8f06b2d8 20506 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
c19d1205
ZW
20507 case BFD_RELOC_ARM_THUMB_ADD: type = "THUMB_ADD"; break;
20508 case BFD_RELOC_ARM_THUMB_SHIFT: type = "THUMB_SHIFT"; break;
20509 case BFD_RELOC_ARM_THUMB_IMM: type = "THUMB_IMM"; break;
20510 case BFD_RELOC_ARM_THUMB_OFFSET: type = "THUMB_OFFSET"; break;
20511 default: type = _("<unknown>"); break;
20512 }
20513 as_bad_where (fixp->fx_file, fixp->fx_line,
20514 _("cannot represent %s relocation in this object file format"),
20515 type);
20516 return NULL;
20517 }
a737bd4d 20518 }
6c43fab6 20519
c19d1205
ZW
20520#ifdef OBJ_ELF
20521 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
20522 && GOT_symbol
20523 && fixp->fx_addsy == GOT_symbol)
20524 {
20525 code = BFD_RELOC_ARM_GOTPC;
20526 reloc->addend = fixp->fx_offset = reloc->address;
20527 }
20528#endif
6c43fab6 20529
c19d1205 20530 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
6c43fab6 20531
c19d1205
ZW
20532 if (reloc->howto == NULL)
20533 {
20534 as_bad_where (fixp->fx_file, fixp->fx_line,
20535 _("cannot represent %s relocation in this object file format"),
20536 bfd_get_reloc_code_name (code));
20537 return NULL;
20538 }
6c43fab6 20539
c19d1205
ZW
20540 /* HACK: Since arm ELF uses Rel instead of Rela, encode the
20541 vtable entry to be used in the relocation's section offset. */
20542 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20543 reloc->address = fixp->fx_offset;
6c43fab6 20544
c19d1205 20545 return reloc;
6c43fab6
RE
20546}
20547
c19d1205 20548/* This fix_new is called by cons via TC_CONS_FIX_NEW. */
6c43fab6 20549
c19d1205
ZW
20550void
20551cons_fix_new_arm (fragS * frag,
20552 int where,
20553 int size,
20554 expressionS * exp)
6c43fab6 20555{
c19d1205
ZW
20556 bfd_reloc_code_real_type type;
20557 int pcrel = 0;
6c43fab6 20558
c19d1205
ZW
20559 /* Pick a reloc.
20560 FIXME: @@ Should look at CPU word size. */
20561 switch (size)
20562 {
20563 case 1:
20564 type = BFD_RELOC_8;
20565 break;
20566 case 2:
20567 type = BFD_RELOC_16;
20568 break;
20569 case 4:
20570 default:
20571 type = BFD_RELOC_32;
20572 break;
20573 case 8:
20574 type = BFD_RELOC_64;
20575 break;
20576 }
6c43fab6 20577
f0927246
NC
20578#ifdef TE_PE
20579 if (exp->X_op == O_secrel)
20580 {
20581 exp->X_op = O_symbol;
20582 type = BFD_RELOC_32_SECREL;
20583 }
20584#endif
20585
c19d1205
ZW
20586 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
20587}
6c43fab6 20588
4343666d 20589#if defined (OBJ_COFF)
c19d1205
ZW
20590void
20591arm_validate_fix (fixS * fixP)
6c43fab6 20592{
c19d1205
ZW
20593 /* If the destination of the branch is a defined symbol which does not have
20594 the THUMB_FUNC attribute, then we must be calling a function which has
20595 the (interfacearm) attribute. We look for the Thumb entry point to that
20596 function and change the branch to refer to that function instead. */
20597 if (fixP->fx_r_type == BFD_RELOC_THUMB_PCREL_BRANCH23
20598 && fixP->fx_addsy != NULL
20599 && S_IS_DEFINED (fixP->fx_addsy)
20600 && ! THUMB_IS_FUNC (fixP->fx_addsy))
6c43fab6 20601 {
c19d1205 20602 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
6c43fab6 20603 }
c19d1205
ZW
20604}
20605#endif
6c43fab6 20606
267bf995 20607
c19d1205
ZW
20608int
20609arm_force_relocation (struct fix * fixp)
20610{
20611#if defined (OBJ_COFF) && defined (TE_PE)
20612 if (fixp->fx_r_type == BFD_RELOC_RVA)
20613 return 1;
20614#endif
6c43fab6 20615
267bf995
RR
20616 /* In case we have a call or a branch to a function in ARM ISA mode from
20617 a thumb function or vice-versa force the relocation. These relocations
20618 are cleared off for some cores that might have blx and simple transformations
20619 are possible. */
20620
20621#ifdef OBJ_ELF
20622 switch (fixp->fx_r_type)
20623 {
20624 case BFD_RELOC_ARM_PCREL_JUMP:
20625 case BFD_RELOC_ARM_PCREL_CALL:
20626 case BFD_RELOC_THUMB_PCREL_BLX:
20627 if (THUMB_IS_FUNC (fixp->fx_addsy))
20628 return 1;
20629 break;
20630
20631 case BFD_RELOC_ARM_PCREL_BLX:
20632 case BFD_RELOC_THUMB_PCREL_BRANCH25:
20633 case BFD_RELOC_THUMB_PCREL_BRANCH20:
20634 case BFD_RELOC_THUMB_PCREL_BRANCH23:
20635 if (ARM_IS_FUNC (fixp->fx_addsy))
20636 return 1;
20637 break;
20638
20639 default:
20640 break;
20641 }
20642#endif
20643
c19d1205
ZW
20644 /* Resolve these relocations even if the symbol is extern or weak. */
20645 if (fixp->fx_r_type == BFD_RELOC_ARM_IMMEDIATE
20646 || fixp->fx_r_type == BFD_RELOC_ARM_OFFSET_IMM
0110f2b8 20647 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
16805f35 20648 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
0110f2b8
PB
20649 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMMEDIATE
20650 || fixp->fx_r_type == BFD_RELOC_ARM_T32_IMM12
20651 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_PC12)
c19d1205 20652 return 0;
a737bd4d 20653
4962c51a
MS
20654 /* Always leave these relocations for the linker. */
20655 if ((fixp->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20656 && fixp->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20657 || fixp->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20658 return 1;
20659
f0291e4c
PB
20660 /* Always generate relocations against function symbols. */
20661 if (fixp->fx_r_type == BFD_RELOC_32
20662 && fixp->fx_addsy
20663 && (symbol_get_bfdsym (fixp->fx_addsy)->flags & BSF_FUNCTION))
20664 return 1;
20665
c19d1205 20666 return generic_force_reloc (fixp);
404ff6b5
AH
20667}
20668
0ffdc86c 20669#if defined (OBJ_ELF) || defined (OBJ_COFF)
e28387c3
PB
20670/* Relocations against function names must be left unadjusted,
20671 so that the linker can use this information to generate interworking
20672 stubs. The MIPS version of this function
c19d1205
ZW
20673 also prevents relocations that are mips-16 specific, but I do not
20674 know why it does this.
404ff6b5 20675
c19d1205
ZW
20676 FIXME:
20677 There is one other problem that ought to be addressed here, but
20678 which currently is not: Taking the address of a label (rather
20679 than a function) and then later jumping to that address. Such
20680 addresses also ought to have their bottom bit set (assuming that
20681 they reside in Thumb code), but at the moment they will not. */
404ff6b5 20682
c19d1205
ZW
20683bfd_boolean
20684arm_fix_adjustable (fixS * fixP)
404ff6b5 20685{
c19d1205
ZW
20686 if (fixP->fx_addsy == NULL)
20687 return 1;
404ff6b5 20688
e28387c3
PB
20689 /* Preserve relocations against symbols with function type. */
20690 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20691 return 0;
20692
c19d1205
ZW
20693 if (THUMB_IS_FUNC (fixP->fx_addsy)
20694 && fixP->fx_subsy == NULL)
20695 return 0;
a737bd4d 20696
c19d1205
ZW
20697 /* We need the symbol name for the VTABLE entries. */
20698 if ( fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
20699 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
20700 return 0;
404ff6b5 20701
c19d1205
ZW
20702 /* Don't allow symbols to be discarded on GOT related relocs. */
20703 if (fixP->fx_r_type == BFD_RELOC_ARM_PLT32
20704 || fixP->fx_r_type == BFD_RELOC_ARM_GOT32
20705 || fixP->fx_r_type == BFD_RELOC_ARM_GOTOFF
20706 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_GD32
20707 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LE32
20708 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_IE32
20709 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDM32
20710 || fixP->fx_r_type == BFD_RELOC_ARM_TLS_LDO32
20711 || fixP->fx_r_type == BFD_RELOC_ARM_TARGET2)
20712 return 0;
a737bd4d 20713
4962c51a
MS
20714 /* Similarly for group relocations. */
20715 if ((fixP->fx_r_type >= BFD_RELOC_ARM_ALU_PC_G0_NC
20716 && fixP->fx_r_type <= BFD_RELOC_ARM_LDC_SB_G2)
20717 || fixP->fx_r_type == BFD_RELOC_ARM_LDR_PC_G0)
20718 return 0;
20719
79947c54
CD
20720 /* MOVW/MOVT REL relocations have limited offsets, so keep the symbols. */
20721 if (fixP->fx_r_type == BFD_RELOC_ARM_MOVW
20722 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20723 || fixP->fx_r_type == BFD_RELOC_ARM_MOVW_PCREL
20724 || fixP->fx_r_type == BFD_RELOC_ARM_MOVT_PCREL
20725 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20726 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT
20727 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW_PCREL
20728 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT_PCREL)
20729 return 0;
20730
c19d1205 20731 return 1;
a737bd4d 20732}
0ffdc86c
NC
20733#endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20734
20735#ifdef OBJ_ELF
404ff6b5 20736
c19d1205
ZW
20737const char *
20738elf32_arm_target_format (void)
404ff6b5 20739{
c19d1205
ZW
20740#ifdef TE_SYMBIAN
20741 return (target_big_endian
20742 ? "elf32-bigarm-symbian"
20743 : "elf32-littlearm-symbian");
20744#elif defined (TE_VXWORKS)
20745 return (target_big_endian
20746 ? "elf32-bigarm-vxworks"
20747 : "elf32-littlearm-vxworks");
20748#else
20749 if (target_big_endian)
20750 return "elf32-bigarm";
20751 else
20752 return "elf32-littlearm";
20753#endif
404ff6b5
AH
20754}
20755
c19d1205
ZW
20756void
20757armelf_frob_symbol (symbolS * symp,
20758 int * puntp)
404ff6b5 20759{
c19d1205
ZW
20760 elf_frob_symbol (symp, puntp);
20761}
20762#endif
404ff6b5 20763
c19d1205 20764/* MD interface: Finalization. */
a737bd4d 20765
c19d1205
ZW
20766void
20767arm_cleanup (void)
20768{
20769 literal_pool * pool;
a737bd4d 20770
e07e6e58
NC
20771 /* Ensure that all the IT blocks are properly closed. */
20772 check_it_blocks_finished ();
20773
c19d1205
ZW
20774 for (pool = list_of_pools; pool; pool = pool->next)
20775 {
5f4273c7 20776 /* Put it at the end of the relevant section. */
c19d1205
ZW
20777 subseg_set (pool->section, pool->sub_section);
20778#ifdef OBJ_ELF
20779 arm_elf_change_section ();
20780#endif
20781 s_ltorg (0);
20782 }
404ff6b5
AH
20783}
20784
c19d1205
ZW
20785/* Adjust the symbol table. This marks Thumb symbols as distinct from
20786 ARM ones. */
404ff6b5 20787
c19d1205
ZW
20788void
20789arm_adjust_symtab (void)
404ff6b5 20790{
c19d1205
ZW
20791#ifdef OBJ_COFF
20792 symbolS * sym;
404ff6b5 20793
c19d1205
ZW
20794 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20795 {
20796 if (ARM_IS_THUMB (sym))
20797 {
20798 if (THUMB_IS_FUNC (sym))
20799 {
20800 /* Mark the symbol as a Thumb function. */
20801 if ( S_GET_STORAGE_CLASS (sym) == C_STAT
20802 || S_GET_STORAGE_CLASS (sym) == C_LABEL) /* This can happen! */
20803 S_SET_STORAGE_CLASS (sym, C_THUMBSTATFUNC);
404ff6b5 20804
c19d1205
ZW
20805 else if (S_GET_STORAGE_CLASS (sym) == C_EXT)
20806 S_SET_STORAGE_CLASS (sym, C_THUMBEXTFUNC);
20807 else
20808 as_bad (_("%s: unexpected function type: %d"),
20809 S_GET_NAME (sym), S_GET_STORAGE_CLASS (sym));
20810 }
20811 else switch (S_GET_STORAGE_CLASS (sym))
20812 {
20813 case C_EXT:
20814 S_SET_STORAGE_CLASS (sym, C_THUMBEXT);
20815 break;
20816 case C_STAT:
20817 S_SET_STORAGE_CLASS (sym, C_THUMBSTAT);
20818 break;
20819 case C_LABEL:
20820 S_SET_STORAGE_CLASS (sym, C_THUMBLABEL);
20821 break;
20822 default:
20823 /* Do nothing. */
20824 break;
20825 }
20826 }
a737bd4d 20827
c19d1205
ZW
20828 if (ARM_IS_INTERWORK (sym))
20829 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
404ff6b5 20830 }
c19d1205
ZW
20831#endif
20832#ifdef OBJ_ELF
20833 symbolS * sym;
20834 char bind;
404ff6b5 20835
c19d1205 20836 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
404ff6b5 20837 {
c19d1205
ZW
20838 if (ARM_IS_THUMB (sym))
20839 {
20840 elf_symbol_type * elf_sym;
404ff6b5 20841
c19d1205
ZW
20842 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20843 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
404ff6b5 20844
b0796911
PB
20845 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20846 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
c19d1205
ZW
20847 {
20848 /* If it's a .thumb_func, declare it as so,
20849 otherwise tag label as .code 16. */
20850 if (THUMB_IS_FUNC (sym))
20851 elf_sym->internal_elf_sym.st_info =
20852 ELF_ST_INFO (bind, STT_ARM_TFUNC);
3ba67470 20853 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
c19d1205
ZW
20854 elf_sym->internal_elf_sym.st_info =
20855 ELF_ST_INFO (bind, STT_ARM_16BIT);
20856 }
20857 }
20858 }
20859#endif
404ff6b5
AH
20860}
20861
c19d1205 20862/* MD interface: Initialization. */
404ff6b5 20863
a737bd4d 20864static void
c19d1205 20865set_constant_flonums (void)
a737bd4d 20866{
c19d1205 20867 int i;
404ff6b5 20868
c19d1205
ZW
20869 for (i = 0; i < NUM_FLOAT_VALS; i++)
20870 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20871 abort ();
a737bd4d 20872}
404ff6b5 20873
3e9e4fcf
JB
20874/* Auto-select Thumb mode if it's the only available instruction set for the
20875 given architecture. */
20876
20877static void
20878autoselect_thumb_from_cpu_variant (void)
20879{
20880 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20881 opcode_select (16);
20882}
20883
c19d1205
ZW
20884void
20885md_begin (void)
a737bd4d 20886{
c19d1205
ZW
20887 unsigned mach;
20888 unsigned int i;
404ff6b5 20889
c19d1205
ZW
20890 if ( (arm_ops_hsh = hash_new ()) == NULL
20891 || (arm_cond_hsh = hash_new ()) == NULL
20892 || (arm_shift_hsh = hash_new ()) == NULL
20893 || (arm_psr_hsh = hash_new ()) == NULL
62b3e311 20894 || (arm_v7m_psr_hsh = hash_new ()) == NULL
c19d1205 20895 || (arm_reg_hsh = hash_new ()) == NULL
62b3e311
PB
20896 || (arm_reloc_hsh = hash_new ()) == NULL
20897 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
c19d1205
ZW
20898 as_fatal (_("virtual memory exhausted"));
20899
20900 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
5a49b8ac 20901 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
c19d1205 20902 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
5a49b8ac 20903 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
c19d1205 20904 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
5a49b8ac 20905 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
c19d1205 20906 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20907 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
62b3e311 20908 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
5a49b8ac 20909 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
c19d1205 20910 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
5a49b8ac 20911 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
62b3e311
PB
20912 for (i = 0;
20913 i < sizeof (barrier_opt_names) / sizeof (struct asm_barrier_opt);
20914 i++)
20915 hash_insert (arm_barrier_opt_hsh, barrier_opt_names[i].template,
5a49b8ac 20916 (void *) (barrier_opt_names + i));
c19d1205
ZW
20917#ifdef OBJ_ELF
20918 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
5a49b8ac 20919 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
c19d1205
ZW
20920#endif
20921
20922 set_constant_flonums ();
404ff6b5 20923
c19d1205
ZW
20924 /* Set the cpu variant based on the command-line options. We prefer
20925 -mcpu= over -march= if both are set (as for GCC); and we prefer
20926 -mfpu= over any other way of setting the floating point unit.
20927 Use of legacy options with new options are faulted. */
e74cfd16 20928 if (legacy_cpu)
404ff6b5 20929 {
e74cfd16 20930 if (mcpu_cpu_opt || march_cpu_opt)
c19d1205
ZW
20931 as_bad (_("use of old and new-style options to set CPU type"));
20932
20933 mcpu_cpu_opt = legacy_cpu;
404ff6b5 20934 }
e74cfd16 20935 else if (!mcpu_cpu_opt)
c19d1205 20936 mcpu_cpu_opt = march_cpu_opt;
404ff6b5 20937
e74cfd16 20938 if (legacy_fpu)
c19d1205 20939 {
e74cfd16 20940 if (mfpu_opt)
c19d1205 20941 as_bad (_("use of old and new-style options to set FPU type"));
03b1477f
RE
20942
20943 mfpu_opt = legacy_fpu;
20944 }
e74cfd16 20945 else if (!mfpu_opt)
03b1477f 20946 {
45eb4c1b
NS
20947#if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
20948 || defined (TE_NetBSD) || defined (TE_VXWORKS))
39c2da32
RE
20949 /* Some environments specify a default FPU. If they don't, infer it
20950 from the processor. */
e74cfd16 20951 if (mcpu_fpu_opt)
03b1477f
RE
20952 mfpu_opt = mcpu_fpu_opt;
20953 else
20954 mfpu_opt = march_fpu_opt;
39c2da32 20955#else
e74cfd16 20956 mfpu_opt = &fpu_default;
39c2da32 20957#endif
03b1477f
RE
20958 }
20959
e74cfd16 20960 if (!mfpu_opt)
03b1477f 20961 {
493cb6ef 20962 if (mcpu_cpu_opt != NULL)
e74cfd16 20963 mfpu_opt = &fpu_default;
493cb6ef 20964 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
e74cfd16 20965 mfpu_opt = &fpu_arch_vfp_v2;
03b1477f 20966 else
e74cfd16 20967 mfpu_opt = &fpu_arch_fpa;
03b1477f
RE
20968 }
20969
ee065d83 20970#ifdef CPU_DEFAULT
e74cfd16 20971 if (!mcpu_cpu_opt)
ee065d83 20972 {
e74cfd16
PB
20973 mcpu_cpu_opt = &cpu_default;
20974 selected_cpu = cpu_default;
ee065d83 20975 }
e74cfd16
PB
20976#else
20977 if (mcpu_cpu_opt)
20978 selected_cpu = *mcpu_cpu_opt;
ee065d83 20979 else
e74cfd16 20980 mcpu_cpu_opt = &arm_arch_any;
ee065d83 20981#endif
03b1477f 20982
e74cfd16 20983 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
03b1477f 20984
3e9e4fcf
JB
20985 autoselect_thumb_from_cpu_variant ();
20986
e74cfd16 20987 arm_arch_used = thumb_arch_used = arm_arch_none;
ee065d83 20988
f17c130b 20989#if defined OBJ_COFF || defined OBJ_ELF
b99bd4ef 20990 {
7cc69913
NC
20991 unsigned int flags = 0;
20992
20993#if defined OBJ_ELF
20994 flags = meabi_flags;
d507cf36
PB
20995
20996 switch (meabi_flags)
33a392fb 20997 {
d507cf36 20998 case EF_ARM_EABI_UNKNOWN:
7cc69913 20999#endif
d507cf36
PB
21000 /* Set the flags in the private structure. */
21001 if (uses_apcs_26) flags |= F_APCS26;
21002 if (support_interwork) flags |= F_INTERWORK;
21003 if (uses_apcs_float) flags |= F_APCS_FLOAT;
c19d1205 21004 if (pic_code) flags |= F_PIC;
e74cfd16 21005 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
7cc69913
NC
21006 flags |= F_SOFT_FLOAT;
21007
d507cf36
PB
21008 switch (mfloat_abi_opt)
21009 {
21010 case ARM_FLOAT_ABI_SOFT:
21011 case ARM_FLOAT_ABI_SOFTFP:
21012 flags |= F_SOFT_FLOAT;
21013 break;
33a392fb 21014
d507cf36
PB
21015 case ARM_FLOAT_ABI_HARD:
21016 if (flags & F_SOFT_FLOAT)
21017 as_bad (_("hard-float conflicts with specified fpu"));
21018 break;
21019 }
03b1477f 21020
e74cfd16
PB
21021 /* Using pure-endian doubles (even if soft-float). */
21022 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
7cc69913 21023 flags |= F_VFP_FLOAT;
f17c130b 21024
fde78edd 21025#if defined OBJ_ELF
e74cfd16 21026 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
d507cf36 21027 flags |= EF_ARM_MAVERICK_FLOAT;
d507cf36
PB
21028 break;
21029
8cb51566 21030 case EF_ARM_EABI_VER4:
3a4a14e9 21031 case EF_ARM_EABI_VER5:
c19d1205 21032 /* No additional flags to set. */
d507cf36
PB
21033 break;
21034
21035 default:
21036 abort ();
21037 }
7cc69913 21038#endif
b99bd4ef
NC
21039 bfd_set_private_flags (stdoutput, flags);
21040
21041 /* We have run out flags in the COFF header to encode the
21042 status of ATPCS support, so instead we create a dummy,
c19d1205 21043 empty, debug section called .arm.atpcs. */
b99bd4ef
NC
21044 if (atpcs)
21045 {
21046 asection * sec;
21047
21048 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21049
21050 if (sec != NULL)
21051 {
21052 bfd_set_section_flags
21053 (stdoutput, sec, SEC_READONLY | SEC_DEBUGGING /* | SEC_HAS_CONTENTS */);
21054 bfd_set_section_size (stdoutput, sec, 0);
21055 bfd_set_section_contents (stdoutput, sec, NULL, 0, 0);
21056 }
21057 }
7cc69913 21058 }
f17c130b 21059#endif
b99bd4ef
NC
21060
21061 /* Record the CPU type as well. */
2d447fca
JM
21062 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2))
21063 mach = bfd_mach_arm_iWMMXt2;
21064 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt))
e16bb312 21065 mach = bfd_mach_arm_iWMMXt;
e74cfd16 21066 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
b99bd4ef 21067 mach = bfd_mach_arm_XScale;
e74cfd16 21068 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
fde78edd 21069 mach = bfd_mach_arm_ep9312;
e74cfd16 21070 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
b99bd4ef 21071 mach = bfd_mach_arm_5TE;
e74cfd16 21072 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
b99bd4ef 21073 {
e74cfd16 21074 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21075 mach = bfd_mach_arm_5T;
21076 else
21077 mach = bfd_mach_arm_5;
21078 }
e74cfd16 21079 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
b99bd4ef 21080 {
e74cfd16 21081 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
b99bd4ef
NC
21082 mach = bfd_mach_arm_4T;
21083 else
21084 mach = bfd_mach_arm_4;
21085 }
e74cfd16 21086 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
b99bd4ef 21087 mach = bfd_mach_arm_3M;
e74cfd16
PB
21088 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3))
21089 mach = bfd_mach_arm_3;
21090 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2s))
21091 mach = bfd_mach_arm_2a;
21092 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v2))
21093 mach = bfd_mach_arm_2;
21094 else
21095 mach = bfd_mach_arm_unknown;
b99bd4ef
NC
21096
21097 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21098}
21099
c19d1205 21100/* Command line processing. */
b99bd4ef 21101
c19d1205
ZW
21102/* md_parse_option
21103 Invocation line includes a switch not recognized by the base assembler.
21104 See if it's a processor-specific option.
b99bd4ef 21105
c19d1205
ZW
21106 This routine is somewhat complicated by the need for backwards
21107 compatibility (since older releases of gcc can't be changed).
21108 The new options try to make the interface as compatible as
21109 possible with GCC.
b99bd4ef 21110
c19d1205 21111 New options (supported) are:
b99bd4ef 21112
c19d1205
ZW
21113 -mcpu=<cpu name> Assemble for selected processor
21114 -march=<architecture name> Assemble for selected architecture
21115 -mfpu=<fpu architecture> Assemble for selected FPU.
21116 -EB/-mbig-endian Big-endian
21117 -EL/-mlittle-endian Little-endian
21118 -k Generate PIC code
21119 -mthumb Start in Thumb mode
21120 -mthumb-interwork Code supports ARM/Thumb interworking
b99bd4ef 21121
278df34e 21122 -m[no-]warn-deprecated Warn about deprecated features
267bf995 21123
c19d1205 21124 For now we will also provide support for:
b99bd4ef 21125
c19d1205
ZW
21126 -mapcs-32 32-bit Program counter
21127 -mapcs-26 26-bit Program counter
21128 -macps-float Floats passed in FP registers
21129 -mapcs-reentrant Reentrant code
21130 -matpcs
21131 (sometime these will probably be replaced with -mapcs=<list of options>
21132 and -matpcs=<list of options>)
b99bd4ef 21133
c19d1205
ZW
21134 The remaining options are only supported for back-wards compatibility.
21135 Cpu variants, the arm part is optional:
21136 -m[arm]1 Currently not supported.
21137 -m[arm]2, -m[arm]250 Arm 2 and Arm 250 processor
21138 -m[arm]3 Arm 3 processor
21139 -m[arm]6[xx], Arm 6 processors
21140 -m[arm]7[xx][t][[d]m] Arm 7 processors
21141 -m[arm]8[10] Arm 8 processors
21142 -m[arm]9[20][tdmi] Arm 9 processors
21143 -mstrongarm[110[0]] StrongARM processors
21144 -mxscale XScale processors
21145 -m[arm]v[2345[t[e]]] Arm architectures
21146 -mall All (except the ARM1)
21147 FP variants:
21148 -mfpa10, -mfpa11 FPA10 and 11 co-processor instructions
21149 -mfpe-old (No float load/store multiples)
21150 -mvfpxd VFP Single precision
21151 -mvfp All VFP
21152 -mno-fpu Disable all floating point instructions
b99bd4ef 21153
c19d1205
ZW
21154 The following CPU names are recognized:
21155 arm1, arm2, arm250, arm3, arm6, arm600, arm610, arm620,
21156 arm7, arm7m, arm7d, arm7dm, arm7di, arm7dmi, arm70, arm700,
21157 arm700i, arm710 arm710t, arm720, arm720t, arm740t, arm710c,
21158 arm7100, arm7500, arm7500fe, arm7tdmi, arm8, arm810, arm9,
21159 arm920, arm920t, arm940t, arm946, arm966, arm9tdmi, arm9e,
21160 arm10t arm10e, arm1020t, arm1020e, arm10200e,
21161 strongarm, strongarm110, strongarm1100, strongarm1110, xscale.
b99bd4ef 21162
c19d1205 21163 */
b99bd4ef 21164
c19d1205 21165const char * md_shortopts = "m:k";
b99bd4ef 21166
c19d1205
ZW
21167#ifdef ARM_BI_ENDIAN
21168#define OPTION_EB (OPTION_MD_BASE + 0)
21169#define OPTION_EL (OPTION_MD_BASE + 1)
b99bd4ef 21170#else
c19d1205
ZW
21171#if TARGET_BYTES_BIG_ENDIAN
21172#define OPTION_EB (OPTION_MD_BASE + 0)
b99bd4ef 21173#else
c19d1205
ZW
21174#define OPTION_EL (OPTION_MD_BASE + 1)
21175#endif
b99bd4ef 21176#endif
845b51d6 21177#define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
b99bd4ef 21178
c19d1205 21179struct option md_longopts[] =
b99bd4ef 21180{
c19d1205
ZW
21181#ifdef OPTION_EB
21182 {"EB", no_argument, NULL, OPTION_EB},
21183#endif
21184#ifdef OPTION_EL
21185 {"EL", no_argument, NULL, OPTION_EL},
b99bd4ef 21186#endif
845b51d6 21187 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
c19d1205
ZW
21188 {NULL, no_argument, NULL, 0}
21189};
b99bd4ef 21190
c19d1205 21191size_t md_longopts_size = sizeof (md_longopts);
b99bd4ef 21192
c19d1205 21193struct arm_option_table
b99bd4ef 21194{
c19d1205
ZW
21195 char *option; /* Option name to match. */
21196 char *help; /* Help information. */
21197 int *var; /* Variable to change. */
21198 int value; /* What to change it to. */
21199 char *deprecated; /* If non-null, print this message. */
21200};
b99bd4ef 21201
c19d1205
ZW
21202struct arm_option_table arm_opts[] =
21203{
21204 {"k", N_("generate PIC code"), &pic_code, 1, NULL},
21205 {"mthumb", N_("assemble Thumb code"), &thumb_mode, 1, NULL},
21206 {"mthumb-interwork", N_("support ARM/Thumb interworking"),
21207 &support_interwork, 1, NULL},
21208 {"mapcs-32", N_("code uses 32-bit program counter"), &uses_apcs_26, 0, NULL},
21209 {"mapcs-26", N_("code uses 26-bit program counter"), &uses_apcs_26, 1, NULL},
21210 {"mapcs-float", N_("floating point args are in fp regs"), &uses_apcs_float,
21211 1, NULL},
21212 {"mapcs-reentrant", N_("re-entrant code"), &pic_code, 1, NULL},
21213 {"matpcs", N_("code is ATPCS conformant"), &atpcs, 1, NULL},
21214 {"mbig-endian", N_("assemble for big-endian"), &target_big_endian, 1, NULL},
21215 {"mlittle-endian", N_("assemble for little-endian"), &target_big_endian, 0,
21216 NULL},
b99bd4ef 21217
c19d1205
ZW
21218 /* These are recognized by the assembler, but have no affect on code. */
21219 {"mapcs-frame", N_("use frame pointer"), NULL, 0, NULL},
21220 {"mapcs-stack-check", N_("use stack size checking"), NULL, 0, NULL},
278df34e
NS
21221
21222 {"mwarn-deprecated", NULL, &warn_on_deprecated, 1, NULL},
21223 {"mno-warn-deprecated", N_("do not warn on use of deprecated feature"),
21224 &warn_on_deprecated, 0, NULL},
e74cfd16
PB
21225 {NULL, NULL, NULL, 0, NULL}
21226};
21227
21228struct arm_legacy_option_table
21229{
21230 char *option; /* Option name to match. */
21231 const arm_feature_set **var; /* Variable to change. */
21232 const arm_feature_set value; /* What to change it to. */
21233 char *deprecated; /* If non-null, print this message. */
21234};
b99bd4ef 21235
e74cfd16
PB
21236const struct arm_legacy_option_table arm_legacy_opts[] =
21237{
c19d1205
ZW
21238 /* DON'T add any new processors to this list -- we want the whole list
21239 to go away... Add them to the processors table instead. */
e74cfd16
PB
21240 {"marm1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21241 {"m1", &legacy_cpu, ARM_ARCH_V1, N_("use -mcpu=arm1")},
21242 {"marm2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21243 {"m2", &legacy_cpu, ARM_ARCH_V2, N_("use -mcpu=arm2")},
21244 {"marm250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21245 {"m250", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm250")},
21246 {"marm3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21247 {"m3", &legacy_cpu, ARM_ARCH_V2S, N_("use -mcpu=arm3")},
21248 {"marm6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21249 {"m6", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm6")},
21250 {"marm600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21251 {"m600", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm600")},
21252 {"marm610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21253 {"m610", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm610")},
21254 {"marm620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21255 {"m620", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm620")},
21256 {"marm7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21257 {"m7", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7")},
21258 {"marm70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21259 {"m70", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm70")},
21260 {"marm700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21261 {"m700", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700")},
21262 {"marm700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21263 {"m700i", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm700i")},
21264 {"marm710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21265 {"m710", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710")},
21266 {"marm710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21267 {"m710c", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm710c")},
21268 {"marm720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21269 {"m720", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm720")},
21270 {"marm7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21271 {"m7d", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7d")},
21272 {"marm7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21273 {"m7di", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7di")},
21274 {"marm7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21275 {"m7m", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7m")},
21276 {"marm7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21277 {"m7dm", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dm")},
21278 {"marm7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21279 {"m7dmi", &legacy_cpu, ARM_ARCH_V3M, N_("use -mcpu=arm7dmi")},
21280 {"marm7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21281 {"m7100", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7100")},
21282 {"marm7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21283 {"m7500", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500")},
21284 {"marm7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21285 {"m7500fe", &legacy_cpu, ARM_ARCH_V3, N_("use -mcpu=arm7500fe")},
21286 {"marm7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21287 {"m7t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21288 {"marm7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21289 {"m7tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm7tdmi")},
21290 {"marm710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21291 {"m710t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm710t")},
21292 {"marm720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21293 {"m720t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm720t")},
21294 {"marm740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21295 {"m740t", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm740t")},
21296 {"marm8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21297 {"m8", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm8")},
21298 {"marm810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21299 {"m810", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=arm810")},
21300 {"marm9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21301 {"m9", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9")},
21302 {"marm9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21303 {"m9tdmi", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm9tdmi")},
21304 {"marm920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21305 {"m920", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm920")},
21306 {"marm940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21307 {"m940", &legacy_cpu, ARM_ARCH_V4T, N_("use -mcpu=arm940")},
21308 {"mstrongarm", &legacy_cpu, ARM_ARCH_V4, N_("use -mcpu=strongarm")},
21309 {"mstrongarm110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21310 N_("use -mcpu=strongarm110")},
e74cfd16 21311 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21312 N_("use -mcpu=strongarm1100")},
e74cfd16 21313 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
c19d1205 21314 N_("use -mcpu=strongarm1110")},
e74cfd16
PB
21315 {"mxscale", &legacy_cpu, ARM_ARCH_XSCALE, N_("use -mcpu=xscale")},
21316 {"miwmmxt", &legacy_cpu, ARM_ARCH_IWMMXT, N_("use -mcpu=iwmmxt")},
21317 {"mall", &legacy_cpu, ARM_ANY, N_("use -mcpu=all")},
7ed4c4c5 21318
c19d1205 21319 /* Architecture variants -- don't add any more to this list either. */
e74cfd16
PB
21320 {"mv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21321 {"marmv2", &legacy_cpu, ARM_ARCH_V2, N_("use -march=armv2")},
21322 {"mv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21323 {"marmv2a", &legacy_cpu, ARM_ARCH_V2S, N_("use -march=armv2a")},
21324 {"mv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21325 {"marmv3", &legacy_cpu, ARM_ARCH_V3, N_("use -march=armv3")},
21326 {"mv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21327 {"marmv3m", &legacy_cpu, ARM_ARCH_V3M, N_("use -march=armv3m")},
21328 {"mv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21329 {"marmv4", &legacy_cpu, ARM_ARCH_V4, N_("use -march=armv4")},
21330 {"mv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21331 {"marmv4t", &legacy_cpu, ARM_ARCH_V4T, N_("use -march=armv4t")},
21332 {"mv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21333 {"marmv5", &legacy_cpu, ARM_ARCH_V5, N_("use -march=armv5")},
21334 {"mv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21335 {"marmv5t", &legacy_cpu, ARM_ARCH_V5T, N_("use -march=armv5t")},
21336 {"mv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
21337 {"marmv5e", &legacy_cpu, ARM_ARCH_V5TE, N_("use -march=armv5te")},
7ed4c4c5 21338
c19d1205 21339 /* Floating point variants -- don't add any more to this list either. */
e74cfd16
PB
21340 {"mfpe-old", &legacy_fpu, FPU_ARCH_FPE, N_("use -mfpu=fpe")},
21341 {"mfpa10", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa10")},
21342 {"mfpa11", &legacy_fpu, FPU_ARCH_FPA, N_("use -mfpu=fpa11")},
21343 {"mno-fpu", &legacy_fpu, ARM_ARCH_NONE,
c19d1205 21344 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
7ed4c4c5 21345
e74cfd16 21346 {NULL, NULL, ARM_ARCH_NONE, NULL}
c19d1205 21347};
7ed4c4c5 21348
c19d1205 21349struct arm_cpu_option_table
7ed4c4c5 21350{
c19d1205 21351 char *name;
e74cfd16 21352 const arm_feature_set value;
c19d1205
ZW
21353 /* For some CPUs we assume an FPU unless the user explicitly sets
21354 -mfpu=... */
e74cfd16 21355 const arm_feature_set default_fpu;
ee065d83
PB
21356 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21357 case. */
21358 const char *canonical_name;
c19d1205 21359};
7ed4c4c5 21360
c19d1205
ZW
21361/* This list should, at a minimum, contain all the cpu names
21362 recognized by GCC. */
e74cfd16 21363static const struct arm_cpu_option_table arm_cpus[] =
c19d1205 21364{
ee065d83
PB
21365 {"all", ARM_ANY, FPU_ARCH_FPA, NULL},
21366 {"arm1", ARM_ARCH_V1, FPU_ARCH_FPA, NULL},
21367 {"arm2", ARM_ARCH_V2, FPU_ARCH_FPA, NULL},
21368 {"arm250", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21369 {"arm3", ARM_ARCH_V2S, FPU_ARCH_FPA, NULL},
21370 {"arm6", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21371 {"arm60", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21372 {"arm600", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21373 {"arm610", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21374 {"arm620", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21375 {"arm7", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21376 {"arm7m", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21377 {"arm7d", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21378 {"arm7dm", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21379 {"arm7di", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21380 {"arm7dmi", ARM_ARCH_V3M, FPU_ARCH_FPA, NULL},
21381 {"arm70", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21382 {"arm700", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21383 {"arm700i", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21384 {"arm710", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21385 {"arm710t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21386 {"arm720", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21387 {"arm720t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21388 {"arm740t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21389 {"arm710c", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21390 {"arm7100", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21391 {"arm7500", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21392 {"arm7500fe", ARM_ARCH_V3, FPU_ARCH_FPA, NULL},
21393 {"arm7t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21394 {"arm7tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21395 {"arm7tdmi-s", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21396 {"arm8", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21397 {"arm810", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21398 {"strongarm", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21399 {"strongarm1", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21400 {"strongarm110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21401 {"strongarm1100", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21402 {"strongarm1110", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21403 {"arm9", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21404 {"arm920", ARM_ARCH_V4T, FPU_ARCH_FPA, "ARM920T"},
21405 {"arm920t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21406 {"arm922t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21407 {"arm940t", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
21408 {"arm9tdmi", ARM_ARCH_V4T, FPU_ARCH_FPA, NULL},
7fac0536
NC
21409 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21410 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
c19d1205
ZW
21411 /* For V5 or later processors we default to using VFP; but the user
21412 should really set the FPU type explicitly. */
ee065d83
PB
21413 {"arm9e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21414 {"arm9e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21415 {"arm926ej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21416 {"arm926ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM926EJ-S"},
21417 {"arm926ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
21418 {"arm946e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21419 {"arm946e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM946E-S"},
21420 {"arm946e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21421 {"arm966e-r0", ARM_ARCH_V5TExP, FPU_ARCH_VFP_V2, NULL},
21422 {"arm966e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM966E-S"},
21423 {"arm966e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21424 {"arm968e-s", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21425 {"arm10t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21426 {"arm10tdmi", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21427 {"arm10e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21428 {"arm1020", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, "ARM1020E"},
21429 {"arm1020t", ARM_ARCH_V5T, FPU_ARCH_VFP_V1, NULL},
21430 {"arm1020e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21431 {"arm1022e", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
21432 {"arm1026ejs", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, "ARM1026EJ-S"},
21433 {"arm1026ej-s", ARM_ARCH_V5TEJ, FPU_ARCH_VFP_V2, NULL},
7fac0536
NC
21434 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
21435 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
ee065d83
PB
21436 {"arm1136js", ARM_ARCH_V6, FPU_NONE, "ARM1136J-S"},
21437 {"arm1136j-s", ARM_ARCH_V6, FPU_NONE, NULL},
21438 {"arm1136jfs", ARM_ARCH_V6, FPU_ARCH_VFP_V2, "ARM1136JF-S"},
21439 {"arm1136jf-s", ARM_ARCH_V6, FPU_ARCH_VFP_V2, NULL},
21440 {"mpcore", ARM_ARCH_V6K, FPU_ARCH_VFP_V2, NULL},
21441 {"mpcorenovfp", ARM_ARCH_V6K, FPU_NONE, NULL},
21442 {"arm1156t2-s", ARM_ARCH_V6T2, FPU_NONE, NULL},
21443 {"arm1156t2f-s", ARM_ARCH_V6T2, FPU_ARCH_VFP_V2, NULL},
21444 {"arm1176jz-s", ARM_ARCH_V6ZK, FPU_NONE, NULL},
21445 {"arm1176jzf-s", ARM_ARCH_V6ZK, FPU_ARCH_VFP_V2, NULL},
e07e6e58 21446 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
5287ad62 21447 | FPU_NEON_EXT_V1),
15290f0a 21448 NULL},
e07e6e58 21449 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
15290f0a 21450 | FPU_NEON_EXT_V1),
5287ad62 21451 NULL},
62b3e311
PB
21452 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
21453 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
7e806470 21454 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
5b19eaba 21455 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
c19d1205 21456 /* ??? XSCALE is really an architecture. */
ee065d83 21457 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21458 /* ??? iwmmxt is not a processor. */
ee065d83 21459 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
2d447fca 21460 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
ee065d83 21461 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
c19d1205 21462 /* Maverick */
e07e6e58 21463 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
e74cfd16 21464 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
c19d1205 21465};
7ed4c4c5 21466
c19d1205 21467struct arm_arch_option_table
7ed4c4c5 21468{
c19d1205 21469 char *name;
e74cfd16
PB
21470 const arm_feature_set value;
21471 const arm_feature_set default_fpu;
c19d1205 21472};
7ed4c4c5 21473
c19d1205
ZW
21474/* This list should, at a minimum, contain all the architecture names
21475 recognized by GCC. */
e74cfd16 21476static const struct arm_arch_option_table arm_archs[] =
c19d1205
ZW
21477{
21478 {"all", ARM_ANY, FPU_ARCH_FPA},
21479 {"armv1", ARM_ARCH_V1, FPU_ARCH_FPA},
21480 {"armv2", ARM_ARCH_V2, FPU_ARCH_FPA},
21481 {"armv2a", ARM_ARCH_V2S, FPU_ARCH_FPA},
21482 {"armv2s", ARM_ARCH_V2S, FPU_ARCH_FPA},
21483 {"armv3", ARM_ARCH_V3, FPU_ARCH_FPA},
21484 {"armv3m", ARM_ARCH_V3M, FPU_ARCH_FPA},
21485 {"armv4", ARM_ARCH_V4, FPU_ARCH_FPA},
21486 {"armv4xm", ARM_ARCH_V4xM, FPU_ARCH_FPA},
21487 {"armv4t", ARM_ARCH_V4T, FPU_ARCH_FPA},
21488 {"armv4txm", ARM_ARCH_V4TxM, FPU_ARCH_FPA},
21489 {"armv5", ARM_ARCH_V5, FPU_ARCH_VFP},
21490 {"armv5t", ARM_ARCH_V5T, FPU_ARCH_VFP},
21491 {"armv5txm", ARM_ARCH_V5TxM, FPU_ARCH_VFP},
21492 {"armv5te", ARM_ARCH_V5TE, FPU_ARCH_VFP},
21493 {"armv5texp", ARM_ARCH_V5TExP, FPU_ARCH_VFP},
21494 {"armv5tej", ARM_ARCH_V5TEJ, FPU_ARCH_VFP},
21495 {"armv6", ARM_ARCH_V6, FPU_ARCH_VFP},
21496 {"armv6j", ARM_ARCH_V6, FPU_ARCH_VFP},
21497 {"armv6k", ARM_ARCH_V6K, FPU_ARCH_VFP},
21498 {"armv6z", ARM_ARCH_V6Z, FPU_ARCH_VFP},
21499 {"armv6zk", ARM_ARCH_V6ZK, FPU_ARCH_VFP},
21500 {"armv6t2", ARM_ARCH_V6T2, FPU_ARCH_VFP},
21501 {"armv6kt2", ARM_ARCH_V6KT2, FPU_ARCH_VFP},
21502 {"armv6zt2", ARM_ARCH_V6ZT2, FPU_ARCH_VFP},
21503 {"armv6zkt2", ARM_ARCH_V6ZKT2, FPU_ARCH_VFP},
7e806470 21504 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
62b3e311 21505 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
c450d570
PB
21506 /* The official spelling of the ARMv7 profile variants is the dashed form.
21507 Accept the non-dashed form for compatibility with old toolchains. */
62b3e311
PB
21508 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
21509 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
21510 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c450d570
PB
21511 {"armv7-a", ARM_ARCH_V7A, FPU_ARCH_VFP},
21512 {"armv7-r", ARM_ARCH_V7R, FPU_ARCH_VFP},
21513 {"armv7-m", ARM_ARCH_V7M, FPU_ARCH_VFP},
c19d1205
ZW
21514 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
21515 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
2d447fca 21516 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
e74cfd16 21517 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
c19d1205 21518};
7ed4c4c5 21519
c19d1205 21520/* ISA extensions in the co-processor space. */
e74cfd16 21521struct arm_option_cpu_value_table
c19d1205
ZW
21522{
21523 char *name;
e74cfd16 21524 const arm_feature_set value;
c19d1205 21525};
7ed4c4c5 21526
e74cfd16 21527static const struct arm_option_cpu_value_table arm_extensions[] =
c19d1205 21528{
e74cfd16
PB
21529 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
21530 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
21531 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
2d447fca 21532 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
e74cfd16 21533 {NULL, ARM_ARCH_NONE}
c19d1205 21534};
7ed4c4c5 21535
c19d1205
ZW
21536/* This list should, at a minimum, contain all the fpu names
21537 recognized by GCC. */
e74cfd16 21538static const struct arm_option_cpu_value_table arm_fpus[] =
c19d1205
ZW
21539{
21540 {"softfpa", FPU_NONE},
21541 {"fpe", FPU_ARCH_FPE},
21542 {"fpe2", FPU_ARCH_FPE},
21543 {"fpe3", FPU_ARCH_FPA}, /* Third release supports LFM/SFM. */
21544 {"fpa", FPU_ARCH_FPA},
21545 {"fpa10", FPU_ARCH_FPA},
21546 {"fpa11", FPU_ARCH_FPA},
21547 {"arm7500fe", FPU_ARCH_FPA},
21548 {"softvfp", FPU_ARCH_VFP},
21549 {"softvfp+vfp", FPU_ARCH_VFP_V2},
21550 {"vfp", FPU_ARCH_VFP_V2},
21551 {"vfp9", FPU_ARCH_VFP_V2},
b1cc4aeb 21552 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
c19d1205
ZW
21553 {"vfp10", FPU_ARCH_VFP_V2},
21554 {"vfp10-r0", FPU_ARCH_VFP_V1},
21555 {"vfpxd", FPU_ARCH_VFP_V1xD},
b1cc4aeb
PB
21556 {"vfpv2", FPU_ARCH_VFP_V2},
21557 {"vfpv3", FPU_ARCH_VFP_V3},
21558 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
c19d1205
ZW
21559 {"arm1020t", FPU_ARCH_VFP_V1},
21560 {"arm1020e", FPU_ARCH_VFP_V2},
21561 {"arm1136jfs", FPU_ARCH_VFP_V2},
21562 {"arm1136jf-s", FPU_ARCH_VFP_V2},
21563 {"maverick", FPU_ARCH_MAVERICK},
5287ad62 21564 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
8e79c3df 21565 {"neon-fp16", FPU_ARCH_NEON_FP16},
e74cfd16
PB
21566 {NULL, ARM_ARCH_NONE}
21567};
21568
21569struct arm_option_value_table
21570{
21571 char *name;
21572 long value;
c19d1205 21573};
7ed4c4c5 21574
e74cfd16 21575static const struct arm_option_value_table arm_float_abis[] =
c19d1205
ZW
21576{
21577 {"hard", ARM_FLOAT_ABI_HARD},
21578 {"softfp", ARM_FLOAT_ABI_SOFTFP},
21579 {"soft", ARM_FLOAT_ABI_SOFT},
e74cfd16 21580 {NULL, 0}
c19d1205 21581};
7ed4c4c5 21582
c19d1205 21583#ifdef OBJ_ELF
3a4a14e9 21584/* We only know how to output GNU and ver 4/5 (AAELF) formats. */
e74cfd16 21585static const struct arm_option_value_table arm_eabis[] =
c19d1205
ZW
21586{
21587 {"gnu", EF_ARM_EABI_UNKNOWN},
21588 {"4", EF_ARM_EABI_VER4},
3a4a14e9 21589 {"5", EF_ARM_EABI_VER5},
e74cfd16 21590 {NULL, 0}
c19d1205
ZW
21591};
21592#endif
7ed4c4c5 21593
c19d1205
ZW
21594struct arm_long_option_table
21595{
21596 char * option; /* Substring to match. */
21597 char * help; /* Help information. */
21598 int (* func) (char * subopt); /* Function to decode sub-option. */
21599 char * deprecated; /* If non-null, print this message. */
21600};
7ed4c4c5
NC
21601
21602static int
e74cfd16 21603arm_parse_extension (char * str, const arm_feature_set **opt_p)
7ed4c4c5 21604{
e74cfd16
PB
21605 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
21606
21607 /* Copy the feature set, so that we can modify it. */
21608 *ext_set = **opt_p;
21609 *opt_p = ext_set;
21610
c19d1205 21611 while (str != NULL && *str != 0)
7ed4c4c5 21612 {
e74cfd16 21613 const struct arm_option_cpu_value_table * opt;
c19d1205
ZW
21614 char * ext;
21615 int optlen;
7ed4c4c5 21616
c19d1205
ZW
21617 if (*str != '+')
21618 {
21619 as_bad (_("invalid architectural extension"));
21620 return 0;
21621 }
7ed4c4c5 21622
c19d1205
ZW
21623 str++;
21624 ext = strchr (str, '+');
7ed4c4c5 21625
c19d1205
ZW
21626 if (ext != NULL)
21627 optlen = ext - str;
21628 else
21629 optlen = strlen (str);
7ed4c4c5 21630
c19d1205
ZW
21631 if (optlen == 0)
21632 {
21633 as_bad (_("missing architectural extension"));
21634 return 0;
21635 }
7ed4c4c5 21636
c19d1205
ZW
21637 for (opt = arm_extensions; opt->name != NULL; opt++)
21638 if (strncmp (opt->name, str, optlen) == 0)
21639 {
e74cfd16 21640 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
c19d1205
ZW
21641 break;
21642 }
7ed4c4c5 21643
c19d1205
ZW
21644 if (opt->name == NULL)
21645 {
5f4273c7 21646 as_bad (_("unknown architectural extension `%s'"), str);
c19d1205
ZW
21647 return 0;
21648 }
7ed4c4c5 21649
c19d1205
ZW
21650 str = ext;
21651 };
7ed4c4c5 21652
c19d1205
ZW
21653 return 1;
21654}
7ed4c4c5 21655
c19d1205
ZW
21656static int
21657arm_parse_cpu (char * str)
7ed4c4c5 21658{
e74cfd16 21659 const struct arm_cpu_option_table * opt;
c19d1205
ZW
21660 char * ext = strchr (str, '+');
21661 int optlen;
7ed4c4c5 21662
c19d1205
ZW
21663 if (ext != NULL)
21664 optlen = ext - str;
7ed4c4c5 21665 else
c19d1205 21666 optlen = strlen (str);
7ed4c4c5 21667
c19d1205 21668 if (optlen == 0)
7ed4c4c5 21669 {
c19d1205
ZW
21670 as_bad (_("missing cpu name `%s'"), str);
21671 return 0;
7ed4c4c5
NC
21672 }
21673
c19d1205
ZW
21674 for (opt = arm_cpus; opt->name != NULL; opt++)
21675 if (strncmp (opt->name, str, optlen) == 0)
21676 {
e74cfd16
PB
21677 mcpu_cpu_opt = &opt->value;
21678 mcpu_fpu_opt = &opt->default_fpu;
ee065d83 21679 if (opt->canonical_name)
5f4273c7 21680 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
21681 else
21682 {
21683 int i;
21684 for (i = 0; i < optlen; i++)
21685 selected_cpu_name[i] = TOUPPER (opt->name[i]);
21686 selected_cpu_name[i] = 0;
21687 }
7ed4c4c5 21688
c19d1205
ZW
21689 if (ext != NULL)
21690 return arm_parse_extension (ext, &mcpu_cpu_opt);
7ed4c4c5 21691
c19d1205
ZW
21692 return 1;
21693 }
7ed4c4c5 21694
c19d1205
ZW
21695 as_bad (_("unknown cpu `%s'"), str);
21696 return 0;
7ed4c4c5
NC
21697}
21698
c19d1205
ZW
21699static int
21700arm_parse_arch (char * str)
7ed4c4c5 21701{
e74cfd16 21702 const struct arm_arch_option_table *opt;
c19d1205
ZW
21703 char *ext = strchr (str, '+');
21704 int optlen;
7ed4c4c5 21705
c19d1205
ZW
21706 if (ext != NULL)
21707 optlen = ext - str;
7ed4c4c5 21708 else
c19d1205 21709 optlen = strlen (str);
7ed4c4c5 21710
c19d1205 21711 if (optlen == 0)
7ed4c4c5 21712 {
c19d1205
ZW
21713 as_bad (_("missing architecture name `%s'"), str);
21714 return 0;
7ed4c4c5
NC
21715 }
21716
c19d1205
ZW
21717 for (opt = arm_archs; opt->name != NULL; opt++)
21718 if (streq (opt->name, str))
21719 {
e74cfd16
PB
21720 march_cpu_opt = &opt->value;
21721 march_fpu_opt = &opt->default_fpu;
5f4273c7 21722 strcpy (selected_cpu_name, opt->name);
7ed4c4c5 21723
c19d1205
ZW
21724 if (ext != NULL)
21725 return arm_parse_extension (ext, &march_cpu_opt);
7ed4c4c5 21726
c19d1205
ZW
21727 return 1;
21728 }
21729
21730 as_bad (_("unknown architecture `%s'\n"), str);
21731 return 0;
7ed4c4c5 21732}
eb043451 21733
c19d1205
ZW
21734static int
21735arm_parse_fpu (char * str)
21736{
e74cfd16 21737 const struct arm_option_cpu_value_table * opt;
b99bd4ef 21738
c19d1205
ZW
21739 for (opt = arm_fpus; opt->name != NULL; opt++)
21740 if (streq (opt->name, str))
21741 {
e74cfd16 21742 mfpu_opt = &opt->value;
c19d1205
ZW
21743 return 1;
21744 }
b99bd4ef 21745
c19d1205
ZW
21746 as_bad (_("unknown floating point format `%s'\n"), str);
21747 return 0;
21748}
21749
21750static int
21751arm_parse_float_abi (char * str)
b99bd4ef 21752{
e74cfd16 21753 const struct arm_option_value_table * opt;
b99bd4ef 21754
c19d1205
ZW
21755 for (opt = arm_float_abis; opt->name != NULL; opt++)
21756 if (streq (opt->name, str))
21757 {
21758 mfloat_abi_opt = opt->value;
21759 return 1;
21760 }
cc8a6dd0 21761
c19d1205
ZW
21762 as_bad (_("unknown floating point abi `%s'\n"), str);
21763 return 0;
21764}
b99bd4ef 21765
c19d1205
ZW
21766#ifdef OBJ_ELF
21767static int
21768arm_parse_eabi (char * str)
21769{
e74cfd16 21770 const struct arm_option_value_table *opt;
cc8a6dd0 21771
c19d1205
ZW
21772 for (opt = arm_eabis; opt->name != NULL; opt++)
21773 if (streq (opt->name, str))
21774 {
21775 meabi_flags = opt->value;
21776 return 1;
21777 }
21778 as_bad (_("unknown EABI `%s'\n"), str);
21779 return 0;
21780}
21781#endif
cc8a6dd0 21782
e07e6e58
NC
21783static int
21784arm_parse_it_mode (char * str)
21785{
21786 int ret = 1;
21787
21788 if (streq ("arm", str))
21789 implicit_it_mode = IMPLICIT_IT_MODE_ARM;
21790 else if (streq ("thumb", str))
21791 implicit_it_mode = IMPLICIT_IT_MODE_THUMB;
21792 else if (streq ("always", str))
21793 implicit_it_mode = IMPLICIT_IT_MODE_ALWAYS;
21794 else if (streq ("never", str))
21795 implicit_it_mode = IMPLICIT_IT_MODE_NEVER;
21796 else
21797 {
21798 as_bad (_("unknown implicit IT mode `%s', should be "\
21799 "arm, thumb, always, or never."), str);
21800 ret = 0;
21801 }
21802
21803 return ret;
21804}
21805
c19d1205
ZW
21806struct arm_long_option_table arm_long_opts[] =
21807{
21808 {"mcpu=", N_("<cpu name>\t assemble for CPU <cpu name>"),
21809 arm_parse_cpu, NULL},
21810 {"march=", N_("<arch name>\t assemble for architecture <arch name>"),
21811 arm_parse_arch, NULL},
21812 {"mfpu=", N_("<fpu name>\t assemble for FPU architecture <fpu name>"),
21813 arm_parse_fpu, NULL},
21814 {"mfloat-abi=", N_("<abi>\t assemble for floating point ABI <abi>"),
21815 arm_parse_float_abi, NULL},
21816#ifdef OBJ_ELF
7fac0536 21817 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
c19d1205
ZW
21818 arm_parse_eabi, NULL},
21819#endif
e07e6e58
NC
21820 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
21821 arm_parse_it_mode, NULL},
c19d1205
ZW
21822 {NULL, NULL, 0, NULL}
21823};
cc8a6dd0 21824
c19d1205
ZW
21825int
21826md_parse_option (int c, char * arg)
21827{
21828 struct arm_option_table *opt;
e74cfd16 21829 const struct arm_legacy_option_table *fopt;
c19d1205 21830 struct arm_long_option_table *lopt;
b99bd4ef 21831
c19d1205 21832 switch (c)
b99bd4ef 21833 {
c19d1205
ZW
21834#ifdef OPTION_EB
21835 case OPTION_EB:
21836 target_big_endian = 1;
21837 break;
21838#endif
cc8a6dd0 21839
c19d1205
ZW
21840#ifdef OPTION_EL
21841 case OPTION_EL:
21842 target_big_endian = 0;
21843 break;
21844#endif
b99bd4ef 21845
845b51d6
PB
21846 case OPTION_FIX_V4BX:
21847 fix_v4bx = TRUE;
21848 break;
21849
c19d1205
ZW
21850 case 'a':
21851 /* Listing option. Just ignore these, we don't support additional
21852 ones. */
21853 return 0;
b99bd4ef 21854
c19d1205
ZW
21855 default:
21856 for (opt = arm_opts; opt->option != NULL; opt++)
21857 {
21858 if (c == opt->option[0]
21859 && ((arg == NULL && opt->option[1] == 0)
21860 || streq (arg, opt->option + 1)))
21861 {
c19d1205 21862 /* If the option is deprecated, tell the user. */
278df34e 21863 if (warn_on_deprecated && opt->deprecated != NULL)
c19d1205
ZW
21864 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21865 arg ? arg : "", _(opt->deprecated));
b99bd4ef 21866
c19d1205
ZW
21867 if (opt->var != NULL)
21868 *opt->var = opt->value;
cc8a6dd0 21869
c19d1205
ZW
21870 return 1;
21871 }
21872 }
b99bd4ef 21873
e74cfd16
PB
21874 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21875 {
21876 if (c == fopt->option[0]
21877 && ((arg == NULL && fopt->option[1] == 0)
21878 || streq (arg, fopt->option + 1)))
21879 {
e74cfd16 21880 /* If the option is deprecated, tell the user. */
278df34e 21881 if (warn_on_deprecated && fopt->deprecated != NULL)
e74cfd16
PB
21882 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21883 arg ? arg : "", _(fopt->deprecated));
e74cfd16
PB
21884
21885 if (fopt->var != NULL)
21886 *fopt->var = &fopt->value;
21887
21888 return 1;
21889 }
21890 }
21891
c19d1205
ZW
21892 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21893 {
21894 /* These options are expected to have an argument. */
21895 if (c == lopt->option[0]
21896 && arg != NULL
21897 && strncmp (arg, lopt->option + 1,
21898 strlen (lopt->option + 1)) == 0)
21899 {
c19d1205 21900 /* If the option is deprecated, tell the user. */
278df34e 21901 if (warn_on_deprecated && lopt->deprecated != NULL)
c19d1205
ZW
21902 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21903 _(lopt->deprecated));
b99bd4ef 21904
c19d1205
ZW
21905 /* Call the sup-option parser. */
21906 return lopt->func (arg + strlen (lopt->option) - 1);
21907 }
21908 }
a737bd4d 21909
c19d1205
ZW
21910 return 0;
21911 }
a394c00f 21912
c19d1205
ZW
21913 return 1;
21914}
a394c00f 21915
c19d1205
ZW
21916void
21917md_show_usage (FILE * fp)
a394c00f 21918{
c19d1205
ZW
21919 struct arm_option_table *opt;
21920 struct arm_long_option_table *lopt;
a394c00f 21921
c19d1205 21922 fprintf (fp, _(" ARM-specific assembler options:\n"));
a394c00f 21923
c19d1205
ZW
21924 for (opt = arm_opts; opt->option != NULL; opt++)
21925 if (opt->help != NULL)
21926 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
a394c00f 21927
c19d1205
ZW
21928 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
21929 if (lopt->help != NULL)
21930 fprintf (fp, " -%s%s\n", lopt->option, _(lopt->help));
a394c00f 21931
c19d1205
ZW
21932#ifdef OPTION_EB
21933 fprintf (fp, _("\
21934 -EB assemble code for a big-endian cpu\n"));
a394c00f
NC
21935#endif
21936
c19d1205
ZW
21937#ifdef OPTION_EL
21938 fprintf (fp, _("\
21939 -EL assemble code for a little-endian cpu\n"));
a737bd4d 21940#endif
845b51d6
PB
21941
21942 fprintf (fp, _("\
21943 --fix-v4bx Allow BX in ARMv4 code\n"));
c19d1205 21944}
ee065d83
PB
21945
21946
21947#ifdef OBJ_ELF
62b3e311
PB
21948typedef struct
21949{
21950 int val;
21951 arm_feature_set flags;
21952} cpu_arch_ver_table;
21953
21954/* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21955 least features first. */
21956static const cpu_arch_ver_table cpu_arch_ver[] =
21957{
21958 {1, ARM_ARCH_V4},
21959 {2, ARM_ARCH_V4T},
21960 {3, ARM_ARCH_V5},
ee3c0378 21961 {3, ARM_ARCH_V5T},
62b3e311
PB
21962 {4, ARM_ARCH_V5TE},
21963 {5, ARM_ARCH_V5TEJ},
21964 {6, ARM_ARCH_V6},
21965 {7, ARM_ARCH_V6Z},
7e806470 21966 {9, ARM_ARCH_V6K},
91e22acd 21967 {11, ARM_ARCH_V6M},
7e806470 21968 {8, ARM_ARCH_V6T2},
62b3e311
PB
21969 {10, ARM_ARCH_V7A},
21970 {10, ARM_ARCH_V7R},
21971 {10, ARM_ARCH_V7M},
21972 {0, ARM_ARCH_NONE}
21973};
21974
ee3c0378
AS
21975/* Set an attribute if it has not already been set by the user. */
21976static void
21977aeabi_set_attribute_int (int tag, int value)
21978{
21979 if (tag < 1
21980 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21981 || !attributes_set_explicitly[tag])
21982 bfd_elf_add_proc_attr_int (stdoutput, tag, value);
21983}
21984
21985static void
21986aeabi_set_attribute_string (int tag, const char *value)
21987{
21988 if (tag < 1
21989 || tag >= NUM_KNOWN_OBJ_ATTRIBUTES
21990 || !attributes_set_explicitly[tag])
21991 bfd_elf_add_proc_attr_string (stdoutput, tag, value);
21992}
21993
ee065d83
PB
21994/* Set the public EABI object attributes. */
21995static void
21996aeabi_set_public_attributes (void)
21997{
21998 int arch;
e74cfd16 21999 arm_feature_set flags;
62b3e311
PB
22000 arm_feature_set tmp;
22001 const cpu_arch_ver_table *p;
ee065d83
PB
22002
22003 /* Choose the architecture based on the capabilities of the requested cpu
22004 (if any) and/or the instructions actually used. */
e74cfd16
PB
22005 ARM_MERGE_FEATURE_SETS (flags, arm_arch_used, thumb_arch_used);
22006 ARM_MERGE_FEATURE_SETS (flags, flags, *mfpu_opt);
22007 ARM_MERGE_FEATURE_SETS (flags, flags, selected_cpu);
7a1d4c38
PB
22008 /*Allow the user to override the reported architecture. */
22009 if (object_arch)
22010 {
22011 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22012 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22013 }
22014
62b3e311
PB
22015 tmp = flags;
22016 arch = 0;
22017 for (p = cpu_arch_ver; p->val; p++)
22018 {
22019 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22020 {
22021 arch = p->val;
22022 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22023 }
22024 }
ee065d83
PB
22025
22026 /* Tag_CPU_name. */
22027 if (selected_cpu_name[0])
22028 {
22029 char *p;
22030
22031 p = selected_cpu_name;
5f4273c7 22032 if (strncmp (p, "armv", 4) == 0)
ee065d83
PB
22033 {
22034 int i;
5f4273c7 22035
ee065d83
PB
22036 p += 4;
22037 for (i = 0; p[i]; i++)
22038 p[i] = TOUPPER (p[i]);
22039 }
ee3c0378 22040 aeabi_set_attribute_string (Tag_CPU_name, p);
ee065d83
PB
22041 }
22042 /* Tag_CPU_arch. */
ee3c0378 22043 aeabi_set_attribute_int (Tag_CPU_arch, arch);
62b3e311
PB
22044 /* Tag_CPU_arch_profile. */
22045 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
ee3c0378 22046 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
62b3e311 22047 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
ee3c0378 22048 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
7e806470 22049 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
ee3c0378 22050 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
ee065d83 22051 /* Tag_ARM_ISA_use. */
ee3c0378
AS
22052 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22053 || arch == 0)
22054 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
ee065d83 22055 /* Tag_THUMB_ISA_use. */
ee3c0378
AS
22056 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v4t)
22057 || arch == 0)
22058 aeabi_set_attribute_int (Tag_THUMB_ISA_use,
22059 ARM_CPU_HAS_FEATURE (flags, arm_arch_t2) ? 2 : 1);
ee065d83 22060 /* Tag_VFP_arch. */
ee3c0378
AS
22061 if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_d32))
22062 aeabi_set_attribute_int (Tag_VFP_arch, 3);
22063 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v3))
22064 aeabi_set_attribute_int (Tag_VFP_arch, 4);
22065 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v2))
22066 aeabi_set_attribute_int (Tag_VFP_arch, 2);
22067 else if (ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1)
22068 || ARM_CPU_HAS_FEATURE (flags, fpu_vfp_ext_v1xd))
22069 aeabi_set_attribute_int (Tag_VFP_arch, 1);
ee065d83 22070 /* Tag_WMMX_arch. */
ee3c0378
AS
22071 if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt2))
22072 aeabi_set_attribute_int (Tag_WMMX_arch, 2);
22073 else if (ARM_CPU_HAS_FEATURE (flags, arm_cext_iwmmxt))
22074 aeabi_set_attribute_int (Tag_WMMX_arch, 1);
22075 /* Tag_Advanced_SIMD_arch (formerly Tag_NEON_arch). */
8e79c3df 22076 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
ee3c0378
AS
22077 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
22078 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
8e79c3df 22079 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
ee3c0378 22080 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
ee065d83
PB
22081}
22082
104d59d1 22083/* Add the default contents for the .ARM.attributes section. */
ee065d83
PB
22084void
22085arm_md_end (void)
22086{
ee065d83
PB
22087 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22088 return;
22089
22090 aeabi_set_public_attributes ();
ee065d83 22091}
8463be01 22092#endif /* OBJ_ELF */
ee065d83
PB
22093
22094
22095/* Parse a .cpu directive. */
22096
22097static void
22098s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22099{
e74cfd16 22100 const struct arm_cpu_option_table *opt;
ee065d83
PB
22101 char *name;
22102 char saved_char;
22103
22104 name = input_line_pointer;
5f4273c7 22105 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22106 input_line_pointer++;
22107 saved_char = *input_line_pointer;
22108 *input_line_pointer = 0;
22109
22110 /* Skip the first "all" entry. */
22111 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22112 if (streq (opt->name, name))
22113 {
e74cfd16
PB
22114 mcpu_cpu_opt = &opt->value;
22115 selected_cpu = opt->value;
ee065d83 22116 if (opt->canonical_name)
5f4273c7 22117 strcpy (selected_cpu_name, opt->canonical_name);
ee065d83
PB
22118 else
22119 {
22120 int i;
22121 for (i = 0; opt->name[i]; i++)
22122 selected_cpu_name[i] = TOUPPER (opt->name[i]);
22123 selected_cpu_name[i] = 0;
22124 }
e74cfd16 22125 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22126 *input_line_pointer = saved_char;
22127 demand_empty_rest_of_line ();
22128 return;
22129 }
22130 as_bad (_("unknown cpu `%s'"), name);
22131 *input_line_pointer = saved_char;
22132 ignore_rest_of_line ();
22133}
22134
22135
22136/* Parse a .arch directive. */
22137
22138static void
22139s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22140{
e74cfd16 22141 const struct arm_arch_option_table *opt;
ee065d83
PB
22142 char saved_char;
22143 char *name;
22144
22145 name = input_line_pointer;
5f4273c7 22146 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22147 input_line_pointer++;
22148 saved_char = *input_line_pointer;
22149 *input_line_pointer = 0;
22150
22151 /* Skip the first "all" entry. */
22152 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22153 if (streq (opt->name, name))
22154 {
e74cfd16
PB
22155 mcpu_cpu_opt = &opt->value;
22156 selected_cpu = opt->value;
5f4273c7 22157 strcpy (selected_cpu_name, opt->name);
e74cfd16 22158 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22159 *input_line_pointer = saved_char;
22160 demand_empty_rest_of_line ();
22161 return;
22162 }
22163
22164 as_bad (_("unknown architecture `%s'\n"), name);
22165 *input_line_pointer = saved_char;
22166 ignore_rest_of_line ();
22167}
22168
22169
7a1d4c38
PB
22170/* Parse a .object_arch directive. */
22171
22172static void
22173s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22174{
22175 const struct arm_arch_option_table *opt;
22176 char saved_char;
22177 char *name;
22178
22179 name = input_line_pointer;
5f4273c7 22180 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
7a1d4c38
PB
22181 input_line_pointer++;
22182 saved_char = *input_line_pointer;
22183 *input_line_pointer = 0;
22184
22185 /* Skip the first "all" entry. */
22186 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22187 if (streq (opt->name, name))
22188 {
22189 object_arch = &opt->value;
22190 *input_line_pointer = saved_char;
22191 demand_empty_rest_of_line ();
22192 return;
22193 }
22194
22195 as_bad (_("unknown architecture `%s'\n"), name);
22196 *input_line_pointer = saved_char;
22197 ignore_rest_of_line ();
22198}
22199
ee065d83
PB
22200/* Parse a .fpu directive. */
22201
22202static void
22203s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22204{
e74cfd16 22205 const struct arm_option_cpu_value_table *opt;
ee065d83
PB
22206 char saved_char;
22207 char *name;
22208
22209 name = input_line_pointer;
5f4273c7 22210 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
ee065d83
PB
22211 input_line_pointer++;
22212 saved_char = *input_line_pointer;
22213 *input_line_pointer = 0;
5f4273c7 22214
ee065d83
PB
22215 for (opt = arm_fpus; opt->name != NULL; opt++)
22216 if (streq (opt->name, name))
22217 {
e74cfd16
PB
22218 mfpu_opt = &opt->value;
22219 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
ee065d83
PB
22220 *input_line_pointer = saved_char;
22221 demand_empty_rest_of_line ();
22222 return;
22223 }
22224
22225 as_bad (_("unknown floating point format `%s'\n"), name);
22226 *input_line_pointer = saved_char;
22227 ignore_rest_of_line ();
22228}
ee065d83 22229
794ba86a 22230/* Copy symbol information. */
f31fef98 22231
794ba86a
DJ
22232void
22233arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22234{
22235 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22236}
e04befd0 22237
f31fef98 22238#ifdef OBJ_ELF
e04befd0
AS
22239/* Given a symbolic attribute NAME, return the proper integer value.
22240 Returns -1 if the attribute is not known. */
f31fef98 22241
e04befd0
AS
22242int
22243arm_convert_symbolic_attribute (const char *name)
22244{
f31fef98
NC
22245 static const struct
22246 {
22247 const char * name;
22248 const int tag;
22249 }
22250 attribute_table[] =
22251 {
22252 /* When you modify this table you should
22253 also modify the list in doc/c-arm.texi. */
e04befd0 22254#define T(tag) {#tag, tag}
f31fef98
NC
22255 T (Tag_CPU_raw_name),
22256 T (Tag_CPU_name),
22257 T (Tag_CPU_arch),
22258 T (Tag_CPU_arch_profile),
22259 T (Tag_ARM_ISA_use),
22260 T (Tag_THUMB_ISA_use),
22261 T (Tag_VFP_arch),
22262 T (Tag_WMMX_arch),
22263 T (Tag_Advanced_SIMD_arch),
22264 T (Tag_PCS_config),
22265 T (Tag_ABI_PCS_R9_use),
22266 T (Tag_ABI_PCS_RW_data),
22267 T (Tag_ABI_PCS_RO_data),
22268 T (Tag_ABI_PCS_GOT_use),
22269 T (Tag_ABI_PCS_wchar_t),
22270 T (Tag_ABI_FP_rounding),
22271 T (Tag_ABI_FP_denormal),
22272 T (Tag_ABI_FP_exceptions),
22273 T (Tag_ABI_FP_user_exceptions),
22274 T (Tag_ABI_FP_number_model),
22275 T (Tag_ABI_align8_needed),
22276 T (Tag_ABI_align8_preserved),
22277 T (Tag_ABI_enum_size),
22278 T (Tag_ABI_HardFP_use),
22279 T (Tag_ABI_VFP_args),
22280 T (Tag_ABI_WMMX_args),
22281 T (Tag_ABI_optimization_goals),
22282 T (Tag_ABI_FP_optimization_goals),
22283 T (Tag_compatibility),
22284 T (Tag_CPU_unaligned_access),
22285 T (Tag_VFP_HP_extension),
22286 T (Tag_ABI_FP_16bit_format),
22287 T (Tag_nodefaults),
22288 T (Tag_also_compatible_with),
22289 T (Tag_conformance),
22290 T (Tag_T2EE_use),
22291 T (Tag_Virtualization_use),
22292 T (Tag_MPextension_use)
e04befd0 22293#undef T
f31fef98 22294 };
e04befd0
AS
22295 unsigned int i;
22296
22297 if (name == NULL)
22298 return -1;
22299
f31fef98 22300 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
e04befd0
AS
22301 if (strcmp (name, attribute_table[i].name) == 0)
22302 return attribute_table[i].tag;
22303
22304 return -1;
22305}
267bf995
RR
22306
22307
22308/* Apply sym value for relocations only in the case that
22309 they are for local symbols and you have the respective
22310 architectural feature for blx and simple switches. */
22311int
22312arm_apply_sym_value (struct fix * fixP)
22313{
22314 if (fixP->fx_addsy
22315 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22316 && !S_IS_EXTERNAL (fixP->fx_addsy))
22317 {
22318 switch (fixP->fx_r_type)
22319 {
22320 case BFD_RELOC_ARM_PCREL_BLX:
22321 case BFD_RELOC_THUMB_PCREL_BRANCH23:
22322 if (ARM_IS_FUNC (fixP->fx_addsy))
22323 return 1;
22324 break;
22325
22326 case BFD_RELOC_ARM_PCREL_CALL:
22327 case BFD_RELOC_THUMB_PCREL_BLX:
22328 if (THUMB_IS_FUNC (fixP->fx_addsy))
22329 return 1;
22330 break;
22331
22332 default:
22333 break;
22334 }
22335
22336 }
22337 return 0;
22338}
f31fef98 22339#endif /* OBJ_ELF */