2009-07-02 Tristan Gingold <gingold@adacore.com>
[binutils.git] / gas / config / tc-arm.c
blob99b6e415606cdbba5dae60715ed5c2b3d67d3274
1 /* tc-arm.c -- Assemble for the ARM
2 Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003,
3 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
5 Contributed by Richard Earnshaw (rwe@pegasus.esprit.ec.org)
6 Modified by David Taylor (dtaylor@armltd.co.uk)
7 Cirrus coprocessor mods by Aldy Hernandez (aldyh@redhat.com)
8 Cirrus coprocessor fixes by Petko Manolov (petkan@nucleusys.com)
9 Cirrus coprocessor fixes by Vladimir Ivanov (vladitx@nucleusys.com)
11 This file is part of GAS, the GNU Assembler.
13 GAS is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 3, or (at your option)
16 any later version.
18 GAS is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
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
25 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 02110-1301, USA. */
28 #include "as.h"
29 #include <limits.h>
30 #include <stdarg.h>
31 #define NO_RELOC 0
32 #include "safe-ctype.h"
33 #include "subsegs.h"
34 #include "obstack.h"
36 #include "opcode/arm.h"
38 #ifdef OBJ_ELF
39 #include "elf/arm.h"
40 #include "dw2gencfi.h"
41 #endif
43 #include "dwarf2dbg.h"
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
49 /* This structure holds the unwinding state. */
51 static struct
53 symbolS * proc_start;
54 symbolS * table_entry;
55 symbolS * personality_routine;
56 int personality_index;
57 /* The segment containing the function. */
58 segT saved_seg;
59 subsegT saved_subseg;
60 /* Opcodes generated from this function. */
61 unsigned char * opcodes;
62 int opcode_count;
63 int opcode_alloc;
64 /* The number of bytes pushed to the stack. */
65 offsetT frame_size;
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. */
69 offsetT pending_offset;
70 /* These two fields are set by both unwind_movsp and unwind_setfp. They
71 hold the reg+offset to use when restoring sp from a frame pointer. */
72 offsetT fp_offset;
73 int fp_reg;
74 /* Nonzero if an unwind_setfp directive has been seen. */
75 unsigned fp_used:1;
76 /* Nonzero if the last opcode restores sp from fp_reg. */
77 unsigned sp_restored:1;
78 } unwind;
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. */
83 static unsigned int marked_pr_dependency = 0;
85 #endif /* OBJ_ELF */
87 /* Results from operand parsing worker functions. */
89 typedef enum
91 PARSE_OPERAND_SUCCESS,
92 PARSE_OPERAND_FAIL,
93 PARSE_OPERAND_FAIL_NO_BACKTRACK
94 } parse_operand_result;
96 enum arm_float_abi
98 ARM_FLOAT_ABI_HARD,
99 ARM_FLOAT_ABI_SOFTFP,
100 ARM_FLOAT_ABI_SOFT
103 /* Types of processor to assemble for. */
104 #ifndef CPU_DEFAULT
105 #if defined __XSCALE__
106 #define CPU_DEFAULT ARM_ARCH_XSCALE
107 #else
108 #if defined __thumb__
109 #define CPU_DEFAULT ARM_ARCH_V5T
110 #endif
111 #endif
112 #endif
114 #ifndef FPU_DEFAULT
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
124 # elif defined (TE_VXWORKS)
125 # define FPU_DEFAULT FPU_ARCH_VFP /* Soft-float, VFP order. */
126 # else
127 /* For backwards compatibility, default to FPA. */
128 # define FPU_DEFAULT FPU_ARCH_FPA
129 # endif
130 #endif /* ifndef FPU_DEFAULT */
132 #define streq(a, b) (strcmp (a, b) == 0)
134 static arm_feature_set cpu_variant;
135 static arm_feature_set arm_arch_used;
136 static arm_feature_set thumb_arch_used;
138 /* Flags stored in private area of BFD structure. */
139 static int uses_apcs_26 = FALSE;
140 static int atpcs = FALSE;
141 static int support_interwork = FALSE;
142 static int uses_apcs_float = FALSE;
143 static int pic_code = FALSE;
144 static int fix_v4bx = FALSE;
145 /* Warn on using deprecated features. */
146 static int warn_on_deprecated = TRUE;
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. */
152 static const arm_feature_set *legacy_cpu = NULL;
153 static const arm_feature_set *legacy_fpu = NULL;
155 static const arm_feature_set *mcpu_cpu_opt = NULL;
156 static const arm_feature_set *mcpu_fpu_opt = NULL;
157 static const arm_feature_set *march_cpu_opt = NULL;
158 static const arm_feature_set *march_fpu_opt = NULL;
159 static const arm_feature_set *mfpu_opt = NULL;
160 static const arm_feature_set *object_arch = NULL;
162 /* Constants for known architecture features. */
163 static const arm_feature_set fpu_default = FPU_DEFAULT;
164 static const arm_feature_set fpu_arch_vfp_v1 = FPU_ARCH_VFP_V1;
165 static const arm_feature_set fpu_arch_vfp_v2 = FPU_ARCH_VFP_V2;
166 static const arm_feature_set fpu_arch_vfp_v3 = FPU_ARCH_VFP_V3;
167 static const arm_feature_set fpu_arch_neon_v1 = FPU_ARCH_NEON_V1;
168 static const arm_feature_set fpu_arch_fpa = FPU_ARCH_FPA;
169 static const arm_feature_set fpu_any_hard = FPU_ANY_HARD;
170 static const arm_feature_set fpu_arch_maverick = FPU_ARCH_MAVERICK;
171 static const arm_feature_set fpu_endian_pure = FPU_ARCH_ENDIAN_PURE;
173 #ifdef CPU_DEFAULT
174 static const arm_feature_set cpu_default = CPU_DEFAULT;
175 #endif
177 static const arm_feature_set arm_ext_v1 = ARM_FEATURE (ARM_EXT_V1, 0);
178 static const arm_feature_set arm_ext_v2 = ARM_FEATURE (ARM_EXT_V1, 0);
179 static const arm_feature_set arm_ext_v2s = ARM_FEATURE (ARM_EXT_V2S, 0);
180 static const arm_feature_set arm_ext_v3 = ARM_FEATURE (ARM_EXT_V3, 0);
181 static const arm_feature_set arm_ext_v3m = ARM_FEATURE (ARM_EXT_V3M, 0);
182 static const arm_feature_set arm_ext_v4 = ARM_FEATURE (ARM_EXT_V4, 0);
183 static const arm_feature_set arm_ext_v4t = ARM_FEATURE (ARM_EXT_V4T, 0);
184 static const arm_feature_set arm_ext_v5 = ARM_FEATURE (ARM_EXT_V5, 0);
185 static const arm_feature_set arm_ext_v4t_5 =
186 ARM_FEATURE (ARM_EXT_V4T | ARM_EXT_V5, 0);
187 static const arm_feature_set arm_ext_v5t = ARM_FEATURE (ARM_EXT_V5T, 0);
188 static const arm_feature_set arm_ext_v5e = ARM_FEATURE (ARM_EXT_V5E, 0);
189 static const arm_feature_set arm_ext_v5exp = ARM_FEATURE (ARM_EXT_V5ExP, 0);
190 static const arm_feature_set arm_ext_v5j = ARM_FEATURE (ARM_EXT_V5J, 0);
191 static const arm_feature_set arm_ext_v6 = ARM_FEATURE (ARM_EXT_V6, 0);
192 static const arm_feature_set arm_ext_v6k = ARM_FEATURE (ARM_EXT_V6K, 0);
193 static const arm_feature_set arm_ext_v6z = ARM_FEATURE (ARM_EXT_V6Z, 0);
194 static const arm_feature_set arm_ext_v6t2 = ARM_FEATURE (ARM_EXT_V6T2, 0);
195 static const arm_feature_set arm_ext_v6_notm = ARM_FEATURE (ARM_EXT_V6_NOTM, 0);
196 static const arm_feature_set arm_ext_barrier = ARM_FEATURE (ARM_EXT_BARRIER, 0);
197 static const arm_feature_set arm_ext_msr = ARM_FEATURE (ARM_EXT_THUMB_MSR, 0);
198 static const arm_feature_set arm_ext_div = ARM_FEATURE (ARM_EXT_DIV, 0);
199 static const arm_feature_set arm_ext_v7 = ARM_FEATURE (ARM_EXT_V7, 0);
200 static const arm_feature_set arm_ext_v7a = ARM_FEATURE (ARM_EXT_V7A, 0);
201 static const arm_feature_set arm_ext_v7r = ARM_FEATURE (ARM_EXT_V7R, 0);
202 static const arm_feature_set arm_ext_m =
203 ARM_FEATURE (ARM_EXT_V6M | ARM_EXT_V7M, 0);
205 static const arm_feature_set arm_arch_any = ARM_ANY;
206 static const arm_feature_set arm_arch_full = ARM_FEATURE (-1, -1);
207 static const arm_feature_set arm_arch_t2 = ARM_ARCH_THUMB2;
208 static const arm_feature_set arm_arch_none = ARM_ARCH_NONE;
210 static const arm_feature_set arm_cext_iwmmxt2 =
211 ARM_FEATURE (0, ARM_CEXT_IWMMXT2);
212 static const arm_feature_set arm_cext_iwmmxt =
213 ARM_FEATURE (0, ARM_CEXT_IWMMXT);
214 static const arm_feature_set arm_cext_xscale =
215 ARM_FEATURE (0, ARM_CEXT_XSCALE);
216 static const arm_feature_set arm_cext_maverick =
217 ARM_FEATURE (0, ARM_CEXT_MAVERICK);
218 static const arm_feature_set fpu_fpa_ext_v1 = ARM_FEATURE (0, FPU_FPA_EXT_V1);
219 static const arm_feature_set fpu_fpa_ext_v2 = ARM_FEATURE (0, FPU_FPA_EXT_V2);
220 static const arm_feature_set fpu_vfp_ext_v1xd =
221 ARM_FEATURE (0, FPU_VFP_EXT_V1xD);
222 static const arm_feature_set fpu_vfp_ext_v1 = ARM_FEATURE (0, FPU_VFP_EXT_V1);
223 static const arm_feature_set fpu_vfp_ext_v2 = ARM_FEATURE (0, FPU_VFP_EXT_V2);
224 static const arm_feature_set fpu_vfp_ext_v3 = ARM_FEATURE (0, FPU_VFP_EXT_V3);
225 static const arm_feature_set fpu_vfp_ext_d32 =
226 ARM_FEATURE (0, FPU_VFP_EXT_D32);
227 static const arm_feature_set fpu_neon_ext_v1 = ARM_FEATURE (0, FPU_NEON_EXT_V1);
228 static const arm_feature_set fpu_vfp_v3_or_neon_ext =
229 ARM_FEATURE (0, FPU_NEON_EXT_V1 | FPU_VFP_EXT_V3);
230 static const arm_feature_set fpu_neon_fp16 = ARM_FEATURE (0, FPU_NEON_FP16);
232 static int mfloat_abi_opt = -1;
233 /* Record user cpu selection for object attributes. */
234 static arm_feature_set selected_cpu = ARM_ARCH_NONE;
235 /* Must be long enough to hold any of the names in arm_cpus. */
236 static char selected_cpu_name[16];
237 #ifdef OBJ_ELF
238 # ifdef EABI_DEFAULT
239 static int meabi_flags = EABI_DEFAULT;
240 # else
241 static int meabi_flags = EF_ARM_EABI_UNKNOWN;
242 # endif
244 static int attributes_set_explicitly[NUM_KNOWN_OBJ_ATTRIBUTES];
246 bfd_boolean
247 arm_is_eabi (void)
249 return (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4);
251 #endif
253 #ifdef OBJ_ELF
254 /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
255 symbolS * GOT_symbol;
256 #endif
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. */
262 static int thumb_mode = 0;
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)
268 /* Specifies the intrinsic IT insn behavior mode. */
269 enum implicit_it_mode
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)
276 static int implicit_it_mode = IMPLICIT_IT_MODE_ARM;
278 /* If unified_syntax is true, we are processing the new unified
279 ARM/Thumb syntax. Important differences from the old ARM mode:
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.
290 Important differences from the old Thumb mode:
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. */
301 static bfd_boolean unified_syntax = FALSE;
303 enum neon_el_type
305 NT_invtype,
306 NT_untyped,
307 NT_integer,
308 NT_float,
309 NT_poly,
310 NT_signed,
311 NT_unsigned
314 struct neon_type_el
316 enum neon_el_type type;
317 unsigned size;
320 #define NEON_MAX_TYPE_ELS 4
322 struct neon_type
324 struct neon_type_el el[NEON_MAX_TYPE_ELS];
325 unsigned elems;
328 enum it_instruction_type
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. */
340 struct arm_it
342 const char * error;
343 unsigned long instruction;
344 int size;
345 int size_req;
346 int cond;
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;
351 struct neon_type vectype;
352 /* Set to the opcode if the instruction needs relaxation.
353 Zero if the instruction is not relaxed. */
354 unsigned long relax;
355 struct
357 bfd_reloc_code_real_type type;
358 expressionS exp;
359 int pc_rel;
360 } reloc;
362 enum it_instruction_type it_insn_type;
364 struct
366 unsigned reg;
367 signed int imm;
368 struct neon_type_el vectype;
369 unsigned present : 1; /* Operand present. */
370 unsigned isreg : 1; /* Operand was a register. */
371 unsigned immisreg : 1; /* .imm field is a second register. */
372 unsigned isscalar : 1; /* Operand is a (Neon) scalar. */
373 unsigned immisalign : 1; /* Immediate is an alignment specifier. */
374 unsigned immisfloat : 1; /* Immediate was parsed as a float. */
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. */
378 unsigned isvec : 1; /* Is a single, double or quad VFP/Neon reg. */
379 unsigned isquad : 1; /* Operand is Neon quad-precision register. */
380 unsigned issingle : 1; /* Operand is VFP single-precision register. */
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). */
388 } operands[6];
391 static struct arm_it inst;
393 #define NUM_FLOAT_VALS 8
395 const char * fp_const[] =
397 "0.0", "1.0", "2.0", "3.0", "4.0", "5.0", "0.5", "10.0", 0
400 /* Number of littlenums required to hold an extended precision number. */
401 #define MAX_LITTLENUMS 6
403 LITTLENUM_TYPE fp_values[NUM_FLOAT_VALS][MAX_LITTLENUMS];
405 #define FAIL (-1)
406 #define SUCCESS (0)
408 #define SUFF_S 1
409 #define SUFF_D 2
410 #define SUFF_E 3
411 #define SUFF_P 4
413 #define CP_T_X 0x00008000
414 #define CP_T_Y 0x00400000
416 #define CONDS_BIT 0x00100000
417 #define LOAD_BIT 0x00100000
419 #define DOUBLE_LOAD_FLAG 0x00000001
421 struct asm_cond
423 const char * template;
424 unsigned long value;
427 #define COND_ALWAYS 0xE
429 struct asm_psr
431 const char *template;
432 unsigned long field;
435 struct asm_barrier_opt
437 const char *template;
438 unsigned long value;
441 /* The bit that distinguishes CPSR and SPSR. */
442 #define SPSR_BIT (1 << 22)
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)
450 struct reloc_entry
452 char *name;
453 bfd_reloc_code_real_type reloc;
456 enum vfp_reg_pos
458 VFP_REG_Sd, VFP_REG_Sm, VFP_REG_Sn,
459 VFP_REG_Dd, VFP_REG_Dm, VFP_REG_Dn
462 enum vfp_ldstm_type
464 VFP_LDSTMIA, VFP_LDSTMDB, VFP_LDSTMIAX, VFP_LDSTMDBX
467 /* Bits for DEFINED field in neon_typed_alias. */
468 #define NTA_HASTYPE 1
469 #define NTA_HASINDEX 2
471 struct neon_typed_alias
473 unsigned char defined;
474 unsigned char index;
475 struct neon_type_el eltype;
478 /* ARM register categories. This includes coprocessor numbers and various
479 architecture extensions' registers. */
480 enum arm_reg_type
482 REG_TYPE_RN,
483 REG_TYPE_CP,
484 REG_TYPE_CN,
485 REG_TYPE_FN,
486 REG_TYPE_VFS,
487 REG_TYPE_VFD,
488 REG_TYPE_NQ,
489 REG_TYPE_VFSD,
490 REG_TYPE_NDQ,
491 REG_TYPE_NSDQ,
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,
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. */
509 struct reg_entry
511 const char *name;
512 unsigned char number;
513 unsigned char type;
514 unsigned char builtin;
515 struct neon_typed_alias *neon;
518 /* Diagnostics used when we don't get a register of the expected type. */
519 const char *const reg_expected_msgs[] =
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"),
526 N_("VFP/Neon double precision register expected"),
527 N_("Neon quad precision register expected"),
528 N_("VFP single or double precision register expected"),
529 N_("Neon double or quad precision register expected"),
530 N_("VFP single, double or Neon quad precision register expected"),
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"),
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
549 /* ARM instructions take 4bytes in the object file, Thumb instructions
550 take 2: */
551 #define INSN_SIZE 4
553 struct asm_opcode
555 /* Basic string to match. */
556 const char *template;
558 /* Parameters to instruction. */
559 unsigned char operands[8];
561 /* Conditional tag - see opcode_lookup. */
562 unsigned int tag : 4;
564 /* Basic instruction code. */
565 unsigned int avalue : 28;
567 /* Thumb-format instruction code. */
568 unsigned int tvalue;
570 /* Which architecture variant provides this instruction. */
571 const arm_feature_set *avariant;
572 const arm_feature_set *tvariant;
574 /* Function to call to encode instruction in ARM format. */
575 void (* aencode) (void);
577 /* Function to call to encode instruction in Thumb format. */
578 void (* tencode) (void);
581 /* Defines for various bits that we will want to toggle. */
582 #define INST_IMMEDIATE 0x02000000
583 #define OFFSET_REG 0x02000000
584 #define HWOFFSET_IMM 0x00400000
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
590 #define CPSI_MMOD 0x00020000
592 #define LITERAL_MASK 0xf000f000
593 #define OPCODE_MASK 0xfe1fffff
594 #define V4_STR_BIT 0x00000020
596 #define T2_SUBS_PC_LR 0xf3de8f00
598 #define DATA_OP_SHIFT 21
600 #define T2_OPCODE_MASK 0xfe1fffff
601 #define T2_DATA_OP_SHIFT 21
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
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
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
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
650 #define T_OPCODE_ASR_R 0x4100
651 #define T_OPCODE_LSL_R 0x4080
652 #define T_OPCODE_LSR_R 0x40c0
653 #define T_OPCODE_ROR_R 0x41c0
654 #define T_OPCODE_ASR_I 0x1000
655 #define T_OPCODE_LSL_I 0x0000
656 #define T_OPCODE_LSR_I 0x0800
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
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
680 #define T_OPCODE_PUSH 0xb400
681 #define T_OPCODE_POP 0xbc00
683 #define T_OPCODE_BRANCH 0xe000
685 #define THUMB_SIZE 2 /* Size of thumb instruction. */
686 #define THUMB_PP_PC_LR 0x0100
687 #define THUMB_LOAD_BIT 0x0800
688 #define THUMB2_LOAD_BIT 0x00100000
690 #define BAD_ARGS _("bad arguments to instruction")
691 #define BAD_SP _("r13 not allowed here")
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")
697 #define BAD_ADDR_MODE _("instruction does not accept this addressing mode");
698 #define BAD_BRANCH _("branch must be last instruction in IT block")
699 #define BAD_NOT_IT _("instruction not allowed in IT block")
700 #define BAD_FPU _("selected FPU does not support instruction")
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")
704 #define MISSING_FNSTART _("missing .fnstart before unwinding directive")
706 static struct hash_control *arm_ops_hsh;
707 static struct hash_control *arm_cond_hsh;
708 static struct hash_control *arm_shift_hsh;
709 static struct hash_control *arm_psr_hsh;
710 static struct hash_control *arm_v7m_psr_hsh;
711 static struct hash_control *arm_reg_hsh;
712 static struct hash_control *arm_reloc_hsh;
713 static struct hash_control *arm_barrier_opt_hsh;
715 /* Stuff needed to resolve the label ambiguity
718 label: <insn>
719 may differ from:
721 label:
722 <insn> */
724 symbolS * last_label_seen;
725 static int label_is_thumb_function_name = FALSE;
727 /* Literal pool structure. Held on a per-section
728 and per-sub-section basis. */
730 #define MAX_LITERAL_POOL_SIZE 1024
731 typedef struct literal_pool
733 expressionS literals [MAX_LITERAL_POOL_SIZE];
734 unsigned int next_free_entry;
735 unsigned int id;
736 symbolS * symbol;
737 segT section;
738 subsegT sub_section;
739 struct literal_pool * next;
740 } literal_pool;
742 /* Pointer to a linked list of literal pools. */
743 literal_pool * list_of_pools = NULL;
745 #ifdef OBJ_ELF
746 # define now_it seg_info (now_seg)->tc_segment_info_data.current_it
747 #else
748 static struct current_it now_it;
749 #endif
751 static inline int
752 now_it_compatible (int cond)
754 return (cond & ~1) == (now_it.cc & ~1);
757 static inline int
758 conditional_insn (void)
760 return inst.cond != COND_ALWAYS;
763 static int in_it_block (void);
765 static int handle_it_state (void);
767 static void force_automatic_it_block_close (void);
769 #define set_it_insn_type(type) \
770 do \
772 inst.it_insn_type = type; \
773 if (handle_it_state () == FAIL) \
774 return; \
776 while (0)
778 #define set_it_insn_type_last() \
779 do \
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); \
786 while (0)
788 /* Pure syntax. */
790 /* This array holds the chars that always start a comment. If the
791 pre-processor is disabled, these aren't very useful. */
792 const char comment_chars[] = "@";
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. */
801 const char line_comment_chars[] = "#";
803 const char line_separator_chars[] = ";";
805 /* Chars that can be used to separate mant
806 from exp in floating point numbers. */
807 const char EXP_CHARS[] = "eE";
809 /* Chars that mean this number is a floating point constant. */
810 /* As in 0f12.456 */
811 /* or 0d1.2345e12 */
813 const char FLT_CHARS[] = "rRsSfFdDxXeEpP";
815 /* Prefix characters that indicate the start of an immediate
816 value. */
817 #define is_immediate_prefix(C) ((C) == '#' || (C) == '$')
819 /* Separator character handling. */
821 #define skip_whitespace(str) do { if (*(str) == ' ') ++(str); } while (0)
823 static inline int
824 skip_past_char (char ** str, char c)
826 if (**str == c)
828 (*str)++;
829 return SUCCESS;
831 else
832 return FAIL;
834 #define skip_past_comma(str) skip_past_char (str, ',')
836 /* Arithmetic expressions (possibly involving symbols). */
838 /* Return TRUE if anything in the expression is a bignum. */
840 static int
841 walk_no_bignums (symbolS * sp)
843 if (symbol_get_value_expression (sp)->X_op == O_big)
844 return 1;
846 if (symbol_get_value_expression (sp)->X_add_symbol)
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)));
853 return 0;
856 static int in_my_get_expression = 0;
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
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
866 static int
867 my_get_expression (expressionS * ep, char ** str, int prefix_mode)
869 char * save_in;
870 segT seg;
872 /* In unified syntax, all prefixes are optional. */
873 if (unified_syntax)
874 prefix_mode = (prefix_mode == GE_OPT_PREFIX_BIG) ? prefix_mode
875 : GE_OPT_PREFIX;
877 switch (prefix_mode)
879 case GE_NO_PREFIX: break;
880 case GE_IMM_PREFIX:
881 if (!is_immediate_prefix (**str))
883 inst.error = _("immediate expression requires a # prefix");
884 return FAIL;
886 (*str)++;
887 break;
888 case GE_OPT_PREFIX:
889 case GE_OPT_PREFIX_BIG:
890 if (is_immediate_prefix (**str))
891 (*str)++;
892 break;
893 default: abort ();
896 memset (ep, 0, sizeof (expressionS));
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;
904 if (ep->X_op == O_illegal)
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;
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)
921 inst.error = _("bad segment");
922 *str = input_line_pointer;
923 input_line_pointer = save_in;
924 return 1;
926 #endif
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. */
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))))))
938 inst.error = _("invalid constant");
939 *str = input_line_pointer;
940 input_line_pointer = save_in;
941 return 1;
944 *str = input_line_pointer;
945 input_line_pointer = save_in;
946 return 0;
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.
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.
961 ??? The format of 12 byte floats is uncertain according to gcc's arm.h. */
963 char *
964 md_atof (int type, char * litP, int * sizeP)
966 int prec;
967 LITTLENUM_TYPE words[MAX_LITTLENUMS];
968 char *t;
969 int i;
971 switch (type)
973 case 'f':
974 case 'F':
975 case 's':
976 case 'S':
977 prec = 2;
978 break;
980 case 'd':
981 case 'D':
982 case 'r':
983 case 'R':
984 prec = 4;
985 break;
987 case 'x':
988 case 'X':
989 prec = 5;
990 break;
992 case 'p':
993 case 'P':
994 prec = 5;
995 break;
997 default:
998 *sizeP = 0;
999 return _("Unrecognized or unsupported floating point constant");
1002 t = atof_ieee (input_line_pointer, type, words);
1003 if (t)
1004 input_line_pointer = t;
1005 *sizeP = prec * sizeof (LITTLENUM_TYPE);
1007 if (target_big_endian)
1009 for (i = 0; i < prec; i++)
1011 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1012 litP += sizeof (LITTLENUM_TYPE);
1015 else
1017 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
1018 for (i = prec - 1; i >= 0; i--)
1020 md_number_to_chars (litP, (valueT) words[i], sizeof (LITTLENUM_TYPE));
1021 litP += sizeof (LITTLENUM_TYPE);
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)
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);
1036 return NULL;
1039 /* We handle all bad expressions here, so that we can report the faulty
1040 instruction in the error message. */
1041 void
1042 md_operand (expressionS * expr)
1044 if (in_my_get_expression)
1045 expr->X_op = O_illegal;
1048 /* Immediate values. */
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
1054 static int
1055 immediate_for_directive (int *val)
1057 expressionS exp;
1058 exp.X_op = O_illegal;
1060 if (is_immediate_prefix (*input_line_pointer))
1062 input_line_pointer++;
1063 expression (&exp);
1066 if (exp.X_op != O_constant)
1068 as_bad (_("expected #constant"));
1069 ignore_rest_of_line ();
1070 return FAIL;
1072 *val = exp.X_add_number;
1073 return SUCCESS;
1075 #endif
1077 /* Register parsing. */
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. */
1084 static struct reg_entry *
1085 arm_reg_parse_multi (char **ccp)
1087 char *start = *ccp;
1088 char *p;
1089 struct reg_entry *reg;
1091 #ifdef REGISTER_PREFIX
1092 if (*start != REGISTER_PREFIX)
1093 return NULL;
1094 start++;
1095 #endif
1096 #ifdef OPTIONAL_REGISTER_PREFIX
1097 if (*start == OPTIONAL_REGISTER_PREFIX)
1098 start++;
1099 #endif
1101 p = start;
1102 if (!ISALPHA (*p) || !is_name_beginner (*p))
1103 return NULL;
1106 p++;
1107 while (ISALPHA (*p) || ISDIGIT (*p) || *p == '_');
1109 reg = (struct reg_entry *) hash_find_n (arm_reg_hsh, start, p - start);
1111 if (!reg)
1112 return NULL;
1114 *ccp = p;
1115 return reg;
1118 static int
1119 arm_reg_alt_syntax (char **ccp, char *start, struct reg_entry *reg,
1120 enum arm_reg_type type)
1122 /* Alternative syntaxes are accepted for a few register classes. */
1123 switch (type)
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. */
1130 if (reg && reg->type == REG_TYPE_CN)
1131 return reg->number;
1132 break;
1134 case REG_TYPE_CP:
1135 /* For backward compatibility, a bare number is valid here. */
1137 unsigned long processor = strtoul (start, ccp, 10);
1138 if (*ccp != start && processor <= 15)
1139 return processor;
1142 case REG_TYPE_MMXWC:
1143 /* WC includes WCG. ??? I'm not sure this is true for all
1144 instructions that take WC registers. */
1145 if (reg && reg->type == REG_TYPE_MMXWCG)
1146 return reg->number;
1147 break;
1149 default:
1150 break;
1153 return FAIL;
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. */
1159 static int
1160 arm_reg_parse (char **ccp, enum arm_reg_type type)
1162 char *start = *ccp;
1163 struct reg_entry *reg = arm_reg_parse_multi (ccp);
1164 int ret;
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;
1170 if (reg && reg->type == type)
1171 return reg->number;
1173 if ((ret = arm_reg_alt_syntax (ccp, start, reg, type)) != FAIL)
1174 return ret;
1176 *ccp = start;
1177 return FAIL;
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.,
1184 .i32.i32.s16
1185 .s32.f32
1186 .u16
1188 Can all be legally parsed by this function.
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. */
1194 static int
1195 parse_neon_type (struct neon_type *type, char **str)
1197 char *ptr = *str;
1199 if (type)
1200 type->elems = 0;
1202 while (type->elems < NEON_MAX_TYPE_ELS)
1204 enum neon_el_type thistype = NT_untyped;
1205 unsigned thissize = -1u;
1207 if (*ptr != '.')
1208 break;
1210 ptr++;
1212 /* Just a size without an explicit type. */
1213 if (ISDIGIT (*ptr))
1214 goto parsesize;
1216 switch (TOLOWER (*ptr))
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;
1223 case 'd':
1224 thistype = NT_float;
1225 thissize = 64;
1226 ptr++;
1227 goto done;
1228 default:
1229 as_bad (_("unexpected character `%c' in type specifier"), *ptr);
1230 return FAIL;
1233 ptr++;
1235 /* .f is an abbreviation for .f32. */
1236 if (thistype == NT_float && !ISDIGIT (*ptr))
1237 thissize = 32;
1238 else
1240 parsesize:
1241 thissize = strtoul (ptr, &ptr, 10);
1243 if (thissize != 8 && thissize != 16 && thissize != 32
1244 && thissize != 64)
1246 as_bad (_("bad size %d in type specifier"), thissize);
1247 return FAIL;
1251 done:
1252 if (type)
1254 type->el[type->elems].type = thistype;
1255 type->el[type->elems].size = thissize;
1256 type->elems++;
1260 /* Empty/missing type is not a successful parse. */
1261 if (type->elems == 0)
1262 return FAIL;
1264 *str = ptr;
1266 return SUCCESS;
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. */
1274 static void
1275 first_error (const char *err)
1277 if (!inst.error)
1278 inst.error = err;
1281 /* Parse a single type, e.g. ".s32", leading period included. */
1282 static int
1283 parse_neon_operand_type (struct neon_type_el *vectype, char **ccp)
1285 char *str = *ccp;
1286 struct neon_type optype;
1288 if (*str == '.')
1290 if (parse_neon_type (&optype, &str) == SUCCESS)
1292 if (optype.elems == 1)
1293 *vectype = optype.el[0];
1294 else
1296 first_error (_("only one type should be specified for operand"));
1297 return FAIL;
1300 else
1302 first_error (_("vector type expected"));
1303 return FAIL;
1306 else
1307 return FAIL;
1309 *ccp = str;
1311 return SUCCESS;
1314 /* Special meanings for indices (which have a range of 0-7), which will fit into
1315 a 4-bit integer. */
1317 #define NEON_ALL_LANES 15
1318 #define NEON_INTERLEAVE_LANES 14
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. */
1325 static int
1326 parse_typed_reg_or_scalar (char **ccp, enum arm_reg_type type,
1327 enum arm_reg_type *rtype,
1328 struct neon_typed_alias *typeinfo)
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;
1335 atype.defined = 0;
1336 atype.index = -1;
1337 atype.eltype.type = NT_invtype;
1338 atype.eltype.size = -1;
1340 /* Try alternate syntax for some types of register. Note these are mutually
1341 exclusive with the Neon syntax extensions. */
1342 if (reg == NULL)
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;
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
1359 || reg->type == REG_TYPE_NQ))
1360 || (type == REG_TYPE_MMXWC
1361 && (reg->type == REG_TYPE_MMXWCG)))
1362 type = reg->type;
1364 if (type != reg->type)
1365 return FAIL;
1367 if (reg->neon)
1368 atype = *reg->neon;
1370 if (parse_neon_operand_type (&parsetype, &str) == SUCCESS)
1372 if ((atype.defined & NTA_HASTYPE) != 0)
1374 first_error (_("can't redefine type for operand"));
1375 return FAIL;
1377 atype.defined |= NTA_HASTYPE;
1378 atype.eltype = parsetype;
1381 if (skip_past_char (&str, '[') == SUCCESS)
1383 if (type != REG_TYPE_VFD)
1385 first_error (_("only D registers may be indexed"));
1386 return FAIL;
1389 if ((atype.defined & NTA_HASINDEX) != 0)
1391 first_error (_("can't change index for operand"));
1392 return FAIL;
1395 atype.defined |= NTA_HASINDEX;
1397 if (skip_past_char (&str, ']') == SUCCESS)
1398 atype.index = NEON_ALL_LANES;
1399 else
1401 expressionS exp;
1403 my_get_expression (&exp, &str, GE_NO_PREFIX);
1405 if (exp.X_op != O_constant)
1407 first_error (_("constant expression required"));
1408 return FAIL;
1411 if (skip_past_char (&str, ']') == FAIL)
1412 return FAIL;
1414 atype.index = exp.X_add_number;
1418 if (typeinfo)
1419 *typeinfo = atype;
1421 if (rtype)
1422 *rtype = type;
1424 *ccp = str;
1426 return reg->number;
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).
1434 This function will fault on encountering a scalar. */
1436 static int
1437 arm_typed_reg_parse (char **ccp, enum arm_reg_type type,
1438 enum arm_reg_type *rtype, struct neon_type_el *vectype)
1440 struct neon_typed_alias atype;
1441 char *str = *ccp;
1442 int reg = parse_typed_reg_or_scalar (&str, type, rtype, &atype);
1444 if (reg == FAIL)
1445 return FAIL;
1447 /* Do not allow a scalar (reg+index) to parse as a register. */
1448 if ((atype.defined & NTA_HASINDEX) != 0)
1450 first_error (_("register operand expected, but got scalar"));
1451 return FAIL;
1454 if (vectype)
1455 *vectype = atype.eltype;
1457 *ccp = str;
1459 return reg;
1462 #define NEON_SCALAR_REG(X) ((X) >> 4)
1463 #define NEON_SCALAR_INDEX(X) ((X) & 15)
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. */
1469 static int
1470 parse_scalar (char **ccp, int elsize, struct neon_type_el *type)
1472 int reg;
1473 char *str = *ccp;
1474 struct neon_typed_alias atype;
1476 reg = parse_typed_reg_or_scalar (&str, REG_TYPE_VFD, NULL, &atype);
1478 if (reg == FAIL || (atype.defined & NTA_HASINDEX) == 0)
1479 return FAIL;
1481 if (atype.index == NEON_ALL_LANES)
1483 first_error (_("scalar must have an index"));
1484 return FAIL;
1486 else if (atype.index >= 64 / elsize)
1488 first_error (_("scalar index out of range"));
1489 return FAIL;
1492 if (type)
1493 *type = atype.eltype;
1495 *ccp = str;
1497 return reg * 16 + atype.index;
1500 /* Parse an ARM register list. Returns the bitmask, or FAIL. */
1502 static long
1503 parse_reg_list (char ** strp)
1505 char * str = * strp;
1506 long range = 0;
1507 int another_range;
1509 /* We come back here if we get ranges concatenated by '+' or '|'. */
1512 another_range = 0;
1514 if (*str == '{')
1516 int in_range = 0;
1517 int cur_reg = -1;
1519 str++;
1522 int reg;
1524 if ((reg = arm_reg_parse (&str, REG_TYPE_RN)) == FAIL)
1526 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
1527 return FAIL;
1530 if (in_range)
1532 int i;
1534 if (reg <= cur_reg)
1536 first_error (_("bad range in register list"));
1537 return FAIL;
1540 for (i = cur_reg + 1; i < reg; i++)
1542 if (range & (1 << i))
1543 as_tsktsk
1544 (_("Warning: duplicated register (r%d) in register list"),
1546 else
1547 range |= 1 << i;
1549 in_range = 0;
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"));
1558 range |= 1 << reg;
1559 cur_reg = reg;
1561 while (skip_past_comma (&str) != FAIL
1562 || (in_range = 1, *str++ == '-'));
1563 str--;
1565 if (*str++ != '}')
1567 first_error (_("missing `}'"));
1568 return FAIL;
1571 else
1573 expressionS expr;
1575 if (my_get_expression (&expr, &str, GE_NO_PREFIX))
1576 return FAIL;
1578 if (expr.X_op == O_constant)
1580 if (expr.X_add_number
1581 != (expr.X_add_number & 0x0000ffff))
1583 inst.error = _("invalid register mask");
1584 return FAIL;
1587 if ((range & expr.X_add_number) != 0)
1589 int regno = range & expr.X_add_number;
1591 regno &= -regno;
1592 regno = (1 << regno) - 1;
1593 as_tsktsk
1594 (_("Warning: duplicated register (r%d) in register list"),
1595 regno);
1598 range |= expr.X_add_number;
1600 else
1602 if (inst.reloc.type != 0)
1604 inst.error = _("expression too complex");
1605 return FAIL;
1608 memcpy (&inst.reloc.exp, &expr, sizeof (expressionS));
1609 inst.reloc.type = BFD_RELOC_ARM_MULTI;
1610 inst.reloc.pc_rel = 0;
1614 if (*str == '|' || *str == '+')
1616 str++;
1617 another_range = 1;
1620 while (another_range);
1622 *strp = str;
1623 return range;
1626 /* Types of registers in a list. */
1628 enum reg_list_els
1630 REGLIST_VFP_S,
1631 REGLIST_VFP_D,
1632 REGLIST_NEON_D
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
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.
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. */
1650 static int
1651 parse_vfp_reg_list (char **ccp, unsigned int *pbase, enum reg_list_els etype)
1653 char *str = *ccp;
1654 int base_reg;
1655 int new_base;
1656 enum arm_reg_type regtype = 0;
1657 int max_regs = 0;
1658 int count = 0;
1659 int warned = 0;
1660 unsigned long mask = 0;
1661 int i;
1663 if (*str != '{')
1665 inst.error = _("expecting {");
1666 return FAIL;
1669 str++;
1671 switch (etype)
1673 case REGLIST_VFP_S:
1674 regtype = REG_TYPE_VFS;
1675 max_regs = 32;
1676 break;
1678 case REGLIST_VFP_D:
1679 regtype = REG_TYPE_VFD;
1680 break;
1682 case REGLIST_NEON_D:
1683 regtype = REG_TYPE_NDQ;
1684 break;
1687 if (etype != REGLIST_VFP_S)
1689 /* VFPv3 allows 32 D registers, except for the VFPv3-D16 variant. */
1690 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
1692 max_regs = 32;
1693 if (thumb_mode)
1694 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
1695 fpu_vfp_ext_d32);
1696 else
1697 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
1698 fpu_vfp_ext_d32);
1700 else
1701 max_regs = 16;
1704 base_reg = max_regs;
1708 int setmask = 1, addregs = 1;
1710 new_base = arm_typed_reg_parse (&str, regtype, &regtype, NULL);
1712 if (new_base == FAIL)
1714 first_error (_(reg_expected_msgs[regtype]));
1715 return FAIL;
1718 if (new_base >= max_regs)
1720 first_error (_("register out of range in list"));
1721 return FAIL;
1724 /* Note: a value of 2 * n is returned for the register Q<n>. */
1725 if (regtype == REG_TYPE_NQ)
1727 setmask = 3;
1728 addregs = 2;
1731 if (new_base < base_reg)
1732 base_reg = new_base;
1734 if (mask & (setmask << new_base))
1736 first_error (_("invalid register list"));
1737 return FAIL;
1740 if ((mask >> new_base) != 0 && ! warned)
1742 as_tsktsk (_("register list not in ascending order"));
1743 warned = 1;
1746 mask |= setmask << new_base;
1747 count += addregs;
1749 if (*str == '-') /* We have the start of a range expression */
1751 int high_range;
1753 str++;
1755 if ((high_range = arm_typed_reg_parse (&str, regtype, NULL, NULL))
1756 == FAIL)
1758 inst.error = gettext (reg_expected_msgs[regtype]);
1759 return FAIL;
1762 if (high_range >= max_regs)
1764 first_error (_("register out of range in list"));
1765 return FAIL;
1768 if (regtype == REG_TYPE_NQ)
1769 high_range = high_range + 1;
1771 if (high_range <= new_base)
1773 inst.error = _("register range not in ascending order");
1774 return FAIL;
1777 for (new_base += addregs; new_base <= high_range; new_base += addregs)
1779 if (mask & (setmask << new_base))
1781 inst.error = _("invalid register list");
1782 return FAIL;
1785 mask |= setmask << new_base;
1786 count += addregs;
1790 while (skip_past_comma (&str) != FAIL);
1792 str++;
1794 /* Sanity check -- should have raised a parse error above. */
1795 if (count == 0 || count > max_regs)
1796 abort ();
1798 *pbase = base_reg;
1800 /* Final test -- the registers must be consecutive. */
1801 mask >>= base_reg;
1802 for (i = 0; i < count; i++)
1804 if ((mask & (1u << i)) == 0)
1806 inst.error = _("non-contiguous register range");
1807 return FAIL;
1811 *ccp = str;
1813 return count;
1816 /* True if two alias types are the same. */
1818 static int
1819 neon_alias_types_same (struct neon_typed_alias *a, struct neon_typed_alias *b)
1821 if (!a && !b)
1822 return 1;
1824 if (!a || !b)
1825 return 0;
1827 if (a->defined != b->defined)
1828 return 0;
1830 if ((a->defined & NTA_HASTYPE) != 0
1831 && (a->eltype.type != b->eltype.type
1832 || a->eltype.size != b->eltype.size))
1833 return 0;
1835 if ((a->defined & NTA_HASINDEX) != 0
1836 && (a->index != b->index))
1837 return 0;
1839 return 1;
1842 /* Parse element/structure lists for Neon VLD<n> and VST<n> instructions.
1843 The base register is put in *PBASE.
1844 The lane (or one of the NEON_*_LANES constants) is placed in bits [3:0] of
1845 the return value.
1846 The register stride (minus one) is put in bit 4 of the return value.
1847 Bits [6:5] encode the list length (minus one).
1848 The type of the list elements is put in *ELTYPE, if non-NULL. */
1850 #define NEON_LANE(X) ((X) & 0xf)
1851 #define NEON_REG_STRIDE(X) ((((X) >> 4) & 1) + 1)
1852 #define NEON_REGLIST_LENGTH(X) ((((X) >> 5) & 3) + 1)
1854 static int
1855 parse_neon_el_struct_list (char **str, unsigned *pbase,
1856 struct neon_type_el *eltype)
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";
1868 struct neon_typed_alias firsttype;
1870 if (skip_past_char (&ptr, '{') == SUCCESS)
1871 leading_brace = 1;
1875 struct neon_typed_alias atype;
1876 int getreg = parse_typed_reg_or_scalar (&ptr, rtype, &rtype, &atype);
1878 if (getreg == FAIL)
1880 first_error (_(reg_expected_msgs[rtype]));
1881 return FAIL;
1884 if (base_reg == -1)
1886 base_reg = getreg;
1887 if (rtype == REG_TYPE_NQ)
1889 reg_incr = 1;
1890 addregs = 2;
1892 firsttype = atype;
1894 else if (reg_incr == -1)
1896 reg_incr = getreg - base_reg;
1897 if (reg_incr < 1 || reg_incr > 2)
1899 first_error (_(incr_error));
1900 return FAIL;
1903 else if (getreg != base_reg + reg_incr * count)
1905 first_error (_(incr_error));
1906 return FAIL;
1909 if (!neon_alias_types_same (&atype, &firsttype))
1911 first_error (_(type_error));
1912 return FAIL;
1915 /* Handle Dn-Dm or Qn-Qm syntax. Can only be used with non-indexed list
1916 modes. */
1917 if (ptr[0] == '-')
1919 struct neon_typed_alias htype;
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)
1925 first_error (_(type_error));
1926 return FAIL;
1928 if (reg_incr == -1)
1929 reg_incr = 1;
1930 else if (reg_incr != 1)
1932 first_error (_("don't use Rn-Rm syntax with non-unit stride"));
1933 return FAIL;
1935 ptr++;
1936 hireg = parse_typed_reg_or_scalar (&ptr, rtype, NULL, &htype);
1937 if (hireg == FAIL)
1939 first_error (_(reg_expected_msgs[rtype]));
1940 return FAIL;
1942 if (!neon_alias_types_same (&htype, &firsttype))
1944 first_error (_(type_error));
1945 return FAIL;
1947 count += hireg + dregs - getreg;
1948 continue;
1951 /* If we're using Q registers, we can't use [] or [n] syntax. */
1952 if (rtype == REG_TYPE_NQ)
1954 count += 2;
1955 continue;
1958 if ((atype.defined & NTA_HASINDEX) != 0)
1960 if (lane == -1)
1961 lane = atype.index;
1962 else if (lane != atype.index)
1964 first_error (_(type_error));
1965 return FAIL;
1968 else if (lane == -1)
1969 lane = NEON_INTERLEAVE_LANES;
1970 else if (lane != NEON_INTERLEAVE_LANES)
1972 first_error (_(type_error));
1973 return FAIL;
1975 count++;
1977 while ((count != 1 || leading_brace) && skip_past_comma (&ptr) != FAIL);
1979 /* No lane set by [x]. We must be interleaving structures. */
1980 if (lane == -1)
1981 lane = NEON_INTERLEAVE_LANES;
1983 /* Sanity check. */
1984 if (lane == -1 || base_reg == -1 || count < 1 || count > 4
1985 || (count > 1 && reg_incr == -1))
1987 first_error (_("error parsing element/structure list"));
1988 return FAIL;
1991 if ((count > 1 || leading_brace) && skip_past_char (&ptr, '}') == FAIL)
1993 first_error (_("expected }"));
1994 return FAIL;
1997 if (reg_incr == -1)
1998 reg_incr = 1;
2000 if (eltype)
2001 *eltype = firsttype.eltype;
2003 *pbase = base_reg;
2004 *str = ptr;
2006 return lane | ((reg_incr - 1) << 4) | ((count - 1) << 5);
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. */
2014 static int
2015 parse_reloc (char **str)
2017 struct reloc_entry *r;
2018 char *p, *q;
2020 if (**str != '(')
2021 return BFD_RELOC_UNUSED;
2023 p = *str + 1;
2024 q = p;
2026 while (*q && *q != ')' && *q != ',')
2027 q++;
2028 if (*q != ')')
2029 return -1;
2031 if ((r = hash_find_n (arm_reloc_hsh, p, q - p)) == NULL)
2032 return -1;
2034 *str = q + 1;
2035 return r->reloc;
2038 /* Directives: register aliases. */
2040 static struct reg_entry *
2041 insert_reg_alias (char *str, int number, int type)
2043 struct reg_entry *new;
2044 const char *name;
2046 if ((new = hash_find (arm_reg_hsh, str)) != 0)
2048 if (new->builtin)
2049 as_warn (_("ignoring attempt to redefine built-in register '%s'"), str);
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);
2056 return NULL;
2059 name = xstrdup (str);
2060 new = xmalloc (sizeof (struct reg_entry));
2062 new->name = name;
2063 new->number = number;
2064 new->type = type;
2065 new->builtin = FALSE;
2066 new->neon = NULL;
2068 if (hash_insert (arm_reg_hsh, name, (void *) new))
2069 abort ();
2071 return new;
2074 static void
2075 insert_neon_reg_alias (char *str, int number, int type,
2076 struct neon_typed_alias *atype)
2078 struct reg_entry *reg = insert_reg_alias (str, number, type);
2080 if (!reg)
2082 first_error (_("attempt to redefine typed alias"));
2083 return;
2086 if (atype)
2088 reg->neon = xmalloc (sizeof (struct neon_typed_alias));
2089 *reg->neon = *atype;
2093 /* Look for the .req directive. This is of the form:
2095 new_register_name .req existing_register_name
2097 If we find one, or if it looks sufficiently like one that we want to
2098 handle any error here, return TRUE. Otherwise return FALSE. */
2100 static bfd_boolean
2101 create_register_alias (char * newname, char *p)
2103 struct reg_entry *old;
2104 char *oldname, *nbuf;
2105 size_t nlen;
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)
2111 return FALSE;
2113 oldname += 6;
2114 if (*oldname == '\0')
2115 return FALSE;
2117 old = hash_find (arm_reg_hsh, oldname);
2118 if (!old)
2120 as_warn (_("unknown register '%s' -- .req ignored"), oldname);
2121 return TRUE;
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
2134 nbuf = alloca (nlen + 1);
2135 memcpy (nbuf, newname, nlen);
2136 nbuf[nlen] = '\0';
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. */
2141 if (insert_reg_alias (nbuf, old->number, old->type) != NULL)
2143 for (p = nbuf; *p; p++)
2144 *p = TOUPPER (*p);
2146 if (strncmp (nbuf, newname, nlen))
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
2155 the artificial FOO alias because it has already been created by the
2156 first .req. */
2157 if (insert_reg_alias (nbuf, old->number, old->type) == NULL)
2158 return TRUE;
2161 for (p = nbuf; *p; p++)
2162 *p = TOLOWER (*p);
2164 if (strncmp (nbuf, newname, nlen))
2165 insert_reg_alias (nbuf, old->number, old->type);
2168 return TRUE;
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.:
2179 vadd d0.s32, d1.s32, d2.s32 */
2181 static int
2182 create_neon_reg_alias (char *newname, char *p)
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;
2192 typeinfo.defined = 0;
2193 typeinfo.eltype.type = NT_invtype;
2194 typeinfo.eltype.size = -1;
2195 typeinfo.index = -1;
2197 nameend = p;
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;
2206 p += 5;
2208 if (*p == '\0')
2209 return 0;
2211 basereg = arm_reg_parse_multi (&p);
2213 if (basereg && basereg->type != basetype)
2215 as_bad (_("bad type for register"));
2216 return 0;
2219 if (basereg == NULL)
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)
2226 as_bad (_("expression must be constant"));
2227 return 0;
2229 basereg = &mybasereg;
2230 basereg->number = (basetype == REG_TYPE_NQ) ? exp.X_add_number * 2
2231 : exp.X_add_number;
2232 basereg->neon = 0;
2235 if (basereg->neon)
2236 typeinfo = *basereg->neon;
2238 if (parse_neon_type (&ntype, &p) == SUCCESS)
2240 /* We got a type. */
2241 if (typeinfo.defined & NTA_HASTYPE)
2243 as_bad (_("can't redefine the type of a register alias"));
2244 return 0;
2247 typeinfo.defined |= NTA_HASTYPE;
2248 if (ntype.elems != 1)
2250 as_bad (_("you must specify a single type only"));
2251 return 0;
2253 typeinfo.eltype = ntype.el[0];
2256 if (skip_past_char (&p, '[') == SUCCESS)
2258 expressionS exp;
2259 /* We got a scalar index. */
2261 if (typeinfo.defined & NTA_HASINDEX)
2263 as_bad (_("can't redefine the index of a scalar alias"));
2264 return 0;
2267 my_get_expression (&exp, &p, GE_NO_PREFIX);
2269 if (exp.X_op != O_constant)
2271 as_bad (_("scalar index must be constant"));
2272 return 0;
2275 typeinfo.defined |= NTA_HASINDEX;
2276 typeinfo.index = exp.X_add_number;
2278 if (skip_past_char (&p, ']') == FAIL)
2280 as_bad (_("expecting ]"));
2281 return 0;
2285 namelen = nameend - newname;
2286 namebuf = alloca (namelen + 1);
2287 strncpy (namebuf, newname, namelen);
2288 namebuf[namelen] = '\0';
2290 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2291 typeinfo.defined != 0 ? &typeinfo : NULL);
2293 /* Insert name in all uppercase. */
2294 for (p = namebuf; *p; p++)
2295 *p = TOUPPER (*p);
2297 if (strncmp (namebuf, newname, namelen))
2298 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2299 typeinfo.defined != 0 ? &typeinfo : NULL);
2301 /* Insert name in all lowercase. */
2302 for (p = namebuf; *p; p++)
2303 *p = TOLOWER (*p);
2305 if (strncmp (namebuf, newname, namelen))
2306 insert_neon_reg_alias (namebuf, basereg->number, basetype,
2307 typeinfo.defined != 0 ? &typeinfo : NULL);
2309 return 1;
2312 /* Should never be called, as .req goes between the alias and the
2313 register name, not at the beginning of the line. */
2314 static void
2315 s_req (int a ATTRIBUTE_UNUSED)
2317 as_bad (_("invalid syntax for .req directive"));
2320 static void
2321 s_dn (int a ATTRIBUTE_UNUSED)
2323 as_bad (_("invalid syntax for .dn directive"));
2326 static void
2327 s_qn (int a ATTRIBUTE_UNUSED)
2329 as_bad (_("invalid syntax for .qn directive"));
2332 /* The .unreq directive deletes an alias which was previously defined
2333 by .req. For example:
2335 my_alias .req r11
2336 .unreq my_alias */
2338 static void
2339 s_unreq (int a ATTRIBUTE_UNUSED)
2341 char * name;
2342 char saved_char;
2344 name = input_line_pointer;
2346 while (*input_line_pointer != 0
2347 && *input_line_pointer != ' '
2348 && *input_line_pointer != '\n')
2349 ++input_line_pointer;
2351 saved_char = *input_line_pointer;
2352 *input_line_pointer = 0;
2354 if (!*name)
2355 as_bad (_("invalid syntax for .unreq directive"));
2356 else
2358 struct reg_entry *reg = hash_find (arm_reg_hsh, name);
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
2367 char * p;
2368 char * nbuf;
2370 hash_delete (arm_reg_hsh, name, FALSE);
2371 free ((char *) reg->name);
2372 if (reg->neon)
2373 free (reg->neon);
2374 free (reg);
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. */
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)
2386 hash_delete (arm_reg_hsh, nbuf, FALSE);
2387 free ((char *) reg->name);
2388 if (reg->neon)
2389 free (reg->neon);
2390 free (reg);
2393 for (p = nbuf; *p; p++)
2394 *p = TOLOWER (*p);
2395 reg = hash_find (arm_reg_hsh, nbuf);
2396 if (reg)
2398 hash_delete (arm_reg_hsh, nbuf, FALSE);
2399 free ((char *) reg->name);
2400 if (reg->neon)
2401 free (reg->neon);
2402 free (reg);
2405 free (nbuf);
2409 *input_line_pointer = saved_char;
2410 demand_empty_rest_of_line ();
2413 /* Directives: Instruction set selection. */
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. */
2421 static enum mstate mapstate = MAP_UNDEFINED;
2423 void
2424 mapping_state (enum mstate state)
2426 symbolS * symbolP;
2427 const char * symname;
2428 int type;
2430 if (mapstate == state)
2431 /* The mapping symbol has already been emitted.
2432 There is nothing else to do. */
2433 return;
2435 mapstate = state;
2437 switch (state)
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 ();
2457 seg_info (now_seg)->tc_segment_info_data.mapstate = state;
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;
2463 switch (state)
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;
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;
2477 case MAP_DATA:
2478 default:
2479 return;
2482 #else
2483 #define mapping_state(x) /* nothing */
2484 #endif
2486 /* Find the real, Thumb encoded start of a Thumb function. */
2488 #ifdef OBJ_COFF
2489 static symbolS *
2490 find_real_start (symbolS * symbolP)
2492 char * real_start;
2493 const char * name = S_GET_NAME (symbolP);
2494 symbolS * new_target;
2496 /* This definition must agree with the one in gcc/config/arm/thumb.c. */
2497 #define STUB_NAME ".real_start_of"
2499 if (name == NULL)
2500 abort ();
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] == '.')
2508 return symbolP;
2510 real_start = ACONCAT ((STUB_NAME, name, NULL));
2511 new_target = symbol_find (real_start);
2513 if (new_target == NULL)
2515 as_warn (_("Failed to find real start of function: %s\n"), name);
2516 new_target = symbolP;
2519 return new_target;
2521 #endif
2523 static void
2524 opcode_select (int width)
2526 switch (width)
2528 case 16:
2529 if (! thumb_mode)
2531 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
2532 as_bad (_("selected processor does not support THUMB opcodes"));
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);
2539 mapping_state (MAP_THUMB);
2540 break;
2542 case 32:
2543 if (thumb_mode)
2545 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
2546 as_bad (_("selected processor does not support ARM opcodes"));
2548 thumb_mode = 0;
2550 if (!need_pass_2)
2551 frag_align (2, 0, 0);
2553 record_alignment (now_seg, 1);
2555 mapping_state (MAP_ARM);
2556 break;
2558 default:
2559 as_bad (_("invalid instruction size selected (%d)"), width);
2563 static void
2564 s_arm (int ignore ATTRIBUTE_UNUSED)
2566 opcode_select (32);
2567 demand_empty_rest_of_line ();
2570 static void
2571 s_thumb (int ignore ATTRIBUTE_UNUSED)
2573 opcode_select (16);
2574 demand_empty_rest_of_line ();
2577 static void
2578 s_code (int unused ATTRIBUTE_UNUSED)
2580 int temp;
2582 temp = get_absolute_expression ();
2583 switch (temp)
2585 case 16:
2586 case 32:
2587 opcode_select (temp);
2588 break;
2590 default:
2591 as_bad (_("invalid operand to .code directive (%d) (expecting 16 or 32)"), temp);
2595 static void
2596 s_force_thumb (int ignore ATTRIBUTE_UNUSED)
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)
2605 thumb_mode = 2;
2606 record_alignment (now_seg, 1);
2609 demand_empty_rest_of_line ();
2612 static void
2613 s_thumb_func (int ignore ATTRIBUTE_UNUSED)
2615 s_thumb (0);
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;
2622 /* Perform a .set directive, but also mark the alias as
2623 being a thumb function. */
2625 static void
2626 s_thumb_set (int equiv)
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;
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;
2644 if (*input_line_pointer != ',')
2646 *end_name = 0;
2647 as_bad (_("expected comma after name \"%s\""), name);
2648 *end_name = delim;
2649 ignore_rest_of_line ();
2650 return;
2653 input_line_pointer++;
2654 *end_name = 0;
2656 if (name[0] == '.' && name[1] == '\0')
2658 /* XXX - this should not happen to .thumb_set. */
2659 abort ();
2662 if ((symbolP = symbol_find (name)) == NULL
2663 && (symbolP = md_undefined_symbol (name)) == NULL)
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
2668 for this symbol. */
2669 if (listing & LISTING_SYMBOLS)
2671 extern struct list_info_struct * listing_tail;
2672 fragS * dummy_frag = xmalloc (sizeof (fragS));
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;
2680 else
2681 #endif
2682 symbolP = symbol_new (name, undefined_section, 0, &zero_address_frag);
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. */
2690 symbol_table_insert (symbolP);
2692 * end_name = delim;
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));
2699 pseudo_set (symbolP);
2701 demand_empty_rest_of_line ();
2703 /* XXX Now we come to the Thumb specific bit of code. */
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
2712 /* Directives: Mode selection. */
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. */
2717 static void
2718 s_syntax (int unused ATTRIBUTE_UNUSED)
2720 char *name, delim;
2722 name = input_line_pointer;
2723 delim = get_symbol_end ();
2725 if (!strcasecmp (name, "unified"))
2726 unified_syntax = TRUE;
2727 else if (!strcasecmp (name, "divided"))
2728 unified_syntax = FALSE;
2729 else
2731 as_bad (_("unrecognized syntax mode \"%s\""), name);
2732 return;
2734 *input_line_pointer = delim;
2735 demand_empty_rest_of_line ();
2738 /* Directives: sectioning and alignment. */
2740 /* Same as s_align_ptwo but align 0 => align 2. */
2742 static void
2743 s_align (int unused ATTRIBUTE_UNUSED)
2745 int temp;
2746 bfd_boolean fill_p;
2747 long temp_fill;
2748 long max_alignment = 15;
2750 temp = get_absolute_expression ();
2751 if (temp > max_alignment)
2752 as_bad (_("alignment too large: %d assumed"), temp = max_alignment);
2753 else if (temp < 0)
2755 as_bad (_("alignment negative. 0 assumed."));
2756 temp = 0;
2759 if (*input_line_pointer == ',')
2761 input_line_pointer++;
2762 temp_fill = get_absolute_expression ();
2763 fill_p = TRUE;
2765 else
2767 fill_p = FALSE;
2768 temp_fill = 0;
2771 if (!temp)
2772 temp = 2;
2774 /* Only make a frag if we HAVE to. */
2775 if (temp && !need_pass_2)
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);
2782 demand_empty_rest_of_line ();
2784 record_alignment (now_seg, temp);
2787 static void
2788 s_bss (int ignore ATTRIBUTE_UNUSED)
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);
2797 static void
2798 s_even (int ignore ATTRIBUTE_UNUSED)
2800 /* Never make frag if expect extra pass. */
2801 if (!need_pass_2)
2802 frag_align (1, 0, 0);
2804 record_alignment (now_seg, 1);
2806 demand_empty_rest_of_line ();
2809 /* Directives: Literal pools. */
2811 static literal_pool *
2812 find_literal_pool (void)
2814 literal_pool * pool;
2816 for (pool = list_of_pools; pool != NULL; pool = pool->next)
2818 if (pool->section == now_seg
2819 && pool->sub_section == now_subseg)
2820 break;
2823 return pool;
2826 static literal_pool *
2827 find_or_make_literal_pool (void)
2829 /* Next literal pool ID number. */
2830 static unsigned int latest_pool_num = 1;
2831 literal_pool * pool;
2833 pool = find_literal_pool ();
2835 if (pool == NULL)
2837 /* Create a new pool. */
2838 pool = xmalloc (sizeof (* pool));
2839 if (! pool)
2840 return NULL;
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;
2848 /* Add it to the list. */
2849 list_of_pools = pool;
2852 /* New pools, and emptied pools, will have a NULL symbol. */
2853 if (pool->symbol == NULL)
2855 pool->symbol = symbol_create (FAKE_LABEL_NAME, undefined_section,
2856 (valueT) 0, &zero_address_frag);
2857 pool->id = latest_pool_num ++;
2860 /* Done. */
2861 return pool;
2864 /* Add the literal in the global 'inst'
2865 structure to the relevant literal pool. */
2867 static int
2868 add_to_lit_pool (void)
2870 literal_pool * pool;
2871 unsigned int entry;
2873 pool = find_or_make_literal_pool ();
2875 /* Check if this literal value is already in the pool. */
2876 for (entry = 0; entry < pool->next_free_entry; entry ++)
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;
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;
2897 /* Do we need to create a new entry? */
2898 if (entry == pool->next_free_entry)
2900 if (entry >= MAX_LITERAL_POOL_SIZE)
2902 inst.error = _("literal pool overflow");
2903 return FAIL;
2906 pool->literals[entry] = inst.reloc.exp;
2907 pool->next_free_entry += 1;
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;
2914 return SUCCESS;
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. */
2920 static void
2921 symbol_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. */
2927 unsigned int name_length;
2928 char * preserved_copy_of_name;
2930 name_length = strlen (name) + 1; /* +1 for \0. */
2931 obstack_grow (&notes, name, name_length);
2932 preserved_copy_of_name = obstack_finish (&notes);
2934 #ifdef tc_canonicalize_symbol_name
2935 preserved_copy_of_name =
2936 tc_canonicalize_symbol_name (preserved_copy_of_name);
2937 #endif
2939 S_SET_NAME (symbolP, preserved_copy_of_name);
2941 S_SET_SEGMENT (symbolP, segment);
2942 S_SET_VALUE (symbolP, valu);
2943 symbol_clear_list_pointers (symbolP);
2945 symbol_set_frag (symbolP, frag);
2947 /* Link to end of symbol chain. */
2949 extern int symbol_table_frozen;
2951 if (symbol_table_frozen)
2952 abort ();
2955 symbol_append (symbolP, symbol_lastP, & symbol_rootP, & symbol_lastP);
2957 obj_symbol_new_hook (symbolP);
2959 #ifdef tc_symbol_new_hook
2960 tc_symbol_new_hook (symbolP);
2961 #endif
2963 #ifdef DEBUG_SYMS
2964 verify_symbol_chain (symbol_rootP, symbol_lastP);
2965 #endif /* DEBUG_SYMS */
2969 static void
2970 s_ltorg (int ignored ATTRIBUTE_UNUSED)
2972 unsigned int entry;
2973 literal_pool * pool;
2974 char sym_name[20];
2976 pool = find_literal_pool ();
2977 if (pool == NULL
2978 || pool->symbol == NULL
2979 || pool->next_free_entry == 0)
2980 return;
2982 mapping_state (MAP_DATA);
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);
2989 record_alignment (now_seg, 2);
2991 sprintf (sym_name, "$$lit_\002%x", pool->id);
2993 symbol_locate (pool->symbol, sym_name, now_seg,
2994 (valueT) frag_now_fix (), frag_now);
2995 symbol_table_insert (pool->symbol);
2997 ARM_SET_THUMB (pool->symbol, thumb_mode);
2999 #if defined OBJ_COFF || defined OBJ_ELF
3000 ARM_SET_INTERWORK (pool->symbol, support_interwork);
3001 #endif
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 */
3007 /* Mark the pool as empty. */
3008 pool->next_free_entry = 0;
3009 pool->symbol = NULL;
3012 #ifdef OBJ_ELF
3013 /* Forward declarations for functions below, in the MD interface
3014 section. */
3015 static void fix_new_arm (fragS *, int, short, expressionS *, int, int);
3016 static valueT create_unwind_entry (int);
3017 static void start_unwind_section (const segT, int);
3018 static void add_unwind_opcode (valueT, int);
3019 static void flush_pending_unwind (void);
3021 /* Directives: Data. */
3023 static void
3024 s_arm_elf_cons (int nbytes)
3026 expressionS exp;
3028 #ifdef md_flush_pending_output
3029 md_flush_pending_output ();
3030 #endif
3032 if (is_it_end_of_statement ())
3034 demand_empty_rest_of_line ();
3035 return;
3038 #ifdef md_cons_align
3039 md_cons_align (nbytes);
3040 #endif
3042 mapping_state (MAP_DATA);
3045 int reloc;
3046 char *base = input_line_pointer;
3048 expression (& exp);
3050 if (exp.X_op != O_symbol)
3051 emit_expr (&exp, (unsigned int) nbytes);
3052 else
3054 char *before_reloc = input_line_pointer;
3055 reloc = parse_reloc (&input_line_pointer);
3056 if (reloc == -1)
3058 as_bad (_("unrecognized relocation suffix"));
3059 ignore_rest_of_line ();
3060 return;
3062 else if (reloc == BFD_RELOC_UNUSED)
3063 emit_expr (&exp, (unsigned int) nbytes);
3064 else
3066 reloc_howto_type *howto = bfd_reloc_type_lookup (stdoutput, reloc);
3067 int size = bfd_get_reloc_size (howto);
3069 if (reloc == BFD_RELOC_ARM_PLT32)
3071 as_bad (_("(plt) is only valid on branch targets"));
3072 reloc = BFD_RELOC_UNUSED;
3073 size = 0;
3076 if (size > nbytes)
3077 as_bad (_("%s relocations do not fit in %d bytes"),
3078 howto->name, nbytes);
3079 else
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);
3092 input_line_pointer = base + (input_line_pointer-before_reloc);
3093 expression (&exp);
3094 memcpy (base, save_buf, p - base);
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);
3104 while (*input_line_pointer++ == ',');
3106 /* Put terminator back into stream. */
3107 input_line_pointer --;
3108 demand_empty_rest_of_line ();
3112 /* Parse a .rel31 directive. */
3114 static void
3115 s_arm_rel31 (int ignored ATTRIBUTE_UNUSED)
3117 expressionS exp;
3118 char *p;
3119 valueT highbit;
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"));
3127 input_line_pointer++;
3128 if (*input_line_pointer != ',')
3129 as_bad (_("missing comma"));
3130 input_line_pointer++;
3132 #ifdef md_flush_pending_output
3133 md_flush_pending_output ();
3134 #endif
3136 #ifdef md_cons_align
3137 md_cons_align (4);
3138 #endif
3140 mapping_state (MAP_DATA);
3142 expression (&exp);
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);
3149 demand_empty_rest_of_line ();
3152 /* Directives: AEABI stack-unwind tables. */
3154 /* Parse an unwind_fnstart directive. Simply records the current location. */
3156 static void
3157 s_arm_unwind_fnstart (int ignored ATTRIBUTE_UNUSED)
3159 demand_empty_rest_of_line ();
3160 if (unwind.proc_start)
3162 as_bad(_("duplicate .fnstart directive"));
3163 return;
3166 /* Mark the start of the function. */
3167 unwind.proc_start = expr_build_dot ();
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;
3176 unwind.fp_reg = REG_SP;
3177 unwind.fp_used = 0;
3178 unwind.sp_restored = 0;
3182 /* Parse a handlerdata directive. Creates the exception handling table entry
3183 for the function. */
3185 static void
3186 s_arm_unwind_handlerdata (int ignored ATTRIBUTE_UNUSED)
3188 demand_empty_rest_of_line ();
3189 if (!unwind.proc_start)
3190 as_bad(MISSING_FNSTART);
3192 if (unwind.table_entry)
3193 as_bad (_("duplicate .handlerdata directive"));
3195 create_unwind_entry (1);
3198 /* Parse an unwind_fnend directive. Generates the index table entry. */
3200 static void
3201 s_arm_unwind_fnend (int ignored ATTRIBUTE_UNUSED)
3203 long where;
3204 char *ptr;
3205 valueT val;
3207 demand_empty_rest_of_line ();
3209 if (!unwind.proc_start)
3211 as_bad(_(".fnend directive without .fnstart"));
3212 return;
3215 /* Add eh table entry. */
3216 if (unwind.table_entry == NULL)
3217 val = create_unwind_entry (0);
3218 else
3219 val = 0;
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);
3226 ptr = frag_more (8);
3227 where = frag_now_fix () - 8;
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);
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)))
3238 static const char *const name[] =
3240 "__aeabi_unwind_cpp_pr0",
3241 "__aeabi_unwind_cpp_pr1",
3242 "__aeabi_unwind_cpp_pr2"
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;
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);
3259 /* Restore the original section. */
3260 subseg_set (unwind.saved_seg, unwind.saved_subseg);
3262 unwind.proc_start = NULL;
3266 /* Parse an unwind_cantunwind directive. */
3268 static void
3269 s_arm_unwind_cantunwind (int ignored ATTRIBUTE_UNUSED)
3271 demand_empty_rest_of_line ();
3272 if (!unwind.proc_start)
3273 as_bad(MISSING_FNSTART);
3275 if (unwind.personality_routine || unwind.personality_index != -1)
3276 as_bad (_("personality routine specified for cantunwind frame"));
3278 unwind.personality_index = -2;
3282 /* Parse a personalityindex directive. */
3284 static void
3285 s_arm_unwind_personalityindex (int ignored ATTRIBUTE_UNUSED)
3287 expressionS exp;
3289 if (!unwind.proc_start)
3290 as_bad(MISSING_FNSTART);
3292 if (unwind.personality_routine || unwind.personality_index != -1)
3293 as_bad (_("duplicate .personalityindex directive"));
3295 expression (&exp);
3297 if (exp.X_op != O_constant
3298 || exp.X_add_number < 0 || exp.X_add_number > 15)
3300 as_bad (_("bad personality routine number"));
3301 ignore_rest_of_line ();
3302 return;
3305 unwind.personality_index = exp.X_add_number;
3307 demand_empty_rest_of_line ();
3311 /* Parse a personality directive. */
3313 static void
3314 s_arm_unwind_personality (int ignored ATTRIBUTE_UNUSED)
3316 char *name, *p, c;
3318 if (!unwind.proc_start)
3319 as_bad(MISSING_FNSTART);
3321 if (unwind.personality_routine || unwind.personality_index != -1)
3322 as_bad (_("duplicate .personality directive"));
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 ();
3333 /* Parse a directive saving core registers. */
3335 static void
3336 s_arm_unwind_save_core (void)
3338 valueT op;
3339 long range;
3340 int n;
3342 range = parse_reg_list (&input_line_pointer);
3343 if (range == FAIL)
3345 as_bad (_("expected register list"));
3346 ignore_rest_of_line ();
3347 return;
3350 demand_empty_rest_of_line ();
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)
3358 unwind.opcode_count--;
3359 unwind.sp_restored = 0;
3360 range = (range | 0x2000) & ~0x1000;
3361 unwind.pending_offset = 0;
3364 /* Pop r4-r15. */
3365 if (range & 0xfff0)
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++)
3371 /* Break at the first non-saved register. */
3372 if ((range & (1 << (n + 4))) == 0)
3373 break;
3375 /* See if there are any other bits set. */
3376 if (n == 0 || (range & (0xfff0 << n) & 0xbff0) != 0)
3378 /* Use the long form. */
3379 op = 0x8000 | ((range >> 4) & 0xfff);
3380 add_unwind_opcode (op, 2);
3382 else
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);
3394 /* Pop r0-r3. */
3395 if (range & 0xf)
3397 op = 0xb100 | (range & 0xf);
3398 add_unwind_opcode (op, 2);
3401 /* Record the number of bytes pushed. */
3402 for (n = 0; n < 16; n++)
3404 if (range & (1 << n))
3405 unwind.frame_size += 4;
3410 /* Parse a directive saving FPA registers. */
3412 static void
3413 s_arm_unwind_save_fpa (int reg)
3415 expressionS exp;
3416 int num_regs;
3417 valueT op;
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;
3425 if (exp.X_op != O_constant)
3427 as_bad (_("expected , <constant>"));
3428 ignore_rest_of_line ();
3429 return;
3432 num_regs = exp.X_add_number;
3434 if (num_regs < 1 || num_regs > 4)
3436 as_bad (_("number of registers must be in the range [1:4]"));
3437 ignore_rest_of_line ();
3438 return;
3441 demand_empty_rest_of_line ();
3443 if (reg == 4)
3445 /* Short form. */
3446 op = 0xb4 | (num_regs - 1);
3447 add_unwind_opcode (op, 1);
3449 else
3451 /* Long form. */
3452 op = 0xc800 | (reg << 4) | (num_regs - 1);
3453 add_unwind_opcode (op, 2);
3455 unwind.frame_size += num_regs * 12;
3459 /* Parse a directive saving VFP registers for ARMv6 and above. */
3461 static void
3462 s_arm_unwind_save_vfp_armv6 (void)
3464 int count;
3465 unsigned int start;
3466 valueT op;
3467 int num_vfpv3_regs = 0;
3468 int num_regs_below_16;
3470 count = parse_vfp_reg_list (&input_line_pointer, &start, REGLIST_VFP_D);
3471 if (count == FAIL)
3473 as_bad (_("expected register list"));
3474 ignore_rest_of_line ();
3475 return;
3478 demand_empty_rest_of_line ();
3480 /* We always generate FSTMD/FLDMD-style unwinding opcodes (rather
3481 than FSTMX/FLDMX-style ones). */
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;
3489 if (num_vfpv3_regs > 0)
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);
3496 /* Generate opcode for registers numbered in the range 0 .. 15. */
3497 num_regs_below_16 = num_vfpv3_regs > 0 ? 16 - (int) start : count;
3498 gas_assert (num_regs_below_16 + num_vfpv3_regs == count);
3499 if (num_regs_below_16 > 0)
3501 op = 0xc900 | (start << 4) | (num_regs_below_16 - 1);
3502 add_unwind_opcode (op, 2);
3505 unwind.frame_size += count * 8;
3509 /* Parse a directive saving VFP registers for pre-ARMv6. */
3511 static void
3512 s_arm_unwind_save_vfp (void)
3514 int count;
3515 unsigned int reg;
3516 valueT op;
3518 count = parse_vfp_reg_list (&input_line_pointer, &reg, REGLIST_VFP_D);
3519 if (count == FAIL)
3521 as_bad (_("expected register list"));
3522 ignore_rest_of_line ();
3523 return;
3526 demand_empty_rest_of_line ();
3528 if (reg == 8)
3530 /* Short form. */
3531 op = 0xb8 | (count - 1);
3532 add_unwind_opcode (op, 1);
3534 else
3536 /* Long form. */
3537 op = 0xb300 | (reg << 4) | (count - 1);
3538 add_unwind_opcode (op, 2);
3540 unwind.frame_size += count * 8 + 4;
3544 /* Parse a directive saving iWMMXt data registers. */
3546 static void
3547 s_arm_unwind_save_mmxwr (void)
3549 int reg;
3550 int hi_reg;
3551 int i;
3552 unsigned mask = 0;
3553 valueT op;
3555 if (*input_line_pointer == '{')
3556 input_line_pointer++;
3560 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3562 if (reg == FAIL)
3564 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3565 goto error;
3568 if (mask >> reg)
3569 as_tsktsk (_("register list not in ascending order"));
3570 mask |= 1 << reg;
3572 if (*input_line_pointer == '-')
3574 input_line_pointer++;
3575 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWR);
3576 if (hi_reg == FAIL)
3578 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWR]));
3579 goto error;
3581 else if (reg >= hi_reg)
3583 as_bad (_("bad register range"));
3584 goto error;
3586 for (; reg < hi_reg; reg++)
3587 mask |= 1 << reg;
3590 while (skip_past_comma (&input_line_pointer) != FAIL);
3592 if (*input_line_pointer == '}')
3593 input_line_pointer++;
3595 demand_empty_rest_of_line ();
3597 /* Generate any deferred opcodes because we're going to be looking at
3598 the list. */
3599 flush_pending_unwind ();
3601 for (i = 0; i < 16; i++)
3603 if (mask & (1 << i))
3604 unwind.frame_size += 8;
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)
3612 i = unwind.opcodes[unwind.opcode_count - 1];
3613 if ((i & 0xf8) == 0xc0)
3615 i &= 7;
3616 /* Only merge if the blocks are contiguous. */
3617 if (i < 6)
3619 if ((mask & 0xfe00) == (1 << 9))
3621 mask |= ((1 << (i + 11)) - 1) & 0xfc00;
3622 unwind.opcode_count--;
3625 else if (i == 6 && unwind.opcode_count >= 2)
3627 i = unwind.opcodes[unwind.opcode_count - 2];
3628 reg = i >> 4;
3629 i &= 0xf;
3631 op = 0xffff << (reg - 1);
3632 if (reg > 0
3633 && ((mask & op) == (1u << (reg - 1))))
3635 op = (1 << (reg + i + 1)) - 1;
3636 op &= ~((1 << reg) - 1);
3637 mask |= op;
3638 unwind.opcode_count -= 2;
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--)
3649 /* Save registers in blocks. */
3650 if (reg < 0
3651 || !(mask & (1 << reg)))
3653 /* We found an unsaved reg. Generate opcodes to save the
3654 preceding block. */
3655 if (reg != hi_reg)
3657 if (reg == 9)
3659 /* Short form. */
3660 op = 0xc0 | (hi_reg - 10);
3661 add_unwind_opcode (op, 1);
3663 else
3665 /* Long form. */
3666 op = 0xc600 | ((reg + 1) << 4) | ((hi_reg - reg) - 1);
3667 add_unwind_opcode (op, 2);
3670 hi_reg = reg - 1;
3674 return;
3675 error:
3676 ignore_rest_of_line ();
3679 static void
3680 s_arm_unwind_save_mmxwcg (void)
3682 int reg;
3683 int hi_reg;
3684 unsigned mask = 0;
3685 valueT op;
3687 if (*input_line_pointer == '{')
3688 input_line_pointer++;
3692 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3694 if (reg == FAIL)
3696 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3697 goto error;
3700 reg -= 8;
3701 if (mask >> reg)
3702 as_tsktsk (_("register list not in ascending order"));
3703 mask |= 1 << reg;
3705 if (*input_line_pointer == '-')
3707 input_line_pointer++;
3708 hi_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_MMXWCG);
3709 if (hi_reg == FAIL)
3711 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_MMXWCG]));
3712 goto error;
3714 else if (reg >= hi_reg)
3716 as_bad (_("bad register range"));
3717 goto error;
3719 for (; reg < hi_reg; reg++)
3720 mask |= 1 << reg;
3723 while (skip_past_comma (&input_line_pointer) != FAIL);
3725 if (*input_line_pointer == '}')
3726 input_line_pointer++;
3728 demand_empty_rest_of_line ();
3730 /* Generate any deferred opcodes because we're going to be looking at
3731 the list. */
3732 flush_pending_unwind ();
3734 for (reg = 0; reg < 16; reg++)
3736 if (mask & (1 << reg))
3737 unwind.frame_size += 4;
3739 op = 0xc700 | mask;
3740 add_unwind_opcode (op, 2);
3741 return;
3742 error:
3743 ignore_rest_of_line ();
3747 /* Parse an unwind_save directive.
3748 If the argument is non-zero, this is a .vsave directive. */
3750 static void
3751 s_arm_unwind_save (int arch_v6)
3753 char *peek;
3754 struct reg_entry *reg;
3755 bfd_boolean had_brace = FALSE;
3757 if (!unwind.proc_start)
3758 as_bad(MISSING_FNSTART);
3760 /* Figure out what sort of save we have. */
3761 peek = input_line_pointer;
3763 if (*peek == '{')
3765 had_brace = TRUE;
3766 peek++;
3769 reg = arm_reg_parse_multi (&peek);
3771 if (!reg)
3773 as_bad (_("register expected"));
3774 ignore_rest_of_line ();
3775 return;
3778 switch (reg->type)
3780 case REG_TYPE_FN:
3781 if (had_brace)
3783 as_bad (_("FPA .unwind_save does not take a register list"));
3784 ignore_rest_of_line ();
3785 return;
3787 input_line_pointer = peek;
3788 s_arm_unwind_save_fpa (reg->number);
3789 return;
3791 case REG_TYPE_RN: s_arm_unwind_save_core (); return;
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;
3798 case REG_TYPE_MMXWR: s_arm_unwind_save_mmxwr (); return;
3799 case REG_TYPE_MMXWCG: s_arm_unwind_save_mmxwcg (); return;
3801 default:
3802 as_bad (_(".unwind_save does not support this kind of register"));
3803 ignore_rest_of_line ();
3808 /* Parse an unwind_movsp directive. */
3810 static void
3811 s_arm_unwind_movsp (int ignored ATTRIBUTE_UNUSED)
3813 int reg;
3814 valueT op;
3815 int offset;
3817 if (!unwind.proc_start)
3818 as_bad(MISSING_FNSTART);
3820 reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3821 if (reg == FAIL)
3823 as_bad ("%s", _(reg_expected_msgs[REG_TYPE_RN]));
3824 ignore_rest_of_line ();
3825 return;
3828 /* Optional constant. */
3829 if (skip_past_comma (&input_line_pointer) != FAIL)
3831 if (immediate_for_directive (&offset) == FAIL)
3832 return;
3834 else
3835 offset = 0;
3837 demand_empty_rest_of_line ();
3839 if (reg == REG_SP || reg == REG_PC)
3841 as_bad (_("SP and PC not permitted in .unwind_movsp directive"));
3842 return;
3845 if (unwind.fp_reg != REG_SP)
3846 as_bad (_("unexpected .unwind_movsp directive"));
3848 /* Generate opcode to restore the value. */
3849 op = 0x90 | reg;
3850 add_unwind_opcode (op, 1);
3852 /* Record the information for later. */
3853 unwind.fp_reg = reg;
3854 unwind.fp_offset = unwind.frame_size - offset;
3855 unwind.sp_restored = 1;
3858 /* Parse an unwind_pad directive. */
3860 static void
3861 s_arm_unwind_pad (int ignored ATTRIBUTE_UNUSED)
3863 int offset;
3865 if (!unwind.proc_start)
3866 as_bad(MISSING_FNSTART);
3868 if (immediate_for_directive (&offset) == FAIL)
3869 return;
3871 if (offset & 3)
3873 as_bad (_("stack increment must be multiple of 4"));
3874 ignore_rest_of_line ();
3875 return;
3878 /* Don't generate any opcodes, just record the details for later. */
3879 unwind.frame_size += offset;
3880 unwind.pending_offset += offset;
3882 demand_empty_rest_of_line ();
3885 /* Parse an unwind_setfp directive. */
3887 static void
3888 s_arm_unwind_setfp (int ignored ATTRIBUTE_UNUSED)
3890 int sp_reg;
3891 int fp_reg;
3892 int offset;
3894 if (!unwind.proc_start)
3895 as_bad(MISSING_FNSTART);
3897 fp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3898 if (skip_past_comma (&input_line_pointer) == FAIL)
3899 sp_reg = FAIL;
3900 else
3901 sp_reg = arm_reg_parse (&input_line_pointer, REG_TYPE_RN);
3903 if (fp_reg == FAIL || sp_reg == FAIL)
3905 as_bad (_("expected <reg>, <reg>"));
3906 ignore_rest_of_line ();
3907 return;
3910 /* Optional constant. */
3911 if (skip_past_comma (&input_line_pointer) != FAIL)
3913 if (immediate_for_directive (&offset) == FAIL)
3914 return;
3916 else
3917 offset = 0;
3919 demand_empty_rest_of_line ();
3921 if (sp_reg != REG_SP && sp_reg != unwind.fp_reg)
3923 as_bad (_("register must be either sp or set by a previous"
3924 "unwind_movsp directive"));
3925 return;
3928 /* Don't generate any opcodes, just record the information for later. */
3929 unwind.fp_reg = fp_reg;
3930 unwind.fp_used = 1;
3931 if (sp_reg == REG_SP)
3932 unwind.fp_offset = unwind.frame_size - offset;
3933 else
3934 unwind.fp_offset -= offset;
3937 /* Parse an unwind_raw directive. */
3939 static void
3940 s_arm_unwind_raw (int ignored ATTRIBUTE_UNUSED)
3942 expressionS exp;
3943 /* This is an arbitrary limit. */
3944 unsigned char op[16];
3945 int count;
3947 if (!unwind.proc_start)
3948 as_bad(MISSING_FNSTART);
3950 expression (&exp);
3951 if (exp.X_op == O_constant
3952 && skip_past_comma (&input_line_pointer) != FAIL)
3954 unwind.frame_size += exp.X_add_number;
3955 expression (&exp);
3957 else
3958 exp.X_op = O_illegal;
3960 if (exp.X_op != O_constant)
3962 as_bad (_("expected <offset>, <opcode>"));
3963 ignore_rest_of_line ();
3964 return;
3967 count = 0;
3969 /* Parse the opcode. */
3970 for (;;)
3972 if (count >= 16)
3974 as_bad (_("unwind opcode too long"));
3975 ignore_rest_of_line ();
3977 if (exp.X_op != O_constant || exp.X_add_number & ~0xff)
3979 as_bad (_("invalid unwind opcode"));
3980 ignore_rest_of_line ();
3981 return;
3983 op[count++] = exp.X_add_number;
3985 /* Parse the next byte. */
3986 if (skip_past_comma (&input_line_pointer) == FAIL)
3987 break;
3989 expression (&exp);
3992 /* Add the opcode bytes in reverse order. */
3993 while (count--)
3994 add_unwind_opcode (op[count], 1);
3996 demand_empty_rest_of_line ();
4000 /* Parse a .eabi_attribute directive. */
4002 static void
4003 s_arm_eabi_attribute (int ignored ATTRIBUTE_UNUSED)
4005 int tag = s_vendor_attribute (OBJ_ATTR_PROC);
4007 if (tag < NUM_KNOWN_OBJ_ATTRIBUTES)
4008 attributes_set_explicitly[tag] = 1;
4010 #endif /* OBJ_ELF */
4012 static void s_arm_arch (int);
4013 static void s_arm_object_arch (int);
4014 static void s_arm_cpu (int);
4015 static void s_arm_fpu (int);
4017 #ifdef TE_PE
4019 static void
4020 pe_directive_secrel (int dummy ATTRIBUTE_UNUSED)
4022 expressionS exp;
4026 expression (&exp);
4027 if (exp.X_op == O_symbol)
4028 exp.X_op = O_secrel;
4030 emit_expr (&exp, 4);
4032 while (*input_line_pointer++ == ',');
4034 input_line_pointer--;
4035 demand_empty_rest_of_line ();
4037 #endif /* TE_PE */
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. */
4045 const pseudo_typeS md_pseudo_table[] =
4047 /* Never called because '.req' does not start a line. */
4048 { "req", s_req, 0 },
4049 /* Following two are likewise never called. */
4050 { "dn", s_dn, 0 },
4051 { "qn", s_qn, 0 },
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 },
4065 { "cpu", s_arm_cpu, 0 },
4066 { "arch", s_arm_arch, 0 },
4067 { "object_arch", s_arm_object_arch, 0 },
4068 { "fpu", s_arm_fpu, 0 },
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 },
4080 { "vsave", s_arm_unwind_save, 1 },
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 },
4085 { "eabi_attribute", s_arm_eabi_attribute, 0 },
4086 #else
4087 { "word", cons, 4},
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 },
4097 #endif
4098 { "extend", float_cons, 'x' },
4099 { "ldouble", float_cons, 'x' },
4100 { "packed", float_cons, 'p' },
4101 #ifdef TE_PE
4102 {"secrel32", pe_directive_secrel, 0},
4103 #endif
4104 { 0, 0, 0 }
4107 /* Parser functions used exclusively in instruction operands. */
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. */
4115 static int
4116 parse_immediate (char **str, int *val, int min, int max,
4117 bfd_boolean prefix_opt)
4119 expressionS exp;
4120 my_get_expression (&exp, str, prefix_opt ? GE_OPT_PREFIX : GE_IMM_PREFIX);
4121 if (exp.X_op != O_constant)
4123 inst.error = _("constant expression required");
4124 return FAIL;
4127 if (exp.X_add_number < min || exp.X_add_number > max)
4129 inst.error = _("immediate value out of range");
4130 return FAIL;
4133 *val = exp.X_add_number;
4134 return SUCCESS;
4137 /* Less-generic immediate-value read function with the possibility of loading a
4138 big (64-bit) immediate, as required by Neon VMOV, VMVN and logic immediate
4139 instructions. Puts the result directly in inst.operands[i]. */
4141 static int
4142 parse_big_immediate (char **str, int i)
4144 expressionS exp;
4145 char *ptr = *str;
4147 my_get_expression (&exp, &ptr, GE_OPT_PREFIX_BIG);
4149 if (exp.X_op == O_constant)
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)
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;
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)
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. */
4170 gas_assert (parts != 0);
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;
4181 else
4182 return FAIL;
4184 *str = ptr;
4186 return SUCCESS;
4189 /* Returns the pseudo-register number of an FPA immediate constant,
4190 or FAIL if there isn't a valid constant here. */
4192 static int
4193 parse_fpa_immediate (char ** str)
4195 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4196 char * save_in;
4197 expressionS exp;
4198 int i;
4199 int j;
4201 /* First try and match exact strings, this is to guarantee
4202 that some formats will work even for cross assembly. */
4204 for (i = 0; fp_const[i]; i++)
4206 if (strncmp (*str, fp_const[i], strlen (fp_const[i])) == 0)
4208 char *start = *str;
4210 *str += strlen (fp_const[i]);
4211 if (is_end_of_line[(unsigned char) **str])
4212 return i + 8;
4213 *str = start;
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. */
4222 memset (words, 0, MAX_LITTLENUMS * sizeof (LITTLENUM_TYPE));
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])
4228 for (i = 0; i < NUM_FLOAT_VALS; i++)
4230 for (j = 0; j < MAX_LITTLENUMS; j++)
4232 if (words[j] != fp_values[i][j])
4233 break;
4236 if (j == MAX_LITTLENUMS)
4238 *str = save_in;
4239 return i + 8;
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)
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)
4256 for (i = 0; i < NUM_FLOAT_VALS; i++)
4258 for (j = 0; j < MAX_LITTLENUMS; j++)
4260 if (words[j] != fp_values[i][j])
4261 break;
4264 if (j == MAX_LITTLENUMS)
4266 *str = input_line_pointer;
4267 input_line_pointer = save_in;
4268 return i + 8;
4274 *str = input_line_pointer;
4275 input_line_pointer = save_in;
4276 inst.error = _("invalid FPA immediate expression");
4277 return FAIL;
4280 /* Returns 1 if a number has "quarter-precision" float format
4281 0baBbbbbbc defgh000 00000000 00000000. */
4283 static int
4284 is_quarter_float (unsigned imm)
4286 int bs = (imm & 0x20000000) ? 0x3e000000 : 0x40000000;
4287 return (imm & 0x7ffff) == 0 && ((imm & 0x7e000000) ^ bs) == 0;
4290 /* Parse an 8-bit "quarter-precision" floating point number of the form:
4291 0baBbbbbbc defgh000 00000000 00000000.
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. */
4296 static unsigned
4297 parse_qfloat_immediate (char **ccp, int *immed)
4299 char *str = *ccp;
4300 char *fpnum;
4301 LITTLENUM_TYPE words[MAX_LITTLENUMS];
4302 int found_fpchar = 0;
4304 skip_past_char (&str, '#');
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);
4314 if (strncmp (fpnum, "0x", 2) == 0)
4315 return FAIL;
4316 else
4318 for (; *fpnum != '\0' && *fpnum != ' ' && *fpnum != '\n'; fpnum++)
4319 if (*fpnum == '.' || *fpnum == 'e' || *fpnum == 'E')
4321 found_fpchar = 1;
4322 break;
4325 if (!found_fpchar)
4326 return FAIL;
4329 if ((str = atof_ieee (str, 's', words)) != NULL)
4331 unsigned fpword = 0;
4332 int i;
4334 /* Our FP word must be 32 bits (single-precision FP). */
4335 for (i = 0; i < 32 / LITTLENUM_NUMBER_OF_BITS; i++)
4337 fpword <<= LITTLENUM_NUMBER_OF_BITS;
4338 fpword |= words[i];
4341 if (is_quarter_float (fpword) || (fpword & 0x7fffffff) == 0)
4342 *immed = fpword;
4343 else
4344 return FAIL;
4346 *ccp = str;
4348 return SUCCESS;
4351 return FAIL;
4354 /* Shift operands. */
4355 enum shift_kind
4357 SHIFT_LSL, SHIFT_LSR, SHIFT_ASR, SHIFT_ROR, SHIFT_RRX
4360 struct asm_shift_name
4362 const char *name;
4363 enum shift_kind kind;
4366 /* Third argument to parse_shift. */
4367 enum parse_shift_mode
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. */
4376 /* Parse a <shift> specifier on an ARM data processing instruction.
4377 This has three forms:
4379 (LSL|LSR|ASL|ASR|ROR) Rs
4380 (LSL|LSR|ASL|ASR|ROR) #imm
4383 Note that ASL is assimilated to LSL in the instruction encoding, and
4384 RRX to ROR #0 (which cannot be written as such). */
4386 static int
4387 parse_shift (char **str, int i, enum parse_shift_mode mode)
4389 const struct asm_shift_name *shift_name;
4390 enum shift_kind shift;
4391 char *s = *str;
4392 char *p = s;
4393 int reg;
4395 for (p = *str; ISALPHA (*p); p++)
4398 if (p == *str)
4400 inst.error = _("shift expression expected");
4401 return FAIL;
4404 shift_name = hash_find_n (arm_shift_hsh, *str, p - *str);
4406 if (shift_name == NULL)
4408 inst.error = _("shift expression expected");
4409 return FAIL;
4412 shift = shift_name->kind;
4414 switch (mode)
4416 case NO_SHIFT_RESTRICT:
4417 case SHIFT_IMMEDIATE: break;
4419 case SHIFT_LSL_OR_ASR_IMMEDIATE:
4420 if (shift != SHIFT_LSL && shift != SHIFT_ASR)
4422 inst.error = _("'LSL' or 'ASR' required");
4423 return FAIL;
4425 break;
4427 case SHIFT_LSL_IMMEDIATE:
4428 if (shift != SHIFT_LSL)
4430 inst.error = _("'LSL' required");
4431 return FAIL;
4433 break;
4435 case SHIFT_ASR_IMMEDIATE:
4436 if (shift != SHIFT_ASR)
4438 inst.error = _("'ASR' required");
4439 return FAIL;
4441 break;
4443 default: abort ();
4446 if (shift != SHIFT_RRX)
4448 /* Whitespace can appear here if the next thing is a bare digit. */
4449 skip_whitespace (p);
4451 if (mode == NO_SHIFT_RESTRICT
4452 && (reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4454 inst.operands[i].imm = reg;
4455 inst.operands[i].immisreg = 1;
4457 else if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4458 return FAIL;
4460 inst.operands[i].shift_kind = shift;
4461 inst.operands[i].shifted = 1;
4462 *str = p;
4463 return SUCCESS;
4466 /* Parse a <shifter_operand> for an ARM data processing instruction:
4468 #<immediate>
4469 #<immediate>, <rotate>
4470 <Rm>
4471 <Rm>, <shift>
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
4475 is deferred to md_apply_fix. */
4477 static int
4478 parse_shifter_operand (char **str, int i)
4480 int value;
4481 expressionS expr;
4483 if ((value = arm_reg_parse (str, REG_TYPE_RN)) != FAIL)
4485 inst.operands[i].reg = value;
4486 inst.operands[i].isreg = 1;
4488 /* parse_shift will override this if appropriate */
4489 inst.reloc.exp.X_op = O_constant;
4490 inst.reloc.exp.X_add_number = 0;
4492 if (skip_past_comma (str) == FAIL)
4493 return SUCCESS;
4495 /* Shift operation on register. */
4496 return parse_shift (str, i, NO_SHIFT_RESTRICT);
4499 if (my_get_expression (&inst.reloc.exp, str, GE_IMM_PREFIX))
4500 return FAIL;
4502 if (skip_past_comma (str) == SUCCESS)
4504 /* #x, y -- ie explicit rotation by Y. */
4505 if (my_get_expression (&expr, str, GE_NO_PREFIX))
4506 return FAIL;
4508 if (expr.X_op != O_constant || inst.reloc.exp.X_op != O_constant)
4510 inst.error = _("constant expression expected");
4511 return FAIL;
4514 value = expr.X_add_number;
4515 if (value < 0 || value > 30 || value % 2 != 0)
4517 inst.error = _("invalid rotation");
4518 return FAIL;
4520 if (inst.reloc.exp.X_add_number < 0 || inst.reloc.exp.X_add_number > 255)
4522 inst.error = _("invalid constant");
4523 return FAIL;
4526 /* Convert to decoded value. md_apply_fix will put it back. */
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);
4532 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
4533 inst.reloc.pc_rel = 0;
4534 return SUCCESS;
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. */
4544 struct group_reloc_table_entry
4546 const char *name;
4547 int alu_code;
4548 int ldr_code;
4549 int ldrs_code;
4550 int ldc_code;
4553 typedef enum
4555 /* Varieties of non-ALU group relocation. */
4557 GROUP_LDR,
4558 GROUP_LDRS,
4559 GROUP_LDC
4560 } group_reloc_type;
4562 static 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 */
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. */
4623 static int
4624 find_group_reloc_table_entry (char **str, struct group_reloc_table_entry **out)
4626 unsigned int i;
4627 for (i = 0; i < ARRAY_SIZE (group_reloc_table); i++)
4629 int length = strlen (group_reloc_table[i].name);
4631 if (strncasecmp (group_reloc_table[i].name, *str, length) == 0
4632 && (*str)[length] == ':')
4634 *out = &group_reloc_table[i];
4635 *str += (length + 1);
4636 return SUCCESS;
4640 return FAIL;
4643 /* Parse a <shifter_operand> for an ARM data processing instruction
4644 (as for parse_shifter_operand) where group relocations are allowed:
4646 #<immediate>
4647 #<immediate>, <rotate>
4648 #:<group_reloc>:<expression>
4649 <Rm>
4650 <Rm>, <shift>
4652 where <group_reloc> is one of the strings defined in group_reloc_table.
4653 The hashes are optional.
4655 Everything else is as for parse_shifter_operand. */
4657 static parse_operand_result
4658 parse_shifter_operand_group_reloc (char **str, int i)
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. */
4664 if (((*str)[0] == '#' && (*str)[1] == ':')
4665 || (*str)[0] == ':')
4667 struct group_reloc_table_entry *entry;
4669 if ((*str)[0] == '#')
4670 (*str) += 2;
4671 else
4672 (*str)++;
4674 /* Try to parse a group relocation. Anything else is an error. */
4675 if (find_group_reloc_table_entry (str, &entry) == FAIL)
4677 inst.error = _("unknown group relocation");
4678 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
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;
4686 /* Record the relocation type (always the ALU variant here). */
4687 inst.reloc.type = entry->alu_code;
4688 gas_assert (inst.reloc.type != 0);
4690 return PARSE_OPERAND_SUCCESS;
4692 else
4693 return parse_shifter_operand (str, i) == SUCCESS
4694 ? PARSE_OPERAND_SUCCESS : PARSE_OPERAND_FAIL;
4696 /* Never reached. */
4699 /* Parse all forms of an ARM address expression. Information is written
4700 to inst.operands[i] and/or inst.reloc.
4702 Preindexed addressing (.preind=1):
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
4709 These three may have a trailing ! which causes .writeback to be set also.
4711 Postindexed addressing (.postind=1, .writeback=1):
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
4718 Unindexed addressing (.preind=0, .postind=0):
4720 [Rn], {option} .reg=Rn .imm=option .immisreg=0
4722 Other:
4724 [Rn]{!} shorthand for [Rn,#0]{!}
4725 =immediate .isreg=0 .reloc.exp=immediate
4726 label .reg=PC .reloc.pc_rel=1 .reloc.exp=label
4728 It is the caller's responsibility to check for addressing modes not
4729 supported by the instruction, and to set inst.reloc.type. */
4731 static parse_operand_result
4732 parse_address_main (char **str, int i, int group_relocations,
4733 group_reloc_type group_type)
4735 char *p = *str;
4736 int reg;
4738 if (skip_past_char (&p, '[') == FAIL)
4740 if (skip_past_char (&p, '=') == FAIL)
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;
4748 /* else a load-constant pseudo op, no special treatment needed here */
4750 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4751 return PARSE_OPERAND_FAIL;
4753 *str = p;
4754 return PARSE_OPERAND_SUCCESS;
4757 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
4759 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
4760 return PARSE_OPERAND_FAIL;
4762 inst.operands[i].reg = reg;
4763 inst.operands[i].isreg = 1;
4765 if (skip_past_comma (&p) == SUCCESS)
4767 inst.operands[i].preind = 1;
4769 if (*p == '+') p++;
4770 else if (*p == '-') p++, inst.operands[i].negative = 1;
4772 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
4774 inst.operands[i].imm = reg;
4775 inst.operands[i].immisreg = 1;
4777 if (skip_past_comma (&p) == SUCCESS)
4778 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4779 return PARSE_OPERAND_FAIL;
4781 else if (skip_past_char (&p, ':') == SUCCESS)
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)
4790 inst.error = _("alignment must be constant");
4791 return PARSE_OPERAND_FAIL;
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;
4798 else
4800 if (inst.operands[i].negative)
4802 inst.operands[i].negative = 0;
4803 p--;
4806 if (group_relocations
4807 && ((*p == '#' && *(p + 1) == ':') || *p == ':'))
4809 struct group_reloc_table_entry *entry;
4811 /* Skip over the #: or : sequence. */
4812 if (*p == '#')
4813 p += 2;
4814 else
4815 p++;
4817 /* Try to parse a group relocation. Anything else is an
4818 error. */
4819 if (find_group_reloc_table_entry (&p, &entry) == FAIL)
4821 inst.error = _("unknown group relocation");
4822 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
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;
4831 /* Record the relocation type. */
4832 switch (group_type)
4834 case GROUP_LDR:
4835 inst.reloc.type = entry->ldr_code;
4836 break;
4838 case GROUP_LDRS:
4839 inst.reloc.type = entry->ldrs_code;
4840 break;
4842 case GROUP_LDC:
4843 inst.reloc.type = entry->ldc_code;
4844 break;
4846 default:
4847 gas_assert (0);
4850 if (inst.reloc.type == 0)
4852 inst.error = _("this group relocation is not allowed on this instruction");
4853 return PARSE_OPERAND_FAIL_NO_BACKTRACK;
4856 else
4857 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4858 return PARSE_OPERAND_FAIL;
4862 if (skip_past_char (&p, ']') == FAIL)
4864 inst.error = _("']' expected");
4865 return PARSE_OPERAND_FAIL;
4868 if (skip_past_char (&p, '!') == SUCCESS)
4869 inst.operands[i].writeback = 1;
4871 else if (skip_past_comma (&p) == SUCCESS)
4873 if (skip_past_char (&p, '{') == SUCCESS)
4875 /* [Rn], {expr} - unindexed, with option */
4876 if (parse_immediate (&p, &inst.operands[i].imm,
4877 0, 255, TRUE) == FAIL)
4878 return PARSE_OPERAND_FAIL;
4880 if (skip_past_char (&p, '}') == FAIL)
4882 inst.error = _("'}' expected at end of 'option' field");
4883 return PARSE_OPERAND_FAIL;
4885 if (inst.operands[i].preind)
4887 inst.error = _("cannot combine index with option");
4888 return PARSE_OPERAND_FAIL;
4890 *str = p;
4891 return PARSE_OPERAND_SUCCESS;
4893 else
4895 inst.operands[i].postind = 1;
4896 inst.operands[i].writeback = 1;
4898 if (inst.operands[i].preind)
4900 inst.error = _("cannot combine pre- and post-indexing");
4901 return PARSE_OPERAND_FAIL;
4904 if (*p == '+') p++;
4905 else if (*p == '-') p++, inst.operands[i].negative = 1;
4907 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) != FAIL)
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;
4915 inst.operands[i].immisreg = 1;
4917 if (skip_past_comma (&p) == SUCCESS)
4918 if (parse_shift (&p, i, SHIFT_IMMEDIATE) == FAIL)
4919 return PARSE_OPERAND_FAIL;
4921 else
4923 if (inst.operands[i].negative)
4925 inst.operands[i].negative = 0;
4926 p--;
4928 if (my_get_expression (&inst.reloc.exp, &p, GE_IMM_PREFIX))
4929 return PARSE_OPERAND_FAIL;
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)
4938 inst.operands[i].preind = 1;
4939 inst.reloc.exp.X_op = O_constant;
4940 inst.reloc.exp.X_add_number = 0;
4942 *str = p;
4943 return PARSE_OPERAND_SUCCESS;
4946 static int
4947 parse_address (char **str, int i)
4949 return parse_address_main (str, i, 0, 0) == PARSE_OPERAND_SUCCESS
4950 ? SUCCESS : FAIL;
4953 static parse_operand_result
4954 parse_address_group_reloc (char **str, int i, group_reloc_type type)
4956 return parse_address_main (str, i, 1, type);
4959 /* Parse an operand for a MOVW or MOVT instruction. */
4960 static int
4961 parse_half (char **str)
4963 char * p;
4965 p = *str;
4966 skip_past_char (&p, '#');
4967 if (strncasecmp (p, ":lower16:", 9) == 0)
4968 inst.reloc.type = BFD_RELOC_ARM_MOVW;
4969 else if (strncasecmp (p, ":upper16:", 9) == 0)
4970 inst.reloc.type = BFD_RELOC_ARM_MOVT;
4972 if (inst.reloc.type != BFD_RELOC_UNUSED)
4974 p += 9;
4975 skip_whitespace (p);
4978 if (my_get_expression (&inst.reloc.exp, &p, GE_NO_PREFIX))
4979 return FAIL;
4981 if (inst.reloc.type == BFD_RELOC_UNUSED)
4983 if (inst.reloc.exp.X_op != O_constant)
4985 inst.error = _("constant expression expected");
4986 return FAIL;
4988 if (inst.reloc.exp.X_add_number < 0
4989 || inst.reloc.exp.X_add_number > 0xffff)
4991 inst.error = _("immediate value out of range");
4992 return FAIL;
4995 *str = p;
4996 return SUCCESS;
4999 /* Miscellaneous. */
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. */
5003 static int
5004 parse_psr (char **str)
5006 char *p;
5007 unsigned long psr_field;
5008 const struct asm_psr *psr;
5009 char *start;
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;
5014 if (strncasecmp (p, "SPSR", 4) == 0)
5015 psr_field = SPSR_BIT;
5016 else if (strncasecmp (p, "CPSR", 4) == 0)
5017 psr_field = 0;
5018 else
5020 start = p;
5022 p++;
5023 while (ISALNUM (*p) || *p == '_');
5025 psr = hash_find_n (arm_v7m_psr_hsh, start, p - start);
5026 if (!psr)
5027 return FAIL;
5029 *str = p;
5030 return psr->field;
5033 p += 4;
5034 if (*p == '_')
5036 /* A suffix follows. */
5037 p++;
5038 start = p;
5041 p++;
5042 while (ISALNUM (*p) || *p == '_');
5044 psr = hash_find_n (arm_psr_hsh, start, p - start);
5045 if (!psr)
5046 goto error;
5048 psr_field |= psr->field;
5050 else
5052 if (ISALNUM (*p))
5053 goto error; /* Garbage after "[CS]PSR". */
5055 psr_field |= (PSR_c | PSR_f);
5057 *str = p;
5058 return psr_field;
5060 error:
5061 inst.error = _("flag for {c}psr instruction expected");
5062 return FAIL;
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. */
5068 static int
5069 parse_cps_flags (char **str)
5071 int val = 0;
5072 int saw_a_flag = 0;
5073 char *s = *str;
5075 for (;;)
5076 switch (*s++)
5078 case '\0': case ',':
5079 goto done;
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;
5085 default:
5086 inst.error = _("unrecognized CPS flag");
5087 return FAIL;
5090 done:
5091 if (saw_a_flag == 0)
5093 inst.error = _("missing CPS flags");
5094 return FAIL;
5097 *str = s - 1;
5098 return val;
5101 /* Parse an endian specifier ("BE" or "LE", case insensitive);
5102 returns 0 for big-endian, 1 for little-endian, FAIL for an error. */
5104 static int
5105 parse_endian_specifier (char **str)
5107 int little_endian;
5108 char *s = *str;
5110 if (strncasecmp (s, "BE", 2))
5111 little_endian = 0;
5112 else if (strncasecmp (s, "LE", 2))
5113 little_endian = 1;
5114 else
5116 inst.error = _("valid endian specifiers are be or le");
5117 return FAIL;
5120 if (ISALNUM (s[2]) || s[2] == '_')
5122 inst.error = _("valid endian specifiers are be or le");
5123 return FAIL;
5126 *str = s + 2;
5127 return little_endian;
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. */
5134 static int
5135 parse_ror (char **str)
5137 int rot;
5138 char *s = *str;
5140 if (strncasecmp (s, "ROR", 3) == 0)
5141 s += 3;
5142 else
5144 inst.error = _("missing rotation field after comma");
5145 return FAIL;
5148 if (parse_immediate (&s, &rot, 0, 24, FALSE) == FAIL)
5149 return FAIL;
5151 switch (rot)
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;
5158 default:
5159 inst.error = _("rotation can only be 0, 8, 16, or 24");
5160 return FAIL;
5164 /* Parse a conditional code (from conds[] below). The value returned is in the
5165 range 0 .. 14, or FAIL. */
5166 static int
5167 parse_cond (char **str)
5169 char *q;
5170 const struct asm_cond *c;
5171 int n;
5172 /* Condition codes are always 2 characters, so matching up to
5173 3 characters is sufficient. */
5174 char cond[3];
5176 q = *str;
5177 n = 0;
5178 while (ISALPHA (*q) && n < 3)
5180 cond[n] = TOLOWER (*q);
5181 q++;
5182 n++;
5185 c = hash_find_n (arm_cond_hsh, cond, n);
5186 if (!c)
5188 inst.error = _("condition required");
5189 return FAIL;
5192 *str = q;
5193 return c->value;
5196 /* Parse an option for a barrier instruction. Returns the encoding for the
5197 option, or FAIL. */
5198 static int
5199 parse_barrier (char **str)
5201 char *p, *q;
5202 const struct asm_barrier_opt *o;
5204 p = q = *str;
5205 while (ISALPHA (*q))
5206 q++;
5208 o = hash_find_n (arm_barrier_opt_hsh, p, q - p);
5209 if (!o)
5210 return FAIL;
5212 *str = q;
5213 return o->value;
5216 /* Parse the operands of a table branch instruction. Similar to a memory
5217 operand. */
5218 static int
5219 parse_tb (char **str)
5221 char * p = *str;
5222 int reg;
5224 if (skip_past_char (&p, '[') == FAIL)
5226 inst.error = _("'[' expected");
5227 return FAIL;
5230 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5232 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5233 return FAIL;
5235 inst.operands[0].reg = reg;
5237 if (skip_past_comma (&p) == FAIL)
5239 inst.error = _("',' expected");
5240 return FAIL;
5243 if ((reg = arm_reg_parse (&p, REG_TYPE_RN)) == FAIL)
5245 inst.error = _(reg_expected_msgs[REG_TYPE_RN]);
5246 return FAIL;
5248 inst.operands[0].imm = reg;
5250 if (skip_past_comma (&p) == SUCCESS)
5252 if (parse_shift (&p, 0, SHIFT_LSL_IMMEDIATE) == FAIL)
5253 return FAIL;
5254 if (inst.reloc.exp.X_add_number != 1)
5256 inst.error = _("invalid shift");
5257 return FAIL;
5259 inst.operands[0].shifted = 1;
5262 if (skip_past_char (&p, ']') == FAIL)
5264 inst.error = _("']' expected");
5265 return FAIL;
5267 *str = p;
5268 return SUCCESS;
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.
5273 Up to four operands may be read; this function handles setting the
5274 ".present" field for each read operand itself.
5275 Updates STR and WHICH_OPERAND if parsing is successful and returns SUCCESS,
5276 else returns FAIL. */
5278 static int
5279 parse_neon_mov (char **str, int *which_operand)
5281 int i = *which_operand, val;
5282 enum arm_reg_type rtype;
5283 char *ptr = *str;
5284 struct neon_type_el optype;
5286 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
5288 /* Case 4: VMOV<c><q>.<size> <Dn[x]>, <Rd>. */
5289 inst.operands[i].reg = val;
5290 inst.operands[i].isscalar = 1;
5291 inst.operands[i].vectype = optype;
5292 inst.operands[i++].present = 1;
5294 if (skip_past_comma (&ptr) == FAIL)
5295 goto wanted_comma;
5297 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5298 goto wanted_arm;
5300 inst.operands[i].reg = val;
5301 inst.operands[i].isreg = 1;
5302 inst.operands[i].present = 1;
5304 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype, &optype))
5305 != FAIL)
5307 /* Cases 0, 1, 2, 3, 5 (D only). */
5308 if (skip_past_comma (&ptr) == FAIL)
5309 goto wanted_comma;
5311 inst.operands[i].reg = val;
5312 inst.operands[i].isreg = 1;
5313 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5314 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5315 inst.operands[i].isvec = 1;
5316 inst.operands[i].vectype = optype;
5317 inst.operands[i++].present = 1;
5319 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5321 /* Case 5: VMOV<c><q> <Dm>, <Rd>, <Rn>.
5322 Case 13: VMOV <Sd>, <Rm> */
5323 inst.operands[i].reg = val;
5324 inst.operands[i].isreg = 1;
5325 inst.operands[i].present = 1;
5327 if (rtype == REG_TYPE_NQ)
5329 first_error (_("can't use Neon quad register here"));
5330 return FAIL;
5332 else if (rtype != REG_TYPE_VFS)
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;
5344 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_NSDQ, &rtype,
5345 &optype)) != FAIL)
5347 /* Case 0: VMOV<c><q> <Qd>, <Qm>
5348 Case 1: VMOV<c><q> <Dd>, <Dm>
5349 Case 8: VMOV.F32 <Sd>, <Sm>
5350 Case 15: VMOV <Sd>, <Se>, <Rn>, <Rm> */
5352 inst.operands[i].reg = val;
5353 inst.operands[i].isreg = 1;
5354 inst.operands[i].isquad = (rtype == REG_TYPE_NQ);
5355 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5356 inst.operands[i].isvec = 1;
5357 inst.operands[i].vectype = optype;
5358 inst.operands[i].present = 1;
5360 if (skip_past_comma (&ptr) == SUCCESS)
5362 /* Case 15. */
5363 i++;
5365 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5366 goto wanted_arm;
5368 inst.operands[i].reg = val;
5369 inst.operands[i].isreg = 1;
5370 inst.operands[i++].present = 1;
5372 if (skip_past_comma (&ptr) == FAIL)
5373 goto wanted_comma;
5375 if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) == FAIL)
5376 goto wanted_arm;
5378 inst.operands[i].reg = val;
5379 inst.operands[i].isreg = 1;
5380 inst.operands[i++].present = 1;
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> */
5393 else
5395 first_error (_("expected <Rm> or <Dm> or <Qm> operand"));
5396 return FAIL;
5399 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
5401 /* Cases 6, 7. */
5402 inst.operands[i].reg = val;
5403 inst.operands[i].isreg = 1;
5404 inst.operands[i++].present = 1;
5406 if (skip_past_comma (&ptr) == FAIL)
5407 goto wanted_comma;
5409 if ((val = parse_scalar (&ptr, 8, &optype)) != FAIL)
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;
5415 inst.operands[i].vectype = optype;
5417 else if ((val = arm_reg_parse (&ptr, REG_TYPE_RN)) != FAIL)
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;
5424 if (skip_past_comma (&ptr) == FAIL)
5425 goto wanted_comma;
5427 if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFSD, &rtype, &optype))
5428 == FAIL)
5430 first_error (_(reg_expected_msgs[REG_TYPE_VFSD]));
5431 return FAIL;
5434 inst.operands[i].reg = val;
5435 inst.operands[i].isreg = 1;
5436 inst.operands[i].isvec = 1;
5437 inst.operands[i].issingle = (rtype == REG_TYPE_VFS);
5438 inst.operands[i].vectype = optype;
5439 inst.operands[i].present = 1;
5441 if (rtype == REG_TYPE_VFS)
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)
5450 first_error (_(reg_expected_msgs[REG_TYPE_VFS]));
5451 return FAIL;
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;
5461 else if ((val = arm_typed_reg_parse (&ptr, REG_TYPE_VFS, NULL, &optype))
5462 != FAIL)
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;
5473 else
5475 first_error (_("parse error"));
5476 return FAIL;
5479 /* Successfully parsed the operands. Update args. */
5480 *which_operand = i;
5481 *str = ptr;
5482 return SUCCESS;
5484 wanted_comma:
5485 first_error (_("expected comma"));
5486 return FAIL;
5488 wanted_arm:
5489 first_error (_(reg_expected_msgs[REG_TYPE_RN]));
5490 return FAIL;
5493 /* Matcher codes for parse_operands. */
5494 enum operand_parse_code
5496 OP_stop, /* end of line */
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 */
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 */
5509 OP_RVSD, /* VFP single or double precision register */
5510 OP_RNDQ, /* Neon double or quad precision register */
5511 OP_RNSDQ, /* Neon single, double or quad precision register */
5512 OP_RNSC, /* Neon scalar D[X] */
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 */
5525 OP_REGLST, /* ARM register list */
5526 OP_VRSLST, /* VFP single-precision register list */
5527 OP_VRDLST, /* VFP double-precision register list */
5528 OP_VRSDLST, /* VFP single or double-precision register list (& quad) */
5529 OP_NRDLST, /* Neon double-precision register list (d0-d31, qN aliases) */
5530 OP_NSTRLST, /* Neon element/structure list */
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. */
5534 OP_RVSD_I0, /* VFP S or D reg, or immediate zero. */
5535 OP_RR_RNSC, /* ARM reg or Neon scalar. */
5536 OP_RNSDQ_RNSC, /* Vector S, D or Q reg, or Neon scalar. */
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. */
5542 OP_RIWR_I32z, /* iWMMXt wR register, or immediate 0 .. 32 for iWMMXt2. */
5544 OP_I0, /* immediate zero */
5545 OP_I7, /* immediate value 0 .. 7 */
5546 OP_I15, /* 0 .. 15 */
5547 OP_I16, /* 1 .. 16 */
5548 OP_I16z, /* 0 .. 16 */
5549 OP_I31, /* 0 .. 31 */
5550 OP_I31w, /* 0 .. 31, optional trailing ! */
5551 OP_I32, /* 1 .. 32 */
5552 OP_I32z, /* 0 .. 32 */
5553 OP_I63, /* 0 .. 63 */
5554 OP_I63s, /* -64 .. 63 */
5555 OP_I64, /* 1 .. 64 */
5556 OP_I64z, /* 0 .. 64 */
5557 OP_I255, /* 0 .. 255 */
5559 OP_I4b, /* immediate, prefix optional, 1 .. 4 */
5560 OP_I7b, /* 0 .. 7 */
5561 OP_I15b, /* 0 .. 15 */
5562 OP_I31b, /* 0 .. 31 */
5564 OP_SH, /* shifter operand */
5565 OP_SHG, /* shifter operand with possible group relocation */
5566 OP_ADDR, /* Memory address expression (any mode) */
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 */
5570 OP_EXP, /* arbitrary expression */
5571 OP_EXPi, /* same, with optional immediate prefix */
5572 OP_EXPr, /* same, with optional relocation suffix */
5573 OP_HALF, /* 0 .. 65535 or low/high reloc. */
5575 OP_CPSF, /* CPS flags */
5576 OP_ENDI, /* Endianness specifier */
5577 OP_PSR, /* CPSR/SPSR mask for msr */
5578 OP_COND, /* conditional code */
5579 OP_TB, /* Table branch. */
5581 OP_RVC_PSR, /* CPSR/SPSR mask for msr, or VFP control register. */
5582 OP_APSR_RR, /* ARM register or "APSR_nzcv". */
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 */
5589 OP_RIWC_RIWG, /* iWMMXt wC or wCG reg */
5591 /* Optional operands. */
5592 OP_oI7b, /* immediate, prefix optional, 0 .. 7 */
5593 OP_oI31b, /* 0 .. 31 */
5594 OP_oI32b, /* 1 .. 32 */
5595 OP_oIffffb, /* 0 .. 65535 */
5596 OP_oI255c, /* curly-brace enclosed, 0 .. 255 */
5598 OP_oRR, /* ARM register */
5599 OP_oRRnpc, /* ARM register, not the PC */
5600 OP_oRRw, /* ARM register, not r15, optional trailing ! */
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 */
5604 OP_oRNSDQ, /* Optional single, double or quad precision vector register */
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 */
5609 OP_oBARRIER, /* Option argument for a barrier instruction. */
5611 OP_FIRST_OPTIONAL = OP_oI7b
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. */
5618 static int
5619 parse_operands (char *str, const unsigned char *pattern)
5621 unsigned const char *upat = pattern;
5622 char *backtrack_pos = 0;
5623 const char *backtrack_error = 0;
5624 int i, val, backtrack_index = 0;
5625 enum arm_reg_type rtype;
5626 parse_operand_result result;
5628 #define po_char_or_fail(chr) \
5629 do \
5631 if (skip_past_char (&str, chr) == FAIL) \
5632 goto bad_args; \
5634 while (0)
5636 #define po_reg_or_fail(regtype) \
5637 do \
5639 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5640 & inst.operands[i].vectype); \
5641 if (val == FAIL) \
5643 first_error (_(reg_expected_msgs[regtype])); \
5644 goto failure; \
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); \
5654 while (0)
5656 #define po_reg_or_goto(regtype, label) \
5657 do \
5659 val = arm_typed_reg_parse (& str, regtype, & rtype, \
5660 & inst.operands[i].vectype); \
5661 if (val == FAIL) \
5662 goto label; \
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); \
5672 while (0)
5674 #define po_imm_or_fail(min, max, popt) \
5675 do \
5677 if (parse_immediate (&str, &val, min, max, popt) == FAIL) \
5678 goto failure; \
5679 inst.operands[i].imm = val; \
5681 while (0)
5683 #define po_scalar_or_goto(elsz, label) \
5684 do \
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; \
5692 while (0)
5694 #define po_misc_or_fail(expr) \
5695 do \
5697 if (expr) \
5698 goto failure; \
5700 while (0)
5702 #define po_misc_or_fail_no_backtrack(expr) \
5703 do \
5705 result = expr; \
5706 if (result == PARSE_OPERAND_FAIL_NO_BACKTRACK) \
5707 backtrack_pos = 0; \
5708 if (result != PARSE_OPERAND_SUCCESS) \
5709 goto failure; \
5711 while (0)
5713 skip_whitespace (str);
5715 for (i = 0; upat[i] != OP_stop; i++)
5717 if (upat[i] >= OP_FIRST_OPTIONAL)
5719 /* Remember where we are in case we need to backtrack. */
5720 gas_assert (!backtrack_pos);
5721 backtrack_pos = str;
5722 backtrack_error = inst.error;
5723 backtrack_index = i;
5726 if (i > 0 && (i > 1 || inst.operands[0].present))
5727 po_char_or_fail (',');
5729 switch (upat[i])
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;
5741 case OP_oRND:
5742 case OP_RND: po_reg_or_fail (REG_TYPE_VFD); break;
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;
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;
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;
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;
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;
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:
5778 po_reg_or_goto (REG_TYPE_NDQ, try_imm);
5779 inst.operands[i].present = 1;
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:
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)
5796 inst.error = _("immediate value is out of range");
5797 goto failure;
5800 break;
5802 case OP_RNDQ_I0:
5804 po_reg_or_goto (REG_TYPE_NDQ, try_imm0);
5805 break;
5806 try_imm0:
5807 po_imm_or_fail (0, 0, TRUE);
5809 break;
5811 case OP_RVSD_I0:
5812 po_reg_or_goto (REG_TYPE_VFSD, try_imm0);
5813 break;
5815 case OP_RR_RNSC:
5817 po_scalar_or_goto (8, try_rr);
5818 break;
5819 try_rr:
5820 po_reg_or_fail (REG_TYPE_RN);
5822 break;
5824 case OP_RNSDQ_RNSC:
5826 po_scalar_or_goto (8, try_nsdq);
5827 break;
5828 try_nsdq:
5829 po_reg_or_fail (REG_TYPE_NSDQ);
5831 break;
5833 case OP_RNDQ_RNSC:
5835 po_scalar_or_goto (8, try_ndq);
5836 break;
5837 try_ndq:
5838 po_reg_or_fail (REG_TYPE_NDQ);
5840 break;
5842 case OP_RND_RNSC:
5844 po_scalar_or_goto (8, try_vfd);
5845 break;
5846 try_vfd:
5847 po_reg_or_fail (REG_TYPE_VFD);
5849 break;
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;
5857 case OP_RNDQ_IMVNb:
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)
5866 inst.error = _("immediate value is out of range");
5867 goto failure;
5870 break;
5872 case OP_RNDQ_I63b:
5874 po_reg_or_goto (REG_TYPE_NDQ, try_shimm);
5875 break;
5876 try_shimm:
5877 po_imm_or_fail (0, 63, TRUE);
5879 break;
5881 case OP_RRnpcb:
5882 po_char_or_fail ('[');
5883 po_reg_or_fail (REG_TYPE_RN);
5884 po_char_or_fail (']');
5885 break;
5887 case OP_RRw:
5888 case OP_oRRw:
5889 po_reg_or_fail (REG_TYPE_RN);
5890 if (skip_past_char (&str, '!') == SUCCESS)
5891 inst.operands[i].writeback = 1;
5892 break;
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;
5898 case OP_I16z: po_imm_or_fail ( 0, 16, FALSE); break;
5899 case OP_I31: po_imm_or_fail ( 0, 31, FALSE); break;
5900 case OP_I32: po_imm_or_fail ( 1, 32, FALSE); break;
5901 case OP_I32z: po_imm_or_fail ( 0, 32, FALSE); break;
5902 case OP_I63s: po_imm_or_fail (-64, 63, FALSE); break;
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;
5906 case OP_I255: po_imm_or_fail ( 0, 255, FALSE); break;
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;
5914 case OP_oI32b: po_imm_or_fail ( 1, 32, TRUE); break;
5915 case OP_oIffffb: po_imm_or_fail ( 0, 0xffff, TRUE); break;
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;
5924 case OP_I31w:
5925 /* The expression parser chokes on a trailing !, so we have
5926 to find it first and zap it. */
5928 char *s = str;
5929 while (*s && *s != ',')
5930 s++;
5931 if (s[-1] == '!')
5933 s[-1] = '\0';
5934 inst.operands[i].writeback = 1;
5936 po_imm_or_fail (0, 31, TRUE);
5937 if (str == s - 1)
5938 str = s;
5940 break;
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;
5948 case OP_EXP:
5949 po_misc_or_fail (my_get_expression (&inst.reloc.exp, &str,
5950 GE_NO_PREFIX));
5951 break;
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)
5958 val = parse_reloc (&str);
5959 if (val == -1)
5961 inst.error = _("unrecognized relocation suffix");
5962 goto failure;
5964 else if (val != BFD_RELOC_UNUSED)
5966 inst.operands[i].imm = val;
5967 inst.operands[i].hasreloc = 1;
5970 break;
5972 /* Operand for MOVW or MOVT. */
5973 case OP_HALF:
5974 po_misc_or_fail (parse_half (&str));
5975 break;
5977 /* Register or expression. */
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;
5981 /* Register or immediate. */
5982 case OP_RRnpc_I0: po_reg_or_goto (REG_TYPE_RN, I0); break;
5983 I0: po_imm_or_fail (0, 0, FALSE); break;
5985 case OP_RF_IF: po_reg_or_goto (REG_TYPE_FN, IF); break;
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;
5999 case OP_RIWR_I32z: po_reg_or_goto (REG_TYPE_MMXWR, I32z); break;
6000 I32z: po_imm_or_fail (0, 32, FALSE); break;
6002 /* Two kinds of register. */
6003 case OP_RIWR_RIWC:
6005 struct reg_entry *rege = arm_reg_parse_multi (&str);
6006 if (!rege
6007 || (rege->type != REG_TYPE_MMXWR
6008 && rege->type != REG_TYPE_MMXWC
6009 && rege->type != REG_TYPE_MMXWCG))
6011 inst.error = _("iWMMXt data or control register expected");
6012 goto failure;
6014 inst.operands[i].reg = rege->number;
6015 inst.operands[i].isreg = (rege->type == REG_TYPE_MMXWR);
6017 break;
6019 case OP_RIWC_RIWG:
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))
6026 inst.error = _("iWMMXt control register expected");
6027 goto failure;
6029 inst.operands[i].reg = rege->number;
6030 inst.operands[i].isreg = 1;
6032 break;
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;
6040 case OP_oBARRIER:val = parse_barrier (&str); break;
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;
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)
6058 unsigned found = 0;
6059 str += 5;
6060 while (found < 15)
6061 switch (*str++)
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;
6069 if (found != 15)
6070 goto failure;
6071 inst.operands[i].isvec = 1;
6073 else
6074 goto failure;
6075 break;
6077 case OP_TB:
6078 po_misc_or_fail (parse_tb (&str));
6079 break;
6081 /* Register lists. */
6082 case OP_REGLST:
6083 val = parse_reg_list (&str);
6084 if (*str == '^')
6086 inst.operands[1].writeback = 1;
6087 str++;
6089 break;
6091 case OP_VRSLST:
6092 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_S);
6093 break;
6095 case OP_VRDLST:
6096 val = parse_vfp_reg_list (&str, &inst.operands[i].reg, REGLIST_VFP_D);
6097 break;
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)
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;
6110 break;
6112 case OP_NRDLST:
6113 val = parse_vfp_reg_list (&str, &inst.operands[i].reg,
6114 REGLIST_NEON_D);
6115 break;
6117 case OP_NSTRLST:
6118 val = parse_neon_el_struct_list (&str, &inst.operands[i].reg,
6119 &inst.operands[i].vectype);
6120 break;
6122 /* Addressing modes */
6123 case OP_ADDR:
6124 po_misc_or_fail (parse_address (&str, i));
6125 break;
6127 case OP_ADDRGLDR:
6128 po_misc_or_fail_no_backtrack (
6129 parse_address_group_reloc (&str, i, GROUP_LDR));
6130 break;
6132 case OP_ADDRGLDRS:
6133 po_misc_or_fail_no_backtrack (
6134 parse_address_group_reloc (&str, i, GROUP_LDRS));
6135 break;
6137 case OP_ADDRGLDC:
6138 po_misc_or_fail_no_backtrack (
6139 parse_address_group_reloc (&str, i, GROUP_LDC));
6140 break;
6142 case OP_SH:
6143 po_misc_or_fail (parse_shifter_operand (&str, i));
6144 break;
6146 case OP_SHG:
6147 po_misc_or_fail_no_backtrack (
6148 parse_shifter_operand_group_reloc (&str, i));
6149 break;
6151 case OP_oSHll:
6152 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_IMMEDIATE));
6153 break;
6155 case OP_oSHar:
6156 po_misc_or_fail (parse_shift (&str, i, SHIFT_ASR_IMMEDIATE));
6157 break;
6159 case OP_oSHllar:
6160 po_misc_or_fail (parse_shift (&str, i, SHIFT_LSL_OR_ASR_IMMEDIATE));
6161 break;
6163 default:
6164 as_fatal (_("unhandled operand code %d"), upat[i]);
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])
6172 case OP_oRRnpc:
6173 case OP_RRnpc:
6174 case OP_RRnpcb:
6175 case OP_RRw:
6176 case OP_oRRw:
6177 case OP_RRnpc_I0:
6178 if (inst.operands[i].isreg && inst.operands[i].reg == REG_PC)
6179 inst.error = BAD_PC;
6180 break;
6182 case OP_CPSF:
6183 case OP_ENDI:
6184 case OP_oROR:
6185 case OP_PSR:
6186 case OP_RVC_PSR:
6187 case OP_COND:
6188 case OP_oBARRIER:
6189 case OP_REGLST:
6190 case OP_VRSLST:
6191 case OP_VRDLST:
6192 case OP_VRSDLST:
6193 case OP_NRDLST:
6194 case OP_NSTRLST:
6195 if (val == FAIL)
6196 goto failure;
6197 inst.operands[i].imm = val;
6198 break;
6200 default:
6201 break;
6204 /* If we get here, this operand was successfully parsed. */
6205 inst.operands[i].present = 1;
6206 continue;
6208 bad_args:
6209 inst.error = BAD_ARGS;
6211 failure:
6212 if (!backtrack_pos)
6214 /* The parse routine should already have set inst.error, but set a
6215 default here just in case. */
6216 if (!inst.error)
6217 inst.error = _("syntax error");
6218 return FAIL;
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)
6228 if (!inst.error)
6229 inst.error = _("syntax error");
6230 return FAIL;
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;
6241 /* Check that we have parsed all the arguments. */
6242 if (*str != '\0' && !inst.error)
6243 inst.error = _("garbage following instruction");
6245 return inst.error ? FAIL : SUCCESS;
6248 #undef po_char_or_fail
6249 #undef po_reg_or_fail
6250 #undef po_reg_or_goto
6251 #undef po_imm_or_fail
6252 #undef po_scalar_or_fail
6254 /* Shorthand macro for instruction encoding functions issuing errors. */
6255 #define constraint(expr, err) \
6256 do \
6258 if (expr) \
6260 inst.error = err; \
6261 return; \
6264 while (0)
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) \
6273 inst.error = (reg == REG_SP) ? BAD_SP : BAD_PC; \
6274 return; \
6276 while (0)
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)
6286 /* Functions for operand encoding. ARM, then Thumb. */
6288 #define rotate_left(v, n) (v << n | v >> (32 - n))
6290 /* If VAL can be encoded in the immediate field of an ARM instruction,
6291 return the encoded form. Otherwise, return FAIL. */
6293 static unsigned int
6294 encode_arm_immediate (unsigned int val)
6296 unsigned int a, i;
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]. */
6302 return FAIL;
6305 /* If VAL can be encoded in the immediate field of a Thumb32 instruction,
6306 return the encoded form. Otherwise, return FAIL. */
6307 static unsigned int
6308 encode_thumb32_immediate (unsigned int val)
6310 unsigned int a, i;
6312 if (val <= 0xff)
6313 return val;
6315 for (i = 1; i <= 24; i++)
6317 a = val >> i;
6318 if ((val & ~(0xff << i)) == 0)
6319 return ((val >> i) & 0x7f) | ((32 - i) << 7);
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;
6328 a = val & 0xff00;
6329 if (val == ((a << 16) | a))
6330 return 0x200 | (a >> 8);
6332 return FAIL;
6334 /* Encode a VFP SP or DP register number into inst.instruction. */
6336 static void
6337 encode_arm_vfp_reg (int reg, enum vfp_reg_pos pos)
6339 if ((pos == VFP_REG_Dd || pos == VFP_REG_Dn || pos == VFP_REG_Dm)
6340 && reg > 15)
6342 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_d32))
6344 if (thumb_mode)
6345 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
6346 fpu_vfp_ext_d32);
6347 else
6348 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
6349 fpu_vfp_ext_d32);
6351 else
6353 first_error (_("D register out of range for selected VFP version"));
6354 return;
6358 switch (pos)
6360 case VFP_REG_Sd:
6361 inst.instruction |= ((reg >> 1) << 12) | ((reg & 1) << 22);
6362 break;
6364 case VFP_REG_Sn:
6365 inst.instruction |= ((reg >> 1) << 16) | ((reg & 1) << 7);
6366 break;
6368 case VFP_REG_Sm:
6369 inst.instruction |= ((reg >> 1) << 0) | ((reg & 1) << 5);
6370 break;
6372 case VFP_REG_Dd:
6373 inst.instruction |= ((reg & 15) << 12) | ((reg >> 4) << 22);
6374 break;
6376 case VFP_REG_Dn:
6377 inst.instruction |= ((reg & 15) << 16) | ((reg >> 4) << 7);
6378 break;
6380 case VFP_REG_Dm:
6381 inst.instruction |= (reg & 15) | ((reg >> 4) << 5);
6382 break;
6384 default:
6385 abort ();
6389 /* Encode a <shift> in an ARM-format instruction. The immediate,
6390 if any, is handled by md_apply_fix. */
6391 static void
6392 encode_arm_shift (int i)
6394 if (inst.operands[i].shift_kind == SHIFT_RRX)
6395 inst.instruction |= SHIFT_ROR << 5;
6396 else
6398 inst.instruction |= inst.operands[i].shift_kind << 5;
6399 if (inst.operands[i].immisreg)
6401 inst.instruction |= SHIFT_BY_REG;
6402 inst.instruction |= inst.operands[i].imm << 8;
6404 else
6405 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6409 static void
6410 encode_arm_shifter_operand (int i)
6412 if (inst.operands[i].isreg)
6414 inst.instruction |= inst.operands[i].reg;
6415 encode_arm_shift (i);
6417 else
6418 inst.instruction |= INST_IMMEDIATE;
6421 /* Subroutine of encode_arm_addr_mode_2 and encode_arm_addr_mode_3. */
6422 static void
6423 encode_arm_addr_mode_common (int i, bfd_boolean is_t)
6425 gas_assert (inst.operands[i].isreg);
6426 inst.instruction |= inst.operands[i].reg << 16;
6428 if (inst.operands[i].preind)
6430 if (is_t)
6432 inst.error = _("instruction does not accept preindexed addressing");
6433 return;
6435 inst.instruction |= PRE_INDEX;
6436 if (inst.operands[i].writeback)
6437 inst.instruction |= WRITE_BACK;
6440 else if (inst.operands[i].postind)
6442 gas_assert (inst.operands[i].writeback);
6443 if (is_t)
6444 inst.instruction |= WRITE_BACK;
6446 else /* unindexed - only for coprocessor */
6448 inst.error = _("instruction does not accept unindexed addressing");
6449 return;
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"));
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). */
6464 static void
6465 encode_arm_addr_mode_2 (int i, bfd_boolean is_t)
6467 encode_arm_addr_mode_common (i, is_t);
6469 if (inst.operands[i].immisreg)
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)
6477 if (inst.operands[i].shift_kind == SHIFT_RRX)
6478 inst.instruction |= SHIFT_ROR << 5;
6479 else
6481 inst.instruction |= inst.operands[i].shift_kind << 5;
6482 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
6486 else /* immediate offset in inst.reloc */
6488 if (inst.reloc.type == BFD_RELOC_UNUSED)
6489 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM;
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). */
6498 static void
6499 encode_arm_addr_mode_3 (int i, bfd_boolean is_t)
6501 if (inst.operands[i].immisreg && inst.operands[i].shifted)
6503 inst.error = _("instruction does not accept scaled register index");
6504 return;
6507 encode_arm_addr_mode_common (i, is_t);
6509 if (inst.operands[i].immisreg)
6511 inst.instruction |= inst.operands[i].imm;
6512 if (!inst.operands[i].negative)
6513 inst.instruction |= INDEX_UP;
6515 else /* immediate offset in inst.reloc */
6517 inst.instruction |= HWOFFSET_IMM;
6518 if (inst.reloc.type == BFD_RELOC_UNUSED)
6519 inst.reloc.type = BFD_RELOC_ARM_OFFSET_IMM8;
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
6528 of BFD_ARM_CP_OFF_IMM, unless the initial relocation is a group one
6529 (in which case it is preserved). */
6531 static int
6532 encode_arm_cp_address (int i, int wb_ok, int unind_ok, int reloc_override)
6534 inst.instruction |= inst.operands[i].reg << 16;
6536 gas_assert (!(inst.operands[i].preind && inst.operands[i].postind));
6538 if (!inst.operands[i].preind && !inst.operands[i].postind) /* unindexed */
6540 gas_assert (!inst.operands[i].writeback);
6541 if (!unind_ok)
6543 inst.error = _("instruction does not support unindexed addressing");
6544 return FAIL;
6546 inst.instruction |= inst.operands[i].imm;
6547 inst.instruction |= INDEX_UP;
6548 return SUCCESS;
6551 if (inst.operands[i].preind)
6552 inst.instruction |= PRE_INDEX;
6554 if (inst.operands[i].writeback)
6556 if (inst.operands[i].reg == REG_PC)
6558 inst.error = _("pc may not be used with write-back");
6559 return FAIL;
6561 if (!wb_ok)
6563 inst.error = _("instruction does not support writeback");
6564 return FAIL;
6566 inst.instruction |= WRITE_BACK;
6569 if (reloc_override)
6570 inst.reloc.type = reloc_override;
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)
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;
6581 return SUCCESS;
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.
6591 inst.operands[i] describes the destination register. */
6593 static int
6594 move_or_literal_pool (int i, bfd_boolean thumb_p, bfd_boolean mode_3)
6596 unsigned long tbit;
6598 if (thumb_p)
6599 tbit = (inst.instruction > 0xffff) ? THUMB2_LOAD_BIT : THUMB_LOAD_BIT;
6600 else
6601 tbit = LOAD_BIT;
6603 if ((inst.instruction & tbit) == 0)
6605 inst.error = _("invalid pseudo operation");
6606 return 1;
6608 if (inst.reloc.exp.X_op != O_constant && inst.reloc.exp.X_op != O_symbol)
6610 inst.error = _("constant expression expected");
6611 return 1;
6613 if (inst.reloc.exp.X_op == O_constant)
6615 if (thumb_p)
6617 if (!unified_syntax && (inst.reloc.exp.X_add_number & ~0xFF) == 0)
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;
6625 else
6627 int value = encode_arm_immediate (inst.reloc.exp.X_add_number);
6628 if (value != FAIL)
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;
6637 value = encode_arm_immediate (~inst.reloc.exp.X_add_number);
6638 if (value != FAIL)
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;
6649 if (add_to_lit_pool () == FAIL)
6651 inst.error = _("literal pool insertion failed");
6652 return 1;
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;
6666 /* Functions for instruction encoding, sorted by sub-architecture.
6667 First some generics; their names are taken from the conventional
6668 bit positions for register arguments in ARM format instructions. */
6670 static void
6671 do_noargs (void)
6675 static void
6676 do_rd (void)
6678 inst.instruction |= inst.operands[0].reg << 12;
6681 static void
6682 do_rd_rm (void)
6684 inst.instruction |= inst.operands[0].reg << 12;
6685 inst.instruction |= inst.operands[1].reg;
6688 static void
6689 do_rd_rn (void)
6691 inst.instruction |= inst.operands[0].reg << 12;
6692 inst.instruction |= inst.operands[1].reg << 16;
6695 static void
6696 do_rn_rd (void)
6698 inst.instruction |= inst.operands[0].reg << 16;
6699 inst.instruction |= inst.operands[1].reg << 12;
6702 static void
6703 do_rd_rm_rn (void)
6705 unsigned Rn = inst.operands[2].reg;
6706 /* Enforce restrictions on SWP instruction. */
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"));
6710 inst.instruction |= inst.operands[0].reg << 12;
6711 inst.instruction |= inst.operands[1].reg;
6712 inst.instruction |= Rn << 16;
6715 static void
6716 do_rd_rn_rm (void)
6718 inst.instruction |= inst.operands[0].reg << 12;
6719 inst.instruction |= inst.operands[1].reg << 16;
6720 inst.instruction |= inst.operands[2].reg;
6723 static void
6724 do_rm_rd_rn (void)
6726 inst.instruction |= inst.operands[0].reg;
6727 inst.instruction |= inst.operands[1].reg << 12;
6728 inst.instruction |= inst.operands[2].reg << 16;
6731 static void
6732 do_imm0 (void)
6734 inst.instruction |= inst.operands[0].imm;
6737 static void
6738 do_rd_cpaddr (void)
6740 inst.instruction |= inst.operands[0].reg << 12;
6741 encode_arm_cp_address (1, TRUE, TRUE, 0);
6744 /* ARM instructions, in alphabetical order by function name (except
6745 that wrapper functions appear immediately after the function they
6746 wrap). */
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". */
6751 static void
6752 do_adr (void)
6754 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
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;
6759 inst.reloc.pc_rel = 1;
6760 inst.reloc.exp.X_add_number -= 8;
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)" */
6768 static void
6769 do_adrl (void)
6771 inst.instruction |= (inst.operands[0].reg << 12); /* Rd */
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;
6776 inst.reloc.pc_rel = 1;
6777 inst.size = INSN_SIZE * 2;
6778 inst.reloc.exp.X_add_number -= 8;
6781 static void
6782 do_arit (void)
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);
6791 static void
6792 do_barrier (void)
6794 if (inst.operands[0].present)
6796 constraint ((inst.instruction & 0xf0) != 0x40
6797 && inst.operands[0].imm != 0xf,
6798 _("bad barrier type"));
6799 inst.instruction |= inst.operands[0].imm;
6801 else
6802 inst.instruction |= 0xf;
6805 static void
6806 do_bfc (void)
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;
6817 static void
6818 do_bfi (void)
6820 unsigned int msb;
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;
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;
6837 static void
6838 do_bfx (void)
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;
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. */
6854 static void
6855 do_bkpt (void)
6857 /* Top 12 of 16 bits to bits 19:8. */
6858 inst.instruction |= (inst.operands[0].imm & 0xfff0) << 4;
6860 /* Bottom 4 of 16 bits to bits 3:0. */
6861 inst.instruction |= inst.operands[0].imm & 0xf;
6864 static void
6865 encode_branch (int default_reloc)
6867 if (inst.operands[0].hasreloc)
6869 constraint (inst.operands[0].imm != BFD_RELOC_ARM_PLT32,
6870 _("the only suffix valid here is '(plt)'"));
6871 inst.reloc.type = BFD_RELOC_ARM_PLT32;
6873 else
6875 inst.reloc.type = default_reloc;
6877 inst.reloc.pc_rel = 1;
6880 static void
6881 do_branch (void)
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);
6891 static void
6892 do_bl (void)
6894 #ifdef OBJ_ELF
6895 if (EF_ARM_EABI_VERSION (meabi_flags) >= EF_ARM_EABI_VER4)
6897 if (inst.cond == COND_ALWAYS)
6898 encode_branch (BFD_RELOC_ARM_PCREL_CALL);
6899 else
6900 encode_branch (BFD_RELOC_ARM_PCREL_JUMP);
6902 else
6903 #endif
6904 encode_branch (BFD_RELOC_ARM_PCREL_BRANCH);
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. */
6915 static void
6916 do_blx (void)
6918 if (inst.operands[0].isreg)
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"));
6925 inst.instruction |= inst.operands[0].reg;
6927 else
6929 /* Arg is an address; this instruction cannot be executed
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. */
6933 constraint (inst.cond != COND_ALWAYS, BAD_COND);
6934 inst.instruction = 0xfa000000;
6935 encode_branch (BFD_RELOC_ARM_PCREL_BLX);
6939 static void
6940 do_bx (void)
6942 bfd_boolean want_reloc;
6944 if (inst.operands[0].reg == REG_PC)
6945 as_tsktsk (_("use of r15 in bx in ARM mode is not really useful"));
6947 inst.instruction |= inst.operands[0].reg;
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;
6954 #ifdef OBJ_ELF
6955 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
6956 #endif
6957 want_reloc = FALSE;
6959 if (want_reloc)
6960 inst.reloc.type = BFD_RELOC_ARM_V4BX;
6964 /* ARM v5TEJ. Jump to Jazelle code. */
6966 static void
6967 do_bxj (void)
6969 if (inst.operands[0].reg == REG_PC)
6970 as_tsktsk (_("use of r15 in bxj is not really useful"));
6972 inst.instruction |= inst.operands[0].reg;
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>} */
6978 static void
6979 do_cdp (void)
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;
6989 static void
6990 do_cmp (void)
6992 inst.instruction |= inst.operands[0].reg << 16;
6993 encode_arm_shifter_operand (1);
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
7002 No special properties. */
7004 static void
7005 do_co_reg (void)
7007 unsigned Rd;
7009 Rd = inst.operands[2].reg;
7010 if (thumb_mode)
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);
7020 else
7022 /* MCR */
7023 if (inst.instruction == 0xe000010)
7024 constraint (Rd == REG_PC, BAD_PC);
7028 inst.instruction |= inst.operands[0].reg << 8;
7029 inst.instruction |= inst.operands[1].imm << 21;
7030 inst.instruction |= Rd << 12;
7031 inst.instruction |= inst.operands[3].reg << 16;
7032 inst.instruction |= inst.operands[4].reg;
7033 inst.instruction |= inst.operands[5].imm << 5;
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
7042 Two XScale instructions are special cases of these:
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
7047 Result unpredictable if Rd or Rn is R15. */
7049 static void
7050 do_co_reg2c (void)
7052 unsigned Rd, Rn;
7054 Rd = inst.operands[2].reg;
7055 Rn = inst.operands[3].reg;
7057 if (thumb_mode)
7059 reject_bad_reg (Rd);
7060 reject_bad_reg (Rn);
7062 else
7064 constraint (Rd == REG_PC, BAD_PC);
7065 constraint (Rn == REG_PC, BAD_PC);
7068 inst.instruction |= inst.operands[0].reg << 8;
7069 inst.instruction |= inst.operands[1].imm << 4;
7070 inst.instruction |= Rd << 12;
7071 inst.instruction |= Rn << 16;
7072 inst.instruction |= inst.operands[4].reg;
7075 static void
7076 do_cpsi (void)
7078 inst.instruction |= inst.operands[0].imm << 6;
7079 if (inst.operands[1].present)
7081 inst.instruction |= CPSI_MMOD;
7082 inst.instruction |= inst.operands[1].imm;
7086 static void
7087 do_dbg (void)
7089 inst.instruction |= inst.operands[0].imm;
7092 static void
7093 do_it (void)
7095 /* There is no IT instruction in ARM mode. We
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. */
7100 inst.size = 0;
7101 if (unified_syntax)
7103 set_it_insn_type (IT_INSN);
7104 now_it.mask = (inst.instruction & 0xf) | 0x10;
7105 now_it.cc = inst.operands[0].imm;
7109 static void
7110 do_ldmstm (void)
7112 int base_reg = inst.operands[0].reg;
7113 int range = inst.operands[1].imm;
7115 inst.instruction |= base_reg << 16;
7116 inst.instruction |= range;
7118 if (inst.operands[1].writeback)
7119 inst.instruction |= LDM_TYPE_2_OR_3;
7121 if (inst.operands[0].writeback)
7123 inst.instruction |= WRITE_BACK;
7124 /* Check for unpredictable uses of writeback. */
7125 if (inst.instruction & LOAD_BIT)
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"));
7135 else /* STM. */
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"));
7148 /* ARMv5TE load-consecutive (argument parse)
7149 Mode is like LDRH.
7151 LDRccD R, mode
7152 STRccD R, mode. */
7154 static void
7155 do_ldrd (void)
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"));
7165 if (!inst.operands[1].present)
7166 inst.operands[1].reg = inst.operands[0].reg + 1;
7168 if (inst.instruction & LOAD_BIT)
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. */
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"));
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
7182 && ((unsigned) inst.operands[2].imm == inst.operands[0].reg
7183 || (unsigned) inst.operands[2].imm == inst.operands[1].reg))
7184 as_warn (_("index register overlaps destination register"));
7187 inst.instruction |= inst.operands[0].reg << 12;
7188 encode_arm_addr_mode_3 (2, /*is_t=*/FALSE);
7191 static void
7192 do_ldrex (void)
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
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);
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"));
7216 inst.instruction |= inst.operands[0].reg << 12;
7217 inst.instruction |= inst.operands[1].reg << 16;
7218 inst.reloc.type = BFD_RELOC_UNUSED;
7221 static void
7222 do_ldrexd (void)
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"));
7233 inst.instruction |= inst.operands[0].reg << 12;
7234 inst.instruction |= inst.operands[2].reg << 16;
7237 static void
7238 do_ldst (void)
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))
7243 return;
7244 encode_arm_addr_mode_2 (1, /*is_t=*/FALSE);
7247 static void
7248 do_ldstt (void)
7250 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7251 reject [Rn,...]. */
7252 if (inst.operands[1].preind)
7254 constraint (inst.reloc.exp.X_op != O_constant
7255 || inst.reloc.exp.X_add_number != 0,
7256 _("this instruction requires a post-indexed address"));
7258 inst.operands[1].preind = 0;
7259 inst.operands[1].postind = 1;
7260 inst.operands[1].writeback = 1;
7262 inst.instruction |= inst.operands[0].reg << 12;
7263 encode_arm_addr_mode_2 (1, /*is_t=*/TRUE);
7266 /* Halfword and signed-byte load/store operations. */
7268 static void
7269 do_ldstv4 (void)
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))
7274 return;
7275 encode_arm_addr_mode_3 (1, /*is_t=*/FALSE);
7278 static void
7279 do_ldsttv4 (void)
7281 /* ldrt/strt always use post-indexed addressing. Turn [Rn] into [Rn]! and
7282 reject [Rn,...]. */
7283 if (inst.operands[1].preind)
7285 constraint (inst.reloc.exp.X_op != O_constant
7286 || inst.reloc.exp.X_add_number != 0,
7287 _("this instruction requires a post-indexed address"));
7289 inst.operands[1].preind = 0;
7290 inst.operands[1].postind = 1;
7291 inst.operands[1].writeback = 1;
7293 inst.instruction |= inst.operands[0].reg << 12;
7294 encode_arm_addr_mode_3 (1, /*is_t=*/TRUE);
7297 /* Co-processor register load/store.
7298 Format: <LDC|STC>{cond}[L] CP#,CRd,<address> */
7299 static void
7300 do_lstc (void)
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);
7307 static void
7308 do_mlas (void)
7310 /* This restriction does not apply to mls (nor to mla in v6 or later). */
7311 if (inst.operands[0].reg == inst.operands[1].reg
7312 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6)
7313 && !(inst.instruction & 0x00400000))
7314 as_tsktsk (_("Rd and Rm should be different in mla"));
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;
7322 static void
7323 do_mov (void)
7325 inst.instruction |= inst.operands[0].reg << 12;
7326 encode_arm_shifter_operand (1);
7329 /* ARM V6T2 16-bit immediate register load: MOV[WT]{cond} Rd, #<imm16>. */
7330 static void
7331 do_mov16 (void)
7333 bfd_vma imm;
7334 bfd_boolean top;
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"));
7341 inst.instruction |= inst.operands[0].reg << 12;
7342 if (inst.reloc.type == BFD_RELOC_UNUSED)
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;
7351 static void do_vfp_nsyn_opcode (const char *);
7353 static int
7354 do_vfp_nsyn_mrs (void)
7356 if (inst.operands[0].isvec)
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");
7364 else if (inst.operands[1].isvec)
7365 do_vfp_nsyn_opcode ("fmrx");
7366 else
7367 return FAIL;
7369 return SUCCESS;
7372 static int
7373 do_vfp_nsyn_msr (void)
7375 if (inst.operands[0].isvec)
7376 do_vfp_nsyn_opcode ("fmxr");
7377 else
7378 return FAIL;
7380 return SUCCESS;
7383 static void
7384 do_mrs (void)
7386 if (do_vfp_nsyn_mrs () == SUCCESS)
7387 return;
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);
7397 /* Two possible forms:
7398 "{C|S}PSR_<field>, Rm",
7399 "{C|S}PSR_f, #expression". */
7401 static void
7402 do_msr (void)
7404 if (do_vfp_nsyn_msr () == SUCCESS)
7405 return;
7407 inst.instruction |= inst.operands[0].imm;
7408 if (inst.operands[1].isreg)
7409 inst.instruction |= inst.operands[1].reg;
7410 else
7412 inst.instruction |= INST_IMMEDIATE;
7413 inst.reloc.type = BFD_RELOC_ARM_IMMEDIATE;
7414 inst.reloc.pc_rel = 0;
7418 static void
7419 do_mul (void)
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;
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"));
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. */
7438 static void
7439 do_mull (void)
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;
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"));
7450 /* rdhi, rdlo and rm must all be different before armv6. */
7451 if ((inst.operands[0].reg == inst.operands[2].reg
7452 || inst.operands[1].reg == inst.operands[2].reg)
7453 && !ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6))
7454 as_tsktsk (_("rdhi, rdlo and rm must all be different"));
7457 static void
7458 do_nop (void)
7460 if (inst.operands[0].present
7461 || ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k))
7463 /* Architectural NOP hints are CPSR sets with no bits selected. */
7464 inst.instruction &= 0xf0000000;
7465 inst.instruction |= 0x0320f000;
7466 if (inst.operands[0].present)
7467 inst.instruction |= inst.operands[0].imm;
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. */
7476 static void
7477 do_pkhbt (void)
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);
7486 /* ARM V6 PKHTB (Argument Parse). */
7488 static void
7489 do_pkhtb (void)
7491 if (!inst.operands[3].present)
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;
7500 else
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);
7509 /* ARMv5TE: Preload-Cache
7511 PLD <addr_mode>
7513 Syntactically, like LDR with B=1, W=0, L=1. */
7515 static void
7516 do_pld (void)
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"));
7526 encode_arm_addr_mode_2 (0, /*is_t=*/FALSE);
7529 /* ARMv7: PLI <addr_mode> */
7530 static void
7531 do_pli (void)
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;
7545 static void
7546 do_push_pop (void)
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 ();
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. */
7562 static void
7563 do_rfe (void)
7565 inst.instruction |= inst.operands[0].reg << 16;
7566 if (inst.operands[0].writeback)
7567 inst.instruction |= WRITE_BACK;
7570 /* ARM V6 ssat (argument parse). */
7572 static void
7573 do_ssat (void)
7575 inst.instruction |= inst.operands[0].reg << 12;
7576 inst.instruction |= (inst.operands[1].imm - 1) << 16;
7577 inst.instruction |= inst.operands[2].reg;
7579 if (inst.operands[3].present)
7580 encode_arm_shift (3);
7583 /* ARM V6 usat (argument parse). */
7585 static void
7586 do_usat (void)
7588 inst.instruction |= inst.operands[0].reg << 12;
7589 inst.instruction |= inst.operands[1].imm << 16;
7590 inst.instruction |= inst.operands[2].reg;
7592 if (inst.operands[3].present)
7593 encode_arm_shift (3);
7596 /* ARM V6 ssat16 (argument parse). */
7598 static void
7599 do_ssat16 (void)
7601 inst.instruction |= inst.operands[0].reg << 12;
7602 inst.instruction |= ((inst.operands[1].imm - 1) << 16);
7603 inst.instruction |= inst.operands[2].reg;
7606 static void
7607 do_usat16 (void)
7609 inst.instruction |= inst.operands[0].reg << 12;
7610 inst.instruction |= inst.operands[1].imm << 16;
7611 inst.instruction |= inst.operands[2].reg;
7614 /* ARM V6 SETEND (argument parse). Sets the E bit in the CPSR while
7615 preserving the other bits.
7617 setend <endian_specifier>, where <endian_specifier> is either
7618 BE or LE. */
7620 static void
7621 do_setend (void)
7623 if (inst.operands[0].imm)
7624 inst.instruction |= 0x200;
7627 static void
7628 do_shift (void)
7630 unsigned int Rm = (inst.operands[1].present
7631 ? inst.operands[1].reg
7632 : inst.operands[0].reg);
7634 inst.instruction |= inst.operands[0].reg << 12;
7635 inst.instruction |= Rm;
7636 if (inst.operands[2].isreg) /* Rd, {Rm,} Rs */
7638 inst.instruction |= inst.operands[2].reg << 8;
7639 inst.instruction |= SHIFT_BY_REG;
7641 else
7642 inst.reloc.type = BFD_RELOC_ARM_SHIFT_IMM;
7645 static void
7646 do_smc (void)
7648 inst.reloc.type = BFD_RELOC_ARM_SMC;
7649 inst.reloc.pc_rel = 0;
7652 static void
7653 do_swi (void)
7655 inst.reloc.type = BFD_RELOC_ARM_SWI;
7656 inst.reloc.pc_rel = 0;
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. */
7664 static void
7665 do_smla (void)
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;
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. */
7678 static void
7679 do_smlal (void)
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;
7686 if (inst.operands[0].reg == inst.operands[1].reg)
7687 as_tsktsk (_("rdhi and rdlo must be different"));
7690 /* ARM V5E (El Segundo) signed-multiply (argument parse)
7691 SMULxy{cond} Rd,Rm,Rs
7692 Error if any register is R15. */
7694 static void
7695 do_smul (void)
7697 inst.instruction |= inst.operands[0].reg << 16;
7698 inst.instruction |= inst.operands[1].reg;
7699 inst.instruction |= inst.operands[2].reg << 8;
7702 /* ARM V6 srs (argument parse). The variable fields in the encoding are
7703 the same for both ARM and Thumb-2. */
7705 static void
7706 do_srs (void)
7708 int reg;
7710 if (inst.operands[0].present)
7712 reg = inst.operands[0].reg;
7713 constraint (reg != REG_SP, _("SRS base register must be r13"));
7715 else
7716 reg = REG_SP;
7718 inst.instruction |= reg << 16;
7719 inst.instruction |= inst.operands[1].imm;
7720 if (inst.operands[0].writeback || inst.operands[1].writeback)
7721 inst.instruction |= WRITE_BACK;
7724 /* ARM V6 strex (argument parse). */
7726 static void
7727 do_strex (void)
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
7732 || inst.operands[2].negative
7733 /* See comment in do_ldrex(). */
7734 || (inst.operands[2].reg == REG_PC),
7735 BAD_ADDR_MODE);
7737 constraint (inst.operands[0].reg == inst.operands[1].reg
7738 || inst.operands[0].reg == inst.operands[2].reg, BAD_OVERLAP);
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"));
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;
7750 static void
7751 do_strexd (void)
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"));
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);
7767 inst.instruction |= inst.operands[0].reg << 12;
7768 inst.instruction |= inst.operands[1].reg;
7769 inst.instruction |= inst.operands[3].reg << 16;
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. */
7780 static void
7781 do_sxtah (void)
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;
7789 /* ARM V6 SXTH.
7791 SXTH {<cond>} <Rd>, <Rm>{, <rotation>}
7792 Condition defaults to COND_ALWAYS.
7793 Error if any register uses R15. */
7795 static void
7796 do_sxth (void)
7798 inst.instruction |= inst.operands[0].reg << 12;
7799 inst.instruction |= inst.operands[1].reg;
7800 inst.instruction |= inst.operands[2].imm << 10;
7803 /* VFP instructions. In a logical order: SP variant first, monad
7804 before dyad, arithmetic then move then load/store. */
7806 static void
7807 do_vfp_sp_monadic (void)
7809 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7810 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7813 static void
7814 do_vfp_sp_dyadic (void)
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);
7821 static void
7822 do_vfp_sp_compare_z (void)
7824 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7827 static void
7828 do_vfp_dp_sp_cvt (void)
7830 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7831 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sm);
7834 static void
7835 do_vfp_sp_dp_cvt (void)
7837 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7838 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7841 static void
7842 do_vfp_reg_from_sp (void)
7844 inst.instruction |= inst.operands[0].reg << 12;
7845 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sn);
7848 static void
7849 do_vfp_reg2_from_sp2 (void)
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;
7855 encode_arm_vfp_reg (inst.operands[2].reg, VFP_REG_Sm);
7858 static void
7859 do_vfp_sp_from_reg (void)
7861 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sn);
7862 inst.instruction |= inst.operands[1].reg << 12;
7865 static void
7866 do_vfp_sp2_from_reg2 (void)
7868 constraint (inst.operands[0].imm != 2,
7869 _("only two consecutive VFP SP registers allowed here"));
7870 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sm);
7871 inst.instruction |= inst.operands[1].reg << 12;
7872 inst.instruction |= inst.operands[2].reg << 16;
7875 static void
7876 do_vfp_sp_ldst (void)
7878 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
7879 encode_arm_cp_address (1, FALSE, TRUE, 0);
7882 static void
7883 do_vfp_dp_ldst (void)
7885 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7886 encode_arm_cp_address (1, FALSE, TRUE, 0);
7890 static void
7891 vfp_sp_ldstm (enum vfp_ldstm_type ldstm_type)
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;
7899 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Sd);
7900 inst.instruction |= inst.operands[1].imm;
7903 static void
7904 vfp_dp_ldstm (enum vfp_ldstm_type ldstm_type)
7906 int count;
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"));
7914 inst.instruction |= inst.operands[0].reg << 16;
7915 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7917 count = inst.operands[1].imm << 1;
7918 if (ldstm_type == VFP_LDSTMIAX || ldstm_type == VFP_LDSTMDBX)
7919 count += 1;
7921 inst.instruction |= count;
7924 static void
7925 do_vfp_sp_ldstmia (void)
7927 vfp_sp_ldstm (VFP_LDSTMIA);
7930 static void
7931 do_vfp_sp_ldstmdb (void)
7933 vfp_sp_ldstm (VFP_LDSTMDB);
7936 static void
7937 do_vfp_dp_ldstmia (void)
7939 vfp_dp_ldstm (VFP_LDSTMIA);
7942 static void
7943 do_vfp_dp_ldstmdb (void)
7945 vfp_dp_ldstm (VFP_LDSTMDB);
7948 static void
7949 do_vfp_xp_ldstmia (void)
7951 vfp_dp_ldstm (VFP_LDSTMIAX);
7954 static void
7955 do_vfp_xp_ldstmdb (void)
7957 vfp_dp_ldstm (VFP_LDSTMDBX);
7960 static void
7961 do_vfp_dp_rd_rm (void)
7963 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7964 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dm);
7967 static void
7968 do_vfp_dp_rn_rd (void)
7970 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dn);
7971 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dd);
7974 static void
7975 do_vfp_dp_rd_rn (void)
7977 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7978 encode_arm_vfp_reg (inst.operands[1].reg, VFP_REG_Dn);
7981 static void
7982 do_vfp_dp_rd_rn_rm (void)
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);
7989 static void
7990 do_vfp_dp_rd (void)
7992 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
7995 static void
7996 do_vfp_dp_rm_rd_rn (void)
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);
8003 /* VFPv3 instructions. */
8004 static void
8005 do_vfp_sp_const (void)
8007 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8008 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8009 inst.instruction |= (inst.operands[1].imm & 0x0f);
8012 static void
8013 do_vfp_dp_const (void)
8015 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8016 inst.instruction |= (inst.operands[1].imm & 0xf0) << 12;
8017 inst.instruction |= (inst.operands[1].imm & 0x0f);
8020 static void
8021 vfp_conv (int srcsize)
8023 unsigned immbits = srcsize - inst.operands[1].imm;
8024 inst.instruction |= (immbits & 1) << 5;
8025 inst.instruction |= (immbits >> 1);
8028 static void
8029 do_vfp_sp_conv_16 (void)
8031 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8032 vfp_conv (16);
8035 static void
8036 do_vfp_dp_conv_16 (void)
8038 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8039 vfp_conv (16);
8042 static void
8043 do_vfp_sp_conv_32 (void)
8045 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Sd);
8046 vfp_conv (32);
8049 static void
8050 do_vfp_dp_conv_32 (void)
8052 encode_arm_vfp_reg (inst.operands[0].reg, VFP_REG_Dd);
8053 vfp_conv (32);
8056 /* FPA instructions. Also in a logical order. */
8058 static void
8059 do_fpa_cmp (void)
8061 inst.instruction |= inst.operands[0].reg << 16;
8062 inst.instruction |= inst.operands[1].reg;
8065 static void
8066 do_fpa_ldmstm (void)
8068 inst.instruction |= inst.operands[0].reg << 12;
8069 switch (inst.operands[1].imm)
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 ();
8078 if (inst.instruction & (PRE_INDEX | INDEX_UP))
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"));
8088 if ((inst.instruction & PRE_INDEX) || inst.operands[2].writeback)
8089 inst.reloc.exp.X_add_number = 12 * inst.operands[1].imm;
8091 if (!(inst.instruction & INDEX_UP))
8092 inst.reloc.exp.X_add_number = -inst.reloc.exp.X_add_number;
8094 if (!(inst.instruction & PRE_INDEX) && inst.operands[2].writeback)
8096 inst.operands[2].preind = 0;
8097 inst.operands[2].postind = 1;
8101 encode_arm_cp_address (2, TRUE, TRUE, 0);
8104 /* iWMMXt instructions: strictly in alphabetical order. */
8106 static void
8107 do_iwmmxt_tandorc (void)
8109 constraint (inst.operands[0].reg != REG_PC, _("only r15 allowed here"));
8112 static void
8113 do_iwmmxt_textrc (void)
8115 inst.instruction |= inst.operands[0].reg << 12;
8116 inst.instruction |= inst.operands[1].imm;
8119 static void
8120 do_iwmmxt_textrm (void)
8122 inst.instruction |= inst.operands[0].reg << 12;
8123 inst.instruction |= inst.operands[1].reg << 16;
8124 inst.instruction |= inst.operands[2].imm;
8127 static void
8128 do_iwmmxt_tinsr (void)
8130 inst.instruction |= inst.operands[0].reg << 16;
8131 inst.instruction |= inst.operands[1].reg << 12;
8132 inst.instruction |= inst.operands[2].imm;
8135 static void
8136 do_iwmmxt_tmia (void)
8138 inst.instruction |= inst.operands[0].reg << 5;
8139 inst.instruction |= inst.operands[1].reg;
8140 inst.instruction |= inst.operands[2].reg << 12;
8143 static void
8144 do_iwmmxt_waligni (void)
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;
8152 static void
8153 do_iwmmxt_wmerge (void)
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;
8161 static void
8162 do_iwmmxt_wmov (void)
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;
8170 static void
8171 do_iwmmxt_wldstbh (void)
8173 int reloc;
8174 inst.instruction |= inst.operands[0].reg << 12;
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);
8182 static void
8183 do_iwmmxt_wldstw (void)
8185 /* RIWR_RIWC clears .isreg for a control register. */
8186 if (!inst.operands[0].isreg)
8188 constraint (inst.cond != COND_ALWAYS, BAD_COND);
8189 inst.instruction |= 0xf0000000;
8192 inst.instruction |= inst.operands[0].reg << 12;
8193 encode_arm_cp_address (1, TRUE, TRUE, 0);
8196 static void
8197 do_iwmmxt_wldstd (void)
8199 inst.instruction |= inst.operands[0].reg << 12;
8200 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_iwmmxt2)
8201 && inst.operands[1].immisreg)
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;
8215 else
8216 encode_arm_cp_address (1, TRUE, FALSE, 0);
8219 static void
8220 do_iwmmxt_wshufh (void)
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);
8228 static void
8229 do_iwmmxt_wzero (void)
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;
8237 static void
8238 do_iwmmxt_wrwrwr_or_imm5 (void)
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)
8248 switch ((inst.instruction >> 20) & 0xf)
8250 case 4:
8251 case 5:
8252 case 6:
8253 case 7:
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:
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;
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);
8287 /* Cirrus Maverick instructions. Simple 2-, 3-, and 4-register
8288 operations first, then control, shift, and load/store. */
8290 /* Insns like "foo X,Y,Z". */
8292 static void
8293 do_mav_triple (void)
8295 inst.instruction |= inst.operands[0].reg << 16;
8296 inst.instruction |= inst.operands[1].reg;
8297 inst.instruction |= inst.operands[2].reg << 12;
8300 /* Insns like "foo W,X,Y,Z".
8301 where W=MVAX[0:3] and X,Y,Z=MVFX[0:15]. */
8303 static void
8304 do_mav_quad (void)
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;
8312 /* cfmvsc32<cond> DSPSC,MVDX[15:0]. */
8313 static void
8314 do_mav_dspsc (void)
8316 inst.instruction |= inst.operands[1].reg << 12;
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]. */
8323 static void
8324 do_mav_shift (void)
8326 int imm = inst.operands[2].imm;
8328 inst.instruction |= inst.operands[0].reg << 12;
8329 inst.instruction |= inst.operands[1].reg << 16;
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);
8336 inst.instruction |= imm;
8339 /* XScale instructions. Also sorted arithmetic before move. */
8341 /* Xscale multiply-accumulate (argument parse)
8342 MIAcc acc0,Rm,Rs
8343 MIAPHcc acc0,Rm,Rs
8344 MIAxycc acc0,Rm,Rs. */
8346 static void
8347 do_xsc_mia (void)
8349 inst.instruction |= inst.operands[1].reg;
8350 inst.instruction |= inst.operands[2].reg << 12;
8353 /* Xscale move-accumulator-register (argument parse)
8355 MARcc acc0,RdLo,RdHi. */
8357 static void
8358 do_xsc_mar (void)
8360 inst.instruction |= inst.operands[1].reg << 12;
8361 inst.instruction |= inst.operands[2].reg << 16;
8364 /* Xscale move-register-accumulator (argument parse)
8366 MRAcc RdLo,RdHi,acc0. */
8368 static void
8369 do_xsc_mra (void)
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;
8376 /* Encoding functions relevant only to Thumb. */
8378 /* inst.operands[i] is a shifted-register operand; encode
8379 it into inst.instruction in the format used by Thumb32. */
8381 static void
8382 encode_thumb32_shifted_operand (int i)
8384 unsigned int value = inst.reloc.exp.X_add_number;
8385 unsigned int shift = inst.operands[i].shift_kind;
8387 constraint (inst.operands[i].immisreg,
8388 _("shift by register not allowed in thumb mode"));
8389 inst.instruction |= inst.operands[i].reg;
8390 if (shift == SHIFT_RRX)
8391 inst.instruction |= SHIFT_ROR << 4;
8392 else
8394 constraint (inst.reloc.exp.X_op != O_constant,
8395 _("expression too complex"));
8397 constraint (value > 32
8398 || (value == 32 && (shift == SHIFT_LSL
8399 || shift == SHIFT_ROR)),
8400 _("shift expression is too large"));
8402 if (value == 0)
8403 shift = SHIFT_LSL;
8404 else if (value == 32)
8405 value = 0;
8407 inst.instruction |= shift << 4;
8408 inst.instruction |= (value & 0x1c) << 10;
8409 inst.instruction |= (value & 0x03) << 6;
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. */
8420 static void
8421 encode_thumb32_addr_mode (int i, bfd_boolean is_t, bfd_boolean is_d)
8423 bfd_boolean is_pc = (inst.operands[i].reg == REG_PC);
8425 constraint (!inst.operands[i].isreg,
8426 _("Instruction does not support =N addresses"));
8428 inst.instruction |= inst.operands[i].reg << 16;
8429 if (inst.operands[i].immisreg)
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"));
8442 inst.instruction |= inst.operands[i].imm;
8443 if (inst.operands[i].shifted)
8445 constraint (inst.reloc.exp.X_op != O_constant,
8446 _("expression too complex"));
8447 constraint (inst.reloc.exp.X_add_number < 0
8448 || inst.reloc.exp.X_add_number > 3,
8449 _("shift out of range"));
8450 inst.instruction |= inst.reloc.exp.X_add_number << 4;
8452 inst.reloc.type = BFD_RELOC_UNUSED;
8454 else if (inst.operands[i].preind)
8456 constraint (is_pc && inst.operands[i].writeback,
8457 _("cannot use writeback with PC-relative addressing"));
8458 constraint (is_t && inst.operands[i].writeback,
8459 _("cannot use writeback with this instruction"));
8461 if (is_d)
8463 inst.instruction |= 0x01000000;
8464 if (inst.operands[i].writeback)
8465 inst.instruction |= 0x00200000;
8467 else
8469 inst.instruction |= 0x00000c00;
8470 if (inst.operands[i].writeback)
8471 inst.instruction |= 0x00000100;
8473 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8475 else if (inst.operands[i].postind)
8477 gas_assert (inst.operands[i].writeback);
8478 constraint (is_pc, _("cannot use post-indexing with PC-relative addressing"));
8479 constraint (is_t, _("cannot use post-indexing with this instruction"));
8481 if (is_d)
8482 inst.instruction |= 0x00200000;
8483 else
8484 inst.instruction |= 0x00000900;
8485 inst.reloc.type = BFD_RELOC_ARM_T32_OFFSET_IMM;
8487 else /* unindexed - only for coprocessor */
8488 inst.error = _("instruction does not accept unindexed addressing");
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
8495 holds variant (1).
8496 Also contains several pseudo-instructions used during relaxation. */
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), \
8502 X(addi, 0000, f1000000), \
8503 X(addis, 0000, f1100000), \
8504 X(add_pc,000f, f20f0000), \
8505 X(add_sp,000d, f10d0000), \
8506 X(adr, 000f, f20f0000), \
8507 X(and, 4000, ea000000), \
8508 X(ands, 4000, ea100000), \
8509 X(asr, 1000, fa40f000), \
8510 X(asrs, 1000, fa50f000), \
8511 X(b, e000, f000b000), \
8512 X(bcond, d000, f0008000), \
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), \
8520 X(dec_sp,80dd, f1ad0d00), \
8521 X(eor, 4040, ea800000), \
8522 X(eors, 4040, ea900000), \
8523 X(inc_sp,00dd, f10d0d00), \
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), \
8530 X(ldr_pc,4800, f85f0000), \
8531 X(ldr_pc2,4800, f85f0000), \
8532 X(ldr_sp,9800, f85d0000), \
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), \
8547 X(pop, bc00, e8bd0000), /* ldmia sp!,... */ \
8548 X(push, b400, e92d0000), /* stmdb sp!,... */ \
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), \
8560 X(str_sp,9000, f84d0000), \
8561 X(sub, 1e00, eba00000), \
8562 X(subs, 1e00, ebb00000), \
8563 X(subi, 8000, f1a00000), \
8564 X(subis, 8000, f1b00000), \
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), \
8574 X(sev, bf40, f3af8004),
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
8580 enum t16_32_codes { T16_32_OFFSET = 0xF7FF, T16_32_TAB };
8581 #undef X
8583 #define X(a,b,c) 0x##b
8584 static const unsigned short thumb_op16[] = { T16_32_TAB };
8585 #define THUMB_OP16(n) (thumb_op16[(n) - (T16_32_OFFSET + 1)])
8586 #undef X
8588 #define X(a,b,c) 0x##c
8589 static 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
8595 /* Thumb instruction encoders, in alphabetical order. */
8597 /* ADDW or SUBW. */
8598 static void
8599 do_t_add_sub_w (void)
8601 int Rd, Rn;
8603 Rd = inst.operands[0].reg;
8604 Rn = inst.operands[1].reg;
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);
8610 inst.instruction |= (Rn << 16) | (Rd << 8);
8611 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8614 /* Parse an add or subtract instruction. We get here with inst.instruction
8615 equalling any of THUMB_OPCODE_add, adds, sub, or subs. */
8617 static void
8618 do_t_add_sub (void)
8620 int Rd, Rs, Rn;
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 */
8627 if (Rd == REG_PC)
8628 set_it_insn_type_last ();
8630 if (unified_syntax)
8632 bfd_boolean flags;
8633 bfd_boolean narrow;
8634 int opcode;
8636 flags = (inst.instruction == T_MNEM_adds
8637 || inst.instruction == T_MNEM_subs);
8638 if (flags)
8639 narrow = !in_it_block ();
8640 else
8641 narrow = in_it_block ();
8642 if (!inst.operands[2].isreg)
8644 int add;
8646 constraint (Rd == REG_SP && Rs != REG_SP, BAD_SP);
8648 add = (inst.instruction == T_MNEM_add
8649 || inst.instruction == T_MNEM_adds);
8650 opcode = 0;
8651 if (inst.size_req != 4)
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)
8663 if (flags)
8664 opcode = add ? T_MNEM_addis : T_MNEM_subis;
8665 else
8666 opcode = add ? T_MNEM_addi : T_MNEM_subi;
8668 if (opcode)
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;
8676 else
8677 constraint (inst.size_req == 2, BAD_HIREG);
8679 if (inst.size_req == 4
8680 || (inst.size_req != 2 && !opcode))
8682 if (Rd == REG_PC)
8684 constraint (add, BAD_PC);
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;
8697 else if (Rs == REG_PC)
8699 /* Always use addw/subw. */
8700 inst.instruction = add ? 0xf20f0000 : 0xf2af0000;
8701 inst.reloc.type = BFD_RELOC_ARM_T32_IMM12;
8703 else
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;
8713 inst.instruction |= Rd << 8;
8714 inst.instruction |= Rs << 16;
8717 else
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)
8723 if (Rd > 7 || Rs > 7 || Rn > 7)
8724 narrow = FALSE;
8726 if (narrow)
8728 inst.instruction = ((inst.instruction == T_MNEM_adds
8729 || inst.instruction == T_MNEM_add)
8730 ? T_OPCODE_ADD_R3
8731 : T_OPCODE_SUB_R3);
8732 inst.instruction |= Rd | (Rs << 3) | (Rn << 6);
8733 return;
8736 if (inst.instruction == T_MNEM_add && (Rd == Rs || Rd == Rn))
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))
8744 if (Rd == Rn)
8746 Rn = Rs;
8747 Rs = Rd;
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;
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);
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);
8772 else
8774 constraint (inst.instruction == T_MNEM_adds
8775 || inst.instruction == T_MNEM_subs,
8776 BAD_THUMB32);
8778 if (!inst.operands[2].isreg) /* Rd, Rs, #imm */
8780 constraint ((Rd > 7 && (Rd != REG_SP || Rs != REG_SP))
8781 || (Rs > 7 && Rs != REG_SP && Rs != REG_PC),
8782 BAD_HIREG);
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;
8788 return;
8791 Rn = inst.operands[2].reg;
8792 constraint (inst.operands[2].shifted, _("unshifted register required"));
8794 /* We now have Rd, Rs, and Rn set to registers. */
8795 if (Rd > 7 || Rs > 7 || Rn > 7)
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"));
8809 else
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);
8818 static void
8819 do_t_adr (void)
8821 unsigned Rd;
8823 Rd = inst.operands[0].reg;
8824 reject_bad_reg (Rd);
8826 if (unified_syntax && inst.size_req == 0 && Rd <= 7)
8828 /* Defer to section relaxation. */
8829 inst.relax = inst.instruction;
8830 inst.instruction = THUMB_OP16 (inst.instruction);
8831 inst.instruction |= Rd << 4;
8833 else if (unified_syntax && inst.size_req != 2)
8835 /* Generate a 32-bit opcode. */
8836 inst.instruction = THUMB_OP32 (inst.instruction);
8837 inst.instruction |= Rd << 8;
8838 inst.reloc.type = BFD_RELOC_ARM_T32_ADD_PC12;
8839 inst.reloc.pc_rel = 1;
8841 else
8843 /* Generate a 16-bit opcode. */
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;
8849 inst.instruction |= Rd << 4;
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. */
8859 static void
8860 do_t_arit3 (void)
8862 int Rd, Rs, Rn;
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;
8870 reject_bad_reg (Rd);
8871 reject_bad_reg (Rs);
8872 if (inst.operands[2].isreg)
8873 reject_bad_reg (Rn);
8875 if (unified_syntax)
8877 if (!inst.operands[2].isreg)
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;
8887 else
8889 bfd_boolean narrow;
8891 /* See if we can do this with a 16-bit instruction. */
8892 if (THUMB_SETS_FLAGS (inst.instruction))
8893 narrow = !in_it_block ();
8894 else
8895 narrow = in_it_block ();
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;
8904 if (narrow
8905 && Rd == Rs)
8907 inst.instruction = THUMB_OP16 (inst.instruction);
8908 inst.instruction |= Rd;
8909 inst.instruction |= Rn << 3;
8910 return;
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);
8923 else
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);
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"));
8936 inst.instruction = THUMB_OP16 (inst.instruction);
8937 inst.instruction |= Rd;
8938 inst.instruction |= Rn << 3;
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. */
8947 static void
8948 do_t_arit3c (void)
8950 int Rd, Rs, Rn;
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;
8958 reject_bad_reg (Rd);
8959 reject_bad_reg (Rs);
8960 if (inst.operands[2].isreg)
8961 reject_bad_reg (Rn);
8963 if (unified_syntax)
8965 if (!inst.operands[2].isreg)
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;
8975 else
8977 bfd_boolean narrow;
8979 /* See if we can do this with a 16-bit instruction. */
8980 if (THUMB_SETS_FLAGS (inst.instruction))
8981 narrow = !in_it_block ();
8982 else
8983 narrow = in_it_block ();
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;
8992 if (narrow)
8994 if (Rd == Rs)
8996 inst.instruction = THUMB_OP16 (inst.instruction);
8997 inst.instruction |= Rd;
8998 inst.instruction |= Rn << 3;
8999 return;
9001 if (Rd == Rn)
9003 inst.instruction = THUMB_OP16 (inst.instruction);
9004 inst.instruction |= Rd;
9005 inst.instruction |= Rs << 3;
9006 return;
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);
9020 else
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);
9027 constraint (!inst.operands[2].isreg || inst.operands[2].shifted,
9028 _("unshifted register required"));
9029 constraint (Rd > 7 || Rs > 7 || Rn > 7, BAD_HIREG);
9031 inst.instruction = THUMB_OP16 (inst.instruction);
9032 inst.instruction |= Rd;
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"));
9043 static void
9044 do_t_barrier (void)
9046 if (inst.operands[0].present)
9048 constraint ((inst.instruction & 0xf0) != 0x40
9049 && inst.operands[0].imm != 0xf,
9050 _("bad barrier type"));
9051 inst.instruction |= inst.operands[0].imm;
9053 else
9054 inst.instruction |= 0xf;
9057 static void
9058 do_t_bfc (void)
9060 unsigned Rd;
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. */
9065 Rd = inst.operands[0].reg;
9066 reject_bad_reg (Rd);
9067 inst.instruction |= Rd << 8;
9068 inst.instruction |= (inst.operands[1].imm & 0x1c) << 10;
9069 inst.instruction |= (inst.operands[1].imm & 0x03) << 6;
9070 inst.instruction |= msb - 1;
9073 static void
9074 do_t_bfi (void)
9076 int Rd, Rn;
9077 unsigned int msb;
9079 Rd = inst.operands[0].reg;
9080 reject_bad_reg (Rd);
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)
9085 Rn = REG_PC;
9086 else
9088 Rn = inst.operands[1].reg;
9089 reject_bad_reg (Rn);
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. */
9096 inst.instruction |= Rd << 8;
9097 inst.instruction |= Rn << 16;
9098 inst.instruction |= (inst.operands[2].imm & 0x1c) << 10;
9099 inst.instruction |= (inst.operands[2].imm & 0x03) << 6;
9100 inst.instruction |= msb - 1;
9103 static void
9104 do_t_bfx (void)
9106 unsigned Rd, Rn;
9108 Rd = inst.operands[0].reg;
9109 Rn = inst.operands[1].reg;
9111 reject_bad_reg (Rd);
9112 reject_bad_reg (Rn);
9114 constraint (inst.operands[2].imm + inst.operands[3].imm > 32,
9115 _("bit-field extends past end of register"));
9116 inst.instruction |= Rd << 8;
9117 inst.instruction |= Rn << 16;
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;
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.
9130 ??? How to take advantage of the additional two bits of displacement
9131 available in Thumb32 mode? Need new relocation? */
9133 static void
9134 do_t_blx (void)
9136 set_it_insn_type_last ();
9138 if (inst.operands[0].isreg)
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;
9144 else
9146 /* No register. This must be BLX(1). */
9147 inst.instruction = 0xf000e800;
9148 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BLX;
9149 inst.reloc.pc_rel = 1;
9153 static void
9154 do_t_branch (void)
9156 int opcode;
9157 int cond;
9159 cond = inst.cond;
9160 set_it_insn_type (IF_INSIDE_IT_LAST_INSN);
9162 if (in_it_block ())
9164 /* Conditional branches inside IT blocks are encoded as unconditional
9165 branches. */
9166 cond = COND_ALWAYS;
9168 else
9169 cond = inst.cond;
9171 if (cond != COND_ALWAYS)
9172 opcode = T_MNEM_bcond;
9173 else
9174 opcode = inst.instruction;
9176 if (unified_syntax && inst.size_req == 4)
9178 inst.instruction = THUMB_OP32(opcode);
9179 if (cond == COND_ALWAYS)
9180 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH25;
9181 else
9183 gas_assert (cond != 0xF);
9184 inst.instruction |= cond << 22;
9185 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH20;
9188 else
9190 inst.instruction = THUMB_OP16(opcode);
9191 if (cond == COND_ALWAYS)
9192 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH12;
9193 else
9195 inst.instruction |= cond << 8;
9196 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH9;
9198 /* Allow section relaxation. */
9199 if (unified_syntax && inst.size_req != 2)
9200 inst.relax = opcode;
9203 inst.reloc.pc_rel = 1;
9206 static void
9207 do_t_bkpt (void)
9209 constraint (inst.cond != COND_ALWAYS,
9210 _("instruction is always unconditional"));
9211 if (inst.operands[0].present)
9213 constraint (inst.operands[0].imm > 255,
9214 _("immediate value out of range"));
9215 inst.instruction |= inst.operands[0].imm;
9216 set_it_insn_type (NEUTRAL_IT_INSN);
9220 static void
9221 do_t_branch23 (void)
9223 set_it_insn_type_last ();
9224 inst.reloc.type = BFD_RELOC_THUMB_PCREL_BRANCH23;
9225 inst.reloc.pc_rel = 1;
9227 #if defined(OBJ_COFF)
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);
9238 #endif
9241 static void
9242 do_t_bx (void)
9244 set_it_insn_type_last ();
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. */
9251 static void
9252 do_t_bxj (void)
9254 int Rm;
9256 set_it_insn_type_last ();
9257 Rm = inst.operands[0].reg;
9258 reject_bad_reg (Rm);
9259 inst.instruction |= Rm << 16;
9262 static void
9263 do_t_clz (void)
9265 unsigned Rd;
9266 unsigned Rm;
9268 Rd = inst.operands[0].reg;
9269 Rm = inst.operands[1].reg;
9271 reject_bad_reg (Rd);
9272 reject_bad_reg (Rm);
9274 inst.instruction |= Rd << 8;
9275 inst.instruction |= Rm << 16;
9276 inst.instruction |= Rm;
9279 static void
9280 do_t_cps (void)
9282 set_it_insn_type (OUTSIDE_IT_INSN);
9283 inst.instruction |= inst.operands[0].imm;
9286 static void
9287 do_t_cpsi (void)
9289 set_it_insn_type (OUTSIDE_IT_INSN);
9290 if (unified_syntax
9291 && (inst.operands[1].present || inst.size_req == 4)
9292 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v6_notm))
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;
9301 else
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,
9308 _("Thumb does not support the 2-argument "
9309 "form of this instruction"));
9310 inst.instruction |= inst.operands[0].imm;
9314 /* THUMB CPY instruction (argument parse). */
9316 static void
9317 do_t_cpy (void)
9319 if (inst.size_req == 4)
9321 inst.instruction = THUMB_OP32 (T_MNEM_mov);
9322 inst.instruction |= inst.operands[0].reg << 8;
9323 inst.instruction |= inst.operands[1].reg;
9325 else
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;
9333 static void
9334 do_t_cbz (void)
9336 set_it_insn_type (OUTSIDE_IT_INSN);
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;
9343 static void
9344 do_t_dbg (void)
9346 inst.instruction |= inst.operands[0].imm;
9349 static void
9350 do_t_div (void)
9352 unsigned Rd, Rn, Rm;
9354 Rd = inst.operands[0].reg;
9355 Rn = (inst.operands[1].present
9356 ? inst.operands[1].reg : Rd);
9357 Rm = inst.operands[2].reg;
9359 reject_bad_reg (Rd);
9360 reject_bad_reg (Rn);
9361 reject_bad_reg (Rm);
9363 inst.instruction |= Rd << 8;
9364 inst.instruction |= Rn << 16;
9365 inst.instruction |= Rm;
9368 static void
9369 do_t_hint (void)
9371 if (unified_syntax && inst.size_req == 4)
9372 inst.instruction = THUMB_OP32 (inst.instruction);
9373 else
9374 inst.instruction = THUMB_OP16 (inst.instruction);
9377 static void
9378 do_t_it (void)
9380 unsigned int cond = inst.operands[0].imm;
9382 set_it_insn_type (IT_INSN);
9383 now_it.mask = (inst.instruction & 0xf) | 0x10;
9384 now_it.cc = cond;
9386 /* If the condition is a negative condition, invert the mask. */
9387 if ((cond & 0x1) == 0x0)
9389 unsigned int mask = inst.instruction & 0x000f;
9391 if ((mask & 0x7) == 0)
9392 /* no conversion needed */;
9393 else if ((mask & 0x3) == 0)
9394 mask ^= 0x8;
9395 else if ((mask & 0x1) == 0)
9396 mask ^= 0xC;
9397 else
9398 mask ^= 0xE;
9400 inst.instruction &= 0xfff0;
9401 inst.instruction |= mask;
9404 inst.instruction |= cond << 4;
9407 /* Helper function used for both push/pop and ldm/stm. */
9408 static void
9409 encode_thumb2_ldmstm (int base, unsigned mask, bfd_boolean writeback)
9411 bfd_boolean load;
9413 load = (inst.instruction & (1 << 20)) != 0;
9415 if (mask & (1 << 13))
9416 inst.error = _("SP not allowed in register list");
9417 if (load)
9419 if (mask & (1 << 15))
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 ();
9427 if ((mask & (1 << base)) != 0
9428 && writeback)
9429 as_warn (_("base register should not be in register list "
9430 "when written back"));
9432 else
9434 if (mask & (1 << 15))
9435 inst.error = _("PC not allowed in register list");
9437 if (mask & (1 << base))
9438 as_warn (_("value stored for r%d is UNPREDICTABLE"), base);
9441 if ((mask & (mask - 1)) == 0)
9443 /* Single register transfers implemented as str/ldr. */
9444 if (writeback)
9446 if (inst.instruction & (1 << 23))
9447 inst.instruction = 0x00000b04; /* ia! -> [base], #4 */
9448 else
9449 inst.instruction = 0x00000d04; /* db! -> [base, #-4]! */
9451 else
9453 if (inst.instruction & (1 << 23))
9454 inst.instruction = 0x00800000; /* ia -> [base] */
9455 else
9456 inst.instruction = 0x00000c04; /* db -> [base, #-4] */
9459 inst.instruction |= 0xf8400000;
9460 if (load)
9461 inst.instruction |= 0x00100000;
9463 mask = ffs (mask) - 1;
9464 mask <<= 12;
9466 else if (writeback)
9467 inst.instruction |= WRITE_BACK;
9469 inst.instruction |= mask;
9470 inst.instruction |= base << 16;
9473 static void
9474 do_t_ldmstm (void)
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}^"));
9482 if (unified_syntax)
9484 bfd_boolean narrow;
9485 unsigned mask;
9487 narrow = FALSE;
9488 /* See if we can use a 16-bit instruction. */
9489 if (inst.instruction < 0xffff /* not ldmdb/stmdb */
9490 && inst.size_req != 4
9491 && !(inst.operands[1].imm & ~0xff))
9493 mask = 1 << inst.operands[0].reg;
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))))
9501 if (inst.instruction == T_MNEM_stmia
9502 && (inst.operands[1].imm & mask)
9503 && (inst.operands[1].imm & (mask - 1)))
9504 as_warn (_("value stored for r%d is UNPREDICTABLE"),
9505 inst.operands[0].reg);
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;
9512 else if (inst.operands[0] .reg == REG_SP
9513 && inst.operands[0].writeback)
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;
9522 if (!narrow)
9524 if (inst.instruction < 0xffff)
9525 inst.instruction = THUMB_OP32 (inst.instruction);
9527 encode_thumb2_ldmstm (inst.operands[0].reg, inst.operands[1].imm,
9528 inst.operands[0].writeback);
9531 else
9533 constraint (inst.operands[0].reg > 7
9534 || (inst.operands[1].imm & ~0xff), BAD_HIREG);
9535 constraint (inst.instruction != T_MNEM_ldmia
9536 && inst.instruction != T_MNEM_stmia,
9537 _("Thumb-2 instruction only valid in unified syntax"));
9538 if (inst.instruction == T_MNEM_stmia)
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);
9547 else
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"));
9557 inst.instruction = THUMB_OP16 (inst.instruction);
9558 inst.instruction |= inst.operands[0].reg << 8;
9559 inst.instruction |= inst.operands[1].imm;
9563 static void
9564 do_t_ldrex (void)
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,
9570 BAD_ADDR_MODE);
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;
9577 static void
9578 do_t_ldrexd (void)
9580 if (!inst.operands[1].present)
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;
9587 constraint (inst.operands[0].reg == inst.operands[1].reg,
9588 BAD_OVERLAP);
9590 inst.instruction |= inst.operands[0].reg << 12;
9591 inst.instruction |= inst.operands[1].reg << 8;
9592 inst.instruction |= inst.operands[2].reg << 16;
9595 static void
9596 do_t_ldst (void)
9598 unsigned long opcode;
9599 int Rn;
9601 if (inst.operands[0].isreg
9602 && !inst.operands[0].preind
9603 && inst.operands[0].reg == REG_PC)
9604 set_it_insn_type_last ();
9606 opcode = inst.instruction;
9607 if (unified_syntax)
9609 if (!inst.operands[1].isreg)
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;
9616 if (inst.operands[1].isreg
9617 && !inst.operands[1].writeback
9618 && !inst.operands[1].shifted && !inst.operands[1].postind
9619 && !inst.operands[1].negative && inst.operands[0].reg <= 7
9620 && opcode <= 0xffff
9621 && inst.size_req != 4)
9623 /* Insn may have a 16-bit form. */
9624 Rn = inst.operands[1].reg;
9625 if (inst.operands[1].immisreg)
9627 inst.instruction = THUMB_OP16 (opcode);
9628 /* [Rn, Rik] */
9629 if (Rn <= 7 && inst.operands[1].imm <= 7)
9630 goto op16;
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))
9637 /* [Rn, #const] */
9638 if (Rn > 7)
9640 if (Rn == REG_PC)
9642 if (inst.reloc.pc_rel)
9643 opcode = T_MNEM_ldr_pc2;
9644 else
9645 opcode = T_MNEM_ldr_pc;
9647 else
9649 if (opcode == T_MNEM_ldr)
9650 opcode = T_MNEM_ldr_sp;
9651 else
9652 opcode = T_MNEM_str_sp;
9654 inst.instruction = inst.operands[0].reg << 8;
9656 else
9658 inst.instruction = inst.operands[0].reg;
9659 inst.instruction |= inst.operands[1].reg << 3;
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;
9669 /* Definitely a 32-bit variant. */
9670 inst.instruction = THUMB_OP32 (opcode);
9671 inst.instruction |= inst.operands[0].reg << 12;
9672 encode_thumb32_addr_mode (1, /*is_t=*/FALSE, /*is_d=*/FALSE);
9673 return;
9676 constraint (inst.operands[0].reg > 7, BAD_HIREG);
9678 if (inst.instruction == T_MNEM_ldrsh || inst.instruction == T_MNEM_ldrsb)
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;
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;
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)
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"));
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;
9716 inst.instruction |= inst.operands[0].reg << 8;
9717 inst.reloc.type = BFD_RELOC_ARM_THUMB_OFFSET;
9718 return;
9721 constraint (inst.operands[1].reg > 7, BAD_HIREG);
9722 if (!inst.operands[1].immisreg)
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;
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"));
9736 op16:
9737 switch (inst.instruction)
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 ();
9750 inst.instruction |= inst.operands[0].reg;
9751 inst.instruction |= inst.operands[1].reg << 3;
9752 inst.instruction |= inst.operands[1].imm << 6;
9755 static void
9756 do_t_ldstd (void)
9758 if (!inst.operands[1].present)
9760 inst.operands[1].reg = inst.operands[0].reg + 1;
9761 constraint (inst.operands[0].reg == REG_LR,
9762 _("r14 not allowed here"));
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);
9769 static void
9770 do_t_ldstt (void)
9772 inst.instruction |= inst.operands[0].reg << 12;
9773 encode_thumb32_addr_mode (1, /*is_t=*/TRUE, /*is_d=*/FALSE);
9776 static void
9777 do_t_mla (void)
9779 unsigned Rd, Rn, Rm, Ra;
9781 Rd = inst.operands[0].reg;
9782 Rn = inst.operands[1].reg;
9783 Rm = inst.operands[2].reg;
9784 Ra = inst.operands[3].reg;
9786 reject_bad_reg (Rd);
9787 reject_bad_reg (Rn);
9788 reject_bad_reg (Rm);
9789 reject_bad_reg (Ra);
9791 inst.instruction |= Rd << 8;
9792 inst.instruction |= Rn << 16;
9793 inst.instruction |= Rm;
9794 inst.instruction |= Ra << 12;
9797 static void
9798 do_t_mlal (void)
9800 unsigned RdLo, RdHi, Rn, Rm;
9802 RdLo = inst.operands[0].reg;
9803 RdHi = inst.operands[1].reg;
9804 Rn = inst.operands[2].reg;
9805 Rm = inst.operands[3].reg;
9807 reject_bad_reg (RdLo);
9808 reject_bad_reg (RdHi);
9809 reject_bad_reg (Rn);
9810 reject_bad_reg (Rm);
9812 inst.instruction |= RdLo << 12;
9813 inst.instruction |= RdHi << 8;
9814 inst.instruction |= Rn << 16;
9815 inst.instruction |= Rm;
9818 static void
9819 do_t_mov_cmp (void)
9821 unsigned Rn, Rm;
9823 Rn = inst.operands[0].reg;
9824 Rm = inst.operands[1].reg;
9826 if (Rn == REG_PC)
9827 set_it_insn_type_last ();
9829 if (unified_syntax)
9831 int r0off = (inst.instruction == T_MNEM_mov
9832 || inst.instruction == T_MNEM_movs) ? 8 : 16;
9833 unsigned long opcode;
9834 bfd_boolean narrow;
9835 bfd_boolean low_regs;
9837 low_regs = (Rn <= 7 && Rm <= 7);
9838 opcode = inst.instruction;
9839 if (in_it_block ())
9840 narrow = opcode != T_MNEM_movs;
9841 else
9842 narrow = opcode != T_MNEM_movs || low_regs;
9843 if (inst.size_req == 4
9844 || inst.operands[1].shifted)
9845 narrow = FALSE;
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
9850 && Rn == REG_PC
9851 && Rm == REG_LR)
9853 inst.instruction = T2_SUBS_PC_LR;
9854 return;
9857 if (opcode == T_MNEM_cmp)
9859 constraint (Rn == REG_PC, BAD_PC);
9860 if (narrow)
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);
9870 else
9871 reject_bad_reg (Rm);
9873 else if (opcode == T_MNEM_mov
9874 || opcode == T_MNEM_movs)
9876 if (inst.operands[1].isreg)
9878 if (opcode == T_MNEM_movs)
9880 reject_bad_reg (Rn);
9881 reject_bad_reg (Rm);
9883 else if ((Rn == REG_SP || Rn == REG_PC)
9884 && (Rm == REG_SP || Rm == REG_PC))
9885 reject_bad_reg (Rm);
9887 else
9888 reject_bad_reg (Rn);
9891 if (!inst.operands[1].isreg)
9893 /* Immediate operand. */
9894 if (!in_it_block () && opcode == T_MNEM_mov)
9895 narrow = 0;
9896 if (low_regs && narrow)
9898 inst.instruction = THUMB_OP16 (opcode);
9899 inst.instruction |= Rn << 8;
9900 if (inst.size_req == 2)
9901 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
9902 else
9903 inst.relax = opcode;
9905 else
9907 inst.instruction = THUMB_OP32 (inst.instruction);
9908 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
9909 inst.instruction |= Rn << r0off;
9910 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
9913 else if (inst.operands[1].shifted && inst.operands[1].immisreg
9914 && (inst.instruction == T_MNEM_mov
9915 || inst.instruction == T_MNEM_movs))
9917 /* Register shifts are encoded as separate shift instructions. */
9918 bfd_boolean flags = (inst.instruction == T_MNEM_movs);
9920 if (in_it_block ())
9921 narrow = !flags;
9922 else
9923 narrow = flags;
9925 if (inst.size_req == 4)
9926 narrow = FALSE;
9928 if (!low_regs || inst.operands[1].imm > 7)
9929 narrow = FALSE;
9931 if (Rn != Rm)
9932 narrow = FALSE;
9934 switch (inst.operands[1].shift_kind)
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:
9949 abort ();
9952 inst.instruction = opcode;
9953 if (narrow)
9955 inst.instruction |= Rn;
9956 inst.instruction |= inst.operands[1].imm << 3;
9958 else
9960 if (flags)
9961 inst.instruction |= CONDS_BIT;
9963 inst.instruction |= Rn << 8;
9964 inst.instruction |= Rm << 16;
9965 inst.instruction |= inst.operands[1].imm;
9968 else if (!narrow)
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))
9976 if (in_it_block ())
9977 narrow = (inst.instruction == T_MNEM_mov);
9978 else
9979 narrow = (inst.instruction == T_MNEM_movs);
9982 if (narrow)
9984 switch (inst.operands[1].shift_kind)
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;
9993 if (narrow)
9995 inst.instruction |= Rn;
9996 inst.instruction |= Rm << 3;
9997 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
9999 else
10001 inst.instruction = THUMB_OP32 (inst.instruction);
10002 inst.instruction |= Rn << r0off;
10003 encode_thumb32_shifted_operand (1);
10006 else
10007 switch (inst.instruction)
10009 case T_MNEM_mov:
10010 inst.instruction = T_OPCODE_MOV_HR;
10011 inst.instruction |= (Rn & 0x8) << 4;
10012 inst.instruction |= (Rn & 0x7);
10013 inst.instruction |= Rm << 3;
10014 break;
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;
10020 inst.instruction |= Rn;
10021 inst.instruction |= Rm << 3;
10022 break;
10024 case T_MNEM_cmp:
10025 if (low_regs)
10027 inst.instruction = T_OPCODE_CMP_LR;
10028 inst.instruction |= Rn;
10029 inst.instruction |= Rm << 3;
10031 else
10033 inst.instruction = T_OPCODE_CMP_HR;
10034 inst.instruction |= (Rn & 0x8) << 4;
10035 inst.instruction |= (Rn & 0x7);
10036 inst.instruction |= Rm << 3;
10038 break;
10040 return;
10043 inst.instruction = THUMB_OP16 (inst.instruction);
10044 if (inst.operands[1].isreg)
10046 if (Rn < 8 && Rm < 8)
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;
10052 else
10053 inst.instruction = T_OPCODE_CMP_LR;
10055 inst.instruction |= Rn;
10056 inst.instruction |= Rm << 3;
10058 else
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 ();
10067 else
10069 constraint (Rn > 7,
10070 _("only lo regs allowed with immediate"));
10071 inst.instruction |= Rn << 8;
10072 inst.reloc.type = BFD_RELOC_ARM_THUMB_IMM;
10076 static void
10077 do_t_mov16 (void)
10079 unsigned Rd;
10080 bfd_vma imm;
10081 bfd_boolean top;
10083 top = (inst.instruction & 0x00800000) != 0;
10084 if (inst.reloc.type == BFD_RELOC_ARM_MOVW)
10086 constraint (top, _(":lower16: not allowed this instruction"));
10087 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVW;
10089 else if (inst.reloc.type == BFD_RELOC_ARM_MOVT)
10091 constraint (!top, _(":upper16: not allowed this instruction"));
10092 inst.reloc.type = BFD_RELOC_ARM_THUMB_MOVT;
10095 Rd = inst.operands[0].reg;
10096 reject_bad_reg (Rd);
10098 inst.instruction |= Rd << 8;
10099 if (inst.reloc.type == BFD_RELOC_UNUSED)
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);
10109 static void
10110 do_t_mvn_tst (void)
10112 unsigned Rn, Rm;
10114 Rn = inst.operands[0].reg;
10115 Rm = inst.operands[1].reg;
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);
10124 if (unified_syntax)
10126 int r0off = (inst.instruction == T_MNEM_mvn
10127 || inst.instruction == T_MNEM_mvns) ? 8 : 16;
10128 bfd_boolean narrow;
10130 if (inst.size_req == 4
10131 || inst.instruction > 0xffff
10132 || inst.operands[1].shifted
10133 || Rn > 7 || Rm > 7)
10134 narrow = FALSE;
10135 else if (inst.instruction == T_MNEM_cmn)
10136 narrow = TRUE;
10137 else if (THUMB_SETS_FLAGS (inst.instruction))
10138 narrow = !in_it_block ();
10139 else
10140 narrow = in_it_block ();
10142 if (!inst.operands[1].isreg)
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;
10149 inst.instruction |= Rn << r0off;
10150 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10152 else
10154 /* See if we can do this with a 16-bit instruction. */
10155 if (narrow)
10157 inst.instruction = THUMB_OP16 (inst.instruction);
10158 inst.instruction |= Rn;
10159 inst.instruction |= Rm << 3;
10161 else
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);
10168 inst.instruction |= Rn << r0off;
10169 encode_thumb32_shifted_operand (1);
10173 else
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"));
10179 constraint (Rn > 7 || Rm > 7,
10180 BAD_HIREG);
10182 inst.instruction = THUMB_OP16 (inst.instruction);
10183 inst.instruction |= Rn;
10184 inst.instruction |= Rm << 3;
10188 static void
10189 do_t_mrs (void)
10191 unsigned Rd;
10192 int flags;
10194 if (do_vfp_nsyn_mrs () == SUCCESS)
10195 return;
10197 flags = inst.operands[1].imm & (PSR_c|PSR_x|PSR_s|PSR_f|SPSR_BIT);
10198 if (flags == 0)
10200 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10201 _("selected processor does not support "
10202 "requested special purpose register"));
10204 else
10206 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10207 _("selected processor does not support "
10208 "requested special purpose register"));
10209 /* mrs only accepts CPSR/SPSR/CPSR_all/SPSR_all. */
10210 constraint ((flags & ~SPSR_BIT) != (PSR_c|PSR_f),
10211 _("'CPSR' or 'SPSR' expected"));
10214 Rd = inst.operands[0].reg;
10215 reject_bad_reg (Rd);
10217 inst.instruction |= Rd << 8;
10218 inst.instruction |= (flags & SPSR_BIT) >> 2;
10219 inst.instruction |= inst.operands[1].imm & 0xff;
10222 static void
10223 do_t_msr (void)
10225 int flags;
10226 unsigned Rn;
10228 if (do_vfp_nsyn_msr () == SUCCESS)
10229 return;
10231 constraint (!inst.operands[1].isreg,
10232 _("Thumb encoding does not support an immediate here"));
10233 flags = inst.operands[0].imm;
10234 if (flags & ~0xff)
10236 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1),
10237 _("selected processor does not support "
10238 "requested special purpose register"));
10240 else
10242 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_m),
10243 _("selected processor does not support "
10244 "requested special purpose register"));
10245 flags |= PSR_f;
10248 Rn = inst.operands[1].reg;
10249 reject_bad_reg (Rn);
10251 inst.instruction |= (flags & SPSR_BIT) >> 2;
10252 inst.instruction |= (flags & ~SPSR_BIT) >> 8;
10253 inst.instruction |= (flags & 0xff);
10254 inst.instruction |= Rn << 16;
10257 static void
10258 do_t_mul (void)
10260 bfd_boolean narrow;
10261 unsigned Rd, Rn, Rm;
10263 if (!inst.operands[2].present)
10264 inst.operands[2].reg = inst.operands[0].reg;
10266 Rd = inst.operands[0].reg;
10267 Rn = inst.operands[1].reg;
10268 Rm = inst.operands[2].reg;
10270 if (unified_syntax)
10272 if (inst.size_req == 4
10273 || (Rd != Rn
10274 && Rd != Rm)
10275 || Rn > 7
10276 || Rm > 7)
10277 narrow = FALSE;
10278 else if (inst.instruction == T_MNEM_muls)
10279 narrow = !in_it_block ();
10280 else
10281 narrow = in_it_block ();
10283 else
10285 constraint (inst.instruction == T_MNEM_muls, BAD_THUMB32);
10286 constraint (Rn > 7 || Rm > 7,
10287 BAD_HIREG);
10288 narrow = TRUE;
10291 if (narrow)
10293 /* 16-bit MULS/Conditional MUL. */
10294 inst.instruction = THUMB_OP16 (inst.instruction);
10295 inst.instruction |= Rd;
10297 if (Rd == Rn)
10298 inst.instruction |= Rm << 3;
10299 else if (Rd == Rm)
10300 inst.instruction |= Rn << 3;
10301 else
10302 constraint (1, _("dest must overlap one source register"));
10304 else
10306 constraint (inst.instruction != T_MNEM_mul,
10307 _("Thumb-2 MUL must not set flags"));
10308 /* 32-bit MUL. */
10309 inst.instruction = THUMB_OP32 (inst.instruction);
10310 inst.instruction |= Rd << 8;
10311 inst.instruction |= Rn << 16;
10312 inst.instruction |= Rm << 0;
10314 reject_bad_reg (Rd);
10315 reject_bad_reg (Rn);
10316 reject_bad_reg (Rm);
10320 static void
10321 do_t_mull (void)
10323 unsigned RdLo, RdHi, Rn, Rm;
10325 RdLo = inst.operands[0].reg;
10326 RdHi = inst.operands[1].reg;
10327 Rn = inst.operands[2].reg;
10328 Rm = inst.operands[3].reg;
10330 reject_bad_reg (RdLo);
10331 reject_bad_reg (RdHi);
10332 reject_bad_reg (Rn);
10333 reject_bad_reg (Rm);
10335 inst.instruction |= RdLo << 12;
10336 inst.instruction |= RdHi << 8;
10337 inst.instruction |= Rn << 16;
10338 inst.instruction |= Rm;
10340 if (RdLo == RdHi)
10341 as_tsktsk (_("rdhi and rdlo must be different"));
10344 static void
10345 do_t_nop (void)
10347 set_it_insn_type (NEUTRAL_IT_INSN);
10349 if (unified_syntax)
10351 if (inst.size_req == 4 || inst.operands[0].imm > 15)
10353 inst.instruction = THUMB_OP32 (inst.instruction);
10354 inst.instruction |= inst.operands[0].imm;
10356 else
10358 /* PR9722: Check for Thumb2 availability before
10359 generating a thumb2 nop instruction. */
10360 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
10362 inst.instruction = THUMB_OP16 (inst.instruction);
10363 inst.instruction |= inst.operands[0].imm << 4;
10365 else
10366 inst.instruction = 0x46c0;
10369 else
10371 constraint (inst.operands[0].present,
10372 _("Thumb does not support NOP with hints"));
10373 inst.instruction = 0x46c0;
10377 static void
10378 do_t_neg (void)
10380 if (unified_syntax)
10382 bfd_boolean narrow;
10384 if (THUMB_SETS_FLAGS (inst.instruction))
10385 narrow = !in_it_block ();
10386 else
10387 narrow = in_it_block ();
10388 if (inst.operands[0].reg > 7 || inst.operands[1].reg > 7)
10389 narrow = FALSE;
10390 if (inst.size_req == 4)
10391 narrow = FALSE;
10393 if (!narrow)
10395 inst.instruction = THUMB_OP32 (inst.instruction);
10396 inst.instruction |= inst.operands[0].reg << 8;
10397 inst.instruction |= inst.operands[1].reg << 16;
10399 else
10401 inst.instruction = THUMB_OP16 (inst.instruction);
10402 inst.instruction |= inst.operands[0].reg;
10403 inst.instruction |= inst.operands[1].reg << 3;
10406 else
10408 constraint (inst.operands[0].reg > 7 || inst.operands[1].reg > 7,
10409 BAD_HIREG);
10410 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10412 inst.instruction = THUMB_OP16 (inst.instruction);
10413 inst.instruction |= inst.operands[0].reg;
10414 inst.instruction |= inst.operands[1].reg << 3;
10418 static void
10419 do_t_orn (void)
10421 unsigned Rd, Rn;
10423 Rd = inst.operands[0].reg;
10424 Rn = inst.operands[1].present ? inst.operands[1].reg : Rd;
10426 reject_bad_reg (Rd);
10427 /* Rn == REG_SP is unpredictable; Rn == REG_PC is MVN. */
10428 reject_bad_reg (Rn);
10430 inst.instruction |= Rd << 8;
10431 inst.instruction |= Rn << 16;
10433 if (!inst.operands[2].isreg)
10435 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10436 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10438 else
10440 unsigned Rm;
10442 Rm = inst.operands[2].reg;
10443 reject_bad_reg (Rm);
10445 constraint (inst.operands[2].shifted
10446 && inst.operands[2].immisreg,
10447 _("shift must be constant"));
10448 encode_thumb32_shifted_operand (2);
10452 static void
10453 do_t_pkhbt (void)
10455 unsigned Rd, Rn, Rm;
10457 Rd = inst.operands[0].reg;
10458 Rn = inst.operands[1].reg;
10459 Rm = inst.operands[2].reg;
10461 reject_bad_reg (Rd);
10462 reject_bad_reg (Rn);
10463 reject_bad_reg (Rm);
10465 inst.instruction |= Rd << 8;
10466 inst.instruction |= Rn << 16;
10467 inst.instruction |= Rm;
10468 if (inst.operands[3].present)
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;
10478 static void
10479 do_t_pkhtb (void)
10481 if (!inst.operands[3].present)
10483 unsigned Rtmp;
10485 inst.instruction &= ~0x00000020;
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;
10492 do_t_pkhbt ();
10495 static void
10496 do_t_pld (void)
10498 if (inst.operands[0].immisreg)
10499 reject_bad_reg (inst.operands[0].imm);
10501 encode_thumb32_addr_mode (0, /*is_t=*/FALSE, /*is_d=*/FALSE);
10504 static void
10505 do_t_push_pop (void)
10507 unsigned mask;
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"));
10514 mask = inst.operands[0].imm;
10515 if ((mask & ~0xff) == 0)
10516 inst.instruction = THUMB_OP16 (inst.instruction) | mask;
10517 else if ((inst.instruction == T_MNEM_push
10518 && (mask & ~0xff) == 1 << REG_LR)
10519 || (inst.instruction == T_MNEM_pop
10520 && (mask & ~0xff) == 1 << REG_PC))
10522 inst.instruction = THUMB_OP16 (inst.instruction);
10523 inst.instruction |= THUMB_PP_PC_LR;
10524 inst.instruction |= mask & 0xff;
10526 else if (unified_syntax)
10528 inst.instruction = THUMB_OP32 (inst.instruction);
10529 encode_thumb2_ldmstm (13, mask, TRUE);
10531 else
10533 inst.error = _("invalid register list to push/pop instruction");
10534 return;
10538 static void
10539 do_t_rbit (void)
10541 unsigned Rd, Rm;
10543 Rd = inst.operands[0].reg;
10544 Rm = inst.operands[1].reg;
10546 reject_bad_reg (Rd);
10547 reject_bad_reg (Rm);
10549 inst.instruction |= Rd << 8;
10550 inst.instruction |= Rm << 16;
10551 inst.instruction |= Rm;
10554 static void
10555 do_t_rev (void)
10557 unsigned Rd, Rm;
10559 Rd = inst.operands[0].reg;
10560 Rm = inst.operands[1].reg;
10562 reject_bad_reg (Rd);
10563 reject_bad_reg (Rm);
10565 if (Rd <= 7 && Rm <= 7
10566 && inst.size_req != 4)
10568 inst.instruction = THUMB_OP16 (inst.instruction);
10569 inst.instruction |= Rd;
10570 inst.instruction |= Rm << 3;
10572 else if (unified_syntax)
10574 inst.instruction = THUMB_OP32 (inst.instruction);
10575 inst.instruction |= Rd << 8;
10576 inst.instruction |= Rm << 16;
10577 inst.instruction |= Rm;
10579 else
10580 inst.error = BAD_HIREG;
10583 static void
10584 do_t_rrx (void)
10586 unsigned Rd, Rm;
10588 Rd = inst.operands[0].reg;
10589 Rm = inst.operands[1].reg;
10591 reject_bad_reg (Rd);
10592 reject_bad_reg (Rm);
10594 inst.instruction |= Rd << 8;
10595 inst.instruction |= Rm;
10598 static void
10599 do_t_rsb (void)
10601 unsigned Rd, Rs;
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 */
10608 reject_bad_reg (Rd);
10609 reject_bad_reg (Rs);
10610 if (inst.operands[2].isreg)
10611 reject_bad_reg (inst.operands[2].reg);
10613 inst.instruction |= Rd << 8;
10614 inst.instruction |= Rs << 16;
10615 if (!inst.operands[2].isreg)
10617 bfd_boolean narrow;
10619 if ((inst.instruction & 0x00100000) != 0)
10620 narrow = !in_it_block ();
10621 else
10622 narrow = in_it_block ();
10624 if (Rd > 7 || Rs > 7)
10625 narrow = FALSE;
10627 if (inst.size_req == 4 || !unified_syntax)
10628 narrow = FALSE;
10630 if (inst.reloc.exp.X_op != O_constant
10631 || inst.reloc.exp.X_add_number != 0)
10632 narrow = FALSE;
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)
10638 inst.reloc.type = BFD_RELOC_UNUSED;
10639 inst.instruction = THUMB_OP16 (T_MNEM_negs);
10640 inst.instruction |= Rs << 3;
10641 inst.instruction |= Rd;
10643 else
10645 inst.instruction = (inst.instruction & 0xe1ffffff) | 0x10000000;
10646 inst.reloc.type = BFD_RELOC_ARM_T32_IMMEDIATE;
10649 else
10650 encode_thumb32_shifted_operand (2);
10653 static void
10654 do_t_setend (void)
10656 set_it_insn_type (OUTSIDE_IT_INSN);
10657 if (inst.operands[0].imm)
10658 inst.instruction |= 0x8;
10661 static void
10662 do_t_shift (void)
10664 if (!inst.operands[1].present)
10665 inst.operands[1].reg = inst.operands[0].reg;
10667 if (unified_syntax)
10669 bfd_boolean narrow;
10670 int shift_kind;
10672 switch (inst.instruction)
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 ();
10685 if (THUMB_SETS_FLAGS (inst.instruction))
10686 narrow = !in_it_block ();
10687 else
10688 narrow = in_it_block ();
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;
10700 reject_bad_reg (inst.operands[0].reg);
10701 reject_bad_reg (inst.operands[1].reg);
10703 if (!narrow)
10705 if (inst.operands[2].isreg)
10707 reject_bad_reg (inst.operands[2].reg);
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;
10713 else
10715 inst.operands[1].shifted = 1;
10716 inst.operands[1].shift_kind = shift_kind;
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;
10725 else
10727 if (inst.operands[2].isreg)
10729 switch (shift_kind)
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;
10735 default: abort ();
10738 inst.instruction |= inst.operands[0].reg;
10739 inst.instruction |= inst.operands[2].reg << 3;
10741 else
10743 switch (shift_kind)
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;
10748 default: abort ();
10750 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10751 inst.instruction |= inst.operands[0].reg;
10752 inst.instruction |= inst.operands[1].reg << 3;
10756 else
10758 constraint (inst.operands[0].reg > 7
10759 || inst.operands[1].reg > 7, BAD_HIREG);
10760 constraint (THUMB_SETS_FLAGS (inst.instruction), BAD_THUMB32);
10762 if (inst.operands[2].isreg) /* Rd, {Rs,} Rn */
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"));
10768 switch (inst.instruction)
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 ();
10777 inst.instruction |= inst.operands[0].reg;
10778 inst.instruction |= inst.operands[2].reg << 3;
10780 else
10782 switch (inst.instruction)
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 ();
10790 inst.reloc.type = BFD_RELOC_ARM_THUMB_SHIFT;
10791 inst.instruction |= inst.operands[0].reg;
10792 inst.instruction |= inst.operands[1].reg << 3;
10797 static void
10798 do_t_simd (void)
10800 unsigned Rd, Rn, Rm;
10802 Rd = inst.operands[0].reg;
10803 Rn = inst.operands[1].reg;
10804 Rm = inst.operands[2].reg;
10806 reject_bad_reg (Rd);
10807 reject_bad_reg (Rn);
10808 reject_bad_reg (Rm);
10810 inst.instruction |= Rd << 8;
10811 inst.instruction |= Rn << 16;
10812 inst.instruction |= Rm;
10815 static void
10816 do_t_smc (void)
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;
10827 static void
10828 do_t_ssat_usat (int bias)
10830 unsigned Rd, Rn;
10832 Rd = inst.operands[0].reg;
10833 Rn = inst.operands[2].reg;
10835 reject_bad_reg (Rd);
10836 reject_bad_reg (Rn);
10838 inst.instruction |= Rd << 8;
10839 inst.instruction |= inst.operands[1].imm - bias;
10840 inst.instruction |= Rn << 16;
10842 if (inst.operands[3].present)
10844 offsetT shift_amount = inst.reloc.exp.X_add_number;
10846 inst.reloc.type = BFD_RELOC_UNUSED;
10848 constraint (inst.reloc.exp.X_op != O_constant,
10849 _("expression too complex"));
10851 if (shift_amount != 0)
10853 constraint (shift_amount > 31,
10854 _("shift expression is too large"));
10856 if (inst.operands[3].shift_kind == SHIFT_ASR)
10857 inst.instruction |= 0x00200000; /* sh bit. */
10859 inst.instruction |= (shift_amount & 0x1c) << 10;
10860 inst.instruction |= (shift_amount & 0x03) << 6;
10865 static void
10866 do_t_ssat (void)
10868 do_t_ssat_usat (1);
10871 static void
10872 do_t_ssat16 (void)
10874 unsigned Rd, Rn;
10876 Rd = inst.operands[0].reg;
10877 Rn = inst.operands[2].reg;
10879 reject_bad_reg (Rd);
10880 reject_bad_reg (Rn);
10882 inst.instruction |= Rd << 8;
10883 inst.instruction |= inst.operands[1].imm - 1;
10884 inst.instruction |= Rn << 16;
10887 static void
10888 do_t_strex (void)
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,
10894 BAD_ADDR_MODE);
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;
10902 static void
10903 do_t_strexd (void)
10905 if (!inst.operands[2].present)
10906 inst.operands[2].reg = inst.operands[1].reg + 1;
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);
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;
10920 static void
10921 do_t_sxtah (void)
10923 unsigned Rd, Rn, Rm;
10925 Rd = inst.operands[0].reg;
10926 Rn = inst.operands[1].reg;
10927 Rm = inst.operands[2].reg;
10929 reject_bad_reg (Rd);
10930 reject_bad_reg (Rn);
10931 reject_bad_reg (Rm);
10933 inst.instruction |= Rd << 8;
10934 inst.instruction |= Rn << 16;
10935 inst.instruction |= Rm;
10936 inst.instruction |= inst.operands[3].imm << 4;
10939 static void
10940 do_t_sxth (void)
10942 unsigned Rd, Rm;
10944 Rd = inst.operands[0].reg;
10945 Rm = inst.operands[1].reg;
10947 reject_bad_reg (Rd);
10948 reject_bad_reg (Rm);
10950 if (inst.instruction <= 0xffff && inst.size_req != 4
10951 && Rd <= 7 && Rm <= 7
10952 && (!inst.operands[2].present || inst.operands[2].imm == 0))
10954 inst.instruction = THUMB_OP16 (inst.instruction);
10955 inst.instruction |= Rd;
10956 inst.instruction |= Rm << 3;
10958 else if (unified_syntax)
10960 if (inst.instruction <= 0xffff)
10961 inst.instruction = THUMB_OP32 (inst.instruction);
10962 inst.instruction |= Rd << 8;
10963 inst.instruction |= Rm;
10964 inst.instruction |= inst.operands[2].imm << 4;
10966 else
10968 constraint (inst.operands[2].present && inst.operands[2].imm != 0,
10969 _("Thumb encoding does not support rotation"));
10970 constraint (1, BAD_HIREG);
10974 static void
10975 do_t_swi (void)
10977 inst.reloc.type = BFD_RELOC_ARM_SWI;
10980 static void
10981 do_t_tb (void)
10983 unsigned Rn, Rm;
10984 int half;
10986 half = (inst.instruction & 0x10) != 0;
10987 set_it_insn_type_last ();
10988 constraint (inst.operands[0].immisreg,
10989 _("instruction requires register index"));
10991 Rn = inst.operands[0].reg;
10992 Rm = inst.operands[0].imm;
10994 constraint (Rn == REG_SP, BAD_SP);
10995 reject_bad_reg (Rm);
10997 constraint (!half && inst.operands[0].shifted,
10998 _("instruction does not allow shifted index"));
10999 inst.instruction |= (Rn << 16) | Rm;
11002 static void
11003 do_t_usat (void)
11005 do_t_ssat_usat (0);
11008 static void
11009 do_t_usat16 (void)
11011 unsigned Rd, Rn;
11013 Rd = inst.operands[0].reg;
11014 Rn = inst.operands[2].reg;
11016 reject_bad_reg (Rd);
11017 reject_bad_reg (Rn);
11019 inst.instruction |= Rd << 8;
11020 inst.instruction |= inst.operands[1].imm;
11021 inst.instruction |= Rn << 16;
11024 /* Neon instruction encoder helpers. */
11026 /* Encodings for the different types for various Neon opcodes. */
11028 /* An "invalid" code for the following tables. */
11029 #define N_INV -1u
11031 struct neon_tab_entry
11033 unsigned integer;
11034 unsigned float_or_poly;
11035 unsigned scalar_or_imm;
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
11052 vcge / vcgt with the operands reversed. */ \
11053 X(vclt, 0x0000300, 0x1200e00, 0x1b10200), \
11054 X(vcle, 0x0000310, 0x1000e00, 0x1b10180), \
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), \
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)
11097 enum neon_opc
11099 #define X(OPC,I,F,S) N_MNEM_##OPC
11100 NEON_ENC_TAB
11101 #undef X
11104 static const struct neon_tab_entry neon_enc_tab[] =
11106 #define X(OPC,I,F,S) { (I), (F), (S) }
11107 NEON_ENC_TAB
11108 #undef X
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)
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))
11125 /* Define shapes for instruction operands. The following mnemonic characters
11126 are used in this table:
11128 F - VFP S<n> register
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
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.
11140 - a table used to drive neon_select_shape. */
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)
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
11188 #define X(N, L, C) S##N L
11190 enum neon_shape
11192 NEON_SHAPE_DEF,
11193 NS_NULL
11196 #undef X
11197 #undef S2
11198 #undef S3
11199 #undef S4
11201 enum neon_shape_class
11203 SC_SINGLE,
11204 SC_DOUBLE,
11205 SC_QUAD,
11206 SC_MIXED
11209 #define X(N, L, C) SC_##C
11211 static enum neon_shape_class neon_shape_class[] =
11213 NEON_SHAPE_DEF
11216 #undef X
11218 enum neon_shape_el
11220 SE_F,
11221 SE_D,
11222 SE_Q,
11223 SE_I,
11224 SE_S,
11225 SE_R,
11226 SE_L
11229 /* Register widths of above. */
11230 static unsigned neon_shape_el_size[] =
11234 128,
11241 struct neon_shape_info
11243 unsigned els;
11244 enum neon_shape_el el[NEON_MAX_TYPE_ELS];
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 }
11251 #define X(N, L, C) { N, S##N L }
11253 static struct neon_shape_info neon_shape_tab[] =
11255 NEON_SHAPE_DEF
11258 #undef X
11259 #undef S2
11260 #undef S3
11261 #undef S4
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. */
11269 enum neon_type_mask
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. */
11302 N_UTYP = 0,
11303 N_MAX_NONSPECIAL = N_F64
11306 #define N_ALLMODS (N_DBL | N_HLF | N_SGN | N_UNS | N_INT | N_FLT | N_SIZ)
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)
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)
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. */
11325 static enum neon_shape
11326 neon_select_shape (enum neon_shape shape, ...)
11328 va_list ap;
11329 enum neon_shape first_shape = shape;
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];
11338 va_start (ap, shape);
11340 for (; shape != NS_NULL; shape = va_arg (ap, int))
11342 unsigned j;
11343 int matches = 1;
11345 for (j = 0; j < neon_shape_tab[shape].els; j++)
11347 if (!inst.operands[j].present)
11349 matches = 0;
11350 break;
11353 switch (neon_shape_tab[shape].el[j])
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;
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;
11371 case SE_R:
11372 if (!(inst.operands[j].isreg
11373 && !inst.operands[j].isvec))
11374 matches = 0;
11375 break;
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;
11385 case SE_I:
11386 if (!(!inst.operands[j].isreg
11387 && !inst.operands[j].isscalar))
11388 matches = 0;
11389 break;
11391 case SE_S:
11392 if (!(!inst.operands[j].isreg
11393 && inst.operands[j].isscalar))
11394 matches = 0;
11395 break;
11397 case SE_L:
11398 break;
11401 if (matches)
11402 break;
11405 va_end (ap);
11407 if (shape == NS_NULL && first_shape != NS_NULL)
11408 first_error (_("invalid instruction shape"));
11410 return shape;
11413 /* True if SHAPE is predominantly a quadword operation (most of the time, this
11414 means the Q bit should be set). */
11416 static int
11417 neon_quad (enum neon_shape shape)
11419 return neon_shape_class[shape] == SC_QUAD;
11422 static void
11423 neon_modify_type_size (unsigned typebits, enum neon_el_type *g_type,
11424 unsigned *g_size)
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)
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;
11442 else if ((typebits & N_SIZ) != 0)
11443 *g_type = NT_untyped;
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. */
11451 static struct neon_type_el
11452 neon_type_promote (struct neon_type_el *key, unsigned thisarg)
11454 struct neon_type_el dest = *key;
11456 gas_assert ((thisarg & N_EQK) != 0);
11458 neon_modify_type_size (thisarg, &dest.type, &dest.size);
11460 return dest;
11463 /* Convert Neon type and size into compact bitmask representation. */
11465 static enum neon_type_mask
11466 type_chk_of_el_type (enum neon_el_type type, unsigned size)
11468 switch (type)
11470 case NT_untyped:
11471 switch (size)
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: ;
11479 break;
11481 case NT_integer:
11482 switch (size)
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: ;
11490 break;
11492 case NT_float:
11493 switch (size)
11495 case 16: return N_F16;
11496 case 32: return N_F32;
11497 case 64: return N_F64;
11498 default: ;
11500 break;
11502 case NT_poly:
11503 switch (size)
11505 case 8: return N_P8;
11506 case 16: return N_P16;
11507 default: ;
11509 break;
11511 case NT_signed:
11512 switch (size)
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: ;
11520 break;
11522 case NT_unsigned:
11523 switch (size)
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: ;
11531 break;
11533 default: ;
11536 return N_UTYP;
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. */
11542 static int
11543 el_type_of_type_chk (enum neon_el_type *type, unsigned *size,
11544 enum neon_type_mask mask)
11546 if ((mask & N_EQK) != 0)
11547 return FAIL;
11549 if ((mask & (N_S8 | N_U8 | N_I8 | N_8 | N_P8)) != 0)
11550 *size = 8;
11551 else if ((mask & (N_S16 | N_U16 | N_I16 | N_16 | N_P16)) != 0)
11552 *size = 16;
11553 else if ((mask & (N_S32 | N_U32 | N_I32 | N_32 | N_F32)) != 0)
11554 *size = 32;
11555 else if ((mask & (N_S64 | N_U64 | N_I64 | N_64 | N_F64)) != 0)
11556 *size = 64;
11557 else
11558 return FAIL;
11560 if ((mask & (N_S8 | N_S16 | N_S32 | N_S64)) != 0)
11561 *type = NT_signed;
11562 else if ((mask & (N_U8 | N_U16 | N_U32 | N_U64)) != 0)
11563 *type = NT_unsigned;
11564 else if ((mask & (N_I8 | N_I16 | N_I32 | N_I64)) != 0)
11565 *type = NT_integer;
11566 else if ((mask & (N_8 | N_16 | N_32 | N_64)) != 0)
11567 *type = NT_untyped;
11568 else if ((mask & (N_P8 | N_P16)) != 0)
11569 *type = NT_poly;
11570 else if ((mask & (N_F32 | N_F64)) != 0)
11571 *type = NT_float;
11572 else
11573 return FAIL;
11575 return SUCCESS;
11578 /* Modify a bitmask of allowed types. This is only needed for type
11579 relaxation. */
11581 static unsigned
11582 modify_types_allowed (unsigned allowed, unsigned mods)
11584 unsigned size;
11585 enum neon_el_type type;
11586 unsigned destmask;
11587 int i;
11589 destmask = 0;
11591 for (i = 1; i <= N_MAX_NONSPECIAL; i <<= 1)
11593 if (el_type_of_type_chk (&type, &size, allowed & i) == SUCCESS)
11595 neon_modify_type_size (mods, &type, &size);
11596 destmask |= type_chk_of_el_type (type, size);
11600 return destmask;
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
11613 Neon instructions should call it before performing bit encoding. */
11615 static struct neon_type_el
11616 neon_check_type (unsigned els, enum neon_shape ns, ...)
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;
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];
11631 /* Suck up all the varargs. */
11632 va_start (ap, ns);
11633 for (i = 0; i < els; i++)
11635 unsigned thisarg = va_arg (ap, unsigned);
11636 if (thisarg == N_IGNORE_TYPE)
11638 va_end (ap);
11639 return badtype;
11641 types[i] = thisarg;
11642 if ((thisarg & N_KEY) != 0)
11643 key_el = i;
11645 va_end (ap);
11647 if (inst.vectype.elems > 0)
11648 for (i = 0; i < els; i++)
11649 if (inst.operands[i].vectype.type != NT_invtype)
11651 first_error (_("types specified in both the mnemonic and operands"));
11652 return badtype;
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)
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++)
11665 if (j != key_el)
11666 inst.vectype.el[j] = neon_type_promote (&inst.vectype.el[key_el],
11667 types[j]);
11669 else if (inst.vectype.elems == 0 && els > 0)
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;
11679 if (inst.operands[key_el].vectype.type != NT_invtype)
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]);
11686 else
11688 first_error (_("operand types can't be inferred"));
11689 return badtype;
11692 else if (inst.vectype.elems != els)
11694 first_error (_("type specifier has the wrong number of parts"));
11695 return badtype;
11698 for (pass = 0; pass < 2; pass++)
11700 for (i = 0; i < els; i++)
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;
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;
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;
11723 if (pass == 0)
11725 if ((thisarg & N_KEY) != 0)
11727 k_type = g_type;
11728 k_size = g_size;
11729 key_allowed = thisarg & ~N_KEY;
11732 else
11734 if ((thisarg & N_VFP) != 0)
11736 enum neon_shape_el regshape = neon_shape_tab[ns].el[i];
11737 unsigned regwidth = neon_shape_el_size[regshape], match;
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;
11747 if (regwidth != match)
11749 first_error (_("operand size must match register width"));
11750 return badtype;
11754 if ((thisarg & N_EQK) == 0)
11756 unsigned given_type = type_chk_of_el_type (g_type, g_size);
11758 if ((given_type & types_allowed) == 0)
11760 first_error (_("bad type in Neon instruction"));
11761 return badtype;
11764 else
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)
11771 first_error (_("inconsistent types in Neon instruction"));
11772 return badtype;
11779 return inst.vectype.el[key_el];
11782 /* Neon-style VFP instruction forwarding. */
11784 /* Thumb VFP instructions have 0xE in the condition field. */
11786 static void
11787 do_vfp_cond_or_thumb (void)
11789 if (thumb_mode)
11790 inst.instruction |= 0xe0000000;
11791 else
11792 inst.instruction |= inst.cond << 28;
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. */
11803 static void
11804 do_vfp_nsyn_opcode (const char *opname)
11806 const struct asm_opcode *opcode;
11808 opcode = hash_find (arm_ops_hsh, opname);
11810 if (!opcode)
11811 abort ();
11813 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant,
11814 thumb_mode ? *opcode->tvariant : *opcode->avariant),
11815 _(BAD_FPU));
11817 if (thumb_mode)
11819 inst.instruction = opcode->tvalue;
11820 opcode->tencode ();
11822 else
11824 inst.instruction = (inst.cond << 28) | opcode->avalue;
11825 opcode->aencode ();
11829 static void
11830 do_vfp_nsyn_add_sub (enum neon_shape rs)
11832 int is_add = (inst.instruction & 0x0fffffff) == N_MNEM_vadd;
11834 if (rs == NS_FFF)
11836 if (is_add)
11837 do_vfp_nsyn_opcode ("fadds");
11838 else
11839 do_vfp_nsyn_opcode ("fsubs");
11841 else
11843 if (is_add)
11844 do_vfp_nsyn_opcode ("faddd");
11845 else
11846 do_vfp_nsyn_opcode ("fsubd");
11850 /* Check operand types to see if this is a VFP instruction, and if so call
11851 PFN (). */
11853 static int
11854 try_vfp_nsyn (int args, void (*pfn) (enum neon_shape))
11856 enum neon_shape rs;
11857 struct neon_type_el et;
11859 switch (args)
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;
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;
11873 default:
11874 abort ();
11877 if (et.type != NT_invtype)
11879 pfn (rs);
11880 return SUCCESS;
11882 else
11883 inst.error = NULL;
11885 return FAIL;
11888 static void
11889 do_vfp_nsyn_mla_mls (enum neon_shape rs)
11891 int is_mla = (inst.instruction & 0x0fffffff) == N_MNEM_vmla;
11893 if (rs == NS_FFF)
11895 if (is_mla)
11896 do_vfp_nsyn_opcode ("fmacs");
11897 else
11898 do_vfp_nsyn_opcode ("fmscs");
11900 else
11902 if (is_mla)
11903 do_vfp_nsyn_opcode ("fmacd");
11904 else
11905 do_vfp_nsyn_opcode ("fmscd");
11909 static void
11910 do_vfp_nsyn_mul (enum neon_shape rs)
11912 if (rs == NS_FFF)
11913 do_vfp_nsyn_opcode ("fmuls");
11914 else
11915 do_vfp_nsyn_opcode ("fmuld");
11918 static void
11919 do_vfp_nsyn_abs_neg (enum neon_shape rs)
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);
11924 if (rs == NS_FF)
11926 if (is_neg)
11927 do_vfp_nsyn_opcode ("fnegs");
11928 else
11929 do_vfp_nsyn_opcode ("fabss");
11931 else
11933 if (is_neg)
11934 do_vfp_nsyn_opcode ("fnegd");
11935 else
11936 do_vfp_nsyn_opcode ("fabsd");
11940 /* Encode single-precision (only!) VFP fldm/fstm instructions. Double precision
11941 insns belong to Neon, and are handled elsewhere. */
11943 static void
11944 do_vfp_nsyn_ldm_stm (int is_dbmode)
11946 int is_ldm = (inst.instruction & (1 << 20)) != 0;
11947 if (is_ldm)
11949 if (is_dbmode)
11950 do_vfp_nsyn_opcode ("fldmdbs");
11951 else
11952 do_vfp_nsyn_opcode ("fldmias");
11954 else
11956 if (is_dbmode)
11957 do_vfp_nsyn_opcode ("fstmdbs");
11958 else
11959 do_vfp_nsyn_opcode ("fstmias");
11963 static void
11964 do_vfp_nsyn_sqrt (void)
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);
11969 if (rs == NS_FF)
11970 do_vfp_nsyn_opcode ("fsqrts");
11971 else
11972 do_vfp_nsyn_opcode ("fsqrtd");
11975 static void
11976 do_vfp_nsyn_div (void)
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);
11982 if (rs == NS_FFF)
11983 do_vfp_nsyn_opcode ("fdivs");
11984 else
11985 do_vfp_nsyn_opcode ("fdivd");
11988 static void
11989 do_vfp_nsyn_nmul (void)
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);
11995 if (rs == NS_FFF)
11997 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
11998 do_vfp_sp_dyadic ();
12000 else
12002 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12003 do_vfp_dp_rd_rn_rm ();
12005 do_vfp_cond_or_thumb ();
12008 static void
12009 do_vfp_nsyn_cmp (void)
12011 if (inst.operands[1].isreg)
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);
12016 if (rs == NS_FF)
12018 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12019 do_vfp_sp_monadic ();
12021 else
12023 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12024 do_vfp_dp_rd_rm ();
12027 else
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);
12032 switch (inst.instruction & 0x0fffffff)
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 ();
12044 if (rs == NS_FI)
12046 inst.instruction = NEON_ENC_SINGLE (inst.instruction);
12047 do_vfp_sp_compare_z ();
12049 else
12051 inst.instruction = NEON_ENC_DOUBLE (inst.instruction);
12052 do_vfp_dp_rd ();
12055 do_vfp_cond_or_thumb ();
12058 static void
12059 nsyn_insert_sp (void)
12061 inst.operands[1] = inst.operands[0];
12062 memset (&inst.operands[0], '\0', sizeof (inst.operands[0]));
12063 inst.operands[0].reg = REG_SP;
12064 inst.operands[0].isreg = 1;
12065 inst.operands[0].writeback = 1;
12066 inst.operands[0].present = 1;
12069 static void
12070 do_vfp_nsyn_push (void)
12072 nsyn_insert_sp ();
12073 if (inst.operands[1].issingle)
12074 do_vfp_nsyn_opcode ("fstmdbs");
12075 else
12076 do_vfp_nsyn_opcode ("fstmdbd");
12079 static void
12080 do_vfp_nsyn_pop (void)
12082 nsyn_insert_sp ();
12083 if (inst.operands[1].issingle)
12084 do_vfp_nsyn_opcode ("fldmias");
12085 else
12086 do_vfp_nsyn_opcode ("fldmiad");
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. */
12092 static unsigned
12093 neon_dp_fixup (unsigned i)
12095 if (thumb_mode)
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;
12101 i &= ~(1 << 24);
12103 i |= 0xef000000;
12105 else
12106 i |= 0xf2000000;
12108 return i;
12111 /* Turn a size (8, 16, 32, 64) into the respective bit number minus 3
12112 (0, 1, 2, 3). */
12114 static unsigned
12115 neon_logbits (unsigned x)
12117 return ffs (x) - 4;
12120 #define LOW4(R) ((R) & 0xf)
12121 #define HI1(R) (((R) >> 4) & 1)
12123 /* Encode insns with bit pattern:
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 |
12128 SIZE is passed in bits. -1 means size field isn't changed, in case it has a
12129 different meaning for some instruction. */
12131 static void
12132 neon_three_same (int isquad, int ubit, int size)
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;
12145 inst.instruction = neon_dp_fixup (inst.instruction);
12148 /* Encode instructions of the form:
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 |
12153 Don't write size if SIZE == -1. */
12155 static void
12156 neon_two_same (int qbit, int ubit, int size)
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;
12165 if (size != -1)
12166 inst.instruction |= neon_logbits (size) << 18;
12168 inst.instruction = neon_dp_fixup (inst.instruction);
12171 /* Neon instruction encoders, in approximate order of appearance. */
12173 static void
12174 do_neon_dyadic_i_su (void)
12176 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12177 struct neon_type_el et = neon_check_type (3, rs,
12178 N_EQK, N_EQK, N_SU_32 | N_KEY);
12179 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12182 static void
12183 do_neon_dyadic_i64_su (void)
12185 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12186 struct neon_type_el et = neon_check_type (3, rs,
12187 N_EQK, N_EQK, N_SU_ALL | N_KEY);
12188 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12191 static void
12192 neon_imm_shift (int write_ubit, int uval, int isquad, struct neon_type_el et,
12193 unsigned immbits)
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;
12207 inst.instruction = neon_dp_fixup (inst.instruction);
12210 static void
12211 do_neon_shl_imm (void)
12213 if (!inst.operands[2].isreg)
12215 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
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);
12218 neon_imm_shift (FALSE, 0, neon_quad (rs), et, inst.operands[2].imm);
12220 else
12222 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12223 struct neon_type_el et = neon_check_type (3, rs,
12224 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12225 unsigned int tmp;
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;
12237 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12238 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12242 static void
12243 do_neon_qshl_imm (void)
12245 if (!inst.operands[2].isreg)
12247 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12248 struct neon_type_el et = neon_check_type (2, rs, N_EQK, N_SU_ALL | N_KEY);
12250 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12251 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
12252 inst.operands[2].imm);
12254 else
12256 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12257 struct neon_type_el et = neon_check_type (3, rs,
12258 N_EQK, N_SU_ALL | N_KEY, N_EQK | N_SGN);
12259 unsigned int tmp;
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;
12265 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12266 neon_three_same (neon_quad (rs), et.type == NT_unsigned, et.size);
12270 static void
12271 do_neon_rshl (void)
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;
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);
12284 static int
12285 neon_cmode_for_logic_imm (unsigned immediate, unsigned *immbits, int size)
12287 /* Handle .I8 pseudo-instructions. */
12288 if (size == 8)
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;
12297 if (size >= 32)
12299 if (immediate == (immediate & 0x000000ff))
12301 *immbits = immediate;
12302 return 0x1;
12304 else if (immediate == (immediate & 0x0000ff00))
12306 *immbits = immediate >> 8;
12307 return 0x3;
12309 else if (immediate == (immediate & 0x00ff0000))
12311 *immbits = immediate >> 16;
12312 return 0x5;
12314 else if (immediate == (immediate & 0xff000000))
12316 *immbits = immediate >> 24;
12317 return 0x7;
12319 if ((immediate & 0xffff) != (immediate >> 16))
12320 goto bad_immediate;
12321 immediate &= 0xffff;
12324 if (immediate == (immediate & 0x000000ff))
12326 *immbits = immediate;
12327 return 0x9;
12329 else if (immediate == (immediate & 0x0000ff00))
12331 *immbits = immediate >> 8;
12332 return 0xb;
12335 bad_immediate:
12336 first_error (_("immediate value out of range"));
12337 return FAIL;
12340 /* True if IMM has form 0bAAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD for bits
12341 A, B, C, D. */
12343 static int
12344 neon_bits_same_in_bytes (unsigned imm)
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);
12352 /* For immediate of above form, return 0bABCD. */
12354 static unsigned
12355 neon_squash_bits (unsigned imm)
12357 return (imm & 0x01) | ((imm & 0x0100) >> 7) | ((imm & 0x010000) >> 14)
12358 | ((imm & 0x01000000) >> 21);
12361 /* Compress quarter-float representation to 0b...000 abcdefgh. */
12363 static unsigned
12364 neon_qfloat_bits (unsigned imm)
12366 return ((imm >> 19) & 0x7f) | ((imm >> 24) & 0x80);
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
12373 MVN). If the immediate looks like a repeated pattern then also
12374 try smaller element sizes. */
12376 static int
12377 neon_cmode_for_move_imm (unsigned immlo, unsigned immhi, int float_p,
12378 unsigned *immbits, int *op, int size,
12379 enum neon_el_type type)
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;
12386 if (type == NT_float && is_quarter_float (immlo) && immhi == 0)
12388 if (size != 32 || *op == 1)
12389 return FAIL;
12390 *immbits = neon_qfloat_bits (immlo);
12391 return 0xf;
12394 if (size == 64)
12396 if (neon_bits_same_in_bytes (immhi)
12397 && neon_bits_same_in_bytes (immlo))
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;
12407 if (immhi != immlo)
12408 return FAIL;
12411 if (size >= 32)
12413 if (immlo == (immlo & 0x000000ff))
12415 *immbits = immlo;
12416 return 0x0;
12418 else if (immlo == (immlo & 0x0000ff00))
12420 *immbits = immlo >> 8;
12421 return 0x2;
12423 else if (immlo == (immlo & 0x00ff0000))
12425 *immbits = immlo >> 16;
12426 return 0x4;
12428 else if (immlo == (immlo & 0xff000000))
12430 *immbits = immlo >> 24;
12431 return 0x6;
12433 else if (immlo == ((immlo & 0x0000ff00) | 0x000000ff))
12435 *immbits = (immlo >> 8) & 0xff;
12436 return 0xc;
12438 else if (immlo == ((immlo & 0x00ff0000) | 0x0000ffff))
12440 *immbits = (immlo >> 16) & 0xff;
12441 return 0xd;
12444 if ((immlo & 0xffff) != (immlo >> 16))
12445 return FAIL;
12446 immlo &= 0xffff;
12449 if (size >= 16)
12451 if (immlo == (immlo & 0x000000ff))
12453 *immbits = immlo;
12454 return 0x8;
12456 else if (immlo == (immlo & 0x0000ff00))
12458 *immbits = immlo >> 8;
12459 return 0xa;
12462 if ((immlo & 0xff) != (immlo >> 8))
12463 return FAIL;
12464 immlo &= 0xff;
12467 if (immlo == (immlo & 0x000000ff))
12469 /* Don't allow MVN with 8-bit immediate. */
12470 if (*op == 1)
12471 return FAIL;
12472 *immbits = immlo;
12473 return 0xe;
12476 return FAIL;
12479 /* Write immediate bits [7:0] to the following locations:
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|
12484 This function is used by VMOV/VMVN/VORR/VBIC. */
12486 static void
12487 neon_write_immbits (unsigned immbits)
12489 inst.instruction |= immbits & 0xf;
12490 inst.instruction |= ((immbits >> 4) & 0x7) << 16;
12491 inst.instruction |= ((immbits >> 7) & 0x1) << 24;
12494 /* Invert low-order SIZE bits of XHI:XLO. */
12496 static void
12497 neon_invert_size (unsigned *xlo, unsigned *xhi, int size)
12499 unsigned immlo = xlo ? *xlo : 0;
12500 unsigned immhi = xhi ? *xhi : 0;
12502 switch (size)
12504 case 8:
12505 immlo = (~immlo) & 0xff;
12506 break;
12508 case 16:
12509 immlo = (~immlo) & 0xffff;
12510 break;
12512 case 64:
12513 immhi = (~immhi) & 0xffffffff;
12514 /* fall through. */
12516 case 32:
12517 immlo = (~immlo) & 0xffffffff;
12518 break;
12520 default:
12521 abort ();
12524 if (xlo)
12525 *xlo = immlo;
12527 if (xhi)
12528 *xhi = immhi;
12531 static void
12532 do_neon_logic (void)
12534 if (inst.operands[2].present && inst.operands[2].isreg)
12536 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
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);
12540 neon_three_same (neon_quad (rs), 0, -1);
12542 else
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);
12547 enum neon_opc opcode = inst.instruction & 0x0fffffff;
12548 unsigned immbits;
12549 int cmode;
12551 if (et.type == NT_invtype)
12552 return;
12554 inst.instruction = NEON_ENC_IMMED (inst.instruction);
12556 immbits = inst.operands[1].imm;
12557 if (et.size == 64)
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))
12564 /* Set immbits to an invalid constant. */
12565 immbits = 0xdeadbeef;
12569 switch (opcode)
12571 case N_MNEM_vbic:
12572 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12573 break;
12575 case N_MNEM_vorr:
12576 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12577 break;
12579 case N_MNEM_vand:
12580 /* Pseudo-instruction for VBIC. */
12581 neon_invert_size (&immbits, 0, et.size);
12582 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12583 break;
12585 case N_MNEM_vorn:
12586 /* Pseudo-instruction for VORR. */
12587 neon_invert_size (&immbits, 0, et.size);
12588 cmode = neon_cmode_for_logic_imm (immbits, &immbits, et.size);
12589 break;
12591 default:
12592 abort ();
12595 if (cmode == FAIL)
12596 return;
12598 inst.instruction |= neon_quad (rs) << 6;
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);
12604 inst.instruction = neon_dp_fixup (inst.instruction);
12608 static void
12609 do_neon_bitfield (void)
12611 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12612 neon_check_type (3, rs, N_IGNORE_TYPE);
12613 neon_three_same (neon_quad (rs), 0, -1);
12616 static void
12617 neon_dyadic_misc (enum neon_el_type ubit_meaning, unsigned types,
12618 unsigned destbits)
12620 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12621 struct neon_type_el et = neon_check_type (3, rs, N_EQK | destbits, N_EQK,
12622 types | N_KEY);
12623 if (et.type == NT_float)
12625 inst.instruction = NEON_ENC_FLOAT (inst.instruction);
12626 neon_three_same (neon_quad (rs), 0, -1);
12628 else
12630 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
12631 neon_three_same (neon_quad (rs), et.type == ubit_meaning, et.size);
12635 static void
12636 do_neon_dyadic_if_su (void)
12638 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12641 static void
12642 do_neon_dyadic_if_su_d (void)
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. */
12646 neon_dyadic_misc (NT_unsigned, N_SUF_32, 0);
12649 static void
12650 do_neon_dyadic_if_i_d (void)
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);
12657 enum vfp_or_neon_is_neon_bits
12659 NEON_CHECK_CC = 1,
12660 NEON_CHECK_ARCH = 2
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:
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.
12673 Which of these operations take place depends on bits from enum
12674 vfp_or_neon_is_neon_bits.
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. */
12682 static int
12683 vfp_or_neon_is_neon (unsigned check)
12685 /* Conditions are always legal in Thumb mode (IT blocks). */
12686 if (!thumb_mode && (check & NEON_CHECK_CC))
12688 if (inst.cond != COND_ALWAYS)
12690 first_error (_(BAD_COND));
12691 return FAIL;
12693 if (inst.uncond_value != -1)
12694 inst.instruction |= inst.uncond_value << 28;
12697 if ((check & NEON_CHECK_ARCH)
12698 && !ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1))
12700 first_error (_(BAD_FPU));
12701 return FAIL;
12704 return SUCCESS;
12707 static void
12708 do_neon_addsub_if_i (void)
12710 if (try_vfp_nsyn (3, do_vfp_nsyn_add_sub) == SUCCESS)
12711 return;
12713 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12714 return;
12716 /* The "untyped" case can't happen. Do this to stop the "U" bit being
12717 affected if we specify unsigned args. */
12718 neon_dyadic_misc (NT_untyped, N_IF_32 | N_I64, 0);
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. */
12730 static void
12731 neon_exchange_operands (void)
12733 void *scratch = alloca (sizeof (inst.operands[0]));
12734 if (inst.operands[1].present)
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]));
12741 else
12743 inst.operands[1] = inst.operands[2];
12744 inst.operands[2] = inst.operands[0];
12748 static void
12749 neon_compare (unsigned regtypes, unsigned immtypes, int invert)
12751 if (inst.operands[2].isreg)
12753 if (invert)
12754 neon_exchange_operands ();
12755 neon_dyadic_misc (NT_unsigned, regtypes, N_SIZ);
12757 else
12759 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
12760 struct neon_type_el et = neon_check_type (2, rs,
12761 N_EQK | N_SIZ, immtypes | N_KEY);
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;
12768 inst.instruction |= neon_quad (rs) << 6;
12769 inst.instruction |= (et.type == NT_float) << 10;
12770 inst.instruction |= neon_logbits (et.size) << 18;
12772 inst.instruction = neon_dp_fixup (inst.instruction);
12776 static void
12777 do_neon_cmp (void)
12779 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, FALSE);
12782 static void
12783 do_neon_cmp_inv (void)
12785 neon_compare (N_SUF_32, N_S8 | N_S16 | N_S32 | N_F32, TRUE);
12788 static void
12789 do_neon_ceq (void)
12791 neon_compare (N_IF_32, N_IF_32, FALSE);
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. */
12800 static unsigned
12801 neon_scalar_for_mul (unsigned scalar, unsigned elsize)
12803 unsigned regno = NEON_SCALAR_REG (scalar);
12804 unsigned elno = NEON_SCALAR_INDEX (scalar);
12806 switch (elsize)
12808 case 16:
12809 if (regno > 7 || elno > 3)
12810 goto bad_scalar;
12811 return regno | (elno << 3);
12813 case 32:
12814 if (regno > 15 || elno > 1)
12815 goto bad_scalar;
12816 return regno | (elno << 4);
12818 default:
12819 bad_scalar:
12820 first_error (_("scalar out of range for multiply instruction"));
12823 return 0;
12826 /* Encode multiply / multiply-accumulate scalar instructions. */
12828 static void
12829 neon_mul_mac (struct neon_type_el et, int ubit)
12831 unsigned scalar;
12833 /* Give a more helpful error message if we have an invalid type. */
12834 if (et.type == NT_invtype)
12835 return;
12837 scalar = neon_scalar_for_mul (inst.operands[2].reg, et.size);
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;
12848 inst.instruction = neon_dp_fixup (inst.instruction);
12851 static void
12852 do_neon_mac_maybe_scalar (void)
12854 if (try_vfp_nsyn (3, do_vfp_nsyn_mla_mls) == SUCCESS)
12855 return;
12857 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12858 return;
12860 if (inst.operands[2].isscalar)
12862 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
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);
12866 neon_mul_mac (et, neon_quad (rs));
12868 else
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);
12876 static void
12877 do_neon_tst (void)
12879 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12880 struct neon_type_el et = neon_check_type (3, rs,
12881 N_EQK, N_EQK, N_8 | N_16 | N_32 | N_KEY);
12882 neon_three_same (neon_quad (rs), 0, et.size);
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. */
12889 static void
12890 do_neon_mul (void)
12892 if (try_vfp_nsyn (3, do_vfp_nsyn_mul) == SUCCESS)
12893 return;
12895 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12896 return;
12898 if (inst.operands[2].isscalar)
12899 do_neon_mac_maybe_scalar ();
12900 else
12901 neon_dyadic_misc (NT_poly, N_I8 | N_I16 | N_I32 | N_F32 | N_P8, 0);
12904 static void
12905 do_neon_qdmulh (void)
12907 if (inst.operands[2].isscalar)
12909 enum neon_shape rs = neon_select_shape (NS_DDS, NS_QQS, NS_NULL);
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);
12913 neon_mul_mac (et, neon_quad (rs));
12915 else
12917 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
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. */
12922 neon_three_same (neon_quad (rs), 0, et.size);
12926 static void
12927 do_neon_fcmp_absolute (void)
12929 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12930 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12931 /* Size field comes from bit mask. */
12932 neon_three_same (neon_quad (rs), 1, -1);
12935 static void
12936 do_neon_fcmp_absolute_inv (void)
12938 neon_exchange_operands ();
12939 do_neon_fcmp_absolute ();
12942 static void
12943 do_neon_step (void)
12945 enum neon_shape rs = neon_select_shape (NS_DDD, NS_QQQ, NS_NULL);
12946 neon_check_type (3, rs, N_EQK, N_EQK, N_F32 | N_KEY);
12947 neon_three_same (neon_quad (rs), 0, -1);
12950 static void
12951 do_neon_abs_neg (void)
12953 enum neon_shape rs;
12954 struct neon_type_el et;
12956 if (try_vfp_nsyn (2, do_vfp_nsyn_abs_neg) == SUCCESS)
12957 return;
12959 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
12960 return;
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);
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;
12969 inst.instruction |= neon_quad (rs) << 6;
12970 inst.instruction |= (et.type == NT_float) << 10;
12971 inst.instruction |= neon_logbits (et.size) << 18;
12973 inst.instruction = neon_dp_fixup (inst.instruction);
12976 static void
12977 do_neon_sli (void)
12979 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
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"));
12985 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
12988 static void
12989 do_neon_sri (void)
12991 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
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"));
12997 neon_imm_shift (FALSE, 0, neon_quad (rs), et, et.size - imm);
13000 static void
13001 do_neon_qshlu_imm (void)
13003 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
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. */
13014 neon_imm_shift (FALSE, 0, neon_quad (rs), et, imm);
13017 static void
13018 do_neon_qmovn (void)
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);
13032 static void
13033 do_neon_qmovun (void)
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);
13042 static void
13043 do_neon_rshift_sat_narrow (void)
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;
13054 /* VQ{R}SHRN.I<size> <Dd>, <Qm>, #0 is a synonym for
13055 VQMOVN.I<size> <Dd>, <Qm>. */
13056 if (imm == 0)
13058 inst.operands[2].present = 0;
13059 inst.instruction = N_MNEM_vqmovn;
13060 do_neon_qmovn ();
13061 return;
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);
13069 static void
13070 do_neon_rshift_sat_narrow_u (void)
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;
13081 /* VQSHRUN.I<size> <Dd>, <Qm>, #0 is a synonym for
13082 VQMOVUN.I<size> <Dd>, <Qm>. */
13083 if (imm == 0)
13085 inst.operands[2].present = 0;
13086 inst.instruction = N_MNEM_vqmovun;
13087 do_neon_qmovun ();
13088 return;
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);
13099 static void
13100 do_neon_movn (void)
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);
13108 static void
13109 do_neon_rshift_narrow (void)
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;
13118 /* If immediate is zero then we are a pseudo-instruction for
13119 VMOVN.I<size> <Dd>, <Qm> */
13120 if (imm == 0)
13122 inst.operands[2].present = 0;
13123 inst.instruction = N_MNEM_vmovn;
13124 do_neon_movn ();
13125 return;
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);
13133 static void
13134 do_neon_shll (void)
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;
13141 if (imm == et.size)
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;
13151 inst.instruction = neon_dp_fixup (inst.instruction);
13153 else
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);
13163 /* Check the various types for the VCVT instruction, and return which version
13164 the current instruction is. */
13166 static int
13167 neon_cvt_flavour (enum neon_shape rs)
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) \
13173 inst.error = NULL; \
13174 return (C); \
13176 struct neon_type_el et;
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;
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);
13189 /* Half-precision conversions. */
13190 CVT_VAR (4, N_F32, N_F16);
13191 CVT_VAR (5, N_F16, N_F32);
13193 whole_reg = N_VFP;
13195 /* VFP instructions. */
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);
13202 /* VFP instructions with bitshift. */
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);
13212 return -1;
13213 #undef CVT_VAR
13216 /* Neon-syntax VFP conversions. */
13218 static void
13219 do_vfp_nsyn_cvt (enum neon_shape rs, int flavour)
13221 const char *opname = 0;
13223 if (rs == NS_DDI || rs == NS_QQI || rs == NS_FFI)
13225 /* Conversions with immediate bitshift. */
13226 const char *enc[] =
13228 "ftosls",
13229 "ftouls",
13230 "fsltos",
13231 "fultos",
13232 NULL,
13233 NULL,
13234 NULL,
13235 NULL,
13236 "ftosld",
13237 "ftould",
13238 "fsltod",
13239 "fultod",
13240 "fshtos",
13241 "fuhtos",
13242 "fshtod",
13243 "fuhtod",
13244 "ftoshs",
13245 "ftouhs",
13246 "ftoshd",
13247 "ftouhd"
13250 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
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]));
13259 else
13261 /* Conversions without bitshift. */
13262 const char *enc[] =
13264 "ftosis",
13265 "ftouis",
13266 "fsitos",
13267 "fuitos",
13268 "NULL",
13269 "NULL",
13270 "fcvtsd",
13271 "fcvtds",
13272 "ftosid",
13273 "ftouid",
13274 "fsitod",
13275 "fuitod"
13278 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc))
13279 opname = enc[flavour];
13282 if (opname)
13283 do_vfp_nsyn_opcode (opname);
13286 static void
13287 do_vfp_nsyn_cvtz (void)
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[] =
13293 "ftosizs",
13294 "ftouizs",
13295 NULL,
13296 NULL,
13297 NULL,
13298 NULL,
13299 NULL,
13300 NULL,
13301 "ftosizd",
13302 "ftouizd"
13305 if (flavour >= 0 && flavour < (int) ARRAY_SIZE (enc) && enc[flavour])
13306 do_vfp_nsyn_opcode (enc[flavour]);
13309 static void
13310 do_neon_cvt (void)
13312 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_FFI, NS_DD, NS_QQ,
13313 NS_FD, NS_DF, NS_FF, NS_QD, NS_DQ, NS_NULL);
13314 int flavour = neon_cvt_flavour (rs);
13316 /* VFP rather than Neon conversions. */
13317 if (flavour >= 6)
13319 do_vfp_nsyn_cvt (rs, flavour);
13320 return;
13323 switch (rs)
13325 case NS_DDI:
13326 case NS_QQI:
13328 unsigned immbits;
13329 unsigned enctab[] = { 0x0000100, 0x1000100, 0x0, 0x1000000 };
13331 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13332 return;
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;
13338 immbits = 32 - inst.operands[2].imm;
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;
13350 inst.instruction = neon_dp_fixup (inst.instruction);
13352 break;
13354 case NS_DD:
13355 case NS_QQ:
13356 int_encode:
13358 unsigned enctab[] = { 0x100, 0x180, 0x0, 0x080 };
13360 inst.instruction = NEON_ENC_INTEGER (inst.instruction);
13362 if (vfp_or_neon_is_neon (NEON_CHECK_CC | NEON_CHECK_ARCH) == FAIL)
13363 return;
13365 if (flavour != -1)
13366 inst.instruction |= enctab[flavour];
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;
13375 inst.instruction = neon_dp_fixup (inst.instruction);
13377 break;
13379 /* Half-precision conversions for Advanced SIMD -- neon. */
13380 case NS_QD:
13381 case NS_DQ:
13383 if ((rs == NS_DQ)
13384 && (inst.vectype.el[0].size != 16 || inst.vectype.el[1].size != 32))
13386 as_bad (_("operand size must match register width"));
13387 break;
13390 if ((rs == NS_QD)
13391 && ((inst.vectype.el[0].size != 32 || inst.vectype.el[1].size != 16)))
13393 as_bad (_("operand size must match register width"));
13394 break;
13397 if (rs == NS_DQ)
13398 inst.instruction = 0x3b60600;
13399 else
13400 inst.instruction = 0x3b60700;
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;
13409 default:
13410 /* Some VFP conversions go here (s32 <-> f32, u32 <-> f32). */
13411 do_vfp_nsyn_cvt (rs, flavour);
13415 static void
13416 do_neon_cvtb (void)
13418 inst.instruction = 0xeb20a40;
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;
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;
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 ();
13436 static void
13437 do_neon_cvtt (void)
13439 do_neon_cvtb ();
13440 inst.instruction |= 0x80;
13443 static void
13444 neon_move_immediate (void)
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);
13449 unsigned immlo, immhi = 0, immbits;
13450 int op, cmode, float_p;
13452 constraint (et.type == NT_invtype,
13453 _("operand size must be specified for immediate VMOV"));
13455 /* We start out as an MVN instruction if OP = 1, MOV otherwise. */
13456 op = (inst.instruction & (1 << 5)) != 0;
13458 immlo = inst.operands[1].imm;
13459 if (inst.operands[1].regisimm)
13460 immhi = inst.operands[1].reg;
13462 constraint (et.size < 32 && (immlo & ~((1 << et.size) - 1)) != 0,
13463 _("immediate has bits set outside the operand size"));
13465 float_p = inst.operands[1].immisfloat;
13467 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits, &op,
13468 et.size, et.type)) == FAIL)
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;
13476 if ((cmode = neon_cmode_for_move_imm (immlo, immhi, float_p, &immbits,
13477 &op, et.size, et.type)) == FAIL)
13479 first_error (_("immediate out of range"));
13480 return;
13484 inst.instruction &= ~(1 << 5);
13485 inst.instruction |= op << 5;
13487 inst.instruction |= LOW4 (inst.operands[0].reg) << 12;
13488 inst.instruction |= HI1 (inst.operands[0].reg) << 22;
13489 inst.instruction |= neon_quad (rs) << 6;
13490 inst.instruction |= cmode << 8;
13492 neon_write_immbits (immbits);
13495 static void
13496 do_neon_mvn (void)
13498 if (inst.operands[1].isreg)
13500 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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;
13507 inst.instruction |= neon_quad (rs) << 6;
13509 else
13511 inst.instruction = NEON_ENC_IMMED (inst.instruction);
13512 neon_move_immediate ();
13515 inst.instruction = neon_dp_fixup (inst.instruction);
13518 /* Encode instructions of form:
13520 |28/24|23|22|21 20|19 16|15 12|11 8|7|6|5|4|3 0|
13521 | U |x |D |size | Rn | Rd |x x x x|N|x|M|x| Rm | */
13523 static void
13524 neon_mixed_length (struct neon_type_el et, unsigned size)
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;
13535 inst.instruction = neon_dp_fixup (inst.instruction);
13538 static void
13539 do_neon_dyadic_long (void)
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);
13547 static void
13548 do_neon_abal (void)
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);
13555 static void
13556 neon_mac_reg_scalar_long (unsigned regtypes, unsigned scalartypes)
13558 if (inst.operands[2].isscalar)
13560 struct neon_type_el et = neon_check_type (3, NS_QDS,
13561 N_EQK | N_DBL, N_EQK, regtypes | N_KEY);
13562 inst.instruction = NEON_ENC_SCALAR (inst.instruction);
13563 neon_mul_mac (et, et.type == NT_unsigned);
13565 else
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);
13574 static void
13575 do_neon_mac_maybe_scalar_long (void)
13577 neon_mac_reg_scalar_long (N_S16 | N_S32 | N_U16 | N_U32, N_SU_32);
13580 static void
13581 do_neon_dyadic_wide (void)
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);
13588 static void
13589 do_neon_dyadic_narrow (void)
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);
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;
13596 neon_mixed_length (et, et.size / 2);
13599 static void
13600 do_neon_mul_sat_scalar_long (void)
13602 neon_mac_reg_scalar_long (N_S16 | N_S32, N_S16 | N_S32);
13605 static void
13606 do_neon_vmull (void)
13608 if (inst.operands[2].isscalar)
13609 do_neon_mac_maybe_scalar_long ();
13610 else
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);
13624 static void
13625 do_neon_ext (void)
13627 enum neon_shape rs = neon_select_shape (NS_DDDI, NS_QQQI, NS_NULL);
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;
13632 constraint (imm >= (unsigned) (neon_quad (rs) ? 16 : 8),
13633 _("shift out of range"));
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;
13640 inst.instruction |= neon_quad (rs) << 6;
13641 inst.instruction |= imm << 8;
13643 inst.instruction = neon_dp_fixup (inst.instruction);
13646 static void
13647 do_neon_rev (void)
13649 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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;
13657 gas_assert (elsize != 0);
13658 constraint (et.size >= elsize,
13659 _("elements must be smaller than reversal region"));
13660 neon_two_same (neon_quad (rs), 1, et.size);
13663 static void
13664 do_neon_dup (void)
13666 if (inst.operands[1].isscalar)
13668 enum neon_shape rs = neon_select_shape (NS_DS, NS_QS, NS_NULL);
13669 struct neon_type_el et = neon_check_type (2, rs,
13670 N_EQK, N_8 | N_16 | N_32 | N_KEY);
13671 unsigned sizebits = et.size >> 3;
13672 unsigned dm = NEON_SCALAR_REG (inst.operands[1].reg);
13673 int logsize = neon_logbits (et.size);
13674 unsigned x = NEON_SCALAR_INDEX (inst.operands[1].reg) << logsize;
13676 if (vfp_or_neon_is_neon (NEON_CHECK_CC) == FAIL)
13677 return;
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;
13684 inst.instruction |= neon_quad (rs) << 6;
13685 inst.instruction |= x << 17;
13686 inst.instruction |= sizebits << 16;
13688 inst.instruction = neon_dp_fixup (inst.instruction);
13690 else
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);
13695 /* Duplicate ARM register to lanes of vector. */
13696 inst.instruction = NEON_ENC_ARMREG (inst.instruction);
13697 switch (et.size)
13699 case 8: inst.instruction |= 0x400000; break;
13700 case 16: inst.instruction |= 0x000020; break;
13701 case 32: inst.instruction |= 0x000000; break;
13702 default: break;
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;
13707 inst.instruction |= neon_quad (rs) << 21;
13708 /* The encoding for this instruction is identical for the ARM and Thumb
13709 variants, except for the condition field. */
13710 do_vfp_cond_or_thumb ();
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.)
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.)
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.
13747 All the encoded bits are hardcoded by this function.
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.
13752 FIXME: Some of the checking may be a bit sloppy (in a couple of cases you
13753 can specify a type where it doesn't make sense to, and is ignored). */
13755 static void
13756 do_neon_mov (void)
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;
13764 switch (rs)
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)
13772 do_vfp_nsyn_opcode ("fcpyd");
13773 break;
13775 /* fall through. */
13777 case NS_QQ: /* case 0/1. */
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;
13793 inst.instruction = neon_dp_fixup (inst.instruction);
13795 break;
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)
13802 /* case 11 (fconstd). */
13803 ldconst = "fconstd";
13804 goto encode_fconstd;
13806 /* fall through. */
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);
13814 break;
13816 case NS_SR: /* case 4. */
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);
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"));
13832 switch (et.size)
13834 case 8: bcdebits = 0x8; break;
13835 case 16: bcdebits = 0x1; break;
13836 case 32: bcdebits = 0x0; break;
13837 default: ;
13840 bcdebits |= x << logsize;
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;
13850 break;
13852 case NS_DRR: /* case 5 (fmdrr). */
13853 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13854 _(BAD_FPU));
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;
13864 case NS_RS: /* case 6. */
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;
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"));
13880 switch (et.size)
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: ;
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;
13897 break;
13899 case NS_RRD: /* case 7 (fmrrd). */
13900 constraint (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_vfp_ext_v2),
13901 _(BAD_FPU));
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;
13911 case NS_FF: /* case 8 (fcpys). */
13912 do_vfp_nsyn_opcode ("fcpys");
13913 break;
13915 case NS_FI: /* case 10 (fconsts). */
13916 ldconst = "fconsts";
13917 encode_fconstd:
13918 if (is_quarter_float (inst.operands[1].imm))
13920 inst.operands[1].imm = neon_qfloat_bits (inst.operands[1].imm);
13921 do_vfp_nsyn_opcode (ldconst);
13923 else
13924 first_error (_("immediate out of range"));
13925 break;
13927 case NS_RF: /* case 12 (fmrs). */
13928 do_vfp_nsyn_opcode ("fmrs");
13929 break;
13931 case NS_FR: /* case 13 (fmsr). */
13932 do_vfp_nsyn_opcode ("fmsr");
13933 break;
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;
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");
13955 break;
13957 default:
13958 abort ();
13962 static void
13963 do_neon_rshift_round_imm (void)
13965 enum neon_shape rs = neon_select_shape (NS_DDI, NS_QQI, NS_NULL);
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;
13969 /* imm == 0 case is encoded as VMOV for V{R}SHR. */
13970 if (imm == 0)
13972 inst.operands[2].present = 0;
13973 do_neon_mov ();
13974 return;
13977 constraint (imm < 1 || (unsigned)imm > et.size,
13978 _("immediate out of range for shift"));
13979 neon_imm_shift (TRUE, et.type == NT_unsigned, neon_quad (rs), et,
13980 et.size - imm);
13983 static void
13984 do_neon_movl (void)
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);
13993 static void
13994 do_neon_trn (void)
13996 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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);
14000 neon_two_same (neon_quad (rs), 1, et.size);
14003 static void
14004 do_neon_zip_uzp (void)
14006 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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)
14011 /* Special case: encode as VTRN.32 <Dd>, <Dm>. */
14012 inst.instruction = N_MNEM_vtrn;
14013 do_neon_trn ();
14014 return;
14016 neon_two_same (neon_quad (rs), 1, et.size);
14019 static void
14020 do_neon_sat_abs_neg (void)
14022 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14023 struct neon_type_el et = neon_check_type (2, rs,
14024 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14025 neon_two_same (neon_quad (rs), 1, et.size);
14028 static void
14029 do_neon_pair_long (void)
14031 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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;
14035 neon_two_same (neon_quad (rs), 1, et.size);
14038 static void
14039 do_neon_recip_est (void)
14041 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
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;
14045 neon_two_same (neon_quad (rs), 1, et.size);
14048 static void
14049 do_neon_cls (void)
14051 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14052 struct neon_type_el et = neon_check_type (2, rs,
14053 N_EQK, N_S8 | N_S16 | N_S32 | N_KEY);
14054 neon_two_same (neon_quad (rs), 1, et.size);
14057 static void
14058 do_neon_clz (void)
14060 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14061 struct neon_type_el et = neon_check_type (2, rs,
14062 N_EQK, N_I8 | N_I16 | N_I32 | N_KEY);
14063 neon_two_same (neon_quad (rs), 1, et.size);
14066 static void
14067 do_neon_cnt (void)
14069 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14070 struct neon_type_el et = neon_check_type (2, rs,
14071 N_EQK | N_INT, N_8 | N_KEY);
14072 neon_two_same (neon_quad (rs), 1, et.size);
14075 static void
14076 do_neon_swp (void)
14078 enum neon_shape rs = neon_select_shape (NS_DD, NS_QQ, NS_NULL);
14079 neon_two_same (neon_quad (rs), 1, -1);
14082 static void
14083 do_neon_tbl_tbx (void)
14085 unsigned listlenbits;
14086 neon_check_type (3, NS_DLD, N_EQK, N_EQK, N_8 | N_KEY);
14088 if (inst.operands[1].imm < 1 || inst.operands[1].imm > 4)
14090 first_error (_("bad list length for table lookup"));
14091 return;
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;
14103 inst.instruction = neon_dp_fixup (inst.instruction);
14106 static void
14107 do_neon_ldm_stm (void)
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;
14113 if (inst.operands[1].issingle)
14115 do_vfp_nsyn_ldm_stm (is_dbmode);
14116 return;
14119 constraint (is_dbmode && !inst.operands[0].writeback,
14120 _("writeback (!) must be used for VLDMDB and VSTMDB"));
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"));
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;
14131 inst.instruction |= offsetbits;
14133 do_vfp_cond_or_thumb ();
14136 static void
14137 do_neon_ldr_str (void)
14139 int is_ldr = (inst.instruction & (1 << 20)) != 0;
14141 if (inst.operands[0].issingle)
14143 if (is_ldr)
14144 do_vfp_nsyn_opcode ("flds");
14145 else
14146 do_vfp_nsyn_opcode ("fsts");
14148 else
14150 if (is_ldr)
14151 do_vfp_nsyn_opcode ("fldd");
14152 else
14153 do_vfp_nsyn_opcode ("fstd");
14157 /* "interleave" version also handles non-interleaving register VLD1/VST1
14158 instructions. */
14160 static void
14161 do_neon_ld_st_interleave (void)
14163 struct neon_type_el et = neon_check_type (1, NS_NULL,
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[] =
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. */
14179 int typebits;
14181 if (et.type == NT_invtype)
14182 return;
14184 if (inst.operands[1].immisalign)
14185 switch (inst.operands[1].imm >> 8)
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:
14200 first_error (_("bad alignment"));
14201 return;
14204 inst.instruction |= alignbits << 4;
14205 inst.instruction |= neon_logbits (et.size) << 6;
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);
14215 typebits = typetable[idx];
14217 constraint (typebits == -1, _("bad list type for instruction"));
14219 inst.instruction &= ~0xf00;
14220 inst.instruction |= typebits << 8;
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. */
14228 static int
14229 neon_alignment_bit (int size, int align, int *do_align, ...)
14231 va_list ap;
14232 int result = FAIL, thissize, thisalign;
14234 if (!inst.operands[1].immisalign)
14236 *do_align = 0;
14237 return SUCCESS;
14240 va_start (ap, do_align);
14244 thissize = va_arg (ap, int);
14245 if (thissize == -1)
14246 break;
14247 thisalign = va_arg (ap, int);
14249 if (size == thissize && align == thisalign)
14250 result = SUCCESS;
14252 while (result != SUCCESS);
14254 va_end (ap);
14256 if (result == SUCCESS)
14257 *do_align = 1;
14258 else
14259 first_error (_("unsupported alignment for instruction"));
14261 return result;
14264 static void
14265 do_neon_ld_st_lane (void)
14267 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
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;
14274 if (et.type == NT_invtype)
14275 return;
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"));
14285 switch (n)
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)
14294 unsigned alignbits = 0;
14295 switch (et.size)
14297 case 16: alignbits = 0x1; break;
14298 case 32: alignbits = 0x3; break;
14299 default: ;
14301 inst.instruction |= alignbits << 4;
14303 break;
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;
14314 case 2: /* VLD3 / VST3. */
14315 constraint (inst.operands[1].immisalign,
14316 _("can't use alignment with this instruction"));
14317 break;
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)
14326 unsigned alignbits = 0;
14327 switch (et.size)
14329 case 8: alignbits = 0x1; break;
14330 case 16: alignbits = 0x1; break;
14331 case 32: alignbits = (align == 64) ? 0x1 : 0x2; break;
14332 default: ;
14334 inst.instruction |= alignbits << 4;
14336 break;
14338 default: ;
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);
14345 inst.instruction |= NEON_LANE (inst.operands[0].imm) << (logsize + 5);
14346 inst.instruction |= logsize << 10;
14349 /* Encode single n-element structure to all lanes VLD<n> instructions. */
14351 static void
14352 do_neon_ld_dup (void)
14354 struct neon_type_el et = neon_check_type (1, NS_NULL, N_8 | N_16 | N_32);
14355 int align_good, do_align = 0;
14357 if (et.type == NT_invtype)
14358 return;
14360 switch ((inst.instruction >> 8) & 3)
14362 case 0: /* VLD1. */
14363 gas_assert (NEON_REG_STRIDE (inst.operands[0].imm) != 2);
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))
14370 case 1: break;
14371 case 2: inst.instruction |= 1 << 5; break;
14372 default: first_error (_("bad list length")); return;
14374 inst.instruction |= neon_logbits (et.size) << 6;
14375 break;
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;
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;
14399 case 3: /* VLD4. */
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;
14415 break;
14417 default: ;
14420 inst.instruction |= do_align << 4;
14423 /* Disambiguate VLD<n> and VST<n> instructions, and fill in common bits (those
14424 apart from bits [11:4]. */
14426 static void
14427 do_neon_ldx_stx (void)
14429 switch (NEON_LANE (inst.operands[0].imm))
14431 case NEON_INTERLEAVE_LANES:
14432 inst.instruction = NEON_ENC_INTERLV (inst.instruction);
14433 do_neon_ld_st_interleave ();
14434 break;
14436 case NEON_ALL_LANES:
14437 inst.instruction = NEON_ENC_DUP (inst.instruction);
14438 do_neon_ld_dup ();
14439 break;
14441 default:
14442 inst.instruction = NEON_ENC_LANE (inst.instruction);
14443 do_neon_ld_st_lane ();
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;
14451 if (inst.operands[1].postind)
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;
14460 else if (inst.operands[1].writeback)
14462 inst.instruction |= 0xd;
14464 else
14465 inst.instruction |= 0xf;
14467 if (thumb_mode)
14468 inst.instruction |= 0xf9000000;
14469 else
14470 inst.instruction |= 0xf4000000;
14473 /* Overall per-instruction processing. */
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. */
14482 static void
14483 fix_new_arm (fragS * frag,
14484 int where,
14485 short int size,
14486 expressionS * exp,
14487 int pc_rel,
14488 int reloc)
14490 fixS * new_fix;
14492 switch (exp->X_op)
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;
14501 default:
14502 new_fix = fix_new (frag, where, size, make_expr_symbol (exp), 0,
14503 pc_rel, reloc);
14504 break;
14507 /* Mark whether the fix is to a THUMB instruction, or an ARM
14508 instruction. */
14509 new_fix->tc_fix_data = thumb_mode;
14512 /* Create a frg for an instruction requiring relaxation. */
14513 static void
14514 output_relax_insn (void)
14516 char * to;
14517 symbolS *sym;
14518 int offset;
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);
14524 switch (inst.reloc.exp.X_op)
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;
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);
14544 /* Write a 32-bit thumb instruction to buf. */
14545 static void
14546 put_thumb32_insn (char * buf, unsigned long insn)
14548 md_number_to_chars (buf, insn >> 16, THUMB_SIZE);
14549 md_number_to_chars (buf + THUMB_SIZE, insn, THUMB_SIZE);
14552 static void
14553 output_inst (const char * str)
14555 char * to = NULL;
14557 if (inst.error)
14559 as_bad ("%s -- `%s'", inst.error, str);
14560 return;
14562 if (inst.relax)
14564 output_relax_insn ();
14565 return;
14567 if (inst.size == 0)
14568 return;
14570 to = frag_more (inst.size);
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;
14577 if (thumb_mode && (inst.size > THUMB_SIZE))
14579 gas_assert (inst.size == (2 * THUMB_SIZE));
14580 put_thumb32_insn (to, inst.instruction);
14582 else if (inst.size > INSN_SIZE)
14584 gas_assert (inst.size == (2 * INSN_SIZE));
14585 md_number_to_chars (to, inst.instruction, INSN_SIZE);
14586 md_number_to_chars (to + INSN_SIZE, inst.instruction, INSN_SIZE);
14588 else
14589 md_number_to_chars (to, inst.instruction, inst.size);
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);
14596 dwarf2_emit_insn (inst.size);
14599 static char *
14600 output_it_inst (int cond, int mask, char * to)
14602 unsigned long instruction = 0xbf00;
14604 mask &= 0xf;
14605 instruction |= mask;
14606 instruction |= cond << 4;
14608 if (to == NULL)
14610 to = frag_more (2);
14611 #ifdef OBJ_ELF
14612 dwarf2_emit_insn (2);
14613 #endif
14616 md_number_to_chars (to, instruction, 2);
14618 return to;
14621 /* Tag values used in struct asm_opcode's tag field. */
14622 enum opcode_tag
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. */
14629 OT_csuffixF, /* Some forms of the instruction take a conditional
14630 suffix, others place 0xF where the condition field
14631 would be. */
14632 OT_cinfix3, /* Instruction takes a conditional infix,
14633 beginning at character index 3. (In
14634 unified mode, it becomes a suffix.) */
14635 OT_cinfix3_deprecated, /* The same as OT_cinfix3. This is used for
14636 tsts, cmps, cmns, and teqs. */
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. */
14641 OT_csuf_or_in3, /* Instruction takes either a conditional
14642 suffix or an infix at character index 3. */
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. */
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.
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.
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.
14671 Accordingly, the algorithm for looking up primary opcodes given
14672 an identifier is:
14674 1. Look up the identifier in the opcode table.
14675 If we find a match, go to step U.
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.
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.
14688 4. Fail.
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.
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.
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. */
14707 static const struct asm_opcode *
14708 opcode_lookup (char **str)
14710 char *end, *base;
14711 char *affix;
14712 const struct asm_opcode *opcode;
14713 const struct asm_cond *cond;
14714 char save[2];
14715 bfd_boolean neon_supported;
14717 neon_supported = ARM_CPU_HAS_FEATURE (cpu_variant, fpu_neon_ext_v1);
14719 /* Scan up to the end of the mnemonic, which must end in white space,
14720 '.' (in unified mode, or for Neon instructions), or end of string. */
14721 for (base = end = *str; *end != '\0'; end++)
14722 if (*end == ' ' || ((unified_syntax || neon_supported) && *end == '.'))
14723 break;
14725 if (end == base)
14726 return 0;
14728 /* Handle a possible width suffix and/or Neon type suffix. */
14729 if (end[0] == '.')
14731 int offset = 2;
14733 /* The .w and .n suffixes are only valid if the unified syntax is in
14734 use. */
14735 if (unified_syntax && end[1] == 'w')
14736 inst.size_req = 4;
14737 else if (unified_syntax && end[1] == 'n')
14738 inst.size_req = 2;
14739 else
14740 offset = 0;
14742 inst.vectype.elems = 0;
14744 *str = end + offset;
14746 if (end[offset] == '.')
14748 /* See if we have a Neon type suffix (possible in either unified or
14749 non-unified ARM syntax mode). */
14750 if (parse_neon_type (&inst.vectype, str) == FAIL)
14751 return 0;
14753 else if (end[offset] != '\0' && end[offset] != ' ')
14754 return 0;
14756 else
14757 *str = end;
14759 /* Look for unaffixed or special-case affixed mnemonic. */
14760 opcode = hash_find_n (arm_ops_hsh, base, end - base);
14761 if (opcode)
14763 /* step U */
14764 if (opcode->tag < OT_odd_infix_0)
14766 inst.cond = COND_ALWAYS;
14767 return opcode;
14770 if (warn_on_deprecated && unified_syntax)
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);
14774 gas_assert (cond);
14776 inst.cond = cond->value;
14777 return opcode;
14780 /* Cannot have a conditional suffix on a mnemonic of less than two
14781 characters. */
14782 if (end - base < 3)
14783 return 0;
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)
14791 /* step CE */
14792 switch (opcode->tag)
14794 case OT_cinfix3_legacy:
14795 /* Ignore conditional suffixes matched on infix only mnemonics. */
14796 break;
14798 case OT_cinfix3:
14799 case OT_cinfix3_deprecated:
14800 case OT_odd_infix_unc:
14801 if (!unified_syntax)
14802 return 0;
14803 /* else fall through */
14805 case OT_csuffix:
14806 case OT_csuffixF:
14807 case OT_csuf_or_in3:
14808 inst.cond = cond->value;
14809 return opcode;
14811 case OT_unconditional:
14812 case OT_unconditionalF:
14813 if (thumb_mode)
14815 inst.cond = cond->value;
14817 else
14819 /* delayed diagnostic */
14820 inst.error = BAD_COND;
14821 inst.cond = COND_ALWAYS;
14823 return opcode;
14825 default:
14826 return 0;
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;
14835 /* Look for infixed mnemonic in the usual position. */
14836 affix = base + 3;
14837 cond = hash_find_n (arm_cond_hsh, affix, 2);
14838 if (!cond)
14839 return 0;
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);
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))
14853 /* step CM */
14854 if (warn_on_deprecated && unified_syntax
14855 && (opcode->tag == OT_cinfix3
14856 || opcode->tag == OT_cinfix3_deprecated))
14857 as_warn (_("conditional infixes are deprecated in unified syntax"));
14859 inst.cond = cond->value;
14860 return opcode;
14863 return 0;
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. */
14874 static void
14875 new_automatic_it_block (int cond)
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);
14884 /* Close an automatic IT block.
14885 See comments in new_automatic_it_block (). */
14887 static void
14888 close_automatic_it_block (void)
14890 now_it.mask = 0x10;
14891 now_it.block_length = 0;
14894 /* Update the mask of the current automatically-generated IT
14895 instruction. See comments in new_automatic_it_block (). */
14897 static void
14898 now_it_add_mask (int cond)
14900 #define CLEAR_BIT(value, nbit) ((value) & ~(1 << (nbit)))
14901 #define SET_BIT_VALUE(value, bitvalue, nbit) (CLEAR_BIT (value, nbit) \
14902 | ((bitvalue) << (nbit)))
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,
14911 ((5 - now_it.block_length) - 1) );
14912 output_it_inst (now_it.cc, now_it.mask, now_it.insn);
14914 #undef CLEAR_BIT
14915 #undef SET_BIT_VALUE
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
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).
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.
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.
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.
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.
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. */
14973 static void
14974 it_fsm_pre_encode (void)
14976 if (inst.cond != COND_ALWAYS)
14977 inst.it_insn_type = INSIDE_IT_INSN;
14978 else
14979 inst.it_insn_type = OUTSIDE_IT_INSN;
14981 now_it.state_handled = 0;
14984 /* IT state FSM handling function. */
14986 static int
14987 handle_it_state (void)
14989 now_it.state_handled = 1;
14991 switch (now_it.state)
14993 case OUTSIDE_IT_BLOCK:
14994 switch (inst.it_insn_type)
14996 case OUTSIDE_IT_INSN:
14997 break;
14999 case INSIDE_IT_INSN:
15000 case INSIDE_IT_LAST_INSN:
15001 if (thumb_mode == 0)
15003 if (unified_syntax
15004 && !(implicit_it_mode & IMPLICIT_IT_MODE_ARM))
15005 as_tsktsk (_("Warning: conditional outside an IT block"\
15006 " for Thumb."));
15008 else
15010 if ((implicit_it_mode & IMPLICIT_IT_MODE_THUMB)
15011 && ARM_CPU_HAS_FEATURE (cpu_variant, arm_arch_t2))
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 ();
15018 else
15020 inst.error = BAD_OUT_IT;
15021 return FAIL;
15024 break;
15026 case IF_INSIDE_IT_LAST_INSN:
15027 case NEUTRAL_IT_INSN:
15028 break;
15030 case IT_INSN:
15031 now_it.state = MANUAL_IT_BLOCK;
15032 now_it.block_length = 0;
15033 break;
15035 break;
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). */
15045 switch (inst.it_insn_type)
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;
15053 case INSIDE_IT_INSN:
15054 case INSIDE_IT_LAST_INSN:
15055 case IF_INSIDE_IT_LAST_INSN:
15056 now_it.block_length++;
15058 if (now_it.block_length > 4
15059 || !now_it_compatible (inst.cond))
15061 force_automatic_it_block_close ();
15062 if (inst.it_insn_type != IF_INSIDE_IT_LAST_INSN)
15063 new_automatic_it_block (inst.cond);
15065 else
15067 now_it_add_mask (inst.cond);
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;
15076 case NEUTRAL_IT_INSN:
15077 now_it.block_length++;
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;
15085 case IT_INSN:
15086 close_automatic_it_block ();
15087 now_it.state = MANUAL_IT_BLOCK;
15088 break;
15090 break;
15092 case MANUAL_IT_BLOCK:
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);
15101 switch (inst.it_insn_type)
15103 case OUTSIDE_IT_INSN:
15104 inst.error = BAD_NOT_IT;
15105 return FAIL;
15107 case INSIDE_IT_INSN:
15108 if (cond != inst.cond)
15110 inst.error = BAD_IT_COND;
15111 return FAIL;
15113 break;
15115 case INSIDE_IT_LAST_INSN:
15116 case IF_INSIDE_IT_LAST_INSN:
15117 if (cond != inst.cond)
15119 inst.error = BAD_IT_COND;
15120 return FAIL;
15122 if (!is_last)
15124 inst.error = BAD_BRANCH;
15125 return FAIL;
15127 break;
15129 case NEUTRAL_IT_INSN:
15130 /* The BKPT instruction is unconditional even in an IT block. */
15131 break;
15133 case IT_INSN:
15134 inst.error = BAD_IT_IT;
15135 return FAIL;
15138 break;
15141 return SUCCESS;
15144 static void
15145 it_fsm_post_encode (void)
15147 int is_last;
15149 if (!now_it.state_handled)
15150 handle_it_state ();
15152 is_last = (now_it.mask == 0x10);
15153 if (is_last)
15155 now_it.state = OUTSIDE_IT_BLOCK;
15156 now_it.mask = 0;
15160 static void
15161 force_automatic_it_block_close (void)
15163 if (now_it.state == AUTOMATIC_IT_BLOCK)
15165 close_automatic_it_block ();
15166 now_it.state = OUTSIDE_IT_BLOCK;
15167 now_it.mask = 0;
15171 static int
15172 in_it_block (void)
15174 if (!now_it.state_handled)
15175 handle_it_state ();
15177 return now_it.state != OUTSIDE_IT_BLOCK;
15180 void
15181 md_assemble (char *str)
15183 char *p = str;
15184 const struct asm_opcode * opcode;
15186 /* Align the previous label if needed. */
15187 if (last_label_seen != NULL)
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);
15194 memset (&inst, '\0', sizeof (inst));
15195 inst.reloc.type = BFD_RELOC_UNUSED;
15197 opcode = opcode_lookup (&p);
15198 if (!opcode)
15200 /* It wasn't an instruction, but it might be a register alias of
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))
15204 as_bad (_("bad instruction `%s'"), str);
15206 return;
15209 if (warn_on_deprecated && opcode->tag == OT_cinfix3_deprecated)
15210 as_warn (_("s suffix on comparison instruction is deprecated"));
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;
15216 if (thumb_mode)
15218 arm_feature_set variant;
15220 variant = cpu_variant;
15221 /* Only allow coprocessor instructions on Thumb-2 capable devices. */
15222 if (!ARM_CPU_HAS_FEATURE (variant, arm_arch_t2))
15223 ARM_CLEAR_FEATURE (variant, variant, fpu_any_hard);
15224 /* Check that this instruction is supported for this CPU. */
15225 if (!opcode->tvariant
15226 || (thumb_mode == 1
15227 && !ARM_CPU_HAS_FEATURE (variant, *opcode->tvariant)))
15229 as_bad (_("selected processor does not support `%s'"), str);
15230 return;
15232 if (inst.cond != COND_ALWAYS && !unified_syntax
15233 && opcode->tencode != do_t_branch)
15235 as_bad (_("Thumb does not support conditional execution"));
15236 return;
15239 if (!ARM_CPU_HAS_FEATURE (variant, arm_ext_v6t2) && !inst.size_req)
15241 /* Implicit require narrow instructions on Thumb-1. This avoids
15242 relaxation accidentally introducing Thumb-2 instructions. */
15243 if (opcode->tencode != do_t_blx && opcode->tencode != do_t_branch23
15244 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15245 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15246 inst.size_req = 2;
15249 mapping_state (MAP_THUMB);
15250 inst.instruction = opcode->tvalue;
15252 if (!parse_operands (p, opcode->operands))
15254 /* Prepare the it_insn_type for those encodings that don't set
15255 it. */
15256 it_fsm_pre_encode ();
15258 opcode->tencode ();
15260 it_fsm_post_encode ();
15263 if (!(inst.error || inst.relax))
15265 gas_assert (inst.instruction < 0xe800 || inst.instruction > 0xffff);
15266 inst.size = (inst.instruction > 0xffff ? 4 : 2);
15267 if (inst.size_req && inst.size_req != inst.size)
15269 as_bad (_("cannot honor width suffix -- `%s'"), str);
15270 return;
15274 /* Something has gone badly wrong if we try to relax a fixed size
15275 instruction. */
15276 gas_assert (inst.size_req == 0 || !inst.relax);
15278 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15279 *opcode->tvariant);
15280 /* Many Thumb-2 instructions also have Thumb-1 variants, so explicitly
15281 set those bits when Thumb-2 32-bit instructions are seen. ie.
15282 anything other than bl/blx and v6-M instructions.
15283 This is overly pessimistic for relaxable instructions. */
15284 if (((inst.size == 4 && (inst.instruction & 0xf800e800) != 0xf000e800)
15285 || inst.relax)
15286 && !(ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_msr)
15287 || ARM_CPU_HAS_FEATURE (*opcode->tvariant, arm_ext_barrier)))
15288 ARM_MERGE_FEATURE_SETS (thumb_arch_used, thumb_arch_used,
15289 arm_ext_v6t2);
15291 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
15293 bfd_boolean is_bx;
15295 /* bx is allowed on v5 cores, and sometimes on v4 cores. */
15296 is_bx = (opcode->aencode == do_bx);
15298 /* Check that this instruction is supported for this CPU. */
15299 if (!(is_bx && fix_v4bx)
15300 && !(opcode->avariant &&
15301 ARM_CPU_HAS_FEATURE (cpu_variant, *opcode->avariant)))
15303 as_bad (_("selected processor does not support `%s'"), str);
15304 return;
15306 if (inst.size_req)
15308 as_bad (_("width suffixes are invalid in ARM mode -- `%s'"), str);
15309 return;
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))
15321 it_fsm_pre_encode ();
15322 opcode->aencode ();
15323 it_fsm_post_encode ();
15325 /* Arm mode bx is marked as both v4T and v5 because it's still required
15326 on a hypothetical non-thumb v5 core. */
15327 if (is_bx)
15328 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used, arm_ext_v4t);
15329 else
15330 ARM_MERGE_FEATURE_SETS (arm_arch_used, arm_arch_used,
15331 *opcode->avariant);
15333 else
15335 as_bad (_("attempt to use an ARM instruction on a Thumb-only processor "
15336 "-- `%s'"), str);
15337 return;
15339 output_inst (str);
15342 static void
15343 check_it_blocks_finished (void)
15345 #ifdef OBJ_ELF
15346 asection *sect;
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)
15352 as_warn (_("section '%s' finished with an open IT block."),
15353 sect->name);
15355 #else
15356 if (now_it.state == MANUAL_IT_BLOCK)
15357 as_warn (_("file finished with an open IT block."));
15358 #endif
15361 /* Various frobbings of labels and their addresses. */
15363 void
15364 arm_start_line_hook (void)
15366 last_label_seen = NULL;
15369 void
15370 arm_frob_label (symbolS * sym)
15372 last_label_seen = sym;
15374 ARM_SET_THUMB (sym, thumb_mode);
15376 #if defined OBJ_COFF || defined OBJ_ELF
15377 ARM_SET_INTERWORK (sym, support_interwork);
15378 #endif
15380 force_automatic_it_block_close ();
15382 /* Note - do not allow local symbols (.Lxxx) to be labelled
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:
15389 ldr r2, [pc, .Laaa]
15390 lsl r3, r3, #2
15391 ldr r2, [r3, r2]
15392 mov pc, r2
15394 .Lbbb: .word .Lxxx
15395 .Lccc: .word .Lyyy
15396 ..etc...
15397 .Laaa: .word Lbbb
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.
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)
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. */
15420 THUMB_SET_FUNC (sym, 1);
15422 label_is_thumb_function_name = FALSE;
15425 dwarf2_emit_label (sym);
15429 arm_data_in_code (void)
15431 if (thumb_mode && ! strncmp (input_line_pointer + 1, "data:", 5))
15433 *input_line_pointer = '/';
15434 input_line_pointer += 5;
15435 *input_line_pointer = 0;
15436 return 1;
15439 return 0;
15442 char *
15443 arm_canonicalize_symbol_name (char * name)
15445 int len;
15447 if (thumb_mode && (len = strlen (name)) > 5
15448 && streq (name + len - 5, "/data"))
15449 *(name + len - 5) = 0;
15451 return name;
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. */
15459 #define REGDEF(s,n,t) { #s, n, REG_TYPE_##t, TRUE, 0 }
15460 #define REGNUM(p,n,t) REGDEF(p##n, n, t)
15461 #define REGNUM2(p,n,t) REGDEF(p##n, 2 * n, t)
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)
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)
15478 static const struct reg_entry reg_names[] =
15480 /* ARM integer registers. */
15481 REGSET(r, RN), REGSET(R, RN),
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),
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),
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),
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),
15499 /* Coprocessor numbers. */
15500 REGSET(p, CP), REGSET(P, CP),
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),
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),
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),
15514 /* VFP SP registers. */
15515 REGSET(s,VFS), REGSET(S,VFS),
15516 REGSETH(s,VFS), REGSETH(S,VFS),
15518 /* VFP DP Registers. */
15519 REGSET(d,VFD), REGSET(D,VFD),
15520 /* Extra Neon DP registers. */
15521 REGSETH(d,VFD), REGSETH(D,VFD),
15523 /* Neon QP registers. */
15524 REGSET2(q,NQ), REGSET2(Q,NQ),
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),
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),
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),
15538 REGNUM(mvax,0,MVAX), REGNUM(mvax,1,MVAX),
15539 REGNUM(mvax,2,MVAX), REGNUM(mvax,3,MVAX),
15540 REGDEF(dspsc,0,DSPSC),
15542 REGNUM(MVAX,0,MVAX), REGNUM(MVAX,1,MVAX),
15543 REGNUM(MVAX,2,MVAX), REGNUM(MVAX,3,MVAX),
15544 REGDEF(DSPSC,0,DSPSC),
15546 /* iWMMXt data registers - p0, c0-15. */
15547 REGSET(wr,MMXWR), REGSET(wR,MMXWR), REGSET(WR, MMXWR),
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),
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),
15561 /* XScale accumulator registers. */
15562 REGNUM(acc,0,XSCALE), REGNUM(ACC,0,XSCALE),
15564 #undef REGDEF
15565 #undef REGNUM
15566 #undef REGSET
15568 /* Table of all PSR suffixes. Bare "CPSR" and "SPSR" are handled
15569 within psr_required_here. */
15570 static const struct asm_psr psrs[] =
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},
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},
15646 /* Table of V7M psr names. */
15647 static const struct asm_psr v7m_psrs[] =
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}
15666 /* Table of all shift-in-operand names. */
15667 static const struct asm_shift_name shift_names [] =
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 }
15677 /* Table of all explicit relocation names. */
15678 #ifdef OBJ_ELF
15679 static struct reloc_entry reloc_names[] =
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}
15693 #endif
15695 /* Table of all conditional affixes. 0xF is not defined as a condition code. */
15696 static const struct asm_cond conds[] =
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}
15715 static struct asm_barrier_opt barrier_opt_names[] =
15717 { "sy", 0xf },
15718 { "un", 0x7 },
15719 { "st", 0xe },
15720 { "unst", 0x6 }
15723 /* Table of ARM-format instructions. */
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, }
15736 /* These macros abstract out the exact format of the mnemonic table and
15737 save some repeated characters. */
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, \
15742 THUMB_VARIANT, do_##ae, do_##te }
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) \
15747 TxCE (mnem, aop, 0x##top, nops, ops, ae, te)
15748 #define tCE(mnem, aop, top, nops, ops, ae, te) \
15749 TxCE (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
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, \
15755 THUMB_VARIANT, do_##ae, do_##te }
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 }
15759 #define TC3(mnem, aop, top, nops, ops, ae, te) \
15760 TxC3 (mnem, aop, 0x##top, nops, ops, ae, te)
15761 #define TC3w(mnem, aop, top, nops, ops, ae, te) \
15762 TxC3w (mnem, aop, 0x##top, nops, ops, ae, te)
15763 #define tC3(mnem, aop, top, nops, ops, ae, te) \
15764 TxC3 (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
15765 #define tC3w(mnem, aop, top, nops, ops, ae, te) \
15766 TxC3w (mnem, aop, T_MNEM_##top, nops, ops, ae, te)
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) \
15771 { #m1 #m2 #m3, OPS##nops ops, sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
15772 0x##op, top, ARM_VARIANT, THUMB_VARIANT, do_##ae, do_##te }
15774 #define TxCM(m1, m2, op, top, nops, ops, ae, te) \
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)
15795 #define TCM(m1,m2, aop, top, nops, ops, ae, te) \
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)
15800 /* Mnemonic that cannot be conditionalized. The ARM condition-code
15801 field is still 0xE. Many of the Thumb variants can be executed
15802 conditionally, so this is checked separately. */
15803 #define TUE(mnem, op, top, nops, ops, ae, te) \
15804 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0x##top, ARM_VARIANT, \
15805 THUMB_VARIANT, do_##ae, do_##te }
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, \
15811 THUMB_VARIANT, do_##ae, do_##te }
15813 /* ARM-only variants of all the above. */
15814 #define CE(mnem, op, nops, ops, ae) \
15815 { #mnem, OPS##nops ops, OT_csuffix, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15817 #define C3(mnem, op, nops, ops, ae) \
15818 { #mnem, OPS##nops ops, OT_cinfix3, 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
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 }
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 }
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 }
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 }
15843 #define xCM_(m1, m2, m3, op, nops, ops, ae) \
15844 { #m1 #m2 #m3, OPS##nops ops, \
15845 sizeof (#m2) == 1 ? OT_odd_infix_unc : OT_odd_infix_0 + sizeof (#m1) - 1, \
15846 0x##op, 0x0, ARM_VARIANT, 0, do_##ae, NULL }
15848 #define CM(m1, m2, op, nops, ops, ae) \
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)
15869 #define UE(mnem, op, nops, ops, ae) \
15870 { #mnem, OPS##nops ops, OT_unconditional, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
15872 #define UF(mnem, op, nops, ops, ae) \
15873 { #mnem, OPS##nops ops, OT_unconditionalF, 0x##op, 0, ARM_VARIANT, 0, do_##ae, NULL }
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 }
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 }
15888 /* Neon insn with conditional suffix for the ARM version, non-overloaded
15889 version. */
15890 #define NCE_tag(mnem, op, nops, ops, enc, tag) \
15891 { #mnem, OPS##nops ops, tag, 0x##op, 0x##op, ARM_VARIANT, \
15892 THUMB_VARIANT, do_##enc, do_##enc }
15894 #define NCE(mnem, op, nops, ops, enc) \
15895 NCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
15897 #define NCEF(mnem, op, nops, ops, enc) \
15898 NCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
15900 /* Neon insn with conditional suffix for the ARM version, overloaded types. */
15901 #define nCE_tag(mnem, op, nops, ops, enc, tag) \
15902 { #mnem, OPS##nops ops, tag, N_MNEM_##op, N_MNEM_##op, \
15903 ARM_VARIANT, THUMB_VARIANT, do_##enc, do_##enc }
15905 #define nCE(mnem, op, nops, ops, enc) \
15906 nCE_tag (mnem, op, nops, ops, enc, OT_csuffix)
15908 #define nCEF(mnem, op, nops, ops, enc) \
15909 nCE_tag (mnem, op, nops, ops, enc, OT_csuffixF)
15911 #define do_0 0
15913 /* Thumb-only, unconditional. */
15914 #define UT(mnem, op, nops, ops, te) TUE (mnem, 0, op, nops, ops, 0, te)
15916 static const struct asm_opcode insns[] =
15918 #define ARM_VARIANT &arm_ext_v1 /* Core ARM Instructions. */
15919 #define THUMB_VARIANT &arm_ext_v4t
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),
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),
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),
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),
15941 tC3w(tsts, 1100000, tst, 2, (RR, SH), cmp, t_mvn_tst),
15942 CL(tstp, 110f000, 2, (RR, SH), cmp),
15943 tCE(cmp, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15944 tC3w(cmps, 1500000, cmp, 2, (RR, SH), cmp, t_mov_cmp),
15945 CL(cmpp, 150f000, 2, (RR, SH), cmp),
15946 tCE(cmn, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15947 tC3w(cmns, 1700000, cmn, 2, (RR, SH), cmp, t_mvn_tst),
15948 CL(cmnp, 170f000, 2, (RR, SH), cmp),
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),
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),
15960 tCE(stm, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15961 tC3(stmia, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15962 tC3(stmea, 8800000, stmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15963 tCE(ldm, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15964 tC3(ldmia, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15965 tC3(ldmfd, 8900000, ldmia, 2, (RRw, REGLST), ldmstm, t_ldmstm),
15967 TCE(swi, f000000, df00, 1, (EXPi), swi, t_swi),
15968 TCE(svc, f000000, df00, 1, (EXPi), swi, t_swi),
15969 tCE(b, a000000, b, 1, (EXPr), branch, t_branch),
15970 TCE(bl, b000000, f000f800, 1, (EXPr), bl, t_branch23),
15972 /* Pseudo ops. */
15973 tCE(adr, 28f0000, adr, 2, (RR, EXP), adr, t_adr),
15974 C3(adrl, 28f0000, 2, (RR, EXP), adrl),
15975 tCE(nop, 1a00000, nop, 1, (oI255c), nop, t_nop),
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),
15983 tC3(asrs, 1b00040, asrs, 3, (RR, oRR, SH), shift, t_shift),
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),
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),
15995 #undef THUMB_VARIANT
15996 #define THUMB_VARIANT &arm_ext_v6
15997 TCE(cpy, 1a00000, 4600, 2, (RR, RR), rd_rm, t_cpy),
15999 /* V1 instructions with no Thumb analogue prior to V6T2. */
16000 #undef THUMB_VARIANT
16001 #define THUMB_VARIANT &arm_ext_v6t2
16002 TCE(teq, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16003 TC3w(teqs, 1300000, ea900f00, 2, (RR, SH), cmp, t_mvn_tst),
16004 CL(teqp, 130f000, 2, (RR, SH), cmp),
16006 TC3(ldrt, 4300000, f8500e00, 2, (RR, ADDR), ldstt, t_ldstt),
16007 TC3(ldrbt, 4700000, f8100e00, 2, (RR, ADDR), ldstt, t_ldstt),
16008 TC3(strt, 4200000, f8400e00, 2, (RR, ADDR), ldstt, t_ldstt),
16009 TC3(strbt, 4600000, f8000e00, 2, (RR, ADDR), ldstt, t_ldstt),
16011 TC3(stmdb, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16012 TC3(stmfd, 9000000, e9000000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16014 TC3(ldmdb, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
16015 TC3(ldmea, 9100000, e9100000, 2, (RRw, REGLST), ldmstm, t_ldmstm),
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),
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),
16030 #undef ARM_VARIANT
16031 #define ARM_VARIANT &arm_ext_v2 /* ARM 2 - multiplies. */
16032 #undef THUMB_VARIANT
16033 #define THUMB_VARIANT &arm_ext_v4t
16034 tCE(mul, 0000090, mul, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16035 tC3(muls, 0100090, muls, 3, (RRnpc, RRnpc, oRR), mul, t_mul),
16037 #undef THUMB_VARIANT
16038 #define THUMB_VARIANT &arm_ext_v6t2
16039 TCE(mla, 0200090, fb000000, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16040 C3(mlas, 0300090, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas),
16042 /* Generic coprocessor instructions. */
16043 TCE(cdp, e000000, ee000000, 6, (RCP, I15b, RCN, RCN, RCN, oI7b), cdp, cdp),
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),
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),
16051 #undef ARM_VARIANT
16052 #define ARM_VARIANT &arm_ext_v2s /* ARM 3 - swp instructions. */
16053 CE(swp, 1000090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16054 C3(swpb, 1400090, 3, (RRnpc, RRnpc, RRnpcb), rd_rm_rn),
16056 #undef ARM_VARIANT
16057 #define ARM_VARIANT &arm_ext_v3 /* ARM 6 Status register instructions. */
16058 #undef THUMB_VARIANT
16059 #define THUMB_VARIANT &arm_ext_msr
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),
16063 #undef ARM_VARIANT
16064 #define ARM_VARIANT &arm_ext_v3m /* ARM 7M long multiplies. */
16065 #undef THUMB_VARIANT
16066 #define THUMB_VARIANT &arm_ext_v6t2
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),
16076 #undef ARM_VARIANT
16077 #define ARM_VARIANT &arm_ext_v4 /* ARM Architecture 4. */
16078 #undef THUMB_VARIANT
16079 #define THUMB_VARIANT &arm_ext_v4t
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),
16087 #undef ARM_VARIANT
16088 #define ARM_VARIANT &arm_ext_v4t_5
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),
16094 #undef ARM_VARIANT
16095 #define ARM_VARIANT &arm_ext_v5 /* ARM Architecture 5T. */
16096 #undef THUMB_VARIANT
16097 #define THUMB_VARIANT &arm_ext_v5t
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),
16103 #undef THUMB_VARIANT
16104 #define THUMB_VARIANT &arm_ext_v6t2
16105 TCE(clz, 16f0f10, fab0f080, 2, (RRnpc, RRnpc), rd_rm, t_clz),
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),
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),
16114 #undef ARM_VARIANT
16115 #define ARM_VARIANT &arm_ext_v5exp /* ARM Architecture 5TExP. */
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),
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),
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),
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),
16134 TCE(smulwb, 12000a0, fb30f000, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
16135 TCE(smulwt, 12000e0, fb30f010, 3, (RRnpc, RRnpc, RRnpc), smul, t_simd),
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),
16142 #undef ARM_VARIANT
16143 #define ARM_VARIANT &arm_ext_v5e /* ARM Architecture 5TE. */
16144 TUF(pld, 450f000, f810f000, 1, (ADDR), pld, t_pld),
16145 TC3(ldrd, 00000d0, e8500000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
16146 TC3(strd, 00000f0, e8400000, 3, (RRnpc, oRRnpc, ADDRGLDRS), ldrd, t_ldstd),
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),
16151 #undef ARM_VARIANT
16152 #define ARM_VARIANT &arm_ext_v5j /* ARM Architecture 5TEJ. */
16153 TCE(bxj, 12fff20, f3c08f00, 1, (RR), bxj, t_bxj),
16155 #undef ARM_VARIANT
16156 #define ARM_VARIANT &arm_ext_v6 /* ARM V6. */
16157 #undef THUMB_VARIANT
16158 #define THUMB_VARIANT &arm_ext_v6
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),
16170 #undef THUMB_VARIANT
16171 #define THUMB_VARIANT &arm_ext_v6t2
16172 TCE(ldrex, 1900f9f, e8500f00, 2, (RRnpc, ADDR), ldrex, t_ldrex),
16173 TCE(strex, 1800f90, e8400000, 3, (RRnpc, RRnpc, ADDR), strex, t_strex),
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),
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),
16180 /* ARM V6 not included in V7M (eg. integer SIMD). */
16181 #undef THUMB_VARIANT
16182 #define THUMB_VARIANT &arm_ext_v6_notm
16183 TUF(cps, 1020000, f3af8100, 1, (I31b), imm0, t_cps),
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),
16188 TCE(qasx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16189 /* Old name for QASX. */
16190 TCE(qaddsubx, 6200f30, faa0f010, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
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),
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),
16198 TCE(sasx, 6100f30, faa0f000, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16199 /* Old name for SASX. */
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),
16203 TCE(shasx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16204 /* Old name for SHASX. */
16205 TCE(shaddsubx, 6300f30, faa0f020, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
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),
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),
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),
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),
16218 TCE(uasx, 6500f30, faa0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16219 /* Old name for UASX. */
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),
16223 TCE(uhasx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16224 /* Old name for UHASX. */
16225 TCE(uhaddsubx, 6700f30, faa0f060, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
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),
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),
16233 TCE(uqasx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16234 /* Old name for UQASX. */
16235 TCE(uqaddsubx, 6600f30, faa0f050, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
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),
16241 TCE(usub16, 6500f70, fad0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16242 TCE(usax, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16243 /* Old name for USAX. */
16244 TCE(usubaddx, 6500f50, fae0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
16245 TCE(usub8, 6500ff0, fac0f040, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
16262 TCE(sel, 6800fb0, faa0f080, 3, (RRnpc, RRnpc, RRnpc), rd_rn_rm, t_simd),
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),
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),
16285 TCE(ssat16, 6a00f30, f3200000, 3, (RRnpc, I16, RRnpc), ssat16, t_ssat16),
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),
16289 TCE(usat16, 6e00f30, f3a00000, 3, (RRnpc, I15, RRnpc), usat16, t_usat16),
16291 #undef ARM_VARIANT
16292 #define ARM_VARIANT &arm_ext_v6k
16293 #undef THUMB_VARIANT
16294 #define THUMB_VARIANT &arm_ext_v6k
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),
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),
16305 #undef THUMB_VARIANT
16306 #define THUMB_VARIANT &arm_ext_v6t2
16307 TCE(ldrexb, 1d00f9f, e8d00f4f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
16308 TCE(ldrexh, 1f00f9f, e8d00f5f, 2, (RRnpc, RRnpcb), rd_rn, rd_rn),
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),
16311 TUF(clrex, 57ff01f, f3bf8f2f, 0, (), noargs, noargs),
16313 #undef ARM_VARIANT
16314 #define ARM_VARIANT &arm_ext_v6z
16315 TCE(smc, 1600070, f7f08000, 1, (EXPi), smc, t_smc),
16317 #undef ARM_VARIANT
16318 #define ARM_VARIANT &arm_ext_v6t2
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),
16324 TCE(mls, 0600090, fb000010, 4, (RRnpc, RRnpc, RRnpc, RRnpc), mlas, t_mla),
16325 TCE(movw, 3000000, f2400000, 2, (RRnpc, HALF), mov16, t_mov16),
16326 TCE(movt, 3400000, f2c00000, 2, (RRnpc, HALF), mov16, t_mov16),
16327 TCE(rbit, 6ff0f30, fa90f0a0, 2, (RR, RR), rd_rm, t_rbit),
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),
16334 UT(cbnz, b900, 2, (RR, EXP), t_cbz),
16335 UT(cbz, b100, 2, (RR, EXP), t_cbz),
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. */
16339 #undef ARM_VARIANT
16340 #define ARM_VARIANT &arm_ext_v1
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),
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),
16360 /* Thumb2 only instructions. */
16361 #undef ARM_VARIANT
16362 #define ARM_VARIANT NULL
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),
16366 TCE(orn, 0, ea600000, 3, (RR, oRR, SH), 0, t_orn),
16367 TCE(orns, 0, ea700000, 3, (RR, oRR, SH), 0, t_orn),
16368 TCE(tbb, 0, e8d0f000, 1, (TB), 0, t_tb),
16369 TCE(tbh, 0, e8d0f010, 1, (TB), 0, t_tb),
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),
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),
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),
16394 #undef ARM_VARIANT
16395 #define ARM_VARIANT &fpu_fpa_ext_v1 /* Core FPA instruction set (V1). */
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
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),
16788 cCE(cmf, e90f110, 2, (RF, RF_IF), fpa_cmp),
16789 C3E(cmfe, ed0f110, 2, (RF, RF_IF), fpa_cmp),
16790 cCE(cnf, eb0f110, 2, (RF, RF_IF), fpa_cmp),
16791 C3E(cnfe, ef0f110, 2, (RF, RF_IF), fpa_cmp),
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),
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. */
16811 cCE(fix, e100110, 2, (RR, RF), rd_rm),
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),
16825 /* Instructions that were new with the real FPA, call them V2. */
16826 #undef ARM_VARIANT
16827 #define ARM_VARIANT &fpu_fpa_ext_v2
16828 cCE(lfm, c100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16829 cCL(lfmfd, c900200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16830 cCL(lfmea, d100200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16831 cCE(sfm, c000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16832 cCL(sfmfd, d000200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16833 cCL(sfmea, c800200, 3, (RF, I4b, ADDR), fpa_ldmstm),
16835 #undef ARM_VARIANT
16836 #define ARM_VARIANT &fpu_vfp_ext_v1xd /* VFP V1xD (single precision). */
16837 /* Moves and type conversions. */
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),
16851 /* Memory operations. */
16852 cCE(flds, d100a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
16853 cCE(fsts, d000a00, 2, (RVS, ADDRGLDC), vfp_sp_ldst),
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),
16871 /* Monadic operations. */
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),
16876 /* Dyadic operations. */
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),
16887 /* Comparisons. */
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),
16893 #undef ARM_VARIANT
16894 #define ARM_VARIANT &fpu_vfp_ext_v1 /* VFP V1 (Double precision). */
16895 /* Moves and type conversions. */
16896 cCE(fcpyd, eb00b40, 2, (RVD, RVD), vfp_dp_rd_rm),
16897 cCE(fcvtds, eb70ac0, 2, (RVD, RVS), vfp_dp_sp_cvt),
16898 cCE(fcvtsd, eb70bc0, 2, (RVS, RVD), vfp_sp_dp_cvt),
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),
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),
16910 /* Memory operations. */
16911 cCE(fldd, d100b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
16912 cCE(fstd, d000b00, 2, (RVD, ADDRGLDC), vfp_dp_ldst),
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),
16922 /* Monadic operations. */
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),
16927 /* Dyadic operations. */
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),
16938 /* Comparisons. */
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),
16944 #undef ARM_VARIANT
16945 #define ARM_VARIANT &fpu_vfp_ext_v2
16946 cCE(fmsrr, c400a10, 3, (VRSLST, RR, RR), vfp_sp2_from_reg2),
16947 cCE(fmrrs, c500a10, 3, (RR, RR, VRSLST), vfp_reg2_from_sp2),
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),
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),
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),
16974 nCEF(vadd, vadd, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16975 nCEF(vsub, vsub, 3, (RNSDQ, oRNSDQ, RNSDQ), neon_addsub_if_i),
16977 NCEF(vabs, 1b10300, 2, (RNSDQ, RNSDQ), neon_abs_neg),
16978 NCEF(vneg, 1b10380, 2, (RNSDQ, RNSDQ), neon_abs_neg),
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),
16986 NCE(vldr, d100b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16987 NCE(vstr, d000b00, 2, (RVSD, ADDRGLDC), neon_ldr_str),
16989 nCEF(vcvt, vcvt, 3, (RNSDQ, RNSDQ, oI32b), neon_cvt),
16990 nCEF(vcvtb, vcvt, 2, (RVS, RVS), neon_cvtb),
16991 nCEF(vcvtt, vcvt, 2, (RVS, RVS), neon_cvtt),
16994 /* NOTE: All VMOV encoding is special-cased! */
16995 NCE(vmov, 0, 1, (VMOV), neon_mov),
16996 NCE(vmovq, 0, 1, (VMOV), neon_mov),
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),
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),
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),
17063 /* Comparison. Type I8 I16 I32 F32. */
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. */
17070 nUF(vmlaq, vmla, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mac_maybe_scalar),
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. */
17074 nUF(vaddq, vadd, 3, (RNQ, oRNQ, RNQ), neon_addsub_if_i),
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. */
17080 nUF(vmulq, vmul, 3, (RNQ, oRNQ, RNDQ_RNSC), neon_mul),
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),
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),
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),
17099 /* Two address, int/float. Types S8 S16 S32 F32. */
17100 NUF(vabsq, 1b10300, 2, (RNQ, RNQ), neon_abs_neg),
17101 NUF(vnegq, 1b10380, 2, (RNQ, RNQ), neon_abs_neg),
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. */
17135 nUF(vcvtq, vcvt, 3, (RNQ, RNQ, oI32b), neon_cvt),
17137 nUF(vmvn, vmvn, 2, (RNDQ, RNDQ_IMVNb), neon_mvn),
17138 nUF(vmvnq, vmvn, 2, (RNQ, RNDQ_IMVNb), neon_mvn),
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),
17166 /* Extract. Size 8. */
17167 NUF(vext, 0b00000, 4, (RNDQ, oRNDQ, RNDQ, I15), neon_ext),
17168 NUF(vextq, 0b00000, 4, (RNQ, oRNQ, RNQ, I15), neon_ext),
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),
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),
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
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),
17243 #undef THUMB_VARIANT
17244 #define THUMB_VARIANT &fpu_vfp_ext_v3
17245 #undef ARM_VARIANT
17246 #define ARM_VARIANT &fpu_vfp_ext_v3
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),
17266 #undef THUMB_VARIANT
17267 #undef ARM_VARIANT
17268 #define ARM_VARIANT &arm_cext_xscale /* Intel XScale extensions. */
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),
17278 #undef ARM_VARIANT
17279 #define ARM_VARIANT &arm_cext_iwmmxt /* Intel Wireless MMX technology. */
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),
17298 cCE(tmcr, e000110, 2, (RIWC_RIWG, RR), rn_rd),
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),
17309 cCE(tmrc, e100110, 2, (RR, RIWC_RIWG), rd_rn),
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),
17380 cCE(wrorh, e700040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17381 cCE(wrorhg, e700148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17382 cCE(wrorw, eb00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17383 cCE(wrorwg, eb00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17384 cCE(wrord, ef00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
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),
17391 cCE(wsllh, e500040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17392 cCE(wsllhg, e500148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17393 cCE(wsllw, e900040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17394 cCE(wsllwg, e900148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17395 cCE(wslld, ed00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17396 cCE(wslldg, ed00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17397 cCE(wsrah, e400040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17398 cCE(wsrahg, e400148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17399 cCE(wsraw, e800040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17400 cCE(wsrawg, e800148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17401 cCE(wsrad, ec00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17402 cCE(wsradg, ec00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17403 cCE(wsrlh, e600040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17404 cCE(wsrlhg, e600148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17405 cCE(wsrlw, ea00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
17406 cCE(wsrlwg, ea00148, 3, (RIWR, RIWR, RIWG), rd_rn_rm),
17407 cCE(wsrld, ee00040, 3, (RIWR, RIWR, RIWR_I32z),iwmmxt_wrwrwr_or_imm5),
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),
17443 #undef ARM_VARIANT
17444 #define ARM_VARIANT &arm_cext_iwmmxt2 /* Intel Wireless MMX technology, version 2. */
17445 cCE(torvscb, e13f190, 1, (RR), iwmmxt_tandorc),
17446 cCE(torvsch, e53f190, 1, (RR), iwmmxt_tandorc),
17447 cCE(torvscw, e93f190, 1, (RR), iwmmxt_tandorc),
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),
17503 #undef ARM_VARIANT
17504 #define ARM_VARIANT &arm_cext_maverick /* Cirrus Maverick instructions. */
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),
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),
17582 #undef ARM_VARIANT
17583 #undef THUMB_VARIANT
17584 #undef TCE
17585 #undef TCM
17586 #undef TUE
17587 #undef TUF
17588 #undef TCC
17589 #undef cCE
17590 #undef cCL
17591 #undef C3E
17592 #undef CE
17593 #undef CM
17594 #undef UE
17595 #undef UF
17596 #undef UT
17597 #undef NUF
17598 #undef nUF
17599 #undef NCE
17600 #undef nCE
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
17610 /* MD interface: bits in the object file. */
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). */
17619 void
17620 md_number_to_chars (char * buf, valueT val, int n)
17622 if (target_big_endian)
17623 number_to_chars_bigendian (buf, val, n);
17624 else
17625 number_to_chars_littleendian (buf, val, n);
17628 static valueT
17629 md_chars_to_number (char * buf, int n)
17631 valueT result = 0;
17632 unsigned char * where = (unsigned char *) buf;
17634 if (target_big_endian)
17636 while (n--)
17638 result <<= 8;
17639 result |= (*where++ & 255);
17642 else
17644 while (n--)
17646 result <<= 8;
17647 result |= (where[n] & 255);
17651 return result;
17654 /* MD interface: Sections. */
17656 /* Estimate the size of a frag before relaxing. Assume everything fits in
17657 2 bytes. */
17660 md_estimate_size_before_relax (fragS * fragp,
17661 segT segtype ATTRIBUTE_UNUSED)
17663 fragp->fr_var = 2;
17664 return 2;
17667 /* Convert a machine dependent frag. */
17669 void
17670 md_convert_frag (bfd *abfd, segT asec ATTRIBUTE_UNUSED, fragS *fragp)
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;
17681 buf = fragp->fr_literal + fragp->fr_fix;
17683 old_op = bfd_get_16(abfd, buf);
17684 if (fragp->fr_symbol)
17686 exp.X_op = O_symbol;
17687 exp.X_add_symbol = fragp->fr_symbol;
17689 else
17691 exp.X_op = O_constant;
17693 exp.X_add_number = fragp->fr_offset;
17694 opcode = fragp->fr_subtype;
17695 switch (opcode)
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)
17709 insn = THUMB_OP32 (opcode);
17710 if ((old_op >> 12) == 4 || (old_op >> 12) == 9)
17712 insn |= (old_op & 0x700) << 4;
17714 else
17716 insn |= (old_op & 7) << 12;
17717 insn |= (old_op & 0x38) << 13;
17719 insn |= 0x00000c00;
17720 put_thumb32_insn (buf, insn);
17721 reloc_type = BFD_RELOC_ARM_T32_OFFSET_IMM;
17723 else
17725 reloc_type = BFD_RELOC_ARM_THUMB_OFFSET;
17727 pc_rel = (opcode == T_MNEM_ldr_pc2);
17728 break;
17729 case T_MNEM_adr:
17730 if (fragp->fr_var == 4)
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;
17737 else
17739 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17740 exp.X_add_number -= 4;
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)
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;
17758 else
17760 reloc_type = BFD_RELOC_ARM_THUMB_IMM;
17762 pc_rel = 0;
17763 break;
17764 case T_MNEM_b:
17765 if (fragp->fr_var == 4)
17767 insn = THUMB_OP32(opcode);
17768 put_thumb32_insn (buf, insn);
17769 reloc_type = BFD_RELOC_THUMB_PCREL_BRANCH25;
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)
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;
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)
17793 /* ??? Choose between add and addw. */
17794 insn = THUMB_OP32 (opcode);
17795 insn |= (old_op & 0xf0) << 4;
17796 put_thumb32_insn (buf, insn);
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;
17802 else
17803 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17804 pc_rel = 0;
17805 break;
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)
17813 insn = THUMB_OP32 (opcode);
17814 insn |= (old_op & 0xf0) << 4;
17815 insn |= (old_op & 0xf) << 16;
17816 put_thumb32_insn (buf, insn);
17817 if (insn & (1 << 20))
17818 reloc_type = BFD_RELOC_ARM_T32_ADD_IMM;
17819 else
17820 reloc_type = BFD_RELOC_ARM_T32_IMMEDIATE;
17822 else
17823 reloc_type = BFD_RELOC_ARM_THUMB_ADD;
17824 pc_rel = 0;
17825 break;
17826 default:
17827 abort ();
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;
17836 /* Return the size of a relaxable immediate operand instruction.
17837 SHIFT and SIZE specify the form of the allowable immediate. */
17838 static int
17839 relax_immediate (fragS *fragp, int size, int shift)
17841 offsetT offset;
17842 offsetT mask;
17843 offsetT low;
17845 /* ??? Should be able to do better than this. */
17846 if (fragp->fr_symbol)
17847 return 4;
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)
17854 return 4;
17855 if (offset & ~mask)
17856 return 4;
17857 return 2;
17860 /* Get the address of a symbol during relaxation. */
17861 static addressT
17862 relaxed_symbol_addr (fragS *fragp, long stretch)
17864 fragS *sym_frag;
17865 addressT addr;
17866 symbolS *sym;
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;
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. */
17879 if (stretch != 0
17880 && sym_frag->relax_marker != fragp->relax_marker)
17882 fragS *f;
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)
17892 if (f->fr_type == rs_align || f->fr_type == rs_align_code)
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;
17903 if (f != NULL)
17904 addr += stretch;
17907 return addr;
17910 /* Return the size of a relaxable adr pseudo-instruction or PC-relative
17911 load. */
17912 static int
17913 relax_adr (fragS *fragp, asection *sec, long stretch)
17915 addressT addr;
17916 offsetT val;
17918 /* Assume worst case for symbols not known to be in the same section. */
17919 if (!S_IS_DEFINED (fragp->fr_symbol)
17920 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17921 return 4;
17923 val = relaxed_symbol_addr (fragp, stretch);
17924 addr = fragp->fr_address + fragp->fr_fix;
17925 addr = (addr + 4) & ~3;
17926 /* Force misaligned targets to 32-bit variant. */
17927 if (val & 3)
17928 return 4;
17929 val -= addr;
17930 if (val < 0 || val > 1020)
17931 return 4;
17932 return 2;
17935 /* Return the size of a relaxable add/sub immediate instruction. */
17936 static int
17937 relax_addsub (fragS *fragp, asection *sec)
17939 char *buf;
17940 int op;
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);
17951 /* Return the size of a relaxable branch instruction. BITS is the
17952 size of the offset field in the narrow instruction. */
17954 static int
17955 relax_branch (fragS *fragp, asection *sec, int bits, long stretch)
17957 addressT addr;
17958 offsetT val;
17959 offsetT limit;
17961 /* Assume worst case for symbols not known to be in the same section. */
17962 if (!S_IS_DEFINED (fragp->fr_symbol)
17963 || sec != S_GET_SEGMENT (fragp->fr_symbol))
17964 return 4;
17966 #ifdef OBJ_ELF
17967 if (S_IS_DEFINED (fragp->fr_symbol)
17968 && ARM_IS_FUNC (fragp->fr_symbol))
17969 return 4;
17970 #endif
17972 val = relaxed_symbol_addr (fragp, stretch);
17973 addr = fragp->fr_address + fragp->fr_fix + 4;
17974 val -= addr;
17976 /* Offset is a signed value *2 */
17977 limit = 1 << bits;
17978 if (val >= limit || val < -limit)
17979 return 4;
17980 return 2;
17984 /* Relax a machine dependent frag. This returns the amount by which
17985 the current size of the frag should change. */
17988 arm_relax_frag (asection *sec, fragS *fragp, long stretch)
17990 int oldsize;
17991 int newsize;
17993 oldsize = fragp->fr_var;
17994 switch (fragp->fr_subtype)
17996 case T_MNEM_ldr_pc2:
17997 newsize = relax_adr (fragp, sec, stretch);
17998 break;
17999 case T_MNEM_ldr_pc:
18000 case T_MNEM_ldr_sp:
18001 case T_MNEM_str_sp:
18002 newsize = relax_immediate (fragp, 8, 2);
18003 break;
18004 case T_MNEM_ldr:
18005 case T_MNEM_str:
18006 newsize = relax_immediate (fragp, 5, 2);
18007 break;
18008 case T_MNEM_ldrh:
18009 case T_MNEM_strh:
18010 newsize = relax_immediate (fragp, 5, 1);
18011 break;
18012 case T_MNEM_ldrb:
18013 case T_MNEM_strb:
18014 newsize = relax_immediate (fragp, 5, 0);
18015 break;
18016 case T_MNEM_adr:
18017 newsize = relax_adr (fragp, sec, stretch);
18018 break;
18019 case T_MNEM_mov:
18020 case T_MNEM_movs:
18021 case T_MNEM_cmp:
18022 case T_MNEM_cmn:
18023 newsize = relax_immediate (fragp, 8, 0);
18024 break;
18025 case T_MNEM_b:
18026 newsize = relax_branch (fragp, sec, 11, stretch);
18027 break;
18028 case T_MNEM_bcond:
18029 newsize = relax_branch (fragp, sec, 8, stretch);
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:
18046 abort ();
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.
18052 Don't freeze them unconditionally because targets may be artificially
18053 misaligned by the expansion of preceding frags. */
18054 if (stretch <= 0 && newsize > 2)
18056 md_convert_frag (sec->owner, sec, fragp);
18057 frag_wane (fragp);
18060 return newsize - oldsize;
18063 /* Round up a section size to the appropriate boundary. */
18065 valueT
18066 md_section_align (segT segment ATTRIBUTE_UNUSED,
18067 valueT size)
18069 #if (defined (OBJ_AOUT) || defined (OBJ_MAYBE_AOUT))
18070 if (OUTPUT_FLAVOR == bfd_target_aout_flavour)
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;
18079 align = bfd_get_section_alignment (stdoutput, segment);
18080 size = ((size + (1 << align) - 1) & ((valueT) -1 << align));
18082 #endif
18084 return size;
18087 /* This is called from HANDLE_ALIGN in write.c. Fill in the contents
18088 of an rs_align_code fragment. */
18090 void
18091 arm_handle_align (fragS * fragP)
18093 static char const arm_noop[2][2][4] =
18095 { /* ARMv1 */
18096 {0x00, 0x00, 0xa0, 0xe1}, /* LE */
18097 {0xe1, 0xa0, 0x00, 0x00}, /* BE */
18099 { /* ARMv6k */
18100 {0x00, 0xf0, 0x20, 0xe3}, /* LE */
18101 {0xe3, 0x20, 0xf0, 0x00}, /* BE */
18104 static char const thumb_noop[2][2][2] =
18106 { /* Thumb-1 */
18107 {0xc0, 0x46}, /* LE */
18108 {0x46, 0xc0}, /* BE */
18110 { /* Thumb-2 */
18111 {0x00, 0xbf}, /* LE */
18112 {0xbf, 0x00} /* BE */
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 */
18121 unsigned bytes, fix, noop_size;
18122 char * p;
18123 const char * noop;
18124 const char *narrow_noop = NULL;
18126 if (fragP->fr_type != rs_align_code)
18127 return;
18129 bytes = fragP->fr_next->fr_address - fragP->fr_address - fragP->fr_fix;
18130 p = fragP->fr_literal + fragP->fr_fix;
18131 fix = 0;
18133 if (bytes > MAX_MEM_FOR_RS_ALIGN_CODE)
18134 bytes &= MAX_MEM_FOR_RS_ALIGN_CODE;
18136 gas_assert ((fragP->tc_frag_data & MODE_RECORDED) != 0);
18138 if (fragP->tc_frag_data & (~ MODE_RECORDED))
18140 if (ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6t2))
18142 narrow_noop = thumb_noop[1][target_big_endian];
18143 noop = wide_thumb_noop[target_big_endian];
18145 else
18146 noop = thumb_noop[0][target_big_endian];
18147 noop_size = 2;
18149 else
18151 noop = arm_noop[ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v6k) != 0]
18152 [target_big_endian];
18153 noop_size = 4;
18156 fragP->fr_var = noop_size;
18158 if (bytes & (noop_size - 1))
18160 fix = bytes & (noop_size - 1);
18161 memset (p, 0, fix);
18162 p += fix;
18163 bytes -= fix;
18166 if (narrow_noop)
18168 if (bytes & noop_size)
18170 /* Insert a narrow noop. */
18171 memcpy (p, narrow_noop, noop_size);
18172 p += noop_size;
18173 bytes -= noop_size;
18174 fix += noop_size;
18177 /* Use wide noops for the remainder */
18178 noop_size = 4;
18181 while (bytes >= noop_size)
18183 memcpy (p, noop, noop_size);
18184 p += noop_size;
18185 bytes -= noop_size;
18186 fix += noop_size;
18189 fragP->fr_fix += fix;
18192 /* Called from md_do_align. Used to create an alignment
18193 frag in a code section. */
18195 void
18196 arm_frag_align_code (int n, int max)
18198 char * p;
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."));
18205 p = frag_var (rs_align_code,
18206 MAX_MEM_FOR_RS_ALIGN_CODE,
18208 (relax_substateT) max,
18209 (symbolS *) NULL,
18210 (offsetT) n,
18211 (char *) NULL);
18212 *p = 0;
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. */
18221 void
18222 arm_init_frag (fragS * fragP)
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;
18230 #ifdef OBJ_ELF
18231 /* When we change sections we need to issue a new mapping symbol. */
18233 void
18234 arm_elf_change_section (void)
18236 flagword flags;
18237 segment_info_type *seginfo;
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;
18244 if (!SEG_NORMAL (now_seg))
18245 return;
18247 flags = bfd_get_section_flags (stdoutput, now_seg);
18249 /* We can ignore sections that only contain debug info. */
18250 if ((flags & SEC_ALLOC) == 0)
18251 return;
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;
18259 arm_elf_section_type (const char * str, size_t len)
18261 if (len == 5 && strncmp (str, "exidx", 5) == 0)
18262 return SHT_ARM_EXIDX;
18264 return -1;
18267 /* Code to deal with unwinding tables. */
18269 static void add_unwind_adjustsp (offsetT);
18271 /* Generate any deferred unwind frame offset. */
18273 static void
18274 flush_pending_unwind (void)
18276 offsetT offset;
18278 offset = unwind.pending_offset;
18279 unwind.pending_offset = 0;
18280 if (offset != 0)
18281 add_unwind_adjustsp (offset);
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. */
18288 static void
18289 add_unwind_opcode (valueT op, int length)
18291 /* Add any deferred stack adjustment. */
18292 if (unwind.pending_offset)
18293 flush_pending_unwind ();
18295 unwind.sp_restored = 0;
18297 if (unwind.opcode_count + length > unwind.opcode_alloc)
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);
18306 while (length > 0)
18308 length--;
18309 unwind.opcodes[unwind.opcode_count] = op & 0xff;
18310 op >>= 8;
18311 unwind.opcode_count++;
18315 /* Add unwind opcodes to adjust the stack pointer. */
18317 static void
18318 add_unwind_adjustsp (offsetT offset)
18320 valueT op;
18322 if (offset > 0x200)
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;
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);
18336 /* Calculate the uleb128 encoding of the offset. */
18337 n = 0;
18338 while (o)
18340 bytes[n] = o & 0x7f;
18341 o >>= 7;
18342 if (o)
18343 bytes[n] |= 0x80;
18344 n++;
18346 /* Add the insn. */
18347 for (; n; n--)
18348 add_unwind_opcode (bytes[n - 1], 1);
18349 add_unwind_opcode (0xb2, 1);
18351 else if (offset > 0x100)
18353 /* Two short opcodes. */
18354 add_unwind_opcode (0x3f, 1);
18355 op = (offset - 0x104) >> 2;
18356 add_unwind_opcode (op, 1);
18358 else if (offset > 0)
18360 /* Short opcode. */
18361 op = (offset - 4) >> 2;
18362 add_unwind_opcode (op, 1);
18364 else if (offset < 0)
18366 offset = -offset;
18367 while (offset > 0x100)
18369 add_unwind_opcode (0x7f, 1);
18370 offset -= 0x100;
18372 op = ((offset - 4) >> 2) | 0x40;
18373 add_unwind_opcode (op, 1);
18377 /* Finish the list of unwind opcodes for this function. */
18378 static void
18379 finish_unwind_opcodes (void)
18381 valueT op;
18383 if (unwind.fp_used)
18385 /* Adjust sp as necessary. */
18386 unwind.pending_offset += unwind.fp_offset - unwind.frame_size;
18387 flush_pending_unwind ();
18389 /* After restoring sp from the frame pointer. */
18390 op = 0x90 | unwind.fp_reg;
18391 add_unwind_opcode (op, 1);
18393 else
18394 flush_pending_unwind ();
18398 /* Start an exception table entry. If idx is nonzero this is an index table
18399 entry. */
18401 static void
18402 start_unwind_section (const segT text_seg, int idx)
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;
18416 if (idx)
18418 prefix = ELF_STRING_ARM_unwind;
18419 prefix_once = ELF_STRING_ARM_unwind_once;
18420 type = SHT_ARM_EXIDX;
18422 else
18424 prefix = ELF_STRING_ARM_unwind_info;
18425 prefix_once = ELF_STRING_ARM_unwind_info_once;
18426 type = SHT_PROGBITS;
18429 text_name = segment_name (text_seg);
18430 if (streq (text_name, ".text"))
18431 text_name = "";
18433 if (strncmp (text_name, ".gnu.linkonce.t.",
18434 strlen (".gnu.linkonce.t.")) == 0)
18436 prefix = prefix_once;
18437 text_name += strlen (".gnu.linkonce.t.");
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';
18448 flags = SHF_ALLOC;
18449 linkonce = 0;
18450 group_name = 0;
18452 /* Handle COMDAT group. */
18453 if (prefix != prefix_once && (text_seg->flags & SEC_LINK_ONCE) != 0)
18455 group_name = elf_group_name (text_seg);
18456 if (group_name == NULL)
18458 as_bad (_("Group section `%s' has no group signature"),
18459 segment_name (text_seg));
18460 ignore_rest_of_line ();
18461 return;
18463 flags |= SHF_GROUP;
18464 linkonce = 1;
18467 obj_elf_change_section (sec_name, type, flags, 0, group_name, linkonce, 0);
18469 /* Set the section link for index tables. */
18470 if (idx)
18471 elf_linked_to_section (now_seg) = text_seg;
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. */
18479 static valueT
18480 create_unwind_entry (int have_data)
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;
18490 finish_unwind_opcodes ();
18492 /* Remember the current text section. */
18493 unwind.saved_seg = now_seg;
18494 unwind.saved_subseg = now_subseg;
18496 start_unwind_section (now_seg, 0);
18498 if (unwind.personality_routine == NULL)
18500 if (unwind.personality_index == -2)
18502 if (have_data)
18503 as_bad (_("handlerdata in cantunwind frame"));
18504 return 1; /* EXIDX_CANTUNWIND. */
18507 /* Use a default personality routine if none is specified. */
18508 if (unwind.personality_index == -1)
18510 if (unwind.opcode_count > 3)
18511 unwind.personality_index = 1;
18512 else
18513 unwind.personality_index = 0;
18516 /* Space for the personality routine entry. */
18517 if (unwind.personality_index == 0)
18519 if (unwind.opcode_count > 3)
18520 as_bad (_("too many unwind opcodes for personality routine 0"));
18522 if (!have_data)
18524 /* All the data is inline in the index table. */
18525 data = 0x80;
18526 n = 3;
18527 while (unwind.opcode_count > 0)
18529 unwind.opcode_count--;
18530 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18531 n--;
18534 /* Pad with "finish" opcodes. */
18535 while (n--)
18536 data = (data << 8) | 0xb0;
18538 return data;
18540 size = 0;
18542 else
18543 /* We get two opcodes "free" in the first word. */
18544 size = unwind.opcode_count - 2;
18546 else
18547 /* An extra byte is required for the opcode count. */
18548 size = unwind.opcode_count + 1;
18550 size = (size + 3) >> 2;
18551 if (size > 0xff)
18552 as_bad (_("too many unwind opcodes"));
18554 frag_align (2, 0, 0);
18555 record_alignment (now_seg, 2);
18556 unwind.table_entry = expr_build_dot ();
18558 /* Allocate the table entry. */
18559 ptr = frag_more ((size << 2) + 4);
18560 where = frag_now_fix () - ((size << 2) + 4);
18562 switch (unwind.personality_index)
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);
18570 where += 4;
18571 ptr += 4;
18573 /* Set the first byte to the number of additional words. */
18574 data = size - 1;
18575 n = 3;
18576 break;
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;
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;
18592 default:
18593 /* Should never happen. */
18594 abort ();
18597 /* Pack the opcodes into words (MSB first), reversing the list at the same
18598 time. */
18599 while (unwind.opcode_count > 0)
18601 if (n == 0)
18603 md_number_to_chars (ptr, data, 4);
18604 ptr += 4;
18605 n = 4;
18606 data = 0;
18608 unwind.opcode_count--;
18609 n--;
18610 data = (data << 8) | unwind.opcodes[unwind.opcode_count];
18613 /* Finish off the last word. */
18614 if (n < 4)
18616 /* Pad with "finish" opcodes. */
18617 while (n--)
18618 data = (data << 8) | 0xb0;
18620 md_number_to_chars (ptr, data, 4);
18623 if (!have_data)
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);
18630 return 0;
18634 /* Initialize the DWARF-2 unwind information for this procedure. */
18636 void
18637 tc_arm_frame_initial_instructions (void)
18639 cfi_add_CFA_def_cfa (REG_SP, 0);
18641 #endif /* OBJ_ELF */
18643 /* Convert REGNAME to a DWARF-2 register number. */
18646 tc_arm_regname_to_dw2regnum (char *regname)
18648 int reg = arm_reg_parse (&regname, REG_TYPE_RN);
18650 if (reg == FAIL)
18651 return -1;
18653 return reg;
18656 #ifdef TE_PE
18657 void
18658 tc_pe_dwarf2_emit_offset (symbolS *symbol, unsigned int size)
18660 expressionS expr;
18662 expr.X_op = O_secrel;
18663 expr.X_add_symbol = symbol;
18664 expr.X_add_number = 0;
18665 emit_expr (&expr, size);
18667 #endif
18669 /* MD interface: Symbol and relocation handling. */
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. */
18677 long
18678 md_pcrel_from_section (fixS * fixP, segT seg)
18680 offsetT base = fixP->fx_where + fixP->fx_frag->fr_address;
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
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. */
18687 if (fixP->fx_pcrel
18688 && ((fixP->fx_addsy && S_GET_SEGMENT (fixP->fx_addsy) != seg)
18689 || (arm_force_relocation (fixP)
18690 #ifdef TE_WINCE
18691 && !S_IS_EXTERNAL (fixP->fx_addsy)
18692 #endif
18694 base = 0;
18697 switch (fixP->fx_r_type)
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. */
18704 case BFD_RELOC_ARM_THUMB_ADD:
18705 return base & ~3;
18707 case BFD_RELOC_ARM_THUMB_OFFSET:
18708 case BFD_RELOC_ARM_T32_OFFSET_IMM:
18709 case BFD_RELOC_ARM_T32_ADD_PC12:
18710 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
18711 return (base + 4) & ~3;
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:
18718 case BFD_RELOC_THUMB_PCREL_BRANCH25:
18719 return base + 4;
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;
18728 /* BLX is like branches above, but forces the low two bits of PC to
18729 zero. */
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;
18735 return (base + 4) & ~3;
18737 /* ARM mode branches are offset by +8. However, the Windows CE
18738 loader expects the relocation not to take this into account. */
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;
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;
18753 case BFD_RELOC_ARM_PCREL_BRANCH:
18754 case BFD_RELOC_ARM_PCREL_JUMP:
18755 case BFD_RELOC_ARM_PLT32:
18756 #ifdef TE_WINCE
18757 /* When handling fixups immediately, because we have already
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;
18768 return base;
18769 #else
18770 return base + 8;
18771 #endif
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;
18785 /* Other PC-relative relocations are un-offset. */
18786 default:
18787 return base;
18791 /* Under ELF we need to default _GLOBAL_OFFSET_TABLE.
18792 Otherwise we have no need to default values of symbols. */
18794 symbolS *
18795 md_undefined_symbol (char * name ATTRIBUTE_UNUSED)
18797 #ifdef OBJ_ELF
18798 if (name[0] == '_' && name[1] == 'G'
18799 && streq (name, GLOBAL_OFFSET_TABLE_NAME))
18801 if (!GOT_symbol)
18803 if (symbol_find (name))
18804 as_bad (_("GOT already in the symbol table"));
18806 GOT_symbol = symbol_new (name, undefined_section,
18807 (valueT) 0, & zero_address_frag);
18810 return GOT_symbol;
18812 #endif
18814 return 0;
18817 /* Subroutine of md_apply_fix. Check to see if an immediate can be
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. */
18822 static unsigned int
18823 validate_immediate_twopart (unsigned int val,
18824 unsigned int * highpart)
18826 unsigned int a;
18827 unsigned int i;
18829 for (i = 0; i < 32; i += 2)
18830 if (((a = rotate_left (val, i)) & 0xff) != 0)
18832 if (a & 0xff00)
18834 if (a & ~ 0xffff)
18835 continue;
18836 * highpart = (a >> 8) | ((i + 24) << 7);
18838 else if (a & 0xff0000)
18840 if (a & 0xff000000)
18841 continue;
18842 * highpart = (a >> 16) | ((i + 16) << 7);
18844 else
18846 gas_assert (a & 0xff000000);
18847 * highpart = (a >> 24) | ((i + 8) << 7);
18850 return (a & 0xff) | (i << 7);
18853 return FAIL;
18856 static int
18857 validate_offset_imm (unsigned int val, int hwse)
18859 if ((hwse && val > 255) || val > 4095)
18860 return FAIL;
18861 return val;
18864 /* Subroutine of md_apply_fix. Do those data_ops which can take a
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. */
18875 static int
18876 negate_data_op (unsigned long * instruction,
18877 unsigned long value)
18879 int op, new_inst;
18880 unsigned long negated, inverted;
18882 negated = encode_arm_immediate (-value);
18883 inverted = encode_arm_immediate (~value);
18885 op = (*instruction >> DATA_OP_SHIFT) & 0xf;
18886 switch (op)
18888 /* First negates. */
18889 case OPCODE_SUB: /* ADD <-> SUB */
18890 new_inst = OPCODE_ADD;
18891 value = negated;
18892 break;
18894 case OPCODE_ADD:
18895 new_inst = OPCODE_SUB;
18896 value = negated;
18897 break;
18899 case OPCODE_CMP: /* CMP <-> CMN */
18900 new_inst = OPCODE_CMN;
18901 value = negated;
18902 break;
18904 case OPCODE_CMN:
18905 new_inst = OPCODE_CMP;
18906 value = negated;
18907 break;
18909 /* Now Inverted ops. */
18910 case OPCODE_MOV: /* MOV <-> MVN */
18911 new_inst = OPCODE_MVN;
18912 value = inverted;
18913 break;
18915 case OPCODE_MVN:
18916 new_inst = OPCODE_MOV;
18917 value = inverted;
18918 break;
18920 case OPCODE_AND: /* AND <-> BIC */
18921 new_inst = OPCODE_BIC;
18922 value = inverted;
18923 break;
18925 case OPCODE_BIC:
18926 new_inst = OPCODE_AND;
18927 value = inverted;
18928 break;
18930 case OPCODE_ADC: /* ADC <-> SBC */
18931 new_inst = OPCODE_SBC;
18932 value = inverted;
18933 break;
18935 case OPCODE_SBC:
18936 new_inst = OPCODE_ADC;
18937 value = inverted;
18938 break;
18940 /* We cannot do anything. */
18941 default:
18942 return FAIL;
18945 if (value == (unsigned) FAIL)
18946 return FAIL;
18948 *instruction &= OPCODE_MASK;
18949 *instruction |= new_inst << DATA_OP_SHIFT;
18950 return value;
18953 /* Like negate_data_op, but for Thumb-2. */
18955 static unsigned int
18956 thumb32_negate_data_op (offsetT *instruction, unsigned int value)
18958 int op, new_inst;
18959 int rd;
18960 unsigned int negated, inverted;
18962 negated = encode_thumb32_immediate (-value);
18963 inverted = encode_thumb32_immediate (~value);
18965 rd = (*instruction >> 8) & 0xf;
18966 op = (*instruction >> T2_DATA_OP_SHIFT) & 0xf;
18967 switch (op)
18969 /* ADD <-> SUB. Includes CMP <-> CMN. */
18970 case T2_OPCODE_SUB:
18971 new_inst = T2_OPCODE_ADD;
18972 value = negated;
18973 break;
18975 case T2_OPCODE_ADD:
18976 new_inst = T2_OPCODE_SUB;
18977 value = negated;
18978 break;
18980 /* ORR <-> ORN. Includes MOV <-> MVN. */
18981 case T2_OPCODE_ORR:
18982 new_inst = T2_OPCODE_ORN;
18983 value = inverted;
18984 break;
18986 case T2_OPCODE_ORN:
18987 new_inst = T2_OPCODE_ORR;
18988 value = inverted;
18989 break;
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;
19000 case T2_OPCODE_BIC:
19001 new_inst = T2_OPCODE_AND;
19002 value = inverted;
19003 break;
19005 /* ADC <-> SBC */
19006 case T2_OPCODE_ADC:
19007 new_inst = T2_OPCODE_SBC;
19008 value = inverted;
19009 break;
19011 case T2_OPCODE_SBC:
19012 new_inst = T2_OPCODE_ADC;
19013 value = inverted;
19014 break;
19016 /* We cannot do anything. */
19017 default:
19018 return FAIL;
19021 if (value == (unsigned int)FAIL)
19022 return FAIL;
19024 *instruction &= T2_OPCODE_MASK;
19025 *instruction |= new_inst << T2_DATA_OP_SHIFT;
19026 return value;
19029 /* Read a 32-bit thumb instruction from buf. */
19030 static unsigned long
19031 get_thumb32_insn (char * buf)
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);
19037 return insn;
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. */
19047 arm_optimize_expr (expressionS *l, operatorT op, expressionS *r)
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))
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;
19059 /* Process as normal. */
19060 return 0;
19063 void
19064 md_apply_fix (fixS * fixP,
19065 valueT * valP,
19066 segT seg)
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;
19075 gas_assert (fixP->fx_r_type <= BFD_RELOC_UNUSED);
19077 /* Note whether this will delete the relocation. */
19079 if (fixP->fx_addsy == 0 && !fixP->fx_pcrel)
19080 fixP->fx_done = 1;
19082 /* On a 64-bit host, silently truncate 'value' to 32 bits for
19083 consistency with the behaviour on 32-bit hosts. Remember value
19084 for emit_reloc. */
19085 value &= 0xffffffff;
19086 value ^= 0x80000000;
19087 value -= 0x80000000;
19089 *valP = value;
19090 fixP->fx_addnumber = value;
19092 /* Same treatment for fixP->fx_offset. */
19093 fixP->fx_offset &= 0xffffffff;
19094 fixP->fx_offset ^= 0x80000000;
19095 fixP->fx_offset -= 0x80000000;
19097 switch (fixP->fx_r_type)
19099 case BFD_RELOC_NONE:
19100 /* This will need to go in the object file. */
19101 fixP->fx_done = 0;
19102 break;
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;
19110 if (fixP->fx_addsy
19111 && ! S_IS_DEFINED (fixP->fx_addsy))
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;
19119 if (fixP->fx_addsy
19120 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
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;
19128 newimm = encode_arm_immediate (value);
19129 temp = md_chars_to_number (buf, INSN_SIZE);
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)
19136 as_bad_where (fixP->fx_file, fixP->fx_line,
19137 _("invalid constant (%lx) after fixup"),
19138 (unsigned long) value);
19139 break;
19142 newimm |= (temp & 0xfffff000);
19143 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19144 break;
19146 case BFD_RELOC_ARM_ADRL_IMMEDIATE:
19148 unsigned int highpart = 0;
19149 unsigned int newinsn = 0xe1a00000; /* nop. */
19151 if (fixP->fx_addsy
19152 && ! S_IS_DEFINED (fixP->fx_addsy))
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;
19160 if (fixP->fx_addsy
19161 && S_GET_SEGMENT (fixP->fx_addsy) != seg)
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;
19169 newimm = encode_arm_immediate (value);
19170 temp = md_chars_to_number (buf, INSN_SIZE);
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)
19177 /* No ? OK - try using two ADD instructions to generate
19178 the value. */
19179 newimm = validate_immediate_twopart (value, & highpart);
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
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;
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);
19205 newimm |= (temp & 0xfffff000);
19206 md_number_to_chars (buf, (valueT) newimm, INSN_SIZE);
19208 highpart |= (newinsn & 0xfffff000);
19209 md_number_to_chars (buf + INSN_SIZE, (valueT) highpart, INSN_SIZE);
19211 break;
19213 case BFD_RELOC_ARM_OFFSET_IMM:
19214 if (!fixP->fx_done && seg->use_rela_p)
19215 value = 0;
19217 case BFD_RELOC_ARM_LITERAL:
19218 sign = value >= 0;
19220 if (value < 0)
19221 value = - value;
19223 if (validate_offset_imm (value, 0) == FAIL)
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;
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;
19241 case BFD_RELOC_ARM_OFFSET_IMM8:
19242 case BFD_RELOC_ARM_HWLITERAL:
19243 sign = value >= 0;
19245 if (value < 0)
19246 value = - value;
19248 if (validate_offset_imm (value, 1) == FAIL)
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
19254 as_bad (_("bad immediate value for 8-bit offset (%ld)"),
19255 (long) value);
19256 break;
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;
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;
19271 newval = md_chars_to_number (buf+2, THUMB_SIZE);
19272 newval |= value;
19273 md_number_to_chars (buf+2, newval, THUMB_SIZE);
19274 break;
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:
19280 1110 100P u1WL NNNN XXXX YYYY iiii iiii - +/-(U) pre/post(P) 8-bit,
19281 *4, optional writeback(W)
19282 (doubleword load/store)
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
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);
19299 if ((newval & 0xf0000000) == 0xe0000000)
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)
19308 as_bad_where (fixP->fx_file, fixP->fx_line,
19309 _("offset not a multiple of 4"));
19310 break;
19312 value /= 4;
19313 if (value > 0xff)
19315 as_bad_where (fixP->fx_file, fixP->fx_line,
19316 _("offset out of range"));
19317 break;
19319 newval &= ~0xff;
19321 else if ((newval & 0x000f0000) == 0x000f0000)
19323 /* PC-relative, 12-bit offset. */
19324 if (value >= 0)
19325 newval |= (1 << 23);
19326 else
19327 value = -value;
19328 if (value > 0xfff)
19330 as_bad_where (fixP->fx_file, fixP->fx_line,
19331 _("offset out of range"));
19332 break;
19334 newval &= ~0xfff;
19336 else if ((newval & 0x00000100) == 0x00000100)
19338 /* Writeback: 8-bit, +/- offset. */
19339 if (value >= 0)
19340 newval |= (1 << 9);
19341 else
19342 value = -value;
19343 if (value > 0xff)
19345 as_bad_where (fixP->fx_file, fixP->fx_line,
19346 _("offset out of range"));
19347 break;
19349 newval &= ~0xff;
19351 else if ((newval & 0x00000f00) == 0x00000e00)
19353 /* T-instruction: positive 8-bit offset. */
19354 if (value < 0 || value > 0xff)
19356 as_bad_where (fixP->fx_file, fixP->fx_line,
19357 _("offset out of range"));
19358 break;
19360 newval &= ~0xff;
19361 newval |= value;
19363 else
19365 /* Positive 12-bit or negative 8-bit offset. */
19366 int limit;
19367 if (value >= 0)
19369 newval |= (1 << 23);
19370 limit = 0xfff;
19372 else
19374 value = -value;
19375 limit = 0xff;
19377 if (value > limit)
19379 as_bad_where (fixP->fx_file, fixP->fx_line,
19380 _("offset out of range"));
19381 break;
19383 newval &= ~limit;
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;
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)))
19397 as_bad_where (fixP->fx_file, fixP->fx_line,
19398 _("shift expression is too large"));
19399 break;
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;
19412 case BFD_RELOC_ARM_T32_IMMEDIATE:
19413 case BFD_RELOC_ARM_T32_ADD_IMM:
19414 case BFD_RELOC_ARM_T32_IMM12:
19415 case BFD_RELOC_ARM_T32_ADD_PC12:
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;
19421 if (fixP->fx_addsy
19422 && ! S_IS_DEFINED (fixP->fx_addsy))
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;
19430 newval = md_chars_to_number (buf, THUMB_SIZE);
19431 newval <<= 16;
19432 newval |= md_chars_to_number (buf+2, THUMB_SIZE);
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)
19438 newimm = encode_thumb32_immediate (value);
19439 if (newimm == (unsigned int) FAIL)
19440 newimm = thumb32_negate_data_op (&newval, value);
19442 if (fixP->fx_r_type != BFD_RELOC_ARM_T32_IMMEDIATE
19443 && newimm == (unsigned int) FAIL)
19445 /* Turn add/sum into addw/subw. */
19446 if (fixP->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM)
19447 newval = (newval & 0xfeffffff) | 0x02000000;
19449 /* 12 bit immediate for addw/subw. */
19450 if (value < 0)
19452 value = -value;
19453 newval ^= 0x00a00000;
19455 if (value > 0xfff)
19456 newimm = (unsigned int) FAIL;
19457 else
19458 newimm = value;
19461 if (newimm == (unsigned int)FAIL)
19463 as_bad_where (fixP->fx_file, fixP->fx_line,
19464 _("invalid constant (%lx) after fixup"),
19465 (unsigned long) value);
19466 break;
19469 newval |= (newimm & 0x800) << 15;
19470 newval |= (newimm & 0x700) << 4;
19471 newval |= (newimm & 0x0ff);
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;
19477 case BFD_RELOC_ARM_SMC:
19478 if (((unsigned long) value) > 0xffff)
19479 as_bad_where (fixP->fx_file, fixP->fx_line,
19480 _("invalid smc expression"));
19481 newval = md_chars_to_number (buf, INSN_SIZE);
19482 newval |= (value & 0xf) | ((value & 0xfff0) << 4);
19483 md_number_to_chars (buf, newval, INSN_SIZE);
19484 break;
19486 case BFD_RELOC_ARM_SWI:
19487 if (fixP->tc_fix_data != 0)
19489 if (((unsigned long) value) > 0xff)
19490 as_bad_where (fixP->fx_file, fixP->fx_line,
19491 _("invalid swi expression"));
19492 newval = md_chars_to_number (buf, THUMB_SIZE);
19493 newval |= value;
19494 md_number_to_chars (buf, newval, THUMB_SIZE);
19496 else
19498 if (((unsigned long) value) > 0x00ffffff)
19499 as_bad_where (fixP->fx_file, fixP->fx_line,
19500 _("invalid swi expression"));
19501 newval = md_chars_to_number (buf, INSN_SIZE);
19502 newval |= value;
19503 md_number_to_chars (buf, newval, INSN_SIZE);
19505 break;
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;
19515 #ifdef OBJ_ELF
19516 case BFD_RELOC_ARM_PCREL_CALL:
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. */
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;
19533 else
19534 temp = 3;
19535 goto arm_branch_common;
19537 case BFD_RELOC_ARM_PCREL_JUMP:
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))
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;
19552 case BFD_RELOC_ARM_PLT32:
19553 #endif
19554 case BFD_RELOC_ARM_PCREL_BRANCH:
19555 temp = 3;
19556 goto arm_branch_common;
19558 case BFD_RELOC_ARM_PCREL_BLX:
19560 temp = 1;
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))
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;
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
19583 arm_branch_common:
19584 /* We are going to store value (shifted right by two) in the
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)
19589 as_bad_where (fixP->fx_file, fixP->fx_line,
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"));
19596 if (fixP->fx_done || !seg->use_rela_p)
19598 newval = md_chars_to_number (buf, INSN_SIZE);
19599 newval |= (value >> 2) & 0x00ffffff;
19600 /* Set the H bit on BLX instructions. */
19601 if (temp == 1)
19603 if (value & 2)
19604 newval |= 0x01000000;
19605 else
19606 newval &= ~0x01000000;
19608 md_number_to_chars (buf, newval, INSN_SIZE);
19610 break;
19612 case BFD_RELOC_THUMB_PCREL_BRANCH7: /* CBZ */
19613 /* CBZ can only branch forward. */
19615 /* Attempts to use CBZ to branch to the next instruction
19616 (which, strictly speaking, are prohibited) will be turned into
19617 no-ops.
19619 FIXME: It may be better to remove the instruction completely and
19620 perform relaxation. */
19621 if (value == -2)
19623 newval = md_chars_to_number (buf, THUMB_SIZE);
19624 newval = 0xbf00; /* NOP encoding T1 */
19625 md_number_to_chars (buf, newval, THUMB_SIZE);
19627 else
19629 if (value & ~0x7e)
19630 as_bad_where (fixP->fx_file, fixP->fx_line,
19631 _("branch out of range"));
19633 if (fixP->fx_done || !seg->use_rela_p)
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);
19640 break;
19642 case BFD_RELOC_THUMB_PCREL_BRANCH9: /* Conditional branch. */
19643 if ((value & ~0xff) && ((value & ~0xff) != ~0xff))
19644 as_bad_where (fixP->fx_file, fixP->fx_line,
19645 _("branch out of range"));
19647 if (fixP->fx_done || !seg->use_rela_p)
19649 newval = md_chars_to_number (buf, THUMB_SIZE);
19650 newval |= (value & 0x1ff) >> 1;
19651 md_number_to_chars (buf, newval, THUMB_SIZE);
19653 break;
19655 case BFD_RELOC_THUMB_PCREL_BRANCH12: /* Unconditional branch. */
19656 if ((value & ~0x7ff) && ((value & ~0x7ff) != ~0x7ff))
19657 as_bad_where (fixP->fx_file, fixP->fx_line,
19658 _("branch out of range"));
19660 if (fixP->fx_done || !seg->use_rela_p)
19662 newval = md_chars_to_number (buf, THUMB_SIZE);
19663 newval |= (value & 0xfff) >> 1;
19664 md_number_to_chars (buf, newval, THUMB_SIZE);
19666 break;
19668 case BFD_RELOC_THUMB_PCREL_BRANCH20:
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))
19676 /* Force a relocation for a branch 20 bits wide. */
19677 fixP->fx_done = 0;
19679 if ((value & ~0x1fffff) && ((value & ~0x1fffff) != ~0x1fffff))
19680 as_bad_where (fixP->fx_file, fixP->fx_line,
19681 _("conditional branch out of range"));
19683 if (fixP->fx_done || !seg->use_rela_p)
19685 offsetT newval2;
19686 addressT S, J1, J2, lo, hi;
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;
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);
19701 break;
19703 case BFD_RELOC_THUMB_PCREL_BLX:
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. */
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))
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;
19727 goto thumb_bl_common;
19729 case BFD_RELOC_THUMB_PCREL_BRANCH23:
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))
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;
19747 thumb_bl_common:
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
19755 if ((value & ~0x3fffff) && ((value & ~0x3fffff) != ~0x3fffff))
19756 as_bad_where (fixP->fx_file, fixP->fx_line,
19757 _("branch out of range"));
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;
19766 if (fixP->fx_done || !seg->use_rela_p)
19768 offsetT newval2;
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);
19777 break;
19779 case BFD_RELOC_THUMB_PCREL_BRANCH25:
19780 if ((value & ~0x1ffffff) && ((value & ~0x1ffffff) != ~0x1ffffff))
19781 as_bad_where (fixP->fx_file, fixP->fx_line,
19782 _("branch out of range"));
19784 if (fixP->fx_done || !seg->use_rela_p)
19786 offsetT newval2;
19787 addressT S, I1, I2, lo, hi;
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;
19795 I1 = !(I1 ^ S);
19796 I2 = !(I2 ^ S);
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);
19805 break;
19807 case BFD_RELOC_8:
19808 if (fixP->fx_done || !seg->use_rela_p)
19809 md_number_to_chars (buf, value, 1);
19810 break;
19812 case BFD_RELOC_16:
19813 if (fixP->fx_done || !seg->use_rela_p)
19814 md_number_to_chars (buf, value, 2);
19815 break;
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 */
19826 case BFD_RELOC_ARM_GOT32:
19827 case BFD_RELOC_ARM_GOTOFF:
19828 case BFD_RELOC_ARM_TARGET2:
19829 if (fixP->fx_done || !seg->use_rela_p)
19830 md_number_to_chars (buf, 0, 4);
19831 break;
19832 #endif
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:
19840 #ifdef TE_PE
19841 case BFD_RELOC_32_SECREL:
19842 #endif
19843 if (fixP->fx_done || !seg->use_rela_p)
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);
19849 break;
19851 #ifdef OBJ_ELF
19852 case BFD_RELOC_ARM_PREL31:
19853 if (fixP->fx_done || !seg->use_rela_p)
19855 newval = md_chars_to_number (buf, 4) & 0x80000000;
19856 if ((value ^ (value >> 1)) & 0x40000000)
19858 as_bad_where (fixP->fx_file, fixP->fx_line,
19859 _("rel31 relocation overflow"));
19861 newval |= value & 0x7fffffff;
19862 md_number_to_chars (buf, newval, 4);
19864 break;
19865 #endif
19867 case BFD_RELOC_ARM_CP_OFF_IMM:
19868 case BFD_RELOC_ARM_T32_CP_OFF_IMM:
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;
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;
19882 newval |= (value >> 2) | (sign ? INDEX_UP : 0);
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);
19888 break;
19890 case BFD_RELOC_ARM_CP_OFF_IMM_S2:
19891 case BFD_RELOC_ARM_T32_CP_OFF_IMM_S2:
19892 if (value < -255 || value > 255)
19893 as_bad_where (fixP->fx_file, fixP->fx_line,
19894 _("co-processor offset out of range"));
19895 value *= 4;
19896 goto cp_off_common;
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)
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)"),
19912 (((unsigned long) fixP->fx_frag->fr_address
19913 + (unsigned long) fixP->fx_where) & ~3)
19914 + (unsigned long) value);
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);
19921 newval |= value >> 2;
19922 break;
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;
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;
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;
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;
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;
19962 md_number_to_chars (buf, newval, THUMB_SIZE);
19963 break;
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:
19969 3bit ADD/SUB
19970 8bit ADD/SUB
19971 9bit ADD/SUB SP word-aligned
19972 10bit ADD PC/SP word-aligned
19974 The type of instruction being processed is encoded in the
19975 instruction field:
19977 0x8000 SUB
19978 0x00F0 Rd
19979 0x000F Rs
19981 newval = md_chars_to_number (buf, THUMB_SIZE);
19983 int rd = (newval >> 4) & 0xf;
19984 int rs = newval & 0xf;
19985 int subtract = !!(newval & 0x8000);
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"));
19994 /* If value is negative, choose the opposite instruction. */
19995 if (value < 0)
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"));
20004 if (rd == REG_SP)
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;
20012 else if (rs == REG_PC || rs == REG_SP)
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;
20022 else if (rs == rd)
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;
20030 else
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);
20039 md_number_to_chars (buf, newval, THUMB_SIZE);
20040 break;
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,
20046 _("invalid immediate: %ld is out of range"),
20047 (long) value);
20048 newval |= value;
20049 md_number_to_chars (buf, newval, THUMB_SIZE);
20050 break;
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;
20069 case BFD_RELOC_VTABLE_INHERIT:
20070 case BFD_RELOC_VTABLE_ENTRY:
20071 fixP->fx_done = 0;
20072 return;
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)
20080 /* REL format relocations are limited to a 16-bit addend. */
20081 if (!fixP->fx_done)
20083 if (value < -0x8000 || value > 0x7fff)
20084 as_bad_where (fixP->fx_file, fixP->fx_line,
20085 _("offset out of range"));
20087 else if (fixP->fx_r_type == BFD_RELOC_ARM_MOVT
20088 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
20090 value >>= 16;
20093 if (fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVW
20094 || fixP->fx_r_type == BFD_RELOC_ARM_THUMB_MOVT)
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);
20104 else
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);
20113 return;
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:
20125 gas_assert (!fixP->fx_done);
20126 if (!seg->use_rela_p)
20128 bfd_vma insn;
20129 bfd_vma encoded_addend;
20130 bfd_vma addend_abs = abs (value);
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"),
20138 (unsigned long) addend_abs);
20140 /* Extract the instruction. */
20141 insn = md_chars_to_number (buf, INSN_SIZE);
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;
20151 /* Place the encoded addend into the first 12 bits of the
20152 instruction. */
20153 insn &= 0xfffff000;
20154 insn |= encoded_addend;
20156 /* Update the instruction. */
20157 md_number_to_chars (buf, insn, INSN_SIZE);
20159 break;
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:
20167 gas_assert (!fixP->fx_done);
20168 if (!seg->use_rela_p)
20170 bfd_vma insn;
20171 bfd_vma addend_abs = abs (value);
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)"),
20178 (unsigned long) addend_abs);
20180 /* Extract the instruction. */
20181 insn = md_chars_to_number (buf, INSN_SIZE);
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;
20190 /* Place the absolute value of the addend into the first 12 bits
20191 of the instruction. */
20192 insn &= 0xfffff000;
20193 insn |= addend_abs;
20195 /* Update the instruction. */
20196 md_number_to_chars (buf, insn, INSN_SIZE);
20198 break;
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:
20206 gas_assert (!fixP->fx_done);
20207 if (!seg->use_rela_p)
20209 bfd_vma insn;
20210 bfd_vma addend_abs = abs (value);
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)"),
20217 (unsigned long) addend_abs);
20219 /* Extract the instruction. */
20220 insn = md_chars_to_number (buf, INSN_SIZE);
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;
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);
20235 /* Update the instruction. */
20236 md_number_to_chars (buf, insn, INSN_SIZE);
20238 break;
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:
20246 gas_assert (!fixP->fx_done);
20247 if (!seg->use_rela_p)
20249 bfd_vma insn;
20250 bfd_vma addend_abs = abs (value);
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)"),
20257 (unsigned long) addend_abs);
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)"),
20262 (unsigned long) addend_abs);
20264 /* Extract the instruction. */
20265 insn = md_chars_to_number (buf, INSN_SIZE);
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;
20274 /* Place the addend (divided by four) into the first eight
20275 bits of the instruction. */
20276 insn &= 0xfffffff0;
20277 insn |= addend_abs >> 2;
20279 /* Update the instruction. */
20280 md_number_to_chars (buf, insn, INSN_SIZE);
20282 break;
20284 case BFD_RELOC_ARM_V4BX:
20285 /* This will need to go in the object file. */
20286 fixP->fx_done = 0;
20287 break;
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);
20296 /* Translate internal representation of relocation info to BFD target
20297 format. */
20299 arelent *
20300 tc_gen_reloc (asection *section, fixS *fixp)
20302 arelent * reloc;
20303 bfd_reloc_code_real_type code;
20305 reloc = xmalloc (sizeof (arelent));
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;
20311 if (fixp->fx_pcrel)
20313 if (section->use_rela_p)
20314 fixp->fx_offset -= md_pcrel_from_section (fixp, section);
20315 else
20316 fixp->fx_offset = reloc->address;
20318 reloc->addend = fixp->fx_offset;
20320 switch (fixp->fx_r_type)
20322 case BFD_RELOC_8:
20323 if (fixp->fx_pcrel)
20325 code = BFD_RELOC_8_PCREL;
20326 break;
20329 case BFD_RELOC_16:
20330 if (fixp->fx_pcrel)
20332 code = BFD_RELOC_16_PCREL;
20333 break;
20336 case BFD_RELOC_32:
20337 if (fixp->fx_pcrel)
20339 code = BFD_RELOC_32_PCREL;
20340 break;
20343 case BFD_RELOC_ARM_MOVW:
20344 if (fixp->fx_pcrel)
20346 code = BFD_RELOC_ARM_MOVW_PCREL;
20347 break;
20350 case BFD_RELOC_ARM_MOVT:
20351 if (fixp->fx_pcrel)
20353 code = BFD_RELOC_ARM_MOVT_PCREL;
20354 break;
20357 case BFD_RELOC_ARM_THUMB_MOVW:
20358 if (fixp->fx_pcrel)
20360 code = BFD_RELOC_ARM_THUMB_MOVW_PCREL;
20361 break;
20364 case BFD_RELOC_ARM_THUMB_MOVT:
20365 if (fixp->fx_pcrel)
20367 code = BFD_RELOC_ARM_THUMB_MOVT_PCREL;
20368 break;
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:
20381 case BFD_RELOC_VTABLE_ENTRY:
20382 case BFD_RELOC_VTABLE_INHERIT:
20383 #ifdef TE_PE
20384 case BFD_RELOC_32_SECREL:
20385 #endif
20386 code = fixp->fx_r_type;
20387 break;
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;
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;
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:
20417 case BFD_RELOC_ARM_PCREL_CALL:
20418 case BFD_RELOC_ARM_PCREL_JUMP:
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:
20447 case BFD_RELOC_ARM_V4BX:
20448 code = fixp->fx_r_type;
20449 break;
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
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;
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;
20472 case BFD_RELOC_ARM_OFFSET_IMM:
20473 if (section->use_rela_p)
20475 code = fixp->fx_r_type;
20476 break;
20479 if (fixp->fx_addsy != NULL
20480 && !S_IS_DEFINED (fixp->fx_addsy)
20481 && S_IS_LOCAL (fixp->fx_addsy))
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;
20489 as_bad_where (fixp->fx_file, fixp->fx_line,
20490 _("internal_relocation (type: OFFSET_IMM) not fixed up"));
20491 return NULL;
20493 default:
20495 char * type;
20497 switch (fixp->fx_r_type)
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;
20502 case BFD_RELOC_ARM_SMC: type = "SMC"; break;
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;
20506 case BFD_RELOC_ARM_T32_CP_OFF_IMM: type = "T32_CP_OFF_IMM"; break;
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;
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;
20520 #ifdef OBJ_ELF
20521 if ((code == BFD_RELOC_32_PCREL || code == BFD_RELOC_32)
20522 && GOT_symbol
20523 && fixp->fx_addsy == GOT_symbol)
20525 code = BFD_RELOC_ARM_GOTPC;
20526 reloc->addend = fixp->fx_offset = reloc->address;
20528 #endif
20530 reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
20532 if (reloc->howto == NULL)
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;
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;
20545 return reloc;
20548 /* This fix_new is called by cons via TC_CONS_FIX_NEW. */
20550 void
20551 cons_fix_new_arm (fragS * frag,
20552 int where,
20553 int size,
20554 expressionS * exp)
20556 bfd_reloc_code_real_type type;
20557 int pcrel = 0;
20559 /* Pick a reloc.
20560 FIXME: @@ Should look at CPU word size. */
20561 switch (size)
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;
20578 #ifdef TE_PE
20579 if (exp->X_op == O_secrel)
20581 exp->X_op = O_symbol;
20582 type = BFD_RELOC_32_SECREL;
20584 #endif
20586 fix_new_exp (frag, where, (int) size, exp, pcrel, type);
20589 #if defined (OBJ_COFF)
20590 void
20591 arm_validate_fix (fixS * fixP)
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))
20602 fixP->fx_addsy = find_real_start (fixP->fx_addsy);
20605 #endif
20609 arm_force_relocation (struct fix * fixp)
20611 #if defined (OBJ_COFF) && defined (TE_PE)
20612 if (fixp->fx_r_type == BFD_RELOC_RVA)
20613 return 1;
20614 #endif
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. */
20621 #ifdef OBJ_ELF
20622 switch (fixp->fx_r_type)
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;
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;
20639 default:
20640 break;
20642 #endif
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
20647 || fixp->fx_r_type == BFD_RELOC_ARM_ADRL_IMMEDIATE
20648 || fixp->fx_r_type == BFD_RELOC_ARM_T32_ADD_IMM
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)
20652 return 0;
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;
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;
20666 return generic_force_reloc (fixp);
20669 #if defined (OBJ_ELF) || defined (OBJ_COFF)
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
20673 also prevents relocations that are mips-16 specific, but I do not
20674 know why it does this.
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. */
20683 bfd_boolean
20684 arm_fix_adjustable (fixS * fixP)
20686 if (fixP->fx_addsy == NULL)
20687 return 1;
20689 /* Preserve relocations against symbols with function type. */
20690 if (symbol_get_bfdsym (fixP->fx_addsy)->flags & BSF_FUNCTION)
20691 return 0;
20693 if (THUMB_IS_FUNC (fixP->fx_addsy)
20694 && fixP->fx_subsy == NULL)
20695 return 0;
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;
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;
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;
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;
20731 return 1;
20733 #endif /* defined (OBJ_ELF) || defined (OBJ_COFF) */
20735 #ifdef OBJ_ELF
20737 const char *
20738 elf32_arm_target_format (void)
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
20756 void
20757 armelf_frob_symbol (symbolS * symp,
20758 int * puntp)
20760 elf_frob_symbol (symp, puntp);
20762 #endif
20764 /* MD interface: Finalization. */
20766 void
20767 arm_cleanup (void)
20769 literal_pool * pool;
20771 /* Ensure that all the IT blocks are properly closed. */
20772 check_it_blocks_finished ();
20774 for (pool = list_of_pools; pool; pool = pool->next)
20776 /* Put it at the end of the relevant section. */
20777 subseg_set (pool->section, pool->sub_section);
20778 #ifdef OBJ_ELF
20779 arm_elf_change_section ();
20780 #endif
20781 s_ltorg (0);
20785 /* Adjust the symbol table. This marks Thumb symbols as distinct from
20786 ARM ones. */
20788 void
20789 arm_adjust_symtab (void)
20791 #ifdef OBJ_COFF
20792 symbolS * sym;
20794 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20796 if (ARM_IS_THUMB (sym))
20798 if (THUMB_IS_FUNC (sym))
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);
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));
20811 else switch (S_GET_STORAGE_CLASS (sym))
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;
20828 if (ARM_IS_INTERWORK (sym))
20829 coffsymbol (symbol_get_bfdsym (sym))->native->u.syment.n_flags = 0xFF;
20831 #endif
20832 #ifdef OBJ_ELF
20833 symbolS * sym;
20834 char bind;
20836 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
20838 if (ARM_IS_THUMB (sym))
20840 elf_symbol_type * elf_sym;
20842 elf_sym = elf_symbol (symbol_get_bfdsym (sym));
20843 bind = ELF_ST_BIND (elf_sym->internal_elf_sym.st_info);
20845 if (! bfd_is_arm_special_symbol_name (elf_sym->symbol.name,
20846 BFD_ARM_SPECIAL_SYM_TYPE_ANY))
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);
20853 else if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
20854 elf_sym->internal_elf_sym.st_info =
20855 ELF_ST_INFO (bind, STT_ARM_16BIT);
20859 #endif
20862 /* MD interface: Initialization. */
20864 static void
20865 set_constant_flonums (void)
20867 int i;
20869 for (i = 0; i < NUM_FLOAT_VALS; i++)
20870 if (atof_ieee ((char *) fp_const[i], 'x', fp_values[i]) == NULL)
20871 abort ();
20874 /* Auto-select Thumb mode if it's the only available instruction set for the
20875 given architecture. */
20877 static void
20878 autoselect_thumb_from_cpu_variant (void)
20880 if (!ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v1))
20881 opcode_select (16);
20884 void
20885 md_begin (void)
20887 unsigned mach;
20888 unsigned int i;
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
20894 || (arm_v7m_psr_hsh = hash_new ()) == NULL
20895 || (arm_reg_hsh = hash_new ()) == NULL
20896 || (arm_reloc_hsh = hash_new ()) == NULL
20897 || (arm_barrier_opt_hsh = hash_new ()) == NULL)
20898 as_fatal (_("virtual memory exhausted"));
20900 for (i = 0; i < sizeof (insns) / sizeof (struct asm_opcode); i++)
20901 hash_insert (arm_ops_hsh, insns[i].template, (void *) (insns + i));
20902 for (i = 0; i < sizeof (conds) / sizeof (struct asm_cond); i++)
20903 hash_insert (arm_cond_hsh, conds[i].template, (void *) (conds + i));
20904 for (i = 0; i < sizeof (shift_names) / sizeof (struct asm_shift_name); i++)
20905 hash_insert (arm_shift_hsh, shift_names[i].name, (void *) (shift_names + i));
20906 for (i = 0; i < sizeof (psrs) / sizeof (struct asm_psr); i++)
20907 hash_insert (arm_psr_hsh, psrs[i].template, (void *) (psrs + i));
20908 for (i = 0; i < sizeof (v7m_psrs) / sizeof (struct asm_psr); i++)
20909 hash_insert (arm_v7m_psr_hsh, v7m_psrs[i].template, (void *) (v7m_psrs + i));
20910 for (i = 0; i < sizeof (reg_names) / sizeof (struct reg_entry); i++)
20911 hash_insert (arm_reg_hsh, reg_names[i].name, (void *) (reg_names + i));
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,
20916 (void *) (barrier_opt_names + i));
20917 #ifdef OBJ_ELF
20918 for (i = 0; i < sizeof (reloc_names) / sizeof (struct reloc_entry); i++)
20919 hash_insert (arm_reloc_hsh, reloc_names[i].name, (void *) (reloc_names + i));
20920 #endif
20922 set_constant_flonums ();
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. */
20928 if (legacy_cpu)
20930 if (mcpu_cpu_opt || march_cpu_opt)
20931 as_bad (_("use of old and new-style options to set CPU type"));
20933 mcpu_cpu_opt = legacy_cpu;
20935 else if (!mcpu_cpu_opt)
20936 mcpu_cpu_opt = march_cpu_opt;
20938 if (legacy_fpu)
20940 if (mfpu_opt)
20941 as_bad (_("use of old and new-style options to set FPU type"));
20943 mfpu_opt = legacy_fpu;
20945 else if (!mfpu_opt)
20947 #if !(defined (EABI_DEFAULT) || defined (TE_LINUX) \
20948 || defined (TE_NetBSD) || defined (TE_VXWORKS))
20949 /* Some environments specify a default FPU. If they don't, infer it
20950 from the processor. */
20951 if (mcpu_fpu_opt)
20952 mfpu_opt = mcpu_fpu_opt;
20953 else
20954 mfpu_opt = march_fpu_opt;
20955 #else
20956 mfpu_opt = &fpu_default;
20957 #endif
20960 if (!mfpu_opt)
20962 if (mcpu_cpu_opt != NULL)
20963 mfpu_opt = &fpu_default;
20964 else if (mcpu_fpu_opt != NULL && ARM_CPU_HAS_FEATURE (*mcpu_fpu_opt, arm_ext_v5))
20965 mfpu_opt = &fpu_arch_vfp_v2;
20966 else
20967 mfpu_opt = &fpu_arch_fpa;
20970 #ifdef CPU_DEFAULT
20971 if (!mcpu_cpu_opt)
20973 mcpu_cpu_opt = &cpu_default;
20974 selected_cpu = cpu_default;
20976 #else
20977 if (mcpu_cpu_opt)
20978 selected_cpu = *mcpu_cpu_opt;
20979 else
20980 mcpu_cpu_opt = &arm_arch_any;
20981 #endif
20983 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
20985 autoselect_thumb_from_cpu_variant ();
20987 arm_arch_used = thumb_arch_used = arm_arch_none;
20989 #if defined OBJ_COFF || defined OBJ_ELF
20991 unsigned int flags = 0;
20993 #if defined OBJ_ELF
20994 flags = meabi_flags;
20996 switch (meabi_flags)
20998 case EF_ARM_EABI_UNKNOWN:
20999 #endif
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;
21004 if (pic_code) flags |= F_PIC;
21005 if (!ARM_CPU_HAS_FEATURE (cpu_variant, fpu_any_hard))
21006 flags |= F_SOFT_FLOAT;
21008 switch (mfloat_abi_opt)
21010 case ARM_FLOAT_ABI_SOFT:
21011 case ARM_FLOAT_ABI_SOFTFP:
21012 flags |= F_SOFT_FLOAT;
21013 break;
21015 case ARM_FLOAT_ABI_HARD:
21016 if (flags & F_SOFT_FLOAT)
21017 as_bad (_("hard-float conflicts with specified fpu"));
21018 break;
21021 /* Using pure-endian doubles (even if soft-float). */
21022 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_endian_pure))
21023 flags |= F_VFP_FLOAT;
21025 #if defined OBJ_ELF
21026 if (ARM_CPU_HAS_FEATURE (cpu_variant, fpu_arch_maverick))
21027 flags |= EF_ARM_MAVERICK_FLOAT;
21028 break;
21030 case EF_ARM_EABI_VER4:
21031 case EF_ARM_EABI_VER5:
21032 /* No additional flags to set. */
21033 break;
21035 default:
21036 abort ();
21038 #endif
21039 bfd_set_private_flags (stdoutput, flags);
21041 /* We have run out flags in the COFF header to encode the
21042 status of ATPCS support, so instead we create a dummy,
21043 empty, debug section called .arm.atpcs. */
21044 if (atpcs)
21046 asection * sec;
21048 sec = bfd_make_section (stdoutput, ".arm.atpcs");
21050 if (sec != NULL)
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);
21059 #endif
21061 /* Record the CPU type as well. */
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))
21065 mach = bfd_mach_arm_iWMMXt;
21066 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_xscale))
21067 mach = bfd_mach_arm_XScale;
21068 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_cext_maverick))
21069 mach = bfd_mach_arm_ep9312;
21070 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5e))
21071 mach = bfd_mach_arm_5TE;
21072 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v5))
21074 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21075 mach = bfd_mach_arm_5T;
21076 else
21077 mach = bfd_mach_arm_5;
21079 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4))
21081 if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v4t))
21082 mach = bfd_mach_arm_4T;
21083 else
21084 mach = bfd_mach_arm_4;
21086 else if (ARM_CPU_HAS_FEATURE (cpu_variant, arm_ext_v3m))
21087 mach = bfd_mach_arm_3M;
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;
21097 bfd_set_arch_mach (stdoutput, TARGET_ARCH, mach);
21100 /* Command line processing. */
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.
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.
21111 New options (supported) are:
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
21122 -m[no-]warn-deprecated Warn about deprecated features
21124 For now we will also provide support for:
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>)
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
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.
21165 const char * md_shortopts = "m:k";
21167 #ifdef ARM_BI_ENDIAN
21168 #define OPTION_EB (OPTION_MD_BASE + 0)
21169 #define OPTION_EL (OPTION_MD_BASE + 1)
21170 #else
21171 #if TARGET_BYTES_BIG_ENDIAN
21172 #define OPTION_EB (OPTION_MD_BASE + 0)
21173 #else
21174 #define OPTION_EL (OPTION_MD_BASE + 1)
21175 #endif
21176 #endif
21177 #define OPTION_FIX_V4BX (OPTION_MD_BASE + 2)
21179 struct option md_longopts[] =
21181 #ifdef OPTION_EB
21182 {"EB", no_argument, NULL, OPTION_EB},
21183 #endif
21184 #ifdef OPTION_EL
21185 {"EL", no_argument, NULL, OPTION_EL},
21186 #endif
21187 {"fix-v4bx", no_argument, NULL, OPTION_FIX_V4BX},
21188 {NULL, no_argument, NULL, 0}
21191 size_t md_longopts_size = sizeof (md_longopts);
21193 struct arm_option_table
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. */
21202 struct arm_option_table arm_opts[] =
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},
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},
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},
21225 {NULL, NULL, NULL, 0, NULL}
21228 struct arm_legacy_option_table
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. */
21236 const struct arm_legacy_option_table arm_legacy_opts[] =
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. */
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,
21310 N_("use -mcpu=strongarm110")},
21311 {"mstrongarm1100", &legacy_cpu, ARM_ARCH_V4,
21312 N_("use -mcpu=strongarm1100")},
21313 {"mstrongarm1110", &legacy_cpu, ARM_ARCH_V4,
21314 N_("use -mcpu=strongarm1110")},
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")},
21319 /* Architecture variants -- don't add any more to this list either. */
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")},
21339 /* Floating point variants -- don't add any more to this list either. */
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,
21344 N_("use either -mfpu=softfpa or -mfpu=softvfp")},
21346 {NULL, NULL, ARM_ARCH_NONE, NULL}
21349 struct arm_cpu_option_table
21351 char *name;
21352 const arm_feature_set value;
21353 /* For some CPUs we assume an FPU unless the user explicitly sets
21354 -mfpu=... */
21355 const arm_feature_set default_fpu;
21356 /* The canonical name of the CPU, or NULL to use NAME converted to upper
21357 case. */
21358 const char *canonical_name;
21361 /* This list should, at a minimum, contain all the cpu names
21362 recognized by GCC. */
21363 static const struct arm_cpu_option_table arm_cpus[] =
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},
21409 {"fa526", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21410 {"fa626", ARM_ARCH_V4, FPU_ARCH_FPA, NULL},
21411 /* For V5 or later processors we default to using VFP; but the user
21412 should really set the FPU type explicitly. */
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},
21434 {"fa626te", ARM_ARCH_V5TE, FPU_NONE, NULL},
21435 {"fa726te", ARM_ARCH_V5TE, FPU_ARCH_VFP_V2, NULL},
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},
21446 {"cortex-a8", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
21447 | FPU_NEON_EXT_V1),
21448 NULL},
21449 {"cortex-a9", ARM_ARCH_V7A, ARM_FEATURE (0, FPU_VFP_V3
21450 | FPU_NEON_EXT_V1),
21451 NULL},
21452 {"cortex-r4", ARM_ARCH_V7R, FPU_NONE, NULL},
21453 {"cortex-m3", ARM_ARCH_V7M, FPU_NONE, NULL},
21454 {"cortex-m1", ARM_ARCH_V6M, FPU_NONE, NULL},
21455 {"cortex-m0", ARM_ARCH_V6M, FPU_NONE, NULL},
21456 /* ??? XSCALE is really an architecture. */
21457 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
21458 /* ??? iwmmxt is not a processor. */
21459 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP_V2, NULL},
21460 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP_V2, NULL},
21461 {"i80200", ARM_ARCH_XSCALE, FPU_ARCH_VFP_V2, NULL},
21462 /* Maverick */
21463 {"ep9312", ARM_FEATURE (ARM_AEXT_V4T, ARM_CEXT_MAVERICK), FPU_ARCH_MAVERICK, "ARM920T"},
21464 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE, NULL}
21467 struct arm_arch_option_table
21469 char *name;
21470 const arm_feature_set value;
21471 const arm_feature_set default_fpu;
21474 /* This list should, at a minimum, contain all the architecture names
21475 recognized by GCC. */
21476 static const struct arm_arch_option_table arm_archs[] =
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},
21504 {"armv6-m", ARM_ARCH_V6M, FPU_ARCH_VFP},
21505 {"armv7", ARM_ARCH_V7, FPU_ARCH_VFP},
21506 /* The official spelling of the ARMv7 profile variants is the dashed form.
21507 Accept the non-dashed form for compatibility with old toolchains. */
21508 {"armv7a", ARM_ARCH_V7A, FPU_ARCH_VFP},
21509 {"armv7r", ARM_ARCH_V7R, FPU_ARCH_VFP},
21510 {"armv7m", ARM_ARCH_V7M, FPU_ARCH_VFP},
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},
21514 {"xscale", ARM_ARCH_XSCALE, FPU_ARCH_VFP},
21515 {"iwmmxt", ARM_ARCH_IWMMXT, FPU_ARCH_VFP},
21516 {"iwmmxt2", ARM_ARCH_IWMMXT2,FPU_ARCH_VFP},
21517 {NULL, ARM_ARCH_NONE, ARM_ARCH_NONE}
21520 /* ISA extensions in the co-processor space. */
21521 struct arm_option_cpu_value_table
21523 char *name;
21524 const arm_feature_set value;
21527 static const struct arm_option_cpu_value_table arm_extensions[] =
21529 {"maverick", ARM_FEATURE (0, ARM_CEXT_MAVERICK)},
21530 {"xscale", ARM_FEATURE (0, ARM_CEXT_XSCALE)},
21531 {"iwmmxt", ARM_FEATURE (0, ARM_CEXT_IWMMXT)},
21532 {"iwmmxt2", ARM_FEATURE (0, ARM_CEXT_IWMMXT2)},
21533 {NULL, ARM_ARCH_NONE}
21536 /* This list should, at a minimum, contain all the fpu names
21537 recognized by GCC. */
21538 static const struct arm_option_cpu_value_table arm_fpus[] =
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},
21552 {"vfp3", FPU_ARCH_VFP_V3}, /* For backwards compatbility. */
21553 {"vfp10", FPU_ARCH_VFP_V2},
21554 {"vfp10-r0", FPU_ARCH_VFP_V1},
21555 {"vfpxd", FPU_ARCH_VFP_V1xD},
21556 {"vfpv2", FPU_ARCH_VFP_V2},
21557 {"vfpv3", FPU_ARCH_VFP_V3},
21558 {"vfpv3-d16", FPU_ARCH_VFP_V3D16},
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},
21564 {"neon", FPU_ARCH_VFP_V3_PLUS_NEON_V1},
21565 {"neon-fp16", FPU_ARCH_NEON_FP16},
21566 {NULL, ARM_ARCH_NONE}
21569 struct arm_option_value_table
21571 char *name;
21572 long value;
21575 static const struct arm_option_value_table arm_float_abis[] =
21577 {"hard", ARM_FLOAT_ABI_HARD},
21578 {"softfp", ARM_FLOAT_ABI_SOFTFP},
21579 {"soft", ARM_FLOAT_ABI_SOFT},
21580 {NULL, 0}
21583 #ifdef OBJ_ELF
21584 /* We only know how to output GNU and ver 4/5 (AAELF) formats. */
21585 static const struct arm_option_value_table arm_eabis[] =
21587 {"gnu", EF_ARM_EABI_UNKNOWN},
21588 {"4", EF_ARM_EABI_VER4},
21589 {"5", EF_ARM_EABI_VER5},
21590 {NULL, 0}
21592 #endif
21594 struct arm_long_option_table
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. */
21602 static int
21603 arm_parse_extension (char * str, const arm_feature_set **opt_p)
21605 arm_feature_set *ext_set = xmalloc (sizeof (arm_feature_set));
21607 /* Copy the feature set, so that we can modify it. */
21608 *ext_set = **opt_p;
21609 *opt_p = ext_set;
21611 while (str != NULL && *str != 0)
21613 const struct arm_option_cpu_value_table * opt;
21614 char * ext;
21615 int optlen;
21617 if (*str != '+')
21619 as_bad (_("invalid architectural extension"));
21620 return 0;
21623 str++;
21624 ext = strchr (str, '+');
21626 if (ext != NULL)
21627 optlen = ext - str;
21628 else
21629 optlen = strlen (str);
21631 if (optlen == 0)
21633 as_bad (_("missing architectural extension"));
21634 return 0;
21637 for (opt = arm_extensions; opt->name != NULL; opt++)
21638 if (strncmp (opt->name, str, optlen) == 0)
21640 ARM_MERGE_FEATURE_SETS (*ext_set, *ext_set, opt->value);
21641 break;
21644 if (opt->name == NULL)
21646 as_bad (_("unknown architectural extension `%s'"), str);
21647 return 0;
21650 str = ext;
21653 return 1;
21656 static int
21657 arm_parse_cpu (char * str)
21659 const struct arm_cpu_option_table * opt;
21660 char * ext = strchr (str, '+');
21661 int optlen;
21663 if (ext != NULL)
21664 optlen = ext - str;
21665 else
21666 optlen = strlen (str);
21668 if (optlen == 0)
21670 as_bad (_("missing cpu name `%s'"), str);
21671 return 0;
21674 for (opt = arm_cpus; opt->name != NULL; opt++)
21675 if (strncmp (opt->name, str, optlen) == 0)
21677 mcpu_cpu_opt = &opt->value;
21678 mcpu_fpu_opt = &opt->default_fpu;
21679 if (opt->canonical_name)
21680 strcpy (selected_cpu_name, opt->canonical_name);
21681 else
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;
21689 if (ext != NULL)
21690 return arm_parse_extension (ext, &mcpu_cpu_opt);
21692 return 1;
21695 as_bad (_("unknown cpu `%s'"), str);
21696 return 0;
21699 static int
21700 arm_parse_arch (char * str)
21702 const struct arm_arch_option_table *opt;
21703 char *ext = strchr (str, '+');
21704 int optlen;
21706 if (ext != NULL)
21707 optlen = ext - str;
21708 else
21709 optlen = strlen (str);
21711 if (optlen == 0)
21713 as_bad (_("missing architecture name `%s'"), str);
21714 return 0;
21717 for (opt = arm_archs; opt->name != NULL; opt++)
21718 if (streq (opt->name, str))
21720 march_cpu_opt = &opt->value;
21721 march_fpu_opt = &opt->default_fpu;
21722 strcpy (selected_cpu_name, opt->name);
21724 if (ext != NULL)
21725 return arm_parse_extension (ext, &march_cpu_opt);
21727 return 1;
21730 as_bad (_("unknown architecture `%s'\n"), str);
21731 return 0;
21734 static int
21735 arm_parse_fpu (char * str)
21737 const struct arm_option_cpu_value_table * opt;
21739 for (opt = arm_fpus; opt->name != NULL; opt++)
21740 if (streq (opt->name, str))
21742 mfpu_opt = &opt->value;
21743 return 1;
21746 as_bad (_("unknown floating point format `%s'\n"), str);
21747 return 0;
21750 static int
21751 arm_parse_float_abi (char * str)
21753 const struct arm_option_value_table * opt;
21755 for (opt = arm_float_abis; opt->name != NULL; opt++)
21756 if (streq (opt->name, str))
21758 mfloat_abi_opt = opt->value;
21759 return 1;
21762 as_bad (_("unknown floating point abi `%s'\n"), str);
21763 return 0;
21766 #ifdef OBJ_ELF
21767 static int
21768 arm_parse_eabi (char * str)
21770 const struct arm_option_value_table *opt;
21772 for (opt = arm_eabis; opt->name != NULL; opt++)
21773 if (streq (opt->name, str))
21775 meabi_flags = opt->value;
21776 return 1;
21778 as_bad (_("unknown EABI `%s'\n"), str);
21779 return 0;
21781 #endif
21783 static int
21784 arm_parse_it_mode (char * str)
21786 int ret = 1;
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
21798 as_bad (_("unknown implicit IT mode `%s', should be "\
21799 "arm, thumb, always, or never."), str);
21800 ret = 0;
21803 return ret;
21806 struct arm_long_option_table arm_long_opts[] =
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
21817 {"meabi=", N_("<ver>\t\t assemble for eabi version <ver>"),
21818 arm_parse_eabi, NULL},
21819 #endif
21820 {"mimplicit-it=", N_("<mode>\t controls implicit insertion of IT instructions"),
21821 arm_parse_it_mode, NULL},
21822 {NULL, NULL, 0, NULL}
21826 md_parse_option (int c, char * arg)
21828 struct arm_option_table *opt;
21829 const struct arm_legacy_option_table *fopt;
21830 struct arm_long_option_table *lopt;
21832 switch (c)
21834 #ifdef OPTION_EB
21835 case OPTION_EB:
21836 target_big_endian = 1;
21837 break;
21838 #endif
21840 #ifdef OPTION_EL
21841 case OPTION_EL:
21842 target_big_endian = 0;
21843 break;
21844 #endif
21846 case OPTION_FIX_V4BX:
21847 fix_v4bx = TRUE;
21848 break;
21850 case 'a':
21851 /* Listing option. Just ignore these, we don't support additional
21852 ones. */
21853 return 0;
21855 default:
21856 for (opt = arm_opts; opt->option != NULL; opt++)
21858 if (c == opt->option[0]
21859 && ((arg == NULL && opt->option[1] == 0)
21860 || streq (arg, opt->option + 1)))
21862 /* If the option is deprecated, tell the user. */
21863 if (warn_on_deprecated && opt->deprecated != NULL)
21864 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21865 arg ? arg : "", _(opt->deprecated));
21867 if (opt->var != NULL)
21868 *opt->var = opt->value;
21870 return 1;
21874 for (fopt = arm_legacy_opts; fopt->option != NULL; fopt++)
21876 if (c == fopt->option[0]
21877 && ((arg == NULL && fopt->option[1] == 0)
21878 || streq (arg, fopt->option + 1)))
21880 /* If the option is deprecated, tell the user. */
21881 if (warn_on_deprecated && fopt->deprecated != NULL)
21882 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c,
21883 arg ? arg : "", _(fopt->deprecated));
21885 if (fopt->var != NULL)
21886 *fopt->var = &fopt->value;
21888 return 1;
21892 for (lopt = arm_long_opts; lopt->option != NULL; lopt++)
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)
21900 /* If the option is deprecated, tell the user. */
21901 if (warn_on_deprecated && lopt->deprecated != NULL)
21902 as_tsktsk (_("option `-%c%s' is deprecated: %s"), c, arg,
21903 _(lopt->deprecated));
21905 /* Call the sup-option parser. */
21906 return lopt->func (arg + strlen (lopt->option) - 1);
21910 return 0;
21913 return 1;
21916 void
21917 md_show_usage (FILE * fp)
21919 struct arm_option_table *opt;
21920 struct arm_long_option_table *lopt;
21922 fprintf (fp, _(" ARM-specific assembler options:\n"));
21924 for (opt = arm_opts; opt->option != NULL; opt++)
21925 if (opt->help != NULL)
21926 fprintf (fp, " -%-23s%s\n", opt->option, _(opt->help));
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));
21932 #ifdef OPTION_EB
21933 fprintf (fp, _("\
21934 -EB assemble code for a big-endian cpu\n"));
21935 #endif
21937 #ifdef OPTION_EL
21938 fprintf (fp, _("\
21939 -EL assemble code for a little-endian cpu\n"));
21940 #endif
21942 fprintf (fp, _("\
21943 --fix-v4bx Allow BX in ARMv4 code\n"));
21947 #ifdef OBJ_ELF
21948 typedef struct
21950 int val;
21951 arm_feature_set flags;
21952 } cpu_arch_ver_table;
21954 /* Mapping from CPU features to EABI CPU arch values. Table must be sorted
21955 least features first. */
21956 static const cpu_arch_ver_table cpu_arch_ver[] =
21958 {1, ARM_ARCH_V4},
21959 {2, ARM_ARCH_V4T},
21960 {3, ARM_ARCH_V5},
21961 {3, ARM_ARCH_V5T},
21962 {4, ARM_ARCH_V5TE},
21963 {5, ARM_ARCH_V5TEJ},
21964 {6, ARM_ARCH_V6},
21965 {7, ARM_ARCH_V6Z},
21966 {9, ARM_ARCH_V6K},
21967 {11, ARM_ARCH_V6M},
21968 {8, ARM_ARCH_V6T2},
21969 {10, ARM_ARCH_V7A},
21970 {10, ARM_ARCH_V7R},
21971 {10, ARM_ARCH_V7M},
21972 {0, ARM_ARCH_NONE}
21975 /* Set an attribute if it has not already been set by the user. */
21976 static void
21977 aeabi_set_attribute_int (int tag, int value)
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);
21985 static void
21986 aeabi_set_attribute_string (int tag, const char *value)
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);
21994 /* Set the public EABI object attributes. */
21995 static void
21996 aeabi_set_public_attributes (void)
21998 int arch;
21999 arm_feature_set flags;
22000 arm_feature_set tmp;
22001 const cpu_arch_ver_table *p;
22003 /* Choose the architecture based on the capabilities of the requested cpu
22004 (if any) and/or the instructions actually used. */
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);
22008 /*Allow the user to override the reported architecture. */
22009 if (object_arch)
22011 ARM_CLEAR_FEATURE (flags, flags, arm_arch_any);
22012 ARM_MERGE_FEATURE_SETS (flags, flags, *object_arch);
22015 tmp = flags;
22016 arch = 0;
22017 for (p = cpu_arch_ver; p->val; p++)
22019 if (ARM_CPU_HAS_FEATURE (tmp, p->flags))
22021 arch = p->val;
22022 ARM_CLEAR_FEATURE (tmp, tmp, p->flags);
22026 /* Tag_CPU_name. */
22027 if (selected_cpu_name[0])
22029 char *p;
22031 p = selected_cpu_name;
22032 if (strncmp (p, "armv", 4) == 0)
22034 int i;
22036 p += 4;
22037 for (i = 0; p[i]; i++)
22038 p[i] = TOUPPER (p[i]);
22040 aeabi_set_attribute_string (Tag_CPU_name, p);
22042 /* Tag_CPU_arch. */
22043 aeabi_set_attribute_int (Tag_CPU_arch, arch);
22044 /* Tag_CPU_arch_profile. */
22045 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7a))
22046 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'A');
22047 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v7r))
22048 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'R');
22049 else if (ARM_CPU_HAS_FEATURE (flags, arm_ext_m))
22050 aeabi_set_attribute_int (Tag_CPU_arch_profile, 'M');
22051 /* Tag_ARM_ISA_use. */
22052 if (ARM_CPU_HAS_FEATURE (flags, arm_ext_v1)
22053 || arch == 0)
22054 aeabi_set_attribute_int (Tag_ARM_ISA_use, 1);
22055 /* Tag_THUMB_ISA_use. */
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);
22060 /* Tag_VFP_arch. */
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);
22070 /* Tag_WMMX_arch. */
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). */
22076 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_ext_v1))
22077 aeabi_set_attribute_int (Tag_Advanced_SIMD_arch, 1);
22078 /* Tag_VFP_HP_extension (formerly Tag_NEON_FP16_arch). */
22079 if (ARM_CPU_HAS_FEATURE (flags, fpu_neon_fp16))
22080 aeabi_set_attribute_int (Tag_VFP_HP_extension, 1);
22083 /* Add the default contents for the .ARM.attributes section. */
22084 void
22085 arm_md_end (void)
22087 if (EF_ARM_EABI_VERSION (meabi_flags) < EF_ARM_EABI_VER4)
22088 return;
22090 aeabi_set_public_attributes ();
22092 #endif /* OBJ_ELF */
22095 /* Parse a .cpu directive. */
22097 static void
22098 s_arm_cpu (int ignored ATTRIBUTE_UNUSED)
22100 const struct arm_cpu_option_table *opt;
22101 char *name;
22102 char saved_char;
22104 name = input_line_pointer;
22105 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22106 input_line_pointer++;
22107 saved_char = *input_line_pointer;
22108 *input_line_pointer = 0;
22110 /* Skip the first "all" entry. */
22111 for (opt = arm_cpus + 1; opt->name != NULL; opt++)
22112 if (streq (opt->name, name))
22114 mcpu_cpu_opt = &opt->value;
22115 selected_cpu = opt->value;
22116 if (opt->canonical_name)
22117 strcpy (selected_cpu_name, opt->canonical_name);
22118 else
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;
22125 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22126 *input_line_pointer = saved_char;
22127 demand_empty_rest_of_line ();
22128 return;
22130 as_bad (_("unknown cpu `%s'"), name);
22131 *input_line_pointer = saved_char;
22132 ignore_rest_of_line ();
22136 /* Parse a .arch directive. */
22138 static void
22139 s_arm_arch (int ignored ATTRIBUTE_UNUSED)
22141 const struct arm_arch_option_table *opt;
22142 char saved_char;
22143 char *name;
22145 name = input_line_pointer;
22146 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22147 input_line_pointer++;
22148 saved_char = *input_line_pointer;
22149 *input_line_pointer = 0;
22151 /* Skip the first "all" entry. */
22152 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22153 if (streq (opt->name, name))
22155 mcpu_cpu_opt = &opt->value;
22156 selected_cpu = opt->value;
22157 strcpy (selected_cpu_name, opt->name);
22158 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22159 *input_line_pointer = saved_char;
22160 demand_empty_rest_of_line ();
22161 return;
22164 as_bad (_("unknown architecture `%s'\n"), name);
22165 *input_line_pointer = saved_char;
22166 ignore_rest_of_line ();
22170 /* Parse a .object_arch directive. */
22172 static void
22173 s_arm_object_arch (int ignored ATTRIBUTE_UNUSED)
22175 const struct arm_arch_option_table *opt;
22176 char saved_char;
22177 char *name;
22179 name = input_line_pointer;
22180 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22181 input_line_pointer++;
22182 saved_char = *input_line_pointer;
22183 *input_line_pointer = 0;
22185 /* Skip the first "all" entry. */
22186 for (opt = arm_archs + 1; opt->name != NULL; opt++)
22187 if (streq (opt->name, name))
22189 object_arch = &opt->value;
22190 *input_line_pointer = saved_char;
22191 demand_empty_rest_of_line ();
22192 return;
22195 as_bad (_("unknown architecture `%s'\n"), name);
22196 *input_line_pointer = saved_char;
22197 ignore_rest_of_line ();
22200 /* Parse a .fpu directive. */
22202 static void
22203 s_arm_fpu (int ignored ATTRIBUTE_UNUSED)
22205 const struct arm_option_cpu_value_table *opt;
22206 char saved_char;
22207 char *name;
22209 name = input_line_pointer;
22210 while (*input_line_pointer && !ISSPACE (*input_line_pointer))
22211 input_line_pointer++;
22212 saved_char = *input_line_pointer;
22213 *input_line_pointer = 0;
22215 for (opt = arm_fpus; opt->name != NULL; opt++)
22216 if (streq (opt->name, name))
22218 mfpu_opt = &opt->value;
22219 ARM_MERGE_FEATURE_SETS (cpu_variant, *mcpu_cpu_opt, *mfpu_opt);
22220 *input_line_pointer = saved_char;
22221 demand_empty_rest_of_line ();
22222 return;
22225 as_bad (_("unknown floating point format `%s'\n"), name);
22226 *input_line_pointer = saved_char;
22227 ignore_rest_of_line ();
22230 /* Copy symbol information. */
22232 void
22233 arm_copy_symbol_attributes (symbolS *dest, symbolS *src)
22235 ARM_GET_FLAG (dest) = ARM_GET_FLAG (src);
22238 #ifdef OBJ_ELF
22239 /* Given a symbolic attribute NAME, return the proper integer value.
22240 Returns -1 if the attribute is not known. */
22243 arm_convert_symbolic_attribute (const char *name)
22245 static const struct
22247 const char * name;
22248 const int tag;
22250 attribute_table[] =
22252 /* When you modify this table you should
22253 also modify the list in doc/c-arm.texi. */
22254 #define T(tag) {#tag, tag}
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)
22293 #undef T
22295 unsigned int i;
22297 if (name == NULL)
22298 return -1;
22300 for (i = 0; i < ARRAY_SIZE (attribute_table); i++)
22301 if (strcmp (name, attribute_table[i].name) == 0)
22302 return attribute_table[i].tag;
22304 return -1;
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. */
22312 arm_apply_sym_value (struct fix * fixP)
22314 if (fixP->fx_addsy
22315 && ARM_CPU_HAS_FEATURE (selected_cpu, arm_ext_v5t)
22316 && !S_IS_EXTERNAL (fixP->fx_addsy))
22318 switch (fixP->fx_r_type)
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;
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;
22332 default:
22333 break;
22337 return 0;
22339 #endif /* OBJ_ELF */